[
  {
    "path": ".clang-format",
    "content": "---\nLanguage:        Cpp\n# BasedOnStyle:  LLVM\nAccessModifierOffset: -4\nAlignAfterOpenBracket: Align\nAlignConsecutiveAssignments: false\nAlignConsecutiveDeclarations: false\nAlignEscapedNewlines: Right\nAlignOperands:   true\nAlignTrailingComments: true\nAllowAllParametersOfDeclarationOnNextLine: true\nAllowShortBlocksOnASingleLine: false\nAllowShortCaseLabelsOnASingleLine: false\nAllowShortFunctionsOnASingleLine: Inline\nAllowShortIfStatementsOnASingleLine: false\nAllowShortLoopsOnASingleLine: false\nAlwaysBreakAfterDefinitionReturnType: None\nAlwaysBreakAfterReturnType: None\nAlwaysBreakBeforeMultilineStrings: false\nAlwaysBreakTemplateDeclarations: false\nBinPackArguments: false\nBinPackParameters: false\nBraceWrapping:   \n  AfterClass:      false\n  AfterControlStatement: false\n  AfterEnum:       false\n  AfterFunction:   true\n  AfterNamespace:  false\n  AfterObjCDeclaration: false\n  AfterStruct:     false\n  AfterUnion:      false\n  AfterExternBlock: false\n  BeforeCatch:     false\n  BeforeElse:      false\n  IndentBraces:    false\n  SplitEmptyFunction: true\n  SplitEmptyRecord: true\n  SplitEmptyNamespace: true\nBreakBeforeBinaryOperators: None\nBreakBeforeBraces: Custom\nBreakBeforeInheritanceComma: false\nBreakBeforeTernaryOperators: true\nBreakConstructorInitializersBeforeComma: false\nBreakConstructorInitializers: AfterColon\nBreakAfterJavaFieldAnnotations: false\nBreakStringLiterals: true\nColumnLimit:     80\nCommentPragmas:  '^ IWYU pragma:'\nCompactNamespaces: false\nConstructorInitializerAllOnOneLineOrOnePerLine: true\nConstructorInitializerIndentWidth: 4\nContinuationIndentWidth: 4\nCpp11BracedListStyle: true\nDerivePointerAlignment: false\nDisableFormat:   false\nExperimentalAutoDetectBinPacking: false\nFixNamespaceComments: false\nForEachMacros:   \n  - foreach\n  - Q_FOREACH\n  - BOOST_FOREACH\nIncludeBlocks:   Preserve\nIncludeCategories: \n  - Regex:           '^\"(llvm|llvm-c|clang|clang-c)/'\n    Priority:        2\n  - Regex:           '^(<|\"(gtest|gmock|isl|json)/)'\n    Priority:        3\n  - Regex:           '.*'\n    Priority:        1\nIncludeIsMainRegex: '(Test)?$'\nIndentCaseLabels: false\nIndentPPDirectives: AfterHash\nIndentWidth:     4\nIndentWrappedFunctionNames: false\nJavaScriptQuotes: Leave\nJavaScriptWrapImports: true\nKeepEmptyLinesAtTheStartOfBlocks: true\nMacroBlockBegin: ''\nMacroBlockEnd:   ''\nMaxEmptyLinesToKeep: 1\nNamespaceIndentation: All\nObjCBlockIndentWidth: 4\nObjCSpaceAfterProperty: false\nObjCSpaceBeforeProtocolList: true\nPenaltyBreakAssignment: 2\nPenaltyBreakBeforeFirstCallParameter: 19\nPenaltyBreakComment: 300\nPenaltyBreakFirstLessLess: 120\nPenaltyBreakString: 1000\nPenaltyExcessCharacter: 1000000\nPenaltyReturnTypeOnItsOwnLine: 60\nPointerAlignment: Left\nRawStringFormats: \n  - Delimiters:       [pb]\n    Language:        TextProto\n    BasedOnStyle:    google\nReflowComments:  true\nSortIncludes:    true\nSortUsingDeclarations: true\nSpaceAfterCStyleCast: false\nSpaceAfterTemplateKeyword: true\nSpaceBeforeAssignmentOperators: true\nSpaceBeforeParens: ControlStatements\nSpaceInEmptyParentheses: false\nSpacesBeforeTrailingComments: 1\nSpacesInAngles:  false\nSpacesInContainerLiterals: true\nSpacesInCStyleCastParentheses: false\nSpacesInParentheses: false\nSpacesInSquareBrackets: false\nStandard:        Cpp11\nTabWidth:        8\nUseTab:          Never\n...\n\n"
  },
  {
    "path": ".gitignore",
    "content": "/nbproject/\n/build/\n/install/\n*.cmake\n/CMakeFiles/\n/CMakeScripts/\nCMakeCache.txt\n/Release/\n/Debug/\n/Yacas.build/\n/Yacas.xcodeproj/\n/JavaYacas/CVersion.java\n/TEST-net.sf.yacas.YacasTest.xml\n/yacas-logfile.txt\n/jyacas/net/sf/yacas/CVersion.java\n.DS_Store\n.vscode/ipch/*\n*.pyc\n.vs/\nout/"
  },
  {
    "path": ".vscode/launch.json",
    "content": "{\n    \"version\": \"0.2.0\",\n    \"configurations\": [\n        {\n            \"name\": \"(gdb) Launch yacas\",\n            \"type\": \"cppdbg\",\n            \"request\": \"launch\",\n            \"program\": \"${workspaceRoot}/build/cyacas/yacas/yacas\",\n            \"args\": [\"--rootdir\", \"${workspaceRoot}/scripts/\"],\n            \"stopAtEntry\": false,\n            \"cwd\": \"${workspaceRoot}\",\n            \"environment\": [],\n            \"externalConsole\": true,\n            \"MIMode\": \"gdb\",\n            \"setupCommands\": [\n                {\n                    \"description\": \"Enable pretty-printing for gdb\",\n                    \"text\": \"-enable-pretty-printing\",\n                    \"ignoreFailures\": true\n                }\n            ]\n        },\n        {\n            \"name\": \"(gdb) Launch yacas arithmetic.yts\",\n            \"type\": \"cppdbg\",\n            \"request\": \"launch\",\n            \"program\": \"${workspaceRoot}/build/cyacas/yacas/yacas\",\n            \"args\": [\"--rootdir\", \"${workspaceRoot}/scripts/\", \"${workspaceRoot}/tests/arithmetic.yts\"],\n            \"stopAtEntry\": false,\n            \"cwd\": \"${workspaceRoot}\",\n            \"environment\": [],\n            \"externalConsole\": true,\n            \"MIMode\": \"gdb\",\n            \"setupCommands\": [\n                {\n                    \"description\": \"Enable pretty-printing for gdb\",\n                    \"text\": \"-enable-pretty-printing\",\n                    \"ignoreFailures\": true\n                }\n            ]\n        },\n        {\n            \"name\": \"(gdb) Launch yacas numerics.yts\",\n            \"type\": \"cppdbg\",\n            \"request\": \"launch\",\n            \"program\": \"${workspaceRoot}/build/cyacas/yacas/yacas\",\n            \"args\": [\"--rootdir\", \"${workspaceRoot}/scripts/\", \"${workspaceRoot}/tests/numerics.yts\"],\n            \"stopAtEntry\": false,\n            \"cwd\": \"${workspaceRoot}\",\n            \"environment\": [],\n            \"externalConsole\": true,\n            \"MIMode\": \"gdb\",\n            \"setupCommands\": [\n                {\n                    \"description\": \"Enable pretty-printing for gdb\",\n                    \"text\": \"-enable-pretty-printing\",\n                    \"ignoreFailures\": true\n                }\n            ]\n        },\n        {\n            \"name\": \"(gdb) Launch yacas orthopoly.yts\",\n            \"type\": \"cppdbg\",\n            \"request\": \"launch\",\n            \"program\": \"${workspaceRoot}/build/cyacas/yacas/yacas\",\n            \"args\": [\"--rootdir\", \"${workspaceRoot}/scripts/\", \"${workspaceRoot}/tests/orthoppoly.yts\"],\n            \"stopAtEntry\": false,\n            \"cwd\": \"${workspaceRoot}\",\n            \"environment\": [],\n            \"externalConsole\": true,\n            \"MIMode\": \"gdb\",\n            \"setupCommands\": [\n                {\n                    \"description\": \"Enable pretty-printing for gdb\",\n                    \"text\": \"-enable-pretty-printing\",\n                    \"ignoreFailures\": true\n                }\n            ]\n        }\n    ],\n    \"compounds\": []\n}"
  },
  {
    "path": ".vscode/settings.json",
    "content": "{\n    \"C_Cpp.intelliSenseEngine\": \"Default\",\n    \"editor.insertSpaces\": true,\n    \"editor.tabSize\": 4,\n    \"editor.detectIndentation\": true,\n    \"files.associations\": {\n        \"*.ltx\": \"latex\",\n        \"cctype\": \"cpp\",\n        \"cmath\": \"cpp\",\n        \"csignal\": \"cpp\",\n        \"cstdarg\": \"cpp\",\n        \"cstddef\": \"cpp\",\n        \"cstdio\": \"cpp\",\n        \"cstdlib\": \"cpp\",\n        \"cstring\": \"cpp\",\n        \"ctime\": \"cpp\",\n        \"cwchar\": \"cpp\",\n        \"cwctype\": \"cpp\",\n        \"array\": \"cpp\",\n        \"atomic\": \"cpp\",\n        \"*.tcc\": \"cpp\",\n        \"chrono\": \"cpp\",\n        \"condition_variable\": \"cpp\",\n        \"cstdint\": \"cpp\",\n        \"exception\": \"cpp\",\n        \"functional\": \"cpp\",\n        \"future\": \"cpp\",\n        \"initializer_list\": \"cpp\",\n        \"iosfwd\": \"cpp\",\n        \"limits\": \"cpp\",\n        \"mutex\": \"cpp\",\n        \"new\": \"cpp\",\n        \"ratio\": \"cpp\",\n        \"stdexcept\": \"cpp\",\n        \"system_error\": \"cpp\",\n        \"thread\": \"cpp\",\n        \"tuple\": \"cpp\",\n        \"type_traits\": \"cpp\",\n        \"typeinfo\": \"cpp\",\n        \"utility\": \"cpp\",\n        \"codecvt\": \"cpp\",\n        \"bitset\": \"cpp\",\n        \"clocale\": \"cpp\",\n        \"fstream\": \"cpp\",\n        \"iomanip\": \"cpp\",\n        \"iostream\": \"cpp\",\n        \"istream\": \"cpp\",\n        \"memory\": \"cpp\",\n        \"ostream\": \"cpp\",\n        \"sstream\": \"cpp\",\n        \"streambuf\": \"cpp\",\n        \"algorithm\": \"cpp\",\n        \"*.ipp\": \"cpp\",\n        \"deque\": \"cpp\",\n        \"string\": \"cpp\",\n        \"unordered_map\": \"cpp\",\n        \"unordered_set\": \"cpp\",\n        \"vector\": \"cpp\",\n        \"numeric\": \"cpp\",\n        \"optional\": \"cpp\",\n        \"string_view\": \"cpp\",\n        \"variant\": \"cpp\"\n    },\n    \"python.pythonPath\": \"/usr/bin/python3\",\n    \"files.exclude\": {\n        \"**/.DS_Store\": true,\n        \"**/.git\": true,\n        \"**/.hg\": true,\n        \"**/.svn\": true,\n        \"**/*.pyc\": true,\n        \"**/build\": true,\n        \"**/CVS\": true\n    },\n    \"files.trimTrailingWhitespace\": true,\n    \"restructuredtext.builtDocumentationPath\": \"${workspaceRoot}/build/docs/html\",\n    \"cmake.configureOnOpen\": true,\n    \"workbench.colorCustomizations\": {\n        \"statusBar.background\": \"#E49427\",\n        \"statusBar.debuggingBackground\": \"#E49427\",\n        \"statusBar.noFolderBackground\": \"#E49427\",\n        \"statussBar.prominentBackground\": \"#E49427\"\n    },\n    \"files.watcherExclude\": {\n        \"**/build/**\": true\n    },\n    \"cmake.installPrefix\": \"${workspaceRoot}/build/install/${buildKit}/${buildType}\",\n    \"cmake.configureSettings\": {\n        \"Qt5Core_DIR\": \"/usr/lib/x86_64-linux-gnu/cmake/Qt5Core\",\n        \"Qt5Widgets_DIR\": \"/usr/lib/x86_64-linux-gnu/cmake/Qt5Widgets\",\n        \"Qt5WebEngine_DIR\": \"/usr/lib/x86_64-linux-gnu/cmake/Qt5WebEngine\",\n        \"Qt5WebEngineWidgets_DIR\": \"/usr/lib/x86_64-linux-gnu/cmake/Qt5WebEngineWidgets\",\n        \"Qt5Svg_DIR\": \"/usr/lib/x86_64-linux-gnu/cmake/Qt5Svg\"\n    },\n    \"python.linting.pylintEnabled\": true,\n    \"python.linting.enabled\": true,\n    \"restructuredtext.confPath\": \"\"\n}"
  },
  {
    "path": "AUTHORS",
    "content": "************\nCredits [*]_\n************\n\nOriginal/primary authors \n========================\nAyal Pinkus                  *apinkus \"AT\" xs4all \"DOT\" nl*\n    This project was started by Ayal Pinkus who remains the main author and the primary maintainer.\n\nSerge Winitzki               *serge \"AT\" cosmos \"DOT\" phy \"DOT\" tufts \"DOT\" edu*\n    Added factorials over rationals, TeXForm, did a major overhaul of the introduction manual (actually, he wrote\n    large part of the manual as it is), and initiated numerous improvements and test code for Yacas, and\n    implemented yacas_client. Actually, Serge has been one of the larger contributors, and the main force behind\n    the improved documentation.\n\nJitse Niesen                 *jn221 \"AT\" damtp \"DOT\" cam \"DOT\" ac \"DOT\" uk*\n    Reported some bugs, helped improve various parts of Yacas, and greatly improved the manual for Yacas.\n\nMaintainer\n==========\n\nGrzegorz Mazur             *teoretyk \"AT\" gmail \"DOT\" com*\n\nContributors\n============\n\nJim Apple                    *japple \"AT\" freeshell \"DOT\" org*\n    Reported bugs and supplied improved code for gcc 3.3.4\n\nMark Arrasmith               *arrasmith \"AT\" math \"DOT\" twsu \"DOT\" edu*\n    Helped greatly in setting up the fltk-based graphicaluser interface, and fixed some bugs relating to limits\n    regarding infinity.\n\nFred Bacon                   *bacon \"AT\" aerodyne \"DOT\" com*\n    Fixed some compiler errors on the newer gcc compiles. Reported some important bugs.\n\nJay Belanger                 *belanger \"AT\" truman \"DOT\" edu*\n    Reported some bugs and improved some of the GnuPlot code. He also wrote the yacas.el file, which allows you\n    to run yacas from within emacs.\n\nRoberto Colistete Junior\n    Is maintaining a version of `Yacas for SymbianOS <http://www.robertocolistete.net/Yacas/>`_.\n\nSebastian Ferraro            *sferraro \"AT\" criba \"DOT\" edu \"DOT\" ar*\n    Reported bugs and supplied improved code (determinants).\n\nJohn Fremlin\n    Added some code for fast calculation of roots of a cubic polynomial.\n\nPeter Gilbert                *peterdgilbert \"AT\" gmail \"DOT\" com*\n    Made many improvements to the C++ code to make it conform more to standard C++ coding conventions (class\n    interfaces looking more like stl), improved the regression test suite.\n\nJames Gilbertson             *azurite \"AT\" telusplanet \"DOT\" net*\n    Win32 port, improved error reporting. Added initial version of Karatsuba multiplication, and added some matrix\n    functions to the math library.\n\nGabor Grothendieck\n    Gabor is the maintainer of `Ryacas <https://code.google.com/p/ryacas/>`_, and gave valuable feedback on the\n    new web site.\n\nRene Grothmann              *2004 \"AT\" rene-grothmann \"DOT\" de*\n    Married Euler to Yacas.\n\nFranz Hack                   *franz.hack \"AT\" web \"DOT\" de*\n    Supplied a Delphi interface to the Yacas DLL.\n\nIngrid Halters\n    Helped improve the ease of use of the Yacas web site.\n\nMark Hatsell                 *mark \"AT\" autograph-maths \"DOT\" com*\n    Made the server code work on Windows.\n\nJoris van der Hoeven        *TeXmacs \"AT\" math \"DOT\" u-psud \"DOT\" fr*\n    Helped with texmacs support.\n\nWolfgang Hšnig               *pocket_software \"AT\" web \"DOT\" de*\n    Created a port of Yacas that runs on PocketPC, to be found `here <http://www.pocket-software.de.vu>`_.\n\nDaniel Richard G.            *straker \"AT\" MIT \"DOT\" EDU*\n    Added autoconf/automake scripts, made Sun/Sgi compilation possible, created a rpm spec file, many many many\n    changes to clean up the source distribution.\n\nIgor Khavkine\n    Added 'Diverge' and 'Curl', and implemented threading for the derivative operator (the gradient). Fixed GMP\n    code.\n\nJohn Lapeyre\n    Made some modifications to the make file, and improved some math code.\n\nJonathan Leto                *jonathan \"AT\" leto \"DOT\" net*\n    Helped improve the integration algorithm, and helped extend the tests used for Yacas (finding numerous bugs).\n\nVladimir Livshits            *livshits \"AT\" cs \"DOT\" stanford \"DOT\" edu*\n    Set up the initial sourceforge CVS repository, and updated the Windows version source code. He also greatly\n    improved the logic theorem prover code.\n\nEugenia Loli\n    Helped build the BeOS version of Yacas.\n\nAdolf Mathias                *adolf_mathias \"AT\" web \"DOT\" de*\n\nGrzegorz Mazur               *teoretyk \"AT\" gmail \"DOT\" com*\n\nPablo De Nápoli              *pdenapo \"AT\" yahoo \"DOT\" com*\n    Fixed the configure script so Yacas compiles under cygwin.\n\nGopal Narayanan              *gopal \"AT\" debian \"DOT\" org*\n    Debian package maintainer. Made a man page for Yacas.\n\nMarta Noga                   *marta.noga \"AT\" gmail \"DOT\" com*\n\nChristian Obrecht            *christian \"DOT\" obrecht \"AT\" wanadoo \"DOT\" fr*\n    Made a much better Limit, and made Yacas behave better at infinity.\n\nAlberto González Palomo\n    Implemented a console-mode version of Yacas for AgendaVR. Changed the directory structure for the script\n    files, and implemented initial support for OpenMath.\n\nDoreen Pinkus                *d \"DOT\" pinkus \"AT\" hccnet \"DOT\" nl*\n    Designed the second version of the Web site for Yacas.\n\nMike Pinna                   *mike \"AT\" autograph-maths \"DOT\" com*\n    Applied some bug fixes.\n\nSavario Prinz                *yacas \"AT\" mac \"DOT\" com*\n    Built a fantastic Mac version of Yacas.\n\nDirk Reusch\n    Added some linear algebra functions, and fixed some predicate functions.\n\nDaniel Rigby\n    Brought a client-server structure to the EPOC32 version of Yacas.\n\nJuan Pablo Romero            *jpablo_romero \"AT\" hotmail \"DOT\" com*\n    Reported many bugs, made many suggestions for improvements, and supplied improved code (yacas scripts and\n    makefile code).\n\nRobert V Schipper            *rvs \"AT\" achilles \"DOT\" nfia \"DOT\" org*\n    Ironed out a few bugs in Yacas.\n\nSchneelocke\n    Reported an important bug in numeric calculations.\n\nHenSiong Tan                 *tan \"AT\" stat \"DOT\" psu \"DOT\" edu*\n\nYannick Versley              *yannick \"AT\" versley \"DOT\" de*\n    Sent some patches regarding bugs relating integration and differentiation.\n\nAdrian V.                    *qwert2003 \"AT\" users \"DOT\" sourceforge \"DOT\" net*\n\nYijun Yu                     *y.yu \"AT\" open \"DOT\" ac \"DOT\" uk*\n    Implemented LDU decomposition\n\nLadislav Zejda\n    Supplied patches to make Yacas work on Dec Alpha's.\n\nAndrei Zorine\n    Started the body of statistics code.\n\n\n\n.. [*] All with last-known email addresses mangled in an obvious way\n"
  },
  {
    "path": "CMakeLists.txt",
    "content": "cmake_minimum_required (VERSION 3.10)\n\nforeach (p CMP0048 CMP0054 CMP0071 CMP0135)\n    if (POLICY ${p})\n        cmake_policy(SET ${p} NEW)\n    endif ()\nendforeach ()\n\noption (ENABLE_CYACAS_CONSOLE \"build the C++ yacas text console\" ON)\noption (ENABLE_CYACAS_GUI \"build the C++ yacas GUI application\" ON)\noption (ENABLE_CYACAS_GUI_PRIVATE_CODEMIRROR \"use private copy of CodeMirror in yacas GUI application\" ON)\noption (ENABLE_CYACAS_GUI_PRIVATE_MATHJAX \"use private copy of MathJAX in yacas GUI application\" ON)\noption (ENABLE_CYACAS_KERNEL \"build the C++ yacas Jupyter kernel\" OFF)\noption (ENABLE_CYACAS_XEUS \"build the C++ yacas Xeus kernel\" OFF)\noption (ENABLE_CYACAS_UNIT_TESTS \"build the C++ yacas engine unit tests\" OFF)\noption (ENABLE_CYACAS_BENCHMARKS \"build the C++ yacas engine benchmarks\" OFF)\noption (ENABLE_JYACAS \"build the Java yacas engine\" OFF)\noption (ENABLE_DOCS \"generate documentation\" OFF)\noption (ENABLE_CODE_COVERAGE \"enable coverage reporting\" OFF)\n\nif (ENABLE_CYACAS_CONSOLE OR ENABLE_CYACAS_GUI OR ENABLE_CYACAS_KERNEL)\n    set (ENABLE_CYACAS ON)\nelse ()\n    set (ENABLE_CYACAS OFF)\nendif()\n\nset (CMAKE_MODULE_PATH \"${CMAKE_SOURCE_DIR}/cmake\")\n\nset (LANGUAGES CXX C)\n\nif (ENABLE_JYACAS)\n    find_package (Java)\n    include (UseJava)\n    set (LANGUAGES ${LANGUAGES} Java)\nendif ()\n\nproject (yacas VERSION 1.9.2 LANGUAGES ${LANGUAGES})\n\nset (CMAKE_CXX_STANDARD 23)\nset (CMAKE_CXX_STANDARD_REQUIRED ON)\nset (CMAKE_CXX_EXTENSIONS OFF)\n\ninclude (GNUInstallDirs)\ninclude (CTest)\n\nset (YACAS_SCRIPTS\n    scripts/array.rep/code.ys\n    scripts/array.rep/code.ys.def\n    scripts/assoc.rep/code.ys\n    scripts/assoc.rep/code.ys.def\n    scripts/base.rep/math.ys\n    scripts/base.rep/math.ys.def\n    scripts/c_form.rep/code.ys\n    scripts/c_form.rep/code.ys.def\n    scripts/calendar.rep/code.ys\n    scripts/calendar.rep/code.ys.def\n    scripts/complex.rep/code.ys\n    scripts/complex.rep/code.ys.def\n    scripts/complex.rep/om.ys\n    scripts/constants.rep/code.ys\n    scripts/constants.rep/code.ys.def\n    scripts/constants.rep/om.ys\n    scripts/controlflow.rep/code.ys\n    scripts/controlflow.rep/code.ys.def\n    scripts/cse.rep/cse.ys\n    scripts/cse.rep/cse.ys.def\n    scripts/debug.rep/code.ys\n    scripts/debug.rep/code.ys.def\n    scripts/deffunc.rep/code.ys\n    scripts/deffunc.rep/code.ys.def\n    scripts/deriv.rep/code.ys\n    scripts/deriv.rep/code.ys.def\n    scripts/example.rep/code.ys\n    scripts/example.rep/code.ys.def\n    scripts/factors.rep/binaryfactors.ys\n    scripts/factors.rep/binaryfactors.ys.def\n    scripts/factors.rep/code.ys\n    scripts/factors.rep/code.ys.def\n    scripts/functional.rep/code.ys\n    scripts/functional.rep/code.ys.def\n    scripts/functional.rep/om.ys\n    scripts/graph.rep/code.ys\n    scripts/graph.rep/code.ys.def\n    scripts/html.rep/code.ys\n    scripts/html.rep/code.ys.def\n    scripts/integrate.rep/code.ys\n    scripts/integrate.rep/code.ys.def\n    scripts/integrate.rep/om.ys\n    scripts/io.rep/code.ys\n    scripts/io.rep/code.ys.def\n    scripts/io.rep/defaultprint.ys\n    scripts/io.rep/defaultprint.ys.def\n    scripts/io.rep/errors.ys\n    scripts/io.rep/formula.ys\n    scripts/io.rep/print.ys\n    scripts/limit.rep/code.ys\n    scripts/limit.rep/code.ys.def\n    scripts/limit.rep/om.ys\n    scripts/linalg.rep/code.ys\n    scripts/linalg.rep/code.ys.def\n    scripts/lists.rep/code.ys\n    scripts/lists.rep/code.ys.def\n    scripts/lists.rep/scopestack.ys\n    scripts/lists.rep/scopestack.ys.def\n    scripts/localrules.rep/code.ys\n    scripts/localrules.rep/code.ys.def\n    scripts/logic.rep/code.ys\n    scripts/logic.rep/code.ys.def\n    scripts/logic.rep/om.ys\n    scripts/multivar.rep/code.ys\n    scripts/multivar.rep/code.ys.def\n    scripts/multivar.rep/makemulti.ys\n    scripts/multivar.rep/sparsenomial.ys\n    scripts/multivar.rep/sparsetree.ys\n    scripts/multivar.rep/sparsetree.ys.def\n    scripts/newly.rep/code.ys\n    scripts/newly.rep/code.ys.def\n    scripts/nintegrate.rep/code.ys\n    scripts/nintegrate.rep/code.ys.def\n    scripts/numbers.rep/GaussianIntegers.ys\n    scripts/numbers.rep/GaussianIntegers.ys.def\n    scripts/numbers.rep/NumberTheory.ys\n    scripts/numbers.rep/NumberTheory.ys.def\n    scripts/numbers.rep/code.ys\n    scripts/numbers.rep/code.ys.def\n    scripts/numbers.rep/nthroot.ys\n    scripts/numbers.rep/nthroot.ys.def\n    scripts/numbers.rep/om.ys\n    scripts/odesolver.rep/code.ys\n    scripts/odesolver.rep/code.ys.def\n    scripts/openmath.rep/code.ys\n    scripts/openmath.rep/code.ys.def\n    scripts/orthopoly.rep/code.ys\n    scripts/orthopoly.rep/code.ys.def\n    scripts/packages.ys\n    scripts/padic.rep/code.ys\n    scripts/padic.rep/code.ys.def\n    scripts/patterns.rep/code.ys\n    scripts/patterns.rep/code.ys.def\n    scripts/physics.rep/quantum/clebsch-gordan.ys\n    scripts/physics.rep/quantum/clebsch-gordan.ys.def\n    scripts/plots.rep/backends-2d.ys\n    scripts/plots.rep/backends-3d.ys\n    scripts/plots.rep/code.ys\n    scripts/plots.rep/code.ys.def\n    scripts/plots.rep/plot2d.ys\n    scripts/plots.rep/plot2d.ys.def\n    scripts/plots.rep/plot3d.ys\n    scripts/plots.rep/plot3d.ys.def\n    scripts/predicates.rep/code.ys\n    scripts/predicates.rep/code.ys.def\n    scripts/probability.rep/code.ys\n    scripts/probability.rep/code.ys.def\n    scripts/products.rep/code.ys\n    scripts/products.rep/code.ys.def\n    scripts/pslq.rep/code.ys\n    scripts/pslq.rep/code.ys.def\n    scripts/r_form.rep/code.ys\n    scripts/r_form.rep/code.ys.def\n    scripts/rabinmiller.rep/code.ys\n    scripts/rabinmiller.rep/code.ys.def\n    scripts/radsimp.rep/code.ys\n    scripts/radsimp.rep/code.ys.def\n    scripts/random.rep/code.ys\n    scripts/random.rep/code.ys.def\n    scripts/rational.rep/code.ys\n    scripts/rational.rep/code.ys.def\n    scripts/simplify.rep/code.ys\n    scripts/simplify.rep/code.ys.def\n    scripts/simplify.rep/factorial.ys\n    scripts/simplify.rep/factorial.ys.def\n    scripts/solve.rep/code.ys\n    scripts/solve.rep/code.ys.def\n    scripts/specfunc.rep/bernou.ys\n    scripts/specfunc.rep/bernou.ys.def\n    scripts/specfunc.rep/bessel.ys\n    scripts/specfunc.rep/bessel.ys.def\n    scripts/specfunc.rep/code.ys\n    scripts/specfunc.rep/code.ys.def\n    scripts/specfunc.rep/gamma.ys\n    scripts/specfunc.rep/gamma.ys.def\n    scripts/specfunc.rep/gammaconst.ys\n    scripts/specfunc.rep/gammaconst.ys.def\n    scripts/specfunc.rep/om.ys\n    scripts/specfunc.rep/zeta.ys\n    scripts/specfunc.rep/zeta.ys.def\n    scripts/standard.ys\n    scripts/standard.ys.def\n    scripts/statistics.rep/distributions.ys\n    scripts/statistics.rep/distributions.ys.def\n    scripts/statistics.rep/hypothesystest.ys\n    scripts/statistics.rep/hypothesystest.ys.def\n    scripts/statistics.rep/incompletegamma.ys\n    scripts/statistics.rep/incompletegamma.ys.def\n    scripts/statistics.rep/randomtest.ys\n    scripts/statistics.rep/regression.ys\n    scripts/statistics.rep/regression.ys.def\n    scripts/statistics.rep/statistics.ys\n    scripts/statistics.rep/statistics.ys.def\n    scripts/stats.rep/code.ys\n    scripts/stats.rep/code.ys.def\n    scripts/stdarith.ys\n    scripts/stdarith.ys.def\n    scripts/stdfuncs.rep/code.ys\n    scripts/stdfuncs.rep/code.ys.def\n    scripts/stdfuncs.rep/elemfuncs.ys\n    scripts/stdfuncs.rep/elemfuncs.ys.def\n    scripts/stdfuncs.rep/numerical.ys\n    scripts/stdfuncs.rep/numerical.ys.def\n    scripts/stdfuncs.rep/nummethods.ys\n    scripts/stdfuncs.rep/nummethods.ys.def\n    scripts/stdfuncs.rep/om.ys\n    scripts/stdopers.ys\n    scripts/stubs.rep/code.ys\n    scripts/stubs.rep/code.ys.def\n    scripts/stubs.rep/om.ys\n    scripts/substitute.rep/code.ys\n    scripts/substitute.rep/code.ys.def\n    scripts/sums.rep/code.ys\n    scripts/sums.rep/code.ys.def\n    scripts/sums.rep/om.ys\n    scripts/trigsimp.rep/code.ys.def\n    scripts/univar.rep/Cyclotomic.ys\n    scripts/univar.rep/Cyclotomic.ys.def\n    scripts/univar.rep/code.ys\n    scripts/trigsimp.rep/code.ys.def\n    scripts/univar.rep/Cyclotomic.ys\n    scripts/univar.rep/Cyclotomic.ys.def\n    scripts/univar.rep/code.ys\n    scripts/sums.rep/taylor.ys\n    scripts/sums.rep/taylor.ys.def\n    scripts/sums.rep/taylor3.ys\n    scripts/sums.rep/taylor3.ys.def\n    scripts/tensor.rep/code.ys\n    scripts/tensor.rep/code.ys.def\n    scripts/testers.rep/code.ys\n    scripts/testers.rep/code.ys.def\n    scripts/texform.rep/code.ys\n    scripts/texform.rep/code.ys.def\n    scripts/transforms.rep/code.ys\n    scripts/trigsimp.rep/code.ys.def\n    scripts/univar.rep/Cyclotomic.ys\n    scripts/univar.rep/Cyclotomic.ys.def\n    scripts/univar.rep/code.ys\n    scripts/transforms.rep/code.ys.def\n    scripts/trigsimp.rep/code.ys\n    scripts/trigsimp.rep/code.ys.def\n    scripts/univar.rep/Cyclotomic.ys\n    scripts/univar.rep/Cyclotomic.ys.def\n    scripts/univar.rep/code.ys\n    scripts/univar.rep/code.ys.def\n    scripts/univar.rep/sparse.ys\n    scripts/univar.rep/sparse.ys.def\n    scripts/univar.rep/sturm.ys\n    scripts/univar.rep/sturm.ys.def\n    scripts/yacasinit.ys)\n\nif (ENABLE_CYACAS)\n    install (DIRECTORY scripts/ DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/scripts COMPONENT app)\nendif ()\n\nif (ENABLE_DOCS)\n    add_subdirectory (docs)\n    add_subdirectory (man)\nendif()\n\nif (ENABLE_JYACAS)\n    add_subdirectory (jyacas)\nendif ()\n\nif (ENABLE_CYACAS)\n    add_subdirectory (cyacas)\nendif ()\n\nif (ENABLE_CYACAS OR ENABLE_JYACAS)\n    add_subdirectory (tests)\nendif ()\n"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "content": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.\n\n## Our Standards\n\nExamples of behavior that contributes to creating a positive environment include:\n\n* Using welcoming and inclusive language\n* Being respectful of differing viewpoints and experiences\n* Gracefully accepting constructive criticism\n* Focusing on what is best for the community\n* Showing empathy towards other community members\n\nExamples of unacceptable behavior by participants include:\n\n* The use of sexualized language or imagery and unwelcome sexual attention or advances\n* Trolling, insulting/derogatory comments, and personal or political attacks\n* Public or private harassment\n* Publishing others' private information, such as a physical or electronic address, without explicit permission\n* Other conduct which could reasonably be considered inappropriate in a professional setting\n\n## Our Responsibilities\n\nProject maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.\n\nProject maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.\n\n## Scope\n\nThis Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.\n\n## Enforcement\n\nInstances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at teoretyk@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.\n\nProject maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.\n\n## Attribution\n\nThis Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]\n\n[homepage]: http://contributor-covenant.org\n[version]: http://contributor-covenant.org/version/1/4/\n"
  },
  {
    "path": "COPYING",
    "content": "                  GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 2.1, February 1999\n\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n[This is the first released version of the Lesser GPL.  It also counts\n as the successor of the GNU Library Public License, version 2, hence\n the version number 2.1.]\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicenses are intended to guarantee your freedom to share and change\nfree software--to make sure the software is free for all its users.\n\n  This license, the Lesser General Public License, applies to some\nspecially designated software packages--typically libraries--of the\nFree Software Foundation and other authors who decide to use it.  You\ncan use it too, but we suggest you first think carefully about whether\nthis license or the ordinary General Public License is the better\nstrategy to use in any particular case, based on the explanations below.\n\n  When we speak of free software, we are referring to freedom of use,\nnot price.  Our General Public Licenses are designed to make sure that\nyou have the freedom to distribute copies of free software (and charge\nfor this service if you wish); that you receive source code or can get\nit if you want it; that you can change the software and use pieces of\nit in new free programs; and that you are informed that you can do\nthese things.\n\n  To protect your rights, we need to make restrictions that forbid\ndistributors to deny you these rights or to ask you to surrender these\nrights.  These restrictions translate to certain responsibilities for\nyou if you distribute copies of the library or if you modify it.\n\n  For example, if you distribute copies of the library, whether gratis\nor for a fee, you must give the recipients all the rights that we gave\nyou.  You must make sure that they, too, receive or can get the source\ncode.  If you link other code with the library, you must provide\ncomplete object files to the recipients, so that they can relink them\nwith the library after making changes to the library and recompiling\nit.  And you must show them these terms so they know their rights.\n\n  We protect your rights with a two-step method: (1) we copyright the\nlibrary, and (2) we offer you this license, which gives you legal\npermission to copy, distribute and/or modify the library.\n\n  To protect each distributor, we want to make it very clear that\nthere is no warranty for the free library.  Also, if the library is\nmodified by someone else and passed on, the recipients should know\nthat what they have is not the original version, so that the original\nauthor's reputation will not be affected by problems that might be\nintroduced by others.\n\f\n  Finally, software patents pose a constant threat to the existence of\nany free program.  We wish to make sure that a company cannot\neffectively restrict the users of a free program by obtaining a\nrestrictive license from a patent holder.  Therefore, we insist that\nany patent license obtained for a version of the library must be\nconsistent with the full freedom of use specified in this license.\n\n  Most GNU software, including some libraries, is covered by the\nordinary GNU General Public License.  This license, the GNU Lesser\nGeneral Public License, applies to certain designated libraries, and\nis quite different from the ordinary General Public License.  We use\nthis license for certain libraries in order to permit linking those\nlibraries into non-free programs.\n\n  When a program is linked with a library, whether statically or using\na shared library, the combination of the two is legally speaking a\ncombined work, a derivative of the original library.  The ordinary\nGeneral Public License therefore permits such linking only if the\nentire combination fits its criteria of freedom.  The Lesser General\nPublic License permits more lax criteria for linking other code with\nthe library.\n\n  We call this license the \"Lesser\" General Public License because it\ndoes Less to protect the user's freedom than the ordinary General\nPublic License.  It also provides other free software developers Less\nof an advantage over competing non-free programs.  These disadvantages\nare the reason we use the ordinary General Public License for many\nlibraries.  However, the Lesser license provides advantages in certain\nspecial circumstances.\n\n  For example, on rare occasions, there may be a special need to\nencourage the widest possible use of a certain library, so that it becomes\na de-facto standard.  To achieve this, non-free programs must be\nallowed to use the library.  A more frequent case is that a free\nlibrary does the same job as widely used non-free libraries.  In this\ncase, there is little to gain by limiting the free library to free\nsoftware only, so we use the Lesser General Public License.\n\n  In other cases, permission to use a particular library in non-free\nprograms enables a greater number of people to use a large body of\nfree software.  For example, permission to use the GNU C Library in\nnon-free programs enables many more people to use the whole GNU\noperating system, as well as its variant, the GNU/Linux operating\nsystem.\n\n  Although the Lesser General Public License is Less protective of the\nusers' freedom, it does ensure that the user of a program that is\nlinked with the Library has the freedom and the wherewithal to run\nthat program using a modified version of the Library.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.  Pay close attention to the difference between a\n\"work based on the library\" and a \"work that uses the library\".  The\nformer contains code derived from the library, whereas the latter must\nbe combined with the library in order to run.\n\f\n                  GNU LESSER GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License Agreement applies to any software library or other\nprogram which contains a notice placed by the copyright holder or\nother authorized party saying it may be distributed under the terms of\nthis Lesser General Public License (also called \"this License\").\nEach licensee is addressed as \"you\".\n\n  A \"library\" means a collection of software functions and/or data\nprepared so as to be conveniently linked with application programs\n(which use some of those functions and data) to form executables.\n\n  The \"Library\", below, refers to any such software library or work\nwhich has been distributed under these terms.  A \"work based on the\nLibrary\" means either the Library or any derivative work under\ncopyright law: that is to say, a work containing the Library or a\nportion of it, either verbatim or with modifications and/or translated\nstraightforwardly into another language.  (Hereinafter, translation is\nincluded without limitation in the term \"modification\".)\n\n  \"Source code\" for a work means the preferred form of the work for\nmaking modifications to it.  For a library, complete source code means\nall the source code for all modules it contains, plus any associated\ninterface definition files, plus the scripts used to control compilation\nand installation of the library.\n\n  Activities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning a program using the Library is not restricted, and output from\nsuch a program is covered only if its contents constitute a work based\non the Library (independent of the use of the Library in a tool for\nwriting it).  Whether that is true depends on what the Library does\nand what the program that uses the Library does.\n\n  1. You may copy and distribute verbatim copies of the Library's\ncomplete source code as you receive it, in any medium, provided that\nyou conspicuously and appropriately publish on each copy an\nappropriate copyright notice and disclaimer of warranty; keep intact\nall the notices that refer to this License and to the absence of any\nwarranty; and distribute a copy of this License along with the\nLibrary.\n\n  You may charge a fee for the physical act of transferring a copy,\nand you may at your option offer warranty protection in exchange for a\nfee.\n\f\n  2. You may modify your copy or copies of the Library or any portion\nof it, thus forming a work based on the Library, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) The modified work must itself be a software library.\n\n    b) You must cause the files modified to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    c) You must cause the whole of the work to be licensed at no\n    charge to all third parties under the terms of this License.\n\n    d) If a facility in the modified Library refers to a function or a\n    table of data to be supplied by an application program that uses\n    the facility, other than as an argument passed when the facility\n    is invoked, then you must make a good faith effort to ensure that,\n    in the event an application does not supply such function or\n    table, the facility still operates, and performs whatever part of\n    its purpose remains meaningful.\n\n    (For example, a function in a library to compute square roots has\n    a purpose that is entirely well-defined independent of the\n    application.  Therefore, Subsection 2d requires that any\n    application-supplied function or table used by this function must\n    be optional: if the application does not supply it, the square\n    root function must still compute square roots.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Library,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Library, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote\nit.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Library.\n\nIn addition, mere aggregation of another work not based on the Library\nwith the Library (or with a work based on the Library) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may opt to apply the terms of the ordinary GNU General Public\nLicense instead of this License to a given copy of the Library.  To do\nthis, you must alter all the notices that refer to this License, so\nthat they refer to the ordinary GNU General Public License, version 2,\ninstead of to this License.  (If a newer version than version 2 of the\nordinary GNU General Public License has appeared, then you can specify\nthat version instead if you wish.)  Do not make any other change in\nthese notices.\n\f\n  Once this change is made in a given copy, it is irreversible for\nthat copy, so the ordinary GNU General Public License applies to all\nsubsequent copies and derivative works made from that copy.\n\n  This option is useful when you wish to copy part of the code of\nthe Library into a program that is not a library.\n\n  4. You may copy and distribute the Library (or a portion or\nderivative of it, under Section 2) in object code or executable form\nunder the terms of Sections 1 and 2 above provided that you accompany\nit with the complete corresponding machine-readable source code, which\nmust be distributed under the terms of Sections 1 and 2 above on a\nmedium customarily used for software interchange.\n\n  If distribution of object code is made by offering access to copy\nfrom a designated place, then offering equivalent access to copy the\nsource code from the same place satisfies the requirement to\ndistribute the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  5. A program that contains no derivative of any portion of the\nLibrary, but is designed to work with the Library by being compiled or\nlinked with it, is called a \"work that uses the Library\".  Such a\nwork, in isolation, is not a derivative work of the Library, and\ntherefore falls outside the scope of this License.\n\n  However, linking a \"work that uses the Library\" with the Library\ncreates an executable that is a derivative of the Library (because it\ncontains portions of the Library), rather than a \"work that uses the\nlibrary\".  The executable is therefore covered by this License.\nSection 6 states terms for distribution of such executables.\n\n  When a \"work that uses the Library\" uses material from a header file\nthat is part of the Library, the object code for the work may be a\nderivative work of the Library even though the source code is not.\nWhether this is true is especially significant if the work can be\nlinked without the Library, or if the work is itself a library.  The\nthreshold for this to be true is not precisely defined by law.\n\n  If such an object file uses only numerical parameters, data\nstructure layouts and accessors, and small macros and small inline\nfunctions (ten lines or less in length), then the use of the object\nfile is unrestricted, regardless of whether it is legally a derivative\nwork.  (Executables containing this object code plus portions of the\nLibrary will still fall under Section 6.)\n\n  Otherwise, if the work is a derivative of the Library, you may\ndistribute the object code for the work under the terms of Section 6.\nAny executables containing that work also fall under Section 6,\nwhether or not they are linked directly with the Library itself.\n\f\n  6. As an exception to the Sections above, you may also combine or\nlink a \"work that uses the Library\" with the Library to produce a\nwork containing portions of the Library, and distribute that work\nunder terms of your choice, provided that the terms permit\nmodification of the work for the customer's own use and reverse\nengineering for debugging such modifications.\n\n  You must give prominent notice with each copy of the work that the\nLibrary is used in it and that the Library and its use are covered by\nthis License.  You must supply a copy of this License.  If the work\nduring execution displays copyright notices, you must include the\ncopyright notice for the Library among them, as well as a reference\ndirecting the user to the copy of this License.  Also, you must do one\nof these things:\n\n    a) Accompany the work with the complete corresponding\n    machine-readable source code for the Library including whatever\n    changes were used in the work (which must be distributed under\n    Sections 1 and 2 above); and, if the work is an executable linked\n    with the Library, with the complete machine-readable \"work that\n    uses the Library\", as object code and/or source code, so that the\n    user can modify the Library and then relink to produce a modified\n    executable containing the modified Library.  (It is understood\n    that the user who changes the contents of definitions files in the\n    Library will not necessarily be able to recompile the application\n    to use the modified definitions.)\n\n    b) Use a suitable shared library mechanism for linking with the\n    Library.  A suitable mechanism is one that (1) uses at run time a\n    copy of the library already present on the user's computer system,\n    rather than copying library functions into the executable, and (2)\n    will operate properly with a modified version of the library, if\n    the user installs one, as long as the modified version is\n    interface-compatible with the version that the work was made with.\n\n    c) Accompany the work with a written offer, valid for at\n    least three years, to give the same user the materials\n    specified in Subsection 6a, above, for a charge no more\n    than the cost of performing this distribution.\n\n    d) If distribution of the work is made by offering access to copy\n    from a designated place, offer equivalent access to copy the above\n    specified materials from the same place.\n\n    e) Verify that the user has already received a copy of these\n    materials or that you have already sent this user a copy.\n\n  For an executable, the required form of the \"work that uses the\nLibrary\" must include any data and utility programs needed for\nreproducing the executable from it.  However, as a special exception,\nthe materials to be distributed need not include anything that is\nnormally distributed (in either source or binary form) with the major\ncomponents (compiler, kernel, and so on) of the operating system on\nwhich the executable runs, unless that component itself accompanies\nthe executable.\n\n  It may happen that this requirement contradicts the license\nrestrictions of other proprietary libraries that do not normally\naccompany the operating system.  Such a contradiction means you cannot\nuse both them and the Library together in an executable that you\ndistribute.\n\f\n  7. You may place library facilities that are a work based on the\nLibrary side-by-side in a single library together with other library\nfacilities not covered by this License, and distribute such a combined\nlibrary, provided that the separate distribution of the work based on\nthe Library and of the other library facilities is otherwise\npermitted, and provided that you do these two things:\n\n    a) Accompany the combined library with a copy of the same work\n    based on the Library, uncombined with any other library\n    facilities.  This must be distributed under the terms of the\n    Sections above.\n\n    b) Give prominent notice with the combined library of the fact\n    that part of it is a work based on the Library, and explaining\n    where to find the accompanying uncombined form of the same work.\n\n  8. You may not copy, modify, sublicense, link with, or distribute\nthe Library except as expressly provided under this License.  Any\nattempt otherwise to copy, modify, sublicense, link with, or\ndistribute the Library is void, and will automatically terminate your\nrights under this License.  However, parties who have received copies,\nor rights, from you under this License will not have their licenses\nterminated so long as such parties remain in full compliance.\n\n  9. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Library or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Library (or any work based on the\nLibrary), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Library or works based on it.\n\n  10. Each time you redistribute the Library (or any work based on the\nLibrary), the recipient automatically receives a license from the\noriginal licensor to copy, distribute, link with or modify the Library\nsubject to these terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties with\nthis License.\n\f\n  11. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Library at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Library by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Library.\n\nIf any portion of this section is held invalid or unenforceable under any\nparticular circumstance, the balance of the section is intended to apply,\nand the section as a whole is intended to apply in other circumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  12. If the distribution and/or use of the Library is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Library under this License may add\nan explicit geographical distribution limitation excluding those countries,\nso that distribution is permitted only in or among countries not thus\nexcluded.  In such case, this License incorporates the limitation as if\nwritten in the body of this License.\n\n  13. The Free Software Foundation may publish revised and/or new\nversions of the Lesser General Public License from time to time.\nSuch new versions will be similar in spirit to the present version,\nbut may differ in detail to address new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Library\nspecifies a version number of this License which applies to it and\n\"any later version\", you have the option of following the terms and\nconditions either of that version or of any later version published by\nthe Free Software Foundation.  If the Library does not specify a\nlicense version number, you may choose any version ever published by\nthe Free Software Foundation.\n\f\n  14. If you wish to incorporate parts of the Library into other free\nprograms whose distribution conditions are incompatible with these,\nwrite to the author to ask for permission.  For software which is\ncopyrighted by the Free Software Foundation, write to the Free\nSoftware Foundation; we sometimes make exceptions for this.  Our\ndecision will be guided by the two goals of preserving the free status\nof all derivatives of our free software and of promoting the sharing\nand reuse of software generally.\n\n                            NO WARRANTY\n\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\nDAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\f\n           How to Apply These Terms to Your New Libraries\n\n  If you develop a new library, and you want it to be of the greatest\npossible use to the public, we recommend making it free software that\neveryone can redistribute and change.  You can do so by permitting\nredistribution under these terms (or, alternatively, under the terms of the\nordinary General Public License).\n\n  To apply these terms, attach the following notices to the library.  It is\nsafest to attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least the\n\"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the library's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This library is free software; you can redistribute it and/or\n    modify it under the terms of the GNU Lesser General Public\n    License as published by the Free Software Foundation; either\n    version 2.1 of the License, or (at your option) any later version.\n\n    This library is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n    Lesser General Public License for more details.\n\n    You should have received a copy of the GNU Lesser General Public\n    License along with this library; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n\nAlso add information on how to contact you by electronic and paper mail.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\n\n  <signature of Ty Coon>, 1 April 1990\n  Ty Coon, President of Vice\n\nThat's all there is to it!\n"
  },
  {
    "path": "ChangeLog",
    "content": "\nChanges are none, there is only the now.\n"
  },
  {
    "path": "README.rst",
    "content": "=====\nyacas\n=====\n\n.. image:: https://img.shields.io/badge/license-LGPL--2.1%2B-blue.svg\n    :target: ./COPYING\n\n.. image:: https://ci.appveyor.com/api/projects/status/r8gm1gdk61qe4rgd?svg=true\n    :target: https://ci.appveyor.com/project/grzegorzmazur/yacas\n\n.. image:: http://readthedocs.org/projects/yacas/badge/?version=latest\n    :target: http://yacas.readthedocs.org/en/latest/?badge=latest\n\n.. image:: https://api.codacy.com/project/badge/Grade/a66fdf5a0140492f9c6eee6c5ba18bd4\n    :target: https://www.codacy.com/manual/teoretyk/yacas?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=grzegorzmazur/yacas&amp;utm_campaign=Badge_Grade\n\n.. image:: https://codecov.io/gh/grzegorzmazur/yacas/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/grzegorzmazur/yacas\n\nYacas (Yet Another Computer Algebra System) is a small and highly flexible\ngeneral-purpose Computer Algebra System (CAS). The syntax uses an\ninfix-operator grammar parser. The distribution contains a small library\nof mathematical functions, but its real strength is in the language in which\nyou can easily write your own symbolic manipulation algorithms. The core engine\nsupports arbitrary precision arithmetic and is able to execute symbolic\nmanipulations on various mathematical objects by following user-defined rules.\nFor detailed information on yacas features and usage, see\n`<http://www.yacas.org>`_.\n\n=====\nwho is yacas for?\n=====\n\nThis versatile Computer Algebra System (CAS) was developed to cater to a broad\naudience, primarily consisting of mathematicians, engineers, and students. It \nprovides a user-friendly platform for performing symbolic mathematical computations, \nsolving intricate equations, all accessible via a command-line interface. \nFurthermore, it serves as a free alternative to commercial CAS software.\n\nFor mathematics enthusiasts (probably less than 1% of the population), \nthis tool offers the capability to conduct advanced mathematical manipulations\nand solve complex equations, making it valuable for research purposes and even \nrecreational mathematical exploration.\nOn the other hand, students can benefit from its educational potential, \nusing it as an open-source resource to learn and practice mathematics while \nexperiencing the advantages of an open-source product like Yacas.\n\n\n=====\nGetting Started\n=====\n\nStep by step guide to understand what yacas is about and start using it `<https://yacas.readthedocs.io/en/latest/getting_started/index.html>`_\n\n=====\nDownloads\n=====\n\nYacas is available for a variety of platforms. See\n`<http://www.yacas.org/getting_started/downloads/>`_ \nfor binary packages and installation instructions.\n\n=====\nScreenshots\n=====\n\nFor a preview on how yacas looks like\n`<http://www.yacas.org/getting_started/screenshots/>`_ \n\n=====\nContact\n=====\n\nReport bugs or great enhancements ideas to our issue tracker `<https://github.com/grzegorzmazur/yacas/issues>`_\n\nWe have a forum to talk math! `<https://groups.google.com/g/yacas>`_\n\nFAQ `<http://www.yacas.org/getting_started/faq/>`_\n\nYacas is distributed under the GNU LESSER GENERAL PUBLIC LICENSE v2.1 or, at\nyour discretion, any later version.\n"
  },
  {
    "path": "TODO",
    "content": "TODO:\n- Manual titles do not correspond with the manual you go to.\n\n- Ceil, Round and Floor, also try to force to a number.\n\n- From Laurent Debacker:\n  In file scripts/integrate.rep/code.ys, shouldn't the\n    IntFunc(x,(_x)^(-1),Ln(x));\n  be\n    IntFunc(x,(_x)^(-1),Ln(Abs(x)));\n  My motivation is based on http://metric.ma.ic.ac.uk/integration/techniques/indefinite/standard-integrals/integral-of-one-over-x/index.html .\n\n- Remove the examples directory from the scripts directory, placing them somewhere else to reduce jar file size.\n- Use reflection to look up methods, will make the jar file smaller.\n\n- make the default read-eval-print loop print to out on the go, at least for the off-line version.\n\n- do a cleanup of the \"ref\" manual, first pass to throw away functions that should not have been there in the first place.\n- second chapter in refprog titled \"Programming\" has way too many functions\n- chapter \"List operators\" has way too many function entries.\n- chapter \"Control flow\" has entries relating only to the off-line version\n- chapter \"predicates\" has way too many function entries.\n- chapter \"Input/output and plotting\" has way too many function entries.\n- chapter \"Number theory\" needs to be cleaned up.\n- do a cleanup of the other books also\n\n- scripts/examples/ do somewhere else?\n\n- examples should have their own tests\n\n- Test suite fails on Java version. We *have* to make the test suite more lenient.\n- Remove Fast* (does not seem to be used anywhere). FastArcSin, FastAssoc, FastIsPrime, FastLog, FastPower do seem to be used.\n- get rid of the Ortho?Sum functions, replace with just one?\n- (find other ...Num functions)\n- NewtonNum\n\n- Future, change name of builtin functions that are not directly accessible to outside to have prefix Builtin'...\n- Skim through Math... functions, renaming them to Builtin'...\n- manuals, provide as zip files? more people can use unzip than can use untar.\n\n\n\n- cos(arccos(x)) -> x+k*2*pi etc\n \n- try if I can't change the format of numbers from 0.xxx to x.xxxx, is more natural\n- make plain site not too wide also\n- Move brackets slightly down in tex form pretty renderer, especially when what they bracket is not too big.\n- step-by-step solver possible?\n- screenshots, explanation of how to use, demo, tipbox, or *something*, to persuade people to enter something in the search field\n- carefully change things so that the scripts do not have things like \"N(Eval(\" any more (just grep on it).\n\n1) Documentation improvements\n- examples embedded in the manual\n- document \":test\" to run test code from article\n- link to mark-up documentation from the editors.\n- what is Yacas? How did it come into existence? Why did I write it? Who is it for?\n- mention  the use of lists for passing multiple arguments.\n============================================================================================================\n- document the algorithms used, and expand on all of the functions currently implemented.\n- separate manual chapter on tensors. (Serge? Is it going to change?). TSimplify and TExplicitSum, TD, X\n- document the source code.\n- document HoldArg in combination with <-- (or actually remove HoldArg? I want to depreciate UnFence/HoldArg in favor of macros)\n- document II, ReII, ImII, IsComplexII\n- document ExpressionDepth, PAdicExpandInternal, GetPrimeFactors, Rem, Roots, Apart, Together\n- document UnHoldable, GcdReduce, ApplyPure, DestructiveAppendList, Pattern'Matches, Pattern'Create, RuleBaseDefined, Lambda (in combination with Apply), Primes, MapArgs, Substitute,\n- document %, |, &, ^, if, else (else binds to the last if)\n- document DivPoly, RootsWithMultiples,\n- document OdeSolve\n- document Dimensions, IsSquareMatrix, Tr.\n- document Deriv, Berlekamp, ExtendedEuclidean, ExtendedEuclideanMonic\n- document IsVariable\n- document the fact that VarList can also be called with a second argument, a filter predicate.\n- document Extended predicates in the pattern matcher (needs to be explained).\n- document DefaultTokenizer()\n- document XmlTokenizer, XmlExplodeTag\n- document BSearch, FindIsq Search for a zero in a monotonously growing function. BSearch returns -1 if not found, FindIsq returns the insertion point.\n- document MultiDivide, MultiGcd, Groebner\n- document DefLoadFunction\n- document CharString (input integer, output a string with one char, using the ascii code passed in).\n- document FloatIsInt\n- document Explain what is destructive about the Destructive... routines, why they are there, and when to use them.\n- document Do slightly more on pure functions, to show why they are useful. Show for example Select.\n- document Explain what Simplify currently does (internal algorithm).\n- document The PcreLexer and PcreNextToken functions\n- document Small summary of regular expressions syntax accepted.\n- document Html... commands.\n- document some blurb on the pattern matching/multivirtual functionality.\n- Clean up integration code, and document algorithm used.\n- document the extra Is... predicates for matrices that was added by Jonathan\n- document threaded use of integration\n\n2) Web site improvements\n- allow saving multiple programs in cookies\n- work through mommies feedback\n  - computer calculations made easy zou ik in lijn met het logo plaatsen liefst in lijn met de groene balletjes. Nu zweeft het een beetje los.\n  - Get Yacas en contact us is goed, maar ik zou het wat lager plaatsen in lijn met de tabs, maar wel zo laten als tekst links.\n- Explain that a connection to the server is not needed, and that Yacas can be run off-line (with a link to a download of the Yacas web site).\n============================================================================================================\n- should I reconsider the way things are compressed? tgz? Why not zip?\n- when leaving codeedit page, ask to remember code?\n- think through wat it would look like if you could add content\n- make all screens go 100% (edit, tutorial?) or at least center?\n- create a clickable program snippet that is other than a one-liner (?)\n- ideally programs should be uploaded to the datahub from the example\npages themselves, and not from recent.html, but for some reason that did\nnot work. When going from deeply-linked, trying it out does not work any\nmore and editing it also not.\n- make descr/view/edit pages not reload, but refresh content dynamically\n- In the tutorial, at \"Solve\", show how to verify that results are correct\n\n3) Research\n- Scan through my articles\n- scan through examples already in examples directory in scripts dir\n- take a look at Axiom code\n- take a look at Maxima code\n============================================================================================================\n- Think through series of articles on tensors.\n- Quaternions example?\n- Example: the logarithmic derivative example from Fateman is nice.\n- example: inverse, integrate taylor of 1/f'\n- example: generating a polynomial solution for an ordinary DE\n- For fun: try to understand Hensel lifting, and can it be made to apply\nto say Feynman diagrams?\n\n5) Math improvements\n============================================================================================================\n- allow control over formatting of floats.\n- bumping up a version number seems to force a recompile of all the C++ files, config.h rewritten or so?\n- make all the code more consistent, assuming that variables are real-valued.\n- remove use of UnFence/HoldArg in favor of macros\n- after use of UnFence/HoldArg has been removed, remove support for it\n- local transforms: postpredicates do not seem to work any more.\n- pattern matcher that can work on rings\n- Change the system to use the II way of dealing with complex numbers in\nfavor of the Complex(r,i) construct.\n- When the change to the II way of doing complex numbers is finished, add\nit to the tutorial (if not already there), and change the manual\naccordingly\n- replace perl code in favor of C++ code, easier to maintain.\n- sparserep from multi, use for uni too\n- lists/arrays interchangable\n- remove all uses of local files/directories.\n- global var access, test code using a function to return a list of global\nvariables.\n- Clean up Solve code, and document algorithm used.\n- remove the final references to stdlib in the code.\n- put Nl() in a common place (if it is still defined in different places\nor an odd place).\n- test Apart for polys. This might have to be adjusted by adding using the\nsame mechanism used for the integer version.\n- Taylor on functions containing Abs/Sign can not be trusted (no idea what\nI meant by that, but worth checking).\n- Define the Local,.. functions based on their Macro counterparts, in the\nscripts.\n- also define a Head and Tail for arrays, and append/concat/\ninsert/delete/copy. This will ease swapping between lists and arrays.\n- Allow for type convertors in pattern matchers. For instance: IsUniVar,\nshould be combined with CanBeUni and NormalForm to get the correct one\nback.\n- A RuleBaseDefined-like function that returns a list of defined arities.\n- FindZeroes (polynoms and other functions)\n- redivide some code ('newly')\n- make suchthat more powerful, so it simplifies sin(x)=cos(x) to tan(x)=1\nto x=Pi/4\n- groebner bases\n- see if using arrays for matrices speeds up things.\n- Fix CanBeUni so that it deals correctly with 1/c\n- EquateCoefs equate coefficients in two polys, and return as list.\n- document /. and /:: with <-\n- allow solve to return a list usable in /.\n- matrix^negative is inverse^positive\n\n6) Bugs:\n============================================================================================================\n- some limits not working correctly when using infinity: Limit(x,Infinity)\nZeta(x)\n- factorize not checking for correctness of arguments:\nFactorize(Infinity), Factorize(-1)\n- Limit(x,0)D(x,2)Sin(x)/x never terminates (or rather takes a very long\ntime), which in turn causes Taylor(x,0,5)Sin(x)/x to never terminate.\n- Limit(x,Infinity) x^n/Ln(x) returns n*Infinity, should be Infinity\n- Limit(x,0,Right) x^( Ln(a)/(1+Ln(x)) ) returns 1, should be \"a\"\n- [A:={{1,2,3,4},{0,1,2,3},{0,0,1,2},{I,0,I,I}}; EigenValues(A);] hangs\n- L'Hopital's theorem is not always the correct thing to do. There\nis a paper by Richardson, Salvy et al \"Asymptotic expansions of exp-log\nfunctions\" that may be helpful.\n- TrigSimpCombine(x^500)' exhausts the stack\n- 'Solve(Exp(x^2)==Exp(x),x)' yields {} instead of {0,1}.\n- BUG: InverseTaylor not working correctly for Sin and Tan???\n- BUG: complex^float.\n- Mod(a,b) generates some \"UniVariate()\" calls if a and b are undefined (I\nexpected it to return unevaluated). If one of them is defined, and the\nother undefined, Mod() returns some numbers. Mod(x,-3) returns\nunevaluated. I'm not sure what the \"correct\" meaning of Mod is for\nnegative moduli bases, but the answer should in any case be non-negative.\nMod(a,b) is defined as the smallest non-negative number c such that a-c is\ndivisible by b.\n- Simplify(4-x-y) returns 4-y-x, Simplify(4-y-x) returns 4-x-y\n\n- Functions to be implemented in the Java version still:\n  - LispFastMod\n  - YacasDllLoad\n  - LispPatchLoad\n  - LispPatchString\n  - Some more functions that are defined in yacasmain.cpp: Exit, IsExitRequested, HistorySize, StaSiz, IsPromptShown, ReadCmdLineString, FileSize\n  - LispDefaultTokenizer\n  - LispCommonLispTokenizer\n  - LispXmlTokenizer\n  - LispExplodeTag\n  - LispCustomEval\n  - LispCustomEvalExpression\n  - LispCustomEvalResult\n  - LispCustomEvalLocals\n  - LispCustomEvalStop\n  - LispTraceRule\n  - LispTraceStack\n- command line flags for Java console version, useful for doing the test scripts\n- Supporting the default read-eval-print loop from script in Java?\n- Run the tests from Java\n- Give some performance statistics on comparison between Java and C++\n\n8) Unsorted:\n============================================================================================================\n- Search for defines I want to remove\n- Document TeXFormMaxPrec()\n- Document DefFileList()\n- check that unnecessary scripts are not loaded unnecessarily (in debug mode?)\n- Document FormulaMaxWidth()\n- Document SetFormulaMaxWidth(width)\n- Document the debugging facilities in the debug version, warnings on setting global variables etcetera.\n- Global variables are still used in the wester test file\n- Global variables are still used in the scripts that build the manuals\n- Global variables are still used in the scripts that create the plugin stubs\n- Global variables are still used in the scripts that compile/create for example libmath.cpp\n- Is there not enough in common between the different files platfileio.h that we should perhaps consider merging them?\n- For N, Verbose, etcetera, in stead of LocalSymbols guarding scope, perhaps a macro that generalizes the concept (with getters and setters, for a type of expandable singleton).\n- have the application work in a directory structure that is identical to the source tree. --rootdir should be more general (set it and you can find the documentation also, etcetera).\n- plotting functions are extremely verbose, this code needs to be reduced I feel\n- other os-ish modules that I think are ugly, ShowPS ? Tries to write to /tmp/? \n- examples direcory in scripts/, needed?\n- allow sending openmath expressions and receiving them from a socket.\n  - allow parsing without having to require a ;\n  - removing ] from output\n- Remove MacroSet/MacroClear and friends in favor of macros? makes the whole system simpler, and easier to compile.\n- Erf does not work for numbers larger than one but not too large.\n-  http://www.causascientia.org/math_stat/Dists/Compendium.pdf\n- remove TODOs in the source code\n- document as of yet undocumented functions\n- Try Yacas from some other applet, as a scripting language\n- Try out MapReduce\n- allow for a custom REP loop in server mode (would actually be trivial when sockets are defined in Yacas language)\n- Mention MultiGcd in the documentation where polynomial operations are explained.\n- make sure there are no collisions (axiom link in links.html for example) ???\n- change all references to LISP in to YACAS, and Lisp in to Yacas\n- univar.rep/Cyclotomic.ys is the only file to start with a capital (perhaps change to lower case?)\n- some garbage (double defined functions) I'd like to remove from univar\n- Taylor series expansion of Tan is slow, use other form for derivative?\n- Solve: see if I can recreate HEQS?\n- YacasInterpreter: also allow it to work from an applet?\n- Write test for Solve({mean==(A/(A+B)),variance==((A*B)/(((A+B)^2) * (A+B+1)))},{A,B})\n- There are warnings about YacasBase not having a virtual destructor, problem?\n- document the behavior of underscores in Yacas.\n- Clebsch-Gordan coefficients:\n  - Get Clebsch-Gordan code in to the main Yacas distribution.\n  - Test code for Clebsch-Gordan\n  - documentation for Clebsch-Gordan\n- document *how* the random number generators work.\n- -pc flags should also withhold the In> and Out> printing. Document that you need to use --read-eval-print \"\"\n- http://centaur.maths.qmul.ac.uk/Computer_Algebra/MathAlgs/mathalgs.pdf\n- restructure the documentation (there are a lot of unfinished parts written by Ayal).\n- rewrite anumber, and document it this time.\n- implement precision tracking the way Serge wants it, in the anumber version of BigNumber\n- slowness of Taylor, due to its trivial implementation. Perhaps we should do something about this as soon as we have series calculus.\n- Solve is way too simplistic.\n- (Is this still true?) MatchAtom still compares atoms by string representation! It should raise an error if you define a pattern with a float in it.\n\n\n============================================================================================================\n9) Article fodder:\n\nUI to search solution spaces\n============================\nComputers have made many laborious tasks easier to do. You can look up mathematical things in a database-ish way, or have the computer do repetitive work. There are more things computers are good at. Because you can design a user interface, you can design how it interacts with humans, you can effectively design a custom tool for a task. \n\nWhen  I did my internship (high-energy physics, Zeus, 1995-1996, at NIKHEF H) I used a user interface to get more results. The task at hand with high-energy physics is as follows; you have this massive accelerator that accelerates particles in a tube. The accelerated particle beams collide, and out of the collision come other particles. The particles that come out of it can tell you something about the structure of the particles that collided. Now at the point where the collision takes place people place what they call a detector. This detector detects particles coming from the collision. The collisions occur at enormous rates, so you get an enormous amount of data coming from these detectors. Any way, the data is filtered a bit (the amount of data coming from these detectors is so vast that one can not possibly hope to capture all of it, so electronics boards are designed to be able to handle the high bandwidth of data and filter out the events for which it is absolutely sure that the researchers will not be interested in it, reducing the amount of data captured), and then ends on a harddisk somewhere, in what they call (or used to call, don't know how it works nowadays) ntuples, essentially one big database table with rows of records, each record with some fields. Each row is an isolated event that might be of interest. Now the trick is to make a selection of the events, and plot a certain number. For example, one could take all the events where the electron (one of the incoming particles) scattered heavily backwards, and then plot the mass of the whole system, as in a histogram, where you accumulate the results of events with mass between two values in one bin, mass between other values in the next bin, etcetera. You would then see a sea of noise, with hopefully a peak in it, which would be called a \"resonance\", and would indicate that there had been a short-lived particle with that mass. The narrower the peak, the longer-lived the particles. The wider the peak, the shorter-lived the particles. This way you could measure the speed at which they decayed, which you can also calculate from theory sometimes, or at least use as an input parameter for theory. And you could measure the precise point of the top, so as to give you the mass of the particle. And you could count the number of events that were in the peak, and again compare that to theory, which should be able to give a prediction of the amount of events that were observed given the intensity of the beams colliding against each other. The trick would be to find the area where the resonance (the peak) should be, and try to design filters that reduce the background noise while keeping as much as possible of the signal. The filters would be simple things (often referred to as <i>cuts</i>, as they cut out a part of the data). For example, you could select all the events for which a specific value in one of the fields of the ntuple was larger than a certain value. Or smaller than a specific value. Large part of the work consisted of just trial-and-error, finding the good cuts to apply as to get the best view on the resonance. The cut to apply was the real information being sought. It required hard work, putting in many many many hours. The more hours you worked, the more likely you were to find something interesting. Being smart is not enough in such a case, as luck plays a big role (as they say, luck is when opportunity meets preparation). After you found the best cuts to apply to the data, it was surprisingly little information you needed to communicate. It could be as little as just a few conditionals, selecting all the events with, say, a detected electron, and where the virtual photon had a larger energy than such and so, and ... Surprisingly hard work for so little information. One would then proceed to get an estimate of the curve representing the noise, and subtract that from the data, to arrive at the pure signal.\n\nA good estimate of the total noise is then subtracted from the total data in what is hoped to then be the resulting signal of the resonance being sought. The task is thus essentially just to count how often something happened, and to try to make a wise selection of the events to look at.\n\n<make a drawing explaining the noise versus signal>\n\nOne problem I encountered during my internship was that due to the fact that there was just such a vast amount of data, each time I wanted to change a cut, you had to wait forever (10 minutes sometimes), for the result. You would wander off and do something else, and come back to the window where you were trying the cut, wondering what it was again you were trying out. It all just moved very slow.\n\nSo one weekend I resolved to make a nice little tool to make my life easier. The entire group worked on a Silicon Graphics workstation at that time, which apparently had cost the equivalent of 150,000.00 euros, and carried an astonishing 256 megabytes of RAM. Twelve people worked on that. Chances are you are now reading this article on a computer that cost a fraction of that machine, and has many times more memory than we had back then. And we were doing cutting edge research! But I digress.\n\nI used what knowledge I had already gleaned from the data to make a stricter selection on the data. What resulted was something like 38 megabytes of data remaining. What I then did was load that all in to memory (I waited until every one had gone home so I had the full system to myself, one advantage of working on big iron). In addition, I kept an index of each field, and sorted the records per that field, in that index. Now, I created a little user interface that would show a graph, histogram, of the counts of number of events per bin. And I defined scrollbars that allowed me to define ranges from within to select data. Those were effectively two cuts, one to the left and one to the right, limiting the amount to fall within a range of two values, a<x<b. I defined that for certain fields that I thought might give me the results I was looking for (in hindsight, I was already close to finding the right cuts any way, this tool just made me find it faster, but more on that later). For each event, I would keep a reference count. The reference count would start at zero, but as soon as the event fell outside of the selection, the reference count would be increased by one. When it fell from outside a selection to inside a selection again, the count would be decreased. When the scrollbar got dragged, I would only have to visit a few of the events, as I had a sorted index of them. Moreover, for each event, I could then remove it from the bin count if its reference count became nonzero, and add it to the bin again if the reference count became zero again.\n\nThe above allowed me to go through the data with breakneck speed. I could dynamically change cuts and see the result a split-second later, where previously I would have had to wait for ten minutes sometimes. My internship was already a success because I had found the resonance I was looking for. But with the tool I was able to find two more resonances on the Monday morning following the weekend in which I had coded up the tool. Unfortunately, I later found out that other researchers had already found these resonances, but they must have only found them a short period before I did, as I hadn't found any publications yet when I found the resonances. If memory serves (it is more than ten years ago now) the cuts they found were different, but could probably be shown to be roughly equivalent to what I had found. I had dramatically increased the amount of space I could search per unit of time, increasing the chance of finding something interesting accordingly. \n\nThe point I want to make in this article that there might actually be a place for such tools in science. There might be a place for graphical user interfaces. Obviously they do not merit real new knowledge about nature, and would thus not merit a scientific publication, but as a tool they could be very useful. At the end of the day, research is about finding new things, and because what you are looking for is effectively unknown, you proceed by trial and error. And the more you try and the more you err, the more chance you have to accidentally run in to something interesting. With a graphical user interface you can make a custom tool that allows you to search a much much much larger space. With the example given in this article I went mining through data but one can equally make a tool that allows one to search in the world of platonic beauty, to discover new objects in the platonic world. Because such a tool could potentially make you much more productive, effectively making you in to many many researchers as you become as productive as many researchers. Moreover, this is an under-researched area, not many scientists looking at this. Fair enough, you would not be able to publish an article on how the tool works. Just the results of applying the tools yourself. But there is possibly something interesting to be found here. I can not help but wonder what great names from the past would have done had they had access to computers. Would they have used computers to do their work? Probably. Creating user interfaces to search larger parts of problem-solution spaces? Maybe...\n\nThe reason this has not been done could quite possibly be that it means you write a one-off tool to allow you to search in a space. In effect you write something you intend to throw away again soon. This goes against the usual activity of a scientist, which is to discover things that have eternal value.\n\nFor the coming period, I will be exploring this idea, and abusing the Yacas web site for this. Over time, this article section should fill up with articles on this subject, with little applets and snippets of Javascript to demonstrate the point. The focus will not be the usual approach where the applet creator tries to teach something, but rather the focus will be on tools that allow you to venture off in to the unknown. I believe that this is a fruitful area where a lot can be discovered still. \n\n\nEmbeddable applets\n==================\nI have thought in the past on-and-off about writing tools that would allow teachers to create lesson material using Yacas. This usually evolved in to an idea where there was some notebook (or similar metaphor), with the authoring tools to allow such a teacher to write rich documents, with graphs, interactive, etcetera (you would not want to write material for teachers, as most teachers probably think they can do a better job at it than you). \n\nIt is only recently that I realized that those tools actually already exist! There is no reason not to start using html with JavaScript, in combination with a Java applet. The Java applet could do the more computationally intensive work, like calculations or plotting, where one would use JavaScript for creating the user interface, the interactivity, and html for the layout. \n\nYou can use Yacas as an applet inside a page. In effect, it acts like a little server that runs inside the page. The JavaScript code can send requests to it, and receive answers back. Teachers could literally start to write interactive lesson material without having to install any software at all (a text editor and a web browser will do). No need to maintain a server, a plain web site will do. No need for the user to install any special software, other than a browser with Java and JavaScript support.\n\n<some example applet allowing the user to perform operations on formulas, highschool>\n\n\n\n\n- One-off tasks, completable in a few hours\n- A look at Google Analytics\n\n- Example: RootsOfUnity (nice example of threading): Exp(2*Pi*I*(1 .. n)/n)\n- Example: Average (nice example of threading): Average(list_IsList) <-- Add(list)/Length(list); \n- Example: Fibonacci series, Lucas series.\n  - Verify( Fibonacci(242), 168083057059453008835412295811648513482449585399521 );\n  - Verify( Fibonacci(6,.5), 2.03125 );\n  - Verify( Fibonacci(3,.5), 1.25 );\n- Article: rant on strong typing versus test code\n- Article on splitting documentation between the two target audiences \"user\" and \"maintainer\".\n\n- poking fun at systems by caricaturizing their properties\n"
  },
  {
    "path": "appveyor.yml",
    "content": "branches:\n  only:\n    - master\n    - develop\n\nskip_tags: true\n\nplatform:\n  - x64\n\nconfiguration:\n  - Release\n\nenvironment:\n  matrix:\n    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019\n      CMAKE_GENERATOR: \"Visual Studio 16 2019\"\n      ENABLE_CYACAS_GUI: On\n      ENABLE_CYACAS_KERNEL: On\n      QTDIR: C:\\Qt\\5.15.2\\msvc2019_64\n    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022\n      CMAKE_GENERATOR: \"Visual Studio 17 2022\"\n      ENABLE_CYACAS_GUI: Off\n      ENABLE_CYACAS_KERNEL: On\n      QTDIR: C:\\Qt\\5.15.2\\msvc2022_64\n    - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004\n      CMAKE_GENERATOR: \"Ninja\"\n      ENABLE_CYACAS_GUI: Off\n      ENABLE_CYACAS_KERNEL: On\n      QTDIR: $HOME/Qt/5.15.2/gcc_64/bin\n    - APPVEYOR_BUILD_WORKER_IMAGE: macos-bigsur\n      CMAKE_GENERATOR: \"Xcode\"\n      ENABLE_CYACAS_GUI: Off\n      ENABLE_CYACAS_KERNEL: Off\n      QTDIR: $HOME/Qt/5.15.2/clang_64/bin\n\ninstall:\n  - cmd: if not exist C:\\Tools\\vcpkg\\installed\\x64-windows\\bin (\n            cd c:\\tools\\vcpkg &\n            vcpkg install boost-filesystem:x64-windows &\n            vcpkg install boost-date-time:x64-windows &\n            vcpkg install boost-serialization:x64-windows &\n            vcpkg install boost-uuid:x64-windows &\n            vcpkg install boost-dll:x64-windows &\n            vcpkg install openssl:x64-windows &\n            vcpkg install zeromq:x64-windows &\n            vcpkg install jsoncpp:x64-windows &\n            vcpkg install cppzmq:x64-windows &\n            vcpkg integrate install\n         )\n  - sh: if [ \"$APPVEYOR_BUILD_WORKER_IMAGE\" == \"Ubuntu2004\" ]; then\n            sudo apt-get update -qq;\n            sudo apt-get install -qq libboost-all-dev libssl-dev libjsoncpp-dev libzmq3-dev;\n        fi\n  - sh: if [ \"$APPVEYOR_BUILD_WORKER_IMAGE\" == \"macos-bigsur\" ]; then\n            brew update;\n            brew upgrade;\n            brew install boost jsoncpp zeromq;\n        fi\ncache:\n  - c:\\tools\\vcpkg\\installed\\ -> appveyor.yml\n\nbefore_build:\n  - cmd: cd %APPVEYOR_BUILD_FOLDER%\n  - cmd: cmake -H. -Bbuild -G \"%CMAKE_GENERATOR%\" -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DENABLE_CYACAS_KERNEL=%ENABLE_CYACAS_KERNEL% -DENABLE_CYACAS_UNIT_TESTS=Off -DENABLE_CYACAS_BENCHMARKS=Off -DENABLE_CYACAS_GUI=%ENABLE_CYACAS_GUI% -DCMAKE_PREFIX_PATH=\"%QTDIR%\" -DCMAKE_INSTALL_PREFIX=%APPVEYOR_BUILD_FOLDER%\\install\n  - sh: cd $APPVEYOR_BUILD_FOLDER\n  - sh: cmake -H. -Bbuild -G $CMAKE_GENERATOR -DCMAKE_BUILD_TYPE=Release -DENABLE_CYACAS_KERNEL=$ENABLE_CYACAS_KERNEL -DENABLE_CYACAS_UNIT_TESTS=Off -DENABLE_CYACAS_BENCHMARKS=Off -DENABLE_CYACAS_GUI=$ENABLE_CYACAS_GUI -DCMAKE_PREFIX_PATH=\"$QTDIR\" -DCMAKE_INSTALL_PREFIX=$APPVEYOR_BUILD_FOLDER/install\n\nbuild_script:\n  - cmd: cd %APPVEYOR_BUILD_FOLDER%\\build\n  - cmd: cmake --build . --config Release --target install\n  - sh: cd $APPVEYOR_BUILD_FOLDER/build\n  - sh: cmake --build . --config Release --target install\n\ntest_script:\n  - cmd: cd %APPVEYOR_BUILD_FOLDER%\\build\n  - cmd: ctest -C Release\n  - sh: cd $APPVEYOR_BUILD_FOLDER/build\n  - sh: ctest -C Release\n\nafter_build:\n  - cmd: cd ..\\install\n  - cmd: 7z a yacas.zip *\n  - sh: cd ../install\n  - sh: zip -r yacas.zip *\n\nartifacts:\n  - path: install/yacas.zip\n    name: yacas\n"
  },
  {
    "path": "build.xml",
    "content": "<project name=\"jyacas\" default=\"jar\" basedir=\".\">\n  <description>\n    jyacas build file\n  </description>\n  <property name=\"version\" value=\"1.9.2\" />\n  <property name=\"main\" value=\"net.sf.yacas.YacasConsole\" />\n  <property name=\"src\" location=\"jyacas\" />\n  <property name=\"scripts\" location=\"scripts\" />\n  <property name=\"tests\" location=\"tests\" />\n  <property name=\"build\" location=\"build/ant\" />\n  <property name=\"dist\"  location=\"dist/lib\" />\n\n  <fileset dir=\"jyacas/lib\" id=\"libs\">\n    <include name=\"junit-4.11.jar\" />\n    <include name=\"hamcrest-core-1.3.jar\" />\n  </fileset>\n\n  <target name=\"init\">\n    <tstamp/>\n    <mkdir dir=\"${build}\" />\n  </target>\n\n  <target name=\"compile\" depends=\"init\"\n          description=\"compile the source\" >\n    <delete file=\"${src}/net/sf/yacas/CVersion.java\" quiet=\"true\" />\n    <copy file=\"${src}/CVersion.java.in\" tofile=\"${src}/net/sf/yacas//CVersion.java\" >\n      <filterchain>\n        <replacestring from=\"$${YACAS_VERSION}\" to=\"${version}\"/>\n      </filterchain>\n    </copy>\n    <javac srcdir=\"${src}\" destdir=\"${build}\" includeantruntime=\"false\">\n        <classpath>\n            <fileset refid=\"libs\" />\n        </classpath>\n        <!--<compilerarg value=\"-Xlint\"/>!-->\n    </javac>\n    <mkdir dir=\"${build}/scripts\"/>\n    <copy todir=\"${build}/scripts\">\n      <fileset dir=\"${scripts}\"/>\n    </copy>\n    <copy todir=\"${build}/tests\">\n      <fileset dir=\"${tests}\"/>\n    </copy>\n  </target>\n\n  <target name=\"run\" depends=\"compile\" description=\"run yacas\">\n    <java classname=\"${main}\" classpath=\"${build}\" fork=\"true\">\n      <arg value=\"--rootdir\" />\n      <arg value=\"${build}/scripts/\" />\n    </java>\n  </target>\n\n  <target name=\"jar\" depends=\"compile\"\n          description=\"generate the distribution\" >\n    <mkdir dir=\"${dist}\"/>\n    <jar destfile=\"${dist}/yacas-${version}.jar\" basedir=\"${build}\" excludes=\"tests/**\">\n      <manifest>\n        <attribute name=\"Main-Class\" value=\"${main}\"/>\n        <attribute name=\"Specification-Version\" value=\"${version}\"/>\n        <attribute name=\"Implementation-Version\" value=\"${version}\"/>\n      </manifest>\n    </jar>\n  </target>\n\n  <target name=\"test\" depends=\"compile\" description=\"run the tests\">\n    <copy todir=\"${build}/tests\">\n      <fileset dir=\"${scripts}\"/>\n    </copy>\n\n    <junit dir=\"${build}\" fork=\"yes\" printsummary=\"withOutAndErr\"\n           showoutput=\"true\" errorProperty=\"test.failed\"\n           failureProperty=\"test.failed\" filtertrace=\"false\">\n        <formatter type=\"xml\" />\n        <formatter usefile=\"false\" type=\"brief\" />\n        <test name=\"net.sf.yacas.YacasTest\" />\n        <classpath>\n            <pathelement path=\"${build}\" />\n            <fileset refid=\"libs\" />\n        </classpath>\n    </junit>\n  </target>\n\n  <target name=\"clean\" description=\"clean up\" >\n    <delete dir=\"${build}\"/>\n    <delete dir=\"${dist}\"/>\n  </target>\n</project>\n"
  },
  {
    "path": "cyacas/CMakeLists.txt",
    "content": "\nif (APPLE)\n  set(CMAKE_MACOSX_RPATH 1)\n  set(CMAKE_INSTALL_FRAMEWORK_PREFIX \"/Library/Frameworks\" CACHE STRING \"Directory to install frameworks to.\")\n  set(CMAKE_INSTALL_BUNDLE_PREFIX \"/Applications\" CACHE STRING \"Directory to install application bundles to.\")\nendif()\n\nif (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)\n    set (CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -pedantic -Wall -fPIC\")\nelseif (MSVC)\n    set (CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} /wd4800\")\n    add_definitions(-DYACAS_NO_CONSTEXPR -DYACAS_NO_ATOMIC_TYPES -DYACAS_UINT32_T_IN_GLOBAL_NAMESPACE)\nendif ()\n\nif (CMAKE_SYSTEM_NAME STREQUAL Emscripten)\n    set (CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=1 -s EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap'] -s ALLOW_MEMORY_GROWTH=1\")\n    set (CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} --embed-file ${PROJECT_SOURCE_DIR}/scripts@/share/yacas/scripts\")\nendif ()\n\ninclude(CheckIPOSupported)\ncheck_ipo_supported(RESULT IPO_SUPPORTED)\n\nadd_library(coverage_config INTERFACE)\n\nif (ENABLE_CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES \"GNU|Clang\")\n    # Add required flags (GCC & LLVM/Clang)\n    target_compile_options(coverage_config INTERFACE\n      -g         # generate debug info\n      --coverage # sets all required flags\n    )\n    if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)\n        target_link_options(coverage_config INTERFACE --coverage)\n    else ()\n        target_link_libraries(coverage_config INTERFACE --coverage)\n    endif ()\nendif ()\n\nadd_subdirectory (libyacas_mp)\nadd_subdirectory (libyacas)\n\nif (ENABLE_CYACAS_CONSOLE)\n    add_subdirectory (yacas)\nendif ()\n\nif (ENABLE_CYACAS_GUI)\n    add_subdirectory (yacas-gui)\nendif ()\n\nif (ENABLE_CYACAS_KERNEL)\n    add_subdirectory (yacas-kernel)\nendif ()\n\nif (ENABLE_CYACAS_XEUS)\n    add_subdirectory (xeus-yacas)\nendif ()\n"
  },
  {
    "path": "cyacas/libyacas/CMakeLists.txt",
    "content": "configure_file (\n  \"config/yacas/yacas_version.h.in\"\n  \"${CMAKE_CURRENT_BINARY_DIR}/config/yacas/yacas_version.h\"\n  )\n\nset (SOURCES\n  src/associationclass.cpp\n  src/deffile.cpp\n  src/infixparser.cpp\n  src/lispatom.cpp\n  src/lispenvironment.cpp\n  src/lispeval.cpp\n  src/lisperror.cpp\n  src/lispio.cpp\n  src/lispobject.cpp\n  src/lispparser.cpp\n  src/lispuserfunc.cpp\n  src/mathcommands.cpp\n  src/mathuserfunc.cpp\n  src/standard.cpp\n  src/stdfileio.cpp\n  src/arggetter.cpp\n  src/stringio.cpp\n  src/tokenizer.cpp\n  src/yacasapi.cpp\n  src/lispevalhash.cpp\n  src/patterns.cpp\n  src/patternclass.cpp\n  src/substitute.cpp\n  src/mathcommands2.cpp\n  src/mathcommands3.cpp\n  src/mempool.cpp\n  src/errors.cpp\n  src/patcher.cpp\n  src/xmltokenizer.cpp\n  src/anumber.cpp\n  src/yacasnumbers.cpp\n  src/numbers.cpp\n  src/platmath.cpp\n  src/lisphash.cpp)\n\nset (HEADERS\n  include/yacas/anumber.h\n  include/yacas/anumber.inl\n  include/yacas/arggetter.h\n  include/yacas/arrayclass.h\n  include/yacas/associationclass.h\n  include/yacas/corefunctions.h\n  include/yacas/deffile.h\n  include/yacas/errors.h\n  include/yacas/evalfunc.h\n  include/yacas/genericobject.h\n  include/yacas/GPL_stuff.h\n  include/yacas/infixparser.h\n  include/yacas/lispatom.h\n  include/yacas/lispenvironment.h\n  include/yacas/lisperror.h\n  include/yacas/lispeval.h\n  include/yacas/lispevalhash.h\n  include/yacas/lispglobals.h\n  include/yacas/lisphash.h\n  include/yacas/lispio.h\n  include/yacas/lispobject.h\n  include/yacas/lispoperator.h\n  include/yacas/lispparser.h\n  include/yacas/lispstring.h\n  include/yacas/lispuserfunc.h\n  include/yacas/mathcommands.h\n  include/yacas/mathuserfunc.h\n  include/yacas/mempool.h\n  include/yacas/noncopyable.h\n  include/yacas/numbers.h\n  include/yacas/patcher.h\n  include/yacas/patternclass.h\n  include/yacas/patterns.h\n  include/yacas/platfileio.h\n  include/yacas/platmath.h\n  include/yacas/refcount.h\n  include/yacas/standard.h\n  include/yacas/standard.inl\n  include/yacas/stringio.h\n  include/yacas/string_utils.h\n  include/yacas/substitute.h\n  include/yacas/tokenizer.h\n  include/yacas/utf8/core.h\n  include/yacas/utf8/checked.h\n  include/yacas/utf8/unchecked.h\n  include/yacas/utf8.h\n  include/yacas/xmltokenizer.h\n  include/yacas/yacas.h)\n\nadd_library (libyacas ${SOURCES} ${HEADERS})\nset_target_properties (libyacas PROPERTIES OUTPUT_NAME \"yacas\" INTERPROCEDURAL_OPTIMIZATION ${IPO_SUPPORTED})\ntarget_include_directories (libyacas PUBLIC include \"${CMAKE_CURRENT_BINARY_DIR}/config\")\ntarget_link_libraries (libyacas PUBLIC libyacas_mp coverage_config)\n\ninstall (TARGETS libyacas LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\n                          ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}\n                          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT app)\ninstall (DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT dev)\ninstall (FILES \"${CMAKE_CURRENT_BINARY_DIR}/config/yacas/yacas_version.h\" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacas COMPONENT dev)\n\n# if (APPLE)\n#   add_library (libyacas_framework SHARED ${SOURCES} ${HEADERS})\n#   set_target_properties(libyacas_framework PROPERTIES OUTPUT_NAME \"yacas\" VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION} FRAMEWORK ON)\n#   target_link_libraries(libyacas_framework libyacas_mp)\n#   target_include_directories (libyacas_framework PUBLIC include \"${CMAKE_CURRENT_BINARY_DIR}/config\")\n#   add_custom_command(TARGET libyacas_framework POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/scripts $<TARGET_FILE_DIR:libyacas_framework>/Resources/scripts)\n#   add_custom_command(TARGET libyacas_framework POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include $<TARGET_FILE_DIR:libyacas_framework>/Headers)\n#   add_custom_command(TARGET libyacas_framework POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/config $<TARGET_FILE_DIR:libyacas_framework>/Headers)\n#   add_custom_command(TARGET libyacas_framework POST_BUILD COMMAND cd \"$<TARGET_FILE_DIR:libyacas_framework>/../..\" && rm -f Headers && ln -s Versions/Current/Headers Headers)\n#   install (TARGETS libyacas_framework FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT framework)\n# endif()\n"
  },
  {
    "path": "cyacas/libyacas/config/yacas/yacas_version.h.in",
    "content": "#ifndef YACAS_VERSION\n\n#define YACAS_VERSION_MAJOR @PROJECT_VERSION_MAJOR@\n#define YACAS_VERSION_MINOR @PROJECT_VERSION_MINOR@\n#define YACAS_VERSION_MICRO @PROJECT_VERSION_PATCH@\n\n#define YACAS_VERSION \"@PROJECT_VERSION@\"\n\n#endif"
  },
  {
    "path": "cyacas/libyacas/include/yacas/GPL_stuff.h",
    "content": "#ifndef YACAS_GPL_STUFF_H\n#define YACAS_GPL_STUFF_H\n\n#define GPL_base_text \\\n\"Yacas is Free Software--Free as in Freedom--so you can redistribute Yacas or\\n\" \\\n\"modify it under certain conditions. Yacas comes with ABSOLUTELY NO WARRANTY.\\n\" \\\n\"See the GNU Lesser General Public License (LGPL) version 2.1 or (at your\\n\" \\\n\"discretion) any later version for the full conditions.\\n\"\n\n#define Yacas_Web_info \\\n\"See http://www.yacas.org/ for more information on yacas. and documentation.\\n\"\\\n\"Type ?? for help. Or type ?function for help on a function.\\n\"\n\n#define Yacas_help_info \\\n\"Type ?license or ?licence to see the LGPL version 2.1;\\n\"\n\n// This is the full text for systems where the online help (?blah) is available\n#define GPL_blurb GPL_base_text Yacas_help_info Yacas_Web_info \"\\n\"\n\n// This is for systems where online help (?blah) is normally not available\n#define GPL_blurb_nohelp GPL_base_text Yacas_Web_info \"\\n\"\n\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/anumber.h",
    "content": "#ifndef YACAS_ANUMBER_H\n#define YACAS_ANUMBER_H\n\n#include <cassert>\n#include <cctype>\n#include <string>\n#include <vector>\n\n#include \"yacas/mp/zz.hpp\"\n\n// These define the internal types for the arbitrary precision\n// number module. The larger they are the better. PlatDoubleWord\n// should be at least twice as big as PlatWord, to prevent overflowing\n// during multiplication.\n\ntypedef std::uint32_t PlatWord;\ntypedef std::uint64_t PlatDoubleWord;\ntypedef std::int64_t PlatSignedDoubleWord;\n\n/* Quantities derived from the platform-dependent types for doing\n * arithmetic.\n */\n\n#define WordBits  (8*sizeof(PlatWord))\n#define WordBase  (((PlatDoubleWord)1)<<WordBits)\n\n/* Class ANumber represents an arbitrary precision number. it is\n * basically an array of PlatWord objects, with the first element\n * being the least significant. iExp <= 0 for integers.\n */\nclass ANumber : public std::vector<PlatWord>\n{\npublic:\n    ANumber(const std::string& aString,int aPrecision,int aBase=10);\n    ANumber(const yacas::mp::ZZ&, int aPrecision);\n    explicit ANumber(int aPrecision);\n    //TODO the properties of this object are set in the member initialization list, but then immediately overwritten by the CopyFrom. We can make this slightly cleaner by only initializing once.\n    inline ANumber(const ANumber& aOther) : std::vector<PlatWord>(), iExp(0),iNegative(false),iPrecision(0),iTensExp(0)\n    {\n      CopyFrom(aOther);\n    }\n    void CopyFrom(const ANumber& aOther);\n    bool ExactlyEqual(const ANumber& aOther);\n    void SetTo(const std::string& aString,int aBase=10);\n    int Precision() const;\n    void SetPrecision(int aPrecision) {iPrecision = aPrecision;}\n    void ChangePrecision(int aPrecision);\n    void RoundBits();\n    void DropTrailZeroes();\n    void Expand();\n\n    void Negate();\n\n    bool IsZero() const;\n    bool IsNegative() const;\n    bool IsEven() const;\n\n    void Print(std::ostream&, const std::string& prefix) const;\n\npublic:\n    int iExp;\n    bool iNegative;\n    int iPrecision;\n    int iTensExp;\n};\n\ninline\nint ANumber::Precision() const\n{\n    return iPrecision;\n}\n\nbool BaseLessThan(const ANumber& a1, const ANumber& a2);\nbool BaseGreaterThan(const ANumber& a1, const ANumber& a2);\n\nvoid BaseDivide(ANumber& aQuotient, ANumber& aRemainder, ANumber& a1, ANumber& a2);\n\nvoid IntegerDivide(ANumber& aQuotient, ANumber& aRemainder, ANumber& a1, ANumber& a2);\n\nbool Significant(ANumber& a);\n\nint WordDigits(int aPrecision, int aBase);\n\n// Operations on ANumber.\nvoid Negate(ANumber& aNumber);\nvoid ANumberToString(std::string& aResult, ANumber& aNumber, int aBase, bool aForceFloat=false);\nvoid Add(ANumber& aResult, ANumber& a1, ANumber& a2);\nvoid Subtract(ANumber& aResult, ANumber& a1, ANumber& a2);\nvoid Multiply(ANumber& aResult, ANumber& a1, ANumber& a2);\nvoid Divide(ANumber& aQuotient, ANumber& aRemainder, ANumber& a1, ANumber& a2);\nbool GreaterThan(ANumber& a1, ANumber& a2);\nbool LessThan(ANumber& a1, ANumber& a2);\nvoid BaseShiftRight(ANumber& a, int aNrBits);\nvoid BaseShiftLeft(ANumber& a, int aNrBits);\n\nvoid NormalizeFloat(ANumber& a2, int digitsNeeded);\n\ninline\nvoid ANumber::Negate()\n{\n    iNegative = !iNegative;\n\n    // FIXME: do we need negative zero?\n    if (IsZero())\n        iNegative = false;\n}\n\n\ninline\nbool ANumber::IsZero() const\n{\n    return std::all_of(begin(), end(), [](PlatWord a) {return a == 0;});\n}\n\ninline\nbool ANumber::IsNegative() const\n{\n    return iNegative;\n}\n\ninline\nbool ANumber::IsEven() const\n{\n    return (front() & 1) == 0;\n}\n\n#include \"anumber.inl\"\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/anumber.inl",
    "content": "\n#include \"anumber.h\"\n\n\n/* BaseTimesInt : multiply a with one digit in the range 0..(aBase-1)\n */\ntemplate<class T>\ninline void BaseTimesInt(T& a,PlatDoubleWord aNumber, PlatDoubleWord aBase)\n{\n  PlatDoubleWord carry=0;\n  const int nr=a.size();\n\n  typename T::value_type * aptr = &a[0];\n  for (int i=0;i<nr;i++)\n  {\n    const PlatDoubleWord word = ((PlatDoubleWord)(*aptr))*aNumber+carry;\n    *aptr++ = word % aBase;\n    carry= word / aBase;\n  }\n  if (carry)\n    a.push_back(carry);\n}\n\ntemplate<class T>\ninline void WordBaseTimesInt(T& a,PlatDoubleWord aNumber)\n{\n  PlatDoubleWord carry=0;\n  const int nr=a.size();\n\n  typename T::value_type * aptr = &a[0];\n  for (int i=0;i<nr;i++)\n  {\n    const PlatDoubleWord word = ((PlatDoubleWord)(*aptr))*aNumber+carry;\n    *aptr++ = word;\n    carry= word >> WordBits;\n  }\n  if (carry)\n    a.push_back(carry);\n}\n\n\n\ntemplate<class T>\ninline void BaseDivideInt(T& a,PlatDoubleWord aNumber, PlatDoubleWord aBase, PlatDoubleWord& aCarry)\n{\n    const int nr=a.size();\n\n    PlatDoubleWord carry=0;\n\n    typename T::value_type * aptr = &a[0];\n    for (int i=nr-1;i>=0;i--) {\n        const PlatDoubleWord word = (carry*aBase)+((PlatDoubleWord)(aptr[i]));\n        aptr[i] = word / aNumber;\n        carry= word % aNumber;\n    }\n\n    //carry now is the remainder\n    aCarry = carry;\n}\n\n\n/* GrowDigits : add digits to a until it has aDigits digits\n */\ntemplate<class T>\ninline void GrowDigits(T& a, std::size_t aDigits)\n{\n    if (aDigits <= a.size())\n        return;\n\n    a.resize(aDigits, 0);\n}\n\n/* BaseAdd : destructively add aSource to aTarget, in base aBase.\n */\ntemplate<class T>\ninline void BaseAdd(T& aTarget, const T& aSource, PlatDoubleWord aBase)\n{\n    // Initialize result\n\n    GrowDigits(aTarget,aSource.size());\n    aTarget.push_back(0);\n\n    int nr = std::min(aTarget.size(), aSource.size());\n\n    PlatDoubleWord carry=0;\n\n   const typename T::value_type * sourcePtr = &aSource[0];\n   typename T::value_type * targetPtr = &aTarget[0];\n   for (int digit=0;digit<nr;digit++)\n    {\n        PlatDoubleWord word;\n        word = (PlatDoubleWord)targetPtr[digit] +\n            (PlatDoubleWord)sourcePtr[digit] + carry;\n         PlatDoubleWord newDigit = (word%aBase);\n         PlatDoubleWord newCarry = (word/aBase);\n         targetPtr[digit] = (typename T::value_type)newDigit;\n         carry          = newCarry;\n    }\n    while (carry != 0)\n    {\n        PlatSignedDoubleWord ww = targetPtr[nr];\n        ww+=carry;\n        targetPtr[nr] = (typename T::value_type)(ww%aBase);  // PDG - cast to avoid compile-time warning\n        carry = ww/aBase;\n        nr++;\n    }\n}\n\n\ntemplate<class T>\ninline void WordBaseAdd(T& aTarget, const T& aSource)\n{\n    // Initialize result\n\n    GrowDigits(aTarget,aSource.size());\n    aTarget.push_back(0);\n\n    int nr = std::min(aTarget.size(), aSource.size());\n\n    PlatDoubleWord carry=0;\n\n   const typename T::value_type * sourcePtr = &aSource[0];\n   typename T::value_type * targetPtr = &aTarget[0];\n   for (int digit=0;digit<nr;digit++)\n    {\n        PlatDoubleWord word;\n        word = (PlatDoubleWord)targetPtr[digit] +\n            (PlatDoubleWord)sourcePtr[digit] + carry;\n         PlatWord newDigit = (PlatWord)(word);\n         PlatWord newCarry = (PlatWord)(word >> WordBits);\n         targetPtr[digit] = (typename T::value_type)newDigit;\n         carry          = newCarry;\n    }\n    while (carry != 0)\n    {\n        PlatSignedDoubleWord ww = targetPtr[nr];\n        ww+=carry;\n        targetPtr[nr] = (typename T::value_type)ww;  // PDG - cast to avoid compile-time warning\n        carry = ww >> WordBits;\n        nr++;\n    }\n}\n\n\n\n\n\ntemplate<class T>\ninline void BaseSubtract(T& aResult, T& a2, int offset)\n{\n    if (a2.IsZero())\n        return;\n\n    // Initialize result\n    int nr = a2.size();\n\n    typename T::value_type * resultPtr = &aResult[0];\n    typename T::value_type * a2ptr = &a2[0];\n\n    while (a2ptr[nr-1] == 0)\n        nr--;\n\n    // Subtract on a per-digit basis\n    PlatSignedDoubleWord carry=0;\n    int digit;\n\n    for (digit=0;digit<nr;digit++)\n    {\n        PlatSignedDoubleWord word;\n        word = ((PlatSignedDoubleWord)resultPtr[digit+offset]) -\n            ((PlatSignedDoubleWord)a2ptr[digit]) +\n            (PlatSignedDoubleWord)carry;\n        carry=0;\n        while (word<0)\n        {\n            word+=WordBase;\n            carry--;\n        }\n        resultPtr[digit+offset] = ((PlatWord)(word));\n    }\n\n    while (carry != 0)\n    {\n        assert(nr+offset<aResult.size());\n\n        int newCarry = 0;\n        PlatSignedDoubleWord ww = resultPtr[nr+offset]+carry;\n        while (ww<0)\n        {\n            ww = ww + WordBase;\n            newCarry = newCarry - 1;\n        }\n        resultPtr[nr+offset]=(typename T::value_type)ww;\n        carry = newCarry;\n        offset++;\n    }\n}\n\n/* BaseIntNumber : convert a number into a different base,\n */\ninline void BaseIntNumber(std::string& aTarget, PlatSignedDoubleWord aNumber, PlatWord aBase)\n{\n  // Assume aBase is an integer > 0.\n  // Assume aNumber is an integer > 0.\n  // Assume PlatDoubleWord is an integer type.\n  // Will maximum digit (i.e., aBase-1) convert to T::value_type right?\n    //LISPASSERT( (typename T::value_type)(aBase) == (aBase) );  // use aBase instead, to help CTCE\n    aTarget.clear();\n    while (aNumber != 0)\n    {\n        aTarget.push_back(aNumber%aBase);\n        aNumber/=aBase;\n    }\n    if (aTarget.empty())\n        aTarget.push_back(0);\n}\n\n// BaseAddMultiply : multiply x and y, and add result to aTarget\n//\n\ninline\nvoid BaseAddMultiply(std::string& aTarget, const std::string& x, const std::string& y, PlatDoubleWord aBase) {\n    const unsigned nrx = static_cast<unsigned>(x.size());\n    const unsigned nry = static_cast<unsigned>(y.size());\n    GrowDigits(aTarget, nrx + nry + 1);\n\n    std::string::value_type *targetPtr = &aTarget[0];\n    const std::string::value_type *xPtr = &x[0];\n    const std::string::value_type *yPtr = &y[0];\n\n    for (unsigned ix = 0; ix < nrx; ix++) {\n        PlatDoubleWord carry = 0;\n        for (unsigned iy = 0; iy < nry; iy++) {\n            const PlatDoubleWord word =\n                    static_cast<PlatDoubleWord> (targetPtr[ix + iy]) +\n                    static_cast<PlatDoubleWord> (xPtr[ix]) *\n                    static_cast<PlatDoubleWord> (yPtr[iy]) + carry;\n\n\n            targetPtr[ix + iy] = word % aBase;\n            carry = word / aBase;\n        }\n        targetPtr[ix + nry] += carry;\n    }\n}\n\ntemplate<class T>\ninline void WordBaseAddMultiply(T& aTarget, const T& x, const T& y)\n{\n    const unsigned nrx=x.size();\n    const unsigned nry=y.size();\n    GrowDigits(aTarget,nrx+nry+1);\n\n    typename T::value_type *targetPtr = &aTarget[0];\n    const typename T::value_type *xPtr = &x[0];\n    const typename T::value_type *yPtr = &y[0];\n    for (unsigned ix=0;ix<nrx;ix++)\n    {\n        PlatDoubleWord carry = 0;\n        for (unsigned iy=0;iy<nry;iy++)\n        {\n            PlatDoubleWord word =\n                static_cast<PlatDoubleWord>(targetPtr[ix+iy])+\n                static_cast<PlatDoubleWord>(xPtr[ix])*\n                static_cast<PlatDoubleWord>(yPtr[iy])+carry;\n\n            targetPtr[ix+iy] = word;\n            carry            = word >> WordBits;\n        }\n\n        const PlatDoubleWord word =\n            static_cast<PlatDoubleWord>(targetPtr[ix+nry])+carry;\n        targetPtr[ix+nry] = word;\n\n        assert((word >> WordBits) == 0);\n    }\n}\n\n\n\n\n/* BaseMultiply : multiply x and y, and put result in aTarget\n */\n\n\ntemplate<class T>\ninline void BaseMultiply(T& aTarget, const T& x, const T& y, PlatDoubleWord aBase)\n{\n    aTarget.resize(1);\n    aTarget[0] = 0;\n    BaseAddMultiply(aTarget, x, y, aBase);\n}\n\ntemplate<class T>\ninline void WordBaseMultiply(T& aTarget, const T& x, const T& y)\n{\n    aTarget.resize(1);\n    aTarget[0] = 0;\n    WordBaseAddMultiply(aTarget, x, y);\n}\n\ntemplate<class T>\ninline\nbool IsZero(const T& a)\n{\n    const typename T::value_type *ptr = &a[0];\n    const typename T::value_type *endptr = ptr + a.size();\n\n    while (ptr != endptr)\n        if (*ptr++ != 0)\n            return false;\n\n    return true;\n}\n\n\n\ntemplate<class T>\ninline void WordBaseDivide(T& aQuotient, T& aRemainder, T& a1, T& a2)\n{\n    // Find the values n and m as described in Knuth II:\n    int n=a2.size();\n    assert(n>0);\n    assert(a2[n-1] != 0);\n\n    //a1.size() = m+n => m = a1.size()-n\n    int m = a1.size()-n;\n    assert(m>=0);\n\n    aQuotient.resize(m+1);\n\n    //D1:\n    //this calculates d = base/(a2[n-1]+1);\n    PlatDoubleWord d = WordBase/(static_cast<PlatDoubleWord>(a2[n-1])+1);\n\n\n    WordBaseTimesInt(a1, d);\n    WordBaseTimesInt(a2, d);\n    a1.push_back(0);\n    a2.push_back(0);\n\n    //D2:\n    int j = m;\n\n    while (j>=0)\n    {\n        //D3:\n        PlatDoubleWord q = (a1[j+n]*WordBase+a1[j+n-1])/a2[n-1];\n        PlatDoubleWord r = (a1[j+n]*WordBase+a1[j+n-1])%a2[n-1];\n\n    REDO:\n        if (q == WordBase || q*a2[n-2] > WordBase*r+a1[j+n-2])\n        {\n            q = q - 1;\n            r = r + a2[n-1];\n            if (r < WordBase)\n                goto REDO;\n        }\n\n        //D4:\n        ANumber sub(aQuotient.Precision());\n        sub.CopyFrom(a2);\n        WordBaseTimesInt(sub, q);\n        sub.push_back(0);\n\n        PlatSignedDoubleWord carry;\n\n        {//Subtract the two\n            //TODO this can be generalized!!!!\n            //\n            // Beware though: this is not a normal subtraction. Only a\n            // certain set of digits ends up being subtracted.\n\n            // First check if qv isn't too big...\n            carry = 0;\n            for (int digit=0;digit<=n;digit++)\n            {\n                PlatSignedDoubleWord word;\n                word = ((PlatSignedDoubleWord)a1[digit+j]) -\n                    ((PlatSignedDoubleWord)sub[digit]) +\n                    (PlatSignedDoubleWord)carry;\n                carry=0;\n                while (word<0)\n                {\n                    word+=WordBase;\n                    carry--;\n                }\n            }\n            if (carry)\n            {\n                q--;\n                sub.CopyFrom(a2);\n                WordBaseTimesInt(sub, q);\n                sub.push_back(0);\n            }\n\n            carry = 0;\n            for (int digit=0;digit<=n;digit++)\n            {\n                PlatSignedDoubleWord word;\n                word = ((PlatSignedDoubleWord)a1[digit+j]) -\n                    ((PlatSignedDoubleWord)sub[digit]) +\n                    (PlatSignedDoubleWord)carry;\n                carry=0;\n                while (word<0)\n                {\n                    word+=WordBase;\n                    carry--;\n                }\n                a1[digit+j] = ((PlatWord)(word));\n            }\n        }\n        assert(carry == 0);\n\n        //D5:\n        aQuotient[j] = (typename T::value_type)q;\n        //D7:\n        j--;\n\n    }\n\n    //D8:\n    a1.resize(n);\n    PlatDoubleWord carry;\n    BaseDivideInt(a1, d, WordBase,carry);\n    aRemainder.CopyFrom(a1);\n}\n\ninline\nvoid ANumber::Expand()\n{\n    if (iExp+1>int(size()))\n        insert(end(), iExp+1-int(size()), 0);\n}\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/arggetter.h",
    "content": "#ifndef YACAS_ARGGETTER_H\n#define YACAS_ARGGETTER_H\n\n#include \"lispenvironment.h\"\n\n/// Get an argument that should be a short integer\nint GetShortIntegerArgument(LispEnvironment& aEnvironment, int aStackTop, int iArgNr);\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/arrayclass.h",
    "content": "#ifndef YACAS_ARRAYCLASS_H\n#define YACAS_ARRAYCLASS_H\n\n#include \"lispobject.h\"\n#include \"genericobject.h\"\n\n#include <vector>\n\nclass ArrayClass final: public GenericClass\n{\npublic:\n    //required\n    ArrayClass(std::size_t aSize,LispObject* aInitialItem);\n    const char* TypeName() const override;\n\n    //array-specific\n    std::size_t Size() const;\n    LispObject* GetElement(std::size_t aItem) const;\n    void SetElement(std::size_t aItem,LispObject* aObject);\n\nprivate:\n    std::vector<LispPtr> iArray;\n};\n\ninline\nArrayClass::ArrayClass(std::size_t aSize, LispObject* aInitialItem):\n    iArray(aSize, LispPtr(aInitialItem))\n{\n}\n\ninline\nconst char* ArrayClass::TypeName() const\n{\n    return \"\\\"Array\\\"\";\n}\n\ninline\nstd::size_t ArrayClass::Size() const\n{\n    return iArray.size();\n}\n\ninline\nLispObject* ArrayClass::GetElement(std::size_t aItem) const\n{\n    assert(aItem > 0 && aItem<=iArray.size());\n    return iArray[aItem-1];\n}\n\ninline\nvoid ArrayClass::SetElement(std::size_t aItem, LispObject* aObject)\n{\n    assert(aItem > 0 && aItem<=iArray.size());\n    iArray[aItem-1] = aObject;\n}\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/associationclass.h",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n *  of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n * \n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n * \n */\n\n/* \n * File:   associationclass.h\n * Author: mazur\n *\n * Created on September 29, 2015, 3:44 PM\n */\n\n#ifndef ASSOCIATIONCLASS_H\n#define ASSOCIATIONCLASS_H\n\n#include \"lispobject.h\"\n#include \"genericobject.h\"\n#include \"standard.h\"\n\n#include <map>\n\nclass AssociationClass final: public GenericClass\n{\npublic:\n    AssociationClass(const LispEnvironment& env);\n    const char* TypeName() const override;\n\n    std::size_t Size() const;\n    bool Contains(LispObject* k) const;\n    LispObject* GetElement(LispObject* k);\n    void SetElement(LispObject* k,LispObject* v);\n    bool DropElement(LispObject* k);\n    LispPtr Keys() const;\n    LispPtr ToList() const;\n    LispPtr Head() const;\n    \nprivate:\n    class Key {\n    public:\n        Key(const LispEnvironment& env, LispObject* p):\n            value(p), _env(env) {}\n        \n        bool operator == (const Key& rhs) const\n        {\n            return InternalEquals(_env, value, rhs.value);\n        }\n        \n        bool operator < (const Key& rhs) const\n        {\n            return InternalStrictTotalOrder(_env, value, rhs.value);\n        }\n\n        LispPtr value;\n\n    private:\n        const LispEnvironment& _env;\n    };\n\n    const LispEnvironment& _env;\n    std::map<Key, LispPtr> _map;\n};\n\ninline\nAssociationClass::AssociationClass(const LispEnvironment& env):\n    _env(env)\n{\n}\n\ninline\nconst char* AssociationClass::TypeName() const\n{\n    return \"\\\"Association\\\"\";\n}\n\ninline\nstd::size_t AssociationClass::Size() const\n{\n    return _map.size();\n}\n\ninline\nbool AssociationClass::Contains(LispObject* k) const\n{\n    return _map.find(Key(_env, k)) != _map.end();\n}\n\ninline\nLispObject* AssociationClass::GetElement(LispObject* k)\n{\n    auto p = _map.find(Key(_env, k));\n    if (p != _map.end())\n        return p->second;\n    return nullptr;\n}\n\ninline\nvoid AssociationClass::SetElement(LispObject* k, LispObject* v)\n{\n    _map[Key(_env, LispPtr(k))] = v;\n}\n\ninline\nbool AssociationClass::DropElement(LispObject* k)\n{\n    return _map.erase(Key(_env, LispPtr(k)));\n}\n\n#endif /* ASSOCIATIONCLASS_H */\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/corefunctions.h",
    "content": "//\n// declare the core functions that have special syntax\n//\n\nOPERATOR(bodied,KMaxPrecedence,While)\nOPERATOR(bodied,KMaxPrecedence,Rule)\nOPERATOR(bodied,KMaxPrecedence,MacroRule)\nOPERATOR(bodied,KMaxPrecedence,RulePattern)\nOPERATOR(bodied,KMaxPrecedence,MacroRulePattern)\nOPERATOR(bodied,KMaxPrecedence,FromFile)\nOPERATOR(bodied,KMaxPrecedence,FromString)\nOPERATOR(bodied,KMaxPrecedence,ToFile)\nOPERATOR(bodied,KMaxPrecedence,ToString)\nOPERATOR(bodied,KMaxPrecedence,ToStdout)\nOPERATOR(bodied,KMaxPrecedence,TraceRule)\nOPERATOR(bodied,KMaxPrecedence,Subst)\nOPERATOR(bodied,KMaxPrecedence,LocalSymbols)\nOPERATOR(bodied,KMaxPrecedence,BackQuote)\nOPERATOR(prefix,0,`)\nOPERATOR(prefix,0,@)\nOPERATOR(prefix,0,_)\nOPERATOR(infix,0,_)\n\n\n//\n// Evaluation direction.\n//\nCORE_KERNEL_FUNCTION(\"Hold\",LispQuote,1,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Eval\",LispEval,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\n\n//\n// Input/output functions\n//\nCORE_KERNEL_FUNCTION(\"Write\",LispWrite,1,YacasEvaluator::Function | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"WriteString\",LispWriteString,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FullForm\",LispFullForm,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DefaultDirectory\",LispDefaultDirectory,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FromFile\",LispFromFile,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FromString\",LispFromString,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Read\",LispRead,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ReadToken\",LispReadToken,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ToFile\",LispToFile,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ToString\",LispToString,1,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ToStdout\",LispToStdout,1,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Load\",LispLoad,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"TmpFile\",LispTmpFile,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\n\n//\n// Symbol protection\n//\nCORE_KERNEL_FUNCTION(\"Protect\",LispProtect, 1, YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"UnProtect\",LispUnProtect, 1, YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsProtected\",LispIsProtected, 1, YacasEvaluator::Macro | YacasEvaluator::Fixed)\n\n//\n// Variable setting/clearing\n//\nCORE_KERNEL_FUNCTION(\"Set\",LispSetVar,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MacroSet\",LispMacroSetVar,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\n// MacroClear is the same as Clear, but with its arguments evaluated first\nCORE_KERNEL_FUNCTION(\"Clear\",LispClearVar,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"MacroClear\",LispClearVar,1,YacasEvaluator::Function | YacasEvaluator::Variable)\n\nCORE_KERNEL_FUNCTION(\"Local\",LispNewLocal,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"MacroLocal\",LispNewLocal,1,YacasEvaluator::Function | YacasEvaluator::Variable)\n\nCORE_KERNEL_FUNCTION(\"Variables\", LispVars, 0, YacasEvaluator::Function | YacasEvaluator::Fixed)\n\n//\n// List and compound object manipulation\n//\nCORE_KERNEL_FUNCTION(\"Head\",LispHead,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathNth\",LispNth,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Tail\",LispTail,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DestructiveReverse\",LispDestructiveReverse,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Length\",LispLength,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"List\",LispList,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"UnList\",LispUnList,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Listify\",LispListify,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Concat\",LispConcatenate,1,YacasEvaluator::Function | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"ConcatStrings\",LispConcatenateStrings,1,YacasEvaluator::Function | YacasEvaluator::Variable)\n\nCORE_KERNEL_FUNCTION(\"Delete\",LispDelete,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DestructiveDelete\",LispDestructiveDelete,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Insert\",LispInsert,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DestructiveInsert\",LispDestructiveInsert,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Replace\",LispReplace,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DestructiveReplace\",LispDestructiveReplace,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Atom\",LispAtomize,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"String\",LispStringify,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"CharString\",LispCharString,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FlatCopy\",LispFlatCopy,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\n\n//???CORE_KERNEL_FUNCTION(\"\",LispNoCacheConcatenateStrings)\n\n//\n// Program control flow\n//\nCORE_KERNEL_FUNCTION(\"Prog\",LispProgBody,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"While\",LispWhile,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"If\",LispIf,2,YacasEvaluator::Macro | YacasEvaluator::Variable)\n//\n// Error handling\n//\nCORE_KERNEL_FUNCTION(\"Check\",LispCheck,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"TrapError\",LispTrapError,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"GetCoreError\",LispGetCoreError,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\n\n//\n// User function definition\n//\nCORE_KERNEL_FUNCTION(\"Prefix\",LispPreFix,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Infix\",LispInFix,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Postfix\",LispPostFix,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Bodied\",LispBodied,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"RuleBase\",LispRuleBase,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MacroRuleBase\",LispMacroRuleBase,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"RuleBaseListed\",LispRuleBaseListed,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MacroRuleBaseListed\",LispMacroRuleBaseListed,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DefMacroRuleBase\",LispDefMacroRuleBase,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DefMacroRuleBaseListed\",LispDefMacroRuleBaseListed,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"HoldArg\",LispHoldArg,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Rule\",LispNewRule,5,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MacroRule\",LispMacroNewRule,5,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"UnFence\",LispUnFence,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Retract\",LispRetract,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\n//\n// Predicates\n//\nCORE_KERNEL_FUNCTION(\"MathNot\",LispNot,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION_ALIAS(\"Not\",LispNot,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathAnd\",LispLazyAnd,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION_ALIAS(\"And\",LispLazyAnd,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"MathOr\",LispLazyOr,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION_ALIAS(\"Or\",LispLazyOr,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"Equals\",LispEquals,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION_ALIAS(\"=\",LispEquals,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"LessThan\",LispLessThan,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"GreaterThan\",LispGreaterThan,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsFunction\",LispIsFunction,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsAtom\",LispIsAtom,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsNumber\",LispIsNumber,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsInteger\",LispIsInteger,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsList\",LispIsList,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsString\",LispIsString,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsBound\",LispIsBound,1,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"StrictTotalOrder\",LispStrictTotalOrder,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\n//\n// Math functions (REQUIRING number inputs);.\n//\nCORE_KERNEL_FUNCTION(\"MathMultiply\",LispMultiply,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathAdd\",LispAdd,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathSubtract\",LispSubtract,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathDivide\",LispDivide,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Builtin'Precision'Set\",YacasBuiltinPrecisionSet,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathGetExactBits\",LispGetExactBits,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathSetExactBits\",LispSetExactBits,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathBitCount\",LispBitCount,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathSign\",LispMathSign,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathIsSmall\",LispMathIsSmall,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathNegate\",LispMathNegate,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathFloor\",LispFloor,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathCeil\",LispCeil,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathAbs\",LispAbs,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathMod\",LispMod,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathDiv\",LispDiv,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"BitsToDigits\",LispBitsToDigits,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DigitsToBits\",LispDigitsToBits,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathGcd\",LispGcd,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FastArcSin\",LispFastArcSin,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FastLog\",LispFastLog,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FastPower\",LispFastPower,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ShiftLeft\",LispShiftLeft,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ShiftRight\",LispShiftRight,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FromBase\",LispFromBase,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ToBase\",LispToBase,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MaxEvalDepth\",LispMaxEvalDepth,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DefLoad\",LispDefLoad,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Use\",LispUse,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"RightAssociative\",LispRightAssociative,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"LeftPrecedence\",LispLeftPrecedence,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"RightPrecedence\",LispRightPrecedence,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsBodied\",LispIsBodied,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsInfix\",LispIsInFix,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsPrefix\",LispIsPreFix,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsPostfix\",LispIsPostFix,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"OpPrecedence\",LispGetPrecedence,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"OpLeftPrecedence\",LispGetLeftPrecedence,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"OpRightPrecedence\",LispGetRightPrecedence,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Builtin'Precision'Get\",YacasBuiltinPrecisionGet,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"BitAnd\",LispBitAnd,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"BitOr\",LispBitOr,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"BitXor\",LispBitXor,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Secure\",LispSecure,1,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FindFile\",LispFindFile,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FindFunction\",LispFindFunction,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\n// Generic object support\nCORE_KERNEL_FUNCTION(\"IsGeneric\",LispIsGeneric,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"GenericTypeName\",LispGenericTypeName,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Array'Create\",GenArrayCreate,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Array'Size\",GenArraySize,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Array'Get\",GenArrayGet,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Array'Set\",GenArraySet,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'Create\",GenAssociationCreate,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'Size\",GenAssociationSize,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'Contains\",GenAssociationContains,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'Get\",GenAssociationGet,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'Set\",GenAssociationSet,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'Drop\",GenAssociationDrop,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'Keys\",GenAssociationKeys,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'ToList\",GenAssociationToList,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Association'Head\",GenAssociationHead,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"CustomEval\",LispCustomEval,4,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"CustomEval'Expression\",LispCustomEvalExpression,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"CustomEval'Result\",LispCustomEvalResult,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"CustomEval'Locals\",LispCustomEvalLocals,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"CustomEval'Stop\",LispCustomEvalStop,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\n\nCORE_KERNEL_FUNCTION(\"TraceRule\",LispTraceRule,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"TraceStack\",LispTraceStack,1,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"LispRead\",LispReadLisp,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"LispReadListed\",LispReadLispListed,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Type\",LispType,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"StringMid'Get\",YacasStringMidGet,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"StringMid'Set\",YacasStringMidSet,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\n// Pattern matching\nCORE_KERNEL_FUNCTION(\"Pattern'Create\",GenPatternCreate,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Pattern'Matches\",GenPatternMatches,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"RuleBaseDefined\",LispRuleBaseDefined,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DefLoadFunction\",LispDefLoadFunction,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"RuleBaseArgList\",LispRuleBaseArgList,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"RulePattern\",LispNewRulePattern,5,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MacroRulePattern\",LispMacroNewRulePattern,5,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Subst\",LispSubst,3,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"LocalSymbols\",LispLocalSymbols,1,YacasEvaluator::Macro | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"FastIsPrime\",LispFastIsPrime,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"MathFac\",LispFac,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ApplyPure\",LispApplyPure,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"PrettyReader'Set\",YacasPrettyReaderSet,1,YacasEvaluator::Function | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"PrettyReader'Get\",YacasPrettyReaderGet,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"PrettyPrinter'Set\",YacasPrettyPrinterSet,1,YacasEvaluator::Function | YacasEvaluator::Variable)\nCORE_KERNEL_FUNCTION(\"PrettyPrinter'Get\",YacasPrettyPrinterGet,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"GarbageCollect\",LispGarbageCollect,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"SetGlobalLazyVariable\",LispSetGlobalLazyVariable,2,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"PatchLoad\",LispPatchLoad,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"PatchString\",LispPatchString,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DefaultTokenizer\",LispDefaultTokenizer,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"XmlTokenizer\",LispXmlTokenizer,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"XmlExplodeTag\",LispExplodeTag,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Builtin'Assoc\",YacasBuiltinAssoc,2,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"CurrentFile\",LispCurrentFile,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"CurrentLine\",LispCurrentLine,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"`\",LispBackQuote,1,YacasEvaluator::Macro | YacasEvaluator::Fixed)\n\n//\n// Operating System services\n//\nCORE_KERNEL_FUNCTION(\"SystemCall\", LispSystemCall, 1, YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"SystemName\", LispSystemName, 0, YacasEvaluator::Function | YacasEvaluator::Fixed)\n\n//\n// Debugging functions\n//\nCORE_KERNEL_FUNCTION(\"MathDebugInfo\",LispDumpBigNumberDebugInfo,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"InDebugMode\",LispInDebugMode,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DebugFile\",LispDebugFile,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"DebugLine\",LispDebugLine,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\n\n//\n// Information functions\n//\nCORE_KERNEL_FUNCTION(\"Interpreter\",interpreter,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"Version\",LispVersion,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/deffile.h",
    "content": "/** \\file deffile.h deffiles, which speed up loading.\n *  This module adds support for loading files which specify\n *  which script file to look for when trying to use a specific\n *  function.\n */\n\n#ifndef YACAS_DEFFILE_H\n#define YACAS_DEFFILE_H\n\n#include \"yacas/lispstring.h\"\n\n#include <unordered_map>\n#include <unordered_set>\n\n/** LispDefFile represents one file that can be loaded just-in-time.\n */\nclass LispDefFile\n{\npublic:\n    LispDefFile(const std::string& aFile);\n\n    void SetLoaded();\n    bool IsLoaded() const;\n    const std::string& FileName() const;\n\nprivate:\n    std::string iFileName;\n    bool iIsLoaded;\npublic:\n    std::unordered_set<const LispString*> symbols;\n};\n\n/** LispDefFiles maintains an array of files that can be defloaded.\n * When the user invokes a DefLoad on a file, an entry is added to the\n * array of deffiles in the LispEnvironment class. When the function\n * is called, and there is no body of rules defined for this function,\n * the engine looks up the correct file to load from this associated\n * has class.\n */\nclass LispDefFiles\n{\npublic:\n    LispDefFile* File(const std::string& aFileName);\n\nprivate:\n    std::unordered_map<std::string, LispDefFile> _map;\n};\n\nclass LispEnvironment;\n\nvoid LoadDefFile(LispEnvironment& aEnvironment, const std::string& aFileName);\n\n\ninline\nbool LispDefFile::IsLoaded() const\n{\n    return iIsLoaded;\n}\n\ninline\nconst std::string& LispDefFile::FileName() const\n{\n    return iFileName;\n}\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/errors.h",
    "content": "#ifndef YACAS_ERRORS_H\n#define YACAS_ERRORS_H\n\n#include \"lispenvironment.h\"\n\nvoid CheckArg(bool pred, int arg_idx, LispEnvironment& env, int stack_top);\n\nvoid CheckArgIsString(LispPtr arg, int arg_idx, LispEnvironment& env, int stack_top);\nvoid CheckArgIsString(int arg_idx, LispEnvironment& env, int stack_top);\n\nvoid CheckArgIsList(LispPtr arg, int arg_idx, LispEnvironment& env, int stack_top);\nvoid CheckArgIsList(int arg_idx, LispEnvironment& env, int stack_top);\n\nvoid CheckNrArgs(int n, LispPtr& aArguments, LispEnvironment& aEnvironment);\n\nvoid ShowStack(LispEnvironment& aEnvironment);\n\nvoid ShowFunctionError(LispPtr& aArguments, LispEnvironment& aEnvironment);\n\n\nvoid CheckSecure(LispEnvironment& env, int stack_top);\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/evalfunc.h",
    "content": "#ifndef YACAS_EVALFUNCBASE_H\n#define YACAS_EVALFUNCBASE_H\n\n// class EvalFuncBase defines the interface to 'something that can\n// evaluate'\nclass LispEnvironment;\nclass EvalFuncBase\n{\npublic:\n    virtual void Evaluate(LispPtr& aResult,LispEnvironment& aEnvironment,\n                  LispPtr& aArguments) const = 0;\n    virtual ~EvalFuncBase() = default;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/genericobject.h",
    "content": "#ifndef YACAS_GENERICOBJECT_H\n#define YACAS_GENERICOBJECT_H\n\n/// Abstract class which can be put inside a LispGenericClass.\nclass GenericClass {\npublic:\n    GenericClass() : iReferenceCount(0) {};\n    virtual ~GenericClass() = default;\n    virtual const char* TypeName() const = 0;\npublic:\n    unsigned iReferenceCount; //TODO: perhaps share the method of reference counting with how it is done in other places\n};\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/infixparser.h",
    "content": "/** \\file infixparser.h\n *  parsing and printing in the infix style.\n *\n */\n\n#ifndef YACAS_INFIXPARSER_H\n#define YACAS_INFIXPARSER_H\n\n#include \"lispparser.h\"\n#include \"lispoperator.h\"\n\n#include <ostream>\n#include <unordered_map>\n\nclass InfixParser final: public LispParser\n{\npublic:\n    InfixParser(LispTokenizer& aTokenizer,\n                LispInput& aInput,\n                LispEnvironment& aEnvironment,\n                LispOperators& aPrefixOperators,\n                LispOperators& aInfixOperators,\n                LispOperators& aPostfixOperators,\n                LispOperators& aBodiedOperators);\n\n    void Parse(LispPtr& aResult) override;\n\npublic:\n    LispOperators& iPrefixOperators;\n    LispOperators& iInfixOperators;\n    LispOperators& iPostfixOperators;\n    LispOperators& iBodiedOperators;\n\nprivate:\n    void ParseCont(LispPtr& aResult);\n};\n\nclass ParsedObject {\npublic:\n    ParsedObject(InfixParser& aParser):\n        iParser(aParser),\n        iEndOfFile(false),\n        iLookAhead(0),\n        iResult(0)\n    {\n    }\n\n    void Parse();\n\nprivate:\n    void ReadToken();\n    void MatchToken(const LispString * aToken);\n    void ReadExpression(int depth);\n    void ReadAtom();\n\nprivate:\n    void GetOtherSide(int aNrArgsToCombine, int depth);\n    void Combine(int aNrArgsToCombine);\n    void InsertAtom(const LispString* aString);\n\nprivate:\n    void Fail(); // called when parsing fails, raising an exception\n\nprivate:\n    InfixParser& iParser;\n\nprivate:\n    bool iEndOfFile;\n    const LispString* iLookAhead;\n\npublic:\n    LispPtr iResult;\n};\n\n\nclass InfixPrinter final: public LispPrinter\n{\npublic:\n    InfixPrinter(LispOperators& aPrefixOperators,\n                 LispOperators& aInfixOperators,\n                 LispOperators& aPostfixOperators,\n                 LispOperators& aBodiedOperators)\n        : iPrefixOperators(aPrefixOperators),\n          iInfixOperators(aInfixOperators),\n          iPostfixOperators(aPostfixOperators),\n          iBodiedOperators(aBodiedOperators),\n          iPrevLastChar(0),iCurrentEnvironment(nullptr){}\n\n    void Print(\n        const LispPtr& aExpression,\n        std::ostream& aOutput,\n        LispEnvironment& aEnvironment) override;\n\n    void RememberLastChar(char aChar) override;\n\nprivate:\n    void Print(\n        const LispPtr& aExpression,\n        std::ostream& aOutput,\n        int iPrecedence);\n\n    void WriteToken(std::ostream& aOutput, const std::string&  aString);\n\nprivate:\n    LispOperators& iPrefixOperators;\n    LispOperators& iInfixOperators;\n    LispOperators& iPostfixOperators;\n    LispOperators& iBodiedOperators;\n    char iPrevLastChar;\n    LispEnvironment* iCurrentEnvironment;\n};\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispatom.h",
    "content": "/** \\file lispatom.h\n *  implementation of the standard lisp elements: atom and sublist.\n *\n * class LispAtom. This class implements one atom, which is a\n * reference to a string it represents, and a pointer to the next\n * lisp atom if it is in a list.\n * It also has a pointer to the annotation object.\n * The local class LispPtr implements automatic garbage collection\n * through reference counting.\n *\n * The class LispNumber inherits from LispAtom and holds a numeric atom\n * in the string representation and in the numeric representation (BigNumber).\n * The string representation is converted to BigNumber (using the current precision for floats) when a numeric\n * operation is first requested on the atom. The BigNumber representation is\n * converted to the string representation whenever the number needs to be printed i.e. LispAtom::String() method is requested.\n * The string is held in the number (to avoid repeated conversions) and also cached in the string cache (this caching will eventually be abandoned).\n * When LispNumber is constructed from BigNumber, no string representation is available.\n * Conversion from string to BigNumber is done only if no BigNumber object is present.\n */\n\n#ifndef YACAS_LISPATOM_H\n#define YACAS_LISPATOM_H\n\n#include \"lispobject.h\"\n#include \"lispstring.h\"\n#include \"mempool.h\"\n#include \"numbers.h\"  // RefPtr<BigNumber> needs definition of BigNumber\n#include \"noncopyable.h\"\n\n/// This should be used whenever constants 2, 10 mean binary and decimal.\n// maybe move somewhere else?\n#ifdef YACAS_NO_CONSTEXPR\nconst int BASE10 = 10;\nconst int BASE2 = 2;\n#else\nconstexpr int BASE10 = 10;\nconstexpr int BASE2 = 2;\n#endif\n\nclass LispEnvironment;\n\nclass LispAtom: public LispObject, public FastAlloc<LispAtom>\n{\npublic:\n  static LispObject* New(LispEnvironment& aEnvironment, const std::string& aString);\n  const LispString* String() override;\n  LispObject* Copy() const override { return new LispAtom(*this); }\nprivate:\n  LispAtom(const LispString* aString);\n\n  LispStringSmartPtr iString;\n};\n\n//------------------------------------------------------------------------------\n// LispSublist\n\nclass LispSubList: public LispObject, public FastAlloc<LispSubList>\n{\npublic:\n  static LispSubList* New(LispObject* aSubList);\n  ~LispSubList() override;\n  LispPtr* SubList() override { return &iSubList; }\n  LispObject* Copy() const override { return new LispSubList(*this); }\nprivate:\n  // Constructor is private -- use New() instead\n  LispSubList(LispObject* aSubList) : iSubList(aSubList) {}  // iSubList's constructor is messed up (it's a LispPtr, duh)\npublic:\n  LispSubList(const LispSubList& other): LispObject(other), iSubList(other.iSubList) {}\nprivate:\n  LispPtr iSubList;\n};\n\n\n//------------------------------------------------------------------------------\n// LispGenericClass\n\nclass LispGenericClass: public LispObject, public FastAlloc<LispGenericClass>\n{\npublic:\n  static LispGenericClass* New(GenericClass* aClass);\n  ~LispGenericClass() override;\n  GenericClass* Generic() override;\n  LispObject* Copy() const override { return new LispGenericClass(*this); }\nprivate:\n  // Constructor is private -- use New() instead\n  LispGenericClass(GenericClass* aClass);\npublic:\n  LispGenericClass(const LispGenericClass& other) : LispObject(other), iClass(other.iClass) { iClass->iReferenceCount++; }\nprivate:\n  LispGenericClass& operator=(const LispGenericClass& other) = delete;\nprivate:\n    GenericClass* iClass;\n};\n\nclass LispNumber: public LispObject, public FastAlloc<LispNumber>\n{\npublic:\n    /// constructors:\n    /// construct from another LispNumber\n  LispNumber(BigNumber* aNumber) : iNumber(aNumber), iString(nullptr) {}\n  LispNumber(const LispNumber& other) : LispObject(other), iNumber(other.iNumber), iString(other.iString) {}\n  /// construct from a decimal string representation (also create a number object) and use aBasePrecision decimal digits\n  LispNumber(LispString * aString, int aBasePrecision) : iNumber(nullptr), iString(aString) { Number(aBasePrecision); }\n\n  LispObject* Copy() const override { return new LispNumber(*this); }\n  /// return a string representation in decimal with maximum decimal precision allowed by the inherent accuracy of the number\n  LispString * String() override;\n  /// give access to the BigNumber object; if necessary, will create a BigNumber object out of the stored string, at given precision (in decimal?)\n  BigNumber* Number(int aPrecision) override;\nprivate:\n  /// number object; nullptr if not yet converted from string\n  RefPtr<BigNumber> iNumber;\n  /// string representation in decimal; nullptr if not yet converted from BigNumber\n  RefPtr<LispString> iString;\n};\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispenvironment.h",
    "content": "/** \\file lispenvironment.h\n *  General environment access.\n *\n */\n\n#ifndef YACAS_LISPENVIRONMENT_H\n#define YACAS_LISPENVIRONMENT_H\n\n#include \"lispobject.h\"\n#include \"lisphash.h\"\n#include \"lispevalhash.h\"\n#include \"lispuserfunc.h\"\n#include \"deffile.h\"\n#include \"lisperror.h\"\n#include \"lispio.h\"\n#include \"stringio.h\"\n#include \"lispglobals.h\"\n#include \"lispoperator.h\"\n#include \"xmltokenizer.h\"\n#include \"errors.h\"\n#include \"noncopyable.h\"\n\n#include <atomic>\n#include <string>\n#include <sstream>\n#include <vector>\n#include <deque>\n\n#include <unordered_set>\n\ntypedef std::unordered_set<LispStringSmartPtr, std::hash<const LispString*> > LispIdentifiers;\n\n\nclass LispDefFiles;\n\nclass LispInput;\nclass LispOutput;\nclass LispPrinter;\nclass LispUserFunction;\nclass LispMultiUserFunction;\nclass LispEvaluatorBase;\nclass BasicEvaluator;\nclass DefaultDebugger;\nclass LispEnvironment;\n\n\n/// The Lisp environment.\n/// This huge class is the central class of the Yacas program. It\n/// implements a dialect of Lisp.\n\nclass LispEnvironment: NonCopyable {\npublic:\n  /// \\name Constructor and destructor\n  //@{\n  LispEnvironment(YacasCoreCommands &aCoreCommands,\n                  LispUserFunctions& aUserFunctions,\n                  LispGlobal& aGlobals,\n                  LispHashTable& aHashTable,\n                  std::ostream& aOutput,\n                  LispPrinter& aPrinter,\n                  LispOperators &aPreFixOperators,\n                  LispOperators &aInFixOperators,\n                  LispOperators &aPostFixOperators,\n                  LispOperators &aBodiedOperators,\n                  LispIdentifiers& protected_symbols,\n                  LispInput*    aCurrentInput);\n  ~LispEnvironment();\n  //@}\n\npublic:\n  /// \\name Lisp variables\n  //@{\n\n  /// Assign a value to a Lisp variable.\n  /// \\param aString name of the variable\n  /// \\param aValue value to be assigned to \\a aString\n  ///\n  /// If there is a local variable with the name \\a aString, the\n  /// object \\a aValue is assigned to it. Otherwise, a\n  /// LispGlobalVariable is constructed, and it is associated with\n  /// \\a aValue in #iGlobals.\n  /// \\sa FindLocal\n  void SetVariable(const LispString* aString, LispPtr& aValue, bool aGlobalLazyVariable);\n\n  /// Get the value assigned to a variable.\n  /// \\param aVariable name of the variable\n  /// \\param aResult (on exit) value of \\a aVariable\n  ///\n  /// - If there is a local variable with the name \\a aString,\n  ///   \\a aResult is set to point to the value assigned to this local\n  ///   variable.\n  /// - If there is a global variable \\a aString and its\n  ///   #iEvalBeforeReturn is false, its value is returned via\n  ///   \\a aResult.\n  /// - If there is a global variable \\a aString and its\n  ///   #iEvalBeforeReturn is true, its value is evaluated. The\n  ///   result is assigned back to the variable, its\n  ///   #iEvalBeforeReturn is set to false, and a copy of the result\n  ///   is returned in \\a aResult.\n  /// - Otherwise, \\a aResult is set to #nullptr.\n  void GetVariable(const LispString* aVariable, LispPtr& aResult);\n\n  void UnsetVariable(const LispString * aString);\n  void PushLocalFrame(bool aFenced);\n  void PopLocalFrame();\n  void NewLocal(const LispString* aVariable, LispObject* aValue);\n  void CurrentLocals(LispPtr& aResult);\n  void GlobalVariables(LispPtr& aResult);\n  //@}\n\npublic:\n  /// \\name Lisp functions\n  //@{\n\n  /// Return the #iCoreCommands attribute.\n  const YacasCoreCommands& CoreCommands() const;\n  const LispUserFunctions& UserFunctions() const;\n\n  /// Add a command to the list of core commands.\n  /// \\param aEvaluatorFunc C function evaluating the core command\n  /// \\param aString name of the command\n  /// \\param aNrArgs number of arguments\n  /// \\param aFlags flags, see YacasEvaluator::FunctionFlags\n  void SetCommand(YacasEvalCaller aEvaluatorFunc, const char* aString,int aNrArgs,int aFlags);\n\n  void RemoveCoreCommand(char* aString);\n\n  inline  LispHashTable& HashTable();\n  LispUserFunction* UserFunction(LispPtr& aArguments);\n  LispUserFunction* UserFunction(const LispString* aName,int aArity);\n\n  /// Return LispMultiUserFunction with given name.\n  /// \\param aArguments name of the multi user function\n  ///\n  /// The table of user functions, #iUserFunctions, is consulted. If\n  /// a user function with the given name exists, it is returned.\n  /// Otherwise, a new LispMultiUserFunction is constructed, added\n  /// to #iUserFunctions, and returned.\n  LispMultiUserFunction* MultiUserFunction(const LispString* aArguments);\n\n  LispDefFiles& DefFiles();\n  void DeclareRuleBase(const LispString* aOperator, LispPtr& aParameters,\n                       int aListed);\n  void DeclareMacroRuleBase(const LispString* aOperator, LispPtr& aParameters,\n                       int aListed);\n  void DefineRule(const LispString* aOperator,int aArity,\n                          int aPrecedence, LispPtr& aPredicate,\n                          LispPtr& aBody);\n  void DefineRulePattern(const LispString* aOperator,int aArity,\n                         int aPrecedence, LispPtr& aPredicate,\n                         LispPtr& aBody);\n\n\n  void UnFenceRule(const LispString* aOperator,int aArity);\n  void Retract(const LispString* aOperator,int aArity);\n  void HoldArgument(const LispString* aOperator, const LispString* aVariable);\n\n  void Protect(const LispString*);\n  void UnProtect(const LispString*);\n  bool Protected(const LispString*) const;\n  //@}\n\npublic:\n  /// \\name Precision\n  //@{\n\n  /// set precision to a given number of decimal digits\n  void SetPrecision(int aPrecision);\n  int Precision(void) const;\n  int BinaryPrecision(void) const;\n  //@}\n\npublic:\n  void SetPrettyPrinter(const LispString* aPrettyPrinter);\n  const LispString* PrettyPrinter();\n\n  void SetPrettyReader(const LispString* aPrettyReader);\n  const LispString* PrettyReader();\n\npublic:\n  int GetUniqueId();\npublic:\n  LispPrinter& CurrentPrinter();\n\npublic:\n  /// \\name Operators\n  //@{\n  LispOperators& PreFix();\n  LispOperators& InFix();\n  LispOperators& PostFix();\n  LispOperators& Bodied();\n  //@}\n\npublic:\n  /// \\name Input and output\n  //@{\n  LispInput* CurrentInput();\n  void SetCurrentInput(LispInput* aInput);\npublic:\n  std::ostream& CurrentOutput();\n  void SetCurrentOutput(std::ostream&);\n  //@}\n\nprotected:\n  /// current precision for user interaction, in decimal and in binary\n  int iPrecision;\n  int iBinaryPrecision;\npublic:\n  std::vector<std::string> iInputDirectories;\n  //DeletingLispCleanup iCleanup;\n  int iEvalDepth;\n  int iMaxEvalDepth;\n#ifdef YACAS_NO_ATOMIC_TYPES\n  volatile bool\n#else\n  std::atomic_bool\n#endif // YACAS_NO_ATOMIC_TYPES\n    stop_evaluation;\n  LispEvaluatorBase* iEvaluator;\n\npublic: // Error information when some error occurs.\n  InputStatus iInputStatus;\n  bool secure;\npublic: // pre-found\n  RefPtr<LispObject> iTrue;\n  RefPtr<LispObject> iFalse;\n\n  RefPtr<LispObject> iEndOfFile;\n  RefPtr<LispObject> iEndStatement;\n  RefPtr<LispObject> iProgOpen;\n  RefPtr<LispObject> iProgClose;\n  RefPtr<LispObject> iNth;\n  RefPtr<LispObject> iBracketOpen;\n  RefPtr<LispObject> iBracketClose;\n  RefPtr<LispObject> iListOpen;\n  RefPtr<LispObject> iListClose;\n  RefPtr<LispObject> iComma;\n  RefPtr<LispObject> iList;\n  RefPtr<LispObject> iProg;\n\n  int iLastUniqueId;\n\npublic: // Error reporting\n  std::ostringstream iErrorOutput;\n  DefaultDebugger* iDebugger;\n\nprivate:\n    LispPtr *FindLocal(const LispString * aVariable);\n\n    struct LispLocalVariable {\n        LispLocalVariable(const LispString* var, LispObject* val):\n            var(var), val(val)\n        {\n        }\n\n\n        LispStringSmartPtr var;\n        LispPtr val;\n    };\n\n    struct LocalVariableFrame {\n        LocalVariableFrame(std::size_t first, bool fenced):\n        first(first), fenced(fenced)\n        {\n        }\n\n        std::size_t first;\n        bool fenced;\n    };\n\n    std::vector<LispLocalVariable> _local_vars;\n    std::vector<LocalVariableFrame> _local_frames;\n\npublic:\n  std::ostream* iInitialOutput;\n\nprivate:\n  /// Hash of core commands with associated YacasEvaluator\n  YacasCoreCommands& iCoreCommands;\n\n  LispUserFunctions& iUserFunctions;\n  LispHashTable& iHashTable;\n  LispDefFiles   iDefFiles;\n  LispPrinter&   iPrinter;\n  std::ostream*    iCurrentOutput;\n\n  /// Hash of global variables with their values\n  LispGlobal&    iGlobals;\n\n  LispOperators& iPreFixOperators;\n  LispOperators& iInFixOperators;\n  LispOperators& iPostFixOperators;\n  LispOperators& iBodiedOperators;\n\n  LispIdentifiers& protected_symbols;\n\n  LispInput* iCurrentInput;\n\n  const LispString* iPrettyReader;\n  const LispString* iPrettyPrinter;\npublic:\n  LispTokenizer iDefaultTokenizer;\n  XmlTokenizer  iXmlTokenizer;\n  LispTokenizer* iCurrentTokenizer;\n\n  std::deque<LispPtr> iStack;\n};\n\ninline int LispEnvironment::Precision(void) const\n{\n    return iPrecision;\n}\n\ninline int LispEnvironment::BinaryPrecision(void) const\n{\n  return iBinaryPrecision;\n}\n\n\n\ninline const YacasCoreCommands& LispEnvironment::CoreCommands() const\n{\n    return iCoreCommands;\n}\n\ninline const LispUserFunctions& LispEnvironment::UserFunctions() const\n{\n    return iUserFunctions;\n}\n\ninline LispHashTable& LispEnvironment::HashTable()\n{\n    return iHashTable;\n}\n\n\n\n// Local lisp stack, unwindable by the exception handler\nclass LispLocalFrame\n{\npublic:\n    LispLocalFrame(LispEnvironment& aEnvironment, bool aFenced)\n        : iEnvironment(aEnvironment)\n    {\n        iEnvironment.PushLocalFrame(aFenced);\n    };\n\n    virtual ~LispLocalFrame()\n    {\n        iEnvironment.PopLocalFrame();\n    };\n\nprivate:\n    LispEnvironment& iEnvironment;\n};\n\n\n\nclass LispSecureFrame\n{\npublic:\n  LispSecureFrame(LispEnvironment& aEnvironment):\n      iEnvironment(aEnvironment), previous_secure(aEnvironment.secure)\n  {\n    iEnvironment.secure = true;\n  };\n  virtual ~LispSecureFrame()\n  {\n    iEnvironment.secure = previous_secure;\n  };\nprivate:\n  LispEnvironment& iEnvironment;\n  bool previous_secure;\n};\n\n\n// LispLocalInput takes ownership over the LispInput class\nclass LispLocalInput: NonCopyable\n{\npublic:\n  LispLocalInput(LispEnvironment& aEnvironment, LispInput* aInput)\n      : iEnvironment(aEnvironment),iPreviousInput(iEnvironment.CurrentInput())\n  {\n    iEnvironment.SetCurrentInput(aInput);\n  };\n  virtual ~LispLocalInput()\n  {\n    iEnvironment.SetCurrentInput(iPreviousInput);\n  };\n\nprivate:\n  LispEnvironment& iEnvironment;\n  LispInput* iPreviousInput;\n};\n\n\n// LispLocalInput takes ownership over the LispInput class\nclass LispLocalOutput: NonCopyable\n{\npublic:\n  LispLocalOutput(LispEnvironment& aEnvironment, std::ostream& aOutput)\n      : iEnvironment(aEnvironment), iPreviousOutput(&iEnvironment.CurrentOutput())\n  {\n    iEnvironment.SetCurrentOutput(aOutput);\n  };\n  virtual ~LispLocalOutput()\n  {\n    iEnvironment.SetCurrentOutput(*iPreviousOutput);\n  };\n\nprivate:\n  LispEnvironment& iEnvironment;\n  std::ostream* iPreviousOutput;\n};\n\nclass LispLocalEvaluator: NonCopyable\n{\npublic:\n  LispLocalEvaluator(LispEnvironment& aEnvironment,LispEvaluatorBase* aNewEvaluator);\n  ~LispLocalEvaluator();\n\nprivate:\n  LispEvaluatorBase* iPreviousEvaluator;\n  LispEnvironment& iEnvironment;\n};\n\nclass LispLocalTrace: NonCopyable\n{\npublic:\n  LispLocalTrace(LispUserFunction* aUserFunc);\n  ~LispLocalTrace();\nprivate:\n  LispUserFunction* iUserFunc;\n};\n\ninline void LispEnvironment::SetPrettyReader(const LispString* aPrettyReader)\n{\n  iPrettyReader = aPrettyReader;\n}\ninline const LispString* LispEnvironment::PrettyReader()\n{\n  return iPrettyReader;\n}\n\ninline void LispEnvironment::SetPrettyPrinter(const LispString * aPrettyPrinter)\n{\n  iPrettyPrinter = aPrettyPrinter;\n}\ninline const LispString* LispEnvironment::PrettyPrinter()\n{\n  return iPrettyPrinter;\n}\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lisperror.h",
    "content": "#ifndef YACAS_LISPERROR_H\n#define YACAS_LISPERROR_H\n\n#include <string>\n\nclass LispError {\npublic:\n    LispError(const std::string& msg);\n\n    const char* what() const;\n\nprivate:\n    const std::string _what;\n};\n\ninline\nLispError::LispError(const std::string& what):\n    _what(what)\n{\n}\n\ninline\nconst char* LispError::what() const\n{\n    return _what.c_str();\n}\n\nclass LispErrInvalidArg: public LispError {\npublic:\n    LispErrInvalidArg():\n        LispError(\"Invalid argument\") {}\n};\n\nclass LispErrWrongNumberOfArgs: public LispError {\npublic:\n    LispErrWrongNumberOfArgs():\n        LispError(\"Wrong number of arguments\") {}\n};\n\nclass LispErrNotList: public LispError {\npublic:\n    LispErrNotList():\n        LispError(\"Argument is not a list\") {}\n};\n\nclass LispErrListNotLongEnough: public LispError {\npublic:\n    LispErrListNotLongEnough():\n        LispError(\"List not long enough\") {}\n};\n\nclass LispErrInvalidStack: public LispError {\npublic:\n    LispErrInvalidStack():\n        LispError(\"Invalid stack\") {}\n};\n\nclass Quitting: public LispError {\npublic:\n    Quitting():\n        LispError(\"Quitting...\") {}\n};\n\nclass LispErrNotEnoughMemory: public LispError {\npublic:\n    LispErrNotEnoughMemory():\n        LispError(\"Not enough memory\") {}\n};\n\nclass InvalidToken: public LispError {\npublic:\n    InvalidToken():\n        LispError(\"Empty token during parsing\") {}\n};\n\nclass LispErrInvalidExpression: public LispError {\npublic:\n    LispErrInvalidExpression():\n        LispError(\"Error parsing expression\") {}\n\n    explicit LispErrInvalidExpression(const std::string& ctx):\n        LispError(\"Error parsing expression near token \" + ctx) {}\n\n};\n\nclass LispErrUnprintableToken: public LispError {\npublic:\n    LispErrUnprintableToken():\n        LispError(\"Unprintable atom\") {}\n};\n\nclass LispErrFileNotFound: public LispError {\npublic:\n    LispErrFileNotFound():\n        LispError(\"File not found\") {}\n};\n\nclass LispErrReadingFile: public LispError {\npublic:\n    LispErrReadingFile():\n        LispError(\"Error reading file\") {}\n};\n\nclass LispErrCreatingUserFunction: public LispError {\npublic:\n    LispErrCreatingUserFunction():\n        LispError(\"Could not create user function\") {}\n};\n\nclass LispErrCreatingRule: public LispError {\npublic:\n    LispErrCreatingRule():\n        LispError(\"Could not create rule\") {}\n};\n\nclass LispErrArityAlreadyDefined: public LispError {\npublic:\n    LispErrArityAlreadyDefined():\n        LispError(\"Rule base with this arity already defined\") {}\n};\n\nclass LispErrCommentToEndOfFile: public LispError {\npublic:\n    LispErrCommentToEndOfFile():\n        LispError(\"Reaching end of file within a comment block\") {}\n};\n\nclass LispErrNotString: public LispError {\npublic:\n    LispErrNotString():\n        LispError(\"Argument is not a string\") {}\n};\n\nclass LispErrNotInteger: public LispError {\npublic:\n    LispErrNotInteger():\n        LispError(\"Argument is not an integer\") {}\n};\n\nclass LispErrParsingInput: public LispError {\npublic:\n    LispErrParsingInput():\n        LispError(\"Error while parsing input\") {}\n};\n\nclass LispErrMaxRecurseDepthReached: public LispError {\npublic:\n    LispErrMaxRecurseDepthReached():\n        LispError(\"Max evaluation stack depth reached.\\nPlease use MaxEvalDepth to increase the stack size as needed.\") {}\n};\n\nclass LispErrDefFileAlreadyChosen: public LispError {\npublic:\n    LispErrDefFileAlreadyChosen():\n        LispError(\"DefFile already chosen for function\") {}\n};\n\nclass LispErrDivideByZero: public LispError {\npublic:\n    LispErrDivideByZero():\n        LispError(\"Divide by zero\") {}\n};\n\nclass LispErrNotAnInFixOperator: public LispError {\npublic:\n    LispErrNotAnInFixOperator():\n        LispError(\"Trying to make a non-infix operator right-associative\") {}\n};\n\nclass LispErrUser: public LispError {\npublic:\n    LispErrUser(const std::string& msg):\n        LispError(msg) {}\n};\n\nclass LispErrIsNotInFix: public LispError {\npublic:\n    LispErrIsNotInFix():\n        LispError(\"Trying to get precedence of non-infix operator\") {}\n};\n\nclass LispErrSecurityBreach: public LispError {\npublic:\n    LispErrSecurityBreach():\n        LispError(\"Trying to perform an insecure action\") {}\n};\n\nclass LispErrLibraryNotFound: public LispError {\npublic:\n    LispErrLibraryNotFound():\n        LispError(\"Could not find library\") {}\n};\n\nclass LispErrUserInterrupt: public LispError {\npublic:\n    LispErrUserInterrupt():\n        LispError(\"User interrupted calculation\") {}\n};\n\nclass LispErrNonBooleanPredicateInPattern: public LispError {\npublic:\n    LispErrNonBooleanPredicateInPattern():\n        LispError(\"Predicate doesn't evaluate to a boolean in pattern\") {}\n};\n\nclass LispErrProtectedSymbol: public LispError {\npublic:\n    explicit LispErrProtectedSymbol(const std::string& s):\n        LispError(std::string(\"Attempt to override protected symbol: \") + s) {}\n};\n\nclass LispErrGeneric: public LispError {\npublic:\n    LispErrGeneric(const std::string& what):\n        LispError(what) {}\n};\n\nclass LispEnvironment;\nclass LispOutput;\n\nvoid HandleError(const LispError&, LispEnvironment& aEnvironment, std::ostream& aOutput);\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispeval.h",
    "content": "/** \\file lispeval.h\n *  Evaluation of expressions.\n *\n */\n\n#ifndef YACAS_LISPEVAL_H\n#define YACAS_LISPEVAL_H\n\n#include \"lispobject.h\"\n#include \"lispenvironment.h\"\n\nclass UserStackInformation {\npublic:\n    UserStackInformation()\n      : iOperator(),iExpression(),iRulePrecedence(-1),iSide(0)\n    {\n    }\n    LispPtr iOperator;\n    LispPtr iExpression;\n    int iRulePrecedence;\n    int iSide; // 0=pattern, 1=body\n};\n\n/// Abstract evaluator for Lisp expressions.\n/// Eval() is a pure virtual function, to be provided by the derived class.\n/// The other functions are stubs.\n\nclass LispEvaluatorBase {\npublic:\n  LispEvaluatorBase() : iBasicInfo() {}\n  virtual ~LispEvaluatorBase() = default;\n  virtual void Eval(LispEnvironment& aEnvironment, LispPtr& aResult, LispPtr& aExpression)=0;\n  virtual void ResetStack();\n  virtual UserStackInformation& StackInformation();\n  virtual void ShowStack(LispEnvironment& aEnvironment, std::ostream& aOutput);\nprivate:\n  UserStackInformation iBasicInfo;\n};\n\n/// The basic evaluator for Lisp expressions.\n\nclass BasicEvaluator : public LispEvaluatorBase\n{\npublic:\n  /// Evaluate a Lisp expression\n  /// \\param aEnvironment the Lisp environment, in which the\n  /// evaluation should take place.\n  /// \\param aResult the result of the evaluation.\n  /// \\param aExpression the expression to evaluate.\n  ///\n  /// First, the evaluation depth is checked. An error is raised if\n  /// the maximum evaluation depth is exceeded.\n  ///\n  /// The next step is the actual evaluation. \\a aExpression is a\n  /// LispObject, so we can distinguish three cases.\n  ///   - If \\a aExpression is a string starting with \\c \" , it is\n  ///     simply copied in \\a aResult. If it starts with another\n  ///     character (this includes the case where it represents a\n  ///     number), the environment is checked to see whether a\n  ///     variable with this name exists. If it does, its value is\n  ///     copied in \\a aResult, otherwise \\a aExpression is copied.\n  ///   - If \\a aExpression is a list, the head of the list is\n  ///     examined. If the head is not a string. InternalApplyPure()\n  ///     is called. If the head is a string, it is checked against\n  ///     the core commands; if there is a check, the corresponding\n  ///     evaluator is called. Then it is checked agaist the list of\n  ///     user function with GetUserFunction() . Again, the\n  ///     corresponding evaluator is called if there is a check. If\n  ///     all fails, ReturnUnEvaluated() is called.\n  ///   - Otherwise (ie. if \\a aExpression is a generic object), it is\n  ///     copied in \\a aResult.\n  ///\n  /// \\note The result of this operation must be a unique (copied)\n  /// element! Eg. its Next might be set...\n  ///\n  /// The LispPtr it can be stored in to is passed in as argument, so it\n  /// does not need to be constructed by the calling environment.\n  void Eval(LispEnvironment& aEnvironment, LispPtr& aResult, LispPtr& aExpression) override;\n};\n\nclass TracedEvaluator : public BasicEvaluator\n{\npublic:\n  void Eval(LispEnvironment& aEnvironment, LispPtr& aResult, LispPtr& aExpression) override;\nprotected:\n  std::ostringstream errorOutput;\n};\n\n\nclass TracedStackEvaluator final: public BasicEvaluator\n{\npublic:\n  TracedStackEvaluator() : objs() {}\n  ~TracedStackEvaluator() override;\n  void Eval(LispEnvironment& aEnvironment, LispPtr& aResult, LispPtr& aExpression) override;\n  void ResetStack() override;\n  UserStackInformation& StackInformation() override;\n  void ShowStack(LispEnvironment& aEnvironment, std::ostream& aOutput) override;\nprivate:\n  void PushFrame();\n  void PopFrame();\nprivate:\n  std::vector<UserStackInformation*> objs;\n};\n\n\n\n/* GetUserFunction : get user function, possibly loading the required\n   files to read in the function definition */\nLispUserFunction* GetUserFunction(LispEnvironment& aEnvironment,\n                                  LispPtr* subList);\n\n\n/* Tracing functions */\nvoid TraceShowEnter(LispEnvironment& aEnvironment,\n                    LispPtr& aExpression);\nvoid TraceShowLeave(LispEnvironment& aEnvironment, LispPtr& aResult,\n                    LispPtr& aExpression);\nvoid TraceShowArg(LispEnvironment& aEnvironment,LispPtr& aParam,\n                  LispPtr& aValue);\n\n\nvoid ShowExpression(LispString& outString, LispEnvironment& aEnvironment,\n                    LispPtr& aExpression);\n\n\nclass YacasDebuggerBase {\npublic:\n  virtual ~YacasDebuggerBase() = default;\n  virtual void Start() = 0;\n  virtual void Finish() = 0;\n  virtual void Enter(LispEnvironment& aEnvironment,\n                     LispPtr& aExpression) = 0;\n  virtual void Leave(LispEnvironment& aEnvironment, LispPtr& aResult,\n                     LispPtr& aExpression) = 0;\n  virtual void Error(LispEnvironment& aEnvironment) = 0;\n  virtual bool Stopped() = 0;\n};\n\nclass DefaultDebugger final: public YacasDebuggerBase\n{\npublic:\n  DefaultDebugger(LispPtr& aEnter, LispPtr& aLeave, LispPtr& aError)\n    : iEnter(aEnter), iLeave(aLeave), iError(aError), iTopExpr(),iTopResult(),iStopped(false),defaultEval() {};\n  void Start() override;\n  void Finish() override;\n  void Enter(LispEnvironment& aEnvironment, LispPtr& aExpression) override;\n  void Leave(LispEnvironment& aEnvironment, LispPtr& aResult, LispPtr& aExpression) override;\n  void Error(LispEnvironment& aEnvironment) override;\n  bool Stopped() override;\n  LispPtr iEnter;\n  LispPtr iLeave;\n  LispPtr iError;\n  LispPtr iTopExpr;\n  LispPtr iTopResult;\n  bool iStopped;\nprotected:\n  BasicEvaluator defaultEval;\n};\n\n\n#endif\n\n\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispevalhash.h",
    "content": "/** \\file lispevalhash.h\n *  Storage of executable commands\n *\n */\n\n#ifndef YACAS_LISPEVALHASH_H\n#define YACAS_LISPEVALHASH_H\n\n#include \"lispobject.h\"\n#include \"evalfunc.h\"\n\n\n#include <unordered_map>\n\n// new-style evaluator, passing arguments onto the stack in LispEnvironment\ntypedef void (*YacasEvalCaller)(LispEnvironment& aEnvironment,int aStackTop);\nclass YacasEvaluator: public EvalFuncBase\n{\npublic:\n  // FunctionFlags can be orred when passed to the constructor of this function\n  enum FunctionFlags\n  {\n    Function=0,   // Function: evaluate arguments\n    Macro=1,      // Function: don't evaluate arguments\n    Fixed = 0,    // fixed number of arguments\n    Variable = 2  // variable number of arguments\n  };\n  YacasEvaluator(YacasEvalCaller aCaller,int aNrArgs, int aFlags)\n    : iCaller(aCaller), iNrArgs(aNrArgs), iFlags(aFlags)\n  {\n  }\n  void Evaluate(LispPtr& aResult,\n                LispEnvironment& aEnvironment,\n                LispPtr& aArguments) const override;\nprivate:\n  YacasEvalCaller iCaller;\n  int iNrArgs;\n  int iFlags;\n};\n\ntypedef std::unordered_map<LispStringSmartPtr, YacasEvaluator, std::hash<const LispString*> > YacasCoreCommands;\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispglobals.h",
    "content": "\n/** \\file lispglobals.h\n *  Storage of globals in a associated hash\n *\n */\n\n#ifndef YACAS_LISPGLOBALS_H\n#define YACAS_LISPGLOBALS_H\n\n#include \"lispobject.h\"\n#include \"lisphash.h\"\n\n\n/// Value of a Lisp global variable.\n/// The only special feature of this class is the attribute\n/// #iEvalBeforeReturn, which defaults to #false. If this\n/// attribute is set to #true, the value in #iValue needs to be\n/// evaluated to get the value of the Lisp variable.\n/// \\sa LispEnvironment::GetVariable()\n\nclass LispGlobalVariable {\npublic:\n    LispGlobalVariable(const LispGlobalVariable& aOther);\n    LispGlobalVariable(LispPtr& aValue): iValue(aValue), iEvalBeforeReturn(false) {}\n    LispGlobalVariable& operator=(const LispGlobalVariable& aOther);\n\n    void SetEvalBeforeReturn(bool aEval);\n\n    LispPtr iValue;\n    bool iEvalBeforeReturn;\n};\n\ntypedef std::unordered_map<LispStringSmartPtr, LispGlobalVariable, std::hash<const LispString*> > LispGlobal;\n\n\ninline\nLispGlobalVariable::LispGlobalVariable(const LispGlobalVariable& aOther):\n    iValue(aOther.iValue),\n    iEvalBeforeReturn(false)\n{\n}\n\ninline\nvoid LispGlobalVariable::SetEvalBeforeReturn(bool aEval)\n{\n    iEvalBeforeReturn = aEval;\n}\n\n\ninline\nLispGlobalVariable& LispGlobalVariable::operator=(const LispGlobalVariable& aOther)\n{\n    iValue = aOther.iValue;\n    return *this;\n}\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lisphash.h",
    "content": "/** \\file lisphash.h\n *  hashing of strings. Each string will exist only once in the\n * hash table, and have an unique id.\n */\n\n\n#ifndef YACAS_LISPHASH_H\n#define YACAS_LISPHASH_H\n\n#include \"lispstring.h\"\n\n#include <unordered_map>\n\n/**\n * This is the symbol table, implemented as a hash table for fast\n * lookup. It is meant to store any string just once, have fast\n * searching for strings and return a reference to the string.\n * This also allows fast comparison of two strings (two strings\n * are equal iff the pointers to the strings are equal).\n */\nclass LispHashTable {\npublic:\n    // If string not yet in table, insert. Afterwards return the string.\n    const LispString* LookUp(const std::string&);\n    void GarbageCollect();\n\nprivate:\n    std::unordered_map<std::string, LispStringSmartPtr> _rep;\n};\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispio.h",
    "content": "/** \\file lispio.h\n * definitions of pure input output classes.\n */\n\n\n#ifndef YACAS_LISPIO_H\n#define YACAS_LISPIO_H\n\n#include <cstddef>\n#include <string>\n\nclass InputStatus\n{\npublic:\n  InputStatus() : iFileName(\"none\") , iLineNumber(-1)  {}\n\n  void SetTo(const std::string& aFileName);\n  void RestoreFrom(InputStatus& aPreviousStatus);\n  int LineNumber() const;\n  const std::string& FileName() const;\n  void NextLine();\n\nprivate:\n  std::string iFileName;\n  int  iLineNumber;\n};\n\ninline\nint InputStatus::LineNumber() const\n{\n  return iLineNumber;\n}\n\ninline\nconst std::string& InputStatus::FileName() const\n{\n  return iFileName;\n}\n\ninline\nvoid InputStatus::NextLine()\n{\n  iLineNumber++;\n}\n\n/** \\class LispInput : pure abstract class declaring the interface\n *  that needs to be implemented by a file (something that expressions\n *  can be read from).\n */\nclass LispInput\n{\npublic:\n  /** Constructor with InputStatus. InputStatus retains the information\n   * needed when an error occurred, and the file has already been\n   * closed.\n   */\n  LispInput(InputStatus& aStatus) : iStatus(aStatus) {};\n  virtual ~LispInput() = default;\n\n  /// Return the next character in the file\n  virtual char32_t Next() = 0;\n\n  /** Peek at the next character in the file, without advancing the file\n   *  pointer.\n   */\n  virtual char32_t Peek() = 0;\n\n  virtual const InputStatus& Status() const {return iStatus;};\n\n  /// Check if the file position is past the end of the file.\n  virtual bool EndOfStream() const = 0;\n\n  virtual std::size_t Position() const = 0;\n  virtual void SetPosition(std::size_t aPosition) = 0;\nprotected:\n  InputStatus& iStatus;\n};\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispobject.h",
    "content": "/** \\file lispobject.h\n *  Implementation of basic LispObject, which is the base class for\n *  anything that can be put in a linked list.\n *\n * class LispObject. This class implements one lisp object, which is a\n * abstract class containing reference counting and a next pointer.\n * derive from this to implement specific types of list elements.\n * The local class LispPtr implements automatic garbage collection\n * through reference counting.\n *\n */\n\n#ifndef YACAS_LISPOBJECT_H\n#define YACAS_LISPOBJECT_H\n\n#include \"refcount.h\"\n#include \"lispstring.h\"\n#include \"genericobject.h\"\n#include \"noncopyable.h\"\n\nclass LispObject;\nclass BigNumber;\n\n\n/** class LispPtr. A LispPtr is a smart pointer to a LispObject.\n *  It does the reference counting, and consequent destruction if needed.\n *  LispPtr is used in LispObject as a pointer to the next object; and\n *  LispPtr::GoNext() advances one step in this LispObject::Nixed() chain.\n *  Diverse built-in functions use LispPtr to hold temporary values.\n */\ntypedef RefPtr<LispObject> LispPtr;\n\n/** class LispObject is the base object class that can be put in\n *  linked lists. It either has a pointer to a string, obtained through\n *  String(), or it is a holder for a sublist, obtainable through SubList(),\n *  or it is a generic object, in which case Generic() returns non-nullptr.\n *  Only one of these three functions should return a non-nullptr value.\n *  It is a reference-counted object. LispPtr handles the reference counting.\n */\nclass LispObject: public RefCount\n{\npublic:\n  inline LispPtr& Nixed();\n\npublic: //Derivables\n  virtual ~LispObject() = default;\n\n  /** Return string representation, or nullptr if the object doesn't have one.\n   *  the string representation is only relevant if the object is a\n   *  simple atom. This method returns nullptr by default.\n   */\n  virtual const LispString* String()  { return nullptr; }\n  /** If this object is a list, return a pointer to it.\n   *  Default behaviour is to return nullptr.\n   */\n  virtual LispPtr* SubList()      { return nullptr; }\n  virtual GenericClass* Generic() { return nullptr; }\n\n  /** If this is a number, return a BigNumber representation\n   */\n  virtual BigNumber* Number([[maybe_unused]] int aPrecision) { return nullptr; }\n\n  virtual LispObject* Copy() const = 0;\n\npublic:\n  int Equal(LispObject& aOther);\n  inline int operator==(LispObject& aOther);\n  inline int operator!=(LispObject& aOther);\nprotected:\n  inline LispObject() :\n   iNext()\n  {\n  }\n  inline LispObject([[maybe_unused]] const LispObject& other) :\n  RefCount(),\n  iNext()\n  {\n  }\n\n  inline LispObject& operator=([[maybe_unused]] const LispObject& other)\n  {\n    return *this;\n  }\n\n\nprivate:\n  LispPtr   iNext;\n};\n\n/**\n * class LispIterator works almost like LispPtr, but doesn't enforce\n * reference counting, so it should be faster.  Use LispIterator\n * (instead of LispPtr) to traverse a lisp expression non-destructively.\n */\nclass LispIterator {\npublic:\n  // ala TEMPLATE CLASS iterator\n  //typedef forward_iterator_tag iterator_category;\n  typedef LispPtr    value_type;\n  typedef int /*ptrdiff_t*/  difference_type;\n  typedef LispPtr*  pointer;\n  typedef LispPtr&  reference;\npublic:\n  LispIterator() : _Ptr(0) {}  // construct with null node pointer\n  LispIterator(pointer ptr) : _Ptr(ptr) {}  // construct with node pointer\n  /*non-standard*/ LispIterator(reference ref) : _Ptr(&ref) {}  // construct with node reference\n  reference operator*() const { return (*(_Ptr)); }  // return designated value\n  pointer operator->() const { return (_Ptr); }  // return pointer to class object\n  inline LispIterator& operator++()  // preincrement\n  {\n    //precondition: _Ptr != nullptr\n    assert(_Ptr != nullptr);\n    //expand: _Ptr = _Nextnode(_Ptr);\n    LispObject * pObj = _Ptr->operator->();\n    _Ptr = pObj ? &(pObj->Nixed()) : nullptr;\n    return (*this);\n  }\n  LispIterator operator++(int) { LispIterator _Tmp = *this; ++*this; return (_Tmp); }  // postincrement\n  bool operator==(const LispIterator& other) const { return (_Ptr == other._Ptr); }  // test for iterator equality\n  bool operator!=(const LispIterator& other) const { return (!(*this == other)); }  // test for iterator inequality\n  // The following operators are not used yet, and would need to be tested before used.\n  //LispIterator& operator--() { _Ptr = _Prevnode(_Ptr); return (*this); }  // predecrement\n  //LispIterator operator--(int) { LispIterator _Tmp = *this; --*this; return (_Tmp); }  // postdecrement\nprotected:\n  pointer _Ptr;  // pointer to node\npublic:\n  inline LispObject* getObj() const { return (*_Ptr).operator->(); }\n};\n\nclass LispConstIterator {\npublic:\n  // ala TEMPLATE CLASS iterator\n  //typedef forward_iterator_tag iterator_category;\n  typedef const LispPtr    value_type;\n  typedef int /*ptrdiff_t*/  difference_type;\n  typedef const LispPtr*  pointer;\n  typedef const LispPtr&  reference;\npublic:\n  LispConstIterator() : _Ptr(0) {}  // construct with null node pointer\n  LispConstIterator(pointer ptr) : _Ptr(ptr) {}  // construct with node pointer\n  /*non-standard*/ LispConstIterator(reference ref) : _Ptr(&ref) {}  // construct with node reference\n  reference operator*() const { return (*(_Ptr)); }  // return designated value\n  pointer operator->() const { return (_Ptr); }  // return pointer to class object\n  inline LispConstIterator& operator++()  // preincrement\n  {\n    //precondition: _Ptr != nullptr\n    assert(_Ptr != nullptr);\n    //expand: _Ptr = _Nextnode(_Ptr);\n    LispObject * pObj = _Ptr->operator->();\n    _Ptr = pObj ? &(pObj->Nixed()) : nullptr;\n    return (*this);\n  }\n  LispConstIterator operator++(int) { LispConstIterator _Tmp = *this; ++*this; return (_Tmp); }  // postincrement\n  bool operator==(const LispConstIterator& other) const { return (_Ptr == other._Ptr); }  // test for iterator equality\n  bool operator!=(const LispConstIterator& other) const { return (!(*this == other)); }  // test for iterator inequality\n  // The following operators are not used yet, and would need to be tested before used.\n  //LispConstIterator& operator--() { _Ptr = _Prevnode(_Ptr); return (*this); }  // predecrement\n  //LispConstIterator operator--(int) { LispConstIterator _Tmp = *this; --*this; return (_Tmp); }  // postdecrement\nprotected:\n  pointer _Ptr;  // pointer to node\npublic:\n  inline const LispObject* getObj() const { return (*_Ptr).operator->(); }\n};\n\ninline LispPtr& LispObject::Nixed()\n{\n    return iNext;\n}\n\ninline int LispObject::operator==(LispObject& aOther)\n{\n    return Equal(aOther);\n}\n\ninline int LispObject::operator!=(LispObject& aOther)\n{\n    return !Equal(aOther);\n}\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispoperator.h",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n * \n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n * \n */\n\n/* \n * File:   lispoperator.h\n * Author: mazur\n *\n * Created on February 12, 2016, 3:05 PM\n */\n\n#ifndef LISPOPERATOR_H\n#define LISPOPERATOR_H\n\n#include <unordered_map>\n\n#ifdef YACAS_NO_CONSTEXPR\nconst int KMaxPrecedence = 60000;\n#else\nconstexpr int KMaxPrecedence = 60000;\n#endif\n\nclass LispInFixOperator {\npublic:\n    explicit\n#ifndef YACAS_NO_CONSTEXPR\n    constexpr\n#endif\n    LispInFixOperator(int aPrecedence = KMaxPrecedence):\n        iPrecedence(aPrecedence),\n        iLeftPrecedence(aPrecedence),\n        iRightPrecedence(aPrecedence),\n        iRightAssociative(false)\n    {}\n\n    void SetRightAssociative()\n    {\n        iRightAssociative = true;\n    }\n\n    void SetLeftPrecedence(int aPrecedence)\n    {\n        iLeftPrecedence = aPrecedence;\n    }\n\n    void SetRightPrecedence(int aPrecedence)\n    {\n        iRightPrecedence = aPrecedence;\n    }\n\n    int iPrecedence;\n    int iLeftPrecedence;\n    int iRightPrecedence;\n    bool iRightAssociative;\n};\n\ntypedef std::unordered_map<const LispStringSmartPtr, LispInFixOperator, std::hash<const LispString*> > LispOperators;\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispparser.h",
    "content": "/** \\file lispparser.h\n *  parsing and printing in the old-fashioned lisp style\n *\n */\n\n#ifndef YACAS_LISPPARSER_H\n#define YACAS_LISPPARSER_H\n\n#include \"lispobject.h\"\n#include \"tokenizer.h\"\n#include \"lispio.h\"\n#include \"evalfunc.h\"\n\n#include <ostream>\n\nclass LispParser {\npublic:\n    LispParser(LispTokenizer& aTokenizer, LispInput& aInput,\n               LispEnvironment& aEnvironment);\n\n    virtual void Parse(LispPtr& aResult );\nprotected:\n    void ParseList(LispPtr& aResult);\n    void ParseAtom(LispPtr& aResult, const LispString* aToken);\n\npublic:\n    LispTokenizer& iTokenizer;\n    LispInput& iInput;\n    LispEnvironment& iEnvironment;\n    int iListed;\n};\n\nclass LispPrinter {\npublic:\n    virtual void Print(\n        const LispPtr& aExpression,\n        std::ostream& aOutput,\n        LispEnvironment& aEnvironment);\n\n    virtual void RememberLastChar(char aChar);\n\nprivate:\n    void PrintExpression(\n        const LispPtr& aExpression,\n        std::ostream& aOutput,\n        LispEnvironment& aEnvironment,\n        int aDepth=0);\n\n    void Indent(std::ostream& aOutput, int aDepth);\n};\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispstring.h",
    "content": "/** \\file lispstring.h\n *  Defining a string class.\n */\n\n\n#ifndef YACAS_LISPSTRING_H\n#define YACAS_LISPSTRING_H\n\n#include \"refcount.h\"\n\n#include <string>\n\n/** \\class LispString : zero-terminated byte-counted string.\n * Also keeps a reference count for any one interested.\n */\nclass LispString: public RefCount, public std::string\n{\npublic:\n    explicit LispString(const std::string& = \"\");\n};\n\n\ninline LispString::LispString(const std::string& s):\n    std::string(s)\n{\n}\n\ntypedef RefPtr<const LispString> LispStringSmartPtr;\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/lispuserfunc.h",
    "content": "#ifndef YACAS_LISPUSERFUNC_H\n#define YACAS_LISPUSERFUNC_H\n\n#include \"lispobject.h\"\n#include \"evalfunc.h\"\n\n#include <vector>\n#include <unordered_map>\n\nclass LispEnvironment;\n\n/// Abstract class providing the basic user function API.\n/// Instances of this class are associated to the name of the function\n/// via an associated hash table. When obtained, they can be used to\n/// evaluate the function with some arguments.\n\nclass LispUserFunction : public EvalFuncBase\n{\npublic:\n    LispUserFunction() : iFenced(true),iTraced(false) {};\n    virtual void HoldArgument(const LispString* aVariable) = 0;\n    virtual void DeclareRule(int aPrecedence, LispPtr& aPredicate,\n                             LispPtr& aBody) = 0;\n    virtual void DeclareRule(int aPrecedence, LispPtr& aBody) = 0;\n    virtual void DeclarePattern(int aPrecedence, LispPtr& aPredicate,\n                             LispPtr& aBody) = 0;\n    virtual const LispPtr& ArgList() const = 0;\n\npublic: //unfencing\n    inline void UnFence() {iFenced = false;};\n    inline bool Fenced() const {return iFenced;};\npublic: //tracing\n    inline void Trace() {iTraced = true;};\n    inline void UnTrace() {iTraced = false;};\n    inline bool Traced() const {return iTraced;};\nprivate:\n    bool iFenced;\n    bool iTraced;\n};\n\n\n/// User function with a specific arity.\n/// This is still an abstract class, but the arity (number of\n/// arguments) of the function is now fixed.\n\nclass LispArityUserFunction : public LispUserFunction\n{\npublic:\n    virtual unsigned Arity() const = 0;\n    virtual bool IsArity(unsigned aArity) const = 0;\n};\n\n\nclass LispDefFile;\n\n\n/// Set of LispArityUserFunction's.\n/// By using this class, you can associate multiple functions (with\n/// different arities) to one name. A specific LispArityUserFunction\n/// can be selected by providing its name. Additionally, the name of\n/// the file in which the function is defined, can be specified.\n\nclass LispMultiUserFunction final {\npublic:\n  /// Constructor.\n  LispMultiUserFunction() : iFunctions(),iFileToOpen(nullptr) {};\n\n  /** When adding a multi-user function to the association hash table, the copy constructor is used.\n   *  We should at least make sure that iFunctions is empty, so there is no copying needed (for efficiency).\n   *  Casually having a copy-constructor on CDeletingArrayGrower should be avoided, to make sure it is\n   *  not used accidentally.\n   */\n  inline LispMultiUserFunction([[maybe_unused]] const LispMultiUserFunction& aOther) : iFunctions(), iFileToOpen(nullptr)\n  {\n    assert(aOther.iFileToOpen == 0);\n    assert(aOther.iFunctions.size() == 0);\n  }\n  inline LispMultiUserFunction& operator=([[maybe_unused]] const LispMultiUserFunction& aOther)\n  {\n    // copy constructor not written yet, hence the assert\n    assert(aOther.iFileToOpen == 0);\n    assert(aOther.iFunctions.size() == 0);\n\n    assert(iFileToOpen == 0);\n    assert(iFunctions.size() == 0);\n    return *this;\n  }\n\n  /// Return user function with given arity.\n  LispUserFunction* UserFunc(int aArity);\n\n  /// Destructor.\n  virtual ~LispMultiUserFunction();\n\n  /// Specify that some argument should be held.\n  virtual void HoldArgument(const LispString* aVariable);\n\n  /// Add another LispArityUserFunction to #iFunctions.\n  virtual void DefineRuleBase(LispArityUserFunction* aNewFunction);\n\n  /// Delete tuser function with given arity.\n  virtual void DeleteBase(int aArity);\n\nprivate:\n  /// Set of LispArityUserFunction's provided by this LispMultiUserFunction.\n  std::vector<LispArityUserFunction*> iFunctions;\n\npublic:\n  /// File to read for the definition of this function.\n  LispDefFile* iFileToOpen;\n};\n\n\n/// Associated hash of LispMultiUserFunction objects.\ntypedef std::unordered_map<LispStringSmartPtr, LispMultiUserFunction, std::hash<const LispString*> > LispUserFunctions;\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/mathcommands.h",
    "content": "#ifndef YACAS_MATHCOMMANDS_H\n#define YACAS_MATHCOMMANDS_H\n\n#include \"lispenvironment.h\"\n#include \"lispevalhash.h\"\n#include \"lispobject.h\"\n#include \"lispglobals.h\"\n\n\n//#define CORE_FUNCTION(NAME) void NAME(LispEnvironment& aEnvironment, LispPtr& aResult, LispPtr& aArguments);\n\n#define CORE_KERNEL_FUNCTION(iname,fname,nrargs,flags) void fname(LispEnvironment& aEnvironment, int aStackTop);\n#define CORE_KERNEL_FUNCTION_ALIAS(iname,fname,nrargs,flags)  int JimDummyFunction();\n#define OPERATOR(kind, prec, yacas_name) int JimDummyFunction();\n\n#include \"corefunctions.h\"\n#undef CORE_KERNEL_FUNCTION\n#undef CORE_KERNEL_FUNCTION_ALIAS\n#undef OPERATOR\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/mathuserfunc.h",
    "content": "#ifndef YACAS_MATHUSERFUNC_H\n#define YACAS_MATHUSERFUNC_H\n\n#include \"lispuserfunc.h\"\n#include \"patternclass.h\"\n#include \"noncopyable.h\"\n\n#include <vector>\n\n/// A mathematical function defined by several rules.\n/// This is the basic class which implements functions in Yacas.\n/// Evaluation is done by consulting a set of rewriting rules. The\n/// body of the first rule that matches, is evaluated and this gives\n/// the result of evaluating the function.\n\nclass BranchingUserFunction : public LispArityUserFunction\n{\npublic:\n  /// Structure containing name of parameter and whether it is put on hold.\n  class BranchParameter {\n  public:\n    BranchParameter(const LispString* aParameter = nullptr, int aHold=false)\n        : iParameter(aParameter), iHold(aHold) {}\n    const LispString* iParameter;\n    int iHold;\n  };\n\n  /// Abstract base class for rules.\n  class BranchRuleBase {\n  public:\n    virtual ~BranchRuleBase() = default;\n    virtual bool Matches(LispEnvironment& aEnvironment, LispPtr* aArguments) = 0;\n    virtual int Precedence() const = 0;\n    virtual LispPtr& Body() = 0;\n  };\n\n  /// A rule with a predicate.\n  /// This rule matches if the predicate evaluates to #true.\n  class BranchRule : public BranchRuleBase\n  {\n  public:\n    BranchRule(int aPrecedence,LispPtr& aPredicate,LispPtr& aBody) : iPrecedence(aPrecedence),iBody(aBody),iPredicate(aPredicate)\n    {\n    }\n\n    /// Return true if the rule matches.\n    /// #iPredicate is evaluated in \\a Environment. If the result\n    /// IsTrue(), this function returns true.\n    bool Matches(LispEnvironment& aEnvironment, LispPtr* aArguments);\n\n    /// Access #iPrecedence.\n    int Precedence() const;\n\n    /// Access #iBody.\n    LispPtr& Body();\n  protected:\n    BranchRule() : iPrecedence(0),iBody(),iPredicate() {};\n  protected:\n    int iPrecedence;\n    LispPtr iBody;\n    LispPtr iPredicate;\n  };\n\n  /// A rule that always matches.\n  class BranchRuleTruePredicate : public BranchRule\n  {\n  public:\n    BranchRuleTruePredicate(int aPrecedence,LispPtr& aBody)\n    {\n      iPrecedence = aPrecedence;\n      iBody = (aBody);\n    }\n    /// Return #true, always.\n    bool Matches(LispEnvironment& aEnvironment, LispPtr* aArguments);\n  };\n\n  /// A rule which matches if the corresponding PatternClass matches.\n  class BranchPattern : public BranchRuleBase, NonCopyable\n  {\n  public:\n    /// Constructor.\n    /// \\param aPrecedence precedence of the rule\n    /// \\param aPredicate generic object of type \\c Pattern\n    /// \\param aBody body of the rule\n    BranchPattern(int aPrecedence,LispPtr& aPredicate,LispPtr& aBody) : iPrecedence(aPrecedence),iBody(aBody),iPredicate(aPredicate),iPatternClass(nullptr)\n    {\n      GenericClass *gen = aPredicate->Generic();\n      PatternClass* pat = dynamic_cast<PatternClass*>(gen);\n      if (!pat)\n        throw LispErrInvalidArg();\n      iPatternClass = pat;\n    }\n\n    /// Return true if the corresponding pattern matches.\n    bool Matches(LispEnvironment& aEnvironment, LispPtr* aArguments);\n\n    /// Access #iPrecedence\n    int Precedence() const;\n\n    /// Access #iBody\n    LispPtr& Body();\n\n  protected:\n    /// The precedence of this rule.\n    int iPrecedence;\n\n    /// The body of this rule.\n    LispPtr iBody;\n\n    /// Generic object of type \\c Pattern containing #iPatternClass\n    LispPtr iPredicate;\n\n    /// The pattern that decides whether this rule matches.\n    PatternClass *iPatternClass;\n  };\n\n  /// Constructor.\n  /// \\param aParameters linked list constaining the names of the arguments\n  ///\n  /// #iParamList and #iParameters are set from \\a aParameters.\n  BranchingUserFunction(LispPtr& aParameters);\n\n  /// Destructor.\n  ~BranchingUserFunction();\n\n  /// Evaluate the function on given arguments.\n  /// \\param aResult (on output) the result of the evaluation\n  /// \\param aEnvironment the underlying Lisp environment\n  /// \\param aArguments the arguments to the function\n  ///\n  /// First, all arguments are evaluated by the evaluator associated\n  /// to \\a aEnvironment, unless the \\c iHold flag of the\n  /// corresponding parameter is true. Then a new LispLocalFrame is\n  /// constructed, in which the actual arguments are assigned to the\n  /// names of the formal arguments, as stored in \\c iParameter. Then\n  /// all rules in #iRules are tried one by one. The body of the\n  /// first rule that matches is evaluated, and the result is put in\n  /// \\a aResult. If no rule matches, \\a aResult will recieve a new\n  /// expression with evaluated arguments.\n  void Evaluate(LispPtr& aResult,LispEnvironment& aEnvironment, LispPtr& aArguments) const override;\n\n  /// Put an argument on hold.\n  /// \\param aVariable name of argument to put un hold\n  ///\n  /// The \\c iHold flag of the corresponding argument is set. This\n  /// implies that this argument is not evaluated by Evaluate().\n  void HoldArgument(const LispString* aVariable) override;\n\n  /// Return true if the arity of the function equals \\a aArity.\n  bool IsArity(unsigned aArity) const override;\n\n  /// Return the arity (number of arguments) of the function.\n  unsigned Arity() const override;\n\n  /// Add a BranchRule to the list of rules.\n  /// \\sa InsertRule()\n  void DeclareRule(int aPrecedence, LispPtr& aPredicate, LispPtr& aBody) override;\n\n  /// Add a BranchRuleTruePredicate to the list of rules.\n  /// \\sa InsertRule()\n  void DeclareRule(int aPrecedence, LispPtr& aBody) override;\n\n  /// Add a BranchPattern to the list of rules.\n  /// \\sa InsertRule()\n  void DeclarePattern(int aPrecedence, LispPtr& aPredicate, LispPtr& aBody) override;\n\n  /// Insert any BranchRuleBase object in the list of rules.\n  /// This function does the real work for DeclareRule() and\n  /// DeclarePattern(): it inserts the rule in #iRules, while\n  /// keeping it sorted. The algorithm is \\f$O(\\log n)\\f$, where\n  /// \\f$n\\f$ denotes the number of rules.\n  void InsertRule(int aPrecedence,BranchRuleBase* newRule);\n\n  /// Return the argument list, stored in #iParamList\n  const LispPtr& ArgList() const override;\n\nprotected:\n  /// List of arguments, with corresponding \\c iHold property.\n  std::vector<BranchParameter> iParameters;\n\n  /// List of rules, sorted on precedence.\n  std::vector<BranchRuleBase*> iRules;\n\n  /// List of arguments\n  LispPtr iParamList;\n};\n\nclass ListedBranchingUserFunction final: public BranchingUserFunction\n{\npublic:\n  ListedBranchingUserFunction(LispPtr& aParameters);\n  bool IsArity(unsigned aArity) const override;\n  void Evaluate(LispPtr& aResult,LispEnvironment& aEnvironment, LispPtr& aArguments) const override;\n};\n\n\nclass MacroUserFunction : public BranchingUserFunction\n{\npublic:\n  MacroUserFunction(LispPtr& aParameters);\n  void Evaluate(LispPtr& aResult,LispEnvironment& aEnvironment, LispPtr& aArguments) const override;\n};\n\n\nclass ListedMacroUserFunction final: public MacroUserFunction\n{\npublic:\n  ListedMacroUserFunction(LispPtr& aParameters);\n  bool IsArity(unsigned aArity) const override;\n  void Evaluate(LispPtr& aResult,LispEnvironment& aEnvironment, LispPtr& aArguments) const override;\n};\n\n\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/mempool.h",
    "content": "#ifndef YACAS_MEMPOOL_H\n#define YACAS_MEMPOOL_H\n\n#include \"noncopyable.h\"\n\n#include <cstddef>\n#include <cstdint>\n\nclass MemPool: NonCopyable {\npublic:\n    explicit MemPool(unsigned block_size, unsigned no_blocks);\n    ~MemPool() noexcept;\n\n    void* alloc();\n    void free(void *p) noexcept;\n\nprivate:\n    unsigned _block_size;\n    unsigned _no_blocks;\n\n    unsigned _no_free_blocks;\n    unsigned _no_initialized_blocks;\n\n    std::uint8_t* _pool;\n\n    std::uint8_t* _next_free_block;\n\n    MemPool* _next_pool;\n};\n\ntemplate <typename T>\nclass FastAlloc {\npublic:\n    static void* operator new(std::size_t) { return _pool.alloc(); }\n    static void operator delete(void* p) { _pool.free(p); }\nprivate:\n    static MemPool _pool;\n};\n\ntemplate <typename T>\nMemPool FastAlloc<T>::_pool(sizeof (T), 32768);\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/noncopyable.h",
    "content": "#ifndef YACAS_NONCOPYABLE_H\n#define YACAS_NONCOPYABLE_H\n\nclass NonCopyable {\nprotected:\n#ifndef YACAS_NO_CONSTEXPR\n    constexpr\n#endif\n    NonCopyable() = default;\n    ~NonCopyable() = default;\nprivate:\n    NonCopyable(const NonCopyable&) = delete;\n    NonCopyable& operator=(const NonCopyable&) = delete;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/numbers.h",
    "content": "#ifndef YACAS_NUMBERS_H\n#define YACAS_NUMBERS_H\n\n#include \"lispenvironment.h\"\n#include \"anumber.h\"\n#include \"refcount.h\"\n#include \"yacas/mp/zz.hpp\"\n\n#include <memory>\n\nusing namespace yacas;\n\nLispObject* GcdInteger(LispObject* int1, LispObject* int2, LispEnvironment& aEnvironment);\nLispObject* ModFloat( LispObject* int1, LispObject* int2, LispEnvironment& aEnvironment,\n                        int aPrecision);\n\nLispObject* PowerFloat(LispObject* int1, LispObject* int2,\n                         LispEnvironment& aEnvironment,int aPrecision);\nLispObject* ShiftLeft( LispObject* int1, LispObject* int2, LispEnvironment& aEnvironment,int aPrecision);\nLispObject* ShiftRight( LispObject* int1, LispObject* int2, LispEnvironment& aEnvironment,int aPrecision);\nLispObject* LispFactorial(LispObject* int1, LispEnvironment& aEnvironment,int aPrecision);\n\n/** Base number class.\n */\n\n\n/// Main class for multiple-precision arithmetic.\n/// All calculations are done at given precision. Integers grow as needed, floats don't grow beyond given precision.\nclass BigNumber: public RefCount {\npublic: //constructors\n    BigNumber(const std::string& aString,int aPrecision,int aBase=10);\n    explicit BigNumber(const mp::ZZ& zz);\n    /// copy constructor\n    explicit BigNumber(const BigNumber& aOther);\n\n    BigNumber& operator = (const BigNumber&);\n\n    /// ToString : return string representation of number in aResult to given precision (base digits)\n    void ToString(std::string& aResult, int aPrecision, int aBase=10) const;\n    /// Give approximate representation as a double number\n    double Double() const;\n\n    //basic object manipulation\n    bool Equals(const BigNumber& aOther) const;\n    bool IsInt() const;\n    bool IsSmall() const;\n    void BecomeInt();\n    void BecomeFloat(int aPrecision=0);\n    bool LessThan(const BigNumber& aOther) const;\n    //arithmetic\n    /// Multiply two numbers at given precision and put result in *this\n    void Multiply(const BigNumber& aX, const BigNumber& aY, int aPrecision);\n    /// Add two numbers at given precision and return result in *this\n    void Add(const BigNumber& aX, const BigNumber& aY, int aPrecision);\n    /// Negate the given number, return result in *this\n    void Negate(const BigNumber& aX);\n    /// Divide two numbers and return result in *this. Note: if the two arguments are integer, it should return an integer result!\n    void Divide(const BigNumber& aX, const BigNumber& aY, int aPrecision);\n\n    /// For debugging purposes, dump internal state of this object into a string\n    void DumpDebugInfo(std::ostream&) const;\n\n    /// assign self to Floor(aX) if possible\n    void Floor(const BigNumber& aX);\n    /// set precision (in bits)\n    void Precision(int aPrecision);\n\n    /// Bitwise operations, return result in *this.\n    void ShiftLeft( const BigNumber& aX, int aNrToShift);\n    void ShiftRight( const BigNumber& aX, int aNrToShift);\n    void BitAnd(const BigNumber& aX, const BigNumber& aY);\n    void BitOr(const BigNumber& aX, const BigNumber& aY);\n    void BitXor(const BigNumber& aX, const BigNumber& aY);\n    void BitNot(const BigNumber& aX);\n    /// Bit count operation: return the number of significant bits if integer, return the binary exponent if float (shortcut for binary logarithm)\n    /// give bit count as a platform integer\n    signed long BitCount() const;\n\n    /// Give sign (-1, 0, 1)\n    int Sign() const;\n\n    inline int GetPrecision() const {return iPrecision;};\n\nprivate:\n    int iPrecision;\n\n    friend LispObject* GcdInteger(LispObject* int1, LispObject* int2, LispEnvironment& aEnvironment);\n    friend LispObject* SqrtFloat(LispObject* int1, LispEnvironment& aEnvironment,int aPrecision);\n    friend LispObject* PowerFloat(LispObject* int1, LispObject* int2, LispEnvironment& aEnvironment,int aPrecision);\n\n    std::unique_ptr<ANumber> iNumber;\n    std::unique_ptr<mp::ZZ> _zz;\n};\n\n/// bits_to_digits and digits_to_bits, utility functions\n/// to convert the number of digits in some base (usually 10) to bits and back\n\n// lookup table for Ln(n)/Ln(2)\n// table range is from 2 to this value:\nunsigned log2_table_range();\n// convert the number of digits in given base to the number of bits, and back.\n// need to round the number of digits.\n// These functions only work for aBase inside the allowed table range.\nunsigned long digits_to_bits(unsigned long aDigits, unsigned aBase);\nunsigned long bits_to_digits(unsigned long abits, unsigned aBase);\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/patcher.h",
    "content": "#ifndef YACAS_PATCHER_H\n#define YACAS_PATCHER_H\n\n#include <string>\n#include <ostream>\n\n#include \"lispenvironment.h\"\n\nvoid PatchLoad(const std::string&, std::ostream&, LispEnvironment&);\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/patternclass.h",
    "content": "#ifndef YACAS_PATTERNCLASS_H\n#define YACAS_PATTERNCLASS_H\n\n#include \"lispobject.h\"\n#include \"genericobject.h\"\n#include \"patterns.h\"\n#include \"noncopyable.h\"\n\n/// Wrapper for YacasPatternPredicateBase.\n/// This class allows a YacasPatternPredicateBase to be put in a\n/// LispGenericObject.\nclass PatternClass final: public GenericClass, NonCopyable\n{\npublic:\n  PatternClass(YacasPatternPredicateBase* aPatternMatcher);\n  ~PatternClass();\n\n  bool Matches(LispEnvironment& aEnvironment,\n                      LispPtr& aArguments);\n  bool Matches(LispEnvironment& aEnvironment,\n                      LispPtr* aArguments);\n\n  const char* TypeName() const override;\n\nprotected:\n  YacasPatternPredicateBase* iPatternMatcher;\n};\n\n\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/patterns.h",
    "content": "#ifndef YACAS_PATTERNS_H\n#define YACAS_PATTERNS_H\n\n/// \\file\n/// Pattern matching code.\n///\n/// General idea: have a class that can match function parameters\n/// to a pattern, check for predicates on the arguments, and return\n/// whether there was a match.\n///\n/// First the pattern is mapped onto the arguments. Then local variables\n/// are set. Then the predicates are called. If they all return true,\n/// Then the pattern matches, and the locals can stay (the body is expected\n/// to use these variables).\n\n\n#include \"lispenvironment.h\"\n#include \"noncopyable.h\"\n#include \"numbers.h\"\n\n#include <vector>\n\n/// Abstract class for matching one argument to a pattern.\nclass YacasParamMatcherBase {\npublic:\n    /// Destructor.\n    virtual ~YacasParamMatcherBase() = default;\n\n    /// Check whether some expression matches to the pattern.\n    /// \\param aEnvironment the underlying Lisp environment.\n    /// \\param aExpression the expression to test.\n    /// \\param arguments (input/output) actual values of the pattern\n    /// variables for \\a aExpression.\n    virtual bool ArgumentMatches(LispEnvironment& aEnvironment,\n                                 LispPtr& aExpression,\n                                 LispPtr* arguments) const = 0;\n};\n\n/// Class for matching an expression to a given atom.\nclass MatchAtom : public YacasParamMatcherBase\n{\npublic:\n    explicit MatchAtom(const LispString* aString);\n    bool ArgumentMatches(LispEnvironment& aEnvironment,\n                         LispPtr& aExpression,\n                         LispPtr* arguments) const override;\nprotected:\n    const LispString* iString;\n};\n\ninline\nMatchAtom::MatchAtom(const LispString* aString):\n    iString(aString)\n{\n}\n\n/// Class for matching an expression to a given number.\nclass MatchNumber : public YacasParamMatcherBase\n{\npublic:\n    explicit MatchNumber(BigNumber* aNumber);\n    bool ArgumentMatches(LispEnvironment& aEnvironment,\n                         LispPtr& aExpression,\n                         LispPtr* arguments) const override;\nprotected:\n    RefPtr<BigNumber> iNumber;\n};\n\ninline\nMatchNumber::MatchNumber(BigNumber* aNumber):\n    iNumber(aNumber)\n{\n}\n\n/// Class for matching against a list of YacasParamMatcherBase objects.\nclass MatchSubList final: public YacasParamMatcherBase, NonCopyable {\npublic:\n    explicit MatchSubList(const std::vector<const YacasParamMatcherBase*>&& aMatchers);\n    ~MatchSubList() override;\n\n    bool ArgumentMatches(\n        LispEnvironment& aEnvironment,\n        LispPtr& aExpression,\n        LispPtr* arguments) const override;\n\nprotected:\n    std::vector<const YacasParamMatcherBase*> iMatchers;\n};\n\ninline\nMatchSubList::MatchSubList(const std::vector<const YacasParamMatcherBase*>&& aMatchers):\n    iMatchers(aMatchers)\n{\n}\n\ninline\nMatchSubList::~MatchSubList()\n{\n    for (const YacasParamMatcherBase* m: iMatchers)\n        delete m;\n}\n\n/// Class for matching against a pattern variable.\nclass MatchVariable final: public YacasParamMatcherBase\n{\npublic:\n    explicit MatchVariable(int aVarIndex);\n\n    /// Matches an expression against the pattern variable.\n    /// \\param aEnvironment the underlying Lisp environment.\n    /// \\param aExpression the expression to test.\n    /// \\param arguments (input/output) actual values of the pattern\n    /// variables for \\a aExpression.\n    ///\n    /// If entry #iVarIndex in \\a arguments is still empty, the\n    /// pattern matches and \\a aExpression is stored in this\n    /// entry. Otherwise, the pattern only matches if the entry equals\n    /// \\a aExpression.\n    bool ArgumentMatches(LispEnvironment& aEnvironment,\n                         LispPtr& aExpression,\n                         LispPtr* arguments) const override;\nprotected:\n    /// Index of variable in YacasPatternPredicateBase::iVariables.\n    int iVarIndex;\n};\n\ninline\nMatchVariable::MatchVariable(int aVarIndex):\n    iVarIndex(aVarIndex)\n{\n}\n\n/// Class that matches function arguments to a pattern.\n/// This class (specifically, the Matches() member function) can match\n/// function parameters to a pattern, check for predicates on the\n/// arguments, and return whether there was a match.\nclass YacasPatternPredicateBase: NonCopyable {\npublic:\n    /// Constructor.\n    /// \\param aEnvironment the underlying Lisp environment\n    /// \\param aPattern Lisp expression containing the pattern\n    /// \\param aPostPredicate Lisp expression containing the\n    /// postpredicate\n    ///\n    /// The function MakePatternMatcher() is called for every argument\n    /// in \\a aPattern, and the resulting pattern matchers are\n    /// collected in #iParamMatchers. Additionally, \\a aPostPredicate\n    /// is copied, and the copy is added to #iPredicates.\n    YacasPatternPredicateBase(LispEnvironment& aEnvironment,\n                              LispPtr& aPattern,\n                              LispPtr& aPostPredicate);\n\n    /// Destructor.\n    virtual ~YacasPatternPredicateBase();\n\n    /// Try to match the pattern against \\a aArguments.\n    /// First, every argument in \\a aArguments is matched against the\n    /// corresponding YacasParamMatcherBase in #iParamMatches. If any\n    /// match fails, Matches() returns false. Otherwise, a temporary\n    /// LispLocalFrame is constructed, then SetPatternVariables() and\n    /// CheckPredicates() are called, and then the LispLocalFrame is\n    /// immediately deleted. If CheckPredicates() returns false, this\n    /// function also returns false. Otherwise, SetPatternVariables()\n    /// is called again, but now in the current LispLocalFrame, and\n    /// this function returns true.\n    bool Matches(LispEnvironment& aEnvironment, LispPtr& aArguments);\n\n    /// Try to match the pattern against \\a aArguments.\n    /// This function does the same as Matches(LispEnvironment&,LispPtr&),\n    /// but differs in the type of the arguments.\n    bool Matches(LispEnvironment& aEnvironment, LispPtr* aArguments);\n\nprotected:\n    /// Construct a pattern matcher out of a Lisp expression.\n    /// The result of this function depends on the value of \\a aPattern:\n    /// - If \\a aPattern is a number, the corresponding MatchNumber is\n    ///   constructed and returned.\n    /// - If \\a aPattern is an atom, the corresponding MatchAtom is\n    ///   constructed and returned.\n    /// - If \\a aPattern is a list of the form <tt>( _ var )</tt>,\n    ///   where \\c var is an atom, LookUp() is called on \\c var. Then\n    ///   the corresponding MatchVariable is constructed and returned.\n    /// - If \\a aPattern is a list of the form <tt>( _ var expr )</tt>,\n    ///   where \\c var is an atom, LookUp() is called on \\c var. Then,\n    ///   \\a expr is appended to #iPredicates. Finally, the\n    ///   correspoding MatchVariable is constructed and returned.\n    /// - If \\a aPattern is a list of another form, this function\n    ///   calls itself on any of the entries in this list. The\n    ///   resulting YacasParamMatcherBase objects are collected in a\n    ///   MatchSubList, which is returned.\n    /// - Otherwise, this function returns #nullptr.\n    const YacasParamMatcherBase* MakeParamMatcher(LispEnvironment& aEnvironment, LispObject* aPattern);\n\n    /// Look up a variable name in #iVariables\n    /// \\returns index in #iVariables array where \\a aVariable\n    /// appears.\n    ///\n    /// If \\a aVariable is not in #iVariables, it is added.\n    int LookUp(const LispString* aVariable);\n\nprotected:\n    /// Set local variables corresponding to the pattern variables.\n    /// This function goes through the #iVariables array. A local\n    /// variable is made for every entry in the array, and the\n    /// corresponding argument is assigned to it.\n    void SetPatternVariables(LispEnvironment& aEnvironment, LispPtr* arguments);\n\n    /// Check whether all predicates are true.\n    /// This function goes through all predicates in #iPredicates, and\n    /// evaluates them. It returns #false if at least one\n    /// of these results IsFalse(). An error is raised if any result\n    /// neither IsTrue() nor IsFalse().\n    bool CheckPredicates(LispEnvironment& aEnvironment);\n\nprotected:\n    /// List of parameter matches, one for every parameter.\n    std::vector<const YacasParamMatcherBase*> iParamMatchers;\n\n    /// List of variables appearing in the pattern.\n    std::vector<LispStringSmartPtr> iVariables;\n\n    /// List of predicates which need to be true for a match.\n    std::vector<LispPtr> iPredicates;\n};\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/platfileio.h",
    "content": "#ifndef YACAS_PLATFILEIO_H\n#define YACAS_PLATFILEIO_H\n\n#include \"lispenvironment.h\"\n#include \"noncopyable.h\"\n\n#include <fstream>\n#include <iostream>\n\nclass LispLocalFile: NonCopyable {\npublic:\n    LispLocalFile(\n        LispEnvironment& environment,\n        const std::string& fname,\n        bool read,\n        const std::vector<std::string>& dirs);\n    virtual ~LispLocalFile();\n\npublic:\n    std::fstream stream;\n    LispEnvironment& environment;\n};\n\nclass StdFileInput: public LispInput {\npublic:\n    StdFileInput(std::istream&, InputStatus& aStatus);\n    StdFileInput(LispLocalFile& aFile,InputStatus& aStatus);\n\n    char32_t Next() override;\n    char32_t Peek() override;\n    bool EndOfStream() const override;\n    virtual void Rewind();\n    std::size_t Position() const override;\n    void SetPosition(std::size_t) override;\n    \nprivate:\n    void _get() const;\n\n    std::istream& _stream;\n    std::size_t _position;\n    mutable bool _cp_ready;\n    mutable char32_t _cp;\n};\n\nclass StdUserInput final: public StdFileInput {\npublic:\n    StdUserInput(InputStatus& aStatus):\n        StdFileInput(std::cin, aStatus)\n    {\n    }\n};\n\n\nstd::string InternalFindFile(const std::string& fname, const std::vector<std::string>& dirs);\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/platmath.h",
    "content": "#ifndef YACAS_PLATMATH_H\n#define YACAS_PLATMATH_H\n\n#include \"lispenvironment.h\"\n\n// // Beware the use of these functions! They cannot be guaranteed to be\n// // supported on any platform.\n// double GetDouble(LispObject* aInteger);\n// LispObject* Double(LispEnvironment& aEnvironment,double aValue);\n\n// LispObject* PlatArcSin(LispEnvironment& aEnvironment,LispObject* int1, int aPrecision);\n// LispObject* PlatLn(LispEnvironment& aEnvironment,LispObject* int1, int aPrecision);\n// LispObject* PlatPower(LispEnvironment& aEnvironment,LispObject* int1, LispObject* int2,\n//                         int aPrecision);\n\n// LispObject* PlatDiv(LispEnvironment& aEnvironment,LispObject* int1, LispObject* int2,int aPrecision);\n\n// LispObject* PlatIsPrime(LispEnvironment& aEnvironment,LispObject* int1, int aPrecision);\n\n// table lookup for small prime numbers\nunsigned primes_table_check(unsigned long p);\nunsigned primes_table_range();\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/refcount.h",
    "content": "#ifndef YACAS_REFCOUNT_H\r\n#define YACAS_REFCOUNT_H\r\n\r\n#include <cassert>\r\n\r\n//------------------------------------------------------------------------------\r\n// RefPtr - Smart pointer for (intrusive) reference counting.\r\n// Simply, an object's reference count is the number of RefPtrs referring to it.\r\n// The RefPtr will delete the referenced object when the count reaches zero.\r\n\r\n/*TODO: this might be improved a little by having RefPtr wrap the object being\r\n  pointed to so the user of RefPtr does not need to add ReferenceCount explicitly.\r\n  One can use RefPtr on any arbitrary object from that moment on.\r\n */\r\n\r\ntemplate<class T>\r\nclass RefPtr {\r\npublic:\r\n  // Default constructor (not explicit, so it auto-initializes)\r\n  inline RefPtr() : iPtr(nullptr) {}\r\n  // Construct from pointer to T\r\n  /*explicit*/ RefPtr(T* ptr) : iPtr(ptr) { if (ptr) { ptr->_use_count++; } }\r\n  // Copy constructor\r\n  RefPtr(const RefPtr &refPtr) : iPtr(refPtr.ptr()) { if (iPtr) { iPtr->_use_count++; } }\r\n  // Destructor\r\n  ~RefPtr()\r\n  {\r\n      if (iPtr && !--iPtr->_use_count)\r\n        delete iPtr;\r\n  }\r\n  // Assignment from pointer\r\n  RefPtr &operator=(T *ptr)\r\n  {\r\n    if (ptr)\r\n      ptr->_use_count++;\r\n\r\n    if (iPtr && !--iPtr->_use_count)\r\n      delete iPtr;\r\n\r\n    iPtr = ptr;\r\n\r\n    return *this;\r\n  }\r\n  // Assignment from another\r\n  RefPtr &operator=(const RefPtr &refPtr) { return this->operator=(refPtr.ptr()); }\r\n\r\n  operator T*()    const { return  iPtr; }  // implicit conversion to pointer to T\r\n  T &operator*()   const { return *iPtr; }  // so (*refPtr) is a reference to T\r\n  T *operator->()  const { return  iPtr; }  // so (refPtr->member) accesses T's member\r\n  T *ptr()         const { return  iPtr; }  // so (refPtr.ptr()) returns the pointer to T (boost calls this method 'get')\r\n  bool operator!() const { return !iPtr; }  // is null pointer\r\n\r\nprivate:\r\n   T *iPtr;\r\n};\r\n\r\nclass RefCount {\r\npublic:\r\n  RefCount(): _use_count(0) {}\r\n  RefCount(const RefCount&): _use_count(0) {}\r\n\r\n  virtual ~RefCount() = default;\r\n\r\n  RefCount& operator = (const RefCount&) { return *this; }\r\n\r\n  unsigned use_count() const { return _use_count; }\r\n\r\nprivate:\r\n  template <typename T> friend class RefPtr;\r\n\r\n  mutable unsigned _use_count;\r\n};\r\n\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/standard.h",
    "content": "#ifndef YACAS_STANDARD_H\n#define YACAS_STANDARD_H\n\n#include \"lispobject.h\"\n#include \"lispenvironment.h\"\n#include \"lisphash.h\"\n#include \"lispatom.h\"\n#include \"numbers.h\"\n\n// Prototypes\nclass LispHashTable;\n\nbool InternalIsList(const LispEnvironment& env, const LispPtr& aPtr);\nbool InternalIsString(const LispString* aOriginal);\nstd::string InternalUnstringify(const std::string& s);\nint InternalAsciiToInt(const LispString& aString);\nbool IsNumber(const std::string& s, bool aAllowFloat);\n\nvoid InternalNth(LispPtr& aResult, const LispPtr& aArg, int n);\nvoid InternalTail(LispPtr& aResult, const LispPtr& aArg);\nvoid InternalAssociate(LispPtr& aResult, const LispPtr& aKey,\n                      const LispPtr& aAssociationList);\n\nvoid InternalReverseList(LispPtr& aResult, const LispPtr& aOriginal);\nvoid InternalFlatCopy(LispPtr& aResult, const LispPtr& aOriginal);\nstd::size_t InternalListLength(const LispPtr& aOriginal);\n\nbool InternalStrictTotalOrder(const LispEnvironment& env,\n                  const LispPtr& e1,\n                  const LispPtr& e2);\n\nbool InternalEquals(const LispEnvironment& aEnvironment,\n                    const LispPtr& aExpression1,\n                    const LispPtr& aExpression2);\n\n\ninline LispPtr& Argument(LispPtr& cur, int n);\n\ninline void InternalTrue(const LispEnvironment& aEnvironment, LispPtr& aResult);\ninline void InternalFalse(const LispEnvironment& aEnvironment, LispPtr& aResult);\ninline void InternalBoolean(LispEnvironment& aEnvironment, LispPtr& aResult,\n                            bool aValue);\ninline bool IsTrue(LispEnvironment& aEnvironment, const LispPtr& aExpression);\ninline bool IsFalse(LispEnvironment& aEnvironment, const LispPtr& aExpression);\ninline void InternalNot(LispPtr& aResult, LispEnvironment& aEnvironment, LispPtr& aExpression);\n\nvoid DoInternalLoad(LispEnvironment& aEnvironment,LispInput* aInput);\nvoid InternalLoad(LispEnvironment& aEnvironment, const std::string& aFileName);\nvoid InternalUse(LispEnvironment& aEnvironment, const std::string& aFileName);\nvoid InternalApplyString(LispEnvironment& aEnvironment, LispPtr& aResult,\n                         const LispString* aOperator,LispPtr& aArgs);\nvoid InternalApplyPure(LispPtr& oper,LispPtr& args2,LispPtr& aResult,LispEnvironment& aEnvironment);\n\nvoid InternalEvalString(LispEnvironment& aEnvironment, LispPtr& aResult,\n                        const char* aString);\n\nclass LispObjectAdder {\npublic:\n    LispObjectAdder(LispObject* aPtr)\n        : iPtr(aPtr) {};\n   LispObject* iPtr;\n};\n\nLispObject* operator+(const LispObjectAdder& left, const LispObjectAdder& right);\n\nvoid ParseExpression(LispPtr& aResult, const char* aString, LispEnvironment& aEnvironment);\n\nvoid ReturnUnEvaluated(LispPtr& aResult,LispPtr& aArguments,\n                       LispEnvironment& aEnvironment);\n\n/** PrintExpression : print an expression into a string,\n limiting it to a maximum number of characters. If aMaxChars\n is less than zero, the result is not truncated.\n */\nvoid PrintExpression(LispString& aResult,\n                     LispPtr& aExpression,\n                     LispEnvironment& aEnvironment,\n                     std::size_t aMaxChars);\n\nconst LispString* SymbolName(LispEnvironment& aEnvironment, const std::string& aSymbol);\n\n\n\n\n#include \"standard.inl\"\n\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/standard.inl",
    "content": "\n\n\ninline LispPtr& Argument(LispPtr& cur, int n)\n{\n    assert(n>=0);\n\n    LispPtr* loop = &cur;\n    while(n--) loop = &(*loop)->Nixed();\n    return *loop;\n}\n\n// Boolean operations\ninline void InternalTrue(const LispEnvironment& aEnvironment, LispPtr& aResult)\n{\n    aResult = (aEnvironment.iTrue->Copy());\n}\n\ninline void InternalFalse(const LispEnvironment& aEnvironment, LispPtr& aResult)\n{\n    aResult = (aEnvironment.iFalse->Copy());\n}\n\ninline void InternalBoolean(LispEnvironment& aEnvironment, LispPtr& aResult,\n                            bool aValue)\n{\n    if (aValue)\n    {\n        InternalTrue(aEnvironment, aResult);\n    }\n    else\n    {\n        InternalFalse(aEnvironment, aResult);\n    }\n}\n\n\ninline bool IsTrue(LispEnvironment& aEnvironment, const LispPtr& aExpression)\n{\n    assert(aExpression);\n    return aExpression->String() == aEnvironment.iTrue->String();\n}\ninline bool IsFalse(LispEnvironment& aEnvironment, const LispPtr& aExpression)\n{\n    assert(aExpression);\n    return aExpression->String() == aEnvironment.iFalse->String();\n}\n\n\ninline void InternalNot(LispPtr& aResult, LispEnvironment& aEnvironment, LispPtr& aExpression)\n{\n    if (IsTrue(aEnvironment, aExpression))\n    {\n        InternalFalse(aEnvironment,aResult);\n    }\n    else\n    {\n        if (!IsFalse(aEnvironment, aExpression))\n            throw LispErrInvalidArg();\n\n        InternalTrue(aEnvironment,aResult);\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/string_utils.h",
    "content": "#ifndef STRING_UTILS_H\n#define STRING_UTILS_H\n\n#include <algorithm>\n#include <functional>\n#include <cctype>\n#include <locale>\n#include <string>\n\ninline\nstd::string stringify(const std::string& s)\n{\n    return \"\\\"\" + s + \"\\\"\";\n}\n\ninline\nstd::string& ltrim(std::string& s)\n{\n    s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); }));\n    return s;\n}\n\ninline\nstd::string& rtrim(std::string& s)\n{\n    s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end());\n    return s;\n}\n\ninline\nstd::string& trim(std::string& s)\n{\n    return ltrim(rtrim(s));\n}\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/stringio.h",
    "content": "/** \\file stringio.h\n * definitions of input output classes that read and write from string.\n */\n\n#ifndef YACAS_STRINGIO_H\n#define YACAS_STRINGIO_H\n\n#include \"lispio.h\"\n#include \"utf8.h\"\n\n#include <string>\n\nclass StringInput final: public LispInput\n{\npublic:\n    StringInput(const std::string&, InputStatus&);\n    char32_t Next() override;\n    char32_t Peek() override;\n    bool EndOfStream() const override;\n    std::size_t Position() const override;\n    void SetPosition(std::size_t aPosition) override;\nprotected:\n    std::string _string;\n    std::string::const_iterator _current;\n};\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/substitute.h",
    "content": "#ifndef YACAS_SUBSTITUTE_H\n#define YACAS_SUBSTITUTE_H\n\n#include \"lispobject.h\"\n#include \"lispenvironment.h\"\n\n#include <vector>\n\n/** Behaviour for substituting sub-expressions.\n */\nclass SubstBehaviourBase {\npublic:\n    virtual ~SubstBehaviourBase() = default;\n    virtual bool Matches(LispPtr& aResult, LispPtr& aElement) = 0;\n};\n\n/** main routine that can perform substituting of expressions\n */\nvoid InternalSubstitute(LispPtr& aTarget, LispPtr& aSource,\n                        SubstBehaviourBase& aBehaviour);\n\n\n/** Substing one expression for another. The simplest form\n * of substitution\n */\nclass SubstBehaviour final: public SubstBehaviourBase\n{\npublic:\n    SubstBehaviour(LispEnvironment& aEnvironment,LispPtr& aToMatch,\n                  LispPtr& aToReplaceWith);\n    bool Matches(LispPtr& aResult, LispPtr& aElement) override;\nprivate:\n    LispEnvironment& iEnvironment;\n    LispPtr& iToMatch;\n    LispPtr& iToReplaceWith;\n};\n\n/** subst behaviour for changing the local variables to have unique\n * names.\n */\nclass LocalSymbolBehaviour final: public SubstBehaviourBase\n{\npublic:\n    LocalSymbolBehaviour(\n        LispEnvironment& aEnvironment,\n        const std::vector<const LispString*>&& aOriginalNames,\n        const std::vector<const LispString*>&& aNewNames);\n\n    bool Matches(LispPtr& aResult, LispPtr& aElement) override;\n\nprivate:\n    LispEnvironment& iEnvironment;\n    std::vector<const LispString*> iOriginalNames;\n    std::vector<const LispString*> iNewNames;\n};\n\n/** subst behaviour for backquote mechanism as in LISP.\n * When typing `(...) all occurrences of @a will be\n * replaced with:\n * 1) a evaluated if a is an atom\n * 2) function call with function name replaced by evaluated\n *    head of function if a is a function. For instance, if\n *    a is f(x) and f is g, then f(x) gets replaced by g(x)\n */\nclass BackQuoteBehaviour final: public SubstBehaviourBase\n{\npublic:\n    BackQuoteBehaviour(LispEnvironment& aEnvironment)\n        : iEnvironment(aEnvironment) {};\n    bool Matches(LispPtr& aResult, LispPtr& aElement) override;\n    \nprivate:\n    LispEnvironment& iEnvironment;\n};\n\n\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/tokenizer.h",
    "content": "/** \\file tokenizer.h\n * definitions of input output classes that read and write from string.\n */\n\n\n#ifndef YACAS_TOKENIZER_H\n#define YACAS_TOKENIZER_H\n\n#include \"lispio.h\"\n\n#include <cctype>\n#include <cstdint>\n#include <string>\n\nclass LispTokenizer {\npublic:\n    virtual ~LispTokenizer() = default;\n\n    /// NextToken returns a string representing the next token,\n    /// or an empty list.\n    virtual std::string NextToken(LispInput& aInput);\n};\n\n// utility functions\n#ifdef YACAS_UINT32_T_IN_GLOBAL_NAMESPACE\n    bool IsAlpha(uint32_t c);\n    bool IsAlNum(uint32_t c);\n#else\n    bool IsAlpha(std::uint32_t c);\n    bool IsAlNum(std::uint32_t c);\n#endif\n\nbool IsSymbolic(char c);\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/utf8/checked.h",
    "content": "// Copyright 2006-2016 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n*/\n\n\n#ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731\n#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731\n\n#include \"core.h\"\n#include <stdexcept>\n\nnamespace utf8\n{\n    // Base for the exceptions that may be thrown from the library\n    class exception : public ::std::exception {\n    };\n\n    // Exceptions that may be thrown from the library functions.\n    class invalid_code_point : public exception {\n        utfchar32_t cp;\n    public:\n        invalid_code_point(utfchar32_t codepoint) : cp(codepoint) {}\n        virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return \"Invalid code point\"; }\n        utfchar32_t code_point() const {return cp;}\n    };\n\n    class invalid_utf8 : public exception {\n        utfchar8_t u8;\n    public:\n        invalid_utf8 (utfchar8_t u) : u8(u) {}\n        invalid_utf8 (char c) : u8(static_cast<utfchar8_t>(c)) {}\n        virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return \"Invalid UTF-8\"; }\n        utfchar8_t utf8_octet() const {return u8;}\n    };\n\n    class invalid_utf16 : public exception {\n        utfchar16_t u16;\n    public:\n        invalid_utf16 (utfchar16_t u) : u16(u) {}\n        virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return \"Invalid UTF-16\"; }\n        utfchar16_t utf16_word() const {return u16;}\n    };\n\n    class not_enough_room : public exception {\n    public:\n        virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return \"Not enough space\"; }\n    };\n\n    /// The library API - functions intended to be called by the users\n\n    template <typename octet_iterator>\n    octet_iterator append(utfchar32_t cp, octet_iterator result)\n    {\n        if (!utf8::internal::is_code_point_valid(cp))\n            throw invalid_code_point(cp);\n\n        return internal::append(cp, result);\n    }\n\n    inline void append(utfchar32_t cp, std::string& s)\n    {\n        append(cp, std::back_inserter(s));\n    }\n\n    template <typename word_iterator>\n    word_iterator append16(utfchar32_t cp, word_iterator result)\n    {\n        if (!utf8::internal::is_code_point_valid(cp))\n            throw invalid_code_point(cp);\n\n        return internal::append16(cp, result);\n    }\n\n    template <typename octet_iterator, typename output_iterator>\n    output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, utfchar32_t replacement)\n    {\n        while (start != end) {\n            octet_iterator sequence_start = start;\n            internal::utf_error err_code = utf8::internal::validate_next(start, end);\n            switch (err_code) {\n                case internal::UTF8_OK :\n                    for (octet_iterator it = sequence_start; it != start; ++it)\n                        *out++ = *it;\n                    break;\n                case internal::NOT_ENOUGH_ROOM:\n                    out = utf8::append (replacement, out);\n                    start = end;\n                    break;\n                case internal::INVALID_LEAD:\n                    out = utf8::append (replacement, out);\n                    ++start;\n                    break;\n                case internal::INCOMPLETE_SEQUENCE:\n                case internal::OVERLONG_SEQUENCE:\n                case internal::INVALID_CODE_POINT:\n                    out = utf8::append (replacement, out);\n                    ++start;\n                    // just one replacement mark for the sequence\n                    while (start != end && utf8::internal::is_trail(*start))\n                        ++start;\n                    break;\n            }\n        }\n        return out;\n    }\n\n    template <typename octet_iterator, typename output_iterator>\n    inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)\n    {\n        static const utfchar32_t replacement_marker = static_cast<utfchar32_t>(utf8::internal::mask16(0xfffd));\n        return utf8::replace_invalid(start, end, out, replacement_marker);\n    }\n\n    inline std::string replace_invalid(const std::string& s, utfchar32_t replacement)\n    {\n        std::string result;\n        replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement);\n        return result;\n    }\n\n    inline std::string replace_invalid(const std::string& s)\n    {\n        std::string result;\n        replace_invalid(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    template <typename octet_iterator>\n    utfchar32_t next(octet_iterator& it, octet_iterator end)\n    {\n        utfchar32_t cp = 0;\n        internal::utf_error err_code = utf8::internal::validate_next(it, end, cp);\n        switch (err_code) {\n            case internal::UTF8_OK :\n                break;\n            case internal::NOT_ENOUGH_ROOM :\n                throw not_enough_room();\n            case internal::INVALID_LEAD :\n            case internal::INCOMPLETE_SEQUENCE :\n            case internal::OVERLONG_SEQUENCE :\n                throw invalid_utf8(static_cast<utfchar8_t>(*it));\n            case internal::INVALID_CODE_POINT :\n                throw invalid_code_point(cp);\n        }\n        return cp;\n    }\n\n    template <typename word_iterator>\n    utfchar32_t next16(word_iterator& it, word_iterator end)\n    {\n        utfchar32_t cp = 0;\n        internal::utf_error err_code = utf8::internal::validate_next16(it, end, cp);\n        if (err_code == internal::NOT_ENOUGH_ROOM)\n            throw not_enough_room();\n        return cp;\n    }\n\n    template <typename octet_iterator>\n    utfchar32_t peek_next(octet_iterator it, octet_iterator end)\n    {\n        return utf8::next(it, end);\n    }\n\n    template <typename octet_iterator>\n    utfchar32_t prior(octet_iterator& it, octet_iterator start)\n    {\n        // can't do much if it == start\n        if (it == start)\n            throw not_enough_room();\n\n        octet_iterator end = it;\n        // Go back until we hit either a lead octet or start\n        while (utf8::internal::is_trail(*(--it)))\n            if (it == start)\n                throw invalid_utf8(*it); // error - no lead byte in the sequence\n        return utf8::peek_next(it, end);\n    }\n\n    template <typename octet_iterator, typename distance_type>\n    void advance (octet_iterator& it, distance_type n, octet_iterator end)\n    {\n        const distance_type zero(0);\n        if (n < zero) {\n            // backward\n            for (distance_type i = n; i < zero; ++i)\n                utf8::prior(it, end);\n        } else {\n            // forward\n            for (distance_type i = zero; i < n; ++i)\n                utf8::next(it, end);\n        }\n    }\n\n    template <typename octet_iterator>\n    typename std::iterator_traits<octet_iterator>::difference_type\n    distance (octet_iterator first, octet_iterator last)\n    {\n        typename std::iterator_traits<octet_iterator>::difference_type dist;\n        for (dist = 0; first < last; ++dist)\n            utf8::next(first, last);\n        return dist;\n    }\n\n    template <typename u16bit_iterator, typename octet_iterator>\n    octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)\n    {\n        while (start != end) {\n            utfchar32_t cp = static_cast<utfchar32_t>(utf8::internal::mask16(*start++));\n            // Take care of surrogate pairs first\n            if (utf8::internal::is_lead_surrogate(cp)) {\n                if (start != end) {\n                    const utfchar32_t trail_surrogate = static_cast<utfchar32_t>(utf8::internal::mask16(*start++));\n                    if (utf8::internal::is_trail_surrogate(trail_surrogate))\n                        cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;\n                    else\n                        throw invalid_utf16(static_cast<utfchar16_t>(trail_surrogate));\n                }\n                else\n                    throw invalid_utf16(static_cast<utfchar16_t>(cp));\n\n            }\n            // Lone trail surrogate\n            else if (utf8::internal::is_trail_surrogate(cp))\n                throw invalid_utf16(static_cast<utfchar16_t>(cp));\n\n            result = utf8::append(cp, result);\n        }\n        return result;\n    }\n\n    template <typename u16bit_iterator, typename octet_iterator>\n    u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)\n    {\n        while (start < end) {\n            const utfchar32_t cp = utf8::next(start, end);\n            if (cp > 0xffff) { //make a surrogate pair\n                *result++ = static_cast<utfchar16_t>((cp >> 10)   + internal::LEAD_OFFSET);\n                *result++ = static_cast<utfchar16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);\n            }\n            else\n                *result++ = static_cast<utfchar16_t>(cp);\n        }\n        return result;\n    }\n\n    template <typename octet_iterator, typename u32bit_iterator>\n    octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)\n    {\n        while (start != end)\n            result = utf8::append(*(start++), result);\n\n        return result;\n    }\n\n    template <typename octet_iterator, typename u32bit_iterator>\n    u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)\n    {\n        while (start < end)\n            (*result++) = utf8::next(start, end);\n\n        return result;\n    }\n\n    // The iterator class\n    template <typename octet_iterator>\n    class iterator {\n      octet_iterator it;\n      octet_iterator range_start;\n      octet_iterator range_end;\n      public:\n      typedef utfchar32_t value_type;\n      typedef utfchar32_t* pointer;\n      typedef utfchar32_t& reference;\n      typedef std::ptrdiff_t difference_type;\n      typedef std::bidirectional_iterator_tag iterator_category;\n      iterator () {}\n      explicit iterator (const octet_iterator& octet_it,\n                         const octet_iterator& rangestart,\n                         const octet_iterator& rangeend) :\n               it(octet_it), range_start(rangestart), range_end(rangeend)\n      {\n          if (it < range_start || it > range_end)\n              throw std::out_of_range(\"Invalid utf-8 iterator position\");\n      }\n      // the default \"big three\" are OK\n      octet_iterator base () const { return it; }\n      utfchar32_t operator * () const\n      {\n          octet_iterator temp = it;\n          return utf8::next(temp, range_end);\n      }\n      bool operator == (const iterator& rhs) const\n      {\n          if (range_start != rhs.range_start || range_end != rhs.range_end)\n              throw std::logic_error(\"Comparing utf-8 iterators defined with different ranges\");\n          return (it == rhs.it);\n      }\n      bool operator != (const iterator& rhs) const\n      {\n          return !(operator == (rhs));\n      }\n      iterator& operator ++ ()\n      {\n          utf8::next(it, range_end);\n          return *this;\n      }\n      iterator operator ++ (int)\n      {\n          iterator temp = *this;\n          utf8::next(it, range_end);\n          return temp;\n      }\n      iterator& operator -- ()\n      {\n          utf8::prior(it, range_start);\n          return *this;\n      }\n      iterator operator -- (int)\n      {\n          iterator temp = *this;\n          utf8::prior(it, range_start);\n          return temp;\n      }\n    }; // class iterator\n\n} // namespace utf8\n\n#if UTF_CPP_CPLUSPLUS >= 202002L // C++ 20 or later\n#include \"cpp20.h\"\n#elif UTF_CPP_CPLUSPLUS >= 201703L // C++ 17 or later\n#include \"cpp17.h\"\n#elif UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later\n#include \"cpp11.h\"\n#endif // C++ 11 or later\n\n#endif //header guard\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/utf8/core.h",
    "content": "// Copyright 2006 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n*/\n\n\n#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731\n#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731\n\n#include <iterator>\n#include <cstring>\n#include <string>\n\n// Determine the C++ standard version.\n// If the user defines UTF_CPP_CPLUSPLUS, use that.\n// Otherwise, trust the unreliable predefined macro __cplusplus\n\n#if !defined UTF_CPP_CPLUSPLUS\n    #define UTF_CPP_CPLUSPLUS __cplusplus\n#endif\n\n#if UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later\n    #define UTF_CPP_OVERRIDE override\n    #define UTF_CPP_NOEXCEPT noexcept\n    #define UTF_CPP_STATIC_ASSERT(condition) static_assert(condition, \"UTFCPP static assert\");\n#else // C++ 98/03\n    #define UTF_CPP_OVERRIDE\n    #define UTF_CPP_NOEXCEPT throw()\n    // Not worth simulating static_assert:\n    #define UTF_CPP_STATIC_ASSERT(condition) (void)(condition);\n#endif // C++ 11 or later\n\n\nnamespace utf8\n{\n// The typedefs for 8-bit, 16-bit and 32-bit code units\n#if UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later\n    #if UTF_CPP_CPLUSPLUS >= 202002L // C++ 20 or later\n        typedef char8_t         utfchar8_t;\n    #else // C++ 11/14/17\n        typedef unsigned char   utfchar8_t;\n    #endif\n    typedef char16_t        utfchar16_t;\n    typedef char32_t        utfchar32_t;\n#else // C++ 98/03\n    typedef unsigned char   utfchar8_t;\n    typedef unsigned short  utfchar16_t;\n    typedef unsigned int    utfchar32_t;\n#endif // C++ 11 or later\n\n// Helper code - not intended to be directly called by the library users. May be changed at any time\nnamespace internal\n{\n    // Unicode constants\n    // Leading (high) surrogates: 0xd800 - 0xdbff\n    // Trailing (low) surrogates: 0xdc00 - 0xdfff\n    const utfchar16_t LEAD_SURROGATE_MIN  = 0xd800u;\n    const utfchar16_t LEAD_SURROGATE_MAX  = 0xdbffu;\n    const utfchar16_t TRAIL_SURROGATE_MIN = 0xdc00u;\n    const utfchar16_t TRAIL_SURROGATE_MAX = 0xdfffu;\n    const utfchar16_t LEAD_OFFSET         = 0xd7c0u;       // LEAD_SURROGATE_MIN - (0x10000 >> 10)\n    const utfchar32_t SURROGATE_OFFSET    = 0xfca02400u;   // 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN\n\n    // Maximum valid value for a Unicode code point\n    const utfchar32_t CODE_POINT_MAX      = 0x0010ffffu;\n\n    template<typename octet_type>\n    inline utfchar8_t mask8(octet_type oc)\n    {\n        return static_cast<utfchar8_t>(0xff & oc);\n    }\n\n    template<typename u16_type>\n    inline utfchar16_t mask16(u16_type oc)\n    {\n        return static_cast<utfchar16_t>(0xffff & oc);\n    }\n\n    template<typename octet_type>\n    inline bool is_trail(octet_type oc)\n    {\n        return ((utf8::internal::mask8(oc) >> 6) == 0x2);\n    }\n\n    inline bool is_lead_surrogate(utfchar32_t cp)\n    {\n        return (cp >= static_cast<utfchar32_t>(LEAD_SURROGATE_MIN) && cp <= static_cast<utfchar32_t>(LEAD_SURROGATE_MAX));\n    }\n\n    inline bool is_trail_surrogate(utfchar32_t cp)\n    {\n        return (cp >= static_cast<utfchar32_t>(TRAIL_SURROGATE_MIN) && cp <= static_cast<utfchar32_t>(TRAIL_SURROGATE_MAX));\n    }\n\n    inline bool is_surrogate(utfchar32_t cp)\n    {\n        return (cp >= static_cast<utfchar32_t>(LEAD_SURROGATE_MIN) && cp <= static_cast<utfchar32_t>(TRAIL_SURROGATE_MAX));\n    }\n\n    inline bool is_code_point_valid(utfchar32_t cp)\n    {\n        return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp));\n    }\n\n    inline bool is_in_bmp(utfchar32_t cp)\n    {\n        return cp < utfchar32_t(0x10000);\n    }\n\n    template <typename octet_iterator>\n    int sequence_length(octet_iterator lead_it)\n    {\n        const utfchar8_t lead = utf8::internal::mask8(*lead_it);\n        if (lead < 0x80)\n            return 1;\n        else if ((lead >> 5) == 0x6)\n            return 2;\n        else if ((lead >> 4) == 0xe)\n            return 3;\n        else if ((lead >> 3) == 0x1e)\n            return 4;\n        else\n            return 0;\n    }\n\n    inline bool is_overlong_sequence(utfchar32_t cp, int length)\n    {\n        if (cp < 0x80) {\n            if (length != 1)\n                return true;\n        }\n        else if (cp < 0x800) {\n            if (length != 2)\n                return true;\n        }\n        else if (cp < 0x10000) {\n            if (length != 3)\n                return true;\n        }\n        return false;\n    }\n\n    enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT};\n\n    /// Helper for get_sequence_x\n    template <typename octet_iterator>\n    utf_error increase_safely(octet_iterator& it, const octet_iterator end)\n    {\n        if (++it == end)\n            return NOT_ENOUGH_ROOM;\n\n        if (!utf8::internal::is_trail(*it))\n            return INCOMPLETE_SEQUENCE;\n\n        return UTF8_OK;\n    }\n\n    #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;}\n\n    /// get_sequence_x functions decode utf-8 sequences of the length x\n    template <typename octet_iterator>\n    utf_error get_sequence_1(octet_iterator& it, octet_iterator end, utfchar32_t& code_point)\n    {\n        if (it == end)\n            return NOT_ENOUGH_ROOM;\n\n        code_point = static_cast<utfchar32_t>(utf8::internal::mask8(*it));\n\n        return UTF8_OK;\n    }\n\n    template <typename octet_iterator>\n    utf_error get_sequence_2(octet_iterator& it, octet_iterator end, utfchar32_t& code_point)\n    {\n        if (it == end)\n            return NOT_ENOUGH_ROOM;\n\n        code_point = static_cast<utfchar32_t>(utf8::internal::mask8(*it));\n\n        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)\n\n        code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f);\n\n        return UTF8_OK;\n    }\n\n    template <typename octet_iterator>\n    utf_error get_sequence_3(octet_iterator& it, octet_iterator end, utfchar32_t& code_point)\n    {\n        if (it == end)\n            return NOT_ENOUGH_ROOM;\n\n        code_point = static_cast<utfchar32_t>(utf8::internal::mask8(*it));\n\n        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)\n\n        code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);\n\n        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)\n\n        code_point = static_cast<utfchar32_t>(code_point + ((*it) & 0x3f));\n\n        return UTF8_OK;\n    }\n\n    template <typename octet_iterator>\n    utf_error get_sequence_4(octet_iterator& it, octet_iterator end, utfchar32_t& code_point)\n    {\n        if (it == end)\n           return NOT_ENOUGH_ROOM;\n\n        code_point = static_cast<utfchar32_t>(utf8::internal::mask8(*it));\n\n        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)\n\n        code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);\n\n        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)\n\n        code_point = static_cast<utfchar32_t>(code_point + ((utf8::internal::mask8(*it) << 6) & 0xfff));\n\n        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)\n\n        code_point = static_cast<utfchar32_t>(code_point + ((*it) & 0x3f));\n\n        return UTF8_OK;\n    }\n\n    #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR\n\n    template <typename octet_iterator>\n    utf_error validate_next(octet_iterator& it, octet_iterator end, utfchar32_t& code_point)\n    {\n        if (it == end)\n            return NOT_ENOUGH_ROOM;\n\n        // Save the original value of it so we can go back in case of failure\n        // Of course, it does not make much sense with i.e. stream iterators\n        octet_iterator original_it = it;\n\n        utfchar32_t cp = 0;\n        // Determine the sequence length based on the lead octet\n        const int length = utf8::internal::sequence_length(it);\n\n        // Get trail octets and calculate the code point\n        utf_error err = UTF8_OK;\n        switch (length) {\n            case 0:\n                return INVALID_LEAD;\n            case 1:\n                err = utf8::internal::get_sequence_1(it, end, cp);\n                break;\n            case 2:\n                err = utf8::internal::get_sequence_2(it, end, cp);\n            break;\n            case 3:\n                err = utf8::internal::get_sequence_3(it, end, cp);\n            break;\n            case 4:\n                err = utf8::internal::get_sequence_4(it, end, cp);\n            break;\n        }\n\n        if (err == UTF8_OK) {\n            // Decoding succeeded. Now, security checks...\n            if (utf8::internal::is_code_point_valid(cp)) {\n                if (!utf8::internal::is_overlong_sequence(cp, length)){\n                    // Passed! Return here.\n                    code_point = cp;\n                    ++it;\n                    return UTF8_OK;\n                }\n                else\n                    err = OVERLONG_SEQUENCE;\n            }\n            else\n                err = INVALID_CODE_POINT;\n        }\n\n        // Failure branch - restore the original value of the iterator\n        it = original_it;\n        return err;\n    }\n\n    template <typename octet_iterator>\n    inline utf_error validate_next(octet_iterator& it, octet_iterator end) {\n        utfchar32_t ignored;\n        return utf8::internal::validate_next(it, end, ignored);\n    }\n\n    template <typename word_iterator>\n    utf_error validate_next16(word_iterator& it, word_iterator end, utfchar32_t& code_point)\n    {\n        // Make sure the iterator dereferences a large enough type\n        typedef typename std::iterator_traits<word_iterator>::value_type word_type;\n        UTF_CPP_STATIC_ASSERT(sizeof(word_type) >= sizeof(utfchar16_t));\n        // Check the edge case:\n        if (it == end)\n            return NOT_ENOUGH_ROOM;\n        // Save the original value of it so we can go back in case of failure\n        // Of course, it does not make much sense with i.e. stream iterators\n        word_iterator original_it = it;\n\n        utf_error err = UTF8_OK;\n\n        const utfchar16_t first_word = *it++;\n        if (!is_surrogate(first_word)) {\n            code_point = first_word;\n            return UTF8_OK;\n        }\n        else {\n            if (it == end)\n                err = NOT_ENOUGH_ROOM;\n            else if (is_lead_surrogate(first_word)) {\n                const utfchar16_t second_word = *it++;\n                if (is_trail_surrogate(static_cast<utfchar32_t>(second_word))) {\n                    code_point = static_cast<utfchar32_t>(first_word << 10) +  static_cast<utfchar32_t>(second_word) + SURROGATE_OFFSET;\n                    return UTF8_OK;\n                } else\n                    err = INCOMPLETE_SEQUENCE;\n\n            } else {\n                err = INVALID_LEAD;\n            }\n        }\n        // error branch\n        it = original_it;\n        return err;\n    }\n\n    // Internal implementation of both checked and unchecked append() function\n    // This function will be invoked by the overloads below, as they will know\n    // the octet_type.\n    template <typename octet_iterator, typename octet_type>\n    octet_iterator append(utfchar32_t cp, octet_iterator result) {\n        if (cp < 0x80)                        // one octet\n            *(result++) = static_cast<octet_type>(cp);\n        else if (cp < 0x800) {                // two octets\n            *(result++) = static_cast<octet_type>((cp >> 6)          | 0xc0);\n            *(result++) = static_cast<octet_type>((cp & 0x3f)        | 0x80);\n        }\n        else if (cp < 0x10000) {              // three octets\n            *(result++) = static_cast<octet_type>((cp >> 12)         | 0xe0);\n            *(result++) = static_cast<octet_type>(((cp >> 6) & 0x3f) | 0x80);\n            *(result++) = static_cast<octet_type>((cp & 0x3f)        | 0x80);\n        }\n        else {                                // four octets\n            *(result++) = static_cast<octet_type>((cp >> 18)         | 0xf0);\n            *(result++) = static_cast<octet_type>(((cp >> 12) & 0x3f)| 0x80);\n            *(result++) = static_cast<octet_type>(((cp >> 6) & 0x3f) | 0x80);\n            *(result++) = static_cast<octet_type>((cp & 0x3f)        | 0x80);\n        }\n        return result;\n    }\n\n    // One of the following overloads will be invoked from the API calls\n\n    // A simple (but dangerous) case: the caller appends byte(s) to a char array\n    inline char* append(utfchar32_t cp, char* result) {\n        return append<char*, char>(cp, result);\n    }\n\n    // Hopefully, most common case: the caller uses back_inserter\n    // i.e. append(cp, std::back_inserter(str));\n    template<typename container_type>\n    std::back_insert_iterator<container_type> append\n            (utfchar32_t cp, std::back_insert_iterator<container_type> result) {\n        return append<std::back_insert_iterator<container_type>,\n            typename container_type::value_type>(cp, result);\n    }\n\n    // The caller uses some other kind of output operator - not covered above\n    // Note that in this case we are not able to determine octet_type\n    // so we assume it's utfchar8_t; that can cause a conversion warning if we are wrong.\n    template <typename octet_iterator>\n    octet_iterator append(utfchar32_t cp, octet_iterator result) {\n        return append<octet_iterator, utfchar8_t>(cp, result);\n    }\n\n    // Internal implementation of both checked and unchecked append16() function\n    // This function will be invoked by the overloads below, as they will know\n    // the word_type.\n    template <typename word_iterator, typename word_type>\n    word_iterator append16(utfchar32_t cp, word_iterator result) {\n        UTF_CPP_STATIC_ASSERT(sizeof(word_type) >= sizeof(utfchar16_t));\n        if (is_in_bmp(cp))\n            *(result++) = static_cast<word_type>(cp);\n        else {\n            // Code points from the supplementary planes are encoded via surrogate pairs\n            *(result++) = static_cast<word_type>(LEAD_OFFSET + (cp >> 10));\n            *(result++) = static_cast<word_type>(TRAIL_SURROGATE_MIN + (cp & 0x3FF));\n        }\n        return result;\n    }\n\n    // Hopefully, most common case: the caller uses back_inserter\n    // i.e. append16(cp, std::back_inserter(str));\n    template<typename container_type>\n    std::back_insert_iterator<container_type> append16\n            (utfchar32_t cp, std::back_insert_iterator<container_type> result) {\n        return append16<std::back_insert_iterator<container_type>,\n            typename container_type::value_type>(cp, result);\n    }\n\n    // The caller uses some other kind of output operator - not covered above\n    // Note that in this case we are not able to determine word_type\n    // so we assume it's utfchar16_t; that can cause a conversion warning if we are wrong.\n    template <typename word_iterator>\n    word_iterator append16(utfchar32_t cp, word_iterator result) {\n        return append16<word_iterator, utfchar16_t>(cp, result);\n    }\n\n} // namespace internal\n\n    /// The library API - functions intended to be called by the users\n\n    // Byte order mark\n    const utfchar8_t bom[] = {0xef, 0xbb, 0xbf};\n\n    template <typename octet_iterator>\n    octet_iterator find_invalid(octet_iterator start, octet_iterator end)\n    {\n        octet_iterator result = start;\n        while (result != end) {\n            utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end);\n            if (err_code != internal::UTF8_OK)\n                return result;\n        }\n        return result;\n    }\n\n    inline const char* find_invalid(const char* str)\n    {\n        const char* end = str + std::strlen(str);\n        return find_invalid(str, end);\n    }\n\n    inline std::size_t find_invalid(const std::string& s)\n    {\n        std::string::const_iterator invalid = find_invalid(s.begin(), s.end());\n        return (invalid == s.end()) ? std::string::npos : static_cast<std::size_t>(invalid - s.begin());\n    }\n\n    template <typename octet_iterator>\n    inline bool is_valid(octet_iterator start, octet_iterator end)\n    {\n        return (utf8::find_invalid(start, end) == end);\n    }\n\n    inline bool is_valid(const char* str)\n    {\n        return (*(utf8::find_invalid(str)) == '\\0');\n    }\n\n    inline bool is_valid(const std::string& s)\n    {\n        return is_valid(s.begin(), s.end());\n    }\n\n\n\n    template <typename octet_iterator>\n    inline bool starts_with_bom (octet_iterator it, octet_iterator end)\n    {\n        return (\n            ((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) &&\n            ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) &&\n            ((it != end) && (utf8::internal::mask8(*it))   == bom[2])\n           );\n    }\n\n    inline bool starts_with_bom(const std::string& s)\n    {\n        return starts_with_bom(s.begin(), s.end());\n    }\n} // namespace utf8\n\n#endif // header guard\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/utf8/cpp11.h",
    "content": "// Copyright 2018 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n*/\n\n\n#ifndef UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1\n#define UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1\n\n#include \"checked.h\"\n\nnamespace utf8\n{\n    inline void append16(utfchar32_t cp, std::u16string& s)\n    {\n        append16(cp, std::back_inserter(s));\n    }\n\n    inline std::string utf16to8(const std::u16string& s)\n    {\n        std::string result;\n        utf16to8(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u16string utf8to16(const std::string& s)\n    {\n        std::u16string result;\n        utf8to16(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::string utf32to8(const std::u32string& s)\n    {\n        std::string result;\n        utf32to8(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u32string utf8to32(const std::string& s)\n    {\n        std::u32string result;\n        utf8to32(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n} // namespace utf8\n\n#endif // header guard\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/utf8/cpp17.h",
    "content": "// Copyright 2018 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n*/\n\n\n#ifndef UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9\n#define UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9\n\n#include \"cpp11.h\"\n\nnamespace utf8\n{\n    inline std::string utf16to8(std::u16string_view s)\n    {\n        std::string result;\n        utf16to8(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u16string utf8to16(std::string_view s)\n    {\n        std::u16string result;\n        utf8to16(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::string utf32to8(std::u32string_view s)\n    {\n        std::string result;\n        utf32to8(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u32string utf8to32(std::string_view s)\n    {\n        std::u32string result;\n        utf8to32(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::size_t find_invalid(std::string_view s)\n    {\n        std::string_view::const_iterator invalid = find_invalid(s.begin(), s.end());\n        return (invalid == s.end()) ? std::string_view::npos : static_cast<std::size_t>(invalid - s.begin());\n    }\n\n    inline bool is_valid(std::string_view s)\n    {\n        return is_valid(s.begin(), s.end());\n    }\n\n    inline std::string replace_invalid(std::string_view s, char32_t replacement)\n    {\n        std::string result;\n        replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement);\n        return result;\n    }\n\n    inline std::string replace_invalid(std::string_view s)\n    {\n        std::string result;\n        replace_invalid(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline bool starts_with_bom(std::string_view s)\n    {\n        return starts_with_bom(s.begin(), s.end());\n    }\n\n} // namespace utf8\n\n#endif // header guard\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/utf8/cpp20.h",
    "content": "// Copyright 2022 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n*/\n\n\n#ifndef UTF8_FOR_CPP_207e906c01_03a3_4daf_b420_ea7ea952b3c9\n#define UTF8_FOR_CPP_207e906c01_03a3_4daf_b420_ea7ea952b3c9\n\n#include \"cpp17.h\"\n\nnamespace utf8\n{\n    inline std::u8string utf16tou8(const std::u16string& s)\n    {\n        std::u8string result;\n        utf16to8(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u8string utf16tou8(std::u16string_view s)\n    {\n        std::u8string result;\n        utf16to8(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u16string utf8to16(const std::u8string& s)\n    {\n        std::u16string result;\n        utf8to16(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u16string utf8to16(const std::u8string_view& s)\n    {\n        std::u16string result;\n        utf8to16(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u8string utf32tou8(const std::u32string& s)\n    {\n        std::u8string result;\n        utf32to8(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u8string utf32tou8(const std::u32string_view& s)\n    {\n        std::u8string result;\n        utf32to8(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u32string utf8to32(const std::u8string& s)\n    {\n        std::u32string result;\n        utf8to32(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::u32string utf8to32(const std::u8string_view& s)\n    {\n        std::u32string result;\n        utf8to32(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline std::size_t find_invalid(const std::u8string& s)\n    {\n        std::u8string::const_iterator invalid = find_invalid(s.begin(), s.end());\n        return (invalid == s.end()) ? std::string_view::npos : static_cast<std::size_t>(invalid - s.begin());\n    }\n\n    inline bool is_valid(const std::u8string& s)\n    {\n        return is_valid(s.begin(), s.end());\n    }\n\n    inline std::u8string replace_invalid(const std::u8string& s, char32_t replacement)\n    {\n        std::u8string result;\n        replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement);\n        return result;\n    }\n\n    inline std::u8string replace_invalid(const std::u8string& s)\n    {\n        std::u8string result;\n        replace_invalid(s.begin(), s.end(), std::back_inserter(result));\n        return result;\n    }\n\n    inline bool starts_with_bom(const std::u8string& s)\n    {\n        return starts_with_bom(s.begin(), s.end());\n    }\n \n} // namespace utf8\n\n#endif // header guard\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/utf8/unchecked.h",
    "content": "// Copyright 2006 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n*/\n\n\n#ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731\n#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731\n\n#include \"core.h\"\n\nnamespace utf8\n{\n    namespace unchecked\n    {\n        template <typename octet_iterator>\n        octet_iterator append(utfchar32_t cp, octet_iterator result)\n        {\n            return internal::append(cp, result);\n        }\n\n        template <typename word_iterator>\n        word_iterator append16(utfchar32_t cp, word_iterator result)\n        {\n            return internal::append16(cp, result);\n        }\n\n        template <typename octet_iterator, typename output_iterator>\n        output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, utfchar32_t replacement)\n        {\n            while (start != end) {\n                octet_iterator sequence_start = start;\n                internal::utf_error err_code = utf8::internal::validate_next(start, end);\n                switch (err_code) {\n                    case internal::UTF8_OK :\n                        for (octet_iterator it = sequence_start; it != start; ++it)\n                            *out++ = *it;\n                        break;\n                    case internal::NOT_ENOUGH_ROOM:\n                        out = utf8::unchecked::append(replacement, out);\n                        start = end;\n                        break;\n                    case internal::INVALID_LEAD:\n                        out = utf8::unchecked::append(replacement, out);\n                        ++start;\n                        break;\n                    case internal::INCOMPLETE_SEQUENCE:\n                    case internal::OVERLONG_SEQUENCE:\n                    case internal::INVALID_CODE_POINT:\n                        out = utf8::unchecked::append(replacement, out);\n                        ++start;\n                        // just one replacement mark for the sequence\n                        while (start != end && utf8::internal::is_trail(*start))\n                            ++start;\n                        break;\n                }\n            }\n            return out;\n        }\n\n        template <typename octet_iterator, typename output_iterator>\n        inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)\n        {\n            static const utfchar32_t replacement_marker = static_cast<utfchar32_t>(utf8::internal::mask16(0xfffd));\n            return utf8::unchecked::replace_invalid(start, end, out, replacement_marker);\n        }\n\n        inline std::string replace_invalid(const std::string& s, utfchar32_t replacement)\n        {\n            std::string result;\n            replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement);\n            return result;\n        }\n\n        inline std::string replace_invalid(const std::string& s)\n        {\n            std::string result;\n            replace_invalid(s.begin(), s.end(), std::back_inserter(result));\n            return result;\n        }\n\n        template <typename octet_iterator>\n        utfchar32_t next(octet_iterator& it)\n        {\n            utfchar32_t cp = utf8::internal::mask8(*it);\n            switch (utf8::internal::sequence_length(it)) {\n                case 1:\n                    break;\n                case 2:\n                    ++it;\n                    cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);\n                    break;\n                case 3:\n                    ++it;\n                    cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);\n                    ++it;\n                    cp = static_cast<utfchar32_t>(cp + ((*it) & 0x3f));\n                    break;\n                case 4:\n                    ++it;\n                    cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);\n                    ++it;\n                    cp = static_cast<utfchar32_t>(cp + ((utf8::internal::mask8(*it) << 6) & 0xfff));\n                    ++it;\n                    cp = static_cast<utfchar32_t>(cp + ((*it) & 0x3f));\n                    break;\n            }\n            ++it;\n            return cp;\n        }\n\n        template <typename octet_iterator>\n        utfchar32_t peek_next(octet_iterator it)\n        {\n            return utf8::unchecked::next(it);\n        }\n\n        template <typename word_iterator>\n        utfchar32_t next16(word_iterator& it)\n        {\n            utfchar32_t cp = utf8::internal::mask16(*it++);\n            if (utf8::internal::is_lead_surrogate(cp))\n                return (cp << 10) + *it++ + utf8::internal::SURROGATE_OFFSET;\n            return cp;\n        }\n\n        template <typename octet_iterator>\n        utfchar32_t prior(octet_iterator& it)\n        {\n            while (utf8::internal::is_trail(*(--it))) ;\n            octet_iterator temp = it;\n            return utf8::unchecked::next(temp);\n        }\n\n        template <typename octet_iterator, typename distance_type>\n        void advance(octet_iterator& it, distance_type n)\n        {\n            const distance_type zero(0);\n            if (n < zero) {\n                // backward\n                for (distance_type i = n; i < zero; ++i)\n                    utf8::unchecked::prior(it);\n            } else {\n                // forward\n                for (distance_type i = zero; i < n; ++i)\n                    utf8::unchecked::next(it);\n            }\n        }\n\n        template <typename octet_iterator>\n        typename std::iterator_traits<octet_iterator>::difference_type\n        distance(octet_iterator first, octet_iterator last)\n        {\n            typename std::iterator_traits<octet_iterator>::difference_type dist;\n            for (dist = 0; first < last; ++dist)\n                utf8::unchecked::next(first);\n            return dist;\n        }\n\n        template <typename u16bit_iterator, typename octet_iterator>\n        octet_iterator utf16to8(u16bit_iterator start, u16bit_iterator end, octet_iterator result)\n        {\n            while (start != end) {\n                utfchar32_t cp = utf8::internal::mask16(*start++);\n                // Take care of surrogate pairs first\n                if (utf8::internal::is_lead_surrogate(cp)) {\n                    if (start == end)\n                        return result;\n                    utfchar32_t trail_surrogate = utf8::internal::mask16(*start++);\n                    cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;\n                }\n                result = utf8::unchecked::append(cp, result);\n            }\n            return result;\n        }\n\n        template <typename u16bit_iterator, typename octet_iterator>\n        u16bit_iterator utf8to16(octet_iterator start, octet_iterator end, u16bit_iterator result)\n        {\n            while (start < end) {\n                utfchar32_t cp = utf8::unchecked::next(start);\n                if (cp > 0xffff) { //make a surrogate pair\n                    *result++ = static_cast<utfchar16_t>((cp >> 10)   + internal::LEAD_OFFSET);\n                    *result++ = static_cast<utfchar16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);\n                }\n                else\n                    *result++ = static_cast<utfchar16_t>(cp);\n            }\n            return result;\n        }\n\n        template <typename octet_iterator, typename u32bit_iterator>\n        octet_iterator utf32to8(u32bit_iterator start, u32bit_iterator end, octet_iterator result)\n        {\n            while (start != end)\n                result = utf8::unchecked::append(*(start++), result);\n\n            return result;\n        }\n\n        template <typename octet_iterator, typename u32bit_iterator>\n        u32bit_iterator utf8to32(octet_iterator start, octet_iterator end, u32bit_iterator result)\n        {\n            while (start < end)\n                (*result++) = utf8::unchecked::next(start);\n\n            return result;\n        }\n\n        // The iterator class\n        template <typename octet_iterator>\n          class iterator {\n            octet_iterator it;\n            public:\n            typedef utfchar32_t value_type;\n            typedef utfchar32_t* pointer;\n            typedef utfchar32_t& reference;\n            typedef std::ptrdiff_t difference_type;\n            typedef std::bidirectional_iterator_tag iterator_category;\n            iterator () {}\n            explicit iterator (const octet_iterator& octet_it): it(octet_it) {}\n            // the default \"big three\" are OK\n            octet_iterator base () const { return it; }\n            utfchar32_t operator * () const\n            {\n                octet_iterator temp = it;\n                return utf8::unchecked::next(temp);\n            }\n            bool operator == (const iterator& rhs) const\n            {\n                return (it == rhs.it);\n            }\n            bool operator != (const iterator& rhs) const\n            {\n                return !(operator == (rhs));\n            }\n            iterator& operator ++ ()\n            {\n                ::std::advance(it, utf8::internal::sequence_length(it));\n                return *this;\n            }\n            iterator operator ++ (int)\n            {\n                iterator temp = *this;\n                ::std::advance(it, utf8::internal::sequence_length(it));\n                return temp;\n            }\n            iterator& operator -- ()\n            {\n                utf8::unchecked::prior(it);\n                return *this;\n            }\n            iterator operator -- (int)\n            {\n                iterator temp = *this;\n                utf8::unchecked::prior(it);\n                return temp;\n            }\n          }; // class iterator\n\n    } // namespace utf8::unchecked\n} // namespace utf8\n\n#endif // header guard\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/utf8.h",
    "content": "// Copyright 2006 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n*/\n\n\n#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731\n#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731\n\n/*\nTo control the C++ language version used by the library, you can define UTF_CPP_CPLUSPLUS macro\nand set it to one of the values used by the __cplusplus predefined macro.\n\nFor instance,\n    #define UTF_CPP_CPLUSPLUS 199711L\nwill cause the UTF-8 CPP library to use only types and language features available in the C++ 98 standard.\nSome library features will be disabled.\n\nIf you leave UTF_CPP_CPLUSPLUS undefined, it will be internally assigned to __cplusplus.\n*/\n\n#include \"utf8/checked.h\"\n#include \"utf8/unchecked.h\"\n\n#endif // header guard\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/xmltokenizer.h",
    "content": "\n#ifndef _xmltokenizer_h_\n#define _xmltokenizer_h_\n\n#include \"tokenizer.h\"\n\nclass XmlTokenizer final: public LispTokenizer\n{\npublic:\n  XmlTokenizer() {}\n  /// NextToken returns a string representing the next token,\n  /// or an empty list.\n  std::string NextToken(LispInput& aInput) override;\n};\n\n#endif\n\n"
  },
  {
    "path": "cyacas/libyacas/include/yacas/yacas.h",
    "content": "/// \\file\n/// Definitions of DefaultYacasEnvironment and CYacas.\n\n#ifndef YACAS_YACAS_H\n#define YACAS_YACAS_H\n\n#include \"lispstring.h\"\n#include \"stringio.h\"\n#include \"tokenizer.h\"\n#include \"lisphash.h\"\n#include \"lispevalhash.h\"\n#include \"infixparser.h\"\n#include \"platfileio.h\"\n#include \"lispatom.h\"\n#include \"lispeval.h\"\n#include \"lispglobals.h\"\n#include \"lisperror.h\"\n#include \"lispuserfunc.h\"\n#include \"noncopyable.h\"\n\n#include <sstream>\n\n\n/// The default environment for a Yacas session.\n/// This class constructs a LispEnvironment (to be found in\n/// #iEnvironment), and defines the Yacas core functions. The core\n/// functions are listed in corefunctions.h . Examples of core\n/// functions are \\c Head, \\c Set and \\c Eval.\n\nclass DefaultYacasEnvironment: NonCopyable\n{\npublic:\n  explicit DefaultYacasEnvironment(std::ostream&);\n  LispEnvironment& getEnv() {return iEnvironment;}\n\nprivate:\n  std::ostream& output;\n  LispHashTable hash;\n  LispPrinter printer;\n\n  YacasCoreCommands coreCommands;\n  LispGlobal globals;\n\n  //Define the default operators.\n  LispOperators prefixoperators;\n  LispOperators infixoperators;\n  LispOperators postfixoperators;\n  LispOperators bodiedoperators;\n  InfixPrinter infixprinter;\n\n  LispUserFunctions userFunctions;\n\n  LispIdentifiers protected_symbols;\n\n  LispEnvironment iEnvironment;\n\npublic:\n  StdUserInput input;\n};\n\n\n/// The Yacas engine.\n/// This is the only class that applications need to use. It can\n/// evaluate Yacas expressions. Every instance has its own Yacas\n/// environment, in which the expressions are evaluated.\n\n\n\nclass CYacas {\npublic:\n    /// Constructor\n    explicit CYacas(std::ostream&);\n\n    /// Return the underlying Yacas environment.\n    DefaultYacasEnvironment& getDefEnv() {return environment;}\n\n    /// Evaluate a Yacas expression.\n    /// First, \\p aExpression is parsed by an InfixParser. Then it is\n    /// evaluated in the underlying Lisp environment. Finally, the\n    /// result is printed to #iResultOutput via the pretty printer or,\n    /// if this is not defined, via an InfixPrinter.\n    void Evaluate(const std::string& aExpression);\n\n    /// Return the result of the expression.\n    /// This is stored in #iResult.\n    const std::string& Result() const;\n\n    /// Return the error message produced by the last evaluation.\n    /// The error is retrieved from #environment.\n    const std::string& Error() const;\n\n    /// Whether an error occured during the last evaluation.\n    bool IsError() const;\n\nprivate:\n\n    /// The underlying Yacas environment\n    DefaultYacasEnvironment environment;\n\n    std::string _result;\n    std::string _error;\n};\n\ninline\nconst std::string& CYacas::Result() const\n{\n  return _result;\n}\n\ninline\nconst std::string& CYacas::Error() const\n{\n  return _error;\n}\n\ninline\nbool CYacas::IsError() const\n{\n    return !Error().empty();\n}\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas/src/anumber.cpp",
    "content": "\n\n/* Arbitrary precision arithmetic classes. These are NOT designed\n * to be bleeding fast, just reaonably fast, but very clean code.\n *\n */\n\n#include \"yacas/anumber.h\"\n\n#include \"yacas/lispstring.h\"\n\n#include <algorithm>\n#include <cstring>\n#include <iostream>\n\n/* The Base... functions perform actions on the mantissa part of the\n * number, that is, it treats them as unsigned integers.\n */\nvoid BaseAddFull(ANumber& aResult, ANumber& a1, ANumber& a2);\nvoid BaseSubtract(ANumber& aResult, ANumber& a1, ANumber& a2);\nvoid BaseMultiplyFull(ANumber& aResult, ANumber& a1, ANumber& a2);\n\nvoid ANumber::Print(std::ostream& os, const std::string& prefix) const\n{\n    os << prefix << \"\\n\";\n    os << size() << \" words, \" << iExp << \" after point (x10^\" << iTensExp\n       << \"), 10-prec \" << iPrecision << \"\\n\";\n\n    for (int i = size() - 1; i >= 0; --i) {\n        if (iExp == i + 1)\n            os << \".\\n\";\n\n        PlatWord w = at(i);\n        PlatWord bit = (WordBase) >> 1;\n\n        int k = 0;\n        while (bit) {\n            if ((k & 3) == 0)\n                os << \" \";\n            k++;\n            if (w & bit)\n                os << \"1\";\n            else\n                os << \"0\";\n            bit >>= 1;\n        }\n        os << \"\\n\";\n    }\n}\n\nstatic int DigitIndex(int c)\n{\n    if (std::isdigit(c))\n        return c - '0';\n    if (std::islower(c))\n        return c - 'a' + 10;\n    if (std::isupper(c))\n        return c - 'A' + 10;\n\n    // TODO error!!!\n    return 0;\n}\n\nstatic int Digit(int c)\n{\n    if (c == '.')\n        return '.';\n    if (c == '-')\n        return '-';\n    if (c <= 9)\n        return '0' + c;\n    return 'a' + c - 10;\n}\n\nANumber::ANumber(int aPrecision) :\n    iExp(0),\n    iNegative(false),\n    iPrecision(aPrecision),\n    iTensExp(0)\n{\n    assert(sizeof(PlatDoubleWord) >= 2 * sizeof(PlatWord));\n    reserve(16);\n    push_back(0);\n}\n\n/* ANumber: Constructor for an arbitrary precision number. */\nANumber::ANumber(const std::string& aString, int aPrecision, int aBase) :\n    iExp(0),\n    iNegative(false),\n    iPrecision(aPrecision),\n    iTensExp(0)\n{\n    reserve(16);\n    SetTo(aString, aBase);\n}\n\nANumber::ANumber(const yacas::mp::ZZ& zz, int aPrecision):\n    std::vector<PlatWord>(zz.to_NN().limbs().cbegin(), zz.to_NN().limbs().cend()),\n    iExp(0),\n    iNegative(zz.is_negative()),\n    iPrecision(aPrecision),\n    iTensExp(0)\n{\n    reserve(16);\n\n    if (zz.is_zero())\n        push_back(0);\n}\n\nstd::string IntToBaseString(PlatDoubleWord aInt, int aBase)\n{\n    std::string s;\n\n    while (aInt != 0) {\n        s.push_back(aInt % aBase);\n        aInt /= aBase;\n    }\n\n    return s;\n}\n\nint WordDigits(int aPrecision, int aBase)\n{\n    if (aPrecision == 0)\n        return 0;\n    int bitsPerBase = 0;\n\n    while (aBase != 0) {\n        aBase >>= 1;\n        bitsPerBase++;\n    }\n    // I changed this to add two extra words at the end in stead of one, when\n    // we moved over to scientific notation. An example of what went wrong was\n    // typing -6.23, which for sufficiently low precision got read as 6.229999\n    // The original thought was that one word should be enough. This  will have\n    // to be examined more closely.\n    return (aPrecision * bitsPerBase + 2 * WordBits) / WordBits;\n    // return (aPrecision*bitsPerBase+WordBits)/WordBits;\n}\n\nvoid ANumber::SetTo(const std::string& str, int aBase)\n{\n    clear();\n    reserve(16);\n\n    assert(sizeof(PlatDoubleWord) >= 2 * sizeof(PlatWord));\n    assert(aBase <= 36);\n    iNegative = false;\n    iExp = 0;\n    iTensExp = 0;\n\n    const char* aString = str.c_str();\n    const char* endptr = aString;\n\n    // Parse minus sign\n    if (*endptr == '-') {\n        iNegative = true;\n        endptr++;\n    }\n\n    int endIntIndex = -1;\n    int endFloatIndex = 0;\n    int endNumberIndex = 0;\n    while (aString[endNumberIndex] != '\\0') {\n        if (aString[endNumberIndex] == '.')\n            endIntIndex = endNumberIndex;\n        if ((aBase < 14 && aString[endNumberIndex] == 'e') ||\n            aString[endNumberIndex] == 'E')\n            endFloatIndex = endNumberIndex;\n        endNumberIndex++;\n    }\n    if (endFloatIndex == 0)\n        endFloatIndex = endNumberIndex;\n\n    if (endIntIndex == -1)\n        endIntIndex = endFloatIndex;\n    if (endFloatIndex == endIntIndex + 1)\n        endFloatIndex = endIntIndex;\n\n    if (endFloatIndex - endIntIndex - 1 > iPrecision)\n        iPrecision = endFloatIndex - endIntIndex - 1;\n\n    // Go to least significant digit first\n    const char* ptr = aString + endIntIndex - 1;\n\n    // Now parse the integer part of the number.\n    ANumber factor2(iPrecision);\n    factor2[0] = 1;\n    while (ptr >= endptr) {\n        ANumber term(iPrecision);\n        term.CopyFrom(factor2);\n        WordBaseTimesInt(term, DigitIndex(*ptr));\n        WordBaseAdd(*this, term);\n        WordBaseTimesInt(factor2, aBase);\n        ptr--;\n    }\n\n    // Parse the fraction\n    if (endFloatIndex > endIntIndex) {\n        std::string fraction(aString + endIntIndex + 1);\n\n        // Map to a char base number\n        const int nr = endFloatIndex - endIntIndex - 1;\n        LispString::value_type* fractionPtr = &fraction[0];\n\n        std::reverse(fractionPtr, fractionPtr + nr);\n        std::transform(fractionPtr, fractionPtr + nr, fractionPtr, &DigitIndex);\n\n        const std::string base = IntToBaseString(WordBase, aBase);\n\n        const int nrDigits = WordDigits(iPrecision, aBase);\n\n        for (int i = 0; i < nrDigits; ++i) {\n            PlatWord word = 0;\n            std::string copied = fraction;\n\n            BaseMultiply(fraction, copied, base, aBase);\n\n            const int nrc = fraction.size();\n            PlatDoubleWord factor = 1;\n            for (int j = nr; j < nrc; ++j) {\n                word += fraction[j] * factor;\n                factor = factor * aBase;\n            }\n\n            fraction.resize(nr);\n            insert(begin(), word);\n            iExp++;\n        }\n    }\n\n    // Parse the E<num> part at the end\n    if (endNumberIndex > endFloatIndex + 1) {\n        if (aString[endFloatIndex] == '.')\n            endFloatIndex++;\n\n        if (aString[endFloatIndex + 1] == '+')\n            endFloatIndex++;\n\n        iTensExp = std::atoi(aString + endFloatIndex + 1);\n    }\n\n    DropTrailZeroes();\n}\n\nvoid ANumber::CopyFrom(const ANumber& aOther)\n{\n    iExp = aOther.iExp;\n    iTensExp = aOther.iTensExp;\n    iNegative = aOther.iNegative;\n    iPrecision = aOther.iPrecision;\n    resize(aOther.size());\n\n    const int nr = aOther.size();\n    if (nr) {\n        std::memcpy(\n            &((*this)[0]), &(aOther[0]), nr * sizeof(ANumber::value_type));\n    } else {\n        resize(1);\n        (*this)[0] = 0;\n    }\n}\n\nbool ANumber::ExactlyEqual(const ANumber& aOther)\n{\n    if (iExp != aOther.iExp)\n        return false;\n    if (iTensExp != aOther.iTensExp)\n        return false;\n    if (iNegative != aOther.iNegative)\n        return false;\n    //  if (iPrecision != aOther.iPrecision) return false;\n    if (size() != aOther.size())\n        return false;\n\n    // TODO there HAS to be a faster way to copy...\n    int nr = size();\n    if (nr) {\n        const ANumber::value_type* sptr = &(aOther[0]);\n        ANumber::value_type* tptr = &((*this)[0]);\n        while (nr--) {\n            if (*tptr++ != *sptr++)\n                return false;\n        }\n    }\n    return true;\n}\n\nvoid Multiply(ANumber& aResult, ANumber& a1, ANumber& a2)\n{\n    // Truncate zeroes (the multiplication is heavy enough as it is...)\n    a1.DropTrailZeroes();\n    a2.DropTrailZeroes();\n\n    if (a1.iExp || a1.iTensExp)\n        NormalizeFloat(a1, WordDigits(a1.iPrecision, 10));\n    if (a2.iExp || a2.iTensExp)\n        NormalizeFloat(a2, WordDigits(a2.iPrecision, 10));\n\n    // this does some additional removing, as for the multiplication we don't\n    // need any trailing zeroes at all, regardless of the value of iExp\n    std::size_t end;\n\n    end = a1.size();\n    while (end > 1 && a1[end - 1] == 0)\n        end--;\n\n    a1.resize(end);\n\n    end = a2.size();\n    while (end > 1 && a2[end - 1] == 0)\n        end--;\n\n    a2.resize(end);\n\n    // Multiply\n    BaseMultiplyFull(aResult, a1, a2);\n\n    // PrintNumber(\"Mult\",aResult);\n\n    // Adjust the sign\n    aResult.iNegative = a1.IsNegative() != a2.IsNegative();\n\n    // Adjust the exponent.\n    aResult.iExp = a1.iExp + a2.iExp;\n    aResult.iTensExp = a1.iTensExp + a2.iTensExp;\n\n    a1.Expand();\n    a2.Expand();\n\n    aResult.DropTrailZeroes();\n    if (aResult.iExp || aResult.iTensExp)\n        NormalizeFloat(aResult, WordDigits(aResult.iPrecision, 10));\n}\n\nstatic void BalanceFractions(ANumber& a1, ANumber& a2)\n{\n    PlatWord word = 0;\n\n    // ANumber a3(\"10e2\");\n    // PrintNumber(\"a3 enter \",a3);\n    // a3.iTensExp = 0;\n    // PrintNumber(\"a3 enter \",a3);\n\n    int nr;\n\n    nr = a2.iExp - a1.iExp;\n    // a2 has more decimal digits...\n    if (nr > 0) {\n        a1.insert(a1.begin(), nr, word);\n        a1.iExp += nr;\n    }\n    nr = a1.iExp - a2.iExp;\n    // a1 has more decimal digits...\n    if (nr > 0) {\n        a2.insert(a2.begin(), nr, word);\n        a2.iExp += nr;\n    }\n\n    // TODO this is not the fastest way to multiply by 10^exp\n    if (a1.iTensExp < a2.iTensExp) {\n        int diff = a2.iTensExp - a1.iTensExp;\n        a2.iTensExp = a1.iTensExp;\n        while (diff > 0) {\n            WordBaseTimesInt(a2, 10);\n            diff--;\n        }\n    } else if (a2.iTensExp < a1.iTensExp) {\n        int diff = a1.iTensExp - a2.iTensExp;\n        a1.iTensExp = a2.iTensExp;\n        while (diff > 0) {\n            WordBaseTimesInt(a1, 10);\n            diff--;\n        }\n    }\n}\n\nvoid Add(ANumber& aResult, ANumber& a1, ANumber& a2)\n{\n\n    // if the numbers are float, make sure they are normalized\n    if (a1.iExp || a1.iTensExp)\n        NormalizeFloat(a1, WordDigits(a1.iPrecision, 10));\n    if (a2.iExp || a2.iTensExp)\n        NormalizeFloat(a2, WordDigits(a2.iPrecision, 10));\n\n    // Two positive numbers\n    BalanceFractions(a1, a2);\n\n    if (!(a1.IsNegative() || a2.IsNegative())) {\n        BaseAddFull(aResult, a1, a2);\n        aResult.iNegative = false;\n    }\n    // Two negative numbers\n    else if (a1.IsNegative() && a2.IsNegative()) {\n        BaseAddFull(aResult, a1, a2);\n        aResult.iNegative = true;\n    }\n    // Negative plus positive\n    else if (a1.IsNegative() && !a2.IsNegative()) {\n        // if |a1|<|a2| then BaseSubtract(a2,a1)\n        if (BaseLessThan(a1, a2)) {\n            BaseSubtract(aResult, a2, a1);\n            aResult.iNegative = false;\n        } else if (BaseGreaterThan(a1, a2)) { // else if (|a1| > |a2|\n                                              // Negate(BaseSubtract(a1,a2))\n            BaseSubtract(aResult, a1, a2);\n            aResult.iNegative = true;\n        } else {\n            ANumber zero(/*???\"0\",*/ aResult.iPrecision);\n            aResult.CopyFrom(zero);\n        }\n    }\n    // Positive plus Negative\n    else {\n        assert(!a1.IsNegative() && a2.IsNegative());\n        // if |a1|>|a2| then BaseSubtract(a2,a1)\n        if (BaseGreaterThan(a1, a2)) {\n            BaseSubtract(aResult, a1, a2);\n            aResult.iNegative = false;\n        } else if (BaseLessThan(a1, a2)) { // else if (|a1| > |a2|\n                                           // Negate(BaseSubtract(a1,a2))\n            BaseSubtract(aResult, a2, a1);\n            aResult.iNegative = true;\n        } else {\n            ANumber zero(/*???\"0\",*/ aResult.iPrecision);\n            aResult.CopyFrom(zero);\n        }\n    }\n    aResult.DropTrailZeroes();\n\n    if (aResult.iExp || aResult.iTensExp) {\n        if (aResult.iPrecision < a2.iPrecision)\n            aResult.iPrecision = a2.iPrecision;\n        if (aResult.iPrecision < a1.iPrecision)\n            aResult.iPrecision = a1.iPrecision;\n\n        NormalizeFloat(aResult, WordDigits(aResult.iPrecision, 10));\n    }\n}\n\n// void Subtract(ANumber& aResult, ANumber& a1, ANumber& a2)\n// {\n//     BalanceFractions(a1, a2);\n//     if (!a1.IsNegative() && a2.IsNegative()) {\n//         BaseAddFull(aResult, a1, a2);\n//         aResult.iNegative = false;\n//     } else if (a1.IsNegative() && !a2.IsNegative()) {\n//         BaseAddFull(aResult, a1, a2);\n//         aResult.iNegative = true;\n//     } else if (a1.IsNegative() && a2.IsNegative()) {\n//         // if |a1|<|a2| then BaseSubtract(a2,a1)\n//         if (BaseLessThan(a1, a2)) {\n//             BaseSubtract(aResult, a2, a1);\n//             aResult.iNegative = false;\n//         } else if (BaseGreaterThan(a1, a2)) { // else if (|a1| > |a2|\n//                                               // Negate(BaseSubtract(a1,a2))\n//             BaseSubtract(aResult, a1, a2);\n//             aResult.iNegative = true;\n//         } else {\n//             ANumber zero(/*???\"0\",*/ aResult.iPrecision);\n//             aResult.CopyFrom(zero);\n//         }\n//     }\n//     // Positive plus Negative\n//     else {\n//         assert(!(a1.IsNegative() || a2.IsNegative()));\n//         // if |a1|>|a2| then BaseSubtract(a2,a1)\n//         if (BaseGreaterThan(a1, a2)) {\n//             BaseSubtract(aResult, a1, a2);\n//             aResult.iNegative = false;\n//         } else if (BaseLessThan(a1, a2)) { // else if (|a1| > |a2|\n//                                            // Negate(BaseSubtract(a1,a2))\n//             BaseSubtract(aResult, a2, a1);\n//             aResult.iNegative = true;\n//         } else {\n//             ANumber zero(/*???\"0\",*/ aResult.iPrecision);\n//             aResult.CopyFrom(zero);\n//         }\n//     }\n//     aResult.DropTrailZeroes();\n// }\n\nbool GreaterThan(ANumber& a1, ANumber& a2)\n{\n    BalanceFractions(a1, a2);\n    if (a1.IsNegative() && !a2.IsNegative())\n        return false;\n    if (!a1.IsNegative() && a2.IsNegative())\n        return true;\n    if (!a1.IsNegative() && !a2.IsNegative())\n        return BaseGreaterThan(a1, a2);\n    return BaseLessThan(a1, a2);\n}\n\nbool LessThan(ANumber& a1, ANumber& a2)\n{\n\n    // if the numbers are float, make sure they are normalized\n    if (a1.iExp || a1.iTensExp)\n        NormalizeFloat(a1, WordDigits(a1.iPrecision, 10));\n    if (a2.iExp || a2.iTensExp)\n        NormalizeFloat(a2, WordDigits(a2.iPrecision, 10));\n\n    BalanceFractions(a1, a2);\n    if (a1.IsNegative() && !a2.IsNegative())\n        return true;\n    if (!a1.IsNegative() && a2.IsNegative())\n        return false;\n    if (!a1.IsNegative() && !a2.IsNegative())\n        return BaseLessThan(a1, a2);\n    return BaseGreaterThan(a1, a2);\n}\n\nvoid ANumberToString(std::string& aResult,\n                     ANumber& aNumber,\n                     int aBase,\n                     bool aForceFloat)\n{\n    while (aNumber.size() > 1 && aNumber.back() == 0)\n        aNumber.pop_back();\n\n    std::size_t nr = aNumber.size();\n\n    // Formatting small numbers can be done faster.\n    if (aNumber.iExp == 0 && nr == 1) {\n        BaseIntNumber(aResult, aNumber[0], aBase);\n        std::reverse(aResult.begin(), aResult.end());\n        std::transform(aResult.begin(), aResult.end(), aResult.begin(), &Digit);\n\n        if (aForceFloat && !(aResult.size() == 1 && aResult[0] == '0'))\n            aResult.push_back('.');\n\n        if (aNumber.iNegative && (aResult.size() > 1 || aResult[0] != '0'))\n            aResult.insert(aResult.begin(), '-');\n\n        goto TENSEXP;\n    }\n    {\n        ANumber number(aNumber.iPrecision);\n        number.CopyFrom(aNumber);\n\n        assert(aBase <= 36);\n        // Reset number\n        aResult.clear();\n        aResult.push_back(0);\n\n        // Create the number\n        std::string factor2;\n        BaseIntNumber(factor2, 1, aBase);\n\n        std::string factor3;\n        BaseIntNumber(factor3, WordBase, aBase);\n\n        assert(number.iExp >= 0);\n\n        const std::size_t ns = number.size();\n        for (std::size_t i = number.iExp; i < ns; ++i) {\n            // aResult = aResult + number[i] * factor2\n            std::string term;\n            BaseIntNumber(term, number[i], aBase);\n            BaseAddMultiply(aResult, term, factor2, aBase);\n\n            // factor2 = factor2*factor3\n            term.swap(factor2);\n\n            BaseMultiply(factor2, term, factor3, aBase);\n        }\n\n        // Remove trailing zeroes (most significant side)\n        while (aResult.size() > 1 && aResult.back() == 0)\n            aResult.pop_back();\n\n        std::reverse(aResult.begin(), aResult.end());\n\n        // Get the fraction\n        number.resize(number.iExp, 0);\n        if (aForceFloat || (number.iExp > 0 && !number.IsZero())) {\n            int digitPos = aResult.size();\n\n            int i;\n            // Build the fraction\n            for (i = 0; i < number.iPrecision + 1; i++) {\n                WordBaseTimesInt(number, aBase);\n                if (int(number.size()) > number.iExp) {\n                    aResult.push_back(number[number.iExp]);\n                    number.resize(number.iExp);\n                } else {\n                    aResult.push_back(0);\n                }\n            }\n\n            // Round off\n            if (aResult[aResult.size() - 1] >= (aBase >> 1)) {\n                // TODO code bloat!\n                int carry = 1;\n                for (i = aResult.size() - 1; i >= 0; i--) {\n                    const int word = aResult[i] + carry;\n                    aResult[i] = word % aBase;\n                    carry = word / aBase;\n                }\n                if (carry) {\n                    aResult.insert(aResult.begin(), carry);\n                    digitPos++;\n                }\n            }\n            aResult.resize(aResult.size() - 1);\n            // Insert dot\n            aResult.insert(aResult.begin() + digitPos, '.');\n\n            // Remove trailing zeros\n            int nr = aResult.size();\n            while (nr > 1 && aResult[nr - 1] == 0)\n                nr--;\n\n            if (aResult[nr - 1] == '.' && nr == 2 && aResult[0] == 0)\n                nr--;\n            aResult.resize(nr);\n        }\n\n        // Map to ascii\n        {\n            LispString::value_type* rptr = &aResult[0];\n            const std::size_t nr = aResult.size();\n            for (std::size_t i = 0; i < nr; ++i) {\n                *rptr = Digit(*rptr);\n                rptr++;\n            }\n        }\n\n        // If signed, insert a minus sign\n        if (number.iNegative)\n            if (aResult.size() > 1 || aResult[0] != '0') {\n                char c = '-';\n                aResult.insert(aResult.begin(), c);\n            }\n    }\n\n    // Handle tens exp\nTENSEXP:\n    if (aNumber.iTensExp != 0 && !(aResult[0] == '0' && aResult.size() == 1)) {\n        aResult.push_back('e');\n        aResult.append(std::to_string(aNumber.iTensExp));\n    }\n}\n\nvoid BaseAddFull(ANumber& aResult, ANumber& a1, ANumber& a2)\n{\n    // Initialize result\n    aResult.CopyFrom(a1);\n    WordBaseAdd(aResult, a2);\n}\n\nvoid BaseSubtract(ANumber& aResult, ANumber& a1, ANumber& a2)\n{\n    aResult.CopyFrom(a1);\n    BaseSubtract(aResult, a2, 0);\n}\n\nvoid BaseMultiplyFull(ANumber& aResult, ANumber& a1, ANumber& a2)\n{\n    // Initialize result\n    WordBaseMultiply(aResult, a1, a2);\n}\n\nbool BaseGreaterThan(const ANumber& a1, const ANumber& a2)\n{\n    const int nr1 = a1.size();\n    const int nr2 = a2.size();\n\n    // Nr is the number of words the two numbers share.\n    const int nr = std::min(nr1, nr2);\n\n    // Comparison of shared words.\n    bool highSame;\n    {\n        int i = nr - 1;\n        while (i > 0 && a1[i] == a2[i])\n            i--;\n        highSame = (a1[i] > a2[i]);\n    }\n\n    // Two numbers with same numbers of words: compare these words.\n    if (nr1 == nr2)\n        return highSame;\n\n    // a1 has more words.\n    if (nr1 > nr2) {\n        // If any of a1's higher words is non-zero, it will be bigger.\n        int i;\n        for (i = nr2; i < nr1; i++)\n            if (a1[i] != 0)\n                return true;\n        // Otherwise compare the shared highest word.\n        return highSame;\n    }\n\n    // If any of a2's higher words is non-zero, it will be bigger.\n    int i;\n    for (i = nr1; i < nr2; i++)\n        if (a2[i] != 0)\n            return false;\n    // Otherwise compare the shared highest word.\n    return highSame;\n}\n\nbool BaseLessThan(const ANumber& a1, const ANumber& a2)\n{\n    return BaseGreaterThan(a2, a1);\n}\n\nvoid BaseShiftRight(ANumber& a, int aNrBits)\n{\n    // Number of words a word jumps\n    int wordsShifted = aNrBits / WordBits;\n\n    // Residue: bits shifted out.\n    int residue = aNrBits % WordBits;\n\n    // Bit mask: bits that are going to be shifted out of each word.\n    PlatDoubleWord bitMask =\n        (PlatDoubleWord)((((PlatDoubleWord)1) << residue) - 1);\n\n    // Nr of bits to move to the other side.\n    int otherSideBits = WordBits - residue;\n\n    int i;\n\n    int nr = a.size();\n\n    ANumber::value_type* ptr = &a[0];\n    ANumber::value_type* ptrshifted = &a[wordsShifted];\n    ANumber::value_type* endp = ptr + nr - wordsShifted;\n    if (ptr < endp) {\n        *ptr = ((*ptrshifted) >> residue);\n        ptr++;\n        ptrshifted++;\n        while (ptr < endp)\n        //    for (i=1;i<nr-wordsShifted;i++)\n        {\n            PlatDoubleWord newCarry = (((PlatDoubleWord)*ptrshifted) & bitMask)\n                                      << otherSideBits;\n            *ptr = ((*ptrshifted) >> residue);\n            ptr[-1] |= newCarry;\n            ptr++;\n            ptrshifted++;\n        }\n    }\n\n    int start = nr - wordsShifted;\n    if (start < 0)\n        start = 0;\n    for (i = start; i < nr; i++) {\n        a[i] = 0;\n    }\n}\n\nvoid BaseShiftLeft(ANumber& a, int aNrBits)\n{\n    // Number of words a word jumps\n    int wordsShifted = aNrBits / WordBits;\n\n    // Residue: bits shifted out.\n    int residue = aNrBits % WordBits;\n\n    // Nr of bits to move to the other side.\n    int otherSideBits = WordBits - residue;\n\n    // Bit mask: bits that are going to be shifted out of each word.\n    int bitMask = ((1L << residue) - 1) << otherSideBits;\n\n    int i;\n    int nr = a.size();\n\n    for (i = 0; i <= wordsShifted; i++) {\n        a.push_back(0);\n    }\n\n    ANumber::value_type* ptr = &a[0];\n\n    for (i = nr + wordsShifted; i >= wordsShifted; i--) {\n        PlatDoubleWord newCarry =\n            (((PlatDoubleWord)ptr[i - wordsShifted]) & bitMask) >>\n            otherSideBits;\n        ptr[i] = (ptr[i - wordsShifted] << residue);\n\n        if (i < nr + wordsShifted)\n            ptr[i + 1] |= newCarry;\n    }\n    for (i = wordsShifted - 1; i >= 0; i--) {\n        ptr[i] = 0;\n    }\n}\n\n// /* Binary Greatest common divisor algorithm. */\n// void BaseGcd(ANumber& aResult, ANumber& a1, ANumber& a2)\n// {\n//     ANumber zero(aResult.Precision());\n//     ANumber u(aResult.Precision());\n//     ANumber v(aResult.Precision());\n//     u.CopyFrom(a1);\n//     v.CopyFrom(a2);\n//     u.iNegative = v.iNegative = false;\n\n//     int k = 0;\n\n//     {\n//         int i = 0;\n//         PlatWord bit = 1;\n//         while (u[i] == 0 && v[i] == 0)\n//             i++;\n//         k += WordBits * i;\n//         while ((u[i] & bit) == 0 && (v[i] & bit) == 0) {\n//             bit <<= 1;\n//             k++;\n//         }\n//         BaseShiftRight(u, k);\n//         BaseShiftRight(v, k);\n//     }\n//     ANumber t(/*???\"0\",*/ 10);\n\n//     if (!u.IsEven()) {\n//         t.CopyFrom(v);\n//         t.Negate();\n//     } else\n//         t.CopyFrom(u);\n\n//     while (!IsZero(t)) {\n\n//         {\n//             int k = 0;\n//             int i = 0;\n//             PlatWord bit = 1;\n//             while (t[i] == 0)\n//                 i++;\n//             k += WordBits * i;\n//             while ((t[i] & bit) == 0) {\n//                 bit <<= 1;\n//                 k++;\n//             }\n//             BaseShiftRight(t, k);\n//         }\n//         if (GreaterThan(t, zero)) {\n//             u.CopyFrom(t);\n//         } else {\n//             v.CopyFrom(t);\n//             v.Negate();\n//         }\n//         Subtract(t, u, v);\n//     }\n//     aResult.CopyFrom(u);\n//     aResult.iNegative = false;\n//     BaseShiftLeft(aResult, k);\n// }\n\nvoid BaseDivide(ANumber& aQuotient,\n                ANumber& aRemainder,\n                ANumber& a1,\n                ANumber& a2)\n{\n    // Find the values n and m as described in Knuth II:\n    int n, m;\n    n = a2.size();\n    assert(n > 0);\n    assert(a2[n - 1] != 0);\n\n    // a1.size() = m+n => m = a1.size()-n\n    m = a1.size() - n;\n    assert(m >= 0);\n\n    aQuotient.resize(m + 1);\n\n    // D1:\n    PlatDoubleWord d = WordBase / (a2[n - 1] + 1);\n    WordBaseTimesInt(a1, d);\n    WordBaseTimesInt(a2, d);\n    a1.push_back(0);\n    a2.push_back(0);\n\n    // D2:\n    int j = m;\n\n    while (j >= 0) {\n        // D3:\n        PlatDoubleWord q = (a1[j + n] * WordBase + a1[j + n - 1]) / a2[n - 1];\n        PlatDoubleWord r = (a1[j + n] * WordBase + a1[j + n - 1]) % a2[n - 1];\n\n    REDO:\n        if (q == WordBase || q * a2[n - 2] > WordBase * r + a1[j + n - 2]) {\n            q = q - 1;\n            r = r + a2[n - 1];\n            if (r < WordBase)\n                goto REDO;\n        }\n\n        // D4:\n        ANumber sub(aQuotient.Precision());\n        sub.CopyFrom(a2);\n        WordBaseTimesInt(sub, q);\n        sub.push_back(0);\n\n        PlatSignedDoubleWord carry;\n        { // Subtract the two\n            // TODO this can be generalized!!!!\n            //\n            // Beware though: this is not a normal subtraction. Only a\n            // certain set of digits ends up being subtracted.\n\n            // First check if qv isn't too big...\n            carry = 0;\n            for (int digit = 0; digit <= n; digit++) {\n                PlatSignedDoubleWord word;\n                word = ((PlatSignedDoubleWord)a1[digit + j]) -\n                       ((PlatSignedDoubleWord)sub[digit]) +\n                       (PlatSignedDoubleWord)carry;\n                carry = 0;\n                while (word < 0) {\n                    word += WordBase;\n                    carry--;\n                }\n            }\n            if (carry) {\n                q--;\n                sub.CopyFrom(a2);\n                WordBaseTimesInt(sub, q);\n                sub.push_back(0);\n            }\n\n            carry = 0;\n            for (int digit = 0; digit <= n; digit++) {\n                PlatSignedDoubleWord word;\n                word = ((PlatSignedDoubleWord)a1[digit + j]) -\n                       ((PlatSignedDoubleWord)sub[digit]) +\n                       (PlatSignedDoubleWord)carry;\n                carry = 0;\n                while (word < 0) {\n                    word += WordBase;\n                    carry--;\n                }\n                a1[digit + j] = ((PlatWord)(word));\n            }\n        }\n        assert(carry == 0);\n\n        // D5:\n        aQuotient[j] = (PlatWord)q;\n        // D7:\n        j--;\n    }\n\n    // D8:\n    a1.resize(n);\n    PlatDoubleWord carry;\n    BaseDivideInt(a1, d, WordBase, carry);\n    aRemainder.CopyFrom(a1);\n}\n\nvoid IntegerDivide(ANumber& aQuotient,\n                   ANumber& aRemainder,\n                   ANumber& a1,\n                   ANumber& a2)\n{\n    assert(!a2.IsZero());\n\n    int n = a2.size();\n\n    while (a2[n - 1] == 0)\n        n--;\n    a2.resize(n);\n\n    if (n == 1) {\n        PlatDoubleWord carry;\n        aQuotient.CopyFrom(a1);\n        aQuotient.iExp = a1.iExp - a2.iExp;\n        aQuotient.iTensExp = a1.iTensExp - a2.iTensExp;\n\n        BaseDivideInt(aQuotient, a2[0], WordBase, carry);\n        aRemainder.resize(1);\n        aRemainder[0] = (PlatWord)carry;\n    }\n    // if |a1| < |a2| then result is zero.\n    else if (BaseLessThan(a1, a2)) {\n        aQuotient.iExp = 0;\n        aQuotient.iTensExp = 0;\n        aQuotient.resize(1);\n        aQuotient[0] = 0;\n        aRemainder.CopyFrom(a1);\n    } else {\n        aQuotient.iExp = a1.iExp - a2.iExp;\n        aQuotient.iTensExp = a1.iTensExp - a2.iTensExp;\n        // Divide the mantissas\n        WordBaseDivide(aQuotient, aRemainder, a1, a2);\n    }\n\n    // Correct for signs\n    if (a1.IsNegative() == a2.IsNegative()) {\n        aQuotient.iNegative = false;\n        aRemainder.iNegative = false;\n    } else {\n        aQuotient.iNegative = true;\n        aRemainder.iNegative = true;\n    }\n}\n\nvoid NormalizeFloat(ANumber& a2, int digitsNeeded)\n{\n    if (a2.iExp - digitsNeeded > 0) {\n        a2.erase(a2.begin(), a2.begin() + a2.iExp - digitsNeeded);\n        a2.iExp -= (a2.iExp - digitsNeeded);\n    }\n\n    const std::size_t min = std::max(1 + digitsNeeded, a2.iExp + 1);\n\n    std::size_t n = a2.size();\n    while (n > min || (n == min && a2.back() > 10)) {\n        PlatDoubleWord carry = 0;\n        BaseDivideInt(a2, 10, WordBase, carry);\n        if (a2.back() == 0)\n            a2.pop_back();\n        a2.iTensExp++;\n        n = a2.size();\n    }\n}\n\nvoid Divide(ANumber& aQuotient, ANumber& aRemainder, ANumber& a1, ANumber& a2)\n{\n\n    // Now add some digits to the front, to end up with the correct\n    // precision: the resulting precision will be a1.iExp-a2.iExp.\n    // This value should at least be WordDigits, so grow a1\n    // by WordDigits-(a1.iExp-a2.iExp) = WordDigits+a2.iExp-a1.iExp\n    const int digitsNeeded = WordDigits(aQuotient.iPrecision, 10);\n\n    NormalizeFloat(a2, digitsNeeded);\n\n    const int toadd = a2.iExp - a1.iExp;\n    PlatWord zero = 0;\n    if (toadd > 0) {\n        a1.insert(a1.begin(), toadd, zero);\n        a1.iExp += toadd;\n    }\n\n    if (!a1.IsZero()) {\n        const std::size_t n = a2.size();\n        while (a1.size() < n + digitsNeeded || a1.back() < a2.back()) {\n            WordBaseTimesInt(a1, 10);\n            a1.iTensExp--;\n        }\n    }\n\n    IntegerDivide(aQuotient, aRemainder, a1, a2);\n\n    NormalizeFloat(aQuotient, digitsNeeded);\n}\n\n// void BaseSqrt(ANumber& aResult, const ANumber& N)\n// {\n\n//     int l2;\n//     ANumber u(aResult.Precision());\n//     ANumber v(aResult.Precision());\n//     ANumber u2(aResult.Precision());\n//     ANumber v2(aResult.Precision());\n//     ANumber uv2(aResult.Precision());\n//     ANumber n(aResult.Precision());\n//     ANumber two(\"2\", 10);\n\n//     // sqrt(1) = 1, sqrt(0) = 0\n//     if (BaseGreaterThan(two, N)) {\n//         aResult.CopyFrom(N);\n//         return;\n//     }\n\n//     // Find highest set bit, l2\n//     u.CopyFrom(N);\n//     l2 = 0;\n//     while (!u.IsZero()) {\n//         BaseShiftRight(u, 1);\n//         l2++;\n//     }\n//     l2--;\n\n//     // 1<<(l2/2) now would be a good under estimate for the square root.\n//     // 1<<(l2/2) is definitely set in the result. Also it is the highest\n//     // set bit.\n//     l2 >>= 1;\n\n//     // initialize u and u2 (u2==u^2).\n//     u.SetTo(\"1\");\n//     BaseShiftLeft(u, l2);\n//     u2.CopyFrom(u);\n//     BaseShiftLeft(u2, l2);\n\n//     // Now for each lower bit:\n//     while (l2--) {\n//         // Get that bit in v, and v2 == v^2.\n//         v.SetTo(\"1\");\n//         BaseShiftLeft(v, l2);\n//         v2.CopyFrom(v);\n//         BaseShiftLeft(v2, l2);\n\n//         // uv2 == 2*u*v\n//         uv2.CopyFrom(u);\n//         BaseShiftLeft(uv2, (l2 + 1));\n\n//         // n = (u+v)^2  =  u^2 + 2*u*v + v^2 = u2+uv2+v2\n//         n.CopyFrom(u2);\n//         WordBaseAdd(n, uv2);\n//         WordBaseAdd(n, v2);\n//         // if n (possible new best estimate for sqrt(N)^2 is smaller than\n//         // N, then the bit l2 is set in the result, and add v to u.\n//         if (!BaseGreaterThan(n, N)) {\n//             WordBaseAdd(u, v); // u <- u+v\n//             u2.CopyFrom(n);    // u^2 <- u^2 + 2*u*v + v^2\n//         }\n//     }\n//     aResult.CopyFrom(u);\n// }\n\n// void Sqrt(ANumber& aResult, ANumber& N)\n// {\n//     int digs = WordDigits(N.iPrecision, 10);\n//     PlatWord zero = 0;\n//     if ((N.iTensExp & 1) != 0) {\n//         WordBaseTimesInt(N, 10);\n//         N.iTensExp--;\n//     }\n//     while (N.iExp < 2 * digs || (N.iExp & 1)) {\n//         N.insert(N.begin(), zero);\n//         N.iExp++;\n//     }\n\n//     const int resultDigits = N.iExp / 2;\n//     const int resultTensExp = N.iTensExp / 2;\n\n//     BaseSqrt(aResult, N);\n\n//     aResult.iExp = resultDigits;\n//     aResult.iTensExp = resultTensExp;\n// }\n\n/*** Significant : return whether this number is not zero, up to\n * the number of digits specified behind the dot (as per aPrecision).\n */\nbool Significant(ANumber& a)\n{\n    int significantDigits = WordDigits(a.iPrecision, 10);\n    NormalizeFloat(a, significantDigits);\n    // hier\n    int nrExt = (a.size() - a.iExp) * ((WordBits) / 3);\n    if ((-a.iTensExp) > a.iPrecision + 2 + nrExt) {\n        return false;\n    }\n    return true;\n}\n\nvoid ANumber::RoundBits()\n{\n    PlatWord* ptr = data();\n    if (front() >= (WordBase / 2)) {\n        PlatDoubleWord carry = 1;\n        for (int i = 1, nr = size(); i < nr; i++) {\n            const PlatDoubleWord dword = ptr[i] + carry;\n            ptr[i] = dword;\n            carry = dword >> WordBits;\n        }\n\n        if (carry)\n            push_back(carry);\n    }\n\n    front() = 0;\n}\n\nvoid ANumber::ChangePrecision(int aPrecision)\n{\n    // First, round.\n    /*FIXME TODO not working correctly yet */\n    // TODO code bloat! Deserves its own routine!\n    if (aPrecision == 0 && iExp > 1) {\n        RoundBits();\n    }\n    //  return;\n\n    // FIXME the following line is there to assure there are enough words.\n    // Somehow this got truncated?\n    // FIXME numerics.yts fails\n    Expand();\n\n    int oldExp = iExp;\n\n    iPrecision = aPrecision;\n    int newExp = WordDigits(iPrecision, 10);\n    if (newExp < oldExp) {\n        iExp = newExp;\n        erase(begin(), begin() + oldExp - iExp);\n    } else if (newExp > oldExp) {\n        iExp = newExp;\n        PlatWord zero = 0;\n        insert(begin(), newExp - oldExp, zero);\n    }\n}\n\nvoid ANumber::DropTrailZeroes()\n{\n    Expand();\n\n    {\n        int nr = size();\n        while (nr > iExp + 1 && (*this)[nr - 1] == 0)\n            nr--;\n        resize(nr);\n    }\n    {\n        int low = 0;\n        while (low < iExp && (*this)[low] == 0)\n            low++;\n        if (low) {\n            erase(begin(), begin() + low);\n            iExp -= low;\n        }\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/arggetter.cpp",
    "content": "\n#include \"yacas/arggetter.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispstring.h\"\n#include \"yacas/platmath.h\"\n#include \"yacas/standard.h\"\n\nstatic const LispString*\nGetIntegerArgument(LispEnvironment& aEnvironment, int aStackTop, int aArgNr)\n{\n    const LispString* str = aEnvironment.iStack[aStackTop + aArgNr]->String();\n    CheckArg(str, aArgNr, aEnvironment, aStackTop);\n    CheckArg(IsNumber(*str, false), aArgNr, aEnvironment, aStackTop);\n    return str;\n}\n\nint GetShortIntegerArgument(LispEnvironment& aEnvironment,\n                            int aStackTop,\n                            int aArgNr)\n{\n    const LispString* str = GetIntegerArgument(aEnvironment, aStackTop, aArgNr);\n    return InternalAsciiToInt(*str);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/associationclass.cpp",
    "content": "/*\n * Copyright (C) 2016 Grzegorz Mazur.\n *\n * Yacas is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n * MA 02110-1301  USA\n */\n\n#include \"yacas/associationclass.h\"\n\nLispPtr AssociationClass::Keys() const\n{\n    LispPtr head(LispAtom::New(const_cast<LispEnvironment&>(_env), \"List\"));\n    LispPtr p(head);\n    for (std::map<Key, LispPtr>::const_reference e : _map) {\n        p->Nixed() = e.first.value->Copy();\n        p = p->Nixed();\n    }\n    return LispPtr(LispSubList::New(head));\n}\n\nLispPtr AssociationClass::ToList() const\n{\n    LispPtr head(LispAtom::New(const_cast<LispEnvironment&>(_env), \"List\"));\n    LispPtr p(head);\n    for (std::map<Key, LispPtr>::const_reference e : _map) {\n        LispPtr q(LispAtom::New(const_cast<LispEnvironment&>(_env), \"List\"));\n        p->Nixed() = LispSubList::New(q);\n        p = p->Nixed();\n        q->Nixed() = e.first.value->Copy();\n        q = q->Nixed();\n        q->Nixed() = e.second->Copy();\n    }\n    return LispPtr(LispSubList::New(head));\n}\n\nLispPtr AssociationClass::Head() const\n{\n    assert(_map.size());\n\n    std::map<Key, LispPtr>::const_reference e = *_map.begin();\n    LispPtr p(LispAtom::New(const_cast<LispEnvironment&>(_env), \"List\"));\n    LispPtr q(p);\n    q->Nixed() = e.first.value->Copy();\n    q = q->Nixed();\n    q->Nixed() = e.second->Copy();\n    return LispPtr(LispSubList::New(p));\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/deffile.cpp",
    "content": "#include \"yacas/deffile.h\"\n\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lisperror.h\"\n#include \"yacas/lispio.h\"\n#include \"yacas/lispuserfunc.h\"\n#include \"yacas/platfileio.h\"\n#include \"yacas/standard.h\"\n#include \"yacas/stringio.h\"\n#include \"yacas/tokenizer.h\"\n\nLispDefFile::LispDefFile(const std::string& aFileName) :\n    iFileName(aFileName),\n    iIsLoaded(false)\n{\n}\n\nvoid LispDefFile::SetLoaded()\n{\n    iIsLoaded = true;\n}\n\nLispDefFile* LispDefFiles::File(const std::string& aFileName)\n{\n    auto i = _map.find(aFileName);\n\n    if (i == _map.end())\n        i = _map.emplace(aFileName, aFileName).first;\n\n    return &i->second;\n}\n\nstatic void DoLoadDefFile(LispEnvironment& aEnvironment,\n                          LispInput* aInput,\n                          LispDefFile* def)\n{\n    LispLocalInput localInput(aEnvironment, aInput);\n\n    const LispString* eof = aEnvironment.iEndOfFile->String();\n    const LispString* end = aEnvironment.iListClose->String();\n\n    bool endoffile = false;\n\n    LispTokenizer tok;\n\n    while (!endoffile) {\n        // Read expression\n        const LispString* token = aEnvironment.HashTable().LookUp(\n            tok.NextToken(*aEnvironment.CurrentInput()));\n\n        // Check for end of file\n        if (token == eof || token == end) {\n            endoffile = true;\n        }\n        // Else evaluate\n        else {\n            LispMultiUserFunction* multiUser =\n                aEnvironment.MultiUserFunction(token);\n\n            if (multiUser->iFileToOpen != nullptr) {\n                aEnvironment.CurrentOutput() << '[' << *token << \"]\\n\";\n                if (multiUser->iFileToOpen)\n                    throw LispErrDefFileAlreadyChosen();\n            }\n\n            multiUser->iFileToOpen = def;\n\n            def->symbols.insert(token);\n\n            aEnvironment.Protect(token);\n        }\n    }\n}\n\nvoid LoadDefFile(LispEnvironment& aEnvironment, const std::string& aFileName)\n{\n    const std::string flatfile = InternalUnstringify(aFileName) + \".def\";\n    LispDefFile* def = aEnvironment.DefFiles().File(aFileName);\n\n    InputStatus oldstatus = aEnvironment.iInputStatus;\n    aEnvironment.iInputStatus.SetTo(flatfile);\n\n    LispLocalFile localFP(\n        aEnvironment, flatfile, true, aEnvironment.iInputDirectories);\n    if (!localFP.stream.is_open())\n        throw LispErrFileNotFound();\n\n    StdFileInput newInput(localFP, aEnvironment.iInputStatus);\n    DoLoadDefFile(aEnvironment, &newInput, def);\n\n    aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/errors.cpp",
    "content": "#include \"yacas/errors.h\"\n#include \"yacas/infixparser.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/standard.h\"\n\nvoid ShowStack(LispEnvironment& aEnvironment)\n{\n    aEnvironment.iEvaluator->ShowStack(aEnvironment, aEnvironment.iErrorOutput);\n}\n\nvoid ShowFunctionError(LispPtr& aArguments, LispEnvironment& aEnvironment)\n{\n    if (const LispString* string = aArguments->String())\n        aEnvironment.iErrorOutput << \"In function \\\"\" << *string << \"\\\" : \\n\";\n}\n\nvoid ShowArgTypeErrorInfo(int aArgNr,\n                          LispPtr& aArguments,\n                          LispEnvironment& aEnvironment)\n{\n    ShowStack(aEnvironment);\n    ShowFunctionError(aArguments, aEnvironment);\n\n    aEnvironment.iErrorOutput << \"bad argument number \" << aArgNr\n                              << \" (counting from 1)\\n\";\n\n    const int LIM_AL = 60;\n\n    LispPtr& arg = Argument(aArguments, aArgNr);\n    LispString strout;\n\n    PrintExpression(strout, arg, aEnvironment, LIM_AL);\n    aEnvironment.iErrorOutput << \"The offending argument \" << strout;\n\n    LispPtr eval;\n    aEnvironment.iEvaluator->Eval(aEnvironment, eval, arg);\n    PrintExpression(strout, eval, aEnvironment, LIM_AL);\n\n    aEnvironment.iErrorOutput << \" evaluated to \" << strout << '\\n';\n}\n\nvoid CheckArg(bool pred, int arg_idx, LispEnvironment& env, int stack_top)\n{\n    if (!pred) {\n        ShowArgTypeErrorInfo(arg_idx, env.iStack[stack_top], env);\n        throw LispErrInvalidArg();\n    }\n}\n\nvoid CheckArgIsString(LispPtr arg,\n                      int arg_idx,\n                      LispEnvironment& env,\n                      int stack_top)\n{\n    if (!InternalIsString(arg->String())) {\n        ShowArgTypeErrorInfo(arg_idx, env.iStack[stack_top], env);\n        throw LispErrNotString();\n    }\n}\n\nvoid CheckArgIsString(int arg_idx, LispEnvironment& env, int stack_top)\n{\n    CheckArgIsString(env.iStack[stack_top + arg_idx], arg_idx, env, stack_top);\n}\n\nvoid CheckArgIsList(LispPtr arg,\n                    int arg_idx,\n                    LispEnvironment& env,\n                    int stack_top)\n{\n    if (!InternalIsList(env, arg)) {\n        ShowArgTypeErrorInfo(arg_idx, env.iStack[stack_top], env);\n        throw LispErrNotList();\n    }\n}\n\nvoid CheckArgIsList(int arg_idx, LispEnvironment& env, int stack_top)\n{\n    CheckArgIsList(env.iStack[stack_top + arg_idx], arg_idx, env, stack_top);\n}\n\nvoid CheckNrArgs(int n, LispPtr& aArguments, LispEnvironment& aEnvironment)\n{\n    const int nrArguments = InternalListLength(aArguments);\n\n    if (nrArguments == n)\n        return;\n\n    const int needed = n - 1;\n    const int passed = nrArguments - 1;\n\n    ShowStack(aEnvironment);\n    ShowFunctionError(aArguments, aEnvironment);\n\n    aEnvironment.iErrorOutput << \"expected \" << needed << \" arguments, got \"\n                              << passed << \"\\n\";\n\n    throw LispErrWrongNumberOfArgs();\n}\n\nvoid CheckSecure(LispEnvironment& env, int stack_top)\n{\n    if (env.secure) {\n        ShowStack(env);\n        ShowFunctionError(env.iStack[stack_top], env);\n        throw LispErrSecurityBreach();\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/infixparser.cpp",
    "content": "\n#include \"yacas/infixparser.h\"\n#include \"yacas/arrayclass.h\"\n#include \"yacas/associationclass.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lisperror.h\"\n#include \"yacas/standard.h\"\n\n#include <cassert>\n#include <string>\n\nvoid ParsedObject::Fail()\n{\n    if (iLookAhead && !iLookAhead->empty())\n        throw LispErrInvalidExpression(*iLookAhead);\n\n    throw LispErrInvalidExpression();\n}\n\nInfixParser::InfixParser(LispTokenizer& aTokenizer,\n                         LispInput& aInput,\n                         LispEnvironment& aEnvironment,\n                         LispOperators& aPrefixOperators,\n                         LispOperators& aInfixOperators,\n                         LispOperators& aPostfixOperators,\n                         LispOperators& aBodiedOperators) :\n    LispParser(aTokenizer, aInput, aEnvironment),\n    iPrefixOperators(aPrefixOperators),\n    iInfixOperators(aInfixOperators),\n    iPostfixOperators(aPostfixOperators),\n    iBodiedOperators(aBodiedOperators)\n{\n}\n\nvoid InfixParser::Parse(LispPtr& aResult)\n{\n    ParseCont(aResult);\n}\n\nvoid InfixParser::ParseCont(LispPtr& aResult)\n{\n    ParsedObject object(*this);\n    object.Parse();\n    aResult = object.iResult;\n}\n\nvoid ParsedObject::ReadToken()\n{\n    // Get token.\n    iLookAhead = iParser.iEnvironment.HashTable().LookUp(\n        iParser.iTokenizer.NextToken(iParser.iInput));\n    if (iLookAhead->empty())\n        iEndOfFile = true;\n}\n\nvoid ParsedObject::MatchToken(const LispString* aToken)\n{\n    if (aToken != iLookAhead)\n        Fail();\n\n    ReadToken();\n}\n\nvoid ParsedObject::Parse()\n{\n    ReadToken();\n    if (iEndOfFile) {\n        iResult = (iParser.iEnvironment.iEndOfFile->Copy());\n        return;\n    }\n\n    ReadExpression(KMaxPrecedence); // least precedence\n\n    if (iLookAhead != iParser.iEnvironment.iEndStatement->String())\n        Fail();\n}\n\nvoid ParsedObject::Combine(int aNrArgsToCombine)\n{\n    LispPtr subList(LispSubList::New(iResult));\n\n    // TODO: woof -- such ugliness!\n\n    LispIterator iter(iResult);\n    for (int i = 0; i < aNrArgsToCombine; i++, ++iter)\n        if (!iter.getObj())\n            Fail();\n\n    if (!iter.getObj())\n        Fail();\n\n    subList->Nixed() = *++iter;\n    *iter = nullptr;\n\n    InternalReverseList((*subList->SubList())->Nixed(), // TODO: woof\n                        (*subList->SubList())->Nixed());\n    iResult = subList;\n}\n\nvoid ParsedObject::GetOtherSide(int aNrArgsToCombine, int depth)\n{\n    const LispString* theOperator = iLookAhead;\n    MatchToken(iLookAhead);\n    ReadExpression(depth);\n    InsertAtom(theOperator);\n    Combine(aNrArgsToCombine);\n}\n\nvoid ParsedObject::InsertAtom(const LispString* aString)\n{\n    LispPtr ptr(LispAtom::New(iParser.iEnvironment, *aString));\n\n    ptr->Nixed() = iResult;\n    iResult = ptr;\n}\n\nvoid ParsedObject::ReadExpression(int depth)\n{\n    ReadAtom();\n\n    for (;;) {\n        // Handle special case: a[b]. a is matched with lowest precedence!!\n        if (iLookAhead == iParser.iEnvironment.iProgOpen->String()) {\n            // Match opening bracket\n            MatchToken(iLookAhead);\n            // Read \"index\" argument\n            ReadExpression(KMaxPrecedence);\n            // Match closing bracket\n            if (iLookAhead != iParser.iEnvironment.iProgClose->String())\n                throw LispErrGeneric(\n                    std::string(\"Expecting a ] close bracket for program \"\n                                \"block, but got \") +\n                    *iLookAhead + std::string(\" instead\"));\n\n            MatchToken(iLookAhead);\n            // Build into Ntn(...)\n            const LispString* theOperator = iParser.iEnvironment.iNth->String();\n            InsertAtom(theOperator);\n            Combine(2);\n        } else {\n            LispOperators::const_iterator opi =\n                iParser.iInfixOperators.find(iLookAhead);\n\n            if (opi == iParser.iInfixOperators.end()) {\n                if (!IsSymbolic((*iLookAhead)[0]))\n                    return;\n\n                const std::size_t origlen = iLookAhead->size();\n                std::size_t len = origlen;\n\n                while (len > 1) {\n                    len -= 1;\n                    const LispString* lookUp =\n                        iParser.iEnvironment.HashTable().LookUp(\n                            iLookAhead->substr(0, len));\n\n                    opi = iParser.iInfixOperators.find(lookUp);\n\n                    if (opi != iParser.iInfixOperators.end()) {\n\n                        const LispString* lookUpRight =\n                            iParser.iEnvironment.HashTable().LookUp(\n                                iLookAhead->substr(len, origlen - len));\n\n                        if (iParser.iPrefixOperators.find(lookUpRight) !=\n                            iParser.iPrefixOperators.end()) {\n                            iLookAhead = lookUp;\n                            LispInput& input = iParser.iInput;\n                            std::size_t newPos =\n                                input.Position() - (origlen - len);\n                            input.SetPosition(newPos);\n                            break;\n                        }\n\n                        opi = iParser.iInfixOperators.end();\n                    }\n                }\n\n                if (opi == iParser.iInfixOperators.end())\n                    return;\n            }\n\n            if (depth < opi->second.iPrecedence)\n                return;\n            int upper = opi->second.iPrecedence;\n            if (!opi->second.iRightAssociative)\n                upper--;\n            GetOtherSide(2, upper);\n        }\n    }\n}\n\nvoid ParsedObject::ReadAtom()\n{\n    LispOperators::const_iterator opi =\n        iParser.iPrefixOperators.find(iLookAhead);\n    if (opi != iParser.iPrefixOperators.end()) {\n        const LispString* theOperator = iLookAhead;\n        MatchToken(iLookAhead);\n        {\n            ReadExpression(opi->second.iPrecedence);\n            InsertAtom(theOperator);\n            Combine(1);\n        }\n    } // Else parse brackets\n    else if (iLookAhead == iParser.iEnvironment.iBracketOpen->String()) {\n        MatchToken(iLookAhead);\n        ReadExpression(KMaxPrecedence); // least precedence\n        MatchToken(iParser.iEnvironment.iBracketClose->String());\n    } // Parse lists\n    else if (iLookAhead == iParser.iEnvironment.iListOpen->String()) {\n        int nrargs = 0;\n        MatchToken(iLookAhead);\n        while (iLookAhead != iParser.iEnvironment.iListClose->String()) {\n            ReadExpression(KMaxPrecedence); // least precedence\n            nrargs++;\n\n            if (iLookAhead == iParser.iEnvironment.iComma->String()) {\n                MatchToken(iLookAhead);\n            } else if (iLookAhead !=\n                       iParser.iEnvironment.iListClose->String()) {\n                throw LispErrGeneric(\n                    std::string(\"Expecting a } close bracket for program \"\n                                \"block, but got \") +\n                    *iLookAhead + std::string(\" instead\"));\n            }\n        }\n        MatchToken(iLookAhead);\n        const LispString* theOperator = iParser.iEnvironment.iList->String();\n        InsertAtom(theOperator);\n        Combine(nrargs);\n\n    } // Parse prog bodies\n    else if (iLookAhead == iParser.iEnvironment.iProgOpen->String()) {\n        int nrargs = 0;\n\n        MatchToken(iLookAhead);\n        while (iLookAhead != iParser.iEnvironment.iProgClose->String()) {\n            ReadExpression(KMaxPrecedence); // least precedence\n            nrargs++;\n\n            if (iLookAhead == iParser.iEnvironment.iEndStatement->String()) {\n                MatchToken(iLookAhead);\n            } else {\n                throw LispErrGeneric(std::string(\"Expecting ; end of statement \"\n                                                 \"in program block, but got \") +\n                                     *iLookAhead + std::string(\" instead\"));\n            }\n        }\n        MatchToken(iLookAhead);\n        const LispString* theOperator = iParser.iEnvironment.iProg->String();\n        InsertAtom(theOperator);\n\n        Combine(nrargs);\n    } // Else we have an atom.\n    else {\n        const LispString* theOperator = iLookAhead;\n        MatchToken(iLookAhead);\n\n        int nrargs = -1;\n        if (iLookAhead == iParser.iEnvironment.iBracketOpen->String()) {\n            nrargs = 0;\n            MatchToken(iLookAhead);\n            while (iLookAhead != iParser.iEnvironment.iBracketClose->String()) {\n                ReadExpression(KMaxPrecedence); // least precedence\n                nrargs++;\n\n                if (iLookAhead == iParser.iEnvironment.iComma->String()) {\n                    MatchToken(iLookAhead);\n                } else if (iLookAhead !=\n                           iParser.iEnvironment.iBracketClose->String()) {\n                    throw LispErrGeneric(\n                        std::string(\"Expecting a ) closing bracket for \"\n                                    \"sub-expression, but got \") +\n                        *iLookAhead + std::string(\" instead\"));\n                }\n            }\n            MatchToken(iLookAhead);\n\n            opi = iParser.iBodiedOperators.find(theOperator);\n            if (opi != iParser.iBodiedOperators.end()) {\n                ReadExpression(opi->second.iPrecedence); // KMaxPrecedence\n                nrargs++;\n            }\n        }\n        InsertAtom(theOperator);\n        if (nrargs >= 0)\n            Combine(nrargs);\n    }\n\n    // Parse postfix operators\n\n    while (iParser.iPostfixOperators.find(iLookAhead) !=\n           iParser.iPostfixOperators.end()) {\n        InsertAtom(iLookAhead);\n        MatchToken(iLookAhead);\n        Combine(1);\n    }\n}\n\nvoid InfixPrinter::WriteToken(std::ostream& aOutput, const std::string& aString)\n{\n    if (IsAlNum(iPrevLastChar) && (IsAlNum(aString[0]) || aString[0] == '_'))\n        aOutput.put(' ');\n    else if (IsSymbolic(iPrevLastChar) && IsSymbolic(aString[0]))\n        aOutput.put(' ');\n\n    aOutput.write(aString.c_str(), aString.size());\n    RememberLastChar(aString.back());\n}\n\nvoid InfixPrinter::RememberLastChar(char aChar)\n{\n    iPrevLastChar = aChar;\n}\n\nvoid InfixPrinter::Print(const LispPtr& aExpression,\n                         std::ostream& aOutput,\n                         LispEnvironment& aEnvironment)\n{\n    iCurrentEnvironment = &aEnvironment;\n    Print(aExpression, aOutput, KMaxPrecedence);\n}\n\nvoid InfixPrinter::Print(const LispPtr& aExpression,\n                         std::ostream& aOutput,\n                         int iPrecedence)\n{\n    assert(aExpression);\n\n    const LispString* string = aExpression->String();\n    if (string) {\n        int bracket = 0;\n        if (iPrecedence < KMaxPrecedence && (*string)[0] == '-' &&\n            (std::isdigit((*string)[1]) || (*string)[1] == '.')) {\n            bracket = 1;\n        }\n        if (bracket)\n            WriteToken(aOutput, \"(\");\n        WriteToken(aOutput, *string);\n        if (bracket)\n            WriteToken(aOutput, \")\");\n        return;\n    }\n\n    if (const GenericClass* g = aExpression->Generic()) {\n        if (const AssociationClass* a =\n                dynamic_cast<const AssociationClass*>(g)) {\n            WriteToken(aOutput, \"Association\");\n            WriteToken(aOutput, \"(\");\n            Print(a->ToList(), aOutput, KMaxPrecedence);\n            WriteToken(aOutput, \")\");\n        } else if (const ArrayClass* a = dynamic_cast<const ArrayClass*>(g)) {\n            WriteToken(aOutput, \"Array\");\n            WriteToken(aOutput, \"(\");\n            WriteToken(aOutput, \"{\");\n            const std::size_t n = a->Size();\n            for (std::size_t i = 1; i <= n; ++i) {\n                Print(LispPtr(a->GetElement(i)), aOutput, KMaxPrecedence);\n                if (i != n)\n                    WriteToken(aOutput, \",\");\n            }\n            WriteToken(aOutput, \"}\");\n            WriteToken(aOutput, \")\");\n        } else {\n            WriteToken(aOutput, g->TypeName());\n        }\n        return;\n    }\n\n    LispPtr* subList = aExpression->SubList();\n    if (!subList) {\n        throw LispErrUnprintableToken();\n    } else {\n        const std::size_t length = InternalListLength(*subList);\n        string = (*subList)->String();\n\n        const LispOperators::const_iterator prefix =\n            length != 2 ? iPrefixOperators.end()\n                        : iPrefixOperators.find(string);\n\n        const LispOperators::const_iterator infix =\n            length != 3 ? iInfixOperators.end() : iInfixOperators.find(string);\n\n        const LispOperators::const_iterator postfix =\n            length != 2 ? iPostfixOperators.end()\n                        : iPostfixOperators.find(string);\n\n        const LispOperators::const_iterator bodied =\n            iBodiedOperators.find(string);\n\n        const LispInFixOperator* op = nullptr;\n\n        if (prefix != iPrefixOperators.end())\n            op = &prefix->second;\n\n        if (postfix != iPostfixOperators.end())\n            op = &postfix->second;\n\n        if (infix != iInfixOperators.end())\n            op = &infix->second;\n\n        if (op) {\n            LispPtr* left = nullptr;\n            LispPtr* right = nullptr;\n\n            if (prefix != iPrefixOperators.end()) {\n                right = &(*subList)->Nixed();\n            } else if (infix != iInfixOperators.end()) {\n                left = &(*subList)->Nixed();\n                right = &(*subList)->Nixed()->Nixed();\n            } else if (postfix != iPostfixOperators.end()) {\n                left = &(*subList)->Nixed();\n            }\n\n            if (iPrecedence < op->iPrecedence) {\n                WriteToken(aOutput, \"(\");\n            } else {\n                // Vladimir?    aOutput.Write(\" \");\n            }\n            if (left)\n                Print(*left, aOutput, op->iLeftPrecedence);\n            WriteToken(aOutput, *string);\n            if (right)\n                Print(*right, aOutput, op->iRightPrecedence);\n            if (iPrecedence < op->iPrecedence)\n                WriteToken(aOutput, \")\");\n        } else {\n            LispIterator iter((*subList)->Nixed());\n            if (string == iCurrentEnvironment->iList->String()) {\n                WriteToken(aOutput, \"{\");\n                for (int ii = 0; iter.getObj(); ii++, ++iter) {\n                    if (ii)\n                        WriteToken(aOutput, \",\");\n                    Print(*iter, aOutput, KMaxPrecedence);\n                }\n                WriteToken(aOutput, \"}\");\n            } else if (string == iCurrentEnvironment->iProg->String()) {\n                WriteToken(aOutput, \"[\");\n                while (iter.getObj()) {\n                    Print(*iter, aOutput, KMaxPrecedence);\n                    ++iter;\n                    WriteToken(aOutput, \";\");\n                }\n                WriteToken(aOutput, \"]\");\n            } else if (string == iCurrentEnvironment->iNth->String()) {\n                Print(*iter, aOutput, 0);\n                ++iter;\n                WriteToken(aOutput, \"[\");\n                Print(*iter, aOutput, KMaxPrecedence);\n                WriteToken(aOutput, \"]\");\n            } else {\n                int bracket = false;\n                if (bodied != iBodiedOperators.end()) {\n                    // printf(\"%d > %d\\n\",iPrecedence, bodied->iPrecedence);\n                    if (iPrecedence < bodied->second.iPrecedence)\n                        bracket = true;\n                }\n                if (bracket)\n                    WriteToken(aOutput, \"(\");\n                if (string) {\n                    WriteToken(aOutput, *string);\n                } else {\n                    Print(*subList, aOutput, 0);\n                }\n                WriteToken(aOutput, \"(\");\n\n                LispIterator counter(*iter);\n                int nr = 0;\n\n                while (counter.getObj()) {\n                    ++counter;\n                    nr++;\n                }\n\n                if (bodied != iBodiedOperators.end())\n                    nr--;\n                while (nr--) {\n                    Print(*iter, aOutput, KMaxPrecedence);\n                    ++iter;\n                    if (nr)\n                        WriteToken(aOutput, \",\");\n                }\n                WriteToken(aOutput, \")\");\n                if (iter.getObj()) {\n                    assert(bodied != iBodiedOperators.end());\n                    Print(*iter, aOutput, bodied->second.iPrecedence);\n                }\n\n                if (bracket)\n                    WriteToken(aOutput, \")\");\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lispatom.cpp",
    "content": "\n#include \"yacas/lispatom.h\"\n#include \"yacas/lisperror.h\"\n#include \"yacas/numbers.h\"\n#include \"yacas/standard.h\"\n\n#include <algorithm>\n#include <cassert>\n\n/// construct an atom from a string representation.\nLispObject* LispAtom::New(LispEnvironment& aEnvironment,\n                          const std::string& aString)\n{\n    if (IsNumber(aString, true)) // check if aString is a number (int or float)\n        return new LispNumber(new LispString(aString),\n                              aEnvironment.Precision());\n\n    return new LispAtom(aEnvironment.HashTable().LookUp(aString));\n}\n\nLispAtom::LispAtom(const LispString* aString) : iString(aString)\n{\n    assert(aString);\n}\n\nconst LispString* LispAtom::String()\n{\n    assert(iString);\n    return iString;\n}\n\n//------------------------------------------------------------------------------\n// LispSublist methods\n\nLispSubList* LispSubList::New(LispObject* aSubList)\n{\n    return new LispSubList(aSubList);\n}\n\n// A destructor for lists that is less taxing for stacks :-)\n// Eg. deleting a list deletes the entire sublist also, in\n// a tail-recursive way...\nLispSubList::~LispSubList()\n{\n    if (!!iSubList) {\n        LispPtr next;\n        LispIterator iter(iSubList);\n        bool busy = (iter.getObj()->use_count() == 1);\n        while (busy) // while there are things to delete...\n        {\n            // TODO: woof -- fix this ugliness!\n            LispPtr nextToDelete;\n            // Make sure \"next\" holds the tail of the list\n            nextToDelete = (iter.getObj()->Nixed());\n            // Separate out the current element...\n            if (iter.getObj()->use_count() ==\n                1) { // Destructive operation only if necessary...\n                iter.getObj()->Nixed() = (nullptr);\n                // And delete it.\n                (*iter) = (nullptr);\n            } else\n                busy = false;\n            next = (nextToDelete);\n            iter = next;\n            if (!iter.getObj())\n                busy = false;\n        }\n    }\n}\n\n//------------------------------------------------------------------------------\n// LispGenericClass methods\n\nLispGenericClass* LispGenericClass::New(GenericClass* aClass)\n{\n    return new LispGenericClass(aClass);\n}\n\nLispGenericClass::LispGenericClass(GenericClass* aClass) : iClass(aClass)\n{\n    assert(aClass != nullptr);\n    aClass->iReferenceCount++;\n}\n\nLispGenericClass::~LispGenericClass()\n{\n    if (--iClass->iReferenceCount == 0)\n        delete iClass;\n}\n\nGenericClass* LispGenericClass::Generic()\n{\n    return iClass;\n}\n\n//------------------------------------------------------------------------------\n// LispNumber methods - proceed at your own risk\n\n/// return a string representation in decimal\nLispString* LispNumber::String()\n{\n    if (!iString) {\n        assert(\n            iNumber\n                .ptr()); // either the string is null or the number but not both\n        LispString* str = new LispString;\n        // export the current number to string and store it as\n        // LispNumber::iString\n        iNumber->ToString(\n            *str,\n            bits_to_digits(std::max(1, iNumber->GetPrecision()), BASE10),\n            BASE10);\n        iString = str;\n    }\n    return iString;\n}\n\n/// Return a BigNumber object.\n// Will create a BigNumber object out of a stored string, at given precision (in\n// decimal) - that's why the aPrecision argument must be here - but only if no\n// BigNumber object is already present\nBigNumber* LispNumber::Number(int aBasePrecision)\n{\n    if (!iNumber) { // create and store a BigNumber out of string\n        assert(iString.ptr());\n        // aBasePrecision is in digits, not in bits, ok\n        iNumber = new BigNumber(*iString, aBasePrecision, BASE10);\n    }\n\n    // check if the BigNumber object has enough precision, if not, extend it\n    // (applies only to floats). Note that iNumber->GetPrecision() might be < 0\n    else if (!iNumber->IsInt() &&\n             iNumber->GetPrecision() <\n                 (int)digits_to_bits(aBasePrecision, BASE10)) {\n        if (iString) // have string representation, can extend precision\n            iNumber = new BigNumber(*iString, aBasePrecision, BASE10);\n    }\n    return iNumber;\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lispenvironment.cpp",
    "content": "\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispuserfunc.h\"\n#include \"yacas/mathuserfunc.h\"\n#include \"yacas/standard.h\"\n\n// we need this only for digits_to_bits\n#include \"yacas/numbers.h\"\n\nLispEnvironment::LispEnvironment(YacasCoreCommands& aCoreCommands,\n                                 LispUserFunctions& aUserFunctions,\n                                 LispGlobal& aGlobals,\n                                 LispHashTable& aHashTable,\n                                 std::ostream& aOutput,\n                                 LispPrinter& aPrinter,\n                                 LispOperators& aPreFixOperators,\n                                 LispOperators& aInFixOperators,\n                                 LispOperators& aPostFixOperators,\n                                 LispOperators& aBodiedOperators,\n                                 LispIdentifiers& protected_symbols,\n                                 LispInput* aCurrentInput) :\n    iPrecision(10),       // default user precision of 10 decimal digits\n    iBinaryPrecision(34), // same as 34 bits\n    iInputDirectories(),\n    // iCleanup(),\n    iEvalDepth(0),\n    iMaxEvalDepth(1000),\n    stop_evaluation(false),\n    iEvaluator(new BasicEvaluator),\n    iInputStatus(),\n    secure(false),\n    iTrue(),\n    iFalse(),\n    iEndOfFile(),\n    iEndStatement(),\n    iProgOpen(),\n    iProgClose(),\n    iNth(),\n    iBracketOpen(),\n    iBracketClose(),\n    iListOpen(),\n    iListClose(),\n    iComma(),\n    iList(),\n    iProg(),\n    iLastUniqueId(1),\n    iDebugger(nullptr),\n    iInitialOutput(&aOutput),\n    iCoreCommands(aCoreCommands),\n    iUserFunctions(aUserFunctions),\n    iHashTable(aHashTable),\n    iDefFiles(),\n    iPrinter(aPrinter),\n    iCurrentOutput(&aOutput),\n    iGlobals(aGlobals),\n    iPreFixOperators(aPreFixOperators),\n    iInFixOperators(aInFixOperators),\n    iPostFixOperators(aPostFixOperators),\n    iBodiedOperators(aBodiedOperators),\n    protected_symbols(protected_symbols),\n    iCurrentInput(aCurrentInput),\n    iPrettyReader(nullptr),\n    iPrettyPrinter(nullptr),\n    iDefaultTokenizer(),\n    iXmlTokenizer(),\n    iCurrentTokenizer(&iDefaultTokenizer)\n{\n    iTrue = LispAtom::New(*this, \"True\");\n    iFalse = LispAtom::New(*this, \"False\");\n\n    Protect(iTrue->String());\n    Protect(iFalse->String());\n\n    iEndOfFile = LispAtom::New(*this, \"EndOfFile\");\n    iEndStatement = LispAtom::New(*this, \";\");\n    iProgOpen = LispAtom::New(*this, \"[\");\n    iProgClose = LispAtom::New(*this, \"]\");\n    iNth = LispAtom::New(*this, \"Nth\");\n    iBracketOpen = LispAtom::New(*this, \"(\");\n    iBracketClose = LispAtom::New(*this, \")\");\n    iListOpen = LispAtom::New(*this, \"{\");\n    iListClose = LispAtom::New(*this, \"}\");\n    iComma = LispAtom::New(*this, \",\");\n    iList = LispAtom::New(*this, \"List\");\n    iProg = LispAtom::New(*this, \"Prog\");\n\n    Protect(iList->String());\n    Protect(iProg->String());\n\n    Protect(iHashTable.LookUp(\"Infinity\"));\n    Protect(iHashTable.LookUp(\"Undefined\"));\n\n    PushLocalFrame(true);\n}\n\nLispEnvironment::~LispEnvironment()\n{\n    delete iEvaluator;\n    delete iDebugger;\n}\n\nvoid LispEnvironment::SetPrecision(int aPrecision)\n{\n    iPrecision = aPrecision; // precision in decimal digits\n    iBinaryPrecision = digits_to_bits(aPrecision, BASE10); // in bits\n}\n\nint LispEnvironment::GetUniqueId()\n{\n    return iLastUniqueId++;\n}\n\nLispPtr* LispEnvironment::FindLocal(const LispString* aVariable)\n{\n    assert(!_local_frames.empty());\n\n    std::size_t last = _local_vars.size();\n\n    for (std::vector<LocalVariableFrame>::const_reverse_iterator f =\n             _local_frames.rbegin();\n         f != _local_frames.rend();\n         ++f) {\n        const std::size_t first = f->first;\n        for (std::size_t i = last; i > first; --i)\n            if (_local_vars[i - 1].var == aVariable)\n                return &_local_vars[i - 1].val;\n\n        if (f->fenced)\n            break;\n\n        last = first;\n    }\n    return nullptr;\n}\n\nvoid LispEnvironment::SetVariable(const LispString* aVariable,\n                                  LispPtr& aValue,\n                                  bool aGlobalLazyVariable)\n{\n    if (LispPtr* local = FindLocal(aVariable)) {\n        *local = aValue;\n        return;\n    }\n\n    // FIXME: or should local variables be protected as well?\n    if (Protected(aVariable))\n        throw LispErrProtectedSymbol(*aVariable);\n\n    auto i = iGlobals.find(aVariable);\n    if (i != iGlobals.end())\n        i->second = LispGlobalVariable(aValue);\n    else\n        i = iGlobals\n                .insert(std::make_pair(aVariable, LispGlobalVariable(aValue)))\n                .first;\n\n    if (aGlobalLazyVariable)\n        i->second.SetEvalBeforeReturn(true);\n}\n\nvoid LispEnvironment::GetVariable(const LispString* aVariable, LispPtr& aResult)\n{\n    aResult = nullptr;\n\n    if (LispPtr* local = FindLocal(aVariable)) {\n        aResult = *local;\n        return;\n    }\n\n    auto i = iGlobals.find(aVariable);\n\n    if (i != iGlobals.end()) {\n        LispGlobalVariable* l = &i->second;\n        if (l->iEvalBeforeReturn) {\n            iEvaluator->Eval(*this, aResult, l->iValue);\n            // re-lookup the global variable, as this pointer might now be\n            // invalid due to the evaluation actually changing the global\n            // itself.\n            l = &iGlobals.find(aVariable)->second;\n\n            l->iValue = aResult;\n            l->iEvalBeforeReturn = false;\n        } else {\n            aResult = l->iValue;\n        }\n    }\n}\n\nvoid LispEnvironment::UnsetVariable(const LispString* var)\n{\n    if (LispPtr* local = FindLocal(var))\n        *local = nullptr;\n    else {\n        // FIXME: or should local variables be protected as well?\n        if (Protected(var))\n            throw LispErrProtectedSymbol(*var);\n        iGlobals.erase(var);\n    }\n}\n\nvoid LispEnvironment::PushLocalFrame(bool fenced)\n{\n    _local_frames.emplace_back(_local_vars.size(), fenced);\n}\n\nvoid LispEnvironment::PopLocalFrame()\n{\n    assert(!_local_frames.empty());\n\n    _local_vars.erase(_local_vars.begin() + _local_frames.back().first,\n                      _local_vars.end());\n    _local_frames.pop_back();\n}\n\nvoid LispEnvironment::NewLocal(const LispString* var, LispObject* val)\n{\n    assert(!_local_frames.empty());\n\n    _local_vars.emplace_back(var, val);\n}\n\nvoid LispEnvironment::CurrentLocals(LispPtr& aResult)\n{\n    assert(!_local_frames.empty());\n\n    LispObject* locals = nullptr;\n\n    std::size_t last = _local_vars.size();\n\n    for (std::vector<LocalVariableFrame>::const_reverse_iterator f =\n             _local_frames.rbegin();\n         f != _local_frames.rend();\n         ++f) {\n        const std::size_t first = f->first;\n        for (std::size_t i = last; i > first; --i)\n            locals =\n                LispObjectAdder(LispAtom::New(*this, *_local_vars[i - 1].var)) +\n                LispObjectAdder(locals);\n\n        if (f->fenced)\n            break;\n\n        last = first;\n    }\n    aResult = LispSubList::New(LispObjectAdder(iList->Copy()) +\n                               LispObjectAdder(locals));\n}\n\nvoid LispEnvironment::GlobalVariables(LispPtr& aResult)\n{\n    LispPtr vars(iList->Copy());\n    LispIterator tail(vars);\n    ++tail;\n\n    for (const auto& p: iGlobals) {\n        if (p.first->front() == '$' || p.first->front() == '%')\n            continue;\n        *tail = LispAtom::New(*this, *p.first);\n        ++tail;\n    }\n    aResult = LispSubList::New(vars);\n}\n\nLispPrinter& LispEnvironment::CurrentPrinter()\n{\n    return iPrinter;\n}\n\nLispDefFiles& LispEnvironment::DefFiles()\n{\n    return iDefFiles;\n}\n\nLispOperators& LispEnvironment::PreFix()\n{\n    return iPreFixOperators;\n}\nLispOperators& LispEnvironment::InFix()\n{\n    return iInFixOperators;\n}\nLispOperators& LispEnvironment::PostFix()\n{\n    return iPostFixOperators;\n}\nLispOperators& LispEnvironment::Bodied()\n{\n    return iBodiedOperators;\n}\n\nLispInput* LispEnvironment::CurrentInput()\n{\n    return iCurrentInput;\n}\n\nvoid LispEnvironment::SetCurrentInput(LispInput* aInput)\n{\n    iCurrentInput = aInput;\n}\n\nstd::ostream& LispEnvironment::CurrentOutput()\n{\n    return *iCurrentOutput;\n}\n\nvoid LispEnvironment::SetCurrentOutput(std::ostream& aOutput)\n{\n    iCurrentOutput = &aOutput;\n}\n\nLispUserFunction* LispEnvironment::UserFunction(LispPtr& aArguments)\n{\n    auto i = iUserFunctions.find(aArguments->String());\n    if (i != iUserFunctions.end()) {\n        LispMultiUserFunction* multiUserFunc = &i->second;\n        int arity = InternalListLength(aArguments) - 1;\n        return multiUserFunc->UserFunc(arity);\n    }\n    return nullptr;\n}\n\nLispUserFunction* LispEnvironment::UserFunction(const LispString* aName,\n                                                int aArity)\n{\n    auto i = iUserFunctions.find(aName);\n    if (i != iUserFunctions.end())\n        return i->second.UserFunc(aArity);\n\n    return nullptr;\n}\n\nvoid LispEnvironment::UnFenceRule(const LispString* aOperator, int aArity)\n{\n    if (Protected(aOperator))\n        throw LispErrProtectedSymbol(*aOperator);\n\n    auto i = iUserFunctions.find(aOperator);\n\n    if (i == iUserFunctions.end())\n        throw LispErrInvalidArg();\n\n    LispMultiUserFunction* multiUserFunc = &i->second;\n\n    LispUserFunction* userFunc = multiUserFunc->UserFunc(aArity);\n\n    if (!userFunc)\n        throw LispErrInvalidArg();\n\n    userFunc->UnFence();\n}\n\nvoid LispEnvironment::Retract(const LispString* aOperator, int aArity)\n{\n    if (Protected(aOperator))\n        throw LispErrProtectedSymbol(*aOperator);\n\n    auto i = iUserFunctions.find(aOperator);\n\n    if (i != iUserFunctions.end())\n        i->second.DeleteBase(aArity);\n}\n\nvoid LispEnvironment::DeclareRuleBase(const LispString* aOperator,\n                                      LispPtr& aParameters,\n                                      int aListed)\n{\n    if (Protected(aOperator))\n        throw LispErrProtectedSymbol(*aOperator);\n\n    LispMultiUserFunction* multiUserFunc = MultiUserFunction(aOperator);\n\n    /*\n     if (multiUserFunc->iFileToOpen)\n    {\n        LISPASSERT(multiUserFunc->iFileToOpen->iIsLoaded);\n        }\n        */\n\n    // add an operator with this arity to the multiuserfunc.\n    BranchingUserFunction* newFunc =\n        aListed ? new ListedBranchingUserFunction(aParameters)\n                : new BranchingUserFunction(aParameters);\n\n    multiUserFunc->DefineRuleBase(newFunc);\n}\n\nvoid LispEnvironment::DeclareMacroRuleBase(const LispString* aOperator,\n                                           LispPtr& aParameters,\n                                           int aListed)\n{\n    if (Protected(aOperator))\n        throw LispErrProtectedSymbol(*aOperator);\n\n    LispMultiUserFunction* multiUserFunc = MultiUserFunction(aOperator);\n\n    MacroUserFunction* newFunc = aListed\n                                     ? new ListedMacroUserFunction(aParameters)\n                                     : new MacroUserFunction(aParameters);\n\n    multiUserFunc->DefineRuleBase(newFunc);\n}\n\nLispMultiUserFunction*\nLispEnvironment::MultiUserFunction(const LispString* aOperator)\n{\n    auto i = iUserFunctions.find(aOperator);\n\n    if (i != iUserFunctions.end())\n        return &i->second;\n\n    LispMultiUserFunction newMulti;\n    return &iUserFunctions.insert(std::make_pair(aOperator, newMulti))\n                .first->second;\n}\n\nvoid LispEnvironment::HoldArgument(const LispString* aOperator,\n                                   const LispString* aVariable)\n{\n    auto i = iUserFunctions.find(aOperator);\n\n    if (i == iUserFunctions.end())\n        throw LispErrInvalidArg();\n\n    LispMultiUserFunction* multiUserFunc = &i->second;\n\n    multiUserFunc->HoldArgument(aVariable);\n}\n\nvoid LispEnvironment::Protect(const LispString* symbol)\n{\n    protected_symbols.insert(symbol);\n}\n\nvoid LispEnvironment::UnProtect(const LispString* symbol)\n{\n    protected_symbols.erase(symbol);\n}\n\nbool LispEnvironment::Protected(const LispString* symbol) const\n{\n    return protected_symbols.find(symbol) != protected_symbols.end();\n}\n\nvoid LispEnvironment::DefineRule(const LispString* aOperator,\n                                 int aArity,\n                                 int aPrecedence,\n                                 LispPtr& aPredicate,\n                                 LispPtr& aBody)\n{\n    if (Protected(aOperator))\n        throw LispErrProtectedSymbol(*aOperator);\n\n    // Find existing multiuser func.\n    auto i = iUserFunctions.find(aOperator);\n\n    if (i == iUserFunctions.end())\n        throw LispErrCreatingRule();\n\n    LispMultiUserFunction* multiUserFunc = &i->second;\n\n    // Get the specific user function with the right arity\n    LispUserFunction* userFunc = multiUserFunc->UserFunc(aArity);\n\n    if (!userFunc)\n        throw LispErrCreatingRule();\n\n    // Declare a new evaluation rule\n\n    if (IsTrue(*this, aPredicate)) {\n        //        printf(\"FastPredicate on %s\\n\",aOperator->String());\n        userFunc->DeclareRule(aPrecedence, aBody);\n    } else\n        userFunc->DeclareRule(aPrecedence, aPredicate, aBody);\n}\n\nvoid LispEnvironment::DefineRulePattern(const LispString* aOperator,\n                                        int aArity,\n                                        int aPrecedence,\n                                        LispPtr& aPredicate,\n                                        LispPtr& aBody)\n{\n    //    if (Protected(aOperator))\n    //        throw LispErrProtectedSymbol(*aOperator);\n\n    // Find existing multiuser func.\n    auto i = iUserFunctions.find(aOperator);\n\n    if (i == iUserFunctions.end())\n        throw LispErrCreatingRule();\n\n    LispMultiUserFunction* multiUserFunc = &i->second;\n\n    // Get the specific user function with the right arity\n    LispUserFunction* userFunc = multiUserFunc->UserFunc(aArity);\n\n    if (!userFunc)\n        throw LispErrCreatingRule();\n\n    // Declare a new evaluation rule\n    userFunc->DeclarePattern(aPrecedence, aPredicate, aBody);\n}\n\nvoid LispEnvironment::SetCommand(YacasEvalCaller aEvaluatorFunc,\n                                 const char* aString,\n                                 int aNrArgs,\n                                 int aFlags)\n{\n    const LispString* name = HashTable().LookUp(aString);\n    YacasEvaluator eval(aEvaluatorFunc, aNrArgs, aFlags);\n    auto i = iCoreCommands.find(name);\n    if (i != iCoreCommands.end())\n        i->second = eval;\n    else\n        iCoreCommands.insert(std::make_pair(name, eval));\n}\n\nvoid LispEnvironment::RemoveCoreCommand(char* aString)\n{\n    iCoreCommands.erase(HashTable().LookUp(aString));\n}\n\nLispLocalEvaluator::LispLocalEvaluator(LispEnvironment& aEnvironment,\n                                       LispEvaluatorBase* aNewEvaluator) :\n    iPreviousEvaluator(aEnvironment.iEvaluator),\n    iEnvironment(aEnvironment)\n{\n    aEnvironment.iEvaluator = aNewEvaluator;\n}\nLispLocalEvaluator::~LispLocalEvaluator()\n{\n    delete iEnvironment.iEvaluator;\n    iEnvironment.iEvaluator = iPreviousEvaluator;\n}\n\nLispLocalTrace::LispLocalTrace(LispUserFunction* aUserFunc) :\n    iUserFunc(aUserFunc)\n{\n    if (iUserFunc != nullptr)\n        iUserFunc->Trace();\n}\nLispLocalTrace::~LispLocalTrace()\n{\n    if (iUserFunc != nullptr)\n        iUserFunc->UnTrace();\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lisperror.cpp",
    "content": "#include \"yacas/lisperror.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/standard.h\"\n\nvoid HandleError(const LispError& error,\n                 LispEnvironment& aEnvironment,\n                 std::ostream& aOutput)\n{\n    if (aEnvironment.iInputStatus.LineNumber() >= 0) {\n        aOutput << aEnvironment.iInputStatus.FileName();\n        aOutput << \"(\";\n        aOutput << aEnvironment.iInputStatus.LineNumber();\n        aOutput << \") : \";\n    }\n    // aEnvironment.iCleanup.Delete();\n    aOutput << error.what() << '\\n';\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lispeval.cpp",
    "content": "\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispuserfunc.h\"\n#include \"yacas/standard.h\"\n\n#include \"yacas/errors.h\"\n#include \"yacas/infixparser.h\"\n#include \"yacas/lispio.h\"\n#include \"yacas/platfileio.h\"\n\n#include <regex>\n#include <sstream>\n\nLispUserFunction* GetUserFunction(LispEnvironment& aEnvironment,\n                                  LispPtr* subList)\n{\n    LispObject* head = (*subList);\n    LispUserFunction* userFunc = aEnvironment.UserFunction(*subList);\n    if (userFunc) {\n        return userFunc;\n    } else if (head->String() != nullptr) {\n        LispMultiUserFunction* multiUserFunc =\n            aEnvironment.MultiUserFunction(head->String());\n        if (multiUserFunc->iFileToOpen != nullptr) {\n            LispDefFile* def = multiUserFunc->iFileToOpen;\n            multiUserFunc->iFileToOpen = nullptr;\n            InternalUse(aEnvironment, def->FileName());\n        }\n        userFunc = aEnvironment.UserFunction(*subList);\n    }\n    return userFunc;\n}\n\nUserStackInformation& LispEvaluatorBase::StackInformation()\n{\n    return iBasicInfo;\n}\n\nvoid LispEvaluatorBase::ResetStack() {}\n\nvoid LispEvaluatorBase::ShowStack(LispEnvironment& aEnvironment,\n                                  std::ostream& aOutput)\n{\n}\n\n// Eval: evaluates an expression. The result of this operation must\n// be a unique (copied) element! Eg. its Nixed might be set...\nvoid BasicEvaluator::Eval(LispEnvironment& aEnvironment,\n                          LispPtr& aResult,\n                          LispPtr& aExpression)\n{\n    assert(aExpression);\n\n    if (aEnvironment.stop_evaluation) {\n        aEnvironment.stop_evaluation = false;\n        ShowStack(aEnvironment, aEnvironment.CurrentOutput());\n        throw LispErrUserInterrupt();\n    }\n\n    aEnvironment.iEvalDepth++;\n    if (aEnvironment.iEvalDepth >= aEnvironment.iMaxEvalDepth) {\n        ShowStack(aEnvironment, aEnvironment.CurrentOutput());\n        throw LispErrMaxRecurseDepthReached();\n    }\n\n    const LispString* str = aExpression->String();\n\n    // Evaluate an atom: find the bound value (treat it as a variable)\n    if (str) {\n        if (str->front() == '\\\"') {\n            aResult = aExpression->Copy();\n            goto FINISH;\n        }\n\n        LispPtr val;\n        aEnvironment.GetVariable(str, val);\n        if (!!val) {\n            aResult = (val->Copy());\n            goto FINISH;\n        }\n        aResult = (aExpression->Copy());\n        goto FINISH;\n    }\n\n    {\n        LispPtr* subList = aExpression->SubList();\n\n        if (subList) {\n            LispObject* head = (*subList);\n            if (head) {\n                if (head->String()) {\n                    {\n                        const auto i =\n                            aEnvironment.CoreCommands().find(head->String());\n                        if (i != aEnvironment.CoreCommands().end()) {\n                            i->second.Evaluate(aResult, aEnvironment, *subList);\n                            goto FINISH;\n                        }\n                    }\n\n                    {\n                        LispUserFunction* userFunc;\n                        userFunc = GetUserFunction(aEnvironment, subList);\n                        if (userFunc) {\n                            userFunc->Evaluate(aResult, aEnvironment, *subList);\n                            goto FINISH;\n                        }\n                    }\n                } else {\n                    LispPtr oper((*subList));\n                    LispPtr args2((*subList)->Nixed());\n                    InternalApplyPure(oper, args2, aResult, aEnvironment);\n                    goto FINISH;\n                }\n                ReturnUnEvaluated(aResult, *subList, aEnvironment);\n                goto FINISH;\n            }\n        }\n        aResult = (aExpression->Copy());\n    }\nFINISH:\n    aEnvironment.iEvalDepth--;\n}\n\nvoid ShowExpression(LispString& outString,\n                    LispEnvironment& aEnvironment,\n                    LispPtr& aExpression)\n{\n    InfixPrinter infixprinter(aEnvironment.PreFix(),\n                              aEnvironment.InFix(),\n                              aEnvironment.PostFix(),\n                              aEnvironment.Bodied());\n    // Print out the current expression\n    std::ostringstream stream;\n    infixprinter.Print(aExpression, stream, aEnvironment);\n    outString.append(stream.str());\n\n    std::regex_replace(\n        outString, std::regex(\"(^\\\")|([^\\\\\\\\]\\\")\"), std::string(\"\\\\\\\"\"));\n}\n\nstatic void TraceShowExpression(LispEnvironment& aEnvironment,\n                                LispPtr& aExpression)\n{\n    LispString outString;\n    ShowExpression(outString, aEnvironment, aExpression);\n    aEnvironment.CurrentOutput().write(outString.c_str(), outString.size());\n}\n\nvoid TraceShowArg(LispEnvironment& aEnvironment,\n                  LispPtr& aParam,\n                  LispPtr& aValue)\n{\n    for (int i = 0; i < aEnvironment.iEvalDepth + 2; i++)\n        aEnvironment.CurrentOutput().write(\"  \", 2);\n    aEnvironment.CurrentOutput() << \"TrArg(\\\"\";\n    TraceShowExpression(aEnvironment, aParam);\n    aEnvironment.CurrentOutput() << \"\\\",\\\"\";\n    TraceShowExpression(aEnvironment, aValue);\n    aEnvironment.CurrentOutput() << \"\\\");\\n\";\n}\n\nvoid TraceShowEnter(LispEnvironment& aEnvironment, LispPtr& aExpression)\n{\n    for (int i = 0; i < aEnvironment.iEvalDepth; i++)\n        aEnvironment.CurrentOutput().write(\"  \", 2);\n    aEnvironment.CurrentOutput() << \"TrEnter(\\\"\";\n    {\n        const char* function = \"\";\n        if (aExpression->SubList()) {\n            LispPtr* sub = aExpression->SubList();\n            if ((*sub)->String())\n                function = (*sub)->String()->c_str();\n        }\n        aEnvironment.CurrentOutput() << function;\n    }\n    aEnvironment.CurrentOutput() << \"\\\",\\\"\";\n    TraceShowExpression(aEnvironment, aExpression);\n    aEnvironment.CurrentOutput() << \"\\\",\\\"\";\n    aEnvironment.CurrentOutput() << \"\"; // file\n    aEnvironment.CurrentOutput() << \"\\\",\";\n    aEnvironment.CurrentOutput() << \"0\"; // line\n    aEnvironment.CurrentOutput() << \");\\n\";\n}\n\nvoid TraceShowLeave(LispEnvironment& aEnvironment,\n                    LispPtr& aResult,\n                    LispPtr& aExpression)\n{\n    for (int i = 0; i < aEnvironment.iEvalDepth; i++)\n        aEnvironment.CurrentOutput().write(\"  \", 2);\n    aEnvironment.CurrentOutput().write(\"TrLeave(\\\"\", 9);\n    TraceShowExpression(aEnvironment, aExpression);\n    aEnvironment.CurrentOutput().write(\"\\\",\\\"\", 3);\n    TraceShowExpression(aEnvironment, aResult);\n    aEnvironment.CurrentOutput().write(\"\\\");\\n\", 4);\n}\n\nvoid TracedStackEvaluator::PushFrame()\n{\n    UserStackInformation* op = new UserStackInformation;\n    objs.push_back(op);\n}\n\nvoid TracedStackEvaluator::PopFrame()\n{\n    assert(!objs.empty());\n    delete objs.back();\n    objs.pop_back();\n}\n\nvoid TracedStackEvaluator::ResetStack()\n{\n    while (!objs.empty())\n        PopFrame();\n}\n\nUserStackInformation& TracedStackEvaluator::StackInformation()\n{\n    return *objs.back();\n}\n\nTracedStackEvaluator::~TracedStackEvaluator()\n{\n    ResetStack();\n}\n\nvoid TracedStackEvaluator::ShowStack(LispEnvironment& aEnvironment,\n                                     std::ostream& aOutput)\n{\n    LispLocalEvaluator local(aEnvironment, new BasicEvaluator);\n\n    const std::size_t upto = objs.size();\n\n    for (std::size_t i = 0; i < upto; ++i) {\n        aEnvironment.CurrentOutput() << i << \": \";\n        aEnvironment.CurrentPrinter().Print(\n            objs[i]->iOperator, aEnvironment.CurrentOutput(), aEnvironment);\n\n        int internal;\n        internal =\n            aEnvironment.CoreCommands().find(objs[i]->iOperator->String()) !=\n            aEnvironment.CoreCommands().end();\n        if (internal) {\n            aEnvironment.CurrentOutput() << \" (Internal function) \";\n        } else {\n            if (objs[i]->iRulePrecedence >= 0) {\n                aEnvironment.CurrentOutput()\n                    << \" (Rule # \" << objs[i]->iRulePrecedence;\n                if (objs[i]->iSide)\n                    aEnvironment.CurrentOutput() << \" in body) \";\n                else\n                    aEnvironment.CurrentOutput() << \" in pattern) \";\n            } else\n                aEnvironment.CurrentOutput() << \" (User function) \";\n        }\n        if (!!objs[i]->iExpression) {\n            aEnvironment.CurrentOutput() << \"\\n      \";\n            if (aEnvironment.iEvalDepth > (aEnvironment.iMaxEvalDepth - 10)) {\n                LispString expr;\n                PrintExpression(expr, objs[i]->iExpression, aEnvironment, 60);\n                aEnvironment.CurrentOutput() << expr;\n            } else {\n                LispPtr* subList = objs[i]->iExpression->SubList();\n                if (!!subList && !!(*subList)) {\n                    LispString expr;\n                    LispPtr out(objs[i]->iExpression);\n                    PrintExpression(expr, out, aEnvironment, 60);\n                    aEnvironment.CurrentOutput() << expr;\n                }\n            }\n        }\n        aEnvironment.CurrentOutput() << '\\n';\n    }\n}\n\nvoid TracedStackEvaluator::Eval(LispEnvironment& aEnvironment,\n                                LispPtr& aResult,\n                                LispPtr& aExpression)\n{\n    if (aEnvironment.iEvalDepth >= aEnvironment.iMaxEvalDepth) {\n        ShowStack(aEnvironment, aEnvironment.CurrentOutput());\n        throw LispErrMaxRecurseDepthReached();\n    }\n\n    LispPtr* subList = aExpression->SubList();\n    const LispString* str = nullptr;\n    if (subList) {\n        LispObject* head = (*subList);\n        if (head) {\n            str = head->String();\n            if (str) {\n                PushFrame();\n                UserStackInformation& st = StackInformation();\n                st.iOperator = LispAtom::New(aEnvironment, *str);\n                st.iExpression = aExpression;\n            }\n        }\n    }\n    BasicEvaluator::Eval(aEnvironment, aResult, aExpression);\n    if (str) {\n        PopFrame();\n    }\n}\n\nvoid TracedEvaluator::Eval(LispEnvironment& aEnvironment,\n                           LispPtr& aResult,\n                           LispPtr& aExpression)\n{\n    if (!aEnvironment.iDebugger)\n        throw LispErrGeneric(\"Internal error: debugging failing\");\n    if (aEnvironment.iDebugger->Stopped())\n        throw LispErrGeneric(\"\");\n\nREENTER:\n    errorOutput.clear();\n    errorOutput.str(\"\");\n\n    try {\n        aEnvironment.iDebugger->Enter(aEnvironment, aExpression);\n    } catch (const LispError& error) {\n        HandleError(error, aEnvironment, errorOutput);\n    }\n\n    if (aEnvironment.iDebugger->Stopped())\n        throw LispErrGeneric(\"\");\n\n    if (!errorOutput.str().empty()) {\n        aEnvironment.CurrentOutput() << errorOutput.str();\n        aEnvironment.iEvalDepth = 0;\n        goto REENTER;\n    }\n\n    errorOutput.clear();\n    errorOutput.str(\"\");\n\n    try {\n        BasicEvaluator::Eval(aEnvironment, aResult, aExpression);\n    } catch (const LispError& error) {\n        HandleError(error, aEnvironment, errorOutput);\n    }\n\n    if (!errorOutput.str().empty()) {\n        aEnvironment.CurrentOutput() << errorOutput.str();\n        aEnvironment.iEvalDepth = 0;\n        aEnvironment.iDebugger->Error(aEnvironment);\n        goto REENTER;\n    }\n\n    if (aEnvironment.iDebugger->Stopped())\n        throw LispErrGeneric(\"\");\n\n    aEnvironment.iDebugger->Leave(aEnvironment, aResult, aExpression);\n    if (aEnvironment.iDebugger->Stopped())\n        throw LispErrGeneric(\"\");\n}\n\nvoid DefaultDebugger::Start() {}\n\nvoid DefaultDebugger::Finish() {}\n\nvoid DefaultDebugger::Enter(LispEnvironment& aEnvironment, LispPtr& aExpression)\n{\n    LispLocalEvaluator local(aEnvironment, new BasicEvaluator);\n    iTopExpr = (aExpression->Copy());\n    LispPtr result;\n    defaultEval.Eval(aEnvironment, result, iEnter);\n}\n\nvoid DefaultDebugger::Leave(LispEnvironment& aEnvironment,\n                            LispPtr& aResult,\n                            LispPtr& aExpression)\n{\n    LispLocalEvaluator local(aEnvironment, new BasicEvaluator);\n    LispPtr result;\n    iTopExpr = (aExpression->Copy());\n    iTopResult = (aResult);\n    defaultEval.Eval(aEnvironment, result, iLeave);\n}\n\nbool DefaultDebugger::Stopped()\n{\n    return iStopped;\n}\n\nvoid DefaultDebugger::Error(LispEnvironment& aEnvironment)\n{\n    LispLocalEvaluator local(aEnvironment, new BasicEvaluator);\n    LispPtr result;\n    defaultEval.Eval(aEnvironment, result, iError);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lispevalhash.cpp",
    "content": "\n\n#include \"yacas/lispevalhash.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lispeval.h\"\n\nvoid YacasEvaluator::Evaluate(LispPtr& aResult,\n                              LispEnvironment& aEnvironment,\n                              LispPtr& aArguments) const\n{\n\n    if (!(iFlags & Variable)) {\n        CheckNrArgs(iNrArgs + 1, aArguments, aEnvironment);\n    }\n\n    int stacktop = aEnvironment.iStack.size();\n\n    // Push a place holder for the result: push full expression so it is\n    // available for error reporting\n    aEnvironment.iStack.push_back(aArguments);\n\n    LispIterator iter(aArguments);\n    ++iter;\n\n    int i;\n    int nr = iNrArgs;\n\n    if (iFlags & Variable)\n        nr--;\n\n    // Walk over all arguments, evaluating them as necessary\n    if (iFlags & Macro) {\n        for (i = 0; i < nr; i++) {\n            if (!iter.getObj())\n                throw LispErrWrongNumberOfArgs();\n\n            aEnvironment.iStack.push_back(LispPtr(iter.getObj()->Copy()));\n            ++iter;\n        }\n        if (iFlags & Variable) {\n            LispPtr head(aEnvironment.iList->Copy());\n            head->Nixed() = (iter.getObj());\n            aEnvironment.iStack.push_back(LispPtr(LispSubList::New(head)));\n        }\n    } else {\n        LispPtr arg;\n        for (i = 0; i < nr; i++) {\n            if (!iter.getObj())\n                throw LispErrWrongNumberOfArgs();\n\n            aEnvironment.iEvaluator->Eval(aEnvironment, arg, *iter);\n            aEnvironment.iStack.push_back(arg);\n            ++iter;\n        }\n        if (iFlags & Variable) {\n            LispPtr head(aEnvironment.iList->Copy());\n            head->Nixed() = (iter.getObj());\n            LispPtr list(LispSubList::New(head));\n\n            aEnvironment.iEvaluator->Eval(aEnvironment, arg, list);\n            aEnvironment.iStack.push_back(arg);\n        }\n    }\n\n    iCaller(aEnvironment, stacktop);\n    aResult = (aEnvironment.iStack[stacktop]);\n    aEnvironment.iStack.resize(stacktop);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lisphash.cpp",
    "content": "#include \"yacas/lisphash.h\"\n\nconst LispString* LispHashTable::LookUp(const std::string& s)\n{\n    std::unordered_map<std::string, LispStringSmartPtr>::const_iterator i =\n        _rep.find(s);\n    if (i != _rep.end())\n        return i->second;\n\n    LispString* ls = new LispString(s);\n\n    return _rep.insert(std::make_pair(s, ls)).first->second;\n}\n\nvoid LispHashTable::GarbageCollect()\n{\n    for (auto i = _rep.begin(); i != _rep.end(); ++i)\n        while (i != _rep.end() && i->second->use_count() == 1)\n            i = _rep.erase(i);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lispio.cpp",
    "content": "\n#include \"yacas/lispio.h\"\n\nvoid InputStatus::SetTo(const std::string& aFileName)\n{\n    iFileName = aFileName;\n    iLineNumber = 1;\n}\n\nvoid InputStatus::RestoreFrom(InputStatus& aPreviousStatus)\n{\n    iLineNumber = aPreviousStatus.iLineNumber;\n    iFileName = aPreviousStatus.iFileName;\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lispobject.cpp",
    "content": "\n#include \"yacas/lispobject.h\"\n\nint LispObject::Equal(LispObject& aOther)\n{\n    // next line handles the fact that either one is a string\n    if (String() != aOther.String())\n        return 0; // return false\n\n    // So, no strings.\n    LispPtr* iter1 = SubList();\n    LispPtr* iter2 = aOther.SubList();\n    assert(!!iter1 && !!iter2);\n\n    // check all elements in sublist\n    while (!!(*iter1) && !!(*iter2)) {\n        if (!(*iter1)->Equal(*(*iter2)))\n            return 0;\n        iter1 = &(*iter1)->Nixed();\n        iter2 = &(*iter2)->Nixed();\n    }\n    // One list longer than the other?\n    if (!(*iter1) && !(*iter2))\n        return 1;\n    return 0;\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/lispparser.cpp",
    "content": "\n#include \"yacas/lispparser.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lisperror.h\"\n\nLispParser::LispParser(LispTokenizer& aTokenizer,\n                       LispInput& aInput,\n                       LispEnvironment& aEnvironment) :\n    iTokenizer(aTokenizer),\n    iInput(aInput),\n    iEnvironment(aEnvironment),\n    iListed(false)\n{\n}\n\nvoid LispParser::Parse(LispPtr& aResult)\n{\n    aResult = nullptr;\n\n    // Get token.\n    const LispString* token =\n        iEnvironment.HashTable().LookUp(iTokenizer.NextToken(iInput));\n\n    if (token->empty()) {\n        aResult = iEnvironment.iEndOfFile->Copy();\n        return;\n    }\n    ParseAtom(aResult, token);\n}\n\nvoid LispParser::ParseAtom(LispPtr& aResult, const LispString* aToken)\n{\n    // if token is empty string, return null pointer (no expression)\n    if (aToken->empty())\n        return;\n    // else if token is \"(\" read in a whole array of objects until \")\",\n    //   and make a sublist\n    if (aToken == iEnvironment.iBracketOpen->String()) {\n        LispPtr subList;\n        ParseList(subList);\n        aResult = LispSubList::New(subList);\n        return;\n    }\n    // else make a simple atom, and return it.\n    aResult = LispAtom::New(iEnvironment, *aToken);\n}\n\nvoid LispParser::ParseList(LispPtr& aResult)\n{\n    LispPtr* iter = &aResult;\n    if (iListed) {\n        aResult = iEnvironment.iList->Copy();\n        iter = &(aResult->Nixed());\n    }\n    for (;;) {\n        // Get token.\n        const LispString* token =\n            iEnvironment.HashTable().LookUp(iTokenizer.NextToken(iInput));\n\n        // if token is empty string, error!\n        if (token->empty())\n            throw InvalidToken();\n\n        // if token is \")\" return result.\n        if (token == iEnvironment.iBracketClose->String())\n            return;\n\n        // else parse simple atom with Parse, and append it to the\n        // results list.\n        ParseAtom(*iter, token);\n        iter = &((*iter)->Nixed());\n    }\n}\n\nvoid LispPrinter::Print(const LispPtr& aExpression,\n                        std::ostream& aOutput,\n                        LispEnvironment& aEnvironment)\n{\n    PrintExpression(aExpression, aOutput, aEnvironment, 0);\n}\n\nvoid LispPrinter::Indent(std::ostream& aOutput, int aDepth)\n{\n    aOutput.put('\\n');\n    int i;\n    for (i = aDepth; i > 0; i--) {\n        aOutput.write(\"  \", 2);\n    }\n}\n\nvoid LispPrinter::PrintExpression(const LispPtr& aExpression,\n                                  std::ostream& aOutput,\n                                  LispEnvironment& aEnvironment,\n                                  int aDepth)\n{\n    const LispPtr* iter = &aExpression;\n    int item = 0;\n    while (!!(*iter)) {\n        // if String not null pointer: print string\n        const LispString* string = (*iter)->String();\n\n        if (string) {\n            aOutput << *string << ' ';\n        } // else print \"(\", print sublist, and print \")\"\n        else if ((*iter)->SubList()) {\n            if (item != 0) {\n                Indent(aOutput, aDepth + 1);\n            }\n            aOutput.put('(');\n            PrintExpression(\n                *((*iter)->SubList()), aOutput, aEnvironment, aDepth + 1);\n            aOutput.put(')');\n            item = 0;\n        } else {\n            aOutput << \"[GenericObject]\";\n        }\n        iter = &((*iter)->Nixed());\n        item++;\n    } // print next element\n}\n\n// does nothing in the LispPrinter but is used in derived classes\n\nvoid LispPrinter::RememberLastChar(char aChar) {}\n"
  },
  {
    "path": "cyacas/libyacas/src/lispuserfunc.cpp",
    "content": "\n#include \"yacas/lispuserfunc.h\"\n#include \"yacas/standard.h\"\n\nLispUserFunction* LispMultiUserFunction::UserFunc(int aArity)\n{\n    // Find function body with the right arity\n    for (LispArityUserFunction* p: iFunctions) {\n        assert(p);\n        if (p->IsArity(aArity))\n            return p;\n    }\n\n    // if function not found, just unaccept!\n    // User-defined function not found! Returning nullptr\n    return nullptr;\n}\n\nvoid LispMultiUserFunction::DeleteBase(int aArity)\n{\n    // Find function body with the right arity\n    const std::size_t nrc = iFunctions.size();\n    for (std::size_t i = 0; i < nrc; ++i) {\n        assert(iFunctions[i]);\n        if (iFunctions[i]->IsArity(aArity)) {\n            delete iFunctions[i];\n            iFunctions.erase(iFunctions.begin() + i);\n            return;\n        }\n    }\n}\n\nLispMultiUserFunction::~LispMultiUserFunction()\n{\n    for (LispArityUserFunction* p : iFunctions)\n        delete p;\n}\n\nvoid LispMultiUserFunction::HoldArgument(const LispString* aVariable)\n{\n    const std::size_t n = iFunctions.size();\n    for (std::size_t i = 0; i < n; ++i) {\n        assert(iFunctions[i]);\n        iFunctions[i]->HoldArgument(aVariable);\n    }\n}\n\nvoid LispMultiUserFunction::DefineRuleBase(LispArityUserFunction* aNewFunction)\n{\n    // Find function body with the right arity\n    const std::size_t nrc = iFunctions.size();\n    for (std::size_t i = 0; i < nrc; ++i) {\n        assert(iFunctions[i]);\n        assert(aNewFunction);\n        if (iFunctions[i]->IsArity(aNewFunction->Arity()) ||\n            aNewFunction->IsArity(iFunctions[i]->Arity()))\n            throw LispErrArityAlreadyDefined();\n    }\n    iFunctions.push_back(aNewFunction);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/mathcommands.cpp",
    "content": "\n#include \"yacas/arggetter.h\"\n#include \"yacas/arrayclass.h\"\n#include \"yacas/associationclass.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/infixparser.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lisperror.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispparser.h\"\n#include \"yacas/lispuserfunc.h\"\n#include \"yacas/mathuserfunc.h\"\n#include \"yacas/numbers.h\"\n#include \"yacas/patternclass.h\"\n#include \"yacas/platfileio.h\"\n#include \"yacas/platmath.h\"\n#include \"yacas/standard.h\"\n#include \"yacas/string_utils.h\"\n#include \"yacas/stringio.h\"\n#include \"yacas/substitute.h\"\n\n#include <cstring>\n#include <limits.h>\n#include <sstream>\n#include <stdlib.h>\n#include <string>\n\n#ifdef _WIN32\n#    include <windows.h>\n#else\n#    include <unistd.h>\n#endif\n\n#define InternalEval aEnvironment.iEvaluator->Eval\n#define RESULT aEnvironment.iStack[aStackTop]\n#define ARGUMENT(i) aEnvironment.iStack[aStackTop + i]\n\nvoid LispLexCompare2(LispEnvironment& aEnvironment,\n                     int aStackTop,\n                     bool (*lexfunc)(const char* f1,\n                                     const char* f2,\n                                     LispHashTable& aHashTable,\n                                     int aPrecision),\n                     bool (*numfunc)(BigNumber& n1, BigNumber& n2));\n\nvoid LispQuote(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RESULT = (ARGUMENT(1)->Copy());\n}\n\nvoid LispEval(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalEval(aEnvironment, RESULT, ARGUMENT(1));\n}\n\n/// Execute the Yacas commands \\c Set and \\c MacroSet.\n/// The argument \\a aMacroMode determines whether the first argument\n/// should be evaluated. The real work is done by\n/// LispEnvironment::SetVariable() .\n/// \\sa LispSetVar(), LispMacroSetVar()\nstatic void InternalSetVar(LispEnvironment& aEnvironment,\n                           int aStackTop,\n                           bool aMacroMode,\n                           bool aGlobalLazyVariable)\n{\n    const LispString* varstring = nullptr;\n    if (aMacroMode) {\n        LispPtr result;\n        InternalEval(aEnvironment, result, ARGUMENT(1));\n        varstring = result->String();\n    } else {\n        varstring = ARGUMENT(1)->String();\n    }\n    CheckArg(varstring, 1, aEnvironment, aStackTop);\n    CheckArg(!IsNumber(*varstring, true), 1, aEnvironment, aStackTop);\n\n    LispPtr result;\n    InternalEval(aEnvironment, result, ARGUMENT(2));\n    aEnvironment.SetVariable(varstring, result, aGlobalLazyVariable);\n    InternalTrue(aEnvironment, RESULT);\n}\n\n/// Corresponds to the Yacas function \\c Set.\n/// This function simply calls InternalSetVar() .\nvoid LispSetVar(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalSetVar(aEnvironment, aStackTop, false, false);\n}\n\n/// Corresponds to the Yacas function \\c MacroSet.\n/// This function simply calls InternalSetVar() .\nvoid LispMacroSetVar(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalSetVar(aEnvironment, aStackTop, true, false);\n}\n\nvoid LispSetGlobalLazyVariable(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalSetVar(aEnvironment, aStackTop, false, true);\n}\n\nvoid LispClearVar(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr* subList = ARGUMENT(1)->SubList();\n    if (subList) {\n        LispIterator iter(*subList);\n        for (int nr = 1; (++iter).getObj(); nr++) {\n            const LispString* str = iter.getObj()->String();\n            CheckArg(str, nr, aEnvironment, aStackTop);\n            aEnvironment.UnsetVariable(str);\n        }\n    }\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispVars(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr vars;\n    aEnvironment.GlobalVariables(vars);\n    RESULT = vars;\n}\n\n/* StrCompare returns f1-f2: if f1 < f2 it returns -1, if f1=f2 it\n returns 0, and it returns 1 if f1>f2\n */\n// the aPrecision argument is ignored here\nstatic bool LexLessThan(const char* f1,\n                        const char* f2,\n                        LispHashTable& aHashTable,\n                        int aPrecision)\n{\n    return (std::strcmp(f1, f2) < 0);\n}\n\n// the aPrecision argument is ignored here\nstatic bool LexGreaterThan(const char* f1,\n                           const char* f2,\n                           LispHashTable& aHashTable,\n                           int aPrecision)\n{\n    return (std::strcmp(f1, f2) > 0);\n}\n\nstatic bool BigLessThan(BigNumber& n1, BigNumber& n2)\n{\n    return n1.LessThan(n2) && !n1.Equals(n2);\n}\nstatic bool BigGreaterThan(BigNumber& n1, BigNumber& n2)\n{\n    return !(n1.LessThan(n2) || n1.Equals(n2));\n}\n\nvoid LispStrictTotalOrder(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr e1(ARGUMENT(1));\n    LispPtr e2(ARGUMENT(2));\n\n    InternalBoolean(\n        aEnvironment, RESULT, InternalStrictTotalOrder(aEnvironment, e1, e2));\n}\n\nvoid LispLessThan(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispLexCompare2(aEnvironment, aStackTop, LexLessThan, BigLessThan);\n}\n\nvoid LispGreaterThan(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispLexCompare2(aEnvironment, aStackTop, LexGreaterThan, BigGreaterThan);\n}\n\nvoid LispLexCompare2(LispEnvironment& aEnvironment,\n                     int aStackTop,\n                     bool (*lexfunc)(const char* f1,\n                                     const char* f2,\n                                     LispHashTable& aHashTable,\n                                     int aPrecision),\n                     bool (*numfunc)(BigNumber& n1, BigNumber& n2))\n{\n    LispPtr result1(ARGUMENT(1));\n    LispPtr result2(ARGUMENT(2));\n    bool cmp;\n    BigNumber* n1 = result1->Number(aEnvironment.Precision());\n    BigNumber* n2 = result2->Number(aEnvironment.Precision());\n    if (n1 && n2) {\n        cmp = numfunc(*n1, *n2);\n    } else {\n        const LispString* str1 = result1->String();\n        const LispString* str2 = result2->String();\n        CheckArg(str1, 1, aEnvironment, aStackTop);\n        CheckArg(str2, 2, aEnvironment, aStackTop);\n        // the precision argument is ignored in \"lex\" functions\n        cmp = lexfunc(str1->c_str(),\n                      str2->c_str(),\n                      aEnvironment.HashTable(),\n                      aEnvironment.Precision());\n    }\n\n    InternalBoolean(aEnvironment, RESULT, cmp);\n}\n\nvoid LispFullForm(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RESULT = (ARGUMENT(1));\n    LispPrinter printer;\n    printer.Print(RESULT, aEnvironment.CurrentOutput(), aEnvironment);\n    aEnvironment.CurrentOutput().put('\\n');\n}\n\nvoid LispHead(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalNth(RESULT, ARGUMENT(1), 1);\n}\n\nvoid LispNth(LispEnvironment& aEnvironment, int aStackTop)\n{\n    const LispString* str = ARGUMENT(2)->String();\n    CheckArg(str, 2, aEnvironment, aStackTop);\n    CheckArg(IsNumber(str->c_str(), false), 2, aEnvironment, aStackTop);\n    int index = InternalAsciiToInt(*str);\n    InternalNth(RESULT, ARGUMENT(1), index);\n}\n\nvoid LispTail(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr first;\n    InternalTail(first, ARGUMENT(1));\n    InternalTail(RESULT, first);\n    LispPtr head(aEnvironment.iList->Copy());\n    head->Nixed() = ((*RESULT->SubList()));\n    (*RESULT->SubList()) = (head);\n}\n\nvoid LispUnList(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    CheckArg(ARGUMENT(1)->SubList(), 1, aEnvironment, aStackTop);\n    LispObject* subList = (*ARGUMENT(1)->SubList());\n    CheckArg(subList, 1, aEnvironment, aStackTop);\n    CheckArg(subList->String() == aEnvironment.iList->String(),\n             1,\n             aEnvironment,\n             aStackTop);\n    InternalTail(RESULT, ARGUMENT(1));\n}\n\nvoid LispListify(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArg(ARGUMENT(1)->SubList(), 1, aEnvironment, aStackTop);\n    LispPtr head(aEnvironment.iList->Copy());\n    head->Nixed() = ((*ARGUMENT(1)->SubList()));\n    RESULT = (LispSubList::New(head));\n}\n\nvoid LispDestructiveReverse(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArgIsList(1, aEnvironment, aStackTop);\n\n    LispPtr reversed(aEnvironment.iList->Copy());\n    InternalReverseList(reversed->Nixed(), (*ARGUMENT(1)->SubList())->Nixed());\n    RESULT = (LispSubList::New(reversed));\n}\n\nvoid LispLength(LispEnvironment& aEnvironment, int aStackTop)\n{\n    std::size_t size = 0;\n\n    if (LispPtr* subList = ARGUMENT(1)->SubList()) {\n        size = InternalListLength((*subList)->Nixed());\n    } else if (InternalIsString(ARGUMENT(1)->String())) {\n        size = ARGUMENT(1)->String()->size() - 2;\n    } else if (ArrayClass* arr =\n                   dynamic_cast<ArrayClass*>(ARGUMENT(1)->Generic())) {\n        size = arr->Size();\n    } else if (AssociationClass* assoc =\n                   dynamic_cast<AssociationClass*>(ARGUMENT(1)->Generic())) {\n        size = assoc->Size();\n    } else\n        CheckArg(false, 1, aEnvironment, aStackTop);\n\n    RESULT = LispAtom::New(aEnvironment, std::to_string(size));\n}\n\nvoid LispList(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr all(aEnvironment.iList->Copy());\n    LispIterator tail(all);\n    ++tail;\n    LispIterator iter(*ARGUMENT(1)->SubList());\n    while ((++iter).getObj()) {\n        LispPtr evaluated;\n        InternalEval(aEnvironment, evaluated, *iter);\n        // Ideally this would work, but it does not yet: (*tail++) = (evaluated)\n        (*tail) = (evaluated);\n        ++tail;\n    }\n    RESULT = (LispSubList::New(all));\n}\n\nvoid LispConcatenate(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr all(aEnvironment.iList->Copy());\n    LispIterator tail(all);\n    ++tail;\n    LispIterator iter(*ARGUMENT(1)->SubList());\n    for (int arg = 1; (++iter).getObj(); arg++) {\n        CheckArgIsList(*iter, arg, aEnvironment, aStackTop);\n        InternalFlatCopy(\n            *tail,\n            (*(*iter)->SubList())->Nixed()); // TODO: woof -- prefer below\n        // InternalFlatCopy(*tail,iter.getObj()->Nixed());\n        while (tail.getObj())\n            ++tail;\n    }\n    RESULT = (LispSubList::New(all));\n}\n\nvoid LispConcatenateStrings(LispEnvironment& aEnvironment, int aStackTop)\n{\n    std::string s;\n    s.push_back('\\\"');\n\n    int arg = 1;\n    for (LispIterator iter(*ARGUMENT(1)->SubList()); (++iter).getObj();) {\n        CheckArgIsString(*iter, arg++, aEnvironment, aStackTop);\n        const std::string& p = *iter.getObj()->String();\n        s.append(p.substr(1, p.size() - 2));\n    }\n    s.push_back('\\\"');\n\n    RESULT = LispAtom::New(aEnvironment, s);\n}\n\nstatic void\nInternalDelete(LispEnvironment& aEnvironment, int aStackTop, int aDestructive)\n{\n    LispPtr evaluated(ARGUMENT(1));\n    CheckArgIsList(1, aEnvironment, aStackTop);\n\n    LispPtr copied;\n    if (aDestructive) {\n        copied = ((*evaluated->SubList()));\n    } else {\n        InternalFlatCopy(copied, *evaluated->SubList());\n    }\n\n    LispPtr index(ARGUMENT(2));\n    CheckArg(index, 2, aEnvironment, aStackTop);\n    CheckArg(index->String(), 2, aEnvironment, aStackTop);\n    int ind = InternalAsciiToInt(*index->String());\n    CheckArg(ind > 0, 2, aEnvironment, aStackTop);\n\n    LispIterator iter(copied);\n    while (--ind >= 0)\n        ++iter;\n    if (!iter.getObj()) {\n        ShowStack(aEnvironment);\n        throw LispErrListNotLongEnough();\n    }\n    LispIterator temp = iter++;\n    (*temp) = (*iter);\n    RESULT = (LispSubList::New(copied));\n}\n\nvoid LispDelete(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalDelete(aEnvironment, aStackTop, false);\n}\n\nvoid LispDestructiveDelete(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalDelete(aEnvironment, aStackTop, true);\n}\n\nvoid LispFlatCopy(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr copied;\n\n    if (ARGUMENT(1)->SubList() == nullptr)\n        CheckArgIsList(1, aEnvironment, aStackTop);\n\n    InternalFlatCopy(copied, *ARGUMENT(1)->SubList());\n    RESULT = (LispSubList::New(copied));\n}\n\nstatic void\nInternalInsert(LispEnvironment& aEnvironment, int aStackTop, int aDestructive)\n{\n    CheckArgIsList(1, aEnvironment, aStackTop);\n\n    LispPtr evaluated(ARGUMENT(1));\n\n    LispPtr copied;\n    if (aDestructive) {\n        copied = ((*evaluated->SubList()));\n    } else {\n        InternalFlatCopy(copied, *evaluated->SubList());\n    }\n\n    LispPtr index(ARGUMENT(2));\n    CheckArg(index, 2, aEnvironment, aStackTop);\n    CheckArg(index->String(), 2, aEnvironment, aStackTop);\n    int ind = InternalAsciiToInt(*index->String());\n    CheckArg(ind > 0, 2, aEnvironment, aStackTop);\n\n    LispIterator iter(copied);\n    while (--ind >= 0)\n        ++iter;\n    LispPtr toInsert(ARGUMENT(3));\n    toInsert->Nixed() = (iter.getObj());\n    (*iter) = (toInsert);\n    RESULT = (LispSubList::New(copied));\n}\n\nvoid LispInsert(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalInsert(aEnvironment, aStackTop, false);\n}\n\nvoid LispDestructiveInsert(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalInsert(aEnvironment, aStackTop, true);\n}\n\nstatic void\nInternalReplace(LispEnvironment& aEnvironment, int aStackTop, int aDestructive)\n{\n    LispPtr evaluated(ARGUMENT(1));\n    //    CHK_ISLIST_CORE(evaluated,1);\n    // Ok, so lets not check if it is a list, but it needs to be at least a\n    // 'function'\n    CheckArg(evaluated->SubList(), 1, aEnvironment, aStackTop);\n\n    LispPtr index(ARGUMENT(2));\n    CheckArg(index, 2, aEnvironment, aStackTop);\n    CheckArg(index->String(), 2, aEnvironment, aStackTop);\n    int ind = InternalAsciiToInt(*index->String());\n\n    LispPtr copied;\n    if (aDestructive) {\n        copied = ((*evaluated->SubList()));\n    } else {\n        InternalFlatCopy(copied, *evaluated->SubList());\n    }\n    CheckArg(ind > 0, 2, aEnvironment, aStackTop);\n\n    LispIterator iter(copied);\n    while (--ind >= 0)\n        ++iter;\n    LispPtr toInsert(ARGUMENT(3));\n    CheckArg(iter.getObj(), 2, aEnvironment, aStackTop);\n\n    LispIterator temp = iter++;\n    toInsert->Nixed() = (*iter);\n    (*temp) = (toInsert);\n    RESULT = (LispSubList::New(copied));\n}\n\nvoid LispReplace(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalReplace(aEnvironment, aStackTop, false);\n}\n\nvoid LispDestructiveReplace(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalReplace(aEnvironment, aStackTop, true);\n}\n\nvoid LispNot(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n    if (IsTrue(aEnvironment, evaluated) || IsFalse(aEnvironment, evaluated)) {\n        InternalNot(RESULT, aEnvironment, evaluated);\n    } else {\n        LispPtr ptr(ARGUMENT(0)->Copy());\n        ptr->Nixed() = (evaluated);\n        RESULT = (LispSubList::New(ptr));\n    }\n}\n\nvoid LispLazyAnd(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr nogos;\n    int nrnogos = 0;\n    LispPtr evaluated;\n\n    LispIterator iter(*ARGUMENT(1)->SubList());\n    while ((++iter).getObj()) {\n        InternalEval(aEnvironment, evaluated, *iter);\n        if (IsFalse(aEnvironment, evaluated)) {\n            InternalFalse(aEnvironment, RESULT);\n            return;\n        } else if (!IsTrue(aEnvironment, evaluated)) {\n            nrnogos++;\n            LispPtr ptr(evaluated->Copy());\n            ptr->Nixed() = (nogos);\n            nogos = (ptr);\n        }\n    }\n\n    if (!!nogos) {\n        if (nrnogos == 1) {\n            RESULT = (nogos);\n        } else {\n            LispPtr ptr;\n            InternalReverseList(ptr, nogos);\n            nogos = (ptr);\n\n            ptr = (ARGUMENT(0)->Copy());\n            ptr->Nixed() = (nogos);\n            nogos = (ptr);\n            RESULT = (LispSubList::New(nogos));\n            // aEnvironment.CurrentPrinter().Print(RESULT,\n            // *aEnvironment.CurrentOutput());\n        }\n    } else {\n        InternalTrue(aEnvironment, RESULT);\n    }\n}\n\nvoid LispLazyOr(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr nogos;\n    int nrnogos = 0;\n\n    LispPtr evaluated;\n\n    LispIterator iter(*ARGUMENT(1)->SubList());\n    while ((++iter).getObj()) {\n        InternalEval(aEnvironment, evaluated, *iter);\n        if (IsTrue(aEnvironment, evaluated)) {\n            InternalTrue(aEnvironment, RESULT);\n            return;\n        } else if (!IsFalse(aEnvironment, evaluated)) {\n            nrnogos++;\n            LispPtr ptr(evaluated->Copy());\n            ptr->Nixed() = (nogos);\n            nogos = (ptr);\n        }\n    }\n\n    if (!!nogos) {\n        if (nrnogos == 1) {\n            RESULT = (nogos);\n        } else {\n            LispPtr ptr;\n            InternalReverseList(ptr, nogos);\n            nogos = (ptr);\n\n            ptr = (ARGUMENT(0)->Copy());\n            ptr->Nixed() = (nogos);\n            nogos = (ptr);\n            RESULT = (LispSubList::New(nogos));\n        }\n        // aEnvironment.CurrentPrinter().Print(RESULT,\n        // *aEnvironment.CurrentOutput());\n    } else {\n        InternalFalse(aEnvironment, RESULT);\n    }\n}\n\nvoid LispEquals(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated1(ARGUMENT(1));\n    LispPtr evaluated2(ARGUMENT(2));\n\n    InternalBoolean(aEnvironment,\n                    RESULT,\n                    InternalEquals(aEnvironment, evaluated1, evaluated2));\n}\n\nvoid LispWrite(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr* subList = ARGUMENT(1)->SubList();\n    if (subList) {\n        LispIterator iter(*subList);\n        while ((++iter).getObj()) {\n            aEnvironment.CurrentPrinter().Print(\n                *iter, aEnvironment.CurrentOutput(), aEnvironment);\n        }\n    }\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispWriteString(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* str = ARGUMENT(1)->String();\n    CheckArg(str, 1, aEnvironment, aStackTop);\n    CheckArg((*str)[0] == '\\\"', 1, aEnvironment, aStackTop);\n    CheckArg((*str)[str->size() - 1] == '\\\"', 1, aEnvironment, aStackTop);\n\n    const std::size_t nr = str->size() - 1;\n    //((*str)[i] != '\\\"')\n    for (std::size_t i = 1; i < nr; ++i)\n        aEnvironment.CurrentOutput().put((*str)[i]);\n\n    // pass last printed character to the current printer\n    aEnvironment.CurrentPrinter().RememberLastChar(\n        (*str)[nr - 1]); // hacky hacky\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispProgBody(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Allow accessing previous locals.\n    LispLocalFrame frame(aEnvironment, false);\n\n    InternalTrue(aEnvironment, RESULT);\n\n    // Evaluate args one by one.\n\n    LispIterator iter(*ARGUMENT(1)->SubList());\n    while ((++iter).getObj()) {\n        InternalEval(aEnvironment, RESULT, *iter);\n    }\n}\n\nvoid LispNewLocal(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr* subList = ARGUMENT(1)->SubList();\n    if (subList) {\n        LispIterator iter(*subList);\n        for (int nr = 1; (++iter).getObj(); nr++) {\n            const LispString* variable = iter.getObj()->String();\n            CheckArg(variable, nr, aEnvironment, aStackTop);\n            // printf(\"Variable %s\\n\",variable->String());\n            aEnvironment.NewLocal(variable, nullptr);\n        }\n    }\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispWhile(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr& arg1 = ARGUMENT(1);\n    LispPtr& arg2 = ARGUMENT(2);\n\n    LispPtr predicate;\n    InternalEval(aEnvironment, predicate, arg1);\n\n    while (IsTrue(aEnvironment, predicate)) {\n        LispPtr evaluated;\n        InternalEval(aEnvironment, evaluated, arg2);\n        InternalEval(aEnvironment, predicate, arg1);\n    }\n    CheckArg(IsFalse(aEnvironment, predicate), 1, aEnvironment, aStackTop);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nstatic void\nMultiFix(LispEnvironment& aEnvironment, int aStackTop, LispOperators& aOps)\n{\n\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    LispPtr precedence;\n    InternalEval(aEnvironment, precedence, ARGUMENT(2));\n    CheckArg(precedence->String(), 2, aEnvironment, aStackTop);\n    int prec = InternalAsciiToInt(*precedence->String());\n    CheckArg(prec <= KMaxPrecedence, 2, aEnvironment, aStackTop);\n    aOps[SymbolName(aEnvironment, *orig)] = LispInFixOperator(prec);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispInFix(LispEnvironment& aEnvironment, int aStackTop)\n{\n    MultiFix(aEnvironment, aStackTop, aEnvironment.InFix());\n}\n\nstatic void SingleFix(int aPrecedence,\n                      LispEnvironment& aEnvironment,\n                      int aStackTop,\n                      LispOperators& aOps)\n{\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    aOps[SymbolName(aEnvironment, *orig)] = LispInFixOperator(aPrecedence);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispPreFix(LispEnvironment& aEnvironment, int aStackTop)\n{\n    /*\n        int nrArguments = InternalListLength(ARGUMENT(0));\n        if (nrArguments == 2)\n        {\n            SingleFix(0, aEnvironment, aStackTop, aEnvironment.PreFix());\n        }\n        else\n    */\n    {\n        MultiFix(aEnvironment, aStackTop, aEnvironment.PreFix());\n    }\n}\n\nvoid LispPostFix(LispEnvironment& aEnvironment, int aStackTop)\n{\n    const std::size_t nrArguments = InternalListLength(ARGUMENT(0));\n    if (nrArguments == 2)\n        SingleFix(0, aEnvironment, aStackTop, aEnvironment.PostFix());\n    else\n        MultiFix(aEnvironment, aStackTop, aEnvironment.PostFix());\n}\n\nvoid LispBodied(LispEnvironment& aEnvironment, int aStackTop)\n{\n    MultiFix(aEnvironment, aStackTop, aEnvironment.Bodied());\n}\n\nvoid LispAtomize(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n\n    // Get operator\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    RESULT = LispAtom::New(aEnvironment, orig->substr(1, orig->length() - 2));\n}\n\nvoid LispStringify(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n\n    // Get operator\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    RESULT = LispAtom::New(aEnvironment, stringify(*orig));\n}\n\nvoid LispLoad(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckSecure(aEnvironment, aStackTop);\n\n    LispPtr evaluated(ARGUMENT(1));\n\n    // Get file name\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    InternalLoad(aEnvironment, *orig);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispTmpFile(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckSecure(aEnvironment, aStackTop);\n\n#ifndef _WIN32\n    char fn[] = \"/tmp/yacas-XXXXXX\";\n\n    int fd = mkstemp(fn);\n\n    // FIXME: not very clear\n    if (fd < 0) {\n        ShowStack(aEnvironment);\n        throw LispErrFileNotFound();\n    }\n\n    close(fd);\n    RESULT = LispAtom::New(aEnvironment, stringify(fn));\n\n#else\n    char tmp_path[MAX_PATH];\n    char tmp_fn[MAX_PATH];\n\n    GetTempPath(MAX_PATH, tmp_path);\n    GetTempFileName(tmp_path, \"yacas\", 0, tmp_fn);\n\n    RESULT = LispAtom::New(aEnvironment, stringify(tmp_fn));\n#endif\n}\n\nvoid LispProtect(LispEnvironment& env, int top)\n{\n    LispPtr p(env.iStack[top + 1]);\n\n    CheckArg(p, 1, env, top);\n    const LispString* s = p->String();\n    CheckArg(s, 1, env, top);\n\n    env.Protect(s);\n\n    InternalTrue(env, env.iStack[top]);\n}\n\nvoid LispUnProtect(LispEnvironment& env, int top)\n{\n    LispPtr p(env.iStack[top + 1]);\n\n    CheckArg(p, 1, env, top);\n    const LispString* s = p->String();\n    CheckArg(s, 1, env, top);\n\n    env.UnProtect(s);\n\n    InternalTrue(env, env.iStack[top]);\n}\n\nvoid LispIsProtected(LispEnvironment& env, int top)\n{\n    LispPtr p(env.iStack[top + 1]);\n\n    CheckArg(p, 1, env, top);\n    const LispString* s = p->String();\n    CheckArg(s, 1, env, top);\n\n    env.iStack[top] = env.Protected(s) ? env.iTrue->Copy() : env.iFalse->Copy();\n}\n\n/// Implements the Yacas functions \\c RuleBase and \\c MacroRuleBase .\n/// The real work is done by LispEnvironment::DeclareRuleBase().\nstatic void\nInternalRuleBase(LispEnvironment& aEnvironment, int aStackTop, int aListed)\n{\n    // Get operator\n\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    LispPtr args(ARGUMENT(2));\n\n    // The arguments\n    CheckArgIsList(2, aEnvironment, aStackTop);\n\n    // Finally define the rule base\n    aEnvironment.DeclareRuleBase(\n        SymbolName(aEnvironment, *orig), (*args->SubList())->Nixed(), aListed);\n\n    // Return true\n    InternalTrue(aEnvironment, RESULT);\n}\n\n/// Corresponds to the Yacas function \\c RuleBase .\n/// This function simply calls InternalRuleBase().\nvoid LispRuleBase(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalRuleBase(aEnvironment, aStackTop, false);\n}\n\nvoid LispMacroRuleBase(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalRuleBase(aEnvironment, aStackTop, false);\n}\n\nvoid InternalDefMacroRuleBase(LispEnvironment& aEnvironment,\n                              int aStackTop,\n                              int aListed)\n{\n    // Get operator\n    // LispPtr body;\n\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    // The arguments\n    LispPtr args(ARGUMENT(2));\n    CheckArgIsList(2, aEnvironment, aStackTop);\n\n    // Finally define the rule base\n    aEnvironment.DeclareMacroRuleBase(\n        SymbolName(aEnvironment, *orig), (*args->SubList())->Nixed(), aListed);\n\n    // Return true\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispDefMacroRuleBaseListed(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalDefMacroRuleBase(aEnvironment, aStackTop, true);\n}\n\nvoid LispDefMacroRuleBase(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalDefMacroRuleBase(aEnvironment, aStackTop, false);\n}\n\nvoid LispRuleBaseListed(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalRuleBase(aEnvironment, aStackTop, true);\n}\n\nvoid LispMacroRuleBaseListed(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalRuleBase(aEnvironment, aStackTop, true);\n}\n\nvoid LispHoldArg(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    // The arguments\n    const LispString* tohold = ARGUMENT(2)->String();\n    CheckArg(tohold, 2, aEnvironment, aStackTop);\n    aEnvironment.HoldArgument(SymbolName(aEnvironment, *orig), tohold);\n    // Return true\n    InternalTrue(aEnvironment, RESULT);\n}\n\nstatic void InternalNewRule(LispEnvironment& aEnvironment, int aStackTop)\n{\n    int arity;\n    int precedence;\n\n    LispPtr ar;\n    LispPtr pr;\n    LispPtr predicate;\n    LispPtr body;\n\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    ar = (ARGUMENT(2));\n    pr = (ARGUMENT(3));\n    predicate = (ARGUMENT(4));\n    body = (ARGUMENT(5));\n\n    // The arity\n    CheckArg(ar, 2, aEnvironment, aStackTop);\n    CheckArg(ar->String(), 2, aEnvironment, aStackTop);\n    arity = InternalAsciiToInt(*ar->String());\n\n    // The precedence\n    CheckArg(pr, 3, aEnvironment, aStackTop);\n    CheckArg(pr->String(), 3, aEnvironment, aStackTop);\n    precedence = InternalAsciiToInt(*pr->String());\n\n    // Finally define the rule base\n    aEnvironment.DefineRule(\n        SymbolName(aEnvironment, *orig), arity, precedence, predicate, body);\n\n    // Return true\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispNewRule(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalNewRule(aEnvironment, aStackTop);\n}\n\nvoid LispMacroNewRule(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalNewRule(aEnvironment, aStackTop);\n}\n\nvoid LispUnFence(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    // The arity\n    CheckArg(ARGUMENT(2), 2, aEnvironment, aStackTop);\n    CheckArg(ARGUMENT(2)->String(), 2, aEnvironment, aStackTop);\n    int arity = InternalAsciiToInt(*ARGUMENT(2)->String());\n\n    aEnvironment.UnFenceRule(SymbolName(aEnvironment, *orig), arity);\n\n    // Return true\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispIsFunction(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr result(ARGUMENT(1));\n    InternalBoolean(aEnvironment, RESULT, result->SubList() != nullptr);\n}\n\nvoid LispIsAtom(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr result(ARGUMENT(1));\n    InternalBoolean(aEnvironment, RESULT, result->String() != nullptr);\n}\n\nvoid LispIsNumber(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr result(ARGUMENT(1));\n    InternalBoolean(aEnvironment,\n                    RESULT,\n                    result->Number(aEnvironment.Precision()) != nullptr);\n}\n\nvoid LispIsInteger(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr result(ARGUMENT(1));\n\n    BigNumber* num(result->Number(aEnvironment.Precision()));\n    InternalBoolean(aEnvironment, RESULT, num && num->IsInt());\n}\n\nvoid LispIsList(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr result(ARGUMENT(1));\n    InternalBoolean(aEnvironment, RESULT, InternalIsList(aEnvironment, result));\n}\n\nvoid LispIsString(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr result(ARGUMENT(1));\n    InternalBoolean(aEnvironment, RESULT, InternalIsString(result->String()));\n}\n\nvoid LispIsBound(LispEnvironment& aEnvironment, int aStackTop)\n{\n    const LispString* str = ARGUMENT(1)->String();\n    if (str) {\n        LispPtr val;\n        aEnvironment.GetVariable(str, val);\n        if (!!val) {\n            InternalTrue(aEnvironment, RESULT);\n            return;\n        }\n    }\n    InternalFalse(aEnvironment, RESULT);\n}\n\nvoid LispIf(LispEnvironment& aEnvironment, int aStackTop)\n{\n    int nrArguments = InternalListLength(ARGUMENT(0));\n    if (nrArguments != 3 && nrArguments != 4) {\n        ShowStack(aEnvironment);\n        throw LispErrWrongNumberOfArgs();\n    }\n\n    LispPtr predicate;\n    InternalEval(aEnvironment, predicate, ARGUMENT(1));\n\n    if (IsTrue(aEnvironment, predicate)) {\n        InternalEval(aEnvironment, RESULT, Argument(ARGUMENT(0), 2));\n    } else {\n        CheckArg(IsFalse(aEnvironment, predicate), 1, aEnvironment, aStackTop);\n        if (nrArguments == 4)\n            InternalEval(aEnvironment, RESULT, Argument(ARGUMENT(0), 3));\n        else\n            InternalFalse(aEnvironment, RESULT);\n    }\n}\n\nvoid LispRetract(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get operator\n    LispPtr evaluated(ARGUMENT(1));\n\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    const LispString* oper = SymbolName(aEnvironment, *orig);\n\n    LispPtr arity(ARGUMENT(2));\n    CheckArg(arity->String(), 2, aEnvironment, aStackTop);\n    int ar = InternalAsciiToInt(*arity->String());\n    aEnvironment.Retract(oper, ar);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid YacasBuiltinPrecisionSet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr index(ARGUMENT(1));\n    CheckArg(index, 1, aEnvironment, aStackTop);\n    CheckArg(index->String(), 1, aEnvironment, aStackTop);\n\n    int ind = InternalAsciiToInt(*index->String());\n    CheckArg(ind > 0, 1, aEnvironment, aStackTop);\n    aEnvironment.SetPrecision(ind);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispDefaultDirectory(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get file name\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    aEnvironment.iInputDirectories.push_back(InternalUnstringify(*orig));\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispFromFile(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckSecure(aEnvironment, aStackTop);\n\n    LispPtr evaluated;\n    InternalEval(aEnvironment, evaluated, ARGUMENT(1));\n\n    // Get file name\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    const std::string fname = orig->substr(1, orig->length() - 2);\n\n    InputStatus oldstatus = aEnvironment.iInputStatus;\n    aEnvironment.iInputStatus.SetTo(fname);\n\n    // Open file\n    LispLocalFile localFP(\n        aEnvironment, fname, true, aEnvironment.iInputDirectories);\n    if (!localFP.stream.is_open()) {\n        ShowStack(aEnvironment);\n        throw LispErrFileNotFound();\n    }\n    StdFileInput newInput(localFP, aEnvironment.iInputStatus);\n    LispLocalInput localInput(aEnvironment, &newInput);\n\n    // Evaluate the body\n    InternalEval(aEnvironment, RESULT, ARGUMENT(2));\n\n    aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n    // Return the result\n}\n\nvoid LispFromString(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated;\n    InternalEval(aEnvironment, evaluated, ARGUMENT(1));\n\n    // Get file name\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    const std::string oper = InternalUnstringify(*orig);\n\n    InputStatus oldstatus = aEnvironment.iInputStatus;\n    aEnvironment.iInputStatus.SetTo(\"String\");\n    StringInput newInput(oper, aEnvironment.iInputStatus);\n    LispLocalInput localInput(aEnvironment, &newInput);\n\n    // Evaluate the body\n    InternalEval(aEnvironment, RESULT, ARGUMENT(2));\n    aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n\n    // Return the result\n}\n\nvoid LispRead(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispTokenizer& tok = *aEnvironment.iCurrentTokenizer;\n    InfixParser parser(tok,\n                       *aEnvironment.CurrentInput(),\n                       aEnvironment,\n                       aEnvironment.PreFix(),\n                       aEnvironment.InFix(),\n                       aEnvironment.PostFix(),\n                       aEnvironment.Bodied());\n    // Read expression\n    parser.Parse(RESULT);\n}\n\nvoid LispReadToken(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispTokenizer& tok = *aEnvironment.iCurrentTokenizer;\n    const LispString* result = aEnvironment.HashTable().LookUp(\n        tok.NextToken(*aEnvironment.CurrentInput()));\n\n    if (result->empty()) {\n        RESULT = aEnvironment.iEndOfFile->Copy();\n        return;\n    }\n    RESULT = LispAtom::New(aEnvironment, *result);\n}\n\nvoid LispToFile(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckSecure(aEnvironment, aStackTop);\n\n    LispPtr evaluated;\n    InternalEval(aEnvironment, evaluated, ARGUMENT(1));\n\n    // Get file name\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    const std::string oper = InternalUnstringify(*orig);\n\n    // Open file for writing\n    LispLocalFile localFP(\n        aEnvironment, oper, false, aEnvironment.iInputDirectories);\n    if (!localFP.stream.is_open()) {\n        ShowStack(aEnvironment);\n        throw LispErrFileNotFound();\n    }\n    LispLocalOutput localOutput(aEnvironment, localFP.stream);\n\n    // Evaluate the body\n    InternalEval(aEnvironment, RESULT, ARGUMENT(2));\n\n    // Return the result\n}\n\nvoid LispCheck(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr pred;\n    InternalEval(aEnvironment, pred, ARGUMENT(1));\n    if (!IsTrue(aEnvironment, pred)) {\n        LispPtr evaluated;\n        InternalEval(aEnvironment, evaluated, ARGUMENT(2));\n        CheckArgIsString(evaluated, 2, aEnvironment, aStackTop);\n        ShowStack(aEnvironment);\n        throw LispErrUser(*evaluated->String());\n    }\n    RESULT = pred;\n}\n\nvoid LispTrapError(LispEnvironment& aEnvironment, int aStackTop)\n{\n    try {\n        InternalEval(aEnvironment, RESULT, ARGUMENT(1));\n    } catch (const LispError& error) {\n        HandleError(error, aEnvironment, aEnvironment.iErrorOutput);\n    }\n\n    if (!aEnvironment.iErrorOutput.str().empty()) {\n        InternalEval(aEnvironment, RESULT, ARGUMENT(2));\n        aEnvironment.iErrorOutput.clear();\n        aEnvironment.iErrorOutput.str(\"\");\n    }\n}\n\nvoid LispGetCoreError(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RESULT =\n        LispAtom::New(aEnvironment, stringify(aEnvironment.iErrorOutput.str()));\n}\n\nvoid LispSystemCall(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckSecure(aEnvironment, aStackTop);\n\n    LispPtr result(ARGUMENT(1));\n    CheckArgIsString(1, aEnvironment, aStackTop);\n\n    const std::string command = InternalUnstringify(*result->String());\n\n    // we would like to pass the exit code back to Yacas. Right now, let's pass\n    // True/False according to whether the exit code is 0 or not.\n    InternalBoolean(aEnvironment, RESULT, system(command.c_str()) == 0);\n}\n\nvoid LispSystemName(LispEnvironment& aEnvironment, int aStackTop)\n{\n    const char* s = \"Unknown\";\n\n#if defined(_WIN32)\n    s = \"Windows\";\n#elif defined(__APPLE__)\n    s = \"MacOSX\";\n#elif defined(__linux__)\n    s = \"Linux\";\n#endif\n\n    RESULT = LispAtom::New(aEnvironment, stringify(s));\n}\n\nvoid LispMaxEvalDepth(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr index(ARGUMENT(1));\n    CheckArg(index, 1, aEnvironment, aStackTop);\n    CheckArg(index->String(), 1, aEnvironment, aStackTop);\n\n    int ind = InternalAsciiToInt(*index->String());\n    aEnvironment.iMaxEvalDepth = ind;\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispDefLoad(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckSecure(aEnvironment, aStackTop);\n\n    LispPtr evaluated(ARGUMENT(1));\n\n    // Get file name\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    LoadDefFile(aEnvironment, *orig);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispUse(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n\n    // Get file name\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    InternalUse(aEnvironment, *orig);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispRightAssociative(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    LispOperators::iterator opi =\n        aEnvironment.InFix().find(SymbolName(aEnvironment, *orig));\n    if (opi == aEnvironment.InFix().end())\n        throw LispErrNotAnInFixOperator();\n    opi->second.SetRightAssociative();\n\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispLeftPrecedence(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    LispPtr index;\n    InternalEval(aEnvironment, index, ARGUMENT(2));\n    CheckArg(index, 2, aEnvironment, aStackTop);\n    CheckArg(index->String(), 2, aEnvironment, aStackTop);\n    int ind = InternalAsciiToInt(*index->String());\n\n    LispOperators::iterator opi =\n        aEnvironment.InFix().find(SymbolName(aEnvironment, *orig));\n    if (opi == aEnvironment.InFix().end())\n        throw LispErrNotAnInFixOperator();\n    opi->second.SetLeftPrecedence(ind);\n\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispRightPrecedence(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    LispPtr index;\n    InternalEval(aEnvironment, index, ARGUMENT(2));\n    CheckArg(index, 2, aEnvironment, aStackTop);\n    CheckArg(index->String(), 2, aEnvironment, aStackTop);\n    int ind = InternalAsciiToInt(*index->String());\n\n    LispOperators::iterator opi =\n        aEnvironment.InFix().find(SymbolName(aEnvironment, *orig));\n    if (opi == aEnvironment.InFix().end())\n        throw LispErrNotAnInFixOperator();\n    opi->second.SetRightPrecedence(ind);\n\n    InternalTrue(aEnvironment, RESULT);\n}\n\nstatic LispInFixOperator* OperatorInfo(LispEnvironment& aEnvironment,\n                                       int aStackTop,\n                                       LispOperators& aOperators)\n{\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n\n    LispPtr evaluated(ARGUMENT(1));\n\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n\n    const LispOperators::iterator opi =\n        aOperators.find(SymbolName(aEnvironment, *orig));\n    if (opi != aOperators.end())\n        return &opi->second;\n    return nullptr;\n}\n\nvoid LispIsInFix(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispInFixOperator* op =\n        OperatorInfo(aEnvironment, aStackTop, aEnvironment.InFix());\n    InternalBoolean(aEnvironment, RESULT, op != nullptr);\n}\n\nvoid LispIsBodied(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispInFixOperator* op =\n        OperatorInfo(aEnvironment, aStackTop, aEnvironment.Bodied());\n    InternalBoolean(aEnvironment, RESULT, op != nullptr);\n}\n\nvoid LispGetPrecedence(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispInFixOperator* op =\n        OperatorInfo(aEnvironment, aStackTop, aEnvironment.InFix());\n    if (!op) { // also need to check for a postfix or prefix operator\n        op = OperatorInfo(aEnvironment, aStackTop, aEnvironment.PreFix());\n        if (!op) {\n            op = OperatorInfo(aEnvironment, aStackTop, aEnvironment.PostFix());\n            if (!op) { // or maybe it's a bodied function\n                op = OperatorInfo(\n                    aEnvironment, aStackTop, aEnvironment.Bodied());\n                if (!op) {\n                    ShowStack(aEnvironment);\n                    throw LispErrIsNotInFix();\n                }\n            }\n        }\n    }\n    RESULT = LispAtom::New(aEnvironment, std::to_string(op->iPrecedence));\n}\n\nvoid LispGetLeftPrecedence(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispInFixOperator* op =\n        OperatorInfo(aEnvironment, aStackTop, aEnvironment.InFix());\n    if (!op) { // infix and postfix operators have left precedence\n        op = OperatorInfo(aEnvironment, aStackTop, aEnvironment.PostFix());\n        if (!op) {\n            ShowStack(aEnvironment);\n            throw LispErrIsNotInFix();\n        }\n    }\n\n    RESULT = LispAtom::New(aEnvironment, std::to_string(op->iLeftPrecedence));\n}\n\nvoid LispGetRightPrecedence(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispInFixOperator* op =\n        OperatorInfo(aEnvironment, aStackTop, aEnvironment.InFix());\n    if (!op) { // bodied, infix and prefix operators have right precedence\n        op = OperatorInfo(aEnvironment, aStackTop, aEnvironment.PreFix());\n        if (!op) { // or maybe it's a bodied function\n            op = OperatorInfo(aEnvironment, aStackTop, aEnvironment.Bodied());\n            if (!op) {\n                ShowStack(aEnvironment);\n                throw LispErrIsNotInFix();\n            }\n        }\n    }\n\n    RESULT = LispAtom::New(aEnvironment, std::to_string(op->iRightPrecedence));\n}\n\nvoid LispIsPreFix(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispInFixOperator* op =\n        OperatorInfo(aEnvironment, aStackTop, aEnvironment.PreFix());\n    InternalBoolean(aEnvironment, RESULT, op != nullptr);\n}\n\nvoid LispIsPostFix(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispInFixOperator* op =\n        OperatorInfo(aEnvironment, aStackTop, aEnvironment.PostFix());\n\n    InternalBoolean(aEnvironment, RESULT, op != nullptr);\n}\n\nvoid YacasBuiltinPrecisionGet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RESULT =\n        LispAtom::New(aEnvironment, std::to_string(aEnvironment.Precision()));\n}\n\nvoid LispToString(LispEnvironment& aEnvironment, int aStackTop)\n{\n    std::ostringstream os;\n\n    LispLocalOutput localOutput(aEnvironment, os);\n\n    // Evaluate the body\n    InternalEval(aEnvironment, RESULT, ARGUMENT(1));\n\n    // Return the result\n    RESULT = LispAtom::New(aEnvironment, stringify(os.str()));\n}\n\nvoid LispToStdout(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispLocalOutput localOutput(aEnvironment, *aEnvironment.iInitialOutput);\n    // Evaluate the body\n    InternalEval(aEnvironment, RESULT, ARGUMENT(1));\n}\n\nvoid LispSecure(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispSecureFrame security(aEnvironment);\n    InternalEval(aEnvironment, RESULT, ARGUMENT(1));\n}\n\nvoid LispFindFile(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckSecure(aEnvironment, aStackTop);\n\n    LispPtr evaluated(ARGUMENT(1));\n\n    // Get file name\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    const std::string oper = InternalUnstringify(*orig);\n\n    const std::string path =\n        InternalFindFile(oper, aEnvironment.iInputDirectories);\n\n    RESULT = LispAtom::New(aEnvironment, stringify(path));\n}\n\nvoid LispIsGeneric(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n\n    InternalBoolean(aEnvironment, RESULT, evaluated->Generic() != nullptr);\n}\n\nvoid LispGenericTypeName(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n\n    const char* name = evaluated->Generic()->TypeName();\n    RESULT = (LispAtom::New(aEnvironment, name));\n}\n\nvoid GenArrayCreate(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr sizearg(ARGUMENT(1));\n\n    CheckArg(sizearg, 1, aEnvironment, aStackTop);\n    CheckArg(sizearg->String(), 1, aEnvironment, aStackTop);\n\n    int size = InternalAsciiToInt(*sizearg->String());\n\n    LispPtr initarg(ARGUMENT(2));\n\n    ArrayClass* array = new ArrayClass(size, initarg);\n    RESULT = (LispGenericClass::New(array));\n}\n\nvoid GenArraySize(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n\n    GenericClass* gen = evaluated->Generic();\n    ArrayClass* arr = dynamic_cast<ArrayClass*>(gen);\n    CheckArg(arr, 1, aEnvironment, aStackTop);\n    RESULT = LispAtom::New(aEnvironment, std::to_string(arr->Size()));\n}\n\nvoid GenArrayGet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n\n    GenericClass* gen = evaluated->Generic();\n    ArrayClass* arr = dynamic_cast<ArrayClass*>(gen);\n    CheckArg(arr, 1, aEnvironment, aStackTop);\n\n    LispPtr sizearg(ARGUMENT(2));\n    CheckArg(sizearg, 2, aEnvironment, aStackTop);\n    CheckArg(sizearg->String(), 2, aEnvironment, aStackTop);\n\n    int size = InternalAsciiToInt(*sizearg->String());\n\n    CheckArg(size > 0 && static_cast<std::size_t>(size) <= arr->Size(),\n             2,\n             aEnvironment,\n             aStackTop);\n    LispObject* object = arr->GetElement(size);\n    RESULT = (object->Copy());\n}\n\nvoid GenArraySet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n\n    GenericClass* gen = evaluated->Generic();\n    ArrayClass* arr = dynamic_cast<ArrayClass*>(gen);\n    CheckArg(arr, 1, aEnvironment, aStackTop);\n\n    LispPtr sizearg(ARGUMENT(2));\n    CheckArg(sizearg, 2, aEnvironment, aStackTop);\n    CheckArg(sizearg->String(), 2, aEnvironment, aStackTop);\n\n    int size = InternalAsciiToInt(*sizearg->String());\n\n    CheckArg(size > 0 && static_cast<std::size_t>(size) <= arr->Size(),\n             2,\n             aEnvironment,\n             aStackTop);\n    LispPtr obj(ARGUMENT(3));\n    arr->SetElement(size, obj);\n\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid GenAssociationCreate(LispEnvironment& aEnvironment, int aStackTop)\n{\n    AssociationClass* a = new AssociationClass(aEnvironment);\n    RESULT = LispGenericClass::New(a);\n}\n\nvoid GenAssociationSize(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n\n    GenericClass* gen = evaluated->Generic();\n    AssociationClass* a = dynamic_cast<AssociationClass*>(gen);\n    CheckArg(a, 1, aEnvironment, aStackTop);\n    RESULT = LispAtom::New(aEnvironment, std::to_string(a->Size()));\n}\n\nvoid GenAssociationContains(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr p(ARGUMENT(1));\n    GenericClass* gen = p->Generic();\n    AssociationClass* a = dynamic_cast<AssociationClass*>(gen);\n    CheckArg(a, 1, aEnvironment, aStackTop);\n\n    LispPtr k(ARGUMENT(2));\n\n    if (a->GetElement(k))\n        InternalTrue(aEnvironment, RESULT);\n    else\n        InternalFalse(aEnvironment, RESULT);\n}\n\nvoid GenAssociationGet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr p(ARGUMENT(1));\n    GenericClass* gen = p->Generic();\n    AssociationClass* a = dynamic_cast<AssociationClass*>(gen);\n    CheckArg(a, 1, aEnvironment, aStackTop);\n\n    LispPtr k(ARGUMENT(2));\n    LispObject* v = a->GetElement(k);\n\n    if (v)\n        RESULT = v->Copy();\n    else\n        RESULT = LispAtom::New(aEnvironment, \"Undefined\");\n}\n\nvoid GenAssociationSet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr p(ARGUMENT(1));\n    GenericClass* gen = p->Generic();\n    AssociationClass* a = dynamic_cast<AssociationClass*>(gen);\n    CheckArg(a, 1, aEnvironment, aStackTop);\n\n    LispPtr k(ARGUMENT(2));\n    LispPtr v(ARGUMENT(3));\n\n    a->SetElement(k, v);\n\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid GenAssociationDrop(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr p(ARGUMENT(1));\n    GenericClass* gen = p->Generic();\n    AssociationClass* a = dynamic_cast<AssociationClass*>(gen);\n    CheckArg(a, 1, aEnvironment, aStackTop);\n\n    LispPtr k(ARGUMENT(2));\n    if (a->DropElement(k))\n        InternalTrue(aEnvironment, RESULT);\n    else\n        InternalFalse(aEnvironment, RESULT);\n}\n\nvoid GenAssociationKeys(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr p(ARGUMENT(1));\n    GenericClass* gen = p->Generic();\n    AssociationClass* a = dynamic_cast<AssociationClass*>(gen);\n    CheckArg(a, 1, aEnvironment, aStackTop);\n\n    RESULT = a->Keys();\n}\n\nvoid GenAssociationToList(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr p(ARGUMENT(1));\n    GenericClass* gen = p->Generic();\n    AssociationClass* a = dynamic_cast<AssociationClass*>(gen);\n    CheckArg(a, 1, aEnvironment, aStackTop);\n\n    RESULT = a->ToList();\n}\n\nvoid GenAssociationHead(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr p(ARGUMENT(1));\n    GenericClass* gen = p->Generic();\n    AssociationClass* a = dynamic_cast<AssociationClass*>(gen);\n    CheckArg(a, 1, aEnvironment, aStackTop);\n    CheckArg(a->Size(), 1, aEnvironment, aStackTop);\n\n    RESULT = a->Head();\n}\n\nvoid LispCustomEval(LispEnvironment& aEnvironment, int aStackTop)\n{\n    if (aEnvironment.iDebugger)\n        delete aEnvironment.iDebugger;\n    aEnvironment.iDebugger =\n        new DefaultDebugger(ARGUMENT(1), ARGUMENT(2), ARGUMENT(3));\n    LispLocalEvaluator local(aEnvironment, new TracedEvaluator);\n    aEnvironment.iDebugger->Start();\n    InternalEval(aEnvironment, RESULT, ARGUMENT(4));\n    aEnvironment.iDebugger->Finish();\n    delete aEnvironment.iDebugger;\n    aEnvironment.iDebugger = nullptr;\n}\n\nvoid LispCustomEvalExpression(LispEnvironment& aEnvironment, int aStackTop)\n{\n    if (!aEnvironment.iDebugger)\n        throw LispErrGeneric(\n            \"Trying to get CustomEval results while not in custom evaluation\");\n\n    RESULT = (aEnvironment.iDebugger->iTopExpr);\n}\n\nvoid LispCustomEvalResult(LispEnvironment& aEnvironment, int aStackTop)\n{\n    if (!aEnvironment.iDebugger)\n        throw LispErrGeneric(\n            \"Trying to get CustomEval results while not in custom evaluation\");\n\n    RESULT = (aEnvironment.iDebugger->iTopResult);\n}\n\nvoid LispCustomEvalLocals(LispEnvironment& aEnvironment, int aStackTop)\n{\n    aEnvironment.CurrentLocals(RESULT);\n}\n\nvoid LispCustomEvalStop(LispEnvironment& aEnvironment, int aStackTop)\n{\n    if (!aEnvironment.iDebugger)\n        throw LispErrGeneric(\n            \"Trying to get CustomEval results while not in custom evaluation\");\n\n    aEnvironment.iDebugger->iStopped = true;\n\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispTraceStack(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispLocalEvaluator local(aEnvironment, new TracedStackEvaluator);\n    InternalEval(aEnvironment, RESULT, ARGUMENT(1));\n}\n\nvoid LispReadLisp(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispTokenizer& tok = *aEnvironment.iCurrentTokenizer;\n    LispParser parser(tok, *aEnvironment.CurrentInput(), aEnvironment);\n    // Read expression\n    parser.Parse(RESULT);\n}\n\nvoid LispReadLispListed(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispTokenizer& tok = *aEnvironment.iCurrentTokenizer;\n    LispParser parser(tok, *aEnvironment.CurrentInput(), aEnvironment);\n    parser.iListed = true;\n    // Read expression\n    parser.Parse(RESULT);\n}\n\nvoid LispTraceRule(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr* ptr = ARGUMENT(0)->Nixed()->SubList();\n    LispUserFunction* userfunc = nullptr;\n    if (ptr)\n        userfunc = GetUserFunction(aEnvironment, ptr);\n    LispLocalTrace trace(userfunc);\n    InternalEval(aEnvironment, RESULT, ARGUMENT(2));\n}\n\nvoid LispType(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n    LispPtr* subList = evaluated->SubList();\n    LispObject* head = nullptr;\n    if (!subList) {\n        goto EMPTY;\n    }\n    head = (*subList);\n    if (!head->String())\n        goto EMPTY;\n    RESULT = LispAtom::New(\n        aEnvironment,\n        *aEnvironment.HashTable().LookUp(stringify(*head->String())));\n    return;\n\nEMPTY:\n    RESULT = LispAtom::New(aEnvironment, \"\\\"\\\"\");\n    return;\n}\n\nvoid YacasStringMidGet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArgIsString(3, aEnvironment, aStackTop);\n    LispPtr evaluated(ARGUMENT(3));\n\n    const LispString* orig = evaluated->String();\n\n    LispPtr index(ARGUMENT(1));\n    CheckArg(index, 1, aEnvironment, aStackTop);\n    CheckArg(index->String(), 1, aEnvironment, aStackTop);\n    const int sfrom = InternalAsciiToInt(*index->String());\n    CheckArg(sfrom > 0, 1, aEnvironment, aStackTop);\n    const std::size_t from = sfrom;\n\n    index = (ARGUMENT(2));\n    CheckArg(index, 2, aEnvironment, aStackTop);\n    CheckArg(index->String(), 2, aEnvironment, aStackTop);\n    const int scount = InternalAsciiToInt(*index->String());\n    const std::size_t count = scount;\n\n    std::string str = \"\\\"\";\n    // FIXME: it's actually the set of args which is wrong, not the specific one\n    CheckArg(from + count < orig->size(), 1, aEnvironment, aStackTop);\n    for (std::size_t i = from; i < from + count; ++i)\n        str.push_back((*orig)[i]);\n    str.push_back('\\\"');\n    RESULT = LispAtom::New(aEnvironment, str);\n}\n\nvoid YacasStringMidSet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArgIsString(3, aEnvironment, aStackTop);\n    LispPtr evaluated(ARGUMENT(3));\n    const LispString* orig = evaluated->String();\n    LispPtr index(ARGUMENT(1));\n    CheckArg(index, 1, aEnvironment, aStackTop);\n    CheckArg(index->String(), 1, aEnvironment, aStackTop);\n    const int sfrom = InternalAsciiToInt(*index->String());\n    CheckArg(sfrom > 0, 1, aEnvironment, aStackTop);\n    const std::size_t from = sfrom;\n\n    LispPtr ev2(ARGUMENT(2));\n    CheckArgIsString(2, aEnvironment, aStackTop);\n    const LispString* replace = ev2->String();\n\n    std::string str(*orig);\n    const std::size_t count = replace->size();\n    // FIXME: it's actually the set of args which is wrong, not the specific one\n    CheckArg(from + count < orig->size() + 2, 1, aEnvironment, aStackTop);\n\n    for (std::size_t i = 0; i < count - 2; ++i)\n        str[i + from] = (*replace)[i + 1];\n    RESULT = LispAtom::New(aEnvironment, str);\n}\n\nvoid LispFindFunction(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckSecure(aEnvironment, aStackTop);\n\n    LispPtr evaluated(ARGUMENT(1));\n\n    // Get file name\n    CheckArg(evaluated, 1, aEnvironment, aStackTop);\n    const LispString* orig = evaluated->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    const std::string oper = InternalUnstringify(*orig);\n\n    LispMultiUserFunction* multiUserFunc =\n        aEnvironment.MultiUserFunction(aEnvironment.HashTable().LookUp(oper));\n    if (multiUserFunc) {\n        LispDefFile* def = multiUserFunc->iFileToOpen;\n        if (def) {\n            RESULT = LispAtom::New(aEnvironment, def->FileName());\n            return;\n        }\n    }\n\n    RESULT = LispAtom::New(aEnvironment, \"\\\"\\\"\");\n}\n\n/// Corresponds to the Yacas function \\c PatternCreate .\n/// This function constructs a new PatternClass, and puts it in a new\n/// LispGenericObject. The result is set to this LispGenericObject.\nvoid GenPatternCreate(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr pattern(ARGUMENT(1));\n    LispPtr postpredicate(ARGUMENT(2));\n\n    LispIterator iter(pattern);\n    LispObject* pObj = iter.getObj();\n    CheckArg(pObj, 1, aEnvironment, aStackTop);\n    LispPtr* pPtr = pObj->SubList();\n    CheckArg(pPtr, 1, aEnvironment, aStackTop);\n    iter = *pPtr;\n    CheckArg(iter.getObj(), 1, aEnvironment, aStackTop);\n    ++iter;\n\n    YacasPatternPredicateBase* matcher =\n        new YacasPatternPredicateBase(aEnvironment, *iter, postpredicate);\n    PatternClass* p = new PatternClass(matcher);\n    RESULT = (LispGenericClass::New(p));\n}\n\nvoid GenPatternMatches(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr pattern(ARGUMENT(1));\n    GenericClass* gen = pattern->Generic();\n    PatternClass* pat = dynamic_cast<PatternClass*>(gen);\n    CheckArg(pat, 1, aEnvironment, aStackTop);\n\n    LispPtr list(ARGUMENT(2));\n\n    LispIterator iter(list);\n    LispObject* pObj = iter.getObj();\n    CheckArg(pObj, 2, aEnvironment, aStackTop);\n    LispPtr* pPtr = pObj->SubList();\n    CheckArg(pPtr, 2, aEnvironment, aStackTop);\n    iter = *pPtr;\n    CheckArg(iter.getObj(), 2, aEnvironment, aStackTop);\n    ++iter;\n\n    CheckArg(iter.getObj(), 2, aEnvironment, aStackTop);\n    bool matches = pat->Matches(aEnvironment, *iter);\n    InternalBoolean(aEnvironment, RESULT, matches);\n}\n\nvoid LispRuleBaseDefined(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr name(ARGUMENT(1));\n    const LispString* orig = name->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    const std::string oper = InternalUnstringify(*orig);\n\n    LispPtr sizearg(ARGUMENT(2));\n    CheckArg(sizearg, 2, aEnvironment, aStackTop);\n    CheckArg(sizearg->String(), 2, aEnvironment, aStackTop);\n\n    int arity = InternalAsciiToInt(*sizearg->String());\n\n    LispUserFunction* userFunc =\n        aEnvironment.UserFunction(aEnvironment.HashTable().LookUp(oper), arity);\n    InternalBoolean(aEnvironment, RESULT, !!userFunc);\n}\n\nvoid LispDefLoadFunction(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr name(ARGUMENT(1));\n    const LispString* orig = name->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    const std::string oper = InternalUnstringify(*orig);\n\n    LispMultiUserFunction* multiUserFunc =\n        aEnvironment.MultiUserFunction(aEnvironment.HashTable().LookUp(oper));\n    if (multiUserFunc) {\n        if (multiUserFunc->iFileToOpen != nullptr) {\n            LispDefFile* def = multiUserFunc->iFileToOpen;\n            if (!def->IsLoaded()) {\n                multiUserFunc->iFileToOpen = nullptr;\n                // InternalUse(aEnvironment, def->FileName());\n            }\n        }\n    }\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispRuleBaseArgList(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr name(ARGUMENT(1));\n    const LispString* orig = name->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    const std::string oper = InternalUnstringify(*orig);\n\n    LispPtr sizearg(ARGUMENT(2));\n    CheckArg(sizearg, 2, aEnvironment, aStackTop);\n    CheckArg(sizearg->String(), 2, aEnvironment, aStackTop);\n\n    int arity = InternalAsciiToInt(*sizearg->String());\n\n    LispUserFunction* userFunc =\n        aEnvironment.UserFunction(aEnvironment.HashTable().LookUp(oper), arity);\n    CheckArg(userFunc, 1, aEnvironment, aStackTop);\n\n    const LispPtr& list = userFunc->ArgList();\n    LispPtr head(aEnvironment.iList->Copy());\n    head->Nixed() = (list);\n    RESULT = (LispSubList::New(head));\n}\n\nstatic void InternalNewRulePattern(LispEnvironment& aEnvironment,\n                                   int aStackTop,\n                                   bool aMacroMode)\n{\n    int arity;\n    int precedence;\n\n    LispPtr ar;\n    LispPtr pr;\n    LispPtr predicate;\n    LispPtr body;\n\n    // Get operator\n    CheckArg(ARGUMENT(1), 1, aEnvironment, aStackTop);\n    const LispString* orig = ARGUMENT(1)->String();\n    CheckArg(orig, 1, aEnvironment, aStackTop);\n    ar = (ARGUMENT(2));\n    pr = (ARGUMENT(3));\n    predicate = (ARGUMENT(4));\n    body = (ARGUMENT(5));\n\n    // The arity\n    CheckArg(ar, 2, aEnvironment, aStackTop);\n    CheckArg(ar->String(), 2, aEnvironment, aStackTop);\n    arity = InternalAsciiToInt(*ar->String());\n\n    // The precedence\n    CheckArg(ar, 3, aEnvironment, aStackTop);\n    CheckArg(ar->String(), 3, aEnvironment, aStackTop);\n    precedence = InternalAsciiToInt(*pr->String());\n\n    // Finally define the rule base\n    aEnvironment.DefineRulePattern(\n        SymbolName(aEnvironment, *orig), arity, precedence, predicate, body);\n\n    // Return true\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispNewRulePattern(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalNewRulePattern(aEnvironment, aStackTop, false);\n}\n\nvoid LispMacroNewRulePattern(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalNewRulePattern(aEnvironment, aStackTop, true);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/mathcommands2.cpp",
    "content": "#include \"yacas/arrayclass.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/infixparser.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lisperror.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispparser.h\"\n#include \"yacas/lispuserfunc.h\"\n#include \"yacas/mathuserfunc.h\"\n#include \"yacas/numbers.h\"\n#include \"yacas/patternclass.h\"\n#include \"yacas/platmath.h\"\n#include \"yacas/standard.h\"\n#include \"yacas/substitute.h\"\n\n#include <cstring>\n\n#define InternalEval aEnvironment.iEvaluator->Eval\n#define RESULT aEnvironment.iStack[aStackTop]\n#define ARGUMENT(i) aEnvironment.iStack[aStackTop + i]\n\nvoid LispSubst(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr from(ARGUMENT(1));\n    LispPtr to(ARGUMENT(2));\n    LispPtr body(ARGUMENT(3));\n    SubstBehaviour behaviour(aEnvironment, from, to);\n    InternalSubstitute(RESULT, body, behaviour);\n}\n\nvoid LispLocalSymbols(LispEnvironment& aEnvironment, int aStackTop)\n{\n    int nrArguments = InternalListLength(ARGUMENT(0));\n\n    int nrSymbols = nrArguments - 2;\n\n    std::vector<const LispString*> names(nrSymbols);\n    std::vector<const LispString*> localnames(nrSymbols);\n\n    int uniquenumber = aEnvironment.GetUniqueId();\n    int i;\n    for (i = 0; i < nrSymbols; i++) {\n        const LispString* atomname = Argument(ARGUMENT(0), i + 1)->String();\n        CheckArg(atomname, i + 1, aEnvironment, aStackTop);\n        names[i] = atomname;\n\n        std::string newname = \"$\";\n        newname.append(*atomname);\n        newname.append(std::to_string(uniquenumber));\n        localnames[i] = aEnvironment.HashTable().LookUp(newname);\n    }\n\n    LocalSymbolBehaviour behaviour(\n        aEnvironment, std::move(names), std::move(localnames));\n    LispPtr result;\n    InternalSubstitute(\n        result, Argument(ARGUMENT(0), nrArguments - 1), behaviour);\n\n    InternalEval(aEnvironment, RESULT, result);\n}\n\nvoid LispCharString(LispEnvironment& aEnvironment, int aStackTop)\n{\n    const LispString* str = ARGUMENT(1)->String();\n    CheckArg(str, 2, aEnvironment, aStackTop);\n    CheckArg(IsNumber(*str, false), 2, aEnvironment, aStackTop);\n    int asciiCode = InternalAsciiToInt(*str);\n\n    char ascii[4];\n    ascii[0] = '\\\"';\n    ascii[1] = (char)asciiCode;\n    ascii[2] = '\\\"';\n    ascii[3] = '\\0';\n    RESULT = (LispAtom::New(aEnvironment, ascii));\n}\n\nvoid LispInDebugMode(LispEnvironment& aEnvironment, int aStackTop)\n{\n    InternalFalse(aEnvironment, RESULT);\n}\n\nvoid LispDebugFile(LispEnvironment& aEnvironment, int aStackTop)\n{\n    throw LispErrGeneric(\"Cannot call DebugFile in non-debug version of Yacas\");\n}\n\nvoid LispDebugLine(LispEnvironment& aEnvironment, int aStackTop)\n{\n    throw LispErrGeneric(\"Cannot call DebugLine in non-debug version of Yacas\");\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/mathcommands3.cpp",
    "content": "#include \"yacas/arrayclass.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/infixparser.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lisperror.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispparser.h\"\n#include \"yacas/lispuserfunc.h\"\n#include \"yacas/mathuserfunc.h\"\n#include \"yacas/numbers.h\"\n#include \"yacas/patcher.h\"\n#include \"yacas/patternclass.h\"\n#include \"yacas/platfileio.h\"\n#include \"yacas/platmath.h\"\n#include \"yacas/standard.h\"\n#include \"yacas/string_utils.h\"\n#include \"yacas/stringio.h\"\n#include \"yacas/substitute.h\"\n\n#include <cmath>\n\n#include \"yacas/yacas_version.h\"\n\n#include <iomanip>\n#include <sstream>\n\n#define InternalEval aEnvironment.iEvaluator->Eval\n#define RESULT aEnvironment.iStack[aStackTop]\n#define ARGUMENT(i) aEnvironment.iStack[aStackTop + i]\n\n/// Construct a BigNumber from one of the arguments.\n/// \\param x (on output) the constructed bignumber\n/// \\param aEnvironment the current environment\n/// \\param aStackTop the index of the top of the stack\n/// \\param aArgNr the index of the argument to be converted\nvoid GetNumber(RefPtr<BigNumber>& x,\n               LispEnvironment& aEnvironment,\n               int aStackTop,\n               int aArgNr)\n{\n    x = ARGUMENT(aArgNr)->Number(aEnvironment.Precision());\n    CheckArg(x, aArgNr, aEnvironment, aStackTop);\n}\n\n// FIXME remove these\nvoid LispArithmetic2(LispEnvironment& aEnvironment,\n                     int aStackTop,\n                     LispObject* (*func)(LispObject* f1,\n                                         LispObject* f2,\n                                         LispEnvironment& aEnvironment,\n                                         int aPrecision),\n                     bool arbbase = false);\n\nvoid LispArithmetic1(LispEnvironment& aEnvironment,\n                     int aStackTop,\n                     LispObject* (*func)(LispObject* f1,\n                                         LispEnvironment& aEnvironment,\n                                         int aPrecision));\n\n// FIXME remove these\nvoid LispArithmetic1(LispEnvironment& aEnvironment,\n                     int aStackTop,\n                     LispObject* (*func)(LispObject* f1,\n                                         LispEnvironment& aEnvironment,\n                                         int aPrecision))\n{\n    CheckArg(ARGUMENT(1)->Number(0), 1, aEnvironment, aStackTop);\n    RESULT = (func(ARGUMENT(1), aEnvironment, aEnvironment.Precision()));\n}\n\n// FIXME remove these\nvoid LispArithmetic2(LispEnvironment& aEnvironment,\n                     int aStackTop,\n                     LispObject* (*func)(LispObject* f1,\n                                         LispObject* f2,\n                                         LispEnvironment& aEnvironment,\n                                         int aPrecision),\n                     bool arbbase)\n{\n    if (!arbbase) {\n        CheckArg(ARGUMENT(1)->Number(0), 1, aEnvironment, aStackTop);\n        CheckArg(ARGUMENT(2)->Number(0), 2, aEnvironment, aStackTop);\n    }\n    RESULT = (func(\n        ARGUMENT(1), ARGUMENT(2), aEnvironment, aEnvironment.Precision()));\n}\n\nvoid LispDumpBigNumberDebugInfo(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    x->DumpDebugInfo(aEnvironment.CurrentOutput());\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispMultiply(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    RefPtr<BigNumber> y;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    GetNumber(y, aEnvironment, aStackTop, 2);\n    BigNumber* z = new BigNumber(\"0\", aEnvironment.BinaryPrecision());\n    z->Precision(aEnvironment.BinaryPrecision());\n    z->Multiply(*x, *y, aEnvironment.BinaryPrecision());\n    RESULT = new LispNumber(z);\n    return;\n}\n\n// TODO we need to have Gcd in BigNumber!\nvoid LispGcd(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArg(ARGUMENT(1)->Number(0), 1, aEnvironment, aStackTop);\n    CheckArg(ARGUMENT(2)->Number(0), 2, aEnvironment, aStackTop);\n\n    RESULT = (GcdInteger(ARGUMENT(1), ARGUMENT(2), aEnvironment));\n}\n\n/// Corresponds to the Yacas function \\c MathAdd.\n/// If called with one argument (unary plus), this argument is\n/// converted to BigNumber. If called with two arguments (binary plus),\n/// both argument are converted to a BigNumber, and these are added\n/// together at the current precision. The sum is returned.\n/// \\sa GetNumber(), BigNumber::Add()\nvoid LispAdd(LispEnvironment& aEnvironment, int aStackTop)\n{\n    int length = InternalListLength(ARGUMENT(0));\n    if (length == 2) {\n        RefPtr<BigNumber> x;\n        GetNumber(x, aEnvironment, aStackTop, 1);\n        RESULT = (new LispNumber(x.ptr()));\n        return;\n    } else {\n        RefPtr<BigNumber> x;\n        RefPtr<BigNumber> y;\n        GetNumber(x, aEnvironment, aStackTop, 1);\n        GetNumber(y, aEnvironment, aStackTop, 2);\n        BigNumber* z = new BigNumber(\"0\", aEnvironment.BinaryPrecision());\n        z->Precision(aEnvironment.BinaryPrecision());\n        z->Add(*x.ptr(), *y.ptr(), aEnvironment.BinaryPrecision());\n        RESULT = (new LispNumber(z));\n        return;\n    }\n}\n\nvoid LispSubtract(LispEnvironment& aEnvironment, int aStackTop)\n{\n    int length = InternalListLength(ARGUMENT(0));\n    if (length == 2) {\n        RefPtr<BigNumber> x;\n        GetNumber(x, aEnvironment, aStackTop, 1);\n        BigNumber* z = new BigNumber(*x);\n        z->Negate(*z);\n        RESULT = (new LispNumber(z));\n        return;\n    } else {\n        RefPtr<BigNumber> x;\n        RefPtr<BigNumber> y;\n        GetNumber(x, aEnvironment, aStackTop, 1);\n        GetNumber(y, aEnvironment, aStackTop, 2);\n        BigNumber yneg(*y);\n        yneg.Negate(yneg);\n        BigNumber* z = new BigNumber(\"0\", aEnvironment.BinaryPrecision());\n        z->Precision(aEnvironment.BinaryPrecision());\n        z->Add(*x, yneg, aEnvironment.BinaryPrecision());\n        RESULT = (new LispNumber(z));\n        return;\n    }\n}\n\nvoid LispDivide(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Serge, what was the deal again with divide, floats and integers mixed in\n    // the same function?\n    //  yes, divide works differently on integers and on floats -- see new.chapt\n    //  -- Serge\n    RefPtr<BigNumber> x;\n    RefPtr<BigNumber> y;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    GetNumber(y, aEnvironment, aStackTop, 2);\n    BigNumber* z = new BigNumber(\"0\", aEnvironment.BinaryPrecision());\n    z->Precision(aEnvironment.BinaryPrecision());\n    // if both arguments are integers, then BigNumber::Divide would perform an\n    // integer divide, but we want a float divide here.\n    if (x->IsInt() && y->IsInt()) {\n        // why can't we just say BigNumber temp; ?\n        BigNumber tempx(*x);\n        tempx.BecomeFloat(aEnvironment.BinaryPrecision()); // coerce x to float\n        BigNumber tempy(*y);\n        tempy.BecomeFloat(aEnvironment.BinaryPrecision()); // coerce x to float\n        z->Divide(tempx, tempy, aEnvironment.BinaryPrecision());\n    } else {\n        z->Divide(*x, *y, aEnvironment.BinaryPrecision());\n    }\n    RESULT = (new LispNumber(z));\n    return;\n}\n\n#define UNARYFUNCTION(LispName, BigNumName)                                    \\\n    void LispName(LispEnvironment& aEnvironment, int aStackTop)                \\\n    {                                                                          \\\n        RefPtr<BigNumber> x;                                                   \\\n        GetNumber(x, aEnvironment, aStackTop, 1);                              \\\n        BigNumber* z = new BigNumber(*x);                                      \\\n        z->BigNumName(*z);                                                     \\\n        RESULT = (new LispNumber(z));                                          \\\n    }\n#define BINARYFUNCTION(LispName, BigNumName)                                   \\\n    void LispName(LispEnvironment& aEnvironment, int aStackTop)                \\\n    {                                                                          \\\n        RefPtr<BigNumber> x;                                                   \\\n        RefPtr<BigNumber> y;                                                   \\\n        GetNumber(x, aEnvironment, aStackTop, 1);                              \\\n        GetNumber(y, aEnvironment, aStackTop, 2);                              \\\n        BigNumber* z = new BigNumber(\"0\", 0);                                  \\\n        z->BigNumName(*x, *y);                                                 \\\n        RESULT = (new LispNumber(z));                                          \\\n    }\n\nUNARYFUNCTION(LispFloor, Floor)\nUNARYFUNCTION(LispMathNegate, Negate)\n\n/** the macro\n  UNARYFUNCTION(LispFloor, Floor, FloorFloat)\nis used to help interface Yacas with BigNumber. Suppose we need to access a\nunary function named 'Floor' in BigNumber and 'LispFloor' here, with\n'FloorFloat' the backup function for no BigNumber support. The macro produces\nthe following equivalent code for the unary function: void\nLispFloor(LispEnvironment& aEnvironment, int aStackTop)\n{\n      RefPtr<BigNumber> x;\n      GetNumber(x,aEnvironment, aStackTop, 1);\n      BigNumber *z = new BigNumber(aEnvironment.BinaryPrecision());\n      z->Floor(*x.Ptr());\n      RESULT = (new LispNumber(z));\n}\n*/\n/* FIXME Eventually the BigNumber support will be stable and we can remove old\n * code and simplify these macros */\n\n/// obtain internal precision data on a number object.\nvoid LispGetExactBits(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    BigNumber* z = new BigNumber(\n        std::to_string(x->IsInt() ? x->BitCount() : x->GetPrecision()),\n        aEnvironment.BinaryPrecision());\n    RESULT = (new LispNumber(z));\n}\n/// set internal precision data on a number object.\nvoid LispSetExactBits(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    RefPtr<BigNumber> y;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    GetNumber(y, aEnvironment, aStackTop, 2);\n    BigNumber* z = new BigNumber(*x);\n    // do nothing for integers\n    if (!(z->IsInt()))\n        z->Precision((long)(y->Double())); // segfaults unless y is defined?\n    RESULT = (new LispNumber(z));\n}\n\n/// obtain the bit count of a number object.\nvoid LispBitCount(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    BigNumber* z = new BigNumber(std::to_string(x->BitCount()),\n                                 aEnvironment.BinaryPrecision());\n    RESULT = (new LispNumber(z));\n}\n\n/// obtain the sign of a number object.\nvoid LispMathSign(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    BigNumber* z = new BigNumber(std::to_string(x->Sign()),\n                                 aEnvironment.BinaryPrecision());\n    RESULT = (new LispNumber(z));\n}\n\n/// check whether a number object fits into a platform type.\nvoid LispMathIsSmall(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    InternalBoolean(aEnvironment, RESULT, x->IsSmall());\n}\n\nvoid LispCeil(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    BigNumber* z = new BigNumber(\"0\", aEnvironment.BinaryPrecision());\n    z->Negate(*x);\n    z->Floor(*z); // danger: possible exception raised in Floor() leads to a\n                  // memory leak because z is not destroyed\n    z->Negate(*z);\n    RESULT = (new LispNumber(z));\n}\n\nvoid LispAbs(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    BigNumber* z = new BigNumber(*x);\n    if (x->Sign() < 0)\n        z->Negate(*x);\n    RESULT = (new LispNumber(z));\n}\n// BINARYFUNCTION(LispMod, Mod, ModFloat)\n/* this will be gone */\nvoid LispMod(LispEnvironment& aEnvironment, int aStackTop)\n{ // FIXME\n    LispArithmetic2(aEnvironment, aStackTop, ModFloat);\n}\n/* up to here */\n\nvoid LispDiv(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    RefPtr<BigNumber> y;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    GetNumber(y, aEnvironment, aStackTop, 2);\n\n    // TODO FIXME: either need to report error that one or both of the arguments\n    // are not integer, or coerce them to integers\n    CheckArg(x->IsInt(), 1, aEnvironment, aStackTop);\n    CheckArg(y->IsInt(), 2, aEnvironment, aStackTop);\n\n    BigNumber* z = new BigNumber(\"0\", aEnvironment.BinaryPrecision());\n    z->Precision(aEnvironment.BinaryPrecision());\n    z->Divide(*x, *y, aEnvironment.BinaryPrecision());\n    RESULT = (new LispNumber(z));\n}\n\nvoid LispPower(LispEnvironment& aEnvironment, int aStackTop)\n{ // FIXME move to scripts\n    LispArithmetic2(aEnvironment, aStackTop, PowerFloat);\n}\n\nvoid LispFac(LispEnvironment& aEnvironment, int aStackTop)\n{ // FIXME move to scripts\n    LispArithmetic1(aEnvironment, aStackTop, LispFactorial);\n}\n\n// platform functions, taking/returning a platform int/float\n\nvoid LispFastIsPrime(LispEnvironment& aEnvironment, int aStackTop)\n{ // TODO FIXME\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    long result = primes_table_check((unsigned long)(x->Double()));\n    BigNumber* z =\n        new BigNumber(std::to_string(result), aEnvironment.BinaryPrecision());\n    RESULT = (new LispNumber(z));\n}\n\n// define a macro to replace all platform math functions\n\n#define PLATFORM_UNARY(LispName, PlatformName, LispBackupName, OldName)        \\\n    void LispName(LispEnvironment& aEnvironment, int aStackTop)                \\\n    {                                                                          \\\n        RefPtr<BigNumber> x;                                                   \\\n        GetNumber(x, aEnvironment, aStackTop, 1);                              \\\n        std::ostringstream buf;                                                \\\n        buf << std::setprecision(53) << PlatformName(x->Double());             \\\n        BigNumber* z =                                                         \\\n            new BigNumber(buf.str(), aEnvironment.BinaryPrecision());          \\\n        RESULT = (new LispNumber(z));                                          \\\n    }\n\n#define PLATFORM_BINARY(LispName, PlatformName, LispBackupName, OldName)       \\\n    void LispName(LispEnvironment& aEnvironment, int aStackTop)                \\\n    {                                                                          \\\n        RefPtr<BigNumber> x, y;                                                \\\n        GetNumber(x, aEnvironment, aStackTop, 1);                              \\\n        GetNumber(y, aEnvironment, aStackTop, 2);                              \\\n        std::ostringstream buf;                                                \\\n        buf << std::setprecision(53)                                           \\\n            << PlatformName(x->Double(), y->Double());                         \\\n        BigNumber* z =                                                         \\\n            new BigNumber(buf.str(), aEnvironment.BinaryPrecision());          \\\n        RESULT = (new LispNumber(z));                                          \\\n    }\n\n// now we can define all such functions, e.g.:\n\n// some or all of these functions should be moved to scripts\nPLATFORM_UNARY(LispFastArcSin, std::asin, LispArcSin, PlatArcSin)\nPLATFORM_UNARY(LispFastLog, std::log, LispLn, PlatLn)\nPLATFORM_BINARY(LispFastPower, std::pow, LispPower, PlatPower)\n\nBINARYFUNCTION(LispBitAnd, BitAnd)\nBINARYFUNCTION(LispBitOr, BitOr)\nBINARYFUNCTION(LispBitXor, BitXor)\n/*\n// BitNot not yet in yacasapi etc.\n//BINARYFUNCTION(LispBitNot, BitNot, BitNot)\n*/\n/* this will be gone */\nvoid LispShiftLeft(LispEnvironment& aEnvironment, int aStackTop)\n{ // FIXME\n    LispArithmetic2(aEnvironment, aStackTop, ShiftLeft);\n}\nvoid LispShiftRight(LispEnvironment& aEnvironment, int aStackTop)\n{ // FIXME\n    LispArithmetic2(aEnvironment, aStackTop, ShiftRight);\n}\n\n/* up to here */\n\nvoid LispFromBase(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get the base to convert to:\n    // Evaluate first argument, and store result in oper\n    LispPtr oper(ARGUMENT(1));\n    // Check that result is a number, and that it is in fact an integer\n    RefPtr<BigNumber> num;\n    num = oper->Number(aEnvironment.BinaryPrecision());\n    CheckArg(num, 1, aEnvironment, aStackTop);\n    // check that the base is an integer between 2 and 32\n    CheckArg(num->IsInt() && num->Double() >= BASE2 &&\n                 num->Double() <= log2_table_range(),\n             1,\n             aEnvironment,\n             aStackTop);\n\n    // Get a short platform integer from the first argument\n    int base = (int)(num->Double());\n\n    // Get the number to convert\n    LispPtr fromNum(ARGUMENT(2));\n    const LispString* str2 = fromNum->String();\n    CheckArg(str2, 2, aEnvironment, aStackTop);\n\n    // Added, unquote a string\n    CheckArg(InternalIsString(str2), 2, aEnvironment, aStackTop);\n    str2 = aEnvironment.HashTable().LookUp(str2->substr(1, str2->length() - 2));\n\n    // convert using correct base\n    // FIXME: API breach, must pass precision in base digits and not in bits!\n    // if converting an integer, the precision argument is ignored,\n    // but if converting a float, need to use bits_to_digits(BinaryPrecision,\n    // base)\n    BigNumber* z = new BigNumber(*str2, aEnvironment.BinaryPrecision(), base);\n    RESULT = (new LispNumber(z));\n}\nvoid LispToBase(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Get the base to convert to:\n    // Evaluate first argument, and store result in oper\n    LispPtr oper(ARGUMENT(1));\n    // Check that result is a number, and that it is in fact an integer\n    RefPtr<BigNumber> num;\n    num = oper->Number(aEnvironment.BinaryPrecision());\n    CheckArg(num, 1, aEnvironment, aStackTop);\n    // check that the base is an integer between 2 and 32\n    CheckArg(num->IsInt() && num->Double() >= BASE2 &&\n                 num->Double() <= log2_table_range(),\n             1,\n             aEnvironment,\n             aStackTop);\n\n    // Get a short platform integer from the first argument\n    int base = (int)(num->Double());\n\n    // Get the number to convert\n    RefPtr<BigNumber> x;\n    GetNumber(x, aEnvironment, aStackTop, 2);\n\n    // convert using correct base\n    LispString str;\n    // FIXME: API breach, must pass precision in base digits and not in bits!\n    // if converting an integer, the precision argument is ignored,\n    // but if converting a float, need to use bits_to_digits(BinaryPrecision,\n    // base)\n    x->ToString(str, aEnvironment.BinaryPrecision(), base);\n    // Get unique string from hash table, and create an atom from it.\n\n    RESULT = LispAtom::New(aEnvironment, stringify(str));\n}\n\nvoid LispApplyPure(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr oper(ARGUMENT(1));\n    LispPtr args(ARGUMENT(2));\n\n    CheckArg(args->SubList(), 2, aEnvironment, aStackTop);\n    CheckArg(*args->SubList(), 2, aEnvironment, aStackTop);\n\n    // Apply a pure string\n    if (oper->String()) {\n        InternalApplyString(\n            aEnvironment, RESULT, oper->String(), (*args->SubList())->Nixed());\n    } else { // Apply a pure function {args,body}.\n        LispPtr args2((*args->SubList())->Nixed());\n        CheckArg(oper->SubList(), 1, aEnvironment, aStackTop);\n        CheckArg(*oper->SubList(), 1, aEnvironment, aStackTop);\n        InternalApplyPure(oper, args2, RESULT, aEnvironment);\n    }\n}\n\nvoid YacasPrettyReaderSet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    int nrArguments = InternalListLength(ARGUMENT(0));\n\n    if (nrArguments == 1) {\n        aEnvironment.SetPrettyReader(nullptr);\n    } else {\n        CheckNrArgs(2, ARGUMENT(0), aEnvironment);\n        LispPtr oper(ARGUMENT(0));\n        oper = oper->Nixed(); // oper.GoNext();  // woof woof woof\n        CheckArgIsString(oper, 1, aEnvironment, aStackTop);\n        aEnvironment.SetPrettyReader(oper->String());\n    }\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid YacasPrettyReaderGet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    if (!aEnvironment.PrettyReader())\n        RESULT = LispAtom::New(aEnvironment, \"\\\"\\\"\");\n    else\n        RESULT = LispAtom::New(aEnvironment, *aEnvironment.PrettyReader());\n}\n\nvoid YacasPrettyPrinterSet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    int nrArguments = InternalListLength(ARGUMENT(0));\n\n    if (nrArguments == 1) {\n        aEnvironment.SetPrettyPrinter(nullptr);\n    } else {\n        CheckNrArgs(2, ARGUMENT(0), aEnvironment);\n        LispPtr oper(ARGUMENT(0));\n        oper = oper->Nixed(); // oper.GoNext();  // woof woof woof\n        CheckArgIsString(oper, 1, aEnvironment, aStackTop);\n        aEnvironment.SetPrettyPrinter(oper->String());\n    }\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid YacasPrettyPrinterGet(LispEnvironment& aEnvironment, int aStackTop)\n{\n    if (!aEnvironment.PrettyPrinter())\n        RESULT = LispAtom::New(aEnvironment, \"\\\"\\\"\");\n    else\n        RESULT = LispAtom::New(aEnvironment, *aEnvironment.PrettyPrinter());\n}\n\nvoid LispGarbageCollect(LispEnvironment& aEnvironment, int aStackTop)\n{\n    aEnvironment.HashTable().GarbageCollect();\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispPatchLoad(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n    const LispString* string = evaluated->String();\n    CheckArg(string, 1, aEnvironment, aStackTop);\n    const std::string fname = InternalUnstringify(*string);\n    InputStatus oldstatus = aEnvironment.iInputStatus;\n    aEnvironment.iInputStatus.SetTo(fname);\n    LispLocalFile localFP(\n        aEnvironment, fname, true, aEnvironment.iInputDirectories);\n\n    if (!localFP.stream.is_open())\n        throw LispErrFileNotFound();\n\n    std::string content(std::istreambuf_iterator<char>(localFP.stream),\n                        std::istreambuf_iterator<char>());\n\n    PatchLoad(content, aEnvironment.CurrentOutput(), aEnvironment);\n\n    aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispPatchString(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr evaluated(ARGUMENT(1));\n    const LispString* string = evaluated->String();\n    CheckArg(string, 1, aEnvironment, aStackTop);\n    const std::string oper = InternalUnstringify(*string);\n\n    std::ostringstream os;\n    LispLocalOutput localOutput(aEnvironment, os);\n    PatchLoad(oper, os, aEnvironment);\n    RESULT = LispAtom::New(aEnvironment, stringify(os.str()));\n}\n\nvoid LispDefaultTokenizer(LispEnvironment& aEnvironment, int aStackTop)\n{\n    aEnvironment.iCurrentTokenizer = &aEnvironment.iDefaultTokenizer;\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispXmlTokenizer(LispEnvironment& aEnvironment, int aStackTop)\n{\n    aEnvironment.iCurrentTokenizer = &aEnvironment.iXmlTokenizer;\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispExplodeTag(LispEnvironment& aEnvironment, int aStackTop)\n{\n    LispPtr out(ARGUMENT(1));\n    CheckArgIsString(1, aEnvironment, aStackTop);\n\n    const char* str = out->String()->c_str();\n    str++;\n    if (str[0] != '<') {\n        RESULT = (out);\n        return;\n    }\n    str++;\n    const char* type = (str[0] == '/') ? (str++, \"\\\"Close\\\"\") : \"\\\"Open\\\"\";\n    std::string tag;\n\n    tag.push_back('\\\"');\n    while (IsAlpha(*str)) {\n        char c = *str++;\n        if (c >= 'a' && c <= 'z')\n            c = c + ('A' - 'a');\n        tag.push_back(c);\n    }\n    tag.push_back('\\\"');\n\n    LispObject* info = nullptr;\n\n    while (*str == ' ')\n        str++;\n    while (*str != '>' && *str != '/') {\n        std::string name;\n        name.push_back('\\\"');\n\n        while (IsAlpha(*str)) {\n            char c = *str++;\n            if (c >= 'a' && c <= 'z')\n                c = c + ('A' - 'a');\n            name.push_back(c);\n        }\n        name.push_back('\\\"');\n\n        CheckArg(str[0] == '=', 1, aEnvironment, aStackTop);\n        str++;\n        CheckArg(str[0] == '\\\"', 1, aEnvironment, aStackTop);\n\n        std::string value;\n        value.push_back(*str++);\n        while (*str != '\\\"')\n            value.push_back(*str++);\n\n        value.push_back(*str++);\n\n        info = LispSubList::New(\n                   LispObjectAdder(aEnvironment.iList->Copy()) +\n                   LispObjectAdder(LispAtom::New(aEnvironment, name)) +\n                   LispObjectAdder(LispAtom::New(aEnvironment, value))) +\n               LispObjectAdder(info);\n        while (*str == ' ')\n            str++;\n    }\n    if (*str == '/') {\n        type = \"\\\"OpenClose\\\"\";\n        str++;\n        while (*str == ' ')\n            ++str;\n    }\n\n    info = LispSubList::New(LispObjectAdder(aEnvironment.iList->Copy()) +\n                            LispObjectAdder(info));\n    RESULT = (LispSubList::New(\n        LispObjectAdder(LispAtom::New(aEnvironment, \"XmlTag\")) +\n        LispObjectAdder(LispAtom::New(aEnvironment, tag)) +\n        LispObjectAdder(info) +\n        LispObjectAdder(LispAtom::New(aEnvironment, type))));\n}\n\nvoid YacasBuiltinAssoc(LispEnvironment& aEnvironment, int aStackTop)\n{\n    // Check that we have two arguments.\n\n    // key to find\n    LispPtr key(ARGUMENT(1));\n\n    // assoc-list to find it in\n    LispPtr list(ARGUMENT(2));\n\n    LispObject* t;\n\n    // Check that it is a compound object\n    CheckArg(list->SubList(), 2, aEnvironment, aStackTop);\n    t = (*list->SubList());\n    CheckArg(t, 2, aEnvironment, aStackTop);\n    t = t->Nixed();\n\n    while (t) {\n        if (t->SubList()) {\n            LispObject* sub = (*t->SubList());\n            if (sub) {\n                sub = sub->Nixed();\n                LispPtr temp(sub);\n                if (InternalEquals(aEnvironment, key, temp)) {\n                    RESULT = (t);\n                    return;\n                }\n            }\n        }\n        t = t->Nixed();\n    }\n\n    RESULT = (LispAtom::New(aEnvironment, \"Empty\"));\n}\n\nvoid LispCurrentFile(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RESULT = LispAtom::New(aEnvironment,\n                           stringify(aEnvironment.iInputStatus.FileName()));\n}\n\nvoid LispCurrentLine(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RESULT = LispAtom::New(\n        aEnvironment, std::to_string(aEnvironment.iInputStatus.LineNumber()));\n}\n\nvoid LispBackQuote(LispEnvironment& aEnvironment, int aStackTop)\n{\n    BackQuoteBehaviour behaviour(aEnvironment);\n    LispPtr result;\n    InternalSubstitute(result, ARGUMENT(1), behaviour);\n    InternalEval(aEnvironment, RESULT, result);\n}\n\nvoid interpreter(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RESULT = (LispAtom::New(aEnvironment, \"\\\"yacas\\\"\"));\n}\n\nvoid LispVersion(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RESULT = (LispAtom::New(aEnvironment, \"\\\"\" YACAS_VERSION \"\\\"\"));\n}\n\n/// convert bits to digits. Use the kernel function bits_to_digits. Arguments\n/// must be small integers.\nvoid LispBitsToDigits(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    RefPtr<BigNumber> y;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    GetNumber(y, aEnvironment, aStackTop, 2);\n    long result = 0; // initialize just in case\n    if (x->IsInt() && x->IsSmall() && y->IsInt() && y->IsSmall()) {\n        // bits_to_digits uses unsigned long, see numbers.h\n        unsigned base = unsigned(y->Double());\n        result = bits_to_digits((unsigned long)(x->Double()), base);\n    } else {\n        std::ostringstream buf;\n        buf << \"BitsToDigits: error: arguments (\" << x->Double() << \", \"\n            << y->Double() << \" must be small integers\";\n        throw LispErrGeneric(buf.str());\n    }\n    BigNumber* z =\n        new BigNumber(std::to_string(result), aEnvironment.BinaryPrecision());\n    RESULT = (new LispNumber(z));\n}\n\n/// convert digits to bits. Use the kernel function digits_to_bits. Arguments\n/// must be small integers.\nvoid LispDigitsToBits(LispEnvironment& aEnvironment, int aStackTop)\n{\n    RefPtr<BigNumber> x;\n    RefPtr<BigNumber> y;\n    GetNumber(x, aEnvironment, aStackTop, 1);\n    GetNumber(y, aEnvironment, aStackTop, 2);\n    long result = 0; // initialize just in case\n    if (x->IsInt() && x->IsSmall() && y->IsInt() && y->IsSmall()) {\n        // bits_to_digits uses unsigned long, see numbers.h\n        unsigned base = unsigned(y->Double());\n        result = digits_to_bits((unsigned long)(x->Double()), base);\n    } else {\n        std::ostringstream buf;\n        buf << \"BitsToDigits: error: arguments (\" << x->Double() << \", \"\n            << y->Double() << \" must be small integers\";\n        throw LispErrGeneric(buf.str());\n    }\n    BigNumber* z =\n        new BigNumber(std::to_string(result), aEnvironment.BinaryPrecision());\n    RESULT = (new LispNumber(z));\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/mathuserfunc.cpp",
    "content": "#include \"yacas/mathuserfunc.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispobject.h\"\n#include \"yacas/patternclass.h\"\n#include \"yacas/patterns.h\"\n#include \"yacas/standard.h\"\n#include \"yacas/substitute.h\"\n\n#include <memory>\n\n#define InternalEval aEnvironment.iEvaluator->Eval\n\nbool BranchingUserFunction::BranchRule::Matches(LispEnvironment& aEnvironment,\n                                                LispPtr* aArguments)\n{\n    LispPtr pred;\n    InternalEval(aEnvironment, pred, iPredicate);\n    return IsTrue(aEnvironment, pred);\n}\nint BranchingUserFunction::BranchRule::Precedence() const\n{\n    return iPrecedence;\n}\nLispPtr& BranchingUserFunction::BranchRule::Body()\n{\n    return iBody;\n}\n\nbool BranchingUserFunction::BranchRuleTruePredicate::Matches(\n    LispEnvironment& aEnvironment, LispPtr* aArguments)\n{\n    return true;\n}\n\nbool BranchingUserFunction::BranchPattern::Matches(\n    LispEnvironment& aEnvironment, LispPtr* aArguments)\n{\n    return iPatternClass->Matches(aEnvironment, aArguments);\n}\nint BranchingUserFunction::BranchPattern::Precedence() const\n{\n    return iPrecedence;\n}\nLispPtr& BranchingUserFunction::BranchPattern::Body()\n{\n    return iBody;\n}\n\nBranchingUserFunction::BranchingUserFunction(LispPtr& aParameters) :\n    iParameters(),\n    iRules(),\n    iParamList(aParameters)\n{\n    for (LispIterator iter(aParameters); iter.getObj(); ++iter) {\n        if (!iter.getObj()->String())\n            throw LispErrCreatingUserFunction();\n\n        BranchParameter param(iter.getObj()->String());\n        iParameters.push_back(param);\n    }\n}\n\nBranchingUserFunction::~BranchingUserFunction()\n{\n    for (BranchRuleBase* p : iRules)\n        delete p;\n}\n\nvoid BranchingUserFunction::Evaluate(LispPtr& aResult,\n                                     LispEnvironment& aEnvironment,\n                                     LispPtr& aArguments) const\n{\n    const unsigned arity = Arity();\n\n    if (Traced()) {\n        LispPtr tr(LispSubList::New(aArguments));\n        TraceShowEnter(aEnvironment, tr);\n        tr = nullptr;\n    }\n\n    LispIterator iter(aArguments);\n    ++iter;\n\n    // unrollable arguments\n    std::unique_ptr<LispPtr[]> arguments(arity == 0 ? nullptr\n                                                    : new LispPtr[arity]);\n\n    // Walk over all arguments, evaluating them as necessary\n    for (unsigned i = 0; i < arity; ++i, ++iter) {\n        if (!iter.getObj())\n            throw LispErrWrongNumberOfArgs();\n\n        if (iParameters[i].iHold) {\n            arguments[i] = iter.getObj()->Copy();\n        } else {\n            // Check(iter.getObj(), KLispErrWrongNumberOfArgs);  // checked\n            // above\n            InternalEval(aEnvironment, arguments[i], *iter);\n        }\n    }\n\n    if (Traced()) {\n        LispIterator iter(aArguments);\n        for (unsigned i = 0; i < arity; ++i)\n            TraceShowArg(aEnvironment, *++iter, arguments[i]);\n    }\n\n    // declare a new local stack.\n    LispLocalFrame frame(aEnvironment, Fenced());\n\n    // define the local variables.\n    for (unsigned i = 0; i < arity; ++i) {\n        const LispString* variable = iParameters[i].iParameter;\n        // set the variable to the new value\n        aEnvironment.NewLocal(variable, arguments[i]);\n    }\n\n    // walk the rules database, returning the evaluated result if the\n    // predicate is true.\n    const std::size_t nrRules = iRules.size();\n    UserStackInformation& st = aEnvironment.iEvaluator->StackInformation();\n    for (std::size_t i = 0; i < nrRules; i++) {\n        BranchRuleBase* thisRule = iRules[i];\n        assert(thisRule);\n\n        st.iRulePrecedence = thisRule->Precedence();\n        bool matches = thisRule->Matches(aEnvironment, arguments.get());\n        if (matches) {\n            st.iSide = 1;\n            InternalEval(aEnvironment, aResult, thisRule->Body());\n            goto FINISH;\n        }\n\n        // If rules got inserted, walk back\n        while (thisRule != iRules[i] && i > 0)\n            i--;\n    }\n\n    // No predicate was true: return a new expression with the evaluated\n    // arguments.\n\n    {\n        LispPtr full(aArguments->Copy());\n        if (arity == 0) {\n            full->Nixed() = nullptr;\n        } else {\n            full->Nixed() = arguments[0];\n            for (unsigned i = 0; i < arity - 1; ++i)\n                arguments[i]->Nixed() = arguments[i + 1];\n        }\n        aResult = LispSubList::New(full);\n    }\n\nFINISH:\n    if (Traced()) {\n        LispPtr tr(LispSubList::New(aArguments));\n        TraceShowLeave(aEnvironment, aResult, tr);\n        tr = nullptr;\n    }\n}\n\nvoid BranchingUserFunction::HoldArgument(const LispString* aVariable)\n{\n    const std::size_t nrc = iParameters.size();\n    for (std::size_t i = 0; i < nrc; ++i) {\n        if (iParameters[i].iParameter == aVariable)\n            iParameters[i].iHold = true;\n    }\n}\n\nunsigned BranchingUserFunction::Arity() const\n{\n    return iParameters.size();\n}\n\nbool BranchingUserFunction::IsArity(unsigned aArity) const\n{\n    return Arity() == aArity;\n}\n\nvoid BranchingUserFunction::DeclareRule(int aPrecedence,\n                                        LispPtr& aPredicate,\n                                        LispPtr& aBody)\n{\n    // New branching rule.\n    BranchRule* newRule = new BranchRule(aPrecedence, aPredicate, aBody);\n\n    if (!newRule)\n        throw LispErrCreatingRule();\n\n    InsertRule(aPrecedence, newRule);\n}\n\nvoid BranchingUserFunction::DeclareRule(int aPrecedence, LispPtr& aBody)\n{\n    // New branching rule.\n    BranchRule* newRule = new BranchRuleTruePredicate(aPrecedence, aBody);\n\n    if (!newRule)\n        throw LispErrCreatingRule();\n\n    InsertRule(aPrecedence, newRule);\n}\n\nvoid BranchingUserFunction::DeclarePattern(int aPrecedence,\n                                           LispPtr& aPredicate,\n                                           LispPtr& aBody)\n{\n    // New branching rule.\n    BranchPattern* newRule = new BranchPattern(aPrecedence, aPredicate, aBody);\n\n    if (!newRule)\n        throw LispErrCreatingRule();\n\n    InsertRule(aPrecedence, newRule);\n}\n\nvoid BranchingUserFunction::InsertRule(int aPrecedence, BranchRuleBase* newRule)\n{\n    // Find place to insert\n    int low, high, mid;\n    low = 0;\n    high = iRules.size();\n\n    // Constant time: find out if the precedence is before any of the\n    // currently defined rules or past them.\n    if (high > 0) {\n        if (iRules[0]->Precedence() > aPrecedence) {\n            mid = 0;\n            goto CONTINUE;\n        }\n        if (iRules[high - 1]->Precedence() < aPrecedence) {\n            mid = high;\n            goto CONTINUE;\n        }\n    }\n\n    // Otherwise, O(log n) search algorithm for place to insert\n    for (;;) {\n        if (low >= high) {\n            mid = low;\n            goto CONTINUE;\n        }\n        mid = (low + high) >> 1;\n\n        if (iRules[mid]->Precedence() > aPrecedence) {\n            high = mid;\n        } else if (iRules[mid]->Precedence() < aPrecedence) {\n            low = (++mid);\n        } else {\n            goto CONTINUE;\n        }\n    }\nCONTINUE:\n    // Insert it\n    iRules.insert(iRules.begin() + mid, newRule);\n}\n\nconst LispPtr& BranchingUserFunction::ArgList() const\n{\n    return iParamList;\n}\n\nListedBranchingUserFunction::ListedBranchingUserFunction(LispPtr& aParameters) :\n    BranchingUserFunction(aParameters)\n{\n}\n\nbool ListedBranchingUserFunction::IsArity(unsigned aArity) const\n{\n    // nr arguments handled is bound by a minimum: the number of arguments\n    // to this function.\n    return Arity() <= aArity;\n}\n\nvoid ListedBranchingUserFunction::Evaluate(LispPtr& aResult,\n                                           LispEnvironment& aEnvironment,\n                                           LispPtr& aArguments) const\n{\n    LispPtr newArgs;\n    LispIterator iter(aArguments);\n    LispPtr* ptr = &newArgs;\n    const int arity = Arity();\n    // Make a copy of the arguments first\n    // TODO: if we were to change the internal representation to a cons cell,\n    // this copying would not be needed\n    for (int i = 0; i < arity && iter.getObj(); ++i, ++iter) {\n        *ptr = iter.getObj()->Copy();\n        ptr = &((*ptr)->Nixed());\n    }\n\n    if (!iter.getObj()->Nixed()) {\n        (*ptr) = (iter.getObj()->Copy());\n        ++iter;\n        assert(!iter.getObj());\n    } else {\n        LispPtr head(aEnvironment.iList->Copy());\n        head->Nixed() = iter.getObj();\n        *ptr = (LispSubList::New(head));\n    }\n    BranchingUserFunction::Evaluate(aResult, aEnvironment, newArgs);\n}\n\nMacroUserFunction::MacroUserFunction(LispPtr& aParameters) :\n    BranchingUserFunction(aParameters)\n{\n    LispIterator iter(aParameters);\n    for (int i = 0; iter.getObj(); i++, ++iter) {\n        if (!iter.getObj()->String())\n            throw LispErrCreatingUserFunction();\n\n        iParameters[i].iHold = true;\n    }\n    UnFence();\n}\n\nvoid MacroUserFunction::Evaluate(LispPtr& aResult,\n                                 LispEnvironment& aEnvironment,\n                                 LispPtr& aArguments) const\n{\n    const unsigned arity = Arity();\n\n    if (Traced()) {\n        LispPtr tr(LispSubList::New(aArguments));\n        TraceShowEnter(aEnvironment, tr);\n        tr = (nullptr);\n    }\n\n    LispIterator iter(aArguments);\n    ++iter;\n\n    // unrollable arguments\n    std::unique_ptr<LispPtr[]> arguments(arity == 0 ? nullptr\n                                                    : new LispPtr[arity]);\n\n    // Walk over all arguments, evaluating them as necessary\n    for (unsigned i = 0; i < arity; ++i, ++iter) {\n        if (!iter.getObj())\n            throw LispErrWrongNumberOfArgs();\n\n        if (iParameters[i].iHold)\n            arguments[i] = iter.getObj()->Copy();\n        else\n            InternalEval(aEnvironment, arguments[i], *iter);\n    }\n\n    if (Traced()) {\n        LispIterator iter(aArguments);\n        // TODO: ideally we would only need an iterator here\n        ++iter;\n        for (unsigned i = 0; i < arity; ++i) {\n            TraceShowArg(aEnvironment, *iter, arguments[i]);\n            ++iter;\n        }\n    }\n\n    LispPtr substedBody;\n    {\n        // declare a new local stack.\n        LispLocalFrame frame(aEnvironment, false);\n\n        // define the local variables.\n        for (unsigned i = 0; i < arity; ++i) {\n            const LispString* variable = iParameters[i].iParameter;\n            // set the variable to the new value\n            aEnvironment.NewLocal(variable, arguments[i]);\n        }\n\n        // walk the rules database, returning the evaluated result if the\n        // predicate is true.\n        const std::size_t nrRules = iRules.size();\n        UserStackInformation& st = aEnvironment.iEvaluator->StackInformation();\n        for (std::size_t i = 0; i < nrRules; i++) {\n            BranchRuleBase* thisRule = iRules[i];\n            assert(thisRule);\n\n            st.iRulePrecedence = thisRule->Precedence();\n            const bool matches =\n                thisRule->Matches(aEnvironment, arguments.get());\n            if (matches) {\n                st.iSide = 1;\n\n                BackQuoteBehaviour behaviour(aEnvironment);\n                InternalSubstitute(substedBody, thisRule->Body(), behaviour);\n                break;\n            }\n\n            // If rules got inserted, walk back\n            while (thisRule != iRules[i] && i > 0)\n                i--;\n        }\n    }\n\n    if (!!substedBody) {\n        InternalEval(aEnvironment, aResult, substedBody);\n    } else\n    // No predicate was true: return a new expression with the evaluated\n    // arguments.\n    {\n        LispPtr full(aArguments->Copy());\n        if (arity == 0) {\n            full->Nixed() = nullptr;\n        } else {\n            full->Nixed() = arguments[0];\n            for (unsigned i = 0; i + 1 < arity; ++i) {\n                arguments[i]->Nixed() = arguments[i + 1];\n            }\n        }\n        aResult = LispSubList::New(full);\n    }\n    if (Traced()) {\n        LispPtr tr(LispSubList::New(aArguments));\n        TraceShowLeave(aEnvironment, aResult, tr);\n        tr = nullptr;\n    }\n}\n\nListedMacroUserFunction::ListedMacroUserFunction(LispPtr& aParameters) :\n    MacroUserFunction(aParameters)\n{\n}\n\nbool ListedMacroUserFunction::IsArity(unsigned aArity) const\n{\n    return Arity() <= aArity;\n}\n\nvoid ListedMacroUserFunction::Evaluate(LispPtr& aResult,\n                                       LispEnvironment& aEnvironment,\n                                       LispPtr& aArguments) const\n{\n    LispPtr newArgs;\n    LispIterator iter(aArguments);\n    LispPtr* ptr = &newArgs;\n    const int arity = Arity();\n    // TODO: the code would look a lot easier if we could do with only an\n    // iterator\n    for (int i = 0; i < arity && iter.getObj(); ++i, ++iter) {\n        *ptr = (*iter)->Copy();\n        ptr = &((*ptr)->Nixed());\n    }\n\n    if (!iter.getObj()->Nixed()) {\n        *ptr = iter.getObj()->Copy();\n        (*ptr)->Nixed();\n        ++iter;\n        assert(!iter.getObj());\n    } else {\n        LispPtr head(aEnvironment.iList->Copy());\n        head->Nixed() = iter.getObj();\n        *ptr = LispSubList::New(head);\n    }\n\n    MacroUserFunction::Evaluate(aResult, aEnvironment, newArgs);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/mempool.cpp",
    "content": "#include \"yacas/mempool.h\"\n\n#include <algorithm>\n#include <cassert>\n\nMemPool::MemPool(unsigned block_size, unsigned no_blocks) :\n    _block_size(std::max(static_cast<std::size_t>(block_size), sizeof(void*))),\n    _no_blocks(no_blocks),\n    _no_free_blocks(no_blocks),\n    _no_initialized_blocks(0),\n    _pool(new std::uint8_t[_block_size * _no_blocks]),\n    _next_free_block(_pool),\n    _next_pool(nullptr)\n{\n}\n\nMemPool::~MemPool() noexcept\n{\n    assert(_no_free_blocks == _no_blocks);\n\n    delete _next_pool;\n    delete[] _pool;\n}\n\nvoid* MemPool::alloc()\n{\n    if (_no_free_blocks) {\n        if (_no_initialized_blocks <= _no_blocks - _no_free_blocks) {\n            std::uint8_t* p = _pool + _no_initialized_blocks * _block_size;\n            *reinterpret_cast<std::uint8_t**>(p) = p + _block_size;\n            _no_initialized_blocks += 1;\n        }\n\n        void* ret = _next_free_block;\n\n        if (--_no_free_blocks)\n            _next_free_block =\n                *reinterpret_cast<std::uint8_t**>(_next_free_block);\n        else\n            _next_free_block = nullptr;\n\n        return ret;\n    }\n\n    if (!_next_pool)\n        _next_pool = new MemPool(_block_size, _no_blocks);\n\n    return _next_pool->alloc();\n}\n\nvoid MemPool::free(void* p) noexcept\n{\n    if (p >= _pool && p < _pool + _block_size * _no_blocks) {\n        if (_next_free_block) {\n            *reinterpret_cast<std::uint8_t**>(p) = _next_free_block;\n            _next_free_block = static_cast<std::uint8_t*>(p);\n        } else {\n            *reinterpret_cast<std::uint8_t**>(p) = _pool + _no_blocks;\n            _next_free_block = static_cast<std::uint8_t*>(p);\n        }\n        _no_free_blocks += 1;\n    } else {\n        _next_pool->free(p);\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/numbers.cpp",
    "content": "#include \"yacas/numbers.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/standard.h\"\n\n#include <cmath>\n#include <sstream>\n\n//////////////////////////////////////////////////\n///// bits_to_digits and digits_to_bits implementation\n//////////////////////////////////////////////////\n\n// lookup table for transforming the number of digits\n\nstatic const unsigned log2_table_size = 32;\n// report the table size\nunsigned log2_table_range()\n{\n    return log2_table_size;\n}\n\n// A lookup table of Ln(n)/Ln(2) for n = 1 .. 32.\n// Generated by: PrintList(N(Ln(1 .. 32)/Ln(2)), \",\") at precision 40\nconst double log2_table[log2_table_size] = {\n    0.,\n    1.,\n    1.5849625007211561814537389439478165087598,\n    2.,\n    2.3219280948873623478703194294893901758648,\n    2.5849625007211561814537389439478165087598,\n    2.807354922057604107441969317231830808641,\n    3.,\n    3.1699250014423123629074778878956330175196,\n    3.3219280948873623478703194294893901758648,\n    3.4594316186372972561993630467257929587032,\n    3.5849625007211561814537389439478165087598,\n    3.7004397181410921603968126542566947336284,\n    3.807354922057604107441969317231830808641,\n    3.9068905956085185293240583734372066846246,\n    4.,\n    4.0874628412503394082540660108104043540112,\n    4.1699250014423123629074778878956330175196,\n    4.2479275134435854937935194229068344226935,\n    4.3219280948873623478703194294893901758648,\n    4.3923174227787602888957082611796473174008,\n    4.4594316186372972561993630467257929587032,\n    4.5235619560570128722941482441626688444988,\n    4.5849625007211561814537389439478165087598,\n    4.6438561897747246957406388589787803517296,\n    4.7004397181410921603968126542566947336284,\n    4.7548875021634685443612168318434495262794,\n    4.807354922057604107441969317231830808641,\n    4.8579809951275721207197733246279847624768,\n    4.9068905956085185293240583734372066846246,\n    4.9541963103868752088061235991755544235489,\n    5.};\n\n// table look-up of small integer logarithms, for converting the number of\n// digits to binary and back\ndouble log2_table_lookup(unsigned n)\n{\n    if (n <= log2_table_size && n >= BASE2)\n        return log2_table[n - 1];\n\n    std::ostringstream buf;\n    buf << \"log2_table_lookup: error: invalid argument \" << n;\n    throw LispErrGeneric(buf.str());\n}\n\n// convert the number of digits in given base to the number of bits, and back.\n// need to round the number of digits.\n// to make sure that there is no hysteresis, we round upwards on digits_to_bits\n// but round down on bits_to_digits\nunsigned long digits_to_bits(unsigned long digits, unsigned base)\n{\n    return static_cast<unsigned long>(\n        std::ceil(double(digits) * log2_table_lookup(base)));\n}\n\nunsigned long bits_to_digits(unsigned long bits, unsigned base)\n{\n    return static_cast<unsigned long>(\n        std::floor(double(bits) / log2_table_lookup(base)));\n}\n\n//////////////////////////////////////////////////\n///// End of bits_to_digits and digits_to_bits implementation\n//////////////////////////////////////////////////\n"
  },
  {
    "path": "cyacas/libyacas/src/patcher.cpp",
    "content": "#include \"yacas/patcher.h\"\n\n#include \"yacas/lisperror.h\"\n#include \"yacas/lispio.h\"\n#include \"yacas/standard.h\"\n\n#include <algorithm>\n\n/** PatchLoad: patch a string, and write to current output.\n *  Everything between <? and ?> is evaluated. The result\n *  is thrown away.\n */\nvoid PatchLoad(const std::string& content,\n               std::ostream& out,\n               LispEnvironment& env)\n{\n    std::size_t i = 0;\n\n    for (;;) {\n        const std::size_t p = content.find(\"<?\", i);\n\n        const bool found_start_marker = (p != std::string::npos);\n\n        out << content.substr(i, std::min(p, content.length()) - i);\n\n        if (!found_start_marker)\n            break;\n\n        std::size_t q = content.find(\"?>\", p + 2);\n\n        if (q == std::string::npos)\n            throw LispErrGeneric(\"closing tag not found when patching\");\n\n        InputStatus oldstatus = env.iInputStatus;\n        env.iInputStatus.SetTo(\"String\");\n\n        StringInput newInput(content.substr(p + 2, q - p - 2),\n                             env.iInputStatus);\n        LispLocalInput localInput(env, &newInput);\n\n        DoInternalLoad(env, &newInput);\n\n        env.iInputStatus.RestoreFrom(oldstatus);\n\n        i = q + 2;\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/patternclass.cpp",
    "content": "#include \"yacas/patternclass.h\"\n\nPatternClass::PatternClass(YacasPatternPredicateBase* aPatternMatcher) :\n    iPatternMatcher(aPatternMatcher)\n{\n}\n\nPatternClass::~PatternClass()\n{\n    delete iPatternMatcher;\n}\n\nconst char* PatternClass::TypeName() const\n{\n    return \"\\\"Pattern\\\"\";\n}\n\nbool PatternClass::Matches(LispEnvironment& aEnvironment, LispPtr& aArguments)\n{\n    assert(iPatternMatcher);\n    return iPatternMatcher->Matches(aEnvironment, aArguments);\n}\n\nbool PatternClass::Matches(LispEnvironment& aEnvironment, LispPtr* aArguments)\n{\n    assert(iPatternMatcher);\n    return iPatternMatcher->Matches(aEnvironment, aArguments);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/patterns.cpp",
    "content": "#include \"yacas/patterns.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispobject.h\"\n#include \"yacas/mathuserfunc.h\"\n#include \"yacas/standard.h\"\n\n#include <memory>\n\nbool MatchAtom::ArgumentMatches(LispEnvironment& aEnvironment,\n                                LispPtr& aExpression,\n                                LispPtr* arguments) const\n{\n    // If it is a floating point, don't even bother comparing\n    if (!!aExpression)\n        if (aExpression->Number(0))\n            if (!aExpression->Number(0)->IsInt())\n                return false;\n\n    return (iString == aExpression->String());\n}\n\nbool MatchNumber::ArgumentMatches(LispEnvironment& aEnvironment,\n                                  LispPtr& aExpression,\n                                  LispPtr* arguments) const\n{\n    if (aExpression->Number(aEnvironment.Precision()))\n        return iNumber->Equals(*aExpression->Number(aEnvironment.Precision()));\n\n    return false;\n}\n\nbool MatchVariable::ArgumentMatches(LispEnvironment& aEnvironment,\n                                    LispPtr& aExpression,\n                                    LispPtr* arguments) const\n{\n    if (!arguments[iVarIndex]) {\n        arguments[iVarIndex] = aExpression;\n        return true;\n    }\n\n    if (InternalEquals(aEnvironment, aExpression, arguments[iVarIndex]))\n        return true;\n\n    return false;\n}\n\nbool MatchSubList::ArgumentMatches(LispEnvironment& aEnvironment,\n                                   LispPtr& aExpression,\n                                   LispPtr* arguments) const\n{\n    if (!aExpression->SubList())\n        return false;\n\n    LispIterator iter(aExpression);\n    LispObject* pObj = iter.getObj();\n\n    if (!pObj)\n        throw LispErrInvalidArg();\n\n    LispPtr* pPtr = pObj->SubList();\n\n    if (!pPtr)\n        throw LispErrNotList();\n\n    iter = *pPtr;\n\n    const int iNrMatchers = iMatchers.size();\n    for (int i = 0; i < iNrMatchers; i++, ++iter) {\n        if (!iter.getObj())\n            return false;\n        if (!iMatchers[i]->ArgumentMatches(aEnvironment, *iter, arguments))\n            return false;\n    }\n    if (iter.getObj())\n        return false;\n    return true;\n}\n\nint YacasPatternPredicateBase::LookUp(const LispString* aVariable)\n{\n    const std::size_t n = iVariables.size();\n    for (std::size_t i = 0; i < n; ++i)\n        if (iVariables[i] == aVariable)\n            return i;\n\n    iVariables.push_back(aVariable);\n    return iVariables.size() - 1;\n}\n\nconst YacasParamMatcherBase*\nYacasPatternPredicateBase::MakeParamMatcher(LispEnvironment& aEnvironment,\n                                            LispObject* aPattern)\n{\n    if (!aPattern)\n        return nullptr;\n\n    if (aPattern->Number(aEnvironment.Precision()))\n        return new MatchNumber(aPattern->Number(aEnvironment.Precision()));\n\n    // Deal with atoms\n    if (aPattern->String())\n        return new MatchAtom(aPattern->String());\n\n    // Else it must be a sublist\n    if (aPattern->SubList()) {\n        // See if it is a variable template:\n        LispPtr* sublist = aPattern->SubList();\n        assert(sublist);\n\n        int num = InternalListLength(*sublist);\n\n        // variable matcher here...\n        if (num > 1) {\n            LispObject* head = (*sublist);\n            if (head->String() == aEnvironment.HashTable().LookUp(\"_\")) {\n                LispObject* second = head->Nixed();\n                if (second->String()) {\n                    int index = LookUp(second->String());\n\n                    // Make a predicate for the type, if needed\n                    if (num > 2) {\n                        LispPtr third;\n\n                        LispObject* predicate = second->Nixed();\n                        if (predicate->SubList()) {\n                            InternalFlatCopy(third, *predicate->SubList());\n                        } else {\n                            third = (second->Nixed()->Copy());\n                        }\n\n                        LispObject* last = third;\n                        while (!!last->Nixed())\n                            last = last->Nixed();\n\n                        last->Nixed() =\n                            LispAtom::New(aEnvironment, *second->String());\n\n                        iPredicates.push_back(LispPtr(LispSubList::New(third)));\n                    }\n                    return new MatchVariable(index);\n                }\n            }\n        }\n\n        std::vector<const YacasParamMatcherBase*> matchers;\n        matchers.reserve(num);\n        LispIterator iter(*sublist);\n        for (int i = 0; i < num; ++i, ++iter) {\n            matchers.push_back(MakeParamMatcher(aEnvironment, iter.getObj()));\n            assert(matchers[i]);\n        }\n        return new MatchSubList(std::move(matchers));\n    }\n\n    return nullptr;\n}\n\nYacasPatternPredicateBase::YacasPatternPredicateBase(\n    LispEnvironment& aEnvironment, LispPtr& aPattern, LispPtr& aPostPredicate)\n{\n    for (LispIterator iter(aPattern); iter.getObj(); ++iter) {\n        const YacasParamMatcherBase* matcher =\n            MakeParamMatcher(aEnvironment, iter.getObj());\n        assert(matcher != nullptr);\n        iParamMatchers.push_back(matcher);\n    }\n\n    iPredicates.push_back(aPostPredicate);\n}\n\nbool YacasPatternPredicateBase::Matches(LispEnvironment& aEnvironment,\n                                        LispPtr& aArguments)\n{\n    std::unique_ptr<LispPtr[]> arguments(\n        iVariables.empty() ? nullptr : new LispPtr[iVariables.size()]);\n\n    LispIterator iter(aArguments);\n    const std::size_t n = iParamMatchers.size();\n\n    for (std::size_t i = 0; i < n; ++i, ++iter) {\n\n        if (!iter.getObj())\n            return false;\n\n        if (!iParamMatchers[i]->ArgumentMatches(\n                aEnvironment, *iter, arguments.get()))\n            return false;\n    }\n\n    if (iter.getObj())\n        return false;\n\n    {\n        // set the local variables.\n        LispLocalFrame frame(aEnvironment, false);\n\n        SetPatternVariables(aEnvironment, arguments.get());\n\n        // do the predicates\n        if (!CheckPredicates(aEnvironment))\n            return false;\n    }\n\n    // set the local variables for sure now\n    SetPatternVariables(aEnvironment, arguments.get());\n\n    return true;\n}\n\nbool YacasPatternPredicateBase::Matches(LispEnvironment& aEnvironment,\n                                        LispPtr* aArguments)\n{\n    std::unique_ptr<LispPtr[]> arguments(\n        iVariables.empty() ? nullptr : new LispPtr[iVariables.size()]);\n\n    const std::size_t n = iParamMatchers.size();\n    for (std::size_t i = 0; i < n; ++i)\n        if (!iParamMatchers[i]->ArgumentMatches(\n                aEnvironment, aArguments[i], arguments.get()))\n            return false;\n\n    {\n        // set the local variables.\n        LispLocalFrame frame(aEnvironment, false);\n        SetPatternVariables(aEnvironment, arguments.get());\n\n        // do the predicates\n        if (!CheckPredicates(aEnvironment))\n            return false;\n    }\n\n    // set the local variables for sure now\n    SetPatternVariables(aEnvironment, arguments.get());\n\n    return true;\n}\n\nbool YacasPatternPredicateBase::CheckPredicates(LispEnvironment& aEnvironment)\n{\n    const std::size_t n = iPredicates.size();\n    for (std::size_t i = 0; i < n; ++i) {\n        LispPtr pred;\n        aEnvironment.iEvaluator->Eval(aEnvironment, pred, iPredicates[i]);\n        if (IsFalse(aEnvironment, pred)) {\n            return false;\n        }\n        // If the result is not False, it should be True, else probably\n        // something is wrong (the expression returned unevaluated)\n        bool isTrue = IsTrue(aEnvironment, pred);\n        if (!isTrue) {\n#define LIM_AL 60\n            LispString strout;\n\n            aEnvironment.iErrorOutput << \"The predicate\\n\\t\";\n            PrintExpression(strout, iPredicates[i], aEnvironment, LIM_AL);\n            aEnvironment.iErrorOutput << strout;\n            aEnvironment.iErrorOutput << \"\\nevaluated to\\n\\t\";\n            PrintExpression(strout, pred, aEnvironment, LIM_AL);\n            aEnvironment.iErrorOutput << strout << '\\n';\n\n            ShowStack(aEnvironment);\n            throw LispErrMaxRecurseDepthReached();\n        }\n    }\n    return true;\n}\n\nvoid YacasPatternPredicateBase::SetPatternVariables(\n    LispEnvironment& aEnvironment, LispPtr* arguments)\n{\n    const std::size_t n = iVariables.size();\n    for (std::size_t i = 0; i < n; ++i)\n        aEnvironment.NewLocal(iVariables[i], arguments[i]);\n}\n\nYacasPatternPredicateBase::~YacasPatternPredicateBase()\n{\n    for (const YacasParamMatcherBase* p : iParamMatchers)\n        delete p;\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/platmath.cpp",
    "content": "/* Math using the standard library, if the precision is less than 13 */\n#include \"yacas/platmath.h\"\n#include \"yacas/errors.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lispobject.h\"\n#include \"yacas/numbers.h\"\n\n#include <bitset>\n#include <cmath>\n#include <sstream>\n\ndouble GetDouble(LispObject* aInteger)\n{\n    BigNumber* number = aInteger->Number(0);\n    if (!number) {\n        std::ostringstream buf;\n        buf << \"Argument is not a number: \" << aInteger->String();\n        throw LispErrGeneric(buf.str());\n    }\n    return number->Double();\n}\n\nLispObject* Double(LispEnvironment& aEnvironment, double aValue)\n{\n    std::ostringstream buf;\n    buf << aValue;\n    return LispAtom::New(aEnvironment, buf.str());\n}\n\n// LispObject*\n// PlatArcSin(LispEnvironment& aEnvironment, LispObject* int1, int aPrecision)\n// {\n//     return Double(aEnvironment, std::asin(GetDouble(int1)));\n// }\n\n// LispObject*\n// PlatLn(LispEnvironment& aEnvironment, LispObject* int1, int aPrecision)\n// {\n//     return Double(aEnvironment, std::log(GetDouble(int1)));\n// }\n\n// LispObject* PlatPower(LispEnvironment& aEnvironment,\n//                       LispObject* int1,\n//                       LispObject* int2,\n//                       int aPrecision)\n// {\n//     return Double(aEnvironment, std::pow(GetDouble(int1), GetDouble(int2)));\n// }\n\n// LispObject* PlatDiv(LispEnvironment& aEnvironment,\n//                     LispObject* int1,\n//                     LispObject* int2,\n//                     int aPrecision)\n// {\n//     return Double(aEnvironment,\n//                   ((long)GetDouble(int1)) / ((long)GetDouble(int2)));\n// }\n\nnamespace {\n    static const std::size_t MAX_SMALL_PRIME = 65537;\n\n    static std::bitset<MAX_SMALL_PRIME / 2 + 1> _primes_table;\n\n    static class InitPrimesTable {\n    public:\n        InitPrimesTable();\n    } _init_primes_table;\n\n    InitPrimesTable::InitPrimesTable()\n    {\n        for (std::size_t i = 3; i < MAX_SMALL_PRIME; i += 2) {\n            if (_primes_table.test(i / 2))\n                continue;\n            for (std::size_t j = 3; j < MAX_SMALL_PRIME / i; j += 2)\n                _primes_table.set((i * j) / 2);\n        }\n    }\n}\n\nunsigned primes_table_check(unsigned long p)\n{\n    if (p == 0)\n        return MAX_SMALL_PRIME;\n\n    if (p == 2)\n        return 1;\n\n    if (p < 2 || p > MAX_SMALL_PRIME || (p & 1) == 0)\n        return 0;\n\n    return !_primes_table.test(p / 2);\n}\n\nLispObject*\nPlatIsPrime(LispEnvironment& aEnvironment, LispObject* int1, int aPrecision)\n{\n    return Double(aEnvironment,\n                  primes_table_check((unsigned long)(GetDouble(int1))));\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/standard.cpp",
    "content": "// \\file standard.cpp\n// Implementation of some standard lisp operations\n//\n#include \"yacas/standard.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lisperror.h\"\n\n#include \"yacas/infixparser.h\"\n#include \"yacas/lispenvironment.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/lispio.h\"\n#include \"yacas/numbers.h\"\n#include \"yacas/platfileio.h\"\n#include \"yacas/stringio.h\"\n#include \"yacas/tokenizer.h\"\n\n#include <sstream>\n\nbool InternalIsList(const LispEnvironment& env, const LispPtr& aPtr)\n{\n    if (!aPtr)\n        return false;\n    if (!aPtr->SubList())\n        return false;\n    if (!(*aPtr->SubList()))\n        return false;\n    if ((*aPtr->SubList())->String() != env.iList->String())\n        return false;\n    return true;\n}\n\nbool InternalIsString(const LispString* aOriginal)\n{\n    return aOriginal && aOriginal->length() > 1 && aOriginal->front() == '\\\"' &&\n           aOriginal->back() == '\\\"';\n}\n\n/* TODO: in documenting the choices made in the C++ engine, perhaps document why\n   I pass objects that should contain the result by reference. Result string\n   passed in by reference to avoid copy-constructors etcetera (allowing the code\n   to share the same LispString in different places).\n */\nstd::string InternalUnstringify(const std::string& s)\n{\n    /*TODO: should these not be checked also higher up, and should this not be\n     * an assert at this level? ideally this function should be as efficient as\n     * possible (allowing for a code generator to generate compiled code that\n     * calls this function immediately. The compiler could prove that the input\n     * is valid, so the checks would not be needed here in a non-debug run).\n     *\n     * Also do not forget to make the change in the Java version then, and find\n     * the other places where this is relevant.\n     */\n    if (s.size() < 2 || s.front() != '\\\"' || s.back() != '\\\"')\n        throw LispErrInvalidArg();\n\n    return std::string(s.c_str() + 1, s.size() - 2);\n}\n\nint InternalAsciiToInt(const LispString& aString)\n{\n    const char* ptr = aString.c_str();\n\n    if (!IsNumber(ptr, false))\n        throw LispErrInvalidArg();\n\n    return std::stoi(aString);\n}\n\nbool IsNumber(const std::string& s, bool aAllowFloat)\n{\n    const char* ptr = s.c_str();\n\n    if (*ptr == '-' || *ptr == '+')\n        ptr++;\n\n    int nrDigits = 0;\n    int index = 0;\n    while (std::isdigit(ptr[index])) {\n        nrDigits++;\n        index++;\n    }\n\n    if (ptr[index] == '.') {\n        if (!aAllowFloat)\n            return false;\n        index++;\n        while (std::isdigit(ptr[index])) {\n            nrDigits++;\n            index++;\n        }\n    }\n    if (nrDigits == 0)\n        return false;\n    if (ptr[index] == 'e' || ptr[index] == 'E') {\n        if (!aAllowFloat)\n            return false;\n        index++;\n        if (ptr[index] == '-' || ptr[index] == '+')\n            index++;\n        while (ptr[index] >= '0' && ptr[index] <= '9')\n            index++;\n    }\n    if (ptr[index] != '\\0')\n        return false;\n    return true;\n}\n\nvoid InternalNth(LispPtr& aResult, const LispPtr& aArg, int n)\n{\n    if (n < 0 || !aArg || !aArg->SubList())\n        throw LispErrInvalidArg();\n\n    LispIterator iter(*aArg->SubList());\n\n    while (n > 0) {\n        if (!iter.getObj())\n            throw LispErrInvalidArg();\n\n        ++iter;\n        n--;\n    }\n\n    if (!iter.getObj())\n        throw LispErrInvalidArg();\n\n    aResult = (iter.getObj()->Copy());\n}\n\nvoid InternalTail(LispPtr& aResult, const LispPtr& aArg)\n{\n    if (!aArg)\n        throw LispErrInvalidArg();\n\n    LispPtr* iter = aArg->SubList();\n\n    if (!iter || !*iter)\n        throw LispErrInvalidArg();\n\n    aResult = (LispSubList::New((*iter)->Nixed()));\n}\n\nvoid InternalReverseList(LispPtr& aResult, const LispPtr& aOriginal)\n{\n    LispPtr iter(aOriginal);\n    LispPtr previous;\n    LispPtr tail(aOriginal);\n\n    while (!!iter) {\n        tail = iter->Nixed();\n        iter->Nixed() = (previous);\n        previous = iter;\n        iter = tail;\n    }\n    aResult = previous;\n}\n\nvoid InternalFlatCopy(LispPtr& aResult, const LispPtr& aOriginal)\n{\n    LispConstIterator orig(aOriginal);\n    LispIterator res(aResult);\n\n    while (orig.getObj()) {\n        (*res) = (orig.getObj()->Copy());\n        ++orig;\n        ++res;\n    }\n}\n\nstd::size_t InternalListLength(const LispPtr& aOriginal)\n{\n    LispConstIterator iter(aOriginal);\n    std::size_t length = 0;\n    while (iter.getObj()) {\n        ++iter;\n        length++;\n    }\n    return length;\n}\n\nbool InternalStrictTotalOrder(const LispEnvironment& env,\n                              const LispPtr& e1,\n                              const LispPtr& e2)\n{\n    if (e1.ptr() == e2.ptr())\n        return false;\n\n    if (!e1.ptr() && e2.ptr())\n        return true;\n\n    if (e1.ptr() && !e2.ptr())\n        return false;\n\n    const BigNumber* n1 = e1->Number(env.Precision());\n    const BigNumber* n2 = e2->Number(env.Precision());\n\n    if (n1 && !n2)\n        return true;\n\n    if (!n1 && n2)\n        return false;\n\n    if (n1 && n2) {\n        if (n1->LessThan(*n2))\n            return true;\n\n        if (!n1->Equals(*n2))\n            return false;\n\n        return InternalStrictTotalOrder(env, e1->Nixed(), e2->Nixed());\n    }\n\n    const LispString* s1 = e1->String();\n    const LispString* s2 = e2->String();\n\n    if (s1 && !s2)\n        return true;\n\n    if (!s1 && s2)\n        return false;\n\n    if (s1 && s2) {\n        const int c = s1->compare(*s2);\n\n        if (c)\n            return c < 0;\n\n        return InternalStrictTotalOrder(env, e1->Nixed(), e2->Nixed());\n    }\n\n    LispPtr* l1 = e1->SubList();\n    LispPtr* l2 = e2->SubList();\n\n    if (!l1 && l2)\n        return true;\n\n    if (l1 && !l2)\n        return false;\n\n    if (l1 && l2) {\n        LispIterator i1(*l1);\n        LispIterator i2(*l2);\n\n        while (i1.getObj() && i2.getObj()) {\n            const LispPtr& p1 = *i1;\n            const LispPtr& p2 = *i2;\n\n            if (InternalEquals(env, p1, p2)) {\n                ++i1;\n                ++i2;\n\n                continue;\n            }\n\n            return InternalStrictTotalOrder(env, p1, p2);\n        }\n\n        if (i1.getObj())\n            return false;\n\n        if (i2.getObj())\n            return true;\n\n        return false;\n    }\n\n    // FIXME: deal with generics\n    //    GenericClass* g1 = e1->Generic();\n    //    GenericClass* g2 = e2->Generic();\n    //\n    return false;\n}\n\nbool InternalEquals(const LispEnvironment& aEnvironment,\n                    const LispPtr& aExpression1,\n                    const LispPtr& aExpression2)\n{\n    // Handle pointers to same, or nullptr\n    if (aExpression1.ptr() ==\n        aExpression2.ptr()) // compare pointers to LispObject\n        return true;\n\n    if (!aExpression1.ptr() || !aExpression2.ptr())\n        return false;\n\n    /*TODO This code would be better, if BigNumber::Equals works*/\n\n    BigNumber* n1 = aExpression1->Number(aEnvironment.Precision());\n    BigNumber* n2 = aExpression2->Number(aEnvironment.Precision());\n    if (!(!n1 && !n2)) {\n        if (n1 == n2) {\n            return true;\n        }\n        if (!n1)\n            return false;\n        if (!n2)\n            return false;\n        if (n1->Equals(*n2))\n            return true;\n        // this should be enabled\n        return false;\n    }\n\n    // Pointers to strings should be the same\n    if (aExpression1->String() != aExpression2->String()) {\n        return false;\n    }\n\n    // Handle same sublists, or nullptr\n    if (aExpression1->SubList() == aExpression2->SubList()) {\n        return true;\n    }\n\n    // Now check the sublists\n    if (aExpression1->SubList()) {\n        if (!aExpression2->SubList()) {\n            return false;\n        }\n        LispIterator iter1(*aExpression1->SubList());\n        LispIterator iter2(*aExpression2->SubList());\n\n        while (iter1.getObj() && iter2.getObj()) {\n            // compare two list elements\n            if (!InternalEquals(aEnvironment, *iter1, *iter2)) {\n                return false;\n            }\n\n            // Step to next\n            ++iter1;\n            ++iter2;\n        }\n        // Lists don't have the same length\n        if (iter1.getObj() != iter2.getObj())\n            return false;\n\n        // Same!\n        return true;\n    }\n\n    // expressions sublists are not the same!\n    return false;\n}\n\nvoid DoInternalLoad(LispEnvironment& aEnvironment, LispInput* aInput)\n{\n    LispLocalInput localInput(aEnvironment, aInput);\n\n    // TODO make \"EndOfFile\" a global thing\n    // read-parse-eval to the end of file\n    const LispString* eof = aEnvironment.HashTable().LookUp(\"EndOfFile\");\n    bool endoffile = false;\n\n    LispTokenizer tok;\n    InfixParser parser(tok,\n                       *aEnvironment.CurrentInput(),\n                       aEnvironment,\n                       aEnvironment.PreFix(),\n                       aEnvironment.InFix(),\n                       aEnvironment.PostFix(),\n                       aEnvironment.Bodied());\n\n    while (!endoffile) {\n        LispPtr readIn;\n        // Read expression\n        parser.Parse(readIn);\n\n        if (!readIn)\n            throw LispErrReadingFile();\n\n        // Check for end of file\n        if (readIn->String() == eof) {\n            endoffile = true;\n        }\n        // Else evaluate\n        else {\n            LispPtr result;\n            aEnvironment.iEvaluator->Eval(aEnvironment, result, readIn);\n        }\n    }\n}\n\nvoid InternalLoad(LispEnvironment& aEnvironment, const std::string& aFileName)\n{\n    const std::string oper = InternalUnstringify(aFileName);\n\n    InputStatus oldstatus = aEnvironment.iInputStatus;\n    aEnvironment.iInputStatus.SetTo(oper);\n\n    // TODO make the file api platform independent!!!!\n    // Open file\n    LispLocalFile localFP(\n        aEnvironment, oper, true, aEnvironment.iInputDirectories);\n\n    if (!localFP.stream.is_open())\n        throw LispErrFileNotFound();\n\n    StdFileInput newInput(localFP, aEnvironment.iInputStatus);\n    DoInternalLoad(aEnvironment, &newInput);\n\n    aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n}\n\nvoid InternalUse(LispEnvironment& aEnvironment, const std::string& aFileName)\n{\n    LispDefFile* def = aEnvironment.DefFiles().File(aFileName);\n    if (!def->IsLoaded()) {\n        def->SetLoaded();\n\n        for (const LispString* s : def->symbols)\n            aEnvironment.UnProtect(s);\n\n        InternalLoad(aEnvironment, aFileName);\n\n        for (const LispString* s : def->symbols)\n            aEnvironment.Protect(s);\n    }\n}\n\nvoid InternalApplyString(LispEnvironment& aEnvironment,\n                         LispPtr& aResult,\n                         const LispString* aOperator,\n                         LispPtr& aArgs)\n{\n    if (!InternalIsString(aOperator))\n        throw LispErrNotString();\n\n    LispObject* head =\n        LispAtom::New(aEnvironment, *SymbolName(aEnvironment, *aOperator));\n    head->Nixed() = (aArgs);\n    LispPtr body(LispSubList::New(head));\n    aEnvironment.iEvaluator->Eval(aEnvironment, aResult, body);\n}\n\nvoid InternalApplyPure(LispPtr& oper,\n                       LispPtr& args2,\n                       LispPtr& aResult,\n                       LispEnvironment& aEnvironment)\n{\n    LispPtr* chk1 = oper->SubList();\n\n    if (!chk1)\n        throw LispErrInvalidArg();\n\n    LispPtr oper2((*chk1)->Nixed());\n\n    if (!oper2)\n        throw LispErrInvalidArg();\n\n    LispPtr body(oper2->Nixed());\n\n    if (!body)\n        throw LispErrInvalidArg();\n\n    LispPtr* chk2 = oper2->SubList();\n\n    if (!chk2 || !*chk2)\n        throw LispErrInvalidArg();\n\n    oper2 = ((*chk2)->Nixed());\n\n    LispLocalFrame frame(aEnvironment, false);\n\n    while (!!oper2) {\n        if (!args2)\n            throw LispErrInvalidArg();\n\n        const LispString* var = oper2->String();\n\n        if (!var)\n            throw LispErrInvalidArg();\n\n        LispPtr newly(args2->Copy());\n\n        aEnvironment.NewLocal(var, newly);\n\n        oper2 = (oper2->Nixed());\n\n        args2 = (args2->Nixed());\n    }\n\n    if (args2)\n        throw LispErrInvalidArg();\n\n    aEnvironment.iEvaluator->Eval(aEnvironment, aResult, body);\n}\n\nvoid InternalEvalString(LispEnvironment& aEnvironment,\n                        LispPtr& aResult,\n                        const char* aString)\n{\n    LispString full(aString);\n    full.push_back(';');\n    StringInput input(full, aEnvironment.iInputStatus);\n    LispPtr lispexpr;\n    LispTokenizer& tok = *aEnvironment.iCurrentTokenizer;\n    InfixParser parser(tok,\n                       input,\n                       aEnvironment,\n                       aEnvironment.PreFix(),\n                       aEnvironment.InFix(),\n                       aEnvironment.PostFix(),\n                       aEnvironment.Bodied());\n    parser.Parse(lispexpr);\n\n    aEnvironment.iEvaluator->Eval(aEnvironment, aResult, lispexpr);\n}\n\nLispObject* operator+(const LispObjectAdder& left, const LispObjectAdder& right)\n{\n    LispObject* trav = left.iPtr;\n    while (!!trav->Nixed()) {\n        trav = trav->Nixed();\n    }\n    trav->Nixed() = (right.iPtr);\n    return left.iPtr;\n}\n\nvoid ParseExpression(LispPtr& aResult,\n                     const char* aString,\n                     LispEnvironment& aEnvironment)\n{\n    LispString full(aString);\n    full.push_back(';');\n    StringInput input(full, aEnvironment.iInputStatus);\n    aEnvironment.iInputStatus.SetTo(\"String\");\n    LispTokenizer& tok = *aEnvironment.iCurrentTokenizer;\n    InfixParser parser(tok,\n                       input,\n                       aEnvironment,\n                       aEnvironment.PreFix(),\n                       aEnvironment.InFix(),\n                       aEnvironment.PostFix(),\n                       aEnvironment.Bodied());\n    parser.Parse(aResult);\n}\n\nvoid ReturnUnEvaluated(LispPtr& aResult,\n                       LispPtr& aArguments,\n                       LispEnvironment& aEnvironment)\n{\n    LispPtr full(aArguments->Copy());\n    aResult = (LispSubList::New(full));\n\n    LispIterator iter(aArguments);\n    ++iter;\n\n    while (iter.getObj()) {\n        LispPtr next;\n        aEnvironment.iEvaluator->Eval(aEnvironment, next, *iter);\n        full->Nixed() = (next);\n        full = (next);\n        ++iter;\n    }\n    full->Nixed() = (nullptr);\n}\n\nvoid PrintExpression(LispString& aResult,\n                     LispPtr& aExpression,\n                     LispEnvironment& aEnvironment,\n                     std::size_t aMaxChars)\n{\n    std::ostringstream stream;\n    InfixPrinter infixprinter(aEnvironment.PreFix(),\n                              aEnvironment.InFix(),\n                              aEnvironment.PostFix(),\n                              aEnvironment.Bodied());\n    infixprinter.Print(aExpression, stream, aEnvironment);\n    aResult.assign(stream.str());\n    if (aMaxChars > 0 && aResult.size() > aMaxChars) {\n        aResult.resize(aMaxChars - 3);\n        aResult += \"...\";\n    }\n}\n\nconst LispString* SymbolName(LispEnvironment& aEnvironment,\n                             const std::string& aSymbol)\n{\n    if (aSymbol[0] == '\\\"')\n        return aEnvironment.HashTable().LookUp(\n            aSymbol.substr(1, aSymbol.size() - 2));\n    else\n        return aEnvironment.HashTable().LookUp(aSymbol);\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/stdfileio.cpp",
    "content": "#include \"yacas/platfileio.h\"\n\n#include <memory>\n\n#ifdef _WIN32\n#    define MAP_TO_WIN32_PATH_SEPARATOR\n#endif // WIN32\n\nstatic void MapPathSeparators(std::string& filename)\n{\n#ifdef MAP_TO_WIN32_PATH_SEPARATOR\n    for (std::size_t i = 0; i < filename.size(); ++i)\n        if (filename[i] == '/')\n            filename[i] = '\\\\';\n#endif\n}\n\nStdFileInput::StdFileInput(std::istream& stream, InputStatus& aStatus) :\n    LispInput(aStatus),\n    _stream(stream)\n{\n}\n\nStdFileInput::StdFileInput(LispLocalFile& file, InputStatus& aStatus) :\n    LispInput(aStatus),\n    _stream(file.stream),\n    _position(0),\n    _cp_ready(false)\n{\n}\n\nchar32_t StdFileInput::Next()\n{\n    if (!_cp_ready)\n        _get();\n\n    if (EndOfStream())\n        return std::char_traits<char32_t>::eof();\n\n    _cp_ready = false;\n    _position += 1;\n\n    return _cp;\n}\n\nchar32_t StdFileInput::Peek()\n{\n    if (EndOfStream())\n        return std::char_traits<char32_t>::eof();\n\n    if (!_cp_ready)\n        _get();\n\n    return _cp;\n}\n\nvoid StdFileInput::Rewind()\n{\n    _stream.seekg(0);\n    _position = 0;\n    _cp_ready = false;\n}\n\nbool StdFileInput::EndOfStream() const\n{\n    if (_stream.eof())\n        return true;\n\n    if (!_cp_ready)\n        _get();\n\n    return _stream.eof();\n}\n\nstd::size_t StdFileInput::Position() const\n{\n    return _position;\n}\n\nvoid StdFileInput::SetPosition(std::size_t n)\n{\n    Rewind();\n\n    for (std::size_t i = 0; i < n; ++i)\n        Next();\n}\n\nvoid StdFileInput::_get() const\n{\n    char p[4];\n    char* q = p;\n\n    *q++ = _stream.get();\n\n    while (!_stream.eof() && !utf8::is_valid(p, q))\n        *q++ = _stream.get();\n\n    if (_stream.eof())\n        return;\n\n    utf8::utf8to32(p, q, &_cp);\n\n    if (_cp == '\\n')\n        iStatus.NextLine();\n\n    _cp_ready = true;\n}\n\nstd::string InternalFindFile(const std::string& fname,\n                             const std::vector<std::string>& dirs)\n{\n    std::string path(fname);\n\n    MapPathSeparators(path);\n\n    std::unique_ptr<std::ifstream> f(new std::ifstream(path));\n    for (std::size_t i = 0; !f->good() && i < dirs.size(); ++i) {\n        path = dirs[i] + fname;\n        MapPathSeparators(path);\n        f.reset(new std::ifstream(path));\n    }\n\n    if (!f->good())\n        return \"\";\n\n    return path;\n}\n\nLispLocalFile::LispLocalFile(LispEnvironment& environment,\n                             const std::string& fname,\n                             bool read,\n                             const std::vector<std::string>& dirs) :\n    environment(environment)\n{\n    std::string othername;\n\n    if (read) {\n        othername = fname;\n        MapPathSeparators(othername);\n\n        stream.open(othername, std::ios_base::in | std::ios_base::binary);\n\n        for (std::size_t i = 0; !stream.is_open() && i < dirs.size(); ++i) {\n            othername = dirs[i];\n            othername += fname;\n            MapPathSeparators(othername);\n            stream.open(othername, std::ios_base::in | std::ios_base::binary);\n        }\n    } else {\n        othername = fname;\n        MapPathSeparators(othername);\n        stream.open(othername, std::ios_base::out);\n    }\n}\n\nLispLocalFile::~LispLocalFile()\n{\n    if (stream.is_open())\n        stream.close();\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/stringio.cpp",
    "content": "#include \"yacas/stringio.h\"\n\nStringInput::StringInput(const std::string& aString, InputStatus& aStatus) :\n    LispInput(aStatus),\n    _string(aString),\n    _current(_string.begin())\n{\n}\n\nchar32_t StringInput::Next()\n{\n    if (EndOfStream())\n        return std::char_traits<char32_t>::eof();\n\n    const char32_t cp =\n        utf8::next(_current, std::string::const_iterator(_string.end()));\n\n    if (cp == '\\n')\n        iStatus.NextLine();\n\n    return cp;\n}\n\nchar32_t StringInput::Peek()\n{\n    if (EndOfStream())\n        return std::char_traits<char32_t>::eof();\n\n    return utf8::peek_next(_current,\n                           std::string::const_iterator(_string.end()));\n}\n\nbool StringInput::EndOfStream() const\n{\n    return _current == _string.end();\n}\n\nstd::size_t StringInput::Position() const\n{\n    return utf8::distance(_string.begin(), _current);\n}\n\nvoid StringInput::SetPosition(std::size_t n)\n{\n    _current = _string.begin();\n    utf8::advance(_current, n, std::string::const_iterator(_string.end()));\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/substitute.cpp",
    "content": "#include \"yacas/substitute.h\"\n#include \"yacas/lispatom.h\"\n#include \"yacas/lispeval.h\"\n#include \"yacas/standard.h\"\n\n// Subst, Substitute, FullSubstitute\nvoid InternalSubstitute(LispPtr& aTarget,\n                        LispPtr& aSource,\n                        SubstBehaviourBase& aBehaviour)\n{\n    LispObject* object = aSource;\n    assert(object);\n    if (!aBehaviour.Matches(aTarget, aSource)) {\n        LispPtr* oldList = object->SubList();\n        if (oldList) {\n            LispPtr newList;\n            LispPtr* next = &newList;\n            while (!!(*oldList)) {\n                InternalSubstitute(*next, *oldList, aBehaviour);\n                oldList = &(*oldList)->Nixed();\n                next = &(*next)->Nixed();\n            }\n\n            aTarget = (LispSubList::New(newList));\n        } else {\n            aTarget = (object->Copy());\n        }\n    }\n}\n\nSubstBehaviour::SubstBehaviour(LispEnvironment& aEnvironment,\n                               LispPtr& aToMatch,\n                               LispPtr& aToReplaceWith) :\n    iEnvironment(aEnvironment),\n    iToMatch(aToMatch),\n    iToReplaceWith(aToReplaceWith)\n{\n}\n\nbool SubstBehaviour::Matches(LispPtr& aResult, LispPtr& aElement)\n{\n    if (InternalEquals(iEnvironment, aElement, iToMatch)) {\n        aResult = iToReplaceWith->Copy();\n        return true;\n    }\n    return false;\n}\n\nLocalSymbolBehaviour::LocalSymbolBehaviour(\n    LispEnvironment& aEnvironment,\n    const std::vector<const LispString*>&& aOriginalNames,\n    const std::vector<const LispString*>&& aNewNames) :\n    iEnvironment(aEnvironment),\n    iOriginalNames(aOriginalNames),\n    iNewNames(aNewNames)\n{\n}\n\nbool LocalSymbolBehaviour::Matches(LispPtr& aResult, LispPtr& aElement)\n{\n    const LispString* name = aElement->String();\n    if (!name)\n        return false;\n\n    const std::size_t iNrNames = iOriginalNames.size();\n    for (std::size_t i = 0; i < iNrNames; ++i)\n        if (name == iOriginalNames[i]) {\n            aResult = LispAtom::New(iEnvironment, *iNewNames[i]);\n            return true;\n        }\n    return false;\n}\n\nbool BackQuoteBehaviour::Matches(LispPtr& aResult, LispPtr& aElement)\n{\n    if (!aElement->SubList())\n        return false;\n    LispObject* ptr = (*aElement->SubList());\n    if (!ptr)\n        return false;\n    if (!ptr->String())\n        return false;\n\n    if (*ptr->String() == \"`\") {\n        aResult = (aElement);\n        return true;\n    }\n\n    if (*ptr->String() != \"@\")\n        return false;\n\n    ptr = ptr->Nixed();\n    if (!ptr)\n        return false;\n\n    if (ptr->String()) {\n        LispPtr cur(ptr);\n        /*\n                LispPtr result;\n                iEnvironment.iEvaluator->Eval(iEnvironment, result, cur);\n                InternalSubstitute(aResult, result,*this);\n        */\n        iEnvironment.iEvaluator->Eval(iEnvironment, aResult, cur);\n        return true;\n    } else {\n        ptr = (*ptr->SubList());\n        LispPtr cur(ptr);\n        LispPtr args(ptr->Nixed());\n        LispPtr result;\n        iEnvironment.iEvaluator->Eval(iEnvironment, result, cur);\n        result->Nixed() = (args);\n        LispPtr result2(LispSubList::New(result));\n        InternalSubstitute(aResult, result2, *this);\n        return true;\n    }\n    return false;\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/tokenizer.cpp",
    "content": "#include \"yacas/tokenizer.h\"\n\n#include \"yacas/lisperror.h\"\n\n#include \"yacas/utf8.h\"\n\n#include <unordered_set>\n\nnamespace {\n    static const char symbolics[] = \"~`!@#$^&*-=+:<>?/\\\\|\";\n\n    // Ll and Lu categories combined\n    // see http://www.fileformat.info/info/unicode/category/index.htm\n    static const std::unordered_set<std::uint32_t> letters = {\n        0x41,    0x42,    0x43,    0x44,    0x45,    0x46,    0x47,    0x48,\n        0x49,    0x4a,    0x4b,    0x4c,    0x4d,    0x4e,    0x4f,    0x50,\n        0x51,    0x52,    0x53,    0x54,    0x55,    0x56,    0x57,    0x58,\n        0x59,    0x5a,    0x61,    0x62,    0x63,    0x64,    0x65,    0x66,\n        0x67,    0x68,    0x69,    0x6a,    0x6b,    0x6c,    0x6d,    0x6e,\n        0x6f,    0x70,    0x71,    0x72,    0x73,    0x74,    0x75,    0x76,\n        0x77,    0x78,    0x79,    0x7a,    0xb5,    0xc0,    0xc1,    0xc2,\n        0xc3,    0xc4,    0xc5,    0xc6,    0xc7,    0xc8,    0xc9,    0xca,\n        0xcb,    0xcc,    0xcd,    0xce,    0xcf,    0xd0,    0xd1,    0xd2,\n        0xd3,    0xd4,    0xd5,    0xd6,    0xd8,    0xd9,    0xda,    0xdb,\n        0xdc,    0xdd,    0xde,    0xdf,    0xe0,    0xe1,    0xe2,    0xe3,\n        0xe4,    0xe5,    0xe6,    0xe7,    0xe8,    0xe9,    0xea,    0xeb,\n        0xec,    0xed,    0xee,    0xef,    0xf0,    0xf1,    0xf2,    0xf3,\n        0xf4,    0xf5,    0xf6,    0xf8,    0xf9,    0xfa,    0xfb,    0xfc,\n        0xfd,    0xfe,    0xff,    0x100,   0x101,   0x102,   0x103,   0x104,\n        0x105,   0x106,   0x107,   0x108,   0x109,   0x10a,   0x10b,   0x10c,\n        0x10d,   0x10e,   0x10f,   0x110,   0x111,   0x112,   0x113,   0x114,\n        0x115,   0x116,   0x117,   0x118,   0x119,   0x11a,   0x11b,   0x11c,\n        0x11d,   0x11e,   0x11f,   0x120,   0x121,   0x122,   0x123,   0x124,\n        0x125,   0x126,   0x127,   0x128,   0x129,   0x12a,   0x12b,   0x12c,\n        0x12d,   0x12e,   0x12f,   0x130,   0x131,   0x132,   0x133,   0x134,\n        0x135,   0x136,   0x137,   0x138,   0x139,   0x13a,   0x13b,   0x13c,\n        0x13d,   0x13e,   0x13f,   0x140,   0x141,   0x142,   0x143,   0x144,\n        0x145,   0x146,   0x147,   0x148,   0x149,   0x14a,   0x14b,   0x14c,\n        0x14d,   0x14e,   0x14f,   0x150,   0x151,   0x152,   0x153,   0x154,\n        0x155,   0x156,   0x157,   0x158,   0x159,   0x15a,   0x15b,   0x15c,\n        0x15d,   0x15e,   0x15f,   0x160,   0x161,   0x162,   0x163,   0x164,\n        0x165,   0x166,   0x167,   0x168,   0x169,   0x16a,   0x16b,   0x16c,\n        0x16d,   0x16e,   0x16f,   0x170,   0x171,   0x172,   0x173,   0x174,\n        0x175,   0x176,   0x177,   0x178,   0x179,   0x17a,   0x17b,   0x17c,\n        0x17d,   0x17e,   0x17f,   0x180,   0x181,   0x182,   0x183,   0x184,\n        0x185,   0x186,   0x187,   0x188,   0x189,   0x18a,   0x18b,   0x18c,\n        0x18d,   0x18e,   0x18f,   0x190,   0x191,   0x192,   0x193,   0x194,\n        0x195,   0x196,   0x197,   0x198,   0x199,   0x19a,   0x19b,   0x19c,\n        0x19d,   0x19e,   0x19f,   0x1a0,   0x1a1,   0x1a2,   0x1a3,   0x1a4,\n        0x1a5,   0x1a6,   0x1a7,   0x1a8,   0x1a9,   0x1aa,   0x1ab,   0x1ac,\n        0x1ad,   0x1ae,   0x1af,   0x1b0,   0x1b1,   0x1b2,   0x1b3,   0x1b4,\n        0x1b5,   0x1b6,   0x1b7,   0x1b8,   0x1b9,   0x1ba,   0x1bc,   0x1bd,\n        0x1be,   0x1bf,   0x1c4,   0x1c6,   0x1c7,   0x1c9,   0x1ca,   0x1cc,\n        0x1cd,   0x1ce,   0x1cf,   0x1d0,   0x1d1,   0x1d2,   0x1d3,   0x1d4,\n        0x1d5,   0x1d6,   0x1d7,   0x1d8,   0x1d9,   0x1da,   0x1db,   0x1dc,\n        0x1dd,   0x1de,   0x1df,   0x1e0,   0x1e1,   0x1e2,   0x1e3,   0x1e4,\n        0x1e5,   0x1e6,   0x1e7,   0x1e8,   0x1e9,   0x1ea,   0x1eb,   0x1ec,\n        0x1ed,   0x1ee,   0x1ef,   0x1f0,   0x1f1,   0x1f3,   0x1f4,   0x1f5,\n        0x1f6,   0x1f7,   0x1f8,   0x1f9,   0x1fa,   0x1fb,   0x1fc,   0x1fd,\n        0x1fe,   0x1ff,   0x200,   0x201,   0x202,   0x203,   0x204,   0x205,\n        0x206,   0x207,   0x208,   0x209,   0x20a,   0x20b,   0x20c,   0x20d,\n        0x20e,   0x20f,   0x210,   0x211,   0x212,   0x213,   0x214,   0x215,\n        0x216,   0x217,   0x218,   0x219,   0x21a,   0x21b,   0x21c,   0x21d,\n        0x21e,   0x21f,   0x220,   0x221,   0x222,   0x223,   0x224,   0x225,\n        0x226,   0x227,   0x228,   0x229,   0x22a,   0x22b,   0x22c,   0x22d,\n        0x22e,   0x22f,   0x230,   0x231,   0x232,   0x233,   0x234,   0x235,\n        0x236,   0x237,   0x238,   0x239,   0x23a,   0x23b,   0x23c,   0x23d,\n        0x23e,   0x23f,   0x240,   0x241,   0x242,   0x243,   0x244,   0x245,\n        0x246,   0x247,   0x248,   0x249,   0x24a,   0x24b,   0x24c,   0x24d,\n        0x24e,   0x24f,   0x250,   0x251,   0x252,   0x253,   0x254,   0x255,\n        0x256,   0x257,   0x258,   0x259,   0x25a,   0x25b,   0x25c,   0x25d,\n        0x25e,   0x25f,   0x260,   0x261,   0x262,   0x263,   0x264,   0x265,\n        0x266,   0x267,   0x268,   0x269,   0x26a,   0x26b,   0x26c,   0x26d,\n        0x26e,   0x26f,   0x270,   0x271,   0x272,   0x273,   0x274,   0x275,\n        0x276,   0x277,   0x278,   0x279,   0x27a,   0x27b,   0x27c,   0x27d,\n        0x27e,   0x27f,   0x280,   0x281,   0x282,   0x283,   0x284,   0x285,\n        0x286,   0x287,   0x288,   0x289,   0x28a,   0x28b,   0x28c,   0x28d,\n        0x28e,   0x28f,   0x290,   0x291,   0x292,   0x293,   0x295,   0x296,\n        0x297,   0x298,   0x299,   0x29a,   0x29b,   0x29c,   0x29d,   0x29e,\n        0x29f,   0x2a0,   0x2a1,   0x2a2,   0x2a3,   0x2a4,   0x2a5,   0x2a6,\n        0x2a7,   0x2a8,   0x2a9,   0x2aa,   0x2ab,   0x2ac,   0x2ad,   0x2ae,\n        0x2af,   0x370,   0x371,   0x372,   0x373,   0x376,   0x377,   0x37b,\n        0x37c,   0x37d,   0x37f,   0x386,   0x388,   0x389,   0x38a,   0x38c,\n        0x38e,   0x38f,   0x390,   0x391,   0x392,   0x393,   0x394,   0x395,\n        0x396,   0x397,   0x398,   0x399,   0x39a,   0x39b,   0x39c,   0x39d,\n        0x39e,   0x39f,   0x3a0,   0x3a1,   0x3a3,   0x3a4,   0x3a5,   0x3a6,\n        0x3a7,   0x3a8,   0x3a9,   0x3aa,   0x3ab,   0x3ac,   0x3ad,   0x3ae,\n        0x3af,   0x3b0,   0x3b1,   0x3b2,   0x3b3,   0x3b4,   0x3b5,   0x3b6,\n        0x3b7,   0x3b8,   0x3b9,   0x3ba,   0x3bb,   0x3bc,   0x3bd,   0x3be,\n        0x3bf,   0x3c0,   0x3c1,   0x3c2,   0x3c3,   0x3c4,   0x3c5,   0x3c6,\n        0x3c7,   0x3c8,   0x3c9,   0x3ca,   0x3cb,   0x3cc,   0x3cd,   0x3ce,\n        0x3cf,   0x3d0,   0x3d1,   0x3d2,   0x3d3,   0x3d4,   0x3d5,   0x3d6,\n        0x3d7,   0x3d8,   0x3d9,   0x3da,   0x3db,   0x3dc,   0x3dd,   0x3de,\n        0x3df,   0x3e0,   0x3e1,   0x3e2,   0x3e3,   0x3e4,   0x3e5,   0x3e6,\n        0x3e7,   0x3e8,   0x3e9,   0x3ea,   0x3eb,   0x3ec,   0x3ed,   0x3ee,\n        0x3ef,   0x3f0,   0x3f1,   0x3f2,   0x3f3,   0x3f4,   0x3f5,   0x3f7,\n        0x3f8,   0x3f9,   0x3fa,   0x3fb,   0x3fc,   0x3fd,   0x3fe,   0x3ff,\n        0x400,   0x401,   0x402,   0x403,   0x404,   0x405,   0x406,   0x407,\n        0x408,   0x409,   0x40a,   0x40b,   0x40c,   0x40d,   0x40e,   0x40f,\n        0x410,   0x411,   0x412,   0x413,   0x414,   0x415,   0x416,   0x417,\n        0x418,   0x419,   0x41a,   0x41b,   0x41c,   0x41d,   0x41e,   0x41f,\n        0x420,   0x421,   0x422,   0x423,   0x424,   0x425,   0x426,   0x427,\n        0x428,   0x429,   0x42a,   0x42b,   0x42c,   0x42d,   0x42e,   0x42f,\n        0x430,   0x431,   0x432,   0x433,   0x434,   0x435,   0x436,   0x437,\n        0x438,   0x439,   0x43a,   0x43b,   0x43c,   0x43d,   0x43e,   0x43f,\n        0x440,   0x441,   0x442,   0x443,   0x444,   0x445,   0x446,   0x447,\n        0x448,   0x449,   0x44a,   0x44b,   0x44c,   0x44d,   0x44e,   0x44f,\n        0x450,   0x451,   0x452,   0x453,   0x454,   0x455,   0x456,   0x457,\n        0x458,   0x459,   0x45a,   0x45b,   0x45c,   0x45d,   0x45e,   0x45f,\n        0x460,   0x461,   0x462,   0x463,   0x464,   0x465,   0x466,   0x467,\n        0x468,   0x469,   0x46a,   0x46b,   0x46c,   0x46d,   0x46e,   0x46f,\n        0x470,   0x471,   0x472,   0x473,   0x474,   0x475,   0x476,   0x477,\n        0x478,   0x479,   0x47a,   0x47b,   0x47c,   0x47d,   0x47e,   0x47f,\n        0x480,   0x481,   0x48a,   0x48b,   0x48c,   0x48d,   0x48e,   0x48f,\n        0x490,   0x491,   0x492,   0x493,   0x494,   0x495,   0x496,   0x497,\n        0x498,   0x499,   0x49a,   0x49b,   0x49c,   0x49d,   0x49e,   0x49f,\n        0x4a0,   0x4a1,   0x4a2,   0x4a3,   0x4a4,   0x4a5,   0x4a6,   0x4a7,\n        0x4a8,   0x4a9,   0x4aa,   0x4ab,   0x4ac,   0x4ad,   0x4ae,   0x4af,\n        0x4b0,   0x4b1,   0x4b2,   0x4b3,   0x4b4,   0x4b5,   0x4b6,   0x4b7,\n        0x4b8,   0x4b9,   0x4ba,   0x4bb,   0x4bc,   0x4bd,   0x4be,   0x4bf,\n        0x4c0,   0x4c1,   0x4c2,   0x4c3,   0x4c4,   0x4c5,   0x4c6,   0x4c7,\n        0x4c8,   0x4c9,   0x4ca,   0x4cb,   0x4cc,   0x4cd,   0x4ce,   0x4cf,\n        0x4d0,   0x4d1,   0x4d2,   0x4d3,   0x4d4,   0x4d5,   0x4d6,   0x4d7,\n        0x4d8,   0x4d9,   0x4da,   0x4db,   0x4dc,   0x4dd,   0x4de,   0x4df,\n        0x4e0,   0x4e1,   0x4e2,   0x4e3,   0x4e4,   0x4e5,   0x4e6,   0x4e7,\n        0x4e8,   0x4e9,   0x4ea,   0x4eb,   0x4ec,   0x4ed,   0x4ee,   0x4ef,\n        0x4f0,   0x4f1,   0x4f2,   0x4f3,   0x4f4,   0x4f5,   0x4f6,   0x4f7,\n        0x4f8,   0x4f9,   0x4fa,   0x4fb,   0x4fc,   0x4fd,   0x4fe,   0x4ff,\n        0x500,   0x501,   0x502,   0x503,   0x504,   0x505,   0x506,   0x507,\n        0x508,   0x509,   0x50a,   0x50b,   0x50c,   0x50d,   0x50e,   0x50f,\n        0x510,   0x511,   0x512,   0x513,   0x514,   0x515,   0x516,   0x517,\n        0x518,   0x519,   0x51a,   0x51b,   0x51c,   0x51d,   0x51e,   0x51f,\n        0x520,   0x521,   0x522,   0x523,   0x524,   0x525,   0x526,   0x527,\n        0x528,   0x529,   0x52a,   0x52b,   0x52c,   0x52d,   0x52e,   0x52f,\n        0x531,   0x532,   0x533,   0x534,   0x535,   0x536,   0x537,   0x538,\n        0x539,   0x53a,   0x53b,   0x53c,   0x53d,   0x53e,   0x53f,   0x540,\n        0x541,   0x542,   0x543,   0x544,   0x545,   0x546,   0x547,   0x548,\n        0x549,   0x54a,   0x54b,   0x54c,   0x54d,   0x54e,   0x54f,   0x550,\n        0x551,   0x552,   0x553,   0x554,   0x555,   0x556,   0x561,   0x562,\n        0x563,   0x564,   0x565,   0x566,   0x567,   0x568,   0x569,   0x56a,\n        0x56b,   0x56c,   0x56d,   0x56e,   0x56f,   0x570,   0x571,   0x572,\n        0x573,   0x574,   0x575,   0x576,   0x577,   0x578,   0x579,   0x57a,\n        0x57b,   0x57c,   0x57d,   0x57e,   0x57f,   0x580,   0x581,   0x582,\n        0x583,   0x584,   0x585,   0x586,   0x587,   0x10a0,  0x10a1,  0x10a2,\n        0x10a3,  0x10a4,  0x10a5,  0x10a6,  0x10a7,  0x10a8,  0x10a9,  0x10aa,\n        0x10ab,  0x10ac,  0x10ad,  0x10ae,  0x10af,  0x10b0,  0x10b1,  0x10b2,\n        0x10b3,  0x10b4,  0x10b5,  0x10b6,  0x10b7,  0x10b8,  0x10b9,  0x10ba,\n        0x10bb,  0x10bc,  0x10bd,  0x10be,  0x10bf,  0x10c0,  0x10c1,  0x10c2,\n        0x10c3,  0x10c4,  0x10c5,  0x10c7,  0x10cd,  0x13a0,  0x13a1,  0x13a2,\n        0x13a3,  0x13a4,  0x13a5,  0x13a6,  0x13a7,  0x13a8,  0x13a9,  0x13aa,\n        0x13ab,  0x13ac,  0x13ad,  0x13ae,  0x13af,  0x13b0,  0x13b1,  0x13b2,\n        0x13b3,  0x13b4,  0x13b5,  0x13b6,  0x13b7,  0x13b8,  0x13b9,  0x13ba,\n        0x13bb,  0x13bc,  0x13bd,  0x13be,  0x13bf,  0x13c0,  0x13c1,  0x13c2,\n        0x13c3,  0x13c4,  0x13c5,  0x13c6,  0x13c7,  0x13c8,  0x13c9,  0x13ca,\n        0x13cb,  0x13cc,  0x13cd,  0x13ce,  0x13cf,  0x13d0,  0x13d1,  0x13d2,\n        0x13d3,  0x13d4,  0x13d5,  0x13d6,  0x13d7,  0x13d8,  0x13d9,  0x13da,\n        0x13db,  0x13dc,  0x13dd,  0x13de,  0x13df,  0x13e0,  0x13e1,  0x13e2,\n        0x13e3,  0x13e4,  0x13e5,  0x13e6,  0x13e7,  0x13e8,  0x13e9,  0x13ea,\n        0x13eb,  0x13ec,  0x13ed,  0x13ee,  0x13ef,  0x13f0,  0x13f1,  0x13f2,\n        0x13f3,  0x13f4,  0x13f5,  0x13f8,  0x13f9,  0x13fa,  0x13fb,  0x13fc,\n        0x13fd,  0x1d00,  0x1d01,  0x1d02,  0x1d03,  0x1d04,  0x1d05,  0x1d06,\n        0x1d07,  0x1d08,  0x1d09,  0x1d0a,  0x1d0b,  0x1d0c,  0x1d0d,  0x1d0e,\n        0x1d0f,  0x1d10,  0x1d11,  0x1d12,  0x1d13,  0x1d14,  0x1d15,  0x1d16,\n        0x1d17,  0x1d18,  0x1d19,  0x1d1a,  0x1d1b,  0x1d1c,  0x1d1d,  0x1d1e,\n        0x1d1f,  0x1d20,  0x1d21,  0x1d22,  0x1d23,  0x1d24,  0x1d25,  0x1d26,\n        0x1d27,  0x1d28,  0x1d29,  0x1d2a,  0x1d2b,  0x1d6b,  0x1d6c,  0x1d6d,\n        0x1d6e,  0x1d6f,  0x1d70,  0x1d71,  0x1d72,  0x1d73,  0x1d74,  0x1d75,\n        0x1d76,  0x1d77,  0x1d79,  0x1d7a,  0x1d7b,  0x1d7c,  0x1d7d,  0x1d7e,\n        0x1d7f,  0x1d80,  0x1d81,  0x1d82,  0x1d83,  0x1d84,  0x1d85,  0x1d86,\n        0x1d87,  0x1d88,  0x1d89,  0x1d8a,  0x1d8b,  0x1d8c,  0x1d8d,  0x1d8e,\n        0x1d8f,  0x1d90,  0x1d91,  0x1d92,  0x1d93,  0x1d94,  0x1d95,  0x1d96,\n        0x1d97,  0x1d98,  0x1d99,  0x1d9a,  0x1e00,  0x1e01,  0x1e02,  0x1e03,\n        0x1e04,  0x1e05,  0x1e06,  0x1e07,  0x1e08,  0x1e09,  0x1e0a,  0x1e0b,\n        0x1e0c,  0x1e0d,  0x1e0e,  0x1e0f,  0x1e10,  0x1e11,  0x1e12,  0x1e13,\n        0x1e14,  0x1e15,  0x1e16,  0x1e17,  0x1e18,  0x1e19,  0x1e1a,  0x1e1b,\n        0x1e1c,  0x1e1d,  0x1e1e,  0x1e1f,  0x1e20,  0x1e21,  0x1e22,  0x1e23,\n        0x1e24,  0x1e25,  0x1e26,  0x1e27,  0x1e28,  0x1e29,  0x1e2a,  0x1e2b,\n        0x1e2c,  0x1e2d,  0x1e2e,  0x1e2f,  0x1e30,  0x1e31,  0x1e32,  0x1e33,\n        0x1e34,  0x1e35,  0x1e36,  0x1e37,  0x1e38,  0x1e39,  0x1e3a,  0x1e3b,\n        0x1e3c,  0x1e3d,  0x1e3e,  0x1e3f,  0x1e40,  0x1e41,  0x1e42,  0x1e43,\n        0x1e44,  0x1e45,  0x1e46,  0x1e47,  0x1e48,  0x1e49,  0x1e4a,  0x1e4b,\n        0x1e4c,  0x1e4d,  0x1e4e,  0x1e4f,  0x1e50,  0x1e51,  0x1e52,  0x1e53,\n        0x1e54,  0x1e55,  0x1e56,  0x1e57,  0x1e58,  0x1e59,  0x1e5a,  0x1e5b,\n        0x1e5c,  0x1e5d,  0x1e5e,  0x1e5f,  0x1e60,  0x1e61,  0x1e62,  0x1e63,\n        0x1e64,  0x1e65,  0x1e66,  0x1e67,  0x1e68,  0x1e69,  0x1e6a,  0x1e6b,\n        0x1e6c,  0x1e6d,  0x1e6e,  0x1e6f,  0x1e70,  0x1e71,  0x1e72,  0x1e73,\n        0x1e74,  0x1e75,  0x1e76,  0x1e77,  0x1e78,  0x1e79,  0x1e7a,  0x1e7b,\n        0x1e7c,  0x1e7d,  0x1e7e,  0x1e7f,  0x1e80,  0x1e81,  0x1e82,  0x1e83,\n        0x1e84,  0x1e85,  0x1e86,  0x1e87,  0x1e88,  0x1e89,  0x1e8a,  0x1e8b,\n        0x1e8c,  0x1e8d,  0x1e8e,  0x1e8f,  0x1e90,  0x1e91,  0x1e92,  0x1e93,\n        0x1e94,  0x1e95,  0x1e96,  0x1e97,  0x1e98,  0x1e99,  0x1e9a,  0x1e9b,\n        0x1e9c,  0x1e9d,  0x1e9e,  0x1e9f,  0x1ea0,  0x1ea1,  0x1ea2,  0x1ea3,\n        0x1ea4,  0x1ea5,  0x1ea6,  0x1ea7,  0x1ea8,  0x1ea9,  0x1eaa,  0x1eab,\n        0x1eac,  0x1ead,  0x1eae,  0x1eaf,  0x1eb0,  0x1eb1,  0x1eb2,  0x1eb3,\n        0x1eb4,  0x1eb5,  0x1eb6,  0x1eb7,  0x1eb8,  0x1eb9,  0x1eba,  0x1ebb,\n        0x1ebc,  0x1ebd,  0x1ebe,  0x1ebf,  0x1ec0,  0x1ec1,  0x1ec2,  0x1ec3,\n        0x1ec4,  0x1ec5,  0x1ec6,  0x1ec7,  0x1ec8,  0x1ec9,  0x1eca,  0x1ecb,\n        0x1ecc,  0x1ecd,  0x1ece,  0x1ecf,  0x1ed0,  0x1ed1,  0x1ed2,  0x1ed3,\n        0x1ed4,  0x1ed5,  0x1ed6,  0x1ed7,  0x1ed8,  0x1ed9,  0x1eda,  0x1edb,\n        0x1edc,  0x1edd,  0x1ede,  0x1edf,  0x1ee0,  0x1ee1,  0x1ee2,  0x1ee3,\n        0x1ee4,  0x1ee5,  0x1ee6,  0x1ee7,  0x1ee8,  0x1ee9,  0x1eea,  0x1eeb,\n        0x1eec,  0x1eed,  0x1eee,  0x1eef,  0x1ef0,  0x1ef1,  0x1ef2,  0x1ef3,\n        0x1ef4,  0x1ef5,  0x1ef6,  0x1ef7,  0x1ef8,  0x1ef9,  0x1efa,  0x1efb,\n        0x1efc,  0x1efd,  0x1efe,  0x1eff,  0x1f00,  0x1f01,  0x1f02,  0x1f03,\n        0x1f04,  0x1f05,  0x1f06,  0x1f07,  0x1f08,  0x1f09,  0x1f0a,  0x1f0b,\n        0x1f0c,  0x1f0d,  0x1f0e,  0x1f0f,  0x1f10,  0x1f11,  0x1f12,  0x1f13,\n        0x1f14,  0x1f15,  0x1f18,  0x1f19,  0x1f1a,  0x1f1b,  0x1f1c,  0x1f1d,\n        0x1f20,  0x1f21,  0x1f22,  0x1f23,  0x1f24,  0x1f25,  0x1f26,  0x1f27,\n        0x1f28,  0x1f29,  0x1f2a,  0x1f2b,  0x1f2c,  0x1f2d,  0x1f2e,  0x1f2f,\n        0x1f30,  0x1f31,  0x1f32,  0x1f33,  0x1f34,  0x1f35,  0x1f36,  0x1f37,\n        0x1f38,  0x1f39,  0x1f3a,  0x1f3b,  0x1f3c,  0x1f3d,  0x1f3e,  0x1f3f,\n        0x1f40,  0x1f41,  0x1f42,  0x1f43,  0x1f44,  0x1f45,  0x1f48,  0x1f49,\n        0x1f4a,  0x1f4b,  0x1f4c,  0x1f4d,  0x1f50,  0x1f51,  0x1f52,  0x1f53,\n        0x1f54,  0x1f55,  0x1f56,  0x1f57,  0x1f59,  0x1f5b,  0x1f5d,  0x1f5f,\n        0x1f60,  0x1f61,  0x1f62,  0x1f63,  0x1f64,  0x1f65,  0x1f66,  0x1f67,\n        0x1f68,  0x1f69,  0x1f6a,  0x1f6b,  0x1f6c,  0x1f6d,  0x1f6e,  0x1f6f,\n        0x1f70,  0x1f71,  0x1f72,  0x1f73,  0x1f74,  0x1f75,  0x1f76,  0x1f77,\n        0x1f78,  0x1f79,  0x1f7a,  0x1f7b,  0x1f7c,  0x1f7d,  0x1f80,  0x1f81,\n        0x1f82,  0x1f83,  0x1f84,  0x1f85,  0x1f86,  0x1f87,  0x1f90,  0x1f91,\n        0x1f92,  0x1f93,  0x1f94,  0x1f95,  0x1f96,  0x1f97,  0x1fa0,  0x1fa1,\n        0x1fa2,  0x1fa3,  0x1fa4,  0x1fa5,  0x1fa6,  0x1fa7,  0x1fb0,  0x1fb1,\n        0x1fb2,  0x1fb3,  0x1fb4,  0x1fb6,  0x1fb7,  0x1fb8,  0x1fb9,  0x1fba,\n        0x1fbb,  0x1fbe,  0x1fc2,  0x1fc3,  0x1fc4,  0x1fc6,  0x1fc7,  0x1fc8,\n        0x1fc9,  0x1fca,  0x1fcb,  0x1fd0,  0x1fd1,  0x1fd2,  0x1fd3,  0x1fd6,\n        0x1fd7,  0x1fd8,  0x1fd9,  0x1fda,  0x1fdb,  0x1fe0,  0x1fe1,  0x1fe2,\n        0x1fe3,  0x1fe4,  0x1fe5,  0x1fe6,  0x1fe7,  0x1fe8,  0x1fe9,  0x1fea,\n        0x1feb,  0x1fec,  0x1ff2,  0x1ff3,  0x1ff4,  0x1ff6,  0x1ff7,  0x1ff8,\n        0x1ff9,  0x1ffa,  0x1ffb,  0x2102,  0x2107,  0x210a,  0x210b,  0x210c,\n        0x210d,  0x210e,  0x210f,  0x2110,  0x2111,  0x2112,  0x2113,  0x2115,\n        0x2119,  0x211a,  0x211b,  0x211c,  0x211d,  0x2124,  0x2126,  0x2128,\n        0x212a,  0x212b,  0x212c,  0x212d,  0x212f,  0x2130,  0x2131,  0x2132,\n        0x2133,  0x2134,  0x2139,  0x213c,  0x213d,  0x213e,  0x213f,  0x2145,\n        0x2146,  0x2147,  0x2148,  0x2149,  0x214e,  0x2183,  0x2184,  0x2c00,\n        0x2c01,  0x2c02,  0x2c03,  0x2c04,  0x2c05,  0x2c06,  0x2c07,  0x2c08,\n        0x2c09,  0x2c0a,  0x2c0b,  0x2c0c,  0x2c0d,  0x2c0e,  0x2c0f,  0x2c10,\n        0x2c11,  0x2c12,  0x2c13,  0x2c14,  0x2c15,  0x2c16,  0x2c17,  0x2c18,\n        0x2c19,  0x2c1a,  0x2c1b,  0x2c1c,  0x2c1d,  0x2c1e,  0x2c1f,  0x2c20,\n        0x2c21,  0x2c22,  0x2c23,  0x2c24,  0x2c25,  0x2c26,  0x2c27,  0x2c28,\n        0x2c29,  0x2c2a,  0x2c2b,  0x2c2c,  0x2c2d,  0x2c2e,  0x2c30,  0x2c31,\n        0x2c32,  0x2c33,  0x2c34,  0x2c35,  0x2c36,  0x2c37,  0x2c38,  0x2c39,\n        0x2c3a,  0x2c3b,  0x2c3c,  0x2c3d,  0x2c3e,  0x2c3f,  0x2c40,  0x2c41,\n        0x2c42,  0x2c43,  0x2c44,  0x2c45,  0x2c46,  0x2c47,  0x2c48,  0x2c49,\n        0x2c4a,  0x2c4b,  0x2c4c,  0x2c4d,  0x2c4e,  0x2c4f,  0x2c50,  0x2c51,\n        0x2c52,  0x2c53,  0x2c54,  0x2c55,  0x2c56,  0x2c57,  0x2c58,  0x2c59,\n        0x2c5a,  0x2c5b,  0x2c5c,  0x2c5d,  0x2c5e,  0x2c60,  0x2c61,  0x2c62,\n        0x2c63,  0x2c64,  0x2c65,  0x2c66,  0x2c67,  0x2c68,  0x2c69,  0x2c6a,\n        0x2c6b,  0x2c6c,  0x2c6d,  0x2c6e,  0x2c6f,  0x2c70,  0x2c71,  0x2c72,\n        0x2c73,  0x2c74,  0x2c75,  0x2c76,  0x2c77,  0x2c78,  0x2c79,  0x2c7a,\n        0x2c7b,  0x2c7e,  0x2c7f,  0x2c80,  0x2c81,  0x2c82,  0x2c83,  0x2c84,\n        0x2c85,  0x2c86,  0x2c87,  0x2c88,  0x2c89,  0x2c8a,  0x2c8b,  0x2c8c,\n        0x2c8d,  0x2c8e,  0x2c8f,  0x2c90,  0x2c91,  0x2c92,  0x2c93,  0x2c94,\n        0x2c95,  0x2c96,  0x2c97,  0x2c98,  0x2c99,  0x2c9a,  0x2c9b,  0x2c9c,\n        0x2c9d,  0x2c9e,  0x2c9f,  0x2ca0,  0x2ca1,  0x2ca2,  0x2ca3,  0x2ca4,\n        0x2ca5,  0x2ca6,  0x2ca7,  0x2ca8,  0x2ca9,  0x2caa,  0x2cab,  0x2cac,\n        0x2cad,  0x2cae,  0x2caf,  0x2cb0,  0x2cb1,  0x2cb2,  0x2cb3,  0x2cb4,\n        0x2cb5,  0x2cb6,  0x2cb7,  0x2cb8,  0x2cb9,  0x2cba,  0x2cbb,  0x2cbc,\n        0x2cbd,  0x2cbe,  0x2cbf,  0x2cc0,  0x2cc1,  0x2cc2,  0x2cc3,  0x2cc4,\n        0x2cc5,  0x2cc6,  0x2cc7,  0x2cc8,  0x2cc9,  0x2cca,  0x2ccb,  0x2ccc,\n        0x2ccd,  0x2cce,  0x2ccf,  0x2cd0,  0x2cd1,  0x2cd2,  0x2cd3,  0x2cd4,\n        0x2cd5,  0x2cd6,  0x2cd7,  0x2cd8,  0x2cd9,  0x2cda,  0x2cdb,  0x2cdc,\n        0x2cdd,  0x2cde,  0x2cdf,  0x2ce0,  0x2ce1,  0x2ce2,  0x2ce3,  0x2ce4,\n        0x2ceb,  0x2cec,  0x2ced,  0x2cee,  0x2cf2,  0x2cf3,  0x2d00,  0x2d01,\n        0x2d02,  0x2d03,  0x2d04,  0x2d05,  0x2d06,  0x2d07,  0x2d08,  0x2d09,\n        0x2d0a,  0x2d0b,  0x2d0c,  0x2d0d,  0x2d0e,  0x2d0f,  0x2d10,  0x2d11,\n        0x2d12,  0x2d13,  0x2d14,  0x2d15,  0x2d16,  0x2d17,  0x2d18,  0x2d19,\n        0x2d1a,  0x2d1b,  0x2d1c,  0x2d1d,  0x2d1e,  0x2d1f,  0x2d20,  0x2d21,\n        0x2d22,  0x2d23,  0x2d24,  0x2d25,  0x2d27,  0x2d2d,  0xa640,  0xa641,\n        0xa642,  0xa643,  0xa644,  0xa645,  0xa646,  0xa647,  0xa648,  0xa649,\n        0xa64a,  0xa64b,  0xa64c,  0xa64d,  0xa64e,  0xa64f,  0xa650,  0xa651,\n        0xa652,  0xa653,  0xa654,  0xa655,  0xa656,  0xa657,  0xa658,  0xa659,\n        0xa65a,  0xa65b,  0xa65c,  0xa65d,  0xa65e,  0xa65f,  0xa660,  0xa661,\n        0xa662,  0xa663,  0xa664,  0xa665,  0xa666,  0xa667,  0xa668,  0xa669,\n        0xa66a,  0xa66b,  0xa66c,  0xa66d,  0xa680,  0xa681,  0xa682,  0xa683,\n        0xa684,  0xa685,  0xa686,  0xa687,  0xa688,  0xa689,  0xa68a,  0xa68b,\n        0xa68c,  0xa68d,  0xa68e,  0xa68f,  0xa690,  0xa691,  0xa692,  0xa693,\n        0xa694,  0xa695,  0xa696,  0xa697,  0xa698,  0xa699,  0xa69a,  0xa69b,\n        0xa722,  0xa723,  0xa724,  0xa725,  0xa726,  0xa727,  0xa728,  0xa729,\n        0xa72a,  0xa72b,  0xa72c,  0xa72d,  0xa72e,  0xa72f,  0xa730,  0xa731,\n        0xa732,  0xa733,  0xa734,  0xa735,  0xa736,  0xa737,  0xa738,  0xa739,\n        0xa73a,  0xa73b,  0xa73c,  0xa73d,  0xa73e,  0xa73f,  0xa740,  0xa741,\n        0xa742,  0xa743,  0xa744,  0xa745,  0xa746,  0xa747,  0xa748,  0xa749,\n        0xa74a,  0xa74b,  0xa74c,  0xa74d,  0xa74e,  0xa74f,  0xa750,  0xa751,\n        0xa752,  0xa753,  0xa754,  0xa755,  0xa756,  0xa757,  0xa758,  0xa759,\n        0xa75a,  0xa75b,  0xa75c,  0xa75d,  0xa75e,  0xa75f,  0xa760,  0xa761,\n        0xa762,  0xa763,  0xa764,  0xa765,  0xa766,  0xa767,  0xa768,  0xa769,\n        0xa76a,  0xa76b,  0xa76c,  0xa76d,  0xa76e,  0xa76f,  0xa771,  0xa772,\n        0xa773,  0xa774,  0xa775,  0xa776,  0xa777,  0xa778,  0xa779,  0xa77a,\n        0xa77b,  0xa77c,  0xa77d,  0xa77e,  0xa77f,  0xa780,  0xa781,  0xa782,\n        0xa783,  0xa784,  0xa785,  0xa786,  0xa787,  0xa78b,  0xa78c,  0xa78d,\n        0xa78e,  0xa790,  0xa791,  0xa792,  0xa793,  0xa794,  0xa795,  0xa796,\n        0xa797,  0xa798,  0xa799,  0xa79a,  0xa79b,  0xa79c,  0xa79d,  0xa79e,\n        0xa79f,  0xa7a0,  0xa7a1,  0xa7a2,  0xa7a3,  0xa7a4,  0xa7a5,  0xa7a6,\n        0xa7a7,  0xa7a8,  0xa7a9,  0xa7aa,  0xa7ab,  0xa7ac,  0xa7ad,  0xa7b0,\n        0xa7b1,  0xa7b2,  0xa7b3,  0xa7b4,  0xa7b5,  0xa7b6,  0xa7b7,  0xa7fa,\n        0xab30,  0xab31,  0xab32,  0xab33,  0xab34,  0xab35,  0xab36,  0xab37,\n        0xab38,  0xab39,  0xab3a,  0xab3b,  0xab3c,  0xab3d,  0xab3e,  0xab3f,\n        0xab40,  0xab41,  0xab42,  0xab43,  0xab44,  0xab45,  0xab46,  0xab47,\n        0xab48,  0xab49,  0xab4a,  0xab4b,  0xab4c,  0xab4d,  0xab4e,  0xab4f,\n        0xab50,  0xab51,  0xab52,  0xab53,  0xab54,  0xab55,  0xab56,  0xab57,\n        0xab58,  0xab59,  0xab5a,  0xab60,  0xab61,  0xab62,  0xab63,  0xab64,\n        0xab65,  0xab70,  0xab71,  0xab72,  0xab73,  0xab74,  0xab75,  0xab76,\n        0xab77,  0xab78,  0xab79,  0xab7a,  0xab7b,  0xab7c,  0xab7d,  0xab7e,\n        0xab7f,  0xab80,  0xab81,  0xab82,  0xab83,  0xab84,  0xab85,  0xab86,\n        0xab87,  0xab88,  0xab89,  0xab8a,  0xab8b,  0xab8c,  0xab8d,  0xab8e,\n        0xab8f,  0xab90,  0xab91,  0xab92,  0xab93,  0xab94,  0xab95,  0xab96,\n        0xab97,  0xab98,  0xab99,  0xab9a,  0xab9b,  0xab9c,  0xab9d,  0xab9e,\n        0xab9f,  0xaba0,  0xaba1,  0xaba2,  0xaba3,  0xaba4,  0xaba5,  0xaba6,\n        0xaba7,  0xaba8,  0xaba9,  0xabaa,  0xabab,  0xabac,  0xabad,  0xabae,\n        0xabaf,  0xabb0,  0xabb1,  0xabb2,  0xabb3,  0xabb4,  0xabb5,  0xabb6,\n        0xabb7,  0xabb8,  0xabb9,  0xabba,  0xabbb,  0xabbc,  0xabbd,  0xabbe,\n        0xabbf,  0xfb00,  0xfb01,  0xfb02,  0xfb03,  0xfb04,  0xfb05,  0xfb06,\n        0xfb13,  0xfb14,  0xfb15,  0xfb16,  0xfb17,  0xff21,  0xff22,  0xff23,\n        0xff24,  0xff25,  0xff26,  0xff27,  0xff28,  0xff29,  0xff2a,  0xff2b,\n        0xff2c,  0xff2d,  0xff2e,  0xff2f,  0xff30,  0xff31,  0xff32,  0xff33,\n        0xff34,  0xff35,  0xff36,  0xff37,  0xff38,  0xff39,  0xff3a,  0xff41,\n        0xff42,  0xff43,  0xff44,  0xff45,  0xff46,  0xff47,  0xff48,  0xff49,\n        0xff4a,  0xff4b,  0xff4c,  0xff4d,  0xff4e,  0xff4f,  0xff50,  0xff51,\n        0xff52,  0xff53,  0xff54,  0xff55,  0xff56,  0xff57,  0xff58,  0xff59,\n        0xff5a,  0x10400, 0x10401, 0x10402, 0x10403, 0x10404, 0x10405, 0x10406,\n        0x10407, 0x10408, 0x10409, 0x1040a, 0x1040b, 0x1040c, 0x1040d, 0x1040e,\n        0x1040f, 0x10410, 0x10411, 0x10412, 0x10413, 0x10414, 0x10415, 0x10416,\n        0x10417, 0x10418, 0x10419, 0x1041a, 0x1041b, 0x1041c, 0x1041d, 0x1041e,\n        0x1041f, 0x10420, 0x10421, 0x10422, 0x10423, 0x10424, 0x10425, 0x10426,\n        0x10427, 0x10428, 0x10429, 0x1042a, 0x1042b, 0x1042c, 0x1042d, 0x1042e,\n        0x1042f, 0x10430, 0x10431, 0x10432, 0x10433, 0x10434, 0x10435, 0x10436,\n        0x10437, 0x10438, 0x10439, 0x1043a, 0x1043b, 0x1043c, 0x1043d, 0x1043e,\n        0x1043f, 0x10440, 0x10441, 0x10442, 0x10443, 0x10444, 0x10445, 0x10446,\n        0x10447, 0x10448, 0x10449, 0x1044a, 0x1044b, 0x1044c, 0x1044d, 0x1044e,\n        0x1044f, 0x10c80, 0x10c81, 0x10c82, 0x10c83, 0x10c84, 0x10c85, 0x10c86,\n        0x10c87, 0x10c88, 0x10c89, 0x10c8a, 0x10c8b, 0x10c8c, 0x10c8d, 0x10c8e,\n        0x10c8f, 0x10c90, 0x10c91, 0x10c92, 0x10c93, 0x10c94, 0x10c95, 0x10c96,\n        0x10c97, 0x10c98, 0x10c99, 0x10c9a, 0x10c9b, 0x10c9c, 0x10c9d, 0x10c9e,\n        0x10c9f, 0x10ca0, 0x10ca1, 0x10ca2, 0x10ca3, 0x10ca4, 0x10ca5, 0x10ca6,\n        0x10ca7, 0x10ca8, 0x10ca9, 0x10caa, 0x10cab, 0x10cac, 0x10cad, 0x10cae,\n        0x10caf, 0x10cb0, 0x10cb1, 0x10cb2, 0x10cc0, 0x10cc1, 0x10cc2, 0x10cc3,\n        0x10cc4, 0x10cc5, 0x10cc6, 0x10cc7, 0x10cc8, 0x10cc9, 0x10cca, 0x10ccb,\n        0x10ccc, 0x10ccd, 0x10cce, 0x10ccf, 0x10cd0, 0x10cd1, 0x10cd2, 0x10cd3,\n        0x10cd4, 0x10cd5, 0x10cd6, 0x10cd7, 0x10cd8, 0x10cd9, 0x10cda, 0x10cdb,\n        0x10cdc, 0x10cdd, 0x10cde, 0x10cdf, 0x10ce0, 0x10ce1, 0x10ce2, 0x10ce3,\n        0x10ce4, 0x10ce5, 0x10ce6, 0x10ce7, 0x10ce8, 0x10ce9, 0x10cea, 0x10ceb,\n        0x10cec, 0x10ced, 0x10cee, 0x10cef, 0x10cf0, 0x10cf1, 0x10cf2, 0x118a0,\n        0x118a1, 0x118a2, 0x118a3, 0x118a4, 0x118a5, 0x118a6, 0x118a7, 0x118a8,\n        0x118a9, 0x118aa, 0x118ab, 0x118ac, 0x118ad, 0x118ae, 0x118af, 0x118b0,\n        0x118b1, 0x118b2, 0x118b3, 0x118b4, 0x118b5, 0x118b6, 0x118b7, 0x118b8,\n        0x118b9, 0x118ba, 0x118bb, 0x118bc, 0x118bd, 0x118be, 0x118bf, 0x118c0,\n        0x118c1, 0x118c2, 0x118c3, 0x118c4, 0x118c5, 0x118c6, 0x118c7, 0x118c8,\n        0x118c9, 0x118ca, 0x118cb, 0x118cc, 0x118cd, 0x118ce, 0x118cf, 0x118d0,\n        0x118d1, 0x118d2, 0x118d3, 0x118d4, 0x118d5, 0x118d6, 0x118d7, 0x118d8,\n        0x118d9, 0x118da, 0x118db, 0x118dc, 0x118dd, 0x118de, 0x118df, 0x1d400,\n        0x1d401, 0x1d402, 0x1d403, 0x1d404, 0x1d405, 0x1d406, 0x1d407, 0x1d408,\n        0x1d409, 0x1d40a, 0x1d40b, 0x1d40c, 0x1d40d, 0x1d40e, 0x1d40f, 0x1d410,\n        0x1d411, 0x1d412, 0x1d413, 0x1d414, 0x1d415, 0x1d416, 0x1d417, 0x1d418,\n        0x1d419, 0x1d41a, 0x1d41b, 0x1d41c, 0x1d41d, 0x1d41e, 0x1d41f, 0x1d420,\n        0x1d421, 0x1d422, 0x1d423, 0x1d424, 0x1d425, 0x1d426, 0x1d427, 0x1d428,\n        0x1d429, 0x1d42a, 0x1d42b, 0x1d42c, 0x1d42d, 0x1d42e, 0x1d42f, 0x1d430,\n        0x1d431, 0x1d432, 0x1d433, 0x1d434, 0x1d435, 0x1d436, 0x1d437, 0x1d438,\n        0x1d439, 0x1d43a, 0x1d43b, 0x1d43c, 0x1d43d, 0x1d43e, 0x1d43f, 0x1d440,\n        0x1d441, 0x1d442, 0x1d443, 0x1d444, 0x1d445, 0x1d446, 0x1d447, 0x1d448,\n        0x1d449, 0x1d44a, 0x1d44b, 0x1d44c, 0x1d44d, 0x1d44e, 0x1d44f, 0x1d450,\n        0x1d451, 0x1d452, 0x1d453, 0x1d454, 0x1d456, 0x1d457, 0x1d458, 0x1d459,\n        0x1d45a, 0x1d45b, 0x1d45c, 0x1d45d, 0x1d45e, 0x1d45f, 0x1d460, 0x1d461,\n        0x1d462, 0x1d463, 0x1d464, 0x1d465, 0x1d466, 0x1d467, 0x1d468, 0x1d469,\n        0x1d46a, 0x1d46b, 0x1d46c, 0x1d46d, 0x1d46e, 0x1d46f, 0x1d470, 0x1d471,\n        0x1d472, 0x1d473, 0x1d474, 0x1d475, 0x1d476, 0x1d477, 0x1d478, 0x1d479,\n        0x1d47a, 0x1d47b, 0x1d47c, 0x1d47d, 0x1d47e, 0x1d47f, 0x1d480, 0x1d481,\n        0x1d482, 0x1d483, 0x1d484, 0x1d485, 0x1d486, 0x1d487, 0x1d488, 0x1d489,\n        0x1d48a, 0x1d48b, 0x1d48c, 0x1d48d, 0x1d48e, 0x1d48f, 0x1d490, 0x1d491,\n        0x1d492, 0x1d493, 0x1d494, 0x1d495, 0x1d496, 0x1d497, 0x1d498, 0x1d499,\n        0x1d49a, 0x1d49b, 0x1d49c, 0x1d49e, 0x1d49f, 0x1d4a2, 0x1d4a5, 0x1d4a6,\n        0x1d4a9, 0x1d4aa, 0x1d4ab, 0x1d4ac, 0x1d4ae, 0x1d4af, 0x1d4b0, 0x1d4b1,\n        0x1d4b2, 0x1d4b3, 0x1d4b4, 0x1d4b5, 0x1d4b6, 0x1d4b7, 0x1d4b8, 0x1d4b9,\n        0x1d4bb, 0x1d4bd, 0x1d4be, 0x1d4bf, 0x1d4c0, 0x1d4c1, 0x1d4c2, 0x1d4c3,\n        0x1d4c5, 0x1d4c6, 0x1d4c7, 0x1d4c8, 0x1d4c9, 0x1d4ca, 0x1d4cb, 0x1d4cc,\n        0x1d4cd, 0x1d4ce, 0x1d4cf, 0x1d4d0, 0x1d4d1, 0x1d4d2, 0x1d4d3, 0x1d4d4,\n        0x1d4d5, 0x1d4d6, 0x1d4d7, 0x1d4d8, 0x1d4d9, 0x1d4da, 0x1d4db, 0x1d4dc,\n        0x1d4dd, 0x1d4de, 0x1d4df, 0x1d4e0, 0x1d4e1, 0x1d4e2, 0x1d4e3, 0x1d4e4,\n        0x1d4e5, 0x1d4e6, 0x1d4e7, 0x1d4e8, 0x1d4e9, 0x1d4ea, 0x1d4eb, 0x1d4ec,\n        0x1d4ed, 0x1d4ee, 0x1d4ef, 0x1d4f0, 0x1d4f1, 0x1d4f2, 0x1d4f3, 0x1d4f4,\n        0x1d4f5, 0x1d4f6, 0x1d4f7, 0x1d4f8, 0x1d4f9, 0x1d4fa, 0x1d4fb, 0x1d4fc,\n        0x1d4fd, 0x1d4fe, 0x1d4ff, 0x1d500, 0x1d501, 0x1d502, 0x1d503, 0x1d504,\n        0x1d505, 0x1d507, 0x1d508, 0x1d509, 0x1d50a, 0x1d50d, 0x1d50e, 0x1d50f,\n        0x1d510, 0x1d511, 0x1d512, 0x1d513, 0x1d514, 0x1d516, 0x1d517, 0x1d518,\n        0x1d519, 0x1d51a, 0x1d51b, 0x1d51c, 0x1d51e, 0x1d51f, 0x1d520, 0x1d521,\n        0x1d522, 0x1d523, 0x1d524, 0x1d525, 0x1d526, 0x1d527, 0x1d528, 0x1d529,\n        0x1d52a, 0x1d52b, 0x1d52c, 0x1d52d, 0x1d52e, 0x1d52f, 0x1d530, 0x1d531,\n        0x1d532, 0x1d533, 0x1d534, 0x1d535, 0x1d536, 0x1d537, 0x1d538, 0x1d539,\n        0x1d53b, 0x1d53c, 0x1d53d, 0x1d53e, 0x1d540, 0x1d541, 0x1d542, 0x1d543,\n        0x1d544, 0x1d546, 0x1d54a, 0x1d54b, 0x1d54c, 0x1d54d, 0x1d54e, 0x1d54f,\n        0x1d550, 0x1d552, 0x1d553, 0x1d554, 0x1d555, 0x1d556, 0x1d557, 0x1d558,\n        0x1d559, 0x1d55a, 0x1d55b, 0x1d55c, 0x1d55d, 0x1d55e, 0x1d55f, 0x1d560,\n        0x1d561, 0x1d562, 0x1d563, 0x1d564, 0x1d565, 0x1d566, 0x1d567, 0x1d568,\n        0x1d569, 0x1d56a, 0x1d56b, 0x1d56c, 0x1d56d, 0x1d56e, 0x1d56f, 0x1d570,\n        0x1d571, 0x1d572, 0x1d573, 0x1d574, 0x1d575, 0x1d576, 0x1d577, 0x1d578,\n        0x1d579, 0x1d57a, 0x1d57b, 0x1d57c, 0x1d57d, 0x1d57e, 0x1d57f, 0x1d580,\n        0x1d581, 0x1d582, 0x1d583, 0x1d584, 0x1d585, 0x1d586, 0x1d587, 0x1d588,\n        0x1d589, 0x1d58a, 0x1d58b, 0x1d58c, 0x1d58d, 0x1d58e, 0x1d58f, 0x1d590,\n        0x1d591, 0x1d592, 0x1d593, 0x1d594, 0x1d595, 0x1d596, 0x1d597, 0x1d598,\n        0x1d599, 0x1d59a, 0x1d59b, 0x1d59c, 0x1d59d, 0x1d59e, 0x1d59f, 0x1d5a0,\n        0x1d5a1, 0x1d5a2, 0x1d5a3, 0x1d5a4, 0x1d5a5, 0x1d5a6, 0x1d5a7, 0x1d5a8,\n        0x1d5a9, 0x1d5aa, 0x1d5ab, 0x1d5ac, 0x1d5ad, 0x1d5ae, 0x1d5af, 0x1d5b0,\n        0x1d5b1, 0x1d5b2, 0x1d5b3, 0x1d5b4, 0x1d5b5, 0x1d5b6, 0x1d5b7, 0x1d5b8,\n        0x1d5b9, 0x1d5ba, 0x1d5bb, 0x1d5bc, 0x1d5bd, 0x1d5be, 0x1d5bf, 0x1d5c0,\n        0x1d5c1, 0x1d5c2, 0x1d5c3, 0x1d5c4, 0x1d5c5, 0x1d5c6, 0x1d5c7, 0x1d5c8,\n        0x1d5c9, 0x1d5ca, 0x1d5cb, 0x1d5cc, 0x1d5cd, 0x1d5ce, 0x1d5cf, 0x1d5d0,\n        0x1d5d1, 0x1d5d2, 0x1d5d3, 0x1d5d4, 0x1d5d5, 0x1d5d6, 0x1d5d7, 0x1d5d8,\n        0x1d5d9, 0x1d5da, 0x1d5db, 0x1d5dc, 0x1d5dd, 0x1d5de, 0x1d5df, 0x1d5e0,\n        0x1d5e1, 0x1d5e2, 0x1d5e3, 0x1d5e4, 0x1d5e5, 0x1d5e6, 0x1d5e7, 0x1d5e8,\n        0x1d5e9, 0x1d5ea, 0x1d5eb, 0x1d5ec, 0x1d5ed, 0x1d5ee, 0x1d5ef, 0x1d5f0,\n        0x1d5f1, 0x1d5f2, 0x1d5f3, 0x1d5f4, 0x1d5f5, 0x1d5f6, 0x1d5f7, 0x1d5f8,\n        0x1d5f9, 0x1d5fa, 0x1d5fb, 0x1d5fc, 0x1d5fd, 0x1d5fe, 0x1d5ff, 0x1d600,\n        0x1d601, 0x1d602, 0x1d603, 0x1d604, 0x1d605, 0x1d606, 0x1d607, 0x1d608,\n        0x1d609, 0x1d60a, 0x1d60b, 0x1d60c, 0x1d60d, 0x1d60e, 0x1d60f, 0x1d610,\n        0x1d611, 0x1d612, 0x1d613, 0x1d614, 0x1d615, 0x1d616, 0x1d617, 0x1d618,\n        0x1d619, 0x1d61a, 0x1d61b, 0x1d61c, 0x1d61d, 0x1d61e, 0x1d61f, 0x1d620,\n        0x1d621, 0x1d622, 0x1d623, 0x1d624, 0x1d625, 0x1d626, 0x1d627, 0x1d628,\n        0x1d629, 0x1d62a, 0x1d62b, 0x1d62c, 0x1d62d, 0x1d62e, 0x1d62f, 0x1d630,\n        0x1d631, 0x1d632, 0x1d633, 0x1d634, 0x1d635, 0x1d636, 0x1d637, 0x1d638,\n        0x1d639, 0x1d63a, 0x1d63b, 0x1d63c, 0x1d63d, 0x1d63e, 0x1d63f, 0x1d640,\n        0x1d641, 0x1d642, 0x1d643, 0x1d644, 0x1d645, 0x1d646, 0x1d647, 0x1d648,\n        0x1d649, 0x1d64a, 0x1d64b, 0x1d64c, 0x1d64d, 0x1d64e, 0x1d64f, 0x1d650,\n        0x1d651, 0x1d652, 0x1d653, 0x1d654, 0x1d655, 0x1d656, 0x1d657, 0x1d658,\n        0x1d659, 0x1d65a, 0x1d65b, 0x1d65c, 0x1d65d, 0x1d65e, 0x1d65f, 0x1d660,\n        0x1d661, 0x1d662, 0x1d663, 0x1d664, 0x1d665, 0x1d666, 0x1d667, 0x1d668,\n        0x1d669, 0x1d66a, 0x1d66b, 0x1d66c, 0x1d66d, 0x1d66e, 0x1d66f, 0x1d670,\n        0x1d671, 0x1d672, 0x1d673, 0x1d674, 0x1d675, 0x1d676, 0x1d677, 0x1d678,\n        0x1d679, 0x1d67a, 0x1d67b, 0x1d67c, 0x1d67d, 0x1d67e, 0x1d67f, 0x1d680,\n        0x1d681, 0x1d682, 0x1d683, 0x1d684, 0x1d685, 0x1d686, 0x1d687, 0x1d688,\n        0x1d689, 0x1d68a, 0x1d68b, 0x1d68c, 0x1d68d, 0x1d68e, 0x1d68f, 0x1d690,\n        0x1d691, 0x1d692, 0x1d693, 0x1d694, 0x1d695, 0x1d696, 0x1d697, 0x1d698,\n        0x1d699, 0x1d69a, 0x1d69b, 0x1d69c, 0x1d69d, 0x1d69e, 0x1d69f, 0x1d6a0,\n        0x1d6a1, 0x1d6a2, 0x1d6a3, 0x1d6a4, 0x1d6a5, 0x1d6a8, 0x1d6a9, 0x1d6aa,\n        0x1d6ab, 0x1d6ac, 0x1d6ad, 0x1d6ae, 0x1d6af, 0x1d6b0, 0x1d6b1, 0x1d6b2,\n        0x1d6b3, 0x1d6b4, 0x1d6b5, 0x1d6b6, 0x1d6b7, 0x1d6b8, 0x1d6b9, 0x1d6ba,\n        0x1d6bb, 0x1d6bc, 0x1d6bd, 0x1d6be, 0x1d6bf, 0x1d6c0, 0x1d6c2, 0x1d6c3,\n        0x1d6c4, 0x1d6c5, 0x1d6c6, 0x1d6c7, 0x1d6c8, 0x1d6c9, 0x1d6ca, 0x1d6cb,\n        0x1d6cc, 0x1d6cd, 0x1d6ce, 0x1d6cf, 0x1d6d0, 0x1d6d1, 0x1d6d2, 0x1d6d3,\n        0x1d6d4, 0x1d6d5, 0x1d6d6, 0x1d6d7, 0x1d6d8, 0x1d6d9, 0x1d6da, 0x1d6dc,\n        0x1d6dd, 0x1d6de, 0x1d6df, 0x1d6e0, 0x1d6e1, 0x1d6e2, 0x1d6e3, 0x1d6e4,\n        0x1d6e5, 0x1d6e6, 0x1d6e7, 0x1d6e8, 0x1d6e9, 0x1d6ea, 0x1d6eb, 0x1d6ec,\n        0x1d6ed, 0x1d6ee, 0x1d6ef, 0x1d6f0, 0x1d6f1, 0x1d6f2, 0x1d6f3, 0x1d6f4,\n        0x1d6f5, 0x1d6f6, 0x1d6f7, 0x1d6f8, 0x1d6f9, 0x1d6fa, 0x1d6fc, 0x1d6fd,\n        0x1d6fe, 0x1d6ff, 0x1d700, 0x1d701, 0x1d702, 0x1d703, 0x1d704, 0x1d705,\n        0x1d706, 0x1d707, 0x1d708, 0x1d709, 0x1d70a, 0x1d70b, 0x1d70c, 0x1d70d,\n        0x1d70e, 0x1d70f, 0x1d710, 0x1d711, 0x1d712, 0x1d713, 0x1d714, 0x1d716,\n        0x1d717, 0x1d718, 0x1d719, 0x1d71a, 0x1d71b, 0x1d71c, 0x1d71d, 0x1d71e,\n        0x1d71f, 0x1d720, 0x1d721, 0x1d722, 0x1d723, 0x1d724, 0x1d725, 0x1d726,\n        0x1d727, 0x1d728, 0x1d729, 0x1d72a, 0x1d72b, 0x1d72c, 0x1d72d, 0x1d72e,\n        0x1d72f, 0x1d730, 0x1d731, 0x1d732, 0x1d733, 0x1d734, 0x1d736, 0x1d737,\n        0x1d738, 0x1d739, 0x1d73a, 0x1d73b, 0x1d73c, 0x1d73d, 0x1d73e, 0x1d73f,\n        0x1d740, 0x1d741, 0x1d742, 0x1d743, 0x1d744, 0x1d745, 0x1d746, 0x1d747,\n        0x1d748, 0x1d749, 0x1d74a, 0x1d74b, 0x1d74c, 0x1d74d, 0x1d74e, 0x1d750,\n        0x1d751, 0x1d752, 0x1d753, 0x1d754, 0x1d755, 0x1d756, 0x1d757, 0x1d758,\n        0x1d759, 0x1d75a, 0x1d75b, 0x1d75c, 0x1d75d, 0x1d75e, 0x1d75f, 0x1d760,\n        0x1d761, 0x1d762, 0x1d763, 0x1d764, 0x1d765, 0x1d766, 0x1d767, 0x1d768,\n        0x1d769, 0x1d76a, 0x1d76b, 0x1d76c, 0x1d76d, 0x1d76e, 0x1d770, 0x1d771,\n        0x1d772, 0x1d773, 0x1d774, 0x1d775, 0x1d776, 0x1d777, 0x1d778, 0x1d779,\n        0x1d77a, 0x1d77b, 0x1d77c, 0x1d77d, 0x1d77e, 0x1d77f, 0x1d780, 0x1d781,\n        0x1d782, 0x1d783, 0x1d784, 0x1d785, 0x1d786, 0x1d787, 0x1d788, 0x1d78a,\n        0x1d78b, 0x1d78c, 0x1d78d, 0x1d78e, 0x1d78f, 0x1d790, 0x1d791, 0x1d792,\n        0x1d793, 0x1d794, 0x1d795, 0x1d796, 0x1d797, 0x1d798, 0x1d799, 0x1d79a,\n        0x1d79b, 0x1d79c, 0x1d79d, 0x1d79e, 0x1d79f, 0x1d7a0, 0x1d7a1, 0x1d7a2,\n        0x1d7a3, 0x1d7a4, 0x1d7a5, 0x1d7a6, 0x1d7a7, 0x1d7a8, 0x1d7aa, 0x1d7ab,\n        0x1d7ac, 0x1d7ad, 0x1d7ae, 0x1d7af, 0x1d7b0, 0x1d7b1, 0x1d7b2, 0x1d7b3,\n        0x1d7b4, 0x1d7b5, 0x1d7b6, 0x1d7b7, 0x1d7b8, 0x1d7b9, 0x1d7ba, 0x1d7bb,\n        0x1d7bc, 0x1d7bd, 0x1d7be, 0x1d7bf, 0x1d7c0, 0x1d7c1, 0x1d7c2, 0x1d7c4,\n        0x1d7c5, 0x1d7c6, 0x1d7c7, 0x1d7c8, 0x1d7c9, 0x1d7ca, 0x1d7cb};\n}\n\nbool IsSymbolic(char c)\n{\n    for (const char* ptr = symbolics; *ptr; ++ptr)\n        if (*ptr == c)\n            return true;\n\n    return false;\n}\n\n// utility functions\n#ifdef YACAS_UINT32_T_IN_GLOBAL_NAMESPACE\nbool IsAlpha(uint32_t c)\n#else\nbool IsAlpha(std::uint32_t c)\n#endif\n{\n    return c == '\\'' || letters.find(c) != letters.end();\n}\n\n#ifdef YACAS_UINT32_T_IN_GLOBAL_NAMESPACE\nbool IsAlNum(uint32_t c)\n#else\nbool IsAlNum(std::uint32_t c)\n#endif\n{\n    return IsAlpha(c) || std::isdigit(c);\n}\n\nstd::string LispTokenizer::NextToken(LispInput& aInput)\n{\n#ifdef YACAS_UINT32_T_IN_GLOBAL_NAMESPACE\n    uint32_t c;\n#else\n    std::uint32_t c;\n#endif\n\n    // skip whitespaces and comments\n    for (;;) {\n        // End of stream: return empty string\n        if (aInput.EndOfStream())\n            return \"\";\n\n        c = aInput.Next();\n\n        if (std::isspace(c))\n            continue;\n\n        // parse comments\n        if (c == '/' && aInput.Peek() == '*') {\n            aInput.Next();\n            for (;;) {\n                while (aInput.Next() != '*' && !aInput.EndOfStream())\n                    ;\n\n                if (aInput.EndOfStream())\n                    throw LispErrCommentToEndOfFile();\n\n                if (aInput.Peek() == '/') {\n                    aInput.Next();\n                    break;\n                }\n            }\n\n            continue;\n        }\n\n        if (c == '/' && aInput.Peek() == '/') {\n            aInput.Next();\n            while (aInput.Next() != '\\n' && !aInput.EndOfStream())\n                ;\n            continue;\n        }\n\n        break;\n    }\n\n    // parse brackets\n    if (c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']')\n        return std::string(1, c);\n\n    // percent\n    if (c == '%')\n        return std::string(1, c);\n\n    // comma and semicolon\n    if (c == ',' || c == ';')\n        return std::string(1, c);\n\n    // parse . or ..\n    if (c == '.' && !std::isdigit(aInput.Peek())) {\n        std::string token;\n        token.push_back(c);\n        while (aInput.Peek() == '.')\n            token.push_back(aInput.Next());\n        return token;\n    }\n\n    // parse literal strings\n    if (c == '\\\"') {\n        std::string str;\n        utf8::append(c, std::back_inserter(str));\n        while (aInput.Peek() != '\\\"') {\n            if (aInput.Peek() == '\\\\') {\n                aInput.Next();\n                if (aInput.EndOfStream())\n                    throw LispErrParsingInput();\n                switch (aInput.Next()) {\n                    case '\\\"':\n                        str.push_back('\\\"');\n                        break;\n                    case '\\\\':\n                        str.push_back('\\\\');\n                        break;\n                    case 't':\n                        str.push_back('\\t');\n                        break;\n                    case 'n':\n                        str.push_back('\\n');\n                        break;\n                    default:\n                        throw LispErrParsingInput();\n                }\n            } else {\n                utf8::append(aInput.Next(), std::back_inserter(str));\n            }\n\n            if (aInput.EndOfStream())\n                throw LispErrParsingInput();\n        }\n        utf8::append(aInput.Next(), std::back_inserter(str));\n        return str;\n    }\n\n    // parse atoms\n    if (IsAlpha(c)) {\n        std::string atom;\n        utf8::append(c, std::back_inserter(atom));\n        while (IsAlNum(aInput.Peek()))\n            utf8::append(aInput.Next(), std::back_inserter(atom));\n        return atom;\n    }\n\n    // parse operators\n    if (IsSymbolic(c)) {\n        std::string op;\n        op.push_back(c);\n        while (IsSymbolic(aInput.Peek()))\n            op.push_back(aInput.Next());\n        return op;\n    }\n\n    // parse subscripts\n    if (c == '_') {\n        std::string token;\n        utf8::append(c, std::back_inserter(token));\n        while (aInput.Peek() == '_')\n            utf8::append(aInput.Next(), std::back_inserter(token));\n        return token;\n    }\n\n    // parse numbers\n    if (std::isdigit(c) || c == '.') {\n        std::string number;\n        number.push_back(c);\n\n        while (std::isdigit(aInput.Peek()))\n            number.push_back(aInput.Next());\n\n        if (aInput.Peek() == '.') {\n            number.push_back(aInput.Next());\n            while (std::isdigit(aInput.Peek()))\n                number.push_back(aInput.Next());\n        }\n\n        if (aInput.Peek() == 'e' || aInput.Peek() == 'E') {\n            number.push_back(aInput.Next());\n            if (aInput.Peek() == '-' || aInput.Peek() == '+')\n                number.push_back(aInput.Next());\n            while (std::isdigit(aInput.Peek()))\n                number.push_back(aInput.Next());\n        }\n\n        return number;\n    }\n\n    throw InvalidToken();\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/xmltokenizer.cpp",
    "content": "#include \"yacas/xmltokenizer.h\"\n#include \"yacas/lisperror.h\"\n\n#include <cctype>\n#include <iostream>\n\nstd::string XmlTokenizer::NextToken(LispInput& aInput)\n{\n    if (aInput.EndOfStream())\n        return \"\";\n\n    std::string leading_spaces;\n    while (std::isspace(aInput.Peek()))\n        leading_spaces.push_back(aInput.Next());\n\n    if (aInput.EndOfStream())\n        return \"\";\n\n    std::string s;\n\n    char c = aInput.Next();\n    s.push_back(c);\n\n    if (c == '<') {\n        while (c != '>') {\n            if (aInput.EndOfStream())\n                throw LispErrCommentToEndOfFile();\n\n            c = aInput.Next();\n\n            s.push_back(c);\n        }\n    } else {\n        while (aInput.Peek() != '<' && !aInput.EndOfStream())\n            s.push_back(aInput.Next());\n        s = leading_spaces + s;\n    }\n\n    return s;\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/yacasapi.cpp",
    "content": "\n#include \"yacas/mathcommands.h\"\n#include \"yacas/standard.h\"\n#include \"yacas/yacas.h\"\n\n#define OPERATOR(kind, prec, name)                                             \\\n    kind##operators[hash.LookUp(#name)] = LispInFixOperator(prec);\n\nDefaultYacasEnvironment::DefaultYacasEnvironment(std::ostream& os) :\n    output(os),\n    infixprinter(\n        prefixoperators, infixoperators, postfixoperators, bodiedoperators),\n    iEnvironment(coreCommands,\n                 userFunctions,\n                 globals,\n                 hash,\n                 output,\n                 infixprinter,\n                 prefixoperators,\n                 infixoperators,\n                 postfixoperators,\n                 bodiedoperators,\n                 protected_symbols,\n                 &input),\n    input(iEnvironment.iInputStatus)\n{\n    // Define the built-in functions by tying their string representation\n    // to a kernel callable routine.\n#define CORE_KERNEL_FUNCTION(iname, fname, nrargs, flags)                      \\\n    iEnvironment.SetCommand(fname, iname, nrargs, flags);\n#define CORE_KERNEL_FUNCTION_ALIAS(iname, fname, nrargs, flags)                \\\n    iEnvironment.SetCommand(fname, iname, nrargs, flags);\n#include \"yacas/corefunctions.h\"\n#undef CORE_KERNEL_FUNCTION\n#undef CORE_KERNEL_FUNCTION_ALIAS\n#undef OPERATOR\n}\n\nCYacas::CYacas(std::ostream& os) : environment(os) {}\n\nvoid CYacas::Evaluate(const std::string& aExpression)\n{\n    LispEnvironment& env = environment.getEnv();\n    int stackTop = env.iStack.size();\n\n    env.iErrorOutput.clear();\n    env.iErrorOutput.str(\"\");\n\n    std::ostringstream iResultOutput;\n\n    LispPtr result;\n\n    try {\n        LispPtr lispexpr;\n        // printf(\"Input: [%s]\\n\",aExpression);\n        if (env.PrettyReader()) {\n            const LispString* prettyReader = env.PrettyReader();\n            std::string full(aExpression);\n            full.push_back(';');\n            StringInput input(full, env.iInputStatus);\n            LispLocalInput localInput(env, &input);\n            LispPtr args(nullptr);\n            InternalApplyString(env, lispexpr, prettyReader, args);\n        } else {\n            LispString full(aExpression);\n            full.push_back(';');\n            StringInput input(full, env.iInputStatus);\n            env.iInputStatus.SetTo(\"CommandLine\");\n            LispTokenizer& tok = *env.iCurrentTokenizer;\n            InfixParser parser(tok,\n                               input,\n                               env,\n                               env.PreFix(),\n                               env.InFix(),\n                               env.PostFix(),\n                               env.Bodied());\n            parser.Parse(lispexpr);\n        }\n\n        env.iEvalDepth = 0;\n        env.iEvaluator->ResetStack();\n        env.iEvaluator->Eval(env, result, lispexpr);\n\n        // If no error encountered, print result\n        if (env.PrettyPrinter()) {\n            LispPtr nonresult;\n            InternalApplyString(env, nonresult, env.PrettyPrinter(), result);\n        } else {\n            InfixPrinter infixprinter(\n                env.PreFix(), env.InFix(), env.PostFix(), env.Bodied());\n\n            infixprinter.Print(result, iResultOutput, env);\n            iResultOutput.put(';');\n        }\n        const LispString* percent = env.HashTable().LookUp(\"%\");\n        env.UnProtect(percent);\n        env.SetVariable(percent, result, true);\n        env.Protect(percent);\n    } catch (const LispError& error) {\n        HandleError(error, env, env.iErrorOutput);\n    }\n\n    env.iStack.resize(stackTop);\n\n    _result = iResultOutput.str();\n    _error = env.iErrorOutput.str();\n}\n"
  },
  {
    "path": "cyacas/libyacas/src/yacasnumbers.cpp",
    "content": "/* Implementation of the number classes (the functionality used\n * by yacas any way\n */\n\n#include \"yacas/errors.h\"\n#include \"yacas/lisperror.h\"\n#include \"yacas/numbers.h\"\n#include \"yacas/platmath.h\"\n#include \"yacas/standard.h\"\n\n#include <algorithm>\n#include <iomanip>\n#include <iostream>\n#include <sstream>\n\nnamespace {\n    static LispObject*\n    FloatToString(ANumber& aInt, LispEnvironment& aEnvironment, int aBase = 10)\n    {\n        std::string result;\n        ANumberToString(result, aInt, aBase);\n        return LispAtom::New(aEnvironment, result);\n    }\n\n    static int CalculatePrecision(const std::string& str,\n                                  int aBasePrecision,\n                                  int aBase,\n                                  bool& aIsFloat)\n    {\n        const char* aString = str.c_str();\n        const char* ptr = aString;\n        while (*ptr) {\n            switch (*ptr) {\n            case '.':\n                goto FOUND_FLOAT_INDICATOR;\n            case 'e':\n            case 'E':\n            case '@':\n                if (aBase <= 10)\n                    goto FOUND_FLOAT_INDICATOR;\n                break;\n            }\n            ptr++;\n        }\n    FOUND_FLOAT_INDICATOR:\n        // decide whether the string is an integer or a float\n        if (*ptr) {\n            // converting to a float\n            // estimate the number of bits we need to have\n            // find the first significant digit:\n            // initial zeros are not significant\n            ptr = aString;\n            while (*ptr == '.' || *ptr == '-' || *ptr == '0')\n                ptr++;\n            int digit1 = ptr - aString;\n            // find the number of significant base digits (sig_digits)\n            // trailing zeros and . *are* significant, do not include them in\n            // the sets\n            int sig_digits; // = strcspn(aString+digit1, (aBase<=10) ? \"-eE@\" :\n                            // \"-@\");\n\n            while (*ptr) {\n                switch (*ptr) {\n                case '@':\n                case '-':\n                    goto FND_1;\n                case 'e':\n                case 'E':\n                    if (aBase <= 10)\n                        goto FND_1;\n                }\n                ptr++;\n            }\n        FND_1:\n            sig_digits = ptr - (aString + digit1);\n\n            if (sig_digits <= 0) { // this is when we have \"0.\" in various forms\n                // the number of digits is the number of trailing 0s after .\n\n                // the string cannot consist of only 0 and -, it must contain at\n                // least one of \".eE@\" for example, -0000000.000e10 has 4\n                // significant digits counting . as one of the digits, so that\n                // \"0\" will have 1 digit\n                ptr = aString;\n                while (*ptr == '-' || *ptr == '0')\n                    ptr++;\n                sig_digits = ptr - aString;\n\n                while (*ptr) {\n                    switch (*ptr) {\n                    case 'e':\n                    case 'E':\n                    case '@':\n                        goto FND_2;\n                    }\n                    ptr++;\n                }\n            FND_2:\n                sig_digits = ptr - (aString + sig_digits);\n            } else { // our number is nonzero\n                ptr = aString + digit1;\n                while (*ptr && *ptr != '.')\n                    ptr++;\n                if (*ptr == '.')\n                    --sig_digits; // this is when we have \"1.000001\" where \".\"\n                                  // is not a digit, so need to decrement\n            }\n            // ok, so we need to represent MAX(aPrecision,sig_digits) digits in\n            // base aBase\n            aIsFloat = true;\n            return (int)digits_to_bits(std::max(aBasePrecision, sig_digits),\n                                       aBase);\n        } else {\n            aIsFloat = false;\n            return 0;\n        }\n    }\n}\n\n/* Converting between internal formats and ascii format.\n * It is best done as little as possible. Usually, during calculations,\n * the ascii version of a number will not be required, so only the\n * internal version needs to be stored.\n */\n\nLispObject*\nGcdInteger(LispObject* int1, LispObject* int2, LispEnvironment& aEnvironment)\n{\n    BigNumber* i1 = int1->Number(0);\n    BigNumber* i2 = int2->Number(0);\n\n    BigNumber a(*i1);\n    BigNumber b(*i2);\n\n    if (!a.IsInt() && a.iNumber->iExp != 0)\n        throw LispErrNotInteger();\n\n    if (!b.IsInt() && b.iNumber->iExp != 0)\n        throw LispErrNotInteger();\n\n    a.BecomeInt();\n    b.BecomeInt();\n\n    BigNumber* res = new BigNumber(mp::gcd(*i1->_zz, *i2->_zz));\n    return new LispNumber(res);\n}\n\nLispObject* PowerFloat(LispObject* int1,\n                       LispObject* int2,\n                       LispEnvironment& aEnvironment,\n                       int aPrecision)\n{\n    if (int2->Number(aPrecision)->iNumber->iExp != 0)\n        throw LispErrNotInteger();\n\n    // Raising to the power of an integer can be done fastest by squaring\n    // and bitshifting: x^(a+b) = x^a*x^b . Then, regarding each bit\n    // in y (seen as a binary number) as added, the algorithm becomes:\n    //\n    ANumber x(*int1->Number(aPrecision)->iNumber);\n    ANumber y(*int2->Number(aPrecision)->iNumber);\n    const bool neg = y.iNegative;\n    y.iNegative = false;\n\n    // result <- 1\n    ANumber result(\"1\", aPrecision);\n    // base <- x\n    ANumber base(aPrecision);\n    base.CopyFrom(x);\n\n    ANumber copy(aPrecision);\n\n    // while (y!=0)\n    while (!y.IsZero()) {\n        // if (y&1 != 0)\n        if ((y[0] & 1) != 0) {\n            // result <- result*base\n            copy.CopyFrom(result);\n            Multiply(result, copy, base);\n        }\n        // base <- base*base\n        copy.CopyFrom(base);\n        Multiply(base, copy, copy);\n        // y <- y>>1\n        BaseShiftRight(y, 1);\n    }\n\n    if (neg) {\n        ANumber one(\"1\", aPrecision);\n        ANumber dummy(10);\n        copy.CopyFrom(result);\n        Divide(result, dummy, one, copy);\n    }\n\n    // result\n    return FloatToString(result, aEnvironment);\n}\n\nLispObject* ShiftLeft(LispObject* int1,\n                      LispObject* int2,\n                      LispEnvironment& aEnvironment,\n                      int aPrecision)\n{\n    BigNumber* number = new BigNumber(\"0\", aEnvironment.BinaryPrecision());\n    int bits = InternalAsciiToInt(*int2->String());\n    number->ShiftLeft(*int1->Number(aPrecision), bits);\n    return new LispNumber(number);\n}\n\nLispObject* ShiftRight(LispObject* int1,\n                       LispObject* int2,\n                       LispEnvironment& aEnvironment,\n                       int aPrecision)\n{\n    BigNumber* number = new BigNumber(\"0\", aEnvironment.BinaryPrecision());\n    int bits = InternalAsciiToInt(*int2->String());\n    number->ShiftRight(*int1->Number(aPrecision), bits);\n    return new LispNumber(number);\n}\n\nstatic void DivideInteger(ANumber& aQuotient,\n                          ANumber& aRemainder,\n                          const char* int1,\n                          const char* int2,\n                          int aPrecision)\n{\n    ANumber a1(int1, aPrecision);\n    ANumber a2(int2, aPrecision);\n\n    if (a1.iExp != 0 || a2.iExp != 0)\n        throw LispErrNotInteger();\n\n    if (a2.IsZero())\n        throw LispErrInvalidArg();\n\n    IntegerDivide(aQuotient, aRemainder, a1, a2);\n}\n\nLispObject* ModFloat(LispObject* int1,\n                     LispObject* int2,\n                     LispEnvironment& aEnvironment,\n                     int aPrecision)\n{\n    ANumber quotient(static_cast<int>(0));\n    ANumber remainder(static_cast<int>(0));\n    DivideInteger(quotient,\n                  remainder,\n                  int1->String()->c_str(),\n                  int2->String()->c_str(),\n                  aPrecision);\n    return FloatToString(remainder, aEnvironment, 10);\n}\n\nLispObject*\nLispFactorial(LispObject* int1, LispEnvironment& aEnvironment, int aPrecision)\n{\n    int nr = InternalAsciiToInt(*int1->String());\n\n    if (nr < 0)\n        throw LispErrInvalidArg();\n\n    ANumber fac(\"1\", aPrecision);\n    int i;\n    for (i = 2; i <= nr; i++)\n        BaseTimesInt(fac, i, WordBase);\n\n    return FloatToString(fac, aEnvironment);\n}\n\nBigNumber::BigNumber(const std::string& aString, int aBasePrecision, int aBase)\n{\n    bool isFloat = false;\n\n    const int digits = aBasePrecision;\n    iPrecision = CalculatePrecision(aString, aBasePrecision, aBase, isFloat);\n\n    iNumber.reset(new ANumber(aString, digits, aBase));\n\n    if (!isFloat && iNumber->iExp == 0 && iNumber->iTensExp == 0) {\n        _zz.reset(new mp::ZZ(aString, aBase));\n        iNumber.release();\n    }\n}\n\nBigNumber::BigNumber(const mp::ZZ& zz) : iPrecision(0), _zz(new mp::ZZ(zz)) {}\n\nBigNumber::BigNumber(const BigNumber& aOther) :\n    iPrecision(aOther.GetPrecision())\n{\n    if (aOther.iNumber)\n        iNumber.reset(new ANumber(*aOther.iNumber));\n\n    if (aOther._zz)\n        _zz.reset(new mp::ZZ(*aOther._zz));\n}\n\nBigNumber& BigNumber::operator=(const BigNumber& bn)\n{\n    if (this == &bn)\n        return *this;\n\n    iPrecision = bn.GetPrecision();\n\n    if (bn.iNumber) {\n        if (iNumber)\n            iNumber->CopyFrom(*bn.iNumber);\n        else\n            iNumber.reset(new ANumber(*bn.iNumber));\n\n        _zz.reset();\n    }\n\n    if (bn._zz) {\n        if (_zz)\n            *_zz = *bn._zz;\n        else\n            _zz.reset(new mp::ZZ(*bn._zz));\n\n        iNumber.reset();\n    }\n    return *this;\n}\n\n/// Export a number to a string in given base to given base digits\n// FIXME API breach: aPrecision is supposed to be in digits, not bits\nvoid BigNumber::ToString(std::string& aResult,\n                         int aBasePrecision,\n                         int aBase) const\n{\n    if (_zz) {\n        aResult = _zz->to_string(aBase);\n        return;\n    }\n\n    ANumber num(*iNumber);\n\n    // TODO this round-off code is not correct yet, but will work in most cases\n    // This is a bit of a messy way to round off numbers. It is probably\n    // incorrect, even. When precision drops one digit, it rounds off the last\n    // ten digits. So the following code is probably only correct if\n    // aPrecision>=num.iPrecision or if aPrecision < num.iPrecision-10\n    if (aBasePrecision < num.iPrecision) {\n        if (num.iExp > 1)\n            num.RoundBits();\n    }\n    num.ChangePrecision(aBasePrecision);\n\n    if (!IsInt()) {\n        for (;;) {\n\n            const int ns = num.size();\n            bool greaterOne = false;\n            if (num.iExp >= int(ns))\n                break;\n            for (int i = num.iExp; i < ns; i++) {\n                if (num[i] != 0) {\n                    if (!(i == num.iExp && num[i] < 10000 &&\n                          num.iTensExp == 0)) {\n                        greaterOne = true;\n                        break;\n                    }\n                }\n            }\n            if (!greaterOne)\n                break;\n            PlatDoubleWord carry = 0;\n            BaseDivideInt(num, 10, WordBase, carry);\n            num.iTensExp++;\n        }\n    }\n\n    ANumberToString(aResult, num, aBase, !_zz);\n}\n\ndouble BigNumber::Double() const\n{\n    std::string str;\n\n    if (IsInt()) {\n        str = _zz->to_string();\n    } else {\n        ANumber num(*iNumber);\n        ANumberToString(str, num, 10);\n    }\n\n    std::istringstream is(str);\n    double d;\n    is >> d;\n    return d;\n}\n\nvoid BigNumber::Multiply(const BigNumber& aX,\n                         const BigNumber& aY,\n                         int aPrecision)\n{\n    if (aX.IsInt() && aY.IsInt()) {\n        BecomeInt();\n        *_zz = *aX._zz;\n        *_zz *= *aY._zz;\n\n        return;\n    }\n\n    if (aPrecision < aX.GetPrecision())\n        aPrecision = aX.GetPrecision();\n\n    if (aPrecision < aY.GetPrecision())\n        aPrecision = aY.GetPrecision();\n\n    BecomeFloat(bits_to_digits(aPrecision, 10));\n\n    BigNumber x(aX);\n    x.BecomeFloat(aPrecision);\n    BigNumber y(aY);\n    y.BecomeFloat(aPrecision);\n\n    ANumber a1(*x.iNumber);\n    ANumber a2(*y.iNumber);\n    ::Multiply(*iNumber, a1, a2);\n}\n\nvoid BigNumber::Add(const BigNumber& aX, const BigNumber& aY, int aPrecision)\n{\n    if (aX.IsInt() && aY.IsInt()) {\n        BecomeInt();\n        *_zz = *aX._zz;\n        *_zz += *aY._zz;\n        return;\n    }\n\n\n    if (aPrecision < aX.GetPrecision())\n        aPrecision = aX.GetPrecision();\n    if (aPrecision < aY.GetPrecision())\n        aPrecision = aY.GetPrecision();\n\n    BecomeFloat(aPrecision);\n\n    BigNumber x(aX);\n    BigNumber y(aY);\n\n    x.BecomeFloat(aPrecision);\n    y.BecomeFloat(aPrecision);\n\n\n    ::Add(*iNumber, *x.iNumber, *y.iNumber);\n\n    iNumber->SetPrecision(aPrecision);\n}\n\nvoid BigNumber::Negate(const BigNumber& aX)\n{\n    if (this == &aX) {\n        if (IsInt())\n            _zz->neg();\n        else\n            iNumber->Negate();\n\n        return;\n    }\n    if (aX.IsInt()) {\n        BecomeInt();\n        *_zz = *aX._zz;\n        _zz->neg();\n    } else {\n        BecomeFloat(aX.iPrecision);\n        iNumber->CopyFrom(*aX.iNumber);\n        iNumber->Negate();\n    }\n}\n\nvoid BigNumber::Divide(const BigNumber& aX, const BigNumber& aY, int aPrecision)\n{\n    if (aX.IsInt() && aY.IsInt()) {\n        if (aY._zz->is_zero())\n            throw LispErrInvalidArg();\n\n        BecomeInt();\n        _zz.reset(new mp::ZZ(*aX._zz));\n        *_zz /= *aY._zz;\n    } else {\n        int aPrecision = iPrecision;\n\n        if (aPrecision < aX.GetPrecision())\n            aPrecision = aX.GetPrecision();\n        if (aPrecision < aY.GetPrecision())\n            aPrecision = aY.GetPrecision();\n\n        int digitPrecision = bits_to_digits(aPrecision, 10);\n        BecomeFloat(aPrecision);\n\n        BigNumber x(aX);\n        x.BecomeFloat(digitPrecision);\n        BigNumber y(aY);\n        y.BecomeFloat(digitPrecision);\n\n        iPrecision = aPrecision;\n        iNumber->iPrecision = digitPrecision;\n\n        ANumber a1(*x.iNumber);\n        a1.ChangePrecision(digitPrecision);\n        ANumber a2(*y.iNumber);\n        a2.ChangePrecision(digitPrecision);\n        ANumber remainder(digitPrecision);\n\n        if (a2.IsZero())\n            throw LispErrInvalidArg();\n\n        ::Divide(*iNumber, remainder, a1, a2);\n    }\n}\n\nvoid BigNumber::ShiftLeft(const BigNumber& aX, int aNrToShift)\n{\n    if (this != &aX)\n        *this = aX;\n\n    BecomeInt();\n\n    *_zz <<= aNrToShift;\n}\n\nvoid BigNumber::ShiftRight(const BigNumber& aX, int aNrToShift)\n{\n    if (this != &aX)\n        *this = aX;\n\n    BecomeInt();\n\n    *_zz >>= aNrToShift;\n}\n\nvoid BigNumber::BitAnd(const BigNumber& aX, const BigNumber& aY)\n{\n    BecomeInt();\n\n    BigNumber x(aX);\n    x.BecomeInt();\n    BigNumber y(aY);\n    y.BecomeInt();\n\n    *_zz = *x._zz;\n    *_zz &= *y._zz;\n}\n\nvoid BigNumber::BitOr(const BigNumber& aX, const BigNumber& aY)\n{\n    BecomeInt();\n\n    BigNumber x(aX);\n    x.BecomeInt();\n    BigNumber y(aY);\n    y.BecomeInt();\n\n    *_zz = *x._zz;\n    *_zz |= *y._zz;\n    _zz->abs();\n}\n\nvoid BigNumber::BitXor(const BigNumber& aX, const BigNumber& aY)\n{\n    BecomeInt();\n\n    BigNumber x(aX);\n    x.BecomeInt();\n    BigNumber y(aY);\n    y.BecomeInt();\n\n    *_zz = *x._zz;\n    *_zz ^= *y._zz;\n    _zz->abs();\n}\n\nvoid BigNumber::BitNot(const BigNumber& aX)\n{\n    BecomeInt();\n\n    BigNumber x(aX);\n    x.BecomeInt();\n\n    *_zz = *x._zz;\n    _zz->neg();\n    _zz->abs();\n}\n\n/// Bit count operation: return the number of significant bits if integer,\n/// return the binary exponent if float (shortcut for binary logarithm)\n// give BitCount as platform integer\nsigned long BigNumber::BitCount() const\n{\n    if (_zz) {\n        if (_zz->is_zero())\n            return 0;\n        return _zz->no_bits();\n    }\n\n    if (iNumber->IsZero())\n        return 0; //-(1L<<30);\n\n    ANumber num(*iNumber);\n\n    if (num.iTensExp < 0) {\n        int digs = WordDigits(num.iPrecision, 10);\n        PlatWord zero = 0;\n        while (num.iExp < digs) {\n            num.insert(num.begin(), zero);\n            num.iExp++;\n        }\n    }\n    while (num.iTensExp < 0) {\n        PlatDoubleWord carry = 0;\n        BaseDivideInt(num, 10, WordBase, carry);\n        num.iTensExp++;\n    }\n    while (num.iTensExp > 0) {\n        BaseTimesInt(num, 10, WordBase);\n        num.iTensExp--;\n    }\n\n    int i, nr = num.size();\n    for (i = nr - 1; i >= 0; i--)\n        if (num[i] != 0)\n            break;\n\n    int bits = (i - num.iExp) * sizeof(PlatWord) * 8;\n    if (i >= 0) {\n        PlatWord w = num[i];\n        while (w) {\n            w >>= 1;\n            bits++;\n        }\n    }\n    return (bits);\n}\n\nint BigNumber::Sign() const\n{\n    if (IsInt()) {\n        if (_zz->is_negative())\n            return -1;\n        if (_zz->is_zero())\n            return 0;\n        return 1;\n    }\n\n    if (iNumber->iNegative)\n        return -1;\n    if (iNumber->IsZero())\n        return 0;\n    return 1;\n}\n\nvoid BigNumber::DumpDebugInfo(std::ostream& os) const\n{\n    if (!iNumber)\n        os << \"No number representation\\n\";\n    else\n        iNumber->Print(os, \"Number:\");\n}\n\nvoid BigNumber::Floor(const BigNumber& aX)\n{\n    if (aX.IsInt()) {\n        BecomeInt();\n        *_zz = *aX._zz;\n\n        return;\n    }\n\n    iNumber->CopyFrom(*aX.iNumber);\n    //  If iExp is zero, then we can not look at the decimals and determine the\n    //  floor.\n    // This number has to have digits (see code later in this routine that does\n    // a division). Not extending the digits caused the MathFloor function to\n    // fail on n*10-m where n was an integer. The code below divides away the\n    // 10^-m, but since iExp was zero, this resulted in a premature truncation\n    // (seen when n<0)\n    if (iNumber->iExp == 0)\n        iNumber->ChangePrecision(iNumber->iPrecision);\n\n    if (iNumber->iExp > 1)\n        iNumber->RoundBits();\n\n    // TODO FIXME slow code! But correct\n    if (iNumber->iTensExp > 0) {\n        while (iNumber->iTensExp > 0) {\n            BaseTimesInt(*iNumber, 10, WordBase);\n            iNumber->iTensExp--;\n        }\n    } else if (iNumber->iTensExp < 0) {\n        while (iNumber->iTensExp < 0) {\n            PlatDoubleWord carry;\n            BaseDivideInt(*iNumber, 10, WordBase, carry);\n            iNumber->iTensExp++;\n        }\n    }\n    iNumber->ChangePrecision(iNumber->iPrecision);\n    int i = 0;\n    int fraciszero = true;\n    while (i < iNumber->iExp && fraciszero) {\n        PlatWord digit = (*iNumber)[i];\n        if (digit != 0)\n            fraciszero = false;\n        i++;\n    }\n    iNumber->erase(iNumber->begin(), iNumber->begin() + iNumber->iExp);\n    iNumber->iExp = 0;\n\n    if (iNumber->iNegative && !fraciszero) {\n        ANumber orig(*iNumber);\n        ANumber minone(\"-1\", 10);\n        ::Add(*iNumber, orig, minone);\n    }\n\n    BecomeInt();\n}\n\nvoid BigNumber::Precision(int aPrecision)\n{ // FIXME\n    if (aPrecision < 0)\n        aPrecision = 0;\n\n    if (iNumber && aPrecision > iPrecision)\n        iNumber->ChangePrecision(bits_to_digits(aPrecision, 10));\n\n    iPrecision = aPrecision;\n}\n\n// basic object manipulation\nbool BigNumber::Equals(const BigNumber& aOther) const\n{\n    if (IsInt() && aOther.IsInt())\n        return *_zz == *aOther._zz;\n\n    if (aOther.IsInt() && aOther._zz->is_zero()) {\n        BigNumber x(*this);\n        std::string s;\n        x.ToString(s, iPrecision);\n    }\n\n    if (IsInt() && _zz->is_zero()) {\n        BigNumber x(aOther);\n        std::string s;\n        x.ToString(s, iPrecision);\n    }\n\n    BigNumber x(*this);\n    BigNumber y(aOther);\n\n    int precision = std::max(x.iPrecision, y.iPrecision);\n\n    x.BecomeFloat(precision);\n    y.BecomeFloat(precision);\n\n    if (x.iNumber->iExp == y.iNumber->iExp) {\n        x.iNumber->DropTrailZeroes();\n        y.iNumber->DropTrailZeroes();\n\n        if (x.iNumber->IsZero())\n            x.iNumber->iNegative = false;\n        if (y.iNumber->IsZero())\n            y.iNumber->iNegative = false;\n        if (x.iNumber->ExactlyEqual(*y.iNumber))\n            return true;\n        if (IsInt())\n            return false;\n        if (aOther.Sign() != Sign())\n            return false;\n    }\n\n    {\n        // TODO optimize!!!!\n        /*For tiny numbers like 1e-600, the following seemed necessary to\n    compare it with zero. if (precision< (35*-iNumber->iTensExp)/10) precision =\n    (35*-iNumber->iTensExp)/10; if (precision<\n    (35*-aOther.iNumber->iTensExp)/10) precision =\n    (35*-aOther.iNumber->iTensExp)/10;\n*/\n        BigNumber diff(\"0\", precision);\n        BigNumber otherNeg(aOther);\n        otherNeg.Negate(aOther);\n        diff.Add(*this, otherNeg, bits_to_digits(precision, 10));\n\n        // if the numbers are float, make sure they are normalized\n        if (diff.iNumber->iExp || diff.iNumber->iTensExp) {\n            int pr = diff.iNumber->iPrecision;\n            if (pr < iPrecision)\n                pr = iPrecision;\n            if (pr < aOther.iPrecision)\n                pr = aOther.iPrecision;\n            NormalizeFloat(*diff.iNumber, WordDigits(pr, 10));\n        }\n\n        return !Significant(*diff.iNumber);\n    }\n}\n\nbool BigNumber::IsInt() const\n{\n    return !!_zz;\n}\n\nbool BigNumber::IsSmall() const\n{\n    if (IsInt()) {\n        return _zz->no_bits() <= 53;\n        // PlatWord* ptr = &((*iNumber)[iNumber->size() - 1]);\n        // int nr = iNumber->size();\n        // while (nr > 1 && *ptr == 0) {\n        //     ptr--;\n        //     nr--;\n        // }\n        // return (nr <= iNumber->iExp + 1);\n    } else\n    // a function to test smallness of a float is not present in ANumber, need\n    // to code a workaround to determine whether a number fits into double.\n    {\n        int tensExp = iNumber->iTensExp;\n        if (tensExp < 0)\n            tensExp = -tensExp;\n        return (iNumber->iPrecision <= 53 // standard float is 53 bits\n                && tensExp < 1021 // 306  // 1021 bits is about 306 decimals\n        );\n        // standard range of double precision is about 53 bits of mantissa and\n        // binary exponent of about 1021\n    }\n}\n\nvoid BigNumber::BecomeInt()\n{\n    if (IsInt())\n        return;\n\n    while (iNumber->iTensExp > 0) {\n        BaseTimesInt(*iNumber, 10, WordBase);\n        iNumber->iTensExp--;\n    }\n    while (iNumber->iTensExp < 0) {\n        PlatDoubleWord carry = 0;\n        BaseDivideInt(*iNumber, 10, WordBase, carry);\n        iNumber->iTensExp++;\n    }\n\n    iNumber->ChangePrecision(0);\n\n    ANumber a = *iNumber;\n    std::string s;\n    ANumberToString(s, a, 10, false);\n\n    _zz.reset(new mp::ZZ(s));\n    iNumber.release();\n}\n\n/// Transform integer to float, setting a given bit precision.\n/// Note that aPrecision=0 means automatic setting (just enough digits to\n/// represent the integer).\nvoid BigNumber::BecomeFloat(int aPrecision)\n{ // FIXME: need to specify precision explicitly\n    if (!IsInt())\n        return;\n\n    const int precision = std::max(iPrecision, aPrecision);\n    iNumber.reset(new ANumber(\n        _zz->to_string(),\n        bits_to_digits(precision, 10))); // is this OK or ChangePrecision means\n                                         // floating-point precision?\n\n    _zz.release();\n}\n\nbool BigNumber::LessThan(const BigNumber& aOther) const\n{\n    if (IsInt() && aOther.IsInt())\n        return *_zz < *aOther._zz;\n\n    BigNumber x(*this);\n    BigNumber y(aOther);\n\n    const int precision = std::max(x.iPrecision, y.iPrecision);\n\n    x.BecomeFloat(precision);\n    y.BecomeFloat(precision);\n\n    ANumber a1(*x.iNumber);\n    ANumber a2(*y.iNumber);\n    return ::LessThan(a1, a2);\n}\n"
  },
  {
    "path": "cyacas/libyacas_mp/CMakeLists.txt",
    "content": "#\n#\n# This file is part of yacas.\n# Yacas is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesset General Public License as\n# published by the Free Software Foundation, either version 2.1\n# of the License, or (at your option) any later version.\n#\n# Yacas is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n#\n#\n\nset (SOURCES\n  src/limbs_vector.cpp\n  src/nn.cpp\n  src/zz.cpp\n  src/rr.cpp)\n\nset (HEADERS\n  include/yacas/mp/limbs_vector.hpp\n  include/yacas/mp/nn.hpp\n  include/yacas/mp/zz.hpp\n  include/yacas/mp/rr.hpp)\n\n\nadd_library (libyacas_mp ${SOURCES} ${HEADERS})\nset_target_properties (libyacas_mp PROPERTIES OUTPUT_NAME \"yacas_mp\"  INTERPROCEDURAL_OPTIMIZATION ${IPO_SUPPORTED})\ntarget_include_directories (libyacas_mp PUBLIC include)\ntarget_link_libraries(libyacas_mp PUBLIC coverage_config)\n\ninstall (TARGETS libyacas_mp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\n                             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}\n                             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT app)\ninstall (DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT dev)\n\n# if (APPLE)\n#   add_library (libyacas_mp_framework SHARED ${SOURCES} ${HEADERS})\n#   set_target_properties(libyacas_mp_framework PROPERTIES OUTPUT_NAME \"yacas_mp\" VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION} FRAMEWORK ON)\n#   target_include_directories (libyacas_mp_framework PUBLIC include)\n#   add_custom_command(TARGET libyacas_mp_framework POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include $<TARGET_FILE_DIR:libyacas_mp_framework>/Headers)\n#   add_custom_command(TARGET libyacas_mp_framework POST_BUILD COMMAND cd \"$<TARGET_FILE_DIR:libyacas_mp_framework>/../..\" && rm -f Headers && ln -s Versions/Current/Headers Headers)\n#   install (TARGETS libyacas_mp_framework FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT framework)\n# endif()\n\n\nif (ENABLE_CYACAS_BENCHMARKS)\n    add_subdirectory (benchmark)\nendif ()\n\nif (ENABLE_CYACAS_UNIT_TESTS)\n    add_subdirectory (test)\nendif ()\n"
  },
  {
    "path": "cyacas/libyacas_mp/benchmark/CMakeLists.txt",
    "content": "#\n#\n# This file is part of yacas.\n# Yacas is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesset General Public License as\n# published by the Free Software Foundation, either version 2.1\n# of the License, or (at your option) any later version.\n#\n# Yacas is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n#\n#\n\nfind_package (Threads REQUIRED)\nfind_package (benchmark REQUIRED)\n\nadd_executable (yacas_mp_nn_benchmark src/nn_benchmark.cpp)\ntarget_link_libraries (yacas_mp_nn_benchmark libyacas_mp benchmark::benchmark benchmark::benchmark_main Threads::Threads)\n\nadd_custom_target(bench COMMAND yacas_mp_nn_benchmark --benchmark_min_time=0.1)\n"
  },
  {
    "path": "cyacas/libyacas_mp/benchmark/src/nn_benchmark.cpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#include \"yacas/mp/nn.hpp\"\n\n#include <benchmark/benchmark.h>\n\n#include <algorithm>\n\nstd::mt19937_64 rng;\n\nusing namespace yacas::mp;\n\nstd::string random_string(std::size_t length)\n{\n    auto randchar = []() -> char\n    {\n        const char charset[] = \"0123456789\";\n        const size_t max_index = (sizeof(charset) - 1);\n        return charset[rand() % max_index];\n    };\n    std::string str(length, 0);\n    std::generate_n(str.begin(), length, randchar);\n    return str;\n}\n\nstatic void BM_NN_construct_random(benchmark::State& state)\n{\n    for (auto _: state) {\n        NN b(state.range(), rng);\n    }\n    state.SetComplexityN(state.range());\n}\n\nstatic void BM_NN_parse(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        const std::string s = random_string(state.range());\n        state.ResumeTiming();\n        NN b(s);\n    }\n    state.SetComplexityN(state.range());\n}\n\nstatic void BM_NN_to_string(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(state.range(0), rng);\n        state.ResumeTiming();\n        a.to_string(10);\n    }\n    state.SetComplexityN(state.range());\n}\n\nstatic void BM_NN_shift_left(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(state.range(0), rng);\n        state.ResumeTiming();\n        a <<= state.range(1);\n    }\n    state.SetComplexityN(state.range(0));\n}\n\nstatic void BM_NN_add(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(state.range(0), rng);\n        NN b(state.range(1), rng);\n        state.ResumeTiming();\n        a += b;\n    }\n    state.SetComplexityN(std::min(state.range(0), state.range(1)));\n}\n\nstatic void BM_NN_add_self(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(state.range(0), rng);\n        state.ResumeTiming();\n        a += a;\n    }\n    state.SetComplexityN(state.range());\n}\n\nstatic void BM_NN_add_same(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(random_string(state.range(0)));\n        NN b(random_string(state.range(0)));\n        state.ResumeTiming();\n        a += b;\n    }\n    state.SetComplexityN(state.range());\n}\n\n\nstatic void BM_NN_sqr(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(random_string(state.range(0)));\n        state.ResumeTiming();\n        a.sqr();\n    }\n    state.SetComplexityN(state.range());\n}\n\nstatic void BM_NN_mul_same(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(random_string(state.range(0)));\n        NN b(random_string(state.range(0)));\n        state.ResumeTiming();\n        a *= b;\n    }\n    state.SetComplexityN(state.range());\n}\n\nstatic void BM_NN_mul(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(random_string(state.range(0)));\n        NN b(random_string(state.range(1)));\n        state.ResumeTiming();\n        a *= b;\n    }\n    state.SetComplexityN(state.range(0) * state.range(1));\n}\n\nstatic void BM_NN_div(benchmark::State& state)\n{\n    for (auto _: state) {\n        state.PauseTiming();\n        NN a(random_string(state.range(0)));\n        NN b(random_string(state.range(1)));\n        if (b.is_zero())\n            b = NN::ONE;\n        state.ResumeTiming();\n        a /= b;\n    }\n    state.SetComplexityN(state.range(0));\n}\n\n\nBENCHMARK(BM_NN_construct_random)->Range(1, 1<<16)->Complexity();\nBENCHMARK(BM_NN_parse)->Range(1, 1<<14)->Complexity();\nBENCHMARK(BM_NN_to_string)->Range(1, 1 << 16);\nBENCHMARK(BM_NN_shift_left)->Ranges({{1, 1<<8}, {1, 1<<8}});\nBENCHMARK(BM_NN_add)->Ranges({{1, 1<<8}, {1, 1<<8}});\nBENCHMARK(BM_NN_add_self)->Range(1, 16);\nBENCHMARK(BM_NN_add_self)->Range(16, 1<<10);\nBENCHMARK(BM_NN_add_same)->Range(1, 16);\nBENCHMARK(BM_NN_add_same)->Range(16, 1<<10);\nBENCHMARK(BM_NN_sqr)->Range(1, 1<<16);\nBENCHMARK(BM_NN_mul_same)->Range(1, 16);\nBENCHMARK(BM_NN_mul_same)->Range(16, 1<<10);\nBENCHMARK(BM_NN_mul)->Ranges({{1, 1<<8}, {1, 1<<8}});\nBENCHMARK(BM_NN_div)->Ranges({{1, 1<<8}, {1, 1<<8}});\n\nBENCHMARK_MAIN();\n"
  },
  {
    "path": "cyacas/libyacas_mp/include/yacas/mp/limbs_vector.hpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#ifndef YACAS_MP_LIMBS_VECTOR_HPP\n#define YACAS_MP_LIMBS_VECTOR_HPP\n\n#include <array>\n#include <compare>\n#include <cstdint>\n#include <memory>\n#include <variant>\n\nnamespace yacas::mp {\n    /// @brief A vector of limbs.\n    /// @details This class is a simple vector of limbs. It is used to store the\n    /// limbs of a multi-precision integer. It is implemented as a small buffer\n    /// optimization. If the number of limbs is less than or equal to 2, the\n    /// limbs are stored in a std::array. Otherwise, the limbs are stored in a\n    /// std::unique_ptr. This allows the class to avoid dynamic memory\n    /// allocation for small numbers of limbs. The class provides a simple\n    /// interface for manipulating the limbs, including iterators, push_back,\n    /// pop_back, and resizing. The class also provides a swap method for\n    /// efficiently swapping the contents of two LimbsVector objects. The class\n    /// is also comparable and hashable.\n    class LimbsVector {\n    public:\n        typedef std::uint32_t Limb;\n        typedef std::uint64_t Limb2;\n\n        typedef Limb value_type;\n\n        typedef std::uint32_t size_type;\n        typedef std::int32_t difference_type;\n\n        typedef value_type* iterator;\n        typedef const value_type* const_iterator;\n        typedef std::reverse_iterator<iterator> reverse_iterator;\n        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;\n\n        /// @brief Default constructor.\n        /// @details Constructs an empty LimbsVector.\n        LimbsVector() noexcept;\n\n        /// @brief Constructor from an initializer list.\n        /// @details Constructs a LimbsVector from an initializer list of limbs.\n        LimbsVector(const std::initializer_list<Limb>& limbs);\n\n        /// @brief Constructor from a size and a value.\n        /// @details Constructs a LimbsVector of a given size, with all limbs\n        /// initialized to a given value.\n        LimbsVector(std::size_t n, Limb value);\n\n        /// @brief Copy constructor.\n        /// @details Constructs a LimbsVector from another LimbsVector.\n        explicit LimbsVector(const LimbsVector& limbs);\n\n        /// @brief Move constructor.\n        /// @details Constructs a LimbsVector by moving the contents of another\n        /// LimbsVector.\n        explicit LimbsVector(LimbsVector&& limbs) noexcept;\n\n        /// @brief Constructor from a range.\n        /// @details Constructs a LimbsVector from a range of limbs.\n        template <typename Container>\n        explicit LimbsVector(const Container& container)\n        {\n            for (const auto& limb : container)\n                push_back(limb);\n        }\n\n        /// @brief Destructor.\n        ~LimbsVector() = default;\n\n        /// @brief Comparison operator.\n        /// @details Compares two LimbsVector objects for ordering. The\n        /// comparison is lexicographical, with the most significant limb\n        /// compared first.\n        std::strong_ordering\n        operator<=>(const LimbsVector& that) const noexcept;\n\n        /// @brief Equality comparison.\n        /// @details Compares two LimbsVector objects for equality.\n        bool operator==(const LimbsVector& that) const noexcept;\n\n        /// @brief Inequality comparison.\n        /// @details Compares two LimbsVector objects for inequality.\n        bool operator!=(const LimbsVector& that) const noexcept;\n\n        /// @brief Assignment operator.\n        /// @details Assigns the contents of another LimbsVector to this one.\n        LimbsVector& operator=(const LimbsVector& other);\n\n        /// @brief Move assignment operator.\n        /// @details Moves the contents of another LimbsVector to this one.\n        LimbsVector& operator=(LimbsVector&& other) noexcept;\n\n        template <typename InputIterator>\n        void assign(InputIterator b, InputIterator e)\n        {\n            clear();\n            for (auto it = b; it != e; ++it)\n                push_back(*it);\n        }\n\n        /// @brief Swaps the contents of two LimbsVector objects.\n        /// @details Swaps the contents of two LimbsVector objects in constant\n        /// time.\n        void swap(LimbsVector& other) noexcept;\n\n        /// @brief Inserts a value at a given position.\n        /// @details Inserts n copies of a value at a given position in the\n        void insert(iterator b, std::size_t n, Limb value);\n\n        /// @brief Erases a range of values.\n        /// @details Erases a range of values from the LimbsVector.\n        void erase(iterator b, iterator e);\n\n        /// @brief Returns an iterator to the beginning of the LimbsVector.\n        iterator begin() noexcept;\n        /// @brief Returns an iterator to the end of the LimbsVector.\n        iterator end() noexcept;\n\n        /// @brief Returns a const iterator to the beginning of the LimbsVector.\n        const_iterator begin() const noexcept;\n        /// @brief Returns a const iterator to the end of the LimbsVector.\n        const_iterator end() const noexcept;\n\n        /// @brief Returns a const iterator to the beginning of the LimbsVector.\n        const_iterator cbegin() const;\n        /// @brief Returns a const iterator to the end of the LimbsVector.\n        const_iterator cend() const;\n\n        /// @brief Returns a reverse iterator to the beginning of the\n        /// LimbsVector.\n        reverse_iterator rbegin();\n        /// @brief Returns a reverse iterator to the end of the LimbsVector.\n        reverse_iterator rend();\n\n        /// @brief Returns a const reverse iterator to the beginning of the\n        /// LimbsVector.\n        const_reverse_iterator crbegin() const;\n        /// @brief Returns a const reverse iterator to the end of the\n        /// LimbsVector.\n        const_reverse_iterator crend() const;\n\n        /// @brief Clears the LimbsVector.\n        /// @details Removes all limbs from the LimbsVector.\n        void clear();\n\n        /// @brief Returns the number of limbs in the LimbsVector.\n        std::size_t size() const noexcept;\n\n        /// @brief Returns true if the vector is empty, false otherwise.\n        bool empty() const noexcept;\n\n        /// @brief Appends a limb to the end of the LimbsVector.\n        void push_back(Limb limb);\n\n        /// @brief Removes the last limb from the LimbsVector.\n        void pop_back();\n\n        /// @brief Resizes the LimbsVector.\n        /// @details Resizes the LimbsVector to a given size. If the new size is\n        /// greater than the current size, the new limbs are initialized to a\n        /// given value. If the new size is less than the current size, the\n        /// extra limbs are removed.\n        void resize(std::size_t n, Limb value = 0);\n\n        /// @brief Reserves space for a given number of limbs.\n        /// @details Reserves space for a given number of limbs. If the new\n        /// capacity is greater than the current capacity, the capacity is\n        /// increased. If the new capacity is less than the current capacity,\n        /// the capacity is decreased.\n        void reserve(std::size_t new_capacity);\n\n        /// @brief Returns a pointer to the underlying data.\n        Limb* data();\n        /// @brief Returns a pointer to the underlying data.\n        const Limb* data() const;\n\n        /// @brief Returns a reference to the limb at a given index.\n        /// @details Returns a reference to the limb at a given index. The index\n        /// must be less than the size of the LimbsVector.\n        Limb& operator[](std::size_t index);\n        const Limb& operator[](std::size_t index) const;\n\n        /// @brief Returns a reference to the first limb.\n        /// @details Returns a reference to the first limb in the LimbsVector.\n        /// The LimbsVector must not be empty.\n        Limb& front();\n        /// @brief Returns a const reference to the first limb.\n        /// @details Returns a const reference to the first limb in the\n        /// LimbsVector. The LimbsVector must not be empty.\n        const Limb& front() const;\n\n        /// @brief Returns a reference to the last limb.\n        /// @details Returns a reference to the last limb in the LimbsVector.\n        /// The LimbsVector must not be empty.\n        Limb& back();\n        /// @brief Returns a const reference to the last limb.\n        /// @details Returns a const reference to the last limb in the\n        /// LimbsVector. The LimbsVector must not be empty.\n        const Limb& back() const;\n\n    private:\n        std::variant<std::array<Limb, 2>, std::unique_ptr<Limb[]>> m_data;\n        std::size_t m_size;\n        std::size_t m_capacity;\n\n        void _grow(std::size_t new_capacity);\n    };\n}\n\n#endif"
  },
  {
    "path": "cyacas/libyacas_mp/include/yacas/mp/nn.hpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#ifndef YACAS_MP_NN_HPP\n#define YACAS_MP_NN_HPP\n\n#include <algorithm>\n#include <cassert>\n#include <climits>\n#include <iostream>\n#include <random>\n#include <stdexcept>\n#include <string>\n#include <string_view>\n#include <vector>\n\n#include \"limbs_vector.hpp\"\n\nnamespace yacas {\n    namespace mp {\n        class NN {\n        public:\n            typedef std::uint32_t Limb;\n            typedef std::uint64_t Limb2;\n\n            static const NN ZERO;\n            static const NN ONE;\n            static const NN TWO;\n            static const NN TEN;\n\n            static unsigned PARSE_DC_THRESHOLD;\n            static unsigned TO_STRING_DC_THRESHOLD;\n            static unsigned DIV_REM_DC_THRESHOLD;\n\n            static unsigned MUL_TOOM22_THRESHOLD;\n            static unsigned MUL_TOOM33_THRESHOLD;\n\n            struct ParseError : public std::invalid_argument {\n                ParseError(std::string_view s, std::size_t) :\n                    std::invalid_argument(\"yacas::mp::NN: error parsing \" +\n                                          std::string(s))\n                {\n                }\n            };\n\n            struct DivisionByZeroError : public std::domain_error {\n                explicit DivisionByZeroError(std::string_view s) :\n                    std::domain_error(\"yacas::mp::NN: attempt to divide \" +\n                                      std::string(s) + \" by zero\")\n                {\n                }\n            };\n\n            NN() = default;\n\n            explicit NN(Limb);\n\n            /// @brief Construct from a vector of limbs.\n            explicit NN(const std::vector<Limb>&);\n\n            /// @brief Construct from a string.\n            /// @param s The string to parse.\n            /// @param b The base of the number.\n            /// @throw ParseError if the string cannot be parsed.\n            explicit NN(std::string_view, unsigned b = 10);\n\n            /// @brief Construct a random number with a given number of bits.\n            template <class RndEngine> NN(unsigned no_bits, RndEngine& engine);\n\n            bool operator==(Limb) const noexcept;\n            bool operator!=(Limb) const noexcept;\n            std::strong_ordering operator<=>(Limb) const noexcept;\n\n            /// @brief Equality comparison.\n            bool operator==(const NN&) const noexcept = default;\n            /// @brief Ordering comparison.\n            std::strong_ordering operator<=>(const NN&) const noexcept;\n\n            NN& operator+=(Limb);\n            NN& operator-=(Limb);\n            NN& operator*=(Limb);\n            NN& operator/=(Limb);\n            NN& operator%=(Limb);\n\n            NN& operator+=(const NN&);\n            NN& operator-=(const NN&);\n            NN& operator*=(const NN&);\n            NN& operator/=(const NN&);\n            NN& operator%=(const NN&);\n\n            NN& operator<<=(unsigned);\n            NN& operator>>=(unsigned);\n            NN& operator|=(const NN&);\n            NN& operator&=(const NN&);\n            NN& operator^=(const NN&);\n\n            bool is_zero() const;\n            bool is_even() const;\n\n            void clear();\n\n            unsigned to_unsigned() const;\n\n            /// @brief Return the number as a string.\n            std::string to_string(unsigned base = 10) const;\n\n            void sqr();\n            void pow(unsigned);\n\n            /// @brief Return the number of bits.\n            unsigned long no_bits() const;\n            /// @brief Return the number of decimal digits.\n            unsigned long no_digits() const;\n\n            /// @brief Test a bit.\n            bool test(unsigned long bit) const;\n            /// @brief Set a bit.\n            void set(unsigned long bit);\n            /// @brief Clear a bit.\n            void clear(unsigned long bit);\n\n            /// @brief Return the limbs.\n            const LimbsVector& limbs() const;\n\n        private:\n            static constexpr int LIMB_BITS = sizeof(Limb) * CHAR_BIT;\n            static constexpr int LIMB2_BITS = sizeof(Limb2) * CHAR_BIT;\n\n            static constexpr Limb LIMB_MAX = std::numeric_limits<Limb>::max();\n\n            static constexpr Limb2 BASE = static_cast<Limb2>(LIMB_MAX) + 1;\n\n            LimbsVector _limbs;\n\n            template <typename Iter> NN(Iter b, Iter e)\n            {\n                std::copy(b, e, std::back_inserter(_limbs));\n                drop_zeros();\n            }\n\n            void drop_zeros();\n\n            void add(Limb);\n            void sub(Limb);\n            void mul(Limb);\n            void div(Limb);\n            void rem(Limb);\n            Limb div_rem(Limb);\n\n            void shift_left(unsigned n);\n            void shift_right(unsigned n);\n\n            void add(const NN&, unsigned shift = 0);\n            void sub(const NN&, unsigned shift = 0);\n            void mul(const NN&);\n            void div(const NN&);\n            void rem(const NN&);\n            NN div_rem(const NN&);\n\n            void sqr_bc();\n            void sqr_toom22();\n            void sqr_toom33();\n\n            void mul_bc(const NN&);\n            void mul_toom22(const NN&);\n            void mul_toom33(const NN&);\n\n            NN div_rem_bc(const NN&);\n\n            std::string to_string_bc(unsigned base = 10) const;\n            std::string to_string_dc(unsigned base = 10) const;\n        };\n\n        NN gcd(NN a, NN b);\n\n        inline NN::NN(Limb n)\n        {\n            if (n != 0)\n                _limbs.push_back(n);\n        }\n\n        inline NN::NN(const std::vector<Limb>& limbs) : _limbs(limbs)\n        {\n            drop_zeros();\n        }\n\n        template <class RndEngine> NN::NN(unsigned no_bits, RndEngine& engine)\n        {\n            const unsigned no_limbs =\n                ((unsigned long)no_bits + LIMB_BITS - 1) / LIMB_BITS;\n\n            const unsigned no_full_limbs = no_bits / LIMB_BITS;\n\n            _limbs.reserve(no_limbs);\n\n            std::uniform_int_distribution<Limb> distribution;\n\n            for (unsigned i = 0; i < no_full_limbs; ++i)\n                _limbs.push_back(distribution(engine));\n\n            const unsigned excess_bits = no_limbs * LIMB_BITS - no_bits;\n\n            if (excess_bits) {\n                distribution = std::uniform_int_distribution<Limb>(\n                    0, static_cast<Limb>(1) << (excess_bits - 1));\n                _limbs.push_back(distribution(engine));\n            }\n\n            drop_zeros();\n        }\n\n        inline bool NN::operator==(Limb n) const noexcept\n        {\n            return _limbs.size() == 1 && _limbs.front() == n;\n        }\n\n        inline bool NN::operator!=(Limb n) const noexcept\n        {\n            return !(*this == n);\n        }\n\n        inline std::strong_ordering NN::operator<=>(Limb n) const noexcept\n        {\n            if (_limbs.size() == 1) {\n                if (_limbs.front() < n)\n                    return std::strong_ordering::less;\n                if (_limbs.front() > n)\n                    return std::strong_ordering::greater;\n                return std::strong_ordering::equal;\n            }\n\n            if (_limbs.empty()) {\n                if (n == 0)\n                    return std::strong_ordering::equal;\n                else\n                    return std::strong_ordering::less;\n            }\n\n            return std::strong_ordering::greater;\n        }\n\n\n        inline std::strong_ordering NN::operator<=>(const NN& n) const noexcept\n        {\n            if (_limbs.size() < n._limbs.size())\n                return std::strong_ordering::less;\n\n            if (_limbs.size() > n._limbs.size())\n                return std::strong_ordering::greater;\n\n            return std::lexicographical_compare_three_way(_limbs.crbegin(),\n                                                          _limbs.crend(),\n                                                          n._limbs.crbegin(),\n                                                          n._limbs.crend());\n        }\n\n        inline NN& NN::operator+=(Limb n)\n        {\n            add(n);\n            return *this;\n        }\n\n        inline NN& NN::operator-=(Limb n)\n        {\n            sub(n);\n            return *this;\n        }\n\n        inline NN& NN::operator*=(Limb n)\n        {\n            mul(n);\n            return *this;\n        }\n\n        inline NN& NN::operator/=(Limb n)\n        {\n            div_rem(n);\n            return *this;\n        }\n\n        inline NN& NN::operator%=(Limb n)\n        {\n            _limbs = {div_rem(n)};\n            drop_zeros();\n            return *this;\n        }\n\n        inline NN& NN::operator+=(const NN& n)\n        {\n            add(n);\n            return *this;\n        }\n\n        inline NN& NN::operator-=(const NN& n)\n        {\n            sub(n);\n            return *this;\n        }\n\n        inline NN& NN::operator*=(const NN& n)\n        {\n            mul(n);\n            return *this;\n        }\n\n        inline NN& NN::operator/=(const NN& n)\n        {\n            div(n);\n            return *this;\n        }\n\n        inline NN& NN::operator%=(const NN& n)\n        {\n            rem(n);\n            return *this;\n        }\n\n        inline NN& NN::operator<<=(unsigned n)\n        {\n            shift_left(n);\n            return *this;\n        }\n\n        inline NN& NN::operator>>=(unsigned n)\n        {\n            shift_right(n);\n            return *this;\n        }\n\n        inline NN& NN::operator|=(const NN& b)\n        {\n            const unsigned n = static_cast<unsigned>(b._limbs.size());\n\n            if (_limbs.size() < n)\n                _limbs.resize(n, 0);\n\n            Limb* __restrict p = _limbs.data();\n            const Limb* __restrict q = b._limbs.data();\n\n            for (unsigned i = 0; i < n; ++i)\n                *p++ |= *q++;\n\n            return *this;\n        }\n\n        inline NN& NN::operator&=(const NN& b)\n        {\n            const unsigned n = static_cast<unsigned>(b._limbs.size());\n\n            if (_limbs.size() > n)\n                _limbs.resize(n);\n\n            const unsigned m = static_cast<unsigned>(_limbs.size());\n\n            Limb* __restrict p = _limbs.data();\n            const Limb* __restrict q = b._limbs.data();\n\n            for (unsigned i = 0; i < m; ++i)\n                *p++ &= *q++;\n\n            drop_zeros();\n\n            return *this;\n        }\n\n        inline NN& NN::operator^=(const NN& b)\n        {\n            const unsigned n = static_cast<unsigned>(b._limbs.size());\n\n            if (_limbs.size() > n)\n                _limbs.resize(n);\n\n            const unsigned m = static_cast<unsigned>(_limbs.size());\n\n            Limb* __restrict p = _limbs.data();\n            const Limb* __restrict q = b._limbs.data();\n\n            for (unsigned i = 0; i < m; ++i)\n                *p++ ^= *q++;\n\n            drop_zeros();\n\n            return *this;\n        }\n\n        inline unsigned long NN::no_bits() const\n        {\n            if (is_zero())\n                return 1;\n\n#ifdef _MSC_VER\n            unsigned long index = 0;\n            _BitScanReverse(&index, _limbs.back());\n            return static_cast<unsigned>(_limbs.size() * LIMB_BITS - (31 - index));\n#else\n            return static_cast<unsigned>(_limbs.size() * LIMB_BITS - __builtin_clz(_limbs.back()));\n#endif\n        }\n\n        inline unsigned long NN::no_digits() const\n        {\n            if (is_zero())\n                return 1;\n\n            const unsigned n = ((no_bits() + 1) * 646456993) >> 31;\n\n            NN t = TEN;\n            t.pow(n);\n\n            return *this < t ? n : n + 1;\n        }\n\n        inline bool NN::test(unsigned long bit) const\n        {\n            assert(bit < _limbs.size() * LIMB_BITS);\n            return _limbs[bit / LIMB_BITS] & (1 << (bit % LIMB_BITS));\n        }\n\n        inline void NN::set(unsigned long bit)\n        {\n            assert(bit < _limbs.size() * LIMB_BITS);\n            _limbs[bit / LIMB_BITS] |= (1 << (bit % LIMB_BITS));\n        }\n\n        inline void NN::clear(unsigned long bit)\n        {\n            assert(bit < _limbs.size() * LIMB_BITS);\n            _limbs[bit / LIMB_BITS] &= ~(1 << (bit % LIMB_BITS));\n        }\n\n        inline bool NN::is_zero() const { return _limbs.empty(); }\n\n        inline bool NN::is_even() const\n        {\n            if (is_zero())\n                return true;\n\n            return !(_limbs.front() & 1);\n        }\n\n        inline void NN::clear() { _limbs.clear(); }\n\n        inline unsigned NN::to_unsigned() const\n        {\n            if (is_zero())\n                return 0;\n\n            return _limbs.front();\n        }\n\n        inline void NN::drop_zeros()\n        {\n            while (!_limbs.empty() && (_limbs.back() == 0))\n                _limbs.pop_back();\n        }\n\n        inline const LimbsVector& NN::limbs() const { return _limbs; }\n\n        inline ::std::ostream& operator<<(::std::ostream& os, const NN& n)\n        {\n            unsigned base = 10;\n            if (os.flags() & std::ios::hex)\n                base = 16;\n            if (os.flags() & std::ios::oct)\n                base = 8;\n\n            return os << n.to_string(base);\n        }\n\n        inline ::std::istream& operator>>(::std::istream& os, NN& n)\n        {\n            unsigned base = 10;\n            if (os.flags() & std::ios::hex)\n                base = 16;\n            if (os.flags() & std::ios::oct)\n                base = 8;\n\n            std::string s;\n            os >> s;\n            n = NN(s, base);\n\n            return os;\n        }\n    }\n}\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas_mp/include/yacas/mp/rr.hpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#ifndef YACAS_MP_RR_HPP\n#define YACAS_MP_RR_HPP\n\n#endif"
  },
  {
    "path": "cyacas/libyacas_mp/include/yacas/mp/zz.hpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#ifndef YACAS_MP_ZZ_HPP\n#define YACAS_MP_ZZ_HPP\n\n#include \"nn.hpp\"\n\nnamespace yacas {\n    namespace mp {\n        class ZZ {\n        public:\n            static const ZZ ZERO;\n            static const ZZ ONE;\n            static const ZZ TWO;\n            static const ZZ TEN;\n\n            struct ParseError : public std::invalid_argument {\n                ParseError(std::string_view s, std::size_t) :\n                    std::invalid_argument(\"yacas::mp::ZZ: error parsing \" + std::string(s))\n                {\n                }\n            };\n\n            struct DivisionByZeroError : public std::domain_error {\n                explicit DivisionByZeroError(std::string_view s) :\n                    std::domain_error(\"yacas::mp::ZZ: attempt to divide \" +\n                                       std::string(s) + \" by zero\")\n                {\n                }\n            };\n\n            ZZ();\n            explicit ZZ(int);\n            explicit ZZ(const NN&);\n            explicit ZZ(std::string_view s, unsigned b = 10);\n\n            template <class RndEngine>\n            ZZ(unsigned no_bits, RndEngine& engine);\n\n            bool operator==(int) const;\n            bool operator!=(int) const;\n\n            std::strong_ordering operator<=>(int) const noexcept;\n\n            bool operator==(const ZZ&) const noexcept = default;\n\n            /// @brief Ordering comparison.\n            std::strong_ordering operator<=>(const ZZ&) const noexcept;\n\n            ZZ& operator+=(int);\n            ZZ& operator-=(int);\n            ZZ& operator*=(int);\n            ZZ& operator/=(int);\n            ZZ& operator%=(int);\n\n            ZZ& operator+=(const ZZ&);\n            ZZ& operator-=(const ZZ&);\n            ZZ& operator*=(const ZZ&);\n            ZZ& operator/=(const ZZ&);\n            ZZ& operator%=(const ZZ&);\n\n            ZZ& operator<<=(unsigned);\n            ZZ& operator>>=(unsigned);\n            ZZ& operator|=(const ZZ&);\n            ZZ& operator&=(const ZZ&);\n            ZZ& operator^=(const ZZ&);\n\n            bool is_zero() const;\n            bool is_positive() const;\n            bool is_negative() const;\n            bool is_even() const;\n\n            void clear();\n\n            const NN& to_NN() const;\n\n            int to_int() const;\n            std::string to_string(unsigned base = 10) const;\n\n            void abs();\n            void neg();\n\n            void sqr();\n            void pow(unsigned);\n\n            unsigned long no_bits() const;\n            unsigned long no_digits() const;\n\n            bool test(unsigned long bit) const;\n            void set(unsigned long bit);\n            void clear(unsigned long bit);\n\n        private:\n            NN _nn;\n            bool _neg;\n        };\n\n        inline ZZ gcd(ZZ a, ZZ b)\n        {\n            a.abs();\n            b.abs();\n\n            return ZZ(gcd(a.to_NN(), b.to_NN()));\n        }\n\n        inline ZZ::ZZ() : _neg(false) {}\n\n        inline ZZ::ZZ(int i) : _nn(std::abs(i)), _neg(i < 0) {}\n\n        inline ZZ::ZZ(const NN& n) : _nn(n), _neg(false) {}\n\n        template <class RndEngine>\n        ZZ::ZZ(unsigned no_bits, RndEngine& engine) :\n            _nn(no_bits, engine),\n            _neg(false)\n        {\n        }\n\n        inline bool ZZ::operator==(int i) const\n        {\n            if (_neg == (i < 0))\n                return _nn == std::abs(i);\n\n            return false;\n        }\n\n        inline bool ZZ::operator!=(int i) const\n        {\n            return !(*this == i);\n        }\n\n        inline std::strong_ordering ZZ::operator<=>(const ZZ& z) const noexcept\n        {\n            if (_neg && !z._neg)\n                return std::strong_ordering::less;\n\n            if (!_neg && z._neg)\n                return std::strong_ordering::greater;\n\n            if (_neg && z._neg)\n                return z._nn <=> _nn;\n\n            return _nn <=> z._nn;\n        }\n\n        inline ZZ& ZZ::operator+=(int i)\n        {\n            if (i == 0)\n                return *this;\n\n            if (_neg == (i < 0)) {\n                _nn += std::abs(i);\n                return *this;\n            }\n\n            i = std::abs(i);\n\n            if (_nn > i) {\n                _nn -= i;\n            } else {\n                NN t(i);\n                t -= _nn;\n                _nn = std::move(t);\n                if (_nn.is_zero())\n                    _neg = false;\n                else\n                    _neg = !_neg;\n            }\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator-=(int i)\n        {\n            *this += -i;\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator*=(int i)\n        {\n            if (i == 0) {\n                clear();\n                return *this;\n            }\n\n            if (i < 0) {\n                _neg = !_neg;\n                i = -i;\n            }\n            _nn *= i;\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator/=(int i)\n        {\n            if (i == 0)\n                throw DivisionByZeroError(to_string());\n\n            if (i < 0) {\n                _neg = !_neg;\n                i = -i;\n            }\n            _nn /= i;\n\n            if (_nn.is_zero())\n                _neg = false;\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator%=(int i)\n        {\n            if (i == 0)\n                throw DivisionByZeroError(to_string());\n\n            if (i < 0) {\n                _neg = !_neg;\n                i = -i;\n            }\n            _nn %= i;\n\n            if (_nn.is_zero())\n                _neg = false;\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator+=(const ZZ& z)\n        {\n            if (_neg == z._neg) {\n                _nn += z._nn;\n                return *this;\n            }\n\n            if (_nn > z._nn) {\n                _nn -= z._nn;\n            } else {\n                NN t(z._nn);\n                t -= _nn;\n                _nn = std::move(t);\n                if (_nn.is_zero())\n                    _neg = false;\n                else\n                    _neg = !_neg;\n            }\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator-=(const ZZ& z)\n        {\n            if (_neg != z._neg) {\n                _nn += z._nn;\n                return *this;\n            }\n\n            if (_nn > z._nn) {\n                _nn -= z._nn;\n            } else {\n                NN t(z._nn);\n                t -= _nn;\n                _nn = std::move(t);\n                if (_nn.is_zero())\n                    _neg = false;\n                else\n                    _neg = !_neg;\n            }\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator*=(const ZZ& z)\n        {\n            if (is_zero())\n                return *this;\n\n            if (z.is_zero()) {\n                clear();\n                return *this;\n            }\n\n            if (z._neg)\n                _neg = !_neg;\n\n            _nn *= z._nn;\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator/=(const ZZ& z)\n        {\n            if (is_zero())\n                return *this;\n\n            if (z.is_zero())\n                throw DivisionByZeroError(to_string());\n\n            if (z._neg)\n                _neg = !_neg;\n\n            _nn /= z._nn;\n\n            if (_nn.is_zero())\n                _neg = false;\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator%=(const ZZ& z)\n        {\n            if (z.is_zero())\n                throw DivisionByZeroError(to_string());\n\n            if (z._neg)\n                _neg = !_neg;\n\n            _nn %= z._nn;\n\n            if (_nn.is_zero())\n                _neg = false;\n\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator<<=(unsigned n)\n        {\n            _nn <<= n;\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator>>=(unsigned n)\n        {\n            _nn >>= n;\n            if (_nn.is_zero())\n                _neg = false;\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator|=(const ZZ& z)\n        {\n            _nn |= z._nn;\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator&=(const ZZ& z)\n        {\n            _nn &= z._nn;\n            if (_nn.is_zero())\n                _neg = false;\n            return *this;\n        }\n\n        inline ZZ& ZZ::operator^=(const ZZ& z)\n        {\n            _nn ^= z._nn;\n            if (_nn.is_zero())\n                _neg = false;\n            return *this;\n        }\n\n        inline void ZZ::abs()\n        {\n            _neg = false;\n        }\n\n        inline void ZZ::neg()\n        {\n            if (!is_zero())\n                _neg = !_neg;\n        }\n\n        inline void ZZ::sqr()\n        {\n            _neg = false;\n            _nn.sqr();\n        }\n\n        inline void ZZ::pow(unsigned n)\n        {\n            if (n % 2 == 0)\n                _neg = false;\n\n            _nn.pow(n);\n        }\n\n        inline unsigned long ZZ::no_bits() const { return _nn.no_bits(); }\n\n        inline unsigned long ZZ::no_digits() const { return _nn.no_digits(); }\n\n        inline bool ZZ::test(unsigned long bit) const { return _nn.test(bit); }\n\n        inline void ZZ::set(unsigned long bit) { _nn.set(bit); }\n\n        inline void ZZ::clear(unsigned long bit)\n        {\n            _nn.clear(bit);\n\n            if (_nn.is_zero())\n                _neg = false;\n        }\n\n        inline bool ZZ::is_zero() const { return _nn.is_zero(); }\n\n        inline bool ZZ::is_positive() const\n        {\n            if (is_zero())\n                return false;\n\n            return !_neg;\n        }\n\n        inline bool ZZ::is_negative() const { return _neg; }\n\n        inline bool ZZ::is_even() const { return _nn.is_even(); }\n\n        inline void ZZ::clear()\n        {\n            _nn.clear();\n            _neg = false;\n        }\n\n        inline const NN& ZZ::to_NN() const\n        {\n            assert(!_neg);\n\n            return _nn;\n        }\n\n        inline int ZZ::to_int() const\n        {\n            return (is_negative() ? -1 : 1) *\n                   static_cast<int>(_nn.to_unsigned());\n        }\n\n        inline ::std::ostream& operator<<(::std::ostream& os, const ZZ& z)\n        {\n            unsigned base = 10;\n            if (os.flags() & std::ios::hex)\n                base = 16;\n            if (os.flags() & std::ios::oct)\n                base = 8;\n\n            return os << z.to_string(base);\n        }\n\n        inline ::std::istream& operator>>(::std::istream& os, ZZ& z)\n        {\n            unsigned base = 10;\n            if (os.flags() & std::ios::hex)\n                base = 16;\n            if (os.flags() & std::ios::oct)\n                base = 8;\n\n            std::string s;\n            os >> s;\n            z = ZZ(s, base);\n\n            return os;\n        }\n    }\n}\n\n#endif\n"
  },
  {
    "path": "cyacas/libyacas_mp/src/limbs_vector.cpp",
    "content": "#include \"yacas/mp/limbs_vector.hpp\"\n\n#include <algorithm>\n#include <cassert>\n\nnamespace yacas::mp {\n    LimbsVector::LimbsVector() noexcept :\n        m_data(std::array<Limb, 2>{}), m_size(0), m_capacity(2)\n    {\n    }\n\n    LimbsVector::LimbsVector(const std::initializer_list<Limb>& limbs) :\n        LimbsVector()\n    {\n        for (const auto limb : limbs) {\n            push_back(limb);\n        }\n    }\n\n    LimbsVector::LimbsVector(std::size_t n, Limb value) :\n        m_size(n), m_capacity(n)\n    {\n        if (n <= 2) {\n            m_data = std::array<Limb, 2>{};\n        } else {\n            m_data = std::make_unique<Limb[]>(n);\n        }\n        std::fill_n(begin(), n, value);\n    }\n\n    LimbsVector::LimbsVector(const LimbsVector& limbs) :\n        m_size(limbs.size()), m_capacity(limbs.size())\n    {\n        if (limbs.size() <= 2) {\n            m_data = std::get<0>(limbs.m_data);\n        } else {\n            m_data = std::make_unique<Limb[]>(limbs.size());\n            std::copy(limbs.cbegin(), limbs.cend(), begin());\n        }\n    }\n\n    LimbsVector::LimbsVector(LimbsVector&& limbs) noexcept :\n        m_data(std::move(limbs.m_data)),\n        m_size(limbs.m_size),\n        m_capacity(limbs.m_capacity)\n    {\n        limbs.m_size = 0;\n        limbs.m_capacity = 2;\n    }\n\n    std::strong_ordering\n    LimbsVector::operator<=>(const LimbsVector& that) const noexcept\n    {\n        if (m_size != that.m_size)\n            return m_size <=> that.m_size;\n\n        for (std::size_t i = 0; i < m_size; ++i) {\n            if (auto cmp = (*this)[i] <=> that[i]; cmp != 0)\n                return cmp;\n        }\n\n        return std::strong_ordering::equal;\n    }\n\n    bool LimbsVector::operator==(const LimbsVector& that) const noexcept\n    {\n        return *this <=> that == 0;\n    }\n\n    bool LimbsVector::operator!=(const LimbsVector& that) const noexcept\n    {\n        return *this <=> that != 0;\n    }\n\n    LimbsVector& LimbsVector::operator=(const LimbsVector& other)\n    {\n        LimbsVector tmp(other);\n        swap(tmp);\n        return *this;\n    }\n\n    LimbsVector& LimbsVector::operator=(LimbsVector&& other) noexcept\n    {\n        swap(other);\n        return *this;\n    }\n\n    void LimbsVector::swap(LimbsVector& other) noexcept\n    {\n        using std::swap;\n        swap(m_data, other.m_data);\n        swap(m_size, other.m_size);\n        swap(m_capacity, other.m_capacity);\n    }\n\n    void LimbsVector::insert(iterator b, std::size_t n, Limb value)\n    {\n        const std::size_t index = b - begin();\n        if (m_size + n > m_capacity)\n            _grow(m_size + n);\n        m_size += n;\n\n        // FIXME: use std::move\n        for (std::size_t i = m_size - n; i-- != index;)\n            (*this)[i + n] = (*this)[i];\n\n        std::fill_n(begin() + index, n, value);\n    }\n\n    void LimbsVector::erase(iterator b, iterator e)\n    {\n        assert(b >= begin() && e <= end() && b <= e);\n\n        const std::size_t n = e - b;\n        std::move(e, end(), b);\n        m_size -= n;\n\n        if (m_size <= 2) {\n            if (m_data.index() == 1) {\n                std::array<Limb, 2> new_data;\n                std::copy_n(\n                    std::get<1>(m_data).get(), m_size, new_data.begin());\n                m_data = new_data;\n                m_capacity = 2;\n            }\n        } else if (m_size < m_capacity / 2) {\n            std::unique_ptr<Limb[]> new_data =\n                std::make_unique<Limb[]>(m_capacity / 2);\n            std::copy_n(std::get<1>(m_data).get(), m_size, new_data.get());\n            m_data = std::move(new_data);\n            m_capacity /= 2;\n        }\n    }\n\n    LimbsVector::reverse_iterator LimbsVector::rbegin()\n    {\n        return std::make_reverse_iterator(end());\n    }\n    LimbsVector::reverse_iterator LimbsVector::rend()\n    {\n        return std::make_reverse_iterator(begin());\n    }\n\n    LimbsVector::const_reverse_iterator LimbsVector::crbegin() const\n    {\n        return std::make_reverse_iterator(cend());\n    }\n    LimbsVector::const_reverse_iterator LimbsVector::crend() const\n    {\n        return std::make_reverse_iterator(cbegin());\n    }\n\n    std::size_t LimbsVector::size() const noexcept\n    {\n        return m_size;\n    }\n\n    bool LimbsVector::empty() const noexcept\n    {\n        return m_size == 0;\n    }\n\n    LimbsVector::Limb* LimbsVector::data()\n    {\n        if (m_data.index() == 0)\n            return std::get<0>(m_data).data();\n        else\n            return std::get<1>(m_data).get();\n    }\n\n    const LimbsVector::Limb* LimbsVector::data() const\n    {\n        if (m_data.index() == 0)\n            return std::get<0>(m_data).data();\n        else\n            return std::get<1>(m_data).get();\n    }\n\n    LimbsVector::Limb& LimbsVector::operator[](std::size_t index)\n    {\n        assert(index < m_size);\n        if (m_data.index() == 0)\n            return std::get<0>(m_data)[index];\n        else\n            return std::get<1>(m_data)[index];\n    }\n\n    const LimbsVector::Limb& LimbsVector::operator[](std::size_t index) const\n    {\n        assert(index < m_size);\n        if (m_data.index() == 0)\n            return std::get<0>(m_data)[index];\n        else\n            return std::get<1>(m_data)[index];\n    }\n\n    LimbsVector::Limb& LimbsVector::front()\n    {\n        assert(m_size > 0);\n        if (m_data.index() == 0)\n            return std::get<0>(m_data)[0];\n        else\n            return std::get<1>(m_data)[0];\n    }\n\n    const LimbsVector::Limb& LimbsVector::front() const\n    {\n        assert(m_size > 0);\n        if (m_data.index() == 0)\n            return std::get<0>(m_data)[0];\n        else\n            return std::get<1>(m_data)[0];\n    }\n\n    LimbsVector::Limb& LimbsVector::back()\n    {\n        assert(m_size > 0);\n        if (m_data.index() == 0)\n            return std::get<0>(m_data)[m_size - 1];\n        else\n            return std::get<1>(m_data)[m_size - 1];\n    }\n\n    const LimbsVector::Limb& LimbsVector::back() const\n    {\n        assert(m_size > 0);\n        if (m_data.index() == 0)\n            return std::get<0>(m_data)[m_size - 1];\n        else\n            return std::get<1>(m_data)[m_size - 1];\n    }\n\n    void LimbsVector::clear()\n    {\n        m_data = std::array<Limb, 2>{};\n        m_size = 0;\n        m_capacity = 2;\n    }\n\n    void LimbsVector::push_back(Limb limb)\n    {\n        if (m_size == m_capacity)\n            _grow(m_capacity * 2);\n\n        if (m_data.index() == 0)\n            std::get<0>(m_data)[m_size++] = limb;\n        else\n            std::get<1>(m_data)[m_size++] = limb;\n    }\n\n    void LimbsVector::pop_back()\n    {\n        assert(m_size > 0);\n\n        m_size -= 1;\n\n        if (m_data.index() == 1) {\n            if (m_size <= 2) {\n                std::array<Limb, 2> new_data;\n                std::copy_n(\n                    std::get<1>(m_data).get(), m_size, new_data.begin());\n                m_data = new_data;\n                m_capacity = 2;\n            } else if (m_size < m_capacity / 2) {\n                std::unique_ptr<Limb[]> new_data =\n                    std::make_unique<Limb[]>(m_capacity / 2);\n                std::copy_n(std::get<1>(m_data).get(), m_size, new_data.get());\n                m_data = std::move(new_data);\n                m_capacity /= 2;\n            }\n        }\n    }\n\n    void LimbsVector::resize(std::size_t n, Limb value)\n    {\n        if (n > m_size) {\n            if (n > m_capacity)\n                _grow(n);\n\n            std::fill_n(end(), n - m_size, value);\n            m_size = n;\n        } else if (n < m_size) {\n            m_size = n;\n            if (m_data.index() == 1) {\n                if (n <= 2) {\n                    std::array<Limb, 2> new_data;\n                    for (std::size_t i = 0; i < m_size; ++i)\n                        new_data[i] = std::get<1>(m_data)[i];\n                    m_data = new_data;\n                    m_capacity = 2;\n                } else if (n < m_capacity / 2) {\n                    std::unique_ptr<Limb[]> new_data =\n                        std::make_unique<Limb[]>(m_capacity / 2);\n                    for (std::size_t i = 0; i < m_size; ++i)\n                        new_data[i] = std::get<1>(m_data)[i];\n                    m_data = std::move(new_data);\n                    m_capacity /= 2;\n                }\n            }\n        }\n    }\n\n    void LimbsVector::reserve(std::size_t new_capacity)\n    {\n        if (new_capacity > m_capacity)\n            _grow(new_capacity);\n    }\n\n    void LimbsVector::_grow(std::size_t new_capacity)\n    {\n        assert(new_capacity > m_capacity);\n\n        if (new_capacity > 2) {\n            std::unique_ptr<Limb[]> new_data =\n                std::make_unique<Limb[]>(new_capacity);\n            std::copy_n(data(), m_size, new_data.get());\n            m_data = std::move(new_data);\n        }\n\n        m_capacity = new_capacity;\n    }\n\n    LimbsVector::iterator LimbsVector::begin() noexcept\n    {\n        return data();\n    }\n\n    LimbsVector::iterator LimbsVector::end() noexcept\n    {\n        return data() + m_size;\n    }\n\n    LimbsVector::const_iterator LimbsVector::begin() const noexcept\n    {\n        return data();\n    }\n\n    LimbsVector::const_iterator LimbsVector::end() const noexcept\n    {\n        return data() + m_size;\n    }\n\n    LimbsVector::const_iterator LimbsVector::cbegin() const\n    {\n        return data();\n    }\n\n    LimbsVector::const_iterator LimbsVector::cend() const\n    {\n        return data() + m_size;\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas_mp/src/nn.cpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#include \"yacas/mp/nn.hpp\"\n\n#include <cctype>\n\nnamespace {\n    using namespace yacas::mp;\n\n    typedef NN::Limb Limb;\n    typedef NN::Limb2 Limb2;\n\n    static constexpr int LIMB_BITS = sizeof(Limb) * CHAR_BIT;\n\n    void _mul(const Limb* __restrict p, unsigned n, Limb a, Limb* __restrict r)\n    {\n        if (n == 1) {\n            const Limb2 v = static_cast<Limb2>(*p) * a;\n            r[0] = static_cast<Limb>(v);\n            r[1] = static_cast<Limb>(v >> LIMB_BITS);\n            return;\n        }\n\n        Limb carry = 0;\n\n        for (unsigned j = 0; j < n; ++j) {\n            const Limb2 v = static_cast<Limb2>(*p++) * a + carry;\n            carry = static_cast<Limb>(v >> LIMB_BITS);\n            *r += static_cast<Limb>(v);\n            carry += *r++ < static_cast<Limb>(v);\n        }\n\n        while (carry) {\n            const Limb v = *r + carry;\n            carry = v < *r;\n            *r++ = v;\n        }\n    }\n\n    bool ssub(NN& a, const NN& b)\n    {\n        if (a >= b) {\n            a -= b;\n            return true;\n        }\n\n        NN t(a);\n        a = b;\n        a -= t;\n\n        return false;\n    }\n\n    void sadd(NN& a, bool& ap, const NN& b, bool bp)\n    {\n        if (ap == bp) {\n            a += b;\n            return;\n        }\n\n        if (ap && !bp) {\n            ap = ssub(a, b);\n            return;\n        }\n\n        NN t(a);\n        a = b;\n        ap = ssub(a, t);\n    }\n\n    void ssub(NN& a, bool& ap, const NN& b, bool bp)\n    {\n        sadd(a, ap, b, !bp);\n        return;\n    }\n\n    const Limb2 log2x2to31[] = {\n        2147483648, 1354911328, 1073741824, 924870866, 830760077, 764949109,\n        715827882,  677455664,  646456993,  620761987, 599025414, 580332017,\n        564035581,  549665672,  536870912,  525383038, 514993350, 505536792,\n        496880929,  488918136,  481559945,  474732891, 468375400, 462435433,\n        456868671,  451637109,  446707947,  442052706, 437646531, 433467612,\n        429496729,  425716864,  422112891,  418671311, 415380038};\n}\n\nnamespace yacas {\n    namespace mp {\n\n        const NN NN::ZERO = NN(0u);\n        const NN NN::ONE = NN(1u);\n        const NN NN::TWO = NN(2u);\n        const NN NN::TEN = NN(10u);\n\n        unsigned NN::MUL_TOOM22_THRESHOLD = 32;\n        unsigned NN::MUL_TOOM33_THRESHOLD = 48;\n\n        unsigned NN::PARSE_DC_THRESHOLD = 512;\n        unsigned NN::TO_STRING_DC_THRESHOLD = 24;\n        unsigned NN::DIV_REM_DC_THRESHOLD = 4;\n\n        NN::NN(std::string_view s, unsigned b)\n        {\n            auto p = s.cbegin();\n            const auto q = s.cend();\n\n            while (p != q && std::isspace(*p))\n                p += 1;\n\n            if (p == q)\n                throw ParseError(s, s.length());\n\n            while (p != q && std::isalnum(*p)) {\n                const char c = *p++;\n                const Limb d = std::isdigit(c) ? Limb(c - '0') : Limb((c | 0x20) - 'a' + 10);\n\n                if (d >= b)\n                    throw ParseError(s, std::distance(s.cbegin(), q));\n\n                mul(b);\n                add(d);\n            }\n\n            drop_zeros();\n        }\n\n        std::string NN::to_string(unsigned base) const\n        {\n            assert(base > 1);\n            assert(base <= 36);\n\n            return _limbs.size() < TO_STRING_DC_THRESHOLD ? to_string_bc(base)\n                                                          : to_string_dc(base);\n        }\n\n        std::string NN::to_string_bc(unsigned base) const\n        {\n            assert(base > 1);\n            assert(base <= 36);\n\n            if (_limbs.empty())\n                return \"0\";\n\n            if (base == 10 && _limbs.size() == 1)\n                return std::to_string(_limbs.back());\n\n            if (base == 10 && _limbs.size() == 2)\n                return std::to_string(\n                    (static_cast<Limb2>(_limbs.back()) << LIMB_BITS) +\n                    _limbs.front());\n\n            NN t(*this);\n            std::string s;\n\n            while (!t._limbs.empty()) {\n                const Limb r = t.div_rem(base);\n                s += r <= 9 ? r + '0' : r - 10 + 'a';\n            }\n\n            std::reverse(s.begin(), s.end());\n\n            return s;\n        }\n\n        std::string NN::to_string_dc(unsigned base) const\n        {\n            assert(base > 1);\n            assert(base <= 36);\n\n            if (_limbs.size() < 3)\n                return to_string(base);\n\n            const unsigned k = (no_bits() * log2x2to31[base - 2]) >> 32;\n\n            NN Bk(base);\n            Bk.pow(k);\n\n            NN Q(*this);\n            const NN R = Q.div_rem(Bk);\n\n            const std::string r = R.to_string(base);\n            return Q.to_string(base) + std::string(k - r.length(), '0') + r;\n        }\n\n        void NN::shift_left(unsigned n)\n        {\n            if (n >= LIMB_BITS) {\n                _limbs.insert(_limbs.begin(), n / LIMB_BITS, 0);\n                n %= LIMB_BITS;\n            }\n\n            if (!n)\n                return;\n\n            Limb c = 0;\n            for (LimbsVector::iterator i = _limbs.begin(); i != _limbs.end(); ++i) {\n                const Limb2 t = static_cast<Limb2>(*i) << n;\n                *i = static_cast<Limb>(t) + c;\n                c = static_cast<Limb>(t >> LIMB_BITS);\n            }\n\n            if (c)\n                _limbs.push_back(c);\n        }\n\n        void NN::shift_right(unsigned n)\n        {\n            if (n >= LIMB_BITS) {\n                _limbs.erase(_limbs.begin(), _limbs.begin() + n / LIMB_BITS);\n                n %= LIMB_BITS;\n            }\n\n            if (!n)\n                return;\n\n            Limb c = 0;\n            for (LimbsVector::reverse_iterator i = _limbs.rbegin();\n                 i != _limbs.rend();\n                 ++i) {\n                const Limb t = *i << (LIMB_BITS - n);\n                *i = (*i >> n) + c;\n                c = t;\n            }\n\n            drop_zeros();\n        }\n\n        void NN::add(Limb a)\n        {\n            if (a == 0)\n                return;\n\n            if (_limbs.empty()) {\n                _limbs.push_back(a);\n                return;\n            }\n\n            _limbs.push_back(0);\n\n            Limb* __restrict p = _limbs.data();\n\n            Limb v = *p + a;\n            Limb carry = v < *p;\n            *p++ = v;\n\n            while (carry) {\n                v = *p + carry;\n                carry = v < *p;\n                *p++ = v;\n            }\n\n            drop_zeros();\n        }\n\n        void NN::sub(Limb a)\n        {\n            if (a == 0)\n                return;\n\n            assert(!_limbs.empty());\n\n            Limb* __restrict p = _limbs.data();\n\n            Limb v = *p - a;\n            Limb borrow = v > *p;\n            *p++ = v;\n\n            while (borrow) {\n\n                assert(p < _limbs.data() + _limbs.size());\n\n                const Limb v = *p - borrow;\n                borrow = v > *p;\n                *p++ = v;\n            }\n\n            drop_zeros();\n        }\n\n        void NN::mul(Limb b)\n        {\n            if (_limbs.empty())\n                return;\n\n            if (b == 0) {\n                _limbs.clear();\n                return;\n            }\n\n            const unsigned n = static_cast<unsigned>(_limbs.size());\n            _limbs.push_back(0);\n            Limb* __restrict p = _limbs.data();\n\n            Limb carry = 0;\n\n            for (unsigned i = 0; i < n; ++i) {\n                const Limb2 v = static_cast<Limb2>(*p) * b + carry;\n                carry = static_cast<Limb>(v >> LIMB_BITS);\n                *p++ = static_cast<Limb>(v);\n            }\n\n            while (carry) {\n                const Limb v = *p + carry;\n                carry = v < *p;\n                *p++ = v;\n            }\n\n            drop_zeros();\n        }\n\n        void NN::div(Limb a) { div_rem(a); }\n\n        void NN::rem(Limb a)\n        {\n            _limbs = {div_rem(a)};\n            drop_zeros();\n        }\n\n        NN::Limb NN::div_rem(Limb a)\n        {\n            if (a == 0)\n                throw DivisionByZeroError(to_string());\n\n            const unsigned n = static_cast<unsigned>(_limbs.size());\n            LimbsVector q(n, 0);\n\n            Limb2 t = 0;\n\n            const Limb* __restrict p = _limbs.data() + n - 1;\n            Limb* __restrict qp = q.data() + n - 1;\n\n            for (unsigned i = 0; i < n; ++i) {\n                t <<= LIMB_BITS;\n                t += *p--;\n                *qp-- = static_cast<Limb>(t / a);\n                t %= a;\n            }\n\n            _limbs = std::move(q);\n            drop_zeros();\n\n            return static_cast<Limb>(t);\n        }\n\n        void NN::add(const NN& a, unsigned shift)\n        {\n            if (this == &a) {\n                if (shift == 0)\n                    shift_left(1);\n                else\n                    add(NN(a), shift);\n                return;\n            }\n\n            if (a.is_zero())\n                return;\n\n            if (is_zero()) {\n                _limbs = a._limbs;\n                shift_left(shift);\n                return;\n            }\n\n            const std::size_t na = a._limbs.size();\n\n            if (na + shift > _limbs.size())\n                _limbs.resize(na + shift + 1, 0);\n            else\n                _limbs.push_back(0);\n\n            Limb* __restrict p = _limbs.data() + shift;\n            const Limb* __restrict q = a._limbs.data();\n\n            Limb carry = 0;\n\n            for (unsigned i = 0; i < na; ++i) {\n                const Limb v = *p + *q++ + carry;\n                carry = v < *p;\n                *p++ = v;\n                assert(p <= _limbs.data() + _limbs.size());\n            }\n\n            while (carry) {\n                const Limb v = *p + carry;\n                carry = v < *p;\n                *p++ = v;\n                assert(p <= _limbs.data() + _limbs.size());\n            }\n\n            drop_zeros();\n        }\n\n        void NN::sub(const NN& a, unsigned shift)\n        {\n#ifndef NDEBUG\n            NN aa(a);\n            aa.shift_left(shift);\n            assert(*this >= aa);\n#endif\n            if (a.is_zero())\n                return;\n\n            if (this == &a) {\n                assert(shift == 0);\n                clear();\n                return;\n            }\n\n            const std::size_t na = a._limbs.size();\n\n            if (na + shift > _limbs.size())\n                _limbs.resize(na + shift + 1, 0);\n            else\n                _limbs.push_back(0);\n\n            Limb* __restrict p = _limbs.data() + shift;\n            const Limb* __restrict q = a._limbs.data();\n\n            Limb borrow = 0;\n\n            for (unsigned i = 0; i < na; ++i) {\n                const Limb v = *p - *q++ - borrow;\n                borrow = v > *p;\n                *p++ = v;\n                assert(p <= _limbs.data() + _limbs.size());\n            }\n\n            while (borrow) {\n                const Limb v = *p - borrow;\n                borrow = v > *p;\n                *p++ = v;\n                assert(p <= _limbs.data() + _limbs.size());\n            }\n\n            drop_zeros();\n        }\n\n        void NN::mul(const NN& a) { mul_bc(a); }\n\n        void NN::mul_bc(const NN& a)\n        {\n            const unsigned m = static_cast<unsigned>(_limbs.size());\n            const unsigned n = static_cast<unsigned>(a._limbs.size());\n\n            LimbsVector result(m + n, 0);\n\n            Limb* __restrict r = result.data();\n\n            if (m >= n) {\n                const Limb* __restrict p = _limbs.data();\n                for (unsigned i = 0; i < n; ++i)\n                    if (const Limb u = a._limbs[i])\n                        _mul(p, m, u, r + i);\n            } else {\n                const Limb* __restrict q = a._limbs.data();\n                for (unsigned i = 0; i < m; ++i)\n                    if (const Limb u = _limbs[i])\n                        _mul(q, n, u, r + i);\n            }\n\n            _limbs = std::move(result);\n\n            drop_zeros();\n        }\n\n        void NN::sqr()\n        {\n            const unsigned n = static_cast<unsigned>(_limbs.size());\n\n            if (n < MUL_TOOM22_THRESHOLD)\n                sqr_bc();\n            else if (n < MUL_TOOM33_THRESHOLD)\n                sqr_toom22();\n            else\n                sqr_toom33();\n        }\n\n        void NN::sqr_bc()\n        {\n            if (_limbs.empty())\n                return;\n\n            const unsigned n = static_cast<unsigned>(_limbs.size());\n\n            LimbsVector c(2 * n, 0);\n\n            const Limb* __restrict p = _limbs.data();\n            Limb* __restrict r = c.data();\n\n            for (unsigned i = 0; i < n; ++i)\n                if (const Limb u = p[i])\n                    _mul(p, n, u, r + i);\n\n            _limbs = std::move(c);\n\n            drop_zeros();\n        }\n\n        void NN::sqr_toom22()\n        {\n            const unsigned n = static_cast<unsigned>(_limbs.size());\n\n            assert(n >= 2);\n\n            const unsigned k = n / 2;\n\n            NN x0, x1;\n\n            x1._limbs.assign(_limbs.begin(), _limbs.begin() + k);\n            x1.drop_zeros();\n            x0._limbs.assign(_limbs.begin() + k, _limbs.end());\n            x0.drop_zeros();\n\n            NN d;\n            if (x0 < x1) {\n                d = x1;\n                d.sub(x0);\n            } else {\n                d = x0;\n                d.sub(x1);\n            }\n\n            d.sqr();\n            x0.sqr();\n            x1.sqr();\n\n            _limbs = x1._limbs;\n            x1.add(x0);\n            add(x1, k);\n            add(x0, 2 * k);\n            sub(d, k);\n        }\n\n        void NN::sqr_toom33()\n        {\n            const unsigned n = static_cast<unsigned>(_limbs.size());\n\n            assert(n >= 3);\n\n            const unsigned k = (n + 1) / 3;\n\n            NN x0, x1, x2;\n\n            x0._limbs.assign(_limbs.begin(), _limbs.begin() + k);\n            x0.drop_zeros();\n            x1._limbs.assign(_limbs.begin() + k, _limbs.begin() + 2 * k);\n            x1.drop_zeros();\n            x2._limbs.assign(_limbs.begin() + 2 * k, _limbs.end());\n            x2.drop_zeros();\n\n            // p0 <- x0\n            NN p0(x0);\n\n            // t <- x0 + x2\n            NN t(x0);\n            t += x2;\n\n            // p1 <- t + x1\n            NN p1(t);\n            p1 += x1;\n\n            // p_1 <- t - x1\n            NN p_1(t);\n            bool p_1p = ssub(p_1, x1);\n\n            // p_2 <- (p_1 + x2) * 2 − x0\n            NN p_2(p_1);\n            bool p_2p = p_1p;\n            sadd(p_2, p_2p, x2, true);\n            p_2.shift_left(1);\n            ssub(p_2, p_2p, x0, true);\n\n            NN pi(x2);\n\n            pi.sqr();\n            p_2.sqr();\n            p1.sqr();\n            p_1.sqr();\n            p0.sqr();\n\n            NN r0(p0);\n            NN r4(pi);\n\n            // r3 <- (p_2 - p1) / 3\n            NN r3(p_2);\n            bool r3p = ssub(r3, p1);\n            r3.div(3);\n\n            // r1 <- (p1 - p_1) / 2\n            NN r1(p1);\n            bool r1p = ssub(r1, p_1);\n            r1.shift_right(1);\n\n            // r2 <- p_1 - r0\n            NN r2(p_1);\n            bool r2p = ssub(r2, r0);\n\n            // r3 <- (r2 − r3)/2 + 2 * pi\n            r3p = !r3p;\n            sadd(r3, r3p, r2, r2p);\n            r3.shift_right(1);\n            pi.shift_left(1);\n            sadd(r3, r3p, pi, true);\n\n            // r2 <- r2 + r1 - r4\n            sadd(r2, r2p, r1, r1p);\n            ssub(r2, r2p, r4, true);\n\n            // r1 <- r1 - r3\n            ssub(r1, r1p, r3, r3p);\n\n            _limbs = r0._limbs;\n\n            if (r1p)\n                add(r1, k);\n            if (r2p)\n                add(r2, 2 * k);\n            if (r3p)\n                add(r3, 3 * k);\n\n            add(r4, 4 * k);\n\n            if (!r1p)\n                sub(r1, k);\n            if (!r2p)\n                sub(r2, 2 * k);\n            if (!r3p)\n                sub(r3, 3 * k);\n        }\n\n        void NN::pow(unsigned n)\n        {\n            NN a(ONE);\n            _limbs.swap(a._limbs);\n\n            while (n) {\n                if (n % 2) {\n                    mul(a);\n                    n -= 1;\n                }\n                a.sqr();\n                n /= 2;\n            }\n        }\n\n        void NN::div(const NN& d) { div_rem(d); }\n\n        void NN::rem(const NN& d) { _limbs = std::move(div_rem(d)._limbs); }\n\n        NN NN::div_rem(const NN& d)\n        {\n            if (d.is_zero())\n                throw DivisionByZeroError(to_string());\n\n            if (*this < d) {\n                NN r;\n                r._limbs.swap(_limbs);\n                return r;\n            }\n\n            if (*this == d) {\n                *this = ONE;\n                return ZERO;\n            }\n\n            return div_rem_bc(d);\n        }\n\n        NN NN::div_rem_bc(const NN& d)\n        {\n            assert(!d.is_zero());\n\n            NN A(*this);\n            NN B(d);\n\n#ifdef _MSC_VER\n            unsigned long index = 0;\n            _BitScanReverse(&index, B._limbs.back());\n            const unsigned k = 31 - index;\n#else\n            const unsigned k = __builtin_clz(B._limbs.back());\n#endif\n\n            B <<= k;\n            A <<= k;\n\n            const unsigned n = static_cast<unsigned>(B._limbs.size());\n            const unsigned m = static_cast<unsigned>(A._limbs.size() - n);\n\n            B._limbs.insert(B._limbs.begin(), m, 0);\n\n            _limbs.clear();\n            if (A >= B) {\n                _limbs.resize(m + 1, 0);\n                _limbs[m] = 1;\n                A -= B;\n            } else {\n                _limbs.resize(m, 0);\n            }\n\n            if (A.is_zero()) {\n                drop_zeros();\n                return ZERO;\n            }\n\n            const Limb B_leading_digit = B._limbs.back();\n\n            for (unsigned jj = 0; jj < m; ++jj) {\n                const unsigned j = m - 1 - jj;\n\n                Limb2 qs = 0;\n                if (n + j < A._limbs.size()) {\n                    qs = A._limbs[n + j];\n                    qs <<= LIMB_BITS;\n\n                    if (n + j < A._limbs.size() + 1)\n                        qs += A._limbs[n + j - 1];\n                }\n\n                qs /= B_leading_digit;\n\n                _limbs[j] = static_cast<Limb>(std::min(qs, static_cast<Limb2>(LIMB_MAX)));\n\n                NN T;\n\n                for (;;) {\n                    T._limbs.assign(B._limbs.begin() + jj + 1, B._limbs.end());\n                    T *= _limbs[j];\n\n                    if (A >= T)\n                        break;\n\n                    _limbs[j] -= 1;\n                }\n\n                A -= T;\n            }\n\n            drop_zeros();\n\n            A >>= k;\n\n            return A;\n        }\n\n        NN gcd(NN a, NN b)\n        {\n            NN t;\n\n            while (!b.is_zero()) {\n                t = b;\n                b = a;\n                b %= t;\n                a = t;\n            }\n\n            return a;\n        }\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas_mp/src/rr.cpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n"
  },
  {
    "path": "cyacas/libyacas_mp/src/zz.cpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#include \"yacas/mp/zz.hpp\"\n\n#include <cctype>\n\nnamespace yacas {\n    namespace mp {\n\n        const ZZ ZZ::ZERO = ZZ(0);\n        const ZZ ZZ::ONE = ZZ(1);\n        const ZZ ZZ::TWO = ZZ(2);\n        const ZZ ZZ::TEN = ZZ(10);\n\n        ZZ::ZZ(std::string_view s, unsigned b) : _neg(false)\n        {\n            auto p = s.cbegin();\n            const auto q = s.cend();\n\n            while (p != q && std::isspace(*p))\n                p += 1;\n\n            if (p == q)\n                throw ParseError(s, s.length());\n\n            if (*p == '+') {\n                p += 1;\n            } else if (*p == '-') {\n                _neg = true;\n                p += 1;\n            }\n\n            try {\n                _nn = NN(std::string_view(&(*p), std::distance(p, q)), b);\n            } catch (const NN::ParseError& e) {\n                throw ParseError(&(*p), std::distance(p, q));\n            }\n\n            if (_nn.is_zero())\n                _neg = false;\n        }\n\n        std::string ZZ::to_string(unsigned b) const\n        {\n            std::string s = _neg && !is_zero() ? \"-\" : \"\";\n            return s + _nn.to_string(b);\n        }\n    }\n}\n"
  },
  {
    "path": "cyacas/libyacas_mp/test/CMakeLists.txt",
    "content": "#\n# Copyright (C) 2017 Grzegorz Mazur <teoretyk@gmail.com>\n#\n# This file is part of yacas.\n# Yacas is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesset General Public License as\n# published by the Free Software Foundation, either version 2.1\n# of the License, or (at your option) any later version.\n#\n# Yacas is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n#\n#\n\nfind_package (GTest REQUIRED)\n\nadd_executable (yacas_mp_test src/nn_test.cpp src/zz_test.cpp)\ntarget_link_libraries (yacas_mp_test libyacas_mp GTest::GTest GTest::Main)\n\ngtest_add_tests (yacas_mp_test \"\" AUTO)\n"
  },
  {
    "path": "cyacas/libyacas_mp/test/src/nn_test.cpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#include \"yacas/mp/zz.hpp\"\n\n#include <gtest/gtest.h>\n\nusing namespace yacas::mp;\n\nTEST(YMP_NNTest, construction)\n{\n    ASSERT_TRUE(NN(\"0\").is_zero());\n    ASSERT_EQ(NN(\"123\"), NN(123u));\n    ASSERT_EQ(NN(\" 123\"), NN(123u));\n    ASSERT_EQ(NN(\"FF\", 16), NN(\"255\"));\n    ASSERT_EQ(NN(\"ff\", 16), NN(\"255\"));\n    ASSERT_EQ(NN(\"deadbeef\", 16), NN(\"3735928559\"));\n    ASSERT_THROW(NN(\"\"), NN::ParseError);\n    ASSERT_THROW(NN(\" \"), NN::ParseError);\n    ASSERT_THROW(NN(\"deadbeef\", 15), NN::ParseError);\n}\n\nTEST(YMP_NNTest, is_zero)\n{\n    ASSERT_TRUE(NN(0u).is_zero());\n    ASSERT_FALSE(NN(1u).is_zero());\n    ASSERT_FALSE(NN(\"4294967296\").is_zero());\n}\n\nTEST(YMP_NNTest, comparison)\n{\n    ASSERT_TRUE(NN(\"735\") == NN(735u));\n    ASSERT_TRUE(NN(\"736\") != NN(\"735\"));\n    ASSERT_TRUE(NN(\"736\") > NN(\"735\"));\n    ASSERT_TRUE(NN(\"736\") >= NN(\"735\"));\n}\n\nTEST(YMP_NNTest, parity)\n{\n    ASSERT_TRUE(NN(0u).is_even());\n    ASSERT_FALSE(NN(1u).is_even());\n    ASSERT_TRUE(NN(2u).is_even());\n    ASSERT_FALSE(NN(3u).is_even());\n}\n\nTEST(YMP_NNTest, to_string)\n{\n    ASSERT_EQ(NN(0u).to_string(10), \"0\");\n    ASSERT_EQ(NN(1u).to_string(10), \"1\");\n    ASSERT_EQ(NN(2u).to_string(10), \"2\");\n    ASSERT_EQ(NN(\"18446744073709551616\").to_string(), \"18446744073709551616\");\n\n    ASSERT_EQ(\n        NN(\"121932631356500531591068431703703700581771069347203169112635269\")\n            .to_string(),\n        \"121932631356500531591068431703703700581771069347203169112635269\");\n\n    ASSERT_EQ(NN(\"3735928559\").to_string(16), \"deadbeef\");\n\n    ASSERT_EQ(\n        NN(\"121932631356500531591068431703703700581771069347203169112635269\")\n            .to_string(),\n        \"121932631356500531591068431703703700581771069347203169112635269\");\n}\n\nTEST(YMP_NNTest, io)\n{\n    std::ostringstream os;\n\n    os << std::hex << NN(\"3735928559\");\n    ASSERT_EQ(os.str(), \"deadbeef\");\n    os.str(\"\");\n    os.clear();\n    os << std::oct << NN(\"3735928559\");\n    ASSERT_EQ(os.str(), \"33653337357\");\n}\n\nTEST(YMP_NNTest, shift)\n{\n    NN a;\n\n    a = NN(5);\n    a <<= 1;\n    ASSERT_EQ(a, NN(10));\n\n    a = NN(5);\n    a >>= 1;\n    ASSERT_EQ(a, NN(2));\n\n    a = NN(\"121932631356500531591068431703703700581771069347203169112635268\");\n    a >>= 1;\n    ASSERT_EQ(\n        a,\n        NN(\"60966315678250265795534215851851850290885534673601584556317634\"));\n    a <<= 37;\n    ASSERT_EQ(\n        a,\n        NN(\"8379146623862302403044060157846671297166126665682970886501213062979125248\"));\n    a >>= 32;\n    ASSERT_EQ(\n        a,\n        NN(\"1950922101704008505457094907259259209308337109555250705802164288\"));\n}\n\nTEST(YMP_NNTest, sqr)\n{\n    NN a;\n\n    a.sqr();\n    ASSERT_EQ(a, NN::ZERO);\n\n    a = NN(5);\n    a.sqr();\n    ASSERT_EQ(a, NN(\"25\"));\n\n    a = NN(\"1562953088685537097059913193583733507649747348170814625952201\");\n    a.sqr();\n    ASSERT_EQ(\n        a,\n        NN(\"2442822357431660390046655205292608987306861461763843847861569410791\"\n           \"671541750358984338534812651100785465086339385936744401\"));\n\n    a = NN(\"1667703557600363725046376676090748681843605861855768202333970544912\"\n           \"5918899\");\n    a.sqr();\n    ASSERT_EQ(a,\n              NN(\"2781235156032909688867661347708318236031357056471990889749656\"\n                 \"8874577914400268908763247285607086599717046124954345677502282\"\n                 \"2347627260616871125372201\"));\n    a.sqr();\n    ASSERT_EQ(a,\n              NN(\"7735268993153403503304606191118795696610949078309176540718091\"\n                 \"8697187558629814838215212696461020230376125043081229650956490\"\n                 \"7199281643513660336004802212689814512583461474131759251703924\"\n                 \"1448510014854449620623685195394076123932122239019841816567816\"\n                 \"5748977200849860077295483412916485724330783584401\"));\n\n    a = NN(\"43298432840974328947183271491541079320475403764598753914325843075329\"\n           \"85041258796438702654310726508743652874365432087655736345012364756043\"\n           \"81753408315620873167430821540810560872643218756743810564783105825648\"\n           \"74056087436587431065731486504375673456743053247885032856087432065310\"\n           \"87564398204357520436574325863520007434365308725624380653765208734132\"\n           \"46475659873589327902573743285932585467423285984375932575852094237923\"\n           \"579328\");\n\n    a.sqr();\n    ASSERT_EQ(a,\n              NN(\"187475428648436429856831489259327536436520448042946087510189029\"\n                 \"508938780965513552632980143411535002947654949460620663344635790\"\n                 \"556377422365029345765733894771796962944560922729298314258140552\"\n                 \"929369408117002607439027128831914911354137217799235321698085404\"\n                 \"005442143761335597185337908611893721164171813516683980879772274\"\n                 \"862485082671460833262731384783122158289313793496453424229418477\"\n                 \"994889974902044275544841799735966023054440842435704344714181994\"\n                 \"613927594359524428405377856257194202888469364705167511792141640\"\n                 \"532726328300226911110011094535694877421493842649850484322056237\"\n                 \"900295096809510203923061353581327350260262295074165065947916753\"\n                 \"169818423862934362386660760025589538715872105323918909971201848\"\n                 \"819723597348997720621263653492740044130493923227011660433942814\"\n                 \"829917409985490369529307633336067725045689754286184615455264247\"\n                 \"108931584\"));\n\n    NN b{a};\n    a.sqr();\n    b *= b;\n    ASSERT_EQ(a, b);\n    a.sqr();\n    b *= b;\n    ASSERT_EQ(a, b);\n}\n\nTEST(YMP_NNTest, mul)\n{\n    NN a(10);\n    a *= 10;\n    ASSERT_EQ(a, NN(100));\n    a *= 10;\n    ASSERT_EQ(a, NN(1000));\n    a *= 10;\n    ASSERT_EQ(a, NN(10000));\n    a *= 100;\n    ASSERT_EQ(a, NN(1000000));\n    a *= 100;\n    ASSERT_EQ(a, NN(100000000));\n    a *= 100;\n    ASSERT_EQ(a, NN(\"10000000000\"));\n    a *= 100;\n    ASSERT_EQ(a, NN(\"1000000000000\"));\n    a *= 100;\n    ASSERT_EQ(a, NN(\"100000000000000\"));\n    a *= 753;\n    ASSERT_EQ(a, NN(\"75300000000000000\"));\n    NN b(10);\n    a *= b;\n    ASSERT_EQ(a, NN(\"753000000000000000\"));\n\n    NN x(\"4294967296\");\n    NN y(\"4294967296\");\n    x *= y;\n    ASSERT_EQ(x, NN(\"18446744073709551616\"));\n\n    x = NN(\"123456789123456789123456789\");\n    y = NN(\"987654321987654321987654321987654321\");\n    x *= y;\n    ASSERT_EQ(\n        x,\n        NN(\"121932631356500531591068431703703700581771069347203169112635269\"));\n}\n\nTEST(YMP_NNTest, pow)\n{\n    NN a(\"1234567890123456789\");\n\n    a.pow(7);\n    ASSERT_EQ(\n        a,\n        NN(\"4371241899268725428364208289519510588539212553598950486912858825153\"\n           \"547618526426094549436384682321156604105518810510686881926429\"));\n}\n\nTEST(YMP_NNTest, div_rem)\n{\n    NN a(123);\n\n    ASSERT_THROW(a /= 0, std::domain_error);\n    ASSERT_EQ(a /= 1, NN(123));\n    ASSERT_EQ(a /= 123, NN::ONE);\n    a = NN(\"123\");\n    ASSERT_EQ(a /= 10, NN(12));\n    ASSERT_EQ(a /= 6, NN(2));\n\n    a = NN(\"12314324325435664576576568787687576435342431432545345\");\n    a /= 743;\n    ASSERT_EQ(a, NN(\"16573787786589050574127279660413965592654685642725\"));\n    a = NN(123);\n\n    ASSERT_THROW(a /= NN::ZERO, std::domain_error);\n    ASSERT_EQ((a /= NN(1)), NN(123));\n    ASSERT_EQ((a /= NN(123)), NN::ONE);\n    a = NN(\"123\");\n    ASSERT_EQ((a /= NN(10)), NN(12));\n    ASSERT_EQ((a /= NN(6)), NN(2));\n    a = NN(\"1125899906842624\");\n    NN b(\"562949953421312\");\n    a /= b;\n    ASSERT_EQ(a, NN::TWO);\n    a = NN(\"79228162514264337593543950335\");\n    b = NN(\"39614081257132168796771975168\");\n    a /= b;\n    ASSERT_EQ(a, NN::ONE);\n    a = NN(\"79228162514264337593543950336\");\n    b = NN(\"39614081257132168796771975168\");\n    a /= b;\n    ASSERT_EQ(a, NN::TWO);\n    a = NN(\"12314324325435664576576568787687576435342431432545345\");\n    b = NN(\"42345346452431432543645634543455434\");\n    a /= b;\n    ASSERT_EQ(a, NN(\"290807027385380782\"));\n\n    a = NN(1);\n    for (int i = 1; i <= 20; ++i)\n        a *= NN(i);\n    b = NN(1);\n    for (int i = 1; i <= 10; ++i)\n        b *= NN(i);\n    a /= b;\n    ASSERT_EQ(a, NN(\"670442572800\"));\n\n    a = NN(1);\n    for (int i = 1; i <= 50; ++i)\n        a *= NN(i);\n    b = NN(1);\n    for (int i = 1; i <= 40; ++i)\n        b *= NN(i);\n    a /= b;\n    ASSERT_EQ(a, NN(\"37276043023296000\"));\n\n    a = NN(1);\n    for (int i = 1; i <= 100; ++i)\n        a *= NN(i);\n    b = NN(1);\n    for (int i = 1; i <= 90; ++i)\n        b *= NN(i);\n    a /= b;\n    ASSERT_EQ(a, NN(\"62815650955529472000\"));\n\n    a = NN(1);\n    for (int i = 1; i <= 150; ++i)\n        a *= NN(i);\n    b = NN(1);\n    for (int i = 1; i <= 140; ++i)\n        b *= NN(i);\n    a /= b;\n    ASSERT_EQ(a, NN(\"4244078637389118528000\"));\n\n    a = NN(1);\n    for (int i = 1; i <= 180; ++i)\n        a *= NN(i);\n\n    ASSERT_EQ(\n        a,\n        NN(\"2008960624991342996569513368984668389175403407988677779404353351600\"\n           \"4486095339598094118013811209730973563159410103739960967103213218633\"\n           \"1495273609598531966730972945653558819806475064353856858157445040809\"\n           \"2095603584633196446648911142564300178241417967538181923386423026933\"\n           \"27818731986039603200000000000000000000000000000000000000000000\"));\n\n    b = NN(1);\n    for (int i = 1; i <= 170; ++i)\n        b *= NN(i);\n\n    ASSERT_EQ(\n        b,\n        NN(\"7257415615307998967396728211129263114716991681296451376543577798900\"\n           \"5618434017061578523507492426174595114909912378385207766660225654427\"\n           \"5302532890077320751090240043028005829560396661259965825710439855829\"\n           \"4257568966313439612262571094946806711205568880457193340212661452800\"\n           \"000000000000000000000000000000000000000\"));\n\n    a /= b;\n    ASSERT_EQ(a, NN(\"27681487894311318144000\"));\n\n    a = NN(\"1234567890123456789\");\n    b = NN(\"987654321\");\n    a /= b;\n    ASSERT_EQ(a, NN(\"1249999988\"));\n\n    a = NN(\"281512773099640599001078059567905818350\");\n    b = NN(\"72873402435871630350805926803788103957\");\n\n    a /= b;\n    ASSERT_EQ(a, NN(\"3\"));\n\n    a = NN(\"123456789012345678901234567890123456789012345678901234567890123456\"\n           \"789012345678901234567890123456789012345678901234567890123456789012\"\n           \"345678901234567890123456789012345678901234567890123456789012345678\"\n           \"901234567890123456789012345678901234567890123456789012345678901234\"\n           \"567890123456789012345678901234567890123456789012345678901234567890\"\n           \"123456789012345678901234567890123456789012345678901234567890123456\"\n           \"789012345678901234567890123456789012345678901234567890123456789012\"\n           \"345678901234567890123456789012345678901234567890123456789012345678\"\n           \"901234567890123456789012345678901234567890123456789012345678901234\"\n           \"567890123456789012345678901234567890123456789012345678901234567890\"\n           \"123456789012345678901234567890123456789012345678901234567890123456\"\n           \"789012345678901234567890123456789012345678901234567890123456789012\"\n           \"345678901234567890123456789012345678901234567890123456789012345678\"\n           \"901234567890123456789012345678901234567890123456789012345678901234\"\n           \"567890123456789012345678901234567890123456789012345678901234567890\"\n           \"123456789012345678901234567890123456789012345678901234567890123456\"\n           \"789012345678901234567890123456789012345678901234567890123456789012\"\n           \"345678901234567890123456789012345678901234567890123456789012345678\"\n           \"901234567890123456789012345678901234567890123456789012345678901234\"\n           \"567890123456789012345678901234567890123456789012345678901234567890\"\n           \"123456789012345678901234567890123456789012345678901234567890123456\"\n           \"789012345678901234567890123456789012345678901234567890123456789012\"\n           \"345678901234567890123456789012345678901234567890123456789012345678\"\n           \"901234567890123456789012345678901234567890123456789012345678901234\"\n           \"567890123456789012345678901234567890123456789012345678901234567890\"\n           \"123456789012345678901234567890123456789012345678901234567890123456\"\n           \"789012345678901234567890123456789012345678901234567890123456789012\"\n           \"345678901234567890123456789012345678901234567890123456789012345678\"\n           \"901234567890123456789012345678901234567890123456789012345678901234\"\n           \"5678901234567890123456789012345678901234567890123456789012345678\"\n           \"9\");\n    b = NN(\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"1234567890123456789012345678901234567890123456789012345678901234567890\"\n        \"123456789\");\n\n    a /= b;\n\n    ASSERT_EQ(a,\n              NN(\"1000000000000000000000000000000000000000000000000000000000000\"\n                 \"00000000000000000000\"));\n\n    a = NN(\"340282366920938463463374607431768211456\");\n    b = NN(\"4\");\n    a /= b;\n    ASSERT_EQ(a, NN(\"85070591730234615865843651857942052864\"));\n    a = NN(3);\n    ASSERT_THROW(a %= 0, std::domain_error);\n    a %= NN(2);\n    ASSERT_EQ(a, NN(\"1\"));\n\n    a = NN(\"12314324325435664576576568787687576435342431432545345\");\n    a %= 743;\n    ASSERT_EQ(a, NN(670));\n\n    a = NN(\"1234567890123456789\");\n    b = NN(\"987654321\");\n    a %= b;\n    ASSERT_EQ(a, NN(\"725308641\"));\n\n    a = NN(\"2618461302565558051873150214470675720371752830764642155368330885104190000\");\n    b = NN(\"141326557078049505524642968688\");\n    a /= b;\n    ASSERT_EQ(a, NN(\"18527737155016642260898961793617744820333125\"));\n}\n\nTEST(YMP_NNTest, bitwise) {}\n\nTEST(YMP_NNTest, no_digits)\n{\n    ASSERT_EQ(NN().no_digits(), 1);\n    ASSERT_EQ(NN(\"1234567890123456789\").no_digits(), 19);\n    ASSERT_EQ(\n        NN(\"12314324325435664576576568787687576435342431432545345\").no_digits(),\n        53);\n    NN a = NN(10);\n    a.pow(93);\n    ASSERT_EQ(a.no_digits(), 94);\n    a -= 1;\n    ASSERT_EQ(a.no_digits(), 93);\n}\n\nTEST(YMP_NNTest, gcd)\n{\n    NN a(6);\n    NN b(4);\n\n    NN c;\n\n    c = gcd(a, b);\n\n    ASSERT_EQ(c, NN(2));\n}\n"
  },
  {
    "path": "cyacas/libyacas_mp/test/src/zz_test.cpp",
    "content": "/*\n *\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#include \"yacas/mp/zz.hpp\"\n\n#include <gtest/gtest.h>\n\nusing namespace yacas::mp;\n\nTEST(YMP_ZZTest, construction)\n{\n    ASSERT_EQ(ZZ(\"0\"), ZZ(0));\n    ASSERT_EQ(ZZ(\"123\"), ZZ(123));\n    ASSERT_EQ(ZZ(\" 123\"), ZZ(123));\n    ASSERT_EQ(ZZ(\"+123\"), ZZ(123));\n    ASSERT_EQ(ZZ(\"FF\", 16), ZZ(\"255\"));\n    ASSERT_EQ(ZZ(\"-FF\", 16), ZZ(\"-255\"));\n    ASSERT_EQ(ZZ(\"ff\", 16), ZZ(\"255\"));\n    ASSERT_EQ(ZZ(\"-ff\", 16), ZZ(\"-255\"));\n    ASSERT_EQ(ZZ(\"deadbeef\", 16), ZZ(\"3735928559\"));\n    ASSERT_EQ(ZZ(\"-deadbeef\", 16), ZZ(\"-3735928559\"));\n    ASSERT_THROW(ZZ(\"\"), ZZ::ParseError);\n    ASSERT_THROW(ZZ(\" \"), ZZ::ParseError);\n    ASSERT_THROW(ZZ(\"deadbeef\", 15), ZZ::ParseError);\n}\n\nTEST(YMP_ZZTest, is_zero)\n{\n    ASSERT_TRUE(ZZ(0).is_zero());\n    ASSERT_FALSE(ZZ(1).is_zero());\n    ASSERT_FALSE(ZZ(-1).is_zero());\n    ASSERT_FALSE(ZZ(\"4294967296\").is_zero());\n    ASSERT_TRUE(ZZ(\"-0\").is_zero());\n}\n\nTEST(YMP_ZZTest, comparison)\n{\n    ASSERT_TRUE(ZZ(\"735\") == ZZ(735));\n    ASSERT_TRUE(ZZ(\"-735\") == ZZ(-735));\n    ASSERT_TRUE(ZZ(\"-735\") != ZZ(735));\n    ASSERT_TRUE(ZZ(\"736\") != ZZ(\"735\"));\n    ASSERT_TRUE(ZZ(\"736\") > ZZ(\"735\"));\n    ASSERT_TRUE(ZZ(\"736\") >= ZZ(\"735\"));\n    ASSERT_TRUE(ZZ(\"736\") > ZZ(\"-736\"));\n    ASSERT_TRUE(ZZ(\"-736\") <= ZZ(\"735\"));\n}\n\nTEST(YMP_ZZTest, parity)\n{\n    ASSERT_TRUE(ZZ(0).is_even());\n    ASSERT_FALSE(ZZ(1).is_even());\n    ASSERT_FALSE(ZZ(-1).is_even());\n    ASSERT_TRUE(ZZ(2).is_even());\n    ASSERT_TRUE(ZZ(-2).is_even());\n    ASSERT_FALSE(ZZ(3).is_even());\n    ASSERT_FALSE(ZZ(-3).is_even());\n    ASSERT_TRUE(ZZ(\"167170571948282915479450721253708836308\").is_even());\n    ASSERT_TRUE(ZZ(\"-167170571948282915479450721253708836308\").is_even());\n    ASSERT_FALSE(ZZ(\"167170571948282915479450721253708836309\").is_even());\n    ASSERT_FALSE(ZZ(\"-167170571948282915479450721253708836309\").is_even());\n}\n\nTEST(YMP_ZZTest, to_string)\n{\n    ASSERT_EQ(ZZ(0).to_string(10), \"0\");\n    ASSERT_EQ(ZZ(1).to_string(10), \"1\");\n    ASSERT_EQ(ZZ(-1).to_string(10), \"-1\");\n    ASSERT_EQ(ZZ(2).to_string(10), \"2\");\n    ASSERT_EQ(ZZ(-2).to_string(10), \"-2\");\n    ASSERT_EQ(ZZ(\"18446744073709551616\").to_string(), \"18446744073709551616\");\n    ASSERT_EQ(ZZ(\"-18446744073709551616\").to_string(), \"-18446744073709551616\");\n\n    ASSERT_EQ(ZZ(\"121932631356500531591068431703703700581771069347203169112635269\").to_string(), \"121932631356500531591068431703703700581771069347203169112635269\");\n    ASSERT_EQ(ZZ(\"-121932631356500531591068431703703700581771069347203169112635269\").to_string(), \"-121932631356500531591068431703703700581771069347203169112635269\");\n\n    ASSERT_EQ(ZZ(\"3735928559\").to_string(16), \"deadbeef\");\n    ASSERT_EQ(ZZ(\"-3735928559\").to_string(16), \"-deadbeef\");\n}\n\nTEST(YMP_ZZTest, io)\n{\n    std::ostringstream os;\n\n    os << std::hex << ZZ(\"3735928559\");\n    ASSERT_EQ(os.str(), \"deadbeef\");\n    os.str(\"\");\n    os.clear();\n    os << std::oct << ZZ(\"3735928559\");\n    ASSERT_EQ(os.str(), \"33653337357\");\n}\n\nTEST(YMP_ZZTest, shift)\n{\n    ZZ a;\n\n    a = ZZ(5);\n    a <<= 1;\n    ASSERT_EQ(a, ZZ(10));\n\n    a = ZZ(-5);\n    a <<= 1;\n    ASSERT_EQ(a, ZZ(-10));\n\n    a >>= 2;\n    ASSERT_EQ(a, ZZ(-2));\n\n    a = ZZ(\"-121932631356500531591068431703703700581771069347203169112635268\");\n    a >>= 1;\n    ASSERT_EQ(a, ZZ(\"-60966315678250265795534215851851850290885534673601584556317634\"));\n}\n\n\n\nTEST(YMP_ZZTest, sqr)\n{\n    ZZ a;\n\n    a = ZZ(5);\n    a.sqr();\n    ASSERT_EQ(a, ZZ(\"25\"));\n\n    a = ZZ(\"-1562953088685537097059913193583733507649747348170814625952201\");\n    a.sqr();\n    ASSERT_EQ(a, ZZ(\"2442822357431660390046655205292608987306861461763843847861569410791671541750358984338534812651100785465086339385936744401\"));\n\n    a = ZZ(\"16677035576003637250463766760907486818436058618557682023339705449125918899\");\n    a.sqr();\n    ASSERT_EQ(a, ZZ(\"278123515603290968886766134770831823603135705647199088974965688745779144002689087632472856070865997170461249543456775022822347627260616871125372201\"));\n    a.sqr();\n    ASSERT_EQ(a, ZZ(\"77352689931534035033046061911187956966109490783091765407180918697187558629814838215212696461020230376125043081229650956490719928164351366033600480221268981451258346147413175925170392414485100148544496206236851953940761239321222390198418165678165748977200849860077295483412916485724330783584401\"));\n}\n\nTEST(YMP_ZZTest, add)\n{\n    ZZ a(10);\n    a += 10;\n    ASSERT_EQ(a, 20);\n    a += -21;\n    ASSERT_EQ(a, -1);\n    a += 0;\n    ASSERT_EQ(a, -1);\n    a += -2;\n    ASSERT_EQ(a, -3);\n    a += 4;\n    ASSERT_EQ(a, 1);\n\n    ZZ x(\"123456789123456789123456789\");\n    ZZ y(\"-987654321987654321987654321987654321\");\n\n    x += y;\n\n    ASSERT_EQ(x, ZZ(\"-987654321864197532864197532864197532\"));\n    x += ZZ(\"987654321864197532864197532864197534\");\n    ASSERT_EQ(x, 2);\n}\n\n\nTEST(YMP_ZZTest, mul)\n{\n    ZZ a(10);\n    a *= 10;\n    ASSERT_EQ(a, ZZ(100));\n    a *= 10;\n    ASSERT_EQ(a, ZZ(1000));\n    a *= 10;\n    ASSERT_EQ(a, ZZ(10000));\n    a *= 100;\n    ASSERT_EQ(a, ZZ(1000000));\n    a *= 100;\n    ASSERT_EQ(a, ZZ(100000000));\n    a *= -100;\n    ASSERT_EQ(a, ZZ(\"-10000000000\"));\n    a *= -100;\n    ASSERT_EQ(a, ZZ(\"1000000000000\"));\n    a *= 100;\n    ASSERT_EQ(a, ZZ(\"100000000000000\"));\n    a *= -753;\n    ASSERT_EQ(a, ZZ(\"-75300000000000000\"));\n    ZZ b(-10);\n    a *= b;\n    ASSERT_EQ(a, ZZ(\"753000000000000000\"));\n\n    ZZ x(\"4294967296\");\n    ZZ y(\"-4294967296\");\n    x *= y;\n    ASSERT_EQ(x, ZZ(\"-18446744073709551616\"));\n\n    x = ZZ(\"-123456789123456789123456789\");\n    y = ZZ(\"-987654321987654321987654321987654321\");\n    x *= y;\n    ASSERT_EQ(x, ZZ(\"121932631356500531591068431703703700581771069347203169112635269\"));\n}\n\nTEST(YMP_ZZTest, pow)\n{\n    ZZ a(\"-1234567890123456789\");\n\n    a.pow(7);\n    ASSERT_EQ(a, ZZ(\"-4371241899268725428364208289519510588539212553598950486912858825153547618526426094549436384682321156604105518810510686881926429\"));\n}\n\nTEST(YMP_ZZTest, div)\n{\n    ZZ a(-123);\n\n    ASSERT_THROW(a /= 0, std::domain_error);\n    ASSERT_EQ(a /= 1, ZZ(-123));\n    ASSERT_EQ(a /= -123, ZZ::ONE);\n    a = ZZ(\"123\");\n    ASSERT_EQ(a /= 10, ZZ(12));\n    ASSERT_EQ(a /= -6, ZZ(-2));\n\n    a = ZZ(\"-12314324325435664576576568787687576435342431432545345\");\n    a /= 743;\n    ASSERT_EQ(a, ZZ(\"-16573787786589050574127279660413965592654685642725\"));\n    a = ZZ(-123);\n\n    ASSERT_THROW(a /= ZZ::ZERO, std::domain_error);\n    ASSERT_EQ((a /= ZZ(1)), ZZ(-123));\n    ASSERT_EQ((a /= ZZ(123)), ZZ(-1));\n    a = ZZ(\"-123\");\n    ASSERT_EQ((a /= ZZ(10)), ZZ(-12));\n    ASSERT_EQ((a /= ZZ(-6)), ZZ(2));\n    a = ZZ(\"-1125899906842624\");\n    ZZ b(\"-562949953421312\");\n    a /= b;\n    ASSERT_EQ(a, ZZ::TWO);\n    a = ZZ(\"79228162514264337593543950335\");\n    b = ZZ(\"39614081257132168796771975168\");\n    a /= b;\n    ASSERT_EQ(a, ZZ::ONE);\n    a = ZZ(\"-79228162514264337593543950336\");\n    b = ZZ(\"-39614081257132168796771975168\");\n    a /= b;\n    ASSERT_EQ(a, ZZ::TWO);\n    a = ZZ(\"-12314324325435664576576568787687576435342431432545345\");\n    b = ZZ(\"42345346452431432543645634543455434\");\n    a /= b;\n    ASSERT_EQ(a, ZZ(\"-290807027385380782\"));\n\n    a = ZZ(1);\n    for (int i = 1; i <= 180; ++i)\n        a *= ZZ(-i);\n\n    ASSERT_EQ(a, ZZ(\"200896062499134299656951336898466838917540340798867777940435335160044860953395980941180138112097309735631594101037399609671032132186331495273609598531966730972945653558819806475064353856858157445040809209560358463319644664891114256430017824141796753818192338642302693327818731986039603200000000000000000000000000000000000000000000\"));\n\n    b = ZZ(-1);\n    for (int i = 1; i <= 170; ++i)\n        b *= ZZ(i);\n\n    ASSERT_EQ(b, ZZ(\"-7257415615307998967396728211129263114716991681296451376543577798900561843401706157852350749242617459511490991237838520776666022565442753025328900773207510902400430280058295603966612599658257104398558294257568966313439612262571094946806711205568880457193340212661452800000000000000000000000000000000000000000\"));\n\n    a /= b;\n    ASSERT_EQ(a, ZZ(\"-27681487894311318144000\"));\n\n    a = ZZ(\"1234567890123456789\");\n    b = ZZ(\"-987654321\");\n    a /= b;\n    ASSERT_EQ(a, ZZ(\"-1249999988\"));\n\n    a = ZZ(\"-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\");\n    b = ZZ(\"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\");\n\n    a /= b;\n\n    ASSERT_EQ(a, ZZ(\"-100000000000000000000000000000000000000000000000000000000000000000000000000000000\"));\n}\n\nTEST(YMP_ZZTest, rem)\n{\n    ZZ a(3);\n    a %= ZZ(2);\n    ASSERT_EQ(a, ZZ(\"1\"));\n\n    a = ZZ(\"12314324325435664576576568787687576435342431432545345\");\n    a %= 743;\n    ASSERT_EQ(a, ZZ(670));\n\n    a = ZZ(\"1234567890123456789\");\n    ZZ b(\"987654321\");\n    a %= b;\n    ASSERT_EQ(a, ZZ(\"725308641\"));\n}\n\nTEST(YMP_ZZTest, no_digits)\n{\n    ASSERT_EQ(ZZ().no_digits(), 1);\n    ASSERT_EQ(ZZ(1).no_digits(), 1);\n    ASSERT_EQ(ZZ(2).no_digits(), 1);\n    ASSERT_EQ(ZZ(3).no_digits(), 1);\n    ASSERT_EQ(ZZ(4).no_digits(), 1);\n    ASSERT_EQ(ZZ(5).no_digits(), 1);\n    ASSERT_EQ(ZZ(6).no_digits(), 1);\n    ASSERT_EQ(ZZ(7).no_digits(), 1);\n    ASSERT_EQ(ZZ(8).no_digits(), 1);\n    ASSERT_EQ(ZZ(9).no_digits(), 1);\n    ASSERT_EQ(ZZ(10).no_digits(), 2);\n    ASSERT_EQ(ZZ(99).no_digits(), 2);\n    ASSERT_EQ(ZZ(100).no_digits(), 3);\n    ZZ a = ZZ(\"1234567890123456789\");\n    ASSERT_EQ(a.no_digits(), 19);\n    a = ZZ(\"-12314324325435664576576568787687576435342431432545345\");\n    ASSERT_EQ(a.no_digits(), 53);\n    a = ZZ(-10);\n    a.pow(93);\n    ASSERT_EQ(a.no_digits(), 94);\n}\n\nTEST(YMP_ZZTest, gcd)\n{\n    ZZ a(-6);\n    ZZ b(4);\n\n    ZZ c;\n\n    c = gcd(a, b);\n\n    ASSERT_EQ(c, ZZ(2));\n}\n"
  },
  {
    "path": "cyacas/packaging/deb/changelog",
    "content": "yacas (1.9.2-1) UNRELEASED; urgency=low\n\n  * New upstream release\n\n -- Grzegorz Mazur <teoretyk@gmail.com>  Tue,  4 Aug 2020 19:02:24 +0200\n\nyacas (1.9.1-1) UNRELEASED; urgency=low\n\n  * New upstream release\n\n -- Grzegorz Mazur <teoretyk@gmail.com>  Wed,  1 Jul 2020 14:04:20 +0200\n\nyacas (1.8.0-1) UNRELEASED; urgency=low\n\n  * New upstream release\n\n -- Grzegorz Mazur <teoretyk@gmail.com>  Thu, 31 Oct 2019 13:36:20 +0200\n"
  },
  {
    "path": "cyacas/packaging/deb/compat",
    "content": "12\n\n"
  },
  {
    "path": "cyacas/packaging/deb/control",
    "content": "Source: yacas\nMaintainer: Grzegorz Mazur <teoretyk@gmail.com>\nSection: contrib/math\nPriority: optional\nStandards-Version: 4.4.0\nBuild-Depends: debhelper (>=9),\n               cmake,\n               python3-sphinx,\n               python3-sphinx-rtd-theme,\n               python3-sphinxcontrib.bibtex,\n               qtbase5-dev,\n               qtbase5-dev-tools,\n               qtwebengine5-dev,\n               libqt5webengine5,\n               libqt5svg5-dev,\n               libssl-dev,\n               libzmqpp-dev,\n               libzmq3-dev,\n               libboost-date-time-dev,\n               libboost-filesystem-dev,\n               libboost-program-options-dev,\n               libjsoncpp-dev\nHomepage: http://www.yacas.org\n\nPackage: yacas-common\nArchitecture: all\nDepends: ${misc:Depends}\nDescription: Easy to use, general purpose Computer Algebra System\n Yacas is an easy to use, general purpose Computer Algebra System, a\n program for symbolic manipulation of mathematical expressions. It\n uses its own programming language designed for symbolic as well as\n arbitrary-precision numerical computations. The system has a library\n of scripts that implement many of the symbolic algebra operations;\n new algorithms can be easily added to the library. Yacas comes with\n extensive documentation covering the scripting language, the\n functionality that is already implemented in the system, and the\n algorithms we used.\n\nPackage: yacas-console\nArchitecture: any\nDepends: yacas-common (= ${source:Version}), yacas-doc (= ${source:Version}), gnuplot, ${shlibs:Depends}, ${misc:Depends}\nDescription: Easy to use, general purpose Computer Algebra System\n Yacas is an easy to use, general purpose Computer Algebra System, a\n program for symbolic manipulation of mathematical expressions. It\n uses its own programming language designed for symbolic as well as\n arbitrary-precision numerical computations. The system has a library\n of scripts that implement many of the symbolic algebra operations;\n new algorithms can be easily added to the library. Yacas comes with\n extensive documentation covering the scripting language, the\n functionality that is already implemented in the system, and the\n algorithms we used.\n\nPackage: yacas-gui\nArchitecture: any\nDepends: yacas-common (= ${source:Version}), yacas-doc (= ${source:Version}), ${shlibs:Depends}, ${misc:Depends}, libjs-jquery, libjs-jquery-ui, libjs-mathjax, fonts-mathjax, libjs-codemirror\nDescription: Graphical User Interface for yacas\n Yacas is an easy to use, general purpose Computer Algebra System, a\n program for symbolic manipulation of mathematical expressions. It\n uses its own programming language designed for symbolic as well as\n arbitrary-precision numerical computations. The system has a library\n of scripts that implement many of the symbolic algebra operations;\n new algorithms can be easily added to the library. Yacas comes with\n extensive documentation covering the scripting language, the\n functionality that is already implemented in the system, and the\n algorithms we used.\n\nPackage: yacas-kernel\nArchitecture: any\nDepends: ${shlibs:Depends}, yacas-common (= ${source:Version}), yacas-doc (= ${source:Version}), ${misc:Depends}\nDescription: Yacas kernel for Jupyter\n Yacas is an easy to use, general purpose Computer Algebra System, a\n program for symbolic manipulation of mathematical expressions. It\n uses its own programming language designed for symbolic as well as\n arbitrary-precision numerical computations. The system has a library\n of scripts that implement many of the symbolic algebra operations;\n new algorithms can be easily added to the library. Yacas comes with\n extensive documentation covering the scripting language, the\n functionality that is already implemented in the system, and the\n algorithms we used.\n\nPackage: yacas-doc\nArchitecture: all\nSection: contrib/doc\nDepends: ${misc:Depends}, fonts-lato, fonts-roboto-slab, fonts-glewlwyd, libjs-jquery, libjs-underscore\nSuggests: yacas-console (= ${binary:Version}), yacas-gui (= ${binary:Version})\nDescription: Documentation for Yacas\n Yacas documentation. Yacas is an easy to use, general purpose\n Computer Algebra System, a program for symbolic manipulation of\n mathematical expressions. It uses its own programming language\n designed for symbolic as well as arbitrary-precision numerical\n computations. The system has a library of scripts that implement many\n of the symbolic algebra operations; new algorithms can be easily\n added to the library. Yacas comes with extensive documentation\n covering the scripting language, the  functionality that is already\n implemented in the system, and the algorithms we used.\n\nPackage: yacas-dev\nArchitecture: any\nSection: contrib/devel\nDepends: ${misc:Depends}\nSuggests: yacas-console (= ${binary:Version}), yacas-gui (= ${binary:Version})\nDescription: Development files for Yacas\n Header files and libraries necessary for yacas development. Yacas is\n an easy to use, general purpose Computer Algebra System, a program\n for symbolic manipulation of mathematical expressions. It uses its\n own programming language designed for symbolic as well as\n arbitrary-precision numerical computations. The system has a library\n of scripts that implement many of the symbolic algebra operations;\n new algorithms can be easily added to the library. Yacas comes with\n extensive documentation covering the scripting language, the\n functionality that is already implemented in the system, and the\n algorithms we used.\n"
  },
  {
    "path": "cyacas/packaging/deb/copyright",
    "content": "Debian packaging of yacas originally created in 1998 by:\n   John Lapeyre <lapeyre@physics.arizona.edu>\nand since 2010 improved and maintained by:\n   Muammar El Khatib <muammarelkhatib@gmail.com>\n\nThis set of debian packaging files was independently created in 2016 by:\n   Grzegorz Mazur <teoretyk@gmail.com>\nto facilitate building out-of-distribution packages of newer yacas versions\n\nUpstream source:\n\nhttps://github.com/grzegorzmazur/yacas\n\nCopyright:\n\n  Copyright © 1999-2016 by respective contributors; for the full list of\n  contributors see <https://yacas.readthedocs.io/en/latest/credits.html>\n\nLicense:\n\n  This program is free software: you can redistribute it and/or modify\n  it under the terms of the GNU Lesser General Public License as\n  published by the Free Software Foundation, either version 2.1 of the\n  License, or (at your option) any later version.\n\n  This program is distributed in the hope that it will be useful,\n  but WITHOUT ANY WARRANTY; without even the implied warranty of\n  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n  GNU Lesser General Public License for more details.\n\n  You should have received a copy of the GNU General Public License\n  along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n\n  For your convenience, on Debian systems the complete text of the LGPL 2.1\n  is in /usr/share/common-licenses/LGPL-2.1\n"
  },
  {
    "path": "cyacas/packaging/deb/missing-sources/jquery-ui.js",
    "content": "/*! jQuery UI - v1.12.1 - 2016-09-14\n* http://jqueryui.com\n* Includes: widget.js, position.js, data.js, disable-selection.js, effect.js, effects/effect-blind.js, effects/effect-bounce.js, effects/effect-clip.js, effects/effect-drop.js, effects/effect-explode.js, effects/effect-fade.js, effects/effect-fold.js, effects/effect-highlight.js, effects/effect-puff.js, effects/effect-pulsate.js, effects/effect-scale.js, effects/effect-shake.js, effects/effect-size.js, effects/effect-slide.js, effects/effect-transfer.js, focusable.js, form-reset-mixin.js, jquery-1-7.js, keycode.js, labels.js, scroll-parent.js, tabbable.js, unique-id.js, widgets/accordion.js, widgets/autocomplete.js, widgets/button.js, widgets/checkboxradio.js, widgets/controlgroup.js, widgets/datepicker.js, widgets/dialog.js, widgets/draggable.js, widgets/droppable.js, widgets/menu.js, widgets/mouse.js, widgets/progressbar.js, widgets/resizable.js, widgets/selectable.js, widgets/selectmenu.js, widgets/slider.js, widgets/sortable.js, widgets/spinner.js, widgets/tabs.js, widgets/tooltip.js\n* Copyright jQuery Foundation and other contributors; Licensed MIT */\n\n(function( factory ) {\n\tif ( typeof define === \"function\" && define.amd ) {\n\n\t\t// AMD. Register as an anonymous module.\n\t\tdefine([ \"jquery\" ], factory );\n\t} else {\n\n\t\t// Browser globals\n\t\tfactory( jQuery );\n\t}\n}(function( $ ) {\n\n$.ui = $.ui || {};\n\nvar version = $.ui.version = \"1.12.1\";\n\n\n/*!\n * jQuery UI Widget 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Widget\n//>>group: Core\n//>>description: Provides a factory for creating stateful widgets with a common API.\n//>>docs: http://api.jqueryui.com/jQuery.widget/\n//>>demos: http://jqueryui.com/widget/\n\n\n\nvar widgetUuid = 0;\nvar widgetSlice = Array.prototype.slice;\n\n$.cleanData = ( function( orig ) {\n\treturn function( elems ) {\n\t\tvar events, elem, i;\n\t\tfor ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {\n\t\t\ttry {\n\n\t\t\t\t// Only trigger remove when necessary to save time\n\t\t\t\tevents = $._data( elem, \"events\" );\n\t\t\t\tif ( events && events.remove ) {\n\t\t\t\t\t$( elem ).triggerHandler( \"remove\" );\n\t\t\t\t}\n\n\t\t\t// Http://bugs.jquery.com/ticket/8235\n\t\t\t} catch ( e ) {}\n\t\t}\n\t\torig( elems );\n\t};\n} )( $.cleanData );\n\n$.widget = function( name, base, prototype ) {\n\tvar existingConstructor, constructor, basePrototype;\n\n\t// ProxiedPrototype allows the provided prototype to remain unmodified\n\t// so that it can be used as a mixin for multiple widgets (#8876)\n\tvar proxiedPrototype = {};\n\n\tvar namespace = name.split( \".\" )[ 0 ];\n\tname = name.split( \".\" )[ 1 ];\n\tvar fullName = namespace + \"-\" + name;\n\n\tif ( !prototype ) {\n\t\tprototype = base;\n\t\tbase = $.Widget;\n\t}\n\n\tif ( $.isArray( prototype ) ) {\n\t\tprototype = $.extend.apply( null, [ {} ].concat( prototype ) );\n\t}\n\n\t// Create selector for plugin\n\t$.expr[ \":\" ][ fullName.toLowerCase() ] = function( elem ) {\n\t\treturn !!$.data( elem, fullName );\n\t};\n\n\t$[ namespace ] = $[ namespace ] || {};\n\texistingConstructor = $[ namespace ][ name ];\n\tconstructor = $[ namespace ][ name ] = function( options, element ) {\n\n\t\t// Allow instantiation without \"new\" keyword\n\t\tif ( !this._createWidget ) {\n\t\t\treturn new constructor( options, element );\n\t\t}\n\n\t\t// Allow instantiation without initializing for simple inheritance\n\t\t// must use \"new\" keyword (the code above always passes args)\n\t\tif ( arguments.length ) {\n\t\t\tthis._createWidget( options, element );\n\t\t}\n\t};\n\n\t// Extend with the existing constructor to carry over any static properties\n\t$.extend( constructor, existingConstructor, {\n\t\tversion: prototype.version,\n\n\t\t// Copy the object used to create the prototype in case we need to\n\t\t// redefine the widget later\n\t\t_proto: $.extend( {}, prototype ),\n\n\t\t// Track widgets that inherit from this widget in case this widget is\n\t\t// redefined after a widget inherits from it\n\t\t_childConstructors: []\n\t} );\n\n\tbasePrototype = new base();\n\n\t// We need to make the options hash a property directly on the new instance\n\t// otherwise we'll modify the options hash on the prototype that we're\n\t// inheriting from\n\tbasePrototype.options = $.widget.extend( {}, basePrototype.options );\n\t$.each( prototype, function( prop, value ) {\n\t\tif ( !$.isFunction( value ) ) {\n\t\t\tproxiedPrototype[ prop ] = value;\n\t\t\treturn;\n\t\t}\n\t\tproxiedPrototype[ prop ] = ( function() {\n\t\t\tfunction _super() {\n\t\t\t\treturn base.prototype[ prop ].apply( this, arguments );\n\t\t\t}\n\n\t\t\tfunction _superApply( args ) {\n\t\t\t\treturn base.prototype[ prop ].apply( this, args );\n\t\t\t}\n\n\t\t\treturn function() {\n\t\t\t\tvar __super = this._super;\n\t\t\t\tvar __superApply = this._superApply;\n\t\t\t\tvar returnValue;\n\n\t\t\t\tthis._super = _super;\n\t\t\t\tthis._superApply = _superApply;\n\n\t\t\t\treturnValue = value.apply( this, arguments );\n\n\t\t\t\tthis._super = __super;\n\t\t\t\tthis._superApply = __superApply;\n\n\t\t\t\treturn returnValue;\n\t\t\t};\n\t\t} )();\n\t} );\n\tconstructor.prototype = $.widget.extend( basePrototype, {\n\n\t\t// TODO: remove support for widgetEventPrefix\n\t\t// always use the name + a colon as the prefix, e.g., draggable:start\n\t\t// don't prefix for widgets that aren't DOM-based\n\t\twidgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name\n\t}, proxiedPrototype, {\n\t\tconstructor: constructor,\n\t\tnamespace: namespace,\n\t\twidgetName: name,\n\t\twidgetFullName: fullName\n\t} );\n\n\t// If this widget is being redefined then we need to find all widgets that\n\t// are inheriting from it and redefine all of them so that they inherit from\n\t// the new version of this widget. We're essentially trying to replace one\n\t// level in the prototype chain.\n\tif ( existingConstructor ) {\n\t\t$.each( existingConstructor._childConstructors, function( i, child ) {\n\t\t\tvar childPrototype = child.prototype;\n\n\t\t\t// Redefine the child widget using the same prototype that was\n\t\t\t// originally used, but inherit from the new version of the base\n\t\t\t$.widget( childPrototype.namespace + \".\" + childPrototype.widgetName, constructor,\n\t\t\t\tchild._proto );\n\t\t} );\n\n\t\t// Remove the list of existing child constructors from the old constructor\n\t\t// so the old child constructors can be garbage collected\n\t\tdelete existingConstructor._childConstructors;\n\t} else {\n\t\tbase._childConstructors.push( constructor );\n\t}\n\n\t$.widget.bridge( name, constructor );\n\n\treturn constructor;\n};\n\n$.widget.extend = function( target ) {\n\tvar input = widgetSlice.call( arguments, 1 );\n\tvar inputIndex = 0;\n\tvar inputLength = input.length;\n\tvar key;\n\tvar value;\n\n\tfor ( ; inputIndex < inputLength; inputIndex++ ) {\n\t\tfor ( key in input[ inputIndex ] ) {\n\t\t\tvalue = input[ inputIndex ][ key ];\n\t\t\tif ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {\n\n\t\t\t\t// Clone objects\n\t\t\t\tif ( $.isPlainObject( value ) ) {\n\t\t\t\t\ttarget[ key ] = $.isPlainObject( target[ key ] ) ?\n\t\t\t\t\t\t$.widget.extend( {}, target[ key ], value ) :\n\n\t\t\t\t\t\t// Don't extend strings, arrays, etc. with objects\n\t\t\t\t\t\t$.widget.extend( {}, value );\n\n\t\t\t\t// Copy everything else by reference\n\t\t\t\t} else {\n\t\t\t\t\ttarget[ key ] = value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn target;\n};\n\n$.widget.bridge = function( name, object ) {\n\tvar fullName = object.prototype.widgetFullName || name;\n\t$.fn[ name ] = function( options ) {\n\t\tvar isMethodCall = typeof options === \"string\";\n\t\tvar args = widgetSlice.call( arguments, 1 );\n\t\tvar returnValue = this;\n\n\t\tif ( isMethodCall ) {\n\n\t\t\t// If this is an empty collection, we need to have the instance method\n\t\t\t// return undefined instead of the jQuery instance\n\t\t\tif ( !this.length && options === \"instance\" ) {\n\t\t\t\treturnValue = undefined;\n\t\t\t} else {\n\t\t\t\tthis.each( function() {\n\t\t\t\t\tvar methodValue;\n\t\t\t\t\tvar instance = $.data( this, fullName );\n\n\t\t\t\t\tif ( options === \"instance\" ) {\n\t\t\t\t\t\treturnValue = instance;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( !instance ) {\n\t\t\t\t\t\treturn $.error( \"cannot call methods on \" + name +\n\t\t\t\t\t\t\t\" prior to initialization; \" +\n\t\t\t\t\t\t\t\"attempted to call method '\" + options + \"'\" );\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === \"_\" ) {\n\t\t\t\t\t\treturn $.error( \"no such method '\" + options + \"' for \" + name +\n\t\t\t\t\t\t\t\" widget instance\" );\n\t\t\t\t\t}\n\n\t\t\t\t\tmethodValue = instance[ options ].apply( instance, args );\n\n\t\t\t\t\tif ( methodValue !== instance && methodValue !== undefined ) {\n\t\t\t\t\t\treturnValue = methodValue && methodValue.jquery ?\n\t\t\t\t\t\t\treturnValue.pushStack( methodValue.get() ) :\n\t\t\t\t\t\t\tmethodValue;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\n\t\t\t// Allow multiple hashes to be passed on init\n\t\t\tif ( args.length ) {\n\t\t\t\toptions = $.widget.extend.apply( null, [ options ].concat( args ) );\n\t\t\t}\n\n\t\t\tthis.each( function() {\n\t\t\t\tvar instance = $.data( this, fullName );\n\t\t\t\tif ( instance ) {\n\t\t\t\t\tinstance.option( options || {} );\n\t\t\t\t\tif ( instance._init ) {\n\t\t\t\t\t\tinstance._init();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t$.data( this, fullName, new object( options, this ) );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\treturn returnValue;\n\t};\n};\n\n$.Widget = function( /* options, element */ ) {};\n$.Widget._childConstructors = [];\n\n$.Widget.prototype = {\n\twidgetName: \"widget\",\n\twidgetEventPrefix: \"\",\n\tdefaultElement: \"<div>\",\n\n\toptions: {\n\t\tclasses: {},\n\t\tdisabled: false,\n\n\t\t// Callbacks\n\t\tcreate: null\n\t},\n\n\t_createWidget: function( options, element ) {\n\t\telement = $( element || this.defaultElement || this )[ 0 ];\n\t\tthis.element = $( element );\n\t\tthis.uuid = widgetUuid++;\n\t\tthis.eventNamespace = \".\" + this.widgetName + this.uuid;\n\n\t\tthis.bindings = $();\n\t\tthis.hoverable = $();\n\t\tthis.focusable = $();\n\t\tthis.classesElementLookup = {};\n\n\t\tif ( element !== this ) {\n\t\t\t$.data( element, this.widgetFullName, this );\n\t\t\tthis._on( true, this.element, {\n\t\t\t\tremove: function( event ) {\n\t\t\t\t\tif ( event.target === element ) {\n\t\t\t\t\t\tthis.destroy();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\t\t\tthis.document = $( element.style ?\n\n\t\t\t\t// Element within the document\n\t\t\t\telement.ownerDocument :\n\n\t\t\t\t// Element is window or document\n\t\t\t\telement.document || element );\n\t\t\tthis.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );\n\t\t}\n\n\t\tthis.options = $.widget.extend( {},\n\t\t\tthis.options,\n\t\t\tthis._getCreateOptions(),\n\t\t\toptions );\n\n\t\tthis._create();\n\n\t\tif ( this.options.disabled ) {\n\t\t\tthis._setOptionDisabled( this.options.disabled );\n\t\t}\n\n\t\tthis._trigger( \"create\", null, this._getCreateEventData() );\n\t\tthis._init();\n\t},\n\n\t_getCreateOptions: function() {\n\t\treturn {};\n\t},\n\n\t_getCreateEventData: $.noop,\n\n\t_create: $.noop,\n\n\t_init: $.noop,\n\n\tdestroy: function() {\n\t\tvar that = this;\n\n\t\tthis._destroy();\n\t\t$.each( this.classesElementLookup, function( key, value ) {\n\t\t\tthat._removeClass( value, key );\n\t\t} );\n\n\t\t// We can probably remove the unbind calls in 2.0\n\t\t// all event bindings should go through this._on()\n\t\tthis.element\n\t\t\t.off( this.eventNamespace )\n\t\t\t.removeData( this.widgetFullName );\n\t\tthis.widget()\n\t\t\t.off( this.eventNamespace )\n\t\t\t.removeAttr( \"aria-disabled\" );\n\n\t\t// Clean up events and states\n\t\tthis.bindings.off( this.eventNamespace );\n\t},\n\n\t_destroy: $.noop,\n\n\twidget: function() {\n\t\treturn this.element;\n\t},\n\n\toption: function( key, value ) {\n\t\tvar options = key;\n\t\tvar parts;\n\t\tvar curOption;\n\t\tvar i;\n\n\t\tif ( arguments.length === 0 ) {\n\n\t\t\t// Don't return a reference to the internal hash\n\t\t\treturn $.widget.extend( {}, this.options );\n\t\t}\n\n\t\tif ( typeof key === \"string\" ) {\n\n\t\t\t// Handle nested keys, e.g., \"foo.bar\" => { foo: { bar: ___ } }\n\t\t\toptions = {};\n\t\t\tparts = key.split( \".\" );\n\t\t\tkey = parts.shift();\n\t\t\tif ( parts.length ) {\n\t\t\t\tcurOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );\n\t\t\t\tfor ( i = 0; i < parts.length - 1; i++ ) {\n\t\t\t\t\tcurOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};\n\t\t\t\t\tcurOption = curOption[ parts[ i ] ];\n\t\t\t\t}\n\t\t\t\tkey = parts.pop();\n\t\t\t\tif ( arguments.length === 1 ) {\n\t\t\t\t\treturn curOption[ key ] === undefined ? null : curOption[ key ];\n\t\t\t\t}\n\t\t\t\tcurOption[ key ] = value;\n\t\t\t} else {\n\t\t\t\tif ( arguments.length === 1 ) {\n\t\t\t\t\treturn this.options[ key ] === undefined ? null : this.options[ key ];\n\t\t\t\t}\n\t\t\t\toptions[ key ] = value;\n\t\t\t}\n\t\t}\n\n\t\tthis._setOptions( options );\n\n\t\treturn this;\n\t},\n\n\t_setOptions: function( options ) {\n\t\tvar key;\n\n\t\tfor ( key in options ) {\n\t\t\tthis._setOption( key, options[ key ] );\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tif ( key === \"classes\" ) {\n\t\t\tthis._setOptionClasses( value );\n\t\t}\n\n\t\tthis.options[ key ] = value;\n\n\t\tif ( key === \"disabled\" ) {\n\t\t\tthis._setOptionDisabled( value );\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t_setOptionClasses: function( value ) {\n\t\tvar classKey, elements, currentElements;\n\n\t\tfor ( classKey in value ) {\n\t\t\tcurrentElements = this.classesElementLookup[ classKey ];\n\t\t\tif ( value[ classKey ] === this.options.classes[ classKey ] ||\n\t\t\t\t\t!currentElements ||\n\t\t\t\t\t!currentElements.length ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// We are doing this to create a new jQuery object because the _removeClass() call\n\t\t\t// on the next line is going to destroy the reference to the current elements being\n\t\t\t// tracked. We need to save a copy of this collection so that we can add the new classes\n\t\t\t// below.\n\t\t\telements = $( currentElements.get() );\n\t\t\tthis._removeClass( currentElements, classKey );\n\n\t\t\t// We don't use _addClass() here, because that uses this.options.classes\n\t\t\t// for generating the string of classes. We want to use the value passed in from\n\t\t\t// _setOption(), this is the new value of the classes option which was passed to\n\t\t\t// _setOption(). We pass this value directly to _classes().\n\t\t\telements.addClass( this._classes( {\n\t\t\t\telement: elements,\n\t\t\t\tkeys: classKey,\n\t\t\t\tclasses: value,\n\t\t\t\tadd: true\n\t\t\t} ) );\n\t\t}\n\t},\n\n\t_setOptionDisabled: function( value ) {\n\t\tthis._toggleClass( this.widget(), this.widgetFullName + \"-disabled\", null, !!value );\n\n\t\t// If the widget is becoming disabled, then nothing is interactive\n\t\tif ( value ) {\n\t\t\tthis._removeClass( this.hoverable, null, \"ui-state-hover\" );\n\t\t\tthis._removeClass( this.focusable, null, \"ui-state-focus\" );\n\t\t}\n\t},\n\n\tenable: function() {\n\t\treturn this._setOptions( { disabled: false } );\n\t},\n\n\tdisable: function() {\n\t\treturn this._setOptions( { disabled: true } );\n\t},\n\n\t_classes: function( options ) {\n\t\tvar full = [];\n\t\tvar that = this;\n\n\t\toptions = $.extend( {\n\t\t\telement: this.element,\n\t\t\tclasses: this.options.classes || {}\n\t\t}, options );\n\n\t\tfunction processClassString( classes, checkOption ) {\n\t\t\tvar current, i;\n\t\t\tfor ( i = 0; i < classes.length; i++ ) {\n\t\t\t\tcurrent = that.classesElementLookup[ classes[ i ] ] || $();\n\t\t\t\tif ( options.add ) {\n\t\t\t\t\tcurrent = $( $.unique( current.get().concat( options.element.get() ) ) );\n\t\t\t\t} else {\n\t\t\t\t\tcurrent = $( current.not( options.element ).get() );\n\t\t\t\t}\n\t\t\t\tthat.classesElementLookup[ classes[ i ] ] = current;\n\t\t\t\tfull.push( classes[ i ] );\n\t\t\t\tif ( checkOption && options.classes[ classes[ i ] ] ) {\n\t\t\t\t\tfull.push( options.classes[ classes[ i ] ] );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis._on( options.element, {\n\t\t\t\"remove\": \"_untrackClassesElement\"\n\t\t} );\n\n\t\tif ( options.keys ) {\n\t\t\tprocessClassString( options.keys.match( /\\S+/g ) || [], true );\n\t\t}\n\t\tif ( options.extra ) {\n\t\t\tprocessClassString( options.extra.match( /\\S+/g ) || [] );\n\t\t}\n\n\t\treturn full.join( \" \" );\n\t},\n\n\t_untrackClassesElement: function( event ) {\n\t\tvar that = this;\n\t\t$.each( that.classesElementLookup, function( key, value ) {\n\t\t\tif ( $.inArray( event.target, value ) !== -1 ) {\n\t\t\t\tthat.classesElementLookup[ key ] = $( value.not( event.target ).get() );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_removeClass: function( element, keys, extra ) {\n\t\treturn this._toggleClass( element, keys, extra, false );\n\t},\n\n\t_addClass: function( element, keys, extra ) {\n\t\treturn this._toggleClass( element, keys, extra, true );\n\t},\n\n\t_toggleClass: function( element, keys, extra, add ) {\n\t\tadd = ( typeof add === \"boolean\" ) ? add : extra;\n\t\tvar shift = ( typeof element === \"string\" || element === null ),\n\t\t\toptions = {\n\t\t\t\textra: shift ? keys : extra,\n\t\t\t\tkeys: shift ? element : keys,\n\t\t\t\telement: shift ? this.element : element,\n\t\t\t\tadd: add\n\t\t\t};\n\t\toptions.element.toggleClass( this._classes( options ), add );\n\t\treturn this;\n\t},\n\n\t_on: function( suppressDisabledCheck, element, handlers ) {\n\t\tvar delegateElement;\n\t\tvar instance = this;\n\n\t\t// No suppressDisabledCheck flag, shuffle arguments\n\t\tif ( typeof suppressDisabledCheck !== \"boolean\" ) {\n\t\t\thandlers = element;\n\t\t\telement = suppressDisabledCheck;\n\t\t\tsuppressDisabledCheck = false;\n\t\t}\n\n\t\t// No element argument, shuffle and use this.element\n\t\tif ( !handlers ) {\n\t\t\thandlers = element;\n\t\t\telement = this.element;\n\t\t\tdelegateElement = this.widget();\n\t\t} else {\n\t\t\telement = delegateElement = $( element );\n\t\t\tthis.bindings = this.bindings.add( element );\n\t\t}\n\n\t\t$.each( handlers, function( event, handler ) {\n\t\t\tfunction handlerProxy() {\n\n\t\t\t\t// Allow widgets to customize the disabled handling\n\t\t\t\t// - disabled as an array instead of boolean\n\t\t\t\t// - disabled class as method for disabling individual parts\n\t\t\t\tif ( !suppressDisabledCheck &&\n\t\t\t\t\t\t( instance.options.disabled === true ||\n\t\t\t\t\t\t$( this ).hasClass( \"ui-state-disabled\" ) ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\treturn ( typeof handler === \"string\" ? instance[ handler ] : handler )\n\t\t\t\t\t.apply( instance, arguments );\n\t\t\t}\n\n\t\t\t// Copy the guid so direct unbinding works\n\t\t\tif ( typeof handler !== \"string\" ) {\n\t\t\t\thandlerProxy.guid = handler.guid =\n\t\t\t\t\thandler.guid || handlerProxy.guid || $.guid++;\n\t\t\t}\n\n\t\t\tvar match = event.match( /^([\\w:-]*)\\s*(.*)$/ );\n\t\t\tvar eventName = match[ 1 ] + instance.eventNamespace;\n\t\t\tvar selector = match[ 2 ];\n\n\t\t\tif ( selector ) {\n\t\t\t\tdelegateElement.on( eventName, selector, handlerProxy );\n\t\t\t} else {\n\t\t\t\telement.on( eventName, handlerProxy );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_off: function( element, eventName ) {\n\t\teventName = ( eventName || \"\" ).split( \" \" ).join( this.eventNamespace + \" \" ) +\n\t\t\tthis.eventNamespace;\n\t\telement.off( eventName ).off( eventName );\n\n\t\t// Clear the stack to avoid memory leaks (#10056)\n\t\tthis.bindings = $( this.bindings.not( element ).get() );\n\t\tthis.focusable = $( this.focusable.not( element ).get() );\n\t\tthis.hoverable = $( this.hoverable.not( element ).get() );\n\t},\n\n\t_delay: function( handler, delay ) {\n\t\tfunction handlerProxy() {\n\t\t\treturn ( typeof handler === \"string\" ? instance[ handler ] : handler )\n\t\t\t\t.apply( instance, arguments );\n\t\t}\n\t\tvar instance = this;\n\t\treturn setTimeout( handlerProxy, delay || 0 );\n\t},\n\n\t_hoverable: function( element ) {\n\t\tthis.hoverable = this.hoverable.add( element );\n\t\tthis._on( element, {\n\t\t\tmouseenter: function( event ) {\n\t\t\t\tthis._addClass( $( event.currentTarget ), null, \"ui-state-hover\" );\n\t\t\t},\n\t\t\tmouseleave: function( event ) {\n\t\t\t\tthis._removeClass( $( event.currentTarget ), null, \"ui-state-hover\" );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_focusable: function( element ) {\n\t\tthis.focusable = this.focusable.add( element );\n\t\tthis._on( element, {\n\t\t\tfocusin: function( event ) {\n\t\t\t\tthis._addClass( $( event.currentTarget ), null, \"ui-state-focus\" );\n\t\t\t},\n\t\t\tfocusout: function( event ) {\n\t\t\t\tthis._removeClass( $( event.currentTarget ), null, \"ui-state-focus\" );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_trigger: function( type, event, data ) {\n\t\tvar prop, orig;\n\t\tvar callback = this.options[ type ];\n\n\t\tdata = data || {};\n\t\tevent = $.Event( event );\n\t\tevent.type = ( type === this.widgetEventPrefix ?\n\t\t\ttype :\n\t\t\tthis.widgetEventPrefix + type ).toLowerCase();\n\n\t\t// The original event may come from any element\n\t\t// so we need to reset the target on the new event\n\t\tevent.target = this.element[ 0 ];\n\n\t\t// Copy original event properties over to the new event\n\t\torig = event.originalEvent;\n\t\tif ( orig ) {\n\t\t\tfor ( prop in orig ) {\n\t\t\t\tif ( !( prop in event ) ) {\n\t\t\t\t\tevent[ prop ] = orig[ prop ];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.element.trigger( event, data );\n\t\treturn !( $.isFunction( callback ) &&\n\t\t\tcallback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||\n\t\t\tevent.isDefaultPrevented() );\n\t}\n};\n\n$.each( { show: \"fadeIn\", hide: \"fadeOut\" }, function( method, defaultEffect ) {\n\t$.Widget.prototype[ \"_\" + method ] = function( element, options, callback ) {\n\t\tif ( typeof options === \"string\" ) {\n\t\t\toptions = { effect: options };\n\t\t}\n\n\t\tvar hasOptions;\n\t\tvar effectName = !options ?\n\t\t\tmethod :\n\t\t\toptions === true || typeof options === \"number\" ?\n\t\t\t\tdefaultEffect :\n\t\t\t\toptions.effect || defaultEffect;\n\n\t\toptions = options || {};\n\t\tif ( typeof options === \"number\" ) {\n\t\t\toptions = { duration: options };\n\t\t}\n\n\t\thasOptions = !$.isEmptyObject( options );\n\t\toptions.complete = callback;\n\n\t\tif ( options.delay ) {\n\t\t\telement.delay( options.delay );\n\t\t}\n\n\t\tif ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {\n\t\t\telement[ method ]( options );\n\t\t} else if ( effectName !== method && element[ effectName ] ) {\n\t\t\telement[ effectName ]( options.duration, options.easing, callback );\n\t\t} else {\n\t\t\telement.queue( function( next ) {\n\t\t\t\t$( this )[ method ]();\n\t\t\t\tif ( callback ) {\n\t\t\t\t\tcallback.call( element[ 0 ] );\n\t\t\t\t}\n\t\t\t\tnext();\n\t\t\t} );\n\t\t}\n\t};\n} );\n\nvar widget = $.widget;\n\n\n/*!\n * jQuery UI Position 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n *\n * http://api.jqueryui.com/position/\n */\n\n//>>label: Position\n//>>group: Core\n//>>description: Positions elements relative to other elements.\n//>>docs: http://api.jqueryui.com/position/\n//>>demos: http://jqueryui.com/position/\n\n\n( function() {\nvar cachedScrollbarWidth,\n\tmax = Math.max,\n\tabs = Math.abs,\n\trhorizontal = /left|center|right/,\n\trvertical = /top|center|bottom/,\n\troffset = /[\\+\\-]\\d+(\\.[\\d]+)?%?/,\n\trposition = /^\\w+/,\n\trpercent = /%$/,\n\t_position = $.fn.position;\n\nfunction getOffsets( offsets, width, height ) {\n\treturn [\n\t\tparseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),\n\t\tparseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )\n\t];\n}\n\nfunction parseCss( element, property ) {\n\treturn parseInt( $.css( element, property ), 10 ) || 0;\n}\n\nfunction getDimensions( elem ) {\n\tvar raw = elem[ 0 ];\n\tif ( raw.nodeType === 9 ) {\n\t\treturn {\n\t\t\twidth: elem.width(),\n\t\t\theight: elem.height(),\n\t\t\toffset: { top: 0, left: 0 }\n\t\t};\n\t}\n\tif ( $.isWindow( raw ) ) {\n\t\treturn {\n\t\t\twidth: elem.width(),\n\t\t\theight: elem.height(),\n\t\t\toffset: { top: elem.scrollTop(), left: elem.scrollLeft() }\n\t\t};\n\t}\n\tif ( raw.preventDefault ) {\n\t\treturn {\n\t\t\twidth: 0,\n\t\t\theight: 0,\n\t\t\toffset: { top: raw.pageY, left: raw.pageX }\n\t\t};\n\t}\n\treturn {\n\t\twidth: elem.outerWidth(),\n\t\theight: elem.outerHeight(),\n\t\toffset: elem.offset()\n\t};\n}\n\n$.position = {\n\tscrollbarWidth: function() {\n\t\tif ( cachedScrollbarWidth !== undefined ) {\n\t\t\treturn cachedScrollbarWidth;\n\t\t}\n\t\tvar w1, w2,\n\t\t\tdiv = $( \"<div \" +\n\t\t\t\t\"style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'>\" +\n\t\t\t\t\"<div style='height:100px;width:auto;'></div></div>\" ),\n\t\t\tinnerDiv = div.children()[ 0 ];\n\n\t\t$( \"body\" ).append( div );\n\t\tw1 = innerDiv.offsetWidth;\n\t\tdiv.css( \"overflow\", \"scroll\" );\n\n\t\tw2 = innerDiv.offsetWidth;\n\n\t\tif ( w1 === w2 ) {\n\t\t\tw2 = div[ 0 ].clientWidth;\n\t\t}\n\n\t\tdiv.remove();\n\n\t\treturn ( cachedScrollbarWidth = w1 - w2 );\n\t},\n\tgetScrollInfo: function( within ) {\n\t\tvar overflowX = within.isWindow || within.isDocument ? \"\" :\n\t\t\t\twithin.element.css( \"overflow-x\" ),\n\t\t\toverflowY = within.isWindow || within.isDocument ? \"\" :\n\t\t\t\twithin.element.css( \"overflow-y\" ),\n\t\t\thasOverflowX = overflowX === \"scroll\" ||\n\t\t\t\t( overflowX === \"auto\" && within.width < within.element[ 0 ].scrollWidth ),\n\t\t\thasOverflowY = overflowY === \"scroll\" ||\n\t\t\t\t( overflowY === \"auto\" && within.height < within.element[ 0 ].scrollHeight );\n\t\treturn {\n\t\t\twidth: hasOverflowY ? $.position.scrollbarWidth() : 0,\n\t\t\theight: hasOverflowX ? $.position.scrollbarWidth() : 0\n\t\t};\n\t},\n\tgetWithinInfo: function( element ) {\n\t\tvar withinElement = $( element || window ),\n\t\t\tisWindow = $.isWindow( withinElement[ 0 ] ),\n\t\t\tisDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,\n\t\t\thasOffset = !isWindow && !isDocument;\n\t\treturn {\n\t\t\telement: withinElement,\n\t\t\tisWindow: isWindow,\n\t\t\tisDocument: isDocument,\n\t\t\toffset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },\n\t\t\tscrollLeft: withinElement.scrollLeft(),\n\t\t\tscrollTop: withinElement.scrollTop(),\n\t\t\twidth: withinElement.outerWidth(),\n\t\t\theight: withinElement.outerHeight()\n\t\t};\n\t}\n};\n\n$.fn.position = function( options ) {\n\tif ( !options || !options.of ) {\n\t\treturn _position.apply( this, arguments );\n\t}\n\n\t// Make a copy, we don't want to modify arguments\n\toptions = $.extend( {}, options );\n\n\tvar atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,\n\t\ttarget = $( options.of ),\n\t\twithin = $.position.getWithinInfo( options.within ),\n\t\tscrollInfo = $.position.getScrollInfo( within ),\n\t\tcollision = ( options.collision || \"flip\" ).split( \" \" ),\n\t\toffsets = {};\n\n\tdimensions = getDimensions( target );\n\tif ( target[ 0 ].preventDefault ) {\n\n\t\t// Force left top to allow flipping\n\t\toptions.at = \"left top\";\n\t}\n\ttargetWidth = dimensions.width;\n\ttargetHeight = dimensions.height;\n\ttargetOffset = dimensions.offset;\n\n\t// Clone to reuse original targetOffset later\n\tbasePosition = $.extend( {}, targetOffset );\n\n\t// Force my and at to have valid horizontal and vertical positions\n\t// if a value is missing or invalid, it will be converted to center\n\t$.each( [ \"my\", \"at\" ], function() {\n\t\tvar pos = ( options[ this ] || \"\" ).split( \" \" ),\n\t\t\thorizontalOffset,\n\t\t\tverticalOffset;\n\n\t\tif ( pos.length === 1 ) {\n\t\t\tpos = rhorizontal.test( pos[ 0 ] ) ?\n\t\t\t\tpos.concat( [ \"center\" ] ) :\n\t\t\t\trvertical.test( pos[ 0 ] ) ?\n\t\t\t\t\t[ \"center\" ].concat( pos ) :\n\t\t\t\t\t[ \"center\", \"center\" ];\n\t\t}\n\t\tpos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : \"center\";\n\t\tpos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : \"center\";\n\n\t\t// Calculate offsets\n\t\thorizontalOffset = roffset.exec( pos[ 0 ] );\n\t\tverticalOffset = roffset.exec( pos[ 1 ] );\n\t\toffsets[ this ] = [\n\t\t\thorizontalOffset ? horizontalOffset[ 0 ] : 0,\n\t\t\tverticalOffset ? verticalOffset[ 0 ] : 0\n\t\t];\n\n\t\t// Reduce to just the positions without the offsets\n\t\toptions[ this ] = [\n\t\t\trposition.exec( pos[ 0 ] )[ 0 ],\n\t\t\trposition.exec( pos[ 1 ] )[ 0 ]\n\t\t];\n\t} );\n\n\t// Normalize collision option\n\tif ( collision.length === 1 ) {\n\t\tcollision[ 1 ] = collision[ 0 ];\n\t}\n\n\tif ( options.at[ 0 ] === \"right\" ) {\n\t\tbasePosition.left += targetWidth;\n\t} else if ( options.at[ 0 ] === \"center\" ) {\n\t\tbasePosition.left += targetWidth / 2;\n\t}\n\n\tif ( options.at[ 1 ] === \"bottom\" ) {\n\t\tbasePosition.top += targetHeight;\n\t} else if ( options.at[ 1 ] === \"center\" ) {\n\t\tbasePosition.top += targetHeight / 2;\n\t}\n\n\tatOffset = getOffsets( offsets.at, targetWidth, targetHeight );\n\tbasePosition.left += atOffset[ 0 ];\n\tbasePosition.top += atOffset[ 1 ];\n\n\treturn this.each( function() {\n\t\tvar collisionPosition, using,\n\t\t\telem = $( this ),\n\t\t\telemWidth = elem.outerWidth(),\n\t\t\telemHeight = elem.outerHeight(),\n\t\t\tmarginLeft = parseCss( this, \"marginLeft\" ),\n\t\t\tmarginTop = parseCss( this, \"marginTop\" ),\n\t\t\tcollisionWidth = elemWidth + marginLeft + parseCss( this, \"marginRight\" ) +\n\t\t\t\tscrollInfo.width,\n\t\t\tcollisionHeight = elemHeight + marginTop + parseCss( this, \"marginBottom\" ) +\n\t\t\t\tscrollInfo.height,\n\t\t\tposition = $.extend( {}, basePosition ),\n\t\t\tmyOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );\n\n\t\tif ( options.my[ 0 ] === \"right\" ) {\n\t\t\tposition.left -= elemWidth;\n\t\t} else if ( options.my[ 0 ] === \"center\" ) {\n\t\t\tposition.left -= elemWidth / 2;\n\t\t}\n\n\t\tif ( options.my[ 1 ] === \"bottom\" ) {\n\t\t\tposition.top -= elemHeight;\n\t\t} else if ( options.my[ 1 ] === \"center\" ) {\n\t\t\tposition.top -= elemHeight / 2;\n\t\t}\n\n\t\tposition.left += myOffset[ 0 ];\n\t\tposition.top += myOffset[ 1 ];\n\n\t\tcollisionPosition = {\n\t\t\tmarginLeft: marginLeft,\n\t\t\tmarginTop: marginTop\n\t\t};\n\n\t\t$.each( [ \"left\", \"top\" ], function( i, dir ) {\n\t\t\tif ( $.ui.position[ collision[ i ] ] ) {\n\t\t\t\t$.ui.position[ collision[ i ] ][ dir ]( position, {\n\t\t\t\t\ttargetWidth: targetWidth,\n\t\t\t\t\ttargetHeight: targetHeight,\n\t\t\t\t\telemWidth: elemWidth,\n\t\t\t\t\telemHeight: elemHeight,\n\t\t\t\t\tcollisionPosition: collisionPosition,\n\t\t\t\t\tcollisionWidth: collisionWidth,\n\t\t\t\t\tcollisionHeight: collisionHeight,\n\t\t\t\t\toffset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],\n\t\t\t\t\tmy: options.my,\n\t\t\t\t\tat: options.at,\n\t\t\t\t\twithin: within,\n\t\t\t\t\telem: elem\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\n\t\tif ( options.using ) {\n\n\t\t\t// Adds feedback as second argument to using callback, if present\n\t\t\tusing = function( props ) {\n\t\t\t\tvar left = targetOffset.left - position.left,\n\t\t\t\t\tright = left + targetWidth - elemWidth,\n\t\t\t\t\ttop = targetOffset.top - position.top,\n\t\t\t\t\tbottom = top + targetHeight - elemHeight,\n\t\t\t\t\tfeedback = {\n\t\t\t\t\t\ttarget: {\n\t\t\t\t\t\t\telement: target,\n\t\t\t\t\t\t\tleft: targetOffset.left,\n\t\t\t\t\t\t\ttop: targetOffset.top,\n\t\t\t\t\t\t\twidth: targetWidth,\n\t\t\t\t\t\t\theight: targetHeight\n\t\t\t\t\t\t},\n\t\t\t\t\t\telement: {\n\t\t\t\t\t\t\telement: elem,\n\t\t\t\t\t\t\tleft: position.left,\n\t\t\t\t\t\t\ttop: position.top,\n\t\t\t\t\t\t\twidth: elemWidth,\n\t\t\t\t\t\t\theight: elemHeight\n\t\t\t\t\t\t},\n\t\t\t\t\t\thorizontal: right < 0 ? \"left\" : left > 0 ? \"right\" : \"center\",\n\t\t\t\t\t\tvertical: bottom < 0 ? \"top\" : top > 0 ? \"bottom\" : \"middle\"\n\t\t\t\t\t};\n\t\t\t\tif ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {\n\t\t\t\t\tfeedback.horizontal = \"center\";\n\t\t\t\t}\n\t\t\t\tif ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {\n\t\t\t\t\tfeedback.vertical = \"middle\";\n\t\t\t\t}\n\t\t\t\tif ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {\n\t\t\t\t\tfeedback.important = \"horizontal\";\n\t\t\t\t} else {\n\t\t\t\t\tfeedback.important = \"vertical\";\n\t\t\t\t}\n\t\t\t\toptions.using.call( this, props, feedback );\n\t\t\t};\n\t\t}\n\n\t\telem.offset( $.extend( position, { using: using } ) );\n\t} );\n};\n\n$.ui.position = {\n\tfit: {\n\t\tleft: function( position, data ) {\n\t\t\tvar within = data.within,\n\t\t\t\twithinOffset = within.isWindow ? within.scrollLeft : within.offset.left,\n\t\t\t\touterWidth = within.width,\n\t\t\t\tcollisionPosLeft = position.left - data.collisionPosition.marginLeft,\n\t\t\t\toverLeft = withinOffset - collisionPosLeft,\n\t\t\t\toverRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,\n\t\t\t\tnewOverRight;\n\n\t\t\t// Element is wider than within\n\t\t\tif ( data.collisionWidth > outerWidth ) {\n\n\t\t\t\t// Element is initially over the left side of within\n\t\t\t\tif ( overLeft > 0 && overRight <= 0 ) {\n\t\t\t\t\tnewOverRight = position.left + overLeft + data.collisionWidth - outerWidth -\n\t\t\t\t\t\twithinOffset;\n\t\t\t\t\tposition.left += overLeft - newOverRight;\n\n\t\t\t\t// Element is initially over right side of within\n\t\t\t\t} else if ( overRight > 0 && overLeft <= 0 ) {\n\t\t\t\t\tposition.left = withinOffset;\n\n\t\t\t\t// Element is initially over both left and right sides of within\n\t\t\t\t} else {\n\t\t\t\t\tif ( overLeft > overRight ) {\n\t\t\t\t\t\tposition.left = withinOffset + outerWidth - data.collisionWidth;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tposition.left = withinOffset;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t// Too far left -> align with left edge\n\t\t\t} else if ( overLeft > 0 ) {\n\t\t\t\tposition.left += overLeft;\n\n\t\t\t// Too far right -> align with right edge\n\t\t\t} else if ( overRight > 0 ) {\n\t\t\t\tposition.left -= overRight;\n\n\t\t\t// Adjust based on position and margin\n\t\t\t} else {\n\t\t\t\tposition.left = max( position.left - collisionPosLeft, position.left );\n\t\t\t}\n\t\t},\n\t\ttop: function( position, data ) {\n\t\t\tvar within = data.within,\n\t\t\t\twithinOffset = within.isWindow ? within.scrollTop : within.offset.top,\n\t\t\t\touterHeight = data.within.height,\n\t\t\t\tcollisionPosTop = position.top - data.collisionPosition.marginTop,\n\t\t\t\toverTop = withinOffset - collisionPosTop,\n\t\t\t\toverBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,\n\t\t\t\tnewOverBottom;\n\n\t\t\t// Element is taller than within\n\t\t\tif ( data.collisionHeight > outerHeight ) {\n\n\t\t\t\t// Element is initially over the top of within\n\t\t\t\tif ( overTop > 0 && overBottom <= 0 ) {\n\t\t\t\t\tnewOverBottom = position.top + overTop + data.collisionHeight - outerHeight -\n\t\t\t\t\t\twithinOffset;\n\t\t\t\t\tposition.top += overTop - newOverBottom;\n\n\t\t\t\t// Element is initially over bottom of within\n\t\t\t\t} else if ( overBottom > 0 && overTop <= 0 ) {\n\t\t\t\t\tposition.top = withinOffset;\n\n\t\t\t\t// Element is initially over both top and bottom of within\n\t\t\t\t} else {\n\t\t\t\t\tif ( overTop > overBottom ) {\n\t\t\t\t\t\tposition.top = withinOffset + outerHeight - data.collisionHeight;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tposition.top = withinOffset;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t// Too far up -> align with top\n\t\t\t} else if ( overTop > 0 ) {\n\t\t\t\tposition.top += overTop;\n\n\t\t\t// Too far down -> align with bottom edge\n\t\t\t} else if ( overBottom > 0 ) {\n\t\t\t\tposition.top -= overBottom;\n\n\t\t\t// Adjust based on position and margin\n\t\t\t} else {\n\t\t\t\tposition.top = max( position.top - collisionPosTop, position.top );\n\t\t\t}\n\t\t}\n\t},\n\tflip: {\n\t\tleft: function( position, data ) {\n\t\t\tvar within = data.within,\n\t\t\t\twithinOffset = within.offset.left + within.scrollLeft,\n\t\t\t\touterWidth = within.width,\n\t\t\t\toffsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,\n\t\t\t\tcollisionPosLeft = position.left - data.collisionPosition.marginLeft,\n\t\t\t\toverLeft = collisionPosLeft - offsetLeft,\n\t\t\t\toverRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,\n\t\t\t\tmyOffset = data.my[ 0 ] === \"left\" ?\n\t\t\t\t\t-data.elemWidth :\n\t\t\t\t\tdata.my[ 0 ] === \"right\" ?\n\t\t\t\t\t\tdata.elemWidth :\n\t\t\t\t\t\t0,\n\t\t\t\tatOffset = data.at[ 0 ] === \"left\" ?\n\t\t\t\t\tdata.targetWidth :\n\t\t\t\t\tdata.at[ 0 ] === \"right\" ?\n\t\t\t\t\t\t-data.targetWidth :\n\t\t\t\t\t\t0,\n\t\t\t\toffset = -2 * data.offset[ 0 ],\n\t\t\t\tnewOverRight,\n\t\t\t\tnewOverLeft;\n\n\t\t\tif ( overLeft < 0 ) {\n\t\t\t\tnewOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth -\n\t\t\t\t\touterWidth - withinOffset;\n\t\t\t\tif ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {\n\t\t\t\t\tposition.left += myOffset + atOffset + offset;\n\t\t\t\t}\n\t\t\t} else if ( overRight > 0 ) {\n\t\t\t\tnewOverLeft = position.left - data.collisionPosition.marginLeft + myOffset +\n\t\t\t\t\tatOffset + offset - offsetLeft;\n\t\t\t\tif ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {\n\t\t\t\t\tposition.left += myOffset + atOffset + offset;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\ttop: function( position, data ) {\n\t\t\tvar within = data.within,\n\t\t\t\twithinOffset = within.offset.top + within.scrollTop,\n\t\t\t\touterHeight = within.height,\n\t\t\t\toffsetTop = within.isWindow ? within.scrollTop : within.offset.top,\n\t\t\t\tcollisionPosTop = position.top - data.collisionPosition.marginTop,\n\t\t\t\toverTop = collisionPosTop - offsetTop,\n\t\t\t\toverBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,\n\t\t\t\ttop = data.my[ 1 ] === \"top\",\n\t\t\t\tmyOffset = top ?\n\t\t\t\t\t-data.elemHeight :\n\t\t\t\t\tdata.my[ 1 ] === \"bottom\" ?\n\t\t\t\t\t\tdata.elemHeight :\n\t\t\t\t\t\t0,\n\t\t\t\tatOffset = data.at[ 1 ] === \"top\" ?\n\t\t\t\t\tdata.targetHeight :\n\t\t\t\t\tdata.at[ 1 ] === \"bottom\" ?\n\t\t\t\t\t\t-data.targetHeight :\n\t\t\t\t\t\t0,\n\t\t\t\toffset = -2 * data.offset[ 1 ],\n\t\t\t\tnewOverTop,\n\t\t\t\tnewOverBottom;\n\t\t\tif ( overTop < 0 ) {\n\t\t\t\tnewOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight -\n\t\t\t\t\touterHeight - withinOffset;\n\t\t\t\tif ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {\n\t\t\t\t\tposition.top += myOffset + atOffset + offset;\n\t\t\t\t}\n\t\t\t} else if ( overBottom > 0 ) {\n\t\t\t\tnewOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset +\n\t\t\t\t\toffset - offsetTop;\n\t\t\t\tif ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {\n\t\t\t\t\tposition.top += myOffset + atOffset + offset;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\tflipfit: {\n\t\tleft: function() {\n\t\t\t$.ui.position.flip.left.apply( this, arguments );\n\t\t\t$.ui.position.fit.left.apply( this, arguments );\n\t\t},\n\t\ttop: function() {\n\t\t\t$.ui.position.flip.top.apply( this, arguments );\n\t\t\t$.ui.position.fit.top.apply( this, arguments );\n\t\t}\n\t}\n};\n\n} )();\n\nvar position = $.ui.position;\n\n\n/*!\n * jQuery UI :data 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: :data Selector\n//>>group: Core\n//>>description: Selects elements which have data stored under the specified key.\n//>>docs: http://api.jqueryui.com/data-selector/\n\n\nvar data = $.extend( $.expr[ \":\" ], {\n\tdata: $.expr.createPseudo ?\n\t\t$.expr.createPseudo( function( dataName ) {\n\t\t\treturn function( elem ) {\n\t\t\t\treturn !!$.data( elem, dataName );\n\t\t\t};\n\t\t} ) :\n\n\t\t// Support: jQuery <1.8\n\t\tfunction( elem, i, match ) {\n\t\t\treturn !!$.data( elem, match[ 3 ] );\n\t\t}\n} );\n\n/*!\n * jQuery UI Disable Selection 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: disableSelection\n//>>group: Core\n//>>description: Disable selection of text content within the set of matched elements.\n//>>docs: http://api.jqueryui.com/disableSelection/\n\n// This file is deprecated\n\n\nvar disableSelection = $.fn.extend( {\n\tdisableSelection: ( function() {\n\t\tvar eventType = \"onselectstart\" in document.createElement( \"div\" ) ?\n\t\t\t\"selectstart\" :\n\t\t\t\"mousedown\";\n\n\t\treturn function() {\n\t\t\treturn this.on( eventType + \".ui-disableSelection\", function( event ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t} );\n\t\t};\n\t} )(),\n\n\tenableSelection: function() {\n\t\treturn this.off( \".ui-disableSelection\" );\n\t}\n} );\n\n\n/*!\n * jQuery UI Effects 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Effects Core\n//>>group: Effects\n// jscs:disable maximumLineLength\n//>>description: Extends the internal jQuery effects. Includes morphing and easing. Required by all other effects.\n// jscs:enable maximumLineLength\n//>>docs: http://api.jqueryui.com/category/effects-core/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar dataSpace = \"ui-effects-\",\n\tdataSpaceStyle = \"ui-effects-style\",\n\tdataSpaceAnimated = \"ui-effects-animated\",\n\n\t// Create a local jQuery because jQuery Color relies on it and the\n\t// global may not exist with AMD and a custom build (#10199)\n\tjQuery = $;\n\n$.effects = {\n\teffect: {}\n};\n\n/*!\n * jQuery Color Animations v2.1.2\n * https://github.com/jquery/jquery-color\n *\n * Copyright 2014 jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n *\n * Date: Wed Jan 16 08:47:09 2013 -0600\n */\n( function( jQuery, undefined ) {\n\n\tvar stepHooks = \"backgroundColor borderBottomColor borderLeftColor borderRightColor \" +\n\t\t\"borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor\",\n\n\t// Plusequals test for += 100 -= 100\n\trplusequals = /^([\\-+])=\\s*(\\d+\\.?\\d*)/,\n\n\t// A set of RE's that can match strings and generate color tuples.\n\tstringParsers = [ {\n\t\t\tre: /rgba?\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*(?:,\\s*(\\d?(?:\\.\\d+)?)\\s*)?\\)/,\n\t\t\tparse: function( execResult ) {\n\t\t\t\treturn [\n\t\t\t\t\texecResult[ 1 ],\n\t\t\t\t\texecResult[ 2 ],\n\t\t\t\t\texecResult[ 3 ],\n\t\t\t\t\texecResult[ 4 ]\n\t\t\t\t];\n\t\t\t}\n\t\t}, {\n\t\t\tre: /rgba?\\(\\s*(\\d+(?:\\.\\d+)?)\\%\\s*,\\s*(\\d+(?:\\.\\d+)?)\\%\\s*,\\s*(\\d+(?:\\.\\d+)?)\\%\\s*(?:,\\s*(\\d?(?:\\.\\d+)?)\\s*)?\\)/,\n\t\t\tparse: function( execResult ) {\n\t\t\t\treturn [\n\t\t\t\t\texecResult[ 1 ] * 2.55,\n\t\t\t\t\texecResult[ 2 ] * 2.55,\n\t\t\t\t\texecResult[ 3 ] * 2.55,\n\t\t\t\t\texecResult[ 4 ]\n\t\t\t\t];\n\t\t\t}\n\t\t}, {\n\n\t\t\t// This regex ignores A-F because it's compared against an already lowercased string\n\t\t\tre: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,\n\t\t\tparse: function( execResult ) {\n\t\t\t\treturn [\n\t\t\t\t\tparseInt( execResult[ 1 ], 16 ),\n\t\t\t\t\tparseInt( execResult[ 2 ], 16 ),\n\t\t\t\t\tparseInt( execResult[ 3 ], 16 )\n\t\t\t\t];\n\t\t\t}\n\t\t}, {\n\n\t\t\t// This regex ignores A-F because it's compared against an already lowercased string\n\t\t\tre: /#([a-f0-9])([a-f0-9])([a-f0-9])/,\n\t\t\tparse: function( execResult ) {\n\t\t\t\treturn [\n\t\t\t\t\tparseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),\n\t\t\t\t\tparseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),\n\t\t\t\t\tparseInt( execResult[ 3 ] + execResult[ 3 ], 16 )\n\t\t\t\t];\n\t\t\t}\n\t\t}, {\n\t\t\tre: /hsla?\\(\\s*(\\d+(?:\\.\\d+)?)\\s*,\\s*(\\d+(?:\\.\\d+)?)\\%\\s*,\\s*(\\d+(?:\\.\\d+)?)\\%\\s*(?:,\\s*(\\d?(?:\\.\\d+)?)\\s*)?\\)/,\n\t\t\tspace: \"hsla\",\n\t\t\tparse: function( execResult ) {\n\t\t\t\treturn [\n\t\t\t\t\texecResult[ 1 ],\n\t\t\t\t\texecResult[ 2 ] / 100,\n\t\t\t\t\texecResult[ 3 ] / 100,\n\t\t\t\t\texecResult[ 4 ]\n\t\t\t\t];\n\t\t\t}\n\t\t} ],\n\n\t// JQuery.Color( )\n\tcolor = jQuery.Color = function( color, green, blue, alpha ) {\n\t\treturn new jQuery.Color.fn.parse( color, green, blue, alpha );\n\t},\n\tspaces = {\n\t\trgba: {\n\t\t\tprops: {\n\t\t\t\tred: {\n\t\t\t\t\tidx: 0,\n\t\t\t\t\ttype: \"byte\"\n\t\t\t\t},\n\t\t\t\tgreen: {\n\t\t\t\t\tidx: 1,\n\t\t\t\t\ttype: \"byte\"\n\t\t\t\t},\n\t\t\t\tblue: {\n\t\t\t\t\tidx: 2,\n\t\t\t\t\ttype: \"byte\"\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\thsla: {\n\t\t\tprops: {\n\t\t\t\thue: {\n\t\t\t\t\tidx: 0,\n\t\t\t\t\ttype: \"degrees\"\n\t\t\t\t},\n\t\t\t\tsaturation: {\n\t\t\t\t\tidx: 1,\n\t\t\t\t\ttype: \"percent\"\n\t\t\t\t},\n\t\t\t\tlightness: {\n\t\t\t\t\tidx: 2,\n\t\t\t\t\ttype: \"percent\"\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\tpropTypes = {\n\t\t\"byte\": {\n\t\t\tfloor: true,\n\t\t\tmax: 255\n\t\t},\n\t\t\"percent\": {\n\t\t\tmax: 1\n\t\t},\n\t\t\"degrees\": {\n\t\t\tmod: 360,\n\t\t\tfloor: true\n\t\t}\n\t},\n\tsupport = color.support = {},\n\n\t// Element for support tests\n\tsupportElem = jQuery( \"<p>\" )[ 0 ],\n\n\t// Colors = jQuery.Color.names\n\tcolors,\n\n\t// Local aliases of functions called often\n\teach = jQuery.each;\n\n// Determine rgba support immediately\nsupportElem.style.cssText = \"background-color:rgba(1,1,1,.5)\";\nsupport.rgba = supportElem.style.backgroundColor.indexOf( \"rgba\" ) > -1;\n\n// Define cache name and alpha properties\n// for rgba and hsla spaces\neach( spaces, function( spaceName, space ) {\n\tspace.cache = \"_\" + spaceName;\n\tspace.props.alpha = {\n\t\tidx: 3,\n\t\ttype: \"percent\",\n\t\tdef: 1\n\t};\n} );\n\nfunction clamp( value, prop, allowEmpty ) {\n\tvar type = propTypes[ prop.type ] || {};\n\n\tif ( value == null ) {\n\t\treturn ( allowEmpty || !prop.def ) ? null : prop.def;\n\t}\n\n\t// ~~ is an short way of doing floor for positive numbers\n\tvalue = type.floor ? ~~value : parseFloat( value );\n\n\t// IE will pass in empty strings as value for alpha,\n\t// which will hit this case\n\tif ( isNaN( value ) ) {\n\t\treturn prop.def;\n\t}\n\n\tif ( type.mod ) {\n\n\t\t// We add mod before modding to make sure that negatives values\n\t\t// get converted properly: -10 -> 350\n\t\treturn ( value + type.mod ) % type.mod;\n\t}\n\n\t// For now all property types without mod have min and max\n\treturn 0 > value ? 0 : type.max < value ? type.max : value;\n}\n\nfunction stringParse( string ) {\n\tvar inst = color(),\n\t\trgba = inst._rgba = [];\n\n\tstring = string.toLowerCase();\n\n\teach( stringParsers, function( i, parser ) {\n\t\tvar parsed,\n\t\t\tmatch = parser.re.exec( string ),\n\t\t\tvalues = match && parser.parse( match ),\n\t\t\tspaceName = parser.space || \"rgba\";\n\n\t\tif ( values ) {\n\t\t\tparsed = inst[ spaceName ]( values );\n\n\t\t\t// If this was an rgba parse the assignment might happen twice\n\t\t\t// oh well....\n\t\t\tinst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];\n\t\t\trgba = inst._rgba = parsed._rgba;\n\n\t\t\t// Exit each( stringParsers ) here because we matched\n\t\t\treturn false;\n\t\t}\n\t} );\n\n\t// Found a stringParser that handled it\n\tif ( rgba.length ) {\n\n\t\t// If this came from a parsed string, force \"transparent\" when alpha is 0\n\t\t// chrome, (and maybe others) return \"transparent\" as rgba(0,0,0,0)\n\t\tif ( rgba.join() === \"0,0,0,0\" ) {\n\t\t\tjQuery.extend( rgba, colors.transparent );\n\t\t}\n\t\treturn inst;\n\t}\n\n\t// Named colors\n\treturn colors[ string ];\n}\n\ncolor.fn = jQuery.extend( color.prototype, {\n\tparse: function( red, green, blue, alpha ) {\n\t\tif ( red === undefined ) {\n\t\t\tthis._rgba = [ null, null, null, null ];\n\t\t\treturn this;\n\t\t}\n\t\tif ( red.jquery || red.nodeType ) {\n\t\t\tred = jQuery( red ).css( green );\n\t\t\tgreen = undefined;\n\t\t}\n\n\t\tvar inst = this,\n\t\t\ttype = jQuery.type( red ),\n\t\t\trgba = this._rgba = [];\n\n\t\t// More than 1 argument specified - assume ( red, green, blue, alpha )\n\t\tif ( green !== undefined ) {\n\t\t\tred = [ red, green, blue, alpha ];\n\t\t\ttype = \"array\";\n\t\t}\n\n\t\tif ( type === \"string\" ) {\n\t\t\treturn this.parse( stringParse( red ) || colors._default );\n\t\t}\n\n\t\tif ( type === \"array\" ) {\n\t\t\teach( spaces.rgba.props, function( key, prop ) {\n\t\t\t\trgba[ prop.idx ] = clamp( red[ prop.idx ], prop );\n\t\t\t} );\n\t\t\treturn this;\n\t\t}\n\n\t\tif ( type === \"object\" ) {\n\t\t\tif ( red instanceof color ) {\n\t\t\t\teach( spaces, function( spaceName, space ) {\n\t\t\t\t\tif ( red[ space.cache ] ) {\n\t\t\t\t\t\tinst[ space.cache ] = red[ space.cache ].slice();\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\teach( spaces, function( spaceName, space ) {\n\t\t\t\t\tvar cache = space.cache;\n\t\t\t\t\teach( space.props, function( key, prop ) {\n\n\t\t\t\t\t\t// If the cache doesn't exist, and we know how to convert\n\t\t\t\t\t\tif ( !inst[ cache ] && space.to ) {\n\n\t\t\t\t\t\t\t// If the value was null, we don't need to copy it\n\t\t\t\t\t\t\t// if the key was alpha, we don't need to copy it either\n\t\t\t\t\t\t\tif ( key === \"alpha\" || red[ key ] == null ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tinst[ cache ] = space.to( inst._rgba );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// This is the only case where we allow nulls for ALL properties.\n\t\t\t\t\t\t// call clamp with alwaysAllowEmpty\n\t\t\t\t\t\tinst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );\n\t\t\t\t\t} );\n\n\t\t\t\t\t// Everything defined but alpha?\n\t\t\t\t\tif ( inst[ cache ] &&\n\t\t\t\t\t\t\tjQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {\n\n\t\t\t\t\t\t// Use the default of 1\n\t\t\t\t\t\tinst[ cache ][ 3 ] = 1;\n\t\t\t\t\t\tif ( space.from ) {\n\t\t\t\t\t\t\tinst._rgba = space.from( inst[ cache ] );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\t},\n\tis: function( compare ) {\n\t\tvar is = color( compare ),\n\t\t\tsame = true,\n\t\t\tinst = this;\n\n\t\teach( spaces, function( _, space ) {\n\t\t\tvar localCache,\n\t\t\t\tisCache = is[ space.cache ];\n\t\t\tif ( isCache ) {\n\t\t\t\tlocalCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];\n\t\t\t\teach( space.props, function( _, prop ) {\n\t\t\t\t\tif ( isCache[ prop.idx ] != null ) {\n\t\t\t\t\t\tsame = ( isCache[ prop.idx ] === localCache[ prop.idx ] );\n\t\t\t\t\t\treturn same;\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn same;\n\t\t} );\n\t\treturn same;\n\t},\n\t_space: function() {\n\t\tvar used = [],\n\t\t\tinst = this;\n\t\teach( spaces, function( spaceName, space ) {\n\t\t\tif ( inst[ space.cache ] ) {\n\t\t\t\tused.push( spaceName );\n\t\t\t}\n\t\t} );\n\t\treturn used.pop();\n\t},\n\ttransition: function( other, distance ) {\n\t\tvar end = color( other ),\n\t\t\tspaceName = end._space(),\n\t\t\tspace = spaces[ spaceName ],\n\t\t\tstartColor = this.alpha() === 0 ? color( \"transparent\" ) : this,\n\t\t\tstart = startColor[ space.cache ] || space.to( startColor._rgba ),\n\t\t\tresult = start.slice();\n\n\t\tend = end[ space.cache ];\n\t\teach( space.props, function( key, prop ) {\n\t\t\tvar index = prop.idx,\n\t\t\t\tstartValue = start[ index ],\n\t\t\t\tendValue = end[ index ],\n\t\t\t\ttype = propTypes[ prop.type ] || {};\n\n\t\t\t// If null, don't override start value\n\t\t\tif ( endValue === null ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If null - use end\n\t\t\tif ( startValue === null ) {\n\t\t\t\tresult[ index ] = endValue;\n\t\t\t} else {\n\t\t\t\tif ( type.mod ) {\n\t\t\t\t\tif ( endValue - startValue > type.mod / 2 ) {\n\t\t\t\t\t\tstartValue += type.mod;\n\t\t\t\t\t} else if ( startValue - endValue > type.mod / 2 ) {\n\t\t\t\t\t\tstartValue -= type.mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );\n\t\t\t}\n\t\t} );\n\t\treturn this[ spaceName ]( result );\n\t},\n\tblend: function( opaque ) {\n\n\t\t// If we are already opaque - return ourself\n\t\tif ( this._rgba[ 3 ] === 1 ) {\n\t\t\treturn this;\n\t\t}\n\n\t\tvar rgb = this._rgba.slice(),\n\t\t\ta = rgb.pop(),\n\t\t\tblend = color( opaque )._rgba;\n\n\t\treturn color( jQuery.map( rgb, function( v, i ) {\n\t\t\treturn ( 1 - a ) * blend[ i ] + a * v;\n\t\t} ) );\n\t},\n\ttoRgbaString: function() {\n\t\tvar prefix = \"rgba(\",\n\t\t\trgba = jQuery.map( this._rgba, function( v, i ) {\n\t\t\t\treturn v == null ? ( i > 2 ? 1 : 0 ) : v;\n\t\t\t} );\n\n\t\tif ( rgba[ 3 ] === 1 ) {\n\t\t\trgba.pop();\n\t\t\tprefix = \"rgb(\";\n\t\t}\n\n\t\treturn prefix + rgba.join() + \")\";\n\t},\n\ttoHslaString: function() {\n\t\tvar prefix = \"hsla(\",\n\t\t\thsla = jQuery.map( this.hsla(), function( v, i ) {\n\t\t\t\tif ( v == null ) {\n\t\t\t\t\tv = i > 2 ? 1 : 0;\n\t\t\t\t}\n\n\t\t\t\t// Catch 1 and 2\n\t\t\t\tif ( i && i < 3 ) {\n\t\t\t\t\tv = Math.round( v * 100 ) + \"%\";\n\t\t\t\t}\n\t\t\t\treturn v;\n\t\t\t} );\n\n\t\tif ( hsla[ 3 ] === 1 ) {\n\t\t\thsla.pop();\n\t\t\tprefix = \"hsl(\";\n\t\t}\n\t\treturn prefix + hsla.join() + \")\";\n\t},\n\ttoHexString: function( includeAlpha ) {\n\t\tvar rgba = this._rgba.slice(),\n\t\t\talpha = rgba.pop();\n\n\t\tif ( includeAlpha ) {\n\t\t\trgba.push( ~~( alpha * 255 ) );\n\t\t}\n\n\t\treturn \"#\" + jQuery.map( rgba, function( v ) {\n\n\t\t\t// Default to 0 when nulls exist\n\t\t\tv = ( v || 0 ).toString( 16 );\n\t\t\treturn v.length === 1 ? \"0\" + v : v;\n\t\t} ).join( \"\" );\n\t},\n\ttoString: function() {\n\t\treturn this._rgba[ 3 ] === 0 ? \"transparent\" : this.toRgbaString();\n\t}\n} );\ncolor.fn.parse.prototype = color.fn;\n\n// Hsla conversions adapted from:\n// https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021\n\nfunction hue2rgb( p, q, h ) {\n\th = ( h + 1 ) % 1;\n\tif ( h * 6 < 1 ) {\n\t\treturn p + ( q - p ) * h * 6;\n\t}\n\tif ( h * 2 < 1 ) {\n\t\treturn q;\n\t}\n\tif ( h * 3 < 2 ) {\n\t\treturn p + ( q - p ) * ( ( 2 / 3 ) - h ) * 6;\n\t}\n\treturn p;\n}\n\nspaces.hsla.to = function( rgba ) {\n\tif ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {\n\t\treturn [ null, null, null, rgba[ 3 ] ];\n\t}\n\tvar r = rgba[ 0 ] / 255,\n\t\tg = rgba[ 1 ] / 255,\n\t\tb = rgba[ 2 ] / 255,\n\t\ta = rgba[ 3 ],\n\t\tmax = Math.max( r, g, b ),\n\t\tmin = Math.min( r, g, b ),\n\t\tdiff = max - min,\n\t\tadd = max + min,\n\t\tl = add * 0.5,\n\t\th, s;\n\n\tif ( min === max ) {\n\t\th = 0;\n\t} else if ( r === max ) {\n\t\th = ( 60 * ( g - b ) / diff ) + 360;\n\t} else if ( g === max ) {\n\t\th = ( 60 * ( b - r ) / diff ) + 120;\n\t} else {\n\t\th = ( 60 * ( r - g ) / diff ) + 240;\n\t}\n\n\t// Chroma (diff) == 0 means greyscale which, by definition, saturation = 0%\n\t// otherwise, saturation is based on the ratio of chroma (diff) to lightness (add)\n\tif ( diff === 0 ) {\n\t\ts = 0;\n\t} else if ( l <= 0.5 ) {\n\t\ts = diff / add;\n\t} else {\n\t\ts = diff / ( 2 - add );\n\t}\n\treturn [ Math.round( h ) % 360, s, l, a == null ? 1 : a ];\n};\n\nspaces.hsla.from = function( hsla ) {\n\tif ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {\n\t\treturn [ null, null, null, hsla[ 3 ] ];\n\t}\n\tvar h = hsla[ 0 ] / 360,\n\t\ts = hsla[ 1 ],\n\t\tl = hsla[ 2 ],\n\t\ta = hsla[ 3 ],\n\t\tq = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,\n\t\tp = 2 * l - q;\n\n\treturn [\n\t\tMath.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),\n\t\tMath.round( hue2rgb( p, q, h ) * 255 ),\n\t\tMath.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),\n\t\ta\n\t];\n};\n\neach( spaces, function( spaceName, space ) {\n\tvar props = space.props,\n\t\tcache = space.cache,\n\t\tto = space.to,\n\t\tfrom = space.from;\n\n\t// Makes rgba() and hsla()\n\tcolor.fn[ spaceName ] = function( value ) {\n\n\t\t// Generate a cache for this space if it doesn't exist\n\t\tif ( to && !this[ cache ] ) {\n\t\t\tthis[ cache ] = to( this._rgba );\n\t\t}\n\t\tif ( value === undefined ) {\n\t\t\treturn this[ cache ].slice();\n\t\t}\n\n\t\tvar ret,\n\t\t\ttype = jQuery.type( value ),\n\t\t\tarr = ( type === \"array\" || type === \"object\" ) ? value : arguments,\n\t\t\tlocal = this[ cache ].slice();\n\n\t\teach( props, function( key, prop ) {\n\t\t\tvar val = arr[ type === \"object\" ? key : prop.idx ];\n\t\t\tif ( val == null ) {\n\t\t\t\tval = local[ prop.idx ];\n\t\t\t}\n\t\t\tlocal[ prop.idx ] = clamp( val, prop );\n\t\t} );\n\n\t\tif ( from ) {\n\t\t\tret = color( from( local ) );\n\t\t\tret[ cache ] = local;\n\t\t\treturn ret;\n\t\t} else {\n\t\t\treturn color( local );\n\t\t}\n\t};\n\n\t// Makes red() green() blue() alpha() hue() saturation() lightness()\n\teach( props, function( key, prop ) {\n\n\t\t// Alpha is included in more than one space\n\t\tif ( color.fn[ key ] ) {\n\t\t\treturn;\n\t\t}\n\t\tcolor.fn[ key ] = function( value ) {\n\t\t\tvar vtype = jQuery.type( value ),\n\t\t\t\tfn = ( key === \"alpha\" ? ( this._hsla ? \"hsla\" : \"rgba\" ) : spaceName ),\n\t\t\t\tlocal = this[ fn ](),\n\t\t\t\tcur = local[ prop.idx ],\n\t\t\t\tmatch;\n\n\t\t\tif ( vtype === \"undefined\" ) {\n\t\t\t\treturn cur;\n\t\t\t}\n\n\t\t\tif ( vtype === \"function\" ) {\n\t\t\t\tvalue = value.call( this, cur );\n\t\t\t\tvtype = jQuery.type( value );\n\t\t\t}\n\t\t\tif ( value == null && prop.empty ) {\n\t\t\t\treturn this;\n\t\t\t}\n\t\t\tif ( vtype === \"string\" ) {\n\t\t\t\tmatch = rplusequals.exec( value );\n\t\t\t\tif ( match ) {\n\t\t\t\t\tvalue = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === \"+\" ? 1 : -1 );\n\t\t\t\t}\n\t\t\t}\n\t\t\tlocal[ prop.idx ] = value;\n\t\t\treturn this[ fn ]( local );\n\t\t};\n\t} );\n} );\n\n// Add cssHook and .fx.step function for each named hook.\n// accept a space separated string of properties\ncolor.hook = function( hook ) {\n\tvar hooks = hook.split( \" \" );\n\teach( hooks, function( i, hook ) {\n\t\tjQuery.cssHooks[ hook ] = {\n\t\t\tset: function( elem, value ) {\n\t\t\t\tvar parsed, curElem,\n\t\t\t\t\tbackgroundColor = \"\";\n\n\t\t\t\tif ( value !== \"transparent\" && ( jQuery.type( value ) !== \"string\" ||\n\t\t\t\t\t\t( parsed = stringParse( value ) ) ) ) {\n\t\t\t\t\tvalue = color( parsed || value );\n\t\t\t\t\tif ( !support.rgba && value._rgba[ 3 ] !== 1 ) {\n\t\t\t\t\t\tcurElem = hook === \"backgroundColor\" ? elem.parentNode : elem;\n\t\t\t\t\t\twhile (\n\t\t\t\t\t\t\t( backgroundColor === \"\" || backgroundColor === \"transparent\" ) &&\n\t\t\t\t\t\t\tcurElem && curElem.style\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tbackgroundColor = jQuery.css( curElem, \"backgroundColor\" );\n\t\t\t\t\t\t\t\tcurElem = curElem.parentNode;\n\t\t\t\t\t\t\t} catch ( e ) {\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tvalue = value.blend( backgroundColor && backgroundColor !== \"transparent\" ?\n\t\t\t\t\t\t\tbackgroundColor :\n\t\t\t\t\t\t\t\"_default\" );\n\t\t\t\t\t}\n\n\t\t\t\t\tvalue = value.toRgbaString();\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\telem.style[ hook ] = value;\n\t\t\t\t} catch ( e ) {\n\n\t\t\t\t\t// Wrapped to prevent IE from throwing errors on \"invalid\" values like\n\t\t\t\t\t// 'auto' or 'inherit'\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tjQuery.fx.step[ hook ] = function( fx ) {\n\t\t\tif ( !fx.colorInit ) {\n\t\t\t\tfx.start = color( fx.elem, hook );\n\t\t\t\tfx.end = color( fx.end );\n\t\t\t\tfx.colorInit = true;\n\t\t\t}\n\t\t\tjQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );\n\t\t};\n\t} );\n\n};\n\ncolor.hook( stepHooks );\n\njQuery.cssHooks.borderColor = {\n\texpand: function( value ) {\n\t\tvar expanded = {};\n\n\t\teach( [ \"Top\", \"Right\", \"Bottom\", \"Left\" ], function( i, part ) {\n\t\t\texpanded[ \"border\" + part + \"Color\" ] = value;\n\t\t} );\n\t\treturn expanded;\n\t}\n};\n\n// Basic color names only.\n// Usage of any of the other color names requires adding yourself or including\n// jquery.color.svg-names.js.\ncolors = jQuery.Color.names = {\n\n\t// 4.1. Basic color keywords\n\taqua: \"#00ffff\",\n\tblack: \"#000000\",\n\tblue: \"#0000ff\",\n\tfuchsia: \"#ff00ff\",\n\tgray: \"#808080\",\n\tgreen: \"#008000\",\n\tlime: \"#00ff00\",\n\tmaroon: \"#800000\",\n\tnavy: \"#000080\",\n\tolive: \"#808000\",\n\tpurple: \"#800080\",\n\tred: \"#ff0000\",\n\tsilver: \"#c0c0c0\",\n\tteal: \"#008080\",\n\twhite: \"#ffffff\",\n\tyellow: \"#ffff00\",\n\n\t// 4.2.3. \"transparent\" color keyword\n\ttransparent: [ null, null, null, 0 ],\n\n\t_default: \"#ffffff\"\n};\n\n} )( jQuery );\n\n/******************************************************************************/\n/****************************** CLASS ANIMATIONS ******************************/\n/******************************************************************************/\n( function() {\n\nvar classAnimationActions = [ \"add\", \"remove\", \"toggle\" ],\n\tshorthandStyles = {\n\t\tborder: 1,\n\t\tborderBottom: 1,\n\t\tborderColor: 1,\n\t\tborderLeft: 1,\n\t\tborderRight: 1,\n\t\tborderTop: 1,\n\t\tborderWidth: 1,\n\t\tmargin: 1,\n\t\tpadding: 1\n\t};\n\n$.each(\n\t[ \"borderLeftStyle\", \"borderRightStyle\", \"borderBottomStyle\", \"borderTopStyle\" ],\n\tfunction( _, prop ) {\n\t\t$.fx.step[ prop ] = function( fx ) {\n\t\t\tif ( fx.end !== \"none\" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) {\n\t\t\t\tjQuery.style( fx.elem, prop, fx.end );\n\t\t\t\tfx.setAttr = true;\n\t\t\t}\n\t\t};\n\t}\n);\n\nfunction getElementStyles( elem ) {\n\tvar key, len,\n\t\tstyle = elem.ownerDocument.defaultView ?\n\t\t\telem.ownerDocument.defaultView.getComputedStyle( elem, null ) :\n\t\t\telem.currentStyle,\n\t\tstyles = {};\n\n\tif ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {\n\t\tlen = style.length;\n\t\twhile ( len-- ) {\n\t\t\tkey = style[ len ];\n\t\t\tif ( typeof style[ key ] === \"string\" ) {\n\t\t\t\tstyles[ $.camelCase( key ) ] = style[ key ];\n\t\t\t}\n\t\t}\n\n\t// Support: Opera, IE <9\n\t} else {\n\t\tfor ( key in style ) {\n\t\t\tif ( typeof style[ key ] === \"string\" ) {\n\t\t\t\tstyles[ key ] = style[ key ];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn styles;\n}\n\nfunction styleDifference( oldStyle, newStyle ) {\n\tvar diff = {},\n\t\tname, value;\n\n\tfor ( name in newStyle ) {\n\t\tvalue = newStyle[ name ];\n\t\tif ( oldStyle[ name ] !== value ) {\n\t\t\tif ( !shorthandStyles[ name ] ) {\n\t\t\t\tif ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) {\n\t\t\t\t\tdiff[ name ] = value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn diff;\n}\n\n// Support: jQuery <1.8\nif ( !$.fn.addBack ) {\n\t$.fn.addBack = function( selector ) {\n\t\treturn this.add( selector == null ?\n\t\t\tthis.prevObject : this.prevObject.filter( selector )\n\t\t);\n\t};\n}\n\n$.effects.animateClass = function( value, duration, easing, callback ) {\n\tvar o = $.speed( duration, easing, callback );\n\n\treturn this.queue( function() {\n\t\tvar animated = $( this ),\n\t\t\tbaseClass = animated.attr( \"class\" ) || \"\",\n\t\t\tapplyClassChange,\n\t\t\tallAnimations = o.children ? animated.find( \"*\" ).addBack() : animated;\n\n\t\t// Map the animated objects to store the original styles.\n\t\tallAnimations = allAnimations.map( function() {\n\t\t\tvar el = $( this );\n\t\t\treturn {\n\t\t\t\tel: el,\n\t\t\t\tstart: getElementStyles( this )\n\t\t\t};\n\t\t} );\n\n\t\t// Apply class change\n\t\tapplyClassChange = function() {\n\t\t\t$.each( classAnimationActions, function( i, action ) {\n\t\t\t\tif ( value[ action ] ) {\n\t\t\t\t\tanimated[ action + \"Class\" ]( value[ action ] );\n\t\t\t\t}\n\t\t\t} );\n\t\t};\n\t\tapplyClassChange();\n\n\t\t// Map all animated objects again - calculate new styles and diff\n\t\tallAnimations = allAnimations.map( function() {\n\t\t\tthis.end = getElementStyles( this.el[ 0 ] );\n\t\t\tthis.diff = styleDifference( this.start, this.end );\n\t\t\treturn this;\n\t\t} );\n\n\t\t// Apply original class\n\t\tanimated.attr( \"class\", baseClass );\n\n\t\t// Map all animated objects again - this time collecting a promise\n\t\tallAnimations = allAnimations.map( function() {\n\t\t\tvar styleInfo = this,\n\t\t\t\tdfd = $.Deferred(),\n\t\t\t\topts = $.extend( {}, o, {\n\t\t\t\t\tqueue: false,\n\t\t\t\t\tcomplete: function() {\n\t\t\t\t\t\tdfd.resolve( styleInfo );\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\tthis.el.animate( this.diff, opts );\n\t\t\treturn dfd.promise();\n\t\t} );\n\n\t\t// Once all animations have completed:\n\t\t$.when.apply( $, allAnimations.get() ).done( function() {\n\n\t\t\t// Set the final class\n\t\t\tapplyClassChange();\n\n\t\t\t// For each animated element,\n\t\t\t// clear all css properties that were animated\n\t\t\t$.each( arguments, function() {\n\t\t\t\tvar el = this.el;\n\t\t\t\t$.each( this.diff, function( key ) {\n\t\t\t\t\tel.css( key, \"\" );\n\t\t\t\t} );\n\t\t\t} );\n\n\t\t\t// This is guarnteed to be there if you use jQuery.speed()\n\t\t\t// it also handles dequeuing the next anim...\n\t\t\to.complete.call( animated[ 0 ] );\n\t\t} );\n\t} );\n};\n\n$.fn.extend( {\n\taddClass: ( function( orig ) {\n\t\treturn function( classNames, speed, easing, callback ) {\n\t\t\treturn speed ?\n\t\t\t\t$.effects.animateClass.call( this,\n\t\t\t\t\t{ add: classNames }, speed, easing, callback ) :\n\t\t\t\torig.apply( this, arguments );\n\t\t};\n\t} )( $.fn.addClass ),\n\n\tremoveClass: ( function( orig ) {\n\t\treturn function( classNames, speed, easing, callback ) {\n\t\t\treturn arguments.length > 1 ?\n\t\t\t\t$.effects.animateClass.call( this,\n\t\t\t\t\t{ remove: classNames }, speed, easing, callback ) :\n\t\t\t\torig.apply( this, arguments );\n\t\t};\n\t} )( $.fn.removeClass ),\n\n\ttoggleClass: ( function( orig ) {\n\t\treturn function( classNames, force, speed, easing, callback ) {\n\t\t\tif ( typeof force === \"boolean\" || force === undefined ) {\n\t\t\t\tif ( !speed ) {\n\n\t\t\t\t\t// Without speed parameter\n\t\t\t\t\treturn orig.apply( this, arguments );\n\t\t\t\t} else {\n\t\t\t\t\treturn $.effects.animateClass.call( this,\n\t\t\t\t\t\t( force ? { add: classNames } : { remove: classNames } ),\n\t\t\t\t\t\tspeed, easing, callback );\n\t\t\t\t}\n\t\t\t} else {\n\n\t\t\t\t// Without force parameter\n\t\t\t\treturn $.effects.animateClass.call( this,\n\t\t\t\t\t{ toggle: classNames }, force, speed, easing );\n\t\t\t}\n\t\t};\n\t} )( $.fn.toggleClass ),\n\n\tswitchClass: function( remove, add, speed, easing, callback ) {\n\t\treturn $.effects.animateClass.call( this, {\n\t\t\tadd: add,\n\t\t\tremove: remove\n\t\t}, speed, easing, callback );\n\t}\n} );\n\n} )();\n\n/******************************************************************************/\n/*********************************** EFFECTS **********************************/\n/******************************************************************************/\n\n( function() {\n\nif ( $.expr && $.expr.filters && $.expr.filters.animated ) {\n\t$.expr.filters.animated = ( function( orig ) {\n\t\treturn function( elem ) {\n\t\t\treturn !!$( elem ).data( dataSpaceAnimated ) || orig( elem );\n\t\t};\n\t} )( $.expr.filters.animated );\n}\n\nif ( $.uiBackCompat !== false ) {\n\t$.extend( $.effects, {\n\n\t\t// Saves a set of properties in a data storage\n\t\tsave: function( element, set ) {\n\t\t\tvar i = 0, length = set.length;\n\t\t\tfor ( ; i < length; i++ ) {\n\t\t\t\tif ( set[ i ] !== null ) {\n\t\t\t\t\telement.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t// Restores a set of previously saved properties from a data storage\n\t\trestore: function( element, set ) {\n\t\t\tvar val, i = 0, length = set.length;\n\t\t\tfor ( ; i < length; i++ ) {\n\t\t\t\tif ( set[ i ] !== null ) {\n\t\t\t\t\tval = element.data( dataSpace + set[ i ] );\n\t\t\t\t\telement.css( set[ i ], val );\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\tsetMode: function( el, mode ) {\n\t\t\tif ( mode === \"toggle\" ) {\n\t\t\t\tmode = el.is( \":hidden\" ) ? \"show\" : \"hide\";\n\t\t\t}\n\t\t\treturn mode;\n\t\t},\n\n\t\t// Wraps the element around a wrapper that copies position properties\n\t\tcreateWrapper: function( element ) {\n\n\t\t\t// If the element is already wrapped, return it\n\t\t\tif ( element.parent().is( \".ui-effects-wrapper\" ) ) {\n\t\t\t\treturn element.parent();\n\t\t\t}\n\n\t\t\t// Wrap the element\n\t\t\tvar props = {\n\t\t\t\t\twidth: element.outerWidth( true ),\n\t\t\t\t\theight: element.outerHeight( true ),\n\t\t\t\t\t\"float\": element.css( \"float\" )\n\t\t\t\t},\n\t\t\t\twrapper = $( \"<div></div>\" )\n\t\t\t\t\t.addClass( \"ui-effects-wrapper\" )\n\t\t\t\t\t.css( {\n\t\t\t\t\t\tfontSize: \"100%\",\n\t\t\t\t\t\tbackground: \"transparent\",\n\t\t\t\t\t\tborder: \"none\",\n\t\t\t\t\t\tmargin: 0,\n\t\t\t\t\t\tpadding: 0\n\t\t\t\t\t} ),\n\n\t\t\t\t// Store the size in case width/height are defined in % - Fixes #5245\n\t\t\t\tsize = {\n\t\t\t\t\twidth: element.width(),\n\t\t\t\t\theight: element.height()\n\t\t\t\t},\n\t\t\t\tactive = document.activeElement;\n\n\t\t\t// Support: Firefox\n\t\t\t// Firefox incorrectly exposes anonymous content\n\t\t\t// https://bugzilla.mozilla.org/show_bug.cgi?id=561664\n\t\t\ttry {\n\t\t\t\tactive.id;\n\t\t\t} catch ( e ) {\n\t\t\t\tactive = document.body;\n\t\t\t}\n\n\t\t\telement.wrap( wrapper );\n\n\t\t\t// Fixes #7595 - Elements lose focus when wrapped.\n\t\t\tif ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {\n\t\t\t\t$( active ).trigger( \"focus\" );\n\t\t\t}\n\n\t\t\t// Hotfix for jQuery 1.4 since some change in wrap() seems to actually\n\t\t\t// lose the reference to the wrapped element\n\t\t\twrapper = element.parent();\n\n\t\t\t// Transfer positioning properties to the wrapper\n\t\t\tif ( element.css( \"position\" ) === \"static\" ) {\n\t\t\t\twrapper.css( { position: \"relative\" } );\n\t\t\t\telement.css( { position: \"relative\" } );\n\t\t\t} else {\n\t\t\t\t$.extend( props, {\n\t\t\t\t\tposition: element.css( \"position\" ),\n\t\t\t\t\tzIndex: element.css( \"z-index\" )\n\t\t\t\t} );\n\t\t\t\t$.each( [ \"top\", \"left\", \"bottom\", \"right\" ], function( i, pos ) {\n\t\t\t\t\tprops[ pos ] = element.css( pos );\n\t\t\t\t\tif ( isNaN( parseInt( props[ pos ], 10 ) ) ) {\n\t\t\t\t\t\tprops[ pos ] = \"auto\";\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t\telement.css( {\n\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\ttop: 0,\n\t\t\t\t\tleft: 0,\n\t\t\t\t\tright: \"auto\",\n\t\t\t\t\tbottom: \"auto\"\n\t\t\t\t} );\n\t\t\t}\n\t\t\telement.css( size );\n\n\t\t\treturn wrapper.css( props ).show();\n\t\t},\n\n\t\tremoveWrapper: function( element ) {\n\t\t\tvar active = document.activeElement;\n\n\t\t\tif ( element.parent().is( \".ui-effects-wrapper\" ) ) {\n\t\t\t\telement.parent().replaceWith( element );\n\n\t\t\t\t// Fixes #7595 - Elements lose focus when wrapped.\n\t\t\t\tif ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {\n\t\t\t\t\t$( active ).trigger( \"focus\" );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn element;\n\t\t}\n\t} );\n}\n\n$.extend( $.effects, {\n\tversion: \"1.12.1\",\n\n\tdefine: function( name, mode, effect ) {\n\t\tif ( !effect ) {\n\t\t\teffect = mode;\n\t\t\tmode = \"effect\";\n\t\t}\n\n\t\t$.effects.effect[ name ] = effect;\n\t\t$.effects.effect[ name ].mode = mode;\n\n\t\treturn effect;\n\t},\n\n\tscaledDimensions: function( element, percent, direction ) {\n\t\tif ( percent === 0 ) {\n\t\t\treturn {\n\t\t\t\theight: 0,\n\t\t\t\twidth: 0,\n\t\t\t\touterHeight: 0,\n\t\t\t\touterWidth: 0\n\t\t\t};\n\t\t}\n\n\t\tvar x = direction !== \"horizontal\" ? ( ( percent || 100 ) / 100 ) : 1,\n\t\t\ty = direction !== \"vertical\" ? ( ( percent || 100 ) / 100 ) : 1;\n\n\t\treturn {\n\t\t\theight: element.height() * y,\n\t\t\twidth: element.width() * x,\n\t\t\touterHeight: element.outerHeight() * y,\n\t\t\touterWidth: element.outerWidth() * x\n\t\t};\n\n\t},\n\n\tclipToBox: function( animation ) {\n\t\treturn {\n\t\t\twidth: animation.clip.right - animation.clip.left,\n\t\t\theight: animation.clip.bottom - animation.clip.top,\n\t\t\tleft: animation.clip.left,\n\t\t\ttop: animation.clip.top\n\t\t};\n\t},\n\n\t// Injects recently queued functions to be first in line (after \"inprogress\")\n\tunshift: function( element, queueLength, count ) {\n\t\tvar queue = element.queue();\n\n\t\tif ( queueLength > 1 ) {\n\t\t\tqueue.splice.apply( queue,\n\t\t\t\t[ 1, 0 ].concat( queue.splice( queueLength, count ) ) );\n\t\t}\n\t\telement.dequeue();\n\t},\n\n\tsaveStyle: function( element ) {\n\t\telement.data( dataSpaceStyle, element[ 0 ].style.cssText );\n\t},\n\n\trestoreStyle: function( element ) {\n\t\telement[ 0 ].style.cssText = element.data( dataSpaceStyle ) || \"\";\n\t\telement.removeData( dataSpaceStyle );\n\t},\n\n\tmode: function( element, mode ) {\n\t\tvar hidden = element.is( \":hidden\" );\n\n\t\tif ( mode === \"toggle\" ) {\n\t\t\tmode = hidden ? \"show\" : \"hide\";\n\t\t}\n\t\tif ( hidden ? mode === \"hide\" : mode === \"show\" ) {\n\t\t\tmode = \"none\";\n\t\t}\n\t\treturn mode;\n\t},\n\n\t// Translates a [top,left] array into a baseline value\n\tgetBaseline: function( origin, original ) {\n\t\tvar y, x;\n\n\t\tswitch ( origin[ 0 ] ) {\n\t\tcase \"top\":\n\t\t\ty = 0;\n\t\t\tbreak;\n\t\tcase \"middle\":\n\t\t\ty = 0.5;\n\t\t\tbreak;\n\t\tcase \"bottom\":\n\t\t\ty = 1;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\ty = origin[ 0 ] / original.height;\n\t\t}\n\n\t\tswitch ( origin[ 1 ] ) {\n\t\tcase \"left\":\n\t\t\tx = 0;\n\t\t\tbreak;\n\t\tcase \"center\":\n\t\t\tx = 0.5;\n\t\t\tbreak;\n\t\tcase \"right\":\n\t\t\tx = 1;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tx = origin[ 1 ] / original.width;\n\t\t}\n\n\t\treturn {\n\t\t\tx: x,\n\t\t\ty: y\n\t\t};\n\t},\n\n\t// Creates a placeholder element so that the original element can be made absolute\n\tcreatePlaceholder: function( element ) {\n\t\tvar placeholder,\n\t\t\tcssPosition = element.css( \"position\" ),\n\t\t\tposition = element.position();\n\n\t\t// Lock in margins first to account for form elements, which\n\t\t// will change margin if you explicitly set height\n\t\t// see: http://jsfiddle.net/JZSMt/3/ https://bugs.webkit.org/show_bug.cgi?id=107380\n\t\t// Support: Safari\n\t\telement.css( {\n\t\t\tmarginTop: element.css( \"marginTop\" ),\n\t\t\tmarginBottom: element.css( \"marginBottom\" ),\n\t\t\tmarginLeft: element.css( \"marginLeft\" ),\n\t\t\tmarginRight: element.css( \"marginRight\" )\n\t\t} )\n\t\t.outerWidth( element.outerWidth() )\n\t\t.outerHeight( element.outerHeight() );\n\n\t\tif ( /^(static|relative)/.test( cssPosition ) ) {\n\t\t\tcssPosition = \"absolute\";\n\n\t\t\tplaceholder = $( \"<\" + element[ 0 ].nodeName + \">\" ).insertAfter( element ).css( {\n\n\t\t\t\t// Convert inline to inline block to account for inline elements\n\t\t\t\t// that turn to inline block based on content (like img)\n\t\t\t\tdisplay: /^(inline|ruby)/.test( element.css( \"display\" ) ) ?\n\t\t\t\t\t\"inline-block\" :\n\t\t\t\t\t\"block\",\n\t\t\t\tvisibility: \"hidden\",\n\n\t\t\t\t// Margins need to be set to account for margin collapse\n\t\t\t\tmarginTop: element.css( \"marginTop\" ),\n\t\t\t\tmarginBottom: element.css( \"marginBottom\" ),\n\t\t\t\tmarginLeft: element.css( \"marginLeft\" ),\n\t\t\t\tmarginRight: element.css( \"marginRight\" ),\n\t\t\t\t\"float\": element.css( \"float\" )\n\t\t\t} )\n\t\t\t.outerWidth( element.outerWidth() )\n\t\t\t.outerHeight( element.outerHeight() )\n\t\t\t.addClass( \"ui-effects-placeholder\" );\n\n\t\t\telement.data( dataSpace + \"placeholder\", placeholder );\n\t\t}\n\n\t\telement.css( {\n\t\t\tposition: cssPosition,\n\t\t\tleft: position.left,\n\t\t\ttop: position.top\n\t\t} );\n\n\t\treturn placeholder;\n\t},\n\n\tremovePlaceholder: function( element ) {\n\t\tvar dataKey = dataSpace + \"placeholder\",\n\t\t\t\tplaceholder = element.data( dataKey );\n\n\t\tif ( placeholder ) {\n\t\t\tplaceholder.remove();\n\t\t\telement.removeData( dataKey );\n\t\t}\n\t},\n\n\t// Removes a placeholder if it exists and restores\n\t// properties that were modified during placeholder creation\n\tcleanUp: function( element ) {\n\t\t$.effects.restoreStyle( element );\n\t\t$.effects.removePlaceholder( element );\n\t},\n\n\tsetTransition: function( element, list, factor, value ) {\n\t\tvalue = value || {};\n\t\t$.each( list, function( i, x ) {\n\t\t\tvar unit = element.cssUnit( x );\n\t\t\tif ( unit[ 0 ] > 0 ) {\n\t\t\t\tvalue[ x ] = unit[ 0 ] * factor + unit[ 1 ];\n\t\t\t}\n\t\t} );\n\t\treturn value;\n\t}\n} );\n\n// Return an effect options object for the given parameters:\nfunction _normalizeArguments( effect, options, speed, callback ) {\n\n\t// Allow passing all options as the first parameter\n\tif ( $.isPlainObject( effect ) ) {\n\t\toptions = effect;\n\t\teffect = effect.effect;\n\t}\n\n\t// Convert to an object\n\teffect = { effect: effect };\n\n\t// Catch (effect, null, ...)\n\tif ( options == null ) {\n\t\toptions = {};\n\t}\n\n\t// Catch (effect, callback)\n\tif ( $.isFunction( options ) ) {\n\t\tcallback = options;\n\t\tspeed = null;\n\t\toptions = {};\n\t}\n\n\t// Catch (effect, speed, ?)\n\tif ( typeof options === \"number\" || $.fx.speeds[ options ] ) {\n\t\tcallback = speed;\n\t\tspeed = options;\n\t\toptions = {};\n\t}\n\n\t// Catch (effect, options, callback)\n\tif ( $.isFunction( speed ) ) {\n\t\tcallback = speed;\n\t\tspeed = null;\n\t}\n\n\t// Add options to effect\n\tif ( options ) {\n\t\t$.extend( effect, options );\n\t}\n\n\tspeed = speed || options.duration;\n\teffect.duration = $.fx.off ? 0 :\n\t\ttypeof speed === \"number\" ? speed :\n\t\tspeed in $.fx.speeds ? $.fx.speeds[ speed ] :\n\t\t$.fx.speeds._default;\n\n\teffect.complete = callback || options.complete;\n\n\treturn effect;\n}\n\nfunction standardAnimationOption( option ) {\n\n\t// Valid standard speeds (nothing, number, named speed)\n\tif ( !option || typeof option === \"number\" || $.fx.speeds[ option ] ) {\n\t\treturn true;\n\t}\n\n\t// Invalid strings - treat as \"normal\" speed\n\tif ( typeof option === \"string\" && !$.effects.effect[ option ] ) {\n\t\treturn true;\n\t}\n\n\t// Complete callback\n\tif ( $.isFunction( option ) ) {\n\t\treturn true;\n\t}\n\n\t// Options hash (but not naming an effect)\n\tif ( typeof option === \"object\" && !option.effect ) {\n\t\treturn true;\n\t}\n\n\t// Didn't match any standard API\n\treturn false;\n}\n\n$.fn.extend( {\n\teffect: function( /* effect, options, speed, callback */ ) {\n\t\tvar args = _normalizeArguments.apply( this, arguments ),\n\t\t\teffectMethod = $.effects.effect[ args.effect ],\n\t\t\tdefaultMode = effectMethod.mode,\n\t\t\tqueue = args.queue,\n\t\t\tqueueName = queue || \"fx\",\n\t\t\tcomplete = args.complete,\n\t\t\tmode = args.mode,\n\t\t\tmodes = [],\n\t\t\tprefilter = function( next ) {\n\t\t\t\tvar el = $( this ),\n\t\t\t\t\tnormalizedMode = $.effects.mode( el, mode ) || defaultMode;\n\n\t\t\t\t// Sentinel for duck-punching the :animated psuedo-selector\n\t\t\t\tel.data( dataSpaceAnimated, true );\n\n\t\t\t\t// Save effect mode for later use,\n\t\t\t\t// we can't just call $.effects.mode again later,\n\t\t\t\t// as the .show() below destroys the initial state\n\t\t\t\tmodes.push( normalizedMode );\n\n\t\t\t\t// See $.uiBackCompat inside of run() for removal of defaultMode in 1.13\n\t\t\t\tif ( defaultMode && ( normalizedMode === \"show\" ||\n\t\t\t\t\t\t( normalizedMode === defaultMode && normalizedMode === \"hide\" ) ) ) {\n\t\t\t\t\tel.show();\n\t\t\t\t}\n\n\t\t\t\tif ( !defaultMode || normalizedMode !== \"none\" ) {\n\t\t\t\t\t$.effects.saveStyle( el );\n\t\t\t\t}\n\n\t\t\t\tif ( $.isFunction( next ) ) {\n\t\t\t\t\tnext();\n\t\t\t\t}\n\t\t\t};\n\n\t\tif ( $.fx.off || !effectMethod ) {\n\n\t\t\t// Delegate to the original method (e.g., .show()) if possible\n\t\t\tif ( mode ) {\n\t\t\t\treturn this[ mode ]( args.duration, complete );\n\t\t\t} else {\n\t\t\t\treturn this.each( function() {\n\t\t\t\t\tif ( complete ) {\n\t\t\t\t\t\tcomplete.call( this );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\n\t\tfunction run( next ) {\n\t\t\tvar elem = $( this );\n\n\t\t\tfunction cleanup() {\n\t\t\t\telem.removeData( dataSpaceAnimated );\n\n\t\t\t\t$.effects.cleanUp( elem );\n\n\t\t\t\tif ( args.mode === \"hide\" ) {\n\t\t\t\t\telem.hide();\n\t\t\t\t}\n\n\t\t\t\tdone();\n\t\t\t}\n\n\t\t\tfunction done() {\n\t\t\t\tif ( $.isFunction( complete ) ) {\n\t\t\t\t\tcomplete.call( elem[ 0 ] );\n\t\t\t\t}\n\n\t\t\t\tif ( $.isFunction( next ) ) {\n\t\t\t\t\tnext();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Override mode option on a per element basis,\n\t\t\t// as toggle can be either show or hide depending on element state\n\t\t\targs.mode = modes.shift();\n\n\t\t\tif ( $.uiBackCompat !== false && !defaultMode ) {\n\t\t\t\tif ( elem.is( \":hidden\" ) ? mode === \"hide\" : mode === \"show\" ) {\n\n\t\t\t\t\t// Call the core method to track \"olddisplay\" properly\n\t\t\t\t\telem[ mode ]();\n\t\t\t\t\tdone();\n\t\t\t\t} else {\n\t\t\t\t\teffectMethod.call( elem[ 0 ], args, done );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif ( args.mode === \"none\" ) {\n\n\t\t\t\t\t// Call the core method to track \"olddisplay\" properly\n\t\t\t\t\telem[ mode ]();\n\t\t\t\t\tdone();\n\t\t\t\t} else {\n\t\t\t\t\teffectMethod.call( elem[ 0 ], args, cleanup );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Run prefilter on all elements first to ensure that\n\t\t// any showing or hiding happens before placeholder creation,\n\t\t// which ensures that any layout changes are correctly captured.\n\t\treturn queue === false ?\n\t\t\tthis.each( prefilter ).each( run ) :\n\t\t\tthis.queue( queueName, prefilter ).queue( queueName, run );\n\t},\n\n\tshow: ( function( orig ) {\n\t\treturn function( option ) {\n\t\t\tif ( standardAnimationOption( option ) ) {\n\t\t\t\treturn orig.apply( this, arguments );\n\t\t\t} else {\n\t\t\t\tvar args = _normalizeArguments.apply( this, arguments );\n\t\t\t\targs.mode = \"show\";\n\t\t\t\treturn this.effect.call( this, args );\n\t\t\t}\n\t\t};\n\t} )( $.fn.show ),\n\n\thide: ( function( orig ) {\n\t\treturn function( option ) {\n\t\t\tif ( standardAnimationOption( option ) ) {\n\t\t\t\treturn orig.apply( this, arguments );\n\t\t\t} else {\n\t\t\t\tvar args = _normalizeArguments.apply( this, arguments );\n\t\t\t\targs.mode = \"hide\";\n\t\t\t\treturn this.effect.call( this, args );\n\t\t\t}\n\t\t};\n\t} )( $.fn.hide ),\n\n\ttoggle: ( function( orig ) {\n\t\treturn function( option ) {\n\t\t\tif ( standardAnimationOption( option ) || typeof option === \"boolean\" ) {\n\t\t\t\treturn orig.apply( this, arguments );\n\t\t\t} else {\n\t\t\t\tvar args = _normalizeArguments.apply( this, arguments );\n\t\t\t\targs.mode = \"toggle\";\n\t\t\t\treturn this.effect.call( this, args );\n\t\t\t}\n\t\t};\n\t} )( $.fn.toggle ),\n\n\tcssUnit: function( key ) {\n\t\tvar style = this.css( key ),\n\t\t\tval = [];\n\n\t\t$.each( [ \"em\", \"px\", \"%\", \"pt\" ], function( i, unit ) {\n\t\t\tif ( style.indexOf( unit ) > 0 ) {\n\t\t\t\tval = [ parseFloat( style ), unit ];\n\t\t\t}\n\t\t} );\n\t\treturn val;\n\t},\n\n\tcssClip: function( clipObj ) {\n\t\tif ( clipObj ) {\n\t\t\treturn this.css( \"clip\", \"rect(\" + clipObj.top + \"px \" + clipObj.right + \"px \" +\n\t\t\t\tclipObj.bottom + \"px \" + clipObj.left + \"px)\" );\n\t\t}\n\t\treturn parseClip( this.css( \"clip\" ), this );\n\t},\n\n\ttransfer: function( options, done ) {\n\t\tvar element = $( this ),\n\t\t\ttarget = $( options.to ),\n\t\t\ttargetFixed = target.css( \"position\" ) === \"fixed\",\n\t\t\tbody = $( \"body\" ),\n\t\t\tfixTop = targetFixed ? body.scrollTop() : 0,\n\t\t\tfixLeft = targetFixed ? body.scrollLeft() : 0,\n\t\t\tendPosition = target.offset(),\n\t\t\tanimation = {\n\t\t\t\ttop: endPosition.top - fixTop,\n\t\t\t\tleft: endPosition.left - fixLeft,\n\t\t\t\theight: target.innerHeight(),\n\t\t\t\twidth: target.innerWidth()\n\t\t\t},\n\t\t\tstartPosition = element.offset(),\n\t\t\ttransfer = $( \"<div class='ui-effects-transfer'></div>\" )\n\t\t\t\t.appendTo( \"body\" )\n\t\t\t\t.addClass( options.className )\n\t\t\t\t.css( {\n\t\t\t\t\ttop: startPosition.top - fixTop,\n\t\t\t\t\tleft: startPosition.left - fixLeft,\n\t\t\t\t\theight: element.innerHeight(),\n\t\t\t\t\twidth: element.innerWidth(),\n\t\t\t\t\tposition: targetFixed ? \"fixed\" : \"absolute\"\n\t\t\t\t} )\n\t\t\t\t.animate( animation, options.duration, options.easing, function() {\n\t\t\t\t\ttransfer.remove();\n\t\t\t\t\tif ( $.isFunction( done ) ) {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t}\n\t\t\t\t} );\n\t}\n} );\n\nfunction parseClip( str, element ) {\n\t\tvar outerWidth = element.outerWidth(),\n\t\t\touterHeight = element.outerHeight(),\n\t\t\tclipRegex = /^rect\\((-?\\d*\\.?\\d*px|-?\\d+%|auto),?\\s*(-?\\d*\\.?\\d*px|-?\\d+%|auto),?\\s*(-?\\d*\\.?\\d*px|-?\\d+%|auto),?\\s*(-?\\d*\\.?\\d*px|-?\\d+%|auto)\\)$/,\n\t\t\tvalues = clipRegex.exec( str ) || [ \"\", 0, outerWidth, outerHeight, 0 ];\n\n\t\treturn {\n\t\t\ttop: parseFloat( values[ 1 ] ) || 0,\n\t\t\tright: values[ 2 ] === \"auto\" ? outerWidth : parseFloat( values[ 2 ] ),\n\t\t\tbottom: values[ 3 ] === \"auto\" ? outerHeight : parseFloat( values[ 3 ] ),\n\t\t\tleft: parseFloat( values[ 4 ] ) || 0\n\t\t};\n}\n\n$.fx.step.clip = function( fx ) {\n\tif ( !fx.clipInit ) {\n\t\tfx.start = $( fx.elem ).cssClip();\n\t\tif ( typeof fx.end === \"string\" ) {\n\t\t\tfx.end = parseClip( fx.end, fx.elem );\n\t\t}\n\t\tfx.clipInit = true;\n\t}\n\n\t$( fx.elem ).cssClip( {\n\t\ttop: fx.pos * ( fx.end.top - fx.start.top ) + fx.start.top,\n\t\tright: fx.pos * ( fx.end.right - fx.start.right ) + fx.start.right,\n\t\tbottom: fx.pos * ( fx.end.bottom - fx.start.bottom ) + fx.start.bottom,\n\t\tleft: fx.pos * ( fx.end.left - fx.start.left ) + fx.start.left\n\t} );\n};\n\n} )();\n\n/******************************************************************************/\n/*********************************** EASING ***********************************/\n/******************************************************************************/\n\n( function() {\n\n// Based on easing equations from Robert Penner (http://www.robertpenner.com/easing)\n\nvar baseEasings = {};\n\n$.each( [ \"Quad\", \"Cubic\", \"Quart\", \"Quint\", \"Expo\" ], function( i, name ) {\n\tbaseEasings[ name ] = function( p ) {\n\t\treturn Math.pow( p, i + 2 );\n\t};\n} );\n\n$.extend( baseEasings, {\n\tSine: function( p ) {\n\t\treturn 1 - Math.cos( p * Math.PI / 2 );\n\t},\n\tCirc: function( p ) {\n\t\treturn 1 - Math.sqrt( 1 - p * p );\n\t},\n\tElastic: function( p ) {\n\t\treturn p === 0 || p === 1 ? p :\n\t\t\t-Math.pow( 2, 8 * ( p - 1 ) ) * Math.sin( ( ( p - 1 ) * 80 - 7.5 ) * Math.PI / 15 );\n\t},\n\tBack: function( p ) {\n\t\treturn p * p * ( 3 * p - 2 );\n\t},\n\tBounce: function( p ) {\n\t\tvar pow2,\n\t\t\tbounce = 4;\n\n\t\twhile ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}\n\t\treturn 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );\n\t}\n} );\n\n$.each( baseEasings, function( name, easeIn ) {\n\t$.easing[ \"easeIn\" + name ] = easeIn;\n\t$.easing[ \"easeOut\" + name ] = function( p ) {\n\t\treturn 1 - easeIn( 1 - p );\n\t};\n\t$.easing[ \"easeInOut\" + name ] = function( p ) {\n\t\treturn p < 0.5 ?\n\t\t\teaseIn( p * 2 ) / 2 :\n\t\t\t1 - easeIn( p * -2 + 2 ) / 2;\n\t};\n} );\n\n} )();\n\nvar effect = $.effects;\n\n\n/*!\n * jQuery UI Effects Blind 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Blind Effect\n//>>group: Effects\n//>>description: Blinds the element.\n//>>docs: http://api.jqueryui.com/blind-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectBlind = $.effects.define( \"blind\", \"hide\", function( options, done ) {\n\tvar map = {\n\t\t\tup: [ \"bottom\", \"top\" ],\n\t\t\tvertical: [ \"bottom\", \"top\" ],\n\t\t\tdown: [ \"top\", \"bottom\" ],\n\t\t\tleft: [ \"right\", \"left\" ],\n\t\t\thorizontal: [ \"right\", \"left\" ],\n\t\t\tright: [ \"left\", \"right\" ]\n\t\t},\n\t\telement = $( this ),\n\t\tdirection = options.direction || \"up\",\n\t\tstart = element.cssClip(),\n\t\tanimate = { clip: $.extend( {}, start ) },\n\t\tplaceholder = $.effects.createPlaceholder( element );\n\n\tanimate.clip[ map[ direction ][ 0 ] ] = animate.clip[ map[ direction ][ 1 ] ];\n\n\tif ( options.mode === \"show\" ) {\n\t\telement.cssClip( animate.clip );\n\t\tif ( placeholder ) {\n\t\t\tplaceholder.css( $.effects.clipToBox( animate ) );\n\t\t}\n\n\t\tanimate.clip = start;\n\t}\n\n\tif ( placeholder ) {\n\t\tplaceholder.animate( $.effects.clipToBox( animate ), options.duration, options.easing );\n\t}\n\n\telement.animate( animate, {\n\t\tqueue: false,\n\t\tduration: options.duration,\n\t\teasing: options.easing,\n\t\tcomplete: done\n\t} );\n} );\n\n\n/*!\n * jQuery UI Effects Bounce 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Bounce Effect\n//>>group: Effects\n//>>description: Bounces an element horizontally or vertically n times.\n//>>docs: http://api.jqueryui.com/bounce-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectBounce = $.effects.define( \"bounce\", function( options, done ) {\n\tvar upAnim, downAnim, refValue,\n\t\telement = $( this ),\n\n\t\t// Defaults:\n\t\tmode = options.mode,\n\t\thide = mode === \"hide\",\n\t\tshow = mode === \"show\",\n\t\tdirection = options.direction || \"up\",\n\t\tdistance = options.distance,\n\t\ttimes = options.times || 5,\n\n\t\t// Number of internal animations\n\t\tanims = times * 2 + ( show || hide ? 1 : 0 ),\n\t\tspeed = options.duration / anims,\n\t\teasing = options.easing,\n\n\t\t// Utility:\n\t\tref = ( direction === \"up\" || direction === \"down\" ) ? \"top\" : \"left\",\n\t\tmotion = ( direction === \"up\" || direction === \"left\" ),\n\t\ti = 0,\n\n\t\tqueuelen = element.queue().length;\n\n\t$.effects.createPlaceholder( element );\n\n\trefValue = element.css( ref );\n\n\t// Default distance for the BIGGEST bounce is the outer Distance / 3\n\tif ( !distance ) {\n\t\tdistance = element[ ref === \"top\" ? \"outerHeight\" : \"outerWidth\" ]() / 3;\n\t}\n\n\tif ( show ) {\n\t\tdownAnim = { opacity: 1 };\n\t\tdownAnim[ ref ] = refValue;\n\n\t\t// If we are showing, force opacity 0 and set the initial position\n\t\t// then do the \"first\" animation\n\t\telement\n\t\t\t.css( \"opacity\", 0 )\n\t\t\t.css( ref, motion ? -distance * 2 : distance * 2 )\n\t\t\t.animate( downAnim, speed, easing );\n\t}\n\n\t// Start at the smallest distance if we are hiding\n\tif ( hide ) {\n\t\tdistance = distance / Math.pow( 2, times - 1 );\n\t}\n\n\tdownAnim = {};\n\tdownAnim[ ref ] = refValue;\n\n\t// Bounces up/down/left/right then back to 0 -- times * 2 animations happen here\n\tfor ( ; i < times; i++ ) {\n\t\tupAnim = {};\n\t\tupAnim[ ref ] = ( motion ? \"-=\" : \"+=\" ) + distance;\n\n\t\telement\n\t\t\t.animate( upAnim, speed, easing )\n\t\t\t.animate( downAnim, speed, easing );\n\n\t\tdistance = hide ? distance * 2 : distance / 2;\n\t}\n\n\t// Last Bounce when Hiding\n\tif ( hide ) {\n\t\tupAnim = { opacity: 0 };\n\t\tupAnim[ ref ] = ( motion ? \"-=\" : \"+=\" ) + distance;\n\n\t\telement.animate( upAnim, speed, easing );\n\t}\n\n\telement.queue( done );\n\n\t$.effects.unshift( element, queuelen, anims + 1 );\n} );\n\n\n/*!\n * jQuery UI Effects Clip 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Clip Effect\n//>>group: Effects\n//>>description: Clips the element on and off like an old TV.\n//>>docs: http://api.jqueryui.com/clip-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectClip = $.effects.define( \"clip\", \"hide\", function( options, done ) {\n\tvar start,\n\t\tanimate = {},\n\t\telement = $( this ),\n\t\tdirection = options.direction || \"vertical\",\n\t\tboth = direction === \"both\",\n\t\thorizontal = both || direction === \"horizontal\",\n\t\tvertical = both || direction === \"vertical\";\n\n\tstart = element.cssClip();\n\tanimate.clip = {\n\t\ttop: vertical ? ( start.bottom - start.top ) / 2 : start.top,\n\t\tright: horizontal ? ( start.right - start.left ) / 2 : start.right,\n\t\tbottom: vertical ? ( start.bottom - start.top ) / 2 : start.bottom,\n\t\tleft: horizontal ? ( start.right - start.left ) / 2 : start.left\n\t};\n\n\t$.effects.createPlaceholder( element );\n\n\tif ( options.mode === \"show\" ) {\n\t\telement.cssClip( animate.clip );\n\t\tanimate.clip = start;\n\t}\n\n\telement.animate( animate, {\n\t\tqueue: false,\n\t\tduration: options.duration,\n\t\teasing: options.easing,\n\t\tcomplete: done\n\t} );\n\n} );\n\n\n/*!\n * jQuery UI Effects Drop 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Drop Effect\n//>>group: Effects\n//>>description: Moves an element in one direction and hides it at the same time.\n//>>docs: http://api.jqueryui.com/drop-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectDrop = $.effects.define( \"drop\", \"hide\", function( options, done ) {\n\n\tvar distance,\n\t\telement = $( this ),\n\t\tmode = options.mode,\n\t\tshow = mode === \"show\",\n\t\tdirection = options.direction || \"left\",\n\t\tref = ( direction === \"up\" || direction === \"down\" ) ? \"top\" : \"left\",\n\t\tmotion = ( direction === \"up\" || direction === \"left\" ) ? \"-=\" : \"+=\",\n\t\toppositeMotion = ( motion === \"+=\" ) ? \"-=\" : \"+=\",\n\t\tanimation = {\n\t\t\topacity: 0\n\t\t};\n\n\t$.effects.createPlaceholder( element );\n\n\tdistance = options.distance ||\n\t\telement[ ref === \"top\" ? \"outerHeight\" : \"outerWidth\" ]( true ) / 2;\n\n\tanimation[ ref ] = motion + distance;\n\n\tif ( show ) {\n\t\telement.css( animation );\n\n\t\tanimation[ ref ] = oppositeMotion + distance;\n\t\tanimation.opacity = 1;\n\t}\n\n\t// Animate\n\telement.animate( animation, {\n\t\tqueue: false,\n\t\tduration: options.duration,\n\t\teasing: options.easing,\n\t\tcomplete: done\n\t} );\n} );\n\n\n/*!\n * jQuery UI Effects Explode 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Explode Effect\n//>>group: Effects\n// jscs:disable maximumLineLength\n//>>description: Explodes an element in all directions into n pieces. Implodes an element to its original wholeness.\n// jscs:enable maximumLineLength\n//>>docs: http://api.jqueryui.com/explode-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectExplode = $.effects.define( \"explode\", \"hide\", function( options, done ) {\n\n\tvar i, j, left, top, mx, my,\n\t\trows = options.pieces ? Math.round( Math.sqrt( options.pieces ) ) : 3,\n\t\tcells = rows,\n\t\telement = $( this ),\n\t\tmode = options.mode,\n\t\tshow = mode === \"show\",\n\n\t\t// Show and then visibility:hidden the element before calculating offset\n\t\toffset = element.show().css( \"visibility\", \"hidden\" ).offset(),\n\n\t\t// Width and height of a piece\n\t\twidth = Math.ceil( element.outerWidth() / cells ),\n\t\theight = Math.ceil( element.outerHeight() / rows ),\n\t\tpieces = [];\n\n\t// Children animate complete:\n\tfunction childComplete() {\n\t\tpieces.push( this );\n\t\tif ( pieces.length === rows * cells ) {\n\t\t\tanimComplete();\n\t\t}\n\t}\n\n\t// Clone the element for each row and cell.\n\tfor ( i = 0; i < rows; i++ ) { // ===>\n\t\ttop = offset.top + i * height;\n\t\tmy = i - ( rows - 1 ) / 2;\n\n\t\tfor ( j = 0; j < cells; j++ ) { // |||\n\t\t\tleft = offset.left + j * width;\n\t\t\tmx = j - ( cells - 1 ) / 2;\n\n\t\t\t// Create a clone of the now hidden main element that will be absolute positioned\n\t\t\t// within a wrapper div off the -left and -top equal to size of our pieces\n\t\t\telement\n\t\t\t\t.clone()\n\t\t\t\t.appendTo( \"body\" )\n\t\t\t\t.wrap( \"<div></div>\" )\n\t\t\t\t.css( {\n\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\tvisibility: \"visible\",\n\t\t\t\t\tleft: -j * width,\n\t\t\t\t\ttop: -i * height\n\t\t\t\t} )\n\n\t\t\t\t// Select the wrapper - make it overflow: hidden and absolute positioned based on\n\t\t\t\t// where the original was located +left and +top equal to the size of pieces\n\t\t\t\t.parent()\n\t\t\t\t\t.addClass( \"ui-effects-explode\" )\n\t\t\t\t\t.css( {\n\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\toverflow: \"hidden\",\n\t\t\t\t\t\twidth: width,\n\t\t\t\t\t\theight: height,\n\t\t\t\t\t\tleft: left + ( show ? mx * width : 0 ),\n\t\t\t\t\t\ttop: top + ( show ? my * height : 0 ),\n\t\t\t\t\t\topacity: show ? 0 : 1\n\t\t\t\t\t} )\n\t\t\t\t\t.animate( {\n\t\t\t\t\t\tleft: left + ( show ? 0 : mx * width ),\n\t\t\t\t\t\ttop: top + ( show ? 0 : my * height ),\n\t\t\t\t\t\topacity: show ? 1 : 0\n\t\t\t\t\t}, options.duration || 500, options.easing, childComplete );\n\t\t}\n\t}\n\n\tfunction animComplete() {\n\t\telement.css( {\n\t\t\tvisibility: \"visible\"\n\t\t} );\n\t\t$( pieces ).remove();\n\t\tdone();\n\t}\n} );\n\n\n/*!\n * jQuery UI Effects Fade 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Fade Effect\n//>>group: Effects\n//>>description: Fades the element.\n//>>docs: http://api.jqueryui.com/fade-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectFade = $.effects.define( \"fade\", \"toggle\", function( options, done ) {\n\tvar show = options.mode === \"show\";\n\n\t$( this )\n\t\t.css( \"opacity\", show ? 0 : 1 )\n\t\t.animate( {\n\t\t\topacity: show ? 1 : 0\n\t\t}, {\n\t\t\tqueue: false,\n\t\t\tduration: options.duration,\n\t\t\teasing: options.easing,\n\t\t\tcomplete: done\n\t\t} );\n} );\n\n\n/*!\n * jQuery UI Effects Fold 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Fold Effect\n//>>group: Effects\n//>>description: Folds an element first horizontally and then vertically.\n//>>docs: http://api.jqueryui.com/fold-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectFold = $.effects.define( \"fold\", \"hide\", function( options, done ) {\n\n\t// Create element\n\tvar element = $( this ),\n\t\tmode = options.mode,\n\t\tshow = mode === \"show\",\n\t\thide = mode === \"hide\",\n\t\tsize = options.size || 15,\n\t\tpercent = /([0-9]+)%/.exec( size ),\n\t\thorizFirst = !!options.horizFirst,\n\t\tref = horizFirst ? [ \"right\", \"bottom\" ] : [ \"bottom\", \"right\" ],\n\t\tduration = options.duration / 2,\n\n\t\tplaceholder = $.effects.createPlaceholder( element ),\n\n\t\tstart = element.cssClip(),\n\t\tanimation1 = { clip: $.extend( {}, start ) },\n\t\tanimation2 = { clip: $.extend( {}, start ) },\n\n\t\tdistance = [ start[ ref[ 0 ] ], start[ ref[ 1 ] ] ],\n\n\t\tqueuelen = element.queue().length;\n\n\tif ( percent ) {\n\t\tsize = parseInt( percent[ 1 ], 10 ) / 100 * distance[ hide ? 0 : 1 ];\n\t}\n\tanimation1.clip[ ref[ 0 ] ] = size;\n\tanimation2.clip[ ref[ 0 ] ] = size;\n\tanimation2.clip[ ref[ 1 ] ] = 0;\n\n\tif ( show ) {\n\t\telement.cssClip( animation2.clip );\n\t\tif ( placeholder ) {\n\t\t\tplaceholder.css( $.effects.clipToBox( animation2 ) );\n\t\t}\n\n\t\tanimation2.clip = start;\n\t}\n\n\t// Animate\n\telement\n\t\t.queue( function( next ) {\n\t\t\tif ( placeholder ) {\n\t\t\t\tplaceholder\n\t\t\t\t\t.animate( $.effects.clipToBox( animation1 ), duration, options.easing )\n\t\t\t\t\t.animate( $.effects.clipToBox( animation2 ), duration, options.easing );\n\t\t\t}\n\n\t\t\tnext();\n\t\t} )\n\t\t.animate( animation1, duration, options.easing )\n\t\t.animate( animation2, duration, options.easing )\n\t\t.queue( done );\n\n\t$.effects.unshift( element, queuelen, 4 );\n} );\n\n\n/*!\n * jQuery UI Effects Highlight 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Highlight Effect\n//>>group: Effects\n//>>description: Highlights the background of an element in a defined color for a custom duration.\n//>>docs: http://api.jqueryui.com/highlight-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectHighlight = $.effects.define( \"highlight\", \"show\", function( options, done ) {\n\tvar element = $( this ),\n\t\tanimation = {\n\t\t\tbackgroundColor: element.css( \"backgroundColor\" )\n\t\t};\n\n\tif ( options.mode === \"hide\" ) {\n\t\tanimation.opacity = 0;\n\t}\n\n\t$.effects.saveStyle( element );\n\n\telement\n\t\t.css( {\n\t\t\tbackgroundImage: \"none\",\n\t\t\tbackgroundColor: options.color || \"#ffff99\"\n\t\t} )\n\t\t.animate( animation, {\n\t\t\tqueue: false,\n\t\t\tduration: options.duration,\n\t\t\teasing: options.easing,\n\t\t\tcomplete: done\n\t\t} );\n} );\n\n\n/*!\n * jQuery UI Effects Size 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Size Effect\n//>>group: Effects\n//>>description: Resize an element to a specified width and height.\n//>>docs: http://api.jqueryui.com/size-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectSize = $.effects.define( \"size\", function( options, done ) {\n\n\t// Create element\n\tvar baseline, factor, temp,\n\t\telement = $( this ),\n\n\t\t// Copy for children\n\t\tcProps = [ \"fontSize\" ],\n\t\tvProps = [ \"borderTopWidth\", \"borderBottomWidth\", \"paddingTop\", \"paddingBottom\" ],\n\t\thProps = [ \"borderLeftWidth\", \"borderRightWidth\", \"paddingLeft\", \"paddingRight\" ],\n\n\t\t// Set options\n\t\tmode = options.mode,\n\t\trestore = mode !== \"effect\",\n\t\tscale = options.scale || \"both\",\n\t\torigin = options.origin || [ \"middle\", \"center\" ],\n\t\tposition = element.css( \"position\" ),\n\t\tpos = element.position(),\n\t\toriginal = $.effects.scaledDimensions( element ),\n\t\tfrom = options.from || original,\n\t\tto = options.to || $.effects.scaledDimensions( element, 0 );\n\n\t$.effects.createPlaceholder( element );\n\n\tif ( mode === \"show\" ) {\n\t\ttemp = from;\n\t\tfrom = to;\n\t\tto = temp;\n\t}\n\n\t// Set scaling factor\n\tfactor = {\n\t\tfrom: {\n\t\t\ty: from.height / original.height,\n\t\t\tx: from.width / original.width\n\t\t},\n\t\tto: {\n\t\t\ty: to.height / original.height,\n\t\t\tx: to.width / original.width\n\t\t}\n\t};\n\n\t// Scale the css box\n\tif ( scale === \"box\" || scale === \"both\" ) {\n\n\t\t// Vertical props scaling\n\t\tif ( factor.from.y !== factor.to.y ) {\n\t\t\tfrom = $.effects.setTransition( element, vProps, factor.from.y, from );\n\t\t\tto = $.effects.setTransition( element, vProps, factor.to.y, to );\n\t\t}\n\n\t\t// Horizontal props scaling\n\t\tif ( factor.from.x !== factor.to.x ) {\n\t\t\tfrom = $.effects.setTransition( element, hProps, factor.from.x, from );\n\t\t\tto = $.effects.setTransition( element, hProps, factor.to.x, to );\n\t\t}\n\t}\n\n\t// Scale the content\n\tif ( scale === \"content\" || scale === \"both\" ) {\n\n\t\t// Vertical props scaling\n\t\tif ( factor.from.y !== factor.to.y ) {\n\t\t\tfrom = $.effects.setTransition( element, cProps, factor.from.y, from );\n\t\t\tto = $.effects.setTransition( element, cProps, factor.to.y, to );\n\t\t}\n\t}\n\n\t// Adjust the position properties based on the provided origin points\n\tif ( origin ) {\n\t\tbaseline = $.effects.getBaseline( origin, original );\n\t\tfrom.top = ( original.outerHeight - from.outerHeight ) * baseline.y + pos.top;\n\t\tfrom.left = ( original.outerWidth - from.outerWidth ) * baseline.x + pos.left;\n\t\tto.top = ( original.outerHeight - to.outerHeight ) * baseline.y + pos.top;\n\t\tto.left = ( original.outerWidth - to.outerWidth ) * baseline.x + pos.left;\n\t}\n\telement.css( from );\n\n\t// Animate the children if desired\n\tif ( scale === \"content\" || scale === \"both\" ) {\n\n\t\tvProps = vProps.concat( [ \"marginTop\", \"marginBottom\" ] ).concat( cProps );\n\t\thProps = hProps.concat( [ \"marginLeft\", \"marginRight\" ] );\n\n\t\t// Only animate children with width attributes specified\n\t\t// TODO: is this right? should we include anything with css width specified as well\n\t\telement.find( \"*[width]\" ).each( function() {\n\t\t\tvar child = $( this ),\n\t\t\t\tchildOriginal = $.effects.scaledDimensions( child ),\n\t\t\t\tchildFrom = {\n\t\t\t\t\theight: childOriginal.height * factor.from.y,\n\t\t\t\t\twidth: childOriginal.width * factor.from.x,\n\t\t\t\t\touterHeight: childOriginal.outerHeight * factor.from.y,\n\t\t\t\t\touterWidth: childOriginal.outerWidth * factor.from.x\n\t\t\t\t},\n\t\t\t\tchildTo = {\n\t\t\t\t\theight: childOriginal.height * factor.to.y,\n\t\t\t\t\twidth: childOriginal.width * factor.to.x,\n\t\t\t\t\touterHeight: childOriginal.height * factor.to.y,\n\t\t\t\t\touterWidth: childOriginal.width * factor.to.x\n\t\t\t\t};\n\n\t\t\t// Vertical props scaling\n\t\t\tif ( factor.from.y !== factor.to.y ) {\n\t\t\t\tchildFrom = $.effects.setTransition( child, vProps, factor.from.y, childFrom );\n\t\t\t\tchildTo = $.effects.setTransition( child, vProps, factor.to.y, childTo );\n\t\t\t}\n\n\t\t\t// Horizontal props scaling\n\t\t\tif ( factor.from.x !== factor.to.x ) {\n\t\t\t\tchildFrom = $.effects.setTransition( child, hProps, factor.from.x, childFrom );\n\t\t\t\tchildTo = $.effects.setTransition( child, hProps, factor.to.x, childTo );\n\t\t\t}\n\n\t\t\tif ( restore ) {\n\t\t\t\t$.effects.saveStyle( child );\n\t\t\t}\n\n\t\t\t// Animate children\n\t\t\tchild.css( childFrom );\n\t\t\tchild.animate( childTo, options.duration, options.easing, function() {\n\n\t\t\t\t// Restore children\n\t\t\t\tif ( restore ) {\n\t\t\t\t\t$.effects.restoreStyle( child );\n\t\t\t\t}\n\t\t\t} );\n\t\t} );\n\t}\n\n\t// Animate\n\telement.animate( to, {\n\t\tqueue: false,\n\t\tduration: options.duration,\n\t\teasing: options.easing,\n\t\tcomplete: function() {\n\n\t\t\tvar offset = element.offset();\n\n\t\t\tif ( to.opacity === 0 ) {\n\t\t\t\telement.css( \"opacity\", from.opacity );\n\t\t\t}\n\n\t\t\tif ( !restore ) {\n\t\t\t\telement\n\t\t\t\t\t.css( \"position\", position === \"static\" ? \"relative\" : position )\n\t\t\t\t\t.offset( offset );\n\n\t\t\t\t// Need to save style here so that automatic style restoration\n\t\t\t\t// doesn't restore to the original styles from before the animation.\n\t\t\t\t$.effects.saveStyle( element );\n\t\t\t}\n\n\t\t\tdone();\n\t\t}\n\t} );\n\n} );\n\n\n/*!\n * jQuery UI Effects Scale 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Scale Effect\n//>>group: Effects\n//>>description: Grows or shrinks an element and its content.\n//>>docs: http://api.jqueryui.com/scale-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectScale = $.effects.define( \"scale\", function( options, done ) {\n\n\t// Create element\n\tvar el = $( this ),\n\t\tmode = options.mode,\n\t\tpercent = parseInt( options.percent, 10 ) ||\n\t\t\t( parseInt( options.percent, 10 ) === 0 ? 0 : ( mode !== \"effect\" ? 0 : 100 ) ),\n\n\t\tnewOptions = $.extend( true, {\n\t\t\tfrom: $.effects.scaledDimensions( el ),\n\t\t\tto: $.effects.scaledDimensions( el, percent, options.direction || \"both\" ),\n\t\t\torigin: options.origin || [ \"middle\", \"center\" ]\n\t\t}, options );\n\n\t// Fade option to support puff\n\tif ( options.fade ) {\n\t\tnewOptions.from.opacity = 1;\n\t\tnewOptions.to.opacity = 0;\n\t}\n\n\t$.effects.effect.size.call( this, newOptions, done );\n} );\n\n\n/*!\n * jQuery UI Effects Puff 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Puff Effect\n//>>group: Effects\n//>>description: Creates a puff effect by scaling the element up and hiding it at the same time.\n//>>docs: http://api.jqueryui.com/puff-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectPuff = $.effects.define( \"puff\", \"hide\", function( options, done ) {\n\tvar newOptions = $.extend( true, {}, options, {\n\t\tfade: true,\n\t\tpercent: parseInt( options.percent, 10 ) || 150\n\t} );\n\n\t$.effects.effect.scale.call( this, newOptions, done );\n} );\n\n\n/*!\n * jQuery UI Effects Pulsate 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Pulsate Effect\n//>>group: Effects\n//>>description: Pulsates an element n times by changing the opacity to zero and back.\n//>>docs: http://api.jqueryui.com/pulsate-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectPulsate = $.effects.define( \"pulsate\", \"show\", function( options, done ) {\n\tvar element = $( this ),\n\t\tmode = options.mode,\n\t\tshow = mode === \"show\",\n\t\thide = mode === \"hide\",\n\t\tshowhide = show || hide,\n\n\t\t// Showing or hiding leaves off the \"last\" animation\n\t\tanims = ( ( options.times || 5 ) * 2 ) + ( showhide ? 1 : 0 ),\n\t\tduration = options.duration / anims,\n\t\tanimateTo = 0,\n\t\ti = 1,\n\t\tqueuelen = element.queue().length;\n\n\tif ( show || !element.is( \":visible\" ) ) {\n\t\telement.css( \"opacity\", 0 ).show();\n\t\tanimateTo = 1;\n\t}\n\n\t// Anims - 1 opacity \"toggles\"\n\tfor ( ; i < anims; i++ ) {\n\t\telement.animate( { opacity: animateTo }, duration, options.easing );\n\t\tanimateTo = 1 - animateTo;\n\t}\n\n\telement.animate( { opacity: animateTo }, duration, options.easing );\n\n\telement.queue( done );\n\n\t$.effects.unshift( element, queuelen, anims + 1 );\n} );\n\n\n/*!\n * jQuery UI Effects Shake 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Shake Effect\n//>>group: Effects\n//>>description: Shakes an element horizontally or vertically n times.\n//>>docs: http://api.jqueryui.com/shake-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectShake = $.effects.define( \"shake\", function( options, done ) {\n\n\tvar i = 1,\n\t\telement = $( this ),\n\t\tdirection = options.direction || \"left\",\n\t\tdistance = options.distance || 20,\n\t\ttimes = options.times || 3,\n\t\tanims = times * 2 + 1,\n\t\tspeed = Math.round( options.duration / anims ),\n\t\tref = ( direction === \"up\" || direction === \"down\" ) ? \"top\" : \"left\",\n\t\tpositiveMotion = ( direction === \"up\" || direction === \"left\" ),\n\t\tanimation = {},\n\t\tanimation1 = {},\n\t\tanimation2 = {},\n\n\t\tqueuelen = element.queue().length;\n\n\t$.effects.createPlaceholder( element );\n\n\t// Animation\n\tanimation[ ref ] = ( positiveMotion ? \"-=\" : \"+=\" ) + distance;\n\tanimation1[ ref ] = ( positiveMotion ? \"+=\" : \"-=\" ) + distance * 2;\n\tanimation2[ ref ] = ( positiveMotion ? \"-=\" : \"+=\" ) + distance * 2;\n\n\t// Animate\n\telement.animate( animation, speed, options.easing );\n\n\t// Shakes\n\tfor ( ; i < times; i++ ) {\n\t\telement\n\t\t\t.animate( animation1, speed, options.easing )\n\t\t\t.animate( animation2, speed, options.easing );\n\t}\n\n\telement\n\t\t.animate( animation1, speed, options.easing )\n\t\t.animate( animation, speed / 2, options.easing )\n\t\t.queue( done );\n\n\t$.effects.unshift( element, queuelen, anims + 1 );\n} );\n\n\n/*!\n * jQuery UI Effects Slide 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Slide Effect\n//>>group: Effects\n//>>description: Slides an element in and out of the viewport.\n//>>docs: http://api.jqueryui.com/slide-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effectsEffectSlide = $.effects.define( \"slide\", \"show\", function( options, done ) {\n\tvar startClip, startRef,\n\t\telement = $( this ),\n\t\tmap = {\n\t\t\tup: [ \"bottom\", \"top\" ],\n\t\t\tdown: [ \"top\", \"bottom\" ],\n\t\t\tleft: [ \"right\", \"left\" ],\n\t\t\tright: [ \"left\", \"right\" ]\n\t\t},\n\t\tmode = options.mode,\n\t\tdirection = options.direction || \"left\",\n\t\tref = ( direction === \"up\" || direction === \"down\" ) ? \"top\" : \"left\",\n\t\tpositiveMotion = ( direction === \"up\" || direction === \"left\" ),\n\t\tdistance = options.distance ||\n\t\t\telement[ ref === \"top\" ? \"outerHeight\" : \"outerWidth\" ]( true ),\n\t\tanimation = {};\n\n\t$.effects.createPlaceholder( element );\n\n\tstartClip = element.cssClip();\n\tstartRef = element.position()[ ref ];\n\n\t// Define hide animation\n\tanimation[ ref ] = ( positiveMotion ? -1 : 1 ) * distance + startRef;\n\tanimation.clip = element.cssClip();\n\tanimation.clip[ map[ direction ][ 1 ] ] = animation.clip[ map[ direction ][ 0 ] ];\n\n\t// Reverse the animation if we're showing\n\tif ( mode === \"show\" ) {\n\t\telement.cssClip( animation.clip );\n\t\telement.css( ref, animation[ ref ] );\n\t\tanimation.clip = startClip;\n\t\tanimation[ ref ] = startRef;\n\t}\n\n\t// Actually animate\n\telement.animate( animation, {\n\t\tqueue: false,\n\t\tduration: options.duration,\n\t\teasing: options.easing,\n\t\tcomplete: done\n\t} );\n} );\n\n\n/*!\n * jQuery UI Effects Transfer 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Transfer Effect\n//>>group: Effects\n//>>description: Displays a transfer effect from one element to another.\n//>>docs: http://api.jqueryui.com/transfer-effect/\n//>>demos: http://jqueryui.com/effect/\n\n\n\nvar effect;\nif ( $.uiBackCompat !== false ) {\n\teffect = $.effects.define( \"transfer\", function( options, done ) {\n\t\t$( this ).transfer( options, done );\n\t} );\n}\nvar effectsEffectTransfer = effect;\n\n\n/*!\n * jQuery UI Focusable 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: :focusable Selector\n//>>group: Core\n//>>description: Selects elements which can be focused.\n//>>docs: http://api.jqueryui.com/focusable-selector/\n\n\n\n// Selectors\n$.ui.focusable = function( element, hasTabindex ) {\n\tvar map, mapName, img, focusableIfVisible, fieldset,\n\t\tnodeName = element.nodeName.toLowerCase();\n\n\tif ( \"area\" === nodeName ) {\n\t\tmap = element.parentNode;\n\t\tmapName = map.name;\n\t\tif ( !element.href || !mapName || map.nodeName.toLowerCase() !== \"map\" ) {\n\t\t\treturn false;\n\t\t}\n\t\timg = $( \"img[usemap='#\" + mapName + \"']\" );\n\t\treturn img.length > 0 && img.is( \":visible\" );\n\t}\n\n\tif ( /^(input|select|textarea|button|object)$/.test( nodeName ) ) {\n\t\tfocusableIfVisible = !element.disabled;\n\n\t\tif ( focusableIfVisible ) {\n\n\t\t\t// Form controls within a disabled fieldset are disabled.\n\t\t\t// However, controls within the fieldset's legend do not get disabled.\n\t\t\t// Since controls generally aren't placed inside legends, we skip\n\t\t\t// this portion of the check.\n\t\t\tfieldset = $( element ).closest( \"fieldset\" )[ 0 ];\n\t\t\tif ( fieldset ) {\n\t\t\t\tfocusableIfVisible = !fieldset.disabled;\n\t\t\t}\n\t\t}\n\t} else if ( \"a\" === nodeName ) {\n\t\tfocusableIfVisible = element.href || hasTabindex;\n\t} else {\n\t\tfocusableIfVisible = hasTabindex;\n\t}\n\n\treturn focusableIfVisible && $( element ).is( \":visible\" ) && visible( $( element ) );\n};\n\n// Support: IE 8 only\n// IE 8 doesn't resolve inherit to visible/hidden for computed values\nfunction visible( element ) {\n\tvar visibility = element.css( \"visibility\" );\n\twhile ( visibility === \"inherit\" ) {\n\t\telement = element.parent();\n\t\tvisibility = element.css( \"visibility\" );\n\t}\n\treturn visibility !== \"hidden\";\n}\n\n$.extend( $.expr[ \":\" ], {\n\tfocusable: function( element ) {\n\t\treturn $.ui.focusable( element, $.attr( element, \"tabindex\" ) != null );\n\t}\n} );\n\nvar focusable = $.ui.focusable;\n\n\n\n\n// Support: IE8 Only\n// IE8 does not support the form attribute and when it is supplied. It overwrites the form prop\n// with a string, so we need to find the proper form.\nvar form = $.fn.form = function() {\n\treturn typeof this[ 0 ].form === \"string\" ? this.closest( \"form\" ) : $( this[ 0 ].form );\n};\n\n\n/*!\n * jQuery UI Form Reset Mixin 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Form Reset Mixin\n//>>group: Core\n//>>description: Refresh input widgets when their form is reset\n//>>docs: http://api.jqueryui.com/form-reset-mixin/\n\n\n\nvar formResetMixin = $.ui.formResetMixin = {\n\t_formResetHandler: function() {\n\t\tvar form = $( this );\n\n\t\t// Wait for the form reset to actually happen before refreshing\n\t\tsetTimeout( function() {\n\t\t\tvar instances = form.data( \"ui-form-reset-instances\" );\n\t\t\t$.each( instances, function() {\n\t\t\t\tthis.refresh();\n\t\t\t} );\n\t\t} );\n\t},\n\n\t_bindFormResetHandler: function() {\n\t\tthis.form = this.element.form();\n\t\tif ( !this.form.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar instances = this.form.data( \"ui-form-reset-instances\" ) || [];\n\t\tif ( !instances.length ) {\n\n\t\t\t// We don't use _on() here because we use a single event handler per form\n\t\t\tthis.form.on( \"reset.ui-form-reset\", this._formResetHandler );\n\t\t}\n\t\tinstances.push( this );\n\t\tthis.form.data( \"ui-form-reset-instances\", instances );\n\t},\n\n\t_unbindFormResetHandler: function() {\n\t\tif ( !this.form.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar instances = this.form.data( \"ui-form-reset-instances\" );\n\t\tinstances.splice( $.inArray( this, instances ), 1 );\n\t\tif ( instances.length ) {\n\t\t\tthis.form.data( \"ui-form-reset-instances\", instances );\n\t\t} else {\n\t\t\tthis.form\n\t\t\t\t.removeData( \"ui-form-reset-instances\" )\n\t\t\t\t.off( \"reset.ui-form-reset\" );\n\t\t}\n\t}\n};\n\n\n/*!\n * jQuery UI Support for jQuery core 1.7.x 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n *\n */\n\n//>>label: jQuery 1.7 Support\n//>>group: Core\n//>>description: Support version 1.7.x of jQuery core\n\n\n\n// Support: jQuery 1.7 only\n// Not a great way to check versions, but since we only support 1.7+ and only\n// need to detect <1.8, this is a simple check that should suffice. Checking\n// for \"1.7.\" would be a bit safer, but the version string is 1.7, not 1.7.0\n// and we'll never reach 1.70.0 (if we do, we certainly won't be supporting\n// 1.7 anymore). See #11197 for why we're not using feature detection.\nif ( $.fn.jquery.substring( 0, 3 ) === \"1.7\" ) {\n\n\t// Setters for .innerWidth(), .innerHeight(), .outerWidth(), .outerHeight()\n\t// Unlike jQuery Core 1.8+, these only support numeric values to set the\n\t// dimensions in pixels\n\t$.each( [ \"Width\", \"Height\" ], function( i, name ) {\n\t\tvar side = name === \"Width\" ? [ \"Left\", \"Right\" ] : [ \"Top\", \"Bottom\" ],\n\t\t\ttype = name.toLowerCase(),\n\t\t\torig = {\n\t\t\t\tinnerWidth: $.fn.innerWidth,\n\t\t\t\tinnerHeight: $.fn.innerHeight,\n\t\t\t\touterWidth: $.fn.outerWidth,\n\t\t\t\touterHeight: $.fn.outerHeight\n\t\t\t};\n\n\t\tfunction reduce( elem, size, border, margin ) {\n\t\t\t$.each( side, function() {\n\t\t\t\tsize -= parseFloat( $.css( elem, \"padding\" + this ) ) || 0;\n\t\t\t\tif ( border ) {\n\t\t\t\t\tsize -= parseFloat( $.css( elem, \"border\" + this + \"Width\" ) ) || 0;\n\t\t\t\t}\n\t\t\t\tif ( margin ) {\n\t\t\t\t\tsize -= parseFloat( $.css( elem, \"margin\" + this ) ) || 0;\n\t\t\t\t}\n\t\t\t} );\n\t\t\treturn size;\n\t\t}\n\n\t\t$.fn[ \"inner\" + name ] = function( size ) {\n\t\t\tif ( size === undefined ) {\n\t\t\t\treturn orig[ \"inner\" + name ].call( this );\n\t\t\t}\n\n\t\t\treturn this.each( function() {\n\t\t\t\t$( this ).css( type, reduce( this, size ) + \"px\" );\n\t\t\t} );\n\t\t};\n\n\t\t$.fn[ \"outer\" + name ] = function( size, margin ) {\n\t\t\tif ( typeof size !== \"number\" ) {\n\t\t\t\treturn orig[ \"outer\" + name ].call( this, size );\n\t\t\t}\n\n\t\t\treturn this.each( function() {\n\t\t\t\t$( this ).css( type, reduce( this, size, true, margin ) + \"px\" );\n\t\t\t} );\n\t\t};\n\t} );\n\n\t$.fn.addBack = function( selector ) {\n\t\treturn this.add( selector == null ?\n\t\t\tthis.prevObject : this.prevObject.filter( selector )\n\t\t);\n\t};\n}\n\n;\n/*!\n * jQuery UI Keycode 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Keycode\n//>>group: Core\n//>>description: Provide keycodes as keynames\n//>>docs: http://api.jqueryui.com/jQuery.ui.keyCode/\n\n\nvar keycode = $.ui.keyCode = {\n\tBACKSPACE: 8,\n\tCOMMA: 188,\n\tDELETE: 46,\n\tDOWN: 40,\n\tEND: 35,\n\tENTER: 13,\n\tESCAPE: 27,\n\tHOME: 36,\n\tLEFT: 37,\n\tPAGE_DOWN: 34,\n\tPAGE_UP: 33,\n\tPERIOD: 190,\n\tRIGHT: 39,\n\tSPACE: 32,\n\tTAB: 9,\n\tUP: 38\n};\n\n\n\n\n// Internal use only\nvar escapeSelector = $.ui.escapeSelector = ( function() {\n\tvar selectorEscape = /([!\"#$%&'()*+,./:;<=>?@[\\]^`{|}~])/g;\n\treturn function( selector ) {\n\t\treturn selector.replace( selectorEscape, \"\\\\$1\" );\n\t};\n} )();\n\n\n/*!\n * jQuery UI Labels 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: labels\n//>>group: Core\n//>>description: Find all the labels associated with a given input\n//>>docs: http://api.jqueryui.com/labels/\n\n\n\nvar labels = $.fn.labels = function() {\n\tvar ancestor, selector, id, labels, ancestors;\n\n\t// Check control.labels first\n\tif ( this[ 0 ].labels && this[ 0 ].labels.length ) {\n\t\treturn this.pushStack( this[ 0 ].labels );\n\t}\n\n\t// Support: IE <= 11, FF <= 37, Android <= 2.3 only\n\t// Above browsers do not support control.labels. Everything below is to support them\n\t// as well as document fragments. control.labels does not work on document fragments\n\tlabels = this.eq( 0 ).parents( \"label\" );\n\n\t// Look for the label based on the id\n\tid = this.attr( \"id\" );\n\tif ( id ) {\n\n\t\t// We don't search against the document in case the element\n\t\t// is disconnected from the DOM\n\t\tancestor = this.eq( 0 ).parents().last();\n\n\t\t// Get a full set of top level ancestors\n\t\tancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() );\n\n\t\t// Create a selector for the label based on the id\n\t\tselector = \"label[for='\" + $.ui.escapeSelector( id ) + \"']\";\n\n\t\tlabels = labels.add( ancestors.find( selector ).addBack( selector ) );\n\n\t}\n\n\t// Return whatever we have found for labels\n\treturn this.pushStack( labels );\n};\n\n\n/*!\n * jQuery UI Scroll Parent 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: scrollParent\n//>>group: Core\n//>>description: Get the closest ancestor element that is scrollable.\n//>>docs: http://api.jqueryui.com/scrollParent/\n\n\n\nvar scrollParent = $.fn.scrollParent = function( includeHidden ) {\n\tvar position = this.css( \"position\" ),\n\t\texcludeStaticParent = position === \"absolute\",\n\t\toverflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,\n\t\tscrollParent = this.parents().filter( function() {\n\t\t\tvar parent = $( this );\n\t\t\tif ( excludeStaticParent && parent.css( \"position\" ) === \"static\" ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn overflowRegex.test( parent.css( \"overflow\" ) + parent.css( \"overflow-y\" ) +\n\t\t\t\tparent.css( \"overflow-x\" ) );\n\t\t} ).eq( 0 );\n\n\treturn position === \"fixed\" || !scrollParent.length ?\n\t\t$( this[ 0 ].ownerDocument || document ) :\n\t\tscrollParent;\n};\n\n\n/*!\n * jQuery UI Tabbable 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: :tabbable Selector\n//>>group: Core\n//>>description: Selects elements which can be tabbed to.\n//>>docs: http://api.jqueryui.com/tabbable-selector/\n\n\n\nvar tabbable = $.extend( $.expr[ \":\" ], {\n\ttabbable: function( element ) {\n\t\tvar tabIndex = $.attr( element, \"tabindex\" ),\n\t\t\thasTabindex = tabIndex != null;\n\t\treturn ( !hasTabindex || tabIndex >= 0 ) && $.ui.focusable( element, hasTabindex );\n\t}\n} );\n\n\n/*!\n * jQuery UI Unique ID 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: uniqueId\n//>>group: Core\n//>>description: Functions to generate and remove uniqueId's\n//>>docs: http://api.jqueryui.com/uniqueId/\n\n\n\nvar uniqueId = $.fn.extend( {\n\tuniqueId: ( function() {\n\t\tvar uuid = 0;\n\n\t\treturn function() {\n\t\t\treturn this.each( function() {\n\t\t\t\tif ( !this.id ) {\n\t\t\t\t\tthis.id = \"ui-id-\" + ( ++uuid );\n\t\t\t\t}\n\t\t\t} );\n\t\t};\n\t} )(),\n\n\tremoveUniqueId: function() {\n\t\treturn this.each( function() {\n\t\t\tif ( /^ui-id-\\d+$/.test( this.id ) ) {\n\t\t\t\t$( this ).removeAttr( \"id\" );\n\t\t\t}\n\t\t} );\n\t}\n} );\n\n\n/*!\n * jQuery UI Accordion 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Accordion\n//>>group: Widgets\n// jscs:disable maximumLineLength\n//>>description: Displays collapsible content panels for presenting information in a limited amount of space.\n// jscs:enable maximumLineLength\n//>>docs: http://api.jqueryui.com/accordion/\n//>>demos: http://jqueryui.com/accordion/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/accordion.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\nvar widgetsAccordion = $.widget( \"ui.accordion\", {\n\tversion: \"1.12.1\",\n\toptions: {\n\t\tactive: 0,\n\t\tanimate: {},\n\t\tclasses: {\n\t\t\t\"ui-accordion-header\": \"ui-corner-top\",\n\t\t\t\"ui-accordion-header-collapsed\": \"ui-corner-all\",\n\t\t\t\"ui-accordion-content\": \"ui-corner-bottom\"\n\t\t},\n\t\tcollapsible: false,\n\t\tevent: \"click\",\n\t\theader: \"> li > :first-child, > :not(li):even\",\n\t\theightStyle: \"auto\",\n\t\ticons: {\n\t\t\tactiveHeader: \"ui-icon-triangle-1-s\",\n\t\t\theader: \"ui-icon-triangle-1-e\"\n\t\t},\n\n\t\t// Callbacks\n\t\tactivate: null,\n\t\tbeforeActivate: null\n\t},\n\n\thideProps: {\n\t\tborderTopWidth: \"hide\",\n\t\tborderBottomWidth: \"hide\",\n\t\tpaddingTop: \"hide\",\n\t\tpaddingBottom: \"hide\",\n\t\theight: \"hide\"\n\t},\n\n\tshowProps: {\n\t\tborderTopWidth: \"show\",\n\t\tborderBottomWidth: \"show\",\n\t\tpaddingTop: \"show\",\n\t\tpaddingBottom: \"show\",\n\t\theight: \"show\"\n\t},\n\n\t_create: function() {\n\t\tvar options = this.options;\n\n\t\tthis.prevShow = this.prevHide = $();\n\t\tthis._addClass( \"ui-accordion\", \"ui-widget ui-helper-reset\" );\n\t\tthis.element.attr( \"role\", \"tablist\" );\n\n\t\t// Don't allow collapsible: false and active: false / null\n\t\tif ( !options.collapsible && ( options.active === false || options.active == null ) ) {\n\t\t\toptions.active = 0;\n\t\t}\n\n\t\tthis._processPanels();\n\n\t\t// handle negative values\n\t\tif ( options.active < 0 ) {\n\t\t\toptions.active += this.headers.length;\n\t\t}\n\t\tthis._refresh();\n\t},\n\n\t_getCreateEventData: function() {\n\t\treturn {\n\t\t\theader: this.active,\n\t\t\tpanel: !this.active.length ? $() : this.active.next()\n\t\t};\n\t},\n\n\t_createIcons: function() {\n\t\tvar icon, children,\n\t\t\ticons = this.options.icons;\n\n\t\tif ( icons ) {\n\t\t\ticon = $( \"<span>\" );\n\t\t\tthis._addClass( icon, \"ui-accordion-header-icon\", \"ui-icon \" + icons.header );\n\t\t\ticon.prependTo( this.headers );\n\t\t\tchildren = this.active.children( \".ui-accordion-header-icon\" );\n\t\t\tthis._removeClass( children, icons.header )\n\t\t\t\t._addClass( children, null, icons.activeHeader )\n\t\t\t\t._addClass( this.headers, \"ui-accordion-icons\" );\n\t\t}\n\t},\n\n\t_destroyIcons: function() {\n\t\tthis._removeClass( this.headers, \"ui-accordion-icons\" );\n\t\tthis.headers.children( \".ui-accordion-header-icon\" ).remove();\n\t},\n\n\t_destroy: function() {\n\t\tvar contents;\n\n\t\t// Clean up main element\n\t\tthis.element.removeAttr( \"role\" );\n\n\t\t// Clean up headers\n\t\tthis.headers\n\t\t\t.removeAttr( \"role aria-expanded aria-selected aria-controls tabIndex\" )\n\t\t\t.removeUniqueId();\n\n\t\tthis._destroyIcons();\n\n\t\t// Clean up content panels\n\t\tcontents = this.headers.next()\n\t\t\t.css( \"display\", \"\" )\n\t\t\t.removeAttr( \"role aria-hidden aria-labelledby\" )\n\t\t\t.removeUniqueId();\n\n\t\tif ( this.options.heightStyle !== \"content\" ) {\n\t\t\tcontents.css( \"height\", \"\" );\n\t\t}\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tif ( key === \"active\" ) {\n\n\t\t\t// _activate() will handle invalid values and update this.options\n\t\t\tthis._activate( value );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( key === \"event\" ) {\n\t\t\tif ( this.options.event ) {\n\t\t\t\tthis._off( this.headers, this.options.event );\n\t\t\t}\n\t\t\tthis._setupEvents( value );\n\t\t}\n\n\t\tthis._super( key, value );\n\n\t\t// Setting collapsible: false while collapsed; open first panel\n\t\tif ( key === \"collapsible\" && !value && this.options.active === false ) {\n\t\t\tthis._activate( 0 );\n\t\t}\n\n\t\tif ( key === \"icons\" ) {\n\t\t\tthis._destroyIcons();\n\t\t\tif ( value ) {\n\t\t\t\tthis._createIcons();\n\t\t\t}\n\t\t}\n\t},\n\n\t_setOptionDisabled: function( value ) {\n\t\tthis._super( value );\n\n\t\tthis.element.attr( \"aria-disabled\", value );\n\n\t\t// Support: IE8 Only\n\t\t// #5332 / #6059 - opacity doesn't cascade to positioned elements in IE\n\t\t// so we need to add the disabled class to the headers and panels\n\t\tthis._toggleClass( null, \"ui-state-disabled\", !!value );\n\t\tthis._toggleClass( this.headers.add( this.headers.next() ), null, \"ui-state-disabled\",\n\t\t\t!!value );\n\t},\n\n\t_keydown: function( event ) {\n\t\tif ( event.altKey || event.ctrlKey ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar keyCode = $.ui.keyCode,\n\t\t\tlength = this.headers.length,\n\t\t\tcurrentIndex = this.headers.index( event.target ),\n\t\t\ttoFocus = false;\n\n\t\tswitch ( event.keyCode ) {\n\t\tcase keyCode.RIGHT:\n\t\tcase keyCode.DOWN:\n\t\t\ttoFocus = this.headers[ ( currentIndex + 1 ) % length ];\n\t\t\tbreak;\n\t\tcase keyCode.LEFT:\n\t\tcase keyCode.UP:\n\t\t\ttoFocus = this.headers[ ( currentIndex - 1 + length ) % length ];\n\t\t\tbreak;\n\t\tcase keyCode.SPACE:\n\t\tcase keyCode.ENTER:\n\t\t\tthis._eventHandler( event );\n\t\t\tbreak;\n\t\tcase keyCode.HOME:\n\t\t\ttoFocus = this.headers[ 0 ];\n\t\t\tbreak;\n\t\tcase keyCode.END:\n\t\t\ttoFocus = this.headers[ length - 1 ];\n\t\t\tbreak;\n\t\t}\n\n\t\tif ( toFocus ) {\n\t\t\t$( event.target ).attr( \"tabIndex\", -1 );\n\t\t\t$( toFocus ).attr( \"tabIndex\", 0 );\n\t\t\t$( toFocus ).trigger( \"focus\" );\n\t\t\tevent.preventDefault();\n\t\t}\n\t},\n\n\t_panelKeyDown: function( event ) {\n\t\tif ( event.keyCode === $.ui.keyCode.UP && event.ctrlKey ) {\n\t\t\t$( event.currentTarget ).prev().trigger( \"focus\" );\n\t\t}\n\t},\n\n\trefresh: function() {\n\t\tvar options = this.options;\n\t\tthis._processPanels();\n\n\t\t// Was collapsed or no panel\n\t\tif ( ( options.active === false && options.collapsible === true ) ||\n\t\t\t\t!this.headers.length ) {\n\t\t\toptions.active = false;\n\t\t\tthis.active = $();\n\n\t\t// active false only when collapsible is true\n\t\t} else if ( options.active === false ) {\n\t\t\tthis._activate( 0 );\n\n\t\t// was active, but active panel is gone\n\t\t} else if ( this.active.length && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {\n\n\t\t\t// all remaining panel are disabled\n\t\t\tif ( this.headers.length === this.headers.find( \".ui-state-disabled\" ).length ) {\n\t\t\t\toptions.active = false;\n\t\t\t\tthis.active = $();\n\n\t\t\t// activate previous panel\n\t\t\t} else {\n\t\t\t\tthis._activate( Math.max( 0, options.active - 1 ) );\n\t\t\t}\n\n\t\t// was active, active panel still exists\n\t\t} else {\n\n\t\t\t// make sure active index is correct\n\t\t\toptions.active = this.headers.index( this.active );\n\t\t}\n\n\t\tthis._destroyIcons();\n\n\t\tthis._refresh();\n\t},\n\n\t_processPanels: function() {\n\t\tvar prevHeaders = this.headers,\n\t\t\tprevPanels = this.panels;\n\n\t\tthis.headers = this.element.find( this.options.header );\n\t\tthis._addClass( this.headers, \"ui-accordion-header ui-accordion-header-collapsed\",\n\t\t\t\"ui-state-default\" );\n\n\t\tthis.panels = this.headers.next().filter( \":not(.ui-accordion-content-active)\" ).hide();\n\t\tthis._addClass( this.panels, \"ui-accordion-content\", \"ui-helper-reset ui-widget-content\" );\n\n\t\t// Avoid memory leaks (#10056)\n\t\tif ( prevPanels ) {\n\t\t\tthis._off( prevHeaders.not( this.headers ) );\n\t\t\tthis._off( prevPanels.not( this.panels ) );\n\t\t}\n\t},\n\n\t_refresh: function() {\n\t\tvar maxHeight,\n\t\t\toptions = this.options,\n\t\t\theightStyle = options.heightStyle,\n\t\t\tparent = this.element.parent();\n\n\t\tthis.active = this._findActive( options.active );\n\t\tthis._addClass( this.active, \"ui-accordion-header-active\", \"ui-state-active\" )\n\t\t\t._removeClass( this.active, \"ui-accordion-header-collapsed\" );\n\t\tthis._addClass( this.active.next(), \"ui-accordion-content-active\" );\n\t\tthis.active.next().show();\n\n\t\tthis.headers\n\t\t\t.attr( \"role\", \"tab\" )\n\t\t\t.each( function() {\n\t\t\t\tvar header = $( this ),\n\t\t\t\t\theaderId = header.uniqueId().attr( \"id\" ),\n\t\t\t\t\tpanel = header.next(),\n\t\t\t\t\tpanelId = panel.uniqueId().attr( \"id\" );\n\t\t\t\theader.attr( \"aria-controls\", panelId );\n\t\t\t\tpanel.attr( \"aria-labelledby\", headerId );\n\t\t\t} )\n\t\t\t.next()\n\t\t\t\t.attr( \"role\", \"tabpanel\" );\n\n\t\tthis.headers\n\t\t\t.not( this.active )\n\t\t\t\t.attr( {\n\t\t\t\t\t\"aria-selected\": \"false\",\n\t\t\t\t\t\"aria-expanded\": \"false\",\n\t\t\t\t\ttabIndex: -1\n\t\t\t\t} )\n\t\t\t\t.next()\n\t\t\t\t\t.attr( {\n\t\t\t\t\t\t\"aria-hidden\": \"true\"\n\t\t\t\t\t} )\n\t\t\t\t\t.hide();\n\n\t\t// Make sure at least one header is in the tab order\n\t\tif ( !this.active.length ) {\n\t\t\tthis.headers.eq( 0 ).attr( \"tabIndex\", 0 );\n\t\t} else {\n\t\t\tthis.active.attr( {\n\t\t\t\t\"aria-selected\": \"true\",\n\t\t\t\t\"aria-expanded\": \"true\",\n\t\t\t\ttabIndex: 0\n\t\t\t} )\n\t\t\t\t.next()\n\t\t\t\t\t.attr( {\n\t\t\t\t\t\t\"aria-hidden\": \"false\"\n\t\t\t\t\t} );\n\t\t}\n\n\t\tthis._createIcons();\n\n\t\tthis._setupEvents( options.event );\n\n\t\tif ( heightStyle === \"fill\" ) {\n\t\t\tmaxHeight = parent.height();\n\t\t\tthis.element.siblings( \":visible\" ).each( function() {\n\t\t\t\tvar elem = $( this ),\n\t\t\t\t\tposition = elem.css( \"position\" );\n\n\t\t\t\tif ( position === \"absolute\" || position === \"fixed\" ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tmaxHeight -= elem.outerHeight( true );\n\t\t\t} );\n\n\t\t\tthis.headers.each( function() {\n\t\t\t\tmaxHeight -= $( this ).outerHeight( true );\n\t\t\t} );\n\n\t\t\tthis.headers.next()\n\t\t\t\t.each( function() {\n\t\t\t\t\t$( this ).height( Math.max( 0, maxHeight -\n\t\t\t\t\t\t$( this ).innerHeight() + $( this ).height() ) );\n\t\t\t\t} )\n\t\t\t\t.css( \"overflow\", \"auto\" );\n\t\t} else if ( heightStyle === \"auto\" ) {\n\t\t\tmaxHeight = 0;\n\t\t\tthis.headers.next()\n\t\t\t\t.each( function() {\n\t\t\t\t\tvar isVisible = $( this ).is( \":visible\" );\n\t\t\t\t\tif ( !isVisible ) {\n\t\t\t\t\t\t$( this ).show();\n\t\t\t\t\t}\n\t\t\t\t\tmaxHeight = Math.max( maxHeight, $( this ).css( \"height\", \"\" ).height() );\n\t\t\t\t\tif ( !isVisible ) {\n\t\t\t\t\t\t$( this ).hide();\n\t\t\t\t\t}\n\t\t\t\t} )\n\t\t\t\t.height( maxHeight );\n\t\t}\n\t},\n\n\t_activate: function( index ) {\n\t\tvar active = this._findActive( index )[ 0 ];\n\n\t\t// Trying to activate the already active panel\n\t\tif ( active === this.active[ 0 ] ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Trying to collapse, simulate a click on the currently active header\n\t\tactive = active || this.active[ 0 ];\n\n\t\tthis._eventHandler( {\n\t\t\ttarget: active,\n\t\t\tcurrentTarget: active,\n\t\t\tpreventDefault: $.noop\n\t\t} );\n\t},\n\n\t_findActive: function( selector ) {\n\t\treturn typeof selector === \"number\" ? this.headers.eq( selector ) : $();\n\t},\n\n\t_setupEvents: function( event ) {\n\t\tvar events = {\n\t\t\tkeydown: \"_keydown\"\n\t\t};\n\t\tif ( event ) {\n\t\t\t$.each( event.split( \" \" ), function( index, eventName ) {\n\t\t\t\tevents[ eventName ] = \"_eventHandler\";\n\t\t\t} );\n\t\t}\n\n\t\tthis._off( this.headers.add( this.headers.next() ) );\n\t\tthis._on( this.headers, events );\n\t\tthis._on( this.headers.next(), { keydown: \"_panelKeyDown\" } );\n\t\tthis._hoverable( this.headers );\n\t\tthis._focusable( this.headers );\n\t},\n\n\t_eventHandler: function( event ) {\n\t\tvar activeChildren, clickedChildren,\n\t\t\toptions = this.options,\n\t\t\tactive = this.active,\n\t\t\tclicked = $( event.currentTarget ),\n\t\t\tclickedIsActive = clicked[ 0 ] === active[ 0 ],\n\t\t\tcollapsing = clickedIsActive && options.collapsible,\n\t\t\ttoShow = collapsing ? $() : clicked.next(),\n\t\t\ttoHide = active.next(),\n\t\t\teventData = {\n\t\t\t\toldHeader: active,\n\t\t\t\toldPanel: toHide,\n\t\t\t\tnewHeader: collapsing ? $() : clicked,\n\t\t\t\tnewPanel: toShow\n\t\t\t};\n\n\t\tevent.preventDefault();\n\n\t\tif (\n\n\t\t\t\t// click on active header, but not collapsible\n\t\t\t\t( clickedIsActive && !options.collapsible ) ||\n\n\t\t\t\t// allow canceling activation\n\t\t\t\t( this._trigger( \"beforeActivate\", event, eventData ) === false ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\toptions.active = collapsing ? false : this.headers.index( clicked );\n\n\t\t// When the call to ._toggle() comes after the class changes\n\t\t// it causes a very odd bug in IE 8 (see #6720)\n\t\tthis.active = clickedIsActive ? $() : clicked;\n\t\tthis._toggle( eventData );\n\n\t\t// Switch classes\n\t\t// corner classes on the previously active header stay after the animation\n\t\tthis._removeClass( active, \"ui-accordion-header-active\", \"ui-state-active\" );\n\t\tif ( options.icons ) {\n\t\t\tactiveChildren = active.children( \".ui-accordion-header-icon\" );\n\t\t\tthis._removeClass( activeChildren, null, options.icons.activeHeader )\n\t\t\t\t._addClass( activeChildren, null, options.icons.header );\n\t\t}\n\n\t\tif ( !clickedIsActive ) {\n\t\t\tthis._removeClass( clicked, \"ui-accordion-header-collapsed\" )\n\t\t\t\t._addClass( clicked, \"ui-accordion-header-active\", \"ui-state-active\" );\n\t\t\tif ( options.icons ) {\n\t\t\t\tclickedChildren = clicked.children( \".ui-accordion-header-icon\" );\n\t\t\t\tthis._removeClass( clickedChildren, null, options.icons.header )\n\t\t\t\t\t._addClass( clickedChildren, null, options.icons.activeHeader );\n\t\t\t}\n\n\t\t\tthis._addClass( clicked.next(), \"ui-accordion-content-active\" );\n\t\t}\n\t},\n\n\t_toggle: function( data ) {\n\t\tvar toShow = data.newPanel,\n\t\t\ttoHide = this.prevShow.length ? this.prevShow : data.oldPanel;\n\n\t\t// Handle activating a panel during the animation for another activation\n\t\tthis.prevShow.add( this.prevHide ).stop( true, true );\n\t\tthis.prevShow = toShow;\n\t\tthis.prevHide = toHide;\n\n\t\tif ( this.options.animate ) {\n\t\t\tthis._animate( toShow, toHide, data );\n\t\t} else {\n\t\t\ttoHide.hide();\n\t\t\ttoShow.show();\n\t\t\tthis._toggleComplete( data );\n\t\t}\n\n\t\ttoHide.attr( {\n\t\t\t\"aria-hidden\": \"true\"\n\t\t} );\n\t\ttoHide.prev().attr( {\n\t\t\t\"aria-selected\": \"false\",\n\t\t\t\"aria-expanded\": \"false\"\n\t\t} );\n\n\t\t// if we're switching panels, remove the old header from the tab order\n\t\t// if we're opening from collapsed state, remove the previous header from the tab order\n\t\t// if we're collapsing, then keep the collapsing header in the tab order\n\t\tif ( toShow.length && toHide.length ) {\n\t\t\ttoHide.prev().attr( {\n\t\t\t\t\"tabIndex\": -1,\n\t\t\t\t\"aria-expanded\": \"false\"\n\t\t\t} );\n\t\t} else if ( toShow.length ) {\n\t\t\tthis.headers.filter( function() {\n\t\t\t\treturn parseInt( $( this ).attr( \"tabIndex\" ), 10 ) === 0;\n\t\t\t} )\n\t\t\t\t.attr( \"tabIndex\", -1 );\n\t\t}\n\n\t\ttoShow\n\t\t\t.attr( \"aria-hidden\", \"false\" )\n\t\t\t.prev()\n\t\t\t\t.attr( {\n\t\t\t\t\t\"aria-selected\": \"true\",\n\t\t\t\t\t\"aria-expanded\": \"true\",\n\t\t\t\t\ttabIndex: 0\n\t\t\t\t} );\n\t},\n\n\t_animate: function( toShow, toHide, data ) {\n\t\tvar total, easing, duration,\n\t\t\tthat = this,\n\t\t\tadjust = 0,\n\t\t\tboxSizing = toShow.css( \"box-sizing\" ),\n\t\t\tdown = toShow.length &&\n\t\t\t\t( !toHide.length || ( toShow.index() < toHide.index() ) ),\n\t\t\tanimate = this.options.animate || {},\n\t\t\toptions = down && animate.down || animate,\n\t\t\tcomplete = function() {\n\t\t\t\tthat._toggleComplete( data );\n\t\t\t};\n\n\t\tif ( typeof options === \"number\" ) {\n\t\t\tduration = options;\n\t\t}\n\t\tif ( typeof options === \"string\" ) {\n\t\t\teasing = options;\n\t\t}\n\n\t\t// fall back from options to animation in case of partial down settings\n\t\teasing = easing || options.easing || animate.easing;\n\t\tduration = duration || options.duration || animate.duration;\n\n\t\tif ( !toHide.length ) {\n\t\t\treturn toShow.animate( this.showProps, duration, easing, complete );\n\t\t}\n\t\tif ( !toShow.length ) {\n\t\t\treturn toHide.animate( this.hideProps, duration, easing, complete );\n\t\t}\n\n\t\ttotal = toShow.show().outerHeight();\n\t\ttoHide.animate( this.hideProps, {\n\t\t\tduration: duration,\n\t\t\teasing: easing,\n\t\t\tstep: function( now, fx ) {\n\t\t\t\tfx.now = Math.round( now );\n\t\t\t}\n\t\t} );\n\t\ttoShow\n\t\t\t.hide()\n\t\t\t.animate( this.showProps, {\n\t\t\t\tduration: duration,\n\t\t\t\teasing: easing,\n\t\t\t\tcomplete: complete,\n\t\t\t\tstep: function( now, fx ) {\n\t\t\t\t\tfx.now = Math.round( now );\n\t\t\t\t\tif ( fx.prop !== \"height\" ) {\n\t\t\t\t\t\tif ( boxSizing === \"content-box\" ) {\n\t\t\t\t\t\t\tadjust += fx.now;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if ( that.options.heightStyle !== \"content\" ) {\n\t\t\t\t\t\tfx.now = Math.round( total - toHide.outerHeight() - adjust );\n\t\t\t\t\t\tadjust = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\t},\n\n\t_toggleComplete: function( data ) {\n\t\tvar toHide = data.oldPanel,\n\t\t\tprev = toHide.prev();\n\n\t\tthis._removeClass( toHide, \"ui-accordion-content-active\" );\n\t\tthis._removeClass( prev, \"ui-accordion-header-active\" )\n\t\t\t._addClass( prev, \"ui-accordion-header-collapsed\" );\n\n\t\t// Work around for rendering bug in IE (#5421)\n\t\tif ( toHide.length ) {\n\t\t\ttoHide.parent()[ 0 ].className = toHide.parent()[ 0 ].className;\n\t\t}\n\t\tthis._trigger( \"activate\", null, data );\n\t}\n} );\n\n\n\nvar safeActiveElement = $.ui.safeActiveElement = function( document ) {\n\tvar activeElement;\n\n\t// Support: IE 9 only\n\t// IE9 throws an \"Unspecified error\" accessing document.activeElement from an <iframe>\n\ttry {\n\t\tactiveElement = document.activeElement;\n\t} catch ( error ) {\n\t\tactiveElement = document.body;\n\t}\n\n\t// Support: IE 9 - 11 only\n\t// IE may return null instead of an element\n\t// Interestingly, this only seems to occur when NOT in an iframe\n\tif ( !activeElement ) {\n\t\tactiveElement = document.body;\n\t}\n\n\t// Support: IE 11 only\n\t// IE11 returns a seemingly empty object in some cases when accessing\n\t// document.activeElement from an <iframe>\n\tif ( !activeElement.nodeName ) {\n\t\tactiveElement = document.body;\n\t}\n\n\treturn activeElement;\n};\n\n\n/*!\n * jQuery UI Menu 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Menu\n//>>group: Widgets\n//>>description: Creates nestable menus.\n//>>docs: http://api.jqueryui.com/menu/\n//>>demos: http://jqueryui.com/menu/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/menu.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\nvar widgetsMenu = $.widget( \"ui.menu\", {\n\tversion: \"1.12.1\",\n\tdefaultElement: \"<ul>\",\n\tdelay: 300,\n\toptions: {\n\t\ticons: {\n\t\t\tsubmenu: \"ui-icon-caret-1-e\"\n\t\t},\n\t\titems: \"> *\",\n\t\tmenus: \"ul\",\n\t\tposition: {\n\t\t\tmy: \"left top\",\n\t\t\tat: \"right top\"\n\t\t},\n\t\trole: \"menu\",\n\n\t\t// Callbacks\n\t\tblur: null,\n\t\tfocus: null,\n\t\tselect: null\n\t},\n\n\t_create: function() {\n\t\tthis.activeMenu = this.element;\n\n\t\t// Flag used to prevent firing of the click handler\n\t\t// as the event bubbles up through nested menus\n\t\tthis.mouseHandled = false;\n\t\tthis.element\n\t\t\t.uniqueId()\n\t\t\t.attr( {\n\t\t\t\trole: this.options.role,\n\t\t\t\ttabIndex: 0\n\t\t\t} );\n\n\t\tthis._addClass( \"ui-menu\", \"ui-widget ui-widget-content\" );\n\t\tthis._on( {\n\n\t\t\t// Prevent focus from sticking to links inside menu after clicking\n\t\t\t// them (focus should always stay on UL during navigation).\n\t\t\t\"mousedown .ui-menu-item\": function( event ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t},\n\t\t\t\"click .ui-menu-item\": function( event ) {\n\t\t\t\tvar target = $( event.target );\n\t\t\t\tvar active = $( $.ui.safeActiveElement( this.document[ 0 ] ) );\n\t\t\t\tif ( !this.mouseHandled && target.not( \".ui-state-disabled\" ).length ) {\n\t\t\t\t\tthis.select( event );\n\n\t\t\t\t\t// Only set the mouseHandled flag if the event will bubble, see #9469.\n\t\t\t\t\tif ( !event.isPropagationStopped() ) {\n\t\t\t\t\t\tthis.mouseHandled = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Open submenu on click\n\t\t\t\t\tif ( target.has( \".ui-menu\" ).length ) {\n\t\t\t\t\t\tthis.expand( event );\n\t\t\t\t\t} else if ( !this.element.is( \":focus\" ) &&\n\t\t\t\t\t\t\tactive.closest( \".ui-menu\" ).length ) {\n\n\t\t\t\t\t\t// Redirect focus to the menu\n\t\t\t\t\t\tthis.element.trigger( \"focus\", [ true ] );\n\n\t\t\t\t\t\t// If the active item is on the top level, let it stay active.\n\t\t\t\t\t\t// Otherwise, blur the active item since it is no longer visible.\n\t\t\t\t\t\tif ( this.active && this.active.parents( \".ui-menu\" ).length === 1 ) {\n\t\t\t\t\t\t\tclearTimeout( this.timer );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"mouseenter .ui-menu-item\": function( event ) {\n\n\t\t\t\t// Ignore mouse events while typeahead is active, see #10458.\n\t\t\t\t// Prevents focusing the wrong item when typeahead causes a scroll while the mouse\n\t\t\t\t// is over an item in the menu\n\t\t\t\tif ( this.previousFilter ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tvar actualTarget = $( event.target ).closest( \".ui-menu-item\" ),\n\t\t\t\t\ttarget = $( event.currentTarget );\n\n\t\t\t\t// Ignore bubbled events on parent items, see #11641\n\t\t\t\tif ( actualTarget[ 0 ] !== target[ 0 ] ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Remove ui-state-active class from siblings of the newly focused menu item\n\t\t\t\t// to avoid a jump caused by adjacent elements both having a class with a border\n\t\t\t\tthis._removeClass( target.siblings().children( \".ui-state-active\" ),\n\t\t\t\t\tnull, \"ui-state-active\" );\n\t\t\t\tthis.focus( event, target );\n\t\t\t},\n\t\t\tmouseleave: \"collapseAll\",\n\t\t\t\"mouseleave .ui-menu\": \"collapseAll\",\n\t\t\tfocus: function( event, keepActiveItem ) {\n\n\t\t\t\t// If there's already an active item, keep it active\n\t\t\t\t// If not, activate the first item\n\t\t\t\tvar item = this.active || this.element.find( this.options.items ).eq( 0 );\n\n\t\t\t\tif ( !keepActiveItem ) {\n\t\t\t\t\tthis.focus( event, item );\n\t\t\t\t}\n\t\t\t},\n\t\t\tblur: function( event ) {\n\t\t\t\tthis._delay( function() {\n\t\t\t\t\tvar notContained = !$.contains(\n\t\t\t\t\t\tthis.element[ 0 ],\n\t\t\t\t\t\t$.ui.safeActiveElement( this.document[ 0 ] )\n\t\t\t\t\t);\n\t\t\t\t\tif ( notContained ) {\n\t\t\t\t\t\tthis.collapseAll( event );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\tkeydown: \"_keydown\"\n\t\t} );\n\n\t\tthis.refresh();\n\n\t\t// Clicks outside of a menu collapse any open menus\n\t\tthis._on( this.document, {\n\t\t\tclick: function( event ) {\n\t\t\t\tif ( this._closeOnDocumentClick( event ) ) {\n\t\t\t\t\tthis.collapseAll( event );\n\t\t\t\t}\n\n\t\t\t\t// Reset the mouseHandled flag\n\t\t\t\tthis.mouseHandled = false;\n\t\t\t}\n\t\t} );\n\t},\n\n\t_destroy: function() {\n\t\tvar items = this.element.find( \".ui-menu-item\" )\n\t\t\t\t.removeAttr( \"role aria-disabled\" ),\n\t\t\tsubmenus = items.children( \".ui-menu-item-wrapper\" )\n\t\t\t\t.removeUniqueId()\n\t\t\t\t.removeAttr( \"tabIndex role aria-haspopup\" );\n\n\t\t// Destroy (sub)menus\n\t\tthis.element\n\t\t\t.removeAttr( \"aria-activedescendant\" )\n\t\t\t.find( \".ui-menu\" ).addBack()\n\t\t\t\t.removeAttr( \"role aria-labelledby aria-expanded aria-hidden aria-disabled \" +\n\t\t\t\t\t\"tabIndex\" )\n\t\t\t\t.removeUniqueId()\n\t\t\t\t.show();\n\n\t\tsubmenus.children().each( function() {\n\t\t\tvar elem = $( this );\n\t\t\tif ( elem.data( \"ui-menu-submenu-caret\" ) ) {\n\t\t\t\telem.remove();\n\t\t\t}\n\t\t} );\n\t},\n\n\t_keydown: function( event ) {\n\t\tvar match, prev, character, skip,\n\t\t\tpreventDefault = true;\n\n\t\tswitch ( event.keyCode ) {\n\t\tcase $.ui.keyCode.PAGE_UP:\n\t\t\tthis.previousPage( event );\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.PAGE_DOWN:\n\t\t\tthis.nextPage( event );\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.HOME:\n\t\t\tthis._move( \"first\", \"first\", event );\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.END:\n\t\t\tthis._move( \"last\", \"last\", event );\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.UP:\n\t\t\tthis.previous( event );\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.DOWN:\n\t\t\tthis.next( event );\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.LEFT:\n\t\t\tthis.collapse( event );\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.RIGHT:\n\t\t\tif ( this.active && !this.active.is( \".ui-state-disabled\" ) ) {\n\t\t\t\tthis.expand( event );\n\t\t\t}\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.ENTER:\n\t\tcase $.ui.keyCode.SPACE:\n\t\t\tthis._activate( event );\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.ESCAPE:\n\t\t\tthis.collapse( event );\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tpreventDefault = false;\n\t\t\tprev = this.previousFilter || \"\";\n\t\t\tskip = false;\n\n\t\t\t// Support number pad values\n\t\t\tcharacter = event.keyCode >= 96 && event.keyCode <= 105 ?\n\t\t\t\t( event.keyCode - 96 ).toString() : String.fromCharCode( event.keyCode );\n\n\t\t\tclearTimeout( this.filterTimer );\n\n\t\t\tif ( character === prev ) {\n\t\t\t\tskip = true;\n\t\t\t} else {\n\t\t\t\tcharacter = prev + character;\n\t\t\t}\n\n\t\t\tmatch = this._filterMenuItems( character );\n\t\t\tmatch = skip && match.index( this.active.next() ) !== -1 ?\n\t\t\t\tthis.active.nextAll( \".ui-menu-item\" ) :\n\t\t\t\tmatch;\n\n\t\t\t// If no matches on the current filter, reset to the last character pressed\n\t\t\t// to move down the menu to the first item that starts with that character\n\t\t\tif ( !match.length ) {\n\t\t\t\tcharacter = String.fromCharCode( event.keyCode );\n\t\t\t\tmatch = this._filterMenuItems( character );\n\t\t\t}\n\n\t\t\tif ( match.length ) {\n\t\t\t\tthis.focus( event, match );\n\t\t\t\tthis.previousFilter = character;\n\t\t\t\tthis.filterTimer = this._delay( function() {\n\t\t\t\t\tdelete this.previousFilter;\n\t\t\t\t}, 1000 );\n\t\t\t} else {\n\t\t\t\tdelete this.previousFilter;\n\t\t\t}\n\t\t}\n\n\t\tif ( preventDefault ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t},\n\n\t_activate: function( event ) {\n\t\tif ( this.active && !this.active.is( \".ui-state-disabled\" ) ) {\n\t\t\tif ( this.active.children( \"[aria-haspopup='true']\" ).length ) {\n\t\t\t\tthis.expand( event );\n\t\t\t} else {\n\t\t\t\tthis.select( event );\n\t\t\t}\n\t\t}\n\t},\n\n\trefresh: function() {\n\t\tvar menus, items, newSubmenus, newItems, newWrappers,\n\t\t\tthat = this,\n\t\t\ticon = this.options.icons.submenu,\n\t\t\tsubmenus = this.element.find( this.options.menus );\n\n\t\tthis._toggleClass( \"ui-menu-icons\", null, !!this.element.find( \".ui-icon\" ).length );\n\n\t\t// Initialize nested menus\n\t\tnewSubmenus = submenus.filter( \":not(.ui-menu)\" )\n\t\t\t.hide()\n\t\t\t.attr( {\n\t\t\t\trole: this.options.role,\n\t\t\t\t\"aria-hidden\": \"true\",\n\t\t\t\t\"aria-expanded\": \"false\"\n\t\t\t} )\n\t\t\t.each( function() {\n\t\t\t\tvar menu = $( this ),\n\t\t\t\t\titem = menu.prev(),\n\t\t\t\t\tsubmenuCaret = $( \"<span>\" ).data( \"ui-menu-submenu-caret\", true );\n\n\t\t\t\tthat._addClass( submenuCaret, \"ui-menu-icon\", \"ui-icon \" + icon );\n\t\t\t\titem\n\t\t\t\t\t.attr( \"aria-haspopup\", \"true\" )\n\t\t\t\t\t.prepend( submenuCaret );\n\t\t\t\tmenu.attr( \"aria-labelledby\", item.attr( \"id\" ) );\n\t\t\t} );\n\n\t\tthis._addClass( newSubmenus, \"ui-menu\", \"ui-widget ui-widget-content ui-front\" );\n\n\t\tmenus = submenus.add( this.element );\n\t\titems = menus.find( this.options.items );\n\n\t\t// Initialize menu-items containing spaces and/or dashes only as dividers\n\t\titems.not( \".ui-menu-item\" ).each( function() {\n\t\t\tvar item = $( this );\n\t\t\tif ( that._isDivider( item ) ) {\n\t\t\t\tthat._addClass( item, \"ui-menu-divider\", \"ui-widget-content\" );\n\t\t\t}\n\t\t} );\n\n\t\t// Don't refresh list items that are already adapted\n\t\tnewItems = items.not( \".ui-menu-item, .ui-menu-divider\" );\n\t\tnewWrappers = newItems.children()\n\t\t\t.not( \".ui-menu\" )\n\t\t\t\t.uniqueId()\n\t\t\t\t.attr( {\n\t\t\t\t\ttabIndex: -1,\n\t\t\t\t\trole: this._itemRole()\n\t\t\t\t} );\n\t\tthis._addClass( newItems, \"ui-menu-item\" )\n\t\t\t._addClass( newWrappers, \"ui-menu-item-wrapper\" );\n\n\t\t// Add aria-disabled attribute to any disabled menu item\n\t\titems.filter( \".ui-state-disabled\" ).attr( \"aria-disabled\", \"true\" );\n\n\t\t// If the active item has been removed, blur the menu\n\t\tif ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {\n\t\t\tthis.blur();\n\t\t}\n\t},\n\n\t_itemRole: function() {\n\t\treturn {\n\t\t\tmenu: \"menuitem\",\n\t\t\tlistbox: \"option\"\n\t\t}[ this.options.role ];\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tif ( key === \"icons\" ) {\n\t\t\tvar icons = this.element.find( \".ui-menu-icon\" );\n\t\t\tthis._removeClass( icons, null, this.options.icons.submenu )\n\t\t\t\t._addClass( icons, null, value.submenu );\n\t\t}\n\t\tthis._super( key, value );\n\t},\n\n\t_setOptionDisabled: function( value ) {\n\t\tthis._super( value );\n\n\t\tthis.element.attr( \"aria-disabled\", String( value ) );\n\t\tthis._toggleClass( null, \"ui-state-disabled\", !!value );\n\t},\n\n\tfocus: function( event, item ) {\n\t\tvar nested, focused, activeParent;\n\t\tthis.blur( event, event && event.type === \"focus\" );\n\n\t\tthis._scrollIntoView( item );\n\n\t\tthis.active = item.first();\n\n\t\tfocused = this.active.children( \".ui-menu-item-wrapper\" );\n\t\tthis._addClass( focused, null, \"ui-state-active\" );\n\n\t\t// Only update aria-activedescendant if there's a role\n\t\t// otherwise we assume focus is managed elsewhere\n\t\tif ( this.options.role ) {\n\t\t\tthis.element.attr( \"aria-activedescendant\", focused.attr( \"id\" ) );\n\t\t}\n\n\t\t// Highlight active parent menu item, if any\n\t\tactiveParent = this.active\n\t\t\t.parent()\n\t\t\t\t.closest( \".ui-menu-item\" )\n\t\t\t\t\t.children( \".ui-menu-item-wrapper\" );\n\t\tthis._addClass( activeParent, null, \"ui-state-active\" );\n\n\t\tif ( event && event.type === \"keydown\" ) {\n\t\t\tthis._close();\n\t\t} else {\n\t\t\tthis.timer = this._delay( function() {\n\t\t\t\tthis._close();\n\t\t\t}, this.delay );\n\t\t}\n\n\t\tnested = item.children( \".ui-menu\" );\n\t\tif ( nested.length && event && ( /^mouse/.test( event.type ) ) ) {\n\t\t\tthis._startOpening( nested );\n\t\t}\n\t\tthis.activeMenu = item.parent();\n\n\t\tthis._trigger( \"focus\", event, { item: item } );\n\t},\n\n\t_scrollIntoView: function( item ) {\n\t\tvar borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;\n\t\tif ( this._hasScroll() ) {\n\t\t\tborderTop = parseFloat( $.css( this.activeMenu[ 0 ], \"borderTopWidth\" ) ) || 0;\n\t\t\tpaddingTop = parseFloat( $.css( this.activeMenu[ 0 ], \"paddingTop\" ) ) || 0;\n\t\t\toffset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;\n\t\t\tscroll = this.activeMenu.scrollTop();\n\t\t\telementHeight = this.activeMenu.height();\n\t\t\titemHeight = item.outerHeight();\n\n\t\t\tif ( offset < 0 ) {\n\t\t\t\tthis.activeMenu.scrollTop( scroll + offset );\n\t\t\t} else if ( offset + itemHeight > elementHeight ) {\n\t\t\t\tthis.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );\n\t\t\t}\n\t\t}\n\t},\n\n\tblur: function( event, fromFocus ) {\n\t\tif ( !fromFocus ) {\n\t\t\tclearTimeout( this.timer );\n\t\t}\n\n\t\tif ( !this.active ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._removeClass( this.active.children( \".ui-menu-item-wrapper\" ),\n\t\t\tnull, \"ui-state-active\" );\n\n\t\tthis._trigger( \"blur\", event, { item: this.active } );\n\t\tthis.active = null;\n\t},\n\n\t_startOpening: function( submenu ) {\n\t\tclearTimeout( this.timer );\n\n\t\t// Don't open if already open fixes a Firefox bug that caused a .5 pixel\n\t\t// shift in the submenu position when mousing over the caret icon\n\t\tif ( submenu.attr( \"aria-hidden\" ) !== \"true\" ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.timer = this._delay( function() {\n\t\t\tthis._close();\n\t\t\tthis._open( submenu );\n\t\t}, this.delay );\n\t},\n\n\t_open: function( submenu ) {\n\t\tvar position = $.extend( {\n\t\t\tof: this.active\n\t\t}, this.options.position );\n\n\t\tclearTimeout( this.timer );\n\t\tthis.element.find( \".ui-menu\" ).not( submenu.parents( \".ui-menu\" ) )\n\t\t\t.hide()\n\t\t\t.attr( \"aria-hidden\", \"true\" );\n\n\t\tsubmenu\n\t\t\t.show()\n\t\t\t.removeAttr( \"aria-hidden\" )\n\t\t\t.attr( \"aria-expanded\", \"true\" )\n\t\t\t.position( position );\n\t},\n\n\tcollapseAll: function( event, all ) {\n\t\tclearTimeout( this.timer );\n\t\tthis.timer = this._delay( function() {\n\n\t\t\t// If we were passed an event, look for the submenu that contains the event\n\t\t\tvar currentMenu = all ? this.element :\n\t\t\t\t$( event && event.target ).closest( this.element.find( \".ui-menu\" ) );\n\n\t\t\t// If we found no valid submenu ancestor, use the main menu to close all\n\t\t\t// sub menus anyway\n\t\t\tif ( !currentMenu.length ) {\n\t\t\t\tcurrentMenu = this.element;\n\t\t\t}\n\n\t\t\tthis._close( currentMenu );\n\n\t\t\tthis.blur( event );\n\n\t\t\t// Work around active item staying active after menu is blurred\n\t\t\tthis._removeClass( currentMenu.find( \".ui-state-active\" ), null, \"ui-state-active\" );\n\n\t\t\tthis.activeMenu = currentMenu;\n\t\t}, this.delay );\n\t},\n\n\t// With no arguments, closes the currently active menu - if nothing is active\n\t// it closes all menus.  If passed an argument, it will search for menus BELOW\n\t_close: function( startMenu ) {\n\t\tif ( !startMenu ) {\n\t\t\tstartMenu = this.active ? this.active.parent() : this.element;\n\t\t}\n\n\t\tstartMenu.find( \".ui-menu\" )\n\t\t\t.hide()\n\t\t\t.attr( \"aria-hidden\", \"true\" )\n\t\t\t.attr( \"aria-expanded\", \"false\" );\n\t},\n\n\t_closeOnDocumentClick: function( event ) {\n\t\treturn !$( event.target ).closest( \".ui-menu\" ).length;\n\t},\n\n\t_isDivider: function( item ) {\n\n\t\t// Match hyphen, em dash, en dash\n\t\treturn !/[^\\-\\u2014\\u2013\\s]/.test( item.text() );\n\t},\n\n\tcollapse: function( event ) {\n\t\tvar newItem = this.active &&\n\t\t\tthis.active.parent().closest( \".ui-menu-item\", this.element );\n\t\tif ( newItem && newItem.length ) {\n\t\t\tthis._close();\n\t\t\tthis.focus( event, newItem );\n\t\t}\n\t},\n\n\texpand: function( event ) {\n\t\tvar newItem = this.active &&\n\t\t\tthis.active\n\t\t\t\t.children( \".ui-menu \" )\n\t\t\t\t\t.find( this.options.items )\n\t\t\t\t\t\t.first();\n\n\t\tif ( newItem && newItem.length ) {\n\t\t\tthis._open( newItem.parent() );\n\n\t\t\t// Delay so Firefox will not hide activedescendant change in expanding submenu from AT\n\t\t\tthis._delay( function() {\n\t\t\t\tthis.focus( event, newItem );\n\t\t\t} );\n\t\t}\n\t},\n\n\tnext: function( event ) {\n\t\tthis._move( \"next\", \"first\", event );\n\t},\n\n\tprevious: function( event ) {\n\t\tthis._move( \"prev\", \"last\", event );\n\t},\n\n\tisFirstItem: function() {\n\t\treturn this.active && !this.active.prevAll( \".ui-menu-item\" ).length;\n\t},\n\n\tisLastItem: function() {\n\t\treturn this.active && !this.active.nextAll( \".ui-menu-item\" ).length;\n\t},\n\n\t_move: function( direction, filter, event ) {\n\t\tvar next;\n\t\tif ( this.active ) {\n\t\t\tif ( direction === \"first\" || direction === \"last\" ) {\n\t\t\t\tnext = this.active\n\t\t\t\t\t[ direction === \"first\" ? \"prevAll\" : \"nextAll\" ]( \".ui-menu-item\" )\n\t\t\t\t\t.eq( -1 );\n\t\t\t} else {\n\t\t\t\tnext = this.active\n\t\t\t\t\t[ direction + \"All\" ]( \".ui-menu-item\" )\n\t\t\t\t\t.eq( 0 );\n\t\t\t}\n\t\t}\n\t\tif ( !next || !next.length || !this.active ) {\n\t\t\tnext = this.activeMenu.find( this.options.items )[ filter ]();\n\t\t}\n\n\t\tthis.focus( event, next );\n\t},\n\n\tnextPage: function( event ) {\n\t\tvar item, base, height;\n\n\t\tif ( !this.active ) {\n\t\t\tthis.next( event );\n\t\t\treturn;\n\t\t}\n\t\tif ( this.isLastItem() ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( this._hasScroll() ) {\n\t\t\tbase = this.active.offset().top;\n\t\t\theight = this.element.height();\n\t\t\tthis.active.nextAll( \".ui-menu-item\" ).each( function() {\n\t\t\t\titem = $( this );\n\t\t\t\treturn item.offset().top - base - height < 0;\n\t\t\t} );\n\n\t\t\tthis.focus( event, item );\n\t\t} else {\n\t\t\tthis.focus( event, this.activeMenu.find( this.options.items )\n\t\t\t\t[ !this.active ? \"first\" : \"last\" ]() );\n\t\t}\n\t},\n\n\tpreviousPage: function( event ) {\n\t\tvar item, base, height;\n\t\tif ( !this.active ) {\n\t\t\tthis.next( event );\n\t\t\treturn;\n\t\t}\n\t\tif ( this.isFirstItem() ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( this._hasScroll() ) {\n\t\t\tbase = this.active.offset().top;\n\t\t\theight = this.element.height();\n\t\t\tthis.active.prevAll( \".ui-menu-item\" ).each( function() {\n\t\t\t\titem = $( this );\n\t\t\t\treturn item.offset().top - base + height > 0;\n\t\t\t} );\n\n\t\t\tthis.focus( event, item );\n\t\t} else {\n\t\t\tthis.focus( event, this.activeMenu.find( this.options.items ).first() );\n\t\t}\n\t},\n\n\t_hasScroll: function() {\n\t\treturn this.element.outerHeight() < this.element.prop( \"scrollHeight\" );\n\t},\n\n\tselect: function( event ) {\n\n\t\t// TODO: It should never be possible to not have an active item at this\n\t\t// point, but the tests don't trigger mouseenter before click.\n\t\tthis.active = this.active || $( event.target ).closest( \".ui-menu-item\" );\n\t\tvar ui = { item: this.active };\n\t\tif ( !this.active.has( \".ui-menu\" ).length ) {\n\t\t\tthis.collapseAll( event, true );\n\t\t}\n\t\tthis._trigger( \"select\", event, ui );\n\t},\n\n\t_filterMenuItems: function( character ) {\n\t\tvar escapedCharacter = character.replace( /[\\-\\[\\]{}()*+?.,\\\\\\^$|#\\s]/g, \"\\\\$&\" ),\n\t\t\tregex = new RegExp( \"^\" + escapedCharacter, \"i\" );\n\n\t\treturn this.activeMenu\n\t\t\t.find( this.options.items )\n\n\t\t\t\t// Only match on items, not dividers or other content (#10571)\n\t\t\t\t.filter( \".ui-menu-item\" )\n\t\t\t\t\t.filter( function() {\n\t\t\t\t\t\treturn regex.test(\n\t\t\t\t\t\t\t$.trim( $( this ).children( \".ui-menu-item-wrapper\" ).text() ) );\n\t\t\t\t\t} );\n\t}\n} );\n\n\n/*!\n * jQuery UI Autocomplete 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Autocomplete\n//>>group: Widgets\n//>>description: Lists suggested words as the user is typing.\n//>>docs: http://api.jqueryui.com/autocomplete/\n//>>demos: http://jqueryui.com/autocomplete/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/autocomplete.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\n$.widget( \"ui.autocomplete\", {\n\tversion: \"1.12.1\",\n\tdefaultElement: \"<input>\",\n\toptions: {\n\t\tappendTo: null,\n\t\tautoFocus: false,\n\t\tdelay: 300,\n\t\tminLength: 1,\n\t\tposition: {\n\t\t\tmy: \"left top\",\n\t\t\tat: \"left bottom\",\n\t\t\tcollision: \"none\"\n\t\t},\n\t\tsource: null,\n\n\t\t// Callbacks\n\t\tchange: null,\n\t\tclose: null,\n\t\tfocus: null,\n\t\topen: null,\n\t\tresponse: null,\n\t\tsearch: null,\n\t\tselect: null\n\t},\n\n\trequestIndex: 0,\n\tpending: 0,\n\n\t_create: function() {\n\n\t\t// Some browsers only repeat keydown events, not keypress events,\n\t\t// so we use the suppressKeyPress flag to determine if we've already\n\t\t// handled the keydown event. #7269\n\t\t// Unfortunately the code for & in keypress is the same as the up arrow,\n\t\t// so we use the suppressKeyPressRepeat flag to avoid handling keypress\n\t\t// events when we know the keydown event was used to modify the\n\t\t// search term. #7799\n\t\tvar suppressKeyPress, suppressKeyPressRepeat, suppressInput,\n\t\t\tnodeName = this.element[ 0 ].nodeName.toLowerCase(),\n\t\t\tisTextarea = nodeName === \"textarea\",\n\t\t\tisInput = nodeName === \"input\";\n\n\t\t// Textareas are always multi-line\n\t\t// Inputs are always single-line, even if inside a contentEditable element\n\t\t// IE also treats inputs as contentEditable\n\t\t// All other element types are determined by whether or not they're contentEditable\n\t\tthis.isMultiLine = isTextarea || !isInput && this._isContentEditable( this.element );\n\n\t\tthis.valueMethod = this.element[ isTextarea || isInput ? \"val\" : \"text\" ];\n\t\tthis.isNewMenu = true;\n\n\t\tthis._addClass( \"ui-autocomplete-input\" );\n\t\tthis.element.attr( \"autocomplete\", \"off\" );\n\n\t\tthis._on( this.element, {\n\t\t\tkeydown: function( event ) {\n\t\t\t\tif ( this.element.prop( \"readOnly\" ) ) {\n\t\t\t\t\tsuppressKeyPress = true;\n\t\t\t\t\tsuppressInput = true;\n\t\t\t\t\tsuppressKeyPressRepeat = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsuppressKeyPress = false;\n\t\t\t\tsuppressInput = false;\n\t\t\t\tsuppressKeyPressRepeat = false;\n\t\t\t\tvar keyCode = $.ui.keyCode;\n\t\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase keyCode.PAGE_UP:\n\t\t\t\t\tsuppressKeyPress = true;\n\t\t\t\t\tthis._move( \"previousPage\", event );\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.PAGE_DOWN:\n\t\t\t\t\tsuppressKeyPress = true;\n\t\t\t\t\tthis._move( \"nextPage\", event );\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.UP:\n\t\t\t\t\tsuppressKeyPress = true;\n\t\t\t\t\tthis._keyEvent( \"previous\", event );\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.DOWN:\n\t\t\t\t\tsuppressKeyPress = true;\n\t\t\t\t\tthis._keyEvent( \"next\", event );\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.ENTER:\n\n\t\t\t\t\t// when menu is open and has focus\n\t\t\t\t\tif ( this.menu.active ) {\n\n\t\t\t\t\t\t// #6055 - Opera still allows the keypress to occur\n\t\t\t\t\t\t// which causes forms to submit\n\t\t\t\t\t\tsuppressKeyPress = true;\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tthis.menu.select( event );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.TAB:\n\t\t\t\t\tif ( this.menu.active ) {\n\t\t\t\t\t\tthis.menu.select( event );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.ESCAPE:\n\t\t\t\t\tif ( this.menu.element.is( \":visible\" ) ) {\n\t\t\t\t\t\tif ( !this.isMultiLine ) {\n\t\t\t\t\t\t\tthis._value( this.term );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.close( event );\n\n\t\t\t\t\t\t// Different browsers have different default behavior for escape\n\t\t\t\t\t\t// Single press can mean undo or clear\n\t\t\t\t\t\t// Double press in IE means clear the whole form\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tsuppressKeyPressRepeat = true;\n\n\t\t\t\t\t// search timeout should be triggered before the input value is changed\n\t\t\t\t\tthis._searchTimeout( event );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t\tkeypress: function( event ) {\n\t\t\t\tif ( suppressKeyPress ) {\n\t\t\t\t\tsuppressKeyPress = false;\n\t\t\t\t\tif ( !this.isMultiLine || this.menu.element.is( \":visible\" ) ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( suppressKeyPressRepeat ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Replicate some key handlers to allow them to repeat in Firefox and Opera\n\t\t\t\tvar keyCode = $.ui.keyCode;\n\t\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase keyCode.PAGE_UP:\n\t\t\t\t\tthis._move( \"previousPage\", event );\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.PAGE_DOWN:\n\t\t\t\t\tthis._move( \"nextPage\", event );\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.UP:\n\t\t\t\t\tthis._keyEvent( \"previous\", event );\n\t\t\t\t\tbreak;\n\t\t\t\tcase keyCode.DOWN:\n\t\t\t\t\tthis._keyEvent( \"next\", event );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\t\t\tinput: function( event ) {\n\t\t\t\tif ( suppressInput ) {\n\t\t\t\t\tsuppressInput = false;\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis._searchTimeout( event );\n\t\t\t},\n\t\t\tfocus: function() {\n\t\t\t\tthis.selectedItem = null;\n\t\t\t\tthis.previous = this._value();\n\t\t\t},\n\t\t\tblur: function( event ) {\n\t\t\t\tif ( this.cancelBlur ) {\n\t\t\t\t\tdelete this.cancelBlur;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tclearTimeout( this.searching );\n\t\t\t\tthis.close( event );\n\t\t\t\tthis._change( event );\n\t\t\t}\n\t\t} );\n\n\t\tthis._initSource();\n\t\tthis.menu = $( \"<ul>\" )\n\t\t\t.appendTo( this._appendTo() )\n\t\t\t.menu( {\n\n\t\t\t\t// disable ARIA support, the live region takes care of that\n\t\t\t\trole: null\n\t\t\t} )\n\t\t\t.hide()\n\t\t\t.menu( \"instance\" );\n\n\t\tthis._addClass( this.menu.element, \"ui-autocomplete\", \"ui-front\" );\n\t\tthis._on( this.menu.element, {\n\t\t\tmousedown: function( event ) {\n\n\t\t\t\t// prevent moving focus out of the text field\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// IE doesn't prevent moving focus even with event.preventDefault()\n\t\t\t\t// so we set a flag to know when we should ignore the blur event\n\t\t\t\tthis.cancelBlur = true;\n\t\t\t\tthis._delay( function() {\n\t\t\t\t\tdelete this.cancelBlur;\n\n\t\t\t\t\t// Support: IE 8 only\n\t\t\t\t\t// Right clicking a menu item or selecting text from the menu items will\n\t\t\t\t\t// result in focus moving out of the input. However, we've already received\n\t\t\t\t\t// and ignored the blur event because of the cancelBlur flag set above. So\n\t\t\t\t\t// we restore focus to ensure that the menu closes properly based on the user's\n\t\t\t\t\t// next actions.\n\t\t\t\t\tif ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {\n\t\t\t\t\t\tthis.element.trigger( \"focus\" );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\tmenufocus: function( event, ui ) {\n\t\t\t\tvar label, item;\n\n\t\t\t\t// support: Firefox\n\t\t\t\t// Prevent accidental activation of menu items in Firefox (#7024 #9118)\n\t\t\t\tif ( this.isNewMenu ) {\n\t\t\t\t\tthis.isNewMenu = false;\n\t\t\t\t\tif ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) {\n\t\t\t\t\t\tthis.menu.blur();\n\n\t\t\t\t\t\tthis.document.one( \"mousemove\", function() {\n\t\t\t\t\t\t\t$( event.target ).trigger( event.originalEvent );\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\titem = ui.item.data( \"ui-autocomplete-item\" );\n\t\t\t\tif ( false !== this._trigger( \"focus\", event, { item: item } ) ) {\n\n\t\t\t\t\t// use value to match what will end up in the input, if it was a key event\n\t\t\t\t\tif ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {\n\t\t\t\t\t\tthis._value( item.value );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Announce the value in the liveRegion\n\t\t\t\tlabel = ui.item.attr( \"aria-label\" ) || item.value;\n\t\t\t\tif ( label && $.trim( label ).length ) {\n\t\t\t\t\tthis.liveRegion.children().hide();\n\t\t\t\t\t$( \"<div>\" ).text( label ).appendTo( this.liveRegion );\n\t\t\t\t}\n\t\t\t},\n\t\t\tmenuselect: function( event, ui ) {\n\t\t\t\tvar item = ui.item.data( \"ui-autocomplete-item\" ),\n\t\t\t\t\tprevious = this.previous;\n\n\t\t\t\t// Only trigger when focus was lost (click on menu)\n\t\t\t\tif ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {\n\t\t\t\t\tthis.element.trigger( \"focus\" );\n\t\t\t\t\tthis.previous = previous;\n\n\t\t\t\t\t// #6109 - IE triggers two focus events and the second\n\t\t\t\t\t// is asynchronous, so we need to reset the previous\n\t\t\t\t\t// term synchronously and asynchronously :-(\n\t\t\t\t\tthis._delay( function() {\n\t\t\t\t\t\tthis.previous = previous;\n\t\t\t\t\t\tthis.selectedItem = item;\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tif ( false !== this._trigger( \"select\", event, { item: item } ) ) {\n\t\t\t\t\tthis._value( item.value );\n\t\t\t\t}\n\n\t\t\t\t// reset the term after the select event\n\t\t\t\t// this allows custom select handling to work properly\n\t\t\t\tthis.term = this._value();\n\n\t\t\t\tthis.close( event );\n\t\t\t\tthis.selectedItem = item;\n\t\t\t}\n\t\t} );\n\n\t\tthis.liveRegion = $( \"<div>\", {\n\t\t\trole: \"status\",\n\t\t\t\"aria-live\": \"assertive\",\n\t\t\t\"aria-relevant\": \"additions\"\n\t\t} )\n\t\t\t.appendTo( this.document[ 0 ].body );\n\n\t\tthis._addClass( this.liveRegion, null, \"ui-helper-hidden-accessible\" );\n\n\t\t// Turning off autocomplete prevents the browser from remembering the\n\t\t// value when navigating through history, so we re-enable autocomplete\n\t\t// if the page is unloaded before the widget is destroyed. #7790\n\t\tthis._on( this.window, {\n\t\t\tbeforeunload: function() {\n\t\t\t\tthis.element.removeAttr( \"autocomplete\" );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_destroy: function() {\n\t\tclearTimeout( this.searching );\n\t\tthis.element.removeAttr( \"autocomplete\" );\n\t\tthis.menu.element.remove();\n\t\tthis.liveRegion.remove();\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tthis._super( key, value );\n\t\tif ( key === \"source\" ) {\n\t\t\tthis._initSource();\n\t\t}\n\t\tif ( key === \"appendTo\" ) {\n\t\t\tthis.menu.element.appendTo( this._appendTo() );\n\t\t}\n\t\tif ( key === \"disabled\" && value && this.xhr ) {\n\t\t\tthis.xhr.abort();\n\t\t}\n\t},\n\n\t_isEventTargetInWidget: function( event ) {\n\t\tvar menuElement = this.menu.element[ 0 ];\n\n\t\treturn event.target === this.element[ 0 ] ||\n\t\t\tevent.target === menuElement ||\n\t\t\t$.contains( menuElement, event.target );\n\t},\n\n\t_closeOnClickOutside: function( event ) {\n\t\tif ( !this._isEventTargetInWidget( event ) ) {\n\t\t\tthis.close();\n\t\t}\n\t},\n\n\t_appendTo: function() {\n\t\tvar element = this.options.appendTo;\n\n\t\tif ( element ) {\n\t\t\telement = element.jquery || element.nodeType ?\n\t\t\t\t$( element ) :\n\t\t\t\tthis.document.find( element ).eq( 0 );\n\t\t}\n\n\t\tif ( !element || !element[ 0 ] ) {\n\t\t\telement = this.element.closest( \".ui-front, dialog\" );\n\t\t}\n\n\t\tif ( !element.length ) {\n\t\t\telement = this.document[ 0 ].body;\n\t\t}\n\n\t\treturn element;\n\t},\n\n\t_initSource: function() {\n\t\tvar array, url,\n\t\t\tthat = this;\n\t\tif ( $.isArray( this.options.source ) ) {\n\t\t\tarray = this.options.source;\n\t\t\tthis.source = function( request, response ) {\n\t\t\t\tresponse( $.ui.autocomplete.filter( array, request.term ) );\n\t\t\t};\n\t\t} else if ( typeof this.options.source === \"string\" ) {\n\t\t\turl = this.options.source;\n\t\t\tthis.source = function( request, response ) {\n\t\t\t\tif ( that.xhr ) {\n\t\t\t\t\tthat.xhr.abort();\n\t\t\t\t}\n\t\t\t\tthat.xhr = $.ajax( {\n\t\t\t\t\turl: url,\n\t\t\t\t\tdata: request,\n\t\t\t\t\tdataType: \"json\",\n\t\t\t\t\tsuccess: function( data ) {\n\t\t\t\t\t\tresponse( data );\n\t\t\t\t\t},\n\t\t\t\t\terror: function() {\n\t\t\t\t\t\tresponse( [] );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t};\n\t\t} else {\n\t\t\tthis.source = this.options.source;\n\t\t}\n\t},\n\n\t_searchTimeout: function( event ) {\n\t\tclearTimeout( this.searching );\n\t\tthis.searching = this._delay( function() {\n\n\t\t\t// Search if the value has changed, or if the user retypes the same value (see #7434)\n\t\t\tvar equalValues = this.term === this._value(),\n\t\t\t\tmenuVisible = this.menu.element.is( \":visible\" ),\n\t\t\t\tmodifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n\n\t\t\tif ( !equalValues || ( equalValues && !menuVisible && !modifierKey ) ) {\n\t\t\t\tthis.selectedItem = null;\n\t\t\t\tthis.search( null, event );\n\t\t\t}\n\t\t}, this.options.delay );\n\t},\n\n\tsearch: function( value, event ) {\n\t\tvalue = value != null ? value : this._value();\n\n\t\t// Always save the actual value, not the one passed as an argument\n\t\tthis.term = this._value();\n\n\t\tif ( value.length < this.options.minLength ) {\n\t\t\treturn this.close( event );\n\t\t}\n\n\t\tif ( this._trigger( \"search\", event ) === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this._search( value );\n\t},\n\n\t_search: function( value ) {\n\t\tthis.pending++;\n\t\tthis._addClass( \"ui-autocomplete-loading\" );\n\t\tthis.cancelSearch = false;\n\n\t\tthis.source( { term: value }, this._response() );\n\t},\n\n\t_response: function() {\n\t\tvar index = ++this.requestIndex;\n\n\t\treturn $.proxy( function( content ) {\n\t\t\tif ( index === this.requestIndex ) {\n\t\t\t\tthis.__response( content );\n\t\t\t}\n\n\t\t\tthis.pending--;\n\t\t\tif ( !this.pending ) {\n\t\t\t\tthis._removeClass( \"ui-autocomplete-loading\" );\n\t\t\t}\n\t\t}, this );\n\t},\n\n\t__response: function( content ) {\n\t\tif ( content ) {\n\t\t\tcontent = this._normalize( content );\n\t\t}\n\t\tthis._trigger( \"response\", null, { content: content } );\n\t\tif ( !this.options.disabled && content && content.length && !this.cancelSearch ) {\n\t\t\tthis._suggest( content );\n\t\t\tthis._trigger( \"open\" );\n\t\t} else {\n\n\t\t\t// use ._close() instead of .close() so we don't cancel future searches\n\t\t\tthis._close();\n\t\t}\n\t},\n\n\tclose: function( event ) {\n\t\tthis.cancelSearch = true;\n\t\tthis._close( event );\n\t},\n\n\t_close: function( event ) {\n\n\t\t// Remove the handler that closes the menu on outside clicks\n\t\tthis._off( this.document, \"mousedown\" );\n\n\t\tif ( this.menu.element.is( \":visible\" ) ) {\n\t\t\tthis.menu.element.hide();\n\t\t\tthis.menu.blur();\n\t\t\tthis.isNewMenu = true;\n\t\t\tthis._trigger( \"close\", event );\n\t\t}\n\t},\n\n\t_change: function( event ) {\n\t\tif ( this.previous !== this._value() ) {\n\t\t\tthis._trigger( \"change\", event, { item: this.selectedItem } );\n\t\t}\n\t},\n\n\t_normalize: function( items ) {\n\n\t\t// assume all items have the right format when the first item is complete\n\t\tif ( items.length && items[ 0 ].label && items[ 0 ].value ) {\n\t\t\treturn items;\n\t\t}\n\t\treturn $.map( items, function( item ) {\n\t\t\tif ( typeof item === \"string\" ) {\n\t\t\t\treturn {\n\t\t\t\t\tlabel: item,\n\t\t\t\t\tvalue: item\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn $.extend( {}, item, {\n\t\t\t\tlabel: item.label || item.value,\n\t\t\t\tvalue: item.value || item.label\n\t\t\t} );\n\t\t} );\n\t},\n\n\t_suggest: function( items ) {\n\t\tvar ul = this.menu.element.empty();\n\t\tthis._renderMenu( ul, items );\n\t\tthis.isNewMenu = true;\n\t\tthis.menu.refresh();\n\n\t\t// Size and position menu\n\t\tul.show();\n\t\tthis._resizeMenu();\n\t\tul.position( $.extend( {\n\t\t\tof: this.element\n\t\t}, this.options.position ) );\n\n\t\tif ( this.options.autoFocus ) {\n\t\t\tthis.menu.next();\n\t\t}\n\n\t\t// Listen for interactions outside of the widget (#6642)\n\t\tthis._on( this.document, {\n\t\t\tmousedown: \"_closeOnClickOutside\"\n\t\t} );\n\t},\n\n\t_resizeMenu: function() {\n\t\tvar ul = this.menu.element;\n\t\tul.outerWidth( Math.max(\n\n\t\t\t// Firefox wraps long text (possibly a rounding bug)\n\t\t\t// so we add 1px to avoid the wrapping (#7513)\n\t\t\tul.width( \"\" ).outerWidth() + 1,\n\t\t\tthis.element.outerWidth()\n\t\t) );\n\t},\n\n\t_renderMenu: function( ul, items ) {\n\t\tvar that = this;\n\t\t$.each( items, function( index, item ) {\n\t\t\tthat._renderItemData( ul, item );\n\t\t} );\n\t},\n\n\t_renderItemData: function( ul, item ) {\n\t\treturn this._renderItem( ul, item ).data( \"ui-autocomplete-item\", item );\n\t},\n\n\t_renderItem: function( ul, item ) {\n\t\treturn $( \"<li>\" )\n\t\t\t.append( $( \"<div>\" ).text( item.label ) )\n\t\t\t.appendTo( ul );\n\t},\n\n\t_move: function( direction, event ) {\n\t\tif ( !this.menu.element.is( \":visible\" ) ) {\n\t\t\tthis.search( null, event );\n\t\t\treturn;\n\t\t}\n\t\tif ( this.menu.isFirstItem() && /^previous/.test( direction ) ||\n\t\t\t\tthis.menu.isLastItem() && /^next/.test( direction ) ) {\n\n\t\t\tif ( !this.isMultiLine ) {\n\t\t\t\tthis._value( this.term );\n\t\t\t}\n\n\t\t\tthis.menu.blur();\n\t\t\treturn;\n\t\t}\n\t\tthis.menu[ direction ]( event );\n\t},\n\n\twidget: function() {\n\t\treturn this.menu.element;\n\t},\n\n\t_value: function() {\n\t\treturn this.valueMethod.apply( this.element, arguments );\n\t},\n\n\t_keyEvent: function( keyEvent, event ) {\n\t\tif ( !this.isMultiLine || this.menu.element.is( \":visible\" ) ) {\n\t\t\tthis._move( keyEvent, event );\n\n\t\t\t// Prevents moving cursor to beginning/end of the text field in some browsers\n\t\t\tevent.preventDefault();\n\t\t}\n\t},\n\n\t// Support: Chrome <=50\n\t// We should be able to just use this.element.prop( \"isContentEditable\" )\n\t// but hidden elements always report false in Chrome.\n\t// https://code.google.com/p/chromium/issues/detail?id=313082\n\t_isContentEditable: function( element ) {\n\t\tif ( !element.length ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tvar editable = element.prop( \"contentEditable\" );\n\n\t\tif ( editable === \"inherit\" ) {\n\t\t  return this._isContentEditable( element.parent() );\n\t\t}\n\n\t\treturn editable === \"true\";\n\t}\n} );\n\n$.extend( $.ui.autocomplete, {\n\tescapeRegex: function( value ) {\n\t\treturn value.replace( /[\\-\\[\\]{}()*+?.,\\\\\\^$|#\\s]/g, \"\\\\$&\" );\n\t},\n\tfilter: function( array, term ) {\n\t\tvar matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), \"i\" );\n\t\treturn $.grep( array, function( value ) {\n\t\t\treturn matcher.test( value.label || value.value || value );\n\t\t} );\n\t}\n} );\n\n// Live region extension, adding a `messages` option\n// NOTE: This is an experimental API. We are still investigating\n// a full solution for string manipulation and internationalization.\n$.widget( \"ui.autocomplete\", $.ui.autocomplete, {\n\toptions: {\n\t\tmessages: {\n\t\t\tnoResults: \"No search results.\",\n\t\t\tresults: function( amount ) {\n\t\t\t\treturn amount + ( amount > 1 ? \" results are\" : \" result is\" ) +\n\t\t\t\t\t\" available, use up and down arrow keys to navigate.\";\n\t\t\t}\n\t\t}\n\t},\n\n\t__response: function( content ) {\n\t\tvar message;\n\t\tthis._superApply( arguments );\n\t\tif ( this.options.disabled || this.cancelSearch ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( content && content.length ) {\n\t\t\tmessage = this.options.messages.results( content.length );\n\t\t} else {\n\t\t\tmessage = this.options.messages.noResults;\n\t\t}\n\t\tthis.liveRegion.children().hide();\n\t\t$( \"<div>\" ).text( message ).appendTo( this.liveRegion );\n\t}\n} );\n\nvar widgetsAutocomplete = $.ui.autocomplete;\n\n\n/*!\n * jQuery UI Controlgroup 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Controlgroup\n//>>group: Widgets\n//>>description: Visually groups form control widgets\n//>>docs: http://api.jqueryui.com/controlgroup/\n//>>demos: http://jqueryui.com/controlgroup/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/controlgroup.css\n//>>css.theme: ../../themes/base/theme.css\n\n\nvar controlgroupCornerRegex = /ui-corner-([a-z]){2,6}/g;\n\nvar widgetsControlgroup = $.widget( \"ui.controlgroup\", {\n\tversion: \"1.12.1\",\n\tdefaultElement: \"<div>\",\n\toptions: {\n\t\tdirection: \"horizontal\",\n\t\tdisabled: null,\n\t\tonlyVisible: true,\n\t\titems: {\n\t\t\t\"button\": \"input[type=button], input[type=submit], input[type=reset], button, a\",\n\t\t\t\"controlgroupLabel\": \".ui-controlgroup-label\",\n\t\t\t\"checkboxradio\": \"input[type='checkbox'], input[type='radio']\",\n\t\t\t\"selectmenu\": \"select\",\n\t\t\t\"spinner\": \".ui-spinner-input\"\n\t\t}\n\t},\n\n\t_create: function() {\n\t\tthis._enhance();\n\t},\n\n\t// To support the enhanced option in jQuery Mobile, we isolate DOM manipulation\n\t_enhance: function() {\n\t\tthis.element.attr( \"role\", \"toolbar\" );\n\t\tthis.refresh();\n\t},\n\n\t_destroy: function() {\n\t\tthis._callChildMethod( \"destroy\" );\n\t\tthis.childWidgets.removeData( \"ui-controlgroup-data\" );\n\t\tthis.element.removeAttr( \"role\" );\n\t\tif ( this.options.items.controlgroupLabel ) {\n\t\t\tthis.element\n\t\t\t\t.find( this.options.items.controlgroupLabel )\n\t\t\t\t.find( \".ui-controlgroup-label-contents\" )\n\t\t\t\t.contents().unwrap();\n\t\t}\n\t},\n\n\t_initWidgets: function() {\n\t\tvar that = this,\n\t\t\tchildWidgets = [];\n\n\t\t// First we iterate over each of the items options\n\t\t$.each( this.options.items, function( widget, selector ) {\n\t\t\tvar labels;\n\t\t\tvar options = {};\n\n\t\t\t// Make sure the widget has a selector set\n\t\t\tif ( !selector ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( widget === \"controlgroupLabel\" ) {\n\t\t\t\tlabels = that.element.find( selector );\n\t\t\t\tlabels.each( function() {\n\t\t\t\t\tvar element = $( this );\n\n\t\t\t\t\tif ( element.children( \".ui-controlgroup-label-contents\" ).length ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\telement.contents()\n\t\t\t\t\t\t.wrapAll( \"<span class='ui-controlgroup-label-contents'></span>\" );\n\t\t\t\t} );\n\t\t\t\tthat._addClass( labels, null, \"ui-widget ui-widget-content ui-state-default\" );\n\t\t\t\tchildWidgets = childWidgets.concat( labels.get() );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Make sure the widget actually exists\n\t\t\tif ( !$.fn[ widget ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We assume everything is in the middle to start because we can't determine\n\t\t\t// first / last elements until all enhancments are done.\n\t\t\tif ( that[ \"_\" + widget + \"Options\" ] ) {\n\t\t\t\toptions = that[ \"_\" + widget + \"Options\" ]( \"middle\" );\n\t\t\t} else {\n\t\t\t\toptions = { classes: {} };\n\t\t\t}\n\n\t\t\t// Find instances of this widget inside controlgroup and init them\n\t\t\tthat.element\n\t\t\t\t.find( selector )\n\t\t\t\t.each( function() {\n\t\t\t\t\tvar element = $( this );\n\t\t\t\t\tvar instance = element[ widget ]( \"instance\" );\n\n\t\t\t\t\t// We need to clone the default options for this type of widget to avoid\n\t\t\t\t\t// polluting the variable options which has a wider scope than a single widget.\n\t\t\t\t\tvar instanceOptions = $.widget.extend( {}, options );\n\n\t\t\t\t\t// If the button is the child of a spinner ignore it\n\t\t\t\t\t// TODO: Find a more generic solution\n\t\t\t\t\tif ( widget === \"button\" && element.parent( \".ui-spinner\" ).length ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Create the widget if it doesn't exist\n\t\t\t\t\tif ( !instance ) {\n\t\t\t\t\t\tinstance = element[ widget ]()[ widget ]( \"instance\" );\n\t\t\t\t\t}\n\t\t\t\t\tif ( instance ) {\n\t\t\t\t\t\tinstanceOptions.classes =\n\t\t\t\t\t\t\tthat._resolveClassesValues( instanceOptions.classes, instance );\n\t\t\t\t\t}\n\t\t\t\t\telement[ widget ]( instanceOptions );\n\n\t\t\t\t\t// Store an instance of the controlgroup to be able to reference\n\t\t\t\t\t// from the outermost element for changing options and refresh\n\t\t\t\t\tvar widgetElement = element[ widget ]( \"widget\" );\n\t\t\t\t\t$.data( widgetElement[ 0 ], \"ui-controlgroup-data\",\n\t\t\t\t\t\tinstance ? instance : element[ widget ]( \"instance\" ) );\n\n\t\t\t\t\tchildWidgets.push( widgetElement[ 0 ] );\n\t\t\t\t} );\n\t\t} );\n\n\t\tthis.childWidgets = $( $.unique( childWidgets ) );\n\t\tthis._addClass( this.childWidgets, \"ui-controlgroup-item\" );\n\t},\n\n\t_callChildMethod: function( method ) {\n\t\tthis.childWidgets.each( function() {\n\t\t\tvar element = $( this ),\n\t\t\t\tdata = element.data( \"ui-controlgroup-data\" );\n\t\t\tif ( data && data[ method ] ) {\n\t\t\t\tdata[ method ]();\n\t\t\t}\n\t\t} );\n\t},\n\n\t_updateCornerClass: function( element, position ) {\n\t\tvar remove = \"ui-corner-top ui-corner-bottom ui-corner-left ui-corner-right ui-corner-all\";\n\t\tvar add = this._buildSimpleOptions( position, \"label\" ).classes.label;\n\n\t\tthis._removeClass( element, null, remove );\n\t\tthis._addClass( element, null, add );\n\t},\n\n\t_buildSimpleOptions: function( position, key ) {\n\t\tvar direction = this.options.direction === \"vertical\";\n\t\tvar result = {\n\t\t\tclasses: {}\n\t\t};\n\t\tresult.classes[ key ] = {\n\t\t\t\"middle\": \"\",\n\t\t\t\"first\": \"ui-corner-\" + ( direction ? \"top\" : \"left\" ),\n\t\t\t\"last\": \"ui-corner-\" + ( direction ? \"bottom\" : \"right\" ),\n\t\t\t\"only\": \"ui-corner-all\"\n\t\t}[ position ];\n\n\t\treturn result;\n\t},\n\n\t_spinnerOptions: function( position ) {\n\t\tvar options = this._buildSimpleOptions( position, \"ui-spinner\" );\n\n\t\toptions.classes[ \"ui-spinner-up\" ] = \"\";\n\t\toptions.classes[ \"ui-spinner-down\" ] = \"\";\n\n\t\treturn options;\n\t},\n\n\t_buttonOptions: function( position ) {\n\t\treturn this._buildSimpleOptions( position, \"ui-button\" );\n\t},\n\n\t_checkboxradioOptions: function( position ) {\n\t\treturn this._buildSimpleOptions( position, \"ui-checkboxradio-label\" );\n\t},\n\n\t_selectmenuOptions: function( position ) {\n\t\tvar direction = this.options.direction === \"vertical\";\n\t\treturn {\n\t\t\twidth: direction ? \"auto\" : false,\n\t\t\tclasses: {\n\t\t\t\tmiddle: {\n\t\t\t\t\t\"ui-selectmenu-button-open\": \"\",\n\t\t\t\t\t\"ui-selectmenu-button-closed\": \"\"\n\t\t\t\t},\n\t\t\t\tfirst: {\n\t\t\t\t\t\"ui-selectmenu-button-open\": \"ui-corner-\" + ( direction ? \"top\" : \"tl\" ),\n\t\t\t\t\t\"ui-selectmenu-button-closed\": \"ui-corner-\" + ( direction ? \"top\" : \"left\" )\n\t\t\t\t},\n\t\t\t\tlast: {\n\t\t\t\t\t\"ui-selectmenu-button-open\": direction ? \"\" : \"ui-corner-tr\",\n\t\t\t\t\t\"ui-selectmenu-button-closed\": \"ui-corner-\" + ( direction ? \"bottom\" : \"right\" )\n\t\t\t\t},\n\t\t\t\tonly: {\n\t\t\t\t\t\"ui-selectmenu-button-open\": \"ui-corner-top\",\n\t\t\t\t\t\"ui-selectmenu-button-closed\": \"ui-corner-all\"\n\t\t\t\t}\n\n\t\t\t}[ position ]\n\t\t};\n\t},\n\n\t_resolveClassesValues: function( classes, instance ) {\n\t\tvar result = {};\n\t\t$.each( classes, function( key ) {\n\t\t\tvar current = instance.options.classes[ key ] || \"\";\n\t\t\tcurrent = $.trim( current.replace( controlgroupCornerRegex, \"\" ) );\n\t\t\tresult[ key ] = ( current + \" \" + classes[ key ] ).replace( /\\s+/g, \" \" );\n\t\t} );\n\t\treturn result;\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tif ( key === \"direction\" ) {\n\t\t\tthis._removeClass( \"ui-controlgroup-\" + this.options.direction );\n\t\t}\n\n\t\tthis._super( key, value );\n\t\tif ( key === \"disabled\" ) {\n\t\t\tthis._callChildMethod( value ? \"disable\" : \"enable\" );\n\t\t\treturn;\n\t\t}\n\n\t\tthis.refresh();\n\t},\n\n\trefresh: function() {\n\t\tvar children,\n\t\t\tthat = this;\n\n\t\tthis._addClass( \"ui-controlgroup ui-controlgroup-\" + this.options.direction );\n\n\t\tif ( this.options.direction === \"horizontal\" ) {\n\t\t\tthis._addClass( null, \"ui-helper-clearfix\" );\n\t\t}\n\t\tthis._initWidgets();\n\n\t\tchildren = this.childWidgets;\n\n\t\t// We filter here because we need to track all childWidgets not just the visible ones\n\t\tif ( this.options.onlyVisible ) {\n\t\t\tchildren = children.filter( \":visible\" );\n\t\t}\n\n\t\tif ( children.length ) {\n\n\t\t\t// We do this last because we need to make sure all enhancment is done\n\t\t\t// before determining first and last\n\t\t\t$.each( [ \"first\", \"last\" ], function( index, value ) {\n\t\t\t\tvar instance = children[ value ]().data( \"ui-controlgroup-data\" );\n\n\t\t\t\tif ( instance && that[ \"_\" + instance.widgetName + \"Options\" ] ) {\n\t\t\t\t\tvar options = that[ \"_\" + instance.widgetName + \"Options\" ](\n\t\t\t\t\t\tchildren.length === 1 ? \"only\" : value\n\t\t\t\t\t);\n\t\t\t\t\toptions.classes = that._resolveClassesValues( options.classes, instance );\n\t\t\t\t\tinstance.element[ instance.widgetName ]( options );\n\t\t\t\t} else {\n\t\t\t\t\tthat._updateCornerClass( children[ value ](), value );\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\t// Finally call the refresh method on each of the child widgets.\n\t\t\tthis._callChildMethod( \"refresh\" );\n\t\t}\n\t}\n} );\n\n/*!\n * jQuery UI Checkboxradio 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Checkboxradio\n//>>group: Widgets\n//>>description: Enhances a form with multiple themeable checkboxes or radio buttons.\n//>>docs: http://api.jqueryui.com/checkboxradio/\n//>>demos: http://jqueryui.com/checkboxradio/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/button.css\n//>>css.structure: ../../themes/base/checkboxradio.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\n$.widget( \"ui.checkboxradio\", [ $.ui.formResetMixin, {\n\tversion: \"1.12.1\",\n\toptions: {\n\t\tdisabled: null,\n\t\tlabel: null,\n\t\ticon: true,\n\t\tclasses: {\n\t\t\t\"ui-checkboxradio-label\": \"ui-corner-all\",\n\t\t\t\"ui-checkboxradio-icon\": \"ui-corner-all\"\n\t\t}\n\t},\n\n\t_getCreateOptions: function() {\n\t\tvar disabled, labels;\n\t\tvar that = this;\n\t\tvar options = this._super() || {};\n\n\t\t// We read the type here, because it makes more sense to throw a element type error first,\n\t\t// rather then the error for lack of a label. Often if its the wrong type, it\n\t\t// won't have a label (e.g. calling on a div, btn, etc)\n\t\tthis._readType();\n\n\t\tlabels = this.element.labels();\n\n\t\t// If there are multiple labels, use the last one\n\t\tthis.label = $( labels[ labels.length - 1 ] );\n\t\tif ( !this.label.length ) {\n\t\t\t$.error( \"No label found for checkboxradio widget\" );\n\t\t}\n\n\t\tthis.originalLabel = \"\";\n\n\t\t// We need to get the label text but this may also need to make sure it does not contain the\n\t\t// input itself.\n\t\tthis.label.contents().not( this.element[ 0 ] ).each( function() {\n\n\t\t\t// The label contents could be text, html, or a mix. We concat each element to get a\n\t\t\t// string representation of the label, without the input as part of it.\n\t\t\tthat.originalLabel += this.nodeType === 3 ? $( this ).text() : this.outerHTML;\n\t\t} );\n\n\t\t// Set the label option if we found label text\n\t\tif ( this.originalLabel ) {\n\t\t\toptions.label = this.originalLabel;\n\t\t}\n\n\t\tdisabled = this.element[ 0 ].disabled;\n\t\tif ( disabled != null ) {\n\t\t\toptions.disabled = disabled;\n\t\t}\n\t\treturn options;\n\t},\n\n\t_create: function() {\n\t\tvar checked = this.element[ 0 ].checked;\n\n\t\tthis._bindFormResetHandler();\n\n\t\tif ( this.options.disabled == null ) {\n\t\t\tthis.options.disabled = this.element[ 0 ].disabled;\n\t\t}\n\n\t\tthis._setOption( \"disabled\", this.options.disabled );\n\t\tthis._addClass( \"ui-checkboxradio\", \"ui-helper-hidden-accessible\" );\n\t\tthis._addClass( this.label, \"ui-checkboxradio-label\", \"ui-button ui-widget\" );\n\n\t\tif ( this.type === \"radio\" ) {\n\t\t\tthis._addClass( this.label, \"ui-checkboxradio-radio-label\" );\n\t\t}\n\n\t\tif ( this.options.label && this.options.label !== this.originalLabel ) {\n\t\t\tthis._updateLabel();\n\t\t} else if ( this.originalLabel ) {\n\t\t\tthis.options.label = this.originalLabel;\n\t\t}\n\n\t\tthis._enhance();\n\n\t\tif ( checked ) {\n\t\t\tthis._addClass( this.label, \"ui-checkboxradio-checked\", \"ui-state-active\" );\n\t\t\tif ( this.icon ) {\n\t\t\t\tthis._addClass( this.icon, null, \"ui-state-hover\" );\n\t\t\t}\n\t\t}\n\n\t\tthis._on( {\n\t\t\tchange: \"_toggleClasses\",\n\t\t\tfocus: function() {\n\t\t\t\tthis._addClass( this.label, null, \"ui-state-focus ui-visual-focus\" );\n\t\t\t},\n\t\t\tblur: function() {\n\t\t\t\tthis._removeClass( this.label, null, \"ui-state-focus ui-visual-focus\" );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_readType: function() {\n\t\tvar nodeName = this.element[ 0 ].nodeName.toLowerCase();\n\t\tthis.type = this.element[ 0 ].type;\n\t\tif ( nodeName !== \"input\" || !/radio|checkbox/.test( this.type ) ) {\n\t\t\t$.error( \"Can't create checkboxradio on element.nodeName=\" + nodeName +\n\t\t\t\t\" and element.type=\" + this.type );\n\t\t}\n\t},\n\n\t// Support jQuery Mobile enhanced option\n\t_enhance: function() {\n\t\tthis._updateIcon( this.element[ 0 ].checked );\n\t},\n\n\twidget: function() {\n\t\treturn this.label;\n\t},\n\n\t_getRadioGroup: function() {\n\t\tvar group;\n\t\tvar name = this.element[ 0 ].name;\n\t\tvar nameSelector = \"input[name='\" + $.ui.escapeSelector( name ) + \"']\";\n\n\t\tif ( !name ) {\n\t\t\treturn $( [] );\n\t\t}\n\n\t\tif ( this.form.length ) {\n\t\t\tgroup = $( this.form[ 0 ].elements ).filter( nameSelector );\n\t\t} else {\n\n\t\t\t// Not inside a form, check all inputs that also are not inside a form\n\t\t\tgroup = $( nameSelector ).filter( function() {\n\t\t\t\treturn $( this ).form().length === 0;\n\t\t\t} );\n\t\t}\n\n\t\treturn group.not( this.element );\n\t},\n\n\t_toggleClasses: function() {\n\t\tvar checked = this.element[ 0 ].checked;\n\t\tthis._toggleClass( this.label, \"ui-checkboxradio-checked\", \"ui-state-active\", checked );\n\n\t\tif ( this.options.icon && this.type === \"checkbox\" ) {\n\t\t\tthis._toggleClass( this.icon, null, \"ui-icon-check ui-state-checked\", checked )\n\t\t\t\t._toggleClass( this.icon, null, \"ui-icon-blank\", !checked );\n\t\t}\n\n\t\tif ( this.type === \"radio\" ) {\n\t\t\tthis._getRadioGroup()\n\t\t\t\t.each( function() {\n\t\t\t\t\tvar instance = $( this ).checkboxradio( \"instance\" );\n\n\t\t\t\t\tif ( instance ) {\n\t\t\t\t\t\tinstance._removeClass( instance.label,\n\t\t\t\t\t\t\t\"ui-checkboxradio-checked\", \"ui-state-active\" );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t}\n\t},\n\n\t_destroy: function() {\n\t\tthis._unbindFormResetHandler();\n\n\t\tif ( this.icon ) {\n\t\t\tthis.icon.remove();\n\t\t\tthis.iconSpace.remove();\n\t\t}\n\t},\n\n\t_setOption: function( key, value ) {\n\n\t\t// We don't allow the value to be set to nothing\n\t\tif ( key === \"label\" && !value ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._super( key, value );\n\n\t\tif ( key === \"disabled\" ) {\n\t\t\tthis._toggleClass( this.label, null, \"ui-state-disabled\", value );\n\t\t\tthis.element[ 0 ].disabled = value;\n\n\t\t\t// Don't refresh when setting disabled\n\t\t\treturn;\n\t\t}\n\t\tthis.refresh();\n\t},\n\n\t_updateIcon: function( checked ) {\n\t\tvar toAdd = \"ui-icon ui-icon-background \";\n\n\t\tif ( this.options.icon ) {\n\t\t\tif ( !this.icon ) {\n\t\t\t\tthis.icon = $( \"<span>\" );\n\t\t\t\tthis.iconSpace = $( \"<span> </span>\" );\n\t\t\t\tthis._addClass( this.iconSpace, \"ui-checkboxradio-icon-space\" );\n\t\t\t}\n\n\t\t\tif ( this.type === \"checkbox\" ) {\n\t\t\t\ttoAdd += checked ? \"ui-icon-check ui-state-checked\" : \"ui-icon-blank\";\n\t\t\t\tthis._removeClass( this.icon, null, checked ? \"ui-icon-blank\" : \"ui-icon-check\" );\n\t\t\t} else {\n\t\t\t\ttoAdd += \"ui-icon-blank\";\n\t\t\t}\n\t\t\tthis._addClass( this.icon, \"ui-checkboxradio-icon\", toAdd );\n\t\t\tif ( !checked ) {\n\t\t\t\tthis._removeClass( this.icon, null, \"ui-icon-check ui-state-checked\" );\n\t\t\t}\n\t\t\tthis.icon.prependTo( this.label ).after( this.iconSpace );\n\t\t} else if ( this.icon !== undefined ) {\n\t\t\tthis.icon.remove();\n\t\t\tthis.iconSpace.remove();\n\t\t\tdelete this.icon;\n\t\t}\n\t},\n\n\t_updateLabel: function() {\n\n\t\t// Remove the contents of the label ( minus the icon, icon space, and input )\n\t\tvar contents = this.label.contents().not( this.element[ 0 ] );\n\t\tif ( this.icon ) {\n\t\t\tcontents = contents.not( this.icon[ 0 ] );\n\t\t}\n\t\tif ( this.iconSpace ) {\n\t\t\tcontents = contents.not( this.iconSpace[ 0 ] );\n\t\t}\n\t\tcontents.remove();\n\n\t\tthis.label.append( this.options.label );\n\t},\n\n\trefresh: function() {\n\t\tvar checked = this.element[ 0 ].checked,\n\t\t\tisDisabled = this.element[ 0 ].disabled;\n\n\t\tthis._updateIcon( checked );\n\t\tthis._toggleClass( this.label, \"ui-checkboxradio-checked\", \"ui-state-active\", checked );\n\t\tif ( this.options.label !== null ) {\n\t\t\tthis._updateLabel();\n\t\t}\n\n\t\tif ( isDisabled !== this.options.disabled ) {\n\t\t\tthis._setOptions( { \"disabled\": isDisabled } );\n\t\t}\n\t}\n\n} ] );\n\nvar widgetsCheckboxradio = $.ui.checkboxradio;\n\n\n/*!\n * jQuery UI Button 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Button\n//>>group: Widgets\n//>>description: Enhances a form with themeable buttons.\n//>>docs: http://api.jqueryui.com/button/\n//>>demos: http://jqueryui.com/button/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/button.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\n$.widget( \"ui.button\", {\n\tversion: \"1.12.1\",\n\tdefaultElement: \"<button>\",\n\toptions: {\n\t\tclasses: {\n\t\t\t\"ui-button\": \"ui-corner-all\"\n\t\t},\n\t\tdisabled: null,\n\t\ticon: null,\n\t\ticonPosition: \"beginning\",\n\t\tlabel: null,\n\t\tshowLabel: true\n\t},\n\n\t_getCreateOptions: function() {\n\t\tvar disabled,\n\n\t\t\t// This is to support cases like in jQuery Mobile where the base widget does have\n\t\t\t// an implementation of _getCreateOptions\n\t\t\toptions = this._super() || {};\n\n\t\tthis.isInput = this.element.is( \"input\" );\n\n\t\tdisabled = this.element[ 0 ].disabled;\n\t\tif ( disabled != null ) {\n\t\t\toptions.disabled = disabled;\n\t\t}\n\n\t\tthis.originalLabel = this.isInput ? this.element.val() : this.element.html();\n\t\tif ( this.originalLabel ) {\n\t\t\toptions.label = this.originalLabel;\n\t\t}\n\n\t\treturn options;\n\t},\n\n\t_create: function() {\n\t\tif ( !this.option.showLabel & !this.options.icon ) {\n\t\t\tthis.options.showLabel = true;\n\t\t}\n\n\t\t// We have to check the option again here even though we did in _getCreateOptions,\n\t\t// because null may have been passed on init which would override what was set in\n\t\t// _getCreateOptions\n\t\tif ( this.options.disabled == null ) {\n\t\t\tthis.options.disabled = this.element[ 0 ].disabled || false;\n\t\t}\n\n\t\tthis.hasTitle = !!this.element.attr( \"title\" );\n\n\t\t// Check to see if the label needs to be set or if its already correct\n\t\tif ( this.options.label && this.options.label !== this.originalLabel ) {\n\t\t\tif ( this.isInput ) {\n\t\t\t\tthis.element.val( this.options.label );\n\t\t\t} else {\n\t\t\t\tthis.element.html( this.options.label );\n\t\t\t}\n\t\t}\n\t\tthis._addClass( \"ui-button\", \"ui-widget\" );\n\t\tthis._setOption( \"disabled\", this.options.disabled );\n\t\tthis._enhance();\n\n\t\tif ( this.element.is( \"a\" ) ) {\n\t\t\tthis._on( {\n\t\t\t\t\"keyup\": function( event ) {\n\t\t\t\t\tif ( event.keyCode === $.ui.keyCode.SPACE ) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Support: PhantomJS <= 1.9, IE 8 Only\n\t\t\t\t\t\t// If a native click is available use it so we actually cause navigation\n\t\t\t\t\t\t// otherwise just trigger a click event\n\t\t\t\t\t\tif ( this.element[ 0 ].click ) {\n\t\t\t\t\t\t\tthis.element[ 0 ].click();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.element.trigger( \"click\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t},\n\n\t_enhance: function() {\n\t\tif ( !this.element.is( \"button\" ) ) {\n\t\t\tthis.element.attr( \"role\", \"button\" );\n\t\t}\n\n\t\tif ( this.options.icon ) {\n\t\t\tthis._updateIcon( \"icon\", this.options.icon );\n\t\t\tthis._updateTooltip();\n\t\t}\n\t},\n\n\t_updateTooltip: function() {\n\t\tthis.title = this.element.attr( \"title\" );\n\n\t\tif ( !this.options.showLabel && !this.title ) {\n\t\t\tthis.element.attr( \"title\", this.options.label );\n\t\t}\n\t},\n\n\t_updateIcon: function( option, value ) {\n\t\tvar icon = option !== \"iconPosition\",\n\t\t\tposition = icon ? this.options.iconPosition : value,\n\t\t\tdisplayBlock = position === \"top\" || position === \"bottom\";\n\n\t\t// Create icon\n\t\tif ( !this.icon ) {\n\t\t\tthis.icon = $( \"<span>\" );\n\n\t\t\tthis._addClass( this.icon, \"ui-button-icon\", \"ui-icon\" );\n\n\t\t\tif ( !this.options.showLabel ) {\n\t\t\t\tthis._addClass( \"ui-button-icon-only\" );\n\t\t\t}\n\t\t} else if ( icon ) {\n\n\t\t\t// If we are updating the icon remove the old icon class\n\t\t\tthis._removeClass( this.icon, null, this.options.icon );\n\t\t}\n\n\t\t// If we are updating the icon add the new icon class\n\t\tif ( icon ) {\n\t\t\tthis._addClass( this.icon, null, value );\n\t\t}\n\n\t\tthis._attachIcon( position );\n\n\t\t// If the icon is on top or bottom we need to add the ui-widget-icon-block class and remove\n\t\t// the iconSpace if there is one.\n\t\tif ( displayBlock ) {\n\t\t\tthis._addClass( this.icon, null, \"ui-widget-icon-block\" );\n\t\t\tif ( this.iconSpace ) {\n\t\t\t\tthis.iconSpace.remove();\n\t\t\t}\n\t\t} else {\n\n\t\t\t// Position is beginning or end so remove the ui-widget-icon-block class and add the\n\t\t\t// space if it does not exist\n\t\t\tif ( !this.iconSpace ) {\n\t\t\t\tthis.iconSpace = $( \"<span> </span>\" );\n\t\t\t\tthis._addClass( this.iconSpace, \"ui-button-icon-space\" );\n\t\t\t}\n\t\t\tthis._removeClass( this.icon, null, \"ui-wiget-icon-block\" );\n\t\t\tthis._attachIconSpace( position );\n\t\t}\n\t},\n\n\t_destroy: function() {\n\t\tthis.element.removeAttr( \"role\" );\n\n\t\tif ( this.icon ) {\n\t\t\tthis.icon.remove();\n\t\t}\n\t\tif ( this.iconSpace ) {\n\t\t\tthis.iconSpace.remove();\n\t\t}\n\t\tif ( !this.hasTitle ) {\n\t\t\tthis.element.removeAttr( \"title\" );\n\t\t}\n\t},\n\n\t_attachIconSpace: function( iconPosition ) {\n\t\tthis.icon[ /^(?:end|bottom)/.test( iconPosition ) ? \"before\" : \"after\" ]( this.iconSpace );\n\t},\n\n\t_attachIcon: function( iconPosition ) {\n\t\tthis.element[ /^(?:end|bottom)/.test( iconPosition ) ? \"append\" : \"prepend\" ]( this.icon );\n\t},\n\n\t_setOptions: function( options ) {\n\t\tvar newShowLabel = options.showLabel === undefined ?\n\t\t\t\tthis.options.showLabel :\n\t\t\t\toptions.showLabel,\n\t\t\tnewIcon = options.icon === undefined ? this.options.icon : options.icon;\n\n\t\tif ( !newShowLabel && !newIcon ) {\n\t\t\toptions.showLabel = true;\n\t\t}\n\t\tthis._super( options );\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tif ( key === \"icon\" ) {\n\t\t\tif ( value ) {\n\t\t\t\tthis._updateIcon( key, value );\n\t\t\t} else if ( this.icon ) {\n\t\t\t\tthis.icon.remove();\n\t\t\t\tif ( this.iconSpace ) {\n\t\t\t\t\tthis.iconSpace.remove();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( key === \"iconPosition\" ) {\n\t\t\tthis._updateIcon( key, value );\n\t\t}\n\n\t\t// Make sure we can't end up with a button that has neither text nor icon\n\t\tif ( key === \"showLabel\" ) {\n\t\t\t\tthis._toggleClass( \"ui-button-icon-only\", null, !value );\n\t\t\t\tthis._updateTooltip();\n\t\t}\n\n\t\tif ( key === \"label\" ) {\n\t\t\tif ( this.isInput ) {\n\t\t\t\tthis.element.val( value );\n\t\t\t} else {\n\n\t\t\t\t// If there is an icon, append it, else nothing then append the value\n\t\t\t\t// this avoids removal of the icon when setting label text\n\t\t\t\tthis.element.html( value );\n\t\t\t\tif ( this.icon ) {\n\t\t\t\t\tthis._attachIcon( this.options.iconPosition );\n\t\t\t\t\tthis._attachIconSpace( this.options.iconPosition );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis._super( key, value );\n\n\t\tif ( key === \"disabled\" ) {\n\t\t\tthis._toggleClass( null, \"ui-state-disabled\", value );\n\t\t\tthis.element[ 0 ].disabled = value;\n\t\t\tif ( value ) {\n\t\t\t\tthis.element.blur();\n\t\t\t}\n\t\t}\n\t},\n\n\trefresh: function() {\n\n\t\t// Make sure to only check disabled if its an element that supports this otherwise\n\t\t// check for the disabled class to determine state\n\t\tvar isDisabled = this.element.is( \"input, button\" ) ?\n\t\t\tthis.element[ 0 ].disabled : this.element.hasClass( \"ui-button-disabled\" );\n\n\t\tif ( isDisabled !== this.options.disabled ) {\n\t\t\tthis._setOptions( { disabled: isDisabled } );\n\t\t}\n\n\t\tthis._updateTooltip();\n\t}\n} );\n\n// DEPRECATED\nif ( $.uiBackCompat !== false ) {\n\n\t// Text and Icons options\n\t$.widget( \"ui.button\", $.ui.button, {\n\t\toptions: {\n\t\t\ttext: true,\n\t\t\ticons: {\n\t\t\t\tprimary: null,\n\t\t\t\tsecondary: null\n\t\t\t}\n\t\t},\n\n\t\t_create: function() {\n\t\t\tif ( this.options.showLabel && !this.options.text ) {\n\t\t\t\tthis.options.showLabel = this.options.text;\n\t\t\t}\n\t\t\tif ( !this.options.showLabel && this.options.text ) {\n\t\t\t\tthis.options.text = this.options.showLabel;\n\t\t\t}\n\t\t\tif ( !this.options.icon && ( this.options.icons.primary ||\n\t\t\t\t\tthis.options.icons.secondary ) ) {\n\t\t\t\tif ( this.options.icons.primary ) {\n\t\t\t\t\tthis.options.icon = this.options.icons.primary;\n\t\t\t\t} else {\n\t\t\t\t\tthis.options.icon = this.options.icons.secondary;\n\t\t\t\t\tthis.options.iconPosition = \"end\";\n\t\t\t\t}\n\t\t\t} else if ( this.options.icon ) {\n\t\t\t\tthis.options.icons.primary = this.options.icon;\n\t\t\t}\n\t\t\tthis._super();\n\t\t},\n\n\t\t_setOption: function( key, value ) {\n\t\t\tif ( key === \"text\" ) {\n\t\t\t\tthis._super( \"showLabel\", value );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( key === \"showLabel\" ) {\n\t\t\t\tthis.options.text = value;\n\t\t\t}\n\t\t\tif ( key === \"icon\" ) {\n\t\t\t\tthis.options.icons.primary = value;\n\t\t\t}\n\t\t\tif ( key === \"icons\" ) {\n\t\t\t\tif ( value.primary ) {\n\t\t\t\t\tthis._super( \"icon\", value.primary );\n\t\t\t\t\tthis._super( \"iconPosition\", \"beginning\" );\n\t\t\t\t} else if ( value.secondary ) {\n\t\t\t\t\tthis._super( \"icon\", value.secondary );\n\t\t\t\t\tthis._super( \"iconPosition\", \"end\" );\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._superApply( arguments );\n\t\t}\n\t} );\n\n\t$.fn.button = ( function( orig ) {\n\t\treturn function() {\n\t\t\tif ( !this.length || ( this.length && this[ 0 ].tagName !== \"INPUT\" ) ||\n\t\t\t\t\t( this.length && this[ 0 ].tagName === \"INPUT\" && (\n\t\t\t\t\t\tthis.attr( \"type\" ) !== \"checkbox\" && this.attr( \"type\" ) !== \"radio\"\n\t\t\t\t\t) ) ) {\n\t\t\t\treturn orig.apply( this, arguments );\n\t\t\t}\n\t\t\tif ( !$.ui.checkboxradio ) {\n\t\t\t\t$.error( \"Checkboxradio widget missing\" );\n\t\t\t}\n\t\t\tif ( arguments.length === 0 ) {\n\t\t\t\treturn this.checkboxradio( {\n\t\t\t\t\t\"icon\": false\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn this.checkboxradio.apply( this, arguments );\n\t\t};\n\t} )( $.fn.button );\n\n\t$.fn.buttonset = function() {\n\t\tif ( !$.ui.controlgroup ) {\n\t\t\t$.error( \"Controlgroup widget missing\" );\n\t\t}\n\t\tif ( arguments[ 0 ] === \"option\" && arguments[ 1 ] === \"items\" && arguments[ 2 ] ) {\n\t\t\treturn this.controlgroup.apply( this,\n\t\t\t\t[ arguments[ 0 ], \"items.button\", arguments[ 2 ] ] );\n\t\t}\n\t\tif ( arguments[ 0 ] === \"option\" && arguments[ 1 ] === \"items\" ) {\n\t\t\treturn this.controlgroup.apply( this, [ arguments[ 0 ], \"items.button\" ] );\n\t\t}\n\t\tif ( typeof arguments[ 0 ] === \"object\" && arguments[ 0 ].items ) {\n\t\t\targuments[ 0 ].items = {\n\t\t\t\tbutton: arguments[ 0 ].items\n\t\t\t};\n\t\t}\n\t\treturn this.controlgroup.apply( this, arguments );\n\t};\n}\n\nvar widgetsButton = $.ui.button;\n\n\n// jscs:disable maximumLineLength\n/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */\n/*!\n * jQuery UI Datepicker 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Datepicker\n//>>group: Widgets\n//>>description: Displays a calendar from an input or inline for selecting dates.\n//>>docs: http://api.jqueryui.com/datepicker/\n//>>demos: http://jqueryui.com/datepicker/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/datepicker.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\n$.extend( $.ui, { datepicker: { version: \"1.12.1\" } } );\n\nvar datepicker_instActive;\n\nfunction datepicker_getZindex( elem ) {\n\tvar position, value;\n\twhile ( elem.length && elem[ 0 ] !== document ) {\n\n\t\t// Ignore z-index if position is set to a value where z-index is ignored by the browser\n\t\t// This makes behavior of this function consistent across browsers\n\t\t// WebKit always returns auto if the element is positioned\n\t\tposition = elem.css( \"position\" );\n\t\tif ( position === \"absolute\" || position === \"relative\" || position === \"fixed\" ) {\n\n\t\t\t// IE returns 0 when zIndex is not specified\n\t\t\t// other browsers return a string\n\t\t\t// we ignore the case of nested elements with an explicit value of 0\n\t\t\t// <div style=\"z-index: -10;\"><div style=\"z-index: 0;\"></div></div>\n\t\t\tvalue = parseInt( elem.css( \"zIndex\" ), 10 );\n\t\t\tif ( !isNaN( value ) && value !== 0 ) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\t\telem = elem.parent();\n\t}\n\n\treturn 0;\n}\n/* Date picker manager.\n   Use the singleton instance of this class, $.datepicker, to interact with the date picker.\n   Settings for (groups of) date pickers are maintained in an instance object,\n   allowing multiple different settings on the same page. */\n\nfunction Datepicker() {\n\tthis._curInst = null; // The current instance in use\n\tthis._keyEvent = false; // If the last event was a key event\n\tthis._disabledInputs = []; // List of date picker inputs that have been disabled\n\tthis._datepickerShowing = false; // True if the popup picker is showing , false if not\n\tthis._inDialog = false; // True if showing within a \"dialog\", false if not\n\tthis._mainDivId = \"ui-datepicker-div\"; // The ID of the main datepicker division\n\tthis._inlineClass = \"ui-datepicker-inline\"; // The name of the inline marker class\n\tthis._appendClass = \"ui-datepicker-append\"; // The name of the append marker class\n\tthis._triggerClass = \"ui-datepicker-trigger\"; // The name of the trigger marker class\n\tthis._dialogClass = \"ui-datepicker-dialog\"; // The name of the dialog marker class\n\tthis._disableClass = \"ui-datepicker-disabled\"; // The name of the disabled covering marker class\n\tthis._unselectableClass = \"ui-datepicker-unselectable\"; // The name of the unselectable cell marker class\n\tthis._currentClass = \"ui-datepicker-current-day\"; // The name of the current day marker class\n\tthis._dayOverClass = \"ui-datepicker-days-cell-over\"; // The name of the day hover marker class\n\tthis.regional = []; // Available regional settings, indexed by language code\n\tthis.regional[ \"\" ] = { // Default regional settings\n\t\tcloseText: \"Done\", // Display text for close link\n\t\tprevText: \"Prev\", // Display text for previous month link\n\t\tnextText: \"Next\", // Display text for next month link\n\t\tcurrentText: \"Today\", // Display text for current month link\n\t\tmonthNames: [ \"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\n\t\t\t\"July\",\"August\",\"September\",\"October\",\"November\",\"December\" ], // Names of months for drop-down and formatting\n\t\tmonthNamesShort: [ \"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\" ], // For formatting\n\t\tdayNames: [ \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\" ], // For formatting\n\t\tdayNamesShort: [ \"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\" ], // For formatting\n\t\tdayNamesMin: [ \"Su\",\"Mo\",\"Tu\",\"We\",\"Th\",\"Fr\",\"Sa\" ], // Column headings for days starting at Sunday\n\t\tweekHeader: \"Wk\", // Column header for week of the year\n\t\tdateFormat: \"mm/dd/yy\", // See format options on parseDate\n\t\tfirstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...\n\t\tisRTL: false, // True if right-to-left language, false if left-to-right\n\t\tshowMonthAfterYear: false, // True if the year select precedes month, false for month then year\n\t\tyearSuffix: \"\" // Additional text to append to the year in the month headers\n\t};\n\tthis._defaults = { // Global defaults for all the date picker instances\n\t\tshowOn: \"focus\", // \"focus\" for popup on focus,\n\t\t\t// \"button\" for trigger button, or \"both\" for either\n\t\tshowAnim: \"fadeIn\", // Name of jQuery animation for popup\n\t\tshowOptions: {}, // Options for enhanced animations\n\t\tdefaultDate: null, // Used when field is blank: actual date,\n\t\t\t// +/-number for offset from today, null for today\n\t\tappendText: \"\", // Display text following the input box, e.g. showing the format\n\t\tbuttonText: \"...\", // Text for trigger button\n\t\tbuttonImage: \"\", // URL for trigger button image\n\t\tbuttonImageOnly: false, // True if the image appears alone, false if it appears on a button\n\t\thideIfNoPrevNext: false, // True to hide next/previous month links\n\t\t\t// if not applicable, false to just disable them\n\t\tnavigationAsDateFormat: false, // True if date formatting applied to prev/today/next links\n\t\tgotoCurrent: false, // True if today link goes back to current selection instead\n\t\tchangeMonth: false, // True if month can be selected directly, false if only prev/next\n\t\tchangeYear: false, // True if year can be selected directly, false if only prev/next\n\t\tyearRange: \"c-10:c+10\", // Range of years to display in drop-down,\n\t\t\t// either relative to today's year (-nn:+nn), relative to currently displayed year\n\t\t\t// (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)\n\t\tshowOtherMonths: false, // True to show dates in other months, false to leave blank\n\t\tselectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable\n\t\tshowWeek: false, // True to show week of the year, false to not show it\n\t\tcalculateWeek: this.iso8601Week, // How to calculate the week of the year,\n\t\t\t// takes a Date and returns the number of the week for it\n\t\tshortYearCutoff: \"+10\", // Short year values < this are in the current century,\n\t\t\t// > this are in the previous century,\n\t\t\t// string value starting with \"+\" for current year + value\n\t\tminDate: null, // The earliest selectable date, or null for no limit\n\t\tmaxDate: null, // The latest selectable date, or null for no limit\n\t\tduration: \"fast\", // Duration of display/closure\n\t\tbeforeShowDay: null, // Function that takes a date and returns an array with\n\t\t\t// [0] = true if selectable, false if not, [1] = custom CSS class name(s) or \"\",\n\t\t\t// [2] = cell title (optional), e.g. $.datepicker.noWeekends\n\t\tbeforeShow: null, // Function that takes an input field and\n\t\t\t// returns a set of custom settings for the date picker\n\t\tonSelect: null, // Define a callback function when a date is selected\n\t\tonChangeMonthYear: null, // Define a callback function when the month or year is changed\n\t\tonClose: null, // Define a callback function when the datepicker is closed\n\t\tnumberOfMonths: 1, // Number of months to show at a time\n\t\tshowCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)\n\t\tstepMonths: 1, // Number of months to step back/forward\n\t\tstepBigMonths: 12, // Number of months to step back/forward for the big links\n\t\taltField: \"\", // Selector for an alternate field to store selected dates into\n\t\taltFormat: \"\", // The date format to use for the alternate field\n\t\tconstrainInput: true, // The input is constrained by the current date format\n\t\tshowButtonPanel: false, // True to show button panel, false to not show it\n\t\tautoSize: false, // True to size the input for the date format, false to leave as is\n\t\tdisabled: false // The initial disabled state\n\t};\n\t$.extend( this._defaults, this.regional[ \"\" ] );\n\tthis.regional.en = $.extend( true, {}, this.regional[ \"\" ] );\n\tthis.regional[ \"en-US\" ] = $.extend( true, {}, this.regional.en );\n\tthis.dpDiv = datepicker_bindHover( $( \"<div id='\" + this._mainDivId + \"' class='ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>\" ) );\n}\n\n$.extend( Datepicker.prototype, {\n\t/* Class name added to elements to indicate already configured with a date picker. */\n\tmarkerClassName: \"hasDatepicker\",\n\n\t//Keep track of the maximum number of rows displayed (see #7043)\n\tmaxRows: 4,\n\n\t// TODO rename to \"widget\" when switching to widget factory\n\t_widgetDatepicker: function() {\n\t\treturn this.dpDiv;\n\t},\n\n\t/* Override the default settings for all instances of the date picker.\n\t * @param  settings  object - the new settings to use as defaults (anonymous object)\n\t * @return the manager object\n\t */\n\tsetDefaults: function( settings ) {\n\t\tdatepicker_extendRemove( this._defaults, settings || {} );\n\t\treturn this;\n\t},\n\n\t/* Attach the date picker to a jQuery selection.\n\t * @param  target\telement - the target input field or division or span\n\t * @param  settings  object - the new settings to use for this date picker instance (anonymous)\n\t */\n\t_attachDatepicker: function( target, settings ) {\n\t\tvar nodeName, inline, inst;\n\t\tnodeName = target.nodeName.toLowerCase();\n\t\tinline = ( nodeName === \"div\" || nodeName === \"span\" );\n\t\tif ( !target.id ) {\n\t\t\tthis.uuid += 1;\n\t\t\ttarget.id = \"dp\" + this.uuid;\n\t\t}\n\t\tinst = this._newInst( $( target ), inline );\n\t\tinst.settings = $.extend( {}, settings || {} );\n\t\tif ( nodeName === \"input\" ) {\n\t\t\tthis._connectDatepicker( target, inst );\n\t\t} else if ( inline ) {\n\t\t\tthis._inlineDatepicker( target, inst );\n\t\t}\n\t},\n\n\t/* Create a new instance object. */\n\t_newInst: function( target, inline ) {\n\t\tvar id = target[ 0 ].id.replace( /([^A-Za-z0-9_\\-])/g, \"\\\\\\\\$1\" ); // escape jQuery meta chars\n\t\treturn { id: id, input: target, // associated target\n\t\t\tselectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection\n\t\t\tdrawMonth: 0, drawYear: 0, // month being drawn\n\t\t\tinline: inline, // is datepicker inline or not\n\t\t\tdpDiv: ( !inline ? this.dpDiv : // presentation div\n\t\t\tdatepicker_bindHover( $( \"<div class='\" + this._inlineClass + \" ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>\" ) ) ) };\n\t},\n\n\t/* Attach the date picker to an input field. */\n\t_connectDatepicker: function( target, inst ) {\n\t\tvar input = $( target );\n\t\tinst.append = $( [] );\n\t\tinst.trigger = $( [] );\n\t\tif ( input.hasClass( this.markerClassName ) ) {\n\t\t\treturn;\n\t\t}\n\t\tthis._attachments( input, inst );\n\t\tinput.addClass( this.markerClassName ).on( \"keydown\", this._doKeyDown ).\n\t\t\ton( \"keypress\", this._doKeyPress ).on( \"keyup\", this._doKeyUp );\n\t\tthis._autoSize( inst );\n\t\t$.data( target, \"datepicker\", inst );\n\n\t\t//If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665)\n\t\tif ( inst.settings.disabled ) {\n\t\t\tthis._disableDatepicker( target );\n\t\t}\n\t},\n\n\t/* Make attachments based on settings. */\n\t_attachments: function( input, inst ) {\n\t\tvar showOn, buttonText, buttonImage,\n\t\t\tappendText = this._get( inst, \"appendText\" ),\n\t\t\tisRTL = this._get( inst, \"isRTL\" );\n\n\t\tif ( inst.append ) {\n\t\t\tinst.append.remove();\n\t\t}\n\t\tif ( appendText ) {\n\t\t\tinst.append = $( \"<span class='\" + this._appendClass + \"'>\" + appendText + \"</span>\" );\n\t\t\tinput[ isRTL ? \"before\" : \"after\" ]( inst.append );\n\t\t}\n\n\t\tinput.off( \"focus\", this._showDatepicker );\n\n\t\tif ( inst.trigger ) {\n\t\t\tinst.trigger.remove();\n\t\t}\n\n\t\tshowOn = this._get( inst, \"showOn\" );\n\t\tif ( showOn === \"focus\" || showOn === \"both\" ) { // pop-up date picker when in the marked field\n\t\t\tinput.on( \"focus\", this._showDatepicker );\n\t\t}\n\t\tif ( showOn === \"button\" || showOn === \"both\" ) { // pop-up date picker when button clicked\n\t\t\tbuttonText = this._get( inst, \"buttonText\" );\n\t\t\tbuttonImage = this._get( inst, \"buttonImage\" );\n\t\t\tinst.trigger = $( this._get( inst, \"buttonImageOnly\" ) ?\n\t\t\t\t$( \"<img/>\" ).addClass( this._triggerClass ).\n\t\t\t\t\tattr( { src: buttonImage, alt: buttonText, title: buttonText } ) :\n\t\t\t\t$( \"<button type='button'></button>\" ).addClass( this._triggerClass ).\n\t\t\t\t\thtml( !buttonImage ? buttonText : $( \"<img/>\" ).attr(\n\t\t\t\t\t{ src:buttonImage, alt:buttonText, title:buttonText } ) ) );\n\t\t\tinput[ isRTL ? \"before\" : \"after\" ]( inst.trigger );\n\t\t\tinst.trigger.on( \"click\", function() {\n\t\t\t\tif ( $.datepicker._datepickerShowing && $.datepicker._lastInput === input[ 0 ] ) {\n\t\t\t\t\t$.datepicker._hideDatepicker();\n\t\t\t\t} else if ( $.datepicker._datepickerShowing && $.datepicker._lastInput !== input[ 0 ] ) {\n\t\t\t\t\t$.datepicker._hideDatepicker();\n\t\t\t\t\t$.datepicker._showDatepicker( input[ 0 ] );\n\t\t\t\t} else {\n\t\t\t\t\t$.datepicker._showDatepicker( input[ 0 ] );\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t} );\n\t\t}\n\t},\n\n\t/* Apply the maximum length for the date format. */\n\t_autoSize: function( inst ) {\n\t\tif ( this._get( inst, \"autoSize\" ) && !inst.inline ) {\n\t\t\tvar findMax, max, maxI, i,\n\t\t\t\tdate = new Date( 2009, 12 - 1, 20 ), // Ensure double digits\n\t\t\t\tdateFormat = this._get( inst, \"dateFormat\" );\n\n\t\t\tif ( dateFormat.match( /[DM]/ ) ) {\n\t\t\t\tfindMax = function( names ) {\n\t\t\t\t\tmax = 0;\n\t\t\t\t\tmaxI = 0;\n\t\t\t\t\tfor ( i = 0; i < names.length; i++ ) {\n\t\t\t\t\t\tif ( names[ i ].length > max ) {\n\t\t\t\t\t\t\tmax = names[ i ].length;\n\t\t\t\t\t\t\tmaxI = i;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn maxI;\n\t\t\t\t};\n\t\t\t\tdate.setMonth( findMax( this._get( inst, ( dateFormat.match( /MM/ ) ?\n\t\t\t\t\t\"monthNames\" : \"monthNamesShort\" ) ) ) );\n\t\t\t\tdate.setDate( findMax( this._get( inst, ( dateFormat.match( /DD/ ) ?\n\t\t\t\t\t\"dayNames\" : \"dayNamesShort\" ) ) ) + 20 - date.getDay() );\n\t\t\t}\n\t\t\tinst.input.attr( \"size\", this._formatDate( inst, date ).length );\n\t\t}\n\t},\n\n\t/* Attach an inline date picker to a div. */\n\t_inlineDatepicker: function( target, inst ) {\n\t\tvar divSpan = $( target );\n\t\tif ( divSpan.hasClass( this.markerClassName ) ) {\n\t\t\treturn;\n\t\t}\n\t\tdivSpan.addClass( this.markerClassName ).append( inst.dpDiv );\n\t\t$.data( target, \"datepicker\", inst );\n\t\tthis._setDate( inst, this._getDefaultDate( inst ), true );\n\t\tthis._updateDatepicker( inst );\n\t\tthis._updateAlternate( inst );\n\n\t\t//If disabled option is true, disable the datepicker before showing it (see ticket #5665)\n\t\tif ( inst.settings.disabled ) {\n\t\t\tthis._disableDatepicker( target );\n\t\t}\n\n\t\t// Set display:block in place of inst.dpDiv.show() which won't work on disconnected elements\n\t\t// http://bugs.jqueryui.com/ticket/7552 - A Datepicker created on a detached div has zero height\n\t\tinst.dpDiv.css( \"display\", \"block\" );\n\t},\n\n\t/* Pop-up the date picker in a \"dialog\" box.\n\t * @param  input element - ignored\n\t * @param  date\tstring or Date - the initial date to display\n\t * @param  onSelect  function - the function to call when a date is selected\n\t * @param  settings  object - update the dialog date picker instance's settings (anonymous object)\n\t * @param  pos int[2] - coordinates for the dialog's position within the screen or\n\t *\t\t\t\t\tevent - with x/y coordinates or\n\t *\t\t\t\t\tleave empty for default (screen centre)\n\t * @return the manager object\n\t */\n\t_dialogDatepicker: function( input, date, onSelect, settings, pos ) {\n\t\tvar id, browserWidth, browserHeight, scrollX, scrollY,\n\t\t\tinst = this._dialogInst; // internal instance\n\n\t\tif ( !inst ) {\n\t\t\tthis.uuid += 1;\n\t\t\tid = \"dp\" + this.uuid;\n\t\t\tthis._dialogInput = $( \"<input type='text' id='\" + id +\n\t\t\t\t\"' style='position: absolute; top: -100px; width: 0px;'/>\" );\n\t\t\tthis._dialogInput.on( \"keydown\", this._doKeyDown );\n\t\t\t$( \"body\" ).append( this._dialogInput );\n\t\t\tinst = this._dialogInst = this._newInst( this._dialogInput, false );\n\t\t\tinst.settings = {};\n\t\t\t$.data( this._dialogInput[ 0 ], \"datepicker\", inst );\n\t\t}\n\t\tdatepicker_extendRemove( inst.settings, settings || {} );\n\t\tdate = ( date && date.constructor === Date ? this._formatDate( inst, date ) : date );\n\t\tthis._dialogInput.val( date );\n\n\t\tthis._pos = ( pos ? ( pos.length ? pos : [ pos.pageX, pos.pageY ] ) : null );\n\t\tif ( !this._pos ) {\n\t\t\tbrowserWidth = document.documentElement.clientWidth;\n\t\t\tbrowserHeight = document.documentElement.clientHeight;\n\t\t\tscrollX = document.documentElement.scrollLeft || document.body.scrollLeft;\n\t\t\tscrollY = document.documentElement.scrollTop || document.body.scrollTop;\n\t\t\tthis._pos = // should use actual width/height below\n\t\t\t\t[ ( browserWidth / 2 ) - 100 + scrollX, ( browserHeight / 2 ) - 150 + scrollY ];\n\t\t}\n\n\t\t// Move input on screen for focus, but hidden behind dialog\n\t\tthis._dialogInput.css( \"left\", ( this._pos[ 0 ] + 20 ) + \"px\" ).css( \"top\", this._pos[ 1 ] + \"px\" );\n\t\tinst.settings.onSelect = onSelect;\n\t\tthis._inDialog = true;\n\t\tthis.dpDiv.addClass( this._dialogClass );\n\t\tthis._showDatepicker( this._dialogInput[ 0 ] );\n\t\tif ( $.blockUI ) {\n\t\t\t$.blockUI( this.dpDiv );\n\t\t}\n\t\t$.data( this._dialogInput[ 0 ], \"datepicker\", inst );\n\t\treturn this;\n\t},\n\n\t/* Detach a datepicker from its control.\n\t * @param  target\telement - the target input field or division or span\n\t */\n\t_destroyDatepicker: function( target ) {\n\t\tvar nodeName,\n\t\t\t$target = $( target ),\n\t\t\tinst = $.data( target, \"datepicker\" );\n\n\t\tif ( !$target.hasClass( this.markerClassName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnodeName = target.nodeName.toLowerCase();\n\t\t$.removeData( target, \"datepicker\" );\n\t\tif ( nodeName === \"input\" ) {\n\t\t\tinst.append.remove();\n\t\t\tinst.trigger.remove();\n\t\t\t$target.removeClass( this.markerClassName ).\n\t\t\t\toff( \"focus\", this._showDatepicker ).\n\t\t\t\toff( \"keydown\", this._doKeyDown ).\n\t\t\t\toff( \"keypress\", this._doKeyPress ).\n\t\t\t\toff( \"keyup\", this._doKeyUp );\n\t\t} else if ( nodeName === \"div\" || nodeName === \"span\" ) {\n\t\t\t$target.removeClass( this.markerClassName ).empty();\n\t\t}\n\n\t\tif ( datepicker_instActive === inst ) {\n\t\t\tdatepicker_instActive = null;\n\t\t}\n\t},\n\n\t/* Enable the date picker to a jQuery selection.\n\t * @param  target\telement - the target input field or division or span\n\t */\n\t_enableDatepicker: function( target ) {\n\t\tvar nodeName, inline,\n\t\t\t$target = $( target ),\n\t\t\tinst = $.data( target, \"datepicker\" );\n\n\t\tif ( !$target.hasClass( this.markerClassName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnodeName = target.nodeName.toLowerCase();\n\t\tif ( nodeName === \"input\" ) {\n\t\t\ttarget.disabled = false;\n\t\t\tinst.trigger.filter( \"button\" ).\n\t\t\t\teach( function() { this.disabled = false; } ).end().\n\t\t\t\tfilter( \"img\" ).css( { opacity: \"1.0\", cursor: \"\" } );\n\t\t} else if ( nodeName === \"div\" || nodeName === \"span\" ) {\n\t\t\tinline = $target.children( \".\" + this._inlineClass );\n\t\t\tinline.children().removeClass( \"ui-state-disabled\" );\n\t\t\tinline.find( \"select.ui-datepicker-month, select.ui-datepicker-year\" ).\n\t\t\t\tprop( \"disabled\", false );\n\t\t}\n\t\tthis._disabledInputs = $.map( this._disabledInputs,\n\t\t\tfunction( value ) { return ( value === target ? null : value ); } ); // delete entry\n\t},\n\n\t/* Disable the date picker to a jQuery selection.\n\t * @param  target\telement - the target input field or division or span\n\t */\n\t_disableDatepicker: function( target ) {\n\t\tvar nodeName, inline,\n\t\t\t$target = $( target ),\n\t\t\tinst = $.data( target, \"datepicker\" );\n\n\t\tif ( !$target.hasClass( this.markerClassName ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnodeName = target.nodeName.toLowerCase();\n\t\tif ( nodeName === \"input\" ) {\n\t\t\ttarget.disabled = true;\n\t\t\tinst.trigger.filter( \"button\" ).\n\t\t\t\teach( function() { this.disabled = true; } ).end().\n\t\t\t\tfilter( \"img\" ).css( { opacity: \"0.5\", cursor: \"default\" } );\n\t\t} else if ( nodeName === \"div\" || nodeName === \"span\" ) {\n\t\t\tinline = $target.children( \".\" + this._inlineClass );\n\t\t\tinline.children().addClass( \"ui-state-disabled\" );\n\t\t\tinline.find( \"select.ui-datepicker-month, select.ui-datepicker-year\" ).\n\t\t\t\tprop( \"disabled\", true );\n\t\t}\n\t\tthis._disabledInputs = $.map( this._disabledInputs,\n\t\t\tfunction( value ) { return ( value === target ? null : value ); } ); // delete entry\n\t\tthis._disabledInputs[ this._disabledInputs.length ] = target;\n\t},\n\n\t/* Is the first field in a jQuery collection disabled as a datepicker?\n\t * @param  target\telement - the target input field or division or span\n\t * @return boolean - true if disabled, false if enabled\n\t */\n\t_isDisabledDatepicker: function( target ) {\n\t\tif ( !target ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( var i = 0; i < this._disabledInputs.length; i++ ) {\n\t\t\tif ( this._disabledInputs[ i ] === target ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t},\n\n\t/* Retrieve the instance data for the target control.\n\t * @param  target  element - the target input field or division or span\n\t * @return  object - the associated instance data\n\t * @throws  error if a jQuery problem getting data\n\t */\n\t_getInst: function( target ) {\n\t\ttry {\n\t\t\treturn $.data( target, \"datepicker\" );\n\t\t}\n\t\tcatch ( err ) {\n\t\t\tthrow \"Missing instance data for this datepicker\";\n\t\t}\n\t},\n\n\t/* Update or retrieve the settings for a date picker attached to an input field or division.\n\t * @param  target  element - the target input field or division or span\n\t * @param  name\tobject - the new settings to update or\n\t *\t\t\t\tstring - the name of the setting to change or retrieve,\n\t *\t\t\t\twhen retrieving also \"all\" for all instance settings or\n\t *\t\t\t\t\"defaults\" for all global defaults\n\t * @param  value   any - the new value for the setting\n\t *\t\t\t\t(omit if above is an object or to retrieve a value)\n\t */\n\t_optionDatepicker: function( target, name, value ) {\n\t\tvar settings, date, minDate, maxDate,\n\t\t\tinst = this._getInst( target );\n\n\t\tif ( arguments.length === 2 && typeof name === \"string\" ) {\n\t\t\treturn ( name === \"defaults\" ? $.extend( {}, $.datepicker._defaults ) :\n\t\t\t\t( inst ? ( name === \"all\" ? $.extend( {}, inst.settings ) :\n\t\t\t\tthis._get( inst, name ) ) : null ) );\n\t\t}\n\n\t\tsettings = name || {};\n\t\tif ( typeof name === \"string\" ) {\n\t\t\tsettings = {};\n\t\t\tsettings[ name ] = value;\n\t\t}\n\n\t\tif ( inst ) {\n\t\t\tif ( this._curInst === inst ) {\n\t\t\t\tthis._hideDatepicker();\n\t\t\t}\n\n\t\t\tdate = this._getDateDatepicker( target, true );\n\t\t\tminDate = this._getMinMaxDate( inst, \"min\" );\n\t\t\tmaxDate = this._getMinMaxDate( inst, \"max\" );\n\t\t\tdatepicker_extendRemove( inst.settings, settings );\n\n\t\t\t// reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided\n\t\t\tif ( minDate !== null && settings.dateFormat !== undefined && settings.minDate === undefined ) {\n\t\t\t\tinst.settings.minDate = this._formatDate( inst, minDate );\n\t\t\t}\n\t\t\tif ( maxDate !== null && settings.dateFormat !== undefined && settings.maxDate === undefined ) {\n\t\t\t\tinst.settings.maxDate = this._formatDate( inst, maxDate );\n\t\t\t}\n\t\t\tif ( \"disabled\" in settings ) {\n\t\t\t\tif ( settings.disabled ) {\n\t\t\t\t\tthis._disableDatepicker( target );\n\t\t\t\t} else {\n\t\t\t\t\tthis._enableDatepicker( target );\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._attachments( $( target ), inst );\n\t\t\tthis._autoSize( inst );\n\t\t\tthis._setDate( inst, date );\n\t\t\tthis._updateAlternate( inst );\n\t\t\tthis._updateDatepicker( inst );\n\t\t}\n\t},\n\n\t// Change method deprecated\n\t_changeDatepicker: function( target, name, value ) {\n\t\tthis._optionDatepicker( target, name, value );\n\t},\n\n\t/* Redraw the date picker attached to an input field or division.\n\t * @param  target  element - the target input field or division or span\n\t */\n\t_refreshDatepicker: function( target ) {\n\t\tvar inst = this._getInst( target );\n\t\tif ( inst ) {\n\t\t\tthis._updateDatepicker( inst );\n\t\t}\n\t},\n\n\t/* Set the dates for a jQuery selection.\n\t * @param  target element - the target input field or division or span\n\t * @param  date\tDate - the new date\n\t */\n\t_setDateDatepicker: function( target, date ) {\n\t\tvar inst = this._getInst( target );\n\t\tif ( inst ) {\n\t\t\tthis._setDate( inst, date );\n\t\t\tthis._updateDatepicker( inst );\n\t\t\tthis._updateAlternate( inst );\n\t\t}\n\t},\n\n\t/* Get the date(s) for the first entry in a jQuery selection.\n\t * @param  target element - the target input field or division or span\n\t * @param  noDefault boolean - true if no default date is to be used\n\t * @return Date - the current date\n\t */\n\t_getDateDatepicker: function( target, noDefault ) {\n\t\tvar inst = this._getInst( target );\n\t\tif ( inst && !inst.inline ) {\n\t\t\tthis._setDateFromField( inst, noDefault );\n\t\t}\n\t\treturn ( inst ? this._getDate( inst ) : null );\n\t},\n\n\t/* Handle keystrokes. */\n\t_doKeyDown: function( event ) {\n\t\tvar onSelect, dateStr, sel,\n\t\t\tinst = $.datepicker._getInst( event.target ),\n\t\t\thandled = true,\n\t\t\tisRTL = inst.dpDiv.is( \".ui-datepicker-rtl\" );\n\n\t\tinst._keyEvent = true;\n\t\tif ( $.datepicker._datepickerShowing ) {\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase 9: $.datepicker._hideDatepicker();\n\t\t\t\t\t\thandled = false;\n\t\t\t\t\t\tbreak; // hide on tab out\n\t\t\t\tcase 13: sel = $( \"td.\" + $.datepicker._dayOverClass + \":not(.\" +\n\t\t\t\t\t\t\t\t\t$.datepicker._currentClass + \")\", inst.dpDiv );\n\t\t\t\t\t\tif ( sel[ 0 ] ) {\n\t\t\t\t\t\t\t$.datepicker._selectDay( event.target, inst.selectedMonth, inst.selectedYear, sel[ 0 ] );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonSelect = $.datepicker._get( inst, \"onSelect\" );\n\t\t\t\t\t\tif ( onSelect ) {\n\t\t\t\t\t\t\tdateStr = $.datepicker._formatDate( inst );\n\n\t\t\t\t\t\t\t// Trigger custom callback\n\t\t\t\t\t\t\tonSelect.apply( ( inst.input ? inst.input[ 0 ] : null ), [ dateStr, inst ] );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t$.datepicker._hideDatepicker();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn false; // don't submit the form\n\t\t\t\tcase 27: $.datepicker._hideDatepicker();\n\t\t\t\t\t\tbreak; // hide on escape\n\t\t\t\tcase 33: $.datepicker._adjustDate( event.target, ( event.ctrlKey ?\n\t\t\t\t\t\t\t-$.datepicker._get( inst, \"stepBigMonths\" ) :\n\t\t\t\t\t\t\t-$.datepicker._get( inst, \"stepMonths\" ) ), \"M\" );\n\t\t\t\t\t\tbreak; // previous month/year on page up/+ ctrl\n\t\t\t\tcase 34: $.datepicker._adjustDate( event.target, ( event.ctrlKey ?\n\t\t\t\t\t\t\t+$.datepicker._get( inst, \"stepBigMonths\" ) :\n\t\t\t\t\t\t\t+$.datepicker._get( inst, \"stepMonths\" ) ), \"M\" );\n\t\t\t\t\t\tbreak; // next month/year on page down/+ ctrl\n\t\t\t\tcase 35: if ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\t\t\t$.datepicker._clearDate( event.target );\n\t\t\t\t\t\t}\n\t\t\t\t\t\thandled = event.ctrlKey || event.metaKey;\n\t\t\t\t\t\tbreak; // clear on ctrl or command +end\n\t\t\t\tcase 36: if ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\t\t\t$.datepicker._gotoToday( event.target );\n\t\t\t\t\t\t}\n\t\t\t\t\t\thandled = event.ctrlKey || event.metaKey;\n\t\t\t\t\t\tbreak; // current on ctrl or command +home\n\t\t\t\tcase 37: if ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\t\t\t$.datepicker._adjustDate( event.target, ( isRTL ? +1 : -1 ), \"D\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\thandled = event.ctrlKey || event.metaKey;\n\n\t\t\t\t\t\t// -1 day on ctrl or command +left\n\t\t\t\t\t\tif ( event.originalEvent.altKey ) {\n\t\t\t\t\t\t\t$.datepicker._adjustDate( event.target, ( event.ctrlKey ?\n\t\t\t\t\t\t\t\t-$.datepicker._get( inst, \"stepBigMonths\" ) :\n\t\t\t\t\t\t\t\t-$.datepicker._get( inst, \"stepMonths\" ) ), \"M\" );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// next month/year on alt +left on Mac\n\t\t\t\t\t\tbreak;\n\t\t\t\tcase 38: if ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\t\t\t$.datepicker._adjustDate( event.target, -7, \"D\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\thandled = event.ctrlKey || event.metaKey;\n\t\t\t\t\t\tbreak; // -1 week on ctrl or command +up\n\t\t\t\tcase 39: if ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\t\t\t$.datepicker._adjustDate( event.target, ( isRTL ? -1 : +1 ), \"D\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\thandled = event.ctrlKey || event.metaKey;\n\n\t\t\t\t\t\t// +1 day on ctrl or command +right\n\t\t\t\t\t\tif ( event.originalEvent.altKey ) {\n\t\t\t\t\t\t\t$.datepicker._adjustDate( event.target, ( event.ctrlKey ?\n\t\t\t\t\t\t\t\t+$.datepicker._get( inst, \"stepBigMonths\" ) :\n\t\t\t\t\t\t\t\t+$.datepicker._get( inst, \"stepMonths\" ) ), \"M\" );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// next month/year on alt +right\n\t\t\t\t\t\tbreak;\n\t\t\t\tcase 40: if ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\t\t\t$.datepicker._adjustDate( event.target, +7, \"D\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\thandled = event.ctrlKey || event.metaKey;\n\t\t\t\t\t\tbreak; // +1 week on ctrl or command +down\n\t\t\t\tdefault: handled = false;\n\t\t\t}\n\t\t} else if ( event.keyCode === 36 && event.ctrlKey ) { // display the date picker on ctrl+home\n\t\t\t$.datepicker._showDatepicker( this );\n\t\t} else {\n\t\t\thandled = false;\n\t\t}\n\n\t\tif ( handled ) {\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t}\n\t},\n\n\t/* Filter entered characters - based on date format. */\n\t_doKeyPress: function( event ) {\n\t\tvar chars, chr,\n\t\t\tinst = $.datepicker._getInst( event.target );\n\n\t\tif ( $.datepicker._get( inst, \"constrainInput\" ) ) {\n\t\t\tchars = $.datepicker._possibleChars( $.datepicker._get( inst, \"dateFormat\" ) );\n\t\t\tchr = String.fromCharCode( event.charCode == null ? event.keyCode : event.charCode );\n\t\t\treturn event.ctrlKey || event.metaKey || ( chr < \" \" || !chars || chars.indexOf( chr ) > -1 );\n\t\t}\n\t},\n\n\t/* Synchronise manual entry and field/alternate field. */\n\t_doKeyUp: function( event ) {\n\t\tvar date,\n\t\t\tinst = $.datepicker._getInst( event.target );\n\n\t\tif ( inst.input.val() !== inst.lastVal ) {\n\t\t\ttry {\n\t\t\t\tdate = $.datepicker.parseDate( $.datepicker._get( inst, \"dateFormat\" ),\n\t\t\t\t\t( inst.input ? inst.input.val() : null ),\n\t\t\t\t\t$.datepicker._getFormatConfig( inst ) );\n\n\t\t\t\tif ( date ) { // only if valid\n\t\t\t\t\t$.datepicker._setDateFromField( inst );\n\t\t\t\t\t$.datepicker._updateAlternate( inst );\n\t\t\t\t\t$.datepicker._updateDatepicker( inst );\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch ( err ) {\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t},\n\n\t/* Pop-up the date picker for a given input field.\n\t * If false returned from beforeShow event handler do not show.\n\t * @param  input  element - the input field attached to the date picker or\n\t *\t\t\t\t\tevent - if triggered by focus\n\t */\n\t_showDatepicker: function( input ) {\n\t\tinput = input.target || input;\n\t\tif ( input.nodeName.toLowerCase() !== \"input\" ) { // find from button/image trigger\n\t\t\tinput = $( \"input\", input.parentNode )[ 0 ];\n\t\t}\n\n\t\tif ( $.datepicker._isDisabledDatepicker( input ) || $.datepicker._lastInput === input ) { // already here\n\t\t\treturn;\n\t\t}\n\n\t\tvar inst, beforeShow, beforeShowSettings, isFixed,\n\t\t\toffset, showAnim, duration;\n\n\t\tinst = $.datepicker._getInst( input );\n\t\tif ( $.datepicker._curInst && $.datepicker._curInst !== inst ) {\n\t\t\t$.datepicker._curInst.dpDiv.stop( true, true );\n\t\t\tif ( inst && $.datepicker._datepickerShowing ) {\n\t\t\t\t$.datepicker._hideDatepicker( $.datepicker._curInst.input[ 0 ] );\n\t\t\t}\n\t\t}\n\n\t\tbeforeShow = $.datepicker._get( inst, \"beforeShow\" );\n\t\tbeforeShowSettings = beforeShow ? beforeShow.apply( input, [ input, inst ] ) : {};\n\t\tif ( beforeShowSettings === false ) {\n\t\t\treturn;\n\t\t}\n\t\tdatepicker_extendRemove( inst.settings, beforeShowSettings );\n\n\t\tinst.lastVal = null;\n\t\t$.datepicker._lastInput = input;\n\t\t$.datepicker._setDateFromField( inst );\n\n\t\tif ( $.datepicker._inDialog ) { // hide cursor\n\t\t\tinput.value = \"\";\n\t\t}\n\t\tif ( !$.datepicker._pos ) { // position below input\n\t\t\t$.datepicker._pos = $.datepicker._findPos( input );\n\t\t\t$.datepicker._pos[ 1 ] += input.offsetHeight; // add the height\n\t\t}\n\n\t\tisFixed = false;\n\t\t$( input ).parents().each( function() {\n\t\t\tisFixed |= $( this ).css( \"position\" ) === \"fixed\";\n\t\t\treturn !isFixed;\n\t\t} );\n\n\t\toffset = { left: $.datepicker._pos[ 0 ], top: $.datepicker._pos[ 1 ] };\n\t\t$.datepicker._pos = null;\n\n\t\t//to avoid flashes on Firefox\n\t\tinst.dpDiv.empty();\n\n\t\t// determine sizing offscreen\n\t\tinst.dpDiv.css( { position: \"absolute\", display: \"block\", top: \"-1000px\" } );\n\t\t$.datepicker._updateDatepicker( inst );\n\n\t\t// fix width for dynamic number of date pickers\n\t\t// and adjust position before showing\n\t\toffset = $.datepicker._checkOffset( inst, offset, isFixed );\n\t\tinst.dpDiv.css( { position: ( $.datepicker._inDialog && $.blockUI ?\n\t\t\t\"static\" : ( isFixed ? \"fixed\" : \"absolute\" ) ), display: \"none\",\n\t\t\tleft: offset.left + \"px\", top: offset.top + \"px\" } );\n\n\t\tif ( !inst.inline ) {\n\t\t\tshowAnim = $.datepicker._get( inst, \"showAnim\" );\n\t\t\tduration = $.datepicker._get( inst, \"duration\" );\n\t\t\tinst.dpDiv.css( \"z-index\", datepicker_getZindex( $( input ) ) + 1 );\n\t\t\t$.datepicker._datepickerShowing = true;\n\n\t\t\tif ( $.effects && $.effects.effect[ showAnim ] ) {\n\t\t\t\tinst.dpDiv.show( showAnim, $.datepicker._get( inst, \"showOptions\" ), duration );\n\t\t\t} else {\n\t\t\t\tinst.dpDiv[ showAnim || \"show\" ]( showAnim ? duration : null );\n\t\t\t}\n\n\t\t\tif ( $.datepicker._shouldFocusInput( inst ) ) {\n\t\t\t\tinst.input.trigger( \"focus\" );\n\t\t\t}\n\n\t\t\t$.datepicker._curInst = inst;\n\t\t}\n\t},\n\n\t/* Generate the date picker content. */\n\t_updateDatepicker: function( inst ) {\n\t\tthis.maxRows = 4; //Reset the max number of rows being displayed (see #7043)\n\t\tdatepicker_instActive = inst; // for delegate hover events\n\t\tinst.dpDiv.empty().append( this._generateHTML( inst ) );\n\t\tthis._attachHandlers( inst );\n\n\t\tvar origyearshtml,\n\t\t\tnumMonths = this._getNumberOfMonths( inst ),\n\t\t\tcols = numMonths[ 1 ],\n\t\t\twidth = 17,\n\t\t\tactiveCell = inst.dpDiv.find( \".\" + this._dayOverClass + \" a\" );\n\n\t\tif ( activeCell.length > 0 ) {\n\t\t\tdatepicker_handleMouseover.apply( activeCell.get( 0 ) );\n\t\t}\n\n\t\tinst.dpDiv.removeClass( \"ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4\" ).width( \"\" );\n\t\tif ( cols > 1 ) {\n\t\t\tinst.dpDiv.addClass( \"ui-datepicker-multi-\" + cols ).css( \"width\", ( width * cols ) + \"em\" );\n\t\t}\n\t\tinst.dpDiv[ ( numMonths[ 0 ] !== 1 || numMonths[ 1 ] !== 1 ? \"add\" : \"remove\" ) +\n\t\t\t\"Class\" ]( \"ui-datepicker-multi\" );\n\t\tinst.dpDiv[ ( this._get( inst, \"isRTL\" ) ? \"add\" : \"remove\" ) +\n\t\t\t\"Class\" ]( \"ui-datepicker-rtl\" );\n\n\t\tif ( inst === $.datepicker._curInst && $.datepicker._datepickerShowing && $.datepicker._shouldFocusInput( inst ) ) {\n\t\t\tinst.input.trigger( \"focus\" );\n\t\t}\n\n\t\t// Deffered render of the years select (to avoid flashes on Firefox)\n\t\tif ( inst.yearshtml ) {\n\t\t\torigyearshtml = inst.yearshtml;\n\t\t\tsetTimeout( function() {\n\n\t\t\t\t//assure that inst.yearshtml didn't change.\n\t\t\t\tif ( origyearshtml === inst.yearshtml && inst.yearshtml ) {\n\t\t\t\t\tinst.dpDiv.find( \"select.ui-datepicker-year:first\" ).replaceWith( inst.yearshtml );\n\t\t\t\t}\n\t\t\t\torigyearshtml = inst.yearshtml = null;\n\t\t\t}, 0 );\n\t\t}\n\t},\n\n\t// #6694 - don't focus the input if it's already focused\n\t// this breaks the change event in IE\n\t// Support: IE and jQuery <1.9\n\t_shouldFocusInput: function( inst ) {\n\t\treturn inst.input && inst.input.is( \":visible\" ) && !inst.input.is( \":disabled\" ) && !inst.input.is( \":focus\" );\n\t},\n\n\t/* Check positioning to remain on screen. */\n\t_checkOffset: function( inst, offset, isFixed ) {\n\t\tvar dpWidth = inst.dpDiv.outerWidth(),\n\t\t\tdpHeight = inst.dpDiv.outerHeight(),\n\t\t\tinputWidth = inst.input ? inst.input.outerWidth() : 0,\n\t\t\tinputHeight = inst.input ? inst.input.outerHeight() : 0,\n\t\t\tviewWidth = document.documentElement.clientWidth + ( isFixed ? 0 : $( document ).scrollLeft() ),\n\t\t\tviewHeight = document.documentElement.clientHeight + ( isFixed ? 0 : $( document ).scrollTop() );\n\n\t\toffset.left -= ( this._get( inst, \"isRTL\" ) ? ( dpWidth - inputWidth ) : 0 );\n\t\toffset.left -= ( isFixed && offset.left === inst.input.offset().left ) ? $( document ).scrollLeft() : 0;\n\t\toffset.top -= ( isFixed && offset.top === ( inst.input.offset().top + inputHeight ) ) ? $( document ).scrollTop() : 0;\n\n\t\t// Now check if datepicker is showing outside window viewport - move to a better place if so.\n\t\toffset.left -= Math.min( offset.left, ( offset.left + dpWidth > viewWidth && viewWidth > dpWidth ) ?\n\t\t\tMath.abs( offset.left + dpWidth - viewWidth ) : 0 );\n\t\toffset.top -= Math.min( offset.top, ( offset.top + dpHeight > viewHeight && viewHeight > dpHeight ) ?\n\t\t\tMath.abs( dpHeight + inputHeight ) : 0 );\n\n\t\treturn offset;\n\t},\n\n\t/* Find an object's position on the screen. */\n\t_findPos: function( obj ) {\n\t\tvar position,\n\t\t\tinst = this._getInst( obj ),\n\t\t\tisRTL = this._get( inst, \"isRTL\" );\n\n\t\twhile ( obj && ( obj.type === \"hidden\" || obj.nodeType !== 1 || $.expr.filters.hidden( obj ) ) ) {\n\t\t\tobj = obj[ isRTL ? \"previousSibling\" : \"nextSibling\" ];\n\t\t}\n\n\t\tposition = $( obj ).offset();\n\t\treturn [ position.left, position.top ];\n\t},\n\n\t/* Hide the date picker from view.\n\t * @param  input  element - the input field attached to the date picker\n\t */\n\t_hideDatepicker: function( input ) {\n\t\tvar showAnim, duration, postProcess, onClose,\n\t\t\tinst = this._curInst;\n\n\t\tif ( !inst || ( input && inst !== $.data( input, \"datepicker\" ) ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( this._datepickerShowing ) {\n\t\t\tshowAnim = this._get( inst, \"showAnim\" );\n\t\t\tduration = this._get( inst, \"duration\" );\n\t\t\tpostProcess = function() {\n\t\t\t\t$.datepicker._tidyDialog( inst );\n\t\t\t};\n\n\t\t\t// DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed\n\t\t\tif ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) ) {\n\t\t\t\tinst.dpDiv.hide( showAnim, $.datepicker._get( inst, \"showOptions\" ), duration, postProcess );\n\t\t\t} else {\n\t\t\t\tinst.dpDiv[ ( showAnim === \"slideDown\" ? \"slideUp\" :\n\t\t\t\t\t( showAnim === \"fadeIn\" ? \"fadeOut\" : \"hide\" ) ) ]( ( showAnim ? duration : null ), postProcess );\n\t\t\t}\n\n\t\t\tif ( !showAnim ) {\n\t\t\t\tpostProcess();\n\t\t\t}\n\t\t\tthis._datepickerShowing = false;\n\n\t\t\tonClose = this._get( inst, \"onClose\" );\n\t\t\tif ( onClose ) {\n\t\t\t\tonClose.apply( ( inst.input ? inst.input[ 0 ] : null ), [ ( inst.input ? inst.input.val() : \"\" ), inst ] );\n\t\t\t}\n\n\t\t\tthis._lastInput = null;\n\t\t\tif ( this._inDialog ) {\n\t\t\t\tthis._dialogInput.css( { position: \"absolute\", left: \"0\", top: \"-100px\" } );\n\t\t\t\tif ( $.blockUI ) {\n\t\t\t\t\t$.unblockUI();\n\t\t\t\t\t$( \"body\" ).append( this.dpDiv );\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._inDialog = false;\n\t\t}\n\t},\n\n\t/* Tidy up after a dialog display. */\n\t_tidyDialog: function( inst ) {\n\t\tinst.dpDiv.removeClass( this._dialogClass ).off( \".ui-datepicker-calendar\" );\n\t},\n\n\t/* Close date picker if clicked elsewhere. */\n\t_checkExternalClick: function( event ) {\n\t\tif ( !$.datepicker._curInst ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar $target = $( event.target ),\n\t\t\tinst = $.datepicker._getInst( $target[ 0 ] );\n\n\t\tif ( ( ( $target[ 0 ].id !== $.datepicker._mainDivId &&\n\t\t\t\t$target.parents( \"#\" + $.datepicker._mainDivId ).length === 0 &&\n\t\t\t\t!$target.hasClass( $.datepicker.markerClassName ) &&\n\t\t\t\t!$target.closest( \".\" + $.datepicker._triggerClass ).length &&\n\t\t\t\t$.datepicker._datepickerShowing && !( $.datepicker._inDialog && $.blockUI ) ) ) ||\n\t\t\t( $target.hasClass( $.datepicker.markerClassName ) && $.datepicker._curInst !== inst ) ) {\n\t\t\t\t$.datepicker._hideDatepicker();\n\t\t}\n\t},\n\n\t/* Adjust one of the date sub-fields. */\n\t_adjustDate: function( id, offset, period ) {\n\t\tvar target = $( id ),\n\t\t\tinst = this._getInst( target[ 0 ] );\n\n\t\tif ( this._isDisabledDatepicker( target[ 0 ] ) ) {\n\t\t\treturn;\n\t\t}\n\t\tthis._adjustInstDate( inst, offset +\n\t\t\t( period === \"M\" ? this._get( inst, \"showCurrentAtPos\" ) : 0 ), // undo positioning\n\t\t\tperiod );\n\t\tthis._updateDatepicker( inst );\n\t},\n\n\t/* Action for current link. */\n\t_gotoToday: function( id ) {\n\t\tvar date,\n\t\t\ttarget = $( id ),\n\t\t\tinst = this._getInst( target[ 0 ] );\n\n\t\tif ( this._get( inst, \"gotoCurrent\" ) && inst.currentDay ) {\n\t\t\tinst.selectedDay = inst.currentDay;\n\t\t\tinst.drawMonth = inst.selectedMonth = inst.currentMonth;\n\t\t\tinst.drawYear = inst.selectedYear = inst.currentYear;\n\t\t} else {\n\t\t\tdate = new Date();\n\t\t\tinst.selectedDay = date.getDate();\n\t\t\tinst.drawMonth = inst.selectedMonth = date.getMonth();\n\t\t\tinst.drawYear = inst.selectedYear = date.getFullYear();\n\t\t}\n\t\tthis._notifyChange( inst );\n\t\tthis._adjustDate( target );\n\t},\n\n\t/* Action for selecting a new month/year. */\n\t_selectMonthYear: function( id, select, period ) {\n\t\tvar target = $( id ),\n\t\t\tinst = this._getInst( target[ 0 ] );\n\n\t\tinst[ \"selected\" + ( period === \"M\" ? \"Month\" : \"Year\" ) ] =\n\t\tinst[ \"draw\" + ( period === \"M\" ? \"Month\" : \"Year\" ) ] =\n\t\t\tparseInt( select.options[ select.selectedIndex ].value, 10 );\n\n\t\tthis._notifyChange( inst );\n\t\tthis._adjustDate( target );\n\t},\n\n\t/* Action for selecting a day. */\n\t_selectDay: function( id, month, year, td ) {\n\t\tvar inst,\n\t\t\ttarget = $( id );\n\n\t\tif ( $( td ).hasClass( this._unselectableClass ) || this._isDisabledDatepicker( target[ 0 ] ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tinst = this._getInst( target[ 0 ] );\n\t\tinst.selectedDay = inst.currentDay = $( \"a\", td ).html();\n\t\tinst.selectedMonth = inst.currentMonth = month;\n\t\tinst.selectedYear = inst.currentYear = year;\n\t\tthis._selectDate( id, this._formatDate( inst,\n\t\t\tinst.currentDay, inst.currentMonth, inst.currentYear ) );\n\t},\n\n\t/* Erase the input field and hide the date picker. */\n\t_clearDate: function( id ) {\n\t\tvar target = $( id );\n\t\tthis._selectDate( target, \"\" );\n\t},\n\n\t/* Update the input field with the selected date. */\n\t_selectDate: function( id, dateStr ) {\n\t\tvar onSelect,\n\t\t\ttarget = $( id ),\n\t\t\tinst = this._getInst( target[ 0 ] );\n\n\t\tdateStr = ( dateStr != null ? dateStr : this._formatDate( inst ) );\n\t\tif ( inst.input ) {\n\t\t\tinst.input.val( dateStr );\n\t\t}\n\t\tthis._updateAlternate( inst );\n\n\t\tonSelect = this._get( inst, \"onSelect\" );\n\t\tif ( onSelect ) {\n\t\t\tonSelect.apply( ( inst.input ? inst.input[ 0 ] : null ), [ dateStr, inst ] );  // trigger custom callback\n\t\t} else if ( inst.input ) {\n\t\t\tinst.input.trigger( \"change\" ); // fire the change event\n\t\t}\n\n\t\tif ( inst.inline ) {\n\t\t\tthis._updateDatepicker( inst );\n\t\t} else {\n\t\t\tthis._hideDatepicker();\n\t\t\tthis._lastInput = inst.input[ 0 ];\n\t\t\tif ( typeof( inst.input[ 0 ] ) !== \"object\" ) {\n\t\t\t\tinst.input.trigger( \"focus\" ); // restore focus\n\t\t\t}\n\t\t\tthis._lastInput = null;\n\t\t}\n\t},\n\n\t/* Update any alternate field to synchronise with the main field. */\n\t_updateAlternate: function( inst ) {\n\t\tvar altFormat, date, dateStr,\n\t\t\taltField = this._get( inst, \"altField\" );\n\n\t\tif ( altField ) { // update alternate field too\n\t\t\taltFormat = this._get( inst, \"altFormat\" ) || this._get( inst, \"dateFormat\" );\n\t\t\tdate = this._getDate( inst );\n\t\t\tdateStr = this.formatDate( altFormat, date, this._getFormatConfig( inst ) );\n\t\t\t$( altField ).val( dateStr );\n\t\t}\n\t},\n\n\t/* Set as beforeShowDay function to prevent selection of weekends.\n\t * @param  date  Date - the date to customise\n\t * @return [boolean, string] - is this date selectable?, what is its CSS class?\n\t */\n\tnoWeekends: function( date ) {\n\t\tvar day = date.getDay();\n\t\treturn [ ( day > 0 && day < 6 ), \"\" ];\n\t},\n\n\t/* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.\n\t * @param  date  Date - the date to get the week for\n\t * @return  number - the number of the week within the year that contains this date\n\t */\n\tiso8601Week: function( date ) {\n\t\tvar time,\n\t\t\tcheckDate = new Date( date.getTime() );\n\n\t\t// Find Thursday of this week starting on Monday\n\t\tcheckDate.setDate( checkDate.getDate() + 4 - ( checkDate.getDay() || 7 ) );\n\n\t\ttime = checkDate.getTime();\n\t\tcheckDate.setMonth( 0 ); // Compare with Jan 1\n\t\tcheckDate.setDate( 1 );\n\t\treturn Math.floor( Math.round( ( time - checkDate ) / 86400000 ) / 7 ) + 1;\n\t},\n\n\t/* Parse a string value into a date object.\n\t * See formatDate below for the possible formats.\n\t *\n\t * @param  format string - the expected format of the date\n\t * @param  value string - the date in the above format\n\t * @param  settings Object - attributes include:\n\t *\t\t\t\t\tshortYearCutoff  number - the cutoff year for determining the century (optional)\n\t *\t\t\t\t\tdayNamesShort\tstring[7] - abbreviated names of the days from Sunday (optional)\n\t *\t\t\t\t\tdayNames\t\tstring[7] - names of the days from Sunday (optional)\n\t *\t\t\t\t\tmonthNamesShort string[12] - abbreviated names of the months (optional)\n\t *\t\t\t\t\tmonthNames\t\tstring[12] - names of the months (optional)\n\t * @return  Date - the extracted date value or null if value is blank\n\t */\n\tparseDate: function( format, value, settings ) {\n\t\tif ( format == null || value == null ) {\n\t\t\tthrow \"Invalid arguments\";\n\t\t}\n\n\t\tvalue = ( typeof value === \"object\" ? value.toString() : value + \"\" );\n\t\tif ( value === \"\" ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tvar iFormat, dim, extra,\n\t\t\tiValue = 0,\n\t\t\tshortYearCutoffTemp = ( settings ? settings.shortYearCutoff : null ) || this._defaults.shortYearCutoff,\n\t\t\tshortYearCutoff = ( typeof shortYearCutoffTemp !== \"string\" ? shortYearCutoffTemp :\n\t\t\t\tnew Date().getFullYear() % 100 + parseInt( shortYearCutoffTemp, 10 ) ),\n\t\t\tdayNamesShort = ( settings ? settings.dayNamesShort : null ) || this._defaults.dayNamesShort,\n\t\t\tdayNames = ( settings ? settings.dayNames : null ) || this._defaults.dayNames,\n\t\t\tmonthNamesShort = ( settings ? settings.monthNamesShort : null ) || this._defaults.monthNamesShort,\n\t\t\tmonthNames = ( settings ? settings.monthNames : null ) || this._defaults.monthNames,\n\t\t\tyear = -1,\n\t\t\tmonth = -1,\n\t\t\tday = -1,\n\t\t\tdoy = -1,\n\t\t\tliteral = false,\n\t\t\tdate,\n\n\t\t\t// Check whether a format character is doubled\n\t\t\tlookAhead = function( match ) {\n\t\t\t\tvar matches = ( iFormat + 1 < format.length && format.charAt( iFormat + 1 ) === match );\n\t\t\t\tif ( matches ) {\n\t\t\t\t\tiFormat++;\n\t\t\t\t}\n\t\t\t\treturn matches;\n\t\t\t},\n\n\t\t\t// Extract a number from the string value\n\t\t\tgetNumber = function( match ) {\n\t\t\t\tvar isDoubled = lookAhead( match ),\n\t\t\t\t\tsize = ( match === \"@\" ? 14 : ( match === \"!\" ? 20 :\n\t\t\t\t\t( match === \"y\" && isDoubled ? 4 : ( match === \"o\" ? 3 : 2 ) ) ) ),\n\t\t\t\t\tminSize = ( match === \"y\" ? size : 1 ),\n\t\t\t\t\tdigits = new RegExp( \"^\\\\d{\" + minSize + \",\" + size + \"}\" ),\n\t\t\t\t\tnum = value.substring( iValue ).match( digits );\n\t\t\t\tif ( !num ) {\n\t\t\t\t\tthrow \"Missing number at position \" + iValue;\n\t\t\t\t}\n\t\t\t\tiValue += num[ 0 ].length;\n\t\t\t\treturn parseInt( num[ 0 ], 10 );\n\t\t\t},\n\n\t\t\t// Extract a name from the string value and convert to an index\n\t\t\tgetName = function( match, shortNames, longNames ) {\n\t\t\t\tvar index = -1,\n\t\t\t\t\tnames = $.map( lookAhead( match ) ? longNames : shortNames, function( v, k ) {\n\t\t\t\t\t\treturn [ [ k, v ] ];\n\t\t\t\t\t} ).sort( function( a, b ) {\n\t\t\t\t\t\treturn -( a[ 1 ].length - b[ 1 ].length );\n\t\t\t\t\t} );\n\n\t\t\t\t$.each( names, function( i, pair ) {\n\t\t\t\t\tvar name = pair[ 1 ];\n\t\t\t\t\tif ( value.substr( iValue, name.length ).toLowerCase() === name.toLowerCase() ) {\n\t\t\t\t\t\tindex = pair[ 0 ];\n\t\t\t\t\t\tiValue += name.length;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\treturn index + 1;\n\t\t\t\t} else {\n\t\t\t\t\tthrow \"Unknown name at position \" + iValue;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\t// Confirm that a literal character matches the string value\n\t\t\tcheckLiteral = function() {\n\t\t\t\tif ( value.charAt( iValue ) !== format.charAt( iFormat ) ) {\n\t\t\t\t\tthrow \"Unexpected literal at position \" + iValue;\n\t\t\t\t}\n\t\t\t\tiValue++;\n\t\t\t};\n\n\t\tfor ( iFormat = 0; iFormat < format.length; iFormat++ ) {\n\t\t\tif ( literal ) {\n\t\t\t\tif ( format.charAt( iFormat ) === \"'\" && !lookAhead( \"'\" ) ) {\n\t\t\t\t\tliteral = false;\n\t\t\t\t} else {\n\t\t\t\t\tcheckLiteral();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tswitch ( format.charAt( iFormat ) ) {\n\t\t\t\t\tcase \"d\":\n\t\t\t\t\t\tday = getNumber( \"d\" );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"D\":\n\t\t\t\t\t\tgetName( \"D\", dayNamesShort, dayNames );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"o\":\n\t\t\t\t\t\tdoy = getNumber( \"o\" );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"m\":\n\t\t\t\t\t\tmonth = getNumber( \"m\" );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"M\":\n\t\t\t\t\t\tmonth = getName( \"M\", monthNamesShort, monthNames );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"y\":\n\t\t\t\t\t\tyear = getNumber( \"y\" );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"@\":\n\t\t\t\t\t\tdate = new Date( getNumber( \"@\" ) );\n\t\t\t\t\t\tyear = date.getFullYear();\n\t\t\t\t\t\tmonth = date.getMonth() + 1;\n\t\t\t\t\t\tday = date.getDate();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"!\":\n\t\t\t\t\t\tdate = new Date( ( getNumber( \"!\" ) - this._ticksTo1970 ) / 10000 );\n\t\t\t\t\t\tyear = date.getFullYear();\n\t\t\t\t\t\tmonth = date.getMonth() + 1;\n\t\t\t\t\t\tday = date.getDate();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"'\":\n\t\t\t\t\t\tif ( lookAhead( \"'\" ) ) {\n\t\t\t\t\t\t\tcheckLiteral();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tliteral = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tcheckLiteral();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( iValue < value.length ) {\n\t\t\textra = value.substr( iValue );\n\t\t\tif ( !/^\\s+/.test( extra ) ) {\n\t\t\t\tthrow \"Extra/unparsed characters found in date: \" + extra;\n\t\t\t}\n\t\t}\n\n\t\tif ( year === -1 ) {\n\t\t\tyear = new Date().getFullYear();\n\t\t} else if ( year < 100 ) {\n\t\t\tyear += new Date().getFullYear() - new Date().getFullYear() % 100 +\n\t\t\t\t( year <= shortYearCutoff ? 0 : -100 );\n\t\t}\n\n\t\tif ( doy > -1 ) {\n\t\t\tmonth = 1;\n\t\t\tday = doy;\n\t\t\tdo {\n\t\t\t\tdim = this._getDaysInMonth( year, month - 1 );\n\t\t\t\tif ( day <= dim ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tmonth++;\n\t\t\t\tday -= dim;\n\t\t\t} while ( true );\n\t\t}\n\n\t\tdate = this._daylightSavingAdjust( new Date( year, month - 1, day ) );\n\t\tif ( date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day ) {\n\t\t\tthrow \"Invalid date\"; // E.g. 31/02/00\n\t\t}\n\t\treturn date;\n\t},\n\n\t/* Standard date formats. */\n\tATOM: \"yy-mm-dd\", // RFC 3339 (ISO 8601)\n\tCOOKIE: \"D, dd M yy\",\n\tISO_8601: \"yy-mm-dd\",\n\tRFC_822: \"D, d M y\",\n\tRFC_850: \"DD, dd-M-y\",\n\tRFC_1036: \"D, d M y\",\n\tRFC_1123: \"D, d M yy\",\n\tRFC_2822: \"D, d M yy\",\n\tRSS: \"D, d M y\", // RFC 822\n\tTICKS: \"!\",\n\tTIMESTAMP: \"@\",\n\tW3C: \"yy-mm-dd\", // ISO 8601\n\n\t_ticksTo1970: ( ( ( 1970 - 1 ) * 365 + Math.floor( 1970 / 4 ) - Math.floor( 1970 / 100 ) +\n\t\tMath.floor( 1970 / 400 ) ) * 24 * 60 * 60 * 10000000 ),\n\n\t/* Format a date object into a string value.\n\t * The format can be combinations of the following:\n\t * d  - day of month (no leading zero)\n\t * dd - day of month (two digit)\n\t * o  - day of year (no leading zeros)\n\t * oo - day of year (three digit)\n\t * D  - day name short\n\t * DD - day name long\n\t * m  - month of year (no leading zero)\n\t * mm - month of year (two digit)\n\t * M  - month name short\n\t * MM - month name long\n\t * y  - year (two digit)\n\t * yy - year (four digit)\n\t * @ - Unix timestamp (ms since 01/01/1970)\n\t * ! - Windows ticks (100ns since 01/01/0001)\n\t * \"...\" - literal text\n\t * '' - single quote\n\t *\n\t * @param  format string - the desired format of the date\n\t * @param  date Date - the date value to format\n\t * @param  settings Object - attributes include:\n\t *\t\t\t\t\tdayNamesShort\tstring[7] - abbreviated names of the days from Sunday (optional)\n\t *\t\t\t\t\tdayNames\t\tstring[7] - names of the days from Sunday (optional)\n\t *\t\t\t\t\tmonthNamesShort string[12] - abbreviated names of the months (optional)\n\t *\t\t\t\t\tmonthNames\t\tstring[12] - names of the months (optional)\n\t * @return  string - the date in the above format\n\t */\n\tformatDate: function( format, date, settings ) {\n\t\tif ( !date ) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tvar iFormat,\n\t\t\tdayNamesShort = ( settings ? settings.dayNamesShort : null ) || this._defaults.dayNamesShort,\n\t\t\tdayNames = ( settings ? settings.dayNames : null ) || this._defaults.dayNames,\n\t\t\tmonthNamesShort = ( settings ? settings.monthNamesShort : null ) || this._defaults.monthNamesShort,\n\t\t\tmonthNames = ( settings ? settings.monthNames : null ) || this._defaults.monthNames,\n\n\t\t\t// Check whether a format character is doubled\n\t\t\tlookAhead = function( match ) {\n\t\t\t\tvar matches = ( iFormat + 1 < format.length && format.charAt( iFormat + 1 ) === match );\n\t\t\t\tif ( matches ) {\n\t\t\t\t\tiFormat++;\n\t\t\t\t}\n\t\t\t\treturn matches;\n\t\t\t},\n\n\t\t\t// Format a number, with leading zero if necessary\n\t\t\tformatNumber = function( match, value, len ) {\n\t\t\t\tvar num = \"\" + value;\n\t\t\t\tif ( lookAhead( match ) ) {\n\t\t\t\t\twhile ( num.length < len ) {\n\t\t\t\t\t\tnum = \"0\" + num;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn num;\n\t\t\t},\n\n\t\t\t// Format a name, short or long as requested\n\t\t\tformatName = function( match, value, shortNames, longNames ) {\n\t\t\t\treturn ( lookAhead( match ) ? longNames[ value ] : shortNames[ value ] );\n\t\t\t},\n\t\t\toutput = \"\",\n\t\t\tliteral = false;\n\n\t\tif ( date ) {\n\t\t\tfor ( iFormat = 0; iFormat < format.length; iFormat++ ) {\n\t\t\t\tif ( literal ) {\n\t\t\t\t\tif ( format.charAt( iFormat ) === \"'\" && !lookAhead( \"'\" ) ) {\n\t\t\t\t\t\tliteral = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\toutput += format.charAt( iFormat );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tswitch ( format.charAt( iFormat ) ) {\n\t\t\t\t\t\tcase \"d\":\n\t\t\t\t\t\t\toutput += formatNumber( \"d\", date.getDate(), 2 );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"D\":\n\t\t\t\t\t\t\toutput += formatName( \"D\", date.getDay(), dayNamesShort, dayNames );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"o\":\n\t\t\t\t\t\t\toutput += formatNumber( \"o\",\n\t\t\t\t\t\t\t\tMath.round( ( new Date( date.getFullYear(), date.getMonth(), date.getDate() ).getTime() - new Date( date.getFullYear(), 0, 0 ).getTime() ) / 86400000 ), 3 );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"m\":\n\t\t\t\t\t\t\toutput += formatNumber( \"m\", date.getMonth() + 1, 2 );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"M\":\n\t\t\t\t\t\t\toutput += formatName( \"M\", date.getMonth(), monthNamesShort, monthNames );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"y\":\n\t\t\t\t\t\t\toutput += ( lookAhead( \"y\" ) ? date.getFullYear() :\n\t\t\t\t\t\t\t\t( date.getFullYear() % 100 < 10 ? \"0\" : \"\" ) + date.getFullYear() % 100 );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"@\":\n\t\t\t\t\t\t\toutput += date.getTime();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"!\":\n\t\t\t\t\t\t\toutput += date.getTime() * 10000 + this._ticksTo1970;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"'\":\n\t\t\t\t\t\t\tif ( lookAhead( \"'\" ) ) {\n\t\t\t\t\t\t\t\toutput += \"'\";\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tliteral = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\toutput += format.charAt( iFormat );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn output;\n\t},\n\n\t/* Extract all possible characters from the date format. */\n\t_possibleChars: function( format ) {\n\t\tvar iFormat,\n\t\t\tchars = \"\",\n\t\t\tliteral = false,\n\n\t\t\t// Check whether a format character is doubled\n\t\t\tlookAhead = function( match ) {\n\t\t\t\tvar matches = ( iFormat + 1 < format.length && format.charAt( iFormat + 1 ) === match );\n\t\t\t\tif ( matches ) {\n\t\t\t\t\tiFormat++;\n\t\t\t\t}\n\t\t\t\treturn matches;\n\t\t\t};\n\n\t\tfor ( iFormat = 0; iFormat < format.length; iFormat++ ) {\n\t\t\tif ( literal ) {\n\t\t\t\tif ( format.charAt( iFormat ) === \"'\" && !lookAhead( \"'\" ) ) {\n\t\t\t\t\tliteral = false;\n\t\t\t\t} else {\n\t\t\t\t\tchars += format.charAt( iFormat );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tswitch ( format.charAt( iFormat ) ) {\n\t\t\t\t\tcase \"d\": case \"m\": case \"y\": case \"@\":\n\t\t\t\t\t\tchars += \"0123456789\";\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"D\": case \"M\":\n\t\t\t\t\t\treturn null; // Accept anything\n\t\t\t\t\tcase \"'\":\n\t\t\t\t\t\tif ( lookAhead( \"'\" ) ) {\n\t\t\t\t\t\t\tchars += \"'\";\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tliteral = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tchars += format.charAt( iFormat );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn chars;\n\t},\n\n\t/* Get a setting value, defaulting if necessary. */\n\t_get: function( inst, name ) {\n\t\treturn inst.settings[ name ] !== undefined ?\n\t\t\tinst.settings[ name ] : this._defaults[ name ];\n\t},\n\n\t/* Parse existing date and initialise date picker. */\n\t_setDateFromField: function( inst, noDefault ) {\n\t\tif ( inst.input.val() === inst.lastVal ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar dateFormat = this._get( inst, \"dateFormat\" ),\n\t\t\tdates = inst.lastVal = inst.input ? inst.input.val() : null,\n\t\t\tdefaultDate = this._getDefaultDate( inst ),\n\t\t\tdate = defaultDate,\n\t\t\tsettings = this._getFormatConfig( inst );\n\n\t\ttry {\n\t\t\tdate = this.parseDate( dateFormat, dates, settings ) || defaultDate;\n\t\t} catch ( event ) {\n\t\t\tdates = ( noDefault ? \"\" : dates );\n\t\t}\n\t\tinst.selectedDay = date.getDate();\n\t\tinst.drawMonth = inst.selectedMonth = date.getMonth();\n\t\tinst.drawYear = inst.selectedYear = date.getFullYear();\n\t\tinst.currentDay = ( dates ? date.getDate() : 0 );\n\t\tinst.currentMonth = ( dates ? date.getMonth() : 0 );\n\t\tinst.currentYear = ( dates ? date.getFullYear() : 0 );\n\t\tthis._adjustInstDate( inst );\n\t},\n\n\t/* Retrieve the default date shown on opening. */\n\t_getDefaultDate: function( inst ) {\n\t\treturn this._restrictMinMax( inst,\n\t\t\tthis._determineDate( inst, this._get( inst, \"defaultDate\" ), new Date() ) );\n\t},\n\n\t/* A date may be specified as an exact value or a relative one. */\n\t_determineDate: function( inst, date, defaultDate ) {\n\t\tvar offsetNumeric = function( offset ) {\n\t\t\t\tvar date = new Date();\n\t\t\t\tdate.setDate( date.getDate() + offset );\n\t\t\t\treturn date;\n\t\t\t},\n\t\t\toffsetString = function( offset ) {\n\t\t\t\ttry {\n\t\t\t\t\treturn $.datepicker.parseDate( $.datepicker._get( inst, \"dateFormat\" ),\n\t\t\t\t\t\toffset, $.datepicker._getFormatConfig( inst ) );\n\t\t\t\t}\n\t\t\t\tcatch ( e ) {\n\n\t\t\t\t\t// Ignore\n\t\t\t\t}\n\n\t\t\t\tvar date = ( offset.toLowerCase().match( /^c/ ) ?\n\t\t\t\t\t$.datepicker._getDate( inst ) : null ) || new Date(),\n\t\t\t\t\tyear = date.getFullYear(),\n\t\t\t\t\tmonth = date.getMonth(),\n\t\t\t\t\tday = date.getDate(),\n\t\t\t\t\tpattern = /([+\\-]?[0-9]+)\\s*(d|D|w|W|m|M|y|Y)?/g,\n\t\t\t\t\tmatches = pattern.exec( offset );\n\n\t\t\t\twhile ( matches ) {\n\t\t\t\t\tswitch ( matches[ 2 ] || \"d\" ) {\n\t\t\t\t\t\tcase \"d\" : case \"D\" :\n\t\t\t\t\t\t\tday += parseInt( matches[ 1 ], 10 ); break;\n\t\t\t\t\t\tcase \"w\" : case \"W\" :\n\t\t\t\t\t\t\tday += parseInt( matches[ 1 ], 10 ) * 7; break;\n\t\t\t\t\t\tcase \"m\" : case \"M\" :\n\t\t\t\t\t\t\tmonth += parseInt( matches[ 1 ], 10 );\n\t\t\t\t\t\t\tday = Math.min( day, $.datepicker._getDaysInMonth( year, month ) );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"y\": case \"Y\" :\n\t\t\t\t\t\t\tyear += parseInt( matches[ 1 ], 10 );\n\t\t\t\t\t\t\tday = Math.min( day, $.datepicker._getDaysInMonth( year, month ) );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tmatches = pattern.exec( offset );\n\t\t\t\t}\n\t\t\t\treturn new Date( year, month, day );\n\t\t\t},\n\t\t\tnewDate = ( date == null || date === \"\" ? defaultDate : ( typeof date === \"string\" ? offsetString( date ) :\n\t\t\t\t( typeof date === \"number\" ? ( isNaN( date ) ? defaultDate : offsetNumeric( date ) ) : new Date( date.getTime() ) ) ) );\n\n\t\tnewDate = ( newDate && newDate.toString() === \"Invalid Date\" ? defaultDate : newDate );\n\t\tif ( newDate ) {\n\t\t\tnewDate.setHours( 0 );\n\t\t\tnewDate.setMinutes( 0 );\n\t\t\tnewDate.setSeconds( 0 );\n\t\t\tnewDate.setMilliseconds( 0 );\n\t\t}\n\t\treturn this._daylightSavingAdjust( newDate );\n\t},\n\n\t/* Handle switch to/from daylight saving.\n\t * Hours may be non-zero on daylight saving cut-over:\n\t * > 12 when midnight changeover, but then cannot generate\n\t * midnight datetime, so jump to 1AM, otherwise reset.\n\t * @param  date  (Date) the date to check\n\t * @return  (Date) the corrected date\n\t */\n\t_daylightSavingAdjust: function( date ) {\n\t\tif ( !date ) {\n\t\t\treturn null;\n\t\t}\n\t\tdate.setHours( date.getHours() > 12 ? date.getHours() + 2 : 0 );\n\t\treturn date;\n\t},\n\n\t/* Set the date(s) directly. */\n\t_setDate: function( inst, date, noChange ) {\n\t\tvar clear = !date,\n\t\t\torigMonth = inst.selectedMonth,\n\t\t\torigYear = inst.selectedYear,\n\t\t\tnewDate = this._restrictMinMax( inst, this._determineDate( inst, date, new Date() ) );\n\n\t\tinst.selectedDay = inst.currentDay = newDate.getDate();\n\t\tinst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth();\n\t\tinst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear();\n\t\tif ( ( origMonth !== inst.selectedMonth || origYear !== inst.selectedYear ) && !noChange ) {\n\t\t\tthis._notifyChange( inst );\n\t\t}\n\t\tthis._adjustInstDate( inst );\n\t\tif ( inst.input ) {\n\t\t\tinst.input.val( clear ? \"\" : this._formatDate( inst ) );\n\t\t}\n\t},\n\n\t/* Retrieve the date(s) directly. */\n\t_getDate: function( inst ) {\n\t\tvar startDate = ( !inst.currentYear || ( inst.input && inst.input.val() === \"\" ) ? null :\n\t\t\tthis._daylightSavingAdjust( new Date(\n\t\t\tinst.currentYear, inst.currentMonth, inst.currentDay ) ) );\n\t\t\treturn startDate;\n\t},\n\n\t/* Attach the onxxx handlers.  These are declared statically so\n\t * they work with static code transformers like Caja.\n\t */\n\t_attachHandlers: function( inst ) {\n\t\tvar stepMonths = this._get( inst, \"stepMonths\" ),\n\t\t\tid = \"#\" + inst.id.replace( /\\\\\\\\/g, \"\\\\\" );\n\t\tinst.dpDiv.find( \"[data-handler]\" ).map( function() {\n\t\t\tvar handler = {\n\t\t\t\tprev: function() {\n\t\t\t\t\t$.datepicker._adjustDate( id, -stepMonths, \"M\" );\n\t\t\t\t},\n\t\t\t\tnext: function() {\n\t\t\t\t\t$.datepicker._adjustDate( id, +stepMonths, \"M\" );\n\t\t\t\t},\n\t\t\t\thide: function() {\n\t\t\t\t\t$.datepicker._hideDatepicker();\n\t\t\t\t},\n\t\t\t\ttoday: function() {\n\t\t\t\t\t$.datepicker._gotoToday( id );\n\t\t\t\t},\n\t\t\t\tselectDay: function() {\n\t\t\t\t\t$.datepicker._selectDay( id, +this.getAttribute( \"data-month\" ), +this.getAttribute( \"data-year\" ), this );\n\t\t\t\t\treturn false;\n\t\t\t\t},\n\t\t\t\tselectMonth: function() {\n\t\t\t\t\t$.datepicker._selectMonthYear( id, this, \"M\" );\n\t\t\t\t\treturn false;\n\t\t\t\t},\n\t\t\t\tselectYear: function() {\n\t\t\t\t\t$.datepicker._selectMonthYear( id, this, \"Y\" );\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t};\n\t\t\t$( this ).on( this.getAttribute( \"data-event\" ), handler[ this.getAttribute( \"data-handler\" ) ] );\n\t\t} );\n\t},\n\n\t/* Generate the HTML for the current state of the date picker. */\n\t_generateHTML: function( inst ) {\n\t\tvar maxDraw, prevText, prev, nextText, next, currentText, gotoDate,\n\t\t\tcontrols, buttonPanel, firstDay, showWeek, dayNames, dayNamesMin,\n\t\t\tmonthNames, monthNamesShort, beforeShowDay, showOtherMonths,\n\t\t\tselectOtherMonths, defaultDate, html, dow, row, group, col, selectedDate,\n\t\t\tcornerClass, calender, thead, day, daysInMonth, leadDays, curRows, numRows,\n\t\t\tprintDate, dRow, tbody, daySettings, otherMonth, unselectable,\n\t\t\ttempDate = new Date(),\n\t\t\ttoday = this._daylightSavingAdjust(\n\t\t\t\tnew Date( tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() ) ), // clear time\n\t\t\tisRTL = this._get( inst, \"isRTL\" ),\n\t\t\tshowButtonPanel = this._get( inst, \"showButtonPanel\" ),\n\t\t\thideIfNoPrevNext = this._get( inst, \"hideIfNoPrevNext\" ),\n\t\t\tnavigationAsDateFormat = this._get( inst, \"navigationAsDateFormat\" ),\n\t\t\tnumMonths = this._getNumberOfMonths( inst ),\n\t\t\tshowCurrentAtPos = this._get( inst, \"showCurrentAtPos\" ),\n\t\t\tstepMonths = this._get( inst, \"stepMonths\" ),\n\t\t\tisMultiMonth = ( numMonths[ 0 ] !== 1 || numMonths[ 1 ] !== 1 ),\n\t\t\tcurrentDate = this._daylightSavingAdjust( ( !inst.currentDay ? new Date( 9999, 9, 9 ) :\n\t\t\t\tnew Date( inst.currentYear, inst.currentMonth, inst.currentDay ) ) ),\n\t\t\tminDate = this._getMinMaxDate( inst, \"min\" ),\n\t\t\tmaxDate = this._getMinMaxDate( inst, \"max\" ),\n\t\t\tdrawMonth = inst.drawMonth - showCurrentAtPos,\n\t\t\tdrawYear = inst.drawYear;\n\n\t\tif ( drawMonth < 0 ) {\n\t\t\tdrawMonth += 12;\n\t\t\tdrawYear--;\n\t\t}\n\t\tif ( maxDate ) {\n\t\t\tmaxDraw = this._daylightSavingAdjust( new Date( maxDate.getFullYear(),\n\t\t\t\tmaxDate.getMonth() - ( numMonths[ 0 ] * numMonths[ 1 ] ) + 1, maxDate.getDate() ) );\n\t\t\tmaxDraw = ( minDate && maxDraw < minDate ? minDate : maxDraw );\n\t\t\twhile ( this._daylightSavingAdjust( new Date( drawYear, drawMonth, 1 ) ) > maxDraw ) {\n\t\t\t\tdrawMonth--;\n\t\t\t\tif ( drawMonth < 0 ) {\n\t\t\t\t\tdrawMonth = 11;\n\t\t\t\t\tdrawYear--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tinst.drawMonth = drawMonth;\n\t\tinst.drawYear = drawYear;\n\n\t\tprevText = this._get( inst, \"prevText\" );\n\t\tprevText = ( !navigationAsDateFormat ? prevText : this.formatDate( prevText,\n\t\t\tthis._daylightSavingAdjust( new Date( drawYear, drawMonth - stepMonths, 1 ) ),\n\t\t\tthis._getFormatConfig( inst ) ) );\n\n\t\tprev = ( this._canAdjustMonth( inst, -1, drawYear, drawMonth ) ?\n\t\t\t\"<a class='ui-datepicker-prev ui-corner-all' data-handler='prev' data-event='click'\" +\n\t\t\t\" title='\" + prevText + \"'><span class='ui-icon ui-icon-circle-triangle-\" + ( isRTL ? \"e\" : \"w\" ) + \"'>\" + prevText + \"</span></a>\" :\n\t\t\t( hideIfNoPrevNext ? \"\" : \"<a class='ui-datepicker-prev ui-corner-all ui-state-disabled' title='\" + prevText + \"'><span class='ui-icon ui-icon-circle-triangle-\" + ( isRTL ? \"e\" : \"w\" ) + \"'>\" + prevText + \"</span></a>\" ) );\n\n\t\tnextText = this._get( inst, \"nextText\" );\n\t\tnextText = ( !navigationAsDateFormat ? nextText : this.formatDate( nextText,\n\t\t\tthis._daylightSavingAdjust( new Date( drawYear, drawMonth + stepMonths, 1 ) ),\n\t\t\tthis._getFormatConfig( inst ) ) );\n\n\t\tnext = ( this._canAdjustMonth( inst, +1, drawYear, drawMonth ) ?\n\t\t\t\"<a class='ui-datepicker-next ui-corner-all' data-handler='next' data-event='click'\" +\n\t\t\t\" title='\" + nextText + \"'><span class='ui-icon ui-icon-circle-triangle-\" + ( isRTL ? \"w\" : \"e\" ) + \"'>\" + nextText + \"</span></a>\" :\n\t\t\t( hideIfNoPrevNext ? \"\" : \"<a class='ui-datepicker-next ui-corner-all ui-state-disabled' title='\" + nextText + \"'><span class='ui-icon ui-icon-circle-triangle-\" + ( isRTL ? \"w\" : \"e\" ) + \"'>\" + nextText + \"</span></a>\" ) );\n\n\t\tcurrentText = this._get( inst, \"currentText\" );\n\t\tgotoDate = ( this._get( inst, \"gotoCurrent\" ) && inst.currentDay ? currentDate : today );\n\t\tcurrentText = ( !navigationAsDateFormat ? currentText :\n\t\t\tthis.formatDate( currentText, gotoDate, this._getFormatConfig( inst ) ) );\n\n\t\tcontrols = ( !inst.inline ? \"<button type='button' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>\" +\n\t\t\tthis._get( inst, \"closeText\" ) + \"</button>\" : \"\" );\n\n\t\tbuttonPanel = ( showButtonPanel ) ? \"<div class='ui-datepicker-buttonpane ui-widget-content'>\" + ( isRTL ? controls : \"\" ) +\n\t\t\t( this._isInRange( inst, gotoDate ) ? \"<button type='button' class='ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all' data-handler='today' data-event='click'\" +\n\t\t\t\">\" + currentText + \"</button>\" : \"\" ) + ( isRTL ? \"\" : controls ) + \"</div>\" : \"\";\n\n\t\tfirstDay = parseInt( this._get( inst, \"firstDay\" ), 10 );\n\t\tfirstDay = ( isNaN( firstDay ) ? 0 : firstDay );\n\n\t\tshowWeek = this._get( inst, \"showWeek\" );\n\t\tdayNames = this._get( inst, \"dayNames\" );\n\t\tdayNamesMin = this._get( inst, \"dayNamesMin\" );\n\t\tmonthNames = this._get( inst, \"monthNames\" );\n\t\tmonthNamesShort = this._get( inst, \"monthNamesShort\" );\n\t\tbeforeShowDay = this._get( inst, \"beforeShowDay\" );\n\t\tshowOtherMonths = this._get( inst, \"showOtherMonths\" );\n\t\tselectOtherMonths = this._get( inst, \"selectOtherMonths\" );\n\t\tdefaultDate = this._getDefaultDate( inst );\n\t\thtml = \"\";\n\n\t\tfor ( row = 0; row < numMonths[ 0 ]; row++ ) {\n\t\t\tgroup = \"\";\n\t\t\tthis.maxRows = 4;\n\t\t\tfor ( col = 0; col < numMonths[ 1 ]; col++ ) {\n\t\t\t\tselectedDate = this._daylightSavingAdjust( new Date( drawYear, drawMonth, inst.selectedDay ) );\n\t\t\t\tcornerClass = \" ui-corner-all\";\n\t\t\t\tcalender = \"\";\n\t\t\t\tif ( isMultiMonth ) {\n\t\t\t\t\tcalender += \"<div class='ui-datepicker-group\";\n\t\t\t\t\tif ( numMonths[ 1 ] > 1 ) {\n\t\t\t\t\t\tswitch ( col ) {\n\t\t\t\t\t\t\tcase 0: calender += \" ui-datepicker-group-first\";\n\t\t\t\t\t\t\t\tcornerClass = \" ui-corner-\" + ( isRTL ? \"right\" : \"left\" ); break;\n\t\t\t\t\t\t\tcase numMonths[ 1 ] - 1: calender += \" ui-datepicker-group-last\";\n\t\t\t\t\t\t\t\tcornerClass = \" ui-corner-\" + ( isRTL ? \"left\" : \"right\" ); break;\n\t\t\t\t\t\t\tdefault: calender += \" ui-datepicker-group-middle\"; cornerClass = \"\"; break;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcalender += \"'>\";\n\t\t\t\t}\n\t\t\t\tcalender += \"<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix\" + cornerClass + \"'>\" +\n\t\t\t\t\t( /all|left/.test( cornerClass ) && row === 0 ? ( isRTL ? next : prev ) : \"\" ) +\n\t\t\t\t\t( /all|right/.test( cornerClass ) && row === 0 ? ( isRTL ? prev : next ) : \"\" ) +\n\t\t\t\t\tthis._generateMonthYearHeader( inst, drawMonth, drawYear, minDate, maxDate,\n\t\t\t\t\trow > 0 || col > 0, monthNames, monthNamesShort ) + // draw month headers\n\t\t\t\t\t\"</div><table class='ui-datepicker-calendar'><thead>\" +\n\t\t\t\t\t\"<tr>\";\n\t\t\t\tthead = ( showWeek ? \"<th class='ui-datepicker-week-col'>\" + this._get( inst, \"weekHeader\" ) + \"</th>\" : \"\" );\n\t\t\t\tfor ( dow = 0; dow < 7; dow++ ) { // days of the week\n\t\t\t\t\tday = ( dow + firstDay ) % 7;\n\t\t\t\t\tthead += \"<th scope='col'\" + ( ( dow + firstDay + 6 ) % 7 >= 5 ? \" class='ui-datepicker-week-end'\" : \"\" ) + \">\" +\n\t\t\t\t\t\t\"<span title='\" + dayNames[ day ] + \"'>\" + dayNamesMin[ day ] + \"</span></th>\";\n\t\t\t\t}\n\t\t\t\tcalender += thead + \"</tr></thead><tbody>\";\n\t\t\t\tdaysInMonth = this._getDaysInMonth( drawYear, drawMonth );\n\t\t\t\tif ( drawYear === inst.selectedYear && drawMonth === inst.selectedMonth ) {\n\t\t\t\t\tinst.selectedDay = Math.min( inst.selectedDay, daysInMonth );\n\t\t\t\t}\n\t\t\t\tleadDays = ( this._getFirstDayOfMonth( drawYear, drawMonth ) - firstDay + 7 ) % 7;\n\t\t\t\tcurRows = Math.ceil( ( leadDays + daysInMonth ) / 7 ); // calculate the number of rows to generate\n\t\t\t\tnumRows = ( isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows ); //If multiple months, use the higher number of rows (see #7043)\n\t\t\t\tthis.maxRows = numRows;\n\t\t\t\tprintDate = this._daylightSavingAdjust( new Date( drawYear, drawMonth, 1 - leadDays ) );\n\t\t\t\tfor ( dRow = 0; dRow < numRows; dRow++ ) { // create date picker rows\n\t\t\t\t\tcalender += \"<tr>\";\n\t\t\t\t\ttbody = ( !showWeek ? \"\" : \"<td class='ui-datepicker-week-col'>\" +\n\t\t\t\t\t\tthis._get( inst, \"calculateWeek\" )( printDate ) + \"</td>\" );\n\t\t\t\t\tfor ( dow = 0; dow < 7; dow++ ) { // create date picker days\n\t\t\t\t\t\tdaySettings = ( beforeShowDay ?\n\t\t\t\t\t\t\tbeforeShowDay.apply( ( inst.input ? inst.input[ 0 ] : null ), [ printDate ] ) : [ true, \"\" ] );\n\t\t\t\t\t\totherMonth = ( printDate.getMonth() !== drawMonth );\n\t\t\t\t\t\tunselectable = ( otherMonth && !selectOtherMonths ) || !daySettings[ 0 ] ||\n\t\t\t\t\t\t\t( minDate && printDate < minDate ) || ( maxDate && printDate > maxDate );\n\t\t\t\t\t\ttbody += \"<td class='\" +\n\t\t\t\t\t\t\t( ( dow + firstDay + 6 ) % 7 >= 5 ? \" ui-datepicker-week-end\" : \"\" ) + // highlight weekends\n\t\t\t\t\t\t\t( otherMonth ? \" ui-datepicker-other-month\" : \"\" ) + // highlight days from other months\n\t\t\t\t\t\t\t( ( printDate.getTime() === selectedDate.getTime() && drawMonth === inst.selectedMonth && inst._keyEvent ) || // user pressed key\n\t\t\t\t\t\t\t( defaultDate.getTime() === printDate.getTime() && defaultDate.getTime() === selectedDate.getTime() ) ?\n\n\t\t\t\t\t\t\t// or defaultDate is current printedDate and defaultDate is selectedDate\n\t\t\t\t\t\t\t\" \" + this._dayOverClass : \"\" ) + // highlight selected day\n\t\t\t\t\t\t\t( unselectable ? \" \" + this._unselectableClass + \" ui-state-disabled\" : \"\" ) +  // highlight unselectable days\n\t\t\t\t\t\t\t( otherMonth && !showOtherMonths ? \"\" : \" \" + daySettings[ 1 ] + // highlight custom dates\n\t\t\t\t\t\t\t( printDate.getTime() === currentDate.getTime() ? \" \" + this._currentClass : \"\" ) + // highlight selected day\n\t\t\t\t\t\t\t( printDate.getTime() === today.getTime() ? \" ui-datepicker-today\" : \"\" ) ) + \"'\" + // highlight today (if different)\n\t\t\t\t\t\t\t( ( !otherMonth || showOtherMonths ) && daySettings[ 2 ] ? \" title='\" + daySettings[ 2 ].replace( /'/g, \"&#39;\" ) + \"'\" : \"\" ) + // cell title\n\t\t\t\t\t\t\t( unselectable ? \"\" : \" data-handler='selectDay' data-event='click' data-month='\" + printDate.getMonth() + \"' data-year='\" + printDate.getFullYear() + \"'\" ) + \">\" + // actions\n\t\t\t\t\t\t\t( otherMonth && !showOtherMonths ? \"&#xa0;\" : // display for other months\n\t\t\t\t\t\t\t( unselectable ? \"<span class='ui-state-default'>\" + printDate.getDate() + \"</span>\" : \"<a class='ui-state-default\" +\n\t\t\t\t\t\t\t( printDate.getTime() === today.getTime() ? \" ui-state-highlight\" : \"\" ) +\n\t\t\t\t\t\t\t( printDate.getTime() === currentDate.getTime() ? \" ui-state-active\" : \"\" ) + // highlight selected day\n\t\t\t\t\t\t\t( otherMonth ? \" ui-priority-secondary\" : \"\" ) + // distinguish dates from other months\n\t\t\t\t\t\t\t\"' href='#'>\" + printDate.getDate() + \"</a>\" ) ) + \"</td>\"; // display selectable date\n\t\t\t\t\t\tprintDate.setDate( printDate.getDate() + 1 );\n\t\t\t\t\t\tprintDate = this._daylightSavingAdjust( printDate );\n\t\t\t\t\t}\n\t\t\t\t\tcalender += tbody + \"</tr>\";\n\t\t\t\t}\n\t\t\t\tdrawMonth++;\n\t\t\t\tif ( drawMonth > 11 ) {\n\t\t\t\t\tdrawMonth = 0;\n\t\t\t\t\tdrawYear++;\n\t\t\t\t}\n\t\t\t\tcalender += \"</tbody></table>\" + ( isMultiMonth ? \"</div>\" +\n\t\t\t\t\t\t\t( ( numMonths[ 0 ] > 0 && col === numMonths[ 1 ] - 1 ) ? \"<div class='ui-datepicker-row-break'></div>\" : \"\" ) : \"\" );\n\t\t\t\tgroup += calender;\n\t\t\t}\n\t\t\thtml += group;\n\t\t}\n\t\thtml += buttonPanel;\n\t\tinst._keyEvent = false;\n\t\treturn html;\n\t},\n\n\t/* Generate the month and year header. */\n\t_generateMonthYearHeader: function( inst, drawMonth, drawYear, minDate, maxDate,\n\t\t\tsecondary, monthNames, monthNamesShort ) {\n\n\t\tvar inMinYear, inMaxYear, month, years, thisYear, determineYear, year, endYear,\n\t\t\tchangeMonth = this._get( inst, \"changeMonth\" ),\n\t\t\tchangeYear = this._get( inst, \"changeYear\" ),\n\t\t\tshowMonthAfterYear = this._get( inst, \"showMonthAfterYear\" ),\n\t\t\thtml = \"<div class='ui-datepicker-title'>\",\n\t\t\tmonthHtml = \"\";\n\n\t\t// Month selection\n\t\tif ( secondary || !changeMonth ) {\n\t\t\tmonthHtml += \"<span class='ui-datepicker-month'>\" + monthNames[ drawMonth ] + \"</span>\";\n\t\t} else {\n\t\t\tinMinYear = ( minDate && minDate.getFullYear() === drawYear );\n\t\t\tinMaxYear = ( maxDate && maxDate.getFullYear() === drawYear );\n\t\t\tmonthHtml += \"<select class='ui-datepicker-month' data-handler='selectMonth' data-event='change'>\";\n\t\t\tfor ( month = 0; month < 12; month++ ) {\n\t\t\t\tif ( ( !inMinYear || month >= minDate.getMonth() ) && ( !inMaxYear || month <= maxDate.getMonth() ) ) {\n\t\t\t\t\tmonthHtml += \"<option value='\" + month + \"'\" +\n\t\t\t\t\t\t( month === drawMonth ? \" selected='selected'\" : \"\" ) +\n\t\t\t\t\t\t\">\" + monthNamesShort[ month ] + \"</option>\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tmonthHtml += \"</select>\";\n\t\t}\n\n\t\tif ( !showMonthAfterYear ) {\n\t\t\thtml += monthHtml + ( secondary || !( changeMonth && changeYear ) ? \"&#xa0;\" : \"\" );\n\t\t}\n\n\t\t// Year selection\n\t\tif ( !inst.yearshtml ) {\n\t\t\tinst.yearshtml = \"\";\n\t\t\tif ( secondary || !changeYear ) {\n\t\t\t\thtml += \"<span class='ui-datepicker-year'>\" + drawYear + \"</span>\";\n\t\t\t} else {\n\n\t\t\t\t// determine range of years to display\n\t\t\t\tyears = this._get( inst, \"yearRange\" ).split( \":\" );\n\t\t\t\tthisYear = new Date().getFullYear();\n\t\t\t\tdetermineYear = function( value ) {\n\t\t\t\t\tvar year = ( value.match( /c[+\\-].*/ ) ? drawYear + parseInt( value.substring( 1 ), 10 ) :\n\t\t\t\t\t\t( value.match( /[+\\-].*/ ) ? thisYear + parseInt( value, 10 ) :\n\t\t\t\t\t\tparseInt( value, 10 ) ) );\n\t\t\t\t\treturn ( isNaN( year ) ? thisYear : year );\n\t\t\t\t};\n\t\t\t\tyear = determineYear( years[ 0 ] );\n\t\t\t\tendYear = Math.max( year, determineYear( years[ 1 ] || \"\" ) );\n\t\t\t\tyear = ( minDate ? Math.max( year, minDate.getFullYear() ) : year );\n\t\t\t\tendYear = ( maxDate ? Math.min( endYear, maxDate.getFullYear() ) : endYear );\n\t\t\t\tinst.yearshtml += \"<select class='ui-datepicker-year' data-handler='selectYear' data-event='change'>\";\n\t\t\t\tfor ( ; year <= endYear; year++ ) {\n\t\t\t\t\tinst.yearshtml += \"<option value='\" + year + \"'\" +\n\t\t\t\t\t\t( year === drawYear ? \" selected='selected'\" : \"\" ) +\n\t\t\t\t\t\t\">\" + year + \"</option>\";\n\t\t\t\t}\n\t\t\t\tinst.yearshtml += \"</select>\";\n\n\t\t\t\thtml += inst.yearshtml;\n\t\t\t\tinst.yearshtml = null;\n\t\t\t}\n\t\t}\n\n\t\thtml += this._get( inst, \"yearSuffix\" );\n\t\tif ( showMonthAfterYear ) {\n\t\t\thtml += ( secondary || !( changeMonth && changeYear ) ? \"&#xa0;\" : \"\" ) + monthHtml;\n\t\t}\n\t\thtml += \"</div>\"; // Close datepicker_header\n\t\treturn html;\n\t},\n\n\t/* Adjust one of the date sub-fields. */\n\t_adjustInstDate: function( inst, offset, period ) {\n\t\tvar year = inst.selectedYear + ( period === \"Y\" ? offset : 0 ),\n\t\t\tmonth = inst.selectedMonth + ( period === \"M\" ? offset : 0 ),\n\t\t\tday = Math.min( inst.selectedDay, this._getDaysInMonth( year, month ) ) + ( period === \"D\" ? offset : 0 ),\n\t\t\tdate = this._restrictMinMax( inst, this._daylightSavingAdjust( new Date( year, month, day ) ) );\n\n\t\tinst.selectedDay = date.getDate();\n\t\tinst.drawMonth = inst.selectedMonth = date.getMonth();\n\t\tinst.drawYear = inst.selectedYear = date.getFullYear();\n\t\tif ( period === \"M\" || period === \"Y\" ) {\n\t\t\tthis._notifyChange( inst );\n\t\t}\n\t},\n\n\t/* Ensure a date is within any min/max bounds. */\n\t_restrictMinMax: function( inst, date ) {\n\t\tvar minDate = this._getMinMaxDate( inst, \"min\" ),\n\t\t\tmaxDate = this._getMinMaxDate( inst, \"max\" ),\n\t\t\tnewDate = ( minDate && date < minDate ? minDate : date );\n\t\treturn ( maxDate && newDate > maxDate ? maxDate : newDate );\n\t},\n\n\t/* Notify change of month/year. */\n\t_notifyChange: function( inst ) {\n\t\tvar onChange = this._get( inst, \"onChangeMonthYear\" );\n\t\tif ( onChange ) {\n\t\t\tonChange.apply( ( inst.input ? inst.input[ 0 ] : null ),\n\t\t\t\t[ inst.selectedYear, inst.selectedMonth + 1, inst ] );\n\t\t}\n\t},\n\n\t/* Determine the number of months to show. */\n\t_getNumberOfMonths: function( inst ) {\n\t\tvar numMonths = this._get( inst, \"numberOfMonths\" );\n\t\treturn ( numMonths == null ? [ 1, 1 ] : ( typeof numMonths === \"number\" ? [ 1, numMonths ] : numMonths ) );\n\t},\n\n\t/* Determine the current maximum date - ensure no time components are set. */\n\t_getMinMaxDate: function( inst, minMax ) {\n\t\treturn this._determineDate( inst, this._get( inst, minMax + \"Date\" ), null );\n\t},\n\n\t/* Find the number of days in a given month. */\n\t_getDaysInMonth: function( year, month ) {\n\t\treturn 32 - this._daylightSavingAdjust( new Date( year, month, 32 ) ).getDate();\n\t},\n\n\t/* Find the day of the week of the first of a month. */\n\t_getFirstDayOfMonth: function( year, month ) {\n\t\treturn new Date( year, month, 1 ).getDay();\n\t},\n\n\t/* Determines if we should allow a \"next/prev\" month display change. */\n\t_canAdjustMonth: function( inst, offset, curYear, curMonth ) {\n\t\tvar numMonths = this._getNumberOfMonths( inst ),\n\t\t\tdate = this._daylightSavingAdjust( new Date( curYear,\n\t\t\tcurMonth + ( offset < 0 ? offset : numMonths[ 0 ] * numMonths[ 1 ] ), 1 ) );\n\n\t\tif ( offset < 0 ) {\n\t\t\tdate.setDate( this._getDaysInMonth( date.getFullYear(), date.getMonth() ) );\n\t\t}\n\t\treturn this._isInRange( inst, date );\n\t},\n\n\t/* Is the given date in the accepted range? */\n\t_isInRange: function( inst, date ) {\n\t\tvar yearSplit, currentYear,\n\t\t\tminDate = this._getMinMaxDate( inst, \"min\" ),\n\t\t\tmaxDate = this._getMinMaxDate( inst, \"max\" ),\n\t\t\tminYear = null,\n\t\t\tmaxYear = null,\n\t\t\tyears = this._get( inst, \"yearRange\" );\n\t\t\tif ( years ) {\n\t\t\t\tyearSplit = years.split( \":\" );\n\t\t\t\tcurrentYear = new Date().getFullYear();\n\t\t\t\tminYear = parseInt( yearSplit[ 0 ], 10 );\n\t\t\t\tmaxYear = parseInt( yearSplit[ 1 ], 10 );\n\t\t\t\tif ( yearSplit[ 0 ].match( /[+\\-].*/ ) ) {\n\t\t\t\t\tminYear += currentYear;\n\t\t\t\t}\n\t\t\t\tif ( yearSplit[ 1 ].match( /[+\\-].*/ ) ) {\n\t\t\t\t\tmaxYear += currentYear;\n\t\t\t\t}\n\t\t\t}\n\n\t\treturn ( ( !minDate || date.getTime() >= minDate.getTime() ) &&\n\t\t\t( !maxDate || date.getTime() <= maxDate.getTime() ) &&\n\t\t\t( !minYear || date.getFullYear() >= minYear ) &&\n\t\t\t( !maxYear || date.getFullYear() <= maxYear ) );\n\t},\n\n\t/* Provide the configuration settings for formatting/parsing. */\n\t_getFormatConfig: function( inst ) {\n\t\tvar shortYearCutoff = this._get( inst, \"shortYearCutoff\" );\n\t\tshortYearCutoff = ( typeof shortYearCutoff !== \"string\" ? shortYearCutoff :\n\t\t\tnew Date().getFullYear() % 100 + parseInt( shortYearCutoff, 10 ) );\n\t\treturn { shortYearCutoff: shortYearCutoff,\n\t\t\tdayNamesShort: this._get( inst, \"dayNamesShort\" ), dayNames: this._get( inst, \"dayNames\" ),\n\t\t\tmonthNamesShort: this._get( inst, \"monthNamesShort\" ), monthNames: this._get( inst, \"monthNames\" ) };\n\t},\n\n\t/* Format the given date for display. */\n\t_formatDate: function( inst, day, month, year ) {\n\t\tif ( !day ) {\n\t\t\tinst.currentDay = inst.selectedDay;\n\t\t\tinst.currentMonth = inst.selectedMonth;\n\t\t\tinst.currentYear = inst.selectedYear;\n\t\t}\n\t\tvar date = ( day ? ( typeof day === \"object\" ? day :\n\t\t\tthis._daylightSavingAdjust( new Date( year, month, day ) ) ) :\n\t\t\tthis._daylightSavingAdjust( new Date( inst.currentYear, inst.currentMonth, inst.currentDay ) ) );\n\t\treturn this.formatDate( this._get( inst, \"dateFormat\" ), date, this._getFormatConfig( inst ) );\n\t}\n} );\n\n/*\n * Bind hover events for datepicker elements.\n * Done via delegate so the binding only occurs once in the lifetime of the parent div.\n * Global datepicker_instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.\n */\nfunction datepicker_bindHover( dpDiv ) {\n\tvar selector = \"button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a\";\n\treturn dpDiv.on( \"mouseout\", selector, function() {\n\t\t\t$( this ).removeClass( \"ui-state-hover\" );\n\t\t\tif ( this.className.indexOf( \"ui-datepicker-prev\" ) !== -1 ) {\n\t\t\t\t$( this ).removeClass( \"ui-datepicker-prev-hover\" );\n\t\t\t}\n\t\t\tif ( this.className.indexOf( \"ui-datepicker-next\" ) !== -1 ) {\n\t\t\t\t$( this ).removeClass( \"ui-datepicker-next-hover\" );\n\t\t\t}\n\t\t} )\n\t\t.on( \"mouseover\", selector, datepicker_handleMouseover );\n}\n\nfunction datepicker_handleMouseover() {\n\tif ( !$.datepicker._isDisabledDatepicker( datepicker_instActive.inline ? datepicker_instActive.dpDiv.parent()[ 0 ] : datepicker_instActive.input[ 0 ] ) ) {\n\t\t$( this ).parents( \".ui-datepicker-calendar\" ).find( \"a\" ).removeClass( \"ui-state-hover\" );\n\t\t$( this ).addClass( \"ui-state-hover\" );\n\t\tif ( this.className.indexOf( \"ui-datepicker-prev\" ) !== -1 ) {\n\t\t\t$( this ).addClass( \"ui-datepicker-prev-hover\" );\n\t\t}\n\t\tif ( this.className.indexOf( \"ui-datepicker-next\" ) !== -1 ) {\n\t\t\t$( this ).addClass( \"ui-datepicker-next-hover\" );\n\t\t}\n\t}\n}\n\n/* jQuery extend now ignores nulls! */\nfunction datepicker_extendRemove( target, props ) {\n\t$.extend( target, props );\n\tfor ( var name in props ) {\n\t\tif ( props[ name ] == null ) {\n\t\t\ttarget[ name ] = props[ name ];\n\t\t}\n\t}\n\treturn target;\n}\n\n/* Invoke the datepicker functionality.\n   @param  options  string - a command, optionally followed by additional parameters or\n\t\t\t\t\tObject - settings for attaching new datepicker functionality\n   @return  jQuery object */\n$.fn.datepicker = function( options ) {\n\n\t/* Verify an empty collection wasn't passed - Fixes #6976 */\n\tif ( !this.length ) {\n\t\treturn this;\n\t}\n\n\t/* Initialise the date picker. */\n\tif ( !$.datepicker.initialized ) {\n\t\t$( document ).on( \"mousedown\", $.datepicker._checkExternalClick );\n\t\t$.datepicker.initialized = true;\n\t}\n\n\t/* Append datepicker main container to body if not exist. */\n\tif ( $( \"#\" + $.datepicker._mainDivId ).length === 0 ) {\n\t\t$( \"body\" ).append( $.datepicker.dpDiv );\n\t}\n\n\tvar otherArgs = Array.prototype.slice.call( arguments, 1 );\n\tif ( typeof options === \"string\" && ( options === \"isDisabled\" || options === \"getDate\" || options === \"widget\" ) ) {\n\t\treturn $.datepicker[ \"_\" + options + \"Datepicker\" ].\n\t\t\tapply( $.datepicker, [ this[ 0 ] ].concat( otherArgs ) );\n\t}\n\tif ( options === \"option\" && arguments.length === 2 && typeof arguments[ 1 ] === \"string\" ) {\n\t\treturn $.datepicker[ \"_\" + options + \"Datepicker\" ].\n\t\t\tapply( $.datepicker, [ this[ 0 ] ].concat( otherArgs ) );\n\t}\n\treturn this.each( function() {\n\t\ttypeof options === \"string\" ?\n\t\t\t$.datepicker[ \"_\" + options + \"Datepicker\" ].\n\t\t\t\tapply( $.datepicker, [ this ].concat( otherArgs ) ) :\n\t\t\t$.datepicker._attachDatepicker( this, options );\n\t} );\n};\n\n$.datepicker = new Datepicker(); // singleton instance\n$.datepicker.initialized = false;\n$.datepicker.uuid = new Date().getTime();\n$.datepicker.version = \"1.12.1\";\n\nvar widgetsDatepicker = $.datepicker;\n\n\n\n\n// This file is deprecated\nvar ie = $.ui.ie = !!/msie [\\w.]+/.exec( navigator.userAgent.toLowerCase() );\n\n/*!\n * jQuery UI Mouse 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Mouse\n//>>group: Widgets\n//>>description: Abstracts mouse-based interactions to assist in creating certain widgets.\n//>>docs: http://api.jqueryui.com/mouse/\n\n\n\nvar mouseHandled = false;\n$( document ).on( \"mouseup\", function() {\n\tmouseHandled = false;\n} );\n\nvar widgetsMouse = $.widget( \"ui.mouse\", {\n\tversion: \"1.12.1\",\n\toptions: {\n\t\tcancel: \"input, textarea, button, select, option\",\n\t\tdistance: 1,\n\t\tdelay: 0\n\t},\n\t_mouseInit: function() {\n\t\tvar that = this;\n\n\t\tthis.element\n\t\t\t.on( \"mousedown.\" + this.widgetName, function( event ) {\n\t\t\t\treturn that._mouseDown( event );\n\t\t\t} )\n\t\t\t.on( \"click.\" + this.widgetName, function( event ) {\n\t\t\t\tif ( true === $.data( event.target, that.widgetName + \".preventClickEvent\" ) ) {\n\t\t\t\t\t$.removeData( event.target, that.widgetName + \".preventClickEvent\" );\n\t\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} );\n\n\t\tthis.started = false;\n\t},\n\n\t// TODO: make sure destroying one instance of mouse doesn't mess with\n\t// other instances of mouse\n\t_mouseDestroy: function() {\n\t\tthis.element.off( \".\" + this.widgetName );\n\t\tif ( this._mouseMoveDelegate ) {\n\t\t\tthis.document\n\t\t\t\t.off( \"mousemove.\" + this.widgetName, this._mouseMoveDelegate )\n\t\t\t\t.off( \"mouseup.\" + this.widgetName, this._mouseUpDelegate );\n\t\t}\n\t},\n\n\t_mouseDown: function( event ) {\n\n\t\t// don't let more than one widget handle mouseStart\n\t\tif ( mouseHandled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._mouseMoved = false;\n\n\t\t// We may have missed mouseup (out of window)\n\t\t( this._mouseStarted && this._mouseUp( event ) );\n\n\t\tthis._mouseDownEvent = event;\n\n\t\tvar that = this,\n\t\t\tbtnIsLeft = ( event.which === 1 ),\n\n\t\t\t// event.target.nodeName works around a bug in IE 8 with\n\t\t\t// disabled inputs (#7620)\n\t\t\telIsCancel = ( typeof this.options.cancel === \"string\" && event.target.nodeName ?\n\t\t\t\t$( event.target ).closest( this.options.cancel ).length : false );\n\t\tif ( !btnIsLeft || elIsCancel || !this._mouseCapture( event ) ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tthis.mouseDelayMet = !this.options.delay;\n\t\tif ( !this.mouseDelayMet ) {\n\t\t\tthis._mouseDelayTimer = setTimeout( function() {\n\t\t\t\tthat.mouseDelayMet = true;\n\t\t\t}, this.options.delay );\n\t\t}\n\n\t\tif ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) {\n\t\t\tthis._mouseStarted = ( this._mouseStart( event ) !== false );\n\t\t\tif ( !this._mouseStarted ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\t// Click event may never have fired (Gecko & Opera)\n\t\tif ( true === $.data( event.target, this.widgetName + \".preventClickEvent\" ) ) {\n\t\t\t$.removeData( event.target, this.widgetName + \".preventClickEvent\" );\n\t\t}\n\n\t\t// These delegates are required to keep context\n\t\tthis._mouseMoveDelegate = function( event ) {\n\t\t\treturn that._mouseMove( event );\n\t\t};\n\t\tthis._mouseUpDelegate = function( event ) {\n\t\t\treturn that._mouseUp( event );\n\t\t};\n\n\t\tthis.document\n\t\t\t.on( \"mousemove.\" + this.widgetName, this._mouseMoveDelegate )\n\t\t\t.on( \"mouseup.\" + this.widgetName, this._mouseUpDelegate );\n\n\t\tevent.preventDefault();\n\n\t\tmouseHandled = true;\n\t\treturn true;\n\t},\n\n\t_mouseMove: function( event ) {\n\n\t\t// Only check for mouseups outside the document if you've moved inside the document\n\t\t// at least once. This prevents the firing of mouseup in the case of IE<9, which will\n\t\t// fire a mousemove event if content is placed under the cursor. See #7778\n\t\t// Support: IE <9\n\t\tif ( this._mouseMoved ) {\n\n\t\t\t// IE mouseup check - mouseup happened when mouse was out of window\n\t\t\tif ( $.ui.ie && ( !document.documentMode || document.documentMode < 9 ) &&\n\t\t\t\t\t!event.button ) {\n\t\t\t\treturn this._mouseUp( event );\n\n\t\t\t// Iframe mouseup check - mouseup occurred in another document\n\t\t\t} else if ( !event.which ) {\n\n\t\t\t\t// Support: Safari <=8 - 9\n\t\t\t\t// Safari sets which to 0 if you press any of the following keys\n\t\t\t\t// during a drag (#14461)\n\t\t\t\tif ( event.originalEvent.altKey || event.originalEvent.ctrlKey ||\n\t\t\t\t\t\tevent.originalEvent.metaKey || event.originalEvent.shiftKey ) {\n\t\t\t\t\tthis.ignoreMissingWhich = true;\n\t\t\t\t} else if ( !this.ignoreMissingWhich ) {\n\t\t\t\t\treturn this._mouseUp( event );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( event.which || event.button ) {\n\t\t\tthis._mouseMoved = true;\n\t\t}\n\n\t\tif ( this._mouseStarted ) {\n\t\t\tthis._mouseDrag( event );\n\t\t\treturn event.preventDefault();\n\t\t}\n\n\t\tif ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) {\n\t\t\tthis._mouseStarted =\n\t\t\t\t( this._mouseStart( this._mouseDownEvent, event ) !== false );\n\t\t\t( this._mouseStarted ? this._mouseDrag( event ) : this._mouseUp( event ) );\n\t\t}\n\n\t\treturn !this._mouseStarted;\n\t},\n\n\t_mouseUp: function( event ) {\n\t\tthis.document\n\t\t\t.off( \"mousemove.\" + this.widgetName, this._mouseMoveDelegate )\n\t\t\t.off( \"mouseup.\" + this.widgetName, this._mouseUpDelegate );\n\n\t\tif ( this._mouseStarted ) {\n\t\t\tthis._mouseStarted = false;\n\n\t\t\tif ( event.target === this._mouseDownEvent.target ) {\n\t\t\t\t$.data( event.target, this.widgetName + \".preventClickEvent\", true );\n\t\t\t}\n\n\t\t\tthis._mouseStop( event );\n\t\t}\n\n\t\tif ( this._mouseDelayTimer ) {\n\t\t\tclearTimeout( this._mouseDelayTimer );\n\t\t\tdelete this._mouseDelayTimer;\n\t\t}\n\n\t\tthis.ignoreMissingWhich = false;\n\t\tmouseHandled = false;\n\t\tevent.preventDefault();\n\t},\n\n\t_mouseDistanceMet: function( event ) {\n\t\treturn ( Math.max(\n\t\t\t\tMath.abs( this._mouseDownEvent.pageX - event.pageX ),\n\t\t\t\tMath.abs( this._mouseDownEvent.pageY - event.pageY )\n\t\t\t) >= this.options.distance\n\t\t);\n\t},\n\n\t_mouseDelayMet: function( /* event */ ) {\n\t\treturn this.mouseDelayMet;\n\t},\n\n\t// These are placeholder methods, to be overriden by extending plugin\n\t_mouseStart: function( /* event */ ) {},\n\t_mouseDrag: function( /* event */ ) {},\n\t_mouseStop: function( /* event */ ) {},\n\t_mouseCapture: function( /* event */ ) { return true; }\n} );\n\n\n\n\n// $.ui.plugin is deprecated. Use $.widget() extensions instead.\nvar plugin = $.ui.plugin = {\n\tadd: function( module, option, set ) {\n\t\tvar i,\n\t\t\tproto = $.ui[ module ].prototype;\n\t\tfor ( i in set ) {\n\t\t\tproto.plugins[ i ] = proto.plugins[ i ] || [];\n\t\t\tproto.plugins[ i ].push( [ option, set[ i ] ] );\n\t\t}\n\t},\n\tcall: function( instance, name, args, allowDisconnected ) {\n\t\tvar i,\n\t\t\tset = instance.plugins[ name ];\n\n\t\tif ( !set ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( !allowDisconnected && ( !instance.element[ 0 ].parentNode ||\n\t\t\t\tinstance.element[ 0 ].parentNode.nodeType === 11 ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor ( i = 0; i < set.length; i++ ) {\n\t\t\tif ( instance.options[ set[ i ][ 0 ] ] ) {\n\t\t\t\tset[ i ][ 1 ].apply( instance.element, args );\n\t\t\t}\n\t\t}\n\t}\n};\n\n\n\nvar safeBlur = $.ui.safeBlur = function( element ) {\n\n\t// Support: IE9 - 10 only\n\t// If the <body> is blurred, IE will switch windows, see #9420\n\tif ( element && element.nodeName.toLowerCase() !== \"body\" ) {\n\t\t$( element ).trigger( \"blur\" );\n\t}\n};\n\n\n/*!\n * jQuery UI Draggable 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Draggable\n//>>group: Interactions\n//>>description: Enables dragging functionality for any element.\n//>>docs: http://api.jqueryui.com/draggable/\n//>>demos: http://jqueryui.com/draggable/\n//>>css.structure: ../../themes/base/draggable.css\n\n\n\n$.widget( \"ui.draggable\", $.ui.mouse, {\n\tversion: \"1.12.1\",\n\twidgetEventPrefix: \"drag\",\n\toptions: {\n\t\taddClasses: true,\n\t\tappendTo: \"parent\",\n\t\taxis: false,\n\t\tconnectToSortable: false,\n\t\tcontainment: false,\n\t\tcursor: \"auto\",\n\t\tcursorAt: false,\n\t\tgrid: false,\n\t\thandle: false,\n\t\thelper: \"original\",\n\t\tiframeFix: false,\n\t\topacity: false,\n\t\trefreshPositions: false,\n\t\trevert: false,\n\t\trevertDuration: 500,\n\t\tscope: \"default\",\n\t\tscroll: true,\n\t\tscrollSensitivity: 20,\n\t\tscrollSpeed: 20,\n\t\tsnap: false,\n\t\tsnapMode: \"both\",\n\t\tsnapTolerance: 20,\n\t\tstack: false,\n\t\tzIndex: false,\n\n\t\t// Callbacks\n\t\tdrag: null,\n\t\tstart: null,\n\t\tstop: null\n\t},\n\t_create: function() {\n\n\t\tif ( this.options.helper === \"original\" ) {\n\t\t\tthis._setPositionRelative();\n\t\t}\n\t\tif ( this.options.addClasses ) {\n\t\t\tthis._addClass( \"ui-draggable\" );\n\t\t}\n\t\tthis._setHandleClassName();\n\n\t\tthis._mouseInit();\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tthis._super( key, value );\n\t\tif ( key === \"handle\" ) {\n\t\t\tthis._removeHandleClassName();\n\t\t\tthis._setHandleClassName();\n\t\t}\n\t},\n\n\t_destroy: function() {\n\t\tif ( ( this.helper || this.element ).is( \".ui-draggable-dragging\" ) ) {\n\t\t\tthis.destroyOnClear = true;\n\t\t\treturn;\n\t\t}\n\t\tthis._removeHandleClassName();\n\t\tthis._mouseDestroy();\n\t},\n\n\t_mouseCapture: function( event ) {\n\t\tvar o = this.options;\n\n\t\t// Among others, prevent a drag on a resizable-handle\n\t\tif ( this.helper || o.disabled ||\n\t\t\t\t$( event.target ).closest( \".ui-resizable-handle\" ).length > 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t//Quit if we're not on a valid handle\n\t\tthis.handle = this._getHandle( event );\n\t\tif ( !this.handle ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis._blurActiveElement( event );\n\n\t\tthis._blockFrames( o.iframeFix === true ? \"iframe\" : o.iframeFix );\n\n\t\treturn true;\n\n\t},\n\n\t_blockFrames: function( selector ) {\n\t\tthis.iframeBlocks = this.document.find( selector ).map( function() {\n\t\t\tvar iframe = $( this );\n\n\t\t\treturn $( \"<div>\" )\n\t\t\t\t.css( \"position\", \"absolute\" )\n\t\t\t\t.appendTo( iframe.parent() )\n\t\t\t\t.outerWidth( iframe.outerWidth() )\n\t\t\t\t.outerHeight( iframe.outerHeight() )\n\t\t\t\t.offset( iframe.offset() )[ 0 ];\n\t\t} );\n\t},\n\n\t_unblockFrames: function() {\n\t\tif ( this.iframeBlocks ) {\n\t\t\tthis.iframeBlocks.remove();\n\t\t\tdelete this.iframeBlocks;\n\t\t}\n\t},\n\n\t_blurActiveElement: function( event ) {\n\t\tvar activeElement = $.ui.safeActiveElement( this.document[ 0 ] ),\n\t\t\ttarget = $( event.target );\n\n\t\t// Don't blur if the event occurred on an element that is within\n\t\t// the currently focused element\n\t\t// See #10527, #12472\n\t\tif ( target.closest( activeElement ).length ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Blur any element that currently has focus, see #4261\n\t\t$.ui.safeBlur( activeElement );\n\t},\n\n\t_mouseStart: function( event ) {\n\n\t\tvar o = this.options;\n\n\t\t//Create and append the visible helper\n\t\tthis.helper = this._createHelper( event );\n\n\t\tthis._addClass( this.helper, \"ui-draggable-dragging\" );\n\n\t\t//Cache the helper size\n\t\tthis._cacheHelperProportions();\n\n\t\t//If ddmanager is used for droppables, set the global draggable\n\t\tif ( $.ui.ddmanager ) {\n\t\t\t$.ui.ddmanager.current = this;\n\t\t}\n\n\t\t/*\n\t\t * - Position generation -\n\t\t * This block generates everything position related - it's the core of draggables.\n\t\t */\n\n\t\t//Cache the margins of the original element\n\t\tthis._cacheMargins();\n\n\t\t//Store the helper's css position\n\t\tthis.cssPosition = this.helper.css( \"position\" );\n\t\tthis.scrollParent = this.helper.scrollParent( true );\n\t\tthis.offsetParent = this.helper.offsetParent();\n\t\tthis.hasFixedAncestor = this.helper.parents().filter( function() {\n\t\t\t\treturn $( this ).css( \"position\" ) === \"fixed\";\n\t\t\t} ).length > 0;\n\n\t\t//The element's absolute position on the page minus margins\n\t\tthis.positionAbs = this.element.offset();\n\t\tthis._refreshOffsets( event );\n\n\t\t//Generate the original position\n\t\tthis.originalPosition = this.position = this._generatePosition( event, false );\n\t\tthis.originalPageX = event.pageX;\n\t\tthis.originalPageY = event.pageY;\n\n\t\t//Adjust the mouse offset relative to the helper if \"cursorAt\" is supplied\n\t\t( o.cursorAt && this._adjustOffsetFromHelper( o.cursorAt ) );\n\n\t\t//Set a containment if given in the options\n\t\tthis._setContainment();\n\n\t\t//Trigger event + callbacks\n\t\tif ( this._trigger( \"start\", event ) === false ) {\n\t\t\tthis._clear();\n\t\t\treturn false;\n\t\t}\n\n\t\t//Recache the helper size\n\t\tthis._cacheHelperProportions();\n\n\t\t//Prepare the droppable offsets\n\t\tif ( $.ui.ddmanager && !o.dropBehaviour ) {\n\t\t\t$.ui.ddmanager.prepareOffsets( this, event );\n\t\t}\n\n\t\t// Execute the drag once - this causes the helper not to be visible before getting its\n\t\t// correct position\n\t\tthis._mouseDrag( event, true );\n\n\t\t// If the ddmanager is used for droppables, inform the manager that dragging has started\n\t\t// (see #5003)\n\t\tif ( $.ui.ddmanager ) {\n\t\t\t$.ui.ddmanager.dragStart( this, event );\n\t\t}\n\n\t\treturn true;\n\t},\n\n\t_refreshOffsets: function( event ) {\n\t\tthis.offset = {\n\t\t\ttop: this.positionAbs.top - this.margins.top,\n\t\t\tleft: this.positionAbs.left - this.margins.left,\n\t\t\tscroll: false,\n\t\t\tparent: this._getParentOffset(),\n\t\t\trelative: this._getRelativeOffset()\n\t\t};\n\n\t\tthis.offset.click = {\n\t\t\tleft: event.pageX - this.offset.left,\n\t\t\ttop: event.pageY - this.offset.top\n\t\t};\n\t},\n\n\t_mouseDrag: function( event, noPropagation ) {\n\n\t\t// reset any necessary cached properties (see #5009)\n\t\tif ( this.hasFixedAncestor ) {\n\t\t\tthis.offset.parent = this._getParentOffset();\n\t\t}\n\n\t\t//Compute the helpers position\n\t\tthis.position = this._generatePosition( event, true );\n\t\tthis.positionAbs = this._convertPositionTo( \"absolute\" );\n\n\t\t//Call plugins and callbacks and use the resulting position if something is returned\n\t\tif ( !noPropagation ) {\n\t\t\tvar ui = this._uiHash();\n\t\t\tif ( this._trigger( \"drag\", event, ui ) === false ) {\n\t\t\t\tthis._mouseUp( new $.Event( \"mouseup\", event ) );\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.position = ui.position;\n\t\t}\n\n\t\tthis.helper[ 0 ].style.left = this.position.left + \"px\";\n\t\tthis.helper[ 0 ].style.top = this.position.top + \"px\";\n\n\t\tif ( $.ui.ddmanager ) {\n\t\t\t$.ui.ddmanager.drag( this, event );\n\t\t}\n\n\t\treturn false;\n\t},\n\n\t_mouseStop: function( event ) {\n\n\t\t//If we are using droppables, inform the manager about the drop\n\t\tvar that = this,\n\t\t\tdropped = false;\n\t\tif ( $.ui.ddmanager && !this.options.dropBehaviour ) {\n\t\t\tdropped = $.ui.ddmanager.drop( this, event );\n\t\t}\n\n\t\t//if a drop comes from outside (a sortable)\n\t\tif ( this.dropped ) {\n\t\t\tdropped = this.dropped;\n\t\t\tthis.dropped = false;\n\t\t}\n\n\t\tif ( ( this.options.revert === \"invalid\" && !dropped ) ||\n\t\t\t\t( this.options.revert === \"valid\" && dropped ) ||\n\t\t\t\tthis.options.revert === true || ( $.isFunction( this.options.revert ) &&\n\t\t\t\tthis.options.revert.call( this.element, dropped ) )\n\t\t) {\n\t\t\t$( this.helper ).animate(\n\t\t\t\tthis.originalPosition,\n\t\t\t\tparseInt( this.options.revertDuration, 10 ),\n\t\t\t\tfunction() {\n\t\t\t\t\tif ( that._trigger( \"stop\", event ) !== false ) {\n\t\t\t\t\t\tthat._clear();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t} else {\n\t\t\tif ( this._trigger( \"stop\", event ) !== false ) {\n\t\t\t\tthis._clear();\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t},\n\n\t_mouseUp: function( event ) {\n\t\tthis._unblockFrames();\n\n\t\t// If the ddmanager is used for droppables, inform the manager that dragging has stopped\n\t\t// (see #5003)\n\t\tif ( $.ui.ddmanager ) {\n\t\t\t$.ui.ddmanager.dragStop( this, event );\n\t\t}\n\n\t\t// Only need to focus if the event occurred on the draggable itself, see #10527\n\t\tif ( this.handleElement.is( event.target ) ) {\n\n\t\t\t// The interaction is over; whether or not the click resulted in a drag,\n\t\t\t// focus the element\n\t\t\tthis.element.trigger( \"focus\" );\n\t\t}\n\n\t\treturn $.ui.mouse.prototype._mouseUp.call( this, event );\n\t},\n\n\tcancel: function() {\n\n\t\tif ( this.helper.is( \".ui-draggable-dragging\" ) ) {\n\t\t\tthis._mouseUp( new $.Event( \"mouseup\", { target: this.element[ 0 ] } ) );\n\t\t} else {\n\t\t\tthis._clear();\n\t\t}\n\n\t\treturn this;\n\n\t},\n\n\t_getHandle: function( event ) {\n\t\treturn this.options.handle ?\n\t\t\t!!$( event.target ).closest( this.element.find( this.options.handle ) ).length :\n\t\t\ttrue;\n\t},\n\n\t_setHandleClassName: function() {\n\t\tthis.handleElement = this.options.handle ?\n\t\t\tthis.element.find( this.options.handle ) : this.element;\n\t\tthis._addClass( this.handleElement, \"ui-draggable-handle\" );\n\t},\n\n\t_removeHandleClassName: function() {\n\t\tthis._removeClass( this.handleElement, \"ui-draggable-handle\" );\n\t},\n\n\t_createHelper: function( event ) {\n\n\t\tvar o = this.options,\n\t\t\thelperIsFunction = $.isFunction( o.helper ),\n\t\t\thelper = helperIsFunction ?\n\t\t\t\t$( o.helper.apply( this.element[ 0 ], [ event ] ) ) :\n\t\t\t\t( o.helper === \"clone\" ?\n\t\t\t\t\tthis.element.clone().removeAttr( \"id\" ) :\n\t\t\t\t\tthis.element );\n\n\t\tif ( !helper.parents( \"body\" ).length ) {\n\t\t\thelper.appendTo( ( o.appendTo === \"parent\" ?\n\t\t\t\tthis.element[ 0 ].parentNode :\n\t\t\t\to.appendTo ) );\n\t\t}\n\n\t\t// Http://bugs.jqueryui.com/ticket/9446\n\t\t// a helper function can return the original element\n\t\t// which wouldn't have been set to relative in _create\n\t\tif ( helperIsFunction && helper[ 0 ] === this.element[ 0 ] ) {\n\t\t\tthis._setPositionRelative();\n\t\t}\n\n\t\tif ( helper[ 0 ] !== this.element[ 0 ] &&\n\t\t\t\t!( /(fixed|absolute)/ ).test( helper.css( \"position\" ) ) ) {\n\t\t\thelper.css( \"position\", \"absolute\" );\n\t\t}\n\n\t\treturn helper;\n\n\t},\n\n\t_setPositionRelative: function() {\n\t\tif ( !( /^(?:r|a|f)/ ).test( this.element.css( \"position\" ) ) ) {\n\t\t\tthis.element[ 0 ].style.position = \"relative\";\n\t\t}\n\t},\n\n\t_adjustOffsetFromHelper: function( obj ) {\n\t\tif ( typeof obj === \"string\" ) {\n\t\t\tobj = obj.split( \" \" );\n\t\t}\n\t\tif ( $.isArray( obj ) ) {\n\t\t\tobj = { left: +obj[ 0 ], top: +obj[ 1 ] || 0 };\n\t\t}\n\t\tif ( \"left\" in obj ) {\n\t\t\tthis.offset.click.left = obj.left + this.margins.left;\n\t\t}\n\t\tif ( \"right\" in obj ) {\n\t\t\tthis.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;\n\t\t}\n\t\tif ( \"top\" in obj ) {\n\t\t\tthis.offset.click.top = obj.top + this.margins.top;\n\t\t}\n\t\tif ( \"bottom\" in obj ) {\n\t\t\tthis.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;\n\t\t}\n\t},\n\n\t_isRootNode: function( element ) {\n\t\treturn ( /(html|body)/i ).test( element.tagName ) || element === this.document[ 0 ];\n\t},\n\n\t_getParentOffset: function() {\n\n\t\t//Get the offsetParent and cache its position\n\t\tvar po = this.offsetParent.offset(),\n\t\t\tdocument = this.document[ 0 ];\n\n\t\t// This is a special case where we need to modify a offset calculated on start, since the\n\t\t// following happened:\n\t\t// 1. The position of the helper is absolute, so it's position is calculated based on the\n\t\t// next positioned parent\n\t\t// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't\n\t\t// the document, which means that the scroll is included in the initial calculation of the\n\t\t// offset of the parent, and never recalculated upon drag\n\t\tif ( this.cssPosition === \"absolute\" && this.scrollParent[ 0 ] !== document &&\n\t\t\t\t$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) {\n\t\t\tpo.left += this.scrollParent.scrollLeft();\n\t\t\tpo.top += this.scrollParent.scrollTop();\n\t\t}\n\n\t\tif ( this._isRootNode( this.offsetParent[ 0 ] ) ) {\n\t\t\tpo = { top: 0, left: 0 };\n\t\t}\n\n\t\treturn {\n\t\t\ttop: po.top + ( parseInt( this.offsetParent.css( \"borderTopWidth\" ), 10 ) || 0 ),\n\t\t\tleft: po.left + ( parseInt( this.offsetParent.css( \"borderLeftWidth\" ), 10 ) || 0 )\n\t\t};\n\n\t},\n\n\t_getRelativeOffset: function() {\n\t\tif ( this.cssPosition !== \"relative\" ) {\n\t\t\treturn { top: 0, left: 0 };\n\t\t}\n\n\t\tvar p = this.element.position(),\n\t\t\tscrollIsRootNode = this._isRootNode( this.scrollParent[ 0 ] );\n\n\t\treturn {\n\t\t\ttop: p.top - ( parseInt( this.helper.css( \"top\" ), 10 ) || 0 ) +\n\t\t\t\t( !scrollIsRootNode ? this.scrollParent.scrollTop() : 0 ),\n\t\t\tleft: p.left - ( parseInt( this.helper.css( \"left\" ), 10 ) || 0 ) +\n\t\t\t\t( !scrollIsRootNode ? this.scrollParent.scrollLeft() : 0 )\n\t\t};\n\n\t},\n\n\t_cacheMargins: function() {\n\t\tthis.margins = {\n\t\t\tleft: ( parseInt( this.element.css( \"marginLeft\" ), 10 ) || 0 ),\n\t\t\ttop: ( parseInt( this.element.css( \"marginTop\" ), 10 ) || 0 ),\n\t\t\tright: ( parseInt( this.element.css( \"marginRight\" ), 10 ) || 0 ),\n\t\t\tbottom: ( parseInt( this.element.css( \"marginBottom\" ), 10 ) || 0 )\n\t\t};\n\t},\n\n\t_cacheHelperProportions: function() {\n\t\tthis.helperProportions = {\n\t\t\twidth: this.helper.outerWidth(),\n\t\t\theight: this.helper.outerHeight()\n\t\t};\n\t},\n\n\t_setContainment: function() {\n\n\t\tvar isUserScrollable, c, ce,\n\t\t\to = this.options,\n\t\t\tdocument = this.document[ 0 ];\n\n\t\tthis.relativeContainer = null;\n\n\t\tif ( !o.containment ) {\n\t\t\tthis.containment = null;\n\t\t\treturn;\n\t\t}\n\n\t\tif ( o.containment === \"window\" ) {\n\t\t\tthis.containment = [\n\t\t\t\t$( window ).scrollLeft() - this.offset.relative.left - this.offset.parent.left,\n\t\t\t\t$( window ).scrollTop() - this.offset.relative.top - this.offset.parent.top,\n\t\t\t\t$( window ).scrollLeft() + $( window ).width() -\n\t\t\t\t\tthis.helperProportions.width - this.margins.left,\n\t\t\t\t$( window ).scrollTop() +\n\t\t\t\t\t( $( window ).height() || document.body.parentNode.scrollHeight ) -\n\t\t\t\t\tthis.helperProportions.height - this.margins.top\n\t\t\t];\n\t\t\treturn;\n\t\t}\n\n\t\tif ( o.containment === \"document\" ) {\n\t\t\tthis.containment = [\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\t$( document ).width() - this.helperProportions.width - this.margins.left,\n\t\t\t\t( $( document ).height() || document.body.parentNode.scrollHeight ) -\n\t\t\t\t\tthis.helperProportions.height - this.margins.top\n\t\t\t];\n\t\t\treturn;\n\t\t}\n\n\t\tif ( o.containment.constructor === Array ) {\n\t\t\tthis.containment = o.containment;\n\t\t\treturn;\n\t\t}\n\n\t\tif ( o.containment === \"parent\" ) {\n\t\t\to.containment = this.helper[ 0 ].parentNode;\n\t\t}\n\n\t\tc = $( o.containment );\n\t\tce = c[ 0 ];\n\n\t\tif ( !ce ) {\n\t\t\treturn;\n\t\t}\n\n\t\tisUserScrollable = /(scroll|auto)/.test( c.css( \"overflow\" ) );\n\n\t\tthis.containment = [\n\t\t\t( parseInt( c.css( \"borderLeftWidth\" ), 10 ) || 0 ) +\n\t\t\t\t( parseInt( c.css( \"paddingLeft\" ), 10 ) || 0 ),\n\t\t\t( parseInt( c.css( \"borderTopWidth\" ), 10 ) || 0 ) +\n\t\t\t\t( parseInt( c.css( \"paddingTop\" ), 10 ) || 0 ),\n\t\t\t( isUserScrollable ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) -\n\t\t\t\t( parseInt( c.css( \"borderRightWidth\" ), 10 ) || 0 ) -\n\t\t\t\t( parseInt( c.css( \"paddingRight\" ), 10 ) || 0 ) -\n\t\t\t\tthis.helperProportions.width -\n\t\t\t\tthis.margins.left -\n\t\t\t\tthis.margins.right,\n\t\t\t( isUserScrollable ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) -\n\t\t\t\t( parseInt( c.css( \"borderBottomWidth\" ), 10 ) || 0 ) -\n\t\t\t\t( parseInt( c.css( \"paddingBottom\" ), 10 ) || 0 ) -\n\t\t\t\tthis.helperProportions.height -\n\t\t\t\tthis.margins.top -\n\t\t\t\tthis.margins.bottom\n\t\t];\n\t\tthis.relativeContainer = c;\n\t},\n\n\t_convertPositionTo: function( d, pos ) {\n\n\t\tif ( !pos ) {\n\t\t\tpos = this.position;\n\t\t}\n\n\t\tvar mod = d === \"absolute\" ? 1 : -1,\n\t\t\tscrollIsRootNode = this._isRootNode( this.scrollParent[ 0 ] );\n\n\t\treturn {\n\t\t\ttop: (\n\n\t\t\t\t// The absolute mouse position\n\t\t\t\tpos.top\t+\n\n\t\t\t\t// Only for relative positioned nodes: Relative offset from element to offset parent\n\t\t\t\tthis.offset.relative.top * mod +\n\n\t\t\t\t// The offsetParent's offset without borders (offset + border)\n\t\t\t\tthis.offset.parent.top * mod -\n\t\t\t\t( ( this.cssPosition === \"fixed\" ?\n\t\t\t\t\t-this.offset.scroll.top :\n\t\t\t\t\t( scrollIsRootNode ? 0 : this.offset.scroll.top ) ) * mod )\n\t\t\t),\n\t\t\tleft: (\n\n\t\t\t\t// The absolute mouse position\n\t\t\t\tpos.left +\n\n\t\t\t\t// Only for relative positioned nodes: Relative offset from element to offset parent\n\t\t\t\tthis.offset.relative.left * mod +\n\n\t\t\t\t// The offsetParent's offset without borders (offset + border)\n\t\t\t\tthis.offset.parent.left * mod\t-\n\t\t\t\t( ( this.cssPosition === \"fixed\" ?\n\t\t\t\t\t-this.offset.scroll.left :\n\t\t\t\t\t( scrollIsRootNode ? 0 : this.offset.scroll.left ) ) * mod )\n\t\t\t)\n\t\t};\n\n\t},\n\n\t_generatePosition: function( event, constrainPosition ) {\n\n\t\tvar containment, co, top, left,\n\t\t\to = this.options,\n\t\t\tscrollIsRootNode = this._isRootNode( this.scrollParent[ 0 ] ),\n\t\t\tpageX = event.pageX,\n\t\t\tpageY = event.pageY;\n\n\t\t// Cache the scroll\n\t\tif ( !scrollIsRootNode || !this.offset.scroll ) {\n\t\t\tthis.offset.scroll = {\n\t\t\t\ttop: this.scrollParent.scrollTop(),\n\t\t\t\tleft: this.scrollParent.scrollLeft()\n\t\t\t};\n\t\t}\n\n\t\t/*\n\t\t * - Position constraining -\n\t\t * Constrain the position to a mix of grid, containment.\n\t\t */\n\n\t\t// If we are not dragging yet, we won't check for options\n\t\tif ( constrainPosition ) {\n\t\t\tif ( this.containment ) {\n\t\t\t\tif ( this.relativeContainer ) {\n\t\t\t\t\tco = this.relativeContainer.offset();\n\t\t\t\t\tcontainment = [\n\t\t\t\t\t\tthis.containment[ 0 ] + co.left,\n\t\t\t\t\t\tthis.containment[ 1 ] + co.top,\n\t\t\t\t\t\tthis.containment[ 2 ] + co.left,\n\t\t\t\t\t\tthis.containment[ 3 ] + co.top\n\t\t\t\t\t];\n\t\t\t\t} else {\n\t\t\t\t\tcontainment = this.containment;\n\t\t\t\t}\n\n\t\t\t\tif ( event.pageX - this.offset.click.left < containment[ 0 ] ) {\n\t\t\t\t\tpageX = containment[ 0 ] + this.offset.click.left;\n\t\t\t\t}\n\t\t\t\tif ( event.pageY - this.offset.click.top < containment[ 1 ] ) {\n\t\t\t\t\tpageY = containment[ 1 ] + this.offset.click.top;\n\t\t\t\t}\n\t\t\t\tif ( event.pageX - this.offset.click.left > containment[ 2 ] ) {\n\t\t\t\t\tpageX = containment[ 2 ] + this.offset.click.left;\n\t\t\t\t}\n\t\t\t\tif ( event.pageY - this.offset.click.top > containment[ 3 ] ) {\n\t\t\t\t\tpageY = containment[ 3 ] + this.offset.click.top;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( o.grid ) {\n\n\t\t\t\t//Check for grid elements set to 0 to prevent divide by 0 error causing invalid\n\t\t\t\t// argument errors in IE (see ticket #6950)\n\t\t\t\ttop = o.grid[ 1 ] ? this.originalPageY + Math.round( ( pageY -\n\t\t\t\t\tthis.originalPageY ) / o.grid[ 1 ] ) * o.grid[ 1 ] : this.originalPageY;\n\t\t\t\tpageY = containment ? ( ( top - this.offset.click.top >= containment[ 1 ] ||\n\t\t\t\t\ttop - this.offset.click.top > containment[ 3 ] ) ?\n\t\t\t\t\t\ttop :\n\t\t\t\t\t\t( ( top - this.offset.click.top >= containment[ 1 ] ) ?\n\t\t\t\t\t\t\ttop - o.grid[ 1 ] : top + o.grid[ 1 ] ) ) : top;\n\n\t\t\t\tleft = o.grid[ 0 ] ? this.originalPageX +\n\t\t\t\t\tMath.round( ( pageX - this.originalPageX ) / o.grid[ 0 ] ) * o.grid[ 0 ] :\n\t\t\t\t\tthis.originalPageX;\n\t\t\t\tpageX = containment ? ( ( left - this.offset.click.left >= containment[ 0 ] ||\n\t\t\t\t\tleft - this.offset.click.left > containment[ 2 ] ) ?\n\t\t\t\t\t\tleft :\n\t\t\t\t\t\t( ( left - this.offset.click.left >= containment[ 0 ] ) ?\n\t\t\t\t\t\t\tleft - o.grid[ 0 ] : left + o.grid[ 0 ] ) ) : left;\n\t\t\t}\n\n\t\t\tif ( o.axis === \"y\" ) {\n\t\t\t\tpageX = this.originalPageX;\n\t\t\t}\n\n\t\t\tif ( o.axis === \"x\" ) {\n\t\t\t\tpageY = this.originalPageY;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\ttop: (\n\n\t\t\t\t// The absolute mouse position\n\t\t\t\tpageY -\n\n\t\t\t\t// Click offset (relative to the element)\n\t\t\t\tthis.offset.click.top -\n\n\t\t\t\t// Only for relative positioned nodes: Relative offset from element to offset parent\n\t\t\t\tthis.offset.relative.top -\n\n\t\t\t\t// The offsetParent's offset without borders (offset + border)\n\t\t\t\tthis.offset.parent.top +\n\t\t\t\t( this.cssPosition === \"fixed\" ?\n\t\t\t\t\t-this.offset.scroll.top :\n\t\t\t\t\t( scrollIsRootNode ? 0 : this.offset.scroll.top ) )\n\t\t\t),\n\t\t\tleft: (\n\n\t\t\t\t// The absolute mouse position\n\t\t\t\tpageX -\n\n\t\t\t\t// Click offset (relative to the element)\n\t\t\t\tthis.offset.click.left -\n\n\t\t\t\t// Only for relative positioned nodes: Relative offset from element to offset parent\n\t\t\t\tthis.offset.relative.left -\n\n\t\t\t\t// The offsetParent's offset without borders (offset + border)\n\t\t\t\tthis.offset.parent.left +\n\t\t\t\t( this.cssPosition === \"fixed\" ?\n\t\t\t\t\t-this.offset.scroll.left :\n\t\t\t\t\t( scrollIsRootNode ? 0 : this.offset.scroll.left ) )\n\t\t\t)\n\t\t};\n\n\t},\n\n\t_clear: function() {\n\t\tthis._removeClass( this.helper, \"ui-draggable-dragging\" );\n\t\tif ( this.helper[ 0 ] !== this.element[ 0 ] && !this.cancelHelperRemoval ) {\n\t\t\tthis.helper.remove();\n\t\t}\n\t\tthis.helper = null;\n\t\tthis.cancelHelperRemoval = false;\n\t\tif ( this.destroyOnClear ) {\n\t\t\tthis.destroy();\n\t\t}\n\t},\n\n\t// From now on bulk stuff - mainly helpers\n\n\t_trigger: function( type, event, ui ) {\n\t\tui = ui || this._uiHash();\n\t\t$.ui.plugin.call( this, type, [ event, ui, this ], true );\n\n\t\t// Absolute position and offset (see #6884 ) have to be recalculated after plugins\n\t\tif ( /^(drag|start|stop)/.test( type ) ) {\n\t\t\tthis.positionAbs = this._convertPositionTo( \"absolute\" );\n\t\t\tui.offset = this.positionAbs;\n\t\t}\n\t\treturn $.Widget.prototype._trigger.call( this, type, event, ui );\n\t},\n\n\tplugins: {},\n\n\t_uiHash: function() {\n\t\treturn {\n\t\t\thelper: this.helper,\n\t\t\tposition: this.position,\n\t\t\toriginalPosition: this.originalPosition,\n\t\t\toffset: this.positionAbs\n\t\t};\n\t}\n\n} );\n\n$.ui.plugin.add( \"draggable\", \"connectToSortable\", {\n\tstart: function( event, ui, draggable ) {\n\t\tvar uiSortable = $.extend( {}, ui, {\n\t\t\titem: draggable.element\n\t\t} );\n\n\t\tdraggable.sortables = [];\n\t\t$( draggable.options.connectToSortable ).each( function() {\n\t\t\tvar sortable = $( this ).sortable( \"instance\" );\n\n\t\t\tif ( sortable && !sortable.options.disabled ) {\n\t\t\t\tdraggable.sortables.push( sortable );\n\n\t\t\t\t// RefreshPositions is called at drag start to refresh the containerCache\n\t\t\t\t// which is used in drag. This ensures it's initialized and synchronized\n\t\t\t\t// with any changes that might have happened on the page since initialization.\n\t\t\t\tsortable.refreshPositions();\n\t\t\t\tsortable._trigger( \"activate\", event, uiSortable );\n\t\t\t}\n\t\t} );\n\t},\n\tstop: function( event, ui, draggable ) {\n\t\tvar uiSortable = $.extend( {}, ui, {\n\t\t\titem: draggable.element\n\t\t} );\n\n\t\tdraggable.cancelHelperRemoval = false;\n\n\t\t$.each( draggable.sortables, function() {\n\t\t\tvar sortable = this;\n\n\t\t\tif ( sortable.isOver ) {\n\t\t\t\tsortable.isOver = 0;\n\n\t\t\t\t// Allow this sortable to handle removing the helper\n\t\t\t\tdraggable.cancelHelperRemoval = true;\n\t\t\t\tsortable.cancelHelperRemoval = false;\n\n\t\t\t\t// Use _storedCSS To restore properties in the sortable,\n\t\t\t\t// as this also handles revert (#9675) since the draggable\n\t\t\t\t// may have modified them in unexpected ways (#8809)\n\t\t\t\tsortable._storedCSS = {\n\t\t\t\t\tposition: sortable.placeholder.css( \"position\" ),\n\t\t\t\t\ttop: sortable.placeholder.css( \"top\" ),\n\t\t\t\t\tleft: sortable.placeholder.css( \"left\" )\n\t\t\t\t};\n\n\t\t\t\tsortable._mouseStop( event );\n\n\t\t\t\t// Once drag has ended, the sortable should return to using\n\t\t\t\t// its original helper, not the shared helper from draggable\n\t\t\t\tsortable.options.helper = sortable.options._helper;\n\t\t\t} else {\n\n\t\t\t\t// Prevent this Sortable from removing the helper.\n\t\t\t\t// However, don't set the draggable to remove the helper\n\t\t\t\t// either as another connected Sortable may yet handle the removal.\n\t\t\t\tsortable.cancelHelperRemoval = true;\n\n\t\t\t\tsortable._trigger( \"deactivate\", event, uiSortable );\n\t\t\t}\n\t\t} );\n\t},\n\tdrag: function( event, ui, draggable ) {\n\t\t$.each( draggable.sortables, function() {\n\t\t\tvar innermostIntersecting = false,\n\t\t\t\tsortable = this;\n\n\t\t\t// Copy over variables that sortable's _intersectsWith uses\n\t\t\tsortable.positionAbs = draggable.positionAbs;\n\t\t\tsortable.helperProportions = draggable.helperProportions;\n\t\t\tsortable.offset.click = draggable.offset.click;\n\n\t\t\tif ( sortable._intersectsWith( sortable.containerCache ) ) {\n\t\t\t\tinnermostIntersecting = true;\n\n\t\t\t\t$.each( draggable.sortables, function() {\n\n\t\t\t\t\t// Copy over variables that sortable's _intersectsWith uses\n\t\t\t\t\tthis.positionAbs = draggable.positionAbs;\n\t\t\t\t\tthis.helperProportions = draggable.helperProportions;\n\t\t\t\t\tthis.offset.click = draggable.offset.click;\n\n\t\t\t\t\tif ( this !== sortable &&\n\t\t\t\t\t\t\tthis._intersectsWith( this.containerCache ) &&\n\t\t\t\t\t\t\t$.contains( sortable.element[ 0 ], this.element[ 0 ] ) ) {\n\t\t\t\t\t\tinnermostIntersecting = false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn innermostIntersecting;\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tif ( innermostIntersecting ) {\n\n\t\t\t\t// If it intersects, we use a little isOver variable and set it once,\n\t\t\t\t// so that the move-in stuff gets fired only once.\n\t\t\t\tif ( !sortable.isOver ) {\n\t\t\t\t\tsortable.isOver = 1;\n\n\t\t\t\t\t// Store draggable's parent in case we need to reappend to it later.\n\t\t\t\t\tdraggable._parent = ui.helper.parent();\n\n\t\t\t\t\tsortable.currentItem = ui.helper\n\t\t\t\t\t\t.appendTo( sortable.element )\n\t\t\t\t\t\t.data( \"ui-sortable-item\", true );\n\n\t\t\t\t\t// Store helper option to later restore it\n\t\t\t\t\tsortable.options._helper = sortable.options.helper;\n\n\t\t\t\t\tsortable.options.helper = function() {\n\t\t\t\t\t\treturn ui.helper[ 0 ];\n\t\t\t\t\t};\n\n\t\t\t\t\t// Fire the start events of the sortable with our passed browser event,\n\t\t\t\t\t// and our own helper (so it doesn't create a new one)\n\t\t\t\t\tevent.target = sortable.currentItem[ 0 ];\n\t\t\t\t\tsortable._mouseCapture( event, true );\n\t\t\t\t\tsortable._mouseStart( event, true, true );\n\n\t\t\t\t\t// Because the browser event is way off the new appended portlet,\n\t\t\t\t\t// modify necessary variables to reflect the changes\n\t\t\t\t\tsortable.offset.click.top = draggable.offset.click.top;\n\t\t\t\t\tsortable.offset.click.left = draggable.offset.click.left;\n\t\t\t\t\tsortable.offset.parent.left -= draggable.offset.parent.left -\n\t\t\t\t\t\tsortable.offset.parent.left;\n\t\t\t\t\tsortable.offset.parent.top -= draggable.offset.parent.top -\n\t\t\t\t\t\tsortable.offset.parent.top;\n\n\t\t\t\t\tdraggable._trigger( \"toSortable\", event );\n\n\t\t\t\t\t// Inform draggable that the helper is in a valid drop zone,\n\t\t\t\t\t// used solely in the revert option to handle \"valid/invalid\".\n\t\t\t\t\tdraggable.dropped = sortable.element;\n\n\t\t\t\t\t// Need to refreshPositions of all sortables in the case that\n\t\t\t\t\t// adding to one sortable changes the location of the other sortables (#9675)\n\t\t\t\t\t$.each( draggable.sortables, function() {\n\t\t\t\t\t\tthis.refreshPositions();\n\t\t\t\t\t} );\n\n\t\t\t\t\t// Hack so receive/update callbacks work (mostly)\n\t\t\t\t\tdraggable.currentItem = draggable.element;\n\t\t\t\t\tsortable.fromOutside = draggable;\n\t\t\t\t}\n\n\t\t\t\tif ( sortable.currentItem ) {\n\t\t\t\t\tsortable._mouseDrag( event );\n\n\t\t\t\t\t// Copy the sortable's position because the draggable's can potentially reflect\n\t\t\t\t\t// a relative position, while sortable is always absolute, which the dragged\n\t\t\t\t\t// element has now become. (#8809)\n\t\t\t\t\tui.position = sortable.position;\n\t\t\t\t}\n\t\t\t} else {\n\n\t\t\t\t// If it doesn't intersect with the sortable, and it intersected before,\n\t\t\t\t// we fake the drag stop of the sortable, but make sure it doesn't remove\n\t\t\t\t// the helper by using cancelHelperRemoval.\n\t\t\t\tif ( sortable.isOver ) {\n\n\t\t\t\t\tsortable.isOver = 0;\n\t\t\t\t\tsortable.cancelHelperRemoval = true;\n\n\t\t\t\t\t// Calling sortable's mouseStop would trigger a revert,\n\t\t\t\t\t// so revert must be temporarily false until after mouseStop is called.\n\t\t\t\t\tsortable.options._revert = sortable.options.revert;\n\t\t\t\t\tsortable.options.revert = false;\n\n\t\t\t\t\tsortable._trigger( \"out\", event, sortable._uiHash( sortable ) );\n\t\t\t\t\tsortable._mouseStop( event, true );\n\n\t\t\t\t\t// Restore sortable behaviors that were modfied\n\t\t\t\t\t// when the draggable entered the sortable area (#9481)\n\t\t\t\t\tsortable.options.revert = sortable.options._revert;\n\t\t\t\t\tsortable.options.helper = sortable.options._helper;\n\n\t\t\t\t\tif ( sortable.placeholder ) {\n\t\t\t\t\t\tsortable.placeholder.remove();\n\t\t\t\t\t}\n\n\t\t\t\t\t// Restore and recalculate the draggable's offset considering the sortable\n\t\t\t\t\t// may have modified them in unexpected ways. (#8809, #10669)\n\t\t\t\t\tui.helper.appendTo( draggable._parent );\n\t\t\t\t\tdraggable._refreshOffsets( event );\n\t\t\t\t\tui.position = draggable._generatePosition( event, true );\n\n\t\t\t\t\tdraggable._trigger( \"fromSortable\", event );\n\n\t\t\t\t\t// Inform draggable that the helper is no longer in a valid drop zone\n\t\t\t\t\tdraggable.dropped = false;\n\n\t\t\t\t\t// Need to refreshPositions of all sortables just in case removing\n\t\t\t\t\t// from one sortable changes the location of other sortables (#9675)\n\t\t\t\t\t$.each( draggable.sortables, function() {\n\t\t\t\t\t\tthis.refreshPositions();\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n} );\n\n$.ui.plugin.add( \"draggable\", \"cursor\", {\n\tstart: function( event, ui, instance ) {\n\t\tvar t = $( \"body\" ),\n\t\t\to = instance.options;\n\n\t\tif ( t.css( \"cursor\" ) ) {\n\t\t\to._cursor = t.css( \"cursor\" );\n\t\t}\n\t\tt.css( \"cursor\", o.cursor );\n\t},\n\tstop: function( event, ui, instance ) {\n\t\tvar o = instance.options;\n\t\tif ( o._cursor ) {\n\t\t\t$( \"body\" ).css( \"cursor\", o._cursor );\n\t\t}\n\t}\n} );\n\n$.ui.plugin.add( \"draggable\", \"opacity\", {\n\tstart: function( event, ui, instance ) {\n\t\tvar t = $( ui.helper ),\n\t\t\to = instance.options;\n\t\tif ( t.css( \"opacity\" ) ) {\n\t\t\to._opacity = t.css( \"opacity\" );\n\t\t}\n\t\tt.css( \"opacity\", o.opacity );\n\t},\n\tstop: function( event, ui, instance ) {\n\t\tvar o = instance.options;\n\t\tif ( o._opacity ) {\n\t\t\t$( ui.helper ).css( \"opacity\", o._opacity );\n\t\t}\n\t}\n} );\n\n$.ui.plugin.add( \"draggable\", \"scroll\", {\n\tstart: function( event, ui, i ) {\n\t\tif ( !i.scrollParentNotHidden ) {\n\t\t\ti.scrollParentNotHidden = i.helper.scrollParent( false );\n\t\t}\n\n\t\tif ( i.scrollParentNotHidden[ 0 ] !== i.document[ 0 ] &&\n\t\t\t\ti.scrollParentNotHidden[ 0 ].tagName !== \"HTML\" ) {\n\t\t\ti.overflowOffset = i.scrollParentNotHidden.offset();\n\t\t}\n\t},\n\tdrag: function( event, ui, i  ) {\n\n\t\tvar o = i.options,\n\t\t\tscrolled = false,\n\t\t\tscrollParent = i.scrollParentNotHidden[ 0 ],\n\t\t\tdocument = i.document[ 0 ];\n\n\t\tif ( scrollParent !== document && scrollParent.tagName !== \"HTML\" ) {\n\t\t\tif ( !o.axis || o.axis !== \"x\" ) {\n\t\t\t\tif ( ( i.overflowOffset.top + scrollParent.offsetHeight ) - event.pageY <\n\t\t\t\t\t\to.scrollSensitivity ) {\n\t\t\t\t\tscrollParent.scrollTop = scrolled = scrollParent.scrollTop + o.scrollSpeed;\n\t\t\t\t} else if ( event.pageY - i.overflowOffset.top < o.scrollSensitivity ) {\n\t\t\t\t\tscrollParent.scrollTop = scrolled = scrollParent.scrollTop - o.scrollSpeed;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( !o.axis || o.axis !== \"y\" ) {\n\t\t\t\tif ( ( i.overflowOffset.left + scrollParent.offsetWidth ) - event.pageX <\n\t\t\t\t\t\to.scrollSensitivity ) {\n\t\t\t\t\tscrollParent.scrollLeft = scrolled = scrollParent.scrollLeft + o.scrollSpeed;\n\t\t\t\t} else if ( event.pageX - i.overflowOffset.left < o.scrollSensitivity ) {\n\t\t\t\t\tscrollParent.scrollLeft = scrolled = scrollParent.scrollLeft - o.scrollSpeed;\n\t\t\t\t}\n\t\t\t}\n\n\t\t} else {\n\n\t\t\tif ( !o.axis || o.axis !== \"x\" ) {\n\t\t\t\tif ( event.pageY - $( document ).scrollTop() < o.scrollSensitivity ) {\n\t\t\t\t\tscrolled = $( document ).scrollTop( $( document ).scrollTop() - o.scrollSpeed );\n\t\t\t\t} else if ( $( window ).height() - ( event.pageY - $( document ).scrollTop() ) <\n\t\t\t\t\t\to.scrollSensitivity ) {\n\t\t\t\t\tscrolled = $( document ).scrollTop( $( document ).scrollTop() + o.scrollSpeed );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( !o.axis || o.axis !== \"y\" ) {\n\t\t\t\tif ( event.pageX - $( document ).scrollLeft() < o.scrollSensitivity ) {\n\t\t\t\t\tscrolled = $( document ).scrollLeft(\n\t\t\t\t\t\t$( document ).scrollLeft() - o.scrollSpeed\n\t\t\t\t\t);\n\t\t\t\t} else if ( $( window ).width() - ( event.pageX - $( document ).scrollLeft() ) <\n\t\t\t\t\t\to.scrollSensitivity ) {\n\t\t\t\t\tscrolled = $( document ).scrollLeft(\n\t\t\t\t\t\t$( document ).scrollLeft() + o.scrollSpeed\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\tif ( scrolled !== false && $.ui.ddmanager && !o.dropBehaviour ) {\n\t\t\t$.ui.ddmanager.prepareOffsets( i, event );\n\t\t}\n\n\t}\n} );\n\n$.ui.plugin.add( \"draggable\", \"snap\", {\n\tstart: function( event, ui, i ) {\n\n\t\tvar o = i.options;\n\n\t\ti.snapElements = [];\n\n\t\t$( o.snap.constructor !== String ? ( o.snap.items || \":data(ui-draggable)\" ) : o.snap )\n\t\t\t.each( function() {\n\t\t\t\tvar $t = $( this ),\n\t\t\t\t\t$o = $t.offset();\n\t\t\t\tif ( this !== i.element[ 0 ] ) {\n\t\t\t\t\ti.snapElements.push( {\n\t\t\t\t\t\titem: this,\n\t\t\t\t\t\twidth: $t.outerWidth(), height: $t.outerHeight(),\n\t\t\t\t\t\ttop: $o.top, left: $o.left\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} );\n\n\t},\n\tdrag: function( event, ui, inst ) {\n\n\t\tvar ts, bs, ls, rs, l, r, t, b, i, first,\n\t\t\to = inst.options,\n\t\t\td = o.snapTolerance,\n\t\t\tx1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,\n\t\t\ty1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;\n\n\t\tfor ( i = inst.snapElements.length - 1; i >= 0; i-- ) {\n\n\t\t\tl = inst.snapElements[ i ].left - inst.margins.left;\n\t\t\tr = l + inst.snapElements[ i ].width;\n\t\t\tt = inst.snapElements[ i ].top - inst.margins.top;\n\t\t\tb = t + inst.snapElements[ i ].height;\n\n\t\t\tif ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d ||\n\t\t\t\t\t!$.contains( inst.snapElements[ i ].item.ownerDocument,\n\t\t\t\t\tinst.snapElements[ i ].item ) ) {\n\t\t\t\tif ( inst.snapElements[ i ].snapping ) {\n\t\t\t\t\t( inst.options.snap.release &&\n\t\t\t\t\t\tinst.options.snap.release.call(\n\t\t\t\t\t\t\tinst.element,\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\t$.extend( inst._uiHash(), { snapItem: inst.snapElements[ i ].item } )\n\t\t\t\t\t\t) );\n\t\t\t\t}\n\t\t\t\tinst.snapElements[ i ].snapping = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif ( o.snapMode !== \"inner\" ) {\n\t\t\t\tts = Math.abs( t - y2 ) <= d;\n\t\t\t\tbs = Math.abs( b - y1 ) <= d;\n\t\t\t\tls = Math.abs( l - x2 ) <= d;\n\t\t\t\trs = Math.abs( r - x1 ) <= d;\n\t\t\t\tif ( ts ) {\n\t\t\t\t\tui.position.top = inst._convertPositionTo( \"relative\", {\n\t\t\t\t\t\ttop: t - inst.helperProportions.height,\n\t\t\t\t\t\tleft: 0\n\t\t\t\t\t} ).top;\n\t\t\t\t}\n\t\t\t\tif ( bs ) {\n\t\t\t\t\tui.position.top = inst._convertPositionTo( \"relative\", {\n\t\t\t\t\t\ttop: b,\n\t\t\t\t\t\tleft: 0\n\t\t\t\t\t} ).top;\n\t\t\t\t}\n\t\t\t\tif ( ls ) {\n\t\t\t\t\tui.position.left = inst._convertPositionTo( \"relative\", {\n\t\t\t\t\t\ttop: 0,\n\t\t\t\t\t\tleft: l - inst.helperProportions.width\n\t\t\t\t\t} ).left;\n\t\t\t\t}\n\t\t\t\tif ( rs ) {\n\t\t\t\t\tui.position.left = inst._convertPositionTo( \"relative\", {\n\t\t\t\t\t\ttop: 0,\n\t\t\t\t\t\tleft: r\n\t\t\t\t\t} ).left;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfirst = ( ts || bs || ls || rs );\n\n\t\t\tif ( o.snapMode !== \"outer\" ) {\n\t\t\t\tts = Math.abs( t - y1 ) <= d;\n\t\t\t\tbs = Math.abs( b - y2 ) <= d;\n\t\t\t\tls = Math.abs( l - x1 ) <= d;\n\t\t\t\trs = Math.abs( r - x2 ) <= d;\n\t\t\t\tif ( ts ) {\n\t\t\t\t\tui.position.top = inst._convertPositionTo( \"relative\", {\n\t\t\t\t\t\ttop: t,\n\t\t\t\t\t\tleft: 0\n\t\t\t\t\t} ).top;\n\t\t\t\t}\n\t\t\t\tif ( bs ) {\n\t\t\t\t\tui.position.top = inst._convertPositionTo( \"relative\", {\n\t\t\t\t\t\ttop: b - inst.helperProportions.height,\n\t\t\t\t\t\tleft: 0\n\t\t\t\t\t} ).top;\n\t\t\t\t}\n\t\t\t\tif ( ls ) {\n\t\t\t\t\tui.position.left = inst._convertPositionTo( \"relative\", {\n\t\t\t\t\t\ttop: 0,\n\t\t\t\t\t\tleft: l\n\t\t\t\t\t} ).left;\n\t\t\t\t}\n\t\t\t\tif ( rs ) {\n\t\t\t\t\tui.position.left = inst._convertPositionTo( \"relative\", {\n\t\t\t\t\t\ttop: 0,\n\t\t\t\t\t\tleft: r - inst.helperProportions.width\n\t\t\t\t\t} ).left;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( !inst.snapElements[ i ].snapping && ( ts || bs || ls || rs || first ) ) {\n\t\t\t\t( inst.options.snap.snap &&\n\t\t\t\t\tinst.options.snap.snap.call(\n\t\t\t\t\t\tinst.element,\n\t\t\t\t\t\tevent,\n\t\t\t\t\t\t$.extend( inst._uiHash(), {\n\t\t\t\t\t\t\tsnapItem: inst.snapElements[ i ].item\n\t\t\t\t\t\t} ) ) );\n\t\t\t}\n\t\t\tinst.snapElements[ i ].snapping = ( ts || bs || ls || rs || first );\n\n\t\t}\n\n\t}\n} );\n\n$.ui.plugin.add( \"draggable\", \"stack\", {\n\tstart: function( event, ui, instance ) {\n\t\tvar min,\n\t\t\to = instance.options,\n\t\t\tgroup = $.makeArray( $( o.stack ) ).sort( function( a, b ) {\n\t\t\t\treturn ( parseInt( $( a ).css( \"zIndex\" ), 10 ) || 0 ) -\n\t\t\t\t\t( parseInt( $( b ).css( \"zIndex\" ), 10 ) || 0 );\n\t\t\t} );\n\n\t\tif ( !group.length ) { return; }\n\n\t\tmin = parseInt( $( group[ 0 ] ).css( \"zIndex\" ), 10 ) || 0;\n\t\t$( group ).each( function( i ) {\n\t\t\t$( this ).css( \"zIndex\", min + i );\n\t\t} );\n\t\tthis.css( \"zIndex\", ( min + group.length ) );\n\t}\n} );\n\n$.ui.plugin.add( \"draggable\", \"zIndex\", {\n\tstart: function( event, ui, instance ) {\n\t\tvar t = $( ui.helper ),\n\t\t\to = instance.options;\n\n\t\tif ( t.css( \"zIndex\" ) ) {\n\t\t\to._zIndex = t.css( \"zIndex\" );\n\t\t}\n\t\tt.css( \"zIndex\", o.zIndex );\n\t},\n\tstop: function( event, ui, instance ) {\n\t\tvar o = instance.options;\n\n\t\tif ( o._zIndex ) {\n\t\t\t$( ui.helper ).css( \"zIndex\", o._zIndex );\n\t\t}\n\t}\n} );\n\nvar widgetsDraggable = $.ui.draggable;\n\n\n/*!\n * jQuery UI Resizable 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Resizable\n//>>group: Interactions\n//>>description: Enables resize functionality for any element.\n//>>docs: http://api.jqueryui.com/resizable/\n//>>demos: http://jqueryui.com/resizable/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/resizable.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\n$.widget( \"ui.resizable\", $.ui.mouse, {\n\tversion: \"1.12.1\",\n\twidgetEventPrefix: \"resize\",\n\toptions: {\n\t\talsoResize: false,\n\t\tanimate: false,\n\t\tanimateDuration: \"slow\",\n\t\tanimateEasing: \"swing\",\n\t\taspectRatio: false,\n\t\tautoHide: false,\n\t\tclasses: {\n\t\t\t\"ui-resizable-se\": \"ui-icon ui-icon-gripsmall-diagonal-se\"\n\t\t},\n\t\tcontainment: false,\n\t\tghost: false,\n\t\tgrid: false,\n\t\thandles: \"e,s,se\",\n\t\thelper: false,\n\t\tmaxHeight: null,\n\t\tmaxWidth: null,\n\t\tminHeight: 10,\n\t\tminWidth: 10,\n\n\t\t// See #7960\n\t\tzIndex: 90,\n\n\t\t// Callbacks\n\t\tresize: null,\n\t\tstart: null,\n\t\tstop: null\n\t},\n\n\t_num: function( value ) {\n\t\treturn parseFloat( value ) || 0;\n\t},\n\n\t_isNumber: function( value ) {\n\t\treturn !isNaN( parseFloat( value ) );\n\t},\n\n\t_hasScroll: function( el, a ) {\n\n\t\tif ( $( el ).css( \"overflow\" ) === \"hidden\" ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tvar scroll = ( a && a === \"left\" ) ? \"scrollLeft\" : \"scrollTop\",\n\t\t\thas = false;\n\n\t\tif ( el[ scroll ] > 0 ) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// TODO: determine which cases actually cause this to happen\n\t\t// if the element doesn't have the scroll set, see if it's possible to\n\t\t// set the scroll\n\t\tel[ scroll ] = 1;\n\t\thas = ( el[ scroll ] > 0 );\n\t\tel[ scroll ] = 0;\n\t\treturn has;\n\t},\n\n\t_create: function() {\n\n\t\tvar margins,\n\t\t\to = this.options,\n\t\t\tthat = this;\n\t\tthis._addClass( \"ui-resizable\" );\n\n\t\t$.extend( this, {\n\t\t\t_aspectRatio: !!( o.aspectRatio ),\n\t\t\taspectRatio: o.aspectRatio,\n\t\t\toriginalElement: this.element,\n\t\t\t_proportionallyResizeElements: [],\n\t\t\t_helper: o.helper || o.ghost || o.animate ? o.helper || \"ui-resizable-helper\" : null\n\t\t} );\n\n\t\t// Wrap the element if it cannot hold child nodes\n\t\tif ( this.element[ 0 ].nodeName.match( /^(canvas|textarea|input|select|button|img)$/i ) ) {\n\n\t\t\tthis.element.wrap(\n\t\t\t\t$( \"<div class='ui-wrapper' style='overflow: hidden;'></div>\" ).css( {\n\t\t\t\t\tposition: this.element.css( \"position\" ),\n\t\t\t\t\twidth: this.element.outerWidth(),\n\t\t\t\t\theight: this.element.outerHeight(),\n\t\t\t\t\ttop: this.element.css( \"top\" ),\n\t\t\t\t\tleft: this.element.css( \"left\" )\n\t\t\t\t} )\n\t\t\t);\n\n\t\t\tthis.element = this.element.parent().data(\n\t\t\t\t\"ui-resizable\", this.element.resizable( \"instance\" )\n\t\t\t);\n\n\t\t\tthis.elementIsWrapper = true;\n\n\t\t\tmargins = {\n\t\t\t\tmarginTop: this.originalElement.css( \"marginTop\" ),\n\t\t\t\tmarginRight: this.originalElement.css( \"marginRight\" ),\n\t\t\t\tmarginBottom: this.originalElement.css( \"marginBottom\" ),\n\t\t\t\tmarginLeft: this.originalElement.css( \"marginLeft\" )\n\t\t\t};\n\n\t\t\tthis.element.css( margins );\n\t\t\tthis.originalElement.css( \"margin\", 0 );\n\n\t\t\t// support: Safari\n\t\t\t// Prevent Safari textarea resize\n\t\t\tthis.originalResizeStyle = this.originalElement.css( \"resize\" );\n\t\t\tthis.originalElement.css( \"resize\", \"none\" );\n\n\t\t\tthis._proportionallyResizeElements.push( this.originalElement.css( {\n\t\t\t\tposition: \"static\",\n\t\t\t\tzoom: 1,\n\t\t\t\tdisplay: \"block\"\n\t\t\t} ) );\n\n\t\t\t// Support: IE9\n\t\t\t// avoid IE jump (hard set the margin)\n\t\t\tthis.originalElement.css( margins );\n\n\t\t\tthis._proportionallyResize();\n\t\t}\n\n\t\tthis._setupHandles();\n\n\t\tif ( o.autoHide ) {\n\t\t\t$( this.element )\n\t\t\t\t.on( \"mouseenter\", function() {\n\t\t\t\t\tif ( o.disabled ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthat._removeClass( \"ui-resizable-autohide\" );\n\t\t\t\t\tthat._handles.show();\n\t\t\t\t} )\n\t\t\t\t.on( \"mouseleave\", function() {\n\t\t\t\t\tif ( o.disabled ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif ( !that.resizing ) {\n\t\t\t\t\t\tthat._addClass( \"ui-resizable-autohide\" );\n\t\t\t\t\t\tthat._handles.hide();\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t}\n\n\t\tthis._mouseInit();\n\t},\n\n\t_destroy: function() {\n\n\t\tthis._mouseDestroy();\n\n\t\tvar wrapper,\n\t\t\t_destroy = function( exp ) {\n\t\t\t\t$( exp )\n\t\t\t\t\t.removeData( \"resizable\" )\n\t\t\t\t\t.removeData( \"ui-resizable\" )\n\t\t\t\t\t.off( \".resizable\" )\n\t\t\t\t\t.find( \".ui-resizable-handle\" )\n\t\t\t\t\t\t.remove();\n\t\t\t};\n\n\t\t// TODO: Unwrap at same DOM position\n\t\tif ( this.elementIsWrapper ) {\n\t\t\t_destroy( this.element );\n\t\t\twrapper = this.element;\n\t\t\tthis.originalElement.css( {\n\t\t\t\tposition: wrapper.css( \"position\" ),\n\t\t\t\twidth: wrapper.outerWidth(),\n\t\t\t\theight: wrapper.outerHeight(),\n\t\t\t\ttop: wrapper.css( \"top\" ),\n\t\t\t\tleft: wrapper.css( \"left\" )\n\t\t\t} ).insertAfter( wrapper );\n\t\t\twrapper.remove();\n\t\t}\n\n\t\tthis.originalElement.css( \"resize\", this.originalResizeStyle );\n\t\t_destroy( this.originalElement );\n\n\t\treturn this;\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tthis._super( key, value );\n\n\t\tswitch ( key ) {\n\t\tcase \"handles\":\n\t\t\tthis._removeHandles();\n\t\t\tthis._setupHandles();\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t}\n\t},\n\n\t_setupHandles: function() {\n\t\tvar o = this.options, handle, i, n, hname, axis, that = this;\n\t\tthis.handles = o.handles ||\n\t\t\t( !$( \".ui-resizable-handle\", this.element ).length ?\n\t\t\t\t\"e,s,se\" : {\n\t\t\t\t\tn: \".ui-resizable-n\",\n\t\t\t\t\te: \".ui-resizable-e\",\n\t\t\t\t\ts: \".ui-resizable-s\",\n\t\t\t\t\tw: \".ui-resizable-w\",\n\t\t\t\t\tse: \".ui-resizable-se\",\n\t\t\t\t\tsw: \".ui-resizable-sw\",\n\t\t\t\t\tne: \".ui-resizable-ne\",\n\t\t\t\t\tnw: \".ui-resizable-nw\"\n\t\t\t\t} );\n\n\t\tthis._handles = $();\n\t\tif ( this.handles.constructor === String ) {\n\n\t\t\tif ( this.handles === \"all\" ) {\n\t\t\t\tthis.handles = \"n,e,s,w,se,sw,ne,nw\";\n\t\t\t}\n\n\t\t\tn = this.handles.split( \",\" );\n\t\t\tthis.handles = {};\n\n\t\t\tfor ( i = 0; i < n.length; i++ ) {\n\n\t\t\t\thandle = $.trim( n[ i ] );\n\t\t\t\thname = \"ui-resizable-\" + handle;\n\t\t\t\taxis = $( \"<div>\" );\n\t\t\t\tthis._addClass( axis, \"ui-resizable-handle \" + hname );\n\n\t\t\t\taxis.css( { zIndex: o.zIndex } );\n\n\t\t\t\tthis.handles[ handle ] = \".ui-resizable-\" + handle;\n\t\t\t\tthis.element.append( axis );\n\t\t\t}\n\n\t\t}\n\n\t\tthis._renderAxis = function( target ) {\n\n\t\t\tvar i, axis, padPos, padWrapper;\n\n\t\t\ttarget = target || this.element;\n\n\t\t\tfor ( i in this.handles ) {\n\n\t\t\t\tif ( this.handles[ i ].constructor === String ) {\n\t\t\t\t\tthis.handles[ i ] = this.element.children( this.handles[ i ] ).first().show();\n\t\t\t\t} else if ( this.handles[ i ].jquery || this.handles[ i ].nodeType ) {\n\t\t\t\t\tthis.handles[ i ] = $( this.handles[ i ] );\n\t\t\t\t\tthis._on( this.handles[ i ], { \"mousedown\": that._mouseDown } );\n\t\t\t\t}\n\n\t\t\t\tif ( this.elementIsWrapper &&\n\t\t\t\t\t\tthis.originalElement[ 0 ]\n\t\t\t\t\t\t\t.nodeName\n\t\t\t\t\t\t\t.match( /^(textarea|input|select|button)$/i ) ) {\n\t\t\t\t\taxis = $( this.handles[ i ], this.element );\n\n\t\t\t\t\tpadWrapper = /sw|ne|nw|se|n|s/.test( i ) ?\n\t\t\t\t\t\taxis.outerHeight() :\n\t\t\t\t\t\taxis.outerWidth();\n\n\t\t\t\t\tpadPos = [ \"padding\",\n\t\t\t\t\t\t/ne|nw|n/.test( i ) ? \"Top\" :\n\t\t\t\t\t\t/se|sw|s/.test( i ) ? \"Bottom\" :\n\t\t\t\t\t\t/^e$/.test( i ) ? \"Right\" : \"Left\" ].join( \"\" );\n\n\t\t\t\t\ttarget.css( padPos, padWrapper );\n\n\t\t\t\t\tthis._proportionallyResize();\n\t\t\t\t}\n\n\t\t\t\tthis._handles = this._handles.add( this.handles[ i ] );\n\t\t\t}\n\t\t};\n\n\t\t// TODO: make renderAxis a prototype function\n\t\tthis._renderAxis( this.element );\n\n\t\tthis._handles = this._handles.add( this.element.find( \".ui-resizable-handle\" ) );\n\t\tthis._handles.disableSelection();\n\n\t\tthis._handles.on( \"mouseover\", function() {\n\t\t\tif ( !that.resizing ) {\n\t\t\t\tif ( this.className ) {\n\t\t\t\t\taxis = this.className.match( /ui-resizable-(se|sw|ne|nw|n|e|s|w)/i );\n\t\t\t\t}\n\t\t\t\tthat.axis = axis && axis[ 1 ] ? axis[ 1 ] : \"se\";\n\t\t\t}\n\t\t} );\n\n\t\tif ( o.autoHide ) {\n\t\t\tthis._handles.hide();\n\t\t\tthis._addClass( \"ui-resizable-autohide\" );\n\t\t}\n\t},\n\n\t_removeHandles: function() {\n\t\tthis._handles.remove();\n\t},\n\n\t_mouseCapture: function( event ) {\n\t\tvar i, handle,\n\t\t\tcapture = false;\n\n\t\tfor ( i in this.handles ) {\n\t\t\thandle = $( this.handles[ i ] )[ 0 ];\n\t\t\tif ( handle === event.target || $.contains( handle, event.target ) ) {\n\t\t\t\tcapture = true;\n\t\t\t}\n\t\t}\n\n\t\treturn !this.options.disabled && capture;\n\t},\n\n\t_mouseStart: function( event ) {\n\n\t\tvar curleft, curtop, cursor,\n\t\t\to = this.options,\n\t\t\tel = this.element;\n\n\t\tthis.resizing = true;\n\n\t\tthis._renderProxy();\n\n\t\tcurleft = this._num( this.helper.css( \"left\" ) );\n\t\tcurtop = this._num( this.helper.css( \"top\" ) );\n\n\t\tif ( o.containment ) {\n\t\t\tcurleft += $( o.containment ).scrollLeft() || 0;\n\t\t\tcurtop += $( o.containment ).scrollTop() || 0;\n\t\t}\n\n\t\tthis.offset = this.helper.offset();\n\t\tthis.position = { left: curleft, top: curtop };\n\n\t\tthis.size = this._helper ? {\n\t\t\t\twidth: this.helper.width(),\n\t\t\t\theight: this.helper.height()\n\t\t\t} : {\n\t\t\t\twidth: el.width(),\n\t\t\t\theight: el.height()\n\t\t\t};\n\n\t\tthis.originalSize = this._helper ? {\n\t\t\t\twidth: el.outerWidth(),\n\t\t\t\theight: el.outerHeight()\n\t\t\t} : {\n\t\t\t\twidth: el.width(),\n\t\t\t\theight: el.height()\n\t\t\t};\n\n\t\tthis.sizeDiff = {\n\t\t\twidth: el.outerWidth() - el.width(),\n\t\t\theight: el.outerHeight() - el.height()\n\t\t};\n\n\t\tthis.originalPosition = { left: curleft, top: curtop };\n\t\tthis.originalMousePosition = { left: event.pageX, top: event.pageY };\n\n\t\tthis.aspectRatio = ( typeof o.aspectRatio === \"number\" ) ?\n\t\t\to.aspectRatio :\n\t\t\t( ( this.originalSize.width / this.originalSize.height ) || 1 );\n\n\t\tcursor = $( \".ui-resizable-\" + this.axis ).css( \"cursor\" );\n\t\t$( \"body\" ).css( \"cursor\", cursor === \"auto\" ? this.axis + \"-resize\" : cursor );\n\n\t\tthis._addClass( \"ui-resizable-resizing\" );\n\t\tthis._propagate( \"start\", event );\n\t\treturn true;\n\t},\n\n\t_mouseDrag: function( event ) {\n\n\t\tvar data, props,\n\t\t\tsmp = this.originalMousePosition,\n\t\t\ta = this.axis,\n\t\t\tdx = ( event.pageX - smp.left ) || 0,\n\t\t\tdy = ( event.pageY - smp.top ) || 0,\n\t\t\ttrigger = this._change[ a ];\n\n\t\tthis._updatePrevProperties();\n\n\t\tif ( !trigger ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tdata = trigger.apply( this, [ event, dx, dy ] );\n\n\t\tthis._updateVirtualBoundaries( event.shiftKey );\n\t\tif ( this._aspectRatio || event.shiftKey ) {\n\t\t\tdata = this._updateRatio( data, event );\n\t\t}\n\n\t\tdata = this._respectSize( data, event );\n\n\t\tthis._updateCache( data );\n\n\t\tthis._propagate( \"resize\", event );\n\n\t\tprops = this._applyChanges();\n\n\t\tif ( !this._helper && this._proportionallyResizeElements.length ) {\n\t\t\tthis._proportionallyResize();\n\t\t}\n\n\t\tif ( !$.isEmptyObject( props ) ) {\n\t\t\tthis._updatePrevProperties();\n\t\t\tthis._trigger( \"resize\", event, this.ui() );\n\t\t\tthis._applyChanges();\n\t\t}\n\n\t\treturn false;\n\t},\n\n\t_mouseStop: function( event ) {\n\n\t\tthis.resizing = false;\n\t\tvar pr, ista, soffseth, soffsetw, s, left, top,\n\t\t\to = this.options, that = this;\n\n\t\tif ( this._helper ) {\n\n\t\t\tpr = this._proportionallyResizeElements;\n\t\t\tista = pr.length && ( /textarea/i ).test( pr[ 0 ].nodeName );\n\t\t\tsoffseth = ista && this._hasScroll( pr[ 0 ], \"left\" ) ? 0 : that.sizeDiff.height;\n\t\t\tsoffsetw = ista ? 0 : that.sizeDiff.width;\n\n\t\t\ts = {\n\t\t\t\twidth: ( that.helper.width()  - soffsetw ),\n\t\t\t\theight: ( that.helper.height() - soffseth )\n\t\t\t};\n\t\t\tleft = ( parseFloat( that.element.css( \"left\" ) ) +\n\t\t\t\t( that.position.left - that.originalPosition.left ) ) || null;\n\t\t\ttop = ( parseFloat( that.element.css( \"top\" ) ) +\n\t\t\t\t( that.position.top - that.originalPosition.top ) ) || null;\n\n\t\t\tif ( !o.animate ) {\n\t\t\t\tthis.element.css( $.extend( s, { top: top, left: left } ) );\n\t\t\t}\n\n\t\t\tthat.helper.height( that.size.height );\n\t\t\tthat.helper.width( that.size.width );\n\n\t\t\tif ( this._helper && !o.animate ) {\n\t\t\t\tthis._proportionallyResize();\n\t\t\t}\n\t\t}\n\n\t\t$( \"body\" ).css( \"cursor\", \"auto\" );\n\n\t\tthis._removeClass( \"ui-resizable-resizing\" );\n\n\t\tthis._propagate( \"stop\", event );\n\n\t\tif ( this._helper ) {\n\t\t\tthis.helper.remove();\n\t\t}\n\n\t\treturn false;\n\n\t},\n\n\t_updatePrevProperties: function() {\n\t\tthis.prevPosition = {\n\t\t\ttop: this.position.top,\n\t\t\tleft: this.position.left\n\t\t};\n\t\tthis.prevSize = {\n\t\t\twidth: this.size.width,\n\t\t\theight: this.size.height\n\t\t};\n\t},\n\n\t_applyChanges: function() {\n\t\tvar props = {};\n\n\t\tif ( this.position.top !== this.prevPosition.top ) {\n\t\t\tprops.top = this.position.top + \"px\";\n\t\t}\n\t\tif ( this.position.left !== this.prevPosition.left ) {\n\t\t\tprops.left = this.position.left + \"px\";\n\t\t}\n\t\tif ( this.size.width !== this.prevSize.width ) {\n\t\t\tprops.width = this.size.width + \"px\";\n\t\t}\n\t\tif ( this.size.height !== this.prevSize.height ) {\n\t\t\tprops.height = this.size.height + \"px\";\n\t\t}\n\n\t\tthis.helper.css( props );\n\n\t\treturn props;\n\t},\n\n\t_updateVirtualBoundaries: function( forceAspectRatio ) {\n\t\tvar pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b,\n\t\t\to = this.options;\n\n\t\tb = {\n\t\t\tminWidth: this._isNumber( o.minWidth ) ? o.minWidth : 0,\n\t\t\tmaxWidth: this._isNumber( o.maxWidth ) ? o.maxWidth : Infinity,\n\t\t\tminHeight: this._isNumber( o.minHeight ) ? o.minHeight : 0,\n\t\t\tmaxHeight: this._isNumber( o.maxHeight ) ? o.maxHeight : Infinity\n\t\t};\n\n\t\tif ( this._aspectRatio || forceAspectRatio ) {\n\t\t\tpMinWidth = b.minHeight * this.aspectRatio;\n\t\t\tpMinHeight = b.minWidth / this.aspectRatio;\n\t\t\tpMaxWidth = b.maxHeight * this.aspectRatio;\n\t\t\tpMaxHeight = b.maxWidth / this.aspectRatio;\n\n\t\t\tif ( pMinWidth > b.minWidth ) {\n\t\t\t\tb.minWidth = pMinWidth;\n\t\t\t}\n\t\t\tif ( pMinHeight > b.minHeight ) {\n\t\t\t\tb.minHeight = pMinHeight;\n\t\t\t}\n\t\t\tif ( pMaxWidth < b.maxWidth ) {\n\t\t\t\tb.maxWidth = pMaxWidth;\n\t\t\t}\n\t\t\tif ( pMaxHeight < b.maxHeight ) {\n\t\t\t\tb.maxHeight = pMaxHeight;\n\t\t\t}\n\t\t}\n\t\tthis._vBoundaries = b;\n\t},\n\n\t_updateCache: function( data ) {\n\t\tthis.offset = this.helper.offset();\n\t\tif ( this._isNumber( data.left ) ) {\n\t\t\tthis.position.left = data.left;\n\t\t}\n\t\tif ( this._isNumber( data.top ) ) {\n\t\t\tthis.position.top = data.top;\n\t\t}\n\t\tif ( this._isNumber( data.height ) ) {\n\t\t\tthis.size.height = data.height;\n\t\t}\n\t\tif ( this._isNumber( data.width ) ) {\n\t\t\tthis.size.width = data.width;\n\t\t}\n\t},\n\n\t_updateRatio: function( data ) {\n\n\t\tvar cpos = this.position,\n\t\t\tcsize = this.size,\n\t\t\ta = this.axis;\n\n\t\tif ( this._isNumber( data.height ) ) {\n\t\t\tdata.width = ( data.height * this.aspectRatio );\n\t\t} else if ( this._isNumber( data.width ) ) {\n\t\t\tdata.height = ( data.width / this.aspectRatio );\n\t\t}\n\n\t\tif ( a === \"sw\" ) {\n\t\t\tdata.left = cpos.left + ( csize.width - data.width );\n\t\t\tdata.top = null;\n\t\t}\n\t\tif ( a === \"nw\" ) {\n\t\t\tdata.top = cpos.top + ( csize.height - data.height );\n\t\t\tdata.left = cpos.left + ( csize.width - data.width );\n\t\t}\n\n\t\treturn data;\n\t},\n\n\t_respectSize: function( data ) {\n\n\t\tvar o = this._vBoundaries,\n\t\t\ta = this.axis,\n\t\t\tismaxw = this._isNumber( data.width ) && o.maxWidth && ( o.maxWidth < data.width ),\n\t\t\tismaxh = this._isNumber( data.height ) && o.maxHeight && ( o.maxHeight < data.height ),\n\t\t\tisminw = this._isNumber( data.width ) && o.minWidth && ( o.minWidth > data.width ),\n\t\t\tisminh = this._isNumber( data.height ) && o.minHeight && ( o.minHeight > data.height ),\n\t\t\tdw = this.originalPosition.left + this.originalSize.width,\n\t\t\tdh = this.originalPosition.top + this.originalSize.height,\n\t\t\tcw = /sw|nw|w/.test( a ), ch = /nw|ne|n/.test( a );\n\t\tif ( isminw ) {\n\t\t\tdata.width = o.minWidth;\n\t\t}\n\t\tif ( isminh ) {\n\t\t\tdata.height = o.minHeight;\n\t\t}\n\t\tif ( ismaxw ) {\n\t\t\tdata.width = o.maxWidth;\n\t\t}\n\t\tif ( ismaxh ) {\n\t\t\tdata.height = o.maxHeight;\n\t\t}\n\n\t\tif ( isminw && cw ) {\n\t\t\tdata.left = dw - o.minWidth;\n\t\t}\n\t\tif ( ismaxw && cw ) {\n\t\t\tdata.left = dw - o.maxWidth;\n\t\t}\n\t\tif ( isminh && ch ) {\n\t\t\tdata.top = dh - o.minHeight;\n\t\t}\n\t\tif ( ismaxh && ch ) {\n\t\t\tdata.top = dh - o.maxHeight;\n\t\t}\n\n\t\t// Fixing jump error on top/left - bug #2330\n\t\tif ( !data.width && !data.height && !data.left && data.top ) {\n\t\t\tdata.top = null;\n\t\t} else if ( !data.width && !data.height && !data.top && data.left ) {\n\t\t\tdata.left = null;\n\t\t}\n\n\t\treturn data;\n\t},\n\n\t_getPaddingPlusBorderDimensions: function( element ) {\n\t\tvar i = 0,\n\t\t\twidths = [],\n\t\t\tborders = [\n\t\t\t\telement.css( \"borderTopWidth\" ),\n\t\t\t\telement.css( \"borderRightWidth\" ),\n\t\t\t\telement.css( \"borderBottomWidth\" ),\n\t\t\t\telement.css( \"borderLeftWidth\" )\n\t\t\t],\n\t\t\tpaddings = [\n\t\t\t\telement.css( \"paddingTop\" ),\n\t\t\t\telement.css( \"paddingRight\" ),\n\t\t\t\telement.css( \"paddingBottom\" ),\n\t\t\t\telement.css( \"paddingLeft\" )\n\t\t\t];\n\n\t\tfor ( ; i < 4; i++ ) {\n\t\t\twidths[ i ] = ( parseFloat( borders[ i ] ) || 0 );\n\t\t\twidths[ i ] += ( parseFloat( paddings[ i ] ) || 0 );\n\t\t}\n\n\t\treturn {\n\t\t\theight: widths[ 0 ] + widths[ 2 ],\n\t\t\twidth: widths[ 1 ] + widths[ 3 ]\n\t\t};\n\t},\n\n\t_proportionallyResize: function() {\n\n\t\tif ( !this._proportionallyResizeElements.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar prel,\n\t\t\ti = 0,\n\t\t\telement = this.helper || this.element;\n\n\t\tfor ( ; i < this._proportionallyResizeElements.length; i++ ) {\n\n\t\t\tprel = this._proportionallyResizeElements[ i ];\n\n\t\t\t// TODO: Seems like a bug to cache this.outerDimensions\n\t\t\t// considering that we are in a loop.\n\t\t\tif ( !this.outerDimensions ) {\n\t\t\t\tthis.outerDimensions = this._getPaddingPlusBorderDimensions( prel );\n\t\t\t}\n\n\t\t\tprel.css( {\n\t\t\t\theight: ( element.height() - this.outerDimensions.height ) || 0,\n\t\t\t\twidth: ( element.width() - this.outerDimensions.width ) || 0\n\t\t\t} );\n\n\t\t}\n\n\t},\n\n\t_renderProxy: function() {\n\n\t\tvar el = this.element, o = this.options;\n\t\tthis.elementOffset = el.offset();\n\n\t\tif ( this._helper ) {\n\n\t\t\tthis.helper = this.helper || $( \"<div style='overflow:hidden;'></div>\" );\n\n\t\t\tthis._addClass( this.helper, this._helper );\n\t\t\tthis.helper.css( {\n\t\t\t\twidth: this.element.outerWidth(),\n\t\t\t\theight: this.element.outerHeight(),\n\t\t\t\tposition: \"absolute\",\n\t\t\t\tleft: this.elementOffset.left + \"px\",\n\t\t\t\ttop: this.elementOffset.top + \"px\",\n\t\t\t\tzIndex: ++o.zIndex //TODO: Don't modify option\n\t\t\t} );\n\n\t\t\tthis.helper\n\t\t\t\t.appendTo( \"body\" )\n\t\t\t\t.disableSelection();\n\n\t\t} else {\n\t\t\tthis.helper = this.element;\n\t\t}\n\n\t},\n\n\t_change: {\n\t\te: function( event, dx ) {\n\t\t\treturn { width: this.originalSize.width + dx };\n\t\t},\n\t\tw: function( event, dx ) {\n\t\t\tvar cs = this.originalSize, sp = this.originalPosition;\n\t\t\treturn { left: sp.left + dx, width: cs.width - dx };\n\t\t},\n\t\tn: function( event, dx, dy ) {\n\t\t\tvar cs = this.originalSize, sp = this.originalPosition;\n\t\t\treturn { top: sp.top + dy, height: cs.height - dy };\n\t\t},\n\t\ts: function( event, dx, dy ) {\n\t\t\treturn { height: this.originalSize.height + dy };\n\t\t},\n\t\tse: function( event, dx, dy ) {\n\t\t\treturn $.extend( this._change.s.apply( this, arguments ),\n\t\t\t\tthis._change.e.apply( this, [ event, dx, dy ] ) );\n\t\t},\n\t\tsw: function( event, dx, dy ) {\n\t\t\treturn $.extend( this._change.s.apply( this, arguments ),\n\t\t\t\tthis._change.w.apply( this, [ event, dx, dy ] ) );\n\t\t},\n\t\tne: function( event, dx, dy ) {\n\t\t\treturn $.extend( this._change.n.apply( this, arguments ),\n\t\t\t\tthis._change.e.apply( this, [ event, dx, dy ] ) );\n\t\t},\n\t\tnw: function( event, dx, dy ) {\n\t\t\treturn $.extend( this._change.n.apply( this, arguments ),\n\t\t\t\tthis._change.w.apply( this, [ event, dx, dy ] ) );\n\t\t}\n\t},\n\n\t_propagate: function( n, event ) {\n\t\t$.ui.plugin.call( this, n, [ event, this.ui() ] );\n\t\t( n !== \"resize\" && this._trigger( n, event, this.ui() ) );\n\t},\n\n\tplugins: {},\n\n\tui: function() {\n\t\treturn {\n\t\t\toriginalElement: this.originalElement,\n\t\t\telement: this.element,\n\t\t\thelper: this.helper,\n\t\t\tposition: this.position,\n\t\t\tsize: this.size,\n\t\t\toriginalSize: this.originalSize,\n\t\t\toriginalPosition: this.originalPosition\n\t\t};\n\t}\n\n} );\n\n/*\n * Resizable Extensions\n */\n\n$.ui.plugin.add( \"resizable\", \"animate\", {\n\n\tstop: function( event ) {\n\t\tvar that = $( this ).resizable( \"instance\" ),\n\t\t\to = that.options,\n\t\t\tpr = that._proportionallyResizeElements,\n\t\t\tista = pr.length && ( /textarea/i ).test( pr[ 0 ].nodeName ),\n\t\t\tsoffseth = ista && that._hasScroll( pr[ 0 ], \"left\" ) ? 0 : that.sizeDiff.height,\n\t\t\tsoffsetw = ista ? 0 : that.sizeDiff.width,\n\t\t\tstyle = {\n\t\t\t\twidth: ( that.size.width - soffsetw ),\n\t\t\t\theight: ( that.size.height - soffseth )\n\t\t\t},\n\t\t\tleft = ( parseFloat( that.element.css( \"left\" ) ) +\n\t\t\t\t( that.position.left - that.originalPosition.left ) ) || null,\n\t\t\ttop = ( parseFloat( that.element.css( \"top\" ) ) +\n\t\t\t\t( that.position.top - that.originalPosition.top ) ) || null;\n\n\t\tthat.element.animate(\n\t\t\t$.extend( style, top && left ? { top: top, left: left } : {} ), {\n\t\t\t\tduration: o.animateDuration,\n\t\t\t\teasing: o.animateEasing,\n\t\t\t\tstep: function() {\n\n\t\t\t\t\tvar data = {\n\t\t\t\t\t\twidth: parseFloat( that.element.css( \"width\" ) ),\n\t\t\t\t\t\theight: parseFloat( that.element.css( \"height\" ) ),\n\t\t\t\t\t\ttop: parseFloat( that.element.css( \"top\" ) ),\n\t\t\t\t\t\tleft: parseFloat( that.element.css( \"left\" ) )\n\t\t\t\t\t};\n\n\t\t\t\t\tif ( pr && pr.length ) {\n\t\t\t\t\t\t$( pr[ 0 ] ).css( { width: data.width, height: data.height } );\n\t\t\t\t\t}\n\n\t\t\t\t\t// Propagating resize, and updating values for each animation step\n\t\t\t\t\tthat._updateCache( data );\n\t\t\t\t\tthat._propagate( \"resize\", event );\n\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n} );\n\n$.ui.plugin.add( \"resizable\", \"containment\", {\n\n\tstart: function() {\n\t\tvar element, p, co, ch, cw, width, height,\n\t\t\tthat = $( this ).resizable( \"instance\" ),\n\t\t\to = that.options,\n\t\t\tel = that.element,\n\t\t\toc = o.containment,\n\t\t\tce = ( oc instanceof $ ) ?\n\t\t\t\toc.get( 0 ) :\n\t\t\t\t( /parent/.test( oc ) ) ? el.parent().get( 0 ) : oc;\n\n\t\tif ( !ce ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthat.containerElement = $( ce );\n\n\t\tif ( /document/.test( oc ) || oc === document ) {\n\t\t\tthat.containerOffset = {\n\t\t\t\tleft: 0,\n\t\t\t\ttop: 0\n\t\t\t};\n\t\t\tthat.containerPosition = {\n\t\t\t\tleft: 0,\n\t\t\t\ttop: 0\n\t\t\t};\n\n\t\t\tthat.parentData = {\n\t\t\t\telement: $( document ),\n\t\t\t\tleft: 0,\n\t\t\t\ttop: 0,\n\t\t\t\twidth: $( document ).width(),\n\t\t\t\theight: $( document ).height() || document.body.parentNode.scrollHeight\n\t\t\t};\n\t\t} else {\n\t\t\telement = $( ce );\n\t\t\tp = [];\n\t\t\t$( [ \"Top\", \"Right\", \"Left\", \"Bottom\" ] ).each( function( i, name ) {\n\t\t\t\tp[ i ] = that._num( element.css( \"padding\" + name ) );\n\t\t\t} );\n\n\t\t\tthat.containerOffset = element.offset();\n\t\t\tthat.containerPosition = element.position();\n\t\t\tthat.containerSize = {\n\t\t\t\theight: ( element.innerHeight() - p[ 3 ] ),\n\t\t\t\twidth: ( element.innerWidth() - p[ 1 ] )\n\t\t\t};\n\n\t\t\tco = that.containerOffset;\n\t\t\tch = that.containerSize.height;\n\t\t\tcw = that.containerSize.width;\n\t\t\twidth = ( that._hasScroll ( ce, \"left\" ) ? ce.scrollWidth : cw );\n\t\t\theight = ( that._hasScroll ( ce ) ? ce.scrollHeight : ch ) ;\n\n\t\t\tthat.parentData = {\n\t\t\t\telement: ce,\n\t\t\t\tleft: co.left,\n\t\t\t\ttop: co.top,\n\t\t\t\twidth: width,\n\t\t\t\theight: height\n\t\t\t};\n\t\t}\n\t},\n\n\tresize: function( event ) {\n\t\tvar woset, hoset, isParent, isOffsetRelative,\n\t\t\tthat = $( this ).resizable( \"instance\" ),\n\t\t\to = that.options,\n\t\t\tco = that.containerOffset,\n\t\t\tcp = that.position,\n\t\t\tpRatio = that._aspectRatio || event.shiftKey,\n\t\t\tcop = {\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0\n\t\t\t},\n\t\t\tce = that.containerElement,\n\t\t\tcontinueResize = true;\n\n\t\tif ( ce[ 0 ] !== document && ( /static/ ).test( ce.css( \"position\" ) ) ) {\n\t\t\tcop = co;\n\t\t}\n\n\t\tif ( cp.left < ( that._helper ? co.left : 0 ) ) {\n\t\t\tthat.size.width = that.size.width +\n\t\t\t\t( that._helper ?\n\t\t\t\t\t( that.position.left - co.left ) :\n\t\t\t\t\t( that.position.left - cop.left ) );\n\n\t\t\tif ( pRatio ) {\n\t\t\t\tthat.size.height = that.size.width / that.aspectRatio;\n\t\t\t\tcontinueResize = false;\n\t\t\t}\n\t\t\tthat.position.left = o.helper ? co.left : 0;\n\t\t}\n\n\t\tif ( cp.top < ( that._helper ? co.top : 0 ) ) {\n\t\t\tthat.size.height = that.size.height +\n\t\t\t\t( that._helper ?\n\t\t\t\t\t( that.position.top - co.top ) :\n\t\t\t\t\tthat.position.top );\n\n\t\t\tif ( pRatio ) {\n\t\t\t\tthat.size.width = that.size.height * that.aspectRatio;\n\t\t\t\tcontinueResize = false;\n\t\t\t}\n\t\t\tthat.position.top = that._helper ? co.top : 0;\n\t\t}\n\n\t\tisParent = that.containerElement.get( 0 ) === that.element.parent().get( 0 );\n\t\tisOffsetRelative = /relative|absolute/.test( that.containerElement.css( \"position\" ) );\n\n\t\tif ( isParent && isOffsetRelative ) {\n\t\t\tthat.offset.left = that.parentData.left + that.position.left;\n\t\t\tthat.offset.top = that.parentData.top + that.position.top;\n\t\t} else {\n\t\t\tthat.offset.left = that.element.offset().left;\n\t\t\tthat.offset.top = that.element.offset().top;\n\t\t}\n\n\t\twoset = Math.abs( that.sizeDiff.width +\n\t\t\t( that._helper ?\n\t\t\t\tthat.offset.left - cop.left :\n\t\t\t\t( that.offset.left - co.left ) ) );\n\n\t\thoset = Math.abs( that.sizeDiff.height +\n\t\t\t( that._helper ?\n\t\t\t\tthat.offset.top - cop.top :\n\t\t\t\t( that.offset.top - co.top ) ) );\n\n\t\tif ( woset + that.size.width >= that.parentData.width ) {\n\t\t\tthat.size.width = that.parentData.width - woset;\n\t\t\tif ( pRatio ) {\n\t\t\t\tthat.size.height = that.size.width / that.aspectRatio;\n\t\t\t\tcontinueResize = false;\n\t\t\t}\n\t\t}\n\n\t\tif ( hoset + that.size.height >= that.parentData.height ) {\n\t\t\tthat.size.height = that.parentData.height - hoset;\n\t\t\tif ( pRatio ) {\n\t\t\t\tthat.size.width = that.size.height * that.aspectRatio;\n\t\t\t\tcontinueResize = false;\n\t\t\t}\n\t\t}\n\n\t\tif ( !continueResize ) {\n\t\t\tthat.position.left = that.prevPosition.left;\n\t\t\tthat.position.top = that.prevPosition.top;\n\t\t\tthat.size.width = that.prevSize.width;\n\t\t\tthat.size.height = that.prevSize.height;\n\t\t}\n\t},\n\n\tstop: function() {\n\t\tvar that = $( this ).resizable( \"instance\" ),\n\t\t\to = that.options,\n\t\t\tco = that.containerOffset,\n\t\t\tcop = that.containerPosition,\n\t\t\tce = that.containerElement,\n\t\t\thelper = $( that.helper ),\n\t\t\tho = helper.offset(),\n\t\t\tw = helper.outerWidth() - that.sizeDiff.width,\n\t\t\th = helper.outerHeight() - that.sizeDiff.height;\n\n\t\tif ( that._helper && !o.animate && ( /relative/ ).test( ce.css( \"position\" ) ) ) {\n\t\t\t$( this ).css( {\n\t\t\t\tleft: ho.left - cop.left - co.left,\n\t\t\t\twidth: w,\n\t\t\t\theight: h\n\t\t\t} );\n\t\t}\n\n\t\tif ( that._helper && !o.animate && ( /static/ ).test( ce.css( \"position\" ) ) ) {\n\t\t\t$( this ).css( {\n\t\t\t\tleft: ho.left - cop.left - co.left,\n\t\t\t\twidth: w,\n\t\t\t\theight: h\n\t\t\t} );\n\t\t}\n\t}\n} );\n\n$.ui.plugin.add( \"resizable\", \"alsoResize\", {\n\n\tstart: function() {\n\t\tvar that = $( this ).resizable( \"instance\" ),\n\t\t\to = that.options;\n\n\t\t$( o.alsoResize ).each( function() {\n\t\t\tvar el = $( this );\n\t\t\tel.data( \"ui-resizable-alsoresize\", {\n\t\t\t\twidth: parseFloat( el.width() ), height: parseFloat( el.height() ),\n\t\t\t\tleft: parseFloat( el.css( \"left\" ) ), top: parseFloat( el.css( \"top\" ) )\n\t\t\t} );\n\t\t} );\n\t},\n\n\tresize: function( event, ui ) {\n\t\tvar that = $( this ).resizable( \"instance\" ),\n\t\t\to = that.options,\n\t\t\tos = that.originalSize,\n\t\t\top = that.originalPosition,\n\t\t\tdelta = {\n\t\t\t\theight: ( that.size.height - os.height ) || 0,\n\t\t\t\twidth: ( that.size.width - os.width ) || 0,\n\t\t\t\ttop: ( that.position.top - op.top ) || 0,\n\t\t\t\tleft: ( that.position.left - op.left ) || 0\n\t\t\t};\n\n\t\t\t$( o.alsoResize ).each( function() {\n\t\t\t\tvar el = $( this ), start = $( this ).data( \"ui-resizable-alsoresize\" ), style = {},\n\t\t\t\t\tcss = el.parents( ui.originalElement[ 0 ] ).length ?\n\t\t\t\t\t\t\t[ \"width\", \"height\" ] :\n\t\t\t\t\t\t\t[ \"width\", \"height\", \"top\", \"left\" ];\n\n\t\t\t\t$.each( css, function( i, prop ) {\n\t\t\t\t\tvar sum = ( start[ prop ] || 0 ) + ( delta[ prop ] || 0 );\n\t\t\t\t\tif ( sum && sum >= 0 ) {\n\t\t\t\t\t\tstyle[ prop ] = sum || null;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\tel.css( style );\n\t\t\t} );\n\t},\n\n\tstop: function() {\n\t\t$( this ).removeData( \"ui-resizable-alsoresize\" );\n\t}\n} );\n\n$.ui.plugin.add( \"resizable\", \"ghost\", {\n\n\tstart: function() {\n\n\t\tvar that = $( this ).resizable( \"instance\" ), cs = that.size;\n\n\t\tthat.ghost = that.originalElement.clone();\n\t\tthat.ghost.css( {\n\t\t\topacity: 0.25,\n\t\t\tdisplay: \"block\",\n\t\t\tposition: \"relative\",\n\t\t\theight: cs.height,\n\t\t\twidth: cs.width,\n\t\t\tmargin: 0,\n\t\t\tleft: 0,\n\t\t\ttop: 0\n\t\t} );\n\n\t\tthat._addClass( that.ghost, \"ui-resizable-ghost\" );\n\n\t\t// DEPRECATED\n\t\t// TODO: remove after 1.12\n\t\tif ( $.uiBackCompat !== false && typeof that.options.ghost === \"string\" ) {\n\n\t\t\t// Ghost option\n\t\t\tthat.ghost.addClass( this.options.ghost );\n\t\t}\n\n\t\tthat.ghost.appendTo( that.helper );\n\n\t},\n\n\tresize: function() {\n\t\tvar that = $( this ).resizable( \"instance\" );\n\t\tif ( that.ghost ) {\n\t\t\tthat.ghost.css( {\n\t\t\t\tposition: \"relative\",\n\t\t\t\theight: that.size.height,\n\t\t\t\twidth: that.size.width\n\t\t\t} );\n\t\t}\n\t},\n\n\tstop: function() {\n\t\tvar that = $( this ).resizable( \"instance\" );\n\t\tif ( that.ghost && that.helper ) {\n\t\t\tthat.helper.get( 0 ).removeChild( that.ghost.get( 0 ) );\n\t\t}\n\t}\n\n} );\n\n$.ui.plugin.add( \"resizable\", \"grid\", {\n\n\tresize: function() {\n\t\tvar outerDimensions,\n\t\t\tthat = $( this ).resizable( \"instance\" ),\n\t\t\to = that.options,\n\t\t\tcs = that.size,\n\t\t\tos = that.originalSize,\n\t\t\top = that.originalPosition,\n\t\t\ta = that.axis,\n\t\t\tgrid = typeof o.grid === \"number\" ? [ o.grid, o.grid ] : o.grid,\n\t\t\tgridX = ( grid[ 0 ] || 1 ),\n\t\t\tgridY = ( grid[ 1 ] || 1 ),\n\t\t\tox = Math.round( ( cs.width - os.width ) / gridX ) * gridX,\n\t\t\toy = Math.round( ( cs.height - os.height ) / gridY ) * gridY,\n\t\t\tnewWidth = os.width + ox,\n\t\t\tnewHeight = os.height + oy,\n\t\t\tisMaxWidth = o.maxWidth && ( o.maxWidth < newWidth ),\n\t\t\tisMaxHeight = o.maxHeight && ( o.maxHeight < newHeight ),\n\t\t\tisMinWidth = o.minWidth && ( o.minWidth > newWidth ),\n\t\t\tisMinHeight = o.minHeight && ( o.minHeight > newHeight );\n\n\t\to.grid = grid;\n\n\t\tif ( isMinWidth ) {\n\t\t\tnewWidth += gridX;\n\t\t}\n\t\tif ( isMinHeight ) {\n\t\t\tnewHeight += gridY;\n\t\t}\n\t\tif ( isMaxWidth ) {\n\t\t\tnewWidth -= gridX;\n\t\t}\n\t\tif ( isMaxHeight ) {\n\t\t\tnewHeight -= gridY;\n\t\t}\n\n\t\tif ( /^(se|s|e)$/.test( a ) ) {\n\t\t\tthat.size.width = newWidth;\n\t\t\tthat.size.height = newHeight;\n\t\t} else if ( /^(ne)$/.test( a ) ) {\n\t\t\tthat.size.width = newWidth;\n\t\t\tthat.size.height = newHeight;\n\t\t\tthat.position.top = op.top - oy;\n\t\t} else if ( /^(sw)$/.test( a ) ) {\n\t\t\tthat.size.width = newWidth;\n\t\t\tthat.size.height = newHeight;\n\t\t\tthat.position.left = op.left - ox;\n\t\t} else {\n\t\t\tif ( newHeight - gridY <= 0 || newWidth - gridX <= 0 ) {\n\t\t\t\touterDimensions = that._getPaddingPlusBorderDimensions( this );\n\t\t\t}\n\n\t\t\tif ( newHeight - gridY > 0 ) {\n\t\t\t\tthat.size.height = newHeight;\n\t\t\t\tthat.position.top = op.top - oy;\n\t\t\t} else {\n\t\t\t\tnewHeight = gridY - outerDimensions.height;\n\t\t\t\tthat.size.height = newHeight;\n\t\t\t\tthat.position.top = op.top + os.height - newHeight;\n\t\t\t}\n\t\t\tif ( newWidth - gridX > 0 ) {\n\t\t\t\tthat.size.width = newWidth;\n\t\t\t\tthat.position.left = op.left - ox;\n\t\t\t} else {\n\t\t\t\tnewWidth = gridX - outerDimensions.width;\n\t\t\t\tthat.size.width = newWidth;\n\t\t\t\tthat.position.left = op.left + os.width - newWidth;\n\t\t\t}\n\t\t}\n\t}\n\n} );\n\nvar widgetsResizable = $.ui.resizable;\n\n\n/*!\n * jQuery UI Dialog 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Dialog\n//>>group: Widgets\n//>>description: Displays customizable dialog windows.\n//>>docs: http://api.jqueryui.com/dialog/\n//>>demos: http://jqueryui.com/dialog/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/dialog.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\n$.widget( \"ui.dialog\", {\n\tversion: \"1.12.1\",\n\toptions: {\n\t\tappendTo: \"body\",\n\t\tautoOpen: true,\n\t\tbuttons: [],\n\t\tclasses: {\n\t\t\t\"ui-dialog\": \"ui-corner-all\",\n\t\t\t\"ui-dialog-titlebar\": \"ui-corner-all\"\n\t\t},\n\t\tcloseOnEscape: true,\n\t\tcloseText: \"Close\",\n\t\tdraggable: true,\n\t\thide: null,\n\t\theight: \"auto\",\n\t\tmaxHeight: null,\n\t\tmaxWidth: null,\n\t\tminHeight: 150,\n\t\tminWidth: 150,\n\t\tmodal: false,\n\t\tposition: {\n\t\t\tmy: \"center\",\n\t\t\tat: \"center\",\n\t\t\tof: window,\n\t\t\tcollision: \"fit\",\n\n\t\t\t// Ensure the titlebar is always visible\n\t\t\tusing: function( pos ) {\n\t\t\t\tvar topOffset = $( this ).css( pos ).offset().top;\n\t\t\t\tif ( topOffset < 0 ) {\n\t\t\t\t\t$( this ).css( \"top\", pos.top - topOffset );\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tresizable: true,\n\t\tshow: null,\n\t\ttitle: null,\n\t\twidth: 300,\n\n\t\t// Callbacks\n\t\tbeforeClose: null,\n\t\tclose: null,\n\t\tdrag: null,\n\t\tdragStart: null,\n\t\tdragStop: null,\n\t\tfocus: null,\n\t\topen: null,\n\t\tresize: null,\n\t\tresizeStart: null,\n\t\tresizeStop: null\n\t},\n\n\tsizeRelatedOptions: {\n\t\tbuttons: true,\n\t\theight: true,\n\t\tmaxHeight: true,\n\t\tmaxWidth: true,\n\t\tminHeight: true,\n\t\tminWidth: true,\n\t\twidth: true\n\t},\n\n\tresizableRelatedOptions: {\n\t\tmaxHeight: true,\n\t\tmaxWidth: true,\n\t\tminHeight: true,\n\t\tminWidth: true\n\t},\n\n\t_create: function() {\n\t\tthis.originalCss = {\n\t\t\tdisplay: this.element[ 0 ].style.display,\n\t\t\twidth: this.element[ 0 ].style.width,\n\t\t\tminHeight: this.element[ 0 ].style.minHeight,\n\t\t\tmaxHeight: this.element[ 0 ].style.maxHeight,\n\t\t\theight: this.element[ 0 ].style.height\n\t\t};\n\t\tthis.originalPosition = {\n\t\t\tparent: this.element.parent(),\n\t\t\tindex: this.element.parent().children().index( this.element )\n\t\t};\n\t\tthis.originalTitle = this.element.attr( \"title\" );\n\t\tif ( this.options.title == null && this.originalTitle != null ) {\n\t\t\tthis.options.title = this.originalTitle;\n\t\t}\n\n\t\t// Dialogs can't be disabled\n\t\tif ( this.options.disabled ) {\n\t\t\tthis.options.disabled = false;\n\t\t}\n\n\t\tthis._createWrapper();\n\n\t\tthis.element\n\t\t\t.show()\n\t\t\t.removeAttr( \"title\" )\n\t\t\t.appendTo( this.uiDialog );\n\n\t\tthis._addClass( \"ui-dialog-content\", \"ui-widget-content\" );\n\n\t\tthis._createTitlebar();\n\t\tthis._createButtonPane();\n\n\t\tif ( this.options.draggable && $.fn.draggable ) {\n\t\t\tthis._makeDraggable();\n\t\t}\n\t\tif ( this.options.resizable && $.fn.resizable ) {\n\t\t\tthis._makeResizable();\n\t\t}\n\n\t\tthis._isOpen = false;\n\n\t\tthis._trackFocus();\n\t},\n\n\t_init: function() {\n\t\tif ( this.options.autoOpen ) {\n\t\t\tthis.open();\n\t\t}\n\t},\n\n\t_appendTo: function() {\n\t\tvar element = this.options.appendTo;\n\t\tif ( element && ( element.jquery || element.nodeType ) ) {\n\t\t\treturn $( element );\n\t\t}\n\t\treturn this.document.find( element || \"body\" ).eq( 0 );\n\t},\n\n\t_destroy: function() {\n\t\tvar next,\n\t\t\toriginalPosition = this.originalPosition;\n\n\t\tthis._untrackInstance();\n\t\tthis._destroyOverlay();\n\n\t\tthis.element\n\t\t\t.removeUniqueId()\n\t\t\t.css( this.originalCss )\n\n\t\t\t// Without detaching first, the following becomes really slow\n\t\t\t.detach();\n\n\t\tthis.uiDialog.remove();\n\n\t\tif ( this.originalTitle ) {\n\t\t\tthis.element.attr( \"title\", this.originalTitle );\n\t\t}\n\n\t\tnext = originalPosition.parent.children().eq( originalPosition.index );\n\n\t\t// Don't try to place the dialog next to itself (#8613)\n\t\tif ( next.length && next[ 0 ] !== this.element[ 0 ] ) {\n\t\t\tnext.before( this.element );\n\t\t} else {\n\t\t\toriginalPosition.parent.append( this.element );\n\t\t}\n\t},\n\n\twidget: function() {\n\t\treturn this.uiDialog;\n\t},\n\n\tdisable: $.noop,\n\tenable: $.noop,\n\n\tclose: function( event ) {\n\t\tvar that = this;\n\n\t\tif ( !this._isOpen || this._trigger( \"beforeClose\", event ) === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._isOpen = false;\n\t\tthis._focusedElement = null;\n\t\tthis._destroyOverlay();\n\t\tthis._untrackInstance();\n\n\t\tif ( !this.opener.filter( \":focusable\" ).trigger( \"focus\" ).length ) {\n\n\t\t\t// Hiding a focused element doesn't trigger blur in WebKit\n\t\t\t// so in case we have nothing to focus on, explicitly blur the active element\n\t\t\t// https://bugs.webkit.org/show_bug.cgi?id=47182\n\t\t\t$.ui.safeBlur( $.ui.safeActiveElement( this.document[ 0 ] ) );\n\t\t}\n\n\t\tthis._hide( this.uiDialog, this.options.hide, function() {\n\t\t\tthat._trigger( \"close\", event );\n\t\t} );\n\t},\n\n\tisOpen: function() {\n\t\treturn this._isOpen;\n\t},\n\n\tmoveToTop: function() {\n\t\tthis._moveToTop();\n\t},\n\n\t_moveToTop: function( event, silent ) {\n\t\tvar moved = false,\n\t\t\tzIndices = this.uiDialog.siblings( \".ui-front:visible\" ).map( function() {\n\t\t\t\treturn +$( this ).css( \"z-index\" );\n\t\t\t} ).get(),\n\t\t\tzIndexMax = Math.max.apply( null, zIndices );\n\n\t\tif ( zIndexMax >= +this.uiDialog.css( \"z-index\" ) ) {\n\t\t\tthis.uiDialog.css( \"z-index\", zIndexMax + 1 );\n\t\t\tmoved = true;\n\t\t}\n\n\t\tif ( moved && !silent ) {\n\t\t\tthis._trigger( \"focus\", event );\n\t\t}\n\t\treturn moved;\n\t},\n\n\topen: function() {\n\t\tvar that = this;\n\t\tif ( this._isOpen ) {\n\t\t\tif ( this._moveToTop() ) {\n\t\t\t\tthis._focusTabbable();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tthis._isOpen = true;\n\t\tthis.opener = $( $.ui.safeActiveElement( this.document[ 0 ] ) );\n\n\t\tthis._size();\n\t\tthis._position();\n\t\tthis._createOverlay();\n\t\tthis._moveToTop( null, true );\n\n\t\t// Ensure the overlay is moved to the top with the dialog, but only when\n\t\t// opening. The overlay shouldn't move after the dialog is open so that\n\t\t// modeless dialogs opened after the modal dialog stack properly.\n\t\tif ( this.overlay ) {\n\t\t\tthis.overlay.css( \"z-index\", this.uiDialog.css( \"z-index\" ) - 1 );\n\t\t}\n\n\t\tthis._show( this.uiDialog, this.options.show, function() {\n\t\t\tthat._focusTabbable();\n\t\t\tthat._trigger( \"focus\" );\n\t\t} );\n\n\t\t// Track the dialog immediately upon openening in case a focus event\n\t\t// somehow occurs outside of the dialog before an element inside the\n\t\t// dialog is focused (#10152)\n\t\tthis._makeFocusTarget();\n\n\t\tthis._trigger( \"open\" );\n\t},\n\n\t_focusTabbable: function() {\n\n\t\t// Set focus to the first match:\n\t\t// 1. An element that was focused previously\n\t\t// 2. First element inside the dialog matching [autofocus]\n\t\t// 3. Tabbable element inside the content element\n\t\t// 4. Tabbable element inside the buttonpane\n\t\t// 5. The close button\n\t\t// 6. The dialog itself\n\t\tvar hasFocus = this._focusedElement;\n\t\tif ( !hasFocus ) {\n\t\t\thasFocus = this.element.find( \"[autofocus]\" );\n\t\t}\n\t\tif ( !hasFocus.length ) {\n\t\t\thasFocus = this.element.find( \":tabbable\" );\n\t\t}\n\t\tif ( !hasFocus.length ) {\n\t\t\thasFocus = this.uiDialogButtonPane.find( \":tabbable\" );\n\t\t}\n\t\tif ( !hasFocus.length ) {\n\t\t\thasFocus = this.uiDialogTitlebarClose.filter( \":tabbable\" );\n\t\t}\n\t\tif ( !hasFocus.length ) {\n\t\t\thasFocus = this.uiDialog;\n\t\t}\n\t\thasFocus.eq( 0 ).trigger( \"focus\" );\n\t},\n\n\t_keepFocus: function( event ) {\n\t\tfunction checkFocus() {\n\t\t\tvar activeElement = $.ui.safeActiveElement( this.document[ 0 ] ),\n\t\t\t\tisActive = this.uiDialog[ 0 ] === activeElement ||\n\t\t\t\t\t$.contains( this.uiDialog[ 0 ], activeElement );\n\t\t\tif ( !isActive ) {\n\t\t\t\tthis._focusTabbable();\n\t\t\t}\n\t\t}\n\t\tevent.preventDefault();\n\t\tcheckFocus.call( this );\n\n\t\t// support: IE\n\t\t// IE <= 8 doesn't prevent moving focus even with event.preventDefault()\n\t\t// so we check again later\n\t\tthis._delay( checkFocus );\n\t},\n\n\t_createWrapper: function() {\n\t\tthis.uiDialog = $( \"<div>\" )\n\t\t\t.hide()\n\t\t\t.attr( {\n\n\t\t\t\t// Setting tabIndex makes the div focusable\n\t\t\t\ttabIndex: -1,\n\t\t\t\trole: \"dialog\"\n\t\t\t} )\n\t\t\t.appendTo( this._appendTo() );\n\n\t\tthis._addClass( this.uiDialog, \"ui-dialog\", \"ui-widget ui-widget-content ui-front\" );\n\t\tthis._on( this.uiDialog, {\n\t\t\tkeydown: function( event ) {\n\t\t\t\tif ( this.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&\n\t\t\t\t\t\tevent.keyCode === $.ui.keyCode.ESCAPE ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tthis.close( event );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Prevent tabbing out of dialogs\n\t\t\t\tif ( event.keyCode !== $.ui.keyCode.TAB || event.isDefaultPrevented() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tvar tabbables = this.uiDialog.find( \":tabbable\" ),\n\t\t\t\t\tfirst = tabbables.filter( \":first\" ),\n\t\t\t\t\tlast = tabbables.filter( \":last\" );\n\n\t\t\t\tif ( ( event.target === last[ 0 ] || event.target === this.uiDialog[ 0 ] ) &&\n\t\t\t\t\t\t!event.shiftKey ) {\n\t\t\t\t\tthis._delay( function() {\n\t\t\t\t\t\tfirst.trigger( \"focus\" );\n\t\t\t\t\t} );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t} else if ( ( event.target === first[ 0 ] ||\n\t\t\t\t\t\tevent.target === this.uiDialog[ 0 ] ) && event.shiftKey ) {\n\t\t\t\t\tthis._delay( function() {\n\t\t\t\t\t\tlast.trigger( \"focus\" );\n\t\t\t\t\t} );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t},\n\t\t\tmousedown: function( event ) {\n\t\t\t\tif ( this._moveToTop( event ) ) {\n\t\t\t\t\tthis._focusTabbable();\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\n\t\t// We assume that any existing aria-describedby attribute means\n\t\t// that the dialog content is marked up properly\n\t\t// otherwise we brute force the content as the description\n\t\tif ( !this.element.find( \"[aria-describedby]\" ).length ) {\n\t\t\tthis.uiDialog.attr( {\n\t\t\t\t\"aria-describedby\": this.element.uniqueId().attr( \"id\" )\n\t\t\t} );\n\t\t}\n\t},\n\n\t_createTitlebar: function() {\n\t\tvar uiDialogTitle;\n\n\t\tthis.uiDialogTitlebar = $( \"<div>\" );\n\t\tthis._addClass( this.uiDialogTitlebar,\n\t\t\t\"ui-dialog-titlebar\", \"ui-widget-header ui-helper-clearfix\" );\n\t\tthis._on( this.uiDialogTitlebar, {\n\t\t\tmousedown: function( event ) {\n\n\t\t\t\t// Don't prevent click on close button (#8838)\n\t\t\t\t// Focusing a dialog that is partially scrolled out of view\n\t\t\t\t// causes the browser to scroll it into view, preventing the click event\n\t\t\t\tif ( !$( event.target ).closest( \".ui-dialog-titlebar-close\" ) ) {\n\n\t\t\t\t\t// Dialog isn't getting focus when dragging (#8063)\n\t\t\t\t\tthis.uiDialog.trigger( \"focus\" );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\n\t\t// Support: IE\n\t\t// Use type=\"button\" to prevent enter keypresses in textboxes from closing the\n\t\t// dialog in IE (#9312)\n\t\tthis.uiDialogTitlebarClose = $( \"<button type='button'></button>\" )\n\t\t\t.button( {\n\t\t\t\tlabel: $( \"<a>\" ).text( this.options.closeText ).html(),\n\t\t\t\ticon: \"ui-icon-closethick\",\n\t\t\t\tshowLabel: false\n\t\t\t} )\n\t\t\t.appendTo( this.uiDialogTitlebar );\n\n\t\tthis._addClass( this.uiDialogTitlebarClose, \"ui-dialog-titlebar-close\" );\n\t\tthis._on( this.uiDialogTitlebarClose, {\n\t\t\tclick: function( event ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tthis.close( event );\n\t\t\t}\n\t\t} );\n\n\t\tuiDialogTitle = $( \"<span>\" ).uniqueId().prependTo( this.uiDialogTitlebar );\n\t\tthis._addClass( uiDialogTitle, \"ui-dialog-title\" );\n\t\tthis._title( uiDialogTitle );\n\n\t\tthis.uiDialogTitlebar.prependTo( this.uiDialog );\n\n\t\tthis.uiDialog.attr( {\n\t\t\t\"aria-labelledby\": uiDialogTitle.attr( \"id\" )\n\t\t} );\n\t},\n\n\t_title: function( title ) {\n\t\tif ( this.options.title ) {\n\t\t\ttitle.text( this.options.title );\n\t\t} else {\n\t\t\ttitle.html( \"&#160;\" );\n\t\t}\n\t},\n\n\t_createButtonPane: function() {\n\t\tthis.uiDialogButtonPane = $( \"<div>\" );\n\t\tthis._addClass( this.uiDialogButtonPane, \"ui-dialog-buttonpane\",\n\t\t\t\"ui-widget-content ui-helper-clearfix\" );\n\n\t\tthis.uiButtonSet = $( \"<div>\" )\n\t\t\t.appendTo( this.uiDialogButtonPane );\n\t\tthis._addClass( this.uiButtonSet, \"ui-dialog-buttonset\" );\n\n\t\tthis._createButtons();\n\t},\n\n\t_createButtons: function() {\n\t\tvar that = this,\n\t\t\tbuttons = this.options.buttons;\n\n\t\t// If we already have a button pane, remove it\n\t\tthis.uiDialogButtonPane.remove();\n\t\tthis.uiButtonSet.empty();\n\n\t\tif ( $.isEmptyObject( buttons ) || ( $.isArray( buttons ) && !buttons.length ) ) {\n\t\t\tthis._removeClass( this.uiDialog, \"ui-dialog-buttons\" );\n\t\t\treturn;\n\t\t}\n\n\t\t$.each( buttons, function( name, props ) {\n\t\t\tvar click, buttonOptions;\n\t\t\tprops = $.isFunction( props ) ?\n\t\t\t\t{ click: props, text: name } :\n\t\t\t\tprops;\n\n\t\t\t// Default to a non-submitting button\n\t\t\tprops = $.extend( { type: \"button\" }, props );\n\n\t\t\t// Change the context for the click callback to be the main element\n\t\t\tclick = props.click;\n\t\t\tbuttonOptions = {\n\t\t\t\ticon: props.icon,\n\t\t\t\ticonPosition: props.iconPosition,\n\t\t\t\tshowLabel: props.showLabel,\n\n\t\t\t\t// Deprecated options\n\t\t\t\ticons: props.icons,\n\t\t\t\ttext: props.text\n\t\t\t};\n\n\t\t\tdelete props.click;\n\t\t\tdelete props.icon;\n\t\t\tdelete props.iconPosition;\n\t\t\tdelete props.showLabel;\n\n\t\t\t// Deprecated options\n\t\t\tdelete props.icons;\n\t\t\tif ( typeof props.text === \"boolean\" ) {\n\t\t\t\tdelete props.text;\n\t\t\t}\n\n\t\t\t$( \"<button></button>\", props )\n\t\t\t\t.button( buttonOptions )\n\t\t\t\t.appendTo( that.uiButtonSet )\n\t\t\t\t.on( \"click\", function() {\n\t\t\t\t\tclick.apply( that.element[ 0 ], arguments );\n\t\t\t\t} );\n\t\t} );\n\t\tthis._addClass( this.uiDialog, \"ui-dialog-buttons\" );\n\t\tthis.uiDialogButtonPane.appendTo( this.uiDialog );\n\t},\n\n\t_makeDraggable: function() {\n\t\tvar that = this,\n\t\t\toptions = this.options;\n\n\t\tfunction filteredUi( ui ) {\n\t\t\treturn {\n\t\t\t\tposition: ui.position,\n\t\t\t\toffset: ui.offset\n\t\t\t};\n\t\t}\n\n\t\tthis.uiDialog.draggable( {\n\t\t\tcancel: \".ui-dialog-content, .ui-dialog-titlebar-close\",\n\t\t\thandle: \".ui-dialog-titlebar\",\n\t\t\tcontainment: \"document\",\n\t\t\tstart: function( event, ui ) {\n\t\t\t\tthat._addClass( $( this ), \"ui-dialog-dragging\" );\n\t\t\t\tthat._blockFrames();\n\t\t\t\tthat._trigger( \"dragStart\", event, filteredUi( ui ) );\n\t\t\t},\n\t\t\tdrag: function( event, ui ) {\n\t\t\t\tthat._trigger( \"drag\", event, filteredUi( ui ) );\n\t\t\t},\n\t\t\tstop: function( event, ui ) {\n\t\t\t\tvar left = ui.offset.left - that.document.scrollLeft(),\n\t\t\t\t\ttop = ui.offset.top - that.document.scrollTop();\n\n\t\t\t\toptions.position = {\n\t\t\t\t\tmy: \"left top\",\n\t\t\t\t\tat: \"left\" + ( left >= 0 ? \"+\" : \"\" ) + left + \" \" +\n\t\t\t\t\t\t\"top\" + ( top >= 0 ? \"+\" : \"\" ) + top,\n\t\t\t\t\tof: that.window\n\t\t\t\t};\n\t\t\t\tthat._removeClass( $( this ), \"ui-dialog-dragging\" );\n\t\t\t\tthat._unblockFrames();\n\t\t\t\tthat._trigger( \"dragStop\", event, filteredUi( ui ) );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_makeResizable: function() {\n\t\tvar that = this,\n\t\t\toptions = this.options,\n\t\t\thandles = options.resizable,\n\n\t\t\t// .ui-resizable has position: relative defined in the stylesheet\n\t\t\t// but dialogs have to use absolute or fixed positioning\n\t\t\tposition = this.uiDialog.css( \"position\" ),\n\t\t\tresizeHandles = typeof handles === \"string\" ?\n\t\t\t\thandles :\n\t\t\t\t\"n,e,s,w,se,sw,ne,nw\";\n\n\t\tfunction filteredUi( ui ) {\n\t\t\treturn {\n\t\t\t\toriginalPosition: ui.originalPosition,\n\t\t\t\toriginalSize: ui.originalSize,\n\t\t\t\tposition: ui.position,\n\t\t\t\tsize: ui.size\n\t\t\t};\n\t\t}\n\n\t\tthis.uiDialog.resizable( {\n\t\t\tcancel: \".ui-dialog-content\",\n\t\t\tcontainment: \"document\",\n\t\t\talsoResize: this.element,\n\t\t\tmaxWidth: options.maxWidth,\n\t\t\tmaxHeight: options.maxHeight,\n\t\t\tminWidth: options.minWidth,\n\t\t\tminHeight: this._minHeight(),\n\t\t\thandles: resizeHandles,\n\t\t\tstart: function( event, ui ) {\n\t\t\t\tthat._addClass( $( this ), \"ui-dialog-resizing\" );\n\t\t\t\tthat._blockFrames();\n\t\t\t\tthat._trigger( \"resizeStart\", event, filteredUi( ui ) );\n\t\t\t},\n\t\t\tresize: function( event, ui ) {\n\t\t\t\tthat._trigger( \"resize\", event, filteredUi( ui ) );\n\t\t\t},\n\t\t\tstop: function( event, ui ) {\n\t\t\t\tvar offset = that.uiDialog.offset(),\n\t\t\t\t\tleft = offset.left - that.document.scrollLeft(),\n\t\t\t\t\ttop = offset.top - that.document.scrollTop();\n\n\t\t\t\toptions.height = that.uiDialog.height();\n\t\t\t\toptions.width = that.uiDialog.width();\n\t\t\t\toptions.position = {\n\t\t\t\t\tmy: \"left top\",\n\t\t\t\t\tat: \"left\" + ( left >= 0 ? \"+\" : \"\" ) + left + \" \" +\n\t\t\t\t\t\t\"top\" + ( top >= 0 ? \"+\" : \"\" ) + top,\n\t\t\t\t\tof: that.window\n\t\t\t\t};\n\t\t\t\tthat._removeClass( $( this ), \"ui-dialog-resizing\" );\n\t\t\t\tthat._unblockFrames();\n\t\t\t\tthat._trigger( \"resizeStop\", event, filteredUi( ui ) );\n\t\t\t}\n\t\t} )\n\t\t\t.css( \"position\", position );\n\t},\n\n\t_trackFocus: function() {\n\t\tthis._on( this.widget(), {\n\t\t\tfocusin: function( event ) {\n\t\t\t\tthis._makeFocusTarget();\n\t\t\t\tthis._focusedElement = $( event.target );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_makeFocusTarget: function() {\n\t\tthis._untrackInstance();\n\t\tthis._trackingInstances().unshift( this );\n\t},\n\n\t_untrackInstance: function() {\n\t\tvar instances = this._trackingInstances(),\n\t\t\texists = $.inArray( this, instances );\n\t\tif ( exists !== -1 ) {\n\t\t\tinstances.splice( exists, 1 );\n\t\t}\n\t},\n\n\t_trackingInstances: function() {\n\t\tvar instances = this.document.data( \"ui-dialog-instances\" );\n\t\tif ( !instances ) {\n\t\t\tinstances = [];\n\t\t\tthis.document.data( \"ui-dialog-instances\", instances );\n\t\t}\n\t\treturn instances;\n\t},\n\n\t_minHeight: function() {\n\t\tvar options = this.options;\n\n\t\treturn options.height === \"auto\" ?\n\t\t\toptions.minHeight :\n\t\t\tMath.min( options.minHeight, options.height );\n\t},\n\n\t_position: function() {\n\n\t\t// Need to show the dialog to get the actual offset in the position plugin\n\t\tvar isVisible = this.uiDialog.is( \":visible\" );\n\t\tif ( !isVisible ) {\n\t\t\tthis.uiDialog.show();\n\t\t}\n\t\tthis.uiDialog.position( this.options.position );\n\t\tif ( !isVisible ) {\n\t\t\tthis.uiDialog.hide();\n\t\t}\n\t},\n\n\t_setOptions: function( options ) {\n\t\tvar that = this,\n\t\t\tresize = false,\n\t\t\tresizableOptions = {};\n\n\t\t$.each( options, function( key, value ) {\n\t\t\tthat._setOption( key, value );\n\n\t\t\tif ( key in that.sizeRelatedOptions ) {\n\t\t\t\tresize = true;\n\t\t\t}\n\t\t\tif ( key in that.resizableRelatedOptions ) {\n\t\t\t\tresizableOptions[ key ] = value;\n\t\t\t}\n\t\t} );\n\n\t\tif ( resize ) {\n\t\t\tthis._size();\n\t\t\tthis._position();\n\t\t}\n\t\tif ( this.uiDialog.is( \":data(ui-resizable)\" ) ) {\n\t\t\tthis.uiDialog.resizable( \"option\", resizableOptions );\n\t\t}\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tvar isDraggable, isResizable,\n\t\t\tuiDialog = this.uiDialog;\n\n\t\tif ( key === \"disabled\" ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._super( key, value );\n\n\t\tif ( key === \"appendTo\" ) {\n\t\t\tthis.uiDialog.appendTo( this._appendTo() );\n\t\t}\n\n\t\tif ( key === \"buttons\" ) {\n\t\t\tthis._createButtons();\n\t\t}\n\n\t\tif ( key === \"closeText\" ) {\n\t\t\tthis.uiDialogTitlebarClose.button( {\n\n\t\t\t\t// Ensure that we always pass a string\n\t\t\t\tlabel: $( \"<a>\" ).text( \"\" + this.options.closeText ).html()\n\t\t\t} );\n\t\t}\n\n\t\tif ( key === \"draggable\" ) {\n\t\t\tisDraggable = uiDialog.is( \":data(ui-draggable)\" );\n\t\t\tif ( isDraggable && !value ) {\n\t\t\t\tuiDialog.draggable( \"destroy\" );\n\t\t\t}\n\n\t\t\tif ( !isDraggable && value ) {\n\t\t\t\tthis._makeDraggable();\n\t\t\t}\n\t\t}\n\n\t\tif ( key === \"position\" ) {\n\t\t\tthis._position();\n\t\t}\n\n\t\tif ( key === \"resizable\" ) {\n\n\t\t\t// currently resizable, becoming non-resizable\n\t\t\tisResizable = uiDialog.is( \":data(ui-resizable)\" );\n\t\t\tif ( isResizable && !value ) {\n\t\t\t\tuiDialog.resizable( \"destroy\" );\n\t\t\t}\n\n\t\t\t// Currently resizable, changing handles\n\t\t\tif ( isResizable && typeof value === \"string\" ) {\n\t\t\t\tuiDialog.resizable( \"option\", \"handles\", value );\n\t\t\t}\n\n\t\t\t// Currently non-resizable, becoming resizable\n\t\t\tif ( !isResizable && value !== false ) {\n\t\t\t\tthis._makeResizable();\n\t\t\t}\n\t\t}\n\n\t\tif ( key === \"title\" ) {\n\t\t\tthis._title( this.uiDialogTitlebar.find( \".ui-dialog-title\" ) );\n\t\t}\n\t},\n\n\t_size: function() {\n\n\t\t// If the user has resized the dialog, the .ui-dialog and .ui-dialog-content\n\t\t// divs will both have width and height set, so we need to reset them\n\t\tvar nonContentHeight, minContentHeight, maxContentHeight,\n\t\t\toptions = this.options;\n\n\t\t// Reset content sizing\n\t\tthis.element.show().css( {\n\t\t\twidth: \"auto\",\n\t\t\tminHeight: 0,\n\t\t\tmaxHeight: \"none\",\n\t\t\theight: 0\n\t\t} );\n\n\t\tif ( options.minWidth > options.width ) {\n\t\t\toptions.width = options.minWidth;\n\t\t}\n\n\t\t// Reset wrapper sizing\n\t\t// determine the height of all the non-content elements\n\t\tnonContentHeight = this.uiDialog.css( {\n\t\t\theight: \"auto\",\n\t\t\twidth: options.width\n\t\t} )\n\t\t\t.outerHeight();\n\t\tminContentHeight = Math.max( 0, options.minHeight - nonContentHeight );\n\t\tmaxContentHeight = typeof options.maxHeight === \"number\" ?\n\t\t\tMath.max( 0, options.maxHeight - nonContentHeight ) :\n\t\t\t\"none\";\n\n\t\tif ( options.height === \"auto\" ) {\n\t\t\tthis.element.css( {\n\t\t\t\tminHeight: minContentHeight,\n\t\t\t\tmaxHeight: maxContentHeight,\n\t\t\t\theight: \"auto\"\n\t\t\t} );\n\t\t} else {\n\t\t\tthis.element.height( Math.max( 0, options.height - nonContentHeight ) );\n\t\t}\n\n\t\tif ( this.uiDialog.is( \":data(ui-resizable)\" ) ) {\n\t\t\tthis.uiDialog.resizable( \"option\", \"minHeight\", this._minHeight() );\n\t\t}\n\t},\n\n\t_blockFrames: function() {\n\t\tthis.iframeBlocks = this.document.find( \"iframe\" ).map( function() {\n\t\t\tvar iframe = $( this );\n\n\t\t\treturn $( \"<div>\" )\n\t\t\t\t.css( {\n\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\twidth: iframe.outerWidth(),\n\t\t\t\t\theight: iframe.outerHeight()\n\t\t\t\t} )\n\t\t\t\t.appendTo( iframe.parent() )\n\t\t\t\t.offset( iframe.offset() )[ 0 ];\n\t\t} );\n\t},\n\n\t_unblockFrames: function() {\n\t\tif ( this.iframeBlocks ) {\n\t\t\tthis.iframeBlocks.remove();\n\t\t\tdelete this.iframeBlocks;\n\t\t}\n\t},\n\n\t_allowInteraction: function( event ) {\n\t\tif ( $( event.target ).closest( \".ui-dialog\" ).length ) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// TODO: Remove hack when datepicker implements\n\t\t// the .ui-front logic (#8989)\n\t\treturn !!$( event.target ).closest( \".ui-datepicker\" ).length;\n\t},\n\n\t_createOverlay: function() {\n\t\tif ( !this.options.modal ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We use a delay in case the overlay is created from an\n\t\t// event that we're going to be cancelling (#2804)\n\t\tvar isOpening = true;\n\t\tthis._delay( function() {\n\t\t\tisOpening = false;\n\t\t} );\n\n\t\tif ( !this.document.data( \"ui-dialog-overlays\" ) ) {\n\n\t\t\t// Prevent use of anchors and inputs\n\t\t\t// Using _on() for an event handler shared across many instances is\n\t\t\t// safe because the dialogs stack and must be closed in reverse order\n\t\t\tthis._on( this.document, {\n\t\t\t\tfocusin: function( event ) {\n\t\t\t\t\tif ( isOpening ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( !this._allowInteraction( event ) ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tthis._trackingInstances()[ 0 ]._focusTabbable();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tthis.overlay = $( \"<div>\" )\n\t\t\t.appendTo( this._appendTo() );\n\n\t\tthis._addClass( this.overlay, null, \"ui-widget-overlay ui-front\" );\n\t\tthis._on( this.overlay, {\n\t\t\tmousedown: \"_keepFocus\"\n\t\t} );\n\t\tthis.document.data( \"ui-dialog-overlays\",\n\t\t\t( this.document.data( \"ui-dialog-overlays\" ) || 0 ) + 1 );\n\t},\n\n\t_destroyOverlay: function() {\n\t\tif ( !this.options.modal ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( this.overlay ) {\n\t\t\tvar overlays = this.document.data( \"ui-dialog-overlays\" ) - 1;\n\n\t\t\tif ( !overlays ) {\n\t\t\t\tthis._off( this.document, \"focusin\" );\n\t\t\t\tthis.document.removeData( \"ui-dialog-overlays\" );\n\t\t\t} else {\n\t\t\t\tthis.document.data( \"ui-dialog-overlays\", overlays );\n\t\t\t}\n\n\t\t\tthis.overlay.remove();\n\t\t\tthis.overlay = null;\n\t\t}\n\t}\n} );\n\n// DEPRECATED\n// TODO: switch return back to widget declaration at top of file when this is removed\nif ( $.uiBackCompat !== false ) {\n\n\t// Backcompat for dialogClass option\n\t$.widget( \"ui.dialog\", $.ui.dialog, {\n\t\toptions: {\n\t\t\tdialogClass: \"\"\n\t\t},\n\t\t_createWrapper: function() {\n\t\t\tthis._super();\n\t\t\tthis.uiDialog.addClass( this.options.dialogClass );\n\t\t},\n\t\t_setOption: function( key, value ) {\n\t\t\tif ( key === \"dialogClass\" ) {\n\t\t\t\tthis.uiDialog\n\t\t\t\t\t.removeClass( this.options.dialogClass )\n\t\t\t\t\t.addClass( value );\n\t\t\t}\n\t\t\tthis._superApply( arguments );\n\t\t}\n\t} );\n}\n\nvar widgetsDialog = $.ui.dialog;\n\n\n/*!\n * jQuery UI Droppable 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Droppable\n//>>group: Interactions\n//>>description: Enables drop targets for draggable elements.\n//>>docs: http://api.jqueryui.com/droppable/\n//>>demos: http://jqueryui.com/droppable/\n\n\n\n$.widget( \"ui.droppable\", {\n\tversion: \"1.12.1\",\n\twidgetEventPrefix: \"drop\",\n\toptions: {\n\t\taccept: \"*\",\n\t\taddClasses: true,\n\t\tgreedy: false,\n\t\tscope: \"default\",\n\t\ttolerance: \"intersect\",\n\n\t\t// Callbacks\n\t\tactivate: null,\n\t\tdeactivate: null,\n\t\tdrop: null,\n\t\tout: null,\n\t\tover: null\n\t},\n\t_create: function() {\n\n\t\tvar proportions,\n\t\t\to = this.options,\n\t\t\taccept = o.accept;\n\n\t\tthis.isover = false;\n\t\tthis.isout = true;\n\n\t\tthis.accept = $.isFunction( accept ) ? accept : function( d ) {\n\t\t\treturn d.is( accept );\n\t\t};\n\n\t\tthis.proportions = function( /* valueToWrite */ ) {\n\t\t\tif ( arguments.length ) {\n\n\t\t\t\t// Store the droppable's proportions\n\t\t\t\tproportions = arguments[ 0 ];\n\t\t\t} else {\n\n\t\t\t\t// Retrieve or derive the droppable's proportions\n\t\t\t\treturn proportions ?\n\t\t\t\t\tproportions :\n\t\t\t\t\tproportions = {\n\t\t\t\t\t\twidth: this.element[ 0 ].offsetWidth,\n\t\t\t\t\t\theight: this.element[ 0 ].offsetHeight\n\t\t\t\t\t};\n\t\t\t}\n\t\t};\n\n\t\tthis._addToManager( o.scope );\n\n\t\to.addClasses && this._addClass( \"ui-droppable\" );\n\n\t},\n\n\t_addToManager: function( scope ) {\n\n\t\t// Add the reference and positions to the manager\n\t\t$.ui.ddmanager.droppables[ scope ] = $.ui.ddmanager.droppables[ scope ] || [];\n\t\t$.ui.ddmanager.droppables[ scope ].push( this );\n\t},\n\n\t_splice: function( drop ) {\n\t\tvar i = 0;\n\t\tfor ( ; i < drop.length; i++ ) {\n\t\t\tif ( drop[ i ] === this ) {\n\t\t\t\tdrop.splice( i, 1 );\n\t\t\t}\n\t\t}\n\t},\n\n\t_destroy: function() {\n\t\tvar drop = $.ui.ddmanager.droppables[ this.options.scope ];\n\n\t\tthis._splice( drop );\n\t},\n\n\t_setOption: function( key, value ) {\n\n\t\tif ( key === \"accept\" ) {\n\t\t\tthis.accept = $.isFunction( value ) ? value : function( d ) {\n\t\t\t\treturn d.is( value );\n\t\t\t};\n\t\t} else if ( key === \"scope\" ) {\n\t\t\tvar drop = $.ui.ddmanager.droppables[ this.options.scope ];\n\n\t\t\tthis._splice( drop );\n\t\t\tthis._addToManager( value );\n\t\t}\n\n\t\tthis._super( key, value );\n\t},\n\n\t_activate: function( event ) {\n\t\tvar draggable = $.ui.ddmanager.current;\n\n\t\tthis._addActiveClass();\n\t\tif ( draggable ) {\n\t\t\tthis._trigger( \"activate\", event, this.ui( draggable ) );\n\t\t}\n\t},\n\n\t_deactivate: function( event ) {\n\t\tvar draggable = $.ui.ddmanager.current;\n\n\t\tthis._removeActiveClass();\n\t\tif ( draggable ) {\n\t\t\tthis._trigger( \"deactivate\", event, this.ui( draggable ) );\n\t\t}\n\t},\n\n\t_over: function( event ) {\n\n\t\tvar draggable = $.ui.ddmanager.current;\n\n\t\t// Bail if draggable and droppable are same element\n\t\tif ( !draggable || ( draggable.currentItem ||\n\t\t\t\tdraggable.element )[ 0 ] === this.element[ 0 ] ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( this.accept.call( this.element[ 0 ], ( draggable.currentItem ||\n\t\t\t\tdraggable.element ) ) ) {\n\t\t\tthis._addHoverClass();\n\t\t\tthis._trigger( \"over\", event, this.ui( draggable ) );\n\t\t}\n\n\t},\n\n\t_out: function( event ) {\n\n\t\tvar draggable = $.ui.ddmanager.current;\n\n\t\t// Bail if draggable and droppable are same element\n\t\tif ( !draggable || ( draggable.currentItem ||\n\t\t\t\tdraggable.element )[ 0 ] === this.element[ 0 ] ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( this.accept.call( this.element[ 0 ], ( draggable.currentItem ||\n\t\t\t\tdraggable.element ) ) ) {\n\t\t\tthis._removeHoverClass();\n\t\t\tthis._trigger( \"out\", event, this.ui( draggable ) );\n\t\t}\n\n\t},\n\n\t_drop: function( event, custom ) {\n\n\t\tvar draggable = custom || $.ui.ddmanager.current,\n\t\t\tchildrenIntersection = false;\n\n\t\t// Bail if draggable and droppable are same element\n\t\tif ( !draggable || ( draggable.currentItem ||\n\t\t\t\tdraggable.element )[ 0 ] === this.element[ 0 ] ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.element\n\t\t\t.find( \":data(ui-droppable)\" )\n\t\t\t.not( \".ui-draggable-dragging\" )\n\t\t\t.each( function() {\n\t\t\t\tvar inst = $( this ).droppable( \"instance\" );\n\t\t\t\tif (\n\t\t\t\t\tinst.options.greedy &&\n\t\t\t\t\t!inst.options.disabled &&\n\t\t\t\t\tinst.options.scope === draggable.options.scope &&\n\t\t\t\t\tinst.accept.call(\n\t\t\t\t\t\tinst.element[ 0 ], ( draggable.currentItem || draggable.element )\n\t\t\t\t\t) &&\n\t\t\t\t\tintersect(\n\t\t\t\t\t\tdraggable,\n\t\t\t\t\t\t$.extend( inst, { offset: inst.element.offset() } ),\n\t\t\t\t\t\tinst.options.tolerance, event\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tchildrenIntersection = true;\n\t\t\t\t\treturn false; }\n\t\t\t} );\n\t\tif ( childrenIntersection ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( this.accept.call( this.element[ 0 ],\n\t\t\t\t( draggable.currentItem || draggable.element ) ) ) {\n\t\t\tthis._removeActiveClass();\n\t\t\tthis._removeHoverClass();\n\n\t\t\tthis._trigger( \"drop\", event, this.ui( draggable ) );\n\t\t\treturn this.element;\n\t\t}\n\n\t\treturn false;\n\n\t},\n\n\tui: function( c ) {\n\t\treturn {\n\t\t\tdraggable: ( c.currentItem || c.element ),\n\t\t\thelper: c.helper,\n\t\t\tposition: c.position,\n\t\t\toffset: c.positionAbs\n\t\t};\n\t},\n\n\t// Extension points just to make backcompat sane and avoid duplicating logic\n\t// TODO: Remove in 1.13 along with call to it below\n\t_addHoverClass: function() {\n\t\tthis._addClass( \"ui-droppable-hover\" );\n\t},\n\n\t_removeHoverClass: function() {\n\t\tthis._removeClass( \"ui-droppable-hover\" );\n\t},\n\n\t_addActiveClass: function() {\n\t\tthis._addClass( \"ui-droppable-active\" );\n\t},\n\n\t_removeActiveClass: function() {\n\t\tthis._removeClass( \"ui-droppable-active\" );\n\t}\n} );\n\nvar intersect = $.ui.intersect = ( function() {\n\tfunction isOverAxis( x, reference, size ) {\n\t\treturn ( x >= reference ) && ( x < ( reference + size ) );\n\t}\n\n\treturn function( draggable, droppable, toleranceMode, event ) {\n\n\t\tif ( !droppable.offset ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tvar x1 = ( draggable.positionAbs ||\n\t\t\t\tdraggable.position.absolute ).left + draggable.margins.left,\n\t\t\ty1 = ( draggable.positionAbs ||\n\t\t\t\tdraggable.position.absolute ).top + draggable.margins.top,\n\t\t\tx2 = x1 + draggable.helperProportions.width,\n\t\t\ty2 = y1 + draggable.helperProportions.height,\n\t\t\tl = droppable.offset.left,\n\t\t\tt = droppable.offset.top,\n\t\t\tr = l + droppable.proportions().width,\n\t\t\tb = t + droppable.proportions().height;\n\n\t\tswitch ( toleranceMode ) {\n\t\tcase \"fit\":\n\t\t\treturn ( l <= x1 && x2 <= r && t <= y1 && y2 <= b );\n\t\tcase \"intersect\":\n\t\t\treturn ( l < x1 + ( draggable.helperProportions.width / 2 ) && // Right Half\n\t\t\t\tx2 - ( draggable.helperProportions.width / 2 ) < r && // Left Half\n\t\t\t\tt < y1 + ( draggable.helperProportions.height / 2 ) && // Bottom Half\n\t\t\t\ty2 - ( draggable.helperProportions.height / 2 ) < b ); // Top Half\n\t\tcase \"pointer\":\n\t\t\treturn isOverAxis( event.pageY, t, droppable.proportions().height ) &&\n\t\t\t\tisOverAxis( event.pageX, l, droppable.proportions().width );\n\t\tcase \"touch\":\n\t\t\treturn (\n\t\t\t\t( y1 >= t && y1 <= b ) || // Top edge touching\n\t\t\t\t( y2 >= t && y2 <= b ) || // Bottom edge touching\n\t\t\t\t( y1 < t && y2 > b ) // Surrounded vertically\n\t\t\t) && (\n\t\t\t\t( x1 >= l && x1 <= r ) || // Left edge touching\n\t\t\t\t( x2 >= l && x2 <= r ) || // Right edge touching\n\t\t\t\t( x1 < l && x2 > r ) // Surrounded horizontally\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t\t}\n\t};\n} )();\n\n/*\n\tThis manager tracks offsets of draggables and droppables\n*/\n$.ui.ddmanager = {\n\tcurrent: null,\n\tdroppables: { \"default\": [] },\n\tprepareOffsets: function( t, event ) {\n\n\t\tvar i, j,\n\t\t\tm = $.ui.ddmanager.droppables[ t.options.scope ] || [],\n\t\t\ttype = event ? event.type : null, // workaround for #2317\n\t\t\tlist = ( t.currentItem || t.element ).find( \":data(ui-droppable)\" ).addBack();\n\n\t\tdroppablesLoop: for ( i = 0; i < m.length; i++ ) {\n\n\t\t\t// No disabled and non-accepted\n\t\t\tif ( m[ i ].options.disabled || ( t && !m[ i ].accept.call( m[ i ].element[ 0 ],\n\t\t\t\t\t( t.currentItem || t.element ) ) ) ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Filter out elements in the current dragged item\n\t\t\tfor ( j = 0; j < list.length; j++ ) {\n\t\t\t\tif ( list[ j ] === m[ i ].element[ 0 ] ) {\n\t\t\t\t\tm[ i ].proportions().height = 0;\n\t\t\t\t\tcontinue droppablesLoop;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tm[ i ].visible = m[ i ].element.css( \"display\" ) !== \"none\";\n\t\t\tif ( !m[ i ].visible ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Activate the droppable if used directly from draggables\n\t\t\tif ( type === \"mousedown\" ) {\n\t\t\t\tm[ i ]._activate.call( m[ i ], event );\n\t\t\t}\n\n\t\t\tm[ i ].offset = m[ i ].element.offset();\n\t\t\tm[ i ].proportions( {\n\t\t\t\twidth: m[ i ].element[ 0 ].offsetWidth,\n\t\t\t\theight: m[ i ].element[ 0 ].offsetHeight\n\t\t\t} );\n\n\t\t}\n\n\t},\n\tdrop: function( draggable, event ) {\n\n\t\tvar dropped = false;\n\n\t\t// Create a copy of the droppables in case the list changes during the drop (#9116)\n\t\t$.each( ( $.ui.ddmanager.droppables[ draggable.options.scope ] || [] ).slice(), function() {\n\n\t\t\tif ( !this.options ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( !this.options.disabled && this.visible &&\n\t\t\t\t\tintersect( draggable, this, this.options.tolerance, event ) ) {\n\t\t\t\tdropped = this._drop.call( this, event ) || dropped;\n\t\t\t}\n\n\t\t\tif ( !this.options.disabled && this.visible && this.accept.call( this.element[ 0 ],\n\t\t\t\t\t( draggable.currentItem || draggable.element ) ) ) {\n\t\t\t\tthis.isout = true;\n\t\t\t\tthis.isover = false;\n\t\t\t\tthis._deactivate.call( this, event );\n\t\t\t}\n\n\t\t} );\n\t\treturn dropped;\n\n\t},\n\tdragStart: function( draggable, event ) {\n\n\t\t// Listen for scrolling so that if the dragging causes scrolling the position of the\n\t\t// droppables can be recalculated (see #5003)\n\t\tdraggable.element.parentsUntil( \"body\" ).on( \"scroll.droppable\", function() {\n\t\t\tif ( !draggable.options.refreshPositions ) {\n\t\t\t\t$.ui.ddmanager.prepareOffsets( draggable, event );\n\t\t\t}\n\t\t} );\n\t},\n\tdrag: function( draggable, event ) {\n\n\t\t// If you have a highly dynamic page, you might try this option. It renders positions\n\t\t// every time you move the mouse.\n\t\tif ( draggable.options.refreshPositions ) {\n\t\t\t$.ui.ddmanager.prepareOffsets( draggable, event );\n\t\t}\n\n\t\t// Run through all droppables and check their positions based on specific tolerance options\n\t\t$.each( $.ui.ddmanager.droppables[ draggable.options.scope ] || [], function() {\n\n\t\t\tif ( this.options.disabled || this.greedyChild || !this.visible ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvar parentInstance, scope, parent,\n\t\t\t\tintersects = intersect( draggable, this, this.options.tolerance, event ),\n\t\t\t\tc = !intersects && this.isover ?\n\t\t\t\t\t\"isout\" :\n\t\t\t\t\t( intersects && !this.isover ? \"isover\" : null );\n\t\t\tif ( !c ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( this.options.greedy ) {\n\n\t\t\t\t// find droppable parents with same scope\n\t\t\t\tscope = this.options.scope;\n\t\t\t\tparent = this.element.parents( \":data(ui-droppable)\" ).filter( function() {\n\t\t\t\t\treturn $( this ).droppable( \"instance\" ).options.scope === scope;\n\t\t\t\t} );\n\n\t\t\t\tif ( parent.length ) {\n\t\t\t\t\tparentInstance = $( parent[ 0 ] ).droppable( \"instance\" );\n\t\t\t\t\tparentInstance.greedyChild = ( c === \"isover\" );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// We just moved into a greedy child\n\t\t\tif ( parentInstance && c === \"isover\" ) {\n\t\t\t\tparentInstance.isover = false;\n\t\t\t\tparentInstance.isout = true;\n\t\t\t\tparentInstance._out.call( parentInstance, event );\n\t\t\t}\n\n\t\t\tthis[ c ] = true;\n\t\t\tthis[ c === \"isout\" ? \"isover\" : \"isout\" ] = false;\n\t\t\tthis[ c === \"isover\" ? \"_over\" : \"_out\" ].call( this, event );\n\n\t\t\t// We just moved out of a greedy child\n\t\t\tif ( parentInstance && c === \"isout\" ) {\n\t\t\t\tparentInstance.isout = false;\n\t\t\t\tparentInstance.isover = true;\n\t\t\t\tparentInstance._over.call( parentInstance, event );\n\t\t\t}\n\t\t} );\n\n\t},\n\tdragStop: function( draggable, event ) {\n\t\tdraggable.element.parentsUntil( \"body\" ).off( \"scroll.droppable\" );\n\n\t\t// Call prepareOffsets one final time since IE does not fire return scroll events when\n\t\t// overflow was caused by drag (see #5003)\n\t\tif ( !draggable.options.refreshPositions ) {\n\t\t\t$.ui.ddmanager.prepareOffsets( draggable, event );\n\t\t}\n\t}\n};\n\n// DEPRECATED\n// TODO: switch return back to widget declaration at top of file when this is removed\nif ( $.uiBackCompat !== false ) {\n\n\t// Backcompat for activeClass and hoverClass options\n\t$.widget( \"ui.droppable\", $.ui.droppable, {\n\t\toptions: {\n\t\t\thoverClass: false,\n\t\t\tactiveClass: false\n\t\t},\n\t\t_addActiveClass: function() {\n\t\t\tthis._super();\n\t\t\tif ( this.options.activeClass ) {\n\t\t\t\tthis.element.addClass( this.options.activeClass );\n\t\t\t}\n\t\t},\n\t\t_removeActiveClass: function() {\n\t\t\tthis._super();\n\t\t\tif ( this.options.activeClass ) {\n\t\t\t\tthis.element.removeClass( this.options.activeClass );\n\t\t\t}\n\t\t},\n\t\t_addHoverClass: function() {\n\t\t\tthis._super();\n\t\t\tif ( this.options.hoverClass ) {\n\t\t\t\tthis.element.addClass( this.options.hoverClass );\n\t\t\t}\n\t\t},\n\t\t_removeHoverClass: function() {\n\t\t\tthis._super();\n\t\t\tif ( this.options.hoverClass ) {\n\t\t\t\tthis.element.removeClass( this.options.hoverClass );\n\t\t\t}\n\t\t}\n\t} );\n}\n\nvar widgetsDroppable = $.ui.droppable;\n\n\n/*!\n * jQuery UI Progressbar 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Progressbar\n//>>group: Widgets\n// jscs:disable maximumLineLength\n//>>description: Displays a status indicator for loading state, standard percentage, and other progress indicators.\n// jscs:enable maximumLineLength\n//>>docs: http://api.jqueryui.com/progressbar/\n//>>demos: http://jqueryui.com/progressbar/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/progressbar.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\nvar widgetsProgressbar = $.widget( \"ui.progressbar\", {\n\tversion: \"1.12.1\",\n\toptions: {\n\t\tclasses: {\n\t\t\t\"ui-progressbar\": \"ui-corner-all\",\n\t\t\t\"ui-progressbar-value\": \"ui-corner-left\",\n\t\t\t\"ui-progressbar-complete\": \"ui-corner-right\"\n\t\t},\n\t\tmax: 100,\n\t\tvalue: 0,\n\n\t\tchange: null,\n\t\tcomplete: null\n\t},\n\n\tmin: 0,\n\n\t_create: function() {\n\n\t\t// Constrain initial value\n\t\tthis.oldValue = this.options.value = this._constrainedValue();\n\n\t\tthis.element.attr( {\n\n\t\t\t// Only set static values; aria-valuenow and aria-valuemax are\n\t\t\t// set inside _refreshValue()\n\t\t\trole: \"progressbar\",\n\t\t\t\"aria-valuemin\": this.min\n\t\t} );\n\t\tthis._addClass( \"ui-progressbar\", \"ui-widget ui-widget-content\" );\n\n\t\tthis.valueDiv = $( \"<div>\" ).appendTo( this.element );\n\t\tthis._addClass( this.valueDiv, \"ui-progressbar-value\", \"ui-widget-header\" );\n\t\tthis._refreshValue();\n\t},\n\n\t_destroy: function() {\n\t\tthis.element.removeAttr( \"role aria-valuemin aria-valuemax aria-valuenow\" );\n\n\t\tthis.valueDiv.remove();\n\t},\n\n\tvalue: function( newValue ) {\n\t\tif ( newValue === undefined ) {\n\t\t\treturn this.options.value;\n\t\t}\n\n\t\tthis.options.value = this._constrainedValue( newValue );\n\t\tthis._refreshValue();\n\t},\n\n\t_constrainedValue: function( newValue ) {\n\t\tif ( newValue === undefined ) {\n\t\t\tnewValue = this.options.value;\n\t\t}\n\n\t\tthis.indeterminate = newValue === false;\n\n\t\t// Sanitize value\n\t\tif ( typeof newValue !== \"number\" ) {\n\t\t\tnewValue = 0;\n\t\t}\n\n\t\treturn this.indeterminate ? false :\n\t\t\tMath.min( this.options.max, Math.max( this.min, newValue ) );\n\t},\n\n\t_setOptions: function( options ) {\n\n\t\t// Ensure \"value\" option is set after other values (like max)\n\t\tvar value = options.value;\n\t\tdelete options.value;\n\n\t\tthis._super( options );\n\n\t\tthis.options.value = this._constrainedValue( value );\n\t\tthis._refreshValue();\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tif ( key === \"max\" ) {\n\n\t\t\t// Don't allow a max less than min\n\t\t\tvalue = Math.max( this.min, value );\n\t\t}\n\t\tthis._super( key, value );\n\t},\n\n\t_setOptionDisabled: function( value ) {\n\t\tthis._super( value );\n\n\t\tthis.element.attr( \"aria-disabled\", value );\n\t\tthis._toggleClass( null, \"ui-state-disabled\", !!value );\n\t},\n\n\t_percentage: function() {\n\t\treturn this.indeterminate ?\n\t\t\t100 :\n\t\t\t100 * ( this.options.value - this.min ) / ( this.options.max - this.min );\n\t},\n\n\t_refreshValue: function() {\n\t\tvar value = this.options.value,\n\t\t\tpercentage = this._percentage();\n\n\t\tthis.valueDiv\n\t\t\t.toggle( this.indeterminate || value > this.min )\n\t\t\t.width( percentage.toFixed( 0 ) + \"%\" );\n\n\t\tthis\n\t\t\t._toggleClass( this.valueDiv, \"ui-progressbar-complete\", null,\n\t\t\t\tvalue === this.options.max )\n\t\t\t._toggleClass( \"ui-progressbar-indeterminate\", null, this.indeterminate );\n\n\t\tif ( this.indeterminate ) {\n\t\t\tthis.element.removeAttr( \"aria-valuenow\" );\n\t\t\tif ( !this.overlayDiv ) {\n\t\t\t\tthis.overlayDiv = $( \"<div>\" ).appendTo( this.valueDiv );\n\t\t\t\tthis._addClass( this.overlayDiv, \"ui-progressbar-overlay\" );\n\t\t\t}\n\t\t} else {\n\t\t\tthis.element.attr( {\n\t\t\t\t\"aria-valuemax\": this.options.max,\n\t\t\t\t\"aria-valuenow\": value\n\t\t\t} );\n\t\t\tif ( this.overlayDiv ) {\n\t\t\t\tthis.overlayDiv.remove();\n\t\t\t\tthis.overlayDiv = null;\n\t\t\t}\n\t\t}\n\n\t\tif ( this.oldValue !== value ) {\n\t\t\tthis.oldValue = value;\n\t\t\tthis._trigger( \"change\" );\n\t\t}\n\t\tif ( value === this.options.max ) {\n\t\t\tthis._trigger( \"complete\" );\n\t\t}\n\t}\n} );\n\n\n/*!\n * jQuery UI Selectable 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Selectable\n//>>group: Interactions\n//>>description: Allows groups of elements to be selected with the mouse.\n//>>docs: http://api.jqueryui.com/selectable/\n//>>demos: http://jqueryui.com/selectable/\n//>>css.structure: ../../themes/base/selectable.css\n\n\n\nvar widgetsSelectable = $.widget( \"ui.selectable\", $.ui.mouse, {\n\tversion: \"1.12.1\",\n\toptions: {\n\t\tappendTo: \"body\",\n\t\tautoRefresh: true,\n\t\tdistance: 0,\n\t\tfilter: \"*\",\n\t\ttolerance: \"touch\",\n\n\t\t// Callbacks\n\t\tselected: null,\n\t\tselecting: null,\n\t\tstart: null,\n\t\tstop: null,\n\t\tunselected: null,\n\t\tunselecting: null\n\t},\n\t_create: function() {\n\t\tvar that = this;\n\n\t\tthis._addClass( \"ui-selectable\" );\n\n\t\tthis.dragged = false;\n\n\t\t// Cache selectee children based on filter\n\t\tthis.refresh = function() {\n\t\t\tthat.elementPos = $( that.element[ 0 ] ).offset();\n\t\t\tthat.selectees = $( that.options.filter, that.element[ 0 ] );\n\t\t\tthat._addClass( that.selectees, \"ui-selectee\" );\n\t\t\tthat.selectees.each( function() {\n\t\t\t\tvar $this = $( this ),\n\t\t\t\t\tselecteeOffset = $this.offset(),\n\t\t\t\t\tpos = {\n\t\t\t\t\t\tleft: selecteeOffset.left - that.elementPos.left,\n\t\t\t\t\t\ttop: selecteeOffset.top - that.elementPos.top\n\t\t\t\t\t};\n\t\t\t\t$.data( this, \"selectable-item\", {\n\t\t\t\t\telement: this,\n\t\t\t\t\t$element: $this,\n\t\t\t\t\tleft: pos.left,\n\t\t\t\t\ttop: pos.top,\n\t\t\t\t\tright: pos.left + $this.outerWidth(),\n\t\t\t\t\tbottom: pos.top + $this.outerHeight(),\n\t\t\t\t\tstartselected: false,\n\t\t\t\t\tselected: $this.hasClass( \"ui-selected\" ),\n\t\t\t\t\tselecting: $this.hasClass( \"ui-selecting\" ),\n\t\t\t\t\tunselecting: $this.hasClass( \"ui-unselecting\" )\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t\tthis.refresh();\n\n\t\tthis._mouseInit();\n\n\t\tthis.helper = $( \"<div>\" );\n\t\tthis._addClass( this.helper, \"ui-selectable-helper\" );\n\t},\n\n\t_destroy: function() {\n\t\tthis.selectees.removeData( \"selectable-item\" );\n\t\tthis._mouseDestroy();\n\t},\n\n\t_mouseStart: function( event ) {\n\t\tvar that = this,\n\t\t\toptions = this.options;\n\n\t\tthis.opos = [ event.pageX, event.pageY ];\n\t\tthis.elementPos = $( this.element[ 0 ] ).offset();\n\n\t\tif ( this.options.disabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.selectees = $( options.filter, this.element[ 0 ] );\n\n\t\tthis._trigger( \"start\", event );\n\n\t\t$( options.appendTo ).append( this.helper );\n\n\t\t// position helper (lasso)\n\t\tthis.helper.css( {\n\t\t\t\"left\": event.pageX,\n\t\t\t\"top\": event.pageY,\n\t\t\t\"width\": 0,\n\t\t\t\"height\": 0\n\t\t} );\n\n\t\tif ( options.autoRefresh ) {\n\t\t\tthis.refresh();\n\t\t}\n\n\t\tthis.selectees.filter( \".ui-selected\" ).each( function() {\n\t\t\tvar selectee = $.data( this, \"selectable-item\" );\n\t\t\tselectee.startselected = true;\n\t\t\tif ( !event.metaKey && !event.ctrlKey ) {\n\t\t\t\tthat._removeClass( selectee.$element, \"ui-selected\" );\n\t\t\t\tselectee.selected = false;\n\t\t\t\tthat._addClass( selectee.$element, \"ui-unselecting\" );\n\t\t\t\tselectee.unselecting = true;\n\n\t\t\t\t// selectable UNSELECTING callback\n\t\t\t\tthat._trigger( \"unselecting\", event, {\n\t\t\t\t\tunselecting: selectee.element\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\n\t\t$( event.target ).parents().addBack().each( function() {\n\t\t\tvar doSelect,\n\t\t\t\tselectee = $.data( this, \"selectable-item\" );\n\t\t\tif ( selectee ) {\n\t\t\t\tdoSelect = ( !event.metaKey && !event.ctrlKey ) ||\n\t\t\t\t\t!selectee.$element.hasClass( \"ui-selected\" );\n\t\t\t\tthat._removeClass( selectee.$element, doSelect ? \"ui-unselecting\" : \"ui-selected\" )\n\t\t\t\t\t._addClass( selectee.$element, doSelect ? \"ui-selecting\" : \"ui-unselecting\" );\n\t\t\t\tselectee.unselecting = !doSelect;\n\t\t\t\tselectee.selecting = doSelect;\n\t\t\t\tselectee.selected = doSelect;\n\n\t\t\t\t// selectable (UN)SELECTING callback\n\t\t\t\tif ( doSelect ) {\n\t\t\t\t\tthat._trigger( \"selecting\", event, {\n\t\t\t\t\t\tselecting: selectee.element\n\t\t\t\t\t} );\n\t\t\t\t} else {\n\t\t\t\t\tthat._trigger( \"unselecting\", event, {\n\t\t\t\t\t\tunselecting: selectee.element\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t} );\n\n\t},\n\n\t_mouseDrag: function( event ) {\n\n\t\tthis.dragged = true;\n\n\t\tif ( this.options.disabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar tmp,\n\t\t\tthat = this,\n\t\t\toptions = this.options,\n\t\t\tx1 = this.opos[ 0 ],\n\t\t\ty1 = this.opos[ 1 ],\n\t\t\tx2 = event.pageX,\n\t\t\ty2 = event.pageY;\n\n\t\tif ( x1 > x2 ) { tmp = x2; x2 = x1; x1 = tmp; }\n\t\tif ( y1 > y2 ) { tmp = y2; y2 = y1; y1 = tmp; }\n\t\tthis.helper.css( { left: x1, top: y1, width: x2 - x1, height: y2 - y1 } );\n\n\t\tthis.selectees.each( function() {\n\t\t\tvar selectee = $.data( this, \"selectable-item\" ),\n\t\t\t\thit = false,\n\t\t\t\toffset = {};\n\n\t\t\t//prevent helper from being selected if appendTo: selectable\n\t\t\tif ( !selectee || selectee.element === that.element[ 0 ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\toffset.left   = selectee.left   + that.elementPos.left;\n\t\t\toffset.right  = selectee.right  + that.elementPos.left;\n\t\t\toffset.top    = selectee.top    + that.elementPos.top;\n\t\t\toffset.bottom = selectee.bottom + that.elementPos.top;\n\n\t\t\tif ( options.tolerance === \"touch\" ) {\n\t\t\t\thit = ( !( offset.left > x2 || offset.right < x1 || offset.top > y2 ||\n                    offset.bottom < y1 ) );\n\t\t\t} else if ( options.tolerance === \"fit\" ) {\n\t\t\t\thit = ( offset.left > x1 && offset.right < x2 && offset.top > y1 &&\n                    offset.bottom < y2 );\n\t\t\t}\n\n\t\t\tif ( hit ) {\n\n\t\t\t\t// SELECT\n\t\t\t\tif ( selectee.selected ) {\n\t\t\t\t\tthat._removeClass( selectee.$element, \"ui-selected\" );\n\t\t\t\t\tselectee.selected = false;\n\t\t\t\t}\n\t\t\t\tif ( selectee.unselecting ) {\n\t\t\t\t\tthat._removeClass( selectee.$element, \"ui-unselecting\" );\n\t\t\t\t\tselectee.unselecting = false;\n\t\t\t\t}\n\t\t\t\tif ( !selectee.selecting ) {\n\t\t\t\t\tthat._addClass( selectee.$element, \"ui-selecting\" );\n\t\t\t\t\tselectee.selecting = true;\n\n\t\t\t\t\t// selectable SELECTING callback\n\t\t\t\t\tthat._trigger( \"selecting\", event, {\n\t\t\t\t\t\tselecting: selectee.element\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} else {\n\n\t\t\t\t// UNSELECT\n\t\t\t\tif ( selectee.selecting ) {\n\t\t\t\t\tif ( ( event.metaKey || event.ctrlKey ) && selectee.startselected ) {\n\t\t\t\t\t\tthat._removeClass( selectee.$element, \"ui-selecting\" );\n\t\t\t\t\t\tselectee.selecting = false;\n\t\t\t\t\t\tthat._addClass( selectee.$element, \"ui-selected\" );\n\t\t\t\t\t\tselectee.selected = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthat._removeClass( selectee.$element, \"ui-selecting\" );\n\t\t\t\t\t\tselectee.selecting = false;\n\t\t\t\t\t\tif ( selectee.startselected ) {\n\t\t\t\t\t\t\tthat._addClass( selectee.$element, \"ui-unselecting\" );\n\t\t\t\t\t\t\tselectee.unselecting = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// selectable UNSELECTING callback\n\t\t\t\t\t\tthat._trigger( \"unselecting\", event, {\n\t\t\t\t\t\t\tunselecting: selectee.element\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( selectee.selected ) {\n\t\t\t\t\tif ( !event.metaKey && !event.ctrlKey && !selectee.startselected ) {\n\t\t\t\t\t\tthat._removeClass( selectee.$element, \"ui-selected\" );\n\t\t\t\t\t\tselectee.selected = false;\n\n\t\t\t\t\t\tthat._addClass( selectee.$element, \"ui-unselecting\" );\n\t\t\t\t\t\tselectee.unselecting = true;\n\n\t\t\t\t\t\t// selectable UNSELECTING callback\n\t\t\t\t\t\tthat._trigger( \"unselecting\", event, {\n\t\t\t\t\t\t\tunselecting: selectee.element\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\n\t\treturn false;\n\t},\n\n\t_mouseStop: function( event ) {\n\t\tvar that = this;\n\n\t\tthis.dragged = false;\n\n\t\t$( \".ui-unselecting\", this.element[ 0 ] ).each( function() {\n\t\t\tvar selectee = $.data( this, \"selectable-item\" );\n\t\t\tthat._removeClass( selectee.$element, \"ui-unselecting\" );\n\t\t\tselectee.unselecting = false;\n\t\t\tselectee.startselected = false;\n\t\t\tthat._trigger( \"unselected\", event, {\n\t\t\t\tunselected: selectee.element\n\t\t\t} );\n\t\t} );\n\t\t$( \".ui-selecting\", this.element[ 0 ] ).each( function() {\n\t\t\tvar selectee = $.data( this, \"selectable-item\" );\n\t\t\tthat._removeClass( selectee.$element, \"ui-selecting\" )\n\t\t\t\t._addClass( selectee.$element, \"ui-selected\" );\n\t\t\tselectee.selecting = false;\n\t\t\tselectee.selected = true;\n\t\t\tselectee.startselected = true;\n\t\t\tthat._trigger( \"selected\", event, {\n\t\t\t\tselected: selectee.element\n\t\t\t} );\n\t\t} );\n\t\tthis._trigger( \"stop\", event );\n\n\t\tthis.helper.remove();\n\n\t\treturn false;\n\t}\n\n} );\n\n\n/*!\n * jQuery UI Selectmenu 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Selectmenu\n//>>group: Widgets\n// jscs:disable maximumLineLength\n//>>description: Duplicates and extends the functionality of a native HTML select element, allowing it to be customizable in behavior and appearance far beyond the limitations of a native select.\n// jscs:enable maximumLineLength\n//>>docs: http://api.jqueryui.com/selectmenu/\n//>>demos: http://jqueryui.com/selectmenu/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/selectmenu.css, ../../themes/base/button.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\nvar widgetsSelectmenu = $.widget( \"ui.selectmenu\", [ $.ui.formResetMixin, {\n\tversion: \"1.12.1\",\n\tdefaultElement: \"<select>\",\n\toptions: {\n\t\tappendTo: null,\n\t\tclasses: {\n\t\t\t\"ui-selectmenu-button-open\": \"ui-corner-top\",\n\t\t\t\"ui-selectmenu-button-closed\": \"ui-corner-all\"\n\t\t},\n\t\tdisabled: null,\n\t\ticons: {\n\t\t\tbutton: \"ui-icon-triangle-1-s\"\n\t\t},\n\t\tposition: {\n\t\t\tmy: \"left top\",\n\t\t\tat: \"left bottom\",\n\t\t\tcollision: \"none\"\n\t\t},\n\t\twidth: false,\n\n\t\t// Callbacks\n\t\tchange: null,\n\t\tclose: null,\n\t\tfocus: null,\n\t\topen: null,\n\t\tselect: null\n\t},\n\n\t_create: function() {\n\t\tvar selectmenuId = this.element.uniqueId().attr( \"id\" );\n\t\tthis.ids = {\n\t\t\telement: selectmenuId,\n\t\t\tbutton: selectmenuId + \"-button\",\n\t\t\tmenu: selectmenuId + \"-menu\"\n\t\t};\n\n\t\tthis._drawButton();\n\t\tthis._drawMenu();\n\t\tthis._bindFormResetHandler();\n\n\t\tthis._rendered = false;\n\t\tthis.menuItems = $();\n\t},\n\n\t_drawButton: function() {\n\t\tvar icon,\n\t\t\tthat = this,\n\t\t\titem = this._parseOption(\n\t\t\t\tthis.element.find( \"option:selected\" ),\n\t\t\t\tthis.element[ 0 ].selectedIndex\n\t\t\t);\n\n\t\t// Associate existing label with the new button\n\t\tthis.labels = this.element.labels().attr( \"for\", this.ids.button );\n\t\tthis._on( this.labels, {\n\t\t\tclick: function( event ) {\n\t\t\t\tthis.button.focus();\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t} );\n\n\t\t// Hide original select element\n\t\tthis.element.hide();\n\n\t\t// Create button\n\t\tthis.button = $( \"<span>\", {\n\t\t\ttabindex: this.options.disabled ? -1 : 0,\n\t\t\tid: this.ids.button,\n\t\t\trole: \"combobox\",\n\t\t\t\"aria-expanded\": \"false\",\n\t\t\t\"aria-autocomplete\": \"list\",\n\t\t\t\"aria-owns\": this.ids.menu,\n\t\t\t\"aria-haspopup\": \"true\",\n\t\t\ttitle: this.element.attr( \"title\" )\n\t\t} )\n\t\t\t.insertAfter( this.element );\n\n\t\tthis._addClass( this.button, \"ui-selectmenu-button ui-selectmenu-button-closed\",\n\t\t\t\"ui-button ui-widget\" );\n\n\t\ticon = $( \"<span>\" ).appendTo( this.button );\n\t\tthis._addClass( icon, \"ui-selectmenu-icon\", \"ui-icon \" + this.options.icons.button );\n\t\tthis.buttonItem = this._renderButtonItem( item )\n\t\t\t.appendTo( this.button );\n\n\t\tif ( this.options.width !== false ) {\n\t\t\tthis._resizeButton();\n\t\t}\n\n\t\tthis._on( this.button, this._buttonEvents );\n\t\tthis.button.one( \"focusin\", function() {\n\n\t\t\t// Delay rendering the menu items until the button receives focus.\n\t\t\t// The menu may have already been rendered via a programmatic open.\n\t\t\tif ( !that._rendered ) {\n\t\t\t\tthat._refreshMenu();\n\t\t\t}\n\t\t} );\n\t},\n\n\t_drawMenu: function() {\n\t\tvar that = this;\n\n\t\t// Create menu\n\t\tthis.menu = $( \"<ul>\", {\n\t\t\t\"aria-hidden\": \"true\",\n\t\t\t\"aria-labelledby\": this.ids.button,\n\t\t\tid: this.ids.menu\n\t\t} );\n\n\t\t// Wrap menu\n\t\tthis.menuWrap = $( \"<div>\" ).append( this.menu );\n\t\tthis._addClass( this.menuWrap, \"ui-selectmenu-menu\", \"ui-front\" );\n\t\tthis.menuWrap.appendTo( this._appendTo() );\n\n\t\t// Initialize menu widget\n\t\tthis.menuInstance = this.menu\n\t\t\t.menu( {\n\t\t\t\tclasses: {\n\t\t\t\t\t\"ui-menu\": \"ui-corner-bottom\"\n\t\t\t\t},\n\t\t\t\trole: \"listbox\",\n\t\t\t\tselect: function( event, ui ) {\n\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t// Support: IE8\n\t\t\t\t\t// If the item was selected via a click, the text selection\n\t\t\t\t\t// will be destroyed in IE\n\t\t\t\t\tthat._setSelection();\n\n\t\t\t\t\tthat._select( ui.item.data( \"ui-selectmenu-item\" ), event );\n\t\t\t\t},\n\t\t\t\tfocus: function( event, ui ) {\n\t\t\t\t\tvar item = ui.item.data( \"ui-selectmenu-item\" );\n\n\t\t\t\t\t// Prevent inital focus from firing and check if its a newly focused item\n\t\t\t\t\tif ( that.focusIndex != null && item.index !== that.focusIndex ) {\n\t\t\t\t\t\tthat._trigger( \"focus\", event, { item: item } );\n\t\t\t\t\t\tif ( !that.isOpen ) {\n\t\t\t\t\t\t\tthat._select( item, event );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthat.focusIndex = item.index;\n\n\t\t\t\t\tthat.button.attr( \"aria-activedescendant\",\n\t\t\t\t\t\tthat.menuItems.eq( item.index ).attr( \"id\" ) );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.menu( \"instance\" );\n\n\t\t// Don't close the menu on mouseleave\n\t\tthis.menuInstance._off( this.menu, \"mouseleave\" );\n\n\t\t// Cancel the menu's collapseAll on document click\n\t\tthis.menuInstance._closeOnDocumentClick = function() {\n\t\t\treturn false;\n\t\t};\n\n\t\t// Selects often contain empty items, but never contain dividers\n\t\tthis.menuInstance._isDivider = function() {\n\t\t\treturn false;\n\t\t};\n\t},\n\n\trefresh: function() {\n\t\tthis._refreshMenu();\n\t\tthis.buttonItem.replaceWith(\n\t\t\tthis.buttonItem = this._renderButtonItem(\n\n\t\t\t\t// Fall back to an empty object in case there are no options\n\t\t\t\tthis._getSelectedItem().data( \"ui-selectmenu-item\" ) || {}\n\t\t\t)\n\t\t);\n\t\tif ( this.options.width === null ) {\n\t\t\tthis._resizeButton();\n\t\t}\n\t},\n\n\t_refreshMenu: function() {\n\t\tvar item,\n\t\t\toptions = this.element.find( \"option\" );\n\n\t\tthis.menu.empty();\n\n\t\tthis._parseOptions( options );\n\t\tthis._renderMenu( this.menu, this.items );\n\n\t\tthis.menuInstance.refresh();\n\t\tthis.menuItems = this.menu.find( \"li\" )\n\t\t\t.not( \".ui-selectmenu-optgroup\" )\n\t\t\t\t.find( \".ui-menu-item-wrapper\" );\n\n\t\tthis._rendered = true;\n\n\t\tif ( !options.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\titem = this._getSelectedItem();\n\n\t\t// Update the menu to have the correct item focused\n\t\tthis.menuInstance.focus( null, item );\n\t\tthis._setAria( item.data( \"ui-selectmenu-item\" ) );\n\n\t\t// Set disabled state\n\t\tthis._setOption( \"disabled\", this.element.prop( \"disabled\" ) );\n\t},\n\n\topen: function( event ) {\n\t\tif ( this.options.disabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If this is the first time the menu is being opened, render the items\n\t\tif ( !this._rendered ) {\n\t\t\tthis._refreshMenu();\n\t\t} else {\n\n\t\t\t// Menu clears focus on close, reset focus to selected item\n\t\t\tthis._removeClass( this.menu.find( \".ui-state-active\" ), null, \"ui-state-active\" );\n\t\t\tthis.menuInstance.focus( null, this._getSelectedItem() );\n\t\t}\n\n\t\t// If there are no options, don't open the menu\n\t\tif ( !this.menuItems.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isOpen = true;\n\t\tthis._toggleAttr();\n\t\tthis._resizeMenu();\n\t\tthis._position();\n\n\t\tthis._on( this.document, this._documentClick );\n\n\t\tthis._trigger( \"open\", event );\n\t},\n\n\t_position: function() {\n\t\tthis.menuWrap.position( $.extend( { of: this.button }, this.options.position ) );\n\t},\n\n\tclose: function( event ) {\n\t\tif ( !this.isOpen ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isOpen = false;\n\t\tthis._toggleAttr();\n\n\t\tthis.range = null;\n\t\tthis._off( this.document );\n\n\t\tthis._trigger( \"close\", event );\n\t},\n\n\twidget: function() {\n\t\treturn this.button;\n\t},\n\n\tmenuWidget: function() {\n\t\treturn this.menu;\n\t},\n\n\t_renderButtonItem: function( item ) {\n\t\tvar buttonItem = $( \"<span>\" );\n\n\t\tthis._setText( buttonItem, item.label );\n\t\tthis._addClass( buttonItem, \"ui-selectmenu-text\" );\n\n\t\treturn buttonItem;\n\t},\n\n\t_renderMenu: function( ul, items ) {\n\t\tvar that = this,\n\t\t\tcurrentOptgroup = \"\";\n\n\t\t$.each( items, function( index, item ) {\n\t\t\tvar li;\n\n\t\t\tif ( item.optgroup !== currentOptgroup ) {\n\t\t\t\tli = $( \"<li>\", {\n\t\t\t\t\ttext: item.optgroup\n\t\t\t\t} );\n\t\t\t\tthat._addClass( li, \"ui-selectmenu-optgroup\", \"ui-menu-divider\" +\n\t\t\t\t\t( item.element.parent( \"optgroup\" ).prop( \"disabled\" ) ?\n\t\t\t\t\t\t\" ui-state-disabled\" :\n\t\t\t\t\t\t\"\" ) );\n\n\t\t\t\tli.appendTo( ul );\n\n\t\t\t\tcurrentOptgroup = item.optgroup;\n\t\t\t}\n\n\t\t\tthat._renderItemData( ul, item );\n\t\t} );\n\t},\n\n\t_renderItemData: function( ul, item ) {\n\t\treturn this._renderItem( ul, item ).data( \"ui-selectmenu-item\", item );\n\t},\n\n\t_renderItem: function( ul, item ) {\n\t\tvar li = $( \"<li>\" ),\n\t\t\twrapper = $( \"<div>\", {\n\t\t\t\ttitle: item.element.attr( \"title\" )\n\t\t\t} );\n\n\t\tif ( item.disabled ) {\n\t\t\tthis._addClass( li, null, \"ui-state-disabled\" );\n\t\t}\n\t\tthis._setText( wrapper, item.label );\n\n\t\treturn li.append( wrapper ).appendTo( ul );\n\t},\n\n\t_setText: function( element, value ) {\n\t\tif ( value ) {\n\t\t\telement.text( value );\n\t\t} else {\n\t\t\telement.html( \"&#160;\" );\n\t\t}\n\t},\n\n\t_move: function( direction, event ) {\n\t\tvar item, next,\n\t\t\tfilter = \".ui-menu-item\";\n\n\t\tif ( this.isOpen ) {\n\t\t\titem = this.menuItems.eq( this.focusIndex ).parent( \"li\" );\n\t\t} else {\n\t\t\titem = this.menuItems.eq( this.element[ 0 ].selectedIndex ).parent( \"li\" );\n\t\t\tfilter += \":not(.ui-state-disabled)\";\n\t\t}\n\n\t\tif ( direction === \"first\" || direction === \"last\" ) {\n\t\t\tnext = item[ direction === \"first\" ? \"prevAll\" : \"nextAll\" ]( filter ).eq( -1 );\n\t\t} else {\n\t\t\tnext = item[ direction + \"All\" ]( filter ).eq( 0 );\n\t\t}\n\n\t\tif ( next.length ) {\n\t\t\tthis.menuInstance.focus( event, next );\n\t\t}\n\t},\n\n\t_getSelectedItem: function() {\n\t\treturn this.menuItems.eq( this.element[ 0 ].selectedIndex ).parent( \"li\" );\n\t},\n\n\t_toggle: function( event ) {\n\t\tthis[ this.isOpen ? \"close\" : \"open\" ]( event );\n\t},\n\n\t_setSelection: function() {\n\t\tvar selection;\n\n\t\tif ( !this.range ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( window.getSelection ) {\n\t\t\tselection = window.getSelection();\n\t\t\tselection.removeAllRanges();\n\t\t\tselection.addRange( this.range );\n\n\t\t// Support: IE8\n\t\t} else {\n\t\t\tthis.range.select();\n\t\t}\n\n\t\t// Support: IE\n\t\t// Setting the text selection kills the button focus in IE, but\n\t\t// restoring the focus doesn't kill the selection.\n\t\tthis.button.focus();\n\t},\n\n\t_documentClick: {\n\t\tmousedown: function( event ) {\n\t\t\tif ( !this.isOpen ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( !$( event.target ).closest( \".ui-selectmenu-menu, #\" +\n\t\t\t\t\t$.ui.escapeSelector( this.ids.button ) ).length ) {\n\t\t\t\tthis.close( event );\n\t\t\t}\n\t\t}\n\t},\n\n\t_buttonEvents: {\n\n\t\t// Prevent text selection from being reset when interacting with the selectmenu (#10144)\n\t\tmousedown: function() {\n\t\t\tvar selection;\n\n\t\t\tif ( window.getSelection ) {\n\t\t\t\tselection = window.getSelection();\n\t\t\t\tif ( selection.rangeCount ) {\n\t\t\t\t\tthis.range = selection.getRangeAt( 0 );\n\t\t\t\t}\n\n\t\t\t// Support: IE8\n\t\t\t} else {\n\t\t\t\tthis.range = document.selection.createRange();\n\t\t\t}\n\t\t},\n\n\t\tclick: function( event ) {\n\t\t\tthis._setSelection();\n\t\t\tthis._toggle( event );\n\t\t},\n\n\t\tkeydown: function( event ) {\n\t\t\tvar preventDefault = true;\n\t\t\tswitch ( event.keyCode ) {\n\t\t\tcase $.ui.keyCode.TAB:\n\t\t\tcase $.ui.keyCode.ESCAPE:\n\t\t\t\tthis.close( event );\n\t\t\t\tpreventDefault = false;\n\t\t\t\tbreak;\n\t\t\tcase $.ui.keyCode.ENTER:\n\t\t\t\tif ( this.isOpen ) {\n\t\t\t\t\tthis._selectFocusedItem( event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase $.ui.keyCode.UP:\n\t\t\t\tif ( event.altKey ) {\n\t\t\t\t\tthis._toggle( event );\n\t\t\t\t} else {\n\t\t\t\t\tthis._move( \"prev\", event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase $.ui.keyCode.DOWN:\n\t\t\t\tif ( event.altKey ) {\n\t\t\t\t\tthis._toggle( event );\n\t\t\t\t} else {\n\t\t\t\t\tthis._move( \"next\", event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase $.ui.keyCode.SPACE:\n\t\t\t\tif ( this.isOpen ) {\n\t\t\t\t\tthis._selectFocusedItem( event );\n\t\t\t\t} else {\n\t\t\t\t\tthis._toggle( event );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase $.ui.keyCode.LEFT:\n\t\t\t\tthis._move( \"prev\", event );\n\t\t\t\tbreak;\n\t\t\tcase $.ui.keyCode.RIGHT:\n\t\t\t\tthis._move( \"next\", event );\n\t\t\t\tbreak;\n\t\t\tcase $.ui.keyCode.HOME:\n\t\t\tcase $.ui.keyCode.PAGE_UP:\n\t\t\t\tthis._move( \"first\", event );\n\t\t\t\tbreak;\n\t\t\tcase $.ui.keyCode.END:\n\t\t\tcase $.ui.keyCode.PAGE_DOWN:\n\t\t\t\tthis._move( \"last\", event );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.menu.trigger( event );\n\t\t\t\tpreventDefault = false;\n\t\t\t}\n\n\t\t\tif ( preventDefault ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\t},\n\n\t_selectFocusedItem: function( event ) {\n\t\tvar item = this.menuItems.eq( this.focusIndex ).parent( \"li\" );\n\t\tif ( !item.hasClass( \"ui-state-disabled\" ) ) {\n\t\t\tthis._select( item.data( \"ui-selectmenu-item\" ), event );\n\t\t}\n\t},\n\n\t_select: function( item, event ) {\n\t\tvar oldIndex = this.element[ 0 ].selectedIndex;\n\n\t\t// Change native select element\n\t\tthis.element[ 0 ].selectedIndex = item.index;\n\t\tthis.buttonItem.replaceWith( this.buttonItem = this._renderButtonItem( item ) );\n\t\tthis._setAria( item );\n\t\tthis._trigger( \"select\", event, { item: item } );\n\n\t\tif ( item.index !== oldIndex ) {\n\t\t\tthis._trigger( \"change\", event, { item: item } );\n\t\t}\n\n\t\tthis.close( event );\n\t},\n\n\t_setAria: function( item ) {\n\t\tvar id = this.menuItems.eq( item.index ).attr( \"id\" );\n\n\t\tthis.button.attr( {\n\t\t\t\"aria-labelledby\": id,\n\t\t\t\"aria-activedescendant\": id\n\t\t} );\n\t\tthis.menu.attr( \"aria-activedescendant\", id );\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tif ( key === \"icons\" ) {\n\t\t\tvar icon = this.button.find( \"span.ui-icon\" );\n\t\t\tthis._removeClass( icon, null, this.options.icons.button )\n\t\t\t\t._addClass( icon, null, value.button );\n\t\t}\n\n\t\tthis._super( key, value );\n\n\t\tif ( key === \"appendTo\" ) {\n\t\t\tthis.menuWrap.appendTo( this._appendTo() );\n\t\t}\n\n\t\tif ( key === \"width\" ) {\n\t\t\tthis._resizeButton();\n\t\t}\n\t},\n\n\t_setOptionDisabled: function( value ) {\n\t\tthis._super( value );\n\n\t\tthis.menuInstance.option( \"disabled\", value );\n\t\tthis.button.attr( \"aria-disabled\", value );\n\t\tthis._toggleClass( this.button, null, \"ui-state-disabled\", value );\n\n\t\tthis.element.prop( \"disabled\", value );\n\t\tif ( value ) {\n\t\t\tthis.button.attr( \"tabindex\", -1 );\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tthis.button.attr( \"tabindex\", 0 );\n\t\t}\n\t},\n\n\t_appendTo: function() {\n\t\tvar element = this.options.appendTo;\n\n\t\tif ( element ) {\n\t\t\telement = element.jquery || element.nodeType ?\n\t\t\t\t$( element ) :\n\t\t\t\tthis.document.find( element ).eq( 0 );\n\t\t}\n\n\t\tif ( !element || !element[ 0 ] ) {\n\t\t\telement = this.element.closest( \".ui-front, dialog\" );\n\t\t}\n\n\t\tif ( !element.length ) {\n\t\t\telement = this.document[ 0 ].body;\n\t\t}\n\n\t\treturn element;\n\t},\n\n\t_toggleAttr: function() {\n\t\tthis.button.attr( \"aria-expanded\", this.isOpen );\n\n\t\t// We can't use two _toggleClass() calls here, because we need to make sure\n\t\t// we always remove classes first and add them second, otherwise if both classes have the\n\t\t// same theme class, it will be removed after we add it.\n\t\tthis._removeClass( this.button, \"ui-selectmenu-button-\" +\n\t\t\t( this.isOpen ? \"closed\" : \"open\" ) )\n\t\t\t._addClass( this.button, \"ui-selectmenu-button-\" +\n\t\t\t\t( this.isOpen ? \"open\" : \"closed\" ) )\n\t\t\t._toggleClass( this.menuWrap, \"ui-selectmenu-open\", null, this.isOpen );\n\n\t\tthis.menu.attr( \"aria-hidden\", !this.isOpen );\n\t},\n\n\t_resizeButton: function() {\n\t\tvar width = this.options.width;\n\n\t\t// For `width: false`, just remove inline style and stop\n\t\tif ( width === false ) {\n\t\t\tthis.button.css( \"width\", \"\" );\n\t\t\treturn;\n\t\t}\n\n\t\t// For `width: null`, match the width of the original element\n\t\tif ( width === null ) {\n\t\t\twidth = this.element.show().outerWidth();\n\t\t\tthis.element.hide();\n\t\t}\n\n\t\tthis.button.outerWidth( width );\n\t},\n\n\t_resizeMenu: function() {\n\t\tthis.menu.outerWidth( Math.max(\n\t\t\tthis.button.outerWidth(),\n\n\t\t\t// Support: IE10\n\t\t\t// IE10 wraps long text (possibly a rounding bug)\n\t\t\t// so we add 1px to avoid the wrapping\n\t\t\tthis.menu.width( \"\" ).outerWidth() + 1\n\t\t) );\n\t},\n\n\t_getCreateOptions: function() {\n\t\tvar options = this._super();\n\n\t\toptions.disabled = this.element.prop( \"disabled\" );\n\n\t\treturn options;\n\t},\n\n\t_parseOptions: function( options ) {\n\t\tvar that = this,\n\t\t\tdata = [];\n\t\toptions.each( function( index, item ) {\n\t\t\tdata.push( that._parseOption( $( item ), index ) );\n\t\t} );\n\t\tthis.items = data;\n\t},\n\n\t_parseOption: function( option, index ) {\n\t\tvar optgroup = option.parent( \"optgroup\" );\n\n\t\treturn {\n\t\t\telement: option,\n\t\t\tindex: index,\n\t\t\tvalue: option.val(),\n\t\t\tlabel: option.text(),\n\t\t\toptgroup: optgroup.attr( \"label\" ) || \"\",\n\t\t\tdisabled: optgroup.prop( \"disabled\" ) || option.prop( \"disabled\" )\n\t\t};\n\t},\n\n\t_destroy: function() {\n\t\tthis._unbindFormResetHandler();\n\t\tthis.menuWrap.remove();\n\t\tthis.button.remove();\n\t\tthis.element.show();\n\t\tthis.element.removeUniqueId();\n\t\tthis.labels.attr( \"for\", this.ids.element );\n\t}\n} ] );\n\n\n/*!\n * jQuery UI Slider 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Slider\n//>>group: Widgets\n//>>description: Displays a flexible slider with ranges and accessibility via keyboard.\n//>>docs: http://api.jqueryui.com/slider/\n//>>demos: http://jqueryui.com/slider/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/slider.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\nvar widgetsSlider = $.widget( \"ui.slider\", $.ui.mouse, {\n\tversion: \"1.12.1\",\n\twidgetEventPrefix: \"slide\",\n\n\toptions: {\n\t\tanimate: false,\n\t\tclasses: {\n\t\t\t\"ui-slider\": \"ui-corner-all\",\n\t\t\t\"ui-slider-handle\": \"ui-corner-all\",\n\n\t\t\t// Note: ui-widget-header isn't the most fittingly semantic framework class for this\n\t\t\t// element, but worked best visually with a variety of themes\n\t\t\t\"ui-slider-range\": \"ui-corner-all ui-widget-header\"\n\t\t},\n\t\tdistance: 0,\n\t\tmax: 100,\n\t\tmin: 0,\n\t\torientation: \"horizontal\",\n\t\trange: false,\n\t\tstep: 1,\n\t\tvalue: 0,\n\t\tvalues: null,\n\n\t\t// Callbacks\n\t\tchange: null,\n\t\tslide: null,\n\t\tstart: null,\n\t\tstop: null\n\t},\n\n\t// Number of pages in a slider\n\t// (how many times can you page up/down to go through the whole range)\n\tnumPages: 5,\n\n\t_create: function() {\n\t\tthis._keySliding = false;\n\t\tthis._mouseSliding = false;\n\t\tthis._animateOff = true;\n\t\tthis._handleIndex = null;\n\t\tthis._detectOrientation();\n\t\tthis._mouseInit();\n\t\tthis._calculateNewMax();\n\n\t\tthis._addClass( \"ui-slider ui-slider-\" + this.orientation,\n\t\t\t\"ui-widget ui-widget-content\" );\n\n\t\tthis._refresh();\n\n\t\tthis._animateOff = false;\n\t},\n\n\t_refresh: function() {\n\t\tthis._createRange();\n\t\tthis._createHandles();\n\t\tthis._setupEvents();\n\t\tthis._refreshValue();\n\t},\n\n\t_createHandles: function() {\n\t\tvar i, handleCount,\n\t\t\toptions = this.options,\n\t\t\texistingHandles = this.element.find( \".ui-slider-handle\" ),\n\t\t\thandle = \"<span tabindex='0'></span>\",\n\t\t\thandles = [];\n\n\t\thandleCount = ( options.values && options.values.length ) || 1;\n\n\t\tif ( existingHandles.length > handleCount ) {\n\t\t\texistingHandles.slice( handleCount ).remove();\n\t\t\texistingHandles = existingHandles.slice( 0, handleCount );\n\t\t}\n\n\t\tfor ( i = existingHandles.length; i < handleCount; i++ ) {\n\t\t\thandles.push( handle );\n\t\t}\n\n\t\tthis.handles = existingHandles.add( $( handles.join( \"\" ) ).appendTo( this.element ) );\n\n\t\tthis._addClass( this.handles, \"ui-slider-handle\", \"ui-state-default\" );\n\n\t\tthis.handle = this.handles.eq( 0 );\n\n\t\tthis.handles.each( function( i ) {\n\t\t\t$( this )\n\t\t\t\t.data( \"ui-slider-handle-index\", i )\n\t\t\t\t.attr( \"tabIndex\", 0 );\n\t\t} );\n\t},\n\n\t_createRange: function() {\n\t\tvar options = this.options;\n\n\t\tif ( options.range ) {\n\t\t\tif ( options.range === true ) {\n\t\t\t\tif ( !options.values ) {\n\t\t\t\t\toptions.values = [ this._valueMin(), this._valueMin() ];\n\t\t\t\t} else if ( options.values.length && options.values.length !== 2 ) {\n\t\t\t\t\toptions.values = [ options.values[ 0 ], options.values[ 0 ] ];\n\t\t\t\t} else if ( $.isArray( options.values ) ) {\n\t\t\t\t\toptions.values = options.values.slice( 0 );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( !this.range || !this.range.length ) {\n\t\t\t\tthis.range = $( \"<div>\" )\n\t\t\t\t\t.appendTo( this.element );\n\n\t\t\t\tthis._addClass( this.range, \"ui-slider-range\" );\n\t\t\t} else {\n\t\t\t\tthis._removeClass( this.range, \"ui-slider-range-min ui-slider-range-max\" );\n\n\t\t\t\t// Handle range switching from true to min/max\n\t\t\t\tthis.range.css( {\n\t\t\t\t\t\"left\": \"\",\n\t\t\t\t\t\"bottom\": \"\"\n\t\t\t\t} );\n\t\t\t}\n\t\t\tif ( options.range === \"min\" || options.range === \"max\" ) {\n\t\t\t\tthis._addClass( this.range, \"ui-slider-range-\" + options.range );\n\t\t\t}\n\t\t} else {\n\t\t\tif ( this.range ) {\n\t\t\t\tthis.range.remove();\n\t\t\t}\n\t\t\tthis.range = null;\n\t\t}\n\t},\n\n\t_setupEvents: function() {\n\t\tthis._off( this.handles );\n\t\tthis._on( this.handles, this._handleEvents );\n\t\tthis._hoverable( this.handles );\n\t\tthis._focusable( this.handles );\n\t},\n\n\t_destroy: function() {\n\t\tthis.handles.remove();\n\t\tif ( this.range ) {\n\t\t\tthis.range.remove();\n\t\t}\n\n\t\tthis._mouseDestroy();\n\t},\n\n\t_mouseCapture: function( event ) {\n\t\tvar position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle,\n\t\t\tthat = this,\n\t\t\to = this.options;\n\n\t\tif ( o.disabled ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.elementSize = {\n\t\t\twidth: this.element.outerWidth(),\n\t\t\theight: this.element.outerHeight()\n\t\t};\n\t\tthis.elementOffset = this.element.offset();\n\n\t\tposition = { x: event.pageX, y: event.pageY };\n\t\tnormValue = this._normValueFromMouse( position );\n\t\tdistance = this._valueMax() - this._valueMin() + 1;\n\t\tthis.handles.each( function( i ) {\n\t\t\tvar thisDistance = Math.abs( normValue - that.values( i ) );\n\t\t\tif ( ( distance > thisDistance ) ||\n\t\t\t\t( distance === thisDistance &&\n\t\t\t\t\t( i === that._lastChangedValue || that.values( i ) === o.min ) ) ) {\n\t\t\t\tdistance = thisDistance;\n\t\t\t\tclosestHandle = $( this );\n\t\t\t\tindex = i;\n\t\t\t}\n\t\t} );\n\n\t\tallowed = this._start( event, index );\n\t\tif ( allowed === false ) {\n\t\t\treturn false;\n\t\t}\n\t\tthis._mouseSliding = true;\n\n\t\tthis._handleIndex = index;\n\n\t\tthis._addClass( closestHandle, null, \"ui-state-active\" );\n\t\tclosestHandle.trigger( \"focus\" );\n\n\t\toffset = closestHandle.offset();\n\t\tmouseOverHandle = !$( event.target ).parents().addBack().is( \".ui-slider-handle\" );\n\t\tthis._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {\n\t\t\tleft: event.pageX - offset.left - ( closestHandle.width() / 2 ),\n\t\t\ttop: event.pageY - offset.top -\n\t\t\t\t( closestHandle.height() / 2 ) -\n\t\t\t\t( parseInt( closestHandle.css( \"borderTopWidth\" ), 10 ) || 0 ) -\n\t\t\t\t( parseInt( closestHandle.css( \"borderBottomWidth\" ), 10 ) || 0 ) +\n\t\t\t\t( parseInt( closestHandle.css( \"marginTop\" ), 10 ) || 0 )\n\t\t};\n\n\t\tif ( !this.handles.hasClass( \"ui-state-hover\" ) ) {\n\t\t\tthis._slide( event, index, normValue );\n\t\t}\n\t\tthis._animateOff = true;\n\t\treturn true;\n\t},\n\n\t_mouseStart: function() {\n\t\treturn true;\n\t},\n\n\t_mouseDrag: function( event ) {\n\t\tvar position = { x: event.pageX, y: event.pageY },\n\t\t\tnormValue = this._normValueFromMouse( position );\n\n\t\tthis._slide( event, this._handleIndex, normValue );\n\n\t\treturn false;\n\t},\n\n\t_mouseStop: function( event ) {\n\t\tthis._removeClass( this.handles, null, \"ui-state-active\" );\n\t\tthis._mouseSliding = false;\n\n\t\tthis._stop( event, this._handleIndex );\n\t\tthis._change( event, this._handleIndex );\n\n\t\tthis._handleIndex = null;\n\t\tthis._clickOffset = null;\n\t\tthis._animateOff = false;\n\n\t\treturn false;\n\t},\n\n\t_detectOrientation: function() {\n\t\tthis.orientation = ( this.options.orientation === \"vertical\" ) ? \"vertical\" : \"horizontal\";\n\t},\n\n\t_normValueFromMouse: function( position ) {\n\t\tvar pixelTotal,\n\t\t\tpixelMouse,\n\t\t\tpercentMouse,\n\t\t\tvalueTotal,\n\t\t\tvalueMouse;\n\n\t\tif ( this.orientation === \"horizontal\" ) {\n\t\t\tpixelTotal = this.elementSize.width;\n\t\t\tpixelMouse = position.x - this.elementOffset.left -\n\t\t\t\t( this._clickOffset ? this._clickOffset.left : 0 );\n\t\t} else {\n\t\t\tpixelTotal = this.elementSize.height;\n\t\t\tpixelMouse = position.y - this.elementOffset.top -\n\t\t\t\t( this._clickOffset ? this._clickOffset.top : 0 );\n\t\t}\n\n\t\tpercentMouse = ( pixelMouse / pixelTotal );\n\t\tif ( percentMouse > 1 ) {\n\t\t\tpercentMouse = 1;\n\t\t}\n\t\tif ( percentMouse < 0 ) {\n\t\t\tpercentMouse = 0;\n\t\t}\n\t\tif ( this.orientation === \"vertical\" ) {\n\t\t\tpercentMouse = 1 - percentMouse;\n\t\t}\n\n\t\tvalueTotal = this._valueMax() - this._valueMin();\n\t\tvalueMouse = this._valueMin() + percentMouse * valueTotal;\n\n\t\treturn this._trimAlignValue( valueMouse );\n\t},\n\n\t_uiHash: function( index, value, values ) {\n\t\tvar uiHash = {\n\t\t\thandle: this.handles[ index ],\n\t\t\thandleIndex: index,\n\t\t\tvalue: value !== undefined ? value : this.value()\n\t\t};\n\n\t\tif ( this._hasMultipleValues() ) {\n\t\t\tuiHash.value = value !== undefined ? value : this.values( index );\n\t\t\tuiHash.values = values || this.values();\n\t\t}\n\n\t\treturn uiHash;\n\t},\n\n\t_hasMultipleValues: function() {\n\t\treturn this.options.values && this.options.values.length;\n\t},\n\n\t_start: function( event, index ) {\n\t\treturn this._trigger( \"start\", event, this._uiHash( index ) );\n\t},\n\n\t_slide: function( event, index, newVal ) {\n\t\tvar allowed, otherVal,\n\t\t\tcurrentValue = this.value(),\n\t\t\tnewValues = this.values();\n\n\t\tif ( this._hasMultipleValues() ) {\n\t\t\totherVal = this.values( index ? 0 : 1 );\n\t\t\tcurrentValue = this.values( index );\n\n\t\t\tif ( this.options.values.length === 2 && this.options.range === true ) {\n\t\t\t\tnewVal =  index === 0 ? Math.min( otherVal, newVal ) : Math.max( otherVal, newVal );\n\t\t\t}\n\n\t\t\tnewValues[ index ] = newVal;\n\t\t}\n\n\t\tif ( newVal === currentValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\tallowed = this._trigger( \"slide\", event, this._uiHash( index, newVal, newValues ) );\n\n\t\t// A slide can be canceled by returning false from the slide callback\n\t\tif ( allowed === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( this._hasMultipleValues() ) {\n\t\t\tthis.values( index, newVal );\n\t\t} else {\n\t\t\tthis.value( newVal );\n\t\t}\n\t},\n\n\t_stop: function( event, index ) {\n\t\tthis._trigger( \"stop\", event, this._uiHash( index ) );\n\t},\n\n\t_change: function( event, index ) {\n\t\tif ( !this._keySliding && !this._mouseSliding ) {\n\n\t\t\t//store the last changed value index for reference when handles overlap\n\t\t\tthis._lastChangedValue = index;\n\t\t\tthis._trigger( \"change\", event, this._uiHash( index ) );\n\t\t}\n\t},\n\n\tvalue: function( newValue ) {\n\t\tif ( arguments.length ) {\n\t\t\tthis.options.value = this._trimAlignValue( newValue );\n\t\t\tthis._refreshValue();\n\t\t\tthis._change( null, 0 );\n\t\t\treturn;\n\t\t}\n\n\t\treturn this._value();\n\t},\n\n\tvalues: function( index, newValue ) {\n\t\tvar vals,\n\t\t\tnewValues,\n\t\t\ti;\n\n\t\tif ( arguments.length > 1 ) {\n\t\t\tthis.options.values[ index ] = this._trimAlignValue( newValue );\n\t\t\tthis._refreshValue();\n\t\t\tthis._change( null, index );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( arguments.length ) {\n\t\t\tif ( $.isArray( arguments[ 0 ] ) ) {\n\t\t\t\tvals = this.options.values;\n\t\t\t\tnewValues = arguments[ 0 ];\n\t\t\t\tfor ( i = 0; i < vals.length; i += 1 ) {\n\t\t\t\t\tvals[ i ] = this._trimAlignValue( newValues[ i ] );\n\t\t\t\t\tthis._change( null, i );\n\t\t\t\t}\n\t\t\t\tthis._refreshValue();\n\t\t\t} else {\n\t\t\t\tif ( this._hasMultipleValues() ) {\n\t\t\t\t\treturn this._values( index );\n\t\t\t\t} else {\n\t\t\t\t\treturn this.value();\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\treturn this._values();\n\t\t}\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tvar i,\n\t\t\tvalsLength = 0;\n\n\t\tif ( key === \"range\" && this.options.range === true ) {\n\t\t\tif ( value === \"min\" ) {\n\t\t\t\tthis.options.value = this._values( 0 );\n\t\t\t\tthis.options.values = null;\n\t\t\t} else if ( value === \"max\" ) {\n\t\t\t\tthis.options.value = this._values( this.options.values.length - 1 );\n\t\t\t\tthis.options.values = null;\n\t\t\t}\n\t\t}\n\n\t\tif ( $.isArray( this.options.values ) ) {\n\t\t\tvalsLength = this.options.values.length;\n\t\t}\n\n\t\tthis._super( key, value );\n\n\t\tswitch ( key ) {\n\t\t\tcase \"orientation\":\n\t\t\t\tthis._detectOrientation();\n\t\t\t\tthis._removeClass( \"ui-slider-horizontal ui-slider-vertical\" )\n\t\t\t\t\t._addClass( \"ui-slider-\" + this.orientation );\n\t\t\t\tthis._refreshValue();\n\t\t\t\tif ( this.options.range ) {\n\t\t\t\t\tthis._refreshRange( value );\n\t\t\t\t}\n\n\t\t\t\t// Reset positioning from previous orientation\n\t\t\t\tthis.handles.css( value === \"horizontal\" ? \"bottom\" : \"left\", \"\" );\n\t\t\t\tbreak;\n\t\t\tcase \"value\":\n\t\t\t\tthis._animateOff = true;\n\t\t\t\tthis._refreshValue();\n\t\t\t\tthis._change( null, 0 );\n\t\t\t\tthis._animateOff = false;\n\t\t\t\tbreak;\n\t\t\tcase \"values\":\n\t\t\t\tthis._animateOff = true;\n\t\t\t\tthis._refreshValue();\n\n\t\t\t\t// Start from the last handle to prevent unreachable handles (#9046)\n\t\t\t\tfor ( i = valsLength - 1; i >= 0; i-- ) {\n\t\t\t\t\tthis._change( null, i );\n\t\t\t\t}\n\t\t\t\tthis._animateOff = false;\n\t\t\t\tbreak;\n\t\t\tcase \"step\":\n\t\t\tcase \"min\":\n\t\t\tcase \"max\":\n\t\t\t\tthis._animateOff = true;\n\t\t\t\tthis._calculateNewMax();\n\t\t\t\tthis._refreshValue();\n\t\t\t\tthis._animateOff = false;\n\t\t\t\tbreak;\n\t\t\tcase \"range\":\n\t\t\t\tthis._animateOff = true;\n\t\t\t\tthis._refresh();\n\t\t\t\tthis._animateOff = false;\n\t\t\t\tbreak;\n\t\t}\n\t},\n\n\t_setOptionDisabled: function( value ) {\n\t\tthis._super( value );\n\n\t\tthis._toggleClass( null, \"ui-state-disabled\", !!value );\n\t},\n\n\t//internal value getter\n\t// _value() returns value trimmed by min and max, aligned by step\n\t_value: function() {\n\t\tvar val = this.options.value;\n\t\tval = this._trimAlignValue( val );\n\n\t\treturn val;\n\t},\n\n\t//internal values getter\n\t// _values() returns array of values trimmed by min and max, aligned by step\n\t// _values( index ) returns single value trimmed by min and max, aligned by step\n\t_values: function( index ) {\n\t\tvar val,\n\t\t\tvals,\n\t\t\ti;\n\n\t\tif ( arguments.length ) {\n\t\t\tval = this.options.values[ index ];\n\t\t\tval = this._trimAlignValue( val );\n\n\t\t\treturn val;\n\t\t} else if ( this._hasMultipleValues() ) {\n\n\t\t\t// .slice() creates a copy of the array\n\t\t\t// this copy gets trimmed by min and max and then returned\n\t\t\tvals = this.options.values.slice();\n\t\t\tfor ( i = 0; i < vals.length; i += 1 ) {\n\t\t\t\tvals[ i ] = this._trimAlignValue( vals[ i ] );\n\t\t\t}\n\n\t\t\treturn vals;\n\t\t} else {\n\t\t\treturn [];\n\t\t}\n\t},\n\n\t// Returns the step-aligned value that val is closest to, between (inclusive) min and max\n\t_trimAlignValue: function( val ) {\n\t\tif ( val <= this._valueMin() ) {\n\t\t\treturn this._valueMin();\n\t\t}\n\t\tif ( val >= this._valueMax() ) {\n\t\t\treturn this._valueMax();\n\t\t}\n\t\tvar step = ( this.options.step > 0 ) ? this.options.step : 1,\n\t\t\tvalModStep = ( val - this._valueMin() ) % step,\n\t\t\talignValue = val - valModStep;\n\n\t\tif ( Math.abs( valModStep ) * 2 >= step ) {\n\t\t\talignValue += ( valModStep > 0 ) ? step : ( -step );\n\t\t}\n\n\t\t// Since JavaScript has problems with large floats, round\n\t\t// the final value to 5 digits after the decimal point (see #4124)\n\t\treturn parseFloat( alignValue.toFixed( 5 ) );\n\t},\n\n\t_calculateNewMax: function() {\n\t\tvar max = this.options.max,\n\t\t\tmin = this._valueMin(),\n\t\t\tstep = this.options.step,\n\t\t\taboveMin = Math.round( ( max - min ) / step ) * step;\n\t\tmax = aboveMin + min;\n\t\tif ( max > this.options.max ) {\n\n\t\t\t//If max is not divisible by step, rounding off may increase its value\n\t\t\tmax -= step;\n\t\t}\n\t\tthis.max = parseFloat( max.toFixed( this._precision() ) );\n\t},\n\n\t_precision: function() {\n\t\tvar precision = this._precisionOf( this.options.step );\n\t\tif ( this.options.min !== null ) {\n\t\t\tprecision = Math.max( precision, this._precisionOf( this.options.min ) );\n\t\t}\n\t\treturn precision;\n\t},\n\n\t_precisionOf: function( num ) {\n\t\tvar str = num.toString(),\n\t\t\tdecimal = str.indexOf( \".\" );\n\t\treturn decimal === -1 ? 0 : str.length - decimal - 1;\n\t},\n\n\t_valueMin: function() {\n\t\treturn this.options.min;\n\t},\n\n\t_valueMax: function() {\n\t\treturn this.max;\n\t},\n\n\t_refreshRange: function( orientation ) {\n\t\tif ( orientation === \"vertical\" ) {\n\t\t\tthis.range.css( { \"width\": \"\", \"left\": \"\" } );\n\t\t}\n\t\tif ( orientation === \"horizontal\" ) {\n\t\t\tthis.range.css( { \"height\": \"\", \"bottom\": \"\" } );\n\t\t}\n\t},\n\n\t_refreshValue: function() {\n\t\tvar lastValPercent, valPercent, value, valueMin, valueMax,\n\t\t\toRange = this.options.range,\n\t\t\to = this.options,\n\t\t\tthat = this,\n\t\t\tanimate = ( !this._animateOff ) ? o.animate : false,\n\t\t\t_set = {};\n\n\t\tif ( this._hasMultipleValues() ) {\n\t\t\tthis.handles.each( function( i ) {\n\t\t\t\tvalPercent = ( that.values( i ) - that._valueMin() ) / ( that._valueMax() -\n\t\t\t\t\tthat._valueMin() ) * 100;\n\t\t\t\t_set[ that.orientation === \"horizontal\" ? \"left\" : \"bottom\" ] = valPercent + \"%\";\n\t\t\t\t$( this ).stop( 1, 1 )[ animate ? \"animate\" : \"css\" ]( _set, o.animate );\n\t\t\t\tif ( that.options.range === true ) {\n\t\t\t\t\tif ( that.orientation === \"horizontal\" ) {\n\t\t\t\t\t\tif ( i === 0 ) {\n\t\t\t\t\t\t\tthat.range.stop( 1, 1 )[ animate ? \"animate\" : \"css\" ]( {\n\t\t\t\t\t\t\t\tleft: valPercent + \"%\"\n\t\t\t\t\t\t\t}, o.animate );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( i === 1 ) {\n\t\t\t\t\t\t\tthat.range[ animate ? \"animate\" : \"css\" ]( {\n\t\t\t\t\t\t\t\twidth: ( valPercent - lastValPercent ) + \"%\"\n\t\t\t\t\t\t\t}, {\n\t\t\t\t\t\t\t\tqueue: false,\n\t\t\t\t\t\t\t\tduration: o.animate\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif ( i === 0 ) {\n\t\t\t\t\t\t\tthat.range.stop( 1, 1 )[ animate ? \"animate\" : \"css\" ]( {\n\t\t\t\t\t\t\t\tbottom: ( valPercent ) + \"%\"\n\t\t\t\t\t\t\t}, o.animate );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( i === 1 ) {\n\t\t\t\t\t\t\tthat.range[ animate ? \"animate\" : \"css\" ]( {\n\t\t\t\t\t\t\t\theight: ( valPercent - lastValPercent ) + \"%\"\n\t\t\t\t\t\t\t}, {\n\t\t\t\t\t\t\t\tqueue: false,\n\t\t\t\t\t\t\t\tduration: o.animate\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlastValPercent = valPercent;\n\t\t\t} );\n\t\t} else {\n\t\t\tvalue = this.value();\n\t\t\tvalueMin = this._valueMin();\n\t\t\tvalueMax = this._valueMax();\n\t\t\tvalPercent = ( valueMax !== valueMin ) ?\n\t\t\t\t\t( value - valueMin ) / ( valueMax - valueMin ) * 100 :\n\t\t\t\t\t0;\n\t\t\t_set[ this.orientation === \"horizontal\" ? \"left\" : \"bottom\" ] = valPercent + \"%\";\n\t\t\tthis.handle.stop( 1, 1 )[ animate ? \"animate\" : \"css\" ]( _set, o.animate );\n\n\t\t\tif ( oRange === \"min\" && this.orientation === \"horizontal\" ) {\n\t\t\t\tthis.range.stop( 1, 1 )[ animate ? \"animate\" : \"css\" ]( {\n\t\t\t\t\twidth: valPercent + \"%\"\n\t\t\t\t}, o.animate );\n\t\t\t}\n\t\t\tif ( oRange === \"max\" && this.orientation === \"horizontal\" ) {\n\t\t\t\tthis.range.stop( 1, 1 )[ animate ? \"animate\" : \"css\" ]( {\n\t\t\t\t\twidth: ( 100 - valPercent ) + \"%\"\n\t\t\t\t}, o.animate );\n\t\t\t}\n\t\t\tif ( oRange === \"min\" && this.orientation === \"vertical\" ) {\n\t\t\t\tthis.range.stop( 1, 1 )[ animate ? \"animate\" : \"css\" ]( {\n\t\t\t\t\theight: valPercent + \"%\"\n\t\t\t\t}, o.animate );\n\t\t\t}\n\t\t\tif ( oRange === \"max\" && this.orientation === \"vertical\" ) {\n\t\t\t\tthis.range.stop( 1, 1 )[ animate ? \"animate\" : \"css\" ]( {\n\t\t\t\t\theight: ( 100 - valPercent ) + \"%\"\n\t\t\t\t}, o.animate );\n\t\t\t}\n\t\t}\n\t},\n\n\t_handleEvents: {\n\t\tkeydown: function( event ) {\n\t\t\tvar allowed, curVal, newVal, step,\n\t\t\t\tindex = $( event.target ).data( \"ui-slider-handle-index\" );\n\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase $.ui.keyCode.HOME:\n\t\t\t\tcase $.ui.keyCode.END:\n\t\t\t\tcase $.ui.keyCode.PAGE_UP:\n\t\t\t\tcase $.ui.keyCode.PAGE_DOWN:\n\t\t\t\tcase $.ui.keyCode.UP:\n\t\t\t\tcase $.ui.keyCode.RIGHT:\n\t\t\t\tcase $.ui.keyCode.DOWN:\n\t\t\t\tcase $.ui.keyCode.LEFT:\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tif ( !this._keySliding ) {\n\t\t\t\t\t\tthis._keySliding = true;\n\t\t\t\t\t\tthis._addClass( $( event.target ), null, \"ui-state-active\" );\n\t\t\t\t\t\tallowed = this._start( event, index );\n\t\t\t\t\t\tif ( allowed === false ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tstep = this.options.step;\n\t\t\tif ( this._hasMultipleValues() ) {\n\t\t\t\tcurVal = newVal = this.values( index );\n\t\t\t} else {\n\t\t\t\tcurVal = newVal = this.value();\n\t\t\t}\n\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase $.ui.keyCode.HOME:\n\t\t\t\t\tnewVal = this._valueMin();\n\t\t\t\t\tbreak;\n\t\t\t\tcase $.ui.keyCode.END:\n\t\t\t\t\tnewVal = this._valueMax();\n\t\t\t\t\tbreak;\n\t\t\t\tcase $.ui.keyCode.PAGE_UP:\n\t\t\t\t\tnewVal = this._trimAlignValue(\n\t\t\t\t\t\tcurVal + ( ( this._valueMax() - this._valueMin() ) / this.numPages )\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\tcase $.ui.keyCode.PAGE_DOWN:\n\t\t\t\t\tnewVal = this._trimAlignValue(\n\t\t\t\t\t\tcurVal - ( ( this._valueMax() - this._valueMin() ) / this.numPages ) );\n\t\t\t\t\tbreak;\n\t\t\t\tcase $.ui.keyCode.UP:\n\t\t\t\tcase $.ui.keyCode.RIGHT:\n\t\t\t\t\tif ( curVal === this._valueMax() ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tnewVal = this._trimAlignValue( curVal + step );\n\t\t\t\t\tbreak;\n\t\t\t\tcase $.ui.keyCode.DOWN:\n\t\t\t\tcase $.ui.keyCode.LEFT:\n\t\t\t\t\tif ( curVal === this._valueMin() ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tnewVal = this._trimAlignValue( curVal - step );\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tthis._slide( event, index, newVal );\n\t\t},\n\t\tkeyup: function( event ) {\n\t\t\tvar index = $( event.target ).data( \"ui-slider-handle-index\" );\n\n\t\t\tif ( this._keySliding ) {\n\t\t\t\tthis._keySliding = false;\n\t\t\t\tthis._stop( event, index );\n\t\t\t\tthis._change( event, index );\n\t\t\t\tthis._removeClass( $( event.target ), null, \"ui-state-active\" );\n\t\t\t}\n\t\t}\n\t}\n} );\n\n\n/*!\n * jQuery UI Sortable 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Sortable\n//>>group: Interactions\n//>>description: Enables items in a list to be sorted using the mouse.\n//>>docs: http://api.jqueryui.com/sortable/\n//>>demos: http://jqueryui.com/sortable/\n//>>css.structure: ../../themes/base/sortable.css\n\n\n\nvar widgetsSortable = $.widget( \"ui.sortable\", $.ui.mouse, {\n\tversion: \"1.12.1\",\n\twidgetEventPrefix: \"sort\",\n\tready: false,\n\toptions: {\n\t\tappendTo: \"parent\",\n\t\taxis: false,\n\t\tconnectWith: false,\n\t\tcontainment: false,\n\t\tcursor: \"auto\",\n\t\tcursorAt: false,\n\t\tdropOnEmpty: true,\n\t\tforcePlaceholderSize: false,\n\t\tforceHelperSize: false,\n\t\tgrid: false,\n\t\thandle: false,\n\t\thelper: \"original\",\n\t\titems: \"> *\",\n\t\topacity: false,\n\t\tplaceholder: false,\n\t\trevert: false,\n\t\tscroll: true,\n\t\tscrollSensitivity: 20,\n\t\tscrollSpeed: 20,\n\t\tscope: \"default\",\n\t\ttolerance: \"intersect\",\n\t\tzIndex: 1000,\n\n\t\t// Callbacks\n\t\tactivate: null,\n\t\tbeforeStop: null,\n\t\tchange: null,\n\t\tdeactivate: null,\n\t\tout: null,\n\t\tover: null,\n\t\treceive: null,\n\t\tremove: null,\n\t\tsort: null,\n\t\tstart: null,\n\t\tstop: null,\n\t\tupdate: null\n\t},\n\n\t_isOverAxis: function( x, reference, size ) {\n\t\treturn ( x >= reference ) && ( x < ( reference + size ) );\n\t},\n\n\t_isFloating: function( item ) {\n\t\treturn ( /left|right/ ).test( item.css( \"float\" ) ) ||\n\t\t\t( /inline|table-cell/ ).test( item.css( \"display\" ) );\n\t},\n\n\t_create: function() {\n\t\tthis.containerCache = {};\n\t\tthis._addClass( \"ui-sortable\" );\n\n\t\t//Get the items\n\t\tthis.refresh();\n\n\t\t//Let's determine the parent's offset\n\t\tthis.offset = this.element.offset();\n\n\t\t//Initialize mouse events for interaction\n\t\tthis._mouseInit();\n\n\t\tthis._setHandleClassName();\n\n\t\t//We're ready to go\n\t\tthis.ready = true;\n\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tthis._super( key, value );\n\n\t\tif ( key === \"handle\" ) {\n\t\t\tthis._setHandleClassName();\n\t\t}\n\t},\n\n\t_setHandleClassName: function() {\n\t\tvar that = this;\n\t\tthis._removeClass( this.element.find( \".ui-sortable-handle\" ), \"ui-sortable-handle\" );\n\t\t$.each( this.items, function() {\n\t\t\tthat._addClass(\n\t\t\t\tthis.instance.options.handle ?\n\t\t\t\t\tthis.item.find( this.instance.options.handle ) :\n\t\t\t\t\tthis.item,\n\t\t\t\t\"ui-sortable-handle\"\n\t\t\t);\n\t\t} );\n\t},\n\n\t_destroy: function() {\n\t\tthis._mouseDestroy();\n\n\t\tfor ( var i = this.items.length - 1; i >= 0; i-- ) {\n\t\t\tthis.items[ i ].item.removeData( this.widgetName + \"-item\" );\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t_mouseCapture: function( event, overrideHandle ) {\n\t\tvar currentItem = null,\n\t\t\tvalidHandle = false,\n\t\t\tthat = this;\n\n\t\tif ( this.reverting ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( this.options.disabled || this.options.type === \"static\" ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t//We have to refresh the items data once first\n\t\tthis._refreshItems( event );\n\n\t\t//Find out if the clicked node (or one of its parents) is a actual item in this.items\n\t\t$( event.target ).parents().each( function() {\n\t\t\tif ( $.data( this, that.widgetName + \"-item\" ) === that ) {\n\t\t\t\tcurrentItem = $( this );\n\t\t\t\treturn false;\n\t\t\t}\n\t\t} );\n\t\tif ( $.data( event.target, that.widgetName + \"-item\" ) === that ) {\n\t\t\tcurrentItem = $( event.target );\n\t\t}\n\n\t\tif ( !currentItem ) {\n\t\t\treturn false;\n\t\t}\n\t\tif ( this.options.handle && !overrideHandle ) {\n\t\t\t$( this.options.handle, currentItem ).find( \"*\" ).addBack().each( function() {\n\t\t\t\tif ( this === event.target ) {\n\t\t\t\t\tvalidHandle = true;\n\t\t\t\t}\n\t\t\t} );\n\t\t\tif ( !validHandle ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tthis.currentItem = currentItem;\n\t\tthis._removeCurrentsFromItems();\n\t\treturn true;\n\n\t},\n\n\t_mouseStart: function( event, overrideHandle, noActivation ) {\n\n\t\tvar i, body,\n\t\t\to = this.options;\n\n\t\tthis.currentContainer = this;\n\n\t\t//We only need to call refreshPositions, because the refreshItems call has been moved to\n\t\t// mouseCapture\n\t\tthis.refreshPositions();\n\n\t\t//Create and append the visible helper\n\t\tthis.helper = this._createHelper( event );\n\n\t\t//Cache the helper size\n\t\tthis._cacheHelperProportions();\n\n\t\t/*\n\t\t * - Position generation -\n\t\t * This block generates everything position related - it's the core of draggables.\n\t\t */\n\n\t\t//Cache the margins of the original element\n\t\tthis._cacheMargins();\n\n\t\t//Get the next scrolling parent\n\t\tthis.scrollParent = this.helper.scrollParent();\n\n\t\t//The element's absolute position on the page minus margins\n\t\tthis.offset = this.currentItem.offset();\n\t\tthis.offset = {\n\t\t\ttop: this.offset.top - this.margins.top,\n\t\t\tleft: this.offset.left - this.margins.left\n\t\t};\n\n\t\t$.extend( this.offset, {\n\t\t\tclick: { //Where the click happened, relative to the element\n\t\t\t\tleft: event.pageX - this.offset.left,\n\t\t\t\ttop: event.pageY - this.offset.top\n\t\t\t},\n\t\t\tparent: this._getParentOffset(),\n\n\t\t\t// This is a relative to absolute position minus the actual position calculation -\n\t\t\t// only used for relative positioned helper\n\t\t\trelative: this._getRelativeOffset()\n\t\t} );\n\n\t\t// Only after we got the offset, we can change the helper's position to absolute\n\t\t// TODO: Still need to figure out a way to make relative sorting possible\n\t\tthis.helper.css( \"position\", \"absolute\" );\n\t\tthis.cssPosition = this.helper.css( \"position\" );\n\n\t\t//Generate the original position\n\t\tthis.originalPosition = this._generatePosition( event );\n\t\tthis.originalPageX = event.pageX;\n\t\tthis.originalPageY = event.pageY;\n\n\t\t//Adjust the mouse offset relative to the helper if \"cursorAt\" is supplied\n\t\t( o.cursorAt && this._adjustOffsetFromHelper( o.cursorAt ) );\n\n\t\t//Cache the former DOM position\n\t\tthis.domPosition = {\n\t\t\tprev: this.currentItem.prev()[ 0 ],\n\t\t\tparent: this.currentItem.parent()[ 0 ]\n\t\t};\n\n\t\t// If the helper is not the original, hide the original so it's not playing any role during\n\t\t// the drag, won't cause anything bad this way\n\t\tif ( this.helper[ 0 ] !== this.currentItem[ 0 ] ) {\n\t\t\tthis.currentItem.hide();\n\t\t}\n\n\t\t//Create the placeholder\n\t\tthis._createPlaceholder();\n\n\t\t//Set a containment if given in the options\n\t\tif ( o.containment ) {\n\t\t\tthis._setContainment();\n\t\t}\n\n\t\tif ( o.cursor && o.cursor !== \"auto\" ) { // cursor option\n\t\t\tbody = this.document.find( \"body\" );\n\n\t\t\t// Support: IE\n\t\t\tthis.storedCursor = body.css( \"cursor\" );\n\t\t\tbody.css( \"cursor\", o.cursor );\n\n\t\t\tthis.storedStylesheet =\n\t\t\t\t$( \"<style>*{ cursor: \" + o.cursor + \" !important; }</style>\" ).appendTo( body );\n\t\t}\n\n\t\tif ( o.opacity ) { // opacity option\n\t\t\tif ( this.helper.css( \"opacity\" ) ) {\n\t\t\t\tthis._storedOpacity = this.helper.css( \"opacity\" );\n\t\t\t}\n\t\t\tthis.helper.css( \"opacity\", o.opacity );\n\t\t}\n\n\t\tif ( o.zIndex ) { // zIndex option\n\t\t\tif ( this.helper.css( \"zIndex\" ) ) {\n\t\t\t\tthis._storedZIndex = this.helper.css( \"zIndex\" );\n\t\t\t}\n\t\t\tthis.helper.css( \"zIndex\", o.zIndex );\n\t\t}\n\n\t\t//Prepare scrolling\n\t\tif ( this.scrollParent[ 0 ] !== this.document[ 0 ] &&\n\t\t\t\tthis.scrollParent[ 0 ].tagName !== \"HTML\" ) {\n\t\t\tthis.overflowOffset = this.scrollParent.offset();\n\t\t}\n\n\t\t//Call callbacks\n\t\tthis._trigger( \"start\", event, this._uiHash() );\n\n\t\t//Recache the helper size\n\t\tif ( !this._preserveHelperProportions ) {\n\t\t\tthis._cacheHelperProportions();\n\t\t}\n\n\t\t//Post \"activate\" events to possible containers\n\t\tif ( !noActivation ) {\n\t\t\tfor ( i = this.containers.length - 1; i >= 0; i-- ) {\n\t\t\t\tthis.containers[ i ]._trigger( \"activate\", event, this._uiHash( this ) );\n\t\t\t}\n\t\t}\n\n\t\t//Prepare possible droppables\n\t\tif ( $.ui.ddmanager ) {\n\t\t\t$.ui.ddmanager.current = this;\n\t\t}\n\n\t\tif ( $.ui.ddmanager && !o.dropBehaviour ) {\n\t\t\t$.ui.ddmanager.prepareOffsets( this, event );\n\t\t}\n\n\t\tthis.dragging = true;\n\n\t\tthis._addClass( this.helper, \"ui-sortable-helper\" );\n\n\t\t// Execute the drag once - this causes the helper not to be visiblebefore getting its\n\t\t// correct position\n\t\tthis._mouseDrag( event );\n\t\treturn true;\n\n\t},\n\n\t_mouseDrag: function( event ) {\n\t\tvar i, item, itemElement, intersection,\n\t\t\to = this.options,\n\t\t\tscrolled = false;\n\n\t\t//Compute the helpers position\n\t\tthis.position = this._generatePosition( event );\n\t\tthis.positionAbs = this._convertPositionTo( \"absolute\" );\n\n\t\tif ( !this.lastPositionAbs ) {\n\t\t\tthis.lastPositionAbs = this.positionAbs;\n\t\t}\n\n\t\t//Do scrolling\n\t\tif ( this.options.scroll ) {\n\t\t\tif ( this.scrollParent[ 0 ] !== this.document[ 0 ] &&\n\t\t\t\t\tthis.scrollParent[ 0 ].tagName !== \"HTML\" ) {\n\n\t\t\t\tif ( ( this.overflowOffset.top + this.scrollParent[ 0 ].offsetHeight ) -\n\t\t\t\t\t\tevent.pageY < o.scrollSensitivity ) {\n\t\t\t\t\tthis.scrollParent[ 0 ].scrollTop =\n\t\t\t\t\t\tscrolled = this.scrollParent[ 0 ].scrollTop + o.scrollSpeed;\n\t\t\t\t} else if ( event.pageY - this.overflowOffset.top < o.scrollSensitivity ) {\n\t\t\t\t\tthis.scrollParent[ 0 ].scrollTop =\n\t\t\t\t\t\tscrolled = this.scrollParent[ 0 ].scrollTop - o.scrollSpeed;\n\t\t\t\t}\n\n\t\t\t\tif ( ( this.overflowOffset.left + this.scrollParent[ 0 ].offsetWidth ) -\n\t\t\t\t\t\tevent.pageX < o.scrollSensitivity ) {\n\t\t\t\t\tthis.scrollParent[ 0 ].scrollLeft = scrolled =\n\t\t\t\t\t\tthis.scrollParent[ 0 ].scrollLeft + o.scrollSpeed;\n\t\t\t\t} else if ( event.pageX - this.overflowOffset.left < o.scrollSensitivity ) {\n\t\t\t\t\tthis.scrollParent[ 0 ].scrollLeft = scrolled =\n\t\t\t\t\t\tthis.scrollParent[ 0 ].scrollLeft - o.scrollSpeed;\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\tif ( event.pageY - this.document.scrollTop() < o.scrollSensitivity ) {\n\t\t\t\t\tscrolled = this.document.scrollTop( this.document.scrollTop() - o.scrollSpeed );\n\t\t\t\t} else if ( this.window.height() - ( event.pageY - this.document.scrollTop() ) <\n\t\t\t\t\t\to.scrollSensitivity ) {\n\t\t\t\t\tscrolled = this.document.scrollTop( this.document.scrollTop() + o.scrollSpeed );\n\t\t\t\t}\n\n\t\t\t\tif ( event.pageX - this.document.scrollLeft() < o.scrollSensitivity ) {\n\t\t\t\t\tscrolled = this.document.scrollLeft(\n\t\t\t\t\t\tthis.document.scrollLeft() - o.scrollSpeed\n\t\t\t\t\t);\n\t\t\t\t} else if ( this.window.width() - ( event.pageX - this.document.scrollLeft() ) <\n\t\t\t\t\t\to.scrollSensitivity ) {\n\t\t\t\t\tscrolled = this.document.scrollLeft(\n\t\t\t\t\t\tthis.document.scrollLeft() + o.scrollSpeed\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tif ( scrolled !== false && $.ui.ddmanager && !o.dropBehaviour ) {\n\t\t\t\t$.ui.ddmanager.prepareOffsets( this, event );\n\t\t\t}\n\t\t}\n\n\t\t//Regenerate the absolute position used for position checks\n\t\tthis.positionAbs = this._convertPositionTo( \"absolute\" );\n\n\t\t//Set the helper position\n\t\tif ( !this.options.axis || this.options.axis !== \"y\" ) {\n\t\t\tthis.helper[ 0 ].style.left = this.position.left + \"px\";\n\t\t}\n\t\tif ( !this.options.axis || this.options.axis !== \"x\" ) {\n\t\t\tthis.helper[ 0 ].style.top = this.position.top + \"px\";\n\t\t}\n\n\t\t//Rearrange\n\t\tfor ( i = this.items.length - 1; i >= 0; i-- ) {\n\n\t\t\t//Cache variables and intersection, continue if no intersection\n\t\t\titem = this.items[ i ];\n\t\t\titemElement = item.item[ 0 ];\n\t\t\tintersection = this._intersectsWithPointer( item );\n\t\t\tif ( !intersection ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Only put the placeholder inside the current Container, skip all\n\t\t\t// items from other containers. This works because when moving\n\t\t\t// an item from one container to another the\n\t\t\t// currentContainer is switched before the placeholder is moved.\n\t\t\t//\n\t\t\t// Without this, moving items in \"sub-sortables\" can cause\n\t\t\t// the placeholder to jitter between the outer and inner container.\n\t\t\tif ( item.instance !== this.currentContainer ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Cannot intersect with itself\n\t\t\t// no useless actions that have been done before\n\t\t\t// no action if the item moved is the parent of the item checked\n\t\t\tif ( itemElement !== this.currentItem[ 0 ] &&\n\t\t\t\tthis.placeholder[ intersection === 1 ? \"next\" : \"prev\" ]()[ 0 ] !== itemElement &&\n\t\t\t\t!$.contains( this.placeholder[ 0 ], itemElement ) &&\n\t\t\t\t( this.options.type === \"semi-dynamic\" ?\n\t\t\t\t\t!$.contains( this.element[ 0 ], itemElement ) :\n\t\t\t\t\ttrue\n\t\t\t\t)\n\t\t\t) {\n\n\t\t\t\tthis.direction = intersection === 1 ? \"down\" : \"up\";\n\n\t\t\t\tif ( this.options.tolerance === \"pointer\" || this._intersectsWithSides( item ) ) {\n\t\t\t\t\tthis._rearrange( event, item );\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tthis._trigger( \"change\", event, this._uiHash() );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t//Post events to containers\n\t\tthis._contactContainers( event );\n\n\t\t//Interconnect with droppables\n\t\tif ( $.ui.ddmanager ) {\n\t\t\t$.ui.ddmanager.drag( this, event );\n\t\t}\n\n\t\t//Call callbacks\n\t\tthis._trigger( \"sort\", event, this._uiHash() );\n\n\t\tthis.lastPositionAbs = this.positionAbs;\n\t\treturn false;\n\n\t},\n\n\t_mouseStop: function( event, noPropagation ) {\n\n\t\tif ( !event ) {\n\t\t\treturn;\n\t\t}\n\n\t\t//If we are using droppables, inform the manager about the drop\n\t\tif ( $.ui.ddmanager && !this.options.dropBehaviour ) {\n\t\t\t$.ui.ddmanager.drop( this, event );\n\t\t}\n\n\t\tif ( this.options.revert ) {\n\t\t\tvar that = this,\n\t\t\t\tcur = this.placeholder.offset(),\n\t\t\t\taxis = this.options.axis,\n\t\t\t\tanimation = {};\n\n\t\t\tif ( !axis || axis === \"x\" ) {\n\t\t\t\tanimation.left = cur.left - this.offset.parent.left - this.margins.left +\n\t\t\t\t\t( this.offsetParent[ 0 ] === this.document[ 0 ].body ?\n\t\t\t\t\t\t0 :\n\t\t\t\t\t\tthis.offsetParent[ 0 ].scrollLeft\n\t\t\t\t\t);\n\t\t\t}\n\t\t\tif ( !axis || axis === \"y\" ) {\n\t\t\t\tanimation.top = cur.top - this.offset.parent.top - this.margins.top +\n\t\t\t\t\t( this.offsetParent[ 0 ] === this.document[ 0 ].body ?\n\t\t\t\t\t\t0 :\n\t\t\t\t\t\tthis.offsetParent[ 0 ].scrollTop\n\t\t\t\t\t);\n\t\t\t}\n\t\t\tthis.reverting = true;\n\t\t\t$( this.helper ).animate(\n\t\t\t\tanimation,\n\t\t\t\tparseInt( this.options.revert, 10 ) || 500,\n\t\t\t\tfunction() {\n\t\t\t\t\tthat._clear( event );\n\t\t\t\t}\n\t\t\t);\n\t\t} else {\n\t\t\tthis._clear( event, noPropagation );\n\t\t}\n\n\t\treturn false;\n\n\t},\n\n\tcancel: function() {\n\n\t\tif ( this.dragging ) {\n\n\t\t\tthis._mouseUp( new $.Event( \"mouseup\", { target: null } ) );\n\n\t\t\tif ( this.options.helper === \"original\" ) {\n\t\t\t\tthis.currentItem.css( this._storedCSS );\n\t\t\t\tthis._removeClass( this.currentItem, \"ui-sortable-helper\" );\n\t\t\t} else {\n\t\t\t\tthis.currentItem.show();\n\t\t\t}\n\n\t\t\t//Post deactivating events to containers\n\t\t\tfor ( var i = this.containers.length - 1; i >= 0; i-- ) {\n\t\t\t\tthis.containers[ i ]._trigger( \"deactivate\", null, this._uiHash( this ) );\n\t\t\t\tif ( this.containers[ i ].containerCache.over ) {\n\t\t\t\t\tthis.containers[ i ]._trigger( \"out\", null, this._uiHash( this ) );\n\t\t\t\t\tthis.containers[ i ].containerCache.over = 0;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\tif ( this.placeholder ) {\n\n\t\t\t//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately,\n\t\t\t// it unbinds ALL events from the original node!\n\t\t\tif ( this.placeholder[ 0 ].parentNode ) {\n\t\t\t\tthis.placeholder[ 0 ].parentNode.removeChild( this.placeholder[ 0 ] );\n\t\t\t}\n\t\t\tif ( this.options.helper !== \"original\" && this.helper &&\n\t\t\t\t\tthis.helper[ 0 ].parentNode ) {\n\t\t\t\tthis.helper.remove();\n\t\t\t}\n\n\t\t\t$.extend( this, {\n\t\t\t\thelper: null,\n\t\t\t\tdragging: false,\n\t\t\t\treverting: false,\n\t\t\t\t_noFinalSort: null\n\t\t\t} );\n\n\t\t\tif ( this.domPosition.prev ) {\n\t\t\t\t$( this.domPosition.prev ).after( this.currentItem );\n\t\t\t} else {\n\t\t\t\t$( this.domPosition.parent ).prepend( this.currentItem );\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\n\t},\n\n\tserialize: function( o ) {\n\n\t\tvar items = this._getItemsAsjQuery( o && o.connected ),\n\t\t\tstr = [];\n\t\to = o || {};\n\n\t\t$( items ).each( function() {\n\t\t\tvar res = ( $( o.item || this ).attr( o.attribute || \"id\" ) || \"\" )\n\t\t\t\t.match( o.expression || ( /(.+)[\\-=_](.+)/ ) );\n\t\t\tif ( res ) {\n\t\t\t\tstr.push(\n\t\t\t\t\t( o.key || res[ 1 ] + \"[]\" ) +\n\t\t\t\t\t\"=\" + ( o.key && o.expression ? res[ 1 ] : res[ 2 ] ) );\n\t\t\t}\n\t\t} );\n\n\t\tif ( !str.length && o.key ) {\n\t\t\tstr.push( o.key + \"=\" );\n\t\t}\n\n\t\treturn str.join( \"&\" );\n\n\t},\n\n\ttoArray: function( o ) {\n\n\t\tvar items = this._getItemsAsjQuery( o && o.connected ),\n\t\t\tret = [];\n\n\t\to = o || {};\n\n\t\titems.each( function() {\n\t\t\tret.push( $( o.item || this ).attr( o.attribute || \"id\" ) || \"\" );\n\t\t} );\n\t\treturn ret;\n\n\t},\n\n\t/* Be careful with the following core functions */\n\t_intersectsWith: function( item ) {\n\n\t\tvar x1 = this.positionAbs.left,\n\t\t\tx2 = x1 + this.helperProportions.width,\n\t\t\ty1 = this.positionAbs.top,\n\t\t\ty2 = y1 + this.helperProportions.height,\n\t\t\tl = item.left,\n\t\t\tr = l + item.width,\n\t\t\tt = item.top,\n\t\t\tb = t + item.height,\n\t\t\tdyClick = this.offset.click.top,\n\t\t\tdxClick = this.offset.click.left,\n\t\t\tisOverElementHeight = ( this.options.axis === \"x\" ) || ( ( y1 + dyClick ) > t &&\n\t\t\t\t( y1 + dyClick ) < b ),\n\t\t\tisOverElementWidth = ( this.options.axis === \"y\" ) || ( ( x1 + dxClick ) > l &&\n\t\t\t\t( x1 + dxClick ) < r ),\n\t\t\tisOverElement = isOverElementHeight && isOverElementWidth;\n\n\t\tif ( this.options.tolerance === \"pointer\" ||\n\t\t\tthis.options.forcePointerForContainers ||\n\t\t\t( this.options.tolerance !== \"pointer\" &&\n\t\t\t\tthis.helperProportions[ this.floating ? \"width\" : \"height\" ] >\n\t\t\t\titem[ this.floating ? \"width\" : \"height\" ] )\n\t\t) {\n\t\t\treturn isOverElement;\n\t\t} else {\n\n\t\t\treturn ( l < x1 + ( this.helperProportions.width / 2 ) && // Right Half\n\t\t\t\tx2 - ( this.helperProportions.width / 2 ) < r && // Left Half\n\t\t\t\tt < y1 + ( this.helperProportions.height / 2 ) && // Bottom Half\n\t\t\t\ty2 - ( this.helperProportions.height / 2 ) < b ); // Top Half\n\n\t\t}\n\t},\n\n\t_intersectsWithPointer: function( item ) {\n\t\tvar verticalDirection, horizontalDirection,\n\t\t\tisOverElementHeight = ( this.options.axis === \"x\" ) ||\n\t\t\t\tthis._isOverAxis(\n\t\t\t\t\tthis.positionAbs.top + this.offset.click.top, item.top, item.height ),\n\t\t\tisOverElementWidth = ( this.options.axis === \"y\" ) ||\n\t\t\t\tthis._isOverAxis(\n\t\t\t\t\tthis.positionAbs.left + this.offset.click.left, item.left, item.width ),\n\t\t\tisOverElement = isOverElementHeight && isOverElementWidth;\n\n\t\tif ( !isOverElement ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tverticalDirection = this._getDragVerticalDirection();\n\t\thorizontalDirection = this._getDragHorizontalDirection();\n\n\t\treturn this.floating ?\n\t\t\t( ( horizontalDirection === \"right\" || verticalDirection === \"down\" ) ? 2 : 1 )\n\t\t\t: ( verticalDirection && ( verticalDirection === \"down\" ? 2 : 1 ) );\n\n\t},\n\n\t_intersectsWithSides: function( item ) {\n\n\t\tvar isOverBottomHalf = this._isOverAxis( this.positionAbs.top +\n\t\t\t\tthis.offset.click.top, item.top + ( item.height / 2 ), item.height ),\n\t\t\tisOverRightHalf = this._isOverAxis( this.positionAbs.left +\n\t\t\t\tthis.offset.click.left, item.left + ( item.width / 2 ), item.width ),\n\t\t\tverticalDirection = this._getDragVerticalDirection(),\n\t\t\thorizontalDirection = this._getDragHorizontalDirection();\n\n\t\tif ( this.floating && horizontalDirection ) {\n\t\t\treturn ( ( horizontalDirection === \"right\" && isOverRightHalf ) ||\n\t\t\t\t( horizontalDirection === \"left\" && !isOverRightHalf ) );\n\t\t} else {\n\t\t\treturn verticalDirection && ( ( verticalDirection === \"down\" && isOverBottomHalf ) ||\n\t\t\t\t( verticalDirection === \"up\" && !isOverBottomHalf ) );\n\t\t}\n\n\t},\n\n\t_getDragVerticalDirection: function() {\n\t\tvar delta = this.positionAbs.top - this.lastPositionAbs.top;\n\t\treturn delta !== 0 && ( delta > 0 ? \"down\" : \"up\" );\n\t},\n\n\t_getDragHorizontalDirection: function() {\n\t\tvar delta = this.positionAbs.left - this.lastPositionAbs.left;\n\t\treturn delta !== 0 && ( delta > 0 ? \"right\" : \"left\" );\n\t},\n\n\trefresh: function( event ) {\n\t\tthis._refreshItems( event );\n\t\tthis._setHandleClassName();\n\t\tthis.refreshPositions();\n\t\treturn this;\n\t},\n\n\t_connectWith: function() {\n\t\tvar options = this.options;\n\t\treturn options.connectWith.constructor === String ?\n\t\t\t[ options.connectWith ] :\n\t\t\toptions.connectWith;\n\t},\n\n\t_getItemsAsjQuery: function( connected ) {\n\n\t\tvar i, j, cur, inst,\n\t\t\titems = [],\n\t\t\tqueries = [],\n\t\t\tconnectWith = this._connectWith();\n\n\t\tif ( connectWith && connected ) {\n\t\t\tfor ( i = connectWith.length - 1; i >= 0; i-- ) {\n\t\t\t\tcur = $( connectWith[ i ], this.document[ 0 ] );\n\t\t\t\tfor ( j = cur.length - 1; j >= 0; j-- ) {\n\t\t\t\t\tinst = $.data( cur[ j ], this.widgetFullName );\n\t\t\t\t\tif ( inst && inst !== this && !inst.options.disabled ) {\n\t\t\t\t\t\tqueries.push( [ $.isFunction( inst.options.items ) ?\n\t\t\t\t\t\t\tinst.options.items.call( inst.element ) :\n\t\t\t\t\t\t\t$( inst.options.items, inst.element )\n\t\t\t\t\t\t\t\t.not( \".ui-sortable-helper\" )\n\t\t\t\t\t\t\t\t.not( \".ui-sortable-placeholder\" ), inst ] );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tqueries.push( [ $.isFunction( this.options.items ) ?\n\t\t\tthis.options.items\n\t\t\t\t.call( this.element, null, { options: this.options, item: this.currentItem } ) :\n\t\t\t$( this.options.items, this.element )\n\t\t\t\t.not( \".ui-sortable-helper\" )\n\t\t\t\t.not( \".ui-sortable-placeholder\" ), this ] );\n\n\t\tfunction addItems() {\n\t\t\titems.push( this );\n\t\t}\n\t\tfor ( i = queries.length - 1; i >= 0; i-- ) {\n\t\t\tqueries[ i ][ 0 ].each( addItems );\n\t\t}\n\n\t\treturn $( items );\n\n\t},\n\n\t_removeCurrentsFromItems: function() {\n\n\t\tvar list = this.currentItem.find( \":data(\" + this.widgetName + \"-item)\" );\n\n\t\tthis.items = $.grep( this.items, function( item ) {\n\t\t\tfor ( var j = 0; j < list.length; j++ ) {\n\t\t\t\tif ( list[ j ] === item.item[ 0 ] ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t} );\n\n\t},\n\n\t_refreshItems: function( event ) {\n\n\t\tthis.items = [];\n\t\tthis.containers = [ this ];\n\n\t\tvar i, j, cur, inst, targetData, _queries, item, queriesLength,\n\t\t\titems = this.items,\n\t\t\tqueries = [ [ $.isFunction( this.options.items ) ?\n\t\t\t\tthis.options.items.call( this.element[ 0 ], event, { item: this.currentItem } ) :\n\t\t\t\t$( this.options.items, this.element ), this ] ],\n\t\t\tconnectWith = this._connectWith();\n\n\t\t//Shouldn't be run the first time through due to massive slow-down\n\t\tif ( connectWith && this.ready ) {\n\t\t\tfor ( i = connectWith.length - 1; i >= 0; i-- ) {\n\t\t\t\tcur = $( connectWith[ i ], this.document[ 0 ] );\n\t\t\t\tfor ( j = cur.length - 1; j >= 0; j-- ) {\n\t\t\t\t\tinst = $.data( cur[ j ], this.widgetFullName );\n\t\t\t\t\tif ( inst && inst !== this && !inst.options.disabled ) {\n\t\t\t\t\t\tqueries.push( [ $.isFunction( inst.options.items ) ?\n\t\t\t\t\t\t\tinst.options.items\n\t\t\t\t\t\t\t\t.call( inst.element[ 0 ], event, { item: this.currentItem } ) :\n\t\t\t\t\t\t\t$( inst.options.items, inst.element ), inst ] );\n\t\t\t\t\t\tthis.containers.push( inst );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor ( i = queries.length - 1; i >= 0; i-- ) {\n\t\t\ttargetData = queries[ i ][ 1 ];\n\t\t\t_queries = queries[ i ][ 0 ];\n\n\t\t\tfor ( j = 0, queriesLength = _queries.length; j < queriesLength; j++ ) {\n\t\t\t\titem = $( _queries[ j ] );\n\n\t\t\t\t// Data for target checking (mouse manager)\n\t\t\t\titem.data( this.widgetName + \"-item\", targetData );\n\n\t\t\t\titems.push( {\n\t\t\t\t\titem: item,\n\t\t\t\t\tinstance: targetData,\n\t\t\t\t\twidth: 0, height: 0,\n\t\t\t\t\tleft: 0, top: 0\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\n\t},\n\n\trefreshPositions: function( fast ) {\n\n\t\t// Determine whether items are being displayed horizontally\n\t\tthis.floating = this.items.length ?\n\t\t\tthis.options.axis === \"x\" || this._isFloating( this.items[ 0 ].item ) :\n\t\t\tfalse;\n\n\t\t//This has to be redone because due to the item being moved out/into the offsetParent,\n\t\t// the offsetParent's position will change\n\t\tif ( this.offsetParent && this.helper ) {\n\t\t\tthis.offset.parent = this._getParentOffset();\n\t\t}\n\n\t\tvar i, item, t, p;\n\n\t\tfor ( i = this.items.length - 1; i >= 0; i-- ) {\n\t\t\titem = this.items[ i ];\n\n\t\t\t//We ignore calculating positions of all connected containers when we're not over them\n\t\t\tif ( item.instance !== this.currentContainer && this.currentContainer &&\n\t\t\t\t\titem.item[ 0 ] !== this.currentItem[ 0 ] ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tt = this.options.toleranceElement ?\n\t\t\t\t$( this.options.toleranceElement, item.item ) :\n\t\t\t\titem.item;\n\n\t\t\tif ( !fast ) {\n\t\t\t\titem.width = t.outerWidth();\n\t\t\t\titem.height = t.outerHeight();\n\t\t\t}\n\n\t\t\tp = t.offset();\n\t\t\titem.left = p.left;\n\t\t\titem.top = p.top;\n\t\t}\n\n\t\tif ( this.options.custom && this.options.custom.refreshContainers ) {\n\t\t\tthis.options.custom.refreshContainers.call( this );\n\t\t} else {\n\t\t\tfor ( i = this.containers.length - 1; i >= 0; i-- ) {\n\t\t\t\tp = this.containers[ i ].element.offset();\n\t\t\t\tthis.containers[ i ].containerCache.left = p.left;\n\t\t\t\tthis.containers[ i ].containerCache.top = p.top;\n\t\t\t\tthis.containers[ i ].containerCache.width =\n\t\t\t\t\tthis.containers[ i ].element.outerWidth();\n\t\t\t\tthis.containers[ i ].containerCache.height =\n\t\t\t\t\tthis.containers[ i ].element.outerHeight();\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t_createPlaceholder: function( that ) {\n\t\tthat = that || this;\n\t\tvar className,\n\t\t\to = that.options;\n\n\t\tif ( !o.placeholder || o.placeholder.constructor === String ) {\n\t\t\tclassName = o.placeholder;\n\t\t\to.placeholder = {\n\t\t\t\telement: function() {\n\n\t\t\t\t\tvar nodeName = that.currentItem[ 0 ].nodeName.toLowerCase(),\n\t\t\t\t\t\telement = $( \"<\" + nodeName + \">\", that.document[ 0 ] );\n\n\t\t\t\t\t\tthat._addClass( element, \"ui-sortable-placeholder\",\n\t\t\t\t\t\t\t\tclassName || that.currentItem[ 0 ].className )\n\t\t\t\t\t\t\t._removeClass( element, \"ui-sortable-helper\" );\n\n\t\t\t\t\tif ( nodeName === \"tbody\" ) {\n\t\t\t\t\t\tthat._createTrPlaceholder(\n\t\t\t\t\t\t\tthat.currentItem.find( \"tr\" ).eq( 0 ),\n\t\t\t\t\t\t\t$( \"<tr>\", that.document[ 0 ] ).appendTo( element )\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if ( nodeName === \"tr\" ) {\n\t\t\t\t\t\tthat._createTrPlaceholder( that.currentItem, element );\n\t\t\t\t\t} else if ( nodeName === \"img\" ) {\n\t\t\t\t\t\telement.attr( \"src\", that.currentItem.attr( \"src\" ) );\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( !className ) {\n\t\t\t\t\t\telement.css( \"visibility\", \"hidden\" );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn element;\n\t\t\t\t},\n\t\t\t\tupdate: function( container, p ) {\n\n\t\t\t\t\t// 1. If a className is set as 'placeholder option, we don't force sizes -\n\t\t\t\t\t// the class is responsible for that\n\t\t\t\t\t// 2. The option 'forcePlaceholderSize can be enabled to force it even if a\n\t\t\t\t\t// class name is specified\n\t\t\t\t\tif ( className && !o.forcePlaceholderSize ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t//If the element doesn't have a actual height by itself (without styles coming\n\t\t\t\t\t// from a stylesheet), it receives the inline height from the dragged item\n\t\t\t\t\tif ( !p.height() ) {\n\t\t\t\t\t\tp.height(\n\t\t\t\t\t\t\tthat.currentItem.innerHeight() -\n\t\t\t\t\t\t\tparseInt( that.currentItem.css( \"paddingTop\" ) || 0, 10 ) -\n\t\t\t\t\t\t\tparseInt( that.currentItem.css( \"paddingBottom\" ) || 0, 10 ) );\n\t\t\t\t\t}\n\t\t\t\t\tif ( !p.width() ) {\n\t\t\t\t\t\tp.width(\n\t\t\t\t\t\t\tthat.currentItem.innerWidth() -\n\t\t\t\t\t\t\tparseInt( that.currentItem.css( \"paddingLeft\" ) || 0, 10 ) -\n\t\t\t\t\t\t\tparseInt( that.currentItem.css( \"paddingRight\" ) || 0, 10 ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t//Create the placeholder\n\t\tthat.placeholder = $( o.placeholder.element.call( that.element, that.currentItem ) );\n\n\t\t//Append it after the actual current item\n\t\tthat.currentItem.after( that.placeholder );\n\n\t\t//Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)\n\t\to.placeholder.update( that, that.placeholder );\n\n\t},\n\n\t_createTrPlaceholder: function( sourceTr, targetTr ) {\n\t\tvar that = this;\n\n\t\tsourceTr.children().each( function() {\n\t\t\t$( \"<td>&#160;</td>\", that.document[ 0 ] )\n\t\t\t\t.attr( \"colspan\", $( this ).attr( \"colspan\" ) || 1 )\n\t\t\t\t.appendTo( targetTr );\n\t\t} );\n\t},\n\n\t_contactContainers: function( event ) {\n\t\tvar i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, cur, nearBottom,\n\t\t\tfloating, axis,\n\t\t\tinnermostContainer = null,\n\t\t\tinnermostIndex = null;\n\n\t\t// Get innermost container that intersects with item\n\t\tfor ( i = this.containers.length - 1; i >= 0; i-- ) {\n\n\t\t\t// Never consider a container that's located within the item itself\n\t\t\tif ( $.contains( this.currentItem[ 0 ], this.containers[ i ].element[ 0 ] ) ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif ( this._intersectsWith( this.containers[ i ].containerCache ) ) {\n\n\t\t\t\t// If we've already found a container and it's more \"inner\" than this, then continue\n\t\t\t\tif ( innermostContainer &&\n\t\t\t\t\t\t$.contains(\n\t\t\t\t\t\t\tthis.containers[ i ].element[ 0 ],\n\t\t\t\t\t\t\tinnermostContainer.element[ 0 ] ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tinnermostContainer = this.containers[ i ];\n\t\t\t\tinnermostIndex = i;\n\n\t\t\t} else {\n\n\t\t\t\t// container doesn't intersect. trigger \"out\" event if necessary\n\t\t\t\tif ( this.containers[ i ].containerCache.over ) {\n\t\t\t\t\tthis.containers[ i ]._trigger( \"out\", event, this._uiHash( this ) );\n\t\t\t\t\tthis.containers[ i ].containerCache.over = 0;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\t// If no intersecting containers found, return\n\t\tif ( !innermostContainer ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Move the item into the container if it's not there already\n\t\tif ( this.containers.length === 1 ) {\n\t\t\tif ( !this.containers[ innermostIndex ].containerCache.over ) {\n\t\t\t\tthis.containers[ innermostIndex ]._trigger( \"over\", event, this._uiHash( this ) );\n\t\t\t\tthis.containers[ innermostIndex ].containerCache.over = 1;\n\t\t\t}\n\t\t} else {\n\n\t\t\t// When entering a new container, we will find the item with the least distance and\n\t\t\t// append our item near it\n\t\t\tdist = 10000;\n\t\t\titemWithLeastDistance = null;\n\t\t\tfloating = innermostContainer.floating || this._isFloating( this.currentItem );\n\t\t\tposProperty = floating ? \"left\" : \"top\";\n\t\t\tsizeProperty = floating ? \"width\" : \"height\";\n\t\t\taxis = floating ? \"pageX\" : \"pageY\";\n\n\t\t\tfor ( j = this.items.length - 1; j >= 0; j-- ) {\n\t\t\t\tif ( !$.contains(\n\t\t\t\t\t\tthis.containers[ innermostIndex ].element[ 0 ], this.items[ j ].item[ 0 ] )\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif ( this.items[ j ].item[ 0 ] === this.currentItem[ 0 ] ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tcur = this.items[ j ].item.offset()[ posProperty ];\n\t\t\t\tnearBottom = false;\n\t\t\t\tif ( event[ axis ] - cur > this.items[ j ][ sizeProperty ] / 2 ) {\n\t\t\t\t\tnearBottom = true;\n\t\t\t\t}\n\n\t\t\t\tif ( Math.abs( event[ axis ] - cur ) < dist ) {\n\t\t\t\t\tdist = Math.abs( event[ axis ] - cur );\n\t\t\t\t\titemWithLeastDistance = this.items[ j ];\n\t\t\t\t\tthis.direction = nearBottom ? \"up\" : \"down\";\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t//Check if dropOnEmpty is enabled\n\t\t\tif ( !itemWithLeastDistance && !this.options.dropOnEmpty ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( this.currentContainer === this.containers[ innermostIndex ] ) {\n\t\t\t\tif ( !this.currentContainer.containerCache.over ) {\n\t\t\t\t\tthis.containers[ innermostIndex ]._trigger( \"over\", event, this._uiHash() );\n\t\t\t\t\tthis.currentContainer.containerCache.over = 1;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\titemWithLeastDistance ?\n\t\t\t\tthis._rearrange( event, itemWithLeastDistance, null, true ) :\n\t\t\t\tthis._rearrange( event, null, this.containers[ innermostIndex ].element, true );\n\t\t\tthis._trigger( \"change\", event, this._uiHash() );\n\t\t\tthis.containers[ innermostIndex ]._trigger( \"change\", event, this._uiHash( this ) );\n\t\t\tthis.currentContainer = this.containers[ innermostIndex ];\n\n\t\t\t//Update the placeholder\n\t\t\tthis.options.placeholder.update( this.currentContainer, this.placeholder );\n\n\t\t\tthis.containers[ innermostIndex ]._trigger( \"over\", event, this._uiHash( this ) );\n\t\t\tthis.containers[ innermostIndex ].containerCache.over = 1;\n\t\t}\n\n\t},\n\n\t_createHelper: function( event ) {\n\n\t\tvar o = this.options,\n\t\t\thelper = $.isFunction( o.helper ) ?\n\t\t\t\t$( o.helper.apply( this.element[ 0 ], [ event, this.currentItem ] ) ) :\n\t\t\t\t( o.helper === \"clone\" ? this.currentItem.clone() : this.currentItem );\n\n\t\t//Add the helper to the DOM if that didn't happen already\n\t\tif ( !helper.parents( \"body\" ).length ) {\n\t\t\t$( o.appendTo !== \"parent\" ?\n\t\t\t\to.appendTo :\n\t\t\t\tthis.currentItem[ 0 ].parentNode )[ 0 ].appendChild( helper[ 0 ] );\n\t\t}\n\n\t\tif ( helper[ 0 ] === this.currentItem[ 0 ] ) {\n\t\t\tthis._storedCSS = {\n\t\t\t\twidth: this.currentItem[ 0 ].style.width,\n\t\t\t\theight: this.currentItem[ 0 ].style.height,\n\t\t\t\tposition: this.currentItem.css( \"position\" ),\n\t\t\t\ttop: this.currentItem.css( \"top\" ),\n\t\t\t\tleft: this.currentItem.css( \"left\" )\n\t\t\t};\n\t\t}\n\n\t\tif ( !helper[ 0 ].style.width || o.forceHelperSize ) {\n\t\t\thelper.width( this.currentItem.width() );\n\t\t}\n\t\tif ( !helper[ 0 ].style.height || o.forceHelperSize ) {\n\t\t\thelper.height( this.currentItem.height() );\n\t\t}\n\n\t\treturn helper;\n\n\t},\n\n\t_adjustOffsetFromHelper: function( obj ) {\n\t\tif ( typeof obj === \"string\" ) {\n\t\t\tobj = obj.split( \" \" );\n\t\t}\n\t\tif ( $.isArray( obj ) ) {\n\t\t\tobj = { left: +obj[ 0 ], top: +obj[ 1 ] || 0 };\n\t\t}\n\t\tif ( \"left\" in obj ) {\n\t\t\tthis.offset.click.left = obj.left + this.margins.left;\n\t\t}\n\t\tif ( \"right\" in obj ) {\n\t\t\tthis.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;\n\t\t}\n\t\tif ( \"top\" in obj ) {\n\t\t\tthis.offset.click.top = obj.top + this.margins.top;\n\t\t}\n\t\tif ( \"bottom\" in obj ) {\n\t\t\tthis.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;\n\t\t}\n\t},\n\n\t_getParentOffset: function() {\n\n\t\t//Get the offsetParent and cache its position\n\t\tthis.offsetParent = this.helper.offsetParent();\n\t\tvar po = this.offsetParent.offset();\n\n\t\t// This is a special case where we need to modify a offset calculated on start, since the\n\t\t// following happened:\n\t\t// 1. The position of the helper is absolute, so it's position is calculated based on the\n\t\t// next positioned parent\n\t\t// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't\n\t\t// the document, which means that the scroll is included in the initial calculation of the\n\t\t// offset of the parent, and never recalculated upon drag\n\t\tif ( this.cssPosition === \"absolute\" && this.scrollParent[ 0 ] !== this.document[ 0 ] &&\n\t\t\t\t$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) {\n\t\t\tpo.left += this.scrollParent.scrollLeft();\n\t\t\tpo.top += this.scrollParent.scrollTop();\n\t\t}\n\n\t\t// This needs to be actually done for all browsers, since pageX/pageY includes this\n\t\t// information with an ugly IE fix\n\t\tif ( this.offsetParent[ 0 ] === this.document[ 0 ].body ||\n\t\t\t\t( this.offsetParent[ 0 ].tagName &&\n\t\t\t\tthis.offsetParent[ 0 ].tagName.toLowerCase() === \"html\" && $.ui.ie ) ) {\n\t\t\tpo = { top: 0, left: 0 };\n\t\t}\n\n\t\treturn {\n\t\t\ttop: po.top + ( parseInt( this.offsetParent.css( \"borderTopWidth\" ), 10 ) || 0 ),\n\t\t\tleft: po.left + ( parseInt( this.offsetParent.css( \"borderLeftWidth\" ), 10 ) || 0 )\n\t\t};\n\n\t},\n\n\t_getRelativeOffset: function() {\n\n\t\tif ( this.cssPosition === \"relative\" ) {\n\t\t\tvar p = this.currentItem.position();\n\t\t\treturn {\n\t\t\t\ttop: p.top - ( parseInt( this.helper.css( \"top\" ), 10 ) || 0 ) +\n\t\t\t\t\tthis.scrollParent.scrollTop(),\n\t\t\t\tleft: p.left - ( parseInt( this.helper.css( \"left\" ), 10 ) || 0 ) +\n\t\t\t\t\tthis.scrollParent.scrollLeft()\n\t\t\t};\n\t\t} else {\n\t\t\treturn { top: 0, left: 0 };\n\t\t}\n\n\t},\n\n\t_cacheMargins: function() {\n\t\tthis.margins = {\n\t\t\tleft: ( parseInt( this.currentItem.css( \"marginLeft\" ), 10 ) || 0 ),\n\t\t\ttop: ( parseInt( this.currentItem.css( \"marginTop\" ), 10 ) || 0 )\n\t\t};\n\t},\n\n\t_cacheHelperProportions: function() {\n\t\tthis.helperProportions = {\n\t\t\twidth: this.helper.outerWidth(),\n\t\t\theight: this.helper.outerHeight()\n\t\t};\n\t},\n\n\t_setContainment: function() {\n\n\t\tvar ce, co, over,\n\t\t\to = this.options;\n\t\tif ( o.containment === \"parent\" ) {\n\t\t\to.containment = this.helper[ 0 ].parentNode;\n\t\t}\n\t\tif ( o.containment === \"document\" || o.containment === \"window\" ) {\n\t\t\tthis.containment = [\n\t\t\t\t0 - this.offset.relative.left - this.offset.parent.left,\n\t\t\t\t0 - this.offset.relative.top - this.offset.parent.top,\n\t\t\t\to.containment === \"document\" ?\n\t\t\t\t\tthis.document.width() :\n\t\t\t\t\tthis.window.width() - this.helperProportions.width - this.margins.left,\n\t\t\t\t( o.containment === \"document\" ?\n\t\t\t\t\t( this.document.height() || document.body.parentNode.scrollHeight ) :\n\t\t\t\t\tthis.window.height() || this.document[ 0 ].body.parentNode.scrollHeight\n\t\t\t\t) - this.helperProportions.height - this.margins.top\n\t\t\t];\n\t\t}\n\n\t\tif ( !( /^(document|window|parent)$/ ).test( o.containment ) ) {\n\t\t\tce = $( o.containment )[ 0 ];\n\t\t\tco = $( o.containment ).offset();\n\t\t\tover = ( $( ce ).css( \"overflow\" ) !== \"hidden\" );\n\n\t\t\tthis.containment = [\n\t\t\t\tco.left + ( parseInt( $( ce ).css( \"borderLeftWidth\" ), 10 ) || 0 ) +\n\t\t\t\t\t( parseInt( $( ce ).css( \"paddingLeft\" ), 10 ) || 0 ) - this.margins.left,\n\t\t\t\tco.top + ( parseInt( $( ce ).css( \"borderTopWidth\" ), 10 ) || 0 ) +\n\t\t\t\t\t( parseInt( $( ce ).css( \"paddingTop\" ), 10 ) || 0 ) - this.margins.top,\n\t\t\t\tco.left + ( over ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) -\n\t\t\t\t\t( parseInt( $( ce ).css( \"borderLeftWidth\" ), 10 ) || 0 ) -\n\t\t\t\t\t( parseInt( $( ce ).css( \"paddingRight\" ), 10 ) || 0 ) -\n\t\t\t\t\tthis.helperProportions.width - this.margins.left,\n\t\t\t\tco.top + ( over ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) -\n\t\t\t\t\t( parseInt( $( ce ).css( \"borderTopWidth\" ), 10 ) || 0 ) -\n\t\t\t\t\t( parseInt( $( ce ).css( \"paddingBottom\" ), 10 ) || 0 ) -\n\t\t\t\t\tthis.helperProportions.height - this.margins.top\n\t\t\t];\n\t\t}\n\n\t},\n\n\t_convertPositionTo: function( d, pos ) {\n\n\t\tif ( !pos ) {\n\t\t\tpos = this.position;\n\t\t}\n\t\tvar mod = d === \"absolute\" ? 1 : -1,\n\t\t\tscroll = this.cssPosition === \"absolute\" &&\n\t\t\t\t!( this.scrollParent[ 0 ] !== this.document[ 0 ] &&\n\t\t\t\t$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ?\n\t\t\t\t\tthis.offsetParent :\n\t\t\t\t\tthis.scrollParent,\n\t\t\tscrollIsRootNode = ( /(html|body)/i ).test( scroll[ 0 ].tagName );\n\n\t\treturn {\n\t\t\ttop: (\n\n\t\t\t\t// The absolute mouse position\n\t\t\t\tpos.top\t+\n\n\t\t\t\t// Only for relative positioned nodes: Relative offset from element to offset parent\n\t\t\t\tthis.offset.relative.top * mod +\n\n\t\t\t\t// The offsetParent's offset without borders (offset + border)\n\t\t\t\tthis.offset.parent.top * mod -\n\t\t\t\t( ( this.cssPosition === \"fixed\" ?\n\t\t\t\t\t-this.scrollParent.scrollTop() :\n\t\t\t\t\t( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod )\n\t\t\t),\n\t\t\tleft: (\n\n\t\t\t\t// The absolute mouse position\n\t\t\t\tpos.left +\n\n\t\t\t\t// Only for relative positioned nodes: Relative offset from element to offset parent\n\t\t\t\tthis.offset.relative.left * mod +\n\n\t\t\t\t// The offsetParent's offset without borders (offset + border)\n\t\t\t\tthis.offset.parent.left * mod\t-\n\t\t\t\t( ( this.cssPosition === \"fixed\" ?\n\t\t\t\t\t-this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 :\n\t\t\t\t\tscroll.scrollLeft() ) * mod )\n\t\t\t)\n\t\t};\n\n\t},\n\n\t_generatePosition: function( event ) {\n\n\t\tvar top, left,\n\t\t\to = this.options,\n\t\t\tpageX = event.pageX,\n\t\t\tpageY = event.pageY,\n\t\t\tscroll = this.cssPosition === \"absolute\" &&\n\t\t\t\t!( this.scrollParent[ 0 ] !== this.document[ 0 ] &&\n\t\t\t\t$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ?\n\t\t\t\t\tthis.offsetParent :\n\t\t\t\t\tthis.scrollParent,\n\t\t\t\tscrollIsRootNode = ( /(html|body)/i ).test( scroll[ 0 ].tagName );\n\n\t\t// This is another very weird special case that only happens for relative elements:\n\t\t// 1. If the css position is relative\n\t\t// 2. and the scroll parent is the document or similar to the offset parent\n\t\t// we have to refresh the relative offset during the scroll so there are no jumps\n\t\tif ( this.cssPosition === \"relative\" && !( this.scrollParent[ 0 ] !== this.document[ 0 ] &&\n\t\t\t\tthis.scrollParent[ 0 ] !== this.offsetParent[ 0 ] ) ) {\n\t\t\tthis.offset.relative = this._getRelativeOffset();\n\t\t}\n\n\t\t/*\n\t\t * - Position constraining -\n\t\t * Constrain the position to a mix of grid, containment.\n\t\t */\n\n\t\tif ( this.originalPosition ) { //If we are not dragging yet, we won't check for options\n\n\t\t\tif ( this.containment ) {\n\t\t\t\tif ( event.pageX - this.offset.click.left < this.containment[ 0 ] ) {\n\t\t\t\t\tpageX = this.containment[ 0 ] + this.offset.click.left;\n\t\t\t\t}\n\t\t\t\tif ( event.pageY - this.offset.click.top < this.containment[ 1 ] ) {\n\t\t\t\t\tpageY = this.containment[ 1 ] + this.offset.click.top;\n\t\t\t\t}\n\t\t\t\tif ( event.pageX - this.offset.click.left > this.containment[ 2 ] ) {\n\t\t\t\t\tpageX = this.containment[ 2 ] + this.offset.click.left;\n\t\t\t\t}\n\t\t\t\tif ( event.pageY - this.offset.click.top > this.containment[ 3 ] ) {\n\t\t\t\t\tpageY = this.containment[ 3 ] + this.offset.click.top;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( o.grid ) {\n\t\t\t\ttop = this.originalPageY + Math.round( ( pageY - this.originalPageY ) /\n\t\t\t\t\to.grid[ 1 ] ) * o.grid[ 1 ];\n\t\t\t\tpageY = this.containment ?\n\t\t\t\t\t( ( top - this.offset.click.top >= this.containment[ 1 ] &&\n\t\t\t\t\t\ttop - this.offset.click.top <= this.containment[ 3 ] ) ?\n\t\t\t\t\t\t\ttop :\n\t\t\t\t\t\t\t( ( top - this.offset.click.top >= this.containment[ 1 ] ) ?\n\t\t\t\t\t\t\t\ttop - o.grid[ 1 ] : top + o.grid[ 1 ] ) ) :\n\t\t\t\t\t\t\t\ttop;\n\n\t\t\t\tleft = this.originalPageX + Math.round( ( pageX - this.originalPageX ) /\n\t\t\t\t\to.grid[ 0 ] ) * o.grid[ 0 ];\n\t\t\t\tpageX = this.containment ?\n\t\t\t\t\t( ( left - this.offset.click.left >= this.containment[ 0 ] &&\n\t\t\t\t\t\tleft - this.offset.click.left <= this.containment[ 2 ] ) ?\n\t\t\t\t\t\t\tleft :\n\t\t\t\t\t\t\t( ( left - this.offset.click.left >= this.containment[ 0 ] ) ?\n\t\t\t\t\t\t\t\tleft - o.grid[ 0 ] : left + o.grid[ 0 ] ) ) :\n\t\t\t\t\t\t\t\tleft;\n\t\t\t}\n\n\t\t}\n\n\t\treturn {\n\t\t\ttop: (\n\n\t\t\t\t// The absolute mouse position\n\t\t\t\tpageY -\n\n\t\t\t\t// Click offset (relative to the element)\n\t\t\t\tthis.offset.click.top -\n\n\t\t\t\t// Only for relative positioned nodes: Relative offset from element to offset parent\n\t\t\t\tthis.offset.relative.top -\n\n\t\t\t\t// The offsetParent's offset without borders (offset + border)\n\t\t\t\tthis.offset.parent.top +\n\t\t\t\t( ( this.cssPosition === \"fixed\" ?\n\t\t\t\t\t-this.scrollParent.scrollTop() :\n\t\t\t\t\t( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) )\n\t\t\t),\n\t\t\tleft: (\n\n\t\t\t\t// The absolute mouse position\n\t\t\t\tpageX -\n\n\t\t\t\t// Click offset (relative to the element)\n\t\t\t\tthis.offset.click.left -\n\n\t\t\t\t// Only for relative positioned nodes: Relative offset from element to offset parent\n\t\t\t\tthis.offset.relative.left -\n\n\t\t\t\t// The offsetParent's offset without borders (offset + border)\n\t\t\t\tthis.offset.parent.left +\n\t\t\t\t( ( this.cssPosition === \"fixed\" ?\n\t\t\t\t\t-this.scrollParent.scrollLeft() :\n\t\t\t\t\tscrollIsRootNode ? 0 : scroll.scrollLeft() ) )\n\t\t\t)\n\t\t};\n\n\t},\n\n\t_rearrange: function( event, i, a, hardRefresh ) {\n\n\t\ta ? a[ 0 ].appendChild( this.placeholder[ 0 ] ) :\n\t\t\ti.item[ 0 ].parentNode.insertBefore( this.placeholder[ 0 ],\n\t\t\t\t( this.direction === \"down\" ? i.item[ 0 ] : i.item[ 0 ].nextSibling ) );\n\n\t\t//Various things done here to improve the performance:\n\t\t// 1. we create a setTimeout, that calls refreshPositions\n\t\t// 2. on the instance, we have a counter variable, that get's higher after every append\n\t\t// 3. on the local scope, we copy the counter variable, and check in the timeout,\n\t\t// if it's still the same\n\t\t// 4. this lets only the last addition to the timeout stack through\n\t\tthis.counter = this.counter ? ++this.counter : 1;\n\t\tvar counter = this.counter;\n\n\t\tthis._delay( function() {\n\t\t\tif ( counter === this.counter ) {\n\n\t\t\t\t//Precompute after each DOM insertion, NOT on mousemove\n\t\t\t\tthis.refreshPositions( !hardRefresh );\n\t\t\t}\n\t\t} );\n\n\t},\n\n\t_clear: function( event, noPropagation ) {\n\n\t\tthis.reverting = false;\n\n\t\t// We delay all events that have to be triggered to after the point where the placeholder\n\t\t// has been removed and everything else normalized again\n\t\tvar i,\n\t\t\tdelayedTriggers = [];\n\n\t\t// We first have to update the dom position of the actual currentItem\n\t\t// Note: don't do it if the current item is already removed (by a user), or it gets\n\t\t// reappended (see #4088)\n\t\tif ( !this._noFinalSort && this.currentItem.parent().length ) {\n\t\t\tthis.placeholder.before( this.currentItem );\n\t\t}\n\t\tthis._noFinalSort = null;\n\n\t\tif ( this.helper[ 0 ] === this.currentItem[ 0 ] ) {\n\t\t\tfor ( i in this._storedCSS ) {\n\t\t\t\tif ( this._storedCSS[ i ] === \"auto\" || this._storedCSS[ i ] === \"static\" ) {\n\t\t\t\t\tthis._storedCSS[ i ] = \"\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.currentItem.css( this._storedCSS );\n\t\t\tthis._removeClass( this.currentItem, \"ui-sortable-helper\" );\n\t\t} else {\n\t\t\tthis.currentItem.show();\n\t\t}\n\n\t\tif ( this.fromOutside && !noPropagation ) {\n\t\t\tdelayedTriggers.push( function( event ) {\n\t\t\t\tthis._trigger( \"receive\", event, this._uiHash( this.fromOutside ) );\n\t\t\t} );\n\t\t}\n\t\tif ( ( this.fromOutside ||\n\t\t\t\tthis.domPosition.prev !==\n\t\t\t\tthis.currentItem.prev().not( \".ui-sortable-helper\" )[ 0 ] ||\n\t\t\t\tthis.domPosition.parent !== this.currentItem.parent()[ 0 ] ) && !noPropagation ) {\n\n\t\t\t// Trigger update callback if the DOM position has changed\n\t\t\tdelayedTriggers.push( function( event ) {\n\t\t\t\tthis._trigger( \"update\", event, this._uiHash() );\n\t\t\t} );\n\t\t}\n\n\t\t// Check if the items Container has Changed and trigger appropriate\n\t\t// events.\n\t\tif ( this !== this.currentContainer ) {\n\t\t\tif ( !noPropagation ) {\n\t\t\t\tdelayedTriggers.push( function( event ) {\n\t\t\t\t\tthis._trigger( \"remove\", event, this._uiHash() );\n\t\t\t\t} );\n\t\t\t\tdelayedTriggers.push( ( function( c ) {\n\t\t\t\t\treturn function( event ) {\n\t\t\t\t\t\tc._trigger( \"receive\", event, this._uiHash( this ) );\n\t\t\t\t\t};\n\t\t\t\t} ).call( this, this.currentContainer ) );\n\t\t\t\tdelayedTriggers.push( ( function( c ) {\n\t\t\t\t\treturn function( event ) {\n\t\t\t\t\t\tc._trigger( \"update\", event, this._uiHash( this ) );\n\t\t\t\t\t};\n\t\t\t\t} ).call( this, this.currentContainer ) );\n\t\t\t}\n\t\t}\n\n\t\t//Post events to containers\n\t\tfunction delayEvent( type, instance, container ) {\n\t\t\treturn function( event ) {\n\t\t\t\tcontainer._trigger( type, event, instance._uiHash( instance ) );\n\t\t\t};\n\t\t}\n\t\tfor ( i = this.containers.length - 1; i >= 0; i-- ) {\n\t\t\tif ( !noPropagation ) {\n\t\t\t\tdelayedTriggers.push( delayEvent( \"deactivate\", this, this.containers[ i ] ) );\n\t\t\t}\n\t\t\tif ( this.containers[ i ].containerCache.over ) {\n\t\t\t\tdelayedTriggers.push( delayEvent( \"out\", this, this.containers[ i ] ) );\n\t\t\t\tthis.containers[ i ].containerCache.over = 0;\n\t\t\t}\n\t\t}\n\n\t\t//Do what was originally in plugins\n\t\tif ( this.storedCursor ) {\n\t\t\tthis.document.find( \"body\" ).css( \"cursor\", this.storedCursor );\n\t\t\tthis.storedStylesheet.remove();\n\t\t}\n\t\tif ( this._storedOpacity ) {\n\t\t\tthis.helper.css( \"opacity\", this._storedOpacity );\n\t\t}\n\t\tif ( this._storedZIndex ) {\n\t\t\tthis.helper.css( \"zIndex\", this._storedZIndex === \"auto\" ? \"\" : this._storedZIndex );\n\t\t}\n\n\t\tthis.dragging = false;\n\n\t\tif ( !noPropagation ) {\n\t\t\tthis._trigger( \"beforeStop\", event, this._uiHash() );\n\t\t}\n\n\t\t//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately,\n\t\t// it unbinds ALL events from the original node!\n\t\tthis.placeholder[ 0 ].parentNode.removeChild( this.placeholder[ 0 ] );\n\n\t\tif ( !this.cancelHelperRemoval ) {\n\t\t\tif ( this.helper[ 0 ] !== this.currentItem[ 0 ] ) {\n\t\t\t\tthis.helper.remove();\n\t\t\t}\n\t\t\tthis.helper = null;\n\t\t}\n\n\t\tif ( !noPropagation ) {\n\t\t\tfor ( i = 0; i < delayedTriggers.length; i++ ) {\n\n\t\t\t\t// Trigger all delayed events\n\t\t\t\tdelayedTriggers[ i ].call( this, event );\n\t\t\t}\n\t\t\tthis._trigger( \"stop\", event, this._uiHash() );\n\t\t}\n\n\t\tthis.fromOutside = false;\n\t\treturn !this.cancelHelperRemoval;\n\n\t},\n\n\t_trigger: function() {\n\t\tif ( $.Widget.prototype._trigger.apply( this, arguments ) === false ) {\n\t\t\tthis.cancel();\n\t\t}\n\t},\n\n\t_uiHash: function( _inst ) {\n\t\tvar inst = _inst || this;\n\t\treturn {\n\t\t\thelper: inst.helper,\n\t\t\tplaceholder: inst.placeholder || $( [] ),\n\t\t\tposition: inst.position,\n\t\t\toriginalPosition: inst.originalPosition,\n\t\t\toffset: inst.positionAbs,\n\t\t\titem: inst.currentItem,\n\t\t\tsender: _inst ? _inst.element : null\n\t\t};\n\t}\n\n} );\n\n\n/*!\n * jQuery UI Spinner 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Spinner\n//>>group: Widgets\n//>>description: Displays buttons to easily input numbers via the keyboard or mouse.\n//>>docs: http://api.jqueryui.com/spinner/\n//>>demos: http://jqueryui.com/spinner/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/spinner.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\nfunction spinnerModifer( fn ) {\n\treturn function() {\n\t\tvar previous = this.element.val();\n\t\tfn.apply( this, arguments );\n\t\tthis._refresh();\n\t\tif ( previous !== this.element.val() ) {\n\t\t\tthis._trigger( \"change\" );\n\t\t}\n\t};\n}\n\n$.widget( \"ui.spinner\", {\n\tversion: \"1.12.1\",\n\tdefaultElement: \"<input>\",\n\twidgetEventPrefix: \"spin\",\n\toptions: {\n\t\tclasses: {\n\t\t\t\"ui-spinner\": \"ui-corner-all\",\n\t\t\t\"ui-spinner-down\": \"ui-corner-br\",\n\t\t\t\"ui-spinner-up\": \"ui-corner-tr\"\n\t\t},\n\t\tculture: null,\n\t\ticons: {\n\t\t\tdown: \"ui-icon-triangle-1-s\",\n\t\t\tup: \"ui-icon-triangle-1-n\"\n\t\t},\n\t\tincremental: true,\n\t\tmax: null,\n\t\tmin: null,\n\t\tnumberFormat: null,\n\t\tpage: 10,\n\t\tstep: 1,\n\n\t\tchange: null,\n\t\tspin: null,\n\t\tstart: null,\n\t\tstop: null\n\t},\n\n\t_create: function() {\n\n\t\t// handle string values that need to be parsed\n\t\tthis._setOption( \"max\", this.options.max );\n\t\tthis._setOption( \"min\", this.options.min );\n\t\tthis._setOption( \"step\", this.options.step );\n\n\t\t// Only format if there is a value, prevents the field from being marked\n\t\t// as invalid in Firefox, see #9573.\n\t\tif ( this.value() !== \"\" ) {\n\n\t\t\t// Format the value, but don't constrain.\n\t\t\tthis._value( this.element.val(), true );\n\t\t}\n\n\t\tthis._draw();\n\t\tthis._on( this._events );\n\t\tthis._refresh();\n\n\t\t// Turning off autocomplete prevents the browser from remembering the\n\t\t// value when navigating through history, so we re-enable autocomplete\n\t\t// if the page is unloaded before the widget is destroyed. #7790\n\t\tthis._on( this.window, {\n\t\t\tbeforeunload: function() {\n\t\t\t\tthis.element.removeAttr( \"autocomplete\" );\n\t\t\t}\n\t\t} );\n\t},\n\n\t_getCreateOptions: function() {\n\t\tvar options = this._super();\n\t\tvar element = this.element;\n\n\t\t$.each( [ \"min\", \"max\", \"step\" ], function( i, option ) {\n\t\t\tvar value = element.attr( option );\n\t\t\tif ( value != null && value.length ) {\n\t\t\t\toptions[ option ] = value;\n\t\t\t}\n\t\t} );\n\n\t\treturn options;\n\t},\n\n\t_events: {\n\t\tkeydown: function( event ) {\n\t\t\tif ( this._start( event ) && this._keydown( event ) ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t},\n\t\tkeyup: \"_stop\",\n\t\tfocus: function() {\n\t\t\tthis.previous = this.element.val();\n\t\t},\n\t\tblur: function( event ) {\n\t\t\tif ( this.cancelBlur ) {\n\t\t\t\tdelete this.cancelBlur;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis._stop();\n\t\t\tthis._refresh();\n\t\t\tif ( this.previous !== this.element.val() ) {\n\t\t\t\tthis._trigger( \"change\", event );\n\t\t\t}\n\t\t},\n\t\tmousewheel: function( event, delta ) {\n\t\t\tif ( !delta ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( !this.spinning && !this._start( event ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tthis._spin( ( delta > 0 ? 1 : -1 ) * this.options.step, event );\n\t\t\tclearTimeout( this.mousewheelTimer );\n\t\t\tthis.mousewheelTimer = this._delay( function() {\n\t\t\t\tif ( this.spinning ) {\n\t\t\t\t\tthis._stop( event );\n\t\t\t\t}\n\t\t\t}, 100 );\n\t\t\tevent.preventDefault();\n\t\t},\n\t\t\"mousedown .ui-spinner-button\": function( event ) {\n\t\t\tvar previous;\n\n\t\t\t// We never want the buttons to have focus; whenever the user is\n\t\t\t// interacting with the spinner, the focus should be on the input.\n\t\t\t// If the input is focused then this.previous is properly set from\n\t\t\t// when the input first received focus. If the input is not focused\n\t\t\t// then we need to set this.previous based on the value before spinning.\n\t\t\tprevious = this.element[ 0 ] === $.ui.safeActiveElement( this.document[ 0 ] ) ?\n\t\t\t\tthis.previous : this.element.val();\n\t\t\tfunction checkFocus() {\n\t\t\t\tvar isActive = this.element[ 0 ] === $.ui.safeActiveElement( this.document[ 0 ] );\n\t\t\t\tif ( !isActive ) {\n\t\t\t\t\tthis.element.trigger( \"focus\" );\n\t\t\t\t\tthis.previous = previous;\n\n\t\t\t\t\t// support: IE\n\t\t\t\t\t// IE sets focus asynchronously, so we need to check if focus\n\t\t\t\t\t// moved off of the input because the user clicked on the button.\n\t\t\t\t\tthis._delay( function() {\n\t\t\t\t\t\tthis.previous = previous;\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Ensure focus is on (or stays on) the text field\n\t\t\tevent.preventDefault();\n\t\t\tcheckFocus.call( this );\n\n\t\t\t// Support: IE\n\t\t\t// IE doesn't prevent moving focus even with event.preventDefault()\n\t\t\t// so we set a flag to know when we should ignore the blur event\n\t\t\t// and check (again) if focus moved off of the input.\n\t\t\tthis.cancelBlur = true;\n\t\t\tthis._delay( function() {\n\t\t\t\tdelete this.cancelBlur;\n\t\t\t\tcheckFocus.call( this );\n\t\t\t} );\n\n\t\t\tif ( this._start( event ) === false ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis._repeat( null, $( event.currentTarget )\n\t\t\t\t.hasClass( \"ui-spinner-up\" ) ? 1 : -1, event );\n\t\t},\n\t\t\"mouseup .ui-spinner-button\": \"_stop\",\n\t\t\"mouseenter .ui-spinner-button\": function( event ) {\n\n\t\t\t// button will add ui-state-active if mouse was down while mouseleave and kept down\n\t\t\tif ( !$( event.currentTarget ).hasClass( \"ui-state-active\" ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( this._start( event ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis._repeat( null, $( event.currentTarget )\n\t\t\t\t.hasClass( \"ui-spinner-up\" ) ? 1 : -1, event );\n\t\t},\n\n\t\t// TODO: do we really want to consider this a stop?\n\t\t// shouldn't we just stop the repeater and wait until mouseup before\n\t\t// we trigger the stop event?\n\t\t\"mouseleave .ui-spinner-button\": \"_stop\"\n\t},\n\n\t// Support mobile enhanced option and make backcompat more sane\n\t_enhance: function() {\n\t\tthis.uiSpinner = this.element\n\t\t\t.attr( \"autocomplete\", \"off\" )\n\t\t\t.wrap( \"<span>\" )\n\t\t\t.parent()\n\n\t\t\t\t// Add buttons\n\t\t\t\t.append(\n\t\t\t\t\t\"<a></a><a></a>\"\n\t\t\t\t);\n\t},\n\n\t_draw: function() {\n\t\tthis._enhance();\n\n\t\tthis._addClass( this.uiSpinner, \"ui-spinner\", \"ui-widget ui-widget-content\" );\n\t\tthis._addClass( \"ui-spinner-input\" );\n\n\t\tthis.element.attr( \"role\", \"spinbutton\" );\n\n\t\t// Button bindings\n\t\tthis.buttons = this.uiSpinner.children( \"a\" )\n\t\t\t.attr( \"tabIndex\", -1 )\n\t\t\t.attr( \"aria-hidden\", true )\n\t\t\t.button( {\n\t\t\t\tclasses: {\n\t\t\t\t\t\"ui-button\": \"\"\n\t\t\t\t}\n\t\t\t} );\n\n\t\t// TODO: Right now button does not support classes this is already updated in button PR\n\t\tthis._removeClass( this.buttons, \"ui-corner-all\" );\n\n\t\tthis._addClass( this.buttons.first(), \"ui-spinner-button ui-spinner-up\" );\n\t\tthis._addClass( this.buttons.last(), \"ui-spinner-button ui-spinner-down\" );\n\t\tthis.buttons.first().button( {\n\t\t\t\"icon\": this.options.icons.up,\n\t\t\t\"showLabel\": false\n\t\t} );\n\t\tthis.buttons.last().button( {\n\t\t\t\"icon\": this.options.icons.down,\n\t\t\t\"showLabel\": false\n\t\t} );\n\n\t\t// IE 6 doesn't understand height: 50% for the buttons\n\t\t// unless the wrapper has an explicit height\n\t\tif ( this.buttons.height() > Math.ceil( this.uiSpinner.height() * 0.5 ) &&\n\t\t\t\tthis.uiSpinner.height() > 0 ) {\n\t\t\tthis.uiSpinner.height( this.uiSpinner.height() );\n\t\t}\n\t},\n\n\t_keydown: function( event ) {\n\t\tvar options = this.options,\n\t\t\tkeyCode = $.ui.keyCode;\n\n\t\tswitch ( event.keyCode ) {\n\t\tcase keyCode.UP:\n\t\t\tthis._repeat( null, 1, event );\n\t\t\treturn true;\n\t\tcase keyCode.DOWN:\n\t\t\tthis._repeat( null, -1, event );\n\t\t\treturn true;\n\t\tcase keyCode.PAGE_UP:\n\t\t\tthis._repeat( null, options.page, event );\n\t\t\treturn true;\n\t\tcase keyCode.PAGE_DOWN:\n\t\t\tthis._repeat( null, -options.page, event );\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t},\n\n\t_start: function( event ) {\n\t\tif ( !this.spinning && this._trigger( \"start\", event ) === false ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( !this.counter ) {\n\t\t\tthis.counter = 1;\n\t\t}\n\t\tthis.spinning = true;\n\t\treturn true;\n\t},\n\n\t_repeat: function( i, steps, event ) {\n\t\ti = i || 500;\n\n\t\tclearTimeout( this.timer );\n\t\tthis.timer = this._delay( function() {\n\t\t\tthis._repeat( 40, steps, event );\n\t\t}, i );\n\n\t\tthis._spin( steps * this.options.step, event );\n\t},\n\n\t_spin: function( step, event ) {\n\t\tvar value = this.value() || 0;\n\n\t\tif ( !this.counter ) {\n\t\t\tthis.counter = 1;\n\t\t}\n\n\t\tvalue = this._adjustValue( value + step * this._increment( this.counter ) );\n\n\t\tif ( !this.spinning || this._trigger( \"spin\", event, { value: value } ) !== false ) {\n\t\t\tthis._value( value );\n\t\t\tthis.counter++;\n\t\t}\n\t},\n\n\t_increment: function( i ) {\n\t\tvar incremental = this.options.incremental;\n\n\t\tif ( incremental ) {\n\t\t\treturn $.isFunction( incremental ) ?\n\t\t\t\tincremental( i ) :\n\t\t\t\tMath.floor( i * i * i / 50000 - i * i / 500 + 17 * i / 200 + 1 );\n\t\t}\n\n\t\treturn 1;\n\t},\n\n\t_precision: function() {\n\t\tvar precision = this._precisionOf( this.options.step );\n\t\tif ( this.options.min !== null ) {\n\t\t\tprecision = Math.max( precision, this._precisionOf( this.options.min ) );\n\t\t}\n\t\treturn precision;\n\t},\n\n\t_precisionOf: function( num ) {\n\t\tvar str = num.toString(),\n\t\t\tdecimal = str.indexOf( \".\" );\n\t\treturn decimal === -1 ? 0 : str.length - decimal - 1;\n\t},\n\n\t_adjustValue: function( value ) {\n\t\tvar base, aboveMin,\n\t\t\toptions = this.options;\n\n\t\t// Make sure we're at a valid step\n\t\t// - find out where we are relative to the base (min or 0)\n\t\tbase = options.min !== null ? options.min : 0;\n\t\taboveMin = value - base;\n\n\t\t// - round to the nearest step\n\t\taboveMin = Math.round( aboveMin / options.step ) * options.step;\n\n\t\t// - rounding is based on 0, so adjust back to our base\n\t\tvalue = base + aboveMin;\n\n\t\t// Fix precision from bad JS floating point math\n\t\tvalue = parseFloat( value.toFixed( this._precision() ) );\n\n\t\t// Clamp the value\n\t\tif ( options.max !== null && value > options.max ) {\n\t\t\treturn options.max;\n\t\t}\n\t\tif ( options.min !== null && value < options.min ) {\n\t\t\treturn options.min;\n\t\t}\n\n\t\treturn value;\n\t},\n\n\t_stop: function( event ) {\n\t\tif ( !this.spinning ) {\n\t\t\treturn;\n\t\t}\n\n\t\tclearTimeout( this.timer );\n\t\tclearTimeout( this.mousewheelTimer );\n\t\tthis.counter = 0;\n\t\tthis.spinning = false;\n\t\tthis._trigger( \"stop\", event );\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tvar prevValue, first, last;\n\n\t\tif ( key === \"culture\" || key === \"numberFormat\" ) {\n\t\t\tprevValue = this._parse( this.element.val() );\n\t\t\tthis.options[ key ] = value;\n\t\t\tthis.element.val( this._format( prevValue ) );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( key === \"max\" || key === \"min\" || key === \"step\" ) {\n\t\t\tif ( typeof value === \"string\" ) {\n\t\t\t\tvalue = this._parse( value );\n\t\t\t}\n\t\t}\n\t\tif ( key === \"icons\" ) {\n\t\t\tfirst = this.buttons.first().find( \".ui-icon\" );\n\t\t\tthis._removeClass( first, null, this.options.icons.up );\n\t\t\tthis._addClass( first, null, value.up );\n\t\t\tlast = this.buttons.last().find( \".ui-icon\" );\n\t\t\tthis._removeClass( last, null, this.options.icons.down );\n\t\t\tthis._addClass( last, null, value.down );\n\t\t}\n\n\t\tthis._super( key, value );\n\t},\n\n\t_setOptionDisabled: function( value ) {\n\t\tthis._super( value );\n\n\t\tthis._toggleClass( this.uiSpinner, null, \"ui-state-disabled\", !!value );\n\t\tthis.element.prop( \"disabled\", !!value );\n\t\tthis.buttons.button( value ? \"disable\" : \"enable\" );\n\t},\n\n\t_setOptions: spinnerModifer( function( options ) {\n\t\tthis._super( options );\n\t} ),\n\n\t_parse: function( val ) {\n\t\tif ( typeof val === \"string\" && val !== \"\" ) {\n\t\t\tval = window.Globalize && this.options.numberFormat ?\n\t\t\t\tGlobalize.parseFloat( val, 10, this.options.culture ) : +val;\n\t\t}\n\t\treturn val === \"\" || isNaN( val ) ? null : val;\n\t},\n\n\t_format: function( value ) {\n\t\tif ( value === \"\" ) {\n\t\t\treturn \"\";\n\t\t}\n\t\treturn window.Globalize && this.options.numberFormat ?\n\t\t\tGlobalize.format( value, this.options.numberFormat, this.options.culture ) :\n\t\t\tvalue;\n\t},\n\n\t_refresh: function() {\n\t\tthis.element.attr( {\n\t\t\t\"aria-valuemin\": this.options.min,\n\t\t\t\"aria-valuemax\": this.options.max,\n\n\t\t\t// TODO: what should we do with values that can't be parsed?\n\t\t\t\"aria-valuenow\": this._parse( this.element.val() )\n\t\t} );\n\t},\n\n\tisValid: function() {\n\t\tvar value = this.value();\n\n\t\t// Null is invalid\n\t\tif ( value === null ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// If value gets adjusted, it's invalid\n\t\treturn value === this._adjustValue( value );\n\t},\n\n\t// Update the value without triggering change\n\t_value: function( value, allowAny ) {\n\t\tvar parsed;\n\t\tif ( value !== \"\" ) {\n\t\t\tparsed = this._parse( value );\n\t\t\tif ( parsed !== null ) {\n\t\t\t\tif ( !allowAny ) {\n\t\t\t\t\tparsed = this._adjustValue( parsed );\n\t\t\t\t}\n\t\t\t\tvalue = this._format( parsed );\n\t\t\t}\n\t\t}\n\t\tthis.element.val( value );\n\t\tthis._refresh();\n\t},\n\n\t_destroy: function() {\n\t\tthis.element\n\t\t\t.prop( \"disabled\", false )\n\t\t\t.removeAttr( \"autocomplete role aria-valuemin aria-valuemax aria-valuenow\" );\n\n\t\tthis.uiSpinner.replaceWith( this.element );\n\t},\n\n\tstepUp: spinnerModifer( function( steps ) {\n\t\tthis._stepUp( steps );\n\t} ),\n\t_stepUp: function( steps ) {\n\t\tif ( this._start() ) {\n\t\t\tthis._spin( ( steps || 1 ) * this.options.step );\n\t\t\tthis._stop();\n\t\t}\n\t},\n\n\tstepDown: spinnerModifer( function( steps ) {\n\t\tthis._stepDown( steps );\n\t} ),\n\t_stepDown: function( steps ) {\n\t\tif ( this._start() ) {\n\t\t\tthis._spin( ( steps || 1 ) * -this.options.step );\n\t\t\tthis._stop();\n\t\t}\n\t},\n\n\tpageUp: spinnerModifer( function( pages ) {\n\t\tthis._stepUp( ( pages || 1 ) * this.options.page );\n\t} ),\n\n\tpageDown: spinnerModifer( function( pages ) {\n\t\tthis._stepDown( ( pages || 1 ) * this.options.page );\n\t} ),\n\n\tvalue: function( newVal ) {\n\t\tif ( !arguments.length ) {\n\t\t\treturn this._parse( this.element.val() );\n\t\t}\n\t\tspinnerModifer( this._value ).call( this, newVal );\n\t},\n\n\twidget: function() {\n\t\treturn this.uiSpinner;\n\t}\n} );\n\n// DEPRECATED\n// TODO: switch return back to widget declaration at top of file when this is removed\nif ( $.uiBackCompat !== false ) {\n\n\t// Backcompat for spinner html extension points\n\t$.widget( \"ui.spinner\", $.ui.spinner, {\n\t\t_enhance: function() {\n\t\t\tthis.uiSpinner = this.element\n\t\t\t\t.attr( \"autocomplete\", \"off\" )\n\t\t\t\t.wrap( this._uiSpinnerHtml() )\n\t\t\t\t.parent()\n\n\t\t\t\t\t// Add buttons\n\t\t\t\t\t.append( this._buttonHtml() );\n\t\t},\n\t\t_uiSpinnerHtml: function() {\n\t\t\treturn \"<span>\";\n\t\t},\n\n\t\t_buttonHtml: function() {\n\t\t\treturn \"<a></a><a></a>\";\n\t\t}\n\t} );\n}\n\nvar widgetsSpinner = $.ui.spinner;\n\n\n/*!\n * jQuery UI Tabs 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Tabs\n//>>group: Widgets\n//>>description: Transforms a set of container elements into a tab structure.\n//>>docs: http://api.jqueryui.com/tabs/\n//>>demos: http://jqueryui.com/tabs/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/tabs.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\n$.widget( \"ui.tabs\", {\n\tversion: \"1.12.1\",\n\tdelay: 300,\n\toptions: {\n\t\tactive: null,\n\t\tclasses: {\n\t\t\t\"ui-tabs\": \"ui-corner-all\",\n\t\t\t\"ui-tabs-nav\": \"ui-corner-all\",\n\t\t\t\"ui-tabs-panel\": \"ui-corner-bottom\",\n\t\t\t\"ui-tabs-tab\": \"ui-corner-top\"\n\t\t},\n\t\tcollapsible: false,\n\t\tevent: \"click\",\n\t\theightStyle: \"content\",\n\t\thide: null,\n\t\tshow: null,\n\n\t\t// Callbacks\n\t\tactivate: null,\n\t\tbeforeActivate: null,\n\t\tbeforeLoad: null,\n\t\tload: null\n\t},\n\n\t_isLocal: ( function() {\n\t\tvar rhash = /#.*$/;\n\n\t\treturn function( anchor ) {\n\t\t\tvar anchorUrl, locationUrl;\n\n\t\t\tanchorUrl = anchor.href.replace( rhash, \"\" );\n\t\t\tlocationUrl = location.href.replace( rhash, \"\" );\n\n\t\t\t// Decoding may throw an error if the URL isn't UTF-8 (#9518)\n\t\t\ttry {\n\t\t\t\tanchorUrl = decodeURIComponent( anchorUrl );\n\t\t\t} catch ( error ) {}\n\t\t\ttry {\n\t\t\t\tlocationUrl = decodeURIComponent( locationUrl );\n\t\t\t} catch ( error ) {}\n\n\t\t\treturn anchor.hash.length > 1 && anchorUrl === locationUrl;\n\t\t};\n\t} )(),\n\n\t_create: function() {\n\t\tvar that = this,\n\t\t\toptions = this.options;\n\n\t\tthis.running = false;\n\n\t\tthis._addClass( \"ui-tabs\", \"ui-widget ui-widget-content\" );\n\t\tthis._toggleClass( \"ui-tabs-collapsible\", null, options.collapsible );\n\n\t\tthis._processTabs();\n\t\toptions.active = this._initialActive();\n\n\t\t// Take disabling tabs via class attribute from HTML\n\t\t// into account and update option properly.\n\t\tif ( $.isArray( options.disabled ) ) {\n\t\t\toptions.disabled = $.unique( options.disabled.concat(\n\t\t\t\t$.map( this.tabs.filter( \".ui-state-disabled\" ), function( li ) {\n\t\t\t\t\treturn that.tabs.index( li );\n\t\t\t\t} )\n\t\t\t) ).sort();\n\t\t}\n\n\t\t// Check for length avoids error when initializing empty list\n\t\tif ( this.options.active !== false && this.anchors.length ) {\n\t\t\tthis.active = this._findActive( options.active );\n\t\t} else {\n\t\t\tthis.active = $();\n\t\t}\n\n\t\tthis._refresh();\n\n\t\tif ( this.active.length ) {\n\t\t\tthis.load( options.active );\n\t\t}\n\t},\n\n\t_initialActive: function() {\n\t\tvar active = this.options.active,\n\t\t\tcollapsible = this.options.collapsible,\n\t\t\tlocationHash = location.hash.substring( 1 );\n\n\t\tif ( active === null ) {\n\n\t\t\t// check the fragment identifier in the URL\n\t\t\tif ( locationHash ) {\n\t\t\t\tthis.tabs.each( function( i, tab ) {\n\t\t\t\t\tif ( $( tab ).attr( \"aria-controls\" ) === locationHash ) {\n\t\t\t\t\t\tactive = i;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\t// Check for a tab marked active via a class\n\t\t\tif ( active === null ) {\n\t\t\t\tactive = this.tabs.index( this.tabs.filter( \".ui-tabs-active\" ) );\n\t\t\t}\n\n\t\t\t// No active tab, set to false\n\t\t\tif ( active === null || active === -1 ) {\n\t\t\t\tactive = this.tabs.length ? 0 : false;\n\t\t\t}\n\t\t}\n\n\t\t// Handle numbers: negative, out of range\n\t\tif ( active !== false ) {\n\t\t\tactive = this.tabs.index( this.tabs.eq( active ) );\n\t\t\tif ( active === -1 ) {\n\t\t\t\tactive = collapsible ? false : 0;\n\t\t\t}\n\t\t}\n\n\t\t// Don't allow collapsible: false and active: false\n\t\tif ( !collapsible && active === false && this.anchors.length ) {\n\t\t\tactive = 0;\n\t\t}\n\n\t\treturn active;\n\t},\n\n\t_getCreateEventData: function() {\n\t\treturn {\n\t\t\ttab: this.active,\n\t\t\tpanel: !this.active.length ? $() : this._getPanelForTab( this.active )\n\t\t};\n\t},\n\n\t_tabKeydown: function( event ) {\n\t\tvar focusedTab = $( $.ui.safeActiveElement( this.document[ 0 ] ) ).closest( \"li\" ),\n\t\t\tselectedIndex = this.tabs.index( focusedTab ),\n\t\t\tgoingForward = true;\n\n\t\tif ( this._handlePageNav( event ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( event.keyCode ) {\n\t\tcase $.ui.keyCode.RIGHT:\n\t\tcase $.ui.keyCode.DOWN:\n\t\t\tselectedIndex++;\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.UP:\n\t\tcase $.ui.keyCode.LEFT:\n\t\t\tgoingForward = false;\n\t\t\tselectedIndex--;\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.END:\n\t\t\tselectedIndex = this.anchors.length - 1;\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.HOME:\n\t\t\tselectedIndex = 0;\n\t\t\tbreak;\n\t\tcase $.ui.keyCode.SPACE:\n\n\t\t\t// Activate only, no collapsing\n\t\t\tevent.preventDefault();\n\t\t\tclearTimeout( this.activating );\n\t\t\tthis._activate( selectedIndex );\n\t\t\treturn;\n\t\tcase $.ui.keyCode.ENTER:\n\n\t\t\t// Toggle (cancel delayed activation, allow collapsing)\n\t\t\tevent.preventDefault();\n\t\t\tclearTimeout( this.activating );\n\n\t\t\t// Determine if we should collapse or activate\n\t\t\tthis._activate( selectedIndex === this.options.active ? false : selectedIndex );\n\t\t\treturn;\n\t\tdefault:\n\t\t\treturn;\n\t\t}\n\n\t\t// Focus the appropriate tab, based on which key was pressed\n\t\tevent.preventDefault();\n\t\tclearTimeout( this.activating );\n\t\tselectedIndex = this._focusNextTab( selectedIndex, goingForward );\n\n\t\t// Navigating with control/command key will prevent automatic activation\n\t\tif ( !event.ctrlKey && !event.metaKey ) {\n\n\t\t\t// Update aria-selected immediately so that AT think the tab is already selected.\n\t\t\t// Otherwise AT may confuse the user by stating that they need to activate the tab,\n\t\t\t// but the tab will already be activated by the time the announcement finishes.\n\t\t\tfocusedTab.attr( \"aria-selected\", \"false\" );\n\t\t\tthis.tabs.eq( selectedIndex ).attr( \"aria-selected\", \"true\" );\n\n\t\t\tthis.activating = this._delay( function() {\n\t\t\t\tthis.option( \"active\", selectedIndex );\n\t\t\t}, this.delay );\n\t\t}\n\t},\n\n\t_panelKeydown: function( event ) {\n\t\tif ( this._handlePageNav( event ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+up moves focus to the current tab\n\t\tif ( event.ctrlKey && event.keyCode === $.ui.keyCode.UP ) {\n\t\t\tevent.preventDefault();\n\t\t\tthis.active.trigger( \"focus\" );\n\t\t}\n\t},\n\n\t// Alt+page up/down moves focus to the previous/next tab (and activates)\n\t_handlePageNav: function( event ) {\n\t\tif ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_UP ) {\n\t\t\tthis._activate( this._focusNextTab( this.options.active - 1, false ) );\n\t\t\treturn true;\n\t\t}\n\t\tif ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_DOWN ) {\n\t\t\tthis._activate( this._focusNextTab( this.options.active + 1, true ) );\n\t\t\treturn true;\n\t\t}\n\t},\n\n\t_findNextTab: function( index, goingForward ) {\n\t\tvar lastTabIndex = this.tabs.length - 1;\n\n\t\tfunction constrain() {\n\t\t\tif ( index > lastTabIndex ) {\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t\tif ( index < 0 ) {\n\t\t\t\tindex = lastTabIndex;\n\t\t\t}\n\t\t\treturn index;\n\t\t}\n\n\t\twhile ( $.inArray( constrain(), this.options.disabled ) !== -1 ) {\n\t\t\tindex = goingForward ? index + 1 : index - 1;\n\t\t}\n\n\t\treturn index;\n\t},\n\n\t_focusNextTab: function( index, goingForward ) {\n\t\tindex = this._findNextTab( index, goingForward );\n\t\tthis.tabs.eq( index ).trigger( \"focus\" );\n\t\treturn index;\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tif ( key === \"active\" ) {\n\n\t\t\t// _activate() will handle invalid values and update this.options\n\t\t\tthis._activate( value );\n\t\t\treturn;\n\t\t}\n\n\t\tthis._super( key, value );\n\n\t\tif ( key === \"collapsible\" ) {\n\t\t\tthis._toggleClass( \"ui-tabs-collapsible\", null, value );\n\n\t\t\t// Setting collapsible: false while collapsed; open first panel\n\t\t\tif ( !value && this.options.active === false ) {\n\t\t\t\tthis._activate( 0 );\n\t\t\t}\n\t\t}\n\n\t\tif ( key === \"event\" ) {\n\t\t\tthis._setupEvents( value );\n\t\t}\n\n\t\tif ( key === \"heightStyle\" ) {\n\t\t\tthis._setupHeightStyle( value );\n\t\t}\n\t},\n\n\t_sanitizeSelector: function( hash ) {\n\t\treturn hash ? hash.replace( /[!\"$%&'()*+,.\\/:;<=>?@\\[\\]\\^`{|}~]/g, \"\\\\$&\" ) : \"\";\n\t},\n\n\trefresh: function() {\n\t\tvar options = this.options,\n\t\t\tlis = this.tablist.children( \":has(a[href])\" );\n\n\t\t// Get disabled tabs from class attribute from HTML\n\t\t// this will get converted to a boolean if needed in _refresh()\n\t\toptions.disabled = $.map( lis.filter( \".ui-state-disabled\" ), function( tab ) {\n\t\t\treturn lis.index( tab );\n\t\t} );\n\n\t\tthis._processTabs();\n\n\t\t// Was collapsed or no tabs\n\t\tif ( options.active === false || !this.anchors.length ) {\n\t\t\toptions.active = false;\n\t\t\tthis.active = $();\n\n\t\t// was active, but active tab is gone\n\t\t} else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) {\n\n\t\t\t// all remaining tabs are disabled\n\t\t\tif ( this.tabs.length === options.disabled.length ) {\n\t\t\t\toptions.active = false;\n\t\t\t\tthis.active = $();\n\n\t\t\t// activate previous tab\n\t\t\t} else {\n\t\t\t\tthis._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) );\n\t\t\t}\n\n\t\t// was active, active tab still exists\n\t\t} else {\n\n\t\t\t// make sure active index is correct\n\t\t\toptions.active = this.tabs.index( this.active );\n\t\t}\n\n\t\tthis._refresh();\n\t},\n\n\t_refresh: function() {\n\t\tthis._setOptionDisabled( this.options.disabled );\n\t\tthis._setupEvents( this.options.event );\n\t\tthis._setupHeightStyle( this.options.heightStyle );\n\n\t\tthis.tabs.not( this.active ).attr( {\n\t\t\t\"aria-selected\": \"false\",\n\t\t\t\"aria-expanded\": \"false\",\n\t\t\ttabIndex: -1\n\t\t} );\n\t\tthis.panels.not( this._getPanelForTab( this.active ) )\n\t\t\t.hide()\n\t\t\t.attr( {\n\t\t\t\t\"aria-hidden\": \"true\"\n\t\t\t} );\n\n\t\t// Make sure one tab is in the tab order\n\t\tif ( !this.active.length ) {\n\t\t\tthis.tabs.eq( 0 ).attr( \"tabIndex\", 0 );\n\t\t} else {\n\t\t\tthis.active\n\t\t\t\t.attr( {\n\t\t\t\t\t\"aria-selected\": \"true\",\n\t\t\t\t\t\"aria-expanded\": \"true\",\n\t\t\t\t\ttabIndex: 0\n\t\t\t\t} );\n\t\t\tthis._addClass( this.active, \"ui-tabs-active\", \"ui-state-active\" );\n\t\t\tthis._getPanelForTab( this.active )\n\t\t\t\t.show()\n\t\t\t\t.attr( {\n\t\t\t\t\t\"aria-hidden\": \"false\"\n\t\t\t\t} );\n\t\t}\n\t},\n\n\t_processTabs: function() {\n\t\tvar that = this,\n\t\t\tprevTabs = this.tabs,\n\t\t\tprevAnchors = this.anchors,\n\t\t\tprevPanels = this.panels;\n\n\t\tthis.tablist = this._getList().attr( \"role\", \"tablist\" );\n\t\tthis._addClass( this.tablist, \"ui-tabs-nav\",\n\t\t\t\"ui-helper-reset ui-helper-clearfix ui-widget-header\" );\n\n\t\t// Prevent users from focusing disabled tabs via click\n\t\tthis.tablist\n\t\t\t.on( \"mousedown\" + this.eventNamespace, \"> li\", function( event ) {\n\t\t\t\tif ( $( this ).is( \".ui-state-disabled\" ) ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} )\n\n\t\t\t// Support: IE <9\n\t\t\t// Preventing the default action in mousedown doesn't prevent IE\n\t\t\t// from focusing the element, so if the anchor gets focused, blur.\n\t\t\t// We don't have to worry about focusing the previously focused\n\t\t\t// element since clicking on a non-focusable element should focus\n\t\t\t// the body anyway.\n\t\t\t.on( \"focus\" + this.eventNamespace, \".ui-tabs-anchor\", function() {\n\t\t\t\tif ( $( this ).closest( \"li\" ).is( \".ui-state-disabled\" ) ) {\n\t\t\t\t\tthis.blur();\n\t\t\t\t}\n\t\t\t} );\n\n\t\tthis.tabs = this.tablist.find( \"> li:has(a[href])\" )\n\t\t\t.attr( {\n\t\t\t\trole: \"tab\",\n\t\t\t\ttabIndex: -1\n\t\t\t} );\n\t\tthis._addClass( this.tabs, \"ui-tabs-tab\", \"ui-state-default\" );\n\n\t\tthis.anchors = this.tabs.map( function() {\n\t\t\treturn $( \"a\", this )[ 0 ];\n\t\t} )\n\t\t\t.attr( {\n\t\t\t\trole: \"presentation\",\n\t\t\t\ttabIndex: -1\n\t\t\t} );\n\t\tthis._addClass( this.anchors, \"ui-tabs-anchor\" );\n\n\t\tthis.panels = $();\n\n\t\tthis.anchors.each( function( i, anchor ) {\n\t\t\tvar selector, panel, panelId,\n\t\t\t\tanchorId = $( anchor ).uniqueId().attr( \"id\" ),\n\t\t\t\ttab = $( anchor ).closest( \"li\" ),\n\t\t\t\toriginalAriaControls = tab.attr( \"aria-controls\" );\n\n\t\t\t// Inline tab\n\t\t\tif ( that._isLocal( anchor ) ) {\n\t\t\t\tselector = anchor.hash;\n\t\t\t\tpanelId = selector.substring( 1 );\n\t\t\t\tpanel = that.element.find( that._sanitizeSelector( selector ) );\n\n\t\t\t// remote tab\n\t\t\t} else {\n\n\t\t\t\t// If the tab doesn't already have aria-controls,\n\t\t\t\t// generate an id by using a throw-away element\n\t\t\t\tpanelId = tab.attr( \"aria-controls\" ) || $( {} ).uniqueId()[ 0 ].id;\n\t\t\t\tselector = \"#\" + panelId;\n\t\t\t\tpanel = that.element.find( selector );\n\t\t\t\tif ( !panel.length ) {\n\t\t\t\t\tpanel = that._createPanel( panelId );\n\t\t\t\t\tpanel.insertAfter( that.panels[ i - 1 ] || that.tablist );\n\t\t\t\t}\n\t\t\t\tpanel.attr( \"aria-live\", \"polite\" );\n\t\t\t}\n\n\t\t\tif ( panel.length ) {\n\t\t\t\tthat.panels = that.panels.add( panel );\n\t\t\t}\n\t\t\tif ( originalAriaControls ) {\n\t\t\t\ttab.data( \"ui-tabs-aria-controls\", originalAriaControls );\n\t\t\t}\n\t\t\ttab.attr( {\n\t\t\t\t\"aria-controls\": panelId,\n\t\t\t\t\"aria-labelledby\": anchorId\n\t\t\t} );\n\t\t\tpanel.attr( \"aria-labelledby\", anchorId );\n\t\t} );\n\n\t\tthis.panels.attr( \"role\", \"tabpanel\" );\n\t\tthis._addClass( this.panels, \"ui-tabs-panel\", \"ui-widget-content\" );\n\n\t\t// Avoid memory leaks (#10056)\n\t\tif ( prevTabs ) {\n\t\t\tthis._off( prevTabs.not( this.tabs ) );\n\t\t\tthis._off( prevAnchors.not( this.anchors ) );\n\t\t\tthis._off( prevPanels.not( this.panels ) );\n\t\t}\n\t},\n\n\t// Allow overriding how to find the list for rare usage scenarios (#7715)\n\t_getList: function() {\n\t\treturn this.tablist || this.element.find( \"ol, ul\" ).eq( 0 );\n\t},\n\n\t_createPanel: function( id ) {\n\t\treturn $( \"<div>\" )\n\t\t\t.attr( \"id\", id )\n\t\t\t.data( \"ui-tabs-destroy\", true );\n\t},\n\n\t_setOptionDisabled: function( disabled ) {\n\t\tvar currentItem, li, i;\n\n\t\tif ( $.isArray( disabled ) ) {\n\t\t\tif ( !disabled.length ) {\n\t\t\t\tdisabled = false;\n\t\t\t} else if ( disabled.length === this.anchors.length ) {\n\t\t\t\tdisabled = true;\n\t\t\t}\n\t\t}\n\n\t\t// Disable tabs\n\t\tfor ( i = 0; ( li = this.tabs[ i ] ); i++ ) {\n\t\t\tcurrentItem = $( li );\n\t\t\tif ( disabled === true || $.inArray( i, disabled ) !== -1 ) {\n\t\t\t\tcurrentItem.attr( \"aria-disabled\", \"true\" );\n\t\t\t\tthis._addClass( currentItem, null, \"ui-state-disabled\" );\n\t\t\t} else {\n\t\t\t\tcurrentItem.removeAttr( \"aria-disabled\" );\n\t\t\t\tthis._removeClass( currentItem, null, \"ui-state-disabled\" );\n\t\t\t}\n\t\t}\n\n\t\tthis.options.disabled = disabled;\n\n\t\tthis._toggleClass( this.widget(), this.widgetFullName + \"-disabled\", null,\n\t\t\tdisabled === true );\n\t},\n\n\t_setupEvents: function( event ) {\n\t\tvar events = {};\n\t\tif ( event ) {\n\t\t\t$.each( event.split( \" \" ), function( index, eventName ) {\n\t\t\t\tevents[ eventName ] = \"_eventHandler\";\n\t\t\t} );\n\t\t}\n\n\t\tthis._off( this.anchors.add( this.tabs ).add( this.panels ) );\n\n\t\t// Always prevent the default action, even when disabled\n\t\tthis._on( true, this.anchors, {\n\t\t\tclick: function( event ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t} );\n\t\tthis._on( this.anchors, events );\n\t\tthis._on( this.tabs, { keydown: \"_tabKeydown\" } );\n\t\tthis._on( this.panels, { keydown: \"_panelKeydown\" } );\n\n\t\tthis._focusable( this.tabs );\n\t\tthis._hoverable( this.tabs );\n\t},\n\n\t_setupHeightStyle: function( heightStyle ) {\n\t\tvar maxHeight,\n\t\t\tparent = this.element.parent();\n\n\t\tif ( heightStyle === \"fill\" ) {\n\t\t\tmaxHeight = parent.height();\n\t\t\tmaxHeight -= this.element.outerHeight() - this.element.height();\n\n\t\t\tthis.element.siblings( \":visible\" ).each( function() {\n\t\t\t\tvar elem = $( this ),\n\t\t\t\t\tposition = elem.css( \"position\" );\n\n\t\t\t\tif ( position === \"absolute\" || position === \"fixed\" ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tmaxHeight -= elem.outerHeight( true );\n\t\t\t} );\n\n\t\t\tthis.element.children().not( this.panels ).each( function() {\n\t\t\t\tmaxHeight -= $( this ).outerHeight( true );\n\t\t\t} );\n\n\t\t\tthis.panels.each( function() {\n\t\t\t\t$( this ).height( Math.max( 0, maxHeight -\n\t\t\t\t\t$( this ).innerHeight() + $( this ).height() ) );\n\t\t\t} )\n\t\t\t\t.css( \"overflow\", \"auto\" );\n\t\t} else if ( heightStyle === \"auto\" ) {\n\t\t\tmaxHeight = 0;\n\t\t\tthis.panels.each( function() {\n\t\t\t\tmaxHeight = Math.max( maxHeight, $( this ).height( \"\" ).height() );\n\t\t\t} ).height( maxHeight );\n\t\t}\n\t},\n\n\t_eventHandler: function( event ) {\n\t\tvar options = this.options,\n\t\t\tactive = this.active,\n\t\t\tanchor = $( event.currentTarget ),\n\t\t\ttab = anchor.closest( \"li\" ),\n\t\t\tclickedIsActive = tab[ 0 ] === active[ 0 ],\n\t\t\tcollapsing = clickedIsActive && options.collapsible,\n\t\t\ttoShow = collapsing ? $() : this._getPanelForTab( tab ),\n\t\t\ttoHide = !active.length ? $() : this._getPanelForTab( active ),\n\t\t\teventData = {\n\t\t\t\toldTab: active,\n\t\t\t\toldPanel: toHide,\n\t\t\t\tnewTab: collapsing ? $() : tab,\n\t\t\t\tnewPanel: toShow\n\t\t\t};\n\n\t\tevent.preventDefault();\n\n\t\tif ( tab.hasClass( \"ui-state-disabled\" ) ||\n\n\t\t\t\t// tab is already loading\n\t\t\t\ttab.hasClass( \"ui-tabs-loading\" ) ||\n\n\t\t\t\t// can't switch durning an animation\n\t\t\t\tthis.running ||\n\n\t\t\t\t// click on active header, but not collapsible\n\t\t\t\t( clickedIsActive && !options.collapsible ) ||\n\n\t\t\t\t// allow canceling activation\n\t\t\t\t( this._trigger( \"beforeActivate\", event, eventData ) === false ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\toptions.active = collapsing ? false : this.tabs.index( tab );\n\n\t\tthis.active = clickedIsActive ? $() : tab;\n\t\tif ( this.xhr ) {\n\t\t\tthis.xhr.abort();\n\t\t}\n\n\t\tif ( !toHide.length && !toShow.length ) {\n\t\t\t$.error( \"jQuery UI Tabs: Mismatching fragment identifier.\" );\n\t\t}\n\n\t\tif ( toShow.length ) {\n\t\t\tthis.load( this.tabs.index( tab ), event );\n\t\t}\n\t\tthis._toggle( event, eventData );\n\t},\n\n\t// Handles show/hide for selecting tabs\n\t_toggle: function( event, eventData ) {\n\t\tvar that = this,\n\t\t\ttoShow = eventData.newPanel,\n\t\t\ttoHide = eventData.oldPanel;\n\n\t\tthis.running = true;\n\n\t\tfunction complete() {\n\t\t\tthat.running = false;\n\t\t\tthat._trigger( \"activate\", event, eventData );\n\t\t}\n\n\t\tfunction show() {\n\t\t\tthat._addClass( eventData.newTab.closest( \"li\" ), \"ui-tabs-active\", \"ui-state-active\" );\n\n\t\t\tif ( toShow.length && that.options.show ) {\n\t\t\t\tthat._show( toShow, that.options.show, complete );\n\t\t\t} else {\n\t\t\t\ttoShow.show();\n\t\t\t\tcomplete();\n\t\t\t}\n\t\t}\n\n\t\t// Start out by hiding, then showing, then completing\n\t\tif ( toHide.length && this.options.hide ) {\n\t\t\tthis._hide( toHide, this.options.hide, function() {\n\t\t\t\tthat._removeClass( eventData.oldTab.closest( \"li\" ),\n\t\t\t\t\t\"ui-tabs-active\", \"ui-state-active\" );\n\t\t\t\tshow();\n\t\t\t} );\n\t\t} else {\n\t\t\tthis._removeClass( eventData.oldTab.closest( \"li\" ),\n\t\t\t\t\"ui-tabs-active\", \"ui-state-active\" );\n\t\t\ttoHide.hide();\n\t\t\tshow();\n\t\t}\n\n\t\ttoHide.attr( \"aria-hidden\", \"true\" );\n\t\teventData.oldTab.attr( {\n\t\t\t\"aria-selected\": \"false\",\n\t\t\t\"aria-expanded\": \"false\"\n\t\t} );\n\n\t\t// If we're switching tabs, remove the old tab from the tab order.\n\t\t// If we're opening from collapsed state, remove the previous tab from the tab order.\n\t\t// If we're collapsing, then keep the collapsing tab in the tab order.\n\t\tif ( toShow.length && toHide.length ) {\n\t\t\teventData.oldTab.attr( \"tabIndex\", -1 );\n\t\t} else if ( toShow.length ) {\n\t\t\tthis.tabs.filter( function() {\n\t\t\t\treturn $( this ).attr( \"tabIndex\" ) === 0;\n\t\t\t} )\n\t\t\t\t.attr( \"tabIndex\", -1 );\n\t\t}\n\n\t\ttoShow.attr( \"aria-hidden\", \"false\" );\n\t\teventData.newTab.attr( {\n\t\t\t\"aria-selected\": \"true\",\n\t\t\t\"aria-expanded\": \"true\",\n\t\t\ttabIndex: 0\n\t\t} );\n\t},\n\n\t_activate: function( index ) {\n\t\tvar anchor,\n\t\t\tactive = this._findActive( index );\n\n\t\t// Trying to activate the already active panel\n\t\tif ( active[ 0 ] === this.active[ 0 ] ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Trying to collapse, simulate a click on the current active header\n\t\tif ( !active.length ) {\n\t\t\tactive = this.active;\n\t\t}\n\n\t\tanchor = active.find( \".ui-tabs-anchor\" )[ 0 ];\n\t\tthis._eventHandler( {\n\t\t\ttarget: anchor,\n\t\t\tcurrentTarget: anchor,\n\t\t\tpreventDefault: $.noop\n\t\t} );\n\t},\n\n\t_findActive: function( index ) {\n\t\treturn index === false ? $() : this.tabs.eq( index );\n\t},\n\n\t_getIndex: function( index ) {\n\n\t\t// meta-function to give users option to provide a href string instead of a numerical index.\n\t\tif ( typeof index === \"string\" ) {\n\t\t\tindex = this.anchors.index( this.anchors.filter( \"[href$='\" +\n\t\t\t\t$.ui.escapeSelector( index ) + \"']\" ) );\n\t\t}\n\n\t\treturn index;\n\t},\n\n\t_destroy: function() {\n\t\tif ( this.xhr ) {\n\t\t\tthis.xhr.abort();\n\t\t}\n\n\t\tthis.tablist\n\t\t\t.removeAttr( \"role\" )\n\t\t\t.off( this.eventNamespace );\n\n\t\tthis.anchors\n\t\t\t.removeAttr( \"role tabIndex\" )\n\t\t\t.removeUniqueId();\n\n\t\tthis.tabs.add( this.panels ).each( function() {\n\t\t\tif ( $.data( this, \"ui-tabs-destroy\" ) ) {\n\t\t\t\t$( this ).remove();\n\t\t\t} else {\n\t\t\t\t$( this ).removeAttr( \"role tabIndex \" +\n\t\t\t\t\t\"aria-live aria-busy aria-selected aria-labelledby aria-hidden aria-expanded\" );\n\t\t\t}\n\t\t} );\n\n\t\tthis.tabs.each( function() {\n\t\t\tvar li = $( this ),\n\t\t\t\tprev = li.data( \"ui-tabs-aria-controls\" );\n\t\t\tif ( prev ) {\n\t\t\t\tli\n\t\t\t\t\t.attr( \"aria-controls\", prev )\n\t\t\t\t\t.removeData( \"ui-tabs-aria-controls\" );\n\t\t\t} else {\n\t\t\t\tli.removeAttr( \"aria-controls\" );\n\t\t\t}\n\t\t} );\n\n\t\tthis.panels.show();\n\n\t\tif ( this.options.heightStyle !== \"content\" ) {\n\t\t\tthis.panels.css( \"height\", \"\" );\n\t\t}\n\t},\n\n\tenable: function( index ) {\n\t\tvar disabled = this.options.disabled;\n\t\tif ( disabled === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( index === undefined ) {\n\t\t\tdisabled = false;\n\t\t} else {\n\t\t\tindex = this._getIndex( index );\n\t\t\tif ( $.isArray( disabled ) ) {\n\t\t\t\tdisabled = $.map( disabled, function( num ) {\n\t\t\t\t\treturn num !== index ? num : null;\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tdisabled = $.map( this.tabs, function( li, num ) {\n\t\t\t\t\treturn num !== index ? num : null;\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t\tthis._setOptionDisabled( disabled );\n\t},\n\n\tdisable: function( index ) {\n\t\tvar disabled = this.options.disabled;\n\t\tif ( disabled === true ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( index === undefined ) {\n\t\t\tdisabled = true;\n\t\t} else {\n\t\t\tindex = this._getIndex( index );\n\t\t\tif ( $.inArray( index, disabled ) !== -1 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( $.isArray( disabled ) ) {\n\t\t\t\tdisabled = $.merge( [ index ], disabled ).sort();\n\t\t\t} else {\n\t\t\t\tdisabled = [ index ];\n\t\t\t}\n\t\t}\n\t\tthis._setOptionDisabled( disabled );\n\t},\n\n\tload: function( index, event ) {\n\t\tindex = this._getIndex( index );\n\t\tvar that = this,\n\t\t\ttab = this.tabs.eq( index ),\n\t\t\tanchor = tab.find( \".ui-tabs-anchor\" ),\n\t\t\tpanel = this._getPanelForTab( tab ),\n\t\t\teventData = {\n\t\t\t\ttab: tab,\n\t\t\t\tpanel: panel\n\t\t\t},\n\t\t\tcomplete = function( jqXHR, status ) {\n\t\t\t\tif ( status === \"abort\" ) {\n\t\t\t\t\tthat.panels.stop( false, true );\n\t\t\t\t}\n\n\t\t\t\tthat._removeClass( tab, \"ui-tabs-loading\" );\n\t\t\t\tpanel.removeAttr( \"aria-busy\" );\n\n\t\t\t\tif ( jqXHR === that.xhr ) {\n\t\t\t\t\tdelete that.xhr;\n\t\t\t\t}\n\t\t\t};\n\n\t\t// Not remote\n\t\tif ( this._isLocal( anchor[ 0 ] ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.xhr = $.ajax( this._ajaxSettings( anchor, event, eventData ) );\n\n\t\t// Support: jQuery <1.8\n\t\t// jQuery <1.8 returns false if the request is canceled in beforeSend,\n\t\t// but as of 1.8, $.ajax() always returns a jqXHR object.\n\t\tif ( this.xhr && this.xhr.statusText !== \"canceled\" ) {\n\t\t\tthis._addClass( tab, \"ui-tabs-loading\" );\n\t\t\tpanel.attr( \"aria-busy\", \"true\" );\n\n\t\t\tthis.xhr\n\t\t\t\t.done( function( response, status, jqXHR ) {\n\n\t\t\t\t\t// support: jQuery <1.8\n\t\t\t\t\t// http://bugs.jquery.com/ticket/11778\n\t\t\t\t\tsetTimeout( function() {\n\t\t\t\t\t\tpanel.html( response );\n\t\t\t\t\t\tthat._trigger( \"load\", event, eventData );\n\n\t\t\t\t\t\tcomplete( jqXHR, status );\n\t\t\t\t\t}, 1 );\n\t\t\t\t} )\n\t\t\t\t.fail( function( jqXHR, status ) {\n\n\t\t\t\t\t// support: jQuery <1.8\n\t\t\t\t\t// http://bugs.jquery.com/ticket/11778\n\t\t\t\t\tsetTimeout( function() {\n\t\t\t\t\t\tcomplete( jqXHR, status );\n\t\t\t\t\t}, 1 );\n\t\t\t\t} );\n\t\t}\n\t},\n\n\t_ajaxSettings: function( anchor, event, eventData ) {\n\t\tvar that = this;\n\t\treturn {\n\n\t\t\t// Support: IE <11 only\n\t\t\t// Strip any hash that exists to prevent errors with the Ajax request\n\t\t\turl: anchor.attr( \"href\" ).replace( /#.*$/, \"\" ),\n\t\t\tbeforeSend: function( jqXHR, settings ) {\n\t\t\t\treturn that._trigger( \"beforeLoad\", event,\n\t\t\t\t\t$.extend( { jqXHR: jqXHR, ajaxSettings: settings }, eventData ) );\n\t\t\t}\n\t\t};\n\t},\n\n\t_getPanelForTab: function( tab ) {\n\t\tvar id = $( tab ).attr( \"aria-controls\" );\n\t\treturn this.element.find( this._sanitizeSelector( \"#\" + id ) );\n\t}\n} );\n\n// DEPRECATED\n// TODO: Switch return back to widget declaration at top of file when this is removed\nif ( $.uiBackCompat !== false ) {\n\n\t// Backcompat for ui-tab class (now ui-tabs-tab)\n\t$.widget( \"ui.tabs\", $.ui.tabs, {\n\t\t_processTabs: function() {\n\t\t\tthis._superApply( arguments );\n\t\t\tthis._addClass( this.tabs, \"ui-tab\" );\n\t\t}\n\t} );\n}\n\nvar widgetsTabs = $.ui.tabs;\n\n\n/*!\n * jQuery UI Tooltip 1.12.1\n * http://jqueryui.com\n *\n * Copyright jQuery Foundation and other contributors\n * Released under the MIT license.\n * http://jquery.org/license\n */\n\n//>>label: Tooltip\n//>>group: Widgets\n//>>description: Shows additional information for any element on hover or focus.\n//>>docs: http://api.jqueryui.com/tooltip/\n//>>demos: http://jqueryui.com/tooltip/\n//>>css.structure: ../../themes/base/core.css\n//>>css.structure: ../../themes/base/tooltip.css\n//>>css.theme: ../../themes/base/theme.css\n\n\n\n$.widget( \"ui.tooltip\", {\n\tversion: \"1.12.1\",\n\toptions: {\n\t\tclasses: {\n\t\t\t\"ui-tooltip\": \"ui-corner-all ui-widget-shadow\"\n\t\t},\n\t\tcontent: function() {\n\n\t\t\t// support: IE<9, Opera in jQuery <1.7\n\t\t\t// .text() can't accept undefined, so coerce to a string\n\t\t\tvar title = $( this ).attr( \"title\" ) || \"\";\n\n\t\t\t// Escape title, since we're going from an attribute to raw HTML\n\t\t\treturn $( \"<a>\" ).text( title ).html();\n\t\t},\n\t\thide: true,\n\n\t\t// Disabled elements have inconsistent behavior across browsers (#8661)\n\t\titems: \"[title]:not([disabled])\",\n\t\tposition: {\n\t\t\tmy: \"left top+15\",\n\t\t\tat: \"left bottom\",\n\t\t\tcollision: \"flipfit flip\"\n\t\t},\n\t\tshow: true,\n\t\ttrack: false,\n\n\t\t// Callbacks\n\t\tclose: null,\n\t\topen: null\n\t},\n\n\t_addDescribedBy: function( elem, id ) {\n\t\tvar describedby = ( elem.attr( \"aria-describedby\" ) || \"\" ).split( /\\s+/ );\n\t\tdescribedby.push( id );\n\t\telem\n\t\t\t.data( \"ui-tooltip-id\", id )\n\t\t\t.attr( \"aria-describedby\", $.trim( describedby.join( \" \" ) ) );\n\t},\n\n\t_removeDescribedBy: function( elem ) {\n\t\tvar id = elem.data( \"ui-tooltip-id\" ),\n\t\t\tdescribedby = ( elem.attr( \"aria-describedby\" ) || \"\" ).split( /\\s+/ ),\n\t\t\tindex = $.inArray( id, describedby );\n\n\t\tif ( index !== -1 ) {\n\t\t\tdescribedby.splice( index, 1 );\n\t\t}\n\n\t\telem.removeData( \"ui-tooltip-id\" );\n\t\tdescribedby = $.trim( describedby.join( \" \" ) );\n\t\tif ( describedby ) {\n\t\t\telem.attr( \"aria-describedby\", describedby );\n\t\t} else {\n\t\t\telem.removeAttr( \"aria-describedby\" );\n\t\t}\n\t},\n\n\t_create: function() {\n\t\tthis._on( {\n\t\t\tmouseover: \"open\",\n\t\t\tfocusin: \"open\"\n\t\t} );\n\n\t\t// IDs of generated tooltips, needed for destroy\n\t\tthis.tooltips = {};\n\n\t\t// IDs of parent tooltips where we removed the title attribute\n\t\tthis.parents = {};\n\n\t\t// Append the aria-live region so tooltips announce correctly\n\t\tthis.liveRegion = $( \"<div>\" )\n\t\t\t.attr( {\n\t\t\t\trole: \"log\",\n\t\t\t\t\"aria-live\": \"assertive\",\n\t\t\t\t\"aria-relevant\": \"additions\"\n\t\t\t} )\n\t\t\t.appendTo( this.document[ 0 ].body );\n\t\tthis._addClass( this.liveRegion, null, \"ui-helper-hidden-accessible\" );\n\n\t\tthis.disabledTitles = $( [] );\n\t},\n\n\t_setOption: function( key, value ) {\n\t\tvar that = this;\n\n\t\tthis._super( key, value );\n\n\t\tif ( key === \"content\" ) {\n\t\t\t$.each( this.tooltips, function( id, tooltipData ) {\n\t\t\t\tthat._updateContent( tooltipData.element );\n\t\t\t} );\n\t\t}\n\t},\n\n\t_setOptionDisabled: function( value ) {\n\t\tthis[ value ? \"_disable\" : \"_enable\" ]();\n\t},\n\n\t_disable: function() {\n\t\tvar that = this;\n\n\t\t// Close open tooltips\n\t\t$.each( this.tooltips, function( id, tooltipData ) {\n\t\t\tvar event = $.Event( \"blur\" );\n\t\t\tevent.target = event.currentTarget = tooltipData.element[ 0 ];\n\t\t\tthat.close( event, true );\n\t\t} );\n\n\t\t// Remove title attributes to prevent native tooltips\n\t\tthis.disabledTitles = this.disabledTitles.add(\n\t\t\tthis.element.find( this.options.items ).addBack()\n\t\t\t\t.filter( function() {\n\t\t\t\t\tvar element = $( this );\n\t\t\t\t\tif ( element.is( \"[title]\" ) ) {\n\t\t\t\t\t\treturn element\n\t\t\t\t\t\t\t.data( \"ui-tooltip-title\", element.attr( \"title\" ) )\n\t\t\t\t\t\t\t.removeAttr( \"title\" );\n\t\t\t\t\t}\n\t\t\t\t} )\n\t\t);\n\t},\n\n\t_enable: function() {\n\n\t\t// restore title attributes\n\t\tthis.disabledTitles.each( function() {\n\t\t\tvar element = $( this );\n\t\t\tif ( element.data( \"ui-tooltip-title\" ) ) {\n\t\t\t\telement.attr( \"title\", element.data( \"ui-tooltip-title\" ) );\n\t\t\t}\n\t\t} );\n\t\tthis.disabledTitles = $( [] );\n\t},\n\n\topen: function( event ) {\n\t\tvar that = this,\n\t\t\ttarget = $( event ? event.target : this.element )\n\n\t\t\t\t// we need closest here due to mouseover bubbling,\n\t\t\t\t// but always pointing at the same event target\n\t\t\t\t.closest( this.options.items );\n\n\t\t// No element to show a tooltip for or the tooltip is already open\n\t\tif ( !target.length || target.data( \"ui-tooltip-id\" ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( target.attr( \"title\" ) ) {\n\t\t\ttarget.data( \"ui-tooltip-title\", target.attr( \"title\" ) );\n\t\t}\n\n\t\ttarget.data( \"ui-tooltip-open\", true );\n\n\t\t// Kill parent tooltips, custom or native, for hover\n\t\tif ( event && event.type === \"mouseover\" ) {\n\t\t\ttarget.parents().each( function() {\n\t\t\t\tvar parent = $( this ),\n\t\t\t\t\tblurEvent;\n\t\t\t\tif ( parent.data( \"ui-tooltip-open\" ) ) {\n\t\t\t\t\tblurEvent = $.Event( \"blur\" );\n\t\t\t\t\tblurEvent.target = blurEvent.currentTarget = this;\n\t\t\t\t\tthat.close( blurEvent, true );\n\t\t\t\t}\n\t\t\t\tif ( parent.attr( \"title\" ) ) {\n\t\t\t\t\tparent.uniqueId();\n\t\t\t\t\tthat.parents[ this.id ] = {\n\t\t\t\t\t\telement: this,\n\t\t\t\t\t\ttitle: parent.attr( \"title\" )\n\t\t\t\t\t};\n\t\t\t\t\tparent.attr( \"title\", \"\" );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tthis._registerCloseHandlers( event, target );\n\t\tthis._updateContent( target, event );\n\t},\n\n\t_updateContent: function( target, event ) {\n\t\tvar content,\n\t\t\tcontentOption = this.options.content,\n\t\t\tthat = this,\n\t\t\teventType = event ? event.type : null;\n\n\t\tif ( typeof contentOption === \"string\" || contentOption.nodeType ||\n\t\t\t\tcontentOption.jquery ) {\n\t\t\treturn this._open( event, target, contentOption );\n\t\t}\n\n\t\tcontent = contentOption.call( target[ 0 ], function( response ) {\n\n\t\t\t// IE may instantly serve a cached response for ajax requests\n\t\t\t// delay this call to _open so the other call to _open runs first\n\t\t\tthat._delay( function() {\n\n\t\t\t\t// Ignore async response if tooltip was closed already\n\t\t\t\tif ( !target.data( \"ui-tooltip-open\" ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// JQuery creates a special event for focusin when it doesn't\n\t\t\t\t// exist natively. To improve performance, the native event\n\t\t\t\t// object is reused and the type is changed. Therefore, we can't\n\t\t\t\t// rely on the type being correct after the event finished\n\t\t\t\t// bubbling, so we set it back to the previous value. (#8740)\n\t\t\t\tif ( event ) {\n\t\t\t\t\tevent.type = eventType;\n\t\t\t\t}\n\t\t\t\tthis._open( event, target, response );\n\t\t\t} );\n\t\t} );\n\t\tif ( content ) {\n\t\t\tthis._open( event, target, content );\n\t\t}\n\t},\n\n\t_open: function( event, target, content ) {\n\t\tvar tooltipData, tooltip, delayedShow, a11yContent,\n\t\t\tpositionOption = $.extend( {}, this.options.position );\n\n\t\tif ( !content ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Content can be updated multiple times. If the tooltip already\n\t\t// exists, then just update the content and bail.\n\t\ttooltipData = this._find( target );\n\t\tif ( tooltipData ) {\n\t\t\ttooltipData.tooltip.find( \".ui-tooltip-content\" ).html( content );\n\t\t\treturn;\n\t\t}\n\n\t\t// If we have a title, clear it to prevent the native tooltip\n\t\t// we have to check first to avoid defining a title if none exists\n\t\t// (we don't want to cause an element to start matching [title])\n\t\t//\n\t\t// We use removeAttr only for key events, to allow IE to export the correct\n\t\t// accessible attributes. For mouse events, set to empty string to avoid\n\t\t// native tooltip showing up (happens only when removing inside mouseover).\n\t\tif ( target.is( \"[title]\" ) ) {\n\t\t\tif ( event && event.type === \"mouseover\" ) {\n\t\t\t\ttarget.attr( \"title\", \"\" );\n\t\t\t} else {\n\t\t\t\ttarget.removeAttr( \"title\" );\n\t\t\t}\n\t\t}\n\n\t\ttooltipData = this._tooltip( target );\n\t\ttooltip = tooltipData.tooltip;\n\t\tthis._addDescribedBy( target, tooltip.attr( \"id\" ) );\n\t\ttooltip.find( \".ui-tooltip-content\" ).html( content );\n\n\t\t// Support: Voiceover on OS X, JAWS on IE <= 9\n\t\t// JAWS announces deletions even when aria-relevant=\"additions\"\n\t\t// Voiceover will sometimes re-read the entire log region's contents from the beginning\n\t\tthis.liveRegion.children().hide();\n\t\ta11yContent = $( \"<div>\" ).html( tooltip.find( \".ui-tooltip-content\" ).html() );\n\t\ta11yContent.removeAttr( \"name\" ).find( \"[name]\" ).removeAttr( \"name\" );\n\t\ta11yContent.removeAttr( \"id\" ).find( \"[id]\" ).removeAttr( \"id\" );\n\t\ta11yContent.appendTo( this.liveRegion );\n\n\t\tfunction position( event ) {\n\t\t\tpositionOption.of = event;\n\t\t\tif ( tooltip.is( \":hidden\" ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttooltip.position( positionOption );\n\t\t}\n\t\tif ( this.options.track && event && /^mouse/.test( event.type ) ) {\n\t\t\tthis._on( this.document, {\n\t\t\t\tmousemove: position\n\t\t\t} );\n\n\t\t\t// trigger once to override element-relative positioning\n\t\t\tposition( event );\n\t\t} else {\n\t\t\ttooltip.position( $.extend( {\n\t\t\t\tof: target\n\t\t\t}, this.options.position ) );\n\t\t}\n\n\t\ttooltip.hide();\n\n\t\tthis._show( tooltip, this.options.show );\n\n\t\t// Handle tracking tooltips that are shown with a delay (#8644). As soon\n\t\t// as the tooltip is visible, position the tooltip using the most recent\n\t\t// event.\n\t\t// Adds the check to add the timers only when both delay and track options are set (#14682)\n\t\tif ( this.options.track && this.options.show && this.options.show.delay ) {\n\t\t\tdelayedShow = this.delayedShow = setInterval( function() {\n\t\t\t\tif ( tooltip.is( \":visible\" ) ) {\n\t\t\t\t\tposition( positionOption.of );\n\t\t\t\t\tclearInterval( delayedShow );\n\t\t\t\t}\n\t\t\t}, $.fx.interval );\n\t\t}\n\n\t\tthis._trigger( \"open\", event, { tooltip: tooltip } );\n\t},\n\n\t_registerCloseHandlers: function( event, target ) {\n\t\tvar events = {\n\t\t\tkeyup: function( event ) {\n\t\t\t\tif ( event.keyCode === $.ui.keyCode.ESCAPE ) {\n\t\t\t\t\tvar fakeEvent = $.Event( event );\n\t\t\t\t\tfakeEvent.currentTarget = target[ 0 ];\n\t\t\t\t\tthis.close( fakeEvent, true );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Only bind remove handler for delegated targets. Non-delegated\n\t\t// tooltips will handle this in destroy.\n\t\tif ( target[ 0 ] !== this.element[ 0 ] ) {\n\t\t\tevents.remove = function() {\n\t\t\t\tthis._removeTooltip( this._find( target ).tooltip );\n\t\t\t};\n\t\t}\n\n\t\tif ( !event || event.type === \"mouseover\" ) {\n\t\t\tevents.mouseleave = \"close\";\n\t\t}\n\t\tif ( !event || event.type === \"focusin\" ) {\n\t\t\tevents.focusout = \"close\";\n\t\t}\n\t\tthis._on( true, target, events );\n\t},\n\n\tclose: function( event ) {\n\t\tvar tooltip,\n\t\t\tthat = this,\n\t\t\ttarget = $( event ? event.currentTarget : this.element ),\n\t\t\ttooltipData = this._find( target );\n\n\t\t// The tooltip may already be closed\n\t\tif ( !tooltipData ) {\n\n\t\t\t// We set ui-tooltip-open immediately upon open (in open()), but only set the\n\t\t\t// additional data once there's actually content to show (in _open()). So even if the\n\t\t\t// tooltip doesn't have full data, we always remove ui-tooltip-open in case we're in\n\t\t\t// the period between open() and _open().\n\t\t\ttarget.removeData( \"ui-tooltip-open\" );\n\t\t\treturn;\n\t\t}\n\n\t\ttooltip = tooltipData.tooltip;\n\n\t\t// Disabling closes the tooltip, so we need to track when we're closing\n\t\t// to avoid an infinite loop in case the tooltip becomes disabled on close\n\t\tif ( tooltipData.closing ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear the interval for delayed tracking tooltips\n\t\tclearInterval( this.delayedShow );\n\n\t\t// Only set title if we had one before (see comment in _open())\n\t\t// If the title attribute has changed since open(), don't restore\n\t\tif ( target.data( \"ui-tooltip-title\" ) && !target.attr( \"title\" ) ) {\n\t\t\ttarget.attr( \"title\", target.data( \"ui-tooltip-title\" ) );\n\t\t}\n\n\t\tthis._removeDescribedBy( target );\n\n\t\ttooltipData.hiding = true;\n\t\ttooltip.stop( true );\n\t\tthis._hide( tooltip, this.options.hide, function() {\n\t\t\tthat._removeTooltip( $( this ) );\n\t\t} );\n\n\t\ttarget.removeData( \"ui-tooltip-open\" );\n\t\tthis._off( target, \"mouseleave focusout keyup\" );\n\n\t\t// Remove 'remove' binding only on delegated targets\n\t\tif ( target[ 0 ] !== this.element[ 0 ] ) {\n\t\t\tthis._off( target, \"remove\" );\n\t\t}\n\t\tthis._off( this.document, \"mousemove\" );\n\n\t\tif ( event && event.type === \"mouseleave\" ) {\n\t\t\t$.each( this.parents, function( id, parent ) {\n\t\t\t\t$( parent.element ).attr( \"title\", parent.title );\n\t\t\t\tdelete that.parents[ id ];\n\t\t\t} );\n\t\t}\n\n\t\ttooltipData.closing = true;\n\t\tthis._trigger( \"close\", event, { tooltip: tooltip } );\n\t\tif ( !tooltipData.hiding ) {\n\t\t\ttooltipData.closing = false;\n\t\t}\n\t},\n\n\t_tooltip: function( element ) {\n\t\tvar tooltip = $( \"<div>\" ).attr( \"role\", \"tooltip\" ),\n\t\t\tcontent = $( \"<div>\" ).appendTo( tooltip ),\n\t\t\tid = tooltip.uniqueId().attr( \"id\" );\n\n\t\tthis._addClass( content, \"ui-tooltip-content\" );\n\t\tthis._addClass( tooltip, \"ui-tooltip\", \"ui-widget ui-widget-content\" );\n\n\t\ttooltip.appendTo( this._appendTo( element ) );\n\n\t\treturn this.tooltips[ id ] = {\n\t\t\telement: element,\n\t\t\ttooltip: tooltip\n\t\t};\n\t},\n\n\t_find: function( target ) {\n\t\tvar id = target.data( \"ui-tooltip-id\" );\n\t\treturn id ? this.tooltips[ id ] : null;\n\t},\n\n\t_removeTooltip: function( tooltip ) {\n\t\ttooltip.remove();\n\t\tdelete this.tooltips[ tooltip.attr( \"id\" ) ];\n\t},\n\n\t_appendTo: function( target ) {\n\t\tvar element = target.closest( \".ui-front, dialog\" );\n\n\t\tif ( !element.length ) {\n\t\t\telement = this.document[ 0 ].body;\n\t\t}\n\n\t\treturn element;\n\t},\n\n\t_destroy: function() {\n\t\tvar that = this;\n\n\t\t// Close open tooltips\n\t\t$.each( this.tooltips, function( id, tooltipData ) {\n\n\t\t\t// Delegate to close method to handle common cleanup\n\t\t\tvar event = $.Event( \"blur\" ),\n\t\t\t\telement = tooltipData.element;\n\t\t\tevent.target = event.currentTarget = element[ 0 ];\n\t\t\tthat.close( event, true );\n\n\t\t\t// Remove immediately; destroying an open tooltip doesn't use the\n\t\t\t// hide animation\n\t\t\t$( \"#\" + id ).remove();\n\n\t\t\t// Restore the title\n\t\t\tif ( element.data( \"ui-tooltip-title\" ) ) {\n\n\t\t\t\t// If the title attribute has changed since open(), don't restore\n\t\t\t\tif ( !element.attr( \"title\" ) ) {\n\t\t\t\t\telement.attr( \"title\", element.data( \"ui-tooltip-title\" ) );\n\t\t\t\t}\n\t\t\t\telement.removeData( \"ui-tooltip-title\" );\n\t\t\t}\n\t\t} );\n\t\tthis.liveRegion.remove();\n\t}\n} );\n\n// DEPRECATED\n// TODO: Switch return back to widget declaration at top of file when this is removed\nif ( $.uiBackCompat !== false ) {\n\n\t// Backcompat for tooltipClass option\n\t$.widget( \"ui.tooltip\", $.ui.tooltip, {\n\t\toptions: {\n\t\t\ttooltipClass: null\n\t\t},\n\t\t_tooltip: function() {\n\t\t\tvar tooltipData = this._superApply( arguments );\n\t\t\tif ( this.options.tooltipClass ) {\n\t\t\t\ttooltipData.tooltip.addClass( this.options.tooltipClass );\n\t\t\t}\n\t\t\treturn tooltipData;\n\t\t}\n\t} );\n}\n\nvar widgetsTooltip = $.ui.tooltip;\n\n\n\n\n}));"
  },
  {
    "path": "cyacas/packaging/deb/missing-sources/jquery.autosize.js",
    "content": "/*!\n\tAutosize 1.18.13\n\tlicense: MIT\n\thttp://www.jacklmoore.com/autosize\n*/\n(function ($) {\n\tvar\n\tdefaults = {\n\t\tclassName: 'autosizejs',\n\t\tid: 'autosizejs',\n\t\tappend: '\\n',\n\t\tcallback: false,\n\t\tresizeDelay: 10,\n\t\tplaceholder: true\n\t},\n\n\t// border:0 is unnecessary, but avoids a bug in Firefox on OSX\n\tcopy = '<textarea tabindex=\"-1\" style=\"position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden; transition:none; -webkit-transition:none; -moz-transition:none;\"/>',\n\n\t// line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.\n\ttypographyStyles = [\n\t\t'fontFamily',\n\t\t'fontSize',\n\t\t'fontWeight',\n\t\t'fontStyle',\n\t\t'letterSpacing',\n\t\t'textTransform',\n\t\t'wordSpacing',\n\t\t'textIndent',\n\t\t'whiteSpace'\n\t],\n\n\t// to keep track which textarea is being mirrored when adjust() is called.\n\tmirrored,\n\n\t// the mirror element, which is used to calculate what size the mirrored element should be.\n\tmirror = $(copy).data('autosize', true)[0];\n\n\t// test that line-height can be accurately copied.\n\tmirror.style.lineHeight = '99px';\n\tif ($(mirror).css('lineHeight') === '99px') {\n\t\ttypographyStyles.push('lineHeight');\n\t}\n\tmirror.style.lineHeight = '';\n\n\t$.fn.autosize = function (options) {\n\t\tif (!this.length) {\n\t\t\treturn this;\n\t\t}\n\n\t\toptions = $.extend({}, defaults, options || {});\n\n\t\tif (mirror.parentNode !== document.body) {\n\t\t\t$(document.body).append(mirror);\n\t\t}\n\n\t\treturn this.each(function () {\n\t\t\tvar\n\t\t\tta = this,\n\t\t\t$ta = $(ta),\n\t\t\tmaxHeight,\n\t\t\tminHeight,\n\t\t\tboxOffset = 0,\n\t\t\tcallback = $.isFunction(options.callback),\n\t\t\toriginalStyles = {\n\t\t\t\theight: ta.style.height,\n\t\t\t\toverflow: ta.style.overflow,\n\t\t\t\toverflowY: ta.style.overflowY,\n\t\t\t\twordWrap: ta.style.wordWrap,\n\t\t\t\tresize: ta.style.resize\n\t\t\t},\n\t\t\ttimeout,\n\t\t\twidth = $ta.width(),\n\t\t\ttaResize = $ta.css('resize');\n\n\t\t\tif ($ta.data('autosize')) {\n\t\t\t\t// exit if autosize has already been applied, or if the textarea is the mirror element.\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t$ta.data('autosize', true);\n\n\t\t\tif ($ta.css('box-sizing') === 'border-box' || $ta.css('-moz-box-sizing') === 'border-box' || $ta.css('-webkit-box-sizing') === 'border-box'){\n\t\t\t\tboxOffset = $ta.outerHeight() - $ta.height();\n\t\t\t}\n\n\t\t\t// IE8 and lower return 'auto', which parses to NaN, if no min-height is set.\n\t\t\tminHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height());\n\n\t\t\t$ta.css({\n\t\t\t\toverflow: 'hidden',\n\t\t\t\toverflowY: 'hidden',\n\t\t\t\twordWrap: 'break-word' // horizontal overflow is hidden, so break-word is necessary for handling words longer than the textarea width\n\t\t\t});\n\n\t\t\tif (taResize === 'vertical') {\n\t\t\t\t$ta.css('resize','none');\n\t\t\t} else if (taResize === 'both') {\n\t\t\t\t$ta.css('resize', 'horizontal');\n\t\t\t}\n\n\t\t\t// The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.\n\t\t\t// window.getComputedStyle, getBoundingClientRect returning a width are unsupported, but also unneeded in IE8 and lower.\n\t\t\tfunction setWidth() {\n\t\t\t\tvar width;\n\t\t\t\tvar style = window.getComputedStyle ? window.getComputedStyle(ta, null) : false;\n\t\t\t\t\n\t\t\t\tif (style) {\n\n\t\t\t\t\twidth = ta.getBoundingClientRect().width;\n\n\t\t\t\t\tif (width === 0 || typeof width !== 'number') {\n\t\t\t\t\t\twidth = parseInt(style.width,10);\n\t\t\t\t\t}\n\n\t\t\t\t\t$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){\n\t\t\t\t\t\twidth -= parseInt(style[val],10);\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\twidth = $ta.width();\n\t\t\t\t}\n\n\t\t\t\tmirror.style.width = Math.max(width,0) + 'px';\n\t\t\t}\n\n\t\t\tfunction initMirror() {\n\t\t\t\tvar styles = {};\n\n\t\t\t\tmirrored = ta;\n\t\t\t\tmirror.className = options.className;\n\t\t\t\tmirror.id = options.id;\n\t\t\t\tmaxHeight = parseInt($ta.css('maxHeight'), 10);\n\n\t\t\t\t// mirror is a duplicate textarea located off-screen that\n\t\t\t\t// is automatically updated to contain the same text as the\n\t\t\t\t// original textarea.  mirror always has a height of 0.\n\t\t\t\t// This gives a cross-browser supported way getting the actual\n\t\t\t\t// height of the text, through the scrollTop property.\n\t\t\t\t$.each(typographyStyles, function(i,val){\n\t\t\t\t\tstyles[val] = $ta.css(val);\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\t$(mirror).css(styles).attr('wrap', $ta.attr('wrap'));\n\n\t\t\t\tsetWidth();\n\n\t\t\t\t// Chrome-specific fix:\n\t\t\t\t// When the textarea y-overflow is hidden, Chrome doesn't reflow the text to account for the space\n\t\t\t\t// made available by removing the scrollbar. This workaround triggers the reflow for Chrome.\n\t\t\t\tif (window.chrome) {\n\t\t\t\t\tvar width = ta.style.width;\n\t\t\t\t\tta.style.width = '0px';\n\t\t\t\t\tvar ignore = ta.offsetWidth;\n\t\t\t\t\tta.style.width = width;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Using mainly bare JS in this function because it is going\n\t\t\t// to fire very often while typing, and needs to very efficient.\n\t\t\tfunction adjust() {\n\t\t\t\tvar height, original;\n\n\t\t\t\tif (mirrored !== ta) {\n\t\t\t\t\tinitMirror();\n\t\t\t\t} else {\n\t\t\t\t\tsetWidth();\n\t\t\t\t}\n\n\t\t\t\tif (!ta.value && options.placeholder) {\n\t\t\t\t\t// If the textarea is empty, copy the placeholder text into \n\t\t\t\t\t// the mirror control and use that for sizing so that we \n\t\t\t\t\t// don't end up with placeholder getting trimmed.\n\t\t\t\t\tmirror.value = ($ta.attr(\"placeholder\") || '');\n\t\t\t\t} else {\n\t\t\t\t\tmirror.value = ta.value;\n\t\t\t\t}\n\n\t\t\t\tmirror.value += options.append || '';\n\t\t\t\tmirror.style.overflowY = ta.style.overflowY;\n\t\t\t\toriginal = parseInt(ta.style.height,10);\n\n\t\t\t\t// Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied\n\t\t\t\tmirror.scrollTop = 0;\n\n\t\t\t\tmirror.scrollTop = 9e4;\n\n\t\t\t\t// Using scrollTop rather than scrollHeight because scrollHeight is non-standard and includes padding.\n\t\t\t\theight = mirror.scrollTop;\n\n\t\t\t\tif (maxHeight && height > maxHeight) {\n\t\t\t\t\tta.style.overflowY = 'scroll';\n\t\t\t\t\theight = maxHeight;\n\t\t\t\t} else {\n\t\t\t\t\tta.style.overflowY = 'hidden';\n\t\t\t\t\tif (height < minHeight) {\n\t\t\t\t\t\theight = minHeight;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\theight += boxOffset;\n\n\t\t\t\tif (original !== height) {\n\t\t\t\t\tta.style.height = height + 'px';\n\t\t\t\t\tif (callback) {\n\t\t\t\t\t\toptions.callback.call(ta,ta);\n\t\t\t\t\t}\n\t\t\t\t\t$ta.trigger('autosize.resized');\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction resize () {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\ttimeout = setTimeout(function(){\n\t\t\t\t\tvar newWidth = $ta.width();\n\n\t\t\t\t\tif (newWidth !== width) {\n\t\t\t\t\t\twidth = newWidth;\n\t\t\t\t\t\tadjust();\n\t\t\t\t\t}\n\t\t\t\t}, parseInt(options.resizeDelay,10));\n\t\t\t}\n\n\t\t\tif ('onpropertychange' in ta) {\n\t\t\t\tif ('oninput' in ta) {\n\t\t\t\t\t// Detects IE9.  IE9 does not fire onpropertychange or oninput for deletions,\n\t\t\t\t\t// so binding to onkeyup to catch most of those occasions.  There is no way that I\n\t\t\t\t\t// know of to detect something like 'cut' in IE9.\n\t\t\t\t\t$ta.on('input.autosize keyup.autosize', adjust);\n\t\t\t\t} else {\n\t\t\t\t\t// IE7 / IE8\n\t\t\t\t\t$ta.on('propertychange.autosize', function(){\n\t\t\t\t\t\tif(event.propertyName === 'value'){\n\t\t\t\t\t\t\tadjust();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Modern Browsers\n\t\t\t\t$ta.on('input.autosize', adjust);\n\t\t\t}\n\n\t\t\t// Set options.resizeDelay to false if using fixed-width textarea elements.\n\t\t\t// Uses a timeout and width check to reduce the amount of times adjust needs to be called after window resize.\n\n\t\t\tif (options.resizeDelay !== false) {\n\t\t\t\t$(window).on('resize.autosize', resize);\n\t\t\t}\n\n\t\t\t// Event for manual triggering if needed.\n\t\t\t// Should only be needed when the value of the textarea is changed through JavaScript rather than user input.\n\t\t\t$ta.on('autosize.resize', adjust);\n\n\t\t\t// Event for manual triggering that also forces the styles to update as well.\n\t\t\t// Should only be needed if one of typography styles of the textarea change, and the textarea is already the target of the adjust method.\n\t\t\t$ta.on('autosize.resizeIncludeStyle', function() {\n\t\t\t\tmirrored = null;\n\t\t\t\tadjust();\n\t\t\t});\n\n\t\t\t$ta.on('autosize.destroy', function(){\n\t\t\t\tmirrored = null;\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\t$(window).off('resize', resize);\n\t\t\t\t$ta\n\t\t\t\t\t.off('autosize')\n\t\t\t\t\t.off('.autosize')\n\t\t\t\t\t.css(originalStyles)\n\t\t\t\t\t.removeData('autosize');\n\t\t\t});\n\n\t\t\t// Call adjust in case the textarea already contains text.\n\t\t\tadjust();\n\t\t});\n\t};\n}(jQuery || $)); // jQuery or jQuery-like library, such as Zepto\n"
  },
  {
    "path": "cyacas/packaging/deb/missing-sources/jquery.js",
    "content": "/*!\n * jQuery JavaScript Library v3.4.1\n * https://jquery.com/\n *\n * Includes Sizzle.js\n * https://sizzlejs.com/\n *\n * Copyright JS Foundation and other contributors\n * Released under the MIT license\n * https://jquery.org/license\n *\n * Date: 2019-05-01T21:04Z\n */\n( function( global, factory ) {\n\n\t\"use strict\";\n\n\tif ( typeof module === \"object\" && typeof module.exports === \"object\" ) {\n\n\t\t// For CommonJS and CommonJS-like environments where a proper `window`\n\t\t// is present, execute the factory and get jQuery.\n\t\t// For environments that do not have a `window` with a `document`\n\t\t// (such as Node.js), expose a factory as module.exports.\n\t\t// This accentuates the need for the creation of a real `window`.\n\t\t// e.g. var jQuery = require(\"jquery\")(window);\n\t\t// See ticket #14549 for more info.\n\t\tmodule.exports = global.document ?\n\t\t\tfactory( global, true ) :\n\t\t\tfunction( w ) {\n\t\t\t\tif ( !w.document ) {\n\t\t\t\t\tthrow new Error( \"jQuery requires a window with a document\" );\n\t\t\t\t}\n\t\t\t\treturn factory( w );\n\t\t\t};\n\t} else {\n\t\tfactory( global );\n\t}\n\n// Pass this if window is not defined yet\n} )( typeof window !== \"undefined\" ? window : this, function( window, noGlobal ) {\n\n// Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1\n// throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode\n// arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common\n// enough that all such attempts are guarded in a try block.\n\"use strict\";\n\nvar arr = [];\n\nvar document = window.document;\n\nvar getProto = Object.getPrototypeOf;\n\nvar slice = arr.slice;\n\nvar concat = arr.concat;\n\nvar push = arr.push;\n\nvar indexOf = arr.indexOf;\n\nvar class2type = {};\n\nvar toString = class2type.toString;\n\nvar hasOwn = class2type.hasOwnProperty;\n\nvar fnToString = hasOwn.toString;\n\nvar ObjectFunctionString = fnToString.call( Object );\n\nvar support = {};\n\nvar isFunction = function isFunction( obj ) {\n\n      // Support: Chrome <=57, Firefox <=52\n      // In some browsers, typeof returns \"function\" for HTML <object> elements\n      // (i.e., `typeof document.createElement( \"object\" ) === \"function\"`).\n      // We don't want to classify *any* DOM node as a function.\n      return typeof obj === \"function\" && typeof obj.nodeType !== \"number\";\n  };\n\n\nvar isWindow = function isWindow( obj ) {\n\t\treturn obj != null && obj === obj.window;\n\t};\n\n\n\n\n\tvar preservedScriptAttributes = {\n\t\ttype: true,\n\t\tsrc: true,\n\t\tnonce: true,\n\t\tnoModule: true\n\t};\n\n\tfunction DOMEval( code, node, doc ) {\n\t\tdoc = doc || document;\n\n\t\tvar i, val,\n\t\t\tscript = doc.createElement( \"script\" );\n\n\t\tscript.text = code;\n\t\tif ( node ) {\n\t\t\tfor ( i in preservedScriptAttributes ) {\n\n\t\t\t\t// Support: Firefox 64+, Edge 18+\n\t\t\t\t// Some browsers don't support the \"nonce\" property on scripts.\n\t\t\t\t// On the other hand, just using `getAttribute` is not enough as\n\t\t\t\t// the `nonce` attribute is reset to an empty string whenever it\n\t\t\t\t// becomes browsing-context connected.\n\t\t\t\t// See https://github.com/whatwg/html/issues/2369\n\t\t\t\t// See https://html.spec.whatwg.org/#nonce-attributes\n\t\t\t\t// The `node.getAttribute` check was added for the sake of\n\t\t\t\t// `jQuery.globalEval` so that it can fake a nonce-containing node\n\t\t\t\t// via an object.\n\t\t\t\tval = node[ i ] || node.getAttribute && node.getAttribute( i );\n\t\t\t\tif ( val ) {\n\t\t\t\t\tscript.setAttribute( i, val );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdoc.head.appendChild( script ).parentNode.removeChild( script );\n\t}\n\n\nfunction toType( obj ) {\n\tif ( obj == null ) {\n\t\treturn obj + \"\";\n\t}\n\n\t// Support: Android <=2.3 only (functionish RegExp)\n\treturn typeof obj === \"object\" || typeof obj === \"function\" ?\n\t\tclass2type[ toString.call( obj ) ] || \"object\" :\n\t\ttypeof obj;\n}\n/* global Symbol */\n// Defining this global in .eslintrc.json would create a danger of using the global\n// unguarded in another place, it seems safer to define global only for this module\n\n\n\nvar\n\tversion = \"3.4.1\",\n\n\t// Define a local copy of jQuery\n\tjQuery = function( selector, context ) {\n\n\t\t// The jQuery object is actually just the init constructor 'enhanced'\n\t\t// Need init if jQuery is called (just allow error to be thrown if not included)\n\t\treturn new jQuery.fn.init( selector, context );\n\t},\n\n\t// Support: Android <=4.0 only\n\t// Make sure we trim BOM and NBSP\n\trtrim = /^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g;\n\njQuery.fn = jQuery.prototype = {\n\n\t// The current version of jQuery being used\n\tjquery: version,\n\n\tconstructor: jQuery,\n\n\t// The default length of a jQuery object is 0\n\tlength: 0,\n\n\ttoArray: function() {\n\t\treturn slice.call( this );\n\t},\n\n\t// Get the Nth element in the matched element set OR\n\t// Get the whole matched element set as a clean array\n\tget: function( num ) {\n\n\t\t// Return all the elements in a clean array\n\t\tif ( num == null ) {\n\t\t\treturn slice.call( this );\n\t\t}\n\n\t\t// Return just the one element from the set\n\t\treturn num < 0 ? this[ num + this.length ] : this[ num ];\n\t},\n\n\t// Take an array of elements and push it onto the stack\n\t// (returning the new matched element set)\n\tpushStack: function( elems ) {\n\n\t\t// Build a new jQuery matched element set\n\t\tvar ret = jQuery.merge( this.constructor(), elems );\n\n\t\t// Add the old object onto the stack (as a reference)\n\t\tret.prevObject = this;\n\n\t\t// Return the newly-formed element set\n\t\treturn ret;\n\t},\n\n\t// Execute a callback for every element in the matched set.\n\teach: function( callback ) {\n\t\treturn jQuery.each( this, callback );\n\t},\n\n\tmap: function( callback ) {\n\t\treturn this.pushStack( jQuery.map( this, function( elem, i ) {\n\t\t\treturn callback.call( elem, i, elem );\n\t\t} ) );\n\t},\n\n\tslice: function() {\n\t\treturn this.pushStack( slice.apply( this, arguments ) );\n\t},\n\n\tfirst: function() {\n\t\treturn this.eq( 0 );\n\t},\n\n\tlast: function() {\n\t\treturn this.eq( -1 );\n\t},\n\n\teq: function( i ) {\n\t\tvar len = this.length,\n\t\t\tj = +i + ( i < 0 ? len : 0 );\n\t\treturn this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] );\n\t},\n\n\tend: function() {\n\t\treturn this.prevObject || this.constructor();\n\t},\n\n\t// For internal use only.\n\t// Behaves like an Array's method, not like a jQuery method.\n\tpush: push,\n\tsort: arr.sort,\n\tsplice: arr.splice\n};\n\njQuery.extend = jQuery.fn.extend = function() {\n\tvar options, name, src, copy, copyIsArray, clone,\n\t\ttarget = arguments[ 0 ] || {},\n\t\ti = 1,\n\t\tlength = arguments.length,\n\t\tdeep = false;\n\n\t// Handle a deep copy situation\n\tif ( typeof target === \"boolean\" ) {\n\t\tdeep = target;\n\n\t\t// Skip the boolean and the target\n\t\ttarget = arguments[ i ] || {};\n\t\ti++;\n\t}\n\n\t// Handle case when target is a string or something (possible in deep copy)\n\tif ( typeof target !== \"object\" && !isFunction( target ) ) {\n\t\ttarget = {};\n\t}\n\n\t// Extend jQuery itself if only one argument is passed\n\tif ( i === length ) {\n\t\ttarget = this;\n\t\ti--;\n\t}\n\n\tfor ( ; i < length; i++ ) {\n\n\t\t// Only deal with non-null/undefined values\n\t\tif ( ( options = arguments[ i ] ) != null ) {\n\n\t\t\t// Extend the base object\n\t\t\tfor ( name in options ) {\n\t\t\t\tcopy = options[ name ];\n\n\t\t\t\t// Prevent Object.prototype pollution\n\t\t\t\t// Prevent never-ending loop\n\t\t\t\tif ( name === \"__proto__\" || target === copy ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Recurse if we're merging plain objects or arrays\n\t\t\t\tif ( deep && copy && ( jQuery.isPlainObject( copy ) ||\n\t\t\t\t\t( copyIsArray = Array.isArray( copy ) ) ) ) {\n\t\t\t\t\tsrc = target[ name ];\n\n\t\t\t\t\t// Ensure proper type for the source value\n\t\t\t\t\tif ( copyIsArray && !Array.isArray( src ) ) {\n\t\t\t\t\t\tclone = [];\n\t\t\t\t\t} else if ( !copyIsArray && !jQuery.isPlainObject( src ) ) {\n\t\t\t\t\t\tclone = {};\n\t\t\t\t\t} else {\n\t\t\t\t\t\tclone = src;\n\t\t\t\t\t}\n\t\t\t\t\tcopyIsArray = false;\n\n\t\t\t\t\t// Never move original objects, clone them\n\t\t\t\t\ttarget[ name ] = jQuery.extend( deep, clone, copy );\n\n\t\t\t\t// Don't bring in undefined values\n\t\t\t\t} else if ( copy !== undefined ) {\n\t\t\t\t\ttarget[ name ] = copy;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return the modified object\n\treturn target;\n};\n\njQuery.extend( {\n\n\t// Unique for each copy of jQuery on the page\n\texpando: \"jQuery\" + ( version + Math.random() ).replace( /\\D/g, \"\" ),\n\n\t// Assume jQuery is ready without the ready module\n\tisReady: true,\n\n\terror: function( msg ) {\n\t\tthrow new Error( msg );\n\t},\n\n\tnoop: function() {},\n\n\tisPlainObject: function( obj ) {\n\t\tvar proto, Ctor;\n\n\t\t// Detect obvious negatives\n\t\t// Use toString instead of jQuery.type to catch host objects\n\t\tif ( !obj || toString.call( obj ) !== \"[object Object]\" ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tproto = getProto( obj );\n\n\t\t// Objects with no prototype (e.g., `Object.create( null )`) are plain\n\t\tif ( !proto ) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Objects with prototype are plain iff they were constructed by a global Object function\n\t\tCtor = hasOwn.call( proto, \"constructor\" ) && proto.constructor;\n\t\treturn typeof Ctor === \"function\" && fnToString.call( Ctor ) === ObjectFunctionString;\n\t},\n\n\tisEmptyObject: function( obj ) {\n\t\tvar name;\n\n\t\tfor ( name in obj ) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t},\n\n\t// Evaluates a script in a global context\n\tglobalEval: function( code, options ) {\n\t\tDOMEval( code, { nonce: options && options.nonce } );\n\t},\n\n\teach: function( obj, callback ) {\n\t\tvar length, i = 0;\n\n\t\tif ( isArrayLike( obj ) ) {\n\t\t\tlength = obj.length;\n\t\t\tfor ( ; i < length; i++ ) {\n\t\t\t\tif ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i in obj ) {\n\t\t\t\tif ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn obj;\n\t},\n\n\t// Support: Android <=4.0 only\n\ttrim: function( text ) {\n\t\treturn text == null ?\n\t\t\t\"\" :\n\t\t\t( text + \"\" ).replace( rtrim, \"\" );\n\t},\n\n\t// results is for internal usage only\n\tmakeArray: function( arr, results ) {\n\t\tvar ret = results || [];\n\n\t\tif ( arr != null ) {\n\t\t\tif ( isArrayLike( Object( arr ) ) ) {\n\t\t\t\tjQuery.merge( ret,\n\t\t\t\t\ttypeof arr === \"string\" ?\n\t\t\t\t\t[ arr ] : arr\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tpush.call( ret, arr );\n\t\t\t}\n\t\t}\n\n\t\treturn ret;\n\t},\n\n\tinArray: function( elem, arr, i ) {\n\t\treturn arr == null ? -1 : indexOf.call( arr, elem, i );\n\t},\n\n\t// Support: Android <=4.0 only, PhantomJS 1 only\n\t// push.apply(_, arraylike) throws on ancient WebKit\n\tmerge: function( first, second ) {\n\t\tvar len = +second.length,\n\t\t\tj = 0,\n\t\t\ti = first.length;\n\n\t\tfor ( ; j < len; j++ ) {\n\t\t\tfirst[ i++ ] = second[ j ];\n\t\t}\n\n\t\tfirst.length = i;\n\n\t\treturn first;\n\t},\n\n\tgrep: function( elems, callback, invert ) {\n\t\tvar callbackInverse,\n\t\t\tmatches = [],\n\t\t\ti = 0,\n\t\t\tlength = elems.length,\n\t\t\tcallbackExpect = !invert;\n\n\t\t// Go through the array, only saving the items\n\t\t// that pass the validator function\n\t\tfor ( ; i < length; i++ ) {\n\t\t\tcallbackInverse = !callback( elems[ i ], i );\n\t\t\tif ( callbackInverse !== callbackExpect ) {\n\t\t\t\tmatches.push( elems[ i ] );\n\t\t\t}\n\t\t}\n\n\t\treturn matches;\n\t},\n\n\t// arg is for internal usage only\n\tmap: function( elems, callback, arg ) {\n\t\tvar length, value,\n\t\t\ti = 0,\n\t\t\tret = [];\n\n\t\t// Go through the array, translating each of the items to their new values\n\t\tif ( isArrayLike( elems ) ) {\n\t\t\tlength = elems.length;\n\t\t\tfor ( ; i < length; i++ ) {\n\t\t\t\tvalue = callback( elems[ i ], i, arg );\n\n\t\t\t\tif ( value != null ) {\n\t\t\t\t\tret.push( value );\n\t\t\t\t}\n\t\t\t}\n\n\t\t// Go through every key on the object,\n\t\t} else {\n\t\t\tfor ( i in elems ) {\n\t\t\t\tvalue = callback( elems[ i ], i, arg );\n\n\t\t\t\tif ( value != null ) {\n\t\t\t\t\tret.push( value );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Flatten any nested arrays\n\t\treturn concat.apply( [], ret );\n\t},\n\n\t// A global GUID counter for objects\n\tguid: 1,\n\n\t// jQuery.support is not used in Core but other projects attach their\n\t// properties to it so it needs to exist.\n\tsupport: support\n} );\n\nif ( typeof Symbol === \"function\" ) {\n\tjQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ];\n}\n\n// Populate the class2type map\njQuery.each( \"Boolean Number String Function Array Date RegExp Object Error Symbol\".split( \" \" ),\nfunction( i, name ) {\n\tclass2type[ \"[object \" + name + \"]\" ] = name.toLowerCase();\n} );\n\nfunction isArrayLike( obj ) {\n\n\t// Support: real iOS 8.2 only (not reproducible in simulator)\n\t// `in` check used to prevent JIT error (gh-2145)\n\t// hasOwn isn't used here due to false negatives\n\t// regarding Nodelist length in IE\n\tvar length = !!obj && \"length\" in obj && obj.length,\n\t\ttype = toType( obj );\n\n\tif ( isFunction( obj ) || isWindow( obj ) ) {\n\t\treturn false;\n\t}\n\n\treturn type === \"array\" || length === 0 ||\n\t\ttypeof length === \"number\" && length > 0 && ( length - 1 ) in obj;\n}\nvar Sizzle =\n/*!\n * Sizzle CSS Selector Engine v2.3.4\n * https://sizzlejs.com/\n *\n * Copyright JS Foundation and other contributors\n * Released under the MIT license\n * https://js.foundation/\n *\n * Date: 2019-04-08\n */\n(function( window ) {\n\nvar i,\n\tsupport,\n\tExpr,\n\tgetText,\n\tisXML,\n\ttokenize,\n\tcompile,\n\tselect,\n\toutermostContext,\n\tsortInput,\n\thasDuplicate,\n\n\t// Local document vars\n\tsetDocument,\n\tdocument,\n\tdocElem,\n\tdocumentIsHTML,\n\trbuggyQSA,\n\trbuggyMatches,\n\tmatches,\n\tcontains,\n\n\t// Instance-specific data\n\texpando = \"sizzle\" + 1 * new Date(),\n\tpreferredDoc = window.document,\n\tdirruns = 0,\n\tdone = 0,\n\tclassCache = createCache(),\n\ttokenCache = createCache(),\n\tcompilerCache = createCache(),\n\tnonnativeSelectorCache = createCache(),\n\tsortOrder = function( a, b ) {\n\t\tif ( a === b ) {\n\t\t\thasDuplicate = true;\n\t\t}\n\t\treturn 0;\n\t},\n\n\t// Instance methods\n\thasOwn = ({}).hasOwnProperty,\n\tarr = [],\n\tpop = arr.pop,\n\tpush_native = arr.push,\n\tpush = arr.push,\n\tslice = arr.slice,\n\t// Use a stripped-down indexOf as it's faster than native\n\t// https://jsperf.com/thor-indexof-vs-for/5\n\tindexOf = function( list, elem ) {\n\t\tvar i = 0,\n\t\t\tlen = list.length;\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( list[i] === elem ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t},\n\n\tbooleans = \"checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped\",\n\n\t// Regular expressions\n\n\t// http://www.w3.org/TR/css3-selectors/#whitespace\n\twhitespace = \"[\\\\x20\\\\t\\\\r\\\\n\\\\f]\",\n\n\t// http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier\n\tidentifier = \"(?:\\\\\\\\.|[\\\\w-]|[^\\0-\\\\xa0])+\",\n\n\t// Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors\n\tattributes = \"\\\\[\" + whitespace + \"*(\" + identifier + \")(?:\" + whitespace +\n\t\t// Operator (capture 2)\n\t\t\"*([*^$|!~]?=)\" + whitespace +\n\t\t// \"Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]\"\n\t\t\"*(?:'((?:\\\\\\\\.|[^\\\\\\\\'])*)'|\\\"((?:\\\\\\\\.|[^\\\\\\\\\\\"])*)\\\"|(\" + identifier + \"))|)\" + whitespace +\n\t\t\"*\\\\]\",\n\n\tpseudos = \":(\" + identifier + \")(?:\\\\((\" +\n\t\t// To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:\n\t\t// 1. quoted (capture 3; capture 4 or capture 5)\n\t\t\"('((?:\\\\\\\\.|[^\\\\\\\\'])*)'|\\\"((?:\\\\\\\\.|[^\\\\\\\\\\\"])*)\\\")|\" +\n\t\t// 2. simple (capture 6)\n\t\t\"((?:\\\\\\\\.|[^\\\\\\\\()[\\\\]]|\" + attributes + \")*)|\" +\n\t\t// 3. anything else (capture 2)\n\t\t\".*\" +\n\t\t\")\\\\)|)\",\n\n\t// Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter\n\trwhitespace = new RegExp( whitespace + \"+\", \"g\" ),\n\trtrim = new RegExp( \"^\" + whitespace + \"+|((?:^|[^\\\\\\\\])(?:\\\\\\\\.)*)\" + whitespace + \"+$\", \"g\" ),\n\n\trcomma = new RegExp( \"^\" + whitespace + \"*,\" + whitespace + \"*\" ),\n\trcombinators = new RegExp( \"^\" + whitespace + \"*([>+~]|\" + whitespace + \")\" + whitespace + \"*\" ),\n\trdescend = new RegExp( whitespace + \"|>\" ),\n\n\trpseudo = new RegExp( pseudos ),\n\tridentifier = new RegExp( \"^\" + identifier + \"$\" ),\n\n\tmatchExpr = {\n\t\t\"ID\": new RegExp( \"^#(\" + identifier + \")\" ),\n\t\t\"CLASS\": new RegExp( \"^\\\\.(\" + identifier + \")\" ),\n\t\t\"TAG\": new RegExp( \"^(\" + identifier + \"|[*])\" ),\n\t\t\"ATTR\": new RegExp( \"^\" + attributes ),\n\t\t\"PSEUDO\": new RegExp( \"^\" + pseudos ),\n\t\t\"CHILD\": new RegExp( \"^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\\\(\" + whitespace +\n\t\t\t\"*(even|odd|(([+-]|)(\\\\d*)n|)\" + whitespace + \"*(?:([+-]|)\" + whitespace +\n\t\t\t\"*(\\\\d+)|))\" + whitespace + \"*\\\\)|)\", \"i\" ),\n\t\t\"bool\": new RegExp( \"^(?:\" + booleans + \")$\", \"i\" ),\n\t\t// For use in libraries implementing .is()\n\t\t// We use this for POS matching in `select`\n\t\t\"needsContext\": new RegExp( \"^\" + whitespace + \"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\\\(\" +\n\t\t\twhitespace + \"*((?:-\\\\d)?\\\\d*)\" + whitespace + \"*\\\\)|)(?=[^-]|$)\", \"i\" )\n\t},\n\n\trhtml = /HTML$/i,\n\trinputs = /^(?:input|select|textarea|button)$/i,\n\trheader = /^h\\d$/i,\n\n\trnative = /^[^{]+\\{\\s*\\[native \\w/,\n\n\t// Easily-parseable/retrievable ID or TAG or CLASS selectors\n\trquickExpr = /^(?:#([\\w-]+)|(\\w+)|\\.([\\w-]+))$/,\n\n\trsibling = /[+~]/,\n\n\t// CSS escapes\n\t// http://www.w3.org/TR/CSS21/syndata.html#escaped-characters\n\trunescape = new RegExp( \"\\\\\\\\([\\\\da-f]{1,6}\" + whitespace + \"?|(\" + whitespace + \")|.)\", \"ig\" ),\n\tfunescape = function( _, escaped, escapedWhitespace ) {\n\t\tvar high = \"0x\" + escaped - 0x10000;\n\t\t// NaN means non-codepoint\n\t\t// Support: Firefox<24\n\t\t// Workaround erroneous numeric interpretation of +\"0x\"\n\t\treturn high !== high || escapedWhitespace ?\n\t\t\tescaped :\n\t\t\thigh < 0 ?\n\t\t\t\t// BMP codepoint\n\t\t\t\tString.fromCharCode( high + 0x10000 ) :\n\t\t\t\t// Supplemental Plane codepoint (surrogate pair)\n\t\t\t\tString.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );\n\t},\n\n\t// CSS string/identifier serialization\n\t// https://drafts.csswg.org/cssom/#common-serializing-idioms\n\trcssescape = /([\\0-\\x1f\\x7f]|^-?\\d)|^-$|[^\\0-\\x1f\\x7f-\\uFFFF\\w-]/g,\n\tfcssescape = function( ch, asCodePoint ) {\n\t\tif ( asCodePoint ) {\n\n\t\t\t// U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER\n\t\t\tif ( ch === \"\\0\" ) {\n\t\t\t\treturn \"\\uFFFD\";\n\t\t\t}\n\n\t\t\t// Control characters and (dependent upon position) numbers get escaped as code points\n\t\t\treturn ch.slice( 0, -1 ) + \"\\\\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + \" \";\n\t\t}\n\n\t\t// Other potentially-special ASCII characters get backslash-escaped\n\t\treturn \"\\\\\" + ch;\n\t},\n\n\t// Used for iframes\n\t// See setDocument()\n\t// Removing the function wrapper causes a \"Permission Denied\"\n\t// error in IE\n\tunloadHandler = function() {\n\t\tsetDocument();\n\t},\n\n\tinDisabledFieldset = addCombinator(\n\t\tfunction( elem ) {\n\t\t\treturn elem.disabled === true && elem.nodeName.toLowerCase() === \"fieldset\";\n\t\t},\n\t\t{ dir: \"parentNode\", next: \"legend\" }\n\t);\n\n// Optimize for push.apply( _, NodeList )\ntry {\n\tpush.apply(\n\t\t(arr = slice.call( preferredDoc.childNodes )),\n\t\tpreferredDoc.childNodes\n\t);\n\t// Support: Android<4.0\n\t// Detect silently failing push.apply\n\tarr[ preferredDoc.childNodes.length ].nodeType;\n} catch ( e ) {\n\tpush = { apply: arr.length ?\n\n\t\t// Leverage slice if possible\n\t\tfunction( target, els ) {\n\t\t\tpush_native.apply( target, slice.call(els) );\n\t\t} :\n\n\t\t// Support: IE<9\n\t\t// Otherwise append directly\n\t\tfunction( target, els ) {\n\t\t\tvar j = target.length,\n\t\t\t\ti = 0;\n\t\t\t// Can't trust NodeList.length\n\t\t\twhile ( (target[j++] = els[i++]) ) {}\n\t\t\ttarget.length = j - 1;\n\t\t}\n\t};\n}\n\nfunction Sizzle( selector, context, results, seed ) {\n\tvar m, i, elem, nid, match, groups, newSelector,\n\t\tnewContext = context && context.ownerDocument,\n\n\t\t// nodeType defaults to 9, since context defaults to document\n\t\tnodeType = context ? context.nodeType : 9;\n\n\tresults = results || [];\n\n\t// Return early from calls with invalid selector or context\n\tif ( typeof selector !== \"string\" || !selector ||\n\t\tnodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {\n\n\t\treturn results;\n\t}\n\n\t// Try to shortcut find operations (as opposed to filters) in HTML documents\n\tif ( !seed ) {\n\n\t\tif ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {\n\t\t\tsetDocument( context );\n\t\t}\n\t\tcontext = context || document;\n\n\t\tif ( documentIsHTML ) {\n\n\t\t\t// If the selector is sufficiently simple, try using a \"get*By*\" DOM method\n\t\t\t// (excepting DocumentFragment context, where the methods don't exist)\n\t\t\tif ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {\n\n\t\t\t\t// ID selector\n\t\t\t\tif ( (m = match[1]) ) {\n\n\t\t\t\t\t// Document context\n\t\t\t\t\tif ( nodeType === 9 ) {\n\t\t\t\t\t\tif ( (elem = context.getElementById( m )) ) {\n\n\t\t\t\t\t\t\t// Support: IE, Opera, Webkit\n\t\t\t\t\t\t\t// TODO: identify versions\n\t\t\t\t\t\t\t// getElementById can match elements by name instead of ID\n\t\t\t\t\t\t\tif ( elem.id === m ) {\n\t\t\t\t\t\t\t\tresults.push( elem );\n\t\t\t\t\t\t\t\treturn results;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn results;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t// Element context\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\t// Support: IE, Opera, Webkit\n\t\t\t\t\t\t// TODO: identify versions\n\t\t\t\t\t\t// getElementById can match elements by name instead of ID\n\t\t\t\t\t\tif ( newContext && (elem = newContext.getElementById( m )) &&\n\t\t\t\t\t\t\tcontains( context, elem ) &&\n\t\t\t\t\t\t\telem.id === m ) {\n\n\t\t\t\t\t\t\tresults.push( elem );\n\t\t\t\t\t\t\treturn results;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t// Type selector\n\t\t\t\t} else if ( match[2] ) {\n\t\t\t\t\tpush.apply( results, context.getElementsByTagName( selector ) );\n\t\t\t\t\treturn results;\n\n\t\t\t\t// Class selector\n\t\t\t\t} else if ( (m = match[3]) && support.getElementsByClassName &&\n\t\t\t\t\tcontext.getElementsByClassName ) {\n\n\t\t\t\t\tpush.apply( results, context.getElementsByClassName( m ) );\n\t\t\t\t\treturn results;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Take advantage of querySelectorAll\n\t\t\tif ( support.qsa &&\n\t\t\t\t!nonnativeSelectorCache[ selector + \" \" ] &&\n\t\t\t\t(!rbuggyQSA || !rbuggyQSA.test( selector )) &&\n\n\t\t\t\t// Support: IE 8 only\n\t\t\t\t// Exclude object elements\n\t\t\t\t(nodeType !== 1 || context.nodeName.toLowerCase() !== \"object\") ) {\n\n\t\t\t\tnewSelector = selector;\n\t\t\t\tnewContext = context;\n\n\t\t\t\t// qSA considers elements outside a scoping root when evaluating child or\n\t\t\t\t// descendant combinators, which is not what we want.\n\t\t\t\t// In such cases, we work around the behavior by prefixing every selector in the\n\t\t\t\t// list with an ID selector referencing the scope context.\n\t\t\t\t// Thanks to Andrew Dupont for this technique.\n\t\t\t\tif ( nodeType === 1 && rdescend.test( selector ) ) {\n\n\t\t\t\t\t// Capture the context ID, setting it first if necessary\n\t\t\t\t\tif ( (nid = context.getAttribute( \"id\" )) ) {\n\t\t\t\t\t\tnid = nid.replace( rcssescape, fcssescape );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontext.setAttribute( \"id\", (nid = expando) );\n\t\t\t\t\t}\n\n\t\t\t\t\t// Prefix every selector in the list\n\t\t\t\t\tgroups = tokenize( selector );\n\t\t\t\t\ti = groups.length;\n\t\t\t\t\twhile ( i-- ) {\n\t\t\t\t\t\tgroups[i] = \"#\" + nid + \" \" + toSelector( groups[i] );\n\t\t\t\t\t}\n\t\t\t\t\tnewSelector = groups.join( \",\" );\n\n\t\t\t\t\t// Expand context for sibling selectors\n\t\t\t\t\tnewContext = rsibling.test( selector ) && testContext( context.parentNode ) ||\n\t\t\t\t\t\tcontext;\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tpush.apply( results,\n\t\t\t\t\t\tnewContext.querySelectorAll( newSelector )\n\t\t\t\t\t);\n\t\t\t\t\treturn results;\n\t\t\t\t} catch ( qsaError ) {\n\t\t\t\t\tnonnativeSelectorCache( selector, true );\n\t\t\t\t} finally {\n\t\t\t\t\tif ( nid === expando ) {\n\t\t\t\t\t\tcontext.removeAttribute( \"id\" );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// All others\n\treturn select( selector.replace( rtrim, \"$1\" ), context, results, seed );\n}\n\n/**\n * Create key-value caches of limited size\n * @returns {function(string, object)} Returns the Object data after storing it on itself with\n *\tproperty name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)\n *\tdeleting the oldest entry\n */\nfunction createCache() {\n\tvar keys = [];\n\n\tfunction cache( key, value ) {\n\t\t// Use (key + \" \") to avoid collision with native prototype properties (see Issue #157)\n\t\tif ( keys.push( key + \" \" ) > Expr.cacheLength ) {\n\t\t\t// Only keep the most recent entries\n\t\t\tdelete cache[ keys.shift() ];\n\t\t}\n\t\treturn (cache[ key + \" \" ] = value);\n\t}\n\treturn cache;\n}\n\n/**\n * Mark a function for special use by Sizzle\n * @param {Function} fn The function to mark\n */\nfunction markFunction( fn ) {\n\tfn[ expando ] = true;\n\treturn fn;\n}\n\n/**\n * Support testing using an element\n * @param {Function} fn Passed the created element and returns a boolean result\n */\nfunction assert( fn ) {\n\tvar el = document.createElement(\"fieldset\");\n\n\ttry {\n\t\treturn !!fn( el );\n\t} catch (e) {\n\t\treturn false;\n\t} finally {\n\t\t// Remove from its parent by default\n\t\tif ( el.parentNode ) {\n\t\t\tel.parentNode.removeChild( el );\n\t\t}\n\t\t// release memory in IE\n\t\tel = null;\n\t}\n}\n\n/**\n * Adds the same handler for all of the specified attrs\n * @param {String} attrs Pipe-separated list of attributes\n * @param {Function} handler The method that will be applied\n */\nfunction addHandle( attrs, handler ) {\n\tvar arr = attrs.split(\"|\"),\n\t\ti = arr.length;\n\n\twhile ( i-- ) {\n\t\tExpr.attrHandle[ arr[i] ] = handler;\n\t}\n}\n\n/**\n * Checks document order of two siblings\n * @param {Element} a\n * @param {Element} b\n * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b\n */\nfunction siblingCheck( a, b ) {\n\tvar cur = b && a,\n\t\tdiff = cur && a.nodeType === 1 && b.nodeType === 1 &&\n\t\t\ta.sourceIndex - b.sourceIndex;\n\n\t// Use IE sourceIndex if available on both nodes\n\tif ( diff ) {\n\t\treturn diff;\n\t}\n\n\t// Check if b follows a\n\tif ( cur ) {\n\t\twhile ( (cur = cur.nextSibling) ) {\n\t\t\tif ( cur === b ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn a ? 1 : -1;\n}\n\n/**\n * Returns a function to use in pseudos for input types\n * @param {String} type\n */\nfunction createInputPseudo( type ) {\n\treturn function( elem ) {\n\t\tvar name = elem.nodeName.toLowerCase();\n\t\treturn name === \"input\" && elem.type === type;\n\t};\n}\n\n/**\n * Returns a function to use in pseudos for buttons\n * @param {String} type\n */\nfunction createButtonPseudo( type ) {\n\treturn function( elem ) {\n\t\tvar name = elem.nodeName.toLowerCase();\n\t\treturn (name === \"input\" || name === \"button\") && elem.type === type;\n\t};\n}\n\n/**\n * Returns a function to use in pseudos for :enabled/:disabled\n * @param {Boolean} disabled true for :disabled; false for :enabled\n */\nfunction createDisabledPseudo( disabled ) {\n\n\t// Known :disabled false positives: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable\n\treturn function( elem ) {\n\n\t\t// Only certain elements can match :enabled or :disabled\n\t\t// https://html.spec.whatwg.org/multipage/scripting.html#selector-enabled\n\t\t// https://html.spec.whatwg.org/multipage/scripting.html#selector-disabled\n\t\tif ( \"form\" in elem ) {\n\n\t\t\t// Check for inherited disabledness on relevant non-disabled elements:\n\t\t\t// * listed form-associated elements in a disabled fieldset\n\t\t\t//   https://html.spec.whatwg.org/multipage/forms.html#category-listed\n\t\t\t//   https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled\n\t\t\t// * option elements in a disabled optgroup\n\t\t\t//   https://html.spec.whatwg.org/multipage/forms.html#concept-option-disabled\n\t\t\t// All such elements have a \"form\" property.\n\t\t\tif ( elem.parentNode && elem.disabled === false ) {\n\n\t\t\t\t// Option elements defer to a parent optgroup if present\n\t\t\t\tif ( \"label\" in elem ) {\n\t\t\t\t\tif ( \"label\" in elem.parentNode ) {\n\t\t\t\t\t\treturn elem.parentNode.disabled === disabled;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn elem.disabled === disabled;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Support: IE 6 - 11\n\t\t\t\t// Use the isDisabled shortcut property to check for disabled fieldset ancestors\n\t\t\t\treturn elem.isDisabled === disabled ||\n\n\t\t\t\t\t// Where there is no isDisabled, check manually\n\t\t\t\t\t/* jshint -W018 */\n\t\t\t\t\telem.isDisabled !== !disabled &&\n\t\t\t\t\t\tinDisabledFieldset( elem ) === disabled;\n\t\t\t}\n\n\t\t\treturn elem.disabled === disabled;\n\n\t\t// Try to winnow out elements that can't be disabled before trusting the disabled property.\n\t\t// Some victims get caught in our net (label, legend, menu, track), but it shouldn't\n\t\t// even exist on them, let alone have a boolean value.\n\t\t} else if ( \"label\" in elem ) {\n\t\t\treturn elem.disabled === disabled;\n\t\t}\n\n\t\t// Remaining elements are neither :enabled nor :disabled\n\t\treturn false;\n\t};\n}\n\n/**\n * Returns a function to use in pseudos for positionals\n * @param {Function} fn\n */\nfunction createPositionalPseudo( fn ) {\n\treturn markFunction(function( argument ) {\n\t\targument = +argument;\n\t\treturn markFunction(function( seed, matches ) {\n\t\t\tvar j,\n\t\t\t\tmatchIndexes = fn( [], seed.length, argument ),\n\t\t\t\ti = matchIndexes.length;\n\n\t\t\t// Match elements found at the specified indexes\n\t\t\twhile ( i-- ) {\n\t\t\t\tif ( seed[ (j = matchIndexes[i]) ] ) {\n\t\t\t\t\tseed[j] = !(matches[j] = seed[j]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t});\n}\n\n/**\n * Checks a node for validity as a Sizzle context\n * @param {Element|Object=} context\n * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value\n */\nfunction testContext( context ) {\n\treturn context && typeof context.getElementsByTagName !== \"undefined\" && context;\n}\n\n// Expose support vars for convenience\nsupport = Sizzle.support = {};\n\n/**\n * Detects XML nodes\n * @param {Element|Object} elem An element or a document\n * @returns {Boolean} True iff elem is a non-HTML XML node\n */\nisXML = Sizzle.isXML = function( elem ) {\n\tvar namespace = elem.namespaceURI,\n\t\tdocElem = (elem.ownerDocument || elem).documentElement;\n\n\t// Support: IE <=8\n\t// Assume HTML when documentElement doesn't yet exist, such as inside loading iframes\n\t// https://bugs.jquery.com/ticket/4833\n\treturn !rhtml.test( namespace || docElem && docElem.nodeName || \"HTML\" );\n};\n\n/**\n * Sets document-related variables once based on the current document\n * @param {Element|Object} [doc] An element or document object to use to set the document\n * @returns {Object} Returns the current document\n */\nsetDocument = Sizzle.setDocument = function( node ) {\n\tvar hasCompare, subWindow,\n\t\tdoc = node ? node.ownerDocument || node : preferredDoc;\n\n\t// Return early if doc is invalid or already selected\n\tif ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {\n\t\treturn document;\n\t}\n\n\t// Update global variables\n\tdocument = doc;\n\tdocElem = document.documentElement;\n\tdocumentIsHTML = !isXML( document );\n\n\t// Support: IE 9-11, Edge\n\t// Accessing iframe documents after unload throws \"permission denied\" errors (jQuery #13936)\n\tif ( preferredDoc !== document &&\n\t\t(subWindow = document.defaultView) && subWindow.top !== subWindow ) {\n\n\t\t// Support: IE 11, Edge\n\t\tif ( subWindow.addEventListener ) {\n\t\t\tsubWindow.addEventListener( \"unload\", unloadHandler, false );\n\n\t\t// Support: IE 9 - 10 only\n\t\t} else if ( subWindow.attachEvent ) {\n\t\t\tsubWindow.attachEvent( \"onunload\", unloadHandler );\n\t\t}\n\t}\n\n\t/* Attributes\n\t---------------------------------------------------------------------- */\n\n\t// Support: IE<8\n\t// Verify that getAttribute really returns attributes and not properties\n\t// (excepting IE8 booleans)\n\tsupport.attributes = assert(function( el ) {\n\t\tel.className = \"i\";\n\t\treturn !el.getAttribute(\"className\");\n\t});\n\n\t/* getElement(s)By*\n\t---------------------------------------------------------------------- */\n\n\t// Check if getElementsByTagName(\"*\") returns only elements\n\tsupport.getElementsByTagName = assert(function( el ) {\n\t\tel.appendChild( document.createComment(\"\") );\n\t\treturn !el.getElementsByTagName(\"*\").length;\n\t});\n\n\t// Support: IE<9\n\tsupport.getElementsByClassName = rnative.test( document.getElementsByClassName );\n\n\t// Support: IE<10\n\t// Check if getElementById returns elements by name\n\t// The broken getElementById methods don't pick up programmatically-set names,\n\t// so use a roundabout getElementsByName test\n\tsupport.getById = assert(function( el ) {\n\t\tdocElem.appendChild( el ).id = expando;\n\t\treturn !document.getElementsByName || !document.getElementsByName( expando ).length;\n\t});\n\n\t// ID filter and find\n\tif ( support.getById ) {\n\t\tExpr.filter[\"ID\"] = function( id ) {\n\t\t\tvar attrId = id.replace( runescape, funescape );\n\t\t\treturn function( elem ) {\n\t\t\t\treturn elem.getAttribute(\"id\") === attrId;\n\t\t\t};\n\t\t};\n\t\tExpr.find[\"ID\"] = function( id, context ) {\n\t\t\tif ( typeof context.getElementById !== \"undefined\" && documentIsHTML ) {\n\t\t\t\tvar elem = context.getElementById( id );\n\t\t\t\treturn elem ? [ elem ] : [];\n\t\t\t}\n\t\t};\n\t} else {\n\t\tExpr.filter[\"ID\"] =  function( id ) {\n\t\t\tvar attrId = id.replace( runescape, funescape );\n\t\t\treturn function( elem ) {\n\t\t\t\tvar node = typeof elem.getAttributeNode !== \"undefined\" &&\n\t\t\t\t\telem.getAttributeNode(\"id\");\n\t\t\t\treturn node && node.value === attrId;\n\t\t\t};\n\t\t};\n\n\t\t// Support: IE 6 - 7 only\n\t\t// getElementById is not reliable as a find shortcut\n\t\tExpr.find[\"ID\"] = function( id, context ) {\n\t\t\tif ( typeof context.getElementById !== \"undefined\" && documentIsHTML ) {\n\t\t\t\tvar node, i, elems,\n\t\t\t\t\telem = context.getElementById( id );\n\n\t\t\t\tif ( elem ) {\n\n\t\t\t\t\t// Verify the id attribute\n\t\t\t\t\tnode = elem.getAttributeNode(\"id\");\n\t\t\t\t\tif ( node && node.value === id ) {\n\t\t\t\t\t\treturn [ elem ];\n\t\t\t\t\t}\n\n\t\t\t\t\t// Fall back on getElementsByName\n\t\t\t\t\telems = context.getElementsByName( id );\n\t\t\t\t\ti = 0;\n\t\t\t\t\twhile ( (elem = elems[i++]) ) {\n\t\t\t\t\t\tnode = elem.getAttributeNode(\"id\");\n\t\t\t\t\t\tif ( node && node.value === id ) {\n\t\t\t\t\t\t\treturn [ elem ];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn [];\n\t\t\t}\n\t\t};\n\t}\n\n\t// Tag\n\tExpr.find[\"TAG\"] = support.getElementsByTagName ?\n\t\tfunction( tag, context ) {\n\t\t\tif ( typeof context.getElementsByTagName !== \"undefined\" ) {\n\t\t\t\treturn context.getElementsByTagName( tag );\n\n\t\t\t// DocumentFragment nodes don't have gEBTN\n\t\t\t} else if ( support.qsa ) {\n\t\t\t\treturn context.querySelectorAll( tag );\n\t\t\t}\n\t\t} :\n\n\t\tfunction( tag, context ) {\n\t\t\tvar elem,\n\t\t\t\ttmp = [],\n\t\t\t\ti = 0,\n\t\t\t\t// By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too\n\t\t\t\tresults = context.getElementsByTagName( tag );\n\n\t\t\t// Filter out possible comments\n\t\t\tif ( tag === \"*\" ) {\n\t\t\t\twhile ( (elem = results[i++]) ) {\n\t\t\t\t\tif ( elem.nodeType === 1 ) {\n\t\t\t\t\t\ttmp.push( elem );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn tmp;\n\t\t\t}\n\t\t\treturn results;\n\t\t};\n\n\t// Class\n\tExpr.find[\"CLASS\"] = support.getElementsByClassName && function( className, context ) {\n\t\tif ( typeof context.getElementsByClassName !== \"undefined\" && documentIsHTML ) {\n\t\t\treturn context.getElementsByClassName( className );\n\t\t}\n\t};\n\n\t/* QSA/matchesSelector\n\t---------------------------------------------------------------------- */\n\n\t// QSA and matchesSelector support\n\n\t// matchesSelector(:active) reports false when true (IE9/Opera 11.5)\n\trbuggyMatches = [];\n\n\t// qSa(:focus) reports false when true (Chrome 21)\n\t// We allow this because of a bug in IE8/9 that throws an error\n\t// whenever `document.activeElement` is accessed on an iframe\n\t// So, we allow :focus to pass through QSA all the time to avoid the IE error\n\t// See https://bugs.jquery.com/ticket/13378\n\trbuggyQSA = [];\n\n\tif ( (support.qsa = rnative.test( document.querySelectorAll )) ) {\n\t\t// Build QSA regex\n\t\t// Regex strategy adopted from Diego Perini\n\t\tassert(function( el ) {\n\t\t\t// Select is set to empty string on purpose\n\t\t\t// This is to test IE's treatment of not explicitly\n\t\t\t// setting a boolean content attribute,\n\t\t\t// since its presence should be enough\n\t\t\t// https://bugs.jquery.com/ticket/12359\n\t\t\tdocElem.appendChild( el ).innerHTML = \"<a id='\" + expando + \"'></a>\" +\n\t\t\t\t\"<select id='\" + expando + \"-\\r\\\\' msallowcapture=''>\" +\n\t\t\t\t\"<option selected=''></option></select>\";\n\n\t\t\t// Support: IE8, Opera 11-12.16\n\t\t\t// Nothing should be selected when empty strings follow ^= or $= or *=\n\t\t\t// The test attribute must be unknown in Opera but \"safe\" for WinRT\n\t\t\t// https://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section\n\t\t\tif ( el.querySelectorAll(\"[msallowcapture^='']\").length ) {\n\t\t\t\trbuggyQSA.push( \"[*^$]=\" + whitespace + \"*(?:''|\\\"\\\")\" );\n\t\t\t}\n\n\t\t\t// Support: IE8\n\t\t\t// Boolean attributes and \"value\" are not treated correctly\n\t\t\tif ( !el.querySelectorAll(\"[selected]\").length ) {\n\t\t\t\trbuggyQSA.push( \"\\\\[\" + whitespace + \"*(?:value|\" + booleans + \")\" );\n\t\t\t}\n\n\t\t\t// Support: Chrome<29, Android<4.4, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.8+\n\t\t\tif ( !el.querySelectorAll( \"[id~=\" + expando + \"-]\" ).length ) {\n\t\t\t\trbuggyQSA.push(\"~=\");\n\t\t\t}\n\n\t\t\t// Webkit/Opera - :checked should return selected option elements\n\t\t\t// http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked\n\t\t\t// IE8 throws error here and will not see later tests\n\t\t\tif ( !el.querySelectorAll(\":checked\").length ) {\n\t\t\t\trbuggyQSA.push(\":checked\");\n\t\t\t}\n\n\t\t\t// Support: Safari 8+, iOS 8+\n\t\t\t// https://bugs.webkit.org/show_bug.cgi?id=136851\n\t\t\t// In-page `selector#id sibling-combinator selector` fails\n\t\t\tif ( !el.querySelectorAll( \"a#\" + expando + \"+*\" ).length ) {\n\t\t\t\trbuggyQSA.push(\".#.+[+~]\");\n\t\t\t}\n\t\t});\n\n\t\tassert(function( el ) {\n\t\t\tel.innerHTML = \"<a href='' disabled='disabled'></a>\" +\n\t\t\t\t\"<select disabled='disabled'><option/></select>\";\n\n\t\t\t// Support: Windows 8 Native Apps\n\t\t\t// The type and name attributes are restricted during .innerHTML assignment\n\t\t\tvar input = document.createElement(\"input\");\n\t\t\tinput.setAttribute( \"type\", \"hidden\" );\n\t\t\tel.appendChild( input ).setAttribute( \"name\", \"D\" );\n\n\t\t\t// Support: IE8\n\t\t\t// Enforce case-sensitivity of name attribute\n\t\t\tif ( el.querySelectorAll(\"[name=d]\").length ) {\n\t\t\t\trbuggyQSA.push( \"name\" + whitespace + \"*[*^$|!~]?=\" );\n\t\t\t}\n\n\t\t\t// FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)\n\t\t\t// IE8 throws error here and will not see later tests\n\t\t\tif ( el.querySelectorAll(\":enabled\").length !== 2 ) {\n\t\t\t\trbuggyQSA.push( \":enabled\", \":disabled\" );\n\t\t\t}\n\n\t\t\t// Support: IE9-11+\n\t\t\t// IE's :disabled selector does not pick up the children of disabled fieldsets\n\t\t\tdocElem.appendChild( el ).disabled = true;\n\t\t\tif ( el.querySelectorAll(\":disabled\").length !== 2 ) {\n\t\t\t\trbuggyQSA.push( \":enabled\", \":disabled\" );\n\t\t\t}\n\n\t\t\t// Opera 10-11 does not throw on post-comma invalid pseudos\n\t\t\tel.querySelectorAll(\"*,:x\");\n\t\t\trbuggyQSA.push(\",.*:\");\n\t\t});\n\t}\n\n\tif ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||\n\t\tdocElem.webkitMatchesSelector ||\n\t\tdocElem.mozMatchesSelector ||\n\t\tdocElem.oMatchesSelector ||\n\t\tdocElem.msMatchesSelector) )) ) {\n\n\t\tassert(function( el ) {\n\t\t\t// Check to see if it's possible to do matchesSelector\n\t\t\t// on a disconnected node (IE 9)\n\t\t\tsupport.disconnectedMatch = matches.call( el, \"*\" );\n\n\t\t\t// This should fail with an exception\n\t\t\t// Gecko does not error, returns false instead\n\t\t\tmatches.call( el, \"[s!='']:x\" );\n\t\t\trbuggyMatches.push( \"!=\", pseudos );\n\t\t});\n\t}\n\n\trbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join(\"|\") );\n\trbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join(\"|\") );\n\n\t/* Contains\n\t---------------------------------------------------------------------- */\n\thasCompare = rnative.test( docElem.compareDocumentPosition );\n\n\t// Element contains another\n\t// Purposefully self-exclusive\n\t// As in, an element does not contain itself\n\tcontains = hasCompare || rnative.test( docElem.contains ) ?\n\t\tfunction( a, b ) {\n\t\t\tvar adown = a.nodeType === 9 ? a.documentElement : a,\n\t\t\t\tbup = b && b.parentNode;\n\t\t\treturn a === bup || !!( bup && bup.nodeType === 1 && (\n\t\t\t\tadown.contains ?\n\t\t\t\t\tadown.contains( bup ) :\n\t\t\t\t\ta.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16\n\t\t\t));\n\t\t} :\n\t\tfunction( a, b ) {\n\t\t\tif ( b ) {\n\t\t\t\twhile ( (b = b.parentNode) ) {\n\t\t\t\t\tif ( b === a ) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t};\n\n\t/* Sorting\n\t---------------------------------------------------------------------- */\n\n\t// Document order sorting\n\tsortOrder = hasCompare ?\n\tfunction( a, b ) {\n\n\t\t// Flag for duplicate removal\n\t\tif ( a === b ) {\n\t\t\thasDuplicate = true;\n\t\t\treturn 0;\n\t\t}\n\n\t\t// Sort on method existence if only one input has compareDocumentPosition\n\t\tvar compare = !a.compareDocumentPosition - !b.compareDocumentPosition;\n\t\tif ( compare ) {\n\t\t\treturn compare;\n\t\t}\n\n\t\t// Calculate position if both inputs belong to the same document\n\t\tcompare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?\n\t\t\ta.compareDocumentPosition( b ) :\n\n\t\t\t// Otherwise we know they are disconnected\n\t\t\t1;\n\n\t\t// Disconnected nodes\n\t\tif ( compare & 1 ||\n\t\t\t(!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {\n\n\t\t\t// Choose the first element that is related to our preferred document\n\t\t\tif ( a === document || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif ( b === document || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\t// Maintain original order\n\t\t\treturn sortInput ?\n\t\t\t\t( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :\n\t\t\t\t0;\n\t\t}\n\n\t\treturn compare & 4 ? -1 : 1;\n\t} :\n\tfunction( a, b ) {\n\t\t// Exit early if the nodes are identical\n\t\tif ( a === b ) {\n\t\t\thasDuplicate = true;\n\t\t\treturn 0;\n\t\t}\n\n\t\tvar cur,\n\t\t\ti = 0,\n\t\t\taup = a.parentNode,\n\t\t\tbup = b.parentNode,\n\t\t\tap = [ a ],\n\t\t\tbp = [ b ];\n\n\t\t// Parentless nodes are either documents or disconnected\n\t\tif ( !aup || !bup ) {\n\t\t\treturn a === document ? -1 :\n\t\t\t\tb === document ? 1 :\n\t\t\t\taup ? -1 :\n\t\t\t\tbup ? 1 :\n\t\t\t\tsortInput ?\n\t\t\t\t( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :\n\t\t\t\t0;\n\n\t\t// If the nodes are siblings, we can do a quick check\n\t\t} else if ( aup === bup ) {\n\t\t\treturn siblingCheck( a, b );\n\t\t}\n\n\t\t// Otherwise we need full lists of their ancestors for comparison\n\t\tcur = a;\n\t\twhile ( (cur = cur.parentNode) ) {\n\t\t\tap.unshift( cur );\n\t\t}\n\t\tcur = b;\n\t\twhile ( (cur = cur.parentNode) ) {\n\t\t\tbp.unshift( cur );\n\t\t}\n\n\t\t// Walk down the tree looking for a discrepancy\n\t\twhile ( ap[i] === bp[i] ) {\n\t\t\ti++;\n\t\t}\n\n\t\treturn i ?\n\t\t\t// Do a sibling check if the nodes have a common ancestor\n\t\t\tsiblingCheck( ap[i], bp[i] ) :\n\n\t\t\t// Otherwise nodes in our document sort first\n\t\t\tap[i] === preferredDoc ? -1 :\n\t\t\tbp[i] === preferredDoc ? 1 :\n\t\t\t0;\n\t};\n\n\treturn document;\n};\n\nSizzle.matches = function( expr, elements ) {\n\treturn Sizzle( expr, null, null, elements );\n};\n\nSizzle.matchesSelector = function( elem, expr ) {\n\t// Set document vars if needed\n\tif ( ( elem.ownerDocument || elem ) !== document ) {\n\t\tsetDocument( elem );\n\t}\n\n\tif ( support.matchesSelector && documentIsHTML &&\n\t\t!nonnativeSelectorCache[ expr + \" \" ] &&\n\t\t( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&\n\t\t( !rbuggyQSA     || !rbuggyQSA.test( expr ) ) ) {\n\n\t\ttry {\n\t\t\tvar ret = matches.call( elem, expr );\n\n\t\t\t// IE 9's matchesSelector returns false on disconnected nodes\n\t\t\tif ( ret || support.disconnectedMatch ||\n\t\t\t\t\t// As well, disconnected nodes are said to be in a document\n\t\t\t\t\t// fragment in IE 9\n\t\t\t\t\telem.document && elem.document.nodeType !== 11 ) {\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tnonnativeSelectorCache( expr, true );\n\t\t}\n\t}\n\n\treturn Sizzle( expr, document, null, [ elem ] ).length > 0;\n};\n\nSizzle.contains = function( context, elem ) {\n\t// Set document vars if needed\n\tif ( ( context.ownerDocument || context ) !== document ) {\n\t\tsetDocument( context );\n\t}\n\treturn contains( context, elem );\n};\n\nSizzle.attr = function( elem, name ) {\n\t// Set document vars if needed\n\tif ( ( elem.ownerDocument || elem ) !== document ) {\n\t\tsetDocument( elem );\n\t}\n\n\tvar fn = Expr.attrHandle[ name.toLowerCase() ],\n\t\t// Don't get fooled by Object.prototype properties (jQuery #13807)\n\t\tval = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?\n\t\t\tfn( elem, name, !documentIsHTML ) :\n\t\t\tundefined;\n\n\treturn val !== undefined ?\n\t\tval :\n\t\tsupport.attributes || !documentIsHTML ?\n\t\t\telem.getAttribute( name ) :\n\t\t\t(val = elem.getAttributeNode(name)) && val.specified ?\n\t\t\t\tval.value :\n\t\t\t\tnull;\n};\n\nSizzle.escape = function( sel ) {\n\treturn (sel + \"\").replace( rcssescape, fcssescape );\n};\n\nSizzle.error = function( msg ) {\n\tthrow new Error( \"Syntax error, unrecognized expression: \" + msg );\n};\n\n/**\n * Document sorting and removing duplicates\n * @param {ArrayLike} results\n */\nSizzle.uniqueSort = function( results ) {\n\tvar elem,\n\t\tduplicates = [],\n\t\tj = 0,\n\t\ti = 0;\n\n\t// Unless we *know* we can detect duplicates, assume their presence\n\thasDuplicate = !support.detectDuplicates;\n\tsortInput = !support.sortStable && results.slice( 0 );\n\tresults.sort( sortOrder );\n\n\tif ( hasDuplicate ) {\n\t\twhile ( (elem = results[i++]) ) {\n\t\t\tif ( elem === results[ i ] ) {\n\t\t\t\tj = duplicates.push( i );\n\t\t\t}\n\t\t}\n\t\twhile ( j-- ) {\n\t\t\tresults.splice( duplicates[ j ], 1 );\n\t\t}\n\t}\n\n\t// Clear input after sorting to release objects\n\t// See https://github.com/jquery/sizzle/pull/225\n\tsortInput = null;\n\n\treturn results;\n};\n\n/**\n * Utility function for retrieving the text value of an array of DOM nodes\n * @param {Array|Element} elem\n */\ngetText = Sizzle.getText = function( elem ) {\n\tvar node,\n\t\tret = \"\",\n\t\ti = 0,\n\t\tnodeType = elem.nodeType;\n\n\tif ( !nodeType ) {\n\t\t// If no nodeType, this is expected to be an array\n\t\twhile ( (node = elem[i++]) ) {\n\t\t\t// Do not traverse comment nodes\n\t\t\tret += getText( node );\n\t\t}\n\t} else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {\n\t\t// Use textContent for elements\n\t\t// innerText usage removed for consistency of new lines (jQuery #11153)\n\t\tif ( typeof elem.textContent === \"string\" ) {\n\t\t\treturn elem.textContent;\n\t\t} else {\n\t\t\t// Traverse its children\n\t\t\tfor ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {\n\t\t\t\tret += getText( elem );\n\t\t\t}\n\t\t}\n\t} else if ( nodeType === 3 || nodeType === 4 ) {\n\t\treturn elem.nodeValue;\n\t}\n\t// Do not include comment or processing instruction nodes\n\n\treturn ret;\n};\n\nExpr = Sizzle.selectors = {\n\n\t// Can be adjusted by the user\n\tcacheLength: 50,\n\n\tcreatePseudo: markFunction,\n\n\tmatch: matchExpr,\n\n\tattrHandle: {},\n\n\tfind: {},\n\n\trelative: {\n\t\t\">\": { dir: \"parentNode\", first: true },\n\t\t\" \": { dir: \"parentNode\" },\n\t\t\"+\": { dir: \"previousSibling\", first: true },\n\t\t\"~\": { dir: \"previousSibling\" }\n\t},\n\n\tpreFilter: {\n\t\t\"ATTR\": function( match ) {\n\t\t\tmatch[1] = match[1].replace( runescape, funescape );\n\n\t\t\t// Move the given value to match[3] whether quoted or unquoted\n\t\t\tmatch[3] = ( match[3] || match[4] || match[5] || \"\" ).replace( runescape, funescape );\n\n\t\t\tif ( match[2] === \"~=\" ) {\n\t\t\t\tmatch[3] = \" \" + match[3] + \" \";\n\t\t\t}\n\n\t\t\treturn match.slice( 0, 4 );\n\t\t},\n\n\t\t\"CHILD\": function( match ) {\n\t\t\t/* matches from matchExpr[\"CHILD\"]\n\t\t\t\t1 type (only|nth|...)\n\t\t\t\t2 what (child|of-type)\n\t\t\t\t3 argument (even|odd|\\d*|\\d*n([+-]\\d+)?|...)\n\t\t\t\t4 xn-component of xn+y argument ([+-]?\\d*n|)\n\t\t\t\t5 sign of xn-component\n\t\t\t\t6 x of xn-component\n\t\t\t\t7 sign of y-component\n\t\t\t\t8 y of y-component\n\t\t\t*/\n\t\t\tmatch[1] = match[1].toLowerCase();\n\n\t\t\tif ( match[1].slice( 0, 3 ) === \"nth\" ) {\n\t\t\t\t// nth-* requires argument\n\t\t\t\tif ( !match[3] ) {\n\t\t\t\t\tSizzle.error( match[0] );\n\t\t\t\t}\n\n\t\t\t\t// numeric x and y parameters for Expr.filter.CHILD\n\t\t\t\t// remember that false/true cast respectively to 0/1\n\t\t\t\tmatch[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === \"even\" || match[3] === \"odd\" ) );\n\t\t\t\tmatch[5] = +( ( match[7] + match[8] ) || match[3] === \"odd\" );\n\n\t\t\t// other types prohibit arguments\n\t\t\t} else if ( match[3] ) {\n\t\t\t\tSizzle.error( match[0] );\n\t\t\t}\n\n\t\t\treturn match;\n\t\t},\n\n\t\t\"PSEUDO\": function( match ) {\n\t\t\tvar excess,\n\t\t\t\tunquoted = !match[6] && match[2];\n\n\t\t\tif ( matchExpr[\"CHILD\"].test( match[0] ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// Accept quoted arguments as-is\n\t\t\tif ( match[3] ) {\n\t\t\t\tmatch[2] = match[4] || match[5] || \"\";\n\n\t\t\t// Strip excess characters from unquoted arguments\n\t\t\t} else if ( unquoted && rpseudo.test( unquoted ) &&\n\t\t\t\t// Get excess from tokenize (recursively)\n\t\t\t\t(excess = tokenize( unquoted, true )) &&\n\t\t\t\t// advance to the next closing parenthesis\n\t\t\t\t(excess = unquoted.indexOf( \")\", unquoted.length - excess ) - unquoted.length) ) {\n\n\t\t\t\t// excess is a negative index\n\t\t\t\tmatch[0] = match[0].slice( 0, excess );\n\t\t\t\tmatch[2] = unquoted.slice( 0, excess );\n\t\t\t}\n\n\t\t\t// Return only captures needed by the pseudo filter method (type and argument)\n\t\t\treturn match.slice( 0, 3 );\n\t\t}\n\t},\n\n\tfilter: {\n\n\t\t\"TAG\": function( nodeNameSelector ) {\n\t\t\tvar nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();\n\t\t\treturn nodeNameSelector === \"*\" ?\n\t\t\t\tfunction() { return true; } :\n\t\t\t\tfunction( elem ) {\n\t\t\t\t\treturn elem.nodeName && elem.nodeName.toLowerCase() === nodeName;\n\t\t\t\t};\n\t\t},\n\n\t\t\"CLASS\": function( className ) {\n\t\t\tvar pattern = classCache[ className + \" \" ];\n\n\t\t\treturn pattern ||\n\t\t\t\t(pattern = new RegExp( \"(^|\" + whitespace + \")\" + className + \"(\" + whitespace + \"|$)\" )) &&\n\t\t\t\tclassCache( className, function( elem ) {\n\t\t\t\t\treturn pattern.test( typeof elem.className === \"string\" && elem.className || typeof elem.getAttribute !== \"undefined\" && elem.getAttribute(\"class\") || \"\" );\n\t\t\t\t});\n\t\t},\n\n\t\t\"ATTR\": function( name, operator, check ) {\n\t\t\treturn function( elem ) {\n\t\t\t\tvar result = Sizzle.attr( elem, name );\n\n\t\t\t\tif ( result == null ) {\n\t\t\t\t\treturn operator === \"!=\";\n\t\t\t\t}\n\t\t\t\tif ( !operator ) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tresult += \"\";\n\n\t\t\t\treturn operator === \"=\" ? result === check :\n\t\t\t\t\toperator === \"!=\" ? result !== check :\n\t\t\t\t\toperator === \"^=\" ? check && result.indexOf( check ) === 0 :\n\t\t\t\t\toperator === \"*=\" ? check && result.indexOf( check ) > -1 :\n\t\t\t\t\toperator === \"$=\" ? check && result.slice( -check.length ) === check :\n\t\t\t\t\toperator === \"~=\" ? ( \" \" + result.replace( rwhitespace, \" \" ) + \" \" ).indexOf( check ) > -1 :\n\t\t\t\t\toperator === \"|=\" ? result === check || result.slice( 0, check.length + 1 ) === check + \"-\" :\n\t\t\t\t\tfalse;\n\t\t\t};\n\t\t},\n\n\t\t\"CHILD\": function( type, what, argument, first, last ) {\n\t\t\tvar simple = type.slice( 0, 3 ) !== \"nth\",\n\t\t\t\tforward = type.slice( -4 ) !== \"last\",\n\t\t\t\tofType = what === \"of-type\";\n\n\t\t\treturn first === 1 && last === 0 ?\n\n\t\t\t\t// Shortcut for :nth-*(n)\n\t\t\t\tfunction( elem ) {\n\t\t\t\t\treturn !!elem.parentNode;\n\t\t\t\t} :\n\n\t\t\t\tfunction( elem, context, xml ) {\n\t\t\t\t\tvar cache, uniqueCache, outerCache, node, nodeIndex, start,\n\t\t\t\t\t\tdir = simple !== forward ? \"nextSibling\" : \"previousSibling\",\n\t\t\t\t\t\tparent = elem.parentNode,\n\t\t\t\t\t\tname = ofType && elem.nodeName.toLowerCase(),\n\t\t\t\t\t\tuseCache = !xml && !ofType,\n\t\t\t\t\t\tdiff = false;\n\n\t\t\t\t\tif ( parent ) {\n\n\t\t\t\t\t\t// :(first|last|only)-(child|of-type)\n\t\t\t\t\t\tif ( simple ) {\n\t\t\t\t\t\t\twhile ( dir ) {\n\t\t\t\t\t\t\t\tnode = elem;\n\t\t\t\t\t\t\t\twhile ( (node = node[ dir ]) ) {\n\t\t\t\t\t\t\t\t\tif ( ofType ?\n\t\t\t\t\t\t\t\t\t\tnode.nodeName.toLowerCase() === name :\n\t\t\t\t\t\t\t\t\t\tnode.nodeType === 1 ) {\n\n\t\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Reverse direction for :only-* (if we haven't yet done so)\n\t\t\t\t\t\t\t\tstart = dir = type === \"only\" && !start && \"nextSibling\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tstart = [ forward ? parent.firstChild : parent.lastChild ];\n\n\t\t\t\t\t\t// non-xml :nth-child(...) stores cache data on `parent`\n\t\t\t\t\t\tif ( forward && useCache ) {\n\n\t\t\t\t\t\t\t// Seek `elem` from a previously-cached index\n\n\t\t\t\t\t\t\t// ...in a gzip-friendly way\n\t\t\t\t\t\t\tnode = parent;\n\t\t\t\t\t\t\touterCache = node[ expando ] || (node[ expando ] = {});\n\n\t\t\t\t\t\t\t// Support: IE <9 only\n\t\t\t\t\t\t\t// Defend against cloned attroperties (jQuery gh-1709)\n\t\t\t\t\t\t\tuniqueCache = outerCache[ node.uniqueID ] ||\n\t\t\t\t\t\t\t\t(outerCache[ node.uniqueID ] = {});\n\n\t\t\t\t\t\t\tcache = uniqueCache[ type ] || [];\n\t\t\t\t\t\t\tnodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];\n\t\t\t\t\t\t\tdiff = nodeIndex && cache[ 2 ];\n\t\t\t\t\t\t\tnode = nodeIndex && parent.childNodes[ nodeIndex ];\n\n\t\t\t\t\t\t\twhile ( (node = ++nodeIndex && node && node[ dir ] ||\n\n\t\t\t\t\t\t\t\t// Fallback to seeking `elem` from the start\n\t\t\t\t\t\t\t\t(diff = nodeIndex = 0) || start.pop()) ) {\n\n\t\t\t\t\t\t\t\t// When found, cache indexes on `parent` and break\n\t\t\t\t\t\t\t\tif ( node.nodeType === 1 && ++diff && node === elem ) {\n\t\t\t\t\t\t\t\t\tuniqueCache[ type ] = [ dirruns, nodeIndex, diff ];\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Use previously-cached element index if available\n\t\t\t\t\t\t\tif ( useCache ) {\n\t\t\t\t\t\t\t\t// ...in a gzip-friendly way\n\t\t\t\t\t\t\t\tnode = elem;\n\t\t\t\t\t\t\t\touterCache = node[ expando ] || (node[ expando ] = {});\n\n\t\t\t\t\t\t\t\t// Support: IE <9 only\n\t\t\t\t\t\t\t\t// Defend against cloned attroperties (jQuery gh-1709)\n\t\t\t\t\t\t\t\tuniqueCache = outerCache[ node.uniqueID ] ||\n\t\t\t\t\t\t\t\t\t(outerCache[ node.uniqueID ] = {});\n\n\t\t\t\t\t\t\t\tcache = uniqueCache[ type ] || [];\n\t\t\t\t\t\t\t\tnodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];\n\t\t\t\t\t\t\t\tdiff = nodeIndex;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// xml :nth-child(...)\n\t\t\t\t\t\t\t// or :nth-last-child(...) or :nth(-last)?-of-type(...)\n\t\t\t\t\t\t\tif ( diff === false ) {\n\t\t\t\t\t\t\t\t// Use the same loop as above to seek `elem` from the start\n\t\t\t\t\t\t\t\twhile ( (node = ++nodeIndex && node && node[ dir ] ||\n\t\t\t\t\t\t\t\t\t(diff = nodeIndex = 0) || start.pop()) ) {\n\n\t\t\t\t\t\t\t\t\tif ( ( ofType ?\n\t\t\t\t\t\t\t\t\t\tnode.nodeName.toLowerCase() === name :\n\t\t\t\t\t\t\t\t\t\tnode.nodeType === 1 ) &&\n\t\t\t\t\t\t\t\t\t\t++diff ) {\n\n\t\t\t\t\t\t\t\t\t\t// Cache the index of each encountered element\n\t\t\t\t\t\t\t\t\t\tif ( useCache ) {\n\t\t\t\t\t\t\t\t\t\t\touterCache = node[ expando ] || (node[ expando ] = {});\n\n\t\t\t\t\t\t\t\t\t\t\t// Support: IE <9 only\n\t\t\t\t\t\t\t\t\t\t\t// Defend against cloned attroperties (jQuery gh-1709)\n\t\t\t\t\t\t\t\t\t\t\tuniqueCache = outerCache[ node.uniqueID ] ||\n\t\t\t\t\t\t\t\t\t\t\t\t(outerCache[ node.uniqueID ] = {});\n\n\t\t\t\t\t\t\t\t\t\t\tuniqueCache[ type ] = [ dirruns, diff ];\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tif ( node === elem ) {\n\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Incorporate the offset, then check against cycle size\n\t\t\t\t\t\tdiff -= last;\n\t\t\t\t\t\treturn diff === first || ( diff % first === 0 && diff / first >= 0 );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t},\n\n\t\t\"PSEUDO\": function( pseudo, argument ) {\n\t\t\t// pseudo-class names are case-insensitive\n\t\t\t// http://www.w3.org/TR/selectors/#pseudo-classes\n\t\t\t// Prioritize by case sensitivity in case custom pseudos are added with uppercase letters\n\t\t\t// Remember that setFilters inherits from pseudos\n\t\t\tvar args,\n\t\t\t\tfn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||\n\t\t\t\t\tSizzle.error( \"unsupported pseudo: \" + pseudo );\n\n\t\t\t// The user may use createPseudo to indicate that\n\t\t\t// arguments are needed to create the filter function\n\t\t\t// just as Sizzle does\n\t\t\tif ( fn[ expando ] ) {\n\t\t\t\treturn fn( argument );\n\t\t\t}\n\n\t\t\t// But maintain support for old signatures\n\t\t\tif ( fn.length > 1 ) {\n\t\t\t\targs = [ pseudo, pseudo, \"\", argument ];\n\t\t\t\treturn Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?\n\t\t\t\t\tmarkFunction(function( seed, matches ) {\n\t\t\t\t\t\tvar idx,\n\t\t\t\t\t\t\tmatched = fn( seed, argument ),\n\t\t\t\t\t\t\ti = matched.length;\n\t\t\t\t\t\twhile ( i-- ) {\n\t\t\t\t\t\t\tidx = indexOf( seed, matched[i] );\n\t\t\t\t\t\t\tseed[ idx ] = !( matches[ idx ] = matched[i] );\n\t\t\t\t\t\t}\n\t\t\t\t\t}) :\n\t\t\t\t\tfunction( elem ) {\n\t\t\t\t\t\treturn fn( elem, 0, args );\n\t\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn fn;\n\t\t}\n\t},\n\n\tpseudos: {\n\t\t// Potentially complex pseudos\n\t\t\"not\": markFunction(function( selector ) {\n\t\t\t// Trim the selector passed to compile\n\t\t\t// to avoid treating leading and trailing\n\t\t\t// spaces as combinators\n\t\t\tvar input = [],\n\t\t\t\tresults = [],\n\t\t\t\tmatcher = compile( selector.replace( rtrim, \"$1\" ) );\n\n\t\t\treturn matcher[ expando ] ?\n\t\t\t\tmarkFunction(function( seed, matches, context, xml ) {\n\t\t\t\t\tvar elem,\n\t\t\t\t\t\tunmatched = matcher( seed, null, xml, [] ),\n\t\t\t\t\t\ti = seed.length;\n\n\t\t\t\t\t// Match elements unmatched by `matcher`\n\t\t\t\t\twhile ( i-- ) {\n\t\t\t\t\t\tif ( (elem = unmatched[i]) ) {\n\t\t\t\t\t\t\tseed[i] = !(matches[i] = elem);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}) :\n\t\t\t\tfunction( elem, context, xml ) {\n\t\t\t\t\tinput[0] = elem;\n\t\t\t\t\tmatcher( input, null, xml, results );\n\t\t\t\t\t// Don't keep the element (issue #299)\n\t\t\t\t\tinput[0] = null;\n\t\t\t\t\treturn !results.pop();\n\t\t\t\t};\n\t\t}),\n\n\t\t\"has\": markFunction(function( selector ) {\n\t\t\treturn function( elem ) {\n\t\t\t\treturn Sizzle( selector, elem ).length > 0;\n\t\t\t};\n\t\t}),\n\n\t\t\"contains\": markFunction(function( text ) {\n\t\t\ttext = text.replace( runescape, funescape );\n\t\t\treturn function( elem ) {\n\t\t\t\treturn ( elem.textContent || getText( elem ) ).indexOf( text ) > -1;\n\t\t\t};\n\t\t}),\n\n\t\t// \"Whether an element is represented by a :lang() selector\n\t\t// is based solely on the element's language value\n\t\t// being equal to the identifier C,\n\t\t// or beginning with the identifier C immediately followed by \"-\".\n\t\t// The matching of C against the element's language value is performed case-insensitively.\n\t\t// The identifier C does not have to be a valid language name.\"\n\t\t// http://www.w3.org/TR/selectors/#lang-pseudo\n\t\t\"lang\": markFunction( function( lang ) {\n\t\t\t// lang value must be a valid identifier\n\t\t\tif ( !ridentifier.test(lang || \"\") ) {\n\t\t\t\tSizzle.error( \"unsupported lang: \" + lang );\n\t\t\t}\n\t\t\tlang = lang.replace( runescape, funescape ).toLowerCase();\n\t\t\treturn function( elem ) {\n\t\t\t\tvar elemLang;\n\t\t\t\tdo {\n\t\t\t\t\tif ( (elemLang = documentIsHTML ?\n\t\t\t\t\t\telem.lang :\n\t\t\t\t\t\telem.getAttribute(\"xml:lang\") || elem.getAttribute(\"lang\")) ) {\n\n\t\t\t\t\t\telemLang = elemLang.toLowerCase();\n\t\t\t\t\t\treturn elemLang === lang || elemLang.indexOf( lang + \"-\" ) === 0;\n\t\t\t\t\t}\n\t\t\t\t} while ( (elem = elem.parentNode) && elem.nodeType === 1 );\n\t\t\t\treturn false;\n\t\t\t};\n\t\t}),\n\n\t\t// Miscellaneous\n\t\t\"target\": function( elem ) {\n\t\t\tvar hash = window.location && window.location.hash;\n\t\t\treturn hash && hash.slice( 1 ) === elem.id;\n\t\t},\n\n\t\t\"root\": function( elem ) {\n\t\t\treturn elem === docElem;\n\t\t},\n\n\t\t\"focus\": function( elem ) {\n\t\t\treturn elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);\n\t\t},\n\n\t\t// Boolean properties\n\t\t\"enabled\": createDisabledPseudo( false ),\n\t\t\"disabled\": createDisabledPseudo( true ),\n\n\t\t\"checked\": function( elem ) {\n\t\t\t// In CSS3, :checked should return both checked and selected elements\n\t\t\t// http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked\n\t\t\tvar nodeName = elem.nodeName.toLowerCase();\n\t\t\treturn (nodeName === \"input\" && !!elem.checked) || (nodeName === \"option\" && !!elem.selected);\n\t\t},\n\n\t\t\"selected\": function( elem ) {\n\t\t\t// Accessing this property makes selected-by-default\n\t\t\t// options in Safari work properly\n\t\t\tif ( elem.parentNode ) {\n\t\t\t\telem.parentNode.selectedIndex;\n\t\t\t}\n\n\t\t\treturn elem.selected === true;\n\t\t},\n\n\t\t// Contents\n\t\t\"empty\": function( elem ) {\n\t\t\t// http://www.w3.org/TR/selectors/#empty-pseudo\n\t\t\t// :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),\n\t\t\t//   but not by others (comment: 8; processing instruction: 7; etc.)\n\t\t\t// nodeType < 6 works because attributes (2) do not appear as children\n\t\t\tfor ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {\n\t\t\t\tif ( elem.nodeType < 6 ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t},\n\n\t\t\"parent\": function( elem ) {\n\t\t\treturn !Expr.pseudos[\"empty\"]( elem );\n\t\t},\n\n\t\t// Element/input types\n\t\t\"header\": function( elem ) {\n\t\t\treturn rheader.test( elem.nodeName );\n\t\t},\n\n\t\t\"input\": function( elem ) {\n\t\t\treturn rinputs.test( elem.nodeName );\n\t\t},\n\n\t\t\"button\": function( elem ) {\n\t\t\tvar name = elem.nodeName.toLowerCase();\n\t\t\treturn name === \"input\" && elem.type === \"button\" || name === \"button\";\n\t\t},\n\n\t\t\"text\": function( elem ) {\n\t\t\tvar attr;\n\t\t\treturn elem.nodeName.toLowerCase() === \"input\" &&\n\t\t\t\telem.type === \"text\" &&\n\n\t\t\t\t// Support: IE<8\n\t\t\t\t// New HTML5 attribute values (e.g., \"search\") appear with elem.type === \"text\"\n\t\t\t\t( (attr = elem.getAttribute(\"type\")) == null || attr.toLowerCase() === \"text\" );\n\t\t},\n\n\t\t// Position-in-collection\n\t\t\"first\": createPositionalPseudo(function() {\n\t\t\treturn [ 0 ];\n\t\t}),\n\n\t\t\"last\": createPositionalPseudo(function( matchIndexes, length ) {\n\t\t\treturn [ length - 1 ];\n\t\t}),\n\n\t\t\"eq\": createPositionalPseudo(function( matchIndexes, length, argument ) {\n\t\t\treturn [ argument < 0 ? argument + length : argument ];\n\t\t}),\n\n\t\t\"even\": createPositionalPseudo(function( matchIndexes, length ) {\n\t\t\tvar i = 0;\n\t\t\tfor ( ; i < length; i += 2 ) {\n\t\t\t\tmatchIndexes.push( i );\n\t\t\t}\n\t\t\treturn matchIndexes;\n\t\t}),\n\n\t\t\"odd\": createPositionalPseudo(function( matchIndexes, length ) {\n\t\t\tvar i = 1;\n\t\t\tfor ( ; i < length; i += 2 ) {\n\t\t\t\tmatchIndexes.push( i );\n\t\t\t}\n\t\t\treturn matchIndexes;\n\t\t}),\n\n\t\t\"lt\": createPositionalPseudo(function( matchIndexes, length, argument ) {\n\t\t\tvar i = argument < 0 ?\n\t\t\t\targument + length :\n\t\t\t\targument > length ?\n\t\t\t\t\tlength :\n\t\t\t\t\targument;\n\t\t\tfor ( ; --i >= 0; ) {\n\t\t\t\tmatchIndexes.push( i );\n\t\t\t}\n\t\t\treturn matchIndexes;\n\t\t}),\n\n\t\t\"gt\": createPositionalPseudo(function( matchIndexes, length, argument ) {\n\t\t\tvar i = argument < 0 ? argument + length : argument;\n\t\t\tfor ( ; ++i < length; ) {\n\t\t\t\tmatchIndexes.push( i );\n\t\t\t}\n\t\t\treturn matchIndexes;\n\t\t})\n\t}\n};\n\nExpr.pseudos[\"nth\"] = Expr.pseudos[\"eq\"];\n\n// Add button/input type pseudos\nfor ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {\n\tExpr.pseudos[ i ] = createInputPseudo( i );\n}\nfor ( i in { submit: true, reset: true } ) {\n\tExpr.pseudos[ i ] = createButtonPseudo( i );\n}\n\n// Easy API for creating new setFilters\nfunction setFilters() {}\nsetFilters.prototype = Expr.filters = Expr.pseudos;\nExpr.setFilters = new setFilters();\n\ntokenize = Sizzle.tokenize = function( selector, parseOnly ) {\n\tvar matched, match, tokens, type,\n\t\tsoFar, groups, preFilters,\n\t\tcached = tokenCache[ selector + \" \" ];\n\n\tif ( cached ) {\n\t\treturn parseOnly ? 0 : cached.slice( 0 );\n\t}\n\n\tsoFar = selector;\n\tgroups = [];\n\tpreFilters = Expr.preFilter;\n\n\twhile ( soFar ) {\n\n\t\t// Comma and first run\n\t\tif ( !matched || (match = rcomma.exec( soFar )) ) {\n\t\t\tif ( match ) {\n\t\t\t\t// Don't consume trailing commas as valid\n\t\t\t\tsoFar = soFar.slice( match[0].length ) || soFar;\n\t\t\t}\n\t\t\tgroups.push( (tokens = []) );\n\t\t}\n\n\t\tmatched = false;\n\n\t\t// Combinators\n\t\tif ( (match = rcombinators.exec( soFar )) ) {\n\t\t\tmatched = match.shift();\n\t\t\ttokens.push({\n\t\t\t\tvalue: matched,\n\t\t\t\t// Cast descendant combinators to space\n\t\t\t\ttype: match[0].replace( rtrim, \" \" )\n\t\t\t});\n\t\t\tsoFar = soFar.slice( matched.length );\n\t\t}\n\n\t\t// Filters\n\t\tfor ( type in Expr.filter ) {\n\t\t\tif ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||\n\t\t\t\t(match = preFilters[ type ]( match ))) ) {\n\t\t\t\tmatched = match.shift();\n\t\t\t\ttokens.push({\n\t\t\t\t\tvalue: matched,\n\t\t\t\t\ttype: type,\n\t\t\t\t\tmatches: match\n\t\t\t\t});\n\t\t\t\tsoFar = soFar.slice( matched.length );\n\t\t\t}\n\t\t}\n\n\t\tif ( !matched ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t// Return the length of the invalid excess\n\t// if we're just parsing\n\t// Otherwise, throw an error or return tokens\n\treturn parseOnly ?\n\t\tsoFar.length :\n\t\tsoFar ?\n\t\t\tSizzle.error( selector ) :\n\t\t\t// Cache the tokens\n\t\t\ttokenCache( selector, groups ).slice( 0 );\n};\n\nfunction toSelector( tokens ) {\n\tvar i = 0,\n\t\tlen = tokens.length,\n\t\tselector = \"\";\n\tfor ( ; i < len; i++ ) {\n\t\tselector += tokens[i].value;\n\t}\n\treturn selector;\n}\n\nfunction addCombinator( matcher, combinator, base ) {\n\tvar dir = combinator.dir,\n\t\tskip = combinator.next,\n\t\tkey = skip || dir,\n\t\tcheckNonElements = base && key === \"parentNode\",\n\t\tdoneName = done++;\n\n\treturn combinator.first ?\n\t\t// Check against closest ancestor/preceding element\n\t\tfunction( elem, context, xml ) {\n\t\t\twhile ( (elem = elem[ dir ]) ) {\n\t\t\t\tif ( elem.nodeType === 1 || checkNonElements ) {\n\t\t\t\t\treturn matcher( elem, context, xml );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t} :\n\n\t\t// Check against all ancestor/preceding elements\n\t\tfunction( elem, context, xml ) {\n\t\t\tvar oldCache, uniqueCache, outerCache,\n\t\t\t\tnewCache = [ dirruns, doneName ];\n\n\t\t\t// We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching\n\t\t\tif ( xml ) {\n\t\t\t\twhile ( (elem = elem[ dir ]) ) {\n\t\t\t\t\tif ( elem.nodeType === 1 || checkNonElements ) {\n\t\t\t\t\t\tif ( matcher( elem, context, xml ) ) {\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twhile ( (elem = elem[ dir ]) ) {\n\t\t\t\t\tif ( elem.nodeType === 1 || checkNonElements ) {\n\t\t\t\t\t\touterCache = elem[ expando ] || (elem[ expando ] = {});\n\n\t\t\t\t\t\t// Support: IE <9 only\n\t\t\t\t\t\t// Defend against cloned attroperties (jQuery gh-1709)\n\t\t\t\t\t\tuniqueCache = outerCache[ elem.uniqueID ] || (outerCache[ elem.uniqueID ] = {});\n\n\t\t\t\t\t\tif ( skip && skip === elem.nodeName.toLowerCase() ) {\n\t\t\t\t\t\t\telem = elem[ dir ] || elem;\n\t\t\t\t\t\t} else if ( (oldCache = uniqueCache[ key ]) &&\n\t\t\t\t\t\t\toldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {\n\n\t\t\t\t\t\t\t// Assign to newCache so results back-propagate to previous elements\n\t\t\t\t\t\t\treturn (newCache[ 2 ] = oldCache[ 2 ]);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Reuse newcache so results back-propagate to previous elements\n\t\t\t\t\t\t\tuniqueCache[ key ] = newCache;\n\n\t\t\t\t\t\t\t// A match means we're done; a fail means we have to keep checking\n\t\t\t\t\t\t\tif ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t};\n}\n\nfunction elementMatcher( matchers ) {\n\treturn matchers.length > 1 ?\n\t\tfunction( elem, context, xml ) {\n\t\t\tvar i = matchers.length;\n\t\t\twhile ( i-- ) {\n\t\t\t\tif ( !matchers[i]( elem, context, xml ) ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t} :\n\t\tmatchers[0];\n}\n\nfunction multipleContexts( selector, contexts, results ) {\n\tvar i = 0,\n\t\tlen = contexts.length;\n\tfor ( ; i < len; i++ ) {\n\t\tSizzle( selector, contexts[i], results );\n\t}\n\treturn results;\n}\n\nfunction condense( unmatched, map, filter, context, xml ) {\n\tvar elem,\n\t\tnewUnmatched = [],\n\t\ti = 0,\n\t\tlen = unmatched.length,\n\t\tmapped = map != null;\n\n\tfor ( ; i < len; i++ ) {\n\t\tif ( (elem = unmatched[i]) ) {\n\t\t\tif ( !filter || filter( elem, context, xml ) ) {\n\t\t\t\tnewUnmatched.push( elem );\n\t\t\t\tif ( mapped ) {\n\t\t\t\t\tmap.push( i );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn newUnmatched;\n}\n\nfunction setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {\n\tif ( postFilter && !postFilter[ expando ] ) {\n\t\tpostFilter = setMatcher( postFilter );\n\t}\n\tif ( postFinder && !postFinder[ expando ] ) {\n\t\tpostFinder = setMatcher( postFinder, postSelector );\n\t}\n\treturn markFunction(function( seed, results, context, xml ) {\n\t\tvar temp, i, elem,\n\t\t\tpreMap = [],\n\t\t\tpostMap = [],\n\t\t\tpreexisting = results.length,\n\n\t\t\t// Get initial elements from seed or context\n\t\t\telems = seed || multipleContexts( selector || \"*\", context.nodeType ? [ context ] : context, [] ),\n\n\t\t\t// Prefilter to get matcher input, preserving a map for seed-results synchronization\n\t\t\tmatcherIn = preFilter && ( seed || !selector ) ?\n\t\t\t\tcondense( elems, preMap, preFilter, context, xml ) :\n\t\t\t\telems,\n\n\t\t\tmatcherOut = matcher ?\n\t\t\t\t// If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,\n\t\t\t\tpostFinder || ( seed ? preFilter : preexisting || postFilter ) ?\n\n\t\t\t\t\t// ...intermediate processing is necessary\n\t\t\t\t\t[] :\n\n\t\t\t\t\t// ...otherwise use results directly\n\t\t\t\t\tresults :\n\t\t\t\tmatcherIn;\n\n\t\t// Find primary matches\n\t\tif ( matcher ) {\n\t\t\tmatcher( matcherIn, matcherOut, context, xml );\n\t\t}\n\n\t\t// Apply postFilter\n\t\tif ( postFilter ) {\n\t\t\ttemp = condense( matcherOut, postMap );\n\t\t\tpostFilter( temp, [], context, xml );\n\n\t\t\t// Un-match failing elements by moving them back to matcherIn\n\t\t\ti = temp.length;\n\t\t\twhile ( i-- ) {\n\t\t\t\tif ( (elem = temp[i]) ) {\n\t\t\t\t\tmatcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( seed ) {\n\t\t\tif ( postFinder || preFilter ) {\n\t\t\t\tif ( postFinder ) {\n\t\t\t\t\t// Get the final matcherOut by condensing this intermediate into postFinder contexts\n\t\t\t\t\ttemp = [];\n\t\t\t\t\ti = matcherOut.length;\n\t\t\t\t\twhile ( i-- ) {\n\t\t\t\t\t\tif ( (elem = matcherOut[i]) ) {\n\t\t\t\t\t\t\t// Restore matcherIn since elem is not yet a final match\n\t\t\t\t\t\t\ttemp.push( (matcherIn[i] = elem) );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpostFinder( null, (matcherOut = []), temp, xml );\n\t\t\t\t}\n\n\t\t\t\t// Move matched elements from seed to results to keep them synchronized\n\t\t\t\ti = matcherOut.length;\n\t\t\t\twhile ( i-- ) {\n\t\t\t\t\tif ( (elem = matcherOut[i]) &&\n\t\t\t\t\t\t(temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {\n\n\t\t\t\t\t\tseed[temp] = !(results[temp] = elem);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t// Add elements to results, through postFinder if defined\n\t\t} else {\n\t\t\tmatcherOut = condense(\n\t\t\t\tmatcherOut === results ?\n\t\t\t\t\tmatcherOut.splice( preexisting, matcherOut.length ) :\n\t\t\t\t\tmatcherOut\n\t\t\t);\n\t\t\tif ( postFinder ) {\n\t\t\t\tpostFinder( null, results, matcherOut, xml );\n\t\t\t} else {\n\t\t\t\tpush.apply( results, matcherOut );\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction matcherFromTokens( tokens ) {\n\tvar checkContext, matcher, j,\n\t\tlen = tokens.length,\n\t\tleadingRelative = Expr.relative[ tokens[0].type ],\n\t\timplicitRelative = leadingRelative || Expr.relative[\" \"],\n\t\ti = leadingRelative ? 1 : 0,\n\n\t\t// The foundational matcher ensures that elements are reachable from top-level context(s)\n\t\tmatchContext = addCombinator( function( elem ) {\n\t\t\treturn elem === checkContext;\n\t\t}, implicitRelative, true ),\n\t\tmatchAnyContext = addCombinator( function( elem ) {\n\t\t\treturn indexOf( checkContext, elem ) > -1;\n\t\t}, implicitRelative, true ),\n\t\tmatchers = [ function( elem, context, xml ) {\n\t\t\tvar ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (\n\t\t\t\t(checkContext = context).nodeType ?\n\t\t\t\t\tmatchContext( elem, context, xml ) :\n\t\t\t\t\tmatchAnyContext( elem, context, xml ) );\n\t\t\t// Avoid hanging onto element (issue #299)\n\t\t\tcheckContext = null;\n\t\t\treturn ret;\n\t\t} ];\n\n\tfor ( ; i < len; i++ ) {\n\t\tif ( (matcher = Expr.relative[ tokens[i].type ]) ) {\n\t\t\tmatchers = [ addCombinator(elementMatcher( matchers ), matcher) ];\n\t\t} else {\n\t\t\tmatcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );\n\n\t\t\t// Return special upon seeing a positional matcher\n\t\t\tif ( matcher[ expando ] ) {\n\t\t\t\t// Find the next relative operator (if any) for proper handling\n\t\t\t\tj = ++i;\n\t\t\t\tfor ( ; j < len; j++ ) {\n\t\t\t\t\tif ( Expr.relative[ tokens[j].type ] ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn setMatcher(\n\t\t\t\t\ti > 1 && elementMatcher( matchers ),\n\t\t\t\t\ti > 1 && toSelector(\n\t\t\t\t\t\t// If the preceding token was a descendant combinator, insert an implicit any-element `*`\n\t\t\t\t\t\ttokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === \" \" ? \"*\" : \"\" })\n\t\t\t\t\t).replace( rtrim, \"$1\" ),\n\t\t\t\t\tmatcher,\n\t\t\t\t\ti < j && matcherFromTokens( tokens.slice( i, j ) ),\n\t\t\t\t\tj < len && matcherFromTokens( (tokens = tokens.slice( j )) ),\n\t\t\t\t\tj < len && toSelector( tokens )\n\t\t\t\t);\n\t\t\t}\n\t\t\tmatchers.push( matcher );\n\t\t}\n\t}\n\n\treturn elementMatcher( matchers );\n}\n\nfunction matcherFromGroupMatchers( elementMatchers, setMatchers ) {\n\tvar bySet = setMatchers.length > 0,\n\t\tbyElement = elementMatchers.length > 0,\n\t\tsuperMatcher = function( seed, context, xml, results, outermost ) {\n\t\t\tvar elem, j, matcher,\n\t\t\t\tmatchedCount = 0,\n\t\t\t\ti = \"0\",\n\t\t\t\tunmatched = seed && [],\n\t\t\t\tsetMatched = [],\n\t\t\t\tcontextBackup = outermostContext,\n\t\t\t\t// We must always have either seed elements or outermost context\n\t\t\t\telems = seed || byElement && Expr.find[\"TAG\"]( \"*\", outermost ),\n\t\t\t\t// Use integer dirruns iff this is the outermost matcher\n\t\t\t\tdirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),\n\t\t\t\tlen = elems.length;\n\n\t\t\tif ( outermost ) {\n\t\t\t\toutermostContext = context === document || context || outermost;\n\t\t\t}\n\n\t\t\t// Add elements passing elementMatchers directly to results\n\t\t\t// Support: IE<9, Safari\n\t\t\t// Tolerate NodeList properties (IE: \"length\"; Safari: <number>) matching elements by id\n\t\t\tfor ( ; i !== len && (elem = elems[i]) != null; i++ ) {\n\t\t\t\tif ( byElement && elem ) {\n\t\t\t\t\tj = 0;\n\t\t\t\t\tif ( !context && elem.ownerDocument !== document ) {\n\t\t\t\t\t\tsetDocument( elem );\n\t\t\t\t\t\txml = !documentIsHTML;\n\t\t\t\t\t}\n\t\t\t\t\twhile ( (matcher = elementMatchers[j++]) ) {\n\t\t\t\t\t\tif ( matcher( elem, context || document, xml) ) {\n\t\t\t\t\t\t\tresults.push( elem );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif ( outermost ) {\n\t\t\t\t\t\tdirruns = dirrunsUnique;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Track unmatched elements for set filters\n\t\t\t\tif ( bySet ) {\n\t\t\t\t\t// They will have gone through all possible matchers\n\t\t\t\t\tif ( (elem = !matcher && elem) ) {\n\t\t\t\t\t\tmatchedCount--;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Lengthen the array for every element, matched or not\n\t\t\t\t\tif ( seed ) {\n\t\t\t\t\t\tunmatched.push( elem );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// `i` is now the count of elements visited above, and adding it to `matchedCount`\n\t\t\t// makes the latter nonnegative.\n\t\t\tmatchedCount += i;\n\n\t\t\t// Apply set filters to unmatched elements\n\t\t\t// NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount`\n\t\t\t// equals `i`), unless we didn't visit _any_ elements in the above loop because we have\n\t\t\t// no element matchers and no seed.\n\t\t\t// Incrementing an initially-string \"0\" `i` allows `i` to remain a string only in that\n\t\t\t// case, which will result in a \"00\" `matchedCount` that differs from `i` but is also\n\t\t\t// numerically zero.\n\t\t\tif ( bySet && i !== matchedCount ) {\n\t\t\t\tj = 0;\n\t\t\t\twhile ( (matcher = setMatchers[j++]) ) {\n\t\t\t\t\tmatcher( unmatched, setMatched, context, xml );\n\t\t\t\t}\n\n\t\t\t\tif ( seed ) {\n\t\t\t\t\t// Reintegrate element matches to eliminate the need for sorting\n\t\t\t\t\tif ( matchedCount > 0 ) {\n\t\t\t\t\t\twhile ( i-- ) {\n\t\t\t\t\t\t\tif ( !(unmatched[i] || setMatched[i]) ) {\n\t\t\t\t\t\t\t\tsetMatched[i] = pop.call( results );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Discard index placeholder values to get only actual matches\n\t\t\t\t\tsetMatched = condense( setMatched );\n\t\t\t\t}\n\n\t\t\t\t// Add matches to results\n\t\t\t\tpush.apply( results, setMatched );\n\n\t\t\t\t// Seedless set matches succeeding multiple successful matchers stipulate sorting\n\t\t\t\tif ( outermost && !seed && setMatched.length > 0 &&\n\t\t\t\t\t( matchedCount + setMatchers.length ) > 1 ) {\n\n\t\t\t\t\tSizzle.uniqueSort( results );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Override manipulation of globals by nested matchers\n\t\t\tif ( outermost ) {\n\t\t\t\tdirruns = dirrunsUnique;\n\t\t\t\toutermostContext = contextBackup;\n\t\t\t}\n\n\t\t\treturn unmatched;\n\t\t};\n\n\treturn bySet ?\n\t\tmarkFunction( superMatcher ) :\n\t\tsuperMatcher;\n}\n\ncompile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {\n\tvar i,\n\t\tsetMatchers = [],\n\t\telementMatchers = [],\n\t\tcached = compilerCache[ selector + \" \" ];\n\n\tif ( !cached ) {\n\t\t// Generate a function of recursive functions that can be used to check each element\n\t\tif ( !match ) {\n\t\t\tmatch = tokenize( selector );\n\t\t}\n\t\ti = match.length;\n\t\twhile ( i-- ) {\n\t\t\tcached = matcherFromTokens( match[i] );\n\t\t\tif ( cached[ expando ] ) {\n\t\t\t\tsetMatchers.push( cached );\n\t\t\t} else {\n\t\t\t\telementMatchers.push( cached );\n\t\t\t}\n\t\t}\n\n\t\t// Cache the compiled function\n\t\tcached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );\n\n\t\t// Save selector and tokenization\n\t\tcached.selector = selector;\n\t}\n\treturn cached;\n};\n\n/**\n * A low-level selection function that works with Sizzle's compiled\n *  selector functions\n * @param {String|Function} selector A selector or a pre-compiled\n *  selector function built with Sizzle.compile\n * @param {Element} context\n * @param {Array} [results]\n * @param {Array} [seed] A set of elements to match against\n */\nselect = Sizzle.select = function( selector, context, results, seed ) {\n\tvar i, tokens, token, type, find,\n\t\tcompiled = typeof selector === \"function\" && selector,\n\t\tmatch = !seed && tokenize( (selector = compiled.selector || selector) );\n\n\tresults = results || [];\n\n\t// Try to minimize operations if there is only one selector in the list and no seed\n\t// (the latter of which guarantees us context)\n\tif ( match.length === 1 ) {\n\n\t\t// Reduce context if the leading compound selector is an ID\n\t\ttokens = match[0] = match[0].slice( 0 );\n\t\tif ( tokens.length > 2 && (token = tokens[0]).type === \"ID\" &&\n\t\t\t\tcontext.nodeType === 9 && documentIsHTML && Expr.relative[ tokens[1].type ] ) {\n\n\t\t\tcontext = ( Expr.find[\"ID\"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];\n\t\t\tif ( !context ) {\n\t\t\t\treturn results;\n\n\t\t\t// Precompiled matchers will still verify ancestry, so step up a level\n\t\t\t} else if ( compiled ) {\n\t\t\t\tcontext = context.parentNode;\n\t\t\t}\n\n\t\t\tselector = selector.slice( tokens.shift().value.length );\n\t\t}\n\n\t\t// Fetch a seed set for right-to-left matching\n\t\ti = matchExpr[\"needsContext\"].test( selector ) ? 0 : tokens.length;\n\t\twhile ( i-- ) {\n\t\t\ttoken = tokens[i];\n\n\t\t\t// Abort if we hit a combinator\n\t\t\tif ( Expr.relative[ (type = token.type) ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif ( (find = Expr.find[ type ]) ) {\n\t\t\t\t// Search, expanding context for leading sibling combinators\n\t\t\t\tif ( (seed = find(\n\t\t\t\t\ttoken.matches[0].replace( runescape, funescape ),\n\t\t\t\t\trsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context\n\t\t\t\t)) ) {\n\n\t\t\t\t\t// If seed is empty or no tokens remain, we can return early\n\t\t\t\t\ttokens.splice( i, 1 );\n\t\t\t\t\tselector = seed.length && toSelector( tokens );\n\t\t\t\t\tif ( !selector ) {\n\t\t\t\t\t\tpush.apply( results, seed );\n\t\t\t\t\t\treturn results;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Compile and execute a filtering function if one is not provided\n\t// Provide `match` to avoid retokenization if we modified the selector above\n\t( compiled || compile( selector, match ) )(\n\t\tseed,\n\t\tcontext,\n\t\t!documentIsHTML,\n\t\tresults,\n\t\t!context || rsibling.test( selector ) && testContext( context.parentNode ) || context\n\t);\n\treturn results;\n};\n\n// One-time assignments\n\n// Sort stability\nsupport.sortStable = expando.split(\"\").sort( sortOrder ).join(\"\") === expando;\n\n// Support: Chrome 14-35+\n// Always assume duplicates if they aren't passed to the comparison function\nsupport.detectDuplicates = !!hasDuplicate;\n\n// Initialize against the default document\nsetDocument();\n\n// Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)\n// Detached nodes confoundingly follow *each other*\nsupport.sortDetached = assert(function( el ) {\n\t// Should return 1, but returns 4 (following)\n\treturn el.compareDocumentPosition( document.createElement(\"fieldset\") ) & 1;\n});\n\n// Support: IE<8\n// Prevent attribute/property \"interpolation\"\n// https://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx\nif ( !assert(function( el ) {\n\tel.innerHTML = \"<a href='#'></a>\";\n\treturn el.firstChild.getAttribute(\"href\") === \"#\" ;\n}) ) {\n\taddHandle( \"type|href|height|width\", function( elem, name, isXML ) {\n\t\tif ( !isXML ) {\n\t\t\treturn elem.getAttribute( name, name.toLowerCase() === \"type\" ? 1 : 2 );\n\t\t}\n\t});\n}\n\n// Support: IE<9\n// Use defaultValue in place of getAttribute(\"value\")\nif ( !support.attributes || !assert(function( el ) {\n\tel.innerHTML = \"<input/>\";\n\tel.firstChild.setAttribute( \"value\", \"\" );\n\treturn el.firstChild.getAttribute( \"value\" ) === \"\";\n}) ) {\n\taddHandle( \"value\", function( elem, name, isXML ) {\n\t\tif ( !isXML && elem.nodeName.toLowerCase() === \"input\" ) {\n\t\t\treturn elem.defaultValue;\n\t\t}\n\t});\n}\n\n// Support: IE<9\n// Use getAttributeNode to fetch booleans when getAttribute lies\nif ( !assert(function( el ) {\n\treturn el.getAttribute(\"disabled\") == null;\n}) ) {\n\taddHandle( booleans, function( elem, name, isXML ) {\n\t\tvar val;\n\t\tif ( !isXML ) {\n\t\t\treturn elem[ name ] === true ? name.toLowerCase() :\n\t\t\t\t\t(val = elem.getAttributeNode( name )) && val.specified ?\n\t\t\t\t\tval.value :\n\t\t\t\tnull;\n\t\t}\n\t});\n}\n\nreturn Sizzle;\n\n})( window );\n\n\n\njQuery.find = Sizzle;\njQuery.expr = Sizzle.selectors;\n\n// Deprecated\njQuery.expr[ \":\" ] = jQuery.expr.pseudos;\njQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort;\njQuery.text = Sizzle.getText;\njQuery.isXMLDoc = Sizzle.isXML;\njQuery.contains = Sizzle.contains;\njQuery.escapeSelector = Sizzle.escape;\n\n\n\n\nvar dir = function( elem, dir, until ) {\n\tvar matched = [],\n\t\ttruncate = until !== undefined;\n\n\twhile ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {\n\t\tif ( elem.nodeType === 1 ) {\n\t\t\tif ( truncate && jQuery( elem ).is( until ) ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tmatched.push( elem );\n\t\t}\n\t}\n\treturn matched;\n};\n\n\nvar siblings = function( n, elem ) {\n\tvar matched = [];\n\n\tfor ( ; n; n = n.nextSibling ) {\n\t\tif ( n.nodeType === 1 && n !== elem ) {\n\t\t\tmatched.push( n );\n\t\t}\n\t}\n\n\treturn matched;\n};\n\n\nvar rneedsContext = jQuery.expr.match.needsContext;\n\n\n\nfunction nodeName( elem, name ) {\n\n  return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();\n\n};\nvar rsingleTag = ( /^<([a-z][^\\/\\0>:\\x20\\t\\r\\n\\f]*)[\\x20\\t\\r\\n\\f]*\\/?>(?:<\\/\\1>|)$/i );\n\n\n\n// Implement the identical functionality for filter and not\nfunction winnow( elements, qualifier, not ) {\n\tif ( isFunction( qualifier ) ) {\n\t\treturn jQuery.grep( elements, function( elem, i ) {\n\t\t\treturn !!qualifier.call( elem, i, elem ) !== not;\n\t\t} );\n\t}\n\n\t// Single element\n\tif ( qualifier.nodeType ) {\n\t\treturn jQuery.grep( elements, function( elem ) {\n\t\t\treturn ( elem === qualifier ) !== not;\n\t\t} );\n\t}\n\n\t// Arraylike of elements (jQuery, arguments, Array)\n\tif ( typeof qualifier !== \"string\" ) {\n\t\treturn jQuery.grep( elements, function( elem ) {\n\t\t\treturn ( indexOf.call( qualifier, elem ) > -1 ) !== not;\n\t\t} );\n\t}\n\n\t// Filtered directly for both simple and complex selectors\n\treturn jQuery.filter( qualifier, elements, not );\n}\n\njQuery.filter = function( expr, elems, not ) {\n\tvar elem = elems[ 0 ];\n\n\tif ( not ) {\n\t\texpr = \":not(\" + expr + \")\";\n\t}\n\n\tif ( elems.length === 1 && elem.nodeType === 1 ) {\n\t\treturn jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [];\n\t}\n\n\treturn jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {\n\t\treturn elem.nodeType === 1;\n\t} ) );\n};\n\njQuery.fn.extend( {\n\tfind: function( selector ) {\n\t\tvar i, ret,\n\t\t\tlen = this.length,\n\t\t\tself = this;\n\n\t\tif ( typeof selector !== \"string\" ) {\n\t\t\treturn this.pushStack( jQuery( selector ).filter( function() {\n\t\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\t\tif ( jQuery.contains( self[ i ], this ) ) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} ) );\n\t\t}\n\n\t\tret = this.pushStack( [] );\n\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tjQuery.find( selector, self[ i ], ret );\n\t\t}\n\n\t\treturn len > 1 ? jQuery.uniqueSort( ret ) : ret;\n\t},\n\tfilter: function( selector ) {\n\t\treturn this.pushStack( winnow( this, selector || [], false ) );\n\t},\n\tnot: function( selector ) {\n\t\treturn this.pushStack( winnow( this, selector || [], true ) );\n\t},\n\tis: function( selector ) {\n\t\treturn !!winnow(\n\t\t\tthis,\n\n\t\t\t// If this is a positional/relative selector, check membership in the returned set\n\t\t\t// so $(\"p:first\").is(\"p:last\") won't return true for a doc with two \"p\".\n\t\t\ttypeof selector === \"string\" && rneedsContext.test( selector ) ?\n\t\t\t\tjQuery( selector ) :\n\t\t\t\tselector || [],\n\t\t\tfalse\n\t\t).length;\n\t}\n} );\n\n\n// Initialize a jQuery object\n\n\n// A central reference to the root jQuery(document)\nvar rootjQuery,\n\n\t// A simple way to check for HTML strings\n\t// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)\n\t// Strict HTML recognition (#11290: must start with <)\n\t// Shortcut simple #id case for speed\n\trquickExpr = /^(?:\\s*(<[\\w\\W]+>)[^>]*|#([\\w-]+))$/,\n\n\tinit = jQuery.fn.init = function( selector, context, root ) {\n\t\tvar match, elem;\n\n\t\t// HANDLE: $(\"\"), $(null), $(undefined), $(false)\n\t\tif ( !selector ) {\n\t\t\treturn this;\n\t\t}\n\n\t\t// Method init() accepts an alternate rootjQuery\n\t\t// so migrate can support jQuery.sub (gh-2101)\n\t\troot = root || rootjQuery;\n\n\t\t// Handle HTML strings\n\t\tif ( typeof selector === \"string\" ) {\n\t\t\tif ( selector[ 0 ] === \"<\" &&\n\t\t\t\tselector[ selector.length - 1 ] === \">\" &&\n\t\t\t\tselector.length >= 3 ) {\n\n\t\t\t\t// Assume that strings that start and end with <> are HTML and skip the regex check\n\t\t\t\tmatch = [ null, selector, null ];\n\n\t\t\t} else {\n\t\t\t\tmatch = rquickExpr.exec( selector );\n\t\t\t}\n\n\t\t\t// Match html or make sure no context is specified for #id\n\t\t\tif ( match && ( match[ 1 ] || !context ) ) {\n\n\t\t\t\t// HANDLE: $(html) -> $(array)\n\t\t\t\tif ( match[ 1 ] ) {\n\t\t\t\t\tcontext = context instanceof jQuery ? context[ 0 ] : context;\n\n\t\t\t\t\t// Option to run scripts is true for back-compat\n\t\t\t\t\t// Intentionally let the error be thrown if parseHTML is not present\n\t\t\t\t\tjQuery.merge( this, jQuery.parseHTML(\n\t\t\t\t\t\tmatch[ 1 ],\n\t\t\t\t\t\tcontext && context.nodeType ? context.ownerDocument || context : document,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t) );\n\n\t\t\t\t\t// HANDLE: $(html, props)\n\t\t\t\t\tif ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {\n\t\t\t\t\t\tfor ( match in context ) {\n\n\t\t\t\t\t\t\t// Properties of context are called as methods if possible\n\t\t\t\t\t\t\tif ( isFunction( this[ match ] ) ) {\n\t\t\t\t\t\t\t\tthis[ match ]( context[ match ] );\n\n\t\t\t\t\t\t\t// ...and otherwise set as attributes\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthis.attr( match, context[ match ] );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn this;\n\n\t\t\t\t// HANDLE: $(#id)\n\t\t\t\t} else {\n\t\t\t\t\telem = document.getElementById( match[ 2 ] );\n\n\t\t\t\t\tif ( elem ) {\n\n\t\t\t\t\t\t// Inject the element directly into the jQuery object\n\t\t\t\t\t\tthis[ 0 ] = elem;\n\t\t\t\t\t\tthis.length = 1;\n\t\t\t\t\t}\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\n\t\t\t// HANDLE: $(expr, $(...))\n\t\t\t} else if ( !context || context.jquery ) {\n\t\t\t\treturn ( context || root ).find( selector );\n\n\t\t\t// HANDLE: $(expr, context)\n\t\t\t// (which is just equivalent to: $(context).find(expr)\n\t\t\t} else {\n\t\t\t\treturn this.constructor( context ).find( selector );\n\t\t\t}\n\n\t\t// HANDLE: $(DOMElement)\n\t\t} else if ( selector.nodeType ) {\n\t\t\tthis[ 0 ] = selector;\n\t\t\tthis.length = 1;\n\t\t\treturn this;\n\n\t\t// HANDLE: $(function)\n\t\t// Shortcut for document ready\n\t\t} else if ( isFunction( selector ) ) {\n\t\t\treturn root.ready !== undefined ?\n\t\t\t\troot.ready( selector ) :\n\n\t\t\t\t// Execute immediately if ready is not present\n\t\t\t\tselector( jQuery );\n\t\t}\n\n\t\treturn jQuery.makeArray( selector, this );\n\t};\n\n// Give the init function the jQuery prototype for later instantiation\ninit.prototype = jQuery.fn;\n\n// Initialize central reference\nrootjQuery = jQuery( document );\n\n\nvar rparentsprev = /^(?:parents|prev(?:Until|All))/,\n\n\t// Methods guaranteed to produce a unique set when starting from a unique set\n\tguaranteedUnique = {\n\t\tchildren: true,\n\t\tcontents: true,\n\t\tnext: true,\n\t\tprev: true\n\t};\n\njQuery.fn.extend( {\n\thas: function( target ) {\n\t\tvar targets = jQuery( target, this ),\n\t\t\tl = targets.length;\n\n\t\treturn this.filter( function() {\n\t\t\tvar i = 0;\n\t\t\tfor ( ; i < l; i++ ) {\n\t\t\t\tif ( jQuery.contains( this, targets[ i ] ) ) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t},\n\n\tclosest: function( selectors, context ) {\n\t\tvar cur,\n\t\t\ti = 0,\n\t\t\tl = this.length,\n\t\t\tmatched = [],\n\t\t\ttargets = typeof selectors !== \"string\" && jQuery( selectors );\n\n\t\t// Positional selectors never match, since there's no _selection_ context\n\t\tif ( !rneedsContext.test( selectors ) ) {\n\t\t\tfor ( ; i < l; i++ ) {\n\t\t\t\tfor ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {\n\n\t\t\t\t\t// Always skip document fragments\n\t\t\t\t\tif ( cur.nodeType < 11 && ( targets ?\n\t\t\t\t\t\ttargets.index( cur ) > -1 :\n\n\t\t\t\t\t\t// Don't pass non-elements to Sizzle\n\t\t\t\t\t\tcur.nodeType === 1 &&\n\t\t\t\t\t\t\tjQuery.find.matchesSelector( cur, selectors ) ) ) {\n\n\t\t\t\t\t\tmatched.push( cur );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );\n\t},\n\n\t// Determine the position of an element within the set\n\tindex: function( elem ) {\n\n\t\t// No argument, return index in parent\n\t\tif ( !elem ) {\n\t\t\treturn ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;\n\t\t}\n\n\t\t// Index in selector\n\t\tif ( typeof elem === \"string\" ) {\n\t\t\treturn indexOf.call( jQuery( elem ), this[ 0 ] );\n\t\t}\n\n\t\t// Locate the position of the desired element\n\t\treturn indexOf.call( this,\n\n\t\t\t// If it receives a jQuery object, the first element is used\n\t\t\telem.jquery ? elem[ 0 ] : elem\n\t\t);\n\t},\n\n\tadd: function( selector, context ) {\n\t\treturn this.pushStack(\n\t\t\tjQuery.uniqueSort(\n\t\t\t\tjQuery.merge( this.get(), jQuery( selector, context ) )\n\t\t\t)\n\t\t);\n\t},\n\n\taddBack: function( selector ) {\n\t\treturn this.add( selector == null ?\n\t\t\tthis.prevObject : this.prevObject.filter( selector )\n\t\t);\n\t}\n} );\n\nfunction sibling( cur, dir ) {\n\twhile ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}\n\treturn cur;\n}\n\njQuery.each( {\n\tparent: function( elem ) {\n\t\tvar parent = elem.parentNode;\n\t\treturn parent && parent.nodeType !== 11 ? parent : null;\n\t},\n\tparents: function( elem ) {\n\t\treturn dir( elem, \"parentNode\" );\n\t},\n\tparentsUntil: function( elem, i, until ) {\n\t\treturn dir( elem, \"parentNode\", until );\n\t},\n\tnext: function( elem ) {\n\t\treturn sibling( elem, \"nextSibling\" );\n\t},\n\tprev: function( elem ) {\n\t\treturn sibling( elem, \"previousSibling\" );\n\t},\n\tnextAll: function( elem ) {\n\t\treturn dir( elem, \"nextSibling\" );\n\t},\n\tprevAll: function( elem ) {\n\t\treturn dir( elem, \"previousSibling\" );\n\t},\n\tnextUntil: function( elem, i, until ) {\n\t\treturn dir( elem, \"nextSibling\", until );\n\t},\n\tprevUntil: function( elem, i, until ) {\n\t\treturn dir( elem, \"previousSibling\", until );\n\t},\n\tsiblings: function( elem ) {\n\t\treturn siblings( ( elem.parentNode || {} ).firstChild, elem );\n\t},\n\tchildren: function( elem ) {\n\t\treturn siblings( elem.firstChild );\n\t},\n\tcontents: function( elem ) {\n\t\tif ( typeof elem.contentDocument !== \"undefined\" ) {\n\t\t\treturn elem.contentDocument;\n\t\t}\n\n\t\t// Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only\n\t\t// Treat the template element as a regular one in browsers that\n\t\t// don't support it.\n\t\tif ( nodeName( elem, \"template\" ) ) {\n\t\t\telem = elem.content || elem;\n\t\t}\n\n\t\treturn jQuery.merge( [], elem.childNodes );\n\t}\n}, function( name, fn ) {\n\tjQuery.fn[ name ] = function( until, selector ) {\n\t\tvar matched = jQuery.map( this, fn, until );\n\n\t\tif ( name.slice( -5 ) !== \"Until\" ) {\n\t\t\tselector = until;\n\t\t}\n\n\t\tif ( selector && typeof selector === \"string\" ) {\n\t\t\tmatched = jQuery.filter( selector, matched );\n\t\t}\n\n\t\tif ( this.length > 1 ) {\n\n\t\t\t// Remove duplicates\n\t\t\tif ( !guaranteedUnique[ name ] ) {\n\t\t\t\tjQuery.uniqueSort( matched );\n\t\t\t}\n\n\t\t\t// Reverse order for parents* and prev-derivatives\n\t\t\tif ( rparentsprev.test( name ) ) {\n\t\t\t\tmatched.reverse();\n\t\t\t}\n\t\t}\n\n\t\treturn this.pushStack( matched );\n\t};\n} );\nvar rnothtmlwhite = ( /[^\\x20\\t\\r\\n\\f]+/g );\n\n\n\n// Convert String-formatted options into Object-formatted ones\nfunction createOptions( options ) {\n\tvar object = {};\n\tjQuery.each( options.match( rnothtmlwhite ) || [], function( _, flag ) {\n\t\tobject[ flag ] = true;\n\t} );\n\treturn object;\n}\n\n/*\n * Create a callback list using the following parameters:\n *\n *\toptions: an optional list of space-separated options that will change how\n *\t\t\tthe callback list behaves or a more traditional option object\n *\n * By default a callback list will act like an event callback list and can be\n * \"fired\" multiple times.\n *\n * Possible options:\n *\n *\tonce:\t\t\twill ensure the callback list can only be fired once (like a Deferred)\n *\n *\tmemory:\t\t\twill keep track of previous values and will call any callback added\n *\t\t\t\t\tafter the list has been fired right away with the latest \"memorized\"\n *\t\t\t\t\tvalues (like a Deferred)\n *\n *\tunique:\t\t\twill ensure a callback can only be added once (no duplicate in the list)\n *\n *\tstopOnFalse:\tinterrupt callings when a callback returns false\n *\n */\njQuery.Callbacks = function( options ) {\n\n\t// Convert options from String-formatted to Object-formatted if needed\n\t// (we check in cache first)\n\toptions = typeof options === \"string\" ?\n\t\tcreateOptions( options ) :\n\t\tjQuery.extend( {}, options );\n\n\tvar // Flag to know if list is currently firing\n\t\tfiring,\n\n\t\t// Last fire value for non-forgettable lists\n\t\tmemory,\n\n\t\t// Flag to know if list was already fired\n\t\tfired,\n\n\t\t// Flag to prevent firing\n\t\tlocked,\n\n\t\t// Actual callback list\n\t\tlist = [],\n\n\t\t// Queue of execution data for repeatable lists\n\t\tqueue = [],\n\n\t\t// Index of currently firing callback (modified by add/remove as needed)\n\t\tfiringIndex = -1,\n\n\t\t// Fire callbacks\n\t\tfire = function() {\n\n\t\t\t// Enforce single-firing\n\t\t\tlocked = locked || options.once;\n\n\t\t\t// Execute callbacks for all pending executions,\n\t\t\t// respecting firingIndex overrides and runtime changes\n\t\t\tfired = firing = true;\n\t\t\tfor ( ; queue.length; firingIndex = -1 ) {\n\t\t\t\tmemory = queue.shift();\n\t\t\t\twhile ( ++firingIndex < list.length ) {\n\n\t\t\t\t\t// Run callback and check for early termination\n\t\t\t\t\tif ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false &&\n\t\t\t\t\t\toptions.stopOnFalse ) {\n\n\t\t\t\t\t\t// Jump to end and forget the data so .add doesn't re-fire\n\t\t\t\t\t\tfiringIndex = list.length;\n\t\t\t\t\t\tmemory = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Forget the data if we're done with it\n\t\t\tif ( !options.memory ) {\n\t\t\t\tmemory = false;\n\t\t\t}\n\n\t\t\tfiring = false;\n\n\t\t\t// Clean up if we're done firing for good\n\t\t\tif ( locked ) {\n\n\t\t\t\t// Keep an empty list if we have data for future add calls\n\t\t\t\tif ( memory ) {\n\t\t\t\t\tlist = [];\n\n\t\t\t\t// Otherwise, this object is spent\n\t\t\t\t} else {\n\t\t\t\t\tlist = \"\";\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t// Actual Callbacks object\n\t\tself = {\n\n\t\t\t// Add a callback or a collection of callbacks to the list\n\t\t\tadd: function() {\n\t\t\t\tif ( list ) {\n\n\t\t\t\t\t// If we have memory from a past run, we should fire after adding\n\t\t\t\t\tif ( memory && !firing ) {\n\t\t\t\t\t\tfiringIndex = list.length - 1;\n\t\t\t\t\t\tqueue.push( memory );\n\t\t\t\t\t}\n\n\t\t\t\t\t( function add( args ) {\n\t\t\t\t\t\tjQuery.each( args, function( _, arg ) {\n\t\t\t\t\t\t\tif ( isFunction( arg ) ) {\n\t\t\t\t\t\t\t\tif ( !options.unique || !self.has( arg ) ) {\n\t\t\t\t\t\t\t\t\tlist.push( arg );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if ( arg && arg.length && toType( arg ) !== \"string\" ) {\n\n\t\t\t\t\t\t\t\t// Inspect recursively\n\t\t\t\t\t\t\t\tadd( arg );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\t\t\t\t\t} )( arguments );\n\n\t\t\t\t\tif ( memory && !firing ) {\n\t\t\t\t\t\tfire();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// Remove a callback from the list\n\t\t\tremove: function() {\n\t\t\t\tjQuery.each( arguments, function( _, arg ) {\n\t\t\t\t\tvar index;\n\t\t\t\t\twhile ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {\n\t\t\t\t\t\tlist.splice( index, 1 );\n\n\t\t\t\t\t\t// Handle firing indexes\n\t\t\t\t\t\tif ( index <= firingIndex ) {\n\t\t\t\t\t\t\tfiringIndex--;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// Check if a given callback is in the list.\n\t\t\t// If no argument is given, return whether or not list has callbacks attached.\n\t\t\thas: function( fn ) {\n\t\t\t\treturn fn ?\n\t\t\t\t\tjQuery.inArray( fn, list ) > -1 :\n\t\t\t\t\tlist.length > 0;\n\t\t\t},\n\n\t\t\t// Remove all callbacks from the list\n\t\t\tempty: function() {\n\t\t\t\tif ( list ) {\n\t\t\t\t\tlist = [];\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// Disable .fire and .add\n\t\t\t// Abort any current/pending executions\n\t\t\t// Clear all callbacks and values\n\t\t\tdisable: function() {\n\t\t\t\tlocked = queue = [];\n\t\t\t\tlist = memory = \"\";\n\t\t\t\treturn this;\n\t\t\t},\n\t\t\tdisabled: function() {\n\t\t\t\treturn !list;\n\t\t\t},\n\n\t\t\t// Disable .fire\n\t\t\t// Also disable .add unless we have memory (since it would have no effect)\n\t\t\t// Abort any pending executions\n\t\t\tlock: function() {\n\t\t\t\tlocked = queue = [];\n\t\t\t\tif ( !memory && !firing ) {\n\t\t\t\t\tlist = memory = \"\";\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t},\n\t\t\tlocked: function() {\n\t\t\t\treturn !!locked;\n\t\t\t},\n\n\t\t\t// Call all callbacks with the given context and arguments\n\t\t\tfireWith: function( context, args ) {\n\t\t\t\tif ( !locked ) {\n\t\t\t\t\targs = args || [];\n\t\t\t\t\targs = [ context, args.slice ? args.slice() : args ];\n\t\t\t\t\tqueue.push( args );\n\t\t\t\t\tif ( !firing ) {\n\t\t\t\t\t\tfire();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// Call all the callbacks with the given arguments\n\t\t\tfire: function() {\n\t\t\t\tself.fireWith( this, arguments );\n\t\t\t\treturn this;\n\t\t\t},\n\n\t\t\t// To know if the callbacks have already been called at least once\n\t\t\tfired: function() {\n\t\t\t\treturn !!fired;\n\t\t\t}\n\t\t};\n\n\treturn self;\n};\n\n\nfunction Identity( v ) {\n\treturn v;\n}\nfunction Thrower( ex ) {\n\tthrow ex;\n}\n\nfunction adoptValue( value, resolve, reject, noValue ) {\n\tvar method;\n\n\ttry {\n\n\t\t// Check for promise aspect first to privilege synchronous behavior\n\t\tif ( value && isFunction( ( method = value.promise ) ) ) {\n\t\t\tmethod.call( value ).done( resolve ).fail( reject );\n\n\t\t// Other thenables\n\t\t} else if ( value && isFunction( ( method = value.then ) ) ) {\n\t\t\tmethod.call( value, resolve, reject );\n\n\t\t// Other non-thenables\n\t\t} else {\n\n\t\t\t// Control `resolve` arguments by letting Array#slice cast boolean `noValue` to integer:\n\t\t\t// * false: [ value ].slice( 0 ) => resolve( value )\n\t\t\t// * true: [ value ].slice( 1 ) => resolve()\n\t\t\tresolve.apply( undefined, [ value ].slice( noValue ) );\n\t\t}\n\n\t// For Promises/A+, convert exceptions into rejections\n\t// Since jQuery.when doesn't unwrap thenables, we can skip the extra checks appearing in\n\t// Deferred#then to conditionally suppress rejection.\n\t} catch ( value ) {\n\n\t\t// Support: Android 4.0 only\n\t\t// Strict mode functions invoked without .call/.apply get global-object context\n\t\treject.apply( undefined, [ value ] );\n\t}\n}\n\njQuery.extend( {\n\n\tDeferred: function( func ) {\n\t\tvar tuples = [\n\n\t\t\t\t// action, add listener, callbacks,\n\t\t\t\t// ... .then handlers, argument index, [final state]\n\t\t\t\t[ \"notify\", \"progress\", jQuery.Callbacks( \"memory\" ),\n\t\t\t\t\tjQuery.Callbacks( \"memory\" ), 2 ],\n\t\t\t\t[ \"resolve\", \"done\", jQuery.Callbacks( \"once memory\" ),\n\t\t\t\t\tjQuery.Callbacks( \"once memory\" ), 0, \"resolved\" ],\n\t\t\t\t[ \"reject\", \"fail\", jQuery.Callbacks( \"once memory\" ),\n\t\t\t\t\tjQuery.Callbacks( \"once memory\" ), 1, \"rejected\" ]\n\t\t\t],\n\t\t\tstate = \"pending\",\n\t\t\tpromise = {\n\t\t\t\tstate: function() {\n\t\t\t\t\treturn state;\n\t\t\t\t},\n\t\t\t\talways: function() {\n\t\t\t\t\tdeferred.done( arguments ).fail( arguments );\n\t\t\t\t\treturn this;\n\t\t\t\t},\n\t\t\t\t\"catch\": function( fn ) {\n\t\t\t\t\treturn promise.then( null, fn );\n\t\t\t\t},\n\n\t\t\t\t// Keep pipe for back-compat\n\t\t\t\tpipe: function( /* fnDone, fnFail, fnProgress */ ) {\n\t\t\t\t\tvar fns = arguments;\n\n\t\t\t\t\treturn jQuery.Deferred( function( newDefer ) {\n\t\t\t\t\t\tjQuery.each( tuples, function( i, tuple ) {\n\n\t\t\t\t\t\t\t// Map tuples (progress, done, fail) to arguments (done, fail, progress)\n\t\t\t\t\t\t\tvar fn = isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ];\n\n\t\t\t\t\t\t\t// deferred.progress(function() { bind to newDefer or newDefer.notify })\n\t\t\t\t\t\t\t// deferred.done(function() { bind to newDefer or newDefer.resolve })\n\t\t\t\t\t\t\t// deferred.fail(function() { bind to newDefer or newDefer.reject })\n\t\t\t\t\t\t\tdeferred[ tuple[ 1 ] ]( function() {\n\t\t\t\t\t\t\t\tvar returned = fn && fn.apply( this, arguments );\n\t\t\t\t\t\t\t\tif ( returned && isFunction( returned.promise ) ) {\n\t\t\t\t\t\t\t\t\treturned.promise()\n\t\t\t\t\t\t\t\t\t\t.progress( newDefer.notify )\n\t\t\t\t\t\t\t\t\t\t.done( newDefer.resolve )\n\t\t\t\t\t\t\t\t\t\t.fail( newDefer.reject );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tnewDefer[ tuple[ 0 ] + \"With\" ](\n\t\t\t\t\t\t\t\t\t\tthis,\n\t\t\t\t\t\t\t\t\t\tfn ? [ returned ] : arguments\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tfns = null;\n\t\t\t\t\t} ).promise();\n\t\t\t\t},\n\t\t\t\tthen: function( onFulfilled, onRejected, onProgress ) {\n\t\t\t\t\tvar maxDepth = 0;\n\t\t\t\t\tfunction resolve( depth, deferred, handler, special ) {\n\t\t\t\t\t\treturn function() {\n\t\t\t\t\t\t\tvar that = this,\n\t\t\t\t\t\t\t\targs = arguments,\n\t\t\t\t\t\t\t\tmightThrow = function() {\n\t\t\t\t\t\t\t\t\tvar returned, then;\n\n\t\t\t\t\t\t\t\t\t// Support: Promises/A+ section 2.3.3.3.3\n\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-59\n\t\t\t\t\t\t\t\t\t// Ignore double-resolution attempts\n\t\t\t\t\t\t\t\t\tif ( depth < maxDepth ) {\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturned = handler.apply( that, args );\n\n\t\t\t\t\t\t\t\t\t// Support: Promises/A+ section 2.3.1\n\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-48\n\t\t\t\t\t\t\t\t\tif ( returned === deferred.promise() ) {\n\t\t\t\t\t\t\t\t\t\tthrow new TypeError( \"Thenable self-resolution\" );\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// Support: Promises/A+ sections 2.3.3.1, 3.5\n\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-54\n\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-75\n\t\t\t\t\t\t\t\t\t// Retrieve `then` only once\n\t\t\t\t\t\t\t\t\tthen = returned &&\n\n\t\t\t\t\t\t\t\t\t\t// Support: Promises/A+ section 2.3.4\n\t\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-64\n\t\t\t\t\t\t\t\t\t\t// Only check objects and functions for thenability\n\t\t\t\t\t\t\t\t\t\t( typeof returned === \"object\" ||\n\t\t\t\t\t\t\t\t\t\t\ttypeof returned === \"function\" ) &&\n\t\t\t\t\t\t\t\t\t\treturned.then;\n\n\t\t\t\t\t\t\t\t\t// Handle a returned thenable\n\t\t\t\t\t\t\t\t\tif ( isFunction( then ) ) {\n\n\t\t\t\t\t\t\t\t\t\t// Special processors (notify) just wait for resolution\n\t\t\t\t\t\t\t\t\t\tif ( special ) {\n\t\t\t\t\t\t\t\t\t\t\tthen.call(\n\t\t\t\t\t\t\t\t\t\t\t\treturned,\n\t\t\t\t\t\t\t\t\t\t\t\tresolve( maxDepth, deferred, Identity, special ),\n\t\t\t\t\t\t\t\t\t\t\t\tresolve( maxDepth, deferred, Thrower, special )\n\t\t\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\t\t// Normal processors (resolve) also hook into progress\n\t\t\t\t\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\t\t\t\t\t// ...and disregard older resolution values\n\t\t\t\t\t\t\t\t\t\t\tmaxDepth++;\n\n\t\t\t\t\t\t\t\t\t\t\tthen.call(\n\t\t\t\t\t\t\t\t\t\t\t\treturned,\n\t\t\t\t\t\t\t\t\t\t\t\tresolve( maxDepth, deferred, Identity, special ),\n\t\t\t\t\t\t\t\t\t\t\t\tresolve( maxDepth, deferred, Thrower, special ),\n\t\t\t\t\t\t\t\t\t\t\t\tresolve( maxDepth, deferred, Identity,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdeferred.notifyWith )\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// Handle all other returned values\n\t\t\t\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\t\t\t\t// Only substitute handlers pass on context\n\t\t\t\t\t\t\t\t\t\t// and multiple values (non-spec behavior)\n\t\t\t\t\t\t\t\t\t\tif ( handler !== Identity ) {\n\t\t\t\t\t\t\t\t\t\t\tthat = undefined;\n\t\t\t\t\t\t\t\t\t\t\targs = [ returned ];\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t// Process the value(s)\n\t\t\t\t\t\t\t\t\t\t// Default process is resolve\n\t\t\t\t\t\t\t\t\t\t( special || deferred.resolveWith )( that, args );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\t// Only normal processors (resolve) catch and reject exceptions\n\t\t\t\t\t\t\t\tprocess = special ?\n\t\t\t\t\t\t\t\t\tmightThrow :\n\t\t\t\t\t\t\t\t\tfunction() {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tmightThrow();\n\t\t\t\t\t\t\t\t\t\t} catch ( e ) {\n\n\t\t\t\t\t\t\t\t\t\t\tif ( jQuery.Deferred.exceptionHook ) {\n\t\t\t\t\t\t\t\t\t\t\t\tjQuery.Deferred.exceptionHook( e,\n\t\t\t\t\t\t\t\t\t\t\t\t\tprocess.stackTrace );\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Support: Promises/A+ section 2.3.3.3.4.1\n\t\t\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-61\n\t\t\t\t\t\t\t\t\t\t\t// Ignore post-resolution exceptions\n\t\t\t\t\t\t\t\t\t\t\tif ( depth + 1 >= maxDepth ) {\n\n\t\t\t\t\t\t\t\t\t\t\t\t// Only substitute handlers pass on context\n\t\t\t\t\t\t\t\t\t\t\t\t// and multiple values (non-spec behavior)\n\t\t\t\t\t\t\t\t\t\t\t\tif ( handler !== Thrower ) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tthat = undefined;\n\t\t\t\t\t\t\t\t\t\t\t\t\targs = [ e ];\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\tdeferred.rejectWith( that, args );\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t// Support: Promises/A+ section 2.3.3.3.1\n\t\t\t\t\t\t\t// https://promisesaplus.com/#point-57\n\t\t\t\t\t\t\t// Re-resolve promises immediately to dodge false rejection from\n\t\t\t\t\t\t\t// subsequent errors\n\t\t\t\t\t\t\tif ( depth ) {\n\t\t\t\t\t\t\t\tprocess();\n\t\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\t\t// Call an optional hook to record the stack, in case of exception\n\t\t\t\t\t\t\t\t// since it's otherwise lost when execution goes async\n\t\t\t\t\t\t\t\tif ( jQuery.Deferred.getStackHook ) {\n\t\t\t\t\t\t\t\t\tprocess.stackTrace = jQuery.Deferred.getStackHook();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\twindow.setTimeout( process );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn jQuery.Deferred( function( newDefer ) {\n\n\t\t\t\t\t\t// progress_handlers.add( ... )\n\t\t\t\t\t\ttuples[ 0 ][ 3 ].add(\n\t\t\t\t\t\t\tresolve(\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\tnewDefer,\n\t\t\t\t\t\t\t\tisFunction( onProgress ) ?\n\t\t\t\t\t\t\t\t\tonProgress :\n\t\t\t\t\t\t\t\t\tIdentity,\n\t\t\t\t\t\t\t\tnewDefer.notifyWith\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// fulfilled_handlers.add( ... )\n\t\t\t\t\t\ttuples[ 1 ][ 3 ].add(\n\t\t\t\t\t\t\tresolve(\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\tnewDefer,\n\t\t\t\t\t\t\t\tisFunction( onFulfilled ) ?\n\t\t\t\t\t\t\t\t\tonFulfilled :\n\t\t\t\t\t\t\t\t\tIdentity\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// rejected_handlers.add( ... )\n\t\t\t\t\t\ttuples[ 2 ][ 3 ].add(\n\t\t\t\t\t\t\tresolve(\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\tnewDefer,\n\t\t\t\t\t\t\t\tisFunction( onRejected ) ?\n\t\t\t\t\t\t\t\t\tonRejected :\n\t\t\t\t\t\t\t\t\tThrower\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} ).promise();\n\t\t\t\t},\n\n\t\t\t\t// Get a promise for this deferred\n\t\t\t\t// If obj is provided, the promise aspect is added to the object\n\t\t\t\tpromise: function( obj ) {\n\t\t\t\t\treturn obj != null ? jQuery.extend( obj, promise ) : promise;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdeferred = {};\n\n\t\t// Add list-specific methods\n\t\tjQuery.each( tuples, function( i, tuple ) {\n\t\t\tvar list = tuple[ 2 ],\n\t\t\t\tstateString = tuple[ 5 ];\n\n\t\t\t// promise.progress = list.add\n\t\t\t// promise.done = list.add\n\t\t\t// promise.fail = list.add\n\t\t\tpromise[ tuple[ 1 ] ] = list.add;\n\n\t\t\t// Handle state\n\t\t\tif ( stateString ) {\n\t\t\t\tlist.add(\n\t\t\t\t\tfunction() {\n\n\t\t\t\t\t\t// state = \"resolved\" (i.e., fulfilled)\n\t\t\t\t\t\t// state = \"rejected\"\n\t\t\t\t\t\tstate = stateString;\n\t\t\t\t\t},\n\n\t\t\t\t\t// rejected_callbacks.disable\n\t\t\t\t\t// fulfilled_callbacks.disable\n\t\t\t\t\ttuples[ 3 - i ][ 2 ].disable,\n\n\t\t\t\t\t// rejected_handlers.disable\n\t\t\t\t\t// fulfilled_handlers.disable\n\t\t\t\t\ttuples[ 3 - i ][ 3 ].disable,\n\n\t\t\t\t\t// progress_callbacks.lock\n\t\t\t\t\ttuples[ 0 ][ 2 ].lock,\n\n\t\t\t\t\t// progress_handlers.lock\n\t\t\t\t\ttuples[ 0 ][ 3 ].lock\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// progress_handlers.fire\n\t\t\t// fulfilled_handlers.fire\n\t\t\t// rejected_handlers.fire\n\t\t\tlist.add( tuple[ 3 ].fire );\n\n\t\t\t// deferred.notify = function() { deferred.notifyWith(...) }\n\t\t\t// deferred.resolve = function() { deferred.resolveWith(...) }\n\t\t\t// deferred.reject = function() { deferred.rejectWith(...) }\n\t\t\tdeferred[ tuple[ 0 ] ] = function() {\n\t\t\t\tdeferred[ tuple[ 0 ] + \"With\" ]( this === deferred ? undefined : this, arguments );\n\t\t\t\treturn this;\n\t\t\t};\n\n\t\t\t// deferred.notifyWith = list.fireWith\n\t\t\t// deferred.resolveWith = list.fireWith\n\t\t\t// deferred.rejectWith = list.fireWith\n\t\t\tdeferred[ tuple[ 0 ] + \"With\" ] = list.fireWith;\n\t\t} );\n\n\t\t// Make the deferred a promise\n\t\tpromise.promise( deferred );\n\n\t\t// Call given func if any\n\t\tif ( func ) {\n\t\t\tfunc.call( deferred, deferred );\n\t\t}\n\n\t\t// All done!\n\t\treturn deferred;\n\t},\n\n\t// Deferred helper\n\twhen: function( singleValue ) {\n\t\tvar\n\n\t\t\t// count of uncompleted subordinates\n\t\t\tremaining = arguments.length,\n\n\t\t\t// count of unprocessed arguments\n\t\t\ti = remaining,\n\n\t\t\t// subordinate fulfillment data\n\t\t\tresolveContexts = Array( i ),\n\t\t\tresolveValues = slice.call( arguments ),\n\n\t\t\t// the master Deferred\n\t\t\tmaster = jQuery.Deferred(),\n\n\t\t\t// subordinate callback factory\n\t\t\tupdateFunc = function( i ) {\n\t\t\t\treturn function( value ) {\n\t\t\t\t\tresolveContexts[ i ] = this;\n\t\t\t\t\tresolveValues[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;\n\t\t\t\t\tif ( !( --remaining ) ) {\n\t\t\t\t\t\tmaster.resolveWith( resolveContexts, resolveValues );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t};\n\n\t\t// Single- and empty arguments are adopted like Promise.resolve\n\t\tif ( remaining <= 1 ) {\n\t\t\tadoptValue( singleValue, master.done( updateFunc( i ) ).resolve, master.reject,\n\t\t\t\t!remaining );\n\n\t\t\t// Use .then() to unwrap secondary thenables (cf. gh-3000)\n\t\t\tif ( master.state() === \"pending\" ||\n\t\t\t\tisFunction( resolveValues[ i ] && resolveValues[ i ].then ) ) {\n\n\t\t\t\treturn master.then();\n\t\t\t}\n\t\t}\n\n\t\t// Multiple arguments are aggregated like Promise.all array elements\n\t\twhile ( i-- ) {\n\t\t\tadoptValue( resolveValues[ i ], updateFunc( i ), master.reject );\n\t\t}\n\n\t\treturn master.promise();\n\t}\n} );\n\n\n// These usually indicate a programmer mistake during development,\n// warn about them ASAP rather than swallowing them by default.\nvar rerrorNames = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;\n\njQuery.Deferred.exceptionHook = function( error, stack ) {\n\n\t// Support: IE 8 - 9 only\n\t// Console exists when dev tools are open, which can happen at any time\n\tif ( window.console && window.console.warn && error && rerrorNames.test( error.name ) ) {\n\t\twindow.console.warn( \"jQuery.Deferred exception: \" + error.message, error.stack, stack );\n\t}\n};\n\n\n\n\njQuery.readyException = function( error ) {\n\twindow.setTimeout( function() {\n\t\tthrow error;\n\t} );\n};\n\n\n\n\n// The deferred used on DOM ready\nvar readyList = jQuery.Deferred();\n\njQuery.fn.ready = function( fn ) {\n\n\treadyList\n\t\t.then( fn )\n\n\t\t// Wrap jQuery.readyException in a function so that the lookup\n\t\t// happens at the time of error handling instead of callback\n\t\t// registration.\n\t\t.catch( function( error ) {\n\t\t\tjQuery.readyException( error );\n\t\t} );\n\n\treturn this;\n};\n\njQuery.extend( {\n\n\t// Is the DOM ready to be used? Set to true once it occurs.\n\tisReady: false,\n\n\t// A counter to track how many items to wait for before\n\t// the ready event fires. See #6781\n\treadyWait: 1,\n\n\t// Handle when the DOM is ready\n\tready: function( wait ) {\n\n\t\t// Abort if there are pending holds or we're already ready\n\t\tif ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Remember that the DOM is ready\n\t\tjQuery.isReady = true;\n\n\t\t// If a normal DOM Ready event fired, decrement, and wait if need be\n\t\tif ( wait !== true && --jQuery.readyWait > 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If there are functions bound, to execute\n\t\treadyList.resolveWith( document, [ jQuery ] );\n\t}\n} );\n\njQuery.ready.then = readyList.then;\n\n// The ready event handler and self cleanup method\nfunction completed() {\n\tdocument.removeEventListener( \"DOMContentLoaded\", completed );\n\twindow.removeEventListener( \"load\", completed );\n\tjQuery.ready();\n}\n\n// Catch cases where $(document).ready() is called\n// after the browser event has already occurred.\n// Support: IE <=9 - 10 only\n// Older IE sometimes signals \"interactive\" too soon\nif ( document.readyState === \"complete\" ||\n\t( document.readyState !== \"loading\" && !document.documentElement.doScroll ) ) {\n\n\t// Handle it asynchronously to allow scripts the opportunity to delay ready\n\twindow.setTimeout( jQuery.ready );\n\n} else {\n\n\t// Use the handy event callback\n\tdocument.addEventListener( \"DOMContentLoaded\", completed );\n\n\t// A fallback to window.onload, that will always work\n\twindow.addEventListener( \"load\", completed );\n}\n\n\n\n\n// Multifunctional method to get and set values of a collection\n// The value/s can optionally be executed if it's a function\nvar access = function( elems, fn, key, value, chainable, emptyGet, raw ) {\n\tvar i = 0,\n\t\tlen = elems.length,\n\t\tbulk = key == null;\n\n\t// Sets many values\n\tif ( toType( key ) === \"object\" ) {\n\t\tchainable = true;\n\t\tfor ( i in key ) {\n\t\t\taccess( elems, fn, i, key[ i ], true, emptyGet, raw );\n\t\t}\n\n\t// Sets one value\n\t} else if ( value !== undefined ) {\n\t\tchainable = true;\n\n\t\tif ( !isFunction( value ) ) {\n\t\t\traw = true;\n\t\t}\n\n\t\tif ( bulk ) {\n\n\t\t\t// Bulk operations run against the entire set\n\t\t\tif ( raw ) {\n\t\t\t\tfn.call( elems, value );\n\t\t\t\tfn = null;\n\n\t\t\t// ...except when executing function values\n\t\t\t} else {\n\t\t\t\tbulk = fn;\n\t\t\t\tfn = function( elem, key, value ) {\n\t\t\t\t\treturn bulk.call( jQuery( elem ), value );\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif ( fn ) {\n\t\t\tfor ( ; i < len; i++ ) {\n\t\t\t\tfn(\n\t\t\t\t\telems[ i ], key, raw ?\n\t\t\t\t\tvalue :\n\t\t\t\t\tvalue.call( elems[ i ], i, fn( elems[ i ], key ) )\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( chainable ) {\n\t\treturn elems;\n\t}\n\n\t// Gets\n\tif ( bulk ) {\n\t\treturn fn.call( elems );\n\t}\n\n\treturn len ? fn( elems[ 0 ], key ) : emptyGet;\n};\n\n\n// Matches dashed string for camelizing\nvar rmsPrefix = /^-ms-/,\n\trdashAlpha = /-([a-z])/g;\n\n// Used by camelCase as callback to replace()\nfunction fcamelCase( all, letter ) {\n\treturn letter.toUpperCase();\n}\n\n// Convert dashed to camelCase; used by the css and data modules\n// Support: IE <=9 - 11, Edge 12 - 15\n// Microsoft forgot to hump their vendor prefix (#9572)\nfunction camelCase( string ) {\n\treturn string.replace( rmsPrefix, \"ms-\" ).replace( rdashAlpha, fcamelCase );\n}\nvar acceptData = function( owner ) {\n\n\t// Accepts only:\n\t//  - Node\n\t//    - Node.ELEMENT_NODE\n\t//    - Node.DOCUMENT_NODE\n\t//  - Object\n\t//    - Any\n\treturn owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );\n};\n\n\n\n\nfunction Data() {\n\tthis.expando = jQuery.expando + Data.uid++;\n}\n\nData.uid = 1;\n\nData.prototype = {\n\n\tcache: function( owner ) {\n\n\t\t// Check if the owner object already has a cache\n\t\tvar value = owner[ this.expando ];\n\n\t\t// If not, create one\n\t\tif ( !value ) {\n\t\t\tvalue = {};\n\n\t\t\t// We can accept data for non-element nodes in modern browsers,\n\t\t\t// but we should not, see #8335.\n\t\t\t// Always return an empty object.\n\t\t\tif ( acceptData( owner ) ) {\n\n\t\t\t\t// If it is a node unlikely to be stringify-ed or looped over\n\t\t\t\t// use plain assignment\n\t\t\t\tif ( owner.nodeType ) {\n\t\t\t\t\towner[ this.expando ] = value;\n\n\t\t\t\t// Otherwise secure it in a non-enumerable property\n\t\t\t\t// configurable must be true to allow the property to be\n\t\t\t\t// deleted when data is removed\n\t\t\t\t} else {\n\t\t\t\t\tObject.defineProperty( owner, this.expando, {\n\t\t\t\t\t\tvalue: value,\n\t\t\t\t\t\tconfigurable: true\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t},\n\tset: function( owner, data, value ) {\n\t\tvar prop,\n\t\t\tcache = this.cache( owner );\n\n\t\t// Handle: [ owner, key, value ] args\n\t\t// Always use camelCase key (gh-2257)\n\t\tif ( typeof data === \"string\" ) {\n\t\t\tcache[ camelCase( data ) ] = value;\n\n\t\t// Handle: [ owner, { properties } ] args\n\t\t} else {\n\n\t\t\t// Copy the properties one-by-one to the cache object\n\t\t\tfor ( prop in data ) {\n\t\t\t\tcache[ camelCase( prop ) ] = data[ prop ];\n\t\t\t}\n\t\t}\n\t\treturn cache;\n\t},\n\tget: function( owner, key ) {\n\t\treturn key === undefined ?\n\t\t\tthis.cache( owner ) :\n\n\t\t\t// Always use camelCase key (gh-2257)\n\t\t\towner[ this.expando ] && owner[ this.expando ][ camelCase( key ) ];\n\t},\n\taccess: function( owner, key, value ) {\n\n\t\t// In cases where either:\n\t\t//\n\t\t//   1. No key was specified\n\t\t//   2. A string key was specified, but no value provided\n\t\t//\n\t\t// Take the \"read\" path and allow the get method to determine\n\t\t// which value to return, respectively either:\n\t\t//\n\t\t//   1. The entire cache object\n\t\t//   2. The data stored at the key\n\t\t//\n\t\tif ( key === undefined ||\n\t\t\t\t( ( key && typeof key === \"string\" ) && value === undefined ) ) {\n\n\t\t\treturn this.get( owner, key );\n\t\t}\n\n\t\t// When the key is not a string, or both a key and value\n\t\t// are specified, set or extend (existing objects) with either:\n\t\t//\n\t\t//   1. An object of properties\n\t\t//   2. A key and value\n\t\t//\n\t\tthis.set( owner, key, value );\n\n\t\t// Since the \"set\" path can have two possible entry points\n\t\t// return the expected data based on which path was taken[*]\n\t\treturn value !== undefined ? value : key;\n\t},\n\tremove: function( owner, key ) {\n\t\tvar i,\n\t\t\tcache = owner[ this.expando ];\n\n\t\tif ( cache === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( key !== undefined ) {\n\n\t\t\t// Support array or space separated string of keys\n\t\t\tif ( Array.isArray( key ) ) {\n\n\t\t\t\t// If key is an array of keys...\n\t\t\t\t// We always set camelCase keys, so remove that.\n\t\t\t\tkey = key.map( camelCase );\n\t\t\t} else {\n\t\t\t\tkey = camelCase( key );\n\n\t\t\t\t// If a key with the spaces exists, use it.\n\t\t\t\t// Otherwise, create an array by matching non-whitespace\n\t\t\t\tkey = key in cache ?\n\t\t\t\t\t[ key ] :\n\t\t\t\t\t( key.match( rnothtmlwhite ) || [] );\n\t\t\t}\n\n\t\t\ti = key.length;\n\n\t\t\twhile ( i-- ) {\n\t\t\t\tdelete cache[ key[ i ] ];\n\t\t\t}\n\t\t}\n\n\t\t// Remove the expando if there's no more data\n\t\tif ( key === undefined || jQuery.isEmptyObject( cache ) ) {\n\n\t\t\t// Support: Chrome <=35 - 45\n\t\t\t// Webkit & Blink performance suffers when deleting properties\n\t\t\t// from DOM nodes, so set to undefined instead\n\t\t\t// https://bugs.chromium.org/p/chromium/issues/detail?id=378607 (bug restricted)\n\t\t\tif ( owner.nodeType ) {\n\t\t\t\towner[ this.expando ] = undefined;\n\t\t\t} else {\n\t\t\t\tdelete owner[ this.expando ];\n\t\t\t}\n\t\t}\n\t},\n\thasData: function( owner ) {\n\t\tvar cache = owner[ this.expando ];\n\t\treturn cache !== undefined && !jQuery.isEmptyObject( cache );\n\t}\n};\nvar dataPriv = new Data();\n\nvar dataUser = new Data();\n\n\n\n//\tImplementation Summary\n//\n//\t1. Enforce API surface and semantic compatibility with 1.9.x branch\n//\t2. Improve the module's maintainability by reducing the storage\n//\t\tpaths to a single mechanism.\n//\t3. Use the same single mechanism to support \"private\" and \"user\" data.\n//\t4. _Never_ expose \"private\" data to user code (TODO: Drop _data, _removeData)\n//\t5. Avoid exposing implementation details on user objects (eg. expando properties)\n//\t6. Provide a clear path for implementation upgrade to WeakMap in 2014\n\nvar rbrace = /^(?:\\{[\\w\\W]*\\}|\\[[\\w\\W]*\\])$/,\n\trmultiDash = /[A-Z]/g;\n\nfunction getData( data ) {\n\tif ( data === \"true\" ) {\n\t\treturn true;\n\t}\n\n\tif ( data === \"false\" ) {\n\t\treturn false;\n\t}\n\n\tif ( data === \"null\" ) {\n\t\treturn null;\n\t}\n\n\t// Only convert to a number if it doesn't change the string\n\tif ( data === +data + \"\" ) {\n\t\treturn +data;\n\t}\n\n\tif ( rbrace.test( data ) ) {\n\t\treturn JSON.parse( data );\n\t}\n\n\treturn data;\n}\n\nfunction dataAttr( elem, key, data ) {\n\tvar name;\n\n\t// If nothing was found internally, try to fetch any\n\t// data from the HTML5 data-* attribute\n\tif ( data === undefined && elem.nodeType === 1 ) {\n\t\tname = \"data-\" + key.replace( rmultiDash, \"-$&\" ).toLowerCase();\n\t\tdata = elem.getAttribute( name );\n\n\t\tif ( typeof data === \"string\" ) {\n\t\t\ttry {\n\t\t\t\tdata = getData( data );\n\t\t\t} catch ( e ) {}\n\n\t\t\t// Make sure we set the data so it isn't changed later\n\t\t\tdataUser.set( elem, key, data );\n\t\t} else {\n\t\t\tdata = undefined;\n\t\t}\n\t}\n\treturn data;\n}\n\njQuery.extend( {\n\thasData: function( elem ) {\n\t\treturn dataUser.hasData( elem ) || dataPriv.hasData( elem );\n\t},\n\n\tdata: function( elem, name, data ) {\n\t\treturn dataUser.access( elem, name, data );\n\t},\n\n\tremoveData: function( elem, name ) {\n\t\tdataUser.remove( elem, name );\n\t},\n\n\t// TODO: Now that all calls to _data and _removeData have been replaced\n\t// with direct calls to dataPriv methods, these can be deprecated.\n\t_data: function( elem, name, data ) {\n\t\treturn dataPriv.access( elem, name, data );\n\t},\n\n\t_removeData: function( elem, name ) {\n\t\tdataPriv.remove( elem, name );\n\t}\n} );\n\njQuery.fn.extend( {\n\tdata: function( key, value ) {\n\t\tvar i, name, data,\n\t\t\telem = this[ 0 ],\n\t\t\tattrs = elem && elem.attributes;\n\n\t\t// Gets all values\n\t\tif ( key === undefined ) {\n\t\t\tif ( this.length ) {\n\t\t\t\tdata = dataUser.get( elem );\n\n\t\t\t\tif ( elem.nodeType === 1 && !dataPriv.get( elem, \"hasDataAttrs\" ) ) {\n\t\t\t\t\ti = attrs.length;\n\t\t\t\t\twhile ( i-- ) {\n\n\t\t\t\t\t\t// Support: IE 11 only\n\t\t\t\t\t\t// The attrs elements can be null (#14894)\n\t\t\t\t\t\tif ( attrs[ i ] ) {\n\t\t\t\t\t\t\tname = attrs[ i ].name;\n\t\t\t\t\t\t\tif ( name.indexOf( \"data-\" ) === 0 ) {\n\t\t\t\t\t\t\t\tname = camelCase( name.slice( 5 ) );\n\t\t\t\t\t\t\t\tdataAttr( elem, name, data[ name ] );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdataPriv.set( elem, \"hasDataAttrs\", true );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn data;\n\t\t}\n\n\t\t// Sets multiple values\n\t\tif ( typeof key === \"object\" ) {\n\t\t\treturn this.each( function() {\n\t\t\t\tdataUser.set( this, key );\n\t\t\t} );\n\t\t}\n\n\t\treturn access( this, function( value ) {\n\t\t\tvar data;\n\n\t\t\t// The calling jQuery object (element matches) is not empty\n\t\t\t// (and therefore has an element appears at this[ 0 ]) and the\n\t\t\t// `value` parameter was not undefined. An empty jQuery object\n\t\t\t// will result in `undefined` for elem = this[ 0 ] which will\n\t\t\t// throw an exception if an attempt to read a data cache is made.\n\t\t\tif ( elem && value === undefined ) {\n\n\t\t\t\t// Attempt to get data from the cache\n\t\t\t\t// The key will always be camelCased in Data\n\t\t\t\tdata = dataUser.get( elem, key );\n\t\t\t\tif ( data !== undefined ) {\n\t\t\t\t\treturn data;\n\t\t\t\t}\n\n\t\t\t\t// Attempt to \"discover\" the data in\n\t\t\t\t// HTML5 custom data-* attrs\n\t\t\t\tdata = dataAttr( elem, key );\n\t\t\t\tif ( data !== undefined ) {\n\t\t\t\t\treturn data;\n\t\t\t\t}\n\n\t\t\t\t// We tried really hard, but the data doesn't exist.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Set the data...\n\t\t\tthis.each( function() {\n\n\t\t\t\t// We always store the camelCased key\n\t\t\t\tdataUser.set( this, key, value );\n\t\t\t} );\n\t\t}, null, value, arguments.length > 1, null, true );\n\t},\n\n\tremoveData: function( key ) {\n\t\treturn this.each( function() {\n\t\t\tdataUser.remove( this, key );\n\t\t} );\n\t}\n} );\n\n\njQuery.extend( {\n\tqueue: function( elem, type, data ) {\n\t\tvar queue;\n\n\t\tif ( elem ) {\n\t\t\ttype = ( type || \"fx\" ) + \"queue\";\n\t\t\tqueue = dataPriv.get( elem, type );\n\n\t\t\t// Speed up dequeue by getting out quickly if this is just a lookup\n\t\t\tif ( data ) {\n\t\t\t\tif ( !queue || Array.isArray( data ) ) {\n\t\t\t\t\tqueue = dataPriv.access( elem, type, jQuery.makeArray( data ) );\n\t\t\t\t} else {\n\t\t\t\t\tqueue.push( data );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn queue || [];\n\t\t}\n\t},\n\n\tdequeue: function( elem, type ) {\n\t\ttype = type || \"fx\";\n\n\t\tvar queue = jQuery.queue( elem, type ),\n\t\t\tstartLength = queue.length,\n\t\t\tfn = queue.shift(),\n\t\t\thooks = jQuery._queueHooks( elem, type ),\n\t\t\tnext = function() {\n\t\t\t\tjQuery.dequeue( elem, type );\n\t\t\t};\n\n\t\t// If the fx queue is dequeued, always remove the progress sentinel\n\t\tif ( fn === \"inprogress\" ) {\n\t\t\tfn = queue.shift();\n\t\t\tstartLength--;\n\t\t}\n\n\t\tif ( fn ) {\n\n\t\t\t// Add a progress sentinel to prevent the fx queue from being\n\t\t\t// automatically dequeued\n\t\t\tif ( type === \"fx\" ) {\n\t\t\t\tqueue.unshift( \"inprogress\" );\n\t\t\t}\n\n\t\t\t// Clear up the last queue stop function\n\t\t\tdelete hooks.stop;\n\t\t\tfn.call( elem, next, hooks );\n\t\t}\n\n\t\tif ( !startLength && hooks ) {\n\t\t\thooks.empty.fire();\n\t\t}\n\t},\n\n\t// Not public - generate a queueHooks object, or return the current one\n\t_queueHooks: function( elem, type ) {\n\t\tvar key = type + \"queueHooks\";\n\t\treturn dataPriv.get( elem, key ) || dataPriv.access( elem, key, {\n\t\t\tempty: jQuery.Callbacks( \"once memory\" ).add( function() {\n\t\t\t\tdataPriv.remove( elem, [ type + \"queue\", key ] );\n\t\t\t} )\n\t\t} );\n\t}\n} );\n\njQuery.fn.extend( {\n\tqueue: function( type, data ) {\n\t\tvar setter = 2;\n\n\t\tif ( typeof type !== \"string\" ) {\n\t\t\tdata = type;\n\t\t\ttype = \"fx\";\n\t\t\tsetter--;\n\t\t}\n\n\t\tif ( arguments.length < setter ) {\n\t\t\treturn jQuery.queue( this[ 0 ], type );\n\t\t}\n\n\t\treturn data === undefined ?\n\t\t\tthis :\n\t\t\tthis.each( function() {\n\t\t\t\tvar queue = jQuery.queue( this, type, data );\n\n\t\t\t\t// Ensure a hooks for this queue\n\t\t\t\tjQuery._queueHooks( this, type );\n\n\t\t\t\tif ( type === \"fx\" && queue[ 0 ] !== \"inprogress\" ) {\n\t\t\t\t\tjQuery.dequeue( this, type );\n\t\t\t\t}\n\t\t\t} );\n\t},\n\tdequeue: function( type ) {\n\t\treturn this.each( function() {\n\t\t\tjQuery.dequeue( this, type );\n\t\t} );\n\t},\n\tclearQueue: function( type ) {\n\t\treturn this.queue( type || \"fx\", [] );\n\t},\n\n\t// Get a promise resolved when queues of a certain type\n\t// are emptied (fx is the type by default)\n\tpromise: function( type, obj ) {\n\t\tvar tmp,\n\t\t\tcount = 1,\n\t\t\tdefer = jQuery.Deferred(),\n\t\t\telements = this,\n\t\t\ti = this.length,\n\t\t\tresolve = function() {\n\t\t\t\tif ( !( --count ) ) {\n\t\t\t\t\tdefer.resolveWith( elements, [ elements ] );\n\t\t\t\t}\n\t\t\t};\n\n\t\tif ( typeof type !== \"string\" ) {\n\t\t\tobj = type;\n\t\t\ttype = undefined;\n\t\t}\n\t\ttype = type || \"fx\";\n\n\t\twhile ( i-- ) {\n\t\t\ttmp = dataPriv.get( elements[ i ], type + \"queueHooks\" );\n\t\t\tif ( tmp && tmp.empty ) {\n\t\t\t\tcount++;\n\t\t\t\ttmp.empty.add( resolve );\n\t\t\t}\n\t\t}\n\t\tresolve();\n\t\treturn defer.promise( obj );\n\t}\n} );\nvar pnum = ( /[+-]?(?:\\d*\\.|)\\d+(?:[eE][+-]?\\d+|)/ ).source;\n\nvar rcssNum = new RegExp( \"^(?:([+-])=|)(\" + pnum + \")([a-z%]*)$\", \"i\" );\n\n\nvar cssExpand = [ \"Top\", \"Right\", \"Bottom\", \"Left\" ];\n\nvar documentElement = document.documentElement;\n\n\n\n\tvar isAttached = function( elem ) {\n\t\t\treturn jQuery.contains( elem.ownerDocument, elem );\n\t\t},\n\t\tcomposed = { composed: true };\n\n\t// Support: IE 9 - 11+, Edge 12 - 18+, iOS 10.0 - 10.2 only\n\t// Check attachment across shadow DOM boundaries when possible (gh-3504)\n\t// Support: iOS 10.0-10.2 only\n\t// Early iOS 10 versions support `attachShadow` but not `getRootNode`,\n\t// leading to errors. We need to check for `getRootNode`.\n\tif ( documentElement.getRootNode ) {\n\t\tisAttached = function( elem ) {\n\t\t\treturn jQuery.contains( elem.ownerDocument, elem ) ||\n\t\t\t\telem.getRootNode( composed ) === elem.ownerDocument;\n\t\t};\n\t}\nvar isHiddenWithinTree = function( elem, el ) {\n\n\t\t// isHiddenWithinTree might be called from jQuery#filter function;\n\t\t// in that case, element will be second argument\n\t\telem = el || elem;\n\n\t\t// Inline style trumps all\n\t\treturn elem.style.display === \"none\" ||\n\t\t\telem.style.display === \"\" &&\n\n\t\t\t// Otherwise, check computed style\n\t\t\t// Support: Firefox <=43 - 45\n\t\t\t// Disconnected elements can have computed display: none, so first confirm that elem is\n\t\t\t// in the document.\n\t\t\tisAttached( elem ) &&\n\n\t\t\tjQuery.css( elem, \"display\" ) === \"none\";\n\t};\n\nvar swap = function( elem, options, callback, args ) {\n\tvar ret, name,\n\t\told = {};\n\n\t// Remember the old values, and insert the new ones\n\tfor ( name in options ) {\n\t\told[ name ] = elem.style[ name ];\n\t\telem.style[ name ] = options[ name ];\n\t}\n\n\tret = callback.apply( elem, args || [] );\n\n\t// Revert the old values\n\tfor ( name in options ) {\n\t\telem.style[ name ] = old[ name ];\n\t}\n\n\treturn ret;\n};\n\n\n\n\nfunction adjustCSS( elem, prop, valueParts, tween ) {\n\tvar adjusted, scale,\n\t\tmaxIterations = 20,\n\t\tcurrentValue = tween ?\n\t\t\tfunction() {\n\t\t\t\treturn tween.cur();\n\t\t\t} :\n\t\t\tfunction() {\n\t\t\t\treturn jQuery.css( elem, prop, \"\" );\n\t\t\t},\n\t\tinitial = currentValue(),\n\t\tunit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? \"\" : \"px\" ),\n\n\t\t// Starting value computation is required for potential unit mismatches\n\t\tinitialInUnit = elem.nodeType &&\n\t\t\t( jQuery.cssNumber[ prop ] || unit !== \"px\" && +initial ) &&\n\t\t\trcssNum.exec( jQuery.css( elem, prop ) );\n\n\tif ( initialInUnit && initialInUnit[ 3 ] !== unit ) {\n\n\t\t// Support: Firefox <=54\n\t\t// Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144)\n\t\tinitial = initial / 2;\n\n\t\t// Trust units reported by jQuery.css\n\t\tunit = unit || initialInUnit[ 3 ];\n\n\t\t// Iteratively approximate from a nonzero starting point\n\t\tinitialInUnit = +initial || 1;\n\n\t\twhile ( maxIterations-- ) {\n\n\t\t\t// Evaluate and update our best guess (doubling guesses that zero out).\n\t\t\t// Finish if the scale equals or crosses 1 (making the old*new product non-positive).\n\t\t\tjQuery.style( elem, prop, initialInUnit + unit );\n\t\t\tif ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) {\n\t\t\t\tmaxIterations = 0;\n\t\t\t}\n\t\t\tinitialInUnit = initialInUnit / scale;\n\n\t\t}\n\n\t\tinitialInUnit = initialInUnit * 2;\n\t\tjQuery.style( elem, prop, initialInUnit + unit );\n\n\t\t// Make sure we update the tween properties later on\n\t\tvalueParts = valueParts || [];\n\t}\n\n\tif ( valueParts ) {\n\t\tinitialInUnit = +initialInUnit || +initial || 0;\n\n\t\t// Apply relative offset (+=/-=) if specified\n\t\tadjusted = valueParts[ 1 ] ?\n\t\t\tinitialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :\n\t\t\t+valueParts[ 2 ];\n\t\tif ( tween ) {\n\t\t\ttween.unit = unit;\n\t\t\ttween.start = initialInUnit;\n\t\t\ttween.end = adjusted;\n\t\t}\n\t}\n\treturn adjusted;\n}\n\n\nvar defaultDisplayMap = {};\n\nfunction getDefaultDisplay( elem ) {\n\tvar temp,\n\t\tdoc = elem.ownerDocument,\n\t\tnodeName = elem.nodeName,\n\t\tdisplay = defaultDisplayMap[ nodeName ];\n\n\tif ( display ) {\n\t\treturn display;\n\t}\n\n\ttemp = doc.body.appendChild( doc.createElement( nodeName ) );\n\tdisplay = jQuery.css( temp, \"display\" );\n\n\ttemp.parentNode.removeChild( temp );\n\n\tif ( display === \"none\" ) {\n\t\tdisplay = \"block\";\n\t}\n\tdefaultDisplayMap[ nodeName ] = display;\n\n\treturn display;\n}\n\nfunction showHide( elements, show ) {\n\tvar display, elem,\n\t\tvalues = [],\n\t\tindex = 0,\n\t\tlength = elements.length;\n\n\t// Determine new display value for elements that need to change\n\tfor ( ; index < length; index++ ) {\n\t\telem = elements[ index ];\n\t\tif ( !elem.style ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tdisplay = elem.style.display;\n\t\tif ( show ) {\n\n\t\t\t// Since we force visibility upon cascade-hidden elements, an immediate (and slow)\n\t\t\t// check is required in this first loop unless we have a nonempty display value (either\n\t\t\t// inline or about-to-be-restored)\n\t\t\tif ( display === \"none\" ) {\n\t\t\t\tvalues[ index ] = dataPriv.get( elem, \"display\" ) || null;\n\t\t\t\tif ( !values[ index ] ) {\n\t\t\t\t\telem.style.display = \"\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( elem.style.display === \"\" && isHiddenWithinTree( elem ) ) {\n\t\t\t\tvalues[ index ] = getDefaultDisplay( elem );\n\t\t\t}\n\t\t} else {\n\t\t\tif ( display !== \"none\" ) {\n\t\t\t\tvalues[ index ] = \"none\";\n\n\t\t\t\t// Remember what we're overwriting\n\t\t\t\tdataPriv.set( elem, \"display\", display );\n\t\t\t}\n\t\t}\n\t}\n\n\t// Set the display of the elements in a second loop to avoid constant reflow\n\tfor ( index = 0; index < length; index++ ) {\n\t\tif ( values[ index ] != null ) {\n\t\t\telements[ index ].style.display = values[ index ];\n\t\t}\n\t}\n\n\treturn elements;\n}\n\njQuery.fn.extend( {\n\tshow: function() {\n\t\treturn showHide( this, true );\n\t},\n\thide: function() {\n\t\treturn showHide( this );\n\t},\n\ttoggle: function( state ) {\n\t\tif ( typeof state === \"boolean\" ) {\n\t\t\treturn state ? this.show() : this.hide();\n\t\t}\n\n\t\treturn this.each( function() {\n\t\t\tif ( isHiddenWithinTree( this ) ) {\n\t\t\t\tjQuery( this ).show();\n\t\t\t} else {\n\t\t\t\tjQuery( this ).hide();\n\t\t\t}\n\t\t} );\n\t}\n} );\nvar rcheckableType = ( /^(?:checkbox|radio)$/i );\n\nvar rtagName = ( /<([a-z][^\\/\\0>\\x20\\t\\r\\n\\f]*)/i );\n\nvar rscriptType = ( /^$|^module$|\\/(?:java|ecma)script/i );\n\n\n\n// We have to close these tags to support XHTML (#13200)\nvar wrapMap = {\n\n\t// Support: IE <=9 only\n\toption: [ 1, \"<select multiple='multiple'>\", \"</select>\" ],\n\n\t// XHTML parsers do not magically insert elements in the\n\t// same way that tag soup parsers do. So we cannot shorten\n\t// this by omitting <tbody> or other required elements.\n\tthead: [ 1, \"<table>\", \"</table>\" ],\n\tcol: [ 2, \"<table><colgroup>\", \"</colgroup></table>\" ],\n\ttr: [ 2, \"<table><tbody>\", \"</tbody></table>\" ],\n\ttd: [ 3, \"<table><tbody><tr>\", \"</tr></tbody></table>\" ],\n\n\t_default: [ 0, \"\", \"\" ]\n};\n\n// Support: IE <=9 only\nwrapMap.optgroup = wrapMap.option;\n\nwrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;\nwrapMap.th = wrapMap.td;\n\n\nfunction getAll( context, tag ) {\n\n\t// Support: IE <=9 - 11 only\n\t// Use typeof to avoid zero-argument method invocation on host objects (#15151)\n\tvar ret;\n\n\tif ( typeof context.getElementsByTagName !== \"undefined\" ) {\n\t\tret = context.getElementsByTagName( tag || \"*\" );\n\n\t} else if ( typeof context.querySelectorAll !== \"undefined\" ) {\n\t\tret = context.querySelectorAll( tag || \"*\" );\n\n\t} else {\n\t\tret = [];\n\t}\n\n\tif ( tag === undefined || tag && nodeName( context, tag ) ) {\n\t\treturn jQuery.merge( [ context ], ret );\n\t}\n\n\treturn ret;\n}\n\n\n// Mark scripts as having already been evaluated\nfunction setGlobalEval( elems, refElements ) {\n\tvar i = 0,\n\t\tl = elems.length;\n\n\tfor ( ; i < l; i++ ) {\n\t\tdataPriv.set(\n\t\t\telems[ i ],\n\t\t\t\"globalEval\",\n\t\t\t!refElements || dataPriv.get( refElements[ i ], \"globalEval\" )\n\t\t);\n\t}\n}\n\n\nvar rhtml = /<|&#?\\w+;/;\n\nfunction buildFragment( elems, context, scripts, selection, ignored ) {\n\tvar elem, tmp, tag, wrap, attached, j,\n\t\tfragment = context.createDocumentFragment(),\n\t\tnodes = [],\n\t\ti = 0,\n\t\tl = elems.length;\n\n\tfor ( ; i < l; i++ ) {\n\t\telem = elems[ i ];\n\n\t\tif ( elem || elem === 0 ) {\n\n\t\t\t// Add nodes directly\n\t\t\tif ( toType( elem ) === \"object\" ) {\n\n\t\t\t\t// Support: Android <=4.0 only, PhantomJS 1 only\n\t\t\t\t// push.apply(_, arraylike) throws on ancient WebKit\n\t\t\t\tjQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );\n\n\t\t\t// Convert non-html into a text node\n\t\t\t} else if ( !rhtml.test( elem ) ) {\n\t\t\t\tnodes.push( context.createTextNode( elem ) );\n\n\t\t\t// Convert html into DOM nodes\n\t\t\t} else {\n\t\t\t\ttmp = tmp || fragment.appendChild( context.createElement( \"div\" ) );\n\n\t\t\t\t// Deserialize a standard representation\n\t\t\t\ttag = ( rtagName.exec( elem ) || [ \"\", \"\" ] )[ 1 ].toLowerCase();\n\t\t\t\twrap = wrapMap[ tag ] || wrapMap._default;\n\t\t\t\ttmp.innerHTML = wrap[ 1 ] + jQuery.htmlPrefilter( elem ) + wrap[ 2 ];\n\n\t\t\t\t// Descend through wrappers to the right content\n\t\t\t\tj = wrap[ 0 ];\n\t\t\t\twhile ( j-- ) {\n\t\t\t\t\ttmp = tmp.lastChild;\n\t\t\t\t}\n\n\t\t\t\t// Support: Android <=4.0 only, PhantomJS 1 only\n\t\t\t\t// push.apply(_, arraylike) throws on ancient WebKit\n\t\t\t\tjQuery.merge( nodes, tmp.childNodes );\n\n\t\t\t\t// Remember the top-level container\n\t\t\t\ttmp = fragment.firstChild;\n\n\t\t\t\t// Ensure the created nodes are orphaned (#12392)\n\t\t\t\ttmp.textContent = \"\";\n\t\t\t}\n\t\t}\n\t}\n\n\t// Remove wrapper from fragment\n\tfragment.textContent = \"\";\n\n\ti = 0;\n\twhile ( ( elem = nodes[ i++ ] ) ) {\n\n\t\t// Skip elements already in the context collection (trac-4087)\n\t\tif ( selection && jQuery.inArray( elem, selection ) > -1 ) {\n\t\t\tif ( ignored ) {\n\t\t\t\tignored.push( elem );\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tattached = isAttached( elem );\n\n\t\t// Append to fragment\n\t\ttmp = getAll( fragment.appendChild( elem ), \"script\" );\n\n\t\t// Preserve script evaluation history\n\t\tif ( attached ) {\n\t\t\tsetGlobalEval( tmp );\n\t\t}\n\n\t\t// Capture executables\n\t\tif ( scripts ) {\n\t\t\tj = 0;\n\t\t\twhile ( ( elem = tmp[ j++ ] ) ) {\n\t\t\t\tif ( rscriptType.test( elem.type || \"\" ) ) {\n\t\t\t\t\tscripts.push( elem );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn fragment;\n}\n\n\n( function() {\n\tvar fragment = document.createDocumentFragment(),\n\t\tdiv = fragment.appendChild( document.createElement( \"div\" ) ),\n\t\tinput = document.createElement( \"input\" );\n\n\t// Support: Android 4.0 - 4.3 only\n\t// Check state lost if the name is set (#11217)\n\t// Support: Windows Web Apps (WWA)\n\t// `name` and `type` must use .setAttribute for WWA (#14901)\n\tinput.setAttribute( \"type\", \"radio\" );\n\tinput.setAttribute( \"checked\", \"checked\" );\n\tinput.setAttribute( \"name\", \"t\" );\n\n\tdiv.appendChild( input );\n\n\t// Support: Android <=4.1 only\n\t// Older WebKit doesn't clone checked state correctly in fragments\n\tsupport.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;\n\n\t// Support: IE <=11 only\n\t// Make sure textarea (and checkbox) defaultValue is properly cloned\n\tdiv.innerHTML = \"<textarea>x</textarea>\";\n\tsupport.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;\n} )();\n\n\nvar\n\trkeyEvent = /^key/,\n\trmouseEvent = /^(?:mouse|pointer|contextmenu|drag|drop)|click/,\n\trtypenamespace = /^([^.]*)(?:\\.(.+)|)/;\n\nfunction returnTrue() {\n\treturn true;\n}\n\nfunction returnFalse() {\n\treturn false;\n}\n\n// Support: IE <=9 - 11+\n// focus() and blur() are asynchronous, except when they are no-op.\n// So expect focus to be synchronous when the element is already active,\n// and blur to be synchronous when the element is not already active.\n// (focus and blur are always synchronous in other supported browsers,\n// this just defines when we can count on it).\nfunction expectSync( elem, type ) {\n\treturn ( elem === safeActiveElement() ) === ( type === \"focus\" );\n}\n\n// Support: IE <=9 only\n// Accessing document.activeElement can throw unexpectedly\n// https://bugs.jquery.com/ticket/13393\nfunction safeActiveElement() {\n\ttry {\n\t\treturn document.activeElement;\n\t} catch ( err ) { }\n}\n\nfunction on( elem, types, selector, data, fn, one ) {\n\tvar origFn, type;\n\n\t// Types can be a map of types/handlers\n\tif ( typeof types === \"object\" ) {\n\n\t\t// ( types-Object, selector, data )\n\t\tif ( typeof selector !== \"string\" ) {\n\n\t\t\t// ( types-Object, data )\n\t\t\tdata = data || selector;\n\t\t\tselector = undefined;\n\t\t}\n\t\tfor ( type in types ) {\n\t\t\ton( elem, type, selector, data, types[ type ], one );\n\t\t}\n\t\treturn elem;\n\t}\n\n\tif ( data == null && fn == null ) {\n\n\t\t// ( types, fn )\n\t\tfn = selector;\n\t\tdata = selector = undefined;\n\t} else if ( fn == null ) {\n\t\tif ( typeof selector === \"string\" ) {\n\n\t\t\t// ( types, selector, fn )\n\t\t\tfn = data;\n\t\t\tdata = undefined;\n\t\t} else {\n\n\t\t\t// ( types, data, fn )\n\t\t\tfn = data;\n\t\t\tdata = selector;\n\t\t\tselector = undefined;\n\t\t}\n\t}\n\tif ( fn === false ) {\n\t\tfn = returnFalse;\n\t} else if ( !fn ) {\n\t\treturn elem;\n\t}\n\n\tif ( one === 1 ) {\n\t\torigFn = fn;\n\t\tfn = function( event ) {\n\n\t\t\t// Can use an empty set, since event contains the info\n\t\t\tjQuery().off( event );\n\t\t\treturn origFn.apply( this, arguments );\n\t\t};\n\n\t\t// Use same guid so caller can remove using origFn\n\t\tfn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );\n\t}\n\treturn elem.each( function() {\n\t\tjQuery.event.add( this, types, fn, data, selector );\n\t} );\n}\n\n/*\n * Helper functions for managing events -- not part of the public interface.\n * Props to Dean Edwards' addEvent library for many of the ideas.\n */\njQuery.event = {\n\n\tglobal: {},\n\n\tadd: function( elem, types, handler, data, selector ) {\n\n\t\tvar handleObjIn, eventHandle, tmp,\n\t\t\tevents, t, handleObj,\n\t\t\tspecial, handlers, type, namespaces, origType,\n\t\t\telemData = dataPriv.get( elem );\n\n\t\t// Don't attach events to noData or text/comment nodes (but allow plain objects)\n\t\tif ( !elemData ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Caller can pass in an object of custom data in lieu of the handler\n\t\tif ( handler.handler ) {\n\t\t\thandleObjIn = handler;\n\t\t\thandler = handleObjIn.handler;\n\t\t\tselector = handleObjIn.selector;\n\t\t}\n\n\t\t// Ensure that invalid selectors throw exceptions at attach time\n\t\t// Evaluate against documentElement in case elem is a non-element node (e.g., document)\n\t\tif ( selector ) {\n\t\t\tjQuery.find.matchesSelector( documentElement, selector );\n\t\t}\n\n\t\t// Make sure that the handler has a unique ID, used to find/remove it later\n\t\tif ( !handler.guid ) {\n\t\t\thandler.guid = jQuery.guid++;\n\t\t}\n\n\t\t// Init the element's event structure and main handler, if this is the first\n\t\tif ( !( events = elemData.events ) ) {\n\t\t\tevents = elemData.events = {};\n\t\t}\n\t\tif ( !( eventHandle = elemData.handle ) ) {\n\t\t\teventHandle = elemData.handle = function( e ) {\n\n\t\t\t\t// Discard the second event of a jQuery.event.trigger() and\n\t\t\t\t// when an event is called after a page has unloaded\n\t\t\t\treturn typeof jQuery !== \"undefined\" && jQuery.event.triggered !== e.type ?\n\t\t\t\t\tjQuery.event.dispatch.apply( elem, arguments ) : undefined;\n\t\t\t};\n\t\t}\n\n\t\t// Handle multiple events separated by a space\n\t\ttypes = ( types || \"\" ).match( rnothtmlwhite ) || [ \"\" ];\n\t\tt = types.length;\n\t\twhile ( t-- ) {\n\t\t\ttmp = rtypenamespace.exec( types[ t ] ) || [];\n\t\t\ttype = origType = tmp[ 1 ];\n\t\t\tnamespaces = ( tmp[ 2 ] || \"\" ).split( \".\" ).sort();\n\n\t\t\t// There *must* be a type, no attaching namespace-only handlers\n\t\t\tif ( !type ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If event changes its type, use the special event handlers for the changed type\n\t\t\tspecial = jQuery.event.special[ type ] || {};\n\n\t\t\t// If selector defined, determine special event api type, otherwise given type\n\t\t\ttype = ( selector ? special.delegateType : special.bindType ) || type;\n\n\t\t\t// Update special based on newly reset type\n\t\t\tspecial = jQuery.event.special[ type ] || {};\n\n\t\t\t// handleObj is passed to all event handlers\n\t\t\thandleObj = jQuery.extend( {\n\t\t\t\ttype: type,\n\t\t\t\torigType: origType,\n\t\t\t\tdata: data,\n\t\t\t\thandler: handler,\n\t\t\t\tguid: handler.guid,\n\t\t\t\tselector: selector,\n\t\t\t\tneedsContext: selector && jQuery.expr.match.needsContext.test( selector ),\n\t\t\t\tnamespace: namespaces.join( \".\" )\n\t\t\t}, handleObjIn );\n\n\t\t\t// Init the event handler queue if we're the first\n\t\t\tif ( !( handlers = events[ type ] ) ) {\n\t\t\t\thandlers = events[ type ] = [];\n\t\t\t\thandlers.delegateCount = 0;\n\n\t\t\t\t// Only use addEventListener if the special events handler returns false\n\t\t\t\tif ( !special.setup ||\n\t\t\t\t\tspecial.setup.call( elem, data, namespaces, eventHandle ) === false ) {\n\n\t\t\t\t\tif ( elem.addEventListener ) {\n\t\t\t\t\t\telem.addEventListener( type, eventHandle );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( special.add ) {\n\t\t\t\tspecial.add.call( elem, handleObj );\n\n\t\t\t\tif ( !handleObj.handler.guid ) {\n\t\t\t\t\thandleObj.handler.guid = handler.guid;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add to the element's handler list, delegates in front\n\t\t\tif ( selector ) {\n\t\t\t\thandlers.splice( handlers.delegateCount++, 0, handleObj );\n\t\t\t} else {\n\t\t\t\thandlers.push( handleObj );\n\t\t\t}\n\n\t\t\t// Keep track of which events have ever been used, for event optimization\n\t\t\tjQuery.event.global[ type ] = true;\n\t\t}\n\n\t},\n\n\t// Detach an event or set of events from an element\n\tremove: function( elem, types, handler, selector, mappedTypes ) {\n\n\t\tvar j, origCount, tmp,\n\t\t\tevents, t, handleObj,\n\t\t\tspecial, handlers, type, namespaces, origType,\n\t\t\telemData = dataPriv.hasData( elem ) && dataPriv.get( elem );\n\n\t\tif ( !elemData || !( events = elemData.events ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Once for each type.namespace in types; type may be omitted\n\t\ttypes = ( types || \"\" ).match( rnothtmlwhite ) || [ \"\" ];\n\t\tt = types.length;\n\t\twhile ( t-- ) {\n\t\t\ttmp = rtypenamespace.exec( types[ t ] ) || [];\n\t\t\ttype = origType = tmp[ 1 ];\n\t\t\tnamespaces = ( tmp[ 2 ] || \"\" ).split( \".\" ).sort();\n\n\t\t\t// Unbind all events (on this namespace, if provided) for the element\n\t\t\tif ( !type ) {\n\t\t\t\tfor ( type in events ) {\n\t\t\t\t\tjQuery.event.remove( elem, type + types[ t ], handler, selector, true );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tspecial = jQuery.event.special[ type ] || {};\n\t\t\ttype = ( selector ? special.delegateType : special.bindType ) || type;\n\t\t\thandlers = events[ type ] || [];\n\t\t\ttmp = tmp[ 2 ] &&\n\t\t\t\tnew RegExp( \"(^|\\\\.)\" + namespaces.join( \"\\\\.(?:.*\\\\.|)\" ) + \"(\\\\.|$)\" );\n\n\t\t\t// Remove matching events\n\t\t\torigCount = j = handlers.length;\n\t\t\twhile ( j-- ) {\n\t\t\t\thandleObj = handlers[ j ];\n\n\t\t\t\tif ( ( mappedTypes || origType === handleObj.origType ) &&\n\t\t\t\t\t( !handler || handler.guid === handleObj.guid ) &&\n\t\t\t\t\t( !tmp || tmp.test( handleObj.namespace ) ) &&\n\t\t\t\t\t( !selector || selector === handleObj.selector ||\n\t\t\t\t\t\tselector === \"**\" && handleObj.selector ) ) {\n\t\t\t\t\thandlers.splice( j, 1 );\n\n\t\t\t\t\tif ( handleObj.selector ) {\n\t\t\t\t\t\thandlers.delegateCount--;\n\t\t\t\t\t}\n\t\t\t\t\tif ( special.remove ) {\n\t\t\t\t\t\tspecial.remove.call( elem, handleObj );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Remove generic event handler if we removed something and no more handlers exist\n\t\t\t// (avoids potential for endless recursion during removal of special event handlers)\n\t\t\tif ( origCount && !handlers.length ) {\n\t\t\t\tif ( !special.teardown ||\n\t\t\t\t\tspecial.teardown.call( elem, namespaces, elemData.handle ) === false ) {\n\n\t\t\t\t\tjQuery.removeEvent( elem, type, elemData.handle );\n\t\t\t\t}\n\n\t\t\t\tdelete events[ type ];\n\t\t\t}\n\t\t}\n\n\t\t// Remove data and the expando if it's no longer used\n\t\tif ( jQuery.isEmptyObject( events ) ) {\n\t\t\tdataPriv.remove( elem, \"handle events\" );\n\t\t}\n\t},\n\n\tdispatch: function( nativeEvent ) {\n\n\t\t// Make a writable jQuery.Event from the native event object\n\t\tvar event = jQuery.event.fix( nativeEvent );\n\n\t\tvar i, j, ret, matched, handleObj, handlerQueue,\n\t\t\targs = new Array( arguments.length ),\n\t\t\thandlers = ( dataPriv.get( this, \"events\" ) || {} )[ event.type ] || [],\n\t\t\tspecial = jQuery.event.special[ event.type ] || {};\n\n\t\t// Use the fix-ed jQuery.Event rather than the (read-only) native event\n\t\targs[ 0 ] = event;\n\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\targs[ i ] = arguments[ i ];\n\t\t}\n\n\t\tevent.delegateTarget = this;\n\n\t\t// Call the preDispatch hook for the mapped type, and let it bail if desired\n\t\tif ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Determine handlers\n\t\thandlerQueue = jQuery.event.handlers.call( this, event, handlers );\n\n\t\t// Run delegates first; they may want to stop propagation beneath us\n\t\ti = 0;\n\t\twhile ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) {\n\t\t\tevent.currentTarget = matched.elem;\n\n\t\t\tj = 0;\n\t\t\twhile ( ( handleObj = matched.handlers[ j++ ] ) &&\n\t\t\t\t!event.isImmediatePropagationStopped() ) {\n\n\t\t\t\t// If the event is namespaced, then each handler is only invoked if it is\n\t\t\t\t// specially universal or its namespaces are a superset of the event's.\n\t\t\t\tif ( !event.rnamespace || handleObj.namespace === false ||\n\t\t\t\t\tevent.rnamespace.test( handleObj.namespace ) ) {\n\n\t\t\t\t\tevent.handleObj = handleObj;\n\t\t\t\t\tevent.data = handleObj.data;\n\n\t\t\t\t\tret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle ||\n\t\t\t\t\t\thandleObj.handler ).apply( matched.elem, args );\n\n\t\t\t\t\tif ( ret !== undefined ) {\n\t\t\t\t\t\tif ( ( event.result = ret ) === false ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Call the postDispatch hook for the mapped type\n\t\tif ( special.postDispatch ) {\n\t\t\tspecial.postDispatch.call( this, event );\n\t\t}\n\n\t\treturn event.result;\n\t},\n\n\thandlers: function( event, handlers ) {\n\t\tvar i, handleObj, sel, matchedHandlers, matchedSelectors,\n\t\t\thandlerQueue = [],\n\t\t\tdelegateCount = handlers.delegateCount,\n\t\t\tcur = event.target;\n\n\t\t// Find delegate handlers\n\t\tif ( delegateCount &&\n\n\t\t\t// Support: IE <=9\n\t\t\t// Black-hole SVG <use> instance trees (trac-13180)\n\t\t\tcur.nodeType &&\n\n\t\t\t// Support: Firefox <=42\n\t\t\t// Suppress spec-violating clicks indicating a non-primary pointer button (trac-3861)\n\t\t\t// https://www.w3.org/TR/DOM-Level-3-Events/#event-type-click\n\t\t\t// Support: IE 11 only\n\t\t\t// ...but not arrow key \"clicks\" of radio inputs, which can have `button` -1 (gh-2343)\n\t\t\t!( event.type === \"click\" && event.button >= 1 ) ) {\n\n\t\t\tfor ( ; cur !== this; cur = cur.parentNode || this ) {\n\n\t\t\t\t// Don't check non-elements (#13208)\n\t\t\t\t// Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)\n\t\t\t\tif ( cur.nodeType === 1 && !( event.type === \"click\" && cur.disabled === true ) ) {\n\t\t\t\t\tmatchedHandlers = [];\n\t\t\t\t\tmatchedSelectors = {};\n\t\t\t\t\tfor ( i = 0; i < delegateCount; i++ ) {\n\t\t\t\t\t\thandleObj = handlers[ i ];\n\n\t\t\t\t\t\t// Don't conflict with Object.prototype properties (#13203)\n\t\t\t\t\t\tsel = handleObj.selector + \" \";\n\n\t\t\t\t\t\tif ( matchedSelectors[ sel ] === undefined ) {\n\t\t\t\t\t\t\tmatchedSelectors[ sel ] = handleObj.needsContext ?\n\t\t\t\t\t\t\t\tjQuery( sel, this ).index( cur ) > -1 :\n\t\t\t\t\t\t\t\tjQuery.find( sel, this, null, [ cur ] ).length;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( matchedSelectors[ sel ] ) {\n\t\t\t\t\t\t\tmatchedHandlers.push( handleObj );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif ( matchedHandlers.length ) {\n\t\t\t\t\t\thandlerQueue.push( { elem: cur, handlers: matchedHandlers } );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Add the remaining (directly-bound) handlers\n\t\tcur = this;\n\t\tif ( delegateCount < handlers.length ) {\n\t\t\thandlerQueue.push( { elem: cur, handlers: handlers.slice( delegateCount ) } );\n\t\t}\n\n\t\treturn handlerQueue;\n\t},\n\n\taddProp: function( name, hook ) {\n\t\tObject.defineProperty( jQuery.Event.prototype, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\n\t\t\tget: isFunction( hook ) ?\n\t\t\t\tfunction() {\n\t\t\t\t\tif ( this.originalEvent ) {\n\t\t\t\t\t\t\treturn hook( this.originalEvent );\n\t\t\t\t\t}\n\t\t\t\t} :\n\t\t\t\tfunction() {\n\t\t\t\t\tif ( this.originalEvent ) {\n\t\t\t\t\t\t\treturn this.originalEvent[ name ];\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\tset: function( value ) {\n\t\t\t\tObject.defineProperty( this, name, {\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tvalue: value\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t},\n\n\tfix: function( originalEvent ) {\n\t\treturn originalEvent[ jQuery.expando ] ?\n\t\t\toriginalEvent :\n\t\t\tnew jQuery.Event( originalEvent );\n\t},\n\n\tspecial: {\n\t\tload: {\n\n\t\t\t// Prevent triggered image.load events from bubbling to window.load\n\t\t\tnoBubble: true\n\t\t},\n\t\tclick: {\n\n\t\t\t// Utilize native event to ensure correct state for checkable inputs\n\t\t\tsetup: function( data ) {\n\n\t\t\t\t// For mutual compressibility with _default, replace `this` access with a local var.\n\t\t\t\t// `|| data` is dead code meant only to preserve the variable through minification.\n\t\t\t\tvar el = this || data;\n\n\t\t\t\t// Claim the first handler\n\t\t\t\tif ( rcheckableType.test( el.type ) &&\n\t\t\t\t\tel.click && nodeName( el, \"input\" ) ) {\n\n\t\t\t\t\t// dataPriv.set( el, \"click\", ... )\n\t\t\t\t\tleverageNative( el, \"click\", returnTrue );\n\t\t\t\t}\n\n\t\t\t\t// Return false to allow normal processing in the caller\n\t\t\t\treturn false;\n\t\t\t},\n\t\t\ttrigger: function( data ) {\n\n\t\t\t\t// For mutual compressibility with _default, replace `this` access with a local var.\n\t\t\t\t// `|| data` is dead code meant only to preserve the variable through minification.\n\t\t\t\tvar el = this || data;\n\n\t\t\t\t// Force setup before triggering a click\n\t\t\t\tif ( rcheckableType.test( el.type ) &&\n\t\t\t\t\tel.click && nodeName( el, \"input\" ) ) {\n\n\t\t\t\t\tleverageNative( el, \"click\" );\n\t\t\t\t}\n\n\t\t\t\t// Return non-false to allow normal event-path propagation\n\t\t\t\treturn true;\n\t\t\t},\n\n\t\t\t// For cross-browser consistency, suppress native .click() on links\n\t\t\t// Also prevent it if we're currently inside a leveraged native-event stack\n\t\t\t_default: function( event ) {\n\t\t\t\tvar target = event.target;\n\t\t\t\treturn rcheckableType.test( target.type ) &&\n\t\t\t\t\ttarget.click && nodeName( target, \"input\" ) &&\n\t\t\t\t\tdataPriv.get( target, \"click\" ) ||\n\t\t\t\t\tnodeName( target, \"a\" );\n\t\t\t}\n\t\t},\n\n\t\tbeforeunload: {\n\t\t\tpostDispatch: function( event ) {\n\n\t\t\t\t// Support: Firefox 20+\n\t\t\t\t// Firefox doesn't alert if the returnValue field is not set.\n\t\t\t\tif ( event.result !== undefined && event.originalEvent ) {\n\t\t\t\t\tevent.originalEvent.returnValue = event.result;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};\n\n// Ensure the presence of an event listener that handles manually-triggered\n// synthetic events by interrupting progress until reinvoked in response to\n// *native* events that it fires directly, ensuring that state changes have\n// already occurred before other listeners are invoked.\nfunction leverageNative( el, type, expectSync ) {\n\n\t// Missing expectSync indicates a trigger call, which must force setup through jQuery.event.add\n\tif ( !expectSync ) {\n\t\tif ( dataPriv.get( el, type ) === undefined ) {\n\t\t\tjQuery.event.add( el, type, returnTrue );\n\t\t}\n\t\treturn;\n\t}\n\n\t// Register the controller as a special universal handler for all event namespaces\n\tdataPriv.set( el, type, false );\n\tjQuery.event.add( el, type, {\n\t\tnamespace: false,\n\t\thandler: function( event ) {\n\t\t\tvar notAsync, result,\n\t\t\t\tsaved = dataPriv.get( this, type );\n\n\t\t\tif ( ( event.isTrigger & 1 ) && this[ type ] ) {\n\n\t\t\t\t// Interrupt processing of the outer synthetic .trigger()ed event\n\t\t\t\t// Saved data should be false in such cases, but might be a leftover capture object\n\t\t\t\t// from an async native handler (gh-4350)\n\t\t\t\tif ( !saved.length ) {\n\n\t\t\t\t\t// Store arguments for use when handling the inner native event\n\t\t\t\t\t// There will always be at least one argument (an event object), so this array\n\t\t\t\t\t// will not be confused with a leftover capture object.\n\t\t\t\t\tsaved = slice.call( arguments );\n\t\t\t\t\tdataPriv.set( this, type, saved );\n\n\t\t\t\t\t// Trigger the native event and capture its result\n\t\t\t\t\t// Support: IE <=9 - 11+\n\t\t\t\t\t// focus() and blur() are asynchronous\n\t\t\t\t\tnotAsync = expectSync( this, type );\n\t\t\t\t\tthis[ type ]();\n\t\t\t\t\tresult = dataPriv.get( this, type );\n\t\t\t\t\tif ( saved !== result || notAsync ) {\n\t\t\t\t\t\tdataPriv.set( this, type, false );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult = {};\n\t\t\t\t\t}\n\t\t\t\t\tif ( saved !== result ) {\n\n\t\t\t\t\t\t// Cancel the outer synthetic event\n\t\t\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\treturn result.value;\n\t\t\t\t\t}\n\n\t\t\t\t// If this is an inner synthetic event for an event with a bubbling surrogate\n\t\t\t\t// (focus or blur), assume that the surrogate already propagated from triggering the\n\t\t\t\t// native event and prevent that from happening again here.\n\t\t\t\t// This technically gets the ordering wrong w.r.t. to `.trigger()` (in which the\n\t\t\t\t// bubbling surrogate propagates *after* the non-bubbling base), but that seems\n\t\t\t\t// less bad than duplication.\n\t\t\t\t} else if ( ( jQuery.event.special[ type ] || {} ).delegateType ) {\n\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t}\n\n\t\t\t// If this is a native event triggered above, everything is now in order\n\t\t\t// Fire an inner synthetic event with the original arguments\n\t\t\t} else if ( saved.length ) {\n\n\t\t\t\t// ...and capture the result\n\t\t\t\tdataPriv.set( this, type, {\n\t\t\t\t\tvalue: jQuery.event.trigger(\n\n\t\t\t\t\t\t// Support: IE <=9 - 11+\n\t\t\t\t\t\t// Extend with the prototype to reset the above stopImmediatePropagation()\n\t\t\t\t\t\tjQuery.extend( saved[ 0 ], jQuery.Event.prototype ),\n\t\t\t\t\t\tsaved.slice( 1 ),\n\t\t\t\t\t\tthis\n\t\t\t\t\t)\n\t\t\t\t} );\n\n\t\t\t\t// Abort handling of the native event\n\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t}\n\t\t}\n\t} );\n}\n\njQuery.removeEvent = function( elem, type, handle ) {\n\n\t// This \"if\" is needed for plain objects\n\tif ( elem.removeEventListener ) {\n\t\telem.removeEventListener( type, handle );\n\t}\n};\n\njQuery.Event = function( src, props ) {\n\n\t// Allow instantiation without the 'new' keyword\n\tif ( !( this instanceof jQuery.Event ) ) {\n\t\treturn new jQuery.Event( src, props );\n\t}\n\n\t// Event object\n\tif ( src && src.type ) {\n\t\tthis.originalEvent = src;\n\t\tthis.type = src.type;\n\n\t\t// Events bubbling up the document may have been marked as prevented\n\t\t// by a handler lower down the tree; reflect the correct value.\n\t\tthis.isDefaultPrevented = src.defaultPrevented ||\n\t\t\t\tsrc.defaultPrevented === undefined &&\n\n\t\t\t\t// Support: Android <=2.3 only\n\t\t\t\tsrc.returnValue === false ?\n\t\t\treturnTrue :\n\t\t\treturnFalse;\n\n\t\t// Create target properties\n\t\t// Support: Safari <=6 - 7 only\n\t\t// Target should not be a text node (#504, #13143)\n\t\tthis.target = ( src.target && src.target.nodeType === 3 ) ?\n\t\t\tsrc.target.parentNode :\n\t\t\tsrc.target;\n\n\t\tthis.currentTarget = src.currentTarget;\n\t\tthis.relatedTarget = src.relatedTarget;\n\n\t// Event type\n\t} else {\n\t\tthis.type = src;\n\t}\n\n\t// Put explicitly provided properties onto the event object\n\tif ( props ) {\n\t\tjQuery.extend( this, props );\n\t}\n\n\t// Create a timestamp if incoming event doesn't have one\n\tthis.timeStamp = src && src.timeStamp || Date.now();\n\n\t// Mark it as fixed\n\tthis[ jQuery.expando ] = true;\n};\n\n// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding\n// https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html\njQuery.Event.prototype = {\n\tconstructor: jQuery.Event,\n\tisDefaultPrevented: returnFalse,\n\tisPropagationStopped: returnFalse,\n\tisImmediatePropagationStopped: returnFalse,\n\tisSimulated: false,\n\n\tpreventDefault: function() {\n\t\tvar e = this.originalEvent;\n\n\t\tthis.isDefaultPrevented = returnTrue;\n\n\t\tif ( e && !this.isSimulated ) {\n\t\t\te.preventDefault();\n\t\t}\n\t},\n\tstopPropagation: function() {\n\t\tvar e = this.originalEvent;\n\n\t\tthis.isPropagationStopped = returnTrue;\n\n\t\tif ( e && !this.isSimulated ) {\n\t\t\te.stopPropagation();\n\t\t}\n\t},\n\tstopImmediatePropagation: function() {\n\t\tvar e = this.originalEvent;\n\n\t\tthis.isImmediatePropagationStopped = returnTrue;\n\n\t\tif ( e && !this.isSimulated ) {\n\t\t\te.stopImmediatePropagation();\n\t\t}\n\n\t\tthis.stopPropagation();\n\t}\n};\n\n// Includes all common event props including KeyEvent and MouseEvent specific props\njQuery.each( {\n\taltKey: true,\n\tbubbles: true,\n\tcancelable: true,\n\tchangedTouches: true,\n\tctrlKey: true,\n\tdetail: true,\n\teventPhase: true,\n\tmetaKey: true,\n\tpageX: true,\n\tpageY: true,\n\tshiftKey: true,\n\tview: true,\n\t\"char\": true,\n\tcode: true,\n\tcharCode: true,\n\tkey: true,\n\tkeyCode: true,\n\tbutton: true,\n\tbuttons: true,\n\tclientX: true,\n\tclientY: true,\n\toffsetX: true,\n\toffsetY: true,\n\tpointerId: true,\n\tpointerType: true,\n\tscreenX: true,\n\tscreenY: true,\n\ttargetTouches: true,\n\ttoElement: true,\n\ttouches: true,\n\n\twhich: function( event ) {\n\t\tvar button = event.button;\n\n\t\t// Add which for key events\n\t\tif ( event.which == null && rkeyEvent.test( event.type ) ) {\n\t\t\treturn event.charCode != null ? event.charCode : event.keyCode;\n\t\t}\n\n\t\t// Add which for click: 1 === left; 2 === middle; 3 === right\n\t\tif ( !event.which && button !== undefined && rmouseEvent.test( event.type ) ) {\n\t\t\tif ( button & 1 ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\tif ( button & 2 ) {\n\t\t\t\treturn 3;\n\t\t\t}\n\n\t\t\tif ( button & 4 ) {\n\t\t\t\treturn 2;\n\t\t\t}\n\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn event.which;\n\t}\n}, jQuery.event.addProp );\n\njQuery.each( { focus: \"focusin\", blur: \"focusout\" }, function( type, delegateType ) {\n\tjQuery.event.special[ type ] = {\n\n\t\t// Utilize native event if possible so blur/focus sequence is correct\n\t\tsetup: function() {\n\n\t\t\t// Claim the first handler\n\t\t\t// dataPriv.set( this, \"focus\", ... )\n\t\t\t// dataPriv.set( this, \"blur\", ... )\n\t\t\tleverageNative( this, type, expectSync );\n\n\t\t\t// Return false to allow normal processing in the caller\n\t\t\treturn false;\n\t\t},\n\t\ttrigger: function() {\n\n\t\t\t// Force setup before trigger\n\t\t\tleverageNative( this, type );\n\n\t\t\t// Return non-false to allow normal event-path propagation\n\t\t\treturn true;\n\t\t},\n\n\t\tdelegateType: delegateType\n\t};\n} );\n\n// Create mouseenter/leave events using mouseover/out and event-time checks\n// so that event delegation works in jQuery.\n// Do the same for pointerenter/pointerleave and pointerover/pointerout\n//\n// Support: Safari 7 only\n// Safari sends mouseenter too often; see:\n// https://bugs.chromium.org/p/chromium/issues/detail?id=470258\n// for the description of the bug (it existed in older Chrome versions as well).\njQuery.each( {\n\tmouseenter: \"mouseover\",\n\tmouseleave: \"mouseout\",\n\tpointerenter: \"pointerover\",\n\tpointerleave: \"pointerout\"\n}, function( orig, fix ) {\n\tjQuery.event.special[ orig ] = {\n\t\tdelegateType: fix,\n\t\tbindType: fix,\n\n\t\thandle: function( event ) {\n\t\t\tvar ret,\n\t\t\t\ttarget = this,\n\t\t\t\trelated = event.relatedTarget,\n\t\t\t\thandleObj = event.handleObj;\n\n\t\t\t// For mouseenter/leave call the handler if related is outside the target.\n\t\t\t// NB: No relatedTarget if the mouse left/entered the browser window\n\t\t\tif ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) {\n\t\t\t\tevent.type = handleObj.origType;\n\t\t\t\tret = handleObj.handler.apply( this, arguments );\n\t\t\t\tevent.type = fix;\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t};\n} );\n\njQuery.fn.extend( {\n\n\ton: function( types, selector, data, fn ) {\n\t\treturn on( this, types, selector, data, fn );\n\t},\n\tone: function( types, selector, data, fn ) {\n\t\treturn on( this, types, selector, data, fn, 1 );\n\t},\n\toff: function( types, selector, fn ) {\n\t\tvar handleObj, type;\n\t\tif ( types && types.preventDefault && types.handleObj ) {\n\n\t\t\t// ( event )  dispatched jQuery.Event\n\t\t\thandleObj = types.handleObj;\n\t\t\tjQuery( types.delegateTarget ).off(\n\t\t\t\thandleObj.namespace ?\n\t\t\t\t\thandleObj.origType + \".\" + handleObj.namespace :\n\t\t\t\t\thandleObj.origType,\n\t\t\t\thandleObj.selector,\n\t\t\t\thandleObj.handler\n\t\t\t);\n\t\t\treturn this;\n\t\t}\n\t\tif ( typeof types === \"object\" ) {\n\n\t\t\t// ( types-object [, selector] )\n\t\t\tfor ( type in types ) {\n\t\t\t\tthis.off( type, selector, types[ type ] );\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\t\tif ( selector === false || typeof selector === \"function\" ) {\n\n\t\t\t// ( types [, fn] )\n\t\t\tfn = selector;\n\t\t\tselector = undefined;\n\t\t}\n\t\tif ( fn === false ) {\n\t\t\tfn = returnFalse;\n\t\t}\n\t\treturn this.each( function() {\n\t\t\tjQuery.event.remove( this, types, fn, selector );\n\t\t} );\n\t}\n} );\n\n\nvar\n\n\t/* eslint-disable max-len */\n\n\t// See https://github.com/eslint/eslint/issues/3229\n\trxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\\/\\0>\\x20\\t\\r\\n\\f]*)[^>]*)\\/>/gi,\n\n\t/* eslint-enable */\n\n\t// Support: IE <=10 - 11, Edge 12 - 13 only\n\t// In IE/Edge using regex groups here causes severe slowdowns.\n\t// See https://connect.microsoft.com/IE/feedback/details/1736512/\n\trnoInnerhtml = /<script|<style|<link/i,\n\n\t// checked=\"checked\" or checked\n\trchecked = /checked\\s*(?:[^=]|=\\s*.checked.)/i,\n\trcleanScript = /^\\s*<!(?:\\[CDATA\\[|--)|(?:\\]\\]|--)>\\s*$/g;\n\n// Prefer a tbody over its parent table for containing new rows\nfunction manipulationTarget( elem, content ) {\n\tif ( nodeName( elem, \"table\" ) &&\n\t\tnodeName( content.nodeType !== 11 ? content : content.firstChild, \"tr\" ) ) {\n\n\t\treturn jQuery( elem ).children( \"tbody\" )[ 0 ] || elem;\n\t}\n\n\treturn elem;\n}\n\n// Replace/restore the type attribute of script elements for safe DOM manipulation\nfunction disableScript( elem ) {\n\telem.type = ( elem.getAttribute( \"type\" ) !== null ) + \"/\" + elem.type;\n\treturn elem;\n}\nfunction restoreScript( elem ) {\n\tif ( ( elem.type || \"\" ).slice( 0, 5 ) === \"true/\" ) {\n\t\telem.type = elem.type.slice( 5 );\n\t} else {\n\t\telem.removeAttribute( \"type\" );\n\t}\n\n\treturn elem;\n}\n\nfunction cloneCopyEvent( src, dest ) {\n\tvar i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;\n\n\tif ( dest.nodeType !== 1 ) {\n\t\treturn;\n\t}\n\n\t// 1. Copy private data: events, handlers, etc.\n\tif ( dataPriv.hasData( src ) ) {\n\t\tpdataOld = dataPriv.access( src );\n\t\tpdataCur = dataPriv.set( dest, pdataOld );\n\t\tevents = pdataOld.events;\n\n\t\tif ( events ) {\n\t\t\tdelete pdataCur.handle;\n\t\t\tpdataCur.events = {};\n\n\t\t\tfor ( type in events ) {\n\t\t\t\tfor ( i = 0, l = events[ type ].length; i < l; i++ ) {\n\t\t\t\t\tjQuery.event.add( dest, type, events[ type ][ i ] );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// 2. Copy user data\n\tif ( dataUser.hasData( src ) ) {\n\t\tudataOld = dataUser.access( src );\n\t\tudataCur = jQuery.extend( {}, udataOld );\n\n\t\tdataUser.set( dest, udataCur );\n\t}\n}\n\n// Fix IE bugs, see support tests\nfunction fixInput( src, dest ) {\n\tvar nodeName = dest.nodeName.toLowerCase();\n\n\t// Fails to persist the checked state of a cloned checkbox or radio button.\n\tif ( nodeName === \"input\" && rcheckableType.test( src.type ) ) {\n\t\tdest.checked = src.checked;\n\n\t// Fails to return the selected option to the default selected state when cloning options\n\t} else if ( nodeName === \"input\" || nodeName === \"textarea\" ) {\n\t\tdest.defaultValue = src.defaultValue;\n\t}\n}\n\nfunction domManip( collection, args, callback, ignored ) {\n\n\t// Flatten any nested arrays\n\targs = concat.apply( [], args );\n\n\tvar fragment, first, scripts, hasScripts, node, doc,\n\t\ti = 0,\n\t\tl = collection.length,\n\t\tiNoClone = l - 1,\n\t\tvalue = args[ 0 ],\n\t\tvalueIsFunction = isFunction( value );\n\n\t// We can't cloneNode fragments that contain checked, in WebKit\n\tif ( valueIsFunction ||\n\t\t\t( l > 1 && typeof value === \"string\" &&\n\t\t\t\t!support.checkClone && rchecked.test( value ) ) ) {\n\t\treturn collection.each( function( index ) {\n\t\t\tvar self = collection.eq( index );\n\t\t\tif ( valueIsFunction ) {\n\t\t\t\targs[ 0 ] = value.call( this, index, self.html() );\n\t\t\t}\n\t\t\tdomManip( self, args, callback, ignored );\n\t\t} );\n\t}\n\n\tif ( l ) {\n\t\tfragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );\n\t\tfirst = fragment.firstChild;\n\n\t\tif ( fragment.childNodes.length === 1 ) {\n\t\t\tfragment = first;\n\t\t}\n\n\t\t// Require either new content or an interest in ignored elements to invoke the callback\n\t\tif ( first || ignored ) {\n\t\t\tscripts = jQuery.map( getAll( fragment, \"script\" ), disableScript );\n\t\t\thasScripts = scripts.length;\n\n\t\t\t// Use the original fragment for the last item\n\t\t\t// instead of the first because it can end up\n\t\t\t// being emptied incorrectly in certain situations (#8070).\n\t\t\tfor ( ; i < l; i++ ) {\n\t\t\t\tnode = fragment;\n\n\t\t\t\tif ( i !== iNoClone ) {\n\t\t\t\t\tnode = jQuery.clone( node, true, true );\n\n\t\t\t\t\t// Keep references to cloned scripts for later restoration\n\t\t\t\t\tif ( hasScripts ) {\n\n\t\t\t\t\t\t// Support: Android <=4.0 only, PhantomJS 1 only\n\t\t\t\t\t\t// push.apply(_, arraylike) throws on ancient WebKit\n\t\t\t\t\t\tjQuery.merge( scripts, getAll( node, \"script\" ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tcallback.call( collection[ i ], node, i );\n\t\t\t}\n\n\t\t\tif ( hasScripts ) {\n\t\t\t\tdoc = scripts[ scripts.length - 1 ].ownerDocument;\n\n\t\t\t\t// Reenable scripts\n\t\t\t\tjQuery.map( scripts, restoreScript );\n\n\t\t\t\t// Evaluate executable scripts on first document insertion\n\t\t\t\tfor ( i = 0; i < hasScripts; i++ ) {\n\t\t\t\t\tnode = scripts[ i ];\n\t\t\t\t\tif ( rscriptType.test( node.type || \"\" ) &&\n\t\t\t\t\t\t!dataPriv.access( node, \"globalEval\" ) &&\n\t\t\t\t\t\tjQuery.contains( doc, node ) ) {\n\n\t\t\t\t\t\tif ( node.src && ( node.type || \"\" ).toLowerCase()  !== \"module\" ) {\n\n\t\t\t\t\t\t\t// Optional AJAX dependency, but won't run scripts if not present\n\t\t\t\t\t\t\tif ( jQuery._evalUrl && !node.noModule ) {\n\t\t\t\t\t\t\t\tjQuery._evalUrl( node.src, {\n\t\t\t\t\t\t\t\t\tnonce: node.nonce || node.getAttribute( \"nonce\" )\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tDOMEval( node.textContent.replace( rcleanScript, \"\" ), node, doc );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn collection;\n}\n\nfunction remove( elem, selector, keepData ) {\n\tvar node,\n\t\tnodes = selector ? jQuery.filter( selector, elem ) : elem,\n\t\ti = 0;\n\n\tfor ( ; ( node = nodes[ i ] ) != null; i++ ) {\n\t\tif ( !keepData && node.nodeType === 1 ) {\n\t\t\tjQuery.cleanData( getAll( node ) );\n\t\t}\n\n\t\tif ( node.parentNode ) {\n\t\t\tif ( keepData && isAttached( node ) ) {\n\t\t\t\tsetGlobalEval( getAll( node, \"script\" ) );\n\t\t\t}\n\t\t\tnode.parentNode.removeChild( node );\n\t\t}\n\t}\n\n\treturn elem;\n}\n\njQuery.extend( {\n\thtmlPrefilter: function( html ) {\n\t\treturn html.replace( rxhtmlTag, \"<$1></$2>\" );\n\t},\n\n\tclone: function( elem, dataAndEvents, deepDataAndEvents ) {\n\t\tvar i, l, srcElements, destElements,\n\t\t\tclone = elem.cloneNode( true ),\n\t\t\tinPage = isAttached( elem );\n\n\t\t// Fix IE cloning issues\n\t\tif ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&\n\t\t\t\t!jQuery.isXMLDoc( elem ) ) {\n\n\t\t\t// We eschew Sizzle here for performance reasons: https://jsperf.com/getall-vs-sizzle/2\n\t\t\tdestElements = getAll( clone );\n\t\t\tsrcElements = getAll( elem );\n\n\t\t\tfor ( i = 0, l = srcElements.length; i < l; i++ ) {\n\t\t\t\tfixInput( srcElements[ i ], destElements[ i ] );\n\t\t\t}\n\t\t}\n\n\t\t// Copy the events from the original to the clone\n\t\tif ( dataAndEvents ) {\n\t\t\tif ( deepDataAndEvents ) {\n\t\t\t\tsrcElements = srcElements || getAll( elem );\n\t\t\t\tdestElements = destElements || getAll( clone );\n\n\t\t\t\tfor ( i = 0, l = srcElements.length; i < l; i++ ) {\n\t\t\t\t\tcloneCopyEvent( srcElements[ i ], destElements[ i ] );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcloneCopyEvent( elem, clone );\n\t\t\t}\n\t\t}\n\n\t\t// Preserve script evaluation history\n\t\tdestElements = getAll( clone, \"script\" );\n\t\tif ( destElements.length > 0 ) {\n\t\t\tsetGlobalEval( destElements, !inPage && getAll( elem, \"script\" ) );\n\t\t}\n\n\t\t// Return the cloned set\n\t\treturn clone;\n\t},\n\n\tcleanData: function( elems ) {\n\t\tvar data, elem, type,\n\t\t\tspecial = jQuery.event.special,\n\t\t\ti = 0;\n\n\t\tfor ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {\n\t\t\tif ( acceptData( elem ) ) {\n\t\t\t\tif ( ( data = elem[ dataPriv.expando ] ) ) {\n\t\t\t\t\tif ( data.events ) {\n\t\t\t\t\t\tfor ( type in data.events ) {\n\t\t\t\t\t\t\tif ( special[ type ] ) {\n\t\t\t\t\t\t\t\tjQuery.event.remove( elem, type );\n\n\t\t\t\t\t\t\t// This is a shortcut to avoid jQuery.event.remove's overhead\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tjQuery.removeEvent( elem, type, data.handle );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Support: Chrome <=35 - 45+\n\t\t\t\t\t// Assign undefined instead of using delete, see Data#remove\n\t\t\t\t\telem[ dataPriv.expando ] = undefined;\n\t\t\t\t}\n\t\t\t\tif ( elem[ dataUser.expando ] ) {\n\n\t\t\t\t\t// Support: Chrome <=35 - 45+\n\t\t\t\t\t// Assign undefined instead of using delete, see Data#remove\n\t\t\t\t\telem[ dataUser.expando ] = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n} );\n\njQuery.fn.extend( {\n\tdetach: function( selector ) {\n\t\treturn remove( this, selector, true );\n\t},\n\n\tremove: function( selector ) {\n\t\treturn remove( this, selector );\n\t},\n\n\ttext: function( value ) {\n\t\treturn access( this, function( value ) {\n\t\t\treturn value === undefined ?\n\t\t\t\tjQuery.text( this ) :\n\t\t\t\tthis.empty().each( function() {\n\t\t\t\t\tif ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {\n\t\t\t\t\t\tthis.textContent = value;\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t}, null, value, arguments.length );\n\t},\n\n\tappend: function() {\n\t\treturn domManip( this, arguments, function( elem ) {\n\t\t\tif ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {\n\t\t\t\tvar target = manipulationTarget( this, elem );\n\t\t\t\ttarget.appendChild( elem );\n\t\t\t}\n\t\t} );\n\t},\n\n\tprepend: function() {\n\t\treturn domManip( this, arguments, function( elem ) {\n\t\t\tif ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {\n\t\t\t\tvar target = manipulationTarget( this, elem );\n\t\t\t\ttarget.insertBefore( elem, target.firstChild );\n\t\t\t}\n\t\t} );\n\t},\n\n\tbefore: function() {\n\t\treturn domManip( this, arguments, function( elem ) {\n\t\t\tif ( this.parentNode ) {\n\t\t\t\tthis.parentNode.insertBefore( elem, this );\n\t\t\t}\n\t\t} );\n\t},\n\n\tafter: function() {\n\t\treturn domManip( this, arguments, function( elem ) {\n\t\t\tif ( this.parentNode ) {\n\t\t\t\tthis.parentNode.insertBefore( elem, this.nextSibling );\n\t\t\t}\n\t\t} );\n\t},\n\n\tempty: function() {\n\t\tvar elem,\n\t\t\ti = 0;\n\n\t\tfor ( ; ( elem = this[ i ] ) != null; i++ ) {\n\t\t\tif ( elem.nodeType === 1 ) {\n\n\t\t\t\t// Prevent memory leaks\n\t\t\t\tjQuery.cleanData( getAll( elem, false ) );\n\n\t\t\t\t// Remove any remaining nodes\n\t\t\t\telem.textContent = \"\";\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t},\n\n\tclone: function( dataAndEvents, deepDataAndEvents ) {\n\t\tdataAndEvents = dataAndEvents == null ? false : dataAndEvents;\n\t\tdeepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;\n\n\t\treturn this.map( function() {\n\t\t\treturn jQuery.clone( this, dataAndEvents, deepDataAndEvents );\n\t\t} );\n\t},\n\n\thtml: function( value ) {\n\t\treturn access( this, function( value ) {\n\t\t\tvar elem = this[ 0 ] || {},\n\t\t\t\ti = 0,\n\t\t\t\tl = this.length;\n\n\t\t\tif ( value === undefined && elem.nodeType === 1 ) {\n\t\t\t\treturn elem.innerHTML;\n\t\t\t}\n\n\t\t\t// See if we can take a shortcut and just use innerHTML\n\t\t\tif ( typeof value === \"string\" && !rnoInnerhtml.test( value ) &&\n\t\t\t\t!wrapMap[ ( rtagName.exec( value ) || [ \"\", \"\" ] )[ 1 ].toLowerCase() ] ) {\n\n\t\t\t\tvalue = jQuery.htmlPrefilter( value );\n\n\t\t\t\ttry {\n\t\t\t\t\tfor ( ; i < l; i++ ) {\n\t\t\t\t\t\telem = this[ i ] || {};\n\n\t\t\t\t\t\t// Remove element nodes and prevent memory leaks\n\t\t\t\t\t\tif ( elem.nodeType === 1 ) {\n\t\t\t\t\t\t\tjQuery.cleanData( getAll( elem, false ) );\n\t\t\t\t\t\t\telem.innerHTML = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\telem = 0;\n\n\t\t\t\t// If using innerHTML throws an exception, use the fallback method\n\t\t\t\t} catch ( e ) {}\n\t\t\t}\n\n\t\t\tif ( elem ) {\n\t\t\t\tthis.empty().append( value );\n\t\t\t}\n\t\t}, null, value, arguments.length );\n\t},\n\n\treplaceWith: function() {\n\t\tvar ignored = [];\n\n\t\t// Make the changes, replacing each non-ignored context element with the new content\n\t\treturn domManip( this, arguments, function( elem ) {\n\t\t\tvar parent = this.parentNode;\n\n\t\t\tif ( jQuery.inArray( this, ignored ) < 0 ) {\n\t\t\t\tjQuery.cleanData( getAll( this ) );\n\t\t\t\tif ( parent ) {\n\t\t\t\t\tparent.replaceChild( elem, this );\n\t\t\t\t}\n\t\t\t}\n\n\t\t// Force callback invocation\n\t\t}, ignored );\n\t}\n} );\n\njQuery.each( {\n\tappendTo: \"append\",\n\tprependTo: \"prepend\",\n\tinsertBefore: \"before\",\n\tinsertAfter: \"after\",\n\treplaceAll: \"replaceWith\"\n}, function( name, original ) {\n\tjQuery.fn[ name ] = function( selector ) {\n\t\tvar elems,\n\t\t\tret = [],\n\t\t\tinsert = jQuery( selector ),\n\t\t\tlast = insert.length - 1,\n\t\t\ti = 0;\n\n\t\tfor ( ; i <= last; i++ ) {\n\t\t\telems = i === last ? this : this.clone( true );\n\t\t\tjQuery( insert[ i ] )[ original ]( elems );\n\n\t\t\t// Support: Android <=4.0 only, PhantomJS 1 only\n\t\t\t// .get() because push.apply(_, arraylike) throws on ancient WebKit\n\t\t\tpush.apply( ret, elems.get() );\n\t\t}\n\n\t\treturn this.pushStack( ret );\n\t};\n} );\nvar rnumnonpx = new RegExp( \"^(\" + pnum + \")(?!px)[a-z%]+$\", \"i\" );\n\nvar getStyles = function( elem ) {\n\n\t\t// Support: IE <=11 only, Firefox <=30 (#15098, #14150)\n\t\t// IE throws on elements created in popups\n\t\t// FF meanwhile throws on frame elements through \"defaultView.getComputedStyle\"\n\t\tvar view = elem.ownerDocument.defaultView;\n\n\t\tif ( !view || !view.opener ) {\n\t\t\tview = window;\n\t\t}\n\n\t\treturn view.getComputedStyle( elem );\n\t};\n\nvar rboxStyle = new RegExp( cssExpand.join( \"|\" ), \"i\" );\n\n\n\n( function() {\n\n\t// Executing both pixelPosition & boxSizingReliable tests require only one layout\n\t// so they're executed at the same time to save the second computation.\n\tfunction computeStyleTests() {\n\n\t\t// This is a singleton, we need to execute it only once\n\t\tif ( !div ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcontainer.style.cssText = \"position:absolute;left:-11111px;width:60px;\" +\n\t\t\t\"margin-top:1px;padding:0;border:0\";\n\t\tdiv.style.cssText =\n\t\t\t\"position:relative;display:block;box-sizing:border-box;overflow:scroll;\" +\n\t\t\t\"margin:auto;border:1px;padding:1px;\" +\n\t\t\t\"width:60%;top:1%\";\n\t\tdocumentElement.appendChild( container ).appendChild( div );\n\n\t\tvar divStyle = window.getComputedStyle( div );\n\t\tpixelPositionVal = divStyle.top !== \"1%\";\n\n\t\t// Support: Android 4.0 - 4.3 only, Firefox <=3 - 44\n\t\treliableMarginLeftVal = roundPixelMeasures( divStyle.marginLeft ) === 12;\n\n\t\t// Support: Android 4.0 - 4.3 only, Safari <=9.1 - 10.1, iOS <=7.0 - 9.3\n\t\t// Some styles come back with percentage values, even though they shouldn't\n\t\tdiv.style.right = \"60%\";\n\t\tpixelBoxStylesVal = roundPixelMeasures( divStyle.right ) === 36;\n\n\t\t// Support: IE 9 - 11 only\n\t\t// Detect misreporting of content dimensions for box-sizing:border-box elements\n\t\tboxSizingReliableVal = roundPixelMeasures( divStyle.width ) === 36;\n\n\t\t// Support: IE 9 only\n\t\t// Detect overflow:scroll screwiness (gh-3699)\n\t\t// Support: Chrome <=64\n\t\t// Don't get tricked when zoom affects offsetWidth (gh-4029)\n\t\tdiv.style.position = \"absolute\";\n\t\tscrollboxSizeVal = roundPixelMeasures( div.offsetWidth / 3 ) === 12;\n\n\t\tdocumentElement.removeChild( container );\n\n\t\t// Nullify the div so it wouldn't be stored in the memory and\n\t\t// it will also be a sign that checks already performed\n\t\tdiv = null;\n\t}\n\n\tfunction roundPixelMeasures( measure ) {\n\t\treturn Math.round( parseFloat( measure ) );\n\t}\n\n\tvar pixelPositionVal, boxSizingReliableVal, scrollboxSizeVal, pixelBoxStylesVal,\n\t\treliableMarginLeftVal,\n\t\tcontainer = document.createElement( \"div\" ),\n\t\tdiv = document.createElement( \"div\" );\n\n\t// Finish early in limited (non-browser) environments\n\tif ( !div.style ) {\n\t\treturn;\n\t}\n\n\t// Support: IE <=9 - 11 only\n\t// Style of cloned element affects source element cloned (#8908)\n\tdiv.style.backgroundClip = \"content-box\";\n\tdiv.cloneNode( true ).style.backgroundClip = \"\";\n\tsupport.clearCloneStyle = div.style.backgroundClip === \"content-box\";\n\n\tjQuery.extend( support, {\n\t\tboxSizingReliable: function() {\n\t\t\tcomputeStyleTests();\n\t\t\treturn boxSizingReliableVal;\n\t\t},\n\t\tpixelBoxStyles: function() {\n\t\t\tcomputeStyleTests();\n\t\t\treturn pixelBoxStylesVal;\n\t\t},\n\t\tpixelPosition: function() {\n\t\t\tcomputeStyleTests();\n\t\t\treturn pixelPositionVal;\n\t\t},\n\t\treliableMarginLeft: function() {\n\t\t\tcomputeStyleTests();\n\t\t\treturn reliableMarginLeftVal;\n\t\t},\n\t\tscrollboxSize: function() {\n\t\t\tcomputeStyleTests();\n\t\t\treturn scrollboxSizeVal;\n\t\t}\n\t} );\n} )();\n\n\nfunction curCSS( elem, name, computed ) {\n\tvar width, minWidth, maxWidth, ret,\n\n\t\t// Support: Firefox 51+\n\t\t// Retrieving style before computed somehow\n\t\t// fixes an issue with getting wrong values\n\t\t// on detached elements\n\t\tstyle = elem.style;\n\n\tcomputed = computed || getStyles( elem );\n\n\t// getPropertyValue is needed for:\n\t//   .css('filter') (IE 9 only, #12537)\n\t//   .css('--customProperty) (#3144)\n\tif ( computed ) {\n\t\tret = computed.getPropertyValue( name ) || computed[ name ];\n\n\t\tif ( ret === \"\" && !isAttached( elem ) ) {\n\t\t\tret = jQuery.style( elem, name );\n\t\t}\n\n\t\t// A tribute to the \"awesome hack by Dean Edwards\"\n\t\t// Android Browser returns percentage for some values,\n\t\t// but width seems to be reliably pixels.\n\t\t// This is against the CSSOM draft spec:\n\t\t// https://drafts.csswg.org/cssom/#resolved-values\n\t\tif ( !support.pixelBoxStyles() && rnumnonpx.test( ret ) && rboxStyle.test( name ) ) {\n\n\t\t\t// Remember the original values\n\t\t\twidth = style.width;\n\t\t\tminWidth = style.minWidth;\n\t\t\tmaxWidth = style.maxWidth;\n\n\t\t\t// Put in the new values to get a computed value out\n\t\t\tstyle.minWidth = style.maxWidth = style.width = ret;\n\t\t\tret = computed.width;\n\n\t\t\t// Revert the changed values\n\t\t\tstyle.width = width;\n\t\t\tstyle.minWidth = minWidth;\n\t\t\tstyle.maxWidth = maxWidth;\n\t\t}\n\t}\n\n\treturn ret !== undefined ?\n\n\t\t// Support: IE <=9 - 11 only\n\t\t// IE returns zIndex value as an integer.\n\t\tret + \"\" :\n\t\tret;\n}\n\n\nfunction addGetHookIf( conditionFn, hookFn ) {\n\n\t// Define the hook, we'll check on the first run if it's really needed.\n\treturn {\n\t\tget: function() {\n\t\t\tif ( conditionFn() ) {\n\n\t\t\t\t// Hook not needed (or it's not possible to use it due\n\t\t\t\t// to missing dependency), remove it.\n\t\t\t\tdelete this.get;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Hook needed; redefine it so that the support test is not executed again.\n\t\t\treturn ( this.get = hookFn ).apply( this, arguments );\n\t\t}\n\t};\n}\n\n\nvar cssPrefixes = [ \"Webkit\", \"Moz\", \"ms\" ],\n\temptyStyle = document.createElement( \"div\" ).style,\n\tvendorProps = {};\n\n// Return a vendor-prefixed property or undefined\nfunction vendorPropName( name ) {\n\n\t// Check for vendor prefixed names\n\tvar capName = name[ 0 ].toUpperCase() + name.slice( 1 ),\n\t\ti = cssPrefixes.length;\n\n\twhile ( i-- ) {\n\t\tname = cssPrefixes[ i ] + capName;\n\t\tif ( name in emptyStyle ) {\n\t\t\treturn name;\n\t\t}\n\t}\n}\n\n// Return a potentially-mapped jQuery.cssProps or vendor prefixed property\nfunction finalPropName( name ) {\n\tvar final = jQuery.cssProps[ name ] || vendorProps[ name ];\n\n\tif ( final ) {\n\t\treturn final;\n\t}\n\tif ( name in emptyStyle ) {\n\t\treturn name;\n\t}\n\treturn vendorProps[ name ] = vendorPropName( name ) || name;\n}\n\n\nvar\n\n\t// Swappable if display is none or starts with table\n\t// except \"table\", \"table-cell\", or \"table-caption\"\n\t// See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display\n\trdisplayswap = /^(none|table(?!-c[ea]).+)/,\n\trcustomProp = /^--/,\n\tcssShow = { position: \"absolute\", visibility: \"hidden\", display: \"block\" },\n\tcssNormalTransform = {\n\t\tletterSpacing: \"0\",\n\t\tfontWeight: \"400\"\n\t};\n\nfunction setPositiveNumber( elem, value, subtract ) {\n\n\t// Any relative (+/-) values have already been\n\t// normalized at this point\n\tvar matches = rcssNum.exec( value );\n\treturn matches ?\n\n\t\t// Guard against undefined \"subtract\", e.g., when used as in cssHooks\n\t\tMath.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || \"px\" ) :\n\t\tvalue;\n}\n\nfunction boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computedVal ) {\n\tvar i = dimension === \"width\" ? 1 : 0,\n\t\textra = 0,\n\t\tdelta = 0;\n\n\t// Adjustment may not be necessary\n\tif ( box === ( isBorderBox ? \"border\" : \"content\" ) ) {\n\t\treturn 0;\n\t}\n\n\tfor ( ; i < 4; i += 2 ) {\n\n\t\t// Both box models exclude margin\n\t\tif ( box === \"margin\" ) {\n\t\t\tdelta += jQuery.css( elem, box + cssExpand[ i ], true, styles );\n\t\t}\n\n\t\t// If we get here with a content-box, we're seeking \"padding\" or \"border\" or \"margin\"\n\t\tif ( !isBorderBox ) {\n\n\t\t\t// Add padding\n\t\t\tdelta += jQuery.css( elem, \"padding\" + cssExpand[ i ], true, styles );\n\n\t\t\t// For \"border\" or \"margin\", add border\n\t\t\tif ( box !== \"padding\" ) {\n\t\t\t\tdelta += jQuery.css( elem, \"border\" + cssExpand[ i ] + \"Width\", true, styles );\n\n\t\t\t// But still keep track of it otherwise\n\t\t\t} else {\n\t\t\t\textra += jQuery.css( elem, \"border\" + cssExpand[ i ] + \"Width\", true, styles );\n\t\t\t}\n\n\t\t// If we get here with a border-box (content + padding + border), we're seeking \"content\" or\n\t\t// \"padding\" or \"margin\"\n\t\t} else {\n\n\t\t\t// For \"content\", subtract padding\n\t\t\tif ( box === \"content\" ) {\n\t\t\t\tdelta -= jQuery.css( elem, \"padding\" + cssExpand[ i ], true, styles );\n\t\t\t}\n\n\t\t\t// For \"content\" or \"padding\", subtract border\n\t\t\tif ( box !== \"margin\" ) {\n\t\t\t\tdelta -= jQuery.css( elem, \"border\" + cssExpand[ i ] + \"Width\", true, styles );\n\t\t\t}\n\t\t}\n\t}\n\n\t// Account for positive content-box scroll gutter when requested by providing computedVal\n\tif ( !isBorderBox && computedVal >= 0 ) {\n\n\t\t// offsetWidth/offsetHeight is a rounded sum of content, padding, scroll gutter, and border\n\t\t// Assuming integer scroll gutter, subtract the rest and round down\n\t\tdelta += Math.max( 0, Math.ceil(\n\t\t\telem[ \"offset\" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -\n\t\t\tcomputedVal -\n\t\t\tdelta -\n\t\t\textra -\n\t\t\t0.5\n\n\t\t// If offsetWidth/offsetHeight is unknown, then we can't determine content-box scroll gutter\n\t\t// Use an explicit zero to avoid NaN (gh-3964)\n\t\t) ) || 0;\n\t}\n\n\treturn delta;\n}\n\nfunction getWidthOrHeight( elem, dimension, extra ) {\n\n\t// Start with computed style\n\tvar styles = getStyles( elem ),\n\n\t\t// To avoid forcing a reflow, only fetch boxSizing if we need it (gh-4322).\n\t\t// Fake content-box until we know it's needed to know the true value.\n\t\tboxSizingNeeded = !support.boxSizingReliable() || extra,\n\t\tisBorderBox = boxSizingNeeded &&\n\t\t\tjQuery.css( elem, \"boxSizing\", false, styles ) === \"border-box\",\n\t\tvalueIsBorderBox = isBorderBox,\n\n\t\tval = curCSS( elem, dimension, styles ),\n\t\toffsetProp = \"offset\" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 );\n\n\t// Support: Firefox <=54\n\t// Return a confounding non-pixel value or feign ignorance, as appropriate.\n\tif ( rnumnonpx.test( val ) ) {\n\t\tif ( !extra ) {\n\t\t\treturn val;\n\t\t}\n\t\tval = \"auto\";\n\t}\n\n\n\t// Fall back to offsetWidth/offsetHeight when value is \"auto\"\n\t// This happens for inline elements with no explicit setting (gh-3571)\n\t// Support: Android <=4.1 - 4.3 only\n\t// Also use offsetWidth/offsetHeight for misreported inline dimensions (gh-3602)\n\t// Support: IE 9-11 only\n\t// Also use offsetWidth/offsetHeight for when box sizing is unreliable\n\t// We use getClientRects() to check for hidden/disconnected.\n\t// In those cases, the computed value can be trusted to be border-box\n\tif ( ( !support.boxSizingReliable() && isBorderBox ||\n\t\tval === \"auto\" ||\n\t\t!parseFloat( val ) && jQuery.css( elem, \"display\", false, styles ) === \"inline\" ) &&\n\t\telem.getClientRects().length ) {\n\n\t\tisBorderBox = jQuery.css( elem, \"boxSizing\", false, styles ) === \"border-box\";\n\n\t\t// Where available, offsetWidth/offsetHeight approximate border box dimensions.\n\t\t// Where not available (e.g., SVG), assume unreliable box-sizing and interpret the\n\t\t// retrieved value as a content box dimension.\n\t\tvalueIsBorderBox = offsetProp in elem;\n\t\tif ( valueIsBorderBox ) {\n\t\t\tval = elem[ offsetProp ];\n\t\t}\n\t}\n\n\t// Normalize \"\" and auto\n\tval = parseFloat( val ) || 0;\n\n\t// Adjust for the element's box model\n\treturn ( val +\n\t\tboxModelAdjustment(\n\t\t\telem,\n\t\t\tdimension,\n\t\t\textra || ( isBorderBox ? \"border\" : \"content\" ),\n\t\t\tvalueIsBorderBox,\n\t\t\tstyles,\n\n\t\t\t// Provide the current computed size to request scroll gutter calculation (gh-3589)\n\t\t\tval\n\t\t)\n\t) + \"px\";\n}\n\njQuery.extend( {\n\n\t// Add in style property hooks for overriding the default\n\t// behavior of getting and setting a style property\n\tcssHooks: {\n\t\topacity: {\n\t\t\tget: function( elem, computed ) {\n\t\t\t\tif ( computed ) {\n\n\t\t\t\t\t// We should always get a number back from opacity\n\t\t\t\t\tvar ret = curCSS( elem, \"opacity\" );\n\t\t\t\t\treturn ret === \"\" ? \"1\" : ret;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\n\t// Don't automatically add \"px\" to these possibly-unitless properties\n\tcssNumber: {\n\t\t\"animationIterationCount\": true,\n\t\t\"columnCount\": true,\n\t\t\"fillOpacity\": true,\n\t\t\"flexGrow\": true,\n\t\t\"flexShrink\": true,\n\t\t\"fontWeight\": true,\n\t\t\"gridArea\": true,\n\t\t\"gridColumn\": true,\n\t\t\"gridColumnEnd\": true,\n\t\t\"gridColumnStart\": true,\n\t\t\"gridRow\": true,\n\t\t\"gridRowEnd\": true,\n\t\t\"gridRowStart\": true,\n\t\t\"lineHeight\": true,\n\t\t\"opacity\": true,\n\t\t\"order\": true,\n\t\t\"orphans\": true,\n\t\t\"widows\": true,\n\t\t\"zIndex\": true,\n\t\t\"zoom\": true\n\t},\n\n\t// Add in properties whose names you wish to fix before\n\t// setting or getting the value\n\tcssProps: {},\n\n\t// Get and set the style property on a DOM Node\n\tstyle: function( elem, name, value, extra ) {\n\n\t\t// Don't set styles on text and comment nodes\n\t\tif ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Make sure that we're working with the right name\n\t\tvar ret, type, hooks,\n\t\t\torigName = camelCase( name ),\n\t\t\tisCustomProp = rcustomProp.test( name ),\n\t\t\tstyle = elem.style;\n\n\t\t// Make sure that we're working with the right name. We don't\n\t\t// want to query the value if it is a CSS custom property\n\t\t// since they are user-defined.\n\t\tif ( !isCustomProp ) {\n\t\t\tname = finalPropName( origName );\n\t\t}\n\n\t\t// Gets hook for the prefixed version, then unprefixed version\n\t\thooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];\n\n\t\t// Check if we're setting a value\n\t\tif ( value !== undefined ) {\n\t\t\ttype = typeof value;\n\n\t\t\t// Convert \"+=\" or \"-=\" to relative numbers (#7345)\n\t\t\tif ( type === \"string\" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {\n\t\t\t\tvalue = adjustCSS( elem, name, ret );\n\n\t\t\t\t// Fixes bug #9237\n\t\t\t\ttype = \"number\";\n\t\t\t}\n\n\t\t\t// Make sure that null and NaN values aren't set (#7116)\n\t\t\tif ( value == null || value !== value ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If a number was passed in, add the unit (except for certain CSS properties)\n\t\t\t// The isCustomProp check can be removed in jQuery 4.0 when we only auto-append\n\t\t\t// \"px\" to a few hardcoded values.\n\t\t\tif ( type === \"number\" && !isCustomProp ) {\n\t\t\t\tvalue += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? \"\" : \"px\" );\n\t\t\t}\n\n\t\t\t// background-* props affect original clone's values\n\t\t\tif ( !support.clearCloneStyle && value === \"\" && name.indexOf( \"background\" ) === 0 ) {\n\t\t\t\tstyle[ name ] = \"inherit\";\n\t\t\t}\n\n\t\t\t// If a hook was provided, use that value, otherwise just set the specified value\n\t\t\tif ( !hooks || !( \"set\" in hooks ) ||\n\t\t\t\t( value = hooks.set( elem, value, extra ) ) !== undefined ) {\n\n\t\t\t\tif ( isCustomProp ) {\n\t\t\t\t\tstyle.setProperty( name, value );\n\t\t\t\t} else {\n\t\t\t\t\tstyle[ name ] = value;\n\t\t\t\t}\n\t\t\t}\n\n\t\t} else {\n\n\t\t\t// If a hook was provided get the non-computed value from there\n\t\t\tif ( hooks && \"get\" in hooks &&\n\t\t\t\t( ret = hooks.get( elem, false, extra ) ) !== undefined ) {\n\n\t\t\t\treturn ret;\n\t\t\t}\n\n\t\t\t// Otherwise just get the value from the style object\n\t\t\treturn style[ name ];\n\t\t}\n\t},\n\n\tcss: function( elem, name, extra, styles ) {\n\t\tvar val, num, hooks,\n\t\t\torigName = camelCase( name ),\n\t\t\tisCustomProp = rcustomProp.test( name );\n\n\t\t// Make sure that we're working with the right name. We don't\n\t\t// want to modify the value if it is a CSS custom property\n\t\t// since they are user-defined.\n\t\tif ( !isCustomProp ) {\n\t\t\tname = finalPropName( origName );\n\t\t}\n\n\t\t// Try prefixed name followed by the unprefixed name\n\t\thooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];\n\n\t\t// If a hook was provided get the computed value from there\n\t\tif ( hooks && \"get\" in hooks ) {\n\t\t\tval = hooks.get( elem, true, extra );\n\t\t}\n\n\t\t// Otherwise, if a way to get the computed value exists, use that\n\t\tif ( val === undefined ) {\n\t\t\tval = curCSS( elem, name, styles );\n\t\t}\n\n\t\t// Convert \"normal\" to computed value\n\t\tif ( val === \"normal\" && name in cssNormalTransform ) {\n\t\t\tval = cssNormalTransform[ name ];\n\t\t}\n\n\t\t// Make numeric if forced or a qualifier was provided and val looks numeric\n\t\tif ( extra === \"\" || extra ) {\n\t\t\tnum = parseFloat( val );\n\t\t\treturn extra === true || isFinite( num ) ? num || 0 : val;\n\t\t}\n\n\t\treturn val;\n\t}\n} );\n\njQuery.each( [ \"height\", \"width\" ], function( i, dimension ) {\n\tjQuery.cssHooks[ dimension ] = {\n\t\tget: function( elem, computed, extra ) {\n\t\t\tif ( computed ) {\n\n\t\t\t\t// Certain elements can have dimension info if we invisibly show them\n\t\t\t\t// but it must have a current display style that would benefit\n\t\t\t\treturn rdisplayswap.test( jQuery.css( elem, \"display\" ) ) &&\n\n\t\t\t\t\t// Support: Safari 8+\n\t\t\t\t\t// Table columns in Safari have non-zero offsetWidth & zero\n\t\t\t\t\t// getBoundingClientRect().width unless display is changed.\n\t\t\t\t\t// Support: IE <=11 only\n\t\t\t\t\t// Running getBoundingClientRect on a disconnected node\n\t\t\t\t\t// in IE throws an error.\n\t\t\t\t\t( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?\n\t\t\t\t\t\tswap( elem, cssShow, function() {\n\t\t\t\t\t\t\treturn getWidthOrHeight( elem, dimension, extra );\n\t\t\t\t\t\t} ) :\n\t\t\t\t\t\tgetWidthOrHeight( elem, dimension, extra );\n\t\t\t}\n\t\t},\n\n\t\tset: function( elem, value, extra ) {\n\t\t\tvar matches,\n\t\t\t\tstyles = getStyles( elem ),\n\n\t\t\t\t// Only read styles.position if the test has a chance to fail\n\t\t\t\t// to avoid forcing a reflow.\n\t\t\t\tscrollboxSizeBuggy = !support.scrollboxSize() &&\n\t\t\t\t\tstyles.position === \"absolute\",\n\n\t\t\t\t// To avoid forcing a reflow, only fetch boxSizing if we need it (gh-3991)\n\t\t\t\tboxSizingNeeded = scrollboxSizeBuggy || extra,\n\t\t\t\tisBorderBox = boxSizingNeeded &&\n\t\t\t\t\tjQuery.css( elem, \"boxSizing\", false, styles ) === \"border-box\",\n\t\t\t\tsubtract = extra ?\n\t\t\t\t\tboxModelAdjustment(\n\t\t\t\t\t\telem,\n\t\t\t\t\t\tdimension,\n\t\t\t\t\t\textra,\n\t\t\t\t\t\tisBorderBox,\n\t\t\t\t\t\tstyles\n\t\t\t\t\t) :\n\t\t\t\t\t0;\n\n\t\t\t// Account for unreliable border-box dimensions by comparing offset* to computed and\n\t\t\t// faking a content-box to get border and padding (gh-3699)\n\t\t\tif ( isBorderBox && scrollboxSizeBuggy ) {\n\t\t\t\tsubtract -= Math.ceil(\n\t\t\t\t\telem[ \"offset\" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -\n\t\t\t\t\tparseFloat( styles[ dimension ] ) -\n\t\t\t\t\tboxModelAdjustment( elem, dimension, \"border\", false, styles ) -\n\t\t\t\t\t0.5\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Convert to pixels if value adjustment is needed\n\t\t\tif ( subtract && ( matches = rcssNum.exec( value ) ) &&\n\t\t\t\t( matches[ 3 ] || \"px\" ) !== \"px\" ) {\n\n\t\t\t\telem.style[ dimension ] = value;\n\t\t\t\tvalue = jQuery.css( elem, dimension );\n\t\t\t}\n\n\t\t\treturn setPositiveNumber( elem, value, subtract );\n\t\t}\n\t};\n} );\n\njQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,\n\tfunction( elem, computed ) {\n\t\tif ( computed ) {\n\t\t\treturn ( parseFloat( curCSS( elem, \"marginLeft\" ) ) ||\n\t\t\t\telem.getBoundingClientRect().left -\n\t\t\t\t\tswap( elem, { marginLeft: 0 }, function() {\n\t\t\t\t\t\treturn elem.getBoundingClientRect().left;\n\t\t\t\t\t} )\n\t\t\t\t) + \"px\";\n\t\t}\n\t}\n);\n\n// These hooks are used by animate to expand properties\njQuery.each( {\n\tmargin: \"\",\n\tpadding: \"\",\n\tborder: \"Width\"\n}, function( prefix, suffix ) {\n\tjQuery.cssHooks[ prefix + suffix ] = {\n\t\texpand: function( value ) {\n\t\t\tvar i = 0,\n\t\t\t\texpanded = {},\n\n\t\t\t\t// Assumes a single number if not a string\n\t\t\t\tparts = typeof value === \"string\" ? value.split( \" \" ) : [ value ];\n\n\t\t\tfor ( ; i < 4; i++ ) {\n\t\t\t\texpanded[ prefix + cssExpand[ i ] + suffix ] =\n\t\t\t\t\tparts[ i ] || parts[ i - 2 ] || parts[ 0 ];\n\t\t\t}\n\n\t\t\treturn expanded;\n\t\t}\n\t};\n\n\tif ( prefix !== \"margin\" ) {\n\t\tjQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;\n\t}\n} );\n\njQuery.fn.extend( {\n\tcss: function( name, value ) {\n\t\treturn access( this, function( elem, name, value ) {\n\t\t\tvar styles, len,\n\t\t\t\tmap = {},\n\t\t\t\ti = 0;\n\n\t\t\tif ( Array.isArray( name ) ) {\n\t\t\t\tstyles = getStyles( elem );\n\t\t\t\tlen = name.length;\n\n\t\t\t\tfor ( ; i < len; i++ ) {\n\t\t\t\t\tmap[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );\n\t\t\t\t}\n\n\t\t\t\treturn map;\n\t\t\t}\n\n\t\t\treturn value !== undefined ?\n\t\t\t\tjQuery.style( elem, name, value ) :\n\t\t\t\tjQuery.css( elem, name );\n\t\t}, name, value, arguments.length > 1 );\n\t}\n} );\n\n\nfunction Tween( elem, options, prop, end, easing ) {\n\treturn new Tween.prototype.init( elem, options, prop, end, easing );\n}\njQuery.Tween = Tween;\n\nTween.prototype = {\n\tconstructor: Tween,\n\tinit: function( elem, options, prop, end, easing, unit ) {\n\t\tthis.elem = elem;\n\t\tthis.prop = prop;\n\t\tthis.easing = easing || jQuery.easing._default;\n\t\tthis.options = options;\n\t\tthis.start = this.now = this.cur();\n\t\tthis.end = end;\n\t\tthis.unit = unit || ( jQuery.cssNumber[ prop ] ? \"\" : \"px\" );\n\t},\n\tcur: function() {\n\t\tvar hooks = Tween.propHooks[ this.prop ];\n\n\t\treturn hooks && hooks.get ?\n\t\t\thooks.get( this ) :\n\t\t\tTween.propHooks._default.get( this );\n\t},\n\trun: function( percent ) {\n\t\tvar eased,\n\t\t\thooks = Tween.propHooks[ this.prop ];\n\n\t\tif ( this.options.duration ) {\n\t\t\tthis.pos = eased = jQuery.easing[ this.easing ](\n\t\t\t\tpercent, this.options.duration * percent, 0, 1, this.options.duration\n\t\t\t);\n\t\t} else {\n\t\t\tthis.pos = eased = percent;\n\t\t}\n\t\tthis.now = ( this.end - this.start ) * eased + this.start;\n\n\t\tif ( this.options.step ) {\n\t\t\tthis.options.step.call( this.elem, this.now, this );\n\t\t}\n\n\t\tif ( hooks && hooks.set ) {\n\t\t\thooks.set( this );\n\t\t} else {\n\t\t\tTween.propHooks._default.set( this );\n\t\t}\n\t\treturn this;\n\t}\n};\n\nTween.prototype.init.prototype = Tween.prototype;\n\nTween.propHooks = {\n\t_default: {\n\t\tget: function( tween ) {\n\t\t\tvar result;\n\n\t\t\t// Use a property on the element directly when it is not a DOM element,\n\t\t\t// or when there is no matching style property that exists.\n\t\t\tif ( tween.elem.nodeType !== 1 ||\n\t\t\t\ttween.elem[ tween.prop ] != null && tween.elem.style[ tween.prop ] == null ) {\n\t\t\t\treturn tween.elem[ tween.prop ];\n\t\t\t}\n\n\t\t\t// Passing an empty string as a 3rd parameter to .css will automatically\n\t\t\t// attempt a parseFloat and fallback to a string if the parse fails.\n\t\t\t// Simple values such as \"10px\" are parsed to Float;\n\t\t\t// complex values such as \"rotate(1rad)\" are returned as-is.\n\t\t\tresult = jQuery.css( tween.elem, tween.prop, \"\" );\n\n\t\t\t// Empty strings, null, undefined and \"auto\" are converted to 0.\n\t\t\treturn !result || result === \"auto\" ? 0 : result;\n\t\t},\n\t\tset: function( tween ) {\n\n\t\t\t// Use step hook for back compat.\n\t\t\t// Use cssHook if its there.\n\t\t\t// Use .style if available and use plain properties where available.\n\t\t\tif ( jQuery.fx.step[ tween.prop ] ) {\n\t\t\t\tjQuery.fx.step[ tween.prop ]( tween );\n\t\t\t} else if ( tween.elem.nodeType === 1 && (\n\t\t\t\t\tjQuery.cssHooks[ tween.prop ] ||\n\t\t\t\t\ttween.elem.style[ finalPropName( tween.prop ) ] != null ) ) {\n\t\t\t\tjQuery.style( tween.elem, tween.prop, tween.now + tween.unit );\n\t\t\t} else {\n\t\t\t\ttween.elem[ tween.prop ] = tween.now;\n\t\t\t}\n\t\t}\n\t}\n};\n\n// Support: IE <=9 only\n// Panic based approach to setting things on disconnected nodes\nTween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {\n\tset: function( tween ) {\n\t\tif ( tween.elem.nodeType && tween.elem.parentNode ) {\n\t\t\ttween.elem[ tween.prop ] = tween.now;\n\t\t}\n\t}\n};\n\njQuery.easing = {\n\tlinear: function( p ) {\n\t\treturn p;\n\t},\n\tswing: function( p ) {\n\t\treturn 0.5 - Math.cos( p * Math.PI ) / 2;\n\t},\n\t_default: \"swing\"\n};\n\njQuery.fx = Tween.prototype.init;\n\n// Back compat <1.8 extension point\njQuery.fx.step = {};\n\n\n\n\nvar\n\tfxNow, inProgress,\n\trfxtypes = /^(?:toggle|show|hide)$/,\n\trrun = /queueHooks$/;\n\nfunction schedule() {\n\tif ( inProgress ) {\n\t\tif ( document.hidden === false && window.requestAnimationFrame ) {\n\t\t\twindow.requestAnimationFrame( schedule );\n\t\t} else {\n\t\t\twindow.setTimeout( schedule, jQuery.fx.interval );\n\t\t}\n\n\t\tjQuery.fx.tick();\n\t}\n}\n\n// Animations created synchronously will run synchronously\nfunction createFxNow() {\n\twindow.setTimeout( function() {\n\t\tfxNow = undefined;\n\t} );\n\treturn ( fxNow = Date.now() );\n}\n\n// Generate parameters to create a standard animation\nfunction genFx( type, includeWidth ) {\n\tvar which,\n\t\ti = 0,\n\t\tattrs = { height: type };\n\n\t// If we include width, step value is 1 to do all cssExpand values,\n\t// otherwise step value is 2 to skip over Left and Right\n\tincludeWidth = includeWidth ? 1 : 0;\n\tfor ( ; i < 4; i += 2 - includeWidth ) {\n\t\twhich = cssExpand[ i ];\n\t\tattrs[ \"margin\" + which ] = attrs[ \"padding\" + which ] = type;\n\t}\n\n\tif ( includeWidth ) {\n\t\tattrs.opacity = attrs.width = type;\n\t}\n\n\treturn attrs;\n}\n\nfunction createTween( value, prop, animation ) {\n\tvar tween,\n\t\tcollection = ( Animation.tweeners[ prop ] || [] ).concat( Animation.tweeners[ \"*\" ] ),\n\t\tindex = 0,\n\t\tlength = collection.length;\n\tfor ( ; index < length; index++ ) {\n\t\tif ( ( tween = collection[ index ].call( animation, prop, value ) ) ) {\n\n\t\t\t// We're done with this property\n\t\t\treturn tween;\n\t\t}\n\t}\n}\n\nfunction defaultPrefilter( elem, props, opts ) {\n\tvar prop, value, toggle, hooks, oldfire, propTween, restoreDisplay, display,\n\t\tisBox = \"width\" in props || \"height\" in props,\n\t\tanim = this,\n\t\torig = {},\n\t\tstyle = elem.style,\n\t\thidden = elem.nodeType && isHiddenWithinTree( elem ),\n\t\tdataShow = dataPriv.get( elem, \"fxshow\" );\n\n\t// Queue-skipping animations hijack the fx hooks\n\tif ( !opts.queue ) {\n\t\thooks = jQuery._queueHooks( elem, \"fx\" );\n\t\tif ( hooks.unqueued == null ) {\n\t\t\thooks.unqueued = 0;\n\t\t\toldfire = hooks.empty.fire;\n\t\t\thooks.empty.fire = function() {\n\t\t\t\tif ( !hooks.unqueued ) {\n\t\t\t\t\toldfire();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t\thooks.unqueued++;\n\n\t\tanim.always( function() {\n\n\t\t\t// Ensure the complete handler is called before this completes\n\t\t\tanim.always( function() {\n\t\t\t\thooks.unqueued--;\n\t\t\t\tif ( !jQuery.queue( elem, \"fx\" ).length ) {\n\t\t\t\t\thooks.empty.fire();\n\t\t\t\t}\n\t\t\t} );\n\t\t} );\n\t}\n\n\t// Detect show/hide animations\n\tfor ( prop in props ) {\n\t\tvalue = props[ prop ];\n\t\tif ( rfxtypes.test( value ) ) {\n\t\t\tdelete props[ prop ];\n\t\t\ttoggle = toggle || value === \"toggle\";\n\t\t\tif ( value === ( hidden ? \"hide\" : \"show\" ) ) {\n\n\t\t\t\t// Pretend to be hidden if this is a \"show\" and\n\t\t\t\t// there is still data from a stopped show/hide\n\t\t\t\tif ( value === \"show\" && dataShow && dataShow[ prop ] !== undefined ) {\n\t\t\t\t\thidden = true;\n\n\t\t\t\t// Ignore all other no-op show/hide data\n\t\t\t\t} else {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\torig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );\n\t\t}\n\t}\n\n\t// Bail out if this is a no-op like .hide().hide()\n\tpropTween = !jQuery.isEmptyObject( props );\n\tif ( !propTween && jQuery.isEmptyObject( orig ) ) {\n\t\treturn;\n\t}\n\n\t// Restrict \"overflow\" and \"display\" styles during box animations\n\tif ( isBox && elem.nodeType === 1 ) {\n\n\t\t// Support: IE <=9 - 11, Edge 12 - 15\n\t\t// Record all 3 overflow attributes because IE does not infer the shorthand\n\t\t// from identically-valued overflowX and overflowY and Edge just mirrors\n\t\t// the overflowX value there.\n\t\topts.overflow = [ style.overflow, style.overflowX, style.overflowY ];\n\n\t\t// Identify a display type, preferring old show/hide data over the CSS cascade\n\t\trestoreDisplay = dataShow && dataShow.display;\n\t\tif ( restoreDisplay == null ) {\n\t\t\trestoreDisplay = dataPriv.get( elem, \"display\" );\n\t\t}\n\t\tdisplay = jQuery.css( elem, \"display\" );\n\t\tif ( display === \"none\" ) {\n\t\t\tif ( restoreDisplay ) {\n\t\t\t\tdisplay = restoreDisplay;\n\t\t\t} else {\n\n\t\t\t\t// Get nonempty value(s) by temporarily forcing visibility\n\t\t\t\tshowHide( [ elem ], true );\n\t\t\t\trestoreDisplay = elem.style.display || restoreDisplay;\n\t\t\t\tdisplay = jQuery.css( elem, \"display\" );\n\t\t\t\tshowHide( [ elem ] );\n\t\t\t}\n\t\t}\n\n\t\t// Animate inline elements as inline-block\n\t\tif ( display === \"inline\" || display === \"inline-block\" && restoreDisplay != null ) {\n\t\t\tif ( jQuery.css( elem, \"float\" ) === \"none\" ) {\n\n\t\t\t\t// Restore the original display value at the end of pure show/hide animations\n\t\t\t\tif ( !propTween ) {\n\t\t\t\t\tanim.done( function() {\n\t\t\t\t\t\tstyle.display = restoreDisplay;\n\t\t\t\t\t} );\n\t\t\t\t\tif ( restoreDisplay == null ) {\n\t\t\t\t\t\tdisplay = style.display;\n\t\t\t\t\t\trestoreDisplay = display === \"none\" ? \"\" : display;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstyle.display = \"inline-block\";\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( opts.overflow ) {\n\t\tstyle.overflow = \"hidden\";\n\t\tanim.always( function() {\n\t\t\tstyle.overflow = opts.overflow[ 0 ];\n\t\t\tstyle.overflowX = opts.overflow[ 1 ];\n\t\t\tstyle.overflowY = opts.overflow[ 2 ];\n\t\t} );\n\t}\n\n\t// Implement show/hide animations\n\tpropTween = false;\n\tfor ( prop in orig ) {\n\n\t\t// General show/hide setup for this element animation\n\t\tif ( !propTween ) {\n\t\t\tif ( dataShow ) {\n\t\t\t\tif ( \"hidden\" in dataShow ) {\n\t\t\t\t\thidden = dataShow.hidden;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdataShow = dataPriv.access( elem, \"fxshow\", { display: restoreDisplay } );\n\t\t\t}\n\n\t\t\t// Store hidden/visible for toggle so `.stop().toggle()` \"reverses\"\n\t\t\tif ( toggle ) {\n\t\t\t\tdataShow.hidden = !hidden;\n\t\t\t}\n\n\t\t\t// Show elements before animating them\n\t\t\tif ( hidden ) {\n\t\t\t\tshowHide( [ elem ], true );\n\t\t\t}\n\n\t\t\t/* eslint-disable no-loop-func */\n\n\t\t\tanim.done( function() {\n\n\t\t\t/* eslint-enable no-loop-func */\n\n\t\t\t\t// The final step of a \"hide\" animation is actually hiding the element\n\t\t\t\tif ( !hidden ) {\n\t\t\t\t\tshowHide( [ elem ] );\n\t\t\t\t}\n\t\t\t\tdataPriv.remove( elem, \"fxshow\" );\n\t\t\t\tfor ( prop in orig ) {\n\t\t\t\t\tjQuery.style( elem, prop, orig[ prop ] );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t// Per-property setup\n\t\tpropTween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );\n\t\tif ( !( prop in dataShow ) ) {\n\t\t\tdataShow[ prop ] = propTween.start;\n\t\t\tif ( hidden ) {\n\t\t\t\tpropTween.end = propTween.start;\n\t\t\t\tpropTween.start = 0;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction propFilter( props, specialEasing ) {\n\tvar index, name, easing, value, hooks;\n\n\t// camelCase, specialEasing and expand cssHook pass\n\tfor ( index in props ) {\n\t\tname = camelCase( index );\n\t\teasing = specialEasing[ name ];\n\t\tvalue = props[ index ];\n\t\tif ( Array.isArray( value ) ) {\n\t\t\teasing = value[ 1 ];\n\t\t\tvalue = props[ index ] = value[ 0 ];\n\t\t}\n\n\t\tif ( index !== name ) {\n\t\t\tprops[ name ] = value;\n\t\t\tdelete props[ index ];\n\t\t}\n\n\t\thooks = jQuery.cssHooks[ name ];\n\t\tif ( hooks && \"expand\" in hooks ) {\n\t\t\tvalue = hooks.expand( value );\n\t\t\tdelete props[ name ];\n\n\t\t\t// Not quite $.extend, this won't overwrite existing keys.\n\t\t\t// Reusing 'index' because we have the correct \"name\"\n\t\t\tfor ( index in value ) {\n\t\t\t\tif ( !( index in props ) ) {\n\t\t\t\t\tprops[ index ] = value[ index ];\n\t\t\t\t\tspecialEasing[ index ] = easing;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tspecialEasing[ name ] = easing;\n\t\t}\n\t}\n}\n\nfunction Animation( elem, properties, options ) {\n\tvar result,\n\t\tstopped,\n\t\tindex = 0,\n\t\tlength = Animation.prefilters.length,\n\t\tdeferred = jQuery.Deferred().always( function() {\n\n\t\t\t// Don't match elem in the :animated selector\n\t\t\tdelete tick.elem;\n\t\t} ),\n\t\ttick = function() {\n\t\t\tif ( stopped ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tvar currentTime = fxNow || createFxNow(),\n\t\t\t\tremaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),\n\n\t\t\t\t// Support: Android 2.3 only\n\t\t\t\t// Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)\n\t\t\t\ttemp = remaining / animation.duration || 0,\n\t\t\t\tpercent = 1 - temp,\n\t\t\t\tindex = 0,\n\t\t\t\tlength = animation.tweens.length;\n\n\t\t\tfor ( ; index < length; index++ ) {\n\t\t\t\tanimation.tweens[ index ].run( percent );\n\t\t\t}\n\n\t\t\tdeferred.notifyWith( elem, [ animation, percent, remaining ] );\n\n\t\t\t// If there's more to do, yield\n\t\t\tif ( percent < 1 && length ) {\n\t\t\t\treturn remaining;\n\t\t\t}\n\n\t\t\t// If this was an empty animation, synthesize a final progress notification\n\t\t\tif ( !length ) {\n\t\t\t\tdeferred.notifyWith( elem, [ animation, 1, 0 ] );\n\t\t\t}\n\n\t\t\t// Resolve the animation and report its conclusion\n\t\t\tdeferred.resolveWith( elem, [ animation ] );\n\t\t\treturn false;\n\t\t},\n\t\tanimation = deferred.promise( {\n\t\t\telem: elem,\n\t\t\tprops: jQuery.extend( {}, properties ),\n\t\t\topts: jQuery.extend( true, {\n\t\t\t\tspecialEasing: {},\n\t\t\t\teasing: jQuery.easing._default\n\t\t\t}, options ),\n\t\t\toriginalProperties: properties,\n\t\t\toriginalOptions: options,\n\t\t\tstartTime: fxNow || createFxNow(),\n\t\t\tduration: options.duration,\n\t\t\ttweens: [],\n\t\t\tcreateTween: function( prop, end ) {\n\t\t\t\tvar tween = jQuery.Tween( elem, animation.opts, prop, end,\n\t\t\t\t\t\tanimation.opts.specialEasing[ prop ] || animation.opts.easing );\n\t\t\t\tanimation.tweens.push( tween );\n\t\t\t\treturn tween;\n\t\t\t},\n\t\t\tstop: function( gotoEnd ) {\n\t\t\t\tvar index = 0,\n\n\t\t\t\t\t// If we are going to the end, we want to run all the tweens\n\t\t\t\t\t// otherwise we skip this part\n\t\t\t\t\tlength = gotoEnd ? animation.tweens.length : 0;\n\t\t\t\tif ( stopped ) {\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tstopped = true;\n\t\t\t\tfor ( ; index < length; index++ ) {\n\t\t\t\t\tanimation.tweens[ index ].run( 1 );\n\t\t\t\t}\n\n\t\t\t\t// Resolve when we played the last frame; otherwise, reject\n\t\t\t\tif ( gotoEnd ) {\n\t\t\t\t\tdeferred.notifyWith( elem, [ animation, 1, 0 ] );\n\t\t\t\t\tdeferred.resolveWith( elem, [ animation, gotoEnd ] );\n\t\t\t\t} else {\n\t\t\t\t\tdeferred.rejectWith( elem, [ animation, gotoEnd ] );\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\t\t} ),\n\t\tprops = animation.props;\n\n\tpropFilter( props, animation.opts.specialEasing );\n\n\tfor ( ; index < length; index++ ) {\n\t\tresult = Animation.prefilters[ index ].call( animation, elem, props, animation.opts );\n\t\tif ( result ) {\n\t\t\tif ( isFunction( result.stop ) ) {\n\t\t\t\tjQuery._queueHooks( animation.elem, animation.opts.queue ).stop =\n\t\t\t\t\tresult.stop.bind( result );\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tjQuery.map( props, createTween, animation );\n\n\tif ( isFunction( animation.opts.start ) ) {\n\t\tanimation.opts.start.call( elem, animation );\n\t}\n\n\t// Attach callbacks from options\n\tanimation\n\t\t.progress( animation.opts.progress )\n\t\t.done( animation.opts.done, animation.opts.complete )\n\t\t.fail( animation.opts.fail )\n\t\t.always( animation.opts.always );\n\n\tjQuery.fx.timer(\n\t\tjQuery.extend( tick, {\n\t\t\telem: elem,\n\t\t\tanim: animation,\n\t\t\tqueue: animation.opts.queue\n\t\t} )\n\t);\n\n\treturn animation;\n}\n\njQuery.Animation = jQuery.extend( Animation, {\n\n\ttweeners: {\n\t\t\"*\": [ function( prop, value ) {\n\t\t\tvar tween = this.createTween( prop, value );\n\t\t\tadjustCSS( tween.elem, prop, rcssNum.exec( value ), tween );\n\t\t\treturn tween;\n\t\t} ]\n\t},\n\n\ttweener: function( props, callback ) {\n\t\tif ( isFunction( props ) ) {\n\t\t\tcallback = props;\n\t\t\tprops = [ \"*\" ];\n\t\t} else {\n\t\t\tprops = props.match( rnothtmlwhite );\n\t\t}\n\n\t\tvar prop,\n\t\t\tindex = 0,\n\t\t\tlength = props.length;\n\n\t\tfor ( ; index < length; index++ ) {\n\t\t\tprop = props[ index ];\n\t\t\tAnimation.tweeners[ prop ] = Animation.tweeners[ prop ] || [];\n\t\t\tAnimation.tweeners[ prop ].unshift( callback );\n\t\t}\n\t},\n\n\tprefilters: [ defaultPrefilter ],\n\n\tprefilter: function( callback, prepend ) {\n\t\tif ( prepend ) {\n\t\t\tAnimation.prefilters.unshift( callback );\n\t\t} else {\n\t\t\tAnimation.prefilters.push( callback );\n\t\t}\n\t}\n} );\n\njQuery.speed = function( speed, easing, fn ) {\n\tvar opt = speed && typeof speed === \"object\" ? jQuery.extend( {}, speed ) : {\n\t\tcomplete: fn || !fn && easing ||\n\t\t\tisFunction( speed ) && speed,\n\t\tduration: speed,\n\t\teasing: fn && easing || easing && !isFunction( easing ) && easing\n\t};\n\n\t// Go to the end state if fx are off\n\tif ( jQuery.fx.off ) {\n\t\topt.duration = 0;\n\n\t} else {\n\t\tif ( typeof opt.duration !== \"number\" ) {\n\t\t\tif ( opt.duration in jQuery.fx.speeds ) {\n\t\t\t\topt.duration = jQuery.fx.speeds[ opt.duration ];\n\n\t\t\t} else {\n\t\t\t\topt.duration = jQuery.fx.speeds._default;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Normalize opt.queue - true/undefined/null -> \"fx\"\n\tif ( opt.queue == null || opt.queue === true ) {\n\t\topt.queue = \"fx\";\n\t}\n\n\t// Queueing\n\topt.old = opt.complete;\n\n\topt.complete = function() {\n\t\tif ( isFunction( opt.old ) ) {\n\t\t\topt.old.call( this );\n\t\t}\n\n\t\tif ( opt.queue ) {\n\t\t\tjQuery.dequeue( this, opt.queue );\n\t\t}\n\t};\n\n\treturn opt;\n};\n\njQuery.fn.extend( {\n\tfadeTo: function( speed, to, easing, callback ) {\n\n\t\t// Show any hidden elements after setting opacity to 0\n\t\treturn this.filter( isHiddenWithinTree ).css( \"opacity\", 0 ).show()\n\n\t\t\t// Animate to the value specified\n\t\t\t.end().animate( { opacity: to }, speed, easing, callback );\n\t},\n\tanimate: function( prop, speed, easing, callback ) {\n\t\tvar empty = jQuery.isEmptyObject( prop ),\n\t\t\toptall = jQuery.speed( speed, easing, callback ),\n\t\t\tdoAnimation = function() {\n\n\t\t\t\t// Operate on a copy of prop so per-property easing won't be lost\n\t\t\t\tvar anim = Animation( this, jQuery.extend( {}, prop ), optall );\n\n\t\t\t\t// Empty animations, or finishing resolves immediately\n\t\t\t\tif ( empty || dataPriv.get( this, \"finish\" ) ) {\n\t\t\t\t\tanim.stop( true );\n\t\t\t\t}\n\t\t\t};\n\t\t\tdoAnimation.finish = doAnimation;\n\n\t\treturn empty || optall.queue === false ?\n\t\t\tthis.each( doAnimation ) :\n\t\t\tthis.queue( optall.queue, doAnimation );\n\t},\n\tstop: function( type, clearQueue, gotoEnd ) {\n\t\tvar stopQueue = function( hooks ) {\n\t\t\tvar stop = hooks.stop;\n\t\t\tdelete hooks.stop;\n\t\t\tstop( gotoEnd );\n\t\t};\n\n\t\tif ( typeof type !== \"string\" ) {\n\t\t\tgotoEnd = clearQueue;\n\t\t\tclearQueue = type;\n\t\t\ttype = undefined;\n\t\t}\n\t\tif ( clearQueue && type !== false ) {\n\t\t\tthis.queue( type || \"fx\", [] );\n\t\t}\n\n\t\treturn this.each( function() {\n\t\t\tvar dequeue = true,\n\t\t\t\tindex = type != null && type + \"queueHooks\",\n\t\t\t\ttimers = jQuery.timers,\n\t\t\t\tdata = dataPriv.get( this );\n\n\t\t\tif ( index ) {\n\t\t\t\tif ( data[ index ] && data[ index ].stop ) {\n\t\t\t\t\tstopQueue( data[ index ] );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor ( index in data ) {\n\t\t\t\t\tif ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {\n\t\t\t\t\t\tstopQueue( data[ index ] );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor ( index = timers.length; index--; ) {\n\t\t\t\tif ( timers[ index ].elem === this &&\n\t\t\t\t\t( type == null || timers[ index ].queue === type ) ) {\n\n\t\t\t\t\ttimers[ index ].anim.stop( gotoEnd );\n\t\t\t\t\tdequeue = false;\n\t\t\t\t\ttimers.splice( index, 1 );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Start the next in the queue if the last step wasn't forced.\n\t\t\t// Timers currently will call their complete callbacks, which\n\t\t\t// will dequeue but only if they were gotoEnd.\n\t\t\tif ( dequeue || !gotoEnd ) {\n\t\t\t\tjQuery.dequeue( this, type );\n\t\t\t}\n\t\t} );\n\t},\n\tfinish: function( type ) {\n\t\tif ( type !== false ) {\n\t\t\ttype = type || \"fx\";\n\t\t}\n\t\treturn this.each( function() {\n\t\t\tvar index,\n\t\t\t\tdata = dataPriv.get( this ),\n\t\t\t\tqueue = data[ type + \"queue\" ],\n\t\t\t\thooks = data[ type + \"queueHooks\" ],\n\t\t\t\ttimers = jQuery.timers,\n\t\t\t\tlength = queue ? queue.length : 0;\n\n\t\t\t// Enable finishing flag on private data\n\t\t\tdata.finish = true;\n\n\t\t\t// Empty the queue first\n\t\t\tjQuery.queue( this, type, [] );\n\n\t\t\tif ( hooks && hooks.stop ) {\n\t\t\t\thooks.stop.call( this, true );\n\t\t\t}\n\n\t\t\t// Look for any active animations, and finish them\n\t\t\tfor ( index = timers.length; index--; ) {\n\t\t\t\tif ( timers[ index ].elem === this && timers[ index ].queue === type ) {\n\t\t\t\t\ttimers[ index ].anim.stop( true );\n\t\t\t\t\ttimers.splice( index, 1 );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Look for any animations in the old queue and finish them\n\t\t\tfor ( index = 0; index < length; index++ ) {\n\t\t\t\tif ( queue[ index ] && queue[ index ].finish ) {\n\t\t\t\t\tqueue[ index ].finish.call( this );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Turn off finishing flag\n\t\t\tdelete data.finish;\n\t\t} );\n\t}\n} );\n\njQuery.each( [ \"toggle\", \"show\", \"hide\" ], function( i, name ) {\n\tvar cssFn = jQuery.fn[ name ];\n\tjQuery.fn[ name ] = function( speed, easing, callback ) {\n\t\treturn speed == null || typeof speed === \"boolean\" ?\n\t\t\tcssFn.apply( this, arguments ) :\n\t\t\tthis.animate( genFx( name, true ), speed, easing, callback );\n\t};\n} );\n\n// Generate shortcuts for custom animations\njQuery.each( {\n\tslideDown: genFx( \"show\" ),\n\tslideUp: genFx( \"hide\" ),\n\tslideToggle: genFx( \"toggle\" ),\n\tfadeIn: { opacity: \"show\" },\n\tfadeOut: { opacity: \"hide\" },\n\tfadeToggle: { opacity: \"toggle\" }\n}, function( name, props ) {\n\tjQuery.fn[ name ] = function( speed, easing, callback ) {\n\t\treturn this.animate( props, speed, easing, callback );\n\t};\n} );\n\njQuery.timers = [];\njQuery.fx.tick = function() {\n\tvar timer,\n\t\ti = 0,\n\t\ttimers = jQuery.timers;\n\n\tfxNow = Date.now();\n\n\tfor ( ; i < timers.length; i++ ) {\n\t\ttimer = timers[ i ];\n\n\t\t// Run the timer and safely remove it when done (allowing for external removal)\n\t\tif ( !timer() && timers[ i ] === timer ) {\n\t\t\ttimers.splice( i--, 1 );\n\t\t}\n\t}\n\n\tif ( !timers.length ) {\n\t\tjQuery.fx.stop();\n\t}\n\tfxNow = undefined;\n};\n\njQuery.fx.timer = function( timer ) {\n\tjQuery.timers.push( timer );\n\tjQuery.fx.start();\n};\n\njQuery.fx.interval = 13;\njQuery.fx.start = function() {\n\tif ( inProgress ) {\n\t\treturn;\n\t}\n\n\tinProgress = true;\n\tschedule();\n};\n\njQuery.fx.stop = function() {\n\tinProgress = null;\n};\n\njQuery.fx.speeds = {\n\tslow: 600,\n\tfast: 200,\n\n\t// Default speed\n\t_default: 400\n};\n\n\n// Based off of the plugin by Clint Helfers, with permission.\n// https://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/\njQuery.fn.delay = function( time, type ) {\n\ttime = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;\n\ttype = type || \"fx\";\n\n\treturn this.queue( type, function( next, hooks ) {\n\t\tvar timeout = window.setTimeout( next, time );\n\t\thooks.stop = function() {\n\t\t\twindow.clearTimeout( timeout );\n\t\t};\n\t} );\n};\n\n\n( function() {\n\tvar input = document.createElement( \"input\" ),\n\t\tselect = document.createElement( \"select\" ),\n\t\topt = select.appendChild( document.createElement( \"option\" ) );\n\n\tinput.type = \"checkbox\";\n\n\t// Support: Android <=4.3 only\n\t// Default value for a checkbox should be \"on\"\n\tsupport.checkOn = input.value !== \"\";\n\n\t// Support: IE <=11 only\n\t// Must access selectedIndex to make default options select\n\tsupport.optSelected = opt.selected;\n\n\t// Support: IE <=11 only\n\t// An input loses its value after becoming a radio\n\tinput = document.createElement( \"input\" );\n\tinput.value = \"t\";\n\tinput.type = \"radio\";\n\tsupport.radioValue = input.value === \"t\";\n} )();\n\n\nvar boolHook,\n\tattrHandle = jQuery.expr.attrHandle;\n\njQuery.fn.extend( {\n\tattr: function( name, value ) {\n\t\treturn access( this, jQuery.attr, name, value, arguments.length > 1 );\n\t},\n\n\tremoveAttr: function( name ) {\n\t\treturn this.each( function() {\n\t\t\tjQuery.removeAttr( this, name );\n\t\t} );\n\t}\n} );\n\njQuery.extend( {\n\tattr: function( elem, name, value ) {\n\t\tvar ret, hooks,\n\t\t\tnType = elem.nodeType;\n\n\t\t// Don't get/set attributes on text, comment and attribute nodes\n\t\tif ( nType === 3 || nType === 8 || nType === 2 ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Fallback to prop when attributes are not supported\n\t\tif ( typeof elem.getAttribute === \"undefined\" ) {\n\t\t\treturn jQuery.prop( elem, name, value );\n\t\t}\n\n\t\t// Attribute hooks are determined by the lowercase version\n\t\t// Grab necessary hook if one is defined\n\t\tif ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {\n\t\t\thooks = jQuery.attrHooks[ name.toLowerCase() ] ||\n\t\t\t\t( jQuery.expr.match.bool.test( name ) ? boolHook : undefined );\n\t\t}\n\n\t\tif ( value !== undefined ) {\n\t\t\tif ( value === null ) {\n\t\t\t\tjQuery.removeAttr( elem, name );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( hooks && \"set\" in hooks &&\n\t\t\t\t( ret = hooks.set( elem, value, name ) ) !== undefined ) {\n\t\t\t\treturn ret;\n\t\t\t}\n\n\t\t\telem.setAttribute( name, value + \"\" );\n\t\t\treturn value;\n\t\t}\n\n\t\tif ( hooks && \"get\" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {\n\t\t\treturn ret;\n\t\t}\n\n\t\tret = jQuery.find.attr( elem, name );\n\n\t\t// Non-existent attributes return null, we normalize to undefined\n\t\treturn ret == null ? undefined : ret;\n\t},\n\n\tattrHooks: {\n\t\ttype: {\n\t\t\tset: function( elem, value ) {\n\t\t\t\tif ( !support.radioValue && value === \"radio\" &&\n\t\t\t\t\tnodeName( elem, \"input\" ) ) {\n\t\t\t\t\tvar val = elem.value;\n\t\t\t\t\telem.setAttribute( \"type\", value );\n\t\t\t\t\tif ( val ) {\n\t\t\t\t\t\telem.value = val;\n\t\t\t\t\t}\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\n\tremoveAttr: function( elem, value ) {\n\t\tvar name,\n\t\t\ti = 0,\n\n\t\t\t// Attribute names can contain non-HTML whitespace characters\n\t\t\t// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2\n\t\t\tattrNames = value && value.match( rnothtmlwhite );\n\n\t\tif ( attrNames && elem.nodeType === 1 ) {\n\t\t\twhile ( ( name = attrNames[ i++ ] ) ) {\n\t\t\t\telem.removeAttribute( name );\n\t\t\t}\n\t\t}\n\t}\n} );\n\n// Hooks for boolean attributes\nboolHook = {\n\tset: function( elem, value, name ) {\n\t\tif ( value === false ) {\n\n\t\t\t// Remove boolean attributes when set to false\n\t\t\tjQuery.removeAttr( elem, name );\n\t\t} else {\n\t\t\telem.setAttribute( name, name );\n\t\t}\n\t\treturn name;\n\t}\n};\n\njQuery.each( jQuery.expr.match.bool.source.match( /\\w+/g ), function( i, name ) {\n\tvar getter = attrHandle[ name ] || jQuery.find.attr;\n\n\tattrHandle[ name ] = function( elem, name, isXML ) {\n\t\tvar ret, handle,\n\t\t\tlowercaseName = name.toLowerCase();\n\n\t\tif ( !isXML ) {\n\n\t\t\t// Avoid an infinite loop by temporarily removing this function from the getter\n\t\t\thandle = attrHandle[ lowercaseName ];\n\t\t\tattrHandle[ lowercaseName ] = ret;\n\t\t\tret = getter( elem, name, isXML ) != null ?\n\t\t\t\tlowercaseName :\n\t\t\t\tnull;\n\t\t\tattrHandle[ lowercaseName ] = handle;\n\t\t}\n\t\treturn ret;\n\t};\n} );\n\n\n\n\nvar rfocusable = /^(?:input|select|textarea|button)$/i,\n\trclickable = /^(?:a|area)$/i;\n\njQuery.fn.extend( {\n\tprop: function( name, value ) {\n\t\treturn access( this, jQuery.prop, name, value, arguments.length > 1 );\n\t},\n\n\tremoveProp: function( name ) {\n\t\treturn this.each( function() {\n\t\t\tdelete this[ jQuery.propFix[ name ] || name ];\n\t\t} );\n\t}\n} );\n\njQuery.extend( {\n\tprop: function( elem, name, value ) {\n\t\tvar ret, hooks,\n\t\t\tnType = elem.nodeType;\n\n\t\t// Don't get/set properties on text, comment and attribute nodes\n\t\tif ( nType === 3 || nType === 8 || nType === 2 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {\n\n\t\t\t// Fix name and attach hooks\n\t\t\tname = jQuery.propFix[ name ] || name;\n\t\t\thooks = jQuery.propHooks[ name ];\n\t\t}\n\n\t\tif ( value !== undefined ) {\n\t\t\tif ( hooks && \"set\" in hooks &&\n\t\t\t\t( ret = hooks.set( elem, value, name ) ) !== undefined ) {\n\t\t\t\treturn ret;\n\t\t\t}\n\n\t\t\treturn ( elem[ name ] = value );\n\t\t}\n\n\t\tif ( hooks && \"get\" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {\n\t\t\treturn ret;\n\t\t}\n\n\t\treturn elem[ name ];\n\t},\n\n\tpropHooks: {\n\t\ttabIndex: {\n\t\t\tget: function( elem ) {\n\n\t\t\t\t// Support: IE <=9 - 11 only\n\t\t\t\t// elem.tabIndex doesn't always return the\n\t\t\t\t// correct value when it hasn't been explicitly set\n\t\t\t\t// https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/\n\t\t\t\t// Use proper attribute retrieval(#12072)\n\t\t\t\tvar tabindex = jQuery.find.attr( elem, \"tabindex\" );\n\n\t\t\t\tif ( tabindex ) {\n\t\t\t\t\treturn parseInt( tabindex, 10 );\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\trfocusable.test( elem.nodeName ) ||\n\t\t\t\t\trclickable.test( elem.nodeName ) &&\n\t\t\t\t\telem.href\n\t\t\t\t) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t},\n\n\tpropFix: {\n\t\t\"for\": \"htmlFor\",\n\t\t\"class\": \"className\"\n\t}\n} );\n\n// Support: IE <=11 only\n// Accessing the selectedIndex property\n// forces the browser to respect setting selected\n// on the option\n// The getter ensures a default option is selected\n// when in an optgroup\n// eslint rule \"no-unused-expressions\" is disabled for this code\n// since it considers such accessions noop\nif ( !support.optSelected ) {\n\tjQuery.propHooks.selected = {\n\t\tget: function( elem ) {\n\n\t\t\t/* eslint no-unused-expressions: \"off\" */\n\n\t\t\tvar parent = elem.parentNode;\n\t\t\tif ( parent && parent.parentNode ) {\n\t\t\t\tparent.parentNode.selectedIndex;\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t\tset: function( elem ) {\n\n\t\t\t/* eslint no-unused-expressions: \"off\" */\n\n\t\t\tvar parent = elem.parentNode;\n\t\t\tif ( parent ) {\n\t\t\t\tparent.selectedIndex;\n\n\t\t\t\tif ( parent.parentNode ) {\n\t\t\t\t\tparent.parentNode.selectedIndex;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n}\n\njQuery.each( [\n\t\"tabIndex\",\n\t\"readOnly\",\n\t\"maxLength\",\n\t\"cellSpacing\",\n\t\"cellPadding\",\n\t\"rowSpan\",\n\t\"colSpan\",\n\t\"useMap\",\n\t\"frameBorder\",\n\t\"contentEditable\"\n], function() {\n\tjQuery.propFix[ this.toLowerCase() ] = this;\n} );\n\n\n\n\n\t// Strip and collapse whitespace according to HTML spec\n\t// https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace\n\tfunction stripAndCollapse( value ) {\n\t\tvar tokens = value.match( rnothtmlwhite ) || [];\n\t\treturn tokens.join( \" \" );\n\t}\n\n\nfunction getClass( elem ) {\n\treturn elem.getAttribute && elem.getAttribute( \"class\" ) || \"\";\n}\n\nfunction classesToArray( value ) {\n\tif ( Array.isArray( value ) ) {\n\t\treturn value;\n\t}\n\tif ( typeof value === \"string\" ) {\n\t\treturn value.match( rnothtmlwhite ) || [];\n\t}\n\treturn [];\n}\n\njQuery.fn.extend( {\n\taddClass: function( value ) {\n\t\tvar classes, elem, cur, curValue, clazz, j, finalValue,\n\t\t\ti = 0;\n\n\t\tif ( isFunction( value ) ) {\n\t\t\treturn this.each( function( j ) {\n\t\t\t\tjQuery( this ).addClass( value.call( this, j, getClass( this ) ) );\n\t\t\t} );\n\t\t}\n\n\t\tclasses = classesToArray( value );\n\n\t\tif ( classes.length ) {\n\t\t\twhile ( ( elem = this[ i++ ] ) ) {\n\t\t\t\tcurValue = getClass( elem );\n\t\t\t\tcur = elem.nodeType === 1 && ( \" \" + stripAndCollapse( curValue ) + \" \" );\n\n\t\t\t\tif ( cur ) {\n\t\t\t\t\tj = 0;\n\t\t\t\t\twhile ( ( clazz = classes[ j++ ] ) ) {\n\t\t\t\t\t\tif ( cur.indexOf( \" \" + clazz + \" \" ) < 0 ) {\n\t\t\t\t\t\t\tcur += clazz + \" \";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Only assign if different to avoid unneeded rendering.\n\t\t\t\t\tfinalValue = stripAndCollapse( cur );\n\t\t\t\t\tif ( curValue !== finalValue ) {\n\t\t\t\t\t\telem.setAttribute( \"class\", finalValue );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t},\n\n\tremoveClass: function( value ) {\n\t\tvar classes, elem, cur, curValue, clazz, j, finalValue,\n\t\t\ti = 0;\n\n\t\tif ( isFunction( value ) ) {\n\t\t\treturn this.each( function( j ) {\n\t\t\t\tjQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );\n\t\t\t} );\n\t\t}\n\n\t\tif ( !arguments.length ) {\n\t\t\treturn this.attr( \"class\", \"\" );\n\t\t}\n\n\t\tclasses = classesToArray( value );\n\n\t\tif ( classes.length ) {\n\t\t\twhile ( ( elem = this[ i++ ] ) ) {\n\t\t\t\tcurValue = getClass( elem );\n\n\t\t\t\t// This expression is here for better compressibility (see addClass)\n\t\t\t\tcur = elem.nodeType === 1 && ( \" \" + stripAndCollapse( curValue ) + \" \" );\n\n\t\t\t\tif ( cur ) {\n\t\t\t\t\tj = 0;\n\t\t\t\t\twhile ( ( clazz = classes[ j++ ] ) ) {\n\n\t\t\t\t\t\t// Remove *all* instances\n\t\t\t\t\t\twhile ( cur.indexOf( \" \" + clazz + \" \" ) > -1 ) {\n\t\t\t\t\t\t\tcur = cur.replace( \" \" + clazz + \" \", \" \" );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Only assign if different to avoid unneeded rendering.\n\t\t\t\t\tfinalValue = stripAndCollapse( cur );\n\t\t\t\t\tif ( curValue !== finalValue ) {\n\t\t\t\t\t\telem.setAttribute( \"class\", finalValue );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t},\n\n\ttoggleClass: function( value, stateVal ) {\n\t\tvar type = typeof value,\n\t\t\tisValidValue = type === \"string\" || Array.isArray( value );\n\n\t\tif ( typeof stateVal === \"boolean\" && isValidValue ) {\n\t\t\treturn stateVal ? this.addClass( value ) : this.removeClass( value );\n\t\t}\n\n\t\tif ( isFunction( value ) ) {\n\t\t\treturn this.each( function( i ) {\n\t\t\t\tjQuery( this ).toggleClass(\n\t\t\t\t\tvalue.call( this, i, getClass( this ), stateVal ),\n\t\t\t\t\tstateVal\n\t\t\t\t);\n\t\t\t} );\n\t\t}\n\n\t\treturn this.each( function() {\n\t\t\tvar className, i, self, classNames;\n\n\t\t\tif ( isValidValue ) {\n\n\t\t\t\t// Toggle individual class names\n\t\t\t\ti = 0;\n\t\t\t\tself = jQuery( this );\n\t\t\t\tclassNames = classesToArray( value );\n\n\t\t\t\twhile ( ( className = classNames[ i++ ] ) ) {\n\n\t\t\t\t\t// Check each className given, space separated list\n\t\t\t\t\tif ( self.hasClass( className ) ) {\n\t\t\t\t\t\tself.removeClass( className );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tself.addClass( className );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t// Toggle whole class name\n\t\t\t} else if ( value === undefined || type === \"boolean\" ) {\n\t\t\t\tclassName = getClass( this );\n\t\t\t\tif ( className ) {\n\n\t\t\t\t\t// Store className if set\n\t\t\t\t\tdataPriv.set( this, \"__className__\", className );\n\t\t\t\t}\n\n\t\t\t\t// If the element has a class name or if we're passed `false`,\n\t\t\t\t// then remove the whole classname (if there was one, the above saved it).\n\t\t\t\t// Otherwise bring back whatever was previously saved (if anything),\n\t\t\t\t// falling back to the empty string if nothing was stored.\n\t\t\t\tif ( this.setAttribute ) {\n\t\t\t\t\tthis.setAttribute( \"class\",\n\t\t\t\t\t\tclassName || value === false ?\n\t\t\t\t\t\t\"\" :\n\t\t\t\t\t\tdataPriv.get( this, \"__className__\" ) || \"\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t},\n\n\thasClass: function( selector ) {\n\t\tvar className, elem,\n\t\t\ti = 0;\n\n\t\tclassName = \" \" + selector + \" \";\n\t\twhile ( ( elem = this[ i++ ] ) ) {\n\t\t\tif ( elem.nodeType === 1 &&\n\t\t\t\t( \" \" + stripAndCollapse( getClass( elem ) ) + \" \" ).indexOf( className ) > -1 ) {\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n} );\n\n\n\n\nvar rreturn = /\\r/g;\n\njQuery.fn.extend( {\n\tval: function( value ) {\n\t\tvar hooks, ret, valueIsFunction,\n\t\t\telem = this[ 0 ];\n\n\t\tif ( !arguments.length ) {\n\t\t\tif ( elem ) {\n\t\t\t\thooks = jQuery.valHooks[ elem.type ] ||\n\t\t\t\t\tjQuery.valHooks[ elem.nodeName.toLowerCase() ];\n\n\t\t\t\tif ( hooks &&\n\t\t\t\t\t\"get\" in hooks &&\n\t\t\t\t\t( ret = hooks.get( elem, \"value\" ) ) !== undefined\n\t\t\t\t) {\n\t\t\t\t\treturn ret;\n\t\t\t\t}\n\n\t\t\t\tret = elem.value;\n\n\t\t\t\t// Handle most common string cases\n\t\t\t\tif ( typeof ret === \"string\" ) {\n\t\t\t\t\treturn ret.replace( rreturn, \"\" );\n\t\t\t\t}\n\n\t\t\t\t// Handle cases where value is null/undef or number\n\t\t\t\treturn ret == null ? \"\" : ret;\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tvalueIsFunction = isFunction( value );\n\n\t\treturn this.each( function( i ) {\n\t\t\tvar val;\n\n\t\t\tif ( this.nodeType !== 1 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( valueIsFunction ) {\n\t\t\t\tval = value.call( this, i, jQuery( this ).val() );\n\t\t\t} else {\n\t\t\t\tval = value;\n\t\t\t}\n\n\t\t\t// Treat null/undefined as \"\"; convert numbers to string\n\t\t\tif ( val == null ) {\n\t\t\t\tval = \"\";\n\n\t\t\t} else if ( typeof val === \"number\" ) {\n\t\t\t\tval += \"\";\n\n\t\t\t} else if ( Array.isArray( val ) ) {\n\t\t\t\tval = jQuery.map( val, function( value ) {\n\t\t\t\t\treturn value == null ? \"\" : value + \"\";\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\thooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];\n\n\t\t\t// If set returns undefined, fall back to normal setting\n\t\t\tif ( !hooks || !( \"set\" in hooks ) || hooks.set( this, val, \"value\" ) === undefined ) {\n\t\t\t\tthis.value = val;\n\t\t\t}\n\t\t} );\n\t}\n} );\n\njQuery.extend( {\n\tvalHooks: {\n\t\toption: {\n\t\t\tget: function( elem ) {\n\n\t\t\t\tvar val = jQuery.find.attr( elem, \"value\" );\n\t\t\t\treturn val != null ?\n\t\t\t\t\tval :\n\n\t\t\t\t\t// Support: IE <=10 - 11 only\n\t\t\t\t\t// option.text throws exceptions (#14686, #14858)\n\t\t\t\t\t// Strip and collapse whitespace\n\t\t\t\t\t// https://html.spec.whatwg.org/#strip-and-collapse-whitespace\n\t\t\t\t\tstripAndCollapse( jQuery.text( elem ) );\n\t\t\t}\n\t\t},\n\t\tselect: {\n\t\t\tget: function( elem ) {\n\t\t\t\tvar value, option, i,\n\t\t\t\t\toptions = elem.options,\n\t\t\t\t\tindex = elem.selectedIndex,\n\t\t\t\t\tone = elem.type === \"select-one\",\n\t\t\t\t\tvalues = one ? null : [],\n\t\t\t\t\tmax = one ? index + 1 : options.length;\n\n\t\t\t\tif ( index < 0 ) {\n\t\t\t\t\ti = max;\n\n\t\t\t\t} else {\n\t\t\t\t\ti = one ? index : 0;\n\t\t\t\t}\n\n\t\t\t\t// Loop through all the selected options\n\t\t\t\tfor ( ; i < max; i++ ) {\n\t\t\t\t\toption = options[ i ];\n\n\t\t\t\t\t// Support: IE <=9 only\n\t\t\t\t\t// IE8-9 doesn't update selected after form reset (#2551)\n\t\t\t\t\tif ( ( option.selected || i === index ) &&\n\n\t\t\t\t\t\t\t// Don't return options that are disabled or in a disabled optgroup\n\t\t\t\t\t\t\t!option.disabled &&\n\t\t\t\t\t\t\t( !option.parentNode.disabled ||\n\t\t\t\t\t\t\t\t!nodeName( option.parentNode, \"optgroup\" ) ) ) {\n\n\t\t\t\t\t\t// Get the specific value for the option\n\t\t\t\t\t\tvalue = jQuery( option ).val();\n\n\t\t\t\t\t\t// We don't need an array for one selects\n\t\t\t\t\t\tif ( one ) {\n\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Multi-Selects return an array\n\t\t\t\t\t\tvalues.push( value );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn values;\n\t\t\t},\n\n\t\t\tset: function( elem, value ) {\n\t\t\t\tvar optionSet, option,\n\t\t\t\t\toptions = elem.options,\n\t\t\t\t\tvalues = jQuery.makeArray( value ),\n\t\t\t\t\ti = options.length;\n\n\t\t\t\twhile ( i-- ) {\n\t\t\t\t\toption = options[ i ];\n\n\t\t\t\t\t/* eslint-disable no-cond-assign */\n\n\t\t\t\t\tif ( option.selected =\n\t\t\t\t\t\tjQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1\n\t\t\t\t\t) {\n\t\t\t\t\t\toptionSet = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t/* eslint-enable no-cond-assign */\n\t\t\t\t}\n\n\t\t\t\t// Force browsers to behave consistently when non-matching value is set\n\t\t\t\tif ( !optionSet ) {\n\t\t\t\t\telem.selectedIndex = -1;\n\t\t\t\t}\n\t\t\t\treturn values;\n\t\t\t}\n\t\t}\n\t}\n} );\n\n// Radios and checkboxes getter/setter\njQuery.each( [ \"radio\", \"checkbox\" ], function() {\n\tjQuery.valHooks[ this ] = {\n\t\tset: function( elem, value ) {\n\t\t\tif ( Array.isArray( value ) ) {\n\t\t\t\treturn ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );\n\t\t\t}\n\t\t}\n\t};\n\tif ( !support.checkOn ) {\n\t\tjQuery.valHooks[ this ].get = function( elem ) {\n\t\t\treturn elem.getAttribute( \"value\" ) === null ? \"on\" : elem.value;\n\t\t};\n\t}\n} );\n\n\n\n\n// Return jQuery for attributes-only inclusion\n\n\nsupport.focusin = \"onfocusin\" in window;\n\n\nvar rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,\n\tstopPropagationCallback = function( e ) {\n\t\te.stopPropagation();\n\t};\n\njQuery.extend( jQuery.event, {\n\n\ttrigger: function( event, data, elem, onlyHandlers ) {\n\n\t\tvar i, cur, tmp, bubbleType, ontype, handle, special, lastElement,\n\t\t\teventPath = [ elem || document ],\n\t\t\ttype = hasOwn.call( event, \"type\" ) ? event.type : event,\n\t\t\tnamespaces = hasOwn.call( event, \"namespace\" ) ? event.namespace.split( \".\" ) : [];\n\n\t\tcur = lastElement = tmp = elem = elem || document;\n\n\t\t// Don't do events on text and comment nodes\n\t\tif ( elem.nodeType === 3 || elem.nodeType === 8 ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// focus/blur morphs to focusin/out; ensure we're not firing them right now\n\t\tif ( rfocusMorph.test( type + jQuery.event.triggered ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( type.indexOf( \".\" ) > -1 ) {\n\n\t\t\t// Namespaced trigger; create a regexp to match event type in handle()\n\t\t\tnamespaces = type.split( \".\" );\n\t\t\ttype = namespaces.shift();\n\t\t\tnamespaces.sort();\n\t\t}\n\t\tontype = type.indexOf( \":\" ) < 0 && \"on\" + type;\n\n\t\t// Caller can pass in a jQuery.Event object, Object, or just an event type string\n\t\tevent = event[ jQuery.expando ] ?\n\t\t\tevent :\n\t\t\tnew jQuery.Event( type, typeof event === \"object\" && event );\n\n\t\t// Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)\n\t\tevent.isTrigger = onlyHandlers ? 2 : 3;\n\t\tevent.namespace = namespaces.join( \".\" );\n\t\tevent.rnamespace = event.namespace ?\n\t\t\tnew RegExp( \"(^|\\\\.)\" + namespaces.join( \"\\\\.(?:.*\\\\.|)\" ) + \"(\\\\.|$)\" ) :\n\t\t\tnull;\n\n\t\t// Clean up the event in case it is being reused\n\t\tevent.result = undefined;\n\t\tif ( !event.target ) {\n\t\t\tevent.target = elem;\n\t\t}\n\n\t\t// Clone any incoming data and prepend the event, creating the handler arg list\n\t\tdata = data == null ?\n\t\t\t[ event ] :\n\t\t\tjQuery.makeArray( data, [ event ] );\n\n\t\t// Allow special events to draw outside the lines\n\t\tspecial = jQuery.event.special[ type ] || {};\n\t\tif ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Determine event propagation path in advance, per W3C events spec (#9951)\n\t\t// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)\n\t\tif ( !onlyHandlers && !special.noBubble && !isWindow( elem ) ) {\n\n\t\t\tbubbleType = special.delegateType || type;\n\t\t\tif ( !rfocusMorph.test( bubbleType + type ) ) {\n\t\t\t\tcur = cur.parentNode;\n\t\t\t}\n\t\t\tfor ( ; cur; cur = cur.parentNode ) {\n\t\t\t\teventPath.push( cur );\n\t\t\t\ttmp = cur;\n\t\t\t}\n\n\t\t\t// Only add window if we got to document (e.g., not plain obj or detached DOM)\n\t\t\tif ( tmp === ( elem.ownerDocument || document ) ) {\n\t\t\t\teventPath.push( tmp.defaultView || tmp.parentWindow || window );\n\t\t\t}\n\t\t}\n\n\t\t// Fire handlers on the event path\n\t\ti = 0;\n\t\twhile ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) {\n\t\t\tlastElement = cur;\n\t\t\tevent.type = i > 1 ?\n\t\t\t\tbubbleType :\n\t\t\t\tspecial.bindType || type;\n\n\t\t\t// jQuery handler\n\t\t\thandle = ( dataPriv.get( cur, \"events\" ) || {} )[ event.type ] &&\n\t\t\t\tdataPriv.get( cur, \"handle\" );\n\t\t\tif ( handle ) {\n\t\t\t\thandle.apply( cur, data );\n\t\t\t}\n\n\t\t\t// Native handler\n\t\t\thandle = ontype && cur[ ontype ];\n\t\t\tif ( handle && handle.apply && acceptData( cur ) ) {\n\t\t\t\tevent.result = handle.apply( cur, data );\n\t\t\t\tif ( event.result === false ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tevent.type = type;\n\n\t\t// If nobody prevented the default action, do it now\n\t\tif ( !onlyHandlers && !event.isDefaultPrevented() ) {\n\n\t\t\tif ( ( !special._default ||\n\t\t\t\tspecial._default.apply( eventPath.pop(), data ) === false ) &&\n\t\t\t\tacceptData( elem ) ) {\n\n\t\t\t\t// Call a native DOM method on the target with the same name as the event.\n\t\t\t\t// Don't do default actions on window, that's where global variables be (#6170)\n\t\t\t\tif ( ontype && isFunction( elem[ type ] ) && !isWindow( elem ) ) {\n\n\t\t\t\t\t// Don't re-trigger an onFOO event when we call its FOO() method\n\t\t\t\t\ttmp = elem[ ontype ];\n\n\t\t\t\t\tif ( tmp ) {\n\t\t\t\t\t\telem[ ontype ] = null;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Prevent re-triggering of the same event, since we already bubbled it above\n\t\t\t\t\tjQuery.event.triggered = type;\n\n\t\t\t\t\tif ( event.isPropagationStopped() ) {\n\t\t\t\t\t\tlastElement.addEventListener( type, stopPropagationCallback );\n\t\t\t\t\t}\n\n\t\t\t\t\telem[ type ]();\n\n\t\t\t\t\tif ( event.isPropagationStopped() ) {\n\t\t\t\t\t\tlastElement.removeEventListener( type, stopPropagationCallback );\n\t\t\t\t\t}\n\n\t\t\t\t\tjQuery.event.triggered = undefined;\n\n\t\t\t\t\tif ( tmp ) {\n\t\t\t\t\t\telem[ ontype ] = tmp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn event.result;\n\t},\n\n\t// Piggyback on a donor event to simulate a different one\n\t// Used only for `focus(in | out)` events\n\tsimulate: function( type, elem, event ) {\n\t\tvar e = jQuery.extend(\n\t\t\tnew jQuery.Event(),\n\t\t\tevent,\n\t\t\t{\n\t\t\t\ttype: type,\n\t\t\t\tisSimulated: true\n\t\t\t}\n\t\t);\n\n\t\tjQuery.event.trigger( e, null, elem );\n\t}\n\n} );\n\njQuery.fn.extend( {\n\n\ttrigger: function( type, data ) {\n\t\treturn this.each( function() {\n\t\t\tjQuery.event.trigger( type, data, this );\n\t\t} );\n\t},\n\ttriggerHandler: function( type, data ) {\n\t\tvar elem = this[ 0 ];\n\t\tif ( elem ) {\n\t\t\treturn jQuery.event.trigger( type, data, elem, true );\n\t\t}\n\t}\n} );\n\n\n// Support: Firefox <=44\n// Firefox doesn't have focus(in | out) events\n// Related ticket - https://bugzilla.mozilla.org/show_bug.cgi?id=687787\n//\n// Support: Chrome <=48 - 49, Safari <=9.0 - 9.1\n// focus(in | out) events fire after focus & blur events,\n// which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order\n// Related ticket - https://bugs.chromium.org/p/chromium/issues/detail?id=449857\nif ( !support.focusin ) {\n\tjQuery.each( { focus: \"focusin\", blur: \"focusout\" }, function( orig, fix ) {\n\n\t\t// Attach a single capturing handler on the document while someone wants focusin/focusout\n\t\tvar handler = function( event ) {\n\t\t\tjQuery.event.simulate( fix, event.target, jQuery.event.fix( event ) );\n\t\t};\n\n\t\tjQuery.event.special[ fix ] = {\n\t\t\tsetup: function() {\n\t\t\t\tvar doc = this.ownerDocument || this,\n\t\t\t\t\tattaches = dataPriv.access( doc, fix );\n\n\t\t\t\tif ( !attaches ) {\n\t\t\t\t\tdoc.addEventListener( orig, handler, true );\n\t\t\t\t}\n\t\t\t\tdataPriv.access( doc, fix, ( attaches || 0 ) + 1 );\n\t\t\t},\n\t\t\tteardown: function() {\n\t\t\t\tvar doc = this.ownerDocument || this,\n\t\t\t\t\tattaches = dataPriv.access( doc, fix ) - 1;\n\n\t\t\t\tif ( !attaches ) {\n\t\t\t\t\tdoc.removeEventListener( orig, handler, true );\n\t\t\t\t\tdataPriv.remove( doc, fix );\n\n\t\t\t\t} else {\n\t\t\t\t\tdataPriv.access( doc, fix, attaches );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t} );\n}\nvar location = window.location;\n\nvar nonce = Date.now();\n\nvar rquery = ( /\\?/ );\n\n\n\n// Cross-browser xml parsing\njQuery.parseXML = function( data ) {\n\tvar xml;\n\tif ( !data || typeof data !== \"string\" ) {\n\t\treturn null;\n\t}\n\n\t// Support: IE 9 - 11 only\n\t// IE throws on parseFromString with invalid input.\n\ttry {\n\t\txml = ( new window.DOMParser() ).parseFromString( data, \"text/xml\" );\n\t} catch ( e ) {\n\t\txml = undefined;\n\t}\n\n\tif ( !xml || xml.getElementsByTagName( \"parsererror\" ).length ) {\n\t\tjQuery.error( \"Invalid XML: \" + data );\n\t}\n\treturn xml;\n};\n\n\nvar\n\trbracket = /\\[\\]$/,\n\trCRLF = /\\r?\\n/g,\n\trsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,\n\trsubmittable = /^(?:input|select|textarea|keygen)/i;\n\nfunction buildParams( prefix, obj, traditional, add ) {\n\tvar name;\n\n\tif ( Array.isArray( obj ) ) {\n\n\t\t// Serialize array item.\n\t\tjQuery.each( obj, function( i, v ) {\n\t\t\tif ( traditional || rbracket.test( prefix ) ) {\n\n\t\t\t\t// Treat each array item as a scalar.\n\t\t\t\tadd( prefix, v );\n\n\t\t\t} else {\n\n\t\t\t\t// Item is non-scalar (array or object), encode its numeric index.\n\t\t\t\tbuildParams(\n\t\t\t\t\tprefix + \"[\" + ( typeof v === \"object\" && v != null ? i : \"\" ) + \"]\",\n\t\t\t\t\tv,\n\t\t\t\t\ttraditional,\n\t\t\t\t\tadd\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\n\t} else if ( !traditional && toType( obj ) === \"object\" ) {\n\n\t\t// Serialize object item.\n\t\tfor ( name in obj ) {\n\t\t\tbuildParams( prefix + \"[\" + name + \"]\", obj[ name ], traditional, add );\n\t\t}\n\n\t} else {\n\n\t\t// Serialize scalar item.\n\t\tadd( prefix, obj );\n\t}\n}\n\n// Serialize an array of form elements or a set of\n// key/values into a query string\njQuery.param = function( a, traditional ) {\n\tvar prefix,\n\t\ts = [],\n\t\tadd = function( key, valueOrFunction ) {\n\n\t\t\t// If value is a function, invoke it and use its return value\n\t\t\tvar value = isFunction( valueOrFunction ) ?\n\t\t\t\tvalueOrFunction() :\n\t\t\t\tvalueOrFunction;\n\n\t\t\ts[ s.length ] = encodeURIComponent( key ) + \"=\" +\n\t\t\t\tencodeURIComponent( value == null ? \"\" : value );\n\t\t};\n\n\tif ( a == null ) {\n\t\treturn \"\";\n\t}\n\n\t// If an array was passed in, assume that it is an array of form elements.\n\tif ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {\n\n\t\t// Serialize the form elements\n\t\tjQuery.each( a, function() {\n\t\t\tadd( this.name, this.value );\n\t\t} );\n\n\t} else {\n\n\t\t// If traditional, encode the \"old\" way (the way 1.3.2 or older\n\t\t// did it), otherwise encode params recursively.\n\t\tfor ( prefix in a ) {\n\t\t\tbuildParams( prefix, a[ prefix ], traditional, add );\n\t\t}\n\t}\n\n\t// Return the resulting serialization\n\treturn s.join( \"&\" );\n};\n\njQuery.fn.extend( {\n\tserialize: function() {\n\t\treturn jQuery.param( this.serializeArray() );\n\t},\n\tserializeArray: function() {\n\t\treturn this.map( function() {\n\n\t\t\t// Can add propHook for \"elements\" to filter or add form elements\n\t\t\tvar elements = jQuery.prop( this, \"elements\" );\n\t\t\treturn elements ? jQuery.makeArray( elements ) : this;\n\t\t} )\n\t\t.filter( function() {\n\t\t\tvar type = this.type;\n\n\t\t\t// Use .is( \":disabled\" ) so that fieldset[disabled] works\n\t\t\treturn this.name && !jQuery( this ).is( \":disabled\" ) &&\n\t\t\t\trsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&\n\t\t\t\t( this.checked || !rcheckableType.test( type ) );\n\t\t} )\n\t\t.map( function( i, elem ) {\n\t\t\tvar val = jQuery( this ).val();\n\n\t\t\tif ( val == null ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif ( Array.isArray( val ) ) {\n\t\t\t\treturn jQuery.map( val, function( val ) {\n\t\t\t\t\treturn { name: elem.name, value: val.replace( rCRLF, \"\\r\\n\" ) };\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn { name: elem.name, value: val.replace( rCRLF, \"\\r\\n\" ) };\n\t\t} ).get();\n\t}\n} );\n\n\nvar\n\tr20 = /%20/g,\n\trhash = /#.*$/,\n\trantiCache = /([?&])_=[^&]*/,\n\trheaders = /^(.*?):[ \\t]*([^\\r\\n]*)$/mg,\n\n\t// #7653, #8125, #8152: local protocol detection\n\trlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,\n\trnoContent = /^(?:GET|HEAD)$/,\n\trprotocol = /^\\/\\//,\n\n\t/* Prefilters\n\t * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)\n\t * 2) These are called:\n\t *    - BEFORE asking for a transport\n\t *    - AFTER param serialization (s.data is a string if s.processData is true)\n\t * 3) key is the dataType\n\t * 4) the catchall symbol \"*\" can be used\n\t * 5) execution will start with transport dataType and THEN continue down to \"*\" if needed\n\t */\n\tprefilters = {},\n\n\t/* Transports bindings\n\t * 1) key is the dataType\n\t * 2) the catchall symbol \"*\" can be used\n\t * 3) selection will start with transport dataType and THEN go to \"*\" if needed\n\t */\n\ttransports = {},\n\n\t// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression\n\tallTypes = \"*/\".concat( \"*\" ),\n\n\t// Anchor tag for parsing the document origin\n\toriginAnchor = document.createElement( \"a\" );\n\toriginAnchor.href = location.href;\n\n// Base \"constructor\" for jQuery.ajaxPrefilter and jQuery.ajaxTransport\nfunction addToPrefiltersOrTransports( structure ) {\n\n\t// dataTypeExpression is optional and defaults to \"*\"\n\treturn function( dataTypeExpression, func ) {\n\n\t\tif ( typeof dataTypeExpression !== \"string\" ) {\n\t\t\tfunc = dataTypeExpression;\n\t\t\tdataTypeExpression = \"*\";\n\t\t}\n\n\t\tvar dataType,\n\t\t\ti = 0,\n\t\t\tdataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || [];\n\n\t\tif ( isFunction( func ) ) {\n\n\t\t\t// For each dataType in the dataTypeExpression\n\t\t\twhile ( ( dataType = dataTypes[ i++ ] ) ) {\n\n\t\t\t\t// Prepend if requested\n\t\t\t\tif ( dataType[ 0 ] === \"+\" ) {\n\t\t\t\t\tdataType = dataType.slice( 1 ) || \"*\";\n\t\t\t\t\t( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );\n\n\t\t\t\t// Otherwise append\n\t\t\t\t} else {\n\t\t\t\t\t( structure[ dataType ] = structure[ dataType ] || [] ).push( func );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n}\n\n// Base inspection function for prefilters and transports\nfunction inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {\n\n\tvar inspected = {},\n\t\tseekingTransport = ( structure === transports );\n\n\tfunction inspect( dataType ) {\n\t\tvar selected;\n\t\tinspected[ dataType ] = true;\n\t\tjQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {\n\t\t\tvar dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );\n\t\t\tif ( typeof dataTypeOrTransport === \"string\" &&\n\t\t\t\t!seekingTransport && !inspected[ dataTypeOrTransport ] ) {\n\n\t\t\t\toptions.dataTypes.unshift( dataTypeOrTransport );\n\t\t\t\tinspect( dataTypeOrTransport );\n\t\t\t\treturn false;\n\t\t\t} else if ( seekingTransport ) {\n\t\t\t\treturn !( selected = dataTypeOrTransport );\n\t\t\t}\n\t\t} );\n\t\treturn selected;\n\t}\n\n\treturn inspect( options.dataTypes[ 0 ] ) || !inspected[ \"*\" ] && inspect( \"*\" );\n}\n\n// A special extend for ajax options\n// that takes \"flat\" options (not to be deep extended)\n// Fixes #9887\nfunction ajaxExtend( target, src ) {\n\tvar key, deep,\n\t\tflatOptions = jQuery.ajaxSettings.flatOptions || {};\n\n\tfor ( key in src ) {\n\t\tif ( src[ key ] !== undefined ) {\n\t\t\t( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];\n\t\t}\n\t}\n\tif ( deep ) {\n\t\tjQuery.extend( true, target, deep );\n\t}\n\n\treturn target;\n}\n\n/* Handles responses to an ajax request:\n * - finds the right dataType (mediates between content-type and expected dataType)\n * - returns the corresponding response\n */\nfunction ajaxHandleResponses( s, jqXHR, responses ) {\n\n\tvar ct, type, finalDataType, firstDataType,\n\t\tcontents = s.contents,\n\t\tdataTypes = s.dataTypes;\n\n\t// Remove auto dataType and get content-type in the process\n\twhile ( dataTypes[ 0 ] === \"*\" ) {\n\t\tdataTypes.shift();\n\t\tif ( ct === undefined ) {\n\t\t\tct = s.mimeType || jqXHR.getResponseHeader( \"Content-Type\" );\n\t\t}\n\t}\n\n\t// Check if we're dealing with a known content-type\n\tif ( ct ) {\n\t\tfor ( type in contents ) {\n\t\t\tif ( contents[ type ] && contents[ type ].test( ct ) ) {\n\t\t\t\tdataTypes.unshift( type );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Check to see if we have a response for the expected dataType\n\tif ( dataTypes[ 0 ] in responses ) {\n\t\tfinalDataType = dataTypes[ 0 ];\n\t} else {\n\n\t\t// Try convertible dataTypes\n\t\tfor ( type in responses ) {\n\t\t\tif ( !dataTypes[ 0 ] || s.converters[ type + \" \" + dataTypes[ 0 ] ] ) {\n\t\t\t\tfinalDataType = type;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif ( !firstDataType ) {\n\t\t\t\tfirstDataType = type;\n\t\t\t}\n\t\t}\n\n\t\t// Or just use first one\n\t\tfinalDataType = finalDataType || firstDataType;\n\t}\n\n\t// If we found a dataType\n\t// We add the dataType to the list if needed\n\t// and return the corresponding response\n\tif ( finalDataType ) {\n\t\tif ( finalDataType !== dataTypes[ 0 ] ) {\n\t\t\tdataTypes.unshift( finalDataType );\n\t\t}\n\t\treturn responses[ finalDataType ];\n\t}\n}\n\n/* Chain conversions given the request and the original response\n * Also sets the responseXXX fields on the jqXHR instance\n */\nfunction ajaxConvert( s, response, jqXHR, isSuccess ) {\n\tvar conv2, current, conv, tmp, prev,\n\t\tconverters = {},\n\n\t\t// Work with a copy of dataTypes in case we need to modify it for conversion\n\t\tdataTypes = s.dataTypes.slice();\n\n\t// Create converters map with lowercased keys\n\tif ( dataTypes[ 1 ] ) {\n\t\tfor ( conv in s.converters ) {\n\t\t\tconverters[ conv.toLowerCase() ] = s.converters[ conv ];\n\t\t}\n\t}\n\n\tcurrent = dataTypes.shift();\n\n\t// Convert to each sequential dataType\n\twhile ( current ) {\n\n\t\tif ( s.responseFields[ current ] ) {\n\t\t\tjqXHR[ s.responseFields[ current ] ] = response;\n\t\t}\n\n\t\t// Apply the dataFilter if provided\n\t\tif ( !prev && isSuccess && s.dataFilter ) {\n\t\t\tresponse = s.dataFilter( response, s.dataType );\n\t\t}\n\n\t\tprev = current;\n\t\tcurrent = dataTypes.shift();\n\n\t\tif ( current ) {\n\n\t\t\t// There's only work to do if current dataType is non-auto\n\t\t\tif ( current === \"*\" ) {\n\n\t\t\t\tcurrent = prev;\n\n\t\t\t// Convert response if prev dataType is non-auto and differs from current\n\t\t\t} else if ( prev !== \"*\" && prev !== current ) {\n\n\t\t\t\t// Seek a direct converter\n\t\t\t\tconv = converters[ prev + \" \" + current ] || converters[ \"* \" + current ];\n\n\t\t\t\t// If none found, seek a pair\n\t\t\t\tif ( !conv ) {\n\t\t\t\t\tfor ( conv2 in converters ) {\n\n\t\t\t\t\t\t// If conv2 outputs current\n\t\t\t\t\t\ttmp = conv2.split( \" \" );\n\t\t\t\t\t\tif ( tmp[ 1 ] === current ) {\n\n\t\t\t\t\t\t\t// If prev can be converted to accepted input\n\t\t\t\t\t\t\tconv = converters[ prev + \" \" + tmp[ 0 ] ] ||\n\t\t\t\t\t\t\t\tconverters[ \"* \" + tmp[ 0 ] ];\n\t\t\t\t\t\t\tif ( conv ) {\n\n\t\t\t\t\t\t\t\t// Condense equivalence converters\n\t\t\t\t\t\t\t\tif ( conv === true ) {\n\t\t\t\t\t\t\t\t\tconv = converters[ conv2 ];\n\n\t\t\t\t\t\t\t\t// Otherwise, insert the intermediate dataType\n\t\t\t\t\t\t\t\t} else if ( converters[ conv2 ] !== true ) {\n\t\t\t\t\t\t\t\t\tcurrent = tmp[ 0 ];\n\t\t\t\t\t\t\t\t\tdataTypes.unshift( tmp[ 1 ] );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Apply converter (if not an equivalence)\n\t\t\t\tif ( conv !== true ) {\n\n\t\t\t\t\t// Unless errors are allowed to bubble, catch and return them\n\t\t\t\t\tif ( conv && s.throws ) {\n\t\t\t\t\t\tresponse = conv( response );\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tresponse = conv( response );\n\t\t\t\t\t\t} catch ( e ) {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tstate: \"parsererror\",\n\t\t\t\t\t\t\t\terror: conv ? e : \"No conversion from \" + prev + \" to \" + current\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { state: \"success\", data: response };\n}\n\njQuery.extend( {\n\n\t// Counter for holding the number of active queries\n\tactive: 0,\n\n\t// Last-Modified header cache for next request\n\tlastModified: {},\n\tetag: {},\n\n\tajaxSettings: {\n\t\turl: location.href,\n\t\ttype: \"GET\",\n\t\tisLocal: rlocalProtocol.test( location.protocol ),\n\t\tglobal: true,\n\t\tprocessData: true,\n\t\tasync: true,\n\t\tcontentType: \"application/x-www-form-urlencoded; charset=UTF-8\",\n\n\t\t/*\n\t\ttimeout: 0,\n\t\tdata: null,\n\t\tdataType: null,\n\t\tusername: null,\n\t\tpassword: null,\n\t\tcache: null,\n\t\tthrows: false,\n\t\ttraditional: false,\n\t\theaders: {},\n\t\t*/\n\n\t\taccepts: {\n\t\t\t\"*\": allTypes,\n\t\t\ttext: \"text/plain\",\n\t\t\thtml: \"text/html\",\n\t\t\txml: \"application/xml, text/xml\",\n\t\t\tjson: \"application/json, text/javascript\"\n\t\t},\n\n\t\tcontents: {\n\t\t\txml: /\\bxml\\b/,\n\t\t\thtml: /\\bhtml/,\n\t\t\tjson: /\\bjson\\b/\n\t\t},\n\n\t\tresponseFields: {\n\t\t\txml: \"responseXML\",\n\t\t\ttext: \"responseText\",\n\t\t\tjson: \"responseJSON\"\n\t\t},\n\n\t\t// Data converters\n\t\t// Keys separate source (or catchall \"*\") and destination types with a single space\n\t\tconverters: {\n\n\t\t\t// Convert anything to text\n\t\t\t\"* text\": String,\n\n\t\t\t// Text to html (true = no transformation)\n\t\t\t\"text html\": true,\n\n\t\t\t// Evaluate text as a json expression\n\t\t\t\"text json\": JSON.parse,\n\n\t\t\t// Parse text as xml\n\t\t\t\"text xml\": jQuery.parseXML\n\t\t},\n\n\t\t// For options that shouldn't be deep extended:\n\t\t// you can add your own custom options here if\n\t\t// and when you create one that shouldn't be\n\t\t// deep extended (see ajaxExtend)\n\t\tflatOptions: {\n\t\t\turl: true,\n\t\t\tcontext: true\n\t\t}\n\t},\n\n\t// Creates a full fledged settings object into target\n\t// with both ajaxSettings and settings fields.\n\t// If target is omitted, writes into ajaxSettings.\n\tajaxSetup: function( target, settings ) {\n\t\treturn settings ?\n\n\t\t\t// Building a settings object\n\t\t\tajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :\n\n\t\t\t// Extending ajaxSettings\n\t\t\tajaxExtend( jQuery.ajaxSettings, target );\n\t},\n\n\tajaxPrefilter: addToPrefiltersOrTransports( prefilters ),\n\tajaxTransport: addToPrefiltersOrTransports( transports ),\n\n\t// Main method\n\tajax: function( url, options ) {\n\n\t\t// If url is an object, simulate pre-1.5 signature\n\t\tif ( typeof url === \"object\" ) {\n\t\t\toptions = url;\n\t\t\turl = undefined;\n\t\t}\n\n\t\t// Force options to be an object\n\t\toptions = options || {};\n\n\t\tvar transport,\n\n\t\t\t// URL without anti-cache param\n\t\t\tcacheURL,\n\n\t\t\t// Response headers\n\t\t\tresponseHeadersString,\n\t\t\tresponseHeaders,\n\n\t\t\t// timeout handle\n\t\t\ttimeoutTimer,\n\n\t\t\t// Url cleanup var\n\t\t\turlAnchor,\n\n\t\t\t// Request state (becomes false upon send and true upon completion)\n\t\t\tcompleted,\n\n\t\t\t// To know if global events are to be dispatched\n\t\t\tfireGlobals,\n\n\t\t\t// Loop variable\n\t\t\ti,\n\n\t\t\t// uncached part of the url\n\t\t\tuncached,\n\n\t\t\t// Create the final options object\n\t\t\ts = jQuery.ajaxSetup( {}, options ),\n\n\t\t\t// Callbacks context\n\t\t\tcallbackContext = s.context || s,\n\n\t\t\t// Context for global events is callbackContext if it is a DOM node or jQuery collection\n\t\t\tglobalEventContext = s.context &&\n\t\t\t\t( callbackContext.nodeType || callbackContext.jquery ) ?\n\t\t\t\t\tjQuery( callbackContext ) :\n\t\t\t\t\tjQuery.event,\n\n\t\t\t// Deferreds\n\t\t\tdeferred = jQuery.Deferred(),\n\t\t\tcompleteDeferred = jQuery.Callbacks( \"once memory\" ),\n\n\t\t\t// Status-dependent callbacks\n\t\t\tstatusCode = s.statusCode || {},\n\n\t\t\t// Headers (they are sent all at once)\n\t\t\trequestHeaders = {},\n\t\t\trequestHeadersNames = {},\n\n\t\t\t// Default abort message\n\t\t\tstrAbort = \"canceled\",\n\n\t\t\t// Fake xhr\n\t\t\tjqXHR = {\n\t\t\t\treadyState: 0,\n\n\t\t\t\t// Builds headers hashtable if needed\n\t\t\t\tgetResponseHeader: function( key ) {\n\t\t\t\t\tvar match;\n\t\t\t\t\tif ( completed ) {\n\t\t\t\t\t\tif ( !responseHeaders ) {\n\t\t\t\t\t\t\tresponseHeaders = {};\n\t\t\t\t\t\t\twhile ( ( match = rheaders.exec( responseHeadersString ) ) ) {\n\t\t\t\t\t\t\t\tresponseHeaders[ match[ 1 ].toLowerCase() + \" \" ] =\n\t\t\t\t\t\t\t\t\t( responseHeaders[ match[ 1 ].toLowerCase() + \" \" ] || [] )\n\t\t\t\t\t\t\t\t\t\t.concat( match[ 2 ] );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmatch = responseHeaders[ key.toLowerCase() + \" \" ];\n\t\t\t\t\t}\n\t\t\t\t\treturn match == null ? null : match.join( \", \" );\n\t\t\t\t},\n\n\t\t\t\t// Raw string\n\t\t\t\tgetAllResponseHeaders: function() {\n\t\t\t\t\treturn completed ? responseHeadersString : null;\n\t\t\t\t},\n\n\t\t\t\t// Caches the header\n\t\t\t\tsetRequestHeader: function( name, value ) {\n\t\t\t\t\tif ( completed == null ) {\n\t\t\t\t\t\tname = requestHeadersNames[ name.toLowerCase() ] =\n\t\t\t\t\t\t\trequestHeadersNames[ name.toLowerCase() ] || name;\n\t\t\t\t\t\trequestHeaders[ name ] = value;\n\t\t\t\t\t}\n\t\t\t\t\treturn this;\n\t\t\t\t},\n\n\t\t\t\t// Overrides response content-type header\n\t\t\t\toverrideMimeType: function( type ) {\n\t\t\t\t\tif ( completed == null ) {\n\t\t\t\t\t\ts.mimeType = type;\n\t\t\t\t\t}\n\t\t\t\t\treturn this;\n\t\t\t\t},\n\n\t\t\t\t// Status-dependent callbacks\n\t\t\t\tstatusCode: function( map ) {\n\t\t\t\t\tvar code;\n\t\t\t\t\tif ( map ) {\n\t\t\t\t\t\tif ( completed ) {\n\n\t\t\t\t\t\t\t// Execute the appropriate callbacks\n\t\t\t\t\t\t\tjqXHR.always( map[ jqXHR.status ] );\n\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\t// Lazy-add the new callbacks in a way that preserves old ones\n\t\t\t\t\t\t\tfor ( code in map ) {\n\t\t\t\t\t\t\t\tstatusCode[ code ] = [ statusCode[ code ], map[ code ] ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn this;\n\t\t\t\t},\n\n\t\t\t\t// Cancel the request\n\t\t\t\tabort: function( statusText ) {\n\t\t\t\t\tvar finalText = statusText || strAbort;\n\t\t\t\t\tif ( transport ) {\n\t\t\t\t\t\ttransport.abort( finalText );\n\t\t\t\t\t}\n\t\t\t\t\tdone( 0, finalText );\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t};\n\n\t\t// Attach deferreds\n\t\tdeferred.promise( jqXHR );\n\n\t\t// Add protocol if not provided (prefilters might expect it)\n\t\t// Handle falsy url in the settings object (#10093: consistency with old signature)\n\t\t// We also use the url parameter if available\n\t\ts.url = ( ( url || s.url || location.href ) + \"\" )\n\t\t\t.replace( rprotocol, location.protocol + \"//\" );\n\n\t\t// Alias method option to type as per ticket #12004\n\t\ts.type = options.method || options.type || s.method || s.type;\n\n\t\t// Extract dataTypes list\n\t\ts.dataTypes = ( s.dataType || \"*\" ).toLowerCase().match( rnothtmlwhite ) || [ \"\" ];\n\n\t\t// A cross-domain request is in order when the origin doesn't match the current origin.\n\t\tif ( s.crossDomain == null ) {\n\t\t\turlAnchor = document.createElement( \"a\" );\n\n\t\t\t// Support: IE <=8 - 11, Edge 12 - 15\n\t\t\t// IE throws exception on accessing the href property if url is malformed,\n\t\t\t// e.g. http://example.com:80x/\n\t\t\ttry {\n\t\t\t\turlAnchor.href = s.url;\n\n\t\t\t\t// Support: IE <=8 - 11 only\n\t\t\t\t// Anchor's host property isn't correctly set when s.url is relative\n\t\t\t\turlAnchor.href = urlAnchor.href;\n\t\t\t\ts.crossDomain = originAnchor.protocol + \"//\" + originAnchor.host !==\n\t\t\t\t\turlAnchor.protocol + \"//\" + urlAnchor.host;\n\t\t\t} catch ( e ) {\n\n\t\t\t\t// If there is an error parsing the URL, assume it is crossDomain,\n\t\t\t\t// it can be rejected by the transport if it is invalid\n\t\t\t\ts.crossDomain = true;\n\t\t\t}\n\t\t}\n\n\t\t// Convert data if not already a string\n\t\tif ( s.data && s.processData && typeof s.data !== \"string\" ) {\n\t\t\ts.data = jQuery.param( s.data, s.traditional );\n\t\t}\n\n\t\t// Apply prefilters\n\t\tinspectPrefiltersOrTransports( prefilters, s, options, jqXHR );\n\n\t\t// If request was aborted inside a prefilter, stop there\n\t\tif ( completed ) {\n\t\t\treturn jqXHR;\n\t\t}\n\n\t\t// We can fire global events as of now if asked to\n\t\t// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)\n\t\tfireGlobals = jQuery.event && s.global;\n\n\t\t// Watch for a new set of requests\n\t\tif ( fireGlobals && jQuery.active++ === 0 ) {\n\t\t\tjQuery.event.trigger( \"ajaxStart\" );\n\t\t}\n\n\t\t// Uppercase the type\n\t\ts.type = s.type.toUpperCase();\n\n\t\t// Determine if request has content\n\t\ts.hasContent = !rnoContent.test( s.type );\n\n\t\t// Save the URL in case we're toying with the If-Modified-Since\n\t\t// and/or If-None-Match header later on\n\t\t// Remove hash to simplify url manipulation\n\t\tcacheURL = s.url.replace( rhash, \"\" );\n\n\t\t// More options handling for requests with no content\n\t\tif ( !s.hasContent ) {\n\n\t\t\t// Remember the hash so we can put it back\n\t\t\tuncached = s.url.slice( cacheURL.length );\n\n\t\t\t// If data is available and should be processed, append data to url\n\t\t\tif ( s.data && ( s.processData || typeof s.data === \"string\" ) ) {\n\t\t\t\tcacheURL += ( rquery.test( cacheURL ) ? \"&\" : \"?\" ) + s.data;\n\n\t\t\t\t// #9682: remove data so that it's not used in an eventual retry\n\t\t\t\tdelete s.data;\n\t\t\t}\n\n\t\t\t// Add or update anti-cache param if needed\n\t\t\tif ( s.cache === false ) {\n\t\t\t\tcacheURL = cacheURL.replace( rantiCache, \"$1\" );\n\t\t\t\tuncached = ( rquery.test( cacheURL ) ? \"&\" : \"?\" ) + \"_=\" + ( nonce++ ) + uncached;\n\t\t\t}\n\n\t\t\t// Put hash and anti-cache on the URL that will be requested (gh-1732)\n\t\t\ts.url = cacheURL + uncached;\n\n\t\t// Change '%20' to '+' if this is encoded form body content (gh-2658)\n\t\t} else if ( s.data && s.processData &&\n\t\t\t( s.contentType || \"\" ).indexOf( \"application/x-www-form-urlencoded\" ) === 0 ) {\n\t\t\ts.data = s.data.replace( r20, \"+\" );\n\t\t}\n\n\t\t// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.\n\t\tif ( s.ifModified ) {\n\t\t\tif ( jQuery.lastModified[ cacheURL ] ) {\n\t\t\t\tjqXHR.setRequestHeader( \"If-Modified-Since\", jQuery.lastModified[ cacheURL ] );\n\t\t\t}\n\t\t\tif ( jQuery.etag[ cacheURL ] ) {\n\t\t\t\tjqXHR.setRequestHeader( \"If-None-Match\", jQuery.etag[ cacheURL ] );\n\t\t\t}\n\t\t}\n\n\t\t// Set the correct header, if data is being sent\n\t\tif ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {\n\t\t\tjqXHR.setRequestHeader( \"Content-Type\", s.contentType );\n\t\t}\n\n\t\t// Set the Accepts header for the server, depending on the dataType\n\t\tjqXHR.setRequestHeader(\n\t\t\t\"Accept\",\n\t\t\ts.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?\n\t\t\t\ts.accepts[ s.dataTypes[ 0 ] ] +\n\t\t\t\t\t( s.dataTypes[ 0 ] !== \"*\" ? \", \" + allTypes + \"; q=0.01\" : \"\" ) :\n\t\t\t\ts.accepts[ \"*\" ]\n\t\t);\n\n\t\t// Check for headers option\n\t\tfor ( i in s.headers ) {\n\t\t\tjqXHR.setRequestHeader( i, s.headers[ i ] );\n\t\t}\n\n\t\t// Allow custom headers/mimetypes and early abort\n\t\tif ( s.beforeSend &&\n\t\t\t( s.beforeSend.call( callbackContext, jqXHR, s ) === false || completed ) ) {\n\n\t\t\t// Abort if not done already and return\n\t\t\treturn jqXHR.abort();\n\t\t}\n\n\t\t// Aborting is no longer a cancellation\n\t\tstrAbort = \"abort\";\n\n\t\t// Install callbacks on deferreds\n\t\tcompleteDeferred.add( s.complete );\n\t\tjqXHR.done( s.success );\n\t\tjqXHR.fail( s.error );\n\n\t\t// Get transport\n\t\ttransport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );\n\n\t\t// If no transport, we auto-abort\n\t\tif ( !transport ) {\n\t\t\tdone( -1, \"No Transport\" );\n\t\t} else {\n\t\t\tjqXHR.readyState = 1;\n\n\t\t\t// Send global event\n\t\t\tif ( fireGlobals ) {\n\t\t\t\tglobalEventContext.trigger( \"ajaxSend\", [ jqXHR, s ] );\n\t\t\t}\n\n\t\t\t// If request was aborted inside ajaxSend, stop there\n\t\t\tif ( completed ) {\n\t\t\t\treturn jqXHR;\n\t\t\t}\n\n\t\t\t// Timeout\n\t\t\tif ( s.async && s.timeout > 0 ) {\n\t\t\t\ttimeoutTimer = window.setTimeout( function() {\n\t\t\t\t\tjqXHR.abort( \"timeout\" );\n\t\t\t\t}, s.timeout );\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tcompleted = false;\n\t\t\t\ttransport.send( requestHeaders, done );\n\t\t\t} catch ( e ) {\n\n\t\t\t\t// Rethrow post-completion exceptions\n\t\t\t\tif ( completed ) {\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\n\t\t\t\t// Propagate others as results\n\t\t\t\tdone( -1, e );\n\t\t\t}\n\t\t}\n\n\t\t// Callback for when everything is done\n\t\tfunction done( status, nativeStatusText, responses, headers ) {\n\t\t\tvar isSuccess, success, error, response, modified,\n\t\t\t\tstatusText = nativeStatusText;\n\n\t\t\t// Ignore repeat invocations\n\t\t\tif ( completed ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tcompleted = true;\n\n\t\t\t// Clear timeout if it exists\n\t\t\tif ( timeoutTimer ) {\n\t\t\t\twindow.clearTimeout( timeoutTimer );\n\t\t\t}\n\n\t\t\t// Dereference transport for early garbage collection\n\t\t\t// (no matter how long the jqXHR object will be used)\n\t\t\ttransport = undefined;\n\n\t\t\t// Cache response headers\n\t\t\tresponseHeadersString = headers || \"\";\n\n\t\t\t// Set readyState\n\t\t\tjqXHR.readyState = status > 0 ? 4 : 0;\n\n\t\t\t// Determine if successful\n\t\t\tisSuccess = status >= 200 && status < 300 || status === 304;\n\n\t\t\t// Get response data\n\t\t\tif ( responses ) {\n\t\t\t\tresponse = ajaxHandleResponses( s, jqXHR, responses );\n\t\t\t}\n\n\t\t\t// Convert no matter what (that way responseXXX fields are always set)\n\t\t\tresponse = ajaxConvert( s, response, jqXHR, isSuccess );\n\n\t\t\t// If successful, handle type chaining\n\t\t\tif ( isSuccess ) {\n\n\t\t\t\t// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.\n\t\t\t\tif ( s.ifModified ) {\n\t\t\t\t\tmodified = jqXHR.getResponseHeader( \"Last-Modified\" );\n\t\t\t\t\tif ( modified ) {\n\t\t\t\t\t\tjQuery.lastModified[ cacheURL ] = modified;\n\t\t\t\t\t}\n\t\t\t\t\tmodified = jqXHR.getResponseHeader( \"etag\" );\n\t\t\t\t\tif ( modified ) {\n\t\t\t\t\t\tjQuery.etag[ cacheURL ] = modified;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// if no content\n\t\t\t\tif ( status === 204 || s.type === \"HEAD\" ) {\n\t\t\t\t\tstatusText = \"nocontent\";\n\n\t\t\t\t// if not modified\n\t\t\t\t} else if ( status === 304 ) {\n\t\t\t\t\tstatusText = \"notmodified\";\n\n\t\t\t\t// If we have data, let's convert it\n\t\t\t\t} else {\n\t\t\t\t\tstatusText = response.state;\n\t\t\t\t\tsuccess = response.data;\n\t\t\t\t\terror = response.error;\n\t\t\t\t\tisSuccess = !error;\n\t\t\t\t}\n\t\t\t} else {\n\n\t\t\t\t// Extract error from statusText and normalize for non-aborts\n\t\t\t\terror = statusText;\n\t\t\t\tif ( status || !statusText ) {\n\t\t\t\t\tstatusText = \"error\";\n\t\t\t\t\tif ( status < 0 ) {\n\t\t\t\t\t\tstatus = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Set data for the fake xhr object\n\t\t\tjqXHR.status = status;\n\t\t\tjqXHR.statusText = ( nativeStatusText || statusText ) + \"\";\n\n\t\t\t// Success/Error\n\t\t\tif ( isSuccess ) {\n\t\t\t\tdeferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );\n\t\t\t} else {\n\t\t\t\tdeferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );\n\t\t\t}\n\n\t\t\t// Status-dependent callbacks\n\t\t\tjqXHR.statusCode( statusCode );\n\t\t\tstatusCode = undefined;\n\n\t\t\tif ( fireGlobals ) {\n\t\t\t\tglobalEventContext.trigger( isSuccess ? \"ajaxSuccess\" : \"ajaxError\",\n\t\t\t\t\t[ jqXHR, s, isSuccess ? success : error ] );\n\t\t\t}\n\n\t\t\t// Complete\n\t\t\tcompleteDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );\n\n\t\t\tif ( fireGlobals ) {\n\t\t\t\tglobalEventContext.trigger( \"ajaxComplete\", [ jqXHR, s ] );\n\n\t\t\t\t// Handle the global AJAX counter\n\t\t\t\tif ( !( --jQuery.active ) ) {\n\t\t\t\t\tjQuery.event.trigger( \"ajaxStop\" );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jqXHR;\n\t},\n\n\tgetJSON: function( url, data, callback ) {\n\t\treturn jQuery.get( url, data, callback, \"json\" );\n\t},\n\n\tgetScript: function( url, callback ) {\n\t\treturn jQuery.get( url, undefined, callback, \"script\" );\n\t}\n} );\n\njQuery.each( [ \"get\", \"post\" ], function( i, method ) {\n\tjQuery[ method ] = function( url, data, callback, type ) {\n\n\t\t// Shift arguments if data argument was omitted\n\t\tif ( isFunction( data ) ) {\n\t\t\ttype = type || callback;\n\t\t\tcallback = data;\n\t\t\tdata = undefined;\n\t\t}\n\n\t\t// The url can be an options object (which then must have .url)\n\t\treturn jQuery.ajax( jQuery.extend( {\n\t\t\turl: url,\n\t\t\ttype: method,\n\t\t\tdataType: type,\n\t\t\tdata: data,\n\t\t\tsuccess: callback\n\t\t}, jQuery.isPlainObject( url ) && url ) );\n\t};\n} );\n\n\njQuery._evalUrl = function( url, options ) {\n\treturn jQuery.ajax( {\n\t\turl: url,\n\n\t\t// Make this explicit, since user can override this through ajaxSetup (#11264)\n\t\ttype: \"GET\",\n\t\tdataType: \"script\",\n\t\tcache: true,\n\t\tasync: false,\n\t\tglobal: false,\n\n\t\t// Only evaluate the response if it is successful (gh-4126)\n\t\t// dataFilter is not invoked for failure responses, so using it instead\n\t\t// of the default converter is kludgy but it works.\n\t\tconverters: {\n\t\t\t\"text script\": function() {}\n\t\t},\n\t\tdataFilter: function( response ) {\n\t\t\tjQuery.globalEval( response, options );\n\t\t}\n\t} );\n};\n\n\njQuery.fn.extend( {\n\twrapAll: function( html ) {\n\t\tvar wrap;\n\n\t\tif ( this[ 0 ] ) {\n\t\t\tif ( isFunction( html ) ) {\n\t\t\t\thtml = html.call( this[ 0 ] );\n\t\t\t}\n\n\t\t\t// The elements to wrap the target around\n\t\t\twrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );\n\n\t\t\tif ( this[ 0 ].parentNode ) {\n\t\t\t\twrap.insertBefore( this[ 0 ] );\n\t\t\t}\n\n\t\t\twrap.map( function() {\n\t\t\t\tvar elem = this;\n\n\t\t\t\twhile ( elem.firstElementChild ) {\n\t\t\t\t\telem = elem.firstElementChild;\n\t\t\t\t}\n\n\t\t\t\treturn elem;\n\t\t\t} ).append( this );\n\t\t}\n\n\t\treturn this;\n\t},\n\n\twrapInner: function( html ) {\n\t\tif ( isFunction( html ) ) {\n\t\t\treturn this.each( function( i ) {\n\t\t\t\tjQuery( this ).wrapInner( html.call( this, i ) );\n\t\t\t} );\n\t\t}\n\n\t\treturn this.each( function() {\n\t\t\tvar self = jQuery( this ),\n\t\t\t\tcontents = self.contents();\n\n\t\t\tif ( contents.length ) {\n\t\t\t\tcontents.wrapAll( html );\n\n\t\t\t} else {\n\t\t\t\tself.append( html );\n\t\t\t}\n\t\t} );\n\t},\n\n\twrap: function( html ) {\n\t\tvar htmlIsFunction = isFunction( html );\n\n\t\treturn this.each( function( i ) {\n\t\t\tjQuery( this ).wrapAll( htmlIsFunction ? html.call( this, i ) : html );\n\t\t} );\n\t},\n\n\tunwrap: function( selector ) {\n\t\tthis.parent( selector ).not( \"body\" ).each( function() {\n\t\t\tjQuery( this ).replaceWith( this.childNodes );\n\t\t} );\n\t\treturn this;\n\t}\n} );\n\n\njQuery.expr.pseudos.hidden = function( elem ) {\n\treturn !jQuery.expr.pseudos.visible( elem );\n};\njQuery.expr.pseudos.visible = function( elem ) {\n\treturn !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length );\n};\n\n\n\n\njQuery.ajaxSettings.xhr = function() {\n\ttry {\n\t\treturn new window.XMLHttpRequest();\n\t} catch ( e ) {}\n};\n\nvar xhrSuccessStatus = {\n\n\t\t// File protocol always yields status code 0, assume 200\n\t\t0: 200,\n\n\t\t// Support: IE <=9 only\n\t\t// #1450: sometimes IE returns 1223 when it should be 204\n\t\t1223: 204\n\t},\n\txhrSupported = jQuery.ajaxSettings.xhr();\n\nsupport.cors = !!xhrSupported && ( \"withCredentials\" in xhrSupported );\nsupport.ajax = xhrSupported = !!xhrSupported;\n\njQuery.ajaxTransport( function( options ) {\n\tvar callback, errorCallback;\n\n\t// Cross domain only allowed if supported through XMLHttpRequest\n\tif ( support.cors || xhrSupported && !options.crossDomain ) {\n\t\treturn {\n\t\t\tsend: function( headers, complete ) {\n\t\t\t\tvar i,\n\t\t\t\t\txhr = options.xhr();\n\n\t\t\t\txhr.open(\n\t\t\t\t\toptions.type,\n\t\t\t\t\toptions.url,\n\t\t\t\t\toptions.async,\n\t\t\t\t\toptions.username,\n\t\t\t\t\toptions.password\n\t\t\t\t);\n\n\t\t\t\t// Apply custom fields if provided\n\t\t\t\tif ( options.xhrFields ) {\n\t\t\t\t\tfor ( i in options.xhrFields ) {\n\t\t\t\t\t\txhr[ i ] = options.xhrFields[ i ];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Override mime type if needed\n\t\t\t\tif ( options.mimeType && xhr.overrideMimeType ) {\n\t\t\t\t\txhr.overrideMimeType( options.mimeType );\n\t\t\t\t}\n\n\t\t\t\t// X-Requested-With header\n\t\t\t\t// For cross-domain requests, seeing as conditions for a preflight are\n\t\t\t\t// akin to a jigsaw puzzle, we simply never set it to be sure.\n\t\t\t\t// (it can always be set on a per-request basis or even using ajaxSetup)\n\t\t\t\t// For same-domain requests, won't change header if already provided.\n\t\t\t\tif ( !options.crossDomain && !headers[ \"X-Requested-With\" ] ) {\n\t\t\t\t\theaders[ \"X-Requested-With\" ] = \"XMLHttpRequest\";\n\t\t\t\t}\n\n\t\t\t\t// Set headers\n\t\t\t\tfor ( i in headers ) {\n\t\t\t\t\txhr.setRequestHeader( i, headers[ i ] );\n\t\t\t\t}\n\n\t\t\t\t// Callback\n\t\t\t\tcallback = function( type ) {\n\t\t\t\t\treturn function() {\n\t\t\t\t\t\tif ( callback ) {\n\t\t\t\t\t\t\tcallback = errorCallback = xhr.onload =\n\t\t\t\t\t\t\t\txhr.onerror = xhr.onabort = xhr.ontimeout =\n\t\t\t\t\t\t\t\t\txhr.onreadystatechange = null;\n\n\t\t\t\t\t\t\tif ( type === \"abort\" ) {\n\t\t\t\t\t\t\t\txhr.abort();\n\t\t\t\t\t\t\t} else if ( type === \"error\" ) {\n\n\t\t\t\t\t\t\t\t// Support: IE <=9 only\n\t\t\t\t\t\t\t\t// On a manual native abort, IE9 throws\n\t\t\t\t\t\t\t\t// errors on any property access that is not readyState\n\t\t\t\t\t\t\t\tif ( typeof xhr.status !== \"number\" ) {\n\t\t\t\t\t\t\t\t\tcomplete( 0, \"error\" );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcomplete(\n\n\t\t\t\t\t\t\t\t\t\t// File: protocol always yields status 0; see #8605, #14207\n\t\t\t\t\t\t\t\t\t\txhr.status,\n\t\t\t\t\t\t\t\t\t\txhr.statusText\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcomplete(\n\t\t\t\t\t\t\t\t\txhrSuccessStatus[ xhr.status ] || xhr.status,\n\t\t\t\t\t\t\t\t\txhr.statusText,\n\n\t\t\t\t\t\t\t\t\t// Support: IE <=9 only\n\t\t\t\t\t\t\t\t\t// IE9 has no XHR2 but throws on binary (trac-11426)\n\t\t\t\t\t\t\t\t\t// For XHR2 non-text, let the caller handle it (gh-2498)\n\t\t\t\t\t\t\t\t\t( xhr.responseType || \"text\" ) !== \"text\"  ||\n\t\t\t\t\t\t\t\t\ttypeof xhr.responseText !== \"string\" ?\n\t\t\t\t\t\t\t\t\t\t{ binary: xhr.response } :\n\t\t\t\t\t\t\t\t\t\t{ text: xhr.responseText },\n\t\t\t\t\t\t\t\t\txhr.getAllResponseHeaders()\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t};\n\n\t\t\t\t// Listen to events\n\t\t\t\txhr.onload = callback();\n\t\t\t\terrorCallback = xhr.onerror = xhr.ontimeout = callback( \"error\" );\n\n\t\t\t\t// Support: IE 9 only\n\t\t\t\t// Use onreadystatechange to replace onabort\n\t\t\t\t// to handle uncaught aborts\n\t\t\t\tif ( xhr.onabort !== undefined ) {\n\t\t\t\t\txhr.onabort = errorCallback;\n\t\t\t\t} else {\n\t\t\t\t\txhr.onreadystatechange = function() {\n\n\t\t\t\t\t\t// Check readyState before timeout as it changes\n\t\t\t\t\t\tif ( xhr.readyState === 4 ) {\n\n\t\t\t\t\t\t\t// Allow onerror to be called first,\n\t\t\t\t\t\t\t// but that will not handle a native abort\n\t\t\t\t\t\t\t// Also, save errorCallback to a variable\n\t\t\t\t\t\t\t// as xhr.onerror cannot be accessed\n\t\t\t\t\t\t\twindow.setTimeout( function() {\n\t\t\t\t\t\t\t\tif ( callback ) {\n\t\t\t\t\t\t\t\t\terrorCallback();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// Create the abort callback\n\t\t\t\tcallback = callback( \"abort\" );\n\n\t\t\t\ttry {\n\n\t\t\t\t\t// Do send the request (this may raise an exception)\n\t\t\t\t\txhr.send( options.hasContent && options.data || null );\n\t\t\t\t} catch ( e ) {\n\n\t\t\t\t\t// #14683: Only rethrow if this hasn't been notified as an error yet\n\t\t\t\t\tif ( callback ) {\n\t\t\t\t\t\tthrow e;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tabort: function() {\n\t\t\t\tif ( callback ) {\n\t\t\t\t\tcallback();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n} );\n\n\n\n\n// Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432)\njQuery.ajaxPrefilter( function( s ) {\n\tif ( s.crossDomain ) {\n\t\ts.contents.script = false;\n\t}\n} );\n\n// Install script dataType\njQuery.ajaxSetup( {\n\taccepts: {\n\t\tscript: \"text/javascript, application/javascript, \" +\n\t\t\t\"application/ecmascript, application/x-ecmascript\"\n\t},\n\tcontents: {\n\t\tscript: /\\b(?:java|ecma)script\\b/\n\t},\n\tconverters: {\n\t\t\"text script\": function( text ) {\n\t\t\tjQuery.globalEval( text );\n\t\t\treturn text;\n\t\t}\n\t}\n} );\n\n// Handle cache's special case and crossDomain\njQuery.ajaxPrefilter( \"script\", function( s ) {\n\tif ( s.cache === undefined ) {\n\t\ts.cache = false;\n\t}\n\tif ( s.crossDomain ) {\n\t\ts.type = \"GET\";\n\t}\n} );\n\n// Bind script tag hack transport\njQuery.ajaxTransport( \"script\", function( s ) {\n\n\t// This transport only deals with cross domain or forced-by-attrs requests\n\tif ( s.crossDomain || s.scriptAttrs ) {\n\t\tvar script, callback;\n\t\treturn {\n\t\t\tsend: function( _, complete ) {\n\t\t\t\tscript = jQuery( \"<script>\" )\n\t\t\t\t\t.attr( s.scriptAttrs || {} )\n\t\t\t\t\t.prop( { charset: s.scriptCharset, src: s.url } )\n\t\t\t\t\t.on( \"load error\", callback = function( evt ) {\n\t\t\t\t\t\tscript.remove();\n\t\t\t\t\t\tcallback = null;\n\t\t\t\t\t\tif ( evt ) {\n\t\t\t\t\t\t\tcomplete( evt.type === \"error\" ? 404 : 200, evt.type );\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\n\t\t\t\t// Use native DOM manipulation to avoid our domManip AJAX trickery\n\t\t\t\tdocument.head.appendChild( script[ 0 ] );\n\t\t\t},\n\t\t\tabort: function() {\n\t\t\t\tif ( callback ) {\n\t\t\t\t\tcallback();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n} );\n\n\n\n\nvar oldCallbacks = [],\n\trjsonp = /(=)\\?(?=&|$)|\\?\\?/;\n\n// Default jsonp settings\njQuery.ajaxSetup( {\n\tjsonp: \"callback\",\n\tjsonpCallback: function() {\n\t\tvar callback = oldCallbacks.pop() || ( jQuery.expando + \"_\" + ( nonce++ ) );\n\t\tthis[ callback ] = true;\n\t\treturn callback;\n\t}\n} );\n\n// Detect, normalize options and install callbacks for jsonp requests\njQuery.ajaxPrefilter( \"json jsonp\", function( s, originalSettings, jqXHR ) {\n\n\tvar callbackName, overwritten, responseContainer,\n\t\tjsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?\n\t\t\t\"url\" :\n\t\t\ttypeof s.data === \"string\" &&\n\t\t\t\t( s.contentType || \"\" )\n\t\t\t\t\t.indexOf( \"application/x-www-form-urlencoded\" ) === 0 &&\n\t\t\t\trjsonp.test( s.data ) && \"data\"\n\t\t);\n\n\t// Handle iff the expected data type is \"jsonp\" or we have a parameter to set\n\tif ( jsonProp || s.dataTypes[ 0 ] === \"jsonp\" ) {\n\n\t\t// Get callback name, remembering preexisting value associated with it\n\t\tcallbackName = s.jsonpCallback = isFunction( s.jsonpCallback ) ?\n\t\t\ts.jsonpCallback() :\n\t\t\ts.jsonpCallback;\n\n\t\t// Insert callback into url or form data\n\t\tif ( jsonProp ) {\n\t\t\ts[ jsonProp ] = s[ jsonProp ].replace( rjsonp, \"$1\" + callbackName );\n\t\t} else if ( s.jsonp !== false ) {\n\t\t\ts.url += ( rquery.test( s.url ) ? \"&\" : \"?\" ) + s.jsonp + \"=\" + callbackName;\n\t\t}\n\n\t\t// Use data converter to retrieve json after script execution\n\t\ts.converters[ \"script json\" ] = function() {\n\t\t\tif ( !responseContainer ) {\n\t\t\t\tjQuery.error( callbackName + \" was not called\" );\n\t\t\t}\n\t\t\treturn responseContainer[ 0 ];\n\t\t};\n\n\t\t// Force json dataType\n\t\ts.dataTypes[ 0 ] = \"json\";\n\n\t\t// Install callback\n\t\toverwritten = window[ callbackName ];\n\t\twindow[ callbackName ] = function() {\n\t\t\tresponseContainer = arguments;\n\t\t};\n\n\t\t// Clean-up function (fires after converters)\n\t\tjqXHR.always( function() {\n\n\t\t\t// If previous value didn't exist - remove it\n\t\t\tif ( overwritten === undefined ) {\n\t\t\t\tjQuery( window ).removeProp( callbackName );\n\n\t\t\t// Otherwise restore preexisting value\n\t\t\t} else {\n\t\t\t\twindow[ callbackName ] = overwritten;\n\t\t\t}\n\n\t\t\t// Save back as free\n\t\t\tif ( s[ callbackName ] ) {\n\n\t\t\t\t// Make sure that re-using the options doesn't screw things around\n\t\t\t\ts.jsonpCallback = originalSettings.jsonpCallback;\n\n\t\t\t\t// Save the callback name for future use\n\t\t\t\toldCallbacks.push( callbackName );\n\t\t\t}\n\n\t\t\t// Call if it was a function and we have a response\n\t\t\tif ( responseContainer && isFunction( overwritten ) ) {\n\t\t\t\toverwritten( responseContainer[ 0 ] );\n\t\t\t}\n\n\t\t\tresponseContainer = overwritten = undefined;\n\t\t} );\n\n\t\t// Delegate to script\n\t\treturn \"script\";\n\t}\n} );\n\n\n\n\n// Support: Safari 8 only\n// In Safari 8 documents created via document.implementation.createHTMLDocument\n// collapse sibling forms: the second one becomes a child of the first one.\n// Because of that, this security measure has to be disabled in Safari 8.\n// https://bugs.webkit.org/show_bug.cgi?id=137337\nsupport.createHTMLDocument = ( function() {\n\tvar body = document.implementation.createHTMLDocument( \"\" ).body;\n\tbody.innerHTML = \"<form></form><form></form>\";\n\treturn body.childNodes.length === 2;\n} )();\n\n\n// Argument \"data\" should be string of html\n// context (optional): If specified, the fragment will be created in this context,\n// defaults to document\n// keepScripts (optional): If true, will include scripts passed in the html string\njQuery.parseHTML = function( data, context, keepScripts ) {\n\tif ( typeof data !== \"string\" ) {\n\t\treturn [];\n\t}\n\tif ( typeof context === \"boolean\" ) {\n\t\tkeepScripts = context;\n\t\tcontext = false;\n\t}\n\n\tvar base, parsed, scripts;\n\n\tif ( !context ) {\n\n\t\t// Stop scripts or inline event handlers from being executed immediately\n\t\t// by using document.implementation\n\t\tif ( support.createHTMLDocument ) {\n\t\t\tcontext = document.implementation.createHTMLDocument( \"\" );\n\n\t\t\t// Set the base href for the created document\n\t\t\t// so any parsed elements with URLs\n\t\t\t// are based on the document's URL (gh-2965)\n\t\t\tbase = context.createElement( \"base\" );\n\t\t\tbase.href = document.location.href;\n\t\t\tcontext.head.appendChild( base );\n\t\t} else {\n\t\t\tcontext = document;\n\t\t}\n\t}\n\n\tparsed = rsingleTag.exec( data );\n\tscripts = !keepScripts && [];\n\n\t// Single tag\n\tif ( parsed ) {\n\t\treturn [ context.createElement( parsed[ 1 ] ) ];\n\t}\n\n\tparsed = buildFragment( [ data ], context, scripts );\n\n\tif ( scripts && scripts.length ) {\n\t\tjQuery( scripts ).remove();\n\t}\n\n\treturn jQuery.merge( [], parsed.childNodes );\n};\n\n\n/**\n * Load a url into a page\n */\njQuery.fn.load = function( url, params, callback ) {\n\tvar selector, type, response,\n\t\tself = this,\n\t\toff = url.indexOf( \" \" );\n\n\tif ( off > -1 ) {\n\t\tselector = stripAndCollapse( url.slice( off ) );\n\t\turl = url.slice( 0, off );\n\t}\n\n\t// If it's a function\n\tif ( isFunction( params ) ) {\n\n\t\t// We assume that it's the callback\n\t\tcallback = params;\n\t\tparams = undefined;\n\n\t// Otherwise, build a param string\n\t} else if ( params && typeof params === \"object\" ) {\n\t\ttype = \"POST\";\n\t}\n\n\t// If we have elements to modify, make the request\n\tif ( self.length > 0 ) {\n\t\tjQuery.ajax( {\n\t\t\turl: url,\n\n\t\t\t// If \"type\" variable is undefined, then \"GET\" method will be used.\n\t\t\t// Make value of this field explicit since\n\t\t\t// user can override it through ajaxSetup method\n\t\t\ttype: type || \"GET\",\n\t\t\tdataType: \"html\",\n\t\t\tdata: params\n\t\t} ).done( function( responseText ) {\n\n\t\t\t// Save response for use in complete callback\n\t\t\tresponse = arguments;\n\n\t\t\tself.html( selector ?\n\n\t\t\t\t// If a selector was specified, locate the right elements in a dummy div\n\t\t\t\t// Exclude scripts to avoid IE 'Permission Denied' errors\n\t\t\t\tjQuery( \"<div>\" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :\n\n\t\t\t\t// Otherwise use the full result\n\t\t\t\tresponseText );\n\n\t\t// If the request succeeds, this function gets \"data\", \"status\", \"jqXHR\"\n\t\t// but they are ignored because response was set above.\n\t\t// If it fails, this function gets \"jqXHR\", \"status\", \"error\"\n\t\t} ).always( callback && function( jqXHR, status ) {\n\t\t\tself.each( function() {\n\t\t\t\tcallback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );\n\t\t\t} );\n\t\t} );\n\t}\n\n\treturn this;\n};\n\n\n\n\n// Attach a bunch of functions for handling common AJAX events\njQuery.each( [\n\t\"ajaxStart\",\n\t\"ajaxStop\",\n\t\"ajaxComplete\",\n\t\"ajaxError\",\n\t\"ajaxSuccess\",\n\t\"ajaxSend\"\n], function( i, type ) {\n\tjQuery.fn[ type ] = function( fn ) {\n\t\treturn this.on( type, fn );\n\t};\n} );\n\n\n\n\njQuery.expr.pseudos.animated = function( elem ) {\n\treturn jQuery.grep( jQuery.timers, function( fn ) {\n\t\treturn elem === fn.elem;\n\t} ).length;\n};\n\n\n\n\njQuery.offset = {\n\tsetOffset: function( elem, options, i ) {\n\t\tvar curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,\n\t\t\tposition = jQuery.css( elem, \"position\" ),\n\t\t\tcurElem = jQuery( elem ),\n\t\t\tprops = {};\n\n\t\t// Set position first, in-case top/left are set even on static elem\n\t\tif ( position === \"static\" ) {\n\t\t\telem.style.position = \"relative\";\n\t\t}\n\n\t\tcurOffset = curElem.offset();\n\t\tcurCSSTop = jQuery.css( elem, \"top\" );\n\t\tcurCSSLeft = jQuery.css( elem, \"left\" );\n\t\tcalculatePosition = ( position === \"absolute\" || position === \"fixed\" ) &&\n\t\t\t( curCSSTop + curCSSLeft ).indexOf( \"auto\" ) > -1;\n\n\t\t// Need to be able to calculate position if either\n\t\t// top or left is auto and position is either absolute or fixed\n\t\tif ( calculatePosition ) {\n\t\t\tcurPosition = curElem.position();\n\t\t\tcurTop = curPosition.top;\n\t\t\tcurLeft = curPosition.left;\n\n\t\t} else {\n\t\t\tcurTop = parseFloat( curCSSTop ) || 0;\n\t\t\tcurLeft = parseFloat( curCSSLeft ) || 0;\n\t\t}\n\n\t\tif ( isFunction( options ) ) {\n\n\t\t\t// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)\n\t\t\toptions = options.call( elem, i, jQuery.extend( {}, curOffset ) );\n\t\t}\n\n\t\tif ( options.top != null ) {\n\t\t\tprops.top = ( options.top - curOffset.top ) + curTop;\n\t\t}\n\t\tif ( options.left != null ) {\n\t\t\tprops.left = ( options.left - curOffset.left ) + curLeft;\n\t\t}\n\n\t\tif ( \"using\" in options ) {\n\t\t\toptions.using.call( elem, props );\n\n\t\t} else {\n\t\t\tcurElem.css( props );\n\t\t}\n\t}\n};\n\njQuery.fn.extend( {\n\n\t// offset() relates an element's border box to the document origin\n\toffset: function( options ) {\n\n\t\t// Preserve chaining for setter\n\t\tif ( arguments.length ) {\n\t\t\treturn options === undefined ?\n\t\t\t\tthis :\n\t\t\t\tthis.each( function( i ) {\n\t\t\t\t\tjQuery.offset.setOffset( this, options, i );\n\t\t\t\t} );\n\t\t}\n\n\t\tvar rect, win,\n\t\t\telem = this[ 0 ];\n\n\t\tif ( !elem ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Return zeros for disconnected and hidden (display: none) elements (gh-2310)\n\t\t// Support: IE <=11 only\n\t\t// Running getBoundingClientRect on a\n\t\t// disconnected node in IE throws an error\n\t\tif ( !elem.getClientRects().length ) {\n\t\t\treturn { top: 0, left: 0 };\n\t\t}\n\n\t\t// Get document-relative position by adding viewport scroll to viewport-relative gBCR\n\t\trect = elem.getBoundingClientRect();\n\t\twin = elem.ownerDocument.defaultView;\n\t\treturn {\n\t\t\ttop: rect.top + win.pageYOffset,\n\t\t\tleft: rect.left + win.pageXOffset\n\t\t};\n\t},\n\n\t// position() relates an element's margin box to its offset parent's padding box\n\t// This corresponds to the behavior of CSS absolute positioning\n\tposition: function() {\n\t\tif ( !this[ 0 ] ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar offsetParent, offset, doc,\n\t\t\telem = this[ 0 ],\n\t\t\tparentOffset = { top: 0, left: 0 };\n\n\t\t// position:fixed elements are offset from the viewport, which itself always has zero offset\n\t\tif ( jQuery.css( elem, \"position\" ) === \"fixed\" ) {\n\n\t\t\t// Assume position:fixed implies availability of getBoundingClientRect\n\t\t\toffset = elem.getBoundingClientRect();\n\n\t\t} else {\n\t\t\toffset = this.offset();\n\n\t\t\t// Account for the *real* offset parent, which can be the document or its root element\n\t\t\t// when a statically positioned element is identified\n\t\t\tdoc = elem.ownerDocument;\n\t\t\toffsetParent = elem.offsetParent || doc.documentElement;\n\t\t\twhile ( offsetParent &&\n\t\t\t\t( offsetParent === doc.body || offsetParent === doc.documentElement ) &&\n\t\t\t\tjQuery.css( offsetParent, \"position\" ) === \"static\" ) {\n\n\t\t\t\toffsetParent = offsetParent.parentNode;\n\t\t\t}\n\t\t\tif ( offsetParent && offsetParent !== elem && offsetParent.nodeType === 1 ) {\n\n\t\t\t\t// Incorporate borders into its offset, since they are outside its content origin\n\t\t\t\tparentOffset = jQuery( offsetParent ).offset();\n\t\t\t\tparentOffset.top += jQuery.css( offsetParent, \"borderTopWidth\", true );\n\t\t\t\tparentOffset.left += jQuery.css( offsetParent, \"borderLeftWidth\", true );\n\t\t\t}\n\t\t}\n\n\t\t// Subtract parent offsets and element margins\n\t\treturn {\n\t\t\ttop: offset.top - parentOffset.top - jQuery.css( elem, \"marginTop\", true ),\n\t\t\tleft: offset.left - parentOffset.left - jQuery.css( elem, \"marginLeft\", true )\n\t\t};\n\t},\n\n\t// This method will return documentElement in the following cases:\n\t// 1) For the element inside the iframe without offsetParent, this method will return\n\t//    documentElement of the parent window\n\t// 2) For the hidden or detached element\n\t// 3) For body or html element, i.e. in case of the html node - it will return itself\n\t//\n\t// but those exceptions were never presented as a real life use-cases\n\t// and might be considered as more preferable results.\n\t//\n\t// This logic, however, is not guaranteed and can change at any point in the future\n\toffsetParent: function() {\n\t\treturn this.map( function() {\n\t\t\tvar offsetParent = this.offsetParent;\n\n\t\t\twhile ( offsetParent && jQuery.css( offsetParent, \"position\" ) === \"static\" ) {\n\t\t\t\toffsetParent = offsetParent.offsetParent;\n\t\t\t}\n\n\t\t\treturn offsetParent || documentElement;\n\t\t} );\n\t}\n} );\n\n// Create scrollLeft and scrollTop methods\njQuery.each( { scrollLeft: \"pageXOffset\", scrollTop: \"pageYOffset\" }, function( method, prop ) {\n\tvar top = \"pageYOffset\" === prop;\n\n\tjQuery.fn[ method ] = function( val ) {\n\t\treturn access( this, function( elem, method, val ) {\n\n\t\t\t// Coalesce documents and windows\n\t\t\tvar win;\n\t\t\tif ( isWindow( elem ) ) {\n\t\t\t\twin = elem;\n\t\t\t} else if ( elem.nodeType === 9 ) {\n\t\t\t\twin = elem.defaultView;\n\t\t\t}\n\n\t\t\tif ( val === undefined ) {\n\t\t\t\treturn win ? win[ prop ] : elem[ method ];\n\t\t\t}\n\n\t\t\tif ( win ) {\n\t\t\t\twin.scrollTo(\n\t\t\t\t\t!top ? val : win.pageXOffset,\n\t\t\t\t\ttop ? val : win.pageYOffset\n\t\t\t\t);\n\n\t\t\t} else {\n\t\t\t\telem[ method ] = val;\n\t\t\t}\n\t\t}, method, val, arguments.length );\n\t};\n} );\n\n// Support: Safari <=7 - 9.1, Chrome <=37 - 49\n// Add the top/left cssHooks using jQuery.fn.position\n// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084\n// Blink bug: https://bugs.chromium.org/p/chromium/issues/detail?id=589347\n// getComputedStyle returns percent when specified for top/left/bottom/right;\n// rather than make the css module depend on the offset module, just check for it here\njQuery.each( [ \"top\", \"left\" ], function( i, prop ) {\n\tjQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,\n\t\tfunction( elem, computed ) {\n\t\t\tif ( computed ) {\n\t\t\t\tcomputed = curCSS( elem, prop );\n\n\t\t\t\t// If curCSS returns percentage, fallback to offset\n\t\t\t\treturn rnumnonpx.test( computed ) ?\n\t\t\t\t\tjQuery( elem ).position()[ prop ] + \"px\" :\n\t\t\t\t\tcomputed;\n\t\t\t}\n\t\t}\n\t);\n} );\n\n\n// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods\njQuery.each( { Height: \"height\", Width: \"width\" }, function( name, type ) {\n\tjQuery.each( { padding: \"inner\" + name, content: type, \"\": \"outer\" + name },\n\t\tfunction( defaultExtra, funcName ) {\n\n\t\t// Margin is only for outerHeight, outerWidth\n\t\tjQuery.fn[ funcName ] = function( margin, value ) {\n\t\t\tvar chainable = arguments.length && ( defaultExtra || typeof margin !== \"boolean\" ),\n\t\t\t\textra = defaultExtra || ( margin === true || value === true ? \"margin\" : \"border\" );\n\n\t\t\treturn access( this, function( elem, type, value ) {\n\t\t\t\tvar doc;\n\n\t\t\t\tif ( isWindow( elem ) ) {\n\n\t\t\t\t\t// $( window ).outerWidth/Height return w/h including scrollbars (gh-1729)\n\t\t\t\t\treturn funcName.indexOf( \"outer\" ) === 0 ?\n\t\t\t\t\t\telem[ \"inner\" + name ] :\n\t\t\t\t\t\telem.document.documentElement[ \"client\" + name ];\n\t\t\t\t}\n\n\t\t\t\t// Get document width or height\n\t\t\t\tif ( elem.nodeType === 9 ) {\n\t\t\t\t\tdoc = elem.documentElement;\n\n\t\t\t\t\t// Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],\n\t\t\t\t\t// whichever is greatest\n\t\t\t\t\treturn Math.max(\n\t\t\t\t\t\telem.body[ \"scroll\" + name ], doc[ \"scroll\" + name ],\n\t\t\t\t\t\telem.body[ \"offset\" + name ], doc[ \"offset\" + name ],\n\t\t\t\t\t\tdoc[ \"client\" + name ]\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn value === undefined ?\n\n\t\t\t\t\t// Get width or height on the element, requesting but not forcing parseFloat\n\t\t\t\t\tjQuery.css( elem, type, extra ) :\n\n\t\t\t\t\t// Set width or height on the element\n\t\t\t\t\tjQuery.style( elem, type, value, extra );\n\t\t\t}, type, chainable ? margin : undefined, chainable );\n\t\t};\n\t} );\n} );\n\n\njQuery.each( ( \"blur focus focusin focusout resize scroll click dblclick \" +\n\t\"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave \" +\n\t\"change select submit keydown keypress keyup contextmenu\" ).split( \" \" ),\n\tfunction( i, name ) {\n\n\t// Handle event binding\n\tjQuery.fn[ name ] = function( data, fn ) {\n\t\treturn arguments.length > 0 ?\n\t\t\tthis.on( name, null, data, fn ) :\n\t\t\tthis.trigger( name );\n\t};\n} );\n\njQuery.fn.extend( {\n\thover: function( fnOver, fnOut ) {\n\t\treturn this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );\n\t}\n} );\n\n\n\n\njQuery.fn.extend( {\n\n\tbind: function( types, data, fn ) {\n\t\treturn this.on( types, null, data, fn );\n\t},\n\tunbind: function( types, fn ) {\n\t\treturn this.off( types, null, fn );\n\t},\n\n\tdelegate: function( selector, types, data, fn ) {\n\t\treturn this.on( types, selector, data, fn );\n\t},\n\tundelegate: function( selector, types, fn ) {\n\n\t\t// ( namespace ) or ( selector, types [, fn] )\n\t\treturn arguments.length === 1 ?\n\t\t\tthis.off( selector, \"**\" ) :\n\t\t\tthis.off( types, selector || \"**\", fn );\n\t}\n} );\n\n// Bind a function to a context, optionally partially applying any\n// arguments.\n// jQuery.proxy is deprecated to promote standards (specifically Function#bind)\n// However, it is not slated for removal any time soon\njQuery.proxy = function( fn, context ) {\n\tvar tmp, args, proxy;\n\n\tif ( typeof context === \"string\" ) {\n\t\ttmp = fn[ context ];\n\t\tcontext = fn;\n\t\tfn = tmp;\n\t}\n\n\t// Quick check to determine if target is callable, in the spec\n\t// this throws a TypeError, but we will just return undefined.\n\tif ( !isFunction( fn ) ) {\n\t\treturn undefined;\n\t}\n\n\t// Simulated bind\n\targs = slice.call( arguments, 2 );\n\tproxy = function() {\n\t\treturn fn.apply( context || this, args.concat( slice.call( arguments ) ) );\n\t};\n\n\t// Set the guid of unique handler to the same of original handler, so it can be removed\n\tproxy.guid = fn.guid = fn.guid || jQuery.guid++;\n\n\treturn proxy;\n};\n\njQuery.holdReady = function( hold ) {\n\tif ( hold ) {\n\t\tjQuery.readyWait++;\n\t} else {\n\t\tjQuery.ready( true );\n\t}\n};\njQuery.isArray = Array.isArray;\njQuery.parseJSON = JSON.parse;\njQuery.nodeName = nodeName;\njQuery.isFunction = isFunction;\njQuery.isWindow = isWindow;\njQuery.camelCase = camelCase;\njQuery.type = toType;\n\njQuery.now = Date.now;\n\njQuery.isNumeric = function( obj ) {\n\n\t// As of jQuery 3.0, isNumeric is limited to\n\t// strings and numbers (primitives or objects)\n\t// that can be coerced to finite numbers (gh-2662)\n\tvar type = jQuery.type( obj );\n\treturn ( type === \"number\" || type === \"string\" ) &&\n\n\t\t// parseFloat NaNs numeric-cast false positives (\"\")\n\t\t// ...but misinterprets leading-number strings, particularly hex literals (\"0x...\")\n\t\t// subtraction forces infinities to NaN\n\t\t!isNaN( obj - parseFloat( obj ) );\n};\n\n\n\n\n// Register as a named AMD module, since jQuery can be concatenated with other\n// files that may use define, but not via a proper concatenation script that\n// understands anonymous AMD modules. A named AMD is safest and most robust\n// way to register. Lowercase jquery is used because AMD module names are\n// derived from file names, and jQuery is normally delivered in a lowercase\n// file name. Do this after creating the global so that if an AMD module wants\n// to call noConflict to hide this version of jQuery, it will work.\n\n// Note that for maximum portability, libraries that are not jQuery should\n// declare themselves as anonymous modules, and avoid setting a global if an\n// AMD loader is present. jQuery is a special case. For more information, see\n// https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon\n\nif ( typeof define === \"function\" && define.amd ) {\n\tdefine( \"jquery\", [], function() {\n\t\treturn jQuery;\n\t} );\n}\n\n\n\n\nvar\n\n\t// Map over jQuery in case of overwrite\n\t_jQuery = window.jQuery,\n\n\t// Map over the $ in case of overwrite\n\t_$ = window.$;\n\njQuery.noConflict = function( deep ) {\n\tif ( window.$ === jQuery ) {\n\t\twindow.$ = _$;\n\t}\n\n\tif ( deep && window.jQuery === jQuery ) {\n\t\twindow.jQuery = _jQuery;\n\t}\n\n\treturn jQuery;\n};\n\n// Expose jQuery and $ identifiers, even in AMD\n// (#7102#comment:10, https://github.com/jquery/jquery/pull/557)\n// and CommonJS for browser emulators (#13566)\nif ( !noGlobal ) {\n\twindow.jQuery = window.$ = jQuery;\n}\n\n\n\n\nreturn jQuery;\n} );\n"
  },
  {
    "path": "cyacas/packaging/deb/missing-sources/jquery.ui-contextmenu.js",
    "content": "/*******************************************************************************\n * jquery.ui-contextmenu.js plugin.\n *\n * jQuery plugin that provides a context menu (based on the jQueryUI menu widget).\n *\n * @see https://github.com/mar10/jquery-ui-contextmenu\n *\n * Copyright (c) 2013-2017, Martin Wendt (http://wwWendt.de). Licensed MIT.\n */\n\n(function( factory ) {\n\t\"use strict\";\n\tif ( typeof define === \"function\" && define.amd ) {\n\t\t// AMD. Register as an anonymous module.\n\t\tdefine([ \"jquery\", \"jquery-ui/ui/widgets/menu\" ], factory );\n\t} else {\n\t\t// Browser globals\n\t\tfactory( jQuery );\n\t}\n}(function( $ ) {\n\n\"use strict\";\n\nvar supportSelectstart = \"onselectstart\" in document.createElement(\"div\"),\n\tmatch = $.ui.menu.version.match(/^(\\d)\\.(\\d+)/),\n\tuiVersion = {\n\t\tmajor: parseInt(match[1], 10),\n\t\tminor: parseInt(match[2], 10)\n\t},\n\tisLTE110 = ( uiVersion.major < 2 && uiVersion.minor <= 10 ),\n\tisLTE111 = ( uiVersion.major < 2 && uiVersion.minor <= 11 );\n\n$.widget(\"moogle.contextmenu\", {\n\tversion: \"@VERSION\",\n\toptions: {\n\t\taddClass: \"ui-contextmenu\",  // Add this class to the outer <ul>\n\t\tcloseOnWindowBlur: true,     // Close menu when window loses focus\n\t\tautoFocus: false,     // Set keyboard focus to first entry on open\n\t\tautoTrigger: true,    // open menu on browser's `contextmenu` event\n\t\tdelegate: null,       // selector\n\t\thide: { effect: \"fadeOut\", duration: \"fast\" },\n\t\tignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents\n\t\tmenu: null,           // selector or jQuery pointing to <UL>, or a definition hash\n\t\tposition: null,       // popup positon\n\t\tpreventContextMenuForPopup: false, // prevent opening the browser's system\n\t\t\t\t\t\t\t\t\t\t   // context menu on menu entries\n\t\tpreventSelect: false, // disable text selection of target\n\t\tshow: { effect: \"slideDown\", duration: \"fast\" },\n\t\ttaphold: false,       // open menu on taphold events (requires external plugins)\n\t\tuiMenuOptions: {},\t  // Additional options, used when UI Menu is created\n\t\t// Events:\n\t\tbeforeOpen: $.noop,   // menu about to open; return `false` to prevent opening\n\t\tblur: $.noop,         // menu option lost focus\n\t\tclose: $.noop,        // menu was closed\n\t\tcreate: $.noop,       // menu was initialized\n\t\tcreateMenu: $.noop,   // menu was initialized (original UI Menu)\n\t\tfocus: $.noop,        // menu option got focus\n\t\topen: $.noop,         // menu was opened\n\t\tselect: $.noop        // menu option was selected; return `false` to prevent closing\n\t},\n\t/** Constructor */\n\t_create: function() {\n\t\tvar cssText, eventNames, targetId,\n\t\t\topts = this.options;\n\n\t\tthis.$headStyle = null;\n\t\tthis.$menu = null;\n\t\tthis.menuIsTemp = false;\n\t\tthis.currentTarget = null;\n\t\tthis.extraData = {};\n\t\tthis.previousFocus = null;\n\n\t\tif (opts.delegate == null) {\n\t\t\t$.error(\"ui-contextmenu: Missing required option `delegate`.\");\n\t\t}\n\t\tif (opts.preventSelect) {\n\t\t\t// Create a global style for all potential menu targets\n\t\t\t// If the contextmenu was bound to `document`, we apply the\n\t\t\t// selector relative to the <body> tag instead\n\t\t\ttargetId = ($(this.element).is(document) ? $(\"body\")\n\t\t\t\t: this.element).uniqueId().attr(\"id\");\n\t\t\tcssText = \"#\" + targetId + \" \" + opts.delegate + \" { \" +\n\t\t\t\t\t\"-webkit-user-select: none; \" +\n\t\t\t\t\t\"-khtml-user-select: none; \" +\n\t\t\t\t\t\"-moz-user-select: none; \" +\n\t\t\t\t\t\"-ms-user-select: none; \" +\n\t\t\t\t\t\"user-select: none; \" +\n\t\t\t\t\t\"}\";\n\t\t\tthis.$headStyle = $(\"<style class='moogle-contextmenu-style' />\")\n\t\t\t\t.prop(\"type\", \"text/css\")\n\t\t\t\t.appendTo(\"head\");\n\n\t\t\ttry {\n\t\t\t\tthis.$headStyle.html(cssText);\n\t\t\t} catch ( e ) {\n\t\t\t\t// issue #47: fix for IE 6-8\n\t\t\t\tthis.$headStyle[0].styleSheet.cssText = cssText;\n\t\t\t}\n\t\t\t// TODO: the selectstart is not supported by FF?\n\t\t\tif (supportSelectstart) {\n\t\t\t\tthis.element.on(\"selectstart\" + this.eventNamespace, opts.delegate,\n\t\t\t\t\t\t\t\t\t  function(event) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis._createUiMenu(opts.menu);\n\n\t\teventNames = \"contextmenu\" + this.eventNamespace;\n\t\tif (opts.taphold) {\n\t\t\teventNames += \" taphold\" + this.eventNamespace;\n\t\t}\n\t\tthis.element.on(eventNames, opts.delegate, $.proxy(this._openMenu, this));\n\t},\n\t/** Destructor, called on $().contextmenu(\"destroy\"). */\n\t_destroy: function() {\n\t\tthis.element.off(this.eventNamespace);\n\n\t\tthis._createUiMenu(null);\n\n\t\tif (this.$headStyle) {\n\t\t\tthis.$headStyle.remove();\n\t\t\tthis.$headStyle = null;\n\t\t}\n\t},\n\t/** (Re)Create jQuery UI Menu. */\n\t_createUiMenu: function(menuDef) {\n\t\tvar ct, ed,\n\t\t\topts = this.options;\n\n\t\t// Remove temporary <ul> if any\n\t\tif (this.isOpen()) {\n\t\t\t// #58: 'replaceMenu' in beforeOpen causing select: to lose ui.target\n\t\t\tct = this.currentTarget;\n\t\t\ted = this.extraData;\n\t\t\t// close without animation, to force async mode\n\t\t\tthis._closeMenu(true);\n\t\t\tthis.currentTarget = ct;\n\t\t\tthis.extraData = ed;\n\t\t}\n\t\tif (this.menuIsTemp) {\n\t\t\tthis.$menu.remove(); // this will also destroy ui.menu\n\t\t} else if (this.$menu) {\n\t\t\tthis.$menu\n\t\t\t\t.menu(\"destroy\")\n\t\t\t\t.removeClass(this.options.addClass)\n\t\t\t\t.hide();\n\t\t}\n\t\tthis.$menu = null;\n\t\tthis.menuIsTemp = false;\n\t\t// If a menu definition array was passed, create a hidden <ul>\n\t\t// and generate the structure now\n\t\tif ( !menuDef ) {\n\t\t\treturn;\n\t\t} else if ($.isArray(menuDef)) {\n\t\t\tthis.$menu = $.moogle.contextmenu.createMenuMarkup(menuDef);\n\t\t\tthis.menuIsTemp = true;\n\t\t}else if ( typeof menuDef === \"string\" ) {\n\t\t\tthis.$menu = $(menuDef);\n\t\t} else {\n\t\t\tthis.$menu = menuDef;\n\t\t}\n\t\t// Create - but hide - the jQuery UI Menu widget\n\t\tthis.$menu\n\t\t\t.hide()\n\t\t\t.addClass(opts.addClass)\n\t\t\t// Create a menu instance that delegates events to our widget\n\t\t\t.menu($.extend(true, {}, opts.uiMenuOptions, {\n\t\t\t\titems: \"> :not(.ui-widget-header)\",\n\t\t\t\tblur: $.proxy(opts.blur, this),\n\t\t\t\tcreate: $.proxy(opts.createMenu, this),\n\t\t\t\tfocus: $.proxy(opts.focus, this),\n\t\t\t\tselect: $.proxy(function(event, ui) {\n\t\t\t\t\t// User selected a menu entry\n\t\t\t\t\tvar retval,\n\t\t\t\t\t\tisParent = $.moogle.contextmenu.isMenu(ui.item),\n\t\t\t\t\t\tactionHandler = ui.item.data(\"actionHandler\");\n\n\t\t\t\t\tui.cmd = ui.item.attr(\"data-command\");\n\t\t\t\t\tui.target = $(this.currentTarget);\n\t\t\t\t\tui.extraData = this.extraData;\n\t\t\t\t\t// ignore clicks, if they only open a sub-menu\n\t\t\t\t\tif ( !isParent || !opts.ignoreParentSelect) {\n\t\t\t\t\t\tretval = this._trigger.call(this, \"select\", event, ui);\n\t\t\t\t\t\tif ( actionHandler ) {\n\t\t\t\t\t\t\tretval = actionHandler.call(this, event, ui);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( retval !== false ) {\n\t\t\t\t\t\t\tthis._closeMenu.call(this);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t}\n\t\t\t\t}, this)\n\t\t\t}));\n\t},\n\t/** Open popup (called on 'contextmenu' event). */\n\t_openMenu: function(event, recursive) {\n\t\tvar res, promise, ui,\n\t\t\topts = this.options,\n\t\t\tposOption = opts.position,\n\t\t\tself = this,\n\t\t\tmanualTrigger = !!event.isTrigger;\n\n\t\tif ( !opts.autoTrigger && !manualTrigger ) {\n\t\t\t// ignore browser's `contextmenu` events\n\t\t\treturn;\n\t\t}\n\t\t// Prevent browser from opening the system context menu\n\t\tevent.preventDefault();\n\n\t\tthis.currentTarget = event.target;\n\t\tthis.extraData = event._extraData || {};\n\n\t\tui = { menu: this.$menu, target: $(this.currentTarget), extraData: this.extraData,\n\t\t\t   originalEvent: event, result: null };\n\n\t\tif ( !recursive ) {\n\t\t\tres = this._trigger(\"beforeOpen\", event, ui);\n\t\t\tpromise = (ui.result && $.isFunction(ui.result.promise)) ? ui.result : null;\n\t\t\tui.result = null;\n\t\t\tif ( res === false ) {\n\t\t\t\tthis.currentTarget = null;\n\t\t\t\treturn false;\n\t\t\t} else if ( promise ) {\n\t\t\t\t// Handler returned a Deferred or Promise. Delay menu open until\n\t\t\t\t// the promise is resolved\n\t\t\t\tpromise.done(function() {\n\t\t\t\t\tself._openMenu(event, true);\n\t\t\t\t});\n\t\t\t\tthis.currentTarget = null;\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tui.menu = this.$menu; // Might have changed in beforeOpen\n\t\t}\n\n\t\t// Register global event handlers that close the dropdown-menu\n\t\t$(document).on(\"keydown\" + this.eventNamespace, function(event) {\n\t\t\tif ( event.which === $.ui.keyCode.ESCAPE ) {\n\t\t\t\tself._closeMenu();\n\t\t\t}\n\t\t}).on(\"mousedown\" + this.eventNamespace + \" touchstart\" + this.eventNamespace,\n\t\t\t\tfunction(event) {\n\t\t\t// Close menu when clicked outside menu\n\t\t\tif ( !$(event.target).closest(\".ui-menu-item\").length ) {\n\t\t\t\tself._closeMenu();\n\t\t\t}\n\t\t});\n\t\t$(window).on(\"blur\" + this.eventNamespace, function(event) {\n\t\t\tif ( opts.closeOnWindowBlur ) {\n\t\t\t\tself._closeMenu();\n\t\t\t}\n\t\t});\n\n\t\t// required for custom positioning (issue #18 and #13).\n\t\tif ($.isFunction(posOption)) {\n\t\t\tposOption = posOption(event, ui);\n\t\t}\n\t\tposOption = $.extend({\n\t\t\tmy: \"left top\",\n\t\t\tat: \"left bottom\",\n\t\t\t// if called by 'open' method, event does not have pageX/Y\n\t\t\tof: (event.pageX === undefined) ? event.target : event,\n\t\t\tcollision: \"fit\"\n\t\t}, posOption);\n\n\t\t// Update entry statuses from callbacks\n\t\tthis._updateEntries(this.$menu);\n\n\t\t// Finally display the popup\n\t\tthis.$menu\n\t\t\t.show() // required to fix positioning error\n\t\t\t.css({\n\t\t\t\tposition: \"absolute\",\n\t\t\t\tleft: 0,\n\t\t\t\ttop: 0\n\t\t\t}).position(posOption)\n\t\t\t.hide(); // hide again, so we can apply nice effects\n\n\t\tif ( opts.preventContextMenuForPopup ) {\n\t\t\tthis.$menu.on(\"contextmenu\" + this.eventNamespace, function(event) {\n\t\t\t\tevent.preventDefault();\n\t\t\t});\n\t\t}\n\t\tthis._show(this.$menu, opts.show, function() {\n\t\t\tvar $first;\n\n\t\t\t// Set focus to first active menu entry\n\t\t\tif ( opts.autoFocus ) {\n\t\t\t\tself.previousFocus = $(event.target);\n\t\t\t\t// self.$menu.focus();\n\t\t\t\t$first = self.$menu\n\t\t\t\t\t.children(\"li.ui-menu-item\")\n\t\t\t\t\t.not(\".ui-state-disabled\")\n\t\t\t\t\t.first();\n\t\t\t\tself.$menu.menu(\"focus\", null, $first).focus();\n\t\t\t}\n\t\t\tself._trigger.call(self, \"open\", event, ui);\n\t\t});\n\t},\n\t/** Close popup. */\n\t_closeMenu: function(immediately) {\n\t\tvar self = this,\n\t\t\thideOpts = immediately ? false : this.options.hide,\n\t\t\tui = { menu: this.$menu, target: $(this.currentTarget), extraData: this.extraData };\n\n\t\t// Note: we don't want to unbind the 'contextmenu' event\n\t\t$(document)\n\t\t\t.off(\"mousedown\" + this.eventNamespace)\n\t\t\t.off(\"touchstart\" + this.eventNamespace)\n\t\t\t.off(\"keydown\" + this.eventNamespace);\n\t\t$(window)\n\t\t\t.off(\"blur\" + this.eventNamespace);\n\n\t\tself.currentTarget = null; // issue #44 after hide animation is too late\n\t\tself.extraData = {};\n\t\tif ( this.$menu ) { // #88: widget might have been destroyed already\n\t\t\tthis.$menu\n\t\t\t\t.off(\"contextmenu\" + this.eventNamespace);\n\t\t\tthis._hide(this.$menu, hideOpts, function() {\n\t\t\t\tif ( self.previousFocus ) {\n\t\t\t\t\tself.previousFocus.focus();\n\t\t\t\t\tself.previousFocus = null;\n\t\t\t\t}\n\t\t\t\tself._trigger(\"close\", null, ui);\n\t\t\t});\n\t\t} else {\n\t\t\tself._trigger(\"close\", null, ui);\n\t\t}\n\t},\n\t/** Handle $().contextmenu(\"option\", key, value) calls. */\n\t_setOption: function(key, value) {\n\t\tswitch (key) {\n\t\tcase \"menu\":\n\t\t\tthis.replaceMenu(value);\n\t\t\tbreak;\n\t\t}\n\t\t$.Widget.prototype._setOption.apply(this, arguments);\n\t},\n\t/** Return ui-menu entry (<LI> tag). */\n\t_getMenuEntry: function(cmd) {\n\t\treturn this.$menu.find(\"li[data-command=\" + cmd + \"]\");\n\t},\n\t/** Close context menu. */\n\tclose: function() {\n\t\tif (this.isOpen()) {\n\t\t\tthis._closeMenu();\n\t\t}\n\t},\n\t/* Apply status callbacks when menu is opened. */\n\t_updateEntries: function() {\n\t\tvar self = this,\n\t\t\tui = {\n\t\t\t\tmenu: this.$menu, target: $(this.currentTarget), extraData: this.extraData };\n\n\t\t$.each(this.$menu.find(\".ui-menu-item\"), function(i, o) {\n\t\t\tvar $entry = $(o),\n\t\t\t\tfn = $entry.data(\"disabledHandler\"),\n\t\t\t\tres = fn ? fn({ type: \"disabled\" }, ui) : null;\n\n\t\t\tui.item = $entry;\n\t\t\tui.cmd = $entry.attr(\"data-command\");\n\t\t\t// Evaluate `disabled()` callback\n\t\t\tif ( res != null ) {\n\t\t\t\tself.enableEntry(ui.cmd, !res);\n\t\t\t\tself.showEntry(ui.cmd, res !== \"hide\");\n\t\t\t}\n\t\t\t// Evaluate `title()` callback\n\t\t\tfn = $entry.data(\"titleHandler\"),\n\t\t\tres = fn ? fn({ type: \"title\" }, ui) : null;\n\t\t\tif ( res != null ) {\n\t\t\t\tself.setTitle(ui.cmd, \"\" + res);\n\t\t\t}\n\t\t\t// Evaluate `tooltip()` callback\n\t\t\tfn = $entry.data(\"tooltipHandler\"),\n\t\t\tres = fn ? fn({ type: \"tooltip\" }, ui) : null;\n\t\t\tif ( res != null ) {\n\t\t\t\t$entry.attr(\"title\", \"\" + res);\n\t\t\t}\n\t\t});\n\t},\n\t/** Enable or disable the menu command. */\n\tenableEntry: function(cmd, flag) {\n\t\tthis._getMenuEntry(cmd).toggleClass(\"ui-state-disabled\", (flag === false));\n\t},\n\t/** Return ui-menu entry (LI tag) as jQuery object. */\n\tgetEntry: function(cmd) {\n\t\treturn this._getMenuEntry(cmd);\n\t},\n\t/** Return ui-menu entry wrapper as jQuery object.\n\t\tUI 1.10: this is the <a> tag inside the LI\n\t\tUI 1.11: this is the LI istself\n\t\tUI 1.12: this is the <div> tag inside the LI\n\t */\n\tgetEntryWrapper: function(cmd) {\n\t\treturn this._getMenuEntry(cmd).find(\">[role=menuitem]\").addBack(\"[role=menuitem]\");\n\t},\n\t/** Return Menu element (UL). */\n\tgetMenu: function() {\n\t\treturn this.$menu;\n\t},\n\t/** Return true if menu is open. */\n\tisOpen: function() {\n//            return this.$menu && this.$menu.is(\":visible\");\n\t\treturn !!this.$menu && !!this.currentTarget;\n\t},\n\t/** Open context menu on a specific target (must match options.delegate)\n\t *  Optional `extraData` is passed to event handlers as `ui.extraData`.\n\t */\n\topen: function(targetOrEvent, extraData) {\n\t\t// Fake a 'contextmenu' event\n\t\textraData = extraData || {};\n\n\t\tvar isEvent = (targetOrEvent && targetOrEvent.type && targetOrEvent.target),\n\t\t\tevent =  isEvent ? targetOrEvent : {},\n\t\t\ttarget = isEvent ? targetOrEvent.target : targetOrEvent,\n\t\t\te = jQuery.Event(\"contextmenu\", {\n\t\t\t\ttarget: $(target).get(0),\n\t\t\t\tpageX: event.pageX,\n\t\t\t\tpageY: event.pageY,\n\t\t\t\toriginalEvent: isEvent ? targetOrEvent : undefined,\n\t\t\t\t_extraData: extraData\n\t\t\t});\n\t\treturn this.element.trigger(e);\n\t},\n\t/** Replace the menu altogether. */\n\treplaceMenu: function(data) {\n\t\tthis._createUiMenu(data);\n\t},\n\t/** Redefine a whole menu entry. */\n\tsetEntry: function(cmd, entry) {\n\t\tvar $ul,\n\t\t\t$entryLi = this._getMenuEntry(cmd);\n\n\t\tif (typeof entry === \"string\") {\n\t\t\twindow.console && window.console.warn(\n\t\t\t\t\"setEntry(cmd, t) with a plain string title is deprecated since v1.18.\" +\n\t\t\t\t\"Use setTitle(cmd, '\" + entry + \"') instead.\");\n\t\t\treturn this.setTitle(cmd, entry);\n\t\t}\n\t\t$entryLi.empty();\n\t\tentry.cmd = entry.cmd || cmd;\n\t\t$.moogle.contextmenu.createEntryMarkup(entry, $entryLi);\n\t\tif ($.isArray(entry.children)) {\n\t\t\t$ul = $(\"<ul/>\").appendTo($entryLi);\n\t\t\t$.moogle.contextmenu.createMenuMarkup(entry.children, $ul);\n\t\t}\n\t\t// #110: jQuery UI 1.12: refresh only works when this class is not set:\n\t\t$entryLi.removeClass(\"ui-menu-item\");\n\t\tthis.getMenu().menu(\"refresh\");\n\t},\n\t/** Set icon (pass null to remove). */\n\tsetIcon: function(cmd, icon) {\n\t\treturn this.updateEntry(cmd, { uiIcon: icon });\n\t},\n\t/** Set title. */\n\tsetTitle: function(cmd, title) {\n\t\treturn this.updateEntry(cmd, { title: title });\n\t},\n\t// /** Set tooltip (pass null to remove). */\n\t// setTooltip: function(cmd, tooltip) {\n\t// \tthis._getMenuEntry(cmd).attr(\"title\", tooltip);\n\t// },\n\t/** Show or hide the menu command. */\n\tshowEntry: function(cmd, flag) {\n\t\tthis._getMenuEntry(cmd).toggle(flag !== false);\n\t},\n\t/** Redefine selective attributes of a menu entry. */\n\tupdateEntry: function(cmd, entry) {\n\t\tvar $icon, $wrapper,\n\t\t\t$entryLi = this._getMenuEntry(cmd);\n\n\t\tif ( entry.title !== undefined ) {\n\t\t\t$.moogle.contextmenu.updateTitle($entryLi, \"\" + entry.title);\n\t\t}\n\t\tif ( entry.tooltip !== undefined ) {\n\t\t\tif ( entry.tooltip === null ) {\n\t\t\t\t$entryLi.removeAttr(\"title\");\n\t\t\t} else {\n\t\t\t\t$entryLi.attr(\"title\", entry.tooltip);\n\t\t\t}\n\t\t}\n\t\tif ( entry.uiIcon !== undefined ) {\n\t\t\t$wrapper = this.getEntryWrapper(cmd),\n\t\t\t$icon = $wrapper.find(\"span.ui-icon\").not(\".ui-menu-icon\");\n\t\t\t$icon.remove();\n\t\t\tif ( entry.uiIcon ) {\n\t\t\t\t$wrapper.append($(\"<span class='ui-icon' />\").addClass(entry.uiIcon));\n\t\t\t}\n\t\t}\n\t\tif ( entry.hide !== undefined ) {\n\t\t\t$entryLi.toggle(!entry.hide);\n\t\t} else if ( entry.show !== undefined ) {\n\t\t\t// Note: `show` is an undocumented variant. `hide: false` is preferred\n\t\t\t$entryLi.toggle(!!entry.show);\n\t\t}\n\t\t// if ( entry.isHeader !== undefined ) {\n\t\t// \t$entryLi.toggleClass(\"ui-widget-header\", !!entry.isHeader);\n\t\t// }\n\t\tif ( entry.data !== undefined ) {\n\t\t\t$entryLi.data(entry.data);\n\t\t}\n\n\t\t// Set/clear class names, but handle ui-state-disabled separately\n\t\tif ( entry.disabled === undefined ) {\n\t\t\tentry.disabled = $entryLi.hasClass(\"ui-state-disabled\");\n\t\t}\n\t\tif ( entry.setClass ) {\n\t\t\tif ( $entryLi.hasClass(\"ui-menu-item\") ) {\n\t\t\t\tentry.setClass += \" ui-menu-item\";\n\t\t\t}\n\t\t\t$entryLi.removeClass();\n\t\t\t$entryLi.addClass(entry.setClass);\n\t\t} else if ( entry.addClass ) {\n\t\t\t$entryLi.addClass(entry.addClass);\n\t\t}\n\t\t$entryLi.toggleClass(\"ui-state-disabled\", !!entry.disabled);\n\t\t// // #110: jQuery UI 1.12: refresh only works when this class is not set:\n\t\t// $entryLi.removeClass(\"ui-menu-item\");\n\t\t// this.getMenu().menu(\"refresh\");\n\t}\n});\n\n/*\n * Global functions\n */\n$.extend($.moogle.contextmenu, {\n\t/** Convert a menu description into a into a <li> content. */\n\tcreateEntryMarkup: function(entry, $parentLi) {\n\t\tvar $wrapper = null;\n\n\t\t$parentLi.attr(\"data-command\", entry.cmd);\n\n\t\tif ( !/[^\\-\\u2014\\u2013\\s]/.test( entry.title ) ) {\n\t\t\t// hyphen, em dash, en dash: separator as defined by UI Menu 1.10\n\t\t\t$parentLi.text(entry.title);\n\t\t} else {\n\t\t\tif ( isLTE110 ) {\n\t\t\t\t// jQuery UI Menu 1.10 or before required an `<a>` tag\n\t\t\t\t$wrapper = $(\"<a/>\", {\n\t\t\t\t\t\thtml: \"\" + entry.title,\n\t\t\t\t\t\thref: \"#\"\n\t\t\t\t\t}).appendTo($parentLi);\n\n\t\t\t} else if ( isLTE111 ) {\n\t\t\t\t// jQuery UI Menu 1.11 preferes to avoid `<a>` tags or <div> wrapper\n\t\t\t\t$parentLi.html(\"\" + entry.title);\n\t\t\t\t$wrapper = $parentLi;\n\n\t\t\t} else {\n\t\t\t\t// jQuery UI Menu 1.12 introduced `<div>` wrappers\n\t\t\t\t$wrapper = $(\"<div/>\", {\n\t\t\t\t\t\thtml: \"\" + entry.title\n\t\t\t\t\t}).appendTo($parentLi);\n\t\t\t}\n\t\t\tif ( entry.uiIcon ) {\n\t\t\t\t$wrapper.append($(\"<span class='ui-icon' />\").addClass(entry.uiIcon));\n\t\t\t}\n\t\t\t// Store option callbacks in entry's data\n\t\t\t$.each( [ \"action\", \"disabled\", \"title\", \"tooltip\" ], function(i, attr) {\n\t\t\t\tif ( $.isFunction(entry[attr]) ) {\n\t\t\t\t\t$parentLi.data(attr + \"Handler\", entry[attr]);\n\t\t\t\t}\n\t\t\t});\n\t\t\tif ( entry.disabled === true ) {\n\t\t\t\t$parentLi.addClass(\"ui-state-disabled\");\n\t\t\t}\n\t\t\tif ( entry.isHeader ) {\n\t\t\t\t$parentLi.addClass(\"ui-widget-header\");\n\t\t\t}\n\t\t\tif ( entry.addClass ) {\n\t\t\t\t$parentLi.addClass(entry.addClass);\n\t\t\t}\n\t\t\tif ( $.isPlainObject(entry.data) ) {\n\t\t\t\t$parentLi.data(entry.data);\n\t\t\t}\n\t\t\tif ( typeof entry.tooltip === \"string\" ) {\n\t\t\t\t$parentLi.attr(\"title\", entry.tooltip);\n\t\t\t}\n\t\t}\n\t},\n\t/** Convert a nested array of command objects into a <ul> structure. */\n\tcreateMenuMarkup: function(options, $parentUl) {\n\t\tvar i, menu, $ul, $li;\n\t\tif ( $parentUl == null ) {\n\t\t\t$parentUl = $(\"<ul class='ui-helper-hidden' />\").appendTo(\"body\");\n\t\t}\n\t\tfor (i = 0; i < options.length; i++) {\n\t\t\tmenu = options[i];\n\t\t\t$li = $(\"<li/>\").appendTo($parentUl);\n\n\t\t\t$.moogle.contextmenu.createEntryMarkup(menu, $li);\n\n\t\t\tif ( $.isArray(menu.children) ) {\n\t\t\t\t$ul = $(\"<ul/>\").appendTo($li);\n\t\t\t\t$.moogle.contextmenu.createMenuMarkup(menu.children, $ul);\n\t\t\t}\n\t\t}\n\t\treturn $parentUl;\n\t},\n\t/** Returns true if the menu item has child menu items */\n\tisMenu: function(item) {\n\t\tif ( isLTE110 ) {\n\t\t\treturn item.has(\">a[aria-haspopup='true']\").length > 0;\n\t\t} else if ( isLTE111 ) {  // jQuery UI 1.11 used no tag wrappers\n\t\t\treturn item.is(\"[aria-haspopup='true']\");\n\t\t} else {\n\t\t\treturn item.has(\">div[aria-haspopup='true']\").length > 0;\n\t\t}\n\t},\n\t/** Replace the title of elem', but retain icons andchild entries. */\n\treplaceFirstTextNodeChild: function(elem, html) {\n\t\tvar $icons = elem.find(\">span.ui-icon,>ul.ui-menu\").detach();\n\n\t\telem\n\t\t\t.empty()\n\t\t\t.html(html)\n\t\t\t.append($icons);\n\t},\n\t/** Updates the menu item's title */\n\tupdateTitle: function(item, title) {\n\t\tif ( isLTE110 ) {  // jQuery UI 1.10 and before used <a> tags\n\t\t\t$.moogle.contextmenu.replaceFirstTextNodeChild($(\"a\", item), title);\n\t\t} else if ( isLTE111 ) {  // jQuery UI 1.11 used no tag wrappers\n\t\t\t$.moogle.contextmenu.replaceFirstTextNodeChild(item, title);\n\t\t} else {  // jQuery UI 1.12+ introduced <div> tag wrappers\n\t\t\t$.moogle.contextmenu.replaceFirstTextNodeChild($(\"div\", item), title);\n\t\t}\n\t}\n});\n\n}));\n"
  },
  {
    "path": "cyacas/packaging/deb/missing-sources/plotly-1.49.0.js",
    "content": "/**\n* plotly.js v1.49.0\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n* Licensed under the MIT license\n*/\n(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}g.Plotly = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){\n'use strict';\n\nvar Lib = _dereq_('../src/lib');\nvar rules = {\n    \"X,X div\": \"direction:ltr;font-family:'Open Sans', verdana, arial, sans-serif;margin:0;padding:0;\",\n    \"X input,X button\": \"font-family:'Open Sans', verdana, arial, sans-serif;\",\n    \"X input:focus,X button:focus\": \"outline:none;\",\n    \"X a\": \"text-decoration:none;\",\n    \"X a:hover\": \"text-decoration:none;\",\n    \"X .crisp\": \"shape-rendering:crispEdges;\",\n    \"X .user-select-none\": \"-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;\",\n    \"X svg\": \"overflow:hidden;\",\n    \"X svg a\": \"fill:#447adb;\",\n    \"X svg a:hover\": \"fill:#3c6dc5;\",\n    \"X .main-svg\": \"position:absolute;top:0;left:0;pointer-events:none;\",\n    \"X .main-svg .draglayer\": \"pointer-events:all;\",\n    \"X .cursor-default\": \"cursor:default;\",\n    \"X .cursor-pointer\": \"cursor:pointer;\",\n    \"X .cursor-crosshair\": \"cursor:crosshair;\",\n    \"X .cursor-move\": \"cursor:move;\",\n    \"X .cursor-col-resize\": \"cursor:col-resize;\",\n    \"X .cursor-row-resize\": \"cursor:row-resize;\",\n    \"X .cursor-ns-resize\": \"cursor:ns-resize;\",\n    \"X .cursor-ew-resize\": \"cursor:ew-resize;\",\n    \"X .cursor-sw-resize\": \"cursor:sw-resize;\",\n    \"X .cursor-s-resize\": \"cursor:s-resize;\",\n    \"X .cursor-se-resize\": \"cursor:se-resize;\",\n    \"X .cursor-w-resize\": \"cursor:w-resize;\",\n    \"X .cursor-e-resize\": \"cursor:e-resize;\",\n    \"X .cursor-nw-resize\": \"cursor:nw-resize;\",\n    \"X .cursor-n-resize\": \"cursor:n-resize;\",\n    \"X .cursor-ne-resize\": \"cursor:ne-resize;\",\n    \"X .cursor-grab\": \"cursor:-webkit-grab;cursor:grab;\",\n    \"X .modebar\": \"position:absolute;top:2px;right:2px;\",\n    \"X .ease-bg\": \"-webkit-transition:background-color 0.3s ease 0s;-moz-transition:background-color 0.3s ease 0s;-ms-transition:background-color 0.3s ease 0s;-o-transition:background-color 0.3s ease 0s;transition:background-color 0.3s ease 0s;\",\n    \"X .modebar--hover>:not(.watermark)\": \"opacity:0;-webkit-transition:opacity 0.3s ease 0s;-moz-transition:opacity 0.3s ease 0s;-ms-transition:opacity 0.3s ease 0s;-o-transition:opacity 0.3s ease 0s;transition:opacity 0.3s ease 0s;\",\n    \"X:hover .modebar--hover .modebar-group\": \"opacity:1;\",\n    \"X .modebar-group\": \"float:left;display:inline-block;box-sizing:border-box;padding-left:8px;position:relative;vertical-align:middle;white-space:nowrap;\",\n    \"X .modebar-btn\": \"position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;\",\n    \"X .modebar-btn svg\": \"position:relative;top:2px;\",\n    \"X .modebar.vertical\": \"display:flex;flex-direction:column;flex-wrap:wrap;align-content:flex-end;max-height:100%;\",\n    \"X .modebar.vertical svg\": \"top:-1px;\",\n    \"X .modebar.vertical .modebar-group\": \"display:block;float:none;padding-left:0px;padding-bottom:8px;\",\n    \"X .modebar.vertical .modebar-group .modebar-btn\": \"display:block;text-align:center;\",\n    \"X [data-title]:before,X [data-title]:after\": \"position:absolute;-webkit-transform:translate3d(0, 0, 0);-moz-transform:translate3d(0, 0, 0);-ms-transform:translate3d(0, 0, 0);-o-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);display:none;opacity:0;z-index:1001;pointer-events:none;top:110%;right:50%;\",\n    \"X [data-title]:hover:before,X [data-title]:hover:after\": \"display:block;opacity:1;\",\n    \"X [data-title]:before\": \"content:'';position:absolute;background:transparent;border:6px solid transparent;z-index:1002;margin-top:-12px;border-bottom-color:#69738a;margin-right:-6px;\",\n    \"X [data-title]:after\": \"content:attr(data-title);background:#69738a;color:white;padding:8px 10px;font-size:12px;line-height:12px;white-space:nowrap;margin-right:-18px;border-radius:2px;\",\n    \"X .vertical [data-title]:before,X .vertical [data-title]:after\": \"top:0%;right:200%;\",\n    \"X .vertical [data-title]:before\": \"border:6px solid transparent;border-left-color:#69738a;margin-top:8px;margin-right:-30px;\",\n    \"X .select-outline\": \"fill:none;stroke-width:1;shape-rendering:crispEdges;\",\n    \"X .select-outline-1\": \"stroke:white;\",\n    \"X .select-outline-2\": \"stroke:black;stroke-dasharray:2px 2px;\",\n    Y: \"font-family:'Open Sans';position:fixed;top:50px;right:20px;z-index:10000;font-size:10pt;max-width:180px;\",\n    \"Y p\": \"margin:0;\",\n    \"Y .notifier-note\": \"min-width:180px;max-width:250px;border:1px solid #fff;z-index:3000;margin:0;background-color:#8c97af;background-color:rgba(140,151,175,0.9);color:#fff;padding:10px;overflow-wrap:break-word;word-wrap:break-word;-ms-hyphens:auto;-webkit-hyphens:auto;hyphens:auto;\",\n    \"Y .notifier-close\": \"color:#fff;opacity:0.8;float:right;padding:0 5px;background:none;border:none;font-size:20px;font-weight:bold;line-height:20px;\",\n    \"Y .notifier-close:hover\": \"color:#444;text-decoration:none;cursor:pointer;\"\n};\n\nfor(var selector in rules) {\n    var fullSelector = selector.replace(/^,/,' ,')\n        .replace(/X/g, '.js-plotly-plot .plotly')\n        .replace(/Y/g, '.plotly-notifier');\n    Lib.addStyleRule(fullSelector, rules[selector]);\n}\n\n},{\"../src/lib\":719}],2:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/transforms/aggregate');\n\n},{\"../src/transforms/aggregate\":1265}],3:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/bar');\n\n},{\"../src/traces/bar\":864}],4:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/barpolar');\n\n},{\"../src/traces/barpolar\":876}],5:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/box');\n\n},{\"../src/traces/box\":886}],6:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/components/calendars');\n\n},{\"../src/components/calendars\":591}],7:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/candlestick');\n\n},{\"../src/traces/candlestick\":895}],8:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/carpet');\n\n},{\"../src/traces/carpet\":914}],9:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/choropleth');\n\n},{\"../src/traces/choropleth\":928}],10:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/choroplethmapbox');\n\n},{\"../src/traces/choroplethmapbox\":935}],11:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/cone');\n\n},{\"../src/traces/cone\":941}],12:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/contour');\n\n},{\"../src/traces/contour\":956}],13:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/contourcarpet');\n\n},{\"../src/traces/contourcarpet\":967}],14:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/core');\n\n},{\"../src/core\":697}],15:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/densitymapbox');\n\n},{\"../src/traces/densitymapbox\":977}],16:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/transforms/filter');\n\n},{\"../src/transforms/filter\":1266}],17:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/funnel');\n\n},{\"../src/traces/funnel\":987}],18:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/funnelarea');\n\n},{\"../src/traces/funnelarea\":996}],19:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/transforms/groupby');\n\n},{\"../src/transforms/groupby\":1267}],20:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/heatmap');\n\n},{\"../src/traces/heatmap\":1009}],21:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/heatmapgl');\n\n},{\"../src/traces/heatmapgl\":1018}],22:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/histogram');\n\n},{\"../src/traces/histogram\":1030}],23:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/histogram2d');\n\n},{\"../src/traces/histogram2d\":1036}],24:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/histogram2dcontour');\n\n},{\"../src/traces/histogram2dcontour\":1040}],25:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Plotly = _dereq_('./core');\n\n// traces\nPlotly.register([\n    _dereq_('./bar'),\n    _dereq_('./box'),\n    _dereq_('./heatmap'),\n    _dereq_('./histogram'),\n    _dereq_('./histogram2d'),\n    _dereq_('./histogram2dcontour'),\n    _dereq_('./contour'),\n    _dereq_('./scatterternary'),\n    _dereq_('./violin'),\n    _dereq_('./funnel'),\n    _dereq_('./waterfall'),\n\n    _dereq_('./pie'),\n    _dereq_('./sunburst'),\n    _dereq_('./funnelarea'),\n\n    _dereq_('./scatter3d'),\n    _dereq_('./surface'),\n    _dereq_('./isosurface'),\n    _dereq_('./volume'),\n    _dereq_('./mesh3d'),\n    _dereq_('./cone'),\n    _dereq_('./streamtube'),\n\n    _dereq_('./scattergeo'),\n    _dereq_('./choropleth'),\n\n    _dereq_('./scattergl'),\n    _dereq_('./splom'),\n\n    _dereq_('./pointcloud'),\n    _dereq_('./heatmapgl'),\n\n    _dereq_('./parcoords'),\n\n    _dereq_('./parcats'),\n\n    _dereq_('./scattermapbox'),\n    _dereq_('./choroplethmapbox'),\n    _dereq_('./densitymapbox'),\n\n    _dereq_('./sankey'),\n    _dereq_('./indicator'),\n\n    _dereq_('./table'),\n\n    _dereq_('./carpet'),\n    _dereq_('./scattercarpet'),\n    _dereq_('./contourcarpet'),\n\n    _dereq_('./ohlc'),\n    _dereq_('./candlestick'),\n\n    _dereq_('./scatterpolar'),\n    _dereq_('./scatterpolargl'),\n    _dereq_('./barpolar')\n]);\n\n// transforms\n//\n// Please note that all *transform* methods are executed before\n// all *calcTransform* methods - which could possibly lead to\n// unexpected results when applying multiple transforms of different types\n// to a given trace.\n//\n// For more info, see:\n// https://github.com/plotly/plotly.js/pull/978#pullrequestreview-2403353\n//\nPlotly.register([\n    _dereq_('./aggregate'),\n    _dereq_('./filter'),\n    _dereq_('./groupby'),\n    _dereq_('./sort')\n]);\n\n// components\nPlotly.register([\n    _dereq_('./calendars')\n]);\n\nmodule.exports = Plotly;\n\n},{\"./aggregate\":2,\"./bar\":3,\"./barpolar\":4,\"./box\":5,\"./calendars\":6,\"./candlestick\":7,\"./carpet\":8,\"./choropleth\":9,\"./choroplethmapbox\":10,\"./cone\":11,\"./contour\":12,\"./contourcarpet\":13,\"./core\":14,\"./densitymapbox\":15,\"./filter\":16,\"./funnel\":17,\"./funnelarea\":18,\"./groupby\":19,\"./heatmap\":20,\"./heatmapgl\":21,\"./histogram\":22,\"./histogram2d\":23,\"./histogram2dcontour\":24,\"./indicator\":26,\"./isosurface\":27,\"./mesh3d\":28,\"./ohlc\":29,\"./parcats\":30,\"./parcoords\":31,\"./pie\":32,\"./pointcloud\":33,\"./sankey\":34,\"./scatter3d\":35,\"./scattercarpet\":36,\"./scattergeo\":37,\"./scattergl\":38,\"./scattermapbox\":39,\"./scatterpolar\":40,\"./scatterpolargl\":41,\"./scatterternary\":42,\"./sort\":43,\"./splom\":44,\"./streamtube\":45,\"./sunburst\":46,\"./surface\":47,\"./table\":48,\"./violin\":49,\"./volume\":50,\"./waterfall\":51}],26:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/indicator');\n\n},{\"../src/traces/indicator\":1046}],27:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/isosurface');\n\n},{\"../src/traces/isosurface\":1052}],28:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/mesh3d');\n\n},{\"../src/traces/mesh3d\":1057}],29:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/ohlc');\n\n},{\"../src/traces/ohlc\":1062}],30:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/parcats');\n\n},{\"../src/traces/parcats\":1071}],31:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/parcoords');\n\n},{\"../src/traces/parcoords\":1081}],32:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/pie');\n\n},{\"../src/traces/pie\":1092}],33:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/pointcloud');\n\n},{\"../src/traces/pointcloud\":1101}],34:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/sankey');\n\n},{\"../src/traces/sankey\":1107}],35:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/scatter3d');\n\n},{\"../src/traces/scatter3d\":1143}],36:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/scattercarpet');\n\n},{\"../src/traces/scattercarpet\":1149}],37:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/scattergeo');\n\n},{\"../src/traces/scattergeo\":1156}],38:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/scattergl');\n\n},{\"../src/traces/scattergl\":1167}],39:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/scattermapbox');\n\n},{\"../src/traces/scattermapbox\":1176}],40:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/scatterpolar');\n\n},{\"../src/traces/scatterpolar\":1183}],41:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/scatterpolargl');\n\n},{\"../src/traces/scatterpolargl\":1189}],42:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/scatterternary');\n\n},{\"../src/traces/scatterternary\":1196}],43:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/transforms/sort');\n\n},{\"../src/transforms/sort\":1269}],44:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/splom');\n\n},{\"../src/traces/splom\":1205}],45:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/streamtube');\n\n},{\"../src/traces/streamtube\":1213}],46:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/sunburst');\n\n},{\"../src/traces/sunburst\":1219}],47:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/surface');\n\n},{\"../src/traces/surface\":1228}],48:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/table');\n\n},{\"../src/traces/table\":1236}],49:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/violin');\n\n},{\"../src/traces/violin\":1244}],50:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/volume');\n\n},{\"../src/traces/volume\":1252}],51:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = _dereq_('../src/traces/waterfall');\n\n},{\"../src/traces/waterfall\":1260}],52:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createViewController\n\nvar createTurntable = _dereq_('turntable-camera-controller')\nvar createOrbit     = _dereq_('orbit-camera-controller')\nvar createMatrix    = _dereq_('matrix-camera-controller')\n\nfunction ViewController(controllers, mode) {\n  this._controllerNames = Object.keys(controllers)\n  this._controllerList = this._controllerNames.map(function(n) {\n    return controllers[n]\n  })\n  this._mode   = mode\n  this._active = controllers[mode]\n  if(!this._active) {\n    this._mode   = 'turntable'\n    this._active = controllers.turntable\n  }\n  this.modes = this._controllerNames\n  this.computedMatrix = this._active.computedMatrix\n  this.computedEye    = this._active.computedEye\n  this.computedUp     = this._active.computedUp\n  this.computedCenter = this._active.computedCenter\n  this.computedRadius = this._active.computedRadius\n}\n\nvar proto = ViewController.prototype\n\nvar COMMON_METHODS = [\n  ['flush', 1],\n  ['idle', 1],\n  ['lookAt', 4],\n  ['rotate', 4],\n  ['pan', 4],\n  ['translate', 4],\n  ['setMatrix', 2],\n  ['setDistanceLimits', 2],\n  ['setDistance', 2]\n]\n\nCOMMON_METHODS.forEach(function(method) {\n  var name = method[0]\n  var argNames = []\n  for(var i=0; i<method[1]; ++i) {\n    argNames.push('a'+i)\n  }\n  var code = 'var cc=this._controllerList;for(var i=0;i<cc.length;++i){cc[i].'+method[0]+'('+argNames.join()+')}'\n  proto[name] = Function.apply(null, argNames.concat(code))\n})\n\nproto.recalcMatrix = function(t) {\n  this._active.recalcMatrix(t)\n}\n\nproto.getDistance = function(t) {\n  return this._active.getDistance(t)\n}\nproto.getDistanceLimits = function(out) {\n  return this._active.getDistanceLimits(out)\n}\n\nproto.lastT = function() {\n  return this._active.lastT()\n}\n\nproto.setMode = function(mode) {\n  if(mode === this._mode) {\n    return\n  }\n  var idx = this._controllerNames.indexOf(mode)\n  if(idx < 0) {\n    return\n  }\n  var prev  = this._active\n  var next  = this._controllerList[idx]\n  var lastT = Math.max(prev.lastT(), next.lastT())\n\n  prev.recalcMatrix(lastT)\n  next.setMatrix(lastT, prev.computedMatrix)\n  \n  this._active = next\n  this._mode   = mode\n\n  //Update matrix properties\n  this.computedMatrix = this._active.computedMatrix\n  this.computedEye    = this._active.computedEye\n  this.computedUp     = this._active.computedUp\n  this.computedCenter = this._active.computedCenter\n  this.computedRadius = this._active.computedRadius\n}\n\nproto.getMode = function() {\n  return this._mode\n}\n\nfunction createViewController(options) {\n  options = options || {}\n\n  var eye       = options.eye    || [0,0,1]\n  var center    = options.center || [0,0,0]\n  var up        = options.up     || [0,1,0]\n  var limits    = options.distanceLimits || [0, Infinity]\n  var mode      = options.mode   || 'turntable'\n\n  var turntable = createTurntable()\n  var orbit     = createOrbit()\n  var matrix    = createMatrix()\n\n  turntable.setDistanceLimits(limits[0], limits[1])\n  turntable.lookAt(0, eye, center, up)\n  orbit.setDistanceLimits(limits[0], limits[1])\n  orbit.lookAt(0, eye, center, up)\n  matrix.setDistanceLimits(limits[0], limits[1])\n  matrix.lookAt(0, eye, center, up)\n\n  return new ViewController({\n    turntable: turntable,\n    orbit: orbit,\n    matrix: matrix\n  }, mode)\n}\n},{\"matrix-camera-controller\":433,\"orbit-camera-controller\":456,\"turntable-camera-controller\":542}],53:[function(_dereq_,module,exports){\n(function (global, factory) {\n  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, _dereq_('d3-array'), _dereq_('d3-collection'), _dereq_('d3-shape'), _dereq_('elementary-circuits-directed-graph')) :\n  typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-collection', 'd3-shape', 'elementary-circuits-directed-graph'], factory) :\n  (factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,null));\n}(this, (function (exports,d3Array,d3Collection,d3Shape,findCircuits) { 'use strict';\n\n  findCircuits = findCircuits && findCircuits.hasOwnProperty('default') ? findCircuits['default'] : findCircuits;\n\n  // For a given link, return the target node's depth\n  function targetDepth(d) {\n    return d.target.depth;\n  }\n\n  // The depth of a node when the nodeAlign (align) is set to 'left'\n  function left(node) {\n    return node.depth;\n  }\n\n  // The depth of a node when the nodeAlign (align) is set to 'right'\n  function right(node, n) {\n    return n - 1 - node.height;\n  }\n\n  // The depth of a node when the nodeAlign (align) is set to 'justify'\n  function justify(node, n) {\n    return node.sourceLinks.length ? node.depth : n - 1;\n  }\n\n  // The depth of a node when the nodeAlign (align) is set to 'center'\n  function center(node) {\n    return node.targetLinks.length ? node.depth : node.sourceLinks.length ? d3Array.min(node.sourceLinks, targetDepth) - 1 : 0;\n  }\n\n  // returns a function, using the parameter given to the sankey setting\n  function constant(x) {\n    return function () {\n      return x;\n    };\n  }\n\n  var _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) {\n    return typeof obj;\n  } : function (obj) {\n    return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n  };\n\n  /// https://github.com/tomshanley/d3-sankeyCircular-circular\n\n  // sort links' breadth (ie top to bottom in a column), based on their source nodes' breadths\n  function ascendingSourceBreadth(a, b) {\n    return ascendingBreadth(a.source, b.source) || a.index - b.index;\n  }\n\n  // sort links' breadth (ie top to bottom in a column), based on their target nodes' breadths\n  function ascendingTargetBreadth(a, b) {\n    return ascendingBreadth(a.target, b.target) || a.index - b.index;\n  }\n\n  // sort nodes' breadth (ie top to bottom in a column)\n  // if both nodes have circular links, or both don't have circular links, then sort by the top (y0) of the node\n  // else push nodes that have top circular links to the top, and nodes that have bottom circular links to the bottom\n  function ascendingBreadth(a, b) {\n    if (a.partOfCycle === b.partOfCycle) {\n      return a.y0 - b.y0;\n    } else {\n      if (a.circularLinkType === 'top' || b.circularLinkType === 'bottom') {\n        return -1;\n      } else {\n        return 1;\n      }\n    }\n  }\n\n  // return the value of a node or link\n  function value(d) {\n    return d.value;\n  }\n\n  // return the vertical center of a node\n  function nodeCenter(node) {\n    return (node.y0 + node.y1) / 2;\n  }\n\n  // return the vertical center of a link's source node\n  function linkSourceCenter(link) {\n    return nodeCenter(link.source);\n  }\n\n  // return the vertical center of a link's target node\n  function linkTargetCenter(link) {\n    return nodeCenter(link.target);\n  }\n\n  // Return the default value for ID for node, d.index\n  function defaultId(d) {\n    return d.index;\n  }\n\n  // Return the default object the graph's nodes, graph.nodes\n  function defaultNodes(graph) {\n    return graph.nodes;\n  }\n\n  // Return the default object the graph's nodes, graph.links\n  function defaultLinks(graph) {\n    return graph.links;\n  }\n\n  // Return the node from the collection that matches the provided ID, or throw an error if no match\n  function find(nodeById, id) {\n    var node = nodeById.get(id);\n    if (!node) throw new Error('missing: ' + id);\n    return node;\n  }\n\n  function getNodeID(node, id) {\n    return id(node);\n  }\n\n  // The main sankeyCircular functions\n\n  // Some constants for circular link calculations\n  var verticalMargin = 25;\n  var baseRadius = 10;\n  var scale = 0.3; //Possibly let user control this, although anything over 0.5 starts to get too cramped\n\n  function sankeyCircular () {\n    // Set the default values\n    var x0 = 0,\n        y0 = 0,\n        x1 = 1,\n        y1 = 1,\n        // extent\n    dx = 24,\n        // nodeWidth\n    py,\n        // nodePadding, for vertical postioning\n    id = defaultId,\n        align = justify,\n        nodes = defaultNodes,\n        links = defaultLinks,\n        iterations = 32,\n        circularLinkGap = 2,\n        paddingRatio,\n        sortNodes = null;\n\n    function sankeyCircular() {\n      var graph = {\n        nodes: nodes.apply(null, arguments),\n        links: links.apply(null, arguments)\n\n        // Process the graph's nodes and links, setting their positions\n\n        // 1.  Associate the nodes with their respective links, and vice versa\n      };computeNodeLinks(graph);\n\n      // 2.  Determine which links result in a circular path in the graph\n      identifyCircles(graph, id, sortNodes);\n\n      // 4. Calculate the nodes' values, based on the values of the incoming and outgoing links\n      computeNodeValues(graph);\n\n      // 5.  Calculate the nodes' depth based on the incoming and outgoing links\n      //     Sets the nodes':\n      //     - depth:  the depth in the graph\n      //     - column: the depth (0, 1, 2, etc), as is relates to visual position from left to right\n      //     - x0, x1: the x coordinates, as is relates to visual position from left to right\n      computeNodeDepths(graph);\n\n      // 3.  Determine how the circular links will be drawn,\n      //     either travelling back above the main chart (\"top\")\n      //     or below the main chart (\"bottom\")\n      selectCircularLinkTypes(graph, id);\n\n      // 6.  Calculate the nodes' and links' vertical position within their respective column\n      //     Also readjusts sankeyCircular size if circular links are needed, and node x's\n      computeNodeBreadths(graph, iterations, id);\n      computeLinkBreadths(graph);\n\n      // 7.  Sort links per node, based on the links' source/target nodes' breadths\n      // 8.  Adjust nodes that overlap links that span 2+ columns\n      var linkSortingIterations = 4; //Possibly let user control this number, like the iterations over node placement\n      for (var iteration = 0; iteration < linkSortingIterations; iteration++) {\n\n        sortSourceLinks(graph, y1, id);\n        sortTargetLinks(graph, y1, id);\n        resolveNodeLinkOverlaps(graph, y0, y1, id);\n        sortSourceLinks(graph, y1, id);\n        sortTargetLinks(graph, y1, id);\n      }\n\n      // 8.1  Adjust node and link positions back to fill height of chart area if compressed\n      fillHeight(graph, y0, y1);\n\n      // 9. Calculate visually appealling path for the circular paths, and create the \"d\" string\n      addCircularPathData(graph, circularLinkGap, y1, id);\n\n      return graph;\n    } // end of sankeyCircular function\n\n\n    // Set the sankeyCircular parameters\n    // nodeID, nodeAlign, nodeWidth, nodePadding, nodes, links, size, extent, iterations, nodePaddingRatio, circularLinkGap\n    sankeyCircular.nodeId = function (_) {\n      return arguments.length ? (id = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : id;\n    };\n\n    sankeyCircular.nodeAlign = function (_) {\n      return arguments.length ? (align = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : align;\n    };\n\n    sankeyCircular.nodeWidth = function (_) {\n      return arguments.length ? (dx = +_, sankeyCircular) : dx;\n    };\n\n    sankeyCircular.nodePadding = function (_) {\n      return arguments.length ? (py = +_, sankeyCircular) : py;\n    };\n\n    sankeyCircular.nodes = function (_) {\n      return arguments.length ? (nodes = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : nodes;\n    };\n\n    sankeyCircular.links = function (_) {\n      return arguments.length ? (links = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : links;\n    };\n\n    sankeyCircular.size = function (_) {\n      return arguments.length ? (x0 = y0 = 0, x1 = +_[0], y1 = +_[1], sankeyCircular) : [x1 - x0, y1 - y0];\n    };\n\n    sankeyCircular.extent = function (_) {\n      return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], sankeyCircular) : [[x0, y0], [x1, y1]];\n    };\n\n    sankeyCircular.iterations = function (_) {\n      return arguments.length ? (iterations = +_, sankeyCircular) : iterations;\n    };\n\n    sankeyCircular.circularLinkGap = function (_) {\n      return arguments.length ? (circularLinkGap = +_, sankeyCircular) : circularLinkGap;\n    };\n\n    sankeyCircular.nodePaddingRatio = function (_) {\n      return arguments.length ? (paddingRatio = +_, sankeyCircular) : paddingRatio;\n    };\n\n    sankeyCircular.sortNodes = function (_) {\n      return arguments.length ? (sortNodes = _, sankeyCircular) : sortNodes;\n    };\n\n    sankeyCircular.update = function (graph) {\n      // 5.  Calculate the nodes' depth based on the incoming and outgoing links\n      //     Sets the nodes':\n      //     - depth:  the depth in the graph\n      //     - column: the depth (0, 1, 2, etc), as is relates to visual position from left to right\n      //     - x0, x1: the x coordinates, as is relates to visual position from left to right\n      // computeNodeDepths(graph)\n\n      // 3.  Determine how the circular links will be drawn,\n      //     either travelling back above the main chart (\"top\")\n      //     or below the main chart (\"bottom\")\n      selectCircularLinkTypes(graph, id);\n\n      // 6.  Calculate the nodes' and links' vertical position within their respective column\n      //     Also readjusts sankeyCircular size if circular links are needed, and node x's\n      // computeNodeBreadths(graph, iterations, id)\n      computeLinkBreadths(graph);\n\n      // Force position of circular link type based on position\n      graph.links.forEach(function (link) {\n        if (link.circular) {\n          link.circularLinkType = link.y0 + link.y1 < y1 ? 'top' : 'bottom';\n\n          link.source.circularLinkType = link.circularLinkType;\n          link.target.circularLinkType = link.circularLinkType;\n        }\n      });\n\n      sortSourceLinks(graph, y1, id, false); // Sort links but do not move nodes\n      sortTargetLinks(graph, y1, id);\n\n      // 7.  Sort links per node, based on the links' source/target nodes' breadths\n      // 8.  Adjust nodes that overlap links that span 2+ columns\n      // var linkSortingIterations = 4; //Possibly let user control this number, like the iterations over node placement\n      // for (var iteration = 0; iteration < linkSortingIterations; iteration++) {\n      //\n      //   sortSourceLinks(graph, y1, id)\n      //   sortTargetLinks(graph, y1, id)\n      //   resolveNodeLinkOverlaps(graph, y0, y1, id)\n      //   sortSourceLinks(graph, y1, id)\n      //   sortTargetLinks(graph, y1, id)\n      //\n      // }\n\n      // 8.1  Adjust node and link positions back to fill height of chart area if compressed\n      // fillHeight(graph, y0, y1)\n\n      // 9. Calculate visually appealling path for the circular paths, and create the \"d\" string\n      addCircularPathData(graph, circularLinkGap, y1, id);\n      return graph;\n    };\n\n    // Populate the sourceLinks and targetLinks for each node.\n    // Also, if the source and target are not objects, assume they are indices.\n    function computeNodeLinks(graph) {\n      graph.nodes.forEach(function (node, i) {\n        node.index = i;\n        node.sourceLinks = [];\n        node.targetLinks = [];\n      });\n      var nodeById = d3Collection.map(graph.nodes, id);\n      graph.links.forEach(function (link, i) {\n        link.index = i;\n        var source = link.source;\n        var target = link.target;\n        if ((typeof source === \"undefined\" ? \"undefined\" : _typeof(source)) !== 'object') {\n          source = link.source = find(nodeById, source);\n        }\n        if ((typeof target === \"undefined\" ? \"undefined\" : _typeof(target)) !== 'object') {\n          target = link.target = find(nodeById, target);\n        }\n        source.sourceLinks.push(link);\n        target.targetLinks.push(link);\n      });\n      return graph;\n    }\n\n    // Compute the value (size) and cycleness of each node by summing the associated links.\n    function computeNodeValues(graph) {\n      graph.nodes.forEach(function (node) {\n        node.partOfCycle = false;\n        node.value = Math.max(d3Array.sum(node.sourceLinks, value), d3Array.sum(node.targetLinks, value));\n        node.sourceLinks.forEach(function (link) {\n          if (link.circular) {\n            node.partOfCycle = true;\n            node.circularLinkType = link.circularLinkType;\n          }\n        });\n        node.targetLinks.forEach(function (link) {\n          if (link.circular) {\n            node.partOfCycle = true;\n            node.circularLinkType = link.circularLinkType;\n          }\n        });\n      });\n    }\n\n    function getCircleMargins(graph) {\n      var totalTopLinksWidth = 0,\n          totalBottomLinksWidth = 0,\n          totalRightLinksWidth = 0,\n          totalLeftLinksWidth = 0;\n\n      var maxColumn = d3Array.max(graph.nodes, function (node) {\n        return node.column;\n      });\n\n      graph.links.forEach(function (link) {\n        if (link.circular) {\n          if (link.circularLinkType == 'top') {\n            totalTopLinksWidth = totalTopLinksWidth + link.width;\n          } else {\n            totalBottomLinksWidth = totalBottomLinksWidth + link.width;\n          }\n\n          if (link.target.column == 0) {\n            totalLeftLinksWidth = totalLeftLinksWidth + link.width;\n          }\n\n          if (link.source.column == maxColumn) {\n            totalRightLinksWidth = totalRightLinksWidth + link.width;\n          }\n        }\n      });\n\n      //account for radius of curves and padding between links\n      totalTopLinksWidth = totalTopLinksWidth > 0 ? totalTopLinksWidth + verticalMargin + baseRadius : totalTopLinksWidth;\n      totalBottomLinksWidth = totalBottomLinksWidth > 0 ? totalBottomLinksWidth + verticalMargin + baseRadius : totalBottomLinksWidth;\n      totalRightLinksWidth = totalRightLinksWidth > 0 ? totalRightLinksWidth + verticalMargin + baseRadius : totalRightLinksWidth;\n      totalLeftLinksWidth = totalLeftLinksWidth > 0 ? totalLeftLinksWidth + verticalMargin + baseRadius : totalLeftLinksWidth;\n\n      return { \"top\": totalTopLinksWidth, \"bottom\": totalBottomLinksWidth, \"left\": totalLeftLinksWidth, \"right\": totalRightLinksWidth };\n    }\n\n    // Update the x0, y0, x1 and y1 for the sankeyCircular, to allow space for any circular links\n    function scaleSankeySize(graph, margin) {\n\n      var maxColumn = d3Array.max(graph.nodes, function (node) {\n        return node.column;\n      });\n\n      var currentWidth = x1 - x0;\n      var currentHeight = y1 - y0;\n\n      var newWidth = currentWidth + margin.right + margin.left;\n      var newHeight = currentHeight + margin.top + margin.bottom;\n\n      var scaleX = currentWidth / newWidth;\n      var scaleY = currentHeight / newHeight;\n\n      x0 = x0 * scaleX + margin.left;\n      x1 = margin.right == 0 ? x1 : x1 * scaleX;\n      y0 = y0 * scaleY + margin.top;\n      y1 = y1 * scaleY;\n\n      graph.nodes.forEach(function (node) {\n        node.x0 = x0 + node.column * ((x1 - x0 - dx) / maxColumn);\n        node.x1 = node.x0 + dx;\n      });\n\n      return scaleY;\n    }\n\n    // Iteratively assign the depth for each node.\n    // Nodes are assigned the maximum depth of incoming neighbors plus one;\n    // nodes with no incoming links are assigned depth zero, while\n    // nodes with no outgoing links are assigned the maximum depth.\n    function computeNodeDepths(graph) {\n      var nodes, next, x;\n\n      for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) {\n        nodes.forEach(function (node) {\n          node.depth = x;\n          node.sourceLinks.forEach(function (link) {\n            if (next.indexOf(link.target) < 0 && !link.circular) {\n              next.push(link.target);\n            }\n          });\n        });\n      }\n\n      for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) {\n        nodes.forEach(function (node) {\n          node.height = x;\n          node.targetLinks.forEach(function (link) {\n            if (next.indexOf(link.source) < 0 && !link.circular) {\n              next.push(link.source);\n            }\n          });\n        });\n      }\n\n      // assign column numbers, and get max value\n      graph.nodes.forEach(function (node) {\n        node.column = Math.floor(align.call(null, node, x));\n      });\n    }\n\n    // Assign nodes' breadths, and then shift nodes that overlap (resolveCollisions)\n    function computeNodeBreadths(graph, iterations, id) {\n      var columns = d3Collection.nest().key(function (d) {\n        return d.column;\n      }).sortKeys(d3Array.ascending).entries(graph.nodes).map(function (d) {\n        return d.values;\n      });\n\n      initializeNodeBreadth(id);\n      resolveCollisions();\n\n      for (var alpha = 1, n = iterations; n > 0; --n) {\n        relaxLeftAndRight(alpha *= 0.99, id);\n        resolveCollisions();\n      }\n\n      function initializeNodeBreadth(id) {\n\n        //override py if nodePadding has been set\n        if (paddingRatio) {\n          var padding = Infinity;\n          columns.forEach(function (nodes) {\n            var thisPadding = y1 * paddingRatio / (nodes.length + 1);\n            padding = thisPadding < padding ? thisPadding : padding;\n          });\n          py = padding;\n        }\n\n        var ky = d3Array.min(columns, function (nodes) {\n          return (y1 - y0 - (nodes.length - 1) * py) / d3Array.sum(nodes, value);\n        });\n\n        //calculate the widths of the links\n        ky = ky * scale;\n\n        graph.links.forEach(function (link) {\n          link.width = link.value * ky;\n        });\n\n        //determine how much to scale down the chart, based on circular links\n        var margin = getCircleMargins(graph);\n        var ratio = scaleSankeySize(graph, margin);\n\n        //re-calculate widths\n        ky = ky * ratio;\n\n        graph.links.forEach(function (link) {\n          link.width = link.value * ky;\n        });\n\n        columns.forEach(function (nodes) {\n          var nodesLength = nodes.length;\n          nodes.forEach(function (node, i) {\n            if (node.depth == columns.length - 1 && nodesLength == 1) {\n              node.y0 = y1 / 2 - node.value * ky;\n              node.y1 = node.y0 + node.value * ky;\n            } else if (node.depth == 0 && nodesLength == 1) {\n              node.y0 = y1 / 2 - node.value * ky;\n              node.y1 = node.y0 + node.value * ky;\n            } else if (node.partOfCycle) {\n              if (numberOfNonSelfLinkingCycles(node, id) == 0) {\n                node.y0 = y1 / 2 + i;\n                node.y1 = node.y0 + node.value * ky;\n              } else if (node.circularLinkType == 'top') {\n                node.y0 = y0 + i;\n                node.y1 = node.y0 + node.value * ky;\n              } else {\n                node.y0 = y1 - node.value * ky - i;\n                node.y1 = node.y0 + node.value * ky;\n              }\n            } else {\n              if (margin.top == 0 || margin.bottom == 0) {\n                node.y0 = (y1 - y0) / nodesLength * i;\n                node.y1 = node.y0 + node.value * ky;\n              } else {\n                node.y0 = (y1 - y0) / 2 - nodesLength / 2 + i;\n                node.y1 = node.y0 + node.value * ky;\n              }\n            }\n          });\n        });\n      }\n\n      // For each node in each column, check the node's vertical position in relation to its targets and sources vertical position\n      // and shift up/down to be closer to the vertical middle of those targets and sources\n      function relaxLeftAndRight(alpha, id) {\n        var columnsLength = columns.length;\n\n        columns.forEach(function (nodes) {\n          var n = nodes.length;\n          var depth = nodes[0].depth;\n\n          nodes.forEach(function (node) {\n            // check the node is not an orphan\n            var nodeHeight;\n            if (node.sourceLinks.length || node.targetLinks.length) {\n              if (node.partOfCycle && numberOfNonSelfLinkingCycles(node, id) > 0) ; else if (depth == 0 && n == 1) {\n                nodeHeight = node.y1 - node.y0;\n\n                node.y0 = y1 / 2 - nodeHeight / 2;\n                node.y1 = y1 / 2 + nodeHeight / 2;\n              } else if (depth == columnsLength - 1 && n == 1) {\n                nodeHeight = node.y1 - node.y0;\n\n                node.y0 = y1 / 2 - nodeHeight / 2;\n                node.y1 = y1 / 2 + nodeHeight / 2;\n              } else {\n                var avg = 0;\n\n                var avgTargetY = d3Array.mean(node.sourceLinks, linkTargetCenter);\n                var avgSourceY = d3Array.mean(node.targetLinks, linkSourceCenter);\n\n                if (avgTargetY && avgSourceY) {\n                  avg = (avgTargetY + avgSourceY) / 2;\n                } else {\n                  avg = avgTargetY || avgSourceY;\n                }\n\n                var dy = (avg - nodeCenter(node)) * alpha;\n                // positive if it node needs to move down\n                node.y0 += dy;\n                node.y1 += dy;\n              }\n            }\n          });\n        });\n      }\n\n      // For each column, check if nodes are overlapping, and if so, shift up/down\n      function resolveCollisions() {\n        columns.forEach(function (nodes) {\n          var node,\n              dy,\n              y = y0,\n              n = nodes.length,\n              i;\n\n          // Push any overlapping nodes down.\n          nodes.sort(ascendingBreadth);\n\n          for (i = 0; i < n; ++i) {\n            node = nodes[i];\n            dy = y - node.y0;\n\n            if (dy > 0) {\n              node.y0 += dy;\n              node.y1 += dy;\n            }\n            y = node.y1 + py;\n          }\n\n          // If the bottommost node goes outside the bounds, push it back up.\n          dy = y - py - y1;\n          if (dy > 0) {\n            y = node.y0 -= dy, node.y1 -= dy;\n\n            // Push any overlapping nodes back up.\n            for (i = n - 2; i >= 0; --i) {\n              node = nodes[i];\n              dy = node.y1 + py - y;\n              if (dy > 0) node.y0 -= dy, node.y1 -= dy;\n              y = node.y0;\n            }\n          }\n        });\n      }\n    }\n\n    // Assign the links y0 and y1 based on source/target nodes position,\n    // plus the link's relative position to other links to the same node\n    function computeLinkBreadths(graph) {\n      graph.nodes.forEach(function (node) {\n        node.sourceLinks.sort(ascendingTargetBreadth);\n        node.targetLinks.sort(ascendingSourceBreadth);\n      });\n      graph.nodes.forEach(function (node) {\n        var y0 = node.y0;\n        var y1 = y0;\n\n        // start from the bottom of the node for cycle links\n        var y0cycle = node.y1;\n        var y1cycle = y0cycle;\n\n        node.sourceLinks.forEach(function (link) {\n          if (link.circular) {\n            link.y0 = y0cycle - link.width / 2;\n            y0cycle = y0cycle - link.width;\n          } else {\n            link.y0 = y0 + link.width / 2;\n            y0 += link.width;\n          }\n        });\n        node.targetLinks.forEach(function (link) {\n          if (link.circular) {\n            link.y1 = y1cycle - link.width / 2;\n            y1cycle = y1cycle - link.width;\n          } else {\n            link.y1 = y1 + link.width / 2;\n            y1 += link.width;\n          }\n        });\n      });\n    }\n\n    return sankeyCircular;\n  }\n\n  /// /////////////////////////////////////////////////////////////////////////////////\n  // Cycle functions\n  // portion of code to detect circular links based on Colin Fergus' bl.ock https://gist.github.com/cfergus/3956043\n\n  // Identify circles in the link objects\n  function identifyCircles(graph, id, sortNodes) {\n    var circularLinkID = 0;\n    if (sortNodes === null) {\n\n      // Building adjacency graph\n      var adjList = [];\n      for (var i = 0; i < graph.links.length; i++) {\n        var link = graph.links[i];\n        var source = link.source.index;\n        var target = link.target.index;\n        if (!adjList[source]) adjList[source] = [];\n        if (!adjList[target]) adjList[target] = [];\n\n        // Add links if not already in set\n        if (adjList[source].indexOf(target) === -1) adjList[source].push(target);\n      }\n\n      // Find all elementary circuits\n      var cycles = findCircuits(adjList);\n\n      // Sort by circuits length\n      cycles.sort(function (a, b) {\n        return a.length - b.length;\n      });\n\n      var circularLinks = {};\n      for (i = 0; i < cycles.length; i++) {\n        var cycle = cycles[i];\n        var last = cycle.slice(-2);\n        if (!circularLinks[last[0]]) circularLinks[last[0]] = {};\n        circularLinks[last[0]][last[1]] = true;\n      }\n\n      graph.links.forEach(function (link) {\n        var target = link.target.index;\n        var source = link.source.index;\n        // If self-linking or a back-edge\n        if (target === source || circularLinks[source] && circularLinks[source][target]) {\n          link.circular = true;\n          link.circularLinkID = circularLinkID;\n          circularLinkID = circularLinkID + 1;\n        } else {\n          link.circular = false;\n        }\n      });\n    } else {\n      graph.links.forEach(function (link) {\n        if (link.source[sortNodes] < link.target[sortNodes]) {\n          link.circular = false;\n        } else {\n          link.circular = true;\n          link.circularLinkID = circularLinkID;\n          circularLinkID = circularLinkID + 1;\n        }\n      });\n    }\n  }\n\n  // Assign a circular link type (top or bottom), based on:\n  // - if the source/target node already has circular links, then use the same type\n  // - if not, choose the type with fewer links\n  function selectCircularLinkTypes(graph, id) {\n    var numberOfTops = 0;\n    var numberOfBottoms = 0;\n    graph.links.forEach(function (link) {\n      if (link.circular) {\n        // if either souce or target has type already use that\n        if (link.source.circularLinkType || link.target.circularLinkType) {\n          // default to source type if available\n          link.circularLinkType = link.source.circularLinkType ? link.source.circularLinkType : link.target.circularLinkType;\n        } else {\n          link.circularLinkType = numberOfTops < numberOfBottoms ? 'top' : 'bottom';\n        }\n\n        if (link.circularLinkType == 'top') {\n          numberOfTops = numberOfTops + 1;\n        } else {\n          numberOfBottoms = numberOfBottoms + 1;\n        }\n\n        graph.nodes.forEach(function (node) {\n          if (getNodeID(node, id) == getNodeID(link.source, id) || getNodeID(node, id) == getNodeID(link.target, id)) {\n            node.circularLinkType = link.circularLinkType;\n          }\n        });\n      }\n    });\n\n    //correct self-linking links to be same direction as node\n    graph.links.forEach(function (link) {\n      if (link.circular) {\n        //if both source and target node are same type, then link should have same type\n        if (link.source.circularLinkType == link.target.circularLinkType) {\n          link.circularLinkType = link.source.circularLinkType;\n        }\n        //if link is selflinking, then link should have same type as node\n        if (selfLinking(link, id)) {\n          link.circularLinkType = link.source.circularLinkType;\n        }\n      }\n    });\n  }\n\n  // Return the angle between a straight line between the source and target of the link, and the vertical plane of the node\n  function linkAngle(link) {\n    var adjacent = Math.abs(link.y1 - link.y0);\n    var opposite = Math.abs(link.target.x0 - link.source.x1);\n\n    return Math.atan(opposite / adjacent);\n  }\n\n  // Check if two circular links potentially overlap\n  function circularLinksCross(link1, link2) {\n    if (link1.source.column < link2.target.column) {\n      return false;\n    } else if (link1.target.column > link2.source.column) {\n      return false;\n    } else {\n      return true;\n    }\n  }\n\n  // Return the number of circular links for node, not including self linking links\n  function numberOfNonSelfLinkingCycles(node, id) {\n    var sourceCount = 0;\n    node.sourceLinks.forEach(function (l) {\n      sourceCount = l.circular && !selfLinking(l, id) ? sourceCount + 1 : sourceCount;\n    });\n\n    var targetCount = 0;\n    node.targetLinks.forEach(function (l) {\n      targetCount = l.circular && !selfLinking(l, id) ? targetCount + 1 : targetCount;\n    });\n\n    return sourceCount + targetCount;\n  }\n\n  // Check if a circular link is the only circular link for both its source and target node\n  function onlyCircularLink(link) {\n    var nodeSourceLinks = link.source.sourceLinks;\n    var sourceCount = 0;\n    nodeSourceLinks.forEach(function (l) {\n      sourceCount = l.circular ? sourceCount + 1 : sourceCount;\n    });\n\n    var nodeTargetLinks = link.target.targetLinks;\n    var targetCount = 0;\n    nodeTargetLinks.forEach(function (l) {\n      targetCount = l.circular ? targetCount + 1 : targetCount;\n    });\n\n    if (sourceCount > 1 || targetCount > 1) {\n      return false;\n    } else {\n      return true;\n    }\n  }\n\n  // creates vertical buffer values per set of top/bottom links\n  function calcVerticalBuffer(links, circularLinkGap, id) {\n    links.sort(sortLinkColumnAscending);\n    links.forEach(function (link, i) {\n      var buffer = 0;\n\n      if (selfLinking(link, id) && onlyCircularLink(link)) {\n        link.circularPathData.verticalBuffer = buffer + link.width / 2;\n      } else {\n        var j = 0;\n        for (j; j < i; j++) {\n          if (circularLinksCross(links[i], links[j])) {\n            var bufferOverThisLink = links[j].circularPathData.verticalBuffer + links[j].width / 2 + circularLinkGap;\n            buffer = bufferOverThisLink > buffer ? bufferOverThisLink : buffer;\n          }\n        }\n\n        link.circularPathData.verticalBuffer = buffer + link.width / 2;\n      }\n    });\n\n    return links;\n  }\n\n  // calculate the optimum path for a link to reduce overlaps\n  function addCircularPathData(graph, circularLinkGap, y1, id) {\n    //var baseRadius = 10\n    var buffer = 5;\n    //var verticalMargin = 25\n\n    var minY = d3Array.min(graph.links, function (link) {\n      return link.source.y0;\n    });\n\n    // create object for circular Path Data\n    graph.links.forEach(function (link) {\n      if (link.circular) {\n        link.circularPathData = {};\n      }\n    });\n\n    // calc vertical offsets per top/bottom links\n    var topLinks = graph.links.filter(function (l) {\n      return l.circularLinkType == 'top';\n    });\n    /* topLinks = */calcVerticalBuffer(topLinks, circularLinkGap, id);\n\n    var bottomLinks = graph.links.filter(function (l) {\n      return l.circularLinkType == 'bottom';\n    });\n    /* bottomLinks = */calcVerticalBuffer(bottomLinks, circularLinkGap, id);\n\n    // add the base data for each link\n    graph.links.forEach(function (link) {\n      if (link.circular) {\n        link.circularPathData.arcRadius = link.width + baseRadius;\n        link.circularPathData.leftNodeBuffer = buffer;\n        link.circularPathData.rightNodeBuffer = buffer;\n        link.circularPathData.sourceWidth = link.source.x1 - link.source.x0;\n        link.circularPathData.sourceX = link.source.x0 + link.circularPathData.sourceWidth;\n        link.circularPathData.targetX = link.target.x0;\n        link.circularPathData.sourceY = link.y0;\n        link.circularPathData.targetY = link.y1;\n\n        // for self linking paths, and that the only circular link in/out of that node\n        if (selfLinking(link, id) && onlyCircularLink(link)) {\n          link.circularPathData.leftSmallArcRadius = baseRadius + link.width / 2;\n          link.circularPathData.leftLargeArcRadius = baseRadius + link.width / 2;\n          link.circularPathData.rightSmallArcRadius = baseRadius + link.width / 2;\n          link.circularPathData.rightLargeArcRadius = baseRadius + link.width / 2;\n\n          if (link.circularLinkType == 'bottom') {\n            link.circularPathData.verticalFullExtent = link.source.y1 + verticalMargin + link.circularPathData.verticalBuffer;\n            link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.leftLargeArcRadius;\n            link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.rightLargeArcRadius;\n          } else {\n            // top links\n            link.circularPathData.verticalFullExtent = link.source.y0 - verticalMargin - link.circularPathData.verticalBuffer;\n            link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.leftLargeArcRadius;\n            link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.rightLargeArcRadius;\n          }\n        } else {\n          // else calculate normally\n          // add left extent coordinates, based on links with same source column and circularLink type\n          var thisColumn = link.source.column;\n          var thisCircularLinkType = link.circularLinkType;\n          var sameColumnLinks = graph.links.filter(function (l) {\n            return l.source.column == thisColumn && l.circularLinkType == thisCircularLinkType;\n          });\n\n          if (link.circularLinkType == 'bottom') {\n            sameColumnLinks.sort(sortLinkSourceYDescending);\n          } else {\n            sameColumnLinks.sort(sortLinkSourceYAscending);\n          }\n\n          var radiusOffset = 0;\n          sameColumnLinks.forEach(function (l, i) {\n            if (l.circularLinkID == link.circularLinkID) {\n              link.circularPathData.leftSmallArcRadius = baseRadius + link.width / 2 + radiusOffset;\n              link.circularPathData.leftLargeArcRadius = baseRadius + link.width / 2 + i * circularLinkGap + radiusOffset;\n            }\n            radiusOffset = radiusOffset + l.width;\n          });\n\n          // add right extent coordinates, based on links with same target column and circularLink type\n          thisColumn = link.target.column;\n          sameColumnLinks = graph.links.filter(function (l) {\n            return l.target.column == thisColumn && l.circularLinkType == thisCircularLinkType;\n          });\n          if (link.circularLinkType == 'bottom') {\n            sameColumnLinks.sort(sortLinkTargetYDescending);\n          } else {\n            sameColumnLinks.sort(sortLinkTargetYAscending);\n          }\n\n          radiusOffset = 0;\n          sameColumnLinks.forEach(function (l, i) {\n            if (l.circularLinkID == link.circularLinkID) {\n              link.circularPathData.rightSmallArcRadius = baseRadius + link.width / 2 + radiusOffset;\n              link.circularPathData.rightLargeArcRadius = baseRadius + link.width / 2 + i * circularLinkGap + radiusOffset;\n            }\n            radiusOffset = radiusOffset + l.width;\n          });\n\n          // bottom links\n          if (link.circularLinkType == 'bottom') {\n            link.circularPathData.verticalFullExtent = Math.max(y1, link.source.y1, link.target.y1) + verticalMargin + link.circularPathData.verticalBuffer;\n            link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.leftLargeArcRadius;\n            link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.rightLargeArcRadius;\n          } else {\n            // top links\n            link.circularPathData.verticalFullExtent = minY - verticalMargin - link.circularPathData.verticalBuffer;\n            link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.leftLargeArcRadius;\n            link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.rightLargeArcRadius;\n          }\n        }\n\n        // all links\n        link.circularPathData.leftInnerExtent = link.circularPathData.sourceX + link.circularPathData.leftNodeBuffer;\n        link.circularPathData.rightInnerExtent = link.circularPathData.targetX - link.circularPathData.rightNodeBuffer;\n        link.circularPathData.leftFullExtent = link.circularPathData.sourceX + link.circularPathData.leftLargeArcRadius + link.circularPathData.leftNodeBuffer;\n        link.circularPathData.rightFullExtent = link.circularPathData.targetX - link.circularPathData.rightLargeArcRadius - link.circularPathData.rightNodeBuffer;\n      }\n\n      if (link.circular) {\n        link.path = createCircularPathString(link);\n      } else {\n        var normalPath = d3Shape.linkHorizontal().source(function (d) {\n          var x = d.source.x0 + (d.source.x1 - d.source.x0);\n          var y = d.y0;\n          return [x, y];\n        }).target(function (d) {\n          var x = d.target.x0;\n          var y = d.y1;\n          return [x, y];\n        });\n        link.path = normalPath(link);\n      }\n    });\n  }\n\n  // create a d path using the addCircularPathData\n  function createCircularPathString(link) {\n    var pathString = '';\n    // 'pathData' is assigned a value but never used\n    // var pathData = {}\n\n    if (link.circularLinkType == 'top') {\n      pathString =\n      // start at the right of the source node\n      'M' + link.circularPathData.sourceX + ' ' + link.circularPathData.sourceY + ' ' +\n      // line right to buffer point\n      'L' + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.sourceY + ' ' +\n      // Arc around: Centre of arc X and  //Centre of arc Y\n      'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftSmallArcRadius + ' 0 0 0 ' +\n      // End of arc X //End of arc Y\n      link.circularPathData.leftFullExtent + ' ' + (link.circularPathData.sourceY - link.circularPathData.leftSmallArcRadius) + ' ' + // End of arc X\n      // line up to buffer point\n      'L' + link.circularPathData.leftFullExtent + ' ' + link.circularPathData.verticalLeftInnerExtent + ' ' +\n      // Arc around: Centre of arc X and  //Centre of arc Y\n      'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftLargeArcRadius + ' 0 0 0 ' +\n      // End of arc X //End of arc Y\n      link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + // End of arc X\n      // line left to buffer point\n      'L' + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' +\n      // Arc around: Centre of arc X and  //Centre of arc Y\n      'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightLargeArcRadius + ' 0 0 0 ' +\n      // End of arc X //End of arc Y\n      link.circularPathData.rightFullExtent + ' ' + link.circularPathData.verticalRightInnerExtent + ' ' + // End of arc X\n      // line down\n      'L' + link.circularPathData.rightFullExtent + ' ' + (link.circularPathData.targetY - link.circularPathData.rightSmallArcRadius) + ' ' +\n      // Arc around: Centre of arc X and  //Centre of arc Y\n      'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightSmallArcRadius + ' 0 0 0 ' +\n      // End of arc X //End of arc Y\n      link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.targetY + ' ' + // End of arc X\n      // line to end\n      'L' + link.circularPathData.targetX + ' ' + link.circularPathData.targetY;\n    } else {\n      // bottom path\n      pathString =\n      // start at the right of the source node\n      'M' + link.circularPathData.sourceX + ' ' + link.circularPathData.sourceY + ' ' +\n      // line right to buffer point\n      'L' + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.sourceY + ' ' +\n      // Arc around: Centre of arc X and  //Centre of arc Y\n      'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftSmallArcRadius + ' 0 0 1 ' +\n      // End of arc X //End of arc Y\n      link.circularPathData.leftFullExtent + ' ' + (link.circularPathData.sourceY + link.circularPathData.leftSmallArcRadius) + ' ' + // End of arc X\n      // line down to buffer point\n      'L' + link.circularPathData.leftFullExtent + ' ' + link.circularPathData.verticalLeftInnerExtent + ' ' +\n      // Arc around: Centre of arc X and  //Centre of arc Y\n      'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftLargeArcRadius + ' 0 0 1 ' +\n      // End of arc X //End of arc Y\n      link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + // End of arc X\n      // line left to buffer point\n      'L' + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' +\n      // Arc around: Centre of arc X and  //Centre of arc Y\n      'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightLargeArcRadius + ' 0 0 1 ' +\n      // End of arc X //End of arc Y\n      link.circularPathData.rightFullExtent + ' ' + link.circularPathData.verticalRightInnerExtent + ' ' + // End of arc X\n      // line up\n      'L' + link.circularPathData.rightFullExtent + ' ' + (link.circularPathData.targetY + link.circularPathData.rightSmallArcRadius) + ' ' +\n      // Arc around: Centre of arc X and  //Centre of arc Y\n      'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightSmallArcRadius + ' 0 0 1 ' +\n      // End of arc X //End of arc Y\n      link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.targetY + ' ' + // End of arc X\n      // line to end\n      'L' + link.circularPathData.targetX + ' ' + link.circularPathData.targetY;\n    }\n\n    return pathString;\n  }\n\n  // sort links based on the distance between the source and tartget node columns\n  // if the same, then use Y position of the source node\n  function sortLinkColumnAscending(link1, link2) {\n    if (linkColumnDistance(link1) == linkColumnDistance(link2)) {\n      return link1.circularLinkType == 'bottom' ? sortLinkSourceYDescending(link1, link2) : sortLinkSourceYAscending(link1, link2);\n    } else {\n      return linkColumnDistance(link2) - linkColumnDistance(link1);\n    }\n  }\n\n  // sort ascending links by their source vertical position, y0\n  function sortLinkSourceYAscending(link1, link2) {\n    return link1.y0 - link2.y0;\n  }\n\n  // sort descending links by their source vertical position, y0\n  function sortLinkSourceYDescending(link1, link2) {\n    return link2.y0 - link1.y0;\n  }\n\n  // sort ascending links by their target vertical position, y1\n  function sortLinkTargetYAscending(link1, link2) {\n    return link1.y1 - link2.y1;\n  }\n\n  // sort descending links by their target vertical position, y1\n  function sortLinkTargetYDescending(link1, link2) {\n    return link2.y1 - link1.y1;\n  }\n\n  // return the distance between the link's target and source node, in terms of the nodes' column\n  function linkColumnDistance(link) {\n    return link.target.column - link.source.column;\n  }\n\n  // return the distance between the link's target and source node, in terms of the nodes' X coordinate\n  function linkXLength(link) {\n    return link.target.x0 - link.source.x1;\n  }\n\n  // Return the Y coordinate on the longerLink path * which is perpendicular shorterLink's source.\n  // * approx, based on a straight line from target to source, when in fact the path is a bezier\n  function linkPerpendicularYToLinkSource(longerLink, shorterLink) {\n    // get the angle for the longer link\n    var angle = linkAngle(longerLink);\n\n    // get the adjacent length to the other link's x position\n    var heightFromY1ToPependicular = linkXLength(shorterLink) / Math.tan(angle);\n\n    // add or subtract from longer link1's original y1, depending on the slope\n    var yPerpendicular = incline(longerLink) == 'up' ? longerLink.y1 + heightFromY1ToPependicular : longerLink.y1 - heightFromY1ToPependicular;\n\n    return yPerpendicular;\n  }\n\n  // Return the Y coordinate on the longerLink path * which is perpendicular shorterLink's source.\n  // * approx, based on a straight line from target to source, when in fact the path is a bezier\n  function linkPerpendicularYToLinkTarget(longerLink, shorterLink) {\n    // get the angle for the longer link\n    var angle = linkAngle(longerLink);\n\n    // get the adjacent length to the other link's x position\n    var heightFromY1ToPependicular = linkXLength(shorterLink) / Math.tan(angle);\n\n    // add or subtract from longer link's original y1, depending on the slope\n    var yPerpendicular = incline(longerLink) == 'up' ? longerLink.y1 - heightFromY1ToPependicular : longerLink.y1 + heightFromY1ToPependicular;\n\n    return yPerpendicular;\n  }\n\n  // Move any nodes that overlap links which span 2+ columns\n  function resolveNodeLinkOverlaps(graph, y0, y1, id) {\n\n    graph.links.forEach(function (link) {\n      if (link.circular) {\n        return;\n      }\n\n      if (link.target.column - link.source.column > 1) {\n        var columnToTest = link.source.column + 1;\n        var maxColumnToTest = link.target.column - 1;\n\n        var i = 1;\n        var numberOfColumnsToTest = maxColumnToTest - columnToTest + 1;\n\n        for (i = 1; columnToTest <= maxColumnToTest; columnToTest++, i++) {\n          graph.nodes.forEach(function (node) {\n            if (node.column == columnToTest) {\n              var t = i / (numberOfColumnsToTest + 1);\n\n              // Find all the points of a cubic bezier curve in javascript\n              // https://stackoverflow.com/questions/15397596/find-all-the-points-of-a-cubic-bezier-curve-in-javascript\n\n              var B0_t = Math.pow(1 - t, 3);\n              var B1_t = 3 * t * Math.pow(1 - t, 2);\n              var B2_t = 3 * Math.pow(t, 2) * (1 - t);\n              var B3_t = Math.pow(t, 3);\n\n              var py_t = B0_t * link.y0 + B1_t * link.y0 + B2_t * link.y1 + B3_t * link.y1;\n\n              var linkY0AtColumn = py_t - link.width / 2;\n              var linkY1AtColumn = py_t + link.width / 2;\n              var dy;\n\n              // If top of link overlaps node, push node up\n              if (linkY0AtColumn > node.y0 && linkY0AtColumn < node.y1) {\n\n                dy = node.y1 - linkY0AtColumn + 10;\n                dy = node.circularLinkType == 'bottom' ? dy : -dy;\n\n                node = adjustNodeHeight(node, dy, y0, y1);\n\n                // check if other nodes need to move up too\n                graph.nodes.forEach(function (otherNode) {\n                  // don't need to check itself or nodes at different columns\n                  if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) {\n                    return;\n                  }\n                  if (nodesOverlap(node, otherNode)) {\n                    adjustNodeHeight(otherNode, dy, y0, y1);\n                  }\n                });\n              } else if (linkY1AtColumn > node.y0 && linkY1AtColumn < node.y1) {\n                // If bottom of link overlaps node, push node down\n                dy = linkY1AtColumn - node.y0 + 10;\n\n                node = adjustNodeHeight(node, dy, y0, y1);\n\n                // check if other nodes need to move down too\n                graph.nodes.forEach(function (otherNode) {\n                  // don't need to check itself or nodes at different columns\n                  if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) {\n                    return;\n                  }\n                  if (otherNode.y0 < node.y1 && otherNode.y1 > node.y1) {\n                    adjustNodeHeight(otherNode, dy, y0, y1);\n                  }\n                });\n              } else if (linkY0AtColumn < node.y0 && linkY1AtColumn > node.y1) {\n                // if link completely overlaps node\n                dy = linkY1AtColumn - node.y0 + 10;\n\n                node = adjustNodeHeight(node, dy, y0, y1);\n\n                graph.nodes.forEach(function (otherNode) {\n                  // don't need to check itself or nodes at different columns\n                  if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) {\n                    return;\n                  }\n                  if (otherNode.y0 < node.y1 && otherNode.y1 > node.y1) {\n                    adjustNodeHeight(otherNode, dy, y0, y1);\n                  }\n                });\n              }\n            }\n          });\n        }\n      }\n    });\n  }\n\n  // check if two nodes overlap\n  function nodesOverlap(nodeA, nodeB) {\n    // test if nodeA top partially overlaps nodeB\n    if (nodeA.y0 > nodeB.y0 && nodeA.y0 < nodeB.y1) {\n      return true;\n    } else if (nodeA.y1 > nodeB.y0 && nodeA.y1 < nodeB.y1) {\n      // test if nodeA bottom partially overlaps nodeB\n      return true;\n    } else if (nodeA.y0 < nodeB.y0 && nodeA.y1 > nodeB.y1) {\n      // test if nodeA covers nodeB\n      return true;\n    } else {\n      return false;\n    }\n  }\n\n  // update a node, and its associated links, vertical positions (y0, y1)\n  function adjustNodeHeight(node, dy, sankeyY0, sankeyY1) {\n    if (node.y0 + dy >= sankeyY0 && node.y1 + dy <= sankeyY1) {\n      node.y0 = node.y0 + dy;\n      node.y1 = node.y1 + dy;\n\n      node.targetLinks.forEach(function (l) {\n        l.y1 = l.y1 + dy;\n      });\n\n      node.sourceLinks.forEach(function (l) {\n        l.y0 = l.y0 + dy;\n      });\n    }\n    return node;\n  }\n\n  // sort and set the links' y0 for each node\n  function sortSourceLinks(graph, y1, id, moveNodes) {\n    graph.nodes.forEach(function (node) {\n      // move any nodes up which are off the bottom\n      if (moveNodes && node.y + (node.y1 - node.y0) > y1) {\n        node.y = node.y - (node.y + (node.y1 - node.y0) - y1);\n      }\n\n      var nodesSourceLinks = graph.links.filter(function (l) {\n        return getNodeID(l.source, id) == getNodeID(node, id);\n      });\n\n      var nodeSourceLinksLength = nodesSourceLinks.length;\n\n      // if more than 1 link then sort\n      if (nodeSourceLinksLength > 1) {\n        nodesSourceLinks.sort(function (link1, link2) {\n          // if both are not circular...\n          if (!link1.circular && !link2.circular) {\n            // if the target nodes are the same column, then sort by the link's target y\n            if (link1.target.column == link2.target.column) {\n              return link1.y1 - link2.y1;\n            } else if (!sameInclines(link1, link2)) {\n              // if the links slope in different directions, then sort by the link's target y\n              return link1.y1 - link2.y1;\n\n              // if the links slope in same directions, then sort by any overlap\n            } else {\n              if (link1.target.column > link2.target.column) {\n                var link2Adj = linkPerpendicularYToLinkTarget(link2, link1);\n                return link1.y1 - link2Adj;\n              }\n              if (link2.target.column > link1.target.column) {\n                var link1Adj = linkPerpendicularYToLinkTarget(link1, link2);\n                return link1Adj - link2.y1;\n              }\n            }\n          }\n\n          // if only one is circular, the move top links up, or bottom links down\n          if (link1.circular && !link2.circular) {\n            return link1.circularLinkType == 'top' ? -1 : 1;\n          } else if (link2.circular && !link1.circular) {\n            return link2.circularLinkType == 'top' ? 1 : -1;\n          }\n\n          // if both links are circular...\n          if (link1.circular && link2.circular) {\n            // ...and they both loop the same way (both top)\n            if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'top') {\n              // ...and they both connect to a target with same column, then sort by the target's y\n              if (link1.target.column === link2.target.column) {\n                return link1.target.y1 - link2.target.y1;\n              } else {\n                // ...and they connect to different column targets, then sort by how far back they\n                return link2.target.column - link1.target.column;\n              }\n            } else if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'bottom') {\n              // ...and they both loop the same way (both bottom)\n              // ...and they both connect to a target with same column, then sort by the target's y\n              if (link1.target.column === link2.target.column) {\n                return link2.target.y1 - link1.target.y1;\n              } else {\n                // ...and they connect to different column targets, then sort by how far back they\n                return link1.target.column - link2.target.column;\n              }\n            } else {\n              // ...and they loop around different ways, the move top up and bottom down\n              return link1.circularLinkType == 'top' ? -1 : 1;\n            }\n          }\n        });\n      }\n\n      // update y0 for links\n      var ySourceOffset = node.y0;\n\n      nodesSourceLinks.forEach(function (link) {\n        link.y0 = ySourceOffset + link.width / 2;\n        ySourceOffset = ySourceOffset + link.width;\n      });\n\n      // correct any circular bottom links so they are at the bottom of the node\n      nodesSourceLinks.forEach(function (link, i) {\n        if (link.circularLinkType == 'bottom') {\n          var j = i + 1;\n          var offsetFromBottom = 0;\n          // sum the widths of any links that are below this link\n          for (j; j < nodeSourceLinksLength; j++) {\n            offsetFromBottom = offsetFromBottom + nodesSourceLinks[j].width;\n          }\n          link.y0 = node.y1 - offsetFromBottom - link.width / 2;\n        }\n      });\n    });\n  }\n\n  // sort and set the links' y1 for each node\n  function sortTargetLinks(graph, y1, id) {\n    graph.nodes.forEach(function (node) {\n      var nodesTargetLinks = graph.links.filter(function (l) {\n        return getNodeID(l.target, id) == getNodeID(node, id);\n      });\n\n      var nodesTargetLinksLength = nodesTargetLinks.length;\n\n      if (nodesTargetLinksLength > 1) {\n        nodesTargetLinks.sort(function (link1, link2) {\n          // if both are not circular, the base on the source y position\n          if (!link1.circular && !link2.circular) {\n            if (link1.source.column == link2.source.column) {\n              return link1.y0 - link2.y0;\n            } else if (!sameInclines(link1, link2)) {\n              return link1.y0 - link2.y0;\n            } else {\n              // get the angle of the link to the further source node (ie the smaller column)\n              if (link2.source.column < link1.source.column) {\n                var link2Adj = linkPerpendicularYToLinkSource(link2, link1);\n\n                return link1.y0 - link2Adj;\n              }\n              if (link1.source.column < link2.source.column) {\n                var link1Adj = linkPerpendicularYToLinkSource(link1, link2);\n\n                return link1Adj - link2.y0;\n              }\n            }\n          }\n\n          // if only one is circular, the move top links up, or bottom links down\n          if (link1.circular && !link2.circular) {\n            return link1.circularLinkType == 'top' ? -1 : 1;\n          } else if (link2.circular && !link1.circular) {\n            return link2.circularLinkType == 'top' ? 1 : -1;\n          }\n\n          // if both links are circular...\n          if (link1.circular && link2.circular) {\n            // ...and they both loop the same way (both top)\n            if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'top') {\n              // ...and they both connect to a target with same column, then sort by the target's y\n              if (link1.source.column === link2.source.column) {\n                return link1.source.y1 - link2.source.y1;\n              } else {\n                // ...and they connect to different column targets, then sort by how far back they\n                return link1.source.column - link2.source.column;\n              }\n            } else if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'bottom') {\n              // ...and they both loop the same way (both bottom)\n              // ...and they both connect to a target with same column, then sort by the target's y\n              if (link1.source.column === link2.source.column) {\n                return link1.source.y1 - link2.source.y1;\n              } else {\n                // ...and they connect to different column targets, then sort by how far back they\n                return link2.source.column - link1.source.column;\n              }\n            } else {\n              // ...and they loop around different ways, the move top up and bottom down\n              return link1.circularLinkType == 'top' ? -1 : 1;\n            }\n          }\n        });\n      }\n\n      // update y1 for links\n      var yTargetOffset = node.y0;\n\n      nodesTargetLinks.forEach(function (link) {\n        link.y1 = yTargetOffset + link.width / 2;\n        yTargetOffset = yTargetOffset + link.width;\n      });\n\n      // correct any circular bottom links so they are at the bottom of the node\n      nodesTargetLinks.forEach(function (link, i) {\n        if (link.circularLinkType == 'bottom') {\n          var j = i + 1;\n          var offsetFromBottom = 0;\n          // sum the widths of any links that are below this link\n          for (j; j < nodesTargetLinksLength; j++) {\n            offsetFromBottom = offsetFromBottom + nodesTargetLinks[j].width;\n          }\n          link.y1 = node.y1 - offsetFromBottom - link.width / 2;\n        }\n      });\n    });\n  }\n\n  // test if links both slope up, or both slope down\n  function sameInclines(link1, link2) {\n    return incline(link1) == incline(link2);\n  }\n\n  // returns the slope of a link, from source to target\n  // up => slopes up from source to target\n  // down => slopes down from source to target\n  function incline(link) {\n    return link.y0 - link.y1 > 0 ? 'up' : 'down';\n  }\n\n  // check if link is self linking, ie links a node to the same node\n  function selfLinking(link, id) {\n    return getNodeID(link.source, id) == getNodeID(link.target, id);\n  }\n\n  function fillHeight(graph, y0, y1) {\n\n    var nodes = graph.nodes;\n    var links = graph.links;\n\n    var top = false;\n    var bottom = false;\n\n    links.forEach(function (link) {\n      if (link.circularLinkType == \"top\") {\n        top = true;\n      } else if (link.circularLinkType == \"bottom\") {\n        bottom = true;\n      }\n    });\n\n    if (top == false || bottom == false) {\n      var minY0 = d3Array.min(nodes, function (node) {\n        return node.y0;\n      });\n      var maxY1 = d3Array.max(nodes, function (node) {\n        return node.y1;\n      });\n      var currentHeight = maxY1 - minY0;\n      var chartHeight = y1 - y0;\n      var ratio = chartHeight / currentHeight;\n\n      nodes.forEach(function (node) {\n        var nodeHeight = (node.y1 - node.y0) * ratio;\n        node.y0 = (node.y0 - minY0) * ratio;\n        node.y1 = node.y0 + nodeHeight;\n      });\n\n      links.forEach(function (link) {\n        link.y0 = (link.y0 - minY0) * ratio;\n        link.y1 = (link.y1 - minY0) * ratio;\n        link.width = link.width * ratio;\n      });\n    }\n  }\n\n  exports.sankeyCircular = sankeyCircular;\n  exports.sankeyCenter = center;\n  exports.sankeyLeft = left;\n  exports.sankeyRight = right;\n  exports.sankeyJustify = justify;\n\n  Object.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{\"d3-array\":152,\"d3-collection\":153,\"d3-shape\":161,\"elementary-circuits-directed-graph\":172}],54:[function(_dereq_,module,exports){\n// https://github.com/d3/d3-sankey Version 0.7.2. Copyright 2019 Mike Bostock.\n(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, _dereq_('d3-array'), _dereq_('d3-collection'), _dereq_('d3-shape')) :\n\ttypeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-collection', 'd3-shape'], factory) :\n\t(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3));\n}(this, (function (exports,d3Array,d3Collection,d3Shape) { 'use strict';\n\nfunction targetDepth(d) {\n  return d.target.depth;\n}\n\nfunction left(node) {\n  return node.depth;\n}\n\nfunction right(node, n) {\n  return n - 1 - node.height;\n}\n\nfunction justify(node, n) {\n  return node.sourceLinks.length ? node.depth : n - 1;\n}\n\nfunction center(node) {\n  return node.targetLinks.length ? node.depth\n      : node.sourceLinks.length ? d3Array.min(node.sourceLinks, targetDepth) - 1\n      : 0;\n}\n\nfunction constant(x) {\n  return function() {\n    return x;\n  };\n}\n\nfunction ascendingSourceBreadth(a, b) {\n  return ascendingBreadth(a.source, b.source) || a.index - b.index;\n}\n\nfunction ascendingTargetBreadth(a, b) {\n  return ascendingBreadth(a.target, b.target) || a.index - b.index;\n}\n\nfunction ascendingBreadth(a, b) {\n  return a.y0 - b.y0;\n}\n\nfunction value(d) {\n  return d.value;\n}\n\nfunction nodeCenter(node) {\n  return (node.y0 + node.y1) / 2;\n}\n\nfunction weightedSource(link) {\n  return nodeCenter(link.source) * link.value;\n}\n\nfunction weightedTarget(link) {\n  return nodeCenter(link.target) * link.value;\n}\n\nfunction defaultId(d) {\n  return d.index;\n}\n\nfunction defaultNodes(graph) {\n  return graph.nodes;\n}\n\nfunction defaultLinks(graph) {\n  return graph.links;\n}\n\nfunction find(nodeById, id) {\n  var node = nodeById.get(id);\n  if (!node) throw new Error(\"missing: \" + id);\n  return node;\n}\n\nvar sankey = function() {\n  var x0 = 0, y0 = 0, x1 = 1, y1 = 1, // extent\n      dx = 24, // nodeWidth\n      py = 8, // nodePadding\n      id = defaultId,\n      align = justify,\n      nodes = defaultNodes,\n      links = defaultLinks,\n      iterations = 32,\n      maxPaddedSpace = 2 / 3; // Defined as a fraction of the total available space\n\n  function sankey() {\n    var graph = {nodes: nodes.apply(null, arguments), links: links.apply(null, arguments)};\n    computeNodeLinks(graph);\n    computeNodeValues(graph);\n    computeNodeDepths(graph);\n    computeNodeBreadths(graph, iterations);\n    computeLinkBreadths(graph);\n    return graph;\n  }\n\n  sankey.update = function(graph) {\n    computeLinkBreadths(graph);\n    return graph;\n  };\n\n  sankey.nodeId = function(_) {\n    return arguments.length ? (id = typeof _ === \"function\" ? _ : constant(_), sankey) : id;\n  };\n\n  sankey.nodeAlign = function(_) {\n    return arguments.length ? (align = typeof _ === \"function\" ? _ : constant(_), sankey) : align;\n  };\n\n  sankey.nodeWidth = function(_) {\n    return arguments.length ? (dx = +_, sankey) : dx;\n  };\n\n  sankey.nodePadding = function(_) {\n    return arguments.length ? (py = +_, sankey) : py;\n  };\n\n  sankey.nodes = function(_) {\n    return arguments.length ? (nodes = typeof _ === \"function\" ? _ : constant(_), sankey) : nodes;\n  };\n\n  sankey.links = function(_) {\n    return arguments.length ? (links = typeof _ === \"function\" ? _ : constant(_), sankey) : links;\n  };\n\n  sankey.size = function(_) {\n    return arguments.length ? (x0 = y0 = 0, x1 = +_[0], y1 = +_[1], sankey) : [x1 - x0, y1 - y0];\n  };\n\n  sankey.extent = function(_) {\n    return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], sankey) : [[x0, y0], [x1, y1]];\n  };\n\n  sankey.iterations = function(_) {\n    return arguments.length ? (iterations = +_, sankey) : iterations;\n  };\n\n  // Populate the sourceLinks and targetLinks for each node.\n  // Also, if the source and target are not objects, assume they are indices.\n  function computeNodeLinks(graph) {\n    graph.nodes.forEach(function(node, i) {\n      node.index = i;\n      node.sourceLinks = [];\n      node.targetLinks = [];\n    });\n\n    var nodeById = d3Collection.map(graph.nodes, id);\n    graph.links.forEach(function(link, i) {\n      link.index = i;\n      var source = link.source, target = link.target;\n      if (typeof source !== \"object\") source = link.source = find(nodeById, source);\n      if (typeof target !== \"object\") target = link.target = find(nodeById, target);\n      source.sourceLinks.push(link);\n      target.targetLinks.push(link);\n    });\n  }\n\n  // Compute the value (size) of each node by summing the associated links.\n  function computeNodeValues(graph) {\n    graph.nodes.forEach(function(node) {\n      node.value = Math.max(\n        d3Array.sum(node.sourceLinks, value),\n        d3Array.sum(node.targetLinks, value)\n      );\n    });\n  }\n\n  // Iteratively assign the depth (x-position) for each node.\n  // Nodes are assigned the maximum depth of incoming neighbors plus one;\n  // nodes with no incoming links are assigned depth zero, while\n  // nodes with no outgoing links are assigned the maximum depth.\n  function computeNodeDepths(graph) {\n    var nodes, next, x;\n\n    for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) {\n      nodes.forEach(function(node) {\n        node.depth = x;\n        node.sourceLinks.forEach(function(link) {\n          if (next.indexOf(link.target) < 0) {\n            next.push(link.target);\n          }\n        });\n      });\n    }\n\n    for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) {\n      nodes.forEach(function(node) {\n        node.height = x;\n        node.targetLinks.forEach(function(link) {\n          if (next.indexOf(link.source) < 0) {\n            next.push(link.source);\n          }\n        });\n      });\n    }\n\n    var kx = (x1 - x0 - dx) / (x - 1);\n    graph.nodes.forEach(function(node) {\n      node.x1 = (node.x0 = x0 + Math.max(0, Math.min(x - 1, Math.floor(align.call(null, node, x)))) * kx) + dx;\n    });\n  }\n\n  function computeNodeBreadths(graph) {\n    var columns = d3Collection.nest()\n        .key(function(d) { return d.x0; })\n        .sortKeys(d3Array.ascending)\n        .entries(graph.nodes)\n        .map(function(d) { return d.values; });\n\n    //\n    initializeNodeBreadth();\n    resolveCollisions();\n    for (var alpha = 1, n = iterations; n > 0; --n) {\n      relaxRightToLeft(alpha *= 0.99);\n      resolveCollisions();\n      relaxLeftToRight(alpha);\n      resolveCollisions();\n    }\n\n    function initializeNodeBreadth() {\n      var L = d3Array.max(columns, function(nodes) {\n        return nodes.length;\n      });\n      var maxNodePadding = maxPaddedSpace * (y1 - y0) / (L - 1);\n      if(py > maxNodePadding) py = maxNodePadding;\n      var ky = d3Array.min(columns, function(nodes) {\n        return (y1 - y0 - (nodes.length - 1) * py) / d3Array.sum(nodes, value);\n      });\n\n      columns.forEach(function(nodes) {\n        nodes.forEach(function(node, i) {\n          node.y1 = (node.y0 = i) + node.value * ky;\n        });\n      });\n\n      graph.links.forEach(function(link) {\n        link.width = link.value * ky;\n      });\n    }\n\n    function relaxLeftToRight(alpha) {\n      columns.forEach(function(nodes) {\n        nodes.forEach(function(node) {\n          if (node.targetLinks.length) {\n            var dy = (d3Array.sum(node.targetLinks, weightedSource) / d3Array.sum(node.targetLinks, value) - nodeCenter(node)) * alpha;\n            node.y0 += dy, node.y1 += dy;\n          }\n        });\n      });\n    }\n\n    function relaxRightToLeft(alpha) {\n      columns.slice().reverse().forEach(function(nodes) {\n        nodes.forEach(function(node) {\n          if (node.sourceLinks.length) {\n            var dy = (d3Array.sum(node.sourceLinks, weightedTarget) / d3Array.sum(node.sourceLinks, value) - nodeCenter(node)) * alpha;\n            node.y0 += dy, node.y1 += dy;\n          }\n        });\n      });\n    }\n\n    function resolveCollisions() {\n      columns.forEach(function(nodes) {\n        var node,\n            dy,\n            y = y0,\n            n = nodes.length,\n            i;\n\n        // Push any overlapping nodes down.\n        nodes.sort(ascendingBreadth);\n        for (i = 0; i < n; ++i) {\n          node = nodes[i];\n          dy = y - node.y0;\n          if (dy > 0) node.y0 += dy, node.y1 += dy;\n          y = node.y1 + py;\n        }\n\n        // If the bottommost node goes outside the bounds, push it back up.\n        dy = y - py - y1;\n        if (dy > 0) {\n          y = (node.y0 -= dy), node.y1 -= dy;\n\n          // Push any overlapping nodes back up.\n          for (i = n - 2; i >= 0; --i) {\n            node = nodes[i];\n            dy = node.y1 + py - y;\n            if (dy > 0) node.y0 -= dy, node.y1 -= dy;\n            y = node.y0;\n          }\n        }\n      });\n    }\n  }\n\n  function computeLinkBreadths(graph) {\n    graph.nodes.forEach(function(node) {\n      node.sourceLinks.sort(ascendingTargetBreadth);\n      node.targetLinks.sort(ascendingSourceBreadth);\n    });\n    graph.nodes.forEach(function(node) {\n      var y0 = node.y0, y1 = y0;\n      node.sourceLinks.forEach(function(link) {\n        link.y0 = y0 + link.width / 2, y0 += link.width;\n      });\n      node.targetLinks.forEach(function(link) {\n        link.y1 = y1 + link.width / 2, y1 += link.width;\n      });\n    });\n  }\n\n  return sankey;\n};\n\nfunction horizontalSource(d) {\n  return [d.source.x1, d.y0];\n}\n\nfunction horizontalTarget(d) {\n  return [d.target.x0, d.y1];\n}\n\nvar sankeyLinkHorizontal = function() {\n  return d3Shape.linkHorizontal()\n      .source(horizontalSource)\n      .target(horizontalTarget);\n};\n\nexports.sankey = sankey;\nexports.sankeyCenter = center;\nexports.sankeyLeft = left;\nexports.sankeyRight = right;\nexports.sankeyJustify = justify;\nexports.sankeyLinkHorizontal = sankeyLinkHorizontal;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{\"d3-array\":152,\"d3-collection\":153,\"d3-shape\":161}],55:[function(_dereq_,module,exports){\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar meta_1 = _dereq_(\"@turf/meta\");\n// Note: change RADIUS => earthRadius\nvar RADIUS = 6378137;\n/**\n * Takes one or more features and returns their area in square meters.\n *\n * @name area\n * @param {GeoJSON} geojson input GeoJSON feature(s)\n * @returns {number} area in square meters\n * @example\n * var polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);\n *\n * var area = turf.area(polygon);\n *\n * //addToMap\n * var addToMap = [polygon]\n * polygon.properties.area = area\n */\nfunction area(geojson) {\n    return meta_1.geomReduce(geojson, function (value, geom) {\n        return value + calculateArea(geom);\n    }, 0);\n}\nexports.default = area;\n/**\n * Calculate Area\n *\n * @private\n * @param {Geometry} geom GeoJSON Geometries\n * @returns {number} area\n */\nfunction calculateArea(geom) {\n    var total = 0;\n    var i;\n    switch (geom.type) {\n        case \"Polygon\":\n            return polygonArea(geom.coordinates);\n        case \"MultiPolygon\":\n            for (i = 0; i < geom.coordinates.length; i++) {\n                total += polygonArea(geom.coordinates[i]);\n            }\n            return total;\n        case \"Point\":\n        case \"MultiPoint\":\n        case \"LineString\":\n        case \"MultiLineString\":\n            return 0;\n    }\n    return 0;\n}\nfunction polygonArea(coords) {\n    var total = 0;\n    if (coords && coords.length > 0) {\n        total += Math.abs(ringArea(coords[0]));\n        for (var i = 1; i < coords.length; i++) {\n            total -= Math.abs(ringArea(coords[i]));\n        }\n    }\n    return total;\n}\n/**\n * @private\n * Calculate the approximate area of the polygon were it projected onto the earth.\n * Note that this area will be positive if ring is oriented clockwise, otherwise it will be negative.\n *\n * Reference:\n * Robert. G. Chamberlain and William H. Duquette, \"Some Algorithms for Polygons on a Sphere\",\n * JPL Publication 07-03, Jet Propulsion\n * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409\n *\n * @param {Array<Array<number>>} coords Ring Coordinates\n * @returns {number} The approximate signed geodesic area of the polygon in square meters.\n */\nfunction ringArea(coords) {\n    var p1;\n    var p2;\n    var p3;\n    var lowerIndex;\n    var middleIndex;\n    var upperIndex;\n    var i;\n    var total = 0;\n    var coordsLength = coords.length;\n    if (coordsLength > 2) {\n        for (i = 0; i < coordsLength; i++) {\n            if (i === coordsLength - 2) {\n                lowerIndex = coordsLength - 2;\n                middleIndex = coordsLength - 1;\n                upperIndex = 0;\n            }\n            else if (i === coordsLength - 1) {\n                lowerIndex = coordsLength - 1;\n                middleIndex = 0;\n                upperIndex = 1;\n            }\n            else {\n                lowerIndex = i;\n                middleIndex = i + 1;\n                upperIndex = i + 2;\n            }\n            p1 = coords[lowerIndex];\n            p2 = coords[middleIndex];\n            p3 = coords[upperIndex];\n            total += (rad(p3[0]) - rad(p1[0])) * Math.sin(rad(p2[1]));\n        }\n        total = total * RADIUS * RADIUS / 2;\n    }\n    return total;\n}\nfunction rad(num) {\n    return num * Math.PI / 180;\n}\n\n},{\"@turf/meta\":58}],56:[function(_dereq_,module,exports){\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar meta_1 = _dereq_(\"@turf/meta\");\nvar helpers_1 = _dereq_(\"@turf/helpers\");\n/**\n * Takes one or more features and calculates the centroid using the mean of all vertices.\n * This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.\n *\n * @name centroid\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties\n * @returns {Feature<Point>} the centroid of the input features\n * @example\n * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);\n *\n * var centroid = turf.centroid(polygon);\n *\n * //addToMap\n * var addToMap = [polygon, centroid]\n */\nfunction centroid(geojson, options) {\n    if (options === void 0) { options = {}; }\n    var xSum = 0;\n    var ySum = 0;\n    var len = 0;\n    meta_1.coordEach(geojson, function (coord) {\n        xSum += coord[0];\n        ySum += coord[1];\n        len++;\n    });\n    return helpers_1.point([xSum / len, ySum / len], options.properties);\n}\nexports.default = centroid;\n\n},{\"@turf/helpers\":57,\"@turf/meta\":58}],57:[function(_dereq_,module,exports){\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * @module helpers\n */\n/**\n * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.\n *\n * @memberof helpers\n * @type {number}\n */\nexports.earthRadius = 6371008.8;\n/**\n * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.\n *\n * @memberof helpers\n * @type {Object}\n */\nexports.factors = {\n    centimeters: exports.earthRadius * 100,\n    centimetres: exports.earthRadius * 100,\n    degrees: exports.earthRadius / 111325,\n    feet: exports.earthRadius * 3.28084,\n    inches: exports.earthRadius * 39.370,\n    kilometers: exports.earthRadius / 1000,\n    kilometres: exports.earthRadius / 1000,\n    meters: exports.earthRadius,\n    metres: exports.earthRadius,\n    miles: exports.earthRadius / 1609.344,\n    millimeters: exports.earthRadius * 1000,\n    millimetres: exports.earthRadius * 1000,\n    nauticalmiles: exports.earthRadius / 1852,\n    radians: 1,\n    yards: exports.earthRadius / 1.0936,\n};\n/**\n * Units of measurement factors based on 1 meter.\n *\n * @memberof helpers\n * @type {Object}\n */\nexports.unitsFactors = {\n    centimeters: 100,\n    centimetres: 100,\n    degrees: 1 / 111325,\n    feet: 3.28084,\n    inches: 39.370,\n    kilometers: 1 / 1000,\n    kilometres: 1 / 1000,\n    meters: 1,\n    metres: 1,\n    miles: 1 / 1609.344,\n    millimeters: 1000,\n    millimetres: 1000,\n    nauticalmiles: 1 / 1852,\n    radians: 1 / exports.earthRadius,\n    yards: 1 / 1.0936,\n};\n/**\n * Area of measurement factors based on 1 square meter.\n *\n * @memberof helpers\n * @type {Object}\n */\nexports.areaFactors = {\n    acres: 0.000247105,\n    centimeters: 10000,\n    centimetres: 10000,\n    feet: 10.763910417,\n    inches: 1550.003100006,\n    kilometers: 0.000001,\n    kilometres: 0.000001,\n    meters: 1,\n    metres: 1,\n    miles: 3.86e-7,\n    millimeters: 1000000,\n    millimetres: 1000000,\n    yards: 1.195990046,\n};\n/**\n * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.\n *\n * @name feature\n * @param {Geometry} geometry input geometry\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a GeoJSON Feature\n * @example\n * var geometry = {\n *   \"type\": \"Point\",\n *   \"coordinates\": [110, 50]\n * };\n *\n * var feature = turf.feature(geometry);\n *\n * //=feature\n */\nfunction feature(geom, properties, options) {\n    if (options === void 0) { options = {}; }\n    var feat = { type: \"Feature\" };\n    if (options.id === 0 || options.id) {\n        feat.id = options.id;\n    }\n    if (options.bbox) {\n        feat.bbox = options.bbox;\n    }\n    feat.properties = properties || {};\n    feat.geometry = geom;\n    return feat;\n}\nexports.feature = feature;\n/**\n * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.\n * For GeometryCollection type use `helpers.geometryCollection`\n *\n * @name geometry\n * @param {string} type Geometry Type\n * @param {Array<any>} coordinates Coordinates\n * @param {Object} [options={}] Optional Parameters\n * @returns {Geometry} a GeoJSON Geometry\n * @example\n * var type = \"Point\";\n * var coordinates = [110, 50];\n * var geometry = turf.geometry(type, coordinates);\n * // => geometry\n */\nfunction geometry(type, coordinates, options) {\n    if (options === void 0) { options = {}; }\n    switch (type) {\n        case \"Point\": return point(coordinates).geometry;\n        case \"LineString\": return lineString(coordinates).geometry;\n        case \"Polygon\": return polygon(coordinates).geometry;\n        case \"MultiPoint\": return multiPoint(coordinates).geometry;\n        case \"MultiLineString\": return multiLineString(coordinates).geometry;\n        case \"MultiPolygon\": return multiPolygon(coordinates).geometry;\n        default: throw new Error(type + \" is invalid\");\n    }\n}\nexports.geometry = geometry;\n/**\n * Creates a {@link Point} {@link Feature} from a Position.\n *\n * @name point\n * @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<Point>} a Point feature\n * @example\n * var point = turf.point([-75.343, 39.984]);\n *\n * //=point\n */\nfunction point(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    var geom = {\n        type: \"Point\",\n        coordinates: coordinates,\n    };\n    return feature(geom, properties, options);\n}\nexports.point = point;\n/**\n * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.\n *\n * @name points\n * @param {Array<Array<number>>} coordinates an array of Points\n * @param {Object} [properties={}] Translate these properties to each Feature\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]\n * associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection<Point>} Point Feature\n * @example\n * var points = turf.points([\n *   [-75, 39],\n *   [-80, 45],\n *   [-78, 50]\n * ]);\n *\n * //=points\n */\nfunction points(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    return featureCollection(coordinates.map(function (coords) {\n        return point(coords, properties);\n    }), options);\n}\nexports.points = points;\n/**\n * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.\n *\n * @name polygon\n * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<Polygon>} Polygon Feature\n * @example\n * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });\n *\n * //=polygon\n */\nfunction polygon(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {\n        var ring = coordinates_1[_i];\n        if (ring.length < 4) {\n            throw new Error(\"Each LinearRing of a Polygon must have 4 or more Positions.\");\n        }\n        for (var j = 0; j < ring[ring.length - 1].length; j++) {\n            // Check if first point of Polygon contains two numbers\n            if (ring[ring.length - 1][j] !== ring[0][j]) {\n                throw new Error(\"First and last Position are not equivalent.\");\n            }\n        }\n    }\n    var geom = {\n        type: \"Polygon\",\n        coordinates: coordinates,\n    };\n    return feature(geom, properties, options);\n}\nexports.polygon = polygon;\n/**\n * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.\n *\n * @name polygons\n * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection<Polygon>} Polygon FeatureCollection\n * @example\n * var polygons = turf.polygons([\n *   [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],\n *   [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],\n * ]);\n *\n * //=polygons\n */\nfunction polygons(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    return featureCollection(coordinates.map(function (coords) {\n        return polygon(coords, properties);\n    }), options);\n}\nexports.polygons = polygons;\n/**\n * Creates a {@link LineString} {@link Feature} from an Array of Positions.\n *\n * @name lineString\n * @param {Array<Array<number>>} coordinates an array of Positions\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<LineString>} LineString Feature\n * @example\n * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});\n * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});\n *\n * //=linestring1\n * //=linestring2\n */\nfunction lineString(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    if (coordinates.length < 2) {\n        throw new Error(\"coordinates must be an array of two or more positions\");\n    }\n    var geom = {\n        type: \"LineString\",\n        coordinates: coordinates,\n    };\n    return feature(geom, properties, options);\n}\nexports.lineString = lineString;\n/**\n * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.\n *\n * @name lineStrings\n * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]\n * associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection<LineString>} LineString FeatureCollection\n * @example\n * var linestrings = turf.lineStrings([\n *   [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],\n *   [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]\n * ]);\n *\n * //=linestrings\n */\nfunction lineStrings(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    return featureCollection(coordinates.map(function (coords) {\n        return lineString(coords, properties);\n    }), options);\n}\nexports.lineStrings = lineStrings;\n/**\n * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.\n *\n * @name featureCollection\n * @param {Feature[]} features input features\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {FeatureCollection} FeatureCollection of Features\n * @example\n * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});\n * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});\n * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});\n *\n * var collection = turf.featureCollection([\n *   locationA,\n *   locationB,\n *   locationC\n * ]);\n *\n * //=collection\n */\nfunction featureCollection(features, options) {\n    if (options === void 0) { options = {}; }\n    var fc = { type: \"FeatureCollection\" };\n    if (options.id) {\n        fc.id = options.id;\n    }\n    if (options.bbox) {\n        fc.bbox = options.bbox;\n    }\n    fc.features = features;\n    return fc;\n}\nexports.featureCollection = featureCollection;\n/**\n * Creates a {@link Feature<MultiLineString>} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiLineString\n * @param {Array<Array<Array<number>>>} coordinates an array of LineStrings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<MultiLineString>} a MultiLineString feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiLine = turf.multiLineString([[[0,0],[10,10]]]);\n *\n * //=multiLine\n */\nfunction multiLineString(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    var geom = {\n        type: \"MultiLineString\",\n        coordinates: coordinates,\n    };\n    return feature(geom, properties, options);\n}\nexports.multiLineString = multiLineString;\n/**\n * Creates a {@link Feature<MultiPoint>} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiPoint\n * @param {Array<Array<number>>} coordinates an array of Positions\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<MultiPoint>} a MultiPoint feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiPt = turf.multiPoint([[0,0],[10,10]]);\n *\n * //=multiPt\n */\nfunction multiPoint(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    var geom = {\n        type: \"MultiPoint\",\n        coordinates: coordinates,\n    };\n    return feature(geom, properties, options);\n}\nexports.multiPoint = multiPoint;\n/**\n * Creates a {@link Feature<MultiPolygon>} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiPolygon\n * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygons\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<MultiPolygon>} a multipolygon feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);\n *\n * //=multiPoly\n *\n */\nfunction multiPolygon(coordinates, properties, options) {\n    if (options === void 0) { options = {}; }\n    var geom = {\n        type: \"MultiPolygon\",\n        coordinates: coordinates,\n    };\n    return feature(geom, properties, options);\n}\nexports.multiPolygon = multiPolygon;\n/**\n * Creates a {@link Feature<GeometryCollection>} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name geometryCollection\n * @param {Array<Geometry>} geometries an array of GeoJSON Geometries\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature\n * @example\n * var pt = turf.geometry(\"Point\", [100, 0]);\n * var line = turf.geometry(\"LineString\", [[101, 0], [102, 1]]);\n * var collection = turf.geometryCollection([pt, line]);\n *\n * // => collection\n */\nfunction geometryCollection(geometries, properties, options) {\n    if (options === void 0) { options = {}; }\n    var geom = {\n        type: \"GeometryCollection\",\n        geometries: geometries,\n    };\n    return feature(geom, properties, options);\n}\nexports.geometryCollection = geometryCollection;\n/**\n * Round number to precision\n *\n * @param {number} num Number\n * @param {number} [precision=0] Precision\n * @returns {number} rounded number\n * @example\n * turf.round(120.4321)\n * //=120\n *\n * turf.round(120.4321, 2)\n * //=120.43\n */\nfunction round(num, precision) {\n    if (precision === void 0) { precision = 0; }\n    if (precision && !(precision >= 0)) {\n        throw new Error(\"precision must be a positive number\");\n    }\n    var multiplier = Math.pow(10, precision || 0);\n    return Math.round(num * multiplier) / multiplier;\n}\nexports.round = round;\n/**\n * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @name radiansToLength\n * @param {number} radians in radians across the sphere\n * @param {string} [units=\"kilometers\"] can be degrees, radians, miles, or kilometers inches, yards, metres,\n * meters, kilometres, kilometers.\n * @returns {number} distance\n */\nfunction radiansToLength(radians, units) {\n    if (units === void 0) { units = \"kilometers\"; }\n    var factor = exports.factors[units];\n    if (!factor) {\n        throw new Error(units + \" units is invalid\");\n    }\n    return radians * factor;\n}\nexports.radiansToLength = radiansToLength;\n/**\n * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @name lengthToRadians\n * @param {number} distance in real units\n * @param {string} [units=\"kilometers\"] can be degrees, radians, miles, or kilometers inches, yards, metres,\n * meters, kilometres, kilometers.\n * @returns {number} radians\n */\nfunction lengthToRadians(distance, units) {\n    if (units === void 0) { units = \"kilometers\"; }\n    var factor = exports.factors[units];\n    if (!factor) {\n        throw new Error(units + \" units is invalid\");\n    }\n    return distance / factor;\n}\nexports.lengthToRadians = lengthToRadians;\n/**\n * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet\n *\n * @name lengthToDegrees\n * @param {number} distance in real units\n * @param {string} [units=\"kilometers\"] can be degrees, radians, miles, or kilometers inches, yards, metres,\n * meters, kilometres, kilometers.\n * @returns {number} degrees\n */\nfunction lengthToDegrees(distance, units) {\n    return radiansToDegrees(lengthToRadians(distance, units));\n}\nexports.lengthToDegrees = lengthToDegrees;\n/**\n * Converts any bearing angle from the north line direction (positive clockwise)\n * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line\n *\n * @name bearingToAzimuth\n * @param {number} bearing angle, between -180 and +180 degrees\n * @returns {number} angle between 0 and 360 degrees\n */\nfunction bearingToAzimuth(bearing) {\n    var angle = bearing % 360;\n    if (angle < 0) {\n        angle += 360;\n    }\n    return angle;\n}\nexports.bearingToAzimuth = bearingToAzimuth;\n/**\n * Converts an angle in radians to degrees\n *\n * @name radiansToDegrees\n * @param {number} radians angle in radians\n * @returns {number} degrees between 0 and 360 degrees\n */\nfunction radiansToDegrees(radians) {\n    var degrees = radians % (2 * Math.PI);\n    return degrees * 180 / Math.PI;\n}\nexports.radiansToDegrees = radiansToDegrees;\n/**\n * Converts an angle in degrees to radians\n *\n * @name degreesToRadians\n * @param {number} degrees angle between 0 and 360 degrees\n * @returns {number} angle in radians\n */\nfunction degreesToRadians(degrees) {\n    var radians = degrees % 360;\n    return radians * Math.PI / 180;\n}\nexports.degreesToRadians = degreesToRadians;\n/**\n * Converts a length to the requested unit.\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @param {number} length to be converted\n * @param {Units} [originalUnit=\"kilometers\"] of the length\n * @param {Units} [finalUnit=\"kilometers\"] returned unit\n * @returns {number} the converted length\n */\nfunction convertLength(length, originalUnit, finalUnit) {\n    if (originalUnit === void 0) { originalUnit = \"kilometers\"; }\n    if (finalUnit === void 0) { finalUnit = \"kilometers\"; }\n    if (!(length >= 0)) {\n        throw new Error(\"length must be a positive number\");\n    }\n    return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);\n}\nexports.convertLength = convertLength;\n/**\n * Converts a area to the requested unit.\n * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches\n * @param {number} area to be converted\n * @param {Units} [originalUnit=\"meters\"] of the distance\n * @param {Units} [finalUnit=\"kilometers\"] returned unit\n * @returns {number} the converted distance\n */\nfunction convertArea(area, originalUnit, finalUnit) {\n    if (originalUnit === void 0) { originalUnit = \"meters\"; }\n    if (finalUnit === void 0) { finalUnit = \"kilometers\"; }\n    if (!(area >= 0)) {\n        throw new Error(\"area must be a positive number\");\n    }\n    var startFactor = exports.areaFactors[originalUnit];\n    if (!startFactor) {\n        throw new Error(\"invalid original units\");\n    }\n    var finalFactor = exports.areaFactors[finalUnit];\n    if (!finalFactor) {\n        throw new Error(\"invalid final units\");\n    }\n    return (area / startFactor) * finalFactor;\n}\nexports.convertArea = convertArea;\n/**\n * isNumber\n *\n * @param {*} num Number to validate\n * @returns {boolean} true/false\n * @example\n * turf.isNumber(123)\n * //=true\n * turf.isNumber('foo')\n * //=false\n */\nfunction isNumber(num) {\n    return !isNaN(num) && num !== null && !Array.isArray(num) && !/^\\s*$/.test(num);\n}\nexports.isNumber = isNumber;\n/**\n * isObject\n *\n * @param {*} input variable to validate\n * @returns {boolean} true/false\n * @example\n * turf.isObject({elevation: 10})\n * //=true\n * turf.isObject('foo')\n * //=false\n */\nfunction isObject(input) {\n    return (!!input) && (input.constructor === Object);\n}\nexports.isObject = isObject;\n/**\n * Validate BBox\n *\n * @private\n * @param {Array<number>} bbox BBox to validate\n * @returns {void}\n * @throws Error if BBox is not valid\n * @example\n * validateBBox([-180, -40, 110, 50])\n * //=OK\n * validateBBox([-180, -40])\n * //=Error\n * validateBBox('Foo')\n * //=Error\n * validateBBox(5)\n * //=Error\n * validateBBox(null)\n * //=Error\n * validateBBox(undefined)\n * //=Error\n */\nfunction validateBBox(bbox) {\n    if (!bbox) {\n        throw new Error(\"bbox is required\");\n    }\n    if (!Array.isArray(bbox)) {\n        throw new Error(\"bbox must be an Array\");\n    }\n    if (bbox.length !== 4 && bbox.length !== 6) {\n        throw new Error(\"bbox must be an Array of 4 or 6 numbers\");\n    }\n    bbox.forEach(function (num) {\n        if (!isNumber(num)) {\n            throw new Error(\"bbox must only contain numbers\");\n        }\n    });\n}\nexports.validateBBox = validateBBox;\n/**\n * Validate Id\n *\n * @private\n * @param {string|number} id Id to validate\n * @returns {void}\n * @throws Error if Id is not valid\n * @example\n * validateId([-180, -40, 110, 50])\n * //=Error\n * validateId([-180, -40])\n * //=Error\n * validateId('Foo')\n * //=OK\n * validateId(5)\n * //=OK\n * validateId(null)\n * //=Error\n * validateId(undefined)\n * //=Error\n */\nfunction validateId(id) {\n    if (!id) {\n        throw new Error(\"id is required\");\n    }\n    if ([\"string\", \"number\"].indexOf(typeof id) === -1) {\n        throw new Error(\"id must be a number or a string\");\n    }\n}\nexports.validateId = validateId;\n// Deprecated methods\nfunction radians2degrees() {\n    throw new Error(\"method has been renamed to `radiansToDegrees`\");\n}\nexports.radians2degrees = radians2degrees;\nfunction degrees2radians() {\n    throw new Error(\"method has been renamed to `degreesToRadians`\");\n}\nexports.degrees2radians = degrees2radians;\nfunction distanceToDegrees() {\n    throw new Error(\"method has been renamed to `lengthToDegrees`\");\n}\nexports.distanceToDegrees = distanceToDegrees;\nfunction distanceToRadians() {\n    throw new Error(\"method has been renamed to `lengthToRadians`\");\n}\nexports.distanceToRadians = distanceToRadians;\nfunction radiansToDistance() {\n    throw new Error(\"method has been renamed to `radiansToLength`\");\n}\nexports.radiansToDistance = radiansToDistance;\nfunction bearingToAngle() {\n    throw new Error(\"method has been renamed to `bearingToAzimuth`\");\n}\nexports.bearingToAngle = bearingToAngle;\nfunction convertDistance() {\n    throw new Error(\"method has been renamed to `convertLength`\");\n}\nexports.convertDistance = convertDistance;\n\n},{}],58:[function(_dereq_,module,exports){\n'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nvar helpers = _dereq_('@turf/helpers');\n\n/**\n * Callback for coordEach\n *\n * @callback coordEachCallback\n * @param {Array<number>} currentCoord The current coordinate being processed.\n * @param {number} coordIndex The current index of the coordinate being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n * @param {number} geometryIndex The current index of the Geometry being processed.\n */\n\n/**\n * Iterate over coordinates in any GeoJSON object, similar to Array.forEach()\n *\n * @name coordEach\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)\n * @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.\n * @returns {void}\n * @example\n * var features = turf.featureCollection([\n *   turf.point([26, 37], {\"foo\": \"bar\"}),\n *   turf.point([36, 53], {\"hello\": \"world\"})\n * ]);\n *\n * turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {\n *   //=currentCoord\n *   //=coordIndex\n *   //=featureIndex\n *   //=multiFeatureIndex\n *   //=geometryIndex\n * });\n */\nfunction coordEach(geojson, callback, excludeWrapCoord) {\n    // Handles null Geometry -- Skips this GeoJSON\n    if (geojson === null) return;\n    var j, k, l, geometry, stopG, coords,\n        geometryMaybeCollection,\n        wrapShrink = 0,\n        coordIndex = 0,\n        isGeometryCollection,\n        type = geojson.type,\n        isFeatureCollection = type === 'FeatureCollection',\n        isFeature = type === 'Feature',\n        stop = isFeatureCollection ? geojson.features.length : 1;\n\n    // This logic may look a little weird. The reason why it is that way\n    // is because it's trying to be fast. GeoJSON supports multiple kinds\n    // of objects at its root: FeatureCollection, Features, Geometries.\n    // This function has the responsibility of handling all of them, and that\n    // means that some of the `for` loops you see below actually just don't apply\n    // to certain inputs. For instance, if you give this just a\n    // Point geometry, then both loops are short-circuited and all we do\n    // is gradually rename the input until it's called 'geometry'.\n    //\n    // This also aims to allocate as few resources as possible: just a\n    // few numbers and booleans, rather than any temporary arrays as would\n    // be required with the normalization approach.\n    for (var featureIndex = 0; featureIndex < stop; featureIndex++) {\n        geometryMaybeCollection = (isFeatureCollection ? geojson.features[featureIndex].geometry :\n            (isFeature ? geojson.geometry : geojson));\n        isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;\n        stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;\n\n        for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {\n            var multiFeatureIndex = 0;\n            var geometryIndex = 0;\n            geometry = isGeometryCollection ?\n                geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;\n\n            // Handles null Geometry -- Skips this geometry\n            if (geometry === null) continue;\n            coords = geometry.coordinates;\n            var geomType = geometry.type;\n\n            wrapShrink = (excludeWrapCoord && (geomType === 'Polygon' || geomType === 'MultiPolygon')) ? 1 : 0;\n\n            switch (geomType) {\n            case null:\n                break;\n            case 'Point':\n                if (callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n                coordIndex++;\n                multiFeatureIndex++;\n                break;\n            case 'LineString':\n            case 'MultiPoint':\n                for (j = 0; j < coords.length; j++) {\n                    if (callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n                    coordIndex++;\n                    if (geomType === 'MultiPoint') multiFeatureIndex++;\n                }\n                if (geomType === 'LineString') multiFeatureIndex++;\n                break;\n            case 'Polygon':\n            case 'MultiLineString':\n                for (j = 0; j < coords.length; j++) {\n                    for (k = 0; k < coords[j].length - wrapShrink; k++) {\n                        if (callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n                        coordIndex++;\n                    }\n                    if (geomType === 'MultiLineString') multiFeatureIndex++;\n                    if (geomType === 'Polygon') geometryIndex++;\n                }\n                if (geomType === 'Polygon') multiFeatureIndex++;\n                break;\n            case 'MultiPolygon':\n                for (j = 0; j < coords.length; j++) {\n                    geometryIndex = 0;\n                    for (k = 0; k < coords[j].length; k++) {\n                        for (l = 0; l < coords[j][k].length - wrapShrink; l++) {\n                            if (callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n                            coordIndex++;\n                        }\n                        geometryIndex++;\n                    }\n                    multiFeatureIndex++;\n                }\n                break;\n            case 'GeometryCollection':\n                for (j = 0; j < geometry.geometries.length; j++)\n                    if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false) return false;\n                break;\n            default:\n                throw new Error('Unknown Geometry Type');\n            }\n        }\n    }\n}\n\n/**\n * Callback for coordReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n *  - The previousValue argument is initialValue.\n *  - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n *  - The previousValue argument is the value of the first element present in the array.\n *  - The currentValue argument is the value of the second element present in the array.\n *\n * @callback coordReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Array<number>} currentCoord The current coordinate being processed.\n * @param {number} coordIndex The current index of the coordinate being processed.\n * Starts at index 0, if an initialValue is provided, and at index 1 otherwise.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n * @param {number} geometryIndex The current index of the Geometry being processed.\n */\n\n/**\n * Reduce coordinates in any GeoJSON object, similar to Array.reduce()\n *\n * @name coordReduce\n * @param {FeatureCollection|Geometry|Feature} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentCoord, coordIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n *   turf.point([26, 37], {\"foo\": \"bar\"}),\n *   turf.point([36, 53], {\"hello\": \"world\"})\n * ]);\n *\n * turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {\n *   //=previousValue\n *   //=currentCoord\n *   //=coordIndex\n *   //=featureIndex\n *   //=multiFeatureIndex\n *   //=geometryIndex\n *   return currentCoord;\n * });\n */\nfunction coordReduce(geojson, callback, initialValue, excludeWrapCoord) {\n    var previousValue = initialValue;\n    coordEach(geojson, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {\n        if (coordIndex === 0 && initialValue === undefined) previousValue = currentCoord;\n        else previousValue = callback(previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex);\n    }, excludeWrapCoord);\n    return previousValue;\n}\n\n/**\n * Callback for propEach\n *\n * @callback propEachCallback\n * @param {Object} currentProperties The current Properties being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n */\n\n/**\n * Iterate over properties in any GeoJSON object, similar to Array.forEach()\n *\n * @name propEach\n * @param {FeatureCollection|Feature} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentProperties, featureIndex)\n * @returns {void}\n * @example\n * var features = turf.featureCollection([\n *     turf.point([26, 37], {foo: 'bar'}),\n *     turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.propEach(features, function (currentProperties, featureIndex) {\n *   //=currentProperties\n *   //=featureIndex\n * });\n */\nfunction propEach(geojson, callback) {\n    var i;\n    switch (geojson.type) {\n    case 'FeatureCollection':\n        for (i = 0; i < geojson.features.length; i++) {\n            if (callback(geojson.features[i].properties, i) === false) break;\n        }\n        break;\n    case 'Feature':\n        callback(geojson.properties, 0);\n        break;\n    }\n}\n\n\n/**\n * Callback for propReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n *  - The previousValue argument is initialValue.\n *  - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n *  - The previousValue argument is the value of the first element present in the array.\n *  - The currentValue argument is the value of the second element present in the array.\n *\n * @callback propReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {*} currentProperties The current Properties being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n */\n\n/**\n * Reduce properties in any GeoJSON object into a single value,\n * similar to how Array.reduce works. However, in this case we lazily run\n * the reduction, so an array of all properties is unnecessary.\n *\n * @name propReduce\n * @param {FeatureCollection|Feature} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentProperties, featureIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n *     turf.point([26, 37], {foo: 'bar'}),\n *     turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {\n *   //=previousValue\n *   //=currentProperties\n *   //=featureIndex\n *   return currentProperties\n * });\n */\nfunction propReduce(geojson, callback, initialValue) {\n    var previousValue = initialValue;\n    propEach(geojson, function (currentProperties, featureIndex) {\n        if (featureIndex === 0 && initialValue === undefined) previousValue = currentProperties;\n        else previousValue = callback(previousValue, currentProperties, featureIndex);\n    });\n    return previousValue;\n}\n\n/**\n * Callback for featureEach\n *\n * @callback featureEachCallback\n * @param {Feature<any>} currentFeature The current Feature being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n */\n\n/**\n * Iterate over features in any GeoJSON object, similar to\n * Array.forEach.\n *\n * @name featureEach\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentFeature, featureIndex)\n * @returns {void}\n * @example\n * var features = turf.featureCollection([\n *   turf.point([26, 37], {foo: 'bar'}),\n *   turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.featureEach(features, function (currentFeature, featureIndex) {\n *   //=currentFeature\n *   //=featureIndex\n * });\n */\nfunction featureEach(geojson, callback) {\n    if (geojson.type === 'Feature') {\n        callback(geojson, 0);\n    } else if (geojson.type === 'FeatureCollection') {\n        for (var i = 0; i < geojson.features.length; i++) {\n            if (callback(geojson.features[i], i) === false) break;\n        }\n    }\n}\n\n/**\n * Callback for featureReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n *  - The previousValue argument is initialValue.\n *  - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n *  - The previousValue argument is the value of the first element present in the array.\n *  - The currentValue argument is the value of the second element present in the array.\n *\n * @callback featureReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Feature} currentFeature The current Feature being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n */\n\n/**\n * Reduce features in any GeoJSON object, similar to Array.reduce().\n *\n * @name featureReduce\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n *   turf.point([26, 37], {\"foo\": \"bar\"}),\n *   turf.point([36, 53], {\"hello\": \"world\"})\n * ]);\n *\n * turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {\n *   //=previousValue\n *   //=currentFeature\n *   //=featureIndex\n *   return currentFeature\n * });\n */\nfunction featureReduce(geojson, callback, initialValue) {\n    var previousValue = initialValue;\n    featureEach(geojson, function (currentFeature, featureIndex) {\n        if (featureIndex === 0 && initialValue === undefined) previousValue = currentFeature;\n        else previousValue = callback(previousValue, currentFeature, featureIndex);\n    });\n    return previousValue;\n}\n\n/**\n * Get all coordinates from any GeoJSON object.\n *\n * @name coordAll\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @returns {Array<Array<number>>} coordinate position array\n * @example\n * var features = turf.featureCollection([\n *   turf.point([26, 37], {foo: 'bar'}),\n *   turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * var coords = turf.coordAll(features);\n * //= [[26, 37], [36, 53]]\n */\nfunction coordAll(geojson) {\n    var coords = [];\n    coordEach(geojson, function (coord) {\n        coords.push(coord);\n    });\n    return coords;\n}\n\n/**\n * Callback for geomEach\n *\n * @callback geomEachCallback\n * @param {Geometry} currentGeometry The current Geometry being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {Object} featureProperties The current Feature Properties being processed.\n * @param {Array<number>} featureBBox The current Feature BBox being processed.\n * @param {number|string} featureId The current Feature Id being processed.\n */\n\n/**\n * Iterate over each geometry in any GeoJSON object, similar to Array.forEach()\n *\n * @name geomEach\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)\n * @returns {void}\n * @example\n * var features = turf.featureCollection([\n *     turf.point([26, 37], {foo: 'bar'}),\n *     turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {\n *   //=currentGeometry\n *   //=featureIndex\n *   //=featureProperties\n *   //=featureBBox\n *   //=featureId\n * });\n */\nfunction geomEach(geojson, callback) {\n    var i, j, g, geometry, stopG,\n        geometryMaybeCollection,\n        isGeometryCollection,\n        featureProperties,\n        featureBBox,\n        featureId,\n        featureIndex = 0,\n        isFeatureCollection = geojson.type === 'FeatureCollection',\n        isFeature = geojson.type === 'Feature',\n        stop = isFeatureCollection ? geojson.features.length : 1;\n\n    // This logic may look a little weird. The reason why it is that way\n    // is because it's trying to be fast. GeoJSON supports multiple kinds\n    // of objects at its root: FeatureCollection, Features, Geometries.\n    // This function has the responsibility of handling all of them, and that\n    // means that some of the `for` loops you see below actually just don't apply\n    // to certain inputs. For instance, if you give this just a\n    // Point geometry, then both loops are short-circuited and all we do\n    // is gradually rename the input until it's called 'geometry'.\n    //\n    // This also aims to allocate as few resources as possible: just a\n    // few numbers and booleans, rather than any temporary arrays as would\n    // be required with the normalization approach.\n    for (i = 0; i < stop; i++) {\n\n        geometryMaybeCollection = (isFeatureCollection ? geojson.features[i].geometry :\n            (isFeature ? geojson.geometry : geojson));\n        featureProperties = (isFeatureCollection ? geojson.features[i].properties :\n            (isFeature ? geojson.properties : {}));\n        featureBBox = (isFeatureCollection ? geojson.features[i].bbox :\n            (isFeature ? geojson.bbox : undefined));\n        featureId = (isFeatureCollection ? geojson.features[i].id :\n            (isFeature ? geojson.id : undefined));\n        isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;\n        stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;\n\n        for (g = 0; g < stopG; g++) {\n            geometry = isGeometryCollection ?\n                geometryMaybeCollection.geometries[g] : geometryMaybeCollection;\n\n            // Handle null Geometry\n            if (geometry === null) {\n                if (callback(null, featureIndex, featureProperties, featureBBox, featureId) === false) return false;\n                continue;\n            }\n            switch (geometry.type) {\n            case 'Point':\n            case 'LineString':\n            case 'MultiPoint':\n            case 'Polygon':\n            case 'MultiLineString':\n            case 'MultiPolygon': {\n                if (callback(geometry, featureIndex, featureProperties, featureBBox, featureId) === false) return false;\n                break;\n            }\n            case 'GeometryCollection': {\n                for (j = 0; j < geometry.geometries.length; j++) {\n                    if (callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId) === false) return false;\n                }\n                break;\n            }\n            default:\n                throw new Error('Unknown Geometry Type');\n            }\n        }\n        // Only increase `featureIndex` per each feature\n        featureIndex++;\n    }\n}\n\n/**\n * Callback for geomReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n *  - The previousValue argument is initialValue.\n *  - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n *  - The previousValue argument is the value of the first element present in the array.\n *  - The currentValue argument is the value of the second element present in the array.\n *\n * @callback geomReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Geometry} currentGeometry The current Geometry being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {Object} featureProperties The current Feature Properties being processed.\n * @param {Array<number>} featureBBox The current Feature BBox being processed.\n * @param {number|string} featureId The current Feature Id being processed.\n */\n\n/**\n * Reduce geometry in any GeoJSON object, similar to Array.reduce().\n *\n * @name geomReduce\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n *     turf.point([26, 37], {foo: 'bar'}),\n *     turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {\n *   //=previousValue\n *   //=currentGeometry\n *   //=featureIndex\n *   //=featureProperties\n *   //=featureBBox\n *   //=featureId\n *   return currentGeometry\n * });\n */\nfunction geomReduce(geojson, callback, initialValue) {\n    var previousValue = initialValue;\n    geomEach(geojson, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {\n        if (featureIndex === 0 && initialValue === undefined) previousValue = currentGeometry;\n        else previousValue = callback(previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId);\n    });\n    return previousValue;\n}\n\n/**\n * Callback for flattenEach\n *\n * @callback flattenEachCallback\n * @param {Feature} currentFeature The current flattened feature being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n */\n\n/**\n * Iterate over flattened features in any GeoJSON object, similar to\n * Array.forEach.\n *\n * @name flattenEach\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex)\n * @example\n * var features = turf.featureCollection([\n *     turf.point([26, 37], {foo: 'bar'}),\n *     turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})\n * ]);\n *\n * turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {\n *   //=currentFeature\n *   //=featureIndex\n *   //=multiFeatureIndex\n * });\n */\nfunction flattenEach(geojson, callback) {\n    geomEach(geojson, function (geometry, featureIndex, properties, bbox, id) {\n        // Callback for single geometry\n        var type = (geometry === null) ? null : geometry.type;\n        switch (type) {\n        case null:\n        case 'Point':\n        case 'LineString':\n        case 'Polygon':\n            if (callback(helpers.feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0) === false) return false;\n            return;\n        }\n\n        var geomType;\n\n        // Callback for multi-geometry\n        switch (type) {\n        case 'MultiPoint':\n            geomType = 'Point';\n            break;\n        case 'MultiLineString':\n            geomType = 'LineString';\n            break;\n        case 'MultiPolygon':\n            geomType = 'Polygon';\n            break;\n        }\n\n        for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {\n            var coordinate = geometry.coordinates[multiFeatureIndex];\n            var geom = {\n                type: geomType,\n                coordinates: coordinate\n            };\n            if (callback(helpers.feature(geom, properties), featureIndex, multiFeatureIndex) === false) return false;\n        }\n    });\n}\n\n/**\n * Callback for flattenReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n *  - The previousValue argument is initialValue.\n *  - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n *  - The previousValue argument is the value of the first element present in the array.\n *  - The currentValue argument is the value of the second element present in the array.\n *\n * @callback flattenReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Feature} currentFeature The current Feature being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n */\n\n/**\n * Reduce flattened features in any GeoJSON object, similar to Array.reduce().\n *\n * @name flattenReduce\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n *     turf.point([26, 37], {foo: 'bar'}),\n *     turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})\n * ]);\n *\n * turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {\n *   //=previousValue\n *   //=currentFeature\n *   //=featureIndex\n *   //=multiFeatureIndex\n *   return currentFeature\n * });\n */\nfunction flattenReduce(geojson, callback, initialValue) {\n    var previousValue = initialValue;\n    flattenEach(geojson, function (currentFeature, featureIndex, multiFeatureIndex) {\n        if (featureIndex === 0 && multiFeatureIndex === 0 && initialValue === undefined) previousValue = currentFeature;\n        else previousValue = callback(previousValue, currentFeature, featureIndex, multiFeatureIndex);\n    });\n    return previousValue;\n}\n\n/**\n * Callback for segmentEach\n *\n * @callback segmentEachCallback\n * @param {Feature<LineString>} currentSegment The current Segment being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n * @param {number} geometryIndex The current index of the Geometry being processed.\n * @param {number} segmentIndex The current index of the Segment being processed.\n * @returns {void}\n */\n\n/**\n * Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach()\n * (Multi)Point geometries do not contain segments therefore they are ignored during this operation.\n *\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON\n * @param {Function} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)\n * @returns {void}\n * @example\n * var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);\n *\n * // Iterate over GeoJSON by 2-vertex segments\n * turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {\n *   //=currentSegment\n *   //=featureIndex\n *   //=multiFeatureIndex\n *   //=geometryIndex\n *   //=segmentIndex\n * });\n *\n * // Calculate the total number of segments\n * var total = 0;\n * turf.segmentEach(polygon, function () {\n *     total++;\n * });\n */\nfunction segmentEach(geojson, callback) {\n    flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) {\n        var segmentIndex = 0;\n\n        // Exclude null Geometries\n        if (!feature.geometry) return;\n        // (Multi)Point geometries do not contain segments therefore they are ignored during this operation.\n        var type = feature.geometry.type;\n        if (type === 'Point' || type === 'MultiPoint') return;\n\n        // Generate 2-vertex line segments\n        var previousCoords;\n        var previousFeatureIndex = 0;\n        var previousMultiIndex = 0;\n        var prevGeomIndex = 0;\n        if (coordEach(feature, function (currentCoord, coordIndex, featureIndexCoord, multiPartIndexCoord, geometryIndex) {\n            // Simulating a meta.coordReduce() since `reduce` operations cannot be stopped by returning `false`\n            if (previousCoords === undefined || featureIndex > previousFeatureIndex || multiPartIndexCoord > previousMultiIndex || geometryIndex > prevGeomIndex) {\n                previousCoords = currentCoord;\n                previousFeatureIndex = featureIndex;\n                previousMultiIndex = multiPartIndexCoord;\n                prevGeomIndex = geometryIndex;\n                segmentIndex = 0;\n                return;\n            }\n            var currentSegment = helpers.lineString([previousCoords, currentCoord], feature.properties);\n            if (callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) === false) return false;\n            segmentIndex++;\n            previousCoords = currentCoord;\n        }) === false) return false;\n    });\n}\n\n/**\n * Callback for segmentReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n *  - The previousValue argument is initialValue.\n *  - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n *  - The previousValue argument is the value of the first element present in the array.\n *  - The currentValue argument is the value of the second element present in the array.\n *\n * @callback segmentReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Feature<LineString>} currentSegment The current Segment being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n * @param {number} geometryIndex The current index of the Geometry being processed.\n * @param {number} segmentIndex The current index of the Segment being processed.\n */\n\n/**\n * Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce()\n * (Multi)Point geometries do not contain segments therefore they are ignored during this operation.\n *\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON\n * @param {Function} callback a method that takes (previousValue, currentSegment, currentIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {void}\n * @example\n * var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);\n *\n * // Iterate over GeoJSON by 2-vertex segments\n * turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {\n *   //= previousSegment\n *   //= currentSegment\n *   //= featureIndex\n *   //= multiFeatureIndex\n *   //= geometryIndex\n *   //= segmentInex\n *   return currentSegment\n * });\n *\n * // Calculate the total number of segments\n * var initialValue = 0\n * var total = turf.segmentReduce(polygon, function (previousValue) {\n *     previousValue++;\n *     return previousValue;\n * }, initialValue);\n */\nfunction segmentReduce(geojson, callback, initialValue) {\n    var previousValue = initialValue;\n    var started = false;\n    segmentEach(geojson, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {\n        if (started === false && initialValue === undefined) previousValue = currentSegment;\n        else previousValue = callback(previousValue, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex);\n        started = true;\n    });\n    return previousValue;\n}\n\n/**\n * Callback for lineEach\n *\n * @callback lineEachCallback\n * @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed\n * @param {number} featureIndex The current index of the Feature being processed\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed\n * @param {number} geometryIndex The current index of the Geometry being processed\n */\n\n/**\n * Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries,\n * similar to Array.forEach.\n *\n * @name lineEach\n * @param {Geometry|Feature<LineString|Polygon|MultiLineString|MultiPolygon>} geojson object\n * @param {Function} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex)\n * @example\n * var multiLine = turf.multiLineString([\n *   [[26, 37], [35, 45]],\n *   [[36, 53], [38, 50], [41, 55]]\n * ]);\n *\n * turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {\n *   //=currentLine\n *   //=featureIndex\n *   //=multiFeatureIndex\n *   //=geometryIndex\n * });\n */\nfunction lineEach(geojson, callback) {\n    // validation\n    if (!geojson) throw new Error('geojson is required');\n\n    flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) {\n        if (feature.geometry === null) return;\n        var type = feature.geometry.type;\n        var coords = feature.geometry.coordinates;\n        switch (type) {\n        case 'LineString':\n            if (callback(feature, featureIndex, multiFeatureIndex, 0, 0) === false) return false;\n            break;\n        case 'Polygon':\n            for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {\n                if (callback(helpers.lineString(coords[geometryIndex], feature.properties), featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n            }\n            break;\n        }\n    });\n}\n\n/**\n * Callback for lineReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n *  - The previousValue argument is initialValue.\n *  - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n *  - The previousValue argument is the value of the first element present in the array.\n *  - The currentValue argument is the value of the second element present in the array.\n *\n * @callback lineReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed.\n * @param {number} featureIndex The current index of the Feature being processed\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed\n * @param {number} geometryIndex The current index of the Geometry being processed\n */\n\n/**\n * Reduce features in any GeoJSON object, similar to Array.reduce().\n *\n * @name lineReduce\n * @param {Geometry|Feature<LineString|Polygon|MultiLineString|MultiPolygon>} geojson object\n * @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var multiPoly = turf.multiPolygon([\n *   turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),\n *   turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])\n * ]);\n *\n * turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) {\n *   //=previousValue\n *   //=currentLine\n *   //=featureIndex\n *   //=multiFeatureIndex\n *   //=geometryIndex\n *   return currentLine\n * });\n */\nfunction lineReduce(geojson, callback, initialValue) {\n    var previousValue = initialValue;\n    lineEach(geojson, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {\n        if (featureIndex === 0 && initialValue === undefined) previousValue = currentLine;\n        else previousValue = callback(previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex);\n    });\n    return previousValue;\n}\n\n/**\n * Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.\n *\n * Negative indexes are permitted.\n * Point & MultiPoint will always return null.\n *\n * @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.featureIndex=0] Feature Index\n * @param {number} [options.multiFeatureIndex=0] Multi-Feature Index\n * @param {number} [options.geometryIndex=0] Geometry Index\n * @param {number} [options.segmentIndex=0] Segment Index\n * @param {Object} [options.properties={}] Translate Properties to output LineString\n * @param {BBox} [options.bbox={}] Translate BBox to output LineString\n * @param {number|string} [options.id={}] Translate Id to output LineString\n * @returns {Feature<LineString>} 2-vertex GeoJSON Feature LineString\n * @example\n * var multiLine = turf.multiLineString([\n *     [[10, 10], [50, 30], [30, 40]],\n *     [[-10, -10], [-50, -30], [-30, -40]]\n * ]);\n *\n * // First Segment (defaults are 0)\n * turf.findSegment(multiLine);\n * // => Feature<LineString<[[10, 10], [50, 30]]>>\n *\n * // First Segment of 2nd Multi Feature\n * turf.findSegment(multiLine, {multiFeatureIndex: 1});\n * // => Feature<LineString<[[-10, -10], [-50, -30]]>>\n *\n * // Last Segment of Last Multi Feature\n * turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});\n * // => Feature<LineString<[[-50, -30], [-30, -40]]>>\n */\nfunction findSegment(geojson, options) {\n    // Optional Parameters\n    options = options || {};\n    if (!helpers.isObject(options)) throw new Error('options is invalid');\n    var featureIndex = options.featureIndex || 0;\n    var multiFeatureIndex = options.multiFeatureIndex || 0;\n    var geometryIndex = options.geometryIndex || 0;\n    var segmentIndex = options.segmentIndex || 0;\n\n    // Find FeatureIndex\n    var properties = options.properties;\n    var geometry;\n\n    switch (geojson.type) {\n    case 'FeatureCollection':\n        if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;\n        properties = properties || geojson.features[featureIndex].properties;\n        geometry = geojson.features[featureIndex].geometry;\n        break;\n    case 'Feature':\n        properties = properties || geojson.properties;\n        geometry = geojson.geometry;\n        break;\n    case 'Point':\n    case 'MultiPoint':\n        return null;\n    case 'LineString':\n    case 'Polygon':\n    case 'MultiLineString':\n    case 'MultiPolygon':\n        geometry = geojson;\n        break;\n    default:\n        throw new Error('geojson is invalid');\n    }\n\n    // Find SegmentIndex\n    if (geometry === null) return null;\n    var coords = geometry.coordinates;\n    switch (geometry.type) {\n    case 'Point':\n    case 'MultiPoint':\n        return null;\n    case 'LineString':\n        if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;\n        return helpers.lineString([coords[segmentIndex], coords[segmentIndex + 1]], properties, options);\n    case 'Polygon':\n        if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;\n        if (segmentIndex < 0) segmentIndex = coords[geometryIndex].length + segmentIndex - 1;\n        return helpers.lineString([coords[geometryIndex][segmentIndex], coords[geometryIndex][segmentIndex + 1]], properties, options);\n    case 'MultiLineString':\n        if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n        if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;\n        return helpers.lineString([coords[multiFeatureIndex][segmentIndex], coords[multiFeatureIndex][segmentIndex + 1]], properties, options);\n    case 'MultiPolygon':\n        if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n        if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;\n        if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;\n        return helpers.lineString([coords[multiFeatureIndex][geometryIndex][segmentIndex], coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]], properties, options);\n    }\n    throw new Error('geojson is invalid');\n}\n\n/**\n * Finds a particular Point from a GeoJSON using `@turf/meta` indexes.\n *\n * Negative indexes are permitted.\n *\n * @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.featureIndex=0] Feature Index\n * @param {number} [options.multiFeatureIndex=0] Multi-Feature Index\n * @param {number} [options.geometryIndex=0] Geometry Index\n * @param {number} [options.coordIndex=0] Coord Index\n * @param {Object} [options.properties={}] Translate Properties to output Point\n * @param {BBox} [options.bbox={}] Translate BBox to output Point\n * @param {number|string} [options.id={}] Translate Id to output Point\n * @returns {Feature<Point>} 2-vertex GeoJSON Feature Point\n * @example\n * var multiLine = turf.multiLineString([\n *     [[10, 10], [50, 30], [30, 40]],\n *     [[-10, -10], [-50, -30], [-30, -40]]\n * ]);\n *\n * // First Segment (defaults are 0)\n * turf.findPoint(multiLine);\n * // => Feature<Point<[10, 10]>>\n *\n * // First Segment of the 2nd Multi-Feature\n * turf.findPoint(multiLine, {multiFeatureIndex: 1});\n * // => Feature<Point<[-10, -10]>>\n *\n * // Last Segment of last Multi-Feature\n * turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});\n * // => Feature<Point<[-30, -40]>>\n */\nfunction findPoint(geojson, options) {\n    // Optional Parameters\n    options = options || {};\n    if (!helpers.isObject(options)) throw new Error('options is invalid');\n    var featureIndex = options.featureIndex || 0;\n    var multiFeatureIndex = options.multiFeatureIndex || 0;\n    var geometryIndex = options.geometryIndex || 0;\n    var coordIndex = options.coordIndex || 0;\n\n    // Find FeatureIndex\n    var properties = options.properties;\n    var geometry;\n\n    switch (geojson.type) {\n    case 'FeatureCollection':\n        if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;\n        properties = properties || geojson.features[featureIndex].properties;\n        geometry = geojson.features[featureIndex].geometry;\n        break;\n    case 'Feature':\n        properties = properties || geojson.properties;\n        geometry = geojson.geometry;\n        break;\n    case 'Point':\n    case 'MultiPoint':\n        return null;\n    case 'LineString':\n    case 'Polygon':\n    case 'MultiLineString':\n    case 'MultiPolygon':\n        geometry = geojson;\n        break;\n    default:\n        throw new Error('geojson is invalid');\n    }\n\n    // Find Coord Index\n    if (geometry === null) return null;\n    var coords = geometry.coordinates;\n    switch (geometry.type) {\n    case 'Point':\n        return helpers.point(coords, properties, options);\n    case 'MultiPoint':\n        if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n        return helpers.point(coords[multiFeatureIndex], properties, options);\n    case 'LineString':\n        if (coordIndex < 0) coordIndex = coords.length + coordIndex;\n        return helpers.point(coords[coordIndex], properties, options);\n    case 'Polygon':\n        if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;\n        if (coordIndex < 0) coordIndex = coords[geometryIndex].length + coordIndex;\n        return helpers.point(coords[geometryIndex][coordIndex], properties, options);\n    case 'MultiLineString':\n        if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n        if (coordIndex < 0) coordIndex = coords[multiFeatureIndex].length + coordIndex;\n        return helpers.point(coords[multiFeatureIndex][coordIndex], properties, options);\n    case 'MultiPolygon':\n        if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n        if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;\n        if (coordIndex < 0) coordIndex = coords[multiFeatureIndex][geometryIndex].length - coordIndex;\n        return helpers.point(coords[multiFeatureIndex][geometryIndex][coordIndex], properties, options);\n    }\n    throw new Error('geojson is invalid');\n}\n\nexports.coordEach = coordEach;\nexports.coordReduce = coordReduce;\nexports.propEach = propEach;\nexports.propReduce = propReduce;\nexports.featureEach = featureEach;\nexports.featureReduce = featureReduce;\nexports.coordAll = coordAll;\nexports.geomEach = geomEach;\nexports.geomReduce = geomReduce;\nexports.flattenEach = flattenEach;\nexports.flattenReduce = flattenReduce;\nexports.segmentEach = segmentEach;\nexports.segmentReduce = segmentReduce;\nexports.lineEach = lineEach;\nexports.lineReduce = lineReduce;\nexports.findSegment = findSegment;\nexports.findPoint = findPoint;\n\n},{\"@turf/helpers\":57}],59:[function(_dereq_,module,exports){\n'use strict'\n\nvar weakMap      = typeof WeakMap === 'undefined' ? _dereq_('weak-map') : WeakMap\nvar createBuffer = _dereq_('gl-buffer')\nvar createVAO    = _dereq_('gl-vao')\n\nvar TriangleCache = new weakMap()\n\nfunction createABigTriangle(gl) {\n\n  var triangleVAO = TriangleCache.get(gl)\n  var handle = triangleVAO && (triangleVAO._triangleBuffer.handle || triangleVAO._triangleBuffer.buffer)\n  if(!handle || !gl.isBuffer(handle)) {\n    var buf = createBuffer(gl, new Float32Array([-1, -1, -1, 4, 4, -1]))\n    triangleVAO = createVAO(gl, [\n      { buffer: buf,\n        type: gl.FLOAT,\n        size: 2\n      }\n    ])\n    triangleVAO._triangleBuffer = buf\n    TriangleCache.set(gl, triangleVAO)\n  }\n  triangleVAO.bind()\n  gl.drawArrays(gl.TRIANGLES, 0, 3)\n  triangleVAO.unbind()\n}\n\nmodule.exports = createABigTriangle\n\n},{\"gl-buffer\":241,\"gl-vao\":327,\"weak-map\":552}],60:[function(_dereq_,module,exports){\n\nmodule.exports = absolutize\n\n/**\n * redefine `path` with absolute coordinates\n *\n * @param {Array} path\n * @return {Array}\n */\n\nfunction absolutize(path){\n\tvar startX = 0\n\tvar startY = 0\n\tvar x = 0\n\tvar y = 0\n\n\treturn path.map(function(seg){\n\t\tseg = seg.slice()\n\t\tvar type = seg[0]\n\t\tvar command = type.toUpperCase()\n\n\t\t// is relative\n\t\tif (type != command) {\n\t\t\tseg[0] = command\n\t\t\tswitch (type) {\n\t\t\t\tcase 'a':\n\t\t\t\t\tseg[6] += x\n\t\t\t\t\tseg[7] += y\n\t\t\t\t\tbreak\n\t\t\t\tcase 'v':\n\t\t\t\t\tseg[1] += y\n\t\t\t\t\tbreak\n\t\t\t\tcase 'h':\n\t\t\t\t\tseg[1] += x\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tfor (var i = 1; i < seg.length;) {\n\t\t\t\t\t\tseg[i++] += x\n\t\t\t\t\t\tseg[i++] += y\n\t\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// update cursor state\n\t\tswitch (command) {\n\t\t\tcase 'Z':\n\t\t\t\tx = startX\n\t\t\t\ty = startY\n\t\t\t\tbreak\n\t\t\tcase 'H':\n\t\t\t\tx = seg[1]\n\t\t\t\tbreak\n\t\t\tcase 'V':\n\t\t\t\ty = seg[1]\n\t\t\t\tbreak\n\t\t\tcase 'M':\n\t\t\t\tx = startX = seg[1]\n\t\t\t\ty = startY = seg[2]\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\tx = seg[seg.length - 2]\n\t\t\t\ty = seg[seg.length - 1]\n\t\t}\n\n\t\treturn seg\n\t})\n}\n\n},{}],61:[function(_dereq_,module,exports){\nvar padLeft = _dereq_('pad-left')\n\nmodule.exports = addLineNumbers\nfunction addLineNumbers (string, start, delim) {\n  start = typeof start === 'number' ? start : 1\n  delim = delim || ': '\n\n  var lines = string.split(/\\r?\\n/)\n  var totalDigits = String(lines.length + start - 1).length\n  return lines.map(function (line, i) {\n    var c = i + start\n    var digits = String(c).length\n    var prefix = padLeft(c, totalDigits - digits)\n    return prefix + delim + line\n  }).join('\\n')\n}\n\n},{\"pad-left\":457}],62:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = affineHull\n\nvar orient = _dereq_('robust-orientation')\n\nfunction linearlyIndependent(points, d) {\n  var nhull = new Array(d+1)\n  for(var i=0; i<points.length; ++i) {\n    nhull[i] = points[i]\n  }\n  for(var i=0; i<=points.length; ++i) {\n    for(var j=points.length; j<=d; ++j) {\n      var x = new Array(d)\n      for(var k=0; k<d; ++k) {\n        x[k] = Math.pow(j+1-i, k)\n      }\n      nhull[j] = x\n    }\n    var o = orient.apply(void 0, nhull)\n    if(o) {\n      return true\n    }\n  }\n  return false\n}\n\nfunction affineHull(points) {\n  var n = points.length\n  if(n === 0) {\n    return []\n  }\n  if(n === 1) {\n    return [0]\n  }\n  var d = points[0].length\n  var frame = [ points[0] ]\n  var index = [ 0 ]\n  for(var i=1; i<n; ++i) {\n    frame.push(points[i])\n    if(!linearlyIndependent(frame, d)) {\n      frame.pop()\n      continue\n    }\n    index.push(i)\n    if(index.length === d+1) {\n      return index\n    }\n  }\n  return index\n}\n},{\"robust-orientation\":510}],63:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = alphaComplex\n\nvar delaunay = _dereq_('delaunay-triangulate')\nvar circumradius = _dereq_('circumradius')\n\nfunction alphaComplex(alpha, points) {\n  return delaunay(points).filter(function(cell) {\n    var simplex = new Array(cell.length)\n    for(var i=0; i<cell.length; ++i) {\n      simplex[i] = points[cell[i]]\n    }\n    return circumradius(simplex) * alpha < 1\n  })\n}\n},{\"circumradius\":114,\"delaunay-triangulate\":165}],64:[function(_dereq_,module,exports){\nmodule.exports = alphaShape\n\nvar ac = _dereq_('alpha-complex')\nvar bnd = _dereq_('simplicial-complex-boundary')\n\nfunction alphaShape(alpha, points) {\n  return bnd(ac(alpha, points))\n}\n},{\"alpha-complex\":63,\"simplicial-complex-boundary\":517}],65:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nmodule.exports = normalize;\r\n\r\nfunction normalize (arr, dim) {\r\n\tif (!arr || arr.length == null) throw Error('Argument should be an array')\r\n\r\n\tif (dim == null) dim = 1\r\n\telse dim = Math.floor(dim)\r\n\r\n\tvar bounds = Array(dim * 2)\r\n\r\n\tfor (var offset = 0; offset < dim; offset++) {\r\n\t\tvar max = -Infinity, min = Infinity, i = offset, l = arr.length;\r\n\r\n\t\tfor (; i < l; i+=dim) {\r\n\t\t\tif (arr[i] > max) max = arr[i];\r\n\t\t\tif (arr[i] < min) min = arr[i];\r\n\t\t}\r\n\r\n\t\tbounds[offset] = min\r\n\t\tbounds[dim + offset] = max\r\n\t}\r\n\r\n\treturn bounds;\r\n}\r\n\n},{}],66:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar getBounds = _dereq_('array-bounds')\r\n\r\nmodule.exports = normalize;\r\n\r\nfunction normalize (arr, dim, bounds) {\r\n\tif (!arr || arr.length == null) throw Error('Argument should be an array')\r\n\r\n\tif (dim == null) dim = 1\r\n\tif (bounds == null) bounds = getBounds(arr, dim)\r\n\r\n\tfor (var offset = 0; offset < dim; offset++) {\r\n\t\tvar max = bounds[dim + offset], min = bounds[offset], i = offset, l = arr.length;\r\n\r\n\t\tif (max === Infinity && min === -Infinity) {\r\n\t\t\tfor (i = offset; i < l; i+=dim) {\r\n\t\t\t\tarr[i] = arr[i] === max ? 1 : arr[i] === min ? 0 : .5\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (max === Infinity) {\r\n\t\t\tfor (i = offset; i < l; i+=dim) {\r\n\t\t\t\tarr[i] = arr[i] === max ? 1 : 0\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (min === -Infinity) {\r\n\t\t\tfor (i = offset; i < l; i+=dim) {\r\n\t\t\t\tarr[i] = arr[i] === min ? 0 : 1\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\tvar range = max - min\r\n\t\t\tfor (i = offset; i < l; i+=dim) {\r\n\t\t\t\tarr[i] = range === 0 ? .5 : (arr[i] - min) / range\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn arr;\r\n}\r\n\n},{\"array-bounds\":65}],67:[function(_dereq_,module,exports){\n\nmodule.exports = function newArray(start, end) {\n    var n0 = typeof start === 'number',\n        n1 = typeof end === 'number'\n\n    if (n0 && !n1) {\n        end = start\n        start = 0\n    } else if (!n0 && !n1) {\n        start = 0\n        end = 0\n    }\n\n    start = start|0\n    end = end|0\n    var len = end-start\n    if (len<0)\n        throw new Error('array length must be positive')\n    \n    var a = new Array(len)\n    for (var i=0, c=start; i<len; i++, c++)\n        a[i] = c\n    return a\n}\n},{}],68:[function(_dereq_,module,exports){\n(function (global){\n'use strict';\n\nvar objectAssign = _dereq_('object-assign');\n\n// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js\n// original notice:\n\n/*!\n * The buffer module from node.js, for the browser.\n *\n * @author   Feross Aboukhadijeh <feross@feross.org> <http://feross.org>\n * @license  MIT\n */\nfunction compare(a, b) {\n  if (a === b) {\n    return 0;\n  }\n\n  var x = a.length;\n  var y = b.length;\n\n  for (var i = 0, len = Math.min(x, y); i < len; ++i) {\n    if (a[i] !== b[i]) {\n      x = a[i];\n      y = b[i];\n      break;\n    }\n  }\n\n  if (x < y) {\n    return -1;\n  }\n  if (y < x) {\n    return 1;\n  }\n  return 0;\n}\nfunction isBuffer(b) {\n  if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {\n    return global.Buffer.isBuffer(b);\n  }\n  return !!(b != null && b._isBuffer);\n}\n\n// based on node assert, original notice:\n// NB: The URL to the CommonJS spec is kept just for tradition.\n//     node-assert has evolved a lot since then, both in API and behavior.\n\n// http://wiki.commonjs.org/wiki/Unit_Testing/1.0\n//\n// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!\n//\n// Originally from narwhal.js (http://narwhaljs.org)\n// Copyright (c) 2009 Thomas Robinson <280north.com>\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the 'Software'), to\n// deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n// sell copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\n// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nvar util = _dereq_('util/');\nvar hasOwn = Object.prototype.hasOwnProperty;\nvar pSlice = Array.prototype.slice;\nvar functionsHaveNames = (function () {\n  return function foo() {}.name === 'foo';\n}());\nfunction pToString (obj) {\n  return Object.prototype.toString.call(obj);\n}\nfunction isView(arrbuf) {\n  if (isBuffer(arrbuf)) {\n    return false;\n  }\n  if (typeof global.ArrayBuffer !== 'function') {\n    return false;\n  }\n  if (typeof ArrayBuffer.isView === 'function') {\n    return ArrayBuffer.isView(arrbuf);\n  }\n  if (!arrbuf) {\n    return false;\n  }\n  if (arrbuf instanceof DataView) {\n    return true;\n  }\n  if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {\n    return true;\n  }\n  return false;\n}\n// 1. The assert module provides functions that throw\n// AssertionError's when particular conditions are not met. The\n// assert module must conform to the following interface.\n\nvar assert = module.exports = ok;\n\n// 2. The AssertionError is defined in assert.\n// new assert.AssertionError({ message: message,\n//                             actual: actual,\n//                             expected: expected })\n\nvar regex = /\\s*function\\s+([^\\(\\s]*)\\s*/;\n// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js\nfunction getName(func) {\n  if (!util.isFunction(func)) {\n    return;\n  }\n  if (functionsHaveNames) {\n    return func.name;\n  }\n  var str = func.toString();\n  var match = str.match(regex);\n  return match && match[1];\n}\nassert.AssertionError = function AssertionError(options) {\n  this.name = 'AssertionError';\n  this.actual = options.actual;\n  this.expected = options.expected;\n  this.operator = options.operator;\n  if (options.message) {\n    this.message = options.message;\n    this.generatedMessage = false;\n  } else {\n    this.message = getMessage(this);\n    this.generatedMessage = true;\n  }\n  var stackStartFunction = options.stackStartFunction || fail;\n  if (Error.captureStackTrace) {\n    Error.captureStackTrace(this, stackStartFunction);\n  } else {\n    // non v8 browsers so we can have a stacktrace\n    var err = new Error();\n    if (err.stack) {\n      var out = err.stack;\n\n      // try to strip useless frames\n      var fn_name = getName(stackStartFunction);\n      var idx = out.indexOf('\\n' + fn_name);\n      if (idx >= 0) {\n        // once we have located the function frame\n        // we need to strip out everything before it (and its line)\n        var next_line = out.indexOf('\\n', idx + 1);\n        out = out.substring(next_line + 1);\n      }\n\n      this.stack = out;\n    }\n  }\n};\n\n// assert.AssertionError instanceof Error\nutil.inherits(assert.AssertionError, Error);\n\nfunction truncate(s, n) {\n  if (typeof s === 'string') {\n    return s.length < n ? s : s.slice(0, n);\n  } else {\n    return s;\n  }\n}\nfunction inspect(something) {\n  if (functionsHaveNames || !util.isFunction(something)) {\n    return util.inspect(something);\n  }\n  var rawname = getName(something);\n  var name = rawname ? ': ' + rawname : '';\n  return '[Function' +  name + ']';\n}\nfunction getMessage(self) {\n  return truncate(inspect(self.actual), 128) + ' ' +\n         self.operator + ' ' +\n         truncate(inspect(self.expected), 128);\n}\n\n// At present only the three keys mentioned above are used and\n// understood by the spec. Implementations or sub modules can pass\n// other keys to the AssertionError's constructor - they will be\n// ignored.\n\n// 3. All of the following functions must throw an AssertionError\n// when a corresponding condition is not met, with a message that\n// may be undefined if not provided.  All assertion methods provide\n// both the actual and expected values to the assertion error for\n// display purposes.\n\nfunction fail(actual, expected, message, operator, stackStartFunction) {\n  throw new assert.AssertionError({\n    message: message,\n    actual: actual,\n    expected: expected,\n    operator: operator,\n    stackStartFunction: stackStartFunction\n  });\n}\n\n// EXTENSION! allows for well behaved errors defined elsewhere.\nassert.fail = fail;\n\n// 4. Pure assertion tests whether a value is truthy, as determined\n// by !!guard.\n// assert.ok(guard, message_opt);\n// This statement is equivalent to assert.equal(true, !!guard,\n// message_opt);. To test strictly for the value true, use\n// assert.strictEqual(true, guard, message_opt);.\n\nfunction ok(value, message) {\n  if (!value) fail(value, true, message, '==', assert.ok);\n}\nassert.ok = ok;\n\n// 5. The equality assertion tests shallow, coercive equality with\n// ==.\n// assert.equal(actual, expected, message_opt);\n\nassert.equal = function equal(actual, expected, message) {\n  if (actual != expected) fail(actual, expected, message, '==', assert.equal);\n};\n\n// 6. The non-equality assertion tests for whether two objects are not equal\n// with != assert.notEqual(actual, expected, message_opt);\n\nassert.notEqual = function notEqual(actual, expected, message) {\n  if (actual == expected) {\n    fail(actual, expected, message, '!=', assert.notEqual);\n  }\n};\n\n// 7. The equivalence assertion tests a deep equality relation.\n// assert.deepEqual(actual, expected, message_opt);\n\nassert.deepEqual = function deepEqual(actual, expected, message) {\n  if (!_deepEqual(actual, expected, false)) {\n    fail(actual, expected, message, 'deepEqual', assert.deepEqual);\n  }\n};\n\nassert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {\n  if (!_deepEqual(actual, expected, true)) {\n    fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);\n  }\n};\n\nfunction _deepEqual(actual, expected, strict, memos) {\n  // 7.1. All identical values are equivalent, as determined by ===.\n  if (actual === expected) {\n    return true;\n  } else if (isBuffer(actual) && isBuffer(expected)) {\n    return compare(actual, expected) === 0;\n\n  // 7.2. If the expected value is a Date object, the actual value is\n  // equivalent if it is also a Date object that refers to the same time.\n  } else if (util.isDate(actual) && util.isDate(expected)) {\n    return actual.getTime() === expected.getTime();\n\n  // 7.3 If the expected value is a RegExp object, the actual value is\n  // equivalent if it is also a RegExp object with the same source and\n  // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).\n  } else if (util.isRegExp(actual) && util.isRegExp(expected)) {\n    return actual.source === expected.source &&\n           actual.global === expected.global &&\n           actual.multiline === expected.multiline &&\n           actual.lastIndex === expected.lastIndex &&\n           actual.ignoreCase === expected.ignoreCase;\n\n  // 7.4. Other pairs that do not both pass typeof value == 'object',\n  // equivalence is determined by ==.\n  } else if ((actual === null || typeof actual !== 'object') &&\n             (expected === null || typeof expected !== 'object')) {\n    return strict ? actual === expected : actual == expected;\n\n  // If both values are instances of typed arrays, wrap their underlying\n  // ArrayBuffers in a Buffer each to increase performance\n  // This optimization requires the arrays to have the same type as checked by\n  // Object.prototype.toString (aka pToString). Never perform binary\n  // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their\n  // bit patterns are not identical.\n  } else if (isView(actual) && isView(expected) &&\n             pToString(actual) === pToString(expected) &&\n             !(actual instanceof Float32Array ||\n               actual instanceof Float64Array)) {\n    return compare(new Uint8Array(actual.buffer),\n                   new Uint8Array(expected.buffer)) === 0;\n\n  // 7.5 For all other Object pairs, including Array objects, equivalence is\n  // determined by having the same number of owned properties (as verified\n  // with Object.prototype.hasOwnProperty.call), the same set of keys\n  // (although not necessarily the same order), equivalent values for every\n  // corresponding key, and an identical 'prototype' property. Note: this\n  // accounts for both named and indexed properties on Arrays.\n  } else if (isBuffer(actual) !== isBuffer(expected)) {\n    return false;\n  } else {\n    memos = memos || {actual: [], expected: []};\n\n    var actualIndex = memos.actual.indexOf(actual);\n    if (actualIndex !== -1) {\n      if (actualIndex === memos.expected.indexOf(expected)) {\n        return true;\n      }\n    }\n\n    memos.actual.push(actual);\n    memos.expected.push(expected);\n\n    return objEquiv(actual, expected, strict, memos);\n  }\n}\n\nfunction isArguments(object) {\n  return Object.prototype.toString.call(object) == '[object Arguments]';\n}\n\nfunction objEquiv(a, b, strict, actualVisitedObjects) {\n  if (a === null || a === undefined || b === null || b === undefined)\n    return false;\n  // if one is a primitive, the other must be same\n  if (util.isPrimitive(a) || util.isPrimitive(b))\n    return a === b;\n  if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))\n    return false;\n  var aIsArgs = isArguments(a);\n  var bIsArgs = isArguments(b);\n  if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))\n    return false;\n  if (aIsArgs) {\n    a = pSlice.call(a);\n    b = pSlice.call(b);\n    return _deepEqual(a, b, strict);\n  }\n  var ka = objectKeys(a);\n  var kb = objectKeys(b);\n  var key, i;\n  // having the same number of owned properties (keys incorporates\n  // hasOwnProperty)\n  if (ka.length !== kb.length)\n    return false;\n  //the same set of keys (although not necessarily the same order),\n  ka.sort();\n  kb.sort();\n  //~~~cheap key test\n  for (i = ka.length - 1; i >= 0; i--) {\n    if (ka[i] !== kb[i])\n      return false;\n  }\n  //equivalent values for every corresponding key, and\n  //~~~possibly expensive deep test\n  for (i = ka.length - 1; i >= 0; i--) {\n    key = ka[i];\n    if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))\n      return false;\n  }\n  return true;\n}\n\n// 8. The non-equivalence assertion tests for any deep inequality.\n// assert.notDeepEqual(actual, expected, message_opt);\n\nassert.notDeepEqual = function notDeepEqual(actual, expected, message) {\n  if (_deepEqual(actual, expected, false)) {\n    fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);\n  }\n};\n\nassert.notDeepStrictEqual = notDeepStrictEqual;\nfunction notDeepStrictEqual(actual, expected, message) {\n  if (_deepEqual(actual, expected, true)) {\n    fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);\n  }\n}\n\n\n// 9. The strict equality assertion tests strict equality, as determined by ===.\n// assert.strictEqual(actual, expected, message_opt);\n\nassert.strictEqual = function strictEqual(actual, expected, message) {\n  if (actual !== expected) {\n    fail(actual, expected, message, '===', assert.strictEqual);\n  }\n};\n\n// 10. The strict non-equality assertion tests for strict inequality, as\n// determined by !==.  assert.notStrictEqual(actual, expected, message_opt);\n\nassert.notStrictEqual = function notStrictEqual(actual, expected, message) {\n  if (actual === expected) {\n    fail(actual, expected, message, '!==', assert.notStrictEqual);\n  }\n};\n\nfunction expectedException(actual, expected) {\n  if (!actual || !expected) {\n    return false;\n  }\n\n  if (Object.prototype.toString.call(expected) == '[object RegExp]') {\n    return expected.test(actual);\n  }\n\n  try {\n    if (actual instanceof expected) {\n      return true;\n    }\n  } catch (e) {\n    // Ignore.  The instanceof check doesn't work for arrow functions.\n  }\n\n  if (Error.isPrototypeOf(expected)) {\n    return false;\n  }\n\n  return expected.call({}, actual) === true;\n}\n\nfunction _tryBlock(block) {\n  var error;\n  try {\n    block();\n  } catch (e) {\n    error = e;\n  }\n  return error;\n}\n\nfunction _throws(shouldThrow, block, expected, message) {\n  var actual;\n\n  if (typeof block !== 'function') {\n    throw new TypeError('\"block\" argument must be a function');\n  }\n\n  if (typeof expected === 'string') {\n    message = expected;\n    expected = null;\n  }\n\n  actual = _tryBlock(block);\n\n  message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +\n            (message ? ' ' + message : '.');\n\n  if (shouldThrow && !actual) {\n    fail(actual, expected, 'Missing expected exception' + message);\n  }\n\n  var userProvidedMessage = typeof message === 'string';\n  var isUnwantedException = !shouldThrow && util.isError(actual);\n  var isUnexpectedException = !shouldThrow && actual && !expected;\n\n  if ((isUnwantedException &&\n      userProvidedMessage &&\n      expectedException(actual, expected)) ||\n      isUnexpectedException) {\n    fail(actual, expected, 'Got unwanted exception' + message);\n  }\n\n  if ((shouldThrow && actual && expected &&\n      !expectedException(actual, expected)) || (!shouldThrow && actual)) {\n    throw actual;\n  }\n}\n\n// 11. Expected to throw an error:\n// assert.throws(block, Error_opt, message_opt);\n\nassert.throws = function(block, /*optional*/error, /*optional*/message) {\n  _throws(true, block, error, message);\n};\n\n// EXTENSION! This is annoying to write outside this module.\nassert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {\n  _throws(false, block, error, message);\n};\n\nassert.ifError = function(err) { if (err) throw err; };\n\n// Expose a strict only variant of assert\nfunction strict(value, message) {\n  if (!value) fail(value, true, message, '==', strict);\n}\nassert.strict = objectAssign(strict, assert, {\n  equal: assert.strictEqual,\n  deepEqual: assert.deepStrictEqual,\n  notEqual: assert.notStrictEqual,\n  notDeepEqual: assert.notDeepStrictEqual\n});\nassert.strict.strict = assert.strict;\n\nvar objectKeys = Object.keys || function (obj) {\n  var keys = [];\n  for (var key in obj) {\n    if (hasOwn.call(obj, key)) keys.push(key);\n  }\n  return keys;\n};\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"object-assign\":454,\"util/\":71}],69:[function(_dereq_,module,exports){\nif (typeof Object.create === 'function') {\n  // implementation from standard node.js 'util' module\n  module.exports = function inherits(ctor, superCtor) {\n    ctor.super_ = superCtor\n    ctor.prototype = Object.create(superCtor.prototype, {\n      constructor: {\n        value: ctor,\n        enumerable: false,\n        writable: true,\n        configurable: true\n      }\n    });\n  };\n} else {\n  // old school shim for old browsers\n  module.exports = function inherits(ctor, superCtor) {\n    ctor.super_ = superCtor\n    var TempCtor = function () {}\n    TempCtor.prototype = superCtor.prototype\n    ctor.prototype = new TempCtor()\n    ctor.prototype.constructor = ctor\n  }\n}\n\n},{}],70:[function(_dereq_,module,exports){\nmodule.exports = function isBuffer(arg) {\n  return arg && typeof arg === 'object'\n    && typeof arg.copy === 'function'\n    && typeof arg.fill === 'function'\n    && typeof arg.readUInt8 === 'function';\n}\n},{}],71:[function(_dereq_,module,exports){\n(function (process,global){\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nvar formatRegExp = /%[sdj%]/g;\nexports.format = function(f) {\n  if (!isString(f)) {\n    var objects = [];\n    for (var i = 0; i < arguments.length; i++) {\n      objects.push(inspect(arguments[i]));\n    }\n    return objects.join(' ');\n  }\n\n  var i = 1;\n  var args = arguments;\n  var len = args.length;\n  var str = String(f).replace(formatRegExp, function(x) {\n    if (x === '%%') return '%';\n    if (i >= len) return x;\n    switch (x) {\n      case '%s': return String(args[i++]);\n      case '%d': return Number(args[i++]);\n      case '%j':\n        try {\n          return JSON.stringify(args[i++]);\n        } catch (_) {\n          return '[Circular]';\n        }\n      default:\n        return x;\n    }\n  });\n  for (var x = args[i]; i < len; x = args[++i]) {\n    if (isNull(x) || !isObject(x)) {\n      str += ' ' + x;\n    } else {\n      str += ' ' + inspect(x);\n    }\n  }\n  return str;\n};\n\n\n// Mark that a method should not be used.\n// Returns a modified function which warns once by default.\n// If --no-deprecation is set, then it is a no-op.\nexports.deprecate = function(fn, msg) {\n  // Allow for deprecating things in the process of starting up.\n  if (isUndefined(global.process)) {\n    return function() {\n      return exports.deprecate(fn, msg).apply(this, arguments);\n    };\n  }\n\n  if (process.noDeprecation === true) {\n    return fn;\n  }\n\n  var warned = false;\n  function deprecated() {\n    if (!warned) {\n      if (process.throwDeprecation) {\n        throw new Error(msg);\n      } else if (process.traceDeprecation) {\n        console.trace(msg);\n      } else {\n        console.error(msg);\n      }\n      warned = true;\n    }\n    return fn.apply(this, arguments);\n  }\n\n  return deprecated;\n};\n\n\nvar debugs = {};\nvar debugEnviron;\nexports.debuglog = function(set) {\n  if (isUndefined(debugEnviron))\n    debugEnviron = process.env.NODE_DEBUG || '';\n  set = set.toUpperCase();\n  if (!debugs[set]) {\n    if (new RegExp('\\\\b' + set + '\\\\b', 'i').test(debugEnviron)) {\n      var pid = process.pid;\n      debugs[set] = function() {\n        var msg = exports.format.apply(exports, arguments);\n        console.error('%s %d: %s', set, pid, msg);\n      };\n    } else {\n      debugs[set] = function() {};\n    }\n  }\n  return debugs[set];\n};\n\n\n/**\n * Echos the value of a value. Trys to print the value out\n * in the best way possible given the different types.\n *\n * @param {Object} obj The object to print out.\n * @param {Object} opts Optional options object that alters the output.\n */\n/* legacy: obj, showHidden, depth, colors*/\nfunction inspect(obj, opts) {\n  // default options\n  var ctx = {\n    seen: [],\n    stylize: stylizeNoColor\n  };\n  // legacy...\n  if (arguments.length >= 3) ctx.depth = arguments[2];\n  if (arguments.length >= 4) ctx.colors = arguments[3];\n  if (isBoolean(opts)) {\n    // legacy...\n    ctx.showHidden = opts;\n  } else if (opts) {\n    // got an \"options\" object\n    exports._extend(ctx, opts);\n  }\n  // set default options\n  if (isUndefined(ctx.showHidden)) ctx.showHidden = false;\n  if (isUndefined(ctx.depth)) ctx.depth = 2;\n  if (isUndefined(ctx.colors)) ctx.colors = false;\n  if (isUndefined(ctx.customInspect)) ctx.customInspect = true;\n  if (ctx.colors) ctx.stylize = stylizeWithColor;\n  return formatValue(ctx, obj, ctx.depth);\n}\nexports.inspect = inspect;\n\n\n// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics\ninspect.colors = {\n  'bold' : [1, 22],\n  'italic' : [3, 23],\n  'underline' : [4, 24],\n  'inverse' : [7, 27],\n  'white' : [37, 39],\n  'grey' : [90, 39],\n  'black' : [30, 39],\n  'blue' : [34, 39],\n  'cyan' : [36, 39],\n  'green' : [32, 39],\n  'magenta' : [35, 39],\n  'red' : [31, 39],\n  'yellow' : [33, 39]\n};\n\n// Don't use 'blue' not visible on cmd.exe\ninspect.styles = {\n  'special': 'cyan',\n  'number': 'yellow',\n  'boolean': 'yellow',\n  'undefined': 'grey',\n  'null': 'bold',\n  'string': 'green',\n  'date': 'magenta',\n  // \"name\": intentionally not styling\n  'regexp': 'red'\n};\n\n\nfunction stylizeWithColor(str, styleType) {\n  var style = inspect.styles[styleType];\n\n  if (style) {\n    return '\\u001b[' + inspect.colors[style][0] + 'm' + str +\n           '\\u001b[' + inspect.colors[style][1] + 'm';\n  } else {\n    return str;\n  }\n}\n\n\nfunction stylizeNoColor(str, styleType) {\n  return str;\n}\n\n\nfunction arrayToHash(array) {\n  var hash = {};\n\n  array.forEach(function(val, idx) {\n    hash[val] = true;\n  });\n\n  return hash;\n}\n\n\nfunction formatValue(ctx, value, recurseTimes) {\n  // Provide a hook for user-specified inspect functions.\n  // Check that value is an object with an inspect function on it\n  if (ctx.customInspect &&\n      value &&\n      isFunction(value.inspect) &&\n      // Filter out the util module, it's inspect function is special\n      value.inspect !== exports.inspect &&\n      // Also filter out any prototype objects using the circular check.\n      !(value.constructor && value.constructor.prototype === value)) {\n    var ret = value.inspect(recurseTimes, ctx);\n    if (!isString(ret)) {\n      ret = formatValue(ctx, ret, recurseTimes);\n    }\n    return ret;\n  }\n\n  // Primitive types cannot have properties\n  var primitive = formatPrimitive(ctx, value);\n  if (primitive) {\n    return primitive;\n  }\n\n  // Look up the keys of the object.\n  var keys = Object.keys(value);\n  var visibleKeys = arrayToHash(keys);\n\n  if (ctx.showHidden) {\n    keys = Object.getOwnPropertyNames(value);\n  }\n\n  // IE doesn't make error fields non-enumerable\n  // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx\n  if (isError(value)\n      && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {\n    return formatError(value);\n  }\n\n  // Some type of object without properties can be shortcutted.\n  if (keys.length === 0) {\n    if (isFunction(value)) {\n      var name = value.name ? ': ' + value.name : '';\n      return ctx.stylize('[Function' + name + ']', 'special');\n    }\n    if (isRegExp(value)) {\n      return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');\n    }\n    if (isDate(value)) {\n      return ctx.stylize(Date.prototype.toString.call(value), 'date');\n    }\n    if (isError(value)) {\n      return formatError(value);\n    }\n  }\n\n  var base = '', array = false, braces = ['{', '}'];\n\n  // Make Array say that they are Array\n  if (isArray(value)) {\n    array = true;\n    braces = ['[', ']'];\n  }\n\n  // Make functions say that they are functions\n  if (isFunction(value)) {\n    var n = value.name ? ': ' + value.name : '';\n    base = ' [Function' + n + ']';\n  }\n\n  // Make RegExps say that they are RegExps\n  if (isRegExp(value)) {\n    base = ' ' + RegExp.prototype.toString.call(value);\n  }\n\n  // Make dates with properties first say the date\n  if (isDate(value)) {\n    base = ' ' + Date.prototype.toUTCString.call(value);\n  }\n\n  // Make error with message first say the error\n  if (isError(value)) {\n    base = ' ' + formatError(value);\n  }\n\n  if (keys.length === 0 && (!array || value.length == 0)) {\n    return braces[0] + base + braces[1];\n  }\n\n  if (recurseTimes < 0) {\n    if (isRegExp(value)) {\n      return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');\n    } else {\n      return ctx.stylize('[Object]', 'special');\n    }\n  }\n\n  ctx.seen.push(value);\n\n  var output;\n  if (array) {\n    output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);\n  } else {\n    output = keys.map(function(key) {\n      return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);\n    });\n  }\n\n  ctx.seen.pop();\n\n  return reduceToSingleString(output, base, braces);\n}\n\n\nfunction formatPrimitive(ctx, value) {\n  if (isUndefined(value))\n    return ctx.stylize('undefined', 'undefined');\n  if (isString(value)) {\n    var simple = '\\'' + JSON.stringify(value).replace(/^\"|\"$/g, '')\n                                             .replace(/'/g, \"\\\\'\")\n                                             .replace(/\\\\\"/g, '\"') + '\\'';\n    return ctx.stylize(simple, 'string');\n  }\n  if (isNumber(value))\n    return ctx.stylize('' + value, 'number');\n  if (isBoolean(value))\n    return ctx.stylize('' + value, 'boolean');\n  // For some reason typeof null is \"object\", so special case here.\n  if (isNull(value))\n    return ctx.stylize('null', 'null');\n}\n\n\nfunction formatError(value) {\n  return '[' + Error.prototype.toString.call(value) + ']';\n}\n\n\nfunction formatArray(ctx, value, recurseTimes, visibleKeys, keys) {\n  var output = [];\n  for (var i = 0, l = value.length; i < l; ++i) {\n    if (hasOwnProperty(value, String(i))) {\n      output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,\n          String(i), true));\n    } else {\n      output.push('');\n    }\n  }\n  keys.forEach(function(key) {\n    if (!key.match(/^\\d+$/)) {\n      output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,\n          key, true));\n    }\n  });\n  return output;\n}\n\n\nfunction formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {\n  var name, str, desc;\n  desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };\n  if (desc.get) {\n    if (desc.set) {\n      str = ctx.stylize('[Getter/Setter]', 'special');\n    } else {\n      str = ctx.stylize('[Getter]', 'special');\n    }\n  } else {\n    if (desc.set) {\n      str = ctx.stylize('[Setter]', 'special');\n    }\n  }\n  if (!hasOwnProperty(visibleKeys, key)) {\n    name = '[' + key + ']';\n  }\n  if (!str) {\n    if (ctx.seen.indexOf(desc.value) < 0) {\n      if (isNull(recurseTimes)) {\n        str = formatValue(ctx, desc.value, null);\n      } else {\n        str = formatValue(ctx, desc.value, recurseTimes - 1);\n      }\n      if (str.indexOf('\\n') > -1) {\n        if (array) {\n          str = str.split('\\n').map(function(line) {\n            return '  ' + line;\n          }).join('\\n').substr(2);\n        } else {\n          str = '\\n' + str.split('\\n').map(function(line) {\n            return '   ' + line;\n          }).join('\\n');\n        }\n      }\n    } else {\n      str = ctx.stylize('[Circular]', 'special');\n    }\n  }\n  if (isUndefined(name)) {\n    if (array && key.match(/^\\d+$/)) {\n      return str;\n    }\n    name = JSON.stringify('' + key);\n    if (name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/)) {\n      name = name.substr(1, name.length - 2);\n      name = ctx.stylize(name, 'name');\n    } else {\n      name = name.replace(/'/g, \"\\\\'\")\n                 .replace(/\\\\\"/g, '\"')\n                 .replace(/(^\"|\"$)/g, \"'\");\n      name = ctx.stylize(name, 'string');\n    }\n  }\n\n  return name + ': ' + str;\n}\n\n\nfunction reduceToSingleString(output, base, braces) {\n  var numLinesEst = 0;\n  var length = output.reduce(function(prev, cur) {\n    numLinesEst++;\n    if (cur.indexOf('\\n') >= 0) numLinesEst++;\n    return prev + cur.replace(/\\u001b\\[\\d\\d?m/g, '').length + 1;\n  }, 0);\n\n  if (length > 60) {\n    return braces[0] +\n           (base === '' ? '' : base + '\\n ') +\n           ' ' +\n           output.join(',\\n  ') +\n           ' ' +\n           braces[1];\n  }\n\n  return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];\n}\n\n\n// NOTE: These type checking functions intentionally don't use `instanceof`\n// because it is fragile and can be easily faked with `Object.create()`.\nfunction isArray(ar) {\n  return Array.isArray(ar);\n}\nexports.isArray = isArray;\n\nfunction isBoolean(arg) {\n  return typeof arg === 'boolean';\n}\nexports.isBoolean = isBoolean;\n\nfunction isNull(arg) {\n  return arg === null;\n}\nexports.isNull = isNull;\n\nfunction isNullOrUndefined(arg) {\n  return arg == null;\n}\nexports.isNullOrUndefined = isNullOrUndefined;\n\nfunction isNumber(arg) {\n  return typeof arg === 'number';\n}\nexports.isNumber = isNumber;\n\nfunction isString(arg) {\n  return typeof arg === 'string';\n}\nexports.isString = isString;\n\nfunction isSymbol(arg) {\n  return typeof arg === 'symbol';\n}\nexports.isSymbol = isSymbol;\n\nfunction isUndefined(arg) {\n  return arg === void 0;\n}\nexports.isUndefined = isUndefined;\n\nfunction isRegExp(re) {\n  return isObject(re) && objectToString(re) === '[object RegExp]';\n}\nexports.isRegExp = isRegExp;\n\nfunction isObject(arg) {\n  return typeof arg === 'object' && arg !== null;\n}\nexports.isObject = isObject;\n\nfunction isDate(d) {\n  return isObject(d) && objectToString(d) === '[object Date]';\n}\nexports.isDate = isDate;\n\nfunction isError(e) {\n  return isObject(e) &&\n      (objectToString(e) === '[object Error]' || e instanceof Error);\n}\nexports.isError = isError;\n\nfunction isFunction(arg) {\n  return typeof arg === 'function';\n}\nexports.isFunction = isFunction;\n\nfunction isPrimitive(arg) {\n  return arg === null ||\n         typeof arg === 'boolean' ||\n         typeof arg === 'number' ||\n         typeof arg === 'string' ||\n         typeof arg === 'symbol' ||  // ES6 symbol\n         typeof arg === 'undefined';\n}\nexports.isPrimitive = isPrimitive;\n\nexports.isBuffer = _dereq_('./support/isBuffer');\n\nfunction objectToString(o) {\n  return Object.prototype.toString.call(o);\n}\n\n\nfunction pad(n) {\n  return n < 10 ? '0' + n.toString(10) : n.toString(10);\n}\n\n\nvar months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',\n              'Oct', 'Nov', 'Dec'];\n\n// 26 Feb 16:19:34\nfunction timestamp() {\n  var d = new Date();\n  var time = [pad(d.getHours()),\n              pad(d.getMinutes()),\n              pad(d.getSeconds())].join(':');\n  return [d.getDate(), months[d.getMonth()], time].join(' ');\n}\n\n\n// log is just a thin wrapper to console.log that prepends a timestamp\nexports.log = function() {\n  console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));\n};\n\n\n/**\n * Inherit the prototype methods from one constructor into another.\n *\n * The Function.prototype.inherits from lang.js rewritten as a standalone\n * function (not on Function.prototype). NOTE: If this file is to be loaded\n * during bootstrapping this function needs to be rewritten using some native\n * functions as prototype setup using normal JavaScript does not work as\n * expected during bootstrapping (see mirror.js in r114903).\n *\n * @param {function} ctor Constructor function which needs to inherit the\n *     prototype.\n * @param {function} superCtor Constructor function to inherit prototype from.\n */\nexports.inherits = _dereq_('inherits');\n\nexports._extend = function(origin, add) {\n  // Don't do anything if add isn't an object\n  if (!add || !isObject(add)) return origin;\n\n  var keys = Object.keys(add);\n  var i = keys.length;\n  while (i--) {\n    origin[keys[i]] = add[keys[i]];\n  }\n  return origin;\n};\n\nfunction hasOwnProperty(obj, prop) {\n  return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\n}).call(this,_dereq_('_process'),typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"./support/isBuffer\":70,\"_process\":482,\"inherits\":69}],72:[function(_dereq_,module,exports){\nmodule.exports = function _atob(str) {\n  return atob(str)\n}\n\n},{}],73:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = barycentric\n\nvar solve = _dereq_('robust-linear-solve')\n\nfunction reduce(x) {\n  var r = 0\n  for(var i=0; i<x.length; ++i) {\n    r += x[i]\n  }\n  return r\n}\n\nfunction barycentric(simplex, point) {\n  var d = point.length\n  var A = new Array(d+1)\n  for(var i=0; i<d; ++i) {\n    var row = new Array(d+1)\n    for(var j=0; j<=d; ++j) {\n      row[j] = simplex[j][i]\n    }\n    A[i] = row\n  }\n  A[d] = new Array(d+1)\n  for(var i=0; i<=d; ++i) {\n    A[d][i] = 1\n  }\n\n  var b = new Array(d+1)\n  for(var i=0; i<d; ++i) {\n    b[i] = point[i]\n  }\n  b[d] = 1.0\n\n  var x = solve(A, b)\n  var w = reduce(x[d+1])\n  \n  if(w === 0) {\n    w = 1.0\n  }\n  var y = new Array(d+1)\n  for(var i=0; i<=d; ++i) {\n    y[i] = reduce(x[i]) / w\n  }\n  return y\n}\n},{\"robust-linear-solve\":509}],74:[function(_dereq_,module,exports){\n'use strict'\n\nexports.byteLength = byteLength\nexports.toByteArray = toByteArray\nexports.fromByteArray = fromByteArray\n\nvar lookup = []\nvar revLookup = []\nvar Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array\n\nvar code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'\nfor (var i = 0, len = code.length; i < len; ++i) {\n  lookup[i] = code[i]\n  revLookup[code.charCodeAt(i)] = i\n}\n\n// Support decoding URL-safe base64 strings, as Node.js does.\n// See: https://en.wikipedia.org/wiki/Base64#URL_applications\nrevLookup['-'.charCodeAt(0)] = 62\nrevLookup['_'.charCodeAt(0)] = 63\n\nfunction getLens (b64) {\n  var len = b64.length\n\n  if (len % 4 > 0) {\n    throw new Error('Invalid string. Length must be a multiple of 4')\n  }\n\n  // Trim off extra bytes after placeholder bytes are found\n  // See: https://github.com/beatgammit/base64-js/issues/42\n  var validLen = b64.indexOf('=')\n  if (validLen === -1) validLen = len\n\n  var placeHoldersLen = validLen === len\n    ? 0\n    : 4 - (validLen % 4)\n\n  return [validLen, placeHoldersLen]\n}\n\n// base64 is 4/3 + up to two characters of the original data\nfunction byteLength (b64) {\n  var lens = getLens(b64)\n  var validLen = lens[0]\n  var placeHoldersLen = lens[1]\n  return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen\n}\n\nfunction _byteLength (b64, validLen, placeHoldersLen) {\n  return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen\n}\n\nfunction toByteArray (b64) {\n  var tmp\n  var lens = getLens(b64)\n  var validLen = lens[0]\n  var placeHoldersLen = lens[1]\n\n  var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))\n\n  var curByte = 0\n\n  // if there are placeholders, only get up to the last complete 4 chars\n  var len = placeHoldersLen > 0\n    ? validLen - 4\n    : validLen\n\n  for (var i = 0; i < len; i += 4) {\n    tmp =\n      (revLookup[b64.charCodeAt(i)] << 18) |\n      (revLookup[b64.charCodeAt(i + 1)] << 12) |\n      (revLookup[b64.charCodeAt(i + 2)] << 6) |\n      revLookup[b64.charCodeAt(i + 3)]\n    arr[curByte++] = (tmp >> 16) & 0xFF\n    arr[curByte++] = (tmp >> 8) & 0xFF\n    arr[curByte++] = tmp & 0xFF\n  }\n\n  if (placeHoldersLen === 2) {\n    tmp =\n      (revLookup[b64.charCodeAt(i)] << 2) |\n      (revLookup[b64.charCodeAt(i + 1)] >> 4)\n    arr[curByte++] = tmp & 0xFF\n  }\n\n  if (placeHoldersLen === 1) {\n    tmp =\n      (revLookup[b64.charCodeAt(i)] << 10) |\n      (revLookup[b64.charCodeAt(i + 1)] << 4) |\n      (revLookup[b64.charCodeAt(i + 2)] >> 2)\n    arr[curByte++] = (tmp >> 8) & 0xFF\n    arr[curByte++] = tmp & 0xFF\n  }\n\n  return arr\n}\n\nfunction tripletToBase64 (num) {\n  return lookup[num >> 18 & 0x3F] +\n    lookup[num >> 12 & 0x3F] +\n    lookup[num >> 6 & 0x3F] +\n    lookup[num & 0x3F]\n}\n\nfunction encodeChunk (uint8, start, end) {\n  var tmp\n  var output = []\n  for (var i = start; i < end; i += 3) {\n    tmp =\n      ((uint8[i] << 16) & 0xFF0000) +\n      ((uint8[i + 1] << 8) & 0xFF00) +\n      (uint8[i + 2] & 0xFF)\n    output.push(tripletToBase64(tmp))\n  }\n  return output.join('')\n}\n\nfunction fromByteArray (uint8) {\n  var tmp\n  var len = uint8.length\n  var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes\n  var parts = []\n  var maxChunkLength = 16383 // must be multiple of 3\n\n  // go through the array every three bytes, we'll deal with trailing stuff later\n  for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {\n    parts.push(encodeChunk(\n      uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)\n    ))\n  }\n\n  // pad the end with zeros, but make sure to not forget the extra bytes\n  if (extraBytes === 1) {\n    tmp = uint8[len - 1]\n    parts.push(\n      lookup[tmp >> 2] +\n      lookup[(tmp << 4) & 0x3F] +\n      '=='\n    )\n  } else if (extraBytes === 2) {\n    tmp = (uint8[len - 2] << 8) + uint8[len - 1]\n    parts.push(\n      lookup[tmp >> 10] +\n      lookup[(tmp >> 4) & 0x3F] +\n      lookup[(tmp << 2) & 0x3F] +\n      '='\n    )\n  }\n\n  return parts.join('')\n}\n\n},{}],75:[function(_dereq_,module,exports){\n'use strict'\n\nvar rationalize = _dereq_('./lib/rationalize')\n\nmodule.exports = add\n\nfunction add(a, b) {\n  return rationalize(\n    a[0].mul(b[1]).add(b[0].mul(a[1])),\n    a[1].mul(b[1]))\n}\n\n},{\"./lib/rationalize\":85}],76:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = cmp\n\nfunction cmp(a, b) {\n    return a[0].mul(b[1]).cmp(b[0].mul(a[1]))\n}\n\n},{}],77:[function(_dereq_,module,exports){\n'use strict'\n\nvar rationalize = _dereq_('./lib/rationalize')\n\nmodule.exports = div\n\nfunction div(a, b) {\n  return rationalize(a[0].mul(b[1]), a[1].mul(b[0]))\n}\n\n},{\"./lib/rationalize\":85}],78:[function(_dereq_,module,exports){\n'use strict'\n\nvar isRat = _dereq_('./is-rat')\nvar isBN = _dereq_('./lib/is-bn')\nvar num2bn = _dereq_('./lib/num-to-bn')\nvar str2bn = _dereq_('./lib/str-to-bn')\nvar rationalize = _dereq_('./lib/rationalize')\nvar div = _dereq_('./div')\n\nmodule.exports = makeRational\n\nfunction makeRational(numer, denom) {\n  if(isRat(numer)) {\n    if(denom) {\n      return div(numer, makeRational(denom))\n    }\n    return [numer[0].clone(), numer[1].clone()]\n  }\n  var shift = 0\n  var a, b\n  if(isBN(numer)) {\n    a = numer.clone()\n  } else if(typeof numer === 'string') {\n    a = str2bn(numer)\n  } else if(numer === 0) {\n    return [num2bn(0), num2bn(1)]\n  } else if(numer === Math.floor(numer)) {\n    a = num2bn(numer)\n  } else {\n    while(numer !== Math.floor(numer)) {\n      numer = numer * Math.pow(2, 256)\n      shift -= 256\n    }\n    a = num2bn(numer)\n  }\n  if(isRat(denom)) {\n    a.mul(denom[1])\n    b = denom[0].clone()\n  } else if(isBN(denom)) {\n    b = denom.clone()\n  } else if(typeof denom === 'string') {\n    b = str2bn(denom)\n  } else if(!denom) {\n    b = num2bn(1)\n  } else if(denom === Math.floor(denom)) {\n    b = num2bn(denom)\n  } else {\n    while(denom !== Math.floor(denom)) {\n      denom = denom * Math.pow(2, 256)\n      shift += 256\n    }\n    b = num2bn(denom)\n  }\n  if(shift > 0) {\n    a = a.ushln(shift)\n  } else if(shift < 0) {\n    b = b.ushln(-shift)\n  }\n  return rationalize(a, b)\n}\n\n},{\"./div\":77,\"./is-rat\":79,\"./lib/is-bn\":83,\"./lib/num-to-bn\":84,\"./lib/rationalize\":85,\"./lib/str-to-bn\":86}],79:[function(_dereq_,module,exports){\n'use strict'\n\nvar isBN = _dereq_('./lib/is-bn')\n\nmodule.exports = isRat\n\nfunction isRat(x) {\n  return Array.isArray(x) && x.length === 2 && isBN(x[0]) && isBN(x[1])\n}\n\n},{\"./lib/is-bn\":83}],80:[function(_dereq_,module,exports){\n'use strict'\n\nvar BN = _dereq_('bn.js')\n\nmodule.exports = sign\n\nfunction sign (x) {\n  return x.cmp(new BN(0))\n}\n\n},{\"bn.js\":94}],81:[function(_dereq_,module,exports){\n'use strict'\n\nvar sign = _dereq_('./bn-sign')\n\nmodule.exports = bn2num\n\n//TODO: Make this better\nfunction bn2num(b) {\n  var l = b.length\n  var words = b.words\n  var out = 0\n  if (l === 1) {\n    out = words[0]\n  } else if (l === 2) {\n    out = words[0] + (words[1] * 0x4000000)\n  } else {\n    for (var i = 0; i < l; i++) {\n      var w = words[i]\n      out += w * Math.pow(0x4000000, i)\n    }\n  }\n  return sign(b) * out\n}\n\n},{\"./bn-sign\":80}],82:[function(_dereq_,module,exports){\n'use strict'\n\nvar db = _dereq_('double-bits')\nvar ctz = _dereq_('bit-twiddle').countTrailingZeros\n\nmodule.exports = ctzNumber\n\n//Counts the number of trailing zeros\nfunction ctzNumber(x) {\n  var l = ctz(db.lo(x))\n  if(l < 32) {\n    return l\n  }\n  var h = ctz(db.hi(x))\n  if(h > 20) {\n    return 52\n  }\n  return h + 32\n}\n\n},{\"bit-twiddle\":92,\"double-bits\":167}],83:[function(_dereq_,module,exports){\n'use strict'\n\nvar BN = _dereq_('bn.js')\n\nmodule.exports = isBN\n\n//Test if x is a bignumber\n//FIXME: obviously this is the wrong way to do it\nfunction isBN(x) {\n  return x && typeof x === 'object' && Boolean(x.words)\n}\n\n},{\"bn.js\":94}],84:[function(_dereq_,module,exports){\n'use strict'\n\nvar BN = _dereq_('bn.js')\nvar db = _dereq_('double-bits')\n\nmodule.exports = num2bn\n\nfunction num2bn(x) {\n  var e = db.exponent(x)\n  if(e < 52) {\n    return new BN(x)\n  } else {\n    return (new BN(x * Math.pow(2, 52-e))).ushln(e-52)\n  }\n}\n\n},{\"bn.js\":94,\"double-bits\":167}],85:[function(_dereq_,module,exports){\n'use strict'\n\nvar num2bn = _dereq_('./num-to-bn')\nvar sign = _dereq_('./bn-sign')\n\nmodule.exports = rationalize\n\nfunction rationalize(numer, denom) {\n  var snumer = sign(numer)\n  var sdenom = sign(denom)\n  if(snumer === 0) {\n    return [num2bn(0), num2bn(1)]\n  }\n  if(sdenom === 0) {\n    return [num2bn(0), num2bn(0)]\n  }\n  if(sdenom < 0) {\n    numer = numer.neg()\n    denom = denom.neg()\n  }\n  var d = numer.gcd(denom)\n  if(d.cmpn(1)) {\n    return [ numer.div(d), denom.div(d) ]\n  }\n  return [ numer, denom ]\n}\n\n},{\"./bn-sign\":80,\"./num-to-bn\":84}],86:[function(_dereq_,module,exports){\n'use strict'\n\nvar BN = _dereq_('bn.js')\n\nmodule.exports = str2BN\n\nfunction str2BN(x) {\n  return new BN(x)\n}\n\n},{\"bn.js\":94}],87:[function(_dereq_,module,exports){\n'use strict'\n\nvar rationalize = _dereq_('./lib/rationalize')\n\nmodule.exports = mul\n\nfunction mul(a, b) {\n  return rationalize(a[0].mul(b[0]), a[1].mul(b[1]))\n}\n\n},{\"./lib/rationalize\":85}],88:[function(_dereq_,module,exports){\n'use strict'\n\nvar bnsign = _dereq_('./lib/bn-sign')\n\nmodule.exports = sign\n\nfunction sign(x) {\n  return bnsign(x[0]) * bnsign(x[1])\n}\n\n},{\"./lib/bn-sign\":80}],89:[function(_dereq_,module,exports){\n'use strict'\n\nvar rationalize = _dereq_('./lib/rationalize')\n\nmodule.exports = sub\n\nfunction sub(a, b) {\n  return rationalize(a[0].mul(b[1]).sub(a[1].mul(b[0])), a[1].mul(b[1]))\n}\n\n},{\"./lib/rationalize\":85}],90:[function(_dereq_,module,exports){\n'use strict'\n\nvar bn2num = _dereq_('./lib/bn-to-num')\nvar ctz = _dereq_('./lib/ctz')\n\nmodule.exports = roundRat\n\n// Round a rational to the closest float\nfunction roundRat (f) {\n  var a = f[0]\n  var b = f[1]\n  if (a.cmpn(0) === 0) {\n    return 0\n  }\n  var h = a.abs().divmod(b.abs())\n  var iv = h.div\n  var x = bn2num(iv)\n  var ir = h.mod\n  var sgn = (a.negative !== b.negative) ? -1 : 1\n  if (ir.cmpn(0) === 0) {\n    return sgn * x\n  }\n  if (x) {\n    var s = ctz(x) + 4\n    var y = bn2num(ir.ushln(s).divRound(b))\n    return sgn * (x + y * Math.pow(2, -s))\n  } else {\n    var ybits = b.bitLength() - ir.bitLength() + 53\n    var y = bn2num(ir.ushln(ybits).divRound(b))\n    if (ybits < 1023) {\n      return sgn * y * Math.pow(2, -ybits)\n    }\n    y *= Math.pow(2, -1023)\n    return sgn * y * Math.pow(2, 1023 - ybits)\n  }\n}\n\n},{\"./lib/bn-to-num\":81,\"./lib/ctz\":82}],91:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction compileSearch(funcName, predicate, reversed, extraArgs, useNdarray, earlyOut) {\n  var code = [\n    \"function \", funcName, \"(a,l,h,\", extraArgs.join(\",\"),  \"){\",\nearlyOut ? \"\" : \"var i=\", (reversed ? \"l-1\" : \"h+1\"),\n\";while(l<=h){\\\nvar m=(l+h)>>>1,x=a\", useNdarray ? \".get(m)\" : \"[m]\"]\n  if(earlyOut) {\n    if(predicate.indexOf(\"c\") < 0) {\n      code.push(\";if(x===y){return m}else if(x<=y){\")\n    } else {\n      code.push(\";var p=c(x,y);if(p===0){return m}else if(p<=0){\")\n    }\n  } else {\n    code.push(\";if(\", predicate, \"){i=m;\")\n  }\n  if(reversed) {\n    code.push(\"l=m+1}else{h=m-1}\")\n  } else {\n    code.push(\"h=m-1}else{l=m+1}\")\n  }\n  code.push(\"}\")\n  if(earlyOut) {\n    code.push(\"return -1};\")\n  } else {\n    code.push(\"return i};\")\n  }\n  return code.join(\"\")\n}\n\nfunction compileBoundsSearch(predicate, reversed, suffix, earlyOut) {\n  var result = new Function([\n  compileSearch(\"A\", \"x\" + predicate + \"y\", reversed, [\"y\"], false, earlyOut),\n  compileSearch(\"B\", \"x\" + predicate + \"y\", reversed, [\"y\"], true, earlyOut),\n  compileSearch(\"P\", \"c(x,y)\" + predicate + \"0\", reversed, [\"y\", \"c\"], false, earlyOut),\n  compileSearch(\"Q\", \"c(x,y)\" + predicate + \"0\", reversed, [\"y\", \"c\"], true, earlyOut),\n\"function dispatchBsearch\", suffix, \"(a,y,c,l,h){\\\nif(a.shape){\\\nif(typeof(c)==='function'){\\\nreturn Q(a,(l===undefined)?0:l|0,(h===undefined)?a.shape[0]-1:h|0,y,c)\\\n}else{\\\nreturn B(a,(c===undefined)?0:c|0,(l===undefined)?a.shape[0]-1:l|0,y)\\\n}}else{\\\nif(typeof(c)==='function'){\\\nreturn P(a,(l===undefined)?0:l|0,(h===undefined)?a.length-1:h|0,y,c)\\\n}else{\\\nreturn A(a,(c===undefined)?0:c|0,(l===undefined)?a.length-1:l|0,y)\\\n}}}\\\nreturn dispatchBsearch\", suffix].join(\"\"))\n  return result()\n}\n\nmodule.exports = {\n  ge: compileBoundsSearch(\">=\", false, \"GE\"),\n  gt: compileBoundsSearch(\">\", false, \"GT\"),\n  lt: compileBoundsSearch(\"<\", true, \"LT\"),\n  le: compileBoundsSearch(\"<=\", true, \"LE\"),\n  eq: compileBoundsSearch(\"-\", true, \"EQ\", true)\n}\n\n},{}],92:[function(_dereq_,module,exports){\n/**\n * Bit twiddling hacks for JavaScript.\n *\n * Author: Mikola Lysenko\n *\n * Ported from Stanford bit twiddling hack library:\n *    http://graphics.stanford.edu/~seander/bithacks.html\n */\n\n\"use strict\"; \"use restrict\";\n\n//Number of bits in an integer\nvar INT_BITS = 32;\n\n//Constants\nexports.INT_BITS  = INT_BITS;\nexports.INT_MAX   =  0x7fffffff;\nexports.INT_MIN   = -1<<(INT_BITS-1);\n\n//Returns -1, 0, +1 depending on sign of x\nexports.sign = function(v) {\n  return (v > 0) - (v < 0);\n}\n\n//Computes absolute value of integer\nexports.abs = function(v) {\n  var mask = v >> (INT_BITS-1);\n  return (v ^ mask) - mask;\n}\n\n//Computes minimum of integers x and y\nexports.min = function(x, y) {\n  return y ^ ((x ^ y) & -(x < y));\n}\n\n//Computes maximum of integers x and y\nexports.max = function(x, y) {\n  return x ^ ((x ^ y) & -(x < y));\n}\n\n//Checks if a number is a power of two\nexports.isPow2 = function(v) {\n  return !(v & (v-1)) && (!!v);\n}\n\n//Computes log base 2 of v\nexports.log2 = function(v) {\n  var r, shift;\n  r =     (v > 0xFFFF) << 4; v >>>= r;\n  shift = (v > 0xFF  ) << 3; v >>>= shift; r |= shift;\n  shift = (v > 0xF   ) << 2; v >>>= shift; r |= shift;\n  shift = (v > 0x3   ) << 1; v >>>= shift; r |= shift;\n  return r | (v >> 1);\n}\n\n//Computes log base 10 of v\nexports.log10 = function(v) {\n  return  (v >= 1000000000) ? 9 : (v >= 100000000) ? 8 : (v >= 10000000) ? 7 :\n          (v >= 1000000) ? 6 : (v >= 100000) ? 5 : (v >= 10000) ? 4 :\n          (v >= 1000) ? 3 : (v >= 100) ? 2 : (v >= 10) ? 1 : 0;\n}\n\n//Counts number of bits\nexports.popCount = function(v) {\n  v = v - ((v >>> 1) & 0x55555555);\n  v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);\n  return ((v + (v >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24;\n}\n\n//Counts number of trailing zeros\nfunction countTrailingZeros(v) {\n  var c = 32;\n  v &= -v;\n  if (v) c--;\n  if (v & 0x0000FFFF) c -= 16;\n  if (v & 0x00FF00FF) c -= 8;\n  if (v & 0x0F0F0F0F) c -= 4;\n  if (v & 0x33333333) c -= 2;\n  if (v & 0x55555555) c -= 1;\n  return c;\n}\nexports.countTrailingZeros = countTrailingZeros;\n\n//Rounds to next power of 2\nexports.nextPow2 = function(v) {\n  v += v === 0;\n  --v;\n  v |= v >>> 1;\n  v |= v >>> 2;\n  v |= v >>> 4;\n  v |= v >>> 8;\n  v |= v >>> 16;\n  return v + 1;\n}\n\n//Rounds down to previous power of 2\nexports.prevPow2 = function(v) {\n  v |= v >>> 1;\n  v |= v >>> 2;\n  v |= v >>> 4;\n  v |= v >>> 8;\n  v |= v >>> 16;\n  return v - (v>>>1);\n}\n\n//Computes parity of word\nexports.parity = function(v) {\n  v ^= v >>> 16;\n  v ^= v >>> 8;\n  v ^= v >>> 4;\n  v &= 0xf;\n  return (0x6996 >>> v) & 1;\n}\n\nvar REVERSE_TABLE = new Array(256);\n\n(function(tab) {\n  for(var i=0; i<256; ++i) {\n    var v = i, r = i, s = 7;\n    for (v >>>= 1; v; v >>>= 1) {\n      r <<= 1;\n      r |= v & 1;\n      --s;\n    }\n    tab[i] = (r << s) & 0xff;\n  }\n})(REVERSE_TABLE);\n\n//Reverse bits in a 32 bit word\nexports.reverse = function(v) {\n  return  (REVERSE_TABLE[ v         & 0xff] << 24) |\n          (REVERSE_TABLE[(v >>> 8)  & 0xff] << 16) |\n          (REVERSE_TABLE[(v >>> 16) & 0xff] << 8)  |\n           REVERSE_TABLE[(v >>> 24) & 0xff];\n}\n\n//Interleave bits of 2 coordinates with 16 bits.  Useful for fast quadtree codes\nexports.interleave2 = function(x, y) {\n  x &= 0xFFFF;\n  x = (x | (x << 8)) & 0x00FF00FF;\n  x = (x | (x << 4)) & 0x0F0F0F0F;\n  x = (x | (x << 2)) & 0x33333333;\n  x = (x | (x << 1)) & 0x55555555;\n\n  y &= 0xFFFF;\n  y = (y | (y << 8)) & 0x00FF00FF;\n  y = (y | (y << 4)) & 0x0F0F0F0F;\n  y = (y | (y << 2)) & 0x33333333;\n  y = (y | (y << 1)) & 0x55555555;\n\n  return x | (y << 1);\n}\n\n//Extracts the nth interleaved component\nexports.deinterleave2 = function(v, n) {\n  v = (v >>> n) & 0x55555555;\n  v = (v | (v >>> 1))  & 0x33333333;\n  v = (v | (v >>> 2))  & 0x0F0F0F0F;\n  v = (v | (v >>> 4))  & 0x00FF00FF;\n  v = (v | (v >>> 16)) & 0x000FFFF;\n  return (v << 16) >> 16;\n}\n\n\n//Interleave bits of 3 coordinates, each with 10 bits.  Useful for fast octree codes\nexports.interleave3 = function(x, y, z) {\n  x &= 0x3FF;\n  x  = (x | (x<<16)) & 4278190335;\n  x  = (x | (x<<8))  & 251719695;\n  x  = (x | (x<<4))  & 3272356035;\n  x  = (x | (x<<2))  & 1227133513;\n\n  y &= 0x3FF;\n  y  = (y | (y<<16)) & 4278190335;\n  y  = (y | (y<<8))  & 251719695;\n  y  = (y | (y<<4))  & 3272356035;\n  y  = (y | (y<<2))  & 1227133513;\n  x |= (y << 1);\n  \n  z &= 0x3FF;\n  z  = (z | (z<<16)) & 4278190335;\n  z  = (z | (z<<8))  & 251719695;\n  z  = (z | (z<<4))  & 3272356035;\n  z  = (z | (z<<2))  & 1227133513;\n  \n  return x | (z << 2);\n}\n\n//Extracts nth interleaved component of a 3-tuple\nexports.deinterleave3 = function(v, n) {\n  v = (v >>> n)       & 1227133513;\n  v = (v | (v>>>2))   & 3272356035;\n  v = (v | (v>>>4))   & 251719695;\n  v = (v | (v>>>8))   & 4278190335;\n  v = (v | (v>>>16))  & 0x3FF;\n  return (v<<22)>>22;\n}\n\n//Computes next combination in colexicographic order (this is mistakenly called nextPermutation on the bit twiddling hacks page)\nexports.nextCombination = function(v) {\n  var t = v | (v - 1);\n  return (t + 1) | (((~t & -~t) - 1) >>> (countTrailingZeros(v) + 1));\n}\n\n\n},{}],93:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar clamp = _dereq_('clamp')\r\n\r\nmodule.exports = calcSDF\r\n\r\nvar INF = 1e20;\r\n\r\nfunction calcSDF(src, options) {\r\n    if (!options) options = {}\r\n\r\n    var cutoff = options.cutoff == null ? 0.25 : options.cutoff\r\n    var radius = options.radius == null ? 8 : options.radius\r\n    var channel = options.channel || 0\r\n    var w, h, size, data, intData, stride, ctx, canvas, imgData, i, l\r\n\r\n    // handle image container\r\n    if (ArrayBuffer.isView(src) || Array.isArray(src)) {\r\n        if (!options.width || !options.height) throw Error('For raw data width and height should be provided by options')\r\n        w = options.width, h = options.height\r\n        data = src\r\n\r\n        if (!options.stride) stride = Math.floor(src.length / w / h)\r\n        else stride = options.stride\r\n    }\r\n    else {\r\n        if (window.HTMLCanvasElement && src instanceof window.HTMLCanvasElement) {\r\n            canvas = src\r\n            ctx = canvas.getContext('2d')\r\n            w = canvas.width, h = canvas.height\r\n            imgData = ctx.getImageData(0, 0, w, h)\r\n            data = imgData.data\r\n            stride = 4\r\n        }\r\n        else if (window.CanvasRenderingContext2D && src instanceof window.CanvasRenderingContext2D) {\r\n            canvas = src.canvas\r\n            ctx = src\r\n            w = canvas.width, h = canvas.height\r\n            imgData = ctx.getImageData(0, 0, w, h)\r\n            data = imgData.data\r\n            stride = 4\r\n        }\r\n        else if (window.ImageData && src instanceof window.ImageData) {\r\n            imgData = src\r\n            w = src.width, h = src.height\r\n            data = imgData.data\r\n            stride = 4\r\n        }\r\n    }\r\n\r\n    size = Math.max(w, h)\r\n\r\n    //convert int data to floats\r\n    if ((window.Uint8ClampedArray && data instanceof window.Uint8ClampedArray) || (window.Uint8Array && data instanceof window.Uint8Array)) {\r\n        intData = data\r\n        data = Array(w*h)\r\n\r\n        for (i = 0, l = intData.length; i < l; i++) {\r\n            data[i] = intData[i*stride + channel] / 255\r\n        }\r\n    }\r\n    else {\r\n        if (stride !== 1) throw Error('Raw data can have only 1 value per pixel')\r\n    }\r\n\r\n    // temporary arrays for the distance transform\r\n    var gridOuter = Array(w * h)\r\n    var gridInner = Array(w * h)\r\n    var f = Array(size)\r\n    var d = Array(size)\r\n    var z = Array(size + 1)\r\n    var v = Array(size)\r\n\r\n    for (i = 0, l = w * h; i < l; i++) {\r\n        var a = data[i]\r\n        gridOuter[i] = a === 1 ? 0 : a === 0 ? INF : Math.pow(Math.max(0, 0.5 - a), 2)\r\n        gridInner[i] = a === 1 ? INF : a === 0 ? 0 : Math.pow(Math.max(0, a - 0.5), 2)\r\n    }\r\n\r\n    edt(gridOuter, w, h, f, d, v, z)\r\n    edt(gridInner, w, h, f, d, v, z)\r\n\r\n    var dist = window.Float32Array ? new Float32Array(w * h) : new Array(w * h)\r\n\r\n    for (i = 0, l = w*h; i < l; i++) {\r\n        dist[i] = clamp(1 - ( (gridOuter[i] - gridInner[i]) / radius + cutoff), 0, 1)\r\n    }\r\n\r\n    return dist\r\n}\r\n\r\n// 2D Euclidean distance transform by Felzenszwalb & Huttenlocher https://cs.brown.edu/~pff/dt/\r\nfunction edt(data, width, height, f, d, v, z) {\r\n    for (var x = 0; x < width; x++) {\r\n        for (var y = 0; y < height; y++) {\r\n            f[y] = data[y * width + x]\r\n        }\r\n        edt1d(f, d, v, z, height)\r\n        for (y = 0; y < height; y++) {\r\n            data[y * width + x] = d[y]\r\n        }\r\n    }\r\n    for (y = 0; y < height; y++) {\r\n        for (x = 0; x < width; x++) {\r\n            f[x] = data[y * width + x]\r\n        }\r\n        edt1d(f, d, v, z, width)\r\n        for (x = 0; x < width; x++) {\r\n            data[y * width + x] = Math.sqrt(d[x])\r\n        }\r\n    }\r\n}\r\n\r\n// 1D squared distance transform\r\nfunction edt1d(f, d, v, z, n) {\r\n    v[0] = 0;\r\n    z[0] = -INF\r\n    z[1] = +INF\r\n\r\n    for (var q = 1, k = 0; q < n; q++) {\r\n        var s = ((f[q] + q * q) - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k])\r\n        while (s <= z[k]) {\r\n            k--\r\n            s = ((f[q] + q * q) - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k])\r\n        }\r\n        k++\r\n        v[k] = q\r\n        z[k] = s\r\n        z[k + 1] = +INF\r\n    }\r\n\r\n    for (q = 0, k = 0; q < n; q++) {\r\n        while (z[k + 1] < q) k++\r\n        d[q] = (q - v[k]) * (q - v[k]) + f[v[k]]\r\n    }\r\n}\r\n\n},{\"clamp\":115}],94:[function(_dereq_,module,exports){\n(function (module, exports) {\n  'use strict';\n\n  // Utils\n  function assert (val, msg) {\n    if (!val) throw new Error(msg || 'Assertion failed');\n  }\n\n  // Could use `inherits` module, but don't want to move from single file\n  // architecture yet.\n  function inherits (ctor, superCtor) {\n    ctor.super_ = superCtor;\n    var TempCtor = function () {};\n    TempCtor.prototype = superCtor.prototype;\n    ctor.prototype = new TempCtor();\n    ctor.prototype.constructor = ctor;\n  }\n\n  // BN\n\n  function BN (number, base, endian) {\n    if (BN.isBN(number)) {\n      return number;\n    }\n\n    this.negative = 0;\n    this.words = null;\n    this.length = 0;\n\n    // Reduction context\n    this.red = null;\n\n    if (number !== null) {\n      if (base === 'le' || base === 'be') {\n        endian = base;\n        base = 10;\n      }\n\n      this._init(number || 0, base || 10, endian || 'be');\n    }\n  }\n  if (typeof module === 'object') {\n    module.exports = BN;\n  } else {\n    exports.BN = BN;\n  }\n\n  BN.BN = BN;\n  BN.wordSize = 26;\n\n  var Buffer;\n  try {\n    Buffer = _dereq_('buffer').Buffer;\n  } catch (e) {\n  }\n\n  BN.isBN = function isBN (num) {\n    if (num instanceof BN) {\n      return true;\n    }\n\n    return num !== null && typeof num === 'object' &&\n      num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);\n  };\n\n  BN.max = function max (left, right) {\n    if (left.cmp(right) > 0) return left;\n    return right;\n  };\n\n  BN.min = function min (left, right) {\n    if (left.cmp(right) < 0) return left;\n    return right;\n  };\n\n  BN.prototype._init = function init (number, base, endian) {\n    if (typeof number === 'number') {\n      return this._initNumber(number, base, endian);\n    }\n\n    if (typeof number === 'object') {\n      return this._initArray(number, base, endian);\n    }\n\n    if (base === 'hex') {\n      base = 16;\n    }\n    assert(base === (base | 0) && base >= 2 && base <= 36);\n\n    number = number.toString().replace(/\\s+/g, '');\n    var start = 0;\n    if (number[0] === '-') {\n      start++;\n    }\n\n    if (base === 16) {\n      this._parseHex(number, start);\n    } else {\n      this._parseBase(number, base, start);\n    }\n\n    if (number[0] === '-') {\n      this.negative = 1;\n    }\n\n    this.strip();\n\n    if (endian !== 'le') return;\n\n    this._initArray(this.toArray(), base, endian);\n  };\n\n  BN.prototype._initNumber = function _initNumber (number, base, endian) {\n    if (number < 0) {\n      this.negative = 1;\n      number = -number;\n    }\n    if (number < 0x4000000) {\n      this.words = [ number & 0x3ffffff ];\n      this.length = 1;\n    } else if (number < 0x10000000000000) {\n      this.words = [\n        number & 0x3ffffff,\n        (number / 0x4000000) & 0x3ffffff\n      ];\n      this.length = 2;\n    } else {\n      assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)\n      this.words = [\n        number & 0x3ffffff,\n        (number / 0x4000000) & 0x3ffffff,\n        1\n      ];\n      this.length = 3;\n    }\n\n    if (endian !== 'le') return;\n\n    // Reverse the bytes\n    this._initArray(this.toArray(), base, endian);\n  };\n\n  BN.prototype._initArray = function _initArray (number, base, endian) {\n    // Perhaps a Uint8Array\n    assert(typeof number.length === 'number');\n    if (number.length <= 0) {\n      this.words = [ 0 ];\n      this.length = 1;\n      return this;\n    }\n\n    this.length = Math.ceil(number.length / 3);\n    this.words = new Array(this.length);\n    for (var i = 0; i < this.length; i++) {\n      this.words[i] = 0;\n    }\n\n    var j, w;\n    var off = 0;\n    if (endian === 'be') {\n      for (i = number.length - 1, j = 0; i >= 0; i -= 3) {\n        w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);\n        this.words[j] |= (w << off) & 0x3ffffff;\n        this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;\n        off += 24;\n        if (off >= 26) {\n          off -= 26;\n          j++;\n        }\n      }\n    } else if (endian === 'le') {\n      for (i = 0, j = 0; i < number.length; i += 3) {\n        w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);\n        this.words[j] |= (w << off) & 0x3ffffff;\n        this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;\n        off += 24;\n        if (off >= 26) {\n          off -= 26;\n          j++;\n        }\n      }\n    }\n    return this.strip();\n  };\n\n  function parseHex (str, start, end) {\n    var r = 0;\n    var len = Math.min(str.length, end);\n    for (var i = start; i < len; i++) {\n      var c = str.charCodeAt(i) - 48;\n\n      r <<= 4;\n\n      // 'a' - 'f'\n      if (c >= 49 && c <= 54) {\n        r |= c - 49 + 0xa;\n\n      // 'A' - 'F'\n      } else if (c >= 17 && c <= 22) {\n        r |= c - 17 + 0xa;\n\n      // '0' - '9'\n      } else {\n        r |= c & 0xf;\n      }\n    }\n    return r;\n  }\n\n  BN.prototype._parseHex = function _parseHex (number, start) {\n    // Create possibly bigger array to ensure that it fits the number\n    this.length = Math.ceil((number.length - start) / 6);\n    this.words = new Array(this.length);\n    for (var i = 0; i < this.length; i++) {\n      this.words[i] = 0;\n    }\n\n    var j, w;\n    // Scan 24-bit chunks and add them to the number\n    var off = 0;\n    for (i = number.length - 6, j = 0; i >= start; i -= 6) {\n      w = parseHex(number, i, i + 6);\n      this.words[j] |= (w << off) & 0x3ffffff;\n      // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb\n      this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;\n      off += 24;\n      if (off >= 26) {\n        off -= 26;\n        j++;\n      }\n    }\n    if (i + 6 !== start) {\n      w = parseHex(number, start, i + 6);\n      this.words[j] |= (w << off) & 0x3ffffff;\n      this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;\n    }\n    this.strip();\n  };\n\n  function parseBase (str, start, end, mul) {\n    var r = 0;\n    var len = Math.min(str.length, end);\n    for (var i = start; i < len; i++) {\n      var c = str.charCodeAt(i) - 48;\n\n      r *= mul;\n\n      // 'a'\n      if (c >= 49) {\n        r += c - 49 + 0xa;\n\n      // 'A'\n      } else if (c >= 17) {\n        r += c - 17 + 0xa;\n\n      // '0' - '9'\n      } else {\n        r += c;\n      }\n    }\n    return r;\n  }\n\n  BN.prototype._parseBase = function _parseBase (number, base, start) {\n    // Initialize as zero\n    this.words = [ 0 ];\n    this.length = 1;\n\n    // Find length of limb in base\n    for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {\n      limbLen++;\n    }\n    limbLen--;\n    limbPow = (limbPow / base) | 0;\n\n    var total = number.length - start;\n    var mod = total % limbLen;\n    var end = Math.min(total, total - mod) + start;\n\n    var word = 0;\n    for (var i = start; i < end; i += limbLen) {\n      word = parseBase(number, i, i + limbLen, base);\n\n      this.imuln(limbPow);\n      if (this.words[0] + word < 0x4000000) {\n        this.words[0] += word;\n      } else {\n        this._iaddn(word);\n      }\n    }\n\n    if (mod !== 0) {\n      var pow = 1;\n      word = parseBase(number, i, number.length, base);\n\n      for (i = 0; i < mod; i++) {\n        pow *= base;\n      }\n\n      this.imuln(pow);\n      if (this.words[0] + word < 0x4000000) {\n        this.words[0] += word;\n      } else {\n        this._iaddn(word);\n      }\n    }\n  };\n\n  BN.prototype.copy = function copy (dest) {\n    dest.words = new Array(this.length);\n    for (var i = 0; i < this.length; i++) {\n      dest.words[i] = this.words[i];\n    }\n    dest.length = this.length;\n    dest.negative = this.negative;\n    dest.red = this.red;\n  };\n\n  BN.prototype.clone = function clone () {\n    var r = new BN(null);\n    this.copy(r);\n    return r;\n  };\n\n  BN.prototype._expand = function _expand (size) {\n    while (this.length < size) {\n      this.words[this.length++] = 0;\n    }\n    return this;\n  };\n\n  // Remove leading `0` from `this`\n  BN.prototype.strip = function strip () {\n    while (this.length > 1 && this.words[this.length - 1] === 0) {\n      this.length--;\n    }\n    return this._normSign();\n  };\n\n  BN.prototype._normSign = function _normSign () {\n    // -0 = 0\n    if (this.length === 1 && this.words[0] === 0) {\n      this.negative = 0;\n    }\n    return this;\n  };\n\n  BN.prototype.inspect = function inspect () {\n    return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';\n  };\n\n  /*\n\n  var zeros = [];\n  var groupSizes = [];\n  var groupBases = [];\n\n  var s = '';\n  var i = -1;\n  while (++i < BN.wordSize) {\n    zeros[i] = s;\n    s += '0';\n  }\n  groupSizes[0] = 0;\n  groupSizes[1] = 0;\n  groupBases[0] = 0;\n  groupBases[1] = 0;\n  var base = 2 - 1;\n  while (++base < 36 + 1) {\n    var groupSize = 0;\n    var groupBase = 1;\n    while (groupBase < (1 << BN.wordSize) / base) {\n      groupBase *= base;\n      groupSize += 1;\n    }\n    groupSizes[base] = groupSize;\n    groupBases[base] = groupBase;\n  }\n\n  */\n\n  var zeros = [\n    '',\n    '0',\n    '00',\n    '000',\n    '0000',\n    '00000',\n    '000000',\n    '0000000',\n    '00000000',\n    '000000000',\n    '0000000000',\n    '00000000000',\n    '000000000000',\n    '0000000000000',\n    '00000000000000',\n    '000000000000000',\n    '0000000000000000',\n    '00000000000000000',\n    '000000000000000000',\n    '0000000000000000000',\n    '00000000000000000000',\n    '000000000000000000000',\n    '0000000000000000000000',\n    '00000000000000000000000',\n    '000000000000000000000000',\n    '0000000000000000000000000'\n  ];\n\n  var groupSizes = [\n    0, 0,\n    25, 16, 12, 11, 10, 9, 8,\n    8, 7, 7, 7, 7, 6, 6,\n    6, 6, 6, 6, 6, 5, 5,\n    5, 5, 5, 5, 5, 5, 5,\n    5, 5, 5, 5, 5, 5, 5\n  ];\n\n  var groupBases = [\n    0, 0,\n    33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,\n    43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,\n    16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,\n    6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,\n    24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176\n  ];\n\n  BN.prototype.toString = function toString (base, padding) {\n    base = base || 10;\n    padding = padding | 0 || 1;\n\n    var out;\n    if (base === 16 || base === 'hex') {\n      out = '';\n      var off = 0;\n      var carry = 0;\n      for (var i = 0; i < this.length; i++) {\n        var w = this.words[i];\n        var word = (((w << off) | carry) & 0xffffff).toString(16);\n        carry = (w >>> (24 - off)) & 0xffffff;\n        if (carry !== 0 || i !== this.length - 1) {\n          out = zeros[6 - word.length] + word + out;\n        } else {\n          out = word + out;\n        }\n        off += 2;\n        if (off >= 26) {\n          off -= 26;\n          i--;\n        }\n      }\n      if (carry !== 0) {\n        out = carry.toString(16) + out;\n      }\n      while (out.length % padding !== 0) {\n        out = '0' + out;\n      }\n      if (this.negative !== 0) {\n        out = '-' + out;\n      }\n      return out;\n    }\n\n    if (base === (base | 0) && base >= 2 && base <= 36) {\n      // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));\n      var groupSize = groupSizes[base];\n      // var groupBase = Math.pow(base, groupSize);\n      var groupBase = groupBases[base];\n      out = '';\n      var c = this.clone();\n      c.negative = 0;\n      while (!c.isZero()) {\n        var r = c.modn(groupBase).toString(base);\n        c = c.idivn(groupBase);\n\n        if (!c.isZero()) {\n          out = zeros[groupSize - r.length] + r + out;\n        } else {\n          out = r + out;\n        }\n      }\n      if (this.isZero()) {\n        out = '0' + out;\n      }\n      while (out.length % padding !== 0) {\n        out = '0' + out;\n      }\n      if (this.negative !== 0) {\n        out = '-' + out;\n      }\n      return out;\n    }\n\n    assert(false, 'Base should be between 2 and 36');\n  };\n\n  BN.prototype.toNumber = function toNumber () {\n    var ret = this.words[0];\n    if (this.length === 2) {\n      ret += this.words[1] * 0x4000000;\n    } else if (this.length === 3 && this.words[2] === 0x01) {\n      // NOTE: at this stage it is known that the top bit is set\n      ret += 0x10000000000000 + (this.words[1] * 0x4000000);\n    } else if (this.length > 2) {\n      assert(false, 'Number can only safely store up to 53 bits');\n    }\n    return (this.negative !== 0) ? -ret : ret;\n  };\n\n  BN.prototype.toJSON = function toJSON () {\n    return this.toString(16);\n  };\n\n  BN.prototype.toBuffer = function toBuffer (endian, length) {\n    assert(typeof Buffer !== 'undefined');\n    return this.toArrayLike(Buffer, endian, length);\n  };\n\n  BN.prototype.toArray = function toArray (endian, length) {\n    return this.toArrayLike(Array, endian, length);\n  };\n\n  BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {\n    var byteLength = this.byteLength();\n    var reqLength = length || Math.max(1, byteLength);\n    assert(byteLength <= reqLength, 'byte array longer than desired length');\n    assert(reqLength > 0, 'Requested array length <= 0');\n\n    this.strip();\n    var littleEndian = endian === 'le';\n    var res = new ArrayType(reqLength);\n\n    var b, i;\n    var q = this.clone();\n    if (!littleEndian) {\n      // Assume big-endian\n      for (i = 0; i < reqLength - byteLength; i++) {\n        res[i] = 0;\n      }\n\n      for (i = 0; !q.isZero(); i++) {\n        b = q.andln(0xff);\n        q.iushrn(8);\n\n        res[reqLength - i - 1] = b;\n      }\n    } else {\n      for (i = 0; !q.isZero(); i++) {\n        b = q.andln(0xff);\n        q.iushrn(8);\n\n        res[i] = b;\n      }\n\n      for (; i < reqLength; i++) {\n        res[i] = 0;\n      }\n    }\n\n    return res;\n  };\n\n  if (Math.clz32) {\n    BN.prototype._countBits = function _countBits (w) {\n      return 32 - Math.clz32(w);\n    };\n  } else {\n    BN.prototype._countBits = function _countBits (w) {\n      var t = w;\n      var r = 0;\n      if (t >= 0x1000) {\n        r += 13;\n        t >>>= 13;\n      }\n      if (t >= 0x40) {\n        r += 7;\n        t >>>= 7;\n      }\n      if (t >= 0x8) {\n        r += 4;\n        t >>>= 4;\n      }\n      if (t >= 0x02) {\n        r += 2;\n        t >>>= 2;\n      }\n      return r + t;\n    };\n  }\n\n  BN.prototype._zeroBits = function _zeroBits (w) {\n    // Short-cut\n    if (w === 0) return 26;\n\n    var t = w;\n    var r = 0;\n    if ((t & 0x1fff) === 0) {\n      r += 13;\n      t >>>= 13;\n    }\n    if ((t & 0x7f) === 0) {\n      r += 7;\n      t >>>= 7;\n    }\n    if ((t & 0xf) === 0) {\n      r += 4;\n      t >>>= 4;\n    }\n    if ((t & 0x3) === 0) {\n      r += 2;\n      t >>>= 2;\n    }\n    if ((t & 0x1) === 0) {\n      r++;\n    }\n    return r;\n  };\n\n  // Return number of used bits in a BN\n  BN.prototype.bitLength = function bitLength () {\n    var w = this.words[this.length - 1];\n    var hi = this._countBits(w);\n    return (this.length - 1) * 26 + hi;\n  };\n\n  function toBitArray (num) {\n    var w = new Array(num.bitLength());\n\n    for (var bit = 0; bit < w.length; bit++) {\n      var off = (bit / 26) | 0;\n      var wbit = bit % 26;\n\n      w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;\n    }\n\n    return w;\n  }\n\n  // Number of trailing zero bits\n  BN.prototype.zeroBits = function zeroBits () {\n    if (this.isZero()) return 0;\n\n    var r = 0;\n    for (var i = 0; i < this.length; i++) {\n      var b = this._zeroBits(this.words[i]);\n      r += b;\n      if (b !== 26) break;\n    }\n    return r;\n  };\n\n  BN.prototype.byteLength = function byteLength () {\n    return Math.ceil(this.bitLength() / 8);\n  };\n\n  BN.prototype.toTwos = function toTwos (width) {\n    if (this.negative !== 0) {\n      return this.abs().inotn(width).iaddn(1);\n    }\n    return this.clone();\n  };\n\n  BN.prototype.fromTwos = function fromTwos (width) {\n    if (this.testn(width - 1)) {\n      return this.notn(width).iaddn(1).ineg();\n    }\n    return this.clone();\n  };\n\n  BN.prototype.isNeg = function isNeg () {\n    return this.negative !== 0;\n  };\n\n  // Return negative clone of `this`\n  BN.prototype.neg = function neg () {\n    return this.clone().ineg();\n  };\n\n  BN.prototype.ineg = function ineg () {\n    if (!this.isZero()) {\n      this.negative ^= 1;\n    }\n\n    return this;\n  };\n\n  // Or `num` with `this` in-place\n  BN.prototype.iuor = function iuor (num) {\n    while (this.length < num.length) {\n      this.words[this.length++] = 0;\n    }\n\n    for (var i = 0; i < num.length; i++) {\n      this.words[i] = this.words[i] | num.words[i];\n    }\n\n    return this.strip();\n  };\n\n  BN.prototype.ior = function ior (num) {\n    assert((this.negative | num.negative) === 0);\n    return this.iuor(num);\n  };\n\n  // Or `num` with `this`\n  BN.prototype.or = function or (num) {\n    if (this.length > num.length) return this.clone().ior(num);\n    return num.clone().ior(this);\n  };\n\n  BN.prototype.uor = function uor (num) {\n    if (this.length > num.length) return this.clone().iuor(num);\n    return num.clone().iuor(this);\n  };\n\n  // And `num` with `this` in-place\n  BN.prototype.iuand = function iuand (num) {\n    // b = min-length(num, this)\n    var b;\n    if (this.length > num.length) {\n      b = num;\n    } else {\n      b = this;\n    }\n\n    for (var i = 0; i < b.length; i++) {\n      this.words[i] = this.words[i] & num.words[i];\n    }\n\n    this.length = b.length;\n\n    return this.strip();\n  };\n\n  BN.prototype.iand = function iand (num) {\n    assert((this.negative | num.negative) === 0);\n    return this.iuand(num);\n  };\n\n  // And `num` with `this`\n  BN.prototype.and = function and (num) {\n    if (this.length > num.length) return this.clone().iand(num);\n    return num.clone().iand(this);\n  };\n\n  BN.prototype.uand = function uand (num) {\n    if (this.length > num.length) return this.clone().iuand(num);\n    return num.clone().iuand(this);\n  };\n\n  // Xor `num` with `this` in-place\n  BN.prototype.iuxor = function iuxor (num) {\n    // a.length > b.length\n    var a;\n    var b;\n    if (this.length > num.length) {\n      a = this;\n      b = num;\n    } else {\n      a = num;\n      b = this;\n    }\n\n    for (var i = 0; i < b.length; i++) {\n      this.words[i] = a.words[i] ^ b.words[i];\n    }\n\n    if (this !== a) {\n      for (; i < a.length; i++) {\n        this.words[i] = a.words[i];\n      }\n    }\n\n    this.length = a.length;\n\n    return this.strip();\n  };\n\n  BN.prototype.ixor = function ixor (num) {\n    assert((this.negative | num.negative) === 0);\n    return this.iuxor(num);\n  };\n\n  // Xor `num` with `this`\n  BN.prototype.xor = function xor (num) {\n    if (this.length > num.length) return this.clone().ixor(num);\n    return num.clone().ixor(this);\n  };\n\n  BN.prototype.uxor = function uxor (num) {\n    if (this.length > num.length) return this.clone().iuxor(num);\n    return num.clone().iuxor(this);\n  };\n\n  // Not ``this`` with ``width`` bitwidth\n  BN.prototype.inotn = function inotn (width) {\n    assert(typeof width === 'number' && width >= 0);\n\n    var bytesNeeded = Math.ceil(width / 26) | 0;\n    var bitsLeft = width % 26;\n\n    // Extend the buffer with leading zeroes\n    this._expand(bytesNeeded);\n\n    if (bitsLeft > 0) {\n      bytesNeeded--;\n    }\n\n    // Handle complete words\n    for (var i = 0; i < bytesNeeded; i++) {\n      this.words[i] = ~this.words[i] & 0x3ffffff;\n    }\n\n    // Handle the residue\n    if (bitsLeft > 0) {\n      this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));\n    }\n\n    // And remove leading zeroes\n    return this.strip();\n  };\n\n  BN.prototype.notn = function notn (width) {\n    return this.clone().inotn(width);\n  };\n\n  // Set `bit` of `this`\n  BN.prototype.setn = function setn (bit, val) {\n    assert(typeof bit === 'number' && bit >= 0);\n\n    var off = (bit / 26) | 0;\n    var wbit = bit % 26;\n\n    this._expand(off + 1);\n\n    if (val) {\n      this.words[off] = this.words[off] | (1 << wbit);\n    } else {\n      this.words[off] = this.words[off] & ~(1 << wbit);\n    }\n\n    return this.strip();\n  };\n\n  // Add `num` to `this` in-place\n  BN.prototype.iadd = function iadd (num) {\n    var r;\n\n    // negative + positive\n    if (this.negative !== 0 && num.negative === 0) {\n      this.negative = 0;\n      r = this.isub(num);\n      this.negative ^= 1;\n      return this._normSign();\n\n    // positive + negative\n    } else if (this.negative === 0 && num.negative !== 0) {\n      num.negative = 0;\n      r = this.isub(num);\n      num.negative = 1;\n      return r._normSign();\n    }\n\n    // a.length > b.length\n    var a, b;\n    if (this.length > num.length) {\n      a = this;\n      b = num;\n    } else {\n      a = num;\n      b = this;\n    }\n\n    var carry = 0;\n    for (var i = 0; i < b.length; i++) {\n      r = (a.words[i] | 0) + (b.words[i] | 0) + carry;\n      this.words[i] = r & 0x3ffffff;\n      carry = r >>> 26;\n    }\n    for (; carry !== 0 && i < a.length; i++) {\n      r = (a.words[i] | 0) + carry;\n      this.words[i] = r & 0x3ffffff;\n      carry = r >>> 26;\n    }\n\n    this.length = a.length;\n    if (carry !== 0) {\n      this.words[this.length] = carry;\n      this.length++;\n    // Copy the rest of the words\n    } else if (a !== this) {\n      for (; i < a.length; i++) {\n        this.words[i] = a.words[i];\n      }\n    }\n\n    return this;\n  };\n\n  // Add `num` to `this`\n  BN.prototype.add = function add (num) {\n    var res;\n    if (num.negative !== 0 && this.negative === 0) {\n      num.negative = 0;\n      res = this.sub(num);\n      num.negative ^= 1;\n      return res;\n    } else if (num.negative === 0 && this.negative !== 0) {\n      this.negative = 0;\n      res = num.sub(this);\n      this.negative = 1;\n      return res;\n    }\n\n    if (this.length > num.length) return this.clone().iadd(num);\n\n    return num.clone().iadd(this);\n  };\n\n  // Subtract `num` from `this` in-place\n  BN.prototype.isub = function isub (num) {\n    // this - (-num) = this + num\n    if (num.negative !== 0) {\n      num.negative = 0;\n      var r = this.iadd(num);\n      num.negative = 1;\n      return r._normSign();\n\n    // -this - num = -(this + num)\n    } else if (this.negative !== 0) {\n      this.negative = 0;\n      this.iadd(num);\n      this.negative = 1;\n      return this._normSign();\n    }\n\n    // At this point both numbers are positive\n    var cmp = this.cmp(num);\n\n    // Optimization - zeroify\n    if (cmp === 0) {\n      this.negative = 0;\n      this.length = 1;\n      this.words[0] = 0;\n      return this;\n    }\n\n    // a > b\n    var a, b;\n    if (cmp > 0) {\n      a = this;\n      b = num;\n    } else {\n      a = num;\n      b = this;\n    }\n\n    var carry = 0;\n    for (var i = 0; i < b.length; i++) {\n      r = (a.words[i] | 0) - (b.words[i] | 0) + carry;\n      carry = r >> 26;\n      this.words[i] = r & 0x3ffffff;\n    }\n    for (; carry !== 0 && i < a.length; i++) {\n      r = (a.words[i] | 0) + carry;\n      carry = r >> 26;\n      this.words[i] = r & 0x3ffffff;\n    }\n\n    // Copy rest of the words\n    if (carry === 0 && i < a.length && a !== this) {\n      for (; i < a.length; i++) {\n        this.words[i] = a.words[i];\n      }\n    }\n\n    this.length = Math.max(this.length, i);\n\n    if (a !== this) {\n      this.negative = 1;\n    }\n\n    return this.strip();\n  };\n\n  // Subtract `num` from `this`\n  BN.prototype.sub = function sub (num) {\n    return this.clone().isub(num);\n  };\n\n  function smallMulTo (self, num, out) {\n    out.negative = num.negative ^ self.negative;\n    var len = (self.length + num.length) | 0;\n    out.length = len;\n    len = (len - 1) | 0;\n\n    // Peel one iteration (compiler can't do it, because of code complexity)\n    var a = self.words[0] | 0;\n    var b = num.words[0] | 0;\n    var r = a * b;\n\n    var lo = r & 0x3ffffff;\n    var carry = (r / 0x4000000) | 0;\n    out.words[0] = lo;\n\n    for (var k = 1; k < len; k++) {\n      // Sum all words with the same `i + j = k` and accumulate `ncarry`,\n      // note that ncarry could be >= 0x3ffffff\n      var ncarry = carry >>> 26;\n      var rword = carry & 0x3ffffff;\n      var maxJ = Math.min(k, num.length - 1);\n      for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {\n        var i = (k - j) | 0;\n        a = self.words[i] | 0;\n        b = num.words[j] | 0;\n        r = a * b + rword;\n        ncarry += (r / 0x4000000) | 0;\n        rword = r & 0x3ffffff;\n      }\n      out.words[k] = rword | 0;\n      carry = ncarry | 0;\n    }\n    if (carry !== 0) {\n      out.words[k] = carry | 0;\n    } else {\n      out.length--;\n    }\n\n    return out.strip();\n  }\n\n  // TODO(indutny): it may be reasonable to omit it for users who don't need\n  // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit\n  // multiplication (like elliptic secp256k1).\n  var comb10MulTo = function comb10MulTo (self, num, out) {\n    var a = self.words;\n    var b = num.words;\n    var o = out.words;\n    var c = 0;\n    var lo;\n    var mid;\n    var hi;\n    var a0 = a[0] | 0;\n    var al0 = a0 & 0x1fff;\n    var ah0 = a0 >>> 13;\n    var a1 = a[1] | 0;\n    var al1 = a1 & 0x1fff;\n    var ah1 = a1 >>> 13;\n    var a2 = a[2] | 0;\n    var al2 = a2 & 0x1fff;\n    var ah2 = a2 >>> 13;\n    var a3 = a[3] | 0;\n    var al3 = a3 & 0x1fff;\n    var ah3 = a3 >>> 13;\n    var a4 = a[4] | 0;\n    var al4 = a4 & 0x1fff;\n    var ah4 = a4 >>> 13;\n    var a5 = a[5] | 0;\n    var al5 = a5 & 0x1fff;\n    var ah5 = a5 >>> 13;\n    var a6 = a[6] | 0;\n    var al6 = a6 & 0x1fff;\n    var ah6 = a6 >>> 13;\n    var a7 = a[7] | 0;\n    var al7 = a7 & 0x1fff;\n    var ah7 = a7 >>> 13;\n    var a8 = a[8] | 0;\n    var al8 = a8 & 0x1fff;\n    var ah8 = a8 >>> 13;\n    var a9 = a[9] | 0;\n    var al9 = a9 & 0x1fff;\n    var ah9 = a9 >>> 13;\n    var b0 = b[0] | 0;\n    var bl0 = b0 & 0x1fff;\n    var bh0 = b0 >>> 13;\n    var b1 = b[1] | 0;\n    var bl1 = b1 & 0x1fff;\n    var bh1 = b1 >>> 13;\n    var b2 = b[2] | 0;\n    var bl2 = b2 & 0x1fff;\n    var bh2 = b2 >>> 13;\n    var b3 = b[3] | 0;\n    var bl3 = b3 & 0x1fff;\n    var bh3 = b3 >>> 13;\n    var b4 = b[4] | 0;\n    var bl4 = b4 & 0x1fff;\n    var bh4 = b4 >>> 13;\n    var b5 = b[5] | 0;\n    var bl5 = b5 & 0x1fff;\n    var bh5 = b5 >>> 13;\n    var b6 = b[6] | 0;\n    var bl6 = b6 & 0x1fff;\n    var bh6 = b6 >>> 13;\n    var b7 = b[7] | 0;\n    var bl7 = b7 & 0x1fff;\n    var bh7 = b7 >>> 13;\n    var b8 = b[8] | 0;\n    var bl8 = b8 & 0x1fff;\n    var bh8 = b8 >>> 13;\n    var b9 = b[9] | 0;\n    var bl9 = b9 & 0x1fff;\n    var bh9 = b9 >>> 13;\n\n    out.negative = self.negative ^ num.negative;\n    out.length = 19;\n    /* k = 0 */\n    lo = Math.imul(al0, bl0);\n    mid = Math.imul(al0, bh0);\n    mid = (mid + Math.imul(ah0, bl0)) | 0;\n    hi = Math.imul(ah0, bh0);\n    var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;\n    w0 &= 0x3ffffff;\n    /* k = 1 */\n    lo = Math.imul(al1, bl0);\n    mid = Math.imul(al1, bh0);\n    mid = (mid + Math.imul(ah1, bl0)) | 0;\n    hi = Math.imul(ah1, bh0);\n    lo = (lo + Math.imul(al0, bl1)) | 0;\n    mid = (mid + Math.imul(al0, bh1)) | 0;\n    mid = (mid + Math.imul(ah0, bl1)) | 0;\n    hi = (hi + Math.imul(ah0, bh1)) | 0;\n    var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;\n    w1 &= 0x3ffffff;\n    /* k = 2 */\n    lo = Math.imul(al2, bl0);\n    mid = Math.imul(al2, bh0);\n    mid = (mid + Math.imul(ah2, bl0)) | 0;\n    hi = Math.imul(ah2, bh0);\n    lo = (lo + Math.imul(al1, bl1)) | 0;\n    mid = (mid + Math.imul(al1, bh1)) | 0;\n    mid = (mid + Math.imul(ah1, bl1)) | 0;\n    hi = (hi + Math.imul(ah1, bh1)) | 0;\n    lo = (lo + Math.imul(al0, bl2)) | 0;\n    mid = (mid + Math.imul(al0, bh2)) | 0;\n    mid = (mid + Math.imul(ah0, bl2)) | 0;\n    hi = (hi + Math.imul(ah0, bh2)) | 0;\n    var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;\n    w2 &= 0x3ffffff;\n    /* k = 3 */\n    lo = Math.imul(al3, bl0);\n    mid = Math.imul(al3, bh0);\n    mid = (mid + Math.imul(ah3, bl0)) | 0;\n    hi = Math.imul(ah3, bh0);\n    lo = (lo + Math.imul(al2, bl1)) | 0;\n    mid = (mid + Math.imul(al2, bh1)) | 0;\n    mid = (mid + Math.imul(ah2, bl1)) | 0;\n    hi = (hi + Math.imul(ah2, bh1)) | 0;\n    lo = (lo + Math.imul(al1, bl2)) | 0;\n    mid = (mid + Math.imul(al1, bh2)) | 0;\n    mid = (mid + Math.imul(ah1, bl2)) | 0;\n    hi = (hi + Math.imul(ah1, bh2)) | 0;\n    lo = (lo + Math.imul(al0, bl3)) | 0;\n    mid = (mid + Math.imul(al0, bh3)) | 0;\n    mid = (mid + Math.imul(ah0, bl3)) | 0;\n    hi = (hi + Math.imul(ah0, bh3)) | 0;\n    var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;\n    w3 &= 0x3ffffff;\n    /* k = 4 */\n    lo = Math.imul(al4, bl0);\n    mid = Math.imul(al4, bh0);\n    mid = (mid + Math.imul(ah4, bl0)) | 0;\n    hi = Math.imul(ah4, bh0);\n    lo = (lo + Math.imul(al3, bl1)) | 0;\n    mid = (mid + Math.imul(al3, bh1)) | 0;\n    mid = (mid + Math.imul(ah3, bl1)) | 0;\n    hi = (hi + Math.imul(ah3, bh1)) | 0;\n    lo = (lo + Math.imul(al2, bl2)) | 0;\n    mid = (mid + Math.imul(al2, bh2)) | 0;\n    mid = (mid + Math.imul(ah2, bl2)) | 0;\n    hi = (hi + Math.imul(ah2, bh2)) | 0;\n    lo = (lo + Math.imul(al1, bl3)) | 0;\n    mid = (mid + Math.imul(al1, bh3)) | 0;\n    mid = (mid + Math.imul(ah1, bl3)) | 0;\n    hi = (hi + Math.imul(ah1, bh3)) | 0;\n    lo = (lo + Math.imul(al0, bl4)) | 0;\n    mid = (mid + Math.imul(al0, bh4)) | 0;\n    mid = (mid + Math.imul(ah0, bl4)) | 0;\n    hi = (hi + Math.imul(ah0, bh4)) | 0;\n    var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;\n    w4 &= 0x3ffffff;\n    /* k = 5 */\n    lo = Math.imul(al5, bl0);\n    mid = Math.imul(al5, bh0);\n    mid = (mid + Math.imul(ah5, bl0)) | 0;\n    hi = Math.imul(ah5, bh0);\n    lo = (lo + Math.imul(al4, bl1)) | 0;\n    mid = (mid + Math.imul(al4, bh1)) | 0;\n    mid = (mid + Math.imul(ah4, bl1)) | 0;\n    hi = (hi + Math.imul(ah4, bh1)) | 0;\n    lo = (lo + Math.imul(al3, bl2)) | 0;\n    mid = (mid + Math.imul(al3, bh2)) | 0;\n    mid = (mid + Math.imul(ah3, bl2)) | 0;\n    hi = (hi + Math.imul(ah3, bh2)) | 0;\n    lo = (lo + Math.imul(al2, bl3)) | 0;\n    mid = (mid + Math.imul(al2, bh3)) | 0;\n    mid = (mid + Math.imul(ah2, bl3)) | 0;\n    hi = (hi + Math.imul(ah2, bh3)) | 0;\n    lo = (lo + Math.imul(al1, bl4)) | 0;\n    mid = (mid + Math.imul(al1, bh4)) | 0;\n    mid = (mid + Math.imul(ah1, bl4)) | 0;\n    hi = (hi + Math.imul(ah1, bh4)) | 0;\n    lo = (lo + Math.imul(al0, bl5)) | 0;\n    mid = (mid + Math.imul(al0, bh5)) | 0;\n    mid = (mid + Math.imul(ah0, bl5)) | 0;\n    hi = (hi + Math.imul(ah0, bh5)) | 0;\n    var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;\n    w5 &= 0x3ffffff;\n    /* k = 6 */\n    lo = Math.imul(al6, bl0);\n    mid = Math.imul(al6, bh0);\n    mid = (mid + Math.imul(ah6, bl0)) | 0;\n    hi = Math.imul(ah6, bh0);\n    lo = (lo + Math.imul(al5, bl1)) | 0;\n    mid = (mid + Math.imul(al5, bh1)) | 0;\n    mid = (mid + Math.imul(ah5, bl1)) | 0;\n    hi = (hi + Math.imul(ah5, bh1)) | 0;\n    lo = (lo + Math.imul(al4, bl2)) | 0;\n    mid = (mid + Math.imul(al4, bh2)) | 0;\n    mid = (mid + Math.imul(ah4, bl2)) | 0;\n    hi = (hi + Math.imul(ah4, bh2)) | 0;\n    lo = (lo + Math.imul(al3, bl3)) | 0;\n    mid = (mid + Math.imul(al3, bh3)) | 0;\n    mid = (mid + Math.imul(ah3, bl3)) | 0;\n    hi = (hi + Math.imul(ah3, bh3)) | 0;\n    lo = (lo + Math.imul(al2, bl4)) | 0;\n    mid = (mid + Math.imul(al2, bh4)) | 0;\n    mid = (mid + Math.imul(ah2, bl4)) | 0;\n    hi = (hi + Math.imul(ah2, bh4)) | 0;\n    lo = (lo + Math.imul(al1, bl5)) | 0;\n    mid = (mid + Math.imul(al1, bh5)) | 0;\n    mid = (mid + Math.imul(ah1, bl5)) | 0;\n    hi = (hi + Math.imul(ah1, bh5)) | 0;\n    lo = (lo + Math.imul(al0, bl6)) | 0;\n    mid = (mid + Math.imul(al0, bh6)) | 0;\n    mid = (mid + Math.imul(ah0, bl6)) | 0;\n    hi = (hi + Math.imul(ah0, bh6)) | 0;\n    var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;\n    w6 &= 0x3ffffff;\n    /* k = 7 */\n    lo = Math.imul(al7, bl0);\n    mid = Math.imul(al7, bh0);\n    mid = (mid + Math.imul(ah7, bl0)) | 0;\n    hi = Math.imul(ah7, bh0);\n    lo = (lo + Math.imul(al6, bl1)) | 0;\n    mid = (mid + Math.imul(al6, bh1)) | 0;\n    mid = (mid + Math.imul(ah6, bl1)) | 0;\n    hi = (hi + Math.imul(ah6, bh1)) | 0;\n    lo = (lo + Math.imul(al5, bl2)) | 0;\n    mid = (mid + Math.imul(al5, bh2)) | 0;\n    mid = (mid + Math.imul(ah5, bl2)) | 0;\n    hi = (hi + Math.imul(ah5, bh2)) | 0;\n    lo = (lo + Math.imul(al4, bl3)) | 0;\n    mid = (mid + Math.imul(al4, bh3)) | 0;\n    mid = (mid + Math.imul(ah4, bl3)) | 0;\n    hi = (hi + Math.imul(ah4, bh3)) | 0;\n    lo = (lo + Math.imul(al3, bl4)) | 0;\n    mid = (mid + Math.imul(al3, bh4)) | 0;\n    mid = (mid + Math.imul(ah3, bl4)) | 0;\n    hi = (hi + Math.imul(ah3, bh4)) | 0;\n    lo = (lo + Math.imul(al2, bl5)) | 0;\n    mid = (mid + Math.imul(al2, bh5)) | 0;\n    mid = (mid + Math.imul(ah2, bl5)) | 0;\n    hi = (hi + Math.imul(ah2, bh5)) | 0;\n    lo = (lo + Math.imul(al1, bl6)) | 0;\n    mid = (mid + Math.imul(al1, bh6)) | 0;\n    mid = (mid + Math.imul(ah1, bl6)) | 0;\n    hi = (hi + Math.imul(ah1, bh6)) | 0;\n    lo = (lo + Math.imul(al0, bl7)) | 0;\n    mid = (mid + Math.imul(al0, bh7)) | 0;\n    mid = (mid + Math.imul(ah0, bl7)) | 0;\n    hi = (hi + Math.imul(ah0, bh7)) | 0;\n    var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;\n    w7 &= 0x3ffffff;\n    /* k = 8 */\n    lo = Math.imul(al8, bl0);\n    mid = Math.imul(al8, bh0);\n    mid = (mid + Math.imul(ah8, bl0)) | 0;\n    hi = Math.imul(ah8, bh0);\n    lo = (lo + Math.imul(al7, bl1)) | 0;\n    mid = (mid + Math.imul(al7, bh1)) | 0;\n    mid = (mid + Math.imul(ah7, bl1)) | 0;\n    hi = (hi + Math.imul(ah7, bh1)) | 0;\n    lo = (lo + Math.imul(al6, bl2)) | 0;\n    mid = (mid + Math.imul(al6, bh2)) | 0;\n    mid = (mid + Math.imul(ah6, bl2)) | 0;\n    hi = (hi + Math.imul(ah6, bh2)) | 0;\n    lo = (lo + Math.imul(al5, bl3)) | 0;\n    mid = (mid + Math.imul(al5, bh3)) | 0;\n    mid = (mid + Math.imul(ah5, bl3)) | 0;\n    hi = (hi + Math.imul(ah5, bh3)) | 0;\n    lo = (lo + Math.imul(al4, bl4)) | 0;\n    mid = (mid + Math.imul(al4, bh4)) | 0;\n    mid = (mid + Math.imul(ah4, bl4)) | 0;\n    hi = (hi + Math.imul(ah4, bh4)) | 0;\n    lo = (lo + Math.imul(al3, bl5)) | 0;\n    mid = (mid + Math.imul(al3, bh5)) | 0;\n    mid = (mid + Math.imul(ah3, bl5)) | 0;\n    hi = (hi + Math.imul(ah3, bh5)) | 0;\n    lo = (lo + Math.imul(al2, bl6)) | 0;\n    mid = (mid + Math.imul(al2, bh6)) | 0;\n    mid = (mid + Math.imul(ah2, bl6)) | 0;\n    hi = (hi + Math.imul(ah2, bh6)) | 0;\n    lo = (lo + Math.imul(al1, bl7)) | 0;\n    mid = (mid + Math.imul(al1, bh7)) | 0;\n    mid = (mid + Math.imul(ah1, bl7)) | 0;\n    hi = (hi + Math.imul(ah1, bh7)) | 0;\n    lo = (lo + Math.imul(al0, bl8)) | 0;\n    mid = (mid + Math.imul(al0, bh8)) | 0;\n    mid = (mid + Math.imul(ah0, bl8)) | 0;\n    hi = (hi + Math.imul(ah0, bh8)) | 0;\n    var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;\n    w8 &= 0x3ffffff;\n    /* k = 9 */\n    lo = Math.imul(al9, bl0);\n    mid = Math.imul(al9, bh0);\n    mid = (mid + Math.imul(ah9, bl0)) | 0;\n    hi = Math.imul(ah9, bh0);\n    lo = (lo + Math.imul(al8, bl1)) | 0;\n    mid = (mid + Math.imul(al8, bh1)) | 0;\n    mid = (mid + Math.imul(ah8, bl1)) | 0;\n    hi = (hi + Math.imul(ah8, bh1)) | 0;\n    lo = (lo + Math.imul(al7, bl2)) | 0;\n    mid = (mid + Math.imul(al7, bh2)) | 0;\n    mid = (mid + Math.imul(ah7, bl2)) | 0;\n    hi = (hi + Math.imul(ah7, bh2)) | 0;\n    lo = (lo + Math.imul(al6, bl3)) | 0;\n    mid = (mid + Math.imul(al6, bh3)) | 0;\n    mid = (mid + Math.imul(ah6, bl3)) | 0;\n    hi = (hi + Math.imul(ah6, bh3)) | 0;\n    lo = (lo + Math.imul(al5, bl4)) | 0;\n    mid = (mid + Math.imul(al5, bh4)) | 0;\n    mid = (mid + Math.imul(ah5, bl4)) | 0;\n    hi = (hi + Math.imul(ah5, bh4)) | 0;\n    lo = (lo + Math.imul(al4, bl5)) | 0;\n    mid = (mid + Math.imul(al4, bh5)) | 0;\n    mid = (mid + Math.imul(ah4, bl5)) | 0;\n    hi = (hi + Math.imul(ah4, bh5)) | 0;\n    lo = (lo + Math.imul(al3, bl6)) | 0;\n    mid = (mid + Math.imul(al3, bh6)) | 0;\n    mid = (mid + Math.imul(ah3, bl6)) | 0;\n    hi = (hi + Math.imul(ah3, bh6)) | 0;\n    lo = (lo + Math.imul(al2, bl7)) | 0;\n    mid = (mid + Math.imul(al2, bh7)) | 0;\n    mid = (mid + Math.imul(ah2, bl7)) | 0;\n    hi = (hi + Math.imul(ah2, bh7)) | 0;\n    lo = (lo + Math.imul(al1, bl8)) | 0;\n    mid = (mid + Math.imul(al1, bh8)) | 0;\n    mid = (mid + Math.imul(ah1, bl8)) | 0;\n    hi = (hi + Math.imul(ah1, bh8)) | 0;\n    lo = (lo + Math.imul(al0, bl9)) | 0;\n    mid = (mid + Math.imul(al0, bh9)) | 0;\n    mid = (mid + Math.imul(ah0, bl9)) | 0;\n    hi = (hi + Math.imul(ah0, bh9)) | 0;\n    var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;\n    w9 &= 0x3ffffff;\n    /* k = 10 */\n    lo = Math.imul(al9, bl1);\n    mid = Math.imul(al9, bh1);\n    mid = (mid + Math.imul(ah9, bl1)) | 0;\n    hi = Math.imul(ah9, bh1);\n    lo = (lo + Math.imul(al8, bl2)) | 0;\n    mid = (mid + Math.imul(al8, bh2)) | 0;\n    mid = (mid + Math.imul(ah8, bl2)) | 0;\n    hi = (hi + Math.imul(ah8, bh2)) | 0;\n    lo = (lo + Math.imul(al7, bl3)) | 0;\n    mid = (mid + Math.imul(al7, bh3)) | 0;\n    mid = (mid + Math.imul(ah7, bl3)) | 0;\n    hi = (hi + Math.imul(ah7, bh3)) | 0;\n    lo = (lo + Math.imul(al6, bl4)) | 0;\n    mid = (mid + Math.imul(al6, bh4)) | 0;\n    mid = (mid + Math.imul(ah6, bl4)) | 0;\n    hi = (hi + Math.imul(ah6, bh4)) | 0;\n    lo = (lo + Math.imul(al5, bl5)) | 0;\n    mid = (mid + Math.imul(al5, bh5)) | 0;\n    mid = (mid + Math.imul(ah5, bl5)) | 0;\n    hi = (hi + Math.imul(ah5, bh5)) | 0;\n    lo = (lo + Math.imul(al4, bl6)) | 0;\n    mid = (mid + Math.imul(al4, bh6)) | 0;\n    mid = (mid + Math.imul(ah4, bl6)) | 0;\n    hi = (hi + Math.imul(ah4, bh6)) | 0;\n    lo = (lo + Math.imul(al3, bl7)) | 0;\n    mid = (mid + Math.imul(al3, bh7)) | 0;\n    mid = (mid + Math.imul(ah3, bl7)) | 0;\n    hi = (hi + Math.imul(ah3, bh7)) | 0;\n    lo = (lo + Math.imul(al2, bl8)) | 0;\n    mid = (mid + Math.imul(al2, bh8)) | 0;\n    mid = (mid + Math.imul(ah2, bl8)) | 0;\n    hi = (hi + Math.imul(ah2, bh8)) | 0;\n    lo = (lo + Math.imul(al1, bl9)) | 0;\n    mid = (mid + Math.imul(al1, bh9)) | 0;\n    mid = (mid + Math.imul(ah1, bl9)) | 0;\n    hi = (hi + Math.imul(ah1, bh9)) | 0;\n    var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;\n    w10 &= 0x3ffffff;\n    /* k = 11 */\n    lo = Math.imul(al9, bl2);\n    mid = Math.imul(al9, bh2);\n    mid = (mid + Math.imul(ah9, bl2)) | 0;\n    hi = Math.imul(ah9, bh2);\n    lo = (lo + Math.imul(al8, bl3)) | 0;\n    mid = (mid + Math.imul(al8, bh3)) | 0;\n    mid = (mid + Math.imul(ah8, bl3)) | 0;\n    hi = (hi + Math.imul(ah8, bh3)) | 0;\n    lo = (lo + Math.imul(al7, bl4)) | 0;\n    mid = (mid + Math.imul(al7, bh4)) | 0;\n    mid = (mid + Math.imul(ah7, bl4)) | 0;\n    hi = (hi + Math.imul(ah7, bh4)) | 0;\n    lo = (lo + Math.imul(al6, bl5)) | 0;\n    mid = (mid + Math.imul(al6, bh5)) | 0;\n    mid = (mid + Math.imul(ah6, bl5)) | 0;\n    hi = (hi + Math.imul(ah6, bh5)) | 0;\n    lo = (lo + Math.imul(al5, bl6)) | 0;\n    mid = (mid + Math.imul(al5, bh6)) | 0;\n    mid = (mid + Math.imul(ah5, bl6)) | 0;\n    hi = (hi + Math.imul(ah5, bh6)) | 0;\n    lo = (lo + Math.imul(al4, bl7)) | 0;\n    mid = (mid + Math.imul(al4, bh7)) | 0;\n    mid = (mid + Math.imul(ah4, bl7)) | 0;\n    hi = (hi + Math.imul(ah4, bh7)) | 0;\n    lo = (lo + Math.imul(al3, bl8)) | 0;\n    mid = (mid + Math.imul(al3, bh8)) | 0;\n    mid = (mid + Math.imul(ah3, bl8)) | 0;\n    hi = (hi + Math.imul(ah3, bh8)) | 0;\n    lo = (lo + Math.imul(al2, bl9)) | 0;\n    mid = (mid + Math.imul(al2, bh9)) | 0;\n    mid = (mid + Math.imul(ah2, bl9)) | 0;\n    hi = (hi + Math.imul(ah2, bh9)) | 0;\n    var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;\n    w11 &= 0x3ffffff;\n    /* k = 12 */\n    lo = Math.imul(al9, bl3);\n    mid = Math.imul(al9, bh3);\n    mid = (mid + Math.imul(ah9, bl3)) | 0;\n    hi = Math.imul(ah9, bh3);\n    lo = (lo + Math.imul(al8, bl4)) | 0;\n    mid = (mid + Math.imul(al8, bh4)) | 0;\n    mid = (mid + Math.imul(ah8, bl4)) | 0;\n    hi = (hi + Math.imul(ah8, bh4)) | 0;\n    lo = (lo + Math.imul(al7, bl5)) | 0;\n    mid = (mid + Math.imul(al7, bh5)) | 0;\n    mid = (mid + Math.imul(ah7, bl5)) | 0;\n    hi = (hi + Math.imul(ah7, bh5)) | 0;\n    lo = (lo + Math.imul(al6, bl6)) | 0;\n    mid = (mid + Math.imul(al6, bh6)) | 0;\n    mid = (mid + Math.imul(ah6, bl6)) | 0;\n    hi = (hi + Math.imul(ah6, bh6)) | 0;\n    lo = (lo + Math.imul(al5, bl7)) | 0;\n    mid = (mid + Math.imul(al5, bh7)) | 0;\n    mid = (mid + Math.imul(ah5, bl7)) | 0;\n    hi = (hi + Math.imul(ah5, bh7)) | 0;\n    lo = (lo + Math.imul(al4, bl8)) | 0;\n    mid = (mid + Math.imul(al4, bh8)) | 0;\n    mid = (mid + Math.imul(ah4, bl8)) | 0;\n    hi = (hi + Math.imul(ah4, bh8)) | 0;\n    lo = (lo + Math.imul(al3, bl9)) | 0;\n    mid = (mid + Math.imul(al3, bh9)) | 0;\n    mid = (mid + Math.imul(ah3, bl9)) | 0;\n    hi = (hi + Math.imul(ah3, bh9)) | 0;\n    var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;\n    w12 &= 0x3ffffff;\n    /* k = 13 */\n    lo = Math.imul(al9, bl4);\n    mid = Math.imul(al9, bh4);\n    mid = (mid + Math.imul(ah9, bl4)) | 0;\n    hi = Math.imul(ah9, bh4);\n    lo = (lo + Math.imul(al8, bl5)) | 0;\n    mid = (mid + Math.imul(al8, bh5)) | 0;\n    mid = (mid + Math.imul(ah8, bl5)) | 0;\n    hi = (hi + Math.imul(ah8, bh5)) | 0;\n    lo = (lo + Math.imul(al7, bl6)) | 0;\n    mid = (mid + Math.imul(al7, bh6)) | 0;\n    mid = (mid + Math.imul(ah7, bl6)) | 0;\n    hi = (hi + Math.imul(ah7, bh6)) | 0;\n    lo = (lo + Math.imul(al6, bl7)) | 0;\n    mid = (mid + Math.imul(al6, bh7)) | 0;\n    mid = (mid + Math.imul(ah6, bl7)) | 0;\n    hi = (hi + Math.imul(ah6, bh7)) | 0;\n    lo = (lo + Math.imul(al5, bl8)) | 0;\n    mid = (mid + Math.imul(al5, bh8)) | 0;\n    mid = (mid + Math.imul(ah5, bl8)) | 0;\n    hi = (hi + Math.imul(ah5, bh8)) | 0;\n    lo = (lo + Math.imul(al4, bl9)) | 0;\n    mid = (mid + Math.imul(al4, bh9)) | 0;\n    mid = (mid + Math.imul(ah4, bl9)) | 0;\n    hi = (hi + Math.imul(ah4, bh9)) | 0;\n    var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;\n    w13 &= 0x3ffffff;\n    /* k = 14 */\n    lo = Math.imul(al9, bl5);\n    mid = Math.imul(al9, bh5);\n    mid = (mid + Math.imul(ah9, bl5)) | 0;\n    hi = Math.imul(ah9, bh5);\n    lo = (lo + Math.imul(al8, bl6)) | 0;\n    mid = (mid + Math.imul(al8, bh6)) | 0;\n    mid = (mid + Math.imul(ah8, bl6)) | 0;\n    hi = (hi + Math.imul(ah8, bh6)) | 0;\n    lo = (lo + Math.imul(al7, bl7)) | 0;\n    mid = (mid + Math.imul(al7, bh7)) | 0;\n    mid = (mid + Math.imul(ah7, bl7)) | 0;\n    hi = (hi + Math.imul(ah7, bh7)) | 0;\n    lo = (lo + Math.imul(al6, bl8)) | 0;\n    mid = (mid + Math.imul(al6, bh8)) | 0;\n    mid = (mid + Math.imul(ah6, bl8)) | 0;\n    hi = (hi + Math.imul(ah6, bh8)) | 0;\n    lo = (lo + Math.imul(al5, bl9)) | 0;\n    mid = (mid + Math.imul(al5, bh9)) | 0;\n    mid = (mid + Math.imul(ah5, bl9)) | 0;\n    hi = (hi + Math.imul(ah5, bh9)) | 0;\n    var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;\n    w14 &= 0x3ffffff;\n    /* k = 15 */\n    lo = Math.imul(al9, bl6);\n    mid = Math.imul(al9, bh6);\n    mid = (mid + Math.imul(ah9, bl6)) | 0;\n    hi = Math.imul(ah9, bh6);\n    lo = (lo + Math.imul(al8, bl7)) | 0;\n    mid = (mid + Math.imul(al8, bh7)) | 0;\n    mid = (mid + Math.imul(ah8, bl7)) | 0;\n    hi = (hi + Math.imul(ah8, bh7)) | 0;\n    lo = (lo + Math.imul(al7, bl8)) | 0;\n    mid = (mid + Math.imul(al7, bh8)) | 0;\n    mid = (mid + Math.imul(ah7, bl8)) | 0;\n    hi = (hi + Math.imul(ah7, bh8)) | 0;\n    lo = (lo + Math.imul(al6, bl9)) | 0;\n    mid = (mid + Math.imul(al6, bh9)) | 0;\n    mid = (mid + Math.imul(ah6, bl9)) | 0;\n    hi = (hi + Math.imul(ah6, bh9)) | 0;\n    var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;\n    w15 &= 0x3ffffff;\n    /* k = 16 */\n    lo = Math.imul(al9, bl7);\n    mid = Math.imul(al9, bh7);\n    mid = (mid + Math.imul(ah9, bl7)) | 0;\n    hi = Math.imul(ah9, bh7);\n    lo = (lo + Math.imul(al8, bl8)) | 0;\n    mid = (mid + Math.imul(al8, bh8)) | 0;\n    mid = (mid + Math.imul(ah8, bl8)) | 0;\n    hi = (hi + Math.imul(ah8, bh8)) | 0;\n    lo = (lo + Math.imul(al7, bl9)) | 0;\n    mid = (mid + Math.imul(al7, bh9)) | 0;\n    mid = (mid + Math.imul(ah7, bl9)) | 0;\n    hi = (hi + Math.imul(ah7, bh9)) | 0;\n    var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;\n    w16 &= 0x3ffffff;\n    /* k = 17 */\n    lo = Math.imul(al9, bl8);\n    mid = Math.imul(al9, bh8);\n    mid = (mid + Math.imul(ah9, bl8)) | 0;\n    hi = Math.imul(ah9, bh8);\n    lo = (lo + Math.imul(al8, bl9)) | 0;\n    mid = (mid + Math.imul(al8, bh9)) | 0;\n    mid = (mid + Math.imul(ah8, bl9)) | 0;\n    hi = (hi + Math.imul(ah8, bh9)) | 0;\n    var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;\n    w17 &= 0x3ffffff;\n    /* k = 18 */\n    lo = Math.imul(al9, bl9);\n    mid = Math.imul(al9, bh9);\n    mid = (mid + Math.imul(ah9, bl9)) | 0;\n    hi = Math.imul(ah9, bh9);\n    var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;\n    c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;\n    w18 &= 0x3ffffff;\n    o[0] = w0;\n    o[1] = w1;\n    o[2] = w2;\n    o[3] = w3;\n    o[4] = w4;\n    o[5] = w5;\n    o[6] = w6;\n    o[7] = w7;\n    o[8] = w8;\n    o[9] = w9;\n    o[10] = w10;\n    o[11] = w11;\n    o[12] = w12;\n    o[13] = w13;\n    o[14] = w14;\n    o[15] = w15;\n    o[16] = w16;\n    o[17] = w17;\n    o[18] = w18;\n    if (c !== 0) {\n      o[19] = c;\n      out.length++;\n    }\n    return out;\n  };\n\n  // Polyfill comb\n  if (!Math.imul) {\n    comb10MulTo = smallMulTo;\n  }\n\n  function bigMulTo (self, num, out) {\n    out.negative = num.negative ^ self.negative;\n    out.length = self.length + num.length;\n\n    var carry = 0;\n    var hncarry = 0;\n    for (var k = 0; k < out.length - 1; k++) {\n      // Sum all words with the same `i + j = k` and accumulate `ncarry`,\n      // note that ncarry could be >= 0x3ffffff\n      var ncarry = hncarry;\n      hncarry = 0;\n      var rword = carry & 0x3ffffff;\n      var maxJ = Math.min(k, num.length - 1);\n      for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {\n        var i = k - j;\n        var a = self.words[i] | 0;\n        var b = num.words[j] | 0;\n        var r = a * b;\n\n        var lo = r & 0x3ffffff;\n        ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;\n        lo = (lo + rword) | 0;\n        rword = lo & 0x3ffffff;\n        ncarry = (ncarry + (lo >>> 26)) | 0;\n\n        hncarry += ncarry >>> 26;\n        ncarry &= 0x3ffffff;\n      }\n      out.words[k] = rword;\n      carry = ncarry;\n      ncarry = hncarry;\n    }\n    if (carry !== 0) {\n      out.words[k] = carry;\n    } else {\n      out.length--;\n    }\n\n    return out.strip();\n  }\n\n  function jumboMulTo (self, num, out) {\n    var fftm = new FFTM();\n    return fftm.mulp(self, num, out);\n  }\n\n  BN.prototype.mulTo = function mulTo (num, out) {\n    var res;\n    var len = this.length + num.length;\n    if (this.length === 10 && num.length === 10) {\n      res = comb10MulTo(this, num, out);\n    } else if (len < 63) {\n      res = smallMulTo(this, num, out);\n    } else if (len < 1024) {\n      res = bigMulTo(this, num, out);\n    } else {\n      res = jumboMulTo(this, num, out);\n    }\n\n    return res;\n  };\n\n  // Cooley-Tukey algorithm for FFT\n  // slightly revisited to rely on looping instead of recursion\n\n  function FFTM (x, y) {\n    this.x = x;\n    this.y = y;\n  }\n\n  FFTM.prototype.makeRBT = function makeRBT (N) {\n    var t = new Array(N);\n    var l = BN.prototype._countBits(N) - 1;\n    for (var i = 0; i < N; i++) {\n      t[i] = this.revBin(i, l, N);\n    }\n\n    return t;\n  };\n\n  // Returns binary-reversed representation of `x`\n  FFTM.prototype.revBin = function revBin (x, l, N) {\n    if (x === 0 || x === N - 1) return x;\n\n    var rb = 0;\n    for (var i = 0; i < l; i++) {\n      rb |= (x & 1) << (l - i - 1);\n      x >>= 1;\n    }\n\n    return rb;\n  };\n\n  // Performs \"tweedling\" phase, therefore 'emulating'\n  // behaviour of the recursive algorithm\n  FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {\n    for (var i = 0; i < N; i++) {\n      rtws[i] = rws[rbt[i]];\n      itws[i] = iws[rbt[i]];\n    }\n  };\n\n  FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {\n    this.permute(rbt, rws, iws, rtws, itws, N);\n\n    for (var s = 1; s < N; s <<= 1) {\n      var l = s << 1;\n\n      var rtwdf = Math.cos(2 * Math.PI / l);\n      var itwdf = Math.sin(2 * Math.PI / l);\n\n      for (var p = 0; p < N; p += l) {\n        var rtwdf_ = rtwdf;\n        var itwdf_ = itwdf;\n\n        for (var j = 0; j < s; j++) {\n          var re = rtws[p + j];\n          var ie = itws[p + j];\n\n          var ro = rtws[p + j + s];\n          var io = itws[p + j + s];\n\n          var rx = rtwdf_ * ro - itwdf_ * io;\n\n          io = rtwdf_ * io + itwdf_ * ro;\n          ro = rx;\n\n          rtws[p + j] = re + ro;\n          itws[p + j] = ie + io;\n\n          rtws[p + j + s] = re - ro;\n          itws[p + j + s] = ie - io;\n\n          /* jshint maxdepth : false */\n          if (j !== l) {\n            rx = rtwdf * rtwdf_ - itwdf * itwdf_;\n\n            itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;\n            rtwdf_ = rx;\n          }\n        }\n      }\n    }\n  };\n\n  FFTM.prototype.guessLen13b = function guessLen13b (n, m) {\n    var N = Math.max(m, n) | 1;\n    var odd = N & 1;\n    var i = 0;\n    for (N = N / 2 | 0; N; N = N >>> 1) {\n      i++;\n    }\n\n    return 1 << i + 1 + odd;\n  };\n\n  FFTM.prototype.conjugate = function conjugate (rws, iws, N) {\n    if (N <= 1) return;\n\n    for (var i = 0; i < N / 2; i++) {\n      var t = rws[i];\n\n      rws[i] = rws[N - i - 1];\n      rws[N - i - 1] = t;\n\n      t = iws[i];\n\n      iws[i] = -iws[N - i - 1];\n      iws[N - i - 1] = -t;\n    }\n  };\n\n  FFTM.prototype.normalize13b = function normalize13b (ws, N) {\n    var carry = 0;\n    for (var i = 0; i < N / 2; i++) {\n      var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +\n        Math.round(ws[2 * i] / N) +\n        carry;\n\n      ws[i] = w & 0x3ffffff;\n\n      if (w < 0x4000000) {\n        carry = 0;\n      } else {\n        carry = w / 0x4000000 | 0;\n      }\n    }\n\n    return ws;\n  };\n\n  FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {\n    var carry = 0;\n    for (var i = 0; i < len; i++) {\n      carry = carry + (ws[i] | 0);\n\n      rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;\n      rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;\n    }\n\n    // Pad with zeroes\n    for (i = 2 * len; i < N; ++i) {\n      rws[i] = 0;\n    }\n\n    assert(carry === 0);\n    assert((carry & ~0x1fff) === 0);\n  };\n\n  FFTM.prototype.stub = function stub (N) {\n    var ph = new Array(N);\n    for (var i = 0; i < N; i++) {\n      ph[i] = 0;\n    }\n\n    return ph;\n  };\n\n  FFTM.prototype.mulp = function mulp (x, y, out) {\n    var N = 2 * this.guessLen13b(x.length, y.length);\n\n    var rbt = this.makeRBT(N);\n\n    var _ = this.stub(N);\n\n    var rws = new Array(N);\n    var rwst = new Array(N);\n    var iwst = new Array(N);\n\n    var nrws = new Array(N);\n    var nrwst = new Array(N);\n    var niwst = new Array(N);\n\n    var rmws = out.words;\n    rmws.length = N;\n\n    this.convert13b(x.words, x.length, rws, N);\n    this.convert13b(y.words, y.length, nrws, N);\n\n    this.transform(rws, _, rwst, iwst, N, rbt);\n    this.transform(nrws, _, nrwst, niwst, N, rbt);\n\n    for (var i = 0; i < N; i++) {\n      var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];\n      iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];\n      rwst[i] = rx;\n    }\n\n    this.conjugate(rwst, iwst, N);\n    this.transform(rwst, iwst, rmws, _, N, rbt);\n    this.conjugate(rmws, _, N);\n    this.normalize13b(rmws, N);\n\n    out.negative = x.negative ^ y.negative;\n    out.length = x.length + y.length;\n    return out.strip();\n  };\n\n  // Multiply `this` by `num`\n  BN.prototype.mul = function mul (num) {\n    var out = new BN(null);\n    out.words = new Array(this.length + num.length);\n    return this.mulTo(num, out);\n  };\n\n  // Multiply employing FFT\n  BN.prototype.mulf = function mulf (num) {\n    var out = new BN(null);\n    out.words = new Array(this.length + num.length);\n    return jumboMulTo(this, num, out);\n  };\n\n  // In-place Multiplication\n  BN.prototype.imul = function imul (num) {\n    return this.clone().mulTo(num, this);\n  };\n\n  BN.prototype.imuln = function imuln (num) {\n    assert(typeof num === 'number');\n    assert(num < 0x4000000);\n\n    // Carry\n    var carry = 0;\n    for (var i = 0; i < this.length; i++) {\n      var w = (this.words[i] | 0) * num;\n      var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);\n      carry >>= 26;\n      carry += (w / 0x4000000) | 0;\n      // NOTE: lo is 27bit maximum\n      carry += lo >>> 26;\n      this.words[i] = lo & 0x3ffffff;\n    }\n\n    if (carry !== 0) {\n      this.words[i] = carry;\n      this.length++;\n    }\n\n    return this;\n  };\n\n  BN.prototype.muln = function muln (num) {\n    return this.clone().imuln(num);\n  };\n\n  // `this` * `this`\n  BN.prototype.sqr = function sqr () {\n    return this.mul(this);\n  };\n\n  // `this` * `this` in-place\n  BN.prototype.isqr = function isqr () {\n    return this.imul(this.clone());\n  };\n\n  // Math.pow(`this`, `num`)\n  BN.prototype.pow = function pow (num) {\n    var w = toBitArray(num);\n    if (w.length === 0) return new BN(1);\n\n    // Skip leading zeroes\n    var res = this;\n    for (var i = 0; i < w.length; i++, res = res.sqr()) {\n      if (w[i] !== 0) break;\n    }\n\n    if (++i < w.length) {\n      for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {\n        if (w[i] === 0) continue;\n\n        res = res.mul(q);\n      }\n    }\n\n    return res;\n  };\n\n  // Shift-left in-place\n  BN.prototype.iushln = function iushln (bits) {\n    assert(typeof bits === 'number' && bits >= 0);\n    var r = bits % 26;\n    var s = (bits - r) / 26;\n    var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);\n    var i;\n\n    if (r !== 0) {\n      var carry = 0;\n\n      for (i = 0; i < this.length; i++) {\n        var newCarry = this.words[i] & carryMask;\n        var c = ((this.words[i] | 0) - newCarry) << r;\n        this.words[i] = c | carry;\n        carry = newCarry >>> (26 - r);\n      }\n\n      if (carry) {\n        this.words[i] = carry;\n        this.length++;\n      }\n    }\n\n    if (s !== 0) {\n      for (i = this.length - 1; i >= 0; i--) {\n        this.words[i + s] = this.words[i];\n      }\n\n      for (i = 0; i < s; i++) {\n        this.words[i] = 0;\n      }\n\n      this.length += s;\n    }\n\n    return this.strip();\n  };\n\n  BN.prototype.ishln = function ishln (bits) {\n    // TODO(indutny): implement me\n    assert(this.negative === 0);\n    return this.iushln(bits);\n  };\n\n  // Shift-right in-place\n  // NOTE: `hint` is a lowest bit before trailing zeroes\n  // NOTE: if `extended` is present - it will be filled with destroyed bits\n  BN.prototype.iushrn = function iushrn (bits, hint, extended) {\n    assert(typeof bits === 'number' && bits >= 0);\n    var h;\n    if (hint) {\n      h = (hint - (hint % 26)) / 26;\n    } else {\n      h = 0;\n    }\n\n    var r = bits % 26;\n    var s = Math.min((bits - r) / 26, this.length);\n    var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);\n    var maskedWords = extended;\n\n    h -= s;\n    h = Math.max(0, h);\n\n    // Extended mode, copy masked part\n    if (maskedWords) {\n      for (var i = 0; i < s; i++) {\n        maskedWords.words[i] = this.words[i];\n      }\n      maskedWords.length = s;\n    }\n\n    if (s === 0) {\n      // No-op, we should not move anything at all\n    } else if (this.length > s) {\n      this.length -= s;\n      for (i = 0; i < this.length; i++) {\n        this.words[i] = this.words[i + s];\n      }\n    } else {\n      this.words[0] = 0;\n      this.length = 1;\n    }\n\n    var carry = 0;\n    for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {\n      var word = this.words[i] | 0;\n      this.words[i] = (carry << (26 - r)) | (word >>> r);\n      carry = word & mask;\n    }\n\n    // Push carried bits as a mask\n    if (maskedWords && carry !== 0) {\n      maskedWords.words[maskedWords.length++] = carry;\n    }\n\n    if (this.length === 0) {\n      this.words[0] = 0;\n      this.length = 1;\n    }\n\n    return this.strip();\n  };\n\n  BN.prototype.ishrn = function ishrn (bits, hint, extended) {\n    // TODO(indutny): implement me\n    assert(this.negative === 0);\n    return this.iushrn(bits, hint, extended);\n  };\n\n  // Shift-left\n  BN.prototype.shln = function shln (bits) {\n    return this.clone().ishln(bits);\n  };\n\n  BN.prototype.ushln = function ushln (bits) {\n    return this.clone().iushln(bits);\n  };\n\n  // Shift-right\n  BN.prototype.shrn = function shrn (bits) {\n    return this.clone().ishrn(bits);\n  };\n\n  BN.prototype.ushrn = function ushrn (bits) {\n    return this.clone().iushrn(bits);\n  };\n\n  // Test if n bit is set\n  BN.prototype.testn = function testn (bit) {\n    assert(typeof bit === 'number' && bit >= 0);\n    var r = bit % 26;\n    var s = (bit - r) / 26;\n    var q = 1 << r;\n\n    // Fast case: bit is much higher than all existing words\n    if (this.length <= s) return false;\n\n    // Check bit and return\n    var w = this.words[s];\n\n    return !!(w & q);\n  };\n\n  // Return only lowers bits of number (in-place)\n  BN.prototype.imaskn = function imaskn (bits) {\n    assert(typeof bits === 'number' && bits >= 0);\n    var r = bits % 26;\n    var s = (bits - r) / 26;\n\n    assert(this.negative === 0, 'imaskn works only with positive numbers');\n\n    if (this.length <= s) {\n      return this;\n    }\n\n    if (r !== 0) {\n      s++;\n    }\n    this.length = Math.min(s, this.length);\n\n    if (r !== 0) {\n      var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);\n      this.words[this.length - 1] &= mask;\n    }\n\n    return this.strip();\n  };\n\n  // Return only lowers bits of number\n  BN.prototype.maskn = function maskn (bits) {\n    return this.clone().imaskn(bits);\n  };\n\n  // Add plain number `num` to `this`\n  BN.prototype.iaddn = function iaddn (num) {\n    assert(typeof num === 'number');\n    assert(num < 0x4000000);\n    if (num < 0) return this.isubn(-num);\n\n    // Possible sign change\n    if (this.negative !== 0) {\n      if (this.length === 1 && (this.words[0] | 0) < num) {\n        this.words[0] = num - (this.words[0] | 0);\n        this.negative = 0;\n        return this;\n      }\n\n      this.negative = 0;\n      this.isubn(num);\n      this.negative = 1;\n      return this;\n    }\n\n    // Add without checks\n    return this._iaddn(num);\n  };\n\n  BN.prototype._iaddn = function _iaddn (num) {\n    this.words[0] += num;\n\n    // Carry\n    for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {\n      this.words[i] -= 0x4000000;\n      if (i === this.length - 1) {\n        this.words[i + 1] = 1;\n      } else {\n        this.words[i + 1]++;\n      }\n    }\n    this.length = Math.max(this.length, i + 1);\n\n    return this;\n  };\n\n  // Subtract plain number `num` from `this`\n  BN.prototype.isubn = function isubn (num) {\n    assert(typeof num === 'number');\n    assert(num < 0x4000000);\n    if (num < 0) return this.iaddn(-num);\n\n    if (this.negative !== 0) {\n      this.negative = 0;\n      this.iaddn(num);\n      this.negative = 1;\n      return this;\n    }\n\n    this.words[0] -= num;\n\n    if (this.length === 1 && this.words[0] < 0) {\n      this.words[0] = -this.words[0];\n      this.negative = 1;\n    } else {\n      // Carry\n      for (var i = 0; i < this.length && this.words[i] < 0; i++) {\n        this.words[i] += 0x4000000;\n        this.words[i + 1] -= 1;\n      }\n    }\n\n    return this.strip();\n  };\n\n  BN.prototype.addn = function addn (num) {\n    return this.clone().iaddn(num);\n  };\n\n  BN.prototype.subn = function subn (num) {\n    return this.clone().isubn(num);\n  };\n\n  BN.prototype.iabs = function iabs () {\n    this.negative = 0;\n\n    return this;\n  };\n\n  BN.prototype.abs = function abs () {\n    return this.clone().iabs();\n  };\n\n  BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {\n    var len = num.length + shift;\n    var i;\n\n    this._expand(len);\n\n    var w;\n    var carry = 0;\n    for (i = 0; i < num.length; i++) {\n      w = (this.words[i + shift] | 0) + carry;\n      var right = (num.words[i] | 0) * mul;\n      w -= right & 0x3ffffff;\n      carry = (w >> 26) - ((right / 0x4000000) | 0);\n      this.words[i + shift] = w & 0x3ffffff;\n    }\n    for (; i < this.length - shift; i++) {\n      w = (this.words[i + shift] | 0) + carry;\n      carry = w >> 26;\n      this.words[i + shift] = w & 0x3ffffff;\n    }\n\n    if (carry === 0) return this.strip();\n\n    // Subtraction overflow\n    assert(carry === -1);\n    carry = 0;\n    for (i = 0; i < this.length; i++) {\n      w = -(this.words[i] | 0) + carry;\n      carry = w >> 26;\n      this.words[i] = w & 0x3ffffff;\n    }\n    this.negative = 1;\n\n    return this.strip();\n  };\n\n  BN.prototype._wordDiv = function _wordDiv (num, mode) {\n    var shift = this.length - num.length;\n\n    var a = this.clone();\n    var b = num;\n\n    // Normalize\n    var bhi = b.words[b.length - 1] | 0;\n    var bhiBits = this._countBits(bhi);\n    shift = 26 - bhiBits;\n    if (shift !== 0) {\n      b = b.ushln(shift);\n      a.iushln(shift);\n      bhi = b.words[b.length - 1] | 0;\n    }\n\n    // Initialize quotient\n    var m = a.length - b.length;\n    var q;\n\n    if (mode !== 'mod') {\n      q = new BN(null);\n      q.length = m + 1;\n      q.words = new Array(q.length);\n      for (var i = 0; i < q.length; i++) {\n        q.words[i] = 0;\n      }\n    }\n\n    var diff = a.clone()._ishlnsubmul(b, 1, m);\n    if (diff.negative === 0) {\n      a = diff;\n      if (q) {\n        q.words[m] = 1;\n      }\n    }\n\n    for (var j = m - 1; j >= 0; j--) {\n      var qj = (a.words[b.length + j] | 0) * 0x4000000 +\n        (a.words[b.length + j - 1] | 0);\n\n      // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max\n      // (0x7ffffff)\n      qj = Math.min((qj / bhi) | 0, 0x3ffffff);\n\n      a._ishlnsubmul(b, qj, j);\n      while (a.negative !== 0) {\n        qj--;\n        a.negative = 0;\n        a._ishlnsubmul(b, 1, j);\n        if (!a.isZero()) {\n          a.negative ^= 1;\n        }\n      }\n      if (q) {\n        q.words[j] = qj;\n      }\n    }\n    if (q) {\n      q.strip();\n    }\n    a.strip();\n\n    // Denormalize\n    if (mode !== 'div' && shift !== 0) {\n      a.iushrn(shift);\n    }\n\n    return {\n      div: q || null,\n      mod: a\n    };\n  };\n\n  // NOTE: 1) `mode` can be set to `mod` to request mod only,\n  //       to `div` to request div only, or be absent to\n  //       request both div & mod\n  //       2) `positive` is true if unsigned mod is requested\n  BN.prototype.divmod = function divmod (num, mode, positive) {\n    assert(!num.isZero());\n\n    if (this.isZero()) {\n      return {\n        div: new BN(0),\n        mod: new BN(0)\n      };\n    }\n\n    var div, mod, res;\n    if (this.negative !== 0 && num.negative === 0) {\n      res = this.neg().divmod(num, mode);\n\n      if (mode !== 'mod') {\n        div = res.div.neg();\n      }\n\n      if (mode !== 'div') {\n        mod = res.mod.neg();\n        if (positive && mod.negative !== 0) {\n          mod.iadd(num);\n        }\n      }\n\n      return {\n        div: div,\n        mod: mod\n      };\n    }\n\n    if (this.negative === 0 && num.negative !== 0) {\n      res = this.divmod(num.neg(), mode);\n\n      if (mode !== 'mod') {\n        div = res.div.neg();\n      }\n\n      return {\n        div: div,\n        mod: res.mod\n      };\n    }\n\n    if ((this.negative & num.negative) !== 0) {\n      res = this.neg().divmod(num.neg(), mode);\n\n      if (mode !== 'div') {\n        mod = res.mod.neg();\n        if (positive && mod.negative !== 0) {\n          mod.isub(num);\n        }\n      }\n\n      return {\n        div: res.div,\n        mod: mod\n      };\n    }\n\n    // Both numbers are positive at this point\n\n    // Strip both numbers to approximate shift value\n    if (num.length > this.length || this.cmp(num) < 0) {\n      return {\n        div: new BN(0),\n        mod: this\n      };\n    }\n\n    // Very short reduction\n    if (num.length === 1) {\n      if (mode === 'div') {\n        return {\n          div: this.divn(num.words[0]),\n          mod: null\n        };\n      }\n\n      if (mode === 'mod') {\n        return {\n          div: null,\n          mod: new BN(this.modn(num.words[0]))\n        };\n      }\n\n      return {\n        div: this.divn(num.words[0]),\n        mod: new BN(this.modn(num.words[0]))\n      };\n    }\n\n    return this._wordDiv(num, mode);\n  };\n\n  // Find `this` / `num`\n  BN.prototype.div = function div (num) {\n    return this.divmod(num, 'div', false).div;\n  };\n\n  // Find `this` % `num`\n  BN.prototype.mod = function mod (num) {\n    return this.divmod(num, 'mod', false).mod;\n  };\n\n  BN.prototype.umod = function umod (num) {\n    return this.divmod(num, 'mod', true).mod;\n  };\n\n  // Find Round(`this` / `num`)\n  BN.prototype.divRound = function divRound (num) {\n    var dm = this.divmod(num);\n\n    // Fast case - exact division\n    if (dm.mod.isZero()) return dm.div;\n\n    var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;\n\n    var half = num.ushrn(1);\n    var r2 = num.andln(1);\n    var cmp = mod.cmp(half);\n\n    // Round down\n    if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;\n\n    // Round up\n    return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);\n  };\n\n  BN.prototype.modn = function modn (num) {\n    assert(num <= 0x3ffffff);\n    var p = (1 << 26) % num;\n\n    var acc = 0;\n    for (var i = this.length - 1; i >= 0; i--) {\n      acc = (p * acc + (this.words[i] | 0)) % num;\n    }\n\n    return acc;\n  };\n\n  // In-place division by number\n  BN.prototype.idivn = function idivn (num) {\n    assert(num <= 0x3ffffff);\n\n    var carry = 0;\n    for (var i = this.length - 1; i >= 0; i--) {\n      var w = (this.words[i] | 0) + carry * 0x4000000;\n      this.words[i] = (w / num) | 0;\n      carry = w % num;\n    }\n\n    return this.strip();\n  };\n\n  BN.prototype.divn = function divn (num) {\n    return this.clone().idivn(num);\n  };\n\n  BN.prototype.egcd = function egcd (p) {\n    assert(p.negative === 0);\n    assert(!p.isZero());\n\n    var x = this;\n    var y = p.clone();\n\n    if (x.negative !== 0) {\n      x = x.umod(p);\n    } else {\n      x = x.clone();\n    }\n\n    // A * x + B * y = x\n    var A = new BN(1);\n    var B = new BN(0);\n\n    // C * x + D * y = y\n    var C = new BN(0);\n    var D = new BN(1);\n\n    var g = 0;\n\n    while (x.isEven() && y.isEven()) {\n      x.iushrn(1);\n      y.iushrn(1);\n      ++g;\n    }\n\n    var yp = y.clone();\n    var xp = x.clone();\n\n    while (!x.isZero()) {\n      for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);\n      if (i > 0) {\n        x.iushrn(i);\n        while (i-- > 0) {\n          if (A.isOdd() || B.isOdd()) {\n            A.iadd(yp);\n            B.isub(xp);\n          }\n\n          A.iushrn(1);\n          B.iushrn(1);\n        }\n      }\n\n      for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);\n      if (j > 0) {\n        y.iushrn(j);\n        while (j-- > 0) {\n          if (C.isOdd() || D.isOdd()) {\n            C.iadd(yp);\n            D.isub(xp);\n          }\n\n          C.iushrn(1);\n          D.iushrn(1);\n        }\n      }\n\n      if (x.cmp(y) >= 0) {\n        x.isub(y);\n        A.isub(C);\n        B.isub(D);\n      } else {\n        y.isub(x);\n        C.isub(A);\n        D.isub(B);\n      }\n    }\n\n    return {\n      a: C,\n      b: D,\n      gcd: y.iushln(g)\n    };\n  };\n\n  // This is reduced incarnation of the binary EEA\n  // above, designated to invert members of the\n  // _prime_ fields F(p) at a maximal speed\n  BN.prototype._invmp = function _invmp (p) {\n    assert(p.negative === 0);\n    assert(!p.isZero());\n\n    var a = this;\n    var b = p.clone();\n\n    if (a.negative !== 0) {\n      a = a.umod(p);\n    } else {\n      a = a.clone();\n    }\n\n    var x1 = new BN(1);\n    var x2 = new BN(0);\n\n    var delta = b.clone();\n\n    while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {\n      for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);\n      if (i > 0) {\n        a.iushrn(i);\n        while (i-- > 0) {\n          if (x1.isOdd()) {\n            x1.iadd(delta);\n          }\n\n          x1.iushrn(1);\n        }\n      }\n\n      for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);\n      if (j > 0) {\n        b.iushrn(j);\n        while (j-- > 0) {\n          if (x2.isOdd()) {\n            x2.iadd(delta);\n          }\n\n          x2.iushrn(1);\n        }\n      }\n\n      if (a.cmp(b) >= 0) {\n        a.isub(b);\n        x1.isub(x2);\n      } else {\n        b.isub(a);\n        x2.isub(x1);\n      }\n    }\n\n    var res;\n    if (a.cmpn(1) === 0) {\n      res = x1;\n    } else {\n      res = x2;\n    }\n\n    if (res.cmpn(0) < 0) {\n      res.iadd(p);\n    }\n\n    return res;\n  };\n\n  BN.prototype.gcd = function gcd (num) {\n    if (this.isZero()) return num.abs();\n    if (num.isZero()) return this.abs();\n\n    var a = this.clone();\n    var b = num.clone();\n    a.negative = 0;\n    b.negative = 0;\n\n    // Remove common factor of two\n    for (var shift = 0; a.isEven() && b.isEven(); shift++) {\n      a.iushrn(1);\n      b.iushrn(1);\n    }\n\n    do {\n      while (a.isEven()) {\n        a.iushrn(1);\n      }\n      while (b.isEven()) {\n        b.iushrn(1);\n      }\n\n      var r = a.cmp(b);\n      if (r < 0) {\n        // Swap `a` and `b` to make `a` always bigger than `b`\n        var t = a;\n        a = b;\n        b = t;\n      } else if (r === 0 || b.cmpn(1) === 0) {\n        break;\n      }\n\n      a.isub(b);\n    } while (true);\n\n    return b.iushln(shift);\n  };\n\n  // Invert number in the field F(num)\n  BN.prototype.invm = function invm (num) {\n    return this.egcd(num).a.umod(num);\n  };\n\n  BN.prototype.isEven = function isEven () {\n    return (this.words[0] & 1) === 0;\n  };\n\n  BN.prototype.isOdd = function isOdd () {\n    return (this.words[0] & 1) === 1;\n  };\n\n  // And first word and num\n  BN.prototype.andln = function andln (num) {\n    return this.words[0] & num;\n  };\n\n  // Increment at the bit position in-line\n  BN.prototype.bincn = function bincn (bit) {\n    assert(typeof bit === 'number');\n    var r = bit % 26;\n    var s = (bit - r) / 26;\n    var q = 1 << r;\n\n    // Fast case: bit is much higher than all existing words\n    if (this.length <= s) {\n      this._expand(s + 1);\n      this.words[s] |= q;\n      return this;\n    }\n\n    // Add bit and propagate, if needed\n    var carry = q;\n    for (var i = s; carry !== 0 && i < this.length; i++) {\n      var w = this.words[i] | 0;\n      w += carry;\n      carry = w >>> 26;\n      w &= 0x3ffffff;\n      this.words[i] = w;\n    }\n    if (carry !== 0) {\n      this.words[i] = carry;\n      this.length++;\n    }\n    return this;\n  };\n\n  BN.prototype.isZero = function isZero () {\n    return this.length === 1 && this.words[0] === 0;\n  };\n\n  BN.prototype.cmpn = function cmpn (num) {\n    var negative = num < 0;\n\n    if (this.negative !== 0 && !negative) return -1;\n    if (this.negative === 0 && negative) return 1;\n\n    this.strip();\n\n    var res;\n    if (this.length > 1) {\n      res = 1;\n    } else {\n      if (negative) {\n        num = -num;\n      }\n\n      assert(num <= 0x3ffffff, 'Number is too big');\n\n      var w = this.words[0] | 0;\n      res = w === num ? 0 : w < num ? -1 : 1;\n    }\n    if (this.negative !== 0) return -res | 0;\n    return res;\n  };\n\n  // Compare two numbers and return:\n  // 1 - if `this` > `num`\n  // 0 - if `this` == `num`\n  // -1 - if `this` < `num`\n  BN.prototype.cmp = function cmp (num) {\n    if (this.negative !== 0 && num.negative === 0) return -1;\n    if (this.negative === 0 && num.negative !== 0) return 1;\n\n    var res = this.ucmp(num);\n    if (this.negative !== 0) return -res | 0;\n    return res;\n  };\n\n  // Unsigned comparison\n  BN.prototype.ucmp = function ucmp (num) {\n    // At this point both numbers have the same sign\n    if (this.length > num.length) return 1;\n    if (this.length < num.length) return -1;\n\n    var res = 0;\n    for (var i = this.length - 1; i >= 0; i--) {\n      var a = this.words[i] | 0;\n      var b = num.words[i] | 0;\n\n      if (a === b) continue;\n      if (a < b) {\n        res = -1;\n      } else if (a > b) {\n        res = 1;\n      }\n      break;\n    }\n    return res;\n  };\n\n  BN.prototype.gtn = function gtn (num) {\n    return this.cmpn(num) === 1;\n  };\n\n  BN.prototype.gt = function gt (num) {\n    return this.cmp(num) === 1;\n  };\n\n  BN.prototype.gten = function gten (num) {\n    return this.cmpn(num) >= 0;\n  };\n\n  BN.prototype.gte = function gte (num) {\n    return this.cmp(num) >= 0;\n  };\n\n  BN.prototype.ltn = function ltn (num) {\n    return this.cmpn(num) === -1;\n  };\n\n  BN.prototype.lt = function lt (num) {\n    return this.cmp(num) === -1;\n  };\n\n  BN.prototype.lten = function lten (num) {\n    return this.cmpn(num) <= 0;\n  };\n\n  BN.prototype.lte = function lte (num) {\n    return this.cmp(num) <= 0;\n  };\n\n  BN.prototype.eqn = function eqn (num) {\n    return this.cmpn(num) === 0;\n  };\n\n  BN.prototype.eq = function eq (num) {\n    return this.cmp(num) === 0;\n  };\n\n  //\n  // A reduce context, could be using montgomery or something better, depending\n  // on the `m` itself.\n  //\n  BN.red = function red (num) {\n    return new Red(num);\n  };\n\n  BN.prototype.toRed = function toRed (ctx) {\n    assert(!this.red, 'Already a number in reduction context');\n    assert(this.negative === 0, 'red works only with positives');\n    return ctx.convertTo(this)._forceRed(ctx);\n  };\n\n  BN.prototype.fromRed = function fromRed () {\n    assert(this.red, 'fromRed works only with numbers in reduction context');\n    return this.red.convertFrom(this);\n  };\n\n  BN.prototype._forceRed = function _forceRed (ctx) {\n    this.red = ctx;\n    return this;\n  };\n\n  BN.prototype.forceRed = function forceRed (ctx) {\n    assert(!this.red, 'Already a number in reduction context');\n    return this._forceRed(ctx);\n  };\n\n  BN.prototype.redAdd = function redAdd (num) {\n    assert(this.red, 'redAdd works only with red numbers');\n    return this.red.add(this, num);\n  };\n\n  BN.prototype.redIAdd = function redIAdd (num) {\n    assert(this.red, 'redIAdd works only with red numbers');\n    return this.red.iadd(this, num);\n  };\n\n  BN.prototype.redSub = function redSub (num) {\n    assert(this.red, 'redSub works only with red numbers');\n    return this.red.sub(this, num);\n  };\n\n  BN.prototype.redISub = function redISub (num) {\n    assert(this.red, 'redISub works only with red numbers');\n    return this.red.isub(this, num);\n  };\n\n  BN.prototype.redShl = function redShl (num) {\n    assert(this.red, 'redShl works only with red numbers');\n    return this.red.shl(this, num);\n  };\n\n  BN.prototype.redMul = function redMul (num) {\n    assert(this.red, 'redMul works only with red numbers');\n    this.red._verify2(this, num);\n    return this.red.mul(this, num);\n  };\n\n  BN.prototype.redIMul = function redIMul (num) {\n    assert(this.red, 'redMul works only with red numbers');\n    this.red._verify2(this, num);\n    return this.red.imul(this, num);\n  };\n\n  BN.prototype.redSqr = function redSqr () {\n    assert(this.red, 'redSqr works only with red numbers');\n    this.red._verify1(this);\n    return this.red.sqr(this);\n  };\n\n  BN.prototype.redISqr = function redISqr () {\n    assert(this.red, 'redISqr works only with red numbers');\n    this.red._verify1(this);\n    return this.red.isqr(this);\n  };\n\n  // Square root over p\n  BN.prototype.redSqrt = function redSqrt () {\n    assert(this.red, 'redSqrt works only with red numbers');\n    this.red._verify1(this);\n    return this.red.sqrt(this);\n  };\n\n  BN.prototype.redInvm = function redInvm () {\n    assert(this.red, 'redInvm works only with red numbers');\n    this.red._verify1(this);\n    return this.red.invm(this);\n  };\n\n  // Return negative clone of `this` % `red modulo`\n  BN.prototype.redNeg = function redNeg () {\n    assert(this.red, 'redNeg works only with red numbers');\n    this.red._verify1(this);\n    return this.red.neg(this);\n  };\n\n  BN.prototype.redPow = function redPow (num) {\n    assert(this.red && !num.red, 'redPow(normalNum)');\n    this.red._verify1(this);\n    return this.red.pow(this, num);\n  };\n\n  // Prime numbers with efficient reduction\n  var primes = {\n    k256: null,\n    p224: null,\n    p192: null,\n    p25519: null\n  };\n\n  // Pseudo-Mersenne prime\n  function MPrime (name, p) {\n    // P = 2 ^ N - K\n    this.name = name;\n    this.p = new BN(p, 16);\n    this.n = this.p.bitLength();\n    this.k = new BN(1).iushln(this.n).isub(this.p);\n\n    this.tmp = this._tmp();\n  }\n\n  MPrime.prototype._tmp = function _tmp () {\n    var tmp = new BN(null);\n    tmp.words = new Array(Math.ceil(this.n / 13));\n    return tmp;\n  };\n\n  MPrime.prototype.ireduce = function ireduce (num) {\n    // Assumes that `num` is less than `P^2`\n    // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)\n    var r = num;\n    var rlen;\n\n    do {\n      this.split(r, this.tmp);\n      r = this.imulK(r);\n      r = r.iadd(this.tmp);\n      rlen = r.bitLength();\n    } while (rlen > this.n);\n\n    var cmp = rlen < this.n ? -1 : r.ucmp(this.p);\n    if (cmp === 0) {\n      r.words[0] = 0;\n      r.length = 1;\n    } else if (cmp > 0) {\n      r.isub(this.p);\n    } else {\n      r.strip();\n    }\n\n    return r;\n  };\n\n  MPrime.prototype.split = function split (input, out) {\n    input.iushrn(this.n, 0, out);\n  };\n\n  MPrime.prototype.imulK = function imulK (num) {\n    return num.imul(this.k);\n  };\n\n  function K256 () {\n    MPrime.call(\n      this,\n      'k256',\n      'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');\n  }\n  inherits(K256, MPrime);\n\n  K256.prototype.split = function split (input, output) {\n    // 256 = 9 * 26 + 22\n    var mask = 0x3fffff;\n\n    var outLen = Math.min(input.length, 9);\n    for (var i = 0; i < outLen; i++) {\n      output.words[i] = input.words[i];\n    }\n    output.length = outLen;\n\n    if (input.length <= 9) {\n      input.words[0] = 0;\n      input.length = 1;\n      return;\n    }\n\n    // Shift by 9 limbs\n    var prev = input.words[9];\n    output.words[output.length++] = prev & mask;\n\n    for (i = 10; i < input.length; i++) {\n      var next = input.words[i] | 0;\n      input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);\n      prev = next;\n    }\n    prev >>>= 22;\n    input.words[i - 10] = prev;\n    if (prev === 0 && input.length > 10) {\n      input.length -= 10;\n    } else {\n      input.length -= 9;\n    }\n  };\n\n  K256.prototype.imulK = function imulK (num) {\n    // K = 0x1000003d1 = [ 0x40, 0x3d1 ]\n    num.words[num.length] = 0;\n    num.words[num.length + 1] = 0;\n    num.length += 2;\n\n    // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390\n    var lo = 0;\n    for (var i = 0; i < num.length; i++) {\n      var w = num.words[i] | 0;\n      lo += w * 0x3d1;\n      num.words[i] = lo & 0x3ffffff;\n      lo = w * 0x40 + ((lo / 0x4000000) | 0);\n    }\n\n    // Fast length reduction\n    if (num.words[num.length - 1] === 0) {\n      num.length--;\n      if (num.words[num.length - 1] === 0) {\n        num.length--;\n      }\n    }\n    return num;\n  };\n\n  function P224 () {\n    MPrime.call(\n      this,\n      'p224',\n      'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');\n  }\n  inherits(P224, MPrime);\n\n  function P192 () {\n    MPrime.call(\n      this,\n      'p192',\n      'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');\n  }\n  inherits(P192, MPrime);\n\n  function P25519 () {\n    // 2 ^ 255 - 19\n    MPrime.call(\n      this,\n      '25519',\n      '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');\n  }\n  inherits(P25519, MPrime);\n\n  P25519.prototype.imulK = function imulK (num) {\n    // K = 0x13\n    var carry = 0;\n    for (var i = 0; i < num.length; i++) {\n      var hi = (num.words[i] | 0) * 0x13 + carry;\n      var lo = hi & 0x3ffffff;\n      hi >>>= 26;\n\n      num.words[i] = lo;\n      carry = hi;\n    }\n    if (carry !== 0) {\n      num.words[num.length++] = carry;\n    }\n    return num;\n  };\n\n  // Exported mostly for testing purposes, use plain name instead\n  BN._prime = function prime (name) {\n    // Cached version of prime\n    if (primes[name]) return primes[name];\n\n    var prime;\n    if (name === 'k256') {\n      prime = new K256();\n    } else if (name === 'p224') {\n      prime = new P224();\n    } else if (name === 'p192') {\n      prime = new P192();\n    } else if (name === 'p25519') {\n      prime = new P25519();\n    } else {\n      throw new Error('Unknown prime ' + name);\n    }\n    primes[name] = prime;\n\n    return prime;\n  };\n\n  //\n  // Base reduction engine\n  //\n  function Red (m) {\n    if (typeof m === 'string') {\n      var prime = BN._prime(m);\n      this.m = prime.p;\n      this.prime = prime;\n    } else {\n      assert(m.gtn(1), 'modulus must be greater than 1');\n      this.m = m;\n      this.prime = null;\n    }\n  }\n\n  Red.prototype._verify1 = function _verify1 (a) {\n    assert(a.negative === 0, 'red works only with positives');\n    assert(a.red, 'red works only with red numbers');\n  };\n\n  Red.prototype._verify2 = function _verify2 (a, b) {\n    assert((a.negative | b.negative) === 0, 'red works only with positives');\n    assert(a.red && a.red === b.red,\n      'red works only with red numbers');\n  };\n\n  Red.prototype.imod = function imod (a) {\n    if (this.prime) return this.prime.ireduce(a)._forceRed(this);\n    return a.umod(this.m)._forceRed(this);\n  };\n\n  Red.prototype.neg = function neg (a) {\n    if (a.isZero()) {\n      return a.clone();\n    }\n\n    return this.m.sub(a)._forceRed(this);\n  };\n\n  Red.prototype.add = function add (a, b) {\n    this._verify2(a, b);\n\n    var res = a.add(b);\n    if (res.cmp(this.m) >= 0) {\n      res.isub(this.m);\n    }\n    return res._forceRed(this);\n  };\n\n  Red.prototype.iadd = function iadd (a, b) {\n    this._verify2(a, b);\n\n    var res = a.iadd(b);\n    if (res.cmp(this.m) >= 0) {\n      res.isub(this.m);\n    }\n    return res;\n  };\n\n  Red.prototype.sub = function sub (a, b) {\n    this._verify2(a, b);\n\n    var res = a.sub(b);\n    if (res.cmpn(0) < 0) {\n      res.iadd(this.m);\n    }\n    return res._forceRed(this);\n  };\n\n  Red.prototype.isub = function isub (a, b) {\n    this._verify2(a, b);\n\n    var res = a.isub(b);\n    if (res.cmpn(0) < 0) {\n      res.iadd(this.m);\n    }\n    return res;\n  };\n\n  Red.prototype.shl = function shl (a, num) {\n    this._verify1(a);\n    return this.imod(a.ushln(num));\n  };\n\n  Red.prototype.imul = function imul (a, b) {\n    this._verify2(a, b);\n    return this.imod(a.imul(b));\n  };\n\n  Red.prototype.mul = function mul (a, b) {\n    this._verify2(a, b);\n    return this.imod(a.mul(b));\n  };\n\n  Red.prototype.isqr = function isqr (a) {\n    return this.imul(a, a.clone());\n  };\n\n  Red.prototype.sqr = function sqr (a) {\n    return this.mul(a, a);\n  };\n\n  Red.prototype.sqrt = function sqrt (a) {\n    if (a.isZero()) return a.clone();\n\n    var mod3 = this.m.andln(3);\n    assert(mod3 % 2 === 1);\n\n    // Fast case\n    if (mod3 === 3) {\n      var pow = this.m.add(new BN(1)).iushrn(2);\n      return this.pow(a, pow);\n    }\n\n    // Tonelli-Shanks algorithm (Totally unoptimized and slow)\n    //\n    // Find Q and S, that Q * 2 ^ S = (P - 1)\n    var q = this.m.subn(1);\n    var s = 0;\n    while (!q.isZero() && q.andln(1) === 0) {\n      s++;\n      q.iushrn(1);\n    }\n    assert(!q.isZero());\n\n    var one = new BN(1).toRed(this);\n    var nOne = one.redNeg();\n\n    // Find quadratic non-residue\n    // NOTE: Max is such because of generalized Riemann hypothesis.\n    var lpow = this.m.subn(1).iushrn(1);\n    var z = this.m.bitLength();\n    z = new BN(2 * z * z).toRed(this);\n\n    while (this.pow(z, lpow).cmp(nOne) !== 0) {\n      z.redIAdd(nOne);\n    }\n\n    var c = this.pow(z, q);\n    var r = this.pow(a, q.addn(1).iushrn(1));\n    var t = this.pow(a, q);\n    var m = s;\n    while (t.cmp(one) !== 0) {\n      var tmp = t;\n      for (var i = 0; tmp.cmp(one) !== 0; i++) {\n        tmp = tmp.redSqr();\n      }\n      assert(i < m);\n      var b = this.pow(c, new BN(1).iushln(m - i - 1));\n\n      r = r.redMul(b);\n      c = b.redSqr();\n      t = t.redMul(c);\n      m = i;\n    }\n\n    return r;\n  };\n\n  Red.prototype.invm = function invm (a) {\n    var inv = a._invmp(this.m);\n    if (inv.negative !== 0) {\n      inv.negative = 0;\n      return this.imod(inv).redNeg();\n    } else {\n      return this.imod(inv);\n    }\n  };\n\n  Red.prototype.pow = function pow (a, num) {\n    if (num.isZero()) return new BN(1).toRed(this);\n    if (num.cmpn(1) === 0) return a.clone();\n\n    var windowSize = 4;\n    var wnd = new Array(1 << windowSize);\n    wnd[0] = new BN(1).toRed(this);\n    wnd[1] = a;\n    for (var i = 2; i < wnd.length; i++) {\n      wnd[i] = this.mul(wnd[i - 1], a);\n    }\n\n    var res = wnd[0];\n    var current = 0;\n    var currentLen = 0;\n    var start = num.bitLength() % 26;\n    if (start === 0) {\n      start = 26;\n    }\n\n    for (i = num.length - 1; i >= 0; i--) {\n      var word = num.words[i];\n      for (var j = start - 1; j >= 0; j--) {\n        var bit = (word >> j) & 1;\n        if (res !== wnd[0]) {\n          res = this.sqr(res);\n        }\n\n        if (bit === 0 && current === 0) {\n          currentLen = 0;\n          continue;\n        }\n\n        current <<= 1;\n        current |= bit;\n        currentLen++;\n        if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;\n\n        res = this.mul(res, wnd[current]);\n        currentLen = 0;\n        current = 0;\n      }\n      start = 26;\n    }\n\n    return res;\n  };\n\n  Red.prototype.convertTo = function convertTo (num) {\n    var r = num.umod(this.m);\n\n    return r === num ? r.clone() : r;\n  };\n\n  Red.prototype.convertFrom = function convertFrom (num) {\n    var res = num.clone();\n    res.red = null;\n    return res;\n  };\n\n  //\n  // Montgomery method engine\n  //\n\n  BN.mont = function mont (num) {\n    return new Mont(num);\n  };\n\n  function Mont (m) {\n    Red.call(this, m);\n\n    this.shift = this.m.bitLength();\n    if (this.shift % 26 !== 0) {\n      this.shift += 26 - (this.shift % 26);\n    }\n\n    this.r = new BN(1).iushln(this.shift);\n    this.r2 = this.imod(this.r.sqr());\n    this.rinv = this.r._invmp(this.m);\n\n    this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);\n    this.minv = this.minv.umod(this.r);\n    this.minv = this.r.sub(this.minv);\n  }\n  inherits(Mont, Red);\n\n  Mont.prototype.convertTo = function convertTo (num) {\n    return this.imod(num.ushln(this.shift));\n  };\n\n  Mont.prototype.convertFrom = function convertFrom (num) {\n    var r = this.imod(num.mul(this.rinv));\n    r.red = null;\n    return r;\n  };\n\n  Mont.prototype.imul = function imul (a, b) {\n    if (a.isZero() || b.isZero()) {\n      a.words[0] = 0;\n      a.length = 1;\n      return a;\n    }\n\n    var t = a.imul(b);\n    var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);\n    var u = t.isub(c).iushrn(this.shift);\n    var res = u;\n\n    if (u.cmp(this.m) >= 0) {\n      res = u.isub(this.m);\n    } else if (u.cmpn(0) < 0) {\n      res = u.iadd(this.m);\n    }\n\n    return res._forceRed(this);\n  };\n\n  Mont.prototype.mul = function mul (a, b) {\n    if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);\n\n    var t = a.mul(b);\n    var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);\n    var u = t.isub(c).iushrn(this.shift);\n    var res = u;\n    if (u.cmp(this.m) >= 0) {\n      res = u.isub(this.m);\n    } else if (u.cmpn(0) < 0) {\n      res = u.iadd(this.m);\n    }\n\n    return res._forceRed(this);\n  };\n\n  Mont.prototype.invm = function invm (a) {\n    // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R\n    var res = this.imod(a._invmp(this.m).mul(this.r2));\n    return res._forceRed(this);\n  };\n})(typeof module === 'undefined' || module, this);\n\n},{\"buffer\":103}],95:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = boundary\n\nfunction boundary (cells) {\n  var i, j, k\n  var n = cells.length\n  var sz = 0\n  for (i = 0; i < n; ++i) {\n    sz += cells[i].length\n  }\n  var result = new Array(sz)\n  var ptr = 0\n  for (i = 0; i < n; ++i) {\n    var c = cells[i]\n    var d = c.length\n    for (j = 0; j < d; ++j) {\n      var b = result[ptr++] = new Array(d - 1)\n      var p = 0\n      for (k = 0; k < d; ++k) {\n        if (k === j) {\n          continue\n        }\n        b[p++] = c[k]\n      }\n      if (j & 1) {\n        var tmp = b[1]\n        b[1] = b[0]\n        b[0] = tmp\n      }\n    }\n  }\n  return result\n}\n\n},{}],96:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = boxIntersectWrapper\n\nvar pool = _dereq_('typedarray-pool')\nvar sweep = _dereq_('./lib/sweep')\nvar boxIntersectIter = _dereq_('./lib/intersect')\n\nfunction boxEmpty(d, box) {\n  for(var j=0; j<d; ++j) {\n    if(!(box[j] <= box[j+d])) {\n      return true\n    }\n  }\n  return false\n}\n\n//Unpack boxes into a flat typed array, remove empty boxes\nfunction convertBoxes(boxes, d, data, ids) {\n  var ptr = 0\n  var count = 0\n  for(var i=0, n=boxes.length; i<n; ++i) {\n    var b = boxes[i]\n    if(boxEmpty(d, b)) {\n      continue\n    }\n    for(var j=0; j<2*d; ++j) {\n      data[ptr++] = b[j]\n    }\n    ids[count++] = i\n  }\n  return count\n}\n\n//Perform type conversions, check bounds\nfunction boxIntersect(red, blue, visit, full) {\n  var n = red.length\n  var m = blue.length\n\n  //If either array is empty, then we can skip this whole thing\n  if(n <= 0 || m <= 0) {\n    return\n  }\n\n  //Compute dimension, if it is 0 then we skip\n  var d = (red[0].length)>>>1\n  if(d <= 0) {\n    return\n  }\n\n  var retval\n\n  //Convert red boxes\n  var redList  = pool.mallocDouble(2*d*n)\n  var redIds   = pool.mallocInt32(n)\n  n = convertBoxes(red, d, redList, redIds)\n\n  if(n > 0) {\n    if(d === 1 && full) {\n      //Special case: 1d complete\n      sweep.init(n)\n      retval = sweep.sweepComplete(\n        d, visit, \n        0, n, redList, redIds,\n        0, n, redList, redIds)\n    } else {\n\n      //Convert blue boxes\n      var blueList = pool.mallocDouble(2*d*m)\n      var blueIds  = pool.mallocInt32(m)\n      m = convertBoxes(blue, d, blueList, blueIds)\n\n      if(m > 0) {\n        sweep.init(n+m)\n\n        if(d === 1) {\n          //Special case: 1d bipartite\n          retval = sweep.sweepBipartite(\n            d, visit, \n            0, n, redList,  redIds,\n            0, m, blueList, blueIds)\n        } else {\n          //General case:  d>1\n          retval = boxIntersectIter(\n            d, visit,    full,\n            n, redList,  redIds,\n            m, blueList, blueIds)\n        }\n\n        pool.free(blueList)\n        pool.free(blueIds)\n      }\n    }\n\n    pool.free(redList)\n    pool.free(redIds)\n  }\n\n  return retval\n}\n\n\nvar RESULT\n\nfunction appendItem(i,j) {\n  RESULT.push([i,j])\n}\n\nfunction intersectFullArray(x) {\n  RESULT = []\n  boxIntersect(x, x, appendItem, true)\n  return RESULT\n}\n\nfunction intersectBipartiteArray(x, y) {\n  RESULT = []\n  boxIntersect(x, y, appendItem, false)\n  return RESULT\n}\n\n//User-friendly wrapper, handle full input and no-visitor cases\nfunction boxIntersectWrapper(arg0, arg1, arg2) {\n  var result\n  switch(arguments.length) {\n    case 1:\n      return intersectFullArray(arg0)\n    case 2:\n      if(typeof arg1 === 'function') {\n        return boxIntersect(arg0, arg0, arg1, true)\n      } else {\n        return intersectBipartiteArray(arg0, arg1)\n      }\n    case 3:\n      return boxIntersect(arg0, arg1, arg2, false)\n    default:\n      throw new Error('box-intersect: Invalid arguments')\n  }\n}\n},{\"./lib/intersect\":98,\"./lib/sweep\":102,\"typedarray-pool\":545}],97:[function(_dereq_,module,exports){\n'use strict'\n\nvar DIMENSION   = 'd'\nvar AXIS        = 'ax'\nvar VISIT       = 'vv'\nvar FLIP        = 'fp'\n\nvar ELEM_SIZE   = 'es'\n\nvar RED_START   = 'rs'\nvar RED_END     = 're'\nvar RED_BOXES   = 'rb'\nvar RED_INDEX   = 'ri'\nvar RED_PTR     = 'rp'\n\nvar BLUE_START  = 'bs'\nvar BLUE_END    = 'be'\nvar BLUE_BOXES  = 'bb'\nvar BLUE_INDEX  = 'bi'\nvar BLUE_PTR    = 'bp'\n\nvar RETVAL      = 'rv'\n\nvar INNER_LABEL = 'Q'\n\nvar ARGS = [\n  DIMENSION,\n  AXIS,\n  VISIT,\n  RED_START,\n  RED_END,\n  RED_BOXES,\n  RED_INDEX,\n  BLUE_START,\n  BLUE_END,\n  BLUE_BOXES,\n  BLUE_INDEX\n]\n\nfunction generateBruteForce(redMajor, flip, full) {\n  var funcName = 'bruteForce' + \n    (redMajor ? 'Red' : 'Blue') + \n    (flip ? 'Flip' : '') +\n    (full ? 'Full' : '')\n\n  var code = ['function ', funcName, '(', ARGS.join(), '){',\n    'var ', ELEM_SIZE, '=2*', DIMENSION, ';']\n\n  var redLoop = \n    'for(var i=' + RED_START + ',' + RED_PTR + '=' + ELEM_SIZE + '*' + RED_START + ';' +\n        'i<' + RED_END +';' +\n        '++i,' + RED_PTR + '+=' + ELEM_SIZE + '){' +\n        'var x0=' + RED_BOXES + '[' + AXIS + '+' + RED_PTR + '],' +\n            'x1=' + RED_BOXES + '[' + AXIS + '+' + RED_PTR + '+' + DIMENSION + '],' +\n            'xi=' + RED_INDEX + '[i];'\n\n  var blueLoop = \n    'for(var j=' + BLUE_START + ',' + BLUE_PTR + '=' + ELEM_SIZE + '*' + BLUE_START + ';' +\n        'j<' + BLUE_END + ';' +\n        '++j,' + BLUE_PTR + '+=' + ELEM_SIZE + '){' +\n        'var y0=' + BLUE_BOXES + '[' + AXIS + '+' + BLUE_PTR + '],' +\n            (full ? 'y1=' + BLUE_BOXES + '[' + AXIS + '+' + BLUE_PTR + '+' + DIMENSION + '],' : '') +\n            'yi=' + BLUE_INDEX + '[j];'\n\n  if(redMajor) {\n    code.push(redLoop, INNER_LABEL, ':', blueLoop)\n  } else {\n    code.push(blueLoop, INNER_LABEL, ':', redLoop)\n  }\n\n  if(full) {\n    code.push('if(y1<x0||x1<y0)continue;')\n  } else if(flip) {\n    code.push('if(y0<=x0||x1<y0)continue;')\n  } else {\n    code.push('if(y0<x0||x1<y0)continue;')\n  }\n\n  code.push('for(var k='+AXIS+'+1;k<'+DIMENSION+';++k){'+\n    'var r0='+RED_BOXES+'[k+'+RED_PTR+'],'+\n        'r1='+RED_BOXES+'[k+'+DIMENSION+'+'+RED_PTR+'],'+\n        'b0='+BLUE_BOXES+'[k+'+BLUE_PTR+'],'+\n        'b1='+BLUE_BOXES+'[k+'+DIMENSION+'+'+BLUE_PTR+'];'+\n      'if(r1<b0||b1<r0)continue ' + INNER_LABEL + ';}' +\n      'var ' + RETVAL + '=' + VISIT + '(')\n\n  if(flip) {\n    code.push('yi,xi')\n  } else {\n    code.push('xi,yi')\n  }\n\n  code.push(');if(' + RETVAL + '!==void 0)return ' + RETVAL + ';}}}')\n\n  return {\n    name: funcName, \n    code: code.join('')\n  }\n}\n\nfunction bruteForcePlanner(full) {\n  var funcName = 'bruteForce' + (full ? 'Full' : 'Partial')\n  var prefix = []\n  var fargs = ARGS.slice()\n  if(!full) {\n    fargs.splice(3, 0, FLIP)\n  }\n\n  var code = ['function ' + funcName + '(' + fargs.join() + '){']\n\n  function invoke(redMajor, flip) {\n    var res = generateBruteForce(redMajor, flip, full)\n    prefix.push(res.code)\n    code.push('return ' + res.name + '(' + ARGS.join() + ');')\n  }\n\n  code.push('if(' + RED_END + '-' + RED_START + '>' +\n                    BLUE_END + '-' + BLUE_START + '){')\n\n  if(full) {\n    invoke(true, false)\n    code.push('}else{')\n    invoke(false, false)\n  } else {\n    code.push('if(' + FLIP + '){')\n    invoke(true, true)\n    code.push('}else{')\n    invoke(true, false)\n    code.push('}}else{if(' + FLIP + '){')\n    invoke(false, true)\n    code.push('}else{')\n    invoke(false, false)\n    code.push('}')\n  }\n  code.push('}}return ' + funcName)\n\n  var codeStr = prefix.join('') + code.join('')\n  var proc = new Function(codeStr)\n  return proc()\n}\n\n\nexports.partial = bruteForcePlanner(false)\nexports.full    = bruteForcePlanner(true)\n},{}],98:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = boxIntersectIter\n\nvar pool = _dereq_('typedarray-pool')\nvar bits = _dereq_('bit-twiddle')\nvar bruteForce = _dereq_('./brute')\nvar bruteForcePartial = bruteForce.partial\nvar bruteForceFull = bruteForce.full\nvar sweep = _dereq_('./sweep')\nvar findMedian = _dereq_('./median')\nvar genPartition = _dereq_('./partition')\n\n//Twiddle parameters\nvar BRUTE_FORCE_CUTOFF    = 128       //Cut off for brute force search\nvar SCAN_CUTOFF           = (1<<22)   //Cut off for two way scan\nvar SCAN_COMPLETE_CUTOFF  = (1<<22)  \n\n//Partition functions\nvar partitionInteriorContainsInterval = genPartition(\n  '!(lo>=p0)&&!(p1>=hi)', \n  ['p0', 'p1'])\n\nvar partitionStartEqual = genPartition(\n  'lo===p0',\n  ['p0'])\n\nvar partitionStartLessThan = genPartition(\n  'lo<p0',\n  ['p0'])\n\nvar partitionEndLessThanEqual = genPartition(\n  'hi<=p0',\n  ['p0'])\n\nvar partitionContainsPoint = genPartition(\n  'lo<=p0&&p0<=hi',\n  ['p0'])\n\nvar partitionContainsPointProper = genPartition(\n  'lo<p0&&p0<=hi',\n  ['p0'])\n\n//Frame size for iterative loop\nvar IFRAME_SIZE = 6\nvar DFRAME_SIZE = 2\n\n//Data for box statck\nvar INIT_CAPACITY = 1024\nvar BOX_ISTACK  = pool.mallocInt32(INIT_CAPACITY)\nvar BOX_DSTACK  = pool.mallocDouble(INIT_CAPACITY)\n\n//Initialize iterative loop queue\nfunction iterInit(d, count) {\n  var levels = (8 * bits.log2(count+1) * (d+1))|0\n  var maxInts = bits.nextPow2(IFRAME_SIZE*levels)\n  if(BOX_ISTACK.length < maxInts) {\n    pool.free(BOX_ISTACK)\n    BOX_ISTACK = pool.mallocInt32(maxInts)\n  }\n  var maxDoubles = bits.nextPow2(DFRAME_SIZE*levels)\n  if(BOX_DSTACK < maxDoubles) {\n    pool.free(BOX_DSTACK)\n    BOX_DSTACK = pool.mallocDouble(maxDoubles)\n  }\n}\n\n//Append item to queue\nfunction iterPush(ptr,\n  axis, \n  redStart, redEnd, \n  blueStart, blueEnd, \n  state, \n  lo, hi) {\n\n  var iptr = IFRAME_SIZE * ptr\n  BOX_ISTACK[iptr]   = axis\n  BOX_ISTACK[iptr+1] = redStart\n  BOX_ISTACK[iptr+2] = redEnd\n  BOX_ISTACK[iptr+3] = blueStart\n  BOX_ISTACK[iptr+4] = blueEnd\n  BOX_ISTACK[iptr+5] = state\n\n  var dptr = DFRAME_SIZE * ptr\n  BOX_DSTACK[dptr]   = lo\n  BOX_DSTACK[dptr+1] = hi\n}\n\n//Special case:  Intersect single point with list of intervals\nfunction onePointPartial(\n  d, axis, visit, flip,\n  redStart, redEnd, red, redIndex,\n  blueOffset, blue, blueId) {\n\n  var elemSize = 2 * d\n  var bluePtr  = blueOffset * elemSize\n  var blueX    = blue[bluePtr + axis]\n\nred_loop:\n  for(var i=redStart, redPtr=redStart*elemSize; i<redEnd; ++i, redPtr+=elemSize) {\n    var r0 = red[redPtr+axis]\n    var r1 = red[redPtr+axis+d]\n    if(blueX < r0 || r1 < blueX) {\n      continue\n    }\n    if(flip && blueX === r0) {\n      continue\n    }\n    var redId = redIndex[i]\n    for(var j=axis+1; j<d; ++j) {\n      var r0 = red[redPtr+j]\n      var r1 = red[redPtr+j+d]\n      var b0 = blue[bluePtr+j]\n      var b1 = blue[bluePtr+j+d]\n      if(r1 < b0 || b1 < r0) {\n        continue red_loop\n      }\n    }\n    var retval\n    if(flip) {\n      retval = visit(blueId, redId)\n    } else {\n      retval = visit(redId, blueId)\n    }\n    if(retval !== void 0) {\n      return retval\n    }\n  }\n}\n\n//Special case:  Intersect one point with list of intervals\nfunction onePointFull(\n  d, axis, visit,\n  redStart, redEnd, red, redIndex,\n  blueOffset, blue, blueId) {\n\n  var elemSize = 2 * d\n  var bluePtr  = blueOffset * elemSize\n  var blueX    = blue[bluePtr + axis]\n\nred_loop:\n  for(var i=redStart, redPtr=redStart*elemSize; i<redEnd; ++i, redPtr+=elemSize) {\n    var redId = redIndex[i]\n    if(redId === blueId) {\n      continue\n    }\n    var r0 = red[redPtr+axis]\n    var r1 = red[redPtr+axis+d]\n    if(blueX < r0 || r1 < blueX) {\n      continue\n    }\n    for(var j=axis+1; j<d; ++j) {\n      var r0 = red[redPtr+j]\n      var r1 = red[redPtr+j+d]\n      var b0 = blue[bluePtr+j]\n      var b1 = blue[bluePtr+j+d]\n      if(r1 < b0 || b1 < r0) {\n        continue red_loop\n      }\n    }\n    var retval = visit(redId, blueId)\n    if(retval !== void 0) {\n      return retval\n    }\n  }\n}\n\n//The main box intersection routine\nfunction boxIntersectIter(\n  d, visit, initFull,\n  xSize, xBoxes, xIndex,\n  ySize, yBoxes, yIndex) {\n\n  //Reserve memory for stack\n  iterInit(d, xSize + ySize)\n\n  var top  = 0\n  var elemSize = 2 * d\n  var retval\n\n  iterPush(top++,\n      0,\n      0, xSize,\n      0, ySize,\n      initFull ? 16 : 0, \n      -Infinity, Infinity)\n  if(!initFull) {\n    iterPush(top++,\n      0,\n      0, ySize,\n      0, xSize,\n      1, \n      -Infinity, Infinity)\n  }\n\n  while(top > 0) {\n    top  -= 1\n\n    var iptr = top * IFRAME_SIZE\n    var axis      = BOX_ISTACK[iptr]\n    var redStart  = BOX_ISTACK[iptr+1]\n    var redEnd    = BOX_ISTACK[iptr+2]\n    var blueStart = BOX_ISTACK[iptr+3]\n    var blueEnd   = BOX_ISTACK[iptr+4]\n    var state     = BOX_ISTACK[iptr+5]\n\n    var dptr = top * DFRAME_SIZE\n    var lo        = BOX_DSTACK[dptr]\n    var hi        = BOX_DSTACK[dptr+1]\n\n    //Unpack state info\n    var flip      = (state & 1)\n    var full      = !!(state & 16)\n\n    //Unpack indices\n    var red       = xBoxes\n    var redIndex  = xIndex\n    var blue      = yBoxes\n    var blueIndex = yIndex\n    if(flip) {\n      red         = yBoxes\n      redIndex    = yIndex\n      blue        = xBoxes\n      blueIndex   = xIndex\n    }\n\n    if(state & 2) {\n      redEnd = partitionStartLessThan(\n        d, axis,\n        redStart, redEnd, red, redIndex,\n        hi)\n      if(redStart >= redEnd) {\n        continue\n      }\n    }\n    if(state & 4) {\n      redStart = partitionEndLessThanEqual(\n        d, axis,\n        redStart, redEnd, red, redIndex,\n        lo)\n      if(redStart >= redEnd) {\n        continue\n      }\n    }\n    \n    var redCount  = redEnd  - redStart\n    var blueCount = blueEnd - blueStart\n\n    if(full) {\n      if(d * redCount * (redCount + blueCount) < SCAN_COMPLETE_CUTOFF) {\n        retval = sweep.scanComplete(\n          d, axis, visit, \n          redStart, redEnd, red, redIndex,\n          blueStart, blueEnd, blue, blueIndex)\n        if(retval !== void 0) {\n          return retval\n        }\n        continue\n      }\n    } else {\n      if(d * Math.min(redCount, blueCount) < BRUTE_FORCE_CUTOFF) {\n        //If input small, then use brute force\n        retval = bruteForcePartial(\n            d, axis, visit, flip,\n            redStart,  redEnd,  red,  redIndex,\n            blueStart, blueEnd, blue, blueIndex)\n        if(retval !== void 0) {\n          return retval\n        }\n        continue\n      } else if(d * redCount * blueCount < SCAN_CUTOFF) {\n        //If input medium sized, then use sweep and prune\n        retval = sweep.scanBipartite(\n          d, axis, visit, flip, \n          redStart, redEnd, red, redIndex,\n          blueStart, blueEnd, blue, blueIndex)\n        if(retval !== void 0) {\n          return retval\n        }\n        continue\n      }\n    }\n    \n    //First, find all red intervals whose interior contains (lo,hi)\n    var red0 = partitionInteriorContainsInterval(\n      d, axis, \n      redStart, redEnd, red, redIndex,\n      lo, hi)\n\n    //Lower dimensional case\n    if(redStart < red0) {\n\n      if(d * (red0 - redStart) < BRUTE_FORCE_CUTOFF) {\n        //Special case for small inputs: use brute force\n        retval = bruteForceFull(\n          d, axis+1, visit,\n          redStart, red0, red, redIndex,\n          blueStart, blueEnd, blue, blueIndex)\n        if(retval !== void 0) {\n          return retval\n        }\n      } else if(axis === d-2) {\n        if(flip) {\n          retval = sweep.sweepBipartite(\n            d, visit,\n            blueStart, blueEnd, blue, blueIndex,\n            redStart, red0, red, redIndex)\n        } else {\n          retval = sweep.sweepBipartite(\n            d, visit,\n            redStart, red0, red, redIndex,\n            blueStart, blueEnd, blue, blueIndex)\n        }\n        if(retval !== void 0) {\n          return retval\n        }\n      } else {\n        iterPush(top++,\n          axis+1,\n          redStart, red0,\n          blueStart, blueEnd,\n          flip,\n          -Infinity, Infinity)\n        iterPush(top++,\n          axis+1,\n          blueStart, blueEnd,\n          redStart, red0,\n          flip^1,\n          -Infinity, Infinity)\n      }\n    }\n\n    //Divide and conquer phase\n    if(red0 < redEnd) {\n\n      //Cut blue into 3 parts:\n      //\n      //  Points < mid point\n      //  Points = mid point\n      //  Points > mid point\n      //\n      var blue0 = findMedian(\n        d, axis, \n        blueStart, blueEnd, blue, blueIndex)\n      var mid = blue[elemSize * blue0 + axis]\n      var blue1 = partitionStartEqual(\n        d, axis,\n        blue0, blueEnd, blue, blueIndex,\n        mid)\n\n      //Right case\n      if(blue1 < blueEnd) {\n        iterPush(top++,\n          axis,\n          red0, redEnd,\n          blue1, blueEnd,\n          (flip|4) + (full ? 16 : 0),\n          mid, hi)\n      }\n\n      //Left case\n      if(blueStart < blue0) {\n        iterPush(top++,\n          axis,\n          red0, redEnd,\n          blueStart, blue0,\n          (flip|2) + (full ? 16 : 0),\n          lo, mid)\n      }\n\n      //Center case (the hard part)\n      if(blue0 + 1 === blue1) {\n        //Optimization: Range with exactly 1 point, use a brute force scan\n        if(full) {\n          retval = onePointFull(\n            d, axis, visit,\n            red0, redEnd, red, redIndex,\n            blue0, blue, blueIndex[blue0])\n        } else {\n          retval = onePointPartial(\n            d, axis, visit, flip,\n            red0, redEnd, red, redIndex,\n            blue0, blue, blueIndex[blue0])\n        }\n        if(retval !== void 0) {\n          return retval\n        }\n      } else if(blue0 < blue1) {\n        var red1\n        if(full) {\n          //If full intersection, need to handle special case\n          red1 = partitionContainsPoint(\n            d, axis,\n            red0, redEnd, red, redIndex,\n            mid)\n          if(red0 < red1) {\n            var redX = partitionStartEqual(\n              d, axis,\n              red0, red1, red, redIndex,\n              mid)\n            if(axis === d-2) {\n              //Degenerate sweep intersection:\n              //  [red0, redX] with [blue0, blue1]\n              if(red0 < redX) {\n                retval = sweep.sweepComplete(\n                  d, visit,\n                  red0, redX, red, redIndex,\n                  blue0, blue1, blue, blueIndex)\n                if(retval !== void 0) {\n                  return retval\n                }\n              }\n\n              //Normal sweep intersection:\n              //  [redX, red1] with [blue0, blue1]\n              if(redX < red1) {\n                retval = sweep.sweepBipartite(\n                  d, visit,\n                  redX, red1, red, redIndex,\n                  blue0, blue1, blue, blueIndex)\n                if(retval !== void 0) {\n                  return retval\n                }\n              }\n            } else {\n              if(red0 < redX) {\n                iterPush(top++,\n                  axis+1,\n                  red0, redX,\n                  blue0, blue1,\n                  16,\n                  -Infinity, Infinity)\n              }\n              if(redX < red1) {\n                iterPush(top++,\n                  axis+1,\n                  redX, red1,\n                  blue0, blue1,\n                  0,\n                  -Infinity, Infinity)\n                iterPush(top++,\n                  axis+1,\n                  blue0, blue1,\n                  redX, red1,\n                  1,\n                  -Infinity, Infinity)\n              }\n            }\n          }\n        } else {\n          if(flip) {\n            red1 = partitionContainsPointProper(\n              d, axis,\n              red0, redEnd, red, redIndex,\n              mid)\n          } else {\n            red1 = partitionContainsPoint(\n              d, axis,\n              red0, redEnd, red, redIndex,\n              mid)\n          }\n          if(red0 < red1) {\n            if(axis === d-2) {\n              if(flip) {\n                retval = sweep.sweepBipartite(\n                  d, visit,\n                  blue0, blue1, blue, blueIndex,\n                  red0, red1, red, redIndex)\n              } else {\n                retval = sweep.sweepBipartite(\n                  d, visit,\n                  red0, red1, red, redIndex,\n                  blue0, blue1, blue, blueIndex)\n              }\n            } else {\n              iterPush(top++,\n                axis+1,\n                red0, red1,\n                blue0, blue1,\n                flip,\n                -Infinity, Infinity)\n              iterPush(top++,\n                axis+1,\n                blue0, blue1,\n                red0, red1,\n                flip^1,\n                -Infinity, Infinity)\n            }\n          }\n        }\n      }\n    }\n  }\n}\n},{\"./brute\":97,\"./median\":99,\"./partition\":100,\"./sweep\":102,\"bit-twiddle\":92,\"typedarray-pool\":545}],99:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = findMedian\n\nvar genPartition = _dereq_('./partition')\n\nvar partitionStartLessThan = genPartition('lo<p0', ['p0'])\n\nvar PARTITION_THRESHOLD = 8   //Cut off for using insertion sort in findMedian\n\n//Base case for median finding:  Use insertion sort\nfunction insertionSort(d, axis, start, end, boxes, ids) {\n  var elemSize = 2 * d\n  var boxPtr = elemSize * (start+1) + axis\n  for(var i=start+1; i<end; ++i, boxPtr+=elemSize) {\n    var x = boxes[boxPtr]\n    for(var j=i, ptr=elemSize*(i-1); \n        j>start && boxes[ptr+axis] > x; \n        --j, ptr-=elemSize) {\n      //Swap\n      var aPtr = ptr\n      var bPtr = ptr+elemSize\n      for(var k=0; k<elemSize; ++k, ++aPtr, ++bPtr) {\n        var y = boxes[aPtr]\n        boxes[aPtr] = boxes[bPtr]\n        boxes[bPtr] = y\n      }\n      var tmp = ids[j]\n      ids[j] = ids[j-1]\n      ids[j-1] = tmp\n    }\n  }\n}\n\n//Find median using quick select algorithm\n//  takes O(n) time with high probability\nfunction findMedian(d, axis, start, end, boxes, ids) {\n  if(end <= start+1) {\n    return start\n  }\n\n  var lo       = start\n  var hi       = end\n  var mid      = ((end + start) >>> 1)\n  var elemSize = 2*d\n  var pivot    = mid\n  var value    = boxes[elemSize*mid+axis]\n  \n  while(lo < hi) {\n    if(hi - lo < PARTITION_THRESHOLD) {\n      insertionSort(d, axis, lo, hi, boxes, ids)\n      value = boxes[elemSize*mid+axis]\n      break\n    }\n    \n    //Select pivot using median-of-3\n    var count  = hi - lo\n    var pivot0 = (Math.random()*count+lo)|0\n    var value0 = boxes[elemSize*pivot0 + axis]\n    var pivot1 = (Math.random()*count+lo)|0\n    var value1 = boxes[elemSize*pivot1 + axis]\n    var pivot2 = (Math.random()*count+lo)|0\n    var value2 = boxes[elemSize*pivot2 + axis]\n    if(value0 <= value1) {\n      if(value2 >= value1) {\n        pivot = pivot1\n        value = value1\n      } else if(value0 >= value2) {\n        pivot = pivot0\n        value = value0\n      } else {\n        pivot = pivot2\n        value = value2\n      }\n    } else {\n      if(value1 >= value2) {\n        pivot = pivot1\n        value = value1\n      } else if(value2 >= value0) {\n        pivot = pivot0\n        value = value0\n      } else {\n        pivot = pivot2\n        value = value2\n      }\n    }\n\n    //Swap pivot to end of array\n    var aPtr = elemSize * (hi-1)\n    var bPtr = elemSize * pivot\n    for(var i=0; i<elemSize; ++i, ++aPtr, ++bPtr) {\n      var x = boxes[aPtr]\n      boxes[aPtr] = boxes[bPtr]\n      boxes[bPtr] = x\n    }\n    var y = ids[hi-1]\n    ids[hi-1] = ids[pivot]\n    ids[pivot] = y\n\n    //Partition using pivot\n    pivot = partitionStartLessThan(\n      d, axis, \n      lo, hi-1, boxes, ids,\n      value)\n\n    //Swap pivot back\n    var aPtr = elemSize * (hi-1)\n    var bPtr = elemSize * pivot\n    for(var i=0; i<elemSize; ++i, ++aPtr, ++bPtr) {\n      var x = boxes[aPtr]\n      boxes[aPtr] = boxes[bPtr]\n      boxes[bPtr] = x\n    }\n    var y = ids[hi-1]\n    ids[hi-1] = ids[pivot]\n    ids[pivot] = y\n\n    //Swap pivot to last pivot\n    if(mid < pivot) {\n      hi = pivot-1\n      while(lo < hi && \n        boxes[elemSize*(hi-1)+axis] === value) {\n        hi -= 1\n      }\n      hi += 1\n    } else if(pivot < mid) {\n      lo = pivot + 1\n      while(lo < hi &&\n        boxes[elemSize*lo+axis] === value) {\n        lo += 1\n      }\n    } else {\n      break\n    }\n  }\n\n  //Make sure pivot is at start\n  return partitionStartLessThan(\n    d, axis, \n    start, mid, boxes, ids,\n    boxes[elemSize*mid+axis])\n}\n},{\"./partition\":100}],100:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = genPartition\n\nvar code = 'for(var j=2*a,k=j*c,l=k,m=c,n=b,o=a+b,p=c;d>p;++p,k+=j){var _;if($)if(m===p)m+=1,l+=j;else{for(var s=0;j>s;++s){var t=e[k+s];e[k+s]=e[l],e[l++]=t}var u=f[p];f[p]=f[m],f[m++]=u}}return m'\n\nfunction genPartition(predicate, args) {\n  var fargs ='abcdef'.split('').concat(args)\n  var reads = []\n  if(predicate.indexOf('lo') >= 0) {\n    reads.push('lo=e[k+n]')\n  }\n  if(predicate.indexOf('hi') >= 0) {\n    reads.push('hi=e[k+o]')\n  }\n  fargs.push(\n    code.replace('_', reads.join())\n        .replace('$', predicate))\n  return Function.apply(void 0, fargs)\n}\n},{}],101:[function(_dereq_,module,exports){\n'use strict';\n\n//This code is extracted from ndarray-sort\n//It is inlined here as a temporary workaround\n\nmodule.exports = wrapper;\n\nvar INSERT_SORT_CUTOFF = 32\n\nfunction wrapper(data, n0) {\n  if (n0 <= 4*INSERT_SORT_CUTOFF) {\n    insertionSort(0, n0 - 1, data);\n  } else {\n    quickSort(0, n0 - 1, data);\n  }\n}\n\nfunction insertionSort(left, right, data) {\n  var ptr = 2*(left+1)\n  for(var i=left+1; i<=right; ++i) {\n    var a = data[ptr++]\n    var b = data[ptr++]\n    var j = i\n    var jptr = ptr-2\n    while(j-- > left) {\n      var x = data[jptr-2]\n      var y = data[jptr-1]\n      if(x < a) {\n        break\n      } else if(x === a && y < b) {\n        break\n      }\n      data[jptr]   = x\n      data[jptr+1] = y\n      jptr -= 2\n    }\n    data[jptr]   = a\n    data[jptr+1] = b\n  }\n}\n\nfunction swap(i, j, data) {\n  i *= 2\n  j *= 2\n  var x = data[i]\n  var y = data[i+1]\n  data[i] = data[j]\n  data[i+1] = data[j+1]\n  data[j] = x\n  data[j+1] = y\n}\n\nfunction move(i, j, data) {\n  i *= 2\n  j *= 2\n  data[i] = data[j]\n  data[i+1] = data[j+1]\n}\n\nfunction rotate(i, j, k, data) {\n  i *= 2\n  j *= 2\n  k *= 2\n  var x = data[i]\n  var y = data[i+1]\n  data[i] = data[j]\n  data[i+1] = data[j+1]\n  data[j] = data[k]\n  data[j+1] = data[k+1]\n  data[k] = x\n  data[k+1] = y\n}\n\nfunction shufflePivot(i, j, px, py, data) {\n  i *= 2\n  j *= 2\n  data[i] = data[j]\n  data[j] = px\n  data[i+1] = data[j+1]\n  data[j+1] = py\n}\n\nfunction compare(i, j, data) {\n  i *= 2\n  j *= 2\n  var x = data[i],\n      y = data[j]\n  if(x < y) {\n    return false\n  } else if(x === y) {\n    return data[i+1] > data[j+1]\n  }\n  return true\n}\n\nfunction comparePivot(i, y, b, data) {\n  i *= 2\n  var x = data[i]\n  if(x < y) {\n    return true\n  } else if(x === y) {\n    return data[i+1] < b\n  }\n  return false\n}\n\nfunction quickSort(left, right, data) {\n  var sixth = (right - left + 1) / 6 | 0, \n      index1 = left + sixth, \n      index5 = right - sixth, \n      index3 = left + right >> 1, \n      index2 = index3 - sixth, \n      index4 = index3 + sixth, \n      el1 = index1, \n      el2 = index2, \n      el3 = index3, \n      el4 = index4, \n      el5 = index5, \n      less = left + 1, \n      great = right - 1, \n      tmp = 0\n  if(compare(el1, el2, data)) {\n    tmp = el1\n    el1 = el2\n    el2 = tmp\n  }\n  if(compare(el4, el5, data)) {\n    tmp = el4\n    el4 = el5\n    el5 = tmp\n  }\n  if(compare(el1, el3, data)) {\n    tmp = el1\n    el1 = el3\n    el3 = tmp\n  }\n  if(compare(el2, el3, data)) {\n    tmp = el2\n    el2 = el3\n    el3 = tmp\n  }\n  if(compare(el1, el4, data)) {\n    tmp = el1\n    el1 = el4\n    el4 = tmp\n  }\n  if(compare(el3, el4, data)) {\n    tmp = el3\n    el3 = el4\n    el4 = tmp\n  }\n  if(compare(el2, el5, data)) {\n    tmp = el2\n    el2 = el5\n    el5 = tmp\n  }\n  if(compare(el2, el3, data)) {\n    tmp = el2\n    el2 = el3\n    el3 = tmp\n  }\n  if(compare(el4, el5, data)) {\n    tmp = el4\n    el4 = el5\n    el5 = tmp\n  }\n\n  var pivot1X = data[2*el2]\n  var pivot1Y = data[2*el2+1]\n  var pivot2X = data[2*el4]\n  var pivot2Y = data[2*el4+1]\n\n  var ptr0 = 2 * el1;\n  var ptr2 = 2 * el3;\n  var ptr4 = 2 * el5;\n  var ptr5 = 2 * index1;\n  var ptr6 = 2 * index3;\n  var ptr7 = 2 * index5;\n  for (var i1 = 0; i1 < 2; ++i1) {\n    var x = data[ptr0+i1];\n    var y = data[ptr2+i1];\n    var z = data[ptr4+i1];\n    data[ptr5+i1] = x;\n    data[ptr6+i1] = y;\n    data[ptr7+i1] = z;\n  }\n\n  move(index2, left, data)\n  move(index4, right, data)\n  for (var k = less; k <= great; ++k) {\n    if (comparePivot(k, pivot1X, pivot1Y, data)) {\n      if (k !== less) {\n        swap(k, less, data)\n      }\n      ++less;\n    } else {\n      if (!comparePivot(k, pivot2X, pivot2Y, data)) {\n        while (true) {\n          if (!comparePivot(great, pivot2X, pivot2Y, data)) {\n            if (--great < k) {\n              break;\n            }\n            continue;\n          } else {\n            if (comparePivot(great, pivot1X, pivot1Y, data)) {\n              rotate(k, less, great, data)\n              ++less;\n              --great;\n            } else {\n              swap(k, great, data)\n              --great;\n            }\n            break;\n          }\n        }\n      }\n    }\n  }\n  shufflePivot(left, less-1, pivot1X, pivot1Y, data)\n  shufflePivot(right, great+1, pivot2X, pivot2Y, data)\n  if (less - 2 - left <= INSERT_SORT_CUTOFF) {\n    insertionSort(left, less - 2, data);\n  } else {\n    quickSort(left, less - 2, data);\n  }\n  if (right - (great + 2) <= INSERT_SORT_CUTOFF) {\n    insertionSort(great + 2, right, data);\n  } else {\n    quickSort(great + 2, right, data);\n  }\n  if (great - less <= INSERT_SORT_CUTOFF) {\n    insertionSort(less, great, data);\n  } else {\n    quickSort(less, great, data);\n  }\n}\n},{}],102:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = {\n  init:           sqInit,\n  sweepBipartite: sweepBipartite,\n  sweepComplete:  sweepComplete,\n  scanBipartite:  scanBipartite,\n  scanComplete:   scanComplete\n}\n\nvar pool  = _dereq_('typedarray-pool')\nvar bits  = _dereq_('bit-twiddle')\nvar isort = _dereq_('./sort')\n\n//Flag for blue\nvar BLUE_FLAG = (1<<28)\n\n//1D sweep event queue stuff (use pool to save space)\nvar INIT_CAPACITY      = 1024\nvar RED_SWEEP_QUEUE    = pool.mallocInt32(INIT_CAPACITY)\nvar RED_SWEEP_INDEX    = pool.mallocInt32(INIT_CAPACITY)\nvar BLUE_SWEEP_QUEUE   = pool.mallocInt32(INIT_CAPACITY)\nvar BLUE_SWEEP_INDEX   = pool.mallocInt32(INIT_CAPACITY)\nvar COMMON_SWEEP_QUEUE = pool.mallocInt32(INIT_CAPACITY)\nvar COMMON_SWEEP_INDEX = pool.mallocInt32(INIT_CAPACITY)\nvar SWEEP_EVENTS       = pool.mallocDouble(INIT_CAPACITY * 8)\n\n//Reserves memory for the 1D sweep data structures\nfunction sqInit(count) {\n  var rcount = bits.nextPow2(count)\n  if(RED_SWEEP_QUEUE.length < rcount) {\n    pool.free(RED_SWEEP_QUEUE)\n    RED_SWEEP_QUEUE = pool.mallocInt32(rcount)\n  }\n  if(RED_SWEEP_INDEX.length < rcount) {\n    pool.free(RED_SWEEP_INDEX)\n    RED_SWEEP_INDEX = pool.mallocInt32(rcount)\n  }\n  if(BLUE_SWEEP_QUEUE.length < rcount) {\n    pool.free(BLUE_SWEEP_QUEUE)\n    BLUE_SWEEP_QUEUE = pool.mallocInt32(rcount)\n  }\n  if(BLUE_SWEEP_INDEX.length < rcount) {\n    pool.free(BLUE_SWEEP_INDEX)\n    BLUE_SWEEP_INDEX = pool.mallocInt32(rcount)\n  }\n  if(COMMON_SWEEP_QUEUE.length < rcount) {\n    pool.free(COMMON_SWEEP_QUEUE)\n    COMMON_SWEEP_QUEUE = pool.mallocInt32(rcount)\n  }\n  if(COMMON_SWEEP_INDEX.length < rcount) {\n    pool.free(COMMON_SWEEP_INDEX)\n    COMMON_SWEEP_INDEX = pool.mallocInt32(rcount)\n  }\n  var eventLength = 8 * rcount\n  if(SWEEP_EVENTS.length < eventLength) {\n    pool.free(SWEEP_EVENTS)\n    SWEEP_EVENTS = pool.mallocDouble(eventLength)\n  }\n}\n\n//Remove an item from the active queue in O(1)\nfunction sqPop(queue, index, count, item) {\n  var idx = index[item]\n  var top = queue[count-1]\n  queue[idx] = top\n  index[top] = idx\n}\n\n//Insert an item into the active queue in O(1)\nfunction sqPush(queue, index, count, item) {\n  queue[count] = item\n  index[item]  = count\n}\n\n//Recursion base case: use 1D sweep algorithm\nfunction sweepBipartite(\n    d, visit,\n    redStart,  redEnd, red, redIndex,\n    blueStart, blueEnd, blue, blueIndex) {\n\n  //store events as pairs [coordinate, idx]\n  //\n  //  red create:  -(idx+1)\n  //  red destroy: idx\n  //  blue create: -(idx+BLUE_FLAG)\n  //  blue destroy: idx+BLUE_FLAG\n  //\n  var ptr      = 0\n  var elemSize = 2*d\n  var istart   = d-1\n  var iend     = elemSize-1\n\n  for(var i=redStart; i<redEnd; ++i) {\n    var idx = redIndex[i]\n    var redOffset = elemSize*i\n    SWEEP_EVENTS[ptr++] = red[redOffset+istart]\n    SWEEP_EVENTS[ptr++] = -(idx+1)\n    SWEEP_EVENTS[ptr++] = red[redOffset+iend]\n    SWEEP_EVENTS[ptr++] = idx\n  }\n\n  for(var i=blueStart; i<blueEnd; ++i) {\n    var idx = blueIndex[i]+BLUE_FLAG\n    var blueOffset = elemSize*i\n    SWEEP_EVENTS[ptr++] = blue[blueOffset+istart]\n    SWEEP_EVENTS[ptr++] = -idx\n    SWEEP_EVENTS[ptr++] = blue[blueOffset+iend]\n    SWEEP_EVENTS[ptr++] = idx\n  }\n\n  //process events from left->right\n  var n = ptr >>> 1\n  isort(SWEEP_EVENTS, n)\n  \n  var redActive  = 0\n  var blueActive = 0\n  for(var i=0; i<n; ++i) {\n    var e = SWEEP_EVENTS[2*i+1]|0\n    if(e >= BLUE_FLAG) {\n      //blue destroy event\n      e = (e-BLUE_FLAG)|0\n      sqPop(BLUE_SWEEP_QUEUE, BLUE_SWEEP_INDEX, blueActive--, e)\n    } else if(e >= 0) {\n      //red destroy event\n      sqPop(RED_SWEEP_QUEUE, RED_SWEEP_INDEX, redActive--, e)\n    } else if(e <= -BLUE_FLAG) {\n      //blue create event\n      e = (-e-BLUE_FLAG)|0\n      for(var j=0; j<redActive; ++j) {\n        var retval = visit(RED_SWEEP_QUEUE[j], e)\n        if(retval !== void 0) {\n          return retval\n        }\n      }\n      sqPush(BLUE_SWEEP_QUEUE, BLUE_SWEEP_INDEX, blueActive++, e)\n    } else {\n      //red create event\n      e = (-e-1)|0\n      for(var j=0; j<blueActive; ++j) {\n        var retval = visit(e, BLUE_SWEEP_QUEUE[j])\n        if(retval !== void 0) {\n          return retval\n        }\n      }\n      sqPush(RED_SWEEP_QUEUE, RED_SWEEP_INDEX, redActive++, e)\n    }\n  }\n}\n\n//Complete sweep\nfunction sweepComplete(d, visit, \n  redStart, redEnd, red, redIndex,\n  blueStart, blueEnd, blue, blueIndex) {\n\n  var ptr      = 0\n  var elemSize = 2*d\n  var istart   = d-1\n  var iend     = elemSize-1\n\n  for(var i=redStart; i<redEnd; ++i) {\n    var idx = (redIndex[i]+1)<<1\n    var redOffset = elemSize*i\n    SWEEP_EVENTS[ptr++] = red[redOffset+istart]\n    SWEEP_EVENTS[ptr++] = -idx\n    SWEEP_EVENTS[ptr++] = red[redOffset+iend]\n    SWEEP_EVENTS[ptr++] = idx\n  }\n\n  for(var i=blueStart; i<blueEnd; ++i) {\n    var idx = (blueIndex[i]+1)<<1\n    var blueOffset = elemSize*i\n    SWEEP_EVENTS[ptr++] = blue[blueOffset+istart]\n    SWEEP_EVENTS[ptr++] = (-idx)|1\n    SWEEP_EVENTS[ptr++] = blue[blueOffset+iend]\n    SWEEP_EVENTS[ptr++] = idx|1\n  }\n\n  //process events from left->right\n  var n = ptr >>> 1\n  isort(SWEEP_EVENTS, n)\n  \n  var redActive    = 0\n  var blueActive   = 0\n  var commonActive = 0\n  for(var i=0; i<n; ++i) {\n    var e     = SWEEP_EVENTS[2*i+1]|0\n    var color = e&1\n    if(i < n-1 && (e>>1) === (SWEEP_EVENTS[2*i+3]>>1)) {\n      color = 2\n      i += 1\n    }\n    \n    if(e < 0) {\n      //Create event\n      var id = -(e>>1) - 1\n\n      //Intersect with common\n      for(var j=0; j<commonActive; ++j) {\n        var retval = visit(COMMON_SWEEP_QUEUE[j], id)\n        if(retval !== void 0) {\n          return retval\n        }\n      }\n\n      if(color !== 0) {\n        //Intersect with red\n        for(var j=0; j<redActive; ++j) {\n          var retval = visit(RED_SWEEP_QUEUE[j], id)\n          if(retval !== void 0) {\n            return retval\n          }\n        }\n      }\n\n      if(color !== 1) {\n        //Intersect with blue\n        for(var j=0; j<blueActive; ++j) {\n          var retval = visit(BLUE_SWEEP_QUEUE[j], id)\n          if(retval !== void 0) {\n            return retval\n          }\n        }\n      }\n\n      if(color === 0) {\n        //Red\n        sqPush(RED_SWEEP_QUEUE, RED_SWEEP_INDEX, redActive++, id)\n      } else if(color === 1) {\n        //Blue\n        sqPush(BLUE_SWEEP_QUEUE, BLUE_SWEEP_INDEX, blueActive++, id)\n      } else if(color === 2) {\n        //Both\n        sqPush(COMMON_SWEEP_QUEUE, COMMON_SWEEP_INDEX, commonActive++, id)\n      }\n    } else {\n      //Destroy event\n      var id = (e>>1) - 1\n      if(color === 0) {\n        //Red\n        sqPop(RED_SWEEP_QUEUE, RED_SWEEP_INDEX, redActive--, id)\n      } else if(color === 1) {\n        //Blue\n        sqPop(BLUE_SWEEP_QUEUE, BLUE_SWEEP_INDEX, blueActive--, id)\n      } else if(color === 2) {\n        //Both\n        sqPop(COMMON_SWEEP_QUEUE, COMMON_SWEEP_INDEX, commonActive--, id)\n      }\n    }\n  }\n}\n\n//Sweep and prune/scanline algorithm:\n//  Scan along axis, detect intersections\n//  Brute force all boxes along axis\nfunction scanBipartite(\n  d, axis, visit, flip,\n  redStart,  redEnd, red, redIndex,\n  blueStart, blueEnd, blue, blueIndex) {\n  \n  var ptr      = 0\n  var elemSize = 2*d\n  var istart   = axis\n  var iend     = axis+d\n\n  var redShift  = 1\n  var blueShift = 1\n  if(flip) {\n    blueShift = BLUE_FLAG\n  } else {\n    redShift  = BLUE_FLAG\n  }\n\n  for(var i=redStart; i<redEnd; ++i) {\n    var idx = i + redShift\n    var redOffset = elemSize*i\n    SWEEP_EVENTS[ptr++] = red[redOffset+istart]\n    SWEEP_EVENTS[ptr++] = -idx\n    SWEEP_EVENTS[ptr++] = red[redOffset+iend]\n    SWEEP_EVENTS[ptr++] = idx\n  }\n  for(var i=blueStart; i<blueEnd; ++i) {\n    var idx = i + blueShift\n    var blueOffset = elemSize*i\n    SWEEP_EVENTS[ptr++] = blue[blueOffset+istart]\n    SWEEP_EVENTS[ptr++] = -idx\n  }\n\n  //process events from left->right\n  var n = ptr >>> 1\n  isort(SWEEP_EVENTS, n)\n  \n  var redActive    = 0\n  for(var i=0; i<n; ++i) {\n    var e = SWEEP_EVENTS[2*i+1]|0\n    if(e < 0) {\n      var idx   = -e\n      var isRed = false\n      if(idx >= BLUE_FLAG) {\n        isRed = !flip\n        idx -= BLUE_FLAG \n      } else {\n        isRed = !!flip\n        idx -= 1\n      }\n      if(isRed) {\n        sqPush(RED_SWEEP_QUEUE, RED_SWEEP_INDEX, redActive++, idx)\n      } else {\n        var blueId  = blueIndex[idx]\n        var bluePtr = elemSize * idx\n        \n        var b0 = blue[bluePtr+axis+1]\n        var b1 = blue[bluePtr+axis+1+d]\n\nred_loop:\n        for(var j=0; j<redActive; ++j) {\n          var oidx   = RED_SWEEP_QUEUE[j]\n          var redPtr = elemSize * oidx\n\n          if(b1 < red[redPtr+axis+1] || \n             red[redPtr+axis+1+d] < b0) {\n            continue\n          }\n\n          for(var k=axis+2; k<d; ++k) {\n            if(blue[bluePtr + k + d] < red[redPtr + k] || \n               red[redPtr + k + d] < blue[bluePtr + k]) {\n              continue red_loop\n            }\n          }\n\n          var redId  = redIndex[oidx]\n          var retval\n          if(flip) {\n            retval = visit(blueId, redId)\n          } else {\n            retval = visit(redId, blueId)\n          }\n          if(retval !== void 0) {\n            return retval \n          }\n        }\n      }\n    } else {\n      sqPop(RED_SWEEP_QUEUE, RED_SWEEP_INDEX, redActive--, e - redShift)\n    }\n  }\n}\n\nfunction scanComplete(\n  d, axis, visit,\n  redStart,  redEnd, red, redIndex,\n  blueStart, blueEnd, blue, blueIndex) {\n\n  var ptr      = 0\n  var elemSize = 2*d\n  var istart   = axis\n  var iend     = axis+d\n\n  for(var i=redStart; i<redEnd; ++i) {\n    var idx = i + BLUE_FLAG\n    var redOffset = elemSize*i\n    SWEEP_EVENTS[ptr++] = red[redOffset+istart]\n    SWEEP_EVENTS[ptr++] = -idx\n    SWEEP_EVENTS[ptr++] = red[redOffset+iend]\n    SWEEP_EVENTS[ptr++] = idx\n  }\n  for(var i=blueStart; i<blueEnd; ++i) {\n    var idx = i + 1\n    var blueOffset = elemSize*i\n    SWEEP_EVENTS[ptr++] = blue[blueOffset+istart]\n    SWEEP_EVENTS[ptr++] = -idx\n  }\n\n  //process events from left->right\n  var n = ptr >>> 1\n  isort(SWEEP_EVENTS, n)\n  \n  var redActive    = 0\n  for(var i=0; i<n; ++i) {\n    var e = SWEEP_EVENTS[2*i+1]|0\n    if(e < 0) {\n      var idx   = -e\n      if(idx >= BLUE_FLAG) {\n        RED_SWEEP_QUEUE[redActive++] = idx - BLUE_FLAG\n      } else {\n        idx -= 1\n        var blueId  = blueIndex[idx]\n        var bluePtr = elemSize * idx\n\n        var b0 = blue[bluePtr+axis+1]\n        var b1 = blue[bluePtr+axis+1+d]\n\nred_loop:\n        for(var j=0; j<redActive; ++j) {\n          var oidx   = RED_SWEEP_QUEUE[j]\n          var redId  = redIndex[oidx]\n\n          if(redId === blueId) {\n            break\n          }\n\n          var redPtr = elemSize * oidx\n          if(b1 < red[redPtr+axis+1] || \n            red[redPtr+axis+1+d] < b0) {\n            continue\n          }\n          for(var k=axis+2; k<d; ++k) {\n            if(blue[bluePtr + k + d] < red[redPtr + k] || \n               red[redPtr + k + d]   < blue[bluePtr + k]) {\n              continue red_loop\n            }\n          }\n\n          var retval = visit(redId, blueId)\n          if(retval !== void 0) {\n            return retval \n          }\n        }\n      }\n    } else {\n      var idx = e - BLUE_FLAG\n      for(var j=redActive-1; j>=0; --j) {\n        if(RED_SWEEP_QUEUE[j] === idx) {\n          for(var k=j+1; k<redActive; ++k) {\n            RED_SWEEP_QUEUE[k-1] = RED_SWEEP_QUEUE[k]\n          }\n          break\n        }\n      }\n      --redActive\n    }\n  }\n}\n},{\"./sort\":101,\"bit-twiddle\":92,\"typedarray-pool\":545}],103:[function(_dereq_,module,exports){\n\n},{}],104:[function(_dereq_,module,exports){\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nvar objectCreate = Object.create || objectCreatePolyfill\nvar objectKeys = Object.keys || objectKeysPolyfill\nvar bind = Function.prototype.bind || functionBindPolyfill\n\nfunction EventEmitter() {\n  if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {\n    this._events = objectCreate(null);\n    this._eventsCount = 0;\n  }\n\n  this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nvar defaultMaxListeners = 10;\n\nvar hasDefineProperty;\ntry {\n  var o = {};\n  if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });\n  hasDefineProperty = o.x === 0;\n} catch (err) { hasDefineProperty = false }\nif (hasDefineProperty) {\n  Object.defineProperty(EventEmitter, 'defaultMaxListeners', {\n    enumerable: true,\n    get: function() {\n      return defaultMaxListeners;\n    },\n    set: function(arg) {\n      // check whether the input is a positive number (whose value is zero or\n      // greater and not a NaN).\n      if (typeof arg !== 'number' || arg < 0 || arg !== arg)\n        throw new TypeError('\"defaultMaxListeners\" must be a positive number');\n      defaultMaxListeners = arg;\n    }\n  });\n} else {\n  EventEmitter.defaultMaxListeners = defaultMaxListeners;\n}\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {\n  if (typeof n !== 'number' || n < 0 || isNaN(n))\n    throw new TypeError('\"n\" argument must be a positive number');\n  this._maxListeners = n;\n  return this;\n};\n\nfunction $getMaxListeners(that) {\n  if (that._maxListeners === undefined)\n    return EventEmitter.defaultMaxListeners;\n  return that._maxListeners;\n}\n\nEventEmitter.prototype.getMaxListeners = function getMaxListeners() {\n  return $getMaxListeners(this);\n};\n\n// These standalone emit* functions are used to optimize calling of event\n// handlers for fast cases because emit() itself often has a variable number of\n// arguments and can be deoptimized because of that. These functions always have\n// the same number of arguments and thus do not get deoptimized, so the code\n// inside them can execute faster.\nfunction emitNone(handler, isFn, self) {\n  if (isFn)\n    handler.call(self);\n  else {\n    var len = handler.length;\n    var listeners = arrayClone(handler, len);\n    for (var i = 0; i < len; ++i)\n      listeners[i].call(self);\n  }\n}\nfunction emitOne(handler, isFn, self, arg1) {\n  if (isFn)\n    handler.call(self, arg1);\n  else {\n    var len = handler.length;\n    var listeners = arrayClone(handler, len);\n    for (var i = 0; i < len; ++i)\n      listeners[i].call(self, arg1);\n  }\n}\nfunction emitTwo(handler, isFn, self, arg1, arg2) {\n  if (isFn)\n    handler.call(self, arg1, arg2);\n  else {\n    var len = handler.length;\n    var listeners = arrayClone(handler, len);\n    for (var i = 0; i < len; ++i)\n      listeners[i].call(self, arg1, arg2);\n  }\n}\nfunction emitThree(handler, isFn, self, arg1, arg2, arg3) {\n  if (isFn)\n    handler.call(self, arg1, arg2, arg3);\n  else {\n    var len = handler.length;\n    var listeners = arrayClone(handler, len);\n    for (var i = 0; i < len; ++i)\n      listeners[i].call(self, arg1, arg2, arg3);\n  }\n}\n\nfunction emitMany(handler, isFn, self, args) {\n  if (isFn)\n    handler.apply(self, args);\n  else {\n    var len = handler.length;\n    var listeners = arrayClone(handler, len);\n    for (var i = 0; i < len; ++i)\n      listeners[i].apply(self, args);\n  }\n}\n\nEventEmitter.prototype.emit = function emit(type) {\n  var er, handler, len, args, i, events;\n  var doError = (type === 'error');\n\n  events = this._events;\n  if (events)\n    doError = (doError && events.error == null);\n  else if (!doError)\n    return false;\n\n  // If there is no 'error' event listener then throw.\n  if (doError) {\n    if (arguments.length > 1)\n      er = arguments[1];\n    if (er instanceof Error) {\n      throw er; // Unhandled 'error' event\n    } else {\n      // At least give some kind of context to the user\n      var err = new Error('Unhandled \"error\" event. (' + er + ')');\n      err.context = er;\n      throw err;\n    }\n    return false;\n  }\n\n  handler = events[type];\n\n  if (!handler)\n    return false;\n\n  var isFn = typeof handler === 'function';\n  len = arguments.length;\n  switch (len) {\n      // fast cases\n    case 1:\n      emitNone(handler, isFn, this);\n      break;\n    case 2:\n      emitOne(handler, isFn, this, arguments[1]);\n      break;\n    case 3:\n      emitTwo(handler, isFn, this, arguments[1], arguments[2]);\n      break;\n    case 4:\n      emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);\n      break;\n      // slower\n    default:\n      args = new Array(len - 1);\n      for (i = 1; i < len; i++)\n        args[i - 1] = arguments[i];\n      emitMany(handler, isFn, this, args);\n  }\n\n  return true;\n};\n\nfunction _addListener(target, type, listener, prepend) {\n  var m;\n  var events;\n  var existing;\n\n  if (typeof listener !== 'function')\n    throw new TypeError('\"listener\" argument must be a function');\n\n  events = target._events;\n  if (!events) {\n    events = target._events = objectCreate(null);\n    target._eventsCount = 0;\n  } else {\n    // To avoid recursion in the case that type === \"newListener\"! Before\n    // adding it to the listeners, first emit \"newListener\".\n    if (events.newListener) {\n      target.emit('newListener', type,\n          listener.listener ? listener.listener : listener);\n\n      // Re-assign `events` because a newListener handler could have caused the\n      // this._events to be assigned to a new object\n      events = target._events;\n    }\n    existing = events[type];\n  }\n\n  if (!existing) {\n    // Optimize the case of one listener. Don't need the extra array object.\n    existing = events[type] = listener;\n    ++target._eventsCount;\n  } else {\n    if (typeof existing === 'function') {\n      // Adding the second element, need to change to array.\n      existing = events[type] =\n          prepend ? [listener, existing] : [existing, listener];\n    } else {\n      // If we've already got an array, just append.\n      if (prepend) {\n        existing.unshift(listener);\n      } else {\n        existing.push(listener);\n      }\n    }\n\n    // Check for listener leak\n    if (!existing.warned) {\n      m = $getMaxListeners(target);\n      if (m && m > 0 && existing.length > m) {\n        existing.warned = true;\n        var w = new Error('Possible EventEmitter memory leak detected. ' +\n            existing.length + ' \"' + String(type) + '\" listeners ' +\n            'added. Use emitter.setMaxListeners() to ' +\n            'increase limit.');\n        w.name = 'MaxListenersExceededWarning';\n        w.emitter = target;\n        w.type = type;\n        w.count = existing.length;\n        if (typeof console === 'object' && console.warn) {\n          console.warn('%s: %s', w.name, w.message);\n        }\n      }\n    }\n  }\n\n  return target;\n}\n\nEventEmitter.prototype.addListener = function addListener(type, listener) {\n  return _addListener(this, type, listener, false);\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.prependListener =\n    function prependListener(type, listener) {\n      return _addListener(this, type, listener, true);\n    };\n\nfunction onceWrapper() {\n  if (!this.fired) {\n    this.target.removeListener(this.type, this.wrapFn);\n    this.fired = true;\n    switch (arguments.length) {\n      case 0:\n        return this.listener.call(this.target);\n      case 1:\n        return this.listener.call(this.target, arguments[0]);\n      case 2:\n        return this.listener.call(this.target, arguments[0], arguments[1]);\n      case 3:\n        return this.listener.call(this.target, arguments[0], arguments[1],\n            arguments[2]);\n      default:\n        var args = new Array(arguments.length);\n        for (var i = 0; i < args.length; ++i)\n          args[i] = arguments[i];\n        this.listener.apply(this.target, args);\n    }\n  }\n}\n\nfunction _onceWrap(target, type, listener) {\n  var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };\n  var wrapped = bind.call(onceWrapper, state);\n  wrapped.listener = listener;\n  state.wrapFn = wrapped;\n  return wrapped;\n}\n\nEventEmitter.prototype.once = function once(type, listener) {\n  if (typeof listener !== 'function')\n    throw new TypeError('\"listener\" argument must be a function');\n  this.on(type, _onceWrap(this, type, listener));\n  return this;\n};\n\nEventEmitter.prototype.prependOnceListener =\n    function prependOnceListener(type, listener) {\n      if (typeof listener !== 'function')\n        throw new TypeError('\"listener\" argument must be a function');\n      this.prependListener(type, _onceWrap(this, type, listener));\n      return this;\n    };\n\n// Emits a 'removeListener' event if and only if the listener was removed.\nEventEmitter.prototype.removeListener =\n    function removeListener(type, listener) {\n      var list, events, position, i, originalListener;\n\n      if (typeof listener !== 'function')\n        throw new TypeError('\"listener\" argument must be a function');\n\n      events = this._events;\n      if (!events)\n        return this;\n\n      list = events[type];\n      if (!list)\n        return this;\n\n      if (list === listener || list.listener === listener) {\n        if (--this._eventsCount === 0)\n          this._events = objectCreate(null);\n        else {\n          delete events[type];\n          if (events.removeListener)\n            this.emit('removeListener', type, list.listener || listener);\n        }\n      } else if (typeof list !== 'function') {\n        position = -1;\n\n        for (i = list.length - 1; i >= 0; i--) {\n          if (list[i] === listener || list[i].listener === listener) {\n            originalListener = list[i].listener;\n            position = i;\n            break;\n          }\n        }\n\n        if (position < 0)\n          return this;\n\n        if (position === 0)\n          list.shift();\n        else\n          spliceOne(list, position);\n\n        if (list.length === 1)\n          events[type] = list[0];\n\n        if (events.removeListener)\n          this.emit('removeListener', type, originalListener || listener);\n      }\n\n      return this;\n    };\n\nEventEmitter.prototype.removeAllListeners =\n    function removeAllListeners(type) {\n      var listeners, events, i;\n\n      events = this._events;\n      if (!events)\n        return this;\n\n      // not listening for removeListener, no need to emit\n      if (!events.removeListener) {\n        if (arguments.length === 0) {\n          this._events = objectCreate(null);\n          this._eventsCount = 0;\n        } else if (events[type]) {\n          if (--this._eventsCount === 0)\n            this._events = objectCreate(null);\n          else\n            delete events[type];\n        }\n        return this;\n      }\n\n      // emit removeListener for all listeners on all events\n      if (arguments.length === 0) {\n        var keys = objectKeys(events);\n        var key;\n        for (i = 0; i < keys.length; ++i) {\n          key = keys[i];\n          if (key === 'removeListener') continue;\n          this.removeAllListeners(key);\n        }\n        this.removeAllListeners('removeListener');\n        this._events = objectCreate(null);\n        this._eventsCount = 0;\n        return this;\n      }\n\n      listeners = events[type];\n\n      if (typeof listeners === 'function') {\n        this.removeListener(type, listeners);\n      } else if (listeners) {\n        // LIFO order\n        for (i = listeners.length - 1; i >= 0; i--) {\n          this.removeListener(type, listeners[i]);\n        }\n      }\n\n      return this;\n    };\n\nfunction _listeners(target, type, unwrap) {\n  var events = target._events;\n\n  if (!events)\n    return [];\n\n  var evlistener = events[type];\n  if (!evlistener)\n    return [];\n\n  if (typeof evlistener === 'function')\n    return unwrap ? [evlistener.listener || evlistener] : [evlistener];\n\n  return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);\n}\n\nEventEmitter.prototype.listeners = function listeners(type) {\n  return _listeners(this, type, true);\n};\n\nEventEmitter.prototype.rawListeners = function rawListeners(type) {\n  return _listeners(this, type, false);\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n  if (typeof emitter.listenerCount === 'function') {\n    return emitter.listenerCount(type);\n  } else {\n    return listenerCount.call(emitter, type);\n  }\n};\n\nEventEmitter.prototype.listenerCount = listenerCount;\nfunction listenerCount(type) {\n  var events = this._events;\n\n  if (events) {\n    var evlistener = events[type];\n\n    if (typeof evlistener === 'function') {\n      return 1;\n    } else if (evlistener) {\n      return evlistener.length;\n    }\n  }\n\n  return 0;\n}\n\nEventEmitter.prototype.eventNames = function eventNames() {\n  return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];\n};\n\n// About 1.5x faster than the two-arg version of Array#splice().\nfunction spliceOne(list, index) {\n  for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)\n    list[i] = list[k];\n  list.pop();\n}\n\nfunction arrayClone(arr, n) {\n  var copy = new Array(n);\n  for (var i = 0; i < n; ++i)\n    copy[i] = arr[i];\n  return copy;\n}\n\nfunction unwrapListeners(arr) {\n  var ret = new Array(arr.length);\n  for (var i = 0; i < ret.length; ++i) {\n    ret[i] = arr[i].listener || arr[i];\n  }\n  return ret;\n}\n\nfunction objectCreatePolyfill(proto) {\n  var F = function() {};\n  F.prototype = proto;\n  return new F;\n}\nfunction objectKeysPolyfill(obj) {\n  var keys = [];\n  for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {\n    keys.push(k);\n  }\n  return k;\n}\nfunction functionBindPolyfill(context) {\n  var fn = this;\n  return function () {\n    return fn.apply(context, arguments);\n  };\n}\n\n},{}],105:[function(_dereq_,module,exports){\n(function (Buffer){\n/*!\n * The buffer module from node.js, for the browser.\n *\n * @author   Feross Aboukhadijeh <https://feross.org>\n * @license  MIT\n */\n/* eslint-disable no-proto */\n\n'use strict'\n\nvar base64 = _dereq_('base64-js')\nvar ieee754 = _dereq_('ieee754')\n\nexports.Buffer = Buffer\nexports.SlowBuffer = SlowBuffer\nexports.INSPECT_MAX_BYTES = 50\n\nvar K_MAX_LENGTH = 0x7fffffff\nexports.kMaxLength = K_MAX_LENGTH\n\n/**\n * If `Buffer.TYPED_ARRAY_SUPPORT`:\n *   === true    Use Uint8Array implementation (fastest)\n *   === false   Print warning and recommend using `buffer` v4.x which has an Object\n *               implementation (most compatible, even IE6)\n *\n * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,\n * Opera 11.6+, iOS 4.2+.\n *\n * We report that the browser does not support typed arrays if the are not subclassable\n * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`\n * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support\n * for __proto__ and has a buggy typed array implementation.\n */\nBuffer.TYPED_ARRAY_SUPPORT = typedArraySupport()\n\nif (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&\n    typeof console.error === 'function') {\n  console.error(\n    'This browser lacks typed array (Uint8Array) support which is required by ' +\n    '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'\n  )\n}\n\nfunction typedArraySupport () {\n  // Can typed array instances can be augmented?\n  try {\n    var arr = new Uint8Array(1)\n    arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }\n    return arr.foo() === 42\n  } catch (e) {\n    return false\n  }\n}\n\nObject.defineProperty(Buffer.prototype, 'parent', {\n  enumerable: true,\n  get: function () {\n    if (!Buffer.isBuffer(this)) return undefined\n    return this.buffer\n  }\n})\n\nObject.defineProperty(Buffer.prototype, 'offset', {\n  enumerable: true,\n  get: function () {\n    if (!Buffer.isBuffer(this)) return undefined\n    return this.byteOffset\n  }\n})\n\nfunction createBuffer (length) {\n  if (length > K_MAX_LENGTH) {\n    throw new RangeError('The value \"' + length + '\" is invalid for option \"size\"')\n  }\n  // Return an augmented `Uint8Array` instance\n  var buf = new Uint8Array(length)\n  buf.__proto__ = Buffer.prototype\n  return buf\n}\n\n/**\n * The Buffer constructor returns instances of `Uint8Array` that have their\n * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of\n * `Uint8Array`, so the returned instances will have all the node `Buffer` methods\n * and the `Uint8Array` methods. Square bracket notation works as expected -- it\n * returns a single octet.\n *\n * The `Uint8Array` prototype remains unmodified.\n */\n\nfunction Buffer (arg, encodingOrOffset, length) {\n  // Common case.\n  if (typeof arg === 'number') {\n    if (typeof encodingOrOffset === 'string') {\n      throw new TypeError(\n        'The \"string\" argument must be of type string. Received type number'\n      )\n    }\n    return allocUnsafe(arg)\n  }\n  return from(arg, encodingOrOffset, length)\n}\n\n// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97\nif (typeof Symbol !== 'undefined' && Symbol.species != null &&\n    Buffer[Symbol.species] === Buffer) {\n  Object.defineProperty(Buffer, Symbol.species, {\n    value: null,\n    configurable: true,\n    enumerable: false,\n    writable: false\n  })\n}\n\nBuffer.poolSize = 8192 // not used by this implementation\n\nfunction from (value, encodingOrOffset, length) {\n  if (typeof value === 'string') {\n    return fromString(value, encodingOrOffset)\n  }\n\n  if (ArrayBuffer.isView(value)) {\n    return fromArrayLike(value)\n  }\n\n  if (value == null) {\n    throw TypeError(\n      'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +\n      'or Array-like Object. Received type ' + (typeof value)\n    )\n  }\n\n  if (isInstance(value, ArrayBuffer) ||\n      (value && isInstance(value.buffer, ArrayBuffer))) {\n    return fromArrayBuffer(value, encodingOrOffset, length)\n  }\n\n  if (typeof value === 'number') {\n    throw new TypeError(\n      'The \"value\" argument must not be of type number. Received type number'\n    )\n  }\n\n  var valueOf = value.valueOf && value.valueOf()\n  if (valueOf != null && valueOf !== value) {\n    return Buffer.from(valueOf, encodingOrOffset, length)\n  }\n\n  var b = fromObject(value)\n  if (b) return b\n\n  if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&\n      typeof value[Symbol.toPrimitive] === 'function') {\n    return Buffer.from(\n      value[Symbol.toPrimitive]('string'), encodingOrOffset, length\n    )\n  }\n\n  throw new TypeError(\n    'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +\n    'or Array-like Object. Received type ' + (typeof value)\n  )\n}\n\n/**\n * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError\n * if value is a number.\n * Buffer.from(str[, encoding])\n * Buffer.from(array)\n * Buffer.from(buffer)\n * Buffer.from(arrayBuffer[, byteOffset[, length]])\n **/\nBuffer.from = function (value, encodingOrOffset, length) {\n  return from(value, encodingOrOffset, length)\n}\n\n// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:\n// https://github.com/feross/buffer/pull/148\nBuffer.prototype.__proto__ = Uint8Array.prototype\nBuffer.__proto__ = Uint8Array\n\nfunction assertSize (size) {\n  if (typeof size !== 'number') {\n    throw new TypeError('\"size\" argument must be of type number')\n  } else if (size < 0) {\n    throw new RangeError('The value \"' + size + '\" is invalid for option \"size\"')\n  }\n}\n\nfunction alloc (size, fill, encoding) {\n  assertSize(size)\n  if (size <= 0) {\n    return createBuffer(size)\n  }\n  if (fill !== undefined) {\n    // Only pay attention to encoding if it's a string. This\n    // prevents accidentally sending in a number that would\n    // be interpretted as a start offset.\n    return typeof encoding === 'string'\n      ? createBuffer(size).fill(fill, encoding)\n      : createBuffer(size).fill(fill)\n  }\n  return createBuffer(size)\n}\n\n/**\n * Creates a new filled Buffer instance.\n * alloc(size[, fill[, encoding]])\n **/\nBuffer.alloc = function (size, fill, encoding) {\n  return alloc(size, fill, encoding)\n}\n\nfunction allocUnsafe (size) {\n  assertSize(size)\n  return createBuffer(size < 0 ? 0 : checked(size) | 0)\n}\n\n/**\n * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.\n * */\nBuffer.allocUnsafe = function (size) {\n  return allocUnsafe(size)\n}\n/**\n * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.\n */\nBuffer.allocUnsafeSlow = function (size) {\n  return allocUnsafe(size)\n}\n\nfunction fromString (string, encoding) {\n  if (typeof encoding !== 'string' || encoding === '') {\n    encoding = 'utf8'\n  }\n\n  if (!Buffer.isEncoding(encoding)) {\n    throw new TypeError('Unknown encoding: ' + encoding)\n  }\n\n  var length = byteLength(string, encoding) | 0\n  var buf = createBuffer(length)\n\n  var actual = buf.write(string, encoding)\n\n  if (actual !== length) {\n    // Writing a hex string, for example, that contains invalid characters will\n    // cause everything after the first invalid character to be ignored. (e.g.\n    // 'abxxcd' will be treated as 'ab')\n    buf = buf.slice(0, actual)\n  }\n\n  return buf\n}\n\nfunction fromArrayLike (array) {\n  var length = array.length < 0 ? 0 : checked(array.length) | 0\n  var buf = createBuffer(length)\n  for (var i = 0; i < length; i += 1) {\n    buf[i] = array[i] & 255\n  }\n  return buf\n}\n\nfunction fromArrayBuffer (array, byteOffset, length) {\n  if (byteOffset < 0 || array.byteLength < byteOffset) {\n    throw new RangeError('\"offset\" is outside of buffer bounds')\n  }\n\n  if (array.byteLength < byteOffset + (length || 0)) {\n    throw new RangeError('\"length\" is outside of buffer bounds')\n  }\n\n  var buf\n  if (byteOffset === undefined && length === undefined) {\n    buf = new Uint8Array(array)\n  } else if (length === undefined) {\n    buf = new Uint8Array(array, byteOffset)\n  } else {\n    buf = new Uint8Array(array, byteOffset, length)\n  }\n\n  // Return an augmented `Uint8Array` instance\n  buf.__proto__ = Buffer.prototype\n  return buf\n}\n\nfunction fromObject (obj) {\n  if (Buffer.isBuffer(obj)) {\n    var len = checked(obj.length) | 0\n    var buf = createBuffer(len)\n\n    if (buf.length === 0) {\n      return buf\n    }\n\n    obj.copy(buf, 0, 0, len)\n    return buf\n  }\n\n  if (obj.length !== undefined) {\n    if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {\n      return createBuffer(0)\n    }\n    return fromArrayLike(obj)\n  }\n\n  if (obj.type === 'Buffer' && Array.isArray(obj.data)) {\n    return fromArrayLike(obj.data)\n  }\n}\n\nfunction checked (length) {\n  // Note: cannot use `length < K_MAX_LENGTH` here because that fails when\n  // length is NaN (which is otherwise coerced to zero.)\n  if (length >= K_MAX_LENGTH) {\n    throw new RangeError('Attempt to allocate Buffer larger than maximum ' +\n                         'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')\n  }\n  return length | 0\n}\n\nfunction SlowBuffer (length) {\n  if (+length != length) { // eslint-disable-line eqeqeq\n    length = 0\n  }\n  return Buffer.alloc(+length)\n}\n\nBuffer.isBuffer = function isBuffer (b) {\n  return b != null && b._isBuffer === true &&\n    b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false\n}\n\nBuffer.compare = function compare (a, b) {\n  if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)\n  if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)\n  if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {\n    throw new TypeError(\n      'The \"buf1\", \"buf2\" arguments must be one of type Buffer or Uint8Array'\n    )\n  }\n\n  if (a === b) return 0\n\n  var x = a.length\n  var y = b.length\n\n  for (var i = 0, len = Math.min(x, y); i < len; ++i) {\n    if (a[i] !== b[i]) {\n      x = a[i]\n      y = b[i]\n      break\n    }\n  }\n\n  if (x < y) return -1\n  if (y < x) return 1\n  return 0\n}\n\nBuffer.isEncoding = function isEncoding (encoding) {\n  switch (String(encoding).toLowerCase()) {\n    case 'hex':\n    case 'utf8':\n    case 'utf-8':\n    case 'ascii':\n    case 'latin1':\n    case 'binary':\n    case 'base64':\n    case 'ucs2':\n    case 'ucs-2':\n    case 'utf16le':\n    case 'utf-16le':\n      return true\n    default:\n      return false\n  }\n}\n\nBuffer.concat = function concat (list, length) {\n  if (!Array.isArray(list)) {\n    throw new TypeError('\"list\" argument must be an Array of Buffers')\n  }\n\n  if (list.length === 0) {\n    return Buffer.alloc(0)\n  }\n\n  var i\n  if (length === undefined) {\n    length = 0\n    for (i = 0; i < list.length; ++i) {\n      length += list[i].length\n    }\n  }\n\n  var buffer = Buffer.allocUnsafe(length)\n  var pos = 0\n  for (i = 0; i < list.length; ++i) {\n    var buf = list[i]\n    if (isInstance(buf, Uint8Array)) {\n      buf = Buffer.from(buf)\n    }\n    if (!Buffer.isBuffer(buf)) {\n      throw new TypeError('\"list\" argument must be an Array of Buffers')\n    }\n    buf.copy(buffer, pos)\n    pos += buf.length\n  }\n  return buffer\n}\n\nfunction byteLength (string, encoding) {\n  if (Buffer.isBuffer(string)) {\n    return string.length\n  }\n  if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {\n    return string.byteLength\n  }\n  if (typeof string !== 'string') {\n    throw new TypeError(\n      'The \"string\" argument must be one of type string, Buffer, or ArrayBuffer. ' +\n      'Received type ' + typeof string\n    )\n  }\n\n  var len = string.length\n  var mustMatch = (arguments.length > 2 && arguments[2] === true)\n  if (!mustMatch && len === 0) return 0\n\n  // Use a for loop to avoid recursion\n  var loweredCase = false\n  for (;;) {\n    switch (encoding) {\n      case 'ascii':\n      case 'latin1':\n      case 'binary':\n        return len\n      case 'utf8':\n      case 'utf-8':\n        return utf8ToBytes(string).length\n      case 'ucs2':\n      case 'ucs-2':\n      case 'utf16le':\n      case 'utf-16le':\n        return len * 2\n      case 'hex':\n        return len >>> 1\n      case 'base64':\n        return base64ToBytes(string).length\n      default:\n        if (loweredCase) {\n          return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8\n        }\n        encoding = ('' + encoding).toLowerCase()\n        loweredCase = true\n    }\n  }\n}\nBuffer.byteLength = byteLength\n\nfunction slowToString (encoding, start, end) {\n  var loweredCase = false\n\n  // No need to verify that \"this.length <= MAX_UINT32\" since it's a read-only\n  // property of a typed array.\n\n  // This behaves neither like String nor Uint8Array in that we set start/end\n  // to their upper/lower bounds if the value passed is out of range.\n  // undefined is handled specially as per ECMA-262 6th Edition,\n  // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.\n  if (start === undefined || start < 0) {\n    start = 0\n  }\n  // Return early if start > this.length. Done here to prevent potential uint32\n  // coercion fail below.\n  if (start > this.length) {\n    return ''\n  }\n\n  if (end === undefined || end > this.length) {\n    end = this.length\n  }\n\n  if (end <= 0) {\n    return ''\n  }\n\n  // Force coersion to uint32. This will also coerce falsey/NaN values to 0.\n  end >>>= 0\n  start >>>= 0\n\n  if (end <= start) {\n    return ''\n  }\n\n  if (!encoding) encoding = 'utf8'\n\n  while (true) {\n    switch (encoding) {\n      case 'hex':\n        return hexSlice(this, start, end)\n\n      case 'utf8':\n      case 'utf-8':\n        return utf8Slice(this, start, end)\n\n      case 'ascii':\n        return asciiSlice(this, start, end)\n\n      case 'latin1':\n      case 'binary':\n        return latin1Slice(this, start, end)\n\n      case 'base64':\n        return base64Slice(this, start, end)\n\n      case 'ucs2':\n      case 'ucs-2':\n      case 'utf16le':\n      case 'utf-16le':\n        return utf16leSlice(this, start, end)\n\n      default:\n        if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)\n        encoding = (encoding + '').toLowerCase()\n        loweredCase = true\n    }\n  }\n}\n\n// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)\n// to detect a Buffer instance. It's not possible to use `instanceof Buffer`\n// reliably in a browserify context because there could be multiple different\n// copies of the 'buffer' package in use. This method works even for Buffer\n// instances that were created from another copy of the `buffer` package.\n// See: https://github.com/feross/buffer/issues/154\nBuffer.prototype._isBuffer = true\n\nfunction swap (b, n, m) {\n  var i = b[n]\n  b[n] = b[m]\n  b[m] = i\n}\n\nBuffer.prototype.swap16 = function swap16 () {\n  var len = this.length\n  if (len % 2 !== 0) {\n    throw new RangeError('Buffer size must be a multiple of 16-bits')\n  }\n  for (var i = 0; i < len; i += 2) {\n    swap(this, i, i + 1)\n  }\n  return this\n}\n\nBuffer.prototype.swap32 = function swap32 () {\n  var len = this.length\n  if (len % 4 !== 0) {\n    throw new RangeError('Buffer size must be a multiple of 32-bits')\n  }\n  for (var i = 0; i < len; i += 4) {\n    swap(this, i, i + 3)\n    swap(this, i + 1, i + 2)\n  }\n  return this\n}\n\nBuffer.prototype.swap64 = function swap64 () {\n  var len = this.length\n  if (len % 8 !== 0) {\n    throw new RangeError('Buffer size must be a multiple of 64-bits')\n  }\n  for (var i = 0; i < len; i += 8) {\n    swap(this, i, i + 7)\n    swap(this, i + 1, i + 6)\n    swap(this, i + 2, i + 5)\n    swap(this, i + 3, i + 4)\n  }\n  return this\n}\n\nBuffer.prototype.toString = function toString () {\n  var length = this.length\n  if (length === 0) return ''\n  if (arguments.length === 0) return utf8Slice(this, 0, length)\n  return slowToString.apply(this, arguments)\n}\n\nBuffer.prototype.toLocaleString = Buffer.prototype.toString\n\nBuffer.prototype.equals = function equals (b) {\n  if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')\n  if (this === b) return true\n  return Buffer.compare(this, b) === 0\n}\n\nBuffer.prototype.inspect = function inspect () {\n  var str = ''\n  var max = exports.INSPECT_MAX_BYTES\n  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()\n  if (this.length > max) str += ' ... '\n  return '<Buffer ' + str + '>'\n}\n\nBuffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {\n  if (isInstance(target, Uint8Array)) {\n    target = Buffer.from(target, target.offset, target.byteLength)\n  }\n  if (!Buffer.isBuffer(target)) {\n    throw new TypeError(\n      'The \"target\" argument must be one of type Buffer or Uint8Array. ' +\n      'Received type ' + (typeof target)\n    )\n  }\n\n  if (start === undefined) {\n    start = 0\n  }\n  if (end === undefined) {\n    end = target ? target.length : 0\n  }\n  if (thisStart === undefined) {\n    thisStart = 0\n  }\n  if (thisEnd === undefined) {\n    thisEnd = this.length\n  }\n\n  if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {\n    throw new RangeError('out of range index')\n  }\n\n  if (thisStart >= thisEnd && start >= end) {\n    return 0\n  }\n  if (thisStart >= thisEnd) {\n    return -1\n  }\n  if (start >= end) {\n    return 1\n  }\n\n  start >>>= 0\n  end >>>= 0\n  thisStart >>>= 0\n  thisEnd >>>= 0\n\n  if (this === target) return 0\n\n  var x = thisEnd - thisStart\n  var y = end - start\n  var len = Math.min(x, y)\n\n  var thisCopy = this.slice(thisStart, thisEnd)\n  var targetCopy = target.slice(start, end)\n\n  for (var i = 0; i < len; ++i) {\n    if (thisCopy[i] !== targetCopy[i]) {\n      x = thisCopy[i]\n      y = targetCopy[i]\n      break\n    }\n  }\n\n  if (x < y) return -1\n  if (y < x) return 1\n  return 0\n}\n\n// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,\n// OR the last index of `val` in `buffer` at offset <= `byteOffset`.\n//\n// Arguments:\n// - buffer - a Buffer to search\n// - val - a string, Buffer, or number\n// - byteOffset - an index into `buffer`; will be clamped to an int32\n// - encoding - an optional encoding, relevant is val is a string\n// - dir - true for indexOf, false for lastIndexOf\nfunction bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {\n  // Empty buffer means no match\n  if (buffer.length === 0) return -1\n\n  // Normalize byteOffset\n  if (typeof byteOffset === 'string') {\n    encoding = byteOffset\n    byteOffset = 0\n  } else if (byteOffset > 0x7fffffff) {\n    byteOffset = 0x7fffffff\n  } else if (byteOffset < -0x80000000) {\n    byteOffset = -0x80000000\n  }\n  byteOffset = +byteOffset // Coerce to Number.\n  if (numberIsNaN(byteOffset)) {\n    // byteOffset: it it's undefined, null, NaN, \"foo\", etc, search whole buffer\n    byteOffset = dir ? 0 : (buffer.length - 1)\n  }\n\n  // Normalize byteOffset: negative offsets start from the end of the buffer\n  if (byteOffset < 0) byteOffset = buffer.length + byteOffset\n  if (byteOffset >= buffer.length) {\n    if (dir) return -1\n    else byteOffset = buffer.length - 1\n  } else if (byteOffset < 0) {\n    if (dir) byteOffset = 0\n    else return -1\n  }\n\n  // Normalize val\n  if (typeof val === 'string') {\n    val = Buffer.from(val, encoding)\n  }\n\n  // Finally, search either indexOf (if dir is true) or lastIndexOf\n  if (Buffer.isBuffer(val)) {\n    // Special case: looking for empty string/buffer always fails\n    if (val.length === 0) {\n      return -1\n    }\n    return arrayIndexOf(buffer, val, byteOffset, encoding, dir)\n  } else if (typeof val === 'number') {\n    val = val & 0xFF // Search for a byte value [0-255]\n    if (typeof Uint8Array.prototype.indexOf === 'function') {\n      if (dir) {\n        return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)\n      } else {\n        return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)\n      }\n    }\n    return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)\n  }\n\n  throw new TypeError('val must be string, number or Buffer')\n}\n\nfunction arrayIndexOf (arr, val, byteOffset, encoding, dir) {\n  var indexSize = 1\n  var arrLength = arr.length\n  var valLength = val.length\n\n  if (encoding !== undefined) {\n    encoding = String(encoding).toLowerCase()\n    if (encoding === 'ucs2' || encoding === 'ucs-2' ||\n        encoding === 'utf16le' || encoding === 'utf-16le') {\n      if (arr.length < 2 || val.length < 2) {\n        return -1\n      }\n      indexSize = 2\n      arrLength /= 2\n      valLength /= 2\n      byteOffset /= 2\n    }\n  }\n\n  function read (buf, i) {\n    if (indexSize === 1) {\n      return buf[i]\n    } else {\n      return buf.readUInt16BE(i * indexSize)\n    }\n  }\n\n  var i\n  if (dir) {\n    var foundIndex = -1\n    for (i = byteOffset; i < arrLength; i++) {\n      if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {\n        if (foundIndex === -1) foundIndex = i\n        if (i - foundIndex + 1 === valLength) return foundIndex * indexSize\n      } else {\n        if (foundIndex !== -1) i -= i - foundIndex\n        foundIndex = -1\n      }\n    }\n  } else {\n    if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength\n    for (i = byteOffset; i >= 0; i--) {\n      var found = true\n      for (var j = 0; j < valLength; j++) {\n        if (read(arr, i + j) !== read(val, j)) {\n          found = false\n          break\n        }\n      }\n      if (found) return i\n    }\n  }\n\n  return -1\n}\n\nBuffer.prototype.includes = function includes (val, byteOffset, encoding) {\n  return this.indexOf(val, byteOffset, encoding) !== -1\n}\n\nBuffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {\n  return bidirectionalIndexOf(this, val, byteOffset, encoding, true)\n}\n\nBuffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {\n  return bidirectionalIndexOf(this, val, byteOffset, encoding, false)\n}\n\nfunction hexWrite (buf, string, offset, length) {\n  offset = Number(offset) || 0\n  var remaining = buf.length - offset\n  if (!length) {\n    length = remaining\n  } else {\n    length = Number(length)\n    if (length > remaining) {\n      length = remaining\n    }\n  }\n\n  var strLen = string.length\n\n  if (length > strLen / 2) {\n    length = strLen / 2\n  }\n  for (var i = 0; i < length; ++i) {\n    var parsed = parseInt(string.substr(i * 2, 2), 16)\n    if (numberIsNaN(parsed)) return i\n    buf[offset + i] = parsed\n  }\n  return i\n}\n\nfunction utf8Write (buf, string, offset, length) {\n  return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)\n}\n\nfunction asciiWrite (buf, string, offset, length) {\n  return blitBuffer(asciiToBytes(string), buf, offset, length)\n}\n\nfunction latin1Write (buf, string, offset, length) {\n  return asciiWrite(buf, string, offset, length)\n}\n\nfunction base64Write (buf, string, offset, length) {\n  return blitBuffer(base64ToBytes(string), buf, offset, length)\n}\n\nfunction ucs2Write (buf, string, offset, length) {\n  return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)\n}\n\nBuffer.prototype.write = function write (string, offset, length, encoding) {\n  // Buffer#write(string)\n  if (offset === undefined) {\n    encoding = 'utf8'\n    length = this.length\n    offset = 0\n  // Buffer#write(string, encoding)\n  } else if (length === undefined && typeof offset === 'string') {\n    encoding = offset\n    length = this.length\n    offset = 0\n  // Buffer#write(string, offset[, length][, encoding])\n  } else if (isFinite(offset)) {\n    offset = offset >>> 0\n    if (isFinite(length)) {\n      length = length >>> 0\n      if (encoding === undefined) encoding = 'utf8'\n    } else {\n      encoding = length\n      length = undefined\n    }\n  } else {\n    throw new Error(\n      'Buffer.write(string, encoding, offset[, length]) is no longer supported'\n    )\n  }\n\n  var remaining = this.length - offset\n  if (length === undefined || length > remaining) length = remaining\n\n  if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {\n    throw new RangeError('Attempt to write outside buffer bounds')\n  }\n\n  if (!encoding) encoding = 'utf8'\n\n  var loweredCase = false\n  for (;;) {\n    switch (encoding) {\n      case 'hex':\n        return hexWrite(this, string, offset, length)\n\n      case 'utf8':\n      case 'utf-8':\n        return utf8Write(this, string, offset, length)\n\n      case 'ascii':\n        return asciiWrite(this, string, offset, length)\n\n      case 'latin1':\n      case 'binary':\n        return latin1Write(this, string, offset, length)\n\n      case 'base64':\n        // Warning: maxLength not taken into account in base64Write\n        return base64Write(this, string, offset, length)\n\n      case 'ucs2':\n      case 'ucs-2':\n      case 'utf16le':\n      case 'utf-16le':\n        return ucs2Write(this, string, offset, length)\n\n      default:\n        if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)\n        encoding = ('' + encoding).toLowerCase()\n        loweredCase = true\n    }\n  }\n}\n\nBuffer.prototype.toJSON = function toJSON () {\n  return {\n    type: 'Buffer',\n    data: Array.prototype.slice.call(this._arr || this, 0)\n  }\n}\n\nfunction base64Slice (buf, start, end) {\n  if (start === 0 && end === buf.length) {\n    return base64.fromByteArray(buf)\n  } else {\n    return base64.fromByteArray(buf.slice(start, end))\n  }\n}\n\nfunction utf8Slice (buf, start, end) {\n  end = Math.min(buf.length, end)\n  var res = []\n\n  var i = start\n  while (i < end) {\n    var firstByte = buf[i]\n    var codePoint = null\n    var bytesPerSequence = (firstByte > 0xEF) ? 4\n      : (firstByte > 0xDF) ? 3\n        : (firstByte > 0xBF) ? 2\n          : 1\n\n    if (i + bytesPerSequence <= end) {\n      var secondByte, thirdByte, fourthByte, tempCodePoint\n\n      switch (bytesPerSequence) {\n        case 1:\n          if (firstByte < 0x80) {\n            codePoint = firstByte\n          }\n          break\n        case 2:\n          secondByte = buf[i + 1]\n          if ((secondByte & 0xC0) === 0x80) {\n            tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)\n            if (tempCodePoint > 0x7F) {\n              codePoint = tempCodePoint\n            }\n          }\n          break\n        case 3:\n          secondByte = buf[i + 1]\n          thirdByte = buf[i + 2]\n          if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {\n            tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)\n            if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {\n              codePoint = tempCodePoint\n            }\n          }\n          break\n        case 4:\n          secondByte = buf[i + 1]\n          thirdByte = buf[i + 2]\n          fourthByte = buf[i + 3]\n          if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {\n            tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)\n            if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {\n              codePoint = tempCodePoint\n            }\n          }\n      }\n    }\n\n    if (codePoint === null) {\n      // we did not generate a valid codePoint so insert a\n      // replacement char (U+FFFD) and advance only 1 byte\n      codePoint = 0xFFFD\n      bytesPerSequence = 1\n    } else if (codePoint > 0xFFFF) {\n      // encode to utf16 (surrogate pair dance)\n      codePoint -= 0x10000\n      res.push(codePoint >>> 10 & 0x3FF | 0xD800)\n      codePoint = 0xDC00 | codePoint & 0x3FF\n    }\n\n    res.push(codePoint)\n    i += bytesPerSequence\n  }\n\n  return decodeCodePointsArray(res)\n}\n\n// Based on http://stackoverflow.com/a/22747272/680742, the browser with\n// the lowest limit is Chrome, with 0x10000 args.\n// We go 1 magnitude less, for safety\nvar MAX_ARGUMENTS_LENGTH = 0x1000\n\nfunction decodeCodePointsArray (codePoints) {\n  var len = codePoints.length\n  if (len <= MAX_ARGUMENTS_LENGTH) {\n    return String.fromCharCode.apply(String, codePoints) // avoid extra slice()\n  }\n\n  // Decode in chunks to avoid \"call stack size exceeded\".\n  var res = ''\n  var i = 0\n  while (i < len) {\n    res += String.fromCharCode.apply(\n      String,\n      codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)\n    )\n  }\n  return res\n}\n\nfunction asciiSlice (buf, start, end) {\n  var ret = ''\n  end = Math.min(buf.length, end)\n\n  for (var i = start; i < end; ++i) {\n    ret += String.fromCharCode(buf[i] & 0x7F)\n  }\n  return ret\n}\n\nfunction latin1Slice (buf, start, end) {\n  var ret = ''\n  end = Math.min(buf.length, end)\n\n  for (var i = start; i < end; ++i) {\n    ret += String.fromCharCode(buf[i])\n  }\n  return ret\n}\n\nfunction hexSlice (buf, start, end) {\n  var len = buf.length\n\n  if (!start || start < 0) start = 0\n  if (!end || end < 0 || end > len) end = len\n\n  var out = ''\n  for (var i = start; i < end; ++i) {\n    out += toHex(buf[i])\n  }\n  return out\n}\n\nfunction utf16leSlice (buf, start, end) {\n  var bytes = buf.slice(start, end)\n  var res = ''\n  for (var i = 0; i < bytes.length; i += 2) {\n    res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))\n  }\n  return res\n}\n\nBuffer.prototype.slice = function slice (start, end) {\n  var len = this.length\n  start = ~~start\n  end = end === undefined ? len : ~~end\n\n  if (start < 0) {\n    start += len\n    if (start < 0) start = 0\n  } else if (start > len) {\n    start = len\n  }\n\n  if (end < 0) {\n    end += len\n    if (end < 0) end = 0\n  } else if (end > len) {\n    end = len\n  }\n\n  if (end < start) end = start\n\n  var newBuf = this.subarray(start, end)\n  // Return an augmented `Uint8Array` instance\n  newBuf.__proto__ = Buffer.prototype\n  return newBuf\n}\n\n/*\n * Need to make sure that buffer isn't trying to write out of bounds.\n */\nfunction checkOffset (offset, ext, length) {\n  if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')\n  if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')\n}\n\nBuffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {\n  offset = offset >>> 0\n  byteLength = byteLength >>> 0\n  if (!noAssert) checkOffset(offset, byteLength, this.length)\n\n  var val = this[offset]\n  var mul = 1\n  var i = 0\n  while (++i < byteLength && (mul *= 0x100)) {\n    val += this[offset + i] * mul\n  }\n\n  return val\n}\n\nBuffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {\n  offset = offset >>> 0\n  byteLength = byteLength >>> 0\n  if (!noAssert) {\n    checkOffset(offset, byteLength, this.length)\n  }\n\n  var val = this[offset + --byteLength]\n  var mul = 1\n  while (byteLength > 0 && (mul *= 0x100)) {\n    val += this[offset + --byteLength] * mul\n  }\n\n  return val\n}\n\nBuffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 1, this.length)\n  return this[offset]\n}\n\nBuffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 2, this.length)\n  return this[offset] | (this[offset + 1] << 8)\n}\n\nBuffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 2, this.length)\n  return (this[offset] << 8) | this[offset + 1]\n}\n\nBuffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 4, this.length)\n\n  return ((this[offset]) |\n      (this[offset + 1] << 8) |\n      (this[offset + 2] << 16)) +\n      (this[offset + 3] * 0x1000000)\n}\n\nBuffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 4, this.length)\n\n  return (this[offset] * 0x1000000) +\n    ((this[offset + 1] << 16) |\n    (this[offset + 2] << 8) |\n    this[offset + 3])\n}\n\nBuffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {\n  offset = offset >>> 0\n  byteLength = byteLength >>> 0\n  if (!noAssert) checkOffset(offset, byteLength, this.length)\n\n  var val = this[offset]\n  var mul = 1\n  var i = 0\n  while (++i < byteLength && (mul *= 0x100)) {\n    val += this[offset + i] * mul\n  }\n  mul *= 0x80\n\n  if (val >= mul) val -= Math.pow(2, 8 * byteLength)\n\n  return val\n}\n\nBuffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {\n  offset = offset >>> 0\n  byteLength = byteLength >>> 0\n  if (!noAssert) checkOffset(offset, byteLength, this.length)\n\n  var i = byteLength\n  var mul = 1\n  var val = this[offset + --i]\n  while (i > 0 && (mul *= 0x100)) {\n    val += this[offset + --i] * mul\n  }\n  mul *= 0x80\n\n  if (val >= mul) val -= Math.pow(2, 8 * byteLength)\n\n  return val\n}\n\nBuffer.prototype.readInt8 = function readInt8 (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 1, this.length)\n  if (!(this[offset] & 0x80)) return (this[offset])\n  return ((0xff - this[offset] + 1) * -1)\n}\n\nBuffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 2, this.length)\n  var val = this[offset] | (this[offset + 1] << 8)\n  return (val & 0x8000) ? val | 0xFFFF0000 : val\n}\n\nBuffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 2, this.length)\n  var val = this[offset + 1] | (this[offset] << 8)\n  return (val & 0x8000) ? val | 0xFFFF0000 : val\n}\n\nBuffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 4, this.length)\n\n  return (this[offset]) |\n    (this[offset + 1] << 8) |\n    (this[offset + 2] << 16) |\n    (this[offset + 3] << 24)\n}\n\nBuffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 4, this.length)\n\n  return (this[offset] << 24) |\n    (this[offset + 1] << 16) |\n    (this[offset + 2] << 8) |\n    (this[offset + 3])\n}\n\nBuffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 4, this.length)\n  return ieee754.read(this, offset, true, 23, 4)\n}\n\nBuffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 4, this.length)\n  return ieee754.read(this, offset, false, 23, 4)\n}\n\nBuffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 8, this.length)\n  return ieee754.read(this, offset, true, 52, 8)\n}\n\nBuffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {\n  offset = offset >>> 0\n  if (!noAssert) checkOffset(offset, 8, this.length)\n  return ieee754.read(this, offset, false, 52, 8)\n}\n\nfunction checkInt (buf, value, offset, ext, max, min) {\n  if (!Buffer.isBuffer(buf)) throw new TypeError('\"buffer\" argument must be a Buffer instance')\n  if (value > max || value < min) throw new RangeError('\"value\" argument is out of bounds')\n  if (offset + ext > buf.length) throw new RangeError('Index out of range')\n}\n\nBuffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  byteLength = byteLength >>> 0\n  if (!noAssert) {\n    var maxBytes = Math.pow(2, 8 * byteLength) - 1\n    checkInt(this, value, offset, byteLength, maxBytes, 0)\n  }\n\n  var mul = 1\n  var i = 0\n  this[offset] = value & 0xFF\n  while (++i < byteLength && (mul *= 0x100)) {\n    this[offset + i] = (value / mul) & 0xFF\n  }\n\n  return offset + byteLength\n}\n\nBuffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  byteLength = byteLength >>> 0\n  if (!noAssert) {\n    var maxBytes = Math.pow(2, 8 * byteLength) - 1\n    checkInt(this, value, offset, byteLength, maxBytes, 0)\n  }\n\n  var i = byteLength - 1\n  var mul = 1\n  this[offset + i] = value & 0xFF\n  while (--i >= 0 && (mul *= 0x100)) {\n    this[offset + i] = (value / mul) & 0xFF\n  }\n\n  return offset + byteLength\n}\n\nBuffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)\n  this[offset] = (value & 0xff)\n  return offset + 1\n}\n\nBuffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)\n  this[offset] = (value & 0xff)\n  this[offset + 1] = (value >>> 8)\n  return offset + 2\n}\n\nBuffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)\n  this[offset] = (value >>> 8)\n  this[offset + 1] = (value & 0xff)\n  return offset + 2\n}\n\nBuffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)\n  this[offset + 3] = (value >>> 24)\n  this[offset + 2] = (value >>> 16)\n  this[offset + 1] = (value >>> 8)\n  this[offset] = (value & 0xff)\n  return offset + 4\n}\n\nBuffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)\n  this[offset] = (value >>> 24)\n  this[offset + 1] = (value >>> 16)\n  this[offset + 2] = (value >>> 8)\n  this[offset + 3] = (value & 0xff)\n  return offset + 4\n}\n\nBuffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) {\n    var limit = Math.pow(2, (8 * byteLength) - 1)\n\n    checkInt(this, value, offset, byteLength, limit - 1, -limit)\n  }\n\n  var i = 0\n  var mul = 1\n  var sub = 0\n  this[offset] = value & 0xFF\n  while (++i < byteLength && (mul *= 0x100)) {\n    if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {\n      sub = 1\n    }\n    this[offset + i] = ((value / mul) >> 0) - sub & 0xFF\n  }\n\n  return offset + byteLength\n}\n\nBuffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) {\n    var limit = Math.pow(2, (8 * byteLength) - 1)\n\n    checkInt(this, value, offset, byteLength, limit - 1, -limit)\n  }\n\n  var i = byteLength - 1\n  var mul = 1\n  var sub = 0\n  this[offset + i] = value & 0xFF\n  while (--i >= 0 && (mul *= 0x100)) {\n    if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {\n      sub = 1\n    }\n    this[offset + i] = ((value / mul) >> 0) - sub & 0xFF\n  }\n\n  return offset + byteLength\n}\n\nBuffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)\n  if (value < 0) value = 0xff + value + 1\n  this[offset] = (value & 0xff)\n  return offset + 1\n}\n\nBuffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)\n  this[offset] = (value & 0xff)\n  this[offset + 1] = (value >>> 8)\n  return offset + 2\n}\n\nBuffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)\n  this[offset] = (value >>> 8)\n  this[offset + 1] = (value & 0xff)\n  return offset + 2\n}\n\nBuffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)\n  this[offset] = (value & 0xff)\n  this[offset + 1] = (value >>> 8)\n  this[offset + 2] = (value >>> 16)\n  this[offset + 3] = (value >>> 24)\n  return offset + 4\n}\n\nBuffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)\n  if (value < 0) value = 0xffffffff + value + 1\n  this[offset] = (value >>> 24)\n  this[offset + 1] = (value >>> 16)\n  this[offset + 2] = (value >>> 8)\n  this[offset + 3] = (value & 0xff)\n  return offset + 4\n}\n\nfunction checkIEEE754 (buf, value, offset, ext, max, min) {\n  if (offset + ext > buf.length) throw new RangeError('Index out of range')\n  if (offset < 0) throw new RangeError('Index out of range')\n}\n\nfunction writeFloat (buf, value, offset, littleEndian, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) {\n    checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)\n  }\n  ieee754.write(buf, value, offset, littleEndian, 23, 4)\n  return offset + 4\n}\n\nBuffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {\n  return writeFloat(this, value, offset, true, noAssert)\n}\n\nBuffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {\n  return writeFloat(this, value, offset, false, noAssert)\n}\n\nfunction writeDouble (buf, value, offset, littleEndian, noAssert) {\n  value = +value\n  offset = offset >>> 0\n  if (!noAssert) {\n    checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)\n  }\n  ieee754.write(buf, value, offset, littleEndian, 52, 8)\n  return offset + 8\n}\n\nBuffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {\n  return writeDouble(this, value, offset, true, noAssert)\n}\n\nBuffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {\n  return writeDouble(this, value, offset, false, noAssert)\n}\n\n// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)\nBuffer.prototype.copy = function copy (target, targetStart, start, end) {\n  if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')\n  if (!start) start = 0\n  if (!end && end !== 0) end = this.length\n  if (targetStart >= target.length) targetStart = target.length\n  if (!targetStart) targetStart = 0\n  if (end > 0 && end < start) end = start\n\n  // Copy 0 bytes; we're done\n  if (end === start) return 0\n  if (target.length === 0 || this.length === 0) return 0\n\n  // Fatal error conditions\n  if (targetStart < 0) {\n    throw new RangeError('targetStart out of bounds')\n  }\n  if (start < 0 || start >= this.length) throw new RangeError('Index out of range')\n  if (end < 0) throw new RangeError('sourceEnd out of bounds')\n\n  // Are we oob?\n  if (end > this.length) end = this.length\n  if (target.length - targetStart < end - start) {\n    end = target.length - targetStart + start\n  }\n\n  var len = end - start\n\n  if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {\n    // Use built-in when available, missing from IE11\n    this.copyWithin(targetStart, start, end)\n  } else if (this === target && start < targetStart && targetStart < end) {\n    // descending copy from end\n    for (var i = len - 1; i >= 0; --i) {\n      target[i + targetStart] = this[i + start]\n    }\n  } else {\n    Uint8Array.prototype.set.call(\n      target,\n      this.subarray(start, end),\n      targetStart\n    )\n  }\n\n  return len\n}\n\n// Usage:\n//    buffer.fill(number[, offset[, end]])\n//    buffer.fill(buffer[, offset[, end]])\n//    buffer.fill(string[, offset[, end]][, encoding])\nBuffer.prototype.fill = function fill (val, start, end, encoding) {\n  // Handle string cases:\n  if (typeof val === 'string') {\n    if (typeof start === 'string') {\n      encoding = start\n      start = 0\n      end = this.length\n    } else if (typeof end === 'string') {\n      encoding = end\n      end = this.length\n    }\n    if (encoding !== undefined && typeof encoding !== 'string') {\n      throw new TypeError('encoding must be a string')\n    }\n    if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {\n      throw new TypeError('Unknown encoding: ' + encoding)\n    }\n    if (val.length === 1) {\n      var code = val.charCodeAt(0)\n      if ((encoding === 'utf8' && code < 128) ||\n          encoding === 'latin1') {\n        // Fast path: If `val` fits into a single byte, use that numeric value.\n        val = code\n      }\n    }\n  } else if (typeof val === 'number') {\n    val = val & 255\n  }\n\n  // Invalid ranges are not set to a default, so can range check early.\n  if (start < 0 || this.length < start || this.length < end) {\n    throw new RangeError('Out of range index')\n  }\n\n  if (end <= start) {\n    return this\n  }\n\n  start = start >>> 0\n  end = end === undefined ? this.length : end >>> 0\n\n  if (!val) val = 0\n\n  var i\n  if (typeof val === 'number') {\n    for (i = start; i < end; ++i) {\n      this[i] = val\n    }\n  } else {\n    var bytes = Buffer.isBuffer(val)\n      ? val\n      : Buffer.from(val, encoding)\n    var len = bytes.length\n    if (len === 0) {\n      throw new TypeError('The value \"' + val +\n        '\" is invalid for argument \"value\"')\n    }\n    for (i = 0; i < end - start; ++i) {\n      this[i + start] = bytes[i % len]\n    }\n  }\n\n  return this\n}\n\n// HELPER FUNCTIONS\n// ================\n\nvar INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g\n\nfunction base64clean (str) {\n  // Node takes equal signs as end of the Base64 encoding\n  str = str.split('=')[0]\n  // Node strips out invalid characters like \\n and \\t from the string, base64-js does not\n  str = str.trim().replace(INVALID_BASE64_RE, '')\n  // Node converts strings with length < 2 to ''\n  if (str.length < 2) return ''\n  // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not\n  while (str.length % 4 !== 0) {\n    str = str + '='\n  }\n  return str\n}\n\nfunction toHex (n) {\n  if (n < 16) return '0' + n.toString(16)\n  return n.toString(16)\n}\n\nfunction utf8ToBytes (string, units) {\n  units = units || Infinity\n  var codePoint\n  var length = string.length\n  var leadSurrogate = null\n  var bytes = []\n\n  for (var i = 0; i < length; ++i) {\n    codePoint = string.charCodeAt(i)\n\n    // is surrogate component\n    if (codePoint > 0xD7FF && codePoint < 0xE000) {\n      // last char was a lead\n      if (!leadSurrogate) {\n        // no lead yet\n        if (codePoint > 0xDBFF) {\n          // unexpected trail\n          if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)\n          continue\n        } else if (i + 1 === length) {\n          // unpaired lead\n          if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)\n          continue\n        }\n\n        // valid lead\n        leadSurrogate = codePoint\n\n        continue\n      }\n\n      // 2 leads in a row\n      if (codePoint < 0xDC00) {\n        if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)\n        leadSurrogate = codePoint\n        continue\n      }\n\n      // valid surrogate pair\n      codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000\n    } else if (leadSurrogate) {\n      // valid bmp char, but last char was a lead\n      if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)\n    }\n\n    leadSurrogate = null\n\n    // encode utf8\n    if (codePoint < 0x80) {\n      if ((units -= 1) < 0) break\n      bytes.push(codePoint)\n    } else if (codePoint < 0x800) {\n      if ((units -= 2) < 0) break\n      bytes.push(\n        codePoint >> 0x6 | 0xC0,\n        codePoint & 0x3F | 0x80\n      )\n    } else if (codePoint < 0x10000) {\n      if ((units -= 3) < 0) break\n      bytes.push(\n        codePoint >> 0xC | 0xE0,\n        codePoint >> 0x6 & 0x3F | 0x80,\n        codePoint & 0x3F | 0x80\n      )\n    } else if (codePoint < 0x110000) {\n      if ((units -= 4) < 0) break\n      bytes.push(\n        codePoint >> 0x12 | 0xF0,\n        codePoint >> 0xC & 0x3F | 0x80,\n        codePoint >> 0x6 & 0x3F | 0x80,\n        codePoint & 0x3F | 0x80\n      )\n    } else {\n      throw new Error('Invalid code point')\n    }\n  }\n\n  return bytes\n}\n\nfunction asciiToBytes (str) {\n  var byteArray = []\n  for (var i = 0; i < str.length; ++i) {\n    // Node's code seems to be doing this and not & 0x7F..\n    byteArray.push(str.charCodeAt(i) & 0xFF)\n  }\n  return byteArray\n}\n\nfunction utf16leToBytes (str, units) {\n  var c, hi, lo\n  var byteArray = []\n  for (var i = 0; i < str.length; ++i) {\n    if ((units -= 2) < 0) break\n\n    c = str.charCodeAt(i)\n    hi = c >> 8\n    lo = c % 256\n    byteArray.push(lo)\n    byteArray.push(hi)\n  }\n\n  return byteArray\n}\n\nfunction base64ToBytes (str) {\n  return base64.toByteArray(base64clean(str))\n}\n\nfunction blitBuffer (src, dst, offset, length) {\n  for (var i = 0; i < length; ++i) {\n    if ((i + offset >= dst.length) || (i >= src.length)) break\n    dst[i + offset] = src[i]\n  }\n  return i\n}\n\n// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass\n// the `instanceof` check but they should be treated as of that type.\n// See: https://github.com/feross/buffer/issues/166\nfunction isInstance (obj, type) {\n  return obj instanceof type ||\n    (obj != null && obj.constructor != null && obj.constructor.name != null &&\n      obj.constructor.name === type.name)\n}\nfunction numberIsNaN (obj) {\n  // For IE11 support\n  return obj !== obj // eslint-disable-line no-self-compare\n}\n\n}).call(this,_dereq_(\"buffer\").Buffer)\n},{\"base64-js\":74,\"buffer\":105,\"ieee754\":412}],106:[function(_dereq_,module,exports){\n'use strict'\n\nvar monotoneTriangulate = _dereq_('./lib/monotone')\nvar makeIndex = _dereq_('./lib/triangulation')\nvar delaunayFlip = _dereq_('./lib/delaunay')\nvar filterTriangulation = _dereq_('./lib/filter')\n\nmodule.exports = cdt2d\n\nfunction canonicalizeEdge(e) {\n  return [Math.min(e[0], e[1]), Math.max(e[0], e[1])]\n}\n\nfunction compareEdge(a, b) {\n  return a[0]-b[0] || a[1]-b[1]\n}\n\nfunction canonicalizeEdges(edges) {\n  return edges.map(canonicalizeEdge).sort(compareEdge)\n}\n\nfunction getDefault(options, property, dflt) {\n  if(property in options) {\n    return options[property]\n  }\n  return dflt\n}\n\nfunction cdt2d(points, edges, options) {\n\n  if(!Array.isArray(edges)) {\n    options = edges || {}\n    edges = []\n  } else {\n    options = options || {}\n    edges = edges || []\n  }\n\n  //Parse out options\n  var delaunay = !!getDefault(options, 'delaunay', true)\n  var interior = !!getDefault(options, 'interior', true)\n  var exterior = !!getDefault(options, 'exterior', true)\n  var infinity = !!getDefault(options, 'infinity', false)\n\n  //Handle trivial case\n  if((!interior && !exterior) || points.length === 0) {\n    return []\n  }\n\n  //Construct initial triangulation\n  var cells = monotoneTriangulate(points, edges)\n\n  //If delaunay refinement needed, then improve quality by edge flipping\n  if(delaunay || interior !== exterior || infinity) {\n\n    //Index all of the cells to support fast neighborhood queries\n    var triangulation = makeIndex(points.length, canonicalizeEdges(edges))\n    for(var i=0; i<cells.length; ++i) {\n      var f = cells[i]\n      triangulation.addTriangle(f[0], f[1], f[2])\n    }\n\n    //Run edge flipping\n    if(delaunay) {\n      delaunayFlip(points, triangulation)\n    }\n\n    //Filter points\n    if(!exterior) {\n      return filterTriangulation(triangulation, -1)\n    } else if(!interior) {\n      return filterTriangulation(triangulation,  1, infinity)\n    } else if(infinity) {\n      return filterTriangulation(triangulation, 0, infinity)\n    } else {\n      return triangulation.cells()\n    }\n    \n  } else {\n    return cells\n  }\n}\n\n},{\"./lib/delaunay\":107,\"./lib/filter\":108,\"./lib/monotone\":109,\"./lib/triangulation\":110}],107:[function(_dereq_,module,exports){\n'use strict'\n\nvar inCircle = _dereq_('robust-in-sphere')[4]\nvar bsearch = _dereq_('binary-search-bounds')\n\nmodule.exports = delaunayRefine\n\nfunction testFlip(points, triangulation, stack, a, b, x) {\n  var y = triangulation.opposite(a, b)\n\n  //Test boundary edge\n  if(y < 0) {\n    return\n  }\n\n  //Swap edge if order flipped\n  if(b < a) {\n    var tmp = a\n    a = b\n    b = tmp\n    tmp = x\n    x = y\n    y = tmp\n  }\n\n  //Test if edge is constrained\n  if(triangulation.isConstraint(a, b)) {\n    return\n  }\n\n  //Test if edge is delaunay\n  if(inCircle(points[a], points[b], points[x], points[y]) < 0) {\n    stack.push(a, b)\n  }\n}\n\n//Assume edges are sorted lexicographically\nfunction delaunayRefine(points, triangulation) {\n  var stack = []\n\n  var numPoints = points.length\n  var stars = triangulation.stars\n  for(var a=0; a<numPoints; ++a) {\n    var star = stars[a]\n    for(var j=1; j<star.length; j+=2) {\n      var b = star[j]\n\n      //If order is not consistent, then skip edge\n      if(b < a) {\n        continue\n      }\n\n      //Check if edge is constrained\n      if(triangulation.isConstraint(a, b)) {\n        continue\n      }\n\n      //Find opposite edge\n      var x = star[j-1], y = -1\n      for(var k=1; k<star.length; k+=2) {\n        if(star[k-1] === b) {\n          y = star[k]\n          break\n        }\n      }\n\n      //If this is a boundary edge, don't flip it\n      if(y < 0) {\n        continue\n      }\n\n      //If edge is in circle, flip it\n      if(inCircle(points[a], points[b], points[x], points[y]) < 0) {\n        stack.push(a, b)\n      }\n    }\n  }\n\n  while(stack.length > 0) {\n    var b = stack.pop()\n    var a = stack.pop()\n\n    //Find opposite pairs\n    var x = -1, y = -1\n    var star = stars[a]\n    for(var i=1; i<star.length; i+=2) {\n      var s = star[i-1]\n      var t = star[i]\n      if(s === b) {\n        y = t\n      } else if(t === b) {\n        x = s\n      }\n    }\n\n    //If x/y are both valid then skip edge\n    if(x < 0 || y < 0) {\n      continue\n    }\n\n    //If edge is now delaunay, then don't flip it\n    if(inCircle(points[a], points[b], points[x], points[y]) >= 0) {\n      continue\n    }\n\n    //Flip the edge\n    triangulation.flip(a, b)\n\n    //Test flipping neighboring edges\n    testFlip(points, triangulation, stack, x, a, y)\n    testFlip(points, triangulation, stack, a, y, x)\n    testFlip(points, triangulation, stack, y, b, x)\n    testFlip(points, triangulation, stack, b, x, y)\n  }\n}\n\n},{\"binary-search-bounds\":111,\"robust-in-sphere\":508}],108:[function(_dereq_,module,exports){\n'use strict'\n\nvar bsearch = _dereq_('binary-search-bounds')\n\nmodule.exports = classifyFaces\n\nfunction FaceIndex(cells, neighbor, constraint, flags, active, next, boundary) {\n  this.cells       = cells\n  this.neighbor    = neighbor\n  this.flags       = flags\n  this.constraint  = constraint\n  this.active      = active\n  this.next        = next\n  this.boundary    = boundary\n}\n\nvar proto = FaceIndex.prototype\n\nfunction compareCell(a, b) {\n  return a[0] - b[0] ||\n         a[1] - b[1] ||\n         a[2] - b[2]\n}\n\nproto.locate = (function() {\n  var key = [0,0,0]\n  return function(a, b, c) {\n    var x = a, y = b, z = c\n    if(b < c) {\n      if(b < a) {\n        x = b\n        y = c\n        z = a\n      }\n    } else if(c < a) {\n      x = c\n      y = a\n      z = b\n    }\n    if(x < 0) {\n      return -1\n    }\n    key[0] = x\n    key[1] = y\n    key[2] = z\n    return bsearch.eq(this.cells, key, compareCell)\n  }\n})()\n\nfunction indexCells(triangulation, infinity) {\n  //First get cells and canonicalize\n  var cells = triangulation.cells()\n  var nc = cells.length\n  for(var i=0; i<nc; ++i) {\n    var c = cells[i]\n    var x = c[0], y = c[1], z = c[2]\n    if(y < z) {\n      if(y < x) {\n        c[0] = y\n        c[1] = z\n        c[2] = x\n      }\n    } else if(z < x) {\n      c[0] = z\n      c[1] = x\n      c[2] = y\n    }\n  }\n  cells.sort(compareCell)\n\n  //Initialize flag array\n  var flags = new Array(nc)\n  for(var i=0; i<flags.length; ++i) {\n    flags[i] = 0\n  }\n\n  //Build neighbor index, initialize queues\n  var active = []\n  var next   = []\n  var neighbor = new Array(3*nc)\n  var constraint = new Array(3*nc)\n  var boundary = null\n  if(infinity) {\n    boundary = []\n  }\n  var index = new FaceIndex(\n    cells,\n    neighbor,\n    constraint,\n    flags,\n    active,\n    next,\n    boundary)\n  for(var i=0; i<nc; ++i) {\n    var c = cells[i]\n    for(var j=0; j<3; ++j) {\n      var x = c[j], y = c[(j+1)%3]\n      var a = neighbor[3*i+j] = index.locate(y, x, triangulation.opposite(y, x))\n      var b = constraint[3*i+j] = triangulation.isConstraint(x, y)\n      if(a < 0) {\n        if(b) {\n          next.push(i)\n        } else {\n          active.push(i)\n          flags[i] = 1\n        }\n        if(infinity) {\n          boundary.push([y, x, -1])\n        }\n      }\n    }\n  }\n  return index\n}\n\nfunction filterCells(cells, flags, target) {\n  var ptr = 0\n  for(var i=0; i<cells.length; ++i) {\n    if(flags[i] === target) {\n      cells[ptr++] = cells[i]\n    }\n  }\n  cells.length = ptr\n  return cells\n}\n\nfunction classifyFaces(triangulation, target, infinity) {\n  var index = indexCells(triangulation, infinity)\n\n  if(target === 0) {\n    if(infinity) {\n      return index.cells.concat(index.boundary)\n    } else {\n      return index.cells\n    }\n  }\n\n  var side = 1\n  var active = index.active\n  var next = index.next\n  var flags = index.flags\n  var cells = index.cells\n  var constraint = index.constraint\n  var neighbor = index.neighbor\n\n  while(active.length > 0 || next.length > 0) {\n    while(active.length > 0) {\n      var t = active.pop()\n      if(flags[t] === -side) {\n        continue\n      }\n      flags[t] = side\n      var c = cells[t]\n      for(var j=0; j<3; ++j) {\n        var f = neighbor[3*t+j]\n        if(f >= 0 && flags[f] === 0) {\n          if(constraint[3*t+j]) {\n            next.push(f)\n          } else {\n            active.push(f)\n            flags[f] = side\n          }\n        }\n      }\n    }\n\n    //Swap arrays and loop\n    var tmp = next\n    next = active\n    active = tmp\n    next.length = 0\n    side = -side\n  }\n\n  var result = filterCells(cells, flags, target)\n  if(infinity) {\n    return result.concat(index.boundary)\n  }\n  return result\n}\n\n},{\"binary-search-bounds\":111}],109:[function(_dereq_,module,exports){\n'use strict'\n\nvar bsearch = _dereq_('binary-search-bounds')\nvar orient = _dereq_('robust-orientation')[3]\n\nvar EVENT_POINT = 0\nvar EVENT_END   = 1\nvar EVENT_START = 2\n\nmodule.exports = monotoneTriangulate\n\n//A partial convex hull fragment, made of two unimonotone polygons\nfunction PartialHull(a, b, idx, lowerIds, upperIds) {\n  this.a = a\n  this.b = b\n  this.idx = idx\n  this.lowerIds = lowerIds\n  this.upperIds = upperIds\n}\n\n//An event in the sweep line procedure\nfunction Event(a, b, type, idx) {\n  this.a    = a\n  this.b    = b\n  this.type = type\n  this.idx  = idx\n}\n\n//This is used to compare events for the sweep line procedure\n// Points are:\n//  1. sorted lexicographically\n//  2. sorted by type  (point < end < start)\n//  3. segments sorted by winding order\n//  4. sorted by index\nfunction compareEvent(a, b) {\n  var d =\n    (a.a[0] - b.a[0]) ||\n    (a.a[1] - b.a[1]) ||\n    (a.type - b.type)\n  if(d) { return d }\n  if(a.type !== EVENT_POINT) {\n    d = orient(a.a, a.b, b.b)\n    if(d) { return d }\n  }\n  return a.idx - b.idx\n}\n\nfunction testPoint(hull, p) {\n  return orient(hull.a, hull.b, p)\n}\n\nfunction addPoint(cells, hulls, points, p, idx) {\n  var lo = bsearch.lt(hulls, p, testPoint)\n  var hi = bsearch.gt(hulls, p, testPoint)\n  for(var i=lo; i<hi; ++i) {\n    var hull = hulls[i]\n\n    //Insert p into lower hull\n    var lowerIds = hull.lowerIds\n    var m = lowerIds.length\n    while(m > 1 && orient(\n        points[lowerIds[m-2]],\n        points[lowerIds[m-1]],\n        p) > 0) {\n      cells.push(\n        [lowerIds[m-1],\n         lowerIds[m-2],\n         idx])\n      m -= 1\n    }\n    lowerIds.length = m\n    lowerIds.push(idx)\n\n    //Insert p into upper hull\n    var upperIds = hull.upperIds\n    var m = upperIds.length\n    while(m > 1 && orient(\n        points[upperIds[m-2]],\n        points[upperIds[m-1]],\n        p) < 0) {\n      cells.push(\n        [upperIds[m-2],\n         upperIds[m-1],\n         idx])\n      m -= 1\n    }\n    upperIds.length = m\n    upperIds.push(idx)\n  }\n}\n\nfunction findSplit(hull, edge) {\n  var d\n  if(hull.a[0] < edge.a[0]) {\n    d = orient(hull.a, hull.b, edge.a)\n  } else {\n    d = orient(edge.b, edge.a, hull.a)\n  }\n  if(d) { return d }\n  if(edge.b[0] < hull.b[0]) {\n    d = orient(hull.a, hull.b, edge.b)\n  } else {\n    d = orient(edge.b, edge.a, hull.b)\n  }\n  return d || hull.idx - edge.idx\n}\n\nfunction splitHulls(hulls, points, event) {\n  var splitIdx = bsearch.le(hulls, event, findSplit)\n  var hull = hulls[splitIdx]\n  var upperIds = hull.upperIds\n  var x = upperIds[upperIds.length-1]\n  hull.upperIds = [x]\n  hulls.splice(splitIdx+1, 0,\n    new PartialHull(event.a, event.b, event.idx, [x], upperIds))\n}\n\n\nfunction mergeHulls(hulls, points, event) {\n  //Swap pointers for merge search\n  var tmp = event.a\n  event.a = event.b\n  event.b = tmp\n  var mergeIdx = bsearch.eq(hulls, event, findSplit)\n  var upper = hulls[mergeIdx]\n  var lower = hulls[mergeIdx-1]\n  lower.upperIds = upper.upperIds\n  hulls.splice(mergeIdx, 1)\n}\n\n\nfunction monotoneTriangulate(points, edges) {\n\n  var numPoints = points.length\n  var numEdges = edges.length\n\n  var events = []\n\n  //Create point events\n  for(var i=0; i<numPoints; ++i) {\n    events.push(new Event(\n      points[i],\n      null,\n      EVENT_POINT,\n      i))\n  }\n\n  //Create edge events\n  for(var i=0; i<numEdges; ++i) {\n    var e = edges[i]\n    var a = points[e[0]]\n    var b = points[e[1]]\n    if(a[0] < b[0]) {\n      events.push(\n        new Event(a, b, EVENT_START, i),\n        new Event(b, a, EVENT_END, i))\n    } else if(a[0] > b[0]) {\n      events.push(\n        new Event(b, a, EVENT_START, i),\n        new Event(a, b, EVENT_END, i))\n    }\n  }\n\n  //Sort events\n  events.sort(compareEvent)\n\n  //Initialize hull\n  var minX = events[0].a[0] - (1 + Math.abs(events[0].a[0])) * Math.pow(2, -52)\n  var hull = [ new PartialHull([minX, 1], [minX, 0], -1, [], [], [], []) ]\n\n  //Process events in order\n  var cells = []\n  for(var i=0, numEvents=events.length; i<numEvents; ++i) {\n    var event = events[i]\n    var type = event.type\n    if(type === EVENT_POINT) {\n      addPoint(cells, hull, points, event.a, event.idx)\n    } else if(type === EVENT_START) {\n      splitHulls(hull, points, event)\n    } else {\n      mergeHulls(hull, points, event)\n    }\n  }\n\n  //Return triangulation\n  return cells\n}\n\n},{\"binary-search-bounds\":111,\"robust-orientation\":510}],110:[function(_dereq_,module,exports){\n'use strict'\n\nvar bsearch = _dereq_('binary-search-bounds')\n\nmodule.exports = createTriangulation\n\nfunction Triangulation(stars, edges) {\n  this.stars = stars\n  this.edges = edges\n}\n\nvar proto = Triangulation.prototype\n\nfunction removePair(list, j, k) {\n  for(var i=1, n=list.length; i<n; i+=2) {\n    if(list[i-1] === j && list[i] === k) {\n      list[i-1] = list[n-2]\n      list[i] = list[n-1]\n      list.length = n - 2\n      return\n    }\n  }\n}\n\nproto.isConstraint = (function() {\n  var e = [0,0]\n  function compareLex(a, b) {\n    return a[0] - b[0] || a[1] - b[1]\n  }\n  return function(i, j) {\n    e[0] = Math.min(i,j)\n    e[1] = Math.max(i,j)\n    return bsearch.eq(this.edges, e, compareLex) >= 0\n  }\n})()\n\nproto.removeTriangle = function(i, j, k) {\n  var stars = this.stars\n  removePair(stars[i], j, k)\n  removePair(stars[j], k, i)\n  removePair(stars[k], i, j)\n}\n\nproto.addTriangle = function(i, j, k) {\n  var stars = this.stars\n  stars[i].push(j, k)\n  stars[j].push(k, i)\n  stars[k].push(i, j)\n}\n\nproto.opposite = function(j, i) {\n  var list = this.stars[i]\n  for(var k=1, n=list.length; k<n; k+=2) {\n    if(list[k] === j) {\n      return list[k-1]\n    }\n  }\n  return -1\n}\n\nproto.flip = function(i, j) {\n  var a = this.opposite(i, j)\n  var b = this.opposite(j, i)\n  this.removeTriangle(i, j, a)\n  this.removeTriangle(j, i, b)\n  this.addTriangle(i, b, a)\n  this.addTriangle(j, a, b)\n}\n\nproto.edges = function() {\n  var stars = this.stars\n  var result = []\n  for(var i=0, n=stars.length; i<n; ++i) {\n    var list = stars[i]\n    for(var j=0, m=list.length; j<m; j+=2) {\n      result.push([list[j], list[j+1]])\n    }\n  }\n  return result\n}\n\nproto.cells = function() {\n  var stars = this.stars\n  var result = []\n  for(var i=0, n=stars.length; i<n; ++i) {\n    var list = stars[i]\n    for(var j=0, m=list.length; j<m; j+=2) {\n      var s = list[j]\n      var t = list[j+1]\n      if(i < Math.min(s, t)) {\n        result.push([i, s, t])\n      }\n    }\n  }\n  return result\n}\n\nfunction createTriangulation(numVerts, edges) {\n  var stars = new Array(numVerts)\n  for(var i=0; i<numVerts; ++i) {\n    stars[i] = []\n  }\n  return new Triangulation(stars, edges)\n}\n\n},{\"binary-search-bounds\":111}],111:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction compileSearch(funcName, predicate, reversed, extraArgs, earlyOut) {\n  var code = [\n    \"function \", funcName, \"(a,l,h,\", extraArgs.join(\",\"),  \"){\",\n    earlyOut ? \"\" : \"var i=\", (reversed ? \"l-1\" : \"h+1\"),\n    \";while(l<=h){var m=(l+h)>>>1,x=a[m]\"]\n  if(earlyOut) {\n    if(predicate.indexOf(\"c\") < 0) {\n      code.push(\";if(x===y){return m}else if(x<=y){\")\n    } else {\n      code.push(\";var p=c(x,y);if(p===0){return m}else if(p<=0){\")\n    }\n  } else {\n    code.push(\";if(\", predicate, \"){i=m;\")\n  }\n  if(reversed) {\n    code.push(\"l=m+1}else{h=m-1}\")\n  } else {\n    code.push(\"h=m-1}else{l=m+1}\")\n  }\n  code.push(\"}\")\n  if(earlyOut) {\n    code.push(\"return -1};\")\n  } else {\n    code.push(\"return i};\")\n  }\n  return code.join(\"\")\n}\n\nfunction compileBoundsSearch(predicate, reversed, suffix, earlyOut) {\n  var result = new Function([\n  compileSearch(\"A\", \"x\" + predicate + \"y\", reversed, [\"y\"], earlyOut),\n  compileSearch(\"P\", \"c(x,y)\" + predicate + \"0\", reversed, [\"y\", \"c\"], earlyOut),\n\"function dispatchBsearch\", suffix, \"(a,y,c,l,h){\\\nif(typeof(c)==='function'){\\\nreturn P(a,(l===void 0)?0:l|0,(h===void 0)?a.length-1:h|0,y,c)\\\n}else{\\\nreturn A(a,(c===void 0)?0:c|0,(l===void 0)?a.length-1:l|0,y)\\\n}}\\\nreturn dispatchBsearch\", suffix].join(\"\"))\n  return result()\n}\n\nmodule.exports = {\n  ge: compileBoundsSearch(\">=\", false,  \"GE\"),\n  gt: compileBoundsSearch(\">\",  false,  \"GT\"),\n  lt: compileBoundsSearch(\"<\",  true,   \"LT\"),\n  le: compileBoundsSearch(\"<=\", true,   \"LE\"),\n  eq: compileBoundsSearch(\"-\",  true,   \"EQ\", true)\n}\n\n},{}],112:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = orientation\n\nfunction orientation(s) {\n  var p = 1\n  for(var i=1; i<s.length; ++i) {\n    for(var j=0; j<i; ++j) {\n      if(s[i] < s[j]) {\n        p = -p\n      } else if(s[j] === s[i]) {\n        return 0\n      }\n    }\n  }\n  return p\n}\n\n},{}],113:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar dup = _dereq_(\"dup\")\nvar solve = _dereq_(\"robust-linear-solve\")\n\nfunction dot(a, b) {\n  var s = 0.0\n  var d = a.length\n  for(var i=0; i<d; ++i) {\n    s += a[i] * b[i]\n  }\n  return s\n}\n\nfunction barycentricCircumcenter(points) {\n  var N = points.length\n  if(N === 0) {\n    return []\n  }\n  \n  var D = points[0].length\n  var A = dup([points.length+1, points.length+1], 1.0)\n  var b = dup([points.length+1], 1.0)\n  A[N][N] = 0.0\n  for(var i=0; i<N; ++i) {\n    for(var j=0; j<=i; ++j) {\n      A[j][i] = A[i][j] = 2.0 * dot(points[i], points[j])\n    }\n    b[i] = dot(points[i], points[i])\n  }\n  var x = solve(A, b)\n\n  var denom = 0.0\n  var h = x[N+1]\n  for(var i=0; i<h.length; ++i) {\n    denom += h[i]\n  }\n\n  var y = new Array(N)\n  for(var i=0; i<N; ++i) {\n    var h = x[i]\n    var numer = 0.0\n    for(var j=0; j<h.length; ++j) {\n      numer += h[j]\n    }\n    y[i] =  numer / denom\n  }\n\n  return y\n}\n\nfunction circumcenter(points) {\n  if(points.length === 0) {\n    return []\n  }\n  var D = points[0].length\n  var result = dup([D])\n  var weights = barycentricCircumcenter(points)\n  for(var i=0; i<points.length; ++i) {\n    for(var j=0; j<D; ++j) {\n      result[j] += points[i][j] * weights[i]\n    }\n  }\n  return result\n}\n\ncircumcenter.barycenetric = barycentricCircumcenter\nmodule.exports = circumcenter\n},{\"dup\":170,\"robust-linear-solve\":509}],114:[function(_dereq_,module,exports){\nmodule.exports = circumradius\n\nvar circumcenter = _dereq_('circumcenter')\n\nfunction circumradius(points) {\n  var center = circumcenter(points)\n  var avgDist = 0.0\n  for(var i=0; i<points.length; ++i) {\n    var p = points[i]\n    for(var j=0; j<center.length; ++j) {\n      avgDist += Math.pow(p[j] - center[j], 2)\n    }\n  }\n  return Math.sqrt(avgDist / points.length)\n}\n},{\"circumcenter\":113}],115:[function(_dereq_,module,exports){\nmodule.exports = clamp\n\nfunction clamp(value, min, max) {\n  return min < max\n    ? (value < min ? min : value > max ? max : value)\n    : (value < max ? max : value > min ? min : value)\n}\n\n},{}],116:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = cleanPSLG\n\nvar UnionFind = _dereq_('union-find')\nvar boxIntersect = _dereq_('box-intersect')\nvar segseg = _dereq_('robust-segment-intersect')\nvar rat = _dereq_('big-rat')\nvar ratCmp = _dereq_('big-rat/cmp')\nvar ratToFloat = _dereq_('big-rat/to-float')\nvar ratVec = _dereq_('rat-vec')\nvar nextafter = _dereq_('nextafter')\n\nvar solveIntersection = _dereq_('./lib/rat-seg-intersect')\n\n// Bounds on a rational number when rounded to a float\nfunction boundRat (r) {\n  var f = ratToFloat(r)\n  return [\n    nextafter(f, -Infinity),\n    nextafter(f, Infinity)\n  ]\n}\n\n// Convert a list of edges in a pslg to bounding boxes\nfunction boundEdges (points, edges) {\n  var bounds = new Array(edges.length)\n  for (var i = 0; i < edges.length; ++i) {\n    var e = edges[i]\n    var a = points[e[0]]\n    var b = points[e[1]]\n    bounds[i] = [\n      nextafter(Math.min(a[0], b[0]), -Infinity),\n      nextafter(Math.min(a[1], b[1]), -Infinity),\n      nextafter(Math.max(a[0], b[0]), Infinity),\n      nextafter(Math.max(a[1], b[1]), Infinity)\n    ]\n  }\n  return bounds\n}\n\n// Convert a list of points into bounding boxes by duplicating coords\nfunction boundPoints (points) {\n  var bounds = new Array(points.length)\n  for (var i = 0; i < points.length; ++i) {\n    var p = points[i]\n    bounds[i] = [\n      nextafter(p[0], -Infinity),\n      nextafter(p[1], -Infinity),\n      nextafter(p[0], Infinity),\n      nextafter(p[1], Infinity)\n    ]\n  }\n  return bounds\n}\n\n// Find all pairs of crossing edges in a pslg (given edge bounds)\nfunction getCrossings (points, edges, edgeBounds) {\n  var result = []\n  boxIntersect(edgeBounds, function (i, j) {\n    var e = edges[i]\n    var f = edges[j]\n    if (e[0] === f[0] || e[0] === f[1] ||\n      e[1] === f[0] || e[1] === f[1]) {\n      return\n    }\n    var a = points[e[0]]\n    var b = points[e[1]]\n    var c = points[f[0]]\n    var d = points[f[1]]\n    if (segseg(a, b, c, d)) {\n      result.push([i, j])\n    }\n  })\n  return result\n}\n\n// Find all pairs of crossing vertices in a pslg (given edge/vert bounds)\nfunction getTJunctions (points, edges, edgeBounds, vertBounds) {\n  var result = []\n  boxIntersect(edgeBounds, vertBounds, function (i, v) {\n    var e = edges[i]\n    if (e[0] === v || e[1] === v) {\n      return\n    }\n    var p = points[v]\n    var a = points[e[0]]\n    var b = points[e[1]]\n    if (segseg(a, b, p, p)) {\n      result.push([i, v])\n    }\n  })\n  return result\n}\n\n// Cut edges along crossings/tjunctions\nfunction cutEdges (floatPoints, edges, crossings, junctions, useColor) {\n  var i, e\n\n  // Convert crossings into tjunctions by constructing rational points\n  var ratPoints = floatPoints.map(function(p) {\n      return [\n          rat(p[0]),\n          rat(p[1])\n      ]\n  })\n  for (i = 0; i < crossings.length; ++i) {\n    var crossing = crossings[i]\n    e = crossing[0]\n    var f = crossing[1]\n    var ee = edges[e]\n    var ef = edges[f]\n    var x = solveIntersection(\n      ratVec(floatPoints[ee[0]]),\n      ratVec(floatPoints[ee[1]]),\n      ratVec(floatPoints[ef[0]]),\n      ratVec(floatPoints[ef[1]]))\n    if (!x) {\n      // Segments are parallel, should already be handled by t-junctions\n      continue\n    }\n    var idx = floatPoints.length\n    floatPoints.push([ratToFloat(x[0]), ratToFloat(x[1])])\n    ratPoints.push(x)\n    junctions.push([e, idx], [f, idx])\n  }\n\n  // Sort tjunctions\n  junctions.sort(function (a, b) {\n    if (a[0] !== b[0]) {\n      return a[0] - b[0]\n    }\n    var u = ratPoints[a[1]]\n    var v = ratPoints[b[1]]\n    return ratCmp(u[0], v[0]) || ratCmp(u[1], v[1])\n  })\n\n  // Split edges along junctions\n  for (i = junctions.length - 1; i >= 0; --i) {\n    var junction = junctions[i]\n    e = junction[0]\n\n    var edge = edges[e]\n    var s = edge[0]\n    var t = edge[1]\n\n    // Check if edge is not lexicographically sorted\n    var a = floatPoints[s]\n    var b = floatPoints[t]\n    if (((a[0] - b[0]) || (a[1] - b[1])) < 0) {\n      var tmp = s\n      s = t\n      t = tmp\n    }\n\n    // Split leading edge\n    edge[0] = s\n    var last = edge[1] = junction[1]\n\n    // If we are grouping edges by color, remember to track data\n    var color\n    if (useColor) {\n      color = edge[2]\n    }\n\n    // Split other edges\n    while (i > 0 && junctions[i - 1][0] === e) {\n      var junction = junctions[--i]\n      var next = junction[1]\n      if (useColor) {\n        edges.push([last, next, color])\n      } else {\n        edges.push([last, next])\n      }\n      last = next\n    }\n\n    // Add final edge\n    if (useColor) {\n      edges.push([last, t, color])\n    } else {\n      edges.push([last, t])\n    }\n  }\n\n  // Return constructed rational points\n  return ratPoints\n}\n\n// Merge overlapping points\nfunction dedupPoints (floatPoints, ratPoints, floatBounds) {\n  var numPoints = ratPoints.length\n  var uf = new UnionFind(numPoints)\n\n  // Compute rational bounds\n  var bounds = []\n  for (var i = 0; i < ratPoints.length; ++i) {\n    var p = ratPoints[i]\n    var xb = boundRat(p[0])\n    var yb = boundRat(p[1])\n    bounds.push([\n      nextafter(xb[0], -Infinity),\n      nextafter(yb[0], -Infinity),\n      nextafter(xb[1], Infinity),\n      nextafter(yb[1], Infinity)\n    ])\n  }\n\n  // Link all points with over lapping boxes\n  boxIntersect(bounds, function (i, j) {\n    uf.link(i, j)\n  })\n\n  // Do 1 pass over points to combine points in label sets\n  var noDupes = true\n  var labels = new Array(numPoints)\n  for (var i = 0; i < numPoints; ++i) {\n    var j = uf.find(i)\n    if (j !== i) {\n      // Clear no-dupes flag, zero out label\n      noDupes = false\n      // Make each point the top-left point from its cell\n      floatPoints[j] = [\n        Math.min(floatPoints[i][0], floatPoints[j][0]),\n        Math.min(floatPoints[i][1], floatPoints[j][1])\n      ]\n    }\n  }\n\n  // If no duplicates, return null to signal termination\n  if (noDupes) {\n    return null\n  }\n\n  var ptr = 0\n  for (var i = 0; i < numPoints; ++i) {\n    var j = uf.find(i)\n    if (j === i) {\n      labels[i] = ptr\n      floatPoints[ptr++] = floatPoints[i]\n    } else {\n      labels[i] = -1\n    }\n  }\n\n  floatPoints.length = ptr\n\n  // Do a second pass to fix up missing labels\n  for (var i = 0; i < numPoints; ++i) {\n    if (labels[i] < 0) {\n      labels[i] = labels[uf.find(i)]\n    }\n  }\n\n  // Return resulting union-find data structure\n  return labels\n}\n\nfunction compareLex2 (a, b) { return (a[0] - b[0]) || (a[1] - b[1]) }\nfunction compareLex3 (a, b) {\n  var d = (a[0] - b[0]) || (a[1] - b[1])\n  if (d) {\n    return d\n  }\n  if (a[2] < b[2]) {\n    return -1\n  } else if (a[2] > b[2]) {\n    return 1\n  }\n  return 0\n}\n\n// Remove duplicate edge labels\nfunction dedupEdges (edges, labels, useColor) {\n  if (edges.length === 0) {\n    return\n  }\n  if (labels) {\n    for (var i = 0; i < edges.length; ++i) {\n      var e = edges[i]\n      var a = labels[e[0]]\n      var b = labels[e[1]]\n      e[0] = Math.min(a, b)\n      e[1] = Math.max(a, b)\n    }\n  } else {\n    for (var i = 0; i < edges.length; ++i) {\n      var e = edges[i]\n      var a = e[0]\n      var b = e[1]\n      e[0] = Math.min(a, b)\n      e[1] = Math.max(a, b)\n    }\n  }\n  if (useColor) {\n    edges.sort(compareLex3)\n  } else {\n    edges.sort(compareLex2)\n  }\n  var ptr = 1\n  for (var i = 1; i < edges.length; ++i) {\n    var prev = edges[i - 1]\n    var next = edges[i]\n    if (next[0] === prev[0] && next[1] === prev[1] &&\n      (!useColor || next[2] === prev[2])) {\n      continue\n    }\n    edges[ptr++] = next\n  }\n  edges.length = ptr\n}\n\nfunction preRound (points, edges, useColor) {\n  var labels = dedupPoints(points, [], boundPoints(points))\n  dedupEdges(edges, labels, useColor)\n  return !!labels\n}\n\n// Repeat until convergence\nfunction snapRound (points, edges, useColor) {\n  // 1. find edge crossings\n  var edgeBounds = boundEdges(points, edges)\n  var crossings = getCrossings(points, edges, edgeBounds)\n\n  // 2. find t-junctions\n  var vertBounds = boundPoints(points)\n  var tjunctions = getTJunctions(points, edges, edgeBounds, vertBounds)\n\n  // 3. cut edges, construct rational points\n  var ratPoints = cutEdges(points, edges, crossings, tjunctions, useColor)\n\n  // 4. dedupe verts\n  var labels = dedupPoints(points, ratPoints, vertBounds)\n\n  // 5. dedupe edges\n  dedupEdges(edges, labels, useColor)\n\n  // 6. check termination\n  if (!labels) {\n    return (crossings.length > 0 || tjunctions.length > 0)\n  }\n\n  // More iterations necessary\n  return true\n}\n\n// Main loop, runs PSLG clean up until completion\nfunction cleanPSLG (points, edges, colors) {\n  // If using colors, augment edges with color data\n  var prevEdges\n  if (colors) {\n    prevEdges = edges\n    var augEdges = new Array(edges.length)\n    for (var i = 0; i < edges.length; ++i) {\n      var e = edges[i]\n      augEdges[i] = [e[0], e[1], colors[i]]\n    }\n    edges = augEdges\n  }\n\n  // First round: remove duplicate edges and points\n  var modified = preRound(points, edges, !!colors)\n\n  // Run snap rounding until convergence\n  while (snapRound(points, edges, !!colors)) {\n    modified = true\n  }\n\n  // Strip color tags\n  if (!!colors && modified) {\n    prevEdges.length = 0\n    colors.length = 0\n    for (var i = 0; i < edges.length; ++i) {\n      var e = edges[i]\n      prevEdges.push([e[0], e[1]])\n      colors.push(e[2])\n    }\n  }\n\n  return modified\n}\n\n},{\"./lib/rat-seg-intersect\":117,\"big-rat\":78,\"big-rat/cmp\":76,\"big-rat/to-float\":90,\"box-intersect\":96,\"nextafter\":451,\"rat-vec\":486,\"robust-segment-intersect\":513,\"union-find\":546}],117:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = solveIntersection\n\nvar ratMul = _dereq_('big-rat/mul')\nvar ratDiv = _dereq_('big-rat/div')\nvar ratSub = _dereq_('big-rat/sub')\nvar ratSign = _dereq_('big-rat/sign')\nvar rvSub = _dereq_('rat-vec/sub')\nvar rvAdd = _dereq_('rat-vec/add')\nvar rvMuls = _dereq_('rat-vec/muls')\n\nfunction ratPerp (a, b) {\n  return ratSub(ratMul(a[0], b[1]), ratMul(a[1], b[0]))\n}\n\n// Solve for intersection\n//  x = a + t (b-a)\n//  (x - c) ^ (d-c) = 0\n//  (t * (b-a) + (a-c) ) ^ (d-c) = 0\n//  t * (b-a)^(d-c) = (d-c)^(a-c)\n//  t = (d-c)^(a-c) / (b-a)^(d-c)\n\nfunction solveIntersection (a, b, c, d) {\n  var ba = rvSub(b, a)\n  var dc = rvSub(d, c)\n\n  var baXdc = ratPerp(ba, dc)\n\n  if (ratSign(baXdc) === 0) {\n    return null\n  }\n\n  var ac = rvSub(a, c)\n  var dcXac = ratPerp(dc, ac)\n\n  var t = ratDiv(dcXac, baXdc)\n  var s = rvMuls(ba, t)\n  var r = rvAdd(a, s)\n\n  return r\n}\n\n},{\"big-rat/div\":77,\"big-rat/mul\":87,\"big-rat/sign\":88,\"big-rat/sub\":89,\"rat-vec/add\":485,\"rat-vec/muls\":487,\"rat-vec/sub\":488}],118:[function(_dereq_,module,exports){\n/** @module  color-id */\r\n\r\n'use strict'\r\n\r\nvar clamp = _dereq_('clamp')\r\n\r\nmodule.exports = toNumber\r\nmodule.exports.to = toNumber\r\nmodule.exports.from = fromNumber\r\n\r\nfunction toNumber (rgba, normalized) {\r\n\tif(normalized == null) normalized = true\r\n\r\n\tvar r = rgba[0], g = rgba[1], b = rgba[2], a = rgba[3]\r\n\r\n\tif (a == null) a = normalized ? 1 : 255\r\n\r\n\tif (normalized) {\r\n\t\tr *= 255\r\n\t\tg *= 255\r\n\t\tb *= 255\r\n\t\ta *= 255\r\n\t}\r\n\r\n\tr = clamp(r, 0, 255) & 0xFF\r\n\tg = clamp(g, 0, 255) & 0xFF\r\n\tb = clamp(b, 0, 255) & 0xFF\r\n\ta = clamp(a, 0, 255) & 0xFF\r\n\r\n\t//hi-order shift converts to -1, so we can't use <<24\r\n\tvar n = (r * 0x01000000) + (g << 16) + (b << 8) + (a)\r\n\r\n\treturn n\r\n}\r\n\r\nfunction fromNumber (n, normalized) {\r\n\tn = +n\r\n\r\n\tvar r = n >>> 24\r\n\tvar g = (n & 0x00ff0000) >>> 16\r\n\tvar b = (n & 0x0000ff00) >>> 8\r\n\tvar a = n & 0x000000ff\r\n\r\n\tif (normalized === false) return [r, g, b, a]\r\n\r\n\treturn [r/255, g/255, b/255, a/255]\r\n}\r\n\n},{\"clamp\":115}],119:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nmodule.exports = {\r\n\t\"aliceblue\": [240, 248, 255],\r\n\t\"antiquewhite\": [250, 235, 215],\r\n\t\"aqua\": [0, 255, 255],\r\n\t\"aquamarine\": [127, 255, 212],\r\n\t\"azure\": [240, 255, 255],\r\n\t\"beige\": [245, 245, 220],\r\n\t\"bisque\": [255, 228, 196],\r\n\t\"black\": [0, 0, 0],\r\n\t\"blanchedalmond\": [255, 235, 205],\r\n\t\"blue\": [0, 0, 255],\r\n\t\"blueviolet\": [138, 43, 226],\r\n\t\"brown\": [165, 42, 42],\r\n\t\"burlywood\": [222, 184, 135],\r\n\t\"cadetblue\": [95, 158, 160],\r\n\t\"chartreuse\": [127, 255, 0],\r\n\t\"chocolate\": [210, 105, 30],\r\n\t\"coral\": [255, 127, 80],\r\n\t\"cornflowerblue\": [100, 149, 237],\r\n\t\"cornsilk\": [255, 248, 220],\r\n\t\"crimson\": [220, 20, 60],\r\n\t\"cyan\": [0, 255, 255],\r\n\t\"darkblue\": [0, 0, 139],\r\n\t\"darkcyan\": [0, 139, 139],\r\n\t\"darkgoldenrod\": [184, 134, 11],\r\n\t\"darkgray\": [169, 169, 169],\r\n\t\"darkgreen\": [0, 100, 0],\r\n\t\"darkgrey\": [169, 169, 169],\r\n\t\"darkkhaki\": [189, 183, 107],\r\n\t\"darkmagenta\": [139, 0, 139],\r\n\t\"darkolivegreen\": [85, 107, 47],\r\n\t\"darkorange\": [255, 140, 0],\r\n\t\"darkorchid\": [153, 50, 204],\r\n\t\"darkred\": [139, 0, 0],\r\n\t\"darksalmon\": [233, 150, 122],\r\n\t\"darkseagreen\": [143, 188, 143],\r\n\t\"darkslateblue\": [72, 61, 139],\r\n\t\"darkslategray\": [47, 79, 79],\r\n\t\"darkslategrey\": [47, 79, 79],\r\n\t\"darkturquoise\": [0, 206, 209],\r\n\t\"darkviolet\": [148, 0, 211],\r\n\t\"deeppink\": [255, 20, 147],\r\n\t\"deepskyblue\": [0, 191, 255],\r\n\t\"dimgray\": [105, 105, 105],\r\n\t\"dimgrey\": [105, 105, 105],\r\n\t\"dodgerblue\": [30, 144, 255],\r\n\t\"firebrick\": [178, 34, 34],\r\n\t\"floralwhite\": [255, 250, 240],\r\n\t\"forestgreen\": [34, 139, 34],\r\n\t\"fuchsia\": [255, 0, 255],\r\n\t\"gainsboro\": [220, 220, 220],\r\n\t\"ghostwhite\": [248, 248, 255],\r\n\t\"gold\": [255, 215, 0],\r\n\t\"goldenrod\": [218, 165, 32],\r\n\t\"gray\": [128, 128, 128],\r\n\t\"green\": [0, 128, 0],\r\n\t\"greenyellow\": [173, 255, 47],\r\n\t\"grey\": [128, 128, 128],\r\n\t\"honeydew\": [240, 255, 240],\r\n\t\"hotpink\": [255, 105, 180],\r\n\t\"indianred\": [205, 92, 92],\r\n\t\"indigo\": [75, 0, 130],\r\n\t\"ivory\": [255, 255, 240],\r\n\t\"khaki\": [240, 230, 140],\r\n\t\"lavender\": [230, 230, 250],\r\n\t\"lavenderblush\": [255, 240, 245],\r\n\t\"lawngreen\": [124, 252, 0],\r\n\t\"lemonchiffon\": [255, 250, 205],\r\n\t\"lightblue\": [173, 216, 230],\r\n\t\"lightcoral\": [240, 128, 128],\r\n\t\"lightcyan\": [224, 255, 255],\r\n\t\"lightgoldenrodyellow\": [250, 250, 210],\r\n\t\"lightgray\": [211, 211, 211],\r\n\t\"lightgreen\": [144, 238, 144],\r\n\t\"lightgrey\": [211, 211, 211],\r\n\t\"lightpink\": [255, 182, 193],\r\n\t\"lightsalmon\": [255, 160, 122],\r\n\t\"lightseagreen\": [32, 178, 170],\r\n\t\"lightskyblue\": [135, 206, 250],\r\n\t\"lightslategray\": [119, 136, 153],\r\n\t\"lightslategrey\": [119, 136, 153],\r\n\t\"lightsteelblue\": [176, 196, 222],\r\n\t\"lightyellow\": [255, 255, 224],\r\n\t\"lime\": [0, 255, 0],\r\n\t\"limegreen\": [50, 205, 50],\r\n\t\"linen\": [250, 240, 230],\r\n\t\"magenta\": [255, 0, 255],\r\n\t\"maroon\": [128, 0, 0],\r\n\t\"mediumaquamarine\": [102, 205, 170],\r\n\t\"mediumblue\": [0, 0, 205],\r\n\t\"mediumorchid\": [186, 85, 211],\r\n\t\"mediumpurple\": [147, 112, 219],\r\n\t\"mediumseagreen\": [60, 179, 113],\r\n\t\"mediumslateblue\": [123, 104, 238],\r\n\t\"mediumspringgreen\": [0, 250, 154],\r\n\t\"mediumturquoise\": [72, 209, 204],\r\n\t\"mediumvioletred\": [199, 21, 133],\r\n\t\"midnightblue\": [25, 25, 112],\r\n\t\"mintcream\": [245, 255, 250],\r\n\t\"mistyrose\": [255, 228, 225],\r\n\t\"moccasin\": [255, 228, 181],\r\n\t\"navajowhite\": [255, 222, 173],\r\n\t\"navy\": [0, 0, 128],\r\n\t\"oldlace\": [253, 245, 230],\r\n\t\"olive\": [128, 128, 0],\r\n\t\"olivedrab\": [107, 142, 35],\r\n\t\"orange\": [255, 165, 0],\r\n\t\"orangered\": [255, 69, 0],\r\n\t\"orchid\": [218, 112, 214],\r\n\t\"palegoldenrod\": [238, 232, 170],\r\n\t\"palegreen\": [152, 251, 152],\r\n\t\"paleturquoise\": [175, 238, 238],\r\n\t\"palevioletred\": [219, 112, 147],\r\n\t\"papayawhip\": [255, 239, 213],\r\n\t\"peachpuff\": [255, 218, 185],\r\n\t\"peru\": [205, 133, 63],\r\n\t\"pink\": [255, 192, 203],\r\n\t\"plum\": [221, 160, 221],\r\n\t\"powderblue\": [176, 224, 230],\r\n\t\"purple\": [128, 0, 128],\r\n\t\"rebeccapurple\": [102, 51, 153],\r\n\t\"red\": [255, 0, 0],\r\n\t\"rosybrown\": [188, 143, 143],\r\n\t\"royalblue\": [65, 105, 225],\r\n\t\"saddlebrown\": [139, 69, 19],\r\n\t\"salmon\": [250, 128, 114],\r\n\t\"sandybrown\": [244, 164, 96],\r\n\t\"seagreen\": [46, 139, 87],\r\n\t\"seashell\": [255, 245, 238],\r\n\t\"sienna\": [160, 82, 45],\r\n\t\"silver\": [192, 192, 192],\r\n\t\"skyblue\": [135, 206, 235],\r\n\t\"slateblue\": [106, 90, 205],\r\n\t\"slategray\": [112, 128, 144],\r\n\t\"slategrey\": [112, 128, 144],\r\n\t\"snow\": [255, 250, 250],\r\n\t\"springgreen\": [0, 255, 127],\r\n\t\"steelblue\": [70, 130, 180],\r\n\t\"tan\": [210, 180, 140],\r\n\t\"teal\": [0, 128, 128],\r\n\t\"thistle\": [216, 191, 216],\r\n\t\"tomato\": [255, 99, 71],\r\n\t\"turquoise\": [64, 224, 208],\r\n\t\"violet\": [238, 130, 238],\r\n\t\"wheat\": [245, 222, 179],\r\n\t\"white\": [255, 255, 255],\r\n\t\"whitesmoke\": [245, 245, 245],\r\n\t\"yellow\": [255, 255, 0],\r\n\t\"yellowgreen\": [154, 205, 50]\r\n};\r\n\n},{}],120:[function(_dereq_,module,exports){\n/** @module  color-normalize */\r\n\r\n'use strict'\r\n\r\nvar rgba = _dereq_('color-rgba')\r\nvar clamp = _dereq_('clamp')\r\nvar dtype = _dereq_('dtype')\r\n\r\nmodule.exports = function normalize (color, type) {\r\n\tif (type === 'float' || !type) type = 'array'\r\n\tif (type === 'uint') type = 'uint8'\r\n\tif (type === 'uint_clamped') type = 'uint8_clamped'\r\n\tvar Ctor = dtype(type)\r\n\tvar output = new Ctor(4)\r\n\r\n\tvar normalize = type !== 'uint8' && type !== 'uint8_clamped'\r\n\r\n\t// attempt to parse non-array arguments\r\n\tif (!color.length || typeof color === 'string') {\r\n\t\tcolor = rgba(color)\r\n\t\tcolor[0] /= 255\r\n\t\tcolor[1] /= 255\r\n\t\tcolor[2] /= 255\r\n\t}\r\n\r\n\t// 0, 1 are possible contradictory values for Arrays:\r\n\t// [1,1,1] input gives [1,1,1] output instead of [1/255,1/255,1/255], which may be collision if input is meant to be uint.\r\n\t// converting [1,1,1] to [1/255,1/255,1/255] in case of float input gives larger mistake since [1,1,1] float is frequent edge value, whereas [0,1,1], [1,1,1] etc. uint inputs are relatively rare\r\n\tif (isInt(color)) {\r\n\t\toutput[0] = color[0]\r\n\t\toutput[1] = color[1]\r\n\t\toutput[2] = color[2]\r\n\t\toutput[3] = color[3] != null ? color[3] : 255\r\n\r\n\t\tif (normalize) {\r\n\t\t\toutput[0] /= 255\r\n\t\t\toutput[1] /= 255\r\n\t\t\toutput[2] /= 255\r\n\t\t\toutput[3] /= 255\r\n\t\t}\r\n\r\n\t\treturn output\r\n\t}\r\n\r\n\tif (!normalize) {\r\n\t\toutput[0] = clamp(Math.floor(color[0] * 255), 0, 255)\r\n\t\toutput[1] = clamp(Math.floor(color[1] * 255), 0, 255)\r\n\t\toutput[2] = clamp(Math.floor(color[2] * 255), 0, 255)\r\n\t\toutput[3] = color[3] == null ? 255 : clamp(Math.floor(color[3] * 255), 0, 255)\r\n\t} else {\r\n\t\toutput[0] = color[0]\r\n\t\toutput[1] = color[1]\r\n\t\toutput[2] = color[2]\r\n\t\toutput[3] = color[3] != null ? color[3] : 1\r\n\t}\r\n\r\n\treturn output\r\n}\r\n\r\nfunction isInt(color) {\r\n\tif (color instanceof Uint8Array || color instanceof Uint8ClampedArray) return true\r\n\r\n\tif (Array.isArray(color) &&\r\n\t\t(color[0] > 1 || color[0] === 0) &&\r\n\t\t(color[1] > 1 || color[1] === 0) &&\r\n\t\t(color[2] > 1 || color[2] === 0) &&\r\n\t\t(!color[3] || color[3] > 1)\r\n\t) return true\r\n\r\n\treturn false\r\n}\r\n\n},{\"clamp\":115,\"color-rgba\":122,\"dtype\":169}],121:[function(_dereq_,module,exports){\n(function (global){\n/**\n * @module color-parse\n */\n\n'use strict'\n\nvar names = _dereq_('color-name')\nvar isObject = _dereq_('is-plain-obj')\nvar defined = _dereq_('defined')\n\nmodule.exports = parse\n\n/**\n * Base hues\n * http://dev.w3.org/csswg/css-color/#typedef-named-hue\n */\n//FIXME: use external hue detector\nvar baseHues = {\n\tred: 0,\n\torange: 60,\n\tyellow: 120,\n\tgreen: 180,\n\tblue: 240,\n\tpurple: 300\n}\n\n/**\n * Parse color from the string passed\n *\n * @return {Object} A space indicator `space`, an array `values` and `alpha`\n */\nfunction parse (cstr) {\n\tvar m, parts = [], alpha = 1, space\n\n\tif (typeof cstr === 'string') {\n\t\t//keyword\n\t\tif (names[cstr]) {\n\t\t\tparts = names[cstr].slice()\n\t\t\tspace = 'rgb'\n\t\t}\n\n\t\t//reserved words\n\t\telse if (cstr === 'transparent') {\n\t\t\talpha = 0\n\t\t\tspace = 'rgb'\n\t\t\tparts = [0,0,0]\n\t\t}\n\n\t\t//hex\n\t\telse if (/^#[A-Fa-f0-9]+$/.test(cstr)) {\n\t\t\tvar base = cstr.slice(1)\n\t\t\tvar size = base.length\n\t\t\tvar isShort = size <= 4\n\t\t\talpha = 1\n\n\t\t\tif (isShort) {\n\t\t\t\tparts = [\n\t\t\t\t\tparseInt(base[0] + base[0], 16),\n\t\t\t\t\tparseInt(base[1] + base[1], 16),\n\t\t\t\t\tparseInt(base[2] + base[2], 16)\n\t\t\t\t]\n\t\t\t\tif (size === 4) {\n\t\t\t\t\talpha = parseInt(base[3] + base[3], 16) / 255\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tparts = [\n\t\t\t\t\tparseInt(base[0] + base[1], 16),\n\t\t\t\t\tparseInt(base[2] + base[3], 16),\n\t\t\t\t\tparseInt(base[4] + base[5], 16)\n\t\t\t\t]\n\t\t\t\tif (size === 8) {\n\t\t\t\t\talpha = parseInt(base[6] + base[7], 16) / 255\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!parts[0]) parts[0] = 0\n\t\t\tif (!parts[1]) parts[1] = 0\n\t\t\tif (!parts[2]) parts[2] = 0\n\n\t\t\tspace = 'rgb'\n\t\t}\n\n\t\t//color space\n\t\telse if (m = /^((?:rgb|hs[lvb]|hwb|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms)a?)\\s*\\(([^\\)]*)\\)/.exec(cstr)) {\n\t\t\tvar name = m[1]\n\t\t\tvar isRGB = name === 'rgb'\n\t\t\tvar base = name.replace(/a$/, '')\n\t\t\tspace = base\n\t\t\tvar size = base === 'cmyk' ? 4 : base === 'gray' ? 1 : 3\n\t\t\tparts = m[2].trim()\n\t\t\t\t.split(/\\s*,\\s*/)\n\t\t\t\t.map(function (x, i) {\n\t\t\t\t\t//<percentage>\n\t\t\t\t\tif (/%$/.test(x)) {\n\t\t\t\t\t\t//alpha\n\t\t\t\t\t\tif (i === size)\treturn parseFloat(x) / 100\n\t\t\t\t\t\t//rgb\n\t\t\t\t\t\tif (base === 'rgb') return parseFloat(x) * 255 / 100\n\t\t\t\t\t\treturn parseFloat(x)\n\t\t\t\t\t}\n\t\t\t\t\t//hue\n\t\t\t\t\telse if (base[i] === 'h') {\n\t\t\t\t\t\t//<deg>\n\t\t\t\t\t\tif (/deg$/.test(x)) {\n\t\t\t\t\t\t\treturn parseFloat(x)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t//<base-hue>\n\t\t\t\t\t\telse if (baseHues[x] !== undefined) {\n\t\t\t\t\t\t\treturn baseHues[x]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn parseFloat(x)\n\t\t\t\t})\n\n\t\t\tif (name === base) parts.push(1)\n\t\t\talpha = (isRGB) ? 1 : (parts[size] === undefined) ? 1 : parts[size]\n\t\t\tparts = parts.slice(0, size)\n\t\t}\n\n\t\t//named channels case\n\t\telse if (cstr.length > 10 && /[0-9](?:\\s|\\/)/.test(cstr)) {\n\t\t\tparts = cstr.match(/([0-9]+)/g).map(function (value) {\n\t\t\t\treturn parseFloat(value)\n\t\t\t})\n\n\t\t\tspace = cstr.match(/([a-z])/ig).join('').toLowerCase()\n\t\t}\n\t}\n\n\t//numeric case\n\telse if (!isNaN(cstr)) {\n\t\tspace = 'rgb'\n\t\tparts = [cstr >>> 16, (cstr & 0x00ff00) >>> 8, cstr & 0x0000ff]\n\t}\n\n\t//object case - detects css cases of rgb and hsl\n\telse if (isObject(cstr)) {\n\t\tvar r = defined(cstr.r, cstr.red, cstr.R, null)\n\n\t\tif (r !== null) {\n\t\t\tspace = 'rgb'\n\t\t\tparts = [\n\t\t\t\tr,\n\t\t\t\tdefined(cstr.g, cstr.green, cstr.G),\n\t\t\t\tdefined(cstr.b, cstr.blue, cstr.B)\n\t\t\t]\n\t\t}\n\t\telse {\n\t\t\tspace = 'hsl'\n\t\t\tparts = [\n\t\t\t\tdefined(cstr.h, cstr.hue, cstr.H),\n\t\t\t\tdefined(cstr.s, cstr.saturation, cstr.S),\n\t\t\t\tdefined(cstr.l, cstr.lightness, cstr.L, cstr.b, cstr.brightness)\n\t\t\t]\n\t\t}\n\n\t\talpha = defined(cstr.a, cstr.alpha, cstr.opacity, 1)\n\n\t\tif (cstr.opacity != null) alpha /= 100\n\t}\n\n\t//array\n\telse if (Array.isArray(cstr) || global.ArrayBuffer && ArrayBuffer.isView && ArrayBuffer.isView(cstr)) {\n\t\tparts = [cstr[0], cstr[1], cstr[2]]\n\t\tspace = 'rgb'\n\t\talpha = cstr.length === 4 ? cstr[3] : 1\n\t}\n\n\treturn {\n\t\tspace: space,\n\t\tvalues: parts,\n\t\talpha: alpha\n\t}\n}\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"color-name\":119,\"defined\":164,\"is-plain-obj\":422}],122:[function(_dereq_,module,exports){\n/** @module  color-rgba */\n\n'use strict'\n\nvar parse = _dereq_('color-parse')\nvar hsl = _dereq_('color-space/hsl')\nvar clamp = _dereq_('clamp')\n\nmodule.exports = function rgba (color) {\n\tvar values, i, l\n\n\t//attempt to parse non-array arguments\n\tvar parsed = parse(color)\n\n\tif (!parsed.space) return []\n\n\tvalues = Array(3)\n\tvalues[0] = clamp(parsed.values[0], 0, 255)\n\tvalues[1] = clamp(parsed.values[1], 0, 255)\n\tvalues[2] = clamp(parsed.values[2], 0, 255)\n\n\tif (parsed.space[0] === 'h') {\n\t\tvalues = hsl.rgb(values)\n\t}\n\n\tvalues.push(clamp(parsed.alpha, 0, 1))\n\n\treturn values\n}\n\n},{\"clamp\":115,\"color-parse\":121,\"color-space/hsl\":123}],123:[function(_dereq_,module,exports){\n/**\n * @module color-space/hsl\n */\n'use strict'\n\nvar rgb = _dereq_('./rgb');\n\nmodule.exports = {\n\tname: 'hsl',\n\tmin: [0,0,0],\n\tmax: [360,100,100],\n\tchannel: ['hue', 'saturation', 'lightness'],\n\talias: ['HSL'],\n\n\trgb: function(hsl) {\n\t\tvar h = hsl[0] / 360,\n\t\t\t\ts = hsl[1] / 100,\n\t\t\t\tl = hsl[2] / 100,\n\t\t\t\tt1, t2, t3, rgb, val;\n\n\t\tif (s === 0) {\n\t\t\tval = l * 255;\n\t\t\treturn [val, val, val];\n\t\t}\n\n\t\tif (l < 0.5) {\n\t\t\tt2 = l * (1 + s);\n\t\t}\n\t\telse {\n\t\t\tt2 = l + s - l * s;\n\t\t}\n\t\tt1 = 2 * l - t2;\n\n\t\trgb = [0, 0, 0];\n\t\tfor (var i = 0; i < 3; i++) {\n\t\t\tt3 = h + 1 / 3 * - (i - 1);\n\t\t\tif (t3 < 0) {\n\t\t\t\tt3++;\n\t\t\t}\n\t\t\telse if (t3 > 1) {\n\t\t\t\tt3--;\n\t\t\t}\n\n\t\t\tif (6 * t3 < 1) {\n\t\t\t\tval = t1 + (t2 - t1) * 6 * t3;\n\t\t\t}\n\t\t\telse if (2 * t3 < 1) {\n\t\t\t\tval = t2;\n\t\t\t}\n\t\t\telse if (3 * t3 < 2) {\n\t\t\t\tval = t1 + (t2 - t1) * (2 / 3 - t3) * 6;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tval = t1;\n\t\t\t}\n\n\t\t\trgb[i] = val * 255;\n\t\t}\n\n\t\treturn rgb;\n\t}\n};\n\n\n//extend rgb\nrgb.hsl = function(rgb) {\n\tvar r = rgb[0]/255,\n\t\t\tg = rgb[1]/255,\n\t\t\tb = rgb[2]/255,\n\t\t\tmin = Math.min(r, g, b),\n\t\t\tmax = Math.max(r, g, b),\n\t\t\tdelta = max - min,\n\t\t\th, s, l;\n\n\tif (max === min) {\n\t\th = 0;\n\t}\n\telse if (r === max) {\n\t\th = (g - b) / delta;\n\t}\n\telse if (g === max) {\n\t\th = 2 + (b - r) / delta;\n\t}\n\telse if (b === max) {\n\t\th = 4 + (r - g)/ delta;\n\t}\n\n\th = Math.min(h * 60, 360);\n\n\tif (h < 0) {\n\t\th += 360;\n\t}\n\n\tl = (min + max) / 2;\n\n\tif (max === min) {\n\t\ts = 0;\n\t}\n\telse if (l <= 0.5) {\n\t\ts = delta / (max + min);\n\t}\n\telse {\n\t\ts = delta / (2 - max - min);\n\t}\n\n\treturn [h, s * 100, l * 100];\n};\n\n},{\"./rgb\":124}],124:[function(_dereq_,module,exports){\n/**\n * RGB space.\n *\n * @module  color-space/rgb\n */\n'use strict'\n\nmodule.exports = {\n\tname: 'rgb',\n\tmin: [0,0,0],\n\tmax: [255,255,255],\n\tchannel: ['red', 'green', 'blue'],\n\talias: ['RGB']\n};\n\n},{}],125:[function(_dereq_,module,exports){\nmodule.exports={\n\t\"jet\":[{\"index\":0,\"rgb\":[0,0,131]},{\"index\":0.125,\"rgb\":[0,60,170]},{\"index\":0.375,\"rgb\":[5,255,255]},{\"index\":0.625,\"rgb\":[255,255,0]},{\"index\":0.875,\"rgb\":[250,0,0]},{\"index\":1,\"rgb\":[128,0,0]}],\n\n\t\"hsv\":[{\"index\":0,\"rgb\":[255,0,0]},{\"index\":0.169,\"rgb\":[253,255,2]},{\"index\":0.173,\"rgb\":[247,255,2]},{\"index\":0.337,\"rgb\":[0,252,4]},{\"index\":0.341,\"rgb\":[0,252,10]},{\"index\":0.506,\"rgb\":[1,249,255]},{\"index\":0.671,\"rgb\":[2,0,253]},{\"index\":0.675,\"rgb\":[8,0,253]},{\"index\":0.839,\"rgb\":[255,0,251]},{\"index\":0.843,\"rgb\":[255,0,245]},{\"index\":1,\"rgb\":[255,0,6]}],\n\n\t\"hot\":[{\"index\":0,\"rgb\":[0,0,0]},{\"index\":0.3,\"rgb\":[230,0,0]},{\"index\":0.6,\"rgb\":[255,210,0]},{\"index\":1,\"rgb\":[255,255,255]}],\n\n\t\"cool\":[{\"index\":0,\"rgb\":[0,255,255]},{\"index\":1,\"rgb\":[255,0,255]}],\n\n\t\"spring\":[{\"index\":0,\"rgb\":[255,0,255]},{\"index\":1,\"rgb\":[255,255,0]}],\n\n\t\"summer\":[{\"index\":0,\"rgb\":[0,128,102]},{\"index\":1,\"rgb\":[255,255,102]}],\n\n\t\"autumn\":[{\"index\":0,\"rgb\":[255,0,0]},{\"index\":1,\"rgb\":[255,255,0]}],\n\n\t\"winter\":[{\"index\":0,\"rgb\":[0,0,255]},{\"index\":1,\"rgb\":[0,255,128]}],\n\n\t\"bone\":[{\"index\":0,\"rgb\":[0,0,0]},{\"index\":0.376,\"rgb\":[84,84,116]},{\"index\":0.753,\"rgb\":[169,200,200]},{\"index\":1,\"rgb\":[255,255,255]}],\n\n\t\"copper\":[{\"index\":0,\"rgb\":[0,0,0]},{\"index\":0.804,\"rgb\":[255,160,102]},{\"index\":1,\"rgb\":[255,199,127]}],\n\n\t\"greys\":[{\"index\":0,\"rgb\":[0,0,0]},{\"index\":1,\"rgb\":[255,255,255]}],\n\n\t\"yignbu\":[{\"index\":0,\"rgb\":[8,29,88]},{\"index\":0.125,\"rgb\":[37,52,148]},{\"index\":0.25,\"rgb\":[34,94,168]},{\"index\":0.375,\"rgb\":[29,145,192]},{\"index\":0.5,\"rgb\":[65,182,196]},{\"index\":0.625,\"rgb\":[127,205,187]},{\"index\":0.75,\"rgb\":[199,233,180]},{\"index\":0.875,\"rgb\":[237,248,217]},{\"index\":1,\"rgb\":[255,255,217]}],\n\n\t\"greens\":[{\"index\":0,\"rgb\":[0,68,27]},{\"index\":0.125,\"rgb\":[0,109,44]},{\"index\":0.25,\"rgb\":[35,139,69]},{\"index\":0.375,\"rgb\":[65,171,93]},{\"index\":0.5,\"rgb\":[116,196,118]},{\"index\":0.625,\"rgb\":[161,217,155]},{\"index\":0.75,\"rgb\":[199,233,192]},{\"index\":0.875,\"rgb\":[229,245,224]},{\"index\":1,\"rgb\":[247,252,245]}],\n\n\t\"yiorrd\":[{\"index\":0,\"rgb\":[128,0,38]},{\"index\":0.125,\"rgb\":[189,0,38]},{\"index\":0.25,\"rgb\":[227,26,28]},{\"index\":0.375,\"rgb\":[252,78,42]},{\"index\":0.5,\"rgb\":[253,141,60]},{\"index\":0.625,\"rgb\":[254,178,76]},{\"index\":0.75,\"rgb\":[254,217,118]},{\"index\":0.875,\"rgb\":[255,237,160]},{\"index\":1,\"rgb\":[255,255,204]}],\n\n\t\"bluered\":[{\"index\":0,\"rgb\":[0,0,255]},{\"index\":1,\"rgb\":[255,0,0]}],\n\n\t\"rdbu\":[{\"index\":0,\"rgb\":[5,10,172]},{\"index\":0.35,\"rgb\":[106,137,247]},{\"index\":0.5,\"rgb\":[190,190,190]},{\"index\":0.6,\"rgb\":[220,170,132]},{\"index\":0.7,\"rgb\":[230,145,90]},{\"index\":1,\"rgb\":[178,10,28]}],\n\n\t\"picnic\":[{\"index\":0,\"rgb\":[0,0,255]},{\"index\":0.1,\"rgb\":[51,153,255]},{\"index\":0.2,\"rgb\":[102,204,255]},{\"index\":0.3,\"rgb\":[153,204,255]},{\"index\":0.4,\"rgb\":[204,204,255]},{\"index\":0.5,\"rgb\":[255,255,255]},{\"index\":0.6,\"rgb\":[255,204,255]},{\"index\":0.7,\"rgb\":[255,153,255]},{\"index\":0.8,\"rgb\":[255,102,204]},{\"index\":0.9,\"rgb\":[255,102,102]},{\"index\":1,\"rgb\":[255,0,0]}],\n\n\t\"rainbow\":[{\"index\":0,\"rgb\":[150,0,90]},{\"index\":0.125,\"rgb\":[0,0,200]},{\"index\":0.25,\"rgb\":[0,25,255]},{\"index\":0.375,\"rgb\":[0,152,255]},{\"index\":0.5,\"rgb\":[44,255,150]},{\"index\":0.625,\"rgb\":[151,255,0]},{\"index\":0.75,\"rgb\":[255,234,0]},{\"index\":0.875,\"rgb\":[255,111,0]},{\"index\":1,\"rgb\":[255,0,0]}],\n\n\t\"portland\":[{\"index\":0,\"rgb\":[12,51,131]},{\"index\":0.25,\"rgb\":[10,136,186]},{\"index\":0.5,\"rgb\":[242,211,56]},{\"index\":0.75,\"rgb\":[242,143,56]},{\"index\":1,\"rgb\":[217,30,30]}],\n\n\t\"blackbody\":[{\"index\":0,\"rgb\":[0,0,0]},{\"index\":0.2,\"rgb\":[230,0,0]},{\"index\":0.4,\"rgb\":[230,210,0]},{\"index\":0.7,\"rgb\":[255,255,255]},{\"index\":1,\"rgb\":[160,200,255]}],\n\n\t\"earth\":[{\"index\":0,\"rgb\":[0,0,130]},{\"index\":0.1,\"rgb\":[0,180,180]},{\"index\":0.2,\"rgb\":[40,210,40]},{\"index\":0.4,\"rgb\":[230,230,50]},{\"index\":0.6,\"rgb\":[120,70,20]},{\"index\":1,\"rgb\":[255,255,255]}],\n\n\t\"electric\":[{\"index\":0,\"rgb\":[0,0,0]},{\"index\":0.15,\"rgb\":[30,0,100]},{\"index\":0.4,\"rgb\":[120,0,100]},{\"index\":0.6,\"rgb\":[160,90,0]},{\"index\":0.8,\"rgb\":[230,200,0]},{\"index\":1,\"rgb\":[255,250,220]}],\n\n\t\"alpha\": [{\"index\":0, \"rgb\": [255,255,255,0]},{\"index\":1, \"rgb\": [255,255,255,1]}],\n\n\t\"viridis\": [{\"index\":0,\"rgb\":[68,1,84]},{\"index\":0.13,\"rgb\":[71,44,122]},{\"index\":0.25,\"rgb\":[59,81,139]},{\"index\":0.38,\"rgb\":[44,113,142]},{\"index\":0.5,\"rgb\":[33,144,141]},{\"index\":0.63,\"rgb\":[39,173,129]},{\"index\":0.75,\"rgb\":[92,200,99]},{\"index\":0.88,\"rgb\":[170,220,50]},{\"index\":1,\"rgb\":[253,231,37]}],\n\n\t\"inferno\": [{\"index\":0,\"rgb\":[0,0,4]},{\"index\":0.13,\"rgb\":[31,12,72]},{\"index\":0.25,\"rgb\":[85,15,109]},{\"index\":0.38,\"rgb\":[136,34,106]},{\"index\":0.5,\"rgb\":[186,54,85]},{\"index\":0.63,\"rgb\":[227,89,51]},{\"index\":0.75,\"rgb\":[249,140,10]},{\"index\":0.88,\"rgb\":[249,201,50]},{\"index\":1,\"rgb\":[252,255,164]}],\n\n\t\"magma\": [{\"index\":0,\"rgb\":[0,0,4]},{\"index\":0.13,\"rgb\":[28,16,68]},{\"index\":0.25,\"rgb\":[79,18,123]},{\"index\":0.38,\"rgb\":[129,37,129]},{\"index\":0.5,\"rgb\":[181,54,122]},{\"index\":0.63,\"rgb\":[229,80,100]},{\"index\":0.75,\"rgb\":[251,135,97]},{\"index\":0.88,\"rgb\":[254,194,135]},{\"index\":1,\"rgb\":[252,253,191]}],\n\n\t\"plasma\": [{\"index\":0,\"rgb\":[13,8,135]},{\"index\":0.13,\"rgb\":[75,3,161]},{\"index\":0.25,\"rgb\":[125,3,168]},{\"index\":0.38,\"rgb\":[168,34,150]},{\"index\":0.5,\"rgb\":[203,70,121]},{\"index\":0.63,\"rgb\":[229,107,93]},{\"index\":0.75,\"rgb\":[248,148,65]},{\"index\":0.88,\"rgb\":[253,195,40]},{\"index\":1,\"rgb\":[240,249,33]}],\n\n\t\"warm\": [{\"index\":0,\"rgb\":[125,0,179]},{\"index\":0.13,\"rgb\":[172,0,187]},{\"index\":0.25,\"rgb\":[219,0,170]},{\"index\":0.38,\"rgb\":[255,0,130]},{\"index\":0.5,\"rgb\":[255,63,74]},{\"index\":0.63,\"rgb\":[255,123,0]},{\"index\":0.75,\"rgb\":[234,176,0]},{\"index\":0.88,\"rgb\":[190,228,0]},{\"index\":1,\"rgb\":[147,255,0]}],\n\n\t\"cool\": [{\"index\":0,\"rgb\":[125,0,179]},{\"index\":0.13,\"rgb\":[116,0,218]},{\"index\":0.25,\"rgb\":[98,74,237]},{\"index\":0.38,\"rgb\":[68,146,231]},{\"index\":0.5,\"rgb\":[0,204,197]},{\"index\":0.63,\"rgb\":[0,247,146]},{\"index\":0.75,\"rgb\":[0,255,88]},{\"index\":0.88,\"rgb\":[40,255,8]},{\"index\":1,\"rgb\":[147,255,0]}],\n\n\t\"rainbow-soft\": [{\"index\":0,\"rgb\":[125,0,179]},{\"index\":0.1,\"rgb\":[199,0,180]},{\"index\":0.2,\"rgb\":[255,0,121]},{\"index\":0.3,\"rgb\":[255,108,0]},{\"index\":0.4,\"rgb\":[222,194,0]},{\"index\":0.5,\"rgb\":[150,255,0]},{\"index\":0.6,\"rgb\":[0,255,55]},{\"index\":0.7,\"rgb\":[0,246,150]},{\"index\":0.8,\"rgb\":[50,167,222]},{\"index\":0.9,\"rgb\":[103,51,235]},{\"index\":1,\"rgb\":[124,0,186]}],\n\n\t\"bathymetry\": [{\"index\":0,\"rgb\":[40,26,44]},{\"index\":0.13,\"rgb\":[59,49,90]},{\"index\":0.25,\"rgb\":[64,76,139]},{\"index\":0.38,\"rgb\":[63,110,151]},{\"index\":0.5,\"rgb\":[72,142,158]},{\"index\":0.63,\"rgb\":[85,174,163]},{\"index\":0.75,\"rgb\":[120,206,163]},{\"index\":0.88,\"rgb\":[187,230,172]},{\"index\":1,\"rgb\":[253,254,204]}],\n\n\t\"cdom\": [{\"index\":0,\"rgb\":[47,15,62]},{\"index\":0.13,\"rgb\":[87,23,86]},{\"index\":0.25,\"rgb\":[130,28,99]},{\"index\":0.38,\"rgb\":[171,41,96]},{\"index\":0.5,\"rgb\":[206,67,86]},{\"index\":0.63,\"rgb\":[230,106,84]},{\"index\":0.75,\"rgb\":[242,149,103]},{\"index\":0.88,\"rgb\":[249,193,135]},{\"index\":1,\"rgb\":[254,237,176]}],\n\n\t\"chlorophyll\": [{\"index\":0,\"rgb\":[18,36,20]},{\"index\":0.13,\"rgb\":[25,63,41]},{\"index\":0.25,\"rgb\":[24,91,59]},{\"index\":0.38,\"rgb\":[13,119,72]},{\"index\":0.5,\"rgb\":[18,148,80]},{\"index\":0.63,\"rgb\":[80,173,89]},{\"index\":0.75,\"rgb\":[132,196,122]},{\"index\":0.88,\"rgb\":[175,221,162]},{\"index\":1,\"rgb\":[215,249,208]}],\n\n\t\"density\": [{\"index\":0,\"rgb\":[54,14,36]},{\"index\":0.13,\"rgb\":[89,23,80]},{\"index\":0.25,\"rgb\":[110,45,132]},{\"index\":0.38,\"rgb\":[120,77,178]},{\"index\":0.5,\"rgb\":[120,113,213]},{\"index\":0.63,\"rgb\":[115,151,228]},{\"index\":0.75,\"rgb\":[134,185,227]},{\"index\":0.88,\"rgb\":[177,214,227]},{\"index\":1,\"rgb\":[230,241,241]}],\n\n\t\"freesurface-blue\": [{\"index\":0,\"rgb\":[30,4,110]},{\"index\":0.13,\"rgb\":[47,14,176]},{\"index\":0.25,\"rgb\":[41,45,236]},{\"index\":0.38,\"rgb\":[25,99,212]},{\"index\":0.5,\"rgb\":[68,131,200]},{\"index\":0.63,\"rgb\":[114,156,197]},{\"index\":0.75,\"rgb\":[157,181,203]},{\"index\":0.88,\"rgb\":[200,208,216]},{\"index\":1,\"rgb\":[241,237,236]}],\n\n\t\"freesurface-red\": [{\"index\":0,\"rgb\":[60,9,18]},{\"index\":0.13,\"rgb\":[100,17,27]},{\"index\":0.25,\"rgb\":[142,20,29]},{\"index\":0.38,\"rgb\":[177,43,27]},{\"index\":0.5,\"rgb\":[192,87,63]},{\"index\":0.63,\"rgb\":[205,125,105]},{\"index\":0.75,\"rgb\":[216,162,148]},{\"index\":0.88,\"rgb\":[227,199,193]},{\"index\":1,\"rgb\":[241,237,236]}],\n\n\t\"oxygen\": [{\"index\":0,\"rgb\":[64,5,5]},{\"index\":0.13,\"rgb\":[106,6,15]},{\"index\":0.25,\"rgb\":[144,26,7]},{\"index\":0.38,\"rgb\":[168,64,3]},{\"index\":0.5,\"rgb\":[188,100,4]},{\"index\":0.63,\"rgb\":[206,136,11]},{\"index\":0.75,\"rgb\":[220,174,25]},{\"index\":0.88,\"rgb\":[231,215,44]},{\"index\":1,\"rgb\":[248,254,105]}],\n\n\t\"par\": [{\"index\":0,\"rgb\":[51,20,24]},{\"index\":0.13,\"rgb\":[90,32,35]},{\"index\":0.25,\"rgb\":[129,44,34]},{\"index\":0.38,\"rgb\":[159,68,25]},{\"index\":0.5,\"rgb\":[182,99,19]},{\"index\":0.63,\"rgb\":[199,134,22]},{\"index\":0.75,\"rgb\":[212,171,35]},{\"index\":0.88,\"rgb\":[221,210,54]},{\"index\":1,\"rgb\":[225,253,75]}],\n\n\t\"phase\": [{\"index\":0,\"rgb\":[145,105,18]},{\"index\":0.13,\"rgb\":[184,71,38]},{\"index\":0.25,\"rgb\":[186,58,115]},{\"index\":0.38,\"rgb\":[160,71,185]},{\"index\":0.5,\"rgb\":[110,97,218]},{\"index\":0.63,\"rgb\":[50,123,164]},{\"index\":0.75,\"rgb\":[31,131,110]},{\"index\":0.88,\"rgb\":[77,129,34]},{\"index\":1,\"rgb\":[145,105,18]}],\n\n\t\"salinity\": [{\"index\":0,\"rgb\":[42,24,108]},{\"index\":0.13,\"rgb\":[33,50,162]},{\"index\":0.25,\"rgb\":[15,90,145]},{\"index\":0.38,\"rgb\":[40,118,137]},{\"index\":0.5,\"rgb\":[59,146,135]},{\"index\":0.63,\"rgb\":[79,175,126]},{\"index\":0.75,\"rgb\":[120,203,104]},{\"index\":0.88,\"rgb\":[193,221,100]},{\"index\":1,\"rgb\":[253,239,154]}],\n\n\t\"temperature\": [{\"index\":0,\"rgb\":[4,35,51]},{\"index\":0.13,\"rgb\":[23,51,122]},{\"index\":0.25,\"rgb\":[85,59,157]},{\"index\":0.38,\"rgb\":[129,79,143]},{\"index\":0.5,\"rgb\":[175,95,130]},{\"index\":0.63,\"rgb\":[222,112,101]},{\"index\":0.75,\"rgb\":[249,146,66]},{\"index\":0.88,\"rgb\":[249,196,65]},{\"index\":1,\"rgb\":[232,250,91]}],\n\n\t\"turbidity\": [{\"index\":0,\"rgb\":[34,31,27]},{\"index\":0.13,\"rgb\":[65,50,41]},{\"index\":0.25,\"rgb\":[98,69,52]},{\"index\":0.38,\"rgb\":[131,89,57]},{\"index\":0.5,\"rgb\":[161,112,59]},{\"index\":0.63,\"rgb\":[185,140,66]},{\"index\":0.75,\"rgb\":[202,174,88]},{\"index\":0.88,\"rgb\":[216,209,126]},{\"index\":1,\"rgb\":[233,246,171]}],\n\n\t\"velocity-blue\": [{\"index\":0,\"rgb\":[17,32,64]},{\"index\":0.13,\"rgb\":[35,52,116]},{\"index\":0.25,\"rgb\":[29,81,156]},{\"index\":0.38,\"rgb\":[31,113,162]},{\"index\":0.5,\"rgb\":[50,144,169]},{\"index\":0.63,\"rgb\":[87,173,176]},{\"index\":0.75,\"rgb\":[149,196,189]},{\"index\":0.88,\"rgb\":[203,221,211]},{\"index\":1,\"rgb\":[254,251,230]}],\n\n\t\"velocity-green\": [{\"index\":0,\"rgb\":[23,35,19]},{\"index\":0.13,\"rgb\":[24,64,38]},{\"index\":0.25,\"rgb\":[11,95,45]},{\"index\":0.38,\"rgb\":[39,123,35]},{\"index\":0.5,\"rgb\":[95,146,12]},{\"index\":0.63,\"rgb\":[152,165,18]},{\"index\":0.75,\"rgb\":[201,186,69]},{\"index\":0.88,\"rgb\":[233,216,137]},{\"index\":1,\"rgb\":[255,253,205]}],\n\n\t\"cubehelix\": [{\"index\":0,\"rgb\":[0,0,0]},{\"index\":0.07,\"rgb\":[22,5,59]},{\"index\":0.13,\"rgb\":[60,4,105]},{\"index\":0.2,\"rgb\":[109,1,135]},{\"index\":0.27,\"rgb\":[161,0,147]},{\"index\":0.33,\"rgb\":[210,2,142]},{\"index\":0.4,\"rgb\":[251,11,123]},{\"index\":0.47,\"rgb\":[255,29,97]},{\"index\":0.53,\"rgb\":[255,54,69]},{\"index\":0.6,\"rgb\":[255,85,46]},{\"index\":0.67,\"rgb\":[255,120,34]},{\"index\":0.73,\"rgb\":[255,157,37]},{\"index\":0.8,\"rgb\":[241,191,57]},{\"index\":0.87,\"rgb\":[224,220,93]},{\"index\":0.93,\"rgb\":[218,241,142]},{\"index\":1,\"rgb\":[227,253,198]}]\n};\n\n},{}],126:[function(_dereq_,module,exports){\n/*\n * Ben Postlethwaite\n * January 2013\n * License MIT\n */\n'use strict';\n\nvar colorScale = _dereq_('./colorScale');\nvar lerp = _dereq_('lerp')\n\nmodule.exports = createColormap;\n\nfunction createColormap (spec) {\n    /*\n     * Default Options\n     */\n    var indicies, fromrgba, torgba,\n        nsteps, cmap, colormap, format,\n        nshades, colors, alpha, i;\n\n    if ( !spec ) spec = {};\n\n    nshades = (spec.nshades || 72) - 1;\n    format = spec.format || 'hex';\n\n    colormap = spec.colormap;\n    if (!colormap) colormap = 'jet';\n\n    if (typeof colormap === 'string') {\n        colormap = colormap.toLowerCase();\n\n        if (!colorScale[colormap]) {\n            throw Error(colormap + ' not a supported colorscale');\n        }\n\n        cmap = colorScale[colormap];\n\n    } else if (Array.isArray(colormap)) {\n        cmap = colormap.slice();\n\n    } else {\n        throw Error('unsupported colormap option', colormap);\n    }\n\n    if (cmap.length > nshades + 1) {\n        throw new Error(\n            colormap+' map requires nshades to be at least size '+cmap.length\n        );\n    }\n\n    if (!Array.isArray(spec.alpha)) {\n\n        if (typeof spec.alpha === 'number') {\n            alpha = [spec.alpha, spec.alpha];\n\n        } else {\n            alpha = [1, 1];\n        }\n\n    } else if (spec.alpha.length !== 2) {\n        alpha = [1, 1];\n\n    } else {\n        alpha = spec.alpha.slice();\n    }\n\n    // map index points from 0..1 to 0..n-1\n    indicies = cmap.map(function(c) {\n        return Math.round(c.index * nshades);\n    });\n\n    // Add alpha channel to the map\n    alpha[0] = Math.min(Math.max(alpha[0], 0), 1);\n    alpha[1] = Math.min(Math.max(alpha[1], 0), 1);\n\n    var steps = cmap.map(function(c, i) {\n        var index = cmap[i].index\n\n        var rgba = cmap[i].rgb.slice();\n\n        // if user supplies their own map use it\n        if (rgba.length === 4 && rgba[3] >= 0 && rgba[3] <= 1) {\n            return rgba\n        }\n        rgba[3] = alpha[0] + (alpha[1] - alpha[0])*index;\n\n        return rgba\n    })\n\n\n    /*\n     * map increasing linear values between indicies to\n     * linear steps in colorvalues\n     */\n    var colors = []\n    for (i = 0; i < indicies.length-1; ++i) {\n        nsteps = indicies[i+1] - indicies[i];\n        fromrgba = steps[i];\n        torgba = steps[i+1];\n\n        for (var j = 0; j < nsteps; j++) {\n            var amt = j / nsteps\n            colors.push([\n                Math.round(lerp(fromrgba[0], torgba[0], amt)),\n                Math.round(lerp(fromrgba[1], torgba[1], amt)),\n                Math.round(lerp(fromrgba[2], torgba[2], amt)),\n                lerp(fromrgba[3], torgba[3], amt)\n            ])\n        }\n    }\n\n    //add 1 step as last value\n    colors.push(cmap[cmap.length - 1].rgb.concat(alpha[1]))\n\n    if (format === 'hex') colors = colors.map( rgb2hex );\n    else if (format === 'rgbaString') colors = colors.map( rgbaStr );\n    else if (format === 'float') colors = colors.map( rgb2float );\n\n    return colors;\n};\n\nfunction rgb2float (rgba) {\n    return [\n        rgba[0] / 255,\n        rgba[1] / 255,\n        rgba[2] / 255,\n        rgba[3]\n    ]\n}\n\nfunction rgb2hex (rgba) {\n    var dig, hex = '#';\n    for (var i = 0; i < 3; ++i) {\n        dig = rgba[i];\n        dig = dig.toString(16);\n        hex += ('00' + dig).substr( dig.length );\n    }\n    return hex;\n}\n\nfunction rgbaStr (rgba) {\n    return 'rgba(' + rgba.join(',') + ')';\n}\n\n},{\"./colorScale\":125,\"lerp\":425}],127:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = compareAngle\n\nvar orient = _dereq_(\"robust-orientation\")\nvar sgn = _dereq_(\"signum\")\nvar twoSum = _dereq_(\"two-sum\")\nvar robustProduct = _dereq_(\"robust-product\")\nvar robustSum = _dereq_(\"robust-sum\")\n\nfunction testInterior(a, b, c) {\n  var x0 = twoSum(a[0], -b[0])\n  var y0 = twoSum(a[1], -b[1])\n  var x1 = twoSum(c[0], -b[0])\n  var y1 = twoSum(c[1], -b[1])\n\n  var d = robustSum(\n    robustProduct(x0, x1),\n    robustProduct(y0, y1))\n\n  return d[d.length-1] >= 0\n}\n\nfunction compareAngle(a, b, c, d) {\n  var bcd = orient(b, c, d)\n  if(bcd === 0) {\n    //Handle degenerate cases\n    var sabc = sgn(orient(a, b, c))\n    var sabd = sgn(orient(a, b, d))\n    if(sabc === sabd) {\n      if(sabc === 0) {\n        var ic = testInterior(a, b, c)\n        var id = testInterior(a, b, d)\n        if(ic === id) {\n          return 0\n        } else if(ic) {\n          return 1\n        } else {\n          return -1\n        }\n      }\n      return 0\n    } else if(sabd === 0) {\n      if(sabc > 0) {\n        return -1\n      } else if(testInterior(a, b, d)) {\n        return -1\n      } else {\n        return 1\n      }\n    } else if(sabc === 0) {\n      if(sabd > 0) {\n        return 1\n      } else if(testInterior(a, b, c)) {\n        return 1\n      } else {\n        return -1\n      }\n    }\n    return sgn(sabd - sabc)\n  }\n  var abc = orient(a, b, c)\n  if(abc > 0) {\n    if(bcd > 0 && orient(a, b, d) > 0) {\n      return 1\n    }\n    return -1\n  } else if(abc < 0) {\n    if(bcd > 0 || orient(a, b, d) > 0) {\n      return 1\n    }\n    return -1\n  } else {\n    var abd = orient(a, b, d)\n    if(abd > 0) {\n      return 1\n    } else {\n      if(testInterior(a, b, c)) {\n        return 1\n      } else {\n        return -1\n      }\n    }\n  }\n}\n},{\"robust-orientation\":510,\"robust-product\":511,\"robust-sum\":515,\"signum\":516,\"two-sum\":544}],128:[function(_dereq_,module,exports){\nmodule.exports = compareCells\n\nvar min = Math.min\n\nfunction compareInt(a, b) {\n  return a - b\n}\n\nfunction compareCells(a, b) {\n  var n = a.length\n    , t = a.length - b.length\n  if(t) {\n    return t\n  }\n  switch(n) {\n    case 0:\n      return 0\n    case 1:\n      return a[0] - b[0]\n    case 2:\n      return (a[0]+a[1]-b[0]-b[1]) ||\n             min(a[0],a[1]) - min(b[0],b[1])\n    case 3:\n      var l1 = a[0]+a[1]\n        , m1 = b[0]+b[1]\n      t = l1+a[2] - (m1+b[2])\n      if(t) {\n        return t\n      }\n      var l0 = min(a[0], a[1])\n        , m0 = min(b[0], b[1])\n      return min(l0, a[2]) - min(m0, b[2]) ||\n             min(l0+a[2], l1) - min(m0+b[2], m1)\n    case 4:\n      var aw=a[0], ax=a[1], ay=a[2], az=a[3]\n        , bw=b[0], bx=b[1], by=b[2], bz=b[3]\n      return (aw+ax+ay+az)-(bw+bx+by+bz) ||\n             min(aw,ax,ay,az)-min(bw,bx,by,bz,bw) ||\n             min(aw+ax,aw+ay,aw+az,ax+ay,ax+az,ay+az) -\n               min(bw+bx,bw+by,bw+bz,bx+by,bx+bz,by+bz) ||\n             min(aw+ax+ay,aw+ax+az,aw+ay+az,ax+ay+az) -\n               min(bw+bx+by,bw+bx+bz,bw+by+bz,bx+by+bz)\n    default:\n      var as = a.slice().sort(compareInt)\n      var bs = b.slice().sort(compareInt)\n      for(var i=0; i<n; ++i) {\n        t = as[i] - bs[i]\n        if(t) {\n          return t\n        }\n      }\n      return 0\n  }\n}\n\n},{}],129:[function(_dereq_,module,exports){\n'use strict'\n\nvar compareCells = _dereq_('compare-cell')\nvar parity = _dereq_('cell-orientation')\n\nmodule.exports = compareOrientedCells\n\nfunction compareOrientedCells(a, b) {\n  return compareCells(a, b) || parity(a) - parity(b)\n}\n\n},{\"cell-orientation\":112,\"compare-cell\":128}],130:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar convexHull1d = _dereq_('./lib/ch1d')\nvar convexHull2d = _dereq_('./lib/ch2d')\nvar convexHullnd = _dereq_('./lib/chnd')\n\nmodule.exports = convexHull\n\nfunction convexHull(points) {\n  var n = points.length\n  if(n === 0) {\n    return []\n  } else if(n === 1) {\n    return [[0]]\n  }\n  var d = points[0].length\n  if(d === 0) {\n    return []\n  } else if(d === 1) {\n    return convexHull1d(points)\n  } else if(d === 2) {\n    return convexHull2d(points)\n  }\n  return convexHullnd(points, d)\n}\n},{\"./lib/ch1d\":131,\"./lib/ch2d\":132,\"./lib/chnd\":133}],131:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = convexHull1d\n\nfunction convexHull1d(points) {\n  var lo = 0\n  var hi = 0\n  for(var i=1; i<points.length; ++i) {\n    if(points[i][0] < points[lo][0]) {\n      lo = i\n    }\n    if(points[i][0] > points[hi][0]) {\n      hi = i\n    }\n  }\n  if(lo < hi) {\n    return [[lo], [hi]]\n  } else if(lo > hi) {\n    return [[hi], [lo]]\n  } else {\n    return [[lo]]\n  }\n}\n},{}],132:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = convexHull2D\n\nvar monotoneHull = _dereq_('monotone-convex-hull-2d')\n\nfunction convexHull2D(points) {\n  var hull = monotoneHull(points)\n  var h = hull.length\n  if(h <= 2) {\n    return []\n  }\n  var edges = new Array(h)\n  var a = hull[h-1]\n  for(var i=0; i<h; ++i) {\n    var b = hull[i]\n    edges[i] = [a,b]\n    a = b\n  }\n  return edges\n}\n\n},{\"monotone-convex-hull-2d\":434}],133:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = convexHullnD\n\nvar ich = _dereq_('incremental-convex-hull')\nvar aff = _dereq_('affine-hull')\n\nfunction permute(points, front) {\n  var n = points.length\n  var npoints = new Array(n)\n  for(var i=0; i<front.length; ++i) {\n    npoints[i] = points[front[i]]\n  }\n  var ptr = front.length\n  for(var i=0; i<n; ++i) {\n    if(front.indexOf(i) < 0) {\n      npoints[ptr++] = points[i]\n    }\n  }\n  return npoints\n}\n\nfunction invPermute(cells, front) {\n  var nc = cells.length\n  var nf = front.length\n  for(var i=0; i<nc; ++i) {\n    var c = cells[i]\n    for(var j=0; j<c.length; ++j) {\n      var x = c[j]\n      if(x < nf) {\n        c[j] = front[x]\n      } else {\n        x = x - nf\n        for(var k=0; k<nf; ++k) {\n          if(x >= front[k]) {\n            x += 1\n          }\n        }\n        c[j] = x\n      }\n    }\n  }\n  return cells\n}\n\nfunction convexHullnD(points, d) {\n  try {\n    return ich(points, true)\n  } catch(e) {\n    //If point set is degenerate, try to find a basis and rerun it\n    var ah = aff(points)\n    if(ah.length <= d) {\n      //No basis, no try\n      return []\n    }\n    var npoints = permute(points, ah)\n    var nhull   = ich(npoints, true)\n    return invPermute(nhull, ah)\n  }\n}\n},{\"affine-hull\":62,\"incremental-convex-hull\":413}],134:[function(_dereq_,module,exports){\nmodule.exports = {\n  AFG: 'afghan',\n  ALA: '\\\\b\\\\wland',\n  ALB: 'albania',\n  DZA: 'algeria',\n  ASM: '^(?=.*americ).*samoa',\n  AND: 'andorra',\n  AGO: 'angola',\n  AIA: 'anguill?a',\n  ATA: 'antarctica',\n  ATG: 'antigua',\n  ARG: 'argentin',\n  ARM: 'armenia',\n  ABW: '^(?!.*bonaire).*\\\\baruba',\n  AUS: 'australia',\n  AUT: '^(?!.*hungary).*austria|\\\\baustri.*\\\\bemp',\n  AZE: 'azerbaijan',\n  BHS: 'bahamas',\n  BHR: 'bahrain',\n  BGD: 'bangladesh|^(?=.*east).*paki?stan',\n  BRB: 'barbados',\n  BLR: 'belarus|byelo',\n  BEL: '^(?!.*luxem).*belgium',\n  BLZ: 'belize|^(?=.*british).*honduras',\n  BEN: 'benin|dahome',\n  BMU: 'bermuda',\n  BTN: 'bhutan',\n  BOL: 'bolivia',\n  BES: '^(?=.*bonaire).*eustatius|^(?=.*carib).*netherlands|\\\\bbes.?islands',\n  BIH: 'herzegovina|bosnia',\n  BWA: 'botswana|bechuana',\n  BVT: 'bouvet',\n  BRA: 'brazil',\n  IOT: 'british.?indian.?ocean',\n  BRN: 'brunei',\n  BGR: 'bulgaria',\n  BFA: 'burkina|\\\\bfaso|upper.?volta',\n  BDI: 'burundi',\n  CPV: 'verde',\n  KHM: 'cambodia|kampuchea|khmer',\n  CMR: 'cameroon',\n  CAN: 'canada',\n  CYM: 'cayman',\n  CAF: '\\\\bcentral.african.republic',\n  TCD: '\\\\bchad',\n  CHL: '\\\\bchile',\n  CHN: '^(?!.*\\\\bmac)(?!.*\\\\bhong)(?!.*\\\\btai)(?!.*\\\\brep).*china|^(?=.*peo)(?=.*rep).*china',\n  CXR: 'christmas',\n  CCK: '\\\\bcocos|keeling',\n  COL: 'colombia',\n  COM: 'comoro',\n  COG: '^(?!.*\\\\bdem)(?!.*\\\\bd[\\\\.]?r)(?!.*kinshasa)(?!.*zaire)(?!.*belg)(?!.*l.opoldville)(?!.*free).*\\\\bcongo',\n  COK: '\\\\bcook',\n  CRI: 'costa.?rica',\n  CIV: 'ivoire|ivory',\n  HRV: 'croatia',\n  CUB: '\\\\bcuba',\n  CUW: '^(?!.*bonaire).*\\\\bcura(c|ç)ao',\n  CYP: 'cyprus',\n  CSK: 'czechoslovakia',\n  CZE: '^(?=.*rep).*czech|czechia|bohemia',\n  COD: '\\\\bdem.*congo|congo.*\\\\bdem|congo.*\\\\bd[\\\\.]?r|\\\\bd[\\\\.]?r.*congo|belgian.?congo|congo.?free.?state|kinshasa|zaire|l.opoldville|drc|droc|rdc',\n  DNK: 'denmark',\n  DJI: 'djibouti',\n  DMA: 'dominica(?!n)',\n  DOM: 'dominican.rep',\n  ECU: 'ecuador',\n  EGY: 'egypt',\n  SLV: 'el.?salvador',\n  GNQ: 'guine.*eq|eq.*guine|^(?=.*span).*guinea',\n  ERI: 'eritrea',\n  EST: 'estonia',\n  ETH: 'ethiopia|abyssinia',\n  FLK: 'falkland|malvinas',\n  FRO: 'faroe|faeroe',\n  FJI: 'fiji',\n  FIN: 'finland',\n  FRA: '^(?!.*\\\\bdep)(?!.*martinique).*france|french.?republic|\\\\bgaul',\n  GUF: '^(?=.*french).*guiana',\n  PYF: 'french.?polynesia|tahiti',\n  ATF: 'french.?southern',\n  GAB: 'gabon',\n  GMB: 'gambia',\n  GEO: '^(?!.*south).*georgia',\n  DDR: 'german.?democratic.?republic|democratic.?republic.*germany|east.germany',\n  DEU: '^(?!.*east).*germany|^(?=.*\\\\bfed.*\\\\brep).*german',\n  GHA: 'ghana|gold.?coast',\n  GIB: 'gibraltar',\n  GRC: 'greece|hellenic|hellas',\n  GRL: 'greenland',\n  GRD: 'grenada',\n  GLP: 'guadeloupe',\n  GUM: '\\\\bguam',\n  GTM: 'guatemala',\n  GGY: 'guernsey',\n  GIN: '^(?!.*eq)(?!.*span)(?!.*bissau)(?!.*portu)(?!.*new).*guinea',\n  GNB: 'bissau|^(?=.*portu).*guinea',\n  GUY: 'guyana|british.?guiana',\n  HTI: 'haiti',\n  HMD: 'heard.*mcdonald',\n  VAT: 'holy.?see|vatican|papal.?st',\n  HND: '^(?!.*brit).*honduras',\n  HKG: 'hong.?kong',\n  HUN: '^(?!.*austr).*hungary',\n  ISL: 'iceland',\n  IND: 'india(?!.*ocea)',\n  IDN: 'indonesia',\n  IRN: '\\\\biran|persia',\n  IRQ: '\\\\biraq|mesopotamia',\n  IRL: '(^ireland)|(^republic.*ireland)',\n  IMN: '^(?=.*isle).*\\\\bman',\n  ISR: 'israel',\n  ITA: 'italy',\n  JAM: 'jamaica',\n  JPN: 'japan',\n  JEY: 'jersey',\n  JOR: 'jordan',\n  KAZ: 'kazak',\n  KEN: 'kenya|british.?east.?africa|east.?africa.?prot',\n  KIR: 'kiribati',\n  PRK: '^(?=.*democrat|people|north|d.*p.*.r).*\\\\bkorea|dprk|korea.*(d.*p.*r)',\n  KWT: 'kuwait',\n  KGZ: 'kyrgyz|kirghiz',\n  LAO: '\\\\blaos?\\\\b',\n  LVA: 'latvia',\n  LBN: 'lebanon',\n  LSO: 'lesotho|basuto',\n  LBR: 'liberia',\n  LBY: 'libya',\n  LIE: 'liechtenstein',\n  LTU: 'lithuania',\n  LUX: '^(?!.*belg).*luxem',\n  MAC: 'maca(o|u)',\n  MDG: 'madagascar|malagasy',\n  MWI: 'malawi|nyasa',\n  MYS: 'malaysia',\n  MDV: 'maldive',\n  MLI: '\\\\bmali\\\\b',\n  MLT: '\\\\bmalta',\n  MHL: 'marshall',\n  MTQ: 'martinique',\n  MRT: 'mauritania',\n  MUS: 'mauritius',\n  MYT: '\\\\bmayotte',\n  MEX: '\\\\bmexic',\n  FSM: 'fed.*micronesia|micronesia.*fed',\n  MCO: 'monaco',\n  MNG: 'mongolia',\n  MNE: '^(?!.*serbia).*montenegro',\n  MSR: 'montserrat',\n  MAR: 'morocco|\\\\bmaroc',\n  MOZ: 'mozambique',\n  MMR: 'myanmar|burma',\n  NAM: 'namibia',\n  NRU: 'nauru',\n  NPL: 'nepal',\n  NLD: '^(?!.*\\\\bant)(?!.*\\\\bcarib).*netherlands',\n  ANT: '^(?=.*\\\\bant).*(nether|dutch)',\n  NCL: 'new.?caledonia',\n  NZL: 'new.?zealand',\n  NIC: 'nicaragua',\n  NER: '\\\\bniger(?!ia)',\n  NGA: 'nigeria',\n  NIU: 'niue',\n  NFK: 'norfolk',\n  MNP: 'mariana',\n  NOR: 'norway',\n  OMN: '\\\\boman|trucial',\n  PAK: '^(?!.*east).*paki?stan',\n  PLW: 'palau',\n  PSE: 'palestin|\\\\bgaza|west.?bank',\n  PAN: 'panama',\n  PNG: 'papua|new.?guinea',\n  PRY: 'paraguay',\n  PER: 'peru',\n  PHL: 'philippines',\n  PCN: 'pitcairn',\n  POL: 'poland',\n  PRT: 'portugal',\n  PRI: 'puerto.?rico',\n  QAT: 'qatar',\n  KOR: '^(?!.*d.*p.*r)(?!.*democrat)(?!.*people)(?!.*north).*\\\\bkorea(?!.*d.*p.*r)',\n  MDA: 'moldov|b(a|e)ssarabia',\n  REU: 'r(e|é)union',\n  ROU: 'r(o|u|ou)mania',\n  RUS: '\\\\brussia|soviet.?union|u\\\\.?s\\\\.?s\\\\.?r|socialist.?republics',\n  RWA: 'rwanda',\n  BLM: 'barth(e|é)lemy',\n  SHN: 'helena',\n  KNA: 'kitts|\\\\bnevis',\n  LCA: '\\\\blucia',\n  MAF: '^(?=.*collectivity).*martin|^(?=.*france).*martin(?!ique)|^(?=.*french).*martin(?!ique)',\n  SPM: 'miquelon',\n  VCT: 'vincent',\n  WSM: '^(?!.*amer).*samoa',\n  SMR: 'san.?marino',\n  STP: '\\\\bs(a|ã)o.?tom(e|é)',\n  SAU: '\\\\bsa\\\\w*.?arabia',\n  SEN: 'senegal',\n  SRB: '^(?!.*monte).*serbia',\n  SYC: 'seychell',\n  SLE: 'sierra',\n  SGP: 'singapore',\n  SXM: '^(?!.*martin)(?!.*saba).*maarten',\n  SVK: '^(?!.*cze).*slovak',\n  SVN: 'slovenia',\n  SLB: 'solomon',\n  SOM: 'somali',\n  ZAF: 'south.africa|s\\\\\\\\..?africa',\n  SGS: 'south.?georgia|sandwich',\n  SSD: '\\\\bs\\\\w*.?sudan',\n  ESP: 'spain',\n  LKA: 'sri.?lanka|ceylon',\n  SDN: '^(?!.*\\\\bs(?!u)).*sudan',\n  SUR: 'surinam|dutch.?guiana',\n  SJM: 'svalbard',\n  SWZ: 'swaziland',\n  SWE: 'sweden',\n  CHE: 'switz|swiss',\n  SYR: 'syria',\n  TWN: 'taiwan|taipei|formosa|^(?!.*peo)(?=.*rep).*china',\n  TJK: 'tajik',\n  THA: 'thailand|\\\\bsiam',\n  MKD: 'macedonia|fyrom',\n  TLS: '^(?=.*leste).*timor|^(?=.*east).*timor',\n  TGO: 'togo',\n  TKL: 'tokelau',\n  TON: 'tonga',\n  TTO: 'trinidad|tobago',\n  TUN: 'tunisia',\n  TUR: 'turkey',\n  TKM: 'turkmen',\n  TCA: 'turks',\n  TUV: 'tuvalu',\n  UGA: 'uganda',\n  UKR: 'ukrain',\n  ARE: 'emirates|^u\\\\.?a\\\\.?e\\\\.?$|united.?arab.?em',\n  GBR: 'united.?kingdom|britain|^u\\\\.?k\\\\.?$',\n  TZA: 'tanzania',\n  USA: 'united.?states\\\\b(?!.*islands)|\\\\bu\\\\.?s\\\\.?a\\\\.?\\\\b|^\\\\s*u\\\\.?s\\\\.?\\\\b(?!.*islands)',\n  UMI: 'minor.?outlying.?is',\n  URY: 'uruguay',\n  UZB: 'uzbek',\n  VUT: 'vanuatu|new.?hebrides',\n  VEN: 'venezuela',\n  VNM: '^(?!.*republic).*viet.?nam|^(?=.*socialist).*viet.?nam',\n  VGB: '^(?=.*\\\\bu\\\\.?\\\\s?k).*virgin|^(?=.*brit).*virgin|^(?=.*kingdom).*virgin',\n  VIR: '^(?=.*\\\\bu\\\\.?\\\\s?s).*virgin|^(?=.*states).*virgin',\n  WLF: 'futuna|wallis',\n  ESH: 'western.sahara',\n  YEM: '^(?!.*arab)(?!.*north)(?!.*sana)(?!.*peo)(?!.*dem)(?!.*south)(?!.*aden)(?!.*\\\\bp\\\\.?d\\\\.?r).*yemen',\n  YMD: '^(?=.*peo).*yemen|^(?!.*rep)(?=.*dem).*yemen|^(?=.*south).*yemen|^(?=.*aden).*yemen|^(?=.*\\\\bp\\\\.?d\\\\.?r).*yemen',\n  YUG: 'yugoslavia',\n  ZMB: 'zambia|northern.?rhodesia',\n  EAZ: 'zanzibar',\n  ZWE: 'zimbabwe|^(?!.*northern).*rhodesia'\n}\n\n},{}],135:[function(_dereq_,module,exports){\nmodule.exports=[\r\n\t\"xx-small\",\r\n\t\"x-small\",\r\n\t\"small\",\r\n\t\"medium\",\r\n\t\"large\",\r\n\t\"x-large\",\r\n\t\"xx-large\",\r\n\t\"larger\",\r\n\t\"smaller\"\r\n]\r\n\n},{}],136:[function(_dereq_,module,exports){\nmodule.exports=[\r\n\t\"normal\",\r\n\t\"condensed\",\r\n\t\"semi-condensed\",\r\n\t\"extra-condensed\",\r\n\t\"ultra-condensed\",\r\n\t\"expanded\",\r\n\t\"semi-expanded\",\r\n\t\"extra-expanded\",\r\n\t\"ultra-expanded\"\r\n]\r\n\n},{}],137:[function(_dereq_,module,exports){\nmodule.exports=[\r\n\t\"normal\",\r\n\t\"italic\",\r\n\t\"oblique\"\r\n]\r\n\n},{}],138:[function(_dereq_,module,exports){\nmodule.exports=[\r\n\t\"normal\",\r\n\t\"bold\",\r\n\t\"bolder\",\r\n\t\"lighter\",\r\n\t\"100\",\r\n\t\"200\",\r\n\t\"300\",\r\n\t\"400\",\r\n\t\"500\",\r\n\t\"600\",\r\n\t\"700\",\r\n\t\"800\",\r\n\t\"900\"\r\n]\r\n\n},{}],139:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nmodule.exports = {\r\n\tparse: _dereq_('./parse'),\r\n\tstringify: _dereq_('./stringify')\r\n}\r\n\n},{\"./parse\":141,\"./stringify\":142}],140:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar sizes = _dereq_('css-font-size-keywords')\r\n\r\nmodule.exports = {\r\n\tisSize: function isSize(value) {\r\n\t\treturn /^[\\d\\.]/.test(value)\r\n\t\t\t|| value.indexOf('/') !== -1\r\n\t\t\t|| sizes.indexOf(value) !== -1\r\n\t}\r\n}\r\n\n},{\"css-font-size-keywords\":135}],141:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar unquote = _dereq_('unquote')\r\nvar globalKeywords = _dereq_('css-global-keywords')\r\nvar systemFontKeywords = _dereq_('css-system-font-keywords')\r\nvar fontWeightKeywords = _dereq_('css-font-weight-keywords')\r\nvar fontStyleKeywords = _dereq_('css-font-style-keywords')\r\nvar fontStretchKeywords = _dereq_('css-font-stretch-keywords')\r\nvar splitBy = _dereq_('string-split-by')\r\nvar isSize = _dereq_('./lib/util').isSize\r\n\r\n\r\nmodule.exports = parseFont\r\n\r\n\r\nvar cache = parseFont.cache = {}\r\n\r\n\r\nfunction parseFont (value) {\r\n\tif (typeof value !== 'string') throw new Error('Font argument must be a string.')\r\n\r\n\tif (cache[value]) return cache[value]\r\n\r\n\tif (value === '') {\r\n\t\tthrow new Error('Cannot parse an empty string.')\r\n\t}\r\n\r\n\tif (systemFontKeywords.indexOf(value) !== -1) {\r\n\t\treturn cache[value] = {system: value}\r\n\t}\r\n\r\n\tvar font = {\r\n\t\tstyle: 'normal',\r\n\t\tvariant: 'normal',\r\n\t\tweight: 'normal',\r\n\t\tstretch: 'normal',\r\n\t\tlineHeight: 'normal',\r\n\t\tsize: '1rem',\r\n\t\tfamily: ['serif']\r\n\t}\r\n\r\n\tvar tokens = splitBy(value, /\\s+/)\r\n\tvar token\r\n\r\n\twhile (token = tokens.shift()) {\r\n\t\tif (globalKeywords.indexOf(token) !== -1) {\r\n\t\t\t['style', 'variant', 'weight', 'stretch'].forEach(function(prop) {\r\n\t\t\t\tfont[prop] = token\r\n\t\t\t})\r\n\r\n\t\t\treturn cache[value] = font\r\n\t\t}\r\n\r\n\t\tif (fontStyleKeywords.indexOf(token) !== -1) {\r\n\t\t\tfont.style = token\r\n\t\t\tcontinue\r\n\t\t}\r\n\r\n\t\tif (token === 'normal' || token === 'small-caps') {\r\n\t\t\tfont.variant = token\r\n\t\t\tcontinue\r\n\t\t}\r\n\r\n\t\tif (fontStretchKeywords.indexOf(token) !== -1) {\r\n\t\t\tfont.stretch = token\r\n\t\t\tcontinue\r\n\t\t}\r\n\r\n\t\tif (fontWeightKeywords.indexOf(token) !== -1) {\r\n\t\t\tfont.weight = token\r\n\t\t\tcontinue\r\n\t\t}\r\n\r\n\r\n\t\tif (isSize(token)) {\r\n\t\t\tvar parts = splitBy(token, '/')\r\n\t\t\tfont.size = parts[0]\r\n\t\t\tif (parts[1] != null) {\r\n\t\t\t\tfont.lineHeight = parseLineHeight(parts[1])\r\n\t\t\t}\r\n\t\t\telse if (tokens[0] === '/') {\r\n\t\t\t\ttokens.shift()\r\n\t\t\t\tfont.lineHeight = parseLineHeight(tokens.shift())\r\n \t\t\t}\r\n\r\n\t\t\tif (!tokens.length) {\r\n\t\t\t\tthrow new Error('Missing required font-family.')\r\n\t\t\t}\r\n\t\t\tfont.family = splitBy(tokens.join(' '), /\\s*,\\s*/).map(unquote)\r\n\r\n\t\t\treturn cache[value] = font\r\n\t\t}\r\n\r\n\t\tthrow new Error('Unknown or unsupported font token: ' + token)\r\n\t}\r\n\r\n\tthrow new Error('Missing required font-size.')\r\n}\r\n\r\n\r\nfunction parseLineHeight(value) {\r\n\tvar parsed = parseFloat(value)\r\n\tif (parsed.toString() === value) {\r\n\t\treturn parsed\r\n\t}\r\n\treturn value\r\n}\r\n\n},{\"./lib/util\":140,\"css-font-stretch-keywords\":136,\"css-font-style-keywords\":137,\"css-font-weight-keywords\":138,\"css-global-keywords\":143,\"css-system-font-keywords\":144,\"string-split-by\":529,\"unquote\":548}],142:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar pick = _dereq_('pick-by-alias')\r\nvar isSize = _dereq_('./lib/util').isSize\r\n\r\nvar globals = a2o(_dereq_('css-global-keywords'))\r\nvar systems = a2o(_dereq_('css-system-font-keywords'))\r\nvar weights = a2o(_dereq_('css-font-weight-keywords'))\r\nvar styles = a2o(_dereq_('css-font-style-keywords'))\r\nvar stretches = a2o(_dereq_('css-font-stretch-keywords'))\r\n\r\nvar variants = {'normal': 1, 'small-caps': 1}\r\nvar fams = {\r\n\t'serif': 1,\r\n\t'sans-serif': 1,\r\n\t'monospace': 1,\r\n\t'cursive': 1,\r\n\t'fantasy': 1,\r\n\t'system-ui': 1\r\n}\r\n\r\nvar defaults = {\r\n\tstyle: 'normal',\r\n\tvariant: 'normal',\r\n\tweight: 'normal',\r\n\tstretch: 'normal',\r\n\tsize: '1rem',\r\n\tlineHeight: 'normal',\r\n\tfamily: 'serif'\r\n}\r\n\r\nmodule.exports = function stringifyFont (o) {\r\n\to = pick(o, {\r\n\t\tstyle: 'style fontstyle fontStyle font-style slope distinction',\r\n\t\tvariant: 'variant font-variant fontVariant fontvariant var capitalization',\r\n\t\tweight: 'weight w font-weight fontWeight fontweight',\r\n\t\tstretch: 'stretch font-stretch fontStretch fontstretch width',\r\n\t\tsize: 'size s font-size fontSize fontsize height em emSize',\r\n\t\tlineHeight: 'lh line-height lineHeight lineheight leading',\r\n\t\tfamily: 'font family fontFamily font-family fontfamily type typeface face',\r\n\t\tsystem: 'system reserved default global',\r\n\t})\r\n\r\n\tif (o.system) {\r\n\t\tif (o.system) verify(o.system, systems)\r\n\t\treturn o.system\r\n\t}\r\n\r\n\tverify(o.style, styles)\r\n\tverify(o.variant, variants)\r\n\tverify(o.weight, weights)\r\n\tverify(o.stretch, stretches)\r\n\r\n\t// default root value is medium, but by default it's inherited\r\n\tif (o.size == null) o.size = defaults.size\r\n\tif (typeof o.size === 'number') o.size += 'px'\r\n\r\n\tif (!isSize) throw Error('Bad size value `' + o.size + '`')\r\n\r\n\t// many user-agents use serif, we don't detect that for consistency\r\n\tif (!o.family) o.family = defaults.family\r\n\tif (Array.isArray(o.family)) {\r\n\t\tif (!o.family.length) o.family = [defaults.family]\r\n\t\to.family = o.family.map(function (f) {\r\n\t\t\treturn fams[f] ? f : '\"' + f + '\"'\r\n\t\t}).join(', ')\r\n\t}\r\n\r\n\t// [ [ <'font-style'> || <font-variant-css21> || <'font-weight'> || <'font-stretch'> ]? <'font-size'> [ / <'line-height'> ]? <'font-family'> ]\r\n\tvar result = []\r\n\r\n\tresult.push(o.style)\r\n\tif (o.variant !== o.style) result.push(o.variant)\r\n\r\n\tif (o.weight !== o.variant &&\r\n\t\to.weight !== o.style) result.push(o.weight)\r\n\r\n\tif (o.stretch !== o.weight &&\r\n\t\to.stretch !== o.variant &&\r\n\t\to.stretch !== o.style) result.push(o.stretch)\r\n\r\n\tresult.push(o.size + (o.lineHeight == null || o.lineHeight === 'normal' || (o.lineHeight + '' === '1')  ? '' : ('/' + o.lineHeight)))\r\n\tresult.push(o.family)\r\n\r\n\treturn result.filter(Boolean).join(' ')\r\n}\r\n\r\nfunction verify (value, values) {\r\n\tif (value && !values[value] && !globals[value]) throw Error('Unknown keyword `' + value +'`')\r\n\r\n\treturn value\r\n}\r\n\r\n\r\n// ['a', 'b'] -> {a: true, b: true}\r\nfunction a2o (a) {\r\n\tvar o = {}\r\n\tfor (var i = 0; i < a.length; i++) {\r\n\t\to[a[i]] = 1\r\n\t}\r\n\treturn o\r\n}\r\n\n},{\"./lib/util\":140,\"css-font-stretch-keywords\":136,\"css-font-style-keywords\":137,\"css-font-weight-keywords\":138,\"css-global-keywords\":143,\"css-system-font-keywords\":144,\"pick-by-alias\":465}],143:[function(_dereq_,module,exports){\nmodule.exports=[\r\n\t\"inherit\",\r\n\t\"initial\",\r\n\t\"unset\"\r\n]\r\n\n},{}],144:[function(_dereq_,module,exports){\nmodule.exports=[\r\n\t\"caption\",\r\n\t\"icon\",\r\n\t\"menu\",\r\n\t\"message-box\",\r\n\t\"small-caption\",\r\n\t\"status-bar\"\r\n]\r\n\n},{}],145:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction dcubicHermite(p0, v0, p1, v1, t, f) {\n  var dh00 = 6*t*t-6*t,\n      dh10 = 3*t*t-4*t + 1,\n      dh01 = -6*t*t+6*t,\n      dh11 = 3*t*t-2*t\n  if(p0.length) {\n    if(!f) {\n      f = new Array(p0.length)\n    }\n    for(var i=p0.length-1; i>=0; --i) {\n      f[i] = dh00*p0[i] + dh10*v0[i] + dh01*p1[i] + dh11*v1[i]\n    }\n    return f\n  }\n  return dh00*p0 + dh10*v0 + dh01*p1[i] + dh11*v1\n}\n\nfunction cubicHermite(p0, v0, p1, v1, t, f) {\n  var ti  = (t-1), t2 = t*t, ti2 = ti*ti,\n      h00 = (1+2*t)*ti2,\n      h10 = t*ti2,\n      h01 = t2*(3-2*t),\n      h11 = t2*ti\n  if(p0.length) {\n    if(!f) {\n      f = new Array(p0.length)\n    }\n    for(var i=p0.length-1; i>=0; --i) {\n      f[i] = h00*p0[i] + h10*v0[i] + h01*p1[i] + h11*v1[i]\n    }\n    return f\n  }\n  return h00*p0 + h10*v0 + h01*p1 + h11*v1\n}\n\nmodule.exports = cubicHermite\nmodule.exports.derivative = dcubicHermite\n},{}],146:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar createThunk = _dereq_(\"./lib/thunk.js\")\n\nfunction Procedure() {\n  this.argTypes = []\n  this.shimArgs = []\n  this.arrayArgs = []\n  this.arrayBlockIndices = []\n  this.scalarArgs = []\n  this.offsetArgs = []\n  this.offsetArgIndex = []\n  this.indexArgs = []\n  this.shapeArgs = []\n  this.funcName = \"\"\n  this.pre = null\n  this.body = null\n  this.post = null\n  this.debug = false\n}\n\nfunction compileCwise(user_args) {\n  //Create procedure\n  var proc = new Procedure()\n  \n  //Parse blocks\n  proc.pre    = user_args.pre\n  proc.body   = user_args.body\n  proc.post   = user_args.post\n\n  //Parse arguments\n  var proc_args = user_args.args.slice(0)\n  proc.argTypes = proc_args\n  for(var i=0; i<proc_args.length; ++i) {\n    var arg_type = proc_args[i]\n    if(arg_type === \"array\" || (typeof arg_type === \"object\" && arg_type.blockIndices)) {\n      proc.argTypes[i] = \"array\"\n      proc.arrayArgs.push(i)\n      proc.arrayBlockIndices.push(arg_type.blockIndices ? arg_type.blockIndices : 0)\n      proc.shimArgs.push(\"array\" + i)\n      if(i < proc.pre.args.length && proc.pre.args[i].count>0) {\n        throw new Error(\"cwise: pre() block may not reference array args\")\n      }\n      if(i < proc.post.args.length && proc.post.args[i].count>0) {\n        throw new Error(\"cwise: post() block may not reference array args\")\n      }\n    } else if(arg_type === \"scalar\") {\n      proc.scalarArgs.push(i)\n      proc.shimArgs.push(\"scalar\" + i)\n    } else if(arg_type === \"index\") {\n      proc.indexArgs.push(i)\n      if(i < proc.pre.args.length && proc.pre.args[i].count > 0) {\n        throw new Error(\"cwise: pre() block may not reference array index\")\n      }\n      if(i < proc.body.args.length && proc.body.args[i].lvalue) {\n        throw new Error(\"cwise: body() block may not write to array index\")\n      }\n      if(i < proc.post.args.length && proc.post.args[i].count > 0) {\n        throw new Error(\"cwise: post() block may not reference array index\")\n      }\n    } else if(arg_type === \"shape\") {\n      proc.shapeArgs.push(i)\n      if(i < proc.pre.args.length && proc.pre.args[i].lvalue) {\n        throw new Error(\"cwise: pre() block may not write to array shape\")\n      }\n      if(i < proc.body.args.length && proc.body.args[i].lvalue) {\n        throw new Error(\"cwise: body() block may not write to array shape\")\n      }\n      if(i < proc.post.args.length && proc.post.args[i].lvalue) {\n        throw new Error(\"cwise: post() block may not write to array shape\")\n      }\n    } else if(typeof arg_type === \"object\" && arg_type.offset) {\n      proc.argTypes[i] = \"offset\"\n      proc.offsetArgs.push({ array: arg_type.array, offset:arg_type.offset })\n      proc.offsetArgIndex.push(i)\n    } else {\n      throw new Error(\"cwise: Unknown argument type \" + proc_args[i])\n    }\n  }\n  \n  //Make sure at least one array argument was specified\n  if(proc.arrayArgs.length <= 0) {\n    throw new Error(\"cwise: No array arguments specified\")\n  }\n  \n  //Make sure arguments are correct\n  if(proc.pre.args.length > proc_args.length) {\n    throw new Error(\"cwise: Too many arguments in pre() block\")\n  }\n  if(proc.body.args.length > proc_args.length) {\n    throw new Error(\"cwise: Too many arguments in body() block\")\n  }\n  if(proc.post.args.length > proc_args.length) {\n    throw new Error(\"cwise: Too many arguments in post() block\")\n  }\n\n  //Check debug flag\n  proc.debug = !!user_args.printCode || !!user_args.debug\n  \n  //Retrieve name\n  proc.funcName = user_args.funcName || \"cwise\"\n  \n  //Read in block size\n  proc.blockSize = user_args.blockSize || 64\n\n  return createThunk(proc)\n}\n\nmodule.exports = compileCwise\n\n},{\"./lib/thunk.js\":148}],147:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar uniq = _dereq_(\"uniq\")\n\n// This function generates very simple loops analogous to how you typically traverse arrays (the outermost loop corresponds to the slowest changing index, the innermost loop to the fastest changing index)\n// TODO: If two arrays have the same strides (and offsets) there is potential for decreasing the number of \"pointers\" and related variables. The drawback is that the type signature would become more specific and that there would thus be less potential for caching, but it might still be worth it, especially when dealing with large numbers of arguments.\nfunction innerFill(order, proc, body) {\n  var dimension = order.length\n    , nargs = proc.arrayArgs.length\n    , has_index = proc.indexArgs.length>0\n    , code = []\n    , vars = []\n    , idx=0, pidx=0, i, j\n  for(i=0; i<dimension; ++i) { // Iteration variables\n    vars.push([\"i\",i,\"=0\"].join(\"\"))\n  }\n  //Compute scan deltas\n  for(j=0; j<nargs; ++j) {\n    for(i=0; i<dimension; ++i) {\n      pidx = idx\n      idx = order[i]\n      if(i === 0) { // The innermost/fastest dimension's delta is simply its stride\n        vars.push([\"d\",j,\"s\",i,\"=t\",j,\"p\",idx].join(\"\"))\n      } else { // For other dimensions the delta is basically the stride minus something which essentially \"rewinds\" the previous (more inner) dimension\n        vars.push([\"d\",j,\"s\",i,\"=(t\",j,\"p\",idx,\"-s\",pidx,\"*t\",j,\"p\",pidx,\")\"].join(\"\"))\n      }\n    }\n  }\n  if (vars.length > 0) {\n    code.push(\"var \" + vars.join(\",\"))\n  }  \n  //Scan loop\n  for(i=dimension-1; i>=0; --i) { // Start at largest stride and work your way inwards\n    idx = order[i]\n    code.push([\"for(i\",i,\"=0;i\",i,\"<s\",idx,\";++i\",i,\"){\"].join(\"\"))\n  }\n  //Push body of inner loop\n  code.push(body)\n  //Advance scan pointers\n  for(i=0; i<dimension; ++i) {\n    pidx = idx\n    idx = order[i]\n    for(j=0; j<nargs; ++j) {\n      code.push([\"p\",j,\"+=d\",j,\"s\",i].join(\"\"))\n    }\n    if(has_index) {\n      if(i > 0) {\n        code.push([\"index[\",pidx,\"]-=s\",pidx].join(\"\"))\n      }\n      code.push([\"++index[\",idx,\"]\"].join(\"\"))\n    }\n    code.push(\"}\")\n  }\n  return code.join(\"\\n\")\n}\n\n// Generate \"outer\" loops that loop over blocks of data, applying \"inner\" loops to the blocks by manipulating the local variables in such a way that the inner loop only \"sees\" the current block.\n// TODO: If this is used, then the previous declaration (done by generateCwiseOp) of s* is essentially unnecessary.\n//       I believe the s* are not used elsewhere (in particular, I don't think they're used in the pre/post parts and \"shape\" is defined independently), so it would be possible to make defining the s* dependent on what loop method is being used.\nfunction outerFill(matched, order, proc, body) {\n  var dimension = order.length\n    , nargs = proc.arrayArgs.length\n    , blockSize = proc.blockSize\n    , has_index = proc.indexArgs.length > 0\n    , code = []\n  for(var i=0; i<nargs; ++i) {\n    code.push([\"var offset\",i,\"=p\",i].join(\"\"))\n  }\n  //Generate loops for unmatched dimensions\n  // The order in which these dimensions are traversed is fairly arbitrary (from small stride to large stride, for the first argument)\n  // TODO: It would be nice if the order in which these loops are placed would also be somehow \"optimal\" (at the very least we should check that it really doesn't hurt us if they're not).\n  for(var i=matched; i<dimension; ++i) {\n    code.push([\"for(var j\"+i+\"=SS[\", order[i], \"]|0;j\", i, \">0;){\"].join(\"\")) // Iterate back to front\n    code.push([\"if(j\",i,\"<\",blockSize,\"){\"].join(\"\")) // Either decrease j by blockSize (s = blockSize), or set it to zero (after setting s = j).\n    code.push([\"s\",order[i],\"=j\",i].join(\"\"))\n    code.push([\"j\",i,\"=0\"].join(\"\"))\n    code.push([\"}else{s\",order[i],\"=\",blockSize].join(\"\"))\n    code.push([\"j\",i,\"-=\",blockSize,\"}\"].join(\"\"))\n    if(has_index) {\n      code.push([\"index[\",order[i],\"]=j\",i].join(\"\"))\n    }\n  }\n  for(var i=0; i<nargs; ++i) {\n    var indexStr = [\"offset\"+i]\n    for(var j=matched; j<dimension; ++j) {\n      indexStr.push([\"j\",j,\"*t\",i,\"p\",order[j]].join(\"\"))\n    }\n    code.push([\"p\",i,\"=(\",indexStr.join(\"+\"),\")\"].join(\"\"))\n  }\n  code.push(innerFill(order, proc, body))\n  for(var i=matched; i<dimension; ++i) {\n    code.push(\"}\")\n  }\n  return code.join(\"\\n\")\n}\n\n//Count the number of compatible inner orders\n// This is the length of the longest common prefix of the arrays in orders.\n// Each array in orders lists the dimensions of the correspond ndarray in order of increasing stride.\n// This is thus the maximum number of dimensions that can be efficiently traversed by simple nested loops for all arrays.\nfunction countMatches(orders) {\n  var matched = 0, dimension = orders[0].length\n  while(matched < dimension) {\n    for(var j=1; j<orders.length; ++j) {\n      if(orders[j][matched] !== orders[0][matched]) {\n        return matched\n      }\n    }\n    ++matched\n  }\n  return matched\n}\n\n//Processes a block according to the given data types\n// Replaces variable names by different ones, either \"local\" ones (that are then ferried in and out of the given array) or ones matching the arguments that the function performing the ultimate loop will accept.\nfunction processBlock(block, proc, dtypes) {\n  var code = block.body\n  var pre = []\n  var post = []\n  for(var i=0; i<block.args.length; ++i) {\n    var carg = block.args[i]\n    if(carg.count <= 0) {\n      continue\n    }\n    var re = new RegExp(carg.name, \"g\")\n    var ptrStr = \"\"\n    var arrNum = proc.arrayArgs.indexOf(i)\n    switch(proc.argTypes[i]) {\n      case \"offset\":\n        var offArgIndex = proc.offsetArgIndex.indexOf(i)\n        var offArg = proc.offsetArgs[offArgIndex]\n        arrNum = offArg.array\n        ptrStr = \"+q\" + offArgIndex // Adds offset to the \"pointer\" in the array\n      case \"array\":\n        ptrStr = \"p\" + arrNum + ptrStr\n        var localStr = \"l\" + i\n        var arrStr = \"a\" + arrNum\n        if (proc.arrayBlockIndices[arrNum] === 0) { // Argument to body is just a single value from this array\n          if(carg.count === 1) { // Argument/array used only once(?)\n            if(dtypes[arrNum] === \"generic\") {\n              if(carg.lvalue) {\n                pre.push([\"var \", localStr, \"=\", arrStr, \".get(\", ptrStr, \")\"].join(\"\")) // Is this necessary if the argument is ONLY used as an lvalue? (keep in mind that we can have a += something, so we would actually need to check carg.rvalue)\n                code = code.replace(re, localStr)\n                post.push([arrStr, \".set(\", ptrStr, \",\", localStr,\")\"].join(\"\"))\n              } else {\n                code = code.replace(re, [arrStr, \".get(\", ptrStr, \")\"].join(\"\"))\n              }\n            } else {\n              code = code.replace(re, [arrStr, \"[\", ptrStr, \"]\"].join(\"\"))\n            }\n          } else if(dtypes[arrNum] === \"generic\") {\n            pre.push([\"var \", localStr, \"=\", arrStr, \".get(\", ptrStr, \")\"].join(\"\")) // TODO: Could we optimize by checking for carg.rvalue?\n            code = code.replace(re, localStr)\n            if(carg.lvalue) {\n              post.push([arrStr, \".set(\", ptrStr, \",\", localStr,\")\"].join(\"\"))\n            }\n          } else {\n            pre.push([\"var \", localStr, \"=\", arrStr, \"[\", ptrStr, \"]\"].join(\"\")) // TODO: Could we optimize by checking for carg.rvalue?\n            code = code.replace(re, localStr)\n            if(carg.lvalue) {\n              post.push([arrStr, \"[\", ptrStr, \"]=\", localStr].join(\"\"))\n            }\n          }\n        } else { // Argument to body is a \"block\"\n          var reStrArr = [carg.name], ptrStrArr = [ptrStr]\n          for(var j=0; j<Math.abs(proc.arrayBlockIndices[arrNum]); j++) {\n            reStrArr.push(\"\\\\s*\\\\[([^\\\\]]+)\\\\]\")\n            ptrStrArr.push(\"$\" + (j+1) + \"*t\" + arrNum + \"b\" + j) // Matched index times stride\n          }\n          re = new RegExp(reStrArr.join(\"\"), \"g\")\n          ptrStr = ptrStrArr.join(\"+\")\n          if(dtypes[arrNum] === \"generic\") {\n            /*if(carg.lvalue) {\n              pre.push([\"var \", localStr, \"=\", arrStr, \".get(\", ptrStr, \")\"].join(\"\")) // Is this necessary if the argument is ONLY used as an lvalue? (keep in mind that we can have a += something, so we would actually need to check carg.rvalue)\n              code = code.replace(re, localStr)\n              post.push([arrStr, \".set(\", ptrStr, \",\", localStr,\")\"].join(\"\"))\n            } else {\n              code = code.replace(re, [arrStr, \".get(\", ptrStr, \")\"].join(\"\"))\n            }*/\n            throw new Error(\"cwise: Generic arrays not supported in combination with blocks!\")\n          } else {\n            // This does not produce any local variables, even if variables are used multiple times. It would be possible to do so, but it would complicate things quite a bit.\n            code = code.replace(re, [arrStr, \"[\", ptrStr, \"]\"].join(\"\"))\n          }\n        }\n      break\n      case \"scalar\":\n        code = code.replace(re, \"Y\" + proc.scalarArgs.indexOf(i))\n      break\n      case \"index\":\n        code = code.replace(re, \"index\")\n      break\n      case \"shape\":\n        code = code.replace(re, \"shape\")\n      break\n    }\n  }\n  return [pre.join(\"\\n\"), code, post.join(\"\\n\")].join(\"\\n\").trim()\n}\n\nfunction typeSummary(dtypes) {\n  var summary = new Array(dtypes.length)\n  var allEqual = true\n  for(var i=0; i<dtypes.length; ++i) {\n    var t = dtypes[i]\n    var digits = t.match(/\\d+/)\n    if(!digits) {\n      digits = \"\"\n    } else {\n      digits = digits[0]\n    }\n    if(t.charAt(0) === 0) {\n      summary[i] = \"u\" + t.charAt(1) + digits\n    } else {\n      summary[i] = t.charAt(0) + digits\n    }\n    if(i > 0) {\n      allEqual = allEqual && summary[i] === summary[i-1]\n    }\n  }\n  if(allEqual) {\n    return summary[0]\n  }\n  return summary.join(\"\")\n}\n\n//Generates a cwise operator\nfunction generateCWiseOp(proc, typesig) {\n\n  //Compute dimension\n  // Arrays get put first in typesig, and there are two entries per array (dtype and order), so this gets the number of dimensions in the first array arg.\n  var dimension = (typesig[1].length - Math.abs(proc.arrayBlockIndices[0]))|0\n  var orders = new Array(proc.arrayArgs.length)\n  var dtypes = new Array(proc.arrayArgs.length)\n  for(var i=0; i<proc.arrayArgs.length; ++i) {\n    dtypes[i] = typesig[2*i]\n    orders[i] = typesig[2*i+1]\n  }\n  \n  //Determine where block and loop indices start and end\n  var blockBegin = [], blockEnd = [] // These indices are exposed as blocks\n  var loopBegin = [], loopEnd = [] // These indices are iterated over\n  var loopOrders = [] // orders restricted to the loop indices\n  for(var i=0; i<proc.arrayArgs.length; ++i) {\n    if (proc.arrayBlockIndices[i]<0) {\n      loopBegin.push(0)\n      loopEnd.push(dimension)\n      blockBegin.push(dimension)\n      blockEnd.push(dimension+proc.arrayBlockIndices[i])\n    } else {\n      loopBegin.push(proc.arrayBlockIndices[i]) // Non-negative\n      loopEnd.push(proc.arrayBlockIndices[i]+dimension)\n      blockBegin.push(0)\n      blockEnd.push(proc.arrayBlockIndices[i])\n    }\n    var newOrder = []\n    for(var j=0; j<orders[i].length; j++) {\n      if (loopBegin[i]<=orders[i][j] && orders[i][j]<loopEnd[i]) {\n        newOrder.push(orders[i][j]-loopBegin[i]) // If this is a loop index, put it in newOrder, subtracting loopBegin, to make sure that all loopOrders are using a common set of indices.\n      }\n    }\n    loopOrders.push(newOrder)\n  }\n\n  //First create arguments for procedure\n  var arglist = [\"SS\"] // SS is the overall shape over which we iterate\n  var code = [\"'use strict'\"]\n  var vars = []\n  \n  for(var j=0; j<dimension; ++j) {\n    vars.push([\"s\", j, \"=SS[\", j, \"]\"].join(\"\")) // The limits for each dimension.\n  }\n  for(var i=0; i<proc.arrayArgs.length; ++i) {\n    arglist.push(\"a\"+i) // Actual data array\n    arglist.push(\"t\"+i) // Strides\n    arglist.push(\"p\"+i) // Offset in the array at which the data starts (also used for iterating over the data)\n    \n    for(var j=0; j<dimension; ++j) { // Unpack the strides into vars for looping\n      vars.push([\"t\",i,\"p\",j,\"=t\",i,\"[\",loopBegin[i]+j,\"]\"].join(\"\"))\n    }\n    \n    for(var j=0; j<Math.abs(proc.arrayBlockIndices[i]); ++j) { // Unpack the strides into vars for block iteration\n      vars.push([\"t\",i,\"b\",j,\"=t\",i,\"[\",blockBegin[i]+j,\"]\"].join(\"\"))\n    }\n  }\n  for(var i=0; i<proc.scalarArgs.length; ++i) {\n    arglist.push(\"Y\" + i)\n  }\n  if(proc.shapeArgs.length > 0) {\n    vars.push(\"shape=SS.slice(0)\") // Makes the shape over which we iterate available to the user defined functions (so you can use width/height for example)\n  }\n  if(proc.indexArgs.length > 0) {\n    // Prepare an array to keep track of the (logical) indices, initialized to dimension zeroes.\n    var zeros = new Array(dimension)\n    for(var i=0; i<dimension; ++i) {\n      zeros[i] = \"0\"\n    }\n    vars.push([\"index=[\", zeros.join(\",\"), \"]\"].join(\"\"))\n  }\n  for(var i=0; i<proc.offsetArgs.length; ++i) { // Offset arguments used for stencil operations\n    var off_arg = proc.offsetArgs[i]\n    var init_string = []\n    for(var j=0; j<off_arg.offset.length; ++j) {\n      if(off_arg.offset[j] === 0) {\n        continue\n      } else if(off_arg.offset[j] === 1) {\n        init_string.push([\"t\", off_arg.array, \"p\", j].join(\"\"))      \n      } else {\n        init_string.push([off_arg.offset[j], \"*t\", off_arg.array, \"p\", j].join(\"\"))\n      }\n    }\n    if(init_string.length === 0) {\n      vars.push(\"q\" + i + \"=0\")\n    } else {\n      vars.push([\"q\", i, \"=\", init_string.join(\"+\")].join(\"\"))\n    }\n  }\n\n  //Prepare this variables\n  var thisVars = uniq([].concat(proc.pre.thisVars)\n                      .concat(proc.body.thisVars)\n                      .concat(proc.post.thisVars))\n  vars = vars.concat(thisVars)\n  if (vars.length > 0) {\n    code.push(\"var \" + vars.join(\",\"))\n  }\n  for(var i=0; i<proc.arrayArgs.length; ++i) {\n    code.push(\"p\"+i+\"|=0\")\n  }\n  \n  //Inline prelude\n  if(proc.pre.body.length > 3) {\n    code.push(processBlock(proc.pre, proc, dtypes))\n  }\n\n  //Process body\n  var body = processBlock(proc.body, proc, dtypes)\n  var matched = countMatches(loopOrders)\n  if(matched < dimension) {\n    code.push(outerFill(matched, loopOrders[0], proc, body)) // TODO: Rather than passing loopOrders[0], it might be interesting to look at passing an order that represents the majority of the arguments for example.\n  } else {\n    code.push(innerFill(loopOrders[0], proc, body))\n  }\n\n  //Inline epilog\n  if(proc.post.body.length > 3) {\n    code.push(processBlock(proc.post, proc, dtypes))\n  }\n  \n  if(proc.debug) {\n    console.log(\"-----Generated cwise routine for \", typesig, \":\\n\" + code.join(\"\\n\") + \"\\n----------\")\n  }\n  \n  var loopName = [(proc.funcName||\"unnamed\"), \"_cwise_loop_\", orders[0].join(\"s\"),\"m\",matched,typeSummary(dtypes)].join(\"\")\n  var f = new Function([\"function \",loopName,\"(\", arglist.join(\",\"),\"){\", code.join(\"\\n\"),\"} return \", loopName].join(\"\"))\n  return f()\n}\nmodule.exports = generateCWiseOp\n\n},{\"uniq\":547}],148:[function(_dereq_,module,exports){\n\"use strict\"\n\n// The function below is called when constructing a cwise function object, and does the following:\n// A function object is constructed which accepts as argument a compilation function and returns another function.\n// It is this other function that is eventually returned by createThunk, and this function is the one that actually\n// checks whether a certain pattern of arguments has already been used before and compiles new loops as needed.\n// The compilation passed to the first function object is used for compiling new functions.\n// Once this function object is created, it is called with compile as argument, where the first argument of compile\n// is bound to \"proc\" (essentially containing a preprocessed version of the user arguments to cwise).\n// So createThunk roughly works like this:\n// function createThunk(proc) {\n//   var thunk = function(compileBound) {\n//     var CACHED = {}\n//     return function(arrays and scalars) {\n//       if (dtype and order of arrays in CACHED) {\n//         var func = CACHED[dtype and order of arrays]\n//       } else {\n//         var func = CACHED[dtype and order of arrays] = compileBound(dtype and order of arrays)\n//       }\n//       return func(arrays and scalars)\n//     }\n//   }\n//   return thunk(compile.bind1(proc))\n// }\n\nvar compile = _dereq_(\"./compile.js\")\n\nfunction createThunk(proc) {\n  var code = [\"'use strict'\", \"var CACHED={}\"]\n  var vars = []\n  var thunkName = proc.funcName + \"_cwise_thunk\"\n  \n  //Build thunk\n  code.push([\"return function \", thunkName, \"(\", proc.shimArgs.join(\",\"), \"){\"].join(\"\"))\n  var typesig = []\n  var string_typesig = []\n  var proc_args = [[\"array\",proc.arrayArgs[0],\".shape.slice(\", // Slice shape so that we only retain the shape over which we iterate (which gets passed to the cwise operator as SS).\n                    Math.max(0,proc.arrayBlockIndices[0]),proc.arrayBlockIndices[0]<0?(\",\"+proc.arrayBlockIndices[0]+\")\"):\")\"].join(\"\")]\n  var shapeLengthConditions = [], shapeConditions = []\n  // Process array arguments\n  for(var i=0; i<proc.arrayArgs.length; ++i) {\n    var j = proc.arrayArgs[i]\n    vars.push([\"t\", j, \"=array\", j, \".dtype,\",\n               \"r\", j, \"=array\", j, \".order\"].join(\"\"))\n    typesig.push(\"t\" + j)\n    typesig.push(\"r\" + j)\n    string_typesig.push(\"t\"+j)\n    string_typesig.push(\"r\"+j+\".join()\")\n    proc_args.push(\"array\" + j + \".data\")\n    proc_args.push(\"array\" + j + \".stride\")\n    proc_args.push(\"array\" + j + \".offset|0\")\n    if (i>0) { // Gather conditions to check for shape equality (ignoring block indices)\n      shapeLengthConditions.push(\"array\" + proc.arrayArgs[0] + \".shape.length===array\" + j + \".shape.length+\" + (Math.abs(proc.arrayBlockIndices[0])-Math.abs(proc.arrayBlockIndices[i])))\n      shapeConditions.push(\"array\" + proc.arrayArgs[0] + \".shape[shapeIndex+\" + Math.max(0,proc.arrayBlockIndices[0]) + \"]===array\" + j + \".shape[shapeIndex+\" + Math.max(0,proc.arrayBlockIndices[i]) + \"]\")\n    }\n  }\n  // Check for shape equality\n  if (proc.arrayArgs.length > 1) {\n    code.push(\"if (!(\" + shapeLengthConditions.join(\" && \") + \")) throw new Error('cwise: Arrays do not all have the same dimensionality!')\")\n    code.push(\"for(var shapeIndex=array\" + proc.arrayArgs[0] + \".shape.length-\" + Math.abs(proc.arrayBlockIndices[0]) + \"; shapeIndex-->0;) {\")\n    code.push(\"if (!(\" + shapeConditions.join(\" && \") + \")) throw new Error('cwise: Arrays do not all have the same shape!')\")\n    code.push(\"}\")\n  }\n  // Process scalar arguments\n  for(var i=0; i<proc.scalarArgs.length; ++i) {\n    proc_args.push(\"scalar\" + proc.scalarArgs[i])\n  }\n  // Check for cached function (and if not present, generate it)\n  vars.push([\"type=[\", string_typesig.join(\",\"), \"].join()\"].join(\"\"))\n  vars.push(\"proc=CACHED[type]\")\n  code.push(\"var \" + vars.join(\",\"))\n  \n  code.push([\"if(!proc){\",\n             \"CACHED[type]=proc=compile([\", typesig.join(\",\"), \"])}\",\n             \"return proc(\", proc_args.join(\",\"), \")}\"].join(\"\"))\n\n  if(proc.debug) {\n    console.log(\"-----Generated thunk:\\n\" + code.join(\"\\n\") + \"\\n----------\")\n  }\n  \n  //Compile thunk\n  var thunk = new Function(\"compile\", code.join(\"\\n\"))\n  return thunk(compile.bind(undefined, proc))\n}\n\nmodule.exports = createThunk\n\n},{\"./compile.js\":147}],149:[function(_dereq_,module,exports){\nmodule.exports = _dereq_(\"cwise-compiler\")\n},{\"cwise-compiler\":146}],150:[function(_dereq_,module,exports){\n'use strict';\n\nvar copy             = _dereq_('es5-ext/object/copy')\n  , normalizeOptions = _dereq_('es5-ext/object/normalize-options')\n  , ensureCallable   = _dereq_('es5-ext/object/valid-callable')\n  , map              = _dereq_('es5-ext/object/map')\n  , callable         = _dereq_('es5-ext/object/valid-callable')\n  , validValue       = _dereq_('es5-ext/object/valid-value')\n\n  , bind = Function.prototype.bind, defineProperty = Object.defineProperty\n  , hasOwnProperty = Object.prototype.hasOwnProperty\n  , define;\n\ndefine = function (name, desc, options) {\n\tvar value = validValue(desc) && callable(desc.value), dgs;\n\tdgs = copy(desc);\n\tdelete dgs.writable;\n\tdelete dgs.value;\n\tdgs.get = function () {\n\t\tif (!options.overwriteDefinition && hasOwnProperty.call(this, name)) return value;\n\t\tdesc.value = bind.call(value, options.resolveContext ? options.resolveContext(this) : this);\n\t\tdefineProperty(this, name, desc);\n\t\treturn this[name];\n\t};\n\treturn dgs;\n};\n\nmodule.exports = function (props/*, options*/) {\n\tvar options = normalizeOptions(arguments[1]);\n\tif (options.resolveContext != null) ensureCallable(options.resolveContext);\n\treturn map(props, function (desc, name) { return define(name, desc, options); });\n};\n\n},{\"es5-ext/object/copy\":189,\"es5-ext/object/map\":198,\"es5-ext/object/normalize-options\":199,\"es5-ext/object/valid-callable\":203,\"es5-ext/object/valid-value\":205}],151:[function(_dereq_,module,exports){\n'use strict';\n\nvar assign        = _dereq_('es5-ext/object/assign')\n  , normalizeOpts = _dereq_('es5-ext/object/normalize-options')\n  , isCallable    = _dereq_('es5-ext/object/is-callable')\n  , contains      = _dereq_('es5-ext/string/#/contains')\n\n  , d;\n\nd = module.exports = function (dscr, value/*, options*/) {\n\tvar c, e, w, options, desc;\n\tif ((arguments.length < 2) || (typeof dscr !== 'string')) {\n\t\toptions = value;\n\t\tvalue = dscr;\n\t\tdscr = null;\n\t} else {\n\t\toptions = arguments[2];\n\t}\n\tif (dscr == null) {\n\t\tc = w = true;\n\t\te = false;\n\t} else {\n\t\tc = contains.call(dscr, 'c');\n\t\te = contains.call(dscr, 'e');\n\t\tw = contains.call(dscr, 'w');\n\t}\n\n\tdesc = { value: value, configurable: c, enumerable: e, writable: w };\n\treturn !options ? desc : assign(normalizeOpts(options), desc);\n};\n\nd.gs = function (dscr, get, set/*, options*/) {\n\tvar c, e, options, desc;\n\tif (typeof dscr !== 'string') {\n\t\toptions = set;\n\t\tset = get;\n\t\tget = dscr;\n\t\tdscr = null;\n\t} else {\n\t\toptions = arguments[3];\n\t}\n\tif (get == null) {\n\t\tget = undefined;\n\t} else if (!isCallable(get)) {\n\t\toptions = get;\n\t\tget = set = undefined;\n\t} else if (set == null) {\n\t\tset = undefined;\n\t} else if (!isCallable(set)) {\n\t\toptions = set;\n\t\tset = undefined;\n\t}\n\tif (dscr == null) {\n\t\tc = true;\n\t\te = false;\n\t} else {\n\t\tc = contains.call(dscr, 'c');\n\t\te = contains.call(dscr, 'e');\n\t}\n\n\tdesc = { get: get, set: set, configurable: c, enumerable: e };\n\treturn !options ? desc : assign(normalizeOpts(options), desc);\n};\n\n},{\"es5-ext/object/assign\":186,\"es5-ext/object/is-callable\":192,\"es5-ext/object/normalize-options\":199,\"es5-ext/string/#/contains\":206}],152:[function(_dereq_,module,exports){\n// https://d3js.org/d3-array/ v1.2.4 Copyright 2018 Mike Bostock\n(function (global, factory) {\ntypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\ntypeof define === 'function' && define.amd ? define(['exports'], factory) :\n(factory((global.d3 = global.d3 || {})));\n}(this, (function (exports) { 'use strict';\n\nfunction ascending(a, b) {\n  return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;\n}\n\nfunction bisector(compare) {\n  if (compare.length === 1) compare = ascendingComparator(compare);\n  return {\n    left: function(a, x, lo, hi) {\n      if (lo == null) lo = 0;\n      if (hi == null) hi = a.length;\n      while (lo < hi) {\n        var mid = lo + hi >>> 1;\n        if (compare(a[mid], x) < 0) lo = mid + 1;\n        else hi = mid;\n      }\n      return lo;\n    },\n    right: function(a, x, lo, hi) {\n      if (lo == null) lo = 0;\n      if (hi == null) hi = a.length;\n      while (lo < hi) {\n        var mid = lo + hi >>> 1;\n        if (compare(a[mid], x) > 0) hi = mid;\n        else lo = mid + 1;\n      }\n      return lo;\n    }\n  };\n}\n\nfunction ascendingComparator(f) {\n  return function(d, x) {\n    return ascending(f(d), x);\n  };\n}\n\nvar ascendingBisect = bisector(ascending);\nvar bisectRight = ascendingBisect.right;\nvar bisectLeft = ascendingBisect.left;\n\nfunction pairs(array, f) {\n  if (f == null) f = pair;\n  var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);\n  while (i < n) pairs[i] = f(p, p = array[++i]);\n  return pairs;\n}\n\nfunction pair(a, b) {\n  return [a, b];\n}\n\nfunction cross(values0, values1, reduce) {\n  var n0 = values0.length,\n      n1 = values1.length,\n      values = new Array(n0 * n1),\n      i0,\n      i1,\n      i,\n      value0;\n\n  if (reduce == null) reduce = pair;\n\n  for (i0 = i = 0; i0 < n0; ++i0) {\n    for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {\n      values[i] = reduce(value0, values1[i1]);\n    }\n  }\n\n  return values;\n}\n\nfunction descending(a, b) {\n  return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;\n}\n\nfunction number(x) {\n  return x === null ? NaN : +x;\n}\n\nfunction variance(values, valueof) {\n  var n = values.length,\n      m = 0,\n      i = -1,\n      mean = 0,\n      value,\n      delta,\n      sum = 0;\n\n  if (valueof == null) {\n    while (++i < n) {\n      if (!isNaN(value = number(values[i]))) {\n        delta = value - mean;\n        mean += delta / ++m;\n        sum += delta * (value - mean);\n      }\n    }\n  }\n\n  else {\n    while (++i < n) {\n      if (!isNaN(value = number(valueof(values[i], i, values)))) {\n        delta = value - mean;\n        mean += delta / ++m;\n        sum += delta * (value - mean);\n      }\n    }\n  }\n\n  if (m > 1) return sum / (m - 1);\n}\n\nfunction deviation(array, f) {\n  var v = variance(array, f);\n  return v ? Math.sqrt(v) : v;\n}\n\nfunction extent(values, valueof) {\n  var n = values.length,\n      i = -1,\n      value,\n      min,\n      max;\n\n  if (valueof == null) {\n    while (++i < n) { // Find the first comparable value.\n      if ((value = values[i]) != null && value >= value) {\n        min = max = value;\n        while (++i < n) { // Compare the remaining values.\n          if ((value = values[i]) != null) {\n            if (min > value) min = value;\n            if (max < value) max = value;\n          }\n        }\n      }\n    }\n  }\n\n  else {\n    while (++i < n) { // Find the first comparable value.\n      if ((value = valueof(values[i], i, values)) != null && value >= value) {\n        min = max = value;\n        while (++i < n) { // Compare the remaining values.\n          if ((value = valueof(values[i], i, values)) != null) {\n            if (min > value) min = value;\n            if (max < value) max = value;\n          }\n        }\n      }\n    }\n  }\n\n  return [min, max];\n}\n\nvar array = Array.prototype;\n\nvar slice = array.slice;\nvar map = array.map;\n\nfunction constant(x) {\n  return function() {\n    return x;\n  };\n}\n\nfunction identity(x) {\n  return x;\n}\n\nfunction range(start, stop, step) {\n  start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;\n\n  var i = -1,\n      n = Math.max(0, Math.ceil((stop - start) / step)) | 0,\n      range = new Array(n);\n\n  while (++i < n) {\n    range[i] = start + i * step;\n  }\n\n  return range;\n}\n\nvar e10 = Math.sqrt(50),\n    e5 = Math.sqrt(10),\n    e2 = Math.sqrt(2);\n\nfunction ticks(start, stop, count) {\n  var reverse,\n      i = -1,\n      n,\n      ticks,\n      step;\n\n  stop = +stop, start = +start, count = +count;\n  if (start === stop && count > 0) return [start];\n  if (reverse = stop < start) n = start, start = stop, stop = n;\n  if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];\n\n  if (step > 0) {\n    start = Math.ceil(start / step);\n    stop = Math.floor(stop / step);\n    ticks = new Array(n = Math.ceil(stop - start + 1));\n    while (++i < n) ticks[i] = (start + i) * step;\n  } else {\n    start = Math.floor(start * step);\n    stop = Math.ceil(stop * step);\n    ticks = new Array(n = Math.ceil(start - stop + 1));\n    while (++i < n) ticks[i] = (start - i) / step;\n  }\n\n  if (reverse) ticks.reverse();\n\n  return ticks;\n}\n\nfunction tickIncrement(start, stop, count) {\n  var step = (stop - start) / Math.max(0, count),\n      power = Math.floor(Math.log(step) / Math.LN10),\n      error = step / Math.pow(10, power);\n  return power >= 0\n      ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)\n      : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);\n}\n\nfunction tickStep(start, stop, count) {\n  var step0 = Math.abs(stop - start) / Math.max(0, count),\n      step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),\n      error = step0 / step1;\n  if (error >= e10) step1 *= 10;\n  else if (error >= e5) step1 *= 5;\n  else if (error >= e2) step1 *= 2;\n  return stop < start ? -step1 : step1;\n}\n\nfunction sturges(values) {\n  return Math.ceil(Math.log(values.length) / Math.LN2) + 1;\n}\n\nfunction histogram() {\n  var value = identity,\n      domain = extent,\n      threshold = sturges;\n\n  function histogram(data) {\n    var i,\n        n = data.length,\n        x,\n        values = new Array(n);\n\n    for (i = 0; i < n; ++i) {\n      values[i] = value(data[i], i, data);\n    }\n\n    var xz = domain(values),\n        x0 = xz[0],\n        x1 = xz[1],\n        tz = threshold(values, x0, x1);\n\n    // Convert number of thresholds into uniform thresholds.\n    if (!Array.isArray(tz)) {\n      tz = tickStep(x0, x1, tz);\n      tz = range(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive\n    }\n\n    // Remove any thresholds outside the domain.\n    var m = tz.length;\n    while (tz[0] <= x0) tz.shift(), --m;\n    while (tz[m - 1] > x1) tz.pop(), --m;\n\n    var bins = new Array(m + 1),\n        bin;\n\n    // Initialize bins.\n    for (i = 0; i <= m; ++i) {\n      bin = bins[i] = [];\n      bin.x0 = i > 0 ? tz[i - 1] : x0;\n      bin.x1 = i < m ? tz[i] : x1;\n    }\n\n    // Assign data to bins by value, ignoring any outside the domain.\n    for (i = 0; i < n; ++i) {\n      x = values[i];\n      if (x0 <= x && x <= x1) {\n        bins[bisectRight(tz, x, 0, m)].push(data[i]);\n      }\n    }\n\n    return bins;\n  }\n\n  histogram.value = function(_) {\n    return arguments.length ? (value = typeof _ === \"function\" ? _ : constant(_), histogram) : value;\n  };\n\n  histogram.domain = function(_) {\n    return arguments.length ? (domain = typeof _ === \"function\" ? _ : constant([_[0], _[1]]), histogram) : domain;\n  };\n\n  histogram.thresholds = function(_) {\n    return arguments.length ? (threshold = typeof _ === \"function\" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;\n  };\n\n  return histogram;\n}\n\nfunction quantile(values, p, valueof) {\n  if (valueof == null) valueof = number;\n  if (!(n = values.length)) return;\n  if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);\n  if (p >= 1) return +valueof(values[n - 1], n - 1, values);\n  var n,\n      i = (n - 1) * p,\n      i0 = Math.floor(i),\n      value0 = +valueof(values[i0], i0, values),\n      value1 = +valueof(values[i0 + 1], i0 + 1, values);\n  return value0 + (value1 - value0) * (i - i0);\n}\n\nfunction freedmanDiaconis(values, min, max) {\n  values = map.call(values, number).sort(ascending);\n  return Math.ceil((max - min) / (2 * (quantile(values, 0.75) - quantile(values, 0.25)) * Math.pow(values.length, -1 / 3)));\n}\n\nfunction scott(values, min, max) {\n  return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));\n}\n\nfunction max(values, valueof) {\n  var n = values.length,\n      i = -1,\n      value,\n      max;\n\n  if (valueof == null) {\n    while (++i < n) { // Find the first comparable value.\n      if ((value = values[i]) != null && value >= value) {\n        max = value;\n        while (++i < n) { // Compare the remaining values.\n          if ((value = values[i]) != null && value > max) {\n            max = value;\n          }\n        }\n      }\n    }\n  }\n\n  else {\n    while (++i < n) { // Find the first comparable value.\n      if ((value = valueof(values[i], i, values)) != null && value >= value) {\n        max = value;\n        while (++i < n) { // Compare the remaining values.\n          if ((value = valueof(values[i], i, values)) != null && value > max) {\n            max = value;\n          }\n        }\n      }\n    }\n  }\n\n  return max;\n}\n\nfunction mean(values, valueof) {\n  var n = values.length,\n      m = n,\n      i = -1,\n      value,\n      sum = 0;\n\n  if (valueof == null) {\n    while (++i < n) {\n      if (!isNaN(value = number(values[i]))) sum += value;\n      else --m;\n    }\n  }\n\n  else {\n    while (++i < n) {\n      if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;\n      else --m;\n    }\n  }\n\n  if (m) return sum / m;\n}\n\nfunction median(values, valueof) {\n  var n = values.length,\n      i = -1,\n      value,\n      numbers = [];\n\n  if (valueof == null) {\n    while (++i < n) {\n      if (!isNaN(value = number(values[i]))) {\n        numbers.push(value);\n      }\n    }\n  }\n\n  else {\n    while (++i < n) {\n      if (!isNaN(value = number(valueof(values[i], i, values)))) {\n        numbers.push(value);\n      }\n    }\n  }\n\n  return quantile(numbers.sort(ascending), 0.5);\n}\n\nfunction merge(arrays) {\n  var n = arrays.length,\n      m,\n      i = -1,\n      j = 0,\n      merged,\n      array;\n\n  while (++i < n) j += arrays[i].length;\n  merged = new Array(j);\n\n  while (--n >= 0) {\n    array = arrays[n];\n    m = array.length;\n    while (--m >= 0) {\n      merged[--j] = array[m];\n    }\n  }\n\n  return merged;\n}\n\nfunction min(values, valueof) {\n  var n = values.length,\n      i = -1,\n      value,\n      min;\n\n  if (valueof == null) {\n    while (++i < n) { // Find the first comparable value.\n      if ((value = values[i]) != null && value >= value) {\n        min = value;\n        while (++i < n) { // Compare the remaining values.\n          if ((value = values[i]) != null && min > value) {\n            min = value;\n          }\n        }\n      }\n    }\n  }\n\n  else {\n    while (++i < n) { // Find the first comparable value.\n      if ((value = valueof(values[i], i, values)) != null && value >= value) {\n        min = value;\n        while (++i < n) { // Compare the remaining values.\n          if ((value = valueof(values[i], i, values)) != null && min > value) {\n            min = value;\n          }\n        }\n      }\n    }\n  }\n\n  return min;\n}\n\nfunction permute(array, indexes) {\n  var i = indexes.length, permutes = new Array(i);\n  while (i--) permutes[i] = array[indexes[i]];\n  return permutes;\n}\n\nfunction scan(values, compare) {\n  if (!(n = values.length)) return;\n  var n,\n      i = 0,\n      j = 0,\n      xi,\n      xj = values[j];\n\n  if (compare == null) compare = ascending;\n\n  while (++i < n) {\n    if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {\n      xj = xi, j = i;\n    }\n  }\n\n  if (compare(xj, xj) === 0) return j;\n}\n\nfunction shuffle(array, i0, i1) {\n  var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),\n      t,\n      i;\n\n  while (m) {\n    i = Math.random() * m-- | 0;\n    t = array[m + i0];\n    array[m + i0] = array[i + i0];\n    array[i + i0] = t;\n  }\n\n  return array;\n}\n\nfunction sum(values, valueof) {\n  var n = values.length,\n      i = -1,\n      value,\n      sum = 0;\n\n  if (valueof == null) {\n    while (++i < n) {\n      if (value = +values[i]) sum += value; // Note: zero and null are equivalent.\n    }\n  }\n\n  else {\n    while (++i < n) {\n      if (value = +valueof(values[i], i, values)) sum += value;\n    }\n  }\n\n  return sum;\n}\n\nfunction transpose(matrix) {\n  if (!(n = matrix.length)) return [];\n  for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {\n    for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {\n      row[j] = matrix[j][i];\n    }\n  }\n  return transpose;\n}\n\nfunction length(d) {\n  return d.length;\n}\n\nfunction zip() {\n  return transpose(arguments);\n}\n\nexports.bisect = bisectRight;\nexports.bisectRight = bisectRight;\nexports.bisectLeft = bisectLeft;\nexports.ascending = ascending;\nexports.bisector = bisector;\nexports.cross = cross;\nexports.descending = descending;\nexports.deviation = deviation;\nexports.extent = extent;\nexports.histogram = histogram;\nexports.thresholdFreedmanDiaconis = freedmanDiaconis;\nexports.thresholdScott = scott;\nexports.thresholdSturges = sturges;\nexports.max = max;\nexports.mean = mean;\nexports.median = median;\nexports.merge = merge;\nexports.min = min;\nexports.pairs = pairs;\nexports.permute = permute;\nexports.quantile = quantile;\nexports.range = range;\nexports.scan = scan;\nexports.shuffle = shuffle;\nexports.sum = sum;\nexports.ticks = ticks;\nexports.tickIncrement = tickIncrement;\nexports.tickStep = tickStep;\nexports.transpose = transpose;\nexports.variance = variance;\nexports.zip = zip;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],153:[function(_dereq_,module,exports){\n// https://d3js.org/d3-collection/ Version 1.0.4. Copyright 2017 Mike Bostock.\n(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n\ttypeof define === 'function' && define.amd ? define(['exports'], factory) :\n\t(factory((global.d3 = global.d3 || {})));\n}(this, (function (exports) { 'use strict';\n\nvar prefix = \"$\";\n\nfunction Map() {}\n\nMap.prototype = map.prototype = {\n  constructor: Map,\n  has: function(key) {\n    return (prefix + key) in this;\n  },\n  get: function(key) {\n    return this[prefix + key];\n  },\n  set: function(key, value) {\n    this[prefix + key] = value;\n    return this;\n  },\n  remove: function(key) {\n    var property = prefix + key;\n    return property in this && delete this[property];\n  },\n  clear: function() {\n    for (var property in this) if (property[0] === prefix) delete this[property];\n  },\n  keys: function() {\n    var keys = [];\n    for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));\n    return keys;\n  },\n  values: function() {\n    var values = [];\n    for (var property in this) if (property[0] === prefix) values.push(this[property]);\n    return values;\n  },\n  entries: function() {\n    var entries = [];\n    for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});\n    return entries;\n  },\n  size: function() {\n    var size = 0;\n    for (var property in this) if (property[0] === prefix) ++size;\n    return size;\n  },\n  empty: function() {\n    for (var property in this) if (property[0] === prefix) return false;\n    return true;\n  },\n  each: function(f) {\n    for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);\n  }\n};\n\nfunction map(object, f) {\n  var map = new Map;\n\n  // Copy constructor.\n  if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });\n\n  // Index array by numeric index or specified key function.\n  else if (Array.isArray(object)) {\n    var i = -1,\n        n = object.length,\n        o;\n\n    if (f == null) while (++i < n) map.set(i, object[i]);\n    else while (++i < n) map.set(f(o = object[i], i, object), o);\n  }\n\n  // Convert object to map.\n  else if (object) for (var key in object) map.set(key, object[key]);\n\n  return map;\n}\n\nvar nest = function() {\n  var keys = [],\n      sortKeys = [],\n      sortValues,\n      rollup,\n      nest;\n\n  function apply(array, depth, createResult, setResult) {\n    if (depth >= keys.length) {\n      if (sortValues != null) array.sort(sortValues);\n      return rollup != null ? rollup(array) : array;\n    }\n\n    var i = -1,\n        n = array.length,\n        key = keys[depth++],\n        keyValue,\n        value,\n        valuesByKey = map(),\n        values,\n        result = createResult();\n\n    while (++i < n) {\n      if (values = valuesByKey.get(keyValue = key(value = array[i]) + \"\")) {\n        values.push(value);\n      } else {\n        valuesByKey.set(keyValue, [value]);\n      }\n    }\n\n    valuesByKey.each(function(values, key) {\n      setResult(result, key, apply(values, depth, createResult, setResult));\n    });\n\n    return result;\n  }\n\n  function entries(map$$1, depth) {\n    if (++depth > keys.length) return map$$1;\n    var array, sortKey = sortKeys[depth - 1];\n    if (rollup != null && depth >= keys.length) array = map$$1.entries();\n    else array = [], map$$1.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });\n    return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;\n  }\n\n  return nest = {\n    object: function(array) { return apply(array, 0, createObject, setObject); },\n    map: function(array) { return apply(array, 0, createMap, setMap); },\n    entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },\n    key: function(d) { keys.push(d); return nest; },\n    sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },\n    sortValues: function(order) { sortValues = order; return nest; },\n    rollup: function(f) { rollup = f; return nest; }\n  };\n};\n\nfunction createObject() {\n  return {};\n}\n\nfunction setObject(object, key, value) {\n  object[key] = value;\n}\n\nfunction createMap() {\n  return map();\n}\n\nfunction setMap(map$$1, key, value) {\n  map$$1.set(key, value);\n}\n\nfunction Set() {}\n\nvar proto = map.prototype;\n\nSet.prototype = set.prototype = {\n  constructor: Set,\n  has: proto.has,\n  add: function(value) {\n    value += \"\";\n    this[prefix + value] = value;\n    return this;\n  },\n  remove: proto.remove,\n  clear: proto.clear,\n  values: proto.keys,\n  size: proto.size,\n  empty: proto.empty,\n  each: proto.each\n};\n\nfunction set(object, f) {\n  var set = new Set;\n\n  // Copy constructor.\n  if (object instanceof Set) object.each(function(value) { set.add(value); });\n\n  // Otherwise, assume it’s an array.\n  else if (object) {\n    var i = -1, n = object.length;\n    if (f == null) while (++i < n) set.add(object[i]);\n    else while (++i < n) set.add(f(object[i], i, object));\n  }\n\n  return set;\n}\n\nvar keys = function(map) {\n  var keys = [];\n  for (var key in map) keys.push(key);\n  return keys;\n};\n\nvar values = function(map) {\n  var values = [];\n  for (var key in map) values.push(map[key]);\n  return values;\n};\n\nvar entries = function(map) {\n  var entries = [];\n  for (var key in map) entries.push({key: key, value: map[key]});\n  return entries;\n};\n\nexports.nest = nest;\nexports.set = set;\nexports.map = map;\nexports.keys = keys;\nexports.values = values;\nexports.entries = entries;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],154:[function(_dereq_,module,exports){\n// https://d3js.org/d3-color/ v1.2.3 Copyright 2018 Mike Bostock\n(function (global, factory) {\ntypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\ntypeof define === 'function' && define.amd ? define(['exports'], factory) :\n(factory((global.d3 = global.d3 || {})));\n}(this, (function (exports) { 'use strict';\n\nfunction define(constructor, factory, prototype) {\n  constructor.prototype = factory.prototype = prototype;\n  prototype.constructor = constructor;\n}\n\nfunction extend(parent, definition) {\n  var prototype = Object.create(parent.prototype);\n  for (var key in definition) prototype[key] = definition[key];\n  return prototype;\n}\n\nfunction Color() {}\n\nvar darker = 0.7;\nvar brighter = 1 / darker;\n\nvar reI = \"\\\\s*([+-]?\\\\d+)\\\\s*\",\n    reN = \"\\\\s*([+-]?\\\\d*\\\\.?\\\\d+(?:[eE][+-]?\\\\d+)?)\\\\s*\",\n    reP = \"\\\\s*([+-]?\\\\d*\\\\.?\\\\d+(?:[eE][+-]?\\\\d+)?)%\\\\s*\",\n    reHex3 = /^#([0-9a-f]{3})$/,\n    reHex6 = /^#([0-9a-f]{6})$/,\n    reRgbInteger = new RegExp(\"^rgb\\\\(\" + [reI, reI, reI] + \"\\\\)$\"),\n    reRgbPercent = new RegExp(\"^rgb\\\\(\" + [reP, reP, reP] + \"\\\\)$\"),\n    reRgbaInteger = new RegExp(\"^rgba\\\\(\" + [reI, reI, reI, reN] + \"\\\\)$\"),\n    reRgbaPercent = new RegExp(\"^rgba\\\\(\" + [reP, reP, reP, reN] + \"\\\\)$\"),\n    reHslPercent = new RegExp(\"^hsl\\\\(\" + [reN, reP, reP] + \"\\\\)$\"),\n    reHslaPercent = new RegExp(\"^hsla\\\\(\" + [reN, reP, reP, reN] + \"\\\\)$\");\n\nvar named = {\n  aliceblue: 0xf0f8ff,\n  antiquewhite: 0xfaebd7,\n  aqua: 0x00ffff,\n  aquamarine: 0x7fffd4,\n  azure: 0xf0ffff,\n  beige: 0xf5f5dc,\n  bisque: 0xffe4c4,\n  black: 0x000000,\n  blanchedalmond: 0xffebcd,\n  blue: 0x0000ff,\n  blueviolet: 0x8a2be2,\n  brown: 0xa52a2a,\n  burlywood: 0xdeb887,\n  cadetblue: 0x5f9ea0,\n  chartreuse: 0x7fff00,\n  chocolate: 0xd2691e,\n  coral: 0xff7f50,\n  cornflowerblue: 0x6495ed,\n  cornsilk: 0xfff8dc,\n  crimson: 0xdc143c,\n  cyan: 0x00ffff,\n  darkblue: 0x00008b,\n  darkcyan: 0x008b8b,\n  darkgoldenrod: 0xb8860b,\n  darkgray: 0xa9a9a9,\n  darkgreen: 0x006400,\n  darkgrey: 0xa9a9a9,\n  darkkhaki: 0xbdb76b,\n  darkmagenta: 0x8b008b,\n  darkolivegreen: 0x556b2f,\n  darkorange: 0xff8c00,\n  darkorchid: 0x9932cc,\n  darkred: 0x8b0000,\n  darksalmon: 0xe9967a,\n  darkseagreen: 0x8fbc8f,\n  darkslateblue: 0x483d8b,\n  darkslategray: 0x2f4f4f,\n  darkslategrey: 0x2f4f4f,\n  darkturquoise: 0x00ced1,\n  darkviolet: 0x9400d3,\n  deeppink: 0xff1493,\n  deepskyblue: 0x00bfff,\n  dimgray: 0x696969,\n  dimgrey: 0x696969,\n  dodgerblue: 0x1e90ff,\n  firebrick: 0xb22222,\n  floralwhite: 0xfffaf0,\n  forestgreen: 0x228b22,\n  fuchsia: 0xff00ff,\n  gainsboro: 0xdcdcdc,\n  ghostwhite: 0xf8f8ff,\n  gold: 0xffd700,\n  goldenrod: 0xdaa520,\n  gray: 0x808080,\n  green: 0x008000,\n  greenyellow: 0xadff2f,\n  grey: 0x808080,\n  honeydew: 0xf0fff0,\n  hotpink: 0xff69b4,\n  indianred: 0xcd5c5c,\n  indigo: 0x4b0082,\n  ivory: 0xfffff0,\n  khaki: 0xf0e68c,\n  lavender: 0xe6e6fa,\n  lavenderblush: 0xfff0f5,\n  lawngreen: 0x7cfc00,\n  lemonchiffon: 0xfffacd,\n  lightblue: 0xadd8e6,\n  lightcoral: 0xf08080,\n  lightcyan: 0xe0ffff,\n  lightgoldenrodyellow: 0xfafad2,\n  lightgray: 0xd3d3d3,\n  lightgreen: 0x90ee90,\n  lightgrey: 0xd3d3d3,\n  lightpink: 0xffb6c1,\n  lightsalmon: 0xffa07a,\n  lightseagreen: 0x20b2aa,\n  lightskyblue: 0x87cefa,\n  lightslategray: 0x778899,\n  lightslategrey: 0x778899,\n  lightsteelblue: 0xb0c4de,\n  lightyellow: 0xffffe0,\n  lime: 0x00ff00,\n  limegreen: 0x32cd32,\n  linen: 0xfaf0e6,\n  magenta: 0xff00ff,\n  maroon: 0x800000,\n  mediumaquamarine: 0x66cdaa,\n  mediumblue: 0x0000cd,\n  mediumorchid: 0xba55d3,\n  mediumpurple: 0x9370db,\n  mediumseagreen: 0x3cb371,\n  mediumslateblue: 0x7b68ee,\n  mediumspringgreen: 0x00fa9a,\n  mediumturquoise: 0x48d1cc,\n  mediumvioletred: 0xc71585,\n  midnightblue: 0x191970,\n  mintcream: 0xf5fffa,\n  mistyrose: 0xffe4e1,\n  moccasin: 0xffe4b5,\n  navajowhite: 0xffdead,\n  navy: 0x000080,\n  oldlace: 0xfdf5e6,\n  olive: 0x808000,\n  olivedrab: 0x6b8e23,\n  orange: 0xffa500,\n  orangered: 0xff4500,\n  orchid: 0xda70d6,\n  palegoldenrod: 0xeee8aa,\n  palegreen: 0x98fb98,\n  paleturquoise: 0xafeeee,\n  palevioletred: 0xdb7093,\n  papayawhip: 0xffefd5,\n  peachpuff: 0xffdab9,\n  peru: 0xcd853f,\n  pink: 0xffc0cb,\n  plum: 0xdda0dd,\n  powderblue: 0xb0e0e6,\n  purple: 0x800080,\n  rebeccapurple: 0x663399,\n  red: 0xff0000,\n  rosybrown: 0xbc8f8f,\n  royalblue: 0x4169e1,\n  saddlebrown: 0x8b4513,\n  salmon: 0xfa8072,\n  sandybrown: 0xf4a460,\n  seagreen: 0x2e8b57,\n  seashell: 0xfff5ee,\n  sienna: 0xa0522d,\n  silver: 0xc0c0c0,\n  skyblue: 0x87ceeb,\n  slateblue: 0x6a5acd,\n  slategray: 0x708090,\n  slategrey: 0x708090,\n  snow: 0xfffafa,\n  springgreen: 0x00ff7f,\n  steelblue: 0x4682b4,\n  tan: 0xd2b48c,\n  teal: 0x008080,\n  thistle: 0xd8bfd8,\n  tomato: 0xff6347,\n  turquoise: 0x40e0d0,\n  violet: 0xee82ee,\n  wheat: 0xf5deb3,\n  white: 0xffffff,\n  whitesmoke: 0xf5f5f5,\n  yellow: 0xffff00,\n  yellowgreen: 0x9acd32\n};\n\ndefine(Color, color, {\n  displayable: function() {\n    return this.rgb().displayable();\n  },\n  hex: function() {\n    return this.rgb().hex();\n  },\n  toString: function() {\n    return this.rgb() + \"\";\n  }\n});\n\nfunction color(format) {\n  var m;\n  format = (format + \"\").trim().toLowerCase();\n  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\n      : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000\n      : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)\n      : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)\n      : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)\n      : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)\n      : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)\n      : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)\n      : named.hasOwnProperty(format) ? rgbn(named[format])\n      : format === \"transparent\" ? new Rgb(NaN, NaN, NaN, 0)\n      : null;\n}\n\nfunction rgbn(n) {\n  return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);\n}\n\nfunction rgba(r, g, b, a) {\n  if (a <= 0) r = g = b = NaN;\n  return new Rgb(r, g, b, a);\n}\n\nfunction rgbConvert(o) {\n  if (!(o instanceof Color)) o = color(o);\n  if (!o) return new Rgb;\n  o = o.rgb();\n  return new Rgb(o.r, o.g, o.b, o.opacity);\n}\n\nfunction rgb(r, g, b, opacity) {\n  return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);\n}\n\nfunction Rgb(r, g, b, opacity) {\n  this.r = +r;\n  this.g = +g;\n  this.b = +b;\n  this.opacity = +opacity;\n}\n\ndefine(Rgb, rgb, extend(Color, {\n  brighter: function(k) {\n    k = k == null ? brighter : Math.pow(brighter, k);\n    return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);\n  },\n  darker: function(k) {\n    k = k == null ? darker : Math.pow(darker, k);\n    return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);\n  },\n  rgb: function() {\n    return this;\n  },\n  displayable: function() {\n    return (0 <= this.r && this.r <= 255)\n        && (0 <= this.g && this.g <= 255)\n        && (0 <= this.b && this.b <= 255)\n        && (0 <= this.opacity && this.opacity <= 1);\n  },\n  hex: function() {\n    return \"#\" + hex(this.r) + hex(this.g) + hex(this.b);\n  },\n  toString: function() {\n    var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));\n    return (a === 1 ? \"rgb(\" : \"rgba(\")\n        + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + \", \"\n        + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + \", \"\n        + Math.max(0, Math.min(255, Math.round(this.b) || 0))\n        + (a === 1 ? \")\" : \", \" + a + \")\");\n  }\n}));\n\nfunction hex(value) {\n  value = Math.max(0, Math.min(255, Math.round(value) || 0));\n  return (value < 16 ? \"0\" : \"\") + value.toString(16);\n}\n\nfunction hsla(h, s, l, a) {\n  if (a <= 0) h = s = l = NaN;\n  else if (l <= 0 || l >= 1) h = s = NaN;\n  else if (s <= 0) h = NaN;\n  return new Hsl(h, s, l, a);\n}\n\nfunction hslConvert(o) {\n  if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);\n  if (!(o instanceof Color)) o = color(o);\n  if (!o) return new Hsl;\n  if (o instanceof Hsl) return o;\n  o = o.rgb();\n  var r = o.r / 255,\n      g = o.g / 255,\n      b = o.b / 255,\n      min = Math.min(r, g, b),\n      max = Math.max(r, g, b),\n      h = NaN,\n      s = max - min,\n      l = (max + min) / 2;\n  if (s) {\n    if (r === max) h = (g - b) / s + (g < b) * 6;\n    else if (g === max) h = (b - r) / s + 2;\n    else h = (r - g) / s + 4;\n    s /= l < 0.5 ? max + min : 2 - max - min;\n    h *= 60;\n  } else {\n    s = l > 0 && l < 1 ? 0 : h;\n  }\n  return new Hsl(h, s, l, o.opacity);\n}\n\nfunction hsl(h, s, l, opacity) {\n  return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);\n}\n\nfunction Hsl(h, s, l, opacity) {\n  this.h = +h;\n  this.s = +s;\n  this.l = +l;\n  this.opacity = +opacity;\n}\n\ndefine(Hsl, hsl, extend(Color, {\n  brighter: function(k) {\n    k = k == null ? brighter : Math.pow(brighter, k);\n    return new Hsl(this.h, this.s, this.l * k, this.opacity);\n  },\n  darker: function(k) {\n    k = k == null ? darker : Math.pow(darker, k);\n    return new Hsl(this.h, this.s, this.l * k, this.opacity);\n  },\n  rgb: function() {\n    var h = this.h % 360 + (this.h < 0) * 360,\n        s = isNaN(h) || isNaN(this.s) ? 0 : this.s,\n        l = this.l,\n        m2 = l + (l < 0.5 ? l : 1 - l) * s,\n        m1 = 2 * l - m2;\n    return new Rgb(\n      hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),\n      hsl2rgb(h, m1, m2),\n      hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),\n      this.opacity\n    );\n  },\n  displayable: function() {\n    return (0 <= this.s && this.s <= 1 || isNaN(this.s))\n        && (0 <= this.l && this.l <= 1)\n        && (0 <= this.opacity && this.opacity <= 1);\n  }\n}));\n\n/* From FvD 13.37, CSS Color Module Level 3 */\nfunction hsl2rgb(h, m1, m2) {\n  return (h < 60 ? m1 + (m2 - m1) * h / 60\n      : h < 180 ? m2\n      : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60\n      : m1) * 255;\n}\n\nvar deg2rad = Math.PI / 180;\nvar rad2deg = 180 / Math.PI;\n\n// https://beta.observablehq.com/@mbostock/lab-and-rgb\nvar K = 18,\n    Xn = 0.96422,\n    Yn = 1,\n    Zn = 0.82521,\n    t0 = 4 / 29,\n    t1 = 6 / 29,\n    t2 = 3 * t1 * t1,\n    t3 = t1 * t1 * t1;\n\nfunction labConvert(o) {\n  if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);\n  if (o instanceof Hcl) {\n    if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);\n    var h = o.h * deg2rad;\n    return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);\n  }\n  if (!(o instanceof Rgb)) o = rgbConvert(o);\n  var r = rgb2lrgb(o.r),\n      g = rgb2lrgb(o.g),\n      b = rgb2lrgb(o.b),\n      y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;\n  if (r === g && g === b) x = z = y; else {\n    x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);\n    z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);\n  }\n  return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);\n}\n\nfunction gray(l, opacity) {\n  return new Lab(l, 0, 0, opacity == null ? 1 : opacity);\n}\n\nfunction lab(l, a, b, opacity) {\n  return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);\n}\n\nfunction Lab(l, a, b, opacity) {\n  this.l = +l;\n  this.a = +a;\n  this.b = +b;\n  this.opacity = +opacity;\n}\n\ndefine(Lab, lab, extend(Color, {\n  brighter: function(k) {\n    return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);\n  },\n  darker: function(k) {\n    return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);\n  },\n  rgb: function() {\n    var y = (this.l + 16) / 116,\n        x = isNaN(this.a) ? y : y + this.a / 500,\n        z = isNaN(this.b) ? y : y - this.b / 200;\n    x = Xn * lab2xyz(x);\n    y = Yn * lab2xyz(y);\n    z = Zn * lab2xyz(z);\n    return new Rgb(\n      lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),\n      lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),\n      lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),\n      this.opacity\n    );\n  }\n}));\n\nfunction xyz2lab(t) {\n  return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;\n}\n\nfunction lab2xyz(t) {\n  return t > t1 ? t * t * t : t2 * (t - t0);\n}\n\nfunction lrgb2rgb(x) {\n  return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);\n}\n\nfunction rgb2lrgb(x) {\n  return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);\n}\n\nfunction hclConvert(o) {\n  if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);\n  if (!(o instanceof Lab)) o = labConvert(o);\n  if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);\n  var h = Math.atan2(o.b, o.a) * rad2deg;\n  return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);\n}\n\nfunction lch(l, c, h, opacity) {\n  return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);\n}\n\nfunction hcl(h, c, l, opacity) {\n  return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);\n}\n\nfunction Hcl(h, c, l, opacity) {\n  this.h = +h;\n  this.c = +c;\n  this.l = +l;\n  this.opacity = +opacity;\n}\n\ndefine(Hcl, hcl, extend(Color, {\n  brighter: function(k) {\n    return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);\n  },\n  darker: function(k) {\n    return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);\n  },\n  rgb: function() {\n    return labConvert(this).rgb();\n  }\n}));\n\nvar A = -0.14861,\n    B = +1.78277,\n    C = -0.29227,\n    D = -0.90649,\n    E = +1.97294,\n    ED = E * D,\n    EB = E * B,\n    BC_DA = B * C - D * A;\n\nfunction cubehelixConvert(o) {\n  if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);\n  if (!(o instanceof Rgb)) o = rgbConvert(o);\n  var r = o.r / 255,\n      g = o.g / 255,\n      b = o.b / 255,\n      l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),\n      bl = b - l,\n      k = (E * (g - l) - C * bl) / D,\n      s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1\n      h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;\n  return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);\n}\n\nfunction cubehelix(h, s, l, opacity) {\n  return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);\n}\n\nfunction Cubehelix(h, s, l, opacity) {\n  this.h = +h;\n  this.s = +s;\n  this.l = +l;\n  this.opacity = +opacity;\n}\n\ndefine(Cubehelix, cubehelix, extend(Color, {\n  brighter: function(k) {\n    k = k == null ? brighter : Math.pow(brighter, k);\n    return new Cubehelix(this.h, this.s, this.l * k, this.opacity);\n  },\n  darker: function(k) {\n    k = k == null ? darker : Math.pow(darker, k);\n    return new Cubehelix(this.h, this.s, this.l * k, this.opacity);\n  },\n  rgb: function() {\n    var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,\n        l = +this.l,\n        a = isNaN(this.s) ? 0 : this.s * l * (1 - l),\n        cosh = Math.cos(h),\n        sinh = Math.sin(h);\n    return new Rgb(\n      255 * (l + a * (A * cosh + B * sinh)),\n      255 * (l + a * (C * cosh + D * sinh)),\n      255 * (l + a * (E * cosh)),\n      this.opacity\n    );\n  }\n}));\n\nexports.color = color;\nexports.rgb = rgb;\nexports.hsl = hsl;\nexports.lab = lab;\nexports.hcl = hcl;\nexports.lch = lch;\nexports.gray = gray;\nexports.cubehelix = cubehelix;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],155:[function(_dereq_,module,exports){\n// https://d3js.org/d3-dispatch/ Version 1.0.3. Copyright 2017 Mike Bostock.\n(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n\ttypeof define === 'function' && define.amd ? define(['exports'], factory) :\n\t(factory((global.d3 = global.d3 || {})));\n}(this, (function (exports) { 'use strict';\n\nvar noop = {value: function() {}};\n\nfunction dispatch() {\n  for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {\n    if (!(t = arguments[i] + \"\") || (t in _)) throw new Error(\"illegal type: \" + t);\n    _[t] = [];\n  }\n  return new Dispatch(_);\n}\n\nfunction Dispatch(_) {\n  this._ = _;\n}\n\nfunction parseTypenames(typenames, types) {\n  return typenames.trim().split(/^|\\s+/).map(function(t) {\n    var name = \"\", i = t.indexOf(\".\");\n    if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);\n    if (t && !types.hasOwnProperty(t)) throw new Error(\"unknown type: \" + t);\n    return {type: t, name: name};\n  });\n}\n\nDispatch.prototype = dispatch.prototype = {\n  constructor: Dispatch,\n  on: function(typename, callback) {\n    var _ = this._,\n        T = parseTypenames(typename + \"\", _),\n        t,\n        i = -1,\n        n = T.length;\n\n    // If no callback was specified, return the callback of the given type and name.\n    if (arguments.length < 2) {\n      while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;\n      return;\n    }\n\n    // If a type was specified, set the callback for the given type and name.\n    // Otherwise, if a null callback was specified, remove callbacks of the given name.\n    if (callback != null && typeof callback !== \"function\") throw new Error(\"invalid callback: \" + callback);\n    while (++i < n) {\n      if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);\n      else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);\n    }\n\n    return this;\n  },\n  copy: function() {\n    var copy = {}, _ = this._;\n    for (var t in _) copy[t] = _[t].slice();\n    return new Dispatch(copy);\n  },\n  call: function(type, that) {\n    if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];\n    if (!this._.hasOwnProperty(type)) throw new Error(\"unknown type: \" + type);\n    for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);\n  },\n  apply: function(type, that, args) {\n    if (!this._.hasOwnProperty(type)) throw new Error(\"unknown type: \" + type);\n    for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);\n  }\n};\n\nfunction get(type, name) {\n  for (var i = 0, n = type.length, c; i < n; ++i) {\n    if ((c = type[i]).name === name) {\n      return c.value;\n    }\n  }\n}\n\nfunction set(type, name, callback) {\n  for (var i = 0, n = type.length; i < n; ++i) {\n    if (type[i].name === name) {\n      type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));\n      break;\n    }\n  }\n  if (callback != null) type.push({name: name, value: callback});\n  return type;\n}\n\nexports.dispatch = dispatch;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],156:[function(_dereq_,module,exports){\n// https://d3js.org/d3-force/ Version 1.1.0. Copyright 2017 Mike Bostock.\n(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, _dereq_('d3-quadtree'), _dereq_('d3-collection'), _dereq_('d3-dispatch'), _dereq_('d3-timer')) :\n\ttypeof define === 'function' && define.amd ? define(['exports', 'd3-quadtree', 'd3-collection', 'd3-dispatch', 'd3-timer'], factory) :\n\t(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3));\n}(this, (function (exports,d3Quadtree,d3Collection,d3Dispatch,d3Timer) { 'use strict';\n\nvar center = function(x, y) {\n  var nodes;\n\n  if (x == null) x = 0;\n  if (y == null) y = 0;\n\n  function force() {\n    var i,\n        n = nodes.length,\n        node,\n        sx = 0,\n        sy = 0;\n\n    for (i = 0; i < n; ++i) {\n      node = nodes[i], sx += node.x, sy += node.y;\n    }\n\n    for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {\n      node = nodes[i], node.x -= sx, node.y -= sy;\n    }\n  }\n\n  force.initialize = function(_) {\n    nodes = _;\n  };\n\n  force.x = function(_) {\n    return arguments.length ? (x = +_, force) : x;\n  };\n\n  force.y = function(_) {\n    return arguments.length ? (y = +_, force) : y;\n  };\n\n  return force;\n};\n\nvar constant = function(x) {\n  return function() {\n    return x;\n  };\n};\n\nvar jiggle = function() {\n  return (Math.random() - 0.5) * 1e-6;\n};\n\nfunction x(d) {\n  return d.x + d.vx;\n}\n\nfunction y(d) {\n  return d.y + d.vy;\n}\n\nvar collide = function(radius) {\n  var nodes,\n      radii,\n      strength = 1,\n      iterations = 1;\n\n  if (typeof radius !== \"function\") radius = constant(radius == null ? 1 : +radius);\n\n  function force() {\n    var i, n = nodes.length,\n        tree,\n        node,\n        xi,\n        yi,\n        ri,\n        ri2;\n\n    for (var k = 0; k < iterations; ++k) {\n      tree = d3Quadtree.quadtree(nodes, x, y).visitAfter(prepare);\n      for (i = 0; i < n; ++i) {\n        node = nodes[i];\n        ri = radii[node.index], ri2 = ri * ri;\n        xi = node.x + node.vx;\n        yi = node.y + node.vy;\n        tree.visit(apply);\n      }\n    }\n\n    function apply(quad, x0, y0, x1, y1) {\n      var data = quad.data, rj = quad.r, r = ri + rj;\n      if (data) {\n        if (data.index > node.index) {\n          var x = xi - data.x - data.vx,\n              y = yi - data.y - data.vy,\n              l = x * x + y * y;\n          if (l < r * r) {\n            if (x === 0) x = jiggle(), l += x * x;\n            if (y === 0) y = jiggle(), l += y * y;\n            l = (r - (l = Math.sqrt(l))) / l * strength;\n            node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));\n            node.vy += (y *= l) * r;\n            data.vx -= x * (r = 1 - r);\n            data.vy -= y * r;\n          }\n        }\n        return;\n      }\n      return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;\n    }\n  }\n\n  function prepare(quad) {\n    if (quad.data) return quad.r = radii[quad.data.index];\n    for (var i = quad.r = 0; i < 4; ++i) {\n      if (quad[i] && quad[i].r > quad.r) {\n        quad.r = quad[i].r;\n      }\n    }\n  }\n\n  function initialize() {\n    if (!nodes) return;\n    var i, n = nodes.length, node;\n    radii = new Array(n);\n    for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);\n  }\n\n  force.initialize = function(_) {\n    nodes = _;\n    initialize();\n  };\n\n  force.iterations = function(_) {\n    return arguments.length ? (iterations = +_, force) : iterations;\n  };\n\n  force.strength = function(_) {\n    return arguments.length ? (strength = +_, force) : strength;\n  };\n\n  force.radius = function(_) {\n    return arguments.length ? (radius = typeof _ === \"function\" ? _ : constant(+_), initialize(), force) : radius;\n  };\n\n  return force;\n};\n\nfunction index(d) {\n  return d.index;\n}\n\nfunction find(nodeById, nodeId) {\n  var node = nodeById.get(nodeId);\n  if (!node) throw new Error(\"missing: \" + nodeId);\n  return node;\n}\n\nvar link = function(links) {\n  var id = index,\n      strength = defaultStrength,\n      strengths,\n      distance = constant(30),\n      distances,\n      nodes,\n      count,\n      bias,\n      iterations = 1;\n\n  if (links == null) links = [];\n\n  function defaultStrength(link) {\n    return 1 / Math.min(count[link.source.index], count[link.target.index]);\n  }\n\n  function force(alpha) {\n    for (var k = 0, n = links.length; k < iterations; ++k) {\n      for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {\n        link = links[i], source = link.source, target = link.target;\n        x = target.x + target.vx - source.x - source.vx || jiggle();\n        y = target.y + target.vy - source.y - source.vy || jiggle();\n        l = Math.sqrt(x * x + y * y);\n        l = (l - distances[i]) / l * alpha * strengths[i];\n        x *= l, y *= l;\n        target.vx -= x * (b = bias[i]);\n        target.vy -= y * b;\n        source.vx += x * (b = 1 - b);\n        source.vy += y * b;\n      }\n    }\n  }\n\n  function initialize() {\n    if (!nodes) return;\n\n    var i,\n        n = nodes.length,\n        m = links.length,\n        nodeById = d3Collection.map(nodes, id),\n        link;\n\n    for (i = 0, count = new Array(n); i < m; ++i) {\n      link = links[i], link.index = i;\n      if (typeof link.source !== \"object\") link.source = find(nodeById, link.source);\n      if (typeof link.target !== \"object\") link.target = find(nodeById, link.target);\n      count[link.source.index] = (count[link.source.index] || 0) + 1;\n      count[link.target.index] = (count[link.target.index] || 0) + 1;\n    }\n\n    for (i = 0, bias = new Array(m); i < m; ++i) {\n      link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);\n    }\n\n    strengths = new Array(m), initializeStrength();\n    distances = new Array(m), initializeDistance();\n  }\n\n  function initializeStrength() {\n    if (!nodes) return;\n\n    for (var i = 0, n = links.length; i < n; ++i) {\n      strengths[i] = +strength(links[i], i, links);\n    }\n  }\n\n  function initializeDistance() {\n    if (!nodes) return;\n\n    for (var i = 0, n = links.length; i < n; ++i) {\n      distances[i] = +distance(links[i], i, links);\n    }\n  }\n\n  force.initialize = function(_) {\n    nodes = _;\n    initialize();\n  };\n\n  force.links = function(_) {\n    return arguments.length ? (links = _, initialize(), force) : links;\n  };\n\n  force.id = function(_) {\n    return arguments.length ? (id = _, force) : id;\n  };\n\n  force.iterations = function(_) {\n    return arguments.length ? (iterations = +_, force) : iterations;\n  };\n\n  force.strength = function(_) {\n    return arguments.length ? (strength = typeof _ === \"function\" ? _ : constant(+_), initializeStrength(), force) : strength;\n  };\n\n  force.distance = function(_) {\n    return arguments.length ? (distance = typeof _ === \"function\" ? _ : constant(+_), initializeDistance(), force) : distance;\n  };\n\n  return force;\n};\n\nfunction x$1(d) {\n  return d.x;\n}\n\nfunction y$1(d) {\n  return d.y;\n}\n\nvar initialRadius = 10;\nvar initialAngle = Math.PI * (3 - Math.sqrt(5));\n\nvar simulation = function(nodes) {\n  var simulation,\n      alpha = 1,\n      alphaMin = 0.001,\n      alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),\n      alphaTarget = 0,\n      velocityDecay = 0.6,\n      forces = d3Collection.map(),\n      stepper = d3Timer.timer(step),\n      event = d3Dispatch.dispatch(\"tick\", \"end\");\n\n  if (nodes == null) nodes = [];\n\n  function step() {\n    tick();\n    event.call(\"tick\", simulation);\n    if (alpha < alphaMin) {\n      stepper.stop();\n      event.call(\"end\", simulation);\n    }\n  }\n\n  function tick() {\n    var i, n = nodes.length, node;\n\n    alpha += (alphaTarget - alpha) * alphaDecay;\n\n    forces.each(function(force) {\n      force(alpha);\n    });\n\n    for (i = 0; i < n; ++i) {\n      node = nodes[i];\n      if (node.fx == null) node.x += node.vx *= velocityDecay;\n      else node.x = node.fx, node.vx = 0;\n      if (node.fy == null) node.y += node.vy *= velocityDecay;\n      else node.y = node.fy, node.vy = 0;\n    }\n  }\n\n  function initializeNodes() {\n    for (var i = 0, n = nodes.length, node; i < n; ++i) {\n      node = nodes[i], node.index = i;\n      if (isNaN(node.x) || isNaN(node.y)) {\n        var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;\n        node.x = radius * Math.cos(angle);\n        node.y = radius * Math.sin(angle);\n      }\n      if (isNaN(node.vx) || isNaN(node.vy)) {\n        node.vx = node.vy = 0;\n      }\n    }\n  }\n\n  function initializeForce(force) {\n    if (force.initialize) force.initialize(nodes);\n    return force;\n  }\n\n  initializeNodes();\n\n  return simulation = {\n    tick: tick,\n\n    restart: function() {\n      return stepper.restart(step), simulation;\n    },\n\n    stop: function() {\n      return stepper.stop(), simulation;\n    },\n\n    nodes: function(_) {\n      return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;\n    },\n\n    alpha: function(_) {\n      return arguments.length ? (alpha = +_, simulation) : alpha;\n    },\n\n    alphaMin: function(_) {\n      return arguments.length ? (alphaMin = +_, simulation) : alphaMin;\n    },\n\n    alphaDecay: function(_) {\n      return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;\n    },\n\n    alphaTarget: function(_) {\n      return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;\n    },\n\n    velocityDecay: function(_) {\n      return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;\n    },\n\n    force: function(name, _) {\n      return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);\n    },\n\n    find: function(x, y, radius) {\n      var i = 0,\n          n = nodes.length,\n          dx,\n          dy,\n          d2,\n          node,\n          closest;\n\n      if (radius == null) radius = Infinity;\n      else radius *= radius;\n\n      for (i = 0; i < n; ++i) {\n        node = nodes[i];\n        dx = x - node.x;\n        dy = y - node.y;\n        d2 = dx * dx + dy * dy;\n        if (d2 < radius) closest = node, radius = d2;\n      }\n\n      return closest;\n    },\n\n    on: function(name, _) {\n      return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);\n    }\n  };\n};\n\nvar manyBody = function() {\n  var nodes,\n      node,\n      alpha,\n      strength = constant(-30),\n      strengths,\n      distanceMin2 = 1,\n      distanceMax2 = Infinity,\n      theta2 = 0.81;\n\n  function force(_) {\n    var i, n = nodes.length, tree = d3Quadtree.quadtree(nodes, x$1, y$1).visitAfter(accumulate);\n    for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);\n  }\n\n  function initialize() {\n    if (!nodes) return;\n    var i, n = nodes.length, node;\n    strengths = new Array(n);\n    for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);\n  }\n\n  function accumulate(quad) {\n    var strength = 0, q, c, weight = 0, x, y, i;\n\n    // For internal nodes, accumulate forces from child quadrants.\n    if (quad.length) {\n      for (x = y = i = 0; i < 4; ++i) {\n        if ((q = quad[i]) && (c = Math.abs(q.value))) {\n          strength += q.value, weight += c, x += c * q.x, y += c * q.y;\n        }\n      }\n      quad.x = x / weight;\n      quad.y = y / weight;\n    }\n\n    // For leaf nodes, accumulate forces from coincident quadrants.\n    else {\n      q = quad;\n      q.x = q.data.x;\n      q.y = q.data.y;\n      do strength += strengths[q.data.index];\n      while (q = q.next);\n    }\n\n    quad.value = strength;\n  }\n\n  function apply(quad, x1, _, x2) {\n    if (!quad.value) return true;\n\n    var x = quad.x - node.x,\n        y = quad.y - node.y,\n        w = x2 - x1,\n        l = x * x + y * y;\n\n    // Apply the Barnes-Hut approximation if possible.\n    // Limit forces for very close nodes; randomize direction if coincident.\n    if (w * w / theta2 < l) {\n      if (l < distanceMax2) {\n        if (x === 0) x = jiggle(), l += x * x;\n        if (y === 0) y = jiggle(), l += y * y;\n        if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);\n        node.vx += x * quad.value * alpha / l;\n        node.vy += y * quad.value * alpha / l;\n      }\n      return true;\n    }\n\n    // Otherwise, process points directly.\n    else if (quad.length || l >= distanceMax2) return;\n\n    // Limit forces for very close nodes; randomize direction if coincident.\n    if (quad.data !== node || quad.next) {\n      if (x === 0) x = jiggle(), l += x * x;\n      if (y === 0) y = jiggle(), l += y * y;\n      if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);\n    }\n\n    do if (quad.data !== node) {\n      w = strengths[quad.data.index] * alpha / l;\n      node.vx += x * w;\n      node.vy += y * w;\n    } while (quad = quad.next);\n  }\n\n  force.initialize = function(_) {\n    nodes = _;\n    initialize();\n  };\n\n  force.strength = function(_) {\n    return arguments.length ? (strength = typeof _ === \"function\" ? _ : constant(+_), initialize(), force) : strength;\n  };\n\n  force.distanceMin = function(_) {\n    return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);\n  };\n\n  force.distanceMax = function(_) {\n    return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);\n  };\n\n  force.theta = function(_) {\n    return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);\n  };\n\n  return force;\n};\n\nvar radial = function(radius, x, y) {\n  var nodes,\n      strength = constant(0.1),\n      strengths,\n      radiuses;\n\n  if (typeof radius !== \"function\") radius = constant(+radius);\n  if (x == null) x = 0;\n  if (y == null) y = 0;\n\n  function force(alpha) {\n    for (var i = 0, n = nodes.length; i < n; ++i) {\n      var node = nodes[i],\n          dx = node.x - x || 1e-6,\n          dy = node.y - y || 1e-6,\n          r = Math.sqrt(dx * dx + dy * dy),\n          k = (radiuses[i] - r) * strengths[i] * alpha / r;\n      node.vx += dx * k;\n      node.vy += dy * k;\n    }\n  }\n\n  function initialize() {\n    if (!nodes) return;\n    var i, n = nodes.length;\n    strengths = new Array(n);\n    radiuses = new Array(n);\n    for (i = 0; i < n; ++i) {\n      radiuses[i] = +radius(nodes[i], i, nodes);\n      strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);\n    }\n  }\n\n  force.initialize = function(_) {\n    nodes = _, initialize();\n  };\n\n  force.strength = function(_) {\n    return arguments.length ? (strength = typeof _ === \"function\" ? _ : constant(+_), initialize(), force) : strength;\n  };\n\n  force.radius = function(_) {\n    return arguments.length ? (radius = typeof _ === \"function\" ? _ : constant(+_), initialize(), force) : radius;\n  };\n\n  force.x = function(_) {\n    return arguments.length ? (x = +_, force) : x;\n  };\n\n  force.y = function(_) {\n    return arguments.length ? (y = +_, force) : y;\n  };\n\n  return force;\n};\n\nvar x$2 = function(x) {\n  var strength = constant(0.1),\n      nodes,\n      strengths,\n      xz;\n\n  if (typeof x !== \"function\") x = constant(x == null ? 0 : +x);\n\n  function force(alpha) {\n    for (var i = 0, n = nodes.length, node; i < n; ++i) {\n      node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;\n    }\n  }\n\n  function initialize() {\n    if (!nodes) return;\n    var i, n = nodes.length;\n    strengths = new Array(n);\n    xz = new Array(n);\n    for (i = 0; i < n; ++i) {\n      strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);\n    }\n  }\n\n  force.initialize = function(_) {\n    nodes = _;\n    initialize();\n  };\n\n  force.strength = function(_) {\n    return arguments.length ? (strength = typeof _ === \"function\" ? _ : constant(+_), initialize(), force) : strength;\n  };\n\n  force.x = function(_) {\n    return arguments.length ? (x = typeof _ === \"function\" ? _ : constant(+_), initialize(), force) : x;\n  };\n\n  return force;\n};\n\nvar y$2 = function(y) {\n  var strength = constant(0.1),\n      nodes,\n      strengths,\n      yz;\n\n  if (typeof y !== \"function\") y = constant(y == null ? 0 : +y);\n\n  function force(alpha) {\n    for (var i = 0, n = nodes.length, node; i < n; ++i) {\n      node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;\n    }\n  }\n\n  function initialize() {\n    if (!nodes) return;\n    var i, n = nodes.length;\n    strengths = new Array(n);\n    yz = new Array(n);\n    for (i = 0; i < n; ++i) {\n      strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);\n    }\n  }\n\n  force.initialize = function(_) {\n    nodes = _;\n    initialize();\n  };\n\n  force.strength = function(_) {\n    return arguments.length ? (strength = typeof _ === \"function\" ? _ : constant(+_), initialize(), force) : strength;\n  };\n\n  force.y = function(_) {\n    return arguments.length ? (y = typeof _ === \"function\" ? _ : constant(+_), initialize(), force) : y;\n  };\n\n  return force;\n};\n\nexports.forceCenter = center;\nexports.forceCollide = collide;\nexports.forceLink = link;\nexports.forceManyBody = manyBody;\nexports.forceRadial = radial;\nexports.forceSimulation = simulation;\nexports.forceX = x$2;\nexports.forceY = y$2;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{\"d3-collection\":153,\"d3-dispatch\":155,\"d3-quadtree\":160,\"d3-timer\":162}],157:[function(_dereq_,module,exports){\n// https://d3js.org/d3-hierarchy/ v1.1.8 Copyright 2018 Mike Bostock\n(function (global, factory) {\ntypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\ntypeof define === 'function' && define.amd ? define(['exports'], factory) :\n(factory((global.d3 = global.d3 || {})));\n}(this, (function (exports) { 'use strict';\n\nfunction defaultSeparation(a, b) {\n  return a.parent === b.parent ? 1 : 2;\n}\n\nfunction meanX(children) {\n  return children.reduce(meanXReduce, 0) / children.length;\n}\n\nfunction meanXReduce(x, c) {\n  return x + c.x;\n}\n\nfunction maxY(children) {\n  return 1 + children.reduce(maxYReduce, 0);\n}\n\nfunction maxYReduce(y, c) {\n  return Math.max(y, c.y);\n}\n\nfunction leafLeft(node) {\n  var children;\n  while (children = node.children) node = children[0];\n  return node;\n}\n\nfunction leafRight(node) {\n  var children;\n  while (children = node.children) node = children[children.length - 1];\n  return node;\n}\n\nfunction cluster() {\n  var separation = defaultSeparation,\n      dx = 1,\n      dy = 1,\n      nodeSize = false;\n\n  function cluster(root) {\n    var previousNode,\n        x = 0;\n\n    // First walk, computing the initial x & y values.\n    root.eachAfter(function(node) {\n      var children = node.children;\n      if (children) {\n        node.x = meanX(children);\n        node.y = maxY(children);\n      } else {\n        node.x = previousNode ? x += separation(node, previousNode) : 0;\n        node.y = 0;\n        previousNode = node;\n      }\n    });\n\n    var left = leafLeft(root),\n        right = leafRight(root),\n        x0 = left.x - separation(left, right) / 2,\n        x1 = right.x + separation(right, left) / 2;\n\n    // Second walk, normalizing x & y to the desired size.\n    return root.eachAfter(nodeSize ? function(node) {\n      node.x = (node.x - root.x) * dx;\n      node.y = (root.y - node.y) * dy;\n    } : function(node) {\n      node.x = (node.x - x0) / (x1 - x0) * dx;\n      node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;\n    });\n  }\n\n  cluster.separation = function(x) {\n    return arguments.length ? (separation = x, cluster) : separation;\n  };\n\n  cluster.size = function(x) {\n    return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);\n  };\n\n  cluster.nodeSize = function(x) {\n    return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);\n  };\n\n  return cluster;\n}\n\nfunction count(node) {\n  var sum = 0,\n      children = node.children,\n      i = children && children.length;\n  if (!i) sum = 1;\n  else while (--i >= 0) sum += children[i].value;\n  node.value = sum;\n}\n\nfunction node_count() {\n  return this.eachAfter(count);\n}\n\nfunction node_each(callback) {\n  var node = this, current, next = [node], children, i, n;\n  do {\n    current = next.reverse(), next = [];\n    while (node = current.pop()) {\n      callback(node), children = node.children;\n      if (children) for (i = 0, n = children.length; i < n; ++i) {\n        next.push(children[i]);\n      }\n    }\n  } while (next.length);\n  return this;\n}\n\nfunction node_eachBefore(callback) {\n  var node = this, nodes = [node], children, i;\n  while (node = nodes.pop()) {\n    callback(node), children = node.children;\n    if (children) for (i = children.length - 1; i >= 0; --i) {\n      nodes.push(children[i]);\n    }\n  }\n  return this;\n}\n\nfunction node_eachAfter(callback) {\n  var node = this, nodes = [node], next = [], children, i, n;\n  while (node = nodes.pop()) {\n    next.push(node), children = node.children;\n    if (children) for (i = 0, n = children.length; i < n; ++i) {\n      nodes.push(children[i]);\n    }\n  }\n  while (node = next.pop()) {\n    callback(node);\n  }\n  return this;\n}\n\nfunction node_sum(value) {\n  return this.eachAfter(function(node) {\n    var sum = +value(node.data) || 0,\n        children = node.children,\n        i = children && children.length;\n    while (--i >= 0) sum += children[i].value;\n    node.value = sum;\n  });\n}\n\nfunction node_sort(compare) {\n  return this.eachBefore(function(node) {\n    if (node.children) {\n      node.children.sort(compare);\n    }\n  });\n}\n\nfunction node_path(end) {\n  var start = this,\n      ancestor = leastCommonAncestor(start, end),\n      nodes = [start];\n  while (start !== ancestor) {\n    start = start.parent;\n    nodes.push(start);\n  }\n  var k = nodes.length;\n  while (end !== ancestor) {\n    nodes.splice(k, 0, end);\n    end = end.parent;\n  }\n  return nodes;\n}\n\nfunction leastCommonAncestor(a, b) {\n  if (a === b) return a;\n  var aNodes = a.ancestors(),\n      bNodes = b.ancestors(),\n      c = null;\n  a = aNodes.pop();\n  b = bNodes.pop();\n  while (a === b) {\n    c = a;\n    a = aNodes.pop();\n    b = bNodes.pop();\n  }\n  return c;\n}\n\nfunction node_ancestors() {\n  var node = this, nodes = [node];\n  while (node = node.parent) {\n    nodes.push(node);\n  }\n  return nodes;\n}\n\nfunction node_descendants() {\n  var nodes = [];\n  this.each(function(node) {\n    nodes.push(node);\n  });\n  return nodes;\n}\n\nfunction node_leaves() {\n  var leaves = [];\n  this.eachBefore(function(node) {\n    if (!node.children) {\n      leaves.push(node);\n    }\n  });\n  return leaves;\n}\n\nfunction node_links() {\n  var root = this, links = [];\n  root.each(function(node) {\n    if (node !== root) { // Don’t include the root’s parent, if any.\n      links.push({source: node.parent, target: node});\n    }\n  });\n  return links;\n}\n\nfunction hierarchy(data, children) {\n  var root = new Node(data),\n      valued = +data.value && (root.value = data.value),\n      node,\n      nodes = [root],\n      child,\n      childs,\n      i,\n      n;\n\n  if (children == null) children = defaultChildren;\n\n  while (node = nodes.pop()) {\n    if (valued) node.value = +node.data.value;\n    if ((childs = children(node.data)) && (n = childs.length)) {\n      node.children = new Array(n);\n      for (i = n - 1; i >= 0; --i) {\n        nodes.push(child = node.children[i] = new Node(childs[i]));\n        child.parent = node;\n        child.depth = node.depth + 1;\n      }\n    }\n  }\n\n  return root.eachBefore(computeHeight);\n}\n\nfunction node_copy() {\n  return hierarchy(this).eachBefore(copyData);\n}\n\nfunction defaultChildren(d) {\n  return d.children;\n}\n\nfunction copyData(node) {\n  node.data = node.data.data;\n}\n\nfunction computeHeight(node) {\n  var height = 0;\n  do node.height = height;\n  while ((node = node.parent) && (node.height < ++height));\n}\n\nfunction Node(data) {\n  this.data = data;\n  this.depth =\n  this.height = 0;\n  this.parent = null;\n}\n\nNode.prototype = hierarchy.prototype = {\n  constructor: Node,\n  count: node_count,\n  each: node_each,\n  eachAfter: node_eachAfter,\n  eachBefore: node_eachBefore,\n  sum: node_sum,\n  sort: node_sort,\n  path: node_path,\n  ancestors: node_ancestors,\n  descendants: node_descendants,\n  leaves: node_leaves,\n  links: node_links,\n  copy: node_copy\n};\n\nvar slice = Array.prototype.slice;\n\nfunction shuffle(array) {\n  var m = array.length,\n      t,\n      i;\n\n  while (m) {\n    i = Math.random() * m-- | 0;\n    t = array[m];\n    array[m] = array[i];\n    array[i] = t;\n  }\n\n  return array;\n}\n\nfunction enclose(circles) {\n  var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e;\n\n  while (i < n) {\n    p = circles[i];\n    if (e && enclosesWeak(e, p)) ++i;\n    else e = encloseBasis(B = extendBasis(B, p)), i = 0;\n  }\n\n  return e;\n}\n\nfunction extendBasis(B, p) {\n  var i, j;\n\n  if (enclosesWeakAll(p, B)) return [p];\n\n  // If we get here then B must have at least one element.\n  for (i = 0; i < B.length; ++i) {\n    if (enclosesNot(p, B[i])\n        && enclosesWeakAll(encloseBasis2(B[i], p), B)) {\n      return [B[i], p];\n    }\n  }\n\n  // If we get here then B must have at least two elements.\n  for (i = 0; i < B.length - 1; ++i) {\n    for (j = i + 1; j < B.length; ++j) {\n      if (enclosesNot(encloseBasis2(B[i], B[j]), p)\n          && enclosesNot(encloseBasis2(B[i], p), B[j])\n          && enclosesNot(encloseBasis2(B[j], p), B[i])\n          && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {\n        return [B[i], B[j], p];\n      }\n    }\n  }\n\n  // If we get here then something is very wrong.\n  throw new Error;\n}\n\nfunction enclosesNot(a, b) {\n  var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;\n  return dr < 0 || dr * dr < dx * dx + dy * dy;\n}\n\nfunction enclosesWeak(a, b) {\n  var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;\n  return dr > 0 && dr * dr > dx * dx + dy * dy;\n}\n\nfunction enclosesWeakAll(a, B) {\n  for (var i = 0; i < B.length; ++i) {\n    if (!enclosesWeak(a, B[i])) {\n      return false;\n    }\n  }\n  return true;\n}\n\nfunction encloseBasis(B) {\n  switch (B.length) {\n    case 1: return encloseBasis1(B[0]);\n    case 2: return encloseBasis2(B[0], B[1]);\n    case 3: return encloseBasis3(B[0], B[1], B[2]);\n  }\n}\n\nfunction encloseBasis1(a) {\n  return {\n    x: a.x,\n    y: a.y,\n    r: a.r\n  };\n}\n\nfunction encloseBasis2(a, b) {\n  var x1 = a.x, y1 = a.y, r1 = a.r,\n      x2 = b.x, y2 = b.y, r2 = b.r,\n      x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,\n      l = Math.sqrt(x21 * x21 + y21 * y21);\n  return {\n    x: (x1 + x2 + x21 / l * r21) / 2,\n    y: (y1 + y2 + y21 / l * r21) / 2,\n    r: (l + r1 + r2) / 2\n  };\n}\n\nfunction encloseBasis3(a, b, c) {\n  var x1 = a.x, y1 = a.y, r1 = a.r,\n      x2 = b.x, y2 = b.y, r2 = b.r,\n      x3 = c.x, y3 = c.y, r3 = c.r,\n      a2 = x1 - x2,\n      a3 = x1 - x3,\n      b2 = y1 - y2,\n      b3 = y1 - y3,\n      c2 = r2 - r1,\n      c3 = r3 - r1,\n      d1 = x1 * x1 + y1 * y1 - r1 * r1,\n      d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,\n      d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,\n      ab = a3 * b2 - a2 * b3,\n      xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,\n      xb = (b3 * c2 - b2 * c3) / ab,\n      ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,\n      yb = (a2 * c3 - a3 * c2) / ab,\n      A = xb * xb + yb * yb - 1,\n      B = 2 * (r1 + xa * xb + ya * yb),\n      C = xa * xa + ya * ya - r1 * r1,\n      r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);\n  return {\n    x: x1 + xa + xb * r,\n    y: y1 + ya + yb * r,\n    r: r\n  };\n}\n\nfunction place(b, a, c) {\n  var dx = b.x - a.x, x, a2,\n      dy = b.y - a.y, y, b2,\n      d2 = dx * dx + dy * dy;\n  if (d2) {\n    a2 = a.r + c.r, a2 *= a2;\n    b2 = b.r + c.r, b2 *= b2;\n    if (a2 > b2) {\n      x = (d2 + b2 - a2) / (2 * d2);\n      y = Math.sqrt(Math.max(0, b2 / d2 - x * x));\n      c.x = b.x - x * dx - y * dy;\n      c.y = b.y - x * dy + y * dx;\n    } else {\n      x = (d2 + a2 - b2) / (2 * d2);\n      y = Math.sqrt(Math.max(0, a2 / d2 - x * x));\n      c.x = a.x + x * dx - y * dy;\n      c.y = a.y + x * dy + y * dx;\n    }\n  } else {\n    c.x = a.x + c.r;\n    c.y = a.y;\n  }\n}\n\nfunction intersects(a, b) {\n  var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;\n  return dr > 0 && dr * dr > dx * dx + dy * dy;\n}\n\nfunction score(node) {\n  var a = node._,\n      b = node.next._,\n      ab = a.r + b.r,\n      dx = (a.x * b.r + b.x * a.r) / ab,\n      dy = (a.y * b.r + b.y * a.r) / ab;\n  return dx * dx + dy * dy;\n}\n\nfunction Node$1(circle) {\n  this._ = circle;\n  this.next = null;\n  this.previous = null;\n}\n\nfunction packEnclose(circles) {\n  if (!(n = circles.length)) return 0;\n\n  var a, b, c, n, aa, ca, i, j, k, sj, sk;\n\n  // Place the first circle.\n  a = circles[0], a.x = 0, a.y = 0;\n  if (!(n > 1)) return a.r;\n\n  // Place the second circle.\n  b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;\n  if (!(n > 2)) return a.r + b.r;\n\n  // Place the third circle.\n  place(b, a, c = circles[2]);\n\n  // Initialize the front-chain using the first three circles a, b and c.\n  a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);\n  a.next = c.previous = b;\n  b.next = a.previous = c;\n  c.next = b.previous = a;\n\n  // Attempt to place each remaining circle…\n  pack: for (i = 3; i < n; ++i) {\n    place(a._, b._, c = circles[i]), c = new Node$1(c);\n\n    // Find the closest intersecting circle on the front-chain, if any.\n    // “Closeness” is determined by linear distance along the front-chain.\n    // “Ahead” or “behind” is likewise determined by linear distance.\n    j = b.next, k = a.previous, sj = b._.r, sk = a._.r;\n    do {\n      if (sj <= sk) {\n        if (intersects(j._, c._)) {\n          b = j, a.next = b, b.previous = a, --i;\n          continue pack;\n        }\n        sj += j._.r, j = j.next;\n      } else {\n        if (intersects(k._, c._)) {\n          a = k, a.next = b, b.previous = a, --i;\n          continue pack;\n        }\n        sk += k._.r, k = k.previous;\n      }\n    } while (j !== k.next);\n\n    // Success! Insert the new circle c between a and b.\n    c.previous = a, c.next = b, a.next = b.previous = b = c;\n\n    // Compute the new closest circle pair to the centroid.\n    aa = score(a);\n    while ((c = c.next) !== b) {\n      if ((ca = score(c)) < aa) {\n        a = c, aa = ca;\n      }\n    }\n    b = a.next;\n  }\n\n  // Compute the enclosing circle of the front chain.\n  a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);\n\n  // Translate the circles to put the enclosing circle around the origin.\n  for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;\n\n  return c.r;\n}\n\nfunction siblings(circles) {\n  packEnclose(circles);\n  return circles;\n}\n\nfunction optional(f) {\n  return f == null ? null : required(f);\n}\n\nfunction required(f) {\n  if (typeof f !== \"function\") throw new Error;\n  return f;\n}\n\nfunction constantZero() {\n  return 0;\n}\n\nfunction constant(x) {\n  return function() {\n    return x;\n  };\n}\n\nfunction defaultRadius(d) {\n  return Math.sqrt(d.value);\n}\n\nfunction index() {\n  var radius = null,\n      dx = 1,\n      dy = 1,\n      padding = constantZero;\n\n  function pack(root) {\n    root.x = dx / 2, root.y = dy / 2;\n    if (radius) {\n      root.eachBefore(radiusLeaf(radius))\n          .eachAfter(packChildren(padding, 0.5))\n          .eachBefore(translateChild(1));\n    } else {\n      root.eachBefore(radiusLeaf(defaultRadius))\n          .eachAfter(packChildren(constantZero, 1))\n          .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))\n          .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));\n    }\n    return root;\n  }\n\n  pack.radius = function(x) {\n    return arguments.length ? (radius = optional(x), pack) : radius;\n  };\n\n  pack.size = function(x) {\n    return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];\n  };\n\n  pack.padding = function(x) {\n    return arguments.length ? (padding = typeof x === \"function\" ? x : constant(+x), pack) : padding;\n  };\n\n  return pack;\n}\n\nfunction radiusLeaf(radius) {\n  return function(node) {\n    if (!node.children) {\n      node.r = Math.max(0, +radius(node) || 0);\n    }\n  };\n}\n\nfunction packChildren(padding, k) {\n  return function(node) {\n    if (children = node.children) {\n      var children,\n          i,\n          n = children.length,\n          r = padding(node) * k || 0,\n          e;\n\n      if (r) for (i = 0; i < n; ++i) children[i].r += r;\n      e = packEnclose(children);\n      if (r) for (i = 0; i < n; ++i) children[i].r -= r;\n      node.r = e + r;\n    }\n  };\n}\n\nfunction translateChild(k) {\n  return function(node) {\n    var parent = node.parent;\n    node.r *= k;\n    if (parent) {\n      node.x = parent.x + k * node.x;\n      node.y = parent.y + k * node.y;\n    }\n  };\n}\n\nfunction roundNode(node) {\n  node.x0 = Math.round(node.x0);\n  node.y0 = Math.round(node.y0);\n  node.x1 = Math.round(node.x1);\n  node.y1 = Math.round(node.y1);\n}\n\nfunction treemapDice(parent, x0, y0, x1, y1) {\n  var nodes = parent.children,\n      node,\n      i = -1,\n      n = nodes.length,\n      k = parent.value && (x1 - x0) / parent.value;\n\n  while (++i < n) {\n    node = nodes[i], node.y0 = y0, node.y1 = y1;\n    node.x0 = x0, node.x1 = x0 += node.value * k;\n  }\n}\n\nfunction partition() {\n  var dx = 1,\n      dy = 1,\n      padding = 0,\n      round = false;\n\n  function partition(root) {\n    var n = root.height + 1;\n    root.x0 =\n    root.y0 = padding;\n    root.x1 = dx;\n    root.y1 = dy / n;\n    root.eachBefore(positionNode(dy, n));\n    if (round) root.eachBefore(roundNode);\n    return root;\n  }\n\n  function positionNode(dy, n) {\n    return function(node) {\n      if (node.children) {\n        treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);\n      }\n      var x0 = node.x0,\n          y0 = node.y0,\n          x1 = node.x1 - padding,\n          y1 = node.y1 - padding;\n      if (x1 < x0) x0 = x1 = (x0 + x1) / 2;\n      if (y1 < y0) y0 = y1 = (y0 + y1) / 2;\n      node.x0 = x0;\n      node.y0 = y0;\n      node.x1 = x1;\n      node.y1 = y1;\n    };\n  }\n\n  partition.round = function(x) {\n    return arguments.length ? (round = !!x, partition) : round;\n  };\n\n  partition.size = function(x) {\n    return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];\n  };\n\n  partition.padding = function(x) {\n    return arguments.length ? (padding = +x, partition) : padding;\n  };\n\n  return partition;\n}\n\nvar keyPrefix = \"$\", // Protect against keys like “__proto__”.\n    preroot = {depth: -1},\n    ambiguous = {};\n\nfunction defaultId(d) {\n  return d.id;\n}\n\nfunction defaultParentId(d) {\n  return d.parentId;\n}\n\nfunction stratify() {\n  var id = defaultId,\n      parentId = defaultParentId;\n\n  function stratify(data) {\n    var d,\n        i,\n        n = data.length,\n        root,\n        parent,\n        node,\n        nodes = new Array(n),\n        nodeId,\n        nodeKey,\n        nodeByKey = {};\n\n    for (i = 0; i < n; ++i) {\n      d = data[i], node = nodes[i] = new Node(d);\n      if ((nodeId = id(d, i, data)) != null && (nodeId += \"\")) {\n        nodeKey = keyPrefix + (node.id = nodeId);\n        nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;\n      }\n    }\n\n    for (i = 0; i < n; ++i) {\n      node = nodes[i], nodeId = parentId(data[i], i, data);\n      if (nodeId == null || !(nodeId += \"\")) {\n        if (root) throw new Error(\"multiple roots\");\n        root = node;\n      } else {\n        parent = nodeByKey[keyPrefix + nodeId];\n        if (!parent) throw new Error(\"missing: \" + nodeId);\n        if (parent === ambiguous) throw new Error(\"ambiguous: \" + nodeId);\n        if (parent.children) parent.children.push(node);\n        else parent.children = [node];\n        node.parent = parent;\n      }\n    }\n\n    if (!root) throw new Error(\"no root\");\n    root.parent = preroot;\n    root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);\n    root.parent = null;\n    if (n > 0) throw new Error(\"cycle\");\n\n    return root;\n  }\n\n  stratify.id = function(x) {\n    return arguments.length ? (id = required(x), stratify) : id;\n  };\n\n  stratify.parentId = function(x) {\n    return arguments.length ? (parentId = required(x), stratify) : parentId;\n  };\n\n  return stratify;\n}\n\nfunction defaultSeparation$1(a, b) {\n  return a.parent === b.parent ? 1 : 2;\n}\n\n// function radialSeparation(a, b) {\n//   return (a.parent === b.parent ? 1 : 2) / a.depth;\n// }\n\n// This function is used to traverse the left contour of a subtree (or\n// subforest). It returns the successor of v on this contour. This successor is\n// either given by the leftmost child of v or by the thread of v. The function\n// returns null if and only if v is on the highest level of its subtree.\nfunction nextLeft(v) {\n  var children = v.children;\n  return children ? children[0] : v.t;\n}\n\n// This function works analogously to nextLeft.\nfunction nextRight(v) {\n  var children = v.children;\n  return children ? children[children.length - 1] : v.t;\n}\n\n// Shifts the current subtree rooted at w+. This is done by increasing\n// prelim(w+) and mod(w+) by shift.\nfunction moveSubtree(wm, wp, shift) {\n  var change = shift / (wp.i - wm.i);\n  wp.c -= change;\n  wp.s += shift;\n  wm.c += change;\n  wp.z += shift;\n  wp.m += shift;\n}\n\n// All other shifts, applied to the smaller subtrees between w- and w+, are\n// performed by this function. To prepare the shifts, we have to adjust\n// change(w+), shift(w+), and change(w-).\nfunction executeShifts(v) {\n  var shift = 0,\n      change = 0,\n      children = v.children,\n      i = children.length,\n      w;\n  while (--i >= 0) {\n    w = children[i];\n    w.z += shift;\n    w.m += shift;\n    shift += w.s + (change += w.c);\n  }\n}\n\n// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,\n// returns the specified (default) ancestor.\nfunction nextAncestor(vim, v, ancestor) {\n  return vim.a.parent === v.parent ? vim.a : ancestor;\n}\n\nfunction TreeNode(node, i) {\n  this._ = node;\n  this.parent = null;\n  this.children = null;\n  this.A = null; // default ancestor\n  this.a = this; // ancestor\n  this.z = 0; // prelim\n  this.m = 0; // mod\n  this.c = 0; // change\n  this.s = 0; // shift\n  this.t = null; // thread\n  this.i = i; // number\n}\n\nTreeNode.prototype = Object.create(Node.prototype);\n\nfunction treeRoot(root) {\n  var tree = new TreeNode(root, 0),\n      node,\n      nodes = [tree],\n      child,\n      children,\n      i,\n      n;\n\n  while (node = nodes.pop()) {\n    if (children = node._.children) {\n      node.children = new Array(n = children.length);\n      for (i = n - 1; i >= 0; --i) {\n        nodes.push(child = node.children[i] = new TreeNode(children[i], i));\n        child.parent = node;\n      }\n    }\n  }\n\n  (tree.parent = new TreeNode(null, 0)).children = [tree];\n  return tree;\n}\n\n// Node-link tree diagram using the Reingold-Tilford \"tidy\" algorithm\nfunction tree() {\n  var separation = defaultSeparation$1,\n      dx = 1,\n      dy = 1,\n      nodeSize = null;\n\n  function tree(root) {\n    var t = treeRoot(root);\n\n    // Compute the layout using Buchheim et al.’s algorithm.\n    t.eachAfter(firstWalk), t.parent.m = -t.z;\n    t.eachBefore(secondWalk);\n\n    // If a fixed node size is specified, scale x and y.\n    if (nodeSize) root.eachBefore(sizeNode);\n\n    // If a fixed tree size is specified, scale x and y based on the extent.\n    // Compute the left-most, right-most, and depth-most nodes for extents.\n    else {\n      var left = root,\n          right = root,\n          bottom = root;\n      root.eachBefore(function(node) {\n        if (node.x < left.x) left = node;\n        if (node.x > right.x) right = node;\n        if (node.depth > bottom.depth) bottom = node;\n      });\n      var s = left === right ? 1 : separation(left, right) / 2,\n          tx = s - left.x,\n          kx = dx / (right.x + s + tx),\n          ky = dy / (bottom.depth || 1);\n      root.eachBefore(function(node) {\n        node.x = (node.x + tx) * kx;\n        node.y = node.depth * ky;\n      });\n    }\n\n    return root;\n  }\n\n  // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is\n  // applied recursively to the children of v, as well as the function\n  // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the\n  // node v is placed to the midpoint of its outermost children.\n  function firstWalk(v) {\n    var children = v.children,\n        siblings = v.parent.children,\n        w = v.i ? siblings[v.i - 1] : null;\n    if (children) {\n      executeShifts(v);\n      var midpoint = (children[0].z + children[children.length - 1].z) / 2;\n      if (w) {\n        v.z = w.z + separation(v._, w._);\n        v.m = v.z - midpoint;\n      } else {\n        v.z = midpoint;\n      }\n    } else if (w) {\n      v.z = w.z + separation(v._, w._);\n    }\n    v.parent.A = apportion(v, w, v.parent.A || siblings[0]);\n  }\n\n  // Computes all real x-coordinates by summing up the modifiers recursively.\n  function secondWalk(v) {\n    v._.x = v.z + v.parent.m;\n    v.m += v.parent.m;\n  }\n\n  // The core of the algorithm. Here, a new subtree is combined with the\n  // previous subtrees. Threads are used to traverse the inside and outside\n  // contours of the left and right subtree up to the highest common level. The\n  // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the\n  // superscript o means outside and i means inside, the subscript - means left\n  // subtree and + means right subtree. For summing up the modifiers along the\n  // contour, we use respective variables si+, si-, so-, and so+. Whenever two\n  // nodes of the inside contours conflict, we compute the left one of the\n  // greatest uncommon ancestors using the function ANCESTOR and call MOVE\n  // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.\n  // Finally, we add a new thread (if necessary).\n  function apportion(v, w, ancestor) {\n    if (w) {\n      var vip = v,\n          vop = v,\n          vim = w,\n          vom = vip.parent.children[0],\n          sip = vip.m,\n          sop = vop.m,\n          sim = vim.m,\n          som = vom.m,\n          shift;\n      while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {\n        vom = nextLeft(vom);\n        vop = nextRight(vop);\n        vop.a = v;\n        shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);\n        if (shift > 0) {\n          moveSubtree(nextAncestor(vim, v, ancestor), v, shift);\n          sip += shift;\n          sop += shift;\n        }\n        sim += vim.m;\n        sip += vip.m;\n        som += vom.m;\n        sop += vop.m;\n      }\n      if (vim && !nextRight(vop)) {\n        vop.t = vim;\n        vop.m += sim - sop;\n      }\n      if (vip && !nextLeft(vom)) {\n        vom.t = vip;\n        vom.m += sip - som;\n        ancestor = v;\n      }\n    }\n    return ancestor;\n  }\n\n  function sizeNode(node) {\n    node.x *= dx;\n    node.y = node.depth * dy;\n  }\n\n  tree.separation = function(x) {\n    return arguments.length ? (separation = x, tree) : separation;\n  };\n\n  tree.size = function(x) {\n    return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);\n  };\n\n  tree.nodeSize = function(x) {\n    return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);\n  };\n\n  return tree;\n}\n\nfunction treemapSlice(parent, x0, y0, x1, y1) {\n  var nodes = parent.children,\n      node,\n      i = -1,\n      n = nodes.length,\n      k = parent.value && (y1 - y0) / parent.value;\n\n  while (++i < n) {\n    node = nodes[i], node.x0 = x0, node.x1 = x1;\n    node.y0 = y0, node.y1 = y0 += node.value * k;\n  }\n}\n\nvar phi = (1 + Math.sqrt(5)) / 2;\n\nfunction squarifyRatio(ratio, parent, x0, y0, x1, y1) {\n  var rows = [],\n      nodes = parent.children,\n      row,\n      nodeValue,\n      i0 = 0,\n      i1 = 0,\n      n = nodes.length,\n      dx, dy,\n      value = parent.value,\n      sumValue,\n      minValue,\n      maxValue,\n      newRatio,\n      minRatio,\n      alpha,\n      beta;\n\n  while (i0 < n) {\n    dx = x1 - x0, dy = y1 - y0;\n\n    // Find the next non-empty node.\n    do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);\n    minValue = maxValue = sumValue;\n    alpha = Math.max(dy / dx, dx / dy) / (value * ratio);\n    beta = sumValue * sumValue * alpha;\n    minRatio = Math.max(maxValue / beta, beta / minValue);\n\n    // Keep adding nodes while the aspect ratio maintains or improves.\n    for (; i1 < n; ++i1) {\n      sumValue += nodeValue = nodes[i1].value;\n      if (nodeValue < minValue) minValue = nodeValue;\n      if (nodeValue > maxValue) maxValue = nodeValue;\n      beta = sumValue * sumValue * alpha;\n      newRatio = Math.max(maxValue / beta, beta / minValue);\n      if (newRatio > minRatio) { sumValue -= nodeValue; break; }\n      minRatio = newRatio;\n    }\n\n    // Position and record the row orientation.\n    rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});\n    if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);\n    else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);\n    value -= sumValue, i0 = i1;\n  }\n\n  return rows;\n}\n\nvar squarify = (function custom(ratio) {\n\n  function squarify(parent, x0, y0, x1, y1) {\n    squarifyRatio(ratio, parent, x0, y0, x1, y1);\n  }\n\n  squarify.ratio = function(x) {\n    return custom((x = +x) > 1 ? x : 1);\n  };\n\n  return squarify;\n})(phi);\n\nfunction index$1() {\n  var tile = squarify,\n      round = false,\n      dx = 1,\n      dy = 1,\n      paddingStack = [0],\n      paddingInner = constantZero,\n      paddingTop = constantZero,\n      paddingRight = constantZero,\n      paddingBottom = constantZero,\n      paddingLeft = constantZero;\n\n  function treemap(root) {\n    root.x0 =\n    root.y0 = 0;\n    root.x1 = dx;\n    root.y1 = dy;\n    root.eachBefore(positionNode);\n    paddingStack = [0];\n    if (round) root.eachBefore(roundNode);\n    return root;\n  }\n\n  function positionNode(node) {\n    var p = paddingStack[node.depth],\n        x0 = node.x0 + p,\n        y0 = node.y0 + p,\n        x1 = node.x1 - p,\n        y1 = node.y1 - p;\n    if (x1 < x0) x0 = x1 = (x0 + x1) / 2;\n    if (y1 < y0) y0 = y1 = (y0 + y1) / 2;\n    node.x0 = x0;\n    node.y0 = y0;\n    node.x1 = x1;\n    node.y1 = y1;\n    if (node.children) {\n      p = paddingStack[node.depth + 1] = paddingInner(node) / 2;\n      x0 += paddingLeft(node) - p;\n      y0 += paddingTop(node) - p;\n      x1 -= paddingRight(node) - p;\n      y1 -= paddingBottom(node) - p;\n      if (x1 < x0) x0 = x1 = (x0 + x1) / 2;\n      if (y1 < y0) y0 = y1 = (y0 + y1) / 2;\n      tile(node, x0, y0, x1, y1);\n    }\n  }\n\n  treemap.round = function(x) {\n    return arguments.length ? (round = !!x, treemap) : round;\n  };\n\n  treemap.size = function(x) {\n    return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];\n  };\n\n  treemap.tile = function(x) {\n    return arguments.length ? (tile = required(x), treemap) : tile;\n  };\n\n  treemap.padding = function(x) {\n    return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();\n  };\n\n  treemap.paddingInner = function(x) {\n    return arguments.length ? (paddingInner = typeof x === \"function\" ? x : constant(+x), treemap) : paddingInner;\n  };\n\n  treemap.paddingOuter = function(x) {\n    return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();\n  };\n\n  treemap.paddingTop = function(x) {\n    return arguments.length ? (paddingTop = typeof x === \"function\" ? x : constant(+x), treemap) : paddingTop;\n  };\n\n  treemap.paddingRight = function(x) {\n    return arguments.length ? (paddingRight = typeof x === \"function\" ? x : constant(+x), treemap) : paddingRight;\n  };\n\n  treemap.paddingBottom = function(x) {\n    return arguments.length ? (paddingBottom = typeof x === \"function\" ? x : constant(+x), treemap) : paddingBottom;\n  };\n\n  treemap.paddingLeft = function(x) {\n    return arguments.length ? (paddingLeft = typeof x === \"function\" ? x : constant(+x), treemap) : paddingLeft;\n  };\n\n  return treemap;\n}\n\nfunction binary(parent, x0, y0, x1, y1) {\n  var nodes = parent.children,\n      i, n = nodes.length,\n      sum, sums = new Array(n + 1);\n\n  for (sums[0] = sum = i = 0; i < n; ++i) {\n    sums[i + 1] = sum += nodes[i].value;\n  }\n\n  partition(0, n, parent.value, x0, y0, x1, y1);\n\n  function partition(i, j, value, x0, y0, x1, y1) {\n    if (i >= j - 1) {\n      var node = nodes[i];\n      node.x0 = x0, node.y0 = y0;\n      node.x1 = x1, node.y1 = y1;\n      return;\n    }\n\n    var valueOffset = sums[i],\n        valueTarget = (value / 2) + valueOffset,\n        k = i + 1,\n        hi = j - 1;\n\n    while (k < hi) {\n      var mid = k + hi >>> 1;\n      if (sums[mid] < valueTarget) k = mid + 1;\n      else hi = mid;\n    }\n\n    if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;\n\n    var valueLeft = sums[k] - valueOffset,\n        valueRight = value - valueLeft;\n\n    if ((x1 - x0) > (y1 - y0)) {\n      var xk = (x0 * valueRight + x1 * valueLeft) / value;\n      partition(i, k, valueLeft, x0, y0, xk, y1);\n      partition(k, j, valueRight, xk, y0, x1, y1);\n    } else {\n      var yk = (y0 * valueRight + y1 * valueLeft) / value;\n      partition(i, k, valueLeft, x0, y0, x1, yk);\n      partition(k, j, valueRight, x0, yk, x1, y1);\n    }\n  }\n}\n\nfunction sliceDice(parent, x0, y0, x1, y1) {\n  (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);\n}\n\nvar resquarify = (function custom(ratio) {\n\n  function resquarify(parent, x0, y0, x1, y1) {\n    if ((rows = parent._squarify) && (rows.ratio === ratio)) {\n      var rows,\n          row,\n          nodes,\n          i,\n          j = -1,\n          n,\n          m = rows.length,\n          value = parent.value;\n\n      while (++j < m) {\n        row = rows[j], nodes = row.children;\n        for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;\n        if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);\n        else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);\n        value -= row.value;\n      }\n    } else {\n      parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);\n      rows.ratio = ratio;\n    }\n  }\n\n  resquarify.ratio = function(x) {\n    return custom((x = +x) > 1 ? x : 1);\n  };\n\n  return resquarify;\n})(phi);\n\nexports.cluster = cluster;\nexports.hierarchy = hierarchy;\nexports.pack = index;\nexports.packSiblings = siblings;\nexports.packEnclose = enclose;\nexports.partition = partition;\nexports.stratify = stratify;\nexports.tree = tree;\nexports.treemap = index$1;\nexports.treemapBinary = binary;\nexports.treemapDice = treemapDice;\nexports.treemapSlice = treemapSlice;\nexports.treemapSliceDice = sliceDice;\nexports.treemapSquarify = squarify;\nexports.treemapResquarify = resquarify;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],158:[function(_dereq_,module,exports){\n// https://d3js.org/d3-interpolate/ v1.3.2 Copyright 2018 Mike Bostock\n(function (global, factory) {\ntypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, _dereq_('d3-color')) :\ntypeof define === 'function' && define.amd ? define(['exports', 'd3-color'], factory) :\n(factory((global.d3 = global.d3 || {}),global.d3));\n}(this, (function (exports,d3Color) { 'use strict';\n\nfunction basis(t1, v0, v1, v2, v3) {\n  var t2 = t1 * t1, t3 = t2 * t1;\n  return ((1 - 3 * t1 + 3 * t2 - t3) * v0\n      + (4 - 6 * t2 + 3 * t3) * v1\n      + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2\n      + t3 * v3) / 6;\n}\n\nfunction basis$1(values) {\n  var n = values.length - 1;\n  return function(t) {\n    var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),\n        v1 = values[i],\n        v2 = values[i + 1],\n        v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,\n        v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;\n    return basis((t - i / n) * n, v0, v1, v2, v3);\n  };\n}\n\nfunction basisClosed(values) {\n  var n = values.length;\n  return function(t) {\n    var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),\n        v0 = values[(i + n - 1) % n],\n        v1 = values[i % n],\n        v2 = values[(i + 1) % n],\n        v3 = values[(i + 2) % n];\n    return basis((t - i / n) * n, v0, v1, v2, v3);\n  };\n}\n\nfunction constant(x) {\n  return function() {\n    return x;\n  };\n}\n\nfunction linear(a, d) {\n  return function(t) {\n    return a + t * d;\n  };\n}\n\nfunction exponential(a, b, y) {\n  return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {\n    return Math.pow(a + t * b, y);\n  };\n}\n\nfunction hue(a, b) {\n  var d = b - a;\n  return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant(isNaN(a) ? b : a);\n}\n\nfunction gamma(y) {\n  return (y = +y) === 1 ? nogamma : function(a, b) {\n    return b - a ? exponential(a, b, y) : constant(isNaN(a) ? b : a);\n  };\n}\n\nfunction nogamma(a, b) {\n  var d = b - a;\n  return d ? linear(a, d) : constant(isNaN(a) ? b : a);\n}\n\nvar rgb = (function rgbGamma(y) {\n  var color = gamma(y);\n\n  function rgb(start, end) {\n    var r = color((start = d3Color.rgb(start)).r, (end = d3Color.rgb(end)).r),\n        g = color(start.g, end.g),\n        b = color(start.b, end.b),\n        opacity = nogamma(start.opacity, end.opacity);\n    return function(t) {\n      start.r = r(t);\n      start.g = g(t);\n      start.b = b(t);\n      start.opacity = opacity(t);\n      return start + \"\";\n    };\n  }\n\n  rgb.gamma = rgbGamma;\n\n  return rgb;\n})(1);\n\nfunction rgbSpline(spline) {\n  return function(colors) {\n    var n = colors.length,\n        r = new Array(n),\n        g = new Array(n),\n        b = new Array(n),\n        i, color;\n    for (i = 0; i < n; ++i) {\n      color = d3Color.rgb(colors[i]);\n      r[i] = color.r || 0;\n      g[i] = color.g || 0;\n      b[i] = color.b || 0;\n    }\n    r = spline(r);\n    g = spline(g);\n    b = spline(b);\n    color.opacity = 1;\n    return function(t) {\n      color.r = r(t);\n      color.g = g(t);\n      color.b = b(t);\n      return color + \"\";\n    };\n  };\n}\n\nvar rgbBasis = rgbSpline(basis$1);\nvar rgbBasisClosed = rgbSpline(basisClosed);\n\nfunction array(a, b) {\n  var nb = b ? b.length : 0,\n      na = a ? Math.min(nb, a.length) : 0,\n      x = new Array(na),\n      c = new Array(nb),\n      i;\n\n  for (i = 0; i < na; ++i) x[i] = value(a[i], b[i]);\n  for (; i < nb; ++i) c[i] = b[i];\n\n  return function(t) {\n    for (i = 0; i < na; ++i) c[i] = x[i](t);\n    return c;\n  };\n}\n\nfunction date(a, b) {\n  var d = new Date;\n  return a = +a, b -= a, function(t) {\n    return d.setTime(a + b * t), d;\n  };\n}\n\nfunction number(a, b) {\n  return a = +a, b -= a, function(t) {\n    return a + b * t;\n  };\n}\n\nfunction object(a, b) {\n  var i = {},\n      c = {},\n      k;\n\n  if (a === null || typeof a !== \"object\") a = {};\n  if (b === null || typeof b !== \"object\") b = {};\n\n  for (k in b) {\n    if (k in a) {\n      i[k] = value(a[k], b[k]);\n    } else {\n      c[k] = b[k];\n    }\n  }\n\n  return function(t) {\n    for (k in i) c[k] = i[k](t);\n    return c;\n  };\n}\n\nvar reA = /[-+]?(?:\\d+\\.?\\d*|\\.?\\d+)(?:[eE][-+]?\\d+)?/g,\n    reB = new RegExp(reA.source, \"g\");\n\nfunction zero(b) {\n  return function() {\n    return b;\n  };\n}\n\nfunction one(b) {\n  return function(t) {\n    return b(t) + \"\";\n  };\n}\n\nfunction string(a, b) {\n  var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b\n      am, // current match in a\n      bm, // current match in b\n      bs, // string preceding current number in b, if any\n      i = -1, // index in s\n      s = [], // string constants and placeholders\n      q = []; // number interpolators\n\n  // Coerce inputs to strings.\n  a = a + \"\", b = b + \"\";\n\n  // Interpolate pairs of numbers in a & b.\n  while ((am = reA.exec(a))\n      && (bm = reB.exec(b))) {\n    if ((bs = bm.index) > bi) { // a string precedes the next number in b\n      bs = b.slice(bi, bs);\n      if (s[i]) s[i] += bs; // coalesce with previous string\n      else s[++i] = bs;\n    }\n    if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match\n      if (s[i]) s[i] += bm; // coalesce with previous string\n      else s[++i] = bm;\n    } else { // interpolate non-matching numbers\n      s[++i] = null;\n      q.push({i: i, x: number(am, bm)});\n    }\n    bi = reB.lastIndex;\n  }\n\n  // Add remains of b.\n  if (bi < b.length) {\n    bs = b.slice(bi);\n    if (s[i]) s[i] += bs; // coalesce with previous string\n    else s[++i] = bs;\n  }\n\n  // Special optimization for only a single match.\n  // Otherwise, interpolate each of the numbers and rejoin the string.\n  return s.length < 2 ? (q[0]\n      ? one(q[0].x)\n      : zero(b))\n      : (b = q.length, function(t) {\n          for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);\n          return s.join(\"\");\n        });\n}\n\nfunction value(a, b) {\n  var t = typeof b, c;\n  return b == null || t === \"boolean\" ? constant(b)\n      : (t === \"number\" ? number\n      : t === \"string\" ? ((c = d3Color.color(b)) ? (b = c, rgb) : string)\n      : b instanceof d3Color.color ? rgb\n      : b instanceof Date ? date\n      : Array.isArray(b) ? array\n      : typeof b.valueOf !== \"function\" && typeof b.toString !== \"function\" || isNaN(b) ? object\n      : number)(a, b);\n}\n\nfunction discrete(range) {\n  var n = range.length;\n  return function(t) {\n    return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];\n  };\n}\n\nfunction hue$1(a, b) {\n  var i = hue(+a, +b);\n  return function(t) {\n    var x = i(t);\n    return x - 360 * Math.floor(x / 360);\n  };\n}\n\nfunction round(a, b) {\n  return a = +a, b -= a, function(t) {\n    return Math.round(a + b * t);\n  };\n}\n\nvar degrees = 180 / Math.PI;\n\nvar identity = {\n  translateX: 0,\n  translateY: 0,\n  rotate: 0,\n  skewX: 0,\n  scaleX: 1,\n  scaleY: 1\n};\n\nfunction decompose(a, b, c, d, e, f) {\n  var scaleX, scaleY, skewX;\n  if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;\n  if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;\n  if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;\n  if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;\n  return {\n    translateX: e,\n    translateY: f,\n    rotate: Math.atan2(b, a) * degrees,\n    skewX: Math.atan(skewX) * degrees,\n    scaleX: scaleX,\n    scaleY: scaleY\n  };\n}\n\nvar cssNode,\n    cssRoot,\n    cssView,\n    svgNode;\n\nfunction parseCss(value) {\n  if (value === \"none\") return identity;\n  if (!cssNode) cssNode = document.createElement(\"DIV\"), cssRoot = document.documentElement, cssView = document.defaultView;\n  cssNode.style.transform = value;\n  value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue(\"transform\");\n  cssRoot.removeChild(cssNode);\n  value = value.slice(7, -1).split(\",\");\n  return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);\n}\n\nfunction parseSvg(value) {\n  if (value == null) return identity;\n  if (!svgNode) svgNode = document.createElementNS(\"http://www.w3.org/2000/svg\", \"g\");\n  svgNode.setAttribute(\"transform\", value);\n  if (!(value = svgNode.transform.baseVal.consolidate())) return identity;\n  value = value.matrix;\n  return decompose(value.a, value.b, value.c, value.d, value.e, value.f);\n}\n\nfunction interpolateTransform(parse, pxComma, pxParen, degParen) {\n\n  function pop(s) {\n    return s.length ? s.pop() + \" \" : \"\";\n  }\n\n  function translate(xa, ya, xb, yb, s, q) {\n    if (xa !== xb || ya !== yb) {\n      var i = s.push(\"translate(\", null, pxComma, null, pxParen);\n      q.push({i: i - 4, x: number(xa, xb)}, {i: i - 2, x: number(ya, yb)});\n    } else if (xb || yb) {\n      s.push(\"translate(\" + xb + pxComma + yb + pxParen);\n    }\n  }\n\n  function rotate(a, b, s, q) {\n    if (a !== b) {\n      if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path\n      q.push({i: s.push(pop(s) + \"rotate(\", null, degParen) - 2, x: number(a, b)});\n    } else if (b) {\n      s.push(pop(s) + \"rotate(\" + b + degParen);\n    }\n  }\n\n  function skewX(a, b, s, q) {\n    if (a !== b) {\n      q.push({i: s.push(pop(s) + \"skewX(\", null, degParen) - 2, x: number(a, b)});\n    } else if (b) {\n      s.push(pop(s) + \"skewX(\" + b + degParen);\n    }\n  }\n\n  function scale(xa, ya, xb, yb, s, q) {\n    if (xa !== xb || ya !== yb) {\n      var i = s.push(pop(s) + \"scale(\", null, \",\", null, \")\");\n      q.push({i: i - 4, x: number(xa, xb)}, {i: i - 2, x: number(ya, yb)});\n    } else if (xb !== 1 || yb !== 1) {\n      s.push(pop(s) + \"scale(\" + xb + \",\" + yb + \")\");\n    }\n  }\n\n  return function(a, b) {\n    var s = [], // string constants and placeholders\n        q = []; // number interpolators\n    a = parse(a), b = parse(b);\n    translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);\n    rotate(a.rotate, b.rotate, s, q);\n    skewX(a.skewX, b.skewX, s, q);\n    scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);\n    a = b = null; // gc\n    return function(t) {\n      var i = -1, n = q.length, o;\n      while (++i < n) s[(o = q[i]).i] = o.x(t);\n      return s.join(\"\");\n    };\n  };\n}\n\nvar interpolateTransformCss = interpolateTransform(parseCss, \"px, \", \"px)\", \"deg)\");\nvar interpolateTransformSvg = interpolateTransform(parseSvg, \", \", \")\", \")\");\n\nvar rho = Math.SQRT2,\n    rho2 = 2,\n    rho4 = 4,\n    epsilon2 = 1e-12;\n\nfunction cosh(x) {\n  return ((x = Math.exp(x)) + 1 / x) / 2;\n}\n\nfunction sinh(x) {\n  return ((x = Math.exp(x)) - 1 / x) / 2;\n}\n\nfunction tanh(x) {\n  return ((x = Math.exp(2 * x)) - 1) / (x + 1);\n}\n\n// p0 = [ux0, uy0, w0]\n// p1 = [ux1, uy1, w1]\nfunction zoom(p0, p1) {\n  var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],\n      ux1 = p1[0], uy1 = p1[1], w1 = p1[2],\n      dx = ux1 - ux0,\n      dy = uy1 - uy0,\n      d2 = dx * dx + dy * dy,\n      i,\n      S;\n\n  // Special case for u0 ≅ u1.\n  if (d2 < epsilon2) {\n    S = Math.log(w1 / w0) / rho;\n    i = function(t) {\n      return [\n        ux0 + t * dx,\n        uy0 + t * dy,\n        w0 * Math.exp(rho * t * S)\n      ];\n    };\n  }\n\n  // General case.\n  else {\n    var d1 = Math.sqrt(d2),\n        b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),\n        b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),\n        r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),\n        r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n    S = (r1 - r0) / rho;\n    i = function(t) {\n      var s = t * S,\n          coshr0 = cosh(r0),\n          u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));\n      return [\n        ux0 + u * dx,\n        uy0 + u * dy,\n        w0 * coshr0 / cosh(rho * s + r0)\n      ];\n    };\n  }\n\n  i.duration = S * 1000;\n\n  return i;\n}\n\nfunction hsl(hue$$1) {\n  return function(start, end) {\n    var h = hue$$1((start = d3Color.hsl(start)).h, (end = d3Color.hsl(end)).h),\n        s = nogamma(start.s, end.s),\n        l = nogamma(start.l, end.l),\n        opacity = nogamma(start.opacity, end.opacity);\n    return function(t) {\n      start.h = h(t);\n      start.s = s(t);\n      start.l = l(t);\n      start.opacity = opacity(t);\n      return start + \"\";\n    };\n  }\n}\n\nvar hsl$1 = hsl(hue);\nvar hslLong = hsl(nogamma);\n\nfunction lab(start, end) {\n  var l = nogamma((start = d3Color.lab(start)).l, (end = d3Color.lab(end)).l),\n      a = nogamma(start.a, end.a),\n      b = nogamma(start.b, end.b),\n      opacity = nogamma(start.opacity, end.opacity);\n  return function(t) {\n    start.l = l(t);\n    start.a = a(t);\n    start.b = b(t);\n    start.opacity = opacity(t);\n    return start + \"\";\n  };\n}\n\nfunction hcl(hue$$1) {\n  return function(start, end) {\n    var h = hue$$1((start = d3Color.hcl(start)).h, (end = d3Color.hcl(end)).h),\n        c = nogamma(start.c, end.c),\n        l = nogamma(start.l, end.l),\n        opacity = nogamma(start.opacity, end.opacity);\n    return function(t) {\n      start.h = h(t);\n      start.c = c(t);\n      start.l = l(t);\n      start.opacity = opacity(t);\n      return start + \"\";\n    };\n  }\n}\n\nvar hcl$1 = hcl(hue);\nvar hclLong = hcl(nogamma);\n\nfunction cubehelix(hue$$1) {\n  return (function cubehelixGamma(y) {\n    y = +y;\n\n    function cubehelix(start, end) {\n      var h = hue$$1((start = d3Color.cubehelix(start)).h, (end = d3Color.cubehelix(end)).h),\n          s = nogamma(start.s, end.s),\n          l = nogamma(start.l, end.l),\n          opacity = nogamma(start.opacity, end.opacity);\n      return function(t) {\n        start.h = h(t);\n        start.s = s(t);\n        start.l = l(Math.pow(t, y));\n        start.opacity = opacity(t);\n        return start + \"\";\n      };\n    }\n\n    cubehelix.gamma = cubehelixGamma;\n\n    return cubehelix;\n  })(1);\n}\n\nvar cubehelix$1 = cubehelix(hue);\nvar cubehelixLong = cubehelix(nogamma);\n\nfunction piecewise(interpolate, values) {\n  var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);\n  while (i < n) I[i] = interpolate(v, v = values[++i]);\n  return function(t) {\n    var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));\n    return I[i](t - i);\n  };\n}\n\nfunction quantize(interpolator, n) {\n  var samples = new Array(n);\n  for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));\n  return samples;\n}\n\nexports.interpolate = value;\nexports.interpolateArray = array;\nexports.interpolateBasis = basis$1;\nexports.interpolateBasisClosed = basisClosed;\nexports.interpolateDate = date;\nexports.interpolateDiscrete = discrete;\nexports.interpolateHue = hue$1;\nexports.interpolateNumber = number;\nexports.interpolateObject = object;\nexports.interpolateRound = round;\nexports.interpolateString = string;\nexports.interpolateTransformCss = interpolateTransformCss;\nexports.interpolateTransformSvg = interpolateTransformSvg;\nexports.interpolateZoom = zoom;\nexports.interpolateRgb = rgb;\nexports.interpolateRgbBasis = rgbBasis;\nexports.interpolateRgbBasisClosed = rgbBasisClosed;\nexports.interpolateHsl = hsl$1;\nexports.interpolateHslLong = hslLong;\nexports.interpolateLab = lab;\nexports.interpolateHcl = hcl$1;\nexports.interpolateHclLong = hclLong;\nexports.interpolateCubehelix = cubehelix$1;\nexports.interpolateCubehelixLong = cubehelixLong;\nexports.piecewise = piecewise;\nexports.quantize = quantize;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{\"d3-color\":154}],159:[function(_dereq_,module,exports){\n// https://d3js.org/d3-path/ v1.0.7 Copyright 2018 Mike Bostock\n(function (global, factory) {\ntypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\ntypeof define === 'function' && define.amd ? define(['exports'], factory) :\n(factory((global.d3 = global.d3 || {})));\n}(this, (function (exports) { 'use strict';\n\nvar pi = Math.PI,\n    tau = 2 * pi,\n    epsilon = 1e-6,\n    tauEpsilon = tau - epsilon;\n\nfunction Path() {\n  this._x0 = this._y0 = // start of current subpath\n  this._x1 = this._y1 = null; // end of current subpath\n  this._ = \"\";\n}\n\nfunction path() {\n  return new Path;\n}\n\nPath.prototype = path.prototype = {\n  constructor: Path,\n  moveTo: function(x, y) {\n    this._ += \"M\" + (this._x0 = this._x1 = +x) + \",\" + (this._y0 = this._y1 = +y);\n  },\n  closePath: function() {\n    if (this._x1 !== null) {\n      this._x1 = this._x0, this._y1 = this._y0;\n      this._ += \"Z\";\n    }\n  },\n  lineTo: function(x, y) {\n    this._ += \"L\" + (this._x1 = +x) + \",\" + (this._y1 = +y);\n  },\n  quadraticCurveTo: function(x1, y1, x, y) {\n    this._ += \"Q\" + (+x1) + \",\" + (+y1) + \",\" + (this._x1 = +x) + \",\" + (this._y1 = +y);\n  },\n  bezierCurveTo: function(x1, y1, x2, y2, x, y) {\n    this._ += \"C\" + (+x1) + \",\" + (+y1) + \",\" + (+x2) + \",\" + (+y2) + \",\" + (this._x1 = +x) + \",\" + (this._y1 = +y);\n  },\n  arcTo: function(x1, y1, x2, y2, r) {\n    x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;\n    var x0 = this._x1,\n        y0 = this._y1,\n        x21 = x2 - x1,\n        y21 = y2 - y1,\n        x01 = x0 - x1,\n        y01 = y0 - y1,\n        l01_2 = x01 * x01 + y01 * y01;\n\n    // Is the radius negative? Error.\n    if (r < 0) throw new Error(\"negative radius: \" + r);\n\n    // Is this path empty? Move to (x1,y1).\n    if (this._x1 === null) {\n      this._ += \"M\" + (this._x1 = x1) + \",\" + (this._y1 = y1);\n    }\n\n    // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.\n    else if (!(l01_2 > epsilon));\n\n    // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?\n    // Equivalently, is (x1,y1) coincident with (x2,y2)?\n    // Or, is the radius zero? Line to (x1,y1).\n    else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) {\n      this._ += \"L\" + (this._x1 = x1) + \",\" + (this._y1 = y1);\n    }\n\n    // Otherwise, draw an arc!\n    else {\n      var x20 = x2 - x0,\n          y20 = y2 - y0,\n          l21_2 = x21 * x21 + y21 * y21,\n          l20_2 = x20 * x20 + y20 * y20,\n          l21 = Math.sqrt(l21_2),\n          l01 = Math.sqrt(l01_2),\n          l = r * Math.tan((pi - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),\n          t01 = l / l01,\n          t21 = l / l21;\n\n      // If the start tangent is not coincident with (x0,y0), line to.\n      if (Math.abs(t01 - 1) > epsilon) {\n        this._ += \"L\" + (x1 + t01 * x01) + \",\" + (y1 + t01 * y01);\n      }\n\n      this._ += \"A\" + r + \",\" + r + \",0,0,\" + (+(y01 * x20 > x01 * y20)) + \",\" + (this._x1 = x1 + t21 * x21) + \",\" + (this._y1 = y1 + t21 * y21);\n    }\n  },\n  arc: function(x, y, r, a0, a1, ccw) {\n    x = +x, y = +y, r = +r;\n    var dx = r * Math.cos(a0),\n        dy = r * Math.sin(a0),\n        x0 = x + dx,\n        y0 = y + dy,\n        cw = 1 ^ ccw,\n        da = ccw ? a0 - a1 : a1 - a0;\n\n    // Is the radius negative? Error.\n    if (r < 0) throw new Error(\"negative radius: \" + r);\n\n    // Is this path empty? Move to (x0,y0).\n    if (this._x1 === null) {\n      this._ += \"M\" + x0 + \",\" + y0;\n    }\n\n    // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).\n    else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) {\n      this._ += \"L\" + x0 + \",\" + y0;\n    }\n\n    // Is this arc empty? We’re done.\n    if (!r) return;\n\n    // Does the angle go the wrong way? Flip the direction.\n    if (da < 0) da = da % tau + tau;\n\n    // Is this a complete circle? Draw two arcs to complete the circle.\n    if (da > tauEpsilon) {\n      this._ += \"A\" + r + \",\" + r + \",0,1,\" + cw + \",\" + (x - dx) + \",\" + (y - dy) + \"A\" + r + \",\" + r + \",0,1,\" + cw + \",\" + (this._x1 = x0) + \",\" + (this._y1 = y0);\n    }\n\n    // Is this arc non-empty? Draw an arc!\n    else if (da > epsilon) {\n      this._ += \"A\" + r + \",\" + r + \",0,\" + (+(da >= pi)) + \",\" + cw + \",\" + (this._x1 = x + r * Math.cos(a1)) + \",\" + (this._y1 = y + r * Math.sin(a1));\n    }\n  },\n  rect: function(x, y, w, h) {\n    this._ += \"M\" + (this._x0 = this._x1 = +x) + \",\" + (this._y0 = this._y1 = +y) + \"h\" + (+w) + \"v\" + (+h) + \"h\" + (-w) + \"Z\";\n  },\n  toString: function() {\n    return this._;\n  }\n};\n\nexports.path = path;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],160:[function(_dereq_,module,exports){\n// https://d3js.org/d3-quadtree/ Version 1.0.3. Copyright 2017 Mike Bostock.\n(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n\ttypeof define === 'function' && define.amd ? define(['exports'], factory) :\n\t(factory((global.d3 = global.d3 || {})));\n}(this, (function (exports) { 'use strict';\n\nvar tree_add = function(d) {\n  var x = +this._x.call(null, d),\n      y = +this._y.call(null, d);\n  return add(this.cover(x, y), x, y, d);\n};\n\nfunction add(tree, x, y, d) {\n  if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points\n\n  var parent,\n      node = tree._root,\n      leaf = {data: d},\n      x0 = tree._x0,\n      y0 = tree._y0,\n      x1 = tree._x1,\n      y1 = tree._y1,\n      xm,\n      ym,\n      xp,\n      yp,\n      right,\n      bottom,\n      i,\n      j;\n\n  // If the tree is empty, initialize the root as a leaf.\n  if (!node) return tree._root = leaf, tree;\n\n  // Find the existing leaf for the new point, or add it.\n  while (node.length) {\n    if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;\n    if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;\n    if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;\n  }\n\n  // Is the new point is exactly coincident with the existing point?\n  xp = +tree._x.call(null, node.data);\n  yp = +tree._y.call(null, node.data);\n  if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;\n\n  // Otherwise, split the leaf node until the old and new point are separated.\n  do {\n    parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);\n    if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;\n    if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;\n  } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));\n  return parent[j] = node, parent[i] = leaf, tree;\n}\n\nfunction addAll(data) {\n  var d, i, n = data.length,\n      x,\n      y,\n      xz = new Array(n),\n      yz = new Array(n),\n      x0 = Infinity,\n      y0 = Infinity,\n      x1 = -Infinity,\n      y1 = -Infinity;\n\n  // Compute the points and their extent.\n  for (i = 0; i < n; ++i) {\n    if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;\n    xz[i] = x;\n    yz[i] = y;\n    if (x < x0) x0 = x;\n    if (x > x1) x1 = x;\n    if (y < y0) y0 = y;\n    if (y > y1) y1 = y;\n  }\n\n  // If there were no (valid) points, inherit the existing extent.\n  if (x1 < x0) x0 = this._x0, x1 = this._x1;\n  if (y1 < y0) y0 = this._y0, y1 = this._y1;\n\n  // Expand the tree to cover the new points.\n  this.cover(x0, y0).cover(x1, y1);\n\n  // Add the new points.\n  for (i = 0; i < n; ++i) {\n    add(this, xz[i], yz[i], data[i]);\n  }\n\n  return this;\n}\n\nvar tree_cover = function(x, y) {\n  if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points\n\n  var x0 = this._x0,\n      y0 = this._y0,\n      x1 = this._x1,\n      y1 = this._y1;\n\n  // If the quadtree has no extent, initialize them.\n  // Integer extent are necessary so that if we later double the extent,\n  // the existing quadrant boundaries don’t change due to floating point error!\n  if (isNaN(x0)) {\n    x1 = (x0 = Math.floor(x)) + 1;\n    y1 = (y0 = Math.floor(y)) + 1;\n  }\n\n  // Otherwise, double repeatedly to cover.\n  else if (x0 > x || x > x1 || y0 > y || y > y1) {\n    var z = x1 - x0,\n        node = this._root,\n        parent,\n        i;\n\n    switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {\n      case 0: {\n        do parent = new Array(4), parent[i] = node, node = parent;\n        while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);\n        break;\n      }\n      case 1: {\n        do parent = new Array(4), parent[i] = node, node = parent;\n        while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);\n        break;\n      }\n      case 2: {\n        do parent = new Array(4), parent[i] = node, node = parent;\n        while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);\n        break;\n      }\n      case 3: {\n        do parent = new Array(4), parent[i] = node, node = parent;\n        while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);\n        break;\n      }\n    }\n\n    if (this._root && this._root.length) this._root = node;\n  }\n\n  // If the quadtree covers the point already, just return.\n  else return this;\n\n  this._x0 = x0;\n  this._y0 = y0;\n  this._x1 = x1;\n  this._y1 = y1;\n  return this;\n};\n\nvar tree_data = function() {\n  var data = [];\n  this.visit(function(node) {\n    if (!node.length) do data.push(node.data); while (node = node.next)\n  });\n  return data;\n};\n\nvar tree_extent = function(_) {\n  return arguments.length\n      ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])\n      : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];\n};\n\nvar Quad = function(node, x0, y0, x1, y1) {\n  this.node = node;\n  this.x0 = x0;\n  this.y0 = y0;\n  this.x1 = x1;\n  this.y1 = y1;\n};\n\nvar tree_find = function(x, y, radius) {\n  var data,\n      x0 = this._x0,\n      y0 = this._y0,\n      x1,\n      y1,\n      x2,\n      y2,\n      x3 = this._x1,\n      y3 = this._y1,\n      quads = [],\n      node = this._root,\n      q,\n      i;\n\n  if (node) quads.push(new Quad(node, x0, y0, x3, y3));\n  if (radius == null) radius = Infinity;\n  else {\n    x0 = x - radius, y0 = y - radius;\n    x3 = x + radius, y3 = y + radius;\n    radius *= radius;\n  }\n\n  while (q = quads.pop()) {\n\n    // Stop searching if this quadrant can’t contain a closer node.\n    if (!(node = q.node)\n        || (x1 = q.x0) > x3\n        || (y1 = q.y0) > y3\n        || (x2 = q.x1) < x0\n        || (y2 = q.y1) < y0) continue;\n\n    // Bisect the current quadrant.\n    if (node.length) {\n      var xm = (x1 + x2) / 2,\n          ym = (y1 + y2) / 2;\n\n      quads.push(\n        new Quad(node[3], xm, ym, x2, y2),\n        new Quad(node[2], x1, ym, xm, y2),\n        new Quad(node[1], xm, y1, x2, ym),\n        new Quad(node[0], x1, y1, xm, ym)\n      );\n\n      // Visit the closest quadrant first.\n      if (i = (y >= ym) << 1 | (x >= xm)) {\n        q = quads[quads.length - 1];\n        quads[quads.length - 1] = quads[quads.length - 1 - i];\n        quads[quads.length - 1 - i] = q;\n      }\n    }\n\n    // Visit this point. (Visiting coincident points isn’t necessary!)\n    else {\n      var dx = x - +this._x.call(null, node.data),\n          dy = y - +this._y.call(null, node.data),\n          d2 = dx * dx + dy * dy;\n      if (d2 < radius) {\n        var d = Math.sqrt(radius = d2);\n        x0 = x - d, y0 = y - d;\n        x3 = x + d, y3 = y + d;\n        data = node.data;\n      }\n    }\n  }\n\n  return data;\n};\n\nvar tree_remove = function(d) {\n  if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points\n\n  var parent,\n      node = this._root,\n      retainer,\n      previous,\n      next,\n      x0 = this._x0,\n      y0 = this._y0,\n      x1 = this._x1,\n      y1 = this._y1,\n      x,\n      y,\n      xm,\n      ym,\n      right,\n      bottom,\n      i,\n      j;\n\n  // If the tree is empty, initialize the root as a leaf.\n  if (!node) return this;\n\n  // Find the leaf node for the point.\n  // While descending, also retain the deepest parent with a non-removed sibling.\n  if (node.length) while (true) {\n    if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;\n    if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;\n    if (!(parent = node, node = node[i = bottom << 1 | right])) return this;\n    if (!node.length) break;\n    if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;\n  }\n\n  // Find the point to remove.\n  while (node.data !== d) if (!(previous = node, node = node.next)) return this;\n  if (next = node.next) delete node.next;\n\n  // If there are multiple coincident points, remove just the point.\n  if (previous) return (next ? previous.next = next : delete previous.next), this;\n\n  // If this is the root point, remove it.\n  if (!parent) return this._root = next, this;\n\n  // Remove this leaf.\n  next ? parent[i] = next : delete parent[i];\n\n  // If the parent now contains exactly one leaf, collapse superfluous parents.\n  if ((node = parent[0] || parent[1] || parent[2] || parent[3])\n      && node === (parent[3] || parent[2] || parent[1] || parent[0])\n      && !node.length) {\n    if (retainer) retainer[j] = node;\n    else this._root = node;\n  }\n\n  return this;\n};\n\nfunction removeAll(data) {\n  for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);\n  return this;\n}\n\nvar tree_root = function() {\n  return this._root;\n};\n\nvar tree_size = function() {\n  var size = 0;\n  this.visit(function(node) {\n    if (!node.length) do ++size; while (node = node.next)\n  });\n  return size;\n};\n\nvar tree_visit = function(callback) {\n  var quads = [], q, node = this._root, child, x0, y0, x1, y1;\n  if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));\n  while (q = quads.pop()) {\n    if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {\n      var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;\n      if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));\n      if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));\n      if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));\n      if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));\n    }\n  }\n  return this;\n};\n\nvar tree_visitAfter = function(callback) {\n  var quads = [], next = [], q;\n  if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));\n  while (q = quads.pop()) {\n    var node = q.node;\n    if (node.length) {\n      var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;\n      if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));\n      if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));\n      if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));\n      if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));\n    }\n    next.push(q);\n  }\n  while (q = next.pop()) {\n    callback(q.node, q.x0, q.y0, q.x1, q.y1);\n  }\n  return this;\n};\n\nfunction defaultX(d) {\n  return d[0];\n}\n\nvar tree_x = function(_) {\n  return arguments.length ? (this._x = _, this) : this._x;\n};\n\nfunction defaultY(d) {\n  return d[1];\n}\n\nvar tree_y = function(_) {\n  return arguments.length ? (this._y = _, this) : this._y;\n};\n\nfunction quadtree(nodes, x, y) {\n  var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);\n  return nodes == null ? tree : tree.addAll(nodes);\n}\n\nfunction Quadtree(x, y, x0, y0, x1, y1) {\n  this._x = x;\n  this._y = y;\n  this._x0 = x0;\n  this._y0 = y0;\n  this._x1 = x1;\n  this._y1 = y1;\n  this._root = undefined;\n}\n\nfunction leaf_copy(leaf) {\n  var copy = {data: leaf.data}, next = copy;\n  while (leaf = leaf.next) next = next.next = {data: leaf.data};\n  return copy;\n}\n\nvar treeProto = quadtree.prototype = Quadtree.prototype;\n\ntreeProto.copy = function() {\n  var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),\n      node = this._root,\n      nodes,\n      child;\n\n  if (!node) return copy;\n\n  if (!node.length) return copy._root = leaf_copy(node), copy;\n\n  nodes = [{source: node, target: copy._root = new Array(4)}];\n  while (node = nodes.pop()) {\n    for (var i = 0; i < 4; ++i) {\n      if (child = node.source[i]) {\n        if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});\n        else node.target[i] = leaf_copy(child);\n      }\n    }\n  }\n\n  return copy;\n};\n\ntreeProto.add = tree_add;\ntreeProto.addAll = addAll;\ntreeProto.cover = tree_cover;\ntreeProto.data = tree_data;\ntreeProto.extent = tree_extent;\ntreeProto.find = tree_find;\ntreeProto.remove = tree_remove;\ntreeProto.removeAll = removeAll;\ntreeProto.root = tree_root;\ntreeProto.size = tree_size;\ntreeProto.visit = tree_visit;\ntreeProto.visitAfter = tree_visitAfter;\ntreeProto.x = tree_x;\ntreeProto.y = tree_y;\n\nexports.quadtree = quadtree;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],161:[function(_dereq_,module,exports){\n// https://d3js.org/d3-shape/ v1.3.4 Copyright 2019 Mike Bostock\n(function (global, factory) {\ntypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, _dereq_('d3-path')) :\ntypeof define === 'function' && define.amd ? define(['exports', 'd3-path'], factory) :\n(factory((global.d3 = global.d3 || {}),global.d3));\n}(this, (function (exports,d3Path) { 'use strict';\n\nfunction constant(x) {\n  return function constant() {\n    return x;\n  };\n}\n\nvar abs = Math.abs;\nvar atan2 = Math.atan2;\nvar cos = Math.cos;\nvar max = Math.max;\nvar min = Math.min;\nvar sin = Math.sin;\nvar sqrt = Math.sqrt;\n\nvar epsilon = 1e-12;\nvar pi = Math.PI;\nvar halfPi = pi / 2;\nvar tau = 2 * pi;\n\nfunction acos(x) {\n  return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);\n}\n\nfunction asin(x) {\n  return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);\n}\n\nfunction arcInnerRadius(d) {\n  return d.innerRadius;\n}\n\nfunction arcOuterRadius(d) {\n  return d.outerRadius;\n}\n\nfunction arcStartAngle(d) {\n  return d.startAngle;\n}\n\nfunction arcEndAngle(d) {\n  return d.endAngle;\n}\n\nfunction arcPadAngle(d) {\n  return d && d.padAngle; // Note: optional!\n}\n\nfunction intersect(x0, y0, x1, y1, x2, y2, x3, y3) {\n  var x10 = x1 - x0, y10 = y1 - y0,\n      x32 = x3 - x2, y32 = y3 - y2,\n      t = y32 * x10 - x32 * y10;\n  if (t * t < epsilon) return;\n  t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;\n  return [x0 + t * x10, y0 + t * y10];\n}\n\n// Compute perpendicular offset line of length rc.\n// http://mathworld.wolfram.com/Circle-LineIntersection.html\nfunction cornerTangents(x0, y0, x1, y1, r1, rc, cw) {\n  var x01 = x0 - x1,\n      y01 = y0 - y1,\n      lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),\n      ox = lo * y01,\n      oy = -lo * x01,\n      x11 = x0 + ox,\n      y11 = y0 + oy,\n      x10 = x1 + ox,\n      y10 = y1 + oy,\n      x00 = (x11 + x10) / 2,\n      y00 = (y11 + y10) / 2,\n      dx = x10 - x11,\n      dy = y10 - y11,\n      d2 = dx * dx + dy * dy,\n      r = r1 - rc,\n      D = x11 * y10 - x10 * y11,\n      d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),\n      cx0 = (D * dy - dx * d) / d2,\n      cy0 = (-D * dx - dy * d) / d2,\n      cx1 = (D * dy + dx * d) / d2,\n      cy1 = (-D * dx + dy * d) / d2,\n      dx0 = cx0 - x00,\n      dy0 = cy0 - y00,\n      dx1 = cx1 - x00,\n      dy1 = cy1 - y00;\n\n  // Pick the closer of the two intersection points.\n  // TODO Is there a faster way to determine which intersection to use?\n  if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;\n\n  return {\n    cx: cx0,\n    cy: cy0,\n    x01: -ox,\n    y01: -oy,\n    x11: cx0 * (r1 / r - 1),\n    y11: cy0 * (r1 / r - 1)\n  };\n}\n\nfunction arc() {\n  var innerRadius = arcInnerRadius,\n      outerRadius = arcOuterRadius,\n      cornerRadius = constant(0),\n      padRadius = null,\n      startAngle = arcStartAngle,\n      endAngle = arcEndAngle,\n      padAngle = arcPadAngle,\n      context = null;\n\n  function arc() {\n    var buffer,\n        r,\n        r0 = +innerRadius.apply(this, arguments),\n        r1 = +outerRadius.apply(this, arguments),\n        a0 = startAngle.apply(this, arguments) - halfPi,\n        a1 = endAngle.apply(this, arguments) - halfPi,\n        da = abs(a1 - a0),\n        cw = a1 > a0;\n\n    if (!context) context = buffer = d3Path.path();\n\n    // Ensure that the outer radius is always larger than the inner radius.\n    if (r1 < r0) r = r1, r1 = r0, r0 = r;\n\n    // Is it a point?\n    if (!(r1 > epsilon)) context.moveTo(0, 0);\n\n    // Or is it a circle or annulus?\n    else if (da > tau - epsilon) {\n      context.moveTo(r1 * cos(a0), r1 * sin(a0));\n      context.arc(0, 0, r1, a0, a1, !cw);\n      if (r0 > epsilon) {\n        context.moveTo(r0 * cos(a1), r0 * sin(a1));\n        context.arc(0, 0, r0, a1, a0, cw);\n      }\n    }\n\n    // Or is it a circular or annular sector?\n    else {\n      var a01 = a0,\n          a11 = a1,\n          a00 = a0,\n          a10 = a1,\n          da0 = da,\n          da1 = da,\n          ap = padAngle.apply(this, arguments) / 2,\n          rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),\n          rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),\n          rc0 = rc,\n          rc1 = rc,\n          t0,\n          t1;\n\n      // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.\n      if (rp > epsilon) {\n        var p0 = asin(rp / r0 * sin(ap)),\n            p1 = asin(rp / r1 * sin(ap));\n        if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;\n        else da0 = 0, a00 = a10 = (a0 + a1) / 2;\n        if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;\n        else da1 = 0, a01 = a11 = (a0 + a1) / 2;\n      }\n\n      var x01 = r1 * cos(a01),\n          y01 = r1 * sin(a01),\n          x10 = r0 * cos(a10),\n          y10 = r0 * sin(a10);\n\n      // Apply rounded corners?\n      if (rc > epsilon) {\n        var x11 = r1 * cos(a11),\n            y11 = r1 * sin(a11),\n            x00 = r0 * cos(a00),\n            y00 = r0 * sin(a00),\n            oc;\n\n        // Restrict the corner radius according to the sector angle.\n        if (da < pi && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {\n          var ax = x01 - oc[0],\n              ay = y01 - oc[1],\n              bx = x11 - oc[0],\n              by = y11 - oc[1],\n              kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),\n              lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);\n          rc0 = min(rc, (r0 - lc) / (kc - 1));\n          rc1 = min(rc, (r1 - lc) / (kc + 1));\n        }\n      }\n\n      // Is the sector collapsed to a line?\n      if (!(da1 > epsilon)) context.moveTo(x01, y01);\n\n      // Does the sector’s outer ring have rounded corners?\n      else if (rc1 > epsilon) {\n        t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);\n        t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);\n\n        context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);\n\n        // Have the corners merged?\n        if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);\n\n        // Otherwise, draw the two corners and the ring.\n        else {\n          context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);\n          context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);\n          context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);\n        }\n      }\n\n      // Or is the outer ring just a circular arc?\n      else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);\n\n      // Is there no inner ring, and it’s a circular sector?\n      // Or perhaps it’s an annular sector collapsed due to padding?\n      if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);\n\n      // Does the sector’s inner ring (or point) have rounded corners?\n      else if (rc0 > epsilon) {\n        t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);\n        t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);\n\n        context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);\n\n        // Have the corners merged?\n        if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);\n\n        // Otherwise, draw the two corners and the ring.\n        else {\n          context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);\n          context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);\n          context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);\n        }\n      }\n\n      // Or is the inner ring just a circular arc?\n      else context.arc(0, 0, r0, a10, a00, cw);\n    }\n\n    context.closePath();\n\n    if (buffer) return context = null, buffer + \"\" || null;\n  }\n\n  arc.centroid = function() {\n    var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,\n        a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;\n    return [cos(a) * r, sin(a) * r];\n  };\n\n  arc.innerRadius = function(_) {\n    return arguments.length ? (innerRadius = typeof _ === \"function\" ? _ : constant(+_), arc) : innerRadius;\n  };\n\n  arc.outerRadius = function(_) {\n    return arguments.length ? (outerRadius = typeof _ === \"function\" ? _ : constant(+_), arc) : outerRadius;\n  };\n\n  arc.cornerRadius = function(_) {\n    return arguments.length ? (cornerRadius = typeof _ === \"function\" ? _ : constant(+_), arc) : cornerRadius;\n  };\n\n  arc.padRadius = function(_) {\n    return arguments.length ? (padRadius = _ == null ? null : typeof _ === \"function\" ? _ : constant(+_), arc) : padRadius;\n  };\n\n  arc.startAngle = function(_) {\n    return arguments.length ? (startAngle = typeof _ === \"function\" ? _ : constant(+_), arc) : startAngle;\n  };\n\n  arc.endAngle = function(_) {\n    return arguments.length ? (endAngle = typeof _ === \"function\" ? _ : constant(+_), arc) : endAngle;\n  };\n\n  arc.padAngle = function(_) {\n    return arguments.length ? (padAngle = typeof _ === \"function\" ? _ : constant(+_), arc) : padAngle;\n  };\n\n  arc.context = function(_) {\n    return arguments.length ? ((context = _ == null ? null : _), arc) : context;\n  };\n\n  return arc;\n}\n\nfunction Linear(context) {\n  this._context = context;\n}\n\nLinear.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._point = 0;\n  },\n  lineEnd: function() {\n    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();\n    this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    switch (this._point) {\n      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;\n      case 1: this._point = 2; // proceed\n      default: this._context.lineTo(x, y); break;\n    }\n  }\n};\n\nfunction curveLinear(context) {\n  return new Linear(context);\n}\n\nfunction x(p) {\n  return p[0];\n}\n\nfunction y(p) {\n  return p[1];\n}\n\nfunction line() {\n  var x$$1 = x,\n      y$$1 = y,\n      defined = constant(true),\n      context = null,\n      curve = curveLinear,\n      output = null;\n\n  function line(data) {\n    var i,\n        n = data.length,\n        d,\n        defined0 = false,\n        buffer;\n\n    if (context == null) output = curve(buffer = d3Path.path());\n\n    for (i = 0; i <= n; ++i) {\n      if (!(i < n && defined(d = data[i], i, data)) === defined0) {\n        if (defined0 = !defined0) output.lineStart();\n        else output.lineEnd();\n      }\n      if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));\n    }\n\n    if (buffer) return output = null, buffer + \"\" || null;\n  }\n\n  line.x = function(_) {\n    return arguments.length ? (x$$1 = typeof _ === \"function\" ? _ : constant(+_), line) : x$$1;\n  };\n\n  line.y = function(_) {\n    return arguments.length ? (y$$1 = typeof _ === \"function\" ? _ : constant(+_), line) : y$$1;\n  };\n\n  line.defined = function(_) {\n    return arguments.length ? (defined = typeof _ === \"function\" ? _ : constant(!!_), line) : defined;\n  };\n\n  line.curve = function(_) {\n    return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;\n  };\n\n  line.context = function(_) {\n    return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;\n  };\n\n  return line;\n}\n\nfunction area() {\n  var x0 = x,\n      x1 = null,\n      y0 = constant(0),\n      y1 = y,\n      defined = constant(true),\n      context = null,\n      curve = curveLinear,\n      output = null;\n\n  function area(data) {\n    var i,\n        j,\n        k,\n        n = data.length,\n        d,\n        defined0 = false,\n        buffer,\n        x0z = new Array(n),\n        y0z = new Array(n);\n\n    if (context == null) output = curve(buffer = d3Path.path());\n\n    for (i = 0; i <= n; ++i) {\n      if (!(i < n && defined(d = data[i], i, data)) === defined0) {\n        if (defined0 = !defined0) {\n          j = i;\n          output.areaStart();\n          output.lineStart();\n        } else {\n          output.lineEnd();\n          output.lineStart();\n          for (k = i - 1; k >= j; --k) {\n            output.point(x0z[k], y0z[k]);\n          }\n          output.lineEnd();\n          output.areaEnd();\n        }\n      }\n      if (defined0) {\n        x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);\n        output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);\n      }\n    }\n\n    if (buffer) return output = null, buffer + \"\" || null;\n  }\n\n  function arealine() {\n    return line().defined(defined).curve(curve).context(context);\n  }\n\n  area.x = function(_) {\n    return arguments.length ? (x0 = typeof _ === \"function\" ? _ : constant(+_), x1 = null, area) : x0;\n  };\n\n  area.x0 = function(_) {\n    return arguments.length ? (x0 = typeof _ === \"function\" ? _ : constant(+_), area) : x0;\n  };\n\n  area.x1 = function(_) {\n    return arguments.length ? (x1 = _ == null ? null : typeof _ === \"function\" ? _ : constant(+_), area) : x1;\n  };\n\n  area.y = function(_) {\n    return arguments.length ? (y0 = typeof _ === \"function\" ? _ : constant(+_), y1 = null, area) : y0;\n  };\n\n  area.y0 = function(_) {\n    return arguments.length ? (y0 = typeof _ === \"function\" ? _ : constant(+_), area) : y0;\n  };\n\n  area.y1 = function(_) {\n    return arguments.length ? (y1 = _ == null ? null : typeof _ === \"function\" ? _ : constant(+_), area) : y1;\n  };\n\n  area.lineX0 =\n  area.lineY0 = function() {\n    return arealine().x(x0).y(y0);\n  };\n\n  area.lineY1 = function() {\n    return arealine().x(x0).y(y1);\n  };\n\n  area.lineX1 = function() {\n    return arealine().x(x1).y(y0);\n  };\n\n  area.defined = function(_) {\n    return arguments.length ? (defined = typeof _ === \"function\" ? _ : constant(!!_), area) : defined;\n  };\n\n  area.curve = function(_) {\n    return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;\n  };\n\n  area.context = function(_) {\n    return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;\n  };\n\n  return area;\n}\n\nfunction descending(a, b) {\n  return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;\n}\n\nfunction identity(d) {\n  return d;\n}\n\nfunction pie() {\n  var value = identity,\n      sortValues = descending,\n      sort = null,\n      startAngle = constant(0),\n      endAngle = constant(tau),\n      padAngle = constant(0);\n\n  function pie(data) {\n    var i,\n        n = data.length,\n        j,\n        k,\n        sum = 0,\n        index = new Array(n),\n        arcs = new Array(n),\n        a0 = +startAngle.apply(this, arguments),\n        da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),\n        a1,\n        p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),\n        pa = p * (da < 0 ? -1 : 1),\n        v;\n\n    for (i = 0; i < n; ++i) {\n      if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {\n        sum += v;\n      }\n    }\n\n    // Optionally sort the arcs by previously-computed values or by data.\n    if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });\n    else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });\n\n    // Compute the arcs! They are stored in the original data's order.\n    for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {\n      j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {\n        data: data[j],\n        index: i,\n        value: v,\n        startAngle: a0,\n        endAngle: a1,\n        padAngle: p\n      };\n    }\n\n    return arcs;\n  }\n\n  pie.value = function(_) {\n    return arguments.length ? (value = typeof _ === \"function\" ? _ : constant(+_), pie) : value;\n  };\n\n  pie.sortValues = function(_) {\n    return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;\n  };\n\n  pie.sort = function(_) {\n    return arguments.length ? (sort = _, sortValues = null, pie) : sort;\n  };\n\n  pie.startAngle = function(_) {\n    return arguments.length ? (startAngle = typeof _ === \"function\" ? _ : constant(+_), pie) : startAngle;\n  };\n\n  pie.endAngle = function(_) {\n    return arguments.length ? (endAngle = typeof _ === \"function\" ? _ : constant(+_), pie) : endAngle;\n  };\n\n  pie.padAngle = function(_) {\n    return arguments.length ? (padAngle = typeof _ === \"function\" ? _ : constant(+_), pie) : padAngle;\n  };\n\n  return pie;\n}\n\nvar curveRadialLinear = curveRadial(curveLinear);\n\nfunction Radial(curve) {\n  this._curve = curve;\n}\n\nRadial.prototype = {\n  areaStart: function() {\n    this._curve.areaStart();\n  },\n  areaEnd: function() {\n    this._curve.areaEnd();\n  },\n  lineStart: function() {\n    this._curve.lineStart();\n  },\n  lineEnd: function() {\n    this._curve.lineEnd();\n  },\n  point: function(a, r) {\n    this._curve.point(r * Math.sin(a), r * -Math.cos(a));\n  }\n};\n\nfunction curveRadial(curve) {\n\n  function radial(context) {\n    return new Radial(curve(context));\n  }\n\n  radial._curve = curve;\n\n  return radial;\n}\n\nfunction lineRadial(l) {\n  var c = l.curve;\n\n  l.angle = l.x, delete l.x;\n  l.radius = l.y, delete l.y;\n\n  l.curve = function(_) {\n    return arguments.length ? c(curveRadial(_)) : c()._curve;\n  };\n\n  return l;\n}\n\nfunction lineRadial$1() {\n  return lineRadial(line().curve(curveRadialLinear));\n}\n\nfunction areaRadial() {\n  var a = area().curve(curveRadialLinear),\n      c = a.curve,\n      x0 = a.lineX0,\n      x1 = a.lineX1,\n      y0 = a.lineY0,\n      y1 = a.lineY1;\n\n  a.angle = a.x, delete a.x;\n  a.startAngle = a.x0, delete a.x0;\n  a.endAngle = a.x1, delete a.x1;\n  a.radius = a.y, delete a.y;\n  a.innerRadius = a.y0, delete a.y0;\n  a.outerRadius = a.y1, delete a.y1;\n  a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;\n  a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;\n  a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;\n  a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;\n\n  a.curve = function(_) {\n    return arguments.length ? c(curveRadial(_)) : c()._curve;\n  };\n\n  return a;\n}\n\nfunction pointRadial(x, y) {\n  return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];\n}\n\nvar slice = Array.prototype.slice;\n\nfunction linkSource(d) {\n  return d.source;\n}\n\nfunction linkTarget(d) {\n  return d.target;\n}\n\nfunction link(curve) {\n  var source = linkSource,\n      target = linkTarget,\n      x$$1 = x,\n      y$$1 = y,\n      context = null;\n\n  function link() {\n    var buffer, argv = slice.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);\n    if (!context) context = buffer = d3Path.path();\n    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));\n    if (buffer) return context = null, buffer + \"\" || null;\n  }\n\n  link.source = function(_) {\n    return arguments.length ? (source = _, link) : source;\n  };\n\n  link.target = function(_) {\n    return arguments.length ? (target = _, link) : target;\n  };\n\n  link.x = function(_) {\n    return arguments.length ? (x$$1 = typeof _ === \"function\" ? _ : constant(+_), link) : x$$1;\n  };\n\n  link.y = function(_) {\n    return arguments.length ? (y$$1 = typeof _ === \"function\" ? _ : constant(+_), link) : y$$1;\n  };\n\n  link.context = function(_) {\n    return arguments.length ? ((context = _ == null ? null : _), link) : context;\n  };\n\n  return link;\n}\n\nfunction curveHorizontal(context, x0, y0, x1, y1) {\n  context.moveTo(x0, y0);\n  context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);\n}\n\nfunction curveVertical(context, x0, y0, x1, y1) {\n  context.moveTo(x0, y0);\n  context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);\n}\n\nfunction curveRadial$1(context, x0, y0, x1, y1) {\n  var p0 = pointRadial(x0, y0),\n      p1 = pointRadial(x0, y0 = (y0 + y1) / 2),\n      p2 = pointRadial(x1, y0),\n      p3 = pointRadial(x1, y1);\n  context.moveTo(p0[0], p0[1]);\n  context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);\n}\n\nfunction linkHorizontal() {\n  return link(curveHorizontal);\n}\n\nfunction linkVertical() {\n  return link(curveVertical);\n}\n\nfunction linkRadial() {\n  var l = link(curveRadial$1);\n  l.angle = l.x, delete l.x;\n  l.radius = l.y, delete l.y;\n  return l;\n}\n\nvar circle = {\n  draw: function(context, size) {\n    var r = Math.sqrt(size / pi);\n    context.moveTo(r, 0);\n    context.arc(0, 0, r, 0, tau);\n  }\n};\n\nvar cross = {\n  draw: function(context, size) {\n    var r = Math.sqrt(size / 5) / 2;\n    context.moveTo(-3 * r, -r);\n    context.lineTo(-r, -r);\n    context.lineTo(-r, -3 * r);\n    context.lineTo(r, -3 * r);\n    context.lineTo(r, -r);\n    context.lineTo(3 * r, -r);\n    context.lineTo(3 * r, r);\n    context.lineTo(r, r);\n    context.lineTo(r, 3 * r);\n    context.lineTo(-r, 3 * r);\n    context.lineTo(-r, r);\n    context.lineTo(-3 * r, r);\n    context.closePath();\n  }\n};\n\nvar tan30 = Math.sqrt(1 / 3),\n    tan30_2 = tan30 * 2;\n\nvar diamond = {\n  draw: function(context, size) {\n    var y = Math.sqrt(size / tan30_2),\n        x = y * tan30;\n    context.moveTo(0, -y);\n    context.lineTo(x, 0);\n    context.lineTo(0, y);\n    context.lineTo(-x, 0);\n    context.closePath();\n  }\n};\n\nvar ka = 0.89081309152928522810,\n    kr = Math.sin(pi / 10) / Math.sin(7 * pi / 10),\n    kx = Math.sin(tau / 10) * kr,\n    ky = -Math.cos(tau / 10) * kr;\n\nvar star = {\n  draw: function(context, size) {\n    var r = Math.sqrt(size * ka),\n        x = kx * r,\n        y = ky * r;\n    context.moveTo(0, -r);\n    context.lineTo(x, y);\n    for (var i = 1; i < 5; ++i) {\n      var a = tau * i / 5,\n          c = Math.cos(a),\n          s = Math.sin(a);\n      context.lineTo(s * r, -c * r);\n      context.lineTo(c * x - s * y, s * x + c * y);\n    }\n    context.closePath();\n  }\n};\n\nvar square = {\n  draw: function(context, size) {\n    var w = Math.sqrt(size),\n        x = -w / 2;\n    context.rect(x, x, w, w);\n  }\n};\n\nvar sqrt3 = Math.sqrt(3);\n\nvar triangle = {\n  draw: function(context, size) {\n    var y = -Math.sqrt(size / (sqrt3 * 3));\n    context.moveTo(0, y * 2);\n    context.lineTo(-sqrt3 * y, -y);\n    context.lineTo(sqrt3 * y, -y);\n    context.closePath();\n  }\n};\n\nvar c = -0.5,\n    s = Math.sqrt(3) / 2,\n    k = 1 / Math.sqrt(12),\n    a = (k / 2 + 1) * 3;\n\nvar wye = {\n  draw: function(context, size) {\n    var r = Math.sqrt(size / a),\n        x0 = r / 2,\n        y0 = r * k,\n        x1 = x0,\n        y1 = r * k + r,\n        x2 = -x1,\n        y2 = y1;\n    context.moveTo(x0, y0);\n    context.lineTo(x1, y1);\n    context.lineTo(x2, y2);\n    context.lineTo(c * x0 - s * y0, s * x0 + c * y0);\n    context.lineTo(c * x1 - s * y1, s * x1 + c * y1);\n    context.lineTo(c * x2 - s * y2, s * x2 + c * y2);\n    context.lineTo(c * x0 + s * y0, c * y0 - s * x0);\n    context.lineTo(c * x1 + s * y1, c * y1 - s * x1);\n    context.lineTo(c * x2 + s * y2, c * y2 - s * x2);\n    context.closePath();\n  }\n};\n\nvar symbols = [\n  circle,\n  cross,\n  diamond,\n  square,\n  star,\n  triangle,\n  wye\n];\n\nfunction symbol() {\n  var type = constant(circle),\n      size = constant(64),\n      context = null;\n\n  function symbol() {\n    var buffer;\n    if (!context) context = buffer = d3Path.path();\n    type.apply(this, arguments).draw(context, +size.apply(this, arguments));\n    if (buffer) return context = null, buffer + \"\" || null;\n  }\n\n  symbol.type = function(_) {\n    return arguments.length ? (type = typeof _ === \"function\" ? _ : constant(_), symbol) : type;\n  };\n\n  symbol.size = function(_) {\n    return arguments.length ? (size = typeof _ === \"function\" ? _ : constant(+_), symbol) : size;\n  };\n\n  symbol.context = function(_) {\n    return arguments.length ? (context = _ == null ? null : _, symbol) : context;\n  };\n\n  return symbol;\n}\n\nfunction noop() {}\n\nfunction point(that, x, y) {\n  that._context.bezierCurveTo(\n    (2 * that._x0 + that._x1) / 3,\n    (2 * that._y0 + that._y1) / 3,\n    (that._x0 + 2 * that._x1) / 3,\n    (that._y0 + 2 * that._y1) / 3,\n    (that._x0 + 4 * that._x1 + x) / 6,\n    (that._y0 + 4 * that._y1 + y) / 6\n  );\n}\n\nfunction Basis(context) {\n  this._context = context;\n}\n\nBasis.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x0 = this._x1 =\n    this._y0 = this._y1 = NaN;\n    this._point = 0;\n  },\n  lineEnd: function() {\n    switch (this._point) {\n      case 3: point(this, this._x1, this._y1); // proceed\n      case 2: this._context.lineTo(this._x1, this._y1); break;\n    }\n    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();\n    this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    switch (this._point) {\n      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;\n      case 1: this._point = 2; break;\n      case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed\n      default: point(this, x, y); break;\n    }\n    this._x0 = this._x1, this._x1 = x;\n    this._y0 = this._y1, this._y1 = y;\n  }\n};\n\nfunction basis(context) {\n  return new Basis(context);\n}\n\nfunction BasisClosed(context) {\n  this._context = context;\n}\n\nBasisClosed.prototype = {\n  areaStart: noop,\n  areaEnd: noop,\n  lineStart: function() {\n    this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =\n    this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;\n    this._point = 0;\n  },\n  lineEnd: function() {\n    switch (this._point) {\n      case 1: {\n        this._context.moveTo(this._x2, this._y2);\n        this._context.closePath();\n        break;\n      }\n      case 2: {\n        this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);\n        this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);\n        this._context.closePath();\n        break;\n      }\n      case 3: {\n        this.point(this._x2, this._y2);\n        this.point(this._x3, this._y3);\n        this.point(this._x4, this._y4);\n        break;\n      }\n    }\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    switch (this._point) {\n      case 0: this._point = 1; this._x2 = x, this._y2 = y; break;\n      case 1: this._point = 2; this._x3 = x, this._y3 = y; break;\n      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;\n      default: point(this, x, y); break;\n    }\n    this._x0 = this._x1, this._x1 = x;\n    this._y0 = this._y1, this._y1 = y;\n  }\n};\n\nfunction basisClosed(context) {\n  return new BasisClosed(context);\n}\n\nfunction BasisOpen(context) {\n  this._context = context;\n}\n\nBasisOpen.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x0 = this._x1 =\n    this._y0 = this._y1 = NaN;\n    this._point = 0;\n  },\n  lineEnd: function() {\n    if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();\n    this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    switch (this._point) {\n      case 0: this._point = 1; break;\n      case 1: this._point = 2; break;\n      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;\n      case 3: this._point = 4; // proceed\n      default: point(this, x, y); break;\n    }\n    this._x0 = this._x1, this._x1 = x;\n    this._y0 = this._y1, this._y1 = y;\n  }\n};\n\nfunction basisOpen(context) {\n  return new BasisOpen(context);\n}\n\nfunction Bundle(context, beta) {\n  this._basis = new Basis(context);\n  this._beta = beta;\n}\n\nBundle.prototype = {\n  lineStart: function() {\n    this._x = [];\n    this._y = [];\n    this._basis.lineStart();\n  },\n  lineEnd: function() {\n    var x = this._x,\n        y = this._y,\n        j = x.length - 1;\n\n    if (j > 0) {\n      var x0 = x[0],\n          y0 = y[0],\n          dx = x[j] - x0,\n          dy = y[j] - y0,\n          i = -1,\n          t;\n\n      while (++i <= j) {\n        t = i / j;\n        this._basis.point(\n          this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),\n          this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)\n        );\n      }\n    }\n\n    this._x = this._y = null;\n    this._basis.lineEnd();\n  },\n  point: function(x, y) {\n    this._x.push(+x);\n    this._y.push(+y);\n  }\n};\n\nvar bundle = (function custom(beta) {\n\n  function bundle(context) {\n    return beta === 1 ? new Basis(context) : new Bundle(context, beta);\n  }\n\n  bundle.beta = function(beta) {\n    return custom(+beta);\n  };\n\n  return bundle;\n})(0.85);\n\nfunction point$1(that, x, y) {\n  that._context.bezierCurveTo(\n    that._x1 + that._k * (that._x2 - that._x0),\n    that._y1 + that._k * (that._y2 - that._y0),\n    that._x2 + that._k * (that._x1 - x),\n    that._y2 + that._k * (that._y1 - y),\n    that._x2,\n    that._y2\n  );\n}\n\nfunction Cardinal(context, tension) {\n  this._context = context;\n  this._k = (1 - tension) / 6;\n}\n\nCardinal.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x0 = this._x1 = this._x2 =\n    this._y0 = this._y1 = this._y2 = NaN;\n    this._point = 0;\n  },\n  lineEnd: function() {\n    switch (this._point) {\n      case 2: this._context.lineTo(this._x2, this._y2); break;\n      case 3: point$1(this, this._x1, this._y1); break;\n    }\n    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();\n    this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    switch (this._point) {\n      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;\n      case 1: this._point = 2; this._x1 = x, this._y1 = y; break;\n      case 2: this._point = 3; // proceed\n      default: point$1(this, x, y); break;\n    }\n    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;\n    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;\n  }\n};\n\nvar cardinal = (function custom(tension) {\n\n  function cardinal(context) {\n    return new Cardinal(context, tension);\n  }\n\n  cardinal.tension = function(tension) {\n    return custom(+tension);\n  };\n\n  return cardinal;\n})(0);\n\nfunction CardinalClosed(context, tension) {\n  this._context = context;\n  this._k = (1 - tension) / 6;\n}\n\nCardinalClosed.prototype = {\n  areaStart: noop,\n  areaEnd: noop,\n  lineStart: function() {\n    this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =\n    this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;\n    this._point = 0;\n  },\n  lineEnd: function() {\n    switch (this._point) {\n      case 1: {\n        this._context.moveTo(this._x3, this._y3);\n        this._context.closePath();\n        break;\n      }\n      case 2: {\n        this._context.lineTo(this._x3, this._y3);\n        this._context.closePath();\n        break;\n      }\n      case 3: {\n        this.point(this._x3, this._y3);\n        this.point(this._x4, this._y4);\n        this.point(this._x5, this._y5);\n        break;\n      }\n    }\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    switch (this._point) {\n      case 0: this._point = 1; this._x3 = x, this._y3 = y; break;\n      case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;\n      case 2: this._point = 3; this._x5 = x, this._y5 = y; break;\n      default: point$1(this, x, y); break;\n    }\n    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;\n    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;\n  }\n};\n\nvar cardinalClosed = (function custom(tension) {\n\n  function cardinal$$1(context) {\n    return new CardinalClosed(context, tension);\n  }\n\n  cardinal$$1.tension = function(tension) {\n    return custom(+tension);\n  };\n\n  return cardinal$$1;\n})(0);\n\nfunction CardinalOpen(context, tension) {\n  this._context = context;\n  this._k = (1 - tension) / 6;\n}\n\nCardinalOpen.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x0 = this._x1 = this._x2 =\n    this._y0 = this._y1 = this._y2 = NaN;\n    this._point = 0;\n  },\n  lineEnd: function() {\n    if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();\n    this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    switch (this._point) {\n      case 0: this._point = 1; break;\n      case 1: this._point = 2; break;\n      case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;\n      case 3: this._point = 4; // proceed\n      default: point$1(this, x, y); break;\n    }\n    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;\n    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;\n  }\n};\n\nvar cardinalOpen = (function custom(tension) {\n\n  function cardinal$$1(context) {\n    return new CardinalOpen(context, tension);\n  }\n\n  cardinal$$1.tension = function(tension) {\n    return custom(+tension);\n  };\n\n  return cardinal$$1;\n})(0);\n\nfunction point$2(that, x, y) {\n  var x1 = that._x1,\n      y1 = that._y1,\n      x2 = that._x2,\n      y2 = that._y2;\n\n  if (that._l01_a > epsilon) {\n    var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,\n        n = 3 * that._l01_a * (that._l01_a + that._l12_a);\n    x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;\n    y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;\n  }\n\n  if (that._l23_a > epsilon) {\n    var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,\n        m = 3 * that._l23_a * (that._l23_a + that._l12_a);\n    x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;\n    y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;\n  }\n\n  that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);\n}\n\nfunction CatmullRom(context, alpha) {\n  this._context = context;\n  this._alpha = alpha;\n}\n\nCatmullRom.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x0 = this._x1 = this._x2 =\n    this._y0 = this._y1 = this._y2 = NaN;\n    this._l01_a = this._l12_a = this._l23_a =\n    this._l01_2a = this._l12_2a = this._l23_2a =\n    this._point = 0;\n  },\n  lineEnd: function() {\n    switch (this._point) {\n      case 2: this._context.lineTo(this._x2, this._y2); break;\n      case 3: this.point(this._x2, this._y2); break;\n    }\n    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();\n    this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n\n    if (this._point) {\n      var x23 = this._x2 - x,\n          y23 = this._y2 - y;\n      this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));\n    }\n\n    switch (this._point) {\n      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;\n      case 1: this._point = 2; break;\n      case 2: this._point = 3; // proceed\n      default: point$2(this, x, y); break;\n    }\n\n    this._l01_a = this._l12_a, this._l12_a = this._l23_a;\n    this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;\n    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;\n    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;\n  }\n};\n\nvar catmullRom = (function custom(alpha) {\n\n  function catmullRom(context) {\n    return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);\n  }\n\n  catmullRom.alpha = function(alpha) {\n    return custom(+alpha);\n  };\n\n  return catmullRom;\n})(0.5);\n\nfunction CatmullRomClosed(context, alpha) {\n  this._context = context;\n  this._alpha = alpha;\n}\n\nCatmullRomClosed.prototype = {\n  areaStart: noop,\n  areaEnd: noop,\n  lineStart: function() {\n    this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =\n    this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;\n    this._l01_a = this._l12_a = this._l23_a =\n    this._l01_2a = this._l12_2a = this._l23_2a =\n    this._point = 0;\n  },\n  lineEnd: function() {\n    switch (this._point) {\n      case 1: {\n        this._context.moveTo(this._x3, this._y3);\n        this._context.closePath();\n        break;\n      }\n      case 2: {\n        this._context.lineTo(this._x3, this._y3);\n        this._context.closePath();\n        break;\n      }\n      case 3: {\n        this.point(this._x3, this._y3);\n        this.point(this._x4, this._y4);\n        this.point(this._x5, this._y5);\n        break;\n      }\n    }\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n\n    if (this._point) {\n      var x23 = this._x2 - x,\n          y23 = this._y2 - y;\n      this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));\n    }\n\n    switch (this._point) {\n      case 0: this._point = 1; this._x3 = x, this._y3 = y; break;\n      case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;\n      case 2: this._point = 3; this._x5 = x, this._y5 = y; break;\n      default: point$2(this, x, y); break;\n    }\n\n    this._l01_a = this._l12_a, this._l12_a = this._l23_a;\n    this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;\n    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;\n    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;\n  }\n};\n\nvar catmullRomClosed = (function custom(alpha) {\n\n  function catmullRom$$1(context) {\n    return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);\n  }\n\n  catmullRom$$1.alpha = function(alpha) {\n    return custom(+alpha);\n  };\n\n  return catmullRom$$1;\n})(0.5);\n\nfunction CatmullRomOpen(context, alpha) {\n  this._context = context;\n  this._alpha = alpha;\n}\n\nCatmullRomOpen.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x0 = this._x1 = this._x2 =\n    this._y0 = this._y1 = this._y2 = NaN;\n    this._l01_a = this._l12_a = this._l23_a =\n    this._l01_2a = this._l12_2a = this._l23_2a =\n    this._point = 0;\n  },\n  lineEnd: function() {\n    if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();\n    this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n\n    if (this._point) {\n      var x23 = this._x2 - x,\n          y23 = this._y2 - y;\n      this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));\n    }\n\n    switch (this._point) {\n      case 0: this._point = 1; break;\n      case 1: this._point = 2; break;\n      case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;\n      case 3: this._point = 4; // proceed\n      default: point$2(this, x, y); break;\n    }\n\n    this._l01_a = this._l12_a, this._l12_a = this._l23_a;\n    this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;\n    this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;\n    this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;\n  }\n};\n\nvar catmullRomOpen = (function custom(alpha) {\n\n  function catmullRom$$1(context) {\n    return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);\n  }\n\n  catmullRom$$1.alpha = function(alpha) {\n    return custom(+alpha);\n  };\n\n  return catmullRom$$1;\n})(0.5);\n\nfunction LinearClosed(context) {\n  this._context = context;\n}\n\nLinearClosed.prototype = {\n  areaStart: noop,\n  areaEnd: noop,\n  lineStart: function() {\n    this._point = 0;\n  },\n  lineEnd: function() {\n    if (this._point) this._context.closePath();\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    if (this._point) this._context.lineTo(x, y);\n    else this._point = 1, this._context.moveTo(x, y);\n  }\n};\n\nfunction linearClosed(context) {\n  return new LinearClosed(context);\n}\n\nfunction sign(x) {\n  return x < 0 ? -1 : 1;\n}\n\n// Calculate the slopes of the tangents (Hermite-type interpolation) based on\n// the following paper: Steffen, M. 1990. A Simple Method for Monotonic\n// Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.\n// NOV(II), P. 443, 1990.\nfunction slope3(that, x2, y2) {\n  var h0 = that._x1 - that._x0,\n      h1 = x2 - that._x1,\n      s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),\n      s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),\n      p = (s0 * h1 + s1 * h0) / (h0 + h1);\n  return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;\n}\n\n// Calculate a one-sided slope.\nfunction slope2(that, t) {\n  var h = that._x1 - that._x0;\n  return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;\n}\n\n// According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations\n// \"you can express cubic Hermite interpolation in terms of cubic Bézier curves\n// with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1\".\nfunction point$3(that, t0, t1) {\n  var x0 = that._x0,\n      y0 = that._y0,\n      x1 = that._x1,\n      y1 = that._y1,\n      dx = (x1 - x0) / 3;\n  that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);\n}\n\nfunction MonotoneX(context) {\n  this._context = context;\n}\n\nMonotoneX.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x0 = this._x1 =\n    this._y0 = this._y1 =\n    this._t0 = NaN;\n    this._point = 0;\n  },\n  lineEnd: function() {\n    switch (this._point) {\n      case 2: this._context.lineTo(this._x1, this._y1); break;\n      case 3: point$3(this, this._t0, slope2(this, this._t0)); break;\n    }\n    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();\n    this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    var t1 = NaN;\n\n    x = +x, y = +y;\n    if (x === this._x1 && y === this._y1) return; // Ignore coincident points.\n    switch (this._point) {\n      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;\n      case 1: this._point = 2; break;\n      case 2: this._point = 3; point$3(this, slope2(this, t1 = slope3(this, x, y)), t1); break;\n      default: point$3(this, this._t0, t1 = slope3(this, x, y)); break;\n    }\n\n    this._x0 = this._x1, this._x1 = x;\n    this._y0 = this._y1, this._y1 = y;\n    this._t0 = t1;\n  }\n};\n\nfunction MonotoneY(context) {\n  this._context = new ReflectContext(context);\n}\n\n(MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {\n  MonotoneX.prototype.point.call(this, y, x);\n};\n\nfunction ReflectContext(context) {\n  this._context = context;\n}\n\nReflectContext.prototype = {\n  moveTo: function(x, y) { this._context.moveTo(y, x); },\n  closePath: function() { this._context.closePath(); },\n  lineTo: function(x, y) { this._context.lineTo(y, x); },\n  bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }\n};\n\nfunction monotoneX(context) {\n  return new MonotoneX(context);\n}\n\nfunction monotoneY(context) {\n  return new MonotoneY(context);\n}\n\nfunction Natural(context) {\n  this._context = context;\n}\n\nNatural.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x = [];\n    this._y = [];\n  },\n  lineEnd: function() {\n    var x = this._x,\n        y = this._y,\n        n = x.length;\n\n    if (n) {\n      this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);\n      if (n === 2) {\n        this._context.lineTo(x[1], y[1]);\n      } else {\n        var px = controlPoints(x),\n            py = controlPoints(y);\n        for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {\n          this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);\n        }\n      }\n    }\n\n    if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();\n    this._line = 1 - this._line;\n    this._x = this._y = null;\n  },\n  point: function(x, y) {\n    this._x.push(+x);\n    this._y.push(+y);\n  }\n};\n\n// See https://www.particleincell.com/2012/bezier-splines/ for derivation.\nfunction controlPoints(x) {\n  var i,\n      n = x.length - 1,\n      m,\n      a = new Array(n),\n      b = new Array(n),\n      r = new Array(n);\n  a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];\n  for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];\n  a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];\n  for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];\n  a[n - 1] = r[n - 1] / b[n - 1];\n  for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];\n  b[n - 1] = (x[n] + a[n - 1]) / 2;\n  for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];\n  return [a, b];\n}\n\nfunction natural(context) {\n  return new Natural(context);\n}\n\nfunction Step(context, t) {\n  this._context = context;\n  this._t = t;\n}\n\nStep.prototype = {\n  areaStart: function() {\n    this._line = 0;\n  },\n  areaEnd: function() {\n    this._line = NaN;\n  },\n  lineStart: function() {\n    this._x = this._y = NaN;\n    this._point = 0;\n  },\n  lineEnd: function() {\n    if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);\n    if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();\n    if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;\n  },\n  point: function(x, y) {\n    x = +x, y = +y;\n    switch (this._point) {\n      case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;\n      case 1: this._point = 2; // proceed\n      default: {\n        if (this._t <= 0) {\n          this._context.lineTo(this._x, y);\n          this._context.lineTo(x, y);\n        } else {\n          var x1 = this._x * (1 - this._t) + x * this._t;\n          this._context.lineTo(x1, this._y);\n          this._context.lineTo(x1, y);\n        }\n        break;\n      }\n    }\n    this._x = x, this._y = y;\n  }\n};\n\nfunction step(context) {\n  return new Step(context, 0.5);\n}\n\nfunction stepBefore(context) {\n  return new Step(context, 0);\n}\n\nfunction stepAfter(context) {\n  return new Step(context, 1);\n}\n\nfunction none(series, order) {\n  if (!((n = series.length) > 1)) return;\n  for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {\n    s0 = s1, s1 = series[order[i]];\n    for (j = 0; j < m; ++j) {\n      s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];\n    }\n  }\n}\n\nfunction none$1(series) {\n  var n = series.length, o = new Array(n);\n  while (--n >= 0) o[n] = n;\n  return o;\n}\n\nfunction stackValue(d, key) {\n  return d[key];\n}\n\nfunction stack() {\n  var keys = constant([]),\n      order = none$1,\n      offset = none,\n      value = stackValue;\n\n  function stack(data) {\n    var kz = keys.apply(this, arguments),\n        i,\n        m = data.length,\n        n = kz.length,\n        sz = new Array(n),\n        oz;\n\n    for (i = 0; i < n; ++i) {\n      for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {\n        si[j] = sij = [0, +value(data[j], ki, j, data)];\n        sij.data = data[j];\n      }\n      si.key = ki;\n    }\n\n    for (i = 0, oz = order(sz); i < n; ++i) {\n      sz[oz[i]].index = i;\n    }\n\n    offset(sz, oz);\n    return sz;\n  }\n\n  stack.keys = function(_) {\n    return arguments.length ? (keys = typeof _ === \"function\" ? _ : constant(slice.call(_)), stack) : keys;\n  };\n\n  stack.value = function(_) {\n    return arguments.length ? (value = typeof _ === \"function\" ? _ : constant(+_), stack) : value;\n  };\n\n  stack.order = function(_) {\n    return arguments.length ? (order = _ == null ? none$1 : typeof _ === \"function\" ? _ : constant(slice.call(_)), stack) : order;\n  };\n\n  stack.offset = function(_) {\n    return arguments.length ? (offset = _ == null ? none : _, stack) : offset;\n  };\n\n  return stack;\n}\n\nfunction expand(series, order) {\n  if (!((n = series.length) > 0)) return;\n  for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {\n    for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;\n    if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;\n  }\n  none(series, order);\n}\n\nfunction diverging(series, order) {\n  if (!((n = series.length) > 1)) return;\n  for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {\n    for (yp = yn = 0, i = 0; i < n; ++i) {\n      if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {\n        d[0] = yp, d[1] = yp += dy;\n      } else if (dy < 0) {\n        d[1] = yn, d[0] = yn += dy;\n      } else {\n        d[0] = yp;\n      }\n    }\n  }\n}\n\nfunction silhouette(series, order) {\n  if (!((n = series.length) > 0)) return;\n  for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {\n    for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;\n    s0[j][1] += s0[j][0] = -y / 2;\n  }\n  none(series, order);\n}\n\nfunction wiggle(series, order) {\n  if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;\n  for (var y = 0, j = 1, s0, m, n; j < m; ++j) {\n    for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {\n      var si = series[order[i]],\n          sij0 = si[j][1] || 0,\n          sij1 = si[j - 1][1] || 0,\n          s3 = (sij0 - sij1) / 2;\n      for (var k = 0; k < i; ++k) {\n        var sk = series[order[k]],\n            skj0 = sk[j][1] || 0,\n            skj1 = sk[j - 1][1] || 0;\n        s3 += skj0 - skj1;\n      }\n      s1 += sij0, s2 += s3 * sij0;\n    }\n    s0[j - 1][1] += s0[j - 1][0] = y;\n    if (s1) y -= s2 / s1;\n  }\n  s0[j - 1][1] += s0[j - 1][0] = y;\n  none(series, order);\n}\n\nfunction appearance(series) {\n  var peaks = series.map(peak);\n  return none$1(series).sort(function(a, b) { return peaks[a] - peaks[b]; });\n}\n\nfunction peak(series) {\n  var i = -1, j = 0, n = series.length, vi, vj = -Infinity;\n  while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;\n  return j;\n}\n\nfunction ascending(series) {\n  var sums = series.map(sum);\n  return none$1(series).sort(function(a, b) { return sums[a] - sums[b]; });\n}\n\nfunction sum(series) {\n  var s = 0, i = -1, n = series.length, v;\n  while (++i < n) if (v = +series[i][1]) s += v;\n  return s;\n}\n\nfunction descending$1(series) {\n  return ascending(series).reverse();\n}\n\nfunction insideOut(series) {\n  var n = series.length,\n      i,\n      j,\n      sums = series.map(sum),\n      order = appearance(series),\n      top = 0,\n      bottom = 0,\n      tops = [],\n      bottoms = [];\n\n  for (i = 0; i < n; ++i) {\n    j = order[i];\n    if (top < bottom) {\n      top += sums[j];\n      tops.push(j);\n    } else {\n      bottom += sums[j];\n      bottoms.push(j);\n    }\n  }\n\n  return bottoms.reverse().concat(tops);\n}\n\nfunction reverse(series) {\n  return none$1(series).reverse();\n}\n\nexports.arc = arc;\nexports.area = area;\nexports.line = line;\nexports.pie = pie;\nexports.areaRadial = areaRadial;\nexports.radialArea = areaRadial;\nexports.lineRadial = lineRadial$1;\nexports.radialLine = lineRadial$1;\nexports.pointRadial = pointRadial;\nexports.linkHorizontal = linkHorizontal;\nexports.linkVertical = linkVertical;\nexports.linkRadial = linkRadial;\nexports.symbol = symbol;\nexports.symbols = symbols;\nexports.symbolCircle = circle;\nexports.symbolCross = cross;\nexports.symbolDiamond = diamond;\nexports.symbolSquare = square;\nexports.symbolStar = star;\nexports.symbolTriangle = triangle;\nexports.symbolWye = wye;\nexports.curveBasisClosed = basisClosed;\nexports.curveBasisOpen = basisOpen;\nexports.curveBasis = basis;\nexports.curveBundle = bundle;\nexports.curveCardinalClosed = cardinalClosed;\nexports.curveCardinalOpen = cardinalOpen;\nexports.curveCardinal = cardinal;\nexports.curveCatmullRomClosed = catmullRomClosed;\nexports.curveCatmullRomOpen = catmullRomOpen;\nexports.curveCatmullRom = catmullRom;\nexports.curveLinearClosed = linearClosed;\nexports.curveLinear = curveLinear;\nexports.curveMonotoneX = monotoneX;\nexports.curveMonotoneY = monotoneY;\nexports.curveNatural = natural;\nexports.curveStep = step;\nexports.curveStepAfter = stepAfter;\nexports.curveStepBefore = stepBefore;\nexports.stack = stack;\nexports.stackOffsetExpand = expand;\nexports.stackOffsetDiverging = diverging;\nexports.stackOffsetNone = none;\nexports.stackOffsetSilhouette = silhouette;\nexports.stackOffsetWiggle = wiggle;\nexports.stackOrderAppearance = appearance;\nexports.stackOrderAscending = ascending;\nexports.stackOrderDescending = descending$1;\nexports.stackOrderInsideOut = insideOut;\nexports.stackOrderNone = none$1;\nexports.stackOrderReverse = reverse;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{\"d3-path\":159}],162:[function(_dereq_,module,exports){\n// https://d3js.org/d3-timer/ Version 1.0.7. Copyright 2017 Mike Bostock.\n(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n\ttypeof define === 'function' && define.amd ? define(['exports'], factory) :\n\t(factory((global.d3 = global.d3 || {})));\n}(this, (function (exports) { 'use strict';\n\nvar frame = 0;\nvar timeout = 0;\nvar interval = 0;\nvar pokeDelay = 1000;\nvar taskHead;\nvar taskTail;\nvar clockLast = 0;\nvar clockNow = 0;\nvar clockSkew = 0;\nvar clock = typeof performance === \"object\" && performance.now ? performance : Date;\nvar setFrame = typeof window === \"object\" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };\n\nfunction now() {\n  return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);\n}\n\nfunction clearNow() {\n  clockNow = 0;\n}\n\nfunction Timer() {\n  this._call =\n  this._time =\n  this._next = null;\n}\n\nTimer.prototype = timer.prototype = {\n  constructor: Timer,\n  restart: function(callback, delay, time) {\n    if (typeof callback !== \"function\") throw new TypeError(\"callback is not a function\");\n    time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);\n    if (!this._next && taskTail !== this) {\n      if (taskTail) taskTail._next = this;\n      else taskHead = this;\n      taskTail = this;\n    }\n    this._call = callback;\n    this._time = time;\n    sleep();\n  },\n  stop: function() {\n    if (this._call) {\n      this._call = null;\n      this._time = Infinity;\n      sleep();\n    }\n  }\n};\n\nfunction timer(callback, delay, time) {\n  var t = new Timer;\n  t.restart(callback, delay, time);\n  return t;\n}\n\nfunction timerFlush() {\n  now(); // Get the current time, if not already set.\n  ++frame; // Pretend we’ve set an alarm, if we haven’t already.\n  var t = taskHead, e;\n  while (t) {\n    if ((e = clockNow - t._time) >= 0) t._call.call(null, e);\n    t = t._next;\n  }\n  --frame;\n}\n\nfunction wake() {\n  clockNow = (clockLast = clock.now()) + clockSkew;\n  frame = timeout = 0;\n  try {\n    timerFlush();\n  } finally {\n    frame = 0;\n    nap();\n    clockNow = 0;\n  }\n}\n\nfunction poke() {\n  var now = clock.now(), delay = now - clockLast;\n  if (delay > pokeDelay) clockSkew -= delay, clockLast = now;\n}\n\nfunction nap() {\n  var t0, t1 = taskHead, t2, time = Infinity;\n  while (t1) {\n    if (t1._call) {\n      if (time > t1._time) time = t1._time;\n      t0 = t1, t1 = t1._next;\n    } else {\n      t2 = t1._next, t1._next = null;\n      t1 = t0 ? t0._next = t2 : taskHead = t2;\n    }\n  }\n  taskTail = t0;\n  sleep(time);\n}\n\nfunction sleep(time) {\n  if (frame) return; // Soonest alarm already set, or will be.\n  if (timeout) timeout = clearTimeout(timeout);\n  var delay = time - clockNow; // Strictly less than if we recomputed clockNow.\n  if (delay > 24) {\n    if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);\n    if (interval) interval = clearInterval(interval);\n  } else {\n    if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);\n    frame = 1, setFrame(wake);\n  }\n}\n\nvar timeout$1 = function(callback, delay, time) {\n  var t = new Timer;\n  delay = delay == null ? 0 : +delay;\n  t.restart(function(elapsed) {\n    t.stop();\n    callback(elapsed + delay);\n  }, delay, time);\n  return t;\n};\n\nvar interval$1 = function(callback, delay, time) {\n  var t = new Timer, total = delay;\n  if (delay == null) return t.restart(callback, delay, time), t;\n  delay = +delay, time = time == null ? now() : +time;\n  t.restart(function tick(elapsed) {\n    elapsed += total;\n    t.restart(tick, total += delay, time);\n    callback(elapsed);\n  }, delay, time);\n  return t;\n};\n\nexports.now = now;\nexports.timer = timer;\nexports.timerFlush = timerFlush;\nexports.timeout = timeout$1;\nexports.interval = interval$1;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],163:[function(_dereq_,module,exports){\n!function() {\n  var d3 = {\n    version: \"3.5.17\"\n  };\n  var d3_arraySlice = [].slice, d3_array = function(list) {\n    return d3_arraySlice.call(list);\n  };\n  var d3_document = this.document;\n  function d3_documentElement(node) {\n    return node && (node.ownerDocument || node.document || node).documentElement;\n  }\n  function d3_window(node) {\n    return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);\n  }\n  if (d3_document) {\n    try {\n      d3_array(d3_document.documentElement.childNodes)[0].nodeType;\n    } catch (e) {\n      d3_array = function(list) {\n        var i = list.length, array = new Array(i);\n        while (i--) array[i] = list[i];\n        return array;\n      };\n    }\n  }\n  if (!Date.now) Date.now = function() {\n    return +new Date();\n  };\n  if (d3_document) {\n    try {\n      d3_document.createElement(\"DIV\").style.setProperty(\"opacity\", 0, \"\");\n    } catch (error) {\n      var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;\n      d3_element_prototype.setAttribute = function(name, value) {\n        d3_element_setAttribute.call(this, name, value + \"\");\n      };\n      d3_element_prototype.setAttributeNS = function(space, local, value) {\n        d3_element_setAttributeNS.call(this, space, local, value + \"\");\n      };\n      d3_style_prototype.setProperty = function(name, value, priority) {\n        d3_style_setProperty.call(this, name, value + \"\", priority);\n      };\n    }\n  }\n  d3.ascending = d3_ascending;\n  function d3_ascending(a, b) {\n    return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;\n  }\n  d3.descending = function(a, b) {\n    return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;\n  };\n  d3.min = function(array, f) {\n    var i = -1, n = array.length, a, b;\n    if (arguments.length === 1) {\n      while (++i < n) if ((b = array[i]) != null && b >= b) {\n        a = b;\n        break;\n      }\n      while (++i < n) if ((b = array[i]) != null && a > b) a = b;\n    } else {\n      while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {\n        a = b;\n        break;\n      }\n      while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;\n    }\n    return a;\n  };\n  d3.max = function(array, f) {\n    var i = -1, n = array.length, a, b;\n    if (arguments.length === 1) {\n      while (++i < n) if ((b = array[i]) != null && b >= b) {\n        a = b;\n        break;\n      }\n      while (++i < n) if ((b = array[i]) != null && b > a) a = b;\n    } else {\n      while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {\n        a = b;\n        break;\n      }\n      while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;\n    }\n    return a;\n  };\n  d3.extent = function(array, f) {\n    var i = -1, n = array.length, a, b, c;\n    if (arguments.length === 1) {\n      while (++i < n) if ((b = array[i]) != null && b >= b) {\n        a = c = b;\n        break;\n      }\n      while (++i < n) if ((b = array[i]) != null) {\n        if (a > b) a = b;\n        if (c < b) c = b;\n      }\n    } else {\n      while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {\n        a = c = b;\n        break;\n      }\n      while (++i < n) if ((b = f.call(array, array[i], i)) != null) {\n        if (a > b) a = b;\n        if (c < b) c = b;\n      }\n    }\n    return [ a, c ];\n  };\n  function d3_number(x) {\n    return x === null ? NaN : +x;\n  }\n  function d3_numeric(x) {\n    return !isNaN(x);\n  }\n  d3.sum = function(array, f) {\n    var s = 0, n = array.length, a, i = -1;\n    if (arguments.length === 1) {\n      while (++i < n) if (d3_numeric(a = +array[i])) s += a;\n    } else {\n      while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;\n    }\n    return s;\n  };\n  d3.mean = function(array, f) {\n    var s = 0, n = array.length, a, i = -1, j = n;\n    if (arguments.length === 1) {\n      while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;\n    } else {\n      while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;\n    }\n    if (j) return s / j;\n  };\n  d3.quantile = function(values, p) {\n    var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;\n    return e ? v + e * (values[h] - v) : v;\n  };\n  d3.median = function(array, f) {\n    var numbers = [], n = array.length, a, i = -1;\n    if (arguments.length === 1) {\n      while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);\n    } else {\n      while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);\n    }\n    if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);\n  };\n  d3.variance = function(array, f) {\n    var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;\n    if (arguments.length === 1) {\n      while (++i < n) {\n        if (d3_numeric(a = d3_number(array[i]))) {\n          d = a - m;\n          m += d / ++j;\n          s += d * (a - m);\n        }\n      }\n    } else {\n      while (++i < n) {\n        if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {\n          d = a - m;\n          m += d / ++j;\n          s += d * (a - m);\n        }\n      }\n    }\n    if (j > 1) return s / (j - 1);\n  };\n  d3.deviation = function() {\n    var v = d3.variance.apply(this, arguments);\n    return v ? Math.sqrt(v) : v;\n  };\n  function d3_bisector(compare) {\n    return {\n      left: function(a, x, lo, hi) {\n        if (arguments.length < 3) lo = 0;\n        if (arguments.length < 4) hi = a.length;\n        while (lo < hi) {\n          var mid = lo + hi >>> 1;\n          if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;\n        }\n        return lo;\n      },\n      right: function(a, x, lo, hi) {\n        if (arguments.length < 3) lo = 0;\n        if (arguments.length < 4) hi = a.length;\n        while (lo < hi) {\n          var mid = lo + hi >>> 1;\n          if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;\n        }\n        return lo;\n      }\n    };\n  }\n  var d3_bisect = d3_bisector(d3_ascending);\n  d3.bisectLeft = d3_bisect.left;\n  d3.bisect = d3.bisectRight = d3_bisect.right;\n  d3.bisector = function(f) {\n    return d3_bisector(f.length === 1 ? function(d, x) {\n      return d3_ascending(f(d), x);\n    } : f);\n  };\n  d3.shuffle = function(array, i0, i1) {\n    if ((m = arguments.length) < 3) {\n      i1 = array.length;\n      if (m < 2) i0 = 0;\n    }\n    var m = i1 - i0, t, i;\n    while (m) {\n      i = Math.random() * m-- | 0;\n      t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;\n    }\n    return array;\n  };\n  d3.permute = function(array, indexes) {\n    var i = indexes.length, permutes = new Array(i);\n    while (i--) permutes[i] = array[indexes[i]];\n    return permutes;\n  };\n  d3.pairs = function(array) {\n    var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);\n    while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];\n    return pairs;\n  };\n  d3.transpose = function(matrix) {\n    if (!(n = matrix.length)) return [];\n    for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {\n      for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {\n        row[j] = matrix[j][i];\n      }\n    }\n    return transpose;\n  };\n  function d3_transposeLength(d) {\n    return d.length;\n  }\n  d3.zip = function() {\n    return d3.transpose(arguments);\n  };\n  d3.keys = function(map) {\n    var keys = [];\n    for (var key in map) keys.push(key);\n    return keys;\n  };\n  d3.values = function(map) {\n    var values = [];\n    for (var key in map) values.push(map[key]);\n    return values;\n  };\n  d3.entries = function(map) {\n    var entries = [];\n    for (var key in map) entries.push({\n      key: key,\n      value: map[key]\n    });\n    return entries;\n  };\n  d3.merge = function(arrays) {\n    var n = arrays.length, m, i = -1, j = 0, merged, array;\n    while (++i < n) j += arrays[i].length;\n    merged = new Array(j);\n    while (--n >= 0) {\n      array = arrays[n];\n      m = array.length;\n      while (--m >= 0) {\n        merged[--j] = array[m];\n      }\n    }\n    return merged;\n  };\n  var abs = Math.abs;\n  d3.range = function(start, stop, step) {\n    if (arguments.length < 3) {\n      step = 1;\n      if (arguments.length < 2) {\n        stop = start;\n        start = 0;\n      }\n    }\n    if ((stop - start) / step === Infinity) throw new Error(\"infinite range\");\n    var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;\n    start *= k, stop *= k, step *= k;\n    if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);\n    return range;\n  };\n  function d3_range_integerScale(x) {\n    var k = 1;\n    while (x * k % 1) k *= 10;\n    return k;\n  }\n  function d3_class(ctor, properties) {\n    for (var key in properties) {\n      Object.defineProperty(ctor.prototype, key, {\n        value: properties[key],\n        enumerable: false\n      });\n    }\n  }\n  d3.map = function(object, f) {\n    var map = new d3_Map();\n    if (object instanceof d3_Map) {\n      object.forEach(function(key, value) {\n        map.set(key, value);\n      });\n    } else if (Array.isArray(object)) {\n      var i = -1, n = object.length, o;\n      if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);\n    } else {\n      for (var key in object) map.set(key, object[key]);\n    }\n    return map;\n  };\n  function d3_Map() {\n    this._ = Object.create(null);\n  }\n  var d3_map_proto = \"__proto__\", d3_map_zero = \"\\x00\";\n  d3_class(d3_Map, {\n    has: d3_map_has,\n    get: function(key) {\n      return this._[d3_map_escape(key)];\n    },\n    set: function(key, value) {\n      return this._[d3_map_escape(key)] = value;\n    },\n    remove: d3_map_remove,\n    keys: d3_map_keys,\n    values: function() {\n      var values = [];\n      for (var key in this._) values.push(this._[key]);\n      return values;\n    },\n    entries: function() {\n      var entries = [];\n      for (var key in this._) entries.push({\n        key: d3_map_unescape(key),\n        value: this._[key]\n      });\n      return entries;\n    },\n    size: d3_map_size,\n    empty: d3_map_empty,\n    forEach: function(f) {\n      for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);\n    }\n  });\n  function d3_map_escape(key) {\n    return (key += \"\") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;\n  }\n  function d3_map_unescape(key) {\n    return (key += \"\")[0] === d3_map_zero ? key.slice(1) : key;\n  }\n  function d3_map_has(key) {\n    return d3_map_escape(key) in this._;\n  }\n  function d3_map_remove(key) {\n    return (key = d3_map_escape(key)) in this._ && delete this._[key];\n  }\n  function d3_map_keys() {\n    var keys = [];\n    for (var key in this._) keys.push(d3_map_unescape(key));\n    return keys;\n  }\n  function d3_map_size() {\n    var size = 0;\n    for (var key in this._) ++size;\n    return size;\n  }\n  function d3_map_empty() {\n    for (var key in this._) return false;\n    return true;\n  }\n  d3.nest = function() {\n    var nest = {}, keys = [], sortKeys = [], sortValues, rollup;\n    function map(mapType, array, depth) {\n      if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;\n      var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;\n      while (++i < n) {\n        if (values = valuesByKey.get(keyValue = key(object = array[i]))) {\n          values.push(object);\n        } else {\n          valuesByKey.set(keyValue, [ object ]);\n        }\n      }\n      if (mapType) {\n        object = mapType();\n        setter = function(keyValue, values) {\n          object.set(keyValue, map(mapType, values, depth));\n        };\n      } else {\n        object = {};\n        setter = function(keyValue, values) {\n          object[keyValue] = map(mapType, values, depth);\n        };\n      }\n      valuesByKey.forEach(setter);\n      return object;\n    }\n    function entries(map, depth) {\n      if (depth >= keys.length) return map;\n      var array = [], sortKey = sortKeys[depth++];\n      map.forEach(function(key, keyMap) {\n        array.push({\n          key: key,\n          values: entries(keyMap, depth)\n        });\n      });\n      return sortKey ? array.sort(function(a, b) {\n        return sortKey(a.key, b.key);\n      }) : array;\n    }\n    nest.map = function(array, mapType) {\n      return map(mapType, array, 0);\n    };\n    nest.entries = function(array) {\n      return entries(map(d3.map, array, 0), 0);\n    };\n    nest.key = function(d) {\n      keys.push(d);\n      return nest;\n    };\n    nest.sortKeys = function(order) {\n      sortKeys[keys.length - 1] = order;\n      return nest;\n    };\n    nest.sortValues = function(order) {\n      sortValues = order;\n      return nest;\n    };\n    nest.rollup = function(f) {\n      rollup = f;\n      return nest;\n    };\n    return nest;\n  };\n  d3.set = function(array) {\n    var set = new d3_Set();\n    if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);\n    return set;\n  };\n  function d3_Set() {\n    this._ = Object.create(null);\n  }\n  d3_class(d3_Set, {\n    has: d3_map_has,\n    add: function(key) {\n      this._[d3_map_escape(key += \"\")] = true;\n      return key;\n    },\n    remove: d3_map_remove,\n    values: d3_map_keys,\n    size: d3_map_size,\n    empty: d3_map_empty,\n    forEach: function(f) {\n      for (var key in this._) f.call(this, d3_map_unescape(key));\n    }\n  });\n  d3.behavior = {};\n  function d3_identity(d) {\n    return d;\n  }\n  d3.rebind = function(target, source) {\n    var i = 1, n = arguments.length, method;\n    while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);\n    return target;\n  };\n  function d3_rebind(target, source, method) {\n    return function() {\n      var value = method.apply(source, arguments);\n      return value === source ? target : value;\n    };\n  }\n  function d3_vendorSymbol(object, name) {\n    if (name in object) return name;\n    name = name.charAt(0).toUpperCase() + name.slice(1);\n    for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {\n      var prefixName = d3_vendorPrefixes[i] + name;\n      if (prefixName in object) return prefixName;\n    }\n  }\n  var d3_vendorPrefixes = [ \"webkit\", \"ms\", \"moz\", \"Moz\", \"o\", \"O\" ];\n  function d3_noop() {}\n  d3.dispatch = function() {\n    var dispatch = new d3_dispatch(), i = -1, n = arguments.length;\n    while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);\n    return dispatch;\n  };\n  function d3_dispatch() {}\n  d3_dispatch.prototype.on = function(type, listener) {\n    var i = type.indexOf(\".\"), name = \"\";\n    if (i >= 0) {\n      name = type.slice(i + 1);\n      type = type.slice(0, i);\n    }\n    if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);\n    if (arguments.length === 2) {\n      if (listener == null) for (type in this) {\n        if (this.hasOwnProperty(type)) this[type].on(name, null);\n      }\n      return this;\n    }\n  };\n  function d3_dispatch_event(dispatch) {\n    var listeners = [], listenerByName = new d3_Map();\n    function event() {\n      var z = listeners, i = -1, n = z.length, l;\n      while (++i < n) if (l = z[i].on) l.apply(this, arguments);\n      return dispatch;\n    }\n    event.on = function(name, listener) {\n      var l = listenerByName.get(name), i;\n      if (arguments.length < 2) return l && l.on;\n      if (l) {\n        l.on = null;\n        listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));\n        listenerByName.remove(name);\n      }\n      if (listener) listeners.push(listenerByName.set(name, {\n        on: listener\n      }));\n      return dispatch;\n    };\n    return event;\n  }\n  d3.event = null;\n  function d3_eventPreventDefault() {\n    d3.event.preventDefault();\n  }\n  function d3_eventSource() {\n    var e = d3.event, s;\n    while (s = e.sourceEvent) e = s;\n    return e;\n  }\n  function d3_eventDispatch(target) {\n    var dispatch = new d3_dispatch(), i = 0, n = arguments.length;\n    while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);\n    dispatch.of = function(thiz, argumentz) {\n      return function(e1) {\n        try {\n          var e0 = e1.sourceEvent = d3.event;\n          e1.target = target;\n          d3.event = e1;\n          dispatch[e1.type].apply(thiz, argumentz);\n        } finally {\n          d3.event = e0;\n        }\n      };\n    };\n    return dispatch;\n  }\n  d3.requote = function(s) {\n    return s.replace(d3_requote_re, \"\\\\$&\");\n  };\n  var d3_requote_re = /[\\\\\\^\\$\\*\\+\\?\\|\\[\\]\\(\\)\\.\\{\\}]/g;\n  var d3_subclass = {}.__proto__ ? function(object, prototype) {\n    object.__proto__ = prototype;\n  } : function(object, prototype) {\n    for (var property in prototype) object[property] = prototype[property];\n  };\n  function d3_selection(groups) {\n    d3_subclass(groups, d3_selectionPrototype);\n    return groups;\n  }\n  var d3_select = function(s, n) {\n    return n.querySelector(s);\n  }, d3_selectAll = function(s, n) {\n    return n.querySelectorAll(s);\n  }, d3_selectMatches = function(n, s) {\n    var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, \"matchesSelector\")];\n    d3_selectMatches = function(n, s) {\n      return d3_selectMatcher.call(n, s);\n    };\n    return d3_selectMatches(n, s);\n  };\n  if (typeof Sizzle === \"function\") {\n    d3_select = function(s, n) {\n      return Sizzle(s, n)[0] || null;\n    };\n    d3_selectAll = Sizzle;\n    d3_selectMatches = Sizzle.matchesSelector;\n  }\n  d3.selection = function() {\n    return d3.select(d3_document.documentElement);\n  };\n  var d3_selectionPrototype = d3.selection.prototype = [];\n  d3_selectionPrototype.select = function(selector) {\n    var subgroups = [], subgroup, subnode, group, node;\n    selector = d3_selection_selector(selector);\n    for (var j = -1, m = this.length; ++j < m; ) {\n      subgroups.push(subgroup = []);\n      subgroup.parentNode = (group = this[j]).parentNode;\n      for (var i = -1, n = group.length; ++i < n; ) {\n        if (node = group[i]) {\n          subgroup.push(subnode = selector.call(node, node.__data__, i, j));\n          if (subnode && \"__data__\" in node) subnode.__data__ = node.__data__;\n        } else {\n          subgroup.push(null);\n        }\n      }\n    }\n    return d3_selection(subgroups);\n  };\n  function d3_selection_selector(selector) {\n    return typeof selector === \"function\" ? selector : function() {\n      return d3_select(selector, this);\n    };\n  }\n  d3_selectionPrototype.selectAll = function(selector) {\n    var subgroups = [], subgroup, node;\n    selector = d3_selection_selectorAll(selector);\n    for (var j = -1, m = this.length; ++j < m; ) {\n      for (var group = this[j], i = -1, n = group.length; ++i < n; ) {\n        if (node = group[i]) {\n          subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));\n          subgroup.parentNode = node;\n        }\n      }\n    }\n    return d3_selection(subgroups);\n  };\n  function d3_selection_selectorAll(selector) {\n    return typeof selector === \"function\" ? selector : function() {\n      return d3_selectAll(selector, this);\n    };\n  }\n  var d3_nsXhtml = \"http://www.w3.org/1999/xhtml\";\n  var d3_nsPrefix = {\n    svg: \"http://www.w3.org/2000/svg\",\n    xhtml: d3_nsXhtml,\n    xlink: \"http://www.w3.org/1999/xlink\",\n    xml: \"http://www.w3.org/XML/1998/namespace\",\n    xmlns: \"http://www.w3.org/2000/xmlns/\"\n  };\n  d3.ns = {\n    prefix: d3_nsPrefix,\n    qualify: function(name) {\n      var i = name.indexOf(\":\"), prefix = name;\n      if (i >= 0 && (prefix = name.slice(0, i)) !== \"xmlns\") name = name.slice(i + 1);\n      return d3_nsPrefix.hasOwnProperty(prefix) ? {\n        space: d3_nsPrefix[prefix],\n        local: name\n      } : name;\n    }\n  };\n  d3_selectionPrototype.attr = function(name, value) {\n    if (arguments.length < 2) {\n      if (typeof name === \"string\") {\n        var node = this.node();\n        name = d3.ns.qualify(name);\n        return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);\n      }\n      for (value in name) this.each(d3_selection_attr(value, name[value]));\n      return this;\n    }\n    return this.each(d3_selection_attr(name, value));\n  };\n  function d3_selection_attr(name, value) {\n    name = d3.ns.qualify(name);\n    function attrNull() {\n      this.removeAttribute(name);\n    }\n    function attrNullNS() {\n      this.removeAttributeNS(name.space, name.local);\n    }\n    function attrConstant() {\n      this.setAttribute(name, value);\n    }\n    function attrConstantNS() {\n      this.setAttributeNS(name.space, name.local, value);\n    }\n    function attrFunction() {\n      var x = value.apply(this, arguments);\n      if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);\n    }\n    function attrFunctionNS() {\n      var x = value.apply(this, arguments);\n      if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);\n    }\n    return value == null ? name.local ? attrNullNS : attrNull : typeof value === \"function\" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;\n  }\n  function d3_collapse(s) {\n    return s.trim().replace(/\\s+/g, \" \");\n  }\n  d3_selectionPrototype.classed = function(name, value) {\n    if (arguments.length < 2) {\n      if (typeof name === \"string\") {\n        var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;\n        if (value = node.classList) {\n          while (++i < n) if (!value.contains(name[i])) return false;\n        } else {\n          value = node.getAttribute(\"class\");\n          while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;\n        }\n        return true;\n      }\n      for (value in name) this.each(d3_selection_classed(value, name[value]));\n      return this;\n    }\n    return this.each(d3_selection_classed(name, value));\n  };\n  function d3_selection_classedRe(name) {\n    return new RegExp(\"(?:^|\\\\s+)\" + d3.requote(name) + \"(?:\\\\s+|$)\", \"g\");\n  }\n  function d3_selection_classes(name) {\n    return (name + \"\").trim().split(/^|\\s+/);\n  }\n  function d3_selection_classed(name, value) {\n    name = d3_selection_classes(name).map(d3_selection_classedName);\n    var n = name.length;\n    function classedConstant() {\n      var i = -1;\n      while (++i < n) name[i](this, value);\n    }\n    function classedFunction() {\n      var i = -1, x = value.apply(this, arguments);\n      while (++i < n) name[i](this, x);\n    }\n    return typeof value === \"function\" ? classedFunction : classedConstant;\n  }\n  function d3_selection_classedName(name) {\n    var re = d3_selection_classedRe(name);\n    return function(node, value) {\n      if (c = node.classList) return value ? c.add(name) : c.remove(name);\n      var c = node.getAttribute(\"class\") || \"\";\n      if (value) {\n        re.lastIndex = 0;\n        if (!re.test(c)) node.setAttribute(\"class\", d3_collapse(c + \" \" + name));\n      } else {\n        node.setAttribute(\"class\", d3_collapse(c.replace(re, \" \")));\n      }\n    };\n  }\n  d3_selectionPrototype.style = function(name, value, priority) {\n    var n = arguments.length;\n    if (n < 3) {\n      if (typeof name !== \"string\") {\n        if (n < 2) value = \"\";\n        for (priority in name) this.each(d3_selection_style(priority, name[priority], value));\n        return this;\n      }\n      if (n < 2) {\n        var node = this.node();\n        return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);\n      }\n      priority = \"\";\n    }\n    return this.each(d3_selection_style(name, value, priority));\n  };\n  function d3_selection_style(name, value, priority) {\n    function styleNull() {\n      this.style.removeProperty(name);\n    }\n    function styleConstant() {\n      this.style.setProperty(name, value, priority);\n    }\n    function styleFunction() {\n      var x = value.apply(this, arguments);\n      if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);\n    }\n    return value == null ? styleNull : typeof value === \"function\" ? styleFunction : styleConstant;\n  }\n  d3_selectionPrototype.property = function(name, value) {\n    if (arguments.length < 2) {\n      if (typeof name === \"string\") return this.node()[name];\n      for (value in name) this.each(d3_selection_property(value, name[value]));\n      return this;\n    }\n    return this.each(d3_selection_property(name, value));\n  };\n  function d3_selection_property(name, value) {\n    function propertyNull() {\n      delete this[name];\n    }\n    function propertyConstant() {\n      this[name] = value;\n    }\n    function propertyFunction() {\n      var x = value.apply(this, arguments);\n      if (x == null) delete this[name]; else this[name] = x;\n    }\n    return value == null ? propertyNull : typeof value === \"function\" ? propertyFunction : propertyConstant;\n  }\n  d3_selectionPrototype.text = function(value) {\n    return arguments.length ? this.each(typeof value === \"function\" ? function() {\n      var v = value.apply(this, arguments);\n      this.textContent = v == null ? \"\" : v;\n    } : value == null ? function() {\n      this.textContent = \"\";\n    } : function() {\n      this.textContent = value;\n    }) : this.node().textContent;\n  };\n  d3_selectionPrototype.html = function(value) {\n    return arguments.length ? this.each(typeof value === \"function\" ? function() {\n      var v = value.apply(this, arguments);\n      this.innerHTML = v == null ? \"\" : v;\n    } : value == null ? function() {\n      this.innerHTML = \"\";\n    } : function() {\n      this.innerHTML = value;\n    }) : this.node().innerHTML;\n  };\n  d3_selectionPrototype.append = function(name) {\n    name = d3_selection_creator(name);\n    return this.select(function() {\n      return this.appendChild(name.apply(this, arguments));\n    });\n  };\n  function d3_selection_creator(name) {\n    function create() {\n      var document = this.ownerDocument, namespace = this.namespaceURI;\n      return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);\n    }\n    function createNS() {\n      return this.ownerDocument.createElementNS(name.space, name.local);\n    }\n    return typeof name === \"function\" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;\n  }\n  d3_selectionPrototype.insert = function(name, before) {\n    name = d3_selection_creator(name);\n    before = d3_selection_selector(before);\n    return this.select(function() {\n      return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);\n    });\n  };\n  d3_selectionPrototype.remove = function() {\n    return this.each(d3_selectionRemove);\n  };\n  function d3_selectionRemove() {\n    var parent = this.parentNode;\n    if (parent) parent.removeChild(this);\n  }\n  d3_selectionPrototype.data = function(value, key) {\n    var i = -1, n = this.length, group, node;\n    if (!arguments.length) {\n      value = new Array(n = (group = this[0]).length);\n      while (++i < n) {\n        if (node = group[i]) {\n          value[i] = node.__data__;\n        }\n      }\n      return value;\n    }\n    function bind(group, groupData) {\n      var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), updateNodes = new Array(m), enterNodes = new Array(m), exitNodes = new Array(n), node, nodeData;\n      if (key) {\n        var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;\n        for (i = -1; ++i < n; ) {\n          if (node = group[i]) {\n            if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {\n              exitNodes[i] = node;\n            } else {\n              nodeByKeyValue.set(keyValue, node);\n            }\n            keyValues[i] = keyValue;\n          }\n        }\n        for (i = -1; ++i < m; ) {\n          if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {\n            enterNodes[i] = d3_selection_dataNode(nodeData);\n          } else if (node !== true) {\n            updateNodes[i] = node;\n            node.__data__ = nodeData;\n          }\n          nodeByKeyValue.set(keyValue, true);\n        }\n        for (i = -1; ++i < n; ) {\n          if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {\n            exitNodes[i] = group[i];\n          }\n        }\n      } else {\n        for (i = -1; ++i < n0; ) {\n          node = group[i];\n          nodeData = groupData[i];\n          if (node) {\n            node.__data__ = nodeData;\n            updateNodes[i] = node;\n          } else {\n            enterNodes[i] = d3_selection_dataNode(nodeData);\n          }\n        }\n        for (;i < m; ++i) {\n          enterNodes[i] = d3_selection_dataNode(groupData[i]);\n        }\n        for (;i < n; ++i) {\n          exitNodes[i] = group[i];\n        }\n      }\n      enterNodes.update = updateNodes;\n      enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;\n      enter.push(enterNodes);\n      update.push(updateNodes);\n      exit.push(exitNodes);\n    }\n    var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);\n    if (typeof value === \"function\") {\n      while (++i < n) {\n        bind(group = this[i], value.call(group, group.parentNode.__data__, i));\n      }\n    } else {\n      while (++i < n) {\n        bind(group = this[i], value);\n      }\n    }\n    update.enter = function() {\n      return enter;\n    };\n    update.exit = function() {\n      return exit;\n    };\n    return update;\n  };\n  function d3_selection_dataNode(data) {\n    return {\n      __data__: data\n    };\n  }\n  d3_selectionPrototype.datum = function(value) {\n    return arguments.length ? this.property(\"__data__\", value) : this.property(\"__data__\");\n  };\n  d3_selectionPrototype.filter = function(filter) {\n    var subgroups = [], subgroup, group, node;\n    if (typeof filter !== \"function\") filter = d3_selection_filter(filter);\n    for (var j = 0, m = this.length; j < m; j++) {\n      subgroups.push(subgroup = []);\n      subgroup.parentNode = (group = this[j]).parentNode;\n      for (var i = 0, n = group.length; i < n; i++) {\n        if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {\n          subgroup.push(node);\n        }\n      }\n    }\n    return d3_selection(subgroups);\n  };\n  function d3_selection_filter(selector) {\n    return function() {\n      return d3_selectMatches(this, selector);\n    };\n  }\n  d3_selectionPrototype.order = function() {\n    for (var j = -1, m = this.length; ++j < m; ) {\n      for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {\n        if (node = group[i]) {\n          if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);\n          next = node;\n        }\n      }\n    }\n    return this;\n  };\n  d3_selectionPrototype.sort = function(comparator) {\n    comparator = d3_selection_sortComparator.apply(this, arguments);\n    for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);\n    return this.order();\n  };\n  function d3_selection_sortComparator(comparator) {\n    if (!arguments.length) comparator = d3_ascending;\n    return function(a, b) {\n      return a && b ? comparator(a.__data__, b.__data__) : !a - !b;\n    };\n  }\n  d3_selectionPrototype.each = function(callback) {\n    return d3_selection_each(this, function(node, i, j) {\n      callback.call(node, node.__data__, i, j);\n    });\n  };\n  function d3_selection_each(groups, callback) {\n    for (var j = 0, m = groups.length; j < m; j++) {\n      for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {\n        if (node = group[i]) callback(node, i, j);\n      }\n    }\n    return groups;\n  }\n  d3_selectionPrototype.call = function(callback) {\n    var args = d3_array(arguments);\n    callback.apply(args[0] = this, args);\n    return this;\n  };\n  d3_selectionPrototype.empty = function() {\n    return !this.node();\n  };\n  d3_selectionPrototype.node = function() {\n    for (var j = 0, m = this.length; j < m; j++) {\n      for (var group = this[j], i = 0, n = group.length; i < n; i++) {\n        var node = group[i];\n        if (node) return node;\n      }\n    }\n    return null;\n  };\n  d3_selectionPrototype.size = function() {\n    var n = 0;\n    d3_selection_each(this, function() {\n      ++n;\n    });\n    return n;\n  };\n  function d3_selection_enter(selection) {\n    d3_subclass(selection, d3_selection_enterPrototype);\n    return selection;\n  }\n  var d3_selection_enterPrototype = [];\n  d3.selection.enter = d3_selection_enter;\n  d3.selection.enter.prototype = d3_selection_enterPrototype;\n  d3_selection_enterPrototype.append = d3_selectionPrototype.append;\n  d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;\n  d3_selection_enterPrototype.node = d3_selectionPrototype.node;\n  d3_selection_enterPrototype.call = d3_selectionPrototype.call;\n  d3_selection_enterPrototype.size = d3_selectionPrototype.size;\n  d3_selection_enterPrototype.select = function(selector) {\n    var subgroups = [], subgroup, subnode, upgroup, group, node;\n    for (var j = -1, m = this.length; ++j < m; ) {\n      upgroup = (group = this[j]).update;\n      subgroups.push(subgroup = []);\n      subgroup.parentNode = group.parentNode;\n      for (var i = -1, n = group.length; ++i < n; ) {\n        if (node = group[i]) {\n          subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));\n          subnode.__data__ = node.__data__;\n        } else {\n          subgroup.push(null);\n        }\n      }\n    }\n    return d3_selection(subgroups);\n  };\n  d3_selection_enterPrototype.insert = function(name, before) {\n    if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);\n    return d3_selectionPrototype.insert.call(this, name, before);\n  };\n  function d3_selection_enterInsertBefore(enter) {\n    var i0, j0;\n    return function(d, i, j) {\n      var group = enter[j].update, n = group.length, node;\n      if (j != j0) j0 = j, i0 = 0;\n      if (i >= i0) i0 = i + 1;\n      while (!(node = group[i0]) && ++i0 < n) ;\n      return node;\n    };\n  }\n  d3.select = function(node) {\n    var group;\n    if (typeof node === \"string\") {\n      group = [ d3_select(node, d3_document) ];\n      group.parentNode = d3_document.documentElement;\n    } else {\n      group = [ node ];\n      group.parentNode = d3_documentElement(node);\n    }\n    return d3_selection([ group ]);\n  };\n  d3.selectAll = function(nodes) {\n    var group;\n    if (typeof nodes === \"string\") {\n      group = d3_array(d3_selectAll(nodes, d3_document));\n      group.parentNode = d3_document.documentElement;\n    } else {\n      group = d3_array(nodes);\n      group.parentNode = null;\n    }\n    return d3_selection([ group ]);\n  };\n  d3_selectionPrototype.on = function(type, listener, capture) {\n    var n = arguments.length;\n    if (n < 3) {\n      if (typeof type !== \"string\") {\n        if (n < 2) listener = false;\n        for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));\n        return this;\n      }\n      if (n < 2) return (n = this.node()[\"__on\" + type]) && n._;\n      capture = false;\n    }\n    return this.each(d3_selection_on(type, listener, capture));\n  };\n  function d3_selection_on(type, listener, capture) {\n    var name = \"__on\" + type, i = type.indexOf(\".\"), wrap = d3_selection_onListener;\n    if (i > 0) type = type.slice(0, i);\n    var filter = d3_selection_onFilters.get(type);\n    if (filter) type = filter, wrap = d3_selection_onFilter;\n    function onRemove() {\n      var l = this[name];\n      if (l) {\n        this.removeEventListener(type, l, l.$);\n        delete this[name];\n      }\n    }\n    function onAdd() {\n      var l = wrap(listener, d3_array(arguments));\n      onRemove.call(this);\n      this.addEventListener(type, this[name] = l, l.$ = capture);\n      l._ = listener;\n    }\n    function removeAll() {\n      var re = new RegExp(\"^__on([^.]+)\" + d3.requote(type) + \"$\"), match;\n      for (var name in this) {\n        if (match = name.match(re)) {\n          var l = this[name];\n          this.removeEventListener(match[1], l, l.$);\n          delete this[name];\n        }\n      }\n    }\n    return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;\n  }\n  var d3_selection_onFilters = d3.map({\n    mouseenter: \"mouseover\",\n    mouseleave: \"mouseout\"\n  });\n  if (d3_document) {\n    d3_selection_onFilters.forEach(function(k) {\n      if (\"on\" + k in d3_document) d3_selection_onFilters.remove(k);\n    });\n  }\n  function d3_selection_onListener(listener, argumentz) {\n    return function(e) {\n      var o = d3.event;\n      d3.event = e;\n      argumentz[0] = this.__data__;\n      try {\n        listener.apply(this, argumentz);\n      } finally {\n        d3.event = o;\n      }\n    };\n  }\n  function d3_selection_onFilter(listener, argumentz) {\n    var l = d3_selection_onListener(listener, argumentz);\n    return function(e) {\n      var target = this, related = e.relatedTarget;\n      if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {\n        l.call(target, e);\n      }\n    };\n  }\n  var d3_event_dragSelect, d3_event_dragId = 0;\n  function d3_event_dragSuppress(node) {\n    var name = \".dragsuppress-\" + ++d3_event_dragId, click = \"click\" + name, w = d3.select(d3_window(node)).on(\"touchmove\" + name, d3_eventPreventDefault).on(\"dragstart\" + name, d3_eventPreventDefault).on(\"selectstart\" + name, d3_eventPreventDefault);\n    if (d3_event_dragSelect == null) {\n      d3_event_dragSelect = \"onselectstart\" in node ? false : d3_vendorSymbol(node.style, \"userSelect\");\n    }\n    if (d3_event_dragSelect) {\n      var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];\n      style[d3_event_dragSelect] = \"none\";\n    }\n    return function(suppressClick) {\n      w.on(name, null);\n      if (d3_event_dragSelect) style[d3_event_dragSelect] = select;\n      if (suppressClick) {\n        var off = function() {\n          w.on(click, null);\n        };\n        w.on(click, function() {\n          d3_eventPreventDefault();\n          off();\n        }, true);\n        setTimeout(off, 0);\n      }\n    };\n  }\n  d3.mouse = function(container) {\n    return d3_mousePoint(container, d3_eventSource());\n  };\n  var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;\n  function d3_mousePoint(container, e) {\n    if (e.changedTouches) e = e.changedTouches[0];\n    var svg = container.ownerSVGElement || container;\n    if (svg.createSVGPoint) {\n      var point = svg.createSVGPoint();\n      if (d3_mouse_bug44083 < 0) {\n        var window = d3_window(container);\n        if (window.scrollX || window.scrollY) {\n          svg = d3.select(\"body\").append(\"svg\").style({\n            position: \"absolute\",\n            top: 0,\n            left: 0,\n            margin: 0,\n            padding: 0,\n            border: \"none\"\n          }, \"important\");\n          var ctm = svg[0][0].getScreenCTM();\n          d3_mouse_bug44083 = !(ctm.f || ctm.e);\n          svg.remove();\n        }\n      }\n      if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX, \n      point.y = e.clientY;\n      point = point.matrixTransform(container.getScreenCTM().inverse());\n      return [ point.x, point.y ];\n    }\n    var rect = container.getBoundingClientRect();\n    return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];\n  }\n  d3.touch = function(container, touches, identifier) {\n    if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;\n    if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {\n      if ((touch = touches[i]).identifier === identifier) {\n        return d3_mousePoint(container, touch);\n      }\n    }\n  };\n  d3.behavior.drag = function() {\n    var event = d3_eventDispatch(drag, \"drag\", \"dragstart\", \"dragend\"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, \"mousemove\", \"mouseup\"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, \"touchmove\", \"touchend\");\n    function drag() {\n      this.on(\"mousedown.drag\", mousedown).on(\"touchstart.drag\", touchstart);\n    }\n    function dragstart(id, position, subject, move, end) {\n      return function() {\n        var that = this, target = d3.event.target.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = \".drag\" + (dragId == null ? \"\" : \"-\" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);\n        if (origin) {\n          dragOffset = origin.apply(that, arguments);\n          dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];\n        } else {\n          dragOffset = [ 0, 0 ];\n        }\n        dispatch({\n          type: \"dragstart\"\n        });\n        function moved() {\n          var position1 = position(parent, dragId), dx, dy;\n          if (!position1) return;\n          dx = position1[0] - position0[0];\n          dy = position1[1] - position0[1];\n          dragged |= dx | dy;\n          position0 = position1;\n          dispatch({\n            type: \"drag\",\n            x: position1[0] + dragOffset[0],\n            y: position1[1] + dragOffset[1],\n            dx: dx,\n            dy: dy\n          });\n        }\n        function ended() {\n          if (!position(parent, dragId)) return;\n          dragSubject.on(move + dragName, null).on(end + dragName, null);\n          dragRestore(dragged);\n          dispatch({\n            type: \"dragend\"\n          });\n        }\n      };\n    }\n    drag.origin = function(x) {\n      if (!arguments.length) return origin;\n      origin = x;\n      return drag;\n    };\n    return d3.rebind(drag, event, \"on\");\n  };\n  function d3_behavior_dragTouchId() {\n    return d3.event.changedTouches[0].identifier;\n  }\n  d3.touches = function(container, touches) {\n    if (arguments.length < 2) touches = d3_eventSource().touches;\n    return touches ? d3_array(touches).map(function(touch) {\n      var point = d3_mousePoint(container, touch);\n      point.identifier = touch.identifier;\n      return point;\n    }) : [];\n  };\n  var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;\n  function d3_sgn(x) {\n    return x > 0 ? 1 : x < 0 ? -1 : 0;\n  }\n  function d3_cross2d(a, b, c) {\n    return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);\n  }\n  function d3_acos(x) {\n    return x > 1 ? 0 : x < -1 ? π : Math.acos(x);\n  }\n  function d3_asin(x) {\n    return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);\n  }\n  function d3_sinh(x) {\n    return ((x = Math.exp(x)) - 1 / x) / 2;\n  }\n  function d3_cosh(x) {\n    return ((x = Math.exp(x)) + 1 / x) / 2;\n  }\n  function d3_tanh(x) {\n    return ((x = Math.exp(2 * x)) - 1) / (x + 1);\n  }\n  function d3_haversin(x) {\n    return (x = Math.sin(x / 2)) * x;\n  }\n  var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;\n  d3.interpolateZoom = function(p0, p1) {\n    var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;\n    if (d2 < ε2) {\n      S = Math.log(w1 / w0) / ρ;\n      i = function(t) {\n        return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];\n      };\n    } else {\n      var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n      S = (r1 - r0) / ρ;\n      i = function(t) {\n        var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));\n        return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];\n      };\n    }\n    i.duration = S * 1e3;\n    return i;\n  };\n  d3.behavior.zoom = function() {\n    var view = {\n      x: 0,\n      y: 0,\n      k: 1\n    }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = \"mousedown.zoom\", mousemove = \"mousemove.zoom\", mouseup = \"mouseup.zoom\", mousewheelTimer, touchstart = \"touchstart.zoom\", touchtime, event = d3_eventDispatch(zoom, \"zoomstart\", \"zoom\", \"zoomend\"), x0, x1, y0, y1;\n    if (!d3_behavior_zoomWheel) {\n      d3_behavior_zoomWheel = \"onwheel\" in d3_document ? (d3_behavior_zoomDelta = function() {\n        return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);\n      }, \"wheel\") : \"onmousewheel\" in d3_document ? (d3_behavior_zoomDelta = function() {\n        return d3.event.wheelDelta;\n      }, \"mousewheel\") : (d3_behavior_zoomDelta = function() {\n        return -d3.event.detail;\n      }, \"MozMousePixelScroll\");\n    }\n    function zoom(g) {\n      g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + \".zoom\", mousewheeled).on(\"dblclick.zoom\", dblclicked).on(touchstart, touchstarted);\n    }\n    zoom.event = function(g) {\n      g.each(function() {\n        var dispatch = event.of(this, arguments), view1 = view;\n        if (d3_transitionInheritId) {\n          d3.select(this).transition().each(\"start.zoom\", function() {\n            view = this.__chart__ || {\n              x: 0,\n              y: 0,\n              k: 1\n            };\n            zoomstarted(dispatch);\n          }).tween(\"zoom:zoom\", function() {\n            var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);\n            return function(t) {\n              var l = i(t), k = dx / l[2];\n              this.__chart__ = view = {\n                x: cx - l[0] * k,\n                y: cy - l[1] * k,\n                k: k\n              };\n              zoomed(dispatch);\n            };\n          }).each(\"interrupt.zoom\", function() {\n            zoomended(dispatch);\n          }).each(\"end.zoom\", function() {\n            zoomended(dispatch);\n          });\n        } else {\n          this.__chart__ = view;\n          zoomstarted(dispatch);\n          zoomed(dispatch);\n          zoomended(dispatch);\n        }\n      });\n    };\n    zoom.translate = function(_) {\n      if (!arguments.length) return [ view.x, view.y ];\n      view = {\n        x: +_[0],\n        y: +_[1],\n        k: view.k\n      };\n      rescale();\n      return zoom;\n    };\n    zoom.scale = function(_) {\n      if (!arguments.length) return view.k;\n      view = {\n        x: view.x,\n        y: view.y,\n        k: null\n      };\n      scaleTo(+_);\n      rescale();\n      return zoom;\n    };\n    zoom.scaleExtent = function(_) {\n      if (!arguments.length) return scaleExtent;\n      scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];\n      return zoom;\n    };\n    zoom.center = function(_) {\n      if (!arguments.length) return center;\n      center = _ && [ +_[0], +_[1] ];\n      return zoom;\n    };\n    zoom.size = function(_) {\n      if (!arguments.length) return size;\n      size = _ && [ +_[0], +_[1] ];\n      return zoom;\n    };\n    zoom.duration = function(_) {\n      if (!arguments.length) return duration;\n      duration = +_;\n      return zoom;\n    };\n    zoom.x = function(z) {\n      if (!arguments.length) return x1;\n      x1 = z;\n      x0 = z.copy();\n      view = {\n        x: 0,\n        y: 0,\n        k: 1\n      };\n      return zoom;\n    };\n    zoom.y = function(z) {\n      if (!arguments.length) return y1;\n      y1 = z;\n      y0 = z.copy();\n      view = {\n        x: 0,\n        y: 0,\n        k: 1\n      };\n      return zoom;\n    };\n    function location(p) {\n      return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];\n    }\n    function point(l) {\n      return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];\n    }\n    function scaleTo(s) {\n      view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));\n    }\n    function translateTo(p, l) {\n      l = point(l);\n      view.x += p[0] - l[0];\n      view.y += p[1] - l[1];\n    }\n    function zoomTo(that, p, l, k) {\n      that.__chart__ = {\n        x: view.x,\n        y: view.y,\n        k: view.k\n      };\n      scaleTo(Math.pow(2, k));\n      translateTo(center0 = p, l);\n      that = d3.select(that);\n      if (duration > 0) that = that.transition().duration(duration);\n      that.call(zoom.event);\n    }\n    function rescale() {\n      if (x1) x1.domain(x0.range().map(function(x) {\n        return (x - view.x) / view.k;\n      }).map(x0.invert));\n      if (y1) y1.domain(y0.range().map(function(y) {\n        return (y - view.y) / view.k;\n      }).map(y0.invert));\n    }\n    function zoomstarted(dispatch) {\n      if (!zooming++) dispatch({\n        type: \"zoomstart\"\n      });\n    }\n    function zoomed(dispatch) {\n      rescale();\n      dispatch({\n        type: \"zoom\",\n        scale: view.k,\n        translate: [ view.x, view.y ]\n      });\n    }\n    function zoomended(dispatch) {\n      if (!--zooming) dispatch({\n        type: \"zoomend\"\n      }), center0 = null;\n    }\n    function mousedowned() {\n      var that = this, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);\n      d3_selection_interrupt.call(that);\n      zoomstarted(dispatch);\n      function moved() {\n        dragged = 1;\n        translateTo(d3.mouse(that), location0);\n        zoomed(dispatch);\n      }\n      function ended() {\n        subject.on(mousemove, null).on(mouseup, null);\n        dragRestore(dragged);\n        zoomended(dispatch);\n      }\n    }\n    function touchstarted() {\n      var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = \".zoom-\" + d3.event.changedTouches[0].identifier, touchmove = \"touchmove\" + zoomName, touchend = \"touchend\" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);\n      started();\n      zoomstarted(dispatch);\n      subject.on(mousedown, null).on(touchstart, started);\n      function relocate() {\n        var touches = d3.touches(that);\n        scale0 = view.k;\n        touches.forEach(function(t) {\n          if (t.identifier in locations0) locations0[t.identifier] = location(t);\n        });\n        return touches;\n      }\n      function started() {\n        var target = d3.event.target;\n        d3.select(target).on(touchmove, moved).on(touchend, ended);\n        targets.push(target);\n        var changed = d3.event.changedTouches;\n        for (var i = 0, n = changed.length; i < n; ++i) {\n          locations0[changed[i].identifier] = null;\n        }\n        var touches = relocate(), now = Date.now();\n        if (touches.length === 1) {\n          if (now - touchtime < 500) {\n            var p = touches[0];\n            zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);\n            d3_eventPreventDefault();\n          }\n          touchtime = now;\n        } else if (touches.length > 1) {\n          var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];\n          distance0 = dx * dx + dy * dy;\n        }\n      }\n      function moved() {\n        var touches = d3.touches(that), p0, l0, p1, l1;\n        d3_selection_interrupt.call(that);\n        for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {\n          p1 = touches[i];\n          if (l1 = locations0[p1.identifier]) {\n            if (l0) break;\n            p0 = p1, l0 = l1;\n          }\n        }\n        if (l1) {\n          var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);\n          p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];\n          l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];\n          scaleTo(scale1 * scale0);\n        }\n        touchtime = null;\n        translateTo(p0, l0);\n        zoomed(dispatch);\n      }\n      function ended() {\n        if (d3.event.touches.length) {\n          var changed = d3.event.changedTouches;\n          for (var i = 0, n = changed.length; i < n; ++i) {\n            delete locations0[changed[i].identifier];\n          }\n          for (var identifier in locations0) {\n            return void relocate();\n          }\n        }\n        d3.selectAll(targets).on(zoomName, null);\n        subject.on(mousedown, mousedowned).on(touchstart, touchstarted);\n        dragRestore();\n        zoomended(dispatch);\n      }\n    }\n    function mousewheeled() {\n      var dispatch = event.of(this, arguments);\n      if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this), \n      translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);\n      mousewheelTimer = setTimeout(function() {\n        mousewheelTimer = null;\n        zoomended(dispatch);\n      }, 50);\n      d3_eventPreventDefault();\n      scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);\n      translateTo(center0, translate0);\n      zoomed(dispatch);\n    }\n    function dblclicked() {\n      var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;\n      zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);\n    }\n    return d3.rebind(zoom, event, \"on\");\n  };\n  var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;\n  d3.color = d3_color;\n  function d3_color() {}\n  d3_color.prototype.toString = function() {\n    return this.rgb() + \"\";\n  };\n  d3.hsl = d3_hsl;\n  function d3_hsl(h, s, l) {\n    return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse(\"\" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);\n  }\n  var d3_hslPrototype = d3_hsl.prototype = new d3_color();\n  d3_hslPrototype.brighter = function(k) {\n    k = Math.pow(.7, arguments.length ? k : 1);\n    return new d3_hsl(this.h, this.s, this.l / k);\n  };\n  d3_hslPrototype.darker = function(k) {\n    k = Math.pow(.7, arguments.length ? k : 1);\n    return new d3_hsl(this.h, this.s, k * this.l);\n  };\n  d3_hslPrototype.rgb = function() {\n    return d3_hsl_rgb(this.h, this.s, this.l);\n  };\n  function d3_hsl_rgb(h, s, l) {\n    var m1, m2;\n    h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;\n    s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;\n    l = l < 0 ? 0 : l > 1 ? 1 : l;\n    m2 = l <= .5 ? l * (1 + s) : l + s - l * s;\n    m1 = 2 * l - m2;\n    function v(h) {\n      if (h > 360) h -= 360; else if (h < 0) h += 360;\n      if (h < 60) return m1 + (m2 - m1) * h / 60;\n      if (h < 180) return m2;\n      if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;\n      return m1;\n    }\n    function vv(h) {\n      return Math.round(v(h) * 255);\n    }\n    return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));\n  }\n  d3.hcl = d3_hcl;\n  function d3_hcl(h, c, l) {\n    return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);\n  }\n  var d3_hclPrototype = d3_hcl.prototype = new d3_color();\n  d3_hclPrototype.brighter = function(k) {\n    return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));\n  };\n  d3_hclPrototype.darker = function(k) {\n    return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));\n  };\n  d3_hclPrototype.rgb = function() {\n    return d3_hcl_lab(this.h, this.c, this.l).rgb();\n  };\n  function d3_hcl_lab(h, c, l) {\n    if (isNaN(h)) h = 0;\n    if (isNaN(c)) c = 0;\n    return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);\n  }\n  d3.lab = d3_lab;\n  function d3_lab(l, a, b) {\n    return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);\n  }\n  var d3_lab_K = 18;\n  var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;\n  var d3_labPrototype = d3_lab.prototype = new d3_color();\n  d3_labPrototype.brighter = function(k) {\n    return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);\n  };\n  d3_labPrototype.darker = function(k) {\n    return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);\n  };\n  d3_labPrototype.rgb = function() {\n    return d3_lab_rgb(this.l, this.a, this.b);\n  };\n  function d3_lab_rgb(l, a, b) {\n    var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;\n    x = d3_lab_xyz(x) * d3_lab_X;\n    y = d3_lab_xyz(y) * d3_lab_Y;\n    z = d3_lab_xyz(z) * d3_lab_Z;\n    return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));\n  }\n  function d3_lab_hcl(l, a, b) {\n    return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);\n  }\n  function d3_lab_xyz(x) {\n    return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;\n  }\n  function d3_xyz_lab(x) {\n    return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;\n  }\n  function d3_xyz_rgb(r) {\n    return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));\n  }\n  d3.rgb = d3_rgb;\n  function d3_rgb(r, g, b) {\n    return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse(\"\" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);\n  }\n  function d3_rgbNumber(value) {\n    return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);\n  }\n  function d3_rgbString(value) {\n    return d3_rgbNumber(value) + \"\";\n  }\n  var d3_rgbPrototype = d3_rgb.prototype = new d3_color();\n  d3_rgbPrototype.brighter = function(k) {\n    k = Math.pow(.7, arguments.length ? k : 1);\n    var r = this.r, g = this.g, b = this.b, i = 30;\n    if (!r && !g && !b) return new d3_rgb(i, i, i);\n    if (r && r < i) r = i;\n    if (g && g < i) g = i;\n    if (b && b < i) b = i;\n    return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));\n  };\n  d3_rgbPrototype.darker = function(k) {\n    k = Math.pow(.7, arguments.length ? k : 1);\n    return new d3_rgb(k * this.r, k * this.g, k * this.b);\n  };\n  d3_rgbPrototype.hsl = function() {\n    return d3_rgb_hsl(this.r, this.g, this.b);\n  };\n  d3_rgbPrototype.toString = function() {\n    return \"#\" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);\n  };\n  function d3_rgb_hex(v) {\n    return v < 16 ? \"0\" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);\n  }\n  function d3_rgb_parse(format, rgb, hsl) {\n    var r = 0, g = 0, b = 0, m1, m2, color;\n    m1 = /([a-z]+)\\((.*)\\)/.exec(format = format.toLowerCase());\n    if (m1) {\n      m2 = m1[2].split(\",\");\n      switch (m1[1]) {\n       case \"hsl\":\n        {\n          return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);\n        }\n\n       case \"rgb\":\n        {\n          return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));\n        }\n      }\n    }\n    if (color = d3_rgb_names.get(format)) {\n      return rgb(color.r, color.g, color.b);\n    }\n    if (format != null && format.charAt(0) === \"#\" && !isNaN(color = parseInt(format.slice(1), 16))) {\n      if (format.length === 4) {\n        r = (color & 3840) >> 4;\n        r = r >> 4 | r;\n        g = color & 240;\n        g = g >> 4 | g;\n        b = color & 15;\n        b = b << 4 | b;\n      } else if (format.length === 7) {\n        r = (color & 16711680) >> 16;\n        g = (color & 65280) >> 8;\n        b = color & 255;\n      }\n    }\n    return rgb(r, g, b);\n  }\n  function d3_rgb_hsl(r, g, b) {\n    var min = Math.min(r /= 255, g /= 255, b /= 255), max = Math.max(r, g, b), d = max - min, h, s, l = (max + min) / 2;\n    if (d) {\n      s = l < .5 ? d / (max + min) : d / (2 - max - min);\n      if (r == max) h = (g - b) / d + (g < b ? 6 : 0); else if (g == max) h = (b - r) / d + 2; else h = (r - g) / d + 4;\n      h *= 60;\n    } else {\n      h = NaN;\n      s = l > 0 && l < 1 ? 0 : h;\n    }\n    return new d3_hsl(h, s, l);\n  }\n  function d3_rgb_lab(r, g, b) {\n    r = d3_rgb_xyz(r);\n    g = d3_rgb_xyz(g);\n    b = d3_rgb_xyz(b);\n    var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);\n    return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));\n  }\n  function d3_rgb_xyz(r) {\n    return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);\n  }\n  function d3_rgb_parseNumber(c) {\n    var f = parseFloat(c);\n    return c.charAt(c.length - 1) === \"%\" ? Math.round(f * 2.55) : f;\n  }\n  var d3_rgb_names = d3.map({\n    aliceblue: 15792383,\n    antiquewhite: 16444375,\n    aqua: 65535,\n    aquamarine: 8388564,\n    azure: 15794175,\n    beige: 16119260,\n    bisque: 16770244,\n    black: 0,\n    blanchedalmond: 16772045,\n    blue: 255,\n    blueviolet: 9055202,\n    brown: 10824234,\n    burlywood: 14596231,\n    cadetblue: 6266528,\n    chartreuse: 8388352,\n    chocolate: 13789470,\n    coral: 16744272,\n    cornflowerblue: 6591981,\n    cornsilk: 16775388,\n    crimson: 14423100,\n    cyan: 65535,\n    darkblue: 139,\n    darkcyan: 35723,\n    darkgoldenrod: 12092939,\n    darkgray: 11119017,\n    darkgreen: 25600,\n    darkgrey: 11119017,\n    darkkhaki: 12433259,\n    darkmagenta: 9109643,\n    darkolivegreen: 5597999,\n    darkorange: 16747520,\n    darkorchid: 10040012,\n    darkred: 9109504,\n    darksalmon: 15308410,\n    darkseagreen: 9419919,\n    darkslateblue: 4734347,\n    darkslategray: 3100495,\n    darkslategrey: 3100495,\n    darkturquoise: 52945,\n    darkviolet: 9699539,\n    deeppink: 16716947,\n    deepskyblue: 49151,\n    dimgray: 6908265,\n    dimgrey: 6908265,\n    dodgerblue: 2003199,\n    firebrick: 11674146,\n    floralwhite: 16775920,\n    forestgreen: 2263842,\n    fuchsia: 16711935,\n    gainsboro: 14474460,\n    ghostwhite: 16316671,\n    gold: 16766720,\n    goldenrod: 14329120,\n    gray: 8421504,\n    green: 32768,\n    greenyellow: 11403055,\n    grey: 8421504,\n    honeydew: 15794160,\n    hotpink: 16738740,\n    indianred: 13458524,\n    indigo: 4915330,\n    ivory: 16777200,\n    khaki: 15787660,\n    lavender: 15132410,\n    lavenderblush: 16773365,\n    lawngreen: 8190976,\n    lemonchiffon: 16775885,\n    lightblue: 11393254,\n    lightcoral: 15761536,\n    lightcyan: 14745599,\n    lightgoldenrodyellow: 16448210,\n    lightgray: 13882323,\n    lightgreen: 9498256,\n    lightgrey: 13882323,\n    lightpink: 16758465,\n    lightsalmon: 16752762,\n    lightseagreen: 2142890,\n    lightskyblue: 8900346,\n    lightslategray: 7833753,\n    lightslategrey: 7833753,\n    lightsteelblue: 11584734,\n    lightyellow: 16777184,\n    lime: 65280,\n    limegreen: 3329330,\n    linen: 16445670,\n    magenta: 16711935,\n    maroon: 8388608,\n    mediumaquamarine: 6737322,\n    mediumblue: 205,\n    mediumorchid: 12211667,\n    mediumpurple: 9662683,\n    mediumseagreen: 3978097,\n    mediumslateblue: 8087790,\n    mediumspringgreen: 64154,\n    mediumturquoise: 4772300,\n    mediumvioletred: 13047173,\n    midnightblue: 1644912,\n    mintcream: 16121850,\n    mistyrose: 16770273,\n    moccasin: 16770229,\n    navajowhite: 16768685,\n    navy: 128,\n    oldlace: 16643558,\n    olive: 8421376,\n    olivedrab: 7048739,\n    orange: 16753920,\n    orangered: 16729344,\n    orchid: 14315734,\n    palegoldenrod: 15657130,\n    palegreen: 10025880,\n    paleturquoise: 11529966,\n    palevioletred: 14381203,\n    papayawhip: 16773077,\n    peachpuff: 16767673,\n    peru: 13468991,\n    pink: 16761035,\n    plum: 14524637,\n    powderblue: 11591910,\n    purple: 8388736,\n    rebeccapurple: 6697881,\n    red: 16711680,\n    rosybrown: 12357519,\n    royalblue: 4286945,\n    saddlebrown: 9127187,\n    salmon: 16416882,\n    sandybrown: 16032864,\n    seagreen: 3050327,\n    seashell: 16774638,\n    sienna: 10506797,\n    silver: 12632256,\n    skyblue: 8900331,\n    slateblue: 6970061,\n    slategray: 7372944,\n    slategrey: 7372944,\n    snow: 16775930,\n    springgreen: 65407,\n    steelblue: 4620980,\n    tan: 13808780,\n    teal: 32896,\n    thistle: 14204888,\n    tomato: 16737095,\n    turquoise: 4251856,\n    violet: 15631086,\n    wheat: 16113331,\n    white: 16777215,\n    whitesmoke: 16119285,\n    yellow: 16776960,\n    yellowgreen: 10145074\n  });\n  d3_rgb_names.forEach(function(key, value) {\n    d3_rgb_names.set(key, d3_rgbNumber(value));\n  });\n  function d3_functor(v) {\n    return typeof v === \"function\" ? v : function() {\n      return v;\n    };\n  }\n  d3.functor = d3_functor;\n  d3.xhr = d3_xhrType(d3_identity);\n  function d3_xhrType(response) {\n    return function(url, mimeType, callback) {\n      if (arguments.length === 2 && typeof mimeType === \"function\") callback = mimeType, \n      mimeType = null;\n      return d3_xhr(url, mimeType, response, callback);\n    };\n  }\n  function d3_xhr(url, mimeType, response, callback) {\n    var xhr = {}, dispatch = d3.dispatch(\"beforesend\", \"progress\", \"load\", \"error\"), headers = {}, request = new XMLHttpRequest(), responseType = null;\n    if (this.XDomainRequest && !(\"withCredentials\" in request) && /^(http(s)?:)?\\/\\//.test(url)) request = new XDomainRequest();\n    \"onload\" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {\n      request.readyState > 3 && respond();\n    };\n    function respond() {\n      var status = request.status, result;\n      if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {\n        try {\n          result = response.call(xhr, request);\n        } catch (e) {\n          dispatch.error.call(xhr, e);\n          return;\n        }\n        dispatch.load.call(xhr, result);\n      } else {\n        dispatch.error.call(xhr, request);\n      }\n    }\n    request.onprogress = function(event) {\n      var o = d3.event;\n      d3.event = event;\n      try {\n        dispatch.progress.call(xhr, request);\n      } finally {\n        d3.event = o;\n      }\n    };\n    xhr.header = function(name, value) {\n      name = (name + \"\").toLowerCase();\n      if (arguments.length < 2) return headers[name];\n      if (value == null) delete headers[name]; else headers[name] = value + \"\";\n      return xhr;\n    };\n    xhr.mimeType = function(value) {\n      if (!arguments.length) return mimeType;\n      mimeType = value == null ? null : value + \"\";\n      return xhr;\n    };\n    xhr.responseType = function(value) {\n      if (!arguments.length) return responseType;\n      responseType = value;\n      return xhr;\n    };\n    xhr.response = function(value) {\n      response = value;\n      return xhr;\n    };\n    [ \"get\", \"post\" ].forEach(function(method) {\n      xhr[method] = function() {\n        return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));\n      };\n    });\n    xhr.send = function(method, data, callback) {\n      if (arguments.length === 2 && typeof data === \"function\") callback = data, data = null;\n      request.open(method, url, true);\n      if (mimeType != null && !(\"accept\" in headers)) headers[\"accept\"] = mimeType + \",*/*\";\n      if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);\n      if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);\n      if (responseType != null) request.responseType = responseType;\n      if (callback != null) xhr.on(\"error\", callback).on(\"load\", function(request) {\n        callback(null, request);\n      });\n      dispatch.beforesend.call(xhr, request);\n      request.send(data == null ? null : data);\n      return xhr;\n    };\n    xhr.abort = function() {\n      request.abort();\n      return xhr;\n    };\n    d3.rebind(xhr, dispatch, \"on\");\n    return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));\n  }\n  function d3_xhr_fixCallback(callback) {\n    return callback.length === 1 ? function(error, request) {\n      callback(error == null ? request : null);\n    } : callback;\n  }\n  function d3_xhrHasResponse(request) {\n    var type = request.responseType;\n    return type && type !== \"text\" ? request.response : request.responseText;\n  }\n  d3.dsv = function(delimiter, mimeType) {\n    var reFormat = new RegExp('[\"' + delimiter + \"\\n]\"), delimiterCode = delimiter.charCodeAt(0);\n    function dsv(url, row, callback) {\n      if (arguments.length < 3) callback = row, row = null;\n      var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);\n      xhr.row = function(_) {\n        return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;\n      };\n      return xhr;\n    }\n    function response(request) {\n      return dsv.parse(request.responseText);\n    }\n    function typedResponse(f) {\n      return function(request) {\n        return dsv.parse(request.responseText, f);\n      };\n    }\n    dsv.parse = function(text, f) {\n      var o;\n      return dsv.parseRows(text, function(row, i) {\n        if (o) return o(row, i - 1);\n        var a = new Function(\"d\", \"return {\" + row.map(function(name, i) {\n          return JSON.stringify(name) + \": d[\" + i + \"]\";\n        }).join(\",\") + \"}\");\n        o = f ? function(row, i) {\n          return f(a(row), i);\n        } : a;\n      });\n    };\n    dsv.parseRows = function(text, f) {\n      var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;\n      function token() {\n        if (I >= N) return EOF;\n        if (eol) return eol = false, EOL;\n        var j = I;\n        if (text.charCodeAt(j) === 34) {\n          var i = j;\n          while (i++ < N) {\n            if (text.charCodeAt(i) === 34) {\n              if (text.charCodeAt(i + 1) !== 34) break;\n              ++i;\n            }\n          }\n          I = i + 2;\n          var c = text.charCodeAt(i + 1);\n          if (c === 13) {\n            eol = true;\n            if (text.charCodeAt(i + 2) === 10) ++I;\n          } else if (c === 10) {\n            eol = true;\n          }\n          return text.slice(j + 1, i).replace(/\"\"/g, '\"');\n        }\n        while (I < N) {\n          var c = text.charCodeAt(I++), k = 1;\n          if (c === 10) eol = true; else if (c === 13) {\n            eol = true;\n            if (text.charCodeAt(I) === 10) ++I, ++k;\n          } else if (c !== delimiterCode) continue;\n          return text.slice(j, I - k);\n        }\n        return text.slice(j);\n      }\n      while ((t = token()) !== EOF) {\n        var a = [];\n        while (t !== EOL && t !== EOF) {\n          a.push(t);\n          t = token();\n        }\n        if (f && (a = f(a, n++)) == null) continue;\n        rows.push(a);\n      }\n      return rows;\n    };\n    dsv.format = function(rows) {\n      if (Array.isArray(rows[0])) return dsv.formatRows(rows);\n      var fieldSet = new d3_Set(), fields = [];\n      rows.forEach(function(row) {\n        for (var field in row) {\n          if (!fieldSet.has(field)) {\n            fields.push(fieldSet.add(field));\n          }\n        }\n      });\n      return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {\n        return fields.map(function(field) {\n          return formatValue(row[field]);\n        }).join(delimiter);\n      })).join(\"\\n\");\n    };\n    dsv.formatRows = function(rows) {\n      return rows.map(formatRow).join(\"\\n\");\n    };\n    function formatRow(row) {\n      return row.map(formatValue).join(delimiter);\n    }\n    function formatValue(text) {\n      return reFormat.test(text) ? '\"' + text.replace(/\\\"/g, '\"\"') + '\"' : text;\n    }\n    return dsv;\n  };\n  d3.csv = d3.dsv(\",\", \"text/csv\");\n  d3.tsv = d3.dsv(\"\t\", \"text/tab-separated-values\");\n  var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, \"requestAnimationFrame\")] || function(callback) {\n    setTimeout(callback, 17);\n  };\n  d3.timer = function() {\n    d3_timer.apply(this, arguments);\n  };\n  function d3_timer(callback, delay, then) {\n    var n = arguments.length;\n    if (n < 2) delay = 0;\n    if (n < 3) then = Date.now();\n    var time = then + delay, timer = {\n      c: callback,\n      t: time,\n      n: null\n    };\n    if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;\n    d3_timer_queueTail = timer;\n    if (!d3_timer_interval) {\n      d3_timer_timeout = clearTimeout(d3_timer_timeout);\n      d3_timer_interval = 1;\n      d3_timer_frame(d3_timer_step);\n    }\n    return timer;\n  }\n  function d3_timer_step() {\n    var now = d3_timer_mark(), delay = d3_timer_sweep() - now;\n    if (delay > 24) {\n      if (isFinite(delay)) {\n        clearTimeout(d3_timer_timeout);\n        d3_timer_timeout = setTimeout(d3_timer_step, delay);\n      }\n      d3_timer_interval = 0;\n    } else {\n      d3_timer_interval = 1;\n      d3_timer_frame(d3_timer_step);\n    }\n  }\n  d3.timer.flush = function() {\n    d3_timer_mark();\n    d3_timer_sweep();\n  };\n  function d3_timer_mark() {\n    var now = Date.now(), timer = d3_timer_queueHead;\n    while (timer) {\n      if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;\n      timer = timer.n;\n    }\n    return now;\n  }\n  function d3_timer_sweep() {\n    var t0, t1 = d3_timer_queueHead, time = Infinity;\n    while (t1) {\n      if (t1.c) {\n        if (t1.t < time) time = t1.t;\n        t1 = (t0 = t1).n;\n      } else {\n        t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;\n      }\n    }\n    d3_timer_queueTail = t0;\n    return time;\n  }\n  function d3_format_precision(x, p) {\n    return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);\n  }\n  d3.round = function(x, n) {\n    return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);\n  };\n  var d3_formatPrefixes = [ \"y\", \"z\", \"a\", \"f\", \"p\", \"n\", \"µ\", \"m\", \"\", \"k\", \"M\", \"G\", \"T\", \"P\", \"E\", \"Z\", \"Y\" ].map(d3_formatPrefix);\n  d3.formatPrefix = function(value, precision) {\n    var i = 0;\n    if (value = +value) {\n      if (value < 0) value *= -1;\n      if (precision) value = d3.round(value, d3_format_precision(value, precision));\n      i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);\n      i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));\n    }\n    return d3_formatPrefixes[8 + i / 3];\n  };\n  function d3_formatPrefix(d, i) {\n    var k = Math.pow(10, abs(8 - i) * 3);\n    return {\n      scale: i > 8 ? function(d) {\n        return d / k;\n      } : function(d) {\n        return d * k;\n      },\n      symbol: d\n    };\n  }\n  function d3_locale_numberFormat(locale) {\n    var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {\n      var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;\n      while (i > 0 && g > 0) {\n        if (length + g + 1 > width) g = Math.max(1, width - length);\n        t.push(value.substring(i -= g, i + g));\n        if ((length += g + 1) > width) break;\n        g = locale_grouping[j = (j + 1) % locale_grouping.length];\n      }\n      return t.reverse().join(locale_thousands);\n    } : d3_identity;\n    return function(specifier) {\n      var match = d3_format_re.exec(specifier), fill = match[1] || \" \", align = match[2] || \">\", sign = match[3] || \"-\", symbol = match[4] || \"\", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = \"\", suffix = \"\", integer = false, exponent = true;\n      if (precision) precision = +precision.substring(1);\n      if (zfill || fill === \"0\" && align === \"=\") {\n        zfill = fill = \"0\";\n        align = \"=\";\n      }\n      switch (type) {\n       case \"n\":\n        comma = true;\n        type = \"g\";\n        break;\n\n       case \"%\":\n        scale = 100;\n        suffix = \"%\";\n        type = \"f\";\n        break;\n\n       case \"p\":\n        scale = 100;\n        suffix = \"%\";\n        type = \"r\";\n        break;\n\n       case \"b\":\n       case \"o\":\n       case \"x\":\n       case \"X\":\n        if (symbol === \"#\") prefix = \"0\" + type.toLowerCase();\n\n       case \"c\":\n        exponent = false;\n\n       case \"d\":\n        integer = true;\n        precision = 0;\n        break;\n\n       case \"s\":\n        scale = -1;\n        type = \"r\";\n        break;\n      }\n      if (symbol === \"$\") prefix = locale_currency[0], suffix = locale_currency[1];\n      if (type == \"r\" && !precision) type = \"g\";\n      if (precision != null) {\n        if (type == \"g\") precision = Math.max(1, Math.min(21, precision)); else if (type == \"e\" || type == \"f\") precision = Math.max(0, Math.min(20, precision));\n      }\n      type = d3_format_types.get(type) || d3_format_typeDefault;\n      var zcomma = zfill && comma;\n      return function(value) {\n        var fullSuffix = suffix;\n        if (integer && value % 1) return \"\";\n        var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, \"-\") : sign === \"-\" ? \"\" : sign;\n        if (scale < 0) {\n          var unit = d3.formatPrefix(value, precision);\n          value = unit.scale(value);\n          fullSuffix = unit.symbol + suffix;\n        } else {\n          value *= scale;\n        }\n        value = type(value, precision);\n        var i = value.lastIndexOf(\".\"), before, after;\n        if (i < 0) {\n          var j = exponent ? value.lastIndexOf(\"e\") : -1;\n          if (j < 0) before = value, after = \"\"; else before = value.substring(0, j), after = value.substring(j);\n        } else {\n          before = value.substring(0, i);\n          after = locale_decimal + value.substring(i + 1);\n        }\n        if (!zfill && comma) before = formatGroup(before, Infinity);\n        var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : \"\";\n        if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);\n        negative += prefix;\n        value = before + after;\n        return (align === \"<\" ? negative + value + padding : align === \">\" ? padding + negative + value : align === \"^\" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix;\n      };\n    };\n  }\n  var d3_format_re = /(?:([^{])?([<>=^]))?([+\\- ])?([$#])?(0)?(\\d+)?(,)?(\\.-?\\d+)?([a-z%])?/i;\n  var d3_format_types = d3.map({\n    b: function(x) {\n      return x.toString(2);\n    },\n    c: function(x) {\n      return String.fromCharCode(x);\n    },\n    o: function(x) {\n      return x.toString(8);\n    },\n    x: function(x) {\n      return x.toString(16);\n    },\n    X: function(x) {\n      return x.toString(16).toUpperCase();\n    },\n    g: function(x, p) {\n      return x.toPrecision(p);\n    },\n    e: function(x, p) {\n      return x.toExponential(p);\n    },\n    f: function(x, p) {\n      return x.toFixed(p);\n    },\n    r: function(x, p) {\n      return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p))));\n    }\n  });\n  function d3_format_typeDefault(x) {\n    return x + \"\";\n  }\n  var d3_time = d3.time = {}, d3_date = Date;\n  function d3_date_utc() {\n    this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);\n  }\n  d3_date_utc.prototype = {\n    getDate: function() {\n      return this._.getUTCDate();\n    },\n    getDay: function() {\n      return this._.getUTCDay();\n    },\n    getFullYear: function() {\n      return this._.getUTCFullYear();\n    },\n    getHours: function() {\n      return this._.getUTCHours();\n    },\n    getMilliseconds: function() {\n      return this._.getUTCMilliseconds();\n    },\n    getMinutes: function() {\n      return this._.getUTCMinutes();\n    },\n    getMonth: function() {\n      return this._.getUTCMonth();\n    },\n    getSeconds: function() {\n      return this._.getUTCSeconds();\n    },\n    getTime: function() {\n      return this._.getTime();\n    },\n    getTimezoneOffset: function() {\n      return 0;\n    },\n    valueOf: function() {\n      return this._.valueOf();\n    },\n    setDate: function() {\n      d3_time_prototype.setUTCDate.apply(this._, arguments);\n    },\n    setDay: function() {\n      d3_time_prototype.setUTCDay.apply(this._, arguments);\n    },\n    setFullYear: function() {\n      d3_time_prototype.setUTCFullYear.apply(this._, arguments);\n    },\n    setHours: function() {\n      d3_time_prototype.setUTCHours.apply(this._, arguments);\n    },\n    setMilliseconds: function() {\n      d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);\n    },\n    setMinutes: function() {\n      d3_time_prototype.setUTCMinutes.apply(this._, arguments);\n    },\n    setMonth: function() {\n      d3_time_prototype.setUTCMonth.apply(this._, arguments);\n    },\n    setSeconds: function() {\n      d3_time_prototype.setUTCSeconds.apply(this._, arguments);\n    },\n    setTime: function() {\n      d3_time_prototype.setTime.apply(this._, arguments);\n    }\n  };\n  var d3_time_prototype = Date.prototype;\n  function d3_time_interval(local, step, number) {\n    function round(date) {\n      var d0 = local(date), d1 = offset(d0, 1);\n      return date - d0 < d1 - date ? d0 : d1;\n    }\n    function ceil(date) {\n      step(date = local(new d3_date(date - 1)), 1);\n      return date;\n    }\n    function offset(date, k) {\n      step(date = new d3_date(+date), k);\n      return date;\n    }\n    function range(t0, t1, dt) {\n      var time = ceil(t0), times = [];\n      if (dt > 1) {\n        while (time < t1) {\n          if (!(number(time) % dt)) times.push(new Date(+time));\n          step(time, 1);\n        }\n      } else {\n        while (time < t1) times.push(new Date(+time)), step(time, 1);\n      }\n      return times;\n    }\n    function range_utc(t0, t1, dt) {\n      try {\n        d3_date = d3_date_utc;\n        var utc = new d3_date_utc();\n        utc._ = t0;\n        return range(utc, t1, dt);\n      } finally {\n        d3_date = Date;\n      }\n    }\n    local.floor = local;\n    local.round = round;\n    local.ceil = ceil;\n    local.offset = offset;\n    local.range = range;\n    var utc = local.utc = d3_time_interval_utc(local);\n    utc.floor = utc;\n    utc.round = d3_time_interval_utc(round);\n    utc.ceil = d3_time_interval_utc(ceil);\n    utc.offset = d3_time_interval_utc(offset);\n    utc.range = range_utc;\n    return local;\n  }\n  function d3_time_interval_utc(method) {\n    return function(date, k) {\n      try {\n        d3_date = d3_date_utc;\n        var utc = new d3_date_utc();\n        utc._ = date;\n        return method(utc, k)._;\n      } finally {\n        d3_date = Date;\n      }\n    };\n  }\n  d3_time.year = d3_time_interval(function(date) {\n    date = d3_time.day(date);\n    date.setMonth(0, 1);\n    return date;\n  }, function(date, offset) {\n    date.setFullYear(date.getFullYear() + offset);\n  }, function(date) {\n    return date.getFullYear();\n  });\n  d3_time.years = d3_time.year.range;\n  d3_time.years.utc = d3_time.year.utc.range;\n  d3_time.day = d3_time_interval(function(date) {\n    var day = new d3_date(2e3, 0);\n    day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());\n    return day;\n  }, function(date, offset) {\n    date.setDate(date.getDate() + offset);\n  }, function(date) {\n    return date.getDate() - 1;\n  });\n  d3_time.days = d3_time.day.range;\n  d3_time.days.utc = d3_time.day.utc.range;\n  d3_time.dayOfYear = function(date) {\n    var year = d3_time.year(date);\n    return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);\n  };\n  [ \"sunday\", \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\" ].forEach(function(day, i) {\n    i = 7 - i;\n    var interval = d3_time[day] = d3_time_interval(function(date) {\n      (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);\n      return date;\n    }, function(date, offset) {\n      date.setDate(date.getDate() + Math.floor(offset) * 7);\n    }, function(date) {\n      var day = d3_time.year(date).getDay();\n      return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);\n    });\n    d3_time[day + \"s\"] = interval.range;\n    d3_time[day + \"s\"].utc = interval.utc.range;\n    d3_time[day + \"OfYear\"] = function(date) {\n      var day = d3_time.year(date).getDay();\n      return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);\n    };\n  });\n  d3_time.week = d3_time.sunday;\n  d3_time.weeks = d3_time.sunday.range;\n  d3_time.weeks.utc = d3_time.sunday.utc.range;\n  d3_time.weekOfYear = d3_time.sundayOfYear;\n  function d3_locale_timeFormat(locale) {\n    var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;\n    function d3_time_format(template) {\n      var n = template.length;\n      function format(date) {\n        var string = [], i = -1, j = 0, c, p, f;\n        while (++i < n) {\n          if (template.charCodeAt(i) === 37) {\n            string.push(template.slice(j, i));\n            if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);\n            if (f = d3_time_formats[c]) c = f(date, p == null ? c === \"e\" ? \" \" : \"0\" : p);\n            string.push(c);\n            j = i + 1;\n          }\n        }\n        string.push(template.slice(j, i));\n        return string.join(\"\");\n      }\n      format.parse = function(string) {\n        var d = {\n          y: 1900,\n          m: 0,\n          d: 1,\n          H: 0,\n          M: 0,\n          S: 0,\n          L: 0,\n          Z: null\n        }, i = d3_time_parse(d, template, string, 0);\n        if (i != string.length) return null;\n        if (\"p\" in d) d.H = d.H % 12 + d.p * 12;\n        var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();\n        if (\"j\" in d) date.setFullYear(d.y, 0, d.j); else if (\"W\" in d || \"U\" in d) {\n          if (!(\"w\" in d)) d.w = \"W\" in d ? 1 : 0;\n          date.setFullYear(d.y, 0, 1);\n          date.setFullYear(d.y, 0, \"W\" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);\n        } else date.setFullYear(d.y, d.m, d.d);\n        date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);\n        return localZ ? date._ : date;\n      };\n      format.toString = function() {\n        return template;\n      };\n      return format;\n    }\n    function d3_time_parse(date, template, string, j) {\n      var c, p, t, i = 0, n = template.length, m = string.length;\n      while (i < n) {\n        if (j >= m) return -1;\n        c = template.charCodeAt(i++);\n        if (c === 37) {\n          t = template.charAt(i++);\n          p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];\n          if (!p || (j = p(date, string, j)) < 0) return -1;\n        } else if (c != string.charCodeAt(j++)) {\n          return -1;\n        }\n      }\n      return j;\n    }\n    d3_time_format.utc = function(template) {\n      var local = d3_time_format(template);\n      function format(date) {\n        try {\n          d3_date = d3_date_utc;\n          var utc = new d3_date();\n          utc._ = date;\n          return local(utc);\n        } finally {\n          d3_date = Date;\n        }\n      }\n      format.parse = function(string) {\n        try {\n          d3_date = d3_date_utc;\n          var date = local.parse(string);\n          return date && date._;\n        } finally {\n          d3_date = Date;\n        }\n      };\n      format.toString = local.toString;\n      return format;\n    };\n    d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;\n    var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);\n    locale_periods.forEach(function(p, i) {\n      d3_time_periodLookup.set(p.toLowerCase(), i);\n    });\n    var d3_time_formats = {\n      a: function(d) {\n        return locale_shortDays[d.getDay()];\n      },\n      A: function(d) {\n        return locale_days[d.getDay()];\n      },\n      b: function(d) {\n        return locale_shortMonths[d.getMonth()];\n      },\n      B: function(d) {\n        return locale_months[d.getMonth()];\n      },\n      c: d3_time_format(locale_dateTime),\n      d: function(d, p) {\n        return d3_time_formatPad(d.getDate(), p, 2);\n      },\n      e: function(d, p) {\n        return d3_time_formatPad(d.getDate(), p, 2);\n      },\n      H: function(d, p) {\n        return d3_time_formatPad(d.getHours(), p, 2);\n      },\n      I: function(d, p) {\n        return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);\n      },\n      j: function(d, p) {\n        return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);\n      },\n      L: function(d, p) {\n        return d3_time_formatPad(d.getMilliseconds(), p, 3);\n      },\n      m: function(d, p) {\n        return d3_time_formatPad(d.getMonth() + 1, p, 2);\n      },\n      M: function(d, p) {\n        return d3_time_formatPad(d.getMinutes(), p, 2);\n      },\n      p: function(d) {\n        return locale_periods[+(d.getHours() >= 12)];\n      },\n      S: function(d, p) {\n        return d3_time_formatPad(d.getSeconds(), p, 2);\n      },\n      U: function(d, p) {\n        return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);\n      },\n      w: function(d) {\n        return d.getDay();\n      },\n      W: function(d, p) {\n        return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);\n      },\n      x: d3_time_format(locale_date),\n      X: d3_time_format(locale_time),\n      y: function(d, p) {\n        return d3_time_formatPad(d.getFullYear() % 100, p, 2);\n      },\n      Y: function(d, p) {\n        return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);\n      },\n      Z: d3_time_zone,\n      \"%\": function() {\n        return \"%\";\n      }\n    };\n    var d3_time_parsers = {\n      a: d3_time_parseWeekdayAbbrev,\n      A: d3_time_parseWeekday,\n      b: d3_time_parseMonthAbbrev,\n      B: d3_time_parseMonth,\n      c: d3_time_parseLocaleFull,\n      d: d3_time_parseDay,\n      e: d3_time_parseDay,\n      H: d3_time_parseHour24,\n      I: d3_time_parseHour24,\n      j: d3_time_parseDayOfYear,\n      L: d3_time_parseMilliseconds,\n      m: d3_time_parseMonthNumber,\n      M: d3_time_parseMinutes,\n      p: d3_time_parseAmPm,\n      S: d3_time_parseSeconds,\n      U: d3_time_parseWeekNumberSunday,\n      w: d3_time_parseWeekdayNumber,\n      W: d3_time_parseWeekNumberMonday,\n      x: d3_time_parseLocaleDate,\n      X: d3_time_parseLocaleTime,\n      y: d3_time_parseYear,\n      Y: d3_time_parseFullYear,\n      Z: d3_time_parseZone,\n      \"%\": d3_time_parseLiteralPercent\n    };\n    function d3_time_parseWeekdayAbbrev(date, string, i) {\n      d3_time_dayAbbrevRe.lastIndex = 0;\n      var n = d3_time_dayAbbrevRe.exec(string.slice(i));\n      return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;\n    }\n    function d3_time_parseWeekday(date, string, i) {\n      d3_time_dayRe.lastIndex = 0;\n      var n = d3_time_dayRe.exec(string.slice(i));\n      return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;\n    }\n    function d3_time_parseMonthAbbrev(date, string, i) {\n      d3_time_monthAbbrevRe.lastIndex = 0;\n      var n = d3_time_monthAbbrevRe.exec(string.slice(i));\n      return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;\n    }\n    function d3_time_parseMonth(date, string, i) {\n      d3_time_monthRe.lastIndex = 0;\n      var n = d3_time_monthRe.exec(string.slice(i));\n      return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;\n    }\n    function d3_time_parseLocaleFull(date, string, i) {\n      return d3_time_parse(date, d3_time_formats.c.toString(), string, i);\n    }\n    function d3_time_parseLocaleDate(date, string, i) {\n      return d3_time_parse(date, d3_time_formats.x.toString(), string, i);\n    }\n    function d3_time_parseLocaleTime(date, string, i) {\n      return d3_time_parse(date, d3_time_formats.X.toString(), string, i);\n    }\n    function d3_time_parseAmPm(date, string, i) {\n      var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());\n      return n == null ? -1 : (date.p = n, i);\n    }\n    return d3_time_format;\n  }\n  var d3_time_formatPads = {\n    \"-\": \"\",\n    _: \" \",\n    \"0\": \"0\"\n  }, d3_time_numberRe = /^\\s*\\d+/, d3_time_percentRe = /^%/;\n  function d3_time_formatPad(value, fill, width) {\n    var sign = value < 0 ? \"-\" : \"\", string = (sign ? -value : value) + \"\", length = string.length;\n    return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);\n  }\n  function d3_time_formatRe(names) {\n    return new RegExp(\"^(?:\" + names.map(d3.requote).join(\"|\") + \")\", \"i\");\n  }\n  function d3_time_formatLookup(names) {\n    var map = new d3_Map(), i = -1, n = names.length;\n    while (++i < n) map.set(names[i].toLowerCase(), i);\n    return map;\n  }\n  function d3_time_parseWeekdayNumber(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 1));\n    return n ? (date.w = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseWeekNumberSunday(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i));\n    return n ? (date.U = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseWeekNumberMonday(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i));\n    return n ? (date.W = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseFullYear(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 4));\n    return n ? (date.y = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseYear(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 2));\n    return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;\n  }\n  function d3_time_parseZone(date, string, i) {\n    return /^[+-]\\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string, \n    i + 5) : -1;\n  }\n  function d3_time_expandYear(d) {\n    return d + (d > 68 ? 1900 : 2e3);\n  }\n  function d3_time_parseMonthNumber(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 2));\n    return n ? (date.m = n[0] - 1, i + n[0].length) : -1;\n  }\n  function d3_time_parseDay(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 2));\n    return n ? (date.d = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseDayOfYear(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 3));\n    return n ? (date.j = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseHour24(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 2));\n    return n ? (date.H = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseMinutes(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 2));\n    return n ? (date.M = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseSeconds(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 2));\n    return n ? (date.S = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_parseMilliseconds(date, string, i) {\n    d3_time_numberRe.lastIndex = 0;\n    var n = d3_time_numberRe.exec(string.slice(i, i + 3));\n    return n ? (date.L = +n[0], i + n[0].length) : -1;\n  }\n  function d3_time_zone(d) {\n    var z = d.getTimezoneOffset(), zs = z > 0 ? \"-\" : \"+\", zh = abs(z) / 60 | 0, zm = abs(z) % 60;\n    return zs + d3_time_formatPad(zh, \"0\", 2) + d3_time_formatPad(zm, \"0\", 2);\n  }\n  function d3_time_parseLiteralPercent(date, string, i) {\n    d3_time_percentRe.lastIndex = 0;\n    var n = d3_time_percentRe.exec(string.slice(i, i + 1));\n    return n ? i + n[0].length : -1;\n  }\n  function d3_time_formatMulti(formats) {\n    var n = formats.length, i = -1;\n    while (++i < n) formats[i][0] = this(formats[i][0]);\n    return function(date) {\n      var i = 0, f = formats[i];\n      while (!f[1](date)) f = formats[++i];\n      return f[0](date);\n    };\n  }\n  d3.locale = function(locale) {\n    return {\n      numberFormat: d3_locale_numberFormat(locale),\n      timeFormat: d3_locale_timeFormat(locale)\n    };\n  };\n  var d3_locale_enUS = d3.locale({\n    decimal: \".\",\n    thousands: \",\",\n    grouping: [ 3 ],\n    currency: [ \"$\", \"\" ],\n    dateTime: \"%a %b %e %X %Y\",\n    date: \"%m/%d/%Y\",\n    time: \"%H:%M:%S\",\n    periods: [ \"AM\", \"PM\" ],\n    days: [ \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\" ],\n    shortDays: [ \"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\" ],\n    months: [ \"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\" ],\n    shortMonths: [ \"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\" ]\n  });\n  d3.format = d3_locale_enUS.numberFormat;\n  d3.geo = {};\n  function d3_adder() {}\n  d3_adder.prototype = {\n    s: 0,\n    t: 0,\n    add: function(y) {\n      d3_adderSum(y, this.t, d3_adderTemp);\n      d3_adderSum(d3_adderTemp.s, this.s, this);\n      if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;\n    },\n    reset: function() {\n      this.s = this.t = 0;\n    },\n    valueOf: function() {\n      return this.s;\n    }\n  };\n  var d3_adderTemp = new d3_adder();\n  function d3_adderSum(a, b, o) {\n    var x = o.s = a + b, bv = x - a, av = x - bv;\n    o.t = a - av + (b - bv);\n  }\n  d3.geo.stream = function(object, listener) {\n    if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {\n      d3_geo_streamObjectType[object.type](object, listener);\n    } else {\n      d3_geo_streamGeometry(object, listener);\n    }\n  };\n  function d3_geo_streamGeometry(geometry, listener) {\n    if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {\n      d3_geo_streamGeometryType[geometry.type](geometry, listener);\n    }\n  }\n  var d3_geo_streamObjectType = {\n    Feature: function(feature, listener) {\n      d3_geo_streamGeometry(feature.geometry, listener);\n    },\n    FeatureCollection: function(object, listener) {\n      var features = object.features, i = -1, n = features.length;\n      while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);\n    }\n  };\n  var d3_geo_streamGeometryType = {\n    Sphere: function(object, listener) {\n      listener.sphere();\n    },\n    Point: function(object, listener) {\n      object = object.coordinates;\n      listener.point(object[0], object[1], object[2]);\n    },\n    MultiPoint: function(object, listener) {\n      var coordinates = object.coordinates, i = -1, n = coordinates.length;\n      while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);\n    },\n    LineString: function(object, listener) {\n      d3_geo_streamLine(object.coordinates, listener, 0);\n    },\n    MultiLineString: function(object, listener) {\n      var coordinates = object.coordinates, i = -1, n = coordinates.length;\n      while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);\n    },\n    Polygon: function(object, listener) {\n      d3_geo_streamPolygon(object.coordinates, listener);\n    },\n    MultiPolygon: function(object, listener) {\n      var coordinates = object.coordinates, i = -1, n = coordinates.length;\n      while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);\n    },\n    GeometryCollection: function(object, listener) {\n      var geometries = object.geometries, i = -1, n = geometries.length;\n      while (++i < n) d3_geo_streamGeometry(geometries[i], listener);\n    }\n  };\n  function d3_geo_streamLine(coordinates, listener, closed) {\n    var i = -1, n = coordinates.length - closed, coordinate;\n    listener.lineStart();\n    while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);\n    listener.lineEnd();\n  }\n  function d3_geo_streamPolygon(coordinates, listener) {\n    var i = -1, n = coordinates.length;\n    listener.polygonStart();\n    while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);\n    listener.polygonEnd();\n  }\n  d3.geo.area = function(object) {\n    d3_geo_areaSum = 0;\n    d3.geo.stream(object, d3_geo_area);\n    return d3_geo_areaSum;\n  };\n  var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();\n  var d3_geo_area = {\n    sphere: function() {\n      d3_geo_areaSum += 4 * π;\n    },\n    point: d3_noop,\n    lineStart: d3_noop,\n    lineEnd: d3_noop,\n    polygonStart: function() {\n      d3_geo_areaRingSum.reset();\n      d3_geo_area.lineStart = d3_geo_areaRingStart;\n    },\n    polygonEnd: function() {\n      var area = 2 * d3_geo_areaRingSum;\n      d3_geo_areaSum += area < 0 ? 4 * π + area : area;\n      d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;\n    }\n  };\n  function d3_geo_areaRingStart() {\n    var λ00, φ00, λ0, cosφ0, sinφ0;\n    d3_geo_area.point = function(λ, φ) {\n      d3_geo_area.point = nextPoint;\n      λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4), \n      sinφ0 = Math.sin(φ);\n    };\n    function nextPoint(λ, φ) {\n      λ *= d3_radians;\n      φ = φ * d3_radians / 2 + π / 4;\n      var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);\n      d3_geo_areaRingSum.add(Math.atan2(v, u));\n      λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;\n    }\n    d3_geo_area.lineEnd = function() {\n      nextPoint(λ00, φ00);\n    };\n  }\n  function d3_geo_cartesian(spherical) {\n    var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);\n    return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];\n  }\n  function d3_geo_cartesianDot(a, b) {\n    return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n  }\n  function d3_geo_cartesianCross(a, b) {\n    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] ];\n  }\n  function d3_geo_cartesianAdd(a, b) {\n    a[0] += b[0];\n    a[1] += b[1];\n    a[2] += b[2];\n  }\n  function d3_geo_cartesianScale(vector, k) {\n    return [ vector[0] * k, vector[1] * k, vector[2] * k ];\n  }\n  function d3_geo_cartesianNormalize(d) {\n    var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);\n    d[0] /= l;\n    d[1] /= l;\n    d[2] /= l;\n  }\n  function d3_geo_spherical(cartesian) {\n    return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];\n  }\n  function d3_geo_sphericalEqual(a, b) {\n    return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;\n  }\n  d3.geo.bounds = function() {\n    var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;\n    var bound = {\n      point: point,\n      lineStart: lineStart,\n      lineEnd: lineEnd,\n      polygonStart: function() {\n        bound.point = ringPoint;\n        bound.lineStart = ringStart;\n        bound.lineEnd = ringEnd;\n        dλSum = 0;\n        d3_geo_area.polygonStart();\n      },\n      polygonEnd: function() {\n        d3_geo_area.polygonEnd();\n        bound.point = point;\n        bound.lineStart = lineStart;\n        bound.lineEnd = lineEnd;\n        if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;\n        range[0] = λ0, range[1] = λ1;\n      }\n    };\n    function point(λ, φ) {\n      ranges.push(range = [ λ0 = λ, λ1 = λ ]);\n      if (φ < φ0) φ0 = φ;\n      if (φ > φ1) φ1 = φ;\n    }\n    function linePoint(λ, φ) {\n      var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);\n      if (p0) {\n        var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);\n        d3_geo_cartesianNormalize(inflection);\n        inflection = d3_geo_spherical(inflection);\n        var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;\n        if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {\n          var φi = inflection[1] * d3_degrees;\n          if (φi > φ1) φ1 = φi;\n        } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {\n          var φi = -inflection[1] * d3_degrees;\n          if (φi < φ0) φ0 = φi;\n        } else {\n          if (φ < φ0) φ0 = φ;\n          if (φ > φ1) φ1 = φ;\n        }\n        if (antimeridian) {\n          if (λ < λ_) {\n            if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;\n          } else {\n            if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;\n          }\n        } else {\n          if (λ1 >= λ0) {\n            if (λ < λ0) λ0 = λ;\n            if (λ > λ1) λ1 = λ;\n          } else {\n            if (λ > λ_) {\n              if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;\n            } else {\n              if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;\n            }\n          }\n        }\n      } else {\n        point(λ, φ);\n      }\n      p0 = p, λ_ = λ;\n    }\n    function lineStart() {\n      bound.point = linePoint;\n    }\n    function lineEnd() {\n      range[0] = λ0, range[1] = λ1;\n      bound.point = point;\n      p0 = null;\n    }\n    function ringPoint(λ, φ) {\n      if (p0) {\n        var dλ = λ - λ_;\n        dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;\n      } else λ__ = λ, φ__ = φ;\n      d3_geo_area.point(λ, φ);\n      linePoint(λ, φ);\n    }\n    function ringStart() {\n      d3_geo_area.lineStart();\n    }\n    function ringEnd() {\n      ringPoint(λ__, φ__);\n      d3_geo_area.lineEnd();\n      if (abs(dλSum) > ε) λ0 = -(λ1 = 180);\n      range[0] = λ0, range[1] = λ1;\n      p0 = null;\n    }\n    function angle(λ0, λ1) {\n      return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;\n    }\n    function compareRanges(a, b) {\n      return a[0] - b[0];\n    }\n    function withinRange(x, range) {\n      return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;\n    }\n    return function(feature) {\n      φ1 = λ1 = -(λ0 = φ0 = Infinity);\n      ranges = [];\n      d3.geo.stream(feature, bound);\n      var n = ranges.length;\n      if (n) {\n        ranges.sort(compareRanges);\n        for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {\n          b = ranges[i];\n          if (withinRange(b[0], a) || withinRange(b[1], a)) {\n            if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];\n            if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];\n          } else {\n            merged.push(a = b);\n          }\n        }\n        var best = -Infinity, dλ;\n        for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {\n          b = merged[i];\n          if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];\n        }\n      }\n      ranges = range = null;\n      return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];\n    };\n  }();\n  d3.geo.centroid = function(object) {\n    d3_geo_centroidW0 = d3_geo_centroidW1 = d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;\n    d3.geo.stream(object, d3_geo_centroid);\n    var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;\n    if (m < ε2) {\n      x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;\n      if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;\n      m = x * x + y * y + z * z;\n      if (m < ε2) return [ NaN, NaN ];\n    }\n    return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];\n  };\n  var d3_geo_centroidW0, d3_geo_centroidW1, d3_geo_centroidX0, d3_geo_centroidY0, d3_geo_centroidZ0, d3_geo_centroidX1, d3_geo_centroidY1, d3_geo_centroidZ1, d3_geo_centroidX2, d3_geo_centroidY2, d3_geo_centroidZ2;\n  var d3_geo_centroid = {\n    sphere: d3_noop,\n    point: d3_geo_centroidPoint,\n    lineStart: d3_geo_centroidLineStart,\n    lineEnd: d3_geo_centroidLineEnd,\n    polygonStart: function() {\n      d3_geo_centroid.lineStart = d3_geo_centroidRingStart;\n    },\n    polygonEnd: function() {\n      d3_geo_centroid.lineStart = d3_geo_centroidLineStart;\n    }\n  };\n  function d3_geo_centroidPoint(λ, φ) {\n    λ *= d3_radians;\n    var cosφ = Math.cos(φ *= d3_radians);\n    d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));\n  }\n  function d3_geo_centroidPointXYZ(x, y, z) {\n    ++d3_geo_centroidW0;\n    d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;\n    d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;\n    d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;\n  }\n  function d3_geo_centroidLineStart() {\n    var x0, y0, z0;\n    d3_geo_centroid.point = function(λ, φ) {\n      λ *= d3_radians;\n      var cosφ = Math.cos(φ *= d3_radians);\n      x0 = cosφ * Math.cos(λ);\n      y0 = cosφ * Math.sin(λ);\n      z0 = Math.sin(φ);\n      d3_geo_centroid.point = nextPoint;\n      d3_geo_centroidPointXYZ(x0, y0, z0);\n    };\n    function nextPoint(λ, φ) {\n      λ *= d3_radians;\n      var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), w = Math.atan2(Math.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);\n      d3_geo_centroidW1 += w;\n      d3_geo_centroidX1 += w * (x0 + (x0 = x));\n      d3_geo_centroidY1 += w * (y0 + (y0 = y));\n      d3_geo_centroidZ1 += w * (z0 + (z0 = z));\n      d3_geo_centroidPointXYZ(x0, y0, z0);\n    }\n  }\n  function d3_geo_centroidLineEnd() {\n    d3_geo_centroid.point = d3_geo_centroidPoint;\n  }\n  function d3_geo_centroidRingStart() {\n    var λ00, φ00, x0, y0, z0;\n    d3_geo_centroid.point = function(λ, φ) {\n      λ00 = λ, φ00 = φ;\n      d3_geo_centroid.point = nextPoint;\n      λ *= d3_radians;\n      var cosφ = Math.cos(φ *= d3_radians);\n      x0 = cosφ * Math.cos(λ);\n      y0 = cosφ * Math.sin(λ);\n      z0 = Math.sin(φ);\n      d3_geo_centroidPointXYZ(x0, y0, z0);\n    };\n    d3_geo_centroid.lineEnd = function() {\n      nextPoint(λ00, φ00);\n      d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;\n      d3_geo_centroid.point = d3_geo_centroidPoint;\n    };\n    function nextPoint(λ, φ) {\n      λ *= d3_radians;\n      var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), cx = y0 * z - z0 * y, cy = z0 * x - x0 * z, cz = x0 * y - y0 * x, m = Math.sqrt(cx * cx + cy * cy + cz * cz), u = x0 * x + y0 * y + z0 * z, v = m && -d3_acos(u) / m, w = Math.atan2(m, u);\n      d3_geo_centroidX2 += v * cx;\n      d3_geo_centroidY2 += v * cy;\n      d3_geo_centroidZ2 += v * cz;\n      d3_geo_centroidW1 += w;\n      d3_geo_centroidX1 += w * (x0 + (x0 = x));\n      d3_geo_centroidY1 += w * (y0 + (y0 = y));\n      d3_geo_centroidZ1 += w * (z0 + (z0 = z));\n      d3_geo_centroidPointXYZ(x0, y0, z0);\n    }\n  }\n  function d3_geo_compose(a, b) {\n    function compose(x, y) {\n      return x = a(x, y), b(x[0], x[1]);\n    }\n    if (a.invert && b.invert) compose.invert = function(x, y) {\n      return x = b.invert(x, y), x && a.invert(x[0], x[1]);\n    };\n    return compose;\n  }\n  function d3_true() {\n    return true;\n  }\n  function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {\n    var subject = [], clip = [];\n    segments.forEach(function(segment) {\n      if ((n = segment.length - 1) <= 0) return;\n      var n, p0 = segment[0], p1 = segment[n];\n      if (d3_geo_sphericalEqual(p0, p1)) {\n        listener.lineStart();\n        for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);\n        listener.lineEnd();\n        return;\n      }\n      var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);\n      a.o = b;\n      subject.push(a);\n      clip.push(b);\n      a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);\n      b = new d3_geo_clipPolygonIntersection(p1, null, a, true);\n      a.o = b;\n      subject.push(a);\n      clip.push(b);\n    });\n    clip.sort(compare);\n    d3_geo_clipPolygonLinkCircular(subject);\n    d3_geo_clipPolygonLinkCircular(clip);\n    if (!subject.length) return;\n    for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {\n      clip[i].e = entry = !entry;\n    }\n    var start = subject[0], points, point;\n    while (1) {\n      var current = start, isSubject = true;\n      while (current.v) if ((current = current.n) === start) return;\n      points = current.z;\n      listener.lineStart();\n      do {\n        current.v = current.o.v = true;\n        if (current.e) {\n          if (isSubject) {\n            for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);\n          } else {\n            interpolate(current.x, current.n.x, 1, listener);\n          }\n          current = current.n;\n        } else {\n          if (isSubject) {\n            points = current.p.z;\n            for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);\n          } else {\n            interpolate(current.x, current.p.x, -1, listener);\n          }\n          current = current.p;\n        }\n        current = current.o;\n        points = current.z;\n        isSubject = !isSubject;\n      } while (!current.v);\n      listener.lineEnd();\n    }\n  }\n  function d3_geo_clipPolygonLinkCircular(array) {\n    if (!(n = array.length)) return;\n    var n, i = 0, a = array[0], b;\n    while (++i < n) {\n      a.n = b = array[i];\n      b.p = a;\n      a = b;\n    }\n    a.n = b = array[0];\n    b.p = a;\n  }\n  function d3_geo_clipPolygonIntersection(point, points, other, entry) {\n    this.x = point;\n    this.z = points;\n    this.o = other;\n    this.e = entry;\n    this.v = false;\n    this.n = this.p = null;\n  }\n  function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {\n    return function(rotate, listener) {\n      var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);\n      var clip = {\n        point: point,\n        lineStart: lineStart,\n        lineEnd: lineEnd,\n        polygonStart: function() {\n          clip.point = pointRing;\n          clip.lineStart = ringStart;\n          clip.lineEnd = ringEnd;\n          segments = [];\n          polygon = [];\n        },\n        polygonEnd: function() {\n          clip.point = point;\n          clip.lineStart = lineStart;\n          clip.lineEnd = lineEnd;\n          segments = d3.merge(segments);\n          var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);\n          if (segments.length) {\n            if (!polygonStarted) listener.polygonStart(), polygonStarted = true;\n            d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);\n          } else if (clipStartInside) {\n            if (!polygonStarted) listener.polygonStart(), polygonStarted = true;\n            listener.lineStart();\n            interpolate(null, null, 1, listener);\n            listener.lineEnd();\n          }\n          if (polygonStarted) listener.polygonEnd(), polygonStarted = false;\n          segments = polygon = null;\n        },\n        sphere: function() {\n          listener.polygonStart();\n          listener.lineStart();\n          interpolate(null, null, 1, listener);\n          listener.lineEnd();\n          listener.polygonEnd();\n        }\n      };\n      function point(λ, φ) {\n        var point = rotate(λ, φ);\n        if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);\n      }\n      function pointLine(λ, φ) {\n        var point = rotate(λ, φ);\n        line.point(point[0], point[1]);\n      }\n      function lineStart() {\n        clip.point = pointLine;\n        line.lineStart();\n      }\n      function lineEnd() {\n        clip.point = point;\n        line.lineEnd();\n      }\n      var segments;\n      var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;\n      function pointRing(λ, φ) {\n        ring.push([ λ, φ ]);\n        var point = rotate(λ, φ);\n        ringListener.point(point[0], point[1]);\n      }\n      function ringStart() {\n        ringListener.lineStart();\n        ring = [];\n      }\n      function ringEnd() {\n        pointRing(ring[0][0], ring[0][1]);\n        ringListener.lineEnd();\n        var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;\n        ring.pop();\n        polygon.push(ring);\n        ring = null;\n        if (!n) return;\n        if (clean & 1) {\n          segment = ringSegments[0];\n          var n = segment.length - 1, i = -1, point;\n          if (n > 0) {\n            if (!polygonStarted) listener.polygonStart(), polygonStarted = true;\n            listener.lineStart();\n            while (++i < n) listener.point((point = segment[i])[0], point[1]);\n            listener.lineEnd();\n          }\n          return;\n        }\n        if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));\n        segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));\n      }\n      return clip;\n    };\n  }\n  function d3_geo_clipSegmentLength1(segment) {\n    return segment.length > 1;\n  }\n  function d3_geo_clipBufferListener() {\n    var lines = [], line;\n    return {\n      lineStart: function() {\n        lines.push(line = []);\n      },\n      point: function(λ, φ) {\n        line.push([ λ, φ ]);\n      },\n      lineEnd: d3_noop,\n      buffer: function() {\n        var buffer = lines;\n        lines = [];\n        line = null;\n        return buffer;\n      },\n      rejoin: function() {\n        if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));\n      }\n    };\n  }\n  function d3_geo_clipSort(a, b) {\n    return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);\n  }\n  var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);\n  function d3_geo_clipAntimeridianLine(listener) {\n    var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;\n    return {\n      lineStart: function() {\n        listener.lineStart();\n        clean = 1;\n      },\n      point: function(λ1, φ1) {\n        var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);\n        if (abs(dλ - π) < ε) {\n          listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);\n          listener.point(sλ0, φ0);\n          listener.lineEnd();\n          listener.lineStart();\n          listener.point(sλ1, φ0);\n          listener.point(λ1, φ0);\n          clean = 0;\n        } else if (sλ0 !== sλ1 && dλ >= π) {\n          if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;\n          if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;\n          φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);\n          listener.point(sλ0, φ0);\n          listener.lineEnd();\n          listener.lineStart();\n          listener.point(sλ1, φ0);\n          clean = 0;\n        }\n        listener.point(λ0 = λ1, φ0 = φ1);\n        sλ0 = sλ1;\n      },\n      lineEnd: function() {\n        listener.lineEnd();\n        λ0 = φ0 = NaN;\n      },\n      clean: function() {\n        return 2 - clean;\n      }\n    };\n  }\n  function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {\n    var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);\n    return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;\n  }\n  function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {\n    var φ;\n    if (from == null) {\n      φ = direction * halfπ;\n      listener.point(-π, φ);\n      listener.point(0, φ);\n      listener.point(π, φ);\n      listener.point(π, 0);\n      listener.point(π, -φ);\n      listener.point(0, -φ);\n      listener.point(-π, -φ);\n      listener.point(-π, 0);\n      listener.point(-π, φ);\n    } else if (abs(from[0] - to[0]) > ε) {\n      var s = from[0] < to[0] ? π : -π;\n      φ = direction * s / 2;\n      listener.point(-s, φ);\n      listener.point(0, φ);\n      listener.point(s, φ);\n    } else {\n      listener.point(to[0], to[1]);\n    }\n  }\n  function d3_geo_pointInPolygon(point, polygon) {\n    var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;\n    d3_geo_areaRingSum.reset();\n    for (var i = 0, n = polygon.length; i < n; ++i) {\n      var ring = polygon[i], m = ring.length;\n      if (!m) continue;\n      var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;\n      while (true) {\n        if (j === m) j = 0;\n        point = ring[j];\n        var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;\n        d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));\n        polarAngle += antimeridian ? dλ + sdλ * τ : dλ;\n        if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {\n          var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));\n          d3_geo_cartesianNormalize(arc);\n          var intersection = d3_geo_cartesianCross(meridianNormal, arc);\n          d3_geo_cartesianNormalize(intersection);\n          var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);\n          if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {\n            winding += antimeridian ^ dλ >= 0 ? 1 : -1;\n          }\n        }\n        if (!j++) break;\n        λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;\n      }\n    }\n    return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < -ε) ^ winding & 1;\n  }\n  function d3_geo_clipCircle(radius) {\n    var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);\n    return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);\n    function visible(λ, φ) {\n      return Math.cos(λ) * Math.cos(φ) > cr;\n    }\n    function clipLine(listener) {\n      var point0, c0, v0, v00, clean;\n      return {\n        lineStart: function() {\n          v00 = v0 = false;\n          clean = 1;\n        },\n        point: function(λ, φ) {\n          var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;\n          if (!point0 && (v00 = v0 = v)) listener.lineStart();\n          if (v !== v0) {\n            point2 = intersect(point0, point1);\n            if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {\n              point1[0] += ε;\n              point1[1] += ε;\n              v = visible(point1[0], point1[1]);\n            }\n          }\n          if (v !== v0) {\n            clean = 0;\n            if (v) {\n              listener.lineStart();\n              point2 = intersect(point1, point0);\n              listener.point(point2[0], point2[1]);\n            } else {\n              point2 = intersect(point0, point1);\n              listener.point(point2[0], point2[1]);\n              listener.lineEnd();\n            }\n            point0 = point2;\n          } else if (notHemisphere && point0 && smallRadius ^ v) {\n            var t;\n            if (!(c & c0) && (t = intersect(point1, point0, true))) {\n              clean = 0;\n              if (smallRadius) {\n                listener.lineStart();\n                listener.point(t[0][0], t[0][1]);\n                listener.point(t[1][0], t[1][1]);\n                listener.lineEnd();\n              } else {\n                listener.point(t[1][0], t[1][1]);\n                listener.lineEnd();\n                listener.lineStart();\n                listener.point(t[0][0], t[0][1]);\n              }\n            }\n          }\n          if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {\n            listener.point(point1[0], point1[1]);\n          }\n          point0 = point1, v0 = v, c0 = c;\n        },\n        lineEnd: function() {\n          if (v0) listener.lineEnd();\n          point0 = null;\n        },\n        clean: function() {\n          return clean | (v00 && v0) << 1;\n        }\n      };\n    }\n    function intersect(a, b, two) {\n      var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);\n      var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;\n      if (!determinant) return !two && a;\n      var c1 = cr * n2n2 / determinant, c2 = -cr * n1n2 / determinant, n1xn2 = d3_geo_cartesianCross(n1, n2), A = d3_geo_cartesianScale(n1, c1), B = d3_geo_cartesianScale(n2, c2);\n      d3_geo_cartesianAdd(A, B);\n      var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t2 = w * w - uu * (d3_geo_cartesianDot(A, A) - 1);\n      if (t2 < 0) return;\n      var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);\n      d3_geo_cartesianAdd(q, A);\n      q = d3_geo_spherical(q);\n      if (!two) return q;\n      var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;\n      if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;\n      var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;\n      if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;\n      if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {\n        var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);\n        d3_geo_cartesianAdd(q1, A);\n        return [ q, d3_geo_spherical(q1) ];\n      }\n    }\n    function code(λ, φ) {\n      var r = smallRadius ? radius : π - radius, code = 0;\n      if (λ < -r) code |= 1; else if (λ > r) code |= 2;\n      if (φ < -r) code |= 4; else if (φ > r) code |= 8;\n      return code;\n    }\n  }\n  function d3_geom_clipLine(x0, y0, x1, y1) {\n    return function(line) {\n      var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;\n      r = x0 - ax;\n      if (!dx && r > 0) return;\n      r /= dx;\n      if (dx < 0) {\n        if (r < t0) return;\n        if (r < t1) t1 = r;\n      } else if (dx > 0) {\n        if (r > t1) return;\n        if (r > t0) t0 = r;\n      }\n      r = x1 - ax;\n      if (!dx && r < 0) return;\n      r /= dx;\n      if (dx < 0) {\n        if (r > t1) return;\n        if (r > t0) t0 = r;\n      } else if (dx > 0) {\n        if (r < t0) return;\n        if (r < t1) t1 = r;\n      }\n      r = y0 - ay;\n      if (!dy && r > 0) return;\n      r /= dy;\n      if (dy < 0) {\n        if (r < t0) return;\n        if (r < t1) t1 = r;\n      } else if (dy > 0) {\n        if (r > t1) return;\n        if (r > t0) t0 = r;\n      }\n      r = y1 - ay;\n      if (!dy && r < 0) return;\n      r /= dy;\n      if (dy < 0) {\n        if (r > t1) return;\n        if (r > t0) t0 = r;\n      } else if (dy > 0) {\n        if (r < t0) return;\n        if (r < t1) t1 = r;\n      }\n      if (t0 > 0) line.a = {\n        x: ax + t0 * dx,\n        y: ay + t0 * dy\n      };\n      if (t1 < 1) line.b = {\n        x: ax + t1 * dx,\n        y: ay + t1 * dy\n      };\n      return line;\n    };\n  }\n  var d3_geo_clipExtentMAX = 1e9;\n  d3.geo.clipExtent = function() {\n    var x0, y0, x1, y1, stream, clip, clipExtent = {\n      stream: function(output) {\n        if (stream) stream.valid = false;\n        stream = clip(output);\n        stream.valid = true;\n        return stream;\n      },\n      extent: function(_) {\n        if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];\n        clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);\n        if (stream) stream.valid = false, stream = null;\n        return clipExtent;\n      }\n    };\n    return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);\n  };\n  function d3_geo_clipExtent(x0, y0, x1, y1) {\n    return function(listener) {\n      var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;\n      var clip = {\n        point: point,\n        lineStart: lineStart,\n        lineEnd: lineEnd,\n        polygonStart: function() {\n          listener = bufferListener;\n          segments = [];\n          polygon = [];\n          clean = true;\n        },\n        polygonEnd: function() {\n          listener = listener_;\n          segments = d3.merge(segments);\n          var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;\n          if (inside || visible) {\n            listener.polygonStart();\n            if (inside) {\n              listener.lineStart();\n              interpolate(null, null, 1, listener);\n              listener.lineEnd();\n            }\n            if (visible) {\n              d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);\n            }\n            listener.polygonEnd();\n          }\n          segments = polygon = ring = null;\n        }\n      };\n      function insidePolygon(p) {\n        var wn = 0, n = polygon.length, y = p[1];\n        for (var i = 0; i < n; ++i) {\n          for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {\n            b = v[j];\n            if (a[1] <= y) {\n              if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;\n            } else {\n              if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;\n            }\n            a = b;\n          }\n        }\n        return wn !== 0;\n      }\n      function interpolate(from, to, direction, listener) {\n        var a = 0, a1 = 0;\n        if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {\n          do {\n            listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);\n          } while ((a = (a + direction + 4) % 4) !== a1);\n        } else {\n          listener.point(to[0], to[1]);\n        }\n      }\n      function pointVisible(x, y) {\n        return x0 <= x && x <= x1 && y0 <= y && y <= y1;\n      }\n      function point(x, y) {\n        if (pointVisible(x, y)) listener.point(x, y);\n      }\n      var x__, y__, v__, x_, y_, v_, first, clean;\n      function lineStart() {\n        clip.point = linePoint;\n        if (polygon) polygon.push(ring = []);\n        first = true;\n        v_ = false;\n        x_ = y_ = NaN;\n      }\n      function lineEnd() {\n        if (segments) {\n          linePoint(x__, y__);\n          if (v__ && v_) bufferListener.rejoin();\n          segments.push(bufferListener.buffer());\n        }\n        clip.point = point;\n        if (v_) listener.lineEnd();\n      }\n      function linePoint(x, y) {\n        x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));\n        y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));\n        var v = pointVisible(x, y);\n        if (polygon) ring.push([ x, y ]);\n        if (first) {\n          x__ = x, y__ = y, v__ = v;\n          first = false;\n          if (v) {\n            listener.lineStart();\n            listener.point(x, y);\n          }\n        } else {\n          if (v && v_) listener.point(x, y); else {\n            var l = {\n              a: {\n                x: x_,\n                y: y_\n              },\n              b: {\n                x: x,\n                y: y\n              }\n            };\n            if (clipLine(l)) {\n              if (!v_) {\n                listener.lineStart();\n                listener.point(l.a.x, l.a.y);\n              }\n              listener.point(l.b.x, l.b.y);\n              if (!v) listener.lineEnd();\n              clean = false;\n            } else if (v) {\n              listener.lineStart();\n              listener.point(x, y);\n              clean = false;\n            }\n          }\n        }\n        x_ = x, y_ = y, v_ = v;\n      }\n      return clip;\n    };\n    function corner(p, direction) {\n      return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;\n    }\n    function compare(a, b) {\n      return comparePoints(a.x, b.x);\n    }\n    function comparePoints(a, b) {\n      var ca = corner(a, 1), cb = corner(b, 1);\n      return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];\n    }\n  }\n  function d3_geo_conic(projectAt) {\n    var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);\n    p.parallels = function(_) {\n      if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];\n      return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);\n    };\n    return p;\n  }\n  function d3_geo_conicEqualArea(φ0, φ1) {\n    var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;\n    function forward(λ, φ) {\n      var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;\n      return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];\n    }\n    forward.invert = function(x, y) {\n      var ρ0_y = ρ0 - y;\n      return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];\n    };\n    return forward;\n  }\n  (d3.geo.conicEqualArea = function() {\n    return d3_geo_conic(d3_geo_conicEqualArea);\n  }).raw = d3_geo_conicEqualArea;\n  d3.geo.albers = function() {\n    return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);\n  };\n  d3.geo.albersUsa = function() {\n    var lower48 = d3.geo.albers();\n    var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);\n    var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);\n    var point, pointStream = {\n      point: function(x, y) {\n        point = [ x, y ];\n      }\n    }, lower48Point, alaskaPoint, hawaiiPoint;\n    function albersUsa(coordinates) {\n      var x = coordinates[0], y = coordinates[1];\n      point = null;\n      (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);\n      return point;\n    }\n    albersUsa.invert = function(coordinates) {\n      var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;\n      return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);\n    };\n    albersUsa.stream = function(stream) {\n      var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);\n      return {\n        point: function(x, y) {\n          lower48Stream.point(x, y);\n          alaskaStream.point(x, y);\n          hawaiiStream.point(x, y);\n        },\n        sphere: function() {\n          lower48Stream.sphere();\n          alaskaStream.sphere();\n          hawaiiStream.sphere();\n        },\n        lineStart: function() {\n          lower48Stream.lineStart();\n          alaskaStream.lineStart();\n          hawaiiStream.lineStart();\n        },\n        lineEnd: function() {\n          lower48Stream.lineEnd();\n          alaskaStream.lineEnd();\n          hawaiiStream.lineEnd();\n        },\n        polygonStart: function() {\n          lower48Stream.polygonStart();\n          alaskaStream.polygonStart();\n          hawaiiStream.polygonStart();\n        },\n        polygonEnd: function() {\n          lower48Stream.polygonEnd();\n          alaskaStream.polygonEnd();\n          hawaiiStream.polygonEnd();\n        }\n      };\n    };\n    albersUsa.precision = function(_) {\n      if (!arguments.length) return lower48.precision();\n      lower48.precision(_);\n      alaska.precision(_);\n      hawaii.precision(_);\n      return albersUsa;\n    };\n    albersUsa.scale = function(_) {\n      if (!arguments.length) return lower48.scale();\n      lower48.scale(_);\n      alaska.scale(_ * .35);\n      hawaii.scale(_);\n      return albersUsa.translate(lower48.translate());\n    };\n    albersUsa.translate = function(_) {\n      if (!arguments.length) return lower48.translate();\n      var k = lower48.scale(), x = +_[0], y = +_[1];\n      lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;\n      alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;\n      hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;\n      return albersUsa;\n    };\n    return albersUsa.scale(1070);\n  };\n  var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {\n    point: d3_noop,\n    lineStart: d3_noop,\n    lineEnd: d3_noop,\n    polygonStart: function() {\n      d3_geo_pathAreaPolygon = 0;\n      d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;\n    },\n    polygonEnd: function() {\n      d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;\n      d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);\n    }\n  };\n  function d3_geo_pathAreaRingStart() {\n    var x00, y00, x0, y0;\n    d3_geo_pathArea.point = function(x, y) {\n      d3_geo_pathArea.point = nextPoint;\n      x00 = x0 = x, y00 = y0 = y;\n    };\n    function nextPoint(x, y) {\n      d3_geo_pathAreaPolygon += y0 * x - x0 * y;\n      x0 = x, y0 = y;\n    }\n    d3_geo_pathArea.lineEnd = function() {\n      nextPoint(x00, y00);\n    };\n  }\n  var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;\n  var d3_geo_pathBounds = {\n    point: d3_geo_pathBoundsPoint,\n    lineStart: d3_noop,\n    lineEnd: d3_noop,\n    polygonStart: d3_noop,\n    polygonEnd: d3_noop\n  };\n  function d3_geo_pathBoundsPoint(x, y) {\n    if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;\n    if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;\n    if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;\n    if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;\n  }\n  function d3_geo_pathBuffer() {\n    var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];\n    var stream = {\n      point: point,\n      lineStart: function() {\n        stream.point = pointLineStart;\n      },\n      lineEnd: lineEnd,\n      polygonStart: function() {\n        stream.lineEnd = lineEndPolygon;\n      },\n      polygonEnd: function() {\n        stream.lineEnd = lineEnd;\n        stream.point = point;\n      },\n      pointRadius: function(_) {\n        pointCircle = d3_geo_pathBufferCircle(_);\n        return stream;\n      },\n      result: function() {\n        if (buffer.length) {\n          var result = buffer.join(\"\");\n          buffer = [];\n          return result;\n        }\n      }\n    };\n    function point(x, y) {\n      buffer.push(\"M\", x, \",\", y, pointCircle);\n    }\n    function pointLineStart(x, y) {\n      buffer.push(\"M\", x, \",\", y);\n      stream.point = pointLine;\n    }\n    function pointLine(x, y) {\n      buffer.push(\"L\", x, \",\", y);\n    }\n    function lineEnd() {\n      stream.point = point;\n    }\n    function lineEndPolygon() {\n      buffer.push(\"Z\");\n    }\n    return stream;\n  }\n  function d3_geo_pathBufferCircle(radius) {\n    return \"m0,\" + radius + \"a\" + radius + \",\" + radius + \" 0 1,1 0,\" + -2 * radius + \"a\" + radius + \",\" + radius + \" 0 1,1 0,\" + 2 * radius + \"z\";\n  }\n  var d3_geo_pathCentroid = {\n    point: d3_geo_pathCentroidPoint,\n    lineStart: d3_geo_pathCentroidLineStart,\n    lineEnd: d3_geo_pathCentroidLineEnd,\n    polygonStart: function() {\n      d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;\n    },\n    polygonEnd: function() {\n      d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;\n      d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;\n      d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;\n    }\n  };\n  function d3_geo_pathCentroidPoint(x, y) {\n    d3_geo_centroidX0 += x;\n    d3_geo_centroidY0 += y;\n    ++d3_geo_centroidZ0;\n  }\n  function d3_geo_pathCentroidLineStart() {\n    var x0, y0;\n    d3_geo_pathCentroid.point = function(x, y) {\n      d3_geo_pathCentroid.point = nextPoint;\n      d3_geo_pathCentroidPoint(x0 = x, y0 = y);\n    };\n    function nextPoint(x, y) {\n      var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);\n      d3_geo_centroidX1 += z * (x0 + x) / 2;\n      d3_geo_centroidY1 += z * (y0 + y) / 2;\n      d3_geo_centroidZ1 += z;\n      d3_geo_pathCentroidPoint(x0 = x, y0 = y);\n    }\n  }\n  function d3_geo_pathCentroidLineEnd() {\n    d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;\n  }\n  function d3_geo_pathCentroidRingStart() {\n    var x00, y00, x0, y0;\n    d3_geo_pathCentroid.point = function(x, y) {\n      d3_geo_pathCentroid.point = nextPoint;\n      d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);\n    };\n    function nextPoint(x, y) {\n      var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);\n      d3_geo_centroidX1 += z * (x0 + x) / 2;\n      d3_geo_centroidY1 += z * (y0 + y) / 2;\n      d3_geo_centroidZ1 += z;\n      z = y0 * x - x0 * y;\n      d3_geo_centroidX2 += z * (x0 + x);\n      d3_geo_centroidY2 += z * (y0 + y);\n      d3_geo_centroidZ2 += z * 3;\n      d3_geo_pathCentroidPoint(x0 = x, y0 = y);\n    }\n    d3_geo_pathCentroid.lineEnd = function() {\n      nextPoint(x00, y00);\n    };\n  }\n  function d3_geo_pathContext(context) {\n    var pointRadius = 4.5;\n    var stream = {\n      point: point,\n      lineStart: function() {\n        stream.point = pointLineStart;\n      },\n      lineEnd: lineEnd,\n      polygonStart: function() {\n        stream.lineEnd = lineEndPolygon;\n      },\n      polygonEnd: function() {\n        stream.lineEnd = lineEnd;\n        stream.point = point;\n      },\n      pointRadius: function(_) {\n        pointRadius = _;\n        return stream;\n      },\n      result: d3_noop\n    };\n    function point(x, y) {\n      context.moveTo(x + pointRadius, y);\n      context.arc(x, y, pointRadius, 0, τ);\n    }\n    function pointLineStart(x, y) {\n      context.moveTo(x, y);\n      stream.point = pointLine;\n    }\n    function pointLine(x, y) {\n      context.lineTo(x, y);\n    }\n    function lineEnd() {\n      stream.point = point;\n    }\n    function lineEndPolygon() {\n      context.closePath();\n    }\n    return stream;\n  }\n  function d3_geo_resample(project) {\n    var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;\n    function resample(stream) {\n      return (maxDepth ? resampleRecursive : resampleNone)(stream);\n    }\n    function resampleNone(stream) {\n      return d3_geo_transformPoint(stream, function(x, y) {\n        x = project(x, y);\n        stream.point(x[0], x[1]);\n      });\n    }\n    function resampleRecursive(stream) {\n      var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;\n      var resample = {\n        point: point,\n        lineStart: lineStart,\n        lineEnd: lineEnd,\n        polygonStart: function() {\n          stream.polygonStart();\n          resample.lineStart = ringStart;\n        },\n        polygonEnd: function() {\n          stream.polygonEnd();\n          resample.lineStart = lineStart;\n        }\n      };\n      function point(x, y) {\n        x = project(x, y);\n        stream.point(x[0], x[1]);\n      }\n      function lineStart() {\n        x0 = NaN;\n        resample.point = linePoint;\n        stream.lineStart();\n      }\n      function linePoint(λ, φ) {\n        var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);\n        resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);\n        stream.point(x0, y0);\n      }\n      function lineEnd() {\n        resample.point = point;\n        stream.lineEnd();\n      }\n      function ringStart() {\n        lineStart();\n        resample.point = ringPoint;\n        resample.lineEnd = ringEnd;\n      }\n      function ringPoint(λ, φ) {\n        linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;\n        resample.point = linePoint;\n      }\n      function ringEnd() {\n        resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);\n        resample.lineEnd = lineEnd;\n        lineEnd();\n      }\n      return resample;\n    }\n    function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {\n      var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;\n      if (d2 > 4 * δ2 && depth--) {\n        var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε || abs(λ0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;\n        if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {\n          resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);\n          stream.point(x2, y2);\n          resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);\n        }\n      }\n    }\n    resample.precision = function(_) {\n      if (!arguments.length) return Math.sqrt(δ2);\n      maxDepth = (δ2 = _ * _) > 0 && 16;\n      return resample;\n    };\n    return resample;\n  }\n  d3.geo.path = function() {\n    var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;\n    function path(object) {\n      if (object) {\n        if (typeof pointRadius === \"function\") contextStream.pointRadius(+pointRadius.apply(this, arguments));\n        if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);\n        d3.geo.stream(object, cacheStream);\n      }\n      return contextStream.result();\n    }\n    path.area = function(object) {\n      d3_geo_pathAreaSum = 0;\n      d3.geo.stream(object, projectStream(d3_geo_pathArea));\n      return d3_geo_pathAreaSum;\n    };\n    path.centroid = function(object) {\n      d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;\n      d3.geo.stream(object, projectStream(d3_geo_pathCentroid));\n      return d3_geo_centroidZ2 ? [ d3_geo_centroidX2 / d3_geo_centroidZ2, d3_geo_centroidY2 / d3_geo_centroidZ2 ] : d3_geo_centroidZ1 ? [ d3_geo_centroidX1 / d3_geo_centroidZ1, d3_geo_centroidY1 / d3_geo_centroidZ1 ] : d3_geo_centroidZ0 ? [ d3_geo_centroidX0 / d3_geo_centroidZ0, d3_geo_centroidY0 / d3_geo_centroidZ0 ] : [ NaN, NaN ];\n    };\n    path.bounds = function(object) {\n      d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);\n      d3.geo.stream(object, projectStream(d3_geo_pathBounds));\n      return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];\n    };\n    path.projection = function(_) {\n      if (!arguments.length) return projection;\n      projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;\n      return reset();\n    };\n    path.context = function(_) {\n      if (!arguments.length) return context;\n      contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);\n      if (typeof pointRadius !== \"function\") contextStream.pointRadius(pointRadius);\n      return reset();\n    };\n    path.pointRadius = function(_) {\n      if (!arguments.length) return pointRadius;\n      pointRadius = typeof _ === \"function\" ? _ : (contextStream.pointRadius(+_), +_);\n      return path;\n    };\n    function reset() {\n      cacheStream = null;\n      return path;\n    }\n    return path.projection(d3.geo.albersUsa()).context(null);\n  };\n  function d3_geo_pathProjectStream(project) {\n    var resample = d3_geo_resample(function(x, y) {\n      return project([ x * d3_degrees, y * d3_degrees ]);\n    });\n    return function(stream) {\n      return d3_geo_projectionRadians(resample(stream));\n    };\n  }\n  d3.geo.transform = function(methods) {\n    return {\n      stream: function(stream) {\n        var transform = new d3_geo_transform(stream);\n        for (var k in methods) transform[k] = methods[k];\n        return transform;\n      }\n    };\n  };\n  function d3_geo_transform(stream) {\n    this.stream = stream;\n  }\n  d3_geo_transform.prototype = {\n    point: function(x, y) {\n      this.stream.point(x, y);\n    },\n    sphere: function() {\n      this.stream.sphere();\n    },\n    lineStart: function() {\n      this.stream.lineStart();\n    },\n    lineEnd: function() {\n      this.stream.lineEnd();\n    },\n    polygonStart: function() {\n      this.stream.polygonStart();\n    },\n    polygonEnd: function() {\n      this.stream.polygonEnd();\n    }\n  };\n  function d3_geo_transformPoint(stream, point) {\n    return {\n      point: point,\n      sphere: function() {\n        stream.sphere();\n      },\n      lineStart: function() {\n        stream.lineStart();\n      },\n      lineEnd: function() {\n        stream.lineEnd();\n      },\n      polygonStart: function() {\n        stream.polygonStart();\n      },\n      polygonEnd: function() {\n        stream.polygonEnd();\n      }\n    };\n  }\n  d3.geo.projection = d3_geo_projection;\n  d3.geo.projectionMutator = d3_geo_projectionMutator;\n  function d3_geo_projection(project) {\n    return d3_geo_projectionMutator(function() {\n      return project;\n    })();\n  }\n  function d3_geo_projectionMutator(projectAt) {\n    var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {\n      x = project(x, y);\n      return [ x[0] * k + δx, δy - x[1] * k ];\n    }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null, stream;\n    function projection(point) {\n      point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);\n      return [ point[0] * k + δx, δy - point[1] * k ];\n    }\n    function invert(point) {\n      point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);\n      return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];\n    }\n    projection.stream = function(output) {\n      if (stream) stream.valid = false;\n      stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));\n      stream.valid = true;\n      return stream;\n    };\n    projection.clipAngle = function(_) {\n      if (!arguments.length) return clipAngle;\n      preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);\n      return invalidate();\n    };\n    projection.clipExtent = function(_) {\n      if (!arguments.length) return clipExtent;\n      clipExtent = _;\n      postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;\n      return invalidate();\n    };\n    projection.scale = function(_) {\n      if (!arguments.length) return k;\n      k = +_;\n      return reset();\n    };\n    projection.translate = function(_) {\n      if (!arguments.length) return [ x, y ];\n      x = +_[0];\n      y = +_[1];\n      return reset();\n    };\n    projection.center = function(_) {\n      if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];\n      λ = _[0] % 360 * d3_radians;\n      φ = _[1] % 360 * d3_radians;\n      return reset();\n    };\n    projection.rotate = function(_) {\n      if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];\n      δλ = _[0] % 360 * d3_radians;\n      δφ = _[1] % 360 * d3_radians;\n      δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;\n      return reset();\n    };\n    d3.rebind(projection, projectResample, \"precision\");\n    function reset() {\n      projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);\n      var center = project(λ, φ);\n      δx = x - center[0] * k;\n      δy = y + center[1] * k;\n      return invalidate();\n    }\n    function invalidate() {\n      if (stream) stream.valid = false, stream = null;\n      return projection;\n    }\n    return function() {\n      project = projectAt.apply(this, arguments);\n      projection.invert = project.invert && invert;\n      return reset();\n    };\n  }\n  function d3_geo_projectionRadians(stream) {\n    return d3_geo_transformPoint(stream, function(x, y) {\n      stream.point(x * d3_radians, y * d3_radians);\n    });\n  }\n  function d3_geo_equirectangular(λ, φ) {\n    return [ λ, φ ];\n  }\n  (d3.geo.equirectangular = function() {\n    return d3_geo_projection(d3_geo_equirectangular);\n  }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;\n  d3.geo.rotation = function(rotate) {\n    rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);\n    function forward(coordinates) {\n      coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);\n      return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;\n    }\n    forward.invert = function(coordinates) {\n      coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);\n      return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;\n    };\n    return forward;\n  };\n  function d3_geo_identityRotation(λ, φ) {\n    return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];\n  }\n  d3_geo_identityRotation.invert = d3_geo_equirectangular;\n  function d3_geo_rotation(δλ, δφ, δγ) {\n    return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;\n  }\n  function d3_geo_forwardRotationλ(δλ) {\n    return function(λ, φ) {\n      return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];\n    };\n  }\n  function d3_geo_rotationλ(δλ) {\n    var rotation = d3_geo_forwardRotationλ(δλ);\n    rotation.invert = d3_geo_forwardRotationλ(-δλ);\n    return rotation;\n  }\n  function d3_geo_rotationφγ(δφ, δγ) {\n    var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);\n    function rotation(λ, φ) {\n      var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;\n      return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];\n    }\n    rotation.invert = function(λ, φ) {\n      var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;\n      return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];\n    };\n    return rotation;\n  }\n  d3.geo.circle = function() {\n    var origin = [ 0, 0 ], angle, precision = 6, interpolate;\n    function circle() {\n      var center = typeof origin === \"function\" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];\n      interpolate(null, null, 1, {\n        point: function(x, y) {\n          ring.push(x = rotate(x, y));\n          x[0] *= d3_degrees, x[1] *= d3_degrees;\n        }\n      });\n      return {\n        type: \"Polygon\",\n        coordinates: [ ring ]\n      };\n    }\n    circle.origin = function(x) {\n      if (!arguments.length) return origin;\n      origin = x;\n      return circle;\n    };\n    circle.angle = function(x) {\n      if (!arguments.length) return angle;\n      interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);\n      return circle;\n    };\n    circle.precision = function(_) {\n      if (!arguments.length) return precision;\n      interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);\n      return circle;\n    };\n    return circle.angle(90);\n  };\n  function d3_geo_circleInterpolate(radius, precision) {\n    var cr = Math.cos(radius), sr = Math.sin(radius);\n    return function(from, to, direction, listener) {\n      var step = direction * precision;\n      if (from != null) {\n        from = d3_geo_circleAngle(cr, from);\n        to = d3_geo_circleAngle(cr, to);\n        if (direction > 0 ? from < to : from > to) from += direction * τ;\n      } else {\n        from = radius + direction * τ;\n        to = radius - .5 * step;\n      }\n      for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {\n        listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);\n      }\n    };\n  }\n  function d3_geo_circleAngle(cr, point) {\n    var a = d3_geo_cartesian(point);\n    a[0] -= cr;\n    d3_geo_cartesianNormalize(a);\n    var angle = d3_acos(-a[1]);\n    return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);\n  }\n  d3.geo.distance = function(a, b) {\n    var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;\n    return Math.atan2(Math.sqrt((t = cosφ1 * sinΔλ) * t + (t = cosφ0 * sinφ1 - sinφ0 * cosφ1 * cosΔλ) * t), sinφ0 * sinφ1 + cosφ0 * cosφ1 * cosΔλ);\n  };\n  d3.geo.graticule = function() {\n    var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;\n    function graticule() {\n      return {\n        type: \"MultiLineString\",\n        coordinates: lines()\n      };\n    }\n    function lines() {\n      return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {\n        return abs(x % DX) > ε;\n      }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {\n        return abs(y % DY) > ε;\n      }).map(y));\n    }\n    graticule.lines = function() {\n      return lines().map(function(coordinates) {\n        return {\n          type: \"LineString\",\n          coordinates: coordinates\n        };\n      });\n    };\n    graticule.outline = function() {\n      return {\n        type: \"Polygon\",\n        coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]\n      };\n    };\n    graticule.extent = function(_) {\n      if (!arguments.length) return graticule.minorExtent();\n      return graticule.majorExtent(_).minorExtent(_);\n    };\n    graticule.majorExtent = function(_) {\n      if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];\n      X0 = +_[0][0], X1 = +_[1][0];\n      Y0 = +_[0][1], Y1 = +_[1][1];\n      if (X0 > X1) _ = X0, X0 = X1, X1 = _;\n      if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;\n      return graticule.precision(precision);\n    };\n    graticule.minorExtent = function(_) {\n      if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];\n      x0 = +_[0][0], x1 = +_[1][0];\n      y0 = +_[0][1], y1 = +_[1][1];\n      if (x0 > x1) _ = x0, x0 = x1, x1 = _;\n      if (y0 > y1) _ = y0, y0 = y1, y1 = _;\n      return graticule.precision(precision);\n    };\n    graticule.step = function(_) {\n      if (!arguments.length) return graticule.minorStep();\n      return graticule.majorStep(_).minorStep(_);\n    };\n    graticule.majorStep = function(_) {\n      if (!arguments.length) return [ DX, DY ];\n      DX = +_[0], DY = +_[1];\n      return graticule;\n    };\n    graticule.minorStep = function(_) {\n      if (!arguments.length) return [ dx, dy ];\n      dx = +_[0], dy = +_[1];\n      return graticule;\n    };\n    graticule.precision = function(_) {\n      if (!arguments.length) return precision;\n      precision = +_;\n      x = d3_geo_graticuleX(y0, y1, 90);\n      y = d3_geo_graticuleY(x0, x1, precision);\n      X = d3_geo_graticuleX(Y0, Y1, 90);\n      Y = d3_geo_graticuleY(X0, X1, precision);\n      return graticule;\n    };\n    return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);\n  };\n  function d3_geo_graticuleX(y0, y1, dy) {\n    var y = d3.range(y0, y1 - ε, dy).concat(y1);\n    return function(x) {\n      return y.map(function(y) {\n        return [ x, y ];\n      });\n    };\n  }\n  function d3_geo_graticuleY(x0, x1, dx) {\n    var x = d3.range(x0, x1 - ε, dx).concat(x1);\n    return function(y) {\n      return x.map(function(x) {\n        return [ x, y ];\n      });\n    };\n  }\n  function d3_source(d) {\n    return d.source;\n  }\n  function d3_target(d) {\n    return d.target;\n  }\n  d3.geo.greatArc = function() {\n    var source = d3_source, source_, target = d3_target, target_;\n    function greatArc() {\n      return {\n        type: \"LineString\",\n        coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]\n      };\n    }\n    greatArc.distance = function() {\n      return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));\n    };\n    greatArc.source = function(_) {\n      if (!arguments.length) return source;\n      source = _, source_ = typeof _ === \"function\" ? null : _;\n      return greatArc;\n    };\n    greatArc.target = function(_) {\n      if (!arguments.length) return target;\n      target = _, target_ = typeof _ === \"function\" ? null : _;\n      return greatArc;\n    };\n    greatArc.precision = function() {\n      return arguments.length ? greatArc : 0;\n    };\n    return greatArc;\n  };\n  d3.geo.interpolate = function(source, target) {\n    return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);\n  };\n  function d3_geo_interpolate(x0, y0, x1, y1) {\n    var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = 2 * Math.asin(Math.sqrt(d3_haversin(y1 - y0) + cy0 * cy1 * d3_haversin(x1 - x0))), k = 1 / Math.sin(d);\n    var interpolate = d ? function(t) {\n      var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1;\n      return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];\n    } : function() {\n      return [ x0 * d3_degrees, y0 * d3_degrees ];\n    };\n    interpolate.distance = d;\n    return interpolate;\n  }\n  d3.geo.length = function(object) {\n    d3_geo_lengthSum = 0;\n    d3.geo.stream(object, d3_geo_length);\n    return d3_geo_lengthSum;\n  };\n  var d3_geo_lengthSum;\n  var d3_geo_length = {\n    sphere: d3_noop,\n    point: d3_noop,\n    lineStart: d3_geo_lengthLineStart,\n    lineEnd: d3_noop,\n    polygonStart: d3_noop,\n    polygonEnd: d3_noop\n  };\n  function d3_geo_lengthLineStart() {\n    var λ0, sinφ0, cosφ0;\n    d3_geo_length.point = function(λ, φ) {\n      λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);\n      d3_geo_length.point = nextPoint;\n    };\n    d3_geo_length.lineEnd = function() {\n      d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;\n    };\n    function nextPoint(λ, φ) {\n      var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);\n      d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);\n      λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;\n    }\n  }\n  function d3_geo_azimuthal(scale, angle) {\n    function azimuthal(λ, φ) {\n      var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);\n      return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];\n    }\n    azimuthal.invert = function(x, y) {\n      var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);\n      return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];\n    };\n    return azimuthal;\n  }\n  var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {\n    return Math.sqrt(2 / (1 + cosλcosφ));\n  }, function(ρ) {\n    return 2 * Math.asin(ρ / 2);\n  });\n  (d3.geo.azimuthalEqualArea = function() {\n    return d3_geo_projection(d3_geo_azimuthalEqualArea);\n  }).raw = d3_geo_azimuthalEqualArea;\n  var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {\n    var c = Math.acos(cosλcosφ);\n    return c && c / Math.sin(c);\n  }, d3_identity);\n  (d3.geo.azimuthalEquidistant = function() {\n    return d3_geo_projection(d3_geo_azimuthalEquidistant);\n  }).raw = d3_geo_azimuthalEquidistant;\n  function d3_geo_conicConformal(φ0, φ1) {\n    var cosφ0 = Math.cos(φ0), t = function(φ) {\n      return Math.tan(π / 4 + φ / 2);\n    }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;\n    if (!n) return d3_geo_mercator;\n    function forward(λ, φ) {\n      if (F > 0) {\n        if (φ < -halfπ + ε) φ = -halfπ + ε;\n      } else {\n        if (φ > halfπ - ε) φ = halfπ - ε;\n      }\n      var ρ = F / Math.pow(t(φ), n);\n      return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];\n    }\n    forward.invert = function(x, y) {\n      var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);\n      return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];\n    };\n    return forward;\n  }\n  (d3.geo.conicConformal = function() {\n    return d3_geo_conic(d3_geo_conicConformal);\n  }).raw = d3_geo_conicConformal;\n  function d3_geo_conicEquidistant(φ0, φ1) {\n    var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;\n    if (abs(n) < ε) return d3_geo_equirectangular;\n    function forward(λ, φ) {\n      var ρ = G - φ;\n      return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];\n    }\n    forward.invert = function(x, y) {\n      var ρ0_y = G - y;\n      return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];\n    };\n    return forward;\n  }\n  (d3.geo.conicEquidistant = function() {\n    return d3_geo_conic(d3_geo_conicEquidistant);\n  }).raw = d3_geo_conicEquidistant;\n  var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {\n    return 1 / cosλcosφ;\n  }, Math.atan);\n  (d3.geo.gnomonic = function() {\n    return d3_geo_projection(d3_geo_gnomonic);\n  }).raw = d3_geo_gnomonic;\n  function d3_geo_mercator(λ, φ) {\n    return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];\n  }\n  d3_geo_mercator.invert = function(x, y) {\n    return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];\n  };\n  function d3_geo_mercatorProjection(project) {\n    var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;\n    m.scale = function() {\n      var v = scale.apply(m, arguments);\n      return v === m ? clipAuto ? m.clipExtent(null) : m : v;\n    };\n    m.translate = function() {\n      var v = translate.apply(m, arguments);\n      return v === m ? clipAuto ? m.clipExtent(null) : m : v;\n    };\n    m.clipExtent = function(_) {\n      var v = clipExtent.apply(m, arguments);\n      if (v === m) {\n        if (clipAuto = _ == null) {\n          var k = π * scale(), t = translate();\n          clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);\n        }\n      } else if (clipAuto) {\n        v = null;\n      }\n      return v;\n    };\n    return m.clipExtent(null);\n  }\n  (d3.geo.mercator = function() {\n    return d3_geo_mercatorProjection(d3_geo_mercator);\n  }).raw = d3_geo_mercator;\n  var d3_geo_orthographic = d3_geo_azimuthal(function() {\n    return 1;\n  }, Math.asin);\n  (d3.geo.orthographic = function() {\n    return d3_geo_projection(d3_geo_orthographic);\n  }).raw = d3_geo_orthographic;\n  var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {\n    return 1 / (1 + cosλcosφ);\n  }, function(ρ) {\n    return 2 * Math.atan(ρ);\n  });\n  (d3.geo.stereographic = function() {\n    return d3_geo_projection(d3_geo_stereographic);\n  }).raw = d3_geo_stereographic;\n  function d3_geo_transverseMercator(λ, φ) {\n    return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];\n  }\n  d3_geo_transverseMercator.invert = function(x, y) {\n    return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];\n  };\n  (d3.geo.transverseMercator = function() {\n    var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;\n    projection.center = function(_) {\n      return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);\n    };\n    projection.rotate = function(_) {\n      return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(), \n      [ _[0], _[1], _[2] - 90 ]);\n    };\n    return rotate([ 0, 0, 90 ]);\n  }).raw = d3_geo_transverseMercator;\n  d3.geom = {};\n  function d3_geom_pointX(d) {\n    return d[0];\n  }\n  function d3_geom_pointY(d) {\n    return d[1];\n  }\n  d3.geom.hull = function(vertices) {\n    var x = d3_geom_pointX, y = d3_geom_pointY;\n    if (arguments.length) return hull(vertices);\n    function hull(data) {\n      if (data.length < 3) return [];\n      var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];\n      for (i = 0; i < n; i++) {\n        points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);\n      }\n      points.sort(d3_geom_hullOrder);\n      for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);\n      var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);\n      var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];\n      for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);\n      for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);\n      return polygon;\n    }\n    hull.x = function(_) {\n      return arguments.length ? (x = _, hull) : x;\n    };\n    hull.y = function(_) {\n      return arguments.length ? (y = _, hull) : y;\n    };\n    return hull;\n  };\n  function d3_geom_hullUpper(points) {\n    var n = points.length, hull = [ 0, 1 ], hs = 2;\n    for (var i = 2; i < n; i++) {\n      while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;\n      hull[hs++] = i;\n    }\n    return hull.slice(0, hs);\n  }\n  function d3_geom_hullOrder(a, b) {\n    return a[0] - b[0] || a[1] - b[1];\n  }\n  d3.geom.polygon = function(coordinates) {\n    d3_subclass(coordinates, d3_geom_polygonPrototype);\n    return coordinates;\n  };\n  var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];\n  d3_geom_polygonPrototype.area = function() {\n    var i = -1, n = this.length, a, b = this[n - 1], area = 0;\n    while (++i < n) {\n      a = b;\n      b = this[i];\n      area += a[1] * b[0] - a[0] * b[1];\n    }\n    return area * .5;\n  };\n  d3_geom_polygonPrototype.centroid = function(k) {\n    var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;\n    if (!arguments.length) k = -1 / (6 * this.area());\n    while (++i < n) {\n      a = b;\n      b = this[i];\n      c = a[0] * b[1] - b[0] * a[1];\n      x += (a[0] + b[0]) * c;\n      y += (a[1] + b[1]) * c;\n    }\n    return [ x * k, y * k ];\n  };\n  d3_geom_polygonPrototype.clip = function(subject) {\n    var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;\n    while (++i < n) {\n      input = subject.slice();\n      subject.length = 0;\n      b = this[i];\n      c = input[(m = input.length - closed) - 1];\n      j = -1;\n      while (++j < m) {\n        d = input[j];\n        if (d3_geom_polygonInside(d, a, b)) {\n          if (!d3_geom_polygonInside(c, a, b)) {\n            subject.push(d3_geom_polygonIntersect(c, d, a, b));\n          }\n          subject.push(d);\n        } else if (d3_geom_polygonInside(c, a, b)) {\n          subject.push(d3_geom_polygonIntersect(c, d, a, b));\n        }\n        c = d;\n      }\n      if (closed) subject.push(subject[0]);\n      a = b;\n    }\n    return subject;\n  };\n  function d3_geom_polygonInside(p, a, b) {\n    return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);\n  }\n  function d3_geom_polygonIntersect(c, d, a, b) {\n    var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21);\n    return [ x1 + ua * x21, y1 + ua * y21 ];\n  }\n  function d3_geom_polygonClosed(coordinates) {\n    var a = coordinates[0], b = coordinates[coordinates.length - 1];\n    return !(a[0] - b[0] || a[1] - b[1]);\n  }\n  var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];\n  function d3_geom_voronoiBeach() {\n    d3_geom_voronoiRedBlackNode(this);\n    this.edge = this.site = this.circle = null;\n  }\n  function d3_geom_voronoiCreateBeach(site) {\n    var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();\n    beach.site = site;\n    return beach;\n  }\n  function d3_geom_voronoiDetachBeach(beach) {\n    d3_geom_voronoiDetachCircle(beach);\n    d3_geom_voronoiBeaches.remove(beach);\n    d3_geom_voronoiBeachPool.push(beach);\n    d3_geom_voronoiRedBlackNode(beach);\n  }\n  function d3_geom_voronoiRemoveBeach(beach) {\n    var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {\n      x: x,\n      y: y\n    }, previous = beach.P, next = beach.N, disappearing = [ beach ];\n    d3_geom_voronoiDetachBeach(beach);\n    var lArc = previous;\n    while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {\n      previous = lArc.P;\n      disappearing.unshift(lArc);\n      d3_geom_voronoiDetachBeach(lArc);\n      lArc = previous;\n    }\n    disappearing.unshift(lArc);\n    d3_geom_voronoiDetachCircle(lArc);\n    var rArc = next;\n    while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {\n      next = rArc.N;\n      disappearing.push(rArc);\n      d3_geom_voronoiDetachBeach(rArc);\n      rArc = next;\n    }\n    disappearing.push(rArc);\n    d3_geom_voronoiDetachCircle(rArc);\n    var nArcs = disappearing.length, iArc;\n    for (iArc = 1; iArc < nArcs; ++iArc) {\n      rArc = disappearing[iArc];\n      lArc = disappearing[iArc - 1];\n      d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);\n    }\n    lArc = disappearing[0];\n    rArc = disappearing[nArcs - 1];\n    rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);\n    d3_geom_voronoiAttachCircle(lArc);\n    d3_geom_voronoiAttachCircle(rArc);\n  }\n  function d3_geom_voronoiAddBeach(site) {\n    var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;\n    while (node) {\n      dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;\n      if (dxl > ε) node = node.L; else {\n        dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);\n        if (dxr > ε) {\n          if (!node.R) {\n            lArc = node;\n            break;\n          }\n          node = node.R;\n        } else {\n          if (dxl > -ε) {\n            lArc = node.P;\n            rArc = node;\n          } else if (dxr > -ε) {\n            lArc = node;\n            rArc = node.N;\n          } else {\n            lArc = rArc = node;\n          }\n          break;\n        }\n      }\n    }\n    var newArc = d3_geom_voronoiCreateBeach(site);\n    d3_geom_voronoiBeaches.insert(lArc, newArc);\n    if (!lArc && !rArc) return;\n    if (lArc === rArc) {\n      d3_geom_voronoiDetachCircle(lArc);\n      rArc = d3_geom_voronoiCreateBeach(lArc.site);\n      d3_geom_voronoiBeaches.insert(newArc, rArc);\n      newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);\n      d3_geom_voronoiAttachCircle(lArc);\n      d3_geom_voronoiAttachCircle(rArc);\n      return;\n    }\n    if (!rArc) {\n      newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);\n      return;\n    }\n    d3_geom_voronoiDetachCircle(lArc);\n    d3_geom_voronoiDetachCircle(rArc);\n    var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {\n      x: (cy * hb - by * hc) / d + ax,\n      y: (bx * hc - cx * hb) / d + ay\n    };\n    d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);\n    newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);\n    rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);\n    d3_geom_voronoiAttachCircle(lArc);\n    d3_geom_voronoiAttachCircle(rArc);\n  }\n  function d3_geom_voronoiLeftBreakPoint(arc, directrix) {\n    var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;\n    if (!pby2) return rfocx;\n    var lArc = arc.P;\n    if (!lArc) return -Infinity;\n    site = lArc.site;\n    var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;\n    if (!plby2) return lfocx;\n    var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;\n    if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;\n    return (rfocx + lfocx) / 2;\n  }\n  function d3_geom_voronoiRightBreakPoint(arc, directrix) {\n    var rArc = arc.N;\n    if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);\n    var site = arc.site;\n    return site.y === directrix ? site.x : Infinity;\n  }\n  function d3_geom_voronoiCell(site) {\n    this.site = site;\n    this.edges = [];\n  }\n  d3_geom_voronoiCell.prototype.prepare = function() {\n    var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;\n    while (iHalfEdge--) {\n      edge = halfEdges[iHalfEdge].edge;\n      if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);\n    }\n    halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);\n    return halfEdges.length;\n  };\n  function d3_geom_voronoiCloseCells(extent) {\n    var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;\n    while (iCell--) {\n      cell = cells[iCell];\n      if (!cell || !cell.prepare()) continue;\n      halfEdges = cell.edges;\n      nHalfEdges = halfEdges.length;\n      iHalfEdge = 0;\n      while (iHalfEdge < nHalfEdges) {\n        end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;\n        start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;\n        if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {\n          halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {\n            x: x0,\n            y: abs(x2 - x0) < ε ? y2 : y1\n          } : abs(y3 - y1) < ε && x1 - x3 > ε ? {\n            x: abs(y2 - y1) < ε ? x2 : x1,\n            y: y1\n          } : abs(x3 - x1) < ε && y3 - y0 > ε ? {\n            x: x1,\n            y: abs(x2 - x1) < ε ? y2 : y0\n          } : abs(y3 - y0) < ε && x3 - x0 > ε ? {\n            x: abs(y2 - y0) < ε ? x2 : x0,\n            y: y0\n          } : null), cell.site, null));\n          ++nHalfEdges;\n        }\n      }\n    }\n  }\n  function d3_geom_voronoiHalfEdgeOrder(a, b) {\n    return b.angle - a.angle;\n  }\n  function d3_geom_voronoiCircle() {\n    d3_geom_voronoiRedBlackNode(this);\n    this.x = this.y = this.arc = this.site = this.cy = null;\n  }\n  function d3_geom_voronoiAttachCircle(arc) {\n    var lArc = arc.P, rArc = arc.N;\n    if (!lArc || !rArc) return;\n    var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;\n    if (lSite === rSite) return;\n    var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;\n    var d = 2 * (ax * cy - ay * cx);\n    if (d >= -ε2) return;\n    var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;\n    var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();\n    circle.arc = arc;\n    circle.site = cSite;\n    circle.x = x + bx;\n    circle.y = cy + Math.sqrt(x * x + y * y);\n    circle.cy = cy;\n    arc.circle = circle;\n    var before = null, node = d3_geom_voronoiCircles._;\n    while (node) {\n      if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {\n        if (node.L) node = node.L; else {\n          before = node.P;\n          break;\n        }\n      } else {\n        if (node.R) node = node.R; else {\n          before = node;\n          break;\n        }\n      }\n    }\n    d3_geom_voronoiCircles.insert(before, circle);\n    if (!before) d3_geom_voronoiFirstCircle = circle;\n  }\n  function d3_geom_voronoiDetachCircle(arc) {\n    var circle = arc.circle;\n    if (circle) {\n      if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;\n      d3_geom_voronoiCircles.remove(circle);\n      d3_geom_voronoiCirclePool.push(circle);\n      d3_geom_voronoiRedBlackNode(circle);\n      arc.circle = null;\n    }\n  }\n  function d3_geom_voronoiClipEdges(extent) {\n    var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;\n    while (i--) {\n      e = edges[i];\n      if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {\n        e.a = e.b = null;\n        edges.splice(i, 1);\n      }\n    }\n  }\n  function d3_geom_voronoiConnectEdge(edge, extent) {\n    var vb = edge.b;\n    if (vb) return true;\n    var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;\n    if (ry === ly) {\n      if (fx < x0 || fx >= x1) return;\n      if (lx > rx) {\n        if (!va) va = {\n          x: fx,\n          y: y0\n        }; else if (va.y >= y1) return;\n        vb = {\n          x: fx,\n          y: y1\n        };\n      } else {\n        if (!va) va = {\n          x: fx,\n          y: y1\n        }; else if (va.y < y0) return;\n        vb = {\n          x: fx,\n          y: y0\n        };\n      }\n    } else {\n      fm = (lx - rx) / (ry - ly);\n      fb = fy - fm * fx;\n      if (fm < -1 || fm > 1) {\n        if (lx > rx) {\n          if (!va) va = {\n            x: (y0 - fb) / fm,\n            y: y0\n          }; else if (va.y >= y1) return;\n          vb = {\n            x: (y1 - fb) / fm,\n            y: y1\n          };\n        } else {\n          if (!va) va = {\n            x: (y1 - fb) / fm,\n            y: y1\n          }; else if (va.y < y0) return;\n          vb = {\n            x: (y0 - fb) / fm,\n            y: y0\n          };\n        }\n      } else {\n        if (ly < ry) {\n          if (!va) va = {\n            x: x0,\n            y: fm * x0 + fb\n          }; else if (va.x >= x1) return;\n          vb = {\n            x: x1,\n            y: fm * x1 + fb\n          };\n        } else {\n          if (!va) va = {\n            x: x1,\n            y: fm * x1 + fb\n          }; else if (va.x < x0) return;\n          vb = {\n            x: x0,\n            y: fm * x0 + fb\n          };\n        }\n      }\n    }\n    edge.a = va;\n    edge.b = vb;\n    return true;\n  }\n  function d3_geom_voronoiEdge(lSite, rSite) {\n    this.l = lSite;\n    this.r = rSite;\n    this.a = this.b = null;\n  }\n  function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {\n    var edge = new d3_geom_voronoiEdge(lSite, rSite);\n    d3_geom_voronoiEdges.push(edge);\n    if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);\n    if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);\n    d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));\n    d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));\n    return edge;\n  }\n  function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {\n    var edge = new d3_geom_voronoiEdge(lSite, null);\n    edge.a = va;\n    edge.b = vb;\n    d3_geom_voronoiEdges.push(edge);\n    return edge;\n  }\n  function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {\n    if (!edge.a && !edge.b) {\n      edge.a = vertex;\n      edge.l = lSite;\n      edge.r = rSite;\n    } else if (edge.l === rSite) {\n      edge.b = vertex;\n    } else {\n      edge.a = vertex;\n    }\n  }\n  function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {\n    var va = edge.a, vb = edge.b;\n    this.edge = edge;\n    this.site = lSite;\n    this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);\n  }\n  d3_geom_voronoiHalfEdge.prototype = {\n    start: function() {\n      return this.edge.l === this.site ? this.edge.a : this.edge.b;\n    },\n    end: function() {\n      return this.edge.l === this.site ? this.edge.b : this.edge.a;\n    }\n  };\n  function d3_geom_voronoiRedBlackTree() {\n    this._ = null;\n  }\n  function d3_geom_voronoiRedBlackNode(node) {\n    node.U = node.C = node.L = node.R = node.P = node.N = null;\n  }\n  d3_geom_voronoiRedBlackTree.prototype = {\n    insert: function(after, node) {\n      var parent, grandpa, uncle;\n      if (after) {\n        node.P = after;\n        node.N = after.N;\n        if (after.N) after.N.P = node;\n        after.N = node;\n        if (after.R) {\n          after = after.R;\n          while (after.L) after = after.L;\n          after.L = node;\n        } else {\n          after.R = node;\n        }\n        parent = after;\n      } else if (this._) {\n        after = d3_geom_voronoiRedBlackFirst(this._);\n        node.P = null;\n        node.N = after;\n        after.P = after.L = node;\n        parent = after;\n      } else {\n        node.P = node.N = null;\n        this._ = node;\n        parent = null;\n      }\n      node.L = node.R = null;\n      node.U = parent;\n      node.C = true;\n      after = node;\n      while (parent && parent.C) {\n        grandpa = parent.U;\n        if (parent === grandpa.L) {\n          uncle = grandpa.R;\n          if (uncle && uncle.C) {\n            parent.C = uncle.C = false;\n            grandpa.C = true;\n            after = grandpa;\n          } else {\n            if (after === parent.R) {\n              d3_geom_voronoiRedBlackRotateLeft(this, parent);\n              after = parent;\n              parent = after.U;\n            }\n            parent.C = false;\n            grandpa.C = true;\n            d3_geom_voronoiRedBlackRotateRight(this, grandpa);\n          }\n        } else {\n          uncle = grandpa.L;\n          if (uncle && uncle.C) {\n            parent.C = uncle.C = false;\n            grandpa.C = true;\n            after = grandpa;\n          } else {\n            if (after === parent.L) {\n              d3_geom_voronoiRedBlackRotateRight(this, parent);\n              after = parent;\n              parent = after.U;\n            }\n            parent.C = false;\n            grandpa.C = true;\n            d3_geom_voronoiRedBlackRotateLeft(this, grandpa);\n          }\n        }\n        parent = after.U;\n      }\n      this._.C = false;\n    },\n    remove: function(node) {\n      if (node.N) node.N.P = node.P;\n      if (node.P) node.P.N = node.N;\n      node.N = node.P = null;\n      var parent = node.U, sibling, left = node.L, right = node.R, next, red;\n      if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);\n      if (parent) {\n        if (parent.L === node) parent.L = next; else parent.R = next;\n      } else {\n        this._ = next;\n      }\n      if (left && right) {\n        red = next.C;\n        next.C = node.C;\n        next.L = left;\n        left.U = next;\n        if (next !== right) {\n          parent = next.U;\n          next.U = node.U;\n          node = next.R;\n          parent.L = node;\n          next.R = right;\n          right.U = next;\n        } else {\n          next.U = parent;\n          parent = next;\n          node = next.R;\n        }\n      } else {\n        red = node.C;\n        node = next;\n      }\n      if (node) node.U = parent;\n      if (red) return;\n      if (node && node.C) {\n        node.C = false;\n        return;\n      }\n      do {\n        if (node === this._) break;\n        if (node === parent.L) {\n          sibling = parent.R;\n          if (sibling.C) {\n            sibling.C = false;\n            parent.C = true;\n            d3_geom_voronoiRedBlackRotateLeft(this, parent);\n            sibling = parent.R;\n          }\n          if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {\n            if (!sibling.R || !sibling.R.C) {\n              sibling.L.C = false;\n              sibling.C = true;\n              d3_geom_voronoiRedBlackRotateRight(this, sibling);\n              sibling = parent.R;\n            }\n            sibling.C = parent.C;\n            parent.C = sibling.R.C = false;\n            d3_geom_voronoiRedBlackRotateLeft(this, parent);\n            node = this._;\n            break;\n          }\n        } else {\n          sibling = parent.L;\n          if (sibling.C) {\n            sibling.C = false;\n            parent.C = true;\n            d3_geom_voronoiRedBlackRotateRight(this, parent);\n            sibling = parent.L;\n          }\n          if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {\n            if (!sibling.L || !sibling.L.C) {\n              sibling.R.C = false;\n              sibling.C = true;\n              d3_geom_voronoiRedBlackRotateLeft(this, sibling);\n              sibling = parent.L;\n            }\n            sibling.C = parent.C;\n            parent.C = sibling.L.C = false;\n            d3_geom_voronoiRedBlackRotateRight(this, parent);\n            node = this._;\n            break;\n          }\n        }\n        sibling.C = true;\n        node = parent;\n        parent = parent.U;\n      } while (!node.C);\n      if (node) node.C = false;\n    }\n  };\n  function d3_geom_voronoiRedBlackRotateLeft(tree, node) {\n    var p = node, q = node.R, parent = p.U;\n    if (parent) {\n      if (parent.L === p) parent.L = q; else parent.R = q;\n    } else {\n      tree._ = q;\n    }\n    q.U = parent;\n    p.U = q;\n    p.R = q.L;\n    if (p.R) p.R.U = p;\n    q.L = p;\n  }\n  function d3_geom_voronoiRedBlackRotateRight(tree, node) {\n    var p = node, q = node.L, parent = p.U;\n    if (parent) {\n      if (parent.L === p) parent.L = q; else parent.R = q;\n    } else {\n      tree._ = q;\n    }\n    q.U = parent;\n    p.U = q;\n    p.L = q.R;\n    if (p.L) p.L.U = p;\n    q.R = p;\n  }\n  function d3_geom_voronoiRedBlackFirst(node) {\n    while (node.L) node = node.L;\n    return node;\n  }\n  function d3_geom_voronoi(sites, bbox) {\n    var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;\n    d3_geom_voronoiEdges = [];\n    d3_geom_voronoiCells = new Array(sites.length);\n    d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();\n    d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();\n    while (true) {\n      circle = d3_geom_voronoiFirstCircle;\n      if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {\n        if (site.x !== x0 || site.y !== y0) {\n          d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);\n          d3_geom_voronoiAddBeach(site);\n          x0 = site.x, y0 = site.y;\n        }\n        site = sites.pop();\n      } else if (circle) {\n        d3_geom_voronoiRemoveBeach(circle.arc);\n      } else {\n        break;\n      }\n    }\n    if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);\n    var diagram = {\n      cells: d3_geom_voronoiCells,\n      edges: d3_geom_voronoiEdges\n    };\n    d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;\n    return diagram;\n  }\n  function d3_geom_voronoiVertexOrder(a, b) {\n    return b.y - a.y || b.x - a.x;\n  }\n  d3.geom.voronoi = function(points) {\n    var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;\n    if (points) return voronoi(points);\n    function voronoi(data) {\n      var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];\n      d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {\n        var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {\n          var s = e.start();\n          return [ s.x, s.y ];\n        }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];\n        polygon.point = data[i];\n      });\n      return polygons;\n    }\n    function sites(data) {\n      return data.map(function(d, i) {\n        return {\n          x: Math.round(fx(d, i) / ε) * ε,\n          y: Math.round(fy(d, i) / ε) * ε,\n          i: i\n        };\n      });\n    }\n    voronoi.links = function(data) {\n      return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {\n        return edge.l && edge.r;\n      }).map(function(edge) {\n        return {\n          source: data[edge.l.i],\n          target: data[edge.r.i]\n        };\n      });\n    };\n    voronoi.triangles = function(data) {\n      var triangles = [];\n      d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {\n        var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;\n        while (++j < m) {\n          e0 = e1;\n          s0 = s1;\n          e1 = edges[j].edge;\n          s1 = e1.l === site ? e1.r : e1.l;\n          if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {\n            triangles.push([ data[i], data[s0.i], data[s1.i] ]);\n          }\n        }\n      });\n      return triangles;\n    };\n    voronoi.x = function(_) {\n      return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;\n    };\n    voronoi.y = function(_) {\n      return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;\n    };\n    voronoi.clipExtent = function(_) {\n      if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;\n      clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;\n      return voronoi;\n    };\n    voronoi.size = function(_) {\n      if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];\n      return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);\n    };\n    return voronoi;\n  };\n  var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];\n  function d3_geom_voronoiTriangleArea(a, b, c) {\n    return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);\n  }\n  d3.geom.delaunay = function(vertices) {\n    return d3.geom.voronoi().triangles(vertices);\n  };\n  d3.geom.quadtree = function(points, x1, y1, x2, y2) {\n    var x = d3_geom_pointX, y = d3_geom_pointY, compat;\n    if (compat = arguments.length) {\n      x = d3_geom_quadtreeCompatX;\n      y = d3_geom_quadtreeCompatY;\n      if (compat === 3) {\n        y2 = y1;\n        x2 = x1;\n        y1 = x1 = 0;\n      }\n      return quadtree(points);\n    }\n    function quadtree(data) {\n      var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;\n      if (x1 != null) {\n        x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;\n      } else {\n        x2_ = y2_ = -(x1_ = y1_ = Infinity);\n        xs = [], ys = [];\n        n = data.length;\n        if (compat) for (i = 0; i < n; ++i) {\n          d = data[i];\n          if (d.x < x1_) x1_ = d.x;\n          if (d.y < y1_) y1_ = d.y;\n          if (d.x > x2_) x2_ = d.x;\n          if (d.y > y2_) y2_ = d.y;\n          xs.push(d.x);\n          ys.push(d.y);\n        } else for (i = 0; i < n; ++i) {\n          var x_ = +fx(d = data[i], i), y_ = +fy(d, i);\n          if (x_ < x1_) x1_ = x_;\n          if (y_ < y1_) y1_ = y_;\n          if (x_ > x2_) x2_ = x_;\n          if (y_ > y2_) y2_ = y_;\n          xs.push(x_);\n          ys.push(y_);\n        }\n      }\n      var dx = x2_ - x1_, dy = y2_ - y1_;\n      if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;\n      function insert(n, d, x, y, x1, y1, x2, y2) {\n        if (isNaN(x) || isNaN(y)) return;\n        if (n.leaf) {\n          var nx = n.x, ny = n.y;\n          if (nx != null) {\n            if (abs(nx - x) + abs(ny - y) < .01) {\n              insertChild(n, d, x, y, x1, y1, x2, y2);\n            } else {\n              var nPoint = n.point;\n              n.x = n.y = n.point = null;\n              insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);\n              insertChild(n, d, x, y, x1, y1, x2, y2);\n            }\n          } else {\n            n.x = x, n.y = y, n.point = d;\n          }\n        } else {\n          insertChild(n, d, x, y, x1, y1, x2, y2);\n        }\n      }\n      function insertChild(n, d, x, y, x1, y1, x2, y2) {\n        var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;\n        n.leaf = false;\n        n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());\n        if (right) x1 = xm; else x2 = xm;\n        if (below) y1 = ym; else y2 = ym;\n        insert(n, d, x, y, x1, y1, x2, y2);\n      }\n      var root = d3_geom_quadtreeNode();\n      root.add = function(d) {\n        insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);\n      };\n      root.visit = function(f) {\n        d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);\n      };\n      root.find = function(point) {\n        return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);\n      };\n      i = -1;\n      if (x1 == null) {\n        while (++i < n) {\n          insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);\n        }\n        --i;\n      } else data.forEach(root.add);\n      xs = ys = data = d = null;\n      return root;\n    }\n    quadtree.x = function(_) {\n      return arguments.length ? (x = _, quadtree) : x;\n    };\n    quadtree.y = function(_) {\n      return arguments.length ? (y = _, quadtree) : y;\n    };\n    quadtree.extent = function(_) {\n      if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];\n      if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], \n      y2 = +_[1][1];\n      return quadtree;\n    };\n    quadtree.size = function(_) {\n      if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];\n      if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];\n      return quadtree;\n    };\n    return quadtree;\n  };\n  function d3_geom_quadtreeCompatX(d) {\n    return d.x;\n  }\n  function d3_geom_quadtreeCompatY(d) {\n    return d.y;\n  }\n  function d3_geom_quadtreeNode() {\n    return {\n      leaf: true,\n      nodes: [],\n      point: null,\n      x: null,\n      y: null\n    };\n  }\n  function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {\n    if (!f(node, x1, y1, x2, y2)) {\n      var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;\n      if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);\n      if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);\n      if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);\n      if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);\n    }\n  }\n  function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {\n    var minDistance2 = Infinity, closestPoint;\n    (function find(node, x1, y1, x2, y2) {\n      if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;\n      if (point = node.point) {\n        var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;\n        if (distance2 < minDistance2) {\n          var distance = Math.sqrt(minDistance2 = distance2);\n          x0 = x - distance, y0 = y - distance;\n          x3 = x + distance, y3 = y + distance;\n          closestPoint = point;\n        }\n      }\n      var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;\n      for (var i = below << 1 | right, j = i + 4; i < j; ++i) {\n        if (node = children[i & 3]) switch (i & 3) {\n         case 0:\n          find(node, x1, y1, xm, ym);\n          break;\n\n         case 1:\n          find(node, xm, y1, x2, ym);\n          break;\n\n         case 2:\n          find(node, x1, ym, xm, y2);\n          break;\n\n         case 3:\n          find(node, xm, ym, x2, y2);\n          break;\n        }\n      }\n    })(root, x0, y0, x3, y3);\n    return closestPoint;\n  }\n  d3.interpolateRgb = d3_interpolateRgb;\n  function d3_interpolateRgb(a, b) {\n    a = d3.rgb(a);\n    b = d3.rgb(b);\n    var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;\n    return function(t) {\n      return \"#\" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t));\n    };\n  }\n  d3.interpolateObject = d3_interpolateObject;\n  function d3_interpolateObject(a, b) {\n    var i = {}, c = {}, k;\n    for (k in a) {\n      if (k in b) {\n        i[k] = d3_interpolate(a[k], b[k]);\n      } else {\n        c[k] = a[k];\n      }\n    }\n    for (k in b) {\n      if (!(k in a)) {\n        c[k] = b[k];\n      }\n    }\n    return function(t) {\n      for (k in i) c[k] = i[k](t);\n      return c;\n    };\n  }\n  d3.interpolateNumber = d3_interpolateNumber;\n  function d3_interpolateNumber(a, b) {\n    a = +a, b = +b;\n    return function(t) {\n      return a * (1 - t) + b * t;\n    };\n  }\n  d3.interpolateString = d3_interpolateString;\n  function d3_interpolateString(a, b) {\n    var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];\n    a = a + \"\", b = b + \"\";\n    while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {\n      if ((bs = bm.index) > bi) {\n        bs = b.slice(bi, bs);\n        if (s[i]) s[i] += bs; else s[++i] = bs;\n      }\n      if ((am = am[0]) === (bm = bm[0])) {\n        if (s[i]) s[i] += bm; else s[++i] = bm;\n      } else {\n        s[++i] = null;\n        q.push({\n          i: i,\n          x: d3_interpolateNumber(am, bm)\n        });\n      }\n      bi = d3_interpolate_numberB.lastIndex;\n    }\n    if (bi < b.length) {\n      bs = b.slice(bi);\n      if (s[i]) s[i] += bs; else s[++i] = bs;\n    }\n    return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {\n      return b(t) + \"\";\n    }) : function() {\n      return b;\n    } : (b = q.length, function(t) {\n      for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);\n      return s.join(\"\");\n    });\n  }\n  var d3_interpolate_numberA = /[-+]?(?:\\d+\\.?\\d*|\\.?\\d+)(?:[eE][-+]?\\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, \"g\");\n  d3.interpolate = d3_interpolate;\n  function d3_interpolate(a, b) {\n    var i = d3.interpolators.length, f;\n    while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;\n    return f;\n  }\n  d3.interpolators = [ function(a, b) {\n    var t = typeof b;\n    return (t === \"string\" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\\(|hsl\\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === \"object\" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);\n  } ];\n  d3.interpolateArray = d3_interpolateArray;\n  function d3_interpolateArray(a, b) {\n    var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;\n    for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));\n    for (;i < na; ++i) c[i] = a[i];\n    for (;i < nb; ++i) c[i] = b[i];\n    return function(t) {\n      for (i = 0; i < n0; ++i) c[i] = x[i](t);\n      return c;\n    };\n  }\n  var d3_ease_default = function() {\n    return d3_identity;\n  };\n  var d3_ease = d3.map({\n    linear: d3_ease_default,\n    poly: d3_ease_poly,\n    quad: function() {\n      return d3_ease_quad;\n    },\n    cubic: function() {\n      return d3_ease_cubic;\n    },\n    sin: function() {\n      return d3_ease_sin;\n    },\n    exp: function() {\n      return d3_ease_exp;\n    },\n    circle: function() {\n      return d3_ease_circle;\n    },\n    elastic: d3_ease_elastic,\n    back: d3_ease_back,\n    bounce: function() {\n      return d3_ease_bounce;\n    }\n  });\n  var d3_ease_mode = d3.map({\n    \"in\": d3_identity,\n    out: d3_ease_reverse,\n    \"in-out\": d3_ease_reflect,\n    \"out-in\": function(f) {\n      return d3_ease_reflect(d3_ease_reverse(f));\n    }\n  });\n  d3.ease = function(name) {\n    var i = name.indexOf(\"-\"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : \"in\";\n    t = d3_ease.get(t) || d3_ease_default;\n    m = d3_ease_mode.get(m) || d3_identity;\n    return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));\n  };\n  function d3_ease_clamp(f) {\n    return function(t) {\n      return t <= 0 ? 0 : t >= 1 ? 1 : f(t);\n    };\n  }\n  function d3_ease_reverse(f) {\n    return function(t) {\n      return 1 - f(1 - t);\n    };\n  }\n  function d3_ease_reflect(f) {\n    return function(t) {\n      return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));\n    };\n  }\n  function d3_ease_quad(t) {\n    return t * t;\n  }\n  function d3_ease_cubic(t) {\n    return t * t * t;\n  }\n  function d3_ease_cubicInOut(t) {\n    if (t <= 0) return 0;\n    if (t >= 1) return 1;\n    var t2 = t * t, t3 = t2 * t;\n    return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);\n  }\n  function d3_ease_poly(e) {\n    return function(t) {\n      return Math.pow(t, e);\n    };\n  }\n  function d3_ease_sin(t) {\n    return 1 - Math.cos(t * halfπ);\n  }\n  function d3_ease_exp(t) {\n    return Math.pow(2, 10 * (t - 1));\n  }\n  function d3_ease_circle(t) {\n    return 1 - Math.sqrt(1 - t * t);\n  }\n  function d3_ease_elastic(a, p) {\n    var s;\n    if (arguments.length < 2) p = .45;\n    if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;\n    return function(t) {\n      return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);\n    };\n  }\n  function d3_ease_back(s) {\n    if (!s) s = 1.70158;\n    return function(t) {\n      return t * t * ((s + 1) * t - s);\n    };\n  }\n  function d3_ease_bounce(t) {\n    return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;\n  }\n  d3.interpolateHcl = d3_interpolateHcl;\n  function d3_interpolateHcl(a, b) {\n    a = d3.hcl(a);\n    b = d3.hcl(b);\n    var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;\n    if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;\n    if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;\n    return function(t) {\n      return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + \"\";\n    };\n  }\n  d3.interpolateHsl = d3_interpolateHsl;\n  function d3_interpolateHsl(a, b) {\n    a = d3.hsl(a);\n    b = d3.hsl(b);\n    var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;\n    if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;\n    if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;\n    return function(t) {\n      return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + \"\";\n    };\n  }\n  d3.interpolateLab = d3_interpolateLab;\n  function d3_interpolateLab(a, b) {\n    a = d3.lab(a);\n    b = d3.lab(b);\n    var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;\n    return function(t) {\n      return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + \"\";\n    };\n  }\n  d3.interpolateRound = d3_interpolateRound;\n  function d3_interpolateRound(a, b) {\n    b -= a;\n    return function(t) {\n      return Math.round(a + b * t);\n    };\n  }\n  d3.transform = function(string) {\n    var g = d3_document.createElementNS(d3.ns.prefix.svg, \"g\");\n    return (d3.transform = function(string) {\n      if (string != null) {\n        g.setAttribute(\"transform\", string);\n        var t = g.transform.baseVal.consolidate();\n      }\n      return new d3_transform(t ? t.matrix : d3_transformIdentity);\n    })(string);\n  };\n  function d3_transform(m) {\n    var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;\n    if (r0[0] * r1[1] < r1[0] * r0[1]) {\n      r0[0] *= -1;\n      r0[1] *= -1;\n      kx *= -1;\n      kz *= -1;\n    }\n    this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;\n    this.translate = [ m.e, m.f ];\n    this.scale = [ kx, ky ];\n    this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;\n  }\n  d3_transform.prototype.toString = function() {\n    return \"translate(\" + this.translate + \")rotate(\" + this.rotate + \")skewX(\" + this.skew + \")scale(\" + this.scale + \")\";\n  };\n  function d3_transformDot(a, b) {\n    return a[0] * b[0] + a[1] * b[1];\n  }\n  function d3_transformNormalize(a) {\n    var k = Math.sqrt(d3_transformDot(a, a));\n    if (k) {\n      a[0] /= k;\n      a[1] /= k;\n    }\n    return k;\n  }\n  function d3_transformCombine(a, b, k) {\n    a[0] += k * b[0];\n    a[1] += k * b[1];\n    return a;\n  }\n  var d3_transformIdentity = {\n    a: 1,\n    b: 0,\n    c: 0,\n    d: 1,\n    e: 0,\n    f: 0\n  };\n  d3.interpolateTransform = d3_interpolateTransform;\n  function d3_interpolateTransformPop(s) {\n    return s.length ? s.pop() + \",\" : \"\";\n  }\n  function d3_interpolateTranslate(ta, tb, s, q) {\n    if (ta[0] !== tb[0] || ta[1] !== tb[1]) {\n      var i = s.push(\"translate(\", null, \",\", null, \")\");\n      q.push({\n        i: i - 4,\n        x: d3_interpolateNumber(ta[0], tb[0])\n      }, {\n        i: i - 2,\n        x: d3_interpolateNumber(ta[1], tb[1])\n      });\n    } else if (tb[0] || tb[1]) {\n      s.push(\"translate(\" + tb + \")\");\n    }\n  }\n  function d3_interpolateRotate(ra, rb, s, q) {\n    if (ra !== rb) {\n      if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;\n      q.push({\n        i: s.push(d3_interpolateTransformPop(s) + \"rotate(\", null, \")\") - 2,\n        x: d3_interpolateNumber(ra, rb)\n      });\n    } else if (rb) {\n      s.push(d3_interpolateTransformPop(s) + \"rotate(\" + rb + \")\");\n    }\n  }\n  function d3_interpolateSkew(wa, wb, s, q) {\n    if (wa !== wb) {\n      q.push({\n        i: s.push(d3_interpolateTransformPop(s) + \"skewX(\", null, \")\") - 2,\n        x: d3_interpolateNumber(wa, wb)\n      });\n    } else if (wb) {\n      s.push(d3_interpolateTransformPop(s) + \"skewX(\" + wb + \")\");\n    }\n  }\n  function d3_interpolateScale(ka, kb, s, q) {\n    if (ka[0] !== kb[0] || ka[1] !== kb[1]) {\n      var i = s.push(d3_interpolateTransformPop(s) + \"scale(\", null, \",\", null, \")\");\n      q.push({\n        i: i - 4,\n        x: d3_interpolateNumber(ka[0], kb[0])\n      }, {\n        i: i - 2,\n        x: d3_interpolateNumber(ka[1], kb[1])\n      });\n    } else if (kb[0] !== 1 || kb[1] !== 1) {\n      s.push(d3_interpolateTransformPop(s) + \"scale(\" + kb + \")\");\n    }\n  }\n  function d3_interpolateTransform(a, b) {\n    var s = [], q = [];\n    a = d3.transform(a), b = d3.transform(b);\n    d3_interpolateTranslate(a.translate, b.translate, s, q);\n    d3_interpolateRotate(a.rotate, b.rotate, s, q);\n    d3_interpolateSkew(a.skew, b.skew, s, q);\n    d3_interpolateScale(a.scale, b.scale, s, q);\n    a = b = null;\n    return function(t) {\n      var i = -1, n = q.length, o;\n      while (++i < n) s[(o = q[i]).i] = o.x(t);\n      return s.join(\"\");\n    };\n  }\n  function d3_uninterpolateNumber(a, b) {\n    b = (b -= a = +a) || 1 / b;\n    return function(x) {\n      return (x - a) / b;\n    };\n  }\n  function d3_uninterpolateClamp(a, b) {\n    b = (b -= a = +a) || 1 / b;\n    return function(x) {\n      return Math.max(0, Math.min(1, (x - a) / b));\n    };\n  }\n  d3.layout = {};\n  d3.layout.bundle = function() {\n    return function(links) {\n      var paths = [], i = -1, n = links.length;\n      while (++i < n) paths.push(d3_layout_bundlePath(links[i]));\n      return paths;\n    };\n  };\n  function d3_layout_bundlePath(link) {\n    var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];\n    while (start !== lca) {\n      start = start.parent;\n      points.push(start);\n    }\n    var k = points.length;\n    while (end !== lca) {\n      points.splice(k, 0, end);\n      end = end.parent;\n    }\n    return points;\n  }\n  function d3_layout_bundleAncestors(node) {\n    var ancestors = [], parent = node.parent;\n    while (parent != null) {\n      ancestors.push(node);\n      node = parent;\n      parent = parent.parent;\n    }\n    ancestors.push(node);\n    return ancestors;\n  }\n  function d3_layout_bundleLeastCommonAncestor(a, b) {\n    if (a === b) return a;\n    var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;\n    while (aNode === bNode) {\n      sharedNode = aNode;\n      aNode = aNodes.pop();\n      bNode = bNodes.pop();\n    }\n    return sharedNode;\n  }\n  d3.layout.chord = function() {\n    var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;\n    function relayout() {\n      var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;\n      chords = [];\n      groups = [];\n      k = 0, i = -1;\n      while (++i < n) {\n        x = 0, j = -1;\n        while (++j < n) {\n          x += matrix[i][j];\n        }\n        groupSums.push(x);\n        subgroupIndex.push(d3.range(n));\n        k += x;\n      }\n      if (sortGroups) {\n        groupIndex.sort(function(a, b) {\n          return sortGroups(groupSums[a], groupSums[b]);\n        });\n      }\n      if (sortSubgroups) {\n        subgroupIndex.forEach(function(d, i) {\n          d.sort(function(a, b) {\n            return sortSubgroups(matrix[i][a], matrix[i][b]);\n          });\n        });\n      }\n      k = (τ - padding * n) / k;\n      x = 0, i = -1;\n      while (++i < n) {\n        x0 = x, j = -1;\n        while (++j < n) {\n          var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;\n          subgroups[di + \"-\" + dj] = {\n            index: di,\n            subindex: dj,\n            startAngle: a0,\n            endAngle: a1,\n            value: v\n          };\n        }\n        groups[di] = {\n          index: di,\n          startAngle: x0,\n          endAngle: x,\n          value: groupSums[di]\n        };\n        x += padding;\n      }\n      i = -1;\n      while (++i < n) {\n        j = i - 1;\n        while (++j < n) {\n          var source = subgroups[i + \"-\" + j], target = subgroups[j + \"-\" + i];\n          if (source.value || target.value) {\n            chords.push(source.value < target.value ? {\n              source: target,\n              target: source\n            } : {\n              source: source,\n              target: target\n            });\n          }\n        }\n      }\n      if (sortChords) resort();\n    }\n    function resort() {\n      chords.sort(function(a, b) {\n        return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);\n      });\n    }\n    chord.matrix = function(x) {\n      if (!arguments.length) return matrix;\n      n = (matrix = x) && matrix.length;\n      chords = groups = null;\n      return chord;\n    };\n    chord.padding = function(x) {\n      if (!arguments.length) return padding;\n      padding = x;\n      chords = groups = null;\n      return chord;\n    };\n    chord.sortGroups = function(x) {\n      if (!arguments.length) return sortGroups;\n      sortGroups = x;\n      chords = groups = null;\n      return chord;\n    };\n    chord.sortSubgroups = function(x) {\n      if (!arguments.length) return sortSubgroups;\n      sortSubgroups = x;\n      chords = null;\n      return chord;\n    };\n    chord.sortChords = function(x) {\n      if (!arguments.length) return sortChords;\n      sortChords = x;\n      if (chords) resort();\n      return chord;\n    };\n    chord.chords = function() {\n      if (!chords) relayout();\n      return chords;\n    };\n    chord.groups = function() {\n      if (!groups) relayout();\n      return groups;\n    };\n    return chord;\n  };\n  d3.layout.force = function() {\n    var force = {}, event = d3.dispatch(\"start\", \"tick\", \"end\"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;\n    function repulse(node) {\n      return function(quad, x1, _, x2) {\n        if (quad.point !== node) {\n          var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;\n          if (dw * dw / theta2 < dn) {\n            if (dn < chargeDistance2) {\n              var k = quad.charge / dn;\n              node.px -= dx * k;\n              node.py -= dy * k;\n            }\n            return true;\n          }\n          if (quad.point && dn && dn < chargeDistance2) {\n            var k = quad.pointCharge / dn;\n            node.px -= dx * k;\n            node.py -= dy * k;\n          }\n        }\n        return !quad.charge;\n      };\n    }\n    force.tick = function() {\n      if ((alpha *= .99) < .005) {\n        timer = null;\n        event.end({\n          type: \"end\",\n          alpha: alpha = 0\n        });\n        return true;\n      }\n      var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;\n      for (i = 0; i < m; ++i) {\n        o = links[i];\n        s = o.source;\n        t = o.target;\n        x = t.x - s.x;\n        y = t.y - s.y;\n        if (l = x * x + y * y) {\n          l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;\n          x *= l;\n          y *= l;\n          t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);\n          t.y -= y * k;\n          s.x += x * (k = 1 - k);\n          s.y += y * k;\n        }\n      }\n      if (k = alpha * gravity) {\n        x = size[0] / 2;\n        y = size[1] / 2;\n        i = -1;\n        if (k) while (++i < n) {\n          o = nodes[i];\n          o.x += (x - o.x) * k;\n          o.y += (y - o.y) * k;\n        }\n      }\n      if (charge) {\n        d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);\n        i = -1;\n        while (++i < n) {\n          if (!(o = nodes[i]).fixed) {\n            q.visit(repulse(o));\n          }\n        }\n      }\n      i = -1;\n      while (++i < n) {\n        o = nodes[i];\n        if (o.fixed) {\n          o.x = o.px;\n          o.y = o.py;\n        } else {\n          o.x -= (o.px - (o.px = o.x)) * friction;\n          o.y -= (o.py - (o.py = o.y)) * friction;\n        }\n      }\n      event.tick({\n        type: \"tick\",\n        alpha: alpha\n      });\n    };\n    force.nodes = function(x) {\n      if (!arguments.length) return nodes;\n      nodes = x;\n      return force;\n    };\n    force.links = function(x) {\n      if (!arguments.length) return links;\n      links = x;\n      return force;\n    };\n    force.size = function(x) {\n      if (!arguments.length) return size;\n      size = x;\n      return force;\n    };\n    force.linkDistance = function(x) {\n      if (!arguments.length) return linkDistance;\n      linkDistance = typeof x === \"function\" ? x : +x;\n      return force;\n    };\n    force.distance = force.linkDistance;\n    force.linkStrength = function(x) {\n      if (!arguments.length) return linkStrength;\n      linkStrength = typeof x === \"function\" ? x : +x;\n      return force;\n    };\n    force.friction = function(x) {\n      if (!arguments.length) return friction;\n      friction = +x;\n      return force;\n    };\n    force.charge = function(x) {\n      if (!arguments.length) return charge;\n      charge = typeof x === \"function\" ? x : +x;\n      return force;\n    };\n    force.chargeDistance = function(x) {\n      if (!arguments.length) return Math.sqrt(chargeDistance2);\n      chargeDistance2 = x * x;\n      return force;\n    };\n    force.gravity = function(x) {\n      if (!arguments.length) return gravity;\n      gravity = +x;\n      return force;\n    };\n    force.theta = function(x) {\n      if (!arguments.length) return Math.sqrt(theta2);\n      theta2 = x * x;\n      return force;\n    };\n    force.alpha = function(x) {\n      if (!arguments.length) return alpha;\n      x = +x;\n      if (alpha) {\n        if (x > 0) {\n          alpha = x;\n        } else {\n          timer.c = null, timer.t = NaN, timer = null;\n          event.end({\n            type: \"end\",\n            alpha: alpha = 0\n          });\n        }\n      } else if (x > 0) {\n        event.start({\n          type: \"start\",\n          alpha: alpha = x\n        });\n        timer = d3_timer(force.tick);\n      }\n      return force;\n    };\n    force.start = function() {\n      var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;\n      for (i = 0; i < n; ++i) {\n        (o = nodes[i]).index = i;\n        o.weight = 0;\n      }\n      for (i = 0; i < m; ++i) {\n        o = links[i];\n        if (typeof o.source == \"number\") o.source = nodes[o.source];\n        if (typeof o.target == \"number\") o.target = nodes[o.target];\n        ++o.source.weight;\n        ++o.target.weight;\n      }\n      for (i = 0; i < n; ++i) {\n        o = nodes[i];\n        if (isNaN(o.x)) o.x = position(\"x\", w);\n        if (isNaN(o.y)) o.y = position(\"y\", h);\n        if (isNaN(o.px)) o.px = o.x;\n        if (isNaN(o.py)) o.py = o.y;\n      }\n      distances = [];\n      if (typeof linkDistance === \"function\") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance;\n      strengths = [];\n      if (typeof linkStrength === \"function\") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength;\n      charges = [];\n      if (typeof charge === \"function\") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;\n      function position(dimension, size) {\n        if (!neighbors) {\n          neighbors = new Array(n);\n          for (j = 0; j < n; ++j) {\n            neighbors[j] = [];\n          }\n          for (j = 0; j < m; ++j) {\n            var o = links[j];\n            neighbors[o.source.index].push(o.target);\n            neighbors[o.target.index].push(o.source);\n          }\n        }\n        var candidates = neighbors[i], j = -1, l = candidates.length, x;\n        while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;\n        return Math.random() * size;\n      }\n      return force.resume();\n    };\n    force.resume = function() {\n      return force.alpha(.1);\n    };\n    force.stop = function() {\n      return force.alpha(0);\n    };\n    force.drag = function() {\n      if (!drag) drag = d3.behavior.drag().origin(d3_identity).on(\"dragstart.force\", d3_layout_forceDragstart).on(\"drag.force\", dragmove).on(\"dragend.force\", d3_layout_forceDragend);\n      if (!arguments.length) return drag;\n      this.on(\"mouseover.force\", d3_layout_forceMouseover).on(\"mouseout.force\", d3_layout_forceMouseout).call(drag);\n    };\n    function dragmove(d) {\n      d.px = d3.event.x, d.py = d3.event.y;\n      force.resume();\n    }\n    return d3.rebind(force, event, \"on\");\n  };\n  function d3_layout_forceDragstart(d) {\n    d.fixed |= 2;\n  }\n  function d3_layout_forceDragend(d) {\n    d.fixed &= ~6;\n  }\n  function d3_layout_forceMouseover(d) {\n    d.fixed |= 4;\n    d.px = d.x, d.py = d.y;\n  }\n  function d3_layout_forceMouseout(d) {\n    d.fixed &= ~4;\n  }\n  function d3_layout_forceAccumulate(quad, alpha, charges) {\n    var cx = 0, cy = 0;\n    quad.charge = 0;\n    if (!quad.leaf) {\n      var nodes = quad.nodes, n = nodes.length, i = -1, c;\n      while (++i < n) {\n        c = nodes[i];\n        if (c == null) continue;\n        d3_layout_forceAccumulate(c, alpha, charges);\n        quad.charge += c.charge;\n        cx += c.charge * c.cx;\n        cy += c.charge * c.cy;\n      }\n    }\n    if (quad.point) {\n      if (!quad.leaf) {\n        quad.point.x += Math.random() - .5;\n        quad.point.y += Math.random() - .5;\n      }\n      var k = alpha * charges[quad.point.index];\n      quad.charge += quad.pointCharge = k;\n      cx += k * quad.point.x;\n      cy += k * quad.point.y;\n    }\n    quad.cx = cx / quad.charge;\n    quad.cy = cy / quad.charge;\n  }\n  var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;\n  d3.layout.hierarchy = function() {\n    var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;\n    function hierarchy(root) {\n      var stack = [ root ], nodes = [], node;\n      root.depth = 0;\n      while ((node = stack.pop()) != null) {\n        nodes.push(node);\n        if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {\n          var n, childs, child;\n          while (--n >= 0) {\n            stack.push(child = childs[n]);\n            child.parent = node;\n            child.depth = node.depth + 1;\n          }\n          if (value) node.value = 0;\n          node.children = childs;\n        } else {\n          if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;\n          delete node.children;\n        }\n      }\n      d3_layout_hierarchyVisitAfter(root, function(node) {\n        var childs, parent;\n        if (sort && (childs = node.children)) childs.sort(sort);\n        if (value && (parent = node.parent)) parent.value += node.value;\n      });\n      return nodes;\n    }\n    hierarchy.sort = function(x) {\n      if (!arguments.length) return sort;\n      sort = x;\n      return hierarchy;\n    };\n    hierarchy.children = function(x) {\n      if (!arguments.length) return children;\n      children = x;\n      return hierarchy;\n    };\n    hierarchy.value = function(x) {\n      if (!arguments.length) return value;\n      value = x;\n      return hierarchy;\n    };\n    hierarchy.revalue = function(root) {\n      if (value) {\n        d3_layout_hierarchyVisitBefore(root, function(node) {\n          if (node.children) node.value = 0;\n        });\n        d3_layout_hierarchyVisitAfter(root, function(node) {\n          var parent;\n          if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;\n          if (parent = node.parent) parent.value += node.value;\n        });\n      }\n      return root;\n    };\n    return hierarchy;\n  };\n  function d3_layout_hierarchyRebind(object, hierarchy) {\n    d3.rebind(object, hierarchy, \"sort\", \"children\", \"value\");\n    object.nodes = object;\n    object.links = d3_layout_hierarchyLinks;\n    return object;\n  }\n  function d3_layout_hierarchyVisitBefore(node, callback) {\n    var nodes = [ node ];\n    while ((node = nodes.pop()) != null) {\n      callback(node);\n      if ((children = node.children) && (n = children.length)) {\n        var n, children;\n        while (--n >= 0) nodes.push(children[n]);\n      }\n    }\n  }\n  function d3_layout_hierarchyVisitAfter(node, callback) {\n    var nodes = [ node ], nodes2 = [];\n    while ((node = nodes.pop()) != null) {\n      nodes2.push(node);\n      if ((children = node.children) && (n = children.length)) {\n        var i = -1, n, children;\n        while (++i < n) nodes.push(children[i]);\n      }\n    }\n    while ((node = nodes2.pop()) != null) {\n      callback(node);\n    }\n  }\n  function d3_layout_hierarchyChildren(d) {\n    return d.children;\n  }\n  function d3_layout_hierarchyValue(d) {\n    return d.value;\n  }\n  function d3_layout_hierarchySort(a, b) {\n    return b.value - a.value;\n  }\n  function d3_layout_hierarchyLinks(nodes) {\n    return d3.merge(nodes.map(function(parent) {\n      return (parent.children || []).map(function(child) {\n        return {\n          source: parent,\n          target: child\n        };\n      });\n    }));\n  }\n  d3.layout.partition = function() {\n    var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];\n    function position(node, x, dx, dy) {\n      var children = node.children;\n      node.x = x;\n      node.y = node.depth * dy;\n      node.dx = dx;\n      node.dy = dy;\n      if (children && (n = children.length)) {\n        var i = -1, n, c, d;\n        dx = node.value ? dx / node.value : 0;\n        while (++i < n) {\n          position(c = children[i], x, d = c.value * dx, dy);\n          x += d;\n        }\n      }\n    }\n    function depth(node) {\n      var children = node.children, d = 0;\n      if (children && (n = children.length)) {\n        var i = -1, n;\n        while (++i < n) d = Math.max(d, depth(children[i]));\n      }\n      return 1 + d;\n    }\n    function partition(d, i) {\n      var nodes = hierarchy.call(this, d, i);\n      position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));\n      return nodes;\n    }\n    partition.size = function(x) {\n      if (!arguments.length) return size;\n      size = x;\n      return partition;\n    };\n    return d3_layout_hierarchyRebind(partition, hierarchy);\n  };\n  d3.layout.pie = function() {\n    var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;\n    function pie(data) {\n      var n = data.length, values = data.map(function(d, i) {\n        return +value.call(pie, d, i);\n      }), a = +(typeof startAngle === \"function\" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === \"function\" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === \"function\" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;\n      if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {\n        return values[j] - values[i];\n      } : function(i, j) {\n        return sort(data[i], data[j]);\n      });\n      index.forEach(function(i) {\n        arcs[i] = {\n          data: data[i],\n          value: v = values[i],\n          startAngle: a,\n          endAngle: a += v * k + pa,\n          padAngle: p\n        };\n      });\n      return arcs;\n    }\n    pie.value = function(_) {\n      if (!arguments.length) return value;\n      value = _;\n      return pie;\n    };\n    pie.sort = function(_) {\n      if (!arguments.length) return sort;\n      sort = _;\n      return pie;\n    };\n    pie.startAngle = function(_) {\n      if (!arguments.length) return startAngle;\n      startAngle = _;\n      return pie;\n    };\n    pie.endAngle = function(_) {\n      if (!arguments.length) return endAngle;\n      endAngle = _;\n      return pie;\n    };\n    pie.padAngle = function(_) {\n      if (!arguments.length) return padAngle;\n      padAngle = _;\n      return pie;\n    };\n    return pie;\n  };\n  var d3_layout_pieSortByValue = {};\n  d3.layout.stack = function() {\n    var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;\n    function stack(data, index) {\n      if (!(n = data.length)) return data;\n      var series = data.map(function(d, i) {\n        return values.call(stack, d, i);\n      });\n      var points = series.map(function(d) {\n        return d.map(function(v, i) {\n          return [ x.call(stack, v, i), y.call(stack, v, i) ];\n        });\n      });\n      var orders = order.call(stack, points, index);\n      series = d3.permute(series, orders);\n      points = d3.permute(points, orders);\n      var offsets = offset.call(stack, points, index);\n      var m = series[0].length, n, i, j, o;\n      for (j = 0; j < m; ++j) {\n        out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);\n        for (i = 1; i < n; ++i) {\n          out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);\n        }\n      }\n      return data;\n    }\n    stack.values = function(x) {\n      if (!arguments.length) return values;\n      values = x;\n      return stack;\n    };\n    stack.order = function(x) {\n      if (!arguments.length) return order;\n      order = typeof x === \"function\" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;\n      return stack;\n    };\n    stack.offset = function(x) {\n      if (!arguments.length) return offset;\n      offset = typeof x === \"function\" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;\n      return stack;\n    };\n    stack.x = function(z) {\n      if (!arguments.length) return x;\n      x = z;\n      return stack;\n    };\n    stack.y = function(z) {\n      if (!arguments.length) return y;\n      y = z;\n      return stack;\n    };\n    stack.out = function(z) {\n      if (!arguments.length) return out;\n      out = z;\n      return stack;\n    };\n    return stack;\n  };\n  function d3_layout_stackX(d) {\n    return d.x;\n  }\n  function d3_layout_stackY(d) {\n    return d.y;\n  }\n  function d3_layout_stackOut(d, y0, y) {\n    d.y0 = y0;\n    d.y = y;\n  }\n  var d3_layout_stackOrders = d3.map({\n    \"inside-out\": function(data) {\n      var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {\n        return max[a] - max[b];\n      }), top = 0, bottom = 0, tops = [], bottoms = [];\n      for (i = 0; i < n; ++i) {\n        j = index[i];\n        if (top < bottom) {\n          top += sums[j];\n          tops.push(j);\n        } else {\n          bottom += sums[j];\n          bottoms.push(j);\n        }\n      }\n      return bottoms.reverse().concat(tops);\n    },\n    reverse: function(data) {\n      return d3.range(data.length).reverse();\n    },\n    \"default\": d3_layout_stackOrderDefault\n  });\n  var d3_layout_stackOffsets = d3.map({\n    silhouette: function(data) {\n      var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];\n      for (j = 0; j < m; ++j) {\n        for (i = 0, o = 0; i < n; i++) o += data[i][j][1];\n        if (o > max) max = o;\n        sums.push(o);\n      }\n      for (j = 0; j < m; ++j) {\n        y0[j] = (max - sums[j]) / 2;\n      }\n      return y0;\n    },\n    wiggle: function(data) {\n      var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];\n      y0[0] = o = o0 = 0;\n      for (j = 1; j < m; ++j) {\n        for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];\n        for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {\n          for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {\n            s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;\n          }\n          s2 += s3 * data[i][j][1];\n        }\n        y0[j] = o -= s1 ? s2 / s1 * dx : 0;\n        if (o < o0) o0 = o;\n      }\n      for (j = 0; j < m; ++j) y0[j] -= o0;\n      return y0;\n    },\n    expand: function(data) {\n      var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];\n      for (j = 0; j < m; ++j) {\n        for (i = 0, o = 0; i < n; i++) o += data[i][j][1];\n        if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;\n      }\n      for (j = 0; j < m; ++j) y0[j] = 0;\n      return y0;\n    },\n    zero: d3_layout_stackOffsetZero\n  });\n  function d3_layout_stackOrderDefault(data) {\n    return d3.range(data.length);\n  }\n  function d3_layout_stackOffsetZero(data) {\n    var j = -1, m = data[0].length, y0 = [];\n    while (++j < m) y0[j] = 0;\n    return y0;\n  }\n  function d3_layout_stackMaxIndex(array) {\n    var i = 1, j = 0, v = array[0][1], k, n = array.length;\n    for (;i < n; ++i) {\n      if ((k = array[i][1]) > v) {\n        j = i;\n        v = k;\n      }\n    }\n    return j;\n  }\n  function d3_layout_stackReduceSum(d) {\n    return d.reduce(d3_layout_stackSum, 0);\n  }\n  function d3_layout_stackSum(p, d) {\n    return p + d[1];\n  }\n  d3.layout.histogram = function() {\n    var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;\n    function histogram(data, i) {\n      var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;\n      while (++i < m) {\n        bin = bins[i] = [];\n        bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);\n        bin.y = 0;\n      }\n      if (m > 0) {\n        i = -1;\n        while (++i < n) {\n          x = values[i];\n          if (x >= range[0] && x <= range[1]) {\n            bin = bins[d3.bisect(thresholds, x, 1, m) - 1];\n            bin.y += k;\n            bin.push(data[i]);\n          }\n        }\n      }\n      return bins;\n    }\n    histogram.value = function(x) {\n      if (!arguments.length) return valuer;\n      valuer = x;\n      return histogram;\n    };\n    histogram.range = function(x) {\n      if (!arguments.length) return ranger;\n      ranger = d3_functor(x);\n      return histogram;\n    };\n    histogram.bins = function(x) {\n      if (!arguments.length) return binner;\n      binner = typeof x === \"number\" ? function(range) {\n        return d3_layout_histogramBinFixed(range, x);\n      } : d3_functor(x);\n      return histogram;\n    };\n    histogram.frequency = function(x) {\n      if (!arguments.length) return frequency;\n      frequency = !!x;\n      return histogram;\n    };\n    return histogram;\n  };\n  function d3_layout_histogramBinSturges(range, values) {\n    return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));\n  }\n  function d3_layout_histogramBinFixed(range, n) {\n    var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];\n    while (++x <= n) f[x] = m * x + b;\n    return f;\n  }\n  function d3_layout_histogramRange(values) {\n    return [ d3.min(values), d3.max(values) ];\n  }\n  d3.layout.pack = function() {\n    var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;\n    function pack(d, i) {\n      var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === \"function\" ? radius : function() {\n        return radius;\n      };\n      root.x = root.y = 0;\n      d3_layout_hierarchyVisitAfter(root, function(d) {\n        d.r = +r(d.value);\n      });\n      d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);\n      if (padding) {\n        var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;\n        d3_layout_hierarchyVisitAfter(root, function(d) {\n          d.r += dr;\n        });\n        d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);\n        d3_layout_hierarchyVisitAfter(root, function(d) {\n          d.r -= dr;\n        });\n      }\n      d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));\n      return nodes;\n    }\n    pack.size = function(_) {\n      if (!arguments.length) return size;\n      size = _;\n      return pack;\n    };\n    pack.radius = function(_) {\n      if (!arguments.length) return radius;\n      radius = _ == null || typeof _ === \"function\" ? _ : +_;\n      return pack;\n    };\n    pack.padding = function(_) {\n      if (!arguments.length) return padding;\n      padding = +_;\n      return pack;\n    };\n    return d3_layout_hierarchyRebind(pack, hierarchy);\n  };\n  function d3_layout_packSort(a, b) {\n    return a.value - b.value;\n  }\n  function d3_layout_packInsert(a, b) {\n    var c = a._pack_next;\n    a._pack_next = b;\n    b._pack_prev = a;\n    b._pack_next = c;\n    c._pack_prev = b;\n  }\n  function d3_layout_packSplice(a, b) {\n    a._pack_next = b;\n    b._pack_prev = a;\n  }\n  function d3_layout_packIntersects(a, b) {\n    var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;\n    return .999 * dr * dr > dx * dx + dy * dy;\n  }\n  function d3_layout_packSiblings(node) {\n    if (!(nodes = node.children) || !(n = nodes.length)) return;\n    var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;\n    function bound(node) {\n      xMin = Math.min(node.x - node.r, xMin);\n      xMax = Math.max(node.x + node.r, xMax);\n      yMin = Math.min(node.y - node.r, yMin);\n      yMax = Math.max(node.y + node.r, yMax);\n    }\n    nodes.forEach(d3_layout_packLink);\n    a = nodes[0];\n    a.x = -a.r;\n    a.y = 0;\n    bound(a);\n    if (n > 1) {\n      b = nodes[1];\n      b.x = b.r;\n      b.y = 0;\n      bound(b);\n      if (n > 2) {\n        c = nodes[2];\n        d3_layout_packPlace(a, b, c);\n        bound(c);\n        d3_layout_packInsert(a, c);\n        a._pack_prev = c;\n        d3_layout_packInsert(c, b);\n        b = a._pack_next;\n        for (i = 3; i < n; i++) {\n          d3_layout_packPlace(a, b, c = nodes[i]);\n          var isect = 0, s1 = 1, s2 = 1;\n          for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {\n            if (d3_layout_packIntersects(j, c)) {\n              isect = 1;\n              break;\n            }\n          }\n          if (isect == 1) {\n            for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {\n              if (d3_layout_packIntersects(k, c)) {\n                break;\n              }\n            }\n          }\n          if (isect) {\n            if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);\n            i--;\n          } else {\n            d3_layout_packInsert(a, c);\n            b = c;\n            bound(c);\n          }\n        }\n      }\n    }\n    var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;\n    for (i = 0; i < n; i++) {\n      c = nodes[i];\n      c.x -= cx;\n      c.y -= cy;\n      cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));\n    }\n    node.r = cr;\n    nodes.forEach(d3_layout_packUnlink);\n  }\n  function d3_layout_packLink(node) {\n    node._pack_next = node._pack_prev = node;\n  }\n  function d3_layout_packUnlink(node) {\n    delete node._pack_next;\n    delete node._pack_prev;\n  }\n  function d3_layout_packTransform(node, x, y, k) {\n    var children = node.children;\n    node.x = x += k * node.x;\n    node.y = y += k * node.y;\n    node.r *= k;\n    if (children) {\n      var i = -1, n = children.length;\n      while (++i < n) d3_layout_packTransform(children[i], x, y, k);\n    }\n  }\n  function d3_layout_packPlace(a, b, c) {\n    var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;\n    if (db && (dx || dy)) {\n      var da = b.r + c.r, dc = dx * dx + dy * dy;\n      da *= da;\n      db *= db;\n      var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);\n      c.x = a.x + x * dx + y * dy;\n      c.y = a.y + x * dy - y * dx;\n    } else {\n      c.x = a.x + db;\n      c.y = a.y;\n    }\n  }\n  d3.layout.tree = function() {\n    var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;\n    function tree(d, i) {\n      var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);\n      d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;\n      d3_layout_hierarchyVisitBefore(root1, secondWalk);\n      if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {\n        var left = root0, right = root0, bottom = root0;\n        d3_layout_hierarchyVisitBefore(root0, function(node) {\n          if (node.x < left.x) left = node;\n          if (node.x > right.x) right = node;\n          if (node.depth > bottom.depth) bottom = node;\n        });\n        var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);\n        d3_layout_hierarchyVisitBefore(root0, function(node) {\n          node.x = (node.x + tx) * kx;\n          node.y = node.depth * ky;\n        });\n      }\n      return nodes;\n    }\n    function wrapTree(root0) {\n      var root1 = {\n        A: null,\n        children: [ root0 ]\n      }, queue = [ root1 ], node1;\n      while ((node1 = queue.pop()) != null) {\n        for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {\n          queue.push((children[i] = child = {\n            _: children[i],\n            parent: node1,\n            children: (child = children[i].children) && child.slice() || [],\n            A: null,\n            a: null,\n            z: 0,\n            m: 0,\n            c: 0,\n            s: 0,\n            t: null,\n            i: i\n          }).a = child);\n        }\n      }\n      return root1.children[0];\n    }\n    function firstWalk(v) {\n      var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;\n      if (children.length) {\n        d3_layout_treeShift(v);\n        var midpoint = (children[0].z + children[children.length - 1].z) / 2;\n        if (w) {\n          v.z = w.z + separation(v._, w._);\n          v.m = v.z - midpoint;\n        } else {\n          v.z = midpoint;\n        }\n      } else if (w) {\n        v.z = w.z + separation(v._, w._);\n      }\n      v.parent.A = apportion(v, w, v.parent.A || siblings[0]);\n    }\n    function secondWalk(v) {\n      v._.x = v.z + v.parent.m;\n      v.m += v.parent.m;\n    }\n    function apportion(v, w, ancestor) {\n      if (w) {\n        var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;\n        while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {\n          vom = d3_layout_treeLeft(vom);\n          vop = d3_layout_treeRight(vop);\n          vop.a = v;\n          shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);\n          if (shift > 0) {\n            d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);\n            sip += shift;\n            sop += shift;\n          }\n          sim += vim.m;\n          sip += vip.m;\n          som += vom.m;\n          sop += vop.m;\n        }\n        if (vim && !d3_layout_treeRight(vop)) {\n          vop.t = vim;\n          vop.m += sim - sop;\n        }\n        if (vip && !d3_layout_treeLeft(vom)) {\n          vom.t = vip;\n          vom.m += sip - som;\n          ancestor = v;\n        }\n      }\n      return ancestor;\n    }\n    function sizeNode(node) {\n      node.x *= size[0];\n      node.y = node.depth * size[1];\n    }\n    tree.separation = function(x) {\n      if (!arguments.length) return separation;\n      separation = x;\n      return tree;\n    };\n    tree.size = function(x) {\n      if (!arguments.length) return nodeSize ? null : size;\n      nodeSize = (size = x) == null ? sizeNode : null;\n      return tree;\n    };\n    tree.nodeSize = function(x) {\n      if (!arguments.length) return nodeSize ? size : null;\n      nodeSize = (size = x) == null ? null : sizeNode;\n      return tree;\n    };\n    return d3_layout_hierarchyRebind(tree, hierarchy);\n  };\n  function d3_layout_treeSeparation(a, b) {\n    return a.parent == b.parent ? 1 : 2;\n  }\n  function d3_layout_treeLeft(v) {\n    var children = v.children;\n    return children.length ? children[0] : v.t;\n  }\n  function d3_layout_treeRight(v) {\n    var children = v.children, n;\n    return (n = children.length) ? children[n - 1] : v.t;\n  }\n  function d3_layout_treeMove(wm, wp, shift) {\n    var change = shift / (wp.i - wm.i);\n    wp.c -= change;\n    wp.s += shift;\n    wm.c += change;\n    wp.z += shift;\n    wp.m += shift;\n  }\n  function d3_layout_treeShift(v) {\n    var shift = 0, change = 0, children = v.children, i = children.length, w;\n    while (--i >= 0) {\n      w = children[i];\n      w.z += shift;\n      w.m += shift;\n      shift += w.s + (change += w.c);\n    }\n  }\n  function d3_layout_treeAncestor(vim, v, ancestor) {\n    return vim.a.parent === v.parent ? vim.a : ancestor;\n  }\n  d3.layout.cluster = function() {\n    var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;\n    function cluster(d, i) {\n      var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;\n      d3_layout_hierarchyVisitAfter(root, function(node) {\n        var children = node.children;\n        if (children && children.length) {\n          node.x = d3_layout_clusterX(children);\n          node.y = d3_layout_clusterY(children);\n        } else {\n          node.x = previousNode ? x += separation(node, previousNode) : 0;\n          node.y = 0;\n          previousNode = node;\n        }\n      });\n      var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;\n      d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {\n        node.x = (node.x - root.x) * size[0];\n        node.y = (root.y - node.y) * size[1];\n      } : function(node) {\n        node.x = (node.x - x0) / (x1 - x0) * size[0];\n        node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];\n      });\n      return nodes;\n    }\n    cluster.separation = function(x) {\n      if (!arguments.length) return separation;\n      separation = x;\n      return cluster;\n    };\n    cluster.size = function(x) {\n      if (!arguments.length) return nodeSize ? null : size;\n      nodeSize = (size = x) == null;\n      return cluster;\n    };\n    cluster.nodeSize = function(x) {\n      if (!arguments.length) return nodeSize ? size : null;\n      nodeSize = (size = x) != null;\n      return cluster;\n    };\n    return d3_layout_hierarchyRebind(cluster, hierarchy);\n  };\n  function d3_layout_clusterY(children) {\n    return 1 + d3.max(children, function(child) {\n      return child.y;\n    });\n  }\n  function d3_layout_clusterX(children) {\n    return children.reduce(function(x, child) {\n      return x + child.x;\n    }, 0) / children.length;\n  }\n  function d3_layout_clusterLeft(node) {\n    var children = node.children;\n    return children && children.length ? d3_layout_clusterLeft(children[0]) : node;\n  }\n  function d3_layout_clusterRight(node) {\n    var children = node.children, n;\n    return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;\n  }\n  d3.layout.treemap = function() {\n    var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = \"squarify\", ratio = .5 * (1 + Math.sqrt(5));\n    function scale(children, k) {\n      var i = -1, n = children.length, child, area;\n      while (++i < n) {\n        area = (child = children[i]).value * (k < 0 ? 0 : k);\n        child.area = isNaN(area) || area <= 0 ? 0 : area;\n      }\n    }\n    function squarify(node) {\n      var children = node.children;\n      if (children && children.length) {\n        var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === \"slice\" ? rect.dx : mode === \"dice\" ? rect.dy : mode === \"slice-dice\" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;\n        scale(remaining, rect.dx * rect.dy / node.value);\n        row.area = 0;\n        while ((n = remaining.length) > 0) {\n          row.push(child = remaining[n - 1]);\n          row.area += child.area;\n          if (mode !== \"squarify\" || (score = worst(row, u)) <= best) {\n            remaining.pop();\n            best = score;\n          } else {\n            row.area -= row.pop().area;\n            position(row, u, rect, false);\n            u = Math.min(rect.dx, rect.dy);\n            row.length = row.area = 0;\n            best = Infinity;\n          }\n        }\n        if (row.length) {\n          position(row, u, rect, true);\n          row.length = row.area = 0;\n        }\n        children.forEach(squarify);\n      }\n    }\n    function stickify(node) {\n      var children = node.children;\n      if (children && children.length) {\n        var rect = pad(node), remaining = children.slice(), child, row = [];\n        scale(remaining, rect.dx * rect.dy / node.value);\n        row.area = 0;\n        while (child = remaining.pop()) {\n          row.push(child);\n          row.area += child.area;\n          if (child.z != null) {\n            position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);\n            row.length = row.area = 0;\n          }\n        }\n        children.forEach(stickify);\n      }\n    }\n    function worst(row, u) {\n      var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;\n      while (++i < n) {\n        if (!(r = row[i].area)) continue;\n        if (r < rmin) rmin = r;\n        if (r > rmax) rmax = r;\n      }\n      s *= s;\n      u *= u;\n      return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;\n    }\n    function position(row, u, rect, flush) {\n      var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;\n      if (u == rect.dx) {\n        if (flush || v > rect.dy) v = rect.dy;\n        while (++i < n) {\n          o = row[i];\n          o.x = x;\n          o.y = y;\n          o.dy = v;\n          x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);\n        }\n        o.z = true;\n        o.dx += rect.x + rect.dx - x;\n        rect.y += v;\n        rect.dy -= v;\n      } else {\n        if (flush || v > rect.dx) v = rect.dx;\n        while (++i < n) {\n          o = row[i];\n          o.x = x;\n          o.y = y;\n          o.dx = v;\n          y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);\n        }\n        o.z = false;\n        o.dy += rect.y + rect.dy - y;\n        rect.x += v;\n        rect.dx -= v;\n      }\n    }\n    function treemap(d) {\n      var nodes = stickies || hierarchy(d), root = nodes[0];\n      root.x = root.y = 0;\n      if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;\n      if (stickies) hierarchy.revalue(root);\n      scale([ root ], root.dx * root.dy / root.value);\n      (stickies ? stickify : squarify)(root);\n      if (sticky) stickies = nodes;\n      return nodes;\n    }\n    treemap.size = function(x) {\n      if (!arguments.length) return size;\n      size = x;\n      return treemap;\n    };\n    treemap.padding = function(x) {\n      if (!arguments.length) return padding;\n      function padFunction(node) {\n        var p = x.call(treemap, node, node.depth);\n        return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === \"number\" ? [ p, p, p, p ] : p);\n      }\n      function padConstant(node) {\n        return d3_layout_treemapPad(node, x);\n      }\n      var type;\n      pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === \"function\" ? padFunction : type === \"number\" ? (x = [ x, x, x, x ], \n      padConstant) : padConstant;\n      return treemap;\n    };\n    treemap.round = function(x) {\n      if (!arguments.length) return round != Number;\n      round = x ? Math.round : Number;\n      return treemap;\n    };\n    treemap.sticky = function(x) {\n      if (!arguments.length) return sticky;\n      sticky = x;\n      stickies = null;\n      return treemap;\n    };\n    treemap.ratio = function(x) {\n      if (!arguments.length) return ratio;\n      ratio = x;\n      return treemap;\n    };\n    treemap.mode = function(x) {\n      if (!arguments.length) return mode;\n      mode = x + \"\";\n      return treemap;\n    };\n    return d3_layout_hierarchyRebind(treemap, hierarchy);\n  };\n  function d3_layout_treemapPadNull(node) {\n    return {\n      x: node.x,\n      y: node.y,\n      dx: node.dx,\n      dy: node.dy\n    };\n  }\n  function d3_layout_treemapPad(node, padding) {\n    var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2];\n    if (dx < 0) {\n      x += dx / 2;\n      dx = 0;\n    }\n    if (dy < 0) {\n      y += dy / 2;\n      dy = 0;\n    }\n    return {\n      x: x,\n      y: y,\n      dx: dx,\n      dy: dy\n    };\n  }\n  d3.random = {\n    normal: function(µ, σ) {\n      var n = arguments.length;\n      if (n < 2) σ = 1;\n      if (n < 1) µ = 0;\n      return function() {\n        var x, y, r;\n        do {\n          x = Math.random() * 2 - 1;\n          y = Math.random() * 2 - 1;\n          r = x * x + y * y;\n        } while (!r || r > 1);\n        return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);\n      };\n    },\n    logNormal: function() {\n      var random = d3.random.normal.apply(d3, arguments);\n      return function() {\n        return Math.exp(random());\n      };\n    },\n    bates: function(m) {\n      var random = d3.random.irwinHall(m);\n      return function() {\n        return random() / m;\n      };\n    },\n    irwinHall: function(m) {\n      return function() {\n        for (var s = 0, j = 0; j < m; j++) s += Math.random();\n        return s;\n      };\n    }\n  };\n  d3.scale = {};\n  function d3_scaleExtent(domain) {\n    var start = domain[0], stop = domain[domain.length - 1];\n    return start < stop ? [ start, stop ] : [ stop, start ];\n  }\n  function d3_scaleRange(scale) {\n    return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());\n  }\n  function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {\n    var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);\n    return function(x) {\n      return i(u(x));\n    };\n  }\n  function d3_scale_nice(domain, nice) {\n    var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;\n    if (x1 < x0) {\n      dx = i0, i0 = i1, i1 = dx;\n      dx = x0, x0 = x1, x1 = dx;\n    }\n    domain[i0] = nice.floor(x0);\n    domain[i1] = nice.ceil(x1);\n    return domain;\n  }\n  function d3_scale_niceStep(step) {\n    return step ? {\n      floor: function(x) {\n        return Math.floor(x / step) * step;\n      },\n      ceil: function(x) {\n        return Math.ceil(x / step) * step;\n      }\n    } : d3_scale_niceIdentity;\n  }\n  var d3_scale_niceIdentity = {\n    floor: d3_identity,\n    ceil: d3_identity\n  };\n  function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {\n    var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;\n    if (domain[k] < domain[0]) {\n      domain = domain.slice().reverse();\n      range = range.slice().reverse();\n    }\n    while (++j <= k) {\n      u.push(uninterpolate(domain[j - 1], domain[j]));\n      i.push(interpolate(range[j - 1], range[j]));\n    }\n    return function(x) {\n      var j = d3.bisect(domain, x, 1, k) - 1;\n      return i[j](u[j](x));\n    };\n  }\n  d3.scale.linear = function() {\n    return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);\n  };\n  function d3_scale_linear(domain, range, interpolate, clamp) {\n    var output, input;\n    function rescale() {\n      var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;\n      output = linear(domain, range, uninterpolate, interpolate);\n      input = linear(range, domain, uninterpolate, d3_interpolate);\n      return scale;\n    }\n    function scale(x) {\n      return output(x);\n    }\n    scale.invert = function(y) {\n      return input(y);\n    };\n    scale.domain = function(x) {\n      if (!arguments.length) return domain;\n      domain = x.map(Number);\n      return rescale();\n    };\n    scale.range = function(x) {\n      if (!arguments.length) return range;\n      range = x;\n      return rescale();\n    };\n    scale.rangeRound = function(x) {\n      return scale.range(x).interpolate(d3_interpolateRound);\n    };\n    scale.clamp = function(x) {\n      if (!arguments.length) return clamp;\n      clamp = x;\n      return rescale();\n    };\n    scale.interpolate = function(x) {\n      if (!arguments.length) return interpolate;\n      interpolate = x;\n      return rescale();\n    };\n    scale.ticks = function(m) {\n      return d3_scale_linearTicks(domain, m);\n    };\n    scale.tickFormat = function(m, format) {\n      return d3_scale_linearTickFormat(domain, m, format);\n    };\n    scale.nice = function(m) {\n      d3_scale_linearNice(domain, m);\n      return rescale();\n    };\n    scale.copy = function() {\n      return d3_scale_linear(domain, range, interpolate, clamp);\n    };\n    return rescale();\n  }\n  function d3_scale_linearRebind(scale, linear) {\n    return d3.rebind(scale, linear, \"range\", \"rangeRound\", \"interpolate\", \"clamp\");\n  }\n  function d3_scale_linearNice(domain, m) {\n    d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));\n    d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));\n    return domain;\n  }\n  function d3_scale_linearTickRange(domain, m) {\n    if (m == null) m = 10;\n    var extent = d3_scaleExtent(domain), span = extent[1] - extent[0], step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step;\n    if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;\n    extent[0] = Math.ceil(extent[0] / step) * step;\n    extent[1] = Math.floor(extent[1] / step) * step + step * .5;\n    extent[2] = step;\n    return extent;\n  }\n  function d3_scale_linearTicks(domain, m) {\n    return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));\n  }\n  function d3_scale_linearTickFormat(domain, m, format) {\n    var range = d3_scale_linearTickRange(domain, m);\n    if (format) {\n      var match = d3_format_re.exec(format);\n      match.shift();\n      if (match[8] === \"s\") {\n        var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));\n        if (!match[7]) match[7] = \".\" + d3_scale_linearPrecision(prefix.scale(range[2]));\n        match[8] = \"f\";\n        format = d3.format(match.join(\"\"));\n        return function(d) {\n          return format(prefix.scale(d)) + prefix.symbol;\n        };\n      }\n      if (!match[7]) match[7] = \".\" + d3_scale_linearFormatPrecision(match[8], range);\n      format = match.join(\"\");\n    } else {\n      format = \",.\" + d3_scale_linearPrecision(range[2]) + \"f\";\n    }\n    return d3.format(format);\n  }\n  var d3_scale_linearFormatSignificant = {\n    s: 1,\n    g: 1,\n    p: 1,\n    r: 1,\n    e: 1\n  };\n  function d3_scale_linearPrecision(value) {\n    return -Math.floor(Math.log(value) / Math.LN10 + .01);\n  }\n  function d3_scale_linearFormatPrecision(type, range) {\n    var p = d3_scale_linearPrecision(range[2]);\n    return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== \"e\") : p - (type === \"%\") * 2;\n  }\n  d3.scale.log = function() {\n    return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);\n  };\n  function d3_scale_log(linear, base, positive, domain) {\n    function log(x) {\n      return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);\n    }\n    function pow(x) {\n      return positive ? Math.pow(base, x) : -Math.pow(base, -x);\n    }\n    function scale(x) {\n      return linear(log(x));\n    }\n    scale.invert = function(x) {\n      return pow(linear.invert(x));\n    };\n    scale.domain = function(x) {\n      if (!arguments.length) return domain;\n      positive = x[0] >= 0;\n      linear.domain((domain = x.map(Number)).map(log));\n      return scale;\n    };\n    scale.base = function(_) {\n      if (!arguments.length) return base;\n      base = +_;\n      linear.domain(domain.map(log));\n      return scale;\n    };\n    scale.nice = function() {\n      var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);\n      linear.domain(niced);\n      domain = niced.map(pow);\n      return scale;\n    };\n    scale.ticks = function() {\n      var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;\n      if (isFinite(j - i)) {\n        if (positive) {\n          for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);\n          ticks.push(pow(i));\n        } else {\n          ticks.push(pow(i));\n          for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);\n        }\n        for (i = 0; ticks[i] < u; i++) {}\n        for (j = ticks.length; ticks[j - 1] > v; j--) {}\n        ticks = ticks.slice(i, j);\n      }\n      return ticks;\n    };\n    scale.tickFormat = function(n, format) {\n      if (!arguments.length) return d3_scale_logFormat;\n      if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== \"function\") format = d3.format(format);\n      var k = Math.max(1, base * n / scale.ticks().length);\n      return function(d) {\n        var i = d / pow(Math.round(log(d)));\n        if (i * base < base - .5) i *= base;\n        return i <= k ? format(d) : \"\";\n      };\n    };\n    scale.copy = function() {\n      return d3_scale_log(linear.copy(), base, positive, domain);\n    };\n    return d3_scale_linearRebind(scale, linear);\n  }\n  var d3_scale_logFormat = d3.format(\".0e\"), d3_scale_logNiceNegative = {\n    floor: function(x) {\n      return -Math.ceil(-x);\n    },\n    ceil: function(x) {\n      return -Math.floor(-x);\n    }\n  };\n  d3.scale.pow = function() {\n    return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);\n  };\n  function d3_scale_pow(linear, exponent, domain) {\n    var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);\n    function scale(x) {\n      return linear(powp(x));\n    }\n    scale.invert = function(x) {\n      return powb(linear.invert(x));\n    };\n    scale.domain = function(x) {\n      if (!arguments.length) return domain;\n      linear.domain((domain = x.map(Number)).map(powp));\n      return scale;\n    };\n    scale.ticks = function(m) {\n      return d3_scale_linearTicks(domain, m);\n    };\n    scale.tickFormat = function(m, format) {\n      return d3_scale_linearTickFormat(domain, m, format);\n    };\n    scale.nice = function(m) {\n      return scale.domain(d3_scale_linearNice(domain, m));\n    };\n    scale.exponent = function(x) {\n      if (!arguments.length) return exponent;\n      powp = d3_scale_powPow(exponent = x);\n      powb = d3_scale_powPow(1 / exponent);\n      linear.domain(domain.map(powp));\n      return scale;\n    };\n    scale.copy = function() {\n      return d3_scale_pow(linear.copy(), exponent, domain);\n    };\n    return d3_scale_linearRebind(scale, linear);\n  }\n  function d3_scale_powPow(e) {\n    return function(x) {\n      return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);\n    };\n  }\n  d3.scale.sqrt = function() {\n    return d3.scale.pow().exponent(.5);\n  };\n  d3.scale.ordinal = function() {\n    return d3_scale_ordinal([], {\n      t: \"range\",\n      a: [ [] ]\n    });\n  };\n  function d3_scale_ordinal(domain, ranger) {\n    var index, range, rangeBand;\n    function scale(x) {\n      return range[((index.get(x) || (ranger.t === \"range\" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];\n    }\n    function steps(start, step) {\n      return d3.range(domain.length).map(function(i) {\n        return start + step * i;\n      });\n    }\n    scale.domain = function(x) {\n      if (!arguments.length) return domain;\n      domain = [];\n      index = new d3_Map();\n      var i = -1, n = x.length, xi;\n      while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));\n      return scale[ranger.t].apply(scale, ranger.a);\n    };\n    scale.range = function(x) {\n      if (!arguments.length) return range;\n      range = x;\n      rangeBand = 0;\n      ranger = {\n        t: \"range\",\n        a: arguments\n      };\n      return scale;\n    };\n    scale.rangePoints = function(x, padding) {\n      if (arguments.length < 2) padding = 0;\n      var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2, \n      0) : (stop - start) / (domain.length - 1 + padding);\n      range = steps(start + step * padding / 2, step);\n      rangeBand = 0;\n      ranger = {\n        t: \"rangePoints\",\n        a: arguments\n      };\n      return scale;\n    };\n    scale.rangeRoundPoints = function(x, padding) {\n      if (arguments.length < 2) padding = 0;\n      var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2), \n      0) : (stop - start) / (domain.length - 1 + padding) | 0;\n      range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);\n      rangeBand = 0;\n      ranger = {\n        t: \"rangeRoundPoints\",\n        a: arguments\n      };\n      return scale;\n    };\n    scale.rangeBands = function(x, padding, outerPadding) {\n      if (arguments.length < 2) padding = 0;\n      if (arguments.length < 3) outerPadding = padding;\n      var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);\n      range = steps(start + step * outerPadding, step);\n      if (reverse) range.reverse();\n      rangeBand = step * (1 - padding);\n      ranger = {\n        t: \"rangeBands\",\n        a: arguments\n      };\n      return scale;\n    };\n    scale.rangeRoundBands = function(x, padding, outerPadding) {\n      if (arguments.length < 2) padding = 0;\n      if (arguments.length < 3) outerPadding = padding;\n      var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));\n      range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);\n      if (reverse) range.reverse();\n      rangeBand = Math.round(step * (1 - padding));\n      ranger = {\n        t: \"rangeRoundBands\",\n        a: arguments\n      };\n      return scale;\n    };\n    scale.rangeBand = function() {\n      return rangeBand;\n    };\n    scale.rangeExtent = function() {\n      return d3_scaleExtent(ranger.a[0]);\n    };\n    scale.copy = function() {\n      return d3_scale_ordinal(domain, ranger);\n    };\n    return scale.domain(domain);\n  }\n  d3.scale.category10 = function() {\n    return d3.scale.ordinal().range(d3_category10);\n  };\n  d3.scale.category20 = function() {\n    return d3.scale.ordinal().range(d3_category20);\n  };\n  d3.scale.category20b = function() {\n    return d3.scale.ordinal().range(d3_category20b);\n  };\n  d3.scale.category20c = function() {\n    return d3.scale.ordinal().range(d3_category20c);\n  };\n  var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);\n  var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);\n  var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);\n  var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);\n  d3.scale.quantile = function() {\n    return d3_scale_quantile([], []);\n  };\n  function d3_scale_quantile(domain, range) {\n    var thresholds;\n    function rescale() {\n      var k = 0, q = range.length;\n      thresholds = [];\n      while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);\n      return scale;\n    }\n    function scale(x) {\n      if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];\n    }\n    scale.domain = function(x) {\n      if (!arguments.length) return domain;\n      domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);\n      return rescale();\n    };\n    scale.range = function(x) {\n      if (!arguments.length) return range;\n      range = x;\n      return rescale();\n    };\n    scale.quantiles = function() {\n      return thresholds;\n    };\n    scale.invertExtent = function(y) {\n      y = range.indexOf(y);\n      return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];\n    };\n    scale.copy = function() {\n      return d3_scale_quantile(domain, range);\n    };\n    return rescale();\n  }\n  d3.scale.quantize = function() {\n    return d3_scale_quantize(0, 1, [ 0, 1 ]);\n  };\n  function d3_scale_quantize(x0, x1, range) {\n    var kx, i;\n    function scale(x) {\n      return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];\n    }\n    function rescale() {\n      kx = range.length / (x1 - x0);\n      i = range.length - 1;\n      return scale;\n    }\n    scale.domain = function(x) {\n      if (!arguments.length) return [ x0, x1 ];\n      x0 = +x[0];\n      x1 = +x[x.length - 1];\n      return rescale();\n    };\n    scale.range = function(x) {\n      if (!arguments.length) return range;\n      range = x;\n      return rescale();\n    };\n    scale.invertExtent = function(y) {\n      y = range.indexOf(y);\n      y = y < 0 ? NaN : y / kx + x0;\n      return [ y, y + 1 / kx ];\n    };\n    scale.copy = function() {\n      return d3_scale_quantize(x0, x1, range);\n    };\n    return rescale();\n  }\n  d3.scale.threshold = function() {\n    return d3_scale_threshold([ .5 ], [ 0, 1 ]);\n  };\n  function d3_scale_threshold(domain, range) {\n    function scale(x) {\n      if (x <= x) return range[d3.bisect(domain, x)];\n    }\n    scale.domain = function(_) {\n      if (!arguments.length) return domain;\n      domain = _;\n      return scale;\n    };\n    scale.range = function(_) {\n      if (!arguments.length) return range;\n      range = _;\n      return scale;\n    };\n    scale.invertExtent = function(y) {\n      y = range.indexOf(y);\n      return [ domain[y - 1], domain[y] ];\n    };\n    scale.copy = function() {\n      return d3_scale_threshold(domain, range);\n    };\n    return scale;\n  }\n  d3.scale.identity = function() {\n    return d3_scale_identity([ 0, 1 ]);\n  };\n  function d3_scale_identity(domain) {\n    function identity(x) {\n      return +x;\n    }\n    identity.invert = identity;\n    identity.domain = identity.range = function(x) {\n      if (!arguments.length) return domain;\n      domain = x.map(identity);\n      return identity;\n    };\n    identity.ticks = function(m) {\n      return d3_scale_linearTicks(domain, m);\n    };\n    identity.tickFormat = function(m, format) {\n      return d3_scale_linearTickFormat(domain, m, format);\n    };\n    identity.copy = function() {\n      return d3_scale_identity(domain);\n    };\n    return identity;\n  }\n  d3.svg = {};\n  function d3_zero() {\n    return 0;\n  }\n  d3.svg.arc = function() {\n    var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;\n    function arc() {\n      var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;\n      if (r1 < r0) rc = r1, r1 = r0, r0 = rc;\n      if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : \"\") + \"Z\";\n      var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];\n      if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {\n        rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);\n        if (!cw) p1 *= -1;\n        if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));\n        if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));\n      }\n      if (r1) {\n        x0 = r1 * Math.cos(a0 + p1);\n        y0 = r1 * Math.sin(a0 + p1);\n        x1 = r1 * Math.cos(a1 - p1);\n        y1 = r1 * Math.sin(a1 - p1);\n        var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;\n        if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {\n          var h1 = (a0 + a1) / 2;\n          x0 = r1 * Math.cos(h1);\n          y0 = r1 * Math.sin(h1);\n          x1 = y1 = null;\n        }\n      } else {\n        x0 = y0 = 0;\n      }\n      if (r0) {\n        x2 = r0 * Math.cos(a1 - p0);\n        y2 = r0 * Math.sin(a1 - p0);\n        x3 = r0 * Math.cos(a0 + p0);\n        y3 = r0 * Math.sin(a0 + p0);\n        var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;\n        if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {\n          var h0 = (a0 + a1) / 2;\n          x2 = r0 * Math.cos(h0);\n          y2 = r0 * Math.sin(h0);\n          x3 = y3 = null;\n        }\n      } else {\n        x2 = y2 = 0;\n      }\n      if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {\n        cr = r0 < r1 ^ cw ? 0 : 1;\n        var rc1 = rc, rc0 = rc;\n        if (da < π) {\n          var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);\n          rc0 = Math.min(rc, (r0 - lc) / (kc - 1));\n          rc1 = Math.min(rc, (r1 - lc) / (kc + 1));\n        }\n        if (x1 != null) {\n          var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);\n          if (rc === rc1) {\n            path.push(\"M\", t30[0], \"A\", rc1, \",\", rc1, \" 0 0,\", cr, \" \", t30[1], \"A\", r1, \",\", r1, \" 0 \", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), \",\", cw, \" \", t12[1], \"A\", rc1, \",\", rc1, \" 0 0,\", cr, \" \", t12[0]);\n          } else {\n            path.push(\"M\", t30[0], \"A\", rc1, \",\", rc1, \" 0 1,\", cr, \" \", t12[0]);\n          }\n        } else {\n          path.push(\"M\", x0, \",\", y0);\n        }\n        if (x3 != null) {\n          var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);\n          if (rc === rc0) {\n            path.push(\"L\", t21[0], \"A\", rc0, \",\", rc0, \" 0 0,\", cr, \" \", t21[1], \"A\", r0, \",\", r0, \" 0 \", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), \",\", 1 - cw, \" \", t03[1], \"A\", rc0, \",\", rc0, \" 0 0,\", cr, \" \", t03[0]);\n          } else {\n            path.push(\"L\", t21[0], \"A\", rc0, \",\", rc0, \" 0 0,\", cr, \" \", t03[0]);\n          }\n        } else {\n          path.push(\"L\", x2, \",\", y2);\n        }\n      } else {\n        path.push(\"M\", x0, \",\", y0);\n        if (x1 != null) path.push(\"A\", r1, \",\", r1, \" 0 \", l1, \",\", cw, \" \", x1, \",\", y1);\n        path.push(\"L\", x2, \",\", y2);\n        if (x3 != null) path.push(\"A\", r0, \",\", r0, \" 0 \", l0, \",\", 1 - cw, \" \", x3, \",\", y3);\n      }\n      path.push(\"Z\");\n      return path.join(\"\");\n    }\n    function circleSegment(r1, cw) {\n      return \"M0,\" + r1 + \"A\" + r1 + \",\" + r1 + \" 0 1,\" + cw + \" 0,\" + -r1 + \"A\" + r1 + \",\" + r1 + \" 0 1,\" + cw + \" 0,\" + r1;\n    }\n    arc.innerRadius = function(v) {\n      if (!arguments.length) return innerRadius;\n      innerRadius = d3_functor(v);\n      return arc;\n    };\n    arc.outerRadius = function(v) {\n      if (!arguments.length) return outerRadius;\n      outerRadius = d3_functor(v);\n      return arc;\n    };\n    arc.cornerRadius = function(v) {\n      if (!arguments.length) return cornerRadius;\n      cornerRadius = d3_functor(v);\n      return arc;\n    };\n    arc.padRadius = function(v) {\n      if (!arguments.length) return padRadius;\n      padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);\n      return arc;\n    };\n    arc.startAngle = function(v) {\n      if (!arguments.length) return startAngle;\n      startAngle = d3_functor(v);\n      return arc;\n    };\n    arc.endAngle = function(v) {\n      if (!arguments.length) return endAngle;\n      endAngle = d3_functor(v);\n      return arc;\n    };\n    arc.padAngle = function(v) {\n      if (!arguments.length) return padAngle;\n      padAngle = d3_functor(v);\n      return arc;\n    };\n    arc.centroid = function() {\n      var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;\n      return [ Math.cos(a) * r, Math.sin(a) * r ];\n    };\n    return arc;\n  };\n  var d3_svg_arcAuto = \"auto\";\n  function d3_svg_arcInnerRadius(d) {\n    return d.innerRadius;\n  }\n  function d3_svg_arcOuterRadius(d) {\n    return d.outerRadius;\n  }\n  function d3_svg_arcStartAngle(d) {\n    return d.startAngle;\n  }\n  function d3_svg_arcEndAngle(d) {\n    return d.endAngle;\n  }\n  function d3_svg_arcPadAngle(d) {\n    return d && d.padAngle;\n  }\n  function d3_svg_arcSweep(x0, y0, x1, y1) {\n    return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;\n  }\n  function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {\n    var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;\n    if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;\n    return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];\n  }\n  function d3_svg_line(projection) {\n    var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;\n    function line(data) {\n      var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);\n      function segment() {\n        segments.push(\"M\", interpolate(projection(points), tension));\n      }\n      while (++i < n) {\n        if (defined.call(this, d = data[i], i)) {\n          points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);\n        } else if (points.length) {\n          segment();\n          points = [];\n        }\n      }\n      if (points.length) segment();\n      return segments.length ? segments.join(\"\") : null;\n    }\n    line.x = function(_) {\n      if (!arguments.length) return x;\n      x = _;\n      return line;\n    };\n    line.y = function(_) {\n      if (!arguments.length) return y;\n      y = _;\n      return line;\n    };\n    line.defined = function(_) {\n      if (!arguments.length) return defined;\n      defined = _;\n      return line;\n    };\n    line.interpolate = function(_) {\n      if (!arguments.length) return interpolateKey;\n      if (typeof _ === \"function\") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;\n      return line;\n    };\n    line.tension = function(_) {\n      if (!arguments.length) return tension;\n      tension = _;\n      return line;\n    };\n    return line;\n  }\n  d3.svg.line = function() {\n    return d3_svg_line(d3_identity);\n  };\n  var d3_svg_lineInterpolators = d3.map({\n    linear: d3_svg_lineLinear,\n    \"linear-closed\": d3_svg_lineLinearClosed,\n    step: d3_svg_lineStep,\n    \"step-before\": d3_svg_lineStepBefore,\n    \"step-after\": d3_svg_lineStepAfter,\n    basis: d3_svg_lineBasis,\n    \"basis-open\": d3_svg_lineBasisOpen,\n    \"basis-closed\": d3_svg_lineBasisClosed,\n    bundle: d3_svg_lineBundle,\n    cardinal: d3_svg_lineCardinal,\n    \"cardinal-open\": d3_svg_lineCardinalOpen,\n    \"cardinal-closed\": d3_svg_lineCardinalClosed,\n    monotone: d3_svg_lineMonotone\n  });\n  d3_svg_lineInterpolators.forEach(function(key, value) {\n    value.key = key;\n    value.closed = /-closed$/.test(key);\n  });\n  function d3_svg_lineLinear(points) {\n    return points.length > 1 ? points.join(\"L\") : points + \"Z\";\n  }\n  function d3_svg_lineLinearClosed(points) {\n    return points.join(\"L\") + \"Z\";\n  }\n  function d3_svg_lineStep(points) {\n    var i = 0, n = points.length, p = points[0], path = [ p[0], \",\", p[1] ];\n    while (++i < n) path.push(\"H\", (p[0] + (p = points[i])[0]) / 2, \"V\", p[1]);\n    if (n > 1) path.push(\"H\", p[0]);\n    return path.join(\"\");\n  }\n  function d3_svg_lineStepBefore(points) {\n    var i = 0, n = points.length, p = points[0], path = [ p[0], \",\", p[1] ];\n    while (++i < n) path.push(\"V\", (p = points[i])[1], \"H\", p[0]);\n    return path.join(\"\");\n  }\n  function d3_svg_lineStepAfter(points) {\n    var i = 0, n = points.length, p = points[0], path = [ p[0], \",\", p[1] ];\n    while (++i < n) path.push(\"H\", (p = points[i])[0], \"V\", p[1]);\n    return path.join(\"\");\n  }\n  function d3_svg_lineCardinalOpen(points, tension) {\n    return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));\n  }\n  function d3_svg_lineCardinalClosed(points, tension) {\n    return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]), \n    points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));\n  }\n  function d3_svg_lineCardinal(points, tension) {\n    return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));\n  }\n  function d3_svg_lineHermite(points, tangents) {\n    if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {\n      return d3_svg_lineLinear(points);\n    }\n    var quad = points.length != tangents.length, path = \"\", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;\n    if (quad) {\n      path += \"Q\" + (p[0] - t0[0] * 2 / 3) + \",\" + (p[1] - t0[1] * 2 / 3) + \",\" + p[0] + \",\" + p[1];\n      p0 = points[1];\n      pi = 2;\n    }\n    if (tangents.length > 1) {\n      t = tangents[1];\n      p = points[pi];\n      pi++;\n      path += \"C\" + (p0[0] + t0[0]) + \",\" + (p0[1] + t0[1]) + \",\" + (p[0] - t[0]) + \",\" + (p[1] - t[1]) + \",\" + p[0] + \",\" + p[1];\n      for (var i = 2; i < tangents.length; i++, pi++) {\n        p = points[pi];\n        t = tangents[i];\n        path += \"S\" + (p[0] - t[0]) + \",\" + (p[1] - t[1]) + \",\" + p[0] + \",\" + p[1];\n      }\n    }\n    if (quad) {\n      var lp = points[pi];\n      path += \"Q\" + (p[0] + t[0] * 2 / 3) + \",\" + (p[1] + t[1] * 2 / 3) + \",\" + lp[0] + \",\" + lp[1];\n    }\n    return path;\n  }\n  function d3_svg_lineCardinalTangents(points, tension) {\n    var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;\n    while (++i < n) {\n      p0 = p1;\n      p1 = p2;\n      p2 = points[i];\n      tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);\n    }\n    return tangents;\n  }\n  function d3_svg_lineBasis(points) {\n    if (points.length < 3) return d3_svg_lineLinear(points);\n    var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, \",\", y0, \"L\", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), \",\", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];\n    points.push(points[n - 1]);\n    while (++i <= n) {\n      pi = points[i];\n      px.shift();\n      px.push(pi[0]);\n      py.shift();\n      py.push(pi[1]);\n      d3_svg_lineBasisBezier(path, px, py);\n    }\n    points.pop();\n    path.push(\"L\", pi);\n    return path.join(\"\");\n  }\n  function d3_svg_lineBasisOpen(points) {\n    if (points.length < 4) return d3_svg_lineLinear(points);\n    var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];\n    while (++i < 3) {\n      pi = points[i];\n      px.push(pi[0]);\n      py.push(pi[1]);\n    }\n    path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + \",\" + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));\n    --i;\n    while (++i < n) {\n      pi = points[i];\n      px.shift();\n      px.push(pi[0]);\n      py.shift();\n      py.push(pi[1]);\n      d3_svg_lineBasisBezier(path, px, py);\n    }\n    return path.join(\"\");\n  }\n  function d3_svg_lineBasisClosed(points) {\n    var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];\n    while (++i < 4) {\n      pi = points[i % n];\n      px.push(pi[0]);\n      py.push(pi[1]);\n    }\n    path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), \",\", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];\n    --i;\n    while (++i < m) {\n      pi = points[i % n];\n      px.shift();\n      px.push(pi[0]);\n      py.shift();\n      py.push(pi[1]);\n      d3_svg_lineBasisBezier(path, px, py);\n    }\n    return path.join(\"\");\n  }\n  function d3_svg_lineBundle(points, tension) {\n    var n = points.length - 1;\n    if (n) {\n      var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;\n      while (++i <= n) {\n        p = points[i];\n        t = i / n;\n        p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);\n        p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);\n      }\n    }\n    return d3_svg_lineBasis(points);\n  }\n  function d3_svg_lineDot4(a, b) {\n    return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];\n  }\n  var d3_svg_lineBasisBezier1 = [ 0, 2 / 3, 1 / 3, 0 ], d3_svg_lineBasisBezier2 = [ 0, 1 / 3, 2 / 3, 0 ], d3_svg_lineBasisBezier3 = [ 0, 1 / 6, 2 / 3, 1 / 6 ];\n  function d3_svg_lineBasisBezier(path, x, y) {\n    path.push(\"C\", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), \",\", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), \",\", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), \",\", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), \",\", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), \",\", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));\n  }\n  function d3_svg_lineSlope(p0, p1) {\n    return (p1[1] - p0[1]) / (p1[0] - p0[0]);\n  }\n  function d3_svg_lineFiniteDifferences(points) {\n    var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);\n    while (++i < j) {\n      m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;\n    }\n    m[i] = d;\n    return m;\n  }\n  function d3_svg_lineMonotoneTangents(points) {\n    var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;\n    while (++i < j) {\n      d = d3_svg_lineSlope(points[i], points[i + 1]);\n      if (abs(d) < ε) {\n        m[i] = m[i + 1] = 0;\n      } else {\n        a = m[i] / d;\n        b = m[i + 1] / d;\n        s = a * a + b * b;\n        if (s > 9) {\n          s = d * 3 / Math.sqrt(s);\n          m[i] = s * a;\n          m[i + 1] = s * b;\n        }\n      }\n    }\n    i = -1;\n    while (++i <= j) {\n      s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));\n      tangents.push([ s || 0, m[i] * s || 0 ]);\n    }\n    return tangents;\n  }\n  function d3_svg_lineMonotone(points) {\n    return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));\n  }\n  d3.svg.line.radial = function() {\n    var line = d3_svg_line(d3_svg_lineRadial);\n    line.radius = line.x, delete line.x;\n    line.angle = line.y, delete line.y;\n    return line;\n  };\n  function d3_svg_lineRadial(points) {\n    var point, i = -1, n = points.length, r, a;\n    while (++i < n) {\n      point = points[i];\n      r = point[0];\n      a = point[1] - halfπ;\n      point[0] = r * Math.cos(a);\n      point[1] = r * Math.sin(a);\n    }\n    return points;\n  }\n  function d3_svg_area(projection) {\n    var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = \"L\", tension = .7;\n    function area(data) {\n      var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {\n        return x;\n      } : d3_functor(x1), fy1 = y0 === y1 ? function() {\n        return y;\n      } : d3_functor(y1), x, y;\n      function segment() {\n        segments.push(\"M\", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), \"Z\");\n      }\n      while (++i < n) {\n        if (defined.call(this, d = data[i], i)) {\n          points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);\n          points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);\n        } else if (points0.length) {\n          segment();\n          points0 = [];\n          points1 = [];\n        }\n      }\n      if (points0.length) segment();\n      return segments.length ? segments.join(\"\") : null;\n    }\n    area.x = function(_) {\n      if (!arguments.length) return x1;\n      x0 = x1 = _;\n      return area;\n    };\n    area.x0 = function(_) {\n      if (!arguments.length) return x0;\n      x0 = _;\n      return area;\n    };\n    area.x1 = function(_) {\n      if (!arguments.length) return x1;\n      x1 = _;\n      return area;\n    };\n    area.y = function(_) {\n      if (!arguments.length) return y1;\n      y0 = y1 = _;\n      return area;\n    };\n    area.y0 = function(_) {\n      if (!arguments.length) return y0;\n      y0 = _;\n      return area;\n    };\n    area.y1 = function(_) {\n      if (!arguments.length) return y1;\n      y1 = _;\n      return area;\n    };\n    area.defined = function(_) {\n      if (!arguments.length) return defined;\n      defined = _;\n      return area;\n    };\n    area.interpolate = function(_) {\n      if (!arguments.length) return interpolateKey;\n      if (typeof _ === \"function\") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;\n      interpolateReverse = interpolate.reverse || interpolate;\n      L = interpolate.closed ? \"M\" : \"L\";\n      return area;\n    };\n    area.tension = function(_) {\n      if (!arguments.length) return tension;\n      tension = _;\n      return area;\n    };\n    return area;\n  }\n  d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;\n  d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;\n  d3.svg.area = function() {\n    return d3_svg_area(d3_identity);\n  };\n  d3.svg.area.radial = function() {\n    var area = d3_svg_area(d3_svg_lineRadial);\n    area.radius = area.x, delete area.x;\n    area.innerRadius = area.x0, delete area.x0;\n    area.outerRadius = area.x1, delete area.x1;\n    area.angle = area.y, delete area.y;\n    area.startAngle = area.y0, delete area.y0;\n    area.endAngle = area.y1, delete area.y1;\n    return area;\n  };\n  d3.svg.chord = function() {\n    var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;\n    function chord(d, i) {\n      var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);\n      return \"M\" + s.p0 + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) ? curve(s.r, s.p1, s.r, s.p0) : curve(s.r, s.p1, t.r, t.p0) + arc(t.r, t.p1, t.a1 - t.a0) + curve(t.r, t.p1, s.r, s.p0)) + \"Z\";\n    }\n    function subgroup(self, f, d, i) {\n      var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;\n      return {\n        r: r,\n        a0: a0,\n        a1: a1,\n        p0: [ r * Math.cos(a0), r * Math.sin(a0) ],\n        p1: [ r * Math.cos(a1), r * Math.sin(a1) ]\n      };\n    }\n    function equals(a, b) {\n      return a.a0 == b.a0 && a.a1 == b.a1;\n    }\n    function arc(r, p, a) {\n      return \"A\" + r + \",\" + r + \" 0 \" + +(a > π) + \",1 \" + p;\n    }\n    function curve(r0, p0, r1, p1) {\n      return \"Q 0,0 \" + p1;\n    }\n    chord.radius = function(v) {\n      if (!arguments.length) return radius;\n      radius = d3_functor(v);\n      return chord;\n    };\n    chord.source = function(v) {\n      if (!arguments.length) return source;\n      source = d3_functor(v);\n      return chord;\n    };\n    chord.target = function(v) {\n      if (!arguments.length) return target;\n      target = d3_functor(v);\n      return chord;\n    };\n    chord.startAngle = function(v) {\n      if (!arguments.length) return startAngle;\n      startAngle = d3_functor(v);\n      return chord;\n    };\n    chord.endAngle = function(v) {\n      if (!arguments.length) return endAngle;\n      endAngle = d3_functor(v);\n      return chord;\n    };\n    return chord;\n  };\n  function d3_svg_chordRadius(d) {\n    return d.radius;\n  }\n  d3.svg.diagonal = function() {\n    var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;\n    function diagonal(d, i) {\n      var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {\n        x: p0.x,\n        y: m\n      }, {\n        x: p3.x,\n        y: m\n      }, p3 ];\n      p = p.map(projection);\n      return \"M\" + p[0] + \"C\" + p[1] + \" \" + p[2] + \" \" + p[3];\n    }\n    diagonal.source = function(x) {\n      if (!arguments.length) return source;\n      source = d3_functor(x);\n      return diagonal;\n    };\n    diagonal.target = function(x) {\n      if (!arguments.length) return target;\n      target = d3_functor(x);\n      return diagonal;\n    };\n    diagonal.projection = function(x) {\n      if (!arguments.length) return projection;\n      projection = x;\n      return diagonal;\n    };\n    return diagonal;\n  };\n  function d3_svg_diagonalProjection(d) {\n    return [ d.x, d.y ];\n  }\n  d3.svg.diagonal.radial = function() {\n    var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;\n    diagonal.projection = function(x) {\n      return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;\n    };\n    return diagonal;\n  };\n  function d3_svg_diagonalRadialProjection(projection) {\n    return function() {\n      var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;\n      return [ r * Math.cos(a), r * Math.sin(a) ];\n    };\n  }\n  d3.svg.symbol = function() {\n    var type = d3_svg_symbolType, size = d3_svg_symbolSize;\n    function symbol(d, i) {\n      return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));\n    }\n    symbol.type = function(x) {\n      if (!arguments.length) return type;\n      type = d3_functor(x);\n      return symbol;\n    };\n    symbol.size = function(x) {\n      if (!arguments.length) return size;\n      size = d3_functor(x);\n      return symbol;\n    };\n    return symbol;\n  };\n  function d3_svg_symbolSize() {\n    return 64;\n  }\n  function d3_svg_symbolType() {\n    return \"circle\";\n  }\n  function d3_svg_symbolCircle(size) {\n    var r = Math.sqrt(size / π);\n    return \"M0,\" + r + \"A\" + r + \",\" + r + \" 0 1,1 0,\" + -r + \"A\" + r + \",\" + r + \" 0 1,1 0,\" + r + \"Z\";\n  }\n  var d3_svg_symbols = d3.map({\n    circle: d3_svg_symbolCircle,\n    cross: function(size) {\n      var r = Math.sqrt(size / 5) / 2;\n      return \"M\" + -3 * r + \",\" + -r + \"H\" + -r + \"V\" + -3 * r + \"H\" + r + \"V\" + -r + \"H\" + 3 * r + \"V\" + r + \"H\" + r + \"V\" + 3 * r + \"H\" + -r + \"V\" + r + \"H\" + -3 * r + \"Z\";\n    },\n    diamond: function(size) {\n      var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;\n      return \"M0,\" + -ry + \"L\" + rx + \",0\" + \" 0,\" + ry + \" \" + -rx + \",0\" + \"Z\";\n    },\n    square: function(size) {\n      var r = Math.sqrt(size) / 2;\n      return \"M\" + -r + \",\" + -r + \"L\" + r + \",\" + -r + \" \" + r + \",\" + r + \" \" + -r + \",\" + r + \"Z\";\n    },\n    \"triangle-down\": function(size) {\n      var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;\n      return \"M0,\" + ry + \"L\" + rx + \",\" + -ry + \" \" + -rx + \",\" + -ry + \"Z\";\n    },\n    \"triangle-up\": function(size) {\n      var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;\n      return \"M0,\" + -ry + \"L\" + rx + \",\" + ry + \" \" + -rx + \",\" + ry + \"Z\";\n    }\n  });\n  d3.svg.symbolTypes = d3_svg_symbols.keys();\n  var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);\n  d3_selectionPrototype.transition = function(name) {\n    var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {\n      time: Date.now(),\n      ease: d3_ease_cubicInOut,\n      delay: 0,\n      duration: 250\n    };\n    for (var j = -1, m = this.length; ++j < m; ) {\n      subgroups.push(subgroup = []);\n      for (var group = this[j], i = -1, n = group.length; ++i < n; ) {\n        if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);\n        subgroup.push(node);\n      }\n    }\n    return d3_transition(subgroups, ns, id);\n  };\n  d3_selectionPrototype.interrupt = function(name) {\n    return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));\n  };\n  var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());\n  function d3_selection_interruptNS(ns) {\n    return function() {\n      var lock, activeId, active;\n      if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {\n        active.timer.c = null;\n        active.timer.t = NaN;\n        if (--lock.count) delete lock[activeId]; else delete this[ns];\n        lock.active += .5;\n        active.event && active.event.interrupt.call(this, this.__data__, active.index);\n      }\n    };\n  }\n  function d3_transition(groups, ns, id) {\n    d3_subclass(groups, d3_transitionPrototype);\n    groups.namespace = ns;\n    groups.id = id;\n    return groups;\n  }\n  var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;\n  d3_transitionPrototype.call = d3_selectionPrototype.call;\n  d3_transitionPrototype.empty = d3_selectionPrototype.empty;\n  d3_transitionPrototype.node = d3_selectionPrototype.node;\n  d3_transitionPrototype.size = d3_selectionPrototype.size;\n  d3.transition = function(selection, name) {\n    return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);\n  };\n  d3.transition.prototype = d3_transitionPrototype;\n  d3_transitionPrototype.select = function(selector) {\n    var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;\n    selector = d3_selection_selector(selector);\n    for (var j = -1, m = this.length; ++j < m; ) {\n      subgroups.push(subgroup = []);\n      for (var group = this[j], i = -1, n = group.length; ++i < n; ) {\n        if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {\n          if (\"__data__\" in node) subnode.__data__ = node.__data__;\n          d3_transitionNode(subnode, i, ns, id, node[ns][id]);\n          subgroup.push(subnode);\n        } else {\n          subgroup.push(null);\n        }\n      }\n    }\n    return d3_transition(subgroups, ns, id);\n  };\n  d3_transitionPrototype.selectAll = function(selector) {\n    var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;\n    selector = d3_selection_selectorAll(selector);\n    for (var j = -1, m = this.length; ++j < m; ) {\n      for (var group = this[j], i = -1, n = group.length; ++i < n; ) {\n        if (node = group[i]) {\n          transition = node[ns][id];\n          subnodes = selector.call(node, node.__data__, i, j);\n          subgroups.push(subgroup = []);\n          for (var k = -1, o = subnodes.length; ++k < o; ) {\n            if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);\n            subgroup.push(subnode);\n          }\n        }\n      }\n    }\n    return d3_transition(subgroups, ns, id);\n  };\n  d3_transitionPrototype.filter = function(filter) {\n    var subgroups = [], subgroup, group, node;\n    if (typeof filter !== \"function\") filter = d3_selection_filter(filter);\n    for (var j = 0, m = this.length; j < m; j++) {\n      subgroups.push(subgroup = []);\n      for (var group = this[j], i = 0, n = group.length; i < n; i++) {\n        if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {\n          subgroup.push(node);\n        }\n      }\n    }\n    return d3_transition(subgroups, this.namespace, this.id);\n  };\n  d3_transitionPrototype.tween = function(name, tween) {\n    var id = this.id, ns = this.namespace;\n    if (arguments.length < 2) return this.node()[ns][id].tween.get(name);\n    return d3_selection_each(this, tween == null ? function(node) {\n      node[ns][id].tween.remove(name);\n    } : function(node) {\n      node[ns][id].tween.set(name, tween);\n    });\n  };\n  function d3_transition_tween(groups, name, value, tween) {\n    var id = groups.id, ns = groups.namespace;\n    return d3_selection_each(groups, typeof value === \"function\" ? function(node, i, j) {\n      node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));\n    } : (value = tween(value), function(node) {\n      node[ns][id].tween.set(name, value);\n    }));\n  }\n  d3_transitionPrototype.attr = function(nameNS, value) {\n    if (arguments.length < 2) {\n      for (value in nameNS) this.attr(value, nameNS[value]);\n      return this;\n    }\n    var interpolate = nameNS == \"transform\" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);\n    function attrNull() {\n      this.removeAttribute(name);\n    }\n    function attrNullNS() {\n      this.removeAttributeNS(name.space, name.local);\n    }\n    function attrTween(b) {\n      return b == null ? attrNull : (b += \"\", function() {\n        var a = this.getAttribute(name), i;\n        return a !== b && (i = interpolate(a, b), function(t) {\n          this.setAttribute(name, i(t));\n        });\n      });\n    }\n    function attrTweenNS(b) {\n      return b == null ? attrNullNS : (b += \"\", function() {\n        var a = this.getAttributeNS(name.space, name.local), i;\n        return a !== b && (i = interpolate(a, b), function(t) {\n          this.setAttributeNS(name.space, name.local, i(t));\n        });\n      });\n    }\n    return d3_transition_tween(this, \"attr.\" + nameNS, value, name.local ? attrTweenNS : attrTween);\n  };\n  d3_transitionPrototype.attrTween = function(nameNS, tween) {\n    var name = d3.ns.qualify(nameNS);\n    function attrTween(d, i) {\n      var f = tween.call(this, d, i, this.getAttribute(name));\n      return f && function(t) {\n        this.setAttribute(name, f(t));\n      };\n    }\n    function attrTweenNS(d, i) {\n      var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));\n      return f && function(t) {\n        this.setAttributeNS(name.space, name.local, f(t));\n      };\n    }\n    return this.tween(\"attr.\" + nameNS, name.local ? attrTweenNS : attrTween);\n  };\n  d3_transitionPrototype.style = function(name, value, priority) {\n    var n = arguments.length;\n    if (n < 3) {\n      if (typeof name !== \"string\") {\n        if (n < 2) value = \"\";\n        for (priority in name) this.style(priority, name[priority], value);\n        return this;\n      }\n      priority = \"\";\n    }\n    function styleNull() {\n      this.style.removeProperty(name);\n    }\n    function styleString(b) {\n      return b == null ? styleNull : (b += \"\", function() {\n        var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;\n        return a !== b && (i = d3_interpolate(a, b), function(t) {\n          this.style.setProperty(name, i(t), priority);\n        });\n      });\n    }\n    return d3_transition_tween(this, \"style.\" + name, value, styleString);\n  };\n  d3_transitionPrototype.styleTween = function(name, tween, priority) {\n    if (arguments.length < 3) priority = \"\";\n    function styleTween(d, i) {\n      var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));\n      return f && function(t) {\n        this.style.setProperty(name, f(t), priority);\n      };\n    }\n    return this.tween(\"style.\" + name, styleTween);\n  };\n  d3_transitionPrototype.text = function(value) {\n    return d3_transition_tween(this, \"text\", value, d3_transition_text);\n  };\n  function d3_transition_text(b) {\n    if (b == null) b = \"\";\n    return function() {\n      this.textContent = b;\n    };\n  }\n  d3_transitionPrototype.remove = function() {\n    var ns = this.namespace;\n    return this.each(\"end.transition\", function() {\n      var p;\n      if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);\n    });\n  };\n  d3_transitionPrototype.ease = function(value) {\n    var id = this.id, ns = this.namespace;\n    if (arguments.length < 1) return this.node()[ns][id].ease;\n    if (typeof value !== \"function\") value = d3.ease.apply(d3, arguments);\n    return d3_selection_each(this, function(node) {\n      node[ns][id].ease = value;\n    });\n  };\n  d3_transitionPrototype.delay = function(value) {\n    var id = this.id, ns = this.namespace;\n    if (arguments.length < 1) return this.node()[ns][id].delay;\n    return d3_selection_each(this, typeof value === \"function\" ? function(node, i, j) {\n      node[ns][id].delay = +value.call(node, node.__data__, i, j);\n    } : (value = +value, function(node) {\n      node[ns][id].delay = value;\n    }));\n  };\n  d3_transitionPrototype.duration = function(value) {\n    var id = this.id, ns = this.namespace;\n    if (arguments.length < 1) return this.node()[ns][id].duration;\n    return d3_selection_each(this, typeof value === \"function\" ? function(node, i, j) {\n      node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));\n    } : (value = Math.max(1, value), function(node) {\n      node[ns][id].duration = value;\n    }));\n  };\n  d3_transitionPrototype.each = function(type, listener) {\n    var id = this.id, ns = this.namespace;\n    if (arguments.length < 2) {\n      var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;\n      try {\n        d3_transitionInheritId = id;\n        d3_selection_each(this, function(node, i, j) {\n          d3_transitionInherit = node[ns][id];\n          type.call(node, node.__data__, i, j);\n        });\n      } finally {\n        d3_transitionInherit = inherit;\n        d3_transitionInheritId = inheritId;\n      }\n    } else {\n      d3_selection_each(this, function(node) {\n        var transition = node[ns][id];\n        (transition.event || (transition.event = d3.dispatch(\"start\", \"end\", \"interrupt\"))).on(type, listener);\n      });\n    }\n    return this;\n  };\n  d3_transitionPrototype.transition = function() {\n    var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;\n    for (var j = 0, m = this.length; j < m; j++) {\n      subgroups.push(subgroup = []);\n      for (var group = this[j], i = 0, n = group.length; i < n; i++) {\n        if (node = group[i]) {\n          transition = node[ns][id0];\n          d3_transitionNode(node, i, ns, id1, {\n            time: transition.time,\n            ease: transition.ease,\n            delay: transition.delay + transition.duration,\n            duration: transition.duration\n          });\n        }\n        subgroup.push(node);\n      }\n    }\n    return d3_transition(subgroups, ns, id1);\n  };\n  function d3_transitionNamespace(name) {\n    return name == null ? \"__transition__\" : \"__transition_\" + name + \"__\";\n  }\n  function d3_transitionNode(node, i, ns, id, inherit) {\n    var lock = node[ns] || (node[ns] = {\n      active: 0,\n      count: 0\n    }), transition = lock[id], time, timer, duration, ease, tweens;\n    function schedule(elapsed) {\n      var delay = transition.delay;\n      timer.t = delay + time;\n      if (delay <= elapsed) return start(elapsed - delay);\n      timer.c = start;\n    }\n    function start(elapsed) {\n      var activeId = lock.active, active = lock[activeId];\n      if (active) {\n        active.timer.c = null;\n        active.timer.t = NaN;\n        --lock.count;\n        delete lock[activeId];\n        active.event && active.event.interrupt.call(node, node.__data__, active.index);\n      }\n      for (var cancelId in lock) {\n        if (+cancelId < id) {\n          var cancel = lock[cancelId];\n          cancel.timer.c = null;\n          cancel.timer.t = NaN;\n          --lock.count;\n          delete lock[cancelId];\n        }\n      }\n      timer.c = tick;\n      d3_timer(function() {\n        if (timer.c && tick(elapsed || 1)) {\n          timer.c = null;\n          timer.t = NaN;\n        }\n        return 1;\n      }, 0, time);\n      lock.active = id;\n      transition.event && transition.event.start.call(node, node.__data__, i);\n      tweens = [];\n      transition.tween.forEach(function(key, value) {\n        if (value = value.call(node, node.__data__, i)) {\n          tweens.push(value);\n        }\n      });\n      ease = transition.ease;\n      duration = transition.duration;\n    }\n    function tick(elapsed) {\n      var t = elapsed / duration, e = ease(t), n = tweens.length;\n      while (n > 0) {\n        tweens[--n].call(node, e);\n      }\n      if (t >= 1) {\n        transition.event && transition.event.end.call(node, node.__data__, i);\n        if (--lock.count) delete lock[id]; else delete node[ns];\n        return 1;\n      }\n    }\n    if (!transition) {\n      time = inherit.time;\n      timer = d3_timer(schedule, 0, time);\n      transition = lock[id] = {\n        tween: new d3_Map(),\n        time: time,\n        timer: timer,\n        delay: inherit.delay,\n        duration: inherit.duration,\n        ease: inherit.ease,\n        index: i\n      };\n      inherit = null;\n      ++lock.count;\n    }\n  }\n  d3.svg.axis = function() {\n    var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;\n    function axis(g) {\n      g.each(function() {\n        var g = d3.select(this);\n        var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();\n        var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(\".tick\").data(ticks, scale1), tickEnter = tick.enter().insert(\"g\", \".domain\").attr(\"class\", \"tick\").style(\"opacity\", ε), tickExit = d3.transition(tick.exit()).style(\"opacity\", ε).remove(), tickUpdate = d3.transition(tick.order()).style(\"opacity\", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;\n        var range = d3_scaleRange(scale1), path = g.selectAll(\".domain\").data([ 0 ]), pathUpdate = (path.enter().append(\"path\").attr(\"class\", \"domain\"), \n        d3.transition(path));\n        tickEnter.append(\"line\");\n        tickEnter.append(\"text\");\n        var lineEnter = tickEnter.select(\"line\"), lineUpdate = tickUpdate.select(\"line\"), text = tick.select(\"text\").text(tickFormat), textEnter = tickEnter.select(\"text\"), textUpdate = tickUpdate.select(\"text\"), sign = orient === \"top\" || orient === \"left\" ? -1 : 1, x1, x2, y1, y2;\n        if (orient === \"bottom\" || orient === \"top\") {\n          tickTransform = d3_svg_axisX, x1 = \"x\", y1 = \"y\", x2 = \"x2\", y2 = \"y2\";\n          text.attr(\"dy\", sign < 0 ? \"0em\" : \".71em\").style(\"text-anchor\", \"middle\");\n          pathUpdate.attr(\"d\", \"M\" + range[0] + \",\" + sign * outerTickSize + \"V0H\" + range[1] + \"V\" + sign * outerTickSize);\n        } else {\n          tickTransform = d3_svg_axisY, x1 = \"y\", y1 = \"x\", x2 = \"y2\", y2 = \"x2\";\n          text.attr(\"dy\", \".32em\").style(\"text-anchor\", sign < 0 ? \"end\" : \"start\");\n          pathUpdate.attr(\"d\", \"M\" + sign * outerTickSize + \",\" + range[0] + \"H0V\" + range[1] + \"H\" + sign * outerTickSize);\n        }\n        lineEnter.attr(y2, sign * innerTickSize);\n        textEnter.attr(y1, sign * tickSpacing);\n        lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);\n        textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);\n        if (scale1.rangeBand) {\n          var x = scale1, dx = x.rangeBand() / 2;\n          scale0 = scale1 = function(d) {\n            return x(d) + dx;\n          };\n        } else if (scale0.rangeBand) {\n          scale0 = scale1;\n        } else {\n          tickExit.call(tickTransform, scale1, scale0);\n        }\n        tickEnter.call(tickTransform, scale0, scale1);\n        tickUpdate.call(tickTransform, scale1, scale1);\n      });\n    }\n    axis.scale = function(x) {\n      if (!arguments.length) return scale;\n      scale = x;\n      return axis;\n    };\n    axis.orient = function(x) {\n      if (!arguments.length) return orient;\n      orient = x in d3_svg_axisOrients ? x + \"\" : d3_svg_axisDefaultOrient;\n      return axis;\n    };\n    axis.ticks = function() {\n      if (!arguments.length) return tickArguments_;\n      tickArguments_ = d3_array(arguments);\n      return axis;\n    };\n    axis.tickValues = function(x) {\n      if (!arguments.length) return tickValues;\n      tickValues = x;\n      return axis;\n    };\n    axis.tickFormat = function(x) {\n      if (!arguments.length) return tickFormat_;\n      tickFormat_ = x;\n      return axis;\n    };\n    axis.tickSize = function(x) {\n      var n = arguments.length;\n      if (!n) return innerTickSize;\n      innerTickSize = +x;\n      outerTickSize = +arguments[n - 1];\n      return axis;\n    };\n    axis.innerTickSize = function(x) {\n      if (!arguments.length) return innerTickSize;\n      innerTickSize = +x;\n      return axis;\n    };\n    axis.outerTickSize = function(x) {\n      if (!arguments.length) return outerTickSize;\n      outerTickSize = +x;\n      return axis;\n    };\n    axis.tickPadding = function(x) {\n      if (!arguments.length) return tickPadding;\n      tickPadding = +x;\n      return axis;\n    };\n    axis.tickSubdivide = function() {\n      return arguments.length && axis;\n    };\n    return axis;\n  };\n  var d3_svg_axisDefaultOrient = \"bottom\", d3_svg_axisOrients = {\n    top: 1,\n    right: 1,\n    bottom: 1,\n    left: 1\n  };\n  function d3_svg_axisX(selection, x0, x1) {\n    selection.attr(\"transform\", function(d) {\n      var v0 = x0(d);\n      return \"translate(\" + (isFinite(v0) ? v0 : x1(d)) + \",0)\";\n    });\n  }\n  function d3_svg_axisY(selection, y0, y1) {\n    selection.attr(\"transform\", function(d) {\n      var v0 = y0(d);\n      return \"translate(0,\" + (isFinite(v0) ? v0 : y1(d)) + \")\";\n    });\n  }\n  d3.svg.brush = function() {\n    var event = d3_eventDispatch(brush, \"brushstart\", \"brush\", \"brushend\"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];\n    function brush(g) {\n      g.each(function() {\n        var g = d3.select(this).style(\"pointer-events\", \"all\").style(\"-webkit-tap-highlight-color\", \"rgba(0,0,0,0)\").on(\"mousedown.brush\", brushstart).on(\"touchstart.brush\", brushstart);\n        var background = g.selectAll(\".background\").data([ 0 ]);\n        background.enter().append(\"rect\").attr(\"class\", \"background\").style(\"visibility\", \"hidden\").style(\"cursor\", \"crosshair\");\n        g.selectAll(\".extent\").data([ 0 ]).enter().append(\"rect\").attr(\"class\", \"extent\").style(\"cursor\", \"move\");\n        var resize = g.selectAll(\".resize\").data(resizes, d3_identity);\n        resize.exit().remove();\n        resize.enter().append(\"g\").attr(\"class\", function(d) {\n          return \"resize \" + d;\n        }).style(\"cursor\", function(d) {\n          return d3_svg_brushCursor[d];\n        }).append(\"rect\").attr(\"x\", function(d) {\n          return /[ew]$/.test(d) ? -3 : null;\n        }).attr(\"y\", function(d) {\n          return /^[ns]/.test(d) ? -3 : null;\n        }).attr(\"width\", 6).attr(\"height\", 6).style(\"visibility\", \"hidden\");\n        resize.style(\"display\", brush.empty() ? \"none\" : null);\n        var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;\n        if (x) {\n          range = d3_scaleRange(x);\n          backgroundUpdate.attr(\"x\", range[0]).attr(\"width\", range[1] - range[0]);\n          redrawX(gUpdate);\n        }\n        if (y) {\n          range = d3_scaleRange(y);\n          backgroundUpdate.attr(\"y\", range[0]).attr(\"height\", range[1] - range[0]);\n          redrawY(gUpdate);\n        }\n        redraw(gUpdate);\n      });\n    }\n    brush.event = function(g) {\n      g.each(function() {\n        var event_ = event.of(this, arguments), extent1 = {\n          x: xExtent,\n          y: yExtent,\n          i: xExtentDomain,\n          j: yExtentDomain\n        }, extent0 = this.__chart__ || extent1;\n        this.__chart__ = extent1;\n        if (d3_transitionInheritId) {\n          d3.select(this).transition().each(\"start.brush\", function() {\n            xExtentDomain = extent0.i;\n            yExtentDomain = extent0.j;\n            xExtent = extent0.x;\n            yExtent = extent0.y;\n            event_({\n              type: \"brushstart\"\n            });\n          }).tween(\"brush:brush\", function() {\n            var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);\n            xExtentDomain = yExtentDomain = null;\n            return function(t) {\n              xExtent = extent1.x = xi(t);\n              yExtent = extent1.y = yi(t);\n              event_({\n                type: \"brush\",\n                mode: \"resize\"\n              });\n            };\n          }).each(\"end.brush\", function() {\n            xExtentDomain = extent1.i;\n            yExtentDomain = extent1.j;\n            event_({\n              type: \"brush\",\n              mode: \"resize\"\n            });\n            event_({\n              type: \"brushend\"\n            });\n          });\n        } else {\n          event_({\n            type: \"brushstart\"\n          });\n          event_({\n            type: \"brush\",\n            mode: \"resize\"\n          });\n          event_({\n            type: \"brushend\"\n          });\n        }\n      });\n    };\n    function redraw(g) {\n      g.selectAll(\".resize\").attr(\"transform\", function(d) {\n        return \"translate(\" + xExtent[+/e$/.test(d)] + \",\" + yExtent[+/^s/.test(d)] + \")\";\n      });\n    }\n    function redrawX(g) {\n      g.select(\".extent\").attr(\"x\", xExtent[0]);\n      g.selectAll(\".extent,.n>rect,.s>rect\").attr(\"width\", xExtent[1] - xExtent[0]);\n    }\n    function redrawY(g) {\n      g.select(\".extent\").attr(\"y\", yExtent[0]);\n      g.selectAll(\".extent,.e>rect,.w>rect\").attr(\"height\", yExtent[1] - yExtent[0]);\n    }\n    function brushstart() {\n      var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed(\"extent\"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;\n      var w = d3.select(d3_window(target)).on(\"keydown.brush\", keydown).on(\"keyup.brush\", keyup);\n      if (d3.event.changedTouches) {\n        w.on(\"touchmove.brush\", brushmove).on(\"touchend.brush\", brushend);\n      } else {\n        w.on(\"mousemove.brush\", brushmove).on(\"mouseup.brush\", brushend);\n      }\n      g.interrupt().selectAll(\"*\").interrupt();\n      if (dragging) {\n        origin[0] = xExtent[0] - origin[0];\n        origin[1] = yExtent[0] - origin[1];\n      } else if (resizing) {\n        var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);\n        offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];\n        origin[0] = xExtent[ex];\n        origin[1] = yExtent[ey];\n      } else if (d3.event.altKey) center = origin.slice();\n      g.style(\"pointer-events\", \"none\").selectAll(\".resize\").style(\"display\", null);\n      d3.select(\"body\").style(\"cursor\", eventTarget.style(\"cursor\"));\n      event_({\n        type: \"brushstart\"\n      });\n      brushmove();\n      function keydown() {\n        if (d3.event.keyCode == 32) {\n          if (!dragging) {\n            center = null;\n            origin[0] -= xExtent[1];\n            origin[1] -= yExtent[1];\n            dragging = 2;\n          }\n          d3_eventPreventDefault();\n        }\n      }\n      function keyup() {\n        if (d3.event.keyCode == 32 && dragging == 2) {\n          origin[0] += xExtent[1];\n          origin[1] += yExtent[1];\n          dragging = 0;\n          d3_eventPreventDefault();\n        }\n      }\n      function brushmove() {\n        var point = d3.mouse(target), moved = false;\n        if (offset) {\n          point[0] += offset[0];\n          point[1] += offset[1];\n        }\n        if (!dragging) {\n          if (d3.event.altKey) {\n            if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];\n            origin[0] = xExtent[+(point[0] < center[0])];\n            origin[1] = yExtent[+(point[1] < center[1])];\n          } else center = null;\n        }\n        if (resizingX && move1(point, x, 0)) {\n          redrawX(g);\n          moved = true;\n        }\n        if (resizingY && move1(point, y, 1)) {\n          redrawY(g);\n          moved = true;\n        }\n        if (moved) {\n          redraw(g);\n          event_({\n            type: \"brush\",\n            mode: dragging ? \"move\" : \"resize\"\n          });\n        }\n      }\n      function move1(point, scale, i) {\n        var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;\n        if (dragging) {\n          r0 -= position;\n          r1 -= size + position;\n        }\n        min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];\n        if (dragging) {\n          max = (min += position) + size;\n        } else {\n          if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));\n          if (position < min) {\n            max = min;\n            min = position;\n          } else {\n            max = position;\n          }\n        }\n        if (extent[0] != min || extent[1] != max) {\n          if (i) yExtentDomain = null; else xExtentDomain = null;\n          extent[0] = min;\n          extent[1] = max;\n          return true;\n        }\n      }\n      function brushend() {\n        brushmove();\n        g.style(\"pointer-events\", \"all\").selectAll(\".resize\").style(\"display\", brush.empty() ? \"none\" : null);\n        d3.select(\"body\").style(\"cursor\", null);\n        w.on(\"mousemove.brush\", null).on(\"mouseup.brush\", null).on(\"touchmove.brush\", null).on(\"touchend.brush\", null).on(\"keydown.brush\", null).on(\"keyup.brush\", null);\n        dragRestore();\n        event_({\n          type: \"brushend\"\n        });\n      }\n    }\n    brush.x = function(z) {\n      if (!arguments.length) return x;\n      x = z;\n      resizes = d3_svg_brushResizes[!x << 1 | !y];\n      return brush;\n    };\n    brush.y = function(z) {\n      if (!arguments.length) return y;\n      y = z;\n      resizes = d3_svg_brushResizes[!x << 1 | !y];\n      return brush;\n    };\n    brush.clamp = function(z) {\n      if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;\n      if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;\n      return brush;\n    };\n    brush.extent = function(z) {\n      var x0, x1, y0, y1, t;\n      if (!arguments.length) {\n        if (x) {\n          if (xExtentDomain) {\n            x0 = xExtentDomain[0], x1 = xExtentDomain[1];\n          } else {\n            x0 = xExtent[0], x1 = xExtent[1];\n            if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);\n            if (x1 < x0) t = x0, x0 = x1, x1 = t;\n          }\n        }\n        if (y) {\n          if (yExtentDomain) {\n            y0 = yExtentDomain[0], y1 = yExtentDomain[1];\n          } else {\n            y0 = yExtent[0], y1 = yExtent[1];\n            if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);\n            if (y1 < y0) t = y0, y0 = y1, y1 = t;\n          }\n        }\n        return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];\n      }\n      if (x) {\n        x0 = z[0], x1 = z[1];\n        if (y) x0 = x0[0], x1 = x1[0];\n        xExtentDomain = [ x0, x1 ];\n        if (x.invert) x0 = x(x0), x1 = x(x1);\n        if (x1 < x0) t = x0, x0 = x1, x1 = t;\n        if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];\n      }\n      if (y) {\n        y0 = z[0], y1 = z[1];\n        if (x) y0 = y0[1], y1 = y1[1];\n        yExtentDomain = [ y0, y1 ];\n        if (y.invert) y0 = y(y0), y1 = y(y1);\n        if (y1 < y0) t = y0, y0 = y1, y1 = t;\n        if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];\n      }\n      return brush;\n    };\n    brush.clear = function() {\n      if (!brush.empty()) {\n        xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];\n        xExtentDomain = yExtentDomain = null;\n      }\n      return brush;\n    };\n    brush.empty = function() {\n      return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];\n    };\n    return d3.rebind(brush, event, \"on\");\n  };\n  var d3_svg_brushCursor = {\n    n: \"ns-resize\",\n    e: \"ew-resize\",\n    s: \"ns-resize\",\n    w: \"ew-resize\",\n    nw: \"nwse-resize\",\n    ne: \"nesw-resize\",\n    se: \"nwse-resize\",\n    sw: \"nesw-resize\"\n  };\n  var d3_svg_brushResizes = [ [ \"n\", \"e\", \"s\", \"w\", \"nw\", \"ne\", \"se\", \"sw\" ], [ \"e\", \"w\" ], [ \"n\", \"s\" ], [] ];\n  var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;\n  var d3_time_formatUtc = d3_time_format.utc;\n  var d3_time_formatIso = d3_time_formatUtc(\"%Y-%m-%dT%H:%M:%S.%LZ\");\n  d3_time_format.iso = Date.prototype.toISOString && +new Date(\"2000-01-01T00:00:00.000Z\") ? d3_time_formatIsoNative : d3_time_formatIso;\n  function d3_time_formatIsoNative(date) {\n    return date.toISOString();\n  }\n  d3_time_formatIsoNative.parse = function(string) {\n    var date = new Date(string);\n    return isNaN(date) ? null : date;\n  };\n  d3_time_formatIsoNative.toString = d3_time_formatIso.toString;\n  d3_time.second = d3_time_interval(function(date) {\n    return new d3_date(Math.floor(date / 1e3) * 1e3);\n  }, function(date, offset) {\n    date.setTime(date.getTime() + Math.floor(offset) * 1e3);\n  }, function(date) {\n    return date.getSeconds();\n  });\n  d3_time.seconds = d3_time.second.range;\n  d3_time.seconds.utc = d3_time.second.utc.range;\n  d3_time.minute = d3_time_interval(function(date) {\n    return new d3_date(Math.floor(date / 6e4) * 6e4);\n  }, function(date, offset) {\n    date.setTime(date.getTime() + Math.floor(offset) * 6e4);\n  }, function(date) {\n    return date.getMinutes();\n  });\n  d3_time.minutes = d3_time.minute.range;\n  d3_time.minutes.utc = d3_time.minute.utc.range;\n  d3_time.hour = d3_time_interval(function(date) {\n    var timezone = date.getTimezoneOffset() / 60;\n    return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);\n  }, function(date, offset) {\n    date.setTime(date.getTime() + Math.floor(offset) * 36e5);\n  }, function(date) {\n    return date.getHours();\n  });\n  d3_time.hours = d3_time.hour.range;\n  d3_time.hours.utc = d3_time.hour.utc.range;\n  d3_time.month = d3_time_interval(function(date) {\n    date = d3_time.day(date);\n    date.setDate(1);\n    return date;\n  }, function(date, offset) {\n    date.setMonth(date.getMonth() + offset);\n  }, function(date) {\n    return date.getMonth();\n  });\n  d3_time.months = d3_time.month.range;\n  d3_time.months.utc = d3_time.month.utc.range;\n  function d3_time_scale(linear, methods, format) {\n    function scale(x) {\n      return linear(x);\n    }\n    scale.invert = function(x) {\n      return d3_time_scaleDate(linear.invert(x));\n    };\n    scale.domain = function(x) {\n      if (!arguments.length) return linear.domain().map(d3_time_scaleDate);\n      linear.domain(x);\n      return scale;\n    };\n    function tickMethod(extent, count) {\n      var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);\n      return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {\n        return d / 31536e6;\n      }), count)[2] ] : !i ? [ d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2] ] : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i];\n    }\n    scale.nice = function(interval, skip) {\n      var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === \"number\" && tickMethod(extent, interval);\n      if (method) interval = method[0], skip = method[1];\n      function skipped(date) {\n        return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;\n      }\n      return scale.domain(d3_scale_nice(domain, skip > 1 ? {\n        floor: function(date) {\n          while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);\n          return date;\n        },\n        ceil: function(date) {\n          while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);\n          return date;\n        }\n      } : interval));\n    };\n    scale.ticks = function(interval, skip) {\n      var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === \"number\" ? tickMethod(extent, interval) : !interval.range && [ {\n        range: interval\n      }, skip ];\n      if (method) interval = method[0], skip = method[1];\n      return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);\n    };\n    scale.tickFormat = function() {\n      return format;\n    };\n    scale.copy = function() {\n      return d3_time_scale(linear.copy(), methods, format);\n    };\n    return d3_scale_linearRebind(scale, linear);\n  }\n  function d3_time_scaleDate(t) {\n    return new Date(t);\n  }\n  var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];\n  var d3_time_scaleLocalMethods = [ [ d3_time.second, 1 ], [ d3_time.second, 5 ], [ d3_time.second, 15 ], [ d3_time.second, 30 ], [ d3_time.minute, 1 ], [ d3_time.minute, 5 ], [ d3_time.minute, 15 ], [ d3_time.minute, 30 ], [ d3_time.hour, 1 ], [ d3_time.hour, 3 ], [ d3_time.hour, 6 ], [ d3_time.hour, 12 ], [ d3_time.day, 1 ], [ d3_time.day, 2 ], [ d3_time.week, 1 ], [ d3_time.month, 1 ], [ d3_time.month, 3 ], [ d3_time.year, 1 ] ];\n  var d3_time_scaleLocalFormat = d3_time_format.multi([ [ \".%L\", function(d) {\n    return d.getMilliseconds();\n  } ], [ \":%S\", function(d) {\n    return d.getSeconds();\n  } ], [ \"%I:%M\", function(d) {\n    return d.getMinutes();\n  } ], [ \"%I %p\", function(d) {\n    return d.getHours();\n  } ], [ \"%a %d\", function(d) {\n    return d.getDay() && d.getDate() != 1;\n  } ], [ \"%b %d\", function(d) {\n    return d.getDate() != 1;\n  } ], [ \"%B\", function(d) {\n    return d.getMonth();\n  } ], [ \"%Y\", d3_true ] ]);\n  var d3_time_scaleMilliseconds = {\n    range: function(start, stop, step) {\n      return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);\n    },\n    floor: d3_identity,\n    ceil: d3_identity\n  };\n  d3_time_scaleLocalMethods.year = d3_time.year;\n  d3_time.scale = function() {\n    return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);\n  };\n  var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {\n    return [ m[0].utc, m[1] ];\n  });\n  var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ \".%L\", function(d) {\n    return d.getUTCMilliseconds();\n  } ], [ \":%S\", function(d) {\n    return d.getUTCSeconds();\n  } ], [ \"%I:%M\", function(d) {\n    return d.getUTCMinutes();\n  } ], [ \"%I %p\", function(d) {\n    return d.getUTCHours();\n  } ], [ \"%a %d\", function(d) {\n    return d.getUTCDay() && d.getUTCDate() != 1;\n  } ], [ \"%b %d\", function(d) {\n    return d.getUTCDate() != 1;\n  } ], [ \"%B\", function(d) {\n    return d.getUTCMonth();\n  } ], [ \"%Y\", d3_true ] ]);\n  d3_time_scaleUtcMethods.year = d3_time.year.utc;\n  d3_time.scale.utc = function() {\n    return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);\n  };\n  d3.text = d3_xhrType(function(request) {\n    return request.responseText;\n  });\n  d3.json = function(url, callback) {\n    return d3_xhr(url, \"application/json\", d3_json, callback);\n  };\n  function d3_json(request) {\n    return JSON.parse(request.responseText);\n  }\n  d3.html = function(url, callback) {\n    return d3_xhr(url, \"text/html\", d3_html, callback);\n  };\n  function d3_html(request) {\n    var range = d3_document.createRange();\n    range.selectNode(d3_document.body);\n    return range.createContextualFragment(request.responseText);\n  }\n  d3.xml = d3_xhrType(function(request) {\n    return request.responseXML;\n  });\n  if (typeof define === \"function\" && define.amd) this.d3 = d3, define(d3); else if (typeof module === \"object\" && module.exports) module.exports = d3; else this.d3 = d3;\n}();\n},{}],164:[function(_dereq_,module,exports){\nmodule.exports = function () {\n    for (var i = 0; i < arguments.length; i++) {\n        if (arguments[i] !== undefined) return arguments[i];\n    }\n};\n\n},{}],165:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar ch = _dereq_(\"incremental-convex-hull\")\nvar uniq = _dereq_(\"uniq\")\n\nmodule.exports = triangulate\n\nfunction LiftedPoint(p, i) {\n  this.point = p\n  this.index = i\n}\n\nfunction compareLifted(a, b) {\n  var ap = a.point\n  var bp = b.point\n  var d = ap.length\n  for(var i=0; i<d; ++i) {\n    var s = bp[i] - ap[i]\n    if(s) {\n      return s\n    }\n  }\n  return 0\n}\n\nfunction triangulate1D(n, points, includePointAtInfinity) {\n  if(n === 1) {\n    if(includePointAtInfinity) {\n      return [ [-1, 0] ]\n    } else {\n      return []\n    }\n  }\n  var lifted = points.map(function(p, i) {\n    return [ p[0], i ]\n  })\n  lifted.sort(function(a,b) {\n    return a[0] - b[0]\n  })\n  var cells = new Array(n - 1)\n  for(var i=1; i<n; ++i) {\n    var a = lifted[i-1]\n    var b = lifted[i]\n    cells[i-1] = [ a[1], b[1] ]\n  }\n  if(includePointAtInfinity) {\n    cells.push(\n      [ -1, cells[0][1], ],\n      [ cells[n-1][1], -1 ])\n  }\n  return cells\n}\n\nfunction triangulate(points, includePointAtInfinity) {\n  var n = points.length\n  if(n === 0) {\n    return []\n  }\n  \n  var d = points[0].length\n  if(d < 1) {\n    return []\n  }\n\n  //Special case:  For 1D we can just sort the points\n  if(d === 1) {\n    return triangulate1D(n, points, includePointAtInfinity)\n  }\n  \n  //Lift points, sort\n  var lifted = new Array(n)\n  var upper = 1.0\n  for(var i=0; i<n; ++i) {\n    var p = points[i]\n    var x = new Array(d+1)\n    var l = 0.0\n    for(var j=0; j<d; ++j) {\n      var v = p[j]\n      x[j] = v\n      l += v * v\n    }\n    x[d] = l\n    lifted[i] = new LiftedPoint(x, i)\n    upper = Math.max(l, upper)\n  }\n  uniq(lifted, compareLifted)\n  \n  //Double points\n  n = lifted.length\n\n  //Create new list of points\n  var dpoints = new Array(n + d + 1)\n  var dindex = new Array(n + d + 1)\n\n  //Add steiner points at top\n  var u = (d+1) * (d+1) * upper\n  var y = new Array(d+1)\n  for(var i=0; i<=d; ++i) {\n    y[i] = 0.0\n  }\n  y[d] = u\n\n  dpoints[0] = y.slice()\n  dindex[0] = -1\n\n  for(var i=0; i<=d; ++i) {\n    var x = y.slice()\n    x[i] = 1\n    dpoints[i+1] = x\n    dindex[i+1] = -1\n  }\n\n  //Copy rest of the points over\n  for(var i=0; i<n; ++i) {\n    var h = lifted[i]\n    dpoints[i + d + 1] = h.point\n    dindex[i + d + 1] =  h.index\n  }\n\n  //Construct convex hull\n  var hull = ch(dpoints, false)\n  if(includePointAtInfinity) {\n    hull = hull.filter(function(cell) {\n      var count = 0\n      for(var j=0; j<=d; ++j) {\n        var v = dindex[cell[j]]\n        if(v < 0) {\n          if(++count >= 2) {\n            return false\n          }\n        }\n        cell[j] = v\n      }\n      return true\n    })\n  } else {\n    hull = hull.filter(function(cell) {\n      for(var i=0; i<=d; ++i) {\n        var v = dindex[cell[i]]\n        if(v < 0) {\n          return false\n        }\n        cell[i] = v\n      }\n      return true\n    })\n  }\n\n  if(d & 1) {\n    for(var i=0; i<hull.length; ++i) {\n      var h = hull[i]\n      var x = h[0]\n      h[0] = h[1]\n      h[1] = x\n    }\n  }\n\n  return hull\n}\n},{\"incremental-convex-hull\":413,\"uniq\":547}],166:[function(_dereq_,module,exports){\n'use strict'\r\n\r\n\r\nmodule.exports = kerning\r\n\r\n\r\nvar canvas = kerning.canvas = document.createElement('canvas')\r\nvar ctx = canvas.getContext('2d')\r\nvar asciiPairs = createPairs([32, 126])\r\n\r\nkerning.createPairs = createPairs\r\nkerning.ascii = asciiPairs\r\n\r\n\r\nfunction kerning (family, o) {\r\n\tif (Array.isArray(family)) family = family.join(', ')\r\n\r\n\tvar table = {}, pairs, fs = 16, threshold = .05\r\n\r\n\tif (o) {\r\n\t\tif (o.length === 2 && typeof o[0] === 'number') {\r\n\t\t\tpairs = createPairs(o)\r\n\t\t}\r\n\t\telse if (Array.isArray(o)) {\r\n\t\t\tpairs = o\r\n\t\t}\r\n\t\telse {\r\n\t\t\tif (o.o) pairs = createPairs(o.o)\r\n\t\t\telse if (o.pairs) pairs = o.pairs\r\n\r\n\t\t\tif (o.fontSize) fs = o.fontSize\r\n\t\t\tif (o.threshold != null) threshold = o.threshold\r\n\t\t}\r\n\t}\r\n\r\n\tif (!pairs) pairs = asciiPairs\r\n\r\n\tctx.font = fs + 'px ' + family\r\n\r\n\tfor (var i = 0; i < pairs.length; i++) {\r\n\t\tvar pair = pairs[i]\r\n\t\tvar width = ctx.measureText(pair[0]).width + ctx.measureText(pair[1]).width\r\n\t\tvar kerningWidth = ctx.measureText(pair).width\r\n\t\tif (Math.abs(width - kerningWidth) > fs * threshold) {\r\n\t\t\tvar emWidth = (kerningWidth - width) / fs\r\n\t\t\ttable[pair] = emWidth * 1000\r\n\t\t}\r\n\t}\r\n\r\n\treturn table\r\n}\r\n\r\n\r\nfunction createPairs (range) {\r\n\tvar pairs = []\r\n\r\n    for (var i = range[0]; i <= range[1]; i++) {\r\n\t\tvar leftChar = String.fromCharCode(i)\r\n\t\tfor (var j = range[0]; j < range[1]; j++) {\r\n\t\t\tvar rightChar = String.fromCharCode(j)\r\n\t\t\tvar pair = leftChar + rightChar\r\n\r\n\t\t\tpairs.push(pair)\r\n\t\t}\r\n\t}\r\n\r\n\treturn pairs\r\n}\r\n\n},{}],167:[function(_dereq_,module,exports){\n(function (Buffer){\nvar hasTypedArrays = false\nif(typeof Float64Array !== \"undefined\") {\n  var DOUBLE_VIEW = new Float64Array(1)\n    , UINT_VIEW   = new Uint32Array(DOUBLE_VIEW.buffer)\n  DOUBLE_VIEW[0] = 1.0\n  hasTypedArrays = true\n  if(UINT_VIEW[1] === 0x3ff00000) {\n    //Use little endian\n    module.exports = function doubleBitsLE(n) {\n      DOUBLE_VIEW[0] = n\n      return [ UINT_VIEW[0], UINT_VIEW[1] ]\n    }\n    function toDoubleLE(lo, hi) {\n      UINT_VIEW[0] = lo\n      UINT_VIEW[1] = hi\n      return DOUBLE_VIEW[0]\n    }\n    module.exports.pack = toDoubleLE\n    function lowUintLE(n) {\n      DOUBLE_VIEW[0] = n\n      return UINT_VIEW[0]\n    }\n    module.exports.lo = lowUintLE\n    function highUintLE(n) {\n      DOUBLE_VIEW[0] = n\n      return UINT_VIEW[1]\n    }\n    module.exports.hi = highUintLE\n  } else if(UINT_VIEW[0] === 0x3ff00000) {\n    //Use big endian\n    module.exports = function doubleBitsBE(n) {\n      DOUBLE_VIEW[0] = n\n      return [ UINT_VIEW[1], UINT_VIEW[0] ]\n    }\n    function toDoubleBE(lo, hi) {\n      UINT_VIEW[1] = lo\n      UINT_VIEW[0] = hi\n      return DOUBLE_VIEW[0]\n    }\n    module.exports.pack = toDoubleBE\n    function lowUintBE(n) {\n      DOUBLE_VIEW[0] = n\n      return UINT_VIEW[1]\n    }\n    module.exports.lo = lowUintBE\n    function highUintBE(n) {\n      DOUBLE_VIEW[0] = n\n      return UINT_VIEW[0]\n    }\n    module.exports.hi = highUintBE\n  } else {\n    hasTypedArrays = false\n  }\n}\nif(!hasTypedArrays) {\n  var buffer = new Buffer(8)\n  module.exports = function doubleBits(n) {\n    buffer.writeDoubleLE(n, 0, true)\n    return [ buffer.readUInt32LE(0, true), buffer.readUInt32LE(4, true) ]\n  }\n  function toDouble(lo, hi) {\n    buffer.writeUInt32LE(lo, 0, true)\n    buffer.writeUInt32LE(hi, 4, true)\n    return buffer.readDoubleLE(0, true)\n  }\n  module.exports.pack = toDouble  \n  function lowUint(n) {\n    buffer.writeDoubleLE(n, 0, true)\n    return buffer.readUInt32LE(0, true)\n  }\n  module.exports.lo = lowUint\n  function highUint(n) {\n    buffer.writeDoubleLE(n, 0, true)\n    return buffer.readUInt32LE(4, true)\n  }\n  module.exports.hi = highUint\n}\n\nmodule.exports.sign = function(n) {\n  return module.exports.hi(n) >>> 31\n}\n\nmodule.exports.exponent = function(n) {\n  var b = module.exports.hi(n)\n  return ((b<<1) >>> 21) - 1023\n}\n\nmodule.exports.fraction = function(n) {\n  var lo = module.exports.lo(n)\n  var hi = module.exports.hi(n)\n  var b = hi & ((1<<20) - 1)\n  if(hi & 0x7ff00000) {\n    b += (1<<20)\n  }\n  return [lo, b]\n}\n\nmodule.exports.denormalized = function(n) {\n  var hi = module.exports.hi(n)\n  return !(hi & 0x7ff00000)\n}\n}).call(this,_dereq_(\"buffer\").Buffer)\n},{\"buffer\":105}],168:[function(_dereq_,module,exports){\nvar abs = _dereq_('abs-svg-path')\nvar normalize = _dereq_('normalize-svg-path')\n\nvar methods = {\n  'M': 'moveTo',\n  'C': 'bezierCurveTo'\n}\n\nmodule.exports = function(context, segments) {\n  context.beginPath()\n\n  // Make path easy to reproduce.\n  normalize(abs(segments)).forEach(\n    function(segment) {\n      var command = segment[0]\n      var args = segment.slice(1)\n\n      // Convert the path command to a context method.\n      context[methods[command]].apply(context, args)\n    }\n  )\n\n  context.closePath()\n}\n\n},{\"abs-svg-path\":60,\"normalize-svg-path\":452}],169:[function(_dereq_,module,exports){\nmodule.exports = function(dtype) {\n  switch (dtype) {\n    case 'int8':\n      return Int8Array\n    case 'int16':\n      return Int16Array\n    case 'int32':\n      return Int32Array\n    case 'uint8':\n      return Uint8Array\n    case 'uint16':\n      return Uint16Array\n    case 'uint32':\n      return Uint32Array\n    case 'float32':\n      return Float32Array\n    case 'float64':\n      return Float64Array\n    case 'array':\n      return Array\n    case 'uint8_clamped':\n      return Uint8ClampedArray\n  }\n}\n\n},{}],170:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction dupe_array(count, value, i) {\n  var c = count[i]|0\n  if(c <= 0) {\n    return []\n  }\n  var result = new Array(c), j\n  if(i === count.length-1) {\n    for(j=0; j<c; ++j) {\n      result[j] = value\n    }\n  } else {\n    for(j=0; j<c; ++j) {\n      result[j] = dupe_array(count, value, i+1)\n    }\n  }\n  return result\n}\n\nfunction dupe_number(count, value) {\n  var result, i\n  result = new Array(count)\n  for(i=0; i<count; ++i) {\n    result[i] = value\n  }\n  return result\n}\n\nfunction dupe(count, value) {\n  if(typeof value === \"undefined\") {\n    value = 0\n  }\n  switch(typeof count) {\n    case \"number\":\n      if(count > 0) {\n        return dupe_number(count|0, value)\n      }\n    break\n    case \"object\":\n      if(typeof (count.length) === \"number\") {\n        return dupe_array(count, value, 0)\n      }\n    break\n  }\n  return []\n}\n\nmodule.exports = dupe\n},{}],171:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = edgeToAdjacency\n\nvar uniq = _dereq_(\"uniq\")\n\nfunction edgeToAdjacency(edges, numVertices) {\n  var numEdges = edges.length\n  if(typeof numVertices !== \"number\") {\n    numVertices = 0\n    for(var i=0; i<numEdges; ++i) {\n      var e = edges[i]\n      numVertices = Math.max(numVertices, e[0], e[1])\n    }\n    numVertices = (numVertices|0) + 1\n  }\n  numVertices = numVertices|0\n  var adj = new Array(numVertices)\n  for(var i=0; i<numVertices; ++i) {\n    adj[i] = []\n  }\n  for(var i=0; i<numEdges; ++i) {\n    var e = edges[i]\n    adj[e[0]].push(e[1])\n    adj[e[1]].push(e[0])\n  }\n  for(var j=0; j<numVertices; ++j) {\n    uniq(adj[j], function(a, b) {\n      return a - b\n    })\n  }\n  return adj\n}\n},{\"uniq\":547}],172:[function(_dereq_,module,exports){\nvar tarjan = _dereq_('strongly-connected-components');\n\nmodule.exports = function findCircuits(edges) {\n    var circuits = []; // Output\n\n    var stack = [];\n    var blocked = [];\n    var B = {};\n    var Ak = [];\n    var s;\n\n    function unblock(u) {\n        blocked[u] = false;\n        if(B.hasOwnProperty(u)) {\n            Object.keys(B[u]).forEach(function(w) {\n                delete B[u][w];\n                if(blocked[w]) {unblock(w);}\n            });\n        }\n    }\n\n    function circuit(v) {\n        var found = false;\n\n        stack.push(v);\n        blocked[v] = true;\n\n        // L1\n        var i;\n        var w;\n        for(i = 0; i < Ak[v].length; i++) {\n            w = Ak[v][i];\n            if(w === s) {\n                output(s, stack);\n                found = true;\n            } else if(!blocked[w]) {\n                found = circuit(w);\n            }\n        }\n\n        // L2\n        if(found) {\n            unblock(v);\n        } else {\n            for(i = 0; i < Ak[v].length; i++) {\n                w = Ak[v][i];\n                var entry = B[w];\n\n                if(!entry) {\n                    entry = {};\n                    B[w] = entry;\n                }\n\n                entry[w] = true;\n            }\n        }\n        stack.pop();\n        return found;\n    }\n\n    function output(start, stack) {\n        var cycle = [].concat(stack).concat(start);\n        circuits.push(cycle);\n    }\n\n    function subgraph(minId) {\n      // Remove edges with indice smaller than minId\n        for(var i = 0; i < edges.length; i++) {\n            if(i < minId) edges[i] = [];\n            edges[i] = edges[i].filter(function(i) {\n                return i >= minId;\n            });\n        }\n    }\n\n    function adjacencyStructureSCC(from) {\n      // Make subgraph starting from vertex minId\n        subgraph(from);\n        var g = edges;\n\n      // Find strongly connected components using Tarjan algorithm\n        var sccs = tarjan(g);\n\n      // Filter out trivial connected components (ie. made of one node)\n        var ccs = sccs.components.filter(function(scc) {\n            return scc.length > 1;\n        });\n\n      // Find least vertex\n        var leastVertex = Infinity;\n        var leastVertexComponent;\n        for(var i = 0; i < ccs.length; i++) {\n            for(var j = 0; j < ccs[i].length; j++) {\n                if(ccs[i][j] < leastVertex) {\n                    leastVertex = ccs[i][j];\n                    leastVertexComponent = i;\n                }\n            }\n        }\n\n        var cc = ccs[leastVertexComponent];\n\n        if(!cc) return false;\n\n      // Return the adjacency list of first component\n        var adjList = edges.map(function(l, index) {\n            if(cc.indexOf(index) === -1) return [];\n            return l.filter(function(i) {\n                return cc.indexOf(i) !== -1;\n            });\n        });\n\n        return {\n            leastVertex: leastVertex,\n            adjList: adjList\n        };\n    }\n\n    s = 0;\n    var n = edges.length;\n    while(s < n) {\n        // find strong component with least vertex in\n        // subgraph starting from vertex `s`\n        var p = adjacencyStructureSCC(s);\n\n        // Its least vertex\n        s = p.leastVertex;\n        // Its adjacency list\n        Ak = p.adjList;\n\n        if(Ak) {\n            for(var i = 0; i < Ak.length; i++) {\n                for(var j = 0; j < Ak[i].length; j++) {\n                    var vertexId = Ak[i][j];\n                    blocked[+vertexId] = false;\n                    B[vertexId] = {};\n                }\n            }\n            circuit(s);\n            s = s + 1;\n        } else {\n            s = n;\n        }\n\n    }\n\n    return circuits;\n};\n\n},{\"strongly-connected-components\":530}],173:[function(_dereq_,module,exports){\n// Inspired by Google Closure:\n// http://closure-library.googlecode.com/svn/docs/\n// closure_goog_array_array.js.html#goog.array.clear\n\n\"use strict\";\n\nvar value = _dereq_(\"../../object/valid-value\");\n\nmodule.exports = function () {\n\tvalue(this).length = 0;\n\treturn this;\n};\n\n},{\"../../object/valid-value\":205}],174:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = _dereq_(\"./is-implemented\")()\n\t? Array.from\n\t: _dereq_(\"./shim\");\n\n},{\"./is-implemented\":175,\"./shim\":176}],175:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = function () {\n\tvar from = Array.from, arr, result;\n\tif (typeof from !== \"function\") return false;\n\tarr = [\"raz\", \"dwa\"];\n\tresult = from(arr);\n\treturn Boolean(result && (result !== arr) && (result[1] === \"dwa\"));\n};\n\n},{}],176:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar iteratorSymbol = _dereq_(\"es6-symbol\").iterator\n  , isArguments    = _dereq_(\"../../function/is-arguments\")\n  , isFunction     = _dereq_(\"../../function/is-function\")\n  , toPosInt       = _dereq_(\"../../number/to-pos-integer\")\n  , callable       = _dereq_(\"../../object/valid-callable\")\n  , validValue     = _dereq_(\"../../object/valid-value\")\n  , isValue        = _dereq_(\"../../object/is-value\")\n  , isString       = _dereq_(\"../../string/is-string\")\n  , isArray        = Array.isArray\n  , call           = Function.prototype.call\n  , desc           = { configurable: true, enumerable: true, writable: true, value: null }\n  , defineProperty = Object.defineProperty;\n\n// eslint-disable-next-line complexity\nmodule.exports = function (arrayLike /*, mapFn, thisArg*/) {\n\tvar mapFn = arguments[1]\n\t  , thisArg = arguments[2]\n\t  , Context\n\t  , i\n\t  , j\n\t  , arr\n\t  , length\n\t  , code\n\t  , iterator\n\t  , result\n\t  , getIterator\n\t  , value;\n\n\tarrayLike = Object(validValue(arrayLike));\n\n\tif (isValue(mapFn)) callable(mapFn);\n\tif (!this || this === Array || !isFunction(this)) {\n\t\t// Result: Plain array\n\t\tif (!mapFn) {\n\t\t\tif (isArguments(arrayLike)) {\n\t\t\t\t// Source: Arguments\n\t\t\t\tlength = arrayLike.length;\n\t\t\t\tif (length !== 1) return Array.apply(null, arrayLike);\n\t\t\t\tarr = new Array(1);\n\t\t\t\tarr[0] = arrayLike[0];\n\t\t\t\treturn arr;\n\t\t\t}\n\t\t\tif (isArray(arrayLike)) {\n\t\t\t\t// Source: Array\n\t\t\t\tarr = new Array(length = arrayLike.length);\n\t\t\t\tfor (i = 0; i < length; ++i) arr[i] = arrayLike[i];\n\t\t\t\treturn arr;\n\t\t\t}\n\t\t}\n\t\tarr = [];\n\t} else {\n\t\t// Result: Non plain array\n\t\tContext = this;\n\t}\n\n\tif (!isArray(arrayLike)) {\n\t\tif ((getIterator = arrayLike[iteratorSymbol]) !== undefined) {\n\t\t\t// Source: Iterator\n\t\t\titerator = callable(getIterator).call(arrayLike);\n\t\t\tif (Context) arr = new Context();\n\t\t\tresult = iterator.next();\n\t\t\ti = 0;\n\t\t\twhile (!result.done) {\n\t\t\t\tvalue = mapFn ? call.call(mapFn, thisArg, result.value, i) : result.value;\n\t\t\t\tif (Context) {\n\t\t\t\t\tdesc.value = value;\n\t\t\t\t\tdefineProperty(arr, i, desc);\n\t\t\t\t} else {\n\t\t\t\t\tarr[i] = value;\n\t\t\t\t}\n\t\t\t\tresult = iterator.next();\n\t\t\t\t++i;\n\t\t\t}\n\t\t\tlength = i;\n\t\t} else if (isString(arrayLike)) {\n\t\t\t// Source: String\n\t\t\tlength = arrayLike.length;\n\t\t\tif (Context) arr = new Context();\n\t\t\tfor (i = 0, j = 0; i < length; ++i) {\n\t\t\t\tvalue = arrayLike[i];\n\t\t\t\tif (i + 1 < length) {\n\t\t\t\t\tcode = value.charCodeAt(0);\n\t\t\t\t\t// eslint-disable-next-line max-depth\n\t\t\t\t\tif (code >= 0xd800 && code <= 0xdbff) value += arrayLike[++i];\n\t\t\t\t}\n\t\t\t\tvalue = mapFn ? call.call(mapFn, thisArg, value, j) : value;\n\t\t\t\tif (Context) {\n\t\t\t\t\tdesc.value = value;\n\t\t\t\t\tdefineProperty(arr, j, desc);\n\t\t\t\t} else {\n\t\t\t\t\tarr[j] = value;\n\t\t\t\t}\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tlength = j;\n\t\t}\n\t}\n\tif (length === undefined) {\n\t\t// Source: array or array-like\n\t\tlength = toPosInt(arrayLike.length);\n\t\tif (Context) arr = new Context(length);\n\t\tfor (i = 0; i < length; ++i) {\n\t\t\tvalue = mapFn ? call.call(mapFn, thisArg, arrayLike[i], i) : arrayLike[i];\n\t\t\tif (Context) {\n\t\t\t\tdesc.value = value;\n\t\t\t\tdefineProperty(arr, i, desc);\n\t\t\t} else {\n\t\t\t\tarr[i] = value;\n\t\t\t}\n\t\t}\n\t}\n\tif (Context) {\n\t\tdesc.value = null;\n\t\tarr.length = length;\n\t}\n\treturn arr;\n};\n\n},{\"../../function/is-arguments\":177,\"../../function/is-function\":178,\"../../number/to-pos-integer\":184,\"../../object/is-value\":194,\"../../object/valid-callable\":203,\"../../object/valid-value\":205,\"../../string/is-string\":209,\"es6-symbol\":219}],177:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar objToString = Object.prototype.toString\n  , id = objToString.call(\n\t(function () {\n\t\treturn arguments;\n\t})()\n);\n\nmodule.exports = function (value) {\n\treturn objToString.call(value) === id;\n};\n\n},{}],178:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar objToString = Object.prototype.toString, id = objToString.call(_dereq_(\"./noop\"));\n\nmodule.exports = function (value) {\n\treturn typeof value === \"function\" && objToString.call(value) === id;\n};\n\n},{\"./noop\":179}],179:[function(_dereq_,module,exports){\n\"use strict\";\n\n// eslint-disable-next-line no-empty-function\nmodule.exports = function () {};\n\n},{}],180:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = _dereq_(\"./is-implemented\")()\n\t? Math.sign\n\t: _dereq_(\"./shim\");\n\n},{\"./is-implemented\":181,\"./shim\":182}],181:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = function () {\n\tvar sign = Math.sign;\n\tif (typeof sign !== \"function\") return false;\n\treturn (sign(10) === 1) && (sign(-20) === -1);\n};\n\n},{}],182:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = function (value) {\n\tvalue = Number(value);\n\tif (isNaN(value) || (value === 0)) return value;\n\treturn value > 0 ? 1 : -1;\n};\n\n},{}],183:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar sign = _dereq_(\"../math/sign\")\n\n  , abs = Math.abs, floor = Math.floor;\n\nmodule.exports = function (value) {\n\tif (isNaN(value)) return 0;\n\tvalue = Number(value);\n\tif ((value === 0) || !isFinite(value)) return value;\n\treturn sign(value) * floor(abs(value));\n};\n\n},{\"../math/sign\":180}],184:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar toInteger = _dereq_(\"./to-integer\")\n\n  , max = Math.max;\n\nmodule.exports = function (value) {\n return max(0, toInteger(value));\n};\n\n},{\"./to-integer\":183}],185:[function(_dereq_,module,exports){\n// Internal method, used by iteration functions.\n// Calls a function for each key-value pair found in object\n// Optionally takes compareFn to iterate object in specific order\n\n\"use strict\";\n\nvar callable                = _dereq_(\"./valid-callable\")\n  , value                   = _dereq_(\"./valid-value\")\n  , bind                    = Function.prototype.bind\n  , call                    = Function.prototype.call\n  , keys                    = Object.keys\n  , objPropertyIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nmodule.exports = function (method, defVal) {\n\treturn function (obj, cb /*, thisArg, compareFn*/) {\n\t\tvar list, thisArg = arguments[2], compareFn = arguments[3];\n\t\tobj = Object(value(obj));\n\t\tcallable(cb);\n\n\t\tlist = keys(obj);\n\t\tif (compareFn) {\n\t\t\tlist.sort(typeof compareFn === \"function\" ? bind.call(compareFn, obj) : undefined);\n\t\t}\n\t\tif (typeof method !== \"function\") method = list[method];\n\t\treturn call.call(method, list, function (key, index) {\n\t\t\tif (!objPropertyIsEnumerable.call(obj, key)) return defVal;\n\t\t\treturn call.call(cb, thisArg, obj[key], key, obj, index);\n\t\t});\n\t};\n};\n\n},{\"./valid-callable\":203,\"./valid-value\":205}],186:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = _dereq_(\"./is-implemented\")()\n\t? Object.assign\n\t: _dereq_(\"./shim\");\n\n},{\"./is-implemented\":187,\"./shim\":188}],187:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = function () {\n\tvar assign = Object.assign, obj;\n\tif (typeof assign !== \"function\") return false;\n\tobj = { foo: \"raz\" };\n\tassign(obj, { bar: \"dwa\" }, { trzy: \"trzy\" });\n\treturn (obj.foo + obj.bar + obj.trzy) === \"razdwatrzy\";\n};\n\n},{}],188:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar keys  = _dereq_(\"../keys\")\n  , value = _dereq_(\"../valid-value\")\n  , max   = Math.max;\n\nmodule.exports = function (dest, src /*, …srcn*/) {\n\tvar error, i, length = max(arguments.length, 2), assign;\n\tdest = Object(value(dest));\n\tassign = function (key) {\n\t\ttry {\n\t\t\tdest[key] = src[key];\n\t\t} catch (e) {\n\t\t\tif (!error) error = e;\n\t\t}\n\t};\n\tfor (i = 1; i < length; ++i) {\n\t\tsrc = arguments[i];\n\t\tkeys(src).forEach(assign);\n\t}\n\tif (error !== undefined) throw error;\n\treturn dest;\n};\n\n},{\"../keys\":195,\"../valid-value\":205}],189:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar aFrom  = _dereq_(\"../array/from\")\n  , assign = _dereq_(\"./assign\")\n  , value  = _dereq_(\"./valid-value\");\n\nmodule.exports = function (obj/*, propertyNames, options*/) {\n\tvar copy = Object(value(obj)), propertyNames = arguments[1], options = Object(arguments[2]);\n\tif (copy !== obj && !propertyNames) return copy;\n\tvar result = {};\n\tif (propertyNames) {\n\t\taFrom(propertyNames, function (propertyName) {\n\t\t\tif (options.ensure || propertyName in obj) result[propertyName] = obj[propertyName];\n\t\t});\n\t} else {\n\t\tassign(result, obj);\n\t}\n\treturn result;\n};\n\n},{\"../array/from\":174,\"./assign\":186,\"./valid-value\":205}],190:[function(_dereq_,module,exports){\n// Workaround for http://code.google.com/p/v8/issues/detail?id=2804\n\n\"use strict\";\n\nvar create = Object.create, shim;\n\nif (!_dereq_(\"./set-prototype-of/is-implemented\")()) {\n\tshim = _dereq_(\"./set-prototype-of/shim\");\n}\n\nmodule.exports = (function () {\n\tvar nullObject, polyProps, desc;\n\tif (!shim) return create;\n\tif (shim.level !== 1) return create;\n\n\tnullObject = {};\n\tpolyProps = {};\n\tdesc = {\n\t\tconfigurable: false,\n\t\tenumerable: false,\n\t\twritable: true,\n\t\tvalue: undefined\n\t};\n\tObject.getOwnPropertyNames(Object.prototype).forEach(function (name) {\n\t\tif (name === \"__proto__\") {\n\t\t\tpolyProps[name] = {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: false,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: undefined\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tpolyProps[name] = desc;\n\t});\n\tObject.defineProperties(nullObject, polyProps);\n\n\tObject.defineProperty(shim, \"nullPolyfill\", {\n\t\tconfigurable: false,\n\t\tenumerable: false,\n\t\twritable: false,\n\t\tvalue: nullObject\n\t});\n\n\treturn function (prototype, props) {\n\t\treturn create(prototype === null ? nullObject : prototype, props);\n\t};\n}());\n\n},{\"./set-prototype-of/is-implemented\":201,\"./set-prototype-of/shim\":202}],191:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = _dereq_(\"./_iterate\")(\"forEach\");\n\n},{\"./_iterate\":185}],192:[function(_dereq_,module,exports){\n// Deprecated\n\n\"use strict\";\n\nmodule.exports = function (obj) {\n return typeof obj === \"function\";\n};\n\n},{}],193:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isValue = _dereq_(\"./is-value\");\n\nvar map = { function: true, object: true };\n\nmodule.exports = function (value) {\n\treturn (isValue(value) && map[typeof value]) || false;\n};\n\n},{\"./is-value\":194}],194:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar _undefined = _dereq_(\"../function/noop\")(); // Support ES3 engines\n\nmodule.exports = function (val) {\n return (val !== _undefined) && (val !== null);\n};\n\n},{\"../function/noop\":179}],195:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = _dereq_(\"./is-implemented\")() ? Object.keys : _dereq_(\"./shim\");\n\n},{\"./is-implemented\":196,\"./shim\":197}],196:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = function () {\n\ttry {\n\t\tObject.keys(\"primitive\");\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t}\n};\n\n},{}],197:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isValue = _dereq_(\"../is-value\");\n\nvar keys = Object.keys;\n\nmodule.exports = function (object) { return keys(isValue(object) ? Object(object) : object); };\n\n},{\"../is-value\":194}],198:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar callable = _dereq_(\"./valid-callable\")\n  , forEach  = _dereq_(\"./for-each\")\n  , call     = Function.prototype.call;\n\nmodule.exports = function (obj, cb /*, thisArg*/) {\n\tvar result = {}, thisArg = arguments[2];\n\tcallable(cb);\n\tforEach(obj, function (value, key, targetObj, index) {\n\t\tresult[key] = call.call(cb, thisArg, value, key, targetObj, index);\n\t});\n\treturn result;\n};\n\n},{\"./for-each\":191,\"./valid-callable\":203}],199:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isValue = _dereq_(\"./is-value\");\n\nvar forEach = Array.prototype.forEach, create = Object.create;\n\nvar process = function (src, obj) {\n\tvar key;\n\tfor (key in src) obj[key] = src[key];\n};\n\n// eslint-disable-next-line no-unused-vars\nmodule.exports = function (opts1 /*, …options*/) {\n\tvar result = create(null);\n\tforEach.call(arguments, function (options) {\n\t\tif (!isValue(options)) return;\n\t\tprocess(Object(options), result);\n\t});\n\treturn result;\n};\n\n},{\"./is-value\":194}],200:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = _dereq_(\"./is-implemented\")()\n\t? Object.setPrototypeOf\n\t: _dereq_(\"./shim\");\n\n},{\"./is-implemented\":201,\"./shim\":202}],201:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar create = Object.create, getPrototypeOf = Object.getPrototypeOf, plainObject = {};\n\nmodule.exports = function (/* CustomCreate*/) {\n\tvar setPrototypeOf = Object.setPrototypeOf, customCreate = arguments[0] || create;\n\tif (typeof setPrototypeOf !== \"function\") return false;\n\treturn getPrototypeOf(setPrototypeOf(customCreate(null), plainObject)) === plainObject;\n};\n\n},{}],202:[function(_dereq_,module,exports){\n/* eslint no-proto: \"off\" */\n\n// Big thanks to @WebReflection for sorting this out\n// https://gist.github.com/WebReflection/5593554\n\n\"use strict\";\n\nvar isObject        = _dereq_(\"../is-object\")\n  , value           = _dereq_(\"../valid-value\")\n  , objIsPrototypeOf = Object.prototype.isPrototypeOf\n  , defineProperty  = Object.defineProperty\n  , nullDesc        = {\n\tconfigurable: true,\n\tenumerable: false,\n\twritable: true,\n\tvalue: undefined\n}\n  , validate;\n\nvalidate = function (obj, prototype) {\n\tvalue(obj);\n\tif (prototype === null || isObject(prototype)) return obj;\n\tthrow new TypeError(\"Prototype must be null or an object\");\n};\n\nmodule.exports = (function (status) {\n\tvar fn, set;\n\tif (!status) return null;\n\tif (status.level === 2) {\n\t\tif (status.set) {\n\t\t\tset = status.set;\n\t\t\tfn = function (obj, prototype) {\n\t\t\t\tset.call(validate(obj, prototype), prototype);\n\t\t\t\treturn obj;\n\t\t\t};\n\t\t} else {\n\t\t\tfn = function (obj, prototype) {\n\t\t\t\tvalidate(obj, prototype).__proto__ = prototype;\n\t\t\t\treturn obj;\n\t\t\t};\n\t\t}\n\t} else {\n\t\tfn = function self(obj, prototype) {\n\t\t\tvar isNullBase;\n\t\t\tvalidate(obj, prototype);\n\t\t\tisNullBase = objIsPrototypeOf.call(self.nullPolyfill, obj);\n\t\t\tif (isNullBase) delete self.nullPolyfill.__proto__;\n\t\t\tif (prototype === null) prototype = self.nullPolyfill;\n\t\t\tobj.__proto__ = prototype;\n\t\t\tif (isNullBase) defineProperty(self.nullPolyfill, \"__proto__\", nullDesc);\n\t\t\treturn obj;\n\t\t};\n\t}\n\treturn Object.defineProperty(fn, \"level\", {\n\t\tconfigurable: false,\n\t\tenumerable: false,\n\t\twritable: false,\n\t\tvalue: status.level\n\t});\n}(\n\t(function () {\n\t\tvar tmpObj1 = Object.create(null)\n\t\t  , tmpObj2 = {}\n\t\t  , set\n\t\t  , desc = Object.getOwnPropertyDescriptor(Object.prototype, \"__proto__\");\n\n\t\tif (desc) {\n\t\t\ttry {\n\t\t\t\tset = desc.set; // Opera crashes at this point\n\t\t\t\tset.call(tmpObj1, tmpObj2);\n\t\t\t} catch (ignore) {}\n\t\t\tif (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { set: set, level: 2 };\n\t\t}\n\n\t\ttmpObj1.__proto__ = tmpObj2;\n\t\tif (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { level: 2 };\n\n\t\ttmpObj1 = {};\n\t\ttmpObj1.__proto__ = tmpObj2;\n\t\tif (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { level: 1 };\n\n\t\treturn false;\n\t})()\n));\n\n_dereq_(\"../create\");\n\n},{\"../create\":190,\"../is-object\":193,\"../valid-value\":205}],203:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = function (fn) {\n\tif (typeof fn !== \"function\") throw new TypeError(fn + \" is not a function\");\n\treturn fn;\n};\n\n},{}],204:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isObject = _dereq_(\"./is-object\");\n\nmodule.exports = function (value) {\n\tif (!isObject(value)) throw new TypeError(value + \" is not an Object\");\n\treturn value;\n};\n\n},{\"./is-object\":193}],205:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isValue = _dereq_(\"./is-value\");\n\nmodule.exports = function (value) {\n\tif (!isValue(value)) throw new TypeError(\"Cannot use null or undefined\");\n\treturn value;\n};\n\n},{\"./is-value\":194}],206:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = _dereq_(\"./is-implemented\")()\n\t? String.prototype.contains\n\t: _dereq_(\"./shim\");\n\n},{\"./is-implemented\":207,\"./shim\":208}],207:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar str = \"razdwatrzy\";\n\nmodule.exports = function () {\n\tif (typeof str.contains !== \"function\") return false;\n\treturn (str.contains(\"dwa\") === true) && (str.contains(\"foo\") === false);\n};\n\n},{}],208:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar indexOf = String.prototype.indexOf;\n\nmodule.exports = function (searchString/*, position*/) {\n\treturn indexOf.call(this, searchString, arguments[1]) > -1;\n};\n\n},{}],209:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar objToString = Object.prototype.toString, id = objToString.call(\"\");\n\nmodule.exports = function (value) {\n\treturn (\n\t\ttypeof value === \"string\" ||\n\t\t(value &&\n\t\t\ttypeof value === \"object\" &&\n\t\t\t(value instanceof String || objToString.call(value) === id)) ||\n\t\tfalse\n\t);\n};\n\n},{}],210:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar generated = Object.create(null), random = Math.random;\n\nmodule.exports = function () {\n\tvar str;\n\tdo {\n\t\tstr = random()\n\t\t\t.toString(36)\n\t\t\t.slice(2);\n\t} while (generated[str]);\n\treturn str;\n};\n\n},{}],211:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar setPrototypeOf = _dereq_(\"es5-ext/object/set-prototype-of\")\n  , contains       = _dereq_(\"es5-ext/string/#/contains\")\n  , d              = _dereq_(\"d\")\n  , Symbol         = _dereq_(\"es6-symbol\")\n  , Iterator       = _dereq_(\"./\");\n\nvar defineProperty = Object.defineProperty, ArrayIterator;\n\nArrayIterator = module.exports = function (arr, kind) {\n\tif (!(this instanceof ArrayIterator)) throw new TypeError(\"Constructor requires 'new'\");\n\tIterator.call(this, arr);\n\tif (!kind) kind = \"value\";\n\telse if (contains.call(kind, \"key+value\")) kind = \"key+value\";\n\telse if (contains.call(kind, \"key\")) kind = \"key\";\n\telse kind = \"value\";\n\tdefineProperty(this, \"__kind__\", d(\"\", kind));\n};\nif (setPrototypeOf) setPrototypeOf(ArrayIterator, Iterator);\n\n// Internal %ArrayIteratorPrototype% doesn't expose its constructor\ndelete ArrayIterator.prototype.constructor;\n\nArrayIterator.prototype = Object.create(Iterator.prototype, {\n\t_resolve: d(function (i) {\n\t\tif (this.__kind__ === \"value\") return this.__list__[i];\n\t\tif (this.__kind__ === \"key+value\") return [i, this.__list__[i]];\n\t\treturn i;\n\t})\n});\ndefineProperty(ArrayIterator.prototype, Symbol.toStringTag, d(\"c\", \"Array Iterator\"));\n\n},{\"./\":214,\"d\":151,\"es5-ext/object/set-prototype-of\":200,\"es5-ext/string/#/contains\":206,\"es6-symbol\":219}],212:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isArguments = _dereq_(\"es5-ext/function/is-arguments\")\n  , callable    = _dereq_(\"es5-ext/object/valid-callable\")\n  , isString    = _dereq_(\"es5-ext/string/is-string\")\n  , get         = _dereq_(\"./get\");\n\nvar isArray = Array.isArray, call = Function.prototype.call, some = Array.prototype.some;\n\nmodule.exports = function (iterable, cb /*, thisArg*/) {\n\tvar mode, thisArg = arguments[2], result, doBreak, broken, i, length, char, code;\n\tif (isArray(iterable) || isArguments(iterable)) mode = \"array\";\n\telse if (isString(iterable)) mode = \"string\";\n\telse iterable = get(iterable);\n\n\tcallable(cb);\n\tdoBreak = function () {\n\t\tbroken = true;\n\t};\n\tif (mode === \"array\") {\n\t\tsome.call(iterable, function (value) {\n\t\t\tcall.call(cb, thisArg, value, doBreak);\n\t\t\treturn broken;\n\t\t});\n\t\treturn;\n\t}\n\tif (mode === \"string\") {\n\t\tlength = iterable.length;\n\t\tfor (i = 0; i < length; ++i) {\n\t\t\tchar = iterable[i];\n\t\t\tif (i + 1 < length) {\n\t\t\t\tcode = char.charCodeAt(0);\n\t\t\t\tif (code >= 0xd800 && code <= 0xdbff) char += iterable[++i];\n\t\t\t}\n\t\t\tcall.call(cb, thisArg, char, doBreak);\n\t\t\tif (broken) break;\n\t\t}\n\t\treturn;\n\t}\n\tresult = iterable.next();\n\n\twhile (!result.done) {\n\t\tcall.call(cb, thisArg, result.value, doBreak);\n\t\tif (broken) return;\n\t\tresult = iterable.next();\n\t}\n};\n\n},{\"./get\":213,\"es5-ext/function/is-arguments\":177,\"es5-ext/object/valid-callable\":203,\"es5-ext/string/is-string\":209}],213:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isArguments    = _dereq_(\"es5-ext/function/is-arguments\")\n  , isString       = _dereq_(\"es5-ext/string/is-string\")\n  , ArrayIterator  = _dereq_(\"./array\")\n  , StringIterator = _dereq_(\"./string\")\n  , iterable       = _dereq_(\"./valid-iterable\")\n  , iteratorSymbol = _dereq_(\"es6-symbol\").iterator;\n\nmodule.exports = function (obj) {\n\tif (typeof iterable(obj)[iteratorSymbol] === \"function\") return obj[iteratorSymbol]();\n\tif (isArguments(obj)) return new ArrayIterator(obj);\n\tif (isString(obj)) return new StringIterator(obj);\n\treturn new ArrayIterator(obj);\n};\n\n},{\"./array\":211,\"./string\":216,\"./valid-iterable\":217,\"es5-ext/function/is-arguments\":177,\"es5-ext/string/is-string\":209,\"es6-symbol\":219}],214:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar clear    = _dereq_(\"es5-ext/array/#/clear\")\n  , assign   = _dereq_(\"es5-ext/object/assign\")\n  , callable = _dereq_(\"es5-ext/object/valid-callable\")\n  , value    = _dereq_(\"es5-ext/object/valid-value\")\n  , d        = _dereq_(\"d\")\n  , autoBind = _dereq_(\"d/auto-bind\")\n  , Symbol   = _dereq_(\"es6-symbol\");\n\nvar defineProperty = Object.defineProperty, defineProperties = Object.defineProperties, Iterator;\n\nmodule.exports = Iterator = function (list, context) {\n\tif (!(this instanceof Iterator)) throw new TypeError(\"Constructor requires 'new'\");\n\tdefineProperties(this, {\n\t\t__list__: d(\"w\", value(list)),\n\t\t__context__: d(\"w\", context),\n\t\t__nextIndex__: d(\"w\", 0)\n\t});\n\tif (!context) return;\n\tcallable(context.on);\n\tcontext.on(\"_add\", this._onAdd);\n\tcontext.on(\"_delete\", this._onDelete);\n\tcontext.on(\"_clear\", this._onClear);\n};\n\n// Internal %IteratorPrototype% doesn't expose its constructor\ndelete Iterator.prototype.constructor;\n\ndefineProperties(\n\tIterator.prototype,\n\tassign(\n\t\t{\n\t\t\t_next: d(function () {\n\t\t\t\tvar i;\n\t\t\t\tif (!this.__list__) return undefined;\n\t\t\t\tif (this.__redo__) {\n\t\t\t\t\ti = this.__redo__.shift();\n\t\t\t\t\tif (i !== undefined) return i;\n\t\t\t\t}\n\t\t\t\tif (this.__nextIndex__ < this.__list__.length) return this.__nextIndex__++;\n\t\t\t\tthis._unBind();\n\t\t\t\treturn undefined;\n\t\t\t}),\n\t\t\tnext: d(function () {\n\t\t\t\treturn this._createResult(this._next());\n\t\t\t}),\n\t\t\t_createResult: d(function (i) {\n\t\t\t\tif (i === undefined) return { done: true, value: undefined };\n\t\t\t\treturn { done: false, value: this._resolve(i) };\n\t\t\t}),\n\t\t\t_resolve: d(function (i) {\n\t\t\t\treturn this.__list__[i];\n\t\t\t}),\n\t\t\t_unBind: d(function () {\n\t\t\t\tthis.__list__ = null;\n\t\t\t\tdelete this.__redo__;\n\t\t\t\tif (!this.__context__) return;\n\t\t\t\tthis.__context__.off(\"_add\", this._onAdd);\n\t\t\t\tthis.__context__.off(\"_delete\", this._onDelete);\n\t\t\t\tthis.__context__.off(\"_clear\", this._onClear);\n\t\t\t\tthis.__context__ = null;\n\t\t\t}),\n\t\t\ttoString: d(function () {\n\t\t\t\treturn \"[object \" + (this[Symbol.toStringTag] || \"Object\") + \"]\";\n\t\t\t})\n\t\t},\n\t\tautoBind({\n\t\t\t_onAdd: d(function (index) {\n\t\t\t\tif (index >= this.__nextIndex__) return;\n\t\t\t\t++this.__nextIndex__;\n\t\t\t\tif (!this.__redo__) {\n\t\t\t\t\tdefineProperty(this, \"__redo__\", d(\"c\", [index]));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.__redo__.forEach(function (redo, i) {\n\t\t\t\t\tif (redo >= index) this.__redo__[i] = ++redo;\n\t\t\t\t}, this);\n\t\t\t\tthis.__redo__.push(index);\n\t\t\t}),\n\t\t\t_onDelete: d(function (index) {\n\t\t\t\tvar i;\n\t\t\t\tif (index >= this.__nextIndex__) return;\n\t\t\t\t--this.__nextIndex__;\n\t\t\t\tif (!this.__redo__) return;\n\t\t\t\ti = this.__redo__.indexOf(index);\n\t\t\t\tif (i !== -1) this.__redo__.splice(i, 1);\n\t\t\t\tthis.__redo__.forEach(function (redo, j) {\n\t\t\t\t\tif (redo > index) this.__redo__[j] = --redo;\n\t\t\t\t}, this);\n\t\t\t}),\n\t\t\t_onClear: d(function () {\n\t\t\t\tif (this.__redo__) clear.call(this.__redo__);\n\t\t\t\tthis.__nextIndex__ = 0;\n\t\t\t})\n\t\t})\n\t)\n);\n\ndefineProperty(\n\tIterator.prototype,\n\tSymbol.iterator,\n\td(function () {\n\t\treturn this;\n\t})\n);\n\n},{\"d\":151,\"d/auto-bind\":150,\"es5-ext/array/#/clear\":173,\"es5-ext/object/assign\":186,\"es5-ext/object/valid-callable\":203,\"es5-ext/object/valid-value\":205,\"es6-symbol\":219}],215:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isArguments = _dereq_(\"es5-ext/function/is-arguments\")\n  , isValue     = _dereq_(\"es5-ext/object/is-value\")\n  , isString    = _dereq_(\"es5-ext/string/is-string\");\n\nvar iteratorSymbol = _dereq_(\"es6-symbol\").iterator\n  , isArray        = Array.isArray;\n\nmodule.exports = function (value) {\n\tif (!isValue(value)) return false;\n\tif (isArray(value)) return true;\n\tif (isString(value)) return true;\n\tif (isArguments(value)) return true;\n\treturn typeof value[iteratorSymbol] === \"function\";\n};\n\n},{\"es5-ext/function/is-arguments\":177,\"es5-ext/object/is-value\":194,\"es5-ext/string/is-string\":209,\"es6-symbol\":219}],216:[function(_dereq_,module,exports){\n// Thanks @mathiasbynens\n// http://mathiasbynens.be/notes/javascript-unicode#iterating-over-symbols\n\n\"use strict\";\n\nvar setPrototypeOf = _dereq_(\"es5-ext/object/set-prototype-of\")\n  , d              = _dereq_(\"d\")\n  , Symbol         = _dereq_(\"es6-symbol\")\n  , Iterator       = _dereq_(\"./\");\n\nvar defineProperty = Object.defineProperty, StringIterator;\n\nStringIterator = module.exports = function (str) {\n\tif (!(this instanceof StringIterator)) throw new TypeError(\"Constructor requires 'new'\");\n\tstr = String(str);\n\tIterator.call(this, str);\n\tdefineProperty(this, \"__length__\", d(\"\", str.length));\n};\nif (setPrototypeOf) setPrototypeOf(StringIterator, Iterator);\n\n// Internal %ArrayIteratorPrototype% doesn't expose its constructor\ndelete StringIterator.prototype.constructor;\n\nStringIterator.prototype = Object.create(Iterator.prototype, {\n\t_next: d(function () {\n\t\tif (!this.__list__) return undefined;\n\t\tif (this.__nextIndex__ < this.__length__) return this.__nextIndex__++;\n\t\tthis._unBind();\n\t\treturn undefined;\n\t}),\n\t_resolve: d(function (i) {\n\t\tvar char = this.__list__[i], code;\n\t\tif (this.__nextIndex__ === this.__length__) return char;\n\t\tcode = char.charCodeAt(0);\n\t\tif (code >= 0xd800 && code <= 0xdbff) return char + this.__list__[this.__nextIndex__++];\n\t\treturn char;\n\t})\n});\ndefineProperty(StringIterator.prototype, Symbol.toStringTag, d(\"c\", \"String Iterator\"));\n\n},{\"./\":214,\"d\":151,\"es5-ext/object/set-prototype-of\":200,\"es6-symbol\":219}],217:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isIterable = _dereq_(\"./is-iterable\");\n\nmodule.exports = function (value) {\n\tif (!isIterable(value)) throw new TypeError(value + \" is not iterable\");\n\treturn value;\n};\n\n},{\"./is-iterable\":215}],218:[function(_dereq_,module,exports){\n(function (process,global){\n/*!\n * @overview es6-promise - a tiny implementation of Promises/A+.\n * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)\n * @license   Licensed under MIT license\n *            See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE\n * @version   3.3.1\n */\n\n(function (global, factory) {\n    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n    typeof define === 'function' && define.amd ? define(factory) :\n    (global.ES6Promise = factory());\n}(this, (function () { 'use strict';\n\nfunction objectOrFunction(x) {\n  return typeof x === 'function' || typeof x === 'object' && x !== null;\n}\n\nfunction isFunction(x) {\n  return typeof x === 'function';\n}\n\nvar _isArray = undefined;\nif (!Array.isArray) {\n  _isArray = function (x) {\n    return Object.prototype.toString.call(x) === '[object Array]';\n  };\n} else {\n  _isArray = Array.isArray;\n}\n\nvar isArray = _isArray;\n\nvar len = 0;\nvar vertxNext = undefined;\nvar customSchedulerFn = undefined;\n\nvar asap = function asap(callback, arg) {\n  queue[len] = callback;\n  queue[len + 1] = arg;\n  len += 2;\n  if (len === 2) {\n    // If len is 2, that means that we need to schedule an async flush.\n    // If additional callbacks are queued before the queue is flushed, they\n    // will be processed by this flush that we are scheduling.\n    if (customSchedulerFn) {\n      customSchedulerFn(flush);\n    } else {\n      scheduleFlush();\n    }\n  }\n};\n\nfunction setScheduler(scheduleFn) {\n  customSchedulerFn = scheduleFn;\n}\n\nfunction setAsap(asapFn) {\n  asap = asapFn;\n}\n\nvar browserWindow = typeof window !== 'undefined' ? window : undefined;\nvar browserGlobal = browserWindow || {};\nvar BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;\nvar isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';\n\n// test for web worker but not in IE10\nvar isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';\n\n// node\nfunction useNextTick() {\n  // node version 0.10.x displays a deprecation warning when nextTick is used recursively\n  // see https://github.com/cujojs/when/issues/410 for details\n  return function () {\n    return process.nextTick(flush);\n  };\n}\n\n// vertx\nfunction useVertxTimer() {\n  return function () {\n    vertxNext(flush);\n  };\n}\n\nfunction useMutationObserver() {\n  var iterations = 0;\n  var observer = new BrowserMutationObserver(flush);\n  var node = document.createTextNode('');\n  observer.observe(node, { characterData: true });\n\n  return function () {\n    node.data = iterations = ++iterations % 2;\n  };\n}\n\n// web worker\nfunction useMessageChannel() {\n  var channel = new MessageChannel();\n  channel.port1.onmessage = flush;\n  return function () {\n    return channel.port2.postMessage(0);\n  };\n}\n\nfunction useSetTimeout() {\n  // Store setTimeout reference so es6-promise will be unaffected by\n  // other code modifying setTimeout (like sinon.useFakeTimers())\n  var globalSetTimeout = setTimeout;\n  return function () {\n    return globalSetTimeout(flush, 1);\n  };\n}\n\nvar queue = new Array(1000);\nfunction flush() {\n  for (var i = 0; i < len; i += 2) {\n    var callback = queue[i];\n    var arg = queue[i + 1];\n\n    callback(arg);\n\n    queue[i] = undefined;\n    queue[i + 1] = undefined;\n  }\n\n  len = 0;\n}\n\nfunction attemptVertx() {\n  try {\n    var r = _dereq_;\n    var vertx = r('vertx');\n    vertxNext = vertx.runOnLoop || vertx.runOnContext;\n    return useVertxTimer();\n  } catch (e) {\n    return useSetTimeout();\n  }\n}\n\nvar scheduleFlush = undefined;\n// Decide what async method to use to triggering processing of queued callbacks:\nif (isNode) {\n  scheduleFlush = useNextTick();\n} else if (BrowserMutationObserver) {\n  scheduleFlush = useMutationObserver();\n} else if (isWorker) {\n  scheduleFlush = useMessageChannel();\n} else if (browserWindow === undefined && typeof _dereq_ === 'function') {\n  scheduleFlush = attemptVertx();\n} else {\n  scheduleFlush = useSetTimeout();\n}\n\nfunction then(onFulfillment, onRejection) {\n  var _arguments = arguments;\n\n  var parent = this;\n\n  var child = new this.constructor(noop);\n\n  if (child[PROMISE_ID] === undefined) {\n    makePromise(child);\n  }\n\n  var _state = parent._state;\n\n  if (_state) {\n    (function () {\n      var callback = _arguments[_state - 1];\n      asap(function () {\n        return invokeCallback(_state, child, callback, parent._result);\n      });\n    })();\n  } else {\n    subscribe(parent, child, onFulfillment, onRejection);\n  }\n\n  return child;\n}\n\n/**\n  `Promise.resolve` returns a promise that will become resolved with the\n  passed `value`. It is shorthand for the following:\n\n  ```javascript\n  let promise = new Promise(function(resolve, reject){\n    resolve(1);\n  });\n\n  promise.then(function(value){\n    // value === 1\n  });\n  ```\n\n  Instead of writing the above, your code now simply becomes the following:\n\n  ```javascript\n  let promise = Promise.resolve(1);\n\n  promise.then(function(value){\n    // value === 1\n  });\n  ```\n\n  @method resolve\n  @static\n  @param {Any} value value that the returned promise will be resolved with\n  Useful for tooling.\n  @return {Promise} a promise that will become fulfilled with the given\n  `value`\n*/\nfunction resolve(object) {\n  /*jshint validthis:true */\n  var Constructor = this;\n\n  if (object && typeof object === 'object' && object.constructor === Constructor) {\n    return object;\n  }\n\n  var promise = new Constructor(noop);\n  _resolve(promise, object);\n  return promise;\n}\n\nvar PROMISE_ID = Math.random().toString(36).substring(16);\n\nfunction noop() {}\n\nvar PENDING = void 0;\nvar FULFILLED = 1;\nvar REJECTED = 2;\n\nvar GET_THEN_ERROR = new ErrorObject();\n\nfunction selfFulfillment() {\n  return new TypeError(\"You cannot resolve a promise with itself\");\n}\n\nfunction cannotReturnOwn() {\n  return new TypeError('A promises callback cannot return that same promise.');\n}\n\nfunction getThen(promise) {\n  try {\n    return promise.then;\n  } catch (error) {\n    GET_THEN_ERROR.error = error;\n    return GET_THEN_ERROR;\n  }\n}\n\nfunction tryThen(then, value, fulfillmentHandler, rejectionHandler) {\n  try {\n    then.call(value, fulfillmentHandler, rejectionHandler);\n  } catch (e) {\n    return e;\n  }\n}\n\nfunction handleForeignThenable(promise, thenable, then) {\n  asap(function (promise) {\n    var sealed = false;\n    var error = tryThen(then, thenable, function (value) {\n      if (sealed) {\n        return;\n      }\n      sealed = true;\n      if (thenable !== value) {\n        _resolve(promise, value);\n      } else {\n        fulfill(promise, value);\n      }\n    }, function (reason) {\n      if (sealed) {\n        return;\n      }\n      sealed = true;\n\n      _reject(promise, reason);\n    }, 'Settle: ' + (promise._label || ' unknown promise'));\n\n    if (!sealed && error) {\n      sealed = true;\n      _reject(promise, error);\n    }\n  }, promise);\n}\n\nfunction handleOwnThenable(promise, thenable) {\n  if (thenable._state === FULFILLED) {\n    fulfill(promise, thenable._result);\n  } else if (thenable._state === REJECTED) {\n    _reject(promise, thenable._result);\n  } else {\n    subscribe(thenable, undefined, function (value) {\n      return _resolve(promise, value);\n    }, function (reason) {\n      return _reject(promise, reason);\n    });\n  }\n}\n\nfunction handleMaybeThenable(promise, maybeThenable, then$$) {\n  if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) {\n    handleOwnThenable(promise, maybeThenable);\n  } else {\n    if (then$$ === GET_THEN_ERROR) {\n      _reject(promise, GET_THEN_ERROR.error);\n    } else if (then$$ === undefined) {\n      fulfill(promise, maybeThenable);\n    } else if (isFunction(then$$)) {\n      handleForeignThenable(promise, maybeThenable, then$$);\n    } else {\n      fulfill(promise, maybeThenable);\n    }\n  }\n}\n\nfunction _resolve(promise, value) {\n  if (promise === value) {\n    _reject(promise, selfFulfillment());\n  } else if (objectOrFunction(value)) {\n    handleMaybeThenable(promise, value, getThen(value));\n  } else {\n    fulfill(promise, value);\n  }\n}\n\nfunction publishRejection(promise) {\n  if (promise._onerror) {\n    promise._onerror(promise._result);\n  }\n\n  publish(promise);\n}\n\nfunction fulfill(promise, value) {\n  if (promise._state !== PENDING) {\n    return;\n  }\n\n  promise._result = value;\n  promise._state = FULFILLED;\n\n  if (promise._subscribers.length !== 0) {\n    asap(publish, promise);\n  }\n}\n\nfunction _reject(promise, reason) {\n  if (promise._state !== PENDING) {\n    return;\n  }\n  promise._state = REJECTED;\n  promise._result = reason;\n\n  asap(publishRejection, promise);\n}\n\nfunction subscribe(parent, child, onFulfillment, onRejection) {\n  var _subscribers = parent._subscribers;\n  var length = _subscribers.length;\n\n  parent._onerror = null;\n\n  _subscribers[length] = child;\n  _subscribers[length + FULFILLED] = onFulfillment;\n  _subscribers[length + REJECTED] = onRejection;\n\n  if (length === 0 && parent._state) {\n    asap(publish, parent);\n  }\n}\n\nfunction publish(promise) {\n  var subscribers = promise._subscribers;\n  var settled = promise._state;\n\n  if (subscribers.length === 0) {\n    return;\n  }\n\n  var child = undefined,\n      callback = undefined,\n      detail = promise._result;\n\n  for (var i = 0; i < subscribers.length; i += 3) {\n    child = subscribers[i];\n    callback = subscribers[i + settled];\n\n    if (child) {\n      invokeCallback(settled, child, callback, detail);\n    } else {\n      callback(detail);\n    }\n  }\n\n  promise._subscribers.length = 0;\n}\n\nfunction ErrorObject() {\n  this.error = null;\n}\n\nvar TRY_CATCH_ERROR = new ErrorObject();\n\nfunction tryCatch(callback, detail) {\n  try {\n    return callback(detail);\n  } catch (e) {\n    TRY_CATCH_ERROR.error = e;\n    return TRY_CATCH_ERROR;\n  }\n}\n\nfunction invokeCallback(settled, promise, callback, detail) {\n  var hasCallback = isFunction(callback),\n      value = undefined,\n      error = undefined,\n      succeeded = undefined,\n      failed = undefined;\n\n  if (hasCallback) {\n    value = tryCatch(callback, detail);\n\n    if (value === TRY_CATCH_ERROR) {\n      failed = true;\n      error = value.error;\n      value = null;\n    } else {\n      succeeded = true;\n    }\n\n    if (promise === value) {\n      _reject(promise, cannotReturnOwn());\n      return;\n    }\n  } else {\n    value = detail;\n    succeeded = true;\n  }\n\n  if (promise._state !== PENDING) {\n    // noop\n  } else if (hasCallback && succeeded) {\n      _resolve(promise, value);\n    } else if (failed) {\n      _reject(promise, error);\n    } else if (settled === FULFILLED) {\n      fulfill(promise, value);\n    } else if (settled === REJECTED) {\n      _reject(promise, value);\n    }\n}\n\nfunction initializePromise(promise, resolver) {\n  try {\n    resolver(function resolvePromise(value) {\n      _resolve(promise, value);\n    }, function rejectPromise(reason) {\n      _reject(promise, reason);\n    });\n  } catch (e) {\n    _reject(promise, e);\n  }\n}\n\nvar id = 0;\nfunction nextId() {\n  return id++;\n}\n\nfunction makePromise(promise) {\n  promise[PROMISE_ID] = id++;\n  promise._state = undefined;\n  promise._result = undefined;\n  promise._subscribers = [];\n}\n\nfunction Enumerator(Constructor, input) {\n  this._instanceConstructor = Constructor;\n  this.promise = new Constructor(noop);\n\n  if (!this.promise[PROMISE_ID]) {\n    makePromise(this.promise);\n  }\n\n  if (isArray(input)) {\n    this._input = input;\n    this.length = input.length;\n    this._remaining = input.length;\n\n    this._result = new Array(this.length);\n\n    if (this.length === 0) {\n      fulfill(this.promise, this._result);\n    } else {\n      this.length = this.length || 0;\n      this._enumerate();\n      if (this._remaining === 0) {\n        fulfill(this.promise, this._result);\n      }\n    }\n  } else {\n    _reject(this.promise, validationError());\n  }\n}\n\nfunction validationError() {\n  return new Error('Array Methods must be provided an Array');\n};\n\nEnumerator.prototype._enumerate = function () {\n  var length = this.length;\n  var _input = this._input;\n\n  for (var i = 0; this._state === PENDING && i < length; i++) {\n    this._eachEntry(_input[i], i);\n  }\n};\n\nEnumerator.prototype._eachEntry = function (entry, i) {\n  var c = this._instanceConstructor;\n  var resolve$$ = c.resolve;\n\n  if (resolve$$ === resolve) {\n    var _then = getThen(entry);\n\n    if (_then === then && entry._state !== PENDING) {\n      this._settledAt(entry._state, i, entry._result);\n    } else if (typeof _then !== 'function') {\n      this._remaining--;\n      this._result[i] = entry;\n    } else if (c === Promise) {\n      var promise = new c(noop);\n      handleMaybeThenable(promise, entry, _then);\n      this._willSettleAt(promise, i);\n    } else {\n      this._willSettleAt(new c(function (resolve$$) {\n        return resolve$$(entry);\n      }), i);\n    }\n  } else {\n    this._willSettleAt(resolve$$(entry), i);\n  }\n};\n\nEnumerator.prototype._settledAt = function (state, i, value) {\n  var promise = this.promise;\n\n  if (promise._state === PENDING) {\n    this._remaining--;\n\n    if (state === REJECTED) {\n      _reject(promise, value);\n    } else {\n      this._result[i] = value;\n    }\n  }\n\n  if (this._remaining === 0) {\n    fulfill(promise, this._result);\n  }\n};\n\nEnumerator.prototype._willSettleAt = function (promise, i) {\n  var enumerator = this;\n\n  subscribe(promise, undefined, function (value) {\n    return enumerator._settledAt(FULFILLED, i, value);\n  }, function (reason) {\n    return enumerator._settledAt(REJECTED, i, reason);\n  });\n};\n\n/**\n  `Promise.all` accepts an array of promises, and returns a new promise which\n  is fulfilled with an array of fulfillment values for the passed promises, or\n  rejected with the reason of the first passed promise to be rejected. It casts all\n  elements of the passed iterable to promises as it runs this algorithm.\n\n  Example:\n\n  ```javascript\n  let promise1 = resolve(1);\n  let promise2 = resolve(2);\n  let promise3 = resolve(3);\n  let promises = [ promise1, promise2, promise3 ];\n\n  Promise.all(promises).then(function(array){\n    // The array here would be [ 1, 2, 3 ];\n  });\n  ```\n\n  If any of the `promises` given to `all` are rejected, the first promise\n  that is rejected will be given as an argument to the returned promises's\n  rejection handler. For example:\n\n  Example:\n\n  ```javascript\n  let promise1 = resolve(1);\n  let promise2 = reject(new Error(\"2\"));\n  let promise3 = reject(new Error(\"3\"));\n  let promises = [ promise1, promise2, promise3 ];\n\n  Promise.all(promises).then(function(array){\n    // Code here never runs because there are rejected promises!\n  }, function(error) {\n    // error.message === \"2\"\n  });\n  ```\n\n  @method all\n  @static\n  @param {Array} entries array of promises\n  @param {String} label optional string for labeling the promise.\n  Useful for tooling.\n  @return {Promise} promise that is fulfilled when all `promises` have been\n  fulfilled, or rejected if any of them become rejected.\n  @static\n*/\nfunction all(entries) {\n  return new Enumerator(this, entries).promise;\n}\n\n/**\n  `Promise.race` returns a new promise which is settled in the same way as the\n  first passed promise to settle.\n\n  Example:\n\n  ```javascript\n  let promise1 = new Promise(function(resolve, reject){\n    setTimeout(function(){\n      resolve('promise 1');\n    }, 200);\n  });\n\n  let promise2 = new Promise(function(resolve, reject){\n    setTimeout(function(){\n      resolve('promise 2');\n    }, 100);\n  });\n\n  Promise.race([promise1, promise2]).then(function(result){\n    // result === 'promise 2' because it was resolved before promise1\n    // was resolved.\n  });\n  ```\n\n  `Promise.race` is deterministic in that only the state of the first\n  settled promise matters. For example, even if other promises given to the\n  `promises` array argument are resolved, but the first settled promise has\n  become rejected before the other promises became fulfilled, the returned\n  promise will become rejected:\n\n  ```javascript\n  let promise1 = new Promise(function(resolve, reject){\n    setTimeout(function(){\n      resolve('promise 1');\n    }, 200);\n  });\n\n  let promise2 = new Promise(function(resolve, reject){\n    setTimeout(function(){\n      reject(new Error('promise 2'));\n    }, 100);\n  });\n\n  Promise.race([promise1, promise2]).then(function(result){\n    // Code here never runs\n  }, function(reason){\n    // reason.message === 'promise 2' because promise 2 became rejected before\n    // promise 1 became fulfilled\n  });\n  ```\n\n  An example real-world use case is implementing timeouts:\n\n  ```javascript\n  Promise.race([ajax('foo.json'), timeout(5000)])\n  ```\n\n  @method race\n  @static\n  @param {Array} promises array of promises to observe\n  Useful for tooling.\n  @return {Promise} a promise which settles in the same way as the first passed\n  promise to settle.\n*/\nfunction race(entries) {\n  /*jshint validthis:true */\n  var Constructor = this;\n\n  if (!isArray(entries)) {\n    return new Constructor(function (_, reject) {\n      return reject(new TypeError('You must pass an array to race.'));\n    });\n  } else {\n    return new Constructor(function (resolve, reject) {\n      var length = entries.length;\n      for (var i = 0; i < length; i++) {\n        Constructor.resolve(entries[i]).then(resolve, reject);\n      }\n    });\n  }\n}\n\n/**\n  `Promise.reject` returns a promise rejected with the passed `reason`.\n  It is shorthand for the following:\n\n  ```javascript\n  let promise = new Promise(function(resolve, reject){\n    reject(new Error('WHOOPS'));\n  });\n\n  promise.then(function(value){\n    // Code here doesn't run because the promise is rejected!\n  }, function(reason){\n    // reason.message === 'WHOOPS'\n  });\n  ```\n\n  Instead of writing the above, your code now simply becomes the following:\n\n  ```javascript\n  let promise = Promise.reject(new Error('WHOOPS'));\n\n  promise.then(function(value){\n    // Code here doesn't run because the promise is rejected!\n  }, function(reason){\n    // reason.message === 'WHOOPS'\n  });\n  ```\n\n  @method reject\n  @static\n  @param {Any} reason value that the returned promise will be rejected with.\n  Useful for tooling.\n  @return {Promise} a promise rejected with the given `reason`.\n*/\nfunction reject(reason) {\n  /*jshint validthis:true */\n  var Constructor = this;\n  var promise = new Constructor(noop);\n  _reject(promise, reason);\n  return promise;\n}\n\nfunction needsResolver() {\n  throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');\n}\n\nfunction needsNew() {\n  throw new TypeError(\"Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.\");\n}\n\n/**\n  Promise objects represent the eventual result of an asynchronous operation. The\n  primary way of interacting with a promise is through its `then` method, which\n  registers callbacks to receive either a promise's eventual value or the reason\n  why the promise cannot be fulfilled.\n\n  Terminology\n  -----------\n\n  - `promise` is an object or function with a `then` method whose behavior conforms to this specification.\n  - `thenable` is an object or function that defines a `then` method.\n  - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).\n  - `exception` is a value that is thrown using the throw statement.\n  - `reason` is a value that indicates why a promise was rejected.\n  - `settled` the final resting state of a promise, fulfilled or rejected.\n\n  A promise can be in one of three states: pending, fulfilled, or rejected.\n\n  Promises that are fulfilled have a fulfillment value and are in the fulfilled\n  state.  Promises that are rejected have a rejection reason and are in the\n  rejected state.  A fulfillment value is never a thenable.\n\n  Promises can also be said to *resolve* a value.  If this value is also a\n  promise, then the original promise's settled state will match the value's\n  settled state.  So a promise that *resolves* a promise that rejects will\n  itself reject, and a promise that *resolves* a promise that fulfills will\n  itself fulfill.\n\n\n  Basic Usage:\n  ------------\n\n  ```js\n  let promise = new Promise(function(resolve, reject) {\n    // on success\n    resolve(value);\n\n    // on failure\n    reject(reason);\n  });\n\n  promise.then(function(value) {\n    // on fulfillment\n  }, function(reason) {\n    // on rejection\n  });\n  ```\n\n  Advanced Usage:\n  ---------------\n\n  Promises shine when abstracting away asynchronous interactions such as\n  `XMLHttpRequest`s.\n\n  ```js\n  function getJSON(url) {\n    return new Promise(function(resolve, reject){\n      let xhr = new XMLHttpRequest();\n\n      xhr.open('GET', url);\n      xhr.onreadystatechange = handler;\n      xhr.responseType = 'json';\n      xhr.setRequestHeader('Accept', 'application/json');\n      xhr.send();\n\n      function handler() {\n        if (this.readyState === this.DONE) {\n          if (this.status === 200) {\n            resolve(this.response);\n          } else {\n            reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));\n          }\n        }\n      };\n    });\n  }\n\n  getJSON('/posts.json').then(function(json) {\n    // on fulfillment\n  }, function(reason) {\n    // on rejection\n  });\n  ```\n\n  Unlike callbacks, promises are great composable primitives.\n\n  ```js\n  Promise.all([\n    getJSON('/posts'),\n    getJSON('/comments')\n  ]).then(function(values){\n    values[0] // => postsJSON\n    values[1] // => commentsJSON\n\n    return values;\n  });\n  ```\n\n  @class Promise\n  @param {function} resolver\n  Useful for tooling.\n  @constructor\n*/\nfunction Promise(resolver) {\n  this[PROMISE_ID] = nextId();\n  this._result = this._state = undefined;\n  this._subscribers = [];\n\n  if (noop !== resolver) {\n    typeof resolver !== 'function' && needsResolver();\n    this instanceof Promise ? initializePromise(this, resolver) : needsNew();\n  }\n}\n\nPromise.all = all;\nPromise.race = race;\nPromise.resolve = resolve;\nPromise.reject = reject;\nPromise._setScheduler = setScheduler;\nPromise._setAsap = setAsap;\nPromise._asap = asap;\n\nPromise.prototype = {\n  constructor: Promise,\n\n  /**\n    The primary way of interacting with a promise is through its `then` method,\n    which registers callbacks to receive either a promise's eventual value or the\n    reason why the promise cannot be fulfilled.\n  \n    ```js\n    findUser().then(function(user){\n      // user is available\n    }, function(reason){\n      // user is unavailable, and you are given the reason why\n    });\n    ```\n  \n    Chaining\n    --------\n  \n    The return value of `then` is itself a promise.  This second, 'downstream'\n    promise is resolved with the return value of the first promise's fulfillment\n    or rejection handler, or rejected if the handler throws an exception.\n  \n    ```js\n    findUser().then(function (user) {\n      return user.name;\n    }, function (reason) {\n      return 'default name';\n    }).then(function (userName) {\n      // If `findUser` fulfilled, `userName` will be the user's name, otherwise it\n      // will be `'default name'`\n    });\n  \n    findUser().then(function (user) {\n      throw new Error('Found user, but still unhappy');\n    }, function (reason) {\n      throw new Error('`findUser` rejected and we're unhappy');\n    }).then(function (value) {\n      // never reached\n    }, function (reason) {\n      // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.\n      // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.\n    });\n    ```\n    If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.\n  \n    ```js\n    findUser().then(function (user) {\n      throw new PedagogicalException('Upstream error');\n    }).then(function (value) {\n      // never reached\n    }).then(function (value) {\n      // never reached\n    }, function (reason) {\n      // The `PedgagocialException` is propagated all the way down to here\n    });\n    ```\n  \n    Assimilation\n    ------------\n  \n    Sometimes the value you want to propagate to a downstream promise can only be\n    retrieved asynchronously. This can be achieved by returning a promise in the\n    fulfillment or rejection handler. The downstream promise will then be pending\n    until the returned promise is settled. This is called *assimilation*.\n  \n    ```js\n    findUser().then(function (user) {\n      return findCommentsByAuthor(user);\n    }).then(function (comments) {\n      // The user's comments are now available\n    });\n    ```\n  \n    If the assimliated promise rejects, then the downstream promise will also reject.\n  \n    ```js\n    findUser().then(function (user) {\n      return findCommentsByAuthor(user);\n    }).then(function (comments) {\n      // If `findCommentsByAuthor` fulfills, we'll have the value here\n    }, function (reason) {\n      // If `findCommentsByAuthor` rejects, we'll have the reason here\n    });\n    ```\n  \n    Simple Example\n    --------------\n  \n    Synchronous Example\n  \n    ```javascript\n    let result;\n  \n    try {\n      result = findResult();\n      // success\n    } catch(reason) {\n      // failure\n    }\n    ```\n  \n    Errback Example\n  \n    ```js\n    findResult(function(result, err){\n      if (err) {\n        // failure\n      } else {\n        // success\n      }\n    });\n    ```\n  \n    Promise Example;\n  \n    ```javascript\n    findResult().then(function(result){\n      // success\n    }, function(reason){\n      // failure\n    });\n    ```\n  \n    Advanced Example\n    --------------\n  \n    Synchronous Example\n  \n    ```javascript\n    let author, books;\n  \n    try {\n      author = findAuthor();\n      books  = findBooksByAuthor(author);\n      // success\n    } catch(reason) {\n      // failure\n    }\n    ```\n  \n    Errback Example\n  \n    ```js\n  \n    function foundBooks(books) {\n  \n    }\n  \n    function failure(reason) {\n  \n    }\n  \n    findAuthor(function(author, err){\n      if (err) {\n        failure(err);\n        // failure\n      } else {\n        try {\n          findBoooksByAuthor(author, function(books, err) {\n            if (err) {\n              failure(err);\n            } else {\n              try {\n                foundBooks(books);\n              } catch(reason) {\n                failure(reason);\n              }\n            }\n          });\n        } catch(error) {\n          failure(err);\n        }\n        // success\n      }\n    });\n    ```\n  \n    Promise Example;\n  \n    ```javascript\n    findAuthor().\n      then(findBooksByAuthor).\n      then(function(books){\n        // found books\n    }).catch(function(reason){\n      // something went wrong\n    });\n    ```\n  \n    @method then\n    @param {Function} onFulfilled\n    @param {Function} onRejected\n    Useful for tooling.\n    @return {Promise}\n  */\n  then: then,\n\n  /**\n    `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same\n    as the catch block of a try/catch statement.\n  \n    ```js\n    function findAuthor(){\n      throw new Error('couldn't find that author');\n    }\n  \n    // synchronous\n    try {\n      findAuthor();\n    } catch(reason) {\n      // something went wrong\n    }\n  \n    // async with promises\n    findAuthor().catch(function(reason){\n      // something went wrong\n    });\n    ```\n  \n    @method catch\n    @param {Function} onRejection\n    Useful for tooling.\n    @return {Promise}\n  */\n  'catch': function _catch(onRejection) {\n    return this.then(null, onRejection);\n  }\n};\n\nfunction polyfill() {\n    var local = undefined;\n\n    if (typeof global !== 'undefined') {\n        local = global;\n    } else if (typeof self !== 'undefined') {\n        local = self;\n    } else {\n        try {\n            local = Function('return this')();\n        } catch (e) {\n            throw new Error('polyfill failed because global object is unavailable in this environment');\n        }\n    }\n\n    var P = local.Promise;\n\n    if (P) {\n        var promiseToString = null;\n        try {\n            promiseToString = Object.prototype.toString.call(P.resolve());\n        } catch (e) {\n            // silently ignored\n        }\n\n        if (promiseToString === '[object Promise]' && !P.cast) {\n            return;\n        }\n    }\n\n    local.Promise = Promise;\n}\n\npolyfill();\n// Strange compat..\nPromise.polyfill = polyfill;\nPromise.Promise = Promise;\n\nreturn Promise;\n\n})));\n\n}).call(this,_dereq_('_process'),typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"_process\":482}],219:[function(_dereq_,module,exports){\n'use strict';\n\nmodule.exports = _dereq_('./is-implemented')() ? Symbol : _dereq_('./polyfill');\n\n},{\"./is-implemented\":220,\"./polyfill\":222}],220:[function(_dereq_,module,exports){\n'use strict';\n\nvar validTypes = { object: true, symbol: true };\n\nmodule.exports = function () {\n\tvar symbol;\n\tif (typeof Symbol !== 'function') return false;\n\tsymbol = Symbol('test symbol');\n\ttry { String(symbol); } catch (e) { return false; }\n\n\t// Return 'true' also for polyfills\n\tif (!validTypes[typeof Symbol.iterator]) return false;\n\tif (!validTypes[typeof Symbol.toPrimitive]) return false;\n\tif (!validTypes[typeof Symbol.toStringTag]) return false;\n\n\treturn true;\n};\n\n},{}],221:[function(_dereq_,module,exports){\n'use strict';\n\nmodule.exports = function (x) {\n\tif (!x) return false;\n\tif (typeof x === 'symbol') return true;\n\tif (!x.constructor) return false;\n\tif (x.constructor.name !== 'Symbol') return false;\n\treturn (x[x.constructor.toStringTag] === 'Symbol');\n};\n\n},{}],222:[function(_dereq_,module,exports){\n// ES2015 Symbol polyfill for environments that do not (or partially) support it\n\n'use strict';\n\nvar d              = _dereq_('d')\n  , validateSymbol = _dereq_('./validate-symbol')\n\n  , create = Object.create, defineProperties = Object.defineProperties\n  , defineProperty = Object.defineProperty, objPrototype = Object.prototype\n  , NativeSymbol, SymbolPolyfill, HiddenSymbol, globalSymbols = create(null)\n  , isNativeSafe;\n\nif (typeof Symbol === 'function') {\n\tNativeSymbol = Symbol;\n\ttry {\n\t\tString(NativeSymbol());\n\t\tisNativeSafe = true;\n\t} catch (ignore) {}\n}\n\nvar generateName = (function () {\n\tvar created = create(null);\n\treturn function (desc) {\n\t\tvar postfix = 0, name, ie11BugWorkaround;\n\t\twhile (created[desc + (postfix || '')]) ++postfix;\n\t\tdesc += (postfix || '');\n\t\tcreated[desc] = true;\n\t\tname = '@@' + desc;\n\t\tdefineProperty(objPrototype, name, d.gs(null, function (value) {\n\t\t\t// For IE11 issue see:\n\t\t\t// https://connect.microsoft.com/IE/feedbackdetail/view/1928508/\n\t\t\t//    ie11-broken-getters-on-dom-objects\n\t\t\t// https://github.com/medikoo/es6-symbol/issues/12\n\t\t\tif (ie11BugWorkaround) return;\n\t\t\tie11BugWorkaround = true;\n\t\t\tdefineProperty(this, name, d(value));\n\t\t\tie11BugWorkaround = false;\n\t\t}));\n\t\treturn name;\n\t};\n}());\n\n// Internal constructor (not one exposed) for creating Symbol instances.\n// This one is used to ensure that `someSymbol instanceof Symbol` always return false\nHiddenSymbol = function Symbol(description) {\n\tif (this instanceof HiddenSymbol) throw new TypeError('Symbol is not a constructor');\n\treturn SymbolPolyfill(description);\n};\n\n// Exposed `Symbol` constructor\n// (returns instances of HiddenSymbol)\nmodule.exports = SymbolPolyfill = function Symbol(description) {\n\tvar symbol;\n\tif (this instanceof Symbol) throw new TypeError('Symbol is not a constructor');\n\tif (isNativeSafe) return NativeSymbol(description);\n\tsymbol = create(HiddenSymbol.prototype);\n\tdescription = (description === undefined ? '' : String(description));\n\treturn defineProperties(symbol, {\n\t\t__description__: d('', description),\n\t\t__name__: d('', generateName(description))\n\t});\n};\ndefineProperties(SymbolPolyfill, {\n\tfor: d(function (key) {\n\t\tif (globalSymbols[key]) return globalSymbols[key];\n\t\treturn (globalSymbols[key] = SymbolPolyfill(String(key)));\n\t}),\n\tkeyFor: d(function (s) {\n\t\tvar key;\n\t\tvalidateSymbol(s);\n\t\tfor (key in globalSymbols) if (globalSymbols[key] === s) return key;\n\t}),\n\n\t// To ensure proper interoperability with other native functions (e.g. Array.from)\n\t// fallback to eventual native implementation of given symbol\n\thasInstance: d('', (NativeSymbol && NativeSymbol.hasInstance) || SymbolPolyfill('hasInstance')),\n\tisConcatSpreadable: d('', (NativeSymbol && NativeSymbol.isConcatSpreadable) ||\n\t\tSymbolPolyfill('isConcatSpreadable')),\n\titerator: d('', (NativeSymbol && NativeSymbol.iterator) || SymbolPolyfill('iterator')),\n\tmatch: d('', (NativeSymbol && NativeSymbol.match) || SymbolPolyfill('match')),\n\treplace: d('', (NativeSymbol && NativeSymbol.replace) || SymbolPolyfill('replace')),\n\tsearch: d('', (NativeSymbol && NativeSymbol.search) || SymbolPolyfill('search')),\n\tspecies: d('', (NativeSymbol && NativeSymbol.species) || SymbolPolyfill('species')),\n\tsplit: d('', (NativeSymbol && NativeSymbol.split) || SymbolPolyfill('split')),\n\ttoPrimitive: d('', (NativeSymbol && NativeSymbol.toPrimitive) || SymbolPolyfill('toPrimitive')),\n\ttoStringTag: d('', (NativeSymbol && NativeSymbol.toStringTag) || SymbolPolyfill('toStringTag')),\n\tunscopables: d('', (NativeSymbol && NativeSymbol.unscopables) || SymbolPolyfill('unscopables'))\n});\n\n// Internal tweaks for real symbol producer\ndefineProperties(HiddenSymbol.prototype, {\n\tconstructor: d(SymbolPolyfill),\n\ttoString: d('', function () { return this.__name__; })\n});\n\n// Proper implementation of methods exposed on Symbol.prototype\n// They won't be accessible on produced symbol instances as they derive from HiddenSymbol.prototype\ndefineProperties(SymbolPolyfill.prototype, {\n\ttoString: d(function () { return 'Symbol (' + validateSymbol(this).__description__ + ')'; }),\n\tvalueOf: d(function () { return validateSymbol(this); })\n});\ndefineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toPrimitive, d('', function () {\n\tvar symbol = validateSymbol(this);\n\tif (typeof symbol === 'symbol') return symbol;\n\treturn symbol.toString();\n}));\ndefineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toStringTag, d('c', 'Symbol'));\n\n// Proper implementaton of toPrimitive and toStringTag for returned symbol instances\ndefineProperty(HiddenSymbol.prototype, SymbolPolyfill.toStringTag,\n\td('c', SymbolPolyfill.prototype[SymbolPolyfill.toStringTag]));\n\n// Note: It's important to define `toPrimitive` as last one, as some implementations\n// implement `toPrimitive` natively without implementing `toStringTag` (or other specified symbols)\n// And that may invoke error in definition flow:\n// See: https://github.com/medikoo/es6-symbol/issues/13#issuecomment-164146149\ndefineProperty(HiddenSymbol.prototype, SymbolPolyfill.toPrimitive,\n\td('c', SymbolPolyfill.prototype[SymbolPolyfill.toPrimitive]));\n\n},{\"./validate-symbol\":223,\"d\":151}],223:[function(_dereq_,module,exports){\n'use strict';\n\nvar isSymbol = _dereq_('./is-symbol');\n\nmodule.exports = function (value) {\n\tif (!isSymbol(value)) throw new TypeError(value + \" is not a symbol\");\n\treturn value;\n};\n\n},{\"./is-symbol\":221}],224:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = extractPlanes\n\nfunction extractPlanes(M, zNear, zFar) {\n  var z  = zNear || 0.0\n  var zf = zFar || 1.0\n  return [\n    [ M[12] + M[0], M[13] + M[1], M[14] + M[2], M[15] + M[3] ],\n    [ M[12] - M[0], M[13] - M[1], M[14] - M[2], M[15] - M[3] ],\n    [ M[12] + M[4], M[13] + M[5], M[14] + M[6], M[15] + M[7] ],\n    [ M[12] - M[4], M[13] - M[5], M[14] - M[6], M[15] - M[7] ],\n    [ z*M[12] + M[8], z*M[13] + M[9], z*M[14] + M[10], z*M[15] + M[11] ],\n    [ zf*M[12] - M[8], zf*M[13] - M[9], zf*M[14] - M[10], zf*M[15] - M[11] ]\n  ]\n}\n},{}],225:[function(_dereq_,module,exports){\n/**\n * inspired by is-number <https://github.com/jonschlinkert/is-number>\n * but significantly simplified and sped up by ignoring number and string constructors\n * ie these return false:\n *   new Number(1)\n *   new String('1')\n */\n\n'use strict';\n\nvar allBlankCharCodes = _dereq_('is-string-blank');\n\nmodule.exports = function(n) {\n    var type = typeof n;\n    if(type === 'string') {\n        var original = n;\n        n = +n;\n        // whitespace strings cast to zero - filter them out\n        if(n===0 && allBlankCharCodes(original)) return false;\n    }\n    else if(type !== 'number') return false;\n\n    return n - n < 1;\n};\n\n},{\"is-string-blank\":423}],226:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createFilteredVector\n\nvar cubicHermite = _dereq_('cubic-hermite')\nvar bsearch = _dereq_('binary-search-bounds')\n\nfunction clamp(lo, hi, x) {\n  return Math.min(hi, Math.max(lo, x))\n}\n\nfunction FilteredVector(state0, velocity0, t0) {\n  this.dimension  = state0.length\n  this.bounds     = [ new Array(this.dimension), new Array(this.dimension) ]\n  for(var i=0; i<this.dimension; ++i) {\n    this.bounds[0][i] = -Infinity\n    this.bounds[1][i] = Infinity\n  }\n  this._state     = state0.slice().reverse()\n  this._velocity  = velocity0.slice().reverse()\n  this._time      = [ t0 ]\n  this._scratch   = [ state0.slice(), state0.slice(), state0.slice(), state0.slice(), state0.slice() ]\n}\n\nvar proto = FilteredVector.prototype\n\nproto.flush = function(t) {\n  var idx = bsearch.gt(this._time, t) - 1\n  if(idx <= 0) {\n    return\n  }\n  this._time.splice(0, idx)\n  this._state.splice(0, idx * this.dimension)\n  this._velocity.splice(0, idx * this.dimension)\n}\n\nproto.curve = function(t) {\n  var time      = this._time\n  var n         = time.length\n  var idx       = bsearch.le(time, t)\n  var result    = this._scratch[0]\n  var state     = this._state\n  var velocity  = this._velocity\n  var d         = this.dimension\n  var bounds    = this.bounds\n  if(idx < 0) {\n    var ptr = d-1\n    for(var i=0; i<d; ++i, --ptr) {\n      result[i] = state[ptr]\n    }\n  } else if(idx >= n-1) {\n    var ptr = state.length-1\n    var tf = t - time[n-1]\n    for(var i=0; i<d; ++i, --ptr) {\n      result[i] = state[ptr] + tf * velocity[ptr]\n    }\n  } else {\n    var ptr = d * (idx+1) - 1\n    var t0  = time[idx]\n    var t1  = time[idx+1]\n    var dt  = (t1 - t0) || 1.0\n    var x0  = this._scratch[1]\n    var x1  = this._scratch[2]\n    var v0  = this._scratch[3]\n    var v1  = this._scratch[4]\n    var steady = true\n    for(var i=0; i<d; ++i, --ptr) {\n      x0[i] = state[ptr]\n      v0[i] = velocity[ptr] * dt\n      x1[i] = state[ptr+d]\n      v1[i] = velocity[ptr+d] * dt\n      steady = steady && (x0[i] === x1[i] && v0[i] === v1[i] && v0[i] === 0.0)\n    }\n    if(steady) {\n      for(var i=0; i<d; ++i) {\n        result[i] = x0[i]\n      }\n    } else {\n      cubicHermite(x0, v0, x1, v1, (t-t0)/dt, result)\n    }\n  }\n  var lo = bounds[0]\n  var hi = bounds[1]\n  for(var i=0; i<d; ++i) {\n    result[i] = clamp(lo[i], hi[i], result[i])\n  }\n  return result\n}\n\nproto.dcurve = function(t) {\n  var time     = this._time\n  var n        = time.length\n  var idx      = bsearch.le(time, t)\n  var result   = this._scratch[0]\n  var state    = this._state\n  var velocity = this._velocity\n  var d        = this.dimension\n  if(idx >= n-1) {\n    var ptr = state.length-1\n    var tf = t - time[n-1]\n    for(var i=0; i<d; ++i, --ptr) {\n      result[i] = velocity[ptr]\n    }\n  } else {\n    var ptr = d * (idx+1) - 1\n    var t0 = time[idx]\n    var t1 = time[idx+1]\n    var dt = (t1 - t0) || 1.0\n    var x0 = this._scratch[1]\n    var x1 = this._scratch[2]\n    var v0 = this._scratch[3]\n    var v1 = this._scratch[4]\n    var steady = true\n    for(var i=0; i<d; ++i, --ptr) {\n      x0[i] = state[ptr]\n      v0[i] = velocity[ptr] * dt\n      x1[i] = state[ptr+d]\n      v1[i] = velocity[ptr+d] * dt\n      steady = steady && (x0[i] === x1[i] && v0[i] === v1[i] && v0[i] === 0.0)\n    }\n    if(steady) {\n      for(var i=0; i<d; ++i) {\n        result[i] = 0.0\n      }\n    } else {\n      cubicHermite.derivative(x0, v0, x1, v1, (t-t0)/dt, result)\n      for(var i=0; i<d; ++i) {\n        result[i] /= dt\n      }\n    }\n  }\n  return result\n}\n\nproto.lastT = function() {\n  var time = this._time\n  return time[time.length-1]\n}\n\nproto.stable = function() {\n  var velocity = this._velocity\n  var ptr = velocity.length\n  for(var i=this.dimension-1; i>=0; --i) {\n    if(velocity[--ptr]) {\n      return false\n    }\n  }\n  return true\n}\n\nproto.jump = function(t) {\n  var t0 = this.lastT()\n  var d  = this.dimension\n  if(t < t0 || arguments.length !== d+1) {\n    return\n  }\n  var state     = this._state\n  var velocity  = this._velocity\n  var ptr       = state.length-this.dimension\n  var bounds    = this.bounds\n  var lo        = bounds[0]\n  var hi        = bounds[1]\n  this._time.push(t0, t)\n  for(var j=0; j<2; ++j) {\n    for(var i=0; i<d; ++i) {\n      state.push(state[ptr++])\n      velocity.push(0)\n    }\n  }\n  this._time.push(t)\n  for(var i=d; i>0; --i) {\n    state.push(clamp(lo[i-1], hi[i-1], arguments[i]))\n    velocity.push(0)\n  }\n}\n\nproto.push = function(t) {\n  var t0 = this.lastT()\n  var d  = this.dimension\n  if(t < t0 || arguments.length !== d+1) {\n    return\n  }\n  var state     = this._state\n  var velocity  = this._velocity\n  var ptr       = state.length-this.dimension\n  var dt        = t - t0\n  var bounds    = this.bounds\n  var lo        = bounds[0]\n  var hi        = bounds[1]\n  var sf        = (dt > 1e-6) ? 1/dt : 0\n  this._time.push(t)\n  for(var i=d; i>0; --i) {\n    var xc = clamp(lo[i-1], hi[i-1], arguments[i])\n    state.push(xc)\n    velocity.push((xc - state[ptr++]) * sf)\n  }\n}\n\nproto.set = function(t) {\n  var d = this.dimension\n  if(t < this.lastT() || arguments.length !== d+1) {\n    return\n  }\n  var state     = this._state\n  var velocity  = this._velocity\n  var bounds    = this.bounds\n  var lo        = bounds[0]\n  var hi        = bounds[1]\n  this._time.push(t)\n  for(var i=d; i>0; --i) {\n    state.push(clamp(lo[i-1], hi[i-1], arguments[i]))\n    velocity.push(0)\n  }\n}\n\nproto.move = function(t) {\n  var t0 = this.lastT()\n  var d  = this.dimension\n  if(t <= t0 || arguments.length !== d+1) {\n    return\n  }\n  var state    = this._state\n  var velocity = this._velocity\n  var statePtr = state.length - this.dimension\n  var bounds   = this.bounds\n  var lo       = bounds[0]\n  var hi       = bounds[1]\n  var dt       = t - t0\n  var sf       = (dt > 1e-6) ? 1/dt : 0.0\n  this._time.push(t)\n  for(var i=d; i>0; --i) {\n    var dx = arguments[i]\n    state.push(clamp(lo[i-1], hi[i-1], state[statePtr++] + dx))\n    velocity.push(dx * sf)\n  }\n}\n\nproto.idle = function(t) {\n  var t0 = this.lastT()\n  if(t < t0) {\n    return\n  }\n  var d        = this.dimension\n  var state    = this._state\n  var velocity = this._velocity\n  var statePtr = state.length-d\n  var bounds   = this.bounds\n  var lo       = bounds[0]\n  var hi       = bounds[1]\n  var dt       = t - t0\n  this._time.push(t)\n  for(var i=d-1; i>=0; --i) {\n    state.push(clamp(lo[i], hi[i], state[statePtr] + dt * velocity[statePtr]))\n    velocity.push(0)\n    statePtr += 1\n  }\n}\n\nfunction getZero(d) {\n  var result = new Array(d)\n  for(var i=0; i<d; ++i) {\n    result[i] = 0.0\n  }\n  return result\n}\n\nfunction createFilteredVector(initState, initVelocity, initTime) {\n  switch(arguments.length) {\n    case 0:\n      return new FilteredVector([0], [0], 0)\n    case 1:\n      if(typeof initState === 'number') {\n        var zero = getZero(initState)\n        return new FilteredVector(zero, zero, 0)\n      } else {\n        return new FilteredVector(initState, getZero(initState.length), 0)\n      }\n    case 2:\n      if(typeof initVelocity === 'number') {\n        var zero = getZero(initState.length)\n        return new FilteredVector(initState, zero, +initVelocity)\n      } else {\n        initTime = 0\n      }\n    case 3:\n      if(initState.length !== initVelocity.length) {\n        throw new Error('state and velocity lengths must match')\n      }\n      return new FilteredVector(initState, initVelocity, initTime)\n  }\n}\n\n},{\"binary-search-bounds\":91,\"cubic-hermite\":145}],227:[function(_dereq_,module,exports){\n/*eslint new-cap:0*/\nvar dtype = _dereq_('dtype')\n\nmodule.exports = flattenVertexData\n\nfunction flattenVertexData (data, output, offset) {\n  if (!data) throw new TypeError('must specify data as first parameter')\n  offset = +(offset || 0) | 0\n\n  if (Array.isArray(data) && (data[0] && typeof data[0][0] === 'number')) {\n    var dim = data[0].length\n    var length = data.length * dim\n    var i, j, k, l\n\n    // no output specified, create a new typed array\n    if (!output || typeof output === 'string') {\n      output = new (dtype(output || 'float32'))(length + offset)\n    }\n\n    var dstLength = output.length - offset\n    if (length !== dstLength) {\n      throw new Error('source length ' + length + ' (' + dim + 'x' + data.length + ')' +\n        ' does not match destination length ' + dstLength)\n    }\n\n    for (i = 0, k = offset; i < data.length; i++) {\n      for (j = 0; j < dim; j++) {\n        output[k++] = data[i][j] === null ? NaN : data[i][j]\n      }\n    }\n  } else {\n    if (!output || typeof output === 'string') {\n      // no output, create a new one\n      var Ctor = dtype(output || 'float32')\n\n      // handle arrays separately due to possible nulls\n      if (Array.isArray(data) || output === 'array') {\n        output = new Ctor(data.length + offset)\n        for (i = 0, k = offset, l = output.length; k < l; k++, i++) {\n          output[k] = data[i] === null ? NaN : data[i]\n        }\n      } else {\n        if (offset === 0) {\n          output = new Ctor(data)\n        } else {\n          output = new Ctor(data.length + offset)\n\n          output.set(data, offset)\n        }\n      }\n    } else {\n      // store output in existing array\n      output.set(data, offset)\n    }\n  }\n\n  return output\n}\n\n},{\"dtype\":169}],228:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar stringifyFont = _dereq_('css-font/stringify')\r\nvar defaultChars = [32, 126]\r\n\r\nmodule.exports = atlas\r\n\r\nfunction atlas(options) {\r\n  options = options || {}\r\n\r\n  var shape  = options.shape ? options.shape : options.canvas ? [options.canvas.width, options.canvas.height] : [512, 512]\r\n  var canvas = options.canvas || document.createElement('canvas')\r\n  var font   = options.font\r\n  var step   = typeof options.step === 'number' ? [options.step, options.step] : options.step || [32, 32]\r\n  var chars  = options.chars || defaultChars\r\n\r\n  if (font && typeof font !== 'string') font = stringifyFont(font)\r\n\r\n  if (!Array.isArray(chars)) {\r\n    chars = String(chars).split('')\r\n  } else\r\n  if (chars.length === 2\r\n    && typeof chars[0] === 'number'\r\n    && typeof chars[1] === 'number'\r\n  ) {\r\n    var newchars = []\r\n\r\n    for (var i = chars[0], j = 0; i <= chars[1]; i++) {\r\n      newchars[j++] = String.fromCharCode(i)\r\n    }\r\n\r\n    chars = newchars\r\n  }\r\n\r\n  shape = shape.slice()\r\n  canvas.width  = shape[0]\r\n  canvas.height = shape[1]\r\n\r\n  var ctx = canvas.getContext('2d')\r\n\r\n  ctx.fillStyle = '#000'\r\n  ctx.fillRect(0, 0, canvas.width, canvas.height)\r\n\r\n  ctx.font = font\r\n  ctx.textAlign = 'center'\r\n  ctx.textBaseline = 'middle'\r\n  ctx.fillStyle = '#fff'\r\n\r\n  var x = step[0] / 2\r\n  var y = step[1] / 2\r\n  for (var i = 0; i < chars.length; i++) {\r\n    ctx.fillText(chars[i], x, y)\r\n    if ((x += step[0]) > shape[0] - step[0]/2) (x = step[0]/2), (y += step[1])\r\n  }\r\n\r\n  return canvas\r\n}\r\n\n},{\"css-font/stringify\":142}],229:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nmodule.exports = measure\r\n\r\nmeasure.canvas = document.createElement('canvas')\r\nmeasure.cache = {}\r\n\r\nfunction measure (font, o) {\r\n\tif (!o) o = {}\r\n\r\n\tif (typeof font === 'string' || Array.isArray(font)) {\r\n\t\to.family = font\r\n\t}\r\n\r\n\tvar family = Array.isArray(o.family) ? o.family.join(', ') : o.family\r\n\tif (!family) throw Error('`family` must be defined')\r\n\r\n\tvar fs = o.size || o.fontSize || o.em || 48\r\n\tvar weight = o.weight || o.fontWeight || ''\r\n\tvar style = o.style || o.fontStyle || ''\r\n\tvar font = [style, weight, fs].join(' ') + 'px ' + family\r\n\tvar origin = o.origin || 'top'\r\n\r\n\tif (measure.cache[family]) {\r\n\t\t// return more precise values if cache has them\r\n\t\tif (fs <= measure.cache[family].em) {\r\n\t\t\treturn applyOrigin(measure.cache[family], origin)\r\n\t\t}\r\n\t}\r\n\r\n\tvar canvas = o.canvas || measure.canvas\r\n\tvar ctx = canvas.getContext('2d')\r\n\tvar chars = {\r\n\t\tupper: o.upper !== undefined ? o.upper : 'H',\r\n\t\tlower: o.lower !== undefined ? o.lower : 'x',\r\n\t\tdescent: o.descent !== undefined ? o.descent : 'p',\r\n\t\tascent: o.ascent !== undefined ? o.ascent : 'h',\r\n\t\ttittle: o.tittle !== undefined ? o.tittle : 'i',\r\n\t\tovershoot: o.overshoot !== undefined ? o.overshoot : 'O'\r\n\t}\r\n\tvar l = Math.ceil(fs * 1.5)\r\n\tcanvas.height = l\r\n\tcanvas.width = l * .5\r\n\tctx.font = font\r\n\r\n\tvar char = 'H'\r\n\tvar result = {\r\n\t\ttop: 0\r\n\t}\r\n\r\n\t// measure line-height\r\n\tctx.clearRect(0, 0, l, l)\r\n\tctx.textBaseline = 'top'\r\n\tctx.fillStyle = 'black'\r\n\tctx.fillText(char, 0, 0)\r\n\tvar topPx = firstTop(ctx.getImageData(0, 0, l, l))\r\n\tctx.clearRect(0, 0, l, l)\r\n\tctx.textBaseline = 'bottom'\r\n\tctx.fillText(char, 0, l)\r\n\tvar bottomPx = firstTop(ctx.getImageData(0, 0, l, l))\r\n\tresult.lineHeight =\r\n\tresult.bottom = l - bottomPx + topPx\r\n\r\n\t// measure baseline\r\n\tctx.clearRect(0, 0, l, l)\r\n\tctx.textBaseline = 'alphabetic'\r\n\tctx.fillText(char, 0, l)\r\n\tvar baselinePx = firstTop(ctx.getImageData(0, 0, l, l))\r\n\tvar baseline = l - baselinePx - 1 + topPx\r\n\tresult.baseline =\r\n\tresult.alphabetic = baseline\r\n\r\n\t// measure median\r\n\tctx.clearRect(0, 0, l, l)\r\n\tctx.textBaseline = 'middle'\r\n\tctx.fillText(char, 0, l * .5)\r\n\tvar medianPx = firstTop(ctx.getImageData(0, 0, l, l))\r\n\tresult.median =\r\n\tresult.middle = l - medianPx - 1 + topPx - l * .5\r\n\r\n\t// measure hanging\r\n\tctx.clearRect(0, 0, l, l)\r\n\tctx.textBaseline = 'hanging'\r\n\tctx.fillText(char, 0, l * .5)\r\n\tvar hangingPx = firstTop(ctx.getImageData(0, 0, l, l))\r\n\tresult.hanging = l - hangingPx - 1 + topPx - l * .5\r\n\r\n\t// measure ideographic\r\n\tctx.clearRect(0, 0, l, l)\r\n\tctx.textBaseline = 'ideographic'\r\n\tctx.fillText(char, 0, l)\r\n\tvar ideographicPx = firstTop(ctx.getImageData(0, 0, l, l))\r\n\tresult.ideographic = l - ideographicPx - 1 + topPx\r\n\r\n\t// measure cap\r\n\tif (chars.upper) {\r\n\t\tctx.clearRect(0, 0, l, l)\r\n\t\tctx.textBaseline = 'top'\r\n\t\tctx.fillText(chars.upper, 0, 0)\r\n\t\tresult.upper = firstTop(ctx.getImageData(0, 0, l, l))\r\n\t\tresult.capHeight = (result.baseline - result.upper)\r\n\t}\r\n\r\n\t// measure x\r\n\tif (chars.lower) {\r\n\t\tctx.clearRect(0, 0, l, l)\r\n\t\tctx.textBaseline = 'top'\r\n\t\tctx.fillText(chars.lower, 0, 0)\r\n\t\tresult.lower = firstTop(ctx.getImageData(0, 0, l, l))\r\n\t\tresult.xHeight = (result.baseline - result.lower)\r\n\t}\r\n\r\n\t// measure tittle\r\n\tif (chars.tittle) {\r\n\t\tctx.clearRect(0, 0, l, l)\r\n\t\tctx.textBaseline = 'top'\r\n\t\tctx.fillText(chars.tittle, 0, 0)\r\n\t\tresult.tittle = firstTop(ctx.getImageData(0, 0, l, l))\r\n\t}\r\n\r\n\t// measure ascent\r\n\tif (chars.ascent) {\r\n\t\tctx.clearRect(0, 0, l, l)\r\n\t\tctx.textBaseline = 'top'\r\n\t\tctx.fillText(chars.ascent, 0, 0)\r\n\t\tresult.ascent = firstTop(ctx.getImageData(0, 0, l, l))\r\n\t}\r\n\r\n\t// measure descent\r\n\tif (chars.descent) {\r\n\t\tctx.clearRect(0, 0, l, l)\r\n\t\tctx.textBaseline = 'top'\r\n\t\tctx.fillText(chars.descent, 0, 0)\r\n\t\tresult.descent = firstBottom(ctx.getImageData(0, 0, l, l))\r\n\t}\r\n\r\n\t// measure overshoot\r\n\tif (chars.overshoot) {\r\n\t\tctx.clearRect(0, 0, l, l)\r\n\t\tctx.textBaseline = 'top'\r\n\t\tctx.fillText(chars.overshoot, 0, 0)\r\n\t\tvar overshootPx = firstBottom(ctx.getImageData(0, 0, l, l))\r\n\t\tresult.overshoot = overshootPx - baseline\r\n\t}\r\n\r\n\t// normalize result\r\n\tfor (var name in result) {\r\n\t\tresult[name] /= fs\r\n\t}\r\n\r\n\tresult.em = fs\r\n\tmeasure.cache[family] = result\r\n\r\n\treturn applyOrigin(result, origin)\r\n}\r\n\r\nfunction applyOrigin(obj, origin) {\r\n\tvar res = {}\r\n\tif (typeof origin === 'string') origin = obj[origin]\r\n\tfor (var name in obj) {\r\n\t\tif (name === 'em') continue\r\n\t\tres[name] = obj[name] - origin\r\n\t}\r\n\treturn res\r\n}\r\n\r\nfunction firstTop(iData) {\r\n\tvar l = iData.height\r\n\tvar data = iData.data\r\n\tfor (var i = 3; i < data.length; i+=4) {\r\n\t\tif (data[i] !== 0) {\r\n\t\t\treturn Math.floor((i - 3) *.25 / l)\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction firstBottom(iData) {\r\n\tvar l = iData.height\r\n\tvar data = iData.data\r\n\tfor (var i = data.length - 1; i > 0; i -= 4) {\r\n\t\tif (data[i] !== 0) {\r\n\t\t\treturn Math.floor((i - 3) *.25 / l)\r\n\t\t}\r\n\t}\r\n}\r\n\n},{}],230:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = createRBTree\n\nvar RED   = 0\nvar BLACK = 1\n\nfunction RBNode(color, key, value, left, right, count) {\n  this._color = color\n  this.key = key\n  this.value = value\n  this.left = left\n  this.right = right\n  this._count = count\n}\n\nfunction cloneNode(node) {\n  return new RBNode(node._color, node.key, node.value, node.left, node.right, node._count)\n}\n\nfunction repaint(color, node) {\n  return new RBNode(color, node.key, node.value, node.left, node.right, node._count)\n}\n\nfunction recount(node) {\n  node._count = 1 + (node.left ? node.left._count : 0) + (node.right ? node.right._count : 0)\n}\n\nfunction RedBlackTree(compare, root) {\n  this._compare = compare\n  this.root = root\n}\n\nvar proto = RedBlackTree.prototype\n\nObject.defineProperty(proto, \"keys\", {\n  get: function() {\n    var result = []\n    this.forEach(function(k,v) {\n      result.push(k)\n    })\n    return result\n  }\n})\n\nObject.defineProperty(proto, \"values\", {\n  get: function() {\n    var result = []\n    this.forEach(function(k,v) {\n      result.push(v)\n    })\n    return result\n  }\n})\n\n//Returns the number of nodes in the tree\nObject.defineProperty(proto, \"length\", {\n  get: function() {\n    if(this.root) {\n      return this.root._count\n    }\n    return 0\n  }\n})\n\n//Insert a new item into the tree\nproto.insert = function(key, value) {\n  var cmp = this._compare\n  //Find point to insert new node at\n  var n = this.root\n  var n_stack = []\n  var d_stack = []\n  while(n) {\n    var d = cmp(key, n.key)\n    n_stack.push(n)\n    d_stack.push(d)\n    if(d <= 0) {\n      n = n.left\n    } else {\n      n = n.right\n    }\n  }\n  //Rebuild path to leaf node\n  n_stack.push(new RBNode(RED, key, value, null, null, 1))\n  for(var s=n_stack.length-2; s>=0; --s) {\n    var n = n_stack[s]\n    if(d_stack[s] <= 0) {\n      n_stack[s] = new RBNode(n._color, n.key, n.value, n_stack[s+1], n.right, n._count+1)\n    } else {\n      n_stack[s] = new RBNode(n._color, n.key, n.value, n.left, n_stack[s+1], n._count+1)\n    }\n  }\n  //Rebalance tree using rotations\n  //console.log(\"start insert\", key, d_stack)\n  for(var s=n_stack.length-1; s>1; --s) {\n    var p = n_stack[s-1]\n    var n = n_stack[s]\n    if(p._color === BLACK || n._color === BLACK) {\n      break\n    }\n    var pp = n_stack[s-2]\n    if(pp.left === p) {\n      if(p.left === n) {\n        var y = pp.right\n        if(y && y._color === RED) {\n          //console.log(\"LLr\")\n          p._color = BLACK\n          pp.right = repaint(BLACK, y)\n          pp._color = RED\n          s -= 1\n        } else {\n          //console.log(\"LLb\")\n          pp._color = RED\n          pp.left = p.right\n          p._color = BLACK\n          p.right = pp\n          n_stack[s-2] = p\n          n_stack[s-1] = n\n          recount(pp)\n          recount(p)\n          if(s >= 3) {\n            var ppp = n_stack[s-3]\n            if(ppp.left === pp) {\n              ppp.left = p\n            } else {\n              ppp.right = p\n            }\n          }\n          break\n        }\n      } else {\n        var y = pp.right\n        if(y && y._color === RED) {\n          //console.log(\"LRr\")\n          p._color = BLACK\n          pp.right = repaint(BLACK, y)\n          pp._color = RED\n          s -= 1\n        } else {\n          //console.log(\"LRb\")\n          p.right = n.left\n          pp._color = RED\n          pp.left = n.right\n          n._color = BLACK\n          n.left = p\n          n.right = pp\n          n_stack[s-2] = n\n          n_stack[s-1] = p\n          recount(pp)\n          recount(p)\n          recount(n)\n          if(s >= 3) {\n            var ppp = n_stack[s-3]\n            if(ppp.left === pp) {\n              ppp.left = n\n            } else {\n              ppp.right = n\n            }\n          }\n          break\n        }\n      }\n    } else {\n      if(p.right === n) {\n        var y = pp.left\n        if(y && y._color === RED) {\n          //console.log(\"RRr\", y.key)\n          p._color = BLACK\n          pp.left = repaint(BLACK, y)\n          pp._color = RED\n          s -= 1\n        } else {\n          //console.log(\"RRb\")\n          pp._color = RED\n          pp.right = p.left\n          p._color = BLACK\n          p.left = pp\n          n_stack[s-2] = p\n          n_stack[s-1] = n\n          recount(pp)\n          recount(p)\n          if(s >= 3) {\n            var ppp = n_stack[s-3]\n            if(ppp.right === pp) {\n              ppp.right = p\n            } else {\n              ppp.left = p\n            }\n          }\n          break\n        }\n      } else {\n        var y = pp.left\n        if(y && y._color === RED) {\n          //console.log(\"RLr\")\n          p._color = BLACK\n          pp.left = repaint(BLACK, y)\n          pp._color = RED\n          s -= 1\n        } else {\n          //console.log(\"RLb\")\n          p.left = n.right\n          pp._color = RED\n          pp.right = n.left\n          n._color = BLACK\n          n.right = p\n          n.left = pp\n          n_stack[s-2] = n\n          n_stack[s-1] = p\n          recount(pp)\n          recount(p)\n          recount(n)\n          if(s >= 3) {\n            var ppp = n_stack[s-3]\n            if(ppp.right === pp) {\n              ppp.right = n\n            } else {\n              ppp.left = n\n            }\n          }\n          break\n        }\n      }\n    }\n  }\n  //Return new tree\n  n_stack[0]._color = BLACK\n  return new RedBlackTree(cmp, n_stack[0])\n}\n\n\n//Visit all nodes inorder\nfunction doVisitFull(visit, node) {\n  if(node.left) {\n    var v = doVisitFull(visit, node.left)\n    if(v) { return v }\n  }\n  var v = visit(node.key, node.value)\n  if(v) { return v }\n  if(node.right) {\n    return doVisitFull(visit, node.right)\n  }\n}\n\n//Visit half nodes in order\nfunction doVisitHalf(lo, compare, visit, node) {\n  var l = compare(lo, node.key)\n  if(l <= 0) {\n    if(node.left) {\n      var v = doVisitHalf(lo, compare, visit, node.left)\n      if(v) { return v }\n    }\n    var v = visit(node.key, node.value)\n    if(v) { return v }\n  }\n  if(node.right) {\n    return doVisitHalf(lo, compare, visit, node.right)\n  }\n}\n\n//Visit all nodes within a range\nfunction doVisit(lo, hi, compare, visit, node) {\n  var l = compare(lo, node.key)\n  var h = compare(hi, node.key)\n  var v\n  if(l <= 0) {\n    if(node.left) {\n      v = doVisit(lo, hi, compare, visit, node.left)\n      if(v) { return v }\n    }\n    if(h > 0) {\n      v = visit(node.key, node.value)\n      if(v) { return v }\n    }\n  }\n  if(h > 0 && node.right) {\n    return doVisit(lo, hi, compare, visit, node.right)\n  }\n}\n\n\nproto.forEach = function rbTreeForEach(visit, lo, hi) {\n  if(!this.root) {\n    return\n  }\n  switch(arguments.length) {\n    case 1:\n      return doVisitFull(visit, this.root)\n    break\n\n    case 2:\n      return doVisitHalf(lo, this._compare, visit, this.root)\n    break\n\n    case 3:\n      if(this._compare(lo, hi) >= 0) {\n        return\n      }\n      return doVisit(lo, hi, this._compare, visit, this.root)\n    break\n  }\n}\n\n//First item in list\nObject.defineProperty(proto, \"begin\", {\n  get: function() {\n    var stack = []\n    var n = this.root\n    while(n) {\n      stack.push(n)\n      n = n.left\n    }\n    return new RedBlackTreeIterator(this, stack)\n  }\n})\n\n//Last item in list\nObject.defineProperty(proto, \"end\", {\n  get: function() {\n    var stack = []\n    var n = this.root\n    while(n) {\n      stack.push(n)\n      n = n.right\n    }\n    return new RedBlackTreeIterator(this, stack)\n  }\n})\n\n//Find the ith item in the tree\nproto.at = function(idx) {\n  if(idx < 0) {\n    return new RedBlackTreeIterator(this, [])\n  }\n  var n = this.root\n  var stack = []\n  while(true) {\n    stack.push(n)\n    if(n.left) {\n      if(idx < n.left._count) {\n        n = n.left\n        continue\n      }\n      idx -= n.left._count\n    }\n    if(!idx) {\n      return new RedBlackTreeIterator(this, stack)\n    }\n    idx -= 1\n    if(n.right) {\n      if(idx >= n.right._count) {\n        break\n      }\n      n = n.right\n    } else {\n      break\n    }\n  }\n  return new RedBlackTreeIterator(this, [])\n}\n\nproto.ge = function(key) {\n  var cmp = this._compare\n  var n = this.root\n  var stack = []\n  var last_ptr = 0\n  while(n) {\n    var d = cmp(key, n.key)\n    stack.push(n)\n    if(d <= 0) {\n      last_ptr = stack.length\n    }\n    if(d <= 0) {\n      n = n.left\n    } else {\n      n = n.right\n    }\n  }\n  stack.length = last_ptr\n  return new RedBlackTreeIterator(this, stack)\n}\n\nproto.gt = function(key) {\n  var cmp = this._compare\n  var n = this.root\n  var stack = []\n  var last_ptr = 0\n  while(n) {\n    var d = cmp(key, n.key)\n    stack.push(n)\n    if(d < 0) {\n      last_ptr = stack.length\n    }\n    if(d < 0) {\n      n = n.left\n    } else {\n      n = n.right\n    }\n  }\n  stack.length = last_ptr\n  return new RedBlackTreeIterator(this, stack)\n}\n\nproto.lt = function(key) {\n  var cmp = this._compare\n  var n = this.root\n  var stack = []\n  var last_ptr = 0\n  while(n) {\n    var d = cmp(key, n.key)\n    stack.push(n)\n    if(d > 0) {\n      last_ptr = stack.length\n    }\n    if(d <= 0) {\n      n = n.left\n    } else {\n      n = n.right\n    }\n  }\n  stack.length = last_ptr\n  return new RedBlackTreeIterator(this, stack)\n}\n\nproto.le = function(key) {\n  var cmp = this._compare\n  var n = this.root\n  var stack = []\n  var last_ptr = 0\n  while(n) {\n    var d = cmp(key, n.key)\n    stack.push(n)\n    if(d >= 0) {\n      last_ptr = stack.length\n    }\n    if(d < 0) {\n      n = n.left\n    } else {\n      n = n.right\n    }\n  }\n  stack.length = last_ptr\n  return new RedBlackTreeIterator(this, stack)\n}\n\n//Finds the item with key if it exists\nproto.find = function(key) {\n  var cmp = this._compare\n  var n = this.root\n  var stack = []\n  while(n) {\n    var d = cmp(key, n.key)\n    stack.push(n)\n    if(d === 0) {\n      return new RedBlackTreeIterator(this, stack)\n    }\n    if(d <= 0) {\n      n = n.left\n    } else {\n      n = n.right\n    }\n  }\n  return new RedBlackTreeIterator(this, [])\n}\n\n//Removes item with key from tree\nproto.remove = function(key) {\n  var iter = this.find(key)\n  if(iter) {\n    return iter.remove()\n  }\n  return this\n}\n\n//Returns the item at `key`\nproto.get = function(key) {\n  var cmp = this._compare\n  var n = this.root\n  while(n) {\n    var d = cmp(key, n.key)\n    if(d === 0) {\n      return n.value\n    }\n    if(d <= 0) {\n      n = n.left\n    } else {\n      n = n.right\n    }\n  }\n  return\n}\n\n//Iterator for red black tree\nfunction RedBlackTreeIterator(tree, stack) {\n  this.tree = tree\n  this._stack = stack\n}\n\nvar iproto = RedBlackTreeIterator.prototype\n\n//Test if iterator is valid\nObject.defineProperty(iproto, \"valid\", {\n  get: function() {\n    return this._stack.length > 0\n  }\n})\n\n//Node of the iterator\nObject.defineProperty(iproto, \"node\", {\n  get: function() {\n    if(this._stack.length > 0) {\n      return this._stack[this._stack.length-1]\n    }\n    return null\n  },\n  enumerable: true\n})\n\n//Makes a copy of an iterator\niproto.clone = function() {\n  return new RedBlackTreeIterator(this.tree, this._stack.slice())\n}\n\n//Swaps two nodes\nfunction swapNode(n, v) {\n  n.key = v.key\n  n.value = v.value\n  n.left = v.left\n  n.right = v.right\n  n._color = v._color\n  n._count = v._count\n}\n\n//Fix up a double black node in a tree\nfunction fixDoubleBlack(stack) {\n  var n, p, s, z\n  for(var i=stack.length-1; i>=0; --i) {\n    n = stack[i]\n    if(i === 0) {\n      n._color = BLACK\n      return\n    }\n    //console.log(\"visit node:\", n.key, i, stack[i].key, stack[i-1].key)\n    p = stack[i-1]\n    if(p.left === n) {\n      //console.log(\"left child\")\n      s = p.right\n      if(s.right && s.right._color === RED) {\n        //console.log(\"case 1: right sibling child red\")\n        s = p.right = cloneNode(s)\n        z = s.right = cloneNode(s.right)\n        p.right = s.left\n        s.left = p\n        s.right = z\n        s._color = p._color\n        n._color = BLACK\n        p._color = BLACK\n        z._color = BLACK\n        recount(p)\n        recount(s)\n        if(i > 1) {\n          var pp = stack[i-2]\n          if(pp.left === p) {\n            pp.left = s\n          } else {\n            pp.right = s\n          }\n        }\n        stack[i-1] = s\n        return\n      } else if(s.left && s.left._color === RED) {\n        //console.log(\"case 1: left sibling child red\")\n        s = p.right = cloneNode(s)\n        z = s.left = cloneNode(s.left)\n        p.right = z.left\n        s.left = z.right\n        z.left = p\n        z.right = s\n        z._color = p._color\n        p._color = BLACK\n        s._color = BLACK\n        n._color = BLACK\n        recount(p)\n        recount(s)\n        recount(z)\n        if(i > 1) {\n          var pp = stack[i-2]\n          if(pp.left === p) {\n            pp.left = z\n          } else {\n            pp.right = z\n          }\n        }\n        stack[i-1] = z\n        return\n      }\n      if(s._color === BLACK) {\n        if(p._color === RED) {\n          //console.log(\"case 2: black sibling, red parent\", p.right.value)\n          p._color = BLACK\n          p.right = repaint(RED, s)\n          return\n        } else {\n          //console.log(\"case 2: black sibling, black parent\", p.right.value)\n          p.right = repaint(RED, s)\n          continue  \n        }\n      } else {\n        //console.log(\"case 3: red sibling\")\n        s = cloneNode(s)\n        p.right = s.left\n        s.left = p\n        s._color = p._color\n        p._color = RED\n        recount(p)\n        recount(s)\n        if(i > 1) {\n          var pp = stack[i-2]\n          if(pp.left === p) {\n            pp.left = s\n          } else {\n            pp.right = s\n          }\n        }\n        stack[i-1] = s\n        stack[i] = p\n        if(i+1 < stack.length) {\n          stack[i+1] = n\n        } else {\n          stack.push(n)\n        }\n        i = i+2\n      }\n    } else {\n      //console.log(\"right child\")\n      s = p.left\n      if(s.left && s.left._color === RED) {\n        //console.log(\"case 1: left sibling child red\", p.value, p._color)\n        s = p.left = cloneNode(s)\n        z = s.left = cloneNode(s.left)\n        p.left = s.right\n        s.right = p\n        s.left = z\n        s._color = p._color\n        n._color = BLACK\n        p._color = BLACK\n        z._color = BLACK\n        recount(p)\n        recount(s)\n        if(i > 1) {\n          var pp = stack[i-2]\n          if(pp.right === p) {\n            pp.right = s\n          } else {\n            pp.left = s\n          }\n        }\n        stack[i-1] = s\n        return\n      } else if(s.right && s.right._color === RED) {\n        //console.log(\"case 1: right sibling child red\")\n        s = p.left = cloneNode(s)\n        z = s.right = cloneNode(s.right)\n        p.left = z.right\n        s.right = z.left\n        z.right = p\n        z.left = s\n        z._color = p._color\n        p._color = BLACK\n        s._color = BLACK\n        n._color = BLACK\n        recount(p)\n        recount(s)\n        recount(z)\n        if(i > 1) {\n          var pp = stack[i-2]\n          if(pp.right === p) {\n            pp.right = z\n          } else {\n            pp.left = z\n          }\n        }\n        stack[i-1] = z\n        return\n      }\n      if(s._color === BLACK) {\n        if(p._color === RED) {\n          //console.log(\"case 2: black sibling, red parent\")\n          p._color = BLACK\n          p.left = repaint(RED, s)\n          return\n        } else {\n          //console.log(\"case 2: black sibling, black parent\")\n          p.left = repaint(RED, s)\n          continue  \n        }\n      } else {\n        //console.log(\"case 3: red sibling\")\n        s = cloneNode(s)\n        p.left = s.right\n        s.right = p\n        s._color = p._color\n        p._color = RED\n        recount(p)\n        recount(s)\n        if(i > 1) {\n          var pp = stack[i-2]\n          if(pp.right === p) {\n            pp.right = s\n          } else {\n            pp.left = s\n          }\n        }\n        stack[i-1] = s\n        stack[i] = p\n        if(i+1 < stack.length) {\n          stack[i+1] = n\n        } else {\n          stack.push(n)\n        }\n        i = i+2\n      }\n    }\n  }\n}\n\n//Removes item at iterator from tree\niproto.remove = function() {\n  var stack = this._stack\n  if(stack.length === 0) {\n    return this.tree\n  }\n  //First copy path to node\n  var cstack = new Array(stack.length)\n  var n = stack[stack.length-1]\n  cstack[cstack.length-1] = new RBNode(n._color, n.key, n.value, n.left, n.right, n._count)\n  for(var i=stack.length-2; i>=0; --i) {\n    var n = stack[i]\n    if(n.left === stack[i+1]) {\n      cstack[i] = new RBNode(n._color, n.key, n.value, cstack[i+1], n.right, n._count)\n    } else {\n      cstack[i] = new RBNode(n._color, n.key, n.value, n.left, cstack[i+1], n._count)\n    }\n  }\n\n  //Get node\n  n = cstack[cstack.length-1]\n  //console.log(\"start remove: \", n.value)\n\n  //If not leaf, then swap with previous node\n  if(n.left && n.right) {\n    //console.log(\"moving to leaf\")\n\n    //First walk to previous leaf\n    var split = cstack.length\n    n = n.left\n    while(n.right) {\n      cstack.push(n)\n      n = n.right\n    }\n    //Copy path to leaf\n    var v = cstack[split-1]\n    cstack.push(new RBNode(n._color, v.key, v.value, n.left, n.right, n._count))\n    cstack[split-1].key = n.key\n    cstack[split-1].value = n.value\n\n    //Fix up stack\n    for(var i=cstack.length-2; i>=split; --i) {\n      n = cstack[i]\n      cstack[i] = new RBNode(n._color, n.key, n.value, n.left, cstack[i+1], n._count)\n    }\n    cstack[split-1].left = cstack[split]\n  }\n  //console.log(\"stack=\", cstack.map(function(v) { return v.value }))\n\n  //Remove leaf node\n  n = cstack[cstack.length-1]\n  if(n._color === RED) {\n    //Easy case: removing red leaf\n    //console.log(\"RED leaf\")\n    var p = cstack[cstack.length-2]\n    if(p.left === n) {\n      p.left = null\n    } else if(p.right === n) {\n      p.right = null\n    }\n    cstack.pop()\n    for(var i=0; i<cstack.length; ++i) {\n      cstack[i]._count--\n    }\n    return new RedBlackTree(this.tree._compare, cstack[0])\n  } else {\n    if(n.left || n.right) {\n      //Second easy case:  Single child black parent\n      //console.log(\"BLACK single child\")\n      if(n.left) {\n        swapNode(n, n.left)\n      } else if(n.right) {\n        swapNode(n, n.right)\n      }\n      //Child must be red, so repaint it black to balance color\n      n._color = BLACK\n      for(var i=0; i<cstack.length-1; ++i) {\n        cstack[i]._count--\n      }\n      return new RedBlackTree(this.tree._compare, cstack[0])\n    } else if(cstack.length === 1) {\n      //Third easy case: root\n      //console.log(\"ROOT\")\n      return new RedBlackTree(this.tree._compare, null)\n    } else {\n      //Hard case: Repaint n, and then do some nasty stuff\n      //console.log(\"BLACK leaf no children\")\n      for(var i=0; i<cstack.length; ++i) {\n        cstack[i]._count--\n      }\n      var parent = cstack[cstack.length-2]\n      fixDoubleBlack(cstack)\n      //Fix up links\n      if(parent.left === n) {\n        parent.left = null\n      } else {\n        parent.right = null\n      }\n    }\n  }\n  return new RedBlackTree(this.tree._compare, cstack[0])\n}\n\n//Returns key\nObject.defineProperty(iproto, \"key\", {\n  get: function() {\n    if(this._stack.length > 0) {\n      return this._stack[this._stack.length-1].key\n    }\n    return\n  },\n  enumerable: true\n})\n\n//Returns value\nObject.defineProperty(iproto, \"value\", {\n  get: function() {\n    if(this._stack.length > 0) {\n      return this._stack[this._stack.length-1].value\n    }\n    return\n  },\n  enumerable: true\n})\n\n\n//Returns the position of this iterator in the sorted list\nObject.defineProperty(iproto, \"index\", {\n  get: function() {\n    var idx = 0\n    var stack = this._stack\n    if(stack.length === 0) {\n      var r = this.tree.root\n      if(r) {\n        return r._count\n      }\n      return 0\n    } else if(stack[stack.length-1].left) {\n      idx = stack[stack.length-1].left._count\n    }\n    for(var s=stack.length-2; s>=0; --s) {\n      if(stack[s+1] === stack[s].right) {\n        ++idx\n        if(stack[s].left) {\n          idx += stack[s].left._count\n        }\n      }\n    }\n    return idx\n  },\n  enumerable: true\n})\n\n//Advances iterator to next element in list\niproto.next = function() {\n  var stack = this._stack\n  if(stack.length === 0) {\n    return\n  }\n  var n = stack[stack.length-1]\n  if(n.right) {\n    n = n.right\n    while(n) {\n      stack.push(n)\n      n = n.left\n    }\n  } else {\n    stack.pop()\n    while(stack.length > 0 && stack[stack.length-1].right === n) {\n      n = stack[stack.length-1]\n      stack.pop()\n    }\n  }\n}\n\n//Checks if iterator is at end of tree\nObject.defineProperty(iproto, \"hasNext\", {\n  get: function() {\n    var stack = this._stack\n    if(stack.length === 0) {\n      return false\n    }\n    if(stack[stack.length-1].right) {\n      return true\n    }\n    for(var s=stack.length-1; s>0; --s) {\n      if(stack[s-1].left === stack[s]) {\n        return true\n      }\n    }\n    return false\n  }\n})\n\n//Update value\niproto.update = function(value) {\n  var stack = this._stack\n  if(stack.length === 0) {\n    throw new Error(\"Can't update empty node!\")\n  }\n  var cstack = new Array(stack.length)\n  var n = stack[stack.length-1]\n  cstack[cstack.length-1] = new RBNode(n._color, n.key, value, n.left, n.right, n._count)\n  for(var i=stack.length-2; i>=0; --i) {\n    n = stack[i]\n    if(n.left === stack[i+1]) {\n      cstack[i] = new RBNode(n._color, n.key, n.value, cstack[i+1], n.right, n._count)\n    } else {\n      cstack[i] = new RBNode(n._color, n.key, n.value, n.left, cstack[i+1], n._count)\n    }\n  }\n  return new RedBlackTree(this.tree._compare, cstack[0])\n}\n\n//Moves iterator backward one element\niproto.prev = function() {\n  var stack = this._stack\n  if(stack.length === 0) {\n    return\n  }\n  var n = stack[stack.length-1]\n  if(n.left) {\n    n = n.left\n    while(n) {\n      stack.push(n)\n      n = n.right\n    }\n  } else {\n    stack.pop()\n    while(stack.length > 0 && stack[stack.length-1].left === n) {\n      n = stack[stack.length-1]\n      stack.pop()\n    }\n  }\n}\n\n//Checks if iterator is at start of tree\nObject.defineProperty(iproto, \"hasPrev\", {\n  get: function() {\n    var stack = this._stack\n    if(stack.length === 0) {\n      return false\n    }\n    if(stack[stack.length-1].left) {\n      return true\n    }\n    for(var s=stack.length-1; s>0; --s) {\n      if(stack[s-1].right === stack[s]) {\n        return true\n      }\n    }\n    return false\n  }\n})\n\n//Default comparison function\nfunction defaultCompare(a, b) {\n  if(a < b) {\n    return -1\n  }\n  if(a > b) {\n    return 1\n  }\n  return 0\n}\n\n//Build a tree\nfunction createRBTree(compare) {\n  return new RedBlackTree(compare || defaultCompare, null)\n}\n},{}],231:[function(_dereq_,module,exports){\n// transliterated from the python snippet here:\n// http://en.wikipedia.org/wiki/Lanczos_approximation\n\nvar g = 7;\nvar p = [\n    0.99999999999980993,\n    676.5203681218851,\n    -1259.1392167224028,\n    771.32342877765313,\n    -176.61502916214059,\n    12.507343278686905,\n    -0.13857109526572012,\n    9.9843695780195716e-6,\n    1.5056327351493116e-7\n];\n\nvar g_ln = 607/128;\nvar p_ln = [\n    0.99999999999999709182,\n    57.156235665862923517,\n    -59.597960355475491248,\n    14.136097974741747174,\n    -0.49191381609762019978,\n    0.33994649984811888699e-4,\n    0.46523628927048575665e-4,\n    -0.98374475304879564677e-4,\n    0.15808870322491248884e-3,\n    -0.21026444172410488319e-3,\n    0.21743961811521264320e-3,\n    -0.16431810653676389022e-3,\n    0.84418223983852743293e-4,\n    -0.26190838401581408670e-4,\n    0.36899182659531622704e-5\n];\n\n// Spouge approximation (suitable for large arguments)\nfunction lngamma(z) {\n\n    if(z < 0) return Number('0/0');\n    var x = p_ln[0];\n    for(var i = p_ln.length - 1; i > 0; --i) x += p_ln[i] / (z + i);\n    var t = z + g_ln + 0.5;\n    return .5*Math.log(2*Math.PI)+(z+.5)*Math.log(t)-t+Math.log(x)-Math.log(z);\n}\n\nmodule.exports = function gamma (z) {\n    if (z < 0.5) {\n        return Math.PI / (Math.sin(Math.PI * z) * gamma(1 - z));\n    }\n    else if(z > 100) return Math.exp(lngamma(z));\n    else {\n        z -= 1;\n        var x = p[0];\n        for (var i = 1; i < g + 2; i++) {\n            x += p[i] / (z + i);\n        }\n        var t = z + g + 0.5;\n\n        return Math.sqrt(2 * Math.PI)\n            * Math.pow(t, z + 0.5)\n            * Math.exp(-t)\n            * x\n        ;\n    }\n};\n\nmodule.exports.log = lngamma;\n\n},{}],232:[function(_dereq_,module,exports){\nmodule.exports = getCanvasContext\nfunction getCanvasContext (type, opts) {\n  if (typeof type !== 'string') {\n    throw new TypeError('must specify type string')\n  }\n\n  opts = opts || {}\n\n  if (typeof document === 'undefined' && !opts.canvas) {\n    return null // check for Node\n  }\n\n  var canvas = opts.canvas || document.createElement('canvas')\n  if (typeof opts.width === 'number') {\n    canvas.width = opts.width\n  }\n  if (typeof opts.height === 'number') {\n    canvas.height = opts.height\n  }\n\n  var attribs = opts\n  var gl\n  try {\n    var names = [ type ]\n    // prefix GL contexts\n    if (type.indexOf('webgl') === 0) {\n      names.push('experimental-' + type)\n    }\n\n    for (var i = 0; i < names.length; i++) {\n      gl = canvas.getContext(names[i], attribs)\n      if (gl) return gl\n    }\n  } catch (e) {\n    gl = null\n  }\n  return (gl || null) // ensure null on fail\n}\n\n},{}],233:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createAxes\n\nvar createText        = _dereq_('./lib/text.js')\nvar createLines       = _dereq_('./lib/lines.js')\nvar createBackground  = _dereq_('./lib/background.js')\nvar getCubeProperties = _dereq_('./lib/cube.js')\nvar Ticks             = _dereq_('./lib/ticks.js')\n\nvar identity = new Float32Array([\n  1, 0, 0, 0,\n  0, 1, 0, 0,\n  0, 0, 1, 0,\n  0, 0, 0, 1])\n\nfunction copyVec3(a, b) {\n  a[0] = b[0]\n  a[1] = b[1]\n  a[2] = b[2]\n  return a\n}\n\nfunction Axes(gl) {\n  this.gl             = gl\n\n  this.pixelRatio     = 1\n\n  this.bounds         = [ [-10, -10, -10],\n                          [ 10,  10,  10] ]\n  this.ticks          = [ [], [], [] ]\n  this.autoTicks      = true\n  this.tickSpacing    = [ 1, 1, 1 ]\n\n  this.tickEnable     = [ true, true, true ]\n  this.tickFont       = [ 'sans-serif', 'sans-serif', 'sans-serif' ]\n  this.tickSize       = [ 12, 12, 12 ]\n  this.tickAngle      = [ 0, 0, 0 ]\n  this.tickAlign      = [ 'auto', 'auto', 'auto' ]\n  this.tickColor      = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]\n  this.tickPad        = [ 10, 10, 10 ]\n\n  this.lastCubeProps  = {\n    cubeEdges: [0,0,0],\n    axis:      [0,0,0]\n  }\n\n  this.labels         = [ 'x', 'y', 'z' ]\n  this.labelEnable    = [ true, true, true ]\n  this.labelFont      = 'sans-serif'\n  this.labelSize      = [ 20, 20, 20 ]\n  this.labelAngle     = [ 0, 0, 0 ]\n  this.labelAlign     = [ 'auto', 'auto', 'auto' ]\n  this.labelColor     = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]\n  this.labelPad       = [ 10, 10, 10 ]\n\n  this.lineEnable     = [ true, true, true ]\n  this.lineMirror     = [ false, false, false ]\n  this.lineWidth      = [ 1, 1, 1 ]\n  this.lineColor      = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]\n\n  this.lineTickEnable = [ true, true, true ]\n  this.lineTickMirror = [ false, false, false ]\n  this.lineTickLength = [ 0, 0, 0 ]\n  this.lineTickWidth  = [ 1, 1, 1 ]\n  this.lineTickColor  = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]\n\n  this.gridEnable     = [ true, true, true ]\n  this.gridWidth      = [ 1, 1, 1 ]\n  this.gridColor      = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]\n\n  this.zeroEnable     = [ true, true, true ]\n  this.zeroLineColor  = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ]\n  this.zeroLineWidth  = [ 2, 2, 2 ]\n\n  this.backgroundEnable = [ false, false, false ]\n  this.backgroundColor  = [ [0.8, 0.8, 0.8, 0.5],\n                            [0.8, 0.8, 0.8, 0.5],\n                            [0.8, 0.8, 0.8, 0.5] ]\n\n  this._firstInit = true\n  this._text  = null\n  this._lines = null\n  this._background = createBackground(gl)\n}\n\nvar proto = Axes.prototype\n\nproto.update = function(options) {\n  options = options || {}\n\n  //Option parsing helper functions\n  function parseOption(nest, cons, name) {\n    if(name in options) {\n      var opt = options[name]\n      var prev = this[name]\n      var next\n      if(nest ? (Array.isArray(opt) && Array.isArray(opt[0])) :\n                 Array.isArray(opt) ) {\n        this[name] = next = [ cons(opt[0]), cons(opt[1]), cons(opt[2]) ]\n      } else {\n        this[name] = next = [ cons(opt), cons(opt), cons(opt) ]\n      }\n      for(var i=0; i<3; ++i) {\n        if(next[i] !== prev[i]) {\n          return true\n        }\n      }\n    }\n    return false\n  }\n\n  var NUMBER  = parseOption.bind(this, false, Number)\n  var BOOLEAN = parseOption.bind(this, false, Boolean)\n  var STRING  = parseOption.bind(this, false, String)\n  var COLOR   = parseOption.bind(this, true, function(v) {\n    if(Array.isArray(v)) {\n      if(v.length === 3) {\n        return [ +v[0], +v[1], +v[2], 1.0 ]\n      } else if(v.length === 4) {\n        return [ +v[0], +v[1], +v[2], +v[3] ]\n      }\n    }\n    return [ 0, 0, 0, 1 ]\n  })\n\n  //Tick marks and bounds\n  var nextTicks\n  var ticksUpdate   = false\n  var boundsChanged = false\n  if('bounds' in options) {\n    var bounds = options.bounds\ni_loop:\n    for(var i=0; i<2; ++i) {\n      for(var j=0; j<3; ++j) {\n        if(bounds[i][j] !== this.bounds[i][j]) {\n          boundsChanged = true\n        }\n        this.bounds[i][j] = bounds[i][j]\n      }\n    }\n  }\n  if('ticks' in options) {\n    nextTicks      = options.ticks\n    ticksUpdate    = true\n    this.autoTicks = false\n    for(var i=0; i<3; ++i) {\n      this.tickSpacing[i] = 0.0\n    }\n  } else if(NUMBER('tickSpacing')) {\n    this.autoTicks  = true\n    boundsChanged   = true\n  }\n\n  if(this._firstInit) {\n    if(!('ticks' in options || 'tickSpacing' in options)) {\n      this.autoTicks = true\n    }\n\n    //Force tick recomputation on first update\n    boundsChanged   = true\n    ticksUpdate     = true\n    this._firstInit = false\n  }\n\n  if(boundsChanged && this.autoTicks) {\n    nextTicks = Ticks.create(this.bounds, this.tickSpacing)\n    ticksUpdate = true\n  }\n\n  //Compare next ticks to previous ticks, only update if needed\n  if(ticksUpdate) {\n    for(var i=0; i<3; ++i) {\n      nextTicks[i].sort(function(a,b) {\n        return a.x-b.x\n      })\n    }\n    if(Ticks.equal(nextTicks, this.ticks)) {\n      ticksUpdate = false\n    } else {\n      this.ticks = nextTicks\n    }\n  }\n\n  //Parse tick properties\n  BOOLEAN('tickEnable')\n  if(STRING('tickFont')) {\n    ticksUpdate = true  //If font changes, must rebuild vbo\n  }\n  NUMBER('tickSize')\n  NUMBER('tickAngle')\n  NUMBER('tickPad')\n  COLOR('tickColor')\n\n  //Axis labels\n  var labelUpdate = STRING('labels')\n  if(STRING('labelFont')) {\n    labelUpdate = true\n  }\n  BOOLEAN('labelEnable')\n  NUMBER('labelSize')\n  NUMBER('labelPad')\n  COLOR('labelColor')\n\n  //Axis lines\n  BOOLEAN('lineEnable')\n  BOOLEAN('lineMirror')\n  NUMBER('lineWidth')\n  COLOR('lineColor')\n\n  //Axis line ticks\n  BOOLEAN('lineTickEnable')\n  BOOLEAN('lineTickMirror')\n  NUMBER('lineTickLength')\n  NUMBER('lineTickWidth')\n  COLOR('lineTickColor')\n\n  //Grid lines\n  BOOLEAN('gridEnable')\n  NUMBER('gridWidth')\n  COLOR('gridColor')\n\n  //Zero line\n  BOOLEAN('zeroEnable')\n  COLOR('zeroLineColor')\n  NUMBER('zeroLineWidth')\n\n  //Background\n  BOOLEAN('backgroundEnable')\n  COLOR('backgroundColor')\n\n  //Update text if necessary\n  if(!this._text) {\n    this._text = createText(\n      this.gl,\n      this.bounds,\n      this.labels,\n      this.labelFont,\n      this.ticks,\n      this.tickFont)\n  } else if(this._text && (labelUpdate || ticksUpdate)) {\n    this._text.update(\n      this.bounds,\n      this.labels,\n      this.labelFont,\n      this.ticks,\n      this.tickFont)\n  }\n\n  //Update lines if necessary\n  if(this._lines && ticksUpdate) {\n    this._lines.dispose()\n    this._lines = null\n  }\n  if(!this._lines) {\n    this._lines = createLines(this.gl, this.bounds, this.ticks)\n  }\n}\n\nfunction OffsetInfo() {\n  this.primalOffset = [0,0,0]\n  this.primalMinor  = [0,0,0]\n  this.mirrorOffset = [0,0,0]\n  this.mirrorMinor  = [0,0,0]\n}\n\nvar LINE_OFFSET = [ new OffsetInfo(), new OffsetInfo(), new OffsetInfo() ]\n\nfunction computeLineOffset(result, i, bounds, cubeEdges, cubeAxis) {\n  var primalOffset = result.primalOffset\n  var primalMinor  = result.primalMinor\n  var dualOffset   = result.mirrorOffset\n  var dualMinor    = result.mirrorMinor\n  var e = cubeEdges[i]\n\n  //Calculate offsets\n  for(var j=0; j<3; ++j) {\n    if(i === j) {\n      continue\n    }\n    var a = primalOffset,\n        b = dualOffset,\n        c = primalMinor,\n        d = dualMinor\n    if(e & (1<<j)) {\n      a = dualOffset\n      b = primalOffset\n      c = dualMinor\n      d = primalMinor\n    }\n    a[j] = bounds[0][j]\n    b[j] = bounds[1][j]\n    if(cubeAxis[j] > 0) {\n      c[j] = -1\n      d[j] = 0\n    } else {\n      c[j] = 0\n      d[j] = +1\n    }\n  }\n}\n\nvar CUBE_ENABLE = [0,0,0]\nvar DEFAULT_PARAMS = {\n  model:      identity,\n  view:       identity,\n  projection: identity,\n  _ortho:      false\n}\n\nproto.isOpaque = function() {\n  return true\n}\n\nproto.isTransparent = function() {\n  return false\n}\n\nproto.drawTransparent = function(params) {}\n\nvar ALIGN_OPTION_AUTO = 0 // i.e. as defined in the shader the text would rotate to stay upwards range: [-90,90]\n\nvar PRIMAL_MINOR  = [0,0,0]\nvar MIRROR_MINOR  = [0,0,0]\nvar PRIMAL_OFFSET = [0,0,0]\n\nproto.draw = function(params) {\n  params = params || DEFAULT_PARAMS\n\n  var gl = this.gl\n\n  //Geometry for camera and axes\n  var model       = params.model || identity\n  var view        = params.view || identity\n  var projection  = params.projection || identity\n  var bounds      = this.bounds\n  var isOrtho     = params._ortho || false\n\n  //Unpack axis info\n  var cubeParams  = getCubeProperties(model, view, projection, bounds, isOrtho)\n  var cubeEdges   = cubeParams.cubeEdges\n  var cubeAxis    = cubeParams.axis\n\n  var cx = view[12]\n  var cy = view[13]\n  var cz = view[14]\n  var cw = view[15]\n\n  var orthoFix = (isOrtho) ? 2 : 1 // double up padding for orthographic ticks & labels\n  var pixelScaleF = orthoFix * this.pixelRatio * (projection[3]*cx + projection[7]*cy + projection[11]*cz + projection[15]*cw) / gl.drawingBufferHeight\n\n  for(var i=0; i<3; ++i) {\n    this.lastCubeProps.cubeEdges[i] = cubeEdges[i]\n    this.lastCubeProps.axis[i] = cubeAxis[i]\n  }\n\n  //Compute axis info\n  var lineOffset  = LINE_OFFSET\n  for(var i=0; i<3; ++i) {\n    computeLineOffset(\n      LINE_OFFSET[i],\n      i,\n      this.bounds,\n      cubeEdges,\n      cubeAxis)\n  }\n\n  //Set up state parameters\n  var gl = this.gl\n\n  //Draw background first\n  var cubeEnable = CUBE_ENABLE\n  for(var i=0; i<3; ++i) {\n    if(this.backgroundEnable[i]) {\n      cubeEnable[i] = cubeAxis[i]\n    } else {\n      cubeEnable[i] = 0\n    }\n  }\n\n  this._background.draw(\n    model,\n    view,\n    projection,\n    bounds,\n    cubeEnable,\n    this.backgroundColor)\n\n  //Draw lines\n  this._lines.bind(\n    model,\n    view,\n    projection,\n    this)\n\n  //First draw grid lines and zero lines\n  for(var i=0; i<3; ++i) {\n    var x = [0,0,0]\n    if(cubeAxis[i] > 0) {\n      x[i] = bounds[1][i]\n    } else {\n      x[i] = bounds[0][i]\n    }\n\n    //Draw grid lines\n    for(var j=0; j<2; ++j) {\n      var u = (i + 1 + j) % 3\n      var v = (i + 1 + (j^1)) % 3\n      if(this.gridEnable[u]) {\n        this._lines.drawGrid(u, v, this.bounds, x, this.gridColor[u], this.gridWidth[u]*this.pixelRatio)\n      }\n    }\n\n    //Draw zero lines (need to do this AFTER all grid lines are drawn)\n    for(var j=0; j<2; ++j) {\n      var u = (i + 1 + j) % 3\n      var v = (i + 1 + (j^1)) % 3\n      if(this.zeroEnable[v]) {\n        //Check if zero line in bounds\n        if(Math.min(bounds[0][v], bounds[1][v]) <= 0 && Math.max(bounds[0][v], bounds[1][v]) >= 0) {\n          this._lines.drawZero(u, v, this.bounds, x, this.zeroLineColor[v], this.zeroLineWidth[v]*this.pixelRatio)\n        }\n      }\n    }\n  }\n\n  //Then draw axis lines and tick marks\n  for(var i=0; i<3; ++i) {\n\n    //Draw axis lines\n    if(this.lineEnable[i]) {\n      this._lines.drawAxisLine(i, this.bounds, lineOffset[i].primalOffset, this.lineColor[i], this.lineWidth[i]*this.pixelRatio)\n    }\n    if(this.lineMirror[i]) {\n      this._lines.drawAxisLine(i, this.bounds, lineOffset[i].mirrorOffset, this.lineColor[i], this.lineWidth[i]*this.pixelRatio)\n    }\n\n    //Compute minor axes\n    var primalMinor = copyVec3(PRIMAL_MINOR, lineOffset[i].primalMinor)\n    var mirrorMinor = copyVec3(MIRROR_MINOR, lineOffset[i].mirrorMinor)\n    var tickLength  = this.lineTickLength\n    for(var j=0; j<3; ++j) {\n      var scaleFactor = pixelScaleF / model[5*j]\n      primalMinor[j] *= tickLength[j] * scaleFactor\n      mirrorMinor[j] *= tickLength[j] * scaleFactor\n    }\n\n\n\n    //Draw axis line ticks\n    if(this.lineTickEnable[i]) {\n      this._lines.drawAxisTicks(i, lineOffset[i].primalOffset, primalMinor, this.lineTickColor[i], this.lineTickWidth[i]*this.pixelRatio)\n    }\n    if(this.lineTickMirror[i]) {\n      this._lines.drawAxisTicks(i, lineOffset[i].mirrorOffset, mirrorMinor, this.lineTickColor[i], this.lineTickWidth[i]*this.pixelRatio)\n    }\n  }\n  this._lines.unbind()\n\n  //Draw text sprites\n  this._text.bind(\n    model,\n    view,\n    projection,\n    this.pixelRatio)\n\n  var alignOpt // options in shader are from this list {-1, 0, 1, 2, 3, ..., n}\n  // -1: backward compatible\n  //  0: raw data\n  //  1: auto align, free angles\n  //  2: auto align, horizontal or vertical\n  //3-n: auto align, round to n directions e.g. 12 -> round to angles with 30-degree steps\n\n  var hv_ratio = 0.5 // can have an effect on the ratio between horizontals and verticals when using option 2\n\n  var enableAlign\n  var alignDir\n\n  function alignTo(i) {\n    alignDir = [0,0,0]\n    alignDir[i] = 1\n  }\n\n  function solveTickAlignments(i, minor, major) {\n\n    var i1 = (i + 1) % 3\n    var i2 = (i + 2) % 3\n\n    var A = minor[i1]\n    var B = minor[i2]\n    var C = major[i1]\n    var D = major[i2]\n\n         if ((A > 0) && (D > 0)) { alignTo(i1); return; }\n    else if ((A > 0) && (D < 0)) { alignTo(i1); return; }\n    else if ((A < 0) && (D > 0)) { alignTo(i1); return; }\n    else if ((A < 0) && (D < 0)) { alignTo(i1); return; }\n    else if ((B > 0) && (C > 0)) { alignTo(i2); return; }\n    else if ((B > 0) && (C < 0)) { alignTo(i2); return; }\n    else if ((B < 0) && (C > 0)) { alignTo(i2); return; }\n    else if ((B < 0) && (C < 0)) { alignTo(i2); return; }\n  }\n\n  for(var i=0; i<3; ++i) {\n\n    var minor      = lineOffset[i].primalMinor\n    var major      = lineOffset[i].mirrorMinor\n\n    var offset     = copyVec3(PRIMAL_OFFSET, lineOffset[i].primalOffset)\n\n    for(var j=0; j<3; ++j) {\n      if(this.lineTickEnable[i]) {\n        offset[j] += pixelScaleF * minor[j] * Math.max(this.lineTickLength[j], 0)  / model[5*j]\n      }\n    }\n\n    var axis = [0,0,0]\n    axis[i] = 1\n\n    //Draw tick text\n    if(this.tickEnable[i]) {\n\n      if(this.tickAngle[i] === -3600) {\n        this.tickAngle[i] = 0\n        this.tickAlign[i] = 'auto'\n      } else {\n        this.tickAlign[i] = -1\n      }\n\n      enableAlign = 1;\n\n      alignOpt = [this.tickAlign[i], hv_ratio, enableAlign]\n      if(alignOpt[0] === 'auto') alignOpt[0] = ALIGN_OPTION_AUTO\n      else alignOpt[0] = parseInt('' + alignOpt[0])\n\n      alignDir = [0,0,0]\n      solveTickAlignments(i, minor, major)\n\n      //Add tick padding\n      for(var j=0; j<3; ++j) {\n        offset[j] += pixelScaleF * minor[j] * this.tickPad[j] / model[5*j]\n      }\n\n      //Draw axis\n      this._text.drawTicks(\n        i,\n        this.tickSize[i],\n        this.tickAngle[i],\n        offset,\n        this.tickColor[i],\n        axis,\n        alignDir,\n        alignOpt)\n    }\n\n    //Draw labels\n    if(this.labelEnable[i]) {\n\n      enableAlign = 0\n      alignDir = [0,0,0]\n      if(this.labels[i].length > 4) { // for large label axis enable alignDir to axis\n        alignTo(i)\n        enableAlign = 1\n      }\n\n      alignOpt = [this.labelAlign[i], hv_ratio, enableAlign]\n      if(alignOpt[0] === 'auto') alignOpt[0] = ALIGN_OPTION_AUTO\n      else alignOpt[0] = parseInt('' + alignOpt[0])\n\n      //Add label padding\n      for(var j=0; j<3; ++j) {\n        offset[j] += pixelScaleF * minor[j] * this.labelPad[j] / model[5*j]\n      }\n      offset[i] += 0.5 * (bounds[0][i] + bounds[1][i])\n\n      //Draw axis\n      this._text.drawLabel(\n        i,\n        this.labelSize[i],\n        this.labelAngle[i],\n        offset,\n        this.labelColor[i],\n        [0,0,0],\n        alignDir,\n        alignOpt)\n    }\n  }\n\n  this._text.unbind()\n}\n\nproto.dispose = function() {\n  this._text.dispose()\n  this._lines.dispose()\n  this._background.dispose()\n  this._lines = null\n  this._text = null\n  this._background = null\n  this.gl = null\n}\n\nfunction createAxes(gl, options) {\n  var axes = new Axes(gl)\n  axes.update(options)\n  return axes\n}\n\n},{\"./lib/background.js\":234,\"./lib/cube.js\":235,\"./lib/lines.js\":236,\"./lib/text.js\":238,\"./lib/ticks.js\":239}],234:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createBackgroundCube\n\nvar createBuffer = _dereq_('gl-buffer')\nvar createVAO    = _dereq_('gl-vao')\nvar createShader = _dereq_('./shaders').bg\n\nfunction BackgroundCube(gl, buffer, vao, shader) {\n  this.gl = gl\n  this.buffer = buffer\n  this.vao = vao\n  this.shader = shader\n}\n\nvar proto = BackgroundCube.prototype\n\nproto.draw = function(model, view, projection, bounds, enable, colors) {\n  var needsBG = false\n  for(var i=0; i<3; ++i) {\n    needsBG = needsBG || enable[i]\n  }\n  if(!needsBG) {\n    return\n  }\n\n  var gl = this.gl\n\n  gl.enable(gl.POLYGON_OFFSET_FILL)\n  gl.polygonOffset(1, 2)\n\n  this.shader.bind()\n  this.shader.uniforms = {\n    model: model,\n    view: view,\n    projection: projection,\n    bounds: bounds,\n    enable: enable,\n    colors: colors\n  }\n  this.vao.bind()\n  this.vao.draw(this.gl.TRIANGLES, 36)\n  this.vao.unbind()\n\n  gl.disable(gl.POLYGON_OFFSET_FILL)\n}\n\nproto.dispose = function() {\n  this.vao.dispose()\n  this.buffer.dispose()\n  this.shader.dispose()\n}\n\nfunction createBackgroundCube(gl) {\n  //Create cube vertices\n  var vertices = []\n  var indices  = []\n  var ptr = 0\n  for(var d=0; d<3; ++d) {\n    var u = (d+1) % 3\n    var v = (d+2) % 3\n    var x = [0,0,0]\n    var c = [0,0,0]\n    for(var s=-1; s<=1; s+=2) {\n      indices.push(ptr,   ptr+2, ptr+1,\n                   ptr+1, ptr+2, ptr+3)\n      x[d] = s\n      c[d] = s\n      for(var i=-1; i<=1; i+=2) {\n        x[u] = i\n        for(var j=-1; j<=1; j+=2) {\n          x[v] = j\n          vertices.push(x[0], x[1], x[2],\n                        c[0], c[1], c[2])\n          ptr += 1\n        }\n      }\n      //Swap u and v\n      var tt = u\n      u = v\n      v = tt\n    }\n  }\n\n  //Allocate buffer and vertex array\n  var buffer = createBuffer(gl, new Float32Array(vertices))\n  var elements = createBuffer(gl, new Uint16Array(indices), gl.ELEMENT_ARRAY_BUFFER)\n  var vao = createVAO(gl, [\n      {\n        buffer: buffer,\n        type: gl.FLOAT,\n        size: 3,\n        offset: 0,\n        stride: 24\n      },\n      {\n        buffer: buffer,\n        type: gl.FLOAT,\n        size: 3,\n        offset: 12,\n        stride: 24\n      }\n    ], elements)\n\n  //Create shader object\n  var shader = createShader(gl)\n  shader.attributes.position.location = 0\n  shader.attributes.normal.location = 1\n\n  return new BackgroundCube(gl, buffer, vao, shader)\n}\n\n},{\"./shaders\":237,\"gl-buffer\":241,\"gl-vao\":327}],235:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = getCubeEdges\n\nvar bits      = _dereq_('bit-twiddle')\nvar multiply  = _dereq_('gl-mat4/multiply')\nvar splitPoly = _dereq_('split-polygon')\nvar orient    = _dereq_('robust-orientation')\n\nvar mvp        = new Array(16)\nvar pCubeVerts = new Array(8)\nvar cubeVerts  = new Array(8)\nvar x          = new Array(3)\nvar zero3      = [0,0,0]\n\n;(function() {\n  for(var i=0; i<8; ++i) {\n    pCubeVerts[i] =[1,1,1,1]\n    cubeVerts[i] = [1,1,1]\n  }\n})()\n\n\nfunction transformHg(result, x, mat) {\n  for(var i=0; i<4; ++i) {\n    result[i] = mat[12+i]\n    for(var j=0; j<3; ++j) {\n      result[i] += x[j]*mat[4*j+i]\n    }\n  }\n}\n\nvar FRUSTUM_PLANES = [\n  [ 0, 0, 1, 0, 0],\n  [ 0, 0,-1, 1, 0],\n  [ 0,-1, 0, 1, 0],\n  [ 0, 1, 0, 1, 0],\n  [-1, 0, 0, 1, 0],\n  [ 1, 0, 0, 1, 0]\n]\n\nfunction polygonArea(p) {\n  for(var i=0; i<FRUSTUM_PLANES.length; ++i) {\n    p = splitPoly.positive(p, FRUSTUM_PLANES[i])\n    if(p.length < 3) {\n      return 0\n    }\n  }\n\n  var base = p[0]\n  var ax = base[0] / base[3]\n  var ay = base[1] / base[3]\n  var area = 0.0\n  for(var i=1; i+1<p.length; ++i) {\n    var b = p[i]\n    var c = p[i+1]\n\n    var bx = b[0]/b[3]\n    var by = b[1]/b[3]\n    var cx = c[0]/c[3]\n    var cy = c[1]/c[3]\n\n    var ux = bx - ax\n    var uy = by - ay\n\n    var vx = cx - ax\n    var vy = cy - ay\n\n    area += Math.abs(ux * vy - uy * vx)\n  }\n\n  return area\n}\n\nvar CUBE_EDGES = [1,1,1]\nvar CUBE_AXIS  = [0,0,0]\nvar CUBE_RESULT = {\n  cubeEdges: CUBE_EDGES,\n  axis: CUBE_AXIS\n}\n\nfunction getCubeEdges(model, view, projection, bounds, ortho) {\n\n  //Concatenate matrices\n  multiply(mvp, view, model)\n  multiply(mvp, projection, mvp)\n\n  //First project cube vertices\n  var ptr = 0\n  for(var i=0; i<2; ++i) {\n    x[2] = bounds[i][2]\n    for(var j=0; j<2; ++j) {\n      x[1] = bounds[j][1]\n      for(var k=0; k<2; ++k) {\n        x[0] = bounds[k][0]\n        transformHg(pCubeVerts[ptr], x, mvp)\n        ptr += 1\n      }\n    }\n  }\n\n  //Classify camera against cube faces\n  var closest = -1\n\n  for(var i=0; i<8; ++i) {\n    var w = pCubeVerts[i][3]\n    for(var l=0; l<3; ++l) {\n      cubeVerts[i][l] = pCubeVerts[i][l] / w\n    }\n\n    if(ortho) cubeVerts[i][2] *= -1;\n\n    if(w < 0) {\n      if(closest < 0) {\n        closest = i\n      } else if(cubeVerts[i][2] < cubeVerts[closest][2]) {\n        closest = i\n      }\n    }\n  }\n\n  if(closest < 0) {\n    closest = 0\n    for(var d=0; d<3; ++d) {\n      var u = (d+2) % 3\n      var v = (d+1) % 3\n      var o0 = -1\n      var o1 = -1\n      for(var s=0; s<2; ++s) {\n        var f0 = (s<<d)\n        var f1 = f0 + (s << u) + ((1-s) << v)\n        var f2 = f0 + ((1-s) << u) + (s << v)\n        if(orient(cubeVerts[f0], cubeVerts[f1], cubeVerts[f2], zero3) < 0) {\n          continue\n        }\n        if(s) {\n          o0 = 1\n        } else {\n          o1 = 1\n        }\n      }\n      if(o0 < 0 || o1 < 0) {\n        if(o1 > o0) {\n          closest |= 1<<d\n        }\n        continue\n      }\n      for(var s=0; s<2; ++s) {\n        var f0 = (s<<d)\n        var f1 = f0 + (s << u) + ((1-s) << v)\n        var f2 = f0 + ((1-s) << u) + (s << v)\n        var o = polygonArea([\n            pCubeVerts[f0],\n            pCubeVerts[f1],\n            pCubeVerts[f2],\n            pCubeVerts[f0+(1<<u)+(1<<v)]])\n        if(s) {\n          o0 = o\n        } else {\n          o1 = o\n        }\n      }\n      if(o1 > o0) {\n        closest |= 1<<d\n        continue\n      }\n    }\n  }\n\n  var farthest = 7^closest\n\n  //Find lowest vertex which is not closest closest\n  var bottom = -1\n  for(var i=0; i<8; ++i) {\n    if(i === closest || i === farthest) {\n      continue\n    }\n    if(bottom < 0) {\n      bottom = i\n    } else if(cubeVerts[bottom][1] > cubeVerts[i][1]) {\n      bottom = i\n    }\n  }\n\n  //Find left/right neighbors of bottom vertex\n  var left = -1\n  for(var i=0; i<3; ++i) {\n    var idx = bottom ^ (1<<i)\n    if(idx === closest || idx === farthest) {\n      continue\n    }\n    if(left < 0) {\n      left = idx\n    }\n    var v = cubeVerts[idx]\n    if(v[0] < cubeVerts[left][0]) {\n      left = idx\n    }\n  }\n  var right = -1\n  for(var i=0; i<3; ++i) {\n    var idx = bottom ^ (1<<i)\n    if(idx === closest || idx === farthest || idx === left) {\n      continue\n    }\n    if(right < 0) {\n      right = idx\n    }\n    var v = cubeVerts[idx]\n    if(v[0] > cubeVerts[right][0]) {\n      right = idx\n    }\n  }\n\n  //Determine edge axis coordinates\n  var cubeEdges = CUBE_EDGES\n  cubeEdges[0] = cubeEdges[1] = cubeEdges[2] = 0\n  cubeEdges[bits.log2(left^bottom)] = bottom&left\n  cubeEdges[bits.log2(bottom^right)] = bottom&right\n  var top = right ^ 7\n  if(top === closest || top === farthest) {\n    top = left ^ 7\n    cubeEdges[bits.log2(right^top)] = top&right\n  } else {\n    cubeEdges[bits.log2(left^top)] = top&left\n  }\n\n  //Determine visible faces\n  var axis = CUBE_AXIS\n  var cutCorner = closest\n  for(var d=0; d<3; ++d) {\n    if(cutCorner & (1<<d)) {\n      axis[d] = -1\n    } else {\n      axis[d] = 1\n    }\n  }\n\n  //Return result\n  return CUBE_RESULT\n}\n},{\"bit-twiddle\":92,\"gl-mat4/multiply\":267,\"robust-orientation\":510,\"split-polygon\":527}],236:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports    = createLines\n\nvar createBuffer  = _dereq_('gl-buffer')\nvar createVAO     = _dereq_('gl-vao')\nvar createShader  = _dereq_('./shaders').line\n\nvar MAJOR_AXIS = [0,0,0]\nvar MINOR_AXIS = [0,0,0]\nvar SCREEN_AXIS = [0,0,0]\nvar OFFSET_VEC = [0,0,0]\nvar SHAPE = [1,1]\n\nfunction zeroVec(a) {\n  a[0] = a[1] = a[2] = 0\n  return a\n}\n\nfunction copyVec(a,b) {\n  a[0] = b[0]\n  a[1] = b[1]\n  a[2] = b[2]\n  return a\n}\n\nfunction Lines(gl, vertBuffer, vao, shader, tickCount, tickOffset, gridCount, gridOffset) {\n  this.gl         = gl\n  this.vertBuffer = vertBuffer\n  this.vao        = vao\n  this.shader     = shader\n  this.tickCount  = tickCount\n  this.tickOffset = tickOffset\n  this.gridCount  = gridCount\n  this.gridOffset = gridOffset\n}\n\nvar proto = Lines.prototype\n\nproto.bind = function(model, view, projection) {\n  this.shader.bind()\n  this.shader.uniforms.model = model\n  this.shader.uniforms.view = view\n  this.shader.uniforms.projection = projection\n\n  SHAPE[0] = this.gl.drawingBufferWidth\n  SHAPE[1] = this.gl.drawingBufferHeight\n\n  this.shader.uniforms.screenShape = SHAPE\n  this.vao.bind()\n}\n\nproto.unbind = function() {\n  this.vao.unbind()\n}\n\nproto.drawAxisLine = function(j, bounds, offset, color, lineWidth) {\n  var minorAxis = zeroVec(MINOR_AXIS)\n  this.shader.uniforms.majorAxis = MINOR_AXIS\n\n  minorAxis[j] = bounds[1][j] - bounds[0][j]\n  this.shader.uniforms.minorAxis = minorAxis\n\n  var noffset = copyVec(OFFSET_VEC, offset)\n  noffset[j] += bounds[0][j]\n  this.shader.uniforms.offset = noffset\n\n  this.shader.uniforms.lineWidth = lineWidth\n\n  this.shader.uniforms.color = color\n\n  var screenAxis = zeroVec(SCREEN_AXIS)\n  screenAxis[(j+2)%3] = 1\n  this.shader.uniforms.screenAxis = screenAxis\n  this.vao.draw(this.gl.TRIANGLES, 6)\n\n  var screenAxis = zeroVec(SCREEN_AXIS)\n  screenAxis[(j+1)%3] = 1\n  this.shader.uniforms.screenAxis = screenAxis\n  this.vao.draw(this.gl.TRIANGLES, 6)\n}\n\nproto.drawAxisTicks = function(j, offset, minorAxis, color, lineWidth) {\n  if(!this.tickCount[j]) {\n    return\n  }\n\n  var majorAxis = zeroVec(MAJOR_AXIS)\n  majorAxis[j]  = 1\n  this.shader.uniforms.majorAxis = majorAxis\n  this.shader.uniforms.offset    = offset\n  this.shader.uniforms.minorAxis = minorAxis\n  this.shader.uniforms.color     = color\n  this.shader.uniforms.lineWidth = lineWidth\n\n  var screenAxis = zeroVec(SCREEN_AXIS)\n  screenAxis[j] = 1\n  this.shader.uniforms.screenAxis = screenAxis\n  this.vao.draw(this.gl.TRIANGLES, this.tickCount[j], this.tickOffset[j])\n}\n\n\nproto.drawGrid = function(i, j, bounds, offset, color, lineWidth) {\n  if(!this.gridCount[i]) {\n    return\n  }\n\n  var minorAxis = zeroVec(MINOR_AXIS)\n  minorAxis[j]  = bounds[1][j] - bounds[0][j]\n  this.shader.uniforms.minorAxis = minorAxis\n\n  var noffset = copyVec(OFFSET_VEC, offset)\n  noffset[j] += bounds[0][j]\n  this.shader.uniforms.offset = noffset\n\n  var majorAxis = zeroVec(MAJOR_AXIS)\n  majorAxis[i]  = 1\n  this.shader.uniforms.majorAxis = majorAxis\n\n  var screenAxis = zeroVec(SCREEN_AXIS)\n  screenAxis[i] = 1\n  this.shader.uniforms.screenAxis = screenAxis\n  this.shader.uniforms.lineWidth = lineWidth\n\n  this.shader.uniforms.color = color\n  this.vao.draw(this.gl.TRIANGLES, this.gridCount[i], this.gridOffset[i])\n}\n\nproto.drawZero = function(j, i, bounds, offset, color, lineWidth) {\n  var minorAxis = zeroVec(MINOR_AXIS)\n  this.shader.uniforms.majorAxis = minorAxis\n\n  minorAxis[j] = bounds[1][j] - bounds[0][j]\n  this.shader.uniforms.minorAxis = minorAxis\n\n  var noffset = copyVec(OFFSET_VEC, offset)\n  noffset[j] += bounds[0][j]\n  this.shader.uniforms.offset = noffset\n\n  var screenAxis = zeroVec(SCREEN_AXIS)\n  screenAxis[i] = 1\n  this.shader.uniforms.screenAxis = screenAxis\n  this.shader.uniforms.lineWidth = lineWidth\n\n  this.shader.uniforms.color = color\n  this.vao.draw(this.gl.TRIANGLES, 6)\n}\n\nproto.dispose = function() {\n  this.vao.dispose()\n  this.vertBuffer.dispose()\n  this.shader.dispose()\n}\n\nfunction createLines(gl, bounds, ticks) {\n  var vertices    = []\n  var tickOffset  = [0,0,0]\n  var tickCount   = [0,0,0]\n\n  //Create grid lines for each axis/direction\n  var gridOffset = [0,0,0]\n  var gridCount  = [0,0,0]\n\n  //Add zero line\n  vertices.push(\n    0,0,1,   0,1,1,   0,0,-1,\n    0,0,-1,  0,1,1,   0,1,-1)\n\n  for(var i=0; i<3; ++i) {\n    //Axis tick marks\n    var start = ((vertices.length / 3)|0)\n    for(var j=0; j<ticks[i].length; ++j) {\n      var x = +ticks[i][j].x\n      vertices.push(\n        x,0,1,   x,1,1,   x,0,-1,\n        x,0,-1,  x,1,1,   x,1,-1)\n    }\n    var end = ((vertices.length / 3)|0)\n    tickOffset[i] = start\n    tickCount[i]  = end - start\n\n    //Grid lines\n    var start = ((vertices.length / 3)|0)\n    for(var k=0; k<ticks[i].length; ++k) {\n      var x = +ticks[i][k].x\n      vertices.push(\n        x,0,1,   x,1,1,   x,0,-1,\n        x,0,-1,  x,1,1,   x,1,-1)\n    }\n    var end = ((vertices.length / 3)|0)\n    gridOffset[i] = start\n    gridCount[i]  = end - start\n  }\n\n  //Create cube VAO\n  var vertBuf = createBuffer(gl, new Float32Array(vertices))\n  var vao = createVAO(gl, [\n    { \"buffer\": vertBuf,\n      \"type\": gl.FLOAT,\n      \"size\": 3,\n      \"stride\": 0,\n      \"offset\": 0\n    }\n  ])\n  var shader = createShader(gl)\n  shader.attributes.position.location = 0\n  return new Lines(gl, vertBuf, vao, shader, tickCount, tickOffset, gridCount, gridOffset)\n}\n\n},{\"./shaders\":237,\"gl-buffer\":241,\"gl-vao\":327}],237:[function(_dereq_,module,exports){\n'use strict'\n\nvar glslify = _dereq_('glslify')\nvar createShader = _dereq_('gl-shader')\n\nvar lineVert = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position;\\n\\nuniform mat4 model, view, projection;\\nuniform vec3 offset, majorAxis, minorAxis, screenAxis;\\nuniform float lineWidth;\\nuniform vec2 screenShape;\\n\\nvec3 project(vec3 p) {\\n  vec4 pp = projection * view * model * vec4(p, 1.0);\\n  return pp.xyz / max(pp.w, 0.0001);\\n}\\n\\nvoid main() {\\n  vec3 major = position.x * majorAxis;\\n  vec3 minor = position.y * minorAxis;\\n\\n  vec3 vPosition = major + minor + offset;\\n  vec3 pPosition = project(vPosition);\\n  vec3 offset = project(vPosition + screenAxis * position.z);\\n\\n  vec2 screen = normalize((offset - pPosition).xy * screenShape) / screenShape;\\n\\n  gl_Position = vec4(pPosition + vec3(0.5 * screen * lineWidth, 0), 1.0);\\n}\\n\"])\nvar lineFrag = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nuniform vec4 color;\\nvoid main() {\\n  gl_FragColor = color;\\n}\"])\nexports.line = function(gl) {\n  return createShader(gl, lineVert, lineFrag, null, [\n    {name: 'position', type: 'vec3'}\n  ])\n}\n\nvar textVert = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position;\\n\\nuniform mat4 model, view, projection;\\nuniform vec3 offset, axis, alignDir, alignOpt;\\nuniform float scale, angle, pixelScale;\\nuniform vec2 resolution;\\n\\nvec3 project(vec3 p) {\\n  vec4 pp = projection * view * model * vec4(p, 1.0);\\n  return pp.xyz / max(pp.w, 0.0001);\\n}\\n\\nfloat computeViewAngle(vec3 a, vec3 b) {\\n  vec3 A = project(a);\\n  vec3 B = project(b);\\n\\n  return atan(\\n    (B.y - A.y) * resolution.y,\\n    (B.x - A.x) * resolution.x\\n  );\\n}\\n\\nconst float PI = 3.141592;\\nconst float TWO_PI = 2.0 * PI;\\nconst float HALF_PI = 0.5 * PI;\\nconst float ONE_AND_HALF_PI = 1.5 * PI;\\n\\nint option = int(floor(alignOpt.x + 0.001));\\nfloat hv_ratio =       alignOpt.y;\\nbool enableAlign =    (alignOpt.z != 0.0);\\n\\nfloat mod_angle(float a) {\\n  return mod(a, PI);\\n}\\n\\nfloat positive_angle(float a) {\\n  return mod_angle((a < 0.0) ?\\n    a + TWO_PI :\\n    a\\n  );\\n}\\n\\nfloat look_upwards(float a) {\\n  float b = positive_angle(a);\\n  return ((b > HALF_PI) && (b <= ONE_AND_HALF_PI)) ?\\n    b - PI :\\n    b;\\n}\\n\\nfloat look_horizontal_or_vertical(float a, float ratio) {\\n  // ratio controls the ratio between being horizontal to (vertical + horizontal)\\n  // if ratio is set to 0.5 then it is 50%, 50%.\\n  // when using a higher ratio e.g. 0.75 the result would\\n  // likely be more horizontal than vertical.\\n\\n  float b = positive_angle(a);\\n\\n  return\\n    (b < (      ratio) * HALF_PI) ? 0.0 :\\n    (b < (2.0 - ratio) * HALF_PI) ? -HALF_PI :\\n    (b < (2.0 + ratio) * HALF_PI) ? 0.0 :\\n    (b < (4.0 - ratio) * HALF_PI) ? HALF_PI :\\n                                    0.0;\\n}\\n\\nfloat roundTo(float a, float b) {\\n  return float(b * floor((a + 0.5 * b) / b));\\n}\\n\\nfloat look_round_n_directions(float a, int n) {\\n  float b = positive_angle(a);\\n  float div = TWO_PI / float(n);\\n  float c = roundTo(b, div);\\n  return look_upwards(c);\\n}\\n\\nfloat applyAlignOption(float rawAngle, float delta) {\\n  return\\n    (option >  2) ? look_round_n_directions(rawAngle + delta, option) :       // option 3-n: round to n directions\\n    (option == 2) ? look_horizontal_or_vertical(rawAngle + delta, hv_ratio) : // horizontal or vertical\\n    (option == 1) ? rawAngle + delta :       // use free angle, and flip to align with one direction of the axis\\n    (option == 0) ? look_upwards(rawAngle) : // use free angle, and stay upwards\\n    (option ==-1) ? 0.0 :                    // useful for backward compatibility, all texts remains horizontal\\n                    rawAngle;                // otherwise return back raw input angle\\n}\\n\\nbool isAxisTitle = (axis.x == 0.0) &&\\n                   (axis.y == 0.0) &&\\n                   (axis.z == 0.0);\\n\\nvoid main() {\\n  //Compute world offset\\n  float axisDistance = position.z;\\n  vec3 dataPosition = axisDistance * axis + offset;\\n\\n  float beta = angle; // i.e. user defined attributes for each tick\\n\\n  float axisAngle;\\n  float clipAngle;\\n  float flip;\\n\\n  if (enableAlign) {\\n    axisAngle = (isAxisTitle) ? HALF_PI :\\n                      computeViewAngle(dataPosition, dataPosition + axis);\\n    clipAngle = computeViewAngle(dataPosition, dataPosition + alignDir);\\n\\n    axisAngle += (sin(axisAngle) < 0.0) ? PI : 0.0;\\n    clipAngle += (sin(clipAngle) < 0.0) ? PI : 0.0;\\n\\n    flip = (dot(vec2(cos(axisAngle), sin(axisAngle)),\\n                vec2(sin(clipAngle),-cos(clipAngle))) > 0.0) ? 1.0 : 0.0;\\n\\n    beta += applyAlignOption(clipAngle, flip * PI);\\n  }\\n\\n  //Compute plane offset\\n  vec2 planeCoord = position.xy * pixelScale;\\n\\n  mat2 planeXform = scale * mat2(\\n     cos(beta), sin(beta),\\n    -sin(beta), cos(beta)\\n  );\\n\\n  vec2 viewOffset = 2.0 * planeXform * planeCoord / resolution;\\n\\n  //Compute clip position\\n  vec3 clipPosition = project(dataPosition);\\n\\n  //Apply text offset in clip coordinates\\n  clipPosition += vec3(viewOffset, 0.0);\\n\\n  //Done\\n  gl_Position = vec4(clipPosition, 1.0);\\n}\"])\nvar textFrag = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nuniform vec4 color;\\nvoid main() {\\n  gl_FragColor = color;\\n}\"])\nexports.text = function(gl) {\n  return createShader(gl, textVert, textFrag, null, [\n    {name: 'position', type: 'vec3'}\n  ])\n}\n\nvar bgVert = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position;\\nattribute vec3 normal;\\n\\nuniform mat4 model, view, projection;\\nuniform vec3 enable;\\nuniform vec3 bounds[2];\\n\\nvarying vec3 colorChannel;\\n\\nvoid main() {\\n\\n  vec3 signAxis = sign(bounds[1] - bounds[0]);\\n\\n  vec3 realNormal = signAxis * normal;\\n\\n  if(dot(realNormal, enable) > 0.0) {\\n    vec3 minRange = min(bounds[0], bounds[1]);\\n    vec3 maxRange = max(bounds[0], bounds[1]);\\n    vec3 nPosition = mix(minRange, maxRange, 0.5 * (position + 1.0));\\n    gl_Position = projection * view * model * vec4(nPosition, 1.0);\\n  } else {\\n    gl_Position = vec4(0,0,0,0);\\n  }\\n\\n  colorChannel = abs(realNormal);\\n}\"])\nvar bgFrag = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nuniform vec4 colors[3];\\n\\nvarying vec3 colorChannel;\\n\\nvoid main() {\\n  gl_FragColor = colorChannel.x * colors[0] +\\n                 colorChannel.y * colors[1] +\\n                 colorChannel.z * colors[2];\\n}\"])\nexports.bg = function(gl) {\n  return createShader(gl, bgVert, bgFrag, null, [\n    {name: 'position', type: 'vec3'},\n    {name: 'normal', type: 'vec3'}\n  ])\n}\n\n},{\"gl-shader\":301,\"glslify\":409}],238:[function(_dereq_,module,exports){\n(function (process){\n\"use strict\"\n\nmodule.exports = createTextSprites\n\nvar createBuffer  = _dereq_('gl-buffer')\nvar createVAO     = _dereq_('gl-vao')\nvar vectorizeText = _dereq_('vectorize-text')\nvar createShader  = _dereq_('./shaders').text\n\nvar globals = window || process.global || {}\nvar __TEXT_CACHE  = globals.__TEXT_CACHE || {}\nglobals.__TEXT_CACHE = {}\n\n//Vertex buffer format for text is:\n//\n/// [x,y,z] = Spatial coordinate\n//\n\nvar VERTEX_SIZE = 3\n\nfunction TextSprites(\n  gl,\n  shader,\n  buffer,\n  vao) {\n  this.gl           = gl\n  this.shader       = shader\n  this.buffer       = buffer\n  this.vao          = vao\n  this.tickOffset   =\n  this.tickCount    =\n  this.labelOffset  =\n  this.labelCount   = null\n}\n\nvar proto = TextSprites.prototype\n\n//Bind textures for rendering\nvar SHAPE = [0,0]\nproto.bind = function(model, view, projection, pixelScale) {\n  this.vao.bind()\n  this.shader.bind()\n  var uniforms = this.shader.uniforms\n  uniforms.model = model\n  uniforms.view = view\n  uniforms.projection = projection\n  uniforms.pixelScale = pixelScale\n  SHAPE[0] = this.gl.drawingBufferWidth\n  SHAPE[1] = this.gl.drawingBufferHeight\n  this.shader.uniforms.resolution = SHAPE\n}\n\nproto.unbind = function() {\n  this.vao.unbind()\n}\n\nproto.update = function(bounds, labels, labelFont, ticks, tickFont) {\n  var data = []\n\n  function addItem(t, text, font, size, lineSpacing, styletags) {\n    var fontcache = __TEXT_CACHE[font]\n    if(!fontcache) {\n      fontcache = __TEXT_CACHE[font] = {}\n    }\n    var mesh = fontcache[text]\n    if(!mesh) {\n      mesh = fontcache[text] = tryVectorizeText(text, {\n        triangles: true,\n        font: font,\n        textAlign: 'center',\n        textBaseline: 'middle',\n        lineSpacing: lineSpacing,\n        styletags: styletags\n      })\n    }\n    var scale = (size || 12) / 12\n    var positions = mesh.positions\n    var cells = mesh.cells\n    for(var i=0, nc=cells.length; i<nc; ++i) {\n      var c = cells[i]\n      for(var j=2; j>=0; --j) {\n        var p = positions[c[j]]\n        data.push(scale*p[0], -scale*p[1], t)\n      }\n    }\n  }\n\n  //Generate sprites for all 3 axes, store data in texture atlases\n  var tickOffset  = [0,0,0]\n  var tickCount   = [0,0,0]\n  var labelOffset = [0,0,0]\n  var labelCount  = [0,0,0]\n  var lineSpacing = 1.25\n  var styletags = {\n    breaklines:true,\n    bolds: true,\n    italics: true,\n    subscripts:true,\n    superscripts:true\n  }\n  for(var d=0; d<3; ++d) {\n\n    //Generate label\n    labelOffset[d] = (data.length/VERTEX_SIZE)|0\n    addItem(\n      0.5*(bounds[0][d]+bounds[1][d]),\n      labels[d],\n      labelFont[d],\n      12, // labelFontSize\n      lineSpacing,\n      styletags\n    )\n    labelCount[d] = ((data.length/VERTEX_SIZE)|0) - labelOffset[d]\n\n    //Generate sprites for tick marks\n    tickOffset[d] = (data.length/VERTEX_SIZE)|0\n    for(var i=0; i<ticks[d].length; ++i) {\n      if(!ticks[d][i].text) {\n        continue\n      }\n      addItem(\n        ticks[d][i].x,\n        ticks[d][i].text,\n        ticks[d][i].font || tickFont,\n        ticks[d][i].fontSize || 12,\n        lineSpacing,\n        styletags\n      )\n    }\n    tickCount[d] = ((data.length/VERTEX_SIZE)|0) - tickOffset[d]\n  }\n\n  this.buffer.update(data)\n  this.tickOffset = tickOffset\n  this.tickCount = tickCount\n  this.labelOffset = labelOffset\n  this.labelCount = labelCount\n}\n\n//Draws the tick marks for an axis\nproto.drawTicks = function(d, scale, angle, offset, color, axis, alignDir, alignOpt) {\n  if(!this.tickCount[d]) {\n    return\n  }\n\n  this.shader.uniforms.axis = axis\n  this.shader.uniforms.color = color\n  this.shader.uniforms.angle = angle\n  this.shader.uniforms.scale = scale\n  this.shader.uniforms.offset = offset\n  this.shader.uniforms.alignDir = alignDir\n  this.shader.uniforms.alignOpt = alignOpt\n  this.vao.draw(this.gl.TRIANGLES, this.tickCount[d], this.tickOffset[d])\n}\n\n//Draws the text label for an axis\nproto.drawLabel = function(d, scale, angle, offset, color, axis, alignDir, alignOpt) {\n  if(!this.labelCount[d]) {\n    return\n  }\n\n  this.shader.uniforms.axis = axis\n  this.shader.uniforms.color = color\n  this.shader.uniforms.angle = angle\n  this.shader.uniforms.scale = scale\n  this.shader.uniforms.offset = offset\n  this.shader.uniforms.alignDir = alignDir\n  this.shader.uniforms.alignOpt = alignOpt\n  this.vao.draw(this.gl.TRIANGLES, this.labelCount[d], this.labelOffset[d])\n}\n\n//Releases all resources attached to this object\nproto.dispose = function() {\n  this.shader.dispose()\n  this.vao.dispose()\n  this.buffer.dispose()\n}\n\nfunction tryVectorizeText(text, options) {\n  try {\n    return vectorizeText(text, options)\n  } catch(e) {\n    console.warn('error vectorizing text:\"' + text + '\" error:', e)\n    return {\n      cells: [],\n      positions: []\n    }\n  }\n}\n\nfunction createTextSprites(\n    gl,\n    bounds,\n    labels,\n    labelFont,\n    ticks,\n    tickFont) {\n\n  var buffer = createBuffer(gl)\n  var vao = createVAO(gl, [\n    { \"buffer\": buffer,\n      \"size\": 3\n    }\n  ])\n\n  var shader = createShader(gl)\n  shader.attributes.position.location = 0\n\n  var result = new TextSprites(\n    gl,\n    shader,\n    buffer,\n    vao)\n\n  result.update(bounds, labels, labelFont, ticks, tickFont)\n\n  return result\n}\n\n}).call(this,_dereq_('_process'))\n},{\"./shaders\":237,\"_process\":482,\"gl-buffer\":241,\"gl-vao\":327,\"vectorize-text\":550}],239:[function(_dereq_,module,exports){\n'use strict'\n\nexports.create   = defaultTicks\nexports.equal    = ticksEqual\n\nfunction prettyPrint(spacing, i) {\n  var stepStr = spacing + \"\"\n  var u = stepStr.indexOf(\".\")\n  var sigFigs = 0\n  if(u >= 0) {\n    sigFigs = stepStr.length - u - 1\n  }\n  var shift = Math.pow(10, sigFigs)\n  var x = Math.round(spacing * i * shift)\n  var xstr = x + \"\"\n  if(xstr.indexOf(\"e\") >= 0) {\n    return xstr\n  }\n  var xi = x / shift, xf = x % shift\n  if(x < 0) {\n    xi = -Math.ceil(xi)|0\n    xf = (-xf)|0\n  } else {\n    xi = Math.floor(xi)|0\n    xf = xf|0\n  }\n  var xis = \"\" + xi \n  if(x < 0) {\n    xis = \"-\" + xis\n  }\n  if(sigFigs) {\n    var xs = \"\" + xf\n    while(xs.length < sigFigs) {\n      xs = \"0\" + xs\n    }\n    return xis + \".\" + xs\n  } else {\n    return xis\n  }\n}\n\nfunction defaultTicks(bounds, tickSpacing) {\n  var array = []\n  for(var d=0; d<3; ++d) {\n    var ticks = []\n    var m = 0.5*(bounds[0][d]+bounds[1][d])\n    for(var t=0; t*tickSpacing[d]<=bounds[1][d]; ++t) {\n      ticks.push({x: t*tickSpacing[d], text: prettyPrint(tickSpacing[d], t)})\n    }\n    for(var t=-1; t*tickSpacing[d]>=bounds[0][d]; --t) {\n      ticks.push({x: t*tickSpacing[d], text: prettyPrint(tickSpacing[d], t)})\n    }\n    array.push(ticks)\n  }\n  return array\n}\n\nfunction ticksEqual(ticksA, ticksB) {\n  for(var i=0; i<3; ++i) {\n    if(ticksA[i].length !== ticksB[i].length) {\n      return false\n    }\n    for(var j=0; j<ticksA[i].length; ++j) {\n      var a = ticksA[i][j]\n      var b = ticksB[i][j]\n      if(\n        a.x !== b.x ||\n        a.text !== b.text ||\n        a.font !== b.font ||\n        a.fontColor !== b.fontColor ||\n        a.fontSize !== b.fontSize ||\n        a.dx !== b.dx ||\n        a.dy !== b.dy\n      ) {\n        return false\n      }\n    }\n  }\n  return true\n}\n},{}],240:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = axesProperties\n\nvar getPlanes   = _dereq_(\"extract-frustum-planes\")\nvar splitPoly   = _dereq_(\"split-polygon\")\nvar cubeParams  = _dereq_(\"./lib/cube.js\")\nvar m4mul       = _dereq_(\"gl-mat4/multiply\")\nvar m4transpose = _dereq_(\"gl-mat4/transpose\")\nvar v4transformMat4 = _dereq_(\"gl-vec4/transformMat4\")\n\nvar identity    = new Float32Array([\n    1, 0, 0, 0,\n    0, 1, 0, 0,\n    0, 0, 1, 0,\n    0, 0, 0, 1\n  ])\n\nvar mvp         = new Float32Array(16)\n\nfunction AxesRange3D(lo, hi, pixelsPerDataUnit) {\n  this.lo = lo\n  this.hi = hi\n  this.pixelsPerDataUnit = pixelsPerDataUnit\n}\n\nvar SCRATCH_P = [0,0,0,1]\nvar SCRATCH_Q = [0,0,0,1]\n\nfunction gradient(result, M, v, width, height) {\n  for(var i=0; i<3; ++i) {\n    var p = SCRATCH_P\n    var q = SCRATCH_Q\n    for(var j=0; j<3; ++j) {\n      q[j] = p[j] = v[j]\n    }\n    q[3] = p[3] = 1\n\n    q[i] += 1\n    v4transformMat4(q, q, M)\n    if(q[3] < 0) {\n      result[i] = Infinity\n    }\n\n    p[i] -= 1\n    v4transformMat4(p, p, M)\n    if(p[3] < 0) {\n      result[i] = Infinity\n    }\n\n    var dx = (p[0]/p[3] - q[0]/q[3]) * width\n    var dy = (p[1]/p[3] - q[1]/q[3]) * height\n\n    result[i] = 0.25 * Math.sqrt(dx*dx + dy*dy)\n  }\n  return result\n}\n\nvar RANGES = [\n  new AxesRange3D(Infinity, -Infinity, Infinity),\n  new AxesRange3D(Infinity, -Infinity, Infinity),\n  new AxesRange3D(Infinity, -Infinity, Infinity)\n]\n\nvar SCRATCH_X = [0,0,0]\n\nfunction axesProperties(axes, camera, width, height, params) {\n  var model       = camera.model || identity\n  var view        = camera.view || identity\n  var projection  = camera.projection || identity\n  var isOrtho     = camera._ortho || false\n  var bounds      = axes.bounds\n  var params      = params || cubeParams(model, view, projection, bounds, isOrtho)\n  var axis        = params.axis\n\n  m4mul(mvp, view, model)\n  m4mul(mvp, projection, mvp)\n\n  //Calculate the following properties for each axis:\n  //\n  // * lo - start of visible range for each axis in tick coordinates\n  // * hi - end of visible range for each axis in tick coordinates\n  // * ticksPerPixel - pixel density of tick marks for the axis\n  //\n  var ranges = RANGES\n  for(var i=0; i<3; ++i) {\n    ranges[i].lo = Infinity\n    ranges[i].hi = -Infinity\n    ranges[i].pixelsPerDataUnit = Infinity\n  }\n\n  //Compute frustum planes, intersect with box\n  var frustum = getPlanes(m4transpose(mvp, mvp))\n  m4transpose(mvp, mvp)\n\n  //Loop over vertices of viewable box\n  for(var d=0; d<3; ++d) {\n    var u = (d+1)%3\n    var v = (d+2)%3\n    var x = SCRATCH_X\ni_loop:\n    for(var i=0; i<2; ++i) {\n      var poly = []\n\n      if((axis[d] < 0) === !!i) {\n        continue\n      }\n\n      x[d] = bounds[i][d]\n      for(var j=0; j<2; ++j) {\n        x[u] = bounds[j^i][u]\n        for(var k=0; k<2; ++k) {\n          x[v] = bounds[k^j^i][v]\n          poly.push(x.slice())\n        }\n      }\n\n      var Q = (isOrtho) ? 5 : 4\n      for(var j=Q; j===Q; ++j) { // Note: using only near plane here (& for orthographic projection we use the far).\n        if(poly.length === 0) {\n          continue i_loop\n        }\n        poly = splitPoly.positive(poly, frustum[j])\n      }\n\n      //Loop over vertices of polygon to find extremal points\n      for(var j=0; j<poly.length; ++j) {\n        var v = poly[j]\n        var grad = gradient(SCRATCH_X, mvp, v, width, height)\n        for(var k=0; k<3; ++k) {\n          ranges[k].lo = Math.min(ranges[k].lo, v[k])\n          ranges[k].hi = Math.max(ranges[k].hi, v[k])\n          if(k !== d) {\n            ranges[k].pixelsPerDataUnit = Math.min(ranges[k].pixelsPerDataUnit, Math.abs(grad[k]))\n          }\n        }\n      }\n    }\n  }\n\n  return ranges\n}\n\n},{\"./lib/cube.js\":235,\"extract-frustum-planes\":224,\"gl-mat4/multiply\":267,\"gl-mat4/transpose\":276,\"gl-vec4/transformMat4\":398,\"split-polygon\":527}],241:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar pool = _dereq_(\"typedarray-pool\")\nvar ops = _dereq_(\"ndarray-ops\")\nvar ndarray = _dereq_(\"ndarray\")\n\nvar SUPPORTED_TYPES = [\n  \"uint8\",\n  \"uint8_clamped\",\n  \"uint16\",\n  \"uint32\",\n  \"int8\",\n  \"int16\",\n  \"int32\",\n  \"float32\" ]\n\nfunction GLBuffer(gl, type, handle, length, usage) {\n  this.gl = gl\n  this.type = type\n  this.handle = handle\n  this.length = length\n  this.usage = usage\n}\n\nvar proto = GLBuffer.prototype\n\nproto.bind = function() {\n  this.gl.bindBuffer(this.type, this.handle)\n}\n\nproto.unbind = function() {\n  this.gl.bindBuffer(this.type, null)\n}\n\nproto.dispose = function() {\n  this.gl.deleteBuffer(this.handle)\n}\n\nfunction updateTypeArray(gl, type, len, usage, data, offset) {\n  var dataLen = data.length * data.BYTES_PER_ELEMENT\n  if(offset < 0) {\n    gl.bufferData(type, data, usage)\n    return dataLen\n  }\n  if(dataLen + offset > len) {\n    throw new Error(\"gl-buffer: If resizing buffer, must not specify offset\")\n  }\n  gl.bufferSubData(type, offset, data)\n  return len\n}\n\nfunction makeScratchTypeArray(array, dtype) {\n  var res = pool.malloc(array.length, dtype)\n  var n = array.length\n  for(var i=0; i<n; ++i) {\n    res[i] = array[i]\n  }\n  return res\n}\n\nfunction isPacked(shape, stride) {\n  var n = 1\n  for(var i=stride.length-1; i>=0; --i) {\n    if(stride[i] !== n) {\n      return false\n    }\n    n *= shape[i]\n  }\n  return true\n}\n\nproto.update = function(array, offset) {\n  if(typeof offset !== \"number\") {\n    offset = -1\n  }\n  this.bind()\n  if(typeof array === \"object\" && typeof array.shape !== \"undefined\") { //ndarray\n    var dtype = array.dtype\n    if(SUPPORTED_TYPES.indexOf(dtype) < 0) {\n      dtype = \"float32\"\n    }\n    if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) {\n      var ext = gl.getExtension('OES_element_index_uint')\n      if(ext && dtype !== \"uint16\") {\n        dtype = \"uint32\"\n      } else {\n        dtype = \"uint16\"\n      }\n    }\n    if(dtype === array.dtype && isPacked(array.shape, array.stride)) {\n      if(array.offset === 0 && array.data.length === array.shape[0]) {\n        this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data, offset)\n      } else {\n        this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array.data.subarray(array.offset, array.shape[0]), offset)\n      }\n    } else {\n      var tmp = pool.malloc(array.size, dtype)\n      var ndt = ndarray(tmp, array.shape)\n      ops.assign(ndt, array)\n      if(offset < 0) {\n        this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp, offset)\n      } else {\n        this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, tmp.subarray(0, array.size), offset)\n      }\n      pool.free(tmp)\n    }\n  } else if(Array.isArray(array)) { //Vanilla array\n    var t\n    if(this.type === this.gl.ELEMENT_ARRAY_BUFFER) {\n      t = makeScratchTypeArray(array, \"uint16\")\n    } else {\n      t = makeScratchTypeArray(array, \"float32\")\n    }\n    if(offset < 0) {\n      this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t, offset)\n    } else {\n      this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, t.subarray(0, array.length), offset)\n    }\n    pool.free(t)\n  } else if(typeof array === \"object\" && typeof array.length === \"number\") { //Typed array\n    this.length = updateTypeArray(this.gl, this.type, this.length, this.usage, array, offset)\n  } else if(typeof array === \"number\" || array === undefined) { //Number/default\n    if(offset >= 0) {\n      throw new Error(\"gl-buffer: Cannot specify offset when resizing buffer\")\n    }\n    array = array | 0\n    if(array <= 0) {\n      array = 1\n    }\n    this.gl.bufferData(this.type, array|0, this.usage)\n    this.length = array\n  } else { //Error, case should not happen\n    throw new Error(\"gl-buffer: Invalid data type\")\n  }\n}\n\nfunction createBuffer(gl, data, type, usage) {\n  type = type || gl.ARRAY_BUFFER\n  usage = usage || gl.DYNAMIC_DRAW\n  if(type !== gl.ARRAY_BUFFER && type !== gl.ELEMENT_ARRAY_BUFFER) {\n    throw new Error(\"gl-buffer: Invalid type for webgl buffer, must be either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER\")\n  }\n  if(usage !== gl.DYNAMIC_DRAW && usage !== gl.STATIC_DRAW && usage !== gl.STREAM_DRAW) {\n    throw new Error(\"gl-buffer: Invalid usage for buffer, must be either gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW\")\n  }\n  var handle = gl.createBuffer()\n  var result = new GLBuffer(gl, type, handle, 0, usage)\n  result.update(data)\n  return result\n}\n\nmodule.exports = createBuffer\n\n},{\"ndarray\":450,\"ndarray-ops\":444,\"typedarray-pool\":545}],242:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar V = _dereq_('gl-vec3');\n\nvar vec3 = function(x, y, z) {\n\tvar v = V.create();\n\tif (x !== undefined) {\n\t\tV.set(v, x, y, z);\n\t}\n\treturn v;\n}\n\nvar createPositionsForMeshgrid = function(meshgrid) {\n\tvar xs = meshgrid[0], ys = meshgrid[1], zs = meshgrid[2];\n\tvar positions = [];\n\tfor (var z=0; z<zs.length; z++) {\n\t\tfor (var y=0; y<ys.length; y++) {\n\t\t\tfor (var x=0; x<xs.length; x++) {\n\t\t\t\tpositions.push([zs[z], ys[y], xs[x]]);\n\t\t\t}\n\t\t}\n\t}\n\treturn positions;\n};\n\nvar findLastSmallerIndex = function(points, v) {\n\tfor (var i=0; i<points.length; i++) {\n\t\tif (points[i] >= v) {\n\t\t\treturn i-1;\n\t\t}\n\t}\n\treturn i;\n};\n\nvar tmp = V.create();\nvar tmp2 = V.create();\n\nvar clamp = function(v, min, max) {\n\treturn v < min ? min : (v > max ? max : v);\n};\n\nvar sampleMeshgrid = function(point, array, meshgrid, clampOverflow) {\n\tvar x = point[0];\n\tvar y = point[1];\n\tvar z = point[2];\n\n\tvar w = meshgrid[0].length;\n\tvar h = meshgrid[1].length;\n\tvar d = meshgrid[2].length;\n\n\t// Find the index of the nearest smaller value in the meshgrid for each coordinate of (x,y,z).\n\t// The nearest smaller value index for x is the index x0 such that\n\t// meshgrid[0][x0] < x and for all x1 > x0, meshgrid[0][x1] >= x.\n\tvar x0 = findLastSmallerIndex(meshgrid[0], x);\n\tvar y0 = findLastSmallerIndex(meshgrid[1], y);\n\tvar z0 = findLastSmallerIndex(meshgrid[2], z);\n\n\t// Get the nearest larger meshgrid value indices.\n\t// From the above \"nearest smaller value\", we know that\n\t//   meshgrid[0][x0] < x\n\t//   meshgrid[0][x0+1] >= x\n\tvar x1 = x0 + 1;\n\tvar y1 = y0 + 1;\n\tvar z1 = z0 + 1;\n\n\tif (clampOverflow) {\n\t\tx0 = clamp(x0, 0, w-1);\n\t\tx1 = clamp(x1, 0, w-1);\n\t\ty0 = clamp(y0, 0, h-1);\n\t\ty1 = clamp(y1, 0, h-1);\n\t\tz0 = clamp(z0, 0, d-1);\n\t\tz1 = clamp(z1, 0, d-1);\n\t}\n\n\t// Reject points outside the meshgrid, return a zero vector.\n\tif (x0 < 0 || y0 < 0 || z0 < 0 || x1 >= w || y1 >= h || z1 >= d) {\n\t\treturn V.create();\n\t}\n\n\t// Normalize point coordinates to 0..1 scaling factor between x0 and x1.\n\tvar xf = (x - meshgrid[0][x0]) / (meshgrid[0][x1] - meshgrid[0][x0]);\n\tvar yf = (y - meshgrid[1][y0]) / (meshgrid[1][y1] - meshgrid[1][y0]);\n\tvar zf = (z - meshgrid[2][z0]) / (meshgrid[2][z1] - meshgrid[2][z0]);\n\n\tif (xf < 0 || xf > 1 || isNaN(xf)) xf = 0;\n\tif (yf < 0 || yf > 1 || isNaN(yf)) yf = 0;\n\tif (zf < 0 || zf > 1 || isNaN(zf)) zf = 0;\n\n\tvar z0off = z0*w*h;\n\tvar z1off = z1*w*h;\n\n\tvar y0off = y0*w;\n\tvar y1off = y1*w;\n\n\tvar x0off = x0;\n\tvar x1off = x1;\n\n\t// Sample data array around the (x,y,z) point.\n\t//  vZYX = array[zZoff + yYoff + xXoff]\n\tvar v000 = array[y0off + z0off + x0off];\n\tvar v001 = array[y0off + z0off + x1off];\n\tvar v010 = array[y1off + z0off + x0off];\n\tvar v011 = array[y1off + z0off + x1off];\n\tvar v100 = array[y0off + z1off + x0off];\n\tvar v101 = array[y0off + z1off + x1off];\n\tvar v110 = array[y1off + z1off + x0off];\n\tvar v111 = array[y1off + z1off + x1off];\n\n\tvar result = V.create();\n\n\t// Average samples according to distance to point.\n\tV.lerp(result, v000, v001, xf);\n\tV.lerp(tmp, v010, v011, xf);\n\tV.lerp(result, result, tmp, yf);\n\tV.lerp(tmp, v100, v101, xf);\n\tV.lerp(tmp2, v110, v111, xf);\n\tV.lerp(tmp, tmp, tmp2, yf);\n\tV.lerp(result, result, tmp, zf);\n\n\treturn result;\n};\n\nvar getOrthogonalVector = function(dst, v) {\n\t// Return up-vector for only-z vector.\n\tif (v[0] === 0 && v[1] === 0) {\n\t\tV.set(dst, 0, 1, 0);\n\t} else {\n\t\t// Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\n\t\t// From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\n\t\t// Assign z = 0, x = -b, y = a:\n\t\t// a*-b + b*a + c*0 = -ba + ba + 0 = 0\n\t\tV.set(dst, -v[1], v[0], 0);\n\t}\n\treturn dst;\n};\n\nmodule.exports = function(vectorfield, bounds) {\n\tvar positions;\n\tif (vectorfield.positions) {\n\t\tpositions = vectorfield.positions;\n\t} else {\n\t\tpositions = createPositionsForMeshgrid(vectorfield.meshgrid);\n\t}\n\tvar meshgrid = vectorfield.meshgrid;\n\tvar vectors = vectorfield.vectors;\n\tvar geo = {\n\t\tpositions: [],\n\t\tvertexIntensity: [],\n\t\tvertexIntensityBounds: vectorfield.vertexIntensityBounds,\n\t\tvertexNormals: [],\n\t\tvectors: [],\n\t\tcells: [],\n\t\tconeOffset: vectorfield.coneOffset,\n\t\tcolormap: vectorfield.colormap\n\t};\n\n\tif (vectorfield.positions.length === 0) {\n\t\tif (bounds) {\n\t\t\tbounds[0] = [0,0,0];\n\t\t\tbounds[1] = [0,0,0];\n\t\t}\n\t\treturn geo;\n\t}\n\n\t// Compute bounding box for the dataset.\n\t// Compute maximum velocity for the dataset to use for scaling the cones.\n\tvar maxNorm = 0;\n\tvar minX = 1/0, maxX = -1/0;\n\tvar minY = 1/0, maxY = -1/0;\n\tvar minZ = 1/0, maxZ = -1/0;\n\tvar p2 = null;\n\tvar u2 = null;\n\tvar positionVectors = [];\n\tvar vectorScale = 1/0;\n\tfor (var i = 0; i < positions.length; i++) {\n\t\tvar p = positions[i];\n\t\tminX = Math.min(p[0], minX);\n\t\tmaxX = Math.max(p[0], maxX);\n\t\tminY = Math.min(p[1], minY);\n\t\tmaxY = Math.max(p[1], maxY);\n\t\tminZ = Math.min(p[2], minZ);\n\t\tmaxZ = Math.max(p[2], maxZ);\n\t\tvar u;\n\t\tif (meshgrid) {\n\t\t\tu = sampleMeshgrid(p, vectors, meshgrid, true);\n\t\t} else {\n\t\t\tu = vectors[i];\n\t\t}\n\t\tif (V.length(u) > maxNorm) {\n\t\t\tmaxNorm = V.length(u);\n\t\t}\n\t\tif (i) {\n\t\t\t// Find vector scale [w/ units of time] using \"successive\" positions\n\t\t\t// (not \"adjacent\" with would be O(n^2)),\n\t\t\t//\n\t\t\t// The vector scale corresponds to the minimum \"time\" to travel across two\n\t\t\t// two adjacent positions at the average velocity of those two adjacent positions\n\t\t\tvectorScale = Math.min(vectorScale,\n\t\t\t\t2 * V.distance(p2, p) / (V.length(u2) + V.length(u))\n\t\t\t);\n\t\t}\n\t\tp2 = p;\n\t\tu2 = u;\n\t\tpositionVectors.push(u);\n\t}\n\tvar minV = [minX, minY, minZ];\n\tvar maxV = [maxX, maxY, maxZ];\n\tif (bounds) {\n\t\tbounds[0] = minV;\n\t\tbounds[1] = maxV;\n\t}\n\tif (maxNorm === 0) {\n\t\tmaxNorm = 1;\n\t}\n\n\t// Inverted max norm would map vector with norm maxNorm to 1 coord space units in length\n\tvar invertedMaxNorm = 1 / maxNorm;\n\n\tif (!isFinite(vectorScale) || isNaN(vectorScale)) {\n\t\tvectorScale = 1.0;\n\t}\n\tgeo.vectorScale = vectorScale;\n\n\tvar nml = vec3(0,1,0);\n\n\tvar coneScale = vectorfield.coneSize || 0.5;\n\n\tif (vectorfield.absoluteConeSize) {\n\t\tconeScale = vectorfield.absoluteConeSize * invertedMaxNorm;\n\t}\n\n\tgeo.coneScale = coneScale;\n\n\t// Build the cone model.\n\tfor (var i = 0, j = 0; i < positions.length; i++) {\n\t\tvar p = positions[i];\n\t\tvar x = p[0], y = p[1], z = p[2];\n\t\tvar d = positionVectors[i];\n\t\tvar intensity = V.length(d) * invertedMaxNorm;\n\t\tfor (var k = 0, l = 8; k < l; k++) {\n\t\t\tgeo.positions.push([x, y, z, j++]);\n\t\t\tgeo.positions.push([x, y, z, j++]);\n\t\t\tgeo.positions.push([x, y, z, j++]);\n\t\t\tgeo.positions.push([x, y, z, j++]);\n\t\t\tgeo.positions.push([x, y, z, j++]);\n\t\t\tgeo.positions.push([x, y, z, j++]);\n\n\t\t\tgeo.vectors.push(d);\n\t\t\tgeo.vectors.push(d);\n\t\t\tgeo.vectors.push(d);\n\t\t\tgeo.vectors.push(d);\n\t\t\tgeo.vectors.push(d);\n\t\t\tgeo.vectors.push(d);\n\n\t\t\tgeo.vertexIntensity.push(intensity, intensity, intensity);\n\t\t\tgeo.vertexIntensity.push(intensity, intensity, intensity);\n\n\t\t\tgeo.vertexNormals.push(nml, nml, nml);\n\t\t\tgeo.vertexNormals.push(nml, nml, nml);\n\n\t\t\tvar m = geo.positions.length;\n\t\t\tgeo.cells.push([m-6, m-5, m-4], [m-3, m-2, m-1]);\n\t\t}\n\t}\n\n\treturn geo;\n};\n\nmodule.exports.createConeMesh = _dereq_('./lib/conemesh');\n\n},{\"./lib/conemesh\":243,\"gl-vec3\":346}],243:[function(_dereq_,module,exports){\n'use strict'\n\nvar DEFAULT_VERTEX_NORMALS_EPSILON = 1e-6; // may be too large if triangles are very small\nvar DEFAULT_FACE_NORMALS_EPSILON = 1e-6;\n\nvar createShader  = _dereq_('gl-shader')\nvar createBuffer  = _dereq_('gl-buffer')\nvar createVAO     = _dereq_('gl-vao')\nvar createTexture = _dereq_('gl-texture2d')\nvar normals       = _dereq_('normals')\nvar multiply      = _dereq_('gl-mat4/multiply')\nvar invert        = _dereq_('gl-mat4/invert')\nvar ndarray       = _dereq_('ndarray')\nvar colormap      = _dereq_('colormap')\nvar getContour    = _dereq_('simplicial-complex-contour')\nvar pool          = _dereq_('typedarray-pool')\nvar shaders       = _dereq_('./shaders')\n\nvar meshShader    = shaders.meshShader\nvar pickShader    = shaders.pickShader\n\nvar IDENTITY = [\n  1,0,0,0,\n  0,1,0,0,\n  0,0,1,0,\n  0,0,0,1]\n\nfunction SimplicialMesh(gl\n  , texture\n  , triShader\n  , pickShader\n  , trianglePositions\n  , triangleVectors\n  , triangleIds\n  , triangleColors\n  , triangleUVs\n  , triangleNormals\n  , triangleVAO\n  , edgePositions\n  , edgeIds\n  , edgeColors\n  , edgeUVs\n  , edgeVAO\n  , pointPositions\n  , pointIds\n  , pointColors\n  , pointUVs\n  , pointSizes\n  , pointVAO\n  , contourPositions\n  , contourVAO) {\n\n  this.gl                = gl\n  this.pixelRatio         = 1\n  this.cells             = []\n  this.positions         = []\n  this.intensity         = []\n  this.texture           = texture\n  this.dirty             = true\n\n  this.triShader         = triShader\n  this.pickShader        = pickShader\n\n  this.trianglePositions = trianglePositions\n  this.triangleVectors   = triangleVectors\n  this.triangleColors    = triangleColors\n  this.triangleNormals   = triangleNormals\n  this.triangleUVs       = triangleUVs\n  this.triangleIds       = triangleIds\n  this.triangleVAO       = triangleVAO\n  this.triangleCount     = 0\n\n  this.lineWidth         = 1\n  this.edgePositions     = edgePositions\n  this.edgeColors        = edgeColors\n  this.edgeUVs           = edgeUVs\n  this.edgeIds           = edgeIds\n  this.edgeVAO           = edgeVAO\n  this.edgeCount         = 0\n\n  this.pointPositions    = pointPositions\n  this.pointColors       = pointColors\n  this.pointUVs          = pointUVs\n  this.pointSizes        = pointSizes\n  this.pointIds          = pointIds\n  this.pointVAO          = pointVAO\n  this.pointCount        = 0\n\n  this.contourLineWidth  = 1\n  this.contourPositions  = contourPositions\n  this.contourVAO        = contourVAO\n  this.contourCount      = 0\n  this.contourColor      = [0,0,0]\n  this.contourEnable     = true\n\n  this.pickId            = 1\n  this.bounds            = [\n    [ Infinity, Infinity, Infinity],\n    [-Infinity,-Infinity,-Infinity] ]\n  this.clipBounds        = [\n    [-Infinity,-Infinity,-Infinity],\n    [ Infinity, Infinity, Infinity] ]\n\n  this.lightPosition = [1e5, 1e5, 0]\n  this.ambientLight  = 0.8\n  this.diffuseLight  = 0.8\n  this.specularLight = 2.0\n  this.roughness     = 0.5\n  this.fresnel       = 1.5\n\n  this.opacity       = 1.0\n\n  this.coneScale     = 2.0\n  this.vectorScale   = 1.0\n  this.coneOffset    = 1.0 / 4.0;\n\n  this._model       = IDENTITY\n  this._view        = IDENTITY\n  this._projection  = IDENTITY\n  this._resolution  = [1,1]\n}\n\nvar proto = SimplicialMesh.prototype\n\nproto.isOpaque = function() {\n  return this.opacity >= 1\n}\n\nproto.isTransparent = function() {\n  return this.opacity < 1\n}\n\nproto.pickSlots = 1\n\nproto.setPickBase = function(id) {\n  this.pickId = id\n}\n\nfunction genColormap(param) {\n  var colors = colormap({\n      colormap: param\n    , nshades:  256\n    , format:  'rgba'\n  })\n\n  var result = new Uint8Array(256*4)\n  for(var i=0; i<256; ++i) {\n    var c = colors[i]\n    for(var j=0; j<3; ++j) {\n      result[4*i+j] = c[j]\n    }\n    result[4*i+3] = c[3]*255\n  }\n\n  return ndarray(result, [256,256,4], [4,0,1])\n}\n\nfunction unpackIntensity(cells, numVerts, cellIntensity) {\n  var result = new Array(numVerts)\n  for(var i=0; i<numVerts; ++i) {\n    result[i] = 0\n  }\n  var numCells = cells.length\n  for(var i=0; i<numCells; ++i) {\n    var c = cells[i]\n    for(var j=0; j<c.length; ++j) {\n      result[c[j]] = cellIntensity[i]\n    }\n  }\n  return result\n}\n\nfunction takeZComponent(array) {\n  var n = array.length\n  var result = new Array(n)\n  for(var i=0; i<n; ++i) {\n    result[i] = array[i][2]\n  }\n  return result\n}\n\nproto.highlight = function(selection) {\n  if(!selection || !this.contourEnable) {\n    this.contourCount = 0\n    return\n  }\n  var level = getContour(this.cells, this.intensity, selection.intensity)\n  var cells         = level.cells\n  var vertexIds     = level.vertexIds\n  var vertexWeights = level.vertexWeights\n  var numCells = cells.length\n  var result = pool.mallocFloat32(2 * 3 * numCells)\n  var ptr = 0\n  for(var i=0; i<numCells; ++i) {\n    var c = cells[i]\n    for(var j=0; j<2; ++j) {\n      var v = c[0]\n      if(c.length === 2) {\n        v = c[j]\n      }\n      var a = vertexIds[v][0]\n      var b = vertexIds[v][1]\n      var w = vertexWeights[v]\n      var wi = 1.0 - w\n      var pa = this.positions[a]\n      var pb = this.positions[b]\n      for(var k=0; k<3; ++k) {\n        result[ptr++] = w * pa[k] + wi * pb[k]\n      }\n    }\n  }\n  this.contourCount = (ptr / 3)|0\n  this.contourPositions.update(result.subarray(0, ptr))\n  pool.free(result)\n}\n\nproto.update = function(params) {\n  params = params || {}\n  var gl = this.gl\n\n  this.dirty = true\n\n  if('contourEnable' in params) {\n    this.contourEnable = params.contourEnable\n  }\n  if('contourColor' in params) {\n    this.contourColor = params.contourColor\n  }\n  if('lineWidth' in params) {\n    this.lineWidth = params.lineWidth\n  }\n  if('lightPosition' in params) {\n    this.lightPosition = params.lightPosition\n  }\n  if('opacity' in params) {\n    this.opacity = params.opacity\n  }\n  if('ambient' in params) {\n    this.ambientLight  = params.ambient\n  }\n  if('diffuse' in params) {\n    this.diffuseLight = params.diffuse\n  }\n  if('specular' in params) {\n    this.specularLight = params.specular\n  }\n  if('roughness' in params) {\n    this.roughness = params.roughness\n  }\n  if('fresnel' in params) {\n    this.fresnel = params.fresnel\n  }\n\n  if (params.vectorScale !== undefined) {\n    this.vectorScale = params.vectorScale;\n  }\n  if (params.coneScale !== undefined) {\n    this.coneScale = params.coneScale;\n  }\n  if (params.coneOffset !== undefined) {\n    this.coneOffset = params.coneOffset;\n  }\n\n  if(params.texture) {\n    this.texture.dispose()\n    this.texture = createTexture(gl, params.texture)\n  } else if (params.colormap) {\n    this.texture.shape = [256,256]\n    this.texture.minFilter = gl.LINEAR_MIPMAP_LINEAR\n    this.texture.magFilter = gl.LINEAR\n    this.texture.setPixels(genColormap(params.colormap))\n    this.texture.generateMipmap()\n  }\n\n  var cells = params.cells\n  var positions = params.positions\n  var vectors = params.vectors\n\n  if(!positions || !cells || !vectors) {\n    return\n  }\n\n  var tPos = []\n  var tVec = []\n  var tCol = []\n  var tNor = []\n  var tUVs = []\n  var tIds = []\n\n  var ePos = []\n  var eCol = []\n  var eUVs = []\n  var eIds = []\n\n  var pPos = []\n  var pCol = []\n  var pUVs = []\n  var pSiz = []\n  var pIds = []\n\n  //Save geometry data for picking calculations\n  this.cells     = cells\n  this.positions = positions\n\n  //Compute normals\n  var vertexNormals = params.vertexNormals\n  var cellNormals   = params.cellNormals\n  var vertexNormalsEpsilon = params.vertexNormalsEpsilon === void(0) ? DEFAULT_VERTEX_NORMALS_EPSILON : params.vertexNormalsEpsilon\n  var faceNormalsEpsilon = params.faceNormalsEpsilon === void(0) ? DEFAULT_FACE_NORMALS_EPSILON : params.faceNormalsEpsilon\n  if(params.useFacetNormals && !cellNormals) {\n    cellNormals = normals.faceNormals(cells, positions, faceNormalsEpsilon)\n  }\n  if(!cellNormals && !vertexNormals) {\n    vertexNormals = normals.vertexNormals(cells, positions, vertexNormalsEpsilon)\n  }\n\n  //Compute colors\n  var vertexColors    = params.vertexColors\n  var cellColors      = params.cellColors\n  var meshColor       = params.meshColor || [1,1,1,1]\n\n  //UVs\n  var vertexUVs       = params.vertexUVs\n  var vertexIntensity = params.vertexIntensity\n  var cellUVs         = params.cellUVs\n  var cellIntensity   = params.cellIntensity\n\n  var intensityLo     = Infinity\n  var intensityHi     = -Infinity\n  if(!vertexUVs && !cellUVs) {\n    if(vertexIntensity) {\n      if(params.vertexIntensityBounds) {\n        intensityLo = +params.vertexIntensityBounds[0]\n        intensityHi = +params.vertexIntensityBounds[1]\n      } else {\n        for(var i=0; i<vertexIntensity.length; ++i) {\n          var f = vertexIntensity[i]\n          intensityLo = Math.min(intensityLo, f)\n          intensityHi = Math.max(intensityHi, f)\n        }\n      }\n    } else if(cellIntensity) {\n      for(var i=0; i<cellIntensity.length; ++i) {\n        var f = cellIntensity[i]\n        intensityLo = Math.min(intensityLo, f)\n        intensityHi = Math.max(intensityHi, f)\n      }\n    } else {\n      for(var i=0; i<positions.length; ++i) {\n        var f = positions[i][2]\n        intensityLo = Math.min(intensityLo, f)\n        intensityHi = Math.max(intensityHi, f)\n      }\n    }\n  }\n\n  if(vertexIntensity) {\n    this.intensity = vertexIntensity\n  } else if(cellIntensity) {\n    this.intensity = unpackIntensity(cells, positions.length, cellIntensity)\n  } else {\n    this.intensity = takeZComponent(positions)\n  }\n\n  //Point size\n  var pointSizes      = params.pointSizes\n  var meshPointSize   = params.pointSize || 1.0\n\n  //Update bounds\n  this.bounds       = [[Infinity,Infinity,Infinity], [-Infinity,-Infinity,-Infinity]]\n  for(var i=0; i<positions.length; ++i) {\n    var p = positions[i]\n    for(var j=0; j<3; ++j) {\n      if(isNaN(p[j]) || !isFinite(p[j])) {\n        continue\n      }\n      this.bounds[0][j] = Math.min(this.bounds[0][j], p[j])\n      this.bounds[1][j] = Math.max(this.bounds[1][j], p[j])\n    }\n  }\n\n  //Pack cells into buffers\n  var triangleCount = 0\n  var edgeCount = 0\n  var pointCount = 0\n\nfill_loop:\n  for(var i=0; i<cells.length; ++i) {\n    var cell = cells[i]\n    switch(cell.length) {\n      case 1:\n\n        var v = cell[0]\n        var p = positions[v]\n\n        //Check NaNs\n        for(var j=0; j<3; ++j) {\n          if(isNaN(p[j]) || !isFinite(p[j])) {\n            continue fill_loop\n          }\n        }\n\n        pPos.push(p[0], p[1], p[2], p[3])\n\n        var c\n        if(vertexColors) {\n          c = vertexColors[v]\n        } else if(cellColors) {\n          c = cellColors[i]\n        } else {\n          c = meshColor\n        }\n        if(c.length === 3) {\n          pCol.push(c[0], c[1], c[2], 1)\n        } else {\n          pCol.push(c[0], c[1], c[2], c[3])\n        }\n\n        var uv\n        if(vertexUVs) {\n          uv = vertexUVs[v]\n        } else if(vertexIntensity) {\n          uv = [\n            (vertexIntensity[v] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        } else if(cellUVs) {\n          uv = cellUVs[i]\n        } else if(cellIntensity) {\n          uv = [\n            (cellIntensity[i] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        } else {\n          uv = [\n            (p[2] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        }\n        pUVs.push(uv[0], uv[1])\n\n        if(pointSizes) {\n          pSiz.push(pointSizes[v])\n        } else {\n          pSiz.push(meshPointSize)\n        }\n\n        pIds.push(i)\n\n        pointCount += 1\n      break\n\n      case 2:\n\n        //Check NaNs\n        for(var j=0; j<2; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n          for(var k=0; k<3; ++k) {\n            if(isNaN(p[k]) || !isFinite(p[k])) {\n              continue fill_loop\n            }\n          }\n        }\n\n        for(var j=0; j<2; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n\n          ePos.push(p[0], p[1], p[2])\n\n          var c\n          if(vertexColors) {\n            c = vertexColors[v]\n          } else if(cellColors) {\n            c = cellColors[i]\n          } else {\n            c = meshColor\n          }\n          if(c.length === 3) {\n            eCol.push(c[0], c[1], c[2], 1)\n          } else {\n            eCol.push(c[0], c[1], c[2], c[3])\n          }\n\n          var uv\n          if(vertexUVs) {\n            uv = vertexUVs[v]\n          } else if(vertexIntensity) {\n            uv = [\n              (vertexIntensity[v] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else if(cellUVs) {\n            uv = cellUVs[i]\n          } else if(cellIntensity) {\n            uv = [\n              (cellIntensity[i] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else {\n            uv = [\n              (p[2] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          }\n          eUVs.push(uv[0], uv[1])\n\n          eIds.push(i)\n        }\n        edgeCount += 1\n      break\n\n      case 3:\n        //Check NaNs\n        for(var j=0; j<3; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n          for(var k=0; k<3; ++k) {\n            if(isNaN(p[k]) || !isFinite(p[k])) {\n              continue fill_loop\n            }\n          }\n        }\n\n        for(var j=0; j<3; ++j) {\n          var v = cell[2 - j]\n\n          var p = positions[v]\n          tPos.push(p[0], p[1], p[2], p[3])\n\n          var w = vectors[v]\n          tVec.push(w[0], w[1], w[2]);\n\n          var c\n          if(vertexColors) {\n            c = vertexColors[v]\n          } else if(cellColors) {\n            c = cellColors[i]\n          } else {\n            c = meshColor\n          }\n          if(c.length === 3) {\n            tCol.push(c[0], c[1], c[2], 1)\n          } else {\n            tCol.push(c[0], c[1], c[2], c[3])\n          }\n\n          var uv\n          if(vertexUVs) {\n            uv = vertexUVs[v]\n          } else if(vertexIntensity) {\n            uv = [\n              (vertexIntensity[v] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else if(cellUVs) {\n            uv = cellUVs[i]\n          } else if(cellIntensity) {\n            uv = [\n              (cellIntensity[i] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else {\n            uv = [\n              (p[2] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          }\n          tUVs.push(uv[0], uv[1])\n\n          var q\n          if(vertexNormals) {\n            q = vertexNormals[v]\n          } else {\n            q = cellNormals[i]\n          }\n          tNor.push(q[0], q[1], q[2])\n\n          tIds.push(i)\n        }\n        triangleCount += 1\n      break\n\n      default:\n      break\n    }\n  }\n\n  this.pointCount     = pointCount\n  this.edgeCount      = edgeCount\n  this.triangleCount  = triangleCount\n\n  this.pointPositions.update(pPos)\n  this.pointColors.update(pCol)\n  this.pointUVs.update(pUVs)\n  this.pointSizes.update(pSiz)\n  this.pointIds.update(new Uint32Array(pIds))\n\n  this.edgePositions.update(ePos)\n  this.edgeColors.update(eCol)\n  this.edgeUVs.update(eUVs)\n  this.edgeIds.update(new Uint32Array(eIds))\n\n  this.trianglePositions.update(tPos)\n  this.triangleVectors.update(tVec)\n  this.triangleColors.update(tCol)\n  this.triangleUVs.update(tUVs)\n  this.triangleNormals.update(tNor)\n  this.triangleIds.update(new Uint32Array(tIds))\n}\n\nproto.drawTransparent = proto.draw = function(params) {\n  params = params || {}\n  var gl          = this.gl\n  var model       = params.model      || IDENTITY\n  var view        = params.view       || IDENTITY\n  var projection  = params.projection || IDENTITY\n\n  var clipBounds = [[-1e6,-1e6,-1e6],[1e6,1e6,1e6]]\n  for(var i=0; i<3; ++i) {\n    clipBounds[0][i] = Math.max(clipBounds[0][i], this.clipBounds[0][i])\n    clipBounds[1][i] = Math.min(clipBounds[1][i], this.clipBounds[1][i])\n  }\n\n  var uniforms = {\n    model:      model,\n    view:       view,\n    projection: projection,\n    inverseModel: IDENTITY.slice(),\n\n    clipBounds: clipBounds,\n\n    kambient:   this.ambientLight,\n    kdiffuse:   this.diffuseLight,\n    kspecular:  this.specularLight,\n    roughness:  this.roughness,\n    fresnel:    this.fresnel,\n\n    eyePosition:   [0,0,0],\n    lightPosition: [0,0,0],\n\n    opacity:  this.opacity,\n\n    vectorScale: this.vectorScale,\n    coneScale: this.coneScale,\n    coneOffset: this.coneOffset,\n\n    contourColor: this.contourColor,\n\n    texture:    0\n  }\n\n  uniforms.inverseModel = invert(uniforms.inverseModel, uniforms.model)\n\n  gl.disable(gl.CULL_FACE)\n\n  this.texture.bind(0)\n\n  var invCameraMatrix = new Array(16)\n  multiply(invCameraMatrix, uniforms.view, uniforms.model)\n  multiply(invCameraMatrix, uniforms.projection, invCameraMatrix)\n  invert(invCameraMatrix, invCameraMatrix)\n\n  for(var i=0; i<3; ++i) {\n    uniforms.eyePosition[i] = invCameraMatrix[12+i] / invCameraMatrix[15]\n  }\n\n  var w = invCameraMatrix[15]\n  for(var i=0; i<3; ++i) {\n    w += this.lightPosition[i] * invCameraMatrix[4*i+3]\n  }\n  for(var i=0; i<3; ++i) {\n    var s = invCameraMatrix[12+i]\n    for(var j=0; j<3; ++j) {\n      s += invCameraMatrix[4*j+i] * this.lightPosition[j]\n    }\n    uniforms.lightPosition[i] = s / w\n  }\n\n  if(this.triangleCount > 0) {\n    var shader = this.triShader\n    shader.bind()\n    shader.uniforms = uniforms\n\n    this.triangleVAO.bind()\n    gl.drawArrays(gl.TRIANGLES, 0, this.triangleCount*3)\n    this.triangleVAO.unbind()\n  }\n}\nproto.drawPick = function(params) {\n  params = params || {}\n\n  var gl         = this.gl\n\n  var model      = params.model      || IDENTITY\n  var view       = params.view       || IDENTITY\n  var projection = params.projection || IDENTITY\n\n  var clipBounds = [[-1e6,-1e6,-1e6],[1e6,1e6,1e6]]\n  for(var i=0; i<3; ++i) {\n    clipBounds[0][i] = Math.max(clipBounds[0][i], this.clipBounds[0][i])\n    clipBounds[1][i] = Math.min(clipBounds[1][i], this.clipBounds[1][i])\n  }\n\n  //Save camera parameters\n  this._model      = [].slice.call(model)\n  this._view       = [].slice.call(view)\n  this._projection = [].slice.call(projection)\n  this._resolution = [gl.drawingBufferWidth, gl.drawingBufferHeight]\n\n  var uniforms = {\n    model:      model,\n    view:       view,\n    projection: projection,\n    clipBounds: clipBounds,\n\n    vectorScale: this.vectorScale,\n    coneScale: this.coneScale,\n    coneOffset: this.coneOffset,\n\n    pickId:     this.pickId / 255.0,\n  }\n\n  var shader = this.pickShader\n  shader.bind()\n  shader.uniforms = uniforms\n\n  if(this.triangleCount > 0) {\n    this.triangleVAO.bind()\n    gl.drawArrays(gl.TRIANGLES, 0, this.triangleCount*3)\n    this.triangleVAO.unbind()\n  }\n\n  if(this.edgeCount > 0) {\n    this.edgeVAO.bind()\n    gl.lineWidth(this.lineWidth * this.pixelRatio)\n    gl.drawArrays(gl.LINES, 0, this.edgeCount*2)\n    this.edgeVAO.unbind()\n  }\n\n}\n\n\nproto.pick = function(pickData) {\n  if(!pickData) {\n    return null\n  }\n  if(pickData.id !== this.pickId) {\n    return null\n  }\n\n  var cellId    = pickData.value[0] + 256*pickData.value[1] + 65536*pickData.value[2]\n  var cell      = this.cells[cellId]\n  var pos =     this.positions[cell[1]].slice(0, 3)\n\n  return {\n    // corresponding to input indices\n    index: Math.floor(cell[1] / 48),\n    position: pos,\n    dataCoordinate: pos\n  }\n}\n\n\nproto.dispose = function() {\n  this.texture.dispose()\n\n  this.triShader.dispose()\n  this.pickShader.dispose()\n\n  this.triangleVAO.dispose()\n  this.trianglePositions.dispose()\n  this.triangleVectors.dispose()\n  this.triangleColors.dispose()\n  this.triangleUVs.dispose()\n  this.triangleNormals.dispose()\n  this.triangleIds.dispose()\n\n  this.edgeVAO.dispose()\n  this.edgePositions.dispose()\n  this.edgeColors.dispose()\n  this.edgeUVs.dispose()\n  this.edgeIds.dispose()\n\n  this.pointVAO.dispose()\n  this.pointPositions.dispose()\n  this.pointColors.dispose()\n  this.pointUVs.dispose()\n  this.pointSizes.dispose()\n  this.pointIds.dispose()\n\n  this.contourVAO.dispose()\n  this.contourPositions.dispose()\n}\n\nfunction createMeshShader(gl) {\n  // need to pass meshShader attributes manually,\n  // to make this work on etpinard's Ubuntu Thinkpad\n  var shader = createShader(gl, meshShader.vertex, meshShader.fragment, null, meshShader.attributes)\n  shader.attributes.position.location = 0\n  shader.attributes.color.location    = 2\n  shader.attributes.uv.location       = 3\n  shader.attributes.vector.location   = 5\n  return shader\n}\n\n\nfunction createPickShader(gl) {\n  var shader = createShader(gl, pickShader.vertex, pickShader.fragment, null, pickShader.attributes)\n  shader.attributes.position.location = 0\n  shader.attributes.id.location       = 1\n  shader.attributes.vector.location   = 5\n  return shader\n}\n\n\n\nfunction createSimplicialMesh(gl, params) {\n  if (arguments.length === 1) {\n    params = gl;\n    gl = params.gl;\n  }\n\n\n  var triShader       = params.triShader || createMeshShader(gl)\n  var pickShader      = createPickShader(gl)\n  var meshTexture       = createTexture(gl,\n    ndarray(new Uint8Array([255,255,255,255]), [1,1,4]))\n  meshTexture.generateMipmap()\n  meshTexture.minFilter = gl.LINEAR_MIPMAP_LINEAR\n  meshTexture.magFilter = gl.LINEAR\n\n  var trianglePositions = createBuffer(gl)\n  var triangleVectors   = createBuffer(gl)\n  var triangleColors    = createBuffer(gl)\n  var triangleUVs       = createBuffer(gl)\n  var triangleNormals   = createBuffer(gl)\n  var triangleIds       = createBuffer(gl)\n  var triangleVAO       = createVAO(gl, [\n    { buffer: trianglePositions,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: triangleIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: triangleColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: triangleUVs,\n      type: gl.FLOAT,\n      size: 2\n    },\n    { buffer: triangleNormals,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: triangleVectors,\n      type: gl.FLOAT,\n      size: 3\n    }\n  ])\n\n  var edgePositions = createBuffer(gl)\n  var edgeColors    = createBuffer(gl)\n  var edgeUVs       = createBuffer(gl)\n  var edgeIds       = createBuffer(gl)\n  var edgeVAO       = createVAO(gl, [\n    { buffer: edgePositions,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: edgeIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: edgeColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: edgeUVs,\n      type: gl.FLOAT,\n      size: 2\n    }\n  ])\n\n  var pointPositions  = createBuffer(gl)\n  var pointColors     = createBuffer(gl)\n  var pointUVs        = createBuffer(gl)\n  var pointSizes      = createBuffer(gl)\n  var pointIds        = createBuffer(gl)\n  var pointVAO        = createVAO(gl, [\n    { buffer: pointPositions,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: pointIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: pointColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: pointUVs,\n      type: gl.FLOAT,\n      size: 2\n    },\n    { buffer: pointSizes,\n      type: gl.FLOAT,\n      size: 1\n    }\n  ])\n\n  var contourPositions = createBuffer(gl)\n  var contourVAO       = createVAO(gl, [\n    { buffer: contourPositions,\n      type:   gl.FLOAT,\n      size:   3\n    }])\n\n  var mesh = new SimplicialMesh(gl\n    , meshTexture\n    , triShader\n    , pickShader\n    , trianglePositions\n    , triangleVectors\n    , triangleIds\n    , triangleColors\n    , triangleUVs\n    , triangleNormals\n    , triangleVAO\n    , edgePositions\n    , edgeIds\n    , edgeColors\n    , edgeUVs\n    , edgeVAO\n    , pointPositions\n    , pointIds\n    , pointColors\n    , pointUVs\n    , pointSizes\n    , pointVAO\n    , contourPositions\n    , contourVAO)\n\n  mesh.update(params)\n\n  return mesh\n}\n\nmodule.exports = createSimplicialMesh\n\n},{\"./shaders\":244,\"colormap\":126,\"gl-buffer\":241,\"gl-mat4/invert\":265,\"gl-mat4/multiply\":267,\"gl-shader\":301,\"gl-texture2d\":322,\"gl-vao\":327,\"ndarray\":450,\"normals\":453,\"simplicial-complex-contour\":518,\"typedarray-pool\":545}],244:[function(_dereq_,module,exports){\nvar glslify       = _dereq_('glslify')\n\nvar triVertSrc = glslify([\"precision highp float;\\n\\nprecision highp float;\\n#define GLSLIFY 1\\n\\nvec3 getOrthogonalVector(vec3 v) {\\n  // Return up-vector for only-z vector.\\n  // Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\\n  // From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\\n  // Assign z = 0, x = -b, y = a:\\n  // a*-b + b*a + c*0 = -ba + ba + 0 = 0\\n  if (v.x*v.x > v.z*v.z || v.y*v.y > v.z*v.z) {\\n    return normalize(vec3(-v.y, v.x, 0.0));\\n  } else {\\n    return normalize(vec3(0.0, v.z, -v.y));\\n  }\\n}\\n\\n// Calculate the cone vertex and normal at the given index.\\n//\\n// The returned vertex is for a cone with its top at origin and height of 1.0,\\n// pointing in the direction of the vector attribute.\\n//\\n// Each cone is made up of a top vertex, a center base vertex and base perimeter vertices.\\n// These vertices are used to make up the triangles of the cone by the following:\\n//   segment + 0 top vertex\\n//   segment + 1 perimeter vertex a+1\\n//   segment + 2 perimeter vertex a\\n//   segment + 3 center base vertex\\n//   segment + 4 perimeter vertex a\\n//   segment + 5 perimeter vertex a+1\\n// Where segment is the number of the radial segment * 6 and a is the angle at that radial segment.\\n// To go from index to segment, floor(index / 6)\\n// To go from segment to angle, 2*pi * (segment/segmentCount)\\n// To go from index to segment index, index - (segment*6)\\n//\\nvec3 getConePosition(vec3 d, float rawIndex, float coneOffset, out vec3 normal) {\\n\\n  const float segmentCount = 8.0;\\n\\n  float index = rawIndex - floor(rawIndex /\\n    (segmentCount * 6.0)) *\\n    (segmentCount * 6.0);\\n\\n  float segment = floor(0.001 + index/6.0);\\n  float segmentIndex = index - (segment*6.0);\\n\\n  normal = -normalize(d);\\n\\n  if (segmentIndex > 2.99 && segmentIndex < 3.01) {\\n    return mix(vec3(0.0), -d, coneOffset);\\n  }\\n\\n  float nextAngle = (\\n    (segmentIndex > 0.99 &&  segmentIndex < 1.01) ||\\n    (segmentIndex > 4.99 &&  segmentIndex < 5.01)\\n  ) ? 1.0 : 0.0;\\n  float angle = 2.0 * 3.14159 * ((segment + nextAngle) / segmentCount);\\n\\n  vec3 v1 = mix(d, vec3(0.0), coneOffset);\\n  vec3 v2 = v1 - d;\\n\\n  vec3 u = getOrthogonalVector(d);\\n  vec3 v = normalize(cross(u, d));\\n\\n  vec3 x = u * cos(angle) * length(d)*0.25;\\n  vec3 y = v * sin(angle) * length(d)*0.25;\\n  vec3 v3 = v2 + x + y;\\n  if (segmentIndex < 3.0) {\\n    vec3 tx = u * sin(angle);\\n    vec3 ty = v * -cos(angle);\\n    vec3 tangent = tx + ty;\\n    normal = normalize(cross(v3 - v1, tangent));\\n  }\\n\\n  if (segmentIndex == 0.0) {\\n    return mix(d, vec3(0.0), coneOffset);\\n  }\\n  return v3;\\n}\\n\\nattribute vec3 vector;\\nattribute vec4 color, position;\\nattribute vec2 uv;\\nuniform float vectorScale;\\nuniform float coneScale;\\n\\nuniform float coneOffset;\\n\\nuniform mat4 model\\n           , view\\n           , projection\\n           , inverseModel;\\nuniform vec3 eyePosition\\n           , lightPosition;\\n\\nvarying vec3 f_normal\\n           , f_lightDirection\\n           , f_eyeDirection\\n           , f_data\\n           , f_position;\\nvarying vec4 f_color;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  // Scale the vector magnitude to stay constant with\\n  // model & view changes.\\n  vec3 normal;\\n  vec3 XYZ = getConePosition(mat3(model) * ((vectorScale * coneScale) * vector), position.w, coneOffset, normal);\\n  vec4 conePosition = model * vec4(position.xyz, 1.0) + vec4(XYZ, 0.0);\\n\\n  //Lighting geometry parameters\\n  vec4 cameraCoordinate = view * conePosition;\\n  cameraCoordinate.xyz /= cameraCoordinate.w;\\n  f_lightDirection = lightPosition - cameraCoordinate.xyz;\\n  f_eyeDirection   = eyePosition - cameraCoordinate.xyz;\\n  f_normal = normalize((vec4(normal,0.0) * inverseModel).xyz);\\n\\n  // vec4 m_position  = model * vec4(conePosition, 1.0);\\n  vec4 t_position  = view * conePosition;\\n  gl_Position      = projection * t_position;\\n\\n  f_color          = color;\\n  f_data           = conePosition.xyz;\\n  f_position       = position.xyz;\\n  f_uv             = uv;\\n}\\n\"])\nvar triFragSrc = glslify([\"#extension GL_OES_standard_derivatives : enable\\n\\nprecision highp float;\\n#define GLSLIFY 1\\n\\nfloat beckmannDistribution(float x, float roughness) {\\n  float NdotH = max(x, 0.0001);\\n  float cos2Alpha = NdotH * NdotH;\\n  float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;\\n  float roughness2 = roughness * roughness;\\n  float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;\\n  return exp(tan2Alpha / roughness2) / denom;\\n}\\n\\nfloat cookTorranceSpecular(\\n  vec3 lightDirection,\\n  vec3 viewDirection,\\n  vec3 surfaceNormal,\\n  float roughness,\\n  float fresnel) {\\n\\n  float VdotN = max(dot(viewDirection, surfaceNormal), 0.0);\\n  float LdotN = max(dot(lightDirection, surfaceNormal), 0.0);\\n\\n  //Half angle vector\\n  vec3 H = normalize(lightDirection + viewDirection);\\n\\n  //Geometric term\\n  float NdotH = max(dot(surfaceNormal, H), 0.0);\\n  float VdotH = max(dot(viewDirection, H), 0.000001);\\n  float LdotH = max(dot(lightDirection, H), 0.000001);\\n  float G1 = (2.0 * NdotH * VdotN) / VdotH;\\n  float G2 = (2.0 * NdotH * LdotN) / LdotH;\\n  float G = min(1.0, min(G1, G2));\\n  \\n  //Distribution term\\n  float D = beckmannDistribution(NdotH, roughness);\\n\\n  //Fresnel term\\n  float F = pow(1.0 - VdotN, fresnel);\\n\\n  //Multiply terms and done\\n  return  G * F * D / max(3.14159265 * VdotN, 0.000001);\\n}\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3 clipBounds[2];\\nuniform float roughness\\n            , fresnel\\n            , kambient\\n            , kdiffuse\\n            , kspecular\\n            , opacity;\\nuniform sampler2D texture;\\n\\nvarying vec3 f_normal\\n           , f_lightDirection\\n           , f_eyeDirection\\n           , f_data\\n           , f_position;\\nvarying vec4 f_color;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\\n  vec3 N = normalize(f_normal);\\n  vec3 L = normalize(f_lightDirection);\\n  vec3 V = normalize(f_eyeDirection);\\n\\n  if(gl_FrontFacing) {\\n    N = -N;\\n  }\\n\\n  float specular = min(1.0, max(0.0, cookTorranceSpecular(L, V, N, roughness, fresnel)));\\n  float diffuse  = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);\\n\\n  vec4 surfaceColor = f_color * texture2D(texture, f_uv);\\n  vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular,  1.0);\\n\\n  gl_FragColor = litColor * opacity;\\n}\\n\"])\nvar pickVertSrc = glslify([\"precision highp float;\\n\\nprecision highp float;\\n#define GLSLIFY 1\\n\\nvec3 getOrthogonalVector(vec3 v) {\\n  // Return up-vector for only-z vector.\\n  // Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\\n  // From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\\n  // Assign z = 0, x = -b, y = a:\\n  // a*-b + b*a + c*0 = -ba + ba + 0 = 0\\n  if (v.x*v.x > v.z*v.z || v.y*v.y > v.z*v.z) {\\n    return normalize(vec3(-v.y, v.x, 0.0));\\n  } else {\\n    return normalize(vec3(0.0, v.z, -v.y));\\n  }\\n}\\n\\n// Calculate the cone vertex and normal at the given index.\\n//\\n// The returned vertex is for a cone with its top at origin and height of 1.0,\\n// pointing in the direction of the vector attribute.\\n//\\n// Each cone is made up of a top vertex, a center base vertex and base perimeter vertices.\\n// These vertices are used to make up the triangles of the cone by the following:\\n//   segment + 0 top vertex\\n//   segment + 1 perimeter vertex a+1\\n//   segment + 2 perimeter vertex a\\n//   segment + 3 center base vertex\\n//   segment + 4 perimeter vertex a\\n//   segment + 5 perimeter vertex a+1\\n// Where segment is the number of the radial segment * 6 and a is the angle at that radial segment.\\n// To go from index to segment, floor(index / 6)\\n// To go from segment to angle, 2*pi * (segment/segmentCount)\\n// To go from index to segment index, index - (segment*6)\\n//\\nvec3 getConePosition(vec3 d, float rawIndex, float coneOffset, out vec3 normal) {\\n\\n  const float segmentCount = 8.0;\\n\\n  float index = rawIndex - floor(rawIndex /\\n    (segmentCount * 6.0)) *\\n    (segmentCount * 6.0);\\n\\n  float segment = floor(0.001 + index/6.0);\\n  float segmentIndex = index - (segment*6.0);\\n\\n  normal = -normalize(d);\\n\\n  if (segmentIndex > 2.99 && segmentIndex < 3.01) {\\n    return mix(vec3(0.0), -d, coneOffset);\\n  }\\n\\n  float nextAngle = (\\n    (segmentIndex > 0.99 &&  segmentIndex < 1.01) ||\\n    (segmentIndex > 4.99 &&  segmentIndex < 5.01)\\n  ) ? 1.0 : 0.0;\\n  float angle = 2.0 * 3.14159 * ((segment + nextAngle) / segmentCount);\\n\\n  vec3 v1 = mix(d, vec3(0.0), coneOffset);\\n  vec3 v2 = v1 - d;\\n\\n  vec3 u = getOrthogonalVector(d);\\n  vec3 v = normalize(cross(u, d));\\n\\n  vec3 x = u * cos(angle) * length(d)*0.25;\\n  vec3 y = v * sin(angle) * length(d)*0.25;\\n  vec3 v3 = v2 + x + y;\\n  if (segmentIndex < 3.0) {\\n    vec3 tx = u * sin(angle);\\n    vec3 ty = v * -cos(angle);\\n    vec3 tangent = tx + ty;\\n    normal = normalize(cross(v3 - v1, tangent));\\n  }\\n\\n  if (segmentIndex == 0.0) {\\n    return mix(d, vec3(0.0), coneOffset);\\n  }\\n  return v3;\\n}\\n\\nattribute vec3 vector;\\nattribute vec4 position;\\nattribute vec4 id;\\n\\nuniform mat4 model, view, projection;\\n\\nuniform float vectorScale;\\nuniform float coneScale;\\nuniform float coneOffset;\\n\\nvarying vec3 f_position;\\nvarying vec4 f_id;\\n\\nvoid main() {\\n  vec3 normal;\\n  vec3 XYZ = getConePosition(mat3(model) * ((vectorScale * coneScale) * vector), position.w, coneOffset, normal);\\n  vec4 conePosition = model * vec4(position.xyz, 1.0) + vec4(XYZ, 0.0);\\n  gl_Position = projection * view * conePosition;\\n  f_id        = id;\\n  f_position  = position.xyz;\\n}\\n\"])\nvar pickFragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3  clipBounds[2];\\nuniform float pickId;\\n\\nvarying vec3 f_position;\\nvarying vec4 f_id;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\\n\\n  gl_FragColor = vec4(pickId, f_id.xyz);\\n}\"])\n\nexports.meshShader = {\n  vertex:   triVertSrc,\n  fragment: triFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec4'},\n    {name: 'normal', type: 'vec3'},\n    {name: 'color', type: 'vec4'},\n    {name: 'uv', type: 'vec2'},\n    {name: 'vector', type: 'vec3'}\n  ]\n}\nexports.pickShader = {\n  vertex:   pickVertSrc,\n  fragment: pickFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec4'},\n    {name: 'id', type: 'vec4'},\n    {name: 'vector', type: 'vec3'}\n  ]\n}\n\n},{\"glslify\":409}],245:[function(_dereq_,module,exports){\nmodule.exports = {\n  0: 'NONE',\n  1: 'ONE',\n  2: 'LINE_LOOP',\n  3: 'LINE_STRIP',\n  4: 'TRIANGLES',\n  5: 'TRIANGLE_STRIP',\n  6: 'TRIANGLE_FAN',\n  256: 'DEPTH_BUFFER_BIT',\n  512: 'NEVER',\n  513: 'LESS',\n  514: 'EQUAL',\n  515: 'LEQUAL',\n  516: 'GREATER',\n  517: 'NOTEQUAL',\n  518: 'GEQUAL',\n  519: 'ALWAYS',\n  768: 'SRC_COLOR',\n  769: 'ONE_MINUS_SRC_COLOR',\n  770: 'SRC_ALPHA',\n  771: 'ONE_MINUS_SRC_ALPHA',\n  772: 'DST_ALPHA',\n  773: 'ONE_MINUS_DST_ALPHA',\n  774: 'DST_COLOR',\n  775: 'ONE_MINUS_DST_COLOR',\n  776: 'SRC_ALPHA_SATURATE',\n  1024: 'STENCIL_BUFFER_BIT',\n  1028: 'FRONT',\n  1029: 'BACK',\n  1032: 'FRONT_AND_BACK',\n  1280: 'INVALID_ENUM',\n  1281: 'INVALID_VALUE',\n  1282: 'INVALID_OPERATION',\n  1285: 'OUT_OF_MEMORY',\n  1286: 'INVALID_FRAMEBUFFER_OPERATION',\n  2304: 'CW',\n  2305: 'CCW',\n  2849: 'LINE_WIDTH',\n  2884: 'CULL_FACE',\n  2885: 'CULL_FACE_MODE',\n  2886: 'FRONT_FACE',\n  2928: 'DEPTH_RANGE',\n  2929: 'DEPTH_TEST',\n  2930: 'DEPTH_WRITEMASK',\n  2931: 'DEPTH_CLEAR_VALUE',\n  2932: 'DEPTH_FUNC',\n  2960: 'STENCIL_TEST',\n  2961: 'STENCIL_CLEAR_VALUE',\n  2962: 'STENCIL_FUNC',\n  2963: 'STENCIL_VALUE_MASK',\n  2964: 'STENCIL_FAIL',\n  2965: 'STENCIL_PASS_DEPTH_FAIL',\n  2966: 'STENCIL_PASS_DEPTH_PASS',\n  2967: 'STENCIL_REF',\n  2968: 'STENCIL_WRITEMASK',\n  2978: 'VIEWPORT',\n  3024: 'DITHER',\n  3042: 'BLEND',\n  3088: 'SCISSOR_BOX',\n  3089: 'SCISSOR_TEST',\n  3106: 'COLOR_CLEAR_VALUE',\n  3107: 'COLOR_WRITEMASK',\n  3317: 'UNPACK_ALIGNMENT',\n  3333: 'PACK_ALIGNMENT',\n  3379: 'MAX_TEXTURE_SIZE',\n  3386: 'MAX_VIEWPORT_DIMS',\n  3408: 'SUBPIXEL_BITS',\n  3410: 'RED_BITS',\n  3411: 'GREEN_BITS',\n  3412: 'BLUE_BITS',\n  3413: 'ALPHA_BITS',\n  3414: 'DEPTH_BITS',\n  3415: 'STENCIL_BITS',\n  3553: 'TEXTURE_2D',\n  4352: 'DONT_CARE',\n  4353: 'FASTEST',\n  4354: 'NICEST',\n  5120: 'BYTE',\n  5121: 'UNSIGNED_BYTE',\n  5122: 'SHORT',\n  5123: 'UNSIGNED_SHORT',\n  5124: 'INT',\n  5125: 'UNSIGNED_INT',\n  5126: 'FLOAT',\n  5386: 'INVERT',\n  5890: 'TEXTURE',\n  6401: 'STENCIL_INDEX',\n  6402: 'DEPTH_COMPONENT',\n  6406: 'ALPHA',\n  6407: 'RGB',\n  6408: 'RGBA',\n  6409: 'LUMINANCE',\n  6410: 'LUMINANCE_ALPHA',\n  7680: 'KEEP',\n  7681: 'REPLACE',\n  7682: 'INCR',\n  7683: 'DECR',\n  7936: 'VENDOR',\n  7937: 'RENDERER',\n  7938: 'VERSION',\n  9728: 'NEAREST',\n  9729: 'LINEAR',\n  9984: 'NEAREST_MIPMAP_NEAREST',\n  9985: 'LINEAR_MIPMAP_NEAREST',\n  9986: 'NEAREST_MIPMAP_LINEAR',\n  9987: 'LINEAR_MIPMAP_LINEAR',\n  10240: 'TEXTURE_MAG_FILTER',\n  10241: 'TEXTURE_MIN_FILTER',\n  10242: 'TEXTURE_WRAP_S',\n  10243: 'TEXTURE_WRAP_T',\n  10497: 'REPEAT',\n  10752: 'POLYGON_OFFSET_UNITS',\n  16384: 'COLOR_BUFFER_BIT',\n  32769: 'CONSTANT_COLOR',\n  32770: 'ONE_MINUS_CONSTANT_COLOR',\n  32771: 'CONSTANT_ALPHA',\n  32772: 'ONE_MINUS_CONSTANT_ALPHA',\n  32773: 'BLEND_COLOR',\n  32774: 'FUNC_ADD',\n  32777: 'BLEND_EQUATION_RGB',\n  32778: 'FUNC_SUBTRACT',\n  32779: 'FUNC_REVERSE_SUBTRACT',\n  32819: 'UNSIGNED_SHORT_4_4_4_4',\n  32820: 'UNSIGNED_SHORT_5_5_5_1',\n  32823: 'POLYGON_OFFSET_FILL',\n  32824: 'POLYGON_OFFSET_FACTOR',\n  32854: 'RGBA4',\n  32855: 'RGB5_A1',\n  32873: 'TEXTURE_BINDING_2D',\n  32926: 'SAMPLE_ALPHA_TO_COVERAGE',\n  32928: 'SAMPLE_COVERAGE',\n  32936: 'SAMPLE_BUFFERS',\n  32937: 'SAMPLES',\n  32938: 'SAMPLE_COVERAGE_VALUE',\n  32939: 'SAMPLE_COVERAGE_INVERT',\n  32968: 'BLEND_DST_RGB',\n  32969: 'BLEND_SRC_RGB',\n  32970: 'BLEND_DST_ALPHA',\n  32971: 'BLEND_SRC_ALPHA',\n  33071: 'CLAMP_TO_EDGE',\n  33170: 'GENERATE_MIPMAP_HINT',\n  33189: 'DEPTH_COMPONENT16',\n  33306: 'DEPTH_STENCIL_ATTACHMENT',\n  33635: 'UNSIGNED_SHORT_5_6_5',\n  33648: 'MIRRORED_REPEAT',\n  33901: 'ALIASED_POINT_SIZE_RANGE',\n  33902: 'ALIASED_LINE_WIDTH_RANGE',\n  33984: 'TEXTURE0',\n  33985: 'TEXTURE1',\n  33986: 'TEXTURE2',\n  33987: 'TEXTURE3',\n  33988: 'TEXTURE4',\n  33989: 'TEXTURE5',\n  33990: 'TEXTURE6',\n  33991: 'TEXTURE7',\n  33992: 'TEXTURE8',\n  33993: 'TEXTURE9',\n  33994: 'TEXTURE10',\n  33995: 'TEXTURE11',\n  33996: 'TEXTURE12',\n  33997: 'TEXTURE13',\n  33998: 'TEXTURE14',\n  33999: 'TEXTURE15',\n  34000: 'TEXTURE16',\n  34001: 'TEXTURE17',\n  34002: 'TEXTURE18',\n  34003: 'TEXTURE19',\n  34004: 'TEXTURE20',\n  34005: 'TEXTURE21',\n  34006: 'TEXTURE22',\n  34007: 'TEXTURE23',\n  34008: 'TEXTURE24',\n  34009: 'TEXTURE25',\n  34010: 'TEXTURE26',\n  34011: 'TEXTURE27',\n  34012: 'TEXTURE28',\n  34013: 'TEXTURE29',\n  34014: 'TEXTURE30',\n  34015: 'TEXTURE31',\n  34016: 'ACTIVE_TEXTURE',\n  34024: 'MAX_RENDERBUFFER_SIZE',\n  34041: 'DEPTH_STENCIL',\n  34055: 'INCR_WRAP',\n  34056: 'DECR_WRAP',\n  34067: 'TEXTURE_CUBE_MAP',\n  34068: 'TEXTURE_BINDING_CUBE_MAP',\n  34069: 'TEXTURE_CUBE_MAP_POSITIVE_X',\n  34070: 'TEXTURE_CUBE_MAP_NEGATIVE_X',\n  34071: 'TEXTURE_CUBE_MAP_POSITIVE_Y',\n  34072: 'TEXTURE_CUBE_MAP_NEGATIVE_Y',\n  34073: 'TEXTURE_CUBE_MAP_POSITIVE_Z',\n  34074: 'TEXTURE_CUBE_MAP_NEGATIVE_Z',\n  34076: 'MAX_CUBE_MAP_TEXTURE_SIZE',\n  34338: 'VERTEX_ATTRIB_ARRAY_ENABLED',\n  34339: 'VERTEX_ATTRIB_ARRAY_SIZE',\n  34340: 'VERTEX_ATTRIB_ARRAY_STRIDE',\n  34341: 'VERTEX_ATTRIB_ARRAY_TYPE',\n  34342: 'CURRENT_VERTEX_ATTRIB',\n  34373: 'VERTEX_ATTRIB_ARRAY_POINTER',\n  34466: 'NUM_COMPRESSED_TEXTURE_FORMATS',\n  34467: 'COMPRESSED_TEXTURE_FORMATS',\n  34660: 'BUFFER_SIZE',\n  34661: 'BUFFER_USAGE',\n  34816: 'STENCIL_BACK_FUNC',\n  34817: 'STENCIL_BACK_FAIL',\n  34818: 'STENCIL_BACK_PASS_DEPTH_FAIL',\n  34819: 'STENCIL_BACK_PASS_DEPTH_PASS',\n  34877: 'BLEND_EQUATION_ALPHA',\n  34921: 'MAX_VERTEX_ATTRIBS',\n  34922: 'VERTEX_ATTRIB_ARRAY_NORMALIZED',\n  34930: 'MAX_TEXTURE_IMAGE_UNITS',\n  34962: 'ARRAY_BUFFER',\n  34963: 'ELEMENT_ARRAY_BUFFER',\n  34964: 'ARRAY_BUFFER_BINDING',\n  34965: 'ELEMENT_ARRAY_BUFFER_BINDING',\n  34975: 'VERTEX_ATTRIB_ARRAY_BUFFER_BINDING',\n  35040: 'STREAM_DRAW',\n  35044: 'STATIC_DRAW',\n  35048: 'DYNAMIC_DRAW',\n  35632: 'FRAGMENT_SHADER',\n  35633: 'VERTEX_SHADER',\n  35660: 'MAX_VERTEX_TEXTURE_IMAGE_UNITS',\n  35661: 'MAX_COMBINED_TEXTURE_IMAGE_UNITS',\n  35663: 'SHADER_TYPE',\n  35664: 'FLOAT_VEC2',\n  35665: 'FLOAT_VEC3',\n  35666: 'FLOAT_VEC4',\n  35667: 'INT_VEC2',\n  35668: 'INT_VEC3',\n  35669: 'INT_VEC4',\n  35670: 'BOOL',\n  35671: 'BOOL_VEC2',\n  35672: 'BOOL_VEC3',\n  35673: 'BOOL_VEC4',\n  35674: 'FLOAT_MAT2',\n  35675: 'FLOAT_MAT3',\n  35676: 'FLOAT_MAT4',\n  35678: 'SAMPLER_2D',\n  35680: 'SAMPLER_CUBE',\n  35712: 'DELETE_STATUS',\n  35713: 'COMPILE_STATUS',\n  35714: 'LINK_STATUS',\n  35715: 'VALIDATE_STATUS',\n  35716: 'INFO_LOG_LENGTH',\n  35717: 'ATTACHED_SHADERS',\n  35718: 'ACTIVE_UNIFORMS',\n  35719: 'ACTIVE_UNIFORM_MAX_LENGTH',\n  35720: 'SHADER_SOURCE_LENGTH',\n  35721: 'ACTIVE_ATTRIBUTES',\n  35722: 'ACTIVE_ATTRIBUTE_MAX_LENGTH',\n  35724: 'SHADING_LANGUAGE_VERSION',\n  35725: 'CURRENT_PROGRAM',\n  36003: 'STENCIL_BACK_REF',\n  36004: 'STENCIL_BACK_VALUE_MASK',\n  36005: 'STENCIL_BACK_WRITEMASK',\n  36006: 'FRAMEBUFFER_BINDING',\n  36007: 'RENDERBUFFER_BINDING',\n  36048: 'FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE',\n  36049: 'FRAMEBUFFER_ATTACHMENT_OBJECT_NAME',\n  36050: 'FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL',\n  36051: 'FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE',\n  36053: 'FRAMEBUFFER_COMPLETE',\n  36054: 'FRAMEBUFFER_INCOMPLETE_ATTACHMENT',\n  36055: 'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT',\n  36057: 'FRAMEBUFFER_INCOMPLETE_DIMENSIONS',\n  36061: 'FRAMEBUFFER_UNSUPPORTED',\n  36064: 'COLOR_ATTACHMENT0',\n  36096: 'DEPTH_ATTACHMENT',\n  36128: 'STENCIL_ATTACHMENT',\n  36160: 'FRAMEBUFFER',\n  36161: 'RENDERBUFFER',\n  36162: 'RENDERBUFFER_WIDTH',\n  36163: 'RENDERBUFFER_HEIGHT',\n  36164: 'RENDERBUFFER_INTERNAL_FORMAT',\n  36168: 'STENCIL_INDEX8',\n  36176: 'RENDERBUFFER_RED_SIZE',\n  36177: 'RENDERBUFFER_GREEN_SIZE',\n  36178: 'RENDERBUFFER_BLUE_SIZE',\n  36179: 'RENDERBUFFER_ALPHA_SIZE',\n  36180: 'RENDERBUFFER_DEPTH_SIZE',\n  36181: 'RENDERBUFFER_STENCIL_SIZE',\n  36194: 'RGB565',\n  36336: 'LOW_FLOAT',\n  36337: 'MEDIUM_FLOAT',\n  36338: 'HIGH_FLOAT',\n  36339: 'LOW_INT',\n  36340: 'MEDIUM_INT',\n  36341: 'HIGH_INT',\n  36346: 'SHADER_COMPILER',\n  36347: 'MAX_VERTEX_UNIFORM_VECTORS',\n  36348: 'MAX_VARYING_VECTORS',\n  36349: 'MAX_FRAGMENT_UNIFORM_VECTORS',\n  37440: 'UNPACK_FLIP_Y_WEBGL',\n  37441: 'UNPACK_PREMULTIPLY_ALPHA_WEBGL',\n  37442: 'CONTEXT_LOST_WEBGL',\n  37443: 'UNPACK_COLORSPACE_CONVERSION_WEBGL',\n  37444: 'BROWSER_DEFAULT_WEBGL'\n}\n\n},{}],246:[function(_dereq_,module,exports){\nvar gl10 = _dereq_('./1.0/numbers')\n\nmodule.exports = function lookupConstant (number) {\n  return gl10[number]\n}\n\n},{\"./1.0/numbers\":245}],247:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createErrorBars\n\nvar createBuffer  = _dereq_('gl-buffer')\nvar createVAO     = _dereq_('gl-vao')\nvar createShader  = _dereq_('./shaders/index')\n\nvar IDENTITY = [1,0,0,0,\n                0,1,0,0,\n                0,0,1,0,\n                0,0,0,1]\n\nfunction ErrorBars(gl, buffer, vao, shader) {\n  this.gl           = gl\n  this.shader       = shader\n  this.buffer       = buffer\n  this.vao          = vao\n  this.pixelRatio   = 1\n  this.bounds       = [[ Infinity, Infinity, Infinity], [-Infinity,-Infinity,-Infinity]]\n  this.clipBounds   = [[-Infinity,-Infinity,-Infinity], [ Infinity, Infinity, Infinity]]\n  this.lineWidth    = [1,1,1]\n  this.capSize      = [10,10,10]\n  this.lineCount    = [0,0,0]\n  this.lineOffset   = [0,0,0]\n  this.opacity      = 1\n  this.hasAlpha     = false\n}\n\nvar proto = ErrorBars.prototype\n\nproto.isOpaque = function() {\n  return !this.hasAlpha\n}\n\nproto.isTransparent = function() {\n  return this.hasAlpha\n}\n\nproto.drawTransparent = proto.draw = function(cameraParams) {\n  var gl = this.gl\n  var uniforms        = this.shader.uniforms\n\n  this.shader.bind()\n  var view       = uniforms.view       = cameraParams.view       || IDENTITY\n  var projection = uniforms.projection = cameraParams.projection || IDENTITY\n  uniforms.model      = cameraParams.model      || IDENTITY\n  uniforms.clipBounds = this.clipBounds\n  uniforms.opacity    = this.opacity\n\n\n  var cx = view[12]\n  var cy = view[13]\n  var cz = view[14]\n  var cw = view[15]\n\n  var isOrtho = cameraParams._ortho || false\n  var orthoFix = (isOrtho) ? 2 : 1 // double up padding for orthographic ticks & labels\n  var pixelScaleF = orthoFix * this.pixelRatio * (projection[3]*cx + projection[7]*cy + projection[11]*cz + projection[15]*cw) / gl.drawingBufferHeight\n\n  this.vao.bind()\n  for(var i=0; i<3; ++i) {\n    gl.lineWidth(this.lineWidth[i] * this.pixelRatio)\n    uniforms.capSize = this.capSize[i] * pixelScaleF\n    if (this.lineCount[i]) {\n      gl.drawArrays(gl.LINES, this.lineOffset[i], this.lineCount[i])\n    }\n  }\n  this.vao.unbind()\n}\n\nfunction updateBounds(bounds, point) {\n  for(var i=0; i<3; ++i) {\n    bounds[0][i] = Math.min(bounds[0][i], point[i])\n    bounds[1][i] = Math.max(bounds[1][i], point[i])\n  }\n}\n\nvar FACE_TABLE = (function(){\n  var table = new Array(3)\n  for(var d=0; d<3; ++d) {\n    var row = []\n    for(var j=1; j<=2; ++j) {\n      for(var s=-1; s<=1; s+=2) {\n        var u = (j+d) % 3\n        var y = [0,0,0]\n        y[u] = s\n        row.push(y)\n      }\n    }\n    table[d] = row\n  }\n  return table\n})()\n\n\nfunction emitFace(verts, x, c, d) {\n  var offsets = FACE_TABLE[d]\n  for(var i=0; i<offsets.length; ++i) {\n    var o = offsets[i]\n    verts.push(x[0], x[1], x[2],\n               c[0], c[1], c[2], c[3],\n               o[0], o[1], o[2])\n  }\n  return offsets.length\n}\n\nproto.update = function(options) {\n  options = options || {}\n\n  if('lineWidth' in options) {\n    this.lineWidth = options.lineWidth\n    if(!Array.isArray(this.lineWidth)) {\n      this.lineWidth = [this.lineWidth, this.lineWidth, this.lineWidth]\n    }\n  }\n  if('capSize' in options) {\n    this.capSize = options.capSize\n    if(!Array.isArray(this.capSize)) {\n      this.capSize = [this.capSize, this.capSize, this.capSize]\n    }\n  }\n\n  this.hasAlpha = false // default to no transparent draw\n  if('opacity' in options) {\n    this.opacity = +options.opacity\n    if(this.opacity < 1) {\n      this.hasAlpha = true;\n    }\n  }\n\n  var color    = options.color || [[0,0,0],[0,0,0],[0,0,0]]\n  var position = options.position\n  var error    = options.error\n  if(!Array.isArray(color[0])) {\n    color = [color,color,color]\n  }\n\n  if(position && error) {\n\n    var verts       = []\n    var n           = position.length\n    var vertexCount = 0\n    this.bounds     = [[ Infinity, Infinity, Infinity],\n                       [-Infinity,-Infinity,-Infinity]]\n    this.lineCount  = [0,0,0]\n\n    //Build geometry for lines\n    for(var j=0; j<3; ++j) {\n      this.lineOffset[j] = vertexCount\n\ni_loop:\n      for(var i=0; i<n; ++i) {\n        var p = position[i]\n\n        for(var k=0; k<3; ++k) {\n          if(isNaN(p[k]) || !isFinite(p[k])) {\n            continue i_loop\n          }\n        }\n\n        var e = error[i]\n        var c = color[j]\n        if(Array.isArray(c[0])) {\n          c = color[i]\n        }\n        if(c.length === 3) {\n          c = [c[0], c[1], c[2], 1]\n        } else if(c.length === 4) {\n          c = [c[0], c[1], c[2], c[3]]\n          if(!this.hasAlpha && c[3] < 1) this.hasAlpha = true\n        }\n\n        if(isNaN(e[0][j]) || isNaN(e[1][j])) {\n          continue\n        }\n        if(e[0][j] < 0) {\n          var x = p.slice()\n          x[j] += e[0][j]\n          verts.push(p[0], p[1], p[2],\n                     c[0], c[1], c[2], c[3],\n                        0,    0,    0,\n                     x[0], x[1], x[2],\n                     c[0], c[1], c[2], c[3],\n                        0,    0,    0)\n          updateBounds(this.bounds, x)\n          vertexCount += 2 + emitFace(verts, x, c, j)\n        }\n        if(e[1][j] > 0) {\n          var x = p.slice()\n          x[j] += e[1][j]\n          verts.push(p[0], p[1], p[2],\n                     c[0], c[1], c[2], c[3],\n                        0,    0,    0,\n                     x[0], x[1], x[2],\n                     c[0], c[1], c[2], c[3],\n                        0,    0,    0)\n          updateBounds(this.bounds, x)\n          vertexCount += 2 + emitFace(verts, x, c, j)\n        }\n      }\n      this.lineCount[j] = vertexCount - this.lineOffset[j]\n    }\n    this.buffer.update(verts)\n  }\n}\n\nproto.dispose = function() {\n  this.shader.dispose()\n  this.buffer.dispose()\n  this.vao.dispose()\n}\n\nfunction createErrorBars(options) {\n  var gl = options.gl\n  var buffer = createBuffer(gl)\n  var vao = createVAO(gl, [\n      {\n        buffer: buffer,\n        type:   gl.FLOAT,\n        size:   3,\n        offset: 0,\n        stride: 40\n      },\n      {\n        buffer: buffer,\n        type:   gl.FLOAT,\n        size:   4,\n        offset: 12,\n        stride: 40\n      },\n      {\n        buffer: buffer,\n        type:   gl.FLOAT,\n        size:   3,\n        offset: 28,\n        stride: 40\n      }\n    ])\n\n  var shader = createShader(gl)\n  shader.attributes.position.location = 0\n  shader.attributes.color.location    = 1\n  shader.attributes.offset.location   = 2\n\n  var result = new ErrorBars(gl, buffer, vao, shader)\n  result.update(options)\n  return result\n}\n\n},{\"./shaders/index\":248,\"gl-buffer\":241,\"gl-vao\":327}],248:[function(_dereq_,module,exports){\n'use strict'\n\nvar glslify = _dereq_('glslify')\nvar createShader = _dereq_('gl-shader')\n\nvar vertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position, offset;\\nattribute vec4 color;\\nuniform mat4 model, view, projection;\\nuniform float capSize;\\nvarying vec4 fragColor;\\nvarying vec3 fragPosition;\\n\\nvoid main() {\\n  vec4 worldPosition  = model * vec4(position, 1.0);\\n  worldPosition       = (worldPosition / worldPosition.w) + vec4(capSize * offset, 0.0);\\n  gl_Position         = projection * view * worldPosition;\\n  fragColor           = color;\\n  fragPosition        = position;\\n}\"])\nvar fragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3 clipBounds[2];\\nuniform float opacity;\\nvarying vec3 fragPosition;\\nvarying vec4 fragColor;\\n\\nvoid main() {\\n  if (\\n    outOfRange(clipBounds[0], clipBounds[1], fragPosition) ||\\n    fragColor.a * opacity == 0.\\n  ) discard;\\n\\n  gl_FragColor = opacity * fragColor;\\n}\"])\n\nmodule.exports = function(gl) {\n  return createShader(gl, vertSrc, fragSrc, null, [\n    {name: 'position', type: 'vec3'},\n    {name: 'color', type: 'vec4'},\n    {name: 'offset', type: 'vec3'}\n  ])\n}\n\n},{\"gl-shader\":301,\"glslify\":409}],249:[function(_dereq_,module,exports){\n'use strict'\n\nvar createTexture = _dereq_('gl-texture2d')\n\nmodule.exports = createFBO\n\nvar colorAttachmentArrays = null\nvar FRAMEBUFFER_UNSUPPORTED\nvar FRAMEBUFFER_INCOMPLETE_ATTACHMENT\nvar FRAMEBUFFER_INCOMPLETE_DIMENSIONS\nvar FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n\nfunction saveFBOState(gl) {\n  var fbo = gl.getParameter(gl.FRAMEBUFFER_BINDING)\n  var rbo = gl.getParameter(gl.RENDERBUFFER_BINDING)\n  var tex = gl.getParameter(gl.TEXTURE_BINDING_2D)\n  return [fbo, rbo, tex]\n}\n\nfunction restoreFBOState(gl, data) {\n  gl.bindFramebuffer(gl.FRAMEBUFFER, data[0])\n  gl.bindRenderbuffer(gl.RENDERBUFFER, data[1])\n  gl.bindTexture(gl.TEXTURE_2D, data[2])\n}\n\nfunction lazyInitColorAttachments(gl, ext) {\n  var maxColorAttachments = gl.getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL)\n  colorAttachmentArrays = new Array(maxColorAttachments + 1)\n  for(var i=0; i<=maxColorAttachments; ++i) {\n    var x = new Array(maxColorAttachments)\n    for(var j=0; j<i; ++j) {\n      x[j] = gl.COLOR_ATTACHMENT0 + j\n    }\n    for(var j=i; j<maxColorAttachments; ++j) {\n      x[j] = gl.NONE\n    }\n    colorAttachmentArrays[i] = x\n  }\n}\n\n//Throw an appropriate error\nfunction throwFBOError(status) {\n  switch(status){\n    case FRAMEBUFFER_UNSUPPORTED:\n      throw new Error('gl-fbo: Framebuffer unsupported')\n    case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:\n      throw new Error('gl-fbo: Framebuffer incomplete attachment')\n    case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:\n      throw new Error('gl-fbo: Framebuffer incomplete dimensions')\n    case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:\n      throw new Error('gl-fbo: Framebuffer incomplete missing attachment')\n    default:\n      throw new Error('gl-fbo: Framebuffer failed for unspecified reason')\n  }\n}\n\n//Initialize a texture object\nfunction initTexture(gl, width, height, type, format, attachment) {\n  if(!type) {\n    return null\n  }\n  var result = createTexture(gl, width, height, format, type)\n  result.magFilter = gl.NEAREST\n  result.minFilter = gl.NEAREST\n  result.mipSamples = 1\n  result.bind()\n  gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, result.handle, 0)\n  return result\n}\n\n//Initialize a render buffer object\nfunction initRenderBuffer(gl, width, height, component, attachment) {\n  var result = gl.createRenderbuffer()\n  gl.bindRenderbuffer(gl.RENDERBUFFER, result)\n  gl.renderbufferStorage(gl.RENDERBUFFER, component, width, height)\n  gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, result)\n  return result\n}\n\n//Rebuild the frame buffer\nfunction rebuildFBO(fbo) {\n\n  //Save FBO state\n  var state = saveFBOState(fbo.gl)\n\n  var gl = fbo.gl\n  var handle = fbo.handle = gl.createFramebuffer()\n  var width = fbo._shape[0]\n  var height = fbo._shape[1]\n  var numColors = fbo.color.length\n  var ext = fbo._ext\n  var useStencil = fbo._useStencil\n  var useDepth = fbo._useDepth\n  var colorType = fbo._colorType\n\n  //Bind the fbo\n  gl.bindFramebuffer(gl.FRAMEBUFFER, handle)\n\n  //Allocate color buffers\n  for(var i=0; i<numColors; ++i) {\n    fbo.color[i] = initTexture(gl, width, height, colorType, gl.RGBA, gl.COLOR_ATTACHMENT0 + i)\n  }\n  if(numColors === 0) {\n    fbo._color_rb = initRenderBuffer(gl, width, height, gl.RGBA4, gl.COLOR_ATTACHMENT0)\n    if(ext) {\n      ext.drawBuffersWEBGL(colorAttachmentArrays[0])\n    }\n  } else if(numColors > 1) {\n    ext.drawBuffersWEBGL(colorAttachmentArrays[numColors])\n  }\n\n  //Allocate depth/stencil buffers\n  var WEBGL_depth_texture = gl.getExtension('WEBGL_depth_texture')\n  if(WEBGL_depth_texture) {\n    if(useStencil) {\n      fbo.depth = initTexture(gl, width, height,\n                          WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL,\n                          gl.DEPTH_STENCIL,\n                          gl.DEPTH_STENCIL_ATTACHMENT)\n    } else if(useDepth) {\n      fbo.depth = initTexture(gl, width, height,\n                          gl.UNSIGNED_SHORT,\n                          gl.DEPTH_COMPONENT,\n                          gl.DEPTH_ATTACHMENT)\n    }\n  } else {\n    if(useDepth && useStencil) {\n      fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_STENCIL, gl.DEPTH_STENCIL_ATTACHMENT)\n    } else if(useDepth) {\n      fbo._depth_rb = initRenderBuffer(gl, width, height, gl.DEPTH_COMPONENT16, gl.DEPTH_ATTACHMENT)\n    } else if(useStencil) {\n      fbo._depth_rb = initRenderBuffer(gl, width, height, gl.STENCIL_INDEX, gl.STENCIL_ATTACHMENT)\n    }\n  }\n\n  //Check frame buffer state\n  var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER)\n  if(status !== gl.FRAMEBUFFER_COMPLETE) {\n\n    //Release all partially allocated resources\n    fbo._destroyed = true\n\n    //Release all resources\n    gl.bindFramebuffer(gl.FRAMEBUFFER, null)\n    gl.deleteFramebuffer(fbo.handle)\n    fbo.handle = null\n    if(fbo.depth) {\n      fbo.depth.dispose()\n      fbo.depth = null\n    }\n    if(fbo._depth_rb) {\n      gl.deleteRenderbuffer(fbo._depth_rb)\n      fbo._depth_rb = null\n    }\n    for(var i=0; i<fbo.color.length; ++i) {\n      fbo.color[i].dispose()\n      fbo.color[i] = null\n    }\n    if(fbo._color_rb) {\n      gl.deleteRenderbuffer(fbo._color_rb)\n      fbo._color_rb = null\n    }\n\n    restoreFBOState(gl, state)\n\n    //Throw the frame buffer error\n    throwFBOError(status)\n  }\n\n  //Everything ok, let's get on with life\n  restoreFBOState(gl, state)\n}\n\nfunction Framebuffer(gl, width, height, colorType, numColors, useDepth, useStencil, ext) {\n\n  //Handle and set properties\n  this.gl = gl\n  this._shape = [width|0, height|0]\n  this._destroyed = false\n  this._ext = ext\n\n  //Allocate buffers\n  this.color = new Array(numColors)\n  for(var i=0; i<numColors; ++i) {\n    this.color[i] = null\n  }\n  this._color_rb = null\n  this.depth = null\n  this._depth_rb = null\n\n  //Save depth and stencil flags\n  this._colorType = colorType\n  this._useDepth = useDepth\n  this._useStencil = useStencil\n\n  //Shape vector for resizing\n  var parent = this\n  var shapeVector = [width|0, height|0]\n  Object.defineProperties(shapeVector, {\n    0: {\n      get: function() {\n        return parent._shape[0]\n      },\n      set: function(w) {\n        return parent.width = w\n      }\n    },\n    1: {\n      get: function() {\n        return parent._shape[1]\n      },\n      set: function(h) {\n        return parent.height = h\n      }\n    }\n  })\n  this._shapeVector = shapeVector\n\n  //Initialize all attachments\n  rebuildFBO(this)\n}\n\nvar proto = Framebuffer.prototype\n\nfunction reshapeFBO(fbo, w, h) {\n  //If fbo is invalid, just skip this\n  if(fbo._destroyed) {\n    throw new Error('gl-fbo: Can\\'t resize destroyed FBO')\n  }\n\n  //Don't resize if no change in shape\n  if( (fbo._shape[0] === w) &&\n      (fbo._shape[1] === h) ) {\n    return\n  }\n\n  var gl = fbo.gl\n\n  //Check parameter ranges\n  var maxFBOSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)\n  if( w < 0 || w > maxFBOSize ||\n      h < 0 || h > maxFBOSize) {\n    throw new Error('gl-fbo: Can\\'t resize FBO, invalid dimensions')\n  }\n\n  //Update shape\n  fbo._shape[0] = w\n  fbo._shape[1] = h\n\n  //Save framebuffer state\n  var state = saveFBOState(gl)\n\n  //Resize framebuffer attachments\n  for(var i=0; i<fbo.color.length; ++i) {\n    fbo.color[i].shape = fbo._shape\n  }\n  if(fbo._color_rb) {\n    gl.bindRenderbuffer(gl.RENDERBUFFER, fbo._color_rb)\n    gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, fbo._shape[0], fbo._shape[1])\n  }\n  if(fbo.depth) {\n    fbo.depth.shape = fbo._shape\n  }\n  if(fbo._depth_rb) {\n    gl.bindRenderbuffer(gl.RENDERBUFFER, fbo._depth_rb)\n    if(fbo._useDepth && fbo._useStencil) {\n      gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, fbo._shape[0], fbo._shape[1])\n    } else if(fbo._useDepth) {\n      gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, fbo._shape[0], fbo._shape[1])\n    } else if(fbo._useStencil) {\n      gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX, fbo._shape[0], fbo._shape[1])\n    }\n  }\n\n  //Check FBO status after resize, if something broke then die in a fire\n  gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.handle)\n  var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER)\n  if(status !== gl.FRAMEBUFFER_COMPLETE) {\n    fbo.dispose()\n    restoreFBOState(gl, state)\n    throwFBOError(status)\n  }\n\n  //Restore framebuffer state\n  restoreFBOState(gl, state)\n}\n\nObject.defineProperties(proto, {\n  'shape': {\n    get: function() {\n      if(this._destroyed) {\n        return [0,0]\n      }\n      return this._shapeVector\n    },\n    set: function(x) {\n      if(!Array.isArray(x)) {\n        x = [x|0, x|0]\n      }\n      if(x.length !== 2) {\n        throw new Error('gl-fbo: Shape vector must be length 2')\n      }\n\n      var w = x[0]|0\n      var h = x[1]|0\n      reshapeFBO(this, w, h)\n\n      return [w, h]\n    },\n    enumerable: false\n  },\n  'width': {\n    get: function() {\n      if(this._destroyed) {\n        return 0\n      }\n      return this._shape[0]\n    },\n    set: function(w) {\n      w = w|0\n      reshapeFBO(this, w, this._shape[1])\n      return w\n    },\n    enumerable: false\n  },\n  'height': {\n    get: function() {\n      if(this._destroyed) {\n        return 0\n      }\n      return this._shape[1]\n    },\n    set: function(h) {\n      h = h|0\n      reshapeFBO(this, this._shape[0], h)\n      return h\n    },\n    enumerable: false\n  }\n})\n\nproto.bind = function() {\n  if(this._destroyed) {\n    return\n  }\n  var gl = this.gl\n  gl.bindFramebuffer(gl.FRAMEBUFFER, this.handle)\n  gl.viewport(0, 0, this._shape[0], this._shape[1])\n}\n\nproto.dispose = function() {\n  if(this._destroyed) {\n    return\n  }\n  this._destroyed = true\n  var gl = this.gl\n  gl.deleteFramebuffer(this.handle)\n  this.handle = null\n  if(this.depth) {\n    this.depth.dispose()\n    this.depth = null\n  }\n  if(this._depth_rb) {\n    gl.deleteRenderbuffer(this._depth_rb)\n    this._depth_rb = null\n  }\n  for(var i=0; i<this.color.length; ++i) {\n    this.color[i].dispose()\n    this.color[i] = null\n  }\n  if(this._color_rb) {\n    gl.deleteRenderbuffer(this._color_rb)\n    this._color_rb = null\n  }\n}\n\nfunction createFBO(gl, width, height, options) {\n\n  //Update frame buffer error code values\n  if(!FRAMEBUFFER_UNSUPPORTED) {\n    FRAMEBUFFER_UNSUPPORTED = gl.FRAMEBUFFER_UNSUPPORTED\n    FRAMEBUFFER_INCOMPLETE_ATTACHMENT = gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n    FRAMEBUFFER_INCOMPLETE_DIMENSIONS = gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS\n    FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n  }\n\n  //Lazily initialize color attachment arrays\n  var WEBGL_draw_buffers = gl.getExtension('WEBGL_draw_buffers')\n  if(!colorAttachmentArrays && WEBGL_draw_buffers) {\n    lazyInitColorAttachments(gl, WEBGL_draw_buffers)\n  }\n\n  //Special case: Can accept an array as argument\n  if(Array.isArray(width)) {\n    options = height\n    height = width[1]|0\n    width = width[0]|0\n  }\n\n  if(typeof width !== 'number') {\n    throw new Error('gl-fbo: Missing shape parameter')\n  }\n\n  //Validate width/height properties\n  var maxFBOSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)\n  if(width < 0 || width > maxFBOSize || height < 0 || height > maxFBOSize) {\n    throw new Error('gl-fbo: Parameters are too large for FBO')\n  }\n\n  //Handle each option type\n  options = options || {}\n\n  //Figure out number of color buffers to use\n  var numColors = 1\n  if('color' in options) {\n    numColors = Math.max(options.color|0, 0)\n    if(numColors < 0) {\n      throw new Error('gl-fbo: Must specify a nonnegative number of colors')\n    }\n    if(numColors > 1) {\n      //Check if multiple render targets supported\n      if(!WEBGL_draw_buffers) {\n        throw new Error('gl-fbo: Multiple draw buffer extension not supported')\n      } else if(numColors > gl.getParameter(WEBGL_draw_buffers.MAX_COLOR_ATTACHMENTS_WEBGL)) {\n        throw new Error('gl-fbo: Context does not support ' + numColors + ' draw buffers')\n      }\n    }\n  }\n\n  //Determine whether to use floating point textures\n  var colorType = gl.UNSIGNED_BYTE\n  var OES_texture_float = gl.getExtension('OES_texture_float')\n  if(options.float && numColors > 0) {\n    if(!OES_texture_float) {\n      throw new Error('gl-fbo: Context does not support floating point textures')\n    }\n    colorType = gl.FLOAT\n  } else if(options.preferFloat && numColors > 0) {\n    if(OES_texture_float) {\n      colorType = gl.FLOAT\n    }\n  }\n\n  //Check if we should use depth buffer\n  var useDepth = true\n  if('depth' in options) {\n    useDepth = !!options.depth\n  }\n\n  //Check if we should use a stencil buffer\n  var useStencil = false\n  if('stencil' in options) {\n    useStencil = !!options.stencil\n  }\n\n  return new Framebuffer(\n    gl,\n    width,\n    height,\n    colorType,\n    numColors,\n    useDepth,\n    useStencil,\n    WEBGL_draw_buffers)\n}\n\n},{\"gl-texture2d\":322}],250:[function(_dereq_,module,exports){\n\nvar sprintf = _dereq_('sprintf-js').sprintf;\nvar glConstants = _dereq_('gl-constants/lookup');\nvar shaderName = _dereq_('glsl-shader-name');\nvar addLineNumbers = _dereq_('add-line-numbers');\n\nmodule.exports = formatCompilerError;\n\nfunction formatCompilerError(errLog, src, type) {\n    \"use strict\";\n\n    var name = shaderName(src) || 'of unknown name (see npm glsl-shader-name)';\n\n    var typeName = 'unknown type';\n    if (type !== undefined) {\n        typeName = type === glConstants.FRAGMENT_SHADER ? 'fragment' : 'vertex'\n    }\n\n    var longForm = sprintf('Error compiling %s shader %s:\\n', typeName, name);\n    var shortForm = sprintf(\"%s%s\", longForm, errLog);\n\n    var errorStrings = errLog.split('\\n');\n    var errors = {};\n\n    for (var i = 0; i < errorStrings.length; i++) {\n        var errorString = errorStrings[i];\n        if (errorString === '' || errorString === \"\\0\") continue;\n        var lineNo = parseInt(errorString.split(':')[2]);\n        if (isNaN(lineNo)) {\n            throw new Error(sprintf('Could not parse error: %s', errorString));\n        }\n        errors[lineNo] = errorString;\n    }\n\n    var lines = addLineNumbers(src).split('\\n');\n\n    for (var i = 0; i < lines.length; i++) {\n        if (!errors[i+3] && !errors[i+2] && !errors[i+1]) continue;\n        var line = lines[i];\n        longForm += line + '\\n';\n        if (errors[i+1]) {\n            var e = errors[i+1];\n            e = e.substr(e.split(':', 3).join(':').length + 1).trim();\n            longForm += sprintf('^^^ %s\\n\\n', e);\n        }\n    }\n\n    return {\n        long: longForm.trim(),\n        short: shortForm.trim()\n    };\n}\n\n\n},{\"add-line-numbers\":61,\"gl-constants/lookup\":246,\"glsl-shader-name\":401,\"sprintf-js\":528}],251:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createHeatmap2D\n\nvar bsearch = _dereq_('binary-search-bounds')\nvar iota = _dereq_('iota-array')\nvar pool = _dereq_('typedarray-pool')\nvar createShader = _dereq_('gl-shader')\nvar createBuffer = _dereq_('gl-buffer')\n\nvar shaders = _dereq_('./lib/shaders')\n\nfunction GLHeatmap2D (\n  plot,\n  shader,\n  pickShader,\n  positionBuffer,\n  weightBuffer,\n  colorBuffer,\n  idBuffer) {\n  this.plot = plot\n  this.shader = shader\n  this.pickShader = pickShader\n  this.positionBuffer = positionBuffer\n  this.weightBuffer = weightBuffer\n  this.colorBuffer = colorBuffer\n  this.idBuffer = idBuffer\n  this.xData = []\n  this.yData = []\n  this.shape = [0, 0]\n  this.bounds = [Infinity, Infinity, -Infinity, -Infinity]\n  this.pickOffset = 0\n}\n\nvar proto = GLHeatmap2D.prototype\n\nvar WEIGHTS = [\n  0, 0,\n  1, 0,\n  0, 1,\n  1, 0,\n  1, 1,\n  0, 1\n]\n\nproto.draw = (function () {\n  var MATRIX = [\n    1, 0, 0,\n    0, 1, 0,\n    0, 0, 1\n  ]\n\n  return function () {\n    var plot = this.plot\n    var shader = this.shader\n    var bounds = this.bounds\n    var numVertices = this.numVertices\n\n    if (numVertices <= 0) {\n      return\n    }\n\n    var gl = plot.gl\n    var dataBox = plot.dataBox\n\n    var boundX = bounds[2] - bounds[0]\n    var boundY = bounds[3] - bounds[1]\n    var dataX = dataBox[2] - dataBox[0]\n    var dataY = dataBox[3] - dataBox[1]\n\n    MATRIX[0] = 2.0 * boundX / dataX\n    MATRIX[4] = 2.0 * boundY / dataY\n    MATRIX[6] = 2.0 * (bounds[0] - dataBox[0]) / dataX - 1.0\n    MATRIX[7] = 2.0 * (bounds[1] - dataBox[1]) / dataY - 1.0\n\n    shader.bind()\n\n    var uniforms = shader.uniforms\n    uniforms.viewTransform = MATRIX\n\n    uniforms.shape = this.shape\n\n    var attributes = shader.attributes\n    this.positionBuffer.bind()\n    attributes.position.pointer()\n\n    this.weightBuffer.bind()\n    attributes.weight.pointer(gl.UNSIGNED_BYTE, false)\n\n    this.colorBuffer.bind()\n    attributes.color.pointer(gl.UNSIGNED_BYTE, true)\n\n    gl.drawArrays(gl.TRIANGLES, 0, numVertices)\n  }\n})()\n\nproto.drawPick = (function () {\n  var MATRIX = [\n    1, 0, 0,\n    0, 1, 0,\n    0, 0, 1\n  ]\n\n  var PICK_VECTOR = [0, 0, 0, 0]\n\n  return function (pickOffset) {\n    var plot = this.plot\n    var shader = this.pickShader\n    var bounds = this.bounds\n    var numVertices = this.numVertices\n\n    if (numVertices <= 0) {\n      return\n    }\n\n    var gl = plot.gl\n    var dataBox = plot.dataBox\n\n    var boundX = bounds[2] - bounds[0]\n    var boundY = bounds[3] - bounds[1]\n    var dataX = dataBox[2] - dataBox[0]\n    var dataY = dataBox[3] - dataBox[1]\n\n    MATRIX[0] = 2.0 * boundX / dataX\n    MATRIX[4] = 2.0 * boundY / dataY\n    MATRIX[6] = 2.0 * (bounds[0] - dataBox[0]) / dataX - 1.0\n    MATRIX[7] = 2.0 * (bounds[1] - dataBox[1]) / dataY - 1.0\n\n    for (var i = 0; i < 4; ++i) {\n      PICK_VECTOR[i] = (pickOffset >> (i * 8)) & 0xff\n    }\n\n    this.pickOffset = pickOffset\n\n    shader.bind()\n\n    var uniforms = shader.uniforms\n    uniforms.viewTransform = MATRIX\n    uniforms.pickOffset = PICK_VECTOR\n    uniforms.shape = this.shape\n\n    var attributes = shader.attributes\n    this.positionBuffer.bind()\n    attributes.position.pointer()\n\n    this.weightBuffer.bind()\n    attributes.weight.pointer(gl.UNSIGNED_BYTE, false)\n\n    this.idBuffer.bind()\n    attributes.pickId.pointer(gl.UNSIGNED_BYTE, false)\n\n    gl.drawArrays(gl.TRIANGLES, 0, numVertices)\n\n    return pickOffset + this.shape[0] * this.shape[1]\n  }\n})()\n\nproto.pick = function (x, y, value) {\n  var pickOffset = this.pickOffset\n  var pointCount = this.shape[0] * this.shape[1]\n  if (value < pickOffset || value >= pickOffset + pointCount) {\n    return null\n  }\n  var pointId = value - pickOffset\n  var xData = this.xData\n  var yData = this.yData\n  return {\n    object: this,\n    pointId: pointId,\n    dataCoord: [\n      xData[pointId % this.shape[0]],\n      yData[(pointId / this.shape[0]) | 0]]\n  }\n}\n\nproto.update = function (options) {\n  options = options || {}\n\n  var shape = options.shape || [0, 0]\n\n  var x = options.x || iota(shape[0])\n  var y = options.y || iota(shape[1])\n  var z = options.z || new Float32Array(shape[0] * shape[1])\n\n  this.xData = x\n  this.yData = y\n\n  var colorLevels = options.colorLevels || [0]\n  var colorValues = options.colorValues || [0, 0, 0, 1]\n  var colorCount = colorLevels.length\n\n  var bounds = this.bounds\n  var lox = bounds[0] = x[0]\n  var loy = bounds[1] = y[0]\n  var hix = bounds[2] = x[x.length - 1]\n  var hiy = bounds[3] = y[y.length - 1]\n\n  var xs = 1.0 / (hix - lox)\n  var ys = 1.0 / (hiy - loy)\n\n  var numX = shape[0]\n  var numY = shape[1]\n\n  this.shape = [numX, numY]\n\n  var numVerts = (numX - 1) * (numY - 1) * (WEIGHTS.length >>> 1)\n\n  this.numVertices = numVerts\n\n  var colors = pool.mallocUint8(numVerts * 4)\n  var positions = pool.mallocFloat32(numVerts * 2)\n  var weights   = pool.mallocUint8 (numVerts * 2)\n  var ids = pool.mallocUint32(numVerts)\n\n  var ptr = 0\n\n  for (var j = 0; j < numY - 1; ++j) {\n    var yc0 = ys * (y[j] - loy)\n    var yc1 = ys * (y[j + 1] - loy)\n    for (var i = 0; i < numX - 1; ++i) {\n      var xc0 = xs * (x[i] - lox)\n      var xc1 = xs * (x[i + 1] - lox)\n\n      for (var dd = 0; dd < WEIGHTS.length; dd += 2) {\n        var dx = WEIGHTS[dd]\n        var dy = WEIGHTS[dd + 1]\n        var offset = (j + dy) * numX + (i + dx)\n        var zc = z[offset]\n        var colorIdx = bsearch.le(colorLevels, zc)\n        var r, g, b, a\n        if (colorIdx < 0) {\n          r = colorValues[0]\n          g = colorValues[1]\n          b = colorValues[2]\n          a = colorValues[3]\n        } else if (colorIdx === colorCount - 1) {\n          r = colorValues[4 * colorCount - 4]\n          g = colorValues[4 * colorCount - 3]\n          b = colorValues[4 * colorCount - 2]\n          a = colorValues[4 * colorCount - 1]\n        } else {\n          var t = (zc - colorLevels[colorIdx]) /\n            (colorLevels[colorIdx + 1] - colorLevels[colorIdx])\n          var ti = 1.0 - t\n          var i0 = 4 * colorIdx\n          var i1 = 4 * (colorIdx + 1)\n          r = ti * colorValues[i0] + t * colorValues[i1]\n          g = ti * colorValues[i0 + 1] + t * colorValues[i1 + 1]\n          b = ti * colorValues[i0 + 2] + t * colorValues[i1 + 2]\n          a = ti * colorValues[i0 + 3] + t * colorValues[i1 + 3]\n        }\n\n        colors[4 * ptr] = 255 * r\n        colors[4 * ptr + 1] = 255 * g\n        colors[4 * ptr + 2] = 255 * b\n        colors[4 * ptr + 3] = 255 * a\n\n        positions[2*ptr] = xc0*.5 + xc1*.5;\n        positions[2*ptr+1] = yc0*.5 + yc1*.5;\n\n        weights[2*ptr] = dx;\n        weights[2*ptr+1] = dy;\n\n        ids[ptr] = j * numX + i\n\n        ptr += 1\n      }\n    }\n  }\n\n  this.positionBuffer.update(positions)\n  this.weightBuffer.update(weights)\n  this.colorBuffer.update(colors)\n  this.idBuffer.update(ids)\n\n  pool.free(positions)\n  pool.free(colors)\n  pool.free(weights)\n  pool.free(ids)\n}\n\nproto.dispose = function () {\n  this.shader.dispose()\n  this.pickShader.dispose()\n  this.positionBuffer.dispose()\n  this.weightBuffer.dispose()\n  this.colorBuffer.dispose()\n  this.idBuffer.dispose()\n  this.plot.removeObject(this)\n}\n\nfunction createHeatmap2D (plot, options) {\n  var gl = plot.gl\n\n  var shader = createShader(gl, shaders.vertex, shaders.fragment)\n  var pickShader = createShader(gl, shaders.pickVertex, shaders.pickFragment)\n\n  var positionBuffer = createBuffer(gl)\n  var weightBuffer   = createBuffer(gl)\n  var colorBuffer = createBuffer(gl)\n  var idBuffer = createBuffer(gl)\n\n  var heatmap = new GLHeatmap2D(\n    plot,\n    shader,\n    pickShader,\n    positionBuffer,\n    weightBuffer,\n    colorBuffer,\n    idBuffer)\n\n  heatmap.update(options)\n  plot.addObject(heatmap)\n\n  return heatmap\n}\n\n},{\"./lib/shaders\":252,\"binary-search-bounds\":253,\"gl-buffer\":241,\"gl-shader\":301,\"iota-array\":416,\"typedarray-pool\":545}],252:[function(_dereq_,module,exports){\n'use strict'\n\nvar glslify = _dereq_('glslify')\n\nmodule.exports = {\n  fragment:     glslify([\"precision lowp float;\\n#define GLSLIFY 1\\nvarying vec4 fragColor;\\nvoid main() {\\n  gl_FragColor = vec4(fragColor.rgb * fragColor.a, fragColor.a);\\n}\\n\"]),\n  vertex:       glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec2 position;\\nattribute vec4 color;\\nattribute vec2 weight;\\n\\nuniform vec2 shape;\\nuniform mat3 viewTransform;\\n\\nvarying vec4 fragColor;\\n\\nvoid main() {\\n  vec3 vPosition = viewTransform * vec3( position + (weight-.5)/(shape-1.) , 1.0);\\n  fragColor = color;\\n  gl_Position = vec4(vPosition.xy, 0, vPosition.z);\\n}\\n\"]),\n  pickFragment: glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nvarying vec4 fragId;\\nvarying vec2 vWeight;\\n\\nuniform vec2 shape;\\nuniform vec4 pickOffset;\\n\\nvoid main() {\\n  vec2 d = step(.5, vWeight);\\n  vec4 id = fragId + pickOffset;\\n  id.x += d.x + d.y*shape.x;\\n\\n  id.y += floor(id.x / 256.0);\\n  id.x -= floor(id.x / 256.0) * 256.0;\\n\\n  id.z += floor(id.y / 256.0);\\n  id.y -= floor(id.y / 256.0) * 256.0;\\n\\n  id.w += floor(id.z / 256.0);\\n  id.z -= floor(id.z / 256.0) * 256.0;\\n\\n  gl_FragColor = id/255.;\\n}\\n\"]),\n  pickVertex:   glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec2 position;\\nattribute vec4 pickId;\\nattribute vec2 weight;\\n\\nuniform vec2 shape;\\nuniform mat3 viewTransform;\\n\\nvarying vec4 fragId;\\nvarying vec2 vWeight;\\n\\nvoid main() {\\n  vWeight = weight;\\n\\n  fragId = pickId;\\n\\n  vec3 vPosition = viewTransform * vec3( position + (weight-.5)/(shape-1.) , 1.0);\\n  gl_Position = vec4(vPosition.xy, 0, vPosition.z);\\n}\\n\"])\n}\n\n},{\"glslify\":409}],253:[function(_dereq_,module,exports){\narguments[4][111][0].apply(exports,arguments)\n},{\"dup\":111}],254:[function(_dereq_,module,exports){\nvar glslify       = _dereq_('glslify')\nvar createShader  = _dereq_('gl-shader')\n\nvar vertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position, nextPosition;\\nattribute float arcLength, lineWidth;\\nattribute vec4 color;\\n\\nuniform vec2 screenShape;\\nuniform float pixelRatio;\\nuniform mat4 model, view, projection;\\n\\nvarying vec4 fragColor;\\nvarying vec3 worldPosition;\\nvarying float pixelArcLength;\\n\\nvec4 project(vec3 p) {\\n  return projection * view * model * vec4(p, 1.0);\\n}\\n\\nvoid main() {\\n  vec4 startPoint = project(position);\\n  vec4 endPoint   = project(nextPosition);\\n\\n  vec2 A = startPoint.xy / startPoint.w;\\n  vec2 B =   endPoint.xy /   endPoint.w;\\n\\n  float clipAngle = atan(\\n    (B.y - A.y) * screenShape.y,\\n    (B.x - A.x) * screenShape.x\\n  );\\n\\n  vec2 offset = 0.5 * pixelRatio * lineWidth * vec2(\\n    sin(clipAngle),\\n    -cos(clipAngle)\\n  ) / screenShape;\\n\\n  gl_Position = vec4(startPoint.xy + startPoint.w * offset, startPoint.zw);\\n\\n  worldPosition = position;\\n  pixelArcLength = arcLength;\\n  fragColor = color;\\n}\\n\"])\nvar forwardFrag = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3      clipBounds[2];\\nuniform sampler2D dashTexture;\\nuniform float     dashScale;\\nuniform float     opacity;\\n\\nvarying vec3    worldPosition;\\nvarying float   pixelArcLength;\\nvarying vec4    fragColor;\\n\\nvoid main() {\\n  if (\\n    outOfRange(clipBounds[0], clipBounds[1], worldPosition) ||\\n    fragColor.a * opacity == 0.\\n  ) discard;\\n\\n  float dashWeight = texture2D(dashTexture, vec2(dashScale * pixelArcLength, 0)).r;\\n  if(dashWeight < 0.5) {\\n    discard;\\n  }\\n  gl_FragColor = fragColor * opacity;\\n}\\n\"])\nvar pickFrag = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\n#define FLOAT_MAX  1.70141184e38\\n#define FLOAT_MIN  1.17549435e-38\\n\\nlowp vec4 encode_float_1540259130(highp float v) {\\n  highp float av = abs(v);\\n\\n  //Handle special cases\\n  if(av < FLOAT_MIN) {\\n    return vec4(0.0, 0.0, 0.0, 0.0);\\n  } else if(v > FLOAT_MAX) {\\n    return vec4(127.0, 128.0, 0.0, 0.0) / 255.0;\\n  } else if(v < -FLOAT_MAX) {\\n    return vec4(255.0, 128.0, 0.0, 0.0) / 255.0;\\n  }\\n\\n  highp vec4 c = vec4(0,0,0,0);\\n\\n  //Compute exponent and mantissa\\n  highp float e = floor(log2(av));\\n  highp float m = av * pow(2.0, -e) - 1.0;\\n  \\n  //Unpack mantissa\\n  c[1] = floor(128.0 * m);\\n  m -= c[1] / 128.0;\\n  c[2] = floor(32768.0 * m);\\n  m -= c[2] / 32768.0;\\n  c[3] = floor(8388608.0 * m);\\n  \\n  //Unpack exponent\\n  highp float ebias = e + 127.0;\\n  c[0] = floor(ebias / 2.0);\\n  ebias -= c[0] * 2.0;\\n  c[1] += floor(ebias) * 128.0; \\n\\n  //Unpack sign bit\\n  c[0] += 128.0 * step(0.0, -v);\\n\\n  //Scale back to range\\n  return c / 255.0;\\n}\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform float pickId;\\nuniform vec3 clipBounds[2];\\n\\nvarying vec3 worldPosition;\\nvarying float pixelArcLength;\\nvarying vec4 fragColor;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], worldPosition)) discard;\\n\\n  gl_FragColor = vec4(pickId/255.0, encode_float_1540259130(pixelArcLength).xyz);\\n}\"])\n\nvar ATTRIBUTES = [\n  {name: 'position', type: 'vec3'},\n  {name: 'nextPosition', type: 'vec3'},\n  {name: 'arcLength', type: 'float'},\n  {name: 'lineWidth', type: 'float'},\n  {name: 'color', type: 'vec4'}\n]\n\nexports.createShader = function(gl) {\n  return createShader(gl, vertSrc, forwardFrag, null, ATTRIBUTES)\n}\n\nexports.createPickShader = function(gl) {\n  return createShader(gl, vertSrc, pickFrag, null, ATTRIBUTES)\n}\n\n},{\"gl-shader\":301,\"glslify\":409}],255:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createLinePlot\n\nvar createBuffer = _dereq_('gl-buffer')\nvar createVAO = _dereq_('gl-vao')\nvar createTexture = _dereq_('gl-texture2d')\nvar unpackFloat = _dereq_('glsl-read-float')\nvar bsearch = _dereq_('binary-search-bounds')\nvar ndarray = _dereq_('ndarray')\nvar shaders = _dereq_('./lib/shaders')\n\nvar createShader = shaders.createShader\nvar createPickShader = shaders.createPickShader\n\nvar identity = [1, 0, 0, 0,\n  0, 1, 0, 0,\n  0, 0, 1, 0,\n  0, 0, 0, 1]\n\nfunction distance (a, b) {\n  var s = 0.0\n  for (var i = 0; i < 3; ++i) {\n    var d = a[i] - b[i]\n    s += d * d\n  }\n  return Math.sqrt(s)\n}\n\nfunction filterClipBounds (bounds) {\n  var result = [[-1e6, -1e6, -1e6], [1e6, 1e6, 1e6]]\n  for (var i = 0; i < 3; ++i) {\n    result[0][i] = Math.max(bounds[0][i], result[0][i])\n    result[1][i] = Math.min(bounds[1][i], result[1][i])\n  }\n  return result\n}\n\nfunction PickResult (tau, position, index, dataCoordinate) {\n  this.arcLength = tau\n  this.position = position\n  this.index = index\n  this.dataCoordinate = dataCoordinate\n}\n\nfunction LinePlot (gl, shader, pickShader, buffer, vao, texture) {\n  this.gl = gl\n  this.shader = shader\n  this.pickShader = pickShader\n  this.buffer = buffer\n  this.vao = vao\n  this.clipBounds = [\n    [ -Infinity, -Infinity, -Infinity ],\n    [ Infinity, Infinity, Infinity ]]\n  this.points = []\n  this.arcLength = []\n  this.vertexCount = 0\n  this.bounds = [[0, 0, 0], [0, 0, 0]]\n  this.pickId = 0\n  this.lineWidth = 1\n  this.texture = texture\n  this.dashScale = 1\n  this.opacity = 1\n  this.hasAlpha = false\n  this.dirty = true\n  this.pixelRatio = 1\n}\n\nvar proto = LinePlot.prototype\n\nproto.isTransparent = function () {\n  return this.hasAlpha\n}\n\nproto.isOpaque = function () {\n  return !this.hasAlpha\n}\n\nproto.pickSlots = 1\n\nproto.setPickBase = function (id) {\n  this.pickId = id\n}\n\nproto.drawTransparent = proto.draw = function (camera) {\n  if (!this.vertexCount) return\n  var gl = this.gl\n  var shader = this.shader\n  var vao = this.vao\n  shader.bind()\n  shader.uniforms = {\n    model: camera.model || identity,\n    view: camera.view || identity,\n    projection: camera.projection || identity,\n    clipBounds: filterClipBounds(this.clipBounds),\n    dashTexture: this.texture.bind(),\n    dashScale: this.dashScale / this.arcLength[this.arcLength.length - 1],\n    opacity: this.opacity,\n    screenShape: [gl.drawingBufferWidth, gl.drawingBufferHeight],\n    pixelRatio: this.pixelRatio\n  }\n  vao.bind()\n  vao.draw(gl.TRIANGLE_STRIP, this.vertexCount)\n  vao.unbind()\n}\n\nproto.drawPick = function (camera) {\n  if (!this.vertexCount) return\n  var gl = this.gl\n  var shader = this.pickShader\n  var vao = this.vao\n  shader.bind()\n  shader.uniforms = {\n    model: camera.model || identity,\n    view: camera.view || identity,\n    projection: camera.projection || identity,\n    pickId: this.pickId,\n    clipBounds: filterClipBounds(this.clipBounds),\n    screenShape: [gl.drawingBufferWidth, gl.drawingBufferHeight],\n    pixelRatio: this.pixelRatio\n  }\n  vao.bind()\n  vao.draw(gl.TRIANGLE_STRIP, this.vertexCount)\n  vao.unbind()\n}\n\nproto.update = function (options) {\n  var i, j\n\n  this.dirty = true\n\n  var connectGaps = !!options.connectGaps\n\n  if ('dashScale' in options) {\n    this.dashScale = options.dashScale\n  }\n\n  this.hasAlpha = false // default to no transparent draw\n  if ('opacity' in options) {\n    this.opacity = +options.opacity\n    if(this.opacity < 1) {\n      this.hasAlpha = true;\n    }\n  }\n\n  // Recalculate buffer data\n  var buffer = []\n  var arcLengthArray = []\n  var pointArray = []\n  var arcLength = 0.0\n  var vertexCount = 0\n  var bounds = [\n    [ Infinity, Infinity, Infinity ],\n    [ -Infinity, -Infinity, -Infinity ]]\n\n  var positions = options.position || options.positions\n  if (positions) {\n\n    // Default color\n    var colors = options.color || options.colors || [0, 0, 0, 1]\n\n    var lineWidth = options.lineWidth || 1\n\n    var hadGap = false\n\n    fill_loop:\n    for (i = 1; i < positions.length; ++i) {\n      var a = positions[i - 1]\n      var b = positions[i]\n\n      arcLengthArray.push(arcLength)\n      pointArray.push(a.slice())\n\n      for (j = 0; j < 3; ++j) {\n        if (isNaN(a[j]) || isNaN(b[j]) ||\n          !isFinite(a[j]) || !isFinite(b[j])) {\n\n          if (!connectGaps && buffer.length > 0) {\n            for (var k = 0; k < 24; ++k) {\n              buffer.push(buffer[buffer.length - 12])\n            }\n            vertexCount += 2\n            hadGap = true\n          }\n\n          continue fill_loop\n        }\n        bounds[0][j] = Math.min(bounds[0][j], a[j], b[j])\n        bounds[1][j] = Math.max(bounds[1][j], a[j], b[j])\n      }\n\n      var acolor, bcolor\n      if (Array.isArray(colors[0])) {\n        acolor = (colors.length > i - 1) ? colors[i - 1] :             // using index value\n                 (colors.length > 0)     ? colors[colors.length - 1] : // using last item\n                                           [0, 0, 0, 1];               // using black\n\n        bcolor = (colors.length > i) ? colors[i] :                 // using index value\n                 (colors.length > 0) ? colors[colors.length - 1] : // using last item\n                                       [0, 0, 0, 1];               // using black\n      } else {\n        acolor = bcolor = colors\n      }\n\n      if (acolor.length === 3) {\n        acolor = [acolor[0], acolor[1], acolor[2], 1]\n      }\n      if (bcolor.length === 3) {\n        bcolor = [bcolor[0], bcolor[1], bcolor[2], 1]\n      }\n\n      if(!this.hasAlpha && acolor[3] < 1) this.hasAlpha = true\n\n      var w0\n      if (Array.isArray(lineWidth)) {\n        w0 = (lineWidth.length > i - 1) ? lineWidth[i - 1] :                // using index value\n             (lineWidth.length > 0)     ? lineWidth[lineWidth.length - 1] : // using last item\n                                          [0, 0, 0, 1];                     // using black\n      } else {\n        w0 = lineWidth\n      }\n\n      var t0 = arcLength\n      arcLength += distance(a, b)\n\n      if (hadGap) {\n        for (j = 0; j < 2; ++j) {\n          buffer.push(\n            a[0], a[1], a[2], b[0], b[1], b[2], t0, w0, acolor[0], acolor[1], acolor[2], acolor[3])\n        }\n        vertexCount += 2\n        hadGap = false\n      }\n\n      buffer.push(\n        a[0], a[1], a[2], b[0], b[1], b[2], t0, w0, acolor[0], acolor[1], acolor[2], acolor[3],\n        a[0], a[1], a[2], b[0], b[1], b[2], t0, -w0, acolor[0], acolor[1], acolor[2], acolor[3],\n        b[0], b[1], b[2], a[0], a[1], a[2], arcLength, -w0, bcolor[0], bcolor[1], bcolor[2], bcolor[3],\n        b[0], b[1], b[2], a[0], a[1], a[2], arcLength, w0, bcolor[0], bcolor[1], bcolor[2], bcolor[3])\n\n      vertexCount += 4\n    }\n  }\n  this.buffer.update(buffer)\n\n  arcLengthArray.push(arcLength)\n  pointArray.push(positions[positions.length - 1].slice())\n\n  this.bounds = bounds\n\n  this.vertexCount = vertexCount\n\n  this.points = pointArray\n  this.arcLength = arcLengthArray\n\n  if ('dashes' in options) {\n    var dashArray = options.dashes\n\n    // Calculate prefix sum\n    var prefixSum = dashArray.slice()\n    prefixSum.unshift(0)\n    for (i = 1; i < prefixSum.length; ++i) {\n      prefixSum[i] = prefixSum[i - 1] + prefixSum[i]\n    }\n\n    var dashTexture = ndarray(new Array(256 * 4), [256, 1, 4])\n    for (i = 0; i < 256; ++i) {\n      for (j = 0; j < 4; ++j) {\n        dashTexture.set(i, 0, j, 0)\n      }\n      if (bsearch.le(prefixSum, prefixSum[prefixSum.length - 1] * i / 255.0) & 1) {\n        dashTexture.set(i, 0, 0, 0)\n      } else {\n        dashTexture.set(i, 0, 0, 255)\n      }\n    }\n\n    this.texture.setPixels(dashTexture)\n  }\n}\n\nproto.dispose = function () {\n  this.shader.dispose()\n  this.vao.dispose()\n  this.buffer.dispose()\n}\n\nproto.pick = function (selection) {\n  if (!selection) {\n    return null\n  }\n  if (selection.id !== this.pickId) {\n    return null\n  }\n  var tau = unpackFloat(\n    selection.value[0],\n    selection.value[1],\n    selection.value[2],\n    0)\n  var index = bsearch.le(this.arcLength, tau)\n  if (index < 0) {\n    return null\n  }\n  if (index === this.arcLength.length - 1) {\n    return new PickResult(\n      this.arcLength[this.arcLength.length - 1],\n      this.points[this.points.length - 1].slice(),\n      index)\n  }\n  var a = this.points[index]\n  var b = this.points[Math.min(index + 1, this.points.length - 1)]\n  var t = (tau - this.arcLength[index]) / (this.arcLength[index + 1] - this.arcLength[index])\n  var ti = 1.0 - t\n  var x = [0, 0, 0]\n  for (var i = 0; i < 3; ++i) {\n    x[i] = ti * a[i] + t * b[i]\n  }\n  var dataIndex = Math.min((t < 0.5) ? index : (index + 1), this.points.length - 1)\n  return new PickResult(\n    tau,\n    x,\n    dataIndex,\n    this.points[dataIndex])\n}\n\nfunction createLinePlot (options) {\n  var gl = options.gl || (options.scene && options.scene.gl)\n\n  var shader = createShader(gl)\n  shader.attributes.position.location = 0\n  shader.attributes.nextPosition.location = 1\n  shader.attributes.arcLength.location = 2\n  shader.attributes.lineWidth.location = 3\n  shader.attributes.color.location = 4\n\n  var pickShader = createPickShader(gl)\n  pickShader.attributes.position.location = 0\n  pickShader.attributes.nextPosition.location = 1\n  pickShader.attributes.arcLength.location = 2\n  pickShader.attributes.lineWidth.location = 3\n  pickShader.attributes.color.location = 4\n\n  var buffer = createBuffer(gl)\n  var vao = createVAO(gl, [\n    {\n      'buffer': buffer,\n      'size': 3,\n      'offset': 0,\n      'stride': 48\n    },\n    {\n      'buffer': buffer,\n      'size': 3,\n      'offset': 12,\n      'stride': 48\n    },\n    {\n      'buffer': buffer,\n      'size': 1,\n      'offset': 24,\n      'stride': 48\n    },\n    {\n      'buffer': buffer,\n      'size': 1,\n      'offset': 28,\n      'stride': 48\n    },\n    {\n      'buffer': buffer,\n      'size': 4,\n      'offset': 32,\n      'stride': 48\n    }\n  ])\n\n  // Create texture for dash pattern\n  var defaultTexture = ndarray(new Array(256 * 4), [256, 1, 4])\n  for (var i = 0; i < 256 * 4; ++i) {\n    defaultTexture.data[i] = 255\n  }\n  var texture = createTexture(gl, defaultTexture)\n  texture.wrap = gl.REPEAT\n\n  var linePlot = new LinePlot(gl, shader, pickShader, buffer, vao, texture)\n  linePlot.update(options)\n  return linePlot\n}\n\n},{\"./lib/shaders\":254,\"binary-search-bounds\":256,\"gl-buffer\":241,\"gl-texture2d\":322,\"gl-vao\":327,\"glsl-read-float\":400,\"ndarray\":450}],256:[function(_dereq_,module,exports){\narguments[4][111][0].apply(exports,arguments)\n},{\"dup\":111}],257:[function(_dereq_,module,exports){\nmodule.exports = invert\n\n/**\n * Inverts a mat2\n *\n * @alias mat2.invert\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nfunction invert(out, a) {\n  var a0 = a[0]\n  var a1 = a[1]\n  var a2 = a[2]\n  var a3 = a[3]\n  var det = a0 * a3 - a2 * a1\n\n  if (!det) return null\n  det = 1.0 / det\n\n  out[0] =  a3 * det\n  out[1] = -a1 * det\n  out[2] = -a2 * det\n  out[3] =  a0 * det\n\n  return out\n}\n\n},{}],258:[function(_dereq_,module,exports){\nmodule.exports = invert\n\n/**\n * Inverts a mat3\n *\n * @alias mat3.invert\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nfunction invert(out, a) {\n  var a00 = a[0], a01 = a[1], a02 = a[2]\n  var a10 = a[3], a11 = a[4], a12 = a[5]\n  var a20 = a[6], a21 = a[7], a22 = a[8]\n\n  var b01 = a22 * a11 - a12 * a21\n  var b11 = -a22 * a10 + a12 * a20\n  var b21 = a21 * a10 - a11 * a20\n\n  // Calculate the determinant\n  var det = a00 * b01 + a01 * b11 + a02 * b21\n\n  if (!det) return null\n  det = 1.0 / det\n\n  out[0] = b01 * det\n  out[1] = (-a22 * a01 + a02 * a21) * det\n  out[2] = (a12 * a01 - a02 * a11) * det\n  out[3] = b11 * det\n  out[4] = (a22 * a00 - a02 * a20) * det\n  out[5] = (-a12 * a00 + a02 * a10) * det\n  out[6] = b21 * det\n  out[7] = (-a21 * a00 + a01 * a20) * det\n  out[8] = (a11 * a00 - a01 * a10) * det\n\n  return out\n}\n\n},{}],259:[function(_dereq_,module,exports){\nmodule.exports = clone;\n\n/**\n * Creates a new mat4 initialized with values from an existing matrix\n *\n * @param {mat4} a matrix to clone\n * @returns {mat4} a new 4x4 matrix\n */\nfunction clone(a) {\n    var out = new Float32Array(16);\n    out[0] = a[0];\n    out[1] = a[1];\n    out[2] = a[2];\n    out[3] = a[3];\n    out[4] = a[4];\n    out[5] = a[5];\n    out[6] = a[6];\n    out[7] = a[7];\n    out[8] = a[8];\n    out[9] = a[9];\n    out[10] = a[10];\n    out[11] = a[11];\n    out[12] = a[12];\n    out[13] = a[13];\n    out[14] = a[14];\n    out[15] = a[15];\n    return out;\n};\n},{}],260:[function(_dereq_,module,exports){\nmodule.exports = create;\n\n/**\n * Creates a new identity mat4\n *\n * @returns {mat4} a new 4x4 matrix\n */\nfunction create() {\n    var out = new Float32Array(16);\n    out[0] = 1;\n    out[1] = 0;\n    out[2] = 0;\n    out[3] = 0;\n    out[4] = 0;\n    out[5] = 1;\n    out[6] = 0;\n    out[7] = 0;\n    out[8] = 0;\n    out[9] = 0;\n    out[10] = 1;\n    out[11] = 0;\n    out[12] = 0;\n    out[13] = 0;\n    out[14] = 0;\n    out[15] = 1;\n    return out;\n};\n},{}],261:[function(_dereq_,module,exports){\nmodule.exports = determinant;\n\n/**\n * Calculates the determinant of a mat4\n *\n * @param {mat4} a the source matrix\n * @returns {Number} determinant of a\n */\nfunction determinant(a) {\n    var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n        a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n        a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n        a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n        b00 = a00 * a11 - a01 * a10,\n        b01 = a00 * a12 - a02 * a10,\n        b02 = a00 * a13 - a03 * a10,\n        b03 = a01 * a12 - a02 * a11,\n        b04 = a01 * a13 - a03 * a11,\n        b05 = a02 * a13 - a03 * a12,\n        b06 = a20 * a31 - a21 * a30,\n        b07 = a20 * a32 - a22 * a30,\n        b08 = a20 * a33 - a23 * a30,\n        b09 = a21 * a32 - a22 * a31,\n        b10 = a21 * a33 - a23 * a31,\n        b11 = a22 * a33 - a23 * a32;\n\n    // Calculate the determinant\n    return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n};\n},{}],262:[function(_dereq_,module,exports){\nmodule.exports = fromQuat;\n\n/**\n * Creates a matrix from a quaternion rotation.\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {quat4} q Rotation quaternion\n * @returns {mat4} out\n */\nfunction fromQuat(out, q) {\n    var x = q[0], y = q[1], z = q[2], w = q[3],\n        x2 = x + x,\n        y2 = y + y,\n        z2 = z + z,\n\n        xx = x * x2,\n        yx = y * x2,\n        yy = y * y2,\n        zx = z * x2,\n        zy = z * y2,\n        zz = z * z2,\n        wx = w * x2,\n        wy = w * y2,\n        wz = w * z2;\n\n    out[0] = 1 - yy - zz;\n    out[1] = yx + wz;\n    out[2] = zx - wy;\n    out[3] = 0;\n\n    out[4] = yx - wz;\n    out[5] = 1 - xx - zz;\n    out[6] = zy + wx;\n    out[7] = 0;\n\n    out[8] = zx + wy;\n    out[9] = zy - wx;\n    out[10] = 1 - xx - yy;\n    out[11] = 0;\n\n    out[12] = 0;\n    out[13] = 0;\n    out[14] = 0;\n    out[15] = 1;\n\n    return out;\n};\n},{}],263:[function(_dereq_,module,exports){\nmodule.exports = fromRotationTranslation;\n\n/**\n * Creates a matrix from a quaternion rotation and vector translation\n * This is equivalent to (but much faster than):\n *\n *     mat4.identity(dest);\n *     mat4.translate(dest, vec);\n *     var quatMat = mat4.create();\n *     quat4.toMat4(quat, quatMat);\n *     mat4.multiply(dest, quatMat);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {quat4} q Rotation quaternion\n * @param {vec3} v Translation vector\n * @returns {mat4} out\n */\nfunction fromRotationTranslation(out, q, v) {\n    // Quaternion math\n    var x = q[0], y = q[1], z = q[2], w = q[3],\n        x2 = x + x,\n        y2 = y + y,\n        z2 = z + z,\n\n        xx = x * x2,\n        xy = x * y2,\n        xz = x * z2,\n        yy = y * y2,\n        yz = y * z2,\n        zz = z * z2,\n        wx = w * x2,\n        wy = w * y2,\n        wz = w * z2;\n\n    out[0] = 1 - (yy + zz);\n    out[1] = xy + wz;\n    out[2] = xz - wy;\n    out[3] = 0;\n    out[4] = xy - wz;\n    out[5] = 1 - (xx + zz);\n    out[6] = yz + wx;\n    out[7] = 0;\n    out[8] = xz + wy;\n    out[9] = yz - wx;\n    out[10] = 1 - (xx + yy);\n    out[11] = 0;\n    out[12] = v[0];\n    out[13] = v[1];\n    out[14] = v[2];\n    out[15] = 1;\n    \n    return out;\n};\n},{}],264:[function(_dereq_,module,exports){\nmodule.exports = identity;\n\n/**\n * Set a mat4 to the identity matrix\n *\n * @param {mat4} out the receiving matrix\n * @returns {mat4} out\n */\nfunction identity(out) {\n    out[0] = 1;\n    out[1] = 0;\n    out[2] = 0;\n    out[3] = 0;\n    out[4] = 0;\n    out[5] = 1;\n    out[6] = 0;\n    out[7] = 0;\n    out[8] = 0;\n    out[9] = 0;\n    out[10] = 1;\n    out[11] = 0;\n    out[12] = 0;\n    out[13] = 0;\n    out[14] = 0;\n    out[15] = 1;\n    return out;\n};\n},{}],265:[function(_dereq_,module,exports){\nmodule.exports = invert;\n\n/**\n * Inverts a mat4\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nfunction invert(out, a) {\n    var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n        a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n        a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n        a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n        b00 = a00 * a11 - a01 * a10,\n        b01 = a00 * a12 - a02 * a10,\n        b02 = a00 * a13 - a03 * a10,\n        b03 = a01 * a12 - a02 * a11,\n        b04 = a01 * a13 - a03 * a11,\n        b05 = a02 * a13 - a03 * a12,\n        b06 = a20 * a31 - a21 * a30,\n        b07 = a20 * a32 - a22 * a30,\n        b08 = a20 * a33 - a23 * a30,\n        b09 = a21 * a32 - a22 * a31,\n        b10 = a21 * a33 - a23 * a31,\n        b11 = a22 * a33 - a23 * a32,\n\n        // Calculate the determinant\n        det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n    if (!det) { \n        return null; \n    }\n    det = 1.0 / det;\n\n    out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n    out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n    out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n    out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;\n    out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n    out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n    out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n    out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;\n    out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n    out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n    out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n    out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;\n    out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;\n    out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;\n    out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;\n    out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;\n\n    return out;\n};\n},{}],266:[function(_dereq_,module,exports){\nvar identity = _dereq_('./identity');\n\nmodule.exports = lookAt;\n\n/**\n * Generates a look-at matrix with the given eye position, focal point, and up axis\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {vec3} eye Position of the viewer\n * @param {vec3} center Point the viewer is looking at\n * @param {vec3} up vec3 pointing up\n * @returns {mat4} out\n */\nfunction lookAt(out, eye, center, up) {\n    var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,\n        eyex = eye[0],\n        eyey = eye[1],\n        eyez = eye[2],\n        upx = up[0],\n        upy = up[1],\n        upz = up[2],\n        centerx = center[0],\n        centery = center[1],\n        centerz = center[2];\n\n    if (Math.abs(eyex - centerx) < 0.000001 &&\n        Math.abs(eyey - centery) < 0.000001 &&\n        Math.abs(eyez - centerz) < 0.000001) {\n        return identity(out);\n    }\n\n    z0 = eyex - centerx;\n    z1 = eyey - centery;\n    z2 = eyez - centerz;\n\n    len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);\n    z0 *= len;\n    z1 *= len;\n    z2 *= len;\n\n    x0 = upy * z2 - upz * z1;\n    x1 = upz * z0 - upx * z2;\n    x2 = upx * z1 - upy * z0;\n    len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);\n    if (!len) {\n        x0 = 0;\n        x1 = 0;\n        x2 = 0;\n    } else {\n        len = 1 / len;\n        x0 *= len;\n        x1 *= len;\n        x2 *= len;\n    }\n\n    y0 = z1 * x2 - z2 * x1;\n    y1 = z2 * x0 - z0 * x2;\n    y2 = z0 * x1 - z1 * x0;\n\n    len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);\n    if (!len) {\n        y0 = 0;\n        y1 = 0;\n        y2 = 0;\n    } else {\n        len = 1 / len;\n        y0 *= len;\n        y1 *= len;\n        y2 *= len;\n    }\n\n    out[0] = x0;\n    out[1] = y0;\n    out[2] = z0;\n    out[3] = 0;\n    out[4] = x1;\n    out[5] = y1;\n    out[6] = z1;\n    out[7] = 0;\n    out[8] = x2;\n    out[9] = y2;\n    out[10] = z2;\n    out[11] = 0;\n    out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);\n    out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);\n    out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);\n    out[15] = 1;\n\n    return out;\n};\n},{\"./identity\":264}],267:[function(_dereq_,module,exports){\nmodule.exports = multiply;\n\n/**\n * Multiplies two mat4's\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the first operand\n * @param {mat4} b the second operand\n * @returns {mat4} out\n */\nfunction multiply(out, a, b) {\n    var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n        a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n        a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n        a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];\n\n    // Cache only the current line of the second matrix\n    var b0  = b[0], b1 = b[1], b2 = b[2], b3 = b[3];  \n    out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n    out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n    out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n    out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n    b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];\n    out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n    out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n    out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n    out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n    b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];\n    out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n    out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n    out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n    out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n    b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];\n    out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n    out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n    out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n    out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n    return out;\n};\n},{}],268:[function(_dereq_,module,exports){\nmodule.exports = ortho;\n\n/**\n * Generates a orthogonal projection matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {number} left Left bound of the frustum\n * @param {number} right Right bound of the frustum\n * @param {number} bottom Bottom bound of the frustum\n * @param {number} top Top bound of the frustum\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nfunction ortho(out, left, right, bottom, top, near, far) {\n    var lr = 1 / (left - right),\n        bt = 1 / (bottom - top),\n        nf = 1 / (near - far);\n    out[0] = -2 * lr;\n    out[1] = 0;\n    out[2] = 0;\n    out[3] = 0;\n    out[4] = 0;\n    out[5] = -2 * bt;\n    out[6] = 0;\n    out[7] = 0;\n    out[8] = 0;\n    out[9] = 0;\n    out[10] = 2 * nf;\n    out[11] = 0;\n    out[12] = (left + right) * lr;\n    out[13] = (top + bottom) * bt;\n    out[14] = (far + near) * nf;\n    out[15] = 1;\n    return out;\n};\n},{}],269:[function(_dereq_,module,exports){\nmodule.exports = perspective;\n\n/**\n * Generates a perspective projection matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {number} fovy Vertical field of view in radians\n * @param {number} aspect Aspect ratio. typically viewport width/height\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nfunction perspective(out, fovy, aspect, near, far) {\n    var f = 1.0 / Math.tan(fovy / 2),\n        nf = 1 / (near - far);\n    out[0] = f / aspect;\n    out[1] = 0;\n    out[2] = 0;\n    out[3] = 0;\n    out[4] = 0;\n    out[5] = f;\n    out[6] = 0;\n    out[7] = 0;\n    out[8] = 0;\n    out[9] = 0;\n    out[10] = (far + near) * nf;\n    out[11] = -1;\n    out[12] = 0;\n    out[13] = 0;\n    out[14] = (2 * far * near) * nf;\n    out[15] = 0;\n    return out;\n};\n},{}],270:[function(_dereq_,module,exports){\nmodule.exports = rotate;\n\n/**\n * Rotates a mat4 by the given angle\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @param {vec3} axis the axis to rotate around\n * @returns {mat4} out\n */\nfunction rotate(out, a, rad, axis) {\n    var x = axis[0], y = axis[1], z = axis[2],\n        len = Math.sqrt(x * x + y * y + z * z),\n        s, c, t,\n        a00, a01, a02, a03,\n        a10, a11, a12, a13,\n        a20, a21, a22, a23,\n        b00, b01, b02,\n        b10, b11, b12,\n        b20, b21, b22;\n\n    if (Math.abs(len) < 0.000001) { return null; }\n    \n    len = 1 / len;\n    x *= len;\n    y *= len;\n    z *= len;\n\n    s = Math.sin(rad);\n    c = Math.cos(rad);\n    t = 1 - c;\n\n    a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];\n    a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];\n    a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];\n\n    // Construct the elements of the rotation matrix\n    b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s;\n    b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s;\n    b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c;\n\n    // Perform rotation-specific matrix multiplication\n    out[0] = a00 * b00 + a10 * b01 + a20 * b02;\n    out[1] = a01 * b00 + a11 * b01 + a21 * b02;\n    out[2] = a02 * b00 + a12 * b01 + a22 * b02;\n    out[3] = a03 * b00 + a13 * b01 + a23 * b02;\n    out[4] = a00 * b10 + a10 * b11 + a20 * b12;\n    out[5] = a01 * b10 + a11 * b11 + a21 * b12;\n    out[6] = a02 * b10 + a12 * b11 + a22 * b12;\n    out[7] = a03 * b10 + a13 * b11 + a23 * b12;\n    out[8] = a00 * b20 + a10 * b21 + a20 * b22;\n    out[9] = a01 * b20 + a11 * b21 + a21 * b22;\n    out[10] = a02 * b20 + a12 * b21 + a22 * b22;\n    out[11] = a03 * b20 + a13 * b21 + a23 * b22;\n\n    if (a !== out) { // If the source and destination differ, copy the unchanged last row\n        out[12] = a[12];\n        out[13] = a[13];\n        out[14] = a[14];\n        out[15] = a[15];\n    }\n    return out;\n};\n},{}],271:[function(_dereq_,module,exports){\nmodule.exports = rotateX;\n\n/**\n * Rotates a matrix by the given angle around the X axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nfunction rotateX(out, a, rad) {\n    var s = Math.sin(rad),\n        c = Math.cos(rad),\n        a10 = a[4],\n        a11 = a[5],\n        a12 = a[6],\n        a13 = a[7],\n        a20 = a[8],\n        a21 = a[9],\n        a22 = a[10],\n        a23 = a[11];\n\n    if (a !== out) { // If the source and destination differ, copy the unchanged rows\n        out[0]  = a[0];\n        out[1]  = a[1];\n        out[2]  = a[2];\n        out[3]  = a[3];\n        out[12] = a[12];\n        out[13] = a[13];\n        out[14] = a[14];\n        out[15] = a[15];\n    }\n\n    // Perform axis-specific matrix multiplication\n    out[4] = a10 * c + a20 * s;\n    out[5] = a11 * c + a21 * s;\n    out[6] = a12 * c + a22 * s;\n    out[7] = a13 * c + a23 * s;\n    out[8] = a20 * c - a10 * s;\n    out[9] = a21 * c - a11 * s;\n    out[10] = a22 * c - a12 * s;\n    out[11] = a23 * c - a13 * s;\n    return out;\n};\n},{}],272:[function(_dereq_,module,exports){\nmodule.exports = rotateY;\n\n/**\n * Rotates a matrix by the given angle around the Y axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nfunction rotateY(out, a, rad) {\n    var s = Math.sin(rad),\n        c = Math.cos(rad),\n        a00 = a[0],\n        a01 = a[1],\n        a02 = a[2],\n        a03 = a[3],\n        a20 = a[8],\n        a21 = a[9],\n        a22 = a[10],\n        a23 = a[11];\n\n    if (a !== out) { // If the source and destination differ, copy the unchanged rows\n        out[4]  = a[4];\n        out[5]  = a[5];\n        out[6]  = a[6];\n        out[7]  = a[7];\n        out[12] = a[12];\n        out[13] = a[13];\n        out[14] = a[14];\n        out[15] = a[15];\n    }\n\n    // Perform axis-specific matrix multiplication\n    out[0] = a00 * c - a20 * s;\n    out[1] = a01 * c - a21 * s;\n    out[2] = a02 * c - a22 * s;\n    out[3] = a03 * c - a23 * s;\n    out[8] = a00 * s + a20 * c;\n    out[9] = a01 * s + a21 * c;\n    out[10] = a02 * s + a22 * c;\n    out[11] = a03 * s + a23 * c;\n    return out;\n};\n},{}],273:[function(_dereq_,module,exports){\nmodule.exports = rotateZ;\n\n/**\n * Rotates a matrix by the given angle around the Z axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nfunction rotateZ(out, a, rad) {\n    var s = Math.sin(rad),\n        c = Math.cos(rad),\n        a00 = a[0],\n        a01 = a[1],\n        a02 = a[2],\n        a03 = a[3],\n        a10 = a[4],\n        a11 = a[5],\n        a12 = a[6],\n        a13 = a[7];\n\n    if (a !== out) { // If the source and destination differ, copy the unchanged last row\n        out[8]  = a[8];\n        out[9]  = a[9];\n        out[10] = a[10];\n        out[11] = a[11];\n        out[12] = a[12];\n        out[13] = a[13];\n        out[14] = a[14];\n        out[15] = a[15];\n    }\n\n    // Perform axis-specific matrix multiplication\n    out[0] = a00 * c + a10 * s;\n    out[1] = a01 * c + a11 * s;\n    out[2] = a02 * c + a12 * s;\n    out[3] = a03 * c + a13 * s;\n    out[4] = a10 * c - a00 * s;\n    out[5] = a11 * c - a01 * s;\n    out[6] = a12 * c - a02 * s;\n    out[7] = a13 * c - a03 * s;\n    return out;\n};\n},{}],274:[function(_dereq_,module,exports){\nmodule.exports = scale;\n\n/**\n * Scales the mat4 by the dimensions in the given vec3\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to scale\n * @param {vec3} v the vec3 to scale the matrix by\n * @returns {mat4} out\n **/\nfunction scale(out, a, v) {\n    var x = v[0], y = v[1], z = v[2];\n\n    out[0] = a[0] * x;\n    out[1] = a[1] * x;\n    out[2] = a[2] * x;\n    out[3] = a[3] * x;\n    out[4] = a[4] * y;\n    out[5] = a[5] * y;\n    out[6] = a[6] * y;\n    out[7] = a[7] * y;\n    out[8] = a[8] * z;\n    out[9] = a[9] * z;\n    out[10] = a[10] * z;\n    out[11] = a[11] * z;\n    out[12] = a[12];\n    out[13] = a[13];\n    out[14] = a[14];\n    out[15] = a[15];\n    return out;\n};\n},{}],275:[function(_dereq_,module,exports){\nmodule.exports = translate;\n\n/**\n * Translate a mat4 by the given vector\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to translate\n * @param {vec3} v vector to translate by\n * @returns {mat4} out\n */\nfunction translate(out, a, v) {\n    var x = v[0], y = v[1], z = v[2],\n        a00, a01, a02, a03,\n        a10, a11, a12, a13,\n        a20, a21, a22, a23;\n\n    if (a === out) {\n        out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];\n        out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];\n        out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];\n        out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];\n    } else {\n        a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];\n        a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];\n        a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];\n\n        out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;\n        out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;\n        out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;\n\n        out[12] = a00 * x + a10 * y + a20 * z + a[12];\n        out[13] = a01 * x + a11 * y + a21 * z + a[13];\n        out[14] = a02 * x + a12 * y + a22 * z + a[14];\n        out[15] = a03 * x + a13 * y + a23 * z + a[15];\n    }\n\n    return out;\n};\n},{}],276:[function(_dereq_,module,exports){\nmodule.exports = transpose;\n\n/**\n * Transpose the values of a mat4\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nfunction transpose(out, a) {\n    // If we are transposing ourselves we can skip a few steps but have to cache some values\n    if (out === a) {\n        var a01 = a[1], a02 = a[2], a03 = a[3],\n            a12 = a[6], a13 = a[7],\n            a23 = a[11];\n\n        out[1] = a[4];\n        out[2] = a[8];\n        out[3] = a[12];\n        out[4] = a01;\n        out[6] = a[9];\n        out[7] = a[13];\n        out[8] = a02;\n        out[9] = a12;\n        out[11] = a[14];\n        out[12] = a03;\n        out[13] = a13;\n        out[14] = a23;\n    } else {\n        out[0] = a[0];\n        out[1] = a[4];\n        out[2] = a[8];\n        out[3] = a[12];\n        out[4] = a[1];\n        out[5] = a[5];\n        out[6] = a[9];\n        out[7] = a[13];\n        out[8] = a[2];\n        out[9] = a[6];\n        out[10] = a[10];\n        out[11] = a[14];\n        out[12] = a[3];\n        out[13] = a[7];\n        out[14] = a[11];\n        out[15] = a[15];\n    }\n    \n    return out;\n};\n},{}],277:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = invert\n\nvar invert2 = _dereq_('gl-mat2/invert')\nvar invert3 = _dereq_('gl-mat3/invert')\nvar invert4 = _dereq_('gl-mat4/invert')\n\nfunction invert(out, M) {\n  switch(M.length) {\n    case 0:\n    break\n    case 1:\n      out[0] = 1.0 / M[0]\n    break\n    case 4:\n      invert2(out, M)\n    break\n    case 9:\n      invert3(out, M)\n    break\n    case 16:\n      invert4(out, M)\n    break\n    default:\n      throw new Error('currently supports matrices up to 4x4')\n    break\n  }\n  return out\n}\n},{\"gl-mat2/invert\":257,\"gl-mat3/invert\":258,\"gl-mat4/invert\":265}],278:[function(_dereq_,module,exports){\n'use strict'\n\nvar barycentric            = _dereq_('barycentric')\nvar closestPointToTriangle = _dereq_('polytope-closest-point/lib/closest_point_2d.js')\n\nmodule.exports = closestPointToPickLocation\n\nfunction xformMatrix(m, v) {\n  var out = [0,0,0,0]\n  for(var i=0; i<4; ++i) {\n    for(var j=0; j<4; ++j) {\n      out[j] += m[4*i + j] * v[i]\n    }\n  }\n  return out\n}\n\nfunction projectVertex(v, model, view, projection, resolution) {\n  var p = xformMatrix(projection,\n            xformMatrix(view,\n              xformMatrix(model, [v[0], v[1], v[2], 1])))\n  for(var i=0; i<3; ++i) {\n    p[i] /= p[3]\n  }\n  return [ 0.5 * resolution[0] * (1.0+p[0]), 0.5 * resolution[1] * (1.0-p[1]) ]\n}\n\nfunction barycentricCoord(simplex, point) {\n  if(simplex.length === 2) {\n    var d0 = 0.0\n    var d1 = 0.0\n    for(var i=0; i<2; ++i) {\n      d0 += Math.pow(point[i] - simplex[0][i], 2)\n      d1 += Math.pow(point[i] - simplex[1][i], 2)\n    }\n    d0 = Math.sqrt(d0)\n    d1 = Math.sqrt(d1)\n    if(d0+d1 < 1e-6) {\n      return [1,0]\n    }\n    return [d1/(d0+d1),d0/(d1+d0)]\n  } else if(simplex.length === 3) {\n    var closestPoint = [0,0]\n    closestPointToTriangle(simplex[0], simplex[1], simplex[2], point, closestPoint)\n    return barycentric(simplex, closestPoint)\n  }\n  return []\n}\n\nfunction interpolate(simplex, weights) {\n  var result = [0,0,0]\n  for(var i=0; i<simplex.length; ++i) {\n    var p = simplex[i]\n    var w = weights[i]\n    for(var j=0; j<3; ++j) {\n      result[j] += w * p[j]\n    }\n  }\n  return result\n}\n\nfunction closestPointToPickLocation(simplex, pixelCoord, model, view, projection, resolution) {\n  if(simplex.length === 1) {\n    return [0, simplex[0].slice()]\n  }\n  var simplex2D = new Array(simplex.length)\n  for(var i=0; i<simplex.length; ++i) {\n    simplex2D[i] = projectVertex(simplex[i], model, view, projection, resolution);\n  }\n\n  var closestIndex = 0\n  var closestDist  = Infinity\n  for(var i=0; i<simplex2D.length; ++i) {\n    var d2 = 0.0\n    for(var j=0; j<2; ++j) {\n      d2 += Math.pow(simplex2D[i][j] - pixelCoord[j], 2)\n    }\n    if(d2 < closestDist) {\n      closestDist  = d2\n      closestIndex = i\n    }\n  }\n\n  var weights = barycentricCoord(simplex2D, pixelCoord)\n  var s = 0.0\n  for(var i=0; i<3; ++i) {\n    if(weights[i] < -0.001 ||\n       weights[i] > 1.0001) {\n      return null\n    }\n    s += weights[i]\n  }\n  if(Math.abs(s - 1.0) > 0.001) {\n    return null\n  }\n  return [closestIndex, interpolate(simplex, weights), weights]\n}\n},{\"barycentric\":73,\"polytope-closest-point/lib/closest_point_2d.js\":481}],279:[function(_dereq_,module,exports){\nvar glslify       = _dereq_('glslify')\n\nvar triVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position, normal;\\nattribute vec4 color;\\nattribute vec2 uv;\\n\\nuniform mat4 model\\n           , view\\n           , projection\\n           , inverseModel;\\nuniform vec3 eyePosition\\n           , lightPosition;\\n\\nvarying vec3 f_normal\\n           , f_lightDirection\\n           , f_eyeDirection\\n           , f_data;\\nvarying vec4 f_color;\\nvarying vec2 f_uv;\\n\\nvec4 project(vec3 p) {\\n  return projection * view * model * vec4(p, 1.0);\\n}\\n\\nvoid main() {\\n  gl_Position      = project(position);\\n\\n  //Lighting geometry parameters\\n  vec4 cameraCoordinate = view * vec4(position , 1.0);\\n  cameraCoordinate.xyz /= cameraCoordinate.w;\\n  f_lightDirection = lightPosition - cameraCoordinate.xyz;\\n  f_eyeDirection   = eyePosition - cameraCoordinate.xyz;\\n  f_normal  = normalize((vec4(normal, 0.0) * inverseModel).xyz);\\n\\n  f_color          = color;\\n  f_data           = position;\\n  f_uv             = uv;\\n}\\n\"])\nvar triFragSrc = glslify([\"#extension GL_OES_standard_derivatives : enable\\n\\nprecision highp float;\\n#define GLSLIFY 1\\n\\nfloat beckmannDistribution(float x, float roughness) {\\n  float NdotH = max(x, 0.0001);\\n  float cos2Alpha = NdotH * NdotH;\\n  float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;\\n  float roughness2 = roughness * roughness;\\n  float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;\\n  return exp(tan2Alpha / roughness2) / denom;\\n}\\n\\nfloat cookTorranceSpecular(\\n  vec3 lightDirection,\\n  vec3 viewDirection,\\n  vec3 surfaceNormal,\\n  float roughness,\\n  float fresnel) {\\n\\n  float VdotN = max(dot(viewDirection, surfaceNormal), 0.0);\\n  float LdotN = max(dot(lightDirection, surfaceNormal), 0.0);\\n\\n  //Half angle vector\\n  vec3 H = normalize(lightDirection + viewDirection);\\n\\n  //Geometric term\\n  float NdotH = max(dot(surfaceNormal, H), 0.0);\\n  float VdotH = max(dot(viewDirection, H), 0.000001);\\n  float LdotH = max(dot(lightDirection, H), 0.000001);\\n  float G1 = (2.0 * NdotH * VdotN) / VdotH;\\n  float G2 = (2.0 * NdotH * LdotN) / LdotH;\\n  float G = min(1.0, min(G1, G2));\\n  \\n  //Distribution term\\n  float D = beckmannDistribution(NdotH, roughness);\\n\\n  //Fresnel term\\n  float F = pow(1.0 - VdotN, fresnel);\\n\\n  //Multiply terms and done\\n  return  G * F * D / max(3.14159265 * VdotN, 0.000001);\\n}\\n\\n//#pragma glslify: beckmann = require(glsl-specular-beckmann) // used in gl-surface3d\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3 clipBounds[2];\\nuniform float roughness\\n            , fresnel\\n            , kambient\\n            , kdiffuse\\n            , kspecular;\\nuniform sampler2D texture;\\n\\nvarying vec3 f_normal\\n           , f_lightDirection\\n           , f_eyeDirection\\n           , f_data;\\nvarying vec4 f_color;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  if (f_color.a == 0.0 ||\\n    outOfRange(clipBounds[0], clipBounds[1], f_data)\\n  ) discard;\\n\\n  vec3 N = normalize(f_normal);\\n  vec3 L = normalize(f_lightDirection);\\n  vec3 V = normalize(f_eyeDirection);\\n\\n  if(gl_FrontFacing) {\\n    N = -N;\\n  }\\n\\n  float specular = min(1.0, max(0.0, cookTorranceSpecular(L, V, N, roughness, fresnel)));\\n  //float specular = max(0.0, beckmann(L, V, N, roughness)); // used in gl-surface3d\\n\\n  float diffuse  = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);\\n\\n  vec4 surfaceColor = vec4(f_color.rgb, 1.0) * texture2D(texture, f_uv);\\n  vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular,  1.0);\\n\\n  gl_FragColor = litColor * f_color.a;\\n}\\n\"])\nvar edgeVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position;\\nattribute vec4 color;\\nattribute vec2 uv;\\n\\nuniform mat4 model, view, projection;\\n\\nvarying vec4 f_color;\\nvarying vec3 f_data;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  gl_Position = projection * view * model * vec4(position, 1.0);\\n  f_color = color;\\n  f_data  = position;\\n  f_uv    = uv;\\n}\"])\nvar edgeFragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3 clipBounds[2];\\nuniform sampler2D texture;\\nuniform float opacity;\\n\\nvarying vec4 f_color;\\nvarying vec3 f_data;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], f_data)) discard;\\n\\n  gl_FragColor = f_color * texture2D(texture, f_uv) * opacity;\\n}\"])\nvar pointVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nattribute vec3 position;\\nattribute vec4 color;\\nattribute vec2 uv;\\nattribute float pointSize;\\n\\nuniform mat4 model, view, projection;\\nuniform vec3 clipBounds[2];\\n\\nvarying vec4 f_color;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\\n\\n    gl_Position = vec4(0.0, 0.0 ,0.0 ,0.0);\\n  } else {\\n    gl_Position = projection * view * model * vec4(position, 1.0);\\n  }\\n  gl_PointSize = pointSize;\\n  f_color = color;\\n  f_uv = uv;\\n}\"])\nvar pointFragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nuniform sampler2D texture;\\nuniform float opacity;\\n\\nvarying vec4 f_color;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  vec2 pointR = gl_PointCoord.xy - vec2(0.5, 0.5);\\n  if(dot(pointR, pointR) > 0.25) {\\n    discard;\\n  }\\n  gl_FragColor = f_color * texture2D(texture, f_uv) * opacity;\\n}\"])\nvar pickVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position;\\nattribute vec4 id;\\n\\nuniform mat4 model, view, projection;\\n\\nvarying vec3 f_position;\\nvarying vec4 f_id;\\n\\nvoid main() {\\n  gl_Position = projection * view * model * vec4(position, 1.0);\\n  f_id        = id;\\n  f_position  = position;\\n}\"])\nvar pickFragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3  clipBounds[2];\\nuniform float pickId;\\n\\nvarying vec3 f_position;\\nvarying vec4 f_id;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\\n\\n  gl_FragColor = vec4(pickId, f_id.xyz);\\n}\"])\nvar pickPointVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nattribute vec3  position;\\nattribute float pointSize;\\nattribute vec4  id;\\n\\nuniform mat4 model, view, projection;\\nuniform vec3 clipBounds[2];\\n\\nvarying vec3 f_position;\\nvarying vec4 f_id;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\\n\\n    gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\\n  } else {\\n    gl_Position  = projection * view * model * vec4(position, 1.0);\\n    gl_PointSize = pointSize;\\n  }\\n  f_id         = id;\\n  f_position   = position;\\n}\"])\nvar contourVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position;\\n\\nuniform mat4 model, view, projection;\\n\\nvoid main() {\\n  gl_Position = projection * view * model * vec4(position, 1.0);\\n}\"])\nvar contourFragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nuniform vec3 contourColor;\\n\\nvoid main() {\\n  gl_FragColor = vec4(contourColor, 1.0);\\n}\\n\"])\n\nexports.meshShader = {\n  vertex:   triVertSrc,\n  fragment: triFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec3'},\n    {name: 'normal', type: 'vec3'},\n    {name: 'color', type: 'vec4'},\n    {name: 'uv', type: 'vec2'}\n  ]\n}\nexports.wireShader = {\n  vertex:   edgeVertSrc,\n  fragment: edgeFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec3'},\n    {name: 'color', type: 'vec4'},\n    {name: 'uv', type: 'vec2'}\n  ]\n}\nexports.pointShader = {\n  vertex:   pointVertSrc,\n  fragment: pointFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec3'},\n    {name: 'color', type: 'vec4'},\n    {name: 'uv', type: 'vec2'},\n    {name: 'pointSize', type: 'float'}\n  ]\n}\nexports.pickShader = {\n  vertex:   pickVertSrc,\n  fragment: pickFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec3'},\n    {name: 'id', type: 'vec4'}\n  ]\n}\nexports.pointPickShader = {\n  vertex:   pickPointVertSrc,\n  fragment: pickFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec3'},\n    {name: 'pointSize', type: 'float'},\n    {name: 'id', type: 'vec4'}\n  ]\n}\nexports.contourShader = {\n  vertex:   contourVertSrc,\n  fragment: contourFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec3'}\n  ]\n}\n\n},{\"glslify\":409}],280:[function(_dereq_,module,exports){\n'use strict'\n\nvar DEFAULT_VERTEX_NORMALS_EPSILON = 1e-6; // may be too large if triangles are very small\nvar DEFAULT_FACE_NORMALS_EPSILON = 1e-6;\n\nvar createShader  = _dereq_('gl-shader')\nvar createBuffer  = _dereq_('gl-buffer')\nvar createVAO     = _dereq_('gl-vao')\nvar createTexture = _dereq_('gl-texture2d')\nvar normals       = _dereq_('normals')\nvar multiply      = _dereq_('gl-mat4/multiply')\nvar invert        = _dereq_('gl-mat4/invert')\nvar ndarray       = _dereq_('ndarray')\nvar colormap      = _dereq_('colormap')\nvar getContour    = _dereq_('simplicial-complex-contour')\nvar pool          = _dereq_('typedarray-pool')\nvar shaders       = _dereq_('./lib/shaders')\nvar closestPoint  = _dereq_('./lib/closest-point')\n\nvar meshShader    = shaders.meshShader\nvar wireShader    = shaders.wireShader\nvar pointShader   = shaders.pointShader\nvar pickShader    = shaders.pickShader\nvar pointPickShader = shaders.pointPickShader\nvar contourShader = shaders.contourShader\n\nvar IDENTITY = [\n  1,0,0,0,\n  0,1,0,0,\n  0,0,1,0,\n  0,0,0,1]\n\n\nfunction SimplicialMesh(gl\n  , texture\n  , triShader\n  , lineShader\n  , pointShader\n  , pickShader\n  , pointPickShader\n  , contourShader\n  , trianglePositions\n  , triangleIds\n  , triangleColors\n  , triangleUVs\n  , triangleNormals\n  , triangleVAO\n  , edgePositions\n  , edgeIds\n  , edgeColors\n  , edgeUVs\n  , edgeVAO\n  , pointPositions\n  , pointIds\n  , pointColors\n  , pointUVs\n  , pointSizes\n  , pointVAO\n  , contourPositions\n  , contourVAO) {\n\n  this.gl                = gl\n  this.pixelRatio         = 1\n  this.cells             = []\n  this.positions         = []\n  this.intensity         = []\n  this.texture           = texture\n  this.dirty             = true\n\n  this.triShader         = triShader\n  this.lineShader        = lineShader\n  this.pointShader       = pointShader\n  this.pickShader        = pickShader\n  this.pointPickShader   = pointPickShader\n  this.contourShader     = contourShader\n\n  this.trianglePositions = trianglePositions\n  this.triangleColors    = triangleColors\n  this.triangleNormals   = triangleNormals\n  this.triangleUVs       = triangleUVs\n  this.triangleIds       = triangleIds\n  this.triangleVAO       = triangleVAO\n  this.triangleCount     = 0\n\n  this.lineWidth         = 1\n  this.edgePositions     = edgePositions\n  this.edgeColors        = edgeColors\n  this.edgeUVs           = edgeUVs\n  this.edgeIds           = edgeIds\n  this.edgeVAO           = edgeVAO\n  this.edgeCount         = 0\n\n  this.pointPositions    = pointPositions\n  this.pointColors       = pointColors\n  this.pointUVs          = pointUVs\n  this.pointSizes        = pointSizes\n  this.pointIds          = pointIds\n  this.pointVAO          = pointVAO\n  this.pointCount        = 0\n\n  this.contourLineWidth  = 1\n  this.contourPositions  = contourPositions\n  this.contourVAO        = contourVAO\n  this.contourCount      = 0\n  this.contourColor      = [0,0,0]\n  this.contourEnable     = true\n\n  this.pickId            = 1\n  this.bounds            = [\n    [ Infinity, Infinity, Infinity],\n    [-Infinity,-Infinity,-Infinity] ]\n  this.clipBounds        = [\n    [-Infinity,-Infinity,-Infinity],\n    [ Infinity, Infinity, Infinity] ]\n\n  this.lightPosition = [1e5, 1e5, 0]\n  this.ambientLight  = 0.8\n  this.diffuseLight  = 0.8\n  this.specularLight = 2.0\n  this.roughness     = 0.5\n  this.fresnel       = 1.5\n\n  this.opacity       = 1.0\n  this.hasAlpha      = false\n  this.opacityscale  = false\n\n  this._model       = IDENTITY\n  this._view        = IDENTITY\n  this._projection  = IDENTITY\n  this._resolution  = [1,1]\n}\n\nvar proto = SimplicialMesh.prototype\n\nproto.isOpaque = function() {\n  return !this.hasAlpha\n}\n\nproto.isTransparent = function() {\n  return this.hasAlpha\n}\n\nproto.pickSlots = 1\n\nproto.setPickBase = function(id) {\n  this.pickId = id\n}\n\nfunction getOpacityFromScale(ratio, opacityscale) {\n\n  if(!opacityscale) return 1\n  if(!opacityscale.length) return 1\n\n  for(var i = 0; i < opacityscale.length; ++i) {\n    if(opacityscale.length < 2) return 1\n    if(opacityscale[i][0] === ratio) return opacityscale[i][1]\n    if(opacityscale[i][0] > ratio && i > 0) {\n      var d = (opacityscale[i][0] - ratio) / (opacityscale[i][0] - opacityscale[i - 1][0])\n      return opacityscale[i][1] * (1 - d) + d * opacityscale[i - 1][1]\n    }\n  }\n\n  return 1\n}\n\nfunction genColormap(param, opacityscale) {\n  var colors = colormap({\n      colormap: param\n    , nshades:  256\n    , format:  'rgba'\n  })\n\n  var result = new Uint8Array(256*4)\n  for(var i=0; i<256; ++i) {\n    var c = colors[i]\n    for(var j=0; j<3; ++j) {\n      result[4*i+j] = c[j]\n    }\n    if(!opacityscale) {\n      result[4*i+3] = 255 * c[3]\n    } else {\n      result[4*i+3] = 255 * getOpacityFromScale(i / 255.0, opacityscale)\n    }\n  }\n\n  return ndarray(result, [256,256,4], [4,0,1])\n}\n\nfunction unpackIntensity(cells, numVerts, cellIntensity) {\n  var result = new Array(numVerts)\n  for(var i=0; i<numVerts; ++i) {\n    result[i] = 0\n  }\n  var numCells = cells.length\n  for(var i=0; i<numCells; ++i) {\n    var c = cells[i]\n    for(var j=0; j<c.length; ++j) {\n      result[c[j]] = cellIntensity[i]\n    }\n  }\n  return result\n}\n\nfunction takeZComponent(array) {\n  var n = array.length\n  var result = new Array(n)\n  for(var i=0; i<n; ++i) {\n    result[i] = array[i][2]\n  }\n  return result\n}\n\nproto.highlight = function(selection) {\n  if(!selection || !this.contourEnable) {\n    this.contourCount = 0\n    return\n  }\n  var level = getContour(this.cells, this.intensity, selection.intensity)\n  var cells         = level.cells\n  var vertexIds     = level.vertexIds\n  var vertexWeights = level.vertexWeights\n  var numCells = cells.length\n  var result = pool.mallocFloat32(2 * 3 * numCells)\n  var ptr = 0\n  for(var i=0; i<numCells; ++i) {\n    var c = cells[i]\n    for(var j=0; j<2; ++j) {\n      var v = c[0]\n      if(c.length === 2) {\n        v = c[j]\n      }\n      var a = vertexIds[v][0]\n      var b = vertexIds[v][1]\n      var w = vertexWeights[v]\n      var wi = 1.0 - w\n      var pa = this.positions[a]\n      var pb = this.positions[b]\n      for(var k=0; k<3; ++k) {\n        result[ptr++] = w * pa[k] + wi * pb[k]\n      }\n    }\n  }\n  this.contourCount = (ptr / 3)|0\n  this.contourPositions.update(result.subarray(0, ptr))\n  pool.free(result)\n}\n\nproto.update = function(params) {\n  params = params || {}\n  var gl = this.gl\n\n  this.dirty = true\n\n  if('contourEnable' in params) {\n    this.contourEnable = params.contourEnable\n  }\n  if('contourColor' in params) {\n    this.contourColor = params.contourColor\n  }\n  if('lineWidth' in params) {\n    this.lineWidth = params.lineWidth\n  }\n  if('lightPosition' in params) {\n    this.lightPosition = params.lightPosition\n  }\n\n  this.hasAlpha = false // default to no transparent draw\n  if('opacity' in params) {\n    this.opacity = params.opacity\n    if(this.opacity < 1) {\n      this.hasAlpha = true;\n    }\n  }\n  if('opacityscale' in params) {\n    this.opacityscale = params.opacityscale\n    this.hasAlpha = true;\n  }\n\n  if('ambient' in params) {\n    this.ambientLight  = params.ambient\n  }\n  if('diffuse' in params) {\n    this.diffuseLight = params.diffuse\n  }\n  if('specular' in params) {\n    this.specularLight = params.specular\n  }\n  if('roughness' in params) {\n    this.roughness = params.roughness\n  }\n  if('fresnel' in params) {\n    this.fresnel = params.fresnel\n  }\n\n  if(params.texture) {\n    this.texture.dispose()\n    this.texture = createTexture(gl, params.texture)\n  } else if (params.colormap) {\n    this.texture.shape = [256,256]\n    this.texture.minFilter = gl.LINEAR_MIPMAP_LINEAR\n    this.texture.magFilter = gl.LINEAR\n    this.texture.setPixels(genColormap(params.colormap, this.opacityscale))\n    this.texture.generateMipmap()\n  }\n\n  var cells = params.cells\n  var positions = params.positions\n\n  if(!positions || !cells) {\n    return\n  }\n\n  var tPos = []\n  var tCol = []\n  var tNor = []\n  var tUVs = []\n  var tIds = []\n\n  var ePos = []\n  var eCol = []\n  var eUVs = []\n  var eIds = []\n\n  var pPos = []\n  var pCol = []\n  var pUVs = []\n  var pSiz = []\n  var pIds = []\n\n  //Save geometry data for picking calculations\n  this.cells     = cells\n  this.positions = positions\n\n  //Compute normals\n  var vertexNormals = params.vertexNormals\n  var cellNormals   = params.cellNormals\n  var vertexNormalsEpsilon = params.vertexNormalsEpsilon === void(0) ? DEFAULT_VERTEX_NORMALS_EPSILON : params.vertexNormalsEpsilon\n  var faceNormalsEpsilon = params.faceNormalsEpsilon === void(0) ? DEFAULT_FACE_NORMALS_EPSILON : params.faceNormalsEpsilon\n  if(params.useFacetNormals && !cellNormals) {\n    cellNormals = normals.faceNormals(cells, positions, faceNormalsEpsilon)\n  }\n  if(!cellNormals && !vertexNormals) {\n    vertexNormals = normals.vertexNormals(cells, positions, vertexNormalsEpsilon)\n  }\n\n  //Compute colors\n  var vertexColors    = params.vertexColors\n  var cellColors      = params.cellColors\n  var meshColor       = params.meshColor || [1,1,1,1]\n\n  //UVs\n  var vertexUVs       = params.vertexUVs\n  var vertexIntensity = params.vertexIntensity\n  var cellUVs         = params.cellUVs\n  var cellIntensity   = params.cellIntensity\n\n  var intensityLo     = Infinity\n  var intensityHi     = -Infinity\n  if(!vertexUVs && !cellUVs) {\n    if(vertexIntensity) {\n      if(params.vertexIntensityBounds) {\n        intensityLo = +params.vertexIntensityBounds[0]\n        intensityHi = +params.vertexIntensityBounds[1]\n      } else {\n        for(var i=0; i<vertexIntensity.length; ++i) {\n          var f = vertexIntensity[i]\n          intensityLo = Math.min(intensityLo, f)\n          intensityHi = Math.max(intensityHi, f)\n        }\n      }\n    } else if(cellIntensity) {\n      for(var i=0; i<cellIntensity.length; ++i) {\n        var f = cellIntensity[i]\n        intensityLo = Math.min(intensityLo, f)\n        intensityHi = Math.max(intensityHi, f)\n      }\n    } else {\n      for(var i=0; i<positions.length; ++i) {\n        var f = positions[i][2]\n        intensityLo = Math.min(intensityLo, f)\n        intensityHi = Math.max(intensityHi, f)\n      }\n    }\n  }\n\n  if(vertexIntensity) {\n    this.intensity = vertexIntensity\n  } else if(cellIntensity) {\n    this.intensity = unpackIntensity(cells, positions.length, cellIntensity)\n  } else {\n    this.intensity = takeZComponent(positions)\n  }\n\n  //Point size\n  var pointSizes      = params.pointSizes\n  var meshPointSize   = params.pointSize || 1.0\n\n  //Update bounds\n  this.bounds       = [[Infinity,Infinity,Infinity], [-Infinity,-Infinity,-Infinity]]\n  for(var i=0; i<positions.length; ++i) {\n    var p = positions[i]\n    for(var j=0; j<3; ++j) {\n      if(isNaN(p[j]) || !isFinite(p[j])) {\n        continue\n      }\n      this.bounds[0][j] = Math.min(this.bounds[0][j], p[j])\n      this.bounds[1][j] = Math.max(this.bounds[1][j], p[j])\n    }\n  }\n\n  //Pack cells into buffers\n  var triangleCount = 0\n  var edgeCount = 0\n  var pointCount = 0\n\nfill_loop:\n  for(var i=0; i<cells.length; ++i) {\n    var cell = cells[i]\n    switch(cell.length) {\n      case 1:\n\n        var v = cell[0]\n        var p = positions[v]\n\n        //Check NaNs\n        for(var j=0; j<3; ++j) {\n          if(isNaN(p[j]) || !isFinite(p[j])) {\n            continue fill_loop\n          }\n        }\n\n        pPos.push(p[0], p[1], p[2])\n\n        var c\n        if(vertexColors) {\n          c = vertexColors[v]\n        } else if(cellColors) {\n          c = cellColors[i]\n        } else {\n          c = meshColor\n        }\n        if(this.opacityscale && vertexIntensity) {\n          tCol.push(c[0], c[1], c[2],\n            this.opacity * getOpacityFromScale(\n              (vertexIntensity[v] - intensityLo) / (intensityHi - intensityLo),\n              this.opacityscale\n            )\n          )\n        } else if(c.length === 3) {\n          pCol.push(c[0], c[1], c[2], this.opacity)\n        } else {\n          pCol.push(c[0], c[1], c[2], c[3] * this.opacity)\n          if(!this.hasAlpha && c[3] < 1) this.hasAlpha = true\n        }\n\n        var uv\n        if(vertexUVs) {\n          uv = vertexUVs[v]\n        } else if(vertexIntensity) {\n          uv = [\n            (vertexIntensity[v] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        } else if(cellUVs) {\n          uv = cellUVs[i]\n        } else if(cellIntensity) {\n          uv = [\n            (cellIntensity[i] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        } else {\n          uv = [\n            (p[2] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        }\n        pUVs.push(uv[0], uv[1])\n\n        if(pointSizes) {\n          pSiz.push(pointSizes[v])\n        } else {\n          pSiz.push(meshPointSize)\n        }\n\n        pIds.push(i)\n\n        pointCount += 1\n      break\n\n      case 2:\n\n        //Check NaNs\n        for(var j=0; j<2; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n          for(var k=0; k<3; ++k) {\n            if(isNaN(p[k]) || !isFinite(p[k])) {\n              continue fill_loop\n            }\n          }\n        }\n\n        for(var j=0; j<2; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n\n          ePos.push(p[0], p[1], p[2])\n\n          var c\n          if(vertexColors) {\n            c = vertexColors[v]\n          } else if(cellColors) {\n            c = cellColors[i]\n          } else {\n            c = meshColor\n          }\n          if(this.opacityscale && vertexIntensity) {\n            tCol.push(c[0], c[1], c[2],\n              this.opacity * getOpacityFromScale(\n                (vertexIntensity[v] - intensityLo) / (intensityHi - intensityLo),\n                this.opacityscale\n              )\n            )\n          } else if(c.length === 3) {\n            eCol.push(c[0], c[1], c[2], this.opacity)\n          } else {\n            eCol.push(c[0], c[1], c[2], c[3] * this.opacity)\n            if(!this.hasAlpha && c[3] < 1) this.hasAlpha = true\n          }\n\n          var uv\n          if(vertexUVs) {\n            uv = vertexUVs[v]\n          } else if(vertexIntensity) {\n            uv = [\n              (vertexIntensity[v] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else if(cellUVs) {\n            uv = cellUVs[i]\n          } else if(cellIntensity) {\n            uv = [\n              (cellIntensity[i] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else {\n            uv = [\n              (p[2] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          }\n          eUVs.push(uv[0], uv[1])\n\n          eIds.push(i)\n        }\n        edgeCount += 1\n      break\n\n      case 3:\n        //Check NaNs\n        for(var j=0; j<3; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n          for(var k=0; k<3; ++k) {\n            if(isNaN(p[k]) || !isFinite(p[k])) {\n              continue fill_loop\n            }\n          }\n        }\n\n        for(var j=0; j<3; ++j) {\n          var v = cell[2 - j]\n\n          var p = positions[v]\n          tPos.push(p[0], p[1], p[2])\n\n          var c\n          if(vertexColors) {\n            c = vertexColors[v]\n          } else if(cellColors) {\n            c = cellColors[i]\n          } else {\n            c = meshColor\n          }\n\n          if(this.opacityscale && vertexIntensity) {\n            tCol.push(c[0], c[1], c[2],\n              this.opacity * getOpacityFromScale(\n                (vertexIntensity[v] - intensityLo) / (intensityHi - intensityLo),\n                this.opacityscale\n              )\n            )\n          } else if(c.length === 3) {\n            tCol.push(c[0], c[1], c[2], this.opacity)\n          } else {\n            tCol.push(c[0], c[1], c[2], c[3] * this.opacity)\n            if(!this.hasAlpha && c[3] < 1) this.hasAlpha = true\n          }\n\n          var uv\n          if(vertexUVs) {\n            uv = vertexUVs[v]\n          } else if(vertexIntensity) {\n            uv = [\n              (vertexIntensity[v] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else if(cellUVs) {\n            uv = cellUVs[i]\n          } else if(cellIntensity) {\n            uv = [\n              (cellIntensity[i] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else {\n            uv = [\n              (p[2] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          }\n          tUVs.push(uv[0], uv[1])\n\n          var q\n          if(vertexNormals) {\n            q = vertexNormals[v]\n          } else {\n            q = cellNormals[i]\n          }\n          tNor.push(q[0], q[1], q[2])\n\n          tIds.push(i)\n        }\n        triangleCount += 1\n      break\n\n      default:\n      break\n    }\n  }\n\n  this.pointCount     = pointCount\n  this.edgeCount      = edgeCount\n  this.triangleCount  = triangleCount\n\n  this.pointPositions.update(pPos)\n  this.pointColors.update(pCol)\n  this.pointUVs.update(pUVs)\n  this.pointSizes.update(pSiz)\n  this.pointIds.update(new Uint32Array(pIds))\n\n  this.edgePositions.update(ePos)\n  this.edgeColors.update(eCol)\n  this.edgeUVs.update(eUVs)\n  this.edgeIds.update(new Uint32Array(eIds))\n\n  this.trianglePositions.update(tPos)\n  this.triangleColors.update(tCol)\n  this.triangleUVs.update(tUVs)\n  this.triangleNormals.update(tNor)\n  this.triangleIds.update(new Uint32Array(tIds))\n}\n\nproto.drawTransparent = proto.draw = function(params) {\n  params = params || {}\n  var gl          = this.gl\n  var model       = params.model      || IDENTITY\n  var view        = params.view       || IDENTITY\n  var projection  = params.projection || IDENTITY\n\n  var clipBounds = [[-1e6,-1e6,-1e6],[1e6,1e6,1e6]]\n  for(var i=0; i<3; ++i) {\n    clipBounds[0][i] = Math.max(clipBounds[0][i], this.clipBounds[0][i])\n    clipBounds[1][i] = Math.min(clipBounds[1][i], this.clipBounds[1][i])\n  }\n\n  var uniforms = {\n    model:      model,\n    view:       view,\n    projection: projection,\n    inverseModel: IDENTITY.slice(),\n\n    clipBounds: clipBounds,\n\n    kambient:   this.ambientLight,\n    kdiffuse:   this.diffuseLight,\n    kspecular:  this.specularLight,\n    roughness:  this.roughness,\n    fresnel:    this.fresnel,\n\n    eyePosition:   [0,0,0],\n    lightPosition: [0,0,0],\n\n    contourColor: this.contourColor,\n\n    texture:    0\n  }\n\n  uniforms.inverseModel = invert(uniforms.inverseModel, uniforms.model)\n\n  gl.disable(gl.CULL_FACE)\n\n  this.texture.bind(0)\n\n  var invCameraMatrix = new Array(16)\n  multiply(invCameraMatrix, uniforms.view, uniforms.model)\n  multiply(invCameraMatrix, uniforms.projection, invCameraMatrix)\n  invert(invCameraMatrix, invCameraMatrix)\n\n  for(var i=0; i<3; ++i) {\n    uniforms.eyePosition[i] = invCameraMatrix[12+i] / invCameraMatrix[15]\n  }\n\n  var w = invCameraMatrix[15]\n  for(var i=0; i<3; ++i) {\n    w += this.lightPosition[i] * invCameraMatrix[4*i+3]\n  }\n  for(var i=0; i<3; ++i) {\n    var s = invCameraMatrix[12+i]\n    for(var j=0; j<3; ++j) {\n      s += invCameraMatrix[4*j+i] * this.lightPosition[j]\n    }\n    uniforms.lightPosition[i] = s / w\n  }\n\n  if(this.triangleCount > 0) {\n    var shader = this.triShader\n    shader.bind()\n    shader.uniforms = uniforms\n\n    this.triangleVAO.bind()\n    gl.drawArrays(gl.TRIANGLES, 0, this.triangleCount*3)\n    this.triangleVAO.unbind()\n  }\n\n  if(this.edgeCount > 0 && this.lineWidth > 0) {\n    var shader = this.lineShader\n    shader.bind()\n    shader.uniforms = uniforms\n\n    this.edgeVAO.bind()\n    gl.lineWidth(this.lineWidth * this.pixelRatio)\n    gl.drawArrays(gl.LINES, 0, this.edgeCount*2)\n    this.edgeVAO.unbind()\n  }\n\n  if(this.pointCount > 0) {\n    var shader = this.pointShader\n    shader.bind()\n    shader.uniforms = uniforms\n\n    this.pointVAO.bind()\n    gl.drawArrays(gl.POINTS, 0, this.pointCount)\n    this.pointVAO.unbind()\n  }\n\n  if(this.contourEnable && this.contourCount > 0 && this.contourLineWidth > 0) {\n    var shader = this.contourShader\n    shader.bind()\n    shader.uniforms = uniforms\n\n    this.contourVAO.bind()\n    gl.drawArrays(gl.LINES, 0, this.contourCount)\n    this.contourVAO.unbind()\n  }\n}\n\nproto.drawPick = function(params) {\n  params = params || {}\n\n  var gl         = this.gl\n\n  var model      = params.model      || IDENTITY\n  var view       = params.view       || IDENTITY\n  var projection = params.projection || IDENTITY\n\n  var clipBounds = [[-1e6,-1e6,-1e6],[1e6,1e6,1e6]]\n  for(var i=0; i<3; ++i) {\n    clipBounds[0][i] = Math.max(clipBounds[0][i], this.clipBounds[0][i])\n    clipBounds[1][i] = Math.min(clipBounds[1][i], this.clipBounds[1][i])\n  }\n\n  //Save camera parameters\n  this._model      = [].slice.call(model)\n  this._view       = [].slice.call(view)\n  this._projection = [].slice.call(projection)\n  this._resolution = [gl.drawingBufferWidth, gl.drawingBufferHeight]\n\n  var uniforms = {\n    model:      model,\n    view:       view,\n    projection: projection,\n    clipBounds: clipBounds,\n    pickId:     this.pickId / 255.0,\n  }\n\n  var shader = this.pickShader\n  shader.bind()\n  shader.uniforms = uniforms\n\n  if(this.triangleCount > 0) {\n    this.triangleVAO.bind()\n    gl.drawArrays(gl.TRIANGLES, 0, this.triangleCount*3)\n    this.triangleVAO.unbind()\n  }\n\n  if(this.edgeCount > 0) {\n    this.edgeVAO.bind()\n    gl.lineWidth(this.lineWidth * this.pixelRatio)\n    gl.drawArrays(gl.LINES, 0, this.edgeCount*2)\n    this.edgeVAO.unbind()\n  }\n\n  if(this.pointCount > 0) {\n    var shader = this.pointPickShader\n    shader.bind()\n    shader.uniforms = uniforms\n\n    this.pointVAO.bind()\n    gl.drawArrays(gl.POINTS, 0, this.pointCount)\n    this.pointVAO.unbind()\n  }\n}\n\n\nproto.pick = function(pickData) {\n  if(!pickData) {\n    return null\n  }\n  if(pickData.id !== this.pickId) {\n    return null\n  }\n\n  var cellId    = pickData.value[0] + 256*pickData.value[1] + 65536*pickData.value[2]\n  var cell      = this.cells[cellId]\n  var positions = this.positions\n\n  var simplex   = new Array(cell.length)\n  for(var i=0; i<cell.length; ++i) {\n    simplex[i] = positions[cell[i]]\n  }\n\n  var data = closestPoint(\n    simplex,\n    [pickData.coord[0], this._resolution[1]-pickData.coord[1]],\n    this._model,\n    this._view,\n    this._projection,\n    this._resolution)\n\n  if(!data) {\n    return null\n  }\n\n  var weights = data[2]\n  var interpIntensity = 0.0\n  for(var i=0; i<cell.length; ++i) {\n    interpIntensity += weights[i] * this.intensity[cell[i]]\n  }\n\n  return {\n    position: data[1],\n    index:    cell[data[0]],\n    cell:     cell,\n    cellId:   cellId,\n    intensity:  interpIntensity,\n    dataCoordinate: this.positions[cell[data[0]]]\n  }\n}\n\n\nproto.dispose = function() {\n  this.texture.dispose()\n\n  this.triShader.dispose()\n  this.lineShader.dispose()\n  this.pointShader.dispose()\n  this.pickShader.dispose()\n  this.pointPickShader.dispose()\n\n  this.triangleVAO.dispose()\n  this.trianglePositions.dispose()\n  this.triangleColors.dispose()\n  this.triangleUVs.dispose()\n  this.triangleNormals.dispose()\n  this.triangleIds.dispose()\n\n  this.edgeVAO.dispose()\n  this.edgePositions.dispose()\n  this.edgeColors.dispose()\n  this.edgeUVs.dispose()\n  this.edgeIds.dispose()\n\n  this.pointVAO.dispose()\n  this.pointPositions.dispose()\n  this.pointColors.dispose()\n  this.pointUVs.dispose()\n  this.pointSizes.dispose()\n  this.pointIds.dispose()\n\n  this.contourVAO.dispose()\n  this.contourPositions.dispose()\n  this.contourShader.dispose()\n}\n\nfunction createMeshShader(gl) {\n  var shader = createShader(gl, meshShader.vertex, meshShader.fragment)\n  shader.attributes.position.location = 0\n  shader.attributes.color.location    = 2\n  shader.attributes.uv.location       = 3\n  shader.attributes.normal.location   = 4\n  return shader\n}\n\nfunction createWireShader(gl) {\n  var shader = createShader(gl, wireShader.vertex, wireShader.fragment)\n  shader.attributes.position.location = 0\n  shader.attributes.color.location    = 2\n  shader.attributes.uv.location       = 3\n  return shader\n}\n\nfunction createPointShader(gl) {\n  var shader = createShader(gl, pointShader.vertex, pointShader.fragment)\n  shader.attributes.position.location  = 0\n  shader.attributes.color.location     = 2\n  shader.attributes.uv.location        = 3\n  shader.attributes.pointSize.location = 4\n  return shader\n}\n\nfunction createPickShader(gl) {\n  var shader = createShader(gl, pickShader.vertex, pickShader.fragment)\n  shader.attributes.position.location = 0\n  shader.attributes.id.location       = 1\n  return shader\n}\n\nfunction createPointPickShader(gl) {\n  var shader = createShader(gl, pointPickShader.vertex, pointPickShader.fragment)\n  shader.attributes.position.location  = 0\n  shader.attributes.id.location        = 1\n  shader.attributes.pointSize.location = 4\n  return shader\n}\n\nfunction createContourShader(gl) {\n  var shader = createShader(gl, contourShader.vertex, contourShader.fragment)\n  shader.attributes.position.location = 0\n  return shader\n}\n\nfunction createSimplicialMesh(gl, params) {\n  if (arguments.length === 1) {\n    params = gl;\n    gl = params.gl;\n  }\n\n  //enable derivatives for face normals\n  var ext = gl.getExtension('OES_standard_derivatives') || gl.getExtension('MOZ_OES_standard_derivatives') || gl.getExtension('WEBKIT_OES_standard_derivatives')\n  if (!ext)\n    throw new Error('derivatives not supported')\n\n  var triShader       = createMeshShader(gl)\n  var lineShader      = createWireShader(gl)\n  var pointShader     = createPointShader(gl)\n  var pickShader      = createPickShader(gl)\n  var pointPickShader = createPointPickShader(gl)\n  var contourShader   = createContourShader(gl)\n\n  var meshTexture       = createTexture(gl,\n    ndarray(new Uint8Array([255,255,255,255]), [1,1,4]))\n  meshTexture.generateMipmap()\n  meshTexture.minFilter = gl.LINEAR_MIPMAP_LINEAR\n  meshTexture.magFilter = gl.LINEAR\n\n  var trianglePositions = createBuffer(gl)\n  var triangleColors    = createBuffer(gl)\n  var triangleUVs       = createBuffer(gl)\n  var triangleNormals   = createBuffer(gl)\n  var triangleIds       = createBuffer(gl)\n  var triangleVAO       = createVAO(gl, [\n    { buffer: trianglePositions,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: triangleIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: triangleColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: triangleUVs,\n      type: gl.FLOAT,\n      size: 2\n    },\n    { buffer: triangleNormals,\n      type: gl.FLOAT,\n      size: 3\n    }\n  ])\n\n  var edgePositions = createBuffer(gl)\n  var edgeColors    = createBuffer(gl)\n  var edgeUVs       = createBuffer(gl)\n  var edgeIds       = createBuffer(gl)\n  var edgeVAO       = createVAO(gl, [\n    { buffer: edgePositions,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: edgeIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: edgeColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: edgeUVs,\n      type: gl.FLOAT,\n      size: 2\n    }\n  ])\n\n  var pointPositions  = createBuffer(gl)\n  var pointColors     = createBuffer(gl)\n  var pointUVs        = createBuffer(gl)\n  var pointSizes      = createBuffer(gl)\n  var pointIds        = createBuffer(gl)\n  var pointVAO        = createVAO(gl, [\n    { buffer: pointPositions,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: pointIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: pointColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: pointUVs,\n      type: gl.FLOAT,\n      size: 2\n    },\n    { buffer: pointSizes,\n      type: gl.FLOAT,\n      size: 1\n    }\n  ])\n\n  var contourPositions = createBuffer(gl)\n  var contourVAO       = createVAO(gl, [\n    { buffer: contourPositions,\n      type:   gl.FLOAT,\n      size:   3\n    }])\n\n  var mesh = new SimplicialMesh(gl\n    , meshTexture\n    , triShader\n    , lineShader\n    , pointShader\n    , pickShader\n    , pointPickShader\n    , contourShader\n    , trianglePositions\n    , triangleIds\n    , triangleColors\n    , triangleUVs\n    , triangleNormals\n    , triangleVAO\n    , edgePositions\n    , edgeIds\n    , edgeColors\n    , edgeUVs\n    , edgeVAO\n    , pointPositions\n    , pointIds\n    , pointColors\n    , pointUVs\n    , pointSizes\n    , pointVAO\n    , contourPositions\n    , contourVAO)\n\n  mesh.update(params)\n\n  return mesh\n}\n\nmodule.exports = createSimplicialMesh\n\n},{\"./lib/closest-point\":278,\"./lib/shaders\":279,\"colormap\":126,\"gl-buffer\":241,\"gl-mat4/invert\":265,\"gl-mat4/multiply\":267,\"gl-shader\":301,\"gl-texture2d\":322,\"gl-vao\":327,\"ndarray\":450,\"normals\":453,\"simplicial-complex-contour\":518,\"typedarray-pool\":545}],281:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createBoxes\n\nvar createBuffer = _dereq_('gl-buffer')\nvar createShader = _dereq_('gl-shader')\n\nvar shaders = _dereq_('./shaders')\n\nfunction Boxes(plot, vbo, shader) {\n  this.plot   = plot\n  this.vbo    = vbo\n  this.shader = shader\n}\n\nvar proto = Boxes.prototype\n\nproto.bind = function() {\n  var shader = this.shader\n  this.vbo.bind()\n  this.shader.bind()\n  shader.attributes.coord.pointer()\n  shader.uniforms.screenBox = this.plot.screenBox\n}\n\nproto.drawBox = (function() {\n  var lo = [0,0]\n  var hi = [0,0]\n  return function(loX, loY, hiX, hiY, color) {\n    var plot       = this.plot\n    var shader     = this.shader\n    var gl         = plot.gl\n\n    lo[0] = loX\n    lo[1] = loY\n    hi[0] = hiX\n    hi[1] = hiY\n\n    shader.uniforms.lo     = lo\n    shader.uniforms.hi     = hi\n    shader.uniforms.color  = color\n\n    gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4)\n  }\n}())\n\nproto.dispose = function() {\n  this.vbo.dispose()\n  this.shader.dispose()\n}\n\nfunction createBoxes(plot) {\n  var gl  = plot.gl\n  var vbo = createBuffer(gl, [\n    0,0,\n    0,1,\n    1,0,\n    1,1])\n  var shader  = createShader(gl, shaders.boxVert, shaders.lineFrag)\n  return new Boxes(plot, vbo, shader)\n}\n\n},{\"./shaders\":284,\"gl-buffer\":241,\"gl-shader\":301}],282:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createGrid\n\nvar createBuffer  = _dereq_('gl-buffer')\nvar createShader  = _dereq_('gl-shader')\nvar bsearch       = _dereq_('binary-search-bounds')\nvar shaders       = _dereq_('./shaders')\n\nfunction Grid(plot, vbo, shader, tickShader) {\n  this.plot   = plot\n  this.vbo    = vbo\n  this.shader = shader\n  this.tickShader = tickShader\n  this.ticks  = [[], []]\n}\n\nfunction compareTickNum(a, b) {\n  return a - b\n}\n\nvar proto = Grid.prototype\n\nproto.draw = (function() {\n\n  var DATA_SHIFT = [0,0]\n  var DATA_SCALE = [0,0]\n  var DATA_AXIS  = [0,0]\n\n  return function() {\n    var plot       = this.plot\n    var vbo        = this.vbo\n    var shader     = this.shader\n    var ticks      = this.ticks\n    var gl         = plot.gl\n    var bounds     = plot._tickBounds\n    var dataBox    = plot.dataBox\n    var viewPixels = plot.viewBox\n    var lineWidth  = plot.gridLineWidth\n    var gridColor  = plot.gridLineColor\n    var gridEnable = plot.gridLineEnable\n    var pixelRatio = plot.pixelRatio\n\n    for(var i=0; i<2; ++i) {\n      var lo = bounds[i]\n      var hi = bounds[i+2]\n      var boundScale = hi - lo\n      var dataCenter  = 0.5 * (dataBox[i+2] + dataBox[i])\n      var dataWidth   = dataBox[i+2] - dataBox[i]\n      DATA_SCALE[i] = 2.0 * boundScale / dataWidth\n      DATA_SHIFT[i] = 2.0 * (lo - dataCenter) / dataWidth\n    }\n\n    shader.bind()\n    vbo.bind()\n    shader.attributes.dataCoord.pointer()\n    shader.uniforms.dataShift = DATA_SHIFT\n    shader.uniforms.dataScale = DATA_SCALE\n\n    var offset = 0\n    for(var i=0; i<2; ++i) {\n      DATA_AXIS[0] = DATA_AXIS[1] = 0\n      DATA_AXIS[i] = 1\n      shader.uniforms.dataAxis  = DATA_AXIS\n      shader.uniforms.lineWidth = lineWidth[i] / (viewPixels[i+2] - viewPixels[i]) * pixelRatio\n      shader.uniforms.color     = gridColor[i]\n\n      var size = ticks[i].length * 6\n      if(gridEnable[i] && size) {\n        gl.drawArrays(gl.TRIANGLES, offset, size)\n      }\n      offset += size\n    }\n  }\n})()\n\nproto.drawTickMarks = (function() {\n  var DATA_SHIFT = [0,0]\n  var DATA_SCALE = [0,0]\n  var X_AXIS     = [1,0]\n  var Y_AXIS     = [0,1]\n  var SCR_OFFSET = [0,0]\n  var TICK_SCALE = [0,0]\n\n  return function() {\n    var plot       = this.plot\n    var vbo        = this.vbo\n    var shader     = this.tickShader\n    var ticks      = this.ticks\n    var gl         = plot.gl\n    var bounds     = plot._tickBounds\n    var dataBox    = plot.dataBox\n    var viewBox    = plot.viewBox\n    var pixelRatio = plot.pixelRatio\n    var screenBox  = plot.screenBox\n\n    var screenWidth  = screenBox[2] - screenBox[0]\n    var screenHeight = screenBox[3] - screenBox[1]\n    var viewWidth    = viewBox[2]   - viewBox[0]\n    var viewHeight   = viewBox[3]   - viewBox[1]\n\n    for(var i=0; i<2; ++i) {\n      var lo = bounds[i]\n      var hi = bounds[i+2]\n      var boundScale = hi - lo\n      var dataCenter  = 0.5 * (dataBox[i+2] + dataBox[i])\n      var dataWidth   = (dataBox[i+2] - dataBox[i])\n      DATA_SCALE[i] = 2.0 * boundScale / dataWidth\n      DATA_SHIFT[i] = 2.0 * (lo - dataCenter) / dataWidth\n    }\n\n    DATA_SCALE[0] *= viewWidth / screenWidth\n    DATA_SHIFT[0] *= viewWidth / screenWidth\n\n    DATA_SCALE[1] *= viewHeight / screenHeight\n    DATA_SHIFT[1] *= viewHeight / screenHeight\n\n    shader.bind()\n    vbo.bind()\n\n    shader.attributes.dataCoord.pointer()\n\n    var uniforms = shader.uniforms\n    uniforms.dataShift = DATA_SHIFT\n    uniforms.dataScale = DATA_SCALE\n\n    var tickMarkLength = plot.tickMarkLength\n    var tickMarkWidth  = plot.tickMarkWidth\n    var tickMarkColor  = plot.tickMarkColor\n\n    var xTicksOffset = 0\n    var yTicksOffset = ticks[0].length * 6\n\n    var xStart = Math.min(bsearch.ge(ticks[0], (dataBox[0] - bounds[0]) / (bounds[2] - bounds[0]), compareTickNum), ticks[0].length)\n    var xEnd   = Math.min(bsearch.gt(ticks[0], (dataBox[2] - bounds[0]) / (bounds[2] - bounds[0]), compareTickNum), ticks[0].length)\n    var xOffset = xTicksOffset + 6 * xStart\n    var xCount  = 6 * Math.max(0, xEnd - xStart)\n\n    var yStart = Math.min(bsearch.ge(ticks[1], (dataBox[1] - bounds[1]) / (bounds[3] - bounds[1]), compareTickNum), ticks[1].length)\n    var yEnd   = Math.min(bsearch.gt(ticks[1], (dataBox[3] - bounds[1]) / (bounds[3] - bounds[1]), compareTickNum), ticks[1].length)\n    var yOffset = yTicksOffset + 6 * yStart\n    var yCount  = 6 * Math.max(0, yEnd - yStart)\n\n    SCR_OFFSET[0]         = 2.0 * (viewBox[0] - tickMarkLength[1]) / screenWidth - 1.0\n    SCR_OFFSET[1]         = (viewBox[3] + viewBox[1]) / screenHeight - 1.0\n    TICK_SCALE[0]         = tickMarkLength[1] * pixelRatio / screenWidth\n    TICK_SCALE[1]         = tickMarkWidth[1]  * pixelRatio / screenHeight\n\n    if(yCount) {\n      uniforms.color        = tickMarkColor[1]\n      uniforms.tickScale    = TICK_SCALE\n      uniforms.dataAxis     = Y_AXIS\n      uniforms.screenOffset = SCR_OFFSET\n      gl.drawArrays(gl.TRIANGLES, yOffset, yCount)\n    }\n\n    SCR_OFFSET[0]         = (viewBox[2] + viewBox[0]) / screenWidth - 1.0\n    SCR_OFFSET[1]         = 2.0 * (viewBox[1] - tickMarkLength[0]) / screenHeight - 1.0\n    TICK_SCALE[0]         = tickMarkWidth[0]  * pixelRatio / screenWidth\n    TICK_SCALE[1]         = tickMarkLength[0] * pixelRatio / screenHeight\n\n    if(xCount) {\n      uniforms.color        = tickMarkColor[0]\n      uniforms.tickScale    = TICK_SCALE\n      uniforms.dataAxis     = X_AXIS\n      uniforms.screenOffset = SCR_OFFSET\n      gl.drawArrays(gl.TRIANGLES, xOffset, xCount)\n    }\n\n    SCR_OFFSET[0]         = 2.0 * (viewBox[2] + tickMarkLength[3]) / screenWidth - 1.0\n    SCR_OFFSET[1]         = (viewBox[3] + viewBox[1]) / screenHeight - 1.0\n    TICK_SCALE[0]         = tickMarkLength[3] * pixelRatio / screenWidth\n    TICK_SCALE[1]         = tickMarkWidth[3]  * pixelRatio / screenHeight\n\n    if(yCount) {\n      uniforms.color        = tickMarkColor[3]\n      uniforms.tickScale    = TICK_SCALE\n      uniforms.dataAxis     = Y_AXIS\n      uniforms.screenOffset = SCR_OFFSET\n      gl.drawArrays(gl.TRIANGLES, yOffset, yCount)\n    }\n\n    SCR_OFFSET[0]         = (viewBox[2] + viewBox[0]) / screenWidth - 1.0\n    SCR_OFFSET[1]         = 2.0 * (viewBox[3] + tickMarkLength[2]) / screenHeight - 1.0\n    TICK_SCALE[0]         = tickMarkWidth[2]  * pixelRatio / screenWidth\n    TICK_SCALE[1]         = tickMarkLength[2] * pixelRatio / screenHeight\n\n    if(xCount) {\n      uniforms.color        = tickMarkColor[2]\n      uniforms.tickScale    = TICK_SCALE\n      uniforms.dataAxis     = X_AXIS\n      uniforms.screenOffset = SCR_OFFSET\n      gl.drawArrays(gl.TRIANGLES, xOffset, xCount)\n    }\n  }\n})()\n\nproto.update = (function() {\n  var OFFSET_X = [1,  1, -1, -1,  1, -1]\n  var OFFSET_Y = [1, -1,  1,  1, -1, -1]\n\n  return function(options) {\n    var ticks  = options.ticks\n    var bounds = options.bounds\n    var data   = new Float32Array(6 * 3 * (ticks[0].length + ticks[1].length))\n\n    var zeroLineEnable = this.plot.zeroLineEnable\n\n    var ptr    = 0\n    var gridTicks = [[], []]\n    for(var dim=0; dim<2; ++dim) {\n      var localTicks = gridTicks[dim]\n      var axisTicks = ticks[dim]\n      var lo = bounds[dim]\n      var hi = bounds[dim+2]\n      for(var i=0; i<axisTicks.length; ++i) {\n        var x = (axisTicks[i].x - lo) / (hi - lo)\n        localTicks.push(x)\n        for(var j=0; j<6; ++j) {\n          data[ptr++] = x\n          data[ptr++] = OFFSET_X[j]\n          data[ptr++] = OFFSET_Y[j]\n        }\n      }\n    }\n\n    this.ticks = gridTicks\n    this.vbo.update(data)\n  }\n})()\n\nproto.dispose = function() {\n  this.vbo.dispose()\n  this.shader.dispose()\n  this.tickShader.dispose()\n}\n\nfunction createGrid(plot) {\n  var gl     = plot.gl\n  var vbo    = createBuffer(gl)\n  var shader = createShader(gl, shaders.gridVert, shaders.gridFrag)\n  var tickShader = createShader(gl, shaders.tickVert, shaders.gridFrag)\n  var grid   = new Grid(plot, vbo, shader, tickShader)\n  return grid\n}\n\n},{\"./shaders\":284,\"binary-search-bounds\":286,\"gl-buffer\":241,\"gl-shader\":301}],283:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createLines\n\nvar createBuffer = _dereq_('gl-buffer')\nvar createShader = _dereq_('gl-shader')\n\nvar shaders = _dereq_('./shaders')\n\nfunction Lines(plot, vbo, shader) {\n  this.plot   = plot\n  this.vbo    = vbo\n  this.shader = shader\n}\n\nvar proto = Lines.prototype\n\nproto.bind = function() {\n  var shader = this.shader\n  this.vbo.bind()\n  this.shader.bind()\n  shader.attributes.coord.pointer()\n  shader.uniforms.screenBox = this.plot.screenBox\n}\n\nproto.drawLine = (function() {\n  var start = [0,0]\n  var end   = [0,0]\n  return function(startX, startY, endX, endY, width, color) {\n    var plot       = this.plot\n    var shader     = this.shader\n    var gl         = plot.gl\n\n    start[0] = startX\n    start[1] = startY\n    end[0]   = endX\n    end[1]   = endY\n\n    shader.uniforms.start  = start\n    shader.uniforms.end    = end\n    shader.uniforms.width  = width * plot.pixelRatio\n    shader.uniforms.color  = color\n\n    gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4)\n  }\n}())\n\nproto.dispose = function() {\n  this.vbo.dispose()\n  this.shader.dispose()\n}\n\nfunction createLines(plot) {\n  var gl  = plot.gl\n  var vbo = createBuffer(gl, [\n    -1,-1,\n    -1,1,\n    1,-1,\n    1,1])\n  var shader  = createShader(gl, shaders.lineVert, shaders.lineFrag)\n  var lines   = new Lines(plot, vbo, shader)\n  return lines\n}\n\n},{\"./shaders\":284,\"gl-buffer\":241,\"gl-shader\":301}],284:[function(_dereq_,module,exports){\n'use strict'\n\nvar glslify = _dereq_('glslify')\n\nvar FRAGMENT = glslify([\"precision lowp float;\\n#define GLSLIFY 1\\nuniform vec4 color;\\nvoid main() {\\n  gl_FragColor = vec4(color.xyz * color.w, color.w);\\n}\\n\"])\n\nmodule.exports = {\n  lineVert: glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec2 coord;\\n\\nuniform vec4 screenBox;\\nuniform vec2 start, end;\\nuniform float width;\\n\\nvec2 perp(vec2 v) {\\n  return vec2(v.y, -v.x);\\n}\\n\\nvec2 screen(vec2 v) {\\n  return 2.0 * (v - screenBox.xy) / (screenBox.zw - screenBox.xy) - 1.0;\\n}\\n\\nvoid main() {\\n  vec2 delta = normalize(perp(start - end));\\n  vec2 offset = mix(start, end, 0.5 * (coord.y+1.0));\\n  gl_Position = vec4(screen(offset + 0.5 * width * delta * coord.x), 0, 1);\\n}\\n\"]),\n  lineFrag: FRAGMENT,\n  textVert: glslify([\"#define GLSLIFY 1\\nattribute vec3 textCoordinate;\\n\\nuniform vec2 dataScale, dataShift, dataAxis, screenOffset, textScale;\\nuniform float angle;\\n\\nvoid main() {\\n  float dataOffset  = textCoordinate.z;\\n  vec2 glyphOffset  = textCoordinate.xy;\\n  mat2 glyphMatrix = mat2(cos(angle), sin(angle), -sin(angle), cos(angle));\\n  vec2 screenCoordinate = dataAxis * (dataScale * dataOffset + dataShift) +\\n    glyphMatrix * glyphOffset * textScale + screenOffset;\\n  gl_Position = vec4(screenCoordinate, 0, 1);\\n}\\n\"]),\n  textFrag: FRAGMENT,\n  gridVert: glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec3 dataCoord;\\n\\nuniform vec2 dataAxis, dataShift, dataScale;\\nuniform float lineWidth;\\n\\nvoid main() {\\n  vec2 pos = dataAxis * (dataScale * dataCoord.x + dataShift);\\n  pos += 10.0 * dataCoord.y * vec2(dataAxis.y, -dataAxis.x) + dataCoord.z * lineWidth;\\n  gl_Position = vec4(pos, 0, 1);\\n}\\n\"]),\n  gridFrag: FRAGMENT,\n  boxVert:  glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec2 coord;\\n\\nuniform vec4 screenBox;\\nuniform vec2 lo, hi;\\n\\nvec2 screen(vec2 v) {\\n  return 2.0 * (v - screenBox.xy) / (screenBox.zw - screenBox.xy) - 1.0;\\n}\\n\\nvoid main() {\\n  gl_Position = vec4(screen(mix(lo, hi, coord)), 0, 1);\\n}\\n\"]),\n  tickVert: glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec3 dataCoord;\\n\\nuniform vec2 dataAxis, dataShift, dataScale, screenOffset, tickScale;\\n\\nvoid main() {\\n  vec2 pos = dataAxis * (dataScale * dataCoord.x + dataShift);\\n  gl_Position = vec4(pos + tickScale*dataCoord.yz + screenOffset, 0, 1);\\n}\\n\"])\n}\n\n},{\"glslify\":409}],285:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createTextElements\n\nvar createBuffer = _dereq_('gl-buffer')\nvar createShader = _dereq_('gl-shader')\nvar getText      = _dereq_('text-cache')\nvar bsearch      = _dereq_('binary-search-bounds')\nvar shaders      = _dereq_('./shaders')\n\nfunction TextElements(plot, vbo, shader) {\n  this.plot         = plot\n  this.vbo          = vbo\n  this.shader       = shader\n  this.tickOffset   = [[],[]]\n  this.tickX        = [[],[]]\n  this.labelOffset  = [0,0]\n  this.labelCount   = [0,0]\n}\n\nvar proto = TextElements.prototype\n\nproto.drawTicks = (function() {\n  var DATA_AXIS = [0,0]\n  var SCREEN_OFFSET = [0,0]\n  var ZERO_2 = [0,0]\n\n  return function(axis) {\n    var plot        = this.plot\n    var shader      = this.shader\n    var tickX       = this.tickX[axis]\n    var tickOffset  = this.tickOffset[axis]\n    var gl          = plot.gl\n    var viewBox     = plot.viewBox\n    var dataBox     = plot.dataBox\n    var screenBox   = plot.screenBox\n    var pixelRatio  = plot.pixelRatio\n    var tickEnable  = plot.tickEnable\n    var tickPad     = plot.tickPad\n    var textColor   = plot.tickColor\n    var textAngle   = plot.tickAngle\n    // todo check if this should be used (now unused)\n    // var tickLength  = plot.tickMarkLength\n\n    var labelEnable = plot.labelEnable\n    var labelPad    = plot.labelPad\n    var labelColor  = plot.labelColor\n    var labelAngle  = plot.labelAngle\n    var labelOffset = this.labelOffset[axis]\n    var labelCount  = this.labelCount[axis]\n\n    var start = bsearch.lt(tickX, dataBox[axis])\n    var end   = bsearch.le(tickX, dataBox[axis+2])\n\n    DATA_AXIS[0]    = DATA_AXIS[1] = 0\n    DATA_AXIS[axis] = 1\n\n    SCREEN_OFFSET[axis] = (viewBox[2+axis] + viewBox[axis]) / (screenBox[2+axis] - screenBox[axis]) - 1.0\n\n    var screenScale = 2.0 / screenBox[2+(axis^1)] - screenBox[axis^1]\n\n    SCREEN_OFFSET[axis^1] = screenScale * viewBox[axis^1] - 1.0\n    if(tickEnable[axis]) {\n      SCREEN_OFFSET[axis^1] -= screenScale * pixelRatio * tickPad[axis]\n      if(start < end && tickOffset[end] > tickOffset[start]) {\n        shader.uniforms.dataAxis     = DATA_AXIS\n        shader.uniforms.screenOffset = SCREEN_OFFSET\n        shader.uniforms.color        = textColor[axis]\n        shader.uniforms.angle        = textAngle[axis]\n        gl.drawArrays(\n          gl.TRIANGLES,\n          tickOffset[start],\n          tickOffset[end] - tickOffset[start])\n      }\n    }\n    if(labelEnable[axis] && labelCount) {\n      SCREEN_OFFSET[axis^1] -= screenScale * pixelRatio * labelPad[axis]\n      shader.uniforms.dataAxis     = ZERO_2\n      shader.uniforms.screenOffset = SCREEN_OFFSET\n      shader.uniforms.color        = labelColor[axis]\n      shader.uniforms.angle        = labelAngle[axis]\n      gl.drawArrays(\n        gl.TRIANGLES,\n        labelOffset,\n        labelCount)\n    }\n\n    SCREEN_OFFSET[axis^1] = screenScale * viewBox[2+(axis^1)] - 1.0\n    if(tickEnable[axis+2]) {\n      SCREEN_OFFSET[axis^1] += screenScale * pixelRatio * tickPad[axis+2]\n      if(start < end && tickOffset[end] > tickOffset[start]) {\n        shader.uniforms.dataAxis     = DATA_AXIS\n        shader.uniforms.screenOffset = SCREEN_OFFSET\n        shader.uniforms.color        = textColor[axis+2]\n        shader.uniforms.angle        = textAngle[axis+2]\n        gl.drawArrays(\n          gl.TRIANGLES,\n          tickOffset[start],\n          tickOffset[end] - tickOffset[start])\n      }\n    }\n    if(labelEnable[axis+2] && labelCount) {\n      SCREEN_OFFSET[axis^1] += screenScale * pixelRatio * labelPad[axis+2]\n      shader.uniforms.dataAxis     = ZERO_2\n      shader.uniforms.screenOffset = SCREEN_OFFSET\n      shader.uniforms.color        = labelColor[axis+2]\n      shader.uniforms.angle        = labelAngle[axis+2]\n      gl.drawArrays(\n        gl.TRIANGLES,\n        labelOffset,\n        labelCount)\n    }\n\n  }\n})()\n\nproto.drawTitle = (function() {\n  var DATA_AXIS = [0,0]\n  var SCREEN_OFFSET = [0,0]\n\n  return function() {\n    var plot        = this.plot\n    var shader      = this.shader\n    var gl          = plot.gl\n    var screenBox   = plot.screenBox\n    var titleCenter = plot.titleCenter\n    var titleAngle  = plot.titleAngle\n    var titleColor  = plot.titleColor\n    var pixelRatio  = plot.pixelRatio\n\n    if(!this.titleCount) {\n      return\n    }\n\n    for(var i=0; i<2; ++i) {\n      SCREEN_OFFSET[i] = 2.0 * (titleCenter[i]*pixelRatio - screenBox[i]) /\n        (screenBox[2+i] - screenBox[i]) - 1\n    }\n\n    shader.bind()\n    shader.uniforms.dataAxis      = DATA_AXIS\n    shader.uniforms.screenOffset  = SCREEN_OFFSET\n    shader.uniforms.angle         = titleAngle\n    shader.uniforms.color         = titleColor\n\n    gl.drawArrays(gl.TRIANGLES, this.titleOffset, this.titleCount)\n  }\n})()\n\nproto.bind = (function() {\n  var DATA_SHIFT = [0,0]\n  var DATA_SCALE = [0,0]\n  var TEXT_SCALE = [0,0]\n\n  return function() {\n    var plot      = this.plot\n    var shader    = this.shader\n    var bounds    = plot._tickBounds\n    var dataBox   = plot.dataBox\n    var screenBox = plot.screenBox\n    var viewBox   = plot.viewBox\n\n    shader.bind()\n\n    //Set up coordinate scaling uniforms\n    for(var i=0; i<2; ++i) {\n\n      var lo = bounds[i]\n      var hi = bounds[i+2]\n      var boundScale = hi - lo\n      var dataCenter  = 0.5 * (dataBox[i+2] + dataBox[i])\n      var dataWidth   = (dataBox[i+2] - dataBox[i])\n\n      var viewLo = viewBox[i]\n      var viewHi = viewBox[i+2]\n      var viewScale = viewHi - viewLo\n      var screenLo = screenBox[i]\n      var screenHi = screenBox[i+2]\n      var screenScale = screenHi - screenLo\n\n      DATA_SCALE[i] = 2.0 * boundScale / dataWidth * viewScale / screenScale\n      DATA_SHIFT[i] = 2.0 * (lo - dataCenter) / dataWidth * viewScale / screenScale\n    }\n\n    TEXT_SCALE[1] = 2.0 * plot.pixelRatio / (screenBox[3] - screenBox[1])\n    TEXT_SCALE[0] = TEXT_SCALE[1] * (screenBox[3] - screenBox[1]) / (screenBox[2] - screenBox[0])\n\n    shader.uniforms.dataScale = DATA_SCALE\n    shader.uniforms.dataShift = DATA_SHIFT\n    shader.uniforms.textScale = TEXT_SCALE\n\n    //Set attributes\n    this.vbo.bind()\n    shader.attributes.textCoordinate.pointer()\n  }\n})()\n\nproto.update = function(options) {\n  var vertices  = []\n  var axesTicks = options.ticks\n  var bounds    = options.bounds\n  var i, j, k, data, scale, dimension\n\n  for(dimension=0; dimension<2; ++dimension) {\n    var offsets = [Math.floor(vertices.length/3)], tickX = [-Infinity]\n\n    //Copy vertices over to buffer\n    var ticks = axesTicks[dimension]\n    for(i=0; i<ticks.length; ++i) {\n      var tick  = ticks[i]\n      var x     = tick.x\n      var text  = tick.text\n      var font  = tick.font || 'sans-serif'\n      scale = (tick.fontSize || 12)\n\n      var coordScale = 1.0 / (bounds[dimension+2] - bounds[dimension])\n      var coordShift = bounds[dimension]\n\n      var rows = text.split('\\n')\n      for(var r = 0; r < rows.length; r++) {\n        data = getText(font, rows[r]).data\n        for (j = 0; j < data.length; j += 2) {\n          vertices.push(\n              data[j] * scale,\n              -data[j + 1] * scale - r * scale * 1.2,\n              (x - coordShift) * coordScale)\n        }\n      }\n\n      offsets.push(Math.floor(vertices.length/3))\n      tickX.push(x)\n    }\n\n    this.tickOffset[dimension] = offsets\n    this.tickX[dimension] = tickX\n  }\n\n  //Add labels\n  for(dimension=0; dimension<2; ++dimension) {\n    this.labelOffset[dimension] = Math.floor(vertices.length/3)\n\n    data  = getText(options.labelFont[dimension], options.labels[dimension], { textAlign: 'center' }).data\n    scale = options.labelSize[dimension]\n    for(i=0; i<data.length; i+=2) {\n      vertices.push(data[i]*scale, -data[i+1]*scale, 0)\n    }\n\n    this.labelCount[dimension] =\n      Math.floor(vertices.length/3) - this.labelOffset[dimension]\n  }\n\n  //Add title\n  this.titleOffset = Math.floor(vertices.length/3)\n  data = getText(options.titleFont, options.title).data\n  scale = options.titleSize\n  for(i=0; i<data.length; i+=2) {\n    vertices.push(data[i]*scale, -data[i+1]*scale, 0)\n  }\n  this.titleCount = Math.floor(vertices.length/3) - this.titleOffset\n\n  //Upload new vertices\n  this.vbo.update(vertices)\n}\n\nproto.dispose = function() {\n  this.vbo.dispose()\n  this.shader.dispose()\n}\n\nfunction createTextElements(plot) {\n  var gl = plot.gl\n  var vbo = createBuffer(gl)\n  var shader = createShader(gl, shaders.textVert, shaders.textFrag)\n  var text = new TextElements(plot, vbo, shader)\n  return text\n}\n\n},{\"./shaders\":284,\"binary-search-bounds\":286,\"gl-buffer\":241,\"gl-shader\":301,\"text-cache\":536}],286:[function(_dereq_,module,exports){\narguments[4][111][0].apply(exports,arguments)\n},{\"dup\":111}],287:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createGLPlot2D\n\nvar createPick = _dereq_('gl-select-static')\n\nvar createGrid = _dereq_('./lib/grid')\nvar createText = _dereq_('./lib/text')\nvar createLine = _dereq_('./lib/line')\nvar createBox  = _dereq_('./lib/box')\n\nfunction GLPlot2D(gl, pickBuffer) {\n  this.gl               = gl\n  this.pickBuffer       = pickBuffer\n\n  this.screenBox        = [0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight]\n  this.viewBox          = [0, 0, 0, 0]\n  this.dataBox          = [-10, -10, 10, 10]\n\n  this.gridLineEnable   = [true,true]\n  this.gridLineWidth    = [1,1]\n  this.gridLineColor    = [[0,0,0,1],\n                           [0,0,0,1]]\n\n  this.pixelRatio       = 1\n\n  this.tickMarkLength   = [0,0,0,0]\n  this.tickMarkWidth    = [0,0,0,0]\n  this.tickMarkColor    = [[0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1]]\n\n  this.tickPad          = [15,15,15,15]\n  this.tickAngle        = [0,0,0,0]\n  this.tickEnable       = [true,true,true,true]\n  this.tickColor        = [[0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1]]\n\n  this.labelPad         = [15,15,15,15]\n  this.labelAngle       = [0,Math.PI/2,0,3.0*Math.PI/2]\n  this.labelEnable      = [true,true,true,true]\n  this.labelColor       = [[0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1]]\n\n  this.titleCenter      = [0,0]\n  this.titleEnable      = true\n  this.titleAngle       = 0\n  this.titleColor       = [0,0,0,1]\n\n  this.borderColor      = [0,0,0,0]\n  this.backgroundColor  = [0,0,0,0]\n\n  this.zeroLineEnable   = [true, true]\n  this.zeroLineWidth    = [4, 4]\n  this.zeroLineColor    = [[0, 0, 0, 1],[0, 0, 0, 1]]\n\n  this.borderLineEnable = [true,true,true,true]\n  this.borderLineWidth  = [2,2,2,2]\n  this.borderLineColor  = [[0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1]]\n\n  //Drawing parameters\n  this.grid             = null\n  this.text             = null\n  this.line             = null\n  this.box              = null\n  this.objects          = []\n  this.overlays         = []\n\n  this._tickBounds      = [Infinity, Infinity, -Infinity, -Infinity]\n\n  this.static = false\n\n  this.dirty        = false\n  this.pickDirty    = false\n  this.pickDelay    = 120\n  this.pickRadius   = 10\n  this._pickTimeout = null\n  this._drawPick    = this.drawPick.bind(this)\n\n  this._depthCounter = 0\n}\n\nvar proto = GLPlot2D.prototype\n\nproto.setDirty = function() {\n  this.dirty = this.pickDirty = true\n}\n\nproto.setOverlayDirty = function() {\n  this.dirty = true\n}\n\nproto.nextDepthValue = function() {\n  return (this._depthCounter++) / 65536.0\n}\n\nfunction lerp(a, b, t) {\n  var s = 0.5 * (t + 1.0)\n  return Math.floor((1.0-s)*a + s*b)|0\n}\n\nproto.draw = (function() {\nvar TICK_MARK_BOX = [0,0,0,0]\nreturn function() {\n  var gl         = this.gl\n  var screenBox  = this.screenBox\n  var viewPixels = this.viewBox\n  var dataBox    = this.dataBox\n  var pixelRatio = this.pixelRatio\n  var grid       = this.grid\n  var line       = this.line\n  var text       = this.text\n  var objects    = this.objects\n\n  this._depthCounter = 0\n\n  if(this.pickDirty) {\n    if(this._pickTimeout) {\n      clearTimeout(this._pickTimeout)\n    }\n    this.pickDirty = false\n    this._pickTimeout = setTimeout(this._drawPick, this.pickDelay)\n  }\n\n  if(!this.dirty) {\n    return\n  }\n  this.dirty = false\n\n  gl.bindFramebuffer(gl.FRAMEBUFFER, null)\n\n  //Turn on scissor\n  gl.enable(gl.SCISSOR_TEST)\n\n  //Turn off depth buffer\n  gl.disable(gl.DEPTH_TEST)\n  gl.depthFunc(gl.LESS)\n  gl.depthMask(false)\n\n  //Configure premultiplied alpha blending\n  gl.enable(gl.BLEND)\n  gl.blendEquation(gl.FUNC_ADD, gl.FUNC_ADD);\n  gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);\n\n  //Draw border\n  if (this.borderColor) {\n    gl.scissor(\n      screenBox[0],\n      screenBox[1],\n      screenBox[2]-screenBox[0],\n      screenBox[3]-screenBox[1])\n    var borderColor = this.borderColor\n    gl.clearColor(\n      borderColor[0]*borderColor[3],\n      borderColor[1]*borderColor[3],\n      borderColor[2]*borderColor[3],\n      borderColor[3])\n    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)\n  }\n\n  //Draw center pane\n  gl.scissor(\n    viewPixels[0],\n    viewPixels[1],\n    viewPixels[2]-viewPixels[0],\n    viewPixels[3]-viewPixels[1])\n  gl.viewport(\n    viewPixels[0],\n    viewPixels[1],\n    viewPixels[2]-viewPixels[0],\n    viewPixels[3]-viewPixels[1])\n  var backgroundColor = this.backgroundColor\n  gl.clearColor(\n    backgroundColor[0]*backgroundColor[3],\n    backgroundColor[1]*backgroundColor[3],\n    backgroundColor[2]*backgroundColor[3],\n    backgroundColor[3])\n  gl.clear(gl.COLOR_BUFFER_BIT)\n\n  //Draw grid\n  grid.draw()\n\n  //Draw zero lines separately\n  var zeroLineEnable = this.zeroLineEnable\n  var zeroLineColor  = this.zeroLineColor\n  var zeroLineWidth  = this.zeroLineWidth\n  if(zeroLineEnable[0] || zeroLineEnable[1]) {\n    line.bind()\n    for(var i=0; i<2; ++i) {\n      if(!zeroLineEnable[i] ||\n        !(dataBox[i] <= 0 && dataBox[i+2] >= 0)) {\n        continue\n      }\n\n      var zeroIntercept = screenBox[i] -\n        dataBox[i] * (screenBox[i+2] - screenBox[i]) / (dataBox[i+2] - dataBox[i])\n\n      if(i === 0) {\n        line.drawLine(\n          zeroIntercept, screenBox[1], zeroIntercept, screenBox[3],\n          zeroLineWidth[i],\n          zeroLineColor[i])\n      } else {\n        line.drawLine(\n          screenBox[0], zeroIntercept, screenBox[2], zeroIntercept,\n          zeroLineWidth[i],\n          zeroLineColor[i])\n      }\n    }\n  }\n\n  //Draw traces\n  for(var i=0; i<objects.length; ++i) {\n    objects[i].draw()\n  }\n\n  //Return viewport to default\n  gl.viewport(\n    screenBox[0],\n    screenBox[1],\n    screenBox[2]-screenBox[0],\n    screenBox[3]-screenBox[1])\n  gl.scissor(\n    screenBox[0],\n    screenBox[1],\n    screenBox[2]-screenBox[0],\n    screenBox[3]-screenBox[1])\n\n  //Draw tick marks\n  this.grid.drawTickMarks()\n\n  //Draw line elements\n  line.bind()\n\n  //Draw border lines\n  var borderLineEnable = this.borderLineEnable\n  var borderLineWidth  = this.borderLineWidth\n  var borderLineColor  = this.borderLineColor\n  if(borderLineEnable[1]) {\n    line.drawLine(\n      viewPixels[0], viewPixels[1] - 0.5*borderLineWidth[1]*pixelRatio,\n      viewPixels[0], viewPixels[3] + 0.5*borderLineWidth[3]*pixelRatio,\n      borderLineWidth[1], borderLineColor[1])\n  }\n  if(borderLineEnable[0]) {\n    line.drawLine(\n      viewPixels[0] - 0.5*borderLineWidth[0]*pixelRatio, viewPixels[1],\n      viewPixels[2] + 0.5*borderLineWidth[2]*pixelRatio, viewPixels[1],\n      borderLineWidth[0], borderLineColor[0])\n  }\n  if(borderLineEnable[3]) {\n    line.drawLine(\n      viewPixels[2], viewPixels[1] - 0.5*borderLineWidth[1]*pixelRatio,\n      viewPixels[2], viewPixels[3] + 0.5*borderLineWidth[3]*pixelRatio,\n      borderLineWidth[3], borderLineColor[3])\n  }\n  if(borderLineEnable[2]) {\n    line.drawLine(\n      viewPixels[0] - 0.5*borderLineWidth[0]*pixelRatio, viewPixels[3],\n      viewPixels[2] + 0.5*borderLineWidth[2]*pixelRatio, viewPixels[3],\n      borderLineWidth[2], borderLineColor[2])\n  }\n\n  //Draw text elements\n  text.bind()\n  for(var i=0; i<2; ++i) {\n    text.drawTicks(i)\n  }\n  if(this.titleEnable) {\n    text.drawTitle()\n  }\n\n  //Draw other overlay elements (select boxes, etc.)\n  var overlays = this.overlays\n  for(var i=0; i<overlays.length; ++i) {\n    overlays[i].draw()\n  }\n\n  //Turn off scissor test\n  gl.disable(gl.SCISSOR_TEST)\n  gl.disable(gl.BLEND)\n  gl.depthMask(true)\n}\n})()\n\nproto.drawPick = (function() {\n\nreturn function() {\n  if (this.static) return;\n\n  var pickBuffer = this.pickBuffer\n  var gl = this.gl\n\n  this._pickTimeout = null\n  pickBuffer.begin()\n\n  var pickOffset = 1\n  var objects = this.objects\n  for(var i=0; i<objects.length; ++i) {\n    pickOffset = objects[i].drawPick(pickOffset)\n  }\n\n  pickBuffer.end()\n}\n})()\n\nproto.pick = (function() {\nreturn function(x, y) {\n  if (this.static) return;\n\n  var pixelRatio     = this.pixelRatio\n  var pickPixelRatio = this.pickPixelRatio\n  var viewBox        = this.viewBox\n\n  var scrX = Math.round((x - viewBox[0] / pixelRatio) * pickPixelRatio)|0\n  var scrY = Math.round((y - viewBox[1] / pixelRatio) * pickPixelRatio)|0\n\n  var pickResult = this.pickBuffer.query(scrX, scrY, this.pickRadius)\n  if(!pickResult) {\n    return null\n  }\n\n  var pickValue = pickResult.id +\n    (pickResult.value[0]<<8)  +\n    (pickResult.value[1]<<16) +\n    (pickResult.value[2]<<24)\n\n  var objects = this.objects\n  for(var i=0; i<objects.length; ++i) {\n    var result = objects[i].pick(scrX, scrY, pickValue)\n    if(result) {\n      return result\n    }\n  }\n\n  return null\n}\n})()\n\nfunction deepClone(array) {\n  var result = array.slice()\n  for(var i=0; i<result.length; ++i) {\n    result[i] = result[i].slice()\n  }\n  return result\n}\n\nfunction compareTicks(a, b) {\n  return a.x - b.x\n}\n\nproto.setScreenBox = function(nbox) {\n  var screenBox = this.screenBox\n  var pixelRatio = this.pixelRatio\n\n  screenBox[0] = Math.round(nbox[0] * pixelRatio) | 0\n  screenBox[1] = Math.round(nbox[1] * pixelRatio) | 0\n  screenBox[2] = Math.round(nbox[2] * pixelRatio) | 0\n  screenBox[3] = Math.round(nbox[3] * pixelRatio) | 0\n\n  this.setDirty()\n}\n\nproto.setDataBox = function(nbox) {\n  var dataBox = this.dataBox\n\n  var different =\n    dataBox[0] !== nbox[0] ||\n    dataBox[1] !== nbox[1] ||\n    dataBox[2] !== nbox[2] ||\n    dataBox[3] !== nbox[3]\n\n  if(different) {\n    dataBox[0] = nbox[0]\n    dataBox[1] = nbox[1]\n    dataBox[2] = nbox[2]\n    dataBox[3] = nbox[3]\n\n    this.setDirty()\n  }\n}\n\nproto.setViewBox = function(nbox) {\n  var pixelRatio = this.pixelRatio\n  var viewBox = this.viewBox\n\n  viewBox[0] = Math.round(nbox[0] * pixelRatio)|0\n  viewBox[1] = Math.round(nbox[1] * pixelRatio)|0\n  viewBox[2] = Math.round(nbox[2] * pixelRatio)|0\n  viewBox[3] = Math.round(nbox[3] * pixelRatio)|0\n\n  var pickPixelRatio = this.pickPixelRatio\n  this.pickBuffer.shape = [\n    Math.round((nbox[2] - nbox[0]) * pickPixelRatio)|0,\n    Math.round((nbox[3] - nbox[1]) * pickPixelRatio)|0 ]\n\n  this.setDirty()\n}\n\nproto.update = function(options) {\n  options = options || {}\n\n  var gl = this.gl\n\n  this.pixelRatio      = options.pixelRatio || 1\n\n  var pixelRatio       = this.pixelRatio\n  this.pickPixelRatio  = Math.max(pixelRatio, 1)\n\n  this.setScreenBox(options.screenBox ||\n    [0, 0, gl.drawingBufferWidth/pixelRatio, gl.drawingBufferHeight/pixelRatio])\n\n  var screenBox = this.screenBox\n  this.setViewBox(options.viewBox ||\n    [0.125*(this.screenBox[2]-this.screenBox[0])/pixelRatio,\n     0.125*(this.screenBox[3]-this.screenBox[1])/pixelRatio,\n     0.875*(this.screenBox[2]-this.screenBox[0])/pixelRatio,\n     0.875*(this.screenBox[3]-this.screenBox[1])/pixelRatio])\n\n  var viewBox = this.viewBox\n  var aspectRatio = (viewBox[2] - viewBox[0]) / (viewBox[3] - viewBox[1])\n  this.setDataBox(options.dataBox || [-10, -10/aspectRatio, 10, 10/aspectRatio])\n\n  this.borderColor     = options.borderColor !== false ? (options.borderColor || [0,0,0,0]).slice() : false\n  this.backgroundColor = (options.backgroundColor || [0,0,0,0]).slice()\n\n  this.gridLineEnable  = (options.gridLineEnable || [true,true]).slice()\n  this.gridLineWidth   = (options.gridLineWidth || [1,1]).slice()\n  this.gridLineColor   = deepClone(options.gridLineColor ||\n    [[0.5,0.5,0.5,1],[0.5,0.5,0.5,1]])\n\n  this.zeroLineEnable   = (options.zeroLineEnable || [true, true]).slice()\n  this.zeroLineWidth    = (options.zeroLineWidth || [4, 4]).slice()\n  this.zeroLineColor    = deepClone(options.zeroLineColor ||\n    [[0, 0, 0, 1],[0, 0, 0, 1]])\n\n  this.tickMarkLength   = (options.tickMarkLength || [0,0,0,0]).slice()\n  this.tickMarkWidth    = (options.tickMarkWidth || [0,0,0,0]).slice()\n  this.tickMarkColor    = deepClone(options.tickMarkColor ||\n    [[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]])\n\n  this.titleCenter      = (options.titleCenter || [\n    0.5*(viewBox[0]+viewBox[2])/pixelRatio,(viewBox[3]+120)/pixelRatio]).slice()\n  this.titleEnable      = !('titleEnable' in options) || !!options.titleEnable\n  this.titleAngle       = options.titleAngle || 0\n  this.titleColor       = (options.titleColor || [0,0,0,1]).slice()\n\n  this.labelPad         = (options.labelPad || [15,15,15,15]).slice()\n  this.labelAngle       = (options.labelAngle ||\n    [0,Math.PI/2,0,3.0*Math.PI/2]).slice()\n  this.labelEnable      = (options.labelEnable || [true,true,true,true]).slice()\n  this.labelColor       = deepClone(options.labelColor ||\n    [[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]])\n\n  this.tickPad         = (options.tickPad || [15,15,15,15]).slice()\n  this.tickAngle       = (options.tickAngle || [0,0,0,0]).slice()\n  this.tickEnable      = (options.tickEnable || [true,true,true,true]).slice()\n  this.tickColor       = deepClone(options.tickColor ||\n    [[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]])\n\n  this.borderLineEnable = (options.borderLineEnable ||\n                            [true,true,true,true]).slice()\n  this.borderLineWidth  = (options.borderLineWidth || [2,2,2,2]).slice()\n  this.borderLineColor  = deepClone(options.borderLineColor ||\n                          [[0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1],\n                           [0,0,0,1]])\n\n  var ticks = options.ticks || [ [], [] ]\n\n  //Compute bounds on ticks\n  var bounds = this._tickBounds\n  bounds[0] = bounds[1] =  Infinity\n  bounds[2] = bounds[3] = -Infinity\n  for(var i=0; i<2; ++i) {\n    var axisTicks = ticks[i].slice(0)\n    if(axisTicks.length === 0) {\n      continue\n    }\n    axisTicks.sort(compareTicks)\n    bounds[i]   = Math.min(bounds[i], axisTicks[0].x)\n    bounds[i+2] = Math.max(bounds[i+2], axisTicks[axisTicks.length-1].x)\n  }\n\n  //Update grid\n  this.grid.update({\n    bounds: bounds,\n    ticks:  ticks\n  })\n\n  //Update text\n  this.text.update({\n    bounds:     bounds,\n    ticks:      ticks,\n    labels:     options.labels    || ['x', 'y'],\n    labelSize:  options.labelSize || [12,12],\n    labelFont:  options.labelFont || ['sans-serif', 'sans-serif'],\n    title:      options.title     || '',\n    titleSize:  options.titleSize || 18,\n    titleFont:  options.titleFont || 'sans-serif'\n  })\n\n  this.static = !!options.static;\n\n  this.setDirty()\n}\n\nproto.dispose = function() {\n  this.box.dispose()\n  this.grid.dispose()\n  this.text.dispose()\n  this.line.dispose()\n  for(var i=this.objects.length-1; i>=0; --i) {\n    this.objects[i].dispose()\n  }\n  this.objects.length = 0\n  for(var i=this.overlays.length-1; i>=0; --i) {\n    this.overlays[i].dispose()\n  }\n  this.overlays.length = 0\n\n  this.gl = null\n}\n\nproto.addObject = function(object) {\n  if(this.objects.indexOf(object) < 0) {\n    this.objects.push(object)\n    this.setDirty()\n  }\n}\n\nproto.removeObject = function(object) {\n  var objects = this.objects\n  for(var i=0; i<objects.length; ++i) {\n    if(objects[i] === object) {\n      objects.splice(i,1)\n      this.setDirty()\n      break\n    }\n  }\n}\n\nproto.addOverlay = function(object) {\n  if(this.overlays.indexOf(object) < 0) {\n    this.overlays.push(object)\n    this.setOverlayDirty()\n  }\n}\n\nproto.removeOverlay = function(object) {\n  var objects = this.overlays\n  for(var i=0; i<objects.length; ++i) {\n    if(objects[i] === object) {\n      objects.splice(i,1)\n      this.setOverlayDirty()\n      break\n    }\n  }\n}\n\nfunction createGLPlot2D(options) {\n  var gl = options.gl\n  var pickBuffer = createPick(gl, [\n    gl.drawingBufferWidth, gl.drawingBufferHeight])\n  var plot = new GLPlot2D(gl, pickBuffer)\n  plot.grid = createGrid(plot)\n  plot.text = createText(plot)\n  plot.line = createLine(plot)\n  plot.box  = createBox(plot)\n  plot.update(options)\n  return plot\n}\n\n},{\"./lib/box\":281,\"./lib/grid\":282,\"./lib/line\":283,\"./lib/text\":285,\"gl-select-static\":300}],288:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createCamera\n\nvar now         = _dereq_('right-now')\nvar createView  = _dereq_('3d-view')\nvar mouseChange = _dereq_('mouse-change')\nvar mouseWheel  = _dereq_('mouse-wheel')\nvar mouseOffset = _dereq_('mouse-event-offset')\nvar hasPassive  = _dereq_('has-passive-events')\n\nfunction createCamera(element, options) {\n  element = element || document.body\n  options = options || {}\n\n  var limits  = [ 0.01, Infinity ]\n  if('distanceLimits' in options) {\n    limits[0] = options.distanceLimits[0]\n    limits[1] = options.distanceLimits[1]\n  }\n  if('zoomMin' in options) {\n    limits[0] = options.zoomMin\n  }\n  if('zoomMax' in options) {\n    limits[1] = options.zoomMax\n  }\n\n  var view = createView({\n    center: options.center || [0,0,0],\n    up:     options.up     || [0,1,0],\n    eye:    options.eye    || [0,0,10],\n    mode:   options.mode   || 'orbit',\n    distanceLimits: limits\n  })\n\n  var pmatrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n  var distance = 0.0\n  var width   = element.clientWidth\n  var height  = element.clientHeight\n\n  var camera = {\n    keyBindingMode: 'rotate',\n    enableWheel: true,\n    view:               view,\n    element:            element,\n    delay:              options.delay          || 16,\n    rotateSpeed:        options.rotateSpeed    || 1,\n    zoomSpeed:          options.zoomSpeed      || 1,\n    translateSpeed:     options.translateSpeed || 1,\n    flipX:              !!options.flipX,\n    flipY:              !!options.flipY,\n    modes:              view.modes,\n    _ortho: options._ortho || (options.projection && options.projection.type === 'orthographic') || false,\n    tick: function() {\n      var t = now()\n      var delay = this.delay\n      var ctime = t - 2 * delay\n      view.idle(t-delay)\n      view.recalcMatrix(ctime)\n      view.flush(t-(100+delay*2))\n      var allEqual = true\n      var matrix = view.computedMatrix\n      for(var i=0; i<16; ++i) {\n        allEqual = allEqual && (pmatrix[i] === matrix[i])\n        pmatrix[i] = matrix[i]\n      }\n      var sizeChanged =\n          element.clientWidth === width &&\n          element.clientHeight === height\n      width  = element.clientWidth\n      height = element.clientHeight\n      if(allEqual) {\n        return !sizeChanged\n      }\n      distance = Math.exp(view.computedRadius[0])\n      return true\n    },\n    lookAt: function(eye, center, up) {\n      view.lookAt(view.lastT(), eye, center, up)\n    },\n    rotate: function(pitch, yaw, roll) {\n      view.rotate(view.lastT(), pitch, yaw, roll)\n    },\n    pan: function(dx, dy, dz) {\n      view.pan(view.lastT(), dx, dy, dz)\n    },\n    translate: function(dx, dy, dz) {\n      view.translate(view.lastT(), dx, dy, dz)\n    }\n  }\n\n  Object.defineProperties(camera, {\n    matrix: {\n      get: function() {\n        return view.computedMatrix\n      },\n      set: function(mat) {\n        view.setMatrix(view.lastT(), mat)\n        return view.computedMatrix\n      },\n      enumerable: true\n    },\n    mode: {\n      get: function() {\n        return view.getMode()\n      },\n      set: function(mode) {\n        var curUp = view.computedUp.slice()\n        var curEye = view.computedEye.slice()\n        var curCenter = view.computedCenter.slice()\n        view.setMode(mode)\n        if(mode === 'turntable') {\n          // Hacky time warping stuff to generate smooth animation\n          var t0 = now()\n          view._active.lookAt(t0, curEye, curCenter, curUp)\n          view._active.lookAt(t0 + 500, curEye, curCenter, [0, 0, 1])\n          view._active.flush(t0)\n        }\n        return view.getMode()\n      },\n      enumerable: true\n    },\n    center: {\n      get: function() {\n        return view.computedCenter\n      },\n      set: function(ncenter) {\n        view.lookAt(view.lastT(), null, ncenter)\n        return view.computedCenter\n      },\n      enumerable: true\n    },\n    eye: {\n      get: function() {\n        return view.computedEye\n      },\n      set: function(neye) {\n        view.lookAt(view.lastT(), neye)\n        return view.computedEye\n      },\n      enumerable: true\n    },\n    up: {\n      get: function() {\n        return view.computedUp\n      },\n      set: function(nup) {\n        view.lookAt(view.lastT(), null, null, nup)\n        return view.computedUp\n      },\n      enumerable: true\n    },\n    distance: {\n      get: function() {\n        return distance\n      },\n      set: function(d) {\n        view.setDistance(view.lastT(), d)\n        return d\n      },\n      enumerable: true\n    },\n    distanceLimits: {\n      get: function() {\n        return view.getDistanceLimits(limits)\n      },\n      set: function(v) {\n        view.setDistanceLimits(v)\n        return v\n      },\n      enumerable: true\n    }\n  })\n\n  element.addEventListener('contextmenu', function(ev) {\n    ev.preventDefault()\n    return false\n  })\n\n  camera._lastX = -1\n  camera._lastY = -1\n  camera._lastMods = {shift: false, control: false, alt: false, meta: false}\n\n  camera.enableMouseListeners = function() {\n\n    camera.mouseListener = mouseChange(element, handleInteraction)\n\n    //enable simple touch interactions\n    element.addEventListener('touchstart', function (ev) {\n      var xy = mouseOffset(ev.changedTouches[0], element)\n      handleInteraction(0, xy[0], xy[1], camera._lastMods)\n      handleInteraction(1, xy[0], xy[1], camera._lastMods)\n\n      ev.preventDefault()\n    }, hasPassive ? {passive: false} : false)\n\n    element.addEventListener('touchmove', function (ev) {\n      var xy = mouseOffset(ev.changedTouches[0], element)\n      handleInteraction(1, xy[0], xy[1], camera._lastMods)\n\n      ev.preventDefault()\n    }, hasPassive ? {passive: false} : false)\n\n    element.addEventListener('touchend', function (ev) {\n\n      handleInteraction(0, camera._lastX, camera._lastY, camera._lastMods)\n\n      ev.preventDefault()\n    }, hasPassive ? {passive: false} : false)\n\n    function handleInteraction (buttons, x, y, mods) {\n      var keyBindingMode = camera.keyBindingMode\n\n      if(keyBindingMode === false) return\n\n      var rotate = keyBindingMode === 'rotate'\n      var pan = keyBindingMode === 'pan'\n      var zoom = keyBindingMode === 'zoom'\n\n      var ctrl = !!mods.control\n      var alt = !!mods.alt\n      var shift = !!mods.shift\n      var left = !!(buttons & 1)\n      var right = !!(buttons & 2)\n      var middle = !!(buttons & 4)\n\n      var scale = 1.0 / element.clientHeight\n      var dx    = scale * (x - camera._lastX)\n      var dy    = scale * (y - camera._lastY)\n\n      var flipX = camera.flipX ? 1 : -1\n      var flipY = camera.flipY ? 1 : -1\n\n      var drot  = Math.PI * camera.rotateSpeed\n\n      var t = now()\n\n      if(camera._lastX !== -1 && camera._lastY !== -1) {\n        if((rotate && left && !ctrl && !alt && !shift) || (left && !ctrl && !alt && shift)) {\n          // Rotate\n          view.rotate(t, flipX * drot * dx, -flipY * drot * dy, 0)\n        }\n\n        if((pan && left && !ctrl && !alt && !shift) || right || (left && ctrl && !alt && !shift)) {\n          // Pan\n          view.pan(t, -camera.translateSpeed * dx * distance, camera.translateSpeed * dy * distance, 0)\n        }\n\n        if((zoom && left && !ctrl && !alt && !shift) || middle || (left && !ctrl && alt && !shift)) {\n          // Zoom\n          var kzoom = -camera.zoomSpeed * dy / window.innerHeight * (t - view.lastT()) * 100\n          view.pan(t, 0, 0, distance * (Math.exp(kzoom) - 1))\n        }\n      }\n\n      camera._lastX = x\n      camera._lastY = y\n      camera._lastMods = mods\n\n      return true\n    }\n\n    camera.wheelListener = mouseWheel(element, function(dx, dy) {\n      // TODO remove now that we can disable scroll via scrollZoom?\n      if(camera.keyBindingMode === false) return\n      if(!camera.enableWheel) return\n\n      var flipX = camera.flipX ? 1 : -1\n      var flipY = camera.flipY ? 1 : -1\n      var t = now()\n      if(Math.abs(dx) > Math.abs(dy)) {\n        view.rotate(t, 0, 0, -dx * flipX * Math.PI * camera.rotateSpeed / window.innerWidth)\n      } else {\n        if(!camera._ortho) {\n          var kzoom = -camera.zoomSpeed * flipY * dy / window.innerHeight * (t - view.lastT()) / 20.0\n          view.pan(t, 0, 0, distance * (Math.exp(kzoom) - 1))\n        }\n      }\n    }, true)\n  }\n\n  camera.enableMouseListeners()\n\n  return camera\n}\n\n},{\"3d-view\":52,\"has-passive-events\":411,\"mouse-change\":435,\"mouse-event-offset\":436,\"mouse-wheel\":438,\"right-now\":504}],289:[function(_dereq_,module,exports){\nvar glslify      = _dereq_('glslify')\nvar createShader = _dereq_('gl-shader')\n\nvar vertSrc = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\nattribute vec2 position;\\nvarying vec2 uv;\\nvoid main() {\\n  uv = position;\\n  gl_Position = vec4(position, 0, 1);\\n}\"])\nvar fragSrc = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nuniform sampler2D accumBuffer;\\nvarying vec2 uv;\\n\\nvoid main() {\\n  vec4 accum = texture2D(accumBuffer, 0.5 * (uv + 1.0));\\n  gl_FragColor = min(vec4(1,1,1,1), accum);\\n}\"])\n\nmodule.exports = function(gl) {\n  return createShader(gl, vertSrc, fragSrc, null, [ { name: 'position', type: 'vec2'}])\n}\n\n},{\"gl-shader\":301,\"glslify\":409}],290:[function(_dereq_,module,exports){\n'use strict'\n\nvar createCamera = _dereq_('./camera.js')\nvar createAxes   = _dereq_('gl-axes3d')\nvar axesRanges   = _dereq_('gl-axes3d/properties')\nvar createSpikes = _dereq_('gl-spikes3d')\nvar createSelect = _dereq_('gl-select-static')\nvar createFBO    = _dereq_('gl-fbo')\nvar drawTriangle = _dereq_('a-big-triangle')\nvar mouseChange  = _dereq_('mouse-change')\nvar mouseWheel   = _dereq_('mouse-wheel')\nvar perspective  = _dereq_('gl-mat4/perspective')\nvar ortho        = _dereq_('gl-mat4/ortho')\nvar createShader = _dereq_('./lib/shader')\nvar isMobile = _dereq_('is-mobile')({ tablet: true })\n\nmodule.exports = {\n  createScene: createScene,\n  createCamera: createCamera\n}\n\nfunction MouseSelect() {\n  this.mouse          = [-1,-1]\n  this.screen         = null\n  this.distance       = Infinity\n  this.index          = null\n  this.dataCoordinate = null\n  this.dataPosition   = null\n  this.object         = null\n  this.data           = null\n}\n\nfunction getContext(canvas, options) {\n  var gl = null\n  try {\n    gl = canvas.getContext('webgl', options)\n    if(!gl) {\n      gl = canvas.getContext('experimental-webgl', options)\n    }\n  } catch(e) {\n    return null\n  }\n  return gl\n}\n\nfunction roundUpPow10(x) {\n  var y = Math.round(Math.log(Math.abs(x)) / Math.log(10))\n  if(y < 0) {\n    var base = Math.round(Math.pow(10, -y))\n    return Math.ceil(x*base) / base\n  } else if(y > 0) {\n    var base = Math.round(Math.pow(10, y))\n    return Math.ceil(x/base) * base\n  }\n  return Math.ceil(x)\n}\n\nfunction defaultBool(x) {\n  if(typeof x === 'boolean') {\n    return x\n  }\n  return true\n}\n\nfunction createScene(options) {\n  options = options || {}\n  options.camera = options.camera || {}\n\n  var canvas = options.canvas\n  if(!canvas) {\n    canvas = document.createElement('canvas')\n    if(options.container) {\n      var container = options.container\n      container.appendChild(canvas)\n    } else {\n      document.body.appendChild(canvas)\n    }\n  }\n\n  var gl = options.gl\n  if(!gl) {\n    gl = getContext(canvas,\n      options.glOptions || {\n        premultipliedAlpha: true,\n        antialias: true,\n        preserveDrawingBuffer: isMobile\n      })\n  }\n  if(!gl) {\n    throw new Error('webgl not supported')\n  }\n\n  //Initial bounds\n  var bounds = options.bounds || [[-10,-10,-10], [10,10,10]]\n\n  //Create selection\n  var selection = new MouseSelect()\n\n  //Accumulation buffer\n  var accumBuffer = createFBO(gl,\n    [gl.drawingBufferWidth, gl.drawingBufferHeight], {\n      preferFloat: !isMobile\n    })\n\n  var accumShader = createShader(gl)\n\n  var isOrtho =\n    (options.cameraObject && options.cameraObject._ortho === true) ||\n    (options.camera.projection && options.camera.projection.type === 'orthographic') ||\n    false\n\n  //Create a camera\n  var cameraOptions = {\n    eye:     options.camera.eye     || [2,0,0],\n    center:  options.camera.center  || [0,0,0],\n    up:      options.camera.up      || [0,1,0],\n    zoomMin: options.camera.zoomMax || 0.1,\n    zoomMax: options.camera.zoomMin || 100,\n    mode:    options.camera.mode    || 'turntable',\n    _ortho:  isOrtho\n  }\n\n  //Create axes\n  var axesOptions = options.axes || {}\n  var axes = createAxes(gl, axesOptions)\n  axes.enable = !axesOptions.disable\n\n  //Create spikes\n  var spikeOptions = options.spikes || {}\n  var spikes = createSpikes(gl, spikeOptions)\n\n  //Object list is empty initially\n  var objects         = []\n  var pickBufferIds   = []\n  var pickBufferCount = []\n  var pickBuffers     = []\n\n  //Dirty flag, skip redraw if scene static\n  var dirty       = true\n  var pickDirty   = true\n\n  var projection     = new Array(16)\n  var model          = new Array(16)\n\n  var cameraParams = {\n    view:         null,\n    projection:   projection,\n    model:        model,\n    _ortho:        false\n  }\n\n  var pickDirty = true\n\n  var viewShape = [ gl.drawingBufferWidth, gl.drawingBufferHeight ]\n\n  var camera = options.cameraObject || createCamera(canvas, cameraOptions)\n\n  //Create scene object\n  var scene = {\n    gl:           gl,\n    contextLost:  false,\n    pixelRatio:   options.pixelRatio || 1,\n    canvas:       canvas,\n    selection:    selection,\n    camera:       camera,\n    axes:         axes,\n    axesPixels:   null,\n    spikes:       spikes,\n    bounds:       bounds,\n    objects:      objects,\n    shape:        viewShape,\n    aspect:       options.aspectRatio || [1,1,1],\n    pickRadius:   options.pickRadius || 10,\n    zNear:        options.zNear || 0.01,\n    zFar:         options.zFar  || 1000,\n    fovy:         options.fovy  || Math.PI/4,\n    clearColor:   options.clearColor || [0,0,0,0],\n    autoResize:   defaultBool(options.autoResize),\n    autoBounds:   defaultBool(options.autoBounds),\n    autoScale:    !!options.autoScale,\n    autoCenter:   defaultBool(options.autoCenter),\n    clipToBounds: defaultBool(options.clipToBounds),\n    snapToData:   !!options.snapToData,\n    onselect:     options.onselect || null,\n    onrender:     options.onrender || null,\n    onclick:      options.onclick  || null,\n    cameraParams: cameraParams,\n    oncontextloss: null,\n    mouseListener: null,\n    _stopped: false\n  }\n\n  var pickShape = [ (gl.drawingBufferWidth/scene.pixelRatio)|0, (gl.drawingBufferHeight/scene.pixelRatio)|0 ]\n\n  function resizeListener() {\n    if(scene._stopped) {\n      return\n    }\n    if(!scene.autoResize) {\n      return\n    }\n    var parent = canvas.parentNode\n    var width  = 1\n    var height = 1\n    if(parent && parent !== document.body) {\n      width  = parent.clientWidth\n      height = parent.clientHeight\n    } else {\n      width  = window.innerWidth\n      height = window.innerHeight\n    }\n    var nextWidth  = Math.ceil(width  * scene.pixelRatio)|0\n    var nextHeight = Math.ceil(height * scene.pixelRatio)|0\n    if(nextWidth !== canvas.width || nextHeight !== canvas.height) {\n      canvas.width   = nextWidth\n      canvas.height  = nextHeight\n      var style = canvas.style\n      style.position = style.position || 'absolute'\n      style.left     = '0px'\n      style.top      = '0px'\n      style.width    = width  + 'px'\n      style.height   = height + 'px'\n      dirty = true\n    }\n  }\n  if(scene.autoResize) {\n    resizeListener()\n  }\n  window.addEventListener('resize', resizeListener)\n\n  function reallocPickIds() {\n    var numObjs = objects.length\n    var numPick = pickBuffers.length\n    for(var i=0; i<numPick; ++i) {\n      pickBufferCount[i] = 0\n    }\n    obj_loop:\n    for(var i=0; i<numObjs; ++i) {\n      var obj = objects[i]\n      var pickCount = obj.pickSlots\n      if(!pickCount) {\n        pickBufferIds[i] = -1\n        continue\n      }\n      for(var j=0; j<numPick; ++j) {\n        if(pickBufferCount[j] + pickCount < 255) {\n          pickBufferIds[i] = j\n          obj.setPickBase(pickBufferCount[j]+1)\n          pickBufferCount[j] += pickCount\n          continue obj_loop\n        }\n      }\n      //Create new pick buffer\n      var nbuffer = createSelect(gl, viewShape)\n      pickBufferIds[i] = numPick\n      pickBuffers.push(nbuffer)\n      pickBufferCount.push(pickCount)\n      obj.setPickBase(1)\n      numPick += 1\n    }\n    while(numPick > 0 && pickBufferCount[numPick-1] === 0) {\n      pickBufferCount.pop()\n      pickBuffers.pop().dispose()\n    }\n  }\n\n  scene.update = function(options) {\n\n    if(scene._stopped) {\n      return\n    }\n    options = options || {}\n    dirty = true\n    pickDirty = true\n  }\n\n  scene.add = function(obj) {\n    if(scene._stopped) {\n      return\n    }\n    obj.axes = axes\n    objects.push(obj)\n    pickBufferIds.push(-1)\n    dirty = true\n    pickDirty = true\n    reallocPickIds()\n  }\n\n  scene.remove = function(obj) {\n    if(scene._stopped) {\n      return\n    }\n    var idx = objects.indexOf(obj)\n    if(idx < 0) {\n      return\n    }\n    objects.splice(idx, 1)\n    pickBufferIds.pop()\n    dirty = true\n    pickDirty = true\n    reallocPickIds()\n  }\n\n  scene.dispose = function() {\n    if(scene._stopped) {\n      return\n    }\n\n    scene._stopped = true\n\n    window.removeEventListener('resize', resizeListener)\n    canvas.removeEventListener('webglcontextlost', checkContextLoss)\n    scene.mouseListener.enabled = false\n\n    if(scene.contextLost) {\n      return\n    }\n\n    //Destroy objects\n    axes.dispose()\n    spikes.dispose()\n    for(var i=0; i<objects.length; ++i) {\n      objects[i].dispose()\n    }\n\n    //Clean up buffers\n    accumBuffer.dispose()\n    for(var i=0; i<pickBuffers.length; ++i) {\n      pickBuffers[i].dispose()\n    }\n\n    //Clean up shaders\n    accumShader.dispose()\n\n    //Release all references\n    gl = null\n    axes = null\n    spikes = null\n    objects = []\n  }\n\n  scene.wheelListener = mouseWheel(canvas, function(dx, dy) {\n    // TODO remove now that we can disable scroll via scrollZoom?\n    if(camera.keyBindingMode === false) return\n    if(!camera.enableWheel) return\n\n    if(camera._ortho) {\n      var s = (dx > dy) ? 1.1 : 1.0 / 1.1\n\n      scene.aspect[0] *= s\n      scene.aspect[1] *= s\n      scene.aspect[2] *= s\n      scene.redraw()\n    }\n  }, true)\n\n  //Update mouse position\n  scene._mouseRotating = false\n  scene._prevButtons = 0\n\n  scene.enableMouseListeners = function() {\n\n    scene.mouseListener = mouseChange(canvas, function(buttons, x, y) {\n      if(scene._stopped) {\n        return\n      }\n\n      var numPick = pickBuffers.length\n      var numObjs = objects.length\n      var prevObj = selection.object\n\n      selection.distance = Infinity\n      selection.mouse[0] = x\n      selection.mouse[1] = y\n      selection.object = null\n      selection.screen = null\n      selection.dataCoordinate = selection.dataPosition = null\n\n      var change = false\n\n      if(buttons && scene._prevButtons) {\n        scene._mouseRotating = true\n      } else {\n        if(scene._mouseRotating) {\n          pickDirty = true\n        }\n        scene._mouseRotating = false\n\n        for(var i=0; i<numPick; ++i) {\n          var result = pickBuffers[i].query(x, pickShape[1] - y - 1, scene.pickRadius)\n          if(result) {\n            if(result.distance > selection.distance) {\n              continue\n            }\n            for(var j=0; j<numObjs; ++j) {\n              var obj = objects[j]\n              if(pickBufferIds[j] !== i) {\n                continue\n              }\n              var objPick = obj.pick(result)\n              if(objPick) {\n                selection.buttons        = buttons\n                selection.screen         = result.coord\n                selection.distance       = result.distance\n                selection.object         = obj\n                selection.index          = objPick.distance\n                selection.dataPosition   = objPick.position\n                selection.dataCoordinate = objPick.dataCoordinate\n                selection.data           = objPick\n                change = true\n              }\n            }\n          }\n        }\n      }\n\n      if(prevObj && prevObj !== selection.object) {\n        if(prevObj.highlight) {\n          prevObj.highlight(null)\n        }\n        dirty = true\n      }\n      if(selection.object) {\n        if(selection.object.highlight) {\n          selection.object.highlight(selection.data)\n        }\n        dirty = true\n      }\n\n      change = change || (selection.object !== prevObj)\n      if(change && scene.onselect) {\n        scene.onselect(selection)\n      }\n\n      if((buttons & 1) && !(scene._prevButtons & 1) && scene.onclick) {\n        scene.onclick(selection)\n      }\n      scene._prevButtons = buttons\n    })\n  }\n\n  function checkContextLoss() {\n    if(scene.contextLost) {\n      return true\n    }\n    if(gl.isContextLost()) {\n      scene.contextLost = true\n      scene.mouseListener.enabled = false\n      scene.selection.object = null\n      if(scene.oncontextloss) {\n        scene.oncontextloss()\n      }\n    }\n  }\n\n  canvas.addEventListener('webglcontextlost', checkContextLoss)\n\n  //Render the scene for mouse picking\n  function renderPick() {\n    if(checkContextLoss()) {\n      return\n    }\n\n    gl.colorMask(true, true, true, true)\n    gl.depthMask(true)\n    gl.disable(gl.BLEND)\n    gl.enable(gl.DEPTH_TEST)\n\n    var numObjs = objects.length\n    var numPick = pickBuffers.length\n    for(var j=0; j<numPick; ++j) {\n      var buf = pickBuffers[j]\n      buf.shape = pickShape\n      buf.begin()\n      for(var i=0; i<numObjs; ++i) {\n        if(pickBufferIds[i] !== j) {\n          continue\n        }\n        var obj = objects[i]\n        if(obj.drawPick) {\n          obj.pixelRatio = 1\n          obj.drawPick(cameraParams)\n        }\n      }\n      buf.end()\n    }\n  }\n\n  var nBounds = [\n    [ Infinity, Infinity, Infinity],\n    [-Infinity,-Infinity,-Infinity]]\n\n  var prevBounds = [nBounds[0].slice(), nBounds[1].slice()]\n\n  function redraw() {\n    if(checkContextLoss()) {\n      return\n    }\n\n    resizeListener()\n\n    //Tick camera\n    var cameraMoved = scene.camera.tick()\n    cameraParams.view = scene.camera.matrix\n    dirty     = dirty || cameraMoved\n    pickDirty = pickDirty || cameraMoved\n\n      //Set pixel ratio\n    axes.pixelRatio   = scene.pixelRatio\n    spikes.pixelRatio = scene.pixelRatio\n\n    //Check if any objects changed, recalculate bounds\n    var numObjs = objects.length\n    var lo = nBounds[0]\n    var hi = nBounds[1]\n    lo[0] = lo[1] = lo[2] =  Infinity\n    hi[0] = hi[1] = hi[2] = -Infinity\n    for(var i=0; i<numObjs; ++i) {\n      var obj = objects[i]\n\n      //Set the axes properties for each object\n      obj.pixelRatio = scene.pixelRatio\n      obj.axes = scene.axes\n\n      dirty = dirty || !!obj.dirty\n      pickDirty = pickDirty || !!obj.dirty\n      var obb = obj.bounds\n      if(obb) {\n        var olo = obb[0]\n        var ohi = obb[1]\n        for(var j=0; j<3; ++j) {\n          lo[j] = Math.min(lo[j], olo[j])\n          hi[j] = Math.max(hi[j], ohi[j])\n        }\n      }\n    }\n\n    //Recalculate bounds\n    var bounds = scene.bounds\n    if(scene.autoBounds) {\n      for(var j=0; j<3; ++j) {\n        if(hi[j] < lo[j]) {\n          lo[j] = -1\n          hi[j] = 1\n        } else {\n          if(lo[j] === hi[j]) {\n            lo[j] -= 1\n            hi[j] += 1\n          }\n          var padding = 0.05 * (hi[j] - lo[j])\n          lo[j] = lo[j] - padding\n          hi[j] = hi[j] + padding\n        }\n        bounds[0][j] = lo[j]\n        bounds[1][j] = hi[j]\n      }\n    }\n\n    var boundsChanged = false\n    for(var j=0; j<3; ++j) {\n        boundsChanged = boundsChanged ||\n            (prevBounds[0][j] !== bounds[0][j])  ||\n            (prevBounds[1][j] !== bounds[1][j])\n        prevBounds[0][j] = bounds[0][j]\n        prevBounds[1][j] = bounds[1][j]\n    }\n\n    //Recalculate bounds\n    pickDirty = pickDirty || boundsChanged\n    dirty = dirty || boundsChanged\n\n    if(!dirty) {\n      return\n    }\n\n    if(boundsChanged) {\n      var tickSpacing = [0,0,0]\n      for(var i=0; i<3; ++i) {\n        tickSpacing[i] = roundUpPow10((bounds[1][i]-bounds[0][i]) / 10.0)\n      }\n      if(axes.autoTicks) {\n        axes.update({\n          bounds: bounds,\n          tickSpacing: tickSpacing\n        })\n      } else {\n        axes.update({\n          bounds: bounds\n        })\n      }\n    }\n\n    //Get scene\n    var width  = gl.drawingBufferWidth\n    var height = gl.drawingBufferHeight\n    viewShape[0] = width\n    viewShape[1] = height\n    pickShape[0] = Math.max(width/scene.pixelRatio, 1)|0\n    pickShape[1] = Math.max(height/scene.pixelRatio, 1)|0\n\n    //Compute camera parameters\n\n    if(isOrtho) {\n      ortho(projection,\n        -width/height,\n        width/height,\n        -1,\n        1,\n        scene.zNear,\n        scene.zFar\n      )\n      cameraParams._ortho = true\n    } else {\n      perspective(projection,\n        scene.fovy,\n        width/height,\n        scene.zNear,\n        scene.zFar\n      )\n      cameraParams._ortho = false\n    }\n\n    //Compute model matrix\n    for(var i=0; i<16; ++i) {\n      model[i] = 0\n    }\n    model[15] = 1\n\n    var maxS = 0\n    for(var i=0; i<3; ++i) {\n      maxS = Math.max(maxS, bounds[1][i] - bounds[0][i])\n    }\n\n    for(var i=0; i<3; ++i) {\n      if(scene.autoScale) {\n        model[5*i] = scene.aspect[i] / (bounds[1][i] - bounds[0][i])\n      } else {\n        model[5*i] = 1  / maxS\n      }\n      if(scene.autoCenter) {\n        model[12+i] = -model[5*i] * 0.5 * (bounds[0][i] + bounds[1][i])\n      }\n    }\n\n    //Apply axes/clip bounds\n    for(var i=0; i<numObjs; ++i) {\n      var obj = objects[i]\n\n      //Set axes bounds\n      obj.axesBounds = bounds\n\n      //Set clip bounds\n      if(scene.clipToBounds) {\n        obj.clipBounds = bounds\n      }\n    }\n    //Set spike parameters\n    if(selection.object) {\n      if(scene.snapToData) {\n        spikes.position = selection.dataCoordinate\n      } else {\n        spikes.position = selection.dataPosition\n      }\n      spikes.bounds = bounds\n    }\n\n    //If state changed, then redraw pick buffers\n    if(pickDirty) {\n      pickDirty = false\n      renderPick()\n    }\n\n    //Recalculate pixel data\n    scene.axesPixels = axesRanges(scene.axes, cameraParams, width, height)\n\n    //Call render callback\n    if(scene.onrender) {\n      scene.onrender()\n    }\n\n    //Read value\n    gl.bindFramebuffer(gl.FRAMEBUFFER, null)\n    gl.viewport(0, 0, width, height)\n\n    //General strategy: 3 steps\n    //  1. render non-transparent objects\n    //  2. accumulate transparent objects into separate fbo\n    //  3. composite final scene\n\n    //Clear FBO\n    var clearColor = scene.clearColor\n    gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3])\n    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)\n    gl.depthMask(true)\n    gl.colorMask(true, true, true, true)\n    gl.enable(gl.DEPTH_TEST)\n    gl.depthFunc(gl.LEQUAL)\n    gl.disable(gl.BLEND)\n    gl.disable(gl.CULL_FACE)  //most visualization surfaces are 2 sided\n\n    //Render opaque pass\n    var hasTransparent = false\n    if(axes.enable) {\n      hasTransparent = hasTransparent || axes.isTransparent()\n      axes.draw(cameraParams)\n    }\n    spikes.axes = axes\n    if(selection.object) {\n      spikes.draw(cameraParams)\n    }\n\n    gl.disable(gl.CULL_FACE)  //most visualization surfaces are 2 sided\n\n    for(var i=0; i<numObjs; ++i) {\n      var obj = objects[i]\n      obj.axes = axes\n      obj.pixelRatio = scene.pixelRatio\n      if(obj.isOpaque && obj.isOpaque()) {\n        obj.draw(cameraParams)\n      }\n      if(obj.isTransparent && obj.isTransparent()) {\n        hasTransparent = true\n      }\n    }\n\n    if(hasTransparent) {\n      //Render transparent pass\n      accumBuffer.shape = viewShape\n      accumBuffer.bind()\n      gl.clear(gl.DEPTH_BUFFER_BIT)\n      gl.colorMask(false, false, false, false)\n      gl.depthMask(true)\n      gl.depthFunc(gl.LESS)\n\n      //Render forward facing objects\n      if(axes.enable && axes.isTransparent()) {\n        axes.drawTransparent(cameraParams)\n      }\n      for(var i=0; i<numObjs; ++i) {\n        var obj = objects[i]\n        if(obj.isOpaque && obj.isOpaque()) {\n          obj.draw(cameraParams)\n        }\n      }\n\n      //Render transparent pass\n      gl.enable(gl.BLEND)\n      gl.blendEquation(gl.FUNC_ADD)\n      gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)\n      gl.colorMask(true, true, true, true)\n      gl.depthMask(false)\n      gl.clearColor(0,0,0,0)\n      gl.clear(gl.COLOR_BUFFER_BIT)\n\n      if(axes.isTransparent()) {\n        axes.drawTransparent(cameraParams)\n      }\n\n      for(var i=0; i<numObjs; ++i) {\n        var obj = objects[i]\n        if(obj.isTransparent && obj.isTransparent()) {\n          obj.drawTransparent(cameraParams)\n        }\n      }\n\n      //Unbind framebuffer\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null)\n\n      //Draw composite pass\n      gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)\n      gl.disable(gl.DEPTH_TEST)\n      accumShader.bind()\n      accumBuffer.color[0].bind(0)\n      accumShader.uniforms.accumBuffer = 0\n      drawTriangle(gl)\n\n      //Turn off blending\n      gl.disable(gl.BLEND)\n    }\n\n    //Clear dirty flags\n    dirty = false\n    for(var i=0; i<numObjs; ++i) {\n      objects[i].dirty = false\n    }\n  }\n\n  //Draw the whole scene\n  function render() {\n    if(scene._stopped || scene.contextLost) {\n      return\n    }\n    // this order is important: ios safari sometimes has sync raf\n    redraw()\n    requestAnimationFrame(render)\n  }\n\n  scene.enableMouseListeners()\n  render()\n\n  //Force redraw of whole scene\n  scene.redraw = function() {\n    if(scene._stopped) {\n      return\n    }\n    dirty = true\n    redraw()\n  }\n\n  return scene\n}\n\n},{\"./camera.js\":288,\"./lib/shader\":289,\"a-big-triangle\":59,\"gl-axes3d\":233,\"gl-axes3d/properties\":240,\"gl-fbo\":249,\"gl-mat4/ortho\":268,\"gl-mat4/perspective\":269,\"gl-select-static\":300,\"gl-spikes3d\":310,\"is-mobile\":420,\"mouse-change\":435,\"mouse-wheel\":438}],291:[function(_dereq_,module,exports){\nvar glslify = _dereq_('glslify')\n\nexports.pointVertex       = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec2 position;\\n\\nuniform mat3 matrix;\\nuniform float pointSize;\\nuniform float pointCloud;\\n\\nhighp float rand(vec2 co) {\\n  highp float a = 12.9898;\\n  highp float b = 78.233;\\n  highp float c = 43758.5453;\\n  highp float d = dot(co.xy, vec2(a, b));\\n  highp float e = mod(d, 3.14);\\n  return fract(sin(e) * c);\\n}\\n\\nvoid main() {\\n  vec3 hgPosition = matrix * vec3(position, 1);\\n  gl_Position  = vec4(hgPosition.xy, 0, hgPosition.z);\\n    // if we don't jitter the point size a bit, overall point cloud\\n    // saturation 'jumps' on zooming, which is disturbing and confusing\\n  gl_PointSize = pointSize * ((19.5 + rand(position)) / 20.0);\\n  if(pointCloud != 0.0) { // pointCloud is truthy\\n    // get the same square surface as circle would be\\n    gl_PointSize *= 0.886;\\n  }\\n}\"])\nexports.pointFragment     = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nuniform vec4 color, borderColor;\\nuniform float centerFraction;\\nuniform float pointCloud;\\n\\nvoid main() {\\n  float radius;\\n  vec4 baseColor;\\n  if(pointCloud != 0.0) { // pointCloud is truthy\\n    if(centerFraction == 1.0) {\\n      gl_FragColor = color;\\n    } else {\\n      gl_FragColor = mix(borderColor, color, centerFraction);\\n    }\\n  } else {\\n    radius = length(2.0 * gl_PointCoord.xy - 1.0);\\n    if(radius > 1.0) {\\n      discard;\\n    }\\n    baseColor = mix(borderColor, color, step(radius, centerFraction));\\n    gl_FragColor = vec4(baseColor.rgb * baseColor.a, baseColor.a);\\n  }\\n}\\n\"])\nexports.pickVertex        = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec2 position;\\nattribute vec4 pickId;\\n\\nuniform mat3 matrix;\\nuniform float pointSize;\\nuniform vec4 pickOffset;\\n\\nvarying vec4 fragId;\\n\\nvoid main() {\\n  vec3 hgPosition = matrix * vec3(position, 1);\\n  gl_Position  = vec4(hgPosition.xy, 0, hgPosition.z);\\n  gl_PointSize = pointSize;\\n\\n  vec4 id = pickId + pickOffset;\\n  id.y += floor(id.x / 256.0);\\n  id.x -= floor(id.x / 256.0) * 256.0;\\n\\n  id.z += floor(id.y / 256.0);\\n  id.y -= floor(id.y / 256.0) * 256.0;\\n\\n  id.w += floor(id.z / 256.0);\\n  id.z -= floor(id.z / 256.0) * 256.0;\\n\\n  fragId = id;\\n}\\n\"])\nexports.pickFragment      = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nvarying vec4 fragId;\\n\\nvoid main() {\\n  float radius = length(2.0 * gl_PointCoord.xy - 1.0);\\n  if(radius > 1.0) {\\n    discard;\\n  }\\n  gl_FragColor = fragId / 255.0;\\n}\\n\"])\n\n},{\"glslify\":409}],292:[function(_dereq_,module,exports){\n'use strict'\n\nvar createShader = _dereq_('gl-shader')\nvar createBuffer = _dereq_('gl-buffer')\n\nvar pool = _dereq_('typedarray-pool')\n\nvar SHADERS = _dereq_('./lib/shader')\n\nmodule.exports = createPointcloud2D\n\nfunction Pointcloud2D(plot, offsetBuffer, pickBuffer, shader, pickShader) {\n  this.plot           = plot\n  this.offsetBuffer   = offsetBuffer\n  this.pickBuffer     = pickBuffer\n  this.shader         = shader\n  this.pickShader     = pickShader\n  this.sizeMin        = 0.5\n  this.sizeMinCap     = 2\n  this.sizeMax        = 20\n  this.areaRatio      = 1.0\n  this.pointCount     = 0\n  this.color          = [1, 0, 0, 1]\n  this.borderColor    = [0, 0, 0, 1]\n  this.blend          = false\n  this.pickOffset     = 0\n  this.points         = null\n}\n\nvar proto = Pointcloud2D.prototype\n\nproto.dispose = function() {\n  this.shader.dispose()\n  this.pickShader.dispose()\n  this.offsetBuffer.dispose()\n  this.pickBuffer.dispose()\n  this.plot.removeObject(this)\n}\n\nproto.update = function(options) {\n\n  var i\n\n  options = options || {}\n\n  function dflt(opt, value) {\n    if(opt in options) {\n      return options[opt]\n    }\n    return value\n  }\n\n  this.sizeMin      = dflt('sizeMin', 0.5)\n  // this.sizeMinCap      = dflt('sizeMinCap', 2)\n  this.sizeMax      = dflt('sizeMax', 20)\n  this.color        = dflt('color', [1, 0, 0, 1]).slice()\n  this.areaRatio    = dflt('areaRatio', 1)\n  this.borderColor  = dflt('borderColor', [0, 0, 0, 1]).slice()\n  this.blend        = dflt('blend', false)\n\n  //Update point data\n\n  // Attempt straight-through processing (STP) to avoid allocation and copy\n  // TODO eventually abstract out STP logic, maybe into `pool` or a layer above\n  var pointCount = options.positions.length >>> 1\n  var dataStraightThrough = options.positions instanceof Float32Array\n  var idStraightThrough = options.idToIndex instanceof Int32Array && options.idToIndex.length >= pointCount // permit larger to help reuse\n\n  var data          = options.positions\n  var packed        = dataStraightThrough ? data : pool.mallocFloat32(data.length)\n  var packedId      = idStraightThrough ? options.idToIndex : pool.mallocInt32(pointCount)\n\n  if(!dataStraightThrough) {\n    packed.set(data)\n  }\n\n  if(!idStraightThrough) {\n    packed.set(data)\n    for(i = 0; i < pointCount; i++) {\n      packedId[i] = i\n    }\n  }\n\n  this.points       = data\n\n  this.offsetBuffer.update(packed)\n  this.pickBuffer.update(packedId)\n\n  if(!dataStraightThrough) {\n    pool.free(packed)\n  }\n\n  if(!idStraightThrough) {\n    pool.free(packedId)\n  }\n\n  this.pointCount = pointCount\n  this.pickOffset = 0\n}\n\nfunction count(points, dataBox) {\n  var visiblePointCountEstimate = 0\n  var length = points.length >>> 1\n  var i\n  for(i = 0; i < length; i++) {\n    var x = points[i * 2]\n    var y = points[i * 2 + 1]\n    if(x >= dataBox[0] && x <= dataBox[2] && y >= dataBox[1] && y <= dataBox[3])\n      visiblePointCountEstimate++\n  }\n  return visiblePointCountEstimate\n}\n\nproto.unifiedDraw = (function() {\n  var MATRIX = [1, 0, 0,\n                0, 1, 0,\n                0, 0, 1]\n  var PICK_VEC4 = [0, 0, 0, 0]\nreturn function(pickOffset) {\n  var pick = pickOffset !== void(0)\n\n  var shader        = pick ? this.pickShader : this.shader\n  var gl            = this.plot.gl\n  var dataBox       = this.plot.dataBox\n\n  if(this.pointCount === 0) {\n    return pickOffset\n  }\n\n  var dataX   = dataBox[2] - dataBox[0]\n  var dataY   = dataBox[3] - dataBox[1]\n\n  var visiblePointCountEstimate = count(this.points, dataBox)\n  var basicPointSize =  this.plot.pickPixelRatio * Math.max(Math.min(this.sizeMinCap, this.sizeMin), Math.min(this.sizeMax, this.sizeMax / Math.pow(visiblePointCountEstimate, 0.33333)))\n\n  MATRIX[0] = 2.0 / dataX\n  MATRIX[4] = 2.0 / dataY\n  MATRIX[6] = -2.0 * dataBox[0] / dataX - 1.0\n  MATRIX[7] = -2.0 * dataBox[1] / dataY - 1.0\n\n  this.offsetBuffer.bind()\n\n  shader.bind()\n  shader.attributes.position.pointer()\n  shader.uniforms.matrix      = MATRIX\n  shader.uniforms.color       = this.color\n  shader.uniforms.borderColor = this.borderColor\n  shader.uniforms.pointCloud = basicPointSize < 5\n  shader.uniforms.pointSize = basicPointSize\n  shader.uniforms.centerFraction = Math.min(1, Math.max(0, Math.sqrt(1 - this.areaRatio)))\n\n  if(pick) {\n\n    PICK_VEC4[0] = ( pickOffset        & 0xff)\n    PICK_VEC4[1] = ((pickOffset >> 8)  & 0xff)\n    PICK_VEC4[2] = ((pickOffset >> 16) & 0xff)\n    PICK_VEC4[3] = ((pickOffset >> 24) & 0xff)\n\n    this.pickBuffer.bind()\n    shader.attributes.pickId.pointer(gl.UNSIGNED_BYTE)\n    shader.uniforms.pickOffset = PICK_VEC4\n    this.pickOffset = pickOffset\n  }\n\n  // Worth switching these off, but we can't make assumptions about other\n  // renderers, so let's restore it after each draw\n  var blend = gl.getParameter(gl.BLEND)\n  var dither = gl.getParameter(gl.DITHER)\n\n  if(blend && !this.blend)\n    gl.disable(gl.BLEND)\n  if(dither)\n    gl.disable(gl.DITHER)\n\n  gl.drawArrays(gl.POINTS, 0, this.pointCount)\n\n  if(blend && !this.blend)\n    gl.enable(gl.BLEND)\n  if(dither)\n    gl.enable(gl.DITHER)\n\n  return pickOffset + this.pointCount\n}\n})()\n\nproto.draw = proto.unifiedDraw\nproto.drawPick = proto.unifiedDraw\n\nproto.pick = function(x, y, value) {\n  var pickOffset = this.pickOffset\n  var pointCount = this.pointCount\n  if(value < pickOffset || value >= pickOffset + pointCount) {\n    return null\n  }\n  var pointId = value - pickOffset\n  var points = this.points\n  return {\n    object: this,\n    pointId: pointId,\n    dataCoord: [points[2 * pointId], points[2 * pointId + 1] ]\n  }\n}\n\nfunction createPointcloud2D(plot, options) {\n  var gl = plot.gl\n  var buffer = createBuffer(gl)\n  var pickBuffer = createBuffer(gl)\n  var shader = createShader(gl, SHADERS.pointVertex, SHADERS.pointFragment)\n  var pickShader = createShader(gl, SHADERS.pickVertex, SHADERS.pickFragment)\n\n  var result = new Pointcloud2D(plot, buffer, pickBuffer, shader, pickShader)\n  result.update(options)\n\n  //Register with plot\n  plot.addObject(result)\n\n  return result\n}\n\n},{\"./lib/shader\":291,\"gl-buffer\":241,\"gl-shader\":301,\"typedarray-pool\":545}],293:[function(_dereq_,module,exports){\nmodule.exports = slerp\n\n/**\n * Performs a spherical linear interpolation between two quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {quat} out\n */\nfunction slerp (out, a, b, t) {\n  // benchmarks:\n  //    http://jsperf.com/quaternion-slerp-implementations\n\n  var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n    bx = b[0], by = b[1], bz = b[2], bw = b[3]\n\n  var omega, cosom, sinom, scale0, scale1\n\n  // calc cosine\n  cosom = ax * bx + ay * by + az * bz + aw * bw\n  // adjust signs (if necessary)\n  if (cosom < 0.0) {\n    cosom = -cosom\n    bx = -bx\n    by = -by\n    bz = -bz\n    bw = -bw\n  }\n  // calculate coefficients\n  if ((1.0 - cosom) > 0.000001) {\n    // standard case (slerp)\n    omega = Math.acos(cosom)\n    sinom = Math.sin(omega)\n    scale0 = Math.sin((1.0 - t) * omega) / sinom\n    scale1 = Math.sin(t * omega) / sinom\n  } else {\n    // \"from\" and \"to\" quaternions are very close\n    //  ... so we can do a linear interpolation\n    scale0 = 1.0 - t\n    scale1 = t\n  }\n  // calculate final values\n  out[0] = scale0 * ax + scale1 * bx\n  out[1] = scale0 * ay + scale1 * by\n  out[2] = scale0 * az + scale1 * bz\n  out[3] = scale0 * aw + scale1 * bw\n\n  return out\n}\n\n},{}],294:[function(_dereq_,module,exports){\n'use strict';\n\nmodule.exports = function(a){\n  return (!a && a !== 0) ? '' : a.toString();\n}\n\n},{}],295:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar vectorizeText = _dereq_(\"vectorize-text\")\n\nmodule.exports = getGlyph\n\nvar GLYPH_CACHE = {}\n\nfunction getGlyph(symbol, font, pixelRatio) {\n  var fontCache = GLYPH_CACHE[font]\n  if(!fontCache) {\n    fontCache = GLYPH_CACHE[font] = {}\n  }\n  if(symbol in fontCache) {\n    return fontCache[symbol]\n  }\n\n  var config = {\n    textAlign: \"center\",\n    textBaseline: \"middle\",\n    lineHeight: 1.0,\n    font: font,\n    lineSpacing: 1.25,\n    styletags: {\n      breaklines:true,\n      bolds: true,\n      italics: true,\n      subscripts:true,\n      superscripts:true\n    }\n  }\n\n  //Get line and triangle meshes for glyph\n  config.triangles = true\n  var triSymbol = vectorizeText(symbol, config)\n  config.triangles = false\n  var lineSymbol = vectorizeText(symbol, config)\n\n  var i, j\n\n  if(pixelRatio && pixelRatio !== 1) {\n    for(i = 0; i < triSymbol.positions.length; ++i){\n      for(j = 0; j < triSymbol.positions[i].length; ++j){\n        triSymbol.positions[i][j] /= pixelRatio;\n      }\n    }\n\n    for(i = 0; i < lineSymbol.positions.length; ++i){\n      for(j = 0; j < lineSymbol.positions[i].length; ++j){\n        lineSymbol.positions[i][j] /= pixelRatio;\n      }\n    }\n  }\n\n  //Calculate bounding box\n  var bounds = [[Infinity,Infinity], [-Infinity,-Infinity]]\n  var n = lineSymbol.positions.length\n  for(i = 0; i < n; ++i) {\n    var p = lineSymbol.positions[i]\n    for(j=0; j<2; ++j) {\n      bounds[0][j] = Math.min(bounds[0][j], p[j])\n      bounds[1][j] = Math.max(bounds[1][j], p[j])\n    }\n  }\n\n  //Save cached symbol\n  return fontCache[symbol] = [triSymbol, lineSymbol, bounds]\n}\n},{\"vectorize-text\":550}],296:[function(_dereq_,module,exports){\nvar createShaderWrapper = _dereq_('gl-shader')\nvar glslify = _dereq_('glslify')\n\nvar perspectiveVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nattribute vec3 position;\\nattribute vec4 color;\\nattribute vec2 glyph;\\nattribute vec4 id;\\n\\nuniform vec4 highlightId;\\nuniform float highlightScale;\\nuniform mat4 model, view, projection;\\nuniform vec3 clipBounds[2];\\n\\nvarying vec4 interpColor;\\nvarying vec4 pickId;\\nvarying vec3 dataCoordinate;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\\n\\n    gl_Position = vec4(0,0,0,0);\\n  } else {\\n    float scale = 1.0;\\n    if(distance(highlightId, id) < 0.0001) {\\n      scale = highlightScale;\\n    }\\n\\n    vec4 worldPosition = model * vec4(position, 1);\\n    vec4 viewPosition = view * worldPosition;\\n    viewPosition = viewPosition / viewPosition.w;\\n    vec4 clipPosition = projection * (viewPosition + scale * vec4(glyph.x, -glyph.y, 0, 0));\\n\\n    gl_Position = clipPosition;\\n    interpColor = color;\\n    pickId = id;\\n    dataCoordinate = position;\\n  }\\n}\"])\nvar orthographicVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nattribute vec3 position;\\nattribute vec4 color;\\nattribute vec2 glyph;\\nattribute vec4 id;\\n\\nuniform mat4 model, view, projection;\\nuniform vec2 screenSize;\\nuniform vec3 clipBounds[2];\\nuniform float highlightScale, pixelRatio;\\nuniform vec4 highlightId;\\n\\nvarying vec4 interpColor;\\nvarying vec4 pickId;\\nvarying vec3 dataCoordinate;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\\n\\n    gl_Position = vec4(0,0,0,0);\\n  } else {\\n    float scale = pixelRatio;\\n    if(distance(highlightId.bgr, id.bgr) < 0.001) {\\n      scale *= highlightScale;\\n    }\\n\\n    vec4 worldPosition = model * vec4(position, 1.0);\\n    vec4 viewPosition = view * worldPosition;\\n    vec4 clipPosition = projection * viewPosition;\\n    clipPosition /= clipPosition.w;\\n\\n    gl_Position = clipPosition + vec4(screenSize * scale * vec2(glyph.x, -glyph.y), 0.0, 0.0);\\n    interpColor = color;\\n    pickId = id;\\n    dataCoordinate = position;\\n  }\\n}\"])\nvar projectionVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nattribute vec3 position;\\nattribute vec4 color;\\nattribute vec2 glyph;\\nattribute vec4 id;\\n\\nuniform float highlightScale;\\nuniform vec4 highlightId;\\nuniform vec3 axes[2];\\nuniform mat4 model, view, projection;\\nuniform vec2 screenSize;\\nuniform vec3 clipBounds[2];\\nuniform float scale, pixelRatio;\\n\\nvarying vec4 interpColor;\\nvarying vec4 pickId;\\nvarying vec3 dataCoordinate;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], position)) {\\n\\n    gl_Position = vec4(0,0,0,0);\\n  } else {\\n    float lscale = pixelRatio * scale;\\n    if(distance(highlightId, id) < 0.0001) {\\n      lscale *= highlightScale;\\n    }\\n\\n    vec4 clipCenter   = projection * view * model * vec4(position, 1);\\n    vec3 dataPosition = position + 0.5*lscale*(axes[0] * glyph.x + axes[1] * glyph.y) * clipCenter.w * screenSize.y;\\n    vec4 clipPosition = projection * view * model * vec4(dataPosition, 1);\\n\\n    gl_Position = clipPosition;\\n    interpColor = color;\\n    pickId = id;\\n    dataCoordinate = dataPosition;\\n  }\\n}\\n\"])\nvar drawFragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3 fragClipBounds[2];\\nuniform float opacity;\\n\\nvarying vec4 interpColor;\\nvarying vec4 pickId;\\nvarying vec3 dataCoordinate;\\n\\nvoid main() {\\n  if (\\n    outOfRange(fragClipBounds[0], fragClipBounds[1], dataCoordinate) ||\\n    interpColor.a * opacity == 0.\\n  ) discard;\\n  gl_FragColor = interpColor * opacity;\\n}\\n\"])\nvar pickFragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3 fragClipBounds[2];\\nuniform float pickGroup;\\n\\nvarying vec4 pickId;\\nvarying vec3 dataCoordinate;\\n\\nvoid main() {\\n  if (outOfRange(fragClipBounds[0], fragClipBounds[1], dataCoordinate)) discard;\\n\\n  gl_FragColor = vec4(pickGroup, pickId.bgr);\\n}\"])\n\nvar ATTRIBUTES = [\n  {name: 'position', type: 'vec3'},\n  {name: 'color', type: 'vec4'},\n  {name: 'glyph', type: 'vec2'},\n  {name: 'id', type: 'vec4'}\n]\n\nvar perspective = {\n    vertex: perspectiveVertSrc,\n    fragment: drawFragSrc,\n    attributes: ATTRIBUTES\n  },\n  ortho = {\n    vertex: orthographicVertSrc,\n    fragment: drawFragSrc,\n    attributes: ATTRIBUTES\n  },\n  project = {\n    vertex: projectionVertSrc,\n    fragment: drawFragSrc,\n    attributes: ATTRIBUTES\n  },\n  pickPerspective = {\n    vertex: perspectiveVertSrc,\n    fragment: pickFragSrc,\n    attributes: ATTRIBUTES\n  },\n  pickOrtho = {\n    vertex: orthographicVertSrc,\n    fragment: pickFragSrc,\n    attributes: ATTRIBUTES\n  },\n  pickProject = {\n    vertex: projectionVertSrc,\n    fragment: pickFragSrc,\n    attributes: ATTRIBUTES\n  }\n\nfunction createShader(gl, src) {\n  var shader = createShaderWrapper(gl, src)\n  var attr = shader.attributes\n  attr.position.location = 0\n  attr.color.location = 1\n  attr.glyph.location = 2\n  attr.id.location = 3\n  return shader\n}\n\nexports.createPerspective = function(gl) {\n  return createShader(gl, perspective)\n}\nexports.createOrtho = function(gl) {\n  return createShader(gl, ortho)\n}\nexports.createProject = function(gl) {\n  return createShader(gl, project)\n}\nexports.createPickPerspective = function(gl) {\n  return createShader(gl, pickPerspective)\n}\nexports.createPickOrtho = function(gl) {\n  return createShader(gl, pickOrtho)\n}\nexports.createPickProject = function(gl) {\n  return createShader(gl, pickProject)\n}\n\n},{\"gl-shader\":301,\"glslify\":409}],297:[function(_dereq_,module,exports){\n'use strict'\n\nvar isAllBlank      = _dereq_('is-string-blank')\nvar createBuffer    = _dereq_('gl-buffer')\nvar createVAO       = _dereq_('gl-vao')\nvar pool            = _dereq_('typedarray-pool')\nvar mat4mult        = _dereq_('gl-mat4/multiply')\nvar shaders         = _dereq_('./lib/shaders')\nvar getGlyph        = _dereq_('./lib/glyphs')\nvar getSimpleString = _dereq_('./lib/get-simple-string')\n\nvar IDENTITY = [1,0,0,0,\n                0,1,0,0,\n                0,0,1,0,\n                0,0,0,1]\n\nmodule.exports = createPointCloud\n\nfunction transformMat4(x, m) {\n  var x0 = x[0]\n  var x1 = x[1]\n  var x2 = x[2]\n  var x3 = x[3]\n  x[0] = m[0] * x0 + m[4] * x1 + m[8]  * x2 + m[12] * x3\n  x[1] = m[1] * x0 + m[5] * x1 + m[9]  * x2 + m[13] * x3\n  x[2] = m[2] * x0 + m[6] * x1 + m[10] * x2 + m[14] * x3\n  x[3] = m[3] * x0 + m[7] * x1 + m[11] * x2 + m[15] * x3\n  return x\n}\n\nfunction project(p, v, m, x) {\n  transformMat4(x, x, m)\n  transformMat4(x, x, v)\n  return transformMat4(x, x, p)\n}\n\nfunction ScatterPlotPickResult(index, position) {\n  this.index = index\n  this.dataCoordinate = this.position = position\n}\n\nfunction fixOpacity(a) {\n  if(a === true) return 1\n  if(a > 1) return 1\n  return a\n}\n\nfunction PointCloud(\n  gl,\n  shader,\n  orthoShader,\n  projectShader,\n  pointBuffer,\n  colorBuffer,\n  glyphBuffer,\n  idBuffer,\n  vao,\n  pickPerspectiveShader,\n  pickOrthoShader,\n  pickProjectShader) {\n\n  this.gl              = gl\n\n  this.pixelRatio      = 1\n\n  this.shader          = shader\n  this.orthoShader     = orthoShader\n  this.projectShader   = projectShader\n\n  this.pointBuffer     = pointBuffer\n  this.colorBuffer     = colorBuffer\n  this.glyphBuffer     = glyphBuffer\n  this.idBuffer        = idBuffer\n  this.vao             = vao\n  this.vertexCount     = 0\n  this.lineVertexCount = 0\n\n  this.opacity         = 1\n  this.hasAlpha        = false\n\n  this.lineWidth       = 0\n  this.projectScale    = [2.0/3.0, 2.0/3.0, 2.0/3.0]\n  this.projectOpacity  = [1, 1, 1]\n  this.projectHasAlpha  = false\n\n  this.pickId                = 0\n  this.pickPerspectiveShader = pickPerspectiveShader\n  this.pickOrthoShader       = pickOrthoShader\n  this.pickProjectShader     = pickProjectShader\n  this.points                = []\n\n  this._selectResult = new ScatterPlotPickResult(0, [0,0,0])\n\n  this.useOrtho = true\n  this.bounds   = [[ Infinity,Infinity,Infinity],\n                   [-Infinity,-Infinity,-Infinity]]\n\n  //Axes projections\n  this.axesProject = [ true, true, true ]\n  this.axesBounds = [[-Infinity,-Infinity,-Infinity],\n                     [ Infinity, Infinity, Infinity]]\n\n  this.highlightId    = [1,1,1,1]\n  this.highlightScale = 2\n\n  this.clipBounds = [[-Infinity,-Infinity,-Infinity],\n                     [ Infinity, Infinity, Infinity]]\n\n  this.dirty = true\n}\n\nvar proto = PointCloud.prototype\n\nproto.pickSlots = 1\n\nproto.setPickBase = function(pickBase) {\n  this.pickId = pickBase\n}\n\nproto.isTransparent = function() {\n  if(this.hasAlpha)  {\n    return true\n  }\n  for(var i=0; i<3; ++i) {\n    if(this.axesProject[i] && this.projectHasAlpha) {\n      return true\n    }\n  }\n  return false\n}\n\nproto.isOpaque = function() {\n  if(!this.hasAlpha)  {\n    return true\n  }\n  for(var i=0; i<3; ++i) {\n    if(this.axesProject[i] && !this.projectHasAlpha) {\n      return true\n    }\n  }\n  return false\n}\n\nvar VIEW_SHAPE = [0,0]\nvar U_VEC = [0,0,0]\nvar V_VEC = [0,0,0]\nvar MU_VEC = [0,0,0,1]\nvar MV_VEC = [0,0,0,1]\nvar SCRATCH_MATRIX = IDENTITY.slice()\nvar SCRATCH_VEC = [0,0,0]\nvar CLIP_BOUNDS = [[0,0,0], [0,0,0]]\n\nfunction zeroVec(a) {\n  a[0] = a[1] = a[2] = 0\n  return a\n}\n\nfunction augment(hg, af) {\n  hg[0] = af[0]\n  hg[1] = af[1]\n  hg[2] = af[2]\n  hg[3] = 1\n  return hg\n}\n\nfunction setComponent(out, v, i, x) {\n  out[0] = v[0]\n  out[1] = v[1]\n  out[2] = v[2]\n  out[i] = x\n  return out\n}\n\nfunction getClipBounds(bounds) {\n  var result = CLIP_BOUNDS\n  for(var i=0; i<2; ++i) {\n    for(var j=0; j<3; ++j) {\n      result[i][j] = Math.max(Math.min(bounds[i][j], 1e8), -1e8)\n    }\n  }\n  return result\n}\n\nfunction drawProject(shader, points, camera, pixelRatio) {\n  var axesProject = points.axesProject\n\n  var gl         = points.gl\n  var uniforms   = shader.uniforms\n  var model      = camera.model      || IDENTITY\n  var view       = camera.view       || IDENTITY\n  var projection = camera.projection || IDENTITY\n  var bounds     = points.axesBounds\n  var clipBounds = getClipBounds(points.clipBounds)\n\n  var cubeAxis\n  if(points.axes && points.axes.lastCubeProps) {\n    cubeAxis = points.axes.lastCubeProps.axis\n  } else {\n    cubeAxis = [1,1,1]\n  }\n\n  VIEW_SHAPE[0] = 2.0/gl.drawingBufferWidth\n  VIEW_SHAPE[1] = 2.0/gl.drawingBufferHeight\n\n  shader.bind()\n  uniforms.view           = view\n  uniforms.projection     = projection\n  uniforms.screenSize     = VIEW_SHAPE\n  uniforms.highlightId    = points.highlightId\n  uniforms.highlightScale = points.highlightScale\n  uniforms.clipBounds     = clipBounds\n  uniforms.pickGroup      = points.pickId / 255.0\n  uniforms.pixelRatio     = pixelRatio\n\n  for(var i=0; i<3; ++i) {\n    if(!axesProject[i]) {\n      continue\n    }\n\n    uniforms.scale          = points.projectScale[i]\n    uniforms.opacity        = points.projectOpacity[i]\n\n    //Project model matrix\n    var pmodel = SCRATCH_MATRIX\n    for(var j=0; j<16; ++j) {\n      pmodel[j] = 0\n    }\n    for(var j=0; j<4; ++j) {\n      pmodel[5*j] = 1\n    }\n    pmodel[5*i] = 0\n    if(cubeAxis[i] < 0) {\n      pmodel[12+i] = bounds[0][i]\n    } else {\n      pmodel[12+i] = bounds[1][i]\n    }\n    mat4mult(pmodel, model, pmodel)\n    uniforms.model = pmodel\n\n    //Compute initial axes\n    var u = (i+1)%3\n    var v = (i+2)%3\n    var du = zeroVec(U_VEC)\n    var dv = zeroVec(V_VEC)\n    du[u] = 1\n    dv[v] = 1\n\n    //Align orientation relative to viewer\n    var mdu = project(projection, view, model, augment(MU_VEC, du))\n    var mdv = project(projection, view, model, augment(MV_VEC, dv))\n    if(Math.abs(mdu[1]) > Math.abs(mdv[1])) {\n      var tmp = mdu\n      mdu = mdv\n      mdv = tmp\n      tmp = du\n      du = dv\n      dv = tmp\n      var t = u\n      u = v\n      v = t\n    }\n    if(mdu[0] < 0) {\n      du[u] = -1\n    }\n    if(mdv[1] > 0) {\n      dv[v] = -1\n    }\n    var su = 0.0\n    var sv = 0.0\n    for(var j=0; j<4; ++j) {\n      su += Math.pow(model[4*u+j], 2)\n      sv += Math.pow(model[4*v+j], 2)\n    }\n    du[u] /= Math.sqrt(su)\n    dv[v] /= Math.sqrt(sv)\n    uniforms.axes[0] = du\n    uniforms.axes[1] = dv\n\n    //Update fragment clip bounds\n    uniforms.fragClipBounds[0] = setComponent(SCRATCH_VEC, clipBounds[0], i, -1e8)\n    uniforms.fragClipBounds[1] = setComponent(SCRATCH_VEC, clipBounds[1], i, 1e8)\n\n    points.vao.bind()\n\n    //Draw interior\n    points.vao.draw(gl.TRIANGLES, points.vertexCount)\n\n    //Draw edges\n    if(points.lineWidth > 0) {\n      gl.lineWidth(points.lineWidth * pixelRatio)\n      points.vao.draw(gl.LINES, points.lineVertexCount, points.vertexCount)\n    }\n\n    points.vao.unbind()\n  }\n}\n\n\nvar NEG_INFINITY3 = [-1e8, -1e8, -1e8]\nvar POS_INFINITY3 = [1e8, 1e8, 1e8]\nvar CLIP_GROUP    = [NEG_INFINITY3, POS_INFINITY3]\n\nfunction drawFull(shader, pshader, points, camera, pixelRatio, transparent, forceDraw) {\n  var gl = points.gl\n\n  if(transparent === points.projectHasAlpha || forceDraw) {\n    drawProject(pshader, points, camera, pixelRatio)\n  }\n\n  if(transparent === points.hasAlpha || forceDraw) {\n\n    shader.bind()\n    var uniforms = shader.uniforms\n\n    uniforms.model      = camera.model      || IDENTITY\n    uniforms.view       = camera.view       || IDENTITY\n    uniforms.projection = camera.projection || IDENTITY\n\n    VIEW_SHAPE[0]       = 2.0/gl.drawingBufferWidth\n    VIEW_SHAPE[1]       = 2.0/gl.drawingBufferHeight\n    uniforms.screenSize = VIEW_SHAPE\n\n    uniforms.highlightId    = points.highlightId\n    uniforms.highlightScale = points.highlightScale\n\n    uniforms.fragClipBounds = CLIP_GROUP\n    uniforms.clipBounds     = points.axes.bounds\n\n    uniforms.opacity    = points.opacity\n    uniforms.pickGroup  = points.pickId / 255.0\n\n    uniforms.pixelRatio = pixelRatio\n\n    points.vao.bind()\n\n    //Draw interior\n    points.vao.draw(gl.TRIANGLES, points.vertexCount)\n\n    //Draw edges\n    if(points.lineWidth > 0) {\n      gl.lineWidth(points.lineWidth * pixelRatio)\n      points.vao.draw(gl.LINES, points.lineVertexCount, points.vertexCount)\n    }\n\n    points.vao.unbind()\n  }\n\n\n}\n\nproto.draw = function(camera) {\n  var shader = this.useOrtho ? this.orthoShader : this.shader\n  drawFull(shader, this.projectShader, this, camera, this.pixelRatio, false, false)\n}\n\nproto.drawTransparent = function(camera) {\n  var shader = this.useOrtho ? this.orthoShader : this.shader\n  drawFull(shader, this.projectShader, this, camera, this.pixelRatio, true, false)\n}\n\nproto.drawPick = function(camera) {\n  var shader = this.useOrtho ? this.pickOrthoShader : this.pickPerspectiveShader\n  drawFull(shader, this.pickProjectShader, this, camera, 1, true, true)\n}\n\nproto.pick = function(selected) {\n  if(!selected) {\n    return null\n  }\n  if(selected.id !== this.pickId) {\n    return null\n  }\n  var x = selected.value[2] + (selected.value[1]<<8) + (selected.value[0]<<16)\n  if(x >= this.pointCount || x < 0) {\n    return null\n  }\n\n  //Unpack result\n  var coord = this.points[x]\n  var result = this._selectResult\n  result.index = x\n  for(var i=0; i<3; ++i) {\n    result.position[i] = result.dataCoordinate[i] = coord[i]\n  }\n  return result\n}\n\nproto.highlight = function(selection) {\n  if(!selection) {\n    this.highlightId = [1,1,1,1]\n  } else {\n    var pointId = selection.index\n    var a0 =  pointId     &0xff\n    var a1 = (pointId>>8) &0xff\n    var a2 = (pointId>>16)&0xff\n    this.highlightId = [a0/255.0, a1/255.0, a2/255.0, 0]\n  }\n}\n\nfunction get_glyphData(glyphs, index, font, pixelRatio) {\n  var str\n\n  // use the data if presented in an array\n  if(Array.isArray(glyphs)) {\n    if(index < glyphs.length) {\n      str = glyphs[index]\n    } else {\n      str = undefined\n    }\n  } else {\n    str = glyphs\n  }\n\n  str = getSimpleString(str) // this would handle undefined cases\n\n  var visible = true\n  if(isAllBlank(str)) {\n    str = '▼' // Note: this special character may have minimum number of surfaces\n    visible = false\n  }\n\n  var glyph = getGlyph(str, font, pixelRatio)\n\n  return { mesh:glyph[0],\n          lines:glyph[1],\n         bounds:glyph[2],\n        visible:visible };\n}\n\n\n\nproto.update = function(options) {\n\n  options = options || {}\n\n  if('perspective' in options) {\n    this.useOrtho = !options.perspective\n  }\n  if('orthographic' in options) {\n    this.useOrtho = !!options.orthographic\n  }\n  if('lineWidth' in options) {\n    this.lineWidth = options.lineWidth\n  }\n  if('project' in options) {\n    if(Array.isArray(options.project)) {\n      this.axesProject = options.project\n    } else {\n      var v = !!options.project\n      this.axesProject = [v,v,v]\n    }\n  }\n  if('projectScale' in options) {\n    if(Array.isArray(options.projectScale)) {\n      this.projectScale = options.projectScale.slice()\n    } else {\n      var s = +options.projectScale\n      this.projectScale = [s,s,s]\n    }\n  }\n\n  this.projectHasAlpha = false // default to no transparent draw\n  if('projectOpacity' in options) {\n    if(Array.isArray(options.projectOpacity)) {\n      this.projectOpacity = options.projectOpacity.slice()\n    } else {\n      var s = +options.projectOpacity\n      this.projectOpacity = [s,s,s]\n    }\n    for(var i=0; i<3; ++i) {\n      this.projectOpacity[i] = fixOpacity(this.projectOpacity[i]);\n      if(this.projectOpacity[i] < 1) {\n        this.projectHasAlpha = true;\n      }\n    }\n  }\n\n  this.hasAlpha = false // default to no transparent draw\n  if('opacity' in options) {\n    this.opacity = fixOpacity(options.opacity)\n    if(this.opacity < 1) {\n      this.hasAlpha = true;\n    }\n  }\n\n  //Set dirty flag\n  this.dirty = true\n\n  //Create new buffers\n  var points = options.position\n\n  //Text font\n  var font      = options.font      || 'normal'\n  var alignment = options.alignment || [0,0]\n\n  var alignmentX;\n  var alignmentY;\n  if (alignment.length === 2) {\n    alignmentX = alignment[0]\n    alignmentY = alignment[1]\n  } else {\n    alignmentX = []\n    alignmentY = []\n    for (var i = 0; i < alignment.length; ++i) {\n      alignmentX[i] = alignment[i][0]\n      alignmentY[i] = alignment[i][1]\n    }\n  }\n\n  //Bounds\n  var lowerBound = [ Infinity, Infinity, Infinity]\n  var upperBound = [-Infinity,-Infinity,-Infinity]\n\n  //Unpack options\n  var glyphs     = options.glyph\n  var colors     = options.color\n  var sizes      = options.size\n  var angles     = options.angle\n  var lineColors = options.lineColor\n\n  //Picking geometry\n  var pickCounter = -1\n\n  //First do pass to compute buffer sizes\n  var triVertexCount  = 0\n  var lineVertexCount = 0\n\n  var numPoints = 0;\n\n  if(points.length) {\n\n    //Count number of points and buffer size\n    numPoints = points.length\n\n  count_loop:\n    for(var i=0; i<numPoints; ++i) {\n      var x = points[i]\n      for(var j=0; j<3; ++j) {\n        if(isNaN(x[j]) || !isFinite(x[j])) {\n          continue count_loop\n        }\n      }\n\n      var glyphData = get_glyphData(glyphs, i, font, this.pixelRatio)\n\n      var glyphMesh   = glyphData.mesh\n      var glyphLines  = glyphData.lines\n      var glyphBounds = glyphData.bounds\n\n      triVertexCount  += glyphMesh.cells.length * 3\n      lineVertexCount += glyphLines.edges.length * 2\n    }\n  }\n\n  var vertexCount   = triVertexCount + lineVertexCount\n\n  //Preallocate data\n  var positionArray = pool.mallocFloat(3*vertexCount)\n  var colorArray    = pool.mallocFloat(4*vertexCount)\n  var glyphArray    = pool.mallocFloat(2*vertexCount)\n  var idArray       = pool.mallocUint32(vertexCount)\n\n  if(vertexCount > 0) {\n    var triOffset  = 0\n    var lineOffset = triVertexCount\n    var color      = [0,0,0,1]\n    var lineColor  = [0,0,0,1]\n\n    var isColorArray      = Array.isArray(colors)     && Array.isArray(colors[0])\n    var isLineColorArray  = Array.isArray(lineColors) && Array.isArray(lineColors[0])\n\n  fill_loop:\n    for(var i=0; i<numPoints; ++i) {\n      //Increment pickCounter\n      pickCounter += 1\n\n      var x = points[i]\n      for(var j=0; j<3; ++j) {\n        if(isNaN(x[j]) || !isFinite(x[j])) {\n          continue fill_loop\n        }\n\n        upperBound[j] = Math.max(upperBound[j], x[j])\n        lowerBound[j] = Math.min(lowerBound[j], x[j])\n      }\n\n      var glyphData = get_glyphData(glyphs, i, font, this.pixelRatio)\n\n      var glyphMesh   = glyphData.mesh\n      var glyphLines  = glyphData.lines\n      var glyphBounds = glyphData.bounds\n      var glyphVisible = glyphData.visible\n\n      //Get color\n      if(!glyphVisible) color = [1,1,1,0]\n      else if(Array.isArray(colors)) {\n        var c\n        if(isColorArray) {\n          if(i < colors.length) {\n            c = colors[i]\n          } else {\n            c = [0,0,0,0]\n          }\n        } else {\n          c = colors\n        }\n\n        if(c.length === 3) {\n          for(var j=0; j<3; ++j) {\n            color[j] = c[j]\n          }\n          color[3] = 1\n        } else if(c.length === 4) {\n          for(var j=0; j<4; ++j) {\n            color[j] = c[j]\n          }\n          if(!this.hasAlpha && c[3] < 1) this.hasAlpha = true\n        }\n      } else {\n        color[0] = color[1] = color[2] = 0\n        color[3] = 1\n      }\n\n\n      //Get lineColor\n      if(!glyphVisible) lineColor = [1,1,1,0]\n      else if(Array.isArray(lineColors)) {\n        var c\n        if(isLineColorArray) {\n          if(i < lineColors.length) {\n            c = lineColors[i]\n          } else {\n            c = [0,0,0,0]\n          }\n        } else {\n          c = lineColors\n        }\n\n        if(c.length === 3) {\n          for(var j=0; j<3; ++j) {\n            lineColor[j] = c[j]\n          }\n          lineColor[j] = 1\n        } else if(c.length === 4) {\n          for(var j=0; j<4; ++j) {\n            lineColor[j] = c[j]\n          }\n          if(!this.hasAlpha && c[3] < 1) this.hasAlpha = true\n        }\n      } else {\n        lineColor[0] = lineColor[1] = lineColor[2] = 0\n        lineColor[3] = 1\n      }\n\n\n      var size = 0.5\n      if(!glyphVisible) size = 0.0\n      else if(Array.isArray(sizes)) {\n        if(i < sizes.length) {\n          size = +sizes[i]\n        } else {\n          size = 12\n        }\n      } else if(sizes) {\n        size = +sizes\n      } else if(this.useOrtho) {\n        size = 12\n      }\n\n\n      var angle = 0\n      if(Array.isArray(angles)) {\n        if(i < angles.length) {\n          angle = +angles[i]\n        } else {\n          angle = 0\n        }\n      } else if(angles) {\n        angle = +angles\n      }\n\n      //Loop through markers and append to buffers\n      var cos = Math.cos(angle)\n      var sin = Math.sin(angle)\n\n      var x = points[i]\n      for(var j=0; j<3; ++j) {\n        upperBound[j] = Math.max(upperBound[j], x[j])\n        lowerBound[j] = Math.min(lowerBound[j], x[j])\n      }\n\n      //Calculate text offset\n      var textOffsetX = alignmentX\n      var textOffsetY = alignmentY\n\n      var textOffsetX = 0\n      if(Array.isArray(alignmentX)) {\n        if(i < alignmentX.length) {\n          textOffsetX = alignmentX[i]\n        } else {\n          textOffsetX = 0\n        }\n      } else if(alignmentX) {\n        textOffsetX = alignmentX\n      }\n\n      var textOffsetY = 0\n      if(Array.isArray(alignmentY)) {\n        if(i < alignmentY.length) {\n          textOffsetY = alignmentY[i]\n        } else {\n          textOffsetY = 0\n        }\n      } else if(alignmentY) {\n        textOffsetY = alignmentY\n      }\n\n      textOffsetX *= (textOffsetX > 0) ? (1 - glyphBounds[0][0]) :\n                     (textOffsetX < 0) ? (1 + glyphBounds[1][0]) : 1;\n\n      textOffsetY *= (textOffsetY > 0) ? (1 - glyphBounds[0][1]) :\n                     (textOffsetY < 0) ? (1 + glyphBounds[1][1]) : 1;\n\n      var textOffset = [textOffsetX, textOffsetY]\n\n      //Write out inner marker\n      var cells = glyphMesh.cells || []\n      var verts = glyphMesh.positions || []\n\n      for(var j=0; j<cells.length; ++j) {\n        var cell = cells[j]\n        for(var k=0; k<3; ++k) {\n          for(var l=0; l<3; ++l) {\n            positionArray[3*triOffset+l] = x[l]\n          }\n          for(var l=0; l<4; ++l) {\n            colorArray[4*triOffset+l] = color[l]\n          }\n          idArray[triOffset] = pickCounter\n          var p = verts[cell[k]]\n          glyphArray[2*triOffset]   = size * (cos*p[0] - sin*p[1] + textOffset[0])\n          glyphArray[2*triOffset+1] = size * (sin*p[0] + cos*p[1] + textOffset[1])\n          triOffset += 1\n        }\n      }\n\n      var cells = glyphLines.edges\n      var verts = glyphLines.positions\n\n      for(var j=0; j<cells.length; ++j) {\n        var cell = cells[j]\n        for(var k=0; k<2; ++k) {\n          for(var l=0; l<3; ++l) {\n            positionArray[3*lineOffset+l] = x[l]\n          }\n          for(var l=0; l<4; ++l) {\n            colorArray[4*lineOffset+l] = lineColor[l]\n          }\n          idArray[lineOffset] = pickCounter\n          var p = verts[cell[k]]\n          glyphArray[2*lineOffset]   = size * (cos*p[0] - sin*p[1] + textOffset[0])\n          glyphArray[2*lineOffset+1] = size * (sin*p[0] + cos*p[1] + textOffset[1])\n          lineOffset += 1\n        }\n      }\n\n    }\n\n\n\n  }\n\n  //Update bounds\n  this.bounds = [lowerBound, upperBound]\n\n  //Save points\n  this.points = points\n\n  //Save number of points\n  this.pointCount = points.length\n\n  //Update vertex counts\n  this.vertexCount      = triVertexCount\n  this.lineVertexCount  = lineVertexCount\n\n  this.pointBuffer.update(positionArray)\n  this.colorBuffer.update(colorArray)\n  this.glyphBuffer.update(glyphArray)\n  //this.idBuffer.update(new Uint32Array(idArray))\n  this.idBuffer.update(idArray)\n\n  pool.free(positionArray)\n  pool.free(colorArray)\n  pool.free(glyphArray)\n  pool.free(idArray)\n}\n\nproto.dispose = function() {\n  //Shaders\n  this.shader.dispose()\n  this.orthoShader.dispose()\n  this.pickPerspectiveShader.dispose()\n  this.pickOrthoShader.dispose()\n\n  //Vertex array\n  this.vao.dispose()\n\n  //Buffers\n  this.pointBuffer.dispose()\n  this.colorBuffer.dispose()\n  this.glyphBuffer.dispose()\n  this.idBuffer.dispose()\n}\n\nfunction createPointCloud(options) {\n  var gl = options.gl\n\n  var shader                = shaders.createPerspective(gl)\n  var orthoShader           = shaders.createOrtho(gl)\n  var projectShader         = shaders.createProject(gl)\n  var pickPerspectiveShader = shaders.createPickPerspective(gl)\n  var pickOrthoShader       = shaders.createPickOrtho(gl)\n  var pickProjectShader     = shaders.createPickProject(gl)\n\n  var pointBuffer = createBuffer(gl)\n  var colorBuffer = createBuffer(gl)\n  var glyphBuffer = createBuffer(gl)\n  var idBuffer    = createBuffer(gl)\n  var vao = createVAO(gl, [\n    {\n      buffer: pointBuffer,\n      size: 3,\n      type: gl.FLOAT\n    },\n    {\n      buffer: colorBuffer,\n      size: 4,\n      type: gl.FLOAT\n    },\n    {\n      buffer: glyphBuffer,\n      size: 2,\n      type: gl.FLOAT\n    },\n    {\n      buffer: idBuffer,\n      size: 4,\n      type: gl.UNSIGNED_BYTE,\n      normalized: true\n    }\n  ])\n\n  var pointCloud = new PointCloud(\n    gl,\n    shader,\n    orthoShader,\n    projectShader,\n    pointBuffer,\n    colorBuffer,\n    glyphBuffer,\n    idBuffer,\n    vao,\n    pickPerspectiveShader,\n    pickOrthoShader,\n    pickProjectShader)\n\n  pointCloud.update(options)\n\n  return pointCloud\n}\n\n},{\"./lib/get-simple-string\":294,\"./lib/glyphs\":295,\"./lib/shaders\":296,\"gl-buffer\":241,\"gl-mat4/multiply\":267,\"gl-vao\":327,\"is-string-blank\":423,\"typedarray-pool\":545}],298:[function(_dereq_,module,exports){\n'use strict'\n\nvar glslify = _dereq_('glslify')\n\nexports.boxVertex = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec2 vertex;\\n\\nuniform vec2 cornerA, cornerB;\\n\\nvoid main() {\\n  gl_Position = vec4(mix(cornerA, cornerB, vertex), 0, 1);\\n}\\n\"])\nexports.boxFragment = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nuniform vec4 color;\\n\\nvoid main() {\\n  gl_FragColor = color;\\n}\\n\"])\n\n},{\"glslify\":409}],299:[function(_dereq_,module,exports){\n'use strict'\n\nvar createShader = _dereq_('gl-shader')\nvar createBuffer = _dereq_('gl-buffer')\n\nvar SHADERS = _dereq_('./lib/shaders')\n\nmodule.exports = createSelectBox\n\nfunction SelectBox(plot, boxBuffer, boxShader) {\n  this.plot = plot\n  this.boxBuffer = boxBuffer\n  this.boxShader = boxShader\n\n  this.enabled = true\n\n  this.selectBox = [Infinity,Infinity,-Infinity,-Infinity]\n\n  this.borderColor = [0,0,0,1]\n  this.innerFill   = false\n  this.innerColor  = [0,0,0,0.25]\n  this.outerFill   = true\n  this.outerColor  = [0,0,0,0.5]\n  this.borderWidth = 10\n}\n\nvar proto = SelectBox.prototype\n\nproto.draw = function() {\n  if(!this.enabled) {\n    return\n  }\n\n  var plot         = this.plot\n  var selectBox    = this.selectBox\n  var lineWidth    = this.borderWidth\n\n  var innerFill    = this.innerFill\n  var innerColor   = this.innerColor\n  var outerFill    = this.outerFill\n  var outerColor   = this.outerColor\n  var borderColor  = this.borderColor\n\n  var boxes        = plot.box\n  var screenBox    = plot.screenBox\n  var dataBox      = plot.dataBox\n  var viewBox      = plot.viewBox\n  var pixelRatio   = plot.pixelRatio\n\n  //Map select box into pixel coordinates\n  var loX = (selectBox[0]-dataBox[0])*(viewBox[2]-viewBox[0])/(dataBox[2]-dataBox[0])+viewBox[0]\n  var loY = (selectBox[1]-dataBox[1])*(viewBox[3]-viewBox[1])/(dataBox[3]-dataBox[1])+viewBox[1]\n  var hiX = (selectBox[2]-dataBox[0])*(viewBox[2]-viewBox[0])/(dataBox[2]-dataBox[0])+viewBox[0]\n  var hiY = (selectBox[3]-dataBox[1])*(viewBox[3]-viewBox[1])/(dataBox[3]-dataBox[1])+viewBox[1]\n\n  loX = Math.max(loX, viewBox[0])\n  loY = Math.max(loY, viewBox[1])\n  hiX = Math.min(hiX, viewBox[2])\n  hiY = Math.min(hiY, viewBox[3])\n\n  if(hiX < loX || hiY < loY) {\n    return\n  }\n\n  boxes.bind()\n\n  //Draw box\n  var screenWidth  = screenBox[2] - screenBox[0]\n  var screenHeight = screenBox[3] - screenBox[1]\n\n  if(this.outerFill) {\n    boxes.drawBox(0, 0, screenWidth, loY, outerColor)\n    boxes.drawBox(0, loY, loX, hiY, outerColor)\n    boxes.drawBox(0, hiY, screenWidth, screenHeight, outerColor)\n    boxes.drawBox(hiX, loY, screenWidth, hiY, outerColor)\n  }\n\n  if(this.innerFill) {\n    boxes.drawBox(loX, loY, hiX, hiY, innerColor)\n  }\n\n  //Draw border\n  if(lineWidth > 0) {\n\n    //Draw border\n    var w = lineWidth * pixelRatio\n    boxes.drawBox(loX-w, loY-w, hiX+w, loY+w, borderColor)\n    boxes.drawBox(loX-w, hiY-w, hiX+w, hiY+w, borderColor)\n    boxes.drawBox(loX-w, loY-w, loX+w, hiY+w, borderColor)\n    boxes.drawBox(hiX-w, loY-w, hiX+w, hiY+w, borderColor)\n  }\n}\n\nproto.update = function(options) {\n  options = options || {}\n\n  this.innerFill    = !!options.innerFill\n  this.outerFill    = !!options.outerFill\n  this.innerColor   = (options.innerColor   || [0,0,0,0.5]).slice()\n  this.outerColor   = (options.outerColor   || [0,0,0,0.5]).slice()\n  this.borderColor  = (options.borderColor || [0,0,0,1]).slice()\n  this.borderWidth  = options.borderWidth || 0\n  this.selectBox    = (options.selectBox || this.selectBox).slice()\n}\n\nproto.dispose = function() {\n  this.boxBuffer.dispose()\n  this.boxShader.dispose()\n  this.plot.removeOverlay(this)\n}\n\nfunction createSelectBox(plot, options) {\n  var gl = plot.gl\n  var buffer = createBuffer(gl, [\n    0, 0,\n    0, 1,\n    1, 0,\n    1, 1 ])\n  var shader = createShader(gl, SHADERS.boxVertex, SHADERS.boxFragment)\n  var selectBox = new SelectBox(plot, buffer, shader)\n  selectBox.update(options)\n  plot.addOverlay(selectBox)\n  return selectBox\n}\n\n},{\"./lib/shaders\":298,\"gl-buffer\":241,\"gl-shader\":301}],300:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createSelectBuffer\n\nvar createFBO = _dereq_('gl-fbo')\nvar pool      = _dereq_('typedarray-pool')\nvar ndarray   = _dereq_('ndarray')\n\nvar nextPow2  = _dereq_('bit-twiddle').nextPow2\n\nvar selectRange = _dereq_('cwise/lib/wrapper')({\"args\":[\"array\",{\"offset\":[0,0,1],\"array\":0},{\"offset\":[0,0,2],\"array\":0},{\"offset\":[0,0,3],\"array\":0},\"scalar\",\"scalar\",\"index\"],\"pre\":{\"body\":\"{this_closestD2=1e8,this_closestX=-1,this_closestY=-1}\",\"args\":[],\"thisVars\":[\"this_closestD2\",\"this_closestX\",\"this_closestY\"],\"localVars\":[]},\"body\":{\"body\":\"{if(_inline_16_arg0_<255||_inline_16_arg1_<255||_inline_16_arg2_<255||_inline_16_arg3_<255){var _inline_16_l=_inline_16_arg4_-_inline_16_arg6_[0],_inline_16_a=_inline_16_arg5_-_inline_16_arg6_[1],_inline_16_f=_inline_16_l*_inline_16_l+_inline_16_a*_inline_16_a;_inline_16_f<this_closestD2&&(this_closestD2=_inline_16_f,this_closestX=_inline_16_arg6_[0],this_closestY=_inline_16_arg6_[1])}}\",\"args\":[{\"name\":\"_inline_16_arg0_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_16_arg1_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_16_arg2_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_16_arg3_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_16_arg4_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_16_arg5_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_16_arg6_\",\"lvalue\":false,\"rvalue\":true,\"count\":4}],\"thisVars\":[\"this_closestD2\",\"this_closestX\",\"this_closestY\"],\"localVars\":[\"_inline_16_a\",\"_inline_16_f\",\"_inline_16_l\"]},\"post\":{\"body\":\"{return[this_closestX,this_closestY,this_closestD2]}\",\"args\":[],\"thisVars\":[\"this_closestD2\",\"this_closestX\",\"this_closestY\"],\"localVars\":[]},\"debug\":false,\"funcName\":\"cwise\",\"blockSize\":64})\n\nfunction SelectResult(x, y, id, value, distance) {\n  this.coord = [x, y]\n  this.id = id\n  this.value = value\n  this.distance = distance\n}\n\nfunction SelectBuffer(gl, fbo, buffer) {\n  this.gl     = gl\n  this.fbo    = fbo\n  this.buffer = buffer\n  this._readTimeout = null\n  var self = this\n\n  this._readCallback = function() {\n    if(!self.gl) {\n      return\n    }\n    fbo.bind()\n    gl.readPixels(0,0,fbo.shape[0],fbo.shape[1],gl.RGBA,gl.UNSIGNED_BYTE,self.buffer)\n    self._readTimeout = null\n  }\n}\n\nvar proto = SelectBuffer.prototype\n\nObject.defineProperty(proto, 'shape', {\n  get: function() {\n    if(!this.gl) {\n      return [0,0]\n    }\n    return this.fbo.shape.slice()\n  },\n  set: function(v) {\n    if(!this.gl) {\n      return\n    }\n    this.fbo.shape = v\n    var c = this.fbo.shape[0]\n    var r = this.fbo.shape[1]\n    if(r*c*4 > this.buffer.length) {\n      pool.free(this.buffer)\n      var buffer = this.buffer = pool.mallocUint8(nextPow2(r*c*4))\n      for(var i=0; i<r*c*4; ++i) {\n        buffer[i] = 0xff\n      }\n    }\n    return v\n  }\n})\n\nproto.begin = function() {\n  var gl = this.gl\n  var shape = this.shape\n  if(!gl) {\n    return\n  }\n\n  this.fbo.bind()\n  gl.clearColor(1,1,1,1)\n  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)\n}\n\nproto.end = function() {\n  var gl = this.gl\n  if(!gl) {\n    return\n  }\n  gl.bindFramebuffer(gl.FRAMEBUFFER, null)\n  if(!this._readTimeout) {\n    clearTimeout(this._readTimeout)\n  }\n  this._readTimeout = setTimeout(this._readCallback, 1)\n}\n\nproto.query = function(x, y, radius) {\n  if(!this.gl) {\n    return null\n  }\n\n  var shape = this.fbo.shape.slice()\n\n  x = x|0\n  y = y|0\n  if(typeof radius !== 'number') {\n    radius = 1.0\n  }\n\n  var x0 = Math.min(Math.max(x - radius, 0), shape[0])|0\n  var x1 = Math.min(Math.max(x + radius, 0), shape[0])|0\n  var y0 = Math.min(Math.max(y - radius, 0), shape[1])|0\n  var y1 = Math.min(Math.max(y + radius, 0), shape[1])|0\n\n  if(x1 <= x0 || y1 <= y0) {\n    return null\n  }\n\n  var dims   = [x1-x0,y1-y0]\n  var region = ndarray(\n    this.buffer,\n    [dims[0], dims[1], 4],\n    [4, shape[0]*4, 1],\n    4*(x0 + shape[0]*y0));\n\n  var closest = selectRange(region.hi(dims[0],dims[1],1), radius, radius)\n  var dx = closest[0]\n  var dy = closest[1]\n  if(dx < 0 || Math.pow(this.radius, 2) < closest[2]) {\n    return null\n  }\n\n  var c0 = region.get(dx, dy, 0)\n  var c1 = region.get(dx, dy, 1)\n  var c2 = region.get(dx, dy, 2)\n  var c3 = region.get(dx, dy, 3)\n\n  return new SelectResult(\n     (dx + x0)|0,\n     (dy + y0)|0,\n     c0,\n     [c1, c2, c3],\n     Math.sqrt(closest[2]))\n}\n\nproto.dispose = function() {\n  if(!this.gl) {\n    return\n  }\n  this.fbo.dispose()\n  pool.free(this.buffer)\n  this.gl = null\n  if(this._readTimeout) {\n    clearTimeout(this._readTimeout)\n  }\n}\n\nfunction createSelectBuffer(gl, shape) {\n  var fbo = createFBO(gl, shape)\n  var buffer = pool.mallocUint8(shape[0]*shape[1]*4)\n  return new SelectBuffer(gl, fbo, buffer)\n}\n\n},{\"bit-twiddle\":92,\"cwise/lib/wrapper\":149,\"gl-fbo\":249,\"ndarray\":450,\"typedarray-pool\":545}],301:[function(_dereq_,module,exports){\n'use strict'\n\nvar createUniformWrapper   = _dereq_('./lib/create-uniforms')\nvar createAttributeWrapper = _dereq_('./lib/create-attributes')\nvar makeReflect            = _dereq_('./lib/reflect')\nvar shaderCache            = _dereq_('./lib/shader-cache')\nvar runtime                = _dereq_('./lib/runtime-reflect')\nvar GLError                = _dereq_(\"./lib/GLError\")\n\n//Shader object\nfunction Shader(gl) {\n  this.gl         = gl\n  this.gl.lastAttribCount = 0  // fixme where else should we store info, safe but not nice on the gl object\n\n  //Default initialize these to null\n  this._vref      =\n  this._fref      =\n  this._relink    =\n  this.vertShader =\n  this.fragShader =\n  this.program    =\n  this.attributes =\n  this.uniforms   =\n  this.types      = null\n}\n\nvar proto = Shader.prototype\n\nproto.bind = function() {\n  if(!this.program) {\n    this._relink()\n  }\n\n  // ensuring that we have the right number of enabled vertex attributes\n  var i\n  var newAttribCount = this.gl.getProgramParameter(this.program, this.gl.ACTIVE_ATTRIBUTES) // more robust approach\n  //var newAttribCount = Object.keys(this.attributes).length // avoids the probably immaterial introspection slowdown\n  var oldAttribCount = this.gl.lastAttribCount\n  if(newAttribCount > oldAttribCount) {\n    for(i = oldAttribCount; i < newAttribCount; i++) {\n      this.gl.enableVertexAttribArray(i)\n    }\n  } else if(oldAttribCount > newAttribCount) {\n    for(i = newAttribCount; i < oldAttribCount; i++) {\n      this.gl.disableVertexAttribArray(i)\n    }\n  }\n\n  this.gl.lastAttribCount = newAttribCount\n\n  this.gl.useProgram(this.program)\n}\n\nproto.dispose = function() {\n\n  // disabling vertex attributes so new shader starts with zero\n  // and it's also useful if all shaders are disposed but the\n  // gl context is reused for subsequent replotting\n  var oldAttribCount = this.gl.lastAttribCount\n  for (var i = 0; i < oldAttribCount; i++) {\n    this.gl.disableVertexAttribArray(i)\n  }\n  this.gl.lastAttribCount = 0\n\n  if(this._fref) {\n    this._fref.dispose()\n  }\n  if(this._vref) {\n    this._vref.dispose()\n  }\n  this.attributes =\n  this.types      =\n  this.vertShader =\n  this.fragShader =\n  this.program    =\n  this._relink    =\n  this._fref      =\n  this._vref      = null\n}\n\nfunction compareAttributes(a, b) {\n  if(a.name < b.name) {\n    return -1\n  }\n  return 1\n}\n\n//Update export hook for glslify-live\nproto.update = function(\n    vertSource\n  , fragSource\n  , uniforms\n  , attributes) {\n\n  //If only one object passed, assume glslify style output\n  if(!fragSource || arguments.length === 1) {\n    var obj = vertSource\n    vertSource = obj.vertex\n    fragSource = obj.fragment\n    uniforms   = obj.uniforms\n    attributes = obj.attributes\n  }\n\n  var wrapper = this\n  var gl      = wrapper.gl\n\n  //Compile vertex and fragment shaders\n  var pvref = wrapper._vref\n  wrapper._vref = shaderCache.shader(gl, gl.VERTEX_SHADER, vertSource)\n  if(pvref) {\n    pvref.dispose()\n  }\n  wrapper.vertShader = wrapper._vref.shader\n  var pfref = this._fref\n  wrapper._fref = shaderCache.shader(gl, gl.FRAGMENT_SHADER, fragSource)\n  if(pfref) {\n    pfref.dispose()\n  }\n  wrapper.fragShader = wrapper._fref.shader\n\n  //If uniforms/attributes is not specified, use RT reflection\n  if(!uniforms || !attributes) {\n\n    //Create initial test program\n    var testProgram = gl.createProgram()\n    gl.attachShader(testProgram, wrapper.fragShader)\n    gl.attachShader(testProgram, wrapper.vertShader)\n    gl.linkProgram(testProgram)\n    if(!gl.getProgramParameter(testProgram, gl.LINK_STATUS)) {\n      var errLog = gl.getProgramInfoLog(testProgram)\n      throw new GLError(errLog, 'Error linking program:' + errLog)\n    }\n\n    //Load data from runtime\n    uniforms   = uniforms   || runtime.uniforms(gl, testProgram)\n    attributes = attributes || runtime.attributes(gl, testProgram)\n\n    //Release test program\n    gl.deleteProgram(testProgram)\n  }\n\n  //Sort attributes lexicographically\n  // overrides undefined WebGL behavior for attribute locations\n  attributes = attributes.slice()\n  attributes.sort(compareAttributes)\n\n  //Convert attribute types, read out locations\n  var attributeUnpacked  = []\n  var attributeNames     = []\n  var attributeLocations = []\n  var i\n  for(i=0; i<attributes.length; ++i) {\n    var attr = attributes[i]\n    if(attr.type.indexOf('mat') >= 0) {\n      var size = attr.type.charAt(attr.type.length-1)|0\n      var locVector = new Array(size)\n      for(var j=0; j<size; ++j) {\n        locVector[j] = attributeLocations.length\n        attributeNames.push(attr.name + '[' + j + ']')\n        if(typeof attr.location === 'number') {\n          attributeLocations.push(attr.location + j)\n        } else if(Array.isArray(attr.location) &&\n                  attr.location.length === size &&\n                  typeof attr.location[j] === 'number') {\n          attributeLocations.push(attr.location[j]|0)\n        } else {\n          attributeLocations.push(-1)\n        }\n      }\n      attributeUnpacked.push({\n        name: attr.name,\n        type: attr.type,\n        locations: locVector\n      })\n    } else {\n      attributeUnpacked.push({\n        name: attr.name,\n        type: attr.type,\n        locations: [ attributeLocations.length ]\n      })\n      attributeNames.push(attr.name)\n      if(typeof attr.location === 'number') {\n        attributeLocations.push(attr.location|0)\n      } else {\n        attributeLocations.push(-1)\n      }\n    }\n  }\n\n  //For all unspecified attributes, assign them lexicographically min attribute\n  var curLocation = 0\n  for(i=0; i<attributeLocations.length; ++i) {\n    if(attributeLocations[i] < 0) {\n      while(attributeLocations.indexOf(curLocation) >= 0) {\n        curLocation += 1\n      }\n      attributeLocations[i] = curLocation\n    }\n  }\n\n  //Rebuild program and recompute all uniform locations\n  var uniformLocations = new Array(uniforms.length)\n  function relink() {\n    wrapper.program = shaderCache.program(\n        gl\n      , wrapper._vref\n      , wrapper._fref\n      , attributeNames\n      , attributeLocations)\n\n    for(var i=0; i<uniforms.length; ++i) {\n      uniformLocations[i] = gl.getUniformLocation(\n          wrapper.program\n        , uniforms[i].name)\n    }\n  }\n\n  //Perform initial linking, reuse program used for reflection\n  relink()\n\n  //Save relinking procedure, defer until runtime\n  wrapper._relink = relink\n\n  //Generate type info\n  wrapper.types = {\n    uniforms:   makeReflect(uniforms),\n    attributes: makeReflect(attributes)\n  }\n\n  //Generate attribute wrappers\n  wrapper.attributes = createAttributeWrapper(\n      gl\n    , wrapper\n    , attributeUnpacked\n    , attributeLocations)\n\n  //Generate uniform wrappers\n  Object.defineProperty(wrapper, 'uniforms', createUniformWrapper(\n      gl\n    , wrapper\n    , uniforms\n    , uniformLocations))\n}\n\n//Compiles and links a shader program with the given attribute and vertex list\nfunction createShader(\n    gl\n  , vertSource\n  , fragSource\n  , uniforms\n  , attributes) {\n\n  var shader = new Shader(gl)\n\n  shader.update(\n      vertSource\n    , fragSource\n    , uniforms\n    , attributes)\n\n  return shader\n}\n\nmodule.exports = createShader\n\n},{\"./lib/GLError\":302,\"./lib/create-attributes\":303,\"./lib/create-uniforms\":304,\"./lib/reflect\":305,\"./lib/runtime-reflect\":306,\"./lib/shader-cache\":307}],302:[function(_dereq_,module,exports){\nfunction GLError (rawError, shortMessage, longMessage) {\n    this.shortMessage = shortMessage || ''\n    this.longMessage = longMessage || ''\n    this.rawError = rawError || ''\n    this.message =\n      'gl-shader: ' + (shortMessage || rawError || '') +\n      (longMessage ? '\\n'+longMessage : '')\n    this.stack = (new Error()).stack\n}\nGLError.prototype = new Error\nGLError.prototype.name = 'GLError'\nGLError.prototype.constructor = GLError\nmodule.exports = GLError\n\n},{}],303:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createAttributeWrapper\n\nvar GLError = _dereq_(\"./GLError\")\n\nfunction ShaderAttribute(\n    gl\n  , wrapper\n  , index\n  , locations\n  , dimension\n  , constFunc) {\n  this._gl        = gl\n  this._wrapper   = wrapper\n  this._index     = index\n  this._locations = locations\n  this._dimension = dimension\n  this._constFunc = constFunc\n}\n\nvar proto = ShaderAttribute.prototype\n\nproto.pointer = function setAttribPointer(\n    type\n  , normalized\n  , stride\n  , offset) {\n\n  var self      = this\n  var gl        = self._gl\n  var location  = self._locations[self._index]\n\n  gl.vertexAttribPointer(\n      location\n    , self._dimension\n    , type || gl.FLOAT\n    , !!normalized\n    , stride || 0\n    , offset || 0)\n  gl.enableVertexAttribArray(location)\n}\n\nproto.set = function(x0, x1, x2, x3) {\n  return this._constFunc(this._locations[this._index], x0, x1, x2, x3)\n}\n\nObject.defineProperty(proto, 'location', {\n  get: function() {\n    return this._locations[this._index]\n  }\n  , set: function(v) {\n    if(v !== this._locations[this._index]) {\n      this._locations[this._index] = v|0\n      this._wrapper.program = null\n    }\n    return v|0\n  }\n})\n\n//Adds a vector attribute to obj\nfunction addVectorAttribute(\n    gl\n  , wrapper\n  , index\n  , locations\n  , dimension\n  , obj\n  , name) {\n\n  //Construct constant function\n  var constFuncArgs = [ 'gl', 'v' ]\n  var varNames = []\n  for(var i=0; i<dimension; ++i) {\n    constFuncArgs.push('x'+i)\n    varNames.push('x'+i)\n  }\n  constFuncArgs.push(\n    'if(x0.length===void 0){return gl.vertexAttrib' +\n    dimension + 'f(v,' +\n    varNames.join() +\n    ')}else{return gl.vertexAttrib' +\n    dimension +\n    'fv(v,x0)}')\n  var constFunc = Function.apply(null, constFuncArgs)\n\n  //Create attribute wrapper\n  var attr = new ShaderAttribute(\n      gl\n    , wrapper\n    , index\n    , locations\n    , dimension\n    , constFunc)\n\n  //Create accessor\n  Object.defineProperty(obj, name, {\n    set: function(x) {\n      gl.disableVertexAttribArray(locations[index])\n      constFunc(gl, locations[index], x)\n      return x\n    }\n    , get: function() {\n      return attr\n    }\n    , enumerable: true\n  })\n}\n\nfunction addMatrixAttribute(\n    gl\n  , wrapper\n  , index\n  , locations\n  , dimension\n  , obj\n  , name) {\n\n  var parts = new Array(dimension)\n  var attrs = new Array(dimension)\n  for(var i=0; i<dimension; ++i) {\n    addVectorAttribute(\n        gl\n      , wrapper\n      , index[i]\n      , locations\n      , dimension\n      , parts\n      , i)\n    attrs[i] = parts[i]\n  }\n\n  Object.defineProperty(parts, 'location', {\n    set: function(v) {\n      if(Array.isArray(v)) {\n        for(var i=0; i<dimension; ++i) {\n          attrs[i].location = v[i]\n        }\n      } else {\n        for(var i=0; i<dimension; ++i) {\n          attrs[i].location = v + i\n        }\n      }\n      return v\n    }\n    , get: function() {\n      var result = new Array(dimension)\n      for(var i=0; i<dimension; ++i) {\n        result[i] = locations[index[i]]\n      }\n      return result\n    }\n    , enumerable: true\n  })\n\n  parts.pointer = function(type, normalized, stride, offset) {\n    type       = type || gl.FLOAT\n    normalized = !!normalized\n    stride     = stride || (dimension * dimension)\n    offset     = offset || 0\n    for(var i=0; i<dimension; ++i) {\n      var location = locations[index[i]]\n      gl.vertexAttribPointer(\n            location\n          , dimension\n          , type\n          , normalized\n          , stride\n          , offset + i * dimension)\n      gl.enableVertexAttribArray(location)\n    }\n  }\n\n  var scratch = new Array(dimension)\n  var vertexAttrib = gl['vertexAttrib' + dimension + 'fv']\n\n  Object.defineProperty(obj, name, {\n    set: function(x) {\n      for(var i=0; i<dimension; ++i) {\n        var loc = locations[index[i]]\n        gl.disableVertexAttribArray(loc)\n        if(Array.isArray(x[0])) {\n          vertexAttrib.call(gl, loc, x[i])\n        } else {\n          for(var j=0; j<dimension; ++j) {\n            scratch[j] = x[dimension*i + j]\n          }\n          vertexAttrib.call(gl, loc, scratch)\n        }\n      }\n      return x\n    }\n    , get: function() {\n      return parts\n    }\n    , enumerable: true\n  })\n}\n\n//Create shims for attributes\nfunction createAttributeWrapper(\n    gl\n  , wrapper\n  , attributes\n  , locations) {\n\n  var obj = {}\n  for(var i=0, n=attributes.length; i<n; ++i) {\n\n    var a = attributes[i]\n    var name = a.name\n    var type = a.type\n    var locs = a.locations\n\n    switch(type) {\n      case 'bool':\n      case 'int':\n      case 'float':\n        addVectorAttribute(\n            gl\n          , wrapper\n          , locs[0]\n          , locations\n          , 1\n          , obj\n          , name)\n      break\n\n      default:\n        if(type.indexOf('vec') >= 0) {\n          var d = type.charCodeAt(type.length-1) - 48\n          if(d < 2 || d > 4) {\n            throw new GLError('', 'Invalid data type for attribute ' + name + ': ' + type)\n          }\n          addVectorAttribute(\n              gl\n            , wrapper\n            , locs[0]\n            , locations\n            , d\n            , obj\n            , name)\n        } else if(type.indexOf('mat') >= 0) {\n          var d = type.charCodeAt(type.length-1) - 48\n          if(d < 2 || d > 4) {\n            throw new GLError('', 'Invalid data type for attribute ' + name + ': ' + type)\n          }\n          addMatrixAttribute(\n              gl\n            , wrapper\n            , locs\n            , locations\n            , d\n            , obj\n            , name)\n        } else {\n          throw new GLError('', 'Unknown data type for attribute ' + name + ': ' + type)\n        }\n      break\n    }\n  }\n  return obj\n}\n\n},{\"./GLError\":302}],304:[function(_dereq_,module,exports){\n'use strict'\n\nvar coallesceUniforms = _dereq_('./reflect')\nvar GLError = _dereq_(\"./GLError\")\n\nmodule.exports = createUniformWrapper\n\n//Binds a function and returns a value\nfunction identity(x) {\n  var c = new Function('y', 'return function(){return y}')\n  return c(x)\n}\n\nfunction makeVector(length, fill) {\n  var result = new Array(length)\n  for(var i=0; i<length; ++i) {\n    result[i] = fill\n  }\n  return result\n}\n\n//Create shims for uniforms\nfunction createUniformWrapper(gl, wrapper, uniforms, locations) {\n\n  function makeGetter(index) {\n    var proc = new Function(\n        'gl'\n      , 'wrapper'\n      , 'locations'\n      , 'return function(){return gl.getUniform(wrapper.program,locations[' + index + '])}')\n    return proc(gl, wrapper, locations)\n  }\n\n  function makePropSetter(path, index, type) {\n    switch(type) {\n      case 'bool':\n      case 'int':\n      case 'sampler2D':\n      case 'samplerCube':\n        return 'gl.uniform1i(locations[' + index + '],obj' + path + ')'\n      case 'float':\n        return 'gl.uniform1f(locations[' + index + '],obj' + path + ')'\n      default:\n        var vidx = type.indexOf('vec')\n        if(0 <= vidx && vidx <= 1 && type.length === 4 + vidx) {\n          var d = type.charCodeAt(type.length-1) - 48\n          if(d < 2 || d > 4) {\n            throw new GLError('', 'Invalid data type')\n          }\n          switch(type.charAt(0)) {\n            case 'b':\n            case 'i':\n              return 'gl.uniform' + d + 'iv(locations[' + index + '],obj' + path + ')'\n            case 'v':\n              return 'gl.uniform' + d + 'fv(locations[' + index + '],obj' + path + ')'\n            default:\n              throw new GLError('', 'Unrecognized data type for vector ' + name + ': ' + type)\n          }\n        } else if(type.indexOf('mat') === 0 && type.length === 4) {\n          var d = type.charCodeAt(type.length-1) - 48\n          if(d < 2 || d > 4) {\n            throw new GLError('', 'Invalid uniform dimension type for matrix ' + name + ': ' + type)\n          }\n          return 'gl.uniformMatrix' + d + 'fv(locations[' + index + '],false,obj' + path + ')'\n        } else {\n          throw new GLError('', 'Unknown uniform data type for ' + name + ': ' + type)\n        }\n      break\n    }\n  }\n\n  function enumerateIndices(prefix, type) {\n    if(typeof type !== 'object') {\n      return [ [prefix, type] ]\n    }\n    var indices = []\n    for(var id in type) {\n      var prop = type[id]\n      var tprefix = prefix\n      if(parseInt(id) + '' === id) {\n        tprefix += '[' + id + ']'\n      } else {\n        tprefix += '.' + id\n      }\n      if(typeof prop === 'object') {\n        indices.push.apply(indices, enumerateIndices(tprefix, prop))\n      } else {\n        indices.push([tprefix, prop])\n      }\n    }\n    return indices\n  }\n\n  function makeSetter(type) {\n    var code = [ 'return function updateProperty(obj){' ]\n    var indices = enumerateIndices('', type)\n    for(var i=0; i<indices.length; ++i) {\n      var item = indices[i]\n      var path = item[0]\n      var idx  = item[1]\n      if(locations[idx]) {\n        code.push(makePropSetter(path, idx, uniforms[idx].type))\n      }\n    }\n    code.push('return obj}')\n    var proc = new Function('gl', 'locations', code.join('\\n'))\n    return proc(gl, locations)\n  }\n\n  function defaultValue(type) {\n    switch(type) {\n      case 'bool':\n        return false\n      case 'int':\n      case 'sampler2D':\n      case 'samplerCube':\n        return 0\n      case 'float':\n        return 0.0\n      default:\n        var vidx = type.indexOf('vec')\n        if(0 <= vidx && vidx <= 1 && type.length === 4 + vidx) {\n          var d = type.charCodeAt(type.length-1) - 48\n          if(d < 2 || d > 4) {\n            throw new GLError('', 'Invalid data type')\n          }\n          if(type.charAt(0) === 'b') {\n            return makeVector(d, false)\n          }\n          return makeVector(d, 0)\n        } else if(type.indexOf('mat') === 0 && type.length === 4) {\n          var d = type.charCodeAt(type.length-1) - 48\n          if(d < 2 || d > 4) {\n            throw new GLError('', 'Invalid uniform dimension type for matrix ' + name + ': ' + type)\n          }\n          return makeVector(d*d, 0)\n        } else {\n          throw new GLError('', 'Unknown uniform data type for ' + name + ': ' + type)\n        }\n      break\n    }\n  }\n\n  function storeProperty(obj, prop, type) {\n    if(typeof type === 'object') {\n      var child = processObject(type)\n      Object.defineProperty(obj, prop, {\n        get: identity(child),\n        set: makeSetter(type),\n        enumerable: true,\n        configurable: false\n      })\n    } else {\n      if(locations[type]) {\n        Object.defineProperty(obj, prop, {\n          get: makeGetter(type),\n          set: makeSetter(type),\n          enumerable: true,\n          configurable: false\n        })\n      } else {\n        obj[prop] = defaultValue(uniforms[type].type)\n      }\n    }\n  }\n\n  function processObject(obj) {\n    var result\n    if(Array.isArray(obj)) {\n      result = new Array(obj.length)\n      for(var i=0; i<obj.length; ++i) {\n        storeProperty(result, i, obj[i])\n      }\n    } else {\n      result = {}\n      for(var id in obj) {\n        storeProperty(result, id, obj[id])\n      }\n    }\n    return result\n  }\n\n  //Return data\n  var coallesced = coallesceUniforms(uniforms, true)\n  return {\n    get: identity(processObject(coallesced)),\n    set: makeSetter(coallesced),\n    enumerable: true,\n    configurable: true\n  }\n}\n\n},{\"./GLError\":302,\"./reflect\":305}],305:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = makeReflectTypes\n\n//Construct type info for reflection.\n//\n// This iterates over the flattened list of uniform type values and smashes them into a JSON object.\n//\n// The leaves of the resulting object are either indices or type strings representing primitive glslify types\nfunction makeReflectTypes(uniforms, useIndex) {\n  var obj = {}\n  for(var i=0; i<uniforms.length; ++i) {\n    var n = uniforms[i].name\n    var parts = n.split(\".\")\n    var o = obj\n    for(var j=0; j<parts.length; ++j) {\n      var x = parts[j].split(\"[\")\n      if(x.length > 1) {\n        if(!(x[0] in o)) {\n          o[x[0]] = []\n        }\n        o = o[x[0]]\n        for(var k=1; k<x.length; ++k) {\n          var y = parseInt(x[k])\n          if(k<x.length-1 || j<parts.length-1) {\n            if(!(y in o)) {\n              if(k < x.length-1) {\n                o[y] = []\n              } else {\n                o[y] = {}\n              }\n            }\n            o = o[y]\n          } else {\n            if(useIndex) {\n              o[y] = i\n            } else {\n              o[y] = uniforms[i].type\n            }\n          }\n        }\n      } else if(j < parts.length-1) {\n        if(!(x[0] in o)) {\n          o[x[0]] = {}\n        }\n        o = o[x[0]]\n      } else {\n        if(useIndex) {\n          o[x[0]] = i\n        } else {\n          o[x[0]] = uniforms[i].type\n        }\n      }\n    }\n  }\n  return obj\n}\n},{}],306:[function(_dereq_,module,exports){\n'use strict'\n\nexports.uniforms    = runtimeUniforms\nexports.attributes  = runtimeAttributes\n\nvar GL_TO_GLSL_TYPES = {\n  'FLOAT':       'float',\n  'FLOAT_VEC2':  'vec2',\n  'FLOAT_VEC3':  'vec3',\n  'FLOAT_VEC4':  'vec4',\n  'INT':         'int',\n  'INT_VEC2':    'ivec2',\n  'INT_VEC3':    'ivec3',\n  'INT_VEC4':    'ivec4',\n  'BOOL':        'bool',\n  'BOOL_VEC2':   'bvec2',\n  'BOOL_VEC3':   'bvec3',\n  'BOOL_VEC4':   'bvec4',\n  'FLOAT_MAT2':  'mat2',\n  'FLOAT_MAT3':  'mat3',\n  'FLOAT_MAT4':  'mat4',\n  'SAMPLER_2D':  'sampler2D',\n  'SAMPLER_CUBE':'samplerCube'\n}\n\nvar GL_TABLE = null\n\nfunction getType(gl, type) {\n  if(!GL_TABLE) {\n    var typeNames = Object.keys(GL_TO_GLSL_TYPES)\n    GL_TABLE = {}\n    for(var i=0; i<typeNames.length; ++i) {\n      var tn = typeNames[i]\n      GL_TABLE[gl[tn]] = GL_TO_GLSL_TYPES[tn]\n    }\n  }\n  return GL_TABLE[type]\n}\n\nfunction runtimeUniforms(gl, program) {\n  var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS)\n  var result = []\n  for(var i=0; i<numUniforms; ++i) {\n    var info = gl.getActiveUniform(program, i)\n    if(info) {\n      var type = getType(gl, info.type)\n      if(info.size > 1) {\n        for(var j=0; j<info.size; ++j) {\n          result.push({\n            name: info.name.replace('[0]', '[' + j + ']'),\n            type: type\n          })\n        }\n      } else {\n        result.push({\n          name: info.name,\n          type: type\n        })\n      }\n    }\n  }\n  return result\n}\n\nfunction runtimeAttributes(gl, program) {\n  var numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES)\n  var result = []\n  for(var i=0; i<numAttributes; ++i) {\n    var info = gl.getActiveAttrib(program, i)\n    if(info) {\n      result.push({\n        name: info.name,\n        type: getType(gl, info.type)\n      })\n    }\n  }\n  return result\n}\n\n},{}],307:[function(_dereq_,module,exports){\n'use strict'\n\nexports.shader   = getShaderReference\nexports.program  = createProgram\n\nvar GLError = _dereq_(\"./GLError\")\nvar formatCompilerError = _dereq_('gl-format-compiler-error');\n\nvar weakMap = typeof WeakMap === 'undefined' ? _dereq_('weakmap-shim') : WeakMap\nvar CACHE = new weakMap()\n\nvar SHADER_COUNTER = 0\n\nfunction ShaderReference(id, src, type, shader, programs, count, cache) {\n  this.id       = id\n  this.src      = src\n  this.type     = type\n  this.shader   = shader\n  this.count    = count\n  this.programs = []\n  this.cache    = cache\n}\n\nShaderReference.prototype.dispose = function() {\n  if(--this.count === 0) {\n    var cache    = this.cache\n    var gl       = cache.gl\n\n    //Remove program references\n    var programs = this.programs\n    for(var i=0, n=programs.length; i<n; ++i) {\n      var p = cache.programs[programs[i]]\n      if(p) {\n        delete cache.programs[i]\n        gl.deleteProgram(p)\n      }\n    }\n\n    //Remove shader reference\n    gl.deleteShader(this.shader)\n    delete cache.shaders[(this.type === gl.FRAGMENT_SHADER)|0][this.src]\n  }\n}\n\nfunction ContextCache(gl) {\n  this.gl       = gl\n  this.shaders  = [{}, {}]\n  this.programs = {}\n}\n\nvar proto = ContextCache.prototype\n\nfunction compileShader(gl, type, src) {\n  var shader = gl.createShader(type)\n  gl.shaderSource(shader, src)\n  gl.compileShader(shader)\n  if(!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n    var errLog = gl.getShaderInfoLog(shader)\n    try {\n        var fmt = formatCompilerError(errLog, src, type);\n    } catch (e){\n        console.warn('Failed to format compiler error: ' + e);\n        throw new GLError(errLog, 'Error compiling shader:\\n' + errLog)\n    }\n    throw new GLError(errLog, fmt.short, fmt.long)\n  }\n  return shader\n}\n\nproto.getShaderReference = function(type, src) {\n  var gl      = this.gl\n  var shaders = this.shaders[(type === gl.FRAGMENT_SHADER)|0]\n  var shader  = shaders[src]\n  if(!shader || !gl.isShader(shader.shader)) {\n    var shaderObj = compileShader(gl, type, src)\n    shader = shaders[src] = new ShaderReference(\n      SHADER_COUNTER++,\n      src,\n      type,\n      shaderObj,\n      [],\n      1,\n      this)\n  } else {\n    shader.count += 1\n  }\n  return shader\n}\n\nfunction linkProgram(gl, vshader, fshader, attribs, locations) {\n  var program = gl.createProgram()\n  gl.attachShader(program, vshader)\n  gl.attachShader(program, fshader)\n  for(var i=0; i<attribs.length; ++i) {\n    gl.bindAttribLocation(program, locations[i], attribs[i])\n  }\n  gl.linkProgram(program)\n  if(!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n    var errLog = gl.getProgramInfoLog(program)\n    throw new GLError(errLog, 'Error linking program: ' + errLog)\n  }\n  return program\n}\n\nproto.getProgram = function(vref, fref, attribs, locations) {\n  var token = [vref.id, fref.id, attribs.join(':'), locations.join(':')].join('@')\n  var prog  = this.programs[token]\n  if(!prog || !this.gl.isProgram(prog)) {\n    this.programs[token] = prog = linkProgram(\n      this.gl,\n      vref.shader,\n      fref.shader,\n      attribs,\n      locations)\n    vref.programs.push(token)\n    fref.programs.push(token)\n  }\n  return prog\n}\n\nfunction getCache(gl) {\n  var ctxCache = CACHE.get(gl)\n  if(!ctxCache) {\n    ctxCache = new ContextCache(gl)\n    CACHE.set(gl, ctxCache)\n  }\n  return ctxCache\n}\n\nfunction getShaderReference(gl, type, src) {\n  return getCache(gl).getShaderReference(type, src)\n}\n\nfunction createProgram(gl, vref, fref, attribs, locations) {\n  return getCache(gl).getProgram(vref, fref, attribs, locations)\n}\n\n},{\"./GLError\":302,\"gl-format-compiler-error\":250,\"weakmap-shim\":555}],308:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createSpikes2D\n\nfunction GLSpikes2D(plot) {\n  this.plot = plot\n  this.enable = [true, true, false, false]\n  this.width  = [1, 1, 1, 1]\n  this.color  = [[0,0,0,1],\n                 [0,0,0,1],\n                 [0,0,0,1],\n                 [0,0,0,1]]\n  this.center = [Infinity, Infinity]\n}\n\nvar proto = GLSpikes2D.prototype\n\nproto.update = function(options) {\n  options = options || {}\n  this.enable = (options.enable || [true,true,false,false]).slice()\n  this.width  = (options.width || [1,1,1,1]).slice()\n  this.color  = (options.color || [\n                  [0,0,0,1],\n                  [0,0,0,1],\n                  [0,0,0,1],\n                  [0,0,0,1]]).map(function(x) { return x.slice() })\n  this.center = (options.center || [Infinity,Infinity]).slice()\n  this.plot.setOverlayDirty()\n}\n\nproto.draw = function() {\n  var spikeEnable = this.enable\n  var spikeWidth  = this.width\n  var spikeColor  = this.color\n  var spikeCenter = this.center\n  var plot        = this.plot\n  var line        = plot.line\n\n  var dataBox     = plot.dataBox\n  var viewPixels  = plot.viewBox\n\n  line.bind()\n\n  if(dataBox[0] <= spikeCenter[0] && spikeCenter[0] <= dataBox[2] &&\n     dataBox[1] <= spikeCenter[1] && spikeCenter[1] <= dataBox[3]) {\n\n    var centerX = viewPixels[0] + (spikeCenter[0] - dataBox[0]) / (dataBox[2] - dataBox[0]) * (viewPixels[2] - viewPixels[0])\n    var centerY = viewPixels[1] + (spikeCenter[1] - dataBox[1]) / (dataBox[3] - dataBox[1]) * (viewPixels[3] - viewPixels[1])\n\n    if(spikeEnable[0]) {\n     line.drawLine(\n       centerX, centerY,\n       viewPixels[0], centerY,\n       spikeWidth[0], spikeColor[0])\n    }\n    if(spikeEnable[1]) {\n     line.drawLine(\n       centerX, centerY,\n       centerX, viewPixels[1],\n       spikeWidth[1], spikeColor[1])\n    }\n    if(spikeEnable[2]) {\n      line.drawLine(\n        centerX, centerY,\n        viewPixels[2], centerY,\n        spikeWidth[2], spikeColor[2])\n    }\n    if(spikeEnable[3]) {\n      line.drawLine(\n        centerX, centerY,\n        centerX, viewPixels[3],\n        spikeWidth[3], spikeColor[3])\n    }\n  }\n}\n\nproto.dispose = function() {\n  this.plot.removeOverlay(this)\n}\n\nfunction createSpikes2D(plot, options) {\n  var spikes = new GLSpikes2D(plot)\n  spikes.update(options)\n  plot.addOverlay(spikes)\n  return spikes\n}\n\n},{}],309:[function(_dereq_,module,exports){\n'use strict'\n\nvar glslify      = _dereq_('glslify')\nvar createShader = _dereq_('gl-shader')\n\nvar vertSrc = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nattribute vec3 position, color;\\nattribute float weight;\\n\\nuniform mat4 model, view, projection;\\nuniform vec3 coordinates[3];\\nuniform vec4 colors[3];\\nuniform vec2 screenShape;\\nuniform float lineWidth;\\n\\nvarying vec4 fragColor;\\n\\nvoid main() {\\n  vec3 vertexPosition = mix(coordinates[0],\\n    mix(coordinates[2], coordinates[1], 0.5 * (position + 1.0)), abs(position));\\n\\n  vec4 clipPos = projection * view * model * vec4(vertexPosition, 1.0);\\n  vec2 clipOffset = (projection * view * model * vec4(color, 0.0)).xy;\\n  vec2 delta = weight * clipOffset * screenShape;\\n  vec2 lineOffset = normalize(vec2(delta.y, -delta.x)) / screenShape;\\n\\n  gl_Position   = vec4(clipPos.xy + clipPos.w * 0.5 * lineWidth * lineOffset, clipPos.z, clipPos.w);\\n  fragColor     = color.x * colors[0] + color.y * colors[1] + color.z * colors[2];\\n}\\n\"])\nvar fragSrc = glslify([\"precision mediump float;\\n#define GLSLIFY 1\\n\\nvarying vec4 fragColor;\\n\\nvoid main() {\\n  gl_FragColor = fragColor;\\n}\"])\n\nmodule.exports = function(gl) {\n  return createShader(gl, vertSrc, fragSrc, null, [\n    {name: 'position', type: 'vec3'},\n    {name: 'color', type: 'vec3'},\n    {name: 'weight', type: 'float'}\n  ])\n}\n\n},{\"gl-shader\":301,\"glslify\":409}],310:[function(_dereq_,module,exports){\n'use strict'\n\nvar createBuffer = _dereq_('gl-buffer')\nvar createVAO = _dereq_('gl-vao')\nvar createShader = _dereq_('./shaders/index')\n\nmodule.exports = createSpikes\n\nvar identity = [1,0,0,0,\n                0,1,0,0,\n                0,0,1,0,\n                0,0,0,1]\n\nfunction AxisSpikes(gl, buffer, vao, shader) {\n  this.gl         = gl\n  this.buffer     = buffer\n  this.vao        = vao\n  this.shader     = shader\n  this.pixelRatio = 1\n  this.bounds     = [[-1000,-1000,-1000], [1000,1000,1000]]\n  this.position   = [0,0,0]\n  this.lineWidth  = [2,2,2]\n  this.colors     = [[0,0,0,1], [0,0,0,1], [0,0,0,1]]\n  this.enabled    = [true,true,true]\n  this.drawSides  = [true,true,true]\n  this.axes       = null\n}\n\nvar proto = AxisSpikes.prototype\n\nvar OUTER_FACE = [0,0,0]\nvar INNER_FACE = [0,0,0]\n\nvar SHAPE = [0,0]\n\nproto.isTransparent = function() {\n  return false\n}\n\nproto.drawTransparent = function(camera) {}\n\nproto.draw = function(camera) {\n  var gl = this.gl\n  var vao = this.vao\n  var shader = this.shader\n\n  vao.bind()\n  shader.bind()\n\n  var model      = camera.model || identity\n  var view       = camera.view || identity\n  var projection = camera.projection || identity\n\n  var axis\n  if(this.axes) {\n    axis = this.axes.lastCubeProps.axis\n  }\n\n  var outerFace = OUTER_FACE\n  var innerFace = INNER_FACE\n  for(var i=0; i<3; ++i) {\n    if(axis && axis[i] < 0) {\n      outerFace[i] = this.bounds[0][i]\n      innerFace[i] = this.bounds[1][i]\n    } else {\n      outerFace[i] = this.bounds[1][i]\n      innerFace[i] = this.bounds[0][i]\n    }\n  }\n\n  SHAPE[0] = gl.drawingBufferWidth\n  SHAPE[1] = gl.drawingBufferHeight\n\n  shader.uniforms.model       = model\n  shader.uniforms.view        = view\n  shader.uniforms.projection  = projection\n  shader.uniforms.coordinates = [this.position, outerFace, innerFace]\n  shader.uniforms.colors      = this.colors\n  shader.uniforms.screenShape = SHAPE\n\n  for(var i=0; i<3; ++i) {\n    shader.uniforms.lineWidth = this.lineWidth[i] * this.pixelRatio\n    if(this.enabled[i]) {\n      vao.draw(gl.TRIANGLES, 6, 6*i)\n      if(this.drawSides[i]) {\n        vao.draw(gl.TRIANGLES, 12, 18+12*i)\n      }\n    }\n  }\n\n  vao.unbind()\n}\n\nproto.update = function(options) {\n  if(!options) {\n    return\n  }\n  if(\"bounds\" in options) {\n    this.bounds = options.bounds\n  }\n  if(\"position\" in options) {\n    this.position = options.position\n  }\n  if(\"lineWidth\" in options) {\n    this.lineWidth = options.lineWidth\n  }\n  if(\"colors\" in options) {\n    this.colors = options.colors\n  }\n  if(\"enabled\" in options) {\n    this.enabled = options.enabled\n  }\n  if(\"drawSides\" in options) {\n    this.drawSides = options.drawSides\n  }\n}\n\nproto.dispose = function() {\n  this.vao.dispose()\n  this.buffer.dispose()\n  this.shader.dispose()\n}\n\n\n\nfunction createSpikes(gl, options) {\n  //Create buffers\n  var data = [ ]\n\n  function line(x,y,z,i,l,h) {\n    var row = [x,y,z,  0,0,0,  1]\n    row[i+3] = 1\n    row[i] = l\n    data.push.apply(data, row)\n    row[6] = -1\n    data.push.apply(data, row)\n    row[i] = h\n    data.push.apply(data, row)\n    data.push.apply(data, row)\n    row[6] = 1\n    data.push.apply(data, row)\n    row[i] = l\n    data.push.apply(data, row)\n  }\n\n  line(0,0,0, 0, 0, 1)\n  line(0,0,0, 1, 0, 1)\n  line(0,0,0, 2, 0, 1)\n\n  line(1,0,0,  1,  -1,1)\n  line(1,0,0,  2,  -1,1)\n\n  line(0,1,0,  0,  -1,1)\n  line(0,1,0,  2,  -1,1)\n\n  line(0,0,1,  0,  -1,1)\n  line(0,0,1,  1,  -1,1)\n\n  var buffer = createBuffer(gl, data)\n  var vao = createVAO(gl, [{\n    type: gl.FLOAT,\n    buffer: buffer,\n    size: 3,\n    offset: 0,\n    stride: 28\n  }, {\n    type: gl.FLOAT,\n    buffer: buffer,\n    size: 3,\n    offset: 12,\n    stride: 28\n  }, {\n    type: gl.FLOAT,\n    buffer: buffer,\n    size: 1,\n    offset: 24,\n    stride: 28\n  }])\n\n  //Create shader\n  var shader = createShader(gl)\n  shader.attributes.position.location = 0\n  shader.attributes.color.location = 1\n  shader.attributes.weight.location = 2\n\n  //Create spike object\n  var spikes = new AxisSpikes(gl, buffer, vao, shader)\n\n  //Set parameters\n  spikes.update(options)\n\n  //Return resulting object\n  return spikes\n}\n\n},{\"./shaders/index\":309,\"gl-buffer\":241,\"gl-vao\":327}],311:[function(_dereq_,module,exports){\nvar glslify       = _dereq_('glslify')\n\nvar triVertSrc = glslify([\"precision highp float;\\n\\nprecision highp float;\\n#define GLSLIFY 1\\n\\nvec3 getOrthogonalVector(vec3 v) {\\n  // Return up-vector for only-z vector.\\n  // Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\\n  // From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\\n  // Assign z = 0, x = -b, y = a:\\n  // a*-b + b*a + c*0 = -ba + ba + 0 = 0\\n  if (v.x*v.x > v.z*v.z || v.y*v.y > v.z*v.z) {\\n    return normalize(vec3(-v.y, v.x, 0.0));\\n  } else {\\n    return normalize(vec3(0.0, v.z, -v.y));\\n  }\\n}\\n\\n// Calculate the tube vertex and normal at the given index.\\n//\\n// The returned vertex is for a tube ring with its center at origin, radius of length(d), pointing in the direction of d.\\n//\\n// Each tube segment is made up of a ring of vertices.\\n// These vertices are used to make up the triangles of the tube by connecting them together in the vertex array.\\n// The indexes of tube segments run from 0 to 8.\\n//\\nvec3 getTubePosition(vec3 d, float index, out vec3 normal) {\\n  float segmentCount = 8.0;\\n\\n  float angle = 2.0 * 3.14159 * (index / segmentCount);\\n\\n  vec3 u = getOrthogonalVector(d);\\n  vec3 v = normalize(cross(u, d));\\n\\n  vec3 x = u * cos(angle) * length(d);\\n  vec3 y = v * sin(angle) * length(d);\\n  vec3 v3 = x + y;\\n\\n  normal = normalize(v3);\\n\\n  return v3;\\n}\\n\\nattribute vec4 vector;\\nattribute vec4 color, position;\\nattribute vec2 uv;\\nuniform float vectorScale;\\nuniform float tubeScale;\\n\\nuniform mat4 model\\n           , view\\n           , projection\\n           , inverseModel;\\nuniform vec3 eyePosition\\n           , lightPosition;\\n\\nvarying vec3 f_normal\\n           , f_lightDirection\\n           , f_eyeDirection\\n           , f_data\\n           , f_position;\\nvarying vec4 f_color;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  // Scale the vector magnitude to stay constant with\\n  // model & view changes.\\n  vec3 normal;\\n  vec3 XYZ = getTubePosition(mat3(model) * (tubeScale * vector.w * normalize(vector.xyz)), position.w, normal);\\n  vec4 tubePosition = model * vec4(position.xyz, 1.0) + vec4(XYZ, 0.0);\\n\\n  //Lighting geometry parameters\\n  vec4 cameraCoordinate = view * tubePosition;\\n  cameraCoordinate.xyz /= cameraCoordinate.w;\\n  f_lightDirection = lightPosition - cameraCoordinate.xyz;\\n  f_eyeDirection   = eyePosition - cameraCoordinate.xyz;\\n  f_normal = normalize((vec4(normal,0.0) * inverseModel).xyz);\\n\\n  // vec4 m_position  = model * vec4(tubePosition, 1.0);\\n  vec4 t_position  = view * tubePosition;\\n  gl_Position      = projection * t_position;\\n\\n  f_color          = color;\\n  f_data           = tubePosition.xyz;\\n  f_position       = position.xyz;\\n  f_uv             = uv;\\n}\\n\"])\nvar triFragSrc = glslify([\"#extension GL_OES_standard_derivatives : enable\\n\\nprecision highp float;\\n#define GLSLIFY 1\\n\\nfloat beckmannDistribution(float x, float roughness) {\\n  float NdotH = max(x, 0.0001);\\n  float cos2Alpha = NdotH * NdotH;\\n  float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;\\n  float roughness2 = roughness * roughness;\\n  float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;\\n  return exp(tan2Alpha / roughness2) / denom;\\n}\\n\\nfloat cookTorranceSpecular(\\n  vec3 lightDirection,\\n  vec3 viewDirection,\\n  vec3 surfaceNormal,\\n  float roughness,\\n  float fresnel) {\\n\\n  float VdotN = max(dot(viewDirection, surfaceNormal), 0.0);\\n  float LdotN = max(dot(lightDirection, surfaceNormal), 0.0);\\n\\n  //Half angle vector\\n  vec3 H = normalize(lightDirection + viewDirection);\\n\\n  //Geometric term\\n  float NdotH = max(dot(surfaceNormal, H), 0.0);\\n  float VdotH = max(dot(viewDirection, H), 0.000001);\\n  float LdotH = max(dot(lightDirection, H), 0.000001);\\n  float G1 = (2.0 * NdotH * VdotN) / VdotH;\\n  float G2 = (2.0 * NdotH * LdotN) / LdotH;\\n  float G = min(1.0, min(G1, G2));\\n  \\n  //Distribution term\\n  float D = beckmannDistribution(NdotH, roughness);\\n\\n  //Fresnel term\\n  float F = pow(1.0 - VdotN, fresnel);\\n\\n  //Multiply terms and done\\n  return  G * F * D / max(3.14159265 * VdotN, 0.000001);\\n}\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3 clipBounds[2];\\nuniform float roughness\\n            , fresnel\\n            , kambient\\n            , kdiffuse\\n            , kspecular\\n            , opacity;\\nuniform sampler2D texture;\\n\\nvarying vec3 f_normal\\n           , f_lightDirection\\n           , f_eyeDirection\\n           , f_data\\n           , f_position;\\nvarying vec4 f_color;\\nvarying vec2 f_uv;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\\n  vec3 N = normalize(f_normal);\\n  vec3 L = normalize(f_lightDirection);\\n  vec3 V = normalize(f_eyeDirection);\\n\\n  if(gl_FrontFacing) {\\n    N = -N;\\n  }\\n\\n  float specular = min(1.0, max(0.0, cookTorranceSpecular(L, V, N, roughness, fresnel)));\\n  float diffuse  = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);\\n\\n  vec4 surfaceColor = f_color * texture2D(texture, f_uv);\\n  vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular,  1.0);\\n\\n  gl_FragColor = litColor * opacity;\\n}\\n\"])\nvar pickVertSrc = glslify([\"precision highp float;\\n\\nprecision highp float;\\n#define GLSLIFY 1\\n\\nvec3 getOrthogonalVector(vec3 v) {\\n  // Return up-vector for only-z vector.\\n  // Return ax + by + cz = 0, a point that lies on the plane that has v as a normal and that isn't (0,0,0).\\n  // From the above if-statement we have ||a|| > 0  U  ||b|| > 0.\\n  // Assign z = 0, x = -b, y = a:\\n  // a*-b + b*a + c*0 = -ba + ba + 0 = 0\\n  if (v.x*v.x > v.z*v.z || v.y*v.y > v.z*v.z) {\\n    return normalize(vec3(-v.y, v.x, 0.0));\\n  } else {\\n    return normalize(vec3(0.0, v.z, -v.y));\\n  }\\n}\\n\\n// Calculate the tube vertex and normal at the given index.\\n//\\n// The returned vertex is for a tube ring with its center at origin, radius of length(d), pointing in the direction of d.\\n//\\n// Each tube segment is made up of a ring of vertices.\\n// These vertices are used to make up the triangles of the tube by connecting them together in the vertex array.\\n// The indexes of tube segments run from 0 to 8.\\n//\\nvec3 getTubePosition(vec3 d, float index, out vec3 normal) {\\n  float segmentCount = 8.0;\\n\\n  float angle = 2.0 * 3.14159 * (index / segmentCount);\\n\\n  vec3 u = getOrthogonalVector(d);\\n  vec3 v = normalize(cross(u, d));\\n\\n  vec3 x = u * cos(angle) * length(d);\\n  vec3 y = v * sin(angle) * length(d);\\n  vec3 v3 = x + y;\\n\\n  normal = normalize(v3);\\n\\n  return v3;\\n}\\n\\nattribute vec4 vector;\\nattribute vec4 position;\\nattribute vec4 id;\\n\\nuniform mat4 model, view, projection;\\nuniform float tubeScale;\\n\\nvarying vec3 f_position;\\nvarying vec4 f_id;\\n\\nvoid main() {\\n  vec3 normal;\\n  vec3 XYZ = getTubePosition(mat3(model) * (tubeScale * vector.w * normalize(vector.xyz)), position.w, normal);\\n  vec4 tubePosition = model * vec4(position.xyz, 1.0) + vec4(XYZ, 0.0);\\n\\n  gl_Position = projection * view * tubePosition;\\n  f_id        = id;\\n  f_position  = position.xyz;\\n}\\n\"])\nvar pickFragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3  clipBounds[2];\\nuniform float pickId;\\n\\nvarying vec3 f_position;\\nvarying vec4 f_id;\\n\\nvoid main() {\\n  if (outOfRange(clipBounds[0], clipBounds[1], f_position)) discard;\\n\\n  gl_FragColor = vec4(pickId, f_id.xyz);\\n}\"])\n\nexports.meshShader = {\n  vertex:   triVertSrc,\n  fragment: triFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec4'},\n    {name: 'normal', type: 'vec3'},\n    {name: 'color', type: 'vec4'},\n    {name: 'uv', type: 'vec2'},\n    {name: 'vector', type: 'vec4'}\n  ]\n}\nexports.pickShader = {\n  vertex:   pickVertSrc,\n  fragment: pickFragSrc,\n  attributes: [\n    {name: 'position', type: 'vec4'},\n    {name: 'id', type: 'vec4'},\n    {name: 'vector', type: 'vec4'}\n  ]\n}\n\n},{\"glslify\":409}],312:[function(_dereq_,module,exports){\n'use strict'\n\nvar DEFAULT_VERTEX_NORMALS_EPSILON = 1e-6; // may be too large if triangles are very small\nvar DEFAULT_FACE_NORMALS_EPSILON = 1e-6;\n\nvar createShader  = _dereq_('gl-shader')\nvar createBuffer  = _dereq_('gl-buffer')\nvar createVAO     = _dereq_('gl-vao')\nvar createTexture = _dereq_('gl-texture2d')\nvar normals       = _dereq_('normals')\nvar multiply      = _dereq_('gl-mat4/multiply')\nvar invert        = _dereq_('gl-mat4/invert')\nvar ndarray       = _dereq_('ndarray')\nvar colormap      = _dereq_('colormap')\nvar getContour    = _dereq_('simplicial-complex-contour')\nvar pool          = _dereq_('typedarray-pool')\nvar shaders       = _dereq_('./shaders')\n\nvar meshShader    = shaders.meshShader\nvar pickShader    = shaders.pickShader\n\nvar IDENTITY = [\n  1,0,0,0,\n  0,1,0,0,\n  0,0,1,0,\n  0,0,0,1]\n\nfunction SimplicialMesh(gl\n  , texture\n  , triShader\n  , pickShader\n  , trianglePositions\n  , triangleVectors\n  , triangleIds\n  , triangleColors\n  , triangleUVs\n  , triangleNormals\n  , triangleVAO\n  , edgePositions\n  , edgeIds\n  , edgeColors\n  , edgeUVs\n  , edgeVAO\n  , pointPositions\n  , pointIds\n  , pointColors\n  , pointUVs\n  , pointSizes\n  , pointVAO\n  , contourPositions\n  , contourVAO) {\n\n  this.gl                = gl\n  this.cells             = []\n  this.positions         = []\n  this.intensity         = []\n  this.texture           = texture\n  this.dirty             = true\n\n  this.triShader         = triShader\n  this.pickShader        = pickShader\n\n  this.trianglePositions = trianglePositions\n  this.triangleVectors   = triangleVectors\n  this.triangleColors    = triangleColors\n  this.triangleNormals   = triangleNormals\n  this.triangleUVs       = triangleUVs\n  this.triangleIds       = triangleIds\n  this.triangleVAO       = triangleVAO\n  this.triangleCount     = 0\n\n  this.lineWidth         = 1\n  this.edgePositions     = edgePositions\n  this.edgeColors        = edgeColors\n  this.edgeUVs           = edgeUVs\n  this.edgeIds           = edgeIds\n  this.edgeVAO           = edgeVAO\n  this.edgeCount         = 0\n\n  this.pointPositions    = pointPositions\n  this.pointColors       = pointColors\n  this.pointUVs          = pointUVs\n  this.pointSizes        = pointSizes\n  this.pointIds          = pointIds\n  this.pointVAO          = pointVAO\n  this.pointCount        = 0\n\n  this.contourLineWidth  = 1\n  this.contourPositions  = contourPositions\n  this.contourVAO        = contourVAO\n  this.contourCount      = 0\n  this.contourColor      = [0,0,0]\n  this.contourEnable     = false\n\n  this.pickId            = 1\n  this.bounds            = [\n    [ Infinity, Infinity, Infinity],\n    [-Infinity,-Infinity,-Infinity] ]\n  this.clipBounds        = [\n    [-Infinity,-Infinity,-Infinity],\n    [ Infinity, Infinity, Infinity] ]\n\n  this.lightPosition = [1e5, 1e5, 0]\n  this.ambientLight  = 0.8\n  this.diffuseLight  = 0.8\n  this.specularLight = 2.0\n  this.roughness     = 0.5\n  this.fresnel       = 1.5\n\n  this.opacity       = 1.0\n\n  this.tubeScale     = 1.0\n\n  this._model       = IDENTITY\n  this._view        = IDENTITY\n  this._projection  = IDENTITY\n  this._resolution  = [1,1]\n  this.pixelRatio   = 1\n}\n\nvar proto = SimplicialMesh.prototype\n\nproto.isOpaque = function() {\n  return this.opacity >= 1\n}\n\nproto.isTransparent = function() {\n  return this.opacity < 1\n}\n\nproto.pickSlots = 1\n\nproto.setPickBase = function(id) {\n  this.pickId = id\n}\n\nfunction genColormap(param) {\n  var colors = colormap({\n      colormap: param\n    , nshades:  256\n    , format:  'rgba'\n  })\n\n  var result = new Uint8Array(256*4)\n  for(var i=0; i<256; ++i) {\n    var c = colors[i]\n    for(var j=0; j<3; ++j) {\n      result[4*i+j] = c[j]\n    }\n    result[4*i+3] = c[3]*255\n  }\n\n  return ndarray(result, [256,256,4], [4,0,1])\n}\n\nfunction unpackIntensity(cells, numVerts, cellIntensity) {\n  var result = new Array(numVerts)\n  for(var i=0; i<numVerts; ++i) {\n    result[i] = 0\n  }\n  var numCells = cells.length\n  for(var i=0; i<numCells; ++i) {\n    var c = cells[i]\n    for(var j=0; j<c.length; ++j) {\n      result[c[j]] = cellIntensity[i]\n    }\n  }\n  return result\n}\n\nfunction takeZComponent(array) {\n  var n = array.length\n  var result = new Array(n)\n  for(var i=0; i<n; ++i) {\n    result[i] = array[i][2]\n  }\n  return result\n}\n\nproto.highlight = function(selection) {\n  if(!selection || !this.contourEnable) {\n    this.contourCount = 0\n    return\n  }\n  var level = getContour(this.cells, this.intensity, selection.intensity)\n  var cells         = level.cells\n  var vertexIds     = level.vertexIds\n  var vertexWeights = level.vertexWeights\n  var numCells = cells.length\n  var result = pool.mallocFloat32(2 * 3 * numCells)\n  var ptr = 0\n  for(var i=0; i<numCells; ++i) {\n    var c = cells[i]\n    for(var j=0; j<2; ++j) {\n      var v = c[0]\n      if(c.length === 2) {\n        v = c[j]\n      }\n      var a = vertexIds[v][0]\n      var b = vertexIds[v][1]\n      var w = vertexWeights[v]\n      var wi = 1.0 - w\n      var pa = this.positions[a]\n      var pb = this.positions[b]\n      for(var k=0; k<3; ++k) {\n        result[ptr++] = w * pa[k] + wi * pb[k]\n      }\n    }\n  }\n  this.contourCount = (ptr / 3)|0\n  this.contourPositions.update(result.subarray(0, ptr))\n  pool.free(result)\n}\n\nproto.update = function(params) {\n  params = params || {}\n  var gl = this.gl\n\n  this.dirty = true\n\n  if('contourEnable' in params) {\n    this.contourEnable = params.contourEnable\n  }\n  if('contourColor' in params) {\n    this.contourColor = params.contourColor\n  }\n  if('lineWidth' in params) {\n    this.lineWidth = params.lineWidth\n  }\n  if('lightPosition' in params) {\n    this.lightPosition = params.lightPosition\n  }\n  if('opacity' in params) {\n    this.opacity = params.opacity\n  }\n  if('ambient' in params) {\n    this.ambientLight  = params.ambient\n  }\n  if('diffuse' in params) {\n    this.diffuseLight = params.diffuse\n  }\n  if('specular' in params) {\n    this.specularLight = params.specular\n  }\n  if('roughness' in params) {\n    this.roughness = params.roughness\n  }\n  if('fresnel' in params) {\n    this.fresnel = params.fresnel\n  }\n\n  if(params.texture) {\n    this.texture.dispose()\n    this.texture = createTexture(gl, params.texture)\n  } else if (params.colormap) {\n    this.texture.shape = [256,256]\n    this.texture.minFilter = gl.LINEAR_MIPMAP_LINEAR\n    this.texture.magFilter = gl.LINEAR\n    this.texture.setPixels(genColormap(params.colormap))\n    this.texture.generateMipmap()\n  }\n\n  var cells = params.cells\n  var positions = params.positions\n  var vectors = params.vectors\n\n  if(!positions || !cells || !vectors) {\n    return\n  }\n\n  if (params.tubeScale !== undefined) {\n    this.tubeScale = params.tubeScale;\n  }\n\n  var tPos = []\n  var tVec = []\n  var tCol = []\n  var tNor = []\n  var tUVs = []\n  var tIds = []\n\n  var ePos = []\n  var eCol = []\n  var eUVs = []\n  var eIds = []\n\n  var pPos = []\n  var pCol = []\n  var pUVs = []\n  var pSiz = []\n  var pIds = []\n\n  //Save geometry data for picking calculations\n  this.cells     = cells\n  this.positions = positions\n  this.vectors   = vectors\n\n  //Compute normals\n  var vertexNormals = params.vertexNormals\n  var cellNormals   = params.cellNormals\n  var vertexNormalsEpsilon = params.vertexNormalsEpsilon === void(0) ? DEFAULT_VERTEX_NORMALS_EPSILON : params.vertexNormalsEpsilon\n  var faceNormalsEpsilon = params.faceNormalsEpsilon === void(0) ? DEFAULT_FACE_NORMALS_EPSILON : params.faceNormalsEpsilon\n  if(params.useFacetNormals && !cellNormals) {\n    cellNormals = normals.faceNormals(cells, positions, faceNormalsEpsilon)\n  }\n  if(!cellNormals && !vertexNormals) {\n    vertexNormals = normals.vertexNormals(cells, positions, vertexNormalsEpsilon)\n  }\n\n  //Compute colors\n  var vertexColors    = params.vertexColors\n  var cellColors      = params.cellColors\n  var meshColor       = params.meshColor || [1,1,1,1]\n\n  //UVs\n  var vertexUVs       = params.vertexUVs\n  var vertexIntensity = params.vertexIntensity\n  var cellUVs         = params.cellUVs\n  var cellIntensity   = params.cellIntensity\n\n  var intensityLo     = Infinity\n  var intensityHi     = -Infinity\n  if(!vertexUVs && !cellUVs) {\n    if(vertexIntensity) {\n      if(params.vertexIntensityBounds) {\n        intensityLo = +params.vertexIntensityBounds[0]\n        intensityHi = +params.vertexIntensityBounds[1]\n      } else {\n        for(var i=0; i<vertexIntensity.length; ++i) {\n          var f = vertexIntensity[i]\n          intensityLo = Math.min(intensityLo, f)\n          intensityHi = Math.max(intensityHi, f)\n        }\n      }\n    } else if(cellIntensity) {\n      for(var i=0; i<cellIntensity.length; ++i) {\n        var f = cellIntensity[i]\n        intensityLo = Math.min(intensityLo, f)\n        intensityHi = Math.max(intensityHi, f)\n      }\n    } else {\n      for(var i=0; i<positions.length; ++i) {\n        var f = positions[i][2]\n        intensityLo = Math.min(intensityLo, f)\n        intensityHi = Math.max(intensityHi, f)\n      }\n    }\n  }\n\n  if(vertexIntensity) {\n    this.intensity = vertexIntensity\n  } else if(cellIntensity) {\n    this.intensity = unpackIntensity(cells, positions.length, cellIntensity)\n  } else {\n    this.intensity = takeZComponent(positions)\n  }\n\n  //Point size\n  var pointSizes      = params.pointSizes\n  var meshPointSize   = params.pointSize || 1.0\n\n  //Update bounds\n  this.bounds       = [[Infinity,Infinity,Infinity], [-Infinity,-Infinity,-Infinity]]\n  for(var i=0; i<positions.length; ++i) {\n    var p = positions[i]\n    for(var j=0; j<3; ++j) {\n      if(isNaN(p[j]) || !isFinite(p[j])) {\n        continue\n      }\n      this.bounds[0][j] = Math.min(this.bounds[0][j], p[j])\n      this.bounds[1][j] = Math.max(this.bounds[1][j], p[j])\n    }\n  }\n\n  //Pack cells into buffers\n  var triangleCount = 0\n  var edgeCount = 0\n  var pointCount = 0\n\nfill_loop:\n  for(var i=0; i<cells.length; ++i) {\n    var cell = cells[i]\n    switch(cell.length) {\n      case 1:\n\n        var v = cell[0]\n        var p = positions[v]\n\n        //Check NaNs\n        for(var j=0; j<3; ++j) {\n          if(isNaN(p[j]) || !isFinite(p[j])) {\n            continue fill_loop\n          }\n        }\n\n        pPos.push(p[0], p[1], p[2], p[3])\n\n        var c\n        if(vertexColors) {\n          c = vertexColors[v]\n        } else if(cellColors) {\n          c = cellColors[i]\n        } else {\n          c = meshColor\n        }\n        if(c.length === 3) {\n          pCol.push(c[0], c[1], c[2], 1)\n        } else {\n          pCol.push(c[0], c[1], c[2], c[3])\n        }\n\n        var uv\n        if(vertexUVs) {\n          uv = vertexUVs[v]\n        } else if(vertexIntensity) {\n          uv = [\n            (vertexIntensity[v] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        } else if(cellUVs) {\n          uv = cellUVs[i]\n        } else if(cellIntensity) {\n          uv = [\n            (cellIntensity[i] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        } else {\n          uv = [\n            (p[2] - intensityLo) /\n            (intensityHi - intensityLo), 0]\n        }\n        pUVs.push(uv[0], uv[1])\n\n        if(pointSizes) {\n          pSiz.push(pointSizes[v])\n        } else {\n          pSiz.push(meshPointSize)\n        }\n\n        pIds.push(i)\n\n        pointCount += 1\n      break\n\n      case 2:\n\n        //Check NaNs\n        for(var j=0; j<2; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n          for(var k=0; k<3; ++k) {\n            if(isNaN(p[k]) || !isFinite(p[k])) {\n              continue fill_loop\n            }\n          }\n        }\n\n        for(var j=0; j<2; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n\n          ePos.push(p[0], p[1], p[2])\n\n          var c\n          if(vertexColors) {\n            c = vertexColors[v]\n          } else if(cellColors) {\n            c = cellColors[i]\n          } else {\n            c = meshColor\n          }\n          if(c.length === 3) {\n            eCol.push(c[0], c[1], c[2], 1)\n          } else {\n            eCol.push(c[0], c[1], c[2], c[3])\n          }\n\n          var uv\n          if(vertexUVs) {\n            uv = vertexUVs[v]\n          } else if(vertexIntensity) {\n            uv = [\n              (vertexIntensity[v] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else if(cellUVs) {\n            uv = cellUVs[i]\n          } else if(cellIntensity) {\n            uv = [\n              (cellIntensity[i] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else {\n            uv = [\n              (p[2] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          }\n          eUVs.push(uv[0], uv[1])\n\n          eIds.push(i)\n        }\n        edgeCount += 1\n      break\n\n      case 3:\n        //Check NaNs\n        for(var j=0; j<3; ++j) {\n          var v = cell[j]\n          var p = positions[v]\n          for(var k=0; k<3; ++k) {\n            if(isNaN(p[k]) || !isFinite(p[k])) {\n              continue fill_loop\n            }\n          }\n        }\n\n        for(var j=0; j<3; ++j) {\n          var v = cell[2 - j]\n\n          var p = positions[v]\n          tPos.push(p[0], p[1], p[2], p[3])\n\n          var w = vectors[v]\n          tVec.push(w[0], w[1], w[2], w[3]);\n\n          var c\n          if(vertexColors) {\n            c = vertexColors[v]\n          } else if(cellColors) {\n            c = cellColors[i]\n          } else {\n            c = meshColor\n          }\n          if(c.length === 3) {\n            tCol.push(c[0], c[1], c[2], 1)\n          } else {\n            tCol.push(c[0], c[1], c[2], c[3])\n          }\n\n          var uv\n          if(vertexUVs) {\n            uv = vertexUVs[v]\n          } else if(vertexIntensity) {\n            uv = [\n              (vertexIntensity[v] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else if(cellUVs) {\n            uv = cellUVs[i]\n          } else if(cellIntensity) {\n            uv = [\n              (cellIntensity[i] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          } else {\n            uv = [\n              (p[2] - intensityLo) /\n              (intensityHi - intensityLo), 0]\n          }\n          tUVs.push(uv[0], uv[1])\n\n          var q\n          if(vertexNormals) {\n            q = vertexNormals[v]\n          } else {\n            q = cellNormals[i]\n          }\n          tNor.push(q[0], q[1], q[2])\n\n          tIds.push(i)\n        }\n        triangleCount += 1\n      break\n\n      default:\n      break\n    }\n  }\n\n  this.pointCount     = pointCount\n  this.edgeCount      = edgeCount\n  this.triangleCount  = triangleCount\n\n  this.pointPositions.update(pPos)\n  this.pointColors.update(pCol)\n  this.pointUVs.update(pUVs)\n  this.pointSizes.update(pSiz)\n  this.pointIds.update(new Uint32Array(pIds))\n\n  this.edgePositions.update(ePos)\n  this.edgeColors.update(eCol)\n  this.edgeUVs.update(eUVs)\n  this.edgeIds.update(new Uint32Array(eIds))\n\n  this.trianglePositions.update(tPos)\n  this.triangleVectors.update(tVec)\n  this.triangleColors.update(tCol)\n  this.triangleUVs.update(tUVs)\n  this.triangleNormals.update(tNor)\n  this.triangleIds.update(new Uint32Array(tIds))\n}\n\nproto.drawTransparent = proto.draw = function(params) {\n  params = params || {}\n  var gl          = this.gl\n  var model       = params.model      || IDENTITY\n  var view        = params.view       || IDENTITY\n  var projection  = params.projection || IDENTITY\n\n  var clipBounds = [[-1e6,-1e6,-1e6],[1e6,1e6,1e6]]\n  for(var i=0; i<3; ++i) {\n    clipBounds[0][i] = Math.max(clipBounds[0][i], this.clipBounds[0][i])\n    clipBounds[1][i] = Math.min(clipBounds[1][i], this.clipBounds[1][i])\n  }\n\n  var uniforms = {\n    model:      model,\n    view:       view,\n    projection: projection,\n    inverseModel: IDENTITY.slice(),\n\n    clipBounds: clipBounds,\n\n    kambient:   this.ambientLight,\n    kdiffuse:   this.diffuseLight,\n    kspecular:  this.specularLight,\n    roughness:  this.roughness,\n    fresnel:    this.fresnel,\n\n    eyePosition:   [0,0,0],\n    lightPosition: [0,0,0],\n\n    opacity:  this.opacity,\n\n    tubeScale: this.tubeScale,\n\n    contourColor: this.contourColor,\n\n    texture:    0\n  }\n\n  uniforms.inverseModel = invert(uniforms.inverseModel, uniforms.model)\n\n  gl.disable(gl.CULL_FACE)\n\n  this.texture.bind(0)\n\n  var invCameraMatrix = new Array(16)\n  multiply(invCameraMatrix, uniforms.view, uniforms.model)\n  multiply(invCameraMatrix, uniforms.projection, invCameraMatrix)\n  invert(invCameraMatrix, invCameraMatrix)\n\n  for(var i=0; i<3; ++i) {\n    uniforms.eyePosition[i] = invCameraMatrix[12+i] / invCameraMatrix[15]\n  }\n\n  var w = invCameraMatrix[15]\n  for(var i=0; i<3; ++i) {\n    w += this.lightPosition[i] * invCameraMatrix[4*i+3]\n  }\n  for(var i=0; i<3; ++i) {\n    var s = invCameraMatrix[12+i]\n    for(var j=0; j<3; ++j) {\n      s += invCameraMatrix[4*j+i] * this.lightPosition[j]\n    }\n    uniforms.lightPosition[i] = s / w\n  }\n\n  if(this.triangleCount > 0) {\n    var shader = this.triShader\n    shader.bind()\n    shader.uniforms = uniforms\n\n    this.triangleVAO.bind()\n    gl.drawArrays(gl.TRIANGLES, 0, this.triangleCount*3)\n    this.triangleVAO.unbind()\n  }\n}\n\nproto.drawPick = function(params) {\n  params = params || {}\n\n  var gl         = this.gl\n\n  var model      = params.model      || IDENTITY\n  var view       = params.view       || IDENTITY\n  var projection = params.projection || IDENTITY\n\n  var clipBounds = [[-1e6,-1e6,-1e6],[1e6,1e6,1e6]]\n  for(var i=0; i<3; ++i) {\n    clipBounds[0][i] = Math.max(clipBounds[0][i], this.clipBounds[0][i])\n    clipBounds[1][i] = Math.min(clipBounds[1][i], this.clipBounds[1][i])\n  }\n\n  //Save camera parameters\n  this._model      = [].slice.call(model)\n  this._view       = [].slice.call(view)\n  this._projection = [].slice.call(projection)\n  this._resolution = [gl.drawingBufferWidth, gl.drawingBufferHeight]\n\n  var uniforms = {\n    model:      model,\n    view:       view,\n    projection: projection,\n    clipBounds: clipBounds,\n\n    tubeScale: this.tubeScale,\n\n    pickId:     this.pickId / 255.0,\n  }\n\n  var shader = this.pickShader\n  shader.bind()\n  shader.uniforms = uniforms\n\n  if(this.triangleCount > 0) {\n    this.triangleVAO.bind()\n    gl.drawArrays(gl.TRIANGLES, 0, this.triangleCount*3)\n    this.triangleVAO.unbind()\n  }\n\n  if(this.edgeCount > 0) {\n    this.edgeVAO.bind()\n    gl.lineWidth(this.lineWidth * this.pixelRatio)\n    gl.drawArrays(gl.LINES, 0, this.edgeCount*2)\n    this.edgeVAO.unbind()\n  }\n\n}\n\n\nproto.pick = function(pickData) {\n  if(!pickData) {\n    return null\n  }\n  if(pickData.id !== this.pickId) {\n    return null\n  }\n\n  var cellId = pickData.value[0] + 256*pickData.value[1] + 65536*pickData.value[2]\n  var cell = this.cells[cellId]\n\n  var pos = this.positions[cell[1]].slice(0, 3)\n  var intensity = this.intensity[cell[1]]\n  var velocity = this.vectors[cell[1]].slice(0, 3)\n  var divergence = this.vectors[cell[1]][3]\n\n  return {\n    index: cellId,\n    position: pos,\n    intensity: intensity,\n    velocity: velocity,\n    divergence: divergence,\n    dataCoordinate: pos\n  }\n}\n\n\nproto.dispose = function() {\n  this.texture.dispose()\n\n  this.triShader.dispose()\n  this.pickShader.dispose()\n\n  this.triangleVAO.dispose()\n  this.trianglePositions.dispose()\n  this.triangleVectors.dispose()\n  this.triangleColors.dispose()\n  this.triangleUVs.dispose()\n  this.triangleNormals.dispose()\n  this.triangleIds.dispose()\n\n  this.edgeVAO.dispose()\n  this.edgePositions.dispose()\n  this.edgeColors.dispose()\n  this.edgeUVs.dispose()\n  this.edgeIds.dispose()\n\n  this.pointVAO.dispose()\n  this.pointPositions.dispose()\n  this.pointColors.dispose()\n  this.pointUVs.dispose()\n  this.pointSizes.dispose()\n  this.pointIds.dispose()\n\n  this.contourVAO.dispose()\n  this.contourPositions.dispose()\n}\n\nfunction createMeshShader(gl) {\n  var shader = createShader(gl, meshShader.vertex, meshShader.fragment, null, meshShader.attributes)\n  shader.attributes.position.location = 0\n  shader.attributes.color.location    = 2\n  shader.attributes.uv.location       = 3\n  shader.attributes.vector.location   = 5\n  return shader\n}\n\n\nfunction createPickShader(gl) {\n  var shader = createShader(gl, pickShader.vertex, pickShader.fragment, null, pickShader.attributes)\n  shader.attributes.position.location = 0\n  shader.attributes.id.location       = 1\n  shader.attributes.vector.location   = 5\n  return shader\n}\n\n\nfunction createSimplicialMesh(gl, params) {\n  if (arguments.length === 1) {\n    params = gl;\n    gl = params.gl;\n  }\n\n  var triShader       = params.triShader || createMeshShader(gl)\n  var pickShader      = createPickShader(gl)\n\n  var meshTexture       = createTexture(gl,\n    ndarray(new Uint8Array([255,255,255,255]), [1,1,4]))\n  meshTexture.generateMipmap()\n  meshTexture.minFilter = gl.LINEAR_MIPMAP_LINEAR\n  meshTexture.magFilter = gl.LINEAR\n\n  var trianglePositions = createBuffer(gl)\n  var triangleVectors   = createBuffer(gl)\n  var triangleColors    = createBuffer(gl)\n  var triangleUVs       = createBuffer(gl)\n  var triangleNormals   = createBuffer(gl)\n  var triangleIds       = createBuffer(gl)\n  var triangleVAO       = createVAO(gl, [\n    { buffer: trianglePositions,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: triangleIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: triangleColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: triangleUVs,\n      type: gl.FLOAT,\n      size: 2\n    },\n    { buffer: triangleNormals,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: triangleVectors,\n      type: gl.FLOAT,\n      size: 4\n    }\n  ])\n\n  var edgePositions = createBuffer(gl)\n  var edgeColors    = createBuffer(gl)\n  var edgeUVs       = createBuffer(gl)\n  var edgeIds       = createBuffer(gl)\n  var edgeVAO       = createVAO(gl, [\n    { buffer: edgePositions,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: edgeIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: edgeColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: edgeUVs,\n      type: gl.FLOAT,\n      size: 2\n    }\n  ])\n\n  var pointPositions  = createBuffer(gl)\n  var pointColors     = createBuffer(gl)\n  var pointUVs        = createBuffer(gl)\n  var pointSizes      = createBuffer(gl)\n  var pointIds        = createBuffer(gl)\n  var pointVAO        = createVAO(gl, [\n    { buffer: pointPositions,\n      type: gl.FLOAT,\n      size: 3\n    },\n    { buffer: pointIds,\n      type: gl.UNSIGNED_BYTE,\n      size: 4,\n      normalized: true\n    },\n    { buffer: pointColors,\n      type: gl.FLOAT,\n      size: 4\n    },\n    { buffer: pointUVs,\n      type: gl.FLOAT,\n      size: 2\n    },\n    { buffer: pointSizes,\n      type: gl.FLOAT,\n      size: 1\n    }\n  ])\n\n  var contourPositions = createBuffer(gl)\n  var contourVAO       = createVAO(gl, [\n    { buffer: contourPositions,\n      type:   gl.FLOAT,\n      size:   3\n    }])\n\n  var mesh = new SimplicialMesh(gl\n    , meshTexture\n    , triShader\n    , pickShader\n    , trianglePositions\n    , triangleVectors\n    , triangleIds\n    , triangleColors\n    , triangleUVs\n    , triangleNormals\n    , triangleVAO\n    , edgePositions\n    , edgeIds\n    , edgeColors\n    , edgeUVs\n    , edgeVAO\n    , pointPositions\n    , pointIds\n    , pointColors\n    , pointUVs\n    , pointSizes\n    , pointVAO\n    , contourPositions\n    , contourVAO)\n\n  mesh.update(params)\n\n  return mesh\n}\n\nmodule.exports = createSimplicialMesh\n\n},{\"./shaders\":311,\"colormap\":126,\"gl-buffer\":241,\"gl-mat4/invert\":265,\"gl-mat4/multiply\":267,\"gl-shader\":301,\"gl-texture2d\":322,\"gl-vao\":327,\"ndarray\":450,\"normals\":453,\"simplicial-complex-contour\":518,\"typedarray-pool\":545}],313:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar vec3 = _dereq_('gl-vec3');\nvar vec4 = _dereq_('gl-vec4');\n\nvar streamToTube = function(stream, maxDivergence, minDistance, maxNorm) {\n\tvar points = stream.points;\n\tvar velocities = stream.velocities;\n\tvar divergences = stream.divergences;\n\n\tvar p, fwd, r, u, v, up;\n\tup = vec3.set(vec3.create(), 0, 1, 0);\n\tu = vec3.create();\n\tv = vec3.create();\n\tvar p2 = vec3.create();\n\n\tvar verts = [];\n\tvar faces = [];\n\tvar vectors = [];\n\tvar previousVerts = [];\n\tvar currentVerts = [];\n\tvar intensities = [];\n\tvar previousIntensity = 0;\n\tvar currentIntensity = 0;\n\tvar currentVector = vec4.create();\n\tvar previousVector = vec4.create();\n\n\tvar facets = 8;\n\n\tfor (var i = 0; i < points.length; i++) {\n\t\tp = points[i];\n\t\tfwd = velocities[i];\n\t\tr = divergences[i];\n\t\tif (maxDivergence === 0) {\n\t\t\tr = minDistance * 0.05;\n\t\t}\n\t\tcurrentIntensity = vec3.length(fwd) / maxNorm;\n\t\tcurrentVector = vec4.create();\n\t\tvec3.copy(currentVector, fwd);\n\t\tcurrentVector[3] = r;\n\t\t\n\t\tfor (var a = 0; a < facets; a++) {\n\t\t\tcurrentVerts[a] = [p[0], p[1], p[2], a];\n\t\t}\n\t\tif (previousVerts.length > 0) {\n\t\t\tfor (var a = 0; a < facets; a++) {\n\t\t\t\tvar a1 = (a+1) % facets;\n\t\t\t\tverts.push(\n\t\t\t\t\tpreviousVerts[a],\n\t\t\t\t\tcurrentVerts[a],\n\t\t\t\t\tcurrentVerts[a1],\n\n\t\t\t\t\tcurrentVerts[a1],\n\t\t\t\t\tpreviousVerts[a1],\n\t\t\t\t\tpreviousVerts[a]\n\t\t\t\t);\n\t\t\t\tvectors.push(\n\t\t\t\t\tpreviousVector,\n\t\t\t\t\tcurrentVector,\n\t\t\t\t\tcurrentVector,\n\n\t\t\t\t\tcurrentVector,\n\t\t\t\t\tpreviousVector,\n\t\t\t\t\tpreviousVector\n\t\t\t\t);\n\t\t\t\tintensities.push(\n\t\t\t\t\tpreviousIntensity,\n\t\t\t\t\tcurrentIntensity,\n\t\t\t\t\tcurrentIntensity,\n\n\t\t\t\t\tcurrentIntensity,\n\t\t\t\t\tpreviousIntensity,\n\t\t\t\t\tpreviousIntensity\n\t\t\t\t);\n\t\t\t\tfaces.push(\n\t\t\t\t\t[verts.length-6, verts.length-5, verts.length-4],\n\t\t\t\t\t[verts.length-3, verts.length-2, verts.length-1]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tvar tmp = previousVerts;\n\t\tpreviousVerts = currentVerts;\n\t\tcurrentVerts = tmp;\n\t\ttmp = previousVector;\n\t\tpreviousVector = currentVector;\n\t\tcurrentVector = tmp;\n\t\ttmp = previousIntensity;\n\t\tpreviousIntensity = currentIntensity;\n\t\tcurrentIntensity = tmp;\n\t}\n\treturn {\n\t\tpositions: verts,\n\t\tcells: faces,\n\t\tvectors: vectors,\n\t\tvertexIntensity: intensities\n\t};\n\n};\n\nvar createTubes = function(streams, colormap, maxDivergence, minDistance) {\n\n\tvar maxNorm = 0;\n\tfor (var i=0; i<streams.length; i++) {\n\t\tvar velocities = streams[i].velocities;\n\t\tfor (var j=0; j<velocities.length; j++) {\n\t\t\tvar norm = vec3.length(velocities[j]);\n\t\t\tif (norm > maxNorm) {\n\t\t\t\tmaxNorm = norm;\n\t\t\t}\n\t\t}\n\t}\n\n\tvar tubes = streams.map(function(s) {\n\t\treturn streamToTube(s, maxDivergence, minDistance, maxNorm);\n\t});\n\n\tvar positions = [];\n\tvar cells = [];\n\tvar vectors = [];\n\tvar vertexIntensity = [];\n\tfor (var i=0; i < tubes.length; i++) {\n\t\tvar tube = tubes[i];\n\t\tvar offset = positions.length;\n\t\tpositions = positions.concat(tube.positions);\n\t\tvectors = vectors.concat(tube.vectors);\n\t\tvertexIntensity = vertexIntensity.concat(tube.vertexIntensity);\n\t\tfor (var j=0; j<tube.cells.length; j++) {\n\t\t\tvar cell = tube.cells[j];\n\t\t\tvar newCell = [];\n\t\t\tcells.push(newCell);\n\t\t\tfor (var k=0; k<cell.length; k++) {\n\t\t\t\tnewCell.push(cell[k] + offset);\n\t\t\t}\n\t\t}\n\t}\n\treturn {\n\t\tpositions: positions,\n\t\tcells: cells,\n\t\tvectors: vectors,\n\t\tvertexIntensity: vertexIntensity,\n\t\tcolormap: colormap\n\t};\n};\n\nvar defaultGetDivergence = function(p, v0) {\n\tvar dp = vec3.create();\n\tvar e = 1/10000;\n\n\tvec3.add(dp, p, [e, 0, 0]);\n\tvar vx = this.getVelocity(dp);\n\tvec3.subtract(vx, vx, v0);\n\tvec3.scale(vx, vx, 1/e);\n\n\tvec3.add(dp, p, [0, e, 0]);\n\tvar vy = this.getVelocity(dp);\n\tvec3.subtract(vy, vy, v0);\n\tvec3.scale(vy, vy, 1/e);\n\n\tvec3.add(dp, p, [0, 0, e]);\n\tvar vz = this.getVelocity(dp);\n\tvec3.subtract(vz, vz, v0);\n\tvec3.scale(vz, vz, 1/e);\n\n\tvec3.add(dp, vx, vy);\n\tvec3.add(dp, dp, vz);\n\treturn dp;\n};\n\nvar defaultGetVelocity = function(p) {\n    var u = sampleMeshgrid(p, this.vectors, this.meshgrid, this.clampBorders);\n    return u;\n};\n\n\nvar findLastSmallerIndex = function(points, v) {\n  for (var i=0; i<points.length; i++) {\n  \tvar p = points[i];\n  \tif (p === v) return i;\n    if (p > v) return i-1;\n  }\n  return i;\n};\n\nvar tmp = vec3.create();\nvar tmp2 = vec3.create();\n\nvar clamp = function(v, min, max) {\n\treturn v < min ? min : (v > max ? max : v);\n};\n\nvar sampleMeshgrid = function(point, array, meshgrid, clampOverflow) {\n\tvar x = point[0];\n\tvar y = point[1];\n\tvar z = point[2];\n\n\tvar w = meshgrid[0].length;\n\tvar h = meshgrid[1].length;\n\tvar d = meshgrid[2].length;\n\n\t// Find the index of the nearest smaller value in the meshgrid for each coordinate of (x,y,z).\n\t// The nearest smaller value index for x is the index x0 such that\n\t// meshgrid[0][x0] < x and for all x1 > x0, meshgrid[0][x1] >= x.\n\tvar x0 = findLastSmallerIndex(meshgrid[0], x);\n\tvar y0 = findLastSmallerIndex(meshgrid[1], y);\n\tvar z0 = findLastSmallerIndex(meshgrid[2], z);\n\n\t// Get the nearest larger meshgrid value indices.\n\t// From the above \"nearest smaller value\", we know that\n\t//   meshgrid[0][x0] < x\n\t//   meshgrid[0][x0+1] >= x\n\tvar x1 = x0 + 1;\n\tvar y1 = y0 + 1;\n\tvar z1 = z0 + 1;\n\n\tif (meshgrid[0][x0] === x) x1 = x0;\n\tif (meshgrid[1][y0] === y) y1 = y0;\n\tif (meshgrid[2][z0] === z) z1 = z0;\n\n\tif (clampOverflow) {\n\t\tx0 = clamp(x0, 0, w-1);\n\t\tx1 = clamp(x1, 0, w-1);\n\t\ty0 = clamp(y0, 0, h-1);\n\t\ty1 = clamp(y1, 0, h-1);\n\t\tz0 = clamp(z0, 0, d-1);\n\t\tz1 = clamp(z1, 0, d-1);\n\t}\n\n\t// Reject points outside the meshgrid, return a zero vector.\n\tif (x0 < 0 || y0 < 0 || z0 < 0 || x1 >= w || y1 >= h || z1 >= d) {\n\t\treturn vec3.create();\n\t}\n\n\t// Normalize point coordinates to 0..1 scaling factor between x0 and x1.\n\tvar xf = (x - meshgrid[0][x0]) / (meshgrid[0][x1] - meshgrid[0][x0]);\n\tvar yf = (y - meshgrid[1][y0]) / (meshgrid[1][y1] - meshgrid[1][y0]);\n\tvar zf = (z - meshgrid[2][z0]) / (meshgrid[2][z1] - meshgrid[2][z0]);\n\n\tif (xf < 0 || xf > 1 || isNaN(xf)) xf = 0;\n\tif (yf < 0 || yf > 1 || isNaN(yf)) yf = 0;\n\tif (zf < 0 || zf > 1 || isNaN(zf)) zf = 0;\n\n\tvar z0off = z0*w*h;\n\tvar z1off = z1*w*h;\n\n\tvar y0off = y0*w;\n\tvar y1off = y1*w;\n\n\tvar x0off = x0;\n\tvar x1off = x1;\n\n\t// Sample data array around the (x,y,z) point.\n\t//  vZYX = array[zZoff + yYoff + xXoff]\n\tvar v000 = array[y0off + z0off + x0off];\n\tvar v001 = array[y0off + z0off + x1off];\n\tvar v010 = array[y1off + z0off + x0off];\n\tvar v011 = array[y1off + z0off + x1off];\n\tvar v100 = array[y0off + z1off + x0off];\n\tvar v101 = array[y0off + z1off + x1off];\n\tvar v110 = array[y1off + z1off + x0off];\n\tvar v111 = array[y1off + z1off + x1off];\n\n\tvar result = vec3.create();\n\n\t// Average samples according to distance to point.\n\tvec3.lerp(result, v000, v001, xf);\n\tvec3.lerp(tmp, v010, v011, xf);\n\tvec3.lerp(result, result, tmp, yf);\n\tvec3.lerp(tmp, v100, v101, xf);\n\tvec3.lerp(tmp2, v110, v111, xf);\n\tvec3.lerp(tmp, tmp, tmp2, yf);\n\tvec3.lerp(result, result, tmp, zf);\n\n\treturn result;\n};\n\n\nvar vabs = function(dst, v) {\n\tvar x = v[0];\n\tvar y = v[1];\n\tvar z = v[2];\n\tdst[0] = x >= 0 ? x : -x;\n\tdst[1] = y >= 0 ? y : -y;\n\tdst[2] = z >= 0 ? z : -z;\n\treturn dst;\n};\n\nvar findMinSeparation = function(xs) {\n\tvar minSeparation = 1/0;\n\txs.sort(function(a, b) { return a - b; });\n\tfor (var i=1; i<xs.length; i++) {\n\t\tvar d = Math.abs(xs[i] - xs[i-1]);\n\t\tif (d < minSeparation) {\n\t\t\tminSeparation = d;\n\t\t}\n\t}\n\treturn minSeparation;\n};\n\n// Finds the minimum per-component distance in positions.\n// \nvar calculateMinPositionDistance = function(positions) {\n\tvar xs = [], ys = [], zs = [];\n\tvar xi = {}, yi = {}, zi = {};\n\tfor (var i=0; i<positions.length; i++) {\n\t\tvar p = positions[i];\n\t\tvar x = p[0], y = p[1], z = p[2];\n\n\t\t// Split the positions array into arrays of unique component values.\n\t\t//\n\t\t// Why go through the trouble of using a uniqueness hash table vs\n\t\t// sort and uniq: \n\t\t//\n\t\t// Suppose you've got a million positions in a 100x100x100 grid.\n\t\t//\n\t\t// Using a uniqueness hash table, you're doing 1M array reads, \n\t\t// 3M hash table lookups from 100-element hashes, 300 hash table inserts, then\n\t\t// sorting three 100-element arrays and iterating over them.\n\t\t// Roughly, 1M + 3M * ln(100) + 300 * ln(100/2) + 3 * 100 * ln(100) + 3 * 100 = \n\t\t//          1M + 13.8M + 0.0012M +  0.0014M + 0.0003M \n\t\t//          =~ 15M\n\t\t//\n\t\t// Sort and uniq solution would do 1M array reads, 3M array inserts,\n\t\t// sort three 1M-element arrays and iterate over them.\n\t\t// Roughly, 1M + 3M + 3 * 1M * ln(1M) + 3 * 1M = \n\t\t//          1M + 3M + 41.4M + 3M \n\t\t//          =~ 48.4M\n\t\t//\n\t\t// Guessing that a hard-coded sort & uniq would be faster due to not having\n\t\t// to run a hashing function on everything. More memory usage though \n\t\t// (bunch of small hash tables vs. duplicating the input array.)\n\t\t//\n\t\t// In JS-land, who knows. Maybe xi[x] casts x to string and destroys perf, \n\t\t// maybe numeric keys get special-cased, maybe the object lookups run at near O(1)-speeds.\n\t\t// Maybe the sorting comparison function is expensive to call, maybe it gets inlined or special-cased.\n\t\t//\n\t\t// ... You're probably not going to call this with more than 10k positions anyhow, so this is very academic.\n\t\t//\n\t\tif (!xi[x]) {\n\t\t\txs.push(x);\n\t\t\txi[x] = true;\n\t\t}\n\t\tif (!yi[y]) {\n\t\t\tys.push(y);\n\t\t\tyi[y] = true;\n\t\t}\n\t\tif (!zi[z]) {\n\t\t\tzs.push(z);\n\t\t\tzi[z] = true;\n\t\t}\n\t}\n\tvar xSep = findMinSeparation(xs);\n\tvar ySep = findMinSeparation(ys);\n\tvar zSep = findMinSeparation(zs);\n\tvar minSeparation = Math.min(xSep, ySep, zSep);\n\tif (!isFinite(minSeparation)) {\n\t\treturn 1;\n\t}\n\treturn minSeparation;\n};\n\nmodule.exports = function(vectorField, bounds) {\n\tvar positions = vectorField.startingPositions;\n\tvar maxLength = vectorField.maxLength || 1000;\n\tvar tubeSize = vectorField.tubeSize || 1;\n\tvar absoluteTubeSize = vectorField.absoluteTubeSize;\n\n\tif (!vectorField.getDivergence) {\n\t\tvectorField.getDivergence = defaultGetDivergence;\n\t}\n\n\tif (!vectorField.getVelocity) {\n\t\tvectorField.getVelocity = defaultGetVelocity;\n\t}\n\n\tif (vectorField.clampBorders === undefined) {\n\t\tvectorField.clampBorders = true;\n\t}\n\n\tvar streams = [];\n\n\tvar minX = bounds[0][0], minY = bounds[0][1], minZ = bounds[0][2];\n\tvar maxX = bounds[1][0], maxY = bounds[1][1], maxZ = bounds[1][2];\n\n\tvar inBounds = function(bounds, p) {\n\t\tvar x = p[0];\n\t\tvar y = p[1];\n\t\tvar z = p[2];\n\t\treturn (\n\t\t\tx >= minX && x <= maxX &&\n\t\t\ty >= minY && y <= maxY &&\n\t\t\tz >= minZ && z <= maxZ\n\t\t);\n\t};\n\n\tvar boundsSize = vec3.distance(bounds[0], bounds[1]);\n\tvar maxStepSize = 10 * boundsSize / maxLength;\n\tvar maxStepSizeSq = maxStepSize * maxStepSize;\n\n\tvar minDistance = 1;\n\tvar maxDivergence = 0; // For component-wise divergence vec3.create();\n\tvar tmp = vec3.create();\n\n\tif (positions.length >= 2) {\n\t\tminDistance = calculateMinPositionDistance(positions);\n\t}\n\n\tfor (var i = 0; i < positions.length; i++) {\n\t\tvar p = vec3.create();\n\t\tvec3.copy(p, positions[i]);\n\n\t\tvar stream = [p];\n\t\tvar velocities = [];\n\t\tvar v = vectorField.getVelocity(p);\n\t\tvar op = p;\n\t\tvelocities.push(v);\n\n\t\tvar divergences = [];\n\n\t\tvar dv = vectorField.getDivergence(p, v);\n\t\tvar dvLength = vec3.length(dv);\n\t\tif (dvLength > maxDivergence && !isNaN(dvLength) && isFinite(dvLength)) {\n\t\t\tmaxDivergence = dvLength;\n\t\t}\n\t\t// In case we need to do component-wise divergence visualization\n\t\t// vec3.max(maxDivergence, maxDivergence, vabs(tmp, dv));\n\t\tdivergences.push(dvLength);\n\n\t\tstreams.push({points: stream, velocities: velocities, divergences: divergences});\n\n\t\tvar j = 0;\n\n\t\twhile (j < maxLength * 100 && stream.length < maxLength && inBounds(bounds, p)) {\n\t\t\tj++;\n\t\t\tvar np = vec3.clone(v);\n\t\t\tvar sqLen = vec3.squaredLength(np);\n\t\t\tif (sqLen === 0) {\n\t\t\t\tbreak;\n\t\t\t} else if (sqLen > maxStepSizeSq) {\n\t\t\t\tvec3.scale(np, np, maxStepSize / Math.sqrt(sqLen));\n\t\t\t}\n\t\t\tvec3.add(np, np, p);\n\n\t\t\tv = vectorField.getVelocity(np);\n\n\t\t\tif (vec3.squaredDistance(op, np) - maxStepSizeSq > -0.0001 * maxStepSizeSq) {\n\t\t\t\tstream.push(np);\n\t\t\t\top = np;\n\t\t\t\tvelocities.push(v);\n\t\t\t\tvar dv = vectorField.getDivergence(np, v);\n\t\t\t\tvar dvLength = vec3.length(dv);\n\t\t\t\tif (dvLength > maxDivergence && !isNaN(dvLength) && isFinite(dvLength)) {\n\t\t\t\t\tmaxDivergence = dvLength;\n\t\t\t\t}\n\t\t\t\t// In case we need to do component-wise divergence visualization\n\t\t\t\t//vec3.max(maxDivergence, maxDivergence, vabs(tmp, dv));\n\t\t\t\tdivergences.push(dvLength);\n\t\t\t}\n\n\t\t\tp = np;\n\t\t}\n\t}\n\n\t// Replace NaNs and Infinities with non-NaN, finite maxDivergence\n\tfor (var i=0; i<divergences.length; i++) {\n\t\tvar dvLength = divergences[i];\n\t\tif (isNaN(dvLength) || !isFinite(dvLength)) {\n\t\t\tdivergences[i] = maxDivergence;\n\t\t}\n\t}\n\n\tvar tubes = createTubes(streams, vectorField.colormap, maxDivergence, minDistance);\n\n\tif (absoluteTubeSize) {\n\t\ttubes.tubeScale = absoluteTubeSize;\n\t} else {\n\t\t// Avoid division by zero.\n\t\tif (maxDivergence === 0) {\n\t\t\tmaxDivergence = 1;\n\t\t}\n\t\ttubes.tubeScale = tubeSize * 0.5 * minDistance / maxDivergence;\n\t}\n\n\treturn tubes;\n};\n\nmodule.exports.createTubeMesh = _dereq_('./lib/tubemesh');\n\n},{\"./lib/tubemesh\":312,\"gl-vec3\":346,\"gl-vec4\":382}],314:[function(_dereq_,module,exports){\nvar createShader = _dereq_('gl-shader')\nvar glslify = _dereq_('glslify')\n\nvar vertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec4 uv;\\nattribute vec3 f;\\nattribute vec3 normal;\\n\\nuniform vec3 objectOffset;\\nuniform mat4 model, view, projection, inverseModel;\\nuniform vec3 lightPosition, eyePosition;\\nuniform sampler2D colormap;\\n\\nvarying float value, kill;\\nvarying vec3 worldCoordinate;\\nvarying vec2 planeCoordinate;\\nvarying vec3 lightDirection, eyeDirection, surfaceNormal;\\nvarying vec4 vColor;\\n\\nvoid main() {\\n  vec3 localCoordinate = vec3(uv.zw, f.x);\\n  worldCoordinate = objectOffset + localCoordinate;\\n  vec4 worldPosition = model * vec4(worldCoordinate, 1.0);\\n  vec4 clipPosition = projection * view * worldPosition;\\n  gl_Position = clipPosition;\\n  kill = f.y;\\n  value = f.z;\\n  planeCoordinate = uv.xy;\\n\\n  vColor = texture2D(colormap, vec2(value, value));\\n\\n  //Lighting geometry parameters\\n  vec4 cameraCoordinate = view * worldPosition;\\n  cameraCoordinate.xyz /= cameraCoordinate.w;\\n  lightDirection = lightPosition - cameraCoordinate.xyz;\\n  eyeDirection   = eyePosition - cameraCoordinate.xyz;\\n  surfaceNormal  = normalize((vec4(normal,0) * inverseModel).xyz);\\n}\\n\"])\nvar fragSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nfloat beckmannDistribution(float x, float roughness) {\\n  float NdotH = max(x, 0.0001);\\n  float cos2Alpha = NdotH * NdotH;\\n  float tan2Alpha = (cos2Alpha - 1.0) / cos2Alpha;\\n  float roughness2 = roughness * roughness;\\n  float denom = 3.141592653589793 * roughness2 * cos2Alpha * cos2Alpha;\\n  return exp(tan2Alpha / roughness2) / denom;\\n}\\n\\nfloat beckmannSpecular(\\n  vec3 lightDirection,\\n  vec3 viewDirection,\\n  vec3 surfaceNormal,\\n  float roughness) {\\n  return beckmannDistribution(dot(surfaceNormal, normalize(lightDirection + viewDirection)), roughness);\\n}\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec3 lowerBound, upperBound;\\nuniform float contourTint;\\nuniform vec4 contourColor;\\nuniform sampler2D colormap;\\nuniform vec3 clipBounds[2];\\nuniform float roughness, fresnel, kambient, kdiffuse, kspecular, opacity;\\nuniform float vertexColor;\\n\\nvarying float value, kill;\\nvarying vec3 worldCoordinate;\\nvarying vec3 lightDirection, eyeDirection, surfaceNormal;\\nvarying vec4 vColor;\\n\\nvoid main() {\\n  if ((kill > 0.0) ||\\n      (outOfRange(clipBounds[0], clipBounds[1], worldCoordinate))) discard;\\n\\n  vec3 N = normalize(surfaceNormal);\\n  vec3 V = normalize(eyeDirection);\\n  vec3 L = normalize(lightDirection);\\n\\n  if(gl_FrontFacing) {\\n    N = -N;\\n  }\\n\\n  float specular = max(beckmannSpecular(L, V, N, roughness), 0.);\\n  float diffuse  = min(kambient + kdiffuse * max(dot(N, L), 0.0), 1.0);\\n\\n  //decide how to interpolate color — in vertex or in fragment\\n  vec4 surfaceColor =\\n    step(vertexColor, .5) * texture2D(colormap, vec2(value, value)) +\\n    step(.5, vertexColor) * vColor;\\n\\n  vec4 litColor = surfaceColor.a * vec4(diffuse * surfaceColor.rgb + kspecular * vec3(1,1,1) * specular,  1.0);\\n\\n  gl_FragColor = mix(litColor, contourColor, contourTint) * opacity;\\n}\\n\"])\nvar contourVertSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec4 uv;\\nattribute float f;\\n\\nuniform vec3 objectOffset;\\nuniform mat3 permutation;\\nuniform mat4 model, view, projection;\\nuniform float height, zOffset;\\nuniform sampler2D colormap;\\n\\nvarying float value, kill;\\nvarying vec3 worldCoordinate;\\nvarying vec2 planeCoordinate;\\nvarying vec3 lightDirection, eyeDirection, surfaceNormal;\\nvarying vec4 vColor;\\n\\nvoid main() {\\n  vec3 dataCoordinate = permutation * vec3(uv.xy, height);\\n  worldCoordinate = objectOffset + dataCoordinate;\\n  vec4 worldPosition = model * vec4(worldCoordinate, 1.0);\\n\\n  vec4 clipPosition = projection * view * worldPosition;\\n  clipPosition.z += zOffset;\\n\\n  gl_Position = clipPosition;\\n  value = f + objectOffset.z;\\n  kill = -1.0;\\n  planeCoordinate = uv.zw;\\n\\n  vColor = texture2D(colormap, vec2(value, value));\\n\\n  //Don't do lighting for contours\\n  surfaceNormal   = vec3(1,0,0);\\n  eyeDirection    = vec3(0,1,0);\\n  lightDirection  = vec3(0,0,1);\\n}\\n\"])\nvar pickSrc = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nbool outOfRange(float a, float b, float p) {\\n  return ((p > max(a, b)) || \\n          (p < min(a, b)));\\n}\\n\\nbool outOfRange(vec2 a, vec2 b, vec2 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y));\\n}\\n\\nbool outOfRange(vec3 a, vec3 b, vec3 p) {\\n  return (outOfRange(a.x, b.x, p.x) ||\\n          outOfRange(a.y, b.y, p.y) ||\\n          outOfRange(a.z, b.z, p.z));\\n}\\n\\nbool outOfRange(vec4 a, vec4 b, vec4 p) {\\n  return outOfRange(a.xyz, b.xyz, p.xyz);\\n}\\n\\nuniform vec2 shape;\\nuniform vec3 clipBounds[2];\\nuniform float pickId;\\n\\nvarying float value, kill;\\nvarying vec3 worldCoordinate;\\nvarying vec2 planeCoordinate;\\nvarying vec3 surfaceNormal;\\n\\nvec2 splitFloat(float v) {\\n  float vh = 255.0 * v;\\n  float upper = floor(vh);\\n  float lower = fract(vh);\\n  return vec2(upper / 255.0, floor(lower * 16.0) / 16.0);\\n}\\n\\nvoid main() {\\n  if ((kill > 0.0) ||\\n      (outOfRange(clipBounds[0], clipBounds[1], worldCoordinate))) discard;\\n\\n  vec2 ux = splitFloat(planeCoordinate.x / shape.x);\\n  vec2 uy = splitFloat(planeCoordinate.y / shape.y);\\n  gl_FragColor = vec4(pickId, ux.x, uy.x, ux.y + (uy.y/16.0));\\n}\\n\"])\n\nexports.createShader = function (gl) {\n  var shader = createShader(gl, vertSrc, fragSrc, null, [\n    {name: 'uv', type: 'vec4'},\n    {name: 'f', type: 'vec3'},\n    {name: 'normal', type: 'vec3'}\n  ])\n  shader.attributes.uv.location = 0\n  shader.attributes.f.location = 1\n  shader.attributes.normal.location = 2\n  return shader\n}\nexports.createPickShader = function (gl) {\n  var shader = createShader(gl, vertSrc, pickSrc, null, [\n    {name: 'uv', type: 'vec4'},\n    {name: 'f', type: 'vec3'},\n    {name: 'normal', type: 'vec3'}\n  ])\n  shader.attributes.uv.location = 0\n  shader.attributes.f.location = 1\n  shader.attributes.normal.location = 2\n  return shader\n}\nexports.createContourShader = function (gl) {\n  var shader = createShader(gl, contourVertSrc, fragSrc, null, [\n    {name: 'uv', type: 'vec4'},\n    {name: 'f', type: 'float'}\n  ])\n  shader.attributes.uv.location = 0\n  shader.attributes.f.location = 1\n  return shader\n}\nexports.createPickContourShader = function (gl) {\n  var shader = createShader(gl, contourVertSrc, pickSrc, null, [\n    {name: 'uv', type: 'vec4'},\n    {name: 'f', type: 'float'}\n  ])\n  shader.attributes.uv.location = 0\n  shader.attributes.f.location = 1\n  return shader\n}\n\n},{\"gl-shader\":301,\"glslify\":409}],315:[function(_dereq_,module,exports){\narguments[4][111][0].apply(exports,arguments)\n},{\"dup\":111}],316:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createSurfacePlot\n\nvar bits = _dereq_('bit-twiddle')\nvar createBuffer = _dereq_('gl-buffer')\nvar createVAO = _dereq_('gl-vao')\nvar createTexture = _dereq_('gl-texture2d')\nvar pool = _dereq_('typedarray-pool')\nvar colormap = _dereq_('colormap')\nvar ops = _dereq_('ndarray-ops')\nvar pack = _dereq_('ndarray-pack')\nvar ndarray = _dereq_('ndarray')\nvar surfaceNets = _dereq_('surface-nets')\nvar multiply = _dereq_('gl-mat4/multiply')\nvar invert = _dereq_('gl-mat4/invert')\nvar bsearch = _dereq_('binary-search-bounds')\nvar gradient = _dereq_('ndarray-gradient')\nvar shaders = _dereq_('./lib/shaders')\n\nvar createShader = shaders.createShader\nvar createContourShader = shaders.createContourShader\nvar createPickShader = shaders.createPickShader\nvar createPickContourShader = shaders.createPickContourShader\n\nvar SURFACE_VERTEX_SIZE = 4 * (4 + 3 + 3)\n\nvar IDENTITY = [\n  1, 0, 0, 0,\n  0, 1, 0, 0,\n  0, 0, 1, 0,\n  0, 0, 0, 1 ]\n\nvar QUAD = [\n  [0, 0],\n  [0, 1],\n  [1, 0],\n  [1, 1],\n  [1, 0],\n  [0, 1]\n]\n\nvar PERMUTATIONS = [\n  [0, 0, 0, 0, 0, 0, 0, 0, 0],\n  [0, 0, 0, 0, 0, 0, 0, 0, 0],\n  [0, 0, 0, 0, 0, 0, 0, 0, 0]\n]\n\n;(function () {\n  for (var i = 0; i < 3; ++i) {\n    var p = PERMUTATIONS[i]\n    var u = (i + 1) % 3\n    var v = (i + 2) % 3\n    p[u + 0] = 1\n    p[v + 3] = 1\n    p[i + 6] = 1\n  }\n})()\n\nfunction SurfacePickResult (position, index, uv, level, dataCoordinate) {\n  this.position = position\n  this.index = index\n  this.uv = uv\n  this.level = level\n  this.dataCoordinate = dataCoordinate\n}\n\nvar N_COLORS = 256\n\nfunction genColormap (name) {\n  var x = pack([colormap({\n    colormap: name,\n    nshades: N_COLORS,\n    format: 'rgba'\n  }).map(function (c) {\n    return [c[0], c[1], c[2], 255 * c[3]]\n  })])\n  ops.divseq(x, 255.0)\n  return x\n}\n\nfunction SurfacePlot (\n  gl,\n  shape,\n  bounds,\n  shader,\n  pickShader,\n  coordinates,\n  vao,\n  colorMap,\n  contourShader,\n  contourPickShader,\n  contourBuffer,\n  contourVAO,\n  dynamicBuffer,\n  dynamicVAO,\n  objectOffset) {\n  this.gl = gl\n  this.shape = shape\n  this.bounds = bounds\n  this.objectOffset = objectOffset\n  this.intensityBounds = []\n\n  this._shader = shader\n  this._pickShader = pickShader\n  this._coordinateBuffer = coordinates\n  this._vao = vao\n  this._colorMap = colorMap\n\n  this._contourShader = contourShader\n  this._contourPickShader = contourPickShader\n  this._contourBuffer = contourBuffer\n  this._contourVAO = contourVAO\n  this._contourOffsets = [[], [], []]\n  this._contourCounts = [[], [], []]\n  this._vertexCount = 0\n\n  this._pickResult = new SurfacePickResult([0, 0, 0], [0, 0], [0, 0], [0, 0, 0], [0, 0, 0])\n\n  this._dynamicBuffer = dynamicBuffer\n  this._dynamicVAO = dynamicVAO\n  this._dynamicOffsets = [0, 0, 0]\n  this._dynamicCounts = [0, 0, 0]\n\n  this.contourWidth = [ 1, 1, 1 ]\n  this.contourLevels = [[1], [1], [1]]\n  this.contourTint = [0, 0, 0]\n  this.contourColor = [[0.5, 0.5, 0.5, 1], [0.5, 0.5, 0.5, 1], [0.5, 0.5, 0.5, 1]]\n\n  this.showContour = true\n  this.showSurface = true\n\n  this.enableHighlight = [true, true, true]\n  this.highlightColor = [[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1]]\n  this.highlightTint = [ 1, 1, 1 ]\n  this.highlightLevel = [-1, -1, -1]\n\n  // Dynamic contour options\n  this.enableDynamic = [ true, true, true ]\n  this.dynamicLevel = [ NaN, NaN, NaN ]\n  this.dynamicColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ]\n  this.dynamicTint = [ 1, 1, 1 ]\n  this.dynamicWidth = [ 1, 1, 1 ]\n\n  this.axesBounds = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]]\n  this.surfaceProject = [ false, false, false ]\n  this.contourProject = [[ false, false, false ],\n    [ false, false, false ],\n    [ false, false, false ]]\n\n  this.colorBounds = [ false, false ]\n\n  // Store xyz fields, need this for picking\n  this._field = [\n    ndarray(pool.mallocFloat(1024), [0, 0]),\n    ndarray(pool.mallocFloat(1024), [0, 0]),\n    ndarray(pool.mallocFloat(1024), [0, 0]) ]\n\n  this.pickId = 1\n  this.clipBounds = [[-Infinity, -Infinity, -Infinity], [Infinity, Infinity, Infinity]]\n\n  this.snapToData = false\n\n  this.pixelRatio = 1\n\n  this.opacity = 1.0\n\n  this.lightPosition = [10, 10000, 0]\n  this.ambientLight = 0.8\n  this.diffuseLight = 0.8\n  this.specularLight = 2.0\n  this.roughness = 0.5\n  this.fresnel = 1.5\n  this.vertexColor = 0\n\n  this.dirty = true\n}\n\nvar proto = SurfacePlot.prototype\n\nproto.isTransparent = function () {\n  return this.opacity < 1\n}\n\nproto.isOpaque = function () {\n  if (this.opacity >= 1) {\n    return true\n  }\n  for (var i = 0; i < 3; ++i) {\n    if (this._contourCounts[i].length > 0 || this._dynamicCounts[i] > 0) {\n      return true\n    }\n  }\n  return false\n}\n\nproto.pickSlots = 1\n\nproto.setPickBase = function (id) {\n  this.pickId = id\n}\n\nvar ZERO_VEC = [0, 0, 0]\n\nvar PROJECT_DATA = {\n  showSurface: false,\n  showContour: false,\n  projections: [IDENTITY.slice(), IDENTITY.slice(), IDENTITY.slice()],\n  clipBounds: [\n    [[0, 0, 0], [0, 0, 0]],\n    [[0, 0, 0], [0, 0, 0]],\n    [[0, 0, 0], [0, 0, 0]]]\n}\n\nfunction computeProjectionData (camera, obj) {\n  var i, j, k\n\n  // Compute cube properties\n  var cubeAxis = (obj.axes && obj.axes.lastCubeProps.axis) || ZERO_VEC\n\n  var showSurface = obj.showSurface\n  var showContour = obj.showContour\n\n  for (i = 0; i < 3; ++i) {\n    showSurface = showSurface || obj.surfaceProject[i]\n    for (j = 0; j < 3; ++j) {\n      showContour = showContour || obj.contourProject[i][j]\n    }\n  }\n\n  for (i = 0; i < 3; ++i) {\n    // Construct projection onto axis\n    var axisSquish = PROJECT_DATA.projections[i]\n    for (j = 0; j < 16; ++j) {\n      axisSquish[j] = 0\n    }\n    for (j = 0; j < 4; ++j) {\n      axisSquish[5 * j] = 1\n    }\n    axisSquish[5 * i] = 0\n    axisSquish[12 + i] = obj.axesBounds[+(cubeAxis[i] > 0)][i]\n    multiply(axisSquish, camera.model, axisSquish)\n\n    var nclipBounds = PROJECT_DATA.clipBounds[i]\n    for (k = 0; k < 2; ++k) {\n      for (j = 0; j < 3; ++j) {\n        nclipBounds[k][j] = camera.clipBounds[k][j]\n      }\n    }\n    nclipBounds[0][i] = -1e8\n    nclipBounds[1][i] = 1e8\n  }\n\n  PROJECT_DATA.showSurface = showSurface\n  PROJECT_DATA.showContour = showContour\n\n  return PROJECT_DATA\n}\n\nvar UNIFORMS = {\n  model: IDENTITY,\n  view: IDENTITY,\n  projection: IDENTITY,\n  inverseModel: IDENTITY.slice(),\n  lowerBound: [0, 0, 0],\n  upperBound: [0, 0, 0],\n  colorMap: 0,\n  clipBounds: [[0, 0, 0], [0, 0, 0]],\n  height: 0.0,\n  contourTint: 0,\n  contourColor: [0, 0, 0, 1],\n  permutation: [1, 0, 0, 0, 1, 0, 0, 0, 1],\n  zOffset: -1e-4,\n  objectOffset: [0, 0, 0],\n  kambient: 1,\n  kdiffuse: 1,\n  kspecular: 1,\n  lightPosition: [1000, 1000, 1000],\n  eyePosition: [0, 0, 0],\n  roughness: 1,\n  fresnel: 1,\n  opacity: 1,\n  vertexColor: 0\n}\n\nvar MATRIX_INVERSE = IDENTITY.slice()\nvar DEFAULT_PERM = [1, 0, 0, 0, 1, 0, 0, 0, 1]\n\nfunction drawCore (params, transparent) {\n  params = params || {}\n  var gl = this.gl\n\n  gl.disable(gl.CULL_FACE)\n\n  this._colorMap.bind(0)\n\n  var uniforms = UNIFORMS\n  uniforms.model = params.model || IDENTITY\n  uniforms.view = params.view || IDENTITY\n  uniforms.projection = params.projection || IDENTITY\n  uniforms.lowerBound = [this.bounds[0][0], this.bounds[0][1], this.colorBounds[0] || this.bounds[0][2]]\n  uniforms.upperBound = [this.bounds[1][0], this.bounds[1][1], this.colorBounds[1] || this.bounds[1][2]]\n  uniforms.objectOffset = this.objectOffset\n  uniforms.contourColor = this.contourColor[0]\n\n  uniforms.inverseModel = invert(uniforms.inverseModel, uniforms.model)\n\n  for (var i = 0; i < 2; ++i) {\n    var clipClamped = uniforms.clipBounds[i]\n    for (var j = 0; j < 3; ++j) {\n      clipClamped[j] = Math.min(Math.max(this.clipBounds[i][j], -1e8), 1e8)\n    }\n  }\n\n  uniforms.kambient = this.ambientLight\n  uniforms.kdiffuse = this.diffuseLight\n  uniforms.kspecular = this.specularLight\n\n  uniforms.roughness = this.roughness\n  uniforms.fresnel = this.fresnel\n  uniforms.opacity = this.opacity\n\n  uniforms.height = 0.0\n  uniforms.permutation = DEFAULT_PERM\n\n  uniforms.vertexColor = this.vertexColor\n\n  // Compute camera matrix inverse\n  var invCameraMatrix = MATRIX_INVERSE\n  multiply(invCameraMatrix, uniforms.view, uniforms.model)\n  multiply(invCameraMatrix, uniforms.projection, invCameraMatrix)\n  invert(invCameraMatrix, invCameraMatrix)\n\n  for (i = 0; i < 3; ++i) {\n    uniforms.eyePosition[i] = invCameraMatrix[12 + i] / invCameraMatrix[15]\n  }\n\n  var w = invCameraMatrix[15]\n  for (i = 0; i < 3; ++i) {\n    w += this.lightPosition[i] * invCameraMatrix[4 * i + 3]\n  }\n  for (i = 0; i < 3; ++i) {\n    var s = invCameraMatrix[12 + i]\n    for (j = 0; j < 3; ++j) {\n      s += invCameraMatrix[4 * j + i] * this.lightPosition[j]\n    }\n    uniforms.lightPosition[i] = s / w\n  }\n\n  var projectData = computeProjectionData(uniforms, this)\n\n  if (projectData.showSurface && (transparent === (this.opacity < 1))) {\n    // Set up uniforms\n    this._shader.bind()\n    this._shader.uniforms = uniforms\n\n    // Draw it\n    this._vao.bind()\n\n    if (this.showSurface && this._vertexCount) {\n      this._vao.draw(gl.TRIANGLES, this._vertexCount)\n    }\n\n    // Draw projections of surface\n    for (i = 0; i < 3; ++i) {\n      if (!this.surfaceProject[i] || !this.vertexCount) {\n        continue\n      }\n      this._shader.uniforms.model = projectData.projections[i]\n      this._shader.uniforms.clipBounds = projectData.clipBounds[i]\n      this._vao.draw(gl.TRIANGLES, this._vertexCount)\n    }\n\n    this._vao.unbind()\n  }\n\n  if (projectData.showContour && !transparent) {\n    var shader = this._contourShader\n\n    // Don't apply lighting to contours\n    uniforms.kambient = 1.0\n    uniforms.kdiffuse = 0.0\n    uniforms.kspecular = 0.0\n    uniforms.opacity = 1.0\n\n    shader.bind()\n    shader.uniforms = uniforms\n\n    // Draw contour lines\n    var vao = this._contourVAO\n    vao.bind()\n\n    // Draw contour levels\n    for (i = 0; i < 3; ++i) {\n      shader.uniforms.permutation = PERMUTATIONS[i]\n      gl.lineWidth(this.contourWidth[i] * this.pixelRatio)\n\n      for (j = 0; j < this.contourLevels[i].length; ++j) {\n        if (j === this.highlightLevel[i]) {\n          shader.uniforms.contourColor = this.highlightColor[i]\n          shader.uniforms.contourTint = this.highlightTint[i]\n        } else if (j === 0 || (j - 1) === this.highlightLevel[i]) {\n          shader.uniforms.contourColor = this.contourColor[i]\n          shader.uniforms.contourTint = this.contourTint[i]\n        }\n        if (!this._contourCounts[i][j]) {\n          continue\n        }\n\n        shader.uniforms.height = this.contourLevels[i][j]\n        vao.draw(gl.LINES, this._contourCounts[i][j], this._contourOffsets[i][j])\n      }\n    }\n\n    // Draw projections of surface\n    for (i = 0; i < 3; ++i) {\n      shader.uniforms.model = projectData.projections[i]\n      shader.uniforms.clipBounds = projectData.clipBounds[i]\n      for (j = 0; j < 3; ++j) {\n        if (!this.contourProject[i][j]) {\n          continue\n        }\n        shader.uniforms.permutation = PERMUTATIONS[j]\n        gl.lineWidth(this.contourWidth[j] * this.pixelRatio)\n        for (var k = 0; k < this.contourLevels[j].length; ++k) {\n          if (k === this.highlightLevel[j]) {\n            shader.uniforms.contourColor = this.highlightColor[j]\n            shader.uniforms.contourTint = this.highlightTint[j]\n          } else if (k === 0 || (k - 1) === this.highlightLevel[j]) {\n            shader.uniforms.contourColor = this.contourColor[j]\n            shader.uniforms.contourTint = this.contourTint[j]\n          }\n          if (!this._contourCounts[j][k]) {\n            continue\n          }\n\n          shader.uniforms.height = this.contourLevels[j][k]\n          vao.draw(gl.LINES, this._contourCounts[j][k], this._contourOffsets[j][k])\n        }\n      }\n    }\n\n    vao.unbind()\n\n    // Draw dynamic contours\n    vao = this._dynamicVAO\n    vao.bind()\n\n    // Draw contour levels\n    for (i = 0; i < 3; ++i) {\n      if (this._dynamicCounts[i] === 0) {\n        continue\n      }\n\n      shader.uniforms.model = uniforms.model\n      shader.uniforms.clipBounds = uniforms.clipBounds\n      shader.uniforms.permutation = PERMUTATIONS[i]\n      gl.lineWidth(this.dynamicWidth[i] * this.pixelRatio)\n\n      shader.uniforms.contourColor = this.dynamicColor[i]\n      shader.uniforms.contourTint = this.dynamicTint[i]\n      shader.uniforms.height = this.dynamicLevel[i]\n      vao.draw(gl.LINES, this._dynamicCounts[i], this._dynamicOffsets[i])\n\n      for (j = 0; j < 3; ++j) {\n        if (!this.contourProject[j][i]) {\n          continue\n        }\n\n        shader.uniforms.model = projectData.projections[j]\n        shader.uniforms.clipBounds = projectData.clipBounds[j]\n        vao.draw(gl.LINES, this._dynamicCounts[i], this._dynamicOffsets[i])\n      }\n    }\n\n    vao.unbind()\n  }\n}\n\nproto.draw = function (params) {\n  return drawCore.call(this, params, false)\n}\n\nproto.drawTransparent = function (params) {\n  return drawCore.call(this, params, true)\n}\n\nvar PICK_UNIFORMS = {\n  model: IDENTITY,\n  view: IDENTITY,\n  projection: IDENTITY,\n  inverseModel: IDENTITY,\n  clipBounds: [[0, 0, 0], [0, 0, 0]],\n  height: 0.0,\n  shape: [0, 0],\n  pickId: 0,\n  lowerBound: [0, 0, 0],\n  upperBound: [0, 0, 0],\n  zOffset: 0.0,\n  objectOffset: [0, 0, 0],\n  permutation: [1, 0, 0, 0, 1, 0, 0, 0, 1],\n  lightPosition: [0, 0, 0],\n  eyePosition: [0, 0, 0]\n}\n\nproto.drawPick = function (params) {\n  params = params || {}\n  var gl = this.gl\n  gl.disable(gl.CULL_FACE)\n\n  var uniforms = PICK_UNIFORMS\n  uniforms.model = params.model || IDENTITY\n  uniforms.view = params.view || IDENTITY\n  uniforms.projection = params.projection || IDENTITY\n  uniforms.shape = this._field[2].shape\n  uniforms.pickId = this.pickId / 255.0\n  uniforms.lowerBound = this.bounds[0]\n  uniforms.upperBound = this.bounds[1]\n  uniforms.objectOffset = this.objectOffset\n  uniforms.permutation = DEFAULT_PERM\n\n  for (var i = 0; i < 2; ++i) {\n    var clipClamped = uniforms.clipBounds[i]\n    for (var j = 0; j < 3; ++j) {\n      clipClamped[j] = Math.min(Math.max(this.clipBounds[i][j], -1e8), 1e8)\n    }\n  }\n\n  var projectData = computeProjectionData(uniforms, this)\n\n  if (projectData.showSurface) {\n    // Set up uniforms\n    this._pickShader.bind()\n    this._pickShader.uniforms = uniforms\n\n    // Draw it\n    this._vao.bind()\n    this._vao.draw(gl.TRIANGLES, this._vertexCount)\n\n    // Draw projections of surface\n    for (i = 0; i < 3; ++i) {\n      if (!this.surfaceProject[i]) {\n        continue\n      }\n      this._pickShader.uniforms.model = projectData.projections[i]\n      this._pickShader.uniforms.clipBounds = projectData.clipBounds[i]\n      this._vao.draw(gl.TRIANGLES, this._vertexCount)\n    }\n\n    this._vao.unbind()\n  }\n\n  if (projectData.showContour) {\n    var shader = this._contourPickShader\n\n    shader.bind()\n    shader.uniforms = uniforms\n\n    var vao = this._contourVAO\n    vao.bind()\n\n    for (j = 0; j < 3; ++j) {\n      gl.lineWidth(this.contourWidth[j] * this.pixelRatio)\n      shader.uniforms.permutation = PERMUTATIONS[j]\n      for (i = 0; i < this.contourLevels[j].length; ++i) {\n        if (this._contourCounts[j][i]) {\n          shader.uniforms.height = this.contourLevels[j][i]\n          vao.draw(gl.LINES, this._contourCounts[j][i], this._contourOffsets[j][i])\n        }\n      }\n    }\n\n    // Draw projections of surface\n    for (i = 0; i < 3; ++i) {\n      shader.uniforms.model = projectData.projections[i]\n      shader.uniforms.clipBounds = projectData.clipBounds[i]\n\n      for (j = 0; j < 3; ++j) {\n        if (!this.contourProject[i][j]) {\n          continue\n        }\n\n        shader.uniforms.permutation = PERMUTATIONS[j]\n        gl.lineWidth(this.contourWidth[j] * this.pixelRatio)\n        for (var k = 0; k < this.contourLevels[j].length; ++k) {\n          if (this._contourCounts[j][k]) {\n            shader.uniforms.height = this.contourLevels[j][k]\n            vao.draw(gl.LINES, this._contourCounts[j][k], this._contourOffsets[j][k])\n          }\n        }\n      }\n    }\n\n    vao.unbind()\n  }\n}\n\nproto.pick = function (selection) {\n  if (!selection) {\n    return null\n  }\n\n  if (selection.id !== this.pickId) {\n    return null\n  }\n\n  var shape = this._field[2].shape\n\n  var result = this._pickResult\n\n  // Compute uv coordinate\n  var x = shape[0] * (selection.value[0] + (selection.value[2] >> 4) / 16.0) / 255.0\n  var ix = Math.floor(x)\n  var fx = x - ix\n\n  var y = shape[1] * (selection.value[1] + (selection.value[2] & 15) / 16.0) / 255.0\n  var iy = Math.floor(y)\n  var fy = y - iy\n\n  ix += 1\n  iy += 1\n\n  // Compute xyz coordinate\n  var pos = result.position\n  pos[0] = pos[1] = pos[2] = 0\n  for (var dx = 0; dx < 2; ++dx) {\n    var s = dx ? fx : 1.0 - fx\n    for (var dy = 0; dy < 2; ++dy) {\n      var t = dy ? fy : 1.0 - fy\n\n      var r = ix + dx\n      var c = iy + dy\n      var w = s * t\n\n      for (var i = 0; i < 3; ++i) {\n        pos[i] += this._field[i].get(r, c) * w\n      }\n    }\n  }\n\n  // Find closest level\n  var levelIndex = this._pickResult.level\n  for (var j = 0; j < 3; ++j) {\n    levelIndex[j] = bsearch.le(this.contourLevels[j], pos[j])\n    if (levelIndex[j] < 0) {\n      if (this.contourLevels[j].length > 0) {\n        levelIndex[j] = 0\n      }\n    } else if (levelIndex[j] < this.contourLevels[j].length - 1) {\n      var a = this.contourLevels[j][levelIndex[j]]\n      var b = this.contourLevels[j][levelIndex[j] + 1]\n      if (Math.abs(a - pos[j]) > Math.abs(b - pos[j])) {\n        levelIndex[j] += 1\n      }\n    }\n  }\n\n  result.index[0] = fx < 0.5 ? ix : (ix + 1)\n  result.index[1] = fy < 0.5 ? iy : (iy + 1)\n\n  result.uv[0] = x / shape[0]\n  result.uv[1] = y / shape[1]\n\n  for (i = 0; i < 3; ++i) {\n    result.dataCoordinate[i] = this._field[i].get(result.index[0], result.index[1])\n  }\n\n  return result\n}\n\nproto.padField = function(dstField, srcField) {\n  var srcShape = srcField.shape.slice()\n  var dstShape = dstField.shape.slice()\n\n  // Center\n  ops.assign(dstField.lo(1, 1).hi(srcShape[0], srcShape[1]), srcField)\n\n  // Edges\n  ops.assign(dstField.lo(1).hi(srcShape[0], 1),\n    srcField.hi(srcShape[0], 1))\n  ops.assign(dstField.lo(1, dstShape[1] - 1).hi(srcShape[0], 1),\n    srcField.lo(0, srcShape[1] - 1).hi(srcShape[0], 1))\n  ops.assign(dstField.lo(0, 1).hi(1, srcShape[1]),\n    srcField.hi(1))\n  ops.assign(dstField.lo(dstShape[0] - 1, 1).hi(1, srcShape[1]),\n    srcField.lo(srcShape[0] - 1))\n  // Corners\n  dstField.set(0, 0, srcField.get(0, 0))\n  dstField.set(0, dstShape[1] - 1, srcField.get(0, srcShape[1] - 1))\n  dstField.set(dstShape[0] - 1, 0, srcField.get(srcShape[0] - 1, 0))\n  dstField.set(dstShape[0] - 1, dstShape[1] - 1, srcField.get(srcShape[0] - 1, srcShape[1] - 1))\n}\n\nfunction handleArray (param, ctor) {\n  if (Array.isArray(param)) {\n    return [ ctor(param[0]), ctor(param[1]), ctor(param[2]) ]\n  }\n  return [ ctor(param), ctor(param), ctor(param) ]\n}\n\nfunction toColor (x) {\n  if (Array.isArray(x)) {\n    if (x.length === 3) {\n      return [x[0], x[1], x[2], 1]\n    }\n    return [x[0], x[1], x[2], x[3]]\n  }\n  return [0, 0, 0, 1]\n}\n\nfunction handleColor (param) {\n  if (Array.isArray(param)) {\n    if (Array.isArray(param)) {\n      return [\n        toColor(param[0]),\n        toColor(param[1]),\n        toColor(param[2]) ]\n    } else {\n      var c = toColor(param)\n      return [\n        c.slice(),\n        c.slice(),\n        c.slice() ]\n    }\n  }\n}\n\nproto.update = function (params) {\n  params = params || {}\n\n  this.objectOffset = params.objectOffset || this.objectOffset\n\n  this.dirty = true\n\n  if ('contourWidth' in params) {\n    this.contourWidth = handleArray(params.contourWidth, Number)\n  }\n  if ('showContour' in params) {\n    this.showContour = handleArray(params.showContour, Boolean)\n  }\n  if ('showSurface' in params) {\n    this.showSurface = !!params.showSurface\n  }\n  if ('contourTint' in params) {\n    this.contourTint = handleArray(params.contourTint, Boolean)\n  }\n  if ('contourColor' in params) {\n    this.contourColor = handleColor(params.contourColor)\n  }\n  if ('contourProject' in params) {\n    this.contourProject = handleArray(params.contourProject, function (x) {\n      return handleArray(x, Boolean)\n    })\n  }\n  if ('surfaceProject' in params) {\n    this.surfaceProject = params.surfaceProject\n  }\n  if ('dynamicColor' in params) {\n    this.dynamicColor = handleColor(params.dynamicColor)\n  }\n  if ('dynamicTint' in params) {\n    this.dynamicTint = handleArray(params.dynamicTint, Number)\n  }\n  if ('dynamicWidth' in params) {\n    this.dynamicWidth = handleArray(params.dynamicWidth, Number)\n  }\n  if ('opacity' in params) {\n    this.opacity = params.opacity\n  }\n  if ('colorBounds' in params) {\n    this.colorBounds = params.colorBounds\n  }\n  if ('vertexColor' in params) {\n    this.vertexColor = params.vertexColor ? 1 : 0;\n  }\n\n  var field = params.field || (params.coords && params.coords[2]) || null\n  var levelsChanged = false\n\n  if (!field) {\n    if (this._field[2].shape[0] || this._field[2].shape[2]) {\n      field = this._field[2].lo(1, 1).hi(this._field[2].shape[0] - 2, this._field[2].shape[1] - 2)\n    } else {\n      field = this._field[2].hi(0, 0)\n    }\n  }\n\n  // Update field\n  if ('field' in params || 'coords' in params) {\n    var fsize = (field.shape[0] + 2) * (field.shape[1] + 2)\n\n    // Resize if necessary\n    if (fsize > this._field[2].data.length) {\n      pool.freeFloat(this._field[2].data)\n      this._field[2].data = pool.mallocFloat(bits.nextPow2(fsize))\n    }\n\n    // Pad field\n    this._field[2] = ndarray(this._field[2].data, [field.shape[0] + 2, field.shape[1] + 2])\n    this.padField(this._field[2], field)\n\n    // Save shape of field\n    this.shape = field.shape.slice()\n    var shape = this.shape\n\n    // Resize coordinate fields if necessary\n    for (var i = 0; i < 2; ++i) {\n      if (this._field[2].size > this._field[i].data.length) {\n        pool.freeFloat(this._field[i].data)\n        this._field[i].data = pool.mallocFloat(this._field[2].size)\n      }\n      this._field[i] = ndarray(this._field[i].data, [shape[0] + 2, shape[1] + 2])\n    }\n\n    // Generate x/y coordinates\n    if (params.coords) {\n      var coords = params.coords\n      if (!Array.isArray(coords) || coords.length !== 3) {\n        throw new Error('gl-surface: invalid coordinates for x/y')\n      }\n      for (i = 0; i < 2; ++i) {\n        var coord = coords[i]\n        for (j = 0; j < 2; ++j) {\n          if (coord.shape[j] !== shape[j]) {\n            throw new Error('gl-surface: coords have incorrect shape')\n          }\n        }\n        this.padField(this._field[i], coord)\n      }\n    } else if (params.ticks) {\n      var ticks = params.ticks\n      if (!Array.isArray(ticks) || ticks.length !== 2) {\n        throw new Error('gl-surface: invalid ticks')\n      }\n      for (i = 0; i < 2; ++i) {\n        var tick = ticks[i]\n        if (Array.isArray(tick) || tick.length) {\n          tick = ndarray(tick)\n        }\n        if (tick.shape[0] !== shape[i]) {\n          throw new Error('gl-surface: invalid tick length')\n        }\n        // Make a copy view of the tick array\n        var tick2 = ndarray(tick.data, shape)\n        tick2.stride[i] = tick.stride[0]\n        tick2.stride[i ^ 1] = 0\n\n        // Fill in field array\n        this.padField(this._field[i], tick2)\n      }\n    } else {\n      for (i = 0; i < 2; ++i) {\n        var offset = [0, 0]\n        offset[i] = 1\n        this._field[i] = ndarray(this._field[i].data, [shape[0] + 2, shape[1] + 2], offset, 0)\n      }\n      this._field[0].set(0, 0, 0)\n      for (var j = 0; j < shape[0]; ++j) {\n        this._field[0].set(j + 1, 0, j)\n      }\n      this._field[0].set(shape[0] + 1, 0, shape[0] - 1)\n      this._field[1].set(0, 0, 0)\n      for (j = 0; j < shape[1]; ++j) {\n        this._field[1].set(0, j + 1, j)\n      }\n      this._field[1].set(0, shape[1] + 1, shape[1] - 1)\n    }\n\n    // Save shape\n    var fields = this._field\n\n    // Compute surface normals\n    var dfields = ndarray(pool.mallocFloat(fields[2].size * 3 * 2), [3, shape[0] + 2, shape[1] + 2, 2])\n    for (i = 0; i < 3; ++i) {\n      gradient(dfields.pick(i), fields[i], 'mirror')\n    }\n    var normals = ndarray(pool.mallocFloat(fields[2].size * 3), [shape[0] + 2, shape[1] + 2, 3])\n    for (i = 0; i < shape[0] + 2; ++i) {\n      for (j = 0; j < shape[1] + 2; ++j) {\n        var dxdu = dfields.get(0, i, j, 0)\n        var dxdv = dfields.get(0, i, j, 1)\n        var dydu = dfields.get(1, i, j, 0)\n        var dydv = dfields.get(1, i, j, 1)\n        var dzdu = dfields.get(2, i, j, 0)\n        var dzdv = dfields.get(2, i, j, 1)\n\n        var nx = dydu * dzdv - dydv * dzdu\n        var ny = dzdu * dxdv - dzdv * dxdu\n        var nz = dxdu * dydv - dxdv * dydu\n\n        var nl = Math.sqrt(nx * nx + ny * ny + nz * nz)\n        if (nl < 1e-8) {\n          nl = Math.max(Math.abs(nx), Math.abs(ny), Math.abs(nz))\n          if (nl < 1e-8) {\n            nz = 1.0\n            ny = nx = 0.0\n            nl = 1.0\n          } else {\n            nl = 1.0 / nl\n          }\n        } else {\n          nl = 1.0 / Math.sqrt(nl)\n        }\n\n        normals.set(i, j, 0, nx * nl)\n        normals.set(i, j, 1, ny * nl)\n        normals.set(i, j, 2, nz * nl)\n      }\n    }\n    pool.free(dfields.data)\n\n    // Initialize surface\n    var lo = [ Infinity, Infinity, Infinity ]\n    var hi = [ -Infinity, -Infinity, -Infinity ]\n    var lo_intensity = Infinity\n    var hi_intensity = -Infinity\n    var count = (shape[0] - 1) * (shape[1] - 1) * 6\n    var tverts = pool.mallocFloat(bits.nextPow2(10 * count))\n    var tptr = 0\n    var vertexCount = 0\n    for (i = 0; i < shape[0] - 1; ++i) {\n      j_loop:\n      for (j = 0; j < shape[1] - 1; ++j) {\n        // Test for NaNs\n        for (var dx = 0; dx < 2; ++dx) {\n          for (var dy = 0; dy < 2; ++dy) {\n            for (var k = 0; k < 3; ++k) {\n              var f = this._field[k].get(1 + i + dx, 1 + j + dy)\n              if (isNaN(f) || !isFinite(f)) {\n                continue j_loop\n              }\n            }\n          }\n        }\n        for (k = 0; k < 6; ++k) {\n          var r = i + QUAD[k][0]\n          var c = j + QUAD[k][1]\n\n          var tx = this._field[0].get(r + 1, c + 1)\n          var ty = this._field[1].get(r + 1, c + 1)\n          f =      this._field[2].get(r + 1, c + 1)\n\n          nx = normals.get(r + 1, c + 1, 0)\n          ny = normals.get(r + 1, c + 1, 1)\n          nz = normals.get(r + 1, c + 1, 2)\n\n          if (params.intensity) {\n            vf = params.intensity.get(r, c)\n          }\n\n          var vf = (params.intensity) ?\n            params.intensity.get(r, c) :\n            f + this.objectOffset[2];\n\n          tverts[tptr++] = r\n          tverts[tptr++] = c\n          tverts[tptr++] = tx\n          tverts[tptr++] = ty\n          tverts[tptr++] = f\n          tverts[tptr++] = 0\n          tverts[tptr++] = vf\n          tverts[tptr++] = nx\n          tverts[tptr++] = ny\n          tverts[tptr++] = nz\n\n          lo[0] = Math.min(lo[0], tx + this.objectOffset[0])\n          lo[1] = Math.min(lo[1], ty + this.objectOffset[1])\n          lo[2] = Math.min(lo[2], f  + this.objectOffset[2])\n          lo_intensity = Math.min(lo_intensity, vf)\n\n          hi[0] = Math.max(hi[0], tx + this.objectOffset[0])\n          hi[1] = Math.max(hi[1], ty + this.objectOffset[1])\n          hi[2] = Math.max(hi[2], f  + this.objectOffset[2])\n          hi_intensity = Math.max(hi_intensity, vf)\n\n          vertexCount += 1\n        }\n      }\n    }\n\n    if (params.intensityBounds) {\n      lo_intensity = +params.intensityBounds[0]\n      hi_intensity = +params.intensityBounds[1]\n    }\n\n    // Scale all vertex intensities\n    for (i = 6; i < tptr; i += 10) {\n      tverts[i] = (tverts[i] - lo_intensity) / (hi_intensity - lo_intensity)\n    }\n\n    this._vertexCount = vertexCount\n    this._coordinateBuffer.update(tverts.subarray(0, tptr))\n    pool.freeFloat(tverts)\n    pool.free(normals.data)\n\n    // Update bounds\n    this.bounds = [lo, hi]\n\n    // Save intensity\n    this.intensity = params.intensity || this._field[2]\n\n    if(this.intensityBounds[0] !== lo_intensity || this.intensityBounds[1] !== hi_intensity) {\n        levelsChanged = true\n    }\n\n    // Save intensity bound\n    this.intensityBounds = [lo_intensity, hi_intensity]\n  }\n\n  // Update level crossings\n  if ('levels' in params) {\n    var levels = params.levels\n    if (!Array.isArray(levels[0])) {\n      levels = [ [], [], levels ]\n    } else {\n      levels = levels.slice()\n    }\n    for (i = 0; i < 3; ++i) {\n      levels[i] = levels[i].slice()\n      levels[i].sort(function (a, b) {\n        return a - b\n      })\n    }\n    for (i = 0; i < 3; ++i) {\n      for (j = 0; j < levels[i].length; ++j) {\n        levels[i][j] -= this.objectOffset[i]\n      }\n    }\n    change_test:\n    for (i = 0; i < 3; ++i) {\n      if (levels[i].length !== this.contourLevels[i].length) {\n        levelsChanged = true\n        break\n      }\n      for (j = 0; j < levels[i].length; ++j) {\n        if (levels[i][j] !== this.contourLevels[i][j]) {\n          levelsChanged = true\n          break change_test\n        }\n      }\n    }\n    this.contourLevels = levels\n  }\n\n  if (levelsChanged) {\n    fields = this._field\n    shape = this.shape\n\n    // Update contour lines\n    var contourVerts = []\n\n    for (var dim = 0; dim < 3; ++dim) {\n      var contourLevel = this.contourLevels[dim]\n\n      var levelOffsets = []\n      var levelCounts = []\n\n      var parts = [0, 0, 0]\n\n      for (i = 0; i < contourLevel.length; ++i) {\n        var graph = surfaceNets(this._field[dim], contourLevel[i])\n\n        levelOffsets.push((contourVerts.length / 5) | 0)\n        vertexCount = 0\n\n        edge_loop:\n        for (j = 0; j < graph.cells.length; ++j) {\n          var e = graph.cells[j]\n          for (k = 0; k < 2; ++k) {\n            var p = graph.positions[e[k]]\n\n            var x = p[0]\n            var ix = Math.floor(x) | 0\n            var fx = x - ix\n\n            var y = p[1]\n            var iy = Math.floor(y) | 0\n            var fy = y - iy\n\n            var hole = false\n            axis_loop:\n            for (var axis = 0; axis < 3; ++axis) {\n              parts[axis] = 0.0\n              var iu = (dim + axis + 1) % 3\n              for (dx = 0; dx < 2; ++dx) {\n                var s = dx ? fx : 1.0 - fx\n                r = Math.min(Math.max(ix + dx, 0), shape[0]) | 0\n                for (dy = 0; dy < 2; ++dy) {\n                  var t = dy ? fy : 1.0 - fy\n                  c = Math.min(Math.max(iy + dy, 0), shape[1]) | 0\n\n                  if (axis < 2) {\n                    f = this._field[iu].get(r, c)\n                  } else {\n                    f = (this.intensity.get(r, c) - this.intensityBounds[0]) / (this.intensityBounds[1] - this.intensityBounds[0])\n                  }\n                  if (!isFinite(f) || isNaN(f)) {\n                    hole = true\n                    break axis_loop\n                  }\n\n                  var w = s * t\n                  parts[axis] += w * f\n                }\n              }\n            }\n\n            if (!hole) {\n              contourVerts.push(\n                parts[0],\n                parts[1],\n                p[0],\n                p[1],\n                parts[2]\n              )\n              vertexCount += 1\n            } else {\n              if (k > 0) {\n                // If we already added first edge, pop off verts\n                for (var l = 0; l < 5; ++l) {\n                  contourVerts.pop()\n                }\n                vertexCount -= 1\n              }\n              continue edge_loop\n            }\n          }\n        }\n        levelCounts.push(vertexCount)\n      }\n\n      // Store results\n      this._contourOffsets[dim] = levelOffsets\n      this._contourCounts[dim] = levelCounts\n\n    }\n\n    var floatBuffer = pool.mallocFloat(contourVerts.length)\n    for (i = 0; i < contourVerts.length; ++i) {\n      floatBuffer[i] = contourVerts[i]\n    }\n    this._contourBuffer.update(floatBuffer)\n    pool.freeFloat(floatBuffer)\n  }\n\n  if (params.colormap) {\n    this._colorMap.setPixels(genColormap(params.colormap))\n  }\n}\n\nproto.dispose = function () {\n  this._shader.dispose()\n  this._vao.dispose()\n  this._coordinateBuffer.dispose()\n  this._colorMap.dispose()\n  this._contourBuffer.dispose()\n  this._contourVAO.dispose()\n  this._contourShader.dispose()\n  this._contourPickShader.dispose()\n  this._dynamicBuffer.dispose()\n  this._dynamicVAO.dispose()\n  for (var i = 0; i < 3; ++i) {\n    pool.freeFloat(this._field[i].data)\n  }\n}\n\nproto.highlight = function (selection) {\n  var i\n\n  if (!selection) {\n    this._dynamicCounts = [0, 0, 0]\n    this.dyanamicLevel = [NaN, NaN, NaN]\n    this.highlightLevel = [-1, -1, -1]\n    return\n  }\n\n  for (i = 0; i < 3; ++i) {\n    if (this.enableHighlight[i]) {\n      this.highlightLevel[i] = selection.level[i]\n    } else {\n      this.highlightLevel[i] = -1\n    }\n  }\n\n  var levels\n  if (this.snapToData) {\n    levels = selection.dataCoordinate\n  } else {\n    levels = selection.position\n  }\n  for (i = 0; i < 3; ++i) {\n    levels[i] -= this.objectOffset[i]\n  }\n  if ((!this.enableDynamic[0] || levels[0] === this.dynamicLevel[0]) &&\n    (!this.enableDynamic[1] || levels[1] === this.dynamicLevel[1]) &&\n    (!this.enableDynamic[2] || levels[2] === this.dynamicLevel[2])) {\n    return\n  }\n\n  var vertexCount = 0\n  var shape = this.shape\n  var scratchBuffer = pool.mallocFloat(12 * shape[0] * shape[1])\n\n  for (var d = 0; d < 3; ++d) {\n    if (!this.enableDynamic[d]) {\n      this.dynamicLevel[d] = NaN\n      this._dynamicCounts[d] = 0\n      continue\n    }\n\n    this.dynamicLevel[d] = levels[d]\n\n    var u = (d + 1) % 3\n    var v = (d + 2) % 3\n\n    var f = this._field[d]\n    var g = this._field[u]\n    var h = this._field[v]\n\n    var graph = surfaceNets(f, levels[d])\n    var edges = graph.cells\n    var positions = graph.positions\n\n    this._dynamicOffsets[d] = vertexCount\n\n    for (i = 0; i < edges.length; ++i) {\n      var e = edges[i]\n      for (var j = 0; j < 2; ++j) {\n        var p = positions[e[j]]\n\n        var x = +p[0]\n        var ix = x | 0\n        var jx = Math.min(ix + 1, shape[0]) | 0\n        var fx = x - ix\n        var hx = 1.0 - fx\n\n        var y = +p[1]\n        var iy = y | 0\n        var jy = Math.min(iy + 1, shape[1]) | 0\n        var fy = y - iy\n        var hy = 1.0 - fy\n\n        var w00 = hx * hy\n        var w01 = hx * fy\n        var w10 = fx * hy\n        var w11 = fx * fy\n\n        var cu = w00 * g.get(ix, iy) +\n          w01 * g.get(ix, jy) +\n          w10 * g.get(jx, iy) +\n          w11 * g.get(jx, jy)\n\n        var cv = w00 * h.get(ix, iy) +\n          w01 * h.get(ix, jy) +\n          w10 * h.get(jx, iy) +\n          w11 * h.get(jx, jy)\n\n        if (isNaN(cu) || isNaN(cv)) {\n          if (j) {\n            vertexCount -= 1\n          }\n          break\n        }\n\n        scratchBuffer[2 * vertexCount + 0] = cu\n        scratchBuffer[2 * vertexCount + 1] = cv\n\n        vertexCount += 1\n      }\n    }\n\n    this._dynamicCounts[d] = vertexCount - this._dynamicOffsets[d]\n  }\n\n  this._dynamicBuffer.update(scratchBuffer.subarray(0, 2 * vertexCount))\n  pool.freeFloat(scratchBuffer)\n}\n\nfunction createSurfacePlot (params) {\n  var gl = params.gl\n\n  var shader = createShader(gl)\n  var pickShader = createPickShader(gl)\n  var contourShader = createContourShader(gl)\n  var contourPickShader = createPickContourShader(gl)\n\n  var coordinateBuffer = createBuffer(gl)\n  var vao = createVAO(gl, [\n    { buffer: coordinateBuffer,\n      size: 4,\n      stride: SURFACE_VERTEX_SIZE,\n      offset: 0\n    },\n    { buffer: coordinateBuffer,\n      size: 3,\n      stride: SURFACE_VERTEX_SIZE,\n      offset: 16\n    },\n    {\n      buffer: coordinateBuffer,\n      size: 3,\n      stride: SURFACE_VERTEX_SIZE,\n      offset: 28\n    }\n  ])\n\n  var contourBuffer = createBuffer(gl)\n  var contourVAO = createVAO(gl, [\n    {\n      buffer: contourBuffer,\n      size: 4,\n      stride: 20,\n      offset: 0\n    },\n    {\n      buffer: contourBuffer,\n      size: 1,\n      stride: 20,\n      offset: 16\n    }\n  ])\n\n  var dynamicBuffer = createBuffer(gl)\n  var dynamicVAO = createVAO(gl, [\n    {\n      buffer: dynamicBuffer,\n      size: 2,\n      type: gl.FLOAT\n    }])\n\n  var cmap = createTexture(gl, 1, N_COLORS, gl.RGBA, gl.UNSIGNED_BYTE)\n  cmap.minFilter = gl.LINEAR\n  cmap.magFilter = gl.LINEAR\n\n  var surface = new SurfacePlot(\n    gl,\n    [0, 0], // shape\n    [[0, 0, 0], [0, 0, 0]], // bounds\n    shader,\n    pickShader,\n    coordinateBuffer,\n    vao,\n    cmap,\n    contourShader,\n    contourPickShader,\n    contourBuffer,\n    contourVAO,\n    dynamicBuffer,\n    dynamicVAO,\n    [0, 0, 0] // objectOffset\n  )\n\n  var nparams = {\n    levels: [[], [], []]\n  }\n  for (var id in params) {\n    nparams[id] = params[id]\n  }\n  nparams.colormap = nparams.colormap || 'jet'\n\n  surface.update(nparams)\n\n  return surface\n}\n\n},{\"./lib/shaders\":314,\"binary-search-bounds\":315,\"bit-twiddle\":92,\"colormap\":126,\"gl-buffer\":241,\"gl-mat4/invert\":265,\"gl-mat4/multiply\":267,\"gl-texture2d\":322,\"gl-vao\":327,\"ndarray\":450,\"ndarray-gradient\":441,\"ndarray-ops\":444,\"ndarray-pack\":445,\"surface-nets\":531,\"typedarray-pool\":545}],317:[function(_dereq_,module,exports){\n'use strict'\n\nvar Font = _dereq_('css-font')\nvar pick = _dereq_('pick-by-alias')\nvar createRegl = _dereq_('regl')\nvar createGl = _dereq_('gl-util/context')\nvar WeakMap = _dereq_('es6-weak-map')\nvar rgba = _dereq_('color-normalize')\nvar fontAtlas = _dereq_('font-atlas')\nvar pool = _dereq_('typedarray-pool')\nvar parseRect = _dereq_('parse-rect')\nvar isObj = _dereq_('is-plain-obj')\nvar parseUnit = _dereq_('parse-unit')\nvar px = _dereq_('to-px')\nvar kerning = _dereq_('detect-kerning')\nvar extend = _dereq_('object-assign')\nvar metrics = _dereq_('font-measure')\nvar flatten = _dereq_('flatten-vertex-data')\nvar ref = _dereq_('bit-twiddle');\nvar nextPow2 = ref.nextPow2;\n\nvar shaderCache = new WeakMap\n\n\n// Safari does not support font-stretch\nvar isStretchSupported = false\nif (document.body) {\n    var el = document.body.appendChild(document.createElement('div'))\n    el.style.font = 'italic small-caps bold condensed 16px/2 cursive'\n    if (getComputedStyle(el).fontStretch) {\n        isStretchSupported = true\n    }\n    document.body.removeChild(el)\n}\n\nvar GlText = function GlText (o) {\n\tif (isRegl(o)) {\n\t\to = {regl: o}\n\t\tthis.gl = o.regl._gl\n\t}\n\telse {\n\t\tthis.gl = createGl(o)\n\t}\n\n\tthis.shader = shaderCache.get(this.gl)\n\n\tif (!this.shader) {\n\t\tthis.regl = o.regl || createRegl({ gl: this.gl })\n\t}\n\telse {\n\t\tthis.regl = this.shader.regl\n\t}\n\n\tthis.charBuffer = this.regl.buffer({ type: 'uint8', usage: 'stream' })\n\tthis.sizeBuffer = this.regl.buffer({ type: 'float', usage: 'stream' })\n\n\tif (!this.shader) {\n\t\tthis.shader = this.createShader()\n\t\tshaderCache.set(this.gl, this.shader)\n\t}\n\n\tthis.batch = []\n\n\t// multiple options initial state\n\tthis.fontSize = []\n\tthis.font = []\n\tthis.fontAtlas = []\n\n\tthis.draw = this.shader.draw.bind(this)\n\tthis.render = function () {\n\t\t// FIXME: add Safari regl report here:\n\t\t// charBuffer and width just do not trigger\n\t\tthis.regl._refresh()\n\t\tthis.draw(this.batch)\n\t}\n\tthis.canvas = this.gl.canvas\n\n\tthis.update(isObj(o) ? o : {})\n};\n\nGlText.prototype.createShader = function createShader () {\n\tvar regl = this.regl\n\n\t// FIXME: store 2 shader versions: with normal viewport and without\n\t// draw texture method\n\tvar draw = regl({\n\t\tblend: {\n\t\t\tenable: true,\n\t\t\tcolor: [0,0,0,1],\n\n\t\t\tfunc: {\n\t\t\t\tsrcRGB: 'src alpha',\n\t\t\t\tdstRGB: 'one minus src alpha',\n\t\t\t\tsrcAlpha: 'one minus dst alpha',\n\t\t\t\tdstAlpha: 'one'\n\t\t\t}\n\t\t},\n\t\tstencil: {enable: false},\n\t\tdepth: {enable: false},\n\n\t\tcount: regl.prop('count'),\n\t\toffset: regl.prop('offset'),\n\t\tattributes: {\n\t\t\tcharOffset: {\n\t\t\t\toffset: 4,\n\t\t\t\tstride: 8,\n\t\t\t\tbuffer: regl.this('sizeBuffer')\n\t\t\t},\n\t\t\twidth: {\n\t\t\t\toffset: 0,\n\t\t\t\tstride: 8,\n\t\t\t\tbuffer: regl.this('sizeBuffer')\n\t\t\t},\n\t\t\tchar: regl.this('charBuffer'),\n\t\t\tposition: regl.this('position')\n\t\t},\n\t\tuniforms: {\n\t\t\tatlasSize: function (c, p) { return [p.atlas.width, p.atlas.height]; },\n\t\t\tatlasDim: function (c, p) { return [p.atlas.cols, p.atlas.rows]; },\n\t\t\tatlas: function (c, p) { return p.atlas.texture; },\n\t\t\tcharStep: function (c, p) { return p.atlas.step; },\n\t\t\tem: function (c, p) { return p.atlas.em; },\n\t\t\tcolor: regl.prop('color'),\n\t\t\topacity: regl.prop('opacity'),\n\t\t\tviewport: regl.this('viewportArray'),\n\t\t\tscale: regl.this('scale'),\n\t\t\talign: regl.prop('align'),\n\t\t\tbaseline: regl.prop('baseline'),\n\t\t\ttranslate: regl.this('translate'),\n\t\t\tpositionOffset: regl.prop('positionOffset')\n\t\t},\n\t\tprimitive: 'points',\n\t\tviewport: regl.this('viewport'),\n\n\t\tvert: (\"\\n\\t\\t\\tprecision highp float;\\n\\t\\t\\tattribute float width, charOffset, char;\\n\\t\\t\\tattribute vec2 position;\\n\\t\\t\\tuniform float fontSize, charStep, em, align, baseline;\\n\\t\\t\\tuniform vec4 viewport;\\n\\t\\t\\tuniform vec4 color;\\n\\t\\t\\tuniform vec2 atlasSize, atlasDim, scale, translate, positionOffset;\\n\\t\\t\\tvarying vec2 charCoord, charId;\\n\\t\\t\\tvarying float charWidth;\\n\\t\\t\\tvarying vec4 fontColor;\\n\\t\\t\\tvoid main () {\\n\\t\\t\\t\\t\" + (!GlText.normalViewport ? 'vec2 positionOffset = vec2(positionOffset.x,- positionOffset.y);' : '') + \"\\n\\n\\t\\t\\t\\tvec2 offset = floor(em * (vec2(align + charOffset, baseline)\\n\\t\\t\\t\\t\\t+ positionOffset))\\n\\t\\t\\t\\t\\t/ (viewport.zw * scale.xy);\\n\\n\\t\\t\\t\\tvec2 position = (position + translate) * scale;\\n\\t\\t\\t\\tposition += offset * scale;\\n\\n\\t\\t\\t\\t\" + (GlText.normalViewport ? 'position.y = 1. - position.y;' : '') + \"\\n\\n\\t\\t\\t\\tcharCoord = position * viewport.zw + viewport.xy;\\n\\n\\t\\t\\t\\tgl_Position = vec4(position * 2. - 1., 0, 1);\\n\\n\\t\\t\\t\\tgl_PointSize = charStep;\\n\\n\\t\\t\\t\\tcharId.x = mod(char, atlasDim.x);\\n\\t\\t\\t\\tcharId.y = floor(char / atlasDim.x);\\n\\n\\t\\t\\t\\tcharWidth = width * em;\\n\\n\\t\\t\\t\\tfontColor = color / 255.;\\n\\t\\t\\t}\"),\n\n\t\tfrag: \"\\n\\t\\t\\tprecision highp float;\\n\\t\\t\\tuniform sampler2D atlas;\\n\\t\\t\\tuniform float fontSize, charStep, opacity;\\n\\t\\t\\tuniform vec2 atlasSize;\\n\\t\\t\\tuniform vec4 viewport;\\n\\t\\t\\tvarying vec4 fontColor;\\n\\t\\t\\tvarying vec2 charCoord, charId;\\n\\t\\t\\tvarying float charWidth;\\n\\n\\t\\t\\tfloat lightness(vec4 color) {\\n\\t\\t\\t\\treturn color.r * 0.299 + color.g * 0.587 + color.b * 0.114;\\n\\t\\t\\t}\\n\\n\\t\\t\\tvoid main () {\\n\\t\\t\\t\\tvec2 uv = gl_FragCoord.xy - charCoord + charStep * .5;\\n\\t\\t\\t\\tfloat halfCharStep = floor(charStep * .5 + .5);\\n\\n\\t\\t\\t\\t// invert y and shift by 1px (FF expecially needs that)\\n\\t\\t\\t\\tuv.y = charStep - uv.y;\\n\\n\\t\\t\\t\\t// ignore points outside of character bounding box\\n\\t\\t\\t\\tfloat halfCharWidth = ceil(charWidth * .5);\\n\\t\\t\\t\\tif (floor(uv.x) > halfCharStep + halfCharWidth ||\\n\\t\\t\\t\\t\\tfloor(uv.x) < halfCharStep - halfCharWidth) return;\\n\\n\\t\\t\\t\\tuv += charId * charStep;\\n\\t\\t\\t\\tuv = uv / atlasSize;\\n\\n\\t\\t\\t\\tvec4 color = fontColor;\\n\\t\\t\\t\\tvec4 mask = texture2D(atlas, uv);\\n\\n\\t\\t\\t\\tfloat maskY = lightness(mask);\\n\\t\\t\\t\\t// float colorY = lightness(color);\\n\\t\\t\\t\\tcolor.a *= maskY;\\n\\t\\t\\t\\tcolor.a *= opacity;\\n\\n\\t\\t\\t\\t// color.a += .1;\\n\\n\\t\\t\\t\\t// antialiasing, see yiq color space y-channel formula\\n\\t\\t\\t\\t// color.rgb += (1. - color.rgb) * (1. - mask.rgb);\\n\\n\\t\\t\\t\\tgl_FragColor = color;\\n\\t\\t\\t}\"\n\t})\n\n\t// per font-size atlas\n\tvar atlas = {}\n\n\treturn { regl: regl, draw: draw, atlas: atlas }\n};\n\nGlText.prototype.update = function update (o) {\n\t\tvar this$1 = this;\n\n\tif (typeof o === 'string') { o = { text: o } }\n\telse if (!o) { return }\n\n\t// FIXME: make this a static transform or more general approact\n\to = pick(o, {\n\t\tposition: 'position positions coord coords coordinates',\n\t\tfont: 'font fontFace fontface typeface cssFont css-font family fontFamily',\n\t\tfontSize: 'fontSize fontsize size font-size',\n\t\ttext: 'text texts chars characters value values symbols',\n\t\talign: 'align alignment textAlign textbaseline',\n\t\tbaseline: 'baseline textBaseline textbaseline',\n\t\tdirection: 'dir direction textDirection',\n\t\tcolor: 'color colour fill fill-color fillColor textColor textcolor',\n\t\tkerning: 'kerning kern',\n\t\trange: 'range dataBox',\n\t\tviewport: 'vp viewport viewBox viewbox viewPort',\n\t\topacity: 'opacity alpha transparency visible visibility opaque',\n\t\toffset: 'offset positionOffset padding shift indent indentation'\n\t}, true)\n\n\n\tif (o.opacity != null) {\n\t\tif (Array.isArray(o.opacity)) {\n\t\t\tthis.opacity = o.opacity.map(function (o) { return parseFloat(o); })\n\t\t}\n\t\telse {\n\t\t\tthis.opacity = parseFloat(o.opacity)\n\t\t}\n\t}\n\n\tif (o.viewport != null) {\n\t\tthis.viewport = parseRect(o.viewport)\n\n\t\tif (GlText.normalViewport) {\n\t\t\tthis.viewport.y = this.canvas.height - this.viewport.y - this.viewport.height\n\t\t}\n\n\t\tthis.viewportArray = [this.viewport.x, this.viewport.y, this.viewport.width, this.viewport.height]\n\n\t}\n\tif (this.viewport == null) {\n\t\tthis.viewport = {\n\t\t\tx: 0, y: 0,\n\t\t\twidth: this.gl.drawingBufferWidth,\n\t\t\theight: this.gl.drawingBufferHeight\n\t\t}\n\t\tthis.viewportArray = [this.viewport.x, this.viewport.y, this.viewport.width, this.viewport.height]\n\t}\n\n\tif (o.kerning != null) { this.kerning = o.kerning }\n\n\tif (o.offset != null) {\n\t\tif (typeof o.offset === 'number') { o.offset = [o.offset, 0] }\n\n\t\tthis.positionOffset = flatten(o.offset)\n\t}\n\n\tif (o.direction) { this.direction = o.direction }\n\n\tif (o.range) {\n\t\tthis.range = o.range\n\t\tthis.scale = [1 / (o.range[2] - o.range[0]), 1 / (o.range[3] - o.range[1])]\n\t\tthis.translate = [-o.range[0], -o.range[1]]\n\t}\n\tif (o.scale) { this.scale = o.scale }\n\tif (o.translate) { this.translate = o.translate }\n\n\t// default scale corresponds to viewport\n\tif (!this.scale) { this.scale = [1 / this.viewport.width, 1 / this.viewport.height] }\n\n\tif (!this.translate) { this.translate = [0, 0] }\n\n\tif (!this.font.length && !o.font) { o.font = GlText.baseFontSize + 'px sans-serif' }\n\n\t// normalize font caching string\n\tvar newFont = false, newFontSize = false\n\n\t// obtain new font data\n\tif (o.font) {\n\t\t(Array.isArray(o.font) ? o.font : [o.font]).forEach(function (font, i) {\n\t\t\t// normalize font\n\t\t\tif (typeof font === 'string') {\n\t\t\t\ttry {\n\t\t\t\t\tfont = Font.parse(font)\n\t\t\t\t} catch (e) {\n\t\t\t\t\tfont = Font.parse(GlText.baseFontSize + 'px ' + font)\n\t\t\t\t}\n\t\t\t}\n\t\t\telse { font = Font.parse(Font.stringify(font)) }\n\n\t\t\tvar baseString = Font.stringify({\n\t\t\t\tsize: GlText.baseFontSize,\n\t\t\t\tfamily: font.family,\n\t\t\t\tstretch: isStretchSupported ? font.stretch : undefined,\n\t\t\t\tvariant: font.variant,\n\t\t\t\tweight: font.weight,\n\t\t\t\tstyle: font.style\n\t\t\t})\n\n\t\t\tvar unit = parseUnit(font.size)\n\t\t\tvar fs = Math.round(unit[0] * px(unit[1]))\n\t\t\tif (fs !== this$1.fontSize[i]) {\n\t\t\t\tnewFontSize = true\n\t\t\t\tthis$1.fontSize[i] = fs\n\t\t\t}\n\n\t\t\t// calc new font metrics/atlas\n\t\t\tif (!this$1.font[i] || baseString != this$1.font[i].baseString) {\n\t\t\t\tnewFont = true\n\n\t\t\t\t// obtain font cache or create one\n\t\t\t\tthis$1.font[i] = GlText.fonts[baseString]\n\t\t\t\tif (!this$1.font[i]) {\n\t\t\t\t\tvar family = font.family.join(', ')\n\t\t\t\t\tvar style = [font.style]\n\t\t\t\t\tif (font.style != font.variant) { style.push(font.variant) }\n\t\t\t\t\tif (font.variant != font.weight) { style.push(font.weight) }\n\t\t\t\t\tif (isStretchSupported && font.weight != font.stretch) { style.push(font.stretch) }\n\n\t\t\t\t\tthis$1.font[i] = {\n\t\t\t\t\t\tbaseString: baseString,\n\n\t\t\t\t\t\t// typeface\n\t\t\t\t\t\tfamily: family,\n\t\t\t\t\t\tweight: font.weight,\n\t\t\t\t\t\tstretch: font.stretch,\n\t\t\t\t\t\tstyle: font.style,\n\t\t\t\t\t\tvariant: font.variant,\n\n\t\t\t\t\t\t// widths of characters\n\t\t\t\t\t\twidth: {},\n\n\t\t\t\t\t\t// kernin pairs offsets\n\t\t\t\t\t\tkerning: {},\n\n\t\t\t\t\t\tmetrics: metrics(family, {\n\t\t\t\t\t\t\torigin: 'top',\n\t\t\t\t\t\t\tfontSize: GlText.baseFontSize,\n\t\t\t\t\t\t\tfontStyle: style.join(' ')\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\n\t\t\t\t\tGlText.fonts[baseString] = this$1.font[i]\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\t// FIXME: make independend font-size\n\t// if (o.fontSize) {\n\t// let unit = parseUnit(o.fontSize)\n\t// let fs = Math.round(unit[0] * px(unit[1]))\n\n\t// if (fs != this.fontSize) {\n\t// \tnewFontSize = true\n\t// \tthis.fontSize = fs\n\t// }\n\t// }\n\n\tif (newFont || newFontSize) {\n\t\tthis.font.forEach(function (font, i) {\n\t\t\tvar fontString = Font.stringify({\n\t\t\t\tsize: this$1.fontSize[i],\n\t\t\t\tfamily: font.family,\n\t\t\t\tstretch: isStretchSupported ? font.stretch : undefined,\n\t\t\t\tvariant: font.variant,\n\t\t\t\tweight: font.weight,\n\t\t\t\tstyle: font.style\n\t\t\t})\n\n\t\t\t// calc new font size atlas\n\t\t\tthis$1.fontAtlas[i] = this$1.shader.atlas[fontString]\n\n\t\t\tif (!this$1.fontAtlas[i]) {\n\t\t\t\tvar metrics = font.metrics\n\n\t\t\t\tthis$1.shader.atlas[fontString] =\n\t\t\t\tthis$1.fontAtlas[i] = {\n\t\t\t\t\tfontString: fontString,\n\t\t\t\t\t// even step is better for rendered characters\n\t\t\t\t\tstep: Math.ceil(this$1.fontSize[i] * metrics.bottom * .5) * 2,\n\t\t\t\t\tem: this$1.fontSize[i],\n\t\t\t\t\tcols: 0,\n\t\t\t\t\trows: 0,\n\t\t\t\t\theight: 0,\n\t\t\t\t\twidth: 0,\n\t\t\t\t\tchars: [],\n\t\t\t\t\tids: {},\n\t\t\t\t\ttexture: this$1.regl.texture()\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// bump atlas characters\n\t\t\tif (o.text == null) { o.text = this$1.text }\n\t\t})\n\t}\n\n\t// if multiple positions - duplicate text arguments\n\t// FIXME: this possibly can be done better to avoid array spawn\n\tif (typeof o.text === 'string' && o.position && o.position.length > 2) {\n\t\tvar textArray = Array(o.position.length * .5)\n\t\tfor (var i = 0; i < textArray.length; i++) {\n\t\t\ttextArray[i] = o.text\n\t\t}\n\t\to.text = textArray\n\t}\n\n\t// calculate offsets for the new font/text\n\tvar newAtlasChars\n\tif (o.text != null || newFont) {\n\t\t// FIXME: ignore spaces\n\t\t// text offsets within the text buffer\n\t\tthis.textOffsets = [0]\n\n\t\tif (Array.isArray(o.text)) {\n\t\t\tthis.count = o.text[0].length\n\t\t\tthis.counts = [this.count]\n\t\t\tfor (var i$1 = 1; i$1 < o.text.length; i$1++) {\n\t\t\t\tthis.textOffsets[i$1] = this.textOffsets[i$1 - 1] + o.text[i$1 - 1].length\n\t\t\t\tthis.count += o.text[i$1].length\n\t\t\t\tthis.counts.push(o.text[i$1].length)\n\t\t\t}\n\t\t\tthis.text = o.text.join('')\n\t\t}\n\t\telse {\n\t\t\tthis.text = o.text\n\t\t\tthis.count = this.text.length\n\t\t\tthis.counts = [this.count]\n\t\t}\n\n\t\tnewAtlasChars = []\n\n\t\t// detect & measure new characters\n\t\tthis.font.forEach(function (font, idx) {\n\t\t\tGlText.atlasContext.font = font.baseString\n\n\t\t\tvar atlas = this$1.fontAtlas[idx]\n\n\t\t\tfor (var i = 0; i < this$1.text.length; i++) {\n\t\t\t\tvar char = this$1.text.charAt(i)\n\n\t\t\t\tif (atlas.ids[char] == null) {\n\t\t\t\t\tatlas.ids[char] = atlas.chars.length\n\t\t\t\t\tatlas.chars.push(char)\n\t\t\t\t\tnewAtlasChars.push(char)\n\t\t\t\t}\n\n\t\t\t\tif (font.width[char] == null) {\n\t\t\t\t\tfont.width[char] = GlText.atlasContext.measureText(char).width / GlText.baseFontSize\n\n\t\t\t\t\t// measure kerning pairs for the new character\n\t\t\t\t\tif (this$1.kerning) {\n\t\t\t\t\t\tvar pairs = []\n\t\t\t\t\t\tfor (var baseChar in font.width) {\n\t\t\t\t\t\t\tpairs.push(baseChar + char, char + baseChar)\n\t\t\t\t\t\t}\n\t\t\t\t\t\textend(font.kerning, kerning(font.family, {\n\t\t\t\t\t\t\tpairs: pairs\n\t\t\t\t\t\t}))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\t// create single position buffer (faster than batch or multiple separate instances)\n\tif (o.position) {\n\t\tif (o.position.length > 2) {\n\t\t\tvar flat = !o.position[0].length\n\t\t\tvar positionData = pool.mallocFloat(this.count * 2)\n\t\t\tfor (var i$2 = 0, ptr = 0; i$2 < this.counts.length; i$2++) {\n\t\t\t\tvar count = this.counts[i$2]\n\t\t\t\tif (flat) {\n\t\t\t\t\tfor (var j = 0; j < count; j++) {\n\t\t\t\t\t\tpositionData[ptr++] = o.position[i$2 * 2]\n\t\t\t\t\t\tpositionData[ptr++] = o.position[i$2 * 2 + 1]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfor (var j$1 = 0; j$1 < count; j$1++) {\n\t\t\t\t\t\tpositionData[ptr++] = o.position[i$2][0]\n\t\t\t\t\t\tpositionData[ptr++] = o.position[i$2][1]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.position.call) {\n\t\t\t\tthis.position({\n\t\t\t\t\ttype: 'float',\n\t\t\t\t\tdata: positionData\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tthis.position = this.regl.buffer({\n\t\t\t\t\ttype: 'float',\n\t\t\t\t\tdata: positionData\n\t\t\t\t})\n\t\t\t}\n\t\t\tpool.freeFloat(positionData)\n\t\t}\n\t\telse {\n\t\t\tif (this.position.destroy) { this.position.destroy() }\n\t\t\tthis.position = {\n\t\t\t\tconstant: o.position\n\t\t\t}\n\t\t}\n\t}\n\n\t// populate text/offset buffers if font/text has changed\n\t// as [charWidth, offset, charWidth, offset...]\n\t// that is in em units since font-size can change often\n\tif (o.text || newFont) {\n\t\tvar charIds = pool.mallocUint8(this.count)\n\t\tvar sizeData = pool.mallocFloat(this.count * 2)\n\t\tthis.textWidth = []\n\n\t\tfor (var i$3 = 0, ptr$1 = 0; i$3 < this.counts.length; i$3++) {\n\t\t\tvar count$1 = this.counts[i$3]\n\t\t\tvar font = this.font[i$3] || this.font[0]\n\t\t\tvar atlas = this.fontAtlas[i$3] || this.fontAtlas[0]\n\n\t\t\tfor (var j$2 = 0; j$2 < count$1; j$2++) {\n\t\t\t\tvar char = this.text.charAt(ptr$1)\n\t\t\t\tvar prevChar = this.text.charAt(ptr$1 - 1)\n\n\t\t\t\tcharIds[ptr$1] = atlas.ids[char]\n\t\t\t\tsizeData[ptr$1 * 2] = font.width[char]\n\n\t\t\t\tif (j$2) {\n\t\t\t\t\tvar prevWidth = sizeData[ptr$1 * 2 - 2]\n\t\t\t\t\tvar currWidth = sizeData[ptr$1 * 2]\n\t\t\t\t\tvar prevOffset = sizeData[ptr$1 * 2 - 1]\n\t\t\t\t\tvar offset = prevOffset + prevWidth * .5 + currWidth * .5;\n\n\t\t\t\t\tif (this.kerning) {\n\t\t\t\t\t\tvar kerning$1 = font.kerning[prevChar + char]\n\t\t\t\t\t\tif (kerning$1) {\n\t\t\t\t\t\t\toffset += kerning$1 * 1e-3\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tsizeData[ptr$1 * 2 + 1] = offset\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tsizeData[ptr$1 * 2 + 1] = sizeData[ptr$1 * 2] * .5\n\t\t\t\t}\n\n\t\t\t\tptr$1++\n\t\t\t}\n\t\t\tthis.textWidth.push(\n\t\t\t\t!sizeData.length ? 0 :\n\t\t\t\t// last offset + half last width\n\t\t\t\tsizeData[ptr$1 * 2 - 2] * .5 + sizeData[ptr$1 * 2 - 1]\n\t\t\t)\n\t\t}\n\n\n\t\t// bump recalc align offset\n\t\tif (!o.align) { o.align = this.align }\n\t\tthis.charBuffer({data: charIds, type: 'uint8', usage: 'stream'})\n\t\tthis.sizeBuffer({data: sizeData, type: 'float', usage: 'stream'})\n\t\tpool.freeUint8(charIds)\n\t\tpool.freeFloat(sizeData)\n\n\t\t// udpate font atlas and texture\n\t\tif (newAtlasChars.length) {\n\t\t\tthis.font.forEach(function (font, i) {\n\t\t\t\tvar atlas = this$1.fontAtlas[i]\n\n\t\t\t\t// FIXME: insert metrics-based ratio here\n\t\t\t\tvar step = atlas.step\n\n\t\t\t\tvar maxCols = Math.floor(GlText.maxAtlasSize / step)\n\t\t\t\tvar cols = Math.min(maxCols, atlas.chars.length)\n\t\t\t\tvar rows = Math.ceil(atlas.chars.length / cols)\n\n\t\t\t\tvar atlasWidth = nextPow2( cols * step )\n\t\t\t\t// let atlasHeight = Math.min(rows * step + step * .5, GlText.maxAtlasSize);\n\t\t\t\tvar atlasHeight = nextPow2( rows * step );\n\n\t\t\t\tatlas.width = atlasWidth\n\t\t\t\tatlas.height = atlasHeight;\n\t\t\t\tatlas.rows = rows\n\t\t\t\tatlas.cols = cols\n\n\t\t\t\tif (!atlas.em) { return }\n\n\t\t\t\tatlas.texture({\n\t\t\t\t\tdata: fontAtlas({\n\t\t\t\t\t\tcanvas: GlText.atlasCanvas,\n\t\t\t\t\t\tfont: atlas.fontString,\n\t\t\t\t\t\tchars: atlas.chars,\n\t\t\t\t\t\tshape: [atlasWidth, atlasHeight],\n\t\t\t\t\t\tstep: [step, step]\n\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t})\n\t\t}\n\t}\n\n\tif (o.align) {\n\t\tthis.align = o.align\n\t\tthis.alignOffset = this.textWidth.map(function (textWidth, i) {\n\t\t\tvar align = !Array.isArray(this$1.align) ? this$1.align : this$1.align.length > 1 ? this$1.align[i] : this$1.align[0]\n\n\t\t\tif (typeof align === 'number') { return align }\n\t\t\tswitch (align) {\n\t\t\t\tcase 'right':\n\t\t\t\tcase 'end':\n\t\t\t\t\treturn -textWidth\n\t\t\t\tcase 'center':\n\t\t\t\tcase 'centre':\n\t\t\t\tcase 'middle':\n\t\t\t\t\treturn -textWidth * .5\n\t\t\t}\n\n\t\t\treturn 0\n\t\t})\n\t}\n\n\tif (this.baseline == null && o.baseline == null) {\n\t\to.baseline = 0\n\t}\n\tif (o.baseline != null) {\n\t\tthis.baseline = o.baseline\n\t\tif (!Array.isArray(this.baseline)) { this.baseline = [this.baseline] }\n\t\tthis.baselineOffset = this.baseline.map(function (baseline, i) {\n\t\t\tvar m = (this$1.font[i] || this$1.font[0]).metrics\n\t\t\tvar base = 0\n\n\t\t\tbase += m.bottom * .5\n\n\t\t\tif (typeof baseline === 'number') {\n\t\t\t\tbase += (baseline - m.baseline)\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbase += -m[baseline]\n\t\t\t}\n\n\t\t\tif (!GlText.normalViewport) { base *= -1 }\n\t\t\treturn base\n\t\t})\n\t}\n\n\t// flatten colors to a single uint8 array\n\tif (o.color != null) {\n\t\tif (!o.color) { o.color = 'transparent' }\n\n\t\t// single color\n\t\tif (typeof o.color === 'string' || !isNaN(o.color)) {\n\t\t\tthis.color = rgba(o.color, 'uint8')\n\t\t}\n\t\t// array\n\t\telse {\n\t\t\tvar colorData\n\n\t\t\t// flat array\n\t\t\tif (typeof o.color[0] === 'number' && o.color.length > this.counts.length) {\n\t\t\t\tvar l = o.color.length\n\t\t\t\tcolorData = pool.mallocUint8(l)\n\t\t\t\tvar sub = (o.color.subarray || o.color.slice).bind(o.color)\n\t\t\t\tfor (var i$4 = 0; i$4 < l; i$4 += 4) {\n\t\t\t\t\tcolorData.set(rgba(sub(i$4, i$4 + 4), 'uint8'), i$4)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// nested array\n\t\t\telse {\n\t\t\t\tvar l$1 = o.color.length\n\t\t\t\tcolorData = pool.mallocUint8(l$1 * 4)\n\t\t\t\tfor (var i$5 = 0; i$5 < l$1; i$5++) {\n\t\t\t\t\tcolorData.set(rgba(o.color[i$5] || 0, 'uint8'), i$5 * 4)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.color = colorData\n\t\t}\n\t}\n\n\t// update render batch\n\tif (o.position || o.text || o.color || o.baseline || o.align || o.font || o.offset || o.opacity) {\n\t\tvar isBatch = (this.color.length > 4)\n\t\t\t|| (this.baselineOffset.length > 1)\n\t\t\t|| (this.align && this.align.length > 1)\n\t\t\t|| (this.fontAtlas.length > 1)\n\t\t\t|| (this.positionOffset.length > 2)\n\t\tif (isBatch) {\n\t\t\tvar length = Math.max(\n\t\t\t\tthis.position.length * .5 || 0,\n\t\t\t\tthis.color.length * .25 || 0,\n\t\t\t\tthis.baselineOffset.length || 0,\n\t\t\t\tthis.alignOffset.length || 0,\n\t\t\t\tthis.font.length || 0,\n\t\t\t\tthis.opacity.length || 0,\n\t\t\t\tthis.positionOffset.length * .5 || 0\n\t\t\t)\n\t\t\tthis.batch = Array(length)\n\t\t\tfor (var i$6 = 0; i$6 < this.batch.length; i$6++) {\n\t\t\t\tthis.batch[i$6] = {\n\t\t\t\t\tcount: this.counts.length > 1 ? this.counts[i$6] : this.counts[0],\n\t\t\t\t\toffset: this.textOffsets.length > 1 ? this.textOffsets[i$6] : this.textOffsets[0],\n\t\t\t\t\tcolor: !this.color ? [0,0,0,255] : this.color.length <= 4 ? this.color : this.color.subarray(i$6 * 4, i$6 * 4 + 4),\n\t\t\t\t\topacity: Array.isArray(this.opacity) ? this.opacity[i$6] : this.opacity,\n\t\t\t\t\tbaseline: this.baselineOffset[i$6] != null ? this.baselineOffset[i$6] : this.baselineOffset[0],\n\t\t\t\t\talign: !this.align ? 0 : this.alignOffset[i$6] != null ? this.alignOffset[i$6] : this.alignOffset[0],\n\t\t\t\t\tatlas: this.fontAtlas[i$6] || this.fontAtlas[0],\n\t\t\t\t\tpositionOffset: this.positionOffset.length > 2 ? this.positionOffset.subarray(i$6 * 2, i$6 * 2 + 2) : this.positionOffset\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// single-color, single-baseline, single-align batch is faster to render\n\t\telse {\n\t\t\tif (this.count) {\n\t\t\t\tthis.batch = [{\n\t\t\t\t\tcount: this.count,\n\t\t\t\t\toffset: 0,\n\t\t\t\t\tcolor: this.color || [0,0,0,255],\n\t\t\t\t\topacity: Array.isArray(this.opacity) ? this.opacity[0] : this.opacity,\n\t\t\t\t\tbaseline: this.baselineOffset[0],\n\t\t\t\t\talign: this.alignOffset ? this.alignOffset[0] : 0,\n\t\t\t\t\tatlas: this.fontAtlas[0],\n\t\t\t\t\tpositionOffset: this.positionOffset\n\t\t\t\t}]\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.batch = []\n\t\t\t}\n\t\t}\n\t}\n};\n\nGlText.prototype.destroy = function destroy () {\n\t// TODO: count instances of atlases and destroy all on null\n};\n\n\n// defaults\nGlText.prototype.kerning = true\nGlText.prototype.position = { constant: new Float32Array(2) }\nGlText.prototype.translate = null\nGlText.prototype.scale = null\nGlText.prototype.font = null\nGlText.prototype.text = ''\nGlText.prototype.positionOffset = [0, 0]\nGlText.prototype.opacity = 1\nGlText.prototype.color = new Uint8Array([0, 0, 0, 255])\nGlText.prototype.alignOffset = [0, 0]\n\n\n// whether viewport should be top↓bottom 2d one (true) or webgl one (false)\nGlText.normalViewport = false\n\n// size of an atlas\nGlText.maxAtlasSize = 1024\n\n// font atlas canvas is singleton\nGlText.atlasCanvas = document.createElement('canvas')\nGlText.atlasContext = GlText.atlasCanvas.getContext('2d', {alpha: false})\n\n// font-size used for metrics, atlas step calculation\nGlText.baseFontSize = 64\n\n// fonts storage\nGlText.fonts = {}\n\n// max number of different font atlases/textures cached\n// FIXME: enable atlas size limitation via LRU\n// GlText.atlasCacheSize = 64\n\nfunction isRegl (o) {\n\treturn typeof o === 'function' &&\n\to._gl &&\n\to.prop &&\n\to.texture &&\n\to.buffer\n}\n\n\nmodule.exports = GlText\n\n\n},{\"bit-twiddle\":92,\"color-normalize\":120,\"css-font\":139,\"detect-kerning\":166,\"es6-weak-map\":318,\"flatten-vertex-data\":227,\"font-atlas\":228,\"font-measure\":229,\"gl-util/context\":323,\"is-plain-obj\":422,\"object-assign\":454,\"parse-rect\":459,\"parse-unit\":461,\"pick-by-alias\":465,\"regl\":502,\"to-px\":539,\"typedarray-pool\":545}],318:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = _dereq_(\"./is-implemented\")() ? WeakMap : _dereq_(\"./polyfill\");\n\n},{\"./is-implemented\":319,\"./polyfill\":321}],319:[function(_dereq_,module,exports){\n\"use strict\";\n\nmodule.exports = function () {\n\tvar weakMap, obj;\n\n\tif (typeof WeakMap !== \"function\") return false;\n\ttry {\n\t\t// WebKit doesn't support arguments and crashes\n\t\tweakMap = new WeakMap([[obj = {}, \"one\"], [{}, \"two\"], [{}, \"three\"]]);\n\t} catch (e) {\n\t\treturn false;\n\t}\n\tif (String(weakMap) !== \"[object WeakMap]\") return false;\n\tif (typeof weakMap.set !== \"function\") return false;\n\tif (weakMap.set({}, 1) !== weakMap) return false;\n\tif (typeof weakMap.delete !== \"function\") return false;\n\tif (typeof weakMap.has !== \"function\") return false;\n\tif (weakMap.get(obj) !== \"one\") return false;\n\n\treturn true;\n};\n\n},{}],320:[function(_dereq_,module,exports){\n// Exports true if environment provides native `WeakMap` implementation, whatever that is.\n\n\"use strict\";\n\nmodule.exports = (function () {\n\tif (typeof WeakMap !== \"function\") return false;\n\treturn Object.prototype.toString.call(new WeakMap()) === \"[object WeakMap]\";\n}());\n\n},{}],321:[function(_dereq_,module,exports){\n\"use strict\";\n\nvar isValue           = _dereq_(\"es5-ext/object/is-value\")\n  , setPrototypeOf    = _dereq_(\"es5-ext/object/set-prototype-of\")\n  , object            = _dereq_(\"es5-ext/object/valid-object\")\n  , ensureValue       = _dereq_(\"es5-ext/object/valid-value\")\n  , randomUniq        = _dereq_(\"es5-ext/string/random-uniq\")\n  , d                 = _dereq_(\"d\")\n  , getIterator       = _dereq_(\"es6-iterator/get\")\n  , forOf             = _dereq_(\"es6-iterator/for-of\")\n  , toStringTagSymbol = _dereq_(\"es6-symbol\").toStringTag\n  , isNative          = _dereq_(\"./is-native-implemented\")\n\n  , isArray = Array.isArray, defineProperty = Object.defineProperty\n  , objHasOwnProperty = Object.prototype.hasOwnProperty, getPrototypeOf = Object.getPrototypeOf\n  , WeakMapPoly;\n\nmodule.exports = WeakMapPoly = function (/* Iterable*/) {\n\tvar iterable = arguments[0], self;\n\n\tif (!(this instanceof WeakMapPoly)) throw new TypeError(\"Constructor requires 'new'\");\n\tself = isNative && setPrototypeOf && (WeakMap !== WeakMapPoly)\n\t\t? setPrototypeOf(new WeakMap(), getPrototypeOf(this)) : this;\n\n\tif (isValue(iterable)) {\n\t\tif (!isArray(iterable)) iterable = getIterator(iterable);\n\t}\n\tdefineProperty(self, \"__weakMapData__\", d(\"c\", \"$weakMap$\" + randomUniq()));\n\tif (!iterable) return self;\n\tforOf(iterable, function (val) {\n\t\tensureValue(val);\n\t\tself.set(val[0], val[1]);\n\t});\n\treturn self;\n};\n\nif (isNative) {\n\tif (setPrototypeOf) setPrototypeOf(WeakMapPoly, WeakMap);\n\tWeakMapPoly.prototype = Object.create(WeakMap.prototype, { constructor: d(WeakMapPoly) });\n}\n\nObject.defineProperties(WeakMapPoly.prototype, {\n\tdelete: d(function (key) {\n\t\tif (objHasOwnProperty.call(object(key), this.__weakMapData__)) {\n\t\t\tdelete key[this.__weakMapData__];\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}),\n\tget: d(function (key) {\n\t\tif (!objHasOwnProperty.call(object(key), this.__weakMapData__)) return undefined;\n\t\treturn key[this.__weakMapData__];\n\t}),\n\thas: d(function (key) {\n\t\treturn objHasOwnProperty.call(object(key), this.__weakMapData__);\n\t}),\n\tset: d(function (key, value) {\n\t\tdefineProperty(object(key), this.__weakMapData__, d(\"c\", value));\n\t\treturn this;\n\t}),\n\ttoString: d(function () {\n\t\treturn \"[object WeakMap]\";\n\t})\n});\ndefineProperty(WeakMapPoly.prototype, toStringTagSymbol, d(\"c\", \"WeakMap\"));\n\n},{\"./is-native-implemented\":320,\"d\":151,\"es5-ext/object/is-value\":194,\"es5-ext/object/set-prototype-of\":200,\"es5-ext/object/valid-object\":204,\"es5-ext/object/valid-value\":205,\"es5-ext/string/random-uniq\":210,\"es6-iterator/for-of\":212,\"es6-iterator/get\":213,\"es6-symbol\":219}],322:[function(_dereq_,module,exports){\n'use strict'\n\nvar ndarray = _dereq_('ndarray')\nvar ops     = _dereq_('ndarray-ops')\nvar pool    = _dereq_('typedarray-pool')\n\nmodule.exports = createTexture2D\n\nvar linearTypes = null\nvar filterTypes = null\nvar wrapTypes   = null\n\nfunction lazyInitLinearTypes(gl) {\n  linearTypes = [\n    gl.LINEAR,\n    gl.NEAREST_MIPMAP_LINEAR,\n    gl.LINEAR_MIPMAP_NEAREST,\n    gl.LINEAR_MIPMAP_NEAREST\n  ]\n  filterTypes = [\n    gl.NEAREST,\n    gl.LINEAR,\n    gl.NEAREST_MIPMAP_NEAREST,\n    gl.NEAREST_MIPMAP_LINEAR,\n    gl.LINEAR_MIPMAP_NEAREST,\n    gl.LINEAR_MIPMAP_LINEAR\n  ]\n  wrapTypes = [\n    gl.REPEAT,\n    gl.CLAMP_TO_EDGE,\n    gl.MIRRORED_REPEAT\n  ]\n}\n\nfunction acceptTextureDOM (obj) {\n  return (\n    ('undefined' != typeof HTMLCanvasElement && obj instanceof HTMLCanvasElement) ||\n    ('undefined' != typeof HTMLImageElement && obj instanceof HTMLImageElement) ||\n    ('undefined' != typeof HTMLVideoElement && obj instanceof HTMLVideoElement) ||\n    ('undefined' != typeof ImageData && obj instanceof ImageData))\n}\n\nvar convertFloatToUint8 = function(out, inp) {\n  ops.muls(out, inp, 255.0)\n}\n\nfunction reshapeTexture(tex, w, h) {\n  var gl = tex.gl\n  var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE)\n  if(w < 0 || w > maxSize || h < 0 || h > maxSize) {\n    throw new Error('gl-texture2d: Invalid texture size')\n  }\n  tex._shape = [w, h]\n  tex.bind()\n  gl.texImage2D(gl.TEXTURE_2D, 0, tex.format, w, h, 0, tex.format, tex.type, null)\n  tex._mipLevels = [0]\n  return tex\n}\n\nfunction Texture2D(gl, handle, width, height, format, type) {\n  this.gl = gl\n  this.handle = handle\n  this.format = format\n  this.type = type\n  this._shape = [width, height]\n  this._mipLevels = [0]\n  this._magFilter = gl.NEAREST\n  this._minFilter = gl.NEAREST\n  this._wrapS = gl.CLAMP_TO_EDGE\n  this._wrapT = gl.CLAMP_TO_EDGE\n  this._anisoSamples = 1\n\n  var parent = this\n  var wrapVector = [this._wrapS, this._wrapT]\n  Object.defineProperties(wrapVector, [\n    {\n      get: function() {\n        return parent._wrapS\n      },\n      set: function(v) {\n        return parent.wrapS = v\n      }\n    },\n    {\n      get: function() {\n        return parent._wrapT\n      },\n      set: function(v) {\n        return parent.wrapT = v\n      }\n    }\n  ])\n  this._wrapVector = wrapVector\n\n  var shapeVector = [this._shape[0], this._shape[1]]\n  Object.defineProperties(shapeVector, [\n    {\n      get: function() {\n        return parent._shape[0]\n      },\n      set: function(v) {\n        return parent.width = v\n      }\n    },\n    {\n      get: function() {\n        return parent._shape[1]\n      },\n      set: function(v) {\n        return parent.height = v\n      }\n    }\n  ])\n  this._shapeVector = shapeVector\n}\n\nvar proto = Texture2D.prototype\n\nObject.defineProperties(proto, {\n  minFilter: {\n    get: function() {\n      return this._minFilter\n    },\n    set: function(v) {\n      this.bind()\n      var gl = this.gl\n      if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) {\n        if(!gl.getExtension('OES_texture_float_linear')) {\n          v = gl.NEAREST\n        }\n      }\n      if(filterTypes.indexOf(v) < 0) {\n        throw new Error('gl-texture2d: Unknown filter mode ' + v)\n      }\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, v)\n      return this._minFilter = v\n    }\n  },\n  magFilter: {\n    get: function() {\n      return this._magFilter\n    },\n    set: function(v) {\n      this.bind()\n      var gl = this.gl\n      if(this.type === gl.FLOAT && linearTypes.indexOf(v) >= 0) {\n        if(!gl.getExtension('OES_texture_float_linear')) {\n          v = gl.NEAREST\n        }\n      }\n      if(filterTypes.indexOf(v) < 0) {\n        throw new Error('gl-texture2d: Unknown filter mode ' + v)\n      }\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, v)\n      return this._magFilter = v\n    }\n  },\n  mipSamples: {\n    get: function() {\n      return this._anisoSamples\n    },\n    set: function(i) {\n      var psamples = this._anisoSamples\n      this._anisoSamples = Math.max(i, 1)|0\n      if(psamples !== this._anisoSamples) {\n        var ext = this.gl.getExtension('EXT_texture_filter_anisotropic')\n        if(ext) {\n          this.gl.texParameterf(this.gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, this._anisoSamples)\n        }\n      }\n      return this._anisoSamples\n    }\n  },\n  wrapS: {\n    get: function() {\n      return this._wrapS\n    },\n    set: function(v) {\n      this.bind()\n      if(wrapTypes.indexOf(v) < 0) {\n        throw new Error('gl-texture2d: Unknown wrap mode ' + v)\n      }\n      this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, v)\n      return this._wrapS = v\n    }\n  },\n  wrapT: {\n    get: function() {\n      return this._wrapT\n    },\n    set: function(v) {\n      this.bind()\n      if(wrapTypes.indexOf(v) < 0) {\n        throw new Error('gl-texture2d: Unknown wrap mode ' + v)\n      }\n      this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, v)\n      return this._wrapT = v\n    }\n  },\n  wrap: {\n    get: function() {\n      return this._wrapVector\n    },\n    set: function(v) {\n      if(!Array.isArray(v)) {\n        v = [v,v]\n      }\n      if(v.length !== 2) {\n        throw new Error('gl-texture2d: Must specify wrap mode for rows and columns')\n      }\n      for(var i=0; i<2; ++i) {\n        if(wrapTypes.indexOf(v[i]) < 0) {\n          throw new Error('gl-texture2d: Unknown wrap mode ' + v)\n        }\n      }\n      this._wrapS = v[0]\n      this._wrapT = v[1]\n\n      var gl = this.gl\n      this.bind()\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this._wrapS)\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this._wrapT)\n\n      return v\n    }\n  },\n  shape: {\n    get: function() {\n      return this._shapeVector\n    },\n    set: function(x) {\n      if(!Array.isArray(x)) {\n        x = [x|0,x|0]\n      } else {\n        if(x.length !== 2) {\n          throw new Error('gl-texture2d: Invalid texture shape')\n        }\n      }\n      reshapeTexture(this, x[0]|0, x[1]|0)\n      return [x[0]|0, x[1]|0]\n    }\n  },\n  width: {\n    get: function() {\n      return this._shape[0]\n    },\n    set: function(w) {\n      w = w|0\n      reshapeTexture(this, w, this._shape[1])\n      return w\n    }\n  },\n  height: {\n    get: function() {\n      return this._shape[1]\n    },\n    set: function(h) {\n      h = h|0\n      reshapeTexture(this, this._shape[0], h)\n      return h\n    }\n  }\n})\n\nproto.bind = function(unit) {\n  var gl = this.gl\n  if(unit !== undefined) {\n    gl.activeTexture(gl.TEXTURE0 + (unit|0))\n  }\n  gl.bindTexture(gl.TEXTURE_2D, this.handle)\n  if(unit !== undefined) {\n    return (unit|0)\n  }\n  return gl.getParameter(gl.ACTIVE_TEXTURE) - gl.TEXTURE0\n}\n\nproto.dispose = function() {\n  this.gl.deleteTexture(this.handle)\n}\n\nproto.generateMipmap = function() {\n  this.bind()\n  this.gl.generateMipmap(this.gl.TEXTURE_2D)\n\n  //Update mip levels\n  var l = Math.min(this._shape[0], this._shape[1])\n  for(var i=0; l>0; ++i, l>>>=1) {\n    if(this._mipLevels.indexOf(i) < 0) {\n      this._mipLevels.push(i)\n    }\n  }\n}\n\nproto.setPixels = function(data, x_off, y_off, mip_level) {\n  var gl = this.gl\n  this.bind()\n  if(Array.isArray(x_off)) {\n    mip_level = y_off\n    y_off = x_off[1]|0\n    x_off = x_off[0]|0\n  } else {\n    x_off = x_off || 0\n    y_off = y_off || 0\n  }\n  mip_level = mip_level || 0\n  var directData = acceptTextureDOM(data) ? data : data.raw\n  if(directData) {\n    var needsMip = this._mipLevels.indexOf(mip_level) < 0\n    if(needsMip) {\n      gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, directData)\n      this._mipLevels.push(mip_level)\n    } else {\n      gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, this.format, this.type, directData)\n    }\n  } else if(data.shape && data.stride && data.data) {\n    if(data.shape.length < 2 ||\n       x_off + data.shape[1] > this._shape[1]>>>mip_level ||\n       y_off + data.shape[0] > this._shape[0]>>>mip_level ||\n       x_off < 0 ||\n       y_off < 0) {\n      throw new Error('gl-texture2d: Texture dimensions are out of bounds')\n    }\n    texSubImageArray(gl, x_off, y_off, mip_level, this.format, this.type, this._mipLevels, data)\n  } else {\n    throw new Error('gl-texture2d: Unsupported data type')\n  }\n}\n\n\nfunction isPacked(shape, stride) {\n  if(shape.length === 3) {\n    return  (stride[2] === 1) &&\n            (stride[1] === shape[0]*shape[2]) &&\n            (stride[0] === shape[2])\n  }\n  return  (stride[0] === 1) &&\n          (stride[1] === shape[0])\n}\n\nfunction texSubImageArray(gl, x_off, y_off, mip_level, cformat, ctype, mipLevels, array) {\n  var dtype = array.dtype\n  var shape = array.shape.slice()\n  if(shape.length < 2 || shape.length > 3) {\n    throw new Error('gl-texture2d: Invalid ndarray, must be 2d or 3d')\n  }\n  var type = 0, format = 0\n  var packed = isPacked(shape, array.stride.slice())\n  if(dtype === 'float32') {\n    type = gl.FLOAT\n  } else if(dtype === 'float64') {\n    type = gl.FLOAT\n    packed = false\n    dtype = 'float32'\n  } else if(dtype === 'uint8') {\n    type = gl.UNSIGNED_BYTE\n  } else {\n    type = gl.UNSIGNED_BYTE\n    packed = false\n    dtype = 'uint8'\n  }\n  var channels = 1\n  if(shape.length === 2) {\n    format = gl.LUMINANCE\n    shape = [shape[0], shape[1], 1]\n    array = ndarray(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset)\n  } else if(shape.length === 3) {\n    if(shape[2] === 1) {\n      format = gl.ALPHA\n    } else if(shape[2] === 2) {\n      format = gl.LUMINANCE_ALPHA\n    } else if(shape[2] === 3) {\n      format = gl.RGB\n    } else if(shape[2] === 4) {\n      format = gl.RGBA\n    } else {\n      throw new Error('gl-texture2d: Invalid shape for pixel coords')\n    }\n    channels = shape[2]\n  } else {\n    throw new Error('gl-texture2d: Invalid shape for texture')\n  }\n  //For 1-channel textures allow conversion between formats\n  if((format  === gl.LUMINANCE || format  === gl.ALPHA) &&\n     (cformat === gl.LUMINANCE || cformat === gl.ALPHA)) {\n    format = cformat\n  }\n  if(format !== cformat) {\n    throw new Error('gl-texture2d: Incompatible texture format for setPixels')\n  }\n  var size = array.size\n  var needsMip = mipLevels.indexOf(mip_level) < 0\n  if(needsMip) {\n    mipLevels.push(mip_level)\n  }\n  if(type === ctype && packed) {\n    //Array data types are compatible, can directly copy into texture\n    if(array.offset === 0 && array.data.length === size) {\n      if(needsMip) {\n        gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, array.data)\n      } else {\n        gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, array.data)\n      }\n    } else {\n      if(needsMip) {\n        gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, array.data.subarray(array.offset, array.offset+size))\n      } else {\n        gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, array.data.subarray(array.offset, array.offset+size))\n      }\n    }\n  } else {\n    //Need to do type conversion to pack data into buffer\n    var pack_buffer\n    if(ctype === gl.FLOAT) {\n      pack_buffer = pool.mallocFloat32(size)\n    } else {\n      pack_buffer = pool.mallocUint8(size)\n    }\n    var pack_view = ndarray(pack_buffer, shape, [shape[2], shape[2]*shape[0], 1])\n    if(type === gl.FLOAT && ctype === gl.UNSIGNED_BYTE) {\n      convertFloatToUint8(pack_view, array)\n    } else {\n      ops.assign(pack_view, array)\n    }\n    if(needsMip) {\n      gl.texImage2D(gl.TEXTURE_2D, mip_level, cformat, shape[0], shape[1], 0, cformat, ctype, pack_buffer.subarray(0, size))\n    } else {\n      gl.texSubImage2D(gl.TEXTURE_2D, mip_level, x_off, y_off, shape[0], shape[1], cformat, ctype, pack_buffer.subarray(0, size))\n    }\n    if(ctype === gl.FLOAT) {\n      pool.freeFloat32(pack_buffer)\n    } else {\n      pool.freeUint8(pack_buffer)\n    }\n  }\n}\n\nfunction initTexture(gl) {\n  var tex = gl.createTexture()\n  gl.bindTexture(gl.TEXTURE_2D, tex)\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)\n  return tex\n}\n\nfunction createTextureShape(gl, width, height, format, type) {\n  var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE)\n  if(width < 0 || width > maxTextureSize || height < 0 || height  > maxTextureSize) {\n    throw new Error('gl-texture2d: Invalid texture shape')\n  }\n  if(type === gl.FLOAT && !gl.getExtension('OES_texture_float')) {\n    throw new Error('gl-texture2d: Floating point textures not supported on this platform')\n  }\n  var tex = initTexture(gl)\n  gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, type, null)\n  return new Texture2D(gl, tex, width, height, format, type)\n}\n\nfunction createTextureDOM(gl, directData, width, height, format, type) {\n  var tex = initTexture(gl)\n  gl.texImage2D(gl.TEXTURE_2D, 0, format, format, type, directData)\n  return new Texture2D(gl, tex, width, height, format, type)\n}\n\n//Creates a texture from an ndarray\nfunction createTextureArray(gl, array) {\n  var dtype = array.dtype\n  var shape = array.shape.slice()\n  var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE)\n  if(shape[0] < 0 || shape[0] > maxSize || shape[1] < 0 || shape[1] > maxSize) {\n    throw new Error('gl-texture2d: Invalid texture size')\n  }\n  var packed = isPacked(shape, array.stride.slice())\n  var type = 0\n  if(dtype === 'float32') {\n    type = gl.FLOAT\n  } else if(dtype === 'float64') {\n    type = gl.FLOAT\n    packed = false\n    dtype = 'float32'\n  } else if(dtype === 'uint8') {\n    type = gl.UNSIGNED_BYTE\n  } else {\n    type = gl.UNSIGNED_BYTE\n    packed = false\n    dtype = 'uint8'\n  }\n  var format = 0\n  if(shape.length === 2) {\n    format = gl.LUMINANCE\n    shape = [shape[0], shape[1], 1]\n    array = ndarray(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset)\n  } else if(shape.length === 3) {\n    if(shape[2] === 1) {\n      format = gl.ALPHA\n    } else if(shape[2] === 2) {\n      format = gl.LUMINANCE_ALPHA\n    } else if(shape[2] === 3) {\n      format = gl.RGB\n    } else if(shape[2] === 4) {\n      format = gl.RGBA\n    } else {\n      throw new Error('gl-texture2d: Invalid shape for pixel coords')\n    }\n  } else {\n    throw new Error('gl-texture2d: Invalid shape for texture')\n  }\n  if(type === gl.FLOAT && !gl.getExtension('OES_texture_float')) {\n    type = gl.UNSIGNED_BYTE\n    packed = false\n  }\n  var buffer, buf_store\n  var size = array.size\n  if(!packed) {\n    var stride = [shape[2], shape[2]*shape[0], 1]\n    buf_store = pool.malloc(size, dtype)\n    var buf_array = ndarray(buf_store, shape, stride, 0)\n    if((dtype === 'float32' || dtype === 'float64') && type === gl.UNSIGNED_BYTE) {\n      convertFloatToUint8(buf_array, array)\n    } else {\n      ops.assign(buf_array, array)\n    }\n    buffer = buf_store.subarray(0, size)\n  } else if (array.offset === 0 && array.data.length === size) {\n    buffer = array.data\n  } else {\n    buffer = array.data.subarray(array.offset, array.offset + size)\n  }\n  var tex = initTexture(gl)\n  gl.texImage2D(gl.TEXTURE_2D, 0, format, shape[0], shape[1], 0, format, type, buffer)\n  if(!packed) {\n    pool.free(buf_store)\n  }\n  return new Texture2D(gl, tex, shape[0], shape[1], format, type)\n}\n\nfunction createTexture2D(gl) {\n  if(arguments.length <= 1) {\n    throw new Error('gl-texture2d: Missing arguments for texture2d constructor')\n  }\n  if(!linearTypes) {\n    lazyInitLinearTypes(gl)\n  }\n  if(typeof arguments[1] === 'number') {\n    return createTextureShape(gl, arguments[1], arguments[2], arguments[3]||gl.RGBA, arguments[4]||gl.UNSIGNED_BYTE)\n  }\n  if(Array.isArray(arguments[1])) {\n    return createTextureShape(gl, arguments[1][0]|0, arguments[1][1]|0, arguments[2]||gl.RGBA, arguments[3]||gl.UNSIGNED_BYTE)\n  }\n  if(typeof arguments[1] === 'object') {\n    var obj = arguments[1]\n    var directData = acceptTextureDOM(obj) ? obj : obj.raw\n    if (directData) {\n      return createTextureDOM(gl, directData, obj.width|0, obj.height|0, arguments[2]||gl.RGBA, arguments[3]||gl.UNSIGNED_BYTE)\n    } else if(obj.shape && obj.data && obj.stride) {\n      return createTextureArray(gl, obj)\n    }\n  }\n  throw new Error('gl-texture2d: Invalid arguments for texture2d constructor')\n}\n\n},{\"ndarray\":450,\"ndarray-ops\":444,\"typedarray-pool\":545}],323:[function(_dereq_,module,exports){\n(function (global){\n/** @module  gl-util/context */\r\n'use strict'\r\n\r\nvar pick = _dereq_('pick-by-alias')\r\n\r\nmodule.exports = function setContext (o) {\r\n\tif (!o) o = {}\r\n\telse if (typeof o === 'string') o = {container: o}\r\n\r\n\t// HTMLCanvasElement\r\n\tif (isCanvas(o)) {\r\n\t\to = {container: o}\r\n\t}\r\n\t// HTMLElement\r\n\telse if (isElement(o)) {\r\n\t\to = {container: o}\r\n\t}\r\n\t// WebGLContext\r\n\telse if (isContext(o)) {\r\n\t\to = {gl: o}\r\n\t}\r\n\t// options object\r\n\telse {\r\n\t\to = pick(o, {\r\n\t\t\tcontainer: 'container target element el canvas holder parent parentNode wrapper use ref root node',\r\n\t\t\tgl: 'gl context webgl glContext',\r\n\t\t\tattrs: 'attributes attrs contextAttributes',\r\n\t\t\tpixelRatio: 'pixelRatio pxRatio px ratio pxratio pixelratio',\r\n\t\t\twidth: 'w width',\r\n\t\t\theight: 'h height'\r\n\t\t}, true)\r\n\t}\r\n\r\n\tif (!o.pixelRatio) o.pixelRatio = global.pixelRatio || 1\r\n\r\n\t// make sure there is container and canvas\r\n\tif (o.gl) {\r\n\t\treturn o.gl\r\n\t}\r\n\tif (o.canvas) {\r\n\t\to.container = o.canvas.parentNode\r\n\t}\r\n\tif (o.container) {\r\n\t\tif (typeof o.container === 'string') {\r\n\t\t\tvar c = document.querySelector(o.container)\r\n\t\t\tif (!c) throw Error('Element ' + o.container + ' is not found')\r\n\t\t\to.container = c\r\n\t\t}\r\n\t\tif (isCanvas(o.container)) {\r\n\t\t\to.canvas = o.container\r\n\t\t\to.container = o.canvas.parentNode\r\n\t\t}\r\n\t\telse if (!o.canvas) {\r\n\t\t\to.canvas = createCanvas()\r\n\t\t\to.container.appendChild(o.canvas)\r\n\t\t\tresize(o)\r\n\t\t}\r\n\t}\r\n\t// blank new canvas\r\n\telse if (!o.canvas) {\r\n\t\tif (typeof document !== 'undefined') {\r\n\t\t\to.container = document.body || document.documentElement\r\n\t\t\to.canvas = createCanvas()\r\n\t\t\to.container.appendChild(o.canvas)\r\n\t\t\tresize(o)\r\n\t\t}\r\n\t\telse {\r\n\t\t\tthrow Error('Not DOM environment. Use headless-gl.')\r\n\t\t}\r\n\t}\r\n\r\n\t// make sure there is context\r\n\tif (!o.gl) {\r\n\t\ttry {\r\n\t\t\to.gl = o.canvas.getContext('webgl', o.attrs)\r\n\t\t} catch (e) {\r\n\t\t\ttry {\r\n\t\t\t\to.gl = o.canvas.getContext('experimental-webgl', o.attrs)\r\n\t\t\t}\r\n\t\t\tcatch (e) {\r\n\t\t\t\to.gl = o.canvas.getContext('webgl-experimental', o.attrs)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn o.gl\r\n}\r\n\r\n\r\nfunction resize (o) {\r\n\tif (o.container) {\r\n\t\tif (o.container == document.body) {\r\n\t\t\tif (!document.body.style.width) o.canvas.width = o.width || (o.pixelRatio * global.innerWidth)\r\n\t\t\tif (!document.body.style.height) o.canvas.height = o.height || (o.pixelRatio * global.innerHeight)\r\n\t\t}\r\n\t\telse {\r\n\t\t\tvar bounds = o.container.getBoundingClientRect()\r\n\t\t\to.canvas.width = o.width || (bounds.right - bounds.left)\r\n\t\t\to.canvas.height = o.height || (bounds.bottom - bounds.top)\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction isCanvas (e) {\r\n\treturn typeof e.getContext === 'function'\r\n\t\t&& 'width' in e\r\n\t\t&& 'height' in e\r\n}\r\n\r\nfunction isElement (e) {\r\n\treturn typeof e.nodeName === 'string' &&\r\n\t\ttypeof e.appendChild === 'function' &&\r\n\t\ttypeof e.getBoundingClientRect === 'function'\r\n}\r\n\r\nfunction isContext (e) {\r\n\treturn typeof e.drawArrays === 'function' ||\r\n\t\ttypeof e.drawElements === 'function'\r\n}\r\n\r\nfunction createCanvas () {\r\n\tvar canvas = document.createElement('canvas')\r\n\tcanvas.style.position = 'absolute'\r\n\tcanvas.style.top = 0\r\n\tcanvas.style.left = 0\r\n\r\n\treturn canvas\r\n}\r\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"pick-by-alias\":465}],324:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction doBind(gl, elements, attributes) {\n  if(elements) {\n    elements.bind()\n  } else {\n    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null)\n  }\n  var nattribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS)|0\n  if(attributes) {\n    if(attributes.length > nattribs) {\n      throw new Error(\"gl-vao: Too many vertex attributes\")\n    }\n    for(var i=0; i<attributes.length; ++i) {\n      var attrib = attributes[i]\n      if(attrib.buffer) {\n        var buffer = attrib.buffer\n        var size = attrib.size || 4\n        var type = attrib.type || gl.FLOAT\n        var normalized = !!attrib.normalized\n        var stride = attrib.stride || 0\n        var offset = attrib.offset || 0\n        buffer.bind()\n        gl.enableVertexAttribArray(i)\n        gl.vertexAttribPointer(i, size, type, normalized, stride, offset)\n      } else {\n        if(typeof attrib === \"number\") {\n          gl.vertexAttrib1f(i, attrib)\n        } else if(attrib.length === 1) {\n          gl.vertexAttrib1f(i, attrib[0])\n        } else if(attrib.length === 2) {\n          gl.vertexAttrib2f(i, attrib[0], attrib[1])\n        } else if(attrib.length === 3) {\n          gl.vertexAttrib3f(i, attrib[0], attrib[1], attrib[2])\n        } else if(attrib.length === 4) {\n          gl.vertexAttrib4f(i, attrib[0], attrib[1], attrib[2], attrib[3])\n        } else {\n          throw new Error(\"gl-vao: Invalid vertex attribute\")\n        }\n        gl.disableVertexAttribArray(i)\n      }\n    }\n    for(; i<nattribs; ++i) {\n      gl.disableVertexAttribArray(i)\n    }\n  } else {\n    gl.bindBuffer(gl.ARRAY_BUFFER, null)\n    for(var i=0; i<nattribs; ++i) {\n      gl.disableVertexAttribArray(i)\n    }\n  }\n}\n\nmodule.exports = doBind\n},{}],325:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar bindAttribs = _dereq_(\"./do-bind.js\")\n\nfunction VAOEmulated(gl) {\n  this.gl = gl\n  this._elements = null\n  this._attributes = null\n  this._elementsType = gl.UNSIGNED_SHORT\n}\n\nVAOEmulated.prototype.bind = function() {\n  bindAttribs(this.gl, this._elements, this._attributes)\n}\n\nVAOEmulated.prototype.update = function(attributes, elements, elementsType) {\n  this._elements = elements\n  this._attributes = attributes\n  this._elementsType = elementsType || this.gl.UNSIGNED_SHORT\n}\n\nVAOEmulated.prototype.dispose = function() { }\nVAOEmulated.prototype.unbind = function() { }\n\nVAOEmulated.prototype.draw = function(mode, count, offset) {\n  offset = offset || 0\n  var gl = this.gl\n  if(this._elements) {\n    gl.drawElements(mode, count, this._elementsType, offset)\n  } else {\n    gl.drawArrays(mode, offset, count)\n  }\n}\n\nfunction createVAOEmulated(gl) {\n  return new VAOEmulated(gl)\n}\n\nmodule.exports = createVAOEmulated\n},{\"./do-bind.js\":324}],326:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar bindAttribs = _dereq_(\"./do-bind.js\")\n\nfunction VertexAttribute(location, dimension, a, b, c, d) {\n  this.location = location\n  this.dimension = dimension\n  this.a = a\n  this.b = b\n  this.c = c\n  this.d = d\n}\n\nVertexAttribute.prototype.bind = function(gl) {\n  switch(this.dimension) {\n    case 1:\n      gl.vertexAttrib1f(this.location, this.a)\n    break\n    case 2:\n      gl.vertexAttrib2f(this.location, this.a, this.b)\n    break\n    case 3:\n      gl.vertexAttrib3f(this.location, this.a, this.b, this.c)\n    break\n    case 4:\n      gl.vertexAttrib4f(this.location, this.a, this.b, this.c, this.d)\n    break\n  }\n}\n\nfunction VAONative(gl, ext, handle) {\n  this.gl = gl\n  this._ext = ext\n  this.handle = handle\n  this._attribs = []\n  this._useElements = false\n  this._elementsType = gl.UNSIGNED_SHORT\n}\n\nVAONative.prototype.bind = function() {\n  this._ext.bindVertexArrayOES(this.handle)\n  for(var i=0; i<this._attribs.length; ++i) {\n    this._attribs[i].bind(this.gl)\n  }\n}\n\nVAONative.prototype.unbind = function() {\n  this._ext.bindVertexArrayOES(null)\n}\n\nVAONative.prototype.dispose = function() {\n  this._ext.deleteVertexArrayOES(this.handle)\n}\n\nVAONative.prototype.update = function(attributes, elements, elementsType) {\n  this.bind()\n  bindAttribs(this.gl, elements, attributes)\n  this.unbind()\n  this._attribs.length = 0\n  if(attributes)\n  for(var i=0; i<attributes.length; ++i) {\n    var a = attributes[i]\n    if(typeof a === \"number\") {\n      this._attribs.push(new VertexAttribute(i, 1, a))\n    } else if(Array.isArray(a)) {\n      this._attribs.push(new VertexAttribute(i, a.length, a[0], a[1], a[2], a[3]))\n    }\n  }\n  this._useElements = !!elements\n  this._elementsType = elementsType || this.gl.UNSIGNED_SHORT\n}\n\nVAONative.prototype.draw = function(mode, count, offset) {\n  offset = offset || 0\n  var gl = this.gl\n  if(this._useElements) {\n    gl.drawElements(mode, count, this._elementsType, offset)\n  } else {\n    gl.drawArrays(mode, offset, count)\n  }\n}\n\nfunction createVAONative(gl, ext) {\n  return new VAONative(gl, ext, ext.createVertexArrayOES())\n}\n\nmodule.exports = createVAONative\n},{\"./do-bind.js\":324}],327:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar createVAONative = _dereq_(\"./lib/vao-native.js\")\nvar createVAOEmulated = _dereq_(\"./lib/vao-emulated.js\")\n\nfunction ExtensionShim (gl) {\n  this.bindVertexArrayOES = gl.bindVertexArray.bind(gl)\n  this.createVertexArrayOES = gl.createVertexArray.bind(gl)\n  this.deleteVertexArrayOES = gl.deleteVertexArray.bind(gl)\n}\n\nfunction createVAO(gl, attributes, elements, elementsType) {\n  var ext = gl.createVertexArray\n    ? new ExtensionShim(gl)\n    : gl.getExtension('OES_vertex_array_object')\n  var vao\n\n  if(ext) {\n    vao = createVAONative(gl, ext)\n  } else {\n    vao = createVAOEmulated(gl)\n  }\n  vao.update(attributes, elements, elementsType)\n  return vao\n}\n\nmodule.exports = createVAO\n\n},{\"./lib/vao-emulated.js\":325,\"./lib/vao-native.js\":326}],328:[function(_dereq_,module,exports){\nmodule.exports = add;\n\n/**\n * Adds two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nfunction add(out, a, b) {\n    out[0] = a[0] + b[0]\n    out[1] = a[1] + b[1]\n    out[2] = a[2] + b[2]\n    return out\n}\n},{}],329:[function(_dereq_,module,exports){\nmodule.exports = angle\n\nvar fromValues = _dereq_('./fromValues')\nvar normalize = _dereq_('./normalize')\nvar dot = _dereq_('./dot')\n\n/**\n * Get the angle between two 3D vectors\n * @param {vec3} a The first operand\n * @param {vec3} b The second operand\n * @returns {Number} The angle in radians\n */\nfunction angle(a, b) {\n    var tempA = fromValues(a[0], a[1], a[2])\n    var tempB = fromValues(b[0], b[1], b[2])\n \n    normalize(tempA, tempA)\n    normalize(tempB, tempB)\n \n    var cosine = dot(tempA, tempB)\n\n    if(cosine > 1.0){\n        return 0\n    } else {\n        return Math.acos(cosine)\n    }     \n}\n\n},{\"./dot\":339,\"./fromValues\":345,\"./normalize\":356}],330:[function(_dereq_,module,exports){\nmodule.exports = ceil\n\n/**\n * Math.ceil the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to ceil\n * @returns {vec3} out\n */\nfunction ceil(out, a) {\n  out[0] = Math.ceil(a[0])\n  out[1] = Math.ceil(a[1])\n  out[2] = Math.ceil(a[2])\n  return out\n}\n\n},{}],331:[function(_dereq_,module,exports){\nmodule.exports = clone;\n\n/**\n * Creates a new vec3 initialized with values from an existing vector\n *\n * @param {vec3} a vector to clone\n * @returns {vec3} a new 3D vector\n */\nfunction clone(a) {\n    var out = new Float32Array(3)\n    out[0] = a[0]\n    out[1] = a[1]\n    out[2] = a[2]\n    return out\n}\n},{}],332:[function(_dereq_,module,exports){\nmodule.exports = copy;\n\n/**\n * Copy the values from one vec3 to another\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the source vector\n * @returns {vec3} out\n */\nfunction copy(out, a) {\n    out[0] = a[0]\n    out[1] = a[1]\n    out[2] = a[2]\n    return out\n}\n},{}],333:[function(_dereq_,module,exports){\nmodule.exports = create;\n\n/**\n * Creates a new, empty vec3\n *\n * @returns {vec3} a new 3D vector\n */\nfunction create() {\n    var out = new Float32Array(3)\n    out[0] = 0\n    out[1] = 0\n    out[2] = 0\n    return out\n}\n},{}],334:[function(_dereq_,module,exports){\nmodule.exports = cross;\n\n/**\n * Computes the cross product of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nfunction cross(out, a, b) {\n    var ax = a[0], ay = a[1], az = a[2],\n        bx = b[0], by = b[1], bz = b[2]\n\n    out[0] = ay * bz - az * by\n    out[1] = az * bx - ax * bz\n    out[2] = ax * by - ay * bx\n    return out\n}\n},{}],335:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('./distance')\n\n},{\"./distance\":336}],336:[function(_dereq_,module,exports){\nmodule.exports = distance;\n\n/**\n * Calculates the euclidian distance between two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} distance between a and b\n */\nfunction distance(a, b) {\n    var x = b[0] - a[0],\n        y = b[1] - a[1],\n        z = b[2] - a[2]\n    return Math.sqrt(x*x + y*y + z*z)\n}\n},{}],337:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('./divide')\n\n},{\"./divide\":338}],338:[function(_dereq_,module,exports){\nmodule.exports = divide;\n\n/**\n * Divides two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nfunction divide(out, a, b) {\n    out[0] = a[0] / b[0]\n    out[1] = a[1] / b[1]\n    out[2] = a[2] / b[2]\n    return out\n}\n},{}],339:[function(_dereq_,module,exports){\nmodule.exports = dot;\n\n/**\n * Calculates the dot product of two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} dot product of a and b\n */\nfunction dot(a, b) {\n    return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]\n}\n},{}],340:[function(_dereq_,module,exports){\nmodule.exports = 0.000001\n\n},{}],341:[function(_dereq_,module,exports){\nmodule.exports = equals\n\nvar EPSILON = _dereq_('./epsilon')\n\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {vec3} a The first vector.\n * @param {vec3} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nfunction equals(a, b) {\n  var a0 = a[0]\n  var a1 = a[1]\n  var a2 = a[2]\n  var b0 = b[0]\n  var b1 = b[1]\n  var b2 = b[2]\n  return (Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n          Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&\n          Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)))\n}\n\n},{\"./epsilon\":340}],342:[function(_dereq_,module,exports){\nmodule.exports = exactEquals\n\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {vec3} a The first vector.\n * @param {vec3} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nfunction exactEquals(a, b) {\n  return a[0] === b[0] && a[1] === b[1] && a[2] === b[2]\n}\n\n},{}],343:[function(_dereq_,module,exports){\nmodule.exports = floor\n\n/**\n * Math.floor the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to floor\n * @returns {vec3} out\n */\nfunction floor(out, a) {\n  out[0] = Math.floor(a[0])\n  out[1] = Math.floor(a[1])\n  out[2] = Math.floor(a[2])\n  return out\n}\n\n},{}],344:[function(_dereq_,module,exports){\nmodule.exports = forEach;\n\nvar vec = _dereq_('./create')()\n\n/**\n * Perform some operation over an array of vec3s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\nfunction forEach(a, stride, offset, count, fn, arg) {\n        var i, l\n        if(!stride) {\n            stride = 3\n        }\n\n        if(!offset) {\n            offset = 0\n        }\n        \n        if(count) {\n            l = Math.min((count * stride) + offset, a.length)\n        } else {\n            l = a.length\n        }\n\n        for(i = offset; i < l; i += stride) {\n            vec[0] = a[i] \n            vec[1] = a[i+1] \n            vec[2] = a[i+2]\n            fn(vec, vec, arg)\n            a[i] = vec[0] \n            a[i+1] = vec[1] \n            a[i+2] = vec[2]\n        }\n        \n        return a\n}\n},{\"./create\":333}],345:[function(_dereq_,module,exports){\nmodule.exports = fromValues;\n\n/**\n * Creates a new vec3 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @returns {vec3} a new 3D vector\n */\nfunction fromValues(x, y, z) {\n    var out = new Float32Array(3)\n    out[0] = x\n    out[1] = y\n    out[2] = z\n    return out\n}\n},{}],346:[function(_dereq_,module,exports){\nmodule.exports = {\n  EPSILON: _dereq_('./epsilon')\n  , create: _dereq_('./create')\n  , clone: _dereq_('./clone')\n  , angle: _dereq_('./angle')\n  , fromValues: _dereq_('./fromValues')\n  , copy: _dereq_('./copy')\n  , set: _dereq_('./set')\n  , equals: _dereq_('./equals')\n  , exactEquals: _dereq_('./exactEquals')\n  , add: _dereq_('./add')\n  , subtract: _dereq_('./subtract')\n  , sub: _dereq_('./sub')\n  , multiply: _dereq_('./multiply')\n  , mul: _dereq_('./mul')\n  , divide: _dereq_('./divide')\n  , div: _dereq_('./div')\n  , min: _dereq_('./min')\n  , max: _dereq_('./max')\n  , floor: _dereq_('./floor')\n  , ceil: _dereq_('./ceil')\n  , round: _dereq_('./round')\n  , scale: _dereq_('./scale')\n  , scaleAndAdd: _dereq_('./scaleAndAdd')\n  , distance: _dereq_('./distance')\n  , dist: _dereq_('./dist')\n  , squaredDistance: _dereq_('./squaredDistance')\n  , sqrDist: _dereq_('./sqrDist')\n  , length: _dereq_('./length')\n  , len: _dereq_('./len')\n  , squaredLength: _dereq_('./squaredLength')\n  , sqrLen: _dereq_('./sqrLen')\n  , negate: _dereq_('./negate')\n  , inverse: _dereq_('./inverse')\n  , normalize: _dereq_('./normalize')\n  , dot: _dereq_('./dot')\n  , cross: _dereq_('./cross')\n  , lerp: _dereq_('./lerp')\n  , random: _dereq_('./random')\n  , transformMat4: _dereq_('./transformMat4')\n  , transformMat3: _dereq_('./transformMat3')\n  , transformQuat: _dereq_('./transformQuat')\n  , rotateX: _dereq_('./rotateX')\n  , rotateY: _dereq_('./rotateY')\n  , rotateZ: _dereq_('./rotateZ')\n  , forEach: _dereq_('./forEach')\n}\n\n},{\"./add\":328,\"./angle\":329,\"./ceil\":330,\"./clone\":331,\"./copy\":332,\"./create\":333,\"./cross\":334,\"./dist\":335,\"./distance\":336,\"./div\":337,\"./divide\":338,\"./dot\":339,\"./epsilon\":340,\"./equals\":341,\"./exactEquals\":342,\"./floor\":343,\"./forEach\":344,\"./fromValues\":345,\"./inverse\":347,\"./len\":348,\"./length\":349,\"./lerp\":350,\"./max\":351,\"./min\":352,\"./mul\":353,\"./multiply\":354,\"./negate\":355,\"./normalize\":356,\"./random\":357,\"./rotateX\":358,\"./rotateY\":359,\"./rotateZ\":360,\"./round\":361,\"./scale\":362,\"./scaleAndAdd\":363,\"./set\":364,\"./sqrDist\":365,\"./sqrLen\":366,\"./squaredDistance\":367,\"./squaredLength\":368,\"./sub\":369,\"./subtract\":370,\"./transformMat3\":371,\"./transformMat4\":372,\"./transformQuat\":373}],347:[function(_dereq_,module,exports){\nmodule.exports = inverse;\n\n/**\n * Returns the inverse of the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to invert\n * @returns {vec3} out\n */\nfunction inverse(out, a) {\n  out[0] = 1.0 / a[0]\n  out[1] = 1.0 / a[1]\n  out[2] = 1.0 / a[2]\n  return out\n}\n},{}],348:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('./length')\n\n},{\"./length\":349}],349:[function(_dereq_,module,exports){\nmodule.exports = length;\n\n/**\n * Calculates the length of a vec3\n *\n * @param {vec3} a vector to calculate length of\n * @returns {Number} length of a\n */\nfunction length(a) {\n    var x = a[0],\n        y = a[1],\n        z = a[2]\n    return Math.sqrt(x*x + y*y + z*z)\n}\n},{}],350:[function(_dereq_,module,exports){\nmodule.exports = lerp;\n\n/**\n * Performs a linear interpolation between two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec3} out\n */\nfunction lerp(out, a, b, t) {\n    var ax = a[0],\n        ay = a[1],\n        az = a[2]\n    out[0] = ax + t * (b[0] - ax)\n    out[1] = ay + t * (b[1] - ay)\n    out[2] = az + t * (b[2] - az)\n    return out\n}\n},{}],351:[function(_dereq_,module,exports){\nmodule.exports = max;\n\n/**\n * Returns the maximum of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nfunction max(out, a, b) {\n    out[0] = Math.max(a[0], b[0])\n    out[1] = Math.max(a[1], b[1])\n    out[2] = Math.max(a[2], b[2])\n    return out\n}\n},{}],352:[function(_dereq_,module,exports){\nmodule.exports = min;\n\n/**\n * Returns the minimum of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nfunction min(out, a, b) {\n    out[0] = Math.min(a[0], b[0])\n    out[1] = Math.min(a[1], b[1])\n    out[2] = Math.min(a[2], b[2])\n    return out\n}\n},{}],353:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('./multiply')\n\n},{\"./multiply\":354}],354:[function(_dereq_,module,exports){\nmodule.exports = multiply;\n\n/**\n * Multiplies two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nfunction multiply(out, a, b) {\n    out[0] = a[0] * b[0]\n    out[1] = a[1] * b[1]\n    out[2] = a[2] * b[2]\n    return out\n}\n},{}],355:[function(_dereq_,module,exports){\nmodule.exports = negate;\n\n/**\n * Negates the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to negate\n * @returns {vec3} out\n */\nfunction negate(out, a) {\n    out[0] = -a[0]\n    out[1] = -a[1]\n    out[2] = -a[2]\n    return out\n}\n},{}],356:[function(_dereq_,module,exports){\nmodule.exports = normalize;\n\n/**\n * Normalize a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to normalize\n * @returns {vec3} out\n */\nfunction normalize(out, a) {\n    var x = a[0],\n        y = a[1],\n        z = a[2]\n    var len = x*x + y*y + z*z\n    if (len > 0) {\n        //TODO: evaluate use of glm_invsqrt here?\n        len = 1 / Math.sqrt(len)\n        out[0] = a[0] * len\n        out[1] = a[1] * len\n        out[2] = a[2] * len\n    }\n    return out\n}\n},{}],357:[function(_dereq_,module,exports){\nmodule.exports = random;\n\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec3} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec3} out\n */\nfunction random(out, scale) {\n    scale = scale || 1.0\n\n    var r = Math.random() * 2.0 * Math.PI\n    var z = (Math.random() * 2.0) - 1.0\n    var zScale = Math.sqrt(1.0-z*z) * scale\n\n    out[0] = Math.cos(r) * zScale\n    out[1] = Math.sin(r) * zScale\n    out[2] = z * scale\n    return out\n}\n},{}],358:[function(_dereq_,module,exports){\nmodule.exports = rotateX;\n\n/**\n * Rotate a 3D vector around the x-axis\n * @param {vec3} out The receiving vec3\n * @param {vec3} a The vec3 point to rotate\n * @param {vec3} b The origin of the rotation\n * @param {Number} c The angle of rotation\n * @returns {vec3} out\n */\nfunction rotateX(out, a, b, c){\n    var by = b[1]\n    var bz = b[2]\n\n    // Translate point to the origin\n    var py = a[1] - by\n    var pz = a[2] - bz\n\n    var sc = Math.sin(c)\n    var cc = Math.cos(c)\n\n    // perform rotation and translate to correct position\n    out[0] = a[0]\n    out[1] = by + py * cc - pz * sc\n    out[2] = bz + py * sc + pz * cc\n\n    return out\n}\n\n},{}],359:[function(_dereq_,module,exports){\nmodule.exports = rotateY;\n\n/**\n * Rotate a 3D vector around the y-axis\n * @param {vec3} out The receiving vec3\n * @param {vec3} a The vec3 point to rotate\n * @param {vec3} b The origin of the rotation\n * @param {Number} c The angle of rotation\n * @returns {vec3} out\n */\nfunction rotateY(out, a, b, c){\n    var bx = b[0]\n    var bz = b[2]\n\n    // translate point to the origin\n    var px = a[0] - bx\n    var pz = a[2] - bz\n    \n    var sc = Math.sin(c)\n    var cc = Math.cos(c)\n  \n    // perform rotation and translate to correct position\n    out[0] = bx + pz * sc + px * cc\n    out[1] = a[1]\n    out[2] = bz + pz * cc - px * sc\n  \n    return out\n}\n\n},{}],360:[function(_dereq_,module,exports){\nmodule.exports = rotateZ;\n\n/**\n * Rotate a 3D vector around the z-axis\n * @param {vec3} out The receiving vec3\n * @param {vec3} a The vec3 point to rotate\n * @param {vec3} b The origin of the rotation\n * @param {Number} c The angle of rotation\n * @returns {vec3} out\n */\nfunction rotateZ(out, a, b, c){\n    var bx = b[0]\n    var by = b[1]\n\n    //Translate point to the origin\n    var px = a[0] - bx\n    var py = a[1] - by\n  \n    var sc = Math.sin(c)\n    var cc = Math.cos(c)\n\n    // perform rotation and translate to correct position\n    out[0] = bx + px * cc - py * sc\n    out[1] = by + px * sc + py * cc\n    out[2] = a[2]\n  \n    return out\n}\n\n},{}],361:[function(_dereq_,module,exports){\nmodule.exports = round\n\n/**\n * Math.round the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to round\n * @returns {vec3} out\n */\nfunction round(out, a) {\n  out[0] = Math.round(a[0])\n  out[1] = Math.round(a[1])\n  out[2] = Math.round(a[2])\n  return out\n}\n\n},{}],362:[function(_dereq_,module,exports){\nmodule.exports = scale;\n\n/**\n * Scales a vec3 by a scalar number\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec3} out\n */\nfunction scale(out, a, b) {\n    out[0] = a[0] * b\n    out[1] = a[1] * b\n    out[2] = a[2] * b\n    return out\n}\n},{}],363:[function(_dereq_,module,exports){\nmodule.exports = scaleAndAdd;\n\n/**\n * Adds two vec3's after scaling the second operand by a scalar value\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec3} out\n */\nfunction scaleAndAdd(out, a, b, scale) {\n    out[0] = a[0] + (b[0] * scale)\n    out[1] = a[1] + (b[1] * scale)\n    out[2] = a[2] + (b[2] * scale)\n    return out\n}\n},{}],364:[function(_dereq_,module,exports){\nmodule.exports = set;\n\n/**\n * Set the components of a vec3 to the given values\n *\n * @param {vec3} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @returns {vec3} out\n */\nfunction set(out, x, y, z) {\n    out[0] = x\n    out[1] = y\n    out[2] = z\n    return out\n}\n},{}],365:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('./squaredDistance')\n\n},{\"./squaredDistance\":367}],366:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('./squaredLength')\n\n},{\"./squaredLength\":368}],367:[function(_dereq_,module,exports){\nmodule.exports = squaredDistance;\n\n/**\n * Calculates the squared euclidian distance between two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} squared distance between a and b\n */\nfunction squaredDistance(a, b) {\n    var x = b[0] - a[0],\n        y = b[1] - a[1],\n        z = b[2] - a[2]\n    return x*x + y*y + z*z\n}\n},{}],368:[function(_dereq_,module,exports){\nmodule.exports = squaredLength;\n\n/**\n * Calculates the squared length of a vec3\n *\n * @param {vec3} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nfunction squaredLength(a) {\n    var x = a[0],\n        y = a[1],\n        z = a[2]\n    return x*x + y*y + z*z\n}\n},{}],369:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('./subtract')\n\n},{\"./subtract\":370}],370:[function(_dereq_,module,exports){\nmodule.exports = subtract;\n\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nfunction subtract(out, a, b) {\n    out[0] = a[0] - b[0]\n    out[1] = a[1] - b[1]\n    out[2] = a[2] - b[2]\n    return out\n}\n},{}],371:[function(_dereq_,module,exports){\nmodule.exports = transformMat3;\n\n/**\n * Transforms the vec3 with a mat3.\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {mat4} m the 3x3 matrix to transform with\n * @returns {vec3} out\n */\nfunction transformMat3(out, a, m) {\n    var x = a[0], y = a[1], z = a[2]\n    out[0] = x * m[0] + y * m[3] + z * m[6]\n    out[1] = x * m[1] + y * m[4] + z * m[7]\n    out[2] = x * m[2] + y * m[5] + z * m[8]\n    return out\n}\n},{}],372:[function(_dereq_,module,exports){\nmodule.exports = transformMat4;\n\n/**\n * Transforms the vec3 with a mat4.\n * 4th vector component is implicitly '1'\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec3} out\n */\nfunction transformMat4(out, a, m) {\n    var x = a[0], y = a[1], z = a[2],\n        w = m[3] * x + m[7] * y + m[11] * z + m[15]\n    w = w || 1.0\n    out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w\n    out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w\n    out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w\n    return out\n}\n},{}],373:[function(_dereq_,module,exports){\nmodule.exports = transformQuat;\n\n/**\n * Transforms the vec3 with a quat\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {quat} q quaternion to transform with\n * @returns {vec3} out\n */\nfunction transformQuat(out, a, q) {\n    // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations\n\n    var x = a[0], y = a[1], z = a[2],\n        qx = q[0], qy = q[1], qz = q[2], qw = q[3],\n\n        // calculate quat * vec\n        ix = qw * x + qy * z - qz * y,\n        iy = qw * y + qz * x - qx * z,\n        iz = qw * z + qx * y - qy * x,\n        iw = -qx * x - qy * y - qz * z\n\n    // calculate result * inverse quat\n    out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy\n    out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz\n    out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx\n    return out\n}\n},{}],374:[function(_dereq_,module,exports){\nmodule.exports = add\n\n/**\n * Adds two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nfunction add (out, a, b) {\n  out[0] = a[0] + b[0]\n  out[1] = a[1] + b[1]\n  out[2] = a[2] + b[2]\n  out[3] = a[3] + b[3]\n  return out\n}\n\n},{}],375:[function(_dereq_,module,exports){\nmodule.exports = clone\n\n/**\n * Creates a new vec4 initialized with values from an existing vector\n *\n * @param {vec4} a vector to clone\n * @returns {vec4} a new 4D vector\n */\nfunction clone (a) {\n  var out = new Float32Array(4)\n  out[0] = a[0]\n  out[1] = a[1]\n  out[2] = a[2]\n  out[3] = a[3]\n  return out\n}\n\n},{}],376:[function(_dereq_,module,exports){\nmodule.exports = copy\n\n/**\n * Copy the values from one vec4 to another\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the source vector\n * @returns {vec4} out\n */\nfunction copy (out, a) {\n  out[0] = a[0]\n  out[1] = a[1]\n  out[2] = a[2]\n  out[3] = a[3]\n  return out\n}\n\n},{}],377:[function(_dereq_,module,exports){\nmodule.exports = create\n\n/**\n * Creates a new, empty vec4\n *\n * @returns {vec4} a new 4D vector\n */\nfunction create () {\n  var out = new Float32Array(4)\n  out[0] = 0\n  out[1] = 0\n  out[2] = 0\n  out[3] = 0\n  return out\n}\n\n},{}],378:[function(_dereq_,module,exports){\nmodule.exports = distance\n\n/**\n * Calculates the euclidian distance between two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} distance between a and b\n */\nfunction distance (a, b) {\n  var x = b[0] - a[0],\n    y = b[1] - a[1],\n    z = b[2] - a[2],\n    w = b[3] - a[3]\n  return Math.sqrt(x * x + y * y + z * z + w * w)\n}\n\n},{}],379:[function(_dereq_,module,exports){\nmodule.exports = divide\n\n/**\n * Divides two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nfunction divide (out, a, b) {\n  out[0] = a[0] / b[0]\n  out[1] = a[1] / b[1]\n  out[2] = a[2] / b[2]\n  out[3] = a[3] / b[3]\n  return out\n}\n\n},{}],380:[function(_dereq_,module,exports){\nmodule.exports = dot\n\n/**\n * Calculates the dot product of two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} dot product of a and b\n */\nfunction dot (a, b) {\n  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]\n}\n\n},{}],381:[function(_dereq_,module,exports){\nmodule.exports = fromValues\n\n/**\n * Creates a new vec4 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {vec4} a new 4D vector\n */\nfunction fromValues (x, y, z, w) {\n  var out = new Float32Array(4)\n  out[0] = x\n  out[1] = y\n  out[2] = z\n  out[3] = w\n  return out\n}\n\n},{}],382:[function(_dereq_,module,exports){\nmodule.exports = {\n  create: _dereq_('./create'),\n  clone: _dereq_('./clone'),\n  fromValues: _dereq_('./fromValues'),\n  copy: _dereq_('./copy'),\n  set: _dereq_('./set'),\n  add: _dereq_('./add'),\n  subtract: _dereq_('./subtract'),\n  multiply: _dereq_('./multiply'),\n  divide: _dereq_('./divide'),\n  min: _dereq_('./min'),\n  max: _dereq_('./max'),\n  scale: _dereq_('./scale'),\n  scaleAndAdd: _dereq_('./scaleAndAdd'),\n  distance: _dereq_('./distance'),\n  squaredDistance: _dereq_('./squaredDistance'),\n  length: _dereq_('./length'),\n  squaredLength: _dereq_('./squaredLength'),\n  negate: _dereq_('./negate'),\n  inverse: _dereq_('./inverse'),\n  normalize: _dereq_('./normalize'),\n  dot: _dereq_('./dot'),\n  lerp: _dereq_('./lerp'),\n  random: _dereq_('./random'),\n  transformMat4: _dereq_('./transformMat4'),\n  transformQuat: _dereq_('./transformQuat')\n}\n\n},{\"./add\":374,\"./clone\":375,\"./copy\":376,\"./create\":377,\"./distance\":378,\"./divide\":379,\"./dot\":380,\"./fromValues\":381,\"./inverse\":383,\"./length\":384,\"./lerp\":385,\"./max\":386,\"./min\":387,\"./multiply\":388,\"./negate\":389,\"./normalize\":390,\"./random\":391,\"./scale\":392,\"./scaleAndAdd\":393,\"./set\":394,\"./squaredDistance\":395,\"./squaredLength\":396,\"./subtract\":397,\"./transformMat4\":398,\"./transformQuat\":399}],383:[function(_dereq_,module,exports){\nmodule.exports = inverse\n\n/**\n * Returns the inverse of the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to invert\n * @returns {vec4} out\n */\nfunction inverse (out, a) {\n  out[0] = 1.0 / a[0]\n  out[1] = 1.0 / a[1]\n  out[2] = 1.0 / a[2]\n  out[3] = 1.0 / a[3]\n  return out\n}\n\n},{}],384:[function(_dereq_,module,exports){\nmodule.exports = length\n\n/**\n * Calculates the length of a vec4\n *\n * @param {vec4} a vector to calculate length of\n * @returns {Number} length of a\n */\nfunction length (a) {\n  var x = a[0],\n    y = a[1],\n    z = a[2],\n    w = a[3]\n  return Math.sqrt(x * x + y * y + z * z + w * w)\n}\n\n},{}],385:[function(_dereq_,module,exports){\nmodule.exports = lerp\n\n/**\n * Performs a linear interpolation between two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec4} out\n */\nfunction lerp (out, a, b, t) {\n  var ax = a[0],\n    ay = a[1],\n    az = a[2],\n    aw = a[3]\n  out[0] = ax + t * (b[0] - ax)\n  out[1] = ay + t * (b[1] - ay)\n  out[2] = az + t * (b[2] - az)\n  out[3] = aw + t * (b[3] - aw)\n  return out\n}\n\n},{}],386:[function(_dereq_,module,exports){\nmodule.exports = max\n\n/**\n * Returns the maximum of two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nfunction max (out, a, b) {\n  out[0] = Math.max(a[0], b[0])\n  out[1] = Math.max(a[1], b[1])\n  out[2] = Math.max(a[2], b[2])\n  out[3] = Math.max(a[3], b[3])\n  return out\n}\n\n},{}],387:[function(_dereq_,module,exports){\nmodule.exports = min\n\n/**\n * Returns the minimum of two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nfunction min (out, a, b) {\n  out[0] = Math.min(a[0], b[0])\n  out[1] = Math.min(a[1], b[1])\n  out[2] = Math.min(a[2], b[2])\n  out[3] = Math.min(a[3], b[3])\n  return out\n}\n\n},{}],388:[function(_dereq_,module,exports){\nmodule.exports = multiply\n\n/**\n * Multiplies two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nfunction multiply (out, a, b) {\n  out[0] = a[0] * b[0]\n  out[1] = a[1] * b[1]\n  out[2] = a[2] * b[2]\n  out[3] = a[3] * b[3]\n  return out\n}\n\n},{}],389:[function(_dereq_,module,exports){\nmodule.exports = negate\n\n/**\n * Negates the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to negate\n * @returns {vec4} out\n */\nfunction negate (out, a) {\n  out[0] = -a[0]\n  out[1] = -a[1]\n  out[2] = -a[2]\n  out[3] = -a[3]\n  return out\n}\n\n},{}],390:[function(_dereq_,module,exports){\nmodule.exports = normalize\n\n/**\n * Normalize a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to normalize\n * @returns {vec4} out\n */\nfunction normalize (out, a) {\n  var x = a[0],\n    y = a[1],\n    z = a[2],\n    w = a[3]\n  var len = x * x + y * y + z * z + w * w\n  if (len > 0) {\n    len = 1 / Math.sqrt(len)\n    out[0] = x * len\n    out[1] = y * len\n    out[2] = z * len\n    out[3] = w * len\n  }\n  return out\n}\n\n},{}],391:[function(_dereq_,module,exports){\nvar vecNormalize = _dereq_('./normalize')\nvar vecScale = _dereq_('./scale')\n\nmodule.exports = random\n\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec4} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec4} out\n */\nfunction random (out, scale) {\n  scale = scale || 1.0\n\n  // TODO: This is a pretty awful way of doing this. Find something better.\n  out[0] = Math.random()\n  out[1] = Math.random()\n  out[2] = Math.random()\n  out[3] = Math.random()\n  vecNormalize(out, out)\n  vecScale(out, out, scale)\n  return out\n}\n\n},{\"./normalize\":390,\"./scale\":392}],392:[function(_dereq_,module,exports){\nmodule.exports = scale\n\n/**\n * Scales a vec4 by a scalar number\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec4} out\n */\nfunction scale (out, a, b) {\n  out[0] = a[0] * b\n  out[1] = a[1] * b\n  out[2] = a[2] * b\n  out[3] = a[3] * b\n  return out\n}\n\n},{}],393:[function(_dereq_,module,exports){\nmodule.exports = scaleAndAdd\n\n/**\n * Adds two vec4's after scaling the second operand by a scalar value\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec4} out\n */\nfunction scaleAndAdd (out, a, b, scale) {\n  out[0] = a[0] + (b[0] * scale)\n  out[1] = a[1] + (b[1] * scale)\n  out[2] = a[2] + (b[2] * scale)\n  out[3] = a[3] + (b[3] * scale)\n  return out\n}\n\n},{}],394:[function(_dereq_,module,exports){\nmodule.exports = set\n\n/**\n * Set the components of a vec4 to the given values\n *\n * @param {vec4} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {vec4} out\n */\nfunction set (out, x, y, z, w) {\n  out[0] = x\n  out[1] = y\n  out[2] = z\n  out[3] = w\n  return out\n}\n\n},{}],395:[function(_dereq_,module,exports){\nmodule.exports = squaredDistance\n\n/**\n * Calculates the squared euclidian distance between two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} squared distance between a and b\n */\nfunction squaredDistance (a, b) {\n  var x = b[0] - a[0],\n    y = b[1] - a[1],\n    z = b[2] - a[2],\n    w = b[3] - a[3]\n  return x * x + y * y + z * z + w * w\n}\n\n},{}],396:[function(_dereq_,module,exports){\nmodule.exports = squaredLength\n\n/**\n * Calculates the squared length of a vec4\n *\n * @param {vec4} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nfunction squaredLength (a) {\n  var x = a[0],\n    y = a[1],\n    z = a[2],\n    w = a[3]\n  return x * x + y * y + z * z + w * w\n}\n\n},{}],397:[function(_dereq_,module,exports){\nmodule.exports = subtract\n\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nfunction subtract (out, a, b) {\n  out[0] = a[0] - b[0]\n  out[1] = a[1] - b[1]\n  out[2] = a[2] - b[2]\n  out[3] = a[3] - b[3]\n  return out\n}\n\n},{}],398:[function(_dereq_,module,exports){\nmodule.exports = transformMat4\n\n/**\n * Transforms the vec4 with a mat4.\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec4} out\n */\nfunction transformMat4 (out, a, m) {\n  var x = a[0], y = a[1], z = a[2], w = a[3]\n  out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w\n  out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w\n  out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w\n  out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w\n  return out\n}\n\n},{}],399:[function(_dereq_,module,exports){\nmodule.exports = transformQuat\n\n/**\n * Transforms the vec4 with a quat\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to transform\n * @param {quat} q quaternion to transform with\n * @returns {vec4} out\n */\nfunction transformQuat (out, a, q) {\n  var x = a[0], y = a[1], z = a[2],\n    qx = q[0], qy = q[1], qz = q[2], qw = q[3],\n\n    // calculate quat * vec\n    ix = qw * x + qy * z - qz * y,\n    iy = qw * y + qz * x - qx * z,\n    iz = qw * z + qx * y - qy * x,\n    iw = -qx * x - qy * y - qz * z\n\n  // calculate result * inverse quat\n  out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy\n  out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz\n  out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx\n  out[3] = a[3]\n  return out\n}\n\n},{}],400:[function(_dereq_,module,exports){\nmodule.exports = decodeFloat\n\nvar UINT8_VIEW = new Uint8Array(4)\nvar FLOAT_VIEW = new Float32Array(UINT8_VIEW.buffer)\n\nfunction decodeFloat(x, y, z, w) {\n  UINT8_VIEW[0] = w\n  UINT8_VIEW[1] = z\n  UINT8_VIEW[2] = y\n  UINT8_VIEW[3] = x\n  return FLOAT_VIEW[0]\n}\n\n},{}],401:[function(_dereq_,module,exports){\nvar tokenize = _dereq_('glsl-tokenizer')\nvar atob     = _dereq_('atob-lite')\n\nmodule.exports = getName\n\nfunction getName(src) {\n  var tokens = Array.isArray(src)\n    ? src\n    : tokenize(src)\n\n  for (var i = 0; i < tokens.length; i++) {\n    var token = tokens[i]\n    if (token.type !== 'preprocessor') continue\n    var match = token.data.match(/\\#define\\s+SHADER_NAME(_B64)?\\s+(.+)$/)\n    if (!match) continue\n    if (!match[2]) continue\n\n    var b64  = match[1]\n    var name = match[2]\n\n    return (b64 ? atob(name) : name).trim()\n  }\n}\n\n},{\"atob-lite\":72,\"glsl-tokenizer\":408}],402:[function(_dereq_,module,exports){\nmodule.exports = tokenize\n\nvar literals100 = _dereq_('./lib/literals')\n  , operators = _dereq_('./lib/operators')\n  , builtins100 = _dereq_('./lib/builtins')\n  , literals300es = _dereq_('./lib/literals-300es')\n  , builtins300es = _dereq_('./lib/builtins-300es')\n\nvar NORMAL = 999          // <-- never emitted\n  , TOKEN = 9999          // <-- never emitted\n  , BLOCK_COMMENT = 0\n  , LINE_COMMENT = 1\n  , PREPROCESSOR = 2\n  , OPERATOR = 3\n  , INTEGER = 4\n  , FLOAT = 5\n  , IDENT = 6\n  , BUILTIN = 7\n  , KEYWORD = 8\n  , WHITESPACE = 9\n  , EOF = 10\n  , HEX = 11\n\nvar map = [\n    'block-comment'\n  , 'line-comment'\n  , 'preprocessor'\n  , 'operator'\n  , 'integer'\n  , 'float'\n  , 'ident'\n  , 'builtin'\n  , 'keyword'\n  , 'whitespace'\n  , 'eof'\n  , 'integer'\n]\n\nfunction tokenize(opt) {\n  var i = 0\n    , total = 0\n    , mode = NORMAL\n    , c\n    , last\n    , content = []\n    , tokens = []\n    , token_idx = 0\n    , token_offs = 0\n    , line = 1\n    , col = 0\n    , start = 0\n    , isnum = false\n    , isoperator = false\n    , input = ''\n    , len\n\n  opt = opt || {}\n  var allBuiltins = builtins100\n  var allLiterals = literals100\n  if (opt.version === '300 es') {\n    allBuiltins = builtins300es\n    allLiterals = literals300es\n  }\n\n  return function(data) {\n    tokens = []\n    if (data !== null) return write(data.replace ? data.replace(/\\r\\n/g, '\\n') : data)\n    return end()\n  }\n\n  function token(data) {\n    if (data.length) {\n      tokens.push({\n        type: map[mode]\n      , data: data\n      , position: start\n      , line: line\n      , column: col\n      })\n    }\n  }\n\n  function write(chunk) {\n    i = 0\n    input += chunk\n    len = input.length\n\n    var last\n\n    while(c = input[i], i < len) {\n      last = i\n\n      switch(mode) {\n        case BLOCK_COMMENT: i = block_comment(); break\n        case LINE_COMMENT: i = line_comment(); break\n        case PREPROCESSOR: i = preprocessor(); break\n        case OPERATOR: i = operator(); break\n        case INTEGER: i = integer(); break\n        case HEX: i = hex(); break\n        case FLOAT: i = decimal(); break\n        case TOKEN: i = readtoken(); break\n        case WHITESPACE: i = whitespace(); break\n        case NORMAL: i = normal(); break\n      }\n\n      if(last !== i) {\n        switch(input[last]) {\n          case '\\n': col = 0; ++line; break\n          default: ++col; break\n        }\n      }\n    }\n\n    total += i\n    input = input.slice(i)\n    return tokens\n  }\n\n  function end(chunk) {\n    if(content.length) {\n      token(content.join(''))\n    }\n\n    mode = EOF\n    token('(eof)')\n    return tokens\n  }\n\n  function normal() {\n    content = content.length ? [] : content\n\n    if(last === '/' && c === '*') {\n      start = total + i - 1\n      mode = BLOCK_COMMENT\n      last = c\n      return i + 1\n    }\n\n    if(last === '/' && c === '/') {\n      start = total + i - 1\n      mode = LINE_COMMENT\n      last = c\n      return i + 1\n    }\n\n    if(c === '#') {\n      mode = PREPROCESSOR\n      start = total + i\n      return i\n    }\n\n    if(/\\s/.test(c)) {\n      mode = WHITESPACE\n      start = total + i\n      return i\n    }\n\n    isnum = /\\d/.test(c)\n    isoperator = /[^\\w_]/.test(c)\n\n    start = total + i\n    mode = isnum ? INTEGER : isoperator ? OPERATOR : TOKEN\n    return i\n  }\n\n  function whitespace() {\n    if(/[^\\s]/g.test(c)) {\n      token(content.join(''))\n      mode = NORMAL\n      return i\n    }\n    content.push(c)\n    last = c\n    return i + 1\n  }\n\n  function preprocessor() {\n    if((c === '\\r' || c === '\\n') && last !== '\\\\') {\n      token(content.join(''))\n      mode = NORMAL\n      return i\n    }\n    content.push(c)\n    last = c\n    return i + 1\n  }\n\n  function line_comment() {\n    return preprocessor()\n  }\n\n  function block_comment() {\n    if(c === '/' && last === '*') {\n      content.push(c)\n      token(content.join(''))\n      mode = NORMAL\n      return i + 1\n    }\n\n    content.push(c)\n    last = c\n    return i + 1\n  }\n\n  function operator() {\n    if(last === '.' && /\\d/.test(c)) {\n      mode = FLOAT\n      return i\n    }\n\n    if(last === '/' && c === '*') {\n      mode = BLOCK_COMMENT\n      return i\n    }\n\n    if(last === '/' && c === '/') {\n      mode = LINE_COMMENT\n      return i\n    }\n\n    if(c === '.' && content.length) {\n      while(determine_operator(content));\n\n      mode = FLOAT\n      return i\n    }\n\n    if(c === ';' || c === ')' || c === '(') {\n      if(content.length) while(determine_operator(content));\n      token(c)\n      mode = NORMAL\n      return i + 1\n    }\n\n    var is_composite_operator = content.length === 2 && c !== '='\n    if(/[\\w_\\d\\s]/.test(c) || is_composite_operator) {\n      while(determine_operator(content));\n      mode = NORMAL\n      return i\n    }\n\n    content.push(c)\n    last = c\n    return i + 1\n  }\n\n  function determine_operator(buf) {\n    var j = 0\n      , idx\n      , res\n\n    do {\n      idx = operators.indexOf(buf.slice(0, buf.length + j).join(''))\n      res = operators[idx]\n\n      if(idx === -1) {\n        if(j-- + buf.length > 0) continue\n        res = buf.slice(0, 1).join('')\n      }\n\n      token(res)\n\n      start += res.length\n      content = content.slice(res.length)\n      return content.length\n    } while(1)\n  }\n\n  function hex() {\n    if(/[^a-fA-F0-9]/.test(c)) {\n      token(content.join(''))\n      mode = NORMAL\n      return i\n    }\n\n    content.push(c)\n    last = c\n    return i + 1\n  }\n\n  function integer() {\n    if(c === '.') {\n      content.push(c)\n      mode = FLOAT\n      last = c\n      return i + 1\n    }\n\n    if(/[eE]/.test(c)) {\n      content.push(c)\n      mode = FLOAT\n      last = c\n      return i + 1\n    }\n\n    if(c === 'x' && content.length === 1 && content[0] === '0') {\n      mode = HEX\n      content.push(c)\n      last = c\n      return i + 1\n    }\n\n    if(/[^\\d]/.test(c)) {\n      token(content.join(''))\n      mode = NORMAL\n      return i\n    }\n\n    content.push(c)\n    last = c\n    return i + 1\n  }\n\n  function decimal() {\n    if(c === 'f') {\n      content.push(c)\n      last = c\n      i += 1\n    }\n\n    if(/[eE]/.test(c)) {\n      content.push(c)\n      last = c\n      return i + 1\n    }\n\n    if (c === '-' && /[eE]/.test(last)) {\n      content.push(c)\n      last = c\n      return i + 1\n    }\n\n    if(/[^\\d]/.test(c)) {\n      token(content.join(''))\n      mode = NORMAL\n      return i\n    }\n\n    content.push(c)\n    last = c\n    return i + 1\n  }\n\n  function readtoken() {\n    if(/[^\\d\\w_]/.test(c)) {\n      var contentstr = content.join('')\n      if(allLiterals.indexOf(contentstr) > -1) {\n        mode = KEYWORD\n      } else if(allBuiltins.indexOf(contentstr) > -1) {\n        mode = BUILTIN\n      } else {\n        mode = IDENT\n      }\n      token(content.join(''))\n      mode = NORMAL\n      return i\n    }\n    content.push(c)\n    last = c\n    return i + 1\n  }\n}\n\n},{\"./lib/builtins\":404,\"./lib/builtins-300es\":403,\"./lib/literals\":406,\"./lib/literals-300es\":405,\"./lib/operators\":407}],403:[function(_dereq_,module,exports){\n// 300es builtins/reserved words that were previously valid in v100\nvar v100 = _dereq_('./builtins')\n\n// The texture2D|Cube functions have been removed\n// And the gl_ features are updated\nv100 = v100.slice().filter(function (b) {\n  return !/^(gl\\_|texture)/.test(b)\n})\n\nmodule.exports = v100.concat([\n  // the updated gl_ constants\n    'gl_VertexID'\n  , 'gl_InstanceID'\n  , 'gl_Position'\n  , 'gl_PointSize'\n  , 'gl_FragCoord'\n  , 'gl_FrontFacing'\n  , 'gl_FragDepth'\n  , 'gl_PointCoord'\n  , 'gl_MaxVertexAttribs'\n  , 'gl_MaxVertexUniformVectors'\n  , 'gl_MaxVertexOutputVectors'\n  , 'gl_MaxFragmentInputVectors'\n  , 'gl_MaxVertexTextureImageUnits'\n  , 'gl_MaxCombinedTextureImageUnits'\n  , 'gl_MaxTextureImageUnits'\n  , 'gl_MaxFragmentUniformVectors'\n  , 'gl_MaxDrawBuffers'\n  , 'gl_MinProgramTexelOffset'\n  , 'gl_MaxProgramTexelOffset'\n  , 'gl_DepthRangeParameters'\n  , 'gl_DepthRange'\n\n  // other builtins\n  , 'trunc'\n  , 'round'\n  , 'roundEven'\n  , 'isnan'\n  , 'isinf'\n  , 'floatBitsToInt'\n  , 'floatBitsToUint'\n  , 'intBitsToFloat'\n  , 'uintBitsToFloat'\n  , 'packSnorm2x16'\n  , 'unpackSnorm2x16'\n  , 'packUnorm2x16'\n  , 'unpackUnorm2x16'\n  , 'packHalf2x16'\n  , 'unpackHalf2x16'\n  , 'outerProduct'\n  , 'transpose'\n  , 'determinant'\n  , 'inverse'\n  , 'texture'\n  , 'textureSize'\n  , 'textureProj'\n  , 'textureLod'\n  , 'textureOffset'\n  , 'texelFetch'\n  , 'texelFetchOffset'\n  , 'textureProjOffset'\n  , 'textureLodOffset'\n  , 'textureProjLod'\n  , 'textureProjLodOffset'\n  , 'textureGrad'\n  , 'textureGradOffset'\n  , 'textureProjGrad'\n  , 'textureProjGradOffset'\n])\n\n},{\"./builtins\":404}],404:[function(_dereq_,module,exports){\nmodule.exports = [\n  // Keep this list sorted\n  'abs'\n  , 'acos'\n  , 'all'\n  , 'any'\n  , 'asin'\n  , 'atan'\n  , 'ceil'\n  , 'clamp'\n  , 'cos'\n  , 'cross'\n  , 'dFdx'\n  , 'dFdy'\n  , 'degrees'\n  , 'distance'\n  , 'dot'\n  , 'equal'\n  , 'exp'\n  , 'exp2'\n  , 'faceforward'\n  , 'floor'\n  , 'fract'\n  , 'gl_BackColor'\n  , 'gl_BackLightModelProduct'\n  , 'gl_BackLightProduct'\n  , 'gl_BackMaterial'\n  , 'gl_BackSecondaryColor'\n  , 'gl_ClipPlane'\n  , 'gl_ClipVertex'\n  , 'gl_Color'\n  , 'gl_DepthRange'\n  , 'gl_DepthRangeParameters'\n  , 'gl_EyePlaneQ'\n  , 'gl_EyePlaneR'\n  , 'gl_EyePlaneS'\n  , 'gl_EyePlaneT'\n  , 'gl_Fog'\n  , 'gl_FogCoord'\n  , 'gl_FogFragCoord'\n  , 'gl_FogParameters'\n  , 'gl_FragColor'\n  , 'gl_FragCoord'\n  , 'gl_FragData'\n  , 'gl_FragDepth'\n  , 'gl_FragDepthEXT'\n  , 'gl_FrontColor'\n  , 'gl_FrontFacing'\n  , 'gl_FrontLightModelProduct'\n  , 'gl_FrontLightProduct'\n  , 'gl_FrontMaterial'\n  , 'gl_FrontSecondaryColor'\n  , 'gl_LightModel'\n  , 'gl_LightModelParameters'\n  , 'gl_LightModelProducts'\n  , 'gl_LightProducts'\n  , 'gl_LightSource'\n  , 'gl_LightSourceParameters'\n  , 'gl_MaterialParameters'\n  , 'gl_MaxClipPlanes'\n  , 'gl_MaxCombinedTextureImageUnits'\n  , 'gl_MaxDrawBuffers'\n  , 'gl_MaxFragmentUniformComponents'\n  , 'gl_MaxLights'\n  , 'gl_MaxTextureCoords'\n  , 'gl_MaxTextureImageUnits'\n  , 'gl_MaxTextureUnits'\n  , 'gl_MaxVaryingFloats'\n  , 'gl_MaxVertexAttribs'\n  , 'gl_MaxVertexTextureImageUnits'\n  , 'gl_MaxVertexUniformComponents'\n  , 'gl_ModelViewMatrix'\n  , 'gl_ModelViewMatrixInverse'\n  , 'gl_ModelViewMatrixInverseTranspose'\n  , 'gl_ModelViewMatrixTranspose'\n  , 'gl_ModelViewProjectionMatrix'\n  , 'gl_ModelViewProjectionMatrixInverse'\n  , 'gl_ModelViewProjectionMatrixInverseTranspose'\n  , 'gl_ModelViewProjectionMatrixTranspose'\n  , 'gl_MultiTexCoord0'\n  , 'gl_MultiTexCoord1'\n  , 'gl_MultiTexCoord2'\n  , 'gl_MultiTexCoord3'\n  , 'gl_MultiTexCoord4'\n  , 'gl_MultiTexCoord5'\n  , 'gl_MultiTexCoord6'\n  , 'gl_MultiTexCoord7'\n  , 'gl_Normal'\n  , 'gl_NormalMatrix'\n  , 'gl_NormalScale'\n  , 'gl_ObjectPlaneQ'\n  , 'gl_ObjectPlaneR'\n  , 'gl_ObjectPlaneS'\n  , 'gl_ObjectPlaneT'\n  , 'gl_Point'\n  , 'gl_PointCoord'\n  , 'gl_PointParameters'\n  , 'gl_PointSize'\n  , 'gl_Position'\n  , 'gl_ProjectionMatrix'\n  , 'gl_ProjectionMatrixInverse'\n  , 'gl_ProjectionMatrixInverseTranspose'\n  , 'gl_ProjectionMatrixTranspose'\n  , 'gl_SecondaryColor'\n  , 'gl_TexCoord'\n  , 'gl_TextureEnvColor'\n  , 'gl_TextureMatrix'\n  , 'gl_TextureMatrixInverse'\n  , 'gl_TextureMatrixInverseTranspose'\n  , 'gl_TextureMatrixTranspose'\n  , 'gl_Vertex'\n  , 'greaterThan'\n  , 'greaterThanEqual'\n  , 'inversesqrt'\n  , 'length'\n  , 'lessThan'\n  , 'lessThanEqual'\n  , 'log'\n  , 'log2'\n  , 'matrixCompMult'\n  , 'max'\n  , 'min'\n  , 'mix'\n  , 'mod'\n  , 'normalize'\n  , 'not'\n  , 'notEqual'\n  , 'pow'\n  , 'radians'\n  , 'reflect'\n  , 'refract'\n  , 'sign'\n  , 'sin'\n  , 'smoothstep'\n  , 'sqrt'\n  , 'step'\n  , 'tan'\n  , 'texture2D'\n  , 'texture2DLod'\n  , 'texture2DProj'\n  , 'texture2DProjLod'\n  , 'textureCube'\n  , 'textureCubeLod'\n  , 'texture2DLodEXT'\n  , 'texture2DProjLodEXT'\n  , 'textureCubeLodEXT'\n  , 'texture2DGradEXT'\n  , 'texture2DProjGradEXT'\n  , 'textureCubeGradEXT'\n]\n\n},{}],405:[function(_dereq_,module,exports){\nvar v100 = _dereq_('./literals')\n\nmodule.exports = v100.slice().concat([\n   'layout'\n  , 'centroid'\n  , 'smooth'\n  , 'case'\n  , 'mat2x2'\n  , 'mat2x3'\n  , 'mat2x4'\n  , 'mat3x2'\n  , 'mat3x3'\n  , 'mat3x4'\n  , 'mat4x2'\n  , 'mat4x3'\n  , 'mat4x4'\n  , 'uint'\n  , 'uvec2'\n  , 'uvec3'\n  , 'uvec4'\n  , 'samplerCubeShadow'\n  , 'sampler2DArray'\n  , 'sampler2DArrayShadow'\n  , 'isampler2D'\n  , 'isampler3D'\n  , 'isamplerCube'\n  , 'isampler2DArray'\n  , 'usampler2D'\n  , 'usampler3D'\n  , 'usamplerCube'\n  , 'usampler2DArray'\n  , 'coherent'\n  , 'restrict'\n  , 'readonly'\n  , 'writeonly'\n  , 'resource'\n  , 'atomic_uint'\n  , 'noperspective'\n  , 'patch'\n  , 'sample'\n  , 'subroutine'\n  , 'common'\n  , 'partition'\n  , 'active'\n  , 'filter'\n  , 'image1D'\n  , 'image2D'\n  , 'image3D'\n  , 'imageCube'\n  , 'iimage1D'\n  , 'iimage2D'\n  , 'iimage3D'\n  , 'iimageCube'\n  , 'uimage1D'\n  , 'uimage2D'\n  , 'uimage3D'\n  , 'uimageCube'\n  , 'image1DArray'\n  , 'image2DArray'\n  , 'iimage1DArray'\n  , 'iimage2DArray'\n  , 'uimage1DArray'\n  , 'uimage2DArray'\n  , 'image1DShadow'\n  , 'image2DShadow'\n  , 'image1DArrayShadow'\n  , 'image2DArrayShadow'\n  , 'imageBuffer'\n  , 'iimageBuffer'\n  , 'uimageBuffer'\n  , 'sampler1DArray'\n  , 'sampler1DArrayShadow'\n  , 'isampler1D'\n  , 'isampler1DArray'\n  , 'usampler1D'\n  , 'usampler1DArray'\n  , 'isampler2DRect'\n  , 'usampler2DRect'\n  , 'samplerBuffer'\n  , 'isamplerBuffer'\n  , 'usamplerBuffer'\n  , 'sampler2DMS'\n  , 'isampler2DMS'\n  , 'usampler2DMS'\n  , 'sampler2DMSArray'\n  , 'isampler2DMSArray'\n  , 'usampler2DMSArray'\n])\n\n},{\"./literals\":406}],406:[function(_dereq_,module,exports){\nmodule.exports = [\n  // current\n    'precision'\n  , 'highp'\n  , 'mediump'\n  , 'lowp'\n  , 'attribute'\n  , 'const'\n  , 'uniform'\n  , 'varying'\n  , 'break'\n  , 'continue'\n  , 'do'\n  , 'for'\n  , 'while'\n  , 'if'\n  , 'else'\n  , 'in'\n  , 'out'\n  , 'inout'\n  , 'float'\n  , 'int'\n  , 'void'\n  , 'bool'\n  , 'true'\n  , 'false'\n  , 'discard'\n  , 'return'\n  , 'mat2'\n  , 'mat3'\n  , 'mat4'\n  , 'vec2'\n  , 'vec3'\n  , 'vec4'\n  , 'ivec2'\n  , 'ivec3'\n  , 'ivec4'\n  , 'bvec2'\n  , 'bvec3'\n  , 'bvec4'\n  , 'sampler1D'\n  , 'sampler2D'\n  , 'sampler3D'\n  , 'samplerCube'\n  , 'sampler1DShadow'\n  , 'sampler2DShadow'\n  , 'struct'\n\n  // future\n  , 'asm'\n  , 'class'\n  , 'union'\n  , 'enum'\n  , 'typedef'\n  , 'template'\n  , 'this'\n  , 'packed'\n  , 'goto'\n  , 'switch'\n  , 'default'\n  , 'inline'\n  , 'noinline'\n  , 'volatile'\n  , 'public'\n  , 'static'\n  , 'extern'\n  , 'external'\n  , 'interface'\n  , 'long'\n  , 'short'\n  , 'double'\n  , 'half'\n  , 'fixed'\n  , 'unsigned'\n  , 'input'\n  , 'output'\n  , 'hvec2'\n  , 'hvec3'\n  , 'hvec4'\n  , 'dvec2'\n  , 'dvec3'\n  , 'dvec4'\n  , 'fvec2'\n  , 'fvec3'\n  , 'fvec4'\n  , 'sampler2DRect'\n  , 'sampler3DRect'\n  , 'sampler2DRectShadow'\n  , 'sizeof'\n  , 'cast'\n  , 'namespace'\n  , 'using'\n]\n\n},{}],407:[function(_dereq_,module,exports){\nmodule.exports = [\n    '<<='\n  , '>>='\n  , '++'\n  , '--'\n  , '<<'\n  , '>>'\n  , '<='\n  , '>='\n  , '=='\n  , '!='\n  , '&&'\n  , '||'\n  , '+='\n  , '-='\n  , '*='\n  , '/='\n  , '%='\n  , '&='\n  , '^^'\n  , '^='\n  , '|='\n  , '('\n  , ')'\n  , '['\n  , ']'\n  , '.'\n  , '!'\n  , '~'\n  , '*'\n  , '/'\n  , '%'\n  , '+'\n  , '-'\n  , '<'\n  , '>'\n  , '&'\n  , '^'\n  , '|'\n  , '?'\n  , ':'\n  , '='\n  , ','\n  , ';'\n  , '{'\n  , '}'\n]\n\n},{}],408:[function(_dereq_,module,exports){\nvar tokenize = _dereq_('./index')\n\nmodule.exports = tokenizeString\n\nfunction tokenizeString(str, opt) {\n  var generator = tokenize(opt)\n  var tokens = []\n\n  tokens = tokens.concat(generator(str))\n  tokens = tokens.concat(generator(null))\n\n  return tokens\n}\n\n},{\"./index\":402}],409:[function(_dereq_,module,exports){\nmodule.exports = function(strings) {\r\n  if (typeof strings === 'string') strings = [strings]\r\n  var exprs = [].slice.call(arguments,1)\r\n  var parts = []\r\n  for (var i = 0; i < strings.length-1; i++) {\r\n    parts.push(strings[i], exprs[i] || '')\r\n  }\r\n  parts.push(strings[i])\r\n  return parts.join('')\r\n}\r\n\n},{}],410:[function(_dereq_,module,exports){\n(function (global){\n'use strict'\r\n\r\nvar isBrowser = _dereq_('is-browser')\r\nvar hasHover\r\n\r\nif (typeof global.matchMedia === 'function') {\r\n\thasHover = !global.matchMedia('(hover: none)').matches\r\n}\r\nelse {\r\n\thasHover = isBrowser\r\n}\r\n\r\nmodule.exports = hasHover\r\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"is-browser\":417}],411:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar isBrowser = _dereq_('is-browser')\r\n\r\nfunction detect() {\r\n\tvar supported = false\r\n\r\n\ttry {\r\n\t\tvar opts = Object.defineProperty({}, 'passive', {\r\n\t\t\tget: function() {\r\n\t\t\t\tsupported = true\r\n\t\t\t}\r\n\t\t})\r\n\r\n\t\twindow.addEventListener('test', null, opts)\r\n\t\twindow.removeEventListener('test', null, opts)\r\n\t} catch(e) {\r\n\t\tsupported = false\r\n\t}\r\n\r\n\treturn supported\r\n}\r\n\r\nmodule.exports = isBrowser && detect()\r\n\n},{\"is-browser\":417}],412:[function(_dereq_,module,exports){\nexports.read = function (buffer, offset, isLE, mLen, nBytes) {\n  var e, m\n  var eLen = (nBytes * 8) - mLen - 1\n  var eMax = (1 << eLen) - 1\n  var eBias = eMax >> 1\n  var nBits = -7\n  var i = isLE ? (nBytes - 1) : 0\n  var d = isLE ? -1 : 1\n  var s = buffer[offset + i]\n\n  i += d\n\n  e = s & ((1 << (-nBits)) - 1)\n  s >>= (-nBits)\n  nBits += eLen\n  for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}\n\n  m = e & ((1 << (-nBits)) - 1)\n  e >>= (-nBits)\n  nBits += mLen\n  for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}\n\n  if (e === 0) {\n    e = 1 - eBias\n  } else if (e === eMax) {\n    return m ? NaN : ((s ? -1 : 1) * Infinity)\n  } else {\n    m = m + Math.pow(2, mLen)\n    e = e - eBias\n  }\n  return (s ? -1 : 1) * m * Math.pow(2, e - mLen)\n}\n\nexports.write = function (buffer, value, offset, isLE, mLen, nBytes) {\n  var e, m, c\n  var eLen = (nBytes * 8) - mLen - 1\n  var eMax = (1 << eLen) - 1\n  var eBias = eMax >> 1\n  var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)\n  var i = isLE ? 0 : (nBytes - 1)\n  var d = isLE ? 1 : -1\n  var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0\n\n  value = Math.abs(value)\n\n  if (isNaN(value) || value === Infinity) {\n    m = isNaN(value) ? 1 : 0\n    e = eMax\n  } else {\n    e = Math.floor(Math.log(value) / Math.LN2)\n    if (value * (c = Math.pow(2, -e)) < 1) {\n      e--\n      c *= 2\n    }\n    if (e + eBias >= 1) {\n      value += rt / c\n    } else {\n      value += rt * Math.pow(2, 1 - eBias)\n    }\n    if (value * c >= 2) {\n      e++\n      c /= 2\n    }\n\n    if (e + eBias >= eMax) {\n      m = 0\n      e = eMax\n    } else if (e + eBias >= 1) {\n      m = ((value * c) - 1) * Math.pow(2, mLen)\n      e = e + eBias\n    } else {\n      m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)\n      e = 0\n    }\n  }\n\n  for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}\n\n  e = (e << mLen) | m\n  eLen += mLen\n  for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}\n\n  buffer[offset + i - d] |= s * 128\n}\n\n},{}],413:[function(_dereq_,module,exports){\n\"use strict\"\n\n//High level idea:\n// 1. Use Clarkson's incremental construction to find convex hull\n// 2. Point location in triangulation by jump and walk\n\nmodule.exports = incrementalConvexHull\n\nvar orient = _dereq_(\"robust-orientation\")\nvar compareCell = _dereq_(\"simplicial-complex\").compareCells\n\nfunction compareInt(a, b) {\n  return a - b\n}\n\nfunction Simplex(vertices, adjacent, boundary) {\n  this.vertices = vertices\n  this.adjacent = adjacent\n  this.boundary = boundary\n  this.lastVisited = -1\n}\n\nSimplex.prototype.flip = function() {\n  var t = this.vertices[0]\n  this.vertices[0] = this.vertices[1]\n  this.vertices[1] = t\n  var u = this.adjacent[0]\n  this.adjacent[0] = this.adjacent[1]\n  this.adjacent[1] = u\n}\n\nfunction GlueFacet(vertices, cell, index) {\n  this.vertices = vertices\n  this.cell = cell\n  this.index = index\n}\n\nfunction compareGlue(a, b) {\n  return compareCell(a.vertices, b.vertices)\n}\n\nfunction bakeOrient(d) {\n  var code = [\"function orient(){var tuple=this.tuple;return test(\"]\n  for(var i=0; i<=d; ++i) {\n    if(i > 0) {\n      code.push(\",\")\n    }\n    code.push(\"tuple[\", i, \"]\")\n  }\n  code.push(\")}return orient\")\n  var proc = new Function(\"test\", code.join(\"\"))\n  var test = orient[d+1]\n  if(!test) {\n    test = orient\n  }\n  return proc(test)\n}\n\nvar BAKED = []\n\nfunction Triangulation(dimension, vertices, simplices) {\n  this.dimension = dimension\n  this.vertices = vertices\n  this.simplices = simplices\n  this.interior = simplices.filter(function(c) {\n    return !c.boundary\n  })\n\n  this.tuple = new Array(dimension+1)\n  for(var i=0; i<=dimension; ++i) {\n    this.tuple[i] = this.vertices[i]\n  }\n\n  var o = BAKED[dimension]\n  if(!o) {\n    o = BAKED[dimension] = bakeOrient(dimension)\n  }\n  this.orient = o\n}\n\nvar proto = Triangulation.prototype\n\n//Degenerate situation where we are on boundary, but coplanar to face\nproto.handleBoundaryDegeneracy = function(cell, point) {\n  var d = this.dimension\n  var n = this.vertices.length - 1\n  var tuple = this.tuple\n  var verts = this.vertices\n\n  //Dumb solution: Just do dfs from boundary cell until we find any peak, or terminate\n  var toVisit = [ cell ]\n  cell.lastVisited = -n\n  while(toVisit.length > 0) {\n    cell = toVisit.pop()\n    var cellVerts = cell.vertices\n    var cellAdj = cell.adjacent\n    for(var i=0; i<=d; ++i) {\n      var neighbor = cellAdj[i]\n      if(!neighbor.boundary || neighbor.lastVisited <= -n) {\n        continue\n      }\n      var nv = neighbor.vertices\n      for(var j=0; j<=d; ++j) {\n        var vv = nv[j]\n        if(vv < 0) {\n          tuple[j] = point\n        } else {\n          tuple[j] = verts[vv]\n        }\n      }\n      var o = this.orient()\n      if(o > 0) {\n        return neighbor\n      }\n      neighbor.lastVisited = -n\n      if(o === 0) {\n        toVisit.push(neighbor)\n      }\n    }\n  }\n  return null\n}\n\nproto.walk = function(point, random) {\n  //Alias local properties\n  var n = this.vertices.length - 1\n  var d = this.dimension\n  var verts = this.vertices\n  var tuple = this.tuple\n\n  //Compute initial jump cell\n  var initIndex = random ? (this.interior.length * Math.random())|0 : (this.interior.length-1)\n  var cell = this.interior[ initIndex ]\n\n  //Start walking\nouterLoop:\n  while(!cell.boundary) {\n    var cellVerts = cell.vertices\n    var cellAdj = cell.adjacent\n\n    for(var i=0; i<=d; ++i) {\n      tuple[i] = verts[cellVerts[i]]\n    }\n    cell.lastVisited = n\n\n    //Find farthest adjacent cell\n    for(var i=0; i<=d; ++i) {\n      var neighbor = cellAdj[i]\n      if(neighbor.lastVisited >= n) {\n        continue\n      }\n      var prev = tuple[i]\n      tuple[i] = point\n      var o = this.orient()\n      tuple[i] = prev\n      if(o < 0) {\n        cell = neighbor\n        continue outerLoop\n      } else {\n        if(!neighbor.boundary) {\n          neighbor.lastVisited = n\n        } else {\n          neighbor.lastVisited = -n\n        }\n      }\n    }\n    return\n  }\n\n  return cell\n}\n\nproto.addPeaks = function(point, cell) {\n  var n = this.vertices.length - 1\n  var d = this.dimension\n  var verts = this.vertices\n  var tuple = this.tuple\n  var interior = this.interior\n  var simplices = this.simplices\n\n  //Walking finished at boundary, time to add peaks\n  var tovisit = [ cell ]\n\n  //Stretch initial boundary cell into a peak\n  cell.lastVisited = n\n  cell.vertices[cell.vertices.indexOf(-1)] = n\n  cell.boundary = false\n  interior.push(cell)\n\n  //Record a list of all new boundaries created by added peaks so we can glue them together when we are all done\n  var glueFacets = []\n\n  //Do a traversal of the boundary walking outward from starting peak\n  while(tovisit.length > 0) {\n    //Pop off peak and walk over adjacent cells\n    var cell = tovisit.pop()\n    var cellVerts = cell.vertices\n    var cellAdj = cell.adjacent\n    var indexOfN = cellVerts.indexOf(n)\n    if(indexOfN < 0) {\n      continue\n    }\n\n    for(var i=0; i<=d; ++i) {\n      if(i === indexOfN) {\n        continue\n      }\n\n      //For each boundary neighbor of the cell\n      var neighbor = cellAdj[i]\n      if(!neighbor.boundary || neighbor.lastVisited >= n) {\n        continue\n      }\n\n      var nv = neighbor.vertices\n\n      //Test if neighbor is a peak\n      if(neighbor.lastVisited !== -n) {      \n        //Compute orientation of p relative to each boundary peak\n        var indexOfNeg1 = 0\n        for(var j=0; j<=d; ++j) {\n          if(nv[j] < 0) {\n            indexOfNeg1 = j\n            tuple[j] = point\n          } else {\n            tuple[j] = verts[nv[j]]\n          }\n        }\n        var o = this.orient()\n\n        //Test if neighbor cell is also a peak\n        if(o > 0) {\n          nv[indexOfNeg1] = n\n          neighbor.boundary = false\n          interior.push(neighbor)\n          tovisit.push(neighbor)\n          neighbor.lastVisited = n\n          continue\n        } else {\n          neighbor.lastVisited = -n\n        }\n      }\n\n      var na = neighbor.adjacent\n\n      //Otherwise, replace neighbor with new face\n      var vverts = cellVerts.slice()\n      var vadj = cellAdj.slice()\n      var ncell = new Simplex(vverts, vadj, true)\n      simplices.push(ncell)\n\n      //Connect to neighbor\n      var opposite = na.indexOf(cell)\n      if(opposite < 0) {\n        continue\n      }\n      na[opposite] = ncell\n      vadj[indexOfN] = neighbor\n\n      //Connect to cell\n      vverts[i] = -1\n      vadj[i] = cell\n      cellAdj[i] = ncell\n\n      //Flip facet\n      ncell.flip()\n\n      //Add to glue list\n      for(var j=0; j<=d; ++j) {\n        var uu = vverts[j]\n        if(uu < 0 || uu === n) {\n          continue\n        }\n        var nface = new Array(d-1)\n        var nptr = 0\n        for(var k=0; k<=d; ++k) {\n          var vv = vverts[k]\n          if(vv < 0 || k === j) {\n            continue\n          }\n          nface[nptr++] = vv\n        }\n        glueFacets.push(new GlueFacet(nface, ncell, j))\n      }\n    }\n  }\n\n  //Glue boundary facets together\n  glueFacets.sort(compareGlue)\n\n  for(var i=0; i+1<glueFacets.length; i+=2) {\n    var a = glueFacets[i]\n    var b = glueFacets[i+1]\n    var ai = a.index\n    var bi = b.index\n    if(ai < 0 || bi < 0) {\n      continue\n    }\n    a.cell.adjacent[a.index] = b.cell\n    b.cell.adjacent[b.index] = a.cell\n  }\n}\n\nproto.insert = function(point, random) {\n  //Add point\n  var verts = this.vertices\n  verts.push(point)\n\n  var cell = this.walk(point, random)\n  if(!cell) {\n    return\n  }\n\n  //Alias local properties\n  var d = this.dimension\n  var tuple = this.tuple\n\n  //Degenerate case: If point is coplanar to cell, then walk until we find a non-degenerate boundary\n  for(var i=0; i<=d; ++i) {\n    var vv = cell.vertices[i]\n    if(vv < 0) {\n      tuple[i] = point\n    } else {\n      tuple[i] = verts[vv]\n    }\n  }\n  var o = this.orient(tuple)\n  if(o < 0) {\n    return\n  } else if(o === 0) {\n    cell = this.handleBoundaryDegeneracy(cell, point)\n    if(!cell) {\n      return\n    }\n  }\n\n  //Add peaks\n  this.addPeaks(point, cell)\n}\n\n//Extract all boundary cells\nproto.boundary = function() {\n  var d = this.dimension\n  var boundary = []\n  var cells = this.simplices\n  var nc = cells.length\n  for(var i=0; i<nc; ++i) {\n    var c = cells[i]\n    if(c.boundary) {\n      var bcell = new Array(d)\n      var cv = c.vertices\n      var ptr = 0\n      var parity = 0\n      for(var j=0; j<=d; ++j) {\n        if(cv[j] >= 0) {\n          bcell[ptr++] = cv[j]\n        } else {\n          parity = j&1\n        }\n      }\n      if(parity === (d&1)) {\n        var t = bcell[0]\n        bcell[0] = bcell[1]\n        bcell[1] = t\n      }\n      boundary.push(bcell)\n    }\n  }\n  return boundary\n}\n\nfunction incrementalConvexHull(points, randomSearch) {\n  var n = points.length\n  if(n === 0) {\n    throw new Error(\"Must have at least d+1 points\")\n  }\n  var d = points[0].length\n  if(n <= d) {\n    throw new Error(\"Must input at least d+1 points\")\n  }\n\n  //FIXME: This could be degenerate, but need to select d+1 non-coplanar points to bootstrap process\n  var initialSimplex = points.slice(0, d+1)\n\n  //Make sure initial simplex is positively oriented\n  var o = orient.apply(void 0, initialSimplex)\n  if(o === 0) {\n    throw new Error(\"Input not in general position\")\n  }\n  var initialCoords = new Array(d+1)\n  for(var i=0; i<=d; ++i) {\n    initialCoords[i] = i\n  }\n  if(o < 0) {\n    initialCoords[0] = 1\n    initialCoords[1] = 0\n  }\n\n  //Create initial topological index, glue pointers together (kind of messy)\n  var initialCell = new Simplex(initialCoords, new Array(d+1), false)\n  var boundary = initialCell.adjacent\n  var list = new Array(d+2)\n  for(var i=0; i<=d; ++i) {\n    var verts = initialCoords.slice()\n    for(var j=0; j<=d; ++j) {\n      if(j === i) {\n        verts[j] = -1\n      }\n    }\n    var t = verts[0]\n    verts[0] = verts[1]\n    verts[1] = t\n    var cell = new Simplex(verts, new Array(d+1), true)\n    boundary[i] = cell\n    list[i] = cell\n  }\n  list[d+1] = initialCell\n  for(var i=0; i<=d; ++i) {\n    var verts = boundary[i].vertices\n    var adj = boundary[i].adjacent\n    for(var j=0; j<=d; ++j) {\n      var v = verts[j]\n      if(v < 0) {\n        adj[j] = initialCell\n        continue\n      }\n      for(var k=0; k<=d; ++k) {\n        if(boundary[k].vertices.indexOf(v) < 0) {\n          adj[j] = boundary[k]\n        }\n      }\n    }\n  }\n\n  //Initialize triangles\n  var triangles = new Triangulation(d, initialSimplex, list)\n\n  //Insert remaining points\n  var useRandom = !!randomSearch\n  for(var i=d+1; i<n; ++i) {\n    triangles.insert(points[i], useRandom)\n  }\n  \n  //Extract boundary cells\n  return triangles.boundary()\n}\n},{\"robust-orientation\":510,\"simplicial-complex\":520}],414:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar bounds = _dereq_(\"binary-search-bounds\")\n\nvar NOT_FOUND = 0\nvar SUCCESS = 1\nvar EMPTY = 2\n\nmodule.exports = createWrapper\n\nfunction IntervalTreeNode(mid, left, right, leftPoints, rightPoints) {\n  this.mid = mid\n  this.left = left\n  this.right = right\n  this.leftPoints = leftPoints\n  this.rightPoints = rightPoints\n  this.count = (left ? left.count : 0) + (right ? right.count : 0) + leftPoints.length\n}\n\nvar proto = IntervalTreeNode.prototype\n\nfunction copy(a, b) {\n  a.mid = b.mid\n  a.left = b.left\n  a.right = b.right\n  a.leftPoints = b.leftPoints\n  a.rightPoints = b.rightPoints\n  a.count = b.count\n}\n\nfunction rebuild(node, intervals) {\n  var ntree = createIntervalTree(intervals)\n  node.mid = ntree.mid\n  node.left = ntree.left\n  node.right = ntree.right\n  node.leftPoints = ntree.leftPoints\n  node.rightPoints = ntree.rightPoints\n  node.count = ntree.count\n}\n\nfunction rebuildWithInterval(node, interval) {\n  var intervals = node.intervals([])\n  intervals.push(interval)\n  rebuild(node, intervals)    \n}\n\nfunction rebuildWithoutInterval(node, interval) {\n  var intervals = node.intervals([])\n  var idx = intervals.indexOf(interval)\n  if(idx < 0) {\n    return NOT_FOUND\n  }\n  intervals.splice(idx, 1)\n  rebuild(node, intervals)\n  return SUCCESS\n}\n\nproto.intervals = function(result) {\n  result.push.apply(result, this.leftPoints)\n  if(this.left) {\n    this.left.intervals(result)\n  }\n  if(this.right) {\n    this.right.intervals(result)\n  }\n  return result\n}\n\nproto.insert = function(interval) {\n  var weight = this.count - this.leftPoints.length\n  this.count += 1\n  if(interval[1] < this.mid) {\n    if(this.left) {\n      if(4*(this.left.count+1) > 3*(weight+1)) {\n        rebuildWithInterval(this, interval)\n      } else {\n        this.left.insert(interval)\n      }\n    } else {\n      this.left = createIntervalTree([interval])\n    }\n  } else if(interval[0] > this.mid) {\n    if(this.right) {\n      if(4*(this.right.count+1) > 3*(weight+1)) {\n        rebuildWithInterval(this, interval)\n      } else {\n        this.right.insert(interval)\n      }\n    } else {\n      this.right = createIntervalTree([interval])\n    }\n  } else {\n    var l = bounds.ge(this.leftPoints, interval, compareBegin)\n    var r = bounds.ge(this.rightPoints, interval, compareEnd)\n    this.leftPoints.splice(l, 0, interval)\n    this.rightPoints.splice(r, 0, interval)\n  }\n}\n\nproto.remove = function(interval) {\n  var weight = this.count - this.leftPoints\n  if(interval[1] < this.mid) {\n    if(!this.left) {\n      return NOT_FOUND\n    }\n    var rw = this.right ? this.right.count : 0\n    if(4 * rw > 3 * (weight-1)) {\n      return rebuildWithoutInterval(this, interval)\n    }\n    var r = this.left.remove(interval)\n    if(r === EMPTY) {\n      this.left = null\n      this.count -= 1\n      return SUCCESS\n    } else if(r === SUCCESS) {\n      this.count -= 1\n    }\n    return r\n  } else if(interval[0] > this.mid) {\n    if(!this.right) {\n      return NOT_FOUND\n    }\n    var lw = this.left ? this.left.count : 0\n    if(4 * lw > 3 * (weight-1)) {\n      return rebuildWithoutInterval(this, interval)\n    }\n    var r = this.right.remove(interval)\n    if(r === EMPTY) {\n      this.right = null\n      this.count -= 1\n      return SUCCESS\n    } else if(r === SUCCESS) {\n      this.count -= 1\n    }\n    return r\n  } else {\n    if(this.count === 1) {\n      if(this.leftPoints[0] === interval) {\n        return EMPTY\n      } else {\n        return NOT_FOUND\n      }\n    }\n    if(this.leftPoints.length === 1 && this.leftPoints[0] === interval) {\n      if(this.left && this.right) {\n        var p = this\n        var n = this.left\n        while(n.right) {\n          p = n\n          n = n.right\n        }\n        if(p === this) {\n          n.right = this.right\n        } else {\n          var l = this.left\n          var r = this.right\n          p.count -= n.count\n          p.right = n.left\n          n.left = l\n          n.right = r\n        }\n        copy(this, n)\n        this.count = (this.left?this.left.count:0) + (this.right?this.right.count:0) + this.leftPoints.length\n      } else if(this.left) {\n        copy(this, this.left)\n      } else {\n        copy(this, this.right)\n      }\n      return SUCCESS\n    }\n    for(var l = bounds.ge(this.leftPoints, interval, compareBegin); l<this.leftPoints.length; ++l) {\n      if(this.leftPoints[l][0] !== interval[0]) {\n        break\n      }\n      if(this.leftPoints[l] === interval) {\n        this.count -= 1\n        this.leftPoints.splice(l, 1)\n        for(var r = bounds.ge(this.rightPoints, interval, compareEnd); r<this.rightPoints.length; ++r) {\n          if(this.rightPoints[r][1] !== interval[1]) {\n            break\n          } else if(this.rightPoints[r] === interval) {\n            this.rightPoints.splice(r, 1)\n            return SUCCESS\n          }\n        }\n      }\n    }\n    return NOT_FOUND\n  }\n}\n\nfunction reportLeftRange(arr, hi, cb) {\n  for(var i=0; i<arr.length && arr[i][0] <= hi; ++i) {\n    var r = cb(arr[i])\n    if(r) { return r }\n  }\n}\n\nfunction reportRightRange(arr, lo, cb) {\n  for(var i=arr.length-1; i>=0 && arr[i][1] >= lo; --i) {\n    var r = cb(arr[i])\n    if(r) { return r }\n  }\n}\n\nfunction reportRange(arr, cb) {\n  for(var i=0; i<arr.length; ++i) {\n    var r = cb(arr[i])\n    if(r) { return r }\n  }\n}\n\nproto.queryPoint = function(x, cb) {\n  if(x < this.mid) {\n    if(this.left) {\n      var r = this.left.queryPoint(x, cb)\n      if(r) { return r }\n    }\n    return reportLeftRange(this.leftPoints, x, cb)\n  } else if(x > this.mid) {\n    if(this.right) {\n      var r = this.right.queryPoint(x, cb)\n      if(r) { return r }\n    }\n    return reportRightRange(this.rightPoints, x, cb)\n  } else {\n    return reportRange(this.leftPoints, cb)\n  }\n}\n\nproto.queryInterval = function(lo, hi, cb) {\n  if(lo < this.mid && this.left) {\n    var r = this.left.queryInterval(lo, hi, cb)\n    if(r) { return r }\n  }\n  if(hi > this.mid && this.right) {\n    var r = this.right.queryInterval(lo, hi, cb)\n    if(r) { return r }\n  }\n  if(hi < this.mid) {\n    return reportLeftRange(this.leftPoints, hi, cb)\n  } else if(lo > this.mid) {\n    return reportRightRange(this.rightPoints, lo, cb)\n  } else {\n    return reportRange(this.leftPoints, cb)\n  }\n}\n\nfunction compareNumbers(a, b) {\n  return a - b\n}\n\nfunction compareBegin(a, b) {\n  var d = a[0] - b[0]\n  if(d) { return d }\n  return a[1] - b[1]\n}\n\nfunction compareEnd(a, b) {\n  var d = a[1] - b[1]\n  if(d) { return d }\n  return a[0] - b[0]\n}\n\nfunction createIntervalTree(intervals) {\n  if(intervals.length === 0) {\n    return null\n  }\n  var pts = []\n  for(var i=0; i<intervals.length; ++i) {\n    pts.push(intervals[i][0], intervals[i][1])\n  }\n  pts.sort(compareNumbers)\n\n  var mid = pts[pts.length>>1]\n\n  var leftIntervals = []\n  var rightIntervals = []\n  var centerIntervals = []\n  for(var i=0; i<intervals.length; ++i) {\n    var s = intervals[i]\n    if(s[1] < mid) {\n      leftIntervals.push(s)\n    } else if(mid < s[0]) {\n      rightIntervals.push(s)\n    } else {\n      centerIntervals.push(s)\n    }\n  }\n\n  //Split center intervals\n  var leftPoints = centerIntervals\n  var rightPoints = centerIntervals.slice()\n  leftPoints.sort(compareBegin)\n  rightPoints.sort(compareEnd)\n\n  return new IntervalTreeNode(mid, \n    createIntervalTree(leftIntervals),\n    createIntervalTree(rightIntervals),\n    leftPoints,\n    rightPoints)\n}\n\n//User friendly wrapper that makes it possible to support empty trees\nfunction IntervalTree(root) {\n  this.root = root\n}\n\nvar tproto = IntervalTree.prototype\n\ntproto.insert = function(interval) {\n  if(this.root) {\n    this.root.insert(interval)\n  } else {\n    this.root = new IntervalTreeNode(interval[0], null, null, [interval], [interval])\n  }\n}\n\ntproto.remove = function(interval) {\n  if(this.root) {\n    var r = this.root.remove(interval)\n    if(r === EMPTY) {\n      this.root = null\n    }\n    return r !== NOT_FOUND\n  }\n  return false\n}\n\ntproto.queryPoint = function(p, cb) {\n  if(this.root) {\n    return this.root.queryPoint(p, cb)\n  }\n}\n\ntproto.queryInterval = function(lo, hi, cb) {\n  if(lo <= hi && this.root) {\n    return this.root.queryInterval(lo, hi, cb)\n  }\n}\n\nObject.defineProperty(tproto, \"count\", {\n  get: function() {\n    if(this.root) {\n      return this.root.count\n    }\n    return 0\n  }\n})\n\nObject.defineProperty(tproto, \"intervals\", {\n  get: function() {\n    if(this.root) {\n      return this.root.intervals([])\n    }\n    return []\n  }\n})\n\nfunction createWrapper(intervals) {\n  if(!intervals || intervals.length === 0) {\n    return new IntervalTree(null)\n  }\n  return new IntervalTree(createIntervalTree(intervals))\n}\n\n},{\"binary-search-bounds\":91}],415:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction invertPermutation(pi, result) {\n  result = result || new Array(pi.length)\n  for(var i=0; i<pi.length; ++i) {\n    result[pi[i]] = i\n  }\n  return result\n}\n\nmodule.exports = invertPermutation\n},{}],416:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction iota(n) {\n  var result = new Array(n)\n  for(var i=0; i<n; ++i) {\n    result[i] = i\n  }\n  return result\n}\n\nmodule.exports = iota\n},{}],417:[function(_dereq_,module,exports){\nmodule.exports = true;\n},{}],418:[function(_dereq_,module,exports){\n/*!\n * Determine if an object is a Buffer\n *\n * @author   Feross Aboukhadijeh <https://feross.org>\n * @license  MIT\n */\n\n// The _isBuffer check is for Safari 5-7 support, because it's missing\n// Object.prototype.constructor. Remove this eventually\nmodule.exports = function (obj) {\n  return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)\n}\n\nfunction isBuffer (obj) {\n  return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)\n}\n\n// For Node v0.10 support. Remove this eventually.\nfunction isSlowBuffer (obj) {\n  return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))\n}\n\n},{}],419:[function(_dereq_,module,exports){\n'use strict';\nmodule.exports = typeof navigator !== 'undefined' &&\n\t(/MSIE/.test(navigator.userAgent) || /Trident\\//.test(navigator.appVersion));\n\n},{}],420:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = isMobile;\nmodule.exports.isMobile = isMobile;\n\nvar mobileRE = /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i;\n\nvar tabletRE = /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i;\n\nfunction isMobile (opts) {\n  if (!opts) opts = {}\n  var ua = opts.ua\n  if (!ua && typeof navigator !== 'undefined') ua = navigator.userAgent;\n  if (ua && ua.headers && typeof ua.headers['user-agent'] === 'string') {\n    ua = ua.headers['user-agent'];\n  }\n  if (typeof ua !== 'string') return false;\n\n  return opts.tablet\n    ? tabletRE.test(ua)\n    : mobileRE.test(ua);\n}\n\n},{}],421:[function(_dereq_,module,exports){\n'use strict';\nmodule.exports = function (x) {\n\tvar type = typeof x;\n\treturn x !== null && (type === 'object' || type === 'function');\n};\n\n},{}],422:[function(_dereq_,module,exports){\n'use strict';\nvar toString = Object.prototype.toString;\n\nmodule.exports = function (x) {\n\tvar prototype;\n\treturn toString.call(x) === '[object Object]' && (prototype = Object.getPrototypeOf(x), prototype === null || prototype === Object.getPrototypeOf({}));\n};\n\n},{}],423:[function(_dereq_,module,exports){\n'use strict';\r\n\r\n/**\r\n * Is this string all whitespace?\r\n * This solution kind of makes my brain hurt, but it's significantly faster\r\n * than !str.trim() or any other solution I could find.\r\n *\r\n * whitespace codes from: http://en.wikipedia.org/wiki/Whitespace_character\r\n * and verified with:\r\n *\r\n *  for(var i = 0; i < 65536; i++) {\r\n *      var s = String.fromCharCode(i);\r\n *      if(+s===0 && !s.trim()) console.log(i, s);\r\n *  }\r\n *\r\n * which counts a couple of these as *not* whitespace, but finds nothing else\r\n * that *is* whitespace. Note that charCodeAt stops at 16 bits, but it appears\r\n * that there are no whitespace characters above this, and code points above\r\n * this do not map onto white space characters.\r\n */\r\n\r\nmodule.exports = function(str){\r\n    var l = str.length,\r\n        a;\r\n    for(var i = 0; i < l; i++) {\r\n        a = str.charCodeAt(i);\r\n        if((a < 9 || a > 13) && (a !== 32) && (a !== 133) && (a !== 160) &&\r\n            (a !== 5760) && (a !== 6158) && (a < 8192 || a > 8205) &&\r\n            (a !== 8232) && (a !== 8233) && (a !== 8239) && (a !== 8287) &&\r\n            (a !== 8288) && (a !== 12288) && (a !== 65279)) {\r\n                return false;\r\n        }\r\n    }\r\n    return true;\r\n}\r\n\n},{}],424:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nmodule.exports = function isPath(str) {\r\n\tif (typeof str !== 'string') return false\r\n\r\n\tstr = str.trim()\r\n\r\n\t// https://www.w3.org/TR/SVG/paths.html#PathDataBNF\r\n\tif (/^[mzlhvcsqta]\\s*[-+.0-9][^mlhvzcsqta]+/i.test(str) && /[\\dz]$/i.test(str) && str.length > 4) return true\r\n\r\n\treturn false\r\n}\r\n\n},{}],425:[function(_dereq_,module,exports){\nfunction lerp(v0, v1, t) {\n    return v0*(1-t)+v1*t\n}\nmodule.exports = lerp\n},{}],426:[function(_dereq_,module,exports){\n/* Mapbox GL JS is licensed under the 3-Clause BSD License. Full text of license: https://github.com/mapbox/mapbox-gl-js/blob/v1.1.1/LICENSE.txt */\n(function (global, factory) {\ntypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\ntypeof define === 'function' && define.amd ? define(factory) :\n(global = global || self, global.mapboxgl = factory());\n}(this, function () { 'use strict';\n\n/* eslint-disable */\n\nvar shared, worker, mapboxgl;\n// define gets called three times: one for each chunk. we rely on the order\n// they're imported to know which is which\nfunction define(_, chunk) {\nif (!shared) {\n    shared = chunk;\n} else if (!worker) {\n    worker = chunk;\n} else {\n    var workerBundleString = 'var sharedChunk = {}; (' + shared + ')(sharedChunk); (' + worker + ')(sharedChunk);'\n\n    var sharedChunk = {};\n    shared(sharedChunk);\n    mapboxgl = chunk(sharedChunk);\n    mapboxgl.workerUrl = window.URL.createObjectURL(new Blob([workerBundleString], { type: 'text/javascript' }));\n}\n}\n\n\ndefine([\"exports\"],function(t){\"use strict\";function e(t,e){return t(e={exports:{}},e.exports),e.exports}var r=n;function n(t,e,r,n){this.cx=3*t,this.bx=3*(r-t)-this.cx,this.ax=1-this.cx-this.bx,this.cy=3*e,this.by=3*(n-e)-this.cy,this.ay=1-this.cy-this.by,this.p1x=t,this.p1y=n,this.p2x=r,this.p2y=n;}n.prototype.sampleCurveX=function(t){return ((this.ax*t+this.bx)*t+this.cx)*t},n.prototype.sampleCurveY=function(t){return ((this.ay*t+this.by)*t+this.cy)*t},n.prototype.sampleCurveDerivativeX=function(t){return (3*this.ax*t+2*this.bx)*t+this.cx},n.prototype.solveCurveX=function(t,e){var r,n,i,a,o;for(void 0===e&&(e=1e-6),i=t,o=0;o<8;o++){if(a=this.sampleCurveX(i)-t,Math.abs(a)<e)return i;var s=this.sampleCurveDerivativeX(i);if(Math.abs(s)<1e-6)break;i-=a/s;}if((i=t)<(r=0))return r;if(i>(n=1))return n;for(;r<n;){if(a=this.sampleCurveX(i),Math.abs(a-t)<e)return i;t>a?r=i:n=i,i=.5*(n-r)+r;}return i},n.prototype.solve=function(t,e){return this.sampleCurveY(this.solveCurveX(t,e))};var i=a;function a(t,e){this.x=t,this.y=e;}function o(t,e){if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return !1;for(var r=0;r<t.length;r++)if(!o(t[r],e[r]))return !1;return !0}if(\"object\"==typeof t&&null!==t&&null!==e){if(\"object\"!=typeof e)return !1;if(Object.keys(t).length!==Object.keys(e).length)return !1;for(var n in t)if(!o(t[n],e[n]))return !1;return !0}return t===e}function s(t,e,n,i){var a=new r(t,e,n,i);return function(t){return a.solve(t)}}a.prototype={clone:function(){return new a(this.x,this.y)},add:function(t){return this.clone()._add(t)},sub:function(t){return this.clone()._sub(t)},multByPoint:function(t){return this.clone()._multByPoint(t)},divByPoint:function(t){return this.clone()._divByPoint(t)},mult:function(t){return this.clone()._mult(t)},div:function(t){return this.clone()._div(t)},rotate:function(t){return this.clone()._rotate(t)},rotateAround:function(t,e){return this.clone()._rotateAround(t,e)},matMult:function(t){return this.clone()._matMult(t)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(t){return this.x===t.x&&this.y===t.y},dist:function(t){return Math.sqrt(this.distSqr(t))},distSqr:function(t){var e=t.x-this.x,r=t.y-this.y;return e*e+r*r},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(t){return Math.atan2(this.y-t.y,this.x-t.x)},angleWith:function(t){return this.angleWithSep(t.x,t.y)},angleWithSep:function(t,e){return Math.atan2(this.x*e-this.y*t,this.x*t+this.y*e)},_matMult:function(t){var e=t[0]*this.x+t[1]*this.y,r=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=r,this},_add:function(t){return this.x+=t.x,this.y+=t.y,this},_sub:function(t){return this.x-=t.x,this.y-=t.y,this},_mult:function(t){return this.x*=t,this.y*=t,this},_div:function(t){return this.x/=t,this.y/=t,this},_multByPoint:function(t){return this.x*=t.x,this.y*=t.y,this},_divByPoint:function(t){return this.x/=t.x,this.y/=t.y,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var t=this.y;return this.y=this.x,this.x=-t,this},_rotate:function(t){var e=Math.cos(t),r=Math.sin(t),n=e*this.x-r*this.y,i=r*this.x+e*this.y;return this.x=n,this.y=i,this},_rotateAround:function(t,e){var r=Math.cos(t),n=Math.sin(t),i=e.x+r*(this.x-e.x)-n*(this.y-e.y),a=e.y+n*(this.x-e.x)+r*(this.y-e.y);return this.x=i,this.y=a,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},a.convert=function(t){return t instanceof a?t:Array.isArray(t)?new a(t[0],t[1]):t};var u=s(.25,.1,.25,1);function l(t,e,r){return Math.min(r,Math.max(e,t))}function p(t,e,r){var n=r-e,i=((t-e)%n+n)%n+e;return i===e?r:i}function c(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];for(var n=0,i=e;n<i.length;n+=1){var a=i[n];for(var o in a)t[o]=a[o];}return t}var h=1;function f(){return h++}function y(){return function t(e){return e?(e^16*Math.random()>>e/4).toString(16):([1e7]+-[1e3]+-4e3+-8e3+-1e11).replace(/[018]/g,t)}()}function d(t){return !!t&&/^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t)}function m(t,e){t.forEach(function(t){e[t]&&(e[t]=e[t].bind(e));});}function v(t,e){return -1!==t.indexOf(e,t.length-e.length)}function g(t,e,r){var n={};for(var i in t)n[i]=e.call(r||this,t[i],i,t);return n}function x(t,e,r){var n={};for(var i in t)e.call(r||this,t[i],i,t)&&(n[i]=t[i]);return n}function b(t){return Array.isArray(t)?t.map(b):\"object\"==typeof t&&t?g(t,b):t}var _={};function w(t){_[t]||(\"undefined\"!=typeof console&&console.warn(t),_[t]=!0);}function A(t,e,r){return (r.y-t.y)*(e.x-t.x)>(e.y-t.y)*(r.x-t.x)}function S(t){for(var e=0,r=0,n=t.length,i=n-1,a=void 0,o=void 0;r<n;i=r++)a=t[r],e+=((o=t[i]).x-a.x)*(a.y+o.y);return e}function k(t){var e={};if(t.replace(/(?:^|(?:\\s*\\,\\s*))([^\\x00-\\x20\\(\\)<>@\\,;\\:\\\\\"\\/\\[\\]\\?\\=\\{\\}\\x7F]+)(?:\\=(?:([^\\x00-\\x20\\(\\)<>@\\,;\\:\\\\\"\\/\\[\\]\\?\\=\\{\\}\\x7F]+)|(?:\\\"((?:[^\"\\\\]|\\\\.)*)\\\")))?/g,function(t,r,n,i){var a=n||i;return e[r]=!a||a.toLowerCase(),\"\"}),e[\"max-age\"]){var r=parseInt(e[\"max-age\"],10);isNaN(r)?delete e[\"max-age\"]:e[\"max-age\"]=r;}return e}function z(t){try{var e=self[t];return e.setItem(\"_mapbox_test_\",1),e.removeItem(\"_mapbox_test_\"),!0}catch(t){return !1}}var I,B,C,E=self.performance&&self.performance.now?self.performance.now.bind(self.performance):Date.now.bind(Date),M=self.requestAnimationFrame||self.mozRequestAnimationFrame||self.webkitRequestAnimationFrame||self.msRequestAnimationFrame,T=self.cancelAnimationFrame||self.mozCancelAnimationFrame||self.webkitCancelAnimationFrame||self.msCancelAnimationFrame,P={now:E,frame:function(t){var e=M(t);return {cancel:function(){return T(e)}}},getImageData:function(t){var e=self.document.createElement(\"canvas\"),r=e.getContext(\"2d\");if(!r)throw new Error(\"failed to create canvas 2d context\");return e.width=t.width,e.height=t.height,r.drawImage(t,0,0,t.width,t.height),r.getImageData(0,0,t.width,t.height)},resolveURL:function(t){return I||(I=self.document.createElement(\"a\")),I.href=t,I.href},hardwareConcurrency:self.navigator.hardwareConcurrency||4,get devicePixelRatio(){return self.devicePixelRatio}},V={API_URL:\"https://api.mapbox.com\",get EVENTS_URL(){return this.API_URL?0===this.API_URL.indexOf(\"https://api.mapbox.cn\")?\"https://events.mapbox.cn/events/v2\":0===this.API_URL.indexOf(\"https://api.mapbox.com\")?\"https://events.mapbox.com/events/v2\":null:null},FEEDBACK_URL:\"https://apps.mapbox.com/feedback\",REQUIRE_ACCESS_TOKEN:!0,ACCESS_TOKEN:null,MAX_PARALLEL_IMAGE_REQUESTS:16},F={supported:!1,testSupport:function(t){if(L||!C)return;D?O(t):B=t;}},L=!1,D=!1;function O(t){var e=t.createTexture();t.bindTexture(t.TEXTURE_2D,e);try{if(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,C),t.isContextLost())return;F.supported=!0;}catch(t){}t.deleteTexture(e),L=!0;}self.document&&((C=self.document.createElement(\"img\")).onload=function(){B&&O(B),B=null,D=!0;},C.onerror=function(){L=!0,B=null;},C.src=\"data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=\");var R=\"01\";var U=function(t){this._transformRequestFn=t,this._createSkuToken();};U.prototype._createSkuToken=function(){var t=function(){for(var t=\"\",e=0;e<10;e++)t+=\"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"[Math.floor(62*Math.random())];return {token:[\"1\",R,t].join(\"\"),tokenExpiresAt:Date.now()+432e5}}();this._skuToken=t.token,this._skuTokenExpiresAt=t.tokenExpiresAt;},U.prototype._isSkuTokenExpired=function(){return Date.now()>this._skuTokenExpiresAt},U.prototype.transformRequest=function(t,e){return this._transformRequestFn&&this._transformRequestFn(t,e)||{url:t}},U.prototype.normalizeStyleURL=function(t,e){return G(t,e)},U.prototype.normalizeGlyphsURL=function(t,e){return X(t,e)},U.prototype.normalizeSourceURL=function(t,e){return J(t,e)},U.prototype.normalizeSpriteURL=function(t,e,r,n){return H(t,e,r,n)},U.prototype.normalizeTileURL=function(t,e,r){return this._isSkuTokenExpired()&&this._createSkuToken(),$(t,e,r,this._skuToken)},U.prototype.canonicalizeTileURL=function(t){return Q(t)},U.prototype.canonicalizeTileset=function(t,e){return tt(t,e)};var j=\"See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes\";function q(t,e){var r=rt(V.API_URL);if(t.protocol=r.protocol,t.authority=r.authority,\"/\"!==r.path&&(t.path=\"\"+r.path+t.path),!V.REQUIRE_ACCESS_TOKEN)return nt(t);if(!(e=e||V.ACCESS_TOKEN))throw new Error(\"An API access token is required to use Mapbox GL. \"+j);if(\"s\"===e[0])throw new Error(\"Use a public access token (pk.*) with Mapbox GL, not a secret access token (sk.*). \"+j);return t.params.push(\"access_token=\"+e),nt(t)}function N(t){return 0===t.indexOf(\"mapbox:\")}var Z=/^((https?:)?\\/\\/)?([^\\/]+\\.)?mapbox\\.c(n|om)(\\/|\\?|$)/i;function K(t){return Z.test(t)}var G=function(t,e){if(!N(t))return t;var r=rt(t);return r.path=\"/styles/v1\"+r.path,q(r,e)},X=function(t,e){if(!N(t))return t;var r=rt(t);return r.path=\"/fonts/v1\"+r.path,q(r,e)},J=function(t,e){if(!N(t))return t;var r=rt(t);return r.path=\"/v4/\"+r.authority+\".json\",r.params.push(\"secure\"),q(r,e)},H=function(t,e,r,n){var i=rt(t);return N(t)?(i.path=\"/styles/v1\"+i.path+\"/sprite\"+e+r,q(i,n)):(i.path+=\"\"+e+r,nt(i))},Y=/(\\.(png|jpg)\\d*)(?=$)/,$=function(t,e,r,n){if(!e||!N(e))return t;var i=rt(t),a=P.devicePixelRatio>=2||512===r?\"@2x\":\"\",o=F.supported?\".webp\":\"$1\";return i.path=i.path.replace(Y,\"\"+a+o),i.path=\"/v4\"+i.path,V.REQUIRE_ACCESS_TOKEN&&V.ACCESS_TOKEN&&n&&i.params.push(\"sku=\"+n),q(i)},W=/\\.[\\w]+$/,Q=function(t){var e=rt(t);if(!e.path.match(/(^\\/v4\\/)/)||!e.path.match(W))return t;var r=\"mapbox://tiles/\";r+=e.path.replace(\"/v4/\",\"\");var n=e.params.filter(function(t){return !t.match(/^access_token=/)});return n.length&&(r+=\"?\"+n.join(\"&\")),r},tt=function(t,e){if(!N(e))return t.tiles||[];for(var r=[],n=0,i=t.tiles;n<i.length;n+=1){var a=i[n],o=Q(a);r.push(o);}return r},et=/^(\\w+):\\/\\/([^\\/?]*)(\\/[^?]+)?\\??(.+)?/;function rt(t){var e=t.match(et);if(!e)throw new Error(\"Unable to parse URL object\");return {protocol:e[1],authority:e[2],path:e[3]||\"/\",params:e[4]?e[4].split(\"&\"):[]}}function nt(t){var e=t.params.length?\"?\"+t.params.join(\"&\"):\"\";return t.protocol+\"://\"+t.authority+t.path+e}function it(t){if(!t)return null;var e,r=t.split(\".\");if(!r||3!==r.length)return null;try{return JSON.parse((e=r[1],decodeURIComponent(self.atob(e).split(\"\").map(function(t){return \"%\"+(\"00\"+t.charCodeAt(0).toString(16)).slice(-2)}).join(\"\"))))}catch(t){return null}}var at=function(t){this.type=t,this.anonId=null,this.eventData={},this.queue=[],this.pendingRequest=null;};at.prototype.getStorageKey=function(t){var e,r=it(V.ACCESS_TOKEN),n=\"\";return r&&r.u?(e=r.u,n=self.btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,e){return String.fromCharCode(Number(\"0x\"+e))}))):n=V.ACCESS_TOKEN||\"\",t?\"mapbox.eventData.\"+t+\":\"+n:\"mapbox.eventData:\"+n},at.prototype.fetchEventData=function(){var t=z(\"localStorage\"),e=this.getStorageKey(),r=this.getStorageKey(\"uuid\");if(t)try{var n=self.localStorage.getItem(e);n&&(this.eventData=JSON.parse(n));var i=self.localStorage.getItem(r);i&&(this.anonId=i);}catch(t){w(\"Unable to read from LocalStorage\");}},at.prototype.saveEventData=function(){var t=z(\"localStorage\"),e=this.getStorageKey(),r=this.getStorageKey(\"uuid\");if(t)try{self.localStorage.setItem(r,this.anonId),Object.keys(this.eventData).length>=1&&self.localStorage.setItem(e,JSON.stringify(this.eventData));}catch(t){w(\"Unable to write to LocalStorage\");}},at.prototype.processRequests=function(){},at.prototype.postEvent=function(t,e,r){var n=this;if(V.EVENTS_URL){var i=rt(V.EVENTS_URL);i.params.push(\"access_token=\"+(V.ACCESS_TOKEN||\"\"));var a={event:this.type,created:new Date(t).toISOString(),sdkIdentifier:\"mapbox-gl-js\",sdkVersion:\"1.1.1\",skuId:R,userId:this.anonId},o=e?c(a,e):a,s={url:nt(i),headers:{\"Content-Type\":\"text/plain\"},body:JSON.stringify([o])};this.pendingRequest=It(s,function(t){n.pendingRequest=null,r(t),n.saveEventData(),n.processRequests();});}},at.prototype.queueRequest=function(t){this.queue.push(t),this.processRequests();};var ot,st=function(t){function e(){t.call(this,\"map.load\"),this.success={},this.skuToken=\"\";}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.postMapLoadEvent=function(t,e,r){this.skuToken=r,V.EVENTS_URL&&V.ACCESS_TOKEN&&Array.isArray(t)&&t.some(function(t){return N(t)||K(t)})&&this.queueRequest({id:e,timestamp:Date.now()});},e.prototype.processRequests=function(){var t=this;if(!this.pendingRequest&&0!==this.queue.length){var e=this.queue.shift(),r=e.id,n=e.timestamp;r&&this.success[r]||(this.anonId||this.fetchEventData(),d(this.anonId)||(this.anonId=y()),this.postEvent(n,{skuToken:this.skuToken},function(e){e||r&&(t.success[r]=!0);}));}},e}(at),ut=new(function(t){function e(){t.call(this,\"appUserTurnstile\");}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.postTurnstileEvent=function(t){V.EVENTS_URL&&V.ACCESS_TOKEN&&Array.isArray(t)&&t.some(function(t){return N(t)||K(t)})&&this.queueRequest(Date.now());},e.prototype.processRequests=function(){var t=this;if(!this.pendingRequest&&0!==this.queue.length){this.anonId&&this.eventData.lastSuccess&&this.eventData.tokenU||this.fetchEventData();var e=it(V.ACCESS_TOKEN),r=e?e.u:V.ACCESS_TOKEN,n=r!==this.eventData.tokenU;d(this.anonId)||(this.anonId=y(),n=!0);var i=this.queue.shift();if(this.eventData.lastSuccess){var a=new Date(this.eventData.lastSuccess),o=new Date(i),s=(i-this.eventData.lastSuccess)/864e5;n=n||s>=1||s<-1||a.getDate()!==o.getDate();}else n=!0;if(!n)return this.processRequests();this.postEvent(i,{\"enabled.telemetry\":!1},function(e){e||(t.eventData.lastSuccess=i,t.eventData.tokenU=r);});}},e}(at)),lt=ut.postTurnstileEvent.bind(ut),pt=new st,ct=pt.postMapLoadEvent.bind(pt),ht=\"mapbox-tiles\",ft=500,yt=50,dt=42e4;function mt(t,e,r){if(self.caches){var n={status:e.status,statusText:e.statusText,headers:new self.Headers};e.headers.forEach(function(t,e){return n.headers.set(e,t)});var i=k(e.headers.get(\"Cache-Control\")||\"\");if(!i[\"no-store\"])i[\"max-age\"]&&n.headers.set(\"Expires\",new Date(r+1e3*i[\"max-age\"]).toUTCString()),new Date(n.headers.get(\"Expires\")).getTime()-r<dt||function(t,e){if(void 0===ot)try{new Response(new ReadableStream),ot=!0;}catch(t){ot=!1;}ot?e(t.body):t.blob().then(e);}(e,function(e){var r=new self.Response(e,n);self.caches.open(ht).then(function(e){return e.put(vt(t.url),r)});});}}function vt(t){var e=t.indexOf(\"?\");return e<0?t:t.slice(0,e)}function gt(t,e){if(!self.caches)return e(null);var r=vt(t.url);self.caches.open(ht).catch(e).then(function(t){t.match(r).catch(e).then(function(n){var i=function(t){if(!t)return !1;var e=new Date(t.headers.get(\"Expires\")),r=k(t.headers.get(\"Cache-Control\")||\"\");return e>Date.now()&&!r[\"no-cache\"]}(n);t.delete(r),i&&t.put(r,n.clone()),e(null,n,i);});});}var xt=1/0;var bt={Unknown:\"Unknown\",Style:\"Style\",Source:\"Source\",Tile:\"Tile\",Glyphs:\"Glyphs\",SpriteImage:\"SpriteImage\",SpriteJSON:\"SpriteJSON\",Image:\"Image\"};\"function\"==typeof Object.freeze&&Object.freeze(bt);var _t=function(t){function e(e,r,n){401===r&&K(n)&&(e+=\": you may have provided an invalid Mapbox access token. See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes\"),t.call(this,e),this.status=r,this.url=n,this.name=this.constructor.name,this.message=e;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.toString=function(){return this.name+\": \"+this.message+\" (\"+this.status+\"): \"+this.url},e}(Error);function wt(){return \"undefined\"!=typeof WorkerGlobalScope&&\"undefined\"!=typeof self&&self instanceof WorkerGlobalScope}var At=wt()?function(){return self.worker&&self.worker.referrer}:function(){var t=self.location.origin;if(t&&\"null\"!==t&&\"file://\"!==t)return t+self.location.pathname};function St(t,e){var r,n=new self.AbortController,i=new self.Request(t.url,{method:t.method||\"GET\",body:t.body,credentials:t.credentials,headers:t.headers,referrer:At(),signal:n.signal}),a=!1,o=!1,s=(r=i.url).indexOf(\"sku=\")>0&&K(r);\"json\"===t.type&&i.headers.set(\"Accept\",\"application/json\");var u=function(r,n,a){if(!o){if(r&&\"SecurityError\"!==r.message&&w(r),n&&a)return l(n);var u=Date.now();self.fetch(i).then(function(r){if(r.ok){var n=s?r.clone():null;return l(r,n,u)}return e(new _t(r.statusText,r.status,t.url))}).catch(function(t){20!==t.code&&e(new Error(t.message));});}},l=function(r,n,s){(\"arrayBuffer\"===t.type?r.arrayBuffer():\"json\"===t.type?r.json():r.text()).then(function(t){o||(n&&s&&mt(i,n,s),a=!0,e(null,t,r.headers.get(\"Cache-Control\"),r.headers.get(\"Expires\")));}).catch(function(t){return e(new Error(t.message))});};return s?gt(i,u):u(null,null),{cancel:function(){o=!0,a||n.abort();}}}var kt=function(t,e){if(!/^file:/.test(t.url)){if(self.fetch&&self.Request&&self.AbortController&&self.Request.prototype.hasOwnProperty(\"signal\"))return St(t,e);if(wt()&&self.worker&&self.worker.actor)return self.worker.actor.send(\"getResource\",t,e)}return function(t,e){var r=new self.XMLHttpRequest;for(var n in r.open(t.method||\"GET\",t.url,!0),\"arrayBuffer\"===t.type&&(r.responseType=\"arraybuffer\"),t.headers)r.setRequestHeader(n,t.headers[n]);return \"json\"===t.type&&r.setRequestHeader(\"Accept\",\"application/json\"),r.withCredentials=\"include\"===t.credentials,r.onerror=function(){e(new Error(r.statusText));},r.onload=function(){if((r.status>=200&&r.status<300||0===r.status)&&null!==r.response){var n=r.response;if(\"json\"===t.type)try{n=JSON.parse(r.response);}catch(t){return e(t)}e(null,n,r.getResponseHeader(\"Cache-Control\"),r.getResponseHeader(\"Expires\"));}else e(new _t(r.statusText,r.status,t.url));},r.send(t.body),{cancel:function(){return r.abort()}}}(t,e)},zt=function(t,e){return kt(c(t,{type:\"arrayBuffer\"}),e)},It=function(t,e){return kt(c(t,{method:\"POST\"}),e)};var Bt,Ct;Bt=[],Ct=0;var Et=function(t,e){if(Ct>=V.MAX_PARALLEL_IMAGE_REQUESTS){var r={requestParameters:t,callback:e,cancelled:!1,cancel:function(){this.cancelled=!0;}};return Bt.push(r),r}Ct++;var n=!1,i=function(){if(!n)for(n=!0,Ct--;Bt.length&&Ct<V.MAX_PARALLEL_IMAGE_REQUESTS;){var t=Bt.shift(),e=t.requestParameters,r=t.callback;t.cancelled||(t.cancel=Et(e,r).cancel);}},a=zt(t,function(t,r,n,a){if(i(),t)e(t);else if(r){var o=new self.Image,s=self.URL||self.webkitURL;o.onload=function(){e(null,o),s.revokeObjectURL(o.src);},o.onerror=function(){return e(new Error(\"Could not load image. Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported.\"))};var u=new self.Blob([new Uint8Array(r)],{type:\"image/png\"});o.cacheControl=n,o.expires=a,o.src=r.byteLength?s.createObjectURL(u):\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=\";}});return {cancel:function(){a.cancel(),i();}}};function Mt(t,e,r){r[t]&&-1!==r[t].indexOf(e)||(r[t]=r[t]||[],r[t].push(e));}function Tt(t,e,r){if(r&&r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1);}}var Pt=function(t,e){void 0===e&&(e={}),c(this,e),this.type=t;},Vt=function(t){function e(e,r){void 0===r&&(r={}),t.call(this,\"error\",c({error:e},r));}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Pt),Ft=function(){};Ft.prototype.on=function(t,e){return this._listeners=this._listeners||{},Mt(t,e,this._listeners),this},Ft.prototype.off=function(t,e){return Tt(t,e,this._listeners),Tt(t,e,this._oneTimeListeners),this},Ft.prototype.once=function(t,e){return this._oneTimeListeners=this._oneTimeListeners||{},Mt(t,e,this._oneTimeListeners),this},Ft.prototype.fire=function(t,e){\"string\"==typeof t&&(t=new Pt(t,e||{}));var r=t.type;if(this.listens(r)){t.target=this;for(var n=0,i=this._listeners&&this._listeners[r]?this._listeners[r].slice():[];n<i.length;n+=1){i[n].call(this,t);}for(var a=0,o=this._oneTimeListeners&&this._oneTimeListeners[r]?this._oneTimeListeners[r].slice():[];a<o.length;a+=1){var s=o[a];Tt(r,s,this._oneTimeListeners),s.call(this,t);}var u=this._eventedParent;u&&(c(t,\"function\"==typeof this._eventedParentData?this._eventedParentData():this._eventedParentData),u.fire(t));}else t instanceof Vt&&console.error(t.error);return this},Ft.prototype.listens=function(t){return this._listeners&&this._listeners[t]&&this._listeners[t].length>0||this._oneTimeListeners&&this._oneTimeListeners[t]&&this._oneTimeListeners[t].length>0||this._eventedParent&&this._eventedParent.listens(t)},Ft.prototype.setEventedParent=function(t,e){return this._eventedParent=t,this._eventedParentData=e,this};var Lt={$version:8,$root:{version:{required:!0,type:\"enum\",values:[8]},name:{type:\"string\"},metadata:{type:\"*\"},center:{type:\"array\",value:\"number\"},zoom:{type:\"number\"},bearing:{type:\"number\",default:0,period:360,units:\"degrees\"},pitch:{type:\"number\",default:0,units:\"degrees\"},light:{type:\"light\"},sources:{required:!0,type:\"sources\"},sprite:{type:\"string\"},glyphs:{type:\"string\"},transition:{type:\"transition\"},layers:{required:!0,type:\"array\",value:\"layer\"}},sources:{\"*\":{type:\"source\"}},source:[\"source_vector\",\"source_raster\",\"source_raster_dem\",\"source_geojson\",\"source_video\",\"source_image\"],source_vector:{type:{required:!0,type:\"enum\",values:{vector:{}}},url:{type:\"string\"},tiles:{type:\"array\",value:\"string\"},bounds:{type:\"array\",value:\"number\",length:4,default:[-180,-85.051129,180,85.051129]},scheme:{type:\"enum\",values:{xyz:{},tms:{}},default:\"xyz\"},minzoom:{type:\"number\",default:0},maxzoom:{type:\"number\",default:22},attribution:{type:\"string\"},\"*\":{type:\"*\"}},source_raster:{type:{required:!0,type:\"enum\",values:{raster:{}}},url:{type:\"string\"},tiles:{type:\"array\",value:\"string\"},bounds:{type:\"array\",value:\"number\",length:4,default:[-180,-85.051129,180,85.051129]},minzoom:{type:\"number\",default:0},maxzoom:{type:\"number\",default:22},tileSize:{type:\"number\",default:512,units:\"pixels\"},scheme:{type:\"enum\",values:{xyz:{},tms:{}},default:\"xyz\"},attribution:{type:\"string\"},\"*\":{type:\"*\"}},source_raster_dem:{type:{required:!0,type:\"enum\",values:{\"raster-dem\":{}}},url:{type:\"string\"},tiles:{type:\"array\",value:\"string\"},bounds:{type:\"array\",value:\"number\",length:4,default:[-180,-85.051129,180,85.051129]},minzoom:{type:\"number\",default:0},maxzoom:{type:\"number\",default:22},tileSize:{type:\"number\",default:512,units:\"pixels\"},attribution:{type:\"string\"},encoding:{type:\"enum\",values:{terrarium:{},mapbox:{}},default:\"mapbox\"},\"*\":{type:\"*\"}},source_geojson:{type:{required:!0,type:\"enum\",values:{geojson:{}}},data:{type:\"*\"},maxzoom:{type:\"number\",default:18},attribution:{type:\"string\"},buffer:{type:\"number\",default:128,maximum:512,minimum:0},tolerance:{type:\"number\",default:.375},cluster:{type:\"boolean\",default:!1},clusterRadius:{type:\"number\",default:50,minimum:0},clusterMaxZoom:{type:\"number\"},clusterProperties:{type:\"*\"},lineMetrics:{type:\"boolean\",default:!1},generateId:{type:\"boolean\",default:!1}},source_video:{type:{required:!0,type:\"enum\",values:{video:{}}},urls:{required:!0,type:\"array\",value:\"string\"},coordinates:{required:!0,type:\"array\",length:4,value:{type:\"array\",length:2,value:\"number\"}}},source_image:{type:{required:!0,type:\"enum\",values:{image:{}}},url:{required:!0,type:\"string\"},coordinates:{required:!0,type:\"array\",length:4,value:{type:\"array\",length:2,value:\"number\"}}},layer:{id:{type:\"string\",required:!0},type:{type:\"enum\",values:{fill:{},line:{},symbol:{},circle:{},heatmap:{},\"fill-extrusion\":{},raster:{},hillshade:{},background:{}},required:!0},metadata:{type:\"*\"},source:{type:\"string\"},\"source-layer\":{type:\"string\"},minzoom:{type:\"number\",minimum:0,maximum:24},maxzoom:{type:\"number\",minimum:0,maximum:24},filter:{type:\"filter\"},layout:{type:\"layout\"},paint:{type:\"paint\"}},layout:[\"layout_fill\",\"layout_line\",\"layout_circle\",\"layout_heatmap\",\"layout_fill-extrusion\",\"layout_symbol\",\"layout_raster\",\"layout_hillshade\",\"layout_background\"],layout_background:{visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},layout_fill:{visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},layout_circle:{visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},layout_heatmap:{visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},\"layout_fill-extrusion\":{visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},layout_line:{\"line-cap\":{type:\"enum\",values:{butt:{},round:{},square:{}},default:\"butt\",expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"line-join\":{type:\"enum\",values:{bevel:{},round:{},miter:{}},default:\"miter\",expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"line-miter-limit\":{type:\"number\",default:2,requires:[{\"line-join\":\"miter\"}],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"line-round-limit\":{type:\"number\",default:1.05,requires:[{\"line-join\":\"round\"}],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},layout_symbol:{\"symbol-placement\":{type:\"enum\",values:{point:{},line:{},\"line-center\":{}},default:\"point\",expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"symbol-spacing\":{type:\"number\",default:250,minimum:1,units:\"pixels\",requires:[{\"symbol-placement\":\"line\"}],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"symbol-avoid-edges\":{type:\"boolean\",default:!1,expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"symbol-sort-key\":{type:\"number\",expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"symbol-z-order\":{type:\"enum\",values:{auto:{},\"viewport-y\":{},source:{}},default:\"auto\",expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-allow-overlap\":{type:\"boolean\",default:!1,requires:[\"icon-image\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-ignore-placement\":{type:\"boolean\",default:!1,requires:[\"icon-image\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-optional\":{type:\"boolean\",default:!1,requires:[\"icon-image\",\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-rotation-alignment\":{type:\"enum\",values:{map:{},viewport:{},auto:{}},default:\"auto\",requires:[\"icon-image\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-size\":{type:\"number\",default:1,minimum:0,units:\"factor of the original icon size\",requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"icon-text-fit\":{type:\"enum\",values:{none:{},width:{},height:{},both:{}},default:\"none\",requires:[\"icon-image\",\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-text-fit-padding\":{type:\"array\",value:\"number\",length:4,default:[0,0,0,0],units:\"pixels\",requires:[\"icon-image\",\"text-field\",{\"icon-text-fit\":[\"both\",\"width\",\"height\"]}],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-image\":{type:\"string\",tokens:!0,expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"icon-rotate\":{type:\"number\",default:0,period:360,units:\"degrees\",requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"icon-padding\":{type:\"number\",default:2,minimum:0,units:\"pixels\",requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-keep-upright\":{type:\"boolean\",default:!1,requires:[\"icon-image\",{\"icon-rotation-alignment\":\"map\"},{\"symbol-placement\":[\"line\",\"line-center\"]}],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-offset\":{type:\"array\",value:\"number\",length:2,default:[0,0],requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"icon-anchor\":{type:\"enum\",values:{center:{},left:{},right:{},top:{},bottom:{},\"top-left\":{},\"top-right\":{},\"bottom-left\":{},\"bottom-right\":{}},default:\"center\",requires:[\"icon-image\"],expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"icon-pitch-alignment\":{type:\"enum\",values:{map:{},viewport:{},auto:{}},default:\"auto\",requires:[\"icon-image\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-pitch-alignment\":{type:\"enum\",values:{map:{},viewport:{},auto:{}},default:\"auto\",requires:[\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-rotation-alignment\":{type:\"enum\",values:{map:{},viewport:{},auto:{}},default:\"auto\",requires:[\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-field\":{type:\"formatted\",default:\"\",tokens:!0,expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-font\":{type:\"array\",value:\"string\",default:[\"Open Sans Regular\",\"Arial Unicode MS Regular\"],requires:[\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-size\":{type:\"number\",default:16,minimum:0,units:\"pixels\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-max-width\":{type:\"number\",default:10,minimum:0,units:\"ems\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-line-height\":{type:\"number\",default:1.2,units:\"ems\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-letter-spacing\":{type:\"number\",default:0,units:\"ems\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-justify\":{type:\"enum\",values:{auto:{},left:{},center:{},right:{}},default:\"center\",requires:[\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-radial-offset\":{type:\"number\",units:\"ems\",default:0,requires:[{\"!\":\"text-offset\"}],\"property-type\":\"data-driven\",expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]}},\"text-variable-anchor\":{type:\"array\",value:\"enum\",values:{center:{},left:{},right:{},top:{},bottom:{},\"top-left\":{},\"top-right\":{},\"bottom-left\":{},\"bottom-right\":{}},requires:[{\"!\":\"text-anchor\"},{\"!\":\"text-offset\"},{\"symbol-placement\":[\"point\"]}],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-anchor\":{type:\"enum\",requires:[\"text-field\"],values:{center:{},left:{},right:{},top:{},bottom:{},\"top-left\":{},\"top-right\":{},\"bottom-left\":{},\"bottom-right\":{}},default:\"center\",expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-max-angle\":{type:\"number\",default:45,units:\"degrees\",requires:[\"text-field\",{\"symbol-placement\":[\"line\",\"line-center\"]}],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-rotate\":{type:\"number\",default:0,period:360,units:\"degrees\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-padding\":{type:\"number\",default:2,minimum:0,units:\"pixels\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-keep-upright\":{type:\"boolean\",default:!0,requires:[\"text-field\",{\"text-rotation-alignment\":\"map\"},{\"symbol-placement\":[\"line\",\"line-center\"]}],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-transform\":{type:\"enum\",values:{none:{},uppercase:{},lowercase:{}},default:\"none\",requires:[\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-offset\":{type:\"array\",value:\"number\",units:\"ems\",length:2,default:[0,0],requires:[\"text-field\",{\"!\":\"text-radial-offset\"}],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"data-driven\"},\"text-allow-overlap\":{type:\"boolean\",default:!1,requires:[\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-ignore-placement\":{type:\"boolean\",default:!1,requires:[\"text-field\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-optional\":{type:\"boolean\",default:!1,requires:[\"text-field\",\"icon-image\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},layout_raster:{visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},layout_hillshade:{visibility:{type:\"enum\",values:{visible:{},none:{}},default:\"visible\",\"property-type\":\"constant\"}},filter:{type:\"array\",value:\"*\"},filter_operator:{type:\"enum\",values:{\"==\":{},\"!=\":{},\">\":{},\">=\":{},\"<\":{},\"<=\":{},in:{},\"!in\":{},all:{},any:{},none:{},has:{},\"!has\":{}}},geometry_type:{type:\"enum\",values:{Point:{},LineString:{},Polygon:{}}},function:{expression:{type:\"expression\"},stops:{type:\"array\",value:\"function_stop\"},base:{type:\"number\",default:1,minimum:0},property:{type:\"string\",default:\"$zoom\"},type:{type:\"enum\",values:{identity:{},exponential:{},interval:{},categorical:{}},default:\"exponential\"},colorSpace:{type:\"enum\",values:{rgb:{},lab:{},hcl:{}},default:\"rgb\"},default:{type:\"*\",required:!1}},function_stop:{type:\"array\",minimum:0,maximum:22,value:[\"number\",\"color\"],length:2},expression:{type:\"array\",value:\"*\",minimum:1},expression_name:{type:\"enum\",values:{let:{group:\"Variable binding\"},var:{group:\"Variable binding\"},literal:{group:\"Types\"},array:{group:\"Types\"},at:{group:\"Lookup\"},case:{group:\"Decision\"},match:{group:\"Decision\"},coalesce:{group:\"Decision\"},step:{group:\"Ramps, scales, curves\"},interpolate:{group:\"Ramps, scales, curves\"},\"interpolate-hcl\":{group:\"Ramps, scales, curves\"},\"interpolate-lab\":{group:\"Ramps, scales, curves\"},ln2:{group:\"Math\"},pi:{group:\"Math\"},e:{group:\"Math\"},typeof:{group:\"Types\"},string:{group:\"Types\"},number:{group:\"Types\"},boolean:{group:\"Types\"},object:{group:\"Types\"},collator:{group:\"Types\"},format:{group:\"Types\"},\"number-format\":{group:\"Types\"},\"to-string\":{group:\"Types\"},\"to-number\":{group:\"Types\"},\"to-boolean\":{group:\"Types\"},\"to-rgba\":{group:\"Color\"},\"to-color\":{group:\"Types\"},rgb:{group:\"Color\"},rgba:{group:\"Color\"},get:{group:\"Lookup\"},has:{group:\"Lookup\"},length:{group:\"Lookup\"},properties:{group:\"Feature data\"},\"feature-state\":{group:\"Feature data\"},\"geometry-type\":{group:\"Feature data\"},id:{group:\"Feature data\"},zoom:{group:\"Zoom\"},\"heatmap-density\":{group:\"Heatmap\"},\"line-progress\":{group:\"Feature data\"},accumulated:{group:\"Feature data\"},\"+\":{group:\"Math\"},\"*\":{group:\"Math\"},\"-\":{group:\"Math\"},\"/\":{group:\"Math\"},\"%\":{group:\"Math\"},\"^\":{group:\"Math\"},sqrt:{group:\"Math\"},log10:{group:\"Math\"},ln:{group:\"Math\"},log2:{group:\"Math\"},sin:{group:\"Math\"},cos:{group:\"Math\"},tan:{group:\"Math\"},asin:{group:\"Math\"},acos:{group:\"Math\"},atan:{group:\"Math\"},min:{group:\"Math\"},max:{group:\"Math\"},round:{group:\"Math\"},abs:{group:\"Math\"},ceil:{group:\"Math\"},floor:{group:\"Math\"},\"==\":{group:\"Decision\"},\"!=\":{group:\"Decision\"},\">\":{group:\"Decision\"},\"<\":{group:\"Decision\"},\">=\":{group:\"Decision\"},\"<=\":{group:\"Decision\"},all:{group:\"Decision\"},any:{group:\"Decision\"},\"!\":{group:\"Decision\"},\"is-supported-script\":{group:\"String\"},upcase:{group:\"String\"},downcase:{group:\"String\"},concat:{group:\"String\"},\"resolved-locale\":{group:\"String\"}}},light:{anchor:{type:\"enum\",default:\"viewport\",values:{map:{},viewport:{}},\"property-type\":\"data-constant\",transition:!1,expression:{interpolated:!1,parameters:[\"zoom\"]}},position:{type:\"array\",default:[1.15,210,30],length:3,value:\"number\",\"property-type\":\"data-constant\",transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]}},color:{type:\"color\",\"property-type\":\"data-constant\",default:\"#ffffff\",expression:{interpolated:!0,parameters:[\"zoom\"]},transition:!0},intensity:{type:\"number\",\"property-type\":\"data-constant\",default:.5,minimum:0,maximum:1,expression:{interpolated:!0,parameters:[\"zoom\"]},transition:!0}},paint:[\"paint_fill\",\"paint_line\",\"paint_circle\",\"paint_heatmap\",\"paint_fill-extrusion\",\"paint_symbol\",\"paint_raster\",\"paint_hillshade\",\"paint_background\"],paint_fill:{\"fill-antialias\":{type:\"boolean\",default:!0,expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"fill-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"fill-color\":{type:\"color\",default:\"#000000\",transition:!0,requires:[{\"!\":\"fill-pattern\"}],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"fill-outline-color\":{type:\"color\",transition:!0,requires:[{\"!\":\"fill-pattern\"},{\"fill-antialias\":!0}],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"fill-translate\":{type:\"array\",value:\"number\",length:2,default:[0,0],transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"fill-translate-anchor\":{type:\"enum\",values:{map:{},viewport:{}},default:\"map\",requires:[\"fill-translate\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"fill-pattern\":{type:\"string\",transition:!0,expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"cross-faded-data-driven\"}},\"paint_fill-extrusion\":{\"fill-extrusion-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"fill-extrusion-color\":{type:\"color\",default:\"#000000\",transition:!0,requires:[{\"!\":\"fill-extrusion-pattern\"}],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"fill-extrusion-translate\":{type:\"array\",value:\"number\",length:2,default:[0,0],transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"fill-extrusion-translate-anchor\":{type:\"enum\",values:{map:{},viewport:{}},default:\"map\",requires:[\"fill-extrusion-translate\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"fill-extrusion-pattern\":{type:\"string\",transition:!0,expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"cross-faded-data-driven\"},\"fill-extrusion-height\":{type:\"number\",default:0,minimum:0,units:\"meters\",transition:!0,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"fill-extrusion-base\":{type:\"number\",default:0,minimum:0,units:\"meters\",transition:!0,requires:[\"fill-extrusion-height\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"fill-extrusion-vertical-gradient\":{type:\"boolean\",default:!0,transition:!1,expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"}},paint_line:{\"line-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"line-color\":{type:\"color\",default:\"#000000\",transition:!0,requires:[{\"!\":\"line-pattern\"}],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"line-translate\":{type:\"array\",value:\"number\",length:2,default:[0,0],transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"line-translate-anchor\":{type:\"enum\",values:{map:{},viewport:{}},default:\"map\",requires:[\"line-translate\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"line-width\":{type:\"number\",default:1,minimum:0,transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"line-gap-width\":{type:\"number\",default:0,minimum:0,transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"line-offset\":{type:\"number\",default:0,transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"line-blur\":{type:\"number\",default:0,minimum:0,transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"line-dasharray\":{type:\"array\",value:\"number\",minimum:0,transition:!0,units:\"line widths\",requires:[{\"!\":\"line-pattern\"}],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"cross-faded\"},\"line-pattern\":{type:\"string\",transition:!0,expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]},\"property-type\":\"cross-faded-data-driven\"},\"line-gradient\":{type:\"color\",transition:!1,requires:[{\"!\":\"line-dasharray\"},{\"!\":\"line-pattern\"},{source:\"geojson\",has:{lineMetrics:!0}}],expression:{interpolated:!0,parameters:[\"line-progress\"]},\"property-type\":\"color-ramp\"}},paint_circle:{\"circle-radius\":{type:\"number\",default:5,minimum:0,transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"circle-color\":{type:\"color\",default:\"#000000\",transition:!0,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"circle-blur\":{type:\"number\",default:0,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"circle-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"circle-translate\":{type:\"array\",value:\"number\",length:2,default:[0,0],transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"circle-translate-anchor\":{type:\"enum\",values:{map:{},viewport:{}},default:\"map\",requires:[\"circle-translate\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"circle-pitch-scale\":{type:\"enum\",values:{map:{},viewport:{}},default:\"map\",expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"circle-pitch-alignment\":{type:\"enum\",values:{map:{},viewport:{}},default:\"viewport\",expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"circle-stroke-width\":{type:\"number\",default:0,minimum:0,transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"circle-stroke-color\":{type:\"color\",default:\"#000000\",transition:!0,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"circle-stroke-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"}},paint_heatmap:{\"heatmap-radius\":{type:\"number\",default:30,minimum:1,transition:!0,units:\"pixels\",expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"heatmap-weight\":{type:\"number\",default:1,minimum:0,transition:!1,expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"heatmap-intensity\":{type:\"number\",default:1,minimum:0,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"heatmap-color\":{type:\"color\",default:[\"interpolate\",[\"linear\"],[\"heatmap-density\"],0,\"rgba(0, 0, 255, 0)\",.1,\"royalblue\",.3,\"cyan\",.5,\"lime\",.7,\"yellow\",1,\"red\"],transition:!1,expression:{interpolated:!0,parameters:[\"heatmap-density\"]},\"property-type\":\"color-ramp\"},\"heatmap-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"}},paint_symbol:{\"icon-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"icon-color\":{type:\"color\",default:\"#000000\",transition:!0,requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"icon-halo-color\":{type:\"color\",default:\"rgba(0, 0, 0, 0)\",transition:!0,requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"icon-halo-width\":{type:\"number\",default:0,minimum:0,transition:!0,units:\"pixels\",requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"icon-halo-blur\":{type:\"number\",default:0,minimum:0,transition:!0,units:\"pixels\",requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"icon-translate\":{type:\"array\",value:\"number\",length:2,default:[0,0],transition:!0,units:\"pixels\",requires:[\"icon-image\"],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"icon-translate-anchor\":{type:\"enum\",values:{map:{},viewport:{}},default:\"map\",requires:[\"icon-image\",\"icon-translate\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"text-color\":{type:\"color\",default:\"#000000\",transition:!0,requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"text-halo-color\":{type:\"color\",default:\"rgba(0, 0, 0, 0)\",transition:!0,requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"text-halo-width\":{type:\"number\",default:0,minimum:0,transition:!0,units:\"pixels\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"text-halo-blur\":{type:\"number\",default:0,minimum:0,transition:!0,units:\"pixels\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\",\"feature\",\"feature-state\"]},\"property-type\":\"data-driven\"},\"text-translate\":{type:\"array\",value:\"number\",length:2,default:[0,0],transition:!0,units:\"pixels\",requires:[\"text-field\"],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"text-translate-anchor\":{type:\"enum\",values:{map:{},viewport:{}},default:\"map\",requires:[\"text-field\",\"text-translate\"],expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"}},paint_raster:{\"raster-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"raster-hue-rotate\":{type:\"number\",default:0,period:360,transition:!0,units:\"degrees\",expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"raster-brightness-min\":{type:\"number\",default:0,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"raster-brightness-max\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"raster-saturation\":{type:\"number\",default:0,minimum:-1,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"raster-contrast\":{type:\"number\",default:0,minimum:-1,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"raster-resampling\":{type:\"enum\",values:{linear:{},nearest:{}},default:\"linear\",expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"raster-fade-duration\":{type:\"number\",default:300,minimum:0,transition:!1,units:\"milliseconds\",expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"}},paint_hillshade:{\"hillshade-illumination-direction\":{type:\"number\",default:335,minimum:0,maximum:359,transition:!1,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"hillshade-illumination-anchor\":{type:\"enum\",values:{map:{},viewport:{}},default:\"viewport\",expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"hillshade-exaggeration\":{type:\"number\",default:.5,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"hillshade-shadow-color\":{type:\"color\",default:\"#000000\",transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"hillshade-highlight-color\":{type:\"color\",default:\"#FFFFFF\",transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"hillshade-accent-color\":{type:\"color\",default:\"#000000\",transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"}},paint_background:{\"background-color\":{type:\"color\",default:\"#000000\",transition:!0,requires:[{\"!\":\"background-pattern\"}],expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"},\"background-pattern\":{type:\"string\",transition:!0,expression:{interpolated:!1,parameters:[\"zoom\"]},\"property-type\":\"cross-faded\"},\"background-opacity\":{type:\"number\",default:1,minimum:0,maximum:1,transition:!0,expression:{interpolated:!0,parameters:[\"zoom\"]},\"property-type\":\"data-constant\"}},transition:{duration:{type:\"number\",default:300,minimum:0,units:\"milliseconds\"},delay:{type:\"number\",default:0,minimum:0,units:\"milliseconds\"}},\"property-type\":{\"data-driven\":{type:\"property-type\"},\"cross-faded\":{type:\"property-type\"},\"cross-faded-data-driven\":{type:\"property-type\"},\"color-ramp\":{type:\"property-type\"},\"data-constant\":{type:\"property-type\"},constant:{type:\"property-type\"}}},Dt=function(t,e,r,n){this.message=(t?t+\": \":\"\")+r,n&&(this.identifier=n),null!=e&&e.__line__&&(this.line=e.__line__);};function Ot(t){var e=t.key,r=t.value;return r?[new Dt(e,r,\"constants have been deprecated as of v8\")]:[]}function Rt(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];for(var n=0,i=e;n<i.length;n+=1){var a=i[n];for(var o in a)t[o]=a[o];}return t}function Ut(t){return t instanceof Number||t instanceof String||t instanceof Boolean}function jt(t){return Ut(t)?t.valueOf():t}function qt(t){if(Array.isArray(t))return t.map(qt);if(t instanceof Object&&!Ut(t)){var e={};for(var r in t)e[r]=qt(t[r]);return e}return jt(t)}var Nt=function(t){function e(e,r){t.call(this,r),this.message=r,this.key=e;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Error),Zt=function(t,e){void 0===e&&(e=[]),this.parent=t,this.bindings={};for(var r=0,n=e;r<n.length;r+=1){var i=n[r],a=i[0],o=i[1];this.bindings[a]=o;}};Zt.prototype.concat=function(t){return new Zt(this,t)},Zt.prototype.get=function(t){if(this.bindings[t])return this.bindings[t];if(this.parent)return this.parent.get(t);throw new Error(t+\" not found in scope.\")},Zt.prototype.has=function(t){return !!this.bindings[t]||!!this.parent&&this.parent.has(t)};var Kt={kind:\"null\"},Gt={kind:\"number\"},Xt={kind:\"string\"},Jt={kind:\"boolean\"},Ht={kind:\"color\"},Yt={kind:\"object\"},$t={kind:\"value\"},Wt={kind:\"collator\"},Qt={kind:\"formatted\"};function te(t,e){return {kind:\"array\",itemType:t,N:e}}function ee(t){if(\"array\"===t.kind){var e=ee(t.itemType);return \"number\"==typeof t.N?\"array<\"+e+\", \"+t.N+\">\":\"value\"===t.itemType.kind?\"array\":\"array<\"+e+\">\"}return t.kind}var re=[Kt,Gt,Xt,Jt,Ht,Qt,Yt,te($t)];function ne(t,e){if(\"error\"===e.kind)return null;if(\"array\"===t.kind){if(\"array\"===e.kind&&(0===e.N&&\"value\"===e.itemType.kind||!ne(t.itemType,e.itemType))&&(\"number\"!=typeof t.N||t.N===e.N))return null}else{if(t.kind===e.kind)return null;if(\"value\"===t.kind)for(var r=0,n=re;r<n.length;r+=1){if(!ne(n[r],e))return null}}return \"Expected \"+ee(t)+\" but found \"+ee(e)+\" instead.\"}var ie=e(function(t,e){var r={transparent:[0,0,0,0],aliceblue:[240,248,255,1],antiquewhite:[250,235,215,1],aqua:[0,255,255,1],aquamarine:[127,255,212,1],azure:[240,255,255,1],beige:[245,245,220,1],bisque:[255,228,196,1],black:[0,0,0,1],blanchedalmond:[255,235,205,1],blue:[0,0,255,1],blueviolet:[138,43,226,1],brown:[165,42,42,1],burlywood:[222,184,135,1],cadetblue:[95,158,160,1],chartreuse:[127,255,0,1],chocolate:[210,105,30,1],coral:[255,127,80,1],cornflowerblue:[100,149,237,1],cornsilk:[255,248,220,1],crimson:[220,20,60,1],cyan:[0,255,255,1],darkblue:[0,0,139,1],darkcyan:[0,139,139,1],darkgoldenrod:[184,134,11,1],darkgray:[169,169,169,1],darkgreen:[0,100,0,1],darkgrey:[169,169,169,1],darkkhaki:[189,183,107,1],darkmagenta:[139,0,139,1],darkolivegreen:[85,107,47,1],darkorange:[255,140,0,1],darkorchid:[153,50,204,1],darkred:[139,0,0,1],darksalmon:[233,150,122,1],darkseagreen:[143,188,143,1],darkslateblue:[72,61,139,1],darkslategray:[47,79,79,1],darkslategrey:[47,79,79,1],darkturquoise:[0,206,209,1],darkviolet:[148,0,211,1],deeppink:[255,20,147,1],deepskyblue:[0,191,255,1],dimgray:[105,105,105,1],dimgrey:[105,105,105,1],dodgerblue:[30,144,255,1],firebrick:[178,34,34,1],floralwhite:[255,250,240,1],forestgreen:[34,139,34,1],fuchsia:[255,0,255,1],gainsboro:[220,220,220,1],ghostwhite:[248,248,255,1],gold:[255,215,0,1],goldenrod:[218,165,32,1],gray:[128,128,128,1],green:[0,128,0,1],greenyellow:[173,255,47,1],grey:[128,128,128,1],honeydew:[240,255,240,1],hotpink:[255,105,180,1],indianred:[205,92,92,1],indigo:[75,0,130,1],ivory:[255,255,240,1],khaki:[240,230,140,1],lavender:[230,230,250,1],lavenderblush:[255,240,245,1],lawngreen:[124,252,0,1],lemonchiffon:[255,250,205,1],lightblue:[173,216,230,1],lightcoral:[240,128,128,1],lightcyan:[224,255,255,1],lightgoldenrodyellow:[250,250,210,1],lightgray:[211,211,211,1],lightgreen:[144,238,144,1],lightgrey:[211,211,211,1],lightpink:[255,182,193,1],lightsalmon:[255,160,122,1],lightseagreen:[32,178,170,1],lightskyblue:[135,206,250,1],lightslategray:[119,136,153,1],lightslategrey:[119,136,153,1],lightsteelblue:[176,196,222,1],lightyellow:[255,255,224,1],lime:[0,255,0,1],limegreen:[50,205,50,1],linen:[250,240,230,1],magenta:[255,0,255,1],maroon:[128,0,0,1],mediumaquamarine:[102,205,170,1],mediumblue:[0,0,205,1],mediumorchid:[186,85,211,1],mediumpurple:[147,112,219,1],mediumseagreen:[60,179,113,1],mediumslateblue:[123,104,238,1],mediumspringgreen:[0,250,154,1],mediumturquoise:[72,209,204,1],mediumvioletred:[199,21,133,1],midnightblue:[25,25,112,1],mintcream:[245,255,250,1],mistyrose:[255,228,225,1],moccasin:[255,228,181,1],navajowhite:[255,222,173,1],navy:[0,0,128,1],oldlace:[253,245,230,1],olive:[128,128,0,1],olivedrab:[107,142,35,1],orange:[255,165,0,1],orangered:[255,69,0,1],orchid:[218,112,214,1],palegoldenrod:[238,232,170,1],palegreen:[152,251,152,1],paleturquoise:[175,238,238,1],palevioletred:[219,112,147,1],papayawhip:[255,239,213,1],peachpuff:[255,218,185,1],peru:[205,133,63,1],pink:[255,192,203,1],plum:[221,160,221,1],powderblue:[176,224,230,1],purple:[128,0,128,1],rebeccapurple:[102,51,153,1],red:[255,0,0,1],rosybrown:[188,143,143,1],royalblue:[65,105,225,1],saddlebrown:[139,69,19,1],salmon:[250,128,114,1],sandybrown:[244,164,96,1],seagreen:[46,139,87,1],seashell:[255,245,238,1],sienna:[160,82,45,1],silver:[192,192,192,1],skyblue:[135,206,235,1],slateblue:[106,90,205,1],slategray:[112,128,144,1],slategrey:[112,128,144,1],snow:[255,250,250,1],springgreen:[0,255,127,1],steelblue:[70,130,180,1],tan:[210,180,140,1],teal:[0,128,128,1],thistle:[216,191,216,1],tomato:[255,99,71,1],turquoise:[64,224,208,1],violet:[238,130,238,1],wheat:[245,222,179,1],white:[255,255,255,1],whitesmoke:[245,245,245,1],yellow:[255,255,0,1],yellowgreen:[154,205,50,1]};function n(t){return (t=Math.round(t))<0?0:t>255?255:t}function i(t){return t<0?0:t>1?1:t}function a(t){return \"%\"===t[t.length-1]?n(parseFloat(t)/100*255):n(parseInt(t))}function o(t){return \"%\"===t[t.length-1]?i(parseFloat(t)/100):i(parseFloat(t))}function s(t,e,r){return r<0?r+=1:r>1&&(r-=1),6*r<1?t+(e-t)*r*6:2*r<1?e:3*r<2?t+(e-t)*(2/3-r)*6:t}try{e.parseCSSColor=function(t){var e,i=t.replace(/ /g,\"\").toLowerCase();if(i in r)return r[i].slice();if(\"#\"===i[0])return 4===i.length?(e=parseInt(i.substr(1),16))>=0&&e<=4095?[(3840&e)>>4|(3840&e)>>8,240&e|(240&e)>>4,15&e|(15&e)<<4,1]:null:7===i.length&&(e=parseInt(i.substr(1),16))>=0&&e<=16777215?[(16711680&e)>>16,(65280&e)>>8,255&e,1]:null;var u=i.indexOf(\"(\"),l=i.indexOf(\")\");if(-1!==u&&l+1===i.length){var p=i.substr(0,u),c=i.substr(u+1,l-(u+1)).split(\",\"),h=1;switch(p){case\"rgba\":if(4!==c.length)return null;h=o(c.pop());case\"rgb\":return 3!==c.length?null:[a(c[0]),a(c[1]),a(c[2]),h];case\"hsla\":if(4!==c.length)return null;h=o(c.pop());case\"hsl\":if(3!==c.length)return null;var f=(parseFloat(c[0])%360+360)%360/360,y=o(c[1]),d=o(c[2]),m=d<=.5?d*(y+1):d+y-d*y,v=2*d-m;return [n(255*s(v,m,f+1/3)),n(255*s(v,m,f)),n(255*s(v,m,f-1/3)),h];default:return null}}return null};}catch(t){}}).parseCSSColor,ae=function(t,e,r,n){void 0===n&&(n=1),this.r=t,this.g=e,this.b=r,this.a=n;};ae.parse=function(t){if(t){if(t instanceof ae)return t;if(\"string\"==typeof t){var e=ie(t);if(e)return new ae(e[0]/255*e[3],e[1]/255*e[3],e[2]/255*e[3],e[3])}}},ae.prototype.toString=function(){var t=this.toArray(),e=t[0],r=t[1],n=t[2],i=t[3];return \"rgba(\"+Math.round(e)+\",\"+Math.round(r)+\",\"+Math.round(n)+\",\"+i+\")\"},ae.prototype.toArray=function(){var t=this.r,e=this.g,r=this.b,n=this.a;return 0===n?[0,0,0,0]:[255*t/n,255*e/n,255*r/n,n]},ae.black=new ae(0,0,0,1),ae.white=new ae(1,1,1,1),ae.transparent=new ae(0,0,0,0),ae.red=new ae(1,0,0,1);var oe=function(t,e,r){this.sensitivity=t?e?\"variant\":\"case\":e?\"accent\":\"base\",this.locale=r,this.collator=new Intl.Collator(this.locale?this.locale:[],{sensitivity:this.sensitivity,usage:\"search\"});};oe.prototype.compare=function(t,e){return this.collator.compare(t,e)},oe.prototype.resolvedLocale=function(){return new Intl.Collator(this.locale?this.locale:[]).resolvedOptions().locale};var se=function(t,e,r){this.text=t,this.scale=e,this.fontStack=r;},ue=function(t){this.sections=t;};function le(t,e,r,n){return \"number\"==typeof t&&t>=0&&t<=255&&\"number\"==typeof e&&e>=0&&e<=255&&\"number\"==typeof r&&r>=0&&r<=255?void 0===n||\"number\"==typeof n&&n>=0&&n<=1?null:\"Invalid rgba value [\"+[t,e,r,n].join(\", \")+\"]: 'a' must be between 0 and 1.\":\"Invalid rgba value [\"+(\"number\"==typeof n?[t,e,r,n]:[t,e,r]).join(\", \")+\"]: 'r', 'g', and 'b' must be between 0 and 255.\"}function pe(t){if(null===t)return Kt;if(\"string\"==typeof t)return Xt;if(\"boolean\"==typeof t)return Jt;if(\"number\"==typeof t)return Gt;if(t instanceof ae)return Ht;if(t instanceof oe)return Wt;if(t instanceof ue)return Qt;if(Array.isArray(t)){for(var e,r=t.length,n=0,i=t;n<i.length;n+=1){var a=pe(i[n]);if(e){if(e===a)continue;e=$t;break}e=a;}return te(e||$t,r)}return Yt}function ce(t){var e=typeof t;return null===t?\"\":\"string\"===e||\"number\"===e||\"boolean\"===e?String(t):t instanceof ae||t instanceof ue?t.toString():JSON.stringify(t)}ue.fromString=function(t){return new ue([new se(t,null,null)])},ue.prototype.toString=function(){return this.sections.map(function(t){return t.text}).join(\"\")},ue.prototype.serialize=function(){for(var t=[\"format\"],e=0,r=this.sections;e<r.length;e+=1){var n=r[e];t.push(n.text);var i={};n.fontStack&&(i[\"text-font\"]=[\"literal\",n.fontStack.split(\",\")]),n.scale&&(i[\"font-scale\"]=n.scale),t.push(i);}return t};var he=function(t,e){this.type=t,this.value=e;};he.parse=function(t,e){if(2!==t.length)return e.error(\"'literal' expression requires exactly one argument, but found \"+(t.length-1)+\" instead.\");if(!function t(e){if(null===e)return !0;if(\"string\"==typeof e)return !0;if(\"boolean\"==typeof e)return !0;if(\"number\"==typeof e)return !0;if(e instanceof ae)return !0;if(e instanceof oe)return !0;if(e instanceof ue)return !0;if(Array.isArray(e)){for(var r=0,n=e;r<n.length;r+=1)if(!t(n[r]))return !1;return !0}if(\"object\"==typeof e){for(var i in e)if(!t(e[i]))return !1;return !0}return !1}(t[1]))return e.error(\"invalid value\");var r=t[1],n=pe(r),i=e.expectedType;return \"array\"!==n.kind||0!==n.N||!i||\"array\"!==i.kind||\"number\"==typeof i.N&&0!==i.N||(n=i),new he(n,r)},he.prototype.evaluate=function(){return this.value},he.prototype.eachChild=function(){},he.prototype.possibleOutputs=function(){return [this.value]},he.prototype.serialize=function(){return \"array\"===this.type.kind||\"object\"===this.type.kind?[\"literal\",this.value]:this.value instanceof ae?[\"rgba\"].concat(this.value.toArray()):this.value instanceof ue?this.value.serialize():this.value};var fe=function(t){this.name=\"ExpressionEvaluationError\",this.message=t;};fe.prototype.toJSON=function(){return this.message};var ye={string:Xt,number:Gt,boolean:Jt,object:Yt},de=function(t,e){this.type=t,this.args=e;};de.parse=function(t,e){if(t.length<2)return e.error(\"Expected at least one argument.\");var r,n=1,i=t[0];if(\"array\"===i){var a,o;if(t.length>2){var s=t[1];if(\"string\"!=typeof s||!(s in ye)||\"object\"===s)return e.error('The item type argument of \"array\" must be one of string, number, boolean',1);a=ye[s],n++;}else a=$t;if(t.length>3){if(null!==t[2]&&(\"number\"!=typeof t[2]||t[2]<0||t[2]!==Math.floor(t[2])))return e.error('The length argument to \"array\" must be a positive integer literal',2);o=t[2],n++;}r=te(a,o);}else r=ye[i];for(var u=[];n<t.length;n++){var l=e.parse(t[n],n,$t);if(!l)return null;u.push(l);}return new de(r,u)},de.prototype.evaluate=function(t){for(var e=0;e<this.args.length;e++){var r=this.args[e].evaluate(t);if(!ne(this.type,pe(r)))return r;if(e===this.args.length-1)throw new fe(\"Expected value to be of type \"+ee(this.type)+\", but found \"+ee(pe(r))+\" instead.\")}return null},de.prototype.eachChild=function(t){this.args.forEach(t);},de.prototype.possibleOutputs=function(){var t;return (t=[]).concat.apply(t,this.args.map(function(t){return t.possibleOutputs()}))},de.prototype.serialize=function(){var t=this.type,e=[t.kind];if(\"array\"===t.kind){var r=t.itemType;if(\"string\"===r.kind||\"number\"===r.kind||\"boolean\"===r.kind){e.push(r.kind);var n=t.N;(\"number\"==typeof n||this.args.length>1)&&e.push(n);}}return e.concat(this.args.map(function(t){return t.serialize()}))};var me=function(t){this.type=Qt,this.sections=t;};me.parse=function(t,e){if(t.length<3)return e.error(\"Expected at least two arguments.\");if((t.length-1)%2!=0)return e.error(\"Expected an even number of arguments.\");for(var r=[],n=1;n<t.length-1;n+=2){var i=e.parse(t[n],1,$t);if(!i)return null;var a=i.type.kind;if(\"string\"!==a&&\"value\"!==a&&\"null\"!==a)return e.error(\"Formatted text type must be 'string', 'value', or 'null'.\");var o=t[n+1];if(\"object\"!=typeof o||Array.isArray(o))return e.error(\"Format options argument must be an object.\");var s=null;if(o[\"font-scale\"]&&!(s=e.parse(o[\"font-scale\"],1,Gt)))return null;var u=null;if(o[\"text-font\"]&&!(u=e.parse(o[\"text-font\"],1,te(Xt))))return null;r.push({text:i,scale:s,font:u});}return new me(r)},me.prototype.evaluate=function(t){return new ue(this.sections.map(function(e){return new se(ce(e.text.evaluate(t)),e.scale?e.scale.evaluate(t):null,e.font?e.font.evaluate(t).join(\",\"):null)}))},me.prototype.eachChild=function(t){for(var e=0,r=this.sections;e<r.length;e+=1){var n=r[e];t(n.text),n.scale&&t(n.scale),n.font&&t(n.font);}},me.prototype.possibleOutputs=function(){return [void 0]},me.prototype.serialize=function(){for(var t=[\"format\"],e=0,r=this.sections;e<r.length;e+=1){var n=r[e];t.push(n.text.serialize());var i={};n.scale&&(i[\"font-scale\"]=n.scale.serialize()),n.font&&(i[\"text-font\"]=n.font.serialize()),t.push(i);}return t};var ve={\"to-boolean\":Jt,\"to-color\":Ht,\"to-number\":Gt,\"to-string\":Xt},ge=function(t,e){this.type=t,this.args=e;};ge.parse=function(t,e){if(t.length<2)return e.error(\"Expected at least one argument.\");var r=t[0];if((\"to-boolean\"===r||\"to-string\"===r)&&2!==t.length)return e.error(\"Expected one argument.\");for(var n=ve[r],i=[],a=1;a<t.length;a++){var o=e.parse(t[a],a,$t);if(!o)return null;i.push(o);}return new ge(n,i)},ge.prototype.evaluate=function(t){if(\"boolean\"===this.type.kind)return Boolean(this.args[0].evaluate(t));if(\"color\"===this.type.kind){for(var e,r,n=0,i=this.args;n<i.length;n+=1){if(r=null,(e=i[n].evaluate(t))instanceof ae)return e;if(\"string\"==typeof e){var a=t.parseColor(e);if(a)return a}else if(Array.isArray(e)&&!(r=e.length<3||e.length>4?\"Invalid rbga value \"+JSON.stringify(e)+\": expected an array containing either three or four numeric values.\":le(e[0],e[1],e[2],e[3])))return new ae(e[0]/255,e[1]/255,e[2]/255,e[3])}throw new fe(r||\"Could not parse color from value '\"+(\"string\"==typeof e?e:String(JSON.stringify(e)))+\"'\")}if(\"number\"===this.type.kind){for(var o=null,s=0,u=this.args;s<u.length;s+=1){if(null===(o=u[s].evaluate(t)))return 0;var l=Number(o);if(!isNaN(l))return l}throw new fe(\"Could not convert \"+JSON.stringify(o)+\" to number.\")}return \"formatted\"===this.type.kind?ue.fromString(ce(this.args[0].evaluate(t))):ce(this.args[0].evaluate(t))},ge.prototype.eachChild=function(t){this.args.forEach(t);},ge.prototype.possibleOutputs=function(){var t;return (t=[]).concat.apply(t,this.args.map(function(t){return t.possibleOutputs()}))},ge.prototype.serialize=function(){if(\"formatted\"===this.type.kind)return new me([{text:this.args[0],scale:null,font:null}]).serialize();var t=[\"to-\"+this.type.kind];return this.eachChild(function(e){t.push(e.serialize());}),t};var xe=[\"Unknown\",\"Point\",\"LineString\",\"Polygon\"],be=function(){this.globals=null,this.feature=null,this.featureState=null,this._parseColorCache={};};be.prototype.id=function(){return this.feature&&\"id\"in this.feature?this.feature.id:null},be.prototype.geometryType=function(){return this.feature?\"number\"==typeof this.feature.type?xe[this.feature.type]:this.feature.type:null},be.prototype.properties=function(){return this.feature&&this.feature.properties||{}},be.prototype.parseColor=function(t){var e=this._parseColorCache[t];return e||(e=this._parseColorCache[t]=ae.parse(t)),e};var _e=function(t,e,r,n){this.name=t,this.type=e,this._evaluate=r,this.args=n;};_e.prototype.evaluate=function(t){return this._evaluate(t,this.args)},_e.prototype.eachChild=function(t){this.args.forEach(t);},_e.prototype.possibleOutputs=function(){return [void 0]},_e.prototype.serialize=function(){return [this.name].concat(this.args.map(function(t){return t.serialize()}))},_e.parse=function(t,e){var r,n=t[0],i=_e.definitions[n];if(!i)return e.error('Unknown expression \"'+n+'\". If you wanted a literal array, use [\"literal\", [...]].',0);for(var a=Array.isArray(i)?i[0]:i.type,o=Array.isArray(i)?[[i[1],i[2]]]:i.overloads,s=o.filter(function(e){var r=e[0];return !Array.isArray(r)||r.length===t.length-1}),u=null,l=0,p=s;l<p.length;l+=1){var c=p[l],h=c[0],f=c[1];u=new Ie(e.registry,e.path,null,e.scope);for(var y=[],d=!1,m=1;m<t.length;m++){var v=t[m],g=Array.isArray(h)?h[m-1]:h.type,x=u.parse(v,1+y.length,g);if(!x){d=!0;break}y.push(x);}if(!d)if(Array.isArray(h)&&h.length!==y.length)u.error(\"Expected \"+h.length+\" arguments, but found \"+y.length+\" instead.\");else{for(var b=0;b<y.length;b++){var _=Array.isArray(h)?h[b]:h.type,w=y[b];u.concat(b+1).checkSubtype(_,w.type);}if(0===u.errors.length)return new _e(n,a,f,y)}}if(1===s.length)(r=e.errors).push.apply(r,u.errors);else{for(var A=(s.length?s:o).map(function(t){var e,r=t[0];return e=r,Array.isArray(e)?\"(\"+e.map(ee).join(\", \")+\")\":\"(\"+ee(e.type)+\"...)\"}).join(\" | \"),S=[],k=1;k<t.length;k++){var z=e.parse(t[k],1+S.length);if(!z)return null;S.push(ee(z.type));}e.error(\"Expected arguments of type \"+A+\", but found (\"+S.join(\", \")+\") instead.\");}return null},_e.register=function(t,e){for(var r in _e.definitions=e,e)t[r]=_e;};var we=function(t,e,r){this.type=Wt,this.locale=r,this.caseSensitive=t,this.diacriticSensitive=e;};function Ae(t){if(t instanceof _e){if(\"get\"===t.name&&1===t.args.length)return !1;if(\"feature-state\"===t.name)return !1;if(\"has\"===t.name&&1===t.args.length)return !1;if(\"properties\"===t.name||\"geometry-type\"===t.name||\"id\"===t.name)return !1;if(/^filter-/.test(t.name))return !1}var e=!0;return t.eachChild(function(t){e&&!Ae(t)&&(e=!1);}),e}function Se(t){if(t instanceof _e&&\"feature-state\"===t.name)return !1;var e=!0;return t.eachChild(function(t){e&&!Se(t)&&(e=!1);}),e}function ke(t,e){if(t instanceof _e&&e.indexOf(t.name)>=0)return !1;var r=!0;return t.eachChild(function(t){r&&!ke(t,e)&&(r=!1);}),r}we.parse=function(t,e){if(2!==t.length)return e.error(\"Expected one argument.\");var r=t[1];if(\"object\"!=typeof r||Array.isArray(r))return e.error(\"Collator options argument must be an object.\");var n=e.parse(void 0!==r[\"case-sensitive\"]&&r[\"case-sensitive\"],1,Jt);if(!n)return null;var i=e.parse(void 0!==r[\"diacritic-sensitive\"]&&r[\"diacritic-sensitive\"],1,Jt);if(!i)return null;var a=null;return r.locale&&!(a=e.parse(r.locale,1,Xt))?null:new we(n,i,a)},we.prototype.evaluate=function(t){return new oe(this.caseSensitive.evaluate(t),this.diacriticSensitive.evaluate(t),this.locale?this.locale.evaluate(t):null)},we.prototype.eachChild=function(t){t(this.caseSensitive),t(this.diacriticSensitive),this.locale&&t(this.locale);},we.prototype.possibleOutputs=function(){return [void 0]},we.prototype.serialize=function(){var t={};return t[\"case-sensitive\"]=this.caseSensitive.serialize(),t[\"diacritic-sensitive\"]=this.diacriticSensitive.serialize(),this.locale&&(t.locale=this.locale.serialize()),[\"collator\",t]};var ze=function(t,e){this.type=e.type,this.name=t,this.boundExpression=e;};ze.parse=function(t,e){if(2!==t.length||\"string\"!=typeof t[1])return e.error(\"'var' expression requires exactly one string literal argument.\");var r=t[1];return e.scope.has(r)?new ze(r,e.scope.get(r)):e.error('Unknown variable \"'+r+'\". Make sure \"'+r+'\" has been bound in an enclosing \"let\" expression before using it.',1)},ze.prototype.evaluate=function(t){return this.boundExpression.evaluate(t)},ze.prototype.eachChild=function(){},ze.prototype.possibleOutputs=function(){return [void 0]},ze.prototype.serialize=function(){return [\"var\",this.name]};var Ie=function(t,e,r,n,i){void 0===e&&(e=[]),void 0===n&&(n=new Zt),void 0===i&&(i=[]),this.registry=t,this.path=e,this.key=e.map(function(t){return \"[\"+t+\"]\"}).join(\"\"),this.scope=n,this.errors=i,this.expectedType=r;};function Be(t,e){for(var r,n,i=t.length-1,a=0,o=i,s=0;a<=o;)if(r=t[s=Math.floor((a+o)/2)],n=t[s+1],r<=e){if(s===i||e<n)return s;a=s+1;}else{if(!(r>e))throw new fe(\"Input is not a number.\");o=s-1;}return 0}Ie.prototype.parse=function(t,e,r,n,i){return void 0===i&&(i={}),e?this.concat(e,r,n)._parse(t,i):this._parse(t,i)},Ie.prototype._parse=function(t,e){function r(t,e,r){return \"assert\"===r?new de(e,[t]):\"coerce\"===r?new ge(e,[t]):t}if(null!==t&&\"string\"!=typeof t&&\"boolean\"!=typeof t&&\"number\"!=typeof t||(t=[\"literal\",t]),Array.isArray(t)){if(0===t.length)return this.error('Expected an array with at least one element. If you wanted a literal array, use [\"literal\", []].');var n=t[0];if(\"string\"!=typeof n)return this.error(\"Expression name must be a string, but found \"+typeof n+' instead. If you wanted a literal array, use [\"literal\", [...]].',0),null;var i=this.registry[n];if(i){var a=i.parse(t,this);if(!a)return null;if(this.expectedType){var o=this.expectedType,s=a.type;if(\"string\"!==o.kind&&\"number\"!==o.kind&&\"boolean\"!==o.kind&&\"object\"!==o.kind&&\"array\"!==o.kind||\"value\"!==s.kind)if(\"color\"!==o.kind&&\"formatted\"!==o.kind||\"value\"!==s.kind&&\"string\"!==s.kind){if(this.checkSubtype(o,s))return null}else a=r(a,o,e.typeAnnotation||\"coerce\");else a=r(a,o,e.typeAnnotation||\"assert\");}if(!(a instanceof he)&&function t(e){if(e instanceof ze)return t(e.boundExpression);if(e instanceof _e&&\"error\"===e.name)return !1;if(e instanceof we)return !1;var r=e instanceof ge||e instanceof de;var n=!0;e.eachChild(function(e){n=r?n&&t(e):n&&e instanceof he;});if(!n)return !1;return Ae(e)&&ke(e,[\"zoom\",\"heatmap-density\",\"line-progress\",\"accumulated\",\"is-supported-script\"])}(a)){var u=new be;try{a=new he(a.type,a.evaluate(u));}catch(t){return this.error(t.message),null}}return a}return this.error('Unknown expression \"'+n+'\". If you wanted a literal array, use [\"literal\", [...]].',0)}return void 0===t?this.error(\"'undefined' value invalid. Use null instead.\"):\"object\"==typeof t?this.error('Bare objects invalid. Use [\"literal\", {...}] instead.'):this.error(\"Expected an array, but found \"+typeof t+\" instead.\")},Ie.prototype.concat=function(t,e,r){var n=\"number\"==typeof t?this.path.concat(t):this.path,i=r?this.scope.concat(r):this.scope;return new Ie(this.registry,n,e||null,i,this.errors)},Ie.prototype.error=function(t){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];var n=\"\"+this.key+e.map(function(t){return \"[\"+t+\"]\"}).join(\"\");this.errors.push(new Nt(n,t));},Ie.prototype.checkSubtype=function(t,e){var r=ne(t,e);return r&&this.error(r),r};var Ce=function(t,e,r){this.type=t,this.input=e,this.labels=[],this.outputs=[];for(var n=0,i=r;n<i.length;n+=1){var a=i[n],o=a[0],s=a[1];this.labels.push(o),this.outputs.push(s);}};function Ee(t,e,r){return t*(1-r)+e*r}Ce.parse=function(t,e){if(t.length-1<4)return e.error(\"Expected at least 4 arguments, but found only \"+(t.length-1)+\".\");if((t.length-1)%2!=0)return e.error(\"Expected an even number of arguments.\");var r=e.parse(t[1],1,Gt);if(!r)return null;var n=[],i=null;e.expectedType&&\"value\"!==e.expectedType.kind&&(i=e.expectedType);for(var a=1;a<t.length;a+=2){var o=1===a?-1/0:t[a],s=t[a+1],u=a,l=a+1;if(\"number\"!=typeof o)return e.error('Input/output pairs for \"step\" expressions must be defined using literal numeric values (not computed expressions) for the input values.',u);if(n.length&&n[n.length-1][0]>=o)return e.error('Input/output pairs for \"step\" expressions must be arranged with input values in strictly ascending order.',u);var p=e.parse(s,l,i);if(!p)return null;i=i||p.type,n.push([o,p]);}return new Ce(i,r,n)},Ce.prototype.evaluate=function(t){var e=this.labels,r=this.outputs;if(1===e.length)return r[0].evaluate(t);var n=this.input.evaluate(t);if(n<=e[0])return r[0].evaluate(t);var i=e.length;return n>=e[i-1]?r[i-1].evaluate(t):r[Be(e,n)].evaluate(t)},Ce.prototype.eachChild=function(t){t(this.input);for(var e=0,r=this.outputs;e<r.length;e+=1){t(r[e]);}},Ce.prototype.possibleOutputs=function(){var t;return (t=[]).concat.apply(t,this.outputs.map(function(t){return t.possibleOutputs()}))},Ce.prototype.serialize=function(){for(var t=[\"step\",this.input.serialize()],e=0;e<this.labels.length;e++)e>0&&t.push(this.labels[e]),t.push(this.outputs[e].serialize());return t};var Me=Object.freeze({number:Ee,color:function(t,e,r){return new ae(Ee(t.r,e.r,r),Ee(t.g,e.g,r),Ee(t.b,e.b,r),Ee(t.a,e.a,r))},array:function(t,e,r){return t.map(function(t,n){return Ee(t,e[n],r)})}}),Te=.95047,Pe=1,Ve=1.08883,Fe=4/29,Le=6/29,De=3*Le*Le,Oe=Le*Le*Le,Re=Math.PI/180,Ue=180/Math.PI;function je(t){return t>Oe?Math.pow(t,1/3):t/De+Fe}function qe(t){return t>Le?t*t*t:De*(t-Fe)}function Ne(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function Ze(t){return (t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function Ke(t){var e=Ze(t.r),r=Ze(t.g),n=Ze(t.b),i=je((.4124564*e+.3575761*r+.1804375*n)/Te),a=je((.2126729*e+.7151522*r+.072175*n)/Pe);return {l:116*a-16,a:500*(i-a),b:200*(a-je((.0193339*e+.119192*r+.9503041*n)/Ve)),alpha:t.a}}function Ge(t){var e=(t.l+16)/116,r=isNaN(t.a)?e:e+t.a/500,n=isNaN(t.b)?e:e-t.b/200;return e=Pe*qe(e),r=Te*qe(r),n=Ve*qe(n),new ae(Ne(3.2404542*r-1.5371385*e-.4985314*n),Ne(-.969266*r+1.8760108*e+.041556*n),Ne(.0556434*r-.2040259*e+1.0572252*n),t.alpha)}function Xe(t,e,r){var n=e-t;return t+r*(n>180||n<-180?n-360*Math.round(n/360):n)}var Je={forward:Ke,reverse:Ge,interpolate:function(t,e,r){return {l:Ee(t.l,e.l,r),a:Ee(t.a,e.a,r),b:Ee(t.b,e.b,r),alpha:Ee(t.alpha,e.alpha,r)}}},He={forward:function(t){var e=Ke(t),r=e.l,n=e.a,i=e.b,a=Math.atan2(i,n)*Ue;return {h:a<0?a+360:a,c:Math.sqrt(n*n+i*i),l:r,alpha:t.a}},reverse:function(t){var e=t.h*Re,r=t.c;return Ge({l:t.l,a:Math.cos(e)*r,b:Math.sin(e)*r,alpha:t.alpha})},interpolate:function(t,e,r){return {h:Xe(t.h,e.h,r),c:Ee(t.c,e.c,r),l:Ee(t.l,e.l,r),alpha:Ee(t.alpha,e.alpha,r)}}},Ye=Object.freeze({lab:Je,hcl:He}),$e=function(t,e,r,n,i){this.type=t,this.operator=e,this.interpolation=r,this.input=n,this.labels=[],this.outputs=[];for(var a=0,o=i;a<o.length;a+=1){var s=o[a],u=s[0],l=s[1];this.labels.push(u),this.outputs.push(l);}};function We(t,e,r,n){var i=n-r,a=t-r;return 0===i?0:1===e?a/i:(Math.pow(e,a)-1)/(Math.pow(e,i)-1)}$e.interpolationFactor=function(t,e,n,i){var a=0;if(\"exponential\"===t.name)a=We(e,t.base,n,i);else if(\"linear\"===t.name)a=We(e,1,n,i);else if(\"cubic-bezier\"===t.name){var o=t.controlPoints;a=new r(o[0],o[1],o[2],o[3]).solve(We(e,1,n,i));}return a},$e.parse=function(t,e){var r=t[0],n=t[1],i=t[2],a=t.slice(3);if(!Array.isArray(n)||0===n.length)return e.error(\"Expected an interpolation type expression.\",1);if(\"linear\"===n[0])n={name:\"linear\"};else if(\"exponential\"===n[0]){var o=n[1];if(\"number\"!=typeof o)return e.error(\"Exponential interpolation requires a numeric base.\",1,1);n={name:\"exponential\",base:o};}else{if(\"cubic-bezier\"!==n[0])return e.error(\"Unknown interpolation type \"+String(n[0]),1,0);var s=n.slice(1);if(4!==s.length||s.some(function(t){return \"number\"!=typeof t||t<0||t>1}))return e.error(\"Cubic bezier interpolation requires four numeric arguments with values between 0 and 1.\",1);n={name:\"cubic-bezier\",controlPoints:s};}if(t.length-1<4)return e.error(\"Expected at least 4 arguments, but found only \"+(t.length-1)+\".\");if((t.length-1)%2!=0)return e.error(\"Expected an even number of arguments.\");if(!(i=e.parse(i,2,Gt)))return null;var u=[],l=null;\"interpolate-hcl\"===r||\"interpolate-lab\"===r?l=Ht:e.expectedType&&\"value\"!==e.expectedType.kind&&(l=e.expectedType);for(var p=0;p<a.length;p+=2){var c=a[p],h=a[p+1],f=p+3,y=p+4;if(\"number\"!=typeof c)return e.error('Input/output pairs for \"interpolate\" expressions must be defined using literal numeric values (not computed expressions) for the input values.',f);if(u.length&&u[u.length-1][0]>=c)return e.error('Input/output pairs for \"interpolate\" expressions must be arranged with input values in strictly ascending order.',f);var d=e.parse(h,y,l);if(!d)return null;l=l||d.type,u.push([c,d]);}return \"number\"===l.kind||\"color\"===l.kind||\"array\"===l.kind&&\"number\"===l.itemType.kind&&\"number\"==typeof l.N?new $e(l,r,n,i,u):e.error(\"Type \"+ee(l)+\" is not interpolatable.\")},$e.prototype.evaluate=function(t){var e=this.labels,r=this.outputs;if(1===e.length)return r[0].evaluate(t);var n=this.input.evaluate(t);if(n<=e[0])return r[0].evaluate(t);var i=e.length;if(n>=e[i-1])return r[i-1].evaluate(t);var a=Be(e,n),o=e[a],s=e[a+1],u=$e.interpolationFactor(this.interpolation,n,o,s),l=r[a].evaluate(t),p=r[a+1].evaluate(t);return \"interpolate\"===this.operator?Me[this.type.kind.toLowerCase()](l,p,u):\"interpolate-hcl\"===this.operator?He.reverse(He.interpolate(He.forward(l),He.forward(p),u)):Je.reverse(Je.interpolate(Je.forward(l),Je.forward(p),u))},$e.prototype.eachChild=function(t){t(this.input);for(var e=0,r=this.outputs;e<r.length;e+=1){t(r[e]);}},$e.prototype.possibleOutputs=function(){var t;return (t=[]).concat.apply(t,this.outputs.map(function(t){return t.possibleOutputs()}))},$e.prototype.serialize=function(){var t;t=\"linear\"===this.interpolation.name?[\"linear\"]:\"exponential\"===this.interpolation.name?1===this.interpolation.base?[\"linear\"]:[\"exponential\",this.interpolation.base]:[\"cubic-bezier\"].concat(this.interpolation.controlPoints);for(var e=[this.operator,t,this.input.serialize()],r=0;r<this.labels.length;r++)e.push(this.labels[r],this.outputs[r].serialize());return e};var Qe=function(t,e){this.type=t,this.args=e;};Qe.parse=function(t,e){if(t.length<2)return e.error(\"Expectected at least one argument.\");var r=null,n=e.expectedType;n&&\"value\"!==n.kind&&(r=n);for(var i=[],a=0,o=t.slice(1);a<o.length;a+=1){var s=o[a],u=e.parse(s,1+i.length,r,void 0,{typeAnnotation:\"omit\"});if(!u)return null;r=r||u.type,i.push(u);}var l=n&&i.some(function(t){return ne(n,t.type)});return new Qe(l?$t:r,i)},Qe.prototype.evaluate=function(t){for(var e=null,r=0,n=this.args;r<n.length;r+=1){if(null!==(e=n[r].evaluate(t)))break}return e},Qe.prototype.eachChild=function(t){this.args.forEach(t);},Qe.prototype.possibleOutputs=function(){var t;return (t=[]).concat.apply(t,this.args.map(function(t){return t.possibleOutputs()}))},Qe.prototype.serialize=function(){var t=[\"coalesce\"];return this.eachChild(function(e){t.push(e.serialize());}),t};var tr=function(t,e){this.type=e.type,this.bindings=[].concat(t),this.result=e;};tr.prototype.evaluate=function(t){return this.result.evaluate(t)},tr.prototype.eachChild=function(t){for(var e=0,r=this.bindings;e<r.length;e+=1){t(r[e][1]);}t(this.result);},tr.parse=function(t,e){if(t.length<4)return e.error(\"Expected at least 3 arguments, but found \"+(t.length-1)+\" instead.\");for(var r=[],n=1;n<t.length-1;n+=2){var i=t[n];if(\"string\"!=typeof i)return e.error(\"Expected string, but found \"+typeof i+\" instead.\",n);if(/[^a-zA-Z0-9_]/.test(i))return e.error(\"Variable names must contain only alphanumeric characters or '_'.\",n);var a=e.parse(t[n+1],n+1);if(!a)return null;r.push([i,a]);}var o=e.parse(t[t.length-1],t.length-1,e.expectedType,r);return o?new tr(r,o):null},tr.prototype.possibleOutputs=function(){return this.result.possibleOutputs()},tr.prototype.serialize=function(){for(var t=[\"let\"],e=0,r=this.bindings;e<r.length;e+=1){var n=r[e],i=n[0],a=n[1];t.push(i,a.serialize());}return t.push(this.result.serialize()),t};var er=function(t,e,r){this.type=t,this.index=e,this.input=r;};er.parse=function(t,e){if(3!==t.length)return e.error(\"Expected 2 arguments, but found \"+(t.length-1)+\" instead.\");var r=e.parse(t[1],1,Gt),n=e.parse(t[2],2,te(e.expectedType||$t));if(!r||!n)return null;var i=n.type;return new er(i.itemType,r,n)},er.prototype.evaluate=function(t){var e=this.index.evaluate(t),r=this.input.evaluate(t);if(e<0)throw new fe(\"Array index out of bounds: \"+e+\" < 0.\");if(e>=r.length)throw new fe(\"Array index out of bounds: \"+e+\" > \"+(r.length-1)+\".\");if(e!==Math.floor(e))throw new fe(\"Array index must be an integer, but found \"+e+\" instead.\");return r[e]},er.prototype.eachChild=function(t){t(this.index),t(this.input);},er.prototype.possibleOutputs=function(){return [void 0]},er.prototype.serialize=function(){return [\"at\",this.index.serialize(),this.input.serialize()]};var rr=function(t,e,r,n,i,a){this.inputType=t,this.type=e,this.input=r,this.cases=n,this.outputs=i,this.otherwise=a;};rr.parse=function(t,e){if(t.length<5)return e.error(\"Expected at least 4 arguments, but found only \"+(t.length-1)+\".\");if(t.length%2!=1)return e.error(\"Expected an even number of arguments.\");var r,n;e.expectedType&&\"value\"!==e.expectedType.kind&&(n=e.expectedType);for(var i={},a=[],o=2;o<t.length-1;o+=2){var s=t[o],u=t[o+1];Array.isArray(s)||(s=[s]);var l=e.concat(o);if(0===s.length)return l.error(\"Expected at least one branch label.\");for(var p=0,c=s;p<c.length;p+=1){var h=c[p];if(\"number\"!=typeof h&&\"string\"!=typeof h)return l.error(\"Branch labels must be numbers or strings.\");if(\"number\"==typeof h&&Math.abs(h)>Number.MAX_SAFE_INTEGER)return l.error(\"Branch labels must be integers no larger than \"+Number.MAX_SAFE_INTEGER+\".\");if(\"number\"==typeof h&&Math.floor(h)!==h)return l.error(\"Numeric branch labels must be integer values.\");if(r){if(l.checkSubtype(r,pe(h)))return null}else r=pe(h);if(void 0!==i[String(h)])return l.error(\"Branch labels must be unique.\");i[String(h)]=a.length;}var f=e.parse(u,o,n);if(!f)return null;n=n||f.type,a.push(f);}var y=e.parse(t[1],1,$t);if(!y)return null;var d=e.parse(t[t.length-1],t.length-1,n);return d?\"value\"!==y.type.kind&&e.concat(1).checkSubtype(r,y.type)?null:new rr(r,n,y,i,a,d):null},rr.prototype.evaluate=function(t){var e=this.input.evaluate(t);return (pe(e)===this.inputType&&this.outputs[this.cases[e]]||this.otherwise).evaluate(t)},rr.prototype.eachChild=function(t){t(this.input),this.outputs.forEach(t),t(this.otherwise);},rr.prototype.possibleOutputs=function(){var t;return (t=[]).concat.apply(t,this.outputs.map(function(t){return t.possibleOutputs()})).concat(this.otherwise.possibleOutputs())},rr.prototype.serialize=function(){for(var t=this,e=[\"match\",this.input.serialize()],r=[],n={},i=0,a=Object.keys(this.cases).sort();i<a.length;i+=1){var o=a[i];void 0===(c=n[this.cases[o]])?(n[this.cases[o]]=r.length,r.push([this.cases[o],[o]])):r[c][1].push(o);}for(var s=function(e){return \"number\"===t.inputType.kind?Number(e):e},u=0,l=r;u<l.length;u+=1){var p=l[u],c=p[0],h=p[1];1===h.length?e.push(s(h[0])):e.push(h.map(s)),e.push(this.outputs[outputIndex$1].serialize());}return e.push(this.otherwise.serialize()),e};var nr=function(t,e,r){this.type=t,this.branches=e,this.otherwise=r;};function ir(t,e){return \"==\"===t||\"!=\"===t?\"boolean\"===e.kind||\"string\"===e.kind||\"number\"===e.kind||\"null\"===e.kind||\"value\"===e.kind:\"string\"===e.kind||\"number\"===e.kind||\"value\"===e.kind}function ar(t,e,r,n){return 0===n.compare(e,r)}function or(t,e,r){var n=\"==\"!==t&&\"!=\"!==t;return function(){function i(t,e,r){this.type=Jt,this.lhs=t,this.rhs=e,this.collator=r,this.hasUntypedArgument=\"value\"===t.type.kind||\"value\"===e.type.kind;}return i.parse=function(t,e){if(3!==t.length&&4!==t.length)return e.error(\"Expected two or three arguments.\");var r=t[0],a=e.parse(t[1],1,$t);if(!a)return null;if(!ir(r,a.type))return e.concat(1).error('\"'+r+\"\\\" comparisons are not supported for type '\"+ee(a.type)+\"'.\");var o=e.parse(t[2],2,$t);if(!o)return null;if(!ir(r,o.type))return e.concat(2).error('\"'+r+\"\\\" comparisons are not supported for type '\"+ee(o.type)+\"'.\");if(a.type.kind!==o.type.kind&&\"value\"!==a.type.kind&&\"value\"!==o.type.kind)return e.error(\"Cannot compare types '\"+ee(a.type)+\"' and '\"+ee(o.type)+\"'.\");n&&(\"value\"===a.type.kind&&\"value\"!==o.type.kind?a=new de(o.type,[a]):\"value\"!==a.type.kind&&\"value\"===o.type.kind&&(o=new de(a.type,[o])));var s=null;if(4===t.length){if(\"string\"!==a.type.kind&&\"string\"!==o.type.kind&&\"value\"!==a.type.kind&&\"value\"!==o.type.kind)return e.error(\"Cannot use collator to compare non-string types.\");if(!(s=e.parse(t[3],3,Wt)))return null}return new i(a,o,s)},i.prototype.evaluate=function(i){var a=this.lhs.evaluate(i),o=this.rhs.evaluate(i);if(n&&this.hasUntypedArgument){var s=pe(a),u=pe(o);if(s.kind!==u.kind||\"string\"!==s.kind&&\"number\"!==s.kind)throw new fe('Expected arguments for \"'+t+'\" to be (string, string) or (number, number), but found ('+s.kind+\", \"+u.kind+\") instead.\")}if(this.collator&&!n&&this.hasUntypedArgument){var l=pe(a),p=pe(o);if(\"string\"!==l.kind||\"string\"!==p.kind)return e(i,a,o)}return this.collator?r(i,a,o,this.collator.evaluate(i)):e(i,a,o)},i.prototype.eachChild=function(t){t(this.lhs),t(this.rhs),this.collator&&t(this.collator);},i.prototype.possibleOutputs=function(){return [!0,!1]},i.prototype.serialize=function(){var e=[t];return this.eachChild(function(t){e.push(t.serialize());}),e},i}()}nr.parse=function(t,e){if(t.length<4)return e.error(\"Expected at least 3 arguments, but found only \"+(t.length-1)+\".\");if(t.length%2!=0)return e.error(\"Expected an odd number of arguments.\");var r;e.expectedType&&\"value\"!==e.expectedType.kind&&(r=e.expectedType);for(var n=[],i=1;i<t.length-1;i+=2){var a=e.parse(t[i],i,Jt);if(!a)return null;var o=e.parse(t[i+1],i+1,r);if(!o)return null;n.push([a,o]),r=r||o.type;}var s=e.parse(t[t.length-1],t.length-1,r);return s?new nr(r,n,s):null},nr.prototype.evaluate=function(t){for(var e=0,r=this.branches;e<r.length;e+=1){var n=r[e],i=n[0],a=n[1];if(i.evaluate(t))return a.evaluate(t)}return this.otherwise.evaluate(t)},nr.prototype.eachChild=function(t){for(var e=0,r=this.branches;e<r.length;e+=1){var n=r[e],i=n[0],a=n[1];t(i),t(a);}t(this.otherwise);},nr.prototype.possibleOutputs=function(){var t;return (t=[]).concat.apply(t,this.branches.map(function(t){t[0];return t[1].possibleOutputs()})).concat(this.otherwise.possibleOutputs())},nr.prototype.serialize=function(){var t=[\"case\"];return this.eachChild(function(e){t.push(e.serialize());}),t};var sr=or(\"==\",function(t,e,r){return e===r},ar),ur=or(\"!=\",function(t,e,r){return e!==r},function(t,e,r,n){return !ar(0,e,r,n)}),lr=or(\"<\",function(t,e,r){return e<r},function(t,e,r,n){return n.compare(e,r)<0}),pr=or(\">\",function(t,e,r){return e>r},function(t,e,r,n){return n.compare(e,r)>0}),cr=or(\"<=\",function(t,e,r){return e<=r},function(t,e,r,n){return n.compare(e,r)<=0}),hr=or(\">=\",function(t,e,r){return e>=r},function(t,e,r,n){return n.compare(e,r)>=0}),fr=function(t,e,r,n,i){this.type=Xt,this.number=t,this.locale=e,this.currency=r,this.minFractionDigits=n,this.maxFractionDigits=i;};fr.parse=function(t,e){if(3!==t.length)return e.error(\"Expected two arguments.\");var r=e.parse(t[1],1,Gt);if(!r)return null;var n=t[2];if(\"object\"!=typeof n||Array.isArray(n))return e.error(\"NumberFormat options argument must be an object.\");var i=null;if(n.locale&&!(i=e.parse(n.locale,1,Xt)))return null;var a=null;if(n.currency&&!(a=e.parse(n.currency,1,Xt)))return null;var o=null;if(n[\"min-fraction-digits\"]&&!(o=e.parse(n[\"min-fraction-digits\"],1,Gt)))return null;var s=null;return n[\"max-fraction-digits\"]&&!(s=e.parse(n[\"max-fraction-digits\"],1,Gt))?null:new fr(r,i,a,o,s)},fr.prototype.evaluate=function(t){return new Intl.NumberFormat(this.locale?this.locale.evaluate(t):[],{style:this.currency?\"currency\":\"decimal\",currency:this.currency?this.currency.evaluate(t):void 0,minimumFractionDigits:this.minFractionDigits?this.minFractionDigits.evaluate(t):void 0,maximumFractionDigits:this.maxFractionDigits?this.maxFractionDigits.evaluate(t):void 0}).format(this.number.evaluate(t))},fr.prototype.eachChild=function(t){t(this.number),this.locale&&t(this.locale),this.currency&&t(this.currency),this.minFractionDigits&&t(this.minFractionDigits),this.maxFractionDigits&&t(this.maxFractionDigits);},fr.prototype.possibleOutputs=function(){return [void 0]},fr.prototype.serialize=function(){var t={};return this.locale&&(t.locale=this.locale.serialize()),this.currency&&(t.currency=this.currency.serialize()),this.minFractionDigits&&(t[\"min-fraction-digits\"]=this.minFractionDigits.serialize()),this.maxFractionDigits&&(t[\"max-fraction-digits\"]=this.maxFractionDigits.serialize()),[\"number-format\",this.number.serialize(),t]};var yr=function(t){this.type=Gt,this.input=t;};yr.parse=function(t,e){if(2!==t.length)return e.error(\"Expected 1 argument, but found \"+(t.length-1)+\" instead.\");var r=e.parse(t[1],1);return r?\"array\"!==r.type.kind&&\"string\"!==r.type.kind&&\"value\"!==r.type.kind?e.error(\"Expected argument of type string or array, but found \"+ee(r.type)+\" instead.\"):new yr(r):null},yr.prototype.evaluate=function(t){var e=this.input.evaluate(t);if(\"string\"==typeof e)return e.length;if(Array.isArray(e))return e.length;throw new fe(\"Expected value to be of type string or array, but found \"+ee(pe(e))+\" instead.\")},yr.prototype.eachChild=function(t){t(this.input);},yr.prototype.possibleOutputs=function(){return [void 0]},yr.prototype.serialize=function(){var t=[\"length\"];return this.eachChild(function(e){t.push(e.serialize());}),t};var dr={\"==\":sr,\"!=\":ur,\">\":pr,\"<\":lr,\">=\":hr,\"<=\":cr,array:de,at:er,boolean:de,case:nr,coalesce:Qe,collator:we,format:me,interpolate:$e,\"interpolate-hcl\":$e,\"interpolate-lab\":$e,length:yr,let:tr,literal:he,match:rr,number:de,\"number-format\":fr,object:de,step:Ce,string:de,\"to-boolean\":ge,\"to-color\":ge,\"to-number\":ge,\"to-string\":ge,var:ze};function mr(t,e){var r=e[0],n=e[1],i=e[2],a=e[3];r=r.evaluate(t),n=n.evaluate(t),i=i.evaluate(t);var o=a?a.evaluate(t):1,s=le(r,n,i,o);if(s)throw new fe(s);return new ae(r/255*o,n/255*o,i/255*o,o)}function vr(t,e){return t in e}function gr(t,e){var r=e[t];return void 0===r?null:r}function xr(t){return {type:t}}function br(t){return {result:\"success\",value:t}}function _r(t){return {result:\"error\",value:t}}function wr(t){return \"data-driven\"===t[\"property-type\"]||\"cross-faded-data-driven\"===t[\"property-type\"]}function Ar(t){return !!t.expression&&t.expression.parameters.indexOf(\"zoom\")>-1}function Sr(t){return !!t.expression&&t.expression.interpolated}function kr(t){return t instanceof Number?\"number\":t instanceof String?\"string\":t instanceof Boolean?\"boolean\":Array.isArray(t)?\"array\":null===t?\"null\":typeof t}function zr(t){return \"object\"==typeof t&&null!==t&&!Array.isArray(t)}function Ir(t){return t}function Br(t,e,r){return void 0!==t?t:void 0!==e?e:void 0!==r?r:void 0}function Cr(t,e,r,n,i){return Br(typeof r===i?n[r]:void 0,t.default,e.default)}function Er(t,e,r){if(\"number\"!==kr(r))return Br(t.default,e.default);var n=t.stops.length;if(1===n)return t.stops[0][1];if(r<=t.stops[0][0])return t.stops[0][1];if(r>=t.stops[n-1][0])return t.stops[n-1][1];var i=Be(t.stops.map(function(t){return t[0]}),r);return t.stops[i][1]}function Mr(t,e,r){var n=void 0!==t.base?t.base:1;if(\"number\"!==kr(r))return Br(t.default,e.default);var i=t.stops.length;if(1===i)return t.stops[0][1];if(r<=t.stops[0][0])return t.stops[0][1];if(r>=t.stops[i-1][0])return t.stops[i-1][1];var a=Be(t.stops.map(function(t){return t[0]}),r),o=function(t,e,r,n){var i=n-r,a=t-r;return 0===i?0:1===e?a/i:(Math.pow(e,a)-1)/(Math.pow(e,i)-1)}(r,n,t.stops[a][0],t.stops[a+1][0]),s=t.stops[a][1],u=t.stops[a+1][1],l=Me[e.type]||Ir;if(t.colorSpace&&\"rgb\"!==t.colorSpace){var p=Ye[t.colorSpace];l=function(t,e){return p.reverse(p.interpolate(p.forward(t),p.forward(e),o))};}return \"function\"==typeof s.evaluate?{evaluate:function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var r=s.evaluate.apply(void 0,t),n=u.evaluate.apply(void 0,t);if(void 0!==r&&void 0!==n)return l(r,n,o)}}:l(s,u,o)}function Tr(t,e,r){return \"color\"===e.type?r=ae.parse(r):\"formatted\"===e.type?r=ue.fromString(r.toString()):kr(r)===e.type||\"enum\"===e.type&&e.values[r]||(r=void 0),Br(r,t.default,e.default)}_e.register(dr,{error:[{kind:\"error\"},[Xt],function(t,e){var r=e[0];throw new fe(r.evaluate(t))}],typeof:[Xt,[$t],function(t,e){return ee(pe(e[0].evaluate(t)))}],\"to-rgba\":[te(Gt,4),[Ht],function(t,e){return e[0].evaluate(t).toArray()}],rgb:[Ht,[Gt,Gt,Gt],mr],rgba:[Ht,[Gt,Gt,Gt,Gt],mr],has:{type:Jt,overloads:[[[Xt],function(t,e){return vr(e[0].evaluate(t),t.properties())}],[[Xt,Yt],function(t,e){var r=e[0],n=e[1];return vr(r.evaluate(t),n.evaluate(t))}]]},get:{type:$t,overloads:[[[Xt],function(t,e){return gr(e[0].evaluate(t),t.properties())}],[[Xt,Yt],function(t,e){var r=e[0],n=e[1];return gr(r.evaluate(t),n.evaluate(t))}]]},\"feature-state\":[$t,[Xt],function(t,e){return gr(e[0].evaluate(t),t.featureState||{})}],properties:[Yt,[],function(t){return t.properties()}],\"geometry-type\":[Xt,[],function(t){return t.geometryType()}],id:[$t,[],function(t){return t.id()}],zoom:[Gt,[],function(t){return t.globals.zoom}],\"heatmap-density\":[Gt,[],function(t){return t.globals.heatmapDensity||0}],\"line-progress\":[Gt,[],function(t){return t.globals.lineProgress||0}],accumulated:[$t,[],function(t){return void 0===t.globals.accumulated?null:t.globals.accumulated}],\"+\":[Gt,xr(Gt),function(t,e){for(var r=0,n=0,i=e;n<i.length;n+=1){r+=i[n].evaluate(t);}return r}],\"*\":[Gt,xr(Gt),function(t,e){for(var r=1,n=0,i=e;n<i.length;n+=1){r*=i[n].evaluate(t);}return r}],\"-\":{type:Gt,overloads:[[[Gt,Gt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)-n.evaluate(t)}],[[Gt],function(t,e){return -e[0].evaluate(t)}]]},\"/\":[Gt,[Gt,Gt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)/n.evaluate(t)}],\"%\":[Gt,[Gt,Gt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)%n.evaluate(t)}],ln2:[Gt,[],function(){return Math.LN2}],pi:[Gt,[],function(){return Math.PI}],e:[Gt,[],function(){return Math.E}],\"^\":[Gt,[Gt,Gt],function(t,e){var r=e[0],n=e[1];return Math.pow(r.evaluate(t),n.evaluate(t))}],sqrt:[Gt,[Gt],function(t,e){var r=e[0];return Math.sqrt(r.evaluate(t))}],log10:[Gt,[Gt],function(t,e){var r=e[0];return Math.log(r.evaluate(t))/Math.LN10}],ln:[Gt,[Gt],function(t,e){var r=e[0];return Math.log(r.evaluate(t))}],log2:[Gt,[Gt],function(t,e){var r=e[0];return Math.log(r.evaluate(t))/Math.LN2}],sin:[Gt,[Gt],function(t,e){var r=e[0];return Math.sin(r.evaluate(t))}],cos:[Gt,[Gt],function(t,e){var r=e[0];return Math.cos(r.evaluate(t))}],tan:[Gt,[Gt],function(t,e){var r=e[0];return Math.tan(r.evaluate(t))}],asin:[Gt,[Gt],function(t,e){var r=e[0];return Math.asin(r.evaluate(t))}],acos:[Gt,[Gt],function(t,e){var r=e[0];return Math.acos(r.evaluate(t))}],atan:[Gt,[Gt],function(t,e){var r=e[0];return Math.atan(r.evaluate(t))}],min:[Gt,xr(Gt),function(t,e){return Math.min.apply(Math,e.map(function(e){return e.evaluate(t)}))}],max:[Gt,xr(Gt),function(t,e){return Math.max.apply(Math,e.map(function(e){return e.evaluate(t)}))}],abs:[Gt,[Gt],function(t,e){var r=e[0];return Math.abs(r.evaluate(t))}],round:[Gt,[Gt],function(t,e){var r=e[0].evaluate(t);return r<0?-Math.round(-r):Math.round(r)}],floor:[Gt,[Gt],function(t,e){var r=e[0];return Math.floor(r.evaluate(t))}],ceil:[Gt,[Gt],function(t,e){var r=e[0];return Math.ceil(r.evaluate(t))}],\"filter-==\":[Jt,[Xt,$t],function(t,e){var r=e[0],n=e[1];return t.properties()[r.value]===n.value}],\"filter-id-==\":[Jt,[$t],function(t,e){var r=e[0];return t.id()===r.value}],\"filter-type-==\":[Jt,[Xt],function(t,e){var r=e[0];return t.geometryType()===r.value}],\"filter-<\":[Jt,[Xt,$t],function(t,e){var r=e[0],n=e[1],i=t.properties()[r.value],a=n.value;return typeof i==typeof a&&i<a}],\"filter-id-<\":[Jt,[$t],function(t,e){var r=e[0],n=t.id(),i=r.value;return typeof n==typeof i&&n<i}],\"filter->\":[Jt,[Xt,$t],function(t,e){var r=e[0],n=e[1],i=t.properties()[r.value],a=n.value;return typeof i==typeof a&&i>a}],\"filter-id->\":[Jt,[$t],function(t,e){var r=e[0],n=t.id(),i=r.value;return typeof n==typeof i&&n>i}],\"filter-<=\":[Jt,[Xt,$t],function(t,e){var r=e[0],n=e[1],i=t.properties()[r.value],a=n.value;return typeof i==typeof a&&i<=a}],\"filter-id-<=\":[Jt,[$t],function(t,e){var r=e[0],n=t.id(),i=r.value;return typeof n==typeof i&&n<=i}],\"filter->=\":[Jt,[Xt,$t],function(t,e){var r=e[0],n=e[1],i=t.properties()[r.value],a=n.value;return typeof i==typeof a&&i>=a}],\"filter-id->=\":[Jt,[$t],function(t,e){var r=e[0],n=t.id(),i=r.value;return typeof n==typeof i&&n>=i}],\"filter-has\":[Jt,[$t],function(t,e){return e[0].value in t.properties()}],\"filter-has-id\":[Jt,[],function(t){return null!==t.id()}],\"filter-type-in\":[Jt,[te(Xt)],function(t,e){return e[0].value.indexOf(t.geometryType())>=0}],\"filter-id-in\":[Jt,[te($t)],function(t,e){return e[0].value.indexOf(t.id())>=0}],\"filter-in-small\":[Jt,[Xt,te($t)],function(t,e){var r=e[0];return e[1].value.indexOf(t.properties()[r.value])>=0}],\"filter-in-large\":[Jt,[Xt,te($t)],function(t,e){var r=e[0],n=e[1];return function(t,e,r,n){for(;r<=n;){var i=r+n>>1;if(e[i]===t)return !0;e[i]>t?n=i-1:r=i+1;}return !1}(t.properties()[r.value],n.value,0,n.value.length-1)}],all:{type:Jt,overloads:[[[Jt,Jt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)&&n.evaluate(t)}],[xr(Jt),function(t,e){for(var r=0,n=e;r<n.length;r+=1){if(!n[r].evaluate(t))return !1}return !0}]]},any:{type:Jt,overloads:[[[Jt,Jt],function(t,e){var r=e[0],n=e[1];return r.evaluate(t)||n.evaluate(t)}],[xr(Jt),function(t,e){for(var r=0,n=e;r<n.length;r+=1){if(n[r].evaluate(t))return !0}return !1}]]},\"!\":[Jt,[Jt],function(t,e){return !e[0].evaluate(t)}],\"is-supported-script\":[Jt,[Xt],function(t,e){var r=e[0],n=t.globals&&t.globals.isSupportedScript;return !n||n(r.evaluate(t))}],upcase:[Xt,[Xt],function(t,e){return e[0].evaluate(t).toUpperCase()}],downcase:[Xt,[Xt],function(t,e){return e[0].evaluate(t).toLowerCase()}],concat:[Xt,xr($t),function(t,e){return e.map(function(e){return ce(e.evaluate(t))}).join(\"\")}],\"resolved-locale\":[Xt,[Wt],function(t,e){return e[0].evaluate(t).resolvedLocale()}]});var Pr=function(t,e){var r;this.expression=t,this._warningHistory={},this._evaluator=new be,this._defaultValue=e?\"color\"===(r=e).type&&zr(r.default)?new ae(0,0,0,0):\"color\"===r.type?ae.parse(r.default)||null:void 0===r.default?null:r.default:null,this._enumValues=e&&\"enum\"===e.type?e.values:null;};function Vr(t){return Array.isArray(t)&&t.length>0&&\"string\"==typeof t[0]&&t[0]in dr}function Fr(t,e){var r=new Ie(dr,[],e?function(t){var e={color:Ht,string:Xt,number:Gt,enum:Xt,boolean:Jt,formatted:Qt};if(\"array\"===t.type)return te(e[t.value]||$t,t.length);return e[t.type]}(e):void 0),n=r.parse(t,void 0,void 0,void 0,e&&\"string\"===e.type?{typeAnnotation:\"coerce\"}:void 0);return n?br(new Pr(n,e)):_r(r.errors)}Pr.prototype.evaluateWithoutErrorHandling=function(t,e,r){return this._evaluator.globals=t,this._evaluator.feature=e,this._evaluator.featureState=r,this.expression.evaluate(this._evaluator)},Pr.prototype.evaluate=function(t,e,r){this._evaluator.globals=t,this._evaluator.feature=e||null,this._evaluator.featureState=r||null;try{var n=this.expression.evaluate(this._evaluator);if(null==n)return this._defaultValue;if(this._enumValues&&!(n in this._enumValues))throw new fe(\"Expected value to be one of \"+Object.keys(this._enumValues).map(function(t){return JSON.stringify(t)}).join(\", \")+\", but found \"+JSON.stringify(n)+\" instead.\");return n}catch(t){return this._warningHistory[t.message]||(this._warningHistory[t.message]=!0,\"undefined\"!=typeof console&&console.warn(t.message)),this._defaultValue}};var Lr=function(t,e){this.kind=t,this._styleExpression=e,this.isStateDependent=\"constant\"!==t&&!Se(e.expression);};Lr.prototype.evaluateWithoutErrorHandling=function(t,e,r){return this._styleExpression.evaluateWithoutErrorHandling(t,e,r)},Lr.prototype.evaluate=function(t,e,r){return this._styleExpression.evaluate(t,e,r)};var Dr=function(t,e,r){this.kind=t,this.zoomStops=r.labels,this._styleExpression=e,this.isStateDependent=\"camera\"!==t&&!Se(e.expression),r instanceof $e&&(this.interpolationType=r.interpolation);};function Or(t,e){if(\"error\"===(t=Fr(t,e)).result)return t;var r=t.value.expression,n=Ae(r);if(!n&&!wr(e))return _r([new Nt(\"\",\"data expressions not supported\")]);var i=ke(r,[\"zoom\"]);if(!i&&!Ar(e))return _r([new Nt(\"\",\"zoom expressions not supported\")]);var a=function t(e){var r=null;if(e instanceof tr)r=t(e.result);else if(e instanceof Qe)for(var n=0,i=e.args;n<i.length;n+=1){var a=i[n];if(r=t(a))break}else(e instanceof Ce||e instanceof $e)&&e.input instanceof _e&&\"zoom\"===e.input.name&&(r=e);if(r instanceof Nt)return r;e.eachChild(function(e){var n=t(e);n instanceof Nt?r=n:!r&&n?r=new Nt(\"\",'\"zoom\" expression may only be used as input to a top-level \"step\" or \"interpolate\" expression.'):r&&n&&r!==n&&(r=new Nt(\"\",'Only one zoom-based \"step\" or \"interpolate\" subexpression may be used in an expression.'));});return r}(r);return a||i?a instanceof Nt?_r([a]):a instanceof $e&&!Sr(e)?_r([new Nt(\"\",'\"interpolate\" expressions cannot be used with this property')]):br(a?new Dr(n?\"camera\":\"composite\",t.value,a):new Lr(n?\"constant\":\"source\",t.value)):_r([new Nt(\"\",'\"zoom\" expression may only be used as input to a top-level \"step\" or \"interpolate\" expression.')])}Dr.prototype.evaluateWithoutErrorHandling=function(t,e,r){return this._styleExpression.evaluateWithoutErrorHandling(t,e,r)},Dr.prototype.evaluate=function(t,e,r){return this._styleExpression.evaluate(t,e,r)},Dr.prototype.interpolationFactor=function(t,e,r){return this.interpolationType?$e.interpolationFactor(this.interpolationType,t,e,r):0};var Rr=function(t,e){this._parameters=t,this._specification=e,Rt(this,function t(e,r){var n,i,a,o=\"color\"===r.type,s=e.stops&&\"object\"==typeof e.stops[0][0],u=s||void 0!==e.property,l=s||!u,p=e.type||(Sr(r)?\"exponential\":\"interval\");if(o&&((e=Rt({},e)).stops&&(e.stops=e.stops.map(function(t){return [t[0],ae.parse(t[1])]})),e.default?e.default=ae.parse(e.default):e.default=ae.parse(r.default)),e.colorSpace&&\"rgb\"!==e.colorSpace&&!Ye[e.colorSpace])throw new Error(\"Unknown color space: \"+e.colorSpace);if(\"exponential\"===p)n=Mr;else if(\"interval\"===p)n=Er;else if(\"categorical\"===p){n=Cr,i=Object.create(null);for(var c=0,h=e.stops;c<h.length;c+=1){var f=h[c];i[f[0]]=f[1];}a=typeof e.stops[0][0];}else{if(\"identity\"!==p)throw new Error('Unknown function type \"'+p+'\"');n=Tr;}if(s){for(var y={},d=[],m=0;m<e.stops.length;m++){var v=e.stops[m],g=v[0].zoom;void 0===y[g]&&(y[g]={zoom:g,type:e.type,property:e.property,default:e.default,stops:[]},d.push(g)),y[g].stops.push([v[0].value,v[1]]);}for(var x=[],b=0,_=d;b<_.length;b+=1){var w=_[b];x.push([y[w].zoom,t(y[w],r)]);}var A={name:\"linear\"};return {kind:\"composite\",interpolationType:A,interpolationFactor:$e.interpolationFactor.bind(void 0,A),zoomStops:x.map(function(t){return t[0]}),evaluate:function(t,n){var i=t.zoom;return Mr({stops:x,base:e.base},r,i).evaluate(i,n)}}}if(l){var S=\"exponential\"===p?{name:\"exponential\",base:void 0!==e.base?e.base:1}:null;return {kind:\"camera\",interpolationType:S,interpolationFactor:$e.interpolationFactor.bind(void 0,S),zoomStops:e.stops.map(function(t){return t[0]}),evaluate:function(t){var o=t.zoom;return n(e,r,o,i,a)}}}return {kind:\"source\",evaluate:function(t,o){var s=o&&o.properties?o.properties[e.property]:void 0;return void 0===s?Br(e.default,r.default):n(e,r,s,i,a)}}}(this._parameters,this._specification));};function Ur(t){var e=t.key,r=t.value,n=t.valueSpec||{},i=t.objectElementValidators||{},a=t.style,o=t.styleSpec,s=[],u=kr(r);if(\"object\"!==u)return [new Dt(e,r,\"object expected, \"+u+\" found\")];for(var l in r){var p=l.split(\".\")[0],c=n[p]||n[\"*\"],h=void 0;if(i[p])h=i[p];else if(n[p])h=cn;else if(i[\"*\"])h=i[\"*\"];else{if(!n[\"*\"]){s.push(new Dt(e,r[l],'unknown property \"'+l+'\"'));continue}h=cn;}s=s.concat(h({key:(e?e+\".\":e)+l,value:r[l],valueSpec:c,style:a,styleSpec:o,object:r,objectKey:l},r));}for(var f in n)i[f]||n[f].required&&void 0===n[f].default&&void 0===r[f]&&s.push(new Dt(e,r,'missing required property \"'+f+'\"'));return s}function jr(t){var e=t.value,r=t.valueSpec,n=t.style,i=t.styleSpec,a=t.key,o=t.arrayElementValidator||cn;if(\"array\"!==kr(e))return [new Dt(a,e,\"array expected, \"+kr(e)+\" found\")];if(r.length&&e.length!==r.length)return [new Dt(a,e,\"array length \"+r.length+\" expected, length \"+e.length+\" found\")];if(r[\"min-length\"]&&e.length<r[\"min-length\"])return [new Dt(a,e,\"array length at least \"+r[\"min-length\"]+\" expected, length \"+e.length+\" found\")];var s={type:r.value,values:r.values};i.$version<7&&(s.function=r.function),\"object\"===kr(r.value)&&(s=r.value);for(var u=[],l=0;l<e.length;l++)u=u.concat(o({array:e,arrayIndex:l,value:e[l],valueSpec:s,style:n,styleSpec:i,key:a+\"[\"+l+\"]\"}));return u}function qr(t){var e=t.key,r=t.value,n=t.valueSpec,i=kr(r);return \"number\"!==i?[new Dt(e,r,\"number expected, \"+i+\" found\")]:\"minimum\"in n&&r<n.minimum?[new Dt(e,r,r+\" is less than the minimum value \"+n.minimum)]:\"maximum\"in n&&r>n.maximum?[new Dt(e,r,r+\" is greater than the maximum value \"+n.maximum)]:[]}function Nr(t){var e,r,n,i=t.valueSpec,a=jt(t.value.type),o={},s=\"categorical\"!==a&&void 0===t.value.property,u=!s,l=\"array\"===kr(t.value.stops)&&\"array\"===kr(t.value.stops[0])&&\"object\"===kr(t.value.stops[0][0]),p=Ur({key:t.key,value:t.value,valueSpec:t.styleSpec.function,style:t.style,styleSpec:t.styleSpec,objectElementValidators:{stops:function(t){if(\"identity\"===a)return [new Dt(t.key,t.value,'identity function may not have a \"stops\" property')];var e=[],r=t.value;e=e.concat(jr({key:t.key,value:r,valueSpec:t.valueSpec,style:t.style,styleSpec:t.styleSpec,arrayElementValidator:c})),\"array\"===kr(r)&&0===r.length&&e.push(new Dt(t.key,r,\"array must have at least one stop\"));return e},default:function(t){return cn({key:t.key,value:t.value,valueSpec:i,style:t.style,styleSpec:t.styleSpec})}}});return \"identity\"===a&&s&&p.push(new Dt(t.key,t.value,'missing required property \"property\"')),\"identity\"===a||t.value.stops||p.push(new Dt(t.key,t.value,'missing required property \"stops\"')),\"exponential\"===a&&t.valueSpec.expression&&!Sr(t.valueSpec)&&p.push(new Dt(t.key,t.value,\"exponential functions not supported\")),t.styleSpec.$version>=8&&(u&&!wr(t.valueSpec)?p.push(new Dt(t.key,t.value,\"property functions not supported\")):s&&!Ar(t.valueSpec)&&p.push(new Dt(t.key,t.value,\"zoom functions not supported\"))),\"categorical\"!==a&&!l||void 0!==t.value.property||p.push(new Dt(t.key,t.value,'\"property\" property is required')),p;function c(t){var e=[],a=t.value,s=t.key;if(\"array\"!==kr(a))return [new Dt(s,a,\"array expected, \"+kr(a)+\" found\")];if(2!==a.length)return [new Dt(s,a,\"array length 2 expected, length \"+a.length+\" found\")];if(l){if(\"object\"!==kr(a[0]))return [new Dt(s,a,\"object expected, \"+kr(a[0])+\" found\")];if(void 0===a[0].zoom)return [new Dt(s,a,\"object stop key must have zoom\")];if(void 0===a[0].value)return [new Dt(s,a,\"object stop key must have value\")];if(n&&n>jt(a[0].zoom))return [new Dt(s,a[0].zoom,\"stop zoom values must appear in ascending order\")];jt(a[0].zoom)!==n&&(n=jt(a[0].zoom),r=void 0,o={}),e=e.concat(Ur({key:s+\"[0]\",value:a[0],valueSpec:{zoom:{}},style:t.style,styleSpec:t.styleSpec,objectElementValidators:{zoom:qr,value:h}}));}else e=e.concat(h({key:s+\"[0]\",value:a[0],valueSpec:{},style:t.style,styleSpec:t.styleSpec},a));return Vr(qt(a[1]))?e.concat([new Dt(s+\"[1]\",a[1],\"expressions are not allowed in function stops.\")]):e.concat(cn({key:s+\"[1]\",value:a[1],valueSpec:i,style:t.style,styleSpec:t.styleSpec}))}function h(t,n){var s=kr(t.value),u=jt(t.value),l=null!==t.value?t.value:n;if(e){if(s!==e)return [new Dt(t.key,l,s+\" stop domain type must match previous stop domain type \"+e)]}else e=s;if(\"number\"!==s&&\"string\"!==s&&\"boolean\"!==s)return [new Dt(t.key,l,\"stop domain value must be a number, string, or boolean\")];if(\"number\"!==s&&\"categorical\"!==a){var p=\"number expected, \"+s+\" found\";return wr(i)&&void 0===a&&(p+='\\nIf you intended to use a categorical function, specify `\"type\": \"categorical\"`.'),[new Dt(t.key,l,p)]}return \"categorical\"!==a||\"number\"!==s||isFinite(u)&&Math.floor(u)===u?\"categorical\"!==a&&\"number\"===s&&void 0!==r&&u<r?[new Dt(t.key,l,\"stop domain values must appear in ascending order\")]:(r=u,\"categorical\"===a&&u in o?[new Dt(t.key,l,\"stop domain values must be unique\")]:(o[u]=!0,[])):[new Dt(t.key,l,\"integer expected, found \"+u)]}}function Zr(t){var e=(\"property\"===t.expressionContext?Or:Fr)(qt(t.value),t.valueSpec);if(\"error\"===e.result)return e.value.map(function(e){return new Dt(\"\"+t.key+e.key,t.value,e.message)});var r=e.value.expression||e.value._styleExpression.expression;if(\"property\"===t.expressionContext&&\"text-font\"===t.propertyKey&&-1!==r.possibleOutputs().indexOf(void 0))return [new Dt(t.key,t.value,'Invalid data expression for \"'+t.propertyKey+'\". Output values must be contained as literals within the expression.')];if(\"property\"===t.expressionContext&&\"layout\"===t.propertyType&&!Se(r))return [new Dt(t.key,t.value,'\"feature-state\" data expressions are not supported with layout properties.')];if(\"filter\"===t.expressionContext&&!Se(r))return [new Dt(t.key,t.value,'\"feature-state\" data expressions are not supported with filters.')];if(t.expressionContext&&0===t.expressionContext.indexOf(\"cluster\")){if(!ke(r,[\"zoom\",\"feature-state\"]))return [new Dt(t.key,t.value,'\"zoom\" and \"feature-state\" expressions are not supported with cluster properties.')];if(\"cluster-initial\"===t.expressionContext&&!Ae(r))return [new Dt(t.key,t.value,\"Feature data expressions are not supported with initial expression part of cluster properties.\")]}return []}function Kr(t){var e=t.key,r=t.value,n=t.valueSpec,i=[];return Array.isArray(n.values)?-1===n.values.indexOf(jt(r))&&i.push(new Dt(e,r,\"expected one of [\"+n.values.join(\", \")+\"], \"+JSON.stringify(r)+\" found\")):-1===Object.keys(n.values).indexOf(jt(r))&&i.push(new Dt(e,r,\"expected one of [\"+Object.keys(n.values).join(\", \")+\"], \"+JSON.stringify(r)+\" found\")),i}function Gr(t){if(!0===t||!1===t)return !0;if(!Array.isArray(t)||0===t.length)return !1;switch(t[0]){case\"has\":return t.length>=2&&\"$id\"!==t[1]&&\"$type\"!==t[1];case\"in\":case\"!in\":case\"!has\":case\"none\":return !1;case\"==\":case\"!=\":case\">\":case\">=\":case\"<\":case\"<=\":return 3!==t.length||Array.isArray(t[1])||Array.isArray(t[2]);case\"any\":case\"all\":for(var e=0,r=t.slice(1);e<r.length;e+=1){var n=r[e];if(!Gr(n)&&\"boolean\"!=typeof n)return !1}return !0;default:return !0}}Rr.deserialize=function(t){return new Rr(t._parameters,t._specification)},Rr.serialize=function(t){return {_parameters:t._parameters,_specification:t._specification}};var Xr={type:\"boolean\",default:!1,transition:!1,\"property-type\":\"data-driven\",expression:{interpolated:!1,parameters:[\"zoom\",\"feature\"]}};function Jr(t){if(null==t)return function(){return !0};Gr(t)||(t=Yr(t));var e=Fr(t,Xr);if(\"error\"===e.result)throw new Error(e.value.map(function(t){return t.key+\": \"+t.message}).join(\", \"));return function(t,r){return e.value.evaluate(t,r)}}function Hr(t,e){return t<e?-1:t>e?1:0}function Yr(t){if(!t)return !0;var e,r=t[0];return t.length<=1?\"any\"!==r:\"==\"===r?$r(t[1],t[2],\"==\"):\"!=\"===r?tn($r(t[1],t[2],\"==\")):\"<\"===r||\">\"===r||\"<=\"===r||\">=\"===r?$r(t[1],t[2],r):\"any\"===r?(e=t.slice(1),[\"any\"].concat(e.map(Yr))):\"all\"===r?[\"all\"].concat(t.slice(1).map(Yr)):\"none\"===r?[\"all\"].concat(t.slice(1).map(Yr).map(tn)):\"in\"===r?Wr(t[1],t.slice(2)):\"!in\"===r?tn(Wr(t[1],t.slice(2))):\"has\"===r?Qr(t[1]):\"!has\"!==r||tn(Qr(t[1]))}function $r(t,e,r){switch(t){case\"$type\":return [\"filter-type-\"+r,e];case\"$id\":return [\"filter-id-\"+r,e];default:return [\"filter-\"+r,t,e]}}function Wr(t,e){if(0===e.length)return !1;switch(t){case\"$type\":return [\"filter-type-in\",[\"literal\",e]];case\"$id\":return [\"filter-id-in\",[\"literal\",e]];default:return e.length>200&&!e.some(function(t){return typeof t!=typeof e[0]})?[\"filter-in-large\",t,[\"literal\",e.sort(Hr)]]:[\"filter-in-small\",t,[\"literal\",e]]}}function Qr(t){switch(t){case\"$type\":return !0;case\"$id\":return [\"filter-has-id\"];default:return [\"filter-has\",t]}}function tn(t){return [\"!\",t]}function en(t){return Gr(qt(t.value))?Zr(Rt({},t,{expressionContext:\"filter\",valueSpec:{value:\"boolean\"}})):function t(e){var r=e.value;var n=e.key;if(\"array\"!==kr(r))return [new Dt(n,r,\"array expected, \"+kr(r)+\" found\")];var i=e.styleSpec;var a;var o=[];if(r.length<1)return [new Dt(n,r,\"filter array must have at least 1 element\")];o=o.concat(Kr({key:n+\"[0]\",value:r[0],valueSpec:i.filter_operator,style:e.style,styleSpec:e.styleSpec}));switch(jt(r[0])){case\"<\":case\"<=\":case\">\":case\">=\":r.length>=2&&\"$type\"===jt(r[1])&&o.push(new Dt(n,r,'\"$type\" cannot be use with operator \"'+r[0]+'\"'));case\"==\":case\"!=\":3!==r.length&&o.push(new Dt(n,r,'filter array for operator \"'+r[0]+'\" must have 3 elements'));case\"in\":case\"!in\":r.length>=2&&\"string\"!==(a=kr(r[1]))&&o.push(new Dt(n+\"[1]\",r[1],\"string expected, \"+a+\" found\"));for(var s=2;s<r.length;s++)a=kr(r[s]),\"$type\"===jt(r[1])?o=o.concat(Kr({key:n+\"[\"+s+\"]\",value:r[s],valueSpec:i.geometry_type,style:e.style,styleSpec:e.styleSpec})):\"string\"!==a&&\"number\"!==a&&\"boolean\"!==a&&o.push(new Dt(n+\"[\"+s+\"]\",r[s],\"string, number, or boolean expected, \"+a+\" found\"));break;case\"any\":case\"all\":case\"none\":for(var u=1;u<r.length;u++)o=o.concat(t({key:n+\"[\"+u+\"]\",value:r[u],style:e.style,styleSpec:e.styleSpec}));break;case\"has\":case\"!has\":a=kr(r[1]),2!==r.length?o.push(new Dt(n,r,'filter array for \"'+r[0]+'\" operator must have 2 elements')):\"string\"!==a&&o.push(new Dt(n+\"[1]\",r[1],\"string expected, \"+a+\" found\"));}return o}(t)}function rn(t,e){var r=t.key,n=t.style,i=t.styleSpec,a=t.value,o=t.objectKey,s=i[e+\"_\"+t.layerType];if(!s)return [];var u=o.match(/^(.*)-transition$/);if(\"paint\"===e&&u&&s[u[1]]&&s[u[1]].transition)return cn({key:r,value:a,valueSpec:i.transition,style:n,styleSpec:i});var l,p=t.valueSpec||s[o];if(!p)return [new Dt(r,a,'unknown property \"'+o+'\"')];if(\"string\"===kr(a)&&wr(p)&&!p.tokens&&(l=/^{([^}]+)}$/.exec(a)))return [new Dt(r,a,'\"'+o+'\" does not support interpolation syntax\\nUse an identity property function instead: `{ \"type\": \"identity\", \"property\": '+JSON.stringify(l[1])+\" }`.\")];var c=[];return \"symbol\"===t.layerType&&(\"text-field\"===o&&n&&!n.glyphs&&c.push(new Dt(r,a,'use of \"text-field\" requires a style \"glyphs\" property')),\"text-font\"===o&&zr(qt(a))&&\"identity\"===jt(a.type)&&c.push(new Dt(r,a,'\"text-font\" does not support identity functions'))),c.concat(cn({key:t.key,value:a,valueSpec:p,style:n,styleSpec:i,expressionContext:\"property\",propertyType:e,propertyKey:o}))}function nn(t){return rn(t,\"paint\")}function an(t){return rn(t,\"layout\")}function on(t){var e=[],r=t.value,n=t.key,i=t.style,a=t.styleSpec;r.type||r.ref||e.push(new Dt(n,r,'either \"type\" or \"ref\" is required'));var o,s=jt(r.type),u=jt(r.ref);if(r.id)for(var l=jt(r.id),p=0;p<t.arrayIndex;p++){var c=i.layers[p];jt(c.id)===l&&e.push(new Dt(n,r.id,'duplicate layer id \"'+r.id+'\", previously used at line '+c.id.__line__));}if(\"ref\"in r)[\"type\",\"source\",\"source-layer\",\"filter\",\"layout\"].forEach(function(t){t in r&&e.push(new Dt(n,r[t],'\"'+t+'\" is prohibited for ref layers'));}),i.layers.forEach(function(t){jt(t.id)===u&&(o=t);}),o?o.ref?e.push(new Dt(n,r.ref,\"ref cannot reference another ref layer\")):s=jt(o.type):e.push(new Dt(n,r.ref,'ref layer \"'+u+'\" not found'));else if(\"background\"!==s)if(r.source){var h=i.sources&&i.sources[r.source],f=h&&jt(h.type);h?\"vector\"===f&&\"raster\"===s?e.push(new Dt(n,r.source,'layer \"'+r.id+'\" requires a raster source')):\"raster\"===f&&\"raster\"!==s?e.push(new Dt(n,r.source,'layer \"'+r.id+'\" requires a vector source')):\"vector\"!==f||r[\"source-layer\"]?\"raster-dem\"===f&&\"hillshade\"!==s?e.push(new Dt(n,r.source,\"raster-dem source can only be used with layer type 'hillshade'.\")):\"line\"!==s||!r.paint||!r.paint[\"line-gradient\"]||\"geojson\"===f&&h.lineMetrics||e.push(new Dt(n,r,'layer \"'+r.id+'\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.')):e.push(new Dt(n,r,'layer \"'+r.id+'\" must specify a \"source-layer\"')):e.push(new Dt(n,r.source,'source \"'+r.source+'\" not found'));}else e.push(new Dt(n,r,'missing required property \"source\"'));return e=e.concat(Ur({key:n,value:r,valueSpec:a.layer,style:t.style,styleSpec:t.styleSpec,objectElementValidators:{\"*\":function(){return []},type:function(){return cn({key:n+\".type\",value:r.type,valueSpec:a.layer.type,style:t.style,styleSpec:t.styleSpec,object:r,objectKey:\"type\"})},filter:en,layout:function(t){return Ur({layer:r,key:t.key,value:t.value,style:t.style,styleSpec:t.styleSpec,objectElementValidators:{\"*\":function(t){return an(Rt({layerType:s},t))}}})},paint:function(t){return Ur({layer:r,key:t.key,value:t.value,style:t.style,styleSpec:t.styleSpec,objectElementValidators:{\"*\":function(t){return nn(Rt({layerType:s},t))}}})}}}))}function sn(t){var e=t.value,r=t.key,n=t.styleSpec,i=t.style;if(!e.type)return [new Dt(r,e,'\"type\" is required')];var a,o=jt(e.type);switch(o){case\"vector\":case\"raster\":case\"raster-dem\":if(a=Ur({key:r,value:e,valueSpec:n[\"source_\"+o.replace(\"-\",\"_\")],style:t.style,styleSpec:n}),\"url\"in e)for(var s in e)[\"type\",\"url\",\"tileSize\"].indexOf(s)<0&&a.push(new Dt(r+\".\"+s,e[s],'a source with a \"url\" property may not include a \"'+s+'\" property'));return a;case\"geojson\":if(a=Ur({key:r,value:e,valueSpec:n.source_geojson,style:i,styleSpec:n}),e.cluster)for(var u in e.clusterProperties){var l=e.clusterProperties[u],p=l[0],c=l[1],h=\"string\"==typeof p?[p,[\"accumulated\"],[\"get\",u]]:p;a.push.apply(a,Zr({key:r+\".\"+u+\".map\",value:c,expressionContext:\"cluster-map\"})),a.push.apply(a,Zr({key:r+\".\"+u+\".reduce\",value:h,expressionContext:\"cluster-reduce\"}));}return a;case\"video\":return Ur({key:r,value:e,valueSpec:n.source_video,style:i,styleSpec:n});case\"image\":return Ur({key:r,value:e,valueSpec:n.source_image,style:i,styleSpec:n});case\"canvas\":return [new Dt(r,null,\"Please use runtime APIs to add canvas sources, rather than including them in stylesheets.\",\"source.canvas\")];default:return Kr({key:r+\".type\",value:e.type,valueSpec:{values:[\"vector\",\"raster\",\"raster-dem\",\"geojson\",\"video\",\"image\"]},style:i,styleSpec:n})}}function un(t){var e=t.value,r=t.styleSpec,n=r.light,i=t.style,a=[],o=kr(e);if(void 0===e)return a;if(\"object\"!==o)return a=a.concat([new Dt(\"light\",e,\"object expected, \"+o+\" found\")]);for(var s in e){var u=s.match(/^(.*)-transition$/);a=u&&n[u[1]]&&n[u[1]].transition?a.concat(cn({key:s,value:e[s],valueSpec:r.transition,style:i,styleSpec:r})):n[s]?a.concat(cn({key:s,value:e[s],valueSpec:n[s],style:i,styleSpec:r})):a.concat([new Dt(s,e[s],'unknown property \"'+s+'\"')]);}return a}function ln(t){var e=t.value,r=t.key,n=kr(e);return \"string\"!==n?[new Dt(r,e,\"string expected, \"+n+\" found\")]:[]}var pn={\"*\":function(){return []},array:jr,boolean:function(t){var e=t.value,r=t.key,n=kr(e);return \"boolean\"!==n?[new Dt(r,e,\"boolean expected, \"+n+\" found\")]:[]},number:qr,color:function(t){var e=t.key,r=t.value,n=kr(r);return \"string\"!==n?[new Dt(e,r,\"color expected, \"+n+\" found\")]:null===ie(r)?[new Dt(e,r,'color expected, \"'+r+'\" found')]:[]},constants:Ot,enum:Kr,filter:en,function:Nr,layer:on,object:Ur,source:sn,light:un,string:ln,formatted:function(t){return 0===ln(t).length?[]:Zr(t)}};function cn(t){var e=t.value,r=t.valueSpec,n=t.styleSpec;return r.expression&&zr(jt(e))?Nr(t):r.expression&&Vr(qt(e))?Zr(t):r.type&&pn[r.type]?pn[r.type](t):Ur(Rt({},t,{valueSpec:r.type?n[r.type]:r}))}function hn(t){var e=t.value,r=t.key,n=ln(t);return n.length?n:(-1===e.indexOf(\"{fontstack}\")&&n.push(new Dt(r,e,'\"glyphs\" url must include a \"{fontstack}\" token')),-1===e.indexOf(\"{range}\")&&n.push(new Dt(r,e,'\"glyphs\" url must include a \"{range}\" token')),n)}function fn(t,e){e=e||Lt;var r=[];return r=r.concat(cn({key:\"\",value:t,valueSpec:e.$root,styleSpec:e,style:t,objectElementValidators:{glyphs:hn,\"*\":function(){return []}}})),t.constants&&(r=r.concat(Ot({key:\"constants\",value:t.constants,style:t,styleSpec:e}))),yn(r)}function yn(t){return [].concat(t).sort(function(t,e){return t.line-e.line})}function dn(t){return function(){for(var e=[],r=arguments.length;r--;)e[r]=arguments[r];return yn(t.apply(this,e))}}fn.source=dn(sn),fn.light=dn(un),fn.layer=dn(on),fn.filter=dn(en),fn.paintProperty=dn(nn),fn.layoutProperty=dn(an);var mn=fn,vn=mn.light,gn=mn.paintProperty,xn=mn.layoutProperty;function bn(t,e){var r=!1;if(e&&e.length)for(var n=0,i=e;n<i.length;n+=1){var a=i[n];t.fire(new Vt(new Error(a.message))),r=!0;}return r}var _n=An,wn=3;function An(t,e,r){var n=this.cells=[];if(t instanceof ArrayBuffer){this.arrayBuffer=t;var i=new Int32Array(this.arrayBuffer);t=i[0],e=i[1],r=i[2],this.d=e+2*r;for(var a=0;a<this.d*this.d;a++){var o=i[wn+a],s=i[wn+a+1];n.push(o===s?null:i.subarray(o,s));}var u=i[wn+n.length],l=i[wn+n.length+1];this.keys=i.subarray(u,l),this.bboxes=i.subarray(l),this.insert=this._insertReadonly;}else{this.d=e+2*r;for(var p=0;p<this.d*this.d;p++)n.push([]);this.keys=[],this.bboxes=[];}this.n=e,this.extent=t,this.padding=r,this.scale=e/t,this.uid=0;var c=r/e*t;this.min=-c,this.max=t+c;}An.prototype.insert=function(t,e,r,n,i){this._forEachCell(e,r,n,i,this._insertCell,this.uid++),this.keys.push(t),this.bboxes.push(e),this.bboxes.push(r),this.bboxes.push(n),this.bboxes.push(i);},An.prototype._insertReadonly=function(){throw\"Cannot insert into a GridIndex created from an ArrayBuffer.\"},An.prototype._insertCell=function(t,e,r,n,i,a){this.cells[i].push(a);},An.prototype.query=function(t,e,r,n,i){var a=this.min,o=this.max;if(t<=a&&e<=a&&o<=r&&o<=n&&!i)return Array.prototype.slice.call(this.keys);var s=[];return this._forEachCell(t,e,r,n,this._queryCell,s,{},i),s},An.prototype._queryCell=function(t,e,r,n,i,a,o,s){var u=this.cells[i];if(null!==u)for(var l=this.keys,p=this.bboxes,c=0;c<u.length;c++){var h=u[c];if(void 0===o[h]){var f=4*h;(s?s(p[f+0],p[f+1],p[f+2],p[f+3]):t<=p[f+2]&&e<=p[f+3]&&r>=p[f+0]&&n>=p[f+1])?(o[h]=!0,a.push(l[h])):o[h]=!1;}}},An.prototype._forEachCell=function(t,e,r,n,i,a,o,s){for(var u=this._convertToCellCoord(t),l=this._convertToCellCoord(e),p=this._convertToCellCoord(r),c=this._convertToCellCoord(n),h=u;h<=p;h++)for(var f=l;f<=c;f++){var y=this.d*f+h;if((!s||s(this._convertFromCellCoord(h),this._convertFromCellCoord(f),this._convertFromCellCoord(h+1),this._convertFromCellCoord(f+1)))&&i.call(this,t,e,r,n,y,a,o,s))return}},An.prototype._convertFromCellCoord=function(t){return (t-this.padding)/this.scale},An.prototype._convertToCellCoord=function(t){return Math.max(0,Math.min(this.d-1,Math.floor(t*this.scale)+this.padding))},An.prototype.toArrayBuffer=function(){if(this.arrayBuffer)return this.arrayBuffer;for(var t=this.cells,e=wn+this.cells.length+1+1,r=0,n=0;n<this.cells.length;n++)r+=this.cells[n].length;var i=new Int32Array(e+r+this.keys.length+this.bboxes.length);i[0]=this.extent,i[1]=this.n,i[2]=this.padding;for(var a=e,o=0;o<t.length;o++){var s=t[o];i[wn+o]=a,i.set(s,a),a+=s.length;}return i[wn+t.length]=a,i.set(this.keys,a),a+=this.keys.length,i[wn+t.length+1]=a,i.set(this.bboxes,a),a+=this.bboxes.length,i.buffer};var Sn=self.ImageData,kn={};function zn(t,e,r){void 0===r&&(r={}),Object.defineProperty(e,\"_classRegistryKey\",{value:t,writeable:!1}),kn[t]={klass:e,omit:r.omit||[],shallow:r.shallow||[]};}for(var In in zn(\"Object\",Object),_n.serialize=function(t,e){var r=t.toArrayBuffer();return e&&e.push(r),{buffer:r}},_n.deserialize=function(t){return new _n(t.buffer)},zn(\"Grid\",_n),zn(\"Color\",ae),zn(\"Error\",Error),zn(\"StylePropertyFunction\",Rr),zn(\"StyleExpression\",Pr,{omit:[\"_evaluator\"]}),zn(\"ZoomDependentExpression\",Dr),zn(\"ZoomConstantExpression\",Lr),zn(\"CompoundExpression\",_e,{omit:[\"_evaluate\"]}),dr)dr[In]._classRegistryKey||zn(\"Expression_\"+In,dr[In]);function Bn(t,e){if(null==t||\"boolean\"==typeof t||\"number\"==typeof t||\"string\"==typeof t||t instanceof Boolean||t instanceof Number||t instanceof String||t instanceof Date||t instanceof RegExp)return t;if(t instanceof ArrayBuffer)return e&&e.push(t),t;if(ArrayBuffer.isView(t)){var r=t;return e&&e.push(r.buffer),r}if(t instanceof Sn)return e&&e.push(t.data.buffer),t;if(Array.isArray(t)){for(var n=[],i=0,a=t;i<a.length;i+=1){var o=a[i];n.push(Bn(o,e));}return n}if(\"object\"==typeof t){var s=t.constructor,u=s._classRegistryKey;if(!u)throw new Error(\"can't serialize object of unregistered class\");var l=s.serialize?s.serialize(t,e):{};if(!s.serialize){for(var p in t)if(t.hasOwnProperty(p)&&!(kn[u].omit.indexOf(p)>=0)){var c=t[p];l[p]=kn[u].shallow.indexOf(p)>=0?c:Bn(c,e);}t instanceof Error&&(l.message=t.message);}if(l.$name)throw new Error(\"$name property is reserved for worker serialization logic.\");return \"Object\"!==u&&(l.$name=u),l}throw new Error(\"can't serialize object of type \"+typeof t)}function Cn(t){if(null==t||\"boolean\"==typeof t||\"number\"==typeof t||\"string\"==typeof t||t instanceof Boolean||t instanceof Number||t instanceof String||t instanceof Date||t instanceof RegExp||t instanceof ArrayBuffer||ArrayBuffer.isView(t)||t instanceof Sn)return t;if(Array.isArray(t))return t.map(Cn);if(\"object\"==typeof t){var e=t.$name||\"Object\",r=kn[e].klass;if(!r)throw new Error(\"can't deserialize unregistered class \"+e);if(r.deserialize)return r.deserialize(t);for(var n=Object.create(r.prototype),i=0,a=Object.keys(t);i<a.length;i+=1){var o=a[i];if(\"$name\"!==o){var s=t[o];n[o]=kn[e].shallow.indexOf(o)>=0?s:Cn(s);}}return n}throw new Error(\"can't deserialize object of type \"+typeof t)}var En=function(){this.first=!0;};En.prototype.update=function(t,e){var r=Math.floor(t);return this.first?(this.first=!1,this.lastIntegerZoom=r,this.lastIntegerZoomTime=0,this.lastZoom=t,this.lastFloorZoom=r,!0):(this.lastFloorZoom>r?(this.lastIntegerZoom=r+1,this.lastIntegerZoomTime=e):this.lastFloorZoom<r&&(this.lastIntegerZoom=r,this.lastIntegerZoomTime=e),t!==this.lastZoom&&(this.lastZoom=t,this.lastFloorZoom=r,!0))};var Mn={\"Latin-1 Supplement\":function(t){return t>=128&&t<=255},Arabic:function(t){return t>=1536&&t<=1791},\"Arabic Supplement\":function(t){return t>=1872&&t<=1919},\"Arabic Extended-A\":function(t){return t>=2208&&t<=2303},\"Hangul Jamo\":function(t){return t>=4352&&t<=4607},\"Unified Canadian Aboriginal Syllabics\":function(t){return t>=5120&&t<=5759},Khmer:function(t){return t>=6016&&t<=6143},\"Unified Canadian Aboriginal Syllabics Extended\":function(t){return t>=6320&&t<=6399},\"General Punctuation\":function(t){return t>=8192&&t<=8303},\"Letterlike Symbols\":function(t){return t>=8448&&t<=8527},\"Number Forms\":function(t){return t>=8528&&t<=8591},\"Miscellaneous Technical\":function(t){return t>=8960&&t<=9215},\"Control Pictures\":function(t){return t>=9216&&t<=9279},\"Optical Character Recognition\":function(t){return t>=9280&&t<=9311},\"Enclosed Alphanumerics\":function(t){return t>=9312&&t<=9471},\"Geometric Shapes\":function(t){return t>=9632&&t<=9727},\"Miscellaneous Symbols\":function(t){return t>=9728&&t<=9983},\"Miscellaneous Symbols and Arrows\":function(t){return t>=11008&&t<=11263},\"CJK Radicals Supplement\":function(t){return t>=11904&&t<=12031},\"Kangxi Radicals\":function(t){return t>=12032&&t<=12255},\"Ideographic Description Characters\":function(t){return t>=12272&&t<=12287},\"CJK Symbols and Punctuation\":function(t){return t>=12288&&t<=12351},Hiragana:function(t){return t>=12352&&t<=12447},Katakana:function(t){return t>=12448&&t<=12543},Bopomofo:function(t){return t>=12544&&t<=12591},\"Hangul Compatibility Jamo\":function(t){return t>=12592&&t<=12687},Kanbun:function(t){return t>=12688&&t<=12703},\"Bopomofo Extended\":function(t){return t>=12704&&t<=12735},\"CJK Strokes\":function(t){return t>=12736&&t<=12783},\"Katakana Phonetic Extensions\":function(t){return t>=12784&&t<=12799},\"Enclosed CJK Letters and Months\":function(t){return t>=12800&&t<=13055},\"CJK Compatibility\":function(t){return t>=13056&&t<=13311},\"CJK Unified Ideographs Extension A\":function(t){return t>=13312&&t<=19903},\"Yijing Hexagram Symbols\":function(t){return t>=19904&&t<=19967},\"CJK Unified Ideographs\":function(t){return t>=19968&&t<=40959},\"Yi Syllables\":function(t){return t>=40960&&t<=42127},\"Yi Radicals\":function(t){return t>=42128&&t<=42191},\"Hangul Jamo Extended-A\":function(t){return t>=43360&&t<=43391},\"Hangul Syllables\":function(t){return t>=44032&&t<=55215},\"Hangul Jamo Extended-B\":function(t){return t>=55216&&t<=55295},\"Private Use Area\":function(t){return t>=57344&&t<=63743},\"CJK Compatibility Ideographs\":function(t){return t>=63744&&t<=64255},\"Arabic Presentation Forms-A\":function(t){return t>=64336&&t<=65023},\"Vertical Forms\":function(t){return t>=65040&&t<=65055},\"CJK Compatibility Forms\":function(t){return t>=65072&&t<=65103},\"Small Form Variants\":function(t){return t>=65104&&t<=65135},\"Arabic Presentation Forms-B\":function(t){return t>=65136&&t<=65279},\"Halfwidth and Fullwidth Forms\":function(t){return t>=65280&&t<=65519}};function Tn(t){for(var e=0,r=t;e<r.length;e+=1){if(Fn(r[e].charCodeAt(0)))return !0}return !1}function Pn(t){for(var e=0,r=t;e<r.length;e+=1){if(!Vn(r[e].charCodeAt(0)))return !1}return !0}function Vn(t){return !Mn.Arabic(t)&&(!Mn[\"Arabic Supplement\"](t)&&(!Mn[\"Arabic Extended-A\"](t)&&(!Mn[\"Arabic Presentation Forms-A\"](t)&&!Mn[\"Arabic Presentation Forms-B\"](t))))}function Fn(t){return 746===t||747===t||!(t<4352)&&(!!Mn[\"Bopomofo Extended\"](t)||(!!Mn.Bopomofo(t)||(!(!Mn[\"CJK Compatibility Forms\"](t)||t>=65097&&t<=65103)||(!!Mn[\"CJK Compatibility Ideographs\"](t)||(!!Mn[\"CJK Compatibility\"](t)||(!!Mn[\"CJK Radicals Supplement\"](t)||(!!Mn[\"CJK Strokes\"](t)||(!(!Mn[\"CJK Symbols and Punctuation\"](t)||t>=12296&&t<=12305||t>=12308&&t<=12319||12336===t)||(!!Mn[\"CJK Unified Ideographs Extension A\"](t)||(!!Mn[\"CJK Unified Ideographs\"](t)||(!!Mn[\"Enclosed CJK Letters and Months\"](t)||(!!Mn[\"Hangul Compatibility Jamo\"](t)||(!!Mn[\"Hangul Jamo Extended-A\"](t)||(!!Mn[\"Hangul Jamo Extended-B\"](t)||(!!Mn[\"Hangul Jamo\"](t)||(!!Mn[\"Hangul Syllables\"](t)||(!!Mn.Hiragana(t)||(!!Mn[\"Ideographic Description Characters\"](t)||(!!Mn.Kanbun(t)||(!!Mn[\"Kangxi Radicals\"](t)||(!!Mn[\"Katakana Phonetic Extensions\"](t)||(!(!Mn.Katakana(t)||12540===t)||(!(!Mn[\"Halfwidth and Fullwidth Forms\"](t)||65288===t||65289===t||65293===t||t>=65306&&t<=65310||65339===t||65341===t||65343===t||t>=65371&&t<=65503||65507===t||t>=65512&&t<=65519)||(!(!Mn[\"Small Form Variants\"](t)||t>=65112&&t<=65118||t>=65123&&t<=65126)||(!!Mn[\"Unified Canadian Aboriginal Syllabics\"](t)||(!!Mn[\"Unified Canadian Aboriginal Syllabics Extended\"](t)||(!!Mn[\"Vertical Forms\"](t)||(!!Mn[\"Yijing Hexagram Symbols\"](t)||(!!Mn[\"Yi Syllables\"](t)||!!Mn[\"Yi Radicals\"](t))))))))))))))))))))))))))))))}function Ln(t){return !(Fn(t)||function(t){return !!(Mn[\"Latin-1 Supplement\"](t)&&(167===t||169===t||174===t||177===t||188===t||189===t||190===t||215===t||247===t)||Mn[\"General Punctuation\"](t)&&(8214===t||8224===t||8225===t||8240===t||8241===t||8251===t||8252===t||8258===t||8263===t||8264===t||8265===t||8273===t)||Mn[\"Letterlike Symbols\"](t)||Mn[\"Number Forms\"](t)||Mn[\"Miscellaneous Technical\"](t)&&(t>=8960&&t<=8967||t>=8972&&t<=8991||t>=8996&&t<=9e3||9003===t||t>=9085&&t<=9114||t>=9150&&t<=9165||9167===t||t>=9169&&t<=9179||t>=9186&&t<=9215)||Mn[\"Control Pictures\"](t)&&9251!==t||Mn[\"Optical Character Recognition\"](t)||Mn[\"Enclosed Alphanumerics\"](t)||Mn[\"Geometric Shapes\"](t)||Mn[\"Miscellaneous Symbols\"](t)&&!(t>=9754&&t<=9759)||Mn[\"Miscellaneous Symbols and Arrows\"](t)&&(t>=11026&&t<=11055||t>=11088&&t<=11097||t>=11192&&t<=11243)||Mn[\"CJK Symbols and Punctuation\"](t)||Mn.Katakana(t)||Mn[\"Private Use Area\"](t)||Mn[\"CJK Compatibility Forms\"](t)||Mn[\"Small Form Variants\"](t)||Mn[\"Halfwidth and Fullwidth Forms\"](t)||8734===t||8756===t||8757===t||t>=9984&&t<=10087||t>=10102&&t<=10131||65532===t||65533===t)}(t))}function Dn(t,e){return !(!e&&(t>=1424&&t<=2303||Mn[\"Arabic Presentation Forms-A\"](t)||Mn[\"Arabic Presentation Forms-B\"](t)))&&!(t>=2304&&t<=3583||t>=3840&&t<=4255||Mn.Khmer(t))}var On,Rn=!1,Un=null,jn=!1,qn=new Ft,Nn={applyArabicShaping:null,processBidirectionalText:null,processStyledBidirectionalText:null,isLoaded:function(){return jn||null!=Nn.applyArabicShaping}},Zn=function(t,e){this.zoom=t,e?(this.now=e.now,this.fadeDuration=e.fadeDuration,this.zoomHistory=e.zoomHistory,this.transition=e.transition):(this.now=0,this.fadeDuration=0,this.zoomHistory=new En,this.transition={});};Zn.prototype.isSupportedScript=function(t){return function(t,e){for(var r=0,n=t;r<n.length;r+=1)if(!Dn(n[r].charCodeAt(0),e))return !1;return !0}(t,Nn.isLoaded())},Zn.prototype.crossFadingFactor=function(){return 0===this.fadeDuration?1:Math.min((this.now-this.zoomHistory.lastIntegerZoomTime)/this.fadeDuration,1)},Zn.prototype.getCrossfadeParameters=function(){var t=this.zoom,e=t-Math.floor(t),r=this.crossFadingFactor();return t>this.zoomHistory.lastIntegerZoom?{fromScale:2,toScale:1,t:e+(1-e)*r}:{fromScale:.5,toScale:1,t:1-(1-r)*e}};var Kn=function(t,e){this.property=t,this.value=e,this.expression=function(t,e){if(zr(t))return new Rr(t,e);if(Vr(t)){var r=Or(t,e);if(\"error\"===r.result)throw new Error(r.value.map(function(t){return t.key+\": \"+t.message}).join(\", \"));return r.value}var n=t;return \"string\"==typeof t&&\"color\"===e.type&&(n=ae.parse(t)),{kind:\"constant\",evaluate:function(){return n}}}(void 0===e?t.specification.default:e,t.specification);};Kn.prototype.isDataDriven=function(){return \"source\"===this.expression.kind||\"composite\"===this.expression.kind},Kn.prototype.possiblyEvaluate=function(t){return this.property.possiblyEvaluate(this,t)};var Gn=function(t){this.property=t,this.value=new Kn(t,void 0);};Gn.prototype.transitioned=function(t,e){return new Jn(this.property,this.value,e,c({},t.transition,this.transition),t.now)},Gn.prototype.untransitioned=function(){return new Jn(this.property,this.value,null,{},0)};var Xn=function(t){this._properties=t,this._values=Object.create(t.defaultTransitionablePropertyValues);};Xn.prototype.getValue=function(t){return b(this._values[t].value.value)},Xn.prototype.setValue=function(t,e){this._values.hasOwnProperty(t)||(this._values[t]=new Gn(this._values[t].property)),this._values[t].value=new Kn(this._values[t].property,null===e?void 0:b(e));},Xn.prototype.getTransition=function(t){return b(this._values[t].transition)},Xn.prototype.setTransition=function(t,e){this._values.hasOwnProperty(t)||(this._values[t]=new Gn(this._values[t].property)),this._values[t].transition=b(e)||void 0;},Xn.prototype.serialize=function(){for(var t={},e=0,r=Object.keys(this._values);e<r.length;e+=1){var n=r[e],i=this.getValue(n);void 0!==i&&(t[n]=i);var a=this.getTransition(n);void 0!==a&&(t[n+\"-transition\"]=a);}return t},Xn.prototype.transitioned=function(t,e){for(var r=new Hn(this._properties),n=0,i=Object.keys(this._values);n<i.length;n+=1){var a=i[n];r._values[a]=this._values[a].transitioned(t,e._values[a]);}return r},Xn.prototype.untransitioned=function(){for(var t=new Hn(this._properties),e=0,r=Object.keys(this._values);e<r.length;e+=1){var n=r[e];t._values[n]=this._values[n].untransitioned();}return t};var Jn=function(t,e,r,n,i){this.property=t,this.value=e,this.begin=i+n.delay||0,this.end=this.begin+n.duration||0,t.specification.transition&&(n.delay||n.duration)&&(this.prior=r);};Jn.prototype.possiblyEvaluate=function(t){var e=t.now||0,r=this.value.possiblyEvaluate(t),n=this.prior;if(n){if(e>this.end)return this.prior=null,r;if(this.value.isDataDriven())return this.prior=null,r;if(e<this.begin)return n.possiblyEvaluate(t);var i=(e-this.begin)/(this.end-this.begin);return this.property.interpolate(n.possiblyEvaluate(t),r,function(t){if(t<=0)return 0;if(t>=1)return 1;var e=t*t,r=e*t;return 4*(t<.5?r:3*(t-e)+r-.75)}(i))}return r};var Hn=function(t){this._properties=t,this._values=Object.create(t.defaultTransitioningPropertyValues);};Hn.prototype.possiblyEvaluate=function(t){for(var e=new Wn(this._properties),r=0,n=Object.keys(this._values);r<n.length;r+=1){var i=n[r];e._values[i]=this._values[i].possiblyEvaluate(t);}return e},Hn.prototype.hasTransition=function(){for(var t=0,e=Object.keys(this._values);t<e.length;t+=1){var r=e[t];if(this._values[r].prior)return !0}return !1};var Yn=function(t){this._properties=t,this._values=Object.create(t.defaultPropertyValues);};Yn.prototype.getValue=function(t){return b(this._values[t].value)},Yn.prototype.setValue=function(t,e){this._values[t]=new Kn(this._values[t].property,null===e?void 0:b(e));},Yn.prototype.serialize=function(){for(var t={},e=0,r=Object.keys(this._values);e<r.length;e+=1){var n=r[e],i=this.getValue(n);void 0!==i&&(t[n]=i);}return t},Yn.prototype.possiblyEvaluate=function(t){for(var e=new Wn(this._properties),r=0,n=Object.keys(this._values);r<n.length;r+=1){var i=n[r];e._values[i]=this._values[i].possiblyEvaluate(t);}return e};var $n=function(t,e,r){this.property=t,this.value=e,this.parameters=r;};$n.prototype.isConstant=function(){return \"constant\"===this.value.kind},$n.prototype.constantOr=function(t){return \"constant\"===this.value.kind?this.value.value:t},$n.prototype.evaluate=function(t,e){return this.property.evaluate(this.value,this.parameters,t,e)};var Wn=function(t){this._properties=t,this._values=Object.create(t.defaultPossiblyEvaluatedValues);};Wn.prototype.get=function(t){return this._values[t]};var Qn=function(t){this.specification=t;};Qn.prototype.possiblyEvaluate=function(t,e){return t.expression.evaluate(e)},Qn.prototype.interpolate=function(t,e,r){var n=Me[this.specification.type];return n?n(t,e,r):t};var ti=function(t){this.specification=t;};ti.prototype.possiblyEvaluate=function(t,e){return \"constant\"===t.expression.kind||\"camera\"===t.expression.kind?new $n(this,{kind:\"constant\",value:t.expression.evaluate(e)},e):new $n(this,t.expression,e)},ti.prototype.interpolate=function(t,e,r){if(\"constant\"!==t.value.kind||\"constant\"!==e.value.kind)return t;if(void 0===t.value.value||void 0===e.value.value)return new $n(this,{kind:\"constant\",value:void 0},t.parameters);var n=Me[this.specification.type];return n?new $n(this,{kind:\"constant\",value:n(t.value.value,e.value.value,r)},t.parameters):t},ti.prototype.evaluate=function(t,e,r,n){return \"constant\"===t.kind?t.value:t.evaluate(e,r,n)};var ei=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.possiblyEvaluate=function(t,e){if(void 0===t.value)return new $n(this,{kind:\"constant\",value:void 0},e);if(\"constant\"===t.expression.kind){var r=t.expression.evaluate(e),n=this._calculate(r,r,r,e);return new $n(this,{kind:\"constant\",value:n},e)}if(\"camera\"===t.expression.kind){var i=this._calculate(t.expression.evaluate({zoom:e.zoom-1}),t.expression.evaluate({zoom:e.zoom}),t.expression.evaluate({zoom:e.zoom+1}),e);return new $n(this,{kind:\"constant\",value:i},e)}return new $n(this,t.expression,e)},e.prototype.evaluate=function(t,e,r,n){if(\"source\"===t.kind){var i=t.evaluate(e,r,n);return this._calculate(i,i,i,e)}return \"composite\"===t.kind?this._calculate(t.evaluate({zoom:Math.floor(e.zoom)-1},r,n),t.evaluate({zoom:Math.floor(e.zoom)},r,n),t.evaluate({zoom:Math.floor(e.zoom)+1},r,n),e):t.value},e.prototype._calculate=function(t,e,r,n){return n.zoom>n.zoomHistory.lastIntegerZoom?{from:t,to:e}:{from:r,to:e}},e.prototype.interpolate=function(t){return t},e}(ti),ri=function(t){this.specification=t;};ri.prototype.possiblyEvaluate=function(t,e){if(void 0!==t.value){if(\"constant\"===t.expression.kind){var r=t.expression.evaluate(e);return this._calculate(r,r,r,e)}return this._calculate(t.expression.evaluate(new Zn(Math.floor(e.zoom-1),e)),t.expression.evaluate(new Zn(Math.floor(e.zoom),e)),t.expression.evaluate(new Zn(Math.floor(e.zoom+1),e)),e)}},ri.prototype._calculate=function(t,e,r,n){return n.zoom>n.zoomHistory.lastIntegerZoom?{from:t,to:e}:{from:r,to:e}},ri.prototype.interpolate=function(t){return t};var ni=function(t){this.specification=t;};ni.prototype.possiblyEvaluate=function(t,e){return !!t.expression.evaluate(e)},ni.prototype.interpolate=function(){return !1};var ii=function(t){for(var e in this.properties=t,this.defaultPropertyValues={},this.defaultTransitionablePropertyValues={},this.defaultTransitioningPropertyValues={},this.defaultPossiblyEvaluatedValues={},t){var r=t[e],n=this.defaultPropertyValues[e]=new Kn(r,void 0),i=this.defaultTransitionablePropertyValues[e]=new Gn(r);this.defaultTransitioningPropertyValues[e]=i.untransitioned(),this.defaultPossiblyEvaluatedValues[e]=n.possiblyEvaluate({});}};zn(\"DataDrivenProperty\",ti),zn(\"DataConstantProperty\",Qn),zn(\"CrossFadedDataDrivenProperty\",ei),zn(\"CrossFadedProperty\",ri),zn(\"ColorRampProperty\",ni);var ai=function(t){function e(e,r){if(t.call(this),this.id=e.id,this.type=e.type,this._featureFilter=function(){return !0},\"custom\"!==e.type&&(e=e,this.metadata=e.metadata,this.minzoom=e.minzoom,this.maxzoom=e.maxzoom,\"background\"!==e.type&&(this.source=e.source,this.sourceLayer=e[\"source-layer\"],this.filter=e.filter),r.layout&&(this._unevaluatedLayout=new Yn(r.layout)),r.paint)){for(var n in this._transitionablePaint=new Xn(r.paint),e.paint)this.setPaintProperty(n,e.paint[n],{validate:!1});for(var i in e.layout)this.setLayoutProperty(i,e.layout[i],{validate:!1});this._transitioningPaint=this._transitionablePaint.untransitioned();}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getCrossfadeParameters=function(){return this._crossfadeParameters},e.prototype.getLayoutProperty=function(t){return \"visibility\"===t?this.visibility:this._unevaluatedLayout.getValue(t)},e.prototype.setLayoutProperty=function(t,e,r){if(void 0===r&&(r={}),null!=e){var n=\"layers.\"+this.id+\".layout.\"+t;if(this._validate(xn,n,t,e,r))return}\"visibility\"!==t?this._unevaluatedLayout.setValue(t,e):this.visibility=e;},e.prototype.getPaintProperty=function(t){return v(t,\"-transition\")?this._transitionablePaint.getTransition(t.slice(0,-\"-transition\".length)):this._transitionablePaint.getValue(t)},e.prototype.setPaintProperty=function(t,e,r){if(void 0===r&&(r={}),null!=e){var n=\"layers.\"+this.id+\".paint.\"+t;if(this._validate(gn,n,t,e,r))return !1}if(v(t,\"-transition\"))return this._transitionablePaint.setTransition(t.slice(0,-\"-transition\".length),e||void 0),!1;var i=this._transitionablePaint._values[t],a=\"cross-faded-data-driven\"===i.property.specification[\"property-type\"],o=i.value.isDataDriven();return this._transitionablePaint.setValue(t,e),this._handleSpecialPaintPropertyUpdate(t),this._transitionablePaint._values[t].value.isDataDriven()||o||a},e.prototype._handleSpecialPaintPropertyUpdate=function(t){},e.prototype.isHidden=function(t){return !!(this.minzoom&&t<this.minzoom)||(!!(this.maxzoom&&t>=this.maxzoom)||\"none\"===this.visibility)},e.prototype.updateTransitions=function(t){this._transitioningPaint=this._transitionablePaint.transitioned(t,this._transitioningPaint);},e.prototype.hasTransition=function(){return this._transitioningPaint.hasTransition()},e.prototype.recalculate=function(t){t.getCrossfadeParameters&&(this._crossfadeParameters=t.getCrossfadeParameters()),this._unevaluatedLayout&&(this.layout=this._unevaluatedLayout.possiblyEvaluate(t)),this.paint=this._transitioningPaint.possiblyEvaluate(t);},e.prototype.serialize=function(){var t={id:this.id,type:this.type,source:this.source,\"source-layer\":this.sourceLayer,metadata:this.metadata,minzoom:this.minzoom,maxzoom:this.maxzoom,filter:this.filter,layout:this._unevaluatedLayout&&this._unevaluatedLayout.serialize(),paint:this._transitionablePaint&&this._transitionablePaint.serialize()};return this.visibility&&(t.layout=t.layout||{},t.layout.visibility=this.visibility),x(t,function(t,e){return !(void 0===t||\"layout\"===e&&!Object.keys(t).length||\"paint\"===e&&!Object.keys(t).length)})},e.prototype._validate=function(t,e,r,n,i){return void 0===i&&(i={}),(!i||!1!==i.validate)&&bn(this,t.call(mn,{key:e,layerType:this.type,objectKey:r,value:n,styleSpec:Lt,style:{glyphs:!0,sprite:!0}}))},e.prototype.is3D=function(){return !1},e.prototype.isTileClipped=function(){return !1},e.prototype.hasOffscreenPass=function(){return !1},e.prototype.resize=function(){},e.prototype.isStateDependent=function(){for(var t in this.paint._values){var e=this.paint.get(t);if(e instanceof $n&&wr(e.property.specification)&&((\"source\"===e.value.kind||\"composite\"===e.value.kind)&&e.value.isStateDependent))return !0}return !1},e}(Ft),oi={Int8:Int8Array,Uint8:Uint8Array,Int16:Int16Array,Uint16:Uint16Array,Int32:Int32Array,Uint32:Uint32Array,Float32:Float32Array},si=function(t,e){this._structArray=t,this._pos1=e*this.size,this._pos2=this._pos1/2,this._pos4=this._pos1/4,this._pos8=this._pos1/8;},ui=function(){this.isTransferred=!1,this.capacity=-1,this.resize(0);};function li(t,e){void 0===e&&(e=1);var r=0,n=0;return {members:t.map(function(t){var i,a=(i=t.type,oi[i].BYTES_PER_ELEMENT),o=r=pi(r,Math.max(e,a)),s=t.components||1;return n=Math.max(n,a),r+=a*s,{name:t.name,type:t.type,components:s,offset:o}}),size:pi(r,Math.max(n,e)),alignment:e}}function pi(t,e){return Math.ceil(t/e)*e}ui.serialize=function(t,e){return t._trim(),e&&(t.isTransferred=!0,e.push(t.arrayBuffer)),{length:t.length,arrayBuffer:t.arrayBuffer}},ui.deserialize=function(t){var e=Object.create(this.prototype);return e.arrayBuffer=t.arrayBuffer,e.length=t.length,e.capacity=t.arrayBuffer.byteLength/e.bytesPerElement,e._refreshViews(),e},ui.prototype._trim=function(){this.length!==this.capacity&&(this.capacity=this.length,this.arrayBuffer=this.arrayBuffer.slice(0,this.length*this.bytesPerElement),this._refreshViews());},ui.prototype.clear=function(){this.length=0;},ui.prototype.resize=function(t){this.reserve(t),this.length=t;},ui.prototype.reserve=function(t){if(t>this.capacity){this.capacity=Math.max(t,Math.floor(5*this.capacity),128),this.arrayBuffer=new ArrayBuffer(this.capacity*this.bytesPerElement);var e=this.uint8;this._refreshViews(),e&&this.uint8.set(e);}},ui.prototype._refreshViews=function(){throw new Error(\"_refreshViews() must be implemented by each concrete StructArray layout\")};var ci=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e){var r=this.length;return this.resize(r+1),this.emplace(r,t,e)},e.prototype.emplace=function(t,e,r){var n=2*t;return this.int16[n+0]=e,this.int16[n+1]=r,t},e}(ui);ci.prototype.bytesPerElement=4,zn(\"StructArrayLayout2i4\",ci);var hi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n){var i=this.length;return this.resize(i+1),this.emplace(i,t,e,r,n)},e.prototype.emplace=function(t,e,r,n,i){var a=4*t;return this.int16[a+0]=e,this.int16[a+1]=r,this.int16[a+2]=n,this.int16[a+3]=i,t},e}(ui);hi.prototype.bytesPerElement=8,zn(\"StructArrayLayout4i8\",hi);var fi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n,i,a){var o=this.length;return this.resize(o+1),this.emplace(o,t,e,r,n,i,a)},e.prototype.emplace=function(t,e,r,n,i,a,o){var s=6*t;return this.int16[s+0]=e,this.int16[s+1]=r,this.int16[s+2]=n,this.int16[s+3]=i,this.int16[s+4]=a,this.int16[s+5]=o,t},e}(ui);fi.prototype.bytesPerElement=12,zn(\"StructArrayLayout2i4i12\",fi);var yi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n,i,a){var o=this.length;return this.resize(o+1),this.emplace(o,t,e,r,n,i,a)},e.prototype.emplace=function(t,e,r,n,i,a,o){var s=4*t,u=8*t;return this.int16[s+0]=e,this.int16[s+1]=r,this.uint8[u+4]=n,this.uint8[u+5]=i,this.uint8[u+6]=a,this.uint8[u+7]=o,t},e}(ui);yi.prototype.bytesPerElement=8,zn(\"StructArrayLayout2i4ub8\",yi);var di=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s){var u=this.length;return this.resize(u+1),this.emplace(u,t,e,r,n,i,a,o,s)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,u){var l=8*t;return this.uint16[l+0]=e,this.uint16[l+1]=r,this.uint16[l+2]=n,this.uint16[l+3]=i,this.uint16[l+4]=a,this.uint16[l+5]=o,this.uint16[l+6]=s,this.uint16[l+7]=u,t},e}(ui);di.prototype.bytesPerElement=16,zn(\"StructArrayLayout8ui16\",di);var mi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s){var u=this.length;return this.resize(u+1),this.emplace(u,t,e,r,n,i,a,o,s)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,u){var l=8*t;return this.int16[l+0]=e,this.int16[l+1]=r,this.int16[l+2]=n,this.int16[l+3]=i,this.uint16[l+4]=a,this.uint16[l+5]=o,this.uint16[l+6]=s,this.uint16[l+7]=u,t},e}(ui);mi.prototype.bytesPerElement=16,zn(\"StructArrayLayout4i4ui16\",mi);var vi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r){var n=this.length;return this.resize(n+1),this.emplace(n,t,e,r)},e.prototype.emplace=function(t,e,r,n){var i=3*t;return this.float32[i+0]=e,this.float32[i+1]=r,this.float32[i+2]=n,t},e}(ui);vi.prototype.bytesPerElement=12,zn(\"StructArrayLayout3f12\",vi);var gi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t){var e=this.length;return this.resize(e+1),this.emplace(e,t)},e.prototype.emplace=function(t,e){var r=1*t;return this.uint32[r+0]=e,t},e}(ui);gi.prototype.bytesPerElement=4,zn(\"StructArrayLayout1ul4\",gi);var xi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s,u,l,p){var c=this.length;return this.resize(c+1),this.emplace(c,t,e,r,n,i,a,o,s,u,l,p)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,u,l,p,c){var h=12*t,f=6*t;return this.int16[h+0]=e,this.int16[h+1]=r,this.int16[h+2]=n,this.int16[h+3]=i,this.int16[h+4]=a,this.int16[h+5]=o,this.uint32[f+3]=s,this.uint16[h+8]=u,this.uint16[h+9]=l,this.int16[h+10]=p,this.int16[h+11]=c,t},e}(ui);xi.prototype.bytesPerElement=24,zn(\"StructArrayLayout6i1ul2ui2i24\",xi);var bi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n,i,a){var o=this.length;return this.resize(o+1),this.emplace(o,t,e,r,n,i,a)},e.prototype.emplace=function(t,e,r,n,i,a,o){var s=6*t;return this.int16[s+0]=e,this.int16[s+1]=r,this.int16[s+2]=n,this.int16[s+3]=i,this.int16[s+4]=a,this.int16[s+5]=o,t},e}(ui);bi.prototype.bytesPerElement=12,zn(\"StructArrayLayout2i2i2i12\",bi);var _i=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n){var i=this.length;return this.resize(i+1),this.emplace(i,t,e,r,n)},e.prototype.emplace=function(t,e,r,n,i){var a=12*t,o=3*t;return this.uint8[a+0]=e,this.uint8[a+1]=r,this.float32[o+1]=n,this.float32[o+2]=i,t},e}(ui);_i.prototype.bytesPerElement=12,zn(\"StructArrayLayout2ub2f12\",_i);var wi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s,u,l,p,c,h,f,y){var d=this.length;return this.resize(d+1),this.emplace(d,t,e,r,n,i,a,o,s,u,l,p,c,h,f,y)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,u,l,p,c,h,f,y,d){var m=22*t,v=11*t,g=44*t;return this.int16[m+0]=e,this.int16[m+1]=r,this.uint16[m+2]=n,this.uint16[m+3]=i,this.uint32[v+2]=a,this.uint32[v+3]=o,this.uint32[v+4]=s,this.uint16[m+10]=u,this.uint16[m+11]=l,this.uint16[m+12]=p,this.float32[v+7]=c,this.float32[v+8]=h,this.uint8[g+36]=f,this.uint8[g+37]=y,this.uint32[v+10]=d,t},e}(ui);wi.prototype.bytesPerElement=44,zn(\"StructArrayLayout2i2ui3ul3ui2f2ub1ul44\",wi);var Ai=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n,i,a,o,s,u,l,p,c,h,f,y,d,m,v){var g=this.length;return this.resize(g+1),this.emplace(g,t,e,r,n,i,a,o,s,u,l,p,c,h,f,y,d,m,v)},e.prototype.emplace=function(t,e,r,n,i,a,o,s,u,l,p,c,h,f,y,d,m,v,g){var x=22*t,b=11*t;return this.int16[x+0]=e,this.int16[x+1]=r,this.int16[x+2]=n,this.int16[x+3]=i,this.int16[x+4]=a,this.int16[x+5]=o,this.uint16[x+6]=s,this.uint16[x+7]=u,this.uint16[x+8]=l,this.uint16[x+9]=p,this.uint16[x+10]=c,this.uint16[x+11]=h,this.uint16[x+12]=f,this.uint16[x+13]=y,this.uint16[x+14]=d,this.uint32[b+8]=m,this.float32[b+9]=v,this.float32[b+10]=g,t},e}(ui);Ai.prototype.bytesPerElement=44,zn(\"StructArrayLayout6i9ui1ul2f44\",Ai);var Si=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t){var e=this.length;return this.resize(e+1),this.emplace(e,t)},e.prototype.emplace=function(t,e){var r=1*t;return this.float32[r+0]=e,t},e}(ui);Si.prototype.bytesPerElement=4,zn(\"StructArrayLayout1f4\",Si);var ki=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.int16=new Int16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r){var n=this.length;return this.resize(n+1),this.emplace(n,t,e,r)},e.prototype.emplace=function(t,e,r,n){var i=3*t;return this.int16[i+0]=e,this.int16[i+1]=r,this.int16[i+2]=n,t},e}(ui);ki.prototype.bytesPerElement=6,zn(\"StructArrayLayout3i6\",ki);var zi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint32=new Uint32Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r){var n=this.length;return this.resize(n+1),this.emplace(n,t,e,r)},e.prototype.emplace=function(t,e,r,n){var i=2*t,a=4*t;return this.uint32[i+0]=e,this.uint16[a+2]=r,this.uint16[a+3]=n,t},e}(ui);zi.prototype.bytesPerElement=8,zn(\"StructArrayLayout1ul2ui8\",zi);var Ii=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r){var n=this.length;return this.resize(n+1),this.emplace(n,t,e,r)},e.prototype.emplace=function(t,e,r,n){var i=3*t;return this.uint16[i+0]=e,this.uint16[i+1]=r,this.uint16[i+2]=n,t},e}(ui);Ii.prototype.bytesPerElement=6,zn(\"StructArrayLayout3ui6\",Ii);var Bi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e){var r=this.length;return this.resize(r+1),this.emplace(r,t,e)},e.prototype.emplace=function(t,e,r){var n=2*t;return this.uint16[n+0]=e,this.uint16[n+1]=r,t},e}(ui);Bi.prototype.bytesPerElement=4,zn(\"StructArrayLayout2ui4\",Bi);var Ci=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.uint16=new Uint16Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t){var e=this.length;return this.resize(e+1),this.emplace(e,t)},e.prototype.emplace=function(t,e){var r=1*t;return this.uint16[r+0]=e,t},e}(ui);Ci.prototype.bytesPerElement=2,zn(\"StructArrayLayout1ui2\",Ci);var Ei=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e){var r=this.length;return this.resize(r+1),this.emplace(r,t,e)},e.prototype.emplace=function(t,e,r){var n=2*t;return this.float32[n+0]=e,this.float32[n+1]=r,t},e}(ui);Ei.prototype.bytesPerElement=8,zn(\"StructArrayLayout2f8\",Ei);var Mi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._refreshViews=function(){this.uint8=new Uint8Array(this.arrayBuffer),this.float32=new Float32Array(this.arrayBuffer);},e.prototype.emplaceBack=function(t,e,r,n){var i=this.length;return this.resize(i+1),this.emplace(i,t,e,r,n)},e.prototype.emplace=function(t,e,r,n,i){var a=4*t;return this.float32[a+0]=e,this.float32[a+1]=r,this.float32[a+2]=n,this.float32[a+3]=i,t},e}(ui);Mi.prototype.bytesPerElement=16,zn(\"StructArrayLayout4f16\",Mi);var Ti=function(t){function e(){t.apply(this,arguments);}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={anchorPointX:{configurable:!0},anchorPointY:{configurable:!0},x1:{configurable:!0},y1:{configurable:!0},x2:{configurable:!0},y2:{configurable:!0},featureIndex:{configurable:!0},sourceLayerIndex:{configurable:!0},bucketIndex:{configurable:!0},radius:{configurable:!0},signedDistanceFromAnchor:{configurable:!0},anchorPoint:{configurable:!0}};return r.anchorPointX.get=function(){return this._structArray.int16[this._pos2+0]},r.anchorPointX.set=function(t){this._structArray.int16[this._pos2+0]=t;},r.anchorPointY.get=function(){return this._structArray.int16[this._pos2+1]},r.anchorPointY.set=function(t){this._structArray.int16[this._pos2+1]=t;},r.x1.get=function(){return this._structArray.int16[this._pos2+2]},r.x1.set=function(t){this._structArray.int16[this._pos2+2]=t;},r.y1.get=function(){return this._structArray.int16[this._pos2+3]},r.y1.set=function(t){this._structArray.int16[this._pos2+3]=t;},r.x2.get=function(){return this._structArray.int16[this._pos2+4]},r.x2.set=function(t){this._structArray.int16[this._pos2+4]=t;},r.y2.get=function(){return this._structArray.int16[this._pos2+5]},r.y2.set=function(t){this._structArray.int16[this._pos2+5]=t;},r.featureIndex.get=function(){return this._structArray.uint32[this._pos4+3]},r.featureIndex.set=function(t){this._structArray.uint32[this._pos4+3]=t;},r.sourceLayerIndex.get=function(){return this._structArray.uint16[this._pos2+8]},r.sourceLayerIndex.set=function(t){this._structArray.uint16[this._pos2+8]=t;},r.bucketIndex.get=function(){return this._structArray.uint16[this._pos2+9]},r.bucketIndex.set=function(t){this._structArray.uint16[this._pos2+9]=t;},r.radius.get=function(){return this._structArray.int16[this._pos2+10]},r.radius.set=function(t){this._structArray.int16[this._pos2+10]=t;},r.signedDistanceFromAnchor.get=function(){return this._structArray.int16[this._pos2+11]},r.signedDistanceFromAnchor.set=function(t){this._structArray.int16[this._pos2+11]=t;},r.anchorPoint.get=function(){return new i(this.anchorPointX,this.anchorPointY)},Object.defineProperties(e.prototype,r),e}(si);Ti.prototype.size=24;var Pi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.get=function(t){return new Ti(this,t)},e}(xi);zn(\"CollisionBoxArray\",Pi);var Vi=function(t){function e(){t.apply(this,arguments);}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={anchorX:{configurable:!0},anchorY:{configurable:!0},glyphStartIndex:{configurable:!0},numGlyphs:{configurable:!0},vertexStartIndex:{configurable:!0},lineStartIndex:{configurable:!0},lineLength:{configurable:!0},segment:{configurable:!0},lowerSize:{configurable:!0},upperSize:{configurable:!0},lineOffsetX:{configurable:!0},lineOffsetY:{configurable:!0},writingMode:{configurable:!0},hidden:{configurable:!0},crossTileID:{configurable:!0}};return r.anchorX.get=function(){return this._structArray.int16[this._pos2+0]},r.anchorX.set=function(t){this._structArray.int16[this._pos2+0]=t;},r.anchorY.get=function(){return this._structArray.int16[this._pos2+1]},r.anchorY.set=function(t){this._structArray.int16[this._pos2+1]=t;},r.glyphStartIndex.get=function(){return this._structArray.uint16[this._pos2+2]},r.glyphStartIndex.set=function(t){this._structArray.uint16[this._pos2+2]=t;},r.numGlyphs.get=function(){return this._structArray.uint16[this._pos2+3]},r.numGlyphs.set=function(t){this._structArray.uint16[this._pos2+3]=t;},r.vertexStartIndex.get=function(){return this._structArray.uint32[this._pos4+2]},r.vertexStartIndex.set=function(t){this._structArray.uint32[this._pos4+2]=t;},r.lineStartIndex.get=function(){return this._structArray.uint32[this._pos4+3]},r.lineStartIndex.set=function(t){this._structArray.uint32[this._pos4+3]=t;},r.lineLength.get=function(){return this._structArray.uint32[this._pos4+4]},r.lineLength.set=function(t){this._structArray.uint32[this._pos4+4]=t;},r.segment.get=function(){return this._structArray.uint16[this._pos2+10]},r.segment.set=function(t){this._structArray.uint16[this._pos2+10]=t;},r.lowerSize.get=function(){return this._structArray.uint16[this._pos2+11]},r.lowerSize.set=function(t){this._structArray.uint16[this._pos2+11]=t;},r.upperSize.get=function(){return this._structArray.uint16[this._pos2+12]},r.upperSize.set=function(t){this._structArray.uint16[this._pos2+12]=t;},r.lineOffsetX.get=function(){return this._structArray.float32[this._pos4+7]},r.lineOffsetX.set=function(t){this._structArray.float32[this._pos4+7]=t;},r.lineOffsetY.get=function(){return this._structArray.float32[this._pos4+8]},r.lineOffsetY.set=function(t){this._structArray.float32[this._pos4+8]=t;},r.writingMode.get=function(){return this._structArray.uint8[this._pos1+36]},r.writingMode.set=function(t){this._structArray.uint8[this._pos1+36]=t;},r.hidden.get=function(){return this._structArray.uint8[this._pos1+37]},r.hidden.set=function(t){this._structArray.uint8[this._pos1+37]=t;},r.crossTileID.get=function(){return this._structArray.uint32[this._pos4+10]},r.crossTileID.set=function(t){this._structArray.uint32[this._pos4+10]=t;},Object.defineProperties(e.prototype,r),e}(si);Vi.prototype.size=44;var Fi=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.get=function(t){return new Vi(this,t)},e}(wi);zn(\"PlacedSymbolArray\",Fi);var Li=function(t){function e(){t.apply(this,arguments);}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={anchorX:{configurable:!0},anchorY:{configurable:!0},rightJustifiedTextSymbolIndex:{configurable:!0},centerJustifiedTextSymbolIndex:{configurable:!0},leftJustifiedTextSymbolIndex:{configurable:!0},verticalPlacedTextSymbolIndex:{configurable:!0},key:{configurable:!0},textBoxStartIndex:{configurable:!0},textBoxEndIndex:{configurable:!0},iconBoxStartIndex:{configurable:!0},iconBoxEndIndex:{configurable:!0},featureIndex:{configurable:!0},numHorizontalGlyphVertices:{configurable:!0},numVerticalGlyphVertices:{configurable:!0},numIconVertices:{configurable:!0},crossTileID:{configurable:!0},textBoxScale:{configurable:!0},radialTextOffset:{configurable:!0}};return r.anchorX.get=function(){return this._structArray.int16[this._pos2+0]},r.anchorX.set=function(t){this._structArray.int16[this._pos2+0]=t;},r.anchorY.get=function(){return this._structArray.int16[this._pos2+1]},r.anchorY.set=function(t){this._structArray.int16[this._pos2+1]=t;},r.rightJustifiedTextSymbolIndex.get=function(){return this._structArray.int16[this._pos2+2]},r.rightJustifiedTextSymbolIndex.set=function(t){this._structArray.int16[this._pos2+2]=t;},r.centerJustifiedTextSymbolIndex.get=function(){return this._structArray.int16[this._pos2+3]},r.centerJustifiedTextSymbolIndex.set=function(t){this._structArray.int16[this._pos2+3]=t;},r.leftJustifiedTextSymbolIndex.get=function(){return this._structArray.int16[this._pos2+4]},r.leftJustifiedTextSymbolIndex.set=function(t){this._structArray.int16[this._pos2+4]=t;},r.verticalPlacedTextSymbolIndex.get=function(){return this._structArray.int16[this._pos2+5]},r.verticalPlacedTextSymbolIndex.set=function(t){this._structArray.int16[this._pos2+5]=t;},r.key.get=function(){return this._structArray.uint16[this._pos2+6]},r.key.set=function(t){this._structArray.uint16[this._pos2+6]=t;},r.textBoxStartIndex.get=function(){return this._structArray.uint16[this._pos2+7]},r.textBoxStartIndex.set=function(t){this._structArray.uint16[this._pos2+7]=t;},r.textBoxEndIndex.get=function(){return this._structArray.uint16[this._pos2+8]},r.textBoxEndIndex.set=function(t){this._structArray.uint16[this._pos2+8]=t;},r.iconBoxStartIndex.get=function(){return this._structArray.uint16[this._pos2+9]},r.iconBoxStartIndex.set=function(t){this._structArray.uint16[this._pos2+9]=t;},r.iconBoxEndIndex.get=function(){return this._structArray.uint16[this._pos2+10]},r.iconBoxEndIndex.set=function(t){this._structArray.uint16[this._pos2+10]=t;},r.featureIndex.get=function(){return this._structArray.uint16[this._pos2+11]},r.featureIndex.set=function(t){this._structArray.uint16[this._pos2+11]=t;},r.numHorizontalGlyphVertices.get=function(){return this._structArray.uint16[this._pos2+12]},r.numHorizontalGlyphVertices.set=function(t){this._structArray.uint16[this._pos2+12]=t;},r.numVerticalGlyphVertices.get=function(){return this._structArray.uint16[this._pos2+13]},r.numVerticalGlyphVertices.set=function(t){this._structArray.uint16[this._pos2+13]=t;},r.numIconVertices.get=function(){return this._structArray.uint16[this._pos2+14]},r.numIconVertices.set=function(t){this._structArray.uint16[this._pos2+14]=t;},r.crossTileID.get=function(){return this._structArray.uint32[this._pos4+8]},r.crossTileID.set=function(t){this._structArray.uint32[this._pos4+8]=t;},r.textBoxScale.get=function(){return this._structArray.float32[this._pos4+9]},r.textBoxScale.set=function(t){this._structArray.float32[this._pos4+9]=t;},r.radialTextOffset.get=function(){return this._structArray.float32[this._pos4+10]},r.radialTextOffset.set=function(t){this._structArray.float32[this._pos4+10]=t;},Object.defineProperties(e.prototype,r),e}(si);Li.prototype.size=44;var Di=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.get=function(t){return new Li(this,t)},e}(Ai);zn(\"SymbolInstanceArray\",Di);var Oi=function(t){function e(){t.apply(this,arguments);}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={offsetX:{configurable:!0}};return r.offsetX.get=function(){return this._structArray.float32[this._pos4+0]},r.offsetX.set=function(t){this._structArray.float32[this._pos4+0]=t;},Object.defineProperties(e.prototype,r),e}(si);Oi.prototype.size=4;var Ri=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getoffsetX=function(t){return this.float32[1*t+0]},e.prototype.get=function(t){return new Oi(this,t)},e}(Si);zn(\"GlyphOffsetArray\",Ri);var Ui=function(t){function e(){t.apply(this,arguments);}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={x:{configurable:!0},y:{configurable:!0},tileUnitDistanceFromAnchor:{configurable:!0}};return r.x.get=function(){return this._structArray.int16[this._pos2+0]},r.x.set=function(t){this._structArray.int16[this._pos2+0]=t;},r.y.get=function(){return this._structArray.int16[this._pos2+1]},r.y.set=function(t){this._structArray.int16[this._pos2+1]=t;},r.tileUnitDistanceFromAnchor.get=function(){return this._structArray.int16[this._pos2+2]},r.tileUnitDistanceFromAnchor.set=function(t){this._structArray.int16[this._pos2+2]=t;},Object.defineProperties(e.prototype,r),e}(si);Ui.prototype.size=6;var ji=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getx=function(t){return this.int16[3*t+0]},e.prototype.gety=function(t){return this.int16[3*t+1]},e.prototype.gettileUnitDistanceFromAnchor=function(t){return this.int16[3*t+2]},e.prototype.get=function(t){return new Ui(this,t)},e}(ki);zn(\"SymbolLineVertexArray\",ji);var qi=function(t){function e(){t.apply(this,arguments);}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={featureIndex:{configurable:!0},sourceLayerIndex:{configurable:!0},bucketIndex:{configurable:!0}};return r.featureIndex.get=function(){return this._structArray.uint32[this._pos4+0]},r.featureIndex.set=function(t){this._structArray.uint32[this._pos4+0]=t;},r.sourceLayerIndex.get=function(){return this._structArray.uint16[this._pos2+2]},r.sourceLayerIndex.set=function(t){this._structArray.uint16[this._pos2+2]=t;},r.bucketIndex.get=function(){return this._structArray.uint16[this._pos2+3]},r.bucketIndex.set=function(t){this._structArray.uint16[this._pos2+3]=t;},Object.defineProperties(e.prototype,r),e}(si);qi.prototype.size=8;var Ni=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.get=function(t){return new qi(this,t)},e}(zi);zn(\"FeatureIndexArray\",Ni);var Zi=li([{name:\"a_pos\",components:2,type:\"Int16\"}],4).members,Ki=function(t){void 0===t&&(t=[]),this.segments=t;};function Gi(t,e){return 256*(t=l(Math.floor(t),0,255))+(e=l(Math.floor(e),0,255))}Ki.prototype.prepareSegment=function(t,e,r,n){var i=this.segments[this.segments.length-1];return t>Ki.MAX_VERTEX_ARRAY_LENGTH&&w(\"Max vertices per segment is \"+Ki.MAX_VERTEX_ARRAY_LENGTH+\": bucket requested \"+t),(!i||i.vertexLength+t>Ki.MAX_VERTEX_ARRAY_LENGTH||i.sortKey!==n)&&(i={vertexOffset:e.length,primitiveOffset:r.length,vertexLength:0,primitiveLength:0},void 0!==n&&(i.sortKey=n),this.segments.push(i)),i},Ki.prototype.get=function(){return this.segments},Ki.prototype.destroy=function(){for(var t=0,e=this.segments;t<e.length;t+=1){var r=e[t];for(var n in r.vaos)r.vaos[n].destroy();}},Ki.simpleSegment=function(t,e,r,n){return new Ki([{vertexOffset:t,primitiveOffset:e,vertexLength:r,primitiveLength:n,vaos:{},sortKey:0}])},Ki.MAX_VERTEX_ARRAY_LENGTH=Math.pow(2,16)-1,zn(\"SegmentVector\",Ki);var Xi=function(){this.ids=[],this.positions=[],this.indexed=!1;};function Ji(t,e,r){var n=t[e];t[e]=t[r],t[r]=n;}Xi.prototype.add=function(t,e,r,n){this.ids.push(t),this.positions.push(e,r,n);},Xi.prototype.getPositions=function(t){for(var e=0,r=this.ids.length-1;e<r;){var n=e+r>>1;this.ids[n]>=t?r=n:e=n+1;}for(var i=[];this.ids[e]===t;){var a=this.positions[3*e],o=this.positions[3*e+1],s=this.positions[3*e+2];i.push({index:a,start:o,end:s}),e++;}return i},Xi.serialize=function(t,e){var r=new Float64Array(t.ids),n=new Uint32Array(t.positions);return function t(e,r,n,i){if(n>=i)return;var a=e[n+i>>1];var o=n-1;var s=i+1;for(;;){do{o++;}while(e[o]<a);do{s--;}while(e[s]>a);if(o>=s)break;Ji(e,o,s),Ji(r,3*o,3*s),Ji(r,3*o+1,3*s+1),Ji(r,3*o+2,3*s+2);}t(e,r,n,s);t(e,r,s+1,i);}(r,n,0,r.length-1),e.push(r.buffer,n.buffer),{ids:r,positions:n}},Xi.deserialize=function(t){var e=new Xi;return e.ids=t.ids,e.positions=t.positions,e.indexed=!0,e},zn(\"FeaturePositionMap\",Xi);var Hi=function(t,e){this.gl=t.gl,this.location=e;},Yi=function(t){function e(e,r){t.call(this,e,r),this.current=0;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){this.current!==t&&(this.current=t,this.gl.uniform1i(this.location,t));},e}(Hi),$i=function(t){function e(e,r){t.call(this,e,r),this.current=0;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){this.current!==t&&(this.current=t,this.gl.uniform1f(this.location,t));},e}(Hi),Wi=function(t){function e(e,r){t.call(this,e,r),this.current=[0,0];}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){t[0]===this.current[0]&&t[1]===this.current[1]||(this.current=t,this.gl.uniform2f(this.location,t[0],t[1]));},e}(Hi),Qi=function(t){function e(e,r){t.call(this,e,r),this.current=[0,0,0];}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){t[0]===this.current[0]&&t[1]===this.current[1]&&t[2]===this.current[2]||(this.current=t,this.gl.uniform3f(this.location,t[0],t[1],t[2]));},e}(Hi),ta=function(t){function e(e,r){t.call(this,e,r),this.current=[0,0,0,0];}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){t[0]===this.current[0]&&t[1]===this.current[1]&&t[2]===this.current[2]&&t[3]===this.current[3]||(this.current=t,this.gl.uniform4f(this.location,t[0],t[1],t[2],t[3]));},e}(Hi),ea=function(t){function e(e,r){t.call(this,e,r),this.current=ae.transparent;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){t.r===this.current.r&&t.g===this.current.g&&t.b===this.current.b&&t.a===this.current.a||(this.current=t,this.gl.uniform4f(this.location,t.r,t.g,t.b,t.a));},e}(Hi),ra=new Float32Array(16),na=function(t){function e(e,r){t.call(this,e,r),this.current=ra;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){if(t[12]!==this.current[12]||t[0]!==this.current[0])return this.current=t,void this.gl.uniformMatrix4fv(this.location,!1,t);for(var e=1;e<16;e++)if(t[e]!==this.current[e]){this.current=t,this.gl.uniformMatrix4fv(this.location,!1,t);break}},e}(Hi);function ia(t){return [Gi(255*t.r,255*t.g),Gi(255*t.b,255*t.a)]}var aa=function(t,e,r){this.value=t,this.names=e,this.uniformNames=this.names.map(function(t){return \"u_\"+t}),this.type=r,this.maxValue=-1/0;};aa.prototype.defines=function(){return this.names.map(function(t){return \"#define HAS_UNIFORM_u_\"+t})},aa.prototype.setConstantPatternPositions=function(){},aa.prototype.populatePaintArray=function(){},aa.prototype.updatePaintArray=function(){},aa.prototype.upload=function(){},aa.prototype.destroy=function(){},aa.prototype.setUniforms=function(t,e,r,n){e.set(n.constantOr(this.value));},aa.prototype.getBinding=function(t,e){return \"color\"===this.type?new ea(t,e):new $i(t,e)},aa.serialize=function(t){var e=t.value,r=t.names,n=t.type;return {value:Bn(e),names:r,type:n}},aa.deserialize=function(t){var e=t.value,r=t.names,n=t.type;return new aa(Cn(e),r,n)};var oa=function(t,e,r){this.value=t,this.names=e,this.uniformNames=this.names.map(function(t){return \"u_\"+t}),this.type=r,this.maxValue=-1/0,this.patternPositions={patternTo:null,patternFrom:null};};oa.prototype.defines=function(){return this.names.map(function(t){return \"#define HAS_UNIFORM_u_\"+t})},oa.prototype.populatePaintArray=function(){},oa.prototype.updatePaintArray=function(){},oa.prototype.upload=function(){},oa.prototype.destroy=function(){},oa.prototype.setConstantPatternPositions=function(t,e){this.patternPositions.patternTo=t.tlbr,this.patternPositions.patternFrom=e.tlbr;},oa.prototype.setUniforms=function(t,e,r,n,i){var a=this.patternPositions;\"u_pattern_to\"===i&&a.patternTo&&e.set(a.patternTo),\"u_pattern_from\"===i&&a.patternFrom&&e.set(a.patternFrom);},oa.prototype.getBinding=function(t,e){return new ta(t,e)};var sa=function(t,e,r,n){this.expression=t,this.names=e,this.type=r,this.uniformNames=this.names.map(function(t){return \"a_\"+t}),this.maxValue=-1/0,this.paintVertexAttributes=e.map(function(t){return {name:\"a_\"+t,type:\"Float32\",components:\"color\"===r?2:1,offset:0}}),this.paintVertexArray=new n;};sa.prototype.defines=function(){return []},sa.prototype.setConstantPatternPositions=function(){},sa.prototype.populatePaintArray=function(t,e){var r=this.paintVertexArray,n=r.length;r.reserve(t);var i=this.expression.evaluate(new Zn(0),e,{});if(\"color\"===this.type)for(var a=ia(i),o=n;o<t;o++)r.emplaceBack(a[0],a[1]);else{for(var s=n;s<t;s++)r.emplaceBack(i);this.maxValue=Math.max(this.maxValue,i);}},sa.prototype.updatePaintArray=function(t,e,r,n){var i=this.paintVertexArray,a=this.expression.evaluate({zoom:0},r,n);if(\"color\"===this.type)for(var o=ia(a),s=t;s<e;s++)i.emplace(s,o[0],o[1]);else{for(var u=t;u<e;u++)i.emplace(u,a);this.maxValue=Math.max(this.maxValue,a);}},sa.prototype.upload=function(t){this.paintVertexArray&&this.paintVertexArray.arrayBuffer&&(this.paintVertexBuffer&&this.paintVertexBuffer.buffer?this.paintVertexBuffer.updateData(this.paintVertexArray):this.paintVertexBuffer=t.createVertexBuffer(this.paintVertexArray,this.paintVertexAttributes,this.expression.isStateDependent));},sa.prototype.destroy=function(){this.paintVertexBuffer&&this.paintVertexBuffer.destroy();},sa.prototype.setUniforms=function(t,e){e.set(0);},sa.prototype.getBinding=function(t,e){return new $i(t,e)};var ua=function(t,e,r,n,i,a){this.expression=t,this.names=e,this.uniformNames=this.names.map(function(t){return \"u_\"+t+\"_t\"}),this.type=r,this.useIntegerZoom=n,this.zoom=i,this.maxValue=-1/0;var o=a;this.paintVertexAttributes=e.map(function(t){return {name:\"a_\"+t,type:\"Float32\",components:\"color\"===r?4:2,offset:0}}),this.paintVertexArray=new o;};ua.prototype.defines=function(){return []},ua.prototype.setConstantPatternPositions=function(){},ua.prototype.populatePaintArray=function(t,e){var r=this.paintVertexArray,n=r.length;r.reserve(t);var i=this.expression.evaluate(new Zn(this.zoom),e,{}),a=this.expression.evaluate(new Zn(this.zoom+1),e,{});if(\"color\"===this.type)for(var o=ia(i),s=ia(a),u=n;u<t;u++)r.emplaceBack(o[0],o[1],s[0],s[1]);else{for(var l=n;l<t;l++)r.emplaceBack(i,a);this.maxValue=Math.max(this.maxValue,i,a);}},ua.prototype.updatePaintArray=function(t,e,r,n){var i=this.paintVertexArray,a=this.expression.evaluate({zoom:this.zoom},r,n),o=this.expression.evaluate({zoom:this.zoom+1},r,n);if(\"color\"===this.type)for(var s=ia(a),u=ia(o),l=t;l<e;l++)i.emplace(l,s[0],s[1],u[0],u[1]);else{for(var p=t;p<e;p++)i.emplace(p,a,o);this.maxValue=Math.max(this.maxValue,a,o);}},ua.prototype.upload=function(t){this.paintVertexArray&&this.paintVertexArray.arrayBuffer&&(this.paintVertexBuffer&&this.paintVertexBuffer.buffer?this.paintVertexBuffer.updateData(this.paintVertexArray):this.paintVertexBuffer=t.createVertexBuffer(this.paintVertexArray,this.paintVertexAttributes,this.expression.isStateDependent));},ua.prototype.destroy=function(){this.paintVertexBuffer&&this.paintVertexBuffer.destroy();},ua.prototype.interpolationFactor=function(t){return this.useIntegerZoom?this.expression.interpolationFactor(Math.floor(t),this.zoom,this.zoom+1):this.expression.interpolationFactor(t,this.zoom,this.zoom+1)},ua.prototype.setUniforms=function(t,e,r){e.set(this.interpolationFactor(r.zoom));},ua.prototype.getBinding=function(t,e){return new $i(t,e)};var la=function(t,e,r,n,i,a,o){this.expression=t,this.names=e,this.type=r,this.uniformNames=this.names.map(function(t){return \"u_\"+t+\"_t\"}),this.useIntegerZoom=n,this.zoom=i,this.maxValue=-1/0,this.layerId=o,this.paintVertexAttributes=e.map(function(t){return {name:\"a_\"+t,type:\"Uint16\",components:4,offset:0}}),this.zoomInPaintVertexArray=new a,this.zoomOutPaintVertexArray=new a;};la.prototype.defines=function(){return []},la.prototype.setConstantPatternPositions=function(){},la.prototype.populatePaintArray=function(t,e,r){var n=this.zoomInPaintVertexArray,i=this.zoomOutPaintVertexArray,a=this.layerId,o=n.length;if(n.reserve(t),i.reserve(t),r&&e.patterns&&e.patterns[a]){var s=e.patterns[a],u=s.min,l=s.mid,p=s.max,c=r[u],h=r[l],f=r[p];if(!c||!h||!f)return;for(var y=o;y<t;y++)n.emplaceBack(h.tl[0],h.tl[1],h.br[0],h.br[1],c.tl[0],c.tl[1],c.br[0],c.br[1]),i.emplaceBack(h.tl[0],h.tl[1],h.br[0],h.br[1],f.tl[0],f.tl[1],f.br[0],f.br[1]);}},la.prototype.updatePaintArray=function(t,e,r,n,i){var a=this.zoomInPaintVertexArray,o=this.zoomOutPaintVertexArray,s=this.layerId;if(i&&r.patterns&&r.patterns[s]){var u=r.patterns[s],l=u.min,p=u.mid,c=u.max,h=i[l],f=i[p],y=i[c];if(!h||!f||!y)return;for(var d=t;d<e;d++)a.emplace(d,f.tl[0],f.tl[1],f.br[0],f.br[1],h.tl[0],h.tl[1],h.br[0],h.br[1]),o.emplace(d,f.tl[0],f.tl[1],f.br[0],f.br[1],y.tl[0],y.tl[1],y.br[0],y.br[1]);}},la.prototype.upload=function(t){this.zoomInPaintVertexArray&&this.zoomInPaintVertexArray.arrayBuffer&&this.zoomOutPaintVertexArray&&this.zoomOutPaintVertexArray.arrayBuffer&&(this.zoomInPaintVertexBuffer=t.createVertexBuffer(this.zoomInPaintVertexArray,this.paintVertexAttributes,this.expression.isStateDependent),this.zoomOutPaintVertexBuffer=t.createVertexBuffer(this.zoomOutPaintVertexArray,this.paintVertexAttributes,this.expression.isStateDependent));},la.prototype.destroy=function(){this.zoomOutPaintVertexBuffer&&this.zoomOutPaintVertexBuffer.destroy(),this.zoomInPaintVertexBuffer&&this.zoomInPaintVertexBuffer.destroy();},la.prototype.setUniforms=function(t,e){e.set(0);},la.prototype.getBinding=function(t,e){return new $i(t,e)};var pa=function(){this.binders={},this.cacheKey=\"\",this._buffers=[],this._featureMap=new Xi,this._bufferOffset=0;};pa.createDynamic=function(t,e,r){var n=new pa,i=[];for(var a in t.paint._values)if(r(a)){var o=t.paint.get(a);if(o instanceof $n&&wr(o.property.specification)){var s=ha(a,t.type),u=o.property.specification.type,l=o.property.useIntegerZoom;if(\"cross-faded\"===o.property.specification[\"property-type\"]||\"cross-faded-data-driven\"===o.property.specification[\"property-type\"])if(\"constant\"===o.value.kind)n.binders[a]=new oa(o.value.value,s,u),i.push(\"/u_\"+a);else{var p=fa(a,u,\"source\");n.binders[a]=new la(o.value,s,u,l,e,p,t.id),i.push(\"/a_\"+a);}else if(\"constant\"===o.value.kind)n.binders[a]=new aa(o.value.value,s,u),i.push(\"/u_\"+a);else if(\"source\"===o.value.kind){var c=fa(a,u,\"source\");n.binders[a]=new sa(o.value,s,u,c),i.push(\"/a_\"+a);}else{var h=fa(a,u,\"composite\");n.binders[a]=new ua(o.value,s,u,l,e,h),i.push(\"/z_\"+a);}}}return n.cacheKey=i.sort().join(\"\"),n},pa.prototype.populatePaintArrays=function(t,e,r,n){for(var i in this.binders){this.binders[i].populatePaintArray(t,e,n);}void 0!==e.id&&this._featureMap.add(+e.id,r,this._bufferOffset,t),this._bufferOffset=t;},pa.prototype.setConstantPatternPositions=function(t,e){for(var r in this.binders){this.binders[r].setConstantPatternPositions(t,e);}},pa.prototype.updatePaintArrays=function(t,e,r,n){var i=!1;for(var a in t)for(var o=0,s=this._featureMap.getPositions(+a);o<s.length;o+=1){var u=s[o],l=e.feature(u.index);for(var p in this.binders){var c=this.binders[p];if(!(c instanceof aa||c instanceof oa)&&!0===c.expression.isStateDependent){var h=r.paint.get(p);c.expression=h.value,c.updatePaintArray(u.start,u.end,l,t[a],n),i=!0;}}}return i},pa.prototype.defines=function(){var t=[];for(var e in this.binders)t.push.apply(t,this.binders[e].defines());return t},pa.prototype.getPaintVertexBuffers=function(){return this._buffers},pa.prototype.getUniforms=function(t,e){var r=[];for(var n in this.binders)for(var i=this.binders[n],a=0,o=i.uniformNames;a<o.length;a+=1){var s=o[a];if(e[s]){var u=i.getBinding(t,e[s]);r.push({name:s,property:n,binding:u});}}return r},pa.prototype.setUniforms=function(t,e,r,n){for(var i=0,a=e;i<a.length;i+=1){var o=a[i],s=o.name,u=o.property,l=o.binding;this.binders[u].setUniforms(t,l,n,r.get(u),s);}},pa.prototype.updatePatternPaintBuffers=function(t){var e=[];for(var r in this.binders){var n=this.binders[r];if(n instanceof la){var i=2===t.fromScale?n.zoomInPaintVertexBuffer:n.zoomOutPaintVertexBuffer;i&&e.push(i);}else(n instanceof sa||n instanceof ua)&&n.paintVertexBuffer&&e.push(n.paintVertexBuffer);}this._buffers=e;},pa.prototype.upload=function(t){for(var e in this.binders)this.binders[e].upload(t);var r=[];for(var n in this.binders){var i=this.binders[n];(i instanceof sa||i instanceof ua)&&i.paintVertexBuffer&&r.push(i.paintVertexBuffer);}this._buffers=r;},pa.prototype.destroy=function(){for(var t in this.binders)this.binders[t].destroy();};var ca=function(t,e,r,n){void 0===n&&(n=function(){return !0}),this.programConfigurations={};for(var i=0,a=e;i<a.length;i+=1){var o=a[i];this.programConfigurations[o.id]=pa.createDynamic(o,r,n),this.programConfigurations[o.id].layoutAttributes=t;}this.needsUpload=!1;};function ha(t,e){return {\"text-opacity\":[\"opacity\"],\"icon-opacity\":[\"opacity\"],\"text-color\":[\"fill_color\"],\"icon-color\":[\"fill_color\"],\"text-halo-color\":[\"halo_color\"],\"icon-halo-color\":[\"halo_color\"],\"text-halo-blur\":[\"halo_blur\"],\"icon-halo-blur\":[\"halo_blur\"],\"text-halo-width\":[\"halo_width\"],\"icon-halo-width\":[\"halo_width\"],\"line-gap-width\":[\"gapwidth\"],\"line-pattern\":[\"pattern_to\",\"pattern_from\"],\"fill-pattern\":[\"pattern_to\",\"pattern_from\"],\"fill-extrusion-pattern\":[\"pattern_to\",\"pattern_from\"]}[t]||[t.replace(e+\"-\",\"\").replace(/-/g,\"_\")]}function fa(t,e,r){var n={color:{source:Ei,composite:Mi},number:{source:Si,composite:Ei}},i=function(t){return {\"line-pattern\":{source:di,composite:di},\"fill-pattern\":{source:di,composite:di},\"fill-extrusion-pattern\":{source:di,composite:di}}[t]}(t);return i&&i[r]||n[e][r]}ca.prototype.populatePaintArrays=function(t,e,r,n){for(var i in this.programConfigurations)this.programConfigurations[i].populatePaintArrays(t,e,r,n);this.needsUpload=!0;},ca.prototype.updatePaintArrays=function(t,e,r,n){for(var i=0,a=r;i<a.length;i+=1){var o=a[i];this.needsUpload=this.programConfigurations[o.id].updatePaintArrays(t,e,o,n)||this.needsUpload;}},ca.prototype.get=function(t){return this.programConfigurations[t]},ca.prototype.upload=function(t){if(this.needsUpload){for(var e in this.programConfigurations)this.programConfigurations[e].upload(t);this.needsUpload=!1;}},ca.prototype.destroy=function(){for(var t in this.programConfigurations)this.programConfigurations[t].destroy();},zn(\"ConstantBinder\",aa),zn(\"CrossFadedConstantBinder\",oa),zn(\"SourceExpressionBinder\",sa),zn(\"CrossFadedCompositeBinder\",la),zn(\"CompositeExpressionBinder\",ua),zn(\"ProgramConfiguration\",pa,{omit:[\"_buffers\"]}),zn(\"ProgramConfigurationSet\",ca);var ya=8192;var da,ma=(da=16,{min:-1*Math.pow(2,da-1),max:Math.pow(2,da-1)-1});function va(t){for(var e=ya/t.extent,r=t.loadGeometry(),n=0;n<r.length;n++)for(var i=r[n],a=0;a<i.length;a++){var o=i[a];o.x=Math.round(o.x*e),o.y=Math.round(o.y*e),(o.x<ma.min||o.x>ma.max||o.y<ma.min||o.y>ma.max)&&w(\"Geometry exceeds allowed extent, reduce your vector tile buffer size\");}return r}function ga(t,e,r,n,i){t.emplaceBack(2*e+(n+1)/2,2*r+(i+1)/2);}var xa=function(t){this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map(function(t){return t.id}),this.index=t.index,this.hasPattern=!1,this.layoutVertexArray=new ci,this.indexArray=new Ii,this.segments=new Ki,this.programConfigurations=new ca(Zi,t.layers,t.zoom),this.stateDependentLayerIds=this.layers.filter(function(t){return t.isStateDependent()}).map(function(t){return t.id});};function ba(t,e){for(var r=0;r<t.length;r++)if(Ca(e,t[r]))return !0;for(var n=0;n<e.length;n++)if(Ca(t,e[n]))return !0;return !!Sa(t,e)}function _a(t,e,r){return !!Ca(t,e)||!!za(e,t,r)}function wa(t,e){if(1===t.length)return Ba(e,t[0]);for(var r=0;r<e.length;r++)for(var n=e[r],i=0;i<n.length;i++)if(Ca(t,n[i]))return !0;for(var a=0;a<t.length;a++)if(Ba(e,t[a]))return !0;for(var o=0;o<e.length;o++)if(Sa(t,e[o]))return !0;return !1}function Aa(t,e,r){if(t.length>1){if(Sa(t,e))return !0;for(var n=0;n<e.length;n++)if(za(e[n],t,r))return !0}for(var i=0;i<t.length;i++)if(za(t[i],e,r))return !0;return !1}function Sa(t,e){if(0===t.length||0===e.length)return !1;for(var r=0;r<t.length-1;r++)for(var n=t[r],i=t[r+1],a=0;a<e.length-1;a++){if(ka(n,i,e[a],e[a+1]))return !0}return !1}function ka(t,e,r,n){return A(t,r,n)!==A(e,r,n)&&A(t,e,r)!==A(t,e,n)}function za(t,e,r){var n=r*r;if(1===e.length)return t.distSqr(e[0])<n;for(var i=1;i<e.length;i++){if(Ia(t,e[i-1],e[i])<n)return !0}return !1}function Ia(t,e,r){var n=e.distSqr(r);if(0===n)return t.distSqr(e);var i=((t.x-e.x)*(r.x-e.x)+(t.y-e.y)*(r.y-e.y))/n;return i<0?t.distSqr(e):i>1?t.distSqr(r):t.distSqr(r.sub(e)._mult(i)._add(e))}function Ba(t,e){for(var r,n,i,a=!1,o=0;o<t.length;o++)for(var s=0,u=(r=t[o]).length-1;s<r.length;u=s++)n=r[s],i=r[u],n.y>e.y!=i.y>e.y&&e.x<(i.x-n.x)*(e.y-n.y)/(i.y-n.y)+n.x&&(a=!a);return a}function Ca(t,e){for(var r=!1,n=0,i=t.length-1;n<t.length;i=n++){var a=t[n],o=t[i];a.y>e.y!=o.y>e.y&&e.x<(o.x-a.x)*(e.y-a.y)/(o.y-a.y)+a.x&&(r=!r);}return r}function Ea(t,e,r){var n=r[0],i=r[2];if(t.x<n.x&&e.x<n.x||t.x>i.x&&e.x>i.x||t.y<n.y&&e.y<n.y||t.y>i.y&&e.y>i.y)return !1;var a=A(t,e,r[0]);return a!==A(t,e,r[1])||a!==A(t,e,r[2])||a!==A(t,e,r[3])}function Ma(t,e,r){var n=e.paint.get(t).value;return \"constant\"===n.kind?n.value:r.programConfigurations.get(e.id).binders[t].maxValue}function Ta(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])}function Pa(t,e,r,n,a){if(!e[0]&&!e[1])return t;var o=i.convert(e)._mult(a);\"viewport\"===r&&o._rotate(-n);for(var s=[],u=0;u<t.length;u++){var l=t[u];s.push(l.sub(o));}return s}xa.prototype.populate=function(t,e){for(var r=0,n=t;r<n.length;r+=1){var i=n[r],a=i.feature,o=i.index,s=i.sourceLayerIndex;if(this.layers[0]._featureFilter(new Zn(this.zoom),a)){var u=va(a);this.addFeature(a,u,o),e.featureIndex.insert(a,u,o,s,this.index);}}},xa.prototype.update=function(t,e,r){this.stateDependentLayers.length&&this.programConfigurations.updatePaintArrays(t,e,this.stateDependentLayers,r);},xa.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length},xa.prototype.uploadPending=function(){return !this.uploaded||this.programConfigurations.needsUpload},xa.prototype.upload=function(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,Zi),this.indexBuffer=t.createIndexBuffer(this.indexArray)),this.programConfigurations.upload(t),this.uploaded=!0;},xa.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy());},xa.prototype.addFeature=function(t,e,r){for(var n=0,i=e;n<i.length;n+=1)for(var a=0,o=i[n];a<o.length;a+=1){var s=o[a],u=s.x,l=s.y;if(!(u<0||u>=ya||l<0||l>=ya)){var p=this.segments.prepareSegment(4,this.layoutVertexArray,this.indexArray),c=p.vertexLength;ga(this.layoutVertexArray,u,l,-1,-1),ga(this.layoutVertexArray,u,l,1,-1),ga(this.layoutVertexArray,u,l,1,1),ga(this.layoutVertexArray,u,l,-1,1),this.indexArray.emplaceBack(c,c+1,c+2),this.indexArray.emplaceBack(c,c+3,c+2),p.vertexLength+=4,p.primitiveLength+=2;}}this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,t,r,{});},zn(\"CircleBucket\",xa,{omit:[\"layers\"]});var Va={paint:new ii({\"circle-radius\":new ti(Lt.paint_circle[\"circle-radius\"]),\"circle-color\":new ti(Lt.paint_circle[\"circle-color\"]),\"circle-blur\":new ti(Lt.paint_circle[\"circle-blur\"]),\"circle-opacity\":new ti(Lt.paint_circle[\"circle-opacity\"]),\"circle-translate\":new Qn(Lt.paint_circle[\"circle-translate\"]),\"circle-translate-anchor\":new Qn(Lt.paint_circle[\"circle-translate-anchor\"]),\"circle-pitch-scale\":new Qn(Lt.paint_circle[\"circle-pitch-scale\"]),\"circle-pitch-alignment\":new Qn(Lt.paint_circle[\"circle-pitch-alignment\"]),\"circle-stroke-width\":new ti(Lt.paint_circle[\"circle-stroke-width\"]),\"circle-stroke-color\":new ti(Lt.paint_circle[\"circle-stroke-color\"]),\"circle-stroke-opacity\":new ti(Lt.paint_circle[\"circle-stroke-opacity\"])})},Fa=1e-6,La=\"undefined\"!=typeof Float32Array?Float32Array:Array;Math.PI;function Da(){var t=new La(9);return La!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function Oa(){var t=new La(3);return La!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Ra(t,e,r){var n=new La(3);return n[0]=t,n[1]=e,n[2]=r,n}function Ua(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],u=r[2];return t[0]=i*u-a*s,t[1]=a*o-n*u,t[2]=n*s-i*o,t}var ja,qa=function(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)};ja=Oa();function Na(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t}!function(){var t,e=(t=new La(4),La!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t);}();function Za(){var t=new La(4);return La!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function Ka(t,e,r,n){var i,a,o,s,u,l=e[0],p=e[1],c=e[2],h=e[3],f=r[0],y=r[1],d=r[2],m=r[3];return (a=l*f+p*y+c*d+h*m)<0&&(a=-a,f=-f,y=-y,d=-d,m=-m),1-a>Fa?(i=Math.acos(a),o=Math.sin(i),s=Math.sin((1-n)*i)/o,u=Math.sin(n*i)/o):(s=1-n,u=n),t[0]=s*l+u*f,t[1]=s*p+u*y,t[2]=s*c+u*d,t[3]=s*h+u*m,t}var Ga,Xa,Ja,Ha,Ya,$a,Wa=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o)),t[0]=r*o,t[1]=n*o,t[2]=i*o,t[3]=a*o,t};Ga=Oa(),Xa=Ra(1,0,0),Ja=Ra(0,1,0),Ha=Za(),Ya=Za(),$a=Da();!function(){var t,e=(t=new La(2),La!=Float32Array&&(t[0]=0,t[1]=0),t);}();var Qa=function(t){function e(e){t.call(this,e,Va);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.createBucket=function(t){return new xa(t)},e.prototype.queryRadius=function(t){var e=t;return Ma(\"circle-radius\",this,e)+Ma(\"circle-stroke-width\",this,e)+Ta(this.paint.get(\"circle-translate\"))},e.prototype.queryIntersectsFeature=function(t,e,r,n,i,a,o,s){for(var u=Pa(t,this.paint.get(\"circle-translate\"),this.paint.get(\"circle-translate-anchor\"),a.angle,o),l=this.paint.get(\"circle-radius\").evaluate(e,r)+this.paint.get(\"circle-stroke-width\").evaluate(e,r),p=\"map\"===this.paint.get(\"circle-pitch-alignment\"),c=p?u:function(t,e){return t.map(function(t){return to(t,e)})}(u,s),h=p?l*o:l,f=0,y=n;f<y.length;f+=1)for(var d=0,m=y[f];d<m.length;d+=1){var v=m[d],g=p?v:to(v,s),x=h,b=Na([],[v.x,v.y,0,1],s);if(\"viewport\"===this.paint.get(\"circle-pitch-scale\")&&\"map\"===this.paint.get(\"circle-pitch-alignment\")?x*=b[3]/a.cameraToCenterDistance:\"map\"===this.paint.get(\"circle-pitch-scale\")&&\"viewport\"===this.paint.get(\"circle-pitch-alignment\")&&(x*=a.cameraToCenterDistance/b[3]),_a(c,g,x))return !0}return !1},e}(ai);function to(t,e){var r=Na([],[t.x,t.y,0,1],e);return new i(r[0]/r[3],r[1]/r[3])}var eo=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(xa);function ro(t,e,r,n){var i=e.width,a=e.height;if(n){if(n instanceof Uint8ClampedArray)n=new Uint8Array(n.buffer);else if(n.length!==i*a*r)throw new RangeError(\"mismatched image size\")}else n=new Uint8Array(i*a*r);return t.width=i,t.height=a,t.data=n,t}function no(t,e,r){var n=e.width,i=e.height;if(n!==t.width||i!==t.height){var a=ro({},{width:n,height:i},r);io(t,a,{x:0,y:0},{x:0,y:0},{width:Math.min(t.width,n),height:Math.min(t.height,i)},r),t.width=n,t.height=i,t.data=a.data;}}function io(t,e,r,n,i,a){if(0===i.width||0===i.height)return e;if(i.width>t.width||i.height>t.height||r.x>t.width-i.width||r.y>t.height-i.height)throw new RangeError(\"out of range source coordinates for image copy\");if(i.width>e.width||i.height>e.height||n.x>e.width-i.width||n.y>e.height-i.height)throw new RangeError(\"out of range destination coordinates for image copy\");for(var o=t.data,s=e.data,u=0;u<i.height;u++)for(var l=((r.y+u)*t.width+r.x)*a,p=((n.y+u)*e.width+n.x)*a,c=0;c<i.width*a;c++)s[p+c]=o[l+c];return e}zn(\"HeatmapBucket\",eo,{omit:[\"layers\"]});var ao=function(t,e){ro(this,t,1,e);};ao.prototype.resize=function(t){no(this,t,1);},ao.prototype.clone=function(){return new ao({width:this.width,height:this.height},new Uint8Array(this.data))},ao.copy=function(t,e,r,n,i){io(t,e,r,n,i,1);};var oo=function(t,e){ro(this,t,4,e);};oo.prototype.resize=function(t){no(this,t,4);},oo.prototype.replace=function(t,e){e?this.data.set(t):t instanceof Uint8ClampedArray?this.data=new Uint8Array(t.buffer):this.data=t;},oo.prototype.clone=function(){return new oo({width:this.width,height:this.height},new Uint8Array(this.data))},oo.copy=function(t,e,r,n,i){io(t,e,r,n,i,4);},zn(\"AlphaImage\",ao),zn(\"RGBAImage\",oo);var so={paint:new ii({\"heatmap-radius\":new ti(Lt.paint_heatmap[\"heatmap-radius\"]),\"heatmap-weight\":new ti(Lt.paint_heatmap[\"heatmap-weight\"]),\"heatmap-intensity\":new Qn(Lt.paint_heatmap[\"heatmap-intensity\"]),\"heatmap-color\":new ni(Lt.paint_heatmap[\"heatmap-color\"]),\"heatmap-opacity\":new Qn(Lt.paint_heatmap[\"heatmap-opacity\"])})};function uo(t,e){for(var r=new Uint8Array(1024),n={},i=0,a=0;i<256;i++,a+=4){n[e]=i/255;var o=t.evaluate(n);r[a+0]=Math.floor(255*o.r/o.a),r[a+1]=Math.floor(255*o.g/o.a),r[a+2]=Math.floor(255*o.b/o.a),r[a+3]=Math.floor(255*o.a);}return new oo({width:256,height:1},r)}var lo=function(t){function e(e){t.call(this,e,so),this._updateColorRamp();}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.createBucket=function(t){return new eo(t)},e.prototype._handleSpecialPaintPropertyUpdate=function(t){\"heatmap-color\"===t&&this._updateColorRamp();},e.prototype._updateColorRamp=function(){var t=this._transitionablePaint._values[\"heatmap-color\"].value.expression;this.colorRamp=uo(t,\"heatmapDensity\"),this.colorRampTexture=null;},e.prototype.resize=function(){this.heatmapFbo&&(this.heatmapFbo.destroy(),this.heatmapFbo=null);},e.prototype.queryRadius=function(){return 0},e.prototype.queryIntersectsFeature=function(){return !1},e.prototype.hasOffscreenPass=function(){return 0!==this.paint.get(\"heatmap-opacity\")&&\"none\"!==this.visibility},e}(ai),po={paint:new ii({\"hillshade-illumination-direction\":new Qn(Lt.paint_hillshade[\"hillshade-illumination-direction\"]),\"hillshade-illumination-anchor\":new Qn(Lt.paint_hillshade[\"hillshade-illumination-anchor\"]),\"hillshade-exaggeration\":new Qn(Lt.paint_hillshade[\"hillshade-exaggeration\"]),\"hillshade-shadow-color\":new Qn(Lt.paint_hillshade[\"hillshade-shadow-color\"]),\"hillshade-highlight-color\":new Qn(Lt.paint_hillshade[\"hillshade-highlight-color\"]),\"hillshade-accent-color\":new Qn(Lt.paint_hillshade[\"hillshade-accent-color\"])})},co=function(t){function e(e){t.call(this,e,po);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.hasOffscreenPass=function(){return 0!==this.paint.get(\"hillshade-exaggeration\")&&\"none\"!==this.visibility},e}(ai),ho=li([{name:\"a_pos\",components:2,type:\"Int16\"}],4).members,fo=mo,yo=mo;function mo(t,e,r){r=r||2;var n,i,a,o,s,u,l,p=e&&e.length,c=p?e[0]*r:t.length,h=vo(t,0,c,r,!0),f=[];if(!h||h.next===h.prev)return f;if(p&&(h=function(t,e,r,n){var i,a,o,s,u,l=[];for(i=0,a=e.length;i<a;i++)o=e[i]*n,s=i<a-1?e[i+1]*n:t.length,(u=vo(t,o,s,n,!1))===u.next&&(u.steiner=!0),l.push(Io(u));for(l.sort(So),i=0;i<l.length;i++)ko(l[i],r),r=go(r,r.next);return r}(t,e,h,r)),t.length>80*r){n=a=t[0],i=o=t[1];for(var y=r;y<c;y+=r)(s=t[y])<n&&(n=s),(u=t[y+1])<i&&(i=u),s>a&&(a=s),u>o&&(o=u);l=0!==(l=Math.max(a-n,o-i))?1/l:0;}return xo(h,f,r,n,i,l),f}function vo(t,e,r,n,i){var a,o;if(i===Oo(t,e,r,n)>0)for(a=e;a<r;a+=n)o=Fo(a,t[a],t[a+1],o);else for(a=r-n;a>=e;a-=n)o=Fo(a,t[a],t[a+1],o);return o&&Mo(o,o.next)&&(Lo(o),o=o.next),o}function go(t,e){if(!t)return t;e||(e=t);var r,n=t;do{if(r=!1,n.steiner||!Mo(n,n.next)&&0!==Eo(n.prev,n,n.next))n=n.next;else{if(Lo(n),(n=e=n.prev)===n.next)break;r=!0;}}while(r||n!==e);return e}function xo(t,e,r,n,i,a,o){if(t){!o&&a&&function(t,e,r,n){var i=t;do{null===i.z&&(i.z=zo(i.x,i.y,e,r,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;}while(i!==t);i.prevZ.nextZ=null,i.prevZ=null,function(t){var e,r,n,i,a,o,s,u,l=1;do{for(r=t,t=null,a=null,o=0;r;){for(o++,n=r,s=0,e=0;e<l&&(s++,n=n.nextZ);e++);for(u=l;s>0||u>0&&n;)0!==s&&(0===u||!n||r.z<=n.z)?(i=r,r=r.nextZ,s--):(i=n,n=n.nextZ,u--),a?a.nextZ=i:t=i,i.prevZ=a,a=i;r=n;}a.nextZ=null,l*=2;}while(o>1)}(i);}(t,n,i,a);for(var s,u,l=t;t.prev!==t.next;)if(s=t.prev,u=t.next,a?_o(t,n,i,a):bo(t))e.push(s.i/r),e.push(t.i/r),e.push(u.i/r),Lo(t),t=u.next,l=u.next;else if((t=u)===l){o?1===o?xo(t=wo(t,e,r),e,r,n,i,a,2):2===o&&Ao(t,e,r,n,i,a):xo(go(t),e,r,n,i,a,1);break}}}function bo(t){var e=t.prev,r=t,n=t.next;if(Eo(e,r,n)>=0)return !1;for(var i=t.next.next;i!==t.prev;){if(Bo(e.x,e.y,r.x,r.y,n.x,n.y,i.x,i.y)&&Eo(i.prev,i,i.next)>=0)return !1;i=i.next;}return !0}function _o(t,e,r,n){var i=t.prev,a=t,o=t.next;if(Eo(i,a,o)>=0)return !1;for(var s=i.x<a.x?i.x<o.x?i.x:o.x:a.x<o.x?a.x:o.x,u=i.y<a.y?i.y<o.y?i.y:o.y:a.y<o.y?a.y:o.y,l=i.x>a.x?i.x>o.x?i.x:o.x:a.x>o.x?a.x:o.x,p=i.y>a.y?i.y>o.y?i.y:o.y:a.y>o.y?a.y:o.y,c=zo(s,u,e,r,n),h=zo(l,p,e,r,n),f=t.prevZ,y=t.nextZ;f&&f.z>=c&&y&&y.z<=h;){if(f!==t.prev&&f!==t.next&&Bo(i.x,i.y,a.x,a.y,o.x,o.y,f.x,f.y)&&Eo(f.prev,f,f.next)>=0)return !1;if(f=f.prevZ,y!==t.prev&&y!==t.next&&Bo(i.x,i.y,a.x,a.y,o.x,o.y,y.x,y.y)&&Eo(y.prev,y,y.next)>=0)return !1;y=y.nextZ;}for(;f&&f.z>=c;){if(f!==t.prev&&f!==t.next&&Bo(i.x,i.y,a.x,a.y,o.x,o.y,f.x,f.y)&&Eo(f.prev,f,f.next)>=0)return !1;f=f.prevZ;}for(;y&&y.z<=h;){if(y!==t.prev&&y!==t.next&&Bo(i.x,i.y,a.x,a.y,o.x,o.y,y.x,y.y)&&Eo(y.prev,y,y.next)>=0)return !1;y=y.nextZ;}return !0}function wo(t,e,r){var n=t;do{var i=n.prev,a=n.next.next;!Mo(i,a)&&To(i,n,n.next,a)&&Po(i,a)&&Po(a,i)&&(e.push(i.i/r),e.push(n.i/r),e.push(a.i/r),Lo(n),Lo(n.next),n=t=a),n=n.next;}while(n!==t);return n}function Ao(t,e,r,n,i,a){var o=t;do{for(var s=o.next.next;s!==o.prev;){if(o.i!==s.i&&Co(o,s)){var u=Vo(o,s);return o=go(o,o.next),u=go(u,u.next),xo(o,e,r,n,i,a),void xo(u,e,r,n,i,a)}s=s.next;}o=o.next;}while(o!==t)}function So(t,e){return t.x-e.x}function ko(t,e){if(e=function(t,e){var r,n=e,i=t.x,a=t.y,o=-1/0;do{if(a<=n.y&&a>=n.next.y&&n.next.y!==n.y){var s=n.x+(a-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(s<=i&&s>o){if(o=s,s===i){if(a===n.y)return n;if(a===n.next.y)return n.next}r=n.x<n.next.x?n:n.next;}}n=n.next;}while(n!==e);if(!r)return null;if(i===o)return r.prev;var u,l=r,p=r.x,c=r.y,h=1/0;n=r.next;for(;n!==l;)i>=n.x&&n.x>=p&&i!==n.x&&Bo(a<c?i:o,a,p,c,a<c?o:i,a,n.x,n.y)&&((u=Math.abs(a-n.y)/(i-n.x))<h||u===h&&n.x>r.x)&&Po(n,t)&&(r=n,h=u),n=n.next;return r}(t,e)){var r=Vo(e,t);go(r,r.next);}}function zo(t,e,r,n,i){return (t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-r)*i)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-n)*i)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Io(t){var e=t,r=t;do{(e.x<r.x||e.x===r.x&&e.y<r.y)&&(r=e),e=e.next;}while(e!==t);return r}function Bo(t,e,r,n,i,a,o,s){return (i-o)*(e-s)-(t-o)*(a-s)>=0&&(t-o)*(n-s)-(r-o)*(e-s)>=0&&(r-o)*(a-s)-(i-o)*(n-s)>=0}function Co(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==e.i&&r.next.i!==e.i&&To(r,r.next,t,e))return !0;r=r.next;}while(r!==t);return !1}(t,e)&&Po(t,e)&&Po(e,t)&&function(t,e){var r=t,n=!1,i=(t.x+e.x)/2,a=(t.y+e.y)/2;do{r.y>a!=r.next.y>a&&r.next.y!==r.y&&i<(r.next.x-r.x)*(a-r.y)/(r.next.y-r.y)+r.x&&(n=!n),r=r.next;}while(r!==t);return n}(t,e)}function Eo(t,e,r){return (e.y-t.y)*(r.x-e.x)-(e.x-t.x)*(r.y-e.y)}function Mo(t,e){return t.x===e.x&&t.y===e.y}function To(t,e,r,n){return !!(Mo(t,e)&&Mo(r,n)||Mo(t,n)&&Mo(r,e))||Eo(t,e,r)>0!=Eo(t,e,n)>0&&Eo(r,n,t)>0!=Eo(r,n,e)>0}function Po(t,e){return Eo(t.prev,t,t.next)<0?Eo(t,e,t.next)>=0&&Eo(t,t.prev,e)>=0:Eo(t,e,t.prev)<0||Eo(t,t.next,e)<0}function Vo(t,e){var r=new Do(t.i,t.x,t.y),n=new Do(e.i,e.x,e.y),i=t.next,a=e.prev;return t.next=e,e.prev=t,r.next=i,i.prev=r,n.next=r,r.prev=n,a.next=n,n.prev=a,n}function Fo(t,e,r,n){var i=new Do(t,e,r);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function Lo(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ);}function Do(t,e,r){this.i=t,this.x=e,this.y=r,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1;}function Oo(t,e,r,n){for(var i=0,a=e,o=r-n;a<r;a+=n)i+=(t[o]-t[a])*(t[a+1]+t[o+1]),o=a;return i}function Ro(t,e,r,n,i){!function t(e,r,n,i,a){for(;i>n;){if(i-n>600){var o=i-n+1,s=r-n+1,u=Math.log(o),l=.5*Math.exp(2*u/3),p=.5*Math.sqrt(u*l*(o-l)/o)*(s-o/2<0?-1:1),c=Math.max(n,Math.floor(r-s*l/o+p)),h=Math.min(i,Math.floor(r+(o-s)*l/o+p));t(e,r,c,h,a);}var f=e[r],y=n,d=i;for(Uo(e,n,r),a(e[i],f)>0&&Uo(e,n,i);y<d;){for(Uo(e,y,d),y++,d--;a(e[y],f)<0;)y++;for(;a(e[d],f)>0;)d--;}0===a(e[n],f)?Uo(e,n,d):Uo(e,++d,i),d<=r&&(n=d+1),r<=d&&(i=d-1);}}(t,e,r||0,n||t.length-1,i||jo);}function Uo(t,e,r){var n=t[e];t[e]=t[r],t[r]=n;}function jo(t,e){return t<e?-1:t>e?1:0}function qo(t,e){var r=t.length;if(r<=1)return [t];for(var n,i,a=[],o=0;o<r;o++){var s=S(t[o]);0!==s&&(t[o].area=Math.abs(s),void 0===i&&(i=s<0),i===s<0?(n&&a.push(n),n=[t[o]]):n.push(t[o]));}if(n&&a.push(n),e>1)for(var u=0;u<a.length;u++)a[u].length<=e||(Ro(a[u],e,1,a[u].length-1,No),a[u]=a[u].slice(0,e));return a}function No(t,e){return e.area-t.area}function Zo(t,e,r){for(var n=r.patternDependencies,i=!1,a=0,o=e;a<o.length;a+=1){var s=o[a].paint.get(t+\"-pattern\");s.isConstant()||(i=!0);var u=s.constantOr(null);u&&(i=!0,n[u.to]=!0,n[u.from]=!0);}return i}function Ko(t,e,r,n,i){for(var a=i.patternDependencies,o=0,s=e;o<s.length;o+=1){var u=s[o],l=u.paint.get(t+\"-pattern\").value;if(\"constant\"!==l.kind){var p=l.evaluate({zoom:n-1},r,{}),c=l.evaluate({zoom:n},r,{}),h=l.evaluate({zoom:n+1},r,{});a[p]=!0,a[c]=!0,a[h]=!0,r.patterns[u.id]={min:p,mid:c,max:h};}}return r}mo.deviation=function(t,e,r,n){var i=e&&e.length,a=i?e[0]*r:t.length,o=Math.abs(Oo(t,0,a,r));if(i)for(var s=0,u=e.length;s<u;s++){var l=e[s]*r,p=s<u-1?e[s+1]*r:t.length;o-=Math.abs(Oo(t,l,p,r));}var c=0;for(s=0;s<n.length;s+=3){var h=n[s]*r,f=n[s+1]*r,y=n[s+2]*r;c+=Math.abs((t[h]-t[y])*(t[f+1]-t[h+1])-(t[h]-t[f])*(t[y+1]-t[h+1]));}return 0===o&&0===c?0:Math.abs((c-o)/o)},mo.flatten=function(t){for(var e=t[0][0].length,r={vertices:[],holes:[],dimensions:e},n=0,i=0;i<t.length;i++){for(var a=0;a<t[i].length;a++)for(var o=0;o<e;o++)r.vertices.push(t[i][a][o]);i>0&&(n+=t[i-1].length,r.holes.push(n));}return r},fo.default=yo;var Go=function(t){this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map(function(t){return t.id}),this.index=t.index,this.hasPattern=!1,this.layoutVertexArray=new ci,this.indexArray=new Ii,this.indexArray2=new Bi,this.programConfigurations=new ca(ho,t.layers,t.zoom),this.segments=new Ki,this.segments2=new Ki,this.stateDependentLayerIds=this.layers.filter(function(t){return t.isStateDependent()}).map(function(t){return t.id});};Go.prototype.populate=function(t,e){this.features=[],this.hasPattern=Zo(\"fill\",this.layers,e);for(var r=0,n=t;r<n.length;r+=1){var i=n[r],a=i.feature,o=i.index,s=i.sourceLayerIndex;if(this.layers[0]._featureFilter(new Zn(this.zoom),a)){var u=va(a),l={sourceLayerIndex:s,index:o,geometry:u,properties:a.properties,type:a.type,patterns:{}};void 0!==a.id&&(l.id=a.id),this.hasPattern?this.features.push(Ko(\"fill\",this.layers,l,this.zoom,e)):this.addFeature(l,u,o,{}),e.featureIndex.insert(a,u,o,s,this.index);}}},Go.prototype.update=function(t,e,r){this.stateDependentLayers.length&&this.programConfigurations.updatePaintArrays(t,e,this.stateDependentLayers,r);},Go.prototype.addFeatures=function(t,e){for(var r=0,n=this.features;r<n.length;r+=1){var i=n[r],a=i.geometry;this.addFeature(i,a,i.index,e);}},Go.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length},Go.prototype.uploadPending=function(){return !this.uploaded||this.programConfigurations.needsUpload},Go.prototype.upload=function(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,ho),this.indexBuffer=t.createIndexBuffer(this.indexArray),this.indexBuffer2=t.createIndexBuffer(this.indexArray2)),this.programConfigurations.upload(t),this.uploaded=!0;},Go.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.indexBuffer2.destroy(),this.programConfigurations.destroy(),this.segments.destroy(),this.segments2.destroy());},Go.prototype.addFeature=function(t,e,r,n){for(var i=0,a=qo(e,500);i<a.length;i+=1){for(var o=a[i],s=0,u=0,l=o;u<l.length;u+=1){s+=l[u].length;}for(var p=this.segments.prepareSegment(s,this.layoutVertexArray,this.indexArray),c=p.vertexLength,h=[],f=[],y=0,d=o;y<d.length;y+=1){var m=d[y];if(0!==m.length){m!==o[0]&&f.push(h.length/2);var v=this.segments2.prepareSegment(m.length,this.layoutVertexArray,this.indexArray2),g=v.vertexLength;this.layoutVertexArray.emplaceBack(m[0].x,m[0].y),this.indexArray2.emplaceBack(g+m.length-1,g),h.push(m[0].x),h.push(m[0].y);for(var x=1;x<m.length;x++)this.layoutVertexArray.emplaceBack(m[x].x,m[x].y),this.indexArray2.emplaceBack(g+x-1,g+x),h.push(m[x].x),h.push(m[x].y);v.vertexLength+=m.length,v.primitiveLength+=m.length;}}for(var b=fo(h,f),_=0;_<b.length;_+=3)this.indexArray.emplaceBack(c+b[_],c+b[_+1],c+b[_+2]);p.vertexLength+=s,p.primitiveLength+=b.length/3;}this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,t,r,n);},zn(\"FillBucket\",Go,{omit:[\"layers\",\"features\"]});var Xo={paint:new ii({\"fill-antialias\":new Qn(Lt.paint_fill[\"fill-antialias\"]),\"fill-opacity\":new ti(Lt.paint_fill[\"fill-opacity\"]),\"fill-color\":new ti(Lt.paint_fill[\"fill-color\"]),\"fill-outline-color\":new ti(Lt.paint_fill[\"fill-outline-color\"]),\"fill-translate\":new Qn(Lt.paint_fill[\"fill-translate\"]),\"fill-translate-anchor\":new Qn(Lt.paint_fill[\"fill-translate-anchor\"]),\"fill-pattern\":new ei(Lt.paint_fill[\"fill-pattern\"])})},Jo=function(t){function e(e){t.call(this,e,Xo);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.recalculate=function(e){t.prototype.recalculate.call(this,e);var r=this.paint._values[\"fill-outline-color\"];\"constant\"===r.value.kind&&void 0===r.value.value&&(this.paint._values[\"fill-outline-color\"]=this.paint._values[\"fill-color\"]);},e.prototype.createBucket=function(t){return new Go(t)},e.prototype.queryRadius=function(){return Ta(this.paint.get(\"fill-translate\"))},e.prototype.queryIntersectsFeature=function(t,e,r,n,i,a,o){return wa(Pa(t,this.paint.get(\"fill-translate\"),this.paint.get(\"fill-translate-anchor\"),a.angle,o),n)},e.prototype.isTileClipped=function(){return !0},e}(ai),Ho=li([{name:\"a_pos\",components:2,type:\"Int16\"},{name:\"a_normal_ed\",components:4,type:\"Int16\"}],4).members,Yo=$o;function $o(t,e,r,n,i){this.properties={},this.extent=r,this.type=0,this._pbf=t,this._geometry=-1,this._keys=n,this._values=i,t.readFields(Wo,this,e);}function Wo(t,e,r){1==t?e.id=r.readVarint():2==t?function(t,e){var r=t.readVarint()+t.pos;for(;t.pos<r;){var n=e._keys[t.readVarint()],i=e._values[t.readVarint()];e.properties[n]=i;}}(r,e):3==t?e.type=r.readVarint():4==t&&(e._geometry=r.pos);}function Qo(t){for(var e,r,n=0,i=0,a=t.length,o=a-1;i<a;o=i++)e=t[i],n+=((r=t[o]).x-e.x)*(e.y+r.y);return n}$o.types=[\"Unknown\",\"Point\",\"LineString\",\"Polygon\"],$o.prototype.loadGeometry=function(){var t=this._pbf;t.pos=this._geometry;for(var e,r=t.readVarint()+t.pos,n=1,a=0,o=0,s=0,u=[];t.pos<r;){if(a<=0){var l=t.readVarint();n=7&l,a=l>>3;}if(a--,1===n||2===n)o+=t.readSVarint(),s+=t.readSVarint(),1===n&&(e&&u.push(e),e=[]),e.push(new i(o,s));else{if(7!==n)throw new Error(\"unknown command \"+n);e&&e.push(e[0].clone());}}return e&&u.push(e),u},$o.prototype.bbox=function(){var t=this._pbf;t.pos=this._geometry;for(var e=t.readVarint()+t.pos,r=1,n=0,i=0,a=0,o=1/0,s=-1/0,u=1/0,l=-1/0;t.pos<e;){if(n<=0){var p=t.readVarint();r=7&p,n=p>>3;}if(n--,1===r||2===r)(i+=t.readSVarint())<o&&(o=i),i>s&&(s=i),(a+=t.readSVarint())<u&&(u=a),a>l&&(l=a);else if(7!==r)throw new Error(\"unknown command \"+r)}return [o,u,s,l]},$o.prototype.toGeoJSON=function(t,e,r){var n,i,a=this.extent*Math.pow(2,r),o=this.extent*t,s=this.extent*e,u=this.loadGeometry(),l=$o.types[this.type];function p(t){for(var e=0;e<t.length;e++){var r=t[e],n=180-360*(r.y+s)/a;t[e]=[360*(r.x+o)/a-180,360/Math.PI*Math.atan(Math.exp(n*Math.PI/180))-90];}}switch(this.type){case 1:var c=[];for(n=0;n<u.length;n++)c[n]=u[n][0];p(u=c);break;case 2:for(n=0;n<u.length;n++)p(u[n]);break;case 3:for(u=function(t){var e=t.length;if(e<=1)return [t];for(var r,n,i=[],a=0;a<e;a++){var o=Qo(t[a]);0!==o&&(void 0===n&&(n=o<0),n===o<0?(r&&i.push(r),r=[t[a]]):r.push(t[a]));}r&&i.push(r);return i}(u),n=0;n<u.length;n++)for(i=0;i<u[n].length;i++)p(u[n][i]);}1===u.length?u=u[0]:l=\"Multi\"+l;var h={type:\"Feature\",geometry:{type:l,coordinates:u},properties:this.properties};return \"id\"in this&&(h.id=this.id),h};var ts=es;function es(t,e){this.version=1,this.name=null,this.extent=4096,this.length=0,this._pbf=t,this._keys=[],this._values=[],this._features=[],t.readFields(rs,this,e),this.length=this._features.length;}function rs(t,e,r){15===t?e.version=r.readVarint():1===t?e.name=r.readString():5===t?e.extent=r.readVarint():2===t?e._features.push(r.pos):3===t?e._keys.push(r.readString()):4===t&&e._values.push(function(t){var e=null,r=t.readVarint()+t.pos;for(;t.pos<r;){var n=t.readVarint()>>3;e=1===n?t.readString():2===n?t.readFloat():3===n?t.readDouble():4===n?t.readVarint64():5===n?t.readVarint():6===n?t.readSVarint():7===n?t.readBoolean():null;}return e}(r));}function ns(t,e,r){if(3===t){var n=new ts(r,r.readVarint()+r.pos);n.length&&(e[n.name]=n);}}es.prototype.feature=function(t){if(t<0||t>=this._features.length)throw new Error(\"feature index out of bounds\");this._pbf.pos=this._features[t];var e=this._pbf.readVarint()+this._pbf.pos;return new Yo(this._pbf,e,this.extent,this._keys,this._values)};var is={VectorTile:function(t,e){this.layers=t.readFields(ns,{},e);},VectorTileFeature:Yo,VectorTileLayer:ts},as=is.VectorTileFeature.types,os=Math.pow(2,13);function ss(t,e,r,n,i,a,o,s){t.emplaceBack(e,r,2*Math.floor(n*os)+o,i*os*2,a*os*2,Math.round(s));}var us=function(t){this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map(function(t){return t.id}),this.index=t.index,this.hasPattern=!1,this.layoutVertexArray=new fi,this.indexArray=new Ii,this.programConfigurations=new ca(Ho,t.layers,t.zoom),this.segments=new Ki,this.stateDependentLayerIds=this.layers.filter(function(t){return t.isStateDependent()}).map(function(t){return t.id});};function ls(t,e){return t.x===e.x&&(t.x<0||t.x>ya)||t.y===e.y&&(t.y<0||t.y>ya)}function ps(t){return t.every(function(t){return t.x<0})||t.every(function(t){return t.x>ya})||t.every(function(t){return t.y<0})||t.every(function(t){return t.y>ya})}us.prototype.populate=function(t,e){this.features=[],this.hasPattern=Zo(\"fill-extrusion\",this.layers,e);for(var r=0,n=t;r<n.length;r+=1){var i=n[r],a=i.feature,o=i.index,s=i.sourceLayerIndex;if(this.layers[0]._featureFilter(new Zn(this.zoom),a)){var u=va(a),l={sourceLayerIndex:s,index:o,geometry:u,properties:a.properties,type:a.type,patterns:{}};void 0!==a.id&&(l.id=a.id),this.hasPattern?this.features.push(Ko(\"fill-extrusion\",this.layers,l,this.zoom,e)):this.addFeature(l,u,o,{}),e.featureIndex.insert(a,u,o,s,this.index,!0);}}},us.prototype.addFeatures=function(t,e){for(var r=0,n=this.features;r<n.length;r+=1){var i=n[r],a=i.geometry;this.addFeature(i,a,i.index,e);}},us.prototype.update=function(t,e,r){this.stateDependentLayers.length&&this.programConfigurations.updatePaintArrays(t,e,this.stateDependentLayers,r);},us.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length},us.prototype.uploadPending=function(){return !this.uploaded||this.programConfigurations.needsUpload},us.prototype.upload=function(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,Ho),this.indexBuffer=t.createIndexBuffer(this.indexArray)),this.programConfigurations.upload(t),this.uploaded=!0;},us.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy());},us.prototype.addFeature=function(t,e,r,n){for(var i=0,a=qo(e,500);i<a.length;i+=1){for(var o=a[i],s=0,u=0,l=o;u<l.length;u+=1){s+=l[u].length;}for(var p=this.segments.prepareSegment(4,this.layoutVertexArray,this.indexArray),c=0,h=o;c<h.length;c+=1){var f=h[c];if(0!==f.length&&!ps(f))for(var y=0,d=0;d<f.length;d++){var m=f[d];if(d>=1){var v=f[d-1];if(!ls(m,v)){p.vertexLength+4>Ki.MAX_VERTEX_ARRAY_LENGTH&&(p=this.segments.prepareSegment(4,this.layoutVertexArray,this.indexArray));var g=m.sub(v)._perp()._unit(),x=v.dist(m);y+x>32768&&(y=0),ss(this.layoutVertexArray,m.x,m.y,g.x,g.y,0,0,y),ss(this.layoutVertexArray,m.x,m.y,g.x,g.y,0,1,y),y+=x,ss(this.layoutVertexArray,v.x,v.y,g.x,g.y,0,0,y),ss(this.layoutVertexArray,v.x,v.y,g.x,g.y,0,1,y);var b=p.vertexLength;this.indexArray.emplaceBack(b,b+2,b+1),this.indexArray.emplaceBack(b+1,b+2,b+3),p.vertexLength+=4,p.primitiveLength+=2;}}}}if(p.vertexLength+s>Ki.MAX_VERTEX_ARRAY_LENGTH&&(p=this.segments.prepareSegment(s,this.layoutVertexArray,this.indexArray)),\"Polygon\"===as[t.type]){for(var _=[],w=[],A=p.vertexLength,S=0,k=o;S<k.length;S+=1){var z=k[S];if(0!==z.length){z!==o[0]&&w.push(_.length/2);for(var I=0;I<z.length;I++){var B=z[I];ss(this.layoutVertexArray,B.x,B.y,0,0,1,1,0),_.push(B.x),_.push(B.y);}}}for(var C=fo(_,w),E=0;E<C.length;E+=3)this.indexArray.emplaceBack(A+C[E],A+C[E+2],A+C[E+1]);p.primitiveLength+=C.length/3,p.vertexLength+=s;}}this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,t,r,n);},zn(\"FillExtrusionBucket\",us,{omit:[\"layers\",\"features\"]});var cs={paint:new ii({\"fill-extrusion-opacity\":new Qn(Lt[\"paint_fill-extrusion\"][\"fill-extrusion-opacity\"]),\"fill-extrusion-color\":new ti(Lt[\"paint_fill-extrusion\"][\"fill-extrusion-color\"]),\"fill-extrusion-translate\":new Qn(Lt[\"paint_fill-extrusion\"][\"fill-extrusion-translate\"]),\"fill-extrusion-translate-anchor\":new Qn(Lt[\"paint_fill-extrusion\"][\"fill-extrusion-translate-anchor\"]),\"fill-extrusion-pattern\":new ei(Lt[\"paint_fill-extrusion\"][\"fill-extrusion-pattern\"]),\"fill-extrusion-height\":new ti(Lt[\"paint_fill-extrusion\"][\"fill-extrusion-height\"]),\"fill-extrusion-base\":new ti(Lt[\"paint_fill-extrusion\"][\"fill-extrusion-base\"]),\"fill-extrusion-vertical-gradient\":new Qn(Lt[\"paint_fill-extrusion\"][\"fill-extrusion-vertical-gradient\"])})},hs=function(t){function e(e){t.call(this,e,cs);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.createBucket=function(t){return new us(t)},e.prototype.queryRadius=function(){return Ta(this.paint.get(\"fill-extrusion-translate\"))},e.prototype.is3D=function(){return !0},e.prototype.queryIntersectsFeature=function(t,e,r,n,a,o,s,u){var l=Pa(t,this.paint.get(\"fill-extrusion-translate\"),this.paint.get(\"fill-extrusion-translate-anchor\"),o.angle,s),p=this.paint.get(\"fill-extrusion-height\").evaluate(e,r),c=this.paint.get(\"fill-extrusion-base\").evaluate(e,r),h=function(t,e,r,n){for(var a=[],o=0,s=t;o<s.length;o+=1){var u=s[o],l=[u.x,u.y,n,1];Na(l,l,e),a.push(new i(l[0]/l[3],l[1]/l[3]));}return a}(l,u,0,0),f=function(t,e,r,n){for(var a=[],o=[],s=n[8]*e,u=n[9]*e,l=n[10]*e,p=n[11]*e,c=n[8]*r,h=n[9]*r,f=n[10]*r,y=n[11]*r,d=0,m=t;d<m.length;d+=1){for(var v=m[d],g=[],x=[],b=0,_=v;b<_.length;b+=1){var w=_[b],A=w.x,S=w.y,k=n[0]*A+n[4]*S+n[12],z=n[1]*A+n[5]*S+n[13],I=n[2]*A+n[6]*S+n[14],B=n[3]*A+n[7]*S+n[15],C=k+s,E=z+u,M=I+l,T=B+p,P=k+c,V=z+h,F=I+f,L=B+y,D=new i(C/T,E/T);D.z=M/T,g.push(D);var O=new i(P/L,V/L);O.z=F/L,x.push(O);}a.push(g),o.push(x);}return [a,o]}(n,c,p,u);return function(t,e,r){var n=1/0;wa(r,e)&&(n=ys(r,e[0]));for(var i=0;i<e.length;i++)for(var a=e[i],o=t[i],s=0;s<a.length-1;s++){var u=a[s],l=a[s+1],p=o[s],c=o[s+1],h=[u,l,c,p,u];ba(r,h)&&(n=Math.min(n,ys(r,h)));}return n!==1/0&&n}(f[0],f[1],h)},e}(ai);function fs(t,e){return t.x*e.x+t.y*e.y}function ys(t,e){if(1===t.length){var r=e[0],n=e[1],i=e[3],a=t[0],o=n.sub(r),s=i.sub(r),u=a.sub(r),l=fs(o,o),p=fs(o,s),c=fs(s,s),h=fs(u,o),f=fs(u,s),y=l*c-p*p,d=(c*h-p*f)/y,m=(l*f-p*h)/y,v=1-d-m;return r.z*v+n.z*d+i.z*m}for(var g=1/0,x=0,b=e;x<b.length;x+=1){var _=b[x];g=Math.min(g,_.z);}return g}var ds=li([{name:\"a_pos_normal\",components:2,type:\"Int16\"},{name:\"a_data\",components:4,type:\"Uint8\"}],4).members,ms=is.VectorTileFeature.types,vs=63,gs=Math.cos(Math.PI/180*37.5),xs=.5,bs=Math.pow(2,14)/xs;function _s(t,e,r,n,i,a,o){t.emplaceBack((e.x<<1)+(n?1:0),(e.y<<1)+(i?1:0),Math.round(vs*r.x)+128,Math.round(vs*r.y)+128,1+(0===a?0:a<0?-1:1)|(o*xs&63)<<2,o*xs>>6);}var ws=function(t){this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map(function(t){return t.id}),this.index=t.index,this.features=[],this.hasPattern=!1,this.layoutVertexArray=new yi,this.indexArray=new Ii,this.programConfigurations=new ca(ds,t.layers,t.zoom),this.segments=new Ki,this.stateDependentLayerIds=this.layers.filter(function(t){return t.isStateDependent()}).map(function(t){return t.id});};function As(t,e){return (t/e.tileTotal*(e.end-e.start)+e.start)*(bs-1)}ws.prototype.populate=function(t,e){this.features=[],this.hasPattern=Zo(\"line\",this.layers,e);for(var r=0,n=t;r<n.length;r+=1){var i=n[r],a=i.feature,o=i.index,s=i.sourceLayerIndex;if(this.layers[0]._featureFilter(new Zn(this.zoom),a)){var u=va(a),l={sourceLayerIndex:s,index:o,geometry:u,properties:a.properties,type:a.type,patterns:{}};void 0!==a.id&&(l.id=a.id),this.hasPattern?this.features.push(Ko(\"line\",this.layers,l,this.zoom,e)):this.addFeature(l,u,o,{}),e.featureIndex.insert(a,u,o,s,this.index);}}},ws.prototype.update=function(t,e,r){this.stateDependentLayers.length&&this.programConfigurations.updatePaintArrays(t,e,this.stateDependentLayers,r);},ws.prototype.addFeatures=function(t,e){for(var r=0,n=this.features;r<n.length;r+=1){var i=n[r],a=i.geometry;this.addFeature(i,a,i.index,e);}},ws.prototype.isEmpty=function(){return 0===this.layoutVertexArray.length},ws.prototype.uploadPending=function(){return !this.uploaded||this.programConfigurations.needsUpload},ws.prototype.upload=function(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,ds),this.indexBuffer=t.createIndexBuffer(this.indexArray)),this.programConfigurations.upload(t),this.uploaded=!0;},ws.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy());},ws.prototype.addFeature=function(t,e,r,n){for(var i=this.layers[0].layout,a=i.get(\"line-join\").evaluate(t,{}),o=i.get(\"line-cap\"),s=i.get(\"line-miter-limit\"),u=i.get(\"line-round-limit\"),l=0,p=e;l<p.length;l+=1){var c=p[l];this.addLine(c,t,a,o,s,u,r,n);}},ws.prototype.addLine=function(t,e,r,n,i,a,o,s){var u=null;e.properties&&e.properties.hasOwnProperty(\"mapbox_clip_start\")&&e.properties.hasOwnProperty(\"mapbox_clip_end\")&&(u={start:e.properties.mapbox_clip_start,end:e.properties.mapbox_clip_end,tileTotal:void 0});for(var l=\"Polygon\"===ms[e.type],p=t.length;p>=2&&t[p-1].equals(t[p-2]);)p--;for(var c=0;c<p-1&&t[c].equals(t[c+1]);)c++;if(!(p<(l?3:2))){u&&(u.tileTotal=function(t,e,r){for(var n,i,a=0,o=e;o<r-1;o++)n=t[o],i=t[o+1],a+=n.dist(i);return a}(t,c,p)),\"bevel\"===r&&(i=1.05);var h=ya/(512*this.overscaling)*15,f=t[c],y=this.segments.prepareSegment(10*p,this.layoutVertexArray,this.indexArray);this.distance=0;var d,m,v,g=n,x=l?\"butt\":n,b=!0,_=void 0,w=void 0,A=void 0,S=void 0;this.e1=this.e2=this.e3=-1,l&&(d=t[p-2],S=f.sub(d)._unit()._perp());for(var k=c;k<p;k++)if(!(w=l&&k===p-1?t[c+1]:t[k+1])||!t[k].equals(w)){S&&(A=S),d&&(_=d),d=t[k],S=w?w.sub(d)._unit()._perp():A;var z=(A=A||S).add(S);0===z.x&&0===z.y||z._unit();var I=z.x*S.x+z.y*S.y,B=0!==I?1/I:1/0,C=I<gs&&_&&w;if(C&&k>c){var E=d.dist(_);if(E>2*h){var M=d.sub(d.sub(_)._mult(h/E)._round());this.distance+=M.dist(_),this.addCurrentVertex(M,this.distance,A.mult(1),0,0,!1,y,u),_=M;}}var T=_&&w,P=T?r:w?g:x;if(T&&\"round\"===P&&(B<a?P=\"miter\":B<=2&&(P=\"fakeround\")),\"miter\"===P&&B>i&&(P=\"bevel\"),\"bevel\"===P&&(B>2&&(P=\"flipbevel\"),B<i&&(P=\"miter\")),_&&(this.distance+=d.dist(_)),\"miter\"===P)z._mult(B),this.addCurrentVertex(d,this.distance,z,0,0,!1,y,u);else if(\"flipbevel\"===P){if(B>100)z=S.clone().mult(-1);else{var V=A.x*S.y-A.y*S.x>0?-1:1,F=B*A.add(S).mag()/A.sub(S).mag();z._perp()._mult(F*V);}this.addCurrentVertex(d,this.distance,z,0,0,!1,y,u),this.addCurrentVertex(d,this.distance,z.mult(-1),0,0,!1,y,u);}else if(\"bevel\"===P||\"fakeround\"===P){var L=A.x*S.y-A.y*S.x>0,D=-Math.sqrt(B*B-1);if(L?(v=0,m=D):(m=0,v=D),b||this.addCurrentVertex(d,this.distance,A,m,v,!1,y,u),\"fakeround\"===P){for(var O=Math.floor(8*(.5-(I-.5))),R=void 0,U=0;U<O;U++)R=S.mult((U+1)/(O+1))._add(A)._unit(),this.addPieSliceVertex(d,this.distance,R,L,y,u);this.addPieSliceVertex(d,this.distance,z,L,y,u);for(var j=O-1;j>=0;j--)R=A.mult((j+1)/(O+1))._add(S)._unit(),this.addPieSliceVertex(d,this.distance,R,L,y,u);}w&&this.addCurrentVertex(d,this.distance,S,-m,-v,!1,y,u);}else\"butt\"===P?(b||this.addCurrentVertex(d,this.distance,A,0,0,!1,y,u),w&&this.addCurrentVertex(d,this.distance,S,0,0,!1,y,u)):\"square\"===P?(b||(this.addCurrentVertex(d,this.distance,A,1,1,!1,y,u),this.e1=this.e2=-1),w&&this.addCurrentVertex(d,this.distance,S,-1,-1,!1,y,u)):\"round\"===P&&(b||(this.addCurrentVertex(d,this.distance,A,0,0,!1,y,u),this.addCurrentVertex(d,this.distance,A,1,1,!0,y,u),this.e1=this.e2=-1),w&&(this.addCurrentVertex(d,this.distance,S,-1,-1,!0,y,u),this.addCurrentVertex(d,this.distance,S,0,0,!1,y,u)));if(C&&k<p-1){var q=d.dist(w);if(q>2*h){var N=d.add(w.sub(d)._mult(h/q)._round());this.distance+=N.dist(d),this.addCurrentVertex(N,this.distance,S.mult(1),0,0,!1,y,u),d=N;}}b=!1;}this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,e,o,s);}},ws.prototype.addCurrentVertex=function(t,e,r,n,i,a,o,s){var u,l=this.layoutVertexArray,p=this.indexArray;s&&(e=As(e,s)),u=r.clone(),n&&u._sub(r.perp()._mult(n)),_s(l,t,u,a,!1,n,e),this.e3=o.vertexLength++,this.e1>=0&&this.e2>=0&&(p.emplaceBack(this.e1,this.e2,this.e3),o.primitiveLength++),this.e1=this.e2,this.e2=this.e3,u=r.mult(-1),i&&u._sub(r.perp()._mult(i)),_s(l,t,u,a,!0,-i,e),this.e3=o.vertexLength++,this.e1>=0&&this.e2>=0&&(p.emplaceBack(this.e1,this.e2,this.e3),o.primitiveLength++),this.e1=this.e2,this.e2=this.e3,e>bs/2&&!s&&(this.distance=0,this.addCurrentVertex(t,this.distance,r,n,i,a,o));},ws.prototype.addPieSliceVertex=function(t,e,r,n,i,a){r=r.mult(n?-1:1);var o=this.layoutVertexArray,s=this.indexArray;a&&(e=As(e,a)),_s(o,t,r,!1,n,0,e),this.e3=i.vertexLength++,this.e1>=0&&this.e2>=0&&(s.emplaceBack(this.e1,this.e2,this.e3),i.primitiveLength++),n?this.e2=this.e3:this.e1=this.e3;},zn(\"LineBucket\",ws,{omit:[\"layers\",\"features\"]});var Ss=new ii({\"line-cap\":new Qn(Lt.layout_line[\"line-cap\"]),\"line-join\":new ti(Lt.layout_line[\"line-join\"]),\"line-miter-limit\":new Qn(Lt.layout_line[\"line-miter-limit\"]),\"line-round-limit\":new Qn(Lt.layout_line[\"line-round-limit\"])}),ks={paint:new ii({\"line-opacity\":new ti(Lt.paint_line[\"line-opacity\"]),\"line-color\":new ti(Lt.paint_line[\"line-color\"]),\"line-translate\":new Qn(Lt.paint_line[\"line-translate\"]),\"line-translate-anchor\":new Qn(Lt.paint_line[\"line-translate-anchor\"]),\"line-width\":new ti(Lt.paint_line[\"line-width\"]),\"line-gap-width\":new ti(Lt.paint_line[\"line-gap-width\"]),\"line-offset\":new ti(Lt.paint_line[\"line-offset\"]),\"line-blur\":new ti(Lt.paint_line[\"line-blur\"]),\"line-dasharray\":new ri(Lt.paint_line[\"line-dasharray\"]),\"line-pattern\":new ei(Lt.paint_line[\"line-pattern\"]),\"line-gradient\":new ni(Lt.paint_line[\"line-gradient\"])}),layout:Ss},zs=new(function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.possiblyEvaluate=function(e,r){return r=new Zn(Math.floor(r.zoom),{now:r.now,fadeDuration:r.fadeDuration,zoomHistory:r.zoomHistory,transition:r.transition}),t.prototype.possiblyEvaluate.call(this,e,r)},e.prototype.evaluate=function(e,r,n,i){return r=c({},r,{zoom:Math.floor(r.zoom)}),t.prototype.evaluate.call(this,e,r,n,i)},e}(ti))(ks.paint.properties[\"line-width\"].specification);zs.useIntegerZoom=!0;var Is=function(t){function e(e){t.call(this,e,ks);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._handleSpecialPaintPropertyUpdate=function(t){\"line-gradient\"===t&&this._updateGradient();},e.prototype._updateGradient=function(){var t=this._transitionablePaint._values[\"line-gradient\"].value.expression;this.gradient=uo(t,\"lineProgress\"),this.gradientTexture=null;},e.prototype.recalculate=function(e){t.prototype.recalculate.call(this,e),this.paint._values[\"line-floorwidth\"]=zs.possiblyEvaluate(this._transitioningPaint._values[\"line-width\"].value,e);},e.prototype.createBucket=function(t){return new ws(t)},e.prototype.queryRadius=function(t){var e=t,r=Bs(Ma(\"line-width\",this,e),Ma(\"line-gap-width\",this,e)),n=Ma(\"line-offset\",this,e);return r/2+Math.abs(n)+Ta(this.paint.get(\"line-translate\"))},e.prototype.queryIntersectsFeature=function(t,e,r,n,a,o,s){var u=Pa(t,this.paint.get(\"line-translate\"),this.paint.get(\"line-translate-anchor\"),o.angle,s),l=s/2*Bs(this.paint.get(\"line-width\").evaluate(e,r),this.paint.get(\"line-gap-width\").evaluate(e,r)),p=this.paint.get(\"line-offset\").evaluate(e,r);return p&&(n=function(t,e){for(var r=[],n=new i(0,0),a=0;a<t.length;a++){for(var o=t[a],s=[],u=0;u<o.length;u++){var l=o[u-1],p=o[u],c=o[u+1],h=0===u?n:p.sub(l)._unit()._perp(),f=u===o.length-1?n:c.sub(p)._unit()._perp(),y=h._add(f)._unit(),d=y.x*f.x+y.y*f.y;y._mult(1/d),s.push(y._mult(e)._add(p));}r.push(s);}return r}(n,p*s)),function(t,e,r){for(var n=0;n<e.length;n++){var i=e[n];if(t.length>=3)for(var a=0;a<i.length;a++)if(Ca(t,i[a]))return !0;if(Aa(t,i,r))return !0}return !1}(u,n,l)},e.prototype.isTileClipped=function(){return !0},e}(ai);function Bs(t,e){return e>0?e+2*t:t}var Cs=li([{name:\"a_pos_offset\",components:4,type:\"Int16\"},{name:\"a_data\",components:4,type:\"Uint16\"}]),Es=li([{name:\"a_projected_pos\",components:3,type:\"Float32\"}],4),Ms=(li([{name:\"a_fade_opacity\",components:1,type:\"Uint32\"}],4),li([{name:\"a_placed\",components:2,type:\"Uint8\"},{name:\"a_shift\",components:2,type:\"Float32\"}])),Ts=(li([{type:\"Int16\",name:\"anchorPointX\"},{type:\"Int16\",name:\"anchorPointY\"},{type:\"Int16\",name:\"x1\"},{type:\"Int16\",name:\"y1\"},{type:\"Int16\",name:\"x2\"},{type:\"Int16\",name:\"y2\"},{type:\"Uint32\",name:\"featureIndex\"},{type:\"Uint16\",name:\"sourceLayerIndex\"},{type:\"Uint16\",name:\"bucketIndex\"},{type:\"Int16\",name:\"radius\"},{type:\"Int16\",name:\"signedDistanceFromAnchor\"}]),li([{name:\"a_pos\",components:2,type:\"Int16\"},{name:\"a_anchor_pos\",components:2,type:\"Int16\"},{name:\"a_extrude\",components:2,type:\"Int16\"}],4)),Ps=li([{name:\"a_pos\",components:2,type:\"Int16\"},{name:\"a_anchor_pos\",components:2,type:\"Int16\"},{name:\"a_extrude\",components:2,type:\"Int16\"}],4);li([{type:\"Int16\",name:\"anchorX\"},{type:\"Int16\",name:\"anchorY\"},{type:\"Uint16\",name:\"glyphStartIndex\"},{type:\"Uint16\",name:\"numGlyphs\"},{type:\"Uint32\",name:\"vertexStartIndex\"},{type:\"Uint32\",name:\"lineStartIndex\"},{type:\"Uint32\",name:\"lineLength\"},{type:\"Uint16\",name:\"segment\"},{type:\"Uint16\",name:\"lowerSize\"},{type:\"Uint16\",name:\"upperSize\"},{type:\"Float32\",name:\"lineOffsetX\"},{type:\"Float32\",name:\"lineOffsetY\"},{type:\"Uint8\",name:\"writingMode\"},{type:\"Uint8\",name:\"hidden\"},{type:\"Uint32\",name:\"crossTileID\"}]),li([{type:\"Int16\",name:\"anchorX\"},{type:\"Int16\",name:\"anchorY\"},{type:\"Int16\",name:\"rightJustifiedTextSymbolIndex\"},{type:\"Int16\",name:\"centerJustifiedTextSymbolIndex\"},{type:\"Int16\",name:\"leftJustifiedTextSymbolIndex\"},{type:\"Int16\",name:\"verticalPlacedTextSymbolIndex\"},{type:\"Uint16\",name:\"key\"},{type:\"Uint16\",name:\"textBoxStartIndex\"},{type:\"Uint16\",name:\"textBoxEndIndex\"},{type:\"Uint16\",name:\"iconBoxStartIndex\"},{type:\"Uint16\",name:\"iconBoxEndIndex\"},{type:\"Uint16\",name:\"featureIndex\"},{type:\"Uint16\",name:\"numHorizontalGlyphVertices\"},{type:\"Uint16\",name:\"numVerticalGlyphVertices\"},{type:\"Uint16\",name:\"numIconVertices\"},{type:\"Uint32\",name:\"crossTileID\"},{type:\"Float32\",name:\"textBoxScale\"},{type:\"Float32\",name:\"radialTextOffset\"}]),li([{type:\"Float32\",name:\"offsetX\"}]),li([{type:\"Int16\",name:\"x\"},{type:\"Int16\",name:\"y\"},{type:\"Int16\",name:\"tileUnitDistanceFromAnchor\"}]);function Vs(t,e,r){return t.sections.forEach(function(t){t.text=function(t,e,r){var n=e.layout.get(\"text-transform\").evaluate(r,{});return \"uppercase\"===n?t=t.toLocaleUpperCase():\"lowercase\"===n&&(t=t.toLocaleLowerCase()),Nn.applyArabicShaping&&(t=Nn.applyArabicShaping(t)),t}(t.text,e,r);}),t}var Fs={\"!\":\"︕\",\"#\":\"＃\",$:\"＄\",\"%\":\"％\",\"&\":\"＆\",\"(\":\"︵\",\")\":\"︶\",\"*\":\"＊\",\"+\":\"＋\",\",\":\"︐\",\"-\":\"︲\",\".\":\"・\",\"/\":\"／\",\":\":\"︓\",\";\":\"︔\",\"<\":\"︿\",\"=\":\"＝\",\">\":\"﹀\",\"?\":\"︖\",\"@\":\"＠\",\"[\":\"﹇\",\"\\\\\":\"＼\",\"]\":\"﹈\",\"^\":\"＾\",_:\"︳\",\"`\":\"｀\",\"{\":\"︷\",\"|\":\"―\",\"}\":\"︸\",\"~\":\"～\",\"¢\":\"￠\",\"£\":\"￡\",\"¥\":\"￥\",\"¦\":\"￤\",\"¬\":\"￢\",\"¯\":\"￣\",\"–\":\"︲\",\"—\":\"︱\",\"‘\":\"﹃\",\"’\":\"﹄\",\"“\":\"﹁\",\"”\":\"﹂\",\"…\":\"︙\",\"‧\":\"・\",\"₩\":\"￦\",\"、\":\"︑\",\"。\":\"︒\",\"〈\":\"︿\",\"〉\":\"﹀\",\"《\":\"︽\",\"》\":\"︾\",\"「\":\"﹁\",\"」\":\"﹂\",\"『\":\"﹃\",\"』\":\"﹄\",\"【\":\"︻\",\"】\":\"︼\",\"〔\":\"︹\",\"〕\":\"︺\",\"〖\":\"︗\",\"〗\":\"︘\",\"！\":\"︕\",\"（\":\"︵\",\"）\":\"︶\",\"，\":\"︐\",\"－\":\"︲\",\"．\":\"・\",\"：\":\"︓\",\"；\":\"︔\",\"＜\":\"︿\",\"＞\":\"﹀\",\"？\":\"︖\",\"［\":\"﹇\",\"］\":\"﹈\",\"＿\":\"︳\",\"｛\":\"︷\",\"｜\":\"―\",\"｝\":\"︸\",\"｟\":\"︵\",\"｠\":\"︶\",\"｡\":\"︒\",\"｢\":\"﹁\",\"｣\":\"﹂\"};var Ls=function(t){function e(e,r,n,i){t.call(this,e,r),this.angle=n,void 0!==i&&(this.segment=i);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.clone=function(){return new e(this.x,this.y,this.angle,this.segment)},e}(i);zn(\"Anchor\",Ls);var Ds=256;function Os(t,e){var r=e.expression;if(\"constant\"===r.kind)return {kind:\"constant\",layoutSize:r.evaluate(new Zn(t+1))};if(\"source\"===r.kind)return {kind:\"source\"};for(var n=r.zoomStops,i=r.interpolationType,a=0;a<n.length&&n[a]<=t;)a++;for(var o=a=Math.max(0,a-1);o<n.length&&n[o]<t+1;)o++;o=Math.min(n.length-1,o);var s=n[a],u=n[o];return \"composite\"===r.kind?{kind:\"composite\",minZoom:s,maxZoom:u,interpolationType:i}:{kind:\"camera\",minZoom:s,maxZoom:u,minSize:r.evaluate(new Zn(s)),maxSize:r.evaluate(new Zn(u)),interpolationType:i}}function Rs(t,e,r){var n=e.uSize,i=e.uSizeT,a=r.lowerSize,o=r.upperSize;return \"source\"===t.kind?a/Ds:\"composite\"===t.kind?Ee(a/Ds,o/Ds,i):n}function Us(t,e){var r=0,n=0;if(\"constant\"===t.kind)n=t.layoutSize;else if(\"source\"!==t.kind){var i=t.interpolationType,a=t.minZoom,o=t.maxZoom,s=i?l($e.interpolationFactor(i,e,a,o),0,1):0;\"camera\"===t.kind?n=Ee(t.minSize,t.maxSize,s):r=s;}return {uSizeT:r,uSize:n}}var js=Object.freeze({getSizeData:Os,evaluateSizeForFeature:Rs,evaluateSizeForZoom:Us,SIZE_PACK_FACTOR:Ds}),qs=is.VectorTileFeature.types,Ns=[{name:\"a_fade_opacity\",components:1,type:\"Uint8\",offset:0}];function Zs(t,e,r,n,i,a,o,s){t.emplaceBack(e,r,Math.round(32*n),Math.round(32*i),a,o,s?s[0]:0,s?s[1]:0);}function Ks(t,e,r){t.emplaceBack(e.x,e.y,r),t.emplaceBack(e.x,e.y,r),t.emplaceBack(e.x,e.y,r),t.emplaceBack(e.x,e.y,r);}var Gs=function(t){this.layoutVertexArray=new mi,this.indexArray=new Ii,this.programConfigurations=t,this.segments=new Ki,this.dynamicLayoutVertexArray=new vi,this.opacityVertexArray=new gi,this.placedSymbolArray=new Fi;};Gs.prototype.upload=function(t,e,r,n){r&&(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,Cs.members),this.indexBuffer=t.createIndexBuffer(this.indexArray,e),this.dynamicLayoutVertexBuffer=t.createVertexBuffer(this.dynamicLayoutVertexArray,Es.members,!0),this.opacityVertexBuffer=t.createVertexBuffer(this.opacityVertexArray,Ns,!0),this.opacityVertexBuffer.itemSize=1),(r||n)&&this.programConfigurations.upload(t);},Gs.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy(),this.dynamicLayoutVertexBuffer.destroy(),this.opacityVertexBuffer.destroy());},zn(\"SymbolBuffers\",Gs);var Xs=function(t,e,r){this.layoutVertexArray=new t,this.layoutAttributes=e,this.indexArray=new r,this.segments=new Ki,this.collisionVertexArray=new _i;};Xs.prototype.upload=function(t){this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,this.layoutAttributes),this.indexBuffer=t.createIndexBuffer(this.indexArray),this.collisionVertexBuffer=t.createVertexBuffer(this.collisionVertexArray,Ms.members,!0);},Xs.prototype.destroy=function(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.segments.destroy(),this.collisionVertexBuffer.destroy());},zn(\"CollisionBuffers\",Xs);var Js=function(t){this.collisionBoxArray=t.collisionBoxArray,this.zoom=t.zoom,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map(function(t){return t.id}),this.index=t.index,this.pixelRatio=t.pixelRatio,this.sourceLayerIndex=t.sourceLayerIndex,this.hasPattern=!1;var e=this.layers[0]._unevaluatedLayout._values;this.textSizeData=Os(this.zoom,e[\"text-size\"]),this.iconSizeData=Os(this.zoom,e[\"icon-size\"]);var r=this.layers[0].layout,n=r.get(\"symbol-sort-key\"),i=r.get(\"symbol-z-order\");this.sortFeaturesByKey=\"viewport-y\"!==i&&void 0!==n.constantOr(1);var a=\"viewport-y\"===i||\"auto\"===i&&!this.sortFeaturesByKey;this.sortFeaturesByY=a&&(r.get(\"text-allow-overlap\")||r.get(\"icon-allow-overlap\")||r.get(\"text-ignore-placement\")||r.get(\"icon-ignore-placement\")),this.stateDependentLayerIds=this.layers.filter(function(t){return t.isStateDependent()}).map(function(t){return t.id}),this.sourceID=t.sourceID;};Js.prototype.createArrays=function(){this.text=new Gs(new ca(Cs.members,this.layers,this.zoom,function(t){return /^text/.test(t)})),this.icon=new Gs(new ca(Cs.members,this.layers,this.zoom,function(t){return /^icon/.test(t)})),this.collisionBox=new Xs(bi,Ts.members,Bi),this.collisionCircle=new Xs(bi,Ps.members,Ii),this.glyphOffsetArray=new Ri,this.lineVertexArray=new ji,this.symbolInstances=new Di;},Js.prototype.calculateGlyphDependencies=function(t,e,r,n){for(var i=0;i<t.length;i++)if(e[t.charCodeAt(i)]=!0,r&&n){var a=Fs[t.charAt(i)];a&&(e[a.charCodeAt(0)]=!0);}},Js.prototype.populate=function(t,e){var r=this.layers[0],n=r.layout,i=n.get(\"text-font\"),a=n.get(\"text-field\"),o=n.get(\"icon-image\"),s=(\"constant\"!==a.value.kind||a.value.value.toString().length>0)&&(\"constant\"!==i.value.kind||i.value.value.length>0),u=\"constant\"!==o.value.kind||o.value.value&&o.value.value.length>0,l=n.get(\"symbol-sort-key\");if(this.features=[],s||u){for(var p=e.iconDependencies,c=e.glyphDependencies,h=new Zn(this.zoom),f=0,y=t;f<y.length;f+=1){var d=y[f],m=d.feature,v=d.index,g=d.sourceLayerIndex;if(r._featureFilter(h,m)){var x=void 0;if(s){var b=r.getValueAndResolveTokens(\"text-field\",m);x=Vs(b instanceof ue?b:ue.fromString(b),r,m);}var _=void 0;if(u&&(_=r.getValueAndResolveTokens(\"icon-image\",m)),x||_){var w=this.sortFeaturesByKey?l.evaluate(m,{}):void 0,A={text:x,icon:_,index:v,sourceLayerIndex:g,geometry:va(m),properties:m.properties,type:qs[m.type],sortKey:w};if(void 0!==m.id&&(A.id=m.id),this.features.push(A),_&&(p[_]=!0),x)for(var S=i.evaluate(m,{}).join(\",\"),k=\"map\"===n.get(\"text-rotation-alignment\")&&\"point\"!==n.get(\"symbol-placement\"),z=0,I=x.sections;z<I.length;z+=1){var B=I[z],C=Tn(x.toString()),E=B.fontStack||S,M=c[E]=c[E]||{};this.calculateGlyphDependencies(B.text,M,k,C);}}}}\"line\"===n.get(\"symbol-placement\")&&(this.features=function(t){var e={},r={},n=[],i=0;function a(e){n.push(t[e]),i++;}function o(t,e,i){var a=r[t];return delete r[t],r[e]=a,n[a].geometry[0].pop(),n[a].geometry[0]=n[a].geometry[0].concat(i[0]),a}function s(t,r,i){var a=e[r];return delete e[r],e[t]=a,n[a].geometry[0].shift(),n[a].geometry[0]=i[0].concat(n[a].geometry[0]),a}function u(t,e,r){var n=r?e[0][e[0].length-1]:e[0][0];return t+\":\"+n.x+\":\"+n.y}for(var l=0;l<t.length;l++){var p=t[l],c=p.geometry,h=p.text?p.text.toString():null;if(h){var f=u(h,c),y=u(h,c,!0);if(f in r&&y in e&&r[f]!==e[y]){var d=s(f,y,c),m=o(f,y,n[d].geometry);delete e[f],delete r[y],r[u(h,n[m].geometry,!0)]=m,n[d].geometry=null;}else f in r?o(f,y,c):y in e?s(f,y,c):(a(l),e[f]=i-1,r[y]=i-1);}else a(l);}return n.filter(function(t){return t.geometry})}(this.features)),this.sortFeaturesByKey&&this.features.sort(function(t,e){return t.sortKey-e.sortKey});}},Js.prototype.update=function(t,e,r){this.stateDependentLayers.length&&(this.text.programConfigurations.updatePaintArrays(t,e,this.layers,r),this.icon.programConfigurations.updatePaintArrays(t,e,this.layers,r));},Js.prototype.isEmpty=function(){return 0===this.symbolInstances.length},Js.prototype.uploadPending=function(){return !this.uploaded||this.text.programConfigurations.needsUpload||this.icon.programConfigurations.needsUpload},Js.prototype.upload=function(t){this.uploaded||(this.collisionBox.upload(t),this.collisionCircle.upload(t)),this.text.upload(t,this.sortFeaturesByY,!this.uploaded,this.text.programConfigurations.needsUpload),this.icon.upload(t,this.sortFeaturesByY,!this.uploaded,this.icon.programConfigurations.needsUpload),this.uploaded=!0;},Js.prototype.destroy=function(){this.text.destroy(),this.icon.destroy(),this.collisionBox.destroy(),this.collisionCircle.destroy();},Js.prototype.addToLineVertexArray=function(t,e){var r=this.lineVertexArray.length;if(void 0!==t.segment){for(var n=t.dist(e[t.segment+1]),i=t.dist(e[t.segment]),a={},o=t.segment+1;o<e.length;o++)a[o]={x:e[o].x,y:e[o].y,tileUnitDistanceFromAnchor:n},o<e.length-1&&(n+=e[o+1].dist(e[o]));for(var s=t.segment||0;s>=0;s--)a[s]={x:e[s].x,y:e[s].y,tileUnitDistanceFromAnchor:i},s>0&&(i+=e[s-1].dist(e[s]));for(var u=0;u<e.length;u++){var l=a[u];this.lineVertexArray.emplaceBack(l.x,l.y,l.tileUnitDistanceFromAnchor);}}return {lineStartIndex:r,lineLength:this.lineVertexArray.length-r}},Js.prototype.addSymbols=function(t,e,r,n,i,a,o,s,u,l){for(var p=t.indexArray,c=t.layoutVertexArray,h=t.dynamicLayoutVertexArray,f=t.segments.prepareSegment(4*e.length,t.layoutVertexArray,t.indexArray,a.sortKey),y=this.glyphOffsetArray.length,d=f.vertexLength,m=0,v=e;m<v.length;m+=1){var g=v[m],x=g.tl,b=g.tr,_=g.bl,w=g.br,A=g.tex,S=f.vertexLength,k=g.glyphOffset[1];Zs(c,s.x,s.y,x.x,k+x.y,A.x,A.y,r),Zs(c,s.x,s.y,b.x,k+b.y,A.x+A.w,A.y,r),Zs(c,s.x,s.y,_.x,k+_.y,A.x,A.y+A.h,r),Zs(c,s.x,s.y,w.x,k+w.y,A.x+A.w,A.y+A.h,r),Ks(h,s,0),p.emplaceBack(S,S+1,S+2),p.emplaceBack(S+1,S+2,S+3),f.vertexLength+=4,f.primitiveLength+=2,this.glyphOffsetArray.emplaceBack(g.glyphOffset[0]);}t.placedSymbolArray.emplaceBack(s.x,s.y,y,this.glyphOffsetArray.length-y,d,u,l,s.segment,r?r[0]:0,r?r[1]:0,n[0],n[1],o,!1,0),t.programConfigurations.populatePaintArrays(t.layoutVertexArray.length,a,a.index,{});},Js.prototype._addCollisionDebugVertex=function(t,e,r,n,i,a){return e.emplaceBack(0,0),t.emplaceBack(r.x,r.y,n,i,Math.round(a.x),Math.round(a.y))},Js.prototype.addCollisionDebugVertices=function(t,e,r,n,a,o,s,u){var l=a.segments.prepareSegment(4,a.layoutVertexArray,a.indexArray),p=l.vertexLength,c=a.layoutVertexArray,h=a.collisionVertexArray,f=s.anchorX,y=s.anchorY;if(this._addCollisionDebugVertex(c,h,o,f,y,new i(t,e)),this._addCollisionDebugVertex(c,h,o,f,y,new i(r,e)),this._addCollisionDebugVertex(c,h,o,f,y,new i(r,n)),this._addCollisionDebugVertex(c,h,o,f,y,new i(t,n)),l.vertexLength+=4,u){var d=a.indexArray;d.emplaceBack(p,p+1,p+2),d.emplaceBack(p,p+2,p+3),l.primitiveLength+=2;}else{var m=a.indexArray;m.emplaceBack(p,p+1),m.emplaceBack(p+1,p+2),m.emplaceBack(p+2,p+3),m.emplaceBack(p+3,p),l.primitiveLength+=4;}},Js.prototype.addDebugCollisionBoxes=function(t,e,r){for(var n=t;n<e;n++){var i=this.collisionBoxArray.get(n),a=i.x1,o=i.y1,s=i.x2,u=i.y2,l=i.radius>0;this.addCollisionDebugVertices(a,o,s,u,l?this.collisionCircle:this.collisionBox,i.anchorPoint,r,l);}},Js.prototype.generateCollisionDebugBuffers=function(){for(var t=0;t<this.symbolInstances.length;t++){var e=this.symbolInstances.get(t);this.addDebugCollisionBoxes(e.textBoxStartIndex,e.textBoxEndIndex,e),this.addDebugCollisionBoxes(e.iconBoxStartIndex,e.iconBoxEndIndex,e);}},Js.prototype._deserializeCollisionBoxesForSymbol=function(t,e,r,n,i){for(var a={},o=e;o<r;o++){var s=t.get(o);if(0===s.radius){a.textBox={x1:s.x1,y1:s.y1,x2:s.x2,y2:s.y2,anchorPointX:s.anchorPointX,anchorPointY:s.anchorPointY},a.textFeatureIndex=s.featureIndex;break}a.textCircles||(a.textCircles=[],a.textFeatureIndex=s.featureIndex);a.textCircles.push(s.anchorPointX,s.anchorPointY,s.radius,s.signedDistanceFromAnchor,1);}for(var u=n;u<i;u++){var l=t.get(u);if(0===l.radius){a.iconBox={x1:l.x1,y1:l.y1,x2:l.x2,y2:l.y2,anchorPointX:l.anchorPointX,anchorPointY:l.anchorPointY},a.iconFeatureIndex=l.featureIndex;break}}return a},Js.prototype.deserializeCollisionBoxes=function(t){this.collisionArrays=[];for(var e=0;e<this.symbolInstances.length;e++){var r=this.symbolInstances.get(e);this.collisionArrays.push(this._deserializeCollisionBoxesForSymbol(t,r.textBoxStartIndex,r.textBoxEndIndex,r.iconBoxStartIndex,r.iconBoxEndIndex));}},Js.prototype.hasTextData=function(){return this.text.segments.get().length>0},Js.prototype.hasIconData=function(){return this.icon.segments.get().length>0},Js.prototype.hasCollisionBoxData=function(){return this.collisionBox.segments.get().length>0},Js.prototype.hasCollisionCircleData=function(){return this.collisionCircle.segments.get().length>0},Js.prototype.addIndicesForPlacedTextSymbol=function(t){for(var e=this.text.placedSymbolArray.get(t),r=e.vertexStartIndex+4*e.numGlyphs,n=e.vertexStartIndex;n<r;n+=4)this.text.indexArray.emplaceBack(n,n+1,n+2),this.text.indexArray.emplaceBack(n+1,n+2,n+3);},Js.prototype.getSortedSymbolIndexes=function(t){if(this.sortedAngle===t&&void 0!==this.symbolInstanceIndexes)return this.symbolInstanceIndexes;for(var e=Math.sin(t),r=Math.cos(t),n=[],i=[],a=[],o=0;o<this.symbolInstances.length;++o){a.push(o);var s=this.symbolInstances.get(o);n.push(0|Math.round(e*s.anchorX+r*s.anchorY)),i.push(s.featureIndex);}return a.sort(function(t,e){return n[t]-n[e]||i[e]-i[t]}),a},Js.prototype.sortFeatures=function(t){var e=this;if(this.sortFeaturesByY&&this.sortedAngle!==t&&!(this.text.segments.get().length>1||this.icon.segments.get().length>1)){this.symbolInstanceIndexes=this.getSortedSymbolIndexes(t),this.sortedAngle=t,this.text.indexArray.clear(),this.icon.indexArray.clear(),this.featureSortOrder=[];for(var r=0,n=this.symbolInstanceIndexes;r<n.length;r+=1){var i=n[r],a=this.symbolInstances.get(i);this.featureSortOrder.push(a.featureIndex),[a.rightJustifiedTextSymbolIndex,a.centerJustifiedTextSymbolIndex,a.leftJustifiedTextSymbolIndex].forEach(function(t,r,n){t>=0&&n.indexOf(t)===r&&e.addIndicesForPlacedTextSymbol(t);}),a.verticalPlacedTextSymbolIndex>=0&&this.addIndicesForPlacedTextSymbol(a.verticalPlacedTextSymbolIndex);var o=this.icon.placedSymbolArray.get(i);if(o.numGlyphs){var s=o.vertexStartIndex;this.icon.indexArray.emplaceBack(s,s+1,s+2),this.icon.indexArray.emplaceBack(s+1,s+2,s+3);}}this.text.indexBuffer&&this.text.indexBuffer.updateData(this.text.indexArray),this.icon.indexBuffer&&this.icon.indexBuffer.updateData(this.icon.indexArray);}},zn(\"SymbolBucket\",Js,{omit:[\"layers\",\"collisionBoxArray\",\"features\",\"compareText\"]}),Js.MAX_GLYPHS=65535,Js.addDynamicAttributes=Ks;var Hs=new ii({\"symbol-placement\":new Qn(Lt.layout_symbol[\"symbol-placement\"]),\"symbol-spacing\":new Qn(Lt.layout_symbol[\"symbol-spacing\"]),\"symbol-avoid-edges\":new Qn(Lt.layout_symbol[\"symbol-avoid-edges\"]),\"symbol-sort-key\":new ti(Lt.layout_symbol[\"symbol-sort-key\"]),\"symbol-z-order\":new Qn(Lt.layout_symbol[\"symbol-z-order\"]),\"icon-allow-overlap\":new Qn(Lt.layout_symbol[\"icon-allow-overlap\"]),\"icon-ignore-placement\":new Qn(Lt.layout_symbol[\"icon-ignore-placement\"]),\"icon-optional\":new Qn(Lt.layout_symbol[\"icon-optional\"]),\"icon-rotation-alignment\":new Qn(Lt.layout_symbol[\"icon-rotation-alignment\"]),\"icon-size\":new ti(Lt.layout_symbol[\"icon-size\"]),\"icon-text-fit\":new Qn(Lt.layout_symbol[\"icon-text-fit\"]),\"icon-text-fit-padding\":new Qn(Lt.layout_symbol[\"icon-text-fit-padding\"]),\"icon-image\":new ti(Lt.layout_symbol[\"icon-image\"]),\"icon-rotate\":new ti(Lt.layout_symbol[\"icon-rotate\"]),\"icon-padding\":new Qn(Lt.layout_symbol[\"icon-padding\"]),\"icon-keep-upright\":new Qn(Lt.layout_symbol[\"icon-keep-upright\"]),\"icon-offset\":new ti(Lt.layout_symbol[\"icon-offset\"]),\"icon-anchor\":new ti(Lt.layout_symbol[\"icon-anchor\"]),\"icon-pitch-alignment\":new Qn(Lt.layout_symbol[\"icon-pitch-alignment\"]),\"text-pitch-alignment\":new Qn(Lt.layout_symbol[\"text-pitch-alignment\"]),\"text-rotation-alignment\":new Qn(Lt.layout_symbol[\"text-rotation-alignment\"]),\"text-field\":new ti(Lt.layout_symbol[\"text-field\"]),\"text-font\":new ti(Lt.layout_symbol[\"text-font\"]),\"text-size\":new ti(Lt.layout_symbol[\"text-size\"]),\"text-max-width\":new ti(Lt.layout_symbol[\"text-max-width\"]),\"text-line-height\":new Qn(Lt.layout_symbol[\"text-line-height\"]),\"text-letter-spacing\":new ti(Lt.layout_symbol[\"text-letter-spacing\"]),\"text-justify\":new ti(Lt.layout_symbol[\"text-justify\"]),\"text-radial-offset\":new ti(Lt.layout_symbol[\"text-radial-offset\"]),\"text-variable-anchor\":new Qn(Lt.layout_symbol[\"text-variable-anchor\"]),\"text-anchor\":new ti(Lt.layout_symbol[\"text-anchor\"]),\"text-max-angle\":new Qn(Lt.layout_symbol[\"text-max-angle\"]),\"text-rotate\":new ti(Lt.layout_symbol[\"text-rotate\"]),\"text-padding\":new Qn(Lt.layout_symbol[\"text-padding\"]),\"text-keep-upright\":new Qn(Lt.layout_symbol[\"text-keep-upright\"]),\"text-transform\":new ti(Lt.layout_symbol[\"text-transform\"]),\"text-offset\":new ti(Lt.layout_symbol[\"text-offset\"]),\"text-allow-overlap\":new Qn(Lt.layout_symbol[\"text-allow-overlap\"]),\"text-ignore-placement\":new Qn(Lt.layout_symbol[\"text-ignore-placement\"]),\"text-optional\":new Qn(Lt.layout_symbol[\"text-optional\"])}),Ys={paint:new ii({\"icon-opacity\":new ti(Lt.paint_symbol[\"icon-opacity\"]),\"icon-color\":new ti(Lt.paint_symbol[\"icon-color\"]),\"icon-halo-color\":new ti(Lt.paint_symbol[\"icon-halo-color\"]),\"icon-halo-width\":new ti(Lt.paint_symbol[\"icon-halo-width\"]),\"icon-halo-blur\":new ti(Lt.paint_symbol[\"icon-halo-blur\"]),\"icon-translate\":new Qn(Lt.paint_symbol[\"icon-translate\"]),\"icon-translate-anchor\":new Qn(Lt.paint_symbol[\"icon-translate-anchor\"]),\"text-opacity\":new ti(Lt.paint_symbol[\"text-opacity\"]),\"text-color\":new ti(Lt.paint_symbol[\"text-color\"]),\"text-halo-color\":new ti(Lt.paint_symbol[\"text-halo-color\"]),\"text-halo-width\":new ti(Lt.paint_symbol[\"text-halo-width\"]),\"text-halo-blur\":new ti(Lt.paint_symbol[\"text-halo-blur\"]),\"text-translate\":new Qn(Lt.paint_symbol[\"text-translate\"]),\"text-translate-anchor\":new Qn(Lt.paint_symbol[\"text-translate-anchor\"])}),layout:Hs},$s=function(t){function e(e){t.call(this,e,Ys);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.recalculate=function(e){t.prototype.recalculate.call(this,e),\"auto\"===this.layout.get(\"icon-rotation-alignment\")&&(\"point\"!==this.layout.get(\"symbol-placement\")?this.layout._values[\"icon-rotation-alignment\"]=\"map\":this.layout._values[\"icon-rotation-alignment\"]=\"viewport\"),\"auto\"===this.layout.get(\"text-rotation-alignment\")&&(\"point\"!==this.layout.get(\"symbol-placement\")?this.layout._values[\"text-rotation-alignment\"]=\"map\":this.layout._values[\"text-rotation-alignment\"]=\"viewport\"),\"auto\"===this.layout.get(\"text-pitch-alignment\")&&(this.layout._values[\"text-pitch-alignment\"]=this.layout.get(\"text-rotation-alignment\")),\"auto\"===this.layout.get(\"icon-pitch-alignment\")&&(this.layout._values[\"icon-pitch-alignment\"]=this.layout.get(\"icon-rotation-alignment\"));},e.prototype.getValueAndResolveTokens=function(t,e){var r,n=this.layout.get(t).evaluate(e,{}),i=this._unevaluatedLayout._values[t];return i.isDataDriven()||Vr(i.value)?n:(r=e.properties,n.replace(/{([^{}]+)}/g,function(t,e){return e in r?String(r[e]):\"\"}))},e.prototype.createBucket=function(t){return new Js(t)},e.prototype.queryRadius=function(){return 0},e.prototype.queryIntersectsFeature=function(){return !1},e}(ai),Ws={paint:new ii({\"background-color\":new Qn(Lt.paint_background[\"background-color\"]),\"background-pattern\":new ri(Lt.paint_background[\"background-pattern\"]),\"background-opacity\":new Qn(Lt.paint_background[\"background-opacity\"])})},Qs=function(t){function e(e){t.call(this,e,Ws);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(ai),tu={paint:new ii({\"raster-opacity\":new Qn(Lt.paint_raster[\"raster-opacity\"]),\"raster-hue-rotate\":new Qn(Lt.paint_raster[\"raster-hue-rotate\"]),\"raster-brightness-min\":new Qn(Lt.paint_raster[\"raster-brightness-min\"]),\"raster-brightness-max\":new Qn(Lt.paint_raster[\"raster-brightness-max\"]),\"raster-saturation\":new Qn(Lt.paint_raster[\"raster-saturation\"]),\"raster-contrast\":new Qn(Lt.paint_raster[\"raster-contrast\"]),\"raster-resampling\":new Qn(Lt.paint_raster[\"raster-resampling\"]),\"raster-fade-duration\":new Qn(Lt.paint_raster[\"raster-fade-duration\"])})},eu=function(t){function e(e){t.call(this,e,tu);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(ai);var ru=function(t){function e(e){t.call(this,e,{}),this.implementation=e;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.is3D=function(){return \"3d\"===this.implementation.renderingMode},e.prototype.hasOffscreenPass=function(){return void 0!==this.implementation.prerender},e.prototype.recalculate=function(){},e.prototype.updateTransitions=function(){},e.prototype.hasTransition=function(){},e.prototype.serialize=function(){},e.prototype.onAdd=function(t){this.implementation.onAdd&&this.implementation.onAdd(t,t.painter.context.gl);},e.prototype.onRemove=function(t){this.implementation.onRemove&&this.implementation.onRemove(t,t.painter.context.gl);},e}(ai),nu={circle:Qa,heatmap:lo,hillshade:co,fill:Jo,\"fill-extrusion\":hs,line:Is,symbol:$s,background:Qs,raster:eu};function iu(t){for(var e=0,r=0,n=0,i=t;n<i.length;n+=1){var a=i[n];e+=a.w*a.h,r=Math.max(r,a.w);}t.sort(function(t,e){return e.h-t.h});for(var o=[{x:0,y:0,w:Math.max(Math.ceil(Math.sqrt(e/.95)),r),h:1/0}],s=0,u=0,l=0,p=t;l<p.length;l+=1)for(var c=p[l],h=o.length-1;h>=0;h--){var f=o[h];if(!(c.w>f.w||c.h>f.h)){if(c.x=f.x,c.y=f.y,u=Math.max(u,c.y+c.h),s=Math.max(s,c.x+c.w),c.w===f.w&&c.h===f.h){var y=o.pop();h<o.length&&(o[h]=y);}else c.h===f.h?(f.x+=c.w,f.w-=c.w):c.w===f.w?(f.y+=c.h,f.h-=c.h):(o.push({x:f.x+c.w,y:f.y,w:f.w-c.w,h:c.h}),f.y+=c.h,f.h-=c.h);break}}return {w:s,h:u,fill:e/(s*u)||0}}var au=function(t,e){var r=e.pixelRatio,n=e.version;this.paddedRect=t,this.pixelRatio=r,this.version=n;},ou={tl:{configurable:!0},br:{configurable:!0},tlbr:{configurable:!0},displaySize:{configurable:!0}};ou.tl.get=function(){return [this.paddedRect.x+1,this.paddedRect.y+1]},ou.br.get=function(){return [this.paddedRect.x+this.paddedRect.w-1,this.paddedRect.y+this.paddedRect.h-1]},ou.tlbr.get=function(){return this.tl.concat(this.br)},ou.displaySize.get=function(){return [(this.paddedRect.w-2)/this.pixelRatio,(this.paddedRect.h-2)/this.pixelRatio]},Object.defineProperties(au.prototype,ou);var su=function(t,e){var r={},n={};this.haveRenderCallbacks=[];var i=[];this.addImages(t,r,i),this.addImages(e,n,i);var a=iu(i),o=a.w,s=a.h,u=new oo({width:o||1,height:s||1});for(var l in t){var p=t[l],c=r[l].paddedRect;oo.copy(p.data,u,{x:0,y:0},{x:c.x+1,y:c.y+1},p.data);}for(var h in e){var f=e[h],y=n[h].paddedRect,d=y.x+1,m=y.y+1,v=f.data.width,g=f.data.height;oo.copy(f.data,u,{x:0,y:0},{x:d,y:m},f.data),oo.copy(f.data,u,{x:0,y:g-1},{x:d,y:m-1},{width:v,height:1}),oo.copy(f.data,u,{x:0,y:0},{x:d,y:m+g},{width:v,height:1}),oo.copy(f.data,u,{x:v-1,y:0},{x:d-1,y:m},{width:1,height:g}),oo.copy(f.data,u,{x:0,y:0},{x:d+v,y:m},{width:1,height:g});}this.image=u,this.iconPositions=r,this.patternPositions=n;};su.prototype.addImages=function(t,e,r){for(var n in t){var i=t[n],a={x:0,y:0,w:i.data.width+2,h:i.data.height+2};r.push(a),e[n]=new au(a,i),i.hasRenderCallback&&this.haveRenderCallbacks.push(n);}},su.prototype.patchUpdatedImages=function(t,e){for(var r in t.dispatchRenderCallbacks(this.haveRenderCallbacks),t.updatedImages)this.patchUpdatedImage(this.iconPositions[r],t.getImage(r),e),this.patchUpdatedImage(this.patternPositions[r],t.getImage(r),e);},su.prototype.patchUpdatedImage=function(t,e,r){if(t&&e&&t.version!==e.version){t.version=e.version;var n=t.tl,i=n[0],a=n[1];r.update(e.data,void 0,{x:i,y:a});}},zn(\"ImagePosition\",au),zn(\"ImageAtlas\",su);var uu=self.HTMLImageElement,lu=self.HTMLCanvasElement,pu=self.HTMLVideoElement,cu=self.ImageData,hu=function(t,e,r,n){this.context=t,this.format=r,this.texture=t.gl.createTexture(),this.update(e,n);};hu.prototype.update=function(t,e,r){var n=t.width,i=t.height,a=!(this.size&&this.size[0]===n&&this.size[1]===i||r),o=this.context,s=o.gl;if(this.useMipmap=Boolean(e&&e.useMipmap),s.bindTexture(s.TEXTURE_2D,this.texture),o.pixelStoreUnpackFlipY.set(!1),o.pixelStoreUnpack.set(1),o.pixelStoreUnpackPremultiplyAlpha.set(this.format===s.RGBA&&(!e||!1!==e.premultiply)),a)this.size=[n,i],t instanceof uu||t instanceof lu||t instanceof pu||t instanceof cu?s.texImage2D(s.TEXTURE_2D,0,this.format,this.format,s.UNSIGNED_BYTE,t):s.texImage2D(s.TEXTURE_2D,0,this.format,n,i,0,this.format,s.UNSIGNED_BYTE,t.data);else{var u=r||{x:0,y:0},l=u.x,p=u.y;t instanceof uu||t instanceof lu||t instanceof pu||t instanceof cu?s.texSubImage2D(s.TEXTURE_2D,0,l,p,s.RGBA,s.UNSIGNED_BYTE,t):s.texSubImage2D(s.TEXTURE_2D,0,l,p,n,i,s.RGBA,s.UNSIGNED_BYTE,t.data);}this.useMipmap&&this.isSizePowerOfTwo()&&s.generateMipmap(s.TEXTURE_2D);},hu.prototype.bind=function(t,e,r){var n=this.context.gl;n.bindTexture(n.TEXTURE_2D,this.texture),r!==n.LINEAR_MIPMAP_NEAREST||this.isSizePowerOfTwo()||(r=n.LINEAR),t!==this.filter&&(n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,t),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,r||t),this.filter=t),e!==this.wrap&&(n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,e),this.wrap=e);},hu.prototype.isSizePowerOfTwo=function(){return this.size[0]===this.size[1]&&Math.log(this.size[0])/Math.LN2%1==0},hu.prototype.destroy=function(){this.context.gl.deleteTexture(this.texture),this.texture=null;};var fu=function(t,e,r,n,i){var a,o,s=8*i-n-1,u=(1<<s)-1,l=u>>1,p=-7,c=r?i-1:0,h=r?-1:1,f=t[e+c];for(c+=h,a=f&(1<<-p)-1,f>>=-p,p+=s;p>0;a=256*a+t[e+c],c+=h,p-=8);for(o=a&(1<<-p)-1,a>>=-p,p+=n;p>0;o=256*o+t[e+c],c+=h,p-=8);if(0===a)a=1-l;else{if(a===u)return o?NaN:1/0*(f?-1:1);o+=Math.pow(2,n),a-=l;}return (f?-1:1)*o*Math.pow(2,a-n)},yu=function(t,e,r,n,i,a){var o,s,u,l=8*a-i-1,p=(1<<l)-1,c=p>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:a-1,y=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,o=p):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),(e+=o+c>=1?h/u:h*Math.pow(2,1-c))*u>=2&&(o++,u/=2),o+c>=p?(s=0,o=p):o+c>=1?(s=(e*u-1)*Math.pow(2,i),o+=c):(s=e*Math.pow(2,c-1)*Math.pow(2,i),o=0));i>=8;t[r+f]=255&s,f+=y,s/=256,i-=8);for(o=o<<i|s,l+=i;l>0;t[r+f]=255&o,f+=y,o/=256,l-=8);t[r+f-y]|=128*d;},du=mu;function mu(t){this.buf=ArrayBuffer.isView&&ArrayBuffer.isView(t)?t:new Uint8Array(t||0),this.pos=0,this.type=0,this.length=this.buf.length;}mu.Varint=0,mu.Fixed64=1,mu.Bytes=2,mu.Fixed32=5;function vu(t){return t.type===mu.Bytes?t.readVarint()+t.pos:t.pos+1}function gu(t,e,r){return r?4294967296*e+(t>>>0):4294967296*(e>>>0)+(t>>>0)}function xu(t,e,r){var n=e<=16383?1:e<=2097151?2:e<=268435455?3:Math.floor(Math.log(e)/(7*Math.LN2));r.realloc(n);for(var i=r.pos-1;i>=t;i--)r.buf[i+n]=r.buf[i];}function bu(t,e){for(var r=0;r<t.length;r++)e.writeVarint(t[r]);}function _u(t,e){for(var r=0;r<t.length;r++)e.writeSVarint(t[r]);}function wu(t,e){for(var r=0;r<t.length;r++)e.writeFloat(t[r]);}function Au(t,e){for(var r=0;r<t.length;r++)e.writeDouble(t[r]);}function Su(t,e){for(var r=0;r<t.length;r++)e.writeBoolean(t[r]);}function ku(t,e){for(var r=0;r<t.length;r++)e.writeFixed32(t[r]);}function zu(t,e){for(var r=0;r<t.length;r++)e.writeSFixed32(t[r]);}function Iu(t,e){for(var r=0;r<t.length;r++)e.writeFixed64(t[r]);}function Bu(t,e){for(var r=0;r<t.length;r++)e.writeSFixed64(t[r]);}function Cu(t,e){return (t[e]|t[e+1]<<8|t[e+2]<<16)+16777216*t[e+3]}function Eu(t,e,r){t[r]=e,t[r+1]=e>>>8,t[r+2]=e>>>16,t[r+3]=e>>>24;}function Mu(t,e){return (t[e]|t[e+1]<<8|t[e+2]<<16)+(t[e+3]<<24)}mu.prototype={destroy:function(){this.buf=null;},readFields:function(t,e,r){for(r=r||this.length;this.pos<r;){var n=this.readVarint(),i=n>>3,a=this.pos;this.type=7&n,t(i,e,this),this.pos===a&&this.skip(n);}return e},readMessage:function(t,e){return this.readFields(t,e,this.readVarint()+this.pos)},readFixed32:function(){var t=Cu(this.buf,this.pos);return this.pos+=4,t},readSFixed32:function(){var t=Mu(this.buf,this.pos);return this.pos+=4,t},readFixed64:function(){var t=Cu(this.buf,this.pos)+4294967296*Cu(this.buf,this.pos+4);return this.pos+=8,t},readSFixed64:function(){var t=Cu(this.buf,this.pos)+4294967296*Mu(this.buf,this.pos+4);return this.pos+=8,t},readFloat:function(){var t=fu(this.buf,this.pos,!0,23,4);return this.pos+=4,t},readDouble:function(){var t=fu(this.buf,this.pos,!0,52,8);return this.pos+=8,t},readVarint:function(t){var e,r,n=this.buf;return e=127&(r=n[this.pos++]),r<128?e:(e|=(127&(r=n[this.pos++]))<<7,r<128?e:(e|=(127&(r=n[this.pos++]))<<14,r<128?e:(e|=(127&(r=n[this.pos++]))<<21,r<128?e:function(t,e,r){var n,i,a=r.buf;if(i=a[r.pos++],n=(112&i)>>4,i<128)return gu(t,n,e);if(i=a[r.pos++],n|=(127&i)<<3,i<128)return gu(t,n,e);if(i=a[r.pos++],n|=(127&i)<<10,i<128)return gu(t,n,e);if(i=a[r.pos++],n|=(127&i)<<17,i<128)return gu(t,n,e);if(i=a[r.pos++],n|=(127&i)<<24,i<128)return gu(t,n,e);if(i=a[r.pos++],n|=(1&i)<<31,i<128)return gu(t,n,e);throw new Error(\"Expected varint not more than 10 bytes\")}(e|=(15&(r=n[this.pos]))<<28,t,this))))},readVarint64:function(){return this.readVarint(!0)},readSVarint:function(){var t=this.readVarint();return t%2==1?(t+1)/-2:t/2},readBoolean:function(){return Boolean(this.readVarint())},readString:function(){var t=this.readVarint()+this.pos,e=function(t,e,r){var n=\"\",i=e;for(;i<r;){var a,o,s,u=t[i],l=null,p=u>239?4:u>223?3:u>191?2:1;if(i+p>r)break;1===p?u<128&&(l=u):2===p?128==(192&(a=t[i+1]))&&(l=(31&u)<<6|63&a)<=127&&(l=null):3===p?(a=t[i+1],o=t[i+2],128==(192&a)&&128==(192&o)&&((l=(15&u)<<12|(63&a)<<6|63&o)<=2047||l>=55296&&l<=57343)&&(l=null)):4===p&&(a=t[i+1],o=t[i+2],s=t[i+3],128==(192&a)&&128==(192&o)&&128==(192&s)&&((l=(15&u)<<18|(63&a)<<12|(63&o)<<6|63&s)<=65535||l>=1114112)&&(l=null)),null===l?(l=65533,p=1):l>65535&&(l-=65536,n+=String.fromCharCode(l>>>10&1023|55296),l=56320|1023&l),n+=String.fromCharCode(l),i+=p;}return n}(this.buf,this.pos,t);return this.pos=t,e},readBytes:function(){var t=this.readVarint()+this.pos,e=this.buf.subarray(this.pos,t);return this.pos=t,e},readPackedVarint:function(t,e){if(this.type!==mu.Bytes)return t.push(this.readVarint(e));var r=vu(this);for(t=t||[];this.pos<r;)t.push(this.readVarint(e));return t},readPackedSVarint:function(t){if(this.type!==mu.Bytes)return t.push(this.readSVarint());var e=vu(this);for(t=t||[];this.pos<e;)t.push(this.readSVarint());return t},readPackedBoolean:function(t){if(this.type!==mu.Bytes)return t.push(this.readBoolean());var e=vu(this);for(t=t||[];this.pos<e;)t.push(this.readBoolean());return t},readPackedFloat:function(t){if(this.type!==mu.Bytes)return t.push(this.readFloat());var e=vu(this);for(t=t||[];this.pos<e;)t.push(this.readFloat());return t},readPackedDouble:function(t){if(this.type!==mu.Bytes)return t.push(this.readDouble());var e=vu(this);for(t=t||[];this.pos<e;)t.push(this.readDouble());return t},readPackedFixed32:function(t){if(this.type!==mu.Bytes)return t.push(this.readFixed32());var e=vu(this);for(t=t||[];this.pos<e;)t.push(this.readFixed32());return t},readPackedSFixed32:function(t){if(this.type!==mu.Bytes)return t.push(this.readSFixed32());var e=vu(this);for(t=t||[];this.pos<e;)t.push(this.readSFixed32());return t},readPackedFixed64:function(t){if(this.type!==mu.Bytes)return t.push(this.readFixed64());var e=vu(this);for(t=t||[];this.pos<e;)t.push(this.readFixed64());return t},readPackedSFixed64:function(t){if(this.type!==mu.Bytes)return t.push(this.readSFixed64());var e=vu(this);for(t=t||[];this.pos<e;)t.push(this.readSFixed64());return t},skip:function(t){var e=7&t;if(e===mu.Varint)for(;this.buf[this.pos++]>127;);else if(e===mu.Bytes)this.pos=this.readVarint()+this.pos;else if(e===mu.Fixed32)this.pos+=4;else{if(e!==mu.Fixed64)throw new Error(\"Unimplemented type: \"+e);this.pos+=8;}},writeTag:function(t,e){this.writeVarint(t<<3|e);},realloc:function(t){for(var e=this.length||16;e<this.pos+t;)e*=2;if(e!==this.length){var r=new Uint8Array(e);r.set(this.buf),this.buf=r,this.length=e;}},finish:function(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)},writeFixed32:function(t){this.realloc(4),Eu(this.buf,t,this.pos),this.pos+=4;},writeSFixed32:function(t){this.realloc(4),Eu(this.buf,t,this.pos),this.pos+=4;},writeFixed64:function(t){this.realloc(8),Eu(this.buf,-1&t,this.pos),Eu(this.buf,Math.floor(t*(1/4294967296)),this.pos+4),this.pos+=8;},writeSFixed64:function(t){this.realloc(8),Eu(this.buf,-1&t,this.pos),Eu(this.buf,Math.floor(t*(1/4294967296)),this.pos+4),this.pos+=8;},writeVarint:function(t){(t=+t||0)>268435455||t<0?function(t,e){var r,n;t>=0?(r=t%4294967296|0,n=t/4294967296|0):(n=~(-t/4294967296),4294967295^(r=~(-t%4294967296))?r=r+1|0:(r=0,n=n+1|0));if(t>=0x10000000000000000||t<-0x10000000000000000)throw new Error(\"Given varint doesn't fit into 10 bytes\");e.realloc(10),function(t,e,r){r.buf[r.pos++]=127&t|128,t>>>=7,r.buf[r.pos++]=127&t|128,t>>>=7,r.buf[r.pos++]=127&t|128,t>>>=7,r.buf[r.pos++]=127&t|128,t>>>=7,r.buf[r.pos]=127&t;}(r,0,e),function(t,e){var r=(7&t)<<4;if(e.buf[e.pos++]|=r|((t>>>=3)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;e.buf[e.pos++]=127&t;}(n,e);}(t,this):(this.realloc(4),this.buf[this.pos++]=127&t|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=t>>>7&127))));},writeSVarint:function(t){this.writeVarint(t<0?2*-t-1:2*t);},writeBoolean:function(t){this.writeVarint(Boolean(t));},writeString:function(t){t=String(t),this.realloc(4*t.length),this.pos++;var e=this.pos;this.pos=function(t,e,r){for(var n,i,a=0;a<e.length;a++){if((n=e.charCodeAt(a))>55295&&n<57344){if(!i){n>56319||a+1===e.length?(t[r++]=239,t[r++]=191,t[r++]=189):i=n;continue}if(n<56320){t[r++]=239,t[r++]=191,t[r++]=189,i=n;continue}n=i-55296<<10|n-56320|65536,i=null;}else i&&(t[r++]=239,t[r++]=191,t[r++]=189,i=null);n<128?t[r++]=n:(n<2048?t[r++]=n>>6|192:(n<65536?t[r++]=n>>12|224:(t[r++]=n>>18|240,t[r++]=n>>12&63|128),t[r++]=n>>6&63|128),t[r++]=63&n|128);}return r}(this.buf,t,this.pos);var r=this.pos-e;r>=128&&xu(e,r,this),this.pos=e-1,this.writeVarint(r),this.pos+=r;},writeFloat:function(t){this.realloc(4),yu(this.buf,t,this.pos,!0,23,4),this.pos+=4;},writeDouble:function(t){this.realloc(8),yu(this.buf,t,this.pos,!0,52,8),this.pos+=8;},writeBytes:function(t){var e=t.length;this.writeVarint(e),this.realloc(e);for(var r=0;r<e;r++)this.buf[this.pos++]=t[r];},writeRawMessage:function(t,e){this.pos++;var r=this.pos;t(e,this);var n=this.pos-r;n>=128&&xu(r,n,this),this.pos=r-1,this.writeVarint(n),this.pos+=n;},writeMessage:function(t,e,r){this.writeTag(t,mu.Bytes),this.writeRawMessage(e,r);},writePackedVarint:function(t,e){e.length&&this.writeMessage(t,bu,e);},writePackedSVarint:function(t,e){e.length&&this.writeMessage(t,_u,e);},writePackedBoolean:function(t,e){e.length&&this.writeMessage(t,Su,e);},writePackedFloat:function(t,e){e.length&&this.writeMessage(t,wu,e);},writePackedDouble:function(t,e){e.length&&this.writeMessage(t,Au,e);},writePackedFixed32:function(t,e){e.length&&this.writeMessage(t,ku,e);},writePackedSFixed32:function(t,e){e.length&&this.writeMessage(t,zu,e);},writePackedFixed64:function(t,e){e.length&&this.writeMessage(t,Iu,e);},writePackedSFixed64:function(t,e){e.length&&this.writeMessage(t,Bu,e);},writeBytesField:function(t,e){this.writeTag(t,mu.Bytes),this.writeBytes(e);},writeFixed32Field:function(t,e){this.writeTag(t,mu.Fixed32),this.writeFixed32(e);},writeSFixed32Field:function(t,e){this.writeTag(t,mu.Fixed32),this.writeSFixed32(e);},writeFixed64Field:function(t,e){this.writeTag(t,mu.Fixed64),this.writeFixed64(e);},writeSFixed64Field:function(t,e){this.writeTag(t,mu.Fixed64),this.writeSFixed64(e);},writeVarintField:function(t,e){this.writeTag(t,mu.Varint),this.writeVarint(e);},writeSVarintField:function(t,e){this.writeTag(t,mu.Varint),this.writeSVarint(e);},writeStringField:function(t,e){this.writeTag(t,mu.Bytes),this.writeString(e);},writeFloatField:function(t,e){this.writeTag(t,mu.Fixed32),this.writeFloat(e);},writeDoubleField:function(t,e){this.writeTag(t,mu.Fixed64),this.writeDouble(e);},writeBooleanField:function(t,e){this.writeVarintField(t,Boolean(e));}};var Tu=3;function Pu(t,e,r){1===t&&r.readMessage(Vu,e);}function Vu(t,e,r){if(3===t){var n=r.readMessage(Fu,{}),i=n.id,a=n.bitmap,o=n.width,s=n.height,u=n.left,l=n.top,p=n.advance;e.push({id:i,bitmap:new ao({width:o+2*Tu,height:s+2*Tu},a),metrics:{width:o,height:s,left:u,top:l,advance:p}});}}function Fu(t,e,r){1===t?e.id=r.readVarint():2===t?e.bitmap=r.readBytes():3===t?e.width=r.readVarint():4===t?e.height=r.readVarint():5===t?e.left=r.readSVarint():6===t?e.top=r.readSVarint():7===t&&(e.advance=r.readVarint());}var Lu=Tu,Du=function(t,e,r){this.target=t,this.parent=e,this.mapId=r,this.callbacks={},this.callbackID=0,m([\"receive\"],this),this.target.addEventListener(\"message\",this.receive,!1);};function Ou(t,e,r){var n=2*Math.PI*6378137/256/Math.pow(2,r);return [t*n-2*Math.PI*6378137/2,e*n-2*Math.PI*6378137/2]}Du.prototype.send=function(t,e,r,n){var i=this,a=r?this.mapId+\":\"+this.callbackID++:null;r&&(this.callbacks[a]=r);var o=[];if(this.target.postMessage({targetMapId:n,sourceMapId:this.mapId,type:t,id:String(a),data:Bn(e,o)},o),r)return {cancel:function(){i.callbacks[a]=null,i.target.postMessage({targetMapId:n,sourceMapId:i.mapId,type:\"<cancel>\",id:String(a)});}}},Du.prototype.receive=function(t){var e,r=this,n=t.data,i=n.id;if(!n.targetMapId||this.mapId===n.targetMapId){var a=function(t,e){delete r.callbacks[i];var n=[];r.target.postMessage({sourceMapId:r.mapId,type:\"<response>\",id:String(i),error:t?Bn(t):null,data:Bn(e,n)},n);};if(\"<response>\"===n.type||\"<cancel>\"===n.type)e=this.callbacks[n.id],delete this.callbacks[n.id],e&&n.error?e(Cn(n.error)):e&&e(null,Cn(n.data));else if(void 0!==n.id&&this.parent[n.type]){this.callbacks[n.id]=null;var o=this.parent[n.type](n.sourceMapId,Cn(n.data),a);o&&null===this.callbacks[n.id]&&(this.callbacks[n.id]=o.cancel);}else if(void 0!==n.id&&this.parent.getWorkerSource){var s=n.type.split(\".\"),u=Cn(n.data);this.parent.getWorkerSource(n.sourceMapId,s[0],u.source)[s[1]](u,a);}else this.parent[n.type](Cn(n.data));}},Du.prototype.remove=function(){this.target.removeEventListener(\"message\",this.receive,!1);};var Ru=function(t,e){t&&(e?this.setSouthWest(t).setNorthEast(e):4===t.length?this.setSouthWest([t[0],t[1]]).setNorthEast([t[2],t[3]]):this.setSouthWest(t[0]).setNorthEast(t[1]));};Ru.prototype.setNorthEast=function(t){return this._ne=t instanceof Uu?new Uu(t.lng,t.lat):Uu.convert(t),this},Ru.prototype.setSouthWest=function(t){return this._sw=t instanceof Uu?new Uu(t.lng,t.lat):Uu.convert(t),this},Ru.prototype.extend=function(t){var e,r,n=this._sw,i=this._ne;if(t instanceof Uu)e=t,r=t;else{if(!(t instanceof Ru))return Array.isArray(t)?t.every(Array.isArray)?this.extend(Ru.convert(t)):this.extend(Uu.convert(t)):this;if(e=t._sw,r=t._ne,!e||!r)return this}return n||i?(n.lng=Math.min(e.lng,n.lng),n.lat=Math.min(e.lat,n.lat),i.lng=Math.max(r.lng,i.lng),i.lat=Math.max(r.lat,i.lat)):(this._sw=new Uu(e.lng,e.lat),this._ne=new Uu(r.lng,r.lat)),this},Ru.prototype.getCenter=function(){return new Uu((this._sw.lng+this._ne.lng)/2,(this._sw.lat+this._ne.lat)/2)},Ru.prototype.getSouthWest=function(){return this._sw},Ru.prototype.getNorthEast=function(){return this._ne},Ru.prototype.getNorthWest=function(){return new Uu(this.getWest(),this.getNorth())},Ru.prototype.getSouthEast=function(){return new Uu(this.getEast(),this.getSouth())},Ru.prototype.getWest=function(){return this._sw.lng},Ru.prototype.getSouth=function(){return this._sw.lat},Ru.prototype.getEast=function(){return this._ne.lng},Ru.prototype.getNorth=function(){return this._ne.lat},Ru.prototype.toArray=function(){return [this._sw.toArray(),this._ne.toArray()]},Ru.prototype.toString=function(){return \"LngLatBounds(\"+this._sw.toString()+\", \"+this._ne.toString()+\")\"},Ru.prototype.isEmpty=function(){return !(this._sw&&this._ne)},Ru.convert=function(t){return !t||t instanceof Ru?t:new Ru(t)};var Uu=function(t,e){if(isNaN(t)||isNaN(e))throw new Error(\"Invalid LngLat object: (\"+t+\", \"+e+\")\");if(this.lng=+t,this.lat=+e,this.lat>90||this.lat<-90)throw new Error(\"Invalid LngLat latitude value: must be between -90 and 90\")};function ju(t){return 2*Math.PI*6378137*Math.cos(t*Math.PI/180)}function qu(t){return (180+t)/360}function Nu(t){return (180-180/Math.PI*Math.log(Math.tan(Math.PI/4+t*Math.PI/360)))/360}function Zu(t,e){return t/ju(e)}function Ku(t){var e=180-360*t;return 360/Math.PI*Math.atan(Math.exp(e*Math.PI/180))-90}Uu.prototype.wrap=function(){return new Uu(p(this.lng,-180,180),this.lat)},Uu.prototype.toArray=function(){return [this.lng,this.lat]},Uu.prototype.toString=function(){return \"LngLat(\"+this.lng+\", \"+this.lat+\")\"},Uu.prototype.toBounds=function(t){void 0===t&&(t=0);var e=360*t/40075017,r=e/Math.cos(Math.PI/180*this.lat);return new Ru(new Uu(this.lng-r,this.lat-e),new Uu(this.lng+r,this.lat+e))},Uu.convert=function(t){if(t instanceof Uu)return t;if(Array.isArray(t)&&(2===t.length||3===t.length))return new Uu(Number(t[0]),Number(t[1]));if(!Array.isArray(t)&&\"object\"==typeof t&&null!==t)return new Uu(Number(\"lng\"in t?t.lng:t.lon),Number(t.lat));throw new Error(\"`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]\")};var Gu=function(t,e,r){void 0===r&&(r=0),this.x=+t,this.y=+e,this.z=+r;};Gu.fromLngLat=function(t,e){void 0===e&&(e=0);var r=Uu.convert(t);return new Gu(qu(r.lng),Nu(r.lat),Zu(e,r.lat))},Gu.prototype.toLngLat=function(){return new Uu(360*this.x-180,Ku(this.y))},Gu.prototype.toAltitude=function(){return t=this.z,e=this.y,t*ju(Ku(e));var t,e;};var Xu=function(t,e,r){this.z=t,this.x=e,this.y=r,this.key=Yu(0,t,e,r);};Xu.prototype.equals=function(t){return this.z===t.z&&this.x===t.x&&this.y===t.y},Xu.prototype.url=function(t,e){var r,n,i,a,o,s=(r=this.x,n=this.y,i=this.z,a=Ou(256*r,256*(n=Math.pow(2,i)-n-1),i),o=Ou(256*(r+1),256*(n+1),i),a[0]+\",\"+a[1]+\",\"+o[0]+\",\"+o[1]),u=function(t,e,r){for(var n,i=\"\",a=t;a>0;a--)i+=(e&(n=1<<a-1)?1:0)+(r&n?2:0);return i}(this.z,this.x,this.y);return t[(this.x+this.y)%t.length].replace(\"{prefix}\",(this.x%16).toString(16)+(this.y%16).toString(16)).replace(\"{z}\",String(this.z)).replace(\"{x}\",String(this.x)).replace(\"{y}\",String(\"tms\"===e?Math.pow(2,this.z)-this.y-1:this.y)).replace(\"{quadkey}\",u).replace(\"{bbox-epsg-3857}\",s)},Xu.prototype.getTilePoint=function(t){var e=Math.pow(2,this.z);return new i((t.x*e-this.x)*ya,(t.y*e-this.y)*ya)};var Ju=function(t,e){this.wrap=t,this.canonical=e,this.key=Yu(t,e.z,e.x,e.y);},Hu=function(t,e,r,n,i){this.overscaledZ=t,this.wrap=e,this.canonical=new Xu(r,+n,+i),this.key=Yu(e,t,n,i);};function Yu(t,e,r,n){(t*=2)<0&&(t=-1*t-1);var i=1<<e;return 32*(i*i*t+i*n+r)+e}Hu.prototype.equals=function(t){return this.overscaledZ===t.overscaledZ&&this.wrap===t.wrap&&this.canonical.equals(t.canonical)},Hu.prototype.scaledTo=function(t){var e=this.canonical.z-t;return t>this.canonical.z?new Hu(t,this.wrap,this.canonical.z,this.canonical.x,this.canonical.y):new Hu(t,this.wrap,t,this.canonical.x>>e,this.canonical.y>>e)},Hu.prototype.isChildOf=function(t){if(t.wrap!==this.wrap)return !1;var e=this.canonical.z-t.canonical.z;return 0===t.overscaledZ||t.overscaledZ<this.overscaledZ&&t.canonical.x===this.canonical.x>>e&&t.canonical.y===this.canonical.y>>e},Hu.prototype.children=function(t){if(this.overscaledZ>=t)return [new Hu(this.overscaledZ+1,this.wrap,this.canonical.z,this.canonical.x,this.canonical.y)];var e=this.canonical.z+1,r=2*this.canonical.x,n=2*this.canonical.y;return [new Hu(e,this.wrap,e,r,n),new Hu(e,this.wrap,e,r+1,n),new Hu(e,this.wrap,e,r,n+1),new Hu(e,this.wrap,e,r+1,n+1)]},Hu.prototype.isLessThan=function(t){return this.wrap<t.wrap||!(this.wrap>t.wrap)&&(this.overscaledZ<t.overscaledZ||!(this.overscaledZ>t.overscaledZ)&&(this.canonical.x<t.canonical.x||!(this.canonical.x>t.canonical.x)&&this.canonical.y<t.canonical.y))},Hu.prototype.wrapped=function(){return new Hu(this.overscaledZ,0,this.canonical.z,this.canonical.x,this.canonical.y)},Hu.prototype.unwrapTo=function(t){return new Hu(this.overscaledZ,t,this.canonical.z,this.canonical.x,this.canonical.y)},Hu.prototype.overscaleFactor=function(){return Math.pow(2,this.overscaledZ-this.canonical.z)},Hu.prototype.toUnwrapped=function(){return new Ju(this.wrap,this.canonical)},Hu.prototype.toString=function(){return this.overscaledZ+\"/\"+this.canonical.x+\"/\"+this.canonical.y},Hu.prototype.getTilePoint=function(t){return this.canonical.getTilePoint(new Gu(t.x-this.wrap,t.y))},zn(\"CanonicalTileID\",Xu),zn(\"OverscaledTileID\",Hu,{omit:[\"posMatrix\"]});var $u=function(t,e,r){if(this.uid=t,e.height!==e.width)throw new RangeError(\"DEM tiles must be square\");if(r&&\"mapbox\"!==r&&\"terrarium\"!==r)return w('\"'+r+'\" is not a valid encoding type. Valid types include \"mapbox\" and \"terrarium\".');var n=this.dim=e.height;this.stride=this.dim+2,this.data=new Int32Array(this.stride*this.stride);for(var i=e.data,a=\"terrarium\"===r?this._unpackTerrarium:this._unpackMapbox,o=0;o<n;o++)for(var s=0;s<n;s++){var u=4*(o*n+s);this.set(s,o,a(i[u],i[u+1],i[u+2]));}for(var l=0;l<n;l++)this.set(-1,l,this.get(0,l)),this.set(n,l,this.get(n-1,l)),this.set(l,-1,this.get(l,0)),this.set(l,n,this.get(l,n-1));this.set(-1,-1,this.get(0,0)),this.set(n,-1,this.get(n-1,0)),this.set(-1,n,this.get(0,n-1)),this.set(n,n,this.get(n-1,n-1));};$u.prototype.set=function(t,e,r){this.data[this._idx(t,e)]=r+65536;},$u.prototype.get=function(t,e){return this.data[this._idx(t,e)]-65536},$u.prototype._idx=function(t,e){if(t<-1||t>=this.dim+1||e<-1||e>=this.dim+1)throw new RangeError(\"out of range source coordinates for DEM data\");return (e+1)*this.stride+(t+1)},$u.prototype._unpackMapbox=function(t,e,r){return (256*t*256+256*e+r)/10-1e4},$u.prototype._unpackTerrarium=function(t,e,r){return 256*t+e+r/256-32768},$u.prototype.getPixels=function(){return new oo({width:this.stride,height:this.stride},new Uint8Array(this.data.buffer))},$u.prototype.backfillBorder=function(t,e,r){if(this.dim!==t.dim)throw new Error(\"dem dimension mismatch\");var n=e*this.dim,i=e*this.dim+this.dim,a=r*this.dim,o=r*this.dim+this.dim;switch(e){case-1:n=i-1;break;case 1:i=n+1;}switch(r){case-1:a=o-1;break;case 1:o=a+1;}for(var s=-e*this.dim,u=-r*this.dim,l=a;l<o;l++)for(var p=n;p<i;p++)this.set(p,l,t.get(p+s,l+u));},zn(\"DEMData\",$u);var Wu=li([{name:\"a_pos\",type:\"Int16\",components:2},{name:\"a_texture_pos\",type:\"Int16\",components:2}]);var Qu=function(t){this._stringToNumber={},this._numberToString=[];for(var e=0;e<t.length;e++){var r=t[e];this._stringToNumber[r]=e,this._numberToString[e]=r;}};Qu.prototype.encode=function(t){return this._stringToNumber[t]},Qu.prototype.decode=function(t){return this._numberToString[t]};var tl=function(t,e,r,n){this.type=\"Feature\",this._vectorTileFeature=t,t._z=e,t._x=r,t._y=n,this.properties=t.properties,null!=t.id&&(this.id=t.id);},el={geometry:{configurable:!0}};el.geometry.get=function(){return void 0===this._geometry&&(this._geometry=this._vectorTileFeature.toGeoJSON(this._vectorTileFeature._x,this._vectorTileFeature._y,this._vectorTileFeature._z).geometry),this._geometry},el.geometry.set=function(t){this._geometry=t;},tl.prototype.toJSON=function(){var t={geometry:this.geometry};for(var e in this)\"_geometry\"!==e&&\"_vectorTileFeature\"!==e&&(t[e]=this[e]);return t},Object.defineProperties(tl.prototype,el);var rl=function(){this.state={},this.stateChanges={},this.deletedStates={};};rl.prototype.updateState=function(t,e,r){var n=String(e);if(this.stateChanges[t]=this.stateChanges[t]||{},this.stateChanges[t][n]=this.stateChanges[t][n]||{},c(this.stateChanges[t][n],r),null===this.deletedStates[t])for(var i in this.deletedStates[t]={},this.state[t])i!==n&&(this.deletedStates[t][i]=null);else if(this.deletedStates[t]&&null===this.deletedStates[t][n])for(var a in this.deletedStates[t][n]={},this.state[t][n])r[a]||(this.deletedStates[t][n][a]=null);else for(var o in r){this.deletedStates[t]&&this.deletedStates[t][n]&&null===this.deletedStates[t][n][o]&&delete this.deletedStates[t][n][o];}},rl.prototype.removeFeatureState=function(t,e,r){if(!(null===this.deletedStates[t])){var n=String(e);if(this.deletedStates[t]=this.deletedStates[t]||{},r&&void 0!==e&&e>=0)null!==this.deletedStates[t][n]&&(this.deletedStates[t][n]=this.deletedStates[t][n]||{},this.deletedStates[t][n][r]=null);else if(void 0!==e&&e>=0){if(this.stateChanges[t]&&this.stateChanges[t][n])for(r in this.deletedStates[t][n]={},this.stateChanges[t][n])this.deletedStates[t][n][r]=null;else this.deletedStates[t][n]=null;}else this.deletedStates[t]=null;}},rl.prototype.getState=function(t,e){var r=String(e),n=this.state[t]||{},i=this.stateChanges[t]||{},a=c({},n[r],i[r]);if(null===this.deletedStates[t])return {};if(this.deletedStates[t]){var o=this.deletedStates[t][e];if(null===o)return {};for(var s in o)delete a[s];}return a},rl.prototype.initializeTileState=function(t,e){t.setFeatureState(this.state,e);},rl.prototype.coalesceChanges=function(t,e){var r={};for(var n in this.stateChanges){this.state[n]=this.state[n]||{};var i={};for(var a in this.stateChanges[n])this.state[n][a]||(this.state[n][a]={}),c(this.state[n][a],this.stateChanges[n][a]),i[a]=this.state[n][a];r[n]=i;}for(var o in this.deletedStates){this.state[o]=this.state[o]||{};var s={};if(null===this.deletedStates[o])for(var u in this.state[o])s[u]={},this.state[o][u]={};else for(var l in this.deletedStates[o]){if(null===this.deletedStates[o][l])this.state[o][l]={};else for(var p=0,h=Object.keys(this.deletedStates[o][l]);p<h.length;p+=1){var f=h[p];delete this.state[o][l][f];}s[l]=this.state[o][l];}r[o]=r[o]||{},c(r[o],s);}if(this.stateChanges={},this.deletedStates={},0!==Object.keys(r).length)for(var y in t){t[y].setFeatureState(r,e);}};var nl=function(t,e,r){this.tileID=t,this.x=t.canonical.x,this.y=t.canonical.y,this.z=t.canonical.z,this.grid=e||new _n(ya,16,0),this.grid3D=new _n(ya,16,0),this.featureIndexArray=r||new Ni;};function il(t){for(var e=1/0,r=1/0,n=-1/0,i=-1/0,a=0,o=t;a<o.length;a+=1){var s=o[a];e=Math.min(e,s.x),r=Math.min(r,s.y),n=Math.max(n,s.x),i=Math.max(i,s.y);}return {minX:e,minY:r,maxX:n,maxY:i}}function al(t,e){return e-t}nl.prototype.insert=function(t,e,r,n,i,a){var o=this.featureIndexArray.length;this.featureIndexArray.emplaceBack(r,n,i);for(var s=a?this.grid3D:this.grid,u=0;u<e.length;u++){for(var l=e[u],p=[1/0,1/0,-1/0,-1/0],c=0;c<l.length;c++){var h=l[c];p[0]=Math.min(p[0],h.x),p[1]=Math.min(p[1],h.y),p[2]=Math.max(p[2],h.x),p[3]=Math.max(p[3],h.y);}p[0]<ya&&p[1]<ya&&p[2]>=0&&p[3]>=0&&s.insert(o,p[0],p[1],p[2],p[3]);}},nl.prototype.loadVTLayers=function(){return this.vtLayers||(this.vtLayers=new is.VectorTile(new du(this.rawTileData)).layers,this.sourceLayerCoder=new Qu(this.vtLayers?Object.keys(this.vtLayers).sort():[\"_geojsonTileLayer\"])),this.vtLayers},nl.prototype.query=function(t,e,r){var n=this;this.loadVTLayers();for(var a=t.params||{},o=ya/t.tileSize/t.scale,s=Jr(a.filter),u=t.queryGeometry,l=t.queryPadding*o,p=il(u),c=this.grid.query(p.minX-l,p.minY-l,p.maxX+l,p.maxY+l),h=il(t.cameraQueryGeometry),f=this.grid3D.query(h.minX-l,h.minY-l,h.maxX+l,h.maxY+l,function(e,r,n,a){return function(t,e,r,n,a){for(var o=0,s=t;o<s.length;o+=1){var u=s[o];if(e<=u.x&&r<=u.y&&n>=u.x&&a>=u.y)return !0}var l=[new i(e,r),new i(e,a),new i(n,a),new i(n,r)];if(t.length>2)for(var p=0,c=l;p<c.length;p+=1)if(Ca(t,c[p]))return !0;for(var h=0;h<t.length-1;h++)if(Ea(t[h],t[h+1],l))return !0;return !1}(t.cameraQueryGeometry,e-l,r-l,n+l,a+l)}),y=0,d=f;y<d.length;y+=1){var m=d[y];c.push(m);}c.sort(al);for(var v,g={},x=function(i){var l=c[i];if(l!==v){v=l;var p=n.featureIndexArray.get(l),h=null;n.loadMatchingFeature(g,p.bucketIndex,p.sourceLayerIndex,p.featureIndex,s,a.layers,e,function(e,i){h||(h=va(e));var a={};return e.id&&(a=r.getState(i.sourceLayer||\"_geojsonTileLayer\",e.id)),i.queryIntersectsFeature(u,e,a,h,n.z,t.transform,o,t.pixelPosMatrix)});}},b=0;b<c.length;b++)x(b);return g},nl.prototype.loadMatchingFeature=function(t,e,r,n,i,a,o,s){var u=this.bucketLayerIDs[e];if(!a||function(t,e){for(var r=0;r<t.length;r++)if(e.indexOf(t[r])>=0)return !0;return !1}(a,u)){var l=this.sourceLayerCoder.decode(r),p=this.vtLayers[l].feature(n);if(i(new Zn(this.tileID.overscaledZ),p))for(var c=0;c<u.length;c++){var h=u[c];if(!(a&&a.indexOf(h)<0)){var f=o[h];if(f){var y=!s||s(p,f);if(y){var d=new tl(p,this.z,this.x,this.y);d.layer=f.serialize();var m=t[h];void 0===m&&(m=t[h]=[]),m.push({featureIndex:n,feature:d,intersectionZ:y});}}}}}},nl.prototype.lookupSymbolFeatures=function(t,e,r,n,i,a){var o={};this.loadVTLayers();for(var s=Jr(n),u=0,l=t;u<l.length;u+=1){var p=l[u];this.loadMatchingFeature(o,e,r,p,s,i,a);}return o},nl.prototype.hasLayer=function(t){for(var e=0,r=this.bucketLayerIDs;e<r.length;e+=1)for(var n=0,i=r[e];n<i.length;n+=1){if(t===i[n])return !0}return !1},zn(\"FeatureIndex\",nl,{omit:[\"rawTileData\",\"sourceLayerCoder\"]});var ol=function(t,e){this.tileID=t,this.uid=f(),this.uses=0,this.tileSize=e,this.buckets={},this.expirationTime=null,this.queryPadding=0,this.hasSymbolBuckets=!1,this.expiredRequestCount=0,this.state=\"loading\";};ol.prototype.registerFadeDuration=function(t){var e=t+this.timeAdded;e<P.now()||this.fadeEndTime&&e<this.fadeEndTime||(this.fadeEndTime=e);},ol.prototype.wasRequested=function(){return \"errored\"===this.state||\"loaded\"===this.state||\"reloading\"===this.state},ol.prototype.loadVectorData=function(t,e,r){if(this.hasData()&&this.unloadVectorData(),this.state=\"loaded\",t){for(var n in t.featureIndex&&(this.latestFeatureIndex=t.featureIndex,t.rawTileData?(this.latestRawTileData=t.rawTileData,this.latestFeatureIndex.rawTileData=t.rawTileData):this.latestRawTileData&&(this.latestFeatureIndex.rawTileData=this.latestRawTileData)),this.collisionBoxArray=t.collisionBoxArray,this.buckets=function(t,e){var r={};if(!e)return r;for(var n=function(){var t=a[i],n=t.layerIds.map(function(t){return e.getLayer(t)}).filter(Boolean);if(0!==n.length){t.layers=n,t.stateDependentLayerIds&&(t.stateDependentLayers=t.stateDependentLayerIds.map(function(t){return n.filter(function(e){return e.id===t})[0]}));for(var o=0,s=n;o<s.length;o+=1){var u=s[o];r[u.id]=t;}}},i=0,a=t;i<a.length;i+=1)n();return r}(t.buckets,e.style),this.hasSymbolBuckets=!1,this.buckets){var i=this.buckets[n];if(i instanceof Js){if(this.hasSymbolBuckets=!0,!r)break;i.justReloaded=!0;}}for(var a in this.queryPadding=0,this.buckets){var o=this.buckets[a];this.queryPadding=Math.max(this.queryPadding,e.style.getLayer(a).queryRadius(o));}t.imageAtlas&&(this.imageAtlas=t.imageAtlas),t.glyphAtlasImage&&(this.glyphAtlasImage=t.glyphAtlasImage);}else this.collisionBoxArray=new Pi;},ol.prototype.unloadVectorData=function(){for(var t in this.buckets)this.buckets[t].destroy();this.buckets={},this.imageAtlasTexture&&this.imageAtlasTexture.destroy(),this.imageAtlas&&(this.imageAtlas=null),this.glyphAtlasTexture&&this.glyphAtlasTexture.destroy(),this.latestFeatureIndex=null,this.state=\"unloaded\";},ol.prototype.unloadDEMData=function(){this.dem=null,this.neighboringTiles=null,this.state=\"unloaded\";},ol.prototype.getBucket=function(t){return this.buckets[t.id]},ol.prototype.upload=function(t){for(var e in this.buckets){var r=this.buckets[e];r.uploadPending()&&r.upload(t);}var n=t.gl;this.imageAtlas&&!this.imageAtlas.uploaded&&(this.imageAtlasTexture=new hu(t,this.imageAtlas.image,n.RGBA),this.imageAtlas.uploaded=!0),this.glyphAtlasImage&&(this.glyphAtlasTexture=new hu(t,this.glyphAtlasImage,n.ALPHA),this.glyphAtlasImage=null);},ol.prototype.prepare=function(t){this.imageAtlas&&this.imageAtlas.patchUpdatedImages(t,this.imageAtlasTexture);},ol.prototype.queryRenderedFeatures=function(t,e,r,n,i,a,o,s,u){return this.latestFeatureIndex&&this.latestFeatureIndex.rawTileData?this.latestFeatureIndex.query({queryGeometry:r,cameraQueryGeometry:n,scale:i,tileSize:this.tileSize,pixelPosMatrix:u,transform:o,params:a,queryPadding:this.queryPadding*s},t,e):{}},ol.prototype.querySourceFeatures=function(t,e){if(this.latestFeatureIndex&&this.latestFeatureIndex.rawTileData){var r=this.latestFeatureIndex.loadVTLayers(),n=e?e.sourceLayer:\"\",i=r._geojsonTileLayer||r[n];if(i)for(var a=Jr(e&&e.filter),o=this.tileID.canonical,s=o.z,u=o.x,l=o.y,p={z:s,x:u,y:l},c=0;c<i.length;c++){var h=i.feature(c);if(a(new Zn(this.tileID.overscaledZ),h)){var f=new tl(h,s,u,l);f.tile=p,t.push(f);}}}},ol.prototype.clearMask=function(){this.segments&&(this.segments.destroy(),delete this.segments),this.maskedBoundsBuffer&&(this.maskedBoundsBuffer.destroy(),delete this.maskedBoundsBuffer),this.maskedIndexBuffer&&(this.maskedIndexBuffer.destroy(),delete this.maskedIndexBuffer);},ol.prototype.setMask=function(t,e){if(!o(this.mask,t)&&(this.mask=t,this.clearMask(),!o(t,{0:!0}))){var r=new hi,n=new Ii;this.segments=new Ki,this.segments.prepareSegment(0,r,n);for(var a=Object.keys(t),s=0;s<a.length;s++){var u=t[+a[s]],l=ya>>u.z,p=new i(u.x*l,u.y*l),c=new i(p.x+l,p.y+l),h=this.segments.prepareSegment(4,r,n);r.emplaceBack(p.x,p.y,p.x,p.y),r.emplaceBack(c.x,p.y,c.x,p.y),r.emplaceBack(p.x,c.y,p.x,c.y),r.emplaceBack(c.x,c.y,c.x,c.y);var f=h.vertexLength;n.emplaceBack(f,f+1,f+2),n.emplaceBack(f+1,f+2,f+3),h.vertexLength+=4,h.primitiveLength+=2;}this.maskedBoundsBuffer=e.createVertexBuffer(r,Wu.members),this.maskedIndexBuffer=e.createIndexBuffer(n);}},ol.prototype.hasData=function(){return \"loaded\"===this.state||\"reloading\"===this.state||\"expired\"===this.state},ol.prototype.patternsLoaded=function(){return this.imageAtlas&&!!Object.keys(this.imageAtlas.patternPositions).length},ol.prototype.setExpiryData=function(t){var e=this.expirationTime;if(t.cacheControl){var r=k(t.cacheControl);r[\"max-age\"]&&(this.expirationTime=Date.now()+1e3*r[\"max-age\"]);}else t.expires&&(this.expirationTime=new Date(t.expires).getTime());if(this.expirationTime){var n=Date.now(),i=!1;if(this.expirationTime>n)i=!1;else if(e)if(this.expirationTime<e)i=!0;else{var a=this.expirationTime-e;a?this.expirationTime=n+Math.max(a,3e4):i=!0;}else i=!0;i?(this.expiredRequestCount++,this.state=\"expired\"):this.expiredRequestCount=0;}},ol.prototype.getExpiryTimeout=function(){if(this.expirationTime)return this.expiredRequestCount?1e3*(1<<Math.min(this.expiredRequestCount-1,31)):Math.min(this.expirationTime-(new Date).getTime(),Math.pow(2,31)-1)},ol.prototype.setFeatureState=function(t,e){if(this.latestFeatureIndex&&this.latestFeatureIndex.rawTileData&&0!==Object.keys(t).length){var r=this.latestFeatureIndex.loadVTLayers();for(var n in this.buckets){var i=this.buckets[n],a=i.layers[0].sourceLayer||\"_geojsonTileLayer\",o=r[a],s=t[a];o&&s&&0!==Object.keys(s).length&&(i.update(s,o,this.imageAtlas&&this.imageAtlas.patternPositions||{}),e&&e.style&&(this.queryPadding=Math.max(this.queryPadding,e.style.getLayer(n).queryRadius(i))));}}},ol.prototype.holdingForFade=function(){return void 0!==this.symbolFadeHoldUntil},ol.prototype.symbolFadeFinished=function(){return !this.symbolFadeHoldUntil||this.symbolFadeHoldUntil<P.now()},ol.prototype.clearFadeHold=function(){this.symbolFadeHoldUntil=void 0;},ol.prototype.setHoldDuration=function(t){this.symbolFadeHoldUntil=P.now()+t;};var sl=24,ul={horizontal:1,vertical:2,horizontalOnly:3},ll=function(){this.text=\"\",this.sectionIndex=[],this.sections=[];};function pl(t,e,r,n,i,a,o,s,u,l){var p,c=ll.fromFeature(t,r);l===ul.vertical&&c.verticalizePunctuation();var h=Nn.processBidirectionalText,f=Nn.processStyledBidirectionalText;if(h&&1===c.sections.length){p=[];for(var y=0,d=h(c.toString(),ml(c,s,n,e));y<d.length;y+=1){var m=d[y],v=new ll;v.text=m,v.sections=c.sections;for(var g=0;g<m.length;g++)v.sectionIndex.push(0);p.push(v);}}else if(f){p=[];for(var x=0,b=f(c.text,c.sectionIndex,ml(c,s,n,e));x<b.length;x+=1){var _=b[x],w=new ll;w.text=_[0],w.sectionIndex=_[1],w.sections=c.sections,p.push(w);}}else p=function(t,e){for(var r=[],n=t.text,i=0,a=0,o=e;a<o.length;a+=1){var s=o[a];r.push(t.substring(i,s)),i=s;}return i<n.length&&r.push(t.substring(i,n.length)),r}(c,ml(c,s,n,e));var A=[],S={positionedGlyphs:A,text:c.toString(),top:u[1],bottom:u[1],left:u[0],right:u[0],writingMode:l,lineCount:p.length};return function(t,e,r,n,i,a,o,s){for(var u=0,l=-17,p=0,c=t.positionedGlyphs,h=\"right\"===a?1:\"left\"===a?0:.5,f=0,y=r;f<y.length;f+=1){var d=y[f];d.trim();var m=d.getMaxScale();if(d.length()){for(var v=c.length,g=0;g<d.length();g++){var x=d.getSection(g),b=d.getCharCode(g),_=24*(m-x.scale),w=e[x.fontStack],A=w&&w[b];A&&(Fn(b)&&o!==ul.horizontal?(c.push({glyph:b,x:u,y:_,vertical:!0,scale:x.scale,fontStack:x.fontStack}),u+=sl*x.scale+s):(c.push({glyph:b,x:u,y:l+_,vertical:!1,scale:x.scale,fontStack:x.fontStack}),u+=A.metrics.advance*x.scale+s));}if(c.length!==v){var S=u-s;p=Math.max(S,p),gl(c,e,v,c.length-1,h);}u=0,l+=n*m;}else l+=n;}var k=vl(i),z=k.horizontalAlign,I=k.verticalAlign;!function(t,e,r,n,i,a,o){for(var s=(e-r)*i,u=(-n*o+.5)*a,l=0;l<t.length;l++)t[l].x+=s,t[l].y+=u;}(c,h,z,I,p,n,r.length);var B=l- -17;t.top+=-I*B,t.bottom=t.top+B,t.left+=-z*p,t.right=t.left+p;}(S,e,p,i,a,o,l,s),!!A.length&&S}ll.fromFeature=function(t,e){for(var r=new ll,n=0;n<t.sections.length;n++){var i=t.sections[n];r.sections.push({scale:i.scale||1,fontStack:i.fontStack||e}),r.text+=i.text;for(var a=0;a<i.text.length;a++)r.sectionIndex.push(n);}return r},ll.prototype.length=function(){return this.text.length},ll.prototype.getSection=function(t){return this.sections[this.sectionIndex[t]]},ll.prototype.getCharCode=function(t){return this.text.charCodeAt(t)},ll.prototype.verticalizePunctuation=function(){this.text=function(t){for(var e=\"\",r=0;r<t.length;r++){var n=t.charCodeAt(r+1)||null,i=t.charCodeAt(r-1)||null;n&&Ln(n)&&!Fs[t[r+1]]||i&&Ln(i)&&!Fs[t[r-1]]||!Fs[t[r]]?e+=t[r]:e+=Fs[t[r]];}return e}(this.text);},ll.prototype.trim=function(){for(var t=0,e=0;e<this.text.length&&cl[this.text.charCodeAt(e)];e++)t++;for(var r=this.text.length,n=this.text.length-1;n>=0&&n>=t&&cl[this.text.charCodeAt(n)];n--)r--;this.text=this.text.substring(t,r),this.sectionIndex=this.sectionIndex.slice(t,r);},ll.prototype.substring=function(t,e){var r=new ll;return r.text=this.text.substring(t,e),r.sectionIndex=this.sectionIndex.slice(t,e),r.sections=this.sections,r},ll.prototype.toString=function(){return this.text},ll.prototype.getMaxScale=function(){var t=this;return this.sectionIndex.reduce(function(e,r){return Math.max(e,t.sections[r].scale)},0)};var cl={9:!0,10:!0,11:!0,12:!0,13:!0,32:!0},hl={};function fl(t,e,r,n){var i=Math.pow(t-e,2);return n?t<e?i/2:2*i:i+Math.abs(r)*r}function yl(t,e,r){var n=0;return 10===t&&(n-=1e4),r&&(n+=150),40!==t&&65288!==t||(n+=50),41!==e&&65289!==e||(n+=50),n}function dl(t,e,r,n,i,a){for(var o=null,s=fl(e,r,i,a),u=0,l=n;u<l.length;u+=1){var p=l[u],c=fl(e-p.x,r,i,a)+p.badness;c<=s&&(o=p,s=c);}return {index:t,x:e,priorBreak:o,badness:s}}function ml(t,e,r,n){if(!r)return [];if(!t)return [];for(var i,a=[],o=function(t,e,r,n){for(var i=0,a=0;a<t.length();a++){var o=t.getSection(a),s=n[o.fontStack],u=s&&s[t.getCharCode(a)];u&&(i+=u.metrics.advance*o.scale+e);}return i/Math.max(1,Math.ceil(i/r))}(t,e,r,n),s=t.text.indexOf(\"​\")>=0,u=0,l=0;l<t.length();l++){var p=t.getSection(l),c=t.getCharCode(l),h=n[p.fontStack],f=h&&h[c];if(f&&!cl[c]&&(u+=f.metrics.advance*p.scale+e),l<t.length()-1){var y=!!(!((i=c)<11904)&&(Mn[\"Bopomofo Extended\"](i)||Mn.Bopomofo(i)||Mn[\"CJK Compatibility Forms\"](i)||Mn[\"CJK Compatibility Ideographs\"](i)||Mn[\"CJK Compatibility\"](i)||Mn[\"CJK Radicals Supplement\"](i)||Mn[\"CJK Strokes\"](i)||Mn[\"CJK Symbols and Punctuation\"](i)||Mn[\"CJK Unified Ideographs Extension A\"](i)||Mn[\"CJK Unified Ideographs\"](i)||Mn[\"Enclosed CJK Letters and Months\"](i)||Mn[\"Halfwidth and Fullwidth Forms\"](i)||Mn.Hiragana(i)||Mn[\"Ideographic Description Characters\"](i)||Mn[\"Kangxi Radicals\"](i)||Mn[\"Katakana Phonetic Extensions\"](i)||Mn.Katakana(i)||Mn[\"Vertical Forms\"](i)||Mn[\"Yi Radicals\"](i)||Mn[\"Yi Syllables\"](i)));(hl[c]||y)&&a.push(dl(l+1,u,o,a,yl(c,t.getCharCode(l+1),y&&s),!1));}}return function t(e){return e?t(e.priorBreak).concat(e.index):[]}(dl(t.length(),u,o,a,0,!0))}function vl(t){var e=.5,r=.5;switch(t){case\"right\":case\"top-right\":case\"bottom-right\":e=1;break;case\"left\":case\"top-left\":case\"bottom-left\":e=0;}switch(t){case\"bottom\":case\"bottom-right\":case\"bottom-left\":r=1;break;case\"top\":case\"top-right\":case\"top-left\":r=0;}return {horizontalAlign:e,verticalAlign:r}}function gl(t,e,r,n,i){if(i){var a=t[n],o=e[a.fontStack],s=o&&o[a.glyph];if(s)for(var u=s.metrics.advance*a.scale,l=(t[n].x+u)*i,p=r;p<=n;p++)t[p].x-=l;}}function xl(t,e,r){var n=vl(r),i=n.horizontalAlign,a=n.verticalAlign,o=e[0],s=e[1],u=o-t.displaySize[0]*i,l=u+t.displaySize[0],p=s-t.displaySize[1]*a;return {image:t,top:p,bottom:p+t.displaySize[1],left:u,right:l}}function bl(t,e,r,n,i){if(void 0===e.segment)return !0;for(var a=e,o=e.segment+1,s=0;s>-r/2;){if(--o<0)return !1;s-=t[o].dist(a),a=t[o];}s+=t[o].dist(t[o+1]),o++;for(var u=[],l=0;s<r/2;){var p=t[o-1],c=t[o],h=t[o+1];if(!h)return !1;var f=p.angleTo(c)-c.angleTo(h);for(f=Math.abs((f+3*Math.PI)%(2*Math.PI)-Math.PI),u.push({distance:s,angleDelta:f}),l+=f;s-u[0].distance>n;)l-=u.shift().angleDelta;if(l>i)return !1;o++,s+=c.dist(h);}return !0}function _l(t){for(var e=0,r=0;r<t.length-1;r++)e+=t[r].dist(t[r+1]);return e}function wl(t,e,r){return t?.6*e*r:0}function Al(t,e){return Math.max(t?t.right-t.left:0,e?e.right-e.left:0)}function Sl(t,e,r,n,i,a){for(var o=wl(r,i,a),s=Al(r,n)*a,u=0,l=_l(t)/2,p=0;p<t.length-1;p++){var c=t[p],h=t[p+1],f=c.dist(h);if(u+f>l){var y=(l-u)/f,d=Ee(c.x,h.x,y),m=Ee(c.y,h.y,y),v=new Ls(d,m,h.angleTo(c),p);return v._round(),!o||bl(t,v,s,o,e)?v:void 0}u+=f;}}function kl(t,e,r,n,i,a,o,s,u){var l=wl(n,a,o),p=Al(n,i),c=p*o,h=0===t[0].x||t[0].x===u||0===t[0].y||t[0].y===u;return e-c<e/4&&(e=c+e/4),function t(e,r,n,i,a,o,s,u,l){var p=o/2;var c=_l(e);var h=0,f=r-n;var y=[];for(var d=0;d<e.length-1;d++){for(var m=e[d],v=e[d+1],g=m.dist(v),x=v.angleTo(m);f+n<h+g;){var b=((f+=n)-h)/g,_=Ee(m.x,v.x,b),w=Ee(m.y,v.y,b);if(_>=0&&_<l&&w>=0&&w<l&&f-p>=0&&f+p<=c){var A=new Ls(_,w,x,d);A._round(),i&&!bl(e,A,o,i,a)||y.push(A);}}h+=g;}u||y.length||s||(y=t(e,h/2,n,i,a,o,s,!0,l));return y}(t,h?e/2*s%e:(p/2+2*a)*o*s%e,e,l,r,c,h,!1,u)}hl[10]=!0,hl[32]=!0,hl[38]=!0,hl[40]=!0,hl[41]=!0,hl[43]=!0,hl[45]=!0,hl[47]=!0,hl[173]=!0,hl[183]=!0,hl[8203]=!0,hl[8208]=!0,hl[8211]=!0,hl[8231]=!0;var zl=function(t,e,r,n,a,o,s,u,l,p,c,h){var f=s.top*u-l,y=s.bottom*u+l,d=s.left*u-l,m=s.right*u+l;if(this.boxStartIndex=t.length,p){var v=y-f,g=m-d;v>0&&(v=Math.max(10*u,v),this._addLineCollisionCircles(t,e,r,r.segment,g,v,n,a,o,c));}else{if(h){var x=new i(d,f),b=new i(m,f),_=new i(d,y),w=new i(m,y),A=h*Math.PI/180;x._rotate(A),b._rotate(A),_._rotate(A),w._rotate(A),d=Math.min(x.x,b.x,_.x,w.x),m=Math.max(x.x,b.x,_.x,w.x),f=Math.min(x.y,b.y,_.y,w.y),y=Math.max(x.y,b.y,_.y,w.y);}t.emplaceBack(r.x,r.y,d,f,m,y,n,a,o,0,0);}this.boxEndIndex=t.length;};zl.prototype._addLineCollisionCircles=function(t,e,r,n,i,a,o,s,u,l){var p=a/2,c=Math.floor(i/p)||1,h=1+.4*Math.log(l)/Math.LN2,f=Math.floor(c*h/2),y=-a/2,d=r,m=n+1,v=y,g=-i/2,x=g-i/4;do{if(--m<0){if(v>g)return;m=0;break}v-=e[m].dist(d),d=e[m];}while(v>x);for(var b=e[m].dist(e[m+1]),_=-f;_<c+f;_++){var w=_*p,A=g+w;if(w<0&&(A+=w),w>i&&(A+=w-i),!(A<v)){for(;v+b<A;){if(v+=b,++m+1>=e.length)return;b=e[m].dist(e[m+1]);}var S=A-v,k=e[m],z=e[m+1].sub(k)._unit()._mult(S)._add(k)._round(),I=Math.abs(A-y)<p?0:.8*(A-y);t.emplaceBack(z.x,z.y,-a/2,-a/2,a/2,a/2,o,s,u,a/2,I);}}};var Il=function(t,e){if(void 0===t&&(t=[]),void 0===e&&(e=Bl),this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(var r=(this.length>>1)-1;r>=0;r--)this._down(r);};function Bl(t,e){return t<e?-1:t>e?1:0}function Cl(t,e,r){void 0===e&&(e=1),void 0===r&&(r=!1);for(var n=1/0,a=1/0,o=-1/0,s=-1/0,u=t[0],l=0;l<u.length;l++){var p=u[l];(!l||p.x<n)&&(n=p.x),(!l||p.y<a)&&(a=p.y),(!l||p.x>o)&&(o=p.x),(!l||p.y>s)&&(s=p.y);}var c=o-n,h=s-a,f=Math.min(c,h),y=f/2,d=new Il([],El);if(0===f)return new i(n,a);for(var m=n;m<o;m+=f)for(var v=a;v<s;v+=f)d.push(new Ml(m+y,v+y,y,t));for(var g=function(t){for(var e=0,r=0,n=0,i=t[0],a=0,o=i.length,s=o-1;a<o;s=a++){var u=i[a],l=i[s],p=u.x*l.y-l.x*u.y;r+=(u.x+l.x)*p,n+=(u.y+l.y)*p,e+=3*p;}return new Ml(r/e,n/e,0,t)}(t),x=d.length;d.length;){var b=d.pop();(b.d>g.d||!g.d)&&(g=b,r&&console.log(\"found best %d after %d probes\",Math.round(1e4*b.d)/1e4,x)),b.max-g.d<=e||(y=b.h/2,d.push(new Ml(b.p.x-y,b.p.y-y,y,t)),d.push(new Ml(b.p.x+y,b.p.y-y,y,t)),d.push(new Ml(b.p.x-y,b.p.y+y,y,t)),d.push(new Ml(b.p.x+y,b.p.y+y,y,t)),x+=4);}return r&&(console.log(\"num probes: \"+x),console.log(\"best distance: \"+g.d)),g.p}function El(t,e){return e.max-t.max}function Ml(t,e,r,n){this.p=new i(t,e),this.h=r,this.d=function(t,e){for(var r=!1,n=1/0,i=0;i<e.length;i++)for(var a=e[i],o=0,s=a.length,u=s-1;o<s;u=o++){var l=a[o],p=a[u];l.y>t.y!=p.y>t.y&&t.x<(p.x-l.x)*(t.y-l.y)/(p.y-l.y)+l.x&&(r=!r),n=Math.min(n,Ia(t,l,p));}return (r?1:-1)*Math.sqrt(n)}(this.p,n),this.max=this.d+this.h*Math.SQRT2;}Il.prototype.push=function(t){this.data.push(t),this.length++,this._up(this.length-1);},Il.prototype.pop=function(){if(0!==this.length){var t=this.data[0];return this.length--,this.length>0&&(this.data[0]=this.data[this.length],this._down(0)),this.data.pop(),t}},Il.prototype.peek=function(){return this.data[0]},Il.prototype._up=function(t){for(var e=this.data,r=this.compare,n=e[t];t>0;){var i=t-1>>1,a=e[i];if(r(n,a)>=0)break;e[t]=a,t=i;}e[t]=n;},Il.prototype._down=function(t){for(var e=this.data,r=this.compare,n=this.length>>1,i=e[t];t<n;){var a=1+(t<<1),o=e[a],s=a+1;if(s<this.length&&r(e[s],o)<0&&(a=s,o=e[s]),r(o,i)>=0)break;e[t]=o,t=a;}e[t]=i;};var Tl=e(function(t){t.exports=function(t,e){var r,n,i,a,o,s,u,l;for(r=3&t.length,n=t.length-r,i=e,o=3432918353,s=461845907,l=0;l<n;)u=255&t.charCodeAt(l)|(255&t.charCodeAt(++l))<<8|(255&t.charCodeAt(++l))<<16|(255&t.charCodeAt(++l))<<24,++l,i=27492+(65535&(a=5*(65535&(i=(i^=u=(65535&(u=(u=(65535&u)*o+(((u>>>16)*o&65535)<<16)&4294967295)<<15|u>>>17))*s+(((u>>>16)*s&65535)<<16)&4294967295)<<13|i>>>19))+((5*(i>>>16)&65535)<<16)&4294967295))+((58964+(a>>>16)&65535)<<16);switch(u=0,r){case 3:u^=(255&t.charCodeAt(l+2))<<16;case 2:u^=(255&t.charCodeAt(l+1))<<8;case 1:i^=u=(65535&(u=(u=(65535&(u^=255&t.charCodeAt(l)))*o+(((u>>>16)*o&65535)<<16)&4294967295)<<15|u>>>17))*s+(((u>>>16)*s&65535)<<16)&4294967295;}return i^=t.length,i=2246822507*(65535&(i^=i>>>16))+((2246822507*(i>>>16)&65535)<<16)&4294967295,i=3266489909*(65535&(i^=i>>>13))+((3266489909*(i>>>16)&65535)<<16)&4294967295,(i^=i>>>16)>>>0};}),Pl=e(function(t){t.exports=function(t,e){for(var r,n=t.length,i=e^n,a=0;n>=4;)r=1540483477*(65535&(r=255&t.charCodeAt(a)|(255&t.charCodeAt(++a))<<8|(255&t.charCodeAt(++a))<<16|(255&t.charCodeAt(++a))<<24))+((1540483477*(r>>>16)&65535)<<16),i=1540483477*(65535&i)+((1540483477*(i>>>16)&65535)<<16)^(r=1540483477*(65535&(r^=r>>>24))+((1540483477*(r>>>16)&65535)<<16)),n-=4,++a;switch(n){case 3:i^=(255&t.charCodeAt(a+2))<<16;case 2:i^=(255&t.charCodeAt(a+1))<<8;case 1:i=1540483477*(65535&(i^=255&t.charCodeAt(a)))+((1540483477*(i>>>16)&65535)<<16);}return i=1540483477*(65535&(i^=i>>>13))+((1540483477*(i>>>16)&65535)<<16),(i^=i>>>15)>>>0};}),Vl=Tl,Fl=Tl,Ll=Pl;Vl.murmur3=Fl,Vl.murmur2=Ll;var Dl=7;function Ol(t,e){var r=0,n=0,i=e/Math.sqrt(2);switch(t){case\"top-right\":case\"top-left\":n=i-Dl;break;case\"bottom-right\":case\"bottom-left\":n=-i+Dl;break;case\"bottom\":n=-e+Dl;break;case\"top\":n=e-Dl;}switch(t){case\"top-right\":case\"bottom-right\":r=-i;break;case\"top-left\":case\"bottom-left\":r=i;break;case\"left\":r=e;break;case\"right\":r=-e;}return [r,n]}function Rl(t){switch(t){case\"right\":case\"top-right\":case\"bottom-right\":return \"right\";case\"left\":case\"top-left\":case\"bottom-left\":return \"left\"}return \"center\"}function Ul(t,e,r,n,a,o,s){var u=o.layoutTextSize.evaluate(e,{}),l=o.layoutIconSize.evaluate(e,{}),p=o.textMaxSize.evaluate(e,{});void 0===p&&(p=u);var c=t.layers[0].layout,h=c.get(\"icon-offset\").evaluate(e,{}),f=Nl(r.horizontal),y=u/24,d=t.tilePixelRatio*y,m=t.tilePixelRatio*p/24,v=t.tilePixelRatio*l,g=t.tilePixelRatio*c.get(\"symbol-spacing\"),x=c.get(\"text-padding\")*t.tilePixelRatio,b=c.get(\"icon-padding\")*t.tilePixelRatio,_=c.get(\"text-max-angle\")/180*Math.PI,A=\"map\"===c.get(\"text-rotation-alignment\")&&\"point\"!==c.get(\"symbol-placement\"),S=\"map\"===c.get(\"icon-rotation-alignment\")&&\"point\"!==c.get(\"symbol-placement\"),k=c.get(\"symbol-placement\"),z=g/2,I=function(u,l){l.x<0||l.x>=ya||l.y<0||l.y>=ya||function(t,e,r,n,a,o,s,u,l,p,c,h,f,y,d,m,v,g,x,b,_){var A,S,k=t.addToLineVertexArray(e,r),z=0,I=0,B=0,C={},E=Vl(\"\"),M=(o.layout.get(\"text-radial-offset\").evaluate(x,{})||0)*sl;for(var T in n.horizontal){var P=n.horizontal[T];if(!A){E=Vl(P.text);var V=o.layout.get(\"text-rotate\").evaluate(x,{});A=new zl(s,r,e,u,l,p,P,c,h,f,t.overscaling,V);}var F=1===P.lineCount;if(I+=ql(t,e,P,o,f,x,y,k,n.vertical?ul.horizontal:ul.horizontalOnly,F?Object.keys(n.horizontal):[T],C,b,_),F)break}n.vertical&&(B+=ql(t,e,n.vertical,o,f,x,y,k,ul.vertical,[\"vertical\"],C,b,_));var L=A?A.boxStartIndex:t.collisionBoxArray.length,D=A?A.boxEndIndex:t.collisionBoxArray.length;if(a){var O=function(t,e,r,n,a,o){var s,u,l,p,c=e.image,h=r.layout,f=e.top-1/c.pixelRatio,y=e.left-1/c.pixelRatio,d=e.bottom+1/c.pixelRatio,m=e.right+1/c.pixelRatio;if(\"none\"!==h.get(\"icon-text-fit\")&&a){var v=m-y,g=d-f,x=h.get(\"text-size\").evaluate(o,{})/24,b=a.left*x,_=a.right*x,w=a.top*x,A=_-b,S=a.bottom*x-w,k=h.get(\"icon-text-fit-padding\")[0],z=h.get(\"icon-text-fit-padding\")[1],I=h.get(\"icon-text-fit-padding\")[2],B=h.get(\"icon-text-fit-padding\")[3],C=\"width\"===h.get(\"icon-text-fit\")?.5*(S-g):0,E=\"height\"===h.get(\"icon-text-fit\")?.5*(A-v):0,M=\"width\"===h.get(\"icon-text-fit\")||\"both\"===h.get(\"icon-text-fit\")?A:v,T=\"height\"===h.get(\"icon-text-fit\")||\"both\"===h.get(\"icon-text-fit\")?S:g;s=new i(b+E-B,w+C-k),u=new i(b+E+z+M,w+C-k),l=new i(b+E+z+M,w+C+I+T),p=new i(b+E-B,w+C+I+T);}else s=new i(y,f),u=new i(m,f),l=new i(m,d),p=new i(y,d);var P=r.layout.get(\"icon-rotate\").evaluate(o,{})*Math.PI/180;if(P){var V=Math.sin(P),F=Math.cos(P),L=[F,-V,V,F];s._matMult(L),u._matMult(L),p._matMult(L),l._matMult(L);}return [{tl:s,tr:u,bl:p,br:l,tex:c.paddedRect,writingMode:void 0,glyphOffset:[0,0]}]}(0,a,o,0,Nl(n.horizontal),x),R=o.layout.get(\"icon-rotate\").evaluate(x,{});S=new zl(s,r,e,u,l,p,a,d,m,!1,t.overscaling,R),z=4*O.length;var U=t.iconSizeData,j=null;\"source\"===U.kind?(j=[Ds*o.layout.get(\"icon-size\").evaluate(x,{})])[0]>jl&&w(t.layerIds[0]+': Value for \"icon-size\" is >= 256. Reduce your \"icon-size\".'):\"composite\"===U.kind&&((j=[Ds*_.compositeIconSizes[0].evaluate(x,{}),Ds*_.compositeIconSizes[1].evaluate(x,{})])[0]>jl||j[1]>jl)&&w(t.layerIds[0]+': Value for \"icon-size\" is >= 256. Reduce your \"icon-size\".'),t.addSymbols(t.icon,O,j,g,v,x,!1,e,k.lineStartIndex,k.lineLength);}var q=S?S.boxStartIndex:t.collisionBoxArray.length,N=S?S.boxEndIndex:t.collisionBoxArray.length;t.glyphOffsetArray.length>=Js.MAX_GLYPHS&&w(\"Too many glyphs being rendered in a tile. See https://github.com/mapbox/mapbox-gl-js/issues/2907\");t.symbolInstances.emplaceBack(e.x,e.y,C.right>=0?C.right:-1,C.center>=0?C.center:-1,C.left>=0?C.left:-1,C.vertical||-1,E,L,D,q,N,u,I,B,z,0,c,M);}(t,l,u,r,n,t.layers[0],t.collisionBoxArray,e.index,e.sourceLayerIndex,t.index,d,x,A,s,v,b,S,h,e,a,o);};if(\"line\"===k)for(var B=0,C=function(t,e,r,n,a){for(var o=[],s=0;s<t.length;s++)for(var u=t[s],l=void 0,p=0;p<u.length-1;p++){var c=u[p],h=u[p+1];c.x<e&&h.x<e||(c.x<e?c=new i(e,c.y+(h.y-c.y)*((e-c.x)/(h.x-c.x)))._round():h.x<e&&(h=new i(e,c.y+(h.y-c.y)*((e-c.x)/(h.x-c.x)))._round()),c.y<r&&h.y<r||(c.y<r?c=new i(c.x+(h.x-c.x)*((r-c.y)/(h.y-c.y)),r)._round():h.y<r&&(h=new i(c.x+(h.x-c.x)*((r-c.y)/(h.y-c.y)),r)._round()),c.x>=n&&h.x>=n||(c.x>=n?c=new i(n,c.y+(h.y-c.y)*((n-c.x)/(h.x-c.x)))._round():h.x>=n&&(h=new i(n,c.y+(h.y-c.y)*((n-c.x)/(h.x-c.x)))._round()),c.y>=a&&h.y>=a||(c.y>=a?c=new i(c.x+(h.x-c.x)*((a-c.y)/(h.y-c.y)),a)._round():h.y>=a&&(h=new i(c.x+(h.x-c.x)*((a-c.y)/(h.y-c.y)),a)._round()),l&&c.equals(l[l.length-1])||(l=[c],o.push(l)),l.push(h)))));}return o}(e.geometry,0,0,ya,ya);B<C.length;B+=1)for(var E=C[B],M=0,T=kl(E,g,_,r.vertical||f,n,24,m,t.overscaling,ya);M<T.length;M+=1){var P=T[M];f&&Zl(t,f.text,z,P)||I(E,P);}else if(\"line-center\"===k)for(var V=0,F=e.geometry;V<F.length;V+=1){var L=F[V];if(L.length>1){var D=Sl(L,_,r.vertical||f,n,24,m);D&&I(L,D);}}else if(\"Polygon\"===e.type)for(var O=0,R=qo(e.geometry,0);O<R.length;O+=1){var U=R[O],j=Cl(U,16);I(U[0],new Ls(j.x,j.y,0));}else if(\"LineString\"===e.type)for(var q=0,N=e.geometry;q<N.length;q+=1){var Z=N[q];I(Z,new Ls(Z[0].x,Z[0].y,0));}else if(\"Point\"===e.type)for(var K=0,G=e.geometry;K<G.length;K+=1)for(var X=0,J=G[K];X<J.length;X+=1){var H=J[X];I([H],new Ls(H.x,H.y,0));}}var jl=65535;function ql(t,e,r,n,a,o,s,u,l,p,c,h,f){var y=function(t,e,r,n,a,o,s){for(var u=n.layout.get(\"text-rotate\").evaluate(o,{})*Math.PI/180,l=e.positionedGlyphs,p=[],c=0;c<l.length;c++){var h=l[c],f=s[h.fontStack],y=f&&f[h.glyph];if(y){var d=y.rect;if(d){var m=Lu+1,v=y.metrics.advance*h.scale/2,g=a?[h.x+v,h.y]:[0,0],x=a?[0,0]:[h.x+v+r[0],h.y+r[1]],b=(y.metrics.left-m)*h.scale-v+x[0],_=(-y.metrics.top-m)*h.scale+x[1],w=b+d.w*h.scale,A=_+d.h*h.scale,S=new i(b,_),k=new i(w,_),z=new i(b,A),I=new i(w,A);if(a&&h.vertical){var B=new i(-v,v),C=-Math.PI/2,E=new i(5,0);S._rotateAround(C,B)._add(E),k._rotateAround(C,B)._add(E),z._rotateAround(C,B)._add(E),I._rotateAround(C,B)._add(E);}if(u){var M=Math.sin(u),T=Math.cos(u),P=[T,-M,M,T];S._matMult(P),k._matMult(P),z._matMult(P),I._matMult(P);}p.push({tl:S,tr:k,bl:z,br:I,tex:d,writingMode:e.writingMode,glyphOffset:g});}}}return p}(0,r,s,n,a,o,h),d=t.textSizeData,m=null;\"source\"===d.kind?(m=[Ds*n.layout.get(\"text-size\").evaluate(o,{})])[0]>jl&&w(t.layerIds[0]+': Value for \"text-size\" is >= 256. Reduce your \"text-size\".'):\"composite\"===d.kind&&((m=[Ds*f.compositeTextSizes[0].evaluate(o,{}),Ds*f.compositeTextSizes[1].evaluate(o,{})])[0]>jl||m[1]>jl)&&w(t.layerIds[0]+': Value for \"text-size\" is >= 256. Reduce your \"text-size\".'),t.addSymbols(t.text,y,m,s,a,o,l,e,u.lineStartIndex,u.lineLength);for(var v=0,g=p;v<g.length;v+=1){c[g[v]]=t.text.placedSymbolArray.length-1;}return 4*y.length}function Nl(t){for(var e in t)return t[e];return null}function Zl(t,e,r,n){var i=t.compareText;if(e in i){for(var a=i[e],o=a.length-1;o>=0;o--)if(n.dist(a[o])<r)return !0}else i[e]=[];return i[e].push(n),!1}t.Actor=Du,t.AlphaImage=ao,t.CanonicalTileID=Xu,t.CollisionBoxArray=Pi,t.Color=ae,t.DEMData=$u,t.DataConstantProperty=Qn,t.DictionaryCoder=Qu,t.EXTENT=ya,t.ErrorEvent=Vt,t.EvaluationParameters=Zn,t.Event=Pt,t.Evented=Ft,t.FeatureIndex=nl,t.FillBucket=Go,t.FillExtrusionBucket=us,t.ImageAtlas=su,t.ImagePosition=au,t.LineBucket=ws,t.LngLat=Uu,t.LngLatBounds=Ru,t.MercatorCoordinate=Gu,t.ONE_EM=sl,t.OverscaledTileID=Hu,t.Point=i,t.Point$1=i,t.ProgramConfiguration=pa,t.Properties=ii,t.Protobuf=du,t.RGBAImage=oo,t.RequestManager=U,t.ResourceType=bt,t.SegmentVector=Ki,t.SourceFeatureState=rl,t.StructArrayLayout1ui2=Ci,t.StructArrayLayout2i4=ci,t.StructArrayLayout2ui4=Bi,t.StructArrayLayout3ui6=Ii,t.StructArrayLayout4i8=hi,t.SymbolBucket=Js,t.Texture=hu,t.Tile=ol,t.Transitionable=Xn,t.Uniform1f=$i,t.Uniform1i=Yi,t.Uniform2f=Wi,t.Uniform3f=Qi,t.Uniform4f=ta,t.UniformColor=ea,t.UniformMatrix4f=na,t.UnwrappedTileID=Ju,t.ValidationError=Dt,t.WritingMode=ul,t.ZoomHistory=En,t.addDynamicAttributes=Ks,t.asyncAll=function(t,e,r){if(!t.length)return r(null,[]);var n=t.length,i=new Array(t.length),a=null;t.forEach(function(t,o){e(t,function(t,e){t&&(a=t),i[o]=e,0==--n&&r(a,i);});});},t.bezier=s,t.bindAll=m,t.browser=P,t.cacheEntryPossiblyAdded=function(t){++xt>yt&&(t.send(\"enforceCacheSizeLimit\",ft),xt=0);},t.clamp=l,t.clearTileCache=function(t){var e=self.caches.delete(ht);t&&e.catch(t).then(function(){return t()});},t.clone=function(t){var e=new La(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},t.clone$1=b,t.config=V,t.create=function(){var t=new La(16);return La!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t},t.create$1=Da,t.create$2=function(){var t=new La(4);return La!=Float32Array&&(t[1]=0,t[2]=0),t[0]=1,t[3]=1,t},t.createCommonjsModule=e,t.createExpression=Fr,t.createLayout=li,t.createStyleLayer=function(t){return \"custom\"===t.type?new ru(t):new nu[t.type](t)},t.deepEqual=o,t.ease=u,t.emitValidationErrors=bn,t.endsWith=v,t.enforceCacheSizeLimit=function(t){self.caches&&self.caches.open(ht).then(function(e){e.keys().then(function(r){for(var n=0;n<r.length-t;n++)e.delete(r[n]);});});},t.evaluateRadialOffset=Ol,t.evaluateSizeForFeature=Rs,t.evaluateSizeForZoom=Us,t.evented=qn,t.extend=c,t.featureFilter=Jr,t.filterObject=x,t.fromRotation=function(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=-r,t[4]=n,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},t.getAnchorAlignment=vl,t.getAnchorJustification=Rl,t.getArrayBuffer=zt,t.getImage=Et,t.getJSON=function(t,e){return kt(c(t,{type:\"json\"}),e)},t.getReferrer=At,t.getVideo=function(t,e){var r,n,i=self.document.createElement(\"video\");i.muted=!0,i.onloadstart=function(){e(null,i);};for(var a=0;a<t.length;a++){var o=self.document.createElement(\"source\");r=t[a],n=void 0,(n=self.document.createElement(\"a\")).href=r,(n.protocol!==self.document.location.protocol||n.host!==self.document.location.host)&&(i.crossOrigin=\"Anonymous\"),o.src=t[a],i.appendChild(o);}return {cancel:function(){}}},t.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},t.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],l=e[7],p=e[8],c=e[9],h=e[10],f=e[11],y=e[12],d=e[13],m=e[14],v=e[15],g=r*s-n*o,x=r*u-i*o,b=r*l-a*o,_=n*u-i*s,w=n*l-a*s,A=i*l-a*u,S=p*d-c*y,k=p*m-h*y,z=p*v-f*y,I=c*m-h*d,B=c*v-f*d,C=h*v-f*m,E=g*C-x*B+b*I+_*z-w*k+A*S;return E?(E=1/E,t[0]=(s*C-u*B+l*I)*E,t[1]=(i*B-n*C-a*I)*E,t[2]=(d*A-m*w+v*_)*E,t[3]=(h*w-c*A-f*_)*E,t[4]=(u*z-o*C-l*k)*E,t[5]=(r*C-i*z+a*k)*E,t[6]=(m*b-y*A-v*x)*E,t[7]=(p*A-h*b+f*x)*E,t[8]=(o*B-s*z+l*S)*E,t[9]=(n*z-r*B-a*S)*E,t[10]=(y*w-d*b+v*g)*E,t[11]=(c*b-p*w-f*g)*E,t[12]=(s*k-o*I-u*S)*E,t[13]=(r*I-n*k+i*S)*E,t[14]=(d*x-y*_-m*g)*E,t[15]=(p*_-c*x+h*g)*E,t):null},t.isChar=Mn,t.isMapboxURL=N,t.keysDifference=function(t,e){var r=[];for(var n in t)n in e||r.push(n);return r},t.makeRequest=kt,t.mapObject=g,t.mercatorXfromLng=qu,t.mercatorYfromLat=Nu,t.mercatorZfromAltitude=Zu,t.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],l=e[6],p=e[7],c=e[8],h=e[9],f=e[10],y=e[11],d=e[12],m=e[13],v=e[14],g=e[15],x=r[0],b=r[1],_=r[2],w=r[3];return t[0]=x*n+b*s+_*c+w*d,t[1]=x*i+b*u+_*h+w*m,t[2]=x*a+b*l+_*f+w*v,t[3]=x*o+b*p+_*y+w*g,x=r[4],b=r[5],_=r[6],w=r[7],t[4]=x*n+b*s+_*c+w*d,t[5]=x*i+b*u+_*h+w*m,t[6]=x*a+b*l+_*f+w*v,t[7]=x*o+b*p+_*y+w*g,x=r[8],b=r[9],_=r[10],w=r[11],t[8]=x*n+b*s+_*c+w*d,t[9]=x*i+b*u+_*h+w*m,t[10]=x*a+b*l+_*f+w*v,t[11]=x*o+b*p+_*y+w*g,x=r[12],b=r[13],_=r[14],w=r[15],t[12]=x*n+b*s+_*c+w*d,t[13]=x*i+b*u+_*h+w*m,t[14]=x*a+b*l+_*f+w*v,t[15]=x*o+b*p+_*y+w*g,t},t.mvt=is,t.number=Ee,t.ortho=function(t,e,r,n,i,a,o){var s=1/(e-r),u=1/(n-i),l=1/(a-o);return t[0]=-2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*s,t[13]=(i+n)*u,t[14]=(o+a)*l,t[15]=1,t},t.parseGlyphPBF=function(t){return new du(t).readFields(Pu,[])},t.pbf=du,t.performSymbolLayout=function(t,e,r,n,i,a){t.createArrays();var o=512*t.overscaling;t.tilePixelRatio=ya/o,t.compareText={},t.iconsNeedLinear=!1;var s=t.layers[0].layout,u=t.layers[0]._unevaluatedLayout._values,l={};if(\"composite\"===t.textSizeData.kind){var p=t.textSizeData,c=p.minZoom,h=p.maxZoom;l.compositeTextSizes=[u[\"text-size\"].possiblyEvaluate(new Zn(c)),u[\"text-size\"].possiblyEvaluate(new Zn(h))];}if(\"composite\"===t.iconSizeData.kind){var f=t.iconSizeData,y=f.minZoom,d=f.maxZoom;l.compositeIconSizes=[u[\"icon-size\"].possiblyEvaluate(new Zn(y)),u[\"icon-size\"].possiblyEvaluate(new Zn(d))];}l.layoutTextSize=u[\"text-size\"].possiblyEvaluate(new Zn(t.zoom+1)),l.layoutIconSize=u[\"icon-size\"].possiblyEvaluate(new Zn(t.zoom+1)),l.textMaxSize=u[\"text-size\"].possiblyEvaluate(new Zn(18));for(var m=s.get(\"text-line-height\")*sl,v=\"map\"===s.get(\"text-rotation-alignment\")&&\"point\"!==s.get(\"symbol-placement\"),g=s.get(\"text-keep-upright\"),x=0,b=t.features;x<b.length;x+=1){var _=b[x],A=s.get(\"text-font\").evaluate(_,{}).join(\",\"),S=r,k={horizontal:{},vertical:void 0},z=_.text,I=[0,0];if(z){var B=z.toString(),C=s.get(\"text-letter-spacing\").evaluate(_,{})*sl,E=Pn(B)?C:0,M=s.get(\"text-anchor\").evaluate(_,{}),T=s.get(\"text-variable-anchor\"),P=s.get(\"text-radial-offset\").evaluate(_,{});T||(I=P?Ol(M,P*sl):s.get(\"text-offset\").evaluate(_,{}).map(function(t){return t*sl}));var V=v?\"center\":s.get(\"text-justify\").evaluate(_,{}),F=\"point\"===s.get(\"symbol-placement\")?s.get(\"text-max-width\").evaluate(_,{})*sl:0;if(!v&&T)for(var L=\"auto\"===V?T.map(function(t){return Rl(t)}):[V],D=!1,O=0;O<L.length;O++){var R=L[O];if(!k.horizontal[R])if(D)k.horizontal[R]=k.horizontal[0];else{var U=pl(z,e,A,F,m,\"center\",R,E,I,ul.horizontal);U&&(k.horizontal[R]=U,D=1===U.lineCount);}}else{\"auto\"===V&&(V=Rl(M));var j=pl(z,e,A,F,m,M,V,E,I,ul.horizontal);j&&(k.horizontal[V]=j),Tn(B)&&v&&g&&(k.vertical=pl(z,e,A,F,m,M,V,E,I,ul.vertical));}}var q=void 0;if(_.icon){var N=n[_.icon];N&&(q=xl(i[_.icon],s.get(\"icon-offset\").evaluate(_,{}),s.get(\"icon-anchor\").evaluate(_,{})),void 0===t.sdfIcons?t.sdfIcons=N.sdf:t.sdfIcons!==N.sdf&&w(\"Style sheet warning: Cannot mix SDF and non-SDF icons in one buffer\"),N.pixelRatio!==t.pixelRatio?t.iconsNeedLinear=!0:0!==s.get(\"icon-rotate\").constantOr(1)&&(t.iconsNeedLinear=!0));}(Object.keys(k.horizontal).length||q)&&Ul(t,_,k,q,S,l,I);}a&&t.generateCollisionDebugBuffers();},t.perspective=function(t,e,r,n,i){var a,o=1/Math.tan(e/2);return t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,null!=i&&i!==1/0?(a=1/(n-i),t[10]=(i+n)*a,t[14]=2*i*n*a):(t[10]=-1,t[14]=-2*n),t},t.pick=function(t,e){for(var r={},n=0;n<e.length;n++){var i=e[n];i in t&&(r[i]=t[i]);}return r},t.plugin=Nn,t.polygonIntersectsPolygon=ba,t.postMapLoadEvent=ct,t.postTurnstileEvent=lt,t.potpack=iu,t.rasterBoundsAttributes=Wu,t.refProperties=[\"type\",\"source\",\"source-layer\",\"minzoom\",\"maxzoom\",\"filter\",\"layout\"],t.register=zn,t.registerForPluginAvailability=function(t){return Un?t({pluginURL:Un,completionCallback:On}):qn.once(\"pluginAvailable\",t),t},t.rotate=function(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),u=Math.cos(r);return t[0]=n*u+a*s,t[1]=i*u+o*s,t[2]=n*-s+a*u,t[3]=i*-s+o*u,t},t.rotateX=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[4],o=e[5],s=e[6],u=e[7],l=e[8],p=e[9],c=e[10],h=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=a*i+l*n,t[5]=o*i+p*n,t[6]=s*i+c*n,t[7]=u*i+h*n,t[8]=l*i-a*n,t[9]=p*i-o*n,t[10]=c*i-s*n,t[11]=h*i-u*n,t},t.rotateZ=function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],u=e[3],l=e[4],p=e[5],c=e[6],h=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=a*i+l*n,t[1]=o*i+p*n,t[2]=s*i+c*n,t[3]=u*i+h*n,t[4]=l*i-a*n,t[5]=p*i-o*n,t[6]=c*i-s*n,t[7]=h*i-u*n,t},t.scale=function(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},t.setCacheLimits=function(t,e){ft=t,yt=e;},t.setRTLTextPlugin=function(t,e){if(Rn)throw new Error(\"setRTLTextPlugin cannot be called multiple times.\");Rn=!0,Un=P.resolveURL(t),On=function(t){t?(Rn=!1,Un=null,e&&e(t)):jn=!0;},qn.fire(new Pt(\"pluginAvailable\",{pluginURL:Un,completionCallback:On}));},t.sphericalToCartesian=function(t){var e=t[0],r=t[1],n=t[2];return r+=90,r*=Math.PI/180,n*=Math.PI/180,{x:e*Math.cos(r)*Math.sin(n),y:e*Math.sin(r)*Math.sin(n),z:e*Math.cos(n)}},t.styleSpec=Lt,t.symbolSize=js,t.transformMat3=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=n*r[0]+i*r[3]+a*r[6],t[1]=n*r[1]+i*r[4]+a*r[7],t[2]=n*r[2]+i*r[5]+a*r[8],t},t.transformMat4=Na,t.translate=function(t,e,r){var n,i,a,o,s,u,l,p,c,h,f,y,d=r[0],m=r[1],v=r[2];return e===t?(t[12]=e[0]*d+e[4]*m+e[8]*v+e[12],t[13]=e[1]*d+e[5]*m+e[9]*v+e[13],t[14]=e[2]*d+e[6]*m+e[10]*v+e[14],t[15]=e[3]*d+e[7]*m+e[11]*v+e[15]):(n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],u=e[5],l=e[6],p=e[7],c=e[8],h=e[9],f=e[10],y=e[11],t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=u,t[6]=l,t[7]=p,t[8]=c,t[9]=h,t[10]=f,t[11]=y,t[12]=n*d+s*m+c*v+e[12],t[13]=i*d+u*m+h*v+e[13],t[14]=a*d+l*m+f*v+e[14],t[15]=o*d+p*m+y*v+e[15]),t},t.uniqueId=f,t.validateCustomStyleLayer=function(t){var e=[],r=t.id;return void 0===r&&e.push({message:\"layers.\"+r+': missing required property \"id\"'}),void 0===t.render&&e.push({message:\"layers.\"+r+': missing required method \"render\"'}),t.renderingMode&&\"2d\"!==t.renderingMode&&\"3d\"!==t.renderingMode&&e.push({message:\"layers.\"+r+': property \"renderingMode\" must be either \"2d\" or \"3d\"'}),e},t.validateLight=vn,t.validateStyle=mn,t.values=function(t){var e=[];for(var r in t)e.push(t[r]);return e},t.vectorTile=is,t.version=\"1.1.1\",t.warnOnce=w,t.webpSupported=F,t.window=self,t.wrap=p;});\n\ndefine([\"./shared.js\"],function(e){\"use strict\";function t(e){var r=typeof e;if(\"number\"===r||\"boolean\"===r||\"string\"===r||null==e)return JSON.stringify(e);if(Array.isArray(e)){for(var o=\"[\",i=0,n=e;i<n.length;i+=1){o+=t(n[i])+\",\";}return o+\"]\"}for(var a=Object.keys(e).sort(),s=\"{\",u=0;u<a.length;u++)s+=JSON.stringify(a[u])+\":\"+t(e[a[u]])+\",\";return s+\"}\"}function r(r){for(var o=\"\",i=0,n=e.refProperties;i<n.length;i+=1){o+=\"/\"+t(r[n[i]]);}return o}var o=function(e){this.keyCache={},e&&this.replace(e);};o.prototype.replace=function(e){this._layerConfigs={},this._layers={},this.update(e,[]);},o.prototype.update=function(t,o){for(var i=this,n=0,a=t;n<a.length;n+=1){var s=a[n];this._layerConfigs[s.id]=s;var u=this._layers[s.id]=e.createStyleLayer(s);u._featureFilter=e.featureFilter(u.filter),this.keyCache[s.id]&&delete this.keyCache[s.id];}for(var l=0,h=o;l<h.length;l+=1){var c=h[l];delete this.keyCache[c],delete this._layerConfigs[c],delete this._layers[c];}this.familiesBySource={};for(var p=0,f=function(e,t){for(var o={},i=0;i<e.length;i++){var n=t&&t[e[i].id]||r(e[i]);t&&(t[e[i].id]=n);var a=o[n];a||(a=o[n]=[]),a.push(e[i]);}var s=[];for(var u in o)s.push(o[u]);return s}(e.values(this._layerConfigs),this.keyCache);p<f.length;p+=1){var d=f[p].map(function(e){return i._layers[e.id]}),g=d[0];if(\"none\"!==g.visibility){var m=g.source||\"\",v=this.familiesBySource[m];v||(v=this.familiesBySource[m]={});var y=g.sourceLayer||\"_geojsonTileLayer\",x=v[y];x||(x=v[y]=[]),x.push(d);}}};var i=function(t){var r={},o=[];for(var i in t){var n=t[i],a=r[i]={};for(var s in n){var u=n[+s];if(u&&0!==u.bitmap.width&&0!==u.bitmap.height){var l={x:0,y:0,w:u.bitmap.width+2,h:u.bitmap.height+2};o.push(l),a[s]={rect:l,metrics:u.metrics};}}}var h=e.potpack(o),c=h.w,p=h.h,f=new e.AlphaImage({width:c||1,height:p||1});for(var d in t){var g=t[d];for(var m in g){var v=g[+m];if(v&&0!==v.bitmap.width&&0!==v.bitmap.height){var y=r[d][m].rect;e.AlphaImage.copy(v.bitmap,f,{x:0,y:0},{x:y.x+1,y:y.y+1},v.bitmap);}}}this.image=f,this.positions=r;};e.register(\"GlyphAtlas\",i);var n=function(t){this.tileID=new e.OverscaledTileID(t.tileID.overscaledZ,t.tileID.wrap,t.tileID.canonical.z,t.tileID.canonical.x,t.tileID.canonical.y),this.uid=t.uid,this.zoom=t.zoom,this.pixelRatio=t.pixelRatio,this.tileSize=t.tileSize,this.source=t.source,this.overscaling=this.tileID.overscaleFactor(),this.showCollisionBoxes=t.showCollisionBoxes,this.collectResourceTiming=!!t.collectResourceTiming,this.returnDependencies=!!t.returnDependencies;};function a(t,r){for(var o=new e.EvaluationParameters(r),i=0,n=t;i<n.length;i+=1){n[i].recalculate(o);}}n.prototype.parse=function(t,r,o,n){var s=this;this.status=\"parsing\",this.data=t,this.collisionBoxArray=new e.CollisionBoxArray;var u=new e.DictionaryCoder(Object.keys(t.layers).sort()),l=new e.FeatureIndex(this.tileID);l.bucketLayerIDs=[];var h,c,p,f,d={},g={featureIndex:l,iconDependencies:{},patternDependencies:{},glyphDependencies:{}},m=r.familiesBySource[this.source];for(var v in m){var y=t.layers[v];if(y){1===y.version&&e.warnOnce('Vector tile source \"'+this.source+'\" layer \"'+v+'\" does not use vector tile spec v2 and therefore may have some rendering errors.');for(var x=u.encode(v),w=[],S=0;S<y.length;S++){var M=y.feature(S);w.push({feature:M,index:S,sourceLayerIndex:x});}for(var k=0,b=m[v];k<b.length;k+=1){var _=b[k],P=_[0];if(!(P.minzoom&&this.zoom<Math.floor(P.minzoom)))if(!(P.maxzoom&&this.zoom>=P.maxzoom))if(\"none\"!==P.visibility)a(_,this.zoom),(d[P.id]=P.createBucket({index:l.bucketLayerIDs.length,layers:_,zoom:this.zoom,pixelRatio:this.pixelRatio,overscaling:this.overscaling,collisionBoxArray:this.collisionBoxArray,sourceLayerIndex:x,sourceID:this.source})).populate(w,g),l.bucketLayerIDs.push(_.map(function(e){return e.id}));}}}var I=e.mapObject(g.glyphDependencies,function(e){return Object.keys(e).map(Number)});Object.keys(I).length?o.send(\"getGlyphs\",{uid:this.uid,stacks:I},function(e,t){h||(h=e,c=t,D.call(s));}):c={};var T=Object.keys(g.iconDependencies);T.length?o.send(\"getImages\",{icons:T},function(e,t){h||(h=e,p=t,D.call(s));}):p={};var L=Object.keys(g.patternDependencies);function D(){if(h)return n(h);if(c&&p&&f){var t=new i(c),r=new e.ImageAtlas(p,f);for(var o in d){var s=d[o];s instanceof e.SymbolBucket?(a(s.layers,this.zoom),e.performSymbolLayout(s,c,t.positions,p,r.iconPositions,this.showCollisionBoxes)):s.hasPattern&&(s instanceof e.LineBucket||s instanceof e.FillBucket||s instanceof e.FillExtrusionBucket)&&(a(s.layers,this.zoom),s.addFeatures(g,r.patternPositions));}this.status=\"done\",n(null,{buckets:e.values(d).filter(function(e){return !e.isEmpty()}),featureIndex:l,collisionBoxArray:this.collisionBoxArray,glyphAtlasImage:t.image,imageAtlas:r,glyphMap:this.returnDependencies?c:null,iconMap:this.returnDependencies?p:null,glyphPositions:this.returnDependencies?t.positions:null});}}L.length?o.send(\"getImages\",{icons:L},function(e,t){h||(h=e,f=t,D.call(s));}):f={},D.call(this);};var s=\"undefined\"!=typeof performance,u={getEntriesByName:function(e){return !!(s&&performance&&performance.getEntriesByName)&&performance.getEntriesByName(e)},mark:function(e){return !!(s&&performance&&performance.mark)&&performance.mark(e)},measure:function(e,t,r){return !!(s&&performance&&performance.measure)&&performance.measure(e,t,r)},clearMarks:function(e){return !!(s&&performance&&performance.clearMarks)&&performance.clearMarks(e)},clearMeasures:function(e){return !!(s&&performance&&performance.clearMeasures)&&performance.clearMeasures(e)}},l=function(e){this._marks={start:[e.url,\"start\"].join(\"#\"),end:[e.url,\"end\"].join(\"#\"),measure:e.url.toString()},u.mark(this._marks.start);};function h(t,r){var o=e.getArrayBuffer(t.request,function(t,o,i,n){t?r(t):o&&r(null,{vectorTile:new e.vectorTile.VectorTile(new e.pbf(o)),rawData:o,cacheControl:i,expires:n});});return function(){o.cancel(),r();}}l.prototype.finish=function(){u.mark(this._marks.end);var e=u.getEntriesByName(this._marks.measure);return 0===e.length&&(u.measure(this._marks.measure,this._marks.start,this._marks.end),e=u.getEntriesByName(this._marks.measure),u.clearMarks(this._marks.start),u.clearMarks(this._marks.end),u.clearMeasures(this._marks.measure)),e},u.Performance=l;var c=function(e,t,r){this.actor=e,this.layerIndex=t,this.loadVectorData=r||h,this.loading={},this.loaded={};};c.prototype.loadTile=function(t,r){var o=this,i=t.uid;this.loading||(this.loading={});var a=!!(t&&t.request&&t.request.collectResourceTiming)&&new u.Performance(t.request),s=this.loading[i]=new n(t);s.abort=this.loadVectorData(t,function(t,n){if(delete o.loading[i],t||!n)return s.status=\"done\",o.loaded[i]=s,r(t);var u=n.rawData,l={};n.expires&&(l.expires=n.expires),n.cacheControl&&(l.cacheControl=n.cacheControl);var h={};if(a){var c=a.finish();c&&(h.resourceTiming=JSON.parse(JSON.stringify(c)));}s.vectorTile=n.vectorTile,s.parse(n.vectorTile,o.layerIndex,o.actor,function(t,o){if(t||!o)return r(t);r(null,e.extend({rawTileData:u.slice(0)},o,l,h));}),o.loaded=o.loaded||{},o.loaded[i]=s;});},c.prototype.reloadTile=function(e,t){var r=this.loaded,o=e.uid,i=this;if(r&&r[o]){var n=r[o];n.showCollisionBoxes=e.showCollisionBoxes;var a=function(e,r){var o=n.reloadCallback;o&&(delete n.reloadCallback,n.parse(n.vectorTile,i.layerIndex,i.actor,o)),t(e,r);};\"parsing\"===n.status?n.reloadCallback=a:\"done\"===n.status&&(n.vectorTile?n.parse(n.vectorTile,this.layerIndex,this.actor,a):a());}},c.prototype.abortTile=function(e,t){var r=this.loading,o=e.uid;r&&r[o]&&r[o].abort&&(r[o].abort(),delete r[o]),t();},c.prototype.removeTile=function(e,t){var r=this.loaded,o=e.uid;r&&r[o]&&delete r[o],t();};var p=function(){this.loaded={};};p.prototype.loadTile=function(t,r){var o=t.uid,i=t.encoding,n=t.rawImageData,a=new e.DEMData(o,n,i);this.loaded=this.loaded||{},this.loaded[o]=a,r(null,a);},p.prototype.removeTile=function(e){var t=this.loaded,r=e.uid;t&&t[r]&&delete t[r];};var f={RADIUS:6378137,FLATTENING:1/298.257223563,POLAR_RADIUS:6356752.3142};function d(e){var t=0;if(e&&e.length>0){t+=Math.abs(g(e[0]));for(var r=1;r<e.length;r++)t-=Math.abs(g(e[r]));}return t}function g(e){var t,r,o,i,n,a,s=0,u=e.length;if(u>2){for(a=0;a<u;a++)a===u-2?(o=u-2,i=u-1,n=0):a===u-1?(o=u-1,i=0,n=1):(o=a,i=a+1,n=a+2),t=e[o],r=e[i],s+=(m(e[n][0])-m(t[0]))*Math.sin(m(r[1]));s=s*f.RADIUS*f.RADIUS/2;}return s}function m(e){return e*Math.PI/180}var v={geometry:function e(t){var r,o=0;switch(t.type){case\"Polygon\":return d(t.coordinates);case\"MultiPolygon\":for(r=0;r<t.coordinates.length;r++)o+=d(t.coordinates[r]);return o;case\"Point\":case\"MultiPoint\":case\"LineString\":case\"MultiLineString\":return 0;case\"GeometryCollection\":for(r=0;r<t.geometries.length;r++)o+=e(t.geometries[r]);return o}},ring:g},y=function e(t,r){switch(t&&t.type||null){case\"FeatureCollection\":return t.features=t.features.map(x(e,r)),t;case\"GeometryCollection\":return t.geometries=t.geometries.map(x(e,r)),t;case\"Feature\":return t.geometry=e(t.geometry,r),t;case\"Polygon\":case\"MultiPolygon\":return function(e,t){\"Polygon\"===e.type?e.coordinates=w(e.coordinates,t):\"MultiPolygon\"===e.type&&(e.coordinates=e.coordinates.map(x(w,t)));return e}(t,r);default:return t}};function x(e,t){return function(r){return e(r,t)}}function w(e,t){t=!!t,e[0]=S(e[0],t);for(var r=1;r<e.length;r++)e[r]=S(e[r],!t);return e}function S(e,t){return function(e){return v.ring(e)>=0}(e)===t?e:e.reverse()}var M=e.vectorTile.VectorTileFeature.prototype.toGeoJSON,k=function(t){this._feature=t,this.extent=e.EXTENT,this.type=t.type,this.properties=t.tags,\"id\"in t&&!isNaN(t.id)&&(this.id=parseInt(t.id,10));};k.prototype.loadGeometry=function(){if(1===this._feature.type){for(var t=[],r=0,o=this._feature.geometry;r<o.length;r+=1){var i=o[r];t.push([new e.Point$1(i[0],i[1])]);}return t}for(var n=[],a=0,s=this._feature.geometry;a<s.length;a+=1){for(var u=[],l=0,h=s[a];l<h.length;l+=1){var c=h[l];u.push(new e.Point$1(c[0],c[1]));}n.push(u);}return n},k.prototype.toGeoJSON=function(e,t,r){return M.call(this,e,t,r)};var b=function(t){this.layers={_geojsonTileLayer:this},this.name=\"_geojsonTileLayer\",this.extent=e.EXTENT,this.length=t.length,this._features=t;};b.prototype.feature=function(e){return new k(this._features[e])};var _=e.vectorTile.VectorTileFeature,P=I;function I(e,t){this.options=t||{},this.features=e,this.length=e.length;}function T(e,t){this.id=\"number\"==typeof e.id?e.id:void 0,this.type=e.type,this.rawGeometry=1===e.type?[e.geometry]:e.geometry,this.properties=e.tags,this.extent=t||4096;}I.prototype.feature=function(e){return new T(this.features[e],this.options.extent)},T.prototype.loadGeometry=function(){var t=this.rawGeometry;this.geometry=[];for(var r=0;r<t.length;r++){for(var o=t[r],i=[],n=0;n<o.length;n++)i.push(new e.Point$1(o[n][0],o[n][1]));this.geometry.push(i);}return this.geometry},T.prototype.bbox=function(){this.geometry||this.loadGeometry();for(var e=this.geometry,t=1/0,r=-1/0,o=1/0,i=-1/0,n=0;n<e.length;n++)for(var a=e[n],s=0;s<a.length;s++){var u=a[s];t=Math.min(t,u.x),r=Math.max(r,u.x),o=Math.min(o,u.y),i=Math.max(i,u.y);}return [t,o,r,i]},T.prototype.toGeoJSON=_.prototype.toGeoJSON;var L=O,D=O,C=function(e,t){t=t||{};var r={};for(var o in e)r[o]=new P(e[o].features,t),r[o].name=o,r[o].version=t.version,r[o].extent=t.extent;return O({layers:r})},z=P;function O(t){var r=new e.pbf;return function(e,t){for(var r in e.layers)t.writeMessage(3,E,e.layers[r]);}(t,r),r.finish()}function E(e,t){var r;t.writeVarintField(15,e.version||1),t.writeStringField(1,e.name||\"\"),t.writeVarintField(5,e.extent||4096);var o={keys:[],values:[],keycache:{},valuecache:{}};for(r=0;r<e.length;r++)o.feature=e.feature(r),t.writeMessage(2,N,o);var i=o.keys;for(r=0;r<i.length;r++)t.writeStringField(3,i[r]);var n=o.values;for(r=0;r<n.length;r++)t.writeMessage(4,G,n[r]);}function N(e,t){var r=e.feature;void 0!==r.id&&t.writeVarintField(1,r.id),t.writeMessage(2,F,e),t.writeVarintField(3,r.type),t.writeMessage(4,J,r);}function F(e,t){var r=e.feature,o=e.keys,i=e.values,n=e.keycache,a=e.valuecache;for(var s in r.properties){var u=n[s];void 0===u&&(o.push(s),u=o.length-1,n[s]=u),t.writeVarint(u);var l=r.properties[s],h=typeof l;\"string\"!==h&&\"boolean\"!==h&&\"number\"!==h&&(l=JSON.stringify(l));var c=h+\":\"+l,p=a[c];void 0===p&&(i.push(l),p=i.length-1,a[c]=p),t.writeVarint(p);}}function A(e,t){return (t<<3)+(7&e)}function B(e){return e<<1^e>>31}function J(e,t){for(var r=e.loadGeometry(),o=e.type,i=0,n=0,a=r.length,s=0;s<a;s++){var u=r[s],l=1;1===o&&(l=u.length),t.writeVarint(A(1,l));for(var h=3===o?u.length-1:u.length,c=0;c<h;c++){1===c&&1!==o&&t.writeVarint(A(2,h-1));var p=u[c].x-i,f=u[c].y-n;t.writeVarint(B(p)),t.writeVarint(B(f)),i+=p,n+=f;}3===o&&t.writeVarint(A(7,1));}}function G(e,t){var r=typeof e;\"string\"===r?t.writeStringField(1,e):\"boolean\"===r?t.writeBooleanField(7,e):\"number\"===r&&(e%1!=0?t.writeDoubleField(3,e):e<0?t.writeSVarintField(6,e):t.writeVarintField(5,e));}function Z(e,t,r,o,i,n){if(!(i-o<=r)){var a=o+i>>1;!function e(t,r,o,i,n,a){for(;n>i;){if(n-i>600){var s=n-i+1,u=o-i+1,l=Math.log(s),h=.5*Math.exp(2*l/3),c=.5*Math.sqrt(l*h*(s-h)/s)*(u-s/2<0?-1:1),p=Math.max(i,Math.floor(o-u*h/s+c)),f=Math.min(n,Math.floor(o+(s-u)*h/s+c));e(t,r,o,p,f,a);}var d=r[2*o+a],g=i,m=n;for(j(t,r,i,o),r[2*n+a]>d&&j(t,r,i,n);g<m;){for(j(t,r,g,m),g++,m--;r[2*g+a]<d;)g++;for(;r[2*m+a]>d;)m--;}r[2*i+a]===d?j(t,r,i,m):j(t,r,++m,n),m<=o&&(i=m+1),o<=m&&(n=m-1);}}(e,t,a,o,i,n%2),Z(e,t,r,o,a-1,n+1),Z(e,t,r,a+1,i,n+1);}}function j(e,t,r,o){Y(e,r,o),Y(t,2*r,2*o),Y(t,2*r+1,2*o+1);}function Y(e,t,r){var o=e[t];e[t]=e[r],e[r]=o;}function V(e,t,r,o){var i=e-r,n=t-o;return i*i+n*n}L.fromVectorTileJs=D,L.fromGeojsonVt=C,L.GeoJSONWrapper=z;var X=function(e){return e[0]},W=function(e){return e[1]},R=function(e,t,r,o,i){void 0===t&&(t=X),void 0===r&&(r=W),void 0===o&&(o=64),void 0===i&&(i=Float64Array),this.nodeSize=o,this.points=e;for(var n=e.length<65536?Uint16Array:Uint32Array,a=this.ids=new n(e.length),s=this.coords=new i(2*e.length),u=0;u<e.length;u++)a[u]=u,s[2*u]=t(e[u]),s[2*u+1]=r(e[u]);Z(a,s,o,0,a.length-1,0);};R.prototype.range=function(e,t,r,o){return function(e,t,r,o,i,n,a){for(var s,u,l=[0,e.length-1,0],h=[];l.length;){var c=l.pop(),p=l.pop(),f=l.pop();if(p-f<=a)for(var d=f;d<=p;d++)s=t[2*d],u=t[2*d+1],s>=r&&s<=i&&u>=o&&u<=n&&h.push(e[d]);else{var g=Math.floor((f+p)/2);s=t[2*g],u=t[2*g+1],s>=r&&s<=i&&u>=o&&u<=n&&h.push(e[g]);var m=(c+1)%2;(0===c?r<=s:o<=u)&&(l.push(f),l.push(g-1),l.push(m)),(0===c?i>=s:n>=u)&&(l.push(g+1),l.push(p),l.push(m));}}return h}(this.ids,this.coords,e,t,r,o,this.nodeSize)},R.prototype.within=function(e,t,r){return function(e,t,r,o,i,n){for(var a=[0,e.length-1,0],s=[],u=i*i;a.length;){var l=a.pop(),h=a.pop(),c=a.pop();if(h-c<=n)for(var p=c;p<=h;p++)V(t[2*p],t[2*p+1],r,o)<=u&&s.push(e[p]);else{var f=Math.floor((c+h)/2),d=t[2*f],g=t[2*f+1];V(d,g,r,o)<=u&&s.push(e[f]);var m=(l+1)%2;(0===l?r-i<=d:o-i<=g)&&(a.push(c),a.push(f-1),a.push(m)),(0===l?r+i>=d:o+i>=g)&&(a.push(f+1),a.push(h),a.push(m));}}return s}(this.ids,this.coords,e,t,r,this.nodeSize)};var q={minZoom:0,maxZoom:16,radius:40,extent:512,nodeSize:64,log:!1,reduce:null,map:function(e){return e}},U=function(e){this.options=re(Object.create(q),e),this.trees=new Array(this.options.maxZoom+1);};function $(e,t,r,o,i){return {x:e,y:t,zoom:1/0,id:r,parentId:-1,numPoints:o,properties:i}}function H(e,t){var r=e.geometry.coordinates,o=r[0],i=r[1];return {x:ee(o),y:te(i),zoom:1/0,index:t,parentId:-1}}function K(e){return {type:\"Feature\",id:e.id,properties:Q(e),geometry:{type:\"Point\",coordinates:[(o=e.x,360*(o-.5)),(t=e.y,r=(180-360*t)*Math.PI/180,360*Math.atan(Math.exp(r))/Math.PI-90)]}};var t,r,o;}function Q(e){var t=e.numPoints,r=t>=1e4?Math.round(t/1e3)+\"k\":t>=1e3?Math.round(t/100)/10+\"k\":t;return re(re({},e.properties),{cluster:!0,cluster_id:e.id,point_count:t,point_count_abbreviated:r})}function ee(e){return e/360+.5}function te(e){var t=Math.sin(e*Math.PI/180),r=.5-.25*Math.log((1+t)/(1-t))/Math.PI;return r<0?0:r>1?1:r}function re(e,t){for(var r in t)e[r]=t[r];return e}function oe(e){return e.x}function ie(e){return e.y}function ne(e,t,r,o,i,n){var a=i-r,s=n-o;if(0!==a||0!==s){var u=((e-r)*a+(t-o)*s)/(a*a+s*s);u>1?(r=i,o=n):u>0&&(r+=a*u,o+=s*u);}return (a=e-r)*a+(s=t-o)*s}function ae(e,t,r,o){var i={id:void 0===e?null:e,type:t,geometry:r,tags:o,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};return function(e){var t=e.geometry,r=e.type;if(\"Point\"===r||\"MultiPoint\"===r||\"LineString\"===r)se(e,t);else if(\"Polygon\"===r||\"MultiLineString\"===r)for(var o=0;o<t.length;o++)se(e,t[o]);else if(\"MultiPolygon\"===r)for(o=0;o<t.length;o++)for(var i=0;i<t[o].length;i++)se(e,t[o][i]);}(i),i}function se(e,t){for(var r=0;r<t.length;r+=3)e.minX=Math.min(e.minX,t[r]),e.minY=Math.min(e.minY,t[r+1]),e.maxX=Math.max(e.maxX,t[r]),e.maxY=Math.max(e.maxY,t[r+1]);}function ue(e,t,r,o){if(t.geometry){var i=t.geometry.coordinates,n=t.geometry.type,a=Math.pow(r.tolerance/((1<<r.maxZoom)*r.extent),2),s=[],u=t.id;if(r.promoteId?u=t.properties[r.promoteId]:r.generateId&&(u=o||0),\"Point\"===n)le(i,s);else if(\"MultiPoint\"===n)for(var l=0;l<i.length;l++)le(i[l],s);else if(\"LineString\"===n)he(i,s,a,!1);else if(\"MultiLineString\"===n){if(r.lineMetrics){for(l=0;l<i.length;l++)s=[],he(i[l],s,a,!1),e.push(ae(u,\"LineString\",s,t.properties));return}ce(i,s,a,!1);}else if(\"Polygon\"===n)ce(i,s,a,!0);else{if(\"MultiPolygon\"!==n){if(\"GeometryCollection\"===n){for(l=0;l<t.geometry.geometries.length;l++)ue(e,{id:u,geometry:t.geometry.geometries[l],properties:t.properties},r,o);return}throw new Error(\"Input data is not a valid GeoJSON object.\")}for(l=0;l<i.length;l++){var h=[];ce(i[l],h,a,!0),s.push(h);}}e.push(ae(u,n,s,t.properties));}}function le(e,t){t.push(pe(e[0])),t.push(fe(e[1])),t.push(0);}function he(e,t,r,o){for(var i,n,a=0,s=0;s<e.length;s++){var u=pe(e[s][0]),l=fe(e[s][1]);t.push(u),t.push(l),t.push(0),s>0&&(a+=o?(i*l-u*n)/2:Math.sqrt(Math.pow(u-i,2)+Math.pow(l-n,2))),i=u,n=l;}var h=t.length-3;t[2]=1,function e(t,r,o,i){for(var n,a=i,s=o-r>>1,u=o-r,l=t[r],h=t[r+1],c=t[o],p=t[o+1],f=r+3;f<o;f+=3){var d=ne(t[f],t[f+1],l,h,c,p);if(d>a)n=f,a=d;else if(d===a){var g=Math.abs(f-s);g<u&&(n=f,u=g);}}a>i&&(n-r>3&&e(t,r,n,i),t[n+2]=a,o-n>3&&e(t,n,o,i));}(t,0,h,r),t[h+2]=1,t.size=Math.abs(a),t.start=0,t.end=t.size;}function ce(e,t,r,o){for(var i=0;i<e.length;i++){var n=[];he(e[i],n,r,o),t.push(n);}}function pe(e){return e/360+.5}function fe(e){var t=Math.sin(e*Math.PI/180),r=.5-.25*Math.log((1+t)/(1-t))/Math.PI;return r<0?0:r>1?1:r}function de(e,t,r,o,i,n,a,s){if(o/=t,n>=(r/=t)&&a<o)return e;if(a<r||n>=o)return null;for(var u=[],l=0;l<e.length;l++){var h=e[l],c=h.geometry,p=h.type,f=0===i?h.minX:h.minY,d=0===i?h.maxX:h.maxY;if(f>=r&&d<o)u.push(h);else if(!(d<r||f>=o)){var g=[];if(\"Point\"===p||\"MultiPoint\"===p)ge(c,g,r,o,i);else if(\"LineString\"===p)me(c,g,r,o,i,!1,s.lineMetrics);else if(\"MultiLineString\"===p)ye(c,g,r,o,i,!1);else if(\"Polygon\"===p)ye(c,g,r,o,i,!0);else if(\"MultiPolygon\"===p)for(var m=0;m<c.length;m++){var v=[];ye(c[m],v,r,o,i,!0),v.length&&g.push(v);}if(g.length){if(s.lineMetrics&&\"LineString\"===p){for(m=0;m<g.length;m++)u.push(ae(h.id,p,g[m],h.tags));continue}\"LineString\"!==p&&\"MultiLineString\"!==p||(1===g.length?(p=\"LineString\",g=g[0]):p=\"MultiLineString\"),\"Point\"!==p&&\"MultiPoint\"!==p||(p=3===g.length?\"Point\":\"MultiPoint\"),u.push(ae(h.id,p,g,h.tags));}}}return u.length?u:null}function ge(e,t,r,o,i){for(var n=0;n<e.length;n+=3){var a=e[n+i];a>=r&&a<=o&&(t.push(e[n]),t.push(e[n+1]),t.push(e[n+2]));}}function me(e,t,r,o,i,n,a){for(var s,u,l=ve(e),h=0===i?we:Se,c=e.start,p=0;p<e.length-3;p+=3){var f=e[p],d=e[p+1],g=e[p+2],m=e[p+3],v=e[p+4],y=0===i?f:d,x=0===i?m:v,w=!1;a&&(s=Math.sqrt(Math.pow(f-m,2)+Math.pow(d-v,2))),y<r?x>r&&(u=h(l,f,d,m,v,r),a&&(l.start=c+s*u)):y>o?x<o&&(u=h(l,f,d,m,v,o),a&&(l.start=c+s*u)):xe(l,f,d,g),x<r&&y>=r&&(u=h(l,f,d,m,v,r),w=!0),x>o&&y<=o&&(u=h(l,f,d,m,v,o),w=!0),!n&&w&&(a&&(l.end=c+s*u),t.push(l),l=ve(e)),a&&(c+=s);}var S=e.length-3;f=e[S],d=e[S+1],g=e[S+2],(y=0===i?f:d)>=r&&y<=o&&xe(l,f,d,g),S=l.length-3,n&&S>=3&&(l[S]!==l[0]||l[S+1]!==l[1])&&xe(l,l[0],l[1],l[2]),l.length&&t.push(l);}function ve(e){var t=[];return t.size=e.size,t.start=e.start,t.end=e.end,t}function ye(e,t,r,o,i,n){for(var a=0;a<e.length;a++)me(e[a],t,r,o,i,n,!1);}function xe(e,t,r,o){e.push(t),e.push(r),e.push(o);}function we(e,t,r,o,i,n){var a=(n-t)/(o-t);return e.push(n),e.push(r+(i-r)*a),e.push(1),a}function Se(e,t,r,o,i,n){var a=(n-r)/(i-r);return e.push(t+(o-t)*a),e.push(n),e.push(1),a}function Me(e,t){for(var r=[],o=0;o<e.length;o++){var i,n=e[o],a=n.type;if(\"Point\"===a||\"MultiPoint\"===a||\"LineString\"===a)i=ke(n.geometry,t);else if(\"MultiLineString\"===a||\"Polygon\"===a){i=[];for(var s=0;s<n.geometry.length;s++)i.push(ke(n.geometry[s],t));}else if(\"MultiPolygon\"===a)for(i=[],s=0;s<n.geometry.length;s++){for(var u=[],l=0;l<n.geometry[s].length;l++)u.push(ke(n.geometry[s][l],t));i.push(u);}r.push(ae(n.id,a,i,n.tags));}return r}function ke(e,t){var r=[];r.size=e.size,void 0!==e.start&&(r.start=e.start,r.end=e.end);for(var o=0;o<e.length;o+=3)r.push(e[o]+t,e[o+1],e[o+2]);return r}function be(e,t){if(e.transformed)return e;var r,o,i,n=1<<e.z,a=e.x,s=e.y;for(r=0;r<e.features.length;r++){var u=e.features[r],l=u.geometry,h=u.type;if(u.geometry=[],1===h)for(o=0;o<l.length;o+=2)u.geometry.push(_e(l[o],l[o+1],t,n,a,s));else for(o=0;o<l.length;o++){var c=[];for(i=0;i<l[o].length;i+=2)c.push(_e(l[o][i],l[o][i+1],t,n,a,s));u.geometry.push(c);}}return e.transformed=!0,e}function _e(e,t,r,o,i,n){return [Math.round(r*(e*o-i)),Math.round(r*(t*o-n))]}function Pe(e,t,r,o,i){for(var n=t===i.maxZoom?0:i.tolerance/((1<<t)*i.extent),a={features:[],numPoints:0,numSimplified:0,numFeatures:0,source:null,x:r,y:o,z:t,transformed:!1,minX:2,minY:1,maxX:-1,maxY:0},s=0;s<e.length;s++){a.numFeatures++,Ie(a,e[s],n,i);var u=e[s].minX,l=e[s].minY,h=e[s].maxX,c=e[s].maxY;u<a.minX&&(a.minX=u),l<a.minY&&(a.minY=l),h>a.maxX&&(a.maxX=h),c>a.maxY&&(a.maxY=c);}return a}function Ie(e,t,r,o){var i=t.geometry,n=t.type,a=[];if(\"Point\"===n||\"MultiPoint\"===n)for(var s=0;s<i.length;s+=3)a.push(i[s]),a.push(i[s+1]),e.numPoints++,e.numSimplified++;else if(\"LineString\"===n)Te(a,i,e,r,!1,!1);else if(\"MultiLineString\"===n||\"Polygon\"===n)for(s=0;s<i.length;s++)Te(a,i[s],e,r,\"Polygon\"===n,0===s);else if(\"MultiPolygon\"===n)for(var u=0;u<i.length;u++){var l=i[u];for(s=0;s<l.length;s++)Te(a,l[s],e,r,!0,0===s);}if(a.length){var h=t.tags||null;if(\"LineString\"===n&&o.lineMetrics){for(var c in h={},t.tags)h[c]=t.tags[c];h.mapbox_clip_start=i.start/i.size,h.mapbox_clip_end=i.end/i.size;}var p={geometry:a,type:\"Polygon\"===n||\"MultiPolygon\"===n?3:\"LineString\"===n||\"MultiLineString\"===n?2:1,tags:h};null!==t.id&&(p.id=t.id),e.features.push(p);}}function Te(e,t,r,o,i,n){var a=o*o;if(o>0&&t.size<(i?a:o))r.numPoints+=t.length/3;else{for(var s=[],u=0;u<t.length;u+=3)(0===o||t[u+2]>a)&&(r.numSimplified++,s.push(t[u]),s.push(t[u+1])),r.numPoints++;i&&function(e,t){for(var r=0,o=0,i=e.length,n=i-2;o<i;n=o,o+=2)r+=(e[o]-e[n])*(e[o+1]+e[n+1]);if(r>0===t)for(o=0,i=e.length;o<i/2;o+=2){var a=e[o],s=e[o+1];e[o]=e[i-2-o],e[o+1]=e[i-1-o],e[i-2-o]=a,e[i-1-o]=s;}}(s,n),e.push(s);}}function Le(e,t){var r=(t=this.options=function(e,t){for(var r in t)e[r]=t[r];return e}(Object.create(this.options),t)).debug;if(r&&console.time(\"preprocess data\"),t.maxZoom<0||t.maxZoom>24)throw new Error(\"maxZoom should be in the 0-24 range\");if(t.promoteId&&t.generateId)throw new Error(\"promoteId and generateId cannot be used together.\");var o=function(e,t){var r=[];if(\"FeatureCollection\"===e.type)for(var o=0;o<e.features.length;o++)ue(r,e.features[o],t,o);else\"Feature\"===e.type?ue(r,e,t):ue(r,{geometry:e},t);return r}(e,t);this.tiles={},this.tileCoords=[],r&&(console.timeEnd(\"preprocess data\"),console.log(\"index: maxZoom: %d, maxPoints: %d\",t.indexMaxZoom,t.indexMaxPoints),console.time(\"generate tiles\"),this.stats={},this.total=0),(o=function(e,t){var r=t.buffer/t.extent,o=e,i=de(e,1,-1-r,r,0,-1,2,t),n=de(e,1,1-r,2+r,0,-1,2,t);return (i||n)&&(o=de(e,1,-r,1+r,0,-1,2,t)||[],i&&(o=Me(i,1).concat(o)),n&&(o=o.concat(Me(n,-1)))),o}(o,t)).length&&this.splitTile(o,0,0,0),r&&(o.length&&console.log(\"features: %d, points: %d\",this.tiles[0].numFeatures,this.tiles[0].numPoints),console.timeEnd(\"generate tiles\"),console.log(\"tiles generated:\",this.total,JSON.stringify(this.stats)));}function De(e,t,r){return 32*((1<<e)*r+t)+e}function Ce(e,t){var r=e.tileID.canonical;if(!this._geoJSONIndex)return t(null,null);var o=this._geoJSONIndex.getTile(r.z,r.x,r.y);if(!o)return t(null,null);var i=new b(o.features),n=L(i);0===n.byteOffset&&n.byteLength===n.buffer.byteLength||(n=new Uint8Array(n)),t(null,{vectorTile:i,rawData:n.buffer});}U.prototype.load=function(e){var t=this.options,r=t.log,o=t.minZoom,i=t.maxZoom,n=t.nodeSize;r&&console.time(\"total time\");var a=\"prepare \"+e.length+\" points\";r&&console.time(a),this.points=e;for(var s=[],u=0;u<e.length;u++)e[u].geometry&&s.push(H(e[u],u));this.trees[i+1]=new R(s,oe,ie,n,Float32Array),r&&console.timeEnd(a);for(var l=i;l>=o;l--){var h=+Date.now();s=this._cluster(s,l),this.trees[l]=new R(s,oe,ie,n,Float32Array),r&&console.log(\"z%d: %d clusters in %dms\",l,s.length,+Date.now()-h);}return r&&console.timeEnd(\"total time\"),this},U.prototype.getClusters=function(e,t){var r=((e[0]+180)%360+360)%360-180,o=Math.max(-90,Math.min(90,e[1])),i=180===e[2]?180:((e[2]+180)%360+360)%360-180,n=Math.max(-90,Math.min(90,e[3]));if(e[2]-e[0]>=360)r=-180,i=180;else if(r>i){var a=this.getClusters([r,o,180,n],t),s=this.getClusters([-180,o,i,n],t);return a.concat(s)}for(var u=this.trees[this._limitZoom(t)],l=[],h=0,c=u.range(ee(r),te(n),ee(i),te(o));h<c.length;h+=1){var p=c[h],f=u.points[p];l.push(f.numPoints?K(f):this.points[f.index]);}return l},U.prototype.getChildren=function(e){var t=e>>5,r=e%32,o=\"No cluster with the specified id.\",i=this.trees[r];if(!i)throw new Error(o);var n=i.points[t];if(!n)throw new Error(o);for(var a=this.options.radius/(this.options.extent*Math.pow(2,r-1)),s=[],u=0,l=i.within(n.x,n.y,a);u<l.length;u+=1){var h=l[u],c=i.points[h];c.parentId===e&&s.push(c.numPoints?K(c):this.points[c.index]);}if(0===s.length)throw new Error(o);return s},U.prototype.getLeaves=function(e,t,r){t=t||10,r=r||0;var o=[];return this._appendLeaves(o,e,t,r,0),o},U.prototype.getTile=function(e,t,r){var o=this.trees[this._limitZoom(e)],i=Math.pow(2,e),n=this.options,a=n.extent,s=n.radius/a,u=(r-s)/i,l=(r+1+s)/i,h={features:[]};return this._addTileFeatures(o.range((t-s)/i,u,(t+1+s)/i,l),o.points,t,r,i,h),0===t&&this._addTileFeatures(o.range(1-s/i,u,1,l),o.points,i,r,i,h),t===i-1&&this._addTileFeatures(o.range(0,u,s/i,l),o.points,-1,r,i,h),h.features.length?h:null},U.prototype.getClusterExpansionZoom=function(e){for(var t=e%32-1;t<=this.options.maxZoom;){var r=this.getChildren(e);if(t++,1!==r.length)break;e=r[0].properties.cluster_id;}return t},U.prototype._appendLeaves=function(e,t,r,o,i){for(var n=0,a=this.getChildren(t);n<a.length;n+=1){var s=a[n],u=s.properties;if(u&&u.cluster?i+u.point_count<=o?i+=u.point_count:i=this._appendLeaves(e,u.cluster_id,r,o,i):i<o?i++:e.push(s),e.length===r)break}return i},U.prototype._addTileFeatures=function(e,t,r,o,i,n){for(var a=0,s=e;a<s.length;a+=1){var u=t[s[a]],l={type:1,geometry:[[Math.round(this.options.extent*(u.x*i-r)),Math.round(this.options.extent*(u.y*i-o))]],tags:u.numPoints?Q(u):this.points[u.index].properties},h=u.numPoints?u.id:this.points[u.index].id;void 0!==h&&(l.id=h),n.features.push(l);}},U.prototype._limitZoom=function(e){return Math.max(this.options.minZoom,Math.min(e,this.options.maxZoom+1))},U.prototype._cluster=function(e,t){for(var r=[],o=this.options,i=o.radius,n=o.extent,a=o.reduce,s=i/(n*Math.pow(2,t)),u=0;u<e.length;u++){var l=e[u];if(!(l.zoom<=t)){l.zoom=t;for(var h=this.trees[t+1],c=h.within(l.x,l.y,s),p=l.numPoints||1,f=l.x*p,d=l.y*p,g=a?this._map(l,!0):null,m=(u<<5)+(t+1),v=0,y=c;v<y.length;v+=1){var x=y[v],w=h.points[x];if(!(w.zoom<=t)){w.zoom=t;var S=w.numPoints||1;f+=w.x*S,d+=w.y*S,p+=S,w.parentId=m,a&&a(g,this._map(w));}}1===p?r.push(l):(l.parentId=m,r.push($(f/p,d/p,m,p,g)));}}return r},U.prototype._map=function(e,t){if(e.numPoints)return t?re({},e.properties):e.properties;var r=this.points[e.index].properties,o=this.options.map(r);return t&&o===r?re({},o):o},Le.prototype.options={maxZoom:14,indexMaxZoom:5,indexMaxPoints:1e5,tolerance:3,extent:4096,buffer:64,lineMetrics:!1,promoteId:null,generateId:!1,debug:0},Le.prototype.splitTile=function(e,t,r,o,i,n,a){for(var s=[e,t,r,o],u=this.options,l=u.debug;s.length;){o=s.pop(),r=s.pop(),t=s.pop(),e=s.pop();var h=1<<t,c=De(t,r,o),p=this.tiles[c];if(!p&&(l>1&&console.time(\"creation\"),p=this.tiles[c]=Pe(e,t,r,o,u),this.tileCoords.push({z:t,x:r,y:o}),l)){l>1&&(console.log(\"tile z%d-%d-%d (features: %d, points: %d, simplified: %d)\",t,r,o,p.numFeatures,p.numPoints,p.numSimplified),console.timeEnd(\"creation\"));var f=\"z\"+t;this.stats[f]=(this.stats[f]||0)+1,this.total++;}if(p.source=e,i){if(t===u.maxZoom||t===i)continue;var d=1<<i-t;if(r!==Math.floor(n/d)||o!==Math.floor(a/d))continue}else if(t===u.indexMaxZoom||p.numPoints<=u.indexMaxPoints)continue;if(p.source=null,0!==e.length){l>1&&console.time(\"clipping\");var g,m,v,y,x,w,S=.5*u.buffer/u.extent,M=.5-S,k=.5+S,b=1+S;g=m=v=y=null,x=de(e,h,r-S,r+k,0,p.minX,p.maxX,u),w=de(e,h,r+M,r+b,0,p.minX,p.maxX,u),e=null,x&&(g=de(x,h,o-S,o+k,1,p.minY,p.maxY,u),m=de(x,h,o+M,o+b,1,p.minY,p.maxY,u),x=null),w&&(v=de(w,h,o-S,o+k,1,p.minY,p.maxY,u),y=de(w,h,o+M,o+b,1,p.minY,p.maxY,u),w=null),l>1&&console.timeEnd(\"clipping\"),s.push(g||[],t+1,2*r,2*o),s.push(m||[],t+1,2*r,2*o+1),s.push(v||[],t+1,2*r+1,2*o),s.push(y||[],t+1,2*r+1,2*o+1);}}},Le.prototype.getTile=function(e,t,r){var o=this.options,i=o.extent,n=o.debug;if(e<0||e>24)return null;var a=1<<e,s=De(e,t=(t%a+a)%a,r);if(this.tiles[s])return be(this.tiles[s],i);n>1&&console.log(\"drilling down to z%d-%d-%d\",e,t,r);for(var u,l=e,h=t,c=r;!u&&l>0;)l--,h=Math.floor(h/2),c=Math.floor(c/2),u=this.tiles[De(l,h,c)];return u&&u.source?(n>1&&console.log(\"found parent tile z%d-%d-%d\",l,h,c),n>1&&console.time(\"drilling down\"),this.splitTile(u.source,l,h,c,e,t,r),n>1&&console.timeEnd(\"drilling down\"),this.tiles[s]?be(this.tiles[s],i):null):null};var ze=function(t){function r(e,r,o){t.call(this,e,r,Ce),o&&(this.loadGeoJSON=o);}return t&&(r.__proto__=t),r.prototype=Object.create(t&&t.prototype),r.prototype.constructor=r,r.prototype.loadData=function(e,t){this._pendingCallback&&this._pendingCallback(null,{abandoned:!0}),this._pendingCallback=t,this._pendingLoadDataParams=e,this._state&&\"Idle\"!==this._state?this._state=\"NeedsLoadData\":(this._state=\"Coalescing\",this._loadData());},r.prototype._loadData=function(){var t=this;if(this._pendingCallback&&this._pendingLoadDataParams){var r=this._pendingCallback,o=this._pendingLoadDataParams;delete this._pendingCallback,delete this._pendingLoadDataParams;var i=!!(o&&o.request&&o.request.collectResourceTiming)&&new u.Performance(o.request);this.loadGeoJSON(o,function(n,a){if(n||!a)return r(n);if(\"object\"!=typeof a)return r(new Error(\"Input data given to '\"+o.source+\"' is not a valid GeoJSON object.\"));y(a,!0);try{t._geoJSONIndex=o.cluster?new U(function(t){var r=t.superclusterOptions,o=t.clusterProperties;if(!o||!r)return r;for(var i={},n={},a={accumulated:null,zoom:0},s={properties:null},u=Object.keys(o),l=0,h=u;l<h.length;l+=1){var c=h[l],p=o[c],f=p[0],d=p[1],g=e.createExpression(d),m=e.createExpression(\"string\"==typeof f?[f,[\"accumulated\"],[\"get\",c]]:f);i[c]=g.value,n[c]=m.value;}return r.map=function(e){s.properties=e;for(var t={},r=0,o=u;r<o.length;r+=1){var n=o[r];t[n]=i[n].evaluate(a,s);}return t},r.reduce=function(e,t){s.properties=t;for(var r=0,o=u;r<o.length;r+=1){var i=o[r];a.accumulated=e[i],e[i]=n[i].evaluate(a,s);}},r}(o)).load(a.features):function(e,t){return new Le(e,t)}(a,o.geojsonVtOptions);}catch(n){return r(n)}t.loaded={};var s={};if(i){var u=i.finish();u&&(s.resourceTiming={},s.resourceTiming[o.source]=JSON.parse(JSON.stringify(u)));}r(null,s);});}},r.prototype.coalesce=function(){\"Coalescing\"===this._state?this._state=\"Idle\":\"NeedsLoadData\"===this._state&&(this._state=\"Coalescing\",this._loadData());},r.prototype.reloadTile=function(e,r){var o=this.loaded,i=e.uid;return o&&o[i]?t.prototype.reloadTile.call(this,e,r):this.loadTile(e,r)},r.prototype.loadGeoJSON=function(t,r){if(t.request)e.getJSON(t.request,r);else{if(\"string\"!=typeof t.data)return r(new Error(\"Input data given to '\"+t.source+\"' is not a valid GeoJSON object.\"));try{return r(null,JSON.parse(t.data))}catch(e){return r(new Error(\"Input data given to '\"+t.source+\"' is not a valid GeoJSON object.\"))}}},r.prototype.removeSource=function(e,t){this._pendingCallback&&this._pendingCallback(null,{abandoned:!0}),t();},r.prototype.getClusterExpansionZoom=function(e,t){t(null,this._geoJSONIndex.getClusterExpansionZoom(e.clusterId));},r.prototype.getClusterChildren=function(e,t){t(null,this._geoJSONIndex.getChildren(e.clusterId));},r.prototype.getClusterLeaves=function(e,t){t(null,this._geoJSONIndex.getLeaves(e.clusterId,e.limit,e.offset));},r}(c);var Oe=function(t){var r=this;this.self=t,this.actor=new e.Actor(t,this),this.layerIndexes={},this.workerSourceTypes={vector:c,geojson:ze},this.workerSources={},this.demWorkerSources={},this.self.registerWorkerSource=function(e,t){if(r.workerSourceTypes[e])throw new Error('Worker source with name \"'+e+'\" already registered.');r.workerSourceTypes[e]=t;},this.self.registerRTLTextPlugin=function(t){if(e.plugin.isLoaded())throw new Error(\"RTL text plugin already registered.\");e.plugin.applyArabicShaping=t.applyArabicShaping,e.plugin.processBidirectionalText=t.processBidirectionalText,e.plugin.processStyledBidirectionalText=t.processStyledBidirectionalText;};};return Oe.prototype.setReferrer=function(e,t){this.referrer=t;},Oe.prototype.setLayers=function(e,t,r){this.getLayerIndex(e).replace(t),r();},Oe.prototype.updateLayers=function(e,t,r){this.getLayerIndex(e).update(t.layers,t.removedIds),r();},Oe.prototype.loadTile=function(e,t,r){this.getWorkerSource(e,t.type,t.source).loadTile(t,r);},Oe.prototype.loadDEMTile=function(e,t,r){this.getDEMWorkerSource(e,t.source).loadTile(t,r);},Oe.prototype.reloadTile=function(e,t,r){this.getWorkerSource(e,t.type,t.source).reloadTile(t,r);},Oe.prototype.abortTile=function(e,t,r){this.getWorkerSource(e,t.type,t.source).abortTile(t,r);},Oe.prototype.removeTile=function(e,t,r){this.getWorkerSource(e,t.type,t.source).removeTile(t,r);},Oe.prototype.removeDEMTile=function(e,t){this.getDEMWorkerSource(e,t.source).removeTile(t);},Oe.prototype.removeSource=function(e,t,r){if(this.workerSources[e]&&this.workerSources[e][t.type]&&this.workerSources[e][t.type][t.source]){var o=this.workerSources[e][t.type][t.source];delete this.workerSources[e][t.type][t.source],void 0!==o.removeSource?o.removeSource(t,r):r();}},Oe.prototype.loadWorkerSource=function(e,t,r){try{this.self.importScripts(t.url),r();}catch(e){r(e.toString());}},Oe.prototype.loadRTLTextPlugin=function(t,r,o){try{e.plugin.isLoaded()||(this.self.importScripts(r),o(e.plugin.isLoaded()?null:new Error(\"RTL Text Plugin failed to import scripts from \"+r)));}catch(e){o(e.toString());}},Oe.prototype.getLayerIndex=function(e){var t=this.layerIndexes[e];return t||(t=this.layerIndexes[e]=new o),t},Oe.prototype.getWorkerSource=function(e,t,r){var o=this;if(this.workerSources[e]||(this.workerSources[e]={}),this.workerSources[e][t]||(this.workerSources[e][t]={}),!this.workerSources[e][t][r]){var i={send:function(t,r,i){o.actor.send(t,r,i,e);}};this.workerSources[e][t][r]=new this.workerSourceTypes[t](i,this.getLayerIndex(e));}return this.workerSources[e][t][r]},Oe.prototype.getDEMWorkerSource=function(e,t){return this.demWorkerSources[e]||(this.demWorkerSources[e]={}),this.demWorkerSources[e][t]||(this.demWorkerSources[e][t]=new p),this.demWorkerSources[e][t]},Oe.prototype.enforceCacheSizeLimit=function(t,r){e.enforceCacheSizeLimit(r);},\"undefined\"!=typeof WorkerGlobalScope&&void 0!==e.window&&e.window instanceof WorkerGlobalScope&&(e.window.worker=new Oe(e.window)),Oe});\n\ndefine([\"./shared.js\"],function(t){\"use strict\";var e=t.createCommonjsModule(function(t){function e(t){return !!(\"undefined\"!=typeof window&&\"undefined\"!=typeof document&&Array.prototype&&Array.prototype.every&&Array.prototype.filter&&Array.prototype.forEach&&Array.prototype.indexOf&&Array.prototype.lastIndexOf&&Array.prototype.map&&Array.prototype.some&&Array.prototype.reduce&&Array.prototype.reduceRight&&Array.isArray&&Function.prototype&&Function.prototype.bind&&Object.keys&&Object.create&&Object.getPrototypeOf&&Object.getOwnPropertyNames&&Object.isSealed&&Object.isFrozen&&Object.isExtensible&&Object.getOwnPropertyDescriptor&&Object.defineProperty&&Object.defineProperties&&Object.seal&&Object.freeze&&Object.preventExtensions&&\"JSON\"in window&&\"parse\"in JSON&&\"stringify\"in JSON&&function(){if(!(\"Worker\"in window&&\"Blob\"in window&&\"URL\"in window))return !1;var t,e,i=new Blob([\"\"],{type:\"text/javascript\"}),o=URL.createObjectURL(i);try{e=new Worker(o),t=!0;}catch(e){t=!1;}e&&e.terminate();return URL.revokeObjectURL(o),t}()&&\"Uint8ClampedArray\"in window&&ArrayBuffer.isView&&function(t){void 0===i[t]&&(i[t]=function(t){var i=document.createElement(\"canvas\"),o=Object.create(e.webGLContextAttributes);return o.failIfMajorPerformanceCaveat=t,i.probablySupportsContext?i.probablySupportsContext(\"webgl\",o)||i.probablySupportsContext(\"experimental-webgl\",o):i.supportsContext?i.supportsContext(\"webgl\",o)||i.supportsContext(\"experimental-webgl\",o):i.getContext(\"webgl\",o)||i.getContext(\"experimental-webgl\",o)}(t));return i[t]}(t&&t.failIfMajorPerformanceCaveat))}t.exports?t.exports=e:window&&(window.mapboxgl=window.mapboxgl||{},window.mapboxgl.supported=e);var i={};e.webGLContextAttributes={antialias:!1,alpha:!0,stencil:!0,depth:!0};}),i={create:function(e,i,o){var r=t.window.document.createElement(e);return void 0!==i&&(r.className=i),o&&o.appendChild(r),r},createNS:function(e,i){return t.window.document.createElementNS(e,i)}},o=t.window.document.documentElement.style;function r(t){if(!o)return t[0];for(var e=0;e<t.length;e++)if(t[e]in o)return t[e];return t[0]}var a,n=r([\"userSelect\",\"MozUserSelect\",\"WebkitUserSelect\",\"msUserSelect\"]);i.disableDrag=function(){o&&n&&(a=o[n],o[n]=\"none\");},i.enableDrag=function(){o&&n&&(o[n]=a);};var s=r([\"transform\",\"WebkitTransform\"]);i.setTransform=function(t,e){t.style[s]=e;};var l=!1;try{var c=Object.defineProperty({},\"passive\",{get:function(){l=!0;}});t.window.addEventListener(\"test\",c,c),t.window.removeEventListener(\"test\",c,c);}catch(t){l=!1;}i.addEventListener=function(t,e,i,o){void 0===o&&(o={}),\"passive\"in o&&l?t.addEventListener(e,i,o):t.addEventListener(e,i,o.capture);},i.removeEventListener=function(t,e,i,o){void 0===o&&(o={}),\"passive\"in o&&l?t.removeEventListener(e,i,o):t.removeEventListener(e,i,o.capture);};var u=function(e){e.preventDefault(),e.stopPropagation(),t.window.removeEventListener(\"click\",u,!0);};function h(t){var e=t.userImage;if(e&&e.render&&e.render())return t.data.replace(new Uint8Array(e.data.buffer)),!0;return !1}i.suppressClick=function(){t.window.addEventListener(\"click\",u,!0),t.window.setTimeout(function(){t.window.removeEventListener(\"click\",u,!0);},0);},i.mousePos=function(e,i){var o=e.getBoundingClientRect(),r=t.window.TouchEvent&&i instanceof t.window.TouchEvent?i.touches[0]:i;return new t.Point(r.clientX-o.left-e.clientLeft,r.clientY-o.top-e.clientTop)},i.touchPos=function(e,i){for(var o=e.getBoundingClientRect(),r=[],a=\"touchend\"===i.type?i.changedTouches:i.touches,n=0;n<a.length;n++)r.push(new t.Point(a[n].clientX-o.left-e.clientLeft,a[n].clientY-o.top-e.clientTop));return r},i.mouseButton=function(e){return void 0!==t.window.InstallTrigger&&2===e.button&&e.ctrlKey&&t.window.navigator.platform.toUpperCase().indexOf(\"MAC\")>=0?0:e.button},i.remove=function(t){t.parentNode&&t.parentNode.removeChild(t);};var p=function(e){function i(){e.call(this),this.images={},this.updatedImages={},this.callbackDispatchedThisFrame={},this.loaded=!1,this.requestors=[],this.patterns={},this.atlasImage=new t.RGBAImage({width:1,height:1}),this.dirty=!0;}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.isLoaded=function(){return this.loaded},i.prototype.setLoaded=function(t){if(this.loaded!==t&&(this.loaded=t,t)){for(var e=0,i=this.requestors;e<i.length;e+=1){var o=i[e],r=o.ids,a=o.callback;this._notify(r,a);}this.requestors=[];}},i.prototype.getImage=function(t){return this.images[t]},i.prototype.addImage=function(t,e){this.images[t]=e;},i.prototype.updateImage=function(t,e){var i=this.images[t];e.version=i.version+1,this.images[t]=e,this.updatedImages[t]=!0;},i.prototype.removeImage=function(t){var e=this.images[t];delete this.images[t],delete this.patterns[t],e.userImage&&e.userImage.onRemove&&e.userImage.onRemove();},i.prototype.listImages=function(){return Object.keys(this.images)},i.prototype.getImages=function(t,e){var i=!0;if(!this.isLoaded())for(var o=0,r=t;o<r.length;o+=1){var a=r[o];this.images[a]||(i=!1);}this.isLoaded()||i?this._notify(t,e):this.requestors.push({ids:t,callback:e});},i.prototype._notify=function(e,i){for(var o={},r=0,a=e;r<a.length;r+=1){var n=a[r];this.images[n]||this.fire(new t.Event(\"styleimagemissing\",{id:n}));var s=this.images[n];s?o[n]={data:s.data.clone(),pixelRatio:s.pixelRatio,sdf:s.sdf,version:s.version,hasRenderCallback:Boolean(s.userImage&&s.userImage.render)}:t.warnOnce('Image \"'+n+'\" could not be loaded. Please make sure you have added the image with map.addImage() or a \"sprite\" property in your style. You can provide missing images by listening for the \"styleimagemissing\" map event.');}i(null,o);},i.prototype.getPixelSize=function(){var t=this.atlasImage;return {width:t.width,height:t.height}},i.prototype.getPattern=function(e){var i=this.patterns[e],o=this.getImage(e);if(!o)return null;if(i&&i.position.version===o.version)return i.position;if(i)i.position.version=o.version;else{var r={w:o.data.width+2,h:o.data.height+2,x:0,y:0},a=new t.ImagePosition(r,o);this.patterns[e]={bin:r,position:a};}return this._updatePatternAtlas(),this.patterns[e].position},i.prototype.bind=function(e){var i=e.gl;this.atlasTexture?this.dirty&&(this.atlasTexture.update(this.atlasImage),this.dirty=!1):this.atlasTexture=new t.Texture(e,this.atlasImage,i.RGBA),this.atlasTexture.bind(i.LINEAR,i.CLAMP_TO_EDGE);},i.prototype._updatePatternAtlas=function(){var e=[];for(var i in this.patterns)e.push(this.patterns[i].bin);var o=t.potpack(e),r=o.w,a=o.h,n=this.atlasImage;for(var s in n.resize({width:r||1,height:a||1}),this.patterns){var l=this.patterns[s].bin,c=l.x+1,u=l.y+1,h=this.images[s].data,p=h.width,d=h.height;t.RGBAImage.copy(h,n,{x:0,y:0},{x:c,y:u},{width:p,height:d}),t.RGBAImage.copy(h,n,{x:0,y:d-1},{x:c,y:u-1},{width:p,height:1}),t.RGBAImage.copy(h,n,{x:0,y:0},{x:c,y:u+d},{width:p,height:1}),t.RGBAImage.copy(h,n,{x:p-1,y:0},{x:c-1,y:u},{width:1,height:d}),t.RGBAImage.copy(h,n,{x:0,y:0},{x:c+p,y:u},{width:1,height:d});}this.dirty=!0;},i.prototype.beginFrame=function(){this.callbackDispatchedThisFrame={};},i.prototype.dispatchRenderCallbacks=function(t){for(var e=0,i=t;e<i.length;e+=1){var o=i[e];if(!this.callbackDispatchedThisFrame[o]){this.callbackDispatchedThisFrame[o]=!0;var r=this.images[o];h(r)&&this.updateImage(o,r);}}},i}(t.Evented);var d=f,_=1e20;function f(t,e,i,o,r,a){this.fontSize=t||24,this.buffer=void 0===e?3:e,this.cutoff=o||.25,this.fontFamily=r||\"sans-serif\",this.fontWeight=a||\"normal\",this.radius=i||8;var n=this.size=this.fontSize+2*this.buffer;this.canvas=document.createElement(\"canvas\"),this.canvas.width=this.canvas.height=n,this.ctx=this.canvas.getContext(\"2d\"),this.ctx.font=this.fontWeight+\" \"+this.fontSize+\"px \"+this.fontFamily,this.ctx.textBaseline=\"middle\",this.ctx.fillStyle=\"black\",this.gridOuter=new Float64Array(n*n),this.gridInner=new Float64Array(n*n),this.f=new Float64Array(n),this.d=new Float64Array(n),this.z=new Float64Array(n+1),this.v=new Int16Array(n),this.middle=Math.round(n/2*(navigator.userAgent.indexOf(\"Gecko/\")>=0?1.2:1));}function m(t,e,i,o,r,a,n){for(var s=0;s<e;s++){for(var l=0;l<i;l++)o[l]=t[l*e+s];for(g(o,r,a,n,i),l=0;l<i;l++)t[l*e+s]=r[l];}for(l=0;l<i;l++){for(s=0;s<e;s++)o[s]=t[l*e+s];for(g(o,r,a,n,e),s=0;s<e;s++)t[l*e+s]=Math.sqrt(r[s]);}}function g(t,e,i,o,r){i[0]=0,o[0]=-_,o[1]=+_;for(var a=1,n=0;a<r;a++){for(var s=(t[a]+a*a-(t[i[n]]+i[n]*i[n]))/(2*a-2*i[n]);s<=o[n];)n--,s=(t[a]+a*a-(t[i[n]]+i[n]*i[n]))/(2*a-2*i[n]);i[++n]=a,o[n]=s,o[n+1]=+_;}for(a=0,n=0;a<r;a++){for(;o[n+1]<a;)n++;e[a]=(a-i[n])*(a-i[n])+t[i[n]];}}f.prototype.draw=function(t){this.ctx.clearRect(0,0,this.size,this.size),this.ctx.fillText(t,this.buffer,this.middle);for(var e=this.ctx.getImageData(0,0,this.size,this.size),i=new Uint8ClampedArray(this.size*this.size),o=0;o<this.size*this.size;o++){var r=e.data[4*o+3]/255;this.gridOuter[o]=1===r?0:0===r?_:Math.pow(Math.max(0,.5-r),2),this.gridInner[o]=1===r?_:0===r?0:Math.pow(Math.max(0,r-.5),2);}for(m(this.gridOuter,this.size,this.size,this.f,this.d,this.v,this.z),m(this.gridInner,this.size,this.size,this.f,this.d,this.v,this.z),o=0;o<this.size*this.size;o++){var a=this.gridOuter[o]-this.gridInner[o];i[o]=Math.max(0,Math.min(255,Math.round(255-255*(a/this.radius+this.cutoff))));}return i};var v=function(t,e){this.requestManager=t,this.localIdeographFontFamily=e,this.entries={};};v.prototype.setURL=function(t){this.url=t;},v.prototype.getGlyphs=function(e,i){var o=this,r=[];for(var a in e)for(var n=0,s=e[a];n<s.length;n+=1){var l=s[n];r.push({stack:a,id:l});}t.asyncAll(r,function(t,e){var i=t.stack,r=t.id,a=o.entries[i];a||(a=o.entries[i]={glyphs:{},requests:{}});var n=a.glyphs[r];if(void 0===n)if(n=o._tinySDF(a,i,r))e(null,{stack:i,id:r,glyph:n});else{var s=Math.floor(r/256);if(256*s>65535)e(new Error(\"glyphs > 65535 not supported\"));else{var l=a.requests[s];l||(l=a.requests[s]=[],v.loadGlyphRange(i,s,o.url,o.requestManager,function(t,e){if(e)for(var i in e)a.glyphs[+i]=e[+i];for(var o=0,r=l;o<r.length;o+=1){(0,r[o])(t,e);}delete a.requests[s];})),l.push(function(t,o){t?e(t):o&&e(null,{stack:i,id:r,glyph:o[r]||null});});}}else e(null,{stack:i,id:r,glyph:n});},function(t,e){if(t)i(t);else if(e){for(var o={},r=0,a=e;r<a.length;r+=1){var n=a[r],s=n.stack,l=n.id,c=n.glyph;(o[s]||(o[s]={}))[l]=c&&{id:c.id,bitmap:c.bitmap.clone(),metrics:c.metrics};}i(null,o);}});},v.prototype._tinySDF=function(e,i,o){var r=this.localIdeographFontFamily;if(r&&(t.isChar[\"CJK Unified Ideographs\"](o)||t.isChar[\"Hangul Syllables\"](o)||t.isChar.Hiragana(o)||t.isChar.Katakana(o))){var a=e.tinySDF;if(!a){var n=\"400\";/bold/i.test(i)?n=\"900\":/medium/i.test(i)?n=\"500\":/light/i.test(i)&&(n=\"200\"),a=e.tinySDF=new v.TinySDF(24,3,8,.25,r,n);}return {id:o,bitmap:new t.AlphaImage({width:30,height:30},a.draw(String.fromCharCode(o))),metrics:{width:24,height:24,left:0,top:-8,advance:24}}}},v.loadGlyphRange=function(e,i,o,r,a){var n=256*i,s=n+255,l=r.transformRequest(r.normalizeGlyphsURL(o).replace(\"{fontstack}\",e).replace(\"{range}\",n+\"-\"+s),t.ResourceType.Glyphs);t.getArrayBuffer(l,function(e,i){if(e)a(e);else if(i){for(var o={},r=0,n=t.parseGlyphPBF(i);r<n.length;r+=1){var s=n[r];o[s.id]=s;}a(null,o);}});},v.TinySDF=d;var y=function(){this.specification=t.styleSpec.light.position;};y.prototype.possiblyEvaluate=function(e,i){return t.sphericalToCartesian(e.expression.evaluate(i))},y.prototype.interpolate=function(e,i,o){return {x:t.number(e.x,i.x,o),y:t.number(e.y,i.y,o),z:t.number(e.z,i.z,o)}};var x=new t.Properties({anchor:new t.DataConstantProperty(t.styleSpec.light.anchor),position:new y,color:new t.DataConstantProperty(t.styleSpec.light.color),intensity:new t.DataConstantProperty(t.styleSpec.light.intensity)}),b=function(e){function i(i){e.call(this),this._transitionable=new t.Transitionable(x),this.setLight(i),this._transitioning=this._transitionable.untransitioned();}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.getLight=function(){return this._transitionable.serialize()},i.prototype.setLight=function(e,i){if(void 0===i&&(i={}),!this._validate(t.validateLight,e,i))for(var o in e){var r=e[o];t.endsWith(o,\"-transition\")?this._transitionable.setTransition(o.slice(0,-\"-transition\".length),r):this._transitionable.setValue(o,r);}},i.prototype.updateTransitions=function(t){this._transitioning=this._transitionable.transitioned(t,this._transitioning);},i.prototype.hasTransition=function(){return this._transitioning.hasTransition()},i.prototype.recalculate=function(t){this.properties=this._transitioning.possiblyEvaluate(t);},i.prototype._validate=function(e,i,o){return (!o||!1!==o.validate)&&t.emitValidationErrors(this,e.call(t.validateStyle,t.extend({value:i,style:{glyphs:!0,sprite:!0},styleSpec:t.styleSpec})))},i}(t.Evented),w=function(t,e){this.width=t,this.height=e,this.nextRow=0,this.bytes=4,this.data=new Uint8Array(this.width*this.height*this.bytes),this.positions={};};w.prototype.getDash=function(t,e){var i=t.join(\",\")+String(e);return this.positions[i]||(this.positions[i]=this.addDash(t,e)),this.positions[i]},w.prototype.addDash=function(e,i){var o=i?7:0,r=2*o+1;if(this.nextRow+r>this.height)return t.warnOnce(\"LineAtlas out of space\"),null;for(var a=0,n=0;n<e.length;n++)a+=e[n];for(var s=this.width/a,l=s/2,c=e.length%2==1,u=-o;u<=o;u++)for(var h=this.nextRow+o+u,p=this.width*h,d=c?-e[e.length-1]:0,_=e[0],f=1,m=0;m<this.width;m++){for(;_<m/s;)d=_,_+=e[f],c&&f===e.length-1&&(_+=e[0]),f++;var g=Math.abs(m-d*s),v=Math.abs(m-_*s),y=Math.min(g,v),x=f%2==1,b=void 0;if(i){var w=o?u/o*(l+1):0;if(x){var E=l-Math.abs(w);b=Math.sqrt(y*y+E*E);}else b=l-Math.sqrt(y*y+w*w);}else b=(x?1:-1)*y;this.data[3+4*(p+m)]=Math.max(0,Math.min(255,b+128));}var T={y:(this.nextRow+o+.5)/this.height,height:2*o/this.height,width:a};return this.nextRow+=r,this.dirty=!0,T},w.prototype.bind=function(t){var e=t.gl;this.texture?(e.bindTexture(e.TEXTURE_2D,this.texture),this.dirty&&(this.dirty=!1,e.texSubImage2D(e.TEXTURE_2D,0,0,0,this.width,this.height,e.RGBA,e.UNSIGNED_BYTE,this.data))):(this.texture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.texture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,this.width,this.height,0,e.RGBA,e.UNSIGNED_BYTE,this.data));};var E=function e(i,o){this.workerPool=i,this.actors=[],this.currentActor=0,this.id=t.uniqueId();for(var r=this.workerPool.acquire(this.id),a=0;a<r.length;a++){var n=r[a],s=new e.Actor(n,o,this.id);s.name=\"Worker \"+a,this.actors.push(s);}};function T(e,i,o){var r=function(r,a){if(r)return o(r);if(a){var n=t.pick(a,[\"tiles\",\"minzoom\",\"maxzoom\",\"attribution\",\"mapbox_logo\",\"bounds\"]);a.vector_layers&&(n.vectorLayers=a.vector_layers,n.vectorLayerIds=n.vectorLayers.map(function(t){return t.id})),e.url&&(n.tiles=i.canonicalizeTileset(n,e.url)),o(null,n);}};return e.url?t.getJSON(i.transformRequest(i.normalizeSourceURL(e.url),t.ResourceType.Source),r):t.browser.frame(function(){return r(null,e)})}E.prototype.broadcast=function(e,i,o){o=o||function(){},t.asyncAll(this.actors,function(t,o){t.send(e,i,o);},o);},E.prototype.send=function(t,e,i,o){return (\"number\"!=typeof o||isNaN(o))&&(o=this.currentActor=(this.currentActor+1)%this.actors.length),this.actors[o].send(t,e,i),o},E.prototype.remove=function(){this.actors.forEach(function(t){t.remove();}),this.actors=[],this.workerPool.release(this.id);},E.Actor=t.Actor;var I=function(e,i,o){this.bounds=t.LngLatBounds.convert(this.validateBounds(e)),this.minzoom=i||0,this.maxzoom=o||24;};I.prototype.validateBounds=function(t){return Array.isArray(t)&&4===t.length?[Math.max(-180,t[0]),Math.max(-90,t[1]),Math.min(180,t[2]),Math.min(90,t[3])]:[-180,-90,180,90]},I.prototype.contains=function(e){var i=Math.pow(2,e.z),o=Math.floor(t.mercatorXfromLng(this.bounds.getWest())*i),r=Math.floor(t.mercatorYfromLat(this.bounds.getNorth())*i),a=Math.ceil(t.mercatorXfromLng(this.bounds.getEast())*i),n=Math.ceil(t.mercatorYfromLat(this.bounds.getSouth())*i);return e.x>=o&&e.x<a&&e.y>=r&&e.y<n};var C=function(e){function i(i,o,r,a){if(e.call(this),this.id=i,this.dispatcher=r,this.type=\"vector\",this.minzoom=0,this.maxzoom=22,this.scheme=\"xyz\",this.tileSize=512,this.reparseOverscaled=!0,this.isTileClipped=!0,t.extend(this,t.pick(o,[\"url\",\"scheme\",\"tileSize\"])),this._options=t.extend({type:\"vector\"},o),this._collectResourceTiming=o.collectResourceTiming,512!==this.tileSize)throw new Error(\"vector tile sources must have a tileSize of 512\");this.setEventedParent(a);}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.load=function(){var e=this;this.fire(new t.Event(\"dataloading\",{dataType:\"source\"})),this._tileJSONRequest=T(this._options,this.map._requestManager,function(i,o){e._tileJSONRequest=null,i?e.fire(new t.ErrorEvent(i)):o&&(t.extend(e,o),o.bounds&&(e.tileBounds=new I(o.bounds,e.minzoom,e.maxzoom)),t.postTurnstileEvent(o.tiles),t.postMapLoadEvent(o.tiles,e.map._getMapId(),e.map._requestManager._skuToken),e.fire(new t.Event(\"data\",{dataType:\"source\",sourceDataType:\"metadata\"})),e.fire(new t.Event(\"data\",{dataType:\"source\",sourceDataType:\"content\"})));});},i.prototype.hasTile=function(t){return !this.tileBounds||this.tileBounds.contains(t.canonical)},i.prototype.onAdd=function(t){this.map=t,this.load();},i.prototype.onRemove=function(){this._tileJSONRequest&&(this._tileJSONRequest.cancel(),this._tileJSONRequest=null);},i.prototype.serialize=function(){return t.extend({},this._options)},i.prototype.loadTile=function(e,i){var o=this.map._requestManager.normalizeTileURL(e.tileID.canonical.url(this.tiles,this.scheme),this.url,null),r={request:this.map._requestManager.transformRequest(o,t.ResourceType.Tile),uid:e.uid,tileID:e.tileID,zoom:e.tileID.overscaledZ,tileSize:this.tileSize*e.tileID.overscaleFactor(),type:this.type,source:this.id,pixelRatio:t.browser.devicePixelRatio,showCollisionBoxes:this.map.showCollisionBoxes};function a(o,r){return e.aborted?i(null):o&&404!==o.status?i(o):(r&&r.resourceTiming&&(e.resourceTiming=r.resourceTiming),this.map._refreshExpiredTiles&&r&&e.setExpiryData(r),e.loadVectorData(r,this.map.painter),t.cacheEntryPossiblyAdded(this.dispatcher),i(null),void(e.reloadCallback&&(this.loadTile(e,e.reloadCallback),e.reloadCallback=null)))}r.request.collectResourceTiming=this._collectResourceTiming,void 0===e.workerID||\"expired\"===e.state?e.workerID=this.dispatcher.send(\"loadTile\",r,a.bind(this)):\"loading\"===e.state?e.reloadCallback=i:this.dispatcher.send(\"reloadTile\",r,a.bind(this),e.workerID);},i.prototype.abortTile=function(t){this.dispatcher.send(\"abortTile\",{uid:t.uid,type:this.type,source:this.id},void 0,t.workerID);},i.prototype.unloadTile=function(t){t.unloadVectorData(),this.dispatcher.send(\"removeTile\",{uid:t.uid,type:this.type,source:this.id},void 0,t.workerID);},i.prototype.hasTransition=function(){return !1},i}(t.Evented),S=function(e){function i(i,o,r,a){e.call(this),this.id=i,this.dispatcher=r,this.setEventedParent(a),this.type=\"raster\",this.minzoom=0,this.maxzoom=22,this.roundZoom=!0,this.scheme=\"xyz\",this.tileSize=512,this._loaded=!1,this._options=t.extend({},o),t.extend(this,t.pick(o,[\"url\",\"scheme\",\"tileSize\"]));}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.load=function(){var e=this;this.fire(new t.Event(\"dataloading\",{dataType:\"source\"})),this._tileJSONRequest=T(this._options,this.map._requestManager,function(i,o){e._tileJSONRequest=null,i?e.fire(new t.ErrorEvent(i)):o&&(t.extend(e,o),o.bounds&&(e.tileBounds=new I(o.bounds,e.minzoom,e.maxzoom)),t.postTurnstileEvent(o.tiles),t.postMapLoadEvent(o.tiles,e.map._getMapId(),e.map._requestManager._skuToken),e.fire(new t.Event(\"data\",{dataType:\"source\",sourceDataType:\"metadata\"})),e.fire(new t.Event(\"data\",{dataType:\"source\",sourceDataType:\"content\"})));});},i.prototype.onAdd=function(t){this.map=t,this.load();},i.prototype.onRemove=function(){this._tileJSONRequest&&(this._tileJSONRequest.cancel(),this._tileJSONRequest=null);},i.prototype.serialize=function(){return t.extend({},this._options)},i.prototype.hasTile=function(t){return !this.tileBounds||this.tileBounds.contains(t.canonical)},i.prototype.loadTile=function(e,i){var o=this,r=this.map._requestManager.normalizeTileURL(e.tileID.canonical.url(this.tiles,this.scheme),this.url,this.tileSize);e.request=t.getImage(this.map._requestManager.transformRequest(r,t.ResourceType.Tile),function(r,a){if(delete e.request,e.aborted)e.state=\"unloaded\",i(null);else if(r)e.state=\"errored\",i(r);else if(a){o.map._refreshExpiredTiles&&e.setExpiryData(a),delete a.cacheControl,delete a.expires;var n=o.map.painter.context,s=n.gl;e.texture=o.map.painter.getTileTexture(a.width),e.texture?e.texture.update(a,{useMipmap:!0}):(e.texture=new t.Texture(n,a,s.RGBA,{useMipmap:!0}),e.texture.bind(s.LINEAR,s.CLAMP_TO_EDGE,s.LINEAR_MIPMAP_NEAREST),n.extTextureFilterAnisotropic&&s.texParameterf(s.TEXTURE_2D,n.extTextureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT,n.extTextureFilterAnisotropicMax)),e.state=\"loaded\",t.cacheEntryPossiblyAdded(o.dispatcher),i(null);}});},i.prototype.abortTile=function(t,e){t.request&&(t.request.cancel(),delete t.request),e();},i.prototype.unloadTile=function(t,e){t.texture&&this.map.painter.saveTileTexture(t.texture),e();},i.prototype.hasTransition=function(){return !1},i}(t.Evented),P=function(e){function i(i,o,r,a){e.call(this,i,o,r,a),this.type=\"raster-dem\",this.maxzoom=22,this._options=t.extend({},o),this.encoding=o.encoding||\"mapbox\";}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.serialize=function(){return {type:\"raster-dem\",url:this.url,tileSize:this.tileSize,tiles:this.tiles,bounds:this.bounds,encoding:this.encoding}},i.prototype.loadTile=function(e,i){var o=this.map._requestManager.normalizeTileURL(e.tileID.canonical.url(this.tiles,this.scheme),this.url,this.tileSize);e.request=t.getImage(this.map._requestManager.transformRequest(o,t.ResourceType.Tile),function(o,r){if(delete e.request,e.aborted)e.state=\"unloaded\",i(null);else if(o)e.state=\"errored\",i(o);else if(r){this.map._refreshExpiredTiles&&e.setExpiryData(r),delete r.cacheControl,delete r.expires;var a=t.browser.getImageData(r),n={uid:e.uid,coord:e.tileID,source:this.id,rawImageData:a,encoding:this.encoding};e.workerID&&\"expired\"!==e.state||(e.workerID=this.dispatcher.send(\"loadDEMTile\",n,function(t,o){t&&(e.state=\"errored\",i(t));o&&(e.dem=o,e.needsHillshadePrepare=!0,e.state=\"loaded\",i(null));}.bind(this)));}}.bind(this)),e.neighboringTiles=this._getNeighboringTiles(e.tileID);},i.prototype._getNeighboringTiles=function(e){var i=e.canonical,o=Math.pow(2,i.z),r=(i.x-1+o)%o,a=0===i.x?e.wrap-1:e.wrap,n=(i.x+1+o)%o,s=i.x+1===o?e.wrap+1:e.wrap,l={};return l[new t.OverscaledTileID(e.overscaledZ,a,i.z,r,i.y).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,s,i.z,n,i.y).key]={backfilled:!1},i.y>0&&(l[new t.OverscaledTileID(e.overscaledZ,a,i.z,r,i.y-1).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,e.wrap,i.z,i.x,i.y-1).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,s,i.z,n,i.y-1).key]={backfilled:!1}),i.y+1<o&&(l[new t.OverscaledTileID(e.overscaledZ,a,i.z,r,i.y+1).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,e.wrap,i.z,i.x,i.y+1).key]={backfilled:!1},l[new t.OverscaledTileID(e.overscaledZ,s,i.z,n,i.y+1).key]={backfilled:!1}),l},i.prototype.unloadTile=function(t){t.demTexture&&this.map.painter.saveTileTexture(t.demTexture),t.fbo&&(t.fbo.destroy(),delete t.fbo),t.dem&&delete t.dem,delete t.neighboringTiles,t.state=\"unloaded\",this.dispatcher.send(\"removeDEMTile\",{uid:t.uid,source:this.id},void 0,t.workerID);},i}(S),z=function(e){function i(i,o,r,a){e.call(this),this.id=i,this.type=\"geojson\",this.minzoom=0,this.maxzoom=18,this.tileSize=512,this.isTileClipped=!0,this.reparseOverscaled=!0,this._removed=!1,this.dispatcher=r,this.setEventedParent(a),this._data=o.data,this._options=t.extend({},o),this._collectResourceTiming=o.collectResourceTiming,this._resourceTiming=[],void 0!==o.maxzoom&&(this.maxzoom=o.maxzoom),o.type&&(this.type=o.type),o.attribution&&(this.attribution=o.attribution);var n=t.EXTENT/this.tileSize;this.workerOptions=t.extend({source:this.id,cluster:o.cluster||!1,geojsonVtOptions:{buffer:(void 0!==o.buffer?o.buffer:128)*n,tolerance:(void 0!==o.tolerance?o.tolerance:.375)*n,extent:t.EXTENT,maxZoom:this.maxzoom,lineMetrics:o.lineMetrics||!1,generateId:o.generateId||!1},superclusterOptions:{maxZoom:void 0!==o.clusterMaxZoom?Math.min(o.clusterMaxZoom,this.maxzoom-1):this.maxzoom-1,extent:t.EXTENT,radius:(o.clusterRadius||50)*n,log:!1},clusterProperties:o.clusterProperties},o.workerOptions);}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.load=function(){var e=this;this.fire(new t.Event(\"dataloading\",{dataType:\"source\"})),this._updateWorkerData(function(i){if(i)e.fire(new t.ErrorEvent(i));else{var o={dataType:\"source\",sourceDataType:\"metadata\"};e._collectResourceTiming&&e._resourceTiming&&e._resourceTiming.length>0&&(o.resourceTiming=e._resourceTiming,e._resourceTiming=[]),e.fire(new t.Event(\"data\",o));}});},i.prototype.onAdd=function(t){this.map=t,this.load();},i.prototype.setData=function(e){var i=this;return this._data=e,this.fire(new t.Event(\"dataloading\",{dataType:\"source\"})),this._updateWorkerData(function(e){if(e)i.fire(new t.ErrorEvent(e));else{var o={dataType:\"source\",sourceDataType:\"content\"};i._collectResourceTiming&&i._resourceTiming&&i._resourceTiming.length>0&&(o.resourceTiming=i._resourceTiming,i._resourceTiming=[]),i.fire(new t.Event(\"data\",o));}}),this},i.prototype.getClusterExpansionZoom=function(t,e){return this.dispatcher.send(\"geojson.getClusterExpansionZoom\",{clusterId:t,source:this.id},e,this.workerID),this},i.prototype.getClusterChildren=function(t,e){return this.dispatcher.send(\"geojson.getClusterChildren\",{clusterId:t,source:this.id},e,this.workerID),this},i.prototype.getClusterLeaves=function(t,e,i,o){return this.dispatcher.send(\"geojson.getClusterLeaves\",{source:this.id,clusterId:t,limit:e,offset:i},o,this.workerID),this},i.prototype._updateWorkerData=function(e){var i=this,o=t.extend({},this.workerOptions),r=this._data;\"string\"==typeof r?(o.request=this.map._requestManager.transformRequest(t.browser.resolveURL(r),t.ResourceType.Source),o.request.collectResourceTiming=this._collectResourceTiming):o.data=JSON.stringify(r),this.workerID=this.dispatcher.send(this.type+\".loadData\",o,function(t,r){i._removed||r&&r.abandoned||(i._loaded=!0,r&&r.resourceTiming&&r.resourceTiming[i.id]&&(i._resourceTiming=r.resourceTiming[i.id].slice(0)),i.dispatcher.send(i.type+\".coalesce\",{source:o.source},null,i.workerID),e(t));},this.workerID);},i.prototype.loadTile=function(e,i){var o=this,r=void 0===e.workerID?\"loadTile\":\"reloadTile\",a={type:this.type,uid:e.uid,tileID:e.tileID,zoom:e.tileID.overscaledZ,maxZoom:this.maxzoom,tileSize:this.tileSize,source:this.id,pixelRatio:t.browser.devicePixelRatio,showCollisionBoxes:this.map.showCollisionBoxes};e.workerID=this.dispatcher.send(r,a,function(t,a){return e.unloadVectorData(),e.aborted?i(null):t?i(t):(e.loadVectorData(a,o.map.painter,\"reloadTile\"===r),i(null))},this.workerID);},i.prototype.abortTile=function(t){t.aborted=!0;},i.prototype.unloadTile=function(t){t.unloadVectorData(),this.dispatcher.send(\"removeTile\",{uid:t.uid,type:this.type,source:this.id},null,t.workerID);},i.prototype.onRemove=function(){this._removed=!0,this.dispatcher.send(\"removeSource\",{type:this.type,source:this.id},null,this.workerID);},i.prototype.serialize=function(){return t.extend({},this._options,{type:this.type,data:this._data})},i.prototype.hasTransition=function(){return !1},i}(t.Evented),L=function(e){function i(t,i,o,r){e.call(this),this.id=t,this.dispatcher=o,this.coordinates=i.coordinates,this.type=\"image\",this.minzoom=0,this.maxzoom=22,this.tileSize=512,this.tiles={},this.setEventedParent(r),this.options=i;}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.load=function(e,i){var o=this;this.fire(new t.Event(\"dataloading\",{dataType:\"source\"})),this.url=this.options.url,t.getImage(this.map._requestManager.transformRequest(this.url,t.ResourceType.Image),function(r,a){r?o.fire(new t.ErrorEvent(r)):a&&(o.image=a,e&&(o.coordinates=e),i&&i(),o._finishLoading());});},i.prototype.updateImage=function(t){var e=this;return this.image&&t.url?(this.options.url=t.url,this.load(t.coordinates,function(){e.texture=null;}),this):this},i.prototype._finishLoading=function(){this.map&&(this.setCoordinates(this.coordinates),this.fire(new t.Event(\"data\",{dataType:\"source\",sourceDataType:\"metadata\"})));},i.prototype.onAdd=function(t){this.map=t,this.load();},i.prototype.setCoordinates=function(e){var i=this;this.coordinates=e;var o=e.map(t.MercatorCoordinate.fromLngLat);this.tileID=function(e){for(var i=1/0,o=1/0,r=-1/0,a=-1/0,n=0,s=e;n<s.length;n+=1){var l=s[n];i=Math.min(i,l.x),o=Math.min(o,l.y),r=Math.max(r,l.x),a=Math.max(a,l.y);}var c=r-i,u=a-o,h=Math.max(c,u),p=Math.max(0,Math.floor(-Math.log(h)/Math.LN2)),d=Math.pow(2,p);return new t.CanonicalTileID(p,Math.floor((i+r)/2*d),Math.floor((o+a)/2*d))}(o),this.minzoom=this.maxzoom=this.tileID.z;var r=o.map(function(t){return i.tileID.getTilePoint(t)._round()});return this._boundsArray=new t.StructArrayLayout4i8,this._boundsArray.emplaceBack(r[0].x,r[0].y,0,0),this._boundsArray.emplaceBack(r[1].x,r[1].y,t.EXTENT,0),this._boundsArray.emplaceBack(r[3].x,r[3].y,0,t.EXTENT),this._boundsArray.emplaceBack(r[2].x,r[2].y,t.EXTENT,t.EXTENT),this.boundsBuffer&&(this.boundsBuffer.destroy(),delete this.boundsBuffer),this.fire(new t.Event(\"data\",{dataType:\"source\",sourceDataType:\"content\"})),this},i.prototype.prepare=function(){if(0!==Object.keys(this.tiles).length&&this.image){var e=this.map.painter.context,i=e.gl;for(var o in this.boundsBuffer||(this.boundsBuffer=e.createVertexBuffer(this._boundsArray,t.rasterBoundsAttributes.members)),this.boundsSegments||(this.boundsSegments=t.SegmentVector.simpleSegment(0,0,4,2)),this.texture||(this.texture=new t.Texture(e,this.image,i.RGBA),this.texture.bind(i.LINEAR,i.CLAMP_TO_EDGE)),this.tiles){var r=this.tiles[o];\"loaded\"!==r.state&&(r.state=\"loaded\",r.texture=this.texture);}}},i.prototype.loadTile=function(t,e){this.tileID&&this.tileID.equals(t.tileID.canonical)?(this.tiles[String(t.tileID.wrap)]=t,t.buckets={},e(null)):(t.state=\"errored\",e(null));},i.prototype.serialize=function(){return {type:\"image\",url:this.options.url,coordinates:this.coordinates}},i.prototype.hasTransition=function(){return !1},i}(t.Evented);var D=function(e){function i(t,i,o,r){e.call(this,t,i,o,r),this.roundZoom=!0,this.type=\"video\",this.options=i;}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.load=function(){var e=this,i=this.options;this.urls=[];for(var o=0,r=i.urls;o<r.length;o+=1){var a=r[o];this.urls.push(this.map._requestManager.transformRequest(a,t.ResourceType.Source).url);}t.getVideo(this.urls,function(i,o){i?e.fire(new t.ErrorEvent(i)):o&&(e.video=o,e.video.loop=!0,e.video.addEventListener(\"playing\",function(){e.map.triggerRepaint();}),e.map&&e.video.play(),e._finishLoading());});},i.prototype.getVideo=function(){return this.video},i.prototype.onAdd=function(t){this.map||(this.map=t,this.load(),this.video&&(this.video.play(),this.setCoordinates(this.coordinates)));},i.prototype.prepare=function(){if(!(0===Object.keys(this.tiles).length||this.video.readyState<2)){var e=this.map.painter.context,i=e.gl;for(var o in this.boundsBuffer||(this.boundsBuffer=e.createVertexBuffer(this._boundsArray,t.rasterBoundsAttributes.members)),this.boundsSegments||(this.boundsSegments=t.SegmentVector.simpleSegment(0,0,4,2)),this.texture?this.video.paused||(this.texture.bind(i.LINEAR,i.CLAMP_TO_EDGE),i.texSubImage2D(i.TEXTURE_2D,0,0,0,i.RGBA,i.UNSIGNED_BYTE,this.video)):(this.texture=new t.Texture(e,this.video,i.RGBA),this.texture.bind(i.LINEAR,i.CLAMP_TO_EDGE)),this.tiles){var r=this.tiles[o];\"loaded\"!==r.state&&(r.state=\"loaded\",r.texture=this.texture);}}},i.prototype.serialize=function(){return {type:\"video\",urls:this.urls,coordinates:this.coordinates}},i.prototype.hasTransition=function(){return this.video&&!this.video.paused},i}(L),M=function(e){function i(i,o,r,a){e.call(this,i,o,r,a),o.coordinates?Array.isArray(o.coordinates)&&4===o.coordinates.length&&!o.coordinates.some(function(t){return !Array.isArray(t)||2!==t.length||t.some(function(t){return \"number\"!=typeof t})})||this.fire(new t.ErrorEvent(new t.ValidationError(\"sources.\"+i,null,'\"coordinates\" property must be an array of 4 longitude/latitude array pairs'))):this.fire(new t.ErrorEvent(new t.ValidationError(\"sources.\"+i,null,'missing required property \"coordinates\"'))),o.animate&&\"boolean\"!=typeof o.animate&&this.fire(new t.ErrorEvent(new t.ValidationError(\"sources.\"+i,null,'optional \"animate\" property must be a boolean value'))),o.canvas?\"string\"==typeof o.canvas||o.canvas instanceof t.window.HTMLCanvasElement||this.fire(new t.ErrorEvent(new t.ValidationError(\"sources.\"+i,null,'\"canvas\" must be either a string representing the ID of the canvas element from which to read, or an HTMLCanvasElement instance'))):this.fire(new t.ErrorEvent(new t.ValidationError(\"sources.\"+i,null,'missing required property \"canvas\"'))),this.options=o,this.animate=void 0===o.animate||o.animate;}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.load=function(){this.canvas||(this.canvas=this.options.canvas instanceof t.window.HTMLCanvasElement?this.options.canvas:t.window.document.getElementById(this.options.canvas)),this.width=this.canvas.width,this.height=this.canvas.height,this._hasInvalidDimensions()?this.fire(new t.ErrorEvent(new Error(\"Canvas dimensions cannot be less than or equal to zero.\"))):(this.play=function(){this._playing=!0,this.map.triggerRepaint();},this.pause=function(){this._playing&&(this.prepare(),this._playing=!1);},this._finishLoading());},i.prototype.getCanvas=function(){return this.canvas},i.prototype.onAdd=function(t){this.map=t,this.load(),this.canvas&&this.animate&&this.play();},i.prototype.onRemove=function(){this.pause();},i.prototype.prepare=function(){var e=!1;if(this.canvas.width!==this.width&&(this.width=this.canvas.width,e=!0),this.canvas.height!==this.height&&(this.height=this.canvas.height,e=!0),!this._hasInvalidDimensions()&&0!==Object.keys(this.tiles).length){var i=this.map.painter.context,o=i.gl;for(var r in this.boundsBuffer||(this.boundsBuffer=i.createVertexBuffer(this._boundsArray,t.rasterBoundsAttributes.members)),this.boundsSegments||(this.boundsSegments=t.SegmentVector.simpleSegment(0,0,4,2)),this.texture?(e||this._playing)&&this.texture.update(this.canvas,{premultiply:!0}):this.texture=new t.Texture(i,this.canvas,o.RGBA,{premultiply:!0}),this.tiles){var a=this.tiles[r];\"loaded\"!==a.state&&(a.state=\"loaded\",a.texture=this.texture);}}},i.prototype.serialize=function(){return {type:\"canvas\",coordinates:this.coordinates}},i.prototype.hasTransition=function(){return this._playing},i.prototype._hasInvalidDimensions=function(){for(var t=0,e=[this.canvas.width,this.canvas.height];t<e.length;t+=1){var i=e[t];if(isNaN(i)||i<=0)return !0}return !1},i}(L),R={vector:C,raster:S,\"raster-dem\":P,geojson:z,video:D,image:L,canvas:M},A=function(e,i,o,r){var a=new R[i.type](e,i,o,r);if(a.id!==e)throw new Error(\"Expected Source id to be \"+e+\" instead of \"+a.id);return t.bindAll([\"load\",\"abort\",\"unload\",\"serialize\",\"prepare\"],a),a};function k(e,i){var o=t.identity([]);return t.translate(o,o,[1,1,0]),t.scale(o,o,[.5*e.width,.5*e.height,1]),t.multiply(o,o,e.calculatePosMatrix(i.toUnwrapped()))}function B(t,e,i,o,r){var a=function(t,e,i){if(t)for(var o=0,r=t;o<r.length;o+=1){var a=e[r[o]];if(a&&a.source===i&&\"fill-extrusion\"===a.type)return !0}else for(var n in e){var s=e[n];if(s.source===i&&\"fill-extrusion\"===s.type)return !0}return !1}(o&&o.layers,e,t.id),n=r.maxPitchScaleFactor(),s=t.tilesIn(i,n,a);s.sort(O);for(var l=[],c=0,u=s;c<u.length;c+=1){var h=u[c];l.push({wrappedTileID:h.tileID.wrapped().key,queryResults:h.tile.queryRenderedFeatures(e,t._state,h.queryGeometry,h.cameraQueryGeometry,h.scale,o,r,n,k(t.transform,h.tileID))});}var p=function(t){for(var e={},i={},o=0,r=t;o<r.length;o+=1){var a=r[o],n=a.queryResults,s=a.wrappedTileID,l=i[s]=i[s]||{};for(var c in n)for(var u=n[c],h=l[c]=l[c]||{},p=e[c]=e[c]||[],d=0,_=u;d<_.length;d+=1){var f=_[d];h[f.featureIndex]||(h[f.featureIndex]=!0,p.push(f));}}return e}(l);for(var d in p)p[d].forEach(function(e){var i=e.feature,o=t.getFeatureState(i.layer[\"source-layer\"],i.id);i.source=i.layer.source,i.layer[\"source-layer\"]&&(i.sourceLayer=i.layer[\"source-layer\"]),i.state=o;});return p}function O(t,e){var i=t.tileID,o=e.tileID;return i.overscaledZ-o.overscaledZ||i.canonical.y-o.canonical.y||i.wrap-o.wrap||i.canonical.x-o.canonical.x}var F=function(t,e){this.max=t,this.onRemove=e,this.reset();};F.prototype.reset=function(){for(var t in this.data)for(var e=0,i=this.data[t];e<i.length;e+=1){var o=i[e];o.timeout&&clearTimeout(o.timeout),this.onRemove(o.value);}return this.data={},this.order=[],this},F.prototype.add=function(t,e,i){var o=this,r=t.wrapped().key;void 0===this.data[r]&&(this.data[r]=[]);var a={value:e,timeout:void 0};if(void 0!==i&&(a.timeout=setTimeout(function(){o.remove(t,a);},i)),this.data[r].push(a),this.order.push(r),this.order.length>this.max){var n=this._getAndRemoveByKey(this.order[0]);n&&this.onRemove(n);}return this},F.prototype.has=function(t){return t.wrapped().key in this.data},F.prototype.getAndRemove=function(t){return this.has(t)?this._getAndRemoveByKey(t.wrapped().key):null},F.prototype._getAndRemoveByKey=function(t){var e=this.data[t].shift();return e.timeout&&clearTimeout(e.timeout),0===this.data[t].length&&delete this.data[t],this.order.splice(this.order.indexOf(t),1),e.value},F.prototype.get=function(t){return this.has(t)?this.data[t.wrapped().key][0].value:null},F.prototype.remove=function(t,e){if(!this.has(t))return this;var i=t.wrapped().key,o=void 0===e?0:this.data[i].indexOf(e),r=this.data[i][o];return this.data[i].splice(o,1),r.timeout&&clearTimeout(r.timeout),0===this.data[i].length&&delete this.data[i],this.onRemove(r.value),this.order.splice(this.order.indexOf(i),1),this},F.prototype.setMaxSize=function(t){for(this.max=t;this.order.length>this.max;){var e=this._getAndRemoveByKey(this.order[0]);e&&this.onRemove(e);}return this};var U=function(t,e,i){this.context=t;var o=t.gl;this.buffer=o.createBuffer(),this.dynamicDraw=Boolean(i),this.context.unbindVAO(),t.bindElementBuffer.set(this.buffer),o.bufferData(o.ELEMENT_ARRAY_BUFFER,e.arrayBuffer,this.dynamicDraw?o.DYNAMIC_DRAW:o.STATIC_DRAW),this.dynamicDraw||delete e.arrayBuffer;};U.prototype.bind=function(){this.context.bindElementBuffer.set(this.buffer);},U.prototype.updateData=function(t){var e=this.context.gl;this.context.unbindVAO(),this.bind(),e.bufferSubData(e.ELEMENT_ARRAY_BUFFER,0,t.arrayBuffer);},U.prototype.destroy=function(){var t=this.context.gl;this.buffer&&(t.deleteBuffer(this.buffer),delete this.buffer);};var N={Int8:\"BYTE\",Uint8:\"UNSIGNED_BYTE\",Int16:\"SHORT\",Uint16:\"UNSIGNED_SHORT\",Int32:\"INT\",Uint32:\"UNSIGNED_INT\",Float32:\"FLOAT\"},Z=function(t,e,i,o){this.length=e.length,this.attributes=i,this.itemSize=e.bytesPerElement,this.dynamicDraw=o,this.context=t;var r=t.gl;this.buffer=r.createBuffer(),t.bindVertexBuffer.set(this.buffer),r.bufferData(r.ARRAY_BUFFER,e.arrayBuffer,this.dynamicDraw?r.DYNAMIC_DRAW:r.STATIC_DRAW),this.dynamicDraw||delete e.arrayBuffer;};Z.prototype.bind=function(){this.context.bindVertexBuffer.set(this.buffer);},Z.prototype.updateData=function(t){var e=this.context.gl;this.bind(),e.bufferSubData(e.ARRAY_BUFFER,0,t.arrayBuffer);},Z.prototype.enableAttributes=function(t,e){for(var i=0;i<this.attributes.length;i++){var o=this.attributes[i],r=e.attributes[o.name];void 0!==r&&t.enableVertexAttribArray(r);}},Z.prototype.setVertexAttribPointers=function(t,e,i){for(var o=0;o<this.attributes.length;o++){var r=this.attributes[o],a=e.attributes[r.name];void 0!==a&&t.vertexAttribPointer(a,r.components,t[N[r.type]],!1,this.itemSize,r.offset+this.itemSize*(i||0));}},Z.prototype.destroy=function(){var t=this.context.gl;this.buffer&&(t.deleteBuffer(this.buffer),delete this.buffer);};var j=function(t){this.gl=t.gl,this.default=this.getDefault(),this.current=this.default,this.dirty=!1;};j.prototype.get=function(){return this.current},j.prototype.set=function(t){},j.prototype.getDefault=function(){return this.default},j.prototype.setDefault=function(){this.set(this.default);};var q=function(e){function i(){e.apply(this,arguments);}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.getDefault=function(){return t.Color.transparent},i.prototype.set=function(t){var e=this.current;(t.r!==e.r||t.g!==e.g||t.b!==e.b||t.a!==e.a||this.dirty)&&(this.gl.clearColor(t.r,t.g,t.b,t.a),this.current=t,this.dirty=!1);},i}(j),V=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return 1},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.clearDepth(t),this.current=t,this.dirty=!1);},e}(j),G=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return 0},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.clearStencil(t),this.current=t,this.dirty=!1);},e}(j),W=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return [!0,!0,!0,!0]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||t[2]!==e[2]||t[3]!==e[3]||this.dirty)&&(this.gl.colorMask(t[0],t[1],t[2],t[3]),this.current=t,this.dirty=!1);},e}(j),X=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return !0},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.depthMask(t),this.current=t,this.dirty=!1);},e}(j),H=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return 255},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.stencilMask(t),this.current=t,this.dirty=!1);},e}(j),K=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return {func:this.gl.ALWAYS,ref:0,mask:255}},e.prototype.set=function(t){var e=this.current;(t.func!==e.func||t.ref!==e.ref||t.mask!==e.mask||this.dirty)&&(this.gl.stencilFunc(t.func,t.ref,t.mask),this.current=t,this.dirty=!1);},e}(j),Y=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){var t=this.gl;return [t.KEEP,t.KEEP,t.KEEP]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||t[2]!==e[2]||this.dirty)&&(this.gl.stencilOp(t[0],t[1],t[2]),this.current=t,this.dirty=!1);},e}(j),J=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return !1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;t?e.enable(e.STENCIL_TEST):e.disable(e.STENCIL_TEST),this.current=t,this.dirty=!1;}},e}(j),Q=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return [0,1]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||this.dirty)&&(this.gl.depthRange(t[0],t[1]),this.current=t,this.dirty=!1);},e}(j),$=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return !1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;t?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST),this.current=t,this.dirty=!1;}},e}(j),tt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.LESS},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.depthFunc(t),this.current=t,this.dirty=!1);},e}(j),et=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return !1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;t?e.enable(e.BLEND):e.disable(e.BLEND),this.current=t,this.dirty=!1;}},e}(j),it=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){var t=this.gl;return [t.ONE,t.ZERO]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||this.dirty)&&(this.gl.blendFunc(t[0],t[1]),this.current=t,this.dirty=!1);},e}(j),ot=function(e){function i(){e.apply(this,arguments);}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.getDefault=function(){return t.Color.transparent},i.prototype.set=function(t){var e=this.current;(t.r!==e.r||t.g!==e.g||t.b!==e.b||t.a!==e.a||this.dirty)&&(this.gl.blendColor(t.r,t.g,t.b,t.a),this.current=t,this.dirty=!1);},i}(j),rt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.FUNC_ADD},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.blendEquation(t),this.current=t,this.dirty=!1);},e}(j),at=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return !1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;t?e.enable(e.CULL_FACE):e.disable(e.CULL_FACE),this.current=t,this.dirty=!1;}},e}(j),nt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.BACK},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.cullFace(t),this.current=t,this.dirty=!1);},e}(j),st=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.CCW},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.frontFace(t),this.current=t,this.dirty=!1);},e}(j),lt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.useProgram(t),this.current=t,this.dirty=!1);},e}(j),ct=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return this.gl.TEXTURE0},e.prototype.set=function(t){(t!==this.current||this.dirty)&&(this.gl.activeTexture(t),this.current=t,this.dirty=!1);},e}(j),ut=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){var t=this.gl;return [0,0,t.drawingBufferWidth,t.drawingBufferHeight]},e.prototype.set=function(t){var e=this.current;(t[0]!==e[0]||t[1]!==e[1]||t[2]!==e[2]||t[3]!==e[3]||this.dirty)&&(this.gl.viewport(t[0],t[1],t[2],t[3]),this.current=t,this.dirty=!1);},e}(j),ht=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,t),this.current=t,this.dirty=!1;}},e}(j),pt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.bindRenderbuffer(e.RENDERBUFFER,t),this.current=t,this.dirty=!1;}},e}(j),dt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.bindTexture(e.TEXTURE_2D,t),this.current=t,this.dirty=!1;}},e}(j),_t=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.bindBuffer(e.ARRAY_BUFFER,t),this.current=t,this.dirty=!1;}},e}(j),ft=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){var e=this.gl;e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t),this.current=t,this.dirty=!1;},e}(j),mt=function(t){function e(e){t.call(this,e),this.vao=e.extVertexArrayObject;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e.prototype.set=function(t){this.vao&&(t!==this.current||this.dirty)&&(this.vao.bindVertexArrayOES(t),this.current=t,this.dirty=!1);},e}(j),gt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return 4},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.pixelStorei(e.UNPACK_ALIGNMENT,t),this.current=t,this.dirty=!1;}},e}(j),vt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return !1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t),this.current=t,this.dirty=!1;}},e}(j),yt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return !1},e.prototype.set=function(t){if(t!==this.current||this.dirty){var e=this.gl;e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,t),this.current=t,this.dirty=!1;}},e}(j),xt=function(t){function e(e,i){t.call(this,e),this.context=e,this.parent=i;}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getDefault=function(){return null},e}(j),bt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setDirty=function(){this.dirty=!0;},e.prototype.set=function(t){if(t!==this.current||this.dirty){this.context.bindFramebuffer.set(this.parent);var e=this.gl;e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0),this.current=t,this.dirty=!1;}},e}(xt),wt=function(t){function e(){t.apply(this,arguments);}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.set=function(t){if(t!==this.current||this.dirty){this.context.bindFramebuffer.set(this.parent);var e=this.gl;e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,t),this.current=t,this.dirty=!1;}},e}(xt),Et=function(t,e,i){this.context=t,this.width=e,this.height=i;var o=t.gl,r=this.framebuffer=o.createFramebuffer();this.colorAttachment=new bt(t,r),this.depthAttachment=new wt(t,r);};Et.prototype.destroy=function(){var t=this.context.gl,e=this.colorAttachment.get();e&&t.deleteTexture(e);var i=this.depthAttachment.get();i&&t.deleteRenderbuffer(i),t.deleteFramebuffer(this.framebuffer);};var Tt=function(t,e,i){this.func=t,this.mask=e,this.range=i;};Tt.ReadOnly=!1,Tt.ReadWrite=!0,Tt.disabled=new Tt(519,Tt.ReadOnly,[0,1]);var It=function(t,e,i,o,r,a){this.test=t,this.ref=e,this.mask=i,this.fail=o,this.depthFail=r,this.pass=a;};It.disabled=new It({func:519,mask:0},0,0,7680,7680,7680);var Ct=function(t,e,i){this.blendFunction=t,this.blendColor=e,this.mask=i;};Ct.Replace=[1,0],Ct.disabled=new Ct(Ct.Replace,t.Color.transparent,[!1,!1,!1,!1]),Ct.unblended=new Ct(Ct.Replace,t.Color.transparent,[!0,!0,!0,!0]),Ct.alphaBlended=new Ct([1,771],t.Color.transparent,[!0,!0,!0,!0]);var St=function(t,e,i){this.enable=t,this.mode=e,this.frontFace=i;};St.disabled=new St(!1,1029,2305),St.backCCW=new St(!0,1029,2305);var Pt=function(t){this.gl=t,this.extVertexArrayObject=this.gl.getExtension(\"OES_vertex_array_object\"),this.clearColor=new q(this),this.clearDepth=new V(this),this.clearStencil=new G(this),this.colorMask=new W(this),this.depthMask=new X(this),this.stencilMask=new H(this),this.stencilFunc=new K(this),this.stencilOp=new Y(this),this.stencilTest=new J(this),this.depthRange=new Q(this),this.depthTest=new $(this),this.depthFunc=new tt(this),this.blend=new et(this),this.blendFunc=new it(this),this.blendColor=new ot(this),this.blendEquation=new rt(this),this.cullFace=new at(this),this.cullFaceSide=new nt(this),this.frontFace=new st(this),this.program=new lt(this),this.activeTexture=new ct(this),this.viewport=new ut(this),this.bindFramebuffer=new ht(this),this.bindRenderbuffer=new pt(this),this.bindTexture=new dt(this),this.bindVertexBuffer=new _t(this),this.bindElementBuffer=new ft(this),this.bindVertexArrayOES=this.extVertexArrayObject&&new mt(this),this.pixelStoreUnpack=new gt(this),this.pixelStoreUnpackPremultiplyAlpha=new vt(this),this.pixelStoreUnpackFlipY=new yt(this),this.extTextureFilterAnisotropic=t.getExtension(\"EXT_texture_filter_anisotropic\")||t.getExtension(\"MOZ_EXT_texture_filter_anisotropic\")||t.getExtension(\"WEBKIT_EXT_texture_filter_anisotropic\"),this.extTextureFilterAnisotropic&&(this.extTextureFilterAnisotropicMax=t.getParameter(this.extTextureFilterAnisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT)),this.extTextureHalfFloat=t.getExtension(\"OES_texture_half_float\"),this.extTextureHalfFloat&&t.getExtension(\"OES_texture_half_float_linear\");};Pt.prototype.setDefault=function(){this.unbindVAO(),this.clearColor.setDefault(),this.clearDepth.setDefault(),this.clearStencil.setDefault(),this.colorMask.setDefault(),this.depthMask.setDefault(),this.stencilMask.setDefault(),this.stencilFunc.setDefault(),this.stencilOp.setDefault(),this.stencilTest.setDefault(),this.depthRange.setDefault(),this.depthTest.setDefault(),this.depthFunc.setDefault(),this.blend.setDefault(),this.blendFunc.setDefault(),this.blendColor.setDefault(),this.blendEquation.setDefault(),this.cullFace.setDefault(),this.cullFaceSide.setDefault(),this.frontFace.setDefault(),this.program.setDefault(),this.activeTexture.setDefault(),this.bindFramebuffer.setDefault(),this.pixelStoreUnpack.setDefault(),this.pixelStoreUnpackPremultiplyAlpha.setDefault(),this.pixelStoreUnpackFlipY.setDefault();},Pt.prototype.setDirty=function(){this.clearColor.dirty=!0,this.clearDepth.dirty=!0,this.clearStencil.dirty=!0,this.colorMask.dirty=!0,this.depthMask.dirty=!0,this.stencilMask.dirty=!0,this.stencilFunc.dirty=!0,this.stencilOp.dirty=!0,this.stencilTest.dirty=!0,this.depthRange.dirty=!0,this.depthTest.dirty=!0,this.depthFunc.dirty=!0,this.blend.dirty=!0,this.blendFunc.dirty=!0,this.blendColor.dirty=!0,this.blendEquation.dirty=!0,this.cullFace.dirty=!0,this.cullFaceSide.dirty=!0,this.frontFace.dirty=!0,this.program.dirty=!0,this.activeTexture.dirty=!0,this.viewport.dirty=!0,this.bindFramebuffer.dirty=!0,this.bindRenderbuffer.dirty=!0,this.bindTexture.dirty=!0,this.bindVertexBuffer.dirty=!0,this.bindElementBuffer.dirty=!0,this.extVertexArrayObject&&(this.bindVertexArrayOES.dirty=!0),this.pixelStoreUnpack.dirty=!0,this.pixelStoreUnpackPremultiplyAlpha.dirty=!0,this.pixelStoreUnpackFlipY.dirty=!0;},Pt.prototype.createIndexBuffer=function(t,e){return new U(this,t,e)},Pt.prototype.createVertexBuffer=function(t,e,i){return new Z(this,t,e,i)},Pt.prototype.createRenderbuffer=function(t,e,i){var o=this.gl,r=o.createRenderbuffer();return this.bindRenderbuffer.set(r),o.renderbufferStorage(o.RENDERBUFFER,t,e,i),this.bindRenderbuffer.set(null),r},Pt.prototype.createFramebuffer=function(t,e){return new Et(this,t,e)},Pt.prototype.clear=function(t){var e=t.color,i=t.depth,o=this.gl,r=0;e&&(r|=o.COLOR_BUFFER_BIT,this.clearColor.set(e),this.colorMask.set([!0,!0,!0,!0])),void 0!==i&&(r|=o.DEPTH_BUFFER_BIT,this.depthRange.set([0,1]),this.clearDepth.set(i),this.depthMask.set(!0)),o.clear(r);},Pt.prototype.setCullFace=function(t){!1===t.enable?this.cullFace.set(!1):(this.cullFace.set(!0),this.cullFaceSide.set(t.mode),this.frontFace.set(t.frontFace));},Pt.prototype.setDepthMode=function(t){t.func!==this.gl.ALWAYS||t.mask?(this.depthTest.set(!0),this.depthFunc.set(t.func),this.depthMask.set(t.mask),this.depthRange.set(t.range)):this.depthTest.set(!1);},Pt.prototype.setStencilMode=function(t){t.test.func!==this.gl.ALWAYS||t.mask?(this.stencilTest.set(!0),this.stencilMask.set(t.mask),this.stencilOp.set([t.fail,t.depthFail,t.pass]),this.stencilFunc.set({func:t.test.func,ref:t.ref,mask:t.test.mask})):this.stencilTest.set(!1);},Pt.prototype.setColorMode=function(e){t.deepEqual(e.blendFunction,Ct.Replace)?this.blend.set(!1):(this.blend.set(!0),this.blendFunc.set(e.blendFunction),this.blendColor.set(e.blendColor)),this.colorMask.set(e.mask);},Pt.prototype.unbindVAO=function(){this.extVertexArrayObject&&this.bindVertexArrayOES.set(null);};var zt=function(e){function i(i,o,r){var a=this;e.call(this),this.id=i,this.dispatcher=r,this.on(\"data\",function(t){\"source\"===t.dataType&&\"metadata\"===t.sourceDataType&&(a._sourceLoaded=!0),a._sourceLoaded&&!a._paused&&\"source\"===t.dataType&&\"content\"===t.sourceDataType&&(a.reload(),a.transform&&a.update(a.transform));}),this.on(\"error\",function(){a._sourceErrored=!0;}),this._source=A(i,o,r,this),this._tiles={},this._cache=new F(0,this._unloadTile.bind(this)),this._timers={},this._cacheTimers={},this._maxTileCacheSize=null,this._coveredTiles={},this._state=new t.SourceFeatureState;}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.onAdd=function(t){this.map=t,this._maxTileCacheSize=t?t._maxTileCacheSize:null,this._source&&this._source.onAdd&&this._source.onAdd(t);},i.prototype.onRemove=function(t){this._source&&this._source.onRemove&&this._source.onRemove(t);},i.prototype.loaded=function(){if(this._sourceErrored)return !0;if(!this._sourceLoaded)return !1;for(var t in this._tiles){var e=this._tiles[t];if(\"loaded\"!==e.state&&\"errored\"!==e.state)return !1}return !0},i.prototype.getSource=function(){return this._source},i.prototype.pause=function(){this._paused=!0;},i.prototype.resume=function(){if(this._paused){var t=this._shouldReloadOnResume;this._paused=!1,this._shouldReloadOnResume=!1,t&&this.reload(),this.transform&&this.update(this.transform);}},i.prototype._loadTile=function(t,e){return this._source.loadTile(t,e)},i.prototype._unloadTile=function(t){if(this._source.unloadTile)return this._source.unloadTile(t,function(){})},i.prototype._abortTile=function(t){if(this._source.abortTile)return this._source.abortTile(t,function(){})},i.prototype.serialize=function(){return this._source.serialize()},i.prototype.prepare=function(t){for(var e in this._source.prepare&&this._source.prepare(),this._state.coalesceChanges(this._tiles,this.map?this.map.painter:null),this._tiles){var i=this._tiles[e];i.upload(t),i.prepare(this.map.style.imageManager);}},i.prototype.getIds=function(){return Object.keys(this._tiles).map(Number).sort(Lt)},i.prototype.getRenderableIds=function(e){var i=this,o=[];for(var r in this._tiles)this._isIdRenderable(+r,e)&&o.push(+r);return e?o.sort(function(e,o){var r=i._tiles[e].tileID,a=i._tiles[o].tileID,n=new t.Point(r.canonical.x,r.canonical.y)._rotate(i.transform.angle),s=new t.Point(a.canonical.x,a.canonical.y)._rotate(i.transform.angle);return r.overscaledZ-a.overscaledZ||s.y-n.y||s.x-n.x}):o.sort(Lt)},i.prototype.hasRenderableParent=function(t){var e=this.findLoadedParent(t,0);return !!e&&this._isIdRenderable(e.tileID.key)},i.prototype._isIdRenderable=function(t,e){return this._tiles[t]&&this._tiles[t].hasData()&&!this._coveredTiles[t]&&(e||!this._tiles[t].holdingForFade())},i.prototype.reload=function(){if(this._paused)this._shouldReloadOnResume=!0;else for(var t in this._cache.reset(),this._tiles)\"errored\"!==this._tiles[t].state&&this._reloadTile(t,\"reloading\");},i.prototype._reloadTile=function(t,e){var i=this._tiles[t];i&&(\"loading\"!==i.state&&(i.state=e),this._loadTile(i,this._tileLoaded.bind(this,i,t,e)));},i.prototype._tileLoaded=function(e,i,o,r){if(r)return e.state=\"errored\",void(404!==r.status?this._source.fire(new t.ErrorEvent(r,{tile:e})):this.update(this.transform));e.timeAdded=t.browser.now(),\"expired\"===o&&(e.refreshedUponExpiration=!0),this._setTileReloadTimer(i,e),\"raster-dem\"===this.getSource().type&&e.dem&&this._backfillDEM(e),this._state.initializeTileState(e,this.map?this.map.painter:null),this._source.fire(new t.Event(\"data\",{dataType:\"source\",tile:e,coord:e.tileID}));},i.prototype._backfillDEM=function(t){for(var e=this.getRenderableIds(),i=0;i<e.length;i++){var o=e[i];if(t.neighboringTiles&&t.neighboringTiles[o]){var r=this.getTileByID(o);a(t,r),a(r,t);}}function a(t,e){t.needsHillshadePrepare=!0;var i=e.tileID.canonical.x-t.tileID.canonical.x,o=e.tileID.canonical.y-t.tileID.canonical.y,r=Math.pow(2,t.tileID.canonical.z),a=e.tileID.key;0===i&&0===o||Math.abs(o)>1||(Math.abs(i)>1&&(1===Math.abs(i+r)?i+=r:1===Math.abs(i-r)&&(i-=r)),e.dem&&t.dem&&(t.dem.backfillBorder(e.dem,i,o),t.neighboringTiles&&t.neighboringTiles[a]&&(t.neighboringTiles[a].backfilled=!0)));}},i.prototype.getTile=function(t){return this.getTileByID(t.key)},i.prototype.getTileByID=function(t){return this._tiles[t]},i.prototype.getZoom=function(t){return t.zoom+t.scaleZoom(t.tileSize/this._source.tileSize)},i.prototype._retainLoadedChildren=function(t,e,i,o){for(var r in this._tiles){var a=this._tiles[r];if(!(o[r]||!a.hasData()||a.tileID.overscaledZ<=e||a.tileID.overscaledZ>i)){for(var n=a.tileID;a&&a.tileID.overscaledZ>e+1;){var s=a.tileID.scaledTo(a.tileID.overscaledZ-1);(a=this._tiles[s.key])&&a.hasData()&&(n=s);}for(var l=n;l.overscaledZ>e;)if(t[(l=l.scaledTo(l.overscaledZ-1)).key]){o[n.key]=n;break}}}},i.prototype.findLoadedParent=function(t,e){for(var i=t.overscaledZ-1;i>=e;i--){var o=t.scaledTo(i);if(!o)return;var r=String(o.key),a=this._tiles[r];if(a&&a.hasData())return a;if(this._cache.has(o))return this._cache.get(o)}},i.prototype.updateCacheSize=function(t){var e=(Math.ceil(t.width/this._source.tileSize)+1)*(Math.ceil(t.height/this._source.tileSize)+1),i=Math.floor(5*e),o=\"number\"==typeof this._maxTileCacheSize?Math.min(this._maxTileCacheSize,i):i;this._cache.setMaxSize(o);},i.prototype.handleWrapJump=function(t){var e=(t-(void 0===this._prevLng?t:this._prevLng))/360,i=Math.round(e);if(this._prevLng=t,i){var o={};for(var r in this._tiles){var a=this._tiles[r];a.tileID=a.tileID.unwrapTo(a.tileID.wrap+i),o[a.tileID.key]=a;}for(var n in this._tiles=o,this._timers)clearTimeout(this._timers[n]),delete this._timers[n];for(var s in this._tiles){var l=this._tiles[s];this._setTileReloadTimer(s,l);}}},i.prototype.update=function(e){var o=this;if(this.transform=e,this._sourceLoaded&&!this._paused){var r;this.updateCacheSize(e),this.handleWrapJump(this.transform.center.lng),this._coveredTiles={},this.used?this._source.tileID?r=e.getVisibleUnwrappedCoordinates(this._source.tileID).map(function(e){return new t.OverscaledTileID(e.canonical.z,e.wrap,e.canonical.z,e.canonical.x,e.canonical.y)}):(r=e.coveringTiles({tileSize:this._source.tileSize,minzoom:this._source.minzoom,maxzoom:this._source.maxzoom,roundZoom:this._source.roundZoom,reparseOverscaled:this._source.reparseOverscaled}),this._source.hasTile&&(r=r.filter(function(t){return o._source.hasTile(t)}))):r=[];var a=(this._source.roundZoom?Math.round:Math.floor)(this.getZoom(e)),n=Math.max(a-i.maxOverzooming,this._source.minzoom),s=Math.max(a+i.maxUnderzooming,this._source.minzoom),l=this._updateRetainedTiles(r,a);if(Dt(this._source.type)){for(var c={},u={},h=0,p=Object.keys(l);h<p.length;h+=1){var d=p[h],_=l[d],f=this._tiles[d];if(f&&!(f.fadeEndTime&&f.fadeEndTime<=t.browser.now())){var m=this.findLoadedParent(_,n);m&&(this._addTile(m.tileID),c[m.tileID.key]=m.tileID),u[d]=_;}}for(var g in this._retainLoadedChildren(u,a,s,l),c)l[g]||(this._coveredTiles[g]=!0,l[g]=c[g]);}for(var v in l)this._tiles[v].clearFadeHold();for(var y=0,x=t.keysDifference(this._tiles,l);y<x.length;y+=1){var b=x[y],w=this._tiles[b];w.hasSymbolBuckets&&!w.holdingForFade()?w.setHoldDuration(this.map._fadeDuration):w.hasSymbolBuckets&&!w.symbolFadeFinished()||this._removeTile(b);}}},i.prototype.releaseSymbolFadeTiles=function(){for(var t in this._tiles)this._tiles[t].holdingForFade()&&this._removeTile(t);},i.prototype._updateRetainedTiles=function(t,e){for(var o={},r={},a=Math.max(e-i.maxOverzooming,this._source.minzoom),n=Math.max(e+i.maxUnderzooming,this._source.minzoom),s={},l=0,c=t;l<c.length;l+=1){var u=c[l],h=this._addTile(u);o[u.key]=u,h.hasData()||e<this._source.maxzoom&&(s[u.key]=u);}this._retainLoadedChildren(s,e,n,o);for(var p=0,d=t;p<d.length;p+=1){var _=d[p],f=this._tiles[_.key];if(!f.hasData()){if(e+1>this._source.maxzoom){var m=_.children(this._source.maxzoom)[0],g=this.getTile(m);if(g&&g.hasData()){o[m.key]=m;continue}}else{var v=_.children(this._source.maxzoom);if(o[v[0].key]&&o[v[1].key]&&o[v[2].key]&&o[v[3].key])continue}for(var y=f.wasRequested(),x=_.overscaledZ-1;x>=a;--x){var b=_.scaledTo(x);if(r[b.key])break;if(r[b.key]=!0,!(f=this.getTile(b))&&y&&(f=this._addTile(b)),f&&(o[b.key]=b,y=f.wasRequested(),f.hasData()))break}}}return o},i.prototype._addTile=function(e){var i=this._tiles[e.key];if(i)return i;(i=this._cache.getAndRemove(e))&&(this._setTileReloadTimer(e.key,i),i.tileID=e,this._state.initializeTileState(i,this.map?this.map.painter:null),this._cacheTimers[e.key]&&(clearTimeout(this._cacheTimers[e.key]),delete this._cacheTimers[e.key],this._setTileReloadTimer(e.key,i)));var o=Boolean(i);return o||(i=new t.Tile(e,this._source.tileSize*e.overscaleFactor()),this._loadTile(i,this._tileLoaded.bind(this,i,e.key,i.state))),i?(i.uses++,this._tiles[e.key]=i,o||this._source.fire(new t.Event(\"dataloading\",{tile:i,coord:i.tileID,dataType:\"source\"})),i):null},i.prototype._setTileReloadTimer=function(t,e){var i=this;t in this._timers&&(clearTimeout(this._timers[t]),delete this._timers[t]);var o=e.getExpiryTimeout();o&&(this._timers[t]=setTimeout(function(){i._reloadTile(t,\"expired\"),delete i._timers[t];},o));},i.prototype._removeTile=function(t){var e=this._tiles[t];e&&(e.uses--,delete this._tiles[t],this._timers[t]&&(clearTimeout(this._timers[t]),delete this._timers[t]),e.uses>0||(e.hasData()?this._cache.add(e.tileID,e,e.getExpiryTimeout()):(e.aborted=!0,this._abortTile(e),this._unloadTile(e))));},i.prototype.clearTiles=function(){for(var t in this._shouldReloadOnResume=!1,this._paused=!1,this._tiles)this._removeTile(t);this._cache.reset();},i.prototype.tilesIn=function(e,i,o){var r=this,a=[],n=this.transform;if(!n)return a;for(var s=o?n.getCameraQueryGeometry(e):e,l=e.map(function(t){return n.pointCoordinate(t)}),c=s.map(function(t){return n.pointCoordinate(t)}),u=this.getIds(),h=1/0,p=1/0,d=-1/0,_=-1/0,f=0,m=c;f<m.length;f+=1){var g=m[f];h=Math.min(h,g.x),p=Math.min(p,g.y),d=Math.max(d,g.x),_=Math.max(_,g.y);}for(var v=function(e){var o=r._tiles[u[e]];if(!o.holdingForFade()){var s=o.tileID,f=Math.pow(2,n.zoom-o.tileID.overscaledZ),m=i*o.queryPadding*t.EXTENT/o.tileSize/f,g=[s.getTilePoint(new t.MercatorCoordinate(h,p)),s.getTilePoint(new t.MercatorCoordinate(d,_))];if(g[0].x-m<t.EXTENT&&g[0].y-m<t.EXTENT&&g[1].x+m>=0&&g[1].y+m>=0){var v=l.map(function(t){return s.getTilePoint(t)}),y=c.map(function(t){return s.getTilePoint(t)});a.push({tile:o,tileID:s,queryGeometry:v,cameraQueryGeometry:y,scale:f});}}},y=0;y<u.length;y++)v(y);return a},i.prototype.getVisibleCoordinates=function(t){for(var e=this,i=this.getRenderableIds(t).map(function(t){return e._tiles[t].tileID}),o=0,r=i;o<r.length;o+=1){var a=r[o];a.posMatrix=this.transform.calculatePosMatrix(a.toUnwrapped());}return i},i.prototype.hasTransition=function(){if(this._source.hasTransition())return !0;if(Dt(this._source.type))for(var e in this._tiles){var i=this._tiles[e];if(void 0!==i.fadeEndTime&&i.fadeEndTime>=t.browser.now())return !0}return !1},i.prototype.setFeatureState=function(t,e,i){t=t||\"_geojsonTileLayer\",this._state.updateState(t,e,i);},i.prototype.removeFeatureState=function(t,e,i){t=t||\"_geojsonTileLayer\",this._state.removeFeatureState(t,e,i);},i.prototype.getFeatureState=function(t,e){return t=t||\"_geojsonTileLayer\",this._state.getState(t,e)},i}(t.Evented);function Lt(t,e){return t%32-e%32||e-t}function Dt(t){return \"raster\"===t||\"image\"===t||\"video\"===t}function Mt(){return new t.window.Worker($o.workerUrl)}zt.maxOverzooming=10,zt.maxUnderzooming=3;var Rt=function(){this.active={};};Rt.prototype.acquire=function(t){if(!this.workers)for(this.workers=[];this.workers.length<Rt.workerCount;)this.workers.push(new Mt);return this.active[t]=!0,this.workers.slice()},Rt.prototype.release=function(t){delete this.active[t],0===Object.keys(this.active).length&&(this.workers.forEach(function(t){t.terminate();}),this.workers=null);};var At,kt=Math.floor(t.browser.hardwareConcurrency/2);function Bt(e,i){var o={};for(var r in e)\"ref\"!==r&&(o[r]=e[r]);return t.refProperties.forEach(function(t){t in i&&(o[t]=i[t]);}),o}function Ot(t){t=t.slice();for(var e=Object.create(null),i=0;i<t.length;i++)e[t[i].id]=t[i];for(var o=0;o<t.length;o++)\"ref\"in t[o]&&(t[o]=Bt(t[o],e[t[o].ref]));return t}Rt.workerCount=Math.max(Math.min(kt,6),1);var Ft={setStyle:\"setStyle\",addLayer:\"addLayer\",removeLayer:\"removeLayer\",setPaintProperty:\"setPaintProperty\",setLayoutProperty:\"setLayoutProperty\",setFilter:\"setFilter\",addSource:\"addSource\",removeSource:\"removeSource\",setGeoJSONSourceData:\"setGeoJSONSourceData\",setLayerZoomRange:\"setLayerZoomRange\",setLayerProperty:\"setLayerProperty\",setCenter:\"setCenter\",setZoom:\"setZoom\",setBearing:\"setBearing\",setPitch:\"setPitch\",setSprite:\"setSprite\",setGlyphs:\"setGlyphs\",setTransition:\"setTransition\",setLight:\"setLight\"};function Ut(t,e,i){i.push({command:Ft.addSource,args:[t,e[t]]});}function Nt(t,e,i){e.push({command:Ft.removeSource,args:[t]}),i[t]=!0;}function Zt(t,e,i,o){Nt(t,i,o),Ut(t,e,i);}function jt(e,i,o){var r;for(r in e[o])if(e[o].hasOwnProperty(r)&&\"data\"!==r&&!t.deepEqual(e[o][r],i[o][r]))return !1;for(r in i[o])if(i[o].hasOwnProperty(r)&&\"data\"!==r&&!t.deepEqual(e[o][r],i[o][r]))return !1;return !0}function qt(e,i,o,r,a,n){var s;for(s in i=i||{},e=e||{})e.hasOwnProperty(s)&&(t.deepEqual(e[s],i[s])||o.push({command:n,args:[r,s,i[s],a]}));for(s in i)i.hasOwnProperty(s)&&!e.hasOwnProperty(s)&&(t.deepEqual(e[s],i[s])||o.push({command:n,args:[r,s,i[s],a]}));}function Vt(t){return t.id}function Gt(t,e){return t[e.id]=e,t}function Wt(e,i){if(!e)return [{command:Ft.setStyle,args:[i]}];var o=[];try{if(!t.deepEqual(e.version,i.version))return [{command:Ft.setStyle,args:[i]}];t.deepEqual(e.center,i.center)||o.push({command:Ft.setCenter,args:[i.center]}),t.deepEqual(e.zoom,i.zoom)||o.push({command:Ft.setZoom,args:[i.zoom]}),t.deepEqual(e.bearing,i.bearing)||o.push({command:Ft.setBearing,args:[i.bearing]}),t.deepEqual(e.pitch,i.pitch)||o.push({command:Ft.setPitch,args:[i.pitch]}),t.deepEqual(e.sprite,i.sprite)||o.push({command:Ft.setSprite,args:[i.sprite]}),t.deepEqual(e.glyphs,i.glyphs)||o.push({command:Ft.setGlyphs,args:[i.glyphs]}),t.deepEqual(e.transition,i.transition)||o.push({command:Ft.setTransition,args:[i.transition]}),t.deepEqual(e.light,i.light)||o.push({command:Ft.setLight,args:[i.light]});var r={},a=[];!function(e,i,o,r){var a;for(a in i=i||{},e=e||{})e.hasOwnProperty(a)&&(i.hasOwnProperty(a)||Nt(a,o,r));for(a in i)i.hasOwnProperty(a)&&(e.hasOwnProperty(a)?t.deepEqual(e[a],i[a])||(\"geojson\"===e[a].type&&\"geojson\"===i[a].type&&jt(e,i,a)?o.push({command:Ft.setGeoJSONSourceData,args:[a,i[a].data]}):Zt(a,i,o,r)):Ut(a,i,o));}(e.sources,i.sources,a,r);var n=[];e.layers&&e.layers.forEach(function(t){r[t.source]?o.push({command:Ft.removeLayer,args:[t.id]}):n.push(t);}),o=o.concat(a),function(e,i,o){i=i||[];var r,a,n,s,l,c,u,h=(e=e||[]).map(Vt),p=i.map(Vt),d=e.reduce(Gt,{}),_=i.reduce(Gt,{}),f=h.slice(),m=Object.create(null);for(r=0,a=0;r<h.length;r++)n=h[r],_.hasOwnProperty(n)?a++:(o.push({command:Ft.removeLayer,args:[n]}),f.splice(f.indexOf(n,a),1));for(r=0,a=0;r<p.length;r++)n=p[p.length-1-r],f[f.length-1-r]!==n&&(d.hasOwnProperty(n)?(o.push({command:Ft.removeLayer,args:[n]}),f.splice(f.lastIndexOf(n,f.length-a),1)):a++,c=f[f.length-r],o.push({command:Ft.addLayer,args:[_[n],c]}),f.splice(f.length-r,0,n),m[n]=!0);for(r=0;r<p.length;r++)if(s=d[n=p[r]],l=_[n],!m[n]&&!t.deepEqual(s,l))if(t.deepEqual(s.source,l.source)&&t.deepEqual(s[\"source-layer\"],l[\"source-layer\"])&&t.deepEqual(s.type,l.type)){for(u in qt(s.layout,l.layout,o,n,null,Ft.setLayoutProperty),qt(s.paint,l.paint,o,n,null,Ft.setPaintProperty),t.deepEqual(s.filter,l.filter)||o.push({command:Ft.setFilter,args:[n,l.filter]}),t.deepEqual(s.minzoom,l.minzoom)&&t.deepEqual(s.maxzoom,l.maxzoom)||o.push({command:Ft.setLayerZoomRange,args:[n,l.minzoom,l.maxzoom]}),s)s.hasOwnProperty(u)&&\"layout\"!==u&&\"paint\"!==u&&\"filter\"!==u&&\"metadata\"!==u&&\"minzoom\"!==u&&\"maxzoom\"!==u&&(0===u.indexOf(\"paint.\")?qt(s[u],l[u],o,n,u.slice(6),Ft.setPaintProperty):t.deepEqual(s[u],l[u])||o.push({command:Ft.setLayerProperty,args:[n,u,l[u]]}));for(u in l)l.hasOwnProperty(u)&&!s.hasOwnProperty(u)&&\"layout\"!==u&&\"paint\"!==u&&\"filter\"!==u&&\"metadata\"!==u&&\"minzoom\"!==u&&\"maxzoom\"!==u&&(0===u.indexOf(\"paint.\")?qt(s[u],l[u],o,n,u.slice(6),Ft.setPaintProperty):t.deepEqual(s[u],l[u])||o.push({command:Ft.setLayerProperty,args:[n,u,l[u]]}));}else o.push({command:Ft.removeLayer,args:[n]}),c=f[f.lastIndexOf(n)+1],o.push({command:Ft.addLayer,args:[l,c]});}(n,i.layers,o);}catch(t){console.warn(\"Unable to compute style diff:\",t),o=[{command:Ft.setStyle,args:[i]}];}return o}var Xt=function(t,e,i){var o=this.boxCells=[],r=this.circleCells=[];this.xCellCount=Math.ceil(t/i),this.yCellCount=Math.ceil(e/i);for(var a=0;a<this.xCellCount*this.yCellCount;a++)o.push([]),r.push([]);this.circleKeys=[],this.boxKeys=[],this.bboxes=[],this.circles=[],this.width=t,this.height=e,this.xScale=this.xCellCount/t,this.yScale=this.yCellCount/e,this.boxUid=0,this.circleUid=0;};function Ht(e,i,o,r,a){var n=t.create();return i?(t.scale(n,n,[1/a,1/a,1]),o||t.rotateZ(n,n,r.angle)):t.multiply(n,r.labelPlaneMatrix,e),n}function Kt(e,i,o,r,a){if(i){var n=t.clone(e);return t.scale(n,n,[a,a,1]),o||t.rotateZ(n,n,-r.angle),n}return r.glCoordMatrix}function Yt(e,i){var o=[e.x,e.y,0,1];ne(o,o,i);var r=o[3];return {point:new t.Point(o[0]/r,o[1]/r),signedDistanceFromCamera:r}}function Jt(t,e){var i=t[0]/t[3],o=t[1]/t[3];return i>=-e[0]&&i<=e[0]&&o>=-e[1]&&o<=e[1]}function Qt(e,i,o,r,a,n,s,l){var c=r?e.textSizeData:e.iconSizeData,u=t.evaluateSizeForZoom(c,o.transform.zoom),h=[256/o.width*2+1,256/o.height*2+1],p=r?e.text.dynamicLayoutVertexArray:e.icon.dynamicLayoutVertexArray;p.clear();for(var d=e.lineVertexArray,_=r?e.text.placedSymbolArray:e.icon.placedSymbolArray,f=o.transform.width/o.transform.height,m=!1,g=0;g<_.length;g++){var v=_.get(g);if(v.hidden||v.writingMode===t.WritingMode.vertical&&!m)ae(v.numGlyphs,p);else{m=!1;var y=[v.anchorX,v.anchorY,0,1];if(t.transformMat4(y,y,i),Jt(y,h)){var x=.5+y[3]/o.transform.cameraToCenterDistance*.5,b=t.evaluateSizeForFeature(c,u,v),w=s?b*x:b/x,E=new t.Point(v.anchorX,v.anchorY),T=Yt(E,a).point,I={},C=ee(v,w,!1,l,i,a,n,e.glyphOffsetArray,d,p,T,E,I,f);m=C.useVertical,(C.notEnoughRoom||m||C.needsFlipping&&ee(v,w,!0,l,i,a,n,e.glyphOffsetArray,d,p,T,E,I,f).notEnoughRoom)&&ae(v.numGlyphs,p);}else ae(v.numGlyphs,p);}}r?e.text.dynamicLayoutVertexBuffer.updateData(p):e.icon.dynamicLayoutVertexBuffer.updateData(p);}function $t(t,e,i,o,r,a,n,s,l,c,u,h){var p=s.glyphStartIndex+s.numGlyphs,d=s.lineStartIndex,_=s.lineStartIndex+s.lineLength,f=e.getoffsetX(s.glyphStartIndex),m=e.getoffsetX(p-1),g=oe(t*f,i,o,r,a,n,s.segment,d,_,l,c,u,h);if(!g)return null;var v=oe(t*m,i,o,r,a,n,s.segment,d,_,l,c,u,h);return v?{first:g,last:v}:null}function te(e,i,o,r){if(e===t.WritingMode.horizontal&&Math.abs(o.y-i.y)>Math.abs(o.x-i.x)*r)return {useVertical:!0};return (e===t.WritingMode.vertical?i.y<o.y:i.x>o.x)?{needsFlipping:!0}:null}function ee(e,i,o,r,a,n,s,l,c,u,h,p,d,_){var f,m=i/24,g=e.lineOffsetX*m,v=e.lineOffsetY*m;if(e.numGlyphs>1){var y=e.glyphStartIndex+e.numGlyphs,x=e.lineStartIndex,b=e.lineStartIndex+e.lineLength,w=$t(m,l,g,v,o,h,p,e,c,n,d,!1);if(!w)return {notEnoughRoom:!0};var E=Yt(w.first.point,s).point,T=Yt(w.last.point,s).point;if(r&&!o){var I=te(e.writingMode,E,T,_);if(I)return I}f=[w.first];for(var C=e.glyphStartIndex+1;C<y-1;C++)f.push(oe(m*l.getoffsetX(C),g,v,o,h,p,e.segment,x,b,c,n,d,!1));f.push(w.last);}else{if(r&&!o){var S=Yt(p,a).point,P=e.lineStartIndex+e.segment+1,z=new t.Point(c.getx(P),c.gety(P)),L=Yt(z,a),D=L.signedDistanceFromCamera>0?L.point:ie(p,z,S,1,a),M=te(e.writingMode,S,D,_);if(M)return M}var R=oe(m*l.getoffsetX(e.glyphStartIndex),g,v,o,h,p,e.segment,e.lineStartIndex,e.lineStartIndex+e.lineLength,c,n,d,!1);if(!R)return {notEnoughRoom:!0};f=[R];}for(var A=0,k=f;A<k.length;A+=1){var B=k[A];t.addDynamicAttributes(u,B.point,B.angle);}return {}}function ie(t,e,i,o,r){var a=Yt(t.add(t.sub(e)._unit()),r).point,n=i.sub(a);return i.add(n._mult(o/n.mag()))}function oe(e,i,o,r,a,n,s,l,c,u,h,p,d){var _=r?e-i:e+i,f=_>0?1:-1,m=0;r&&(f*=-1,m=Math.PI),f<0&&(m+=Math.PI);for(var g=f>0?l+s:l+s+1,v=g,y=a,x=a,b=0,w=0,E=Math.abs(_);b+w<=E;){if((g+=f)<l||g>=c)return null;if(x=y,void 0===(y=p[g])){var T=new t.Point(u.getx(g),u.gety(g)),I=Yt(T,h);if(I.signedDistanceFromCamera>0)y=p[g]=I.point;else{var C=g-f;y=ie(0===b?n:new t.Point(u.getx(C),u.gety(C)),T,x,E-b+1,h);}}b+=w,w=x.dist(y);}var S=(E-b)/w,P=y.sub(x),z=P.mult(S)._add(x);return z._add(P._unit()._perp()._mult(o*f)),{point:z,angle:m+Math.atan2(y.y-x.y,y.x-x.x),tileDistance:d?{prevTileDistance:g-f===v?0:u.gettileUnitDistanceFromAnchor(g-f),lastSegmentViewportDistance:E-b}:null}}Xt.prototype.keysLength=function(){return this.boxKeys.length+this.circleKeys.length},Xt.prototype.insert=function(t,e,i,o,r){this._forEachCell(e,i,o,r,this._insertBoxCell,this.boxUid++),this.boxKeys.push(t),this.bboxes.push(e),this.bboxes.push(i),this.bboxes.push(o),this.bboxes.push(r);},Xt.prototype.insertCircle=function(t,e,i,o){this._forEachCell(e-o,i-o,e+o,i+o,this._insertCircleCell,this.circleUid++),this.circleKeys.push(t),this.circles.push(e),this.circles.push(i),this.circles.push(o);},Xt.prototype._insertBoxCell=function(t,e,i,o,r,a){this.boxCells[r].push(a);},Xt.prototype._insertCircleCell=function(t,e,i,o,r,a){this.circleCells[r].push(a);},Xt.prototype._query=function(t,e,i,o,r,a){if(i<0||t>this.width||o<0||e>this.height)return !r&&[];var n=[];if(t<=0&&e<=0&&this.width<=i&&this.height<=o){if(r)return !0;for(var s=0;s<this.boxKeys.length;s++)n.push({key:this.boxKeys[s],x1:this.bboxes[4*s],y1:this.bboxes[4*s+1],x2:this.bboxes[4*s+2],y2:this.bboxes[4*s+3]});for(var l=0;l<this.circleKeys.length;l++){var c=this.circles[3*l],u=this.circles[3*l+1],h=this.circles[3*l+2];n.push({key:this.circleKeys[l],x1:c-h,y1:u-h,x2:c+h,y2:u+h});}return a?n.filter(a):n}var p={hitTest:r,seenUids:{box:{},circle:{}}};return this._forEachCell(t,e,i,o,this._queryCell,n,p,a),r?n.length>0:n},Xt.prototype._queryCircle=function(t,e,i,o,r){var a=t-i,n=t+i,s=e-i,l=e+i;if(n<0||a>this.width||l<0||s>this.height)return !o&&[];var c=[],u={hitTest:o,circle:{x:t,y:e,radius:i},seenUids:{box:{},circle:{}}};return this._forEachCell(a,s,n,l,this._queryCellCircle,c,u,r),o?c.length>0:c},Xt.prototype.query=function(t,e,i,o,r){return this._query(t,e,i,o,!1,r)},Xt.prototype.hitTest=function(t,e,i,o,r){return this._query(t,e,i,o,!0,r)},Xt.prototype.hitTestCircle=function(t,e,i,o){return this._queryCircle(t,e,i,!0,o)},Xt.prototype._queryCell=function(t,e,i,o,r,a,n,s){var l=n.seenUids,c=this.boxCells[r];if(null!==c)for(var u=this.bboxes,h=0,p=c;h<p.length;h+=1){var d=p[h];if(!l.box[d]){l.box[d]=!0;var _=4*d;if(t<=u[_+2]&&e<=u[_+3]&&i>=u[_+0]&&o>=u[_+1]&&(!s||s(this.boxKeys[d]))){if(n.hitTest)return a.push(!0),!0;a.push({key:this.boxKeys[d],x1:u[_],y1:u[_+1],x2:u[_+2],y2:u[_+3]});}}}var f=this.circleCells[r];if(null!==f)for(var m=this.circles,g=0,v=f;g<v.length;g+=1){var y=v[g];if(!l.circle[y]){l.circle[y]=!0;var x=3*y;if(this._circleAndRectCollide(m[x],m[x+1],m[x+2],t,e,i,o)&&(!s||s(this.circleKeys[y]))){if(n.hitTest)return a.push(!0),!0;var b=m[x],w=m[x+1],E=m[x+2];a.push({key:this.circleKeys[y],x1:b-E,y1:w-E,x2:b+E,y2:w+E});}}}},Xt.prototype._queryCellCircle=function(t,e,i,o,r,a,n,s){var l=n.circle,c=n.seenUids,u=this.boxCells[r];if(null!==u)for(var h=this.bboxes,p=0,d=u;p<d.length;p+=1){var _=d[p];if(!c.box[_]){c.box[_]=!0;var f=4*_;if(this._circleAndRectCollide(l.x,l.y,l.radius,h[f+0],h[f+1],h[f+2],h[f+3])&&(!s||s(this.boxKeys[_])))return a.push(!0),!0}}var m=this.circleCells[r];if(null!==m)for(var g=this.circles,v=0,y=m;v<y.length;v+=1){var x=y[v];if(!c.circle[x]){c.circle[x]=!0;var b=3*x;if(this._circlesCollide(g[b],g[b+1],g[b+2],l.x,l.y,l.radius)&&(!s||s(this.circleKeys[x])))return a.push(!0),!0}}},Xt.prototype._forEachCell=function(t,e,i,o,r,a,n,s){for(var l=this._convertToXCellCoord(t),c=this._convertToYCellCoord(e),u=this._convertToXCellCoord(i),h=this._convertToYCellCoord(o),p=l;p<=u;p++)for(var d=c;d<=h;d++){var _=this.xCellCount*d+p;if(r.call(this,t,e,i,o,_,a,n,s))return}},Xt.prototype._convertToXCellCoord=function(t){return Math.max(0,Math.min(this.xCellCount-1,Math.floor(t*this.xScale)))},Xt.prototype._convertToYCellCoord=function(t){return Math.max(0,Math.min(this.yCellCount-1,Math.floor(t*this.yScale)))},Xt.prototype._circlesCollide=function(t,e,i,o,r,a){var n=o-t,s=r-e,l=i+a;return l*l>n*n+s*s},Xt.prototype._circleAndRectCollide=function(t,e,i,o,r,a,n){var s=(a-o)/2,l=Math.abs(t-(o+s));if(l>s+i)return !1;var c=(n-r)/2,u=Math.abs(e-(r+c));if(u>c+i)return !1;if(l<=s||u<=c)return !0;var h=l-s,p=u-c;return h*h+p*p<=i*i};var re=new Float32Array([-1/0,-1/0,0,-1/0,-1/0,0,-1/0,-1/0,0,-1/0,-1/0,0]);function ae(t,e){for(var i=0;i<t;i++){var o=e.length;e.resize(o+4),e.float32.set(re,3*o);}}function ne(t,e,i){var o=e[0],r=e[1];return t[0]=i[0]*o+i[4]*r+i[12],t[1]=i[1]*o+i[5]*r+i[13],t[3]=i[3]*o+i[7]*r+i[15],t}var se=function(t,e,i){void 0===e&&(e=new Xt(t.width+200,t.height+200,25)),void 0===i&&(i=new Xt(t.width+200,t.height+200,25)),this.transform=t,this.grid=e,this.ignoredGrid=i,this.pitchfactor=Math.cos(t._pitch)*t.cameraToCenterDistance,this.screenRightBoundary=t.width+100,this.screenBottomBoundary=t.height+100,this.gridRightBoundary=t.width+200,this.gridBottomBoundary=t.height+200;};function le(t,e,i){t[e+4]=i?1:0;}function ce(e,i,o){return i*(t.EXTENT/(e.tileSize*Math.pow(2,o-e.tileID.overscaledZ)))}se.prototype.placeCollisionBox=function(t,e,i,o,r){var a=this.projectAndGetPerspectiveRatio(o,t.anchorPointX,t.anchorPointY),n=i*a.perspectiveRatio,s=t.x1*n+a.point.x,l=t.y1*n+a.point.y,c=t.x2*n+a.point.x,u=t.y2*n+a.point.y;return !this.isInsideGrid(s,l,c,u)||!e&&this.grid.hitTest(s,l,c,u,r)?{box:[],offscreen:!1}:{box:[s,l,c,u],offscreen:this.isOffscreen(s,l,c,u)}},se.prototype.approximateTileDistance=function(t,e,i,o,r){var a=r?1:o/this.pitchfactor,n=t.lastSegmentViewportDistance*i;return t.prevTileDistance+n+(a-1)*n*Math.abs(Math.sin(e))},se.prototype.placeCollisionCircles=function(e,i,o,r,a,n,s,l,c,u,h,p,d){var _=[],f=this.projectAnchor(c,a.anchorX,a.anchorY),m=l/24,g=a.lineOffsetX*l,v=a.lineOffsetY*l,y=new t.Point(a.anchorX,a.anchorY),x=$t(m,s,g,v,!1,Yt(y,u).point,y,a,n,u,{},!0),b=!1,w=!1,E=!0,T=f.perspectiveRatio*r,I=1/(r*o),C=0,S=0;x&&(C=this.approximateTileDistance(x.first.tileDistance,x.first.angle,I,f.cameraDistance,p),S=this.approximateTileDistance(x.last.tileDistance,x.last.angle,I,f.cameraDistance,p));for(var P=0;P<e.length;P+=5){var z=e[P],L=e[P+1],D=e[P+2],M=e[P+3];if(!x||M<-C||M>S)le(e,P,!1);else{var R=this.projectPoint(c,z,L),A=D*T;if(_.length>0){var k=R.x-_[_.length-4],B=R.y-_[_.length-3];if(A*A*2>k*k+B*B)if(P+8<e.length){var O=e[P+8];if(O>-C&&O<S){le(e,P,!1);continue}}}var F=P/5;_.push(R.x,R.y,A,F),le(e,P,!0);var U=R.x-A,N=R.y-A,Z=R.x+A,j=R.y+A;if(E=E&&this.isOffscreen(U,N,Z,j),w=w||this.isInsideGrid(U,N,Z,j),!i&&this.grid.hitTestCircle(R.x,R.y,A,d)){if(!h)return {circles:[],offscreen:!1};b=!0;}}}return {circles:b||!w?[]:_,offscreen:E}},se.prototype.queryRenderedSymbols=function(e){if(0===e.length||0===this.grid.keysLength()&&0===this.ignoredGrid.keysLength())return {};for(var i=[],o=1/0,r=1/0,a=-1/0,n=-1/0,s=0,l=e;s<l.length;s+=1){var c=l[s],u=new t.Point(c.x+100,c.y+100);o=Math.min(o,u.x),r=Math.min(r,u.y),a=Math.max(a,u.x),n=Math.max(n,u.y),i.push(u);}for(var h={},p={},d=0,_=this.grid.query(o,r,a,n).concat(this.ignoredGrid.query(o,r,a,n));d<_.length;d+=1){var f=_[d],m=f.key;if(void 0===h[m.bucketInstanceId]&&(h[m.bucketInstanceId]={}),!h[m.bucketInstanceId][m.featureIndex]){var g=[new t.Point(f.x1,f.y1),new t.Point(f.x2,f.y1),new t.Point(f.x2,f.y2),new t.Point(f.x1,f.y2)];t.polygonIntersectsPolygon(i,g)&&(h[m.bucketInstanceId][m.featureIndex]=!0,void 0===p[m.bucketInstanceId]&&(p[m.bucketInstanceId]=[]),p[m.bucketInstanceId].push(m.featureIndex));}}return p},se.prototype.insertCollisionBox=function(t,e,i,o,r){var a={bucketInstanceId:i,featureIndex:o,collisionGroupID:r};(e?this.ignoredGrid:this.grid).insert(a,t[0],t[1],t[2],t[3]);},se.prototype.insertCollisionCircles=function(t,e,i,o,r){for(var a=e?this.ignoredGrid:this.grid,n={bucketInstanceId:i,featureIndex:o,collisionGroupID:r},s=0;s<t.length;s+=4)a.insertCircle(n,t[s],t[s+1],t[s+2]);},se.prototype.projectAnchor=function(t,e,i){var o=[e,i,0,1];return ne(o,o,t),{perspectiveRatio:.5+this.transform.cameraToCenterDistance/o[3]*.5,cameraDistance:o[3]}},se.prototype.projectPoint=function(e,i,o){var r=[i,o,0,1];return ne(r,r,e),new t.Point((r[0]/r[3]+1)/2*this.transform.width+100,(-r[1]/r[3]+1)/2*this.transform.height+100)},se.prototype.projectAndGetPerspectiveRatio=function(e,i,o){var r=[i,o,0,1];return ne(r,r,e),{point:new t.Point((r[0]/r[3]+1)/2*this.transform.width+100,(-r[1]/r[3]+1)/2*this.transform.height+100),perspectiveRatio:.5+this.transform.cameraToCenterDistance/r[3]*.5}},se.prototype.isOffscreen=function(t,e,i,o){return i<100||t>=this.screenRightBoundary||o<100||e>this.screenBottomBoundary},se.prototype.isInsideGrid=function(t,e,i,o){return i>=0&&t<this.gridRightBoundary&&o>=0&&e<this.gridBottomBoundary};var ue=function(t,e,i,o){this.opacity=t?Math.max(0,Math.min(1,t.opacity+(t.placed?e:-e))):o&&i?1:0,this.placed=i;};ue.prototype.isHidden=function(){return 0===this.opacity&&!this.placed};var he=function(t,e,i,o,r){this.text=new ue(t?t.text:null,e,i,r),this.icon=new ue(t?t.icon:null,e,o,r);};he.prototype.isHidden=function(){return this.text.isHidden()&&this.icon.isHidden()};var pe=function(t,e,i){this.text=t,this.icon=e,this.skipFade=i;},de=function(t,e,i,o,r){this.bucketInstanceId=t,this.featureIndex=e,this.sourceLayerIndex=i,this.bucketIndex=o,this.tileID=r;},_e=function(t){this.crossSourceCollisions=t,this.maxGroupID=0,this.collisionGroups={};};function fe(e,i,o,r,a){var n=t.getAnchorAlignment(e),s=-(n.horizontalAlign-.5)*i,l=-(n.verticalAlign-.5)*o,c=t.evaluateRadialOffset(e,r);return new t.Point(s+c[0]*a,l+c[1]*a)}_e.prototype.get=function(t){if(this.crossSourceCollisions)return {ID:0,predicate:null};if(!this.collisionGroups[t]){var e=++this.maxGroupID;this.collisionGroups[t]={ID:e,predicate:function(t){return t.collisionGroupID===e}};}return this.collisionGroups[t]};var me=function(t,e,i,o){this.transform=t.clone(),this.collisionIndex=new se(this.transform),this.placements={},this.opacities={},this.variableOffsets={},this.stale=!1,this.commitTime=0,this.fadeDuration=e,this.retainedQueryData={},this.collisionGroups=new _e(i),this.prevPlacement=o,o&&(o.prevPlacement=void 0);};function ge(t,e,i,o,r){t.emplaceBack(e?1:0,i?1:0,o||0,r||0),t.emplaceBack(e?1:0,i?1:0,o||0,r||0),t.emplaceBack(e?1:0,i?1:0,o||0,r||0),t.emplaceBack(e?1:0,i?1:0,o||0,r||0);}me.prototype.placeLayerTile=function(e,i,o,r){var a=i.getBucket(e),n=i.latestFeatureIndex;if(a&&n&&e.id===a.layerIds[0]){var s=i.collisionBoxArray,l=a.layers[0].layout,c=Math.pow(2,this.transform.zoom-i.tileID.overscaledZ),u=i.tileSize/t.EXTENT,h=this.transform.calculatePosMatrix(i.tileID.toUnwrapped()),p=Ht(h,\"map\"===l.get(\"text-pitch-alignment\"),\"map\"===l.get(\"text-rotation-alignment\"),this.transform,ce(i,1,this.transform.zoom)),d=Ht(h,\"map\"===l.get(\"icon-pitch-alignment\"),\"map\"===l.get(\"icon-rotation-alignment\"),this.transform,ce(i,1,this.transform.zoom));this.retainedQueryData[a.bucketInstanceId]=new de(a.bucketInstanceId,n,a.sourceLayerIndex,a.index,i.tileID),this.placeLayerBucket(a,h,p,d,c,u,o,i.holdingForFade(),r,s);}},me.prototype.attemptAnchorPlacement=function(e,i,o,r,a,n,s,l,c,u,h,p,d,_){var f,m=fe(e,o,r,a,n),g=this.collisionIndex.placeCollisionBox(function(e,i,o,r,a,n){var s=e.x1,l=e.x2,c=e.y1,u=e.y2,h=e.anchorPointX,p=e.anchorPointY,d=new t.Point(i,o);return r&&d._rotate(a?n:-n),{x1:s+d.x,y1:c+d.y,x2:l+d.x,y2:u+d.y,anchorPointX:h,anchorPointY:p}}(i,m.x,m.y,s,l,this.transform.angle),p,c,u,h.predicate);if(g.box.length>0)return this.prevPlacement&&this.prevPlacement.variableOffsets[d.crossTileID]&&this.prevPlacement.placements[d.crossTileID]&&this.prevPlacement.placements[d.crossTileID].text&&(f=this.prevPlacement.variableOffsets[d.crossTileID].anchor),this.variableOffsets[d.crossTileID]={radialOffset:a,width:o,height:r,anchor:e,textBoxScale:n,prevAnchor:f},this.markUsedJustification(_,e,d),g},me.prototype.placeLayerBucket=function(e,i,o,r,a,n,s,l,c,u){var h=this,p=e.layers[0].layout,d=t.evaluateSizeForZoom(e.textSizeData,this.transform.zoom),_=p.get(\"text-optional\"),f=p.get(\"icon-optional\"),m=p.get(\"text-allow-overlap\"),g=p.get(\"icon-allow-overlap\"),v=m&&(g||!e.hasIconData()||f),y=g&&(m||!e.hasTextData()||_),x=this.collisionGroups.get(e.sourceID),b=\"map\"===p.get(\"text-rotation-alignment\"),w=\"map\"===p.get(\"text-pitch-alignment\"),E=\"viewport-y\"===p.get(\"symbol-z-order\");!e.collisionArrays&&u&&e.deserializeCollisionBoxes(u);var T=function(r,u){if(!c[r.crossTileID])if(l)h.placements[r.crossTileID]=new pe(!1,!1,!1);else{var g=!1,E=!1,T=!0,I=null,C=null,S=null,P=0,z=0;u.textFeatureIndex&&(P=u.textFeatureIndex);var L=u.textBox;if(L)if(p.get(\"text-variable-anchor\")){var D=L.x2-L.x1,M=L.y2-L.y1,R=r.textBoxScale,A=p.get(\"text-variable-anchor\");if(h.prevPlacement&&h.prevPlacement.variableOffsets[r.crossTileID]){var k=h.prevPlacement.variableOffsets[r.crossTileID];A[0]!==k.anchor&&(A=A.filter(function(t){return t!==k.anchor})).unshift(k.anchor);}for(var B=0,O=A;B<O.length;B+=1){var F=O[B];if(I=h.attemptAnchorPlacement(F,L,D,M,r.radialTextOffset,R,b,w,n,i,x,m,r,e)){g=!0;break}}if(!h.variableOffsets[r.crossTileID]&&h.prevPlacement){var U=h.prevPlacement.variableOffsets[r.crossTileID];U&&(h.variableOffsets[r.crossTileID]=U,h.markUsedJustification(e,U.anchor,r));}}else g=(I=h.collisionIndex.placeCollisionBox(L,p.get(\"text-allow-overlap\"),n,i,x.predicate)).box.length>0;T=I&&I.offscreen;var N=u.textCircles;if(N){var Z=e.text.placedSymbolArray.get(r.centerJustifiedTextSymbolIndex),j=t.evaluateSizeForFeature(e.textSizeData,d,Z);C=h.collisionIndex.placeCollisionCircles(N,p.get(\"text-allow-overlap\"),a,n,Z,e.lineVertexArray,e.glyphOffsetArray,j,i,o,s,w,x.predicate),g=p.get(\"text-allow-overlap\")||C.circles.length>0,T=T&&C.offscreen;}u.iconFeatureIndex&&(z=u.iconFeatureIndex),u.iconBox&&(E=(S=h.collisionIndex.placeCollisionBox(u.iconBox,p.get(\"icon-allow-overlap\"),n,i,x.predicate)).box.length>0,T=T&&S.offscreen);var q=_||0===r.numHorizontalGlyphVertices&&0===r.numVerticalGlyphVertices,V=f||0===r.numIconVertices;q||V?V?q||(E=E&&g):g=E&&g:E=g=E&&g,g&&I&&h.collisionIndex.insertCollisionBox(I.box,p.get(\"text-ignore-placement\"),e.bucketInstanceId,P,x.ID),E&&S&&h.collisionIndex.insertCollisionBox(S.box,p.get(\"icon-ignore-placement\"),e.bucketInstanceId,z,x.ID),g&&C&&h.collisionIndex.insertCollisionCircles(C.circles,p.get(\"text-ignore-placement\"),e.bucketInstanceId,P,x.ID),h.placements[r.crossTileID]=new pe(g||v,E||y,T||e.justReloaded),c[r.crossTileID]=!0;}};if(E)for(var I=e.getSortedSymbolIndexes(this.transform.angle),C=I.length-1;C>=0;--C){var S=I[C];T(e.symbolInstances.get(S),e.collisionArrays[S]);}else for(var P=0;P<e.symbolInstances.length;++P)T(e.symbolInstances.get(P),e.collisionArrays[P]);e.justReloaded=!1;},me.prototype.markUsedJustification=function(e,i,o){var r={left:o.leftJustifiedTextSymbolIndex,center:o.centerJustifiedTextSymbolIndex,right:o.rightJustifiedTextSymbolIndex},a=r[t.getAnchorJustification(i)];for(var n in r){var s=r[n];s>=0&&(e.text.placedSymbolArray.get(s).crossTileID=a>=0&&s!==a?0:o.crossTileID);}},me.prototype.commit=function(t){this.commitTime=t;var e=this.prevPlacement,i=!1,o=e&&0!==this.fadeDuration?(this.commitTime-e.commitTime)/this.fadeDuration:1,r=e?e.opacities:{},a=e?e.variableOffsets:{};for(var n in this.placements){var s=this.placements[n],l=r[n];l?(this.opacities[n]=new he(l,o,s.text,s.icon),i=i||s.text!==l.text.placed||s.icon!==l.icon.placed):(this.opacities[n]=new he(null,o,s.text,s.icon,s.skipFade),i=i||s.text||s.icon);}for(var c in r){var u=r[c];if(!this.opacities[c]){var h=new he(u,o,!1,!1);h.isHidden()||(this.opacities[c]=h,i=i||u.text.placed||u.icon.placed);}}for(var p in a)this.variableOffsets[p]||!this.opacities[p]||this.opacities[p].isHidden()||(this.variableOffsets[p]=a[p]);i?this.lastPlacementChangeTime=t:\"number\"!=typeof this.lastPlacementChangeTime&&(this.lastPlacementChangeTime=e?e.lastPlacementChangeTime:t);},me.prototype.updateLayerOpacities=function(t,e){for(var i={},o=0,r=e;o<r.length;o+=1){var a=r[o],n=a.getBucket(t);n&&a.latestFeatureIndex&&t.id===n.layerIds[0]&&this.updateBucketOpacities(n,i,a.collisionBoxArray);}},me.prototype.updateBucketOpacities=function(e,i,o){e.hasTextData()&&e.text.opacityVertexArray.clear(),e.hasIconData()&&e.icon.opacityVertexArray.clear(),e.hasCollisionBoxData()&&e.collisionBox.collisionVertexArray.clear(),e.hasCollisionCircleData()&&e.collisionCircle.collisionVertexArray.clear();var r=e.layers[0].layout,a=new he(null,0,!1,!1,!0),n=r.get(\"text-allow-overlap\"),s=r.get(\"icon-allow-overlap\"),l=r.get(\"text-variable-anchor\"),c=\"map\"===r.get(\"text-rotation-alignment\"),u=\"map\"===r.get(\"text-pitch-alignment\"),h=new he(null,0,n&&(s||!e.hasIconData()||r.get(\"icon-optional\")),s&&(n||!e.hasTextData()||r.get(\"text-optional\")),!0);!e.collisionArrays&&o&&(e.hasCollisionBoxData()||e.hasCollisionCircleData())&&e.deserializeCollisionBoxes(o);for(var p=0;p<e.symbolInstances.length;p++){var d=e.symbolInstances.get(p),_=d.numHorizontalGlyphVertices,f=d.numVerticalGlyphVertices,m=d.crossTileID,g=i[m],v=this.opacities[m];g?v=a:v||(v=h,this.opacities[m]=v),i[m]=!0;var y=_>0||f>0,x=d.numIconVertices>0;if(y){for(var b=Ie(v.text),w=(_+f)/4,E=0;E<w;E++)e.text.opacityVertexArray.emplaceBack(b);var T=v.text.isHidden()?1:0;[d.rightJustifiedTextSymbolIndex,d.centerJustifiedTextSymbolIndex,d.leftJustifiedTextSymbolIndex,d.verticalPlacedTextSymbolIndex].forEach(function(t){t>=0&&(e.text.placedSymbolArray.get(t).hidden=T);});var I=this.variableOffsets[d.crossTileID];I&&this.markUsedJustification(e,I.anchor,d);}if(x){for(var C=Ie(v.icon),S=0;S<d.numIconVertices/4;S++)e.icon.opacityVertexArray.emplaceBack(C);e.icon.placedSymbolArray.get(p).hidden=v.icon.isHidden();}if(e.hasCollisionBoxData()||e.hasCollisionCircleData()){var P=e.collisionArrays[p];if(P){if(P.textBox){var z=new t.Point(0,0),L=!0;if(l){var D=this.variableOffsets[m];D?(z=fe(D.anchor,D.width,D.height,D.radialOffset,D.textBoxScale),c&&z._rotate(u?this.transform.angle:-this.transform.angle)):L=!1;}ge(e.collisionBox.collisionVertexArray,v.text.placed,!L,z.x,z.y);}P.iconBox&&ge(e.collisionBox.collisionVertexArray,v.icon.placed,!1);var M=P.textCircles;if(M&&e.hasCollisionCircleData())for(var R=0;R<M.length;R+=5){var A=g||0===M[R+4];ge(e.collisionCircle.collisionVertexArray,v.text.placed,A);}}}}e.sortFeatures(this.transform.angle),this.retainedQueryData[e.bucketInstanceId]&&(this.retainedQueryData[e.bucketInstanceId].featureSortOrder=e.featureSortOrder),e.hasTextData()&&e.text.opacityVertexBuffer&&e.text.opacityVertexBuffer.updateData(e.text.opacityVertexArray),e.hasIconData()&&e.icon.opacityVertexBuffer&&e.icon.opacityVertexBuffer.updateData(e.icon.opacityVertexArray),e.hasCollisionBoxData()&&e.collisionBox.collisionVertexBuffer&&e.collisionBox.collisionVertexBuffer.updateData(e.collisionBox.collisionVertexArray),e.hasCollisionCircleData()&&e.collisionCircle.collisionVertexBuffer&&e.collisionCircle.collisionVertexBuffer.updateData(e.collisionCircle.collisionVertexArray);},me.prototype.symbolFadeChange=function(t){return 0===this.fadeDuration?1:(t-this.commitTime)/this.fadeDuration},me.prototype.hasTransitions=function(t){return this.stale||t-this.lastPlacementChangeTime<this.fadeDuration},me.prototype.stillRecent=function(t){return this.commitTime+this.fadeDuration>t},me.prototype.setStale=function(){this.stale=!0;};var ve=Math.pow(2,25),ye=Math.pow(2,24),xe=Math.pow(2,17),be=Math.pow(2,16),we=Math.pow(2,9),Ee=Math.pow(2,8),Te=Math.pow(2,1);function Ie(t){if(0===t.opacity&&!t.placed)return 0;if(1===t.opacity&&t.placed)return 4294967295;var e=t.placed?1:0,i=Math.floor(127*t.opacity);return i*ve+e*ye+i*xe+e*be+i*we+e*Ee+i*Te+e}var Ce=function(){this._currentTileIndex=0,this._seenCrossTileIDs={};};Ce.prototype.continuePlacement=function(t,e,i,o,r){for(;this._currentTileIndex<t.length;){var a=t[this._currentTileIndex];if(e.placeLayerTile(o,a,i,this._seenCrossTileIDs),this._currentTileIndex++,r())return !0}};var Se=function(t,e,i,o,r,a,n){this.placement=new me(t,r,a,n),this._currentPlacementIndex=e.length-1,this._forceFullPlacement=i,this._showCollisionBoxes=o,this._done=!1;};Se.prototype.isDone=function(){return this._done},Se.prototype.continuePlacement=function(e,i,o){for(var r=this,a=t.browser.now(),n=function(){var e=t.browser.now()-a;return !r._forceFullPlacement&&e>2};this._currentPlacementIndex>=0;){var s=i[e[this._currentPlacementIndex]],l=this.placement.collisionIndex.transform.zoom;if(\"symbol\"===s.type&&(!s.minzoom||s.minzoom<=l)&&(!s.maxzoom||s.maxzoom>l)){if(this._inProgressLayer||(this._inProgressLayer=new Ce),this._inProgressLayer.continuePlacement(o[s.source],this.placement,this._showCollisionBoxes,s,n))return;delete this._inProgressLayer;}this._currentPlacementIndex--;}this._done=!0;},Se.prototype.commit=function(t){return this.placement.commit(t),this.placement};var Pe=512/t.EXTENT/2,ze=function(t,e,i){this.tileID=t,this.indexedSymbolInstances={},this.bucketInstanceId=i;for(var o=0;o<e.length;o++){var r=e.get(o),a=r.key;this.indexedSymbolInstances[a]||(this.indexedSymbolInstances[a]=[]),this.indexedSymbolInstances[a].push({crossTileID:r.crossTileID,coord:this.getScaledCoordinates(r,t)});}};ze.prototype.getScaledCoordinates=function(e,i){var o=i.canonical.z-this.tileID.canonical.z,r=Pe/Math.pow(2,o);return {x:Math.floor((i.canonical.x*t.EXTENT+e.anchorX)*r),y:Math.floor((i.canonical.y*t.EXTENT+e.anchorY)*r)}},ze.prototype.findMatches=function(t,e,i){for(var o=this.tileID.canonical.z<e.canonical.z?1:Math.pow(2,this.tileID.canonical.z-e.canonical.z),r=0;r<t.length;r++){var a=t.get(r);if(!a.crossTileID){var n=this.indexedSymbolInstances[a.key];if(n)for(var s=this.getScaledCoordinates(a,e),l=0,c=n;l<c.length;l+=1){var u=c[l];if(Math.abs(u.coord.x-s.x)<=o&&Math.abs(u.coord.y-s.y)<=o&&!i[u.crossTileID]){i[u.crossTileID]=!0,a.crossTileID=u.crossTileID;break}}}}};var Le=function(){this.maxCrossTileID=0;};Le.prototype.generate=function(){return ++this.maxCrossTileID};var De=function(){this.indexes={},this.usedCrossTileIDs={},this.lng=0;};De.prototype.handleWrapJump=function(t){var e=Math.round((t-this.lng)/360);if(0!==e)for(var i in this.indexes){var o=this.indexes[i],r={};for(var a in o){var n=o[a];n.tileID=n.tileID.unwrapTo(n.tileID.wrap+e),r[n.tileID.key]=n;}this.indexes[i]=r;}this.lng=t;},De.prototype.addBucket=function(t,e,i){if(this.indexes[t.overscaledZ]&&this.indexes[t.overscaledZ][t.key]){if(this.indexes[t.overscaledZ][t.key].bucketInstanceId===e.bucketInstanceId)return !1;this.removeBucketCrossTileIDs(t.overscaledZ,this.indexes[t.overscaledZ][t.key]);}for(var o=0;o<e.symbolInstances.length;o++){e.symbolInstances.get(o).crossTileID=0;}this.usedCrossTileIDs[t.overscaledZ]||(this.usedCrossTileIDs[t.overscaledZ]={});var r=this.usedCrossTileIDs[t.overscaledZ];for(var a in this.indexes){var n=this.indexes[a];if(Number(a)>t.overscaledZ)for(var s in n){var l=n[s];l.tileID.isChildOf(t)&&l.findMatches(e.symbolInstances,t,r);}else{var c=n[t.scaledTo(Number(a)).key];c&&c.findMatches(e.symbolInstances,t,r);}}for(var u=0;u<e.symbolInstances.length;u++){var h=e.symbolInstances.get(u);h.crossTileID||(h.crossTileID=i.generate(),r[h.crossTileID]=!0);}return void 0===this.indexes[t.overscaledZ]&&(this.indexes[t.overscaledZ]={}),this.indexes[t.overscaledZ][t.key]=new ze(t,e.symbolInstances,e.bucketInstanceId),!0},De.prototype.removeBucketCrossTileIDs=function(t,e){for(var i in e.indexedSymbolInstances)for(var o=0,r=e.indexedSymbolInstances[i];o<r.length;o+=1){var a=r[o];delete this.usedCrossTileIDs[t][a.crossTileID];}},De.prototype.removeStaleBuckets=function(t){var e=!1;for(var i in this.indexes){var o=this.indexes[i];for(var r in o)t[o[r].bucketInstanceId]||(this.removeBucketCrossTileIDs(i,o[r]),delete o[r],e=!0);}return e};var Me=function(){this.layerIndexes={},this.crossTileIDs=new Le,this.maxBucketInstanceId=0,this.bucketsInCurrentPlacement={};};Me.prototype.addLayer=function(t,e,i){var o=this.layerIndexes[t.id];void 0===o&&(o=this.layerIndexes[t.id]=new De);var r=!1,a={};o.handleWrapJump(i);for(var n=0,s=e;n<s.length;n+=1){var l=s[n],c=l.getBucket(t);c&&t.id===c.layerIds[0]&&(c.bucketInstanceId||(c.bucketInstanceId=++this.maxBucketInstanceId),o.addBucket(l.tileID,c,this.crossTileIDs)&&(r=!0),a[c.bucketInstanceId]=!0);}return o.removeStaleBuckets(a)&&(r=!0),r},Me.prototype.pruneUnusedLayers=function(t){var e={};for(var i in t.forEach(function(t){e[t]=!0;}),this.layerIndexes)e[i]||delete this.layerIndexes[i];};var Re=function(e,i){return t.emitValidationErrors(e,i&&i.filter(function(t){return \"source.canvas\"!==t.identifier}))},Ae=t.pick(Ft,[\"addLayer\",\"removeLayer\",\"setPaintProperty\",\"setLayoutProperty\",\"setFilter\",\"addSource\",\"removeSource\",\"setLayerZoomRange\",\"setLight\",\"setTransition\",\"setGeoJSONSourceData\"]),ke=t.pick(Ft,[\"setCenter\",\"setZoom\",\"setBearing\",\"setPitch\"]),Be=function(e){function i(o,r){var a=this;void 0===r&&(r={}),e.call(this),this.map=o,this.dispatcher=new E((At||(At=new Rt),At),this),this.imageManager=new p,this.imageManager.setEventedParent(this),this.glyphManager=new v(o._requestManager,r.localIdeographFontFamily),this.lineAtlas=new w(256,512),this.crossTileSymbolIndex=new Me,this._layers={},this._order=[],this.sourceCaches={},this.zoomHistory=new t.ZoomHistory,this._loaded=!1,this._resetUpdates(),this.dispatcher.broadcast(\"setReferrer\",t.getReferrer());var n=this;this._rtlTextPluginCallback=i.registerForPluginAvailability(function(t){for(var e in n.dispatcher.broadcast(\"loadRTLTextPlugin\",t.pluginURL,t.completionCallback),n.sourceCaches)n.sourceCaches[e].reload();}),this.on(\"data\",function(t){if(\"source\"===t.dataType&&\"metadata\"===t.sourceDataType){var e=a.sourceCaches[t.sourceId];if(e){var i=e.getSource();if(i&&i.vectorLayerIds)for(var o in a._layers){var r=a._layers[o];r.source===i.id&&a._validateLayer(r);}}}});}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.loadURL=function(e,i){var o=this;void 0===i&&(i={}),this.fire(new t.Event(\"dataloading\",{dataType:\"style\"}));var r=\"boolean\"==typeof i.validate?i.validate:!t.isMapboxURL(e);e=this.map._requestManager.normalizeStyleURL(e,i.accessToken);var a=this.map._requestManager.transformRequest(e,t.ResourceType.Style);this._request=t.getJSON(a,function(e,i){o._request=null,e?o.fire(new t.ErrorEvent(e)):i&&o._load(i,r);});},i.prototype.loadJSON=function(e,i){var o=this;void 0===i&&(i={}),this.fire(new t.Event(\"dataloading\",{dataType:\"style\"})),this._request=t.browser.frame(function(){o._request=null,o._load(e,!1!==i.validate);});},i.prototype._load=function(e,i){var o=this;if(!i||!Re(this,t.validateStyle(e))){for(var r in this._loaded=!0,this.stylesheet=e,e.sources)this.addSource(r,e.sources[r],{validate:!1});e.sprite?this._spriteRequest=function(e,i,o){var r,a,n,s=t.browser.devicePixelRatio>1?\"@2x\":\"\",l=t.getJSON(i.transformRequest(i.normalizeSpriteURL(e,s,\".json\"),t.ResourceType.SpriteJSON),function(t,e){l=null,n||(n=t,r=e,u());}),c=t.getImage(i.transformRequest(i.normalizeSpriteURL(e,s,\".png\"),t.ResourceType.SpriteImage),function(t,e){c=null,n||(n=t,a=e,u());});function u(){if(n)o(n);else if(r&&a){var e=t.browser.getImageData(a),i={};for(var s in r){var l=r[s],c=l.width,u=l.height,h=l.x,p=l.y,d=l.sdf,_=l.pixelRatio,f=new t.RGBAImage({width:c,height:u});t.RGBAImage.copy(e,f,{x:h,y:p},{x:0,y:0},{width:c,height:u}),i[s]={data:f,pixelRatio:_,sdf:d};}o(null,i);}}return {cancel:function(){l&&(l.cancel(),l=null),c&&(c.cancel(),c=null);}}}(e.sprite,this.map._requestManager,function(e,i){if(o._spriteRequest=null,e)o.fire(new t.ErrorEvent(e));else if(i)for(var r in i)o.imageManager.addImage(r,i[r]);o.imageManager.setLoaded(!0),o.fire(new t.Event(\"data\",{dataType:\"style\"}));}):this.imageManager.setLoaded(!0),this.glyphManager.setURL(e.glyphs);var a=Ot(this.stylesheet.layers);this._order=a.map(function(t){return t.id}),this._layers={};for(var n=0,s=a;n<s.length;n+=1){var l=s[n];(l=t.createStyleLayer(l)).setEventedParent(this,{layer:{id:l.id}}),this._layers[l.id]=l;}this.dispatcher.broadcast(\"setLayers\",this._serializeLayers(this._order)),this.light=new b(this.stylesheet.light),this.fire(new t.Event(\"data\",{dataType:\"style\"})),this.fire(new t.Event(\"style.load\"));}},i.prototype._validateLayer=function(e){var i=this.sourceCaches[e.source];if(i){var o=e.sourceLayer;if(o){var r=i.getSource();(\"geojson\"===r.type||r.vectorLayerIds&&-1===r.vectorLayerIds.indexOf(o))&&this.fire(new t.ErrorEvent(new Error('Source layer \"'+o+'\" does not exist on source \"'+r.id+'\" as specified by style layer \"'+e.id+'\"')));}}},i.prototype.loaded=function(){if(!this._loaded)return !1;if(Object.keys(this._updatedSources).length)return !1;for(var t in this.sourceCaches)if(!this.sourceCaches[t].loaded())return !1;return !!this.imageManager.isLoaded()},i.prototype._serializeLayers=function(t){for(var e=[],i=0,o=t;i<o.length;i+=1){var r=o[i],a=this._layers[r];\"custom\"!==a.type&&e.push(a.serialize());}return e},i.prototype.hasTransitions=function(){if(this.light&&this.light.hasTransition())return !0;for(var t in this.sourceCaches)if(this.sourceCaches[t].hasTransition())return !0;for(var e in this._layers)if(this._layers[e].hasTransition())return !0;return !1},i.prototype._checkLoaded=function(){if(!this._loaded)throw new Error(\"Style is not done loading\")},i.prototype.update=function(e){if(this._loaded){var i=this._changed;if(this._changed){var o=Object.keys(this._updatedLayers),r=Object.keys(this._removedLayers);for(var a in(o.length||r.length)&&this._updateWorkerLayers(o,r),this._updatedSources){var n=this._updatedSources[a];\"reload\"===n?this._reloadSource(a):\"clear\"===n&&this._clearSource(a);}for(var s in this._updatedPaintProps)this._layers[s].updateTransitions(e);this.light.updateTransitions(e),this._resetUpdates();}for(var l in this.sourceCaches)this.sourceCaches[l].used=!1;for(var c=0,u=this._order;c<u.length;c+=1){var h=u[c],p=this._layers[h];p.recalculate(e),!p.isHidden(e.zoom)&&p.source&&(this.sourceCaches[p.source].used=!0);}this.light.recalculate(e),this.z=e.zoom,i&&this.fire(new t.Event(\"data\",{dataType:\"style\"}));}},i.prototype._updateWorkerLayers=function(t,e){this.dispatcher.broadcast(\"updateLayers\",{layers:this._serializeLayers(t),removedIds:e});},i.prototype._resetUpdates=function(){this._changed=!1,this._updatedLayers={},this._removedLayers={},this._updatedSources={},this._updatedPaintProps={};},i.prototype.setState=function(e){var i=this;if(this._checkLoaded(),Re(this,t.validateStyle(e)))return !1;(e=t.clone$1(e)).layers=Ot(e.layers);var o=Wt(this.serialize(),e).filter(function(t){return !(t.command in ke)});if(0===o.length)return !1;var r=o.filter(function(t){return !(t.command in Ae)});if(r.length>0)throw new Error(\"Unimplemented: \"+r.map(function(t){return t.command}).join(\", \")+\".\");return o.forEach(function(t){\"setTransition\"!==t.command&&i[t.command].apply(i,t.args);}),this.stylesheet=e,!0},i.prototype.addImage=function(e,i){if(this.getImage(e))return this.fire(new t.ErrorEvent(new Error(\"An image with this name already exists.\")));this.imageManager.addImage(e,i),this.fire(new t.Event(\"data\",{dataType:\"style\"}));},i.prototype.updateImage=function(t,e){this.imageManager.updateImage(t,e);},i.prototype.getImage=function(t){return this.imageManager.getImage(t)},i.prototype.removeImage=function(e){if(!this.getImage(e))return this.fire(new t.ErrorEvent(new Error(\"No image with this name exists.\")));this.imageManager.removeImage(e),this.fire(new t.Event(\"data\",{dataType:\"style\"}));},i.prototype.listImages=function(){return this._checkLoaded(),this.imageManager.listImages()},i.prototype.addSource=function(e,i,o){var r=this;if(void 0===o&&(o={}),this._checkLoaded(),void 0!==this.sourceCaches[e])throw new Error(\"There is already a source with this ID\");if(!i.type)throw new Error(\"The type property must be defined, but the only the following properties were given: \"+Object.keys(i).join(\", \")+\".\");if(!([\"vector\",\"raster\",\"geojson\",\"video\",\"image\"].indexOf(i.type)>=0)||!this._validate(t.validateStyle.source,\"sources.\"+e,i,null,o)){this.map&&this.map._collectResourceTiming&&(i.collectResourceTiming=!0);var a=this.sourceCaches[e]=new zt(e,i,this.dispatcher);a.style=this,a.setEventedParent(this,function(){return {isSourceLoaded:r.loaded(),source:a.serialize(),sourceId:e}}),a.onAdd(this.map),this._changed=!0;}},i.prototype.removeSource=function(e){if(this._checkLoaded(),void 0===this.sourceCaches[e])throw new Error(\"There is no source with this ID\");for(var i in this._layers)if(this._layers[i].source===e)return this.fire(new t.ErrorEvent(new Error('Source \"'+e+'\" cannot be removed while layer \"'+i+'\" is using it.')));var o=this.sourceCaches[e];delete this.sourceCaches[e],delete this._updatedSources[e],o.fire(new t.Event(\"data\",{sourceDataType:\"metadata\",dataType:\"source\",sourceId:e})),o.setEventedParent(null),o.clearTiles(),o.onRemove&&o.onRemove(this.map),this._changed=!0;},i.prototype.setGeoJSONSourceData=function(t,e){this._checkLoaded(),this.sourceCaches[t].getSource().setData(e),this._changed=!0;},i.prototype.getSource=function(t){return this.sourceCaches[t]&&this.sourceCaches[t].getSource()},i.prototype.addLayer=function(e,i,o){void 0===o&&(o={}),this._checkLoaded();var r=e.id;if(this.getLayer(r))this.fire(new t.ErrorEvent(new Error('Layer with id \"'+r+'\" already exists on this map')));else{var a;if(\"custom\"===e.type){if(Re(this,t.validateCustomStyleLayer(e)))return;a=t.createStyleLayer(e);}else{if(\"object\"==typeof e.source&&(this.addSource(r,e.source),e=t.clone$1(e),e=t.extend(e,{source:r})),this._validate(t.validateStyle.layer,\"layers.\"+r,e,{arrayIndex:-1},o))return;a=t.createStyleLayer(e),this._validateLayer(a),a.setEventedParent(this,{layer:{id:r}});}var n=i?this._order.indexOf(i):this._order.length;if(i&&-1===n)this.fire(new t.ErrorEvent(new Error('Layer with id \"'+i+'\" does not exist on this map.')));else{if(this._order.splice(n,0,r),this._layerOrderChanged=!0,this._layers[r]=a,this._removedLayers[r]&&a.source&&\"custom\"!==a.type){var s=this._removedLayers[r];delete this._removedLayers[r],s.type!==a.type?this._updatedSources[a.source]=\"clear\":(this._updatedSources[a.source]=\"reload\",this.sourceCaches[a.source].pause());}this._updateLayer(a),a.onAdd&&a.onAdd(this.map);}}},i.prototype.moveLayer=function(e,i){if(this._checkLoaded(),this._changed=!0,this._layers[e]){if(e!==i){var o=this._order.indexOf(e);this._order.splice(o,1);var r=i?this._order.indexOf(i):this._order.length;i&&-1===r?this.fire(new t.ErrorEvent(new Error('Layer with id \"'+i+'\" does not exist on this map.'))):(this._order.splice(r,0,e),this._layerOrderChanged=!0);}}else this.fire(new t.ErrorEvent(new Error(\"The layer '\"+e+\"' does not exist in the map's style and cannot be moved.\")));},i.prototype.removeLayer=function(e){this._checkLoaded();var i=this._layers[e];if(i){i.setEventedParent(null);var o=this._order.indexOf(e);this._order.splice(o,1),this._layerOrderChanged=!0,this._changed=!0,this._removedLayers[e]=i,delete this._layers[e],delete this._updatedLayers[e],delete this._updatedPaintProps[e],i.onRemove&&i.onRemove(this.map);}else this.fire(new t.ErrorEvent(new Error(\"The layer '\"+e+\"' does not exist in the map's style and cannot be removed.\")));},i.prototype.getLayer=function(t){return this._layers[t]},i.prototype.setLayerZoomRange=function(e,i,o){this._checkLoaded();var r=this.getLayer(e);r?r.minzoom===i&&r.maxzoom===o||(null!=i&&(r.minzoom=i),null!=o&&(r.maxzoom=o),this._updateLayer(r)):this.fire(new t.ErrorEvent(new Error(\"The layer '\"+e+\"' does not exist in the map's style and cannot have zoom extent.\")));},i.prototype.setFilter=function(e,i,o){void 0===o&&(o={}),this._checkLoaded();var r=this.getLayer(e);if(r){if(!t.deepEqual(r.filter,i))return null==i?(r.filter=void 0,void this._updateLayer(r)):void(this._validate(t.validateStyle.filter,\"layers.\"+r.id+\".filter\",i,null,o)||(r.filter=t.clone$1(i),this._updateLayer(r)))}else this.fire(new t.ErrorEvent(new Error(\"The layer '\"+e+\"' does not exist in the map's style and cannot be filtered.\")));},i.prototype.getFilter=function(e){return t.clone$1(this.getLayer(e).filter)},i.prototype.setLayoutProperty=function(e,i,o,r){void 0===r&&(r={}),this._checkLoaded();var a=this.getLayer(e);a?t.deepEqual(a.getLayoutProperty(i),o)||(a.setLayoutProperty(i,o,r),this._updateLayer(a)):this.fire(new t.ErrorEvent(new Error(\"The layer '\"+e+\"' does not exist in the map's style and cannot be styled.\")));},i.prototype.getLayoutProperty=function(e,i){var o=this.getLayer(e);if(o)return o.getLayoutProperty(i);this.fire(new t.ErrorEvent(new Error(\"The layer '\"+e+\"' does not exist in the map's style.\")));},i.prototype.setPaintProperty=function(e,i,o,r){void 0===r&&(r={}),this._checkLoaded();var a=this.getLayer(e);a?t.deepEqual(a.getPaintProperty(i),o)||(a.setPaintProperty(i,o,r)&&this._updateLayer(a),this._changed=!0,this._updatedPaintProps[e]=!0):this.fire(new t.ErrorEvent(new Error(\"The layer '\"+e+\"' does not exist in the map's style and cannot be styled.\")));},i.prototype.getPaintProperty=function(t,e){return this.getLayer(t).getPaintProperty(e)},i.prototype.setFeatureState=function(e,i){this._checkLoaded();var o=e.source,r=e.sourceLayer,a=this.sourceCaches[o],n=parseInt(e.id,10);if(void 0!==a){var s=a.getSource().type;\"geojson\"===s&&r?this.fire(new t.ErrorEvent(new Error(\"GeoJSON sources cannot have a sourceLayer parameter.\"))):\"vector\"!==s||r?isNaN(n)||n<0?this.fire(new t.ErrorEvent(new Error(\"The feature id parameter must be provided and non-negative.\"))):a.setFeatureState(r,n,i):this.fire(new t.ErrorEvent(new Error(\"The sourceLayer parameter must be provided for vector source types.\")));}else this.fire(new t.ErrorEvent(new Error(\"The source '\"+o+\"' does not exist in the map's style.\")));},i.prototype.removeFeatureState=function(e,i){this._checkLoaded();var o=e.source,r=this.sourceCaches[o];if(void 0!==r){var a=r.getSource().type,n=\"vector\"===a?e.sourceLayer:void 0,s=parseInt(e.id,10);\"vector\"!==a||n?void 0!==e.id&&isNaN(s)||s<0?this.fire(new t.ErrorEvent(new Error(\"The feature id parameter must be non-negative.\"))):i&&\"string\"!=typeof e.id&&\"number\"!=typeof e.id?this.fire(new t.ErrorEvent(new Error(\"A feature id is requred to remove its specific state property.\"))):r.removeFeatureState(n,s,i):this.fire(new t.ErrorEvent(new Error(\"The sourceLayer parameter must be provided for vector source types.\")));}else this.fire(new t.ErrorEvent(new Error(\"The source '\"+o+\"' does not exist in the map's style.\")));},i.prototype.getFeatureState=function(e){this._checkLoaded();var i=e.source,o=e.sourceLayer,r=this.sourceCaches[i],a=parseInt(e.id,10);if(void 0!==r)if(\"vector\"!==r.getSource().type||o){if(!(isNaN(a)||a<0))return r.getFeatureState(o,a);this.fire(new t.ErrorEvent(new Error(\"The feature id parameter must be provided and non-negative.\")));}else this.fire(new t.ErrorEvent(new Error(\"The sourceLayer parameter must be provided for vector source types.\")));else this.fire(new t.ErrorEvent(new Error(\"The source '\"+i+\"' does not exist in the map's style.\")));},i.prototype.getTransition=function(){return t.extend({duration:300,delay:0},this.stylesheet&&this.stylesheet.transition)},i.prototype.serialize=function(){return t.filterObject({version:this.stylesheet.version,name:this.stylesheet.name,metadata:this.stylesheet.metadata,light:this.stylesheet.light,center:this.stylesheet.center,zoom:this.stylesheet.zoom,bearing:this.stylesheet.bearing,pitch:this.stylesheet.pitch,sprite:this.stylesheet.sprite,glyphs:this.stylesheet.glyphs,transition:this.stylesheet.transition,sources:t.mapObject(this.sourceCaches,function(t){return t.serialize()}),layers:this._serializeLayers(this._order)},function(t){return void 0!==t})},i.prototype._updateLayer=function(t){this._updatedLayers[t.id]=!0,t.source&&!this._updatedSources[t.source]&&(this._updatedSources[t.source]=\"reload\",this.sourceCaches[t.source].pause()),this._changed=!0;},i.prototype._flattenAndSortRenderedFeatures=function(t){for(var e=this,i=function(t){return \"fill-extrusion\"===e._layers[t].type},o={},r=[],a=this._order.length-1;a>=0;a--){var n=this._order[a];if(i(n)){o[n]=a;for(var s=0,l=t;s<l.length;s+=1){var c=l[s][n];if(c)for(var u=0,h=c;u<h.length;u+=1){var p=h[u];r.push(p);}}}}r.sort(function(t,e){return e.intersectionZ-t.intersectionZ});for(var d=[],_=this._order.length-1;_>=0;_--){var f=this._order[_];if(i(f))for(var m=r.length-1;m>=0;m--){var g=r[m].feature;if(o[g.layer.id]<_)break;d.push(g),r.pop();}else for(var v=0,y=t;v<y.length;v+=1){var x=y[v][f];if(x)for(var b=0,w=x;b<w.length;b+=1){var E=w[b];d.push(E.feature);}}}return d},i.prototype.queryRenderedFeatures=function(e,i,o){i&&i.filter&&this._validate(t.validateStyle.filter,\"queryRenderedFeatures.filter\",i.filter,null,i);var r={};if(i&&i.layers){if(!Array.isArray(i.layers))return this.fire(new t.ErrorEvent(new Error(\"parameters.layers must be an Array.\"))),[];for(var a=0,n=i.layers;a<n.length;a+=1){var s=n[a],l=this._layers[s];if(!l)return this.fire(new t.ErrorEvent(new Error(\"The layer '\"+s+\"' does not exist in the map's style and cannot be queried for features.\"))),[];r[l.source]=!0;}}var c=[];for(var u in this.sourceCaches)i.layers&&!r[u]||c.push(B(this.sourceCaches[u],this._layers,e,i,o));return this.placement&&c.push(function(t,e,i,o,r,a){for(var n={},s=r.queryRenderedSymbols(i),l=[],c=0,u=Object.keys(s).map(Number);c<u.length;c+=1){var h=u[c];l.push(a[h]);}l.sort(O);for(var p=function(){var e=_[d],i=e.featureIndex.lookupSymbolFeatures(s[e.bucketInstanceId],e.bucketIndex,e.sourceLayerIndex,o.filter,o.layers,t);for(var r in i){var a=n[r]=n[r]||[],l=i[r];l.sort(function(t,i){var o=e.featureSortOrder;if(o){var r=o.indexOf(t.featureIndex);return o.indexOf(i.featureIndex)-r}return i.featureIndex-t.featureIndex});for(var c=0,u=l;c<u.length;c+=1){var h=u[c];a.push(h);}}},d=0,_=l;d<_.length;d+=1)p();var f=function(i){n[i].forEach(function(o){var r=o.feature,a=t[i],n=e[a.source].getFeatureState(r.layer[\"source-layer\"],r.id);r.source=r.layer.source,r.layer[\"source-layer\"]&&(r.sourceLayer=r.layer[\"source-layer\"]),r.state=n;});};for(var m in n)f(m);return n}(this._layers,this.sourceCaches,e,i,this.placement.collisionIndex,this.placement.retainedQueryData)),this._flattenAndSortRenderedFeatures(c)},i.prototype.querySourceFeatures=function(e,i){i&&i.filter&&this._validate(t.validateStyle.filter,\"querySourceFeatures.filter\",i.filter,null,i);var o=this.sourceCaches[e];return o?function(t,e){for(var i=t.getRenderableIds().map(function(e){return t.getTileByID(e)}),o=[],r={},a=0;a<i.length;a++){var n=i[a],s=n.tileID.canonical.key;r[s]||(r[s]=!0,n.querySourceFeatures(o,e));}return o}(o,i):[]},i.prototype.addSourceType=function(t,e,o){return i.getSourceType(t)?o(new Error('A source type called \"'+t+'\" already exists.')):(i.setSourceType(t,e),e.workerSourceURL?void this.dispatcher.broadcast(\"loadWorkerSource\",{name:t,url:e.workerSourceURL},o):o(null,null))},i.prototype.getLight=function(){return this.light.getLight()},i.prototype.setLight=function(e,i){void 0===i&&(i={}),this._checkLoaded();var o=this.light.getLight(),r=!1;for(var a in e)if(!t.deepEqual(e[a],o[a])){r=!0;break}if(r){var n={now:t.browser.now(),transition:t.extend({duration:300,delay:0},this.stylesheet.transition)};this.light.setLight(e,i),this.light.updateTransitions(n);}},i.prototype._validate=function(e,i,o,r,a){return void 0===a&&(a={}),(!a||!1!==a.validate)&&Re(this,e.call(t.validateStyle,t.extend({key:i,style:this.serialize(),value:o,styleSpec:t.styleSpec},r)))},i.prototype._remove=function(){for(var e in this._request&&(this._request.cancel(),this._request=null),this._spriteRequest&&(this._spriteRequest.cancel(),this._spriteRequest=null),t.evented.off(\"pluginAvailable\",this._rtlTextPluginCallback),this.sourceCaches)this.sourceCaches[e].clearTiles();this.dispatcher.remove();},i.prototype._clearSource=function(t){this.sourceCaches[t].clearTiles();},i.prototype._reloadSource=function(t){this.sourceCaches[t].resume(),this.sourceCaches[t].reload();},i.prototype._updateSources=function(t){for(var e in this.sourceCaches)this.sourceCaches[e].update(t);},i.prototype._generateCollisionBoxes=function(){for(var t in this.sourceCaches)this._reloadSource(t);},i.prototype._updatePlacement=function(e,i,o,r){for(var a=!1,n=!1,s={},l=0,c=this._order;l<c.length;l+=1){var u=c[l],h=this._layers[u];if(\"symbol\"===h.type){if(!s[h.source]){var p=this.sourceCaches[h.source];s[h.source]=p.getRenderableIds(!0).map(function(t){return p.getTileByID(t)}).sort(function(t,e){return e.tileID.overscaledZ-t.tileID.overscaledZ||(t.tileID.isLessThan(e.tileID)?-1:1)});}var d=this.crossTileSymbolIndex.addLayer(h,s[h.source],e.center.lng);a=a||d;}}this.crossTileSymbolIndex.pruneUnusedLayers(this._order);var _=this._layerOrderChanged||0===o;if((_||!this.pauseablePlacement||this.pauseablePlacement.isDone()&&!this.placement.stillRecent(t.browser.now()))&&(this.pauseablePlacement=new Se(e,this._order,_,i,o,r,this.placement),this._layerOrderChanged=!1),this.pauseablePlacement.isDone()?this.placement.setStale():(this.pauseablePlacement.continuePlacement(this._order,this._layers,s),this.pauseablePlacement.isDone()&&(this.placement=this.pauseablePlacement.commit(t.browser.now()),n=!0),a&&this.pauseablePlacement.placement.setStale()),n||a)for(var f=0,m=this._order;f<m.length;f+=1){var g=m[f],v=this._layers[g];\"symbol\"===v.type&&this.placement.updateLayerOpacities(v,s[v.source]);}return !this.pauseablePlacement.isDone()||this.placement.hasTransitions(t.browser.now())},i.prototype._releaseSymbolFadeTiles=function(){for(var t in this.sourceCaches)this.sourceCaches[t].releaseSymbolFadeTiles();},i.prototype.getImages=function(t,e,i){this.imageManager.getImages(e.icons,i);},i.prototype.getGlyphs=function(t,e,i){this.glyphManager.getGlyphs(e.stacks,i);},i.prototype.getResource=function(e,i,o){return t.makeRequest(i,o)},i}(t.Evented);Be.getSourceType=function(t){return R[t]},Be.setSourceType=function(t,e){R[t]=e;},Be.registerForPluginAvailability=t.registerForPluginAvailability;var Oe=t.createLayout([{name:\"a_pos\",type:\"Int16\",components:2}]),Fe=ci(\"#ifdef GL_ES\\nprecision mediump float;\\n#else\\n#if !defined(lowp)\\n#define lowp\\n#endif\\n#if !defined(mediump)\\n#define mediump\\n#endif\\n#if !defined(highp)\\n#define highp\\n#endif\\n#endif\",\"#ifdef GL_ES\\nprecision highp float;\\n#else\\n#if !defined(lowp)\\n#define lowp\\n#endif\\n#if !defined(mediump)\\n#define mediump\\n#endif\\n#if !defined(highp)\\n#define highp\\n#endif\\n#endif\\nvec2 unpack_float(const float packedValue) {int packedIntValue=int(packedValue);int v0=packedIntValue/256;return vec2(v0,packedIntValue-v0*256);}vec2 unpack_opacity(const float packedOpacity) {int intOpacity=int(packedOpacity)/2;return vec2(float(intOpacity)/127.0,mod(packedOpacity,2.0));}vec4 decode_color(const vec2 encodedColor) {return vec4(unpack_float(encodedColor[0])/255.0,unpack_float(encodedColor[1])/255.0\\n);}float unpack_mix_vec2(const vec2 packedValue,const float t) {return mix(packedValue[0],packedValue[1],t);}vec4 unpack_mix_color(const vec4 packedColors,const float t) {vec4 minColor=decode_color(vec2(packedColors[0],packedColors[1]));vec4 maxColor=decode_color(vec2(packedColors[2],packedColors[3]));return mix(minColor,maxColor,t);}vec2 get_pattern_pos(const vec2 pixel_coord_upper,const vec2 pixel_coord_lower,const vec2 pattern_size,const float tile_units_to_pixels,const vec2 pos) {vec2 offset=mod(mod(mod(pixel_coord_upper,pattern_size)*256.0,pattern_size)*256.0+pixel_coord_lower,pattern_size);return (tile_units_to_pixels*pos+offset)/pattern_size;}\"),Ue=ci(\"uniform vec4 u_color;uniform float u_opacity;void main() {gl_FragColor=u_color*u_opacity;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"attribute vec2 a_pos;uniform mat4 u_matrix;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);}\"),Ne=ci(\"uniform vec2 u_pattern_tl_a;uniform vec2 u_pattern_br_a;uniform vec2 u_pattern_tl_b;uniform vec2 u_pattern_br_b;uniform vec2 u_texsize;uniform float u_mix;uniform float u_opacity;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;void main() {vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(u_pattern_tl_a/u_texsize,u_pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(u_pattern_tl_b/u_texsize,u_pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);gl_FragColor=mix(color1,color2,u_mix)*u_opacity;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform vec2 u_pattern_size_a;uniform vec2 u_pattern_size_b;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_scale_a;uniform float u_scale_b;uniform float u_tile_units_to_pixels;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,u_scale_a*u_pattern_size_a,u_tile_units_to_pixels,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,u_scale_b*u_pattern_size_b,u_tile_units_to_pixels,a_pos);}\"),Ze=ci(\"varying vec3 v_data;\\n#pragma mapbox: define highp vec4 color\\n#pragma mapbox: define mediump float radius\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define highp vec4 stroke_color\\n#pragma mapbox: define mediump float stroke_width\\n#pragma mapbox: define lowp float stroke_opacity\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 color\\n#pragma mapbox: initialize mediump float radius\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize highp vec4 stroke_color\\n#pragma mapbox: initialize mediump float stroke_width\\n#pragma mapbox: initialize lowp float stroke_opacity\\nvec2 extrude=v_data.xy;float extrude_length=length(extrude);lowp float antialiasblur=v_data.z;float antialiased_blur=-max(blur,antialiasblur);float opacity_t=smoothstep(0.0,antialiased_blur,extrude_length-1.0);float color_t=stroke_width < 0.01 ? 0.0 : smoothstep(antialiased_blur,0.0,extrude_length-radius/(radius+stroke_width));gl_FragColor=opacity_t*mix(color*opacity,stroke_color*stroke_opacity,color_t);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform bool u_scale_with_map;uniform bool u_pitch_with_map;uniform vec2 u_extrude_scale;uniform lowp float u_device_pixel_ratio;uniform highp float u_camera_to_center_distance;attribute vec2 a_pos;varying vec3 v_data;\\n#pragma mapbox: define highp vec4 color\\n#pragma mapbox: define mediump float radius\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define highp vec4 stroke_color\\n#pragma mapbox: define mediump float stroke_width\\n#pragma mapbox: define lowp float stroke_opacity\\nvoid main(void) {\\n#pragma mapbox: initialize highp vec4 color\\n#pragma mapbox: initialize mediump float radius\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize highp vec4 stroke_color\\n#pragma mapbox: initialize mediump float stroke_width\\n#pragma mapbox: initialize lowp float stroke_opacity\\nvec2 extrude=vec2(mod(a_pos,2.0)*2.0-1.0);vec2 circle_center=floor(a_pos*0.5);if (u_pitch_with_map) {vec2 corner_position=circle_center;if (u_scale_with_map) {corner_position+=extrude*(radius+stroke_width)*u_extrude_scale;} else {vec4 projected_center=u_matrix*vec4(circle_center,0,1);corner_position+=extrude*(radius+stroke_width)*u_extrude_scale*(projected_center.w/u_camera_to_center_distance);}gl_Position=u_matrix*vec4(corner_position,0,1);} else {gl_Position=u_matrix*vec4(circle_center,0,1);if (u_scale_with_map) {gl_Position.xy+=extrude*(radius+stroke_width)*u_extrude_scale*u_camera_to_center_distance;} else {gl_Position.xy+=extrude*(radius+stroke_width)*u_extrude_scale*gl_Position.w;}}lowp float antialiasblur=1.0/u_device_pixel_ratio/(radius+stroke_width);v_data=vec3(extrude.x,extrude.y,antialiasblur);}\"),je=ci(\"void main() {gl_FragColor=vec4(1.0);}\",\"attribute vec2 a_pos;uniform mat4 u_matrix;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);}\"),qe=ci(\"uniform highp float u_intensity;varying vec2 v_extrude;\\n#pragma mapbox: define highp float weight\\n#define GAUSS_COEF 0.3989422804014327\\nvoid main() {\\n#pragma mapbox: initialize highp float weight\\nfloat d=-0.5*3.0*3.0*dot(v_extrude,v_extrude);float val=weight*u_intensity*GAUSS_COEF*exp(d);gl_FragColor=vec4(val,1.0,1.0,1.0);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform float u_extrude_scale;uniform float u_opacity;uniform float u_intensity;attribute vec2 a_pos;varying vec2 v_extrude;\\n#pragma mapbox: define highp float weight\\n#pragma mapbox: define mediump float radius\\nconst highp float ZERO=1.0/255.0/16.0;\\n#define GAUSS_COEF 0.3989422804014327\\nvoid main(void) {\\n#pragma mapbox: initialize highp float weight\\n#pragma mapbox: initialize mediump float radius\\nvec2 unscaled_extrude=vec2(mod(a_pos,2.0)*2.0-1.0);float S=sqrt(-2.0*log(ZERO/weight/u_intensity/GAUSS_COEF))/3.0;v_extrude=S*unscaled_extrude;vec2 extrude=v_extrude*radius*u_extrude_scale;vec4 pos=vec4(floor(a_pos*0.5)+extrude,0,1);gl_Position=u_matrix*pos;}\"),Ve=ci(\"uniform sampler2D u_image;uniform sampler2D u_color_ramp;uniform float u_opacity;varying vec2 v_pos;void main() {float t=texture2D(u_image,v_pos).r;vec4 color=texture2D(u_color_ramp,vec2(t,0.5));gl_FragColor=color*u_opacity;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(0.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform vec2 u_world;attribute vec2 a_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos*u_world,0,1);v_pos.x=a_pos.x;v_pos.y=1.0-a_pos.y;}\"),Ge=ci(\"varying float v_placed;varying float v_notUsed;void main() {float alpha=0.5;gl_FragColor=vec4(1.0,0.0,0.0,1.0)*alpha;if (v_placed > 0.5) {gl_FragColor=vec4(0.0,0.0,1.0,0.5)*alpha;}if (v_notUsed > 0.5) {gl_FragColor*=.1;}}\",\"attribute vec2 a_pos;attribute vec2 a_anchor_pos;attribute vec2 a_extrude;attribute vec2 a_placed;attribute vec2 a_shift;uniform mat4 u_matrix;uniform vec2 u_extrude_scale;uniform float u_camera_to_center_distance;varying float v_placed;varying float v_notUsed;void main() {vec4 projectedPoint=u_matrix*vec4(a_anchor_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float collision_perspective_ratio=clamp(0.5+0.5*(u_camera_to_center_distance/camera_to_anchor_distance),0.0,4.0);gl_Position=u_matrix*vec4(a_pos,0.0,1.0);gl_Position.xy+=(a_extrude+a_shift)*u_extrude_scale*gl_Position.w*collision_perspective_ratio;v_placed=a_placed.x;v_notUsed=a_placed.y;}\"),We=ci(\"uniform float u_overscale_factor;varying float v_placed;varying float v_notUsed;varying float v_radius;varying vec2 v_extrude;varying vec2 v_extrude_scale;void main() {float alpha=0.5;vec4 color=vec4(1.0,0.0,0.0,1.0)*alpha;if (v_placed > 0.5) {color=vec4(0.0,0.0,1.0,0.5)*alpha;}if (v_notUsed > 0.5) {color*=.2;}float extrude_scale_length=length(v_extrude_scale);float extrude_length=length(v_extrude)*extrude_scale_length;float stroke_width=15.0*extrude_scale_length/u_overscale_factor;float radius=v_radius*extrude_scale_length;float distance_to_edge=abs(extrude_length-radius);float opacity_t=smoothstep(-stroke_width,0.0,-distance_to_edge);gl_FragColor=opacity_t*color;}\",\"attribute vec2 a_pos;attribute vec2 a_anchor_pos;attribute vec2 a_extrude;attribute vec2 a_placed;uniform mat4 u_matrix;uniform vec2 u_extrude_scale;uniform float u_camera_to_center_distance;varying float v_placed;varying float v_notUsed;varying float v_radius;varying vec2 v_extrude;varying vec2 v_extrude_scale;void main() {vec4 projectedPoint=u_matrix*vec4(a_anchor_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float collision_perspective_ratio=clamp(0.5+0.5*(u_camera_to_center_distance/camera_to_anchor_distance),0.0,4.0);gl_Position=u_matrix*vec4(a_pos,0.0,1.0);highp float padding_factor=1.2;gl_Position.xy+=a_extrude*u_extrude_scale*padding_factor*gl_Position.w*collision_perspective_ratio;v_placed=a_placed.x;v_notUsed=a_placed.y;v_radius=abs(a_extrude.y);v_extrude=a_extrude*padding_factor;v_extrude_scale=u_extrude_scale*u_camera_to_center_distance*collision_perspective_ratio;}\"),Xe=ci(\"uniform highp vec4 u_color;void main() {gl_FragColor=u_color;}\",\"attribute vec2 a_pos;uniform mat4 u_matrix;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);}\"),He=ci(\"#pragma mapbox: define highp vec4 color\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 color\\n#pragma mapbox: initialize lowp float opacity\\ngl_FragColor=color*opacity;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"attribute vec2 a_pos;uniform mat4 u_matrix;\\n#pragma mapbox: define highp vec4 color\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 color\\n#pragma mapbox: initialize lowp float opacity\\ngl_Position=u_matrix*vec4(a_pos,0,1);}\"),Ke=ci(\"varying vec2 v_pos;\\n#pragma mapbox: define highp vec4 outline_color\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 outline_color\\n#pragma mapbox: initialize lowp float opacity\\nfloat dist=length(v_pos-gl_FragCoord.xy);float alpha=1.0-smoothstep(0.0,1.0,dist);gl_FragColor=outline_color*(alpha*opacity);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"attribute vec2 a_pos;uniform mat4 u_matrix;uniform vec2 u_world;varying vec2 v_pos;\\n#pragma mapbox: define highp vec4 outline_color\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 outline_color\\n#pragma mapbox: initialize lowp float opacity\\ngl_Position=u_matrix*vec4(a_pos,0,1);v_pos=(gl_Position.xy/gl_Position.w+1.0)/2.0*u_world;}\"),Ye=ci(\"uniform vec2 u_texsize;uniform sampler2D u_image;uniform float u_fade;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec2 v_pos;\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define lowp vec4 pattern_from\\n#pragma mapbox: define lowp vec4 pattern_to\\nvoid main() {\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize mediump vec4 pattern_from\\n#pragma mapbox: initialize mediump vec4 pattern_to\\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);float dist=length(v_pos-gl_FragCoord.xy);float alpha=1.0-smoothstep(0.0,1.0,dist);gl_FragColor=mix(color1,color2,u_fade)*alpha*opacity;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform vec2 u_world;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform vec4 u_scale;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec2 v_pos;\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define lowp vec4 pattern_from\\n#pragma mapbox: define lowp vec4 pattern_to\\nvoid main() {\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize mediump vec4 pattern_from\\n#pragma mapbox: initialize mediump vec4 pattern_to\\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float pixelRatio=u_scale.x;float tileRatio=u_scale.y;float fromScale=u_scale.z;float toScale=u_scale.w;gl_Position=u_matrix*vec4(a_pos,0,1);vec2 display_size_a=vec2((pattern_br_a.x-pattern_tl_a.x)/pixelRatio,(pattern_br_a.y-pattern_tl_a.y)/pixelRatio);vec2 display_size_b=vec2((pattern_br_b.x-pattern_tl_b.x)/pixelRatio,(pattern_br_b.y-pattern_tl_b.y)/pixelRatio);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileRatio,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileRatio,a_pos);v_pos=(gl_Position.xy/gl_Position.w+1.0)/2.0*u_world;}\"),Je=ci(\"uniform vec2 u_texsize;uniform float u_fade;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define lowp vec4 pattern_from\\n#pragma mapbox: define lowp vec4 pattern_to\\nvoid main() {\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize mediump vec4 pattern_from\\n#pragma mapbox: initialize mediump vec4 pattern_to\\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);gl_FragColor=mix(color1,color2,u_fade)*opacity;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform vec4 u_scale;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define lowp vec4 pattern_from\\n#pragma mapbox: define lowp vec4 pattern_to\\nvoid main() {\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize mediump vec4 pattern_from\\n#pragma mapbox: initialize mediump vec4 pattern_to\\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float pixelRatio=u_scale.x;float tileZoomRatio=u_scale.y;float fromScale=u_scale.z;float toScale=u_scale.w;vec2 display_size_a=vec2((pattern_br_a.x-pattern_tl_a.x)/pixelRatio,(pattern_br_a.y-pattern_tl_a.y)/pixelRatio);vec2 display_size_b=vec2((pattern_br_b.x-pattern_tl_b.x)/pixelRatio,(pattern_br_b.y-pattern_tl_b.y)/pixelRatio);gl_Position=u_matrix*vec4(a_pos,0,1);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileZoomRatio,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileZoomRatio,a_pos);}\"),Qe=ci(\"varying vec4 v_color;void main() {gl_FragColor=v_color;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp float u_lightintensity;uniform float u_vertical_gradient;uniform lowp float u_opacity;attribute vec2 a_pos;attribute vec4 a_normal_ed;varying vec4 v_color;\\n#pragma mapbox: define highp float base\\n#pragma mapbox: define highp float height\\n#pragma mapbox: define highp vec4 color\\nvoid main() {\\n#pragma mapbox: initialize highp float base\\n#pragma mapbox: initialize highp float height\\n#pragma mapbox: initialize highp vec4 color\\nvec3 normal=a_normal_ed.xyz;base=max(0.0,base);height=max(0.0,height);float t=mod(normal.x,2.0);gl_Position=u_matrix*vec4(a_pos,t > 0.0 ? height : base,1);float colorvalue=color.r*0.2126+color.g*0.7152+color.b*0.0722;v_color=vec4(0.0,0.0,0.0,1.0);vec4 ambientlight=vec4(0.03,0.03,0.03,1.0);color+=ambientlight;float directional=clamp(dot(normal/16384.0,u_lightpos),0.0,1.0);directional=mix((1.0-u_lightintensity),max((1.0-colorvalue+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_color.r+=clamp(color.r*directional*u_lightcolor.r,mix(0.0,0.3,1.0-u_lightcolor.r),1.0);v_color.g+=clamp(color.g*directional*u_lightcolor.g,mix(0.0,0.3,1.0-u_lightcolor.g),1.0);v_color.b+=clamp(color.b*directional*u_lightcolor.b,mix(0.0,0.3,1.0-u_lightcolor.b),1.0);v_color*=u_opacity;}\"),$e=ci(\"uniform vec2 u_texsize;uniform float u_fade;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec4 v_lighting;\\n#pragma mapbox: define lowp float base\\n#pragma mapbox: define lowp float height\\n#pragma mapbox: define lowp vec4 pattern_from\\n#pragma mapbox: define lowp vec4 pattern_to\\nvoid main() {\\n#pragma mapbox: initialize lowp float base\\n#pragma mapbox: initialize lowp float height\\n#pragma mapbox: initialize mediump vec4 pattern_from\\n#pragma mapbox: initialize mediump vec4 pattern_to\\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);vec4 mixedColor=mix(color1,color2,u_fade);gl_FragColor=mixedColor*v_lighting;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_height_factor;uniform vec4 u_scale;uniform float u_vertical_gradient;uniform lowp float u_opacity;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp float u_lightintensity;attribute vec2 a_pos;attribute vec4 a_normal_ed;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec4 v_lighting;\\n#pragma mapbox: define lowp float base\\n#pragma mapbox: define lowp float height\\n#pragma mapbox: define lowp vec4 pattern_from\\n#pragma mapbox: define lowp vec4 pattern_to\\nvoid main() {\\n#pragma mapbox: initialize lowp float base\\n#pragma mapbox: initialize lowp float height\\n#pragma mapbox: initialize mediump vec4 pattern_from\\n#pragma mapbox: initialize mediump vec4 pattern_to\\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float pixelRatio=u_scale.x;float tileRatio=u_scale.y;float fromScale=u_scale.z;float toScale=u_scale.w;vec3 normal=a_normal_ed.xyz;float edgedistance=a_normal_ed.w;vec2 display_size_a=vec2((pattern_br_a.x-pattern_tl_a.x)/pixelRatio,(pattern_br_a.y-pattern_tl_a.y)/pixelRatio);vec2 display_size_b=vec2((pattern_br_b.x-pattern_tl_b.x)/pixelRatio,(pattern_br_b.y-pattern_tl_b.y)/pixelRatio);base=max(0.0,base);height=max(0.0,height);float t=mod(normal.x,2.0);float z=t > 0.0 ? height : base;gl_Position=u_matrix*vec4(a_pos,z,1);vec2 pos=normal.x==1.0 && normal.y==0.0 && normal.z==16384.0\\n? a_pos\\n: vec2(edgedistance,z*u_height_factor);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileRatio,pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileRatio,pos);v_lighting=vec4(0.0,0.0,0.0,1.0);float directional=clamp(dot(normal/16383.0,u_lightpos),0.0,1.0);directional=mix((1.0-u_lightintensity),max((0.5+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_lighting.rgb+=clamp(directional*u_lightcolor,mix(vec3(0.0),vec3(0.3),1.0-u_lightcolor),vec3(1.0));v_lighting*=u_opacity;}\"),ti=ci(\"#ifdef GL_ES\\nprecision highp float;\\n#endif\\nuniform sampler2D u_image;varying vec2 v_pos;uniform vec2 u_dimension;uniform float u_zoom;uniform float u_maxzoom;float getElevation(vec2 coord,float bias) {vec4 data=texture2D(u_image,coord)*255.0;return (data.r+data.g*256.0+data.b*256.0*256.0)/4.0;}void main() {vec2 epsilon=1.0/u_dimension;float a=getElevation(v_pos+vec2(-epsilon.x,-epsilon.y),0.0);float b=getElevation(v_pos+vec2(0,-epsilon.y),0.0);float c=getElevation(v_pos+vec2(epsilon.x,-epsilon.y),0.0);float d=getElevation(v_pos+vec2(-epsilon.x,0),0.0);float e=getElevation(v_pos,0.0);float f=getElevation(v_pos+vec2(epsilon.x,0),0.0);float g=getElevation(v_pos+vec2(-epsilon.x,epsilon.y),0.0);float h=getElevation(v_pos+vec2(0,epsilon.y),0.0);float i=getElevation(v_pos+vec2(epsilon.x,epsilon.y),0.0);float exaggeration=u_zoom < 2.0 ? 0.4 : u_zoom < 4.5 ? 0.35 : 0.3;vec2 deriv=vec2((c+f+f+i)-(a+d+d+g),(g+h+h+i)-(a+b+b+c))/ pow(2.0,(u_zoom-u_maxzoom)*exaggeration+19.2562-u_zoom);gl_FragColor=clamp(vec4(deriv.x/2.0+0.5,deriv.y/2.0+0.5,1.0,1.0),0.0,1.0);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform vec2 u_dimension;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);highp vec2 epsilon=1.0/u_dimension;float scale=(u_dimension.x-2.0)/u_dimension.x;v_pos=(a_texture_pos/8192.0)*scale+epsilon;}\"),ei=ci(\"uniform sampler2D u_image;varying vec2 v_pos;uniform vec2 u_latrange;uniform vec2 u_light;uniform vec4 u_shadow;uniform vec4 u_highlight;uniform vec4 u_accent;\\n#define PI 3.141592653589793\\nvoid main() {vec4 pixel=texture2D(u_image,v_pos);vec2 deriv=((pixel.rg*2.0)-1.0);float scaleFactor=cos(radians((u_latrange[0]-u_latrange[1])*(1.0-v_pos.y)+u_latrange[1]));float slope=atan(1.25*length(deriv)/scaleFactor);float aspect=deriv.x !=0.0 ? atan(deriv.y,-deriv.x) : PI/2.0*(deriv.y > 0.0 ? 1.0 :-1.0);float intensity=u_light.x;float azimuth=u_light.y+PI;float base=1.875-intensity*1.75;float maxValue=0.5*PI;float scaledSlope=intensity !=0.5 ? ((pow(base,slope)-1.0)/(pow(base,maxValue)-1.0))*maxValue : slope;float accent=cos(scaledSlope);vec4 accent_color=(1.0-accent)*u_accent*clamp(intensity*2.0,0.0,1.0);float shade=abs(mod((aspect+azimuth)/PI+0.5,2.0)-1.0);vec4 shade_color=mix(u_shadow,u_highlight,shade)*sin(scaledSlope)*clamp(intensity*2.0,0.0,1.0);gl_FragColor=accent_color*(1.0-shade_color.a)+shade_color;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos=a_texture_pos/8192.0;}\"),ii=ci(\"uniform lowp float u_device_pixel_ratio;varying vec2 v_width2;varying vec2 v_normal;varying float v_gamma_scale;\\n#pragma mapbox: define highp vec4 color\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 color\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);gl_FragColor=color*(alpha*opacity);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"\\n#define scale 0.015873016\\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform vec2 u_units_to_pixels;uniform lowp float u_device_pixel_ratio;varying vec2 v_normal;varying vec2 v_width2;varying float v_gamma_scale;varying highp float v_linesofar;\\n#pragma mapbox: define highp vec4 color\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define mediump float gapwidth\\n#pragma mapbox: define lowp float offset\\n#pragma mapbox: define mediump float width\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 color\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize mediump float gapwidth\\n#pragma mapbox: initialize lowp float offset\\n#pragma mapbox: initialize mediump float width\\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;v_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*2.0;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_width2=vec2(outset,inset);}\"),oi=ci(\"uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;varying vec2 v_width2;varying vec2 v_normal;varying float v_gamma_scale;varying highp float v_lineprogress;\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture2D(u_image,vec2(v_lineprogress,0.5));gl_FragColor=color*(alpha*opacity);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"\\n#define MAX_LINE_DISTANCE 32767.0\\n#define scale 0.015873016\\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;varying vec2 v_normal;varying vec2 v_width2;varying float v_gamma_scale;varying highp float v_lineprogress;\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define mediump float gapwidth\\n#pragma mapbox: define lowp float offset\\n#pragma mapbox: define mediump float width\\nvoid main() {\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize mediump float gapwidth\\n#pragma mapbox: initialize lowp float offset\\n#pragma mapbox: initialize mediump float width\\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;v_lineprogress=(floor(a_data.z/4.0)+a_data.w*64.0)*2.0/MAX_LINE_DISTANCE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_width2=vec2(outset,inset);}\"),ri=ci(\"uniform lowp float u_device_pixel_ratio;uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec4 u_scale;uniform sampler2D u_image;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;\\n#pragma mapbox: define lowp vec4 pattern_from\\n#pragma mapbox: define lowp vec4 pattern_to\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize mediump vec4 pattern_from\\n#pragma mapbox: initialize mediump vec4 pattern_to\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float pixelRatio=u_scale.x;float tileZoomRatio=u_scale.y;float fromScale=u_scale.z;float toScale=u_scale.w;vec2 display_size_a=vec2((pattern_br_a.x-pattern_tl_a.x)/pixelRatio,(pattern_br_a.y-pattern_tl_a.y)/pixelRatio);vec2 display_size_b=vec2((pattern_br_b.x-pattern_tl_b.x)/pixelRatio,(pattern_br_b.y-pattern_tl_b.y)/pixelRatio);vec2 pattern_size_a=vec2(display_size_a.x*fromScale/tileZoomRatio,display_size_a.y);vec2 pattern_size_b=vec2(display_size_b.x*toScale/tileZoomRatio,display_size_b.y);float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float x_a=mod(v_linesofar/pattern_size_a.x,1.0);float x_b=mod(v_linesofar/pattern_size_b.x,1.0);float y_a=0.5+(v_normal.y*clamp(v_width2.s,0.0,(pattern_size_a.y+2.0)/2.0)/pattern_size_a.y);float y_b=0.5+(v_normal.y*clamp(v_width2.s,0.0,(pattern_size_b.y+2.0)/2.0)/pattern_size_b.y);vec2 pos_a=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,vec2(x_a,y_a));vec2 pos_b=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,vec2(x_b,y_b));vec4 color=mix(texture2D(u_image,pos_a),texture2D(u_image,pos_b),u_fade);gl_FragColor=color*alpha*opacity;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"\\n#define scale 0.015873016\\n#define LINE_DISTANCE_SCALE 2.0\\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform vec2 u_units_to_pixels;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define lowp float offset\\n#pragma mapbox: define mediump float gapwidth\\n#pragma mapbox: define mediump float width\\n#pragma mapbox: define lowp vec4 pattern_from\\n#pragma mapbox: define lowp vec4 pattern_to\\nvoid main() {\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize lowp float offset\\n#pragma mapbox: initialize mediump float gapwidth\\n#pragma mapbox: initialize mediump float width\\n#pragma mapbox: initialize mediump vec4 pattern_from\\n#pragma mapbox: initialize mediump vec4 pattern_to\\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_linesofar=a_linesofar;v_width2=vec2(outset,inset);}\"),ai=ci(\"uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;uniform float u_sdfgamma;uniform float u_mix;varying vec2 v_normal;varying vec2 v_width2;varying vec2 v_tex_a;varying vec2 v_tex_b;varying float v_gamma_scale;\\n#pragma mapbox: define highp vec4 color\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define mediump float width\\n#pragma mapbox: define lowp float floorwidth\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 color\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize mediump float width\\n#pragma mapbox: initialize lowp float floorwidth\\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float sdfdist_a=texture2D(u_image,v_tex_a).a;float sdfdist_b=texture2D(u_image,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);alpha*=smoothstep(0.5-u_sdfgamma/floorwidth,0.5+u_sdfgamma/floorwidth,sdfdist);gl_FragColor=color*(alpha*opacity);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"\\n#define scale 0.015873016\\n#define LINE_DISTANCE_SCALE 2.0\\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_patternscale_a;uniform float u_tex_y_a;uniform vec2 u_patternscale_b;uniform float u_tex_y_b;uniform vec2 u_units_to_pixels;varying vec2 v_normal;varying vec2 v_width2;varying vec2 v_tex_a;varying vec2 v_tex_b;varying float v_gamma_scale;\\n#pragma mapbox: define highp vec4 color\\n#pragma mapbox: define lowp float blur\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define mediump float gapwidth\\n#pragma mapbox: define lowp float offset\\n#pragma mapbox: define mediump float width\\n#pragma mapbox: define lowp float floorwidth\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 color\\n#pragma mapbox: initialize lowp float blur\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize mediump float gapwidth\\n#pragma mapbox: initialize lowp float offset\\n#pragma mapbox: initialize mediump float width\\n#pragma mapbox: initialize lowp float floorwidth\\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_tex_a=vec2(a_linesofar*u_patternscale_a.x/floorwidth,normal.y*u_patternscale_a.y+u_tex_y_a);v_tex_b=vec2(a_linesofar*u_patternscale_b.x/floorwidth,normal.y*u_patternscale_b.y+u_tex_y_b);v_width2=vec2(outset,inset);}\"),ni=ci(\"uniform float u_fade_t;uniform float u_opacity;uniform sampler2D u_image0;uniform sampler2D u_image1;varying vec2 v_pos0;varying vec2 v_pos1;uniform float u_brightness_low;uniform float u_brightness_high;uniform float u_saturation_factor;uniform float u_contrast_factor;uniform vec3 u_spin_weights;void main() {vec4 color0=texture2D(u_image0,v_pos0);vec4 color1=texture2D(u_image1,v_pos1);if (color0.a > 0.0) {color0.rgb=color0.rgb/color0.a;}if (color1.a > 0.0) {color1.rgb=color1.rgb/color1.a;}vec4 color=mix(color0,color1,u_fade_t);color.a*=u_opacity;vec3 rgb=color.rgb;rgb=vec3(dot(rgb,u_spin_weights.xyz),dot(rgb,u_spin_weights.zxy),dot(rgb,u_spin_weights.yzx));float average=(color.r+color.g+color.b)/3.0;rgb+=(average-rgb)*u_saturation_factor;rgb=(rgb-0.5)*u_contrast_factor+0.5;vec3 u_high_vec=vec3(u_brightness_low,u_brightness_low,u_brightness_low);vec3 u_low_vec=vec3(u_brightness_high,u_brightness_high,u_brightness_high);gl_FragColor=vec4(mix(u_high_vec,u_low_vec,rgb)*color.a,color.a);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"uniform mat4 u_matrix;uniform vec2 u_tl_parent;uniform float u_scale_parent;uniform float u_buffer_scale;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos0;varying vec2 v_pos1;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos0=(((a_texture_pos/8192.0)-0.5)/u_buffer_scale )+0.5;v_pos1=(v_pos0*u_scale_parent)+u_tl_parent;}\"),si=ci(\"uniform sampler2D u_texture;varying vec2 v_tex;varying float v_fade_opacity;\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize lowp float opacity\\nlowp float alpha=opacity*v_fade_opacity;gl_FragColor=texture2D(u_texture,v_tex)*alpha;\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform highp float u_camera_to_center_distance;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform float u_fade_change;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform vec2 u_texsize;varying vec2 v_tex;varying float v_fade_opacity;\\n#pragma mapbox: define lowp float opacity\\nvoid main() {\\n#pragma mapbox: initialize lowp float opacity\\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size[0],a_size[1],u_size_t)/256.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size[0]/256.0;} else if (!u_is_size_zoom_constant && u_is_size_feature_constant) {size=u_size;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\\ncamera_to_anchor_distance/u_camera_to_center_distance :\\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*fontScale),0.0,1.0);v_tex=a_tex/u_texsize;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;v_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));}\"),li=ci(\"#define SDF_PX 8.0\\nuniform bool u_is_halo;uniform sampler2D u_texture;uniform highp float u_gamma_scale;uniform lowp float u_device_pixel_ratio;uniform bool u_is_text;varying vec2 v_data0;varying vec3 v_data1;\\n#pragma mapbox: define highp vec4 fill_color\\n#pragma mapbox: define highp vec4 halo_color\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define lowp float halo_width\\n#pragma mapbox: define lowp float halo_blur\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 fill_color\\n#pragma mapbox: initialize highp vec4 halo_color\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize lowp float halo_width\\n#pragma mapbox: initialize lowp float halo_blur\\nfloat EDGE_GAMMA=0.105/u_device_pixel_ratio;vec2 tex=v_data0.xy;float gamma_scale=v_data1.x;float size=v_data1.y;float fade_opacity=v_data1[2];float fontScale=u_is_text ? size/24.0 : size;lowp vec4 color=fill_color;highp float gamma=EDGE_GAMMA/(fontScale*u_gamma_scale);lowp float buff=(256.0-64.0)/256.0;if (u_is_halo) {color=halo_color;gamma=(halo_blur*1.19/SDF_PX+EDGE_GAMMA)/(fontScale*u_gamma_scale);buff=(6.0-halo_width/fontScale)/SDF_PX;}lowp float dist=texture2D(u_texture,tex).a;highp float gamma_scaled=gamma*gamma_scale;highp float alpha=smoothstep(buff-gamma_scaled,buff+gamma_scaled,dist);gl_FragColor=color*(alpha*opacity*fade_opacity);\\n#ifdef OVERDRAW_INSPECTOR\\ngl_FragColor=vec4(1.0);\\n#endif\\n}\",\"const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform highp float u_camera_to_center_distance;uniform float u_fade_change;uniform vec2 u_texsize;varying vec2 v_data0;varying vec3 v_data1;\\n#pragma mapbox: define highp vec4 fill_color\\n#pragma mapbox: define highp vec4 halo_color\\n#pragma mapbox: define lowp float opacity\\n#pragma mapbox: define lowp float halo_width\\n#pragma mapbox: define lowp float halo_blur\\nvoid main() {\\n#pragma mapbox: initialize highp vec4 fill_color\\n#pragma mapbox: initialize highp vec4 halo_color\\n#pragma mapbox: initialize lowp float opacity\\n#pragma mapbox: initialize lowp float halo_width\\n#pragma mapbox: initialize lowp float halo_blur\\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size[0],a_size[1],u_size_t)/256.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size[0]/256.0;} else if (!u_is_size_zoom_constant && u_is_size_feature_constant) {size=u_size;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\\ncamera_to_anchor_distance/u_camera_to_center_distance :\\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*fontScale),0.0,1.0);float gamma_scale=gl_Position.w;vec2 tex=a_tex/u_texsize;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;float interpolated_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));v_data0=vec2(tex.x,tex.y);v_data1=vec3(gamma_scale,size,interpolated_fade_opacity);}\");function ci(t,e){var i=/#pragma mapbox: ([\\w]+) ([\\w]+) ([\\w]+) ([\\w]+)/g,o={};return {fragmentSource:t=t.replace(i,function(t,e,i,r,a){return o[a]=!0,\"define\"===e?\"\\n#ifndef HAS_UNIFORM_u_\"+a+\"\\nvarying \"+i+\" \"+r+\" \"+a+\";\\n#else\\nuniform \"+i+\" \"+r+\" u_\"+a+\";\\n#endif\\n\":\"\\n#ifdef HAS_UNIFORM_u_\"+a+\"\\n    \"+i+\" \"+r+\" \"+a+\" = u_\"+a+\";\\n#endif\\n\"}),vertexSource:e=e.replace(i,function(t,e,i,r,a){var n=\"float\"===r?\"vec2\":\"vec4\",s=a.match(/color/)?\"color\":n;return o[a]?\"define\"===e?\"\\n#ifndef HAS_UNIFORM_u_\"+a+\"\\nuniform lowp float u_\"+a+\"_t;\\nattribute \"+i+\" \"+n+\" a_\"+a+\";\\nvarying \"+i+\" \"+r+\" \"+a+\";\\n#else\\nuniform \"+i+\" \"+r+\" u_\"+a+\";\\n#endif\\n\":\"vec4\"===s?\"\\n#ifndef HAS_UNIFORM_u_\"+a+\"\\n    \"+a+\" = a_\"+a+\";\\n#else\\n    \"+i+\" \"+r+\" \"+a+\" = u_\"+a+\";\\n#endif\\n\":\"\\n#ifndef HAS_UNIFORM_u_\"+a+\"\\n    \"+a+\" = unpack_mix_\"+s+\"(a_\"+a+\", u_\"+a+\"_t);\\n#else\\n    \"+i+\" \"+r+\" \"+a+\" = u_\"+a+\";\\n#endif\\n\":\"define\"===e?\"\\n#ifndef HAS_UNIFORM_u_\"+a+\"\\nuniform lowp float u_\"+a+\"_t;\\nattribute \"+i+\" \"+n+\" a_\"+a+\";\\n#else\\nuniform \"+i+\" \"+r+\" u_\"+a+\";\\n#endif\\n\":\"vec4\"===s?\"\\n#ifndef HAS_UNIFORM_u_\"+a+\"\\n    \"+i+\" \"+r+\" \"+a+\" = a_\"+a+\";\\n#else\\n    \"+i+\" \"+r+\" \"+a+\" = u_\"+a+\";\\n#endif\\n\":\"\\n#ifndef HAS_UNIFORM_u_\"+a+\"\\n    \"+i+\" \"+r+\" \"+a+\" = unpack_mix_\"+s+\"(a_\"+a+\", u_\"+a+\"_t);\\n#else\\n    \"+i+\" \"+r+\" \"+a+\" = u_\"+a+\";\\n#endif\\n\"})}}var ui=Object.freeze({prelude:Fe,background:Ue,backgroundPattern:Ne,circle:Ze,clippingMask:je,heatmap:qe,heatmapTexture:Ve,collisionBox:Ge,collisionCircle:We,debug:Xe,fill:He,fillOutline:Ke,fillOutlinePattern:Ye,fillPattern:Je,fillExtrusion:Qe,fillExtrusionPattern:$e,hillshadePrepare:ti,hillshade:ei,line:ii,lineGradient:oi,linePattern:ri,lineSDF:ai,raster:ni,symbolIcon:si,symbolSDF:li}),hi=function(){this.boundProgram=null,this.boundLayoutVertexBuffer=null,this.boundPaintVertexBuffers=[],this.boundIndexBuffer=null,this.boundVertexOffset=null,this.boundDynamicVertexBuffer=null,this.vao=null;};hi.prototype.bind=function(t,e,i,o,r,a,n,s){this.context=t;for(var l=this.boundPaintVertexBuffers.length!==o.length,c=0;!l&&c<o.length;c++)this.boundPaintVertexBuffers[c]!==o[c]&&(l=!0);var u=!this.vao||this.boundProgram!==e||this.boundLayoutVertexBuffer!==i||l||this.boundIndexBuffer!==r||this.boundVertexOffset!==a||this.boundDynamicVertexBuffer!==n||this.boundDynamicVertexBuffer2!==s;!t.extVertexArrayObject||u?this.freshBind(e,i,o,r,a,n,s):(t.bindVertexArrayOES.set(this.vao),n&&n.bind(),r&&r.dynamicDraw&&r.bind(),s&&s.bind());},hi.prototype.freshBind=function(t,e,i,o,r,a,n){var s,l=t.numAttributes,c=this.context,u=c.gl;if(c.extVertexArrayObject)this.vao&&this.destroy(),this.vao=c.extVertexArrayObject.createVertexArrayOES(),c.bindVertexArrayOES.set(this.vao),s=0,this.boundProgram=t,this.boundLayoutVertexBuffer=e,this.boundPaintVertexBuffers=i,this.boundIndexBuffer=o,this.boundVertexOffset=r,this.boundDynamicVertexBuffer=a,this.boundDynamicVertexBuffer2=n;else{s=c.currentNumAttributes||0;for(var h=l;h<s;h++)u.disableVertexAttribArray(h);}e.enableAttributes(u,t);for(var p=0,d=i;p<d.length;p+=1){d[p].enableAttributes(u,t);}a&&a.enableAttributes(u,t),n&&n.enableAttributes(u,t),e.bind(),e.setVertexAttribPointers(u,t,r);for(var _=0,f=i;_<f.length;_+=1){var m=f[_];m.bind(),m.setVertexAttribPointers(u,t,r);}a&&(a.bind(),a.setVertexAttribPointers(u,t,r)),o&&o.bind(),n&&(n.bind(),n.setVertexAttribPointers(u,t,r)),c.currentNumAttributes=l;},hi.prototype.destroy=function(){this.vao&&(this.context.extVertexArrayObject.deleteVertexArrayOES(this.vao),this.vao=null);};var pi=function(t,e,i,o,r){var a=t.gl;this.program=a.createProgram();var n=i.defines();r&&n.push(\"#define OVERDRAW_INSPECTOR;\");var s=n.concat(Fe.fragmentSource,e.fragmentSource).join(\"\\n\"),l=n.concat(Fe.vertexSource,e.vertexSource).join(\"\\n\"),c=a.createShader(a.FRAGMENT_SHADER);a.shaderSource(c,s),a.compileShader(c),a.attachShader(this.program,c);var u=a.createShader(a.VERTEX_SHADER);a.shaderSource(u,l),a.compileShader(u),a.attachShader(this.program,u);for(var h=i.layoutAttributes||[],p=0;p<h.length;p++)a.bindAttribLocation(this.program,p,h[p].name);a.linkProgram(this.program),this.numAttributes=a.getProgramParameter(this.program,a.ACTIVE_ATTRIBUTES),this.attributes={};for(var d={},_=0;_<this.numAttributes;_++){var f=a.getActiveAttrib(this.program,_);f&&(this.attributes[f.name]=a.getAttribLocation(this.program,f.name));}for(var m=a.getProgramParameter(this.program,a.ACTIVE_UNIFORMS),g=0;g<m;g++){var v=a.getActiveUniform(this.program,g);v&&(d[v.name]=a.getUniformLocation(this.program,v.name));}this.fixedUniforms=o(t,d),this.binderUniforms=i.getUniforms(t,d);};function di(e,i,o){var r=1/ce(o,1,i.transform.tileZoom),a=Math.pow(2,o.tileID.overscaledZ),n=o.tileSize*Math.pow(2,i.transform.tileZoom)/a,s=n*(o.tileID.canonical.x+o.tileID.wrap*a),l=n*o.tileID.canonical.y;return {u_image:0,u_texsize:o.imageAtlasTexture.size,u_scale:[t.browser.devicePixelRatio,r,e.fromScale,e.toScale],u_fade:e.t,u_pixel_coord_upper:[s>>16,l>>16],u_pixel_coord_lower:[65535&s,65535&l]}}pi.prototype.draw=function(t,e,i,o,r,a,n,s,l,c,u,h,p,d,_,f){var m,g=t.gl;for(var v in t.program.set(this.program),t.setDepthMode(i),t.setStencilMode(o),t.setColorMode(r),t.setCullFace(a),this.fixedUniforms)this.fixedUniforms[v].set(n[v]);d&&d.setUniforms(t,this.binderUniforms,h,{zoom:p});for(var y=(m={},m[g.LINES]=2,m[g.TRIANGLES]=3,m[g.LINE_STRIP]=1,m)[e],x=0,b=u.get();x<b.length;x+=1){var w=b[x],E=w.vaos||(w.vaos={});(E[s]||(E[s]=new hi)).bind(t,this,l,d?d.getPaintVertexBuffers():[],c,w.vertexOffset,_,f),g.drawElements(e,w.primitiveLength*y,g.UNSIGNED_SHORT,w.primitiveOffset*y*2);}};var _i=function(e,i,o,r){var a=i.style.light,n=a.properties.get(\"position\"),s=[n.x,n.y,n.z],l=t.create$1();\"viewport\"===a.properties.get(\"anchor\")&&t.fromRotation(l,-i.transform.angle),t.transformMat3(s,s,l);var c=a.properties.get(\"color\");return {u_matrix:e,u_lightpos:s,u_lightintensity:a.properties.get(\"intensity\"),u_lightcolor:[c.r,c.g,c.b],u_vertical_gradient:+o,u_opacity:r}},fi=function(e,i,o,r,a,n,s){return t.extend(_i(e,i,o,r),di(n,i,s),{u_height_factor:-Math.pow(2,a.overscaledZ)/s.tileSize/8})},mi=function(t){return {u_matrix:t}},gi=function(e,i,o,r){return t.extend(mi(e),di(o,i,r))},vi=function(t,e){return {u_matrix:t,u_world:e}},yi=function(e,i,o,r,a){return t.extend(gi(e,i,o,r),{u_world:a})},xi=function(e,i,o,r){var a,n,s=e.transform;if(\"map\"===r.paint.get(\"circle-pitch-alignment\")){var l=ce(o,1,s.zoom);a=!0,n=[l,l];}else a=!1,n=s.pixelsToGLUnits;return {u_camera_to_center_distance:s.cameraToCenterDistance,u_scale_with_map:+(\"map\"===r.paint.get(\"circle-pitch-scale\")),u_matrix:e.translatePosMatrix(i.posMatrix,o,r.paint.get(\"circle-translate\"),r.paint.get(\"circle-translate-anchor\")),u_pitch_with_map:+a,u_device_pixel_ratio:t.browser.devicePixelRatio,u_extrude_scale:n}},bi=function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_camera_to_center_distance:new t.Uniform1f(e,i.u_camera_to_center_distance),u_pixels_to_tile_units:new t.Uniform1f(e,i.u_pixels_to_tile_units),u_extrude_scale:new t.Uniform2f(e,i.u_extrude_scale),u_overscale_factor:new t.Uniform1f(e,i.u_overscale_factor)}},wi=function(t,e,i){var o=ce(i,1,e.zoom),r=Math.pow(2,e.zoom-i.tileID.overscaledZ),a=i.tileID.overscaleFactor();return {u_matrix:t,u_camera_to_center_distance:e.cameraToCenterDistance,u_pixels_to_tile_units:o,u_extrude_scale:[e.pixelsToGLUnits[0]/(o*r),e.pixelsToGLUnits[1]/(o*r)],u_overscale_factor:a}},Ei=function(t,e){return {u_matrix:t,u_color:e}},Ti=function(t){return {u_matrix:t}},Ii=function(t,e,i,o){return {u_matrix:t,u_extrude_scale:ce(e,1,i),u_intensity:o}},Ci=function(e,i,o,r){var a=t.create();t.ortho(a,0,e.width,e.height,0,0,1);var n=e.context.gl;return {u_matrix:a,u_world:[n.drawingBufferWidth,n.drawingBufferHeight],u_image:o,u_color_ramp:r,u_opacity:i.paint.get(\"heatmap-opacity\")}},Si=function(t,e,i){var o=i.paint.get(\"hillshade-shadow-color\"),r=i.paint.get(\"hillshade-highlight-color\"),a=i.paint.get(\"hillshade-accent-color\"),n=i.paint.get(\"hillshade-illumination-direction\")*(Math.PI/180);\"viewport\"===i.paint.get(\"hillshade-illumination-anchor\")&&(n-=t.transform.angle);var s=!t.options.moving;return {u_matrix:t.transform.calculatePosMatrix(e.tileID.toUnwrapped(),s),u_image:0,u_latrange:zi(t,e.tileID),u_light:[i.paint.get(\"hillshade-exaggeration\"),n],u_shadow:o,u_highlight:r,u_accent:a}},Pi=function(e,i){var o=e.dem.stride,r=t.create();return t.ortho(r,0,t.EXTENT,-t.EXTENT,0,0,1),t.translate(r,r,[0,-t.EXTENT,0]),{u_matrix:r,u_image:1,u_dimension:[o,o],u_zoom:e.tileID.overscaledZ,u_maxzoom:i}};function zi(e,i){var o=Math.pow(2,i.canonical.z),r=i.canonical.y;return [new t.MercatorCoordinate(0,r/o).toLngLat().lat,new t.MercatorCoordinate(0,(r+1)/o).toLngLat().lat]}var Li=function(e,i,o){var r=e.transform;return {u_matrix:ki(e,i,o),u_ratio:1/ce(i,1,r.zoom),u_device_pixel_ratio:t.browser.devicePixelRatio,u_units_to_pixels:[1/r.pixelsToGLUnits[0],1/r.pixelsToGLUnits[1]]}},Di=function(e,i,o){return t.extend(Li(e,i,o),{u_image:0})},Mi=function(e,i,o,r){var a=e.transform,n=Ai(i,a);return {u_matrix:ki(e,i,o),u_texsize:i.imageAtlasTexture.size,u_ratio:1/ce(i,1,a.zoom),u_device_pixel_ratio:t.browser.devicePixelRatio,u_image:0,u_scale:[t.browser.devicePixelRatio,n,r.fromScale,r.toScale],u_fade:r.t,u_units_to_pixels:[1/a.pixelsToGLUnits[0],1/a.pixelsToGLUnits[1]]}},Ri=function(e,i,o,r,a){var n=e.transform,s=e.lineAtlas,l=Ai(i,n),c=\"round\"===o.layout.get(\"line-cap\"),u=s.getDash(r.from,c),h=s.getDash(r.to,c),p=u.width*a.fromScale,d=h.width*a.toScale;return t.extend(Li(e,i,o),{u_patternscale_a:[l/p,-u.height/2],u_patternscale_b:[l/d,-h.height/2],u_sdfgamma:s.width/(256*Math.min(p,d)*t.browser.devicePixelRatio)/2,u_image:0,u_tex_y_a:u.y,u_tex_y_b:h.y,u_mix:a.t})};function Ai(t,e){return 1/ce(t,1,e.tileZoom)}function ki(t,e,i){return t.translatePosMatrix(e.tileID.posMatrix,e,i.paint.get(\"line-translate\"),i.paint.get(\"line-translate-anchor\"))}var Bi=function(t,e,i,o,r){return {u_matrix:t,u_tl_parent:e,u_scale_parent:i,u_buffer_scale:1,u_fade_t:o.mix,u_opacity:o.opacity*r.paint.get(\"raster-opacity\"),u_image0:0,u_image1:1,u_brightness_low:r.paint.get(\"raster-brightness-min\"),u_brightness_high:r.paint.get(\"raster-brightness-max\"),u_saturation_factor:(n=r.paint.get(\"raster-saturation\"),n>0?1-1/(1.001-n):-n),u_contrast_factor:(a=r.paint.get(\"raster-contrast\"),a>0?1/(1-a):1+a),u_spin_weights:Oi(r.paint.get(\"raster-hue-rotate\"))};var a,n;};function Oi(t){t*=Math.PI/180;var e=Math.sin(t),i=Math.cos(t);return [(2*i+1)/3,(-Math.sqrt(3)*e-i+1)/3,(Math.sqrt(3)*e-i+1)/3]}var Fi=function(t,e,i,o,r,a,n,s,l,c){var u=r.transform;return {u_is_size_zoom_constant:+(\"constant\"===t||\"source\"===t),u_is_size_feature_constant:+(\"constant\"===t||\"camera\"===t),u_size_t:e?e.uSizeT:0,u_size:e?e.uSize:0,u_camera_to_center_distance:u.cameraToCenterDistance,u_pitch:u.pitch/360*2*Math.PI,u_rotate_symbol:+i,u_aspect_ratio:u.width/u.height,u_fade_change:r.options.fadeDuration?r.symbolFadeChange:1,u_matrix:a,u_label_plane_matrix:n,u_coord_matrix:s,u_is_text:+l,u_pitch_with_map:+o,u_texsize:c,u_texture:0}},Ui=function(e,i,o,r,a,n,s,l,c,u,h){var p=a.transform;return t.extend(Fi(e,i,o,r,a,n,s,l,c,u),{u_gamma_scale:r?Math.cos(p._pitch)*p.cameraToCenterDistance:1,u_device_pixel_ratio:t.browser.devicePixelRatio,u_is_halo:+h})},Ni=function(t,e,i){return {u_matrix:t,u_opacity:e,u_color:i}},Zi=function(e,i,o,r,a,n){return t.extend(function(t,e,i,o){var r=i.imageManager.getPattern(t.from),a=i.imageManager.getPattern(t.to),n=i.imageManager.getPixelSize(),s=n.width,l=n.height,c=Math.pow(2,o.tileID.overscaledZ),u=o.tileSize*Math.pow(2,i.transform.tileZoom)/c,h=u*(o.tileID.canonical.x+o.tileID.wrap*c),p=u*o.tileID.canonical.y;return {u_image:0,u_pattern_tl_a:r.tl,u_pattern_br_a:r.br,u_pattern_tl_b:a.tl,u_pattern_br_b:a.br,u_texsize:[s,l],u_mix:e.t,u_pattern_size_a:r.displaySize,u_pattern_size_b:a.displaySize,u_scale_a:e.fromScale,u_scale_b:e.toScale,u_tile_units_to_pixels:1/ce(o,1,i.transform.tileZoom),u_pixel_coord_upper:[h>>16,p>>16],u_pixel_coord_lower:[65535&h,65535&p]}}(r,n,o,a),{u_matrix:e,u_opacity:i})},ji={fillExtrusion:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_lightpos:new t.Uniform3f(e,i.u_lightpos),u_lightintensity:new t.Uniform1f(e,i.u_lightintensity),u_lightcolor:new t.Uniform3f(e,i.u_lightcolor),u_vertical_gradient:new t.Uniform1f(e,i.u_vertical_gradient),u_opacity:new t.Uniform1f(e,i.u_opacity)}},fillExtrusionPattern:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_lightpos:new t.Uniform3f(e,i.u_lightpos),u_lightintensity:new t.Uniform1f(e,i.u_lightintensity),u_lightcolor:new t.Uniform3f(e,i.u_lightcolor),u_vertical_gradient:new t.Uniform1f(e,i.u_vertical_gradient),u_height_factor:new t.Uniform1f(e,i.u_height_factor),u_image:new t.Uniform1i(e,i.u_image),u_texsize:new t.Uniform2f(e,i.u_texsize),u_pixel_coord_upper:new t.Uniform2f(e,i.u_pixel_coord_upper),u_pixel_coord_lower:new t.Uniform2f(e,i.u_pixel_coord_lower),u_scale:new t.Uniform4f(e,i.u_scale),u_fade:new t.Uniform1f(e,i.u_fade),u_opacity:new t.Uniform1f(e,i.u_opacity)}},fill:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix)}},fillPattern:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_image:new t.Uniform1i(e,i.u_image),u_texsize:new t.Uniform2f(e,i.u_texsize),u_pixel_coord_upper:new t.Uniform2f(e,i.u_pixel_coord_upper),u_pixel_coord_lower:new t.Uniform2f(e,i.u_pixel_coord_lower),u_scale:new t.Uniform4f(e,i.u_scale),u_fade:new t.Uniform1f(e,i.u_fade)}},fillOutline:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_world:new t.Uniform2f(e,i.u_world)}},fillOutlinePattern:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_world:new t.Uniform2f(e,i.u_world),u_image:new t.Uniform1i(e,i.u_image),u_texsize:new t.Uniform2f(e,i.u_texsize),u_pixel_coord_upper:new t.Uniform2f(e,i.u_pixel_coord_upper),u_pixel_coord_lower:new t.Uniform2f(e,i.u_pixel_coord_lower),u_scale:new t.Uniform4f(e,i.u_scale),u_fade:new t.Uniform1f(e,i.u_fade)}},circle:function(e,i){return {u_camera_to_center_distance:new t.Uniform1f(e,i.u_camera_to_center_distance),u_scale_with_map:new t.Uniform1i(e,i.u_scale_with_map),u_pitch_with_map:new t.Uniform1i(e,i.u_pitch_with_map),u_extrude_scale:new t.Uniform2f(e,i.u_extrude_scale),u_device_pixel_ratio:new t.Uniform1f(e,i.u_device_pixel_ratio),u_matrix:new t.UniformMatrix4f(e,i.u_matrix)}},collisionBox:bi,collisionCircle:bi,debug:function(e,i){return {u_color:new t.UniformColor(e,i.u_color),u_matrix:new t.UniformMatrix4f(e,i.u_matrix)}},clippingMask:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix)}},heatmap:function(e,i){return {u_extrude_scale:new t.Uniform1f(e,i.u_extrude_scale),u_intensity:new t.Uniform1f(e,i.u_intensity),u_matrix:new t.UniformMatrix4f(e,i.u_matrix)}},heatmapTexture:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_world:new t.Uniform2f(e,i.u_world),u_image:new t.Uniform1i(e,i.u_image),u_color_ramp:new t.Uniform1i(e,i.u_color_ramp),u_opacity:new t.Uniform1f(e,i.u_opacity)}},hillshade:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_image:new t.Uniform1i(e,i.u_image),u_latrange:new t.Uniform2f(e,i.u_latrange),u_light:new t.Uniform2f(e,i.u_light),u_shadow:new t.UniformColor(e,i.u_shadow),u_highlight:new t.UniformColor(e,i.u_highlight),u_accent:new t.UniformColor(e,i.u_accent)}},hillshadePrepare:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_image:new t.Uniform1i(e,i.u_image),u_dimension:new t.Uniform2f(e,i.u_dimension),u_zoom:new t.Uniform1f(e,i.u_zoom),u_maxzoom:new t.Uniform1f(e,i.u_maxzoom)}},line:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_ratio:new t.Uniform1f(e,i.u_ratio),u_device_pixel_ratio:new t.Uniform1f(e,i.u_device_pixel_ratio),u_units_to_pixels:new t.Uniform2f(e,i.u_units_to_pixels)}},lineGradient:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_ratio:new t.Uniform1f(e,i.u_ratio),u_device_pixel_ratio:new t.Uniform1f(e,i.u_device_pixel_ratio),u_units_to_pixels:new t.Uniform2f(e,i.u_units_to_pixels),u_image:new t.Uniform1i(e,i.u_image)}},linePattern:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_texsize:new t.Uniform2f(e,i.u_texsize),u_ratio:new t.Uniform1f(e,i.u_ratio),u_device_pixel_ratio:new t.Uniform1f(e,i.u_device_pixel_ratio),u_image:new t.Uniform1i(e,i.u_image),u_units_to_pixels:new t.Uniform2f(e,i.u_units_to_pixels),u_scale:new t.Uniform4f(e,i.u_scale),u_fade:new t.Uniform1f(e,i.u_fade)}},lineSDF:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_ratio:new t.Uniform1f(e,i.u_ratio),u_device_pixel_ratio:new t.Uniform1f(e,i.u_device_pixel_ratio),u_units_to_pixels:new t.Uniform2f(e,i.u_units_to_pixels),u_patternscale_a:new t.Uniform2f(e,i.u_patternscale_a),u_patternscale_b:new t.Uniform2f(e,i.u_patternscale_b),u_sdfgamma:new t.Uniform1f(e,i.u_sdfgamma),u_image:new t.Uniform1i(e,i.u_image),u_tex_y_a:new t.Uniform1f(e,i.u_tex_y_a),u_tex_y_b:new t.Uniform1f(e,i.u_tex_y_b),u_mix:new t.Uniform1f(e,i.u_mix)}},raster:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_tl_parent:new t.Uniform2f(e,i.u_tl_parent),u_scale_parent:new t.Uniform1f(e,i.u_scale_parent),u_buffer_scale:new t.Uniform1f(e,i.u_buffer_scale),u_fade_t:new t.Uniform1f(e,i.u_fade_t),u_opacity:new t.Uniform1f(e,i.u_opacity),u_image0:new t.Uniform1i(e,i.u_image0),u_image1:new t.Uniform1i(e,i.u_image1),u_brightness_low:new t.Uniform1f(e,i.u_brightness_low),u_brightness_high:new t.Uniform1f(e,i.u_brightness_high),u_saturation_factor:new t.Uniform1f(e,i.u_saturation_factor),u_contrast_factor:new t.Uniform1f(e,i.u_contrast_factor),u_spin_weights:new t.Uniform3f(e,i.u_spin_weights)}},symbolIcon:function(e,i){return {u_is_size_zoom_constant:new t.Uniform1i(e,i.u_is_size_zoom_constant),u_is_size_feature_constant:new t.Uniform1i(e,i.u_is_size_feature_constant),u_size_t:new t.Uniform1f(e,i.u_size_t),u_size:new t.Uniform1f(e,i.u_size),u_camera_to_center_distance:new t.Uniform1f(e,i.u_camera_to_center_distance),u_pitch:new t.Uniform1f(e,i.u_pitch),u_rotate_symbol:new t.Uniform1i(e,i.u_rotate_symbol),u_aspect_ratio:new t.Uniform1f(e,i.u_aspect_ratio),u_fade_change:new t.Uniform1f(e,i.u_fade_change),u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_label_plane_matrix:new t.UniformMatrix4f(e,i.u_label_plane_matrix),u_coord_matrix:new t.UniformMatrix4f(e,i.u_coord_matrix),u_is_text:new t.Uniform1f(e,i.u_is_text),u_pitch_with_map:new t.Uniform1i(e,i.u_pitch_with_map),u_texsize:new t.Uniform2f(e,i.u_texsize),u_texture:new t.Uniform1i(e,i.u_texture)}},symbolSDF:function(e,i){return {u_is_size_zoom_constant:new t.Uniform1i(e,i.u_is_size_zoom_constant),u_is_size_feature_constant:new t.Uniform1i(e,i.u_is_size_feature_constant),u_size_t:new t.Uniform1f(e,i.u_size_t),u_size:new t.Uniform1f(e,i.u_size),u_camera_to_center_distance:new t.Uniform1f(e,i.u_camera_to_center_distance),u_pitch:new t.Uniform1f(e,i.u_pitch),u_rotate_symbol:new t.Uniform1i(e,i.u_rotate_symbol),u_aspect_ratio:new t.Uniform1f(e,i.u_aspect_ratio),u_fade_change:new t.Uniform1f(e,i.u_fade_change),u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_label_plane_matrix:new t.UniformMatrix4f(e,i.u_label_plane_matrix),u_coord_matrix:new t.UniformMatrix4f(e,i.u_coord_matrix),u_is_text:new t.Uniform1f(e,i.u_is_text),u_pitch_with_map:new t.Uniform1i(e,i.u_pitch_with_map),u_texsize:new t.Uniform2f(e,i.u_texsize),u_texture:new t.Uniform1i(e,i.u_texture),u_gamma_scale:new t.Uniform1f(e,i.u_gamma_scale),u_device_pixel_ratio:new t.Uniform1f(e,i.u_device_pixel_ratio),u_is_halo:new t.Uniform1f(e,i.u_is_halo)}},background:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_opacity:new t.Uniform1f(e,i.u_opacity),u_color:new t.UniformColor(e,i.u_color)}},backgroundPattern:function(e,i){return {u_matrix:new t.UniformMatrix4f(e,i.u_matrix),u_opacity:new t.Uniform1f(e,i.u_opacity),u_image:new t.Uniform1i(e,i.u_image),u_pattern_tl_a:new t.Uniform2f(e,i.u_pattern_tl_a),u_pattern_br_a:new t.Uniform2f(e,i.u_pattern_br_a),u_pattern_tl_b:new t.Uniform2f(e,i.u_pattern_tl_b),u_pattern_br_b:new t.Uniform2f(e,i.u_pattern_br_b),u_texsize:new t.Uniform2f(e,i.u_texsize),u_mix:new t.Uniform1f(e,i.u_mix),u_pattern_size_a:new t.Uniform2f(e,i.u_pattern_size_a),u_pattern_size_b:new t.Uniform2f(e,i.u_pattern_size_b),u_scale_a:new t.Uniform1f(e,i.u_scale_a),u_scale_b:new t.Uniform1f(e,i.u_scale_b),u_pixel_coord_upper:new t.Uniform2f(e,i.u_pixel_coord_upper),u_pixel_coord_lower:new t.Uniform2f(e,i.u_pixel_coord_lower),u_tile_units_to_pixels:new t.Uniform1f(e,i.u_tile_units_to_pixels)}}};function qi(e,i){for(var o=e.sort(function(t,e){return t.tileID.isLessThan(e.tileID)?-1:e.tileID.isLessThan(t.tileID)?1:0}),r=0;r<o.length;r++){var a={},n=o[r],s=o.slice(r+1);Vi(n.tileID.wrapped(),n.tileID,s,new t.OverscaledTileID(0,n.tileID.wrap+1,0,0,0),a),n.setMask(a,i);}}function Vi(e,i,o,r,a){for(var n=0;n<o.length;n++){var s=o[n];if(r.isLessThan(s.tileID))break;if(i.key===s.tileID.key)return;if(s.tileID.isChildOf(i)){for(var l=i.children(1/0),c=0;c<l.length;c++){Vi(e,l[c],o.slice(n),r,a);}return}}var u=i.overscaledZ-e.overscaledZ,h=new t.CanonicalTileID(u,i.canonical.x-(e.canonical.x<<u),i.canonical.y-(e.canonical.y<<u));a[h.key]=a[h.key]||h;}function Gi(t,e,i,o,r){for(var a=t.context,n=a.gl,s=r?t.useProgram(\"collisionCircle\"):t.useProgram(\"collisionBox\"),l=0;l<o.length;l++){var c=o[l],u=e.getTile(c),h=u.getBucket(i);if(h){var p=r?h.collisionCircle:h.collisionBox;p&&s.draw(a,r?n.TRIANGLES:n.LINES,Tt.disabled,It.disabled,t.colorModeForRenderPass(),St.disabled,wi(c.posMatrix,t.transform,u),i.id,p.layoutVertexBuffer,p.indexBuffer,p.segments,null,t.transform.zoom,null,null,p.collisionVertexBuffer);}}}var Wi=t.identity(new Float32Array(16));function Xi(e,i,o,r,a,n){var s=t.getAnchorAlignment(e),l=-(s.horizontalAlign-.5)*i,c=-(s.verticalAlign-.5)*o,u=t.evaluateRadialOffset(e,r);return new t.Point((l/a+u[0])*n,(c/a+u[1])*n)}function Hi(e,i,o,r,a,n,s,l,c,u){var h=e.text.placedSymbolArray,p=e.text.dynamicLayoutVertexArray;p.clear();for(var d=0;d<h.length;d++){var _=h.get(d),f=!_.hidden&&_.crossTileID?r[_.crossTileID]:null;if(f){var m=new t.Point(_.anchorX,_.anchorY),g=Yt(m,o?l:s),v=.5+n.cameraToCenterDistance/g.signedDistanceFromCamera*.5,y=a.evaluateSizeForFeature(e.textSizeData,u,_)*v/t.ONE_EM;o&&(y*=e.tilePixelRatio/c);for(var x=f.width,b=f.height,w=f.radialOffset,E=f.textBoxScale,T=Xi(f.anchor,x,b,w,E,y),I=o?Yt(m.add(T),s).point:g.point.add(i?T.rotate(-n.angle):T),C=0;C<_.numGlyphs;C++)t.addDynamicAttributes(p,I,0);}else ae(_.numGlyphs,p);}e.text.dynamicLayoutVertexBuffer.updateData(p);}function Ki(e,i,o,r,a,n,s,l,c,u,h,p,d){for(var _,f,m=e.context,g=m.gl,v=e.transform,y=\"map\"===l,x=\"map\"===c,b=y&&\"point\"!==o.layout.get(\"symbol-placement\"),w=y&&!x&&!b,E=void 0!==o.layout.get(\"symbol-sort-key\").constantOr(1),T=e.depthModeForSublayer(0,Tt.ReadOnly),I=o.layout.get(\"text-variable-anchor\"),C=[],S=0,P=r;S<P.length;S+=1){var z=P[S],L=i.getTile(z),D=L.getBucket(o);if(D){var M=a?D.text:D.icon;if(M&&M.segments.get().length){var R=M.programConfigurations.get(o.id),A=a||D.sdfIcons,k=a?D.textSizeData:D.iconSizeData;_||(_=e.useProgram(A?\"symbolSDF\":\"symbolIcon\",R),f=t.evaluateSizeForZoom(k,v.zoom)),m.activeTexture.set(g.TEXTURE0);var B=void 0,O=void 0,F=void 0;if(a)O=L.glyphAtlasTexture,F=g.LINEAR,B=L.glyphAtlasTexture.size;else{var U=1!==o.layout.get(\"icon-size\").constantOr(0)||D.iconsNeedLinear,N=x||0!==v.pitch;O=L.imageAtlasTexture,F=A||e.options.rotating||e.options.zooming||U||N?g.LINEAR:g.NEAREST,B=L.imageAtlasTexture.size;}var Z=ce(L,1,e.transform.zoom),j=Ht(z.posMatrix,x,y,e.transform,Z),q=Kt(z.posMatrix,x,y,e.transform,Z);if(b)Qt(D,z.posMatrix,e,a,j,q,x,u);else if(a&&f&&I){var V=Math.pow(2,v.zoom-L.tileID.overscaledZ);Hi(D,y,x,d,t.symbolSize,v,j,z.posMatrix,V,f);}var G=e.translatePosMatrix(z.posMatrix,L,n,s),W=b||a&&I?Wi:j,X=e.translatePosMatrix(q,L,n,s,!0),H=A&&0!==o.paint.get(a?\"text-halo-width\":\"icon-halo-width\").constantOr(1),K={program:_,buffers:M,uniformValues:A?Ui(k.kind,f,w,x,e,G,W,X,a,B,!0):Fi(k.kind,f,w,x,e,G,W,X,a,B),atlasTexture:O,atlasInterpolation:F,isSDF:A,hasHalo:H};if(E)for(var Y=0,J=M.segments.get();Y<J.length;Y+=1){var Q=J[Y];C.push({segments:new t.SegmentVector([Q]),sortKey:Q.sortKey,state:K});}else C.push({segments:M.segments,sortKey:0,state:K});}}}E&&C.sort(function(t,e){return t.sortKey-e.sortKey});for(var $=0,tt=C;$<tt.length;$+=1){var et=tt[$],it=et.state;if(it.atlasTexture.bind(it.atlasInterpolation,g.CLAMP_TO_EDGE),it.isSDF){var ot=it.uniformValues;it.hasHalo&&(ot.u_is_halo=1,Yi(it.buffers,et.segments,o,e,it.program,T,h,p,ot)),ot.u_is_halo=0;}Yi(it.buffers,et.segments,o,e,it.program,T,h,p,it.uniformValues);}}function Yi(t,e,i,o,r,a,n,s,l){var c=o.context,u=c.gl;r.draw(c,u.TRIANGLES,a,n,s,St.disabled,l,i.id,t.layoutVertexBuffer,t.indexBuffer,e,i.paint,o.transform.zoom,t.programConfigurations.get(i.id),t.dynamicLayoutVertexBuffer,t.opacityVertexBuffer);}function Ji(t,e,i,o,r,a,n){var s,l,c,u,h,p=t.context.gl,d=i.paint.get(\"fill-pattern\"),_=d&&d.constantOr(1),f=i.getCrossfadeParameters();n?(l=_&&!i.getPaintProperty(\"fill-outline-color\")?\"fillOutlinePattern\":\"fillOutline\",s=p.LINES):(l=_?\"fillPattern\":\"fill\",s=p.TRIANGLES);for(var m=0,g=o;m<g.length;m+=1){var v=g[m],y=e.getTile(v);if(!_||y.patternsLoaded()){var x=y.getBucket(i);if(x){var b=x.programConfigurations.get(i.id),w=t.useProgram(l,b);_&&(t.context.activeTexture.set(p.TEXTURE0),y.imageAtlasTexture.bind(p.LINEAR,p.CLAMP_TO_EDGE),b.updatePatternPaintBuffers(f));var E=d.constantOr(null);if(E&&y.imageAtlas){var T=y.imageAtlas.patternPositions[E.to],I=y.imageAtlas.patternPositions[E.from];T&&I&&b.setConstantPatternPositions(T,I);}var C=t.translatePosMatrix(v.posMatrix,y,i.paint.get(\"fill-translate\"),i.paint.get(\"fill-translate-anchor\"));if(n){u=x.indexBuffer2,h=x.segments2;var S=[p.drawingBufferWidth,p.drawingBufferHeight];c=\"fillOutlinePattern\"===l&&_?yi(C,t,f,y,S):vi(C,S);}else u=x.indexBuffer,h=x.segments,c=_?gi(C,t,f,y):mi(C);w.draw(t.context,s,r,t.stencilModeForClipping(v),a,St.disabled,c,i.id,x.layoutVertexBuffer,u,h,i.paint,t.transform.zoom,b);}}}}function Qi(t,e,i,o,r,a,n){for(var s=t.context,l=s.gl,c=i.paint.get(\"fill-extrusion-pattern\"),u=c.constantOr(1),h=i.getCrossfadeParameters(),p=i.paint.get(\"fill-extrusion-opacity\"),d=0,_=o;d<_.length;d+=1){var f=_[d],m=e.getTile(f),g=m.getBucket(i);if(g){var v=g.programConfigurations.get(i.id),y=t.useProgram(u?\"fillExtrusionPattern\":\"fillExtrusion\",v);u&&(t.context.activeTexture.set(l.TEXTURE0),m.imageAtlasTexture.bind(l.LINEAR,l.CLAMP_TO_EDGE),v.updatePatternPaintBuffers(h));var x=c.constantOr(null);if(x&&m.imageAtlas){var b=m.imageAtlas.patternPositions[x.to],w=m.imageAtlas.patternPositions[x.from];b&&w&&v.setConstantPatternPositions(b,w);}var E=t.translatePosMatrix(f.posMatrix,m,i.paint.get(\"fill-extrusion-translate\"),i.paint.get(\"fill-extrusion-translate-anchor\")),T=i.paint.get(\"fill-extrusion-vertical-gradient\"),I=u?fi(E,t,T,p,f,h,m):_i(E,t,T,p);y.draw(s,s.gl.TRIANGLES,r,a,n,St.backCCW,I,i.id,g.layoutVertexBuffer,g.indexBuffer,g.segments,i.paint,t.transform.zoom,v);}}}function $i(t,e,i,o,r,a){var n=t.context,s=n.gl,l=e.fbo;if(l){var c=t.useProgram(\"hillshade\");n.activeTexture.set(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,l.colorAttachment.get());var u=Si(t,e,i);e.maskedBoundsBuffer&&e.maskedIndexBuffer&&e.segments?c.draw(n,s.TRIANGLES,o,r,a,St.disabled,u,i.id,e.maskedBoundsBuffer,e.maskedIndexBuffer,e.segments):c.draw(n,s.TRIANGLES,o,r,a,St.disabled,u,i.id,t.rasterBoundsBuffer,t.quadTriangleIndexBuffer,t.rasterBoundsSegments);}}function to(e,i,o,r,a,n,s){var l=e.context,c=l.gl;if(i.dem&&i.dem.data){var u=i.dem.dim,h=i.dem.stride,p=i.dem.getPixels();if(l.activeTexture.set(c.TEXTURE1),l.pixelStoreUnpackPremultiplyAlpha.set(!1),i.demTexture=i.demTexture||e.getTileTexture(h),i.demTexture){var d=i.demTexture;d.update(p,{premultiply:!1}),d.bind(c.NEAREST,c.CLAMP_TO_EDGE);}else i.demTexture=new t.Texture(l,p,c.RGBA,{premultiply:!1}),i.demTexture.bind(c.NEAREST,c.CLAMP_TO_EDGE);l.activeTexture.set(c.TEXTURE0);var _=i.fbo;if(!_){var f=new t.Texture(l,{width:u,height:u,data:null},c.RGBA);f.bind(c.LINEAR,c.CLAMP_TO_EDGE),(_=i.fbo=l.createFramebuffer(u,u)).colorAttachment.set(f.texture);}l.bindFramebuffer.set(_.framebuffer),l.viewport.set([0,0,u,u]),e.useProgram(\"hillshadePrepare\").draw(l,c.TRIANGLES,a,n,s,St.disabled,Pi(i,r),o.id,e.rasterBoundsBuffer,e.quadTriangleIndexBuffer,e.rasterBoundsSegments),i.needsHillshadePrepare=!1;}}function eo(e,i,o,r,a){var n=r.paint.get(\"raster-fade-duration\");if(n>0){var s=t.browser.now(),l=(s-e.timeAdded)/n,c=i?(s-i.timeAdded)/n:-1,u=o.getSource(),h=a.coveringZoomLevel({tileSize:u.tileSize,roundZoom:u.roundZoom}),p=!i||Math.abs(i.tileID.overscaledZ-h)>Math.abs(e.tileID.overscaledZ-h),d=p&&e.refreshedUponExpiration?1:t.clamp(p?l:1-c,0,1);return e.refreshedUponExpiration&&l>=1&&(e.refreshedUponExpiration=!1),i?{opacity:1,mix:1-d}:{opacity:d,mix:0}}return {opacity:1,mix:0}}function io(e,i,o){var r=e.context,a=r.gl,n=o.posMatrix,s=e.useProgram(\"debug\"),l=Tt.disabled,c=It.disabled,u=e.colorModeForRenderPass(),h=\"$debug\";s.draw(r,a.LINE_STRIP,l,c,u,St.disabled,Ei(n,t.Color.red),h,e.debugBuffer,e.tileBorderIndexBuffer,e.debugSegments);for(var p=i.getTileByID(o.key).latestRawTileData,d=p&&p.byteLength||0,_=Math.floor(d/1024),f=function(t,e,i,o){o=o||1;var r,a,n,s,l,c,u,h,p=[];for(r=0,a=t.length;r<a;r++)if(l=oo[t[r]]){for(h=null,n=0,s=l[1].length;n<s;n+=2)-1===l[1][n]&&-1===l[1][n+1]?h=null:(c=e+l[1][n]*o,u=i-l[1][n+1]*o,h&&p.push(h.x,h.y,c,u),h={x:c,y:u});e+=l[0]*o;}return p}(o.toString()+\" \"+_+\"kb\",50,200,5),m=new t.StructArrayLayout2i4,g=new t.StructArrayLayout2ui4,v=0;v<f.length;v+=2)m.emplaceBack(f[v],f[v+1]),g.emplaceBack(v,v+1);for(var y=r.createVertexBuffer(m,Oe.members),x=r.createIndexBuffer(g),b=t.SegmentVector.simpleSegment(0,0,m.length/2,m.length/2),w=i.getTile(o).tileSize,E=t.EXTENT/(Math.pow(2,e.transform.zoom-o.overscaledZ)*w),T=[[-1,-1],[-1,1],[1,-1],[1,1]],I=0;I<T.length;I++){var C=T[I];s.draw(r,a.LINES,l,c,u,St.disabled,Ei(t.translate([],n,[E*C[0],E*C[1],0]),t.Color.white),h,y,x,b);}s.draw(r,a.LINES,l,c,u,St.disabled,Ei(n,t.Color.black),h,y,x,b);}var oo={\" \":[16,[]],\"!\":[10,[5,21,5,7,-1,-1,5,2,4,1,5,0,6,1,5,2]],'\"':[16,[4,21,4,14,-1,-1,12,21,12,14]],\"#\":[21,[11,25,4,-7,-1,-1,17,25,10,-7,-1,-1,4,12,18,12,-1,-1,3,6,17,6]],$:[20,[8,25,8,-4,-1,-1,12,25,12,-4,-1,-1,17,18,15,20,12,21,8,21,5,20,3,18,3,16,4,14,5,13,7,12,13,10,15,9,16,8,17,6,17,3,15,1,12,0,8,0,5,1,3,3]],\"%\":[24,[21,21,3,0,-1,-1,8,21,10,19,10,17,9,15,7,14,5,14,3,16,3,18,4,20,6,21,8,21,10,20,13,19,16,19,19,20,21,21,-1,-1,17,7,15,6,14,4,14,2,16,0,18,0,20,1,21,3,21,5,19,7,17,7]],\"&\":[26,[23,12,23,13,22,14,21,14,20,13,19,11,17,6,15,3,13,1,11,0,7,0,5,1,4,2,3,4,3,6,4,8,5,9,12,13,13,14,14,16,14,18,13,20,11,21,9,20,8,18,8,16,9,13,11,10,16,3,18,1,20,0,22,0,23,1,23,2]],\"'\":[10,[5,19,4,20,5,21,6,20,6,18,5,16,4,15]],\"(\":[14,[11,25,9,23,7,20,5,16,4,11,4,7,5,2,7,-2,9,-5,11,-7]],\")\":[14,[3,25,5,23,7,20,9,16,10,11,10,7,9,2,7,-2,5,-5,3,-7]],\"*\":[16,[8,21,8,9,-1,-1,3,18,13,12,-1,-1,13,18,3,12]],\"+\":[26,[13,18,13,0,-1,-1,4,9,22,9]],\",\":[10,[6,1,5,0,4,1,5,2,6,1,6,-1,5,-3,4,-4]],\"-\":[26,[4,9,22,9]],\".\":[10,[5,2,4,1,5,0,6,1,5,2]],\"/\":[22,[20,25,2,-7]],0:[20,[9,21,6,20,4,17,3,12,3,9,4,4,6,1,9,0,11,0,14,1,16,4,17,9,17,12,16,17,14,20,11,21,9,21]],1:[20,[6,17,8,18,11,21,11,0]],2:[20,[4,16,4,17,5,19,6,20,8,21,12,21,14,20,15,19,16,17,16,15,15,13,13,10,3,0,17,0]],3:[20,[5,21,16,21,10,13,13,13,15,12,16,11,17,8,17,6,16,3,14,1,11,0,8,0,5,1,4,2,3,4]],4:[20,[13,21,3,7,18,7,-1,-1,13,21,13,0]],5:[20,[15,21,5,21,4,12,5,13,8,14,11,14,14,13,16,11,17,8,17,6,16,3,14,1,11,0,8,0,5,1,4,2,3,4]],6:[20,[16,18,15,20,12,21,10,21,7,20,5,17,4,12,4,7,5,3,7,1,10,0,11,0,14,1,16,3,17,6,17,7,16,10,14,12,11,13,10,13,7,12,5,10,4,7]],7:[20,[17,21,7,0,-1,-1,3,21,17,21]],8:[20,[8,21,5,20,4,18,4,16,5,14,7,13,11,12,14,11,16,9,17,7,17,4,16,2,15,1,12,0,8,0,5,1,4,2,3,4,3,7,4,9,6,11,9,12,13,13,15,14,16,16,16,18,15,20,12,21,8,21]],9:[20,[16,14,15,11,13,9,10,8,9,8,6,9,4,11,3,14,3,15,4,18,6,20,9,21,10,21,13,20,15,18,16,14,16,9,15,4,13,1,10,0,8,0,5,1,4,3]],\":\":[10,[5,14,4,13,5,12,6,13,5,14,-1,-1,5,2,4,1,5,0,6,1,5,2]],\";\":[10,[5,14,4,13,5,12,6,13,5,14,-1,-1,6,1,5,0,4,1,5,2,6,1,6,-1,5,-3,4,-4]],\"<\":[24,[20,18,4,9,20,0]],\"=\":[26,[4,12,22,12,-1,-1,4,6,22,6]],\">\":[24,[4,18,20,9,4,0]],\"?\":[18,[3,16,3,17,4,19,5,20,7,21,11,21,13,20,14,19,15,17,15,15,14,13,13,12,9,10,9,7,-1,-1,9,2,8,1,9,0,10,1,9,2]],\"@\":[27,[18,13,17,15,15,16,12,16,10,15,9,14,8,11,8,8,9,6,11,5,14,5,16,6,17,8,-1,-1,12,16,10,14,9,11,9,8,10,6,11,5,-1,-1,18,16,17,8,17,6,19,5,21,5,23,7,24,10,24,12,23,15,22,17,20,19,18,20,15,21,12,21,9,20,7,19,5,17,4,15,3,12,3,9,4,6,5,4,7,2,9,1,12,0,15,0,18,1,20,2,21,3,-1,-1,19,16,18,8,18,6,19,5]],A:[18,[9,21,1,0,-1,-1,9,21,17,0,-1,-1,4,7,14,7]],B:[21,[4,21,4,0,-1,-1,4,21,13,21,16,20,17,19,18,17,18,15,17,13,16,12,13,11,-1,-1,4,11,13,11,16,10,17,9,18,7,18,4,17,2,16,1,13,0,4,0]],C:[21,[18,16,17,18,15,20,13,21,9,21,7,20,5,18,4,16,3,13,3,8,4,5,5,3,7,1,9,0,13,0,15,1,17,3,18,5]],D:[21,[4,21,4,0,-1,-1,4,21,11,21,14,20,16,18,17,16,18,13,18,8,17,5,16,3,14,1,11,0,4,0]],E:[19,[4,21,4,0,-1,-1,4,21,17,21,-1,-1,4,11,12,11,-1,-1,4,0,17,0]],F:[18,[4,21,4,0,-1,-1,4,21,17,21,-1,-1,4,11,12,11]],G:[21,[18,16,17,18,15,20,13,21,9,21,7,20,5,18,4,16,3,13,3,8,4,5,5,3,7,1,9,0,13,0,15,1,17,3,18,5,18,8,-1,-1,13,8,18,8]],H:[22,[4,21,4,0,-1,-1,18,21,18,0,-1,-1,4,11,18,11]],I:[8,[4,21,4,0]],J:[16,[12,21,12,5,11,2,10,1,8,0,6,0,4,1,3,2,2,5,2,7]],K:[21,[4,21,4,0,-1,-1,18,21,4,7,-1,-1,9,12,18,0]],L:[17,[4,21,4,0,-1,-1,4,0,16,0]],M:[24,[4,21,4,0,-1,-1,4,21,12,0,-1,-1,20,21,12,0,-1,-1,20,21,20,0]],N:[22,[4,21,4,0,-1,-1,4,21,18,0,-1,-1,18,21,18,0]],O:[22,[9,21,7,20,5,18,4,16,3,13,3,8,4,5,5,3,7,1,9,0,13,0,15,1,17,3,18,5,19,8,19,13,18,16,17,18,15,20,13,21,9,21]],P:[21,[4,21,4,0,-1,-1,4,21,13,21,16,20,17,19,18,17,18,14,17,12,16,11,13,10,4,10]],Q:[22,[9,21,7,20,5,18,4,16,3,13,3,8,4,5,5,3,7,1,9,0,13,0,15,1,17,3,18,5,19,8,19,13,18,16,17,18,15,20,13,21,9,21,-1,-1,12,4,18,-2]],R:[21,[4,21,4,0,-1,-1,4,21,13,21,16,20,17,19,18,17,18,15,17,13,16,12,13,11,4,11,-1,-1,11,11,18,0]],S:[20,[17,18,15,20,12,21,8,21,5,20,3,18,3,16,4,14,5,13,7,12,13,10,15,9,16,8,17,6,17,3,15,1,12,0,8,0,5,1,3,3]],T:[16,[8,21,8,0,-1,-1,1,21,15,21]],U:[22,[4,21,4,6,5,3,7,1,10,0,12,0,15,1,17,3,18,6,18,21]],V:[18,[1,21,9,0,-1,-1,17,21,9,0]],W:[24,[2,21,7,0,-1,-1,12,21,7,0,-1,-1,12,21,17,0,-1,-1,22,21,17,0]],X:[20,[3,21,17,0,-1,-1,17,21,3,0]],Y:[18,[1,21,9,11,9,0,-1,-1,17,21,9,11]],Z:[20,[17,21,3,0,-1,-1,3,21,17,21,-1,-1,3,0,17,0]],\"[\":[14,[4,25,4,-7,-1,-1,5,25,5,-7,-1,-1,4,25,11,25,-1,-1,4,-7,11,-7]],\"\\\\\":[14,[0,21,14,-3]],\"]\":[14,[9,25,9,-7,-1,-1,10,25,10,-7,-1,-1,3,25,10,25,-1,-1,3,-7,10,-7]],\"^\":[16,[6,15,8,18,10,15,-1,-1,3,12,8,17,13,12,-1,-1,8,17,8,0]],_:[16,[0,-2,16,-2]],\"`\":[10,[6,21,5,20,4,18,4,16,5,15,6,16,5,17]],a:[19,[15,14,15,0,-1,-1,15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3]],b:[19,[4,21,4,0,-1,-1,4,11,6,13,8,14,11,14,13,13,15,11,16,8,16,6,15,3,13,1,11,0,8,0,6,1,4,3]],c:[18,[15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3]],d:[19,[15,21,15,0,-1,-1,15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3]],e:[18,[3,8,15,8,15,10,14,12,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3]],f:[12,[10,21,8,21,6,20,5,17,5,0,-1,-1,2,14,9,14]],g:[19,[15,14,15,-2,14,-5,13,-6,11,-7,8,-7,6,-6,-1,-1,15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3]],h:[19,[4,21,4,0,-1,-1,4,10,7,13,9,14,12,14,14,13,15,10,15,0]],i:[8,[3,21,4,20,5,21,4,22,3,21,-1,-1,4,14,4,0]],j:[10,[5,21,6,20,7,21,6,22,5,21,-1,-1,6,14,6,-3,5,-6,3,-7,1,-7]],k:[17,[4,21,4,0,-1,-1,14,14,4,4,-1,-1,8,8,15,0]],l:[8,[4,21,4,0]],m:[30,[4,14,4,0,-1,-1,4,10,7,13,9,14,12,14,14,13,15,10,15,0,-1,-1,15,10,18,13,20,14,23,14,25,13,26,10,26,0]],n:[19,[4,14,4,0,-1,-1,4,10,7,13,9,14,12,14,14,13,15,10,15,0]],o:[19,[8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3,16,6,16,8,15,11,13,13,11,14,8,14]],p:[19,[4,14,4,-7,-1,-1,4,11,6,13,8,14,11,14,13,13,15,11,16,8,16,6,15,3,13,1,11,0,8,0,6,1,4,3]],q:[19,[15,14,15,-7,-1,-1,15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3]],r:[13,[4,14,4,0,-1,-1,4,8,5,11,7,13,9,14,12,14]],s:[17,[14,11,13,13,10,14,7,14,4,13,3,11,4,9,6,8,11,7,13,6,14,4,14,3,13,1,10,0,7,0,4,1,3,3]],t:[12,[5,21,5,4,6,1,8,0,10,0,-1,-1,2,14,9,14]],u:[19,[4,14,4,4,5,1,7,0,10,0,12,1,15,4,-1,-1,15,14,15,0]],v:[16,[2,14,8,0,-1,-1,14,14,8,0]],w:[22,[3,14,7,0,-1,-1,11,14,7,0,-1,-1,11,14,15,0,-1,-1,19,14,15,0]],x:[17,[3,14,14,0,-1,-1,14,14,3,0]],y:[16,[2,14,8,0,-1,-1,14,14,8,0,6,-4,4,-6,2,-7,1,-7]],z:[17,[14,14,3,0,-1,-1,3,14,14,14,-1,-1,3,0,14,0]],\"{\":[14,[9,25,7,24,6,23,5,21,5,19,6,17,7,16,8,14,8,12,6,10,-1,-1,7,24,6,22,6,20,7,18,8,17,9,15,9,13,8,11,4,9,8,7,9,5,9,3,8,1,7,0,6,-2,6,-4,7,-6,-1,-1,6,8,8,6,8,4,7,2,6,1,5,-1,5,-3,6,-5,7,-6,9,-7]],\"|\":[8,[4,25,4,-7]],\"}\":[14,[5,25,7,24,8,23,9,21,9,19,8,17,7,16,6,14,6,12,8,10,-1,-1,7,24,8,22,8,20,7,18,6,17,5,15,5,13,6,11,10,9,6,7,5,5,5,3,6,1,7,0,8,-2,8,-4,7,-6,-1,-1,8,8,6,6,6,4,7,2,8,1,9,-1,9,-3,8,-5,7,-6,5,-7]],\"~\":[24,[3,6,3,8,4,11,6,12,8,12,10,11,14,8,16,7,18,7,20,8,21,10,-1,-1,3,8,4,10,6,11,8,11,10,10,14,7,16,6,18,6,20,7,21,10,21,12]]};var ro={symbol:function(t,e,i,o,r){if(\"translucent\"===t.renderPass){var a=It.disabled,n=t.colorModeForRenderPass();0!==i.paint.get(\"icon-opacity\").constantOr(1)&&Ki(t,e,i,o,!1,i.paint.get(\"icon-translate\"),i.paint.get(\"icon-translate-anchor\"),i.layout.get(\"icon-rotation-alignment\"),i.layout.get(\"icon-pitch-alignment\"),i.layout.get(\"icon-keep-upright\"),a,n,r),0!==i.paint.get(\"text-opacity\").constantOr(1)&&Ki(t,e,i,o,!0,i.paint.get(\"text-translate\"),i.paint.get(\"text-translate-anchor\"),i.layout.get(\"text-rotation-alignment\"),i.layout.get(\"text-pitch-alignment\"),i.layout.get(\"text-keep-upright\"),a,n,r),e.map.showCollisionBoxes&&function(t,e,i,o){Gi(t,e,i,o,!1),Gi(t,e,i,o,!0);}(t,e,i,o);}},circle:function(t,e,i,o){if(\"translucent\"===t.renderPass){var r=i.paint.get(\"circle-opacity\"),a=i.paint.get(\"circle-stroke-width\"),n=i.paint.get(\"circle-stroke-opacity\");if(0!==r.constantOr(1)||0!==a.constantOr(1)&&0!==n.constantOr(1))for(var s=t.context,l=s.gl,c=t.depthModeForSublayer(0,Tt.ReadOnly),u=It.disabled,h=t.colorModeForRenderPass(),p=0;p<o.length;p++){var d=o[p],_=e.getTile(d),f=_.getBucket(i);if(f){var m=f.programConfigurations.get(i.id);t.useProgram(\"circle\",m).draw(s,l.TRIANGLES,c,u,h,St.disabled,xi(t,d,_,i),i.id,f.layoutVertexBuffer,f.indexBuffer,f.segments,i.paint,t.transform.zoom,m);}}}},heatmap:function(e,i,o,r){if(0!==o.paint.get(\"heatmap-opacity\"))if(\"offscreen\"===e.renderPass){var a=e.context,n=a.gl,s=e.depthModeForSublayer(0,Tt.ReadOnly),l=It.disabled,c=new Ct([n.ONE,n.ONE],t.Color.transparent,[!0,!0,!0,!0]);!function(t,e,i){var o=t.gl;t.activeTexture.set(o.TEXTURE1),t.viewport.set([0,0,e.width/4,e.height/4]);var r=i.heatmapFbo;if(r)o.bindTexture(o.TEXTURE_2D,r.colorAttachment.get()),t.bindFramebuffer.set(r.framebuffer);else{var a=o.createTexture();o.bindTexture(o.TEXTURE_2D,a),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),r=i.heatmapFbo=t.createFramebuffer(e.width/4,e.height/4),function t(e,i,o,r){var a=e.gl;a.texImage2D(a.TEXTURE_2D,0,a.RGBA,i.width/4,i.height/4,0,a.RGBA,e.extTextureHalfFloat?e.extTextureHalfFloat.HALF_FLOAT_OES:a.UNSIGNED_BYTE,null),r.colorAttachment.set(o),e.extTextureHalfFloat&&a.checkFramebufferStatus(a.FRAMEBUFFER)!==a.FRAMEBUFFER_COMPLETE&&(e.extTextureHalfFloat=null,r.colorAttachment.setDirty(),t(e,i,o,r));}(t,e,a,r);}}(a,e,o),a.clear({color:t.Color.transparent});for(var u=0;u<r.length;u++){var h=r[u];if(!i.hasRenderableParent(h)){var p=i.getTile(h),d=p.getBucket(o);if(d){var _=d.programConfigurations.get(o.id),f=e.useProgram(\"heatmap\",_),m=e.transform.zoom;f.draw(a,n.TRIANGLES,s,l,c,St.disabled,Ii(h.posMatrix,p,m,o.paint.get(\"heatmap-intensity\")),o.id,d.layoutVertexBuffer,d.indexBuffer,d.segments,o.paint,e.transform.zoom,_);}}}a.viewport.set([0,0,e.width,e.height]);}else\"translucent\"===e.renderPass&&(e.context.setColorMode(e.colorModeForRenderPass()),function(e,i){var o=e.context,r=o.gl,a=i.heatmapFbo;if(a){o.activeTexture.set(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,a.colorAttachment.get()),o.activeTexture.set(r.TEXTURE1);var n=i.colorRampTexture;n||(n=i.colorRampTexture=new t.Texture(o,i.colorRamp,r.RGBA)),n.bind(r.LINEAR,r.CLAMP_TO_EDGE),e.useProgram(\"heatmapTexture\").draw(o,r.TRIANGLES,Tt.disabled,It.disabled,e.colorModeForRenderPass(),St.disabled,Ci(e,i,0,1),i.id,e.viewportBuffer,e.quadTriangleIndexBuffer,e.viewportSegments,i.paint,e.transform.zoom);}}(e,o));},line:function(e,i,o,r){if(\"translucent\"===e.renderPass){var a=o.paint.get(\"line-opacity\"),n=o.paint.get(\"line-width\");if(0!==a.constantOr(1)&&0!==n.constantOr(1)){var s=e.depthModeForSublayer(0,Tt.ReadOnly),l=e.colorModeForRenderPass(),c=o.paint.get(\"line-dasharray\"),u=o.paint.get(\"line-pattern\"),h=u.constantOr(1),p=o.paint.get(\"line-gradient\"),d=o.getCrossfadeParameters(),_=c?\"lineSDF\":h?\"linePattern\":p?\"lineGradient\":\"line\",f=e.context,m=f.gl,g=!0;if(p){f.activeTexture.set(m.TEXTURE0);var v=o.gradientTexture;if(!o.gradient)return;v||(v=o.gradientTexture=new t.Texture(f,o.gradient,m.RGBA)),v.bind(m.LINEAR,m.CLAMP_TO_EDGE);}for(var y=0,x=r;y<x.length;y+=1){var b=x[y],w=i.getTile(b);if(!h||w.patternsLoaded()){var E=w.getBucket(o);if(E){var T=E.programConfigurations.get(o.id),I=e.context.program.get(),C=e.useProgram(_,T),S=g||C.program!==I,P=u.constantOr(null);if(P&&w.imageAtlas){var z=w.imageAtlas.patternPositions[P.to],L=w.imageAtlas.patternPositions[P.from];z&&L&&T.setConstantPatternPositions(z,L);}var D=c?Ri(e,w,o,c,d):h?Mi(e,w,o,d):p?Di(e,w,o):Li(e,w,o);c&&(S||e.lineAtlas.dirty)?(f.activeTexture.set(m.TEXTURE0),e.lineAtlas.bind(f)):h&&(f.activeTexture.set(m.TEXTURE0),w.imageAtlasTexture.bind(m.LINEAR,m.CLAMP_TO_EDGE),T.updatePatternPaintBuffers(d)),C.draw(f,m.TRIANGLES,s,e.stencilModeForClipping(b),l,St.disabled,D,o.id,E.layoutVertexBuffer,E.indexBuffer,E.segments,o.paint,e.transform.zoom,T),g=!1;}}}}}},fill:function(e,i,o,r){var a=o.paint.get(\"fill-color\"),n=o.paint.get(\"fill-opacity\");if(0!==n.constantOr(1)){var s=e.colorModeForRenderPass(),l=o.paint.get(\"fill-pattern\"),c=e.opaquePassEnabledForLayer()&&!l.constantOr(1)&&1===a.constantOr(t.Color.transparent).a&&1===n.constantOr(0)?\"opaque\":\"translucent\";if(e.renderPass===c){var u=e.depthModeForSublayer(1,\"opaque\"===e.renderPass?Tt.ReadWrite:Tt.ReadOnly);Ji(e,i,o,r,u,s,!1);}if(\"translucent\"===e.renderPass&&o.paint.get(\"fill-antialias\")){var h=e.depthModeForSublayer(o.getPaintProperty(\"fill-outline-color\")?2:0,Tt.ReadOnly);Ji(e,i,o,r,h,s,!0);}}},\"fill-extrusion\":function(t,e,i,o){var r=i.paint.get(\"fill-extrusion-opacity\");if(0!==r&&\"translucent\"===t.renderPass){var a=new Tt(t.context.gl.LEQUAL,Tt.ReadWrite,t.depthRangeFor3D);if(1!==r||i.paint.get(\"fill-extrusion-pattern\").constantOr(1))Qi(t,e,i,o,a,It.disabled,Ct.disabled),Qi(t,e,i,o,a,t.stencilModeFor3D(),t.colorModeForRenderPass());else{var n=t.colorModeForRenderPass();Qi(t,e,i,o,a,It.disabled,n);}}},hillshade:function(t,e,i,o){if(\"offscreen\"===t.renderPass||\"translucent\"===t.renderPass){for(var r=t.context,a=e.getSource().maxzoom,n=t.depthModeForSublayer(0,Tt.ReadOnly),s=It.disabled,l=t.colorModeForRenderPass(),c=0,u=o;c<u.length;c+=1){var h=u[c],p=e.getTile(h);p.needsHillshadePrepare&&\"offscreen\"===t.renderPass?to(t,p,i,a,n,s,l):\"translucent\"===t.renderPass&&$i(t,p,i,n,s,l);}r.viewport.set([0,0,t.width,t.height]);}},raster:function(t,e,i,o){if(\"translucent\"===t.renderPass&&0!==i.paint.get(\"raster-opacity\"))for(var r=t.context,a=r.gl,n=e.getSource(),s=t.useProgram(\"raster\"),l=It.disabled,c=t.colorModeForRenderPass(),u=o.length&&o[0].overscaledZ,h=!t.options.moving,p=0,d=o;p<d.length;p+=1){var _=d[p],f=t.depthModeForSublayer(_.overscaledZ-u,1===i.paint.get(\"raster-opacity\")?Tt.ReadWrite:Tt.ReadOnly,a.LESS),m=e.getTile(_),g=t.transform.calculatePosMatrix(_.toUnwrapped(),h);m.registerFadeDuration(i.paint.get(\"raster-fade-duration\"));var v=e.findLoadedParent(_,0),y=eo(m,v,e,i,t.transform),x=void 0,b=void 0,w=\"nearest\"===i.paint.get(\"raster-resampling\")?a.NEAREST:a.LINEAR;r.activeTexture.set(a.TEXTURE0),m.texture.bind(w,a.CLAMP_TO_EDGE,a.LINEAR_MIPMAP_NEAREST),r.activeTexture.set(a.TEXTURE1),v?(v.texture.bind(w,a.CLAMP_TO_EDGE,a.LINEAR_MIPMAP_NEAREST),x=Math.pow(2,v.tileID.overscaledZ-m.tileID.overscaledZ),b=[m.tileID.canonical.x*x%1,m.tileID.canonical.y*x%1]):m.texture.bind(w,a.CLAMP_TO_EDGE,a.LINEAR_MIPMAP_NEAREST);var E=Bi(g,b||[0,0],x||1,y,i);n instanceof L?s.draw(r,a.TRIANGLES,f,l,c,St.disabled,E,i.id,n.boundsBuffer,t.quadTriangleIndexBuffer,n.boundsSegments):m.maskedBoundsBuffer&&m.maskedIndexBuffer&&m.segments?s.draw(r,a.TRIANGLES,f,l,c,St.disabled,E,i.id,m.maskedBoundsBuffer,m.maskedIndexBuffer,m.segments,i.paint,t.transform.zoom):s.draw(r,a.TRIANGLES,f,l,c,St.disabled,E,i.id,t.rasterBoundsBuffer,t.quadTriangleIndexBuffer,t.rasterBoundsSegments);}},background:function(t,e,i){var o=i.paint.get(\"background-color\"),r=i.paint.get(\"background-opacity\");if(0!==r){var a=t.context,n=a.gl,s=t.transform,l=s.tileSize,c=i.paint.get(\"background-pattern\");if(!t.isPatternMissing(c)){var u=c||1!==o.a||1!==r?\"translucent\":\"opaque\";if(t.renderPass===u){var h=It.disabled,p=t.depthModeForSublayer(0,\"opaque\"===u?Tt.ReadWrite:Tt.ReadOnly),d=t.colorModeForRenderPass(),_=t.useProgram(c?\"backgroundPattern\":\"background\"),f=s.coveringTiles({tileSize:l});c&&(a.activeTexture.set(n.TEXTURE0),t.imageManager.bind(t.context));for(var m=i.getCrossfadeParameters(),g=0,v=f;g<v.length;g+=1){var y=v[g],x=t.transform.calculatePosMatrix(y.toUnwrapped()),b=c?Zi(x,r,t,c,{tileID:y,tileSize:l},m):Ni(x,r,o);_.draw(a,n.TRIANGLES,p,h,d,St.disabled,b,i.id,t.tileExtentBuffer,t.quadTriangleIndexBuffer,t.tileExtentSegments);}}}}},debug:function(t,e,i){for(var o=0;o<i.length;o++)io(t,e,i[o]);},custom:function(t,e,i){var o=t.context,r=i.implementation;if(\"offscreen\"===t.renderPass){var a=r.prerender;a&&(t.setCustomLayerDefaults(),o.setColorMode(t.colorModeForRenderPass()),a.call(r,o.gl,t.transform.customLayerMatrix()),o.setDirty(),t.setBaseState());}else if(\"translucent\"===t.renderPass){t.setCustomLayerDefaults(),o.setColorMode(t.colorModeForRenderPass()),o.setStencilMode(It.disabled);var n=\"3d\"===r.renderingMode?new Tt(t.context.gl.LEQUAL,Tt.ReadWrite,t.depthRangeFor3D):t.depthModeForSublayer(0,Tt.ReadOnly);o.setDepthMode(n),r.render(o.gl,t.transform.customLayerMatrix()),o.setDirty(),t.setBaseState(),o.bindFramebuffer.set(null);}}},ao=function(e,i){this.context=new Pt(e),this.transform=i,this._tileTextures={},this.setup(),this.numSublayers=zt.maxUnderzooming+zt.maxOverzooming+1,this.depthEpsilon=1/Math.pow(2,16),this.depthRboNeedsClear=!0,this.emptyProgramConfiguration=new t.ProgramConfiguration,this.crossTileSymbolIndex=new Me;};function no(t,e){if(t.y>e.y){var i=t;t=e,e=i;}return {x0:t.x,y0:t.y,x1:e.x,y1:e.y,dx:e.x-t.x,dy:e.y-t.y}}function so(t,e,i,o,r){var a=Math.max(i,Math.floor(e.y0)),n=Math.min(o,Math.ceil(e.y1));if(t.x0===e.x0&&t.y0===e.y0?t.x0+e.dy/t.dy*t.dx<e.x1:t.x1-e.dy/t.dy*t.dx<e.x0){var s=t;t=e,e=s;}for(var l=t.dx/t.dy,c=e.dx/e.dy,u=t.dx>0,h=e.dx<0,p=a;p<n;p++){var d=l*Math.max(0,Math.min(t.dy,p+u-t.y0))+t.x0,_=c*Math.max(0,Math.min(e.dy,p+h-e.y0))+e.x0;r(Math.floor(_),Math.ceil(d),p);}}function lo(t,e,i,o,r,a){var n,s=no(t,e),l=no(e,i),c=no(i,t);s.dy>l.dy&&(n=s,s=l,l=n),s.dy>c.dy&&(n=s,s=c,c=n),l.dy>c.dy&&(n=l,l=c,c=n),s.dy&&so(c,s,o,r,a),l.dy&&so(c,l,o,r,a);}ao.prototype.resize=function(e,i){var o=this.context.gl;if(this.width=e*t.browser.devicePixelRatio,this.height=i*t.browser.devicePixelRatio,this.context.viewport.set([0,0,this.width,this.height]),this.style)for(var r=0,a=this.style._order;r<a.length;r+=1){var n=a[r];this.style._layers[n].resize();}this.depthRbo&&(o.deleteRenderbuffer(this.depthRbo),this.depthRbo=null);},ao.prototype.setup=function(){var e=this.context,i=new t.StructArrayLayout2i4;i.emplaceBack(0,0),i.emplaceBack(t.EXTENT,0),i.emplaceBack(0,t.EXTENT),i.emplaceBack(t.EXTENT,t.EXTENT),this.tileExtentBuffer=e.createVertexBuffer(i,Oe.members),this.tileExtentSegments=t.SegmentVector.simpleSegment(0,0,4,2);var o=new t.StructArrayLayout2i4;o.emplaceBack(0,0),o.emplaceBack(t.EXTENT,0),o.emplaceBack(0,t.EXTENT),o.emplaceBack(t.EXTENT,t.EXTENT),this.debugBuffer=e.createVertexBuffer(o,Oe.members),this.debugSegments=t.SegmentVector.simpleSegment(0,0,4,5);var r=new t.StructArrayLayout4i8;r.emplaceBack(0,0,0,0),r.emplaceBack(t.EXTENT,0,t.EXTENT,0),r.emplaceBack(0,t.EXTENT,0,t.EXTENT),r.emplaceBack(t.EXTENT,t.EXTENT,t.EXTENT,t.EXTENT),this.rasterBoundsBuffer=e.createVertexBuffer(r,t.rasterBoundsAttributes.members),this.rasterBoundsSegments=t.SegmentVector.simpleSegment(0,0,4,2);var a=new t.StructArrayLayout2i4;a.emplaceBack(0,0),a.emplaceBack(1,0),a.emplaceBack(0,1),a.emplaceBack(1,1),this.viewportBuffer=e.createVertexBuffer(a,Oe.members),this.viewportSegments=t.SegmentVector.simpleSegment(0,0,4,2);var n=new t.StructArrayLayout1ui2;n.emplaceBack(0),n.emplaceBack(1),n.emplaceBack(3),n.emplaceBack(2),n.emplaceBack(0),this.tileBorderIndexBuffer=e.createIndexBuffer(n);var s=new t.StructArrayLayout3ui6;s.emplaceBack(0,1,2),s.emplaceBack(2,1,3),this.quadTriangleIndexBuffer=e.createIndexBuffer(s);var l=this.context.gl;this.stencilClearMode=new It({func:l.ALWAYS,mask:0},0,255,l.ZERO,l.ZERO,l.ZERO);},ao.prototype.clearStencil=function(){var e=this.context,i=e.gl;this.nextStencilID=1,this.currentStencilSource=void 0;var o=t.create();t.ortho(o,0,this.width,this.height,0,0,1),t.scale(o,o,[i.drawingBufferWidth,i.drawingBufferHeight,0]),this.useProgram(\"clippingMask\").draw(e,i.TRIANGLES,Tt.disabled,this.stencilClearMode,Ct.disabled,St.disabled,Ti(o),\"$clipping\",this.viewportBuffer,this.quadTriangleIndexBuffer,this.viewportSegments);},ao.prototype._renderTileClippingMasks=function(t,e){if(this.currentStencilSource!==t.source&&t.isTileClipped()&&e&&e.length){this.currentStencilSource=t.source;var i=this.context,o=i.gl;this.nextStencilID+e.length>256&&this.clearStencil(),i.setColorMode(Ct.disabled),i.setDepthMode(Tt.disabled);var r=this.useProgram(\"clippingMask\");this._tileClippingMaskIDs={};for(var a=0,n=e;a<n.length;a+=1){var s=n[a],l=this._tileClippingMaskIDs[s.key]=this.nextStencilID++;r.draw(i,o.TRIANGLES,Tt.disabled,new It({func:o.ALWAYS,mask:0},l,255,o.KEEP,o.KEEP,o.REPLACE),Ct.disabled,St.disabled,Ti(s.posMatrix),\"$clipping\",this.tileExtentBuffer,this.quadTriangleIndexBuffer,this.tileExtentSegments);}}},ao.prototype.stencilModeFor3D=function(){this.nextStencilID+1>256&&this.clearStencil();var t=this.nextStencilID++,e=this.context.gl;return new It({func:e.NOTEQUAL,mask:255},t,255,e.KEEP,e.KEEP,e.REPLACE)},ao.prototype.stencilModeForClipping=function(t){var e=this.context.gl;return new It({func:e.EQUAL,mask:255},this._tileClippingMaskIDs[t.key],0,e.KEEP,e.KEEP,e.REPLACE)},ao.prototype.colorModeForRenderPass=function(){var e=this.context.gl;if(this._showOverdrawInspector){return new Ct([e.CONSTANT_COLOR,e.ONE],new t.Color(1/8,1/8,1/8,0),[!0,!0,!0,!0])}return \"opaque\"===this.renderPass?Ct.unblended:Ct.alphaBlended},ao.prototype.depthModeForSublayer=function(t,e,i){if(!this.opaquePassEnabledForLayer())return Tt.disabled;var o=1-((1+this.currentLayer)*this.numSublayers+t)*this.depthEpsilon;return new Tt(i||this.context.gl.LEQUAL,e,[o,o])},ao.prototype.opaquePassEnabledForLayer=function(){return this.currentLayer<this.opaquePassCutoff},ao.prototype.render=function(e,i){this.style=e,this.options=i,this.lineAtlas=e.lineAtlas,this.imageManager=e.imageManager,this.glyphManager=e.glyphManager,this.symbolFadeChange=e.placement.symbolFadeChange(t.browser.now()),this.imageManager.beginFrame();var o=this.style._order,r=this.style.sourceCaches;for(var a in r){var n=r[a];n.used&&n.prepare(this.context);}var s={},l={},c={};for(var u in r){var h=r[u];s[u]=h.getVisibleCoordinates(),l[u]=s[u].slice().reverse(),c[u]=h.getVisibleCoordinates(!0).reverse();}for(var p in r){var d=r[p],_=d.getSource();if(\"raster\"===_.type||\"raster-dem\"===_.type){for(var f=[],m=0,g=s[p];m<g.length;m+=1){var v=g[m];f.push(d.getTile(v));}qi(f,this.context);}}this.opaquePassCutoff=1/0;for(var y=0;y<o.length;y++){var x=o[y];if(this.style._layers[x].is3D()){this.opaquePassCutoff=y;break}}this.renderPass=\"offscreen\",this.depthRboNeedsClear=!0;for(var b=0,w=o;b<w.length;b+=1){var E=w[b],T=this.style._layers[E];if(T.hasOffscreenPass()&&!T.isHidden(this.transform.zoom)){var I=l[T.source];(\"custom\"===T.type||I.length)&&this.renderLayer(this,r[T.source],T,I);}}for(this.context.bindFramebuffer.set(null),this.context.clear({color:i.showOverdrawInspector?t.Color.black:t.Color.transparent,depth:1}),this.clearStencil(),this._showOverdrawInspector=i.showOverdrawInspector,this.depthRangeFor3D=[0,1-(e._order.length+2)*this.numSublayers*this.depthEpsilon],this.renderPass=\"opaque\",this.currentLayer=o.length-1;this.currentLayer>=0;this.currentLayer--){var C=this.style._layers[o[this.currentLayer]],S=r[C.source],P=s[C.source];this._renderTileClippingMasks(C,P),this.renderLayer(this,S,C,P);}for(this.renderPass=\"translucent\",this.currentLayer=0;this.currentLayer<o.length;this.currentLayer++){var z=this.style._layers[o[this.currentLayer]],L=r[z.source],D=(\"symbol\"===z.type?c:l)[z.source];this._renderTileClippingMasks(z,s[z.source]),this.renderLayer(this,L,z,D);}if(this.options.showTileBoundaries)for(var M in r){ro.debug(this,r[M],s[M]);break}this.context.setDefault();},ao.prototype.setupOffscreenDepthRenderbuffer=function(){var t=this.context;this.depthRbo||(this.depthRbo=t.createRenderbuffer(t.gl.DEPTH_COMPONENT16,this.width,this.height));},ao.prototype.renderLayer=function(t,e,i,o){i.isHidden(this.transform.zoom)||(\"background\"===i.type||\"custom\"===i.type||o.length)&&(this.id=i.id,ro[i.type](t,e,i,o,this.style.placement.variableOffsets));},ao.prototype.translatePosMatrix=function(e,i,o,r,a){if(!o[0]&&!o[1])return e;var n=a?\"map\"===r?this.transform.angle:0:\"viewport\"===r?-this.transform.angle:0;if(n){var s=Math.sin(n),l=Math.cos(n);o=[o[0]*l-o[1]*s,o[0]*s+o[1]*l];}var c=[a?o[0]:ce(i,o[0],this.transform.zoom),a?o[1]:ce(i,o[1],this.transform.zoom),0],u=new Float32Array(16);return t.translate(u,e,c),u},ao.prototype.saveTileTexture=function(t){var e=this._tileTextures[t.size[0]];e?e.push(t):this._tileTextures[t.size[0]]=[t];},ao.prototype.getTileTexture=function(t){var e=this._tileTextures[t];return e&&e.length>0?e.pop():null},ao.prototype.isPatternMissing=function(t){if(!t)return !1;var e=this.imageManager.getPattern(t.from),i=this.imageManager.getPattern(t.to);return !e||!i},ao.prototype.useProgram=function(t,e){void 0===e&&(e=this.emptyProgramConfiguration),this.cache=this.cache||{};var i=\"\"+t+(e.cacheKey||\"\")+(this._showOverdrawInspector?\"/overdraw\":\"\");return this.cache[i]||(this.cache[i]=new pi(this.context,ui[t],e,ji[t],this._showOverdrawInspector)),this.cache[i]},ao.prototype.setCustomLayerDefaults=function(){this.context.unbindVAO(),this.context.cullFace.setDefault(),this.context.activeTexture.setDefault(),this.context.pixelStoreUnpack.setDefault(),this.context.pixelStoreUnpackPremultiplyAlpha.setDefault(),this.context.pixelStoreUnpackFlipY.setDefault();},ao.prototype.setBaseState=function(){var t=this.context.gl;this.context.cullFace.set(!1),this.context.viewport.set([0,0,this.width,this.height]),this.context.blendEquation.set(t.FUNC_ADD);};var co=function(e,i,o){this.tileSize=512,this.maxValidLatitude=85.051129,this._renderWorldCopies=void 0===o||o,this._minZoom=e||0,this._maxZoom=i||22,this.setMaxBounds(),this.width=0,this.height=0,this._center=new t.LngLat(0,0),this.zoom=0,this.angle=0,this._fov=.6435011087932844,this._pitch=0,this._unmodified=!0,this._posMatrixCache={},this._alignedPosMatrixCache={};},uo={minZoom:{configurable:!0},maxZoom:{configurable:!0},renderWorldCopies:{configurable:!0},worldSize:{configurable:!0},centerPoint:{configurable:!0},size:{configurable:!0},bearing:{configurable:!0},pitch:{configurable:!0},fov:{configurable:!0},zoom:{configurable:!0},center:{configurable:!0},unmodified:{configurable:!0},point:{configurable:!0}};co.prototype.clone=function(){var t=new co(this._minZoom,this._maxZoom,this._renderWorldCopies);return t.tileSize=this.tileSize,t.latRange=this.latRange,t.width=this.width,t.height=this.height,t._center=this._center,t.zoom=this.zoom,t.angle=this.angle,t._fov=this._fov,t._pitch=this._pitch,t._unmodified=this._unmodified,t._calcMatrices(),t},uo.minZoom.get=function(){return this._minZoom},uo.minZoom.set=function(t){this._minZoom!==t&&(this._minZoom=t,this.zoom=Math.max(this.zoom,t));},uo.maxZoom.get=function(){return this._maxZoom},uo.maxZoom.set=function(t){this._maxZoom!==t&&(this._maxZoom=t,this.zoom=Math.min(this.zoom,t));},uo.renderWorldCopies.get=function(){return this._renderWorldCopies},uo.renderWorldCopies.set=function(t){void 0===t?t=!0:null===t&&(t=!1),this._renderWorldCopies=t;},uo.worldSize.get=function(){return this.tileSize*this.scale},uo.centerPoint.get=function(){return this.size._div(2)},uo.size.get=function(){return new t.Point(this.width,this.height)},uo.bearing.get=function(){return -this.angle/Math.PI*180},uo.bearing.set=function(e){var i=-t.wrap(e,-180,180)*Math.PI/180;this.angle!==i&&(this._unmodified=!1,this.angle=i,this._calcMatrices(),this.rotationMatrix=t.create$2(),t.rotate(this.rotationMatrix,this.rotationMatrix,this.angle));},uo.pitch.get=function(){return this._pitch/Math.PI*180},uo.pitch.set=function(e){var i=t.clamp(e,0,60)/180*Math.PI;this._pitch!==i&&(this._unmodified=!1,this._pitch=i,this._calcMatrices());},uo.fov.get=function(){return this._fov/Math.PI*180},uo.fov.set=function(t){t=Math.max(.01,Math.min(60,t)),this._fov!==t&&(this._unmodified=!1,this._fov=t/180*Math.PI,this._calcMatrices());},uo.zoom.get=function(){return this._zoom},uo.zoom.set=function(t){var e=Math.min(Math.max(t,this.minZoom),this.maxZoom);this._zoom!==e&&(this._unmodified=!1,this._zoom=e,this.scale=this.zoomScale(e),this.tileZoom=Math.floor(e),this.zoomFraction=e-this.tileZoom,this._constrain(),this._calcMatrices());},uo.center.get=function(){return this._center},uo.center.set=function(t){t.lat===this._center.lat&&t.lng===this._center.lng||(this._unmodified=!1,this._center=t,this._constrain(),this._calcMatrices());},co.prototype.coveringZoomLevel=function(t){return (t.roundZoom?Math.round:Math.floor)(this.zoom+this.scaleZoom(this.tileSize/t.tileSize))},co.prototype.getVisibleUnwrappedCoordinates=function(e){var i=[new t.UnwrappedTileID(0,e)];if(this._renderWorldCopies)for(var o=this.pointCoordinate(new t.Point(0,0)),r=this.pointCoordinate(new t.Point(this.width,0)),a=this.pointCoordinate(new t.Point(this.width,this.height)),n=this.pointCoordinate(new t.Point(0,this.height)),s=Math.floor(Math.min(o.x,r.x,a.x,n.x)),l=Math.floor(Math.max(o.x,r.x,a.x,n.x)),c=s-1;c<=l+1;c++)0!==c&&i.push(new t.UnwrappedTileID(c,e));return i},co.prototype.coveringTiles=function(e){var i=this.coveringZoomLevel(e),o=i;if(void 0!==e.minzoom&&i<e.minzoom)return [];void 0!==e.maxzoom&&i>e.maxzoom&&(i=e.maxzoom);var r=t.MercatorCoordinate.fromLngLat(this.center),a=Math.pow(2,i),n=new t.Point(a*r.x-.5,a*r.y-.5);return function(e,i,o,r){void 0===r&&(r=!0);var a=1<<e,n={};function s(i,s,l){var c,u,h,p;if(l>=0&&l<=a)for(c=i;c<s;c++)u=Math.floor(c/a),h=(c%a+a)%a,0!==u&&!0!==r||(p=new t.OverscaledTileID(o,u,e,h,l),n[p.key]=p);}var l=i.map(function(e){return new t.Point(e.x,e.y)._mult(a)});return lo(l[0],l[1],l[2],0,a,s),lo(l[2],l[3],l[0],0,a,s),Object.keys(n).map(function(t){return n[t]})}(i,[this.pointCoordinate(new t.Point(0,0)),this.pointCoordinate(new t.Point(this.width,0)),this.pointCoordinate(new t.Point(this.width,this.height)),this.pointCoordinate(new t.Point(0,this.height))],e.reparseOverscaled?o:i,this._renderWorldCopies).sort(function(t,e){return n.dist(t.canonical)-n.dist(e.canonical)})},co.prototype.resize=function(t,e){this.width=t,this.height=e,this.pixelsToGLUnits=[2/t,-2/e],this._constrain(),this._calcMatrices();},uo.unmodified.get=function(){return this._unmodified},co.prototype.zoomScale=function(t){return Math.pow(2,t)},co.prototype.scaleZoom=function(t){return Math.log(t)/Math.LN2},co.prototype.project=function(e){var i=t.clamp(e.lat,-this.maxValidLatitude,this.maxValidLatitude);return new t.Point(t.mercatorXfromLng(e.lng)*this.worldSize,t.mercatorYfromLat(i)*this.worldSize)},co.prototype.unproject=function(e){return new t.MercatorCoordinate(e.x/this.worldSize,e.y/this.worldSize).toLngLat()},uo.point.get=function(){return this.project(this.center)},co.prototype.setLocationAtPoint=function(e,i){var o=this.pointCoordinate(i),r=this.pointCoordinate(this.centerPoint),a=this.locationCoordinate(e),n=new t.MercatorCoordinate(a.x-(o.x-r.x),a.y-(o.y-r.y));this.center=this.coordinateLocation(n),this._renderWorldCopies&&(this.center=this.center.wrap());},co.prototype.locationPoint=function(t){return this.coordinatePoint(this.locationCoordinate(t))},co.prototype.pointLocation=function(t){return this.coordinateLocation(this.pointCoordinate(t))},co.prototype.locationCoordinate=function(e){return t.MercatorCoordinate.fromLngLat(e)},co.prototype.coordinateLocation=function(t){return t.toLngLat()},co.prototype.pointCoordinate=function(e){var i=[e.x,e.y,0,1],o=[e.x,e.y,1,1];t.transformMat4(i,i,this.pixelMatrixInverse),t.transformMat4(o,o,this.pixelMatrixInverse);var r=i[3],a=o[3],n=i[0]/r,s=o[0]/a,l=i[1]/r,c=o[1]/a,u=i[2]/r,h=o[2]/a,p=u===h?0:(0-u)/(h-u);return new t.MercatorCoordinate(t.number(n,s,p)/this.worldSize,t.number(l,c,p)/this.worldSize)},co.prototype.coordinatePoint=function(e){var i=[e.x*this.worldSize,e.y*this.worldSize,0,1];return t.transformMat4(i,i,this.pixelMatrix),new t.Point(i[0]/i[3],i[1]/i[3])},co.prototype.getBounds=function(){return (new t.LngLatBounds).extend(this.pointLocation(new t.Point(0,0))).extend(this.pointLocation(new t.Point(this.width,0))).extend(this.pointLocation(new t.Point(this.width,this.height))).extend(this.pointLocation(new t.Point(0,this.height)))},co.prototype.getMaxBounds=function(){return this.latRange&&2===this.latRange.length&&this.lngRange&&2===this.lngRange.length?new t.LngLatBounds([this.lngRange[0],this.latRange[0]],[this.lngRange[1],this.latRange[1]]):null},co.prototype.setMaxBounds=function(t){t?(this.lngRange=[t.getWest(),t.getEast()],this.latRange=[t.getSouth(),t.getNorth()],this._constrain()):(this.lngRange=null,this.latRange=[-this.maxValidLatitude,this.maxValidLatitude]);},co.prototype.calculatePosMatrix=function(e,i){void 0===i&&(i=!1);var o=e.key,r=i?this._alignedPosMatrixCache:this._posMatrixCache;if(r[o])return r[o];var a=e.canonical,n=this.worldSize/this.zoomScale(a.z),s=a.x+Math.pow(2,a.z)*e.wrap,l=t.identity(new Float64Array(16));return t.translate(l,l,[s*n,a.y*n,0]),t.scale(l,l,[n/t.EXTENT,n/t.EXTENT,1]),t.multiply(l,i?this.alignedProjMatrix:this.projMatrix,l),r[o]=new Float32Array(l),r[o]},co.prototype.customLayerMatrix=function(){return this.mercatorMatrix.slice()},co.prototype._constrain=function(){if(this.center&&this.width&&this.height&&!this._constraining){this._constraining=!0;var e,i,o,r,a=-90,n=90,s=-180,l=180,c=this.size,u=this._unmodified;if(this.latRange){var h=this.latRange;a=t.mercatorYfromLat(h[1])*this.worldSize,e=(n=t.mercatorYfromLat(h[0])*this.worldSize)-a<c.y?c.y/(n-a):0;}if(this.lngRange){var p=this.lngRange;s=t.mercatorXfromLng(p[0])*this.worldSize,i=(l=t.mercatorXfromLng(p[1])*this.worldSize)-s<c.x?c.x/(l-s):0;}var d=this.point,_=Math.max(i||0,e||0);if(_)return this.center=this.unproject(new t.Point(i?(l+s)/2:d.x,e?(n+a)/2:d.y)),this.zoom+=this.scaleZoom(_),this._unmodified=u,void(this._constraining=!1);if(this.latRange){var f=d.y,m=c.y/2;f-m<a&&(r=a+m),f+m>n&&(r=n-m);}if(this.lngRange){var g=d.x,v=c.x/2;g-v<s&&(o=s+v),g+v>l&&(o=l-v);}void 0===o&&void 0===r||(this.center=this.unproject(new t.Point(void 0!==o?o:d.x,void 0!==r?r:d.y))),this._unmodified=u,this._constraining=!1;}},co.prototype._calcMatrices=function(){if(this.height){this.cameraToCenterDistance=.5/Math.tan(this._fov/2)*this.height;var e=this._fov/2,i=Math.PI/2+this._pitch,o=Math.sin(e)*this.cameraToCenterDistance/Math.sin(Math.PI-i-e),r=this.point,a=r.x,n=r.y,s=1.01*(Math.cos(Math.PI/2-this._pitch)*o+this.cameraToCenterDistance),l=new Float64Array(16);t.perspective(l,this._fov,this.width/this.height,1,s),t.scale(l,l,[1,-1,1]),t.translate(l,l,[0,0,-this.cameraToCenterDistance]),t.rotateX(l,l,this._pitch),t.rotateZ(l,l,this.angle),t.translate(l,l,[-a,-n,0]),this.mercatorMatrix=t.scale([],l,[this.worldSize,this.worldSize,this.worldSize]),t.scale(l,l,[1,1,t.mercatorZfromAltitude(1,this.center.lat)*this.worldSize,1]),this.projMatrix=l;var c=this.width%2/2,u=this.height%2/2,h=Math.cos(this.angle),p=Math.sin(this.angle),d=a-Math.round(a)+h*c+p*u,_=n-Math.round(n)+h*u+p*c,f=new Float64Array(l);if(t.translate(f,f,[d>.5?d-1:d,_>.5?_-1:_,0]),this.alignedProjMatrix=f,l=t.create(),t.scale(l,l,[this.width/2,-this.height/2,1]),t.translate(l,l,[1,-1,0]),this.labelPlaneMatrix=l,l=t.create(),t.scale(l,l,[1,-1,1]),t.translate(l,l,[-1,-1,0]),t.scale(l,l,[2/this.width,2/this.height,1]),this.glCoordMatrix=l,this.pixelMatrix=t.multiply(new Float64Array(16),this.labelPlaneMatrix,this.projMatrix),!(l=t.invert(new Float64Array(16),this.pixelMatrix)))throw new Error(\"failed to invert matrix\");this.pixelMatrixInverse=l,this._posMatrixCache={},this._alignedPosMatrixCache={};}},co.prototype.maxPitchScaleFactor=function(){if(!this.pixelMatrixInverse)return 1;var e=this.pointCoordinate(new t.Point(0,0)),i=[e.x*this.worldSize,e.y*this.worldSize,0,1];return t.transformMat4(i,i,this.pixelMatrix)[3]/this.cameraToCenterDistance},co.prototype.getCameraPoint=function(){var e=this._pitch,i=Math.tan(e)*(this.cameraToCenterDistance||1);return this.centerPoint.add(new t.Point(0,i))},co.prototype.getCameraQueryGeometry=function(e){var i=this.getCameraPoint();if(1===e.length)return [e[0],i];for(var o=i.x,r=i.y,a=i.x,n=i.y,s=0,l=e;s<l.length;s+=1){var c=l[s];o=Math.min(o,c.x),r=Math.min(r,c.y),a=Math.max(a,c.x),n=Math.max(n,c.y);}return [new t.Point(o,r),new t.Point(a,r),new t.Point(a,n),new t.Point(o,n),new t.Point(o,r)]},Object.defineProperties(co.prototype,uo);var ho=function(){var e,i,o,r,a;t.bindAll([\"_onHashChange\",\"_updateHash\"],this),this._updateHash=(e=this._updateHashUnthrottled.bind(this),i=300,o=!1,r=null,a=function(){r=null,o&&(e(),r=setTimeout(a,i),o=!1);},function(){return o=!0,r||a(),r});};ho.prototype.addTo=function(e){return this._map=e,t.window.addEventListener(\"hashchange\",this._onHashChange,!1),this._map.on(\"moveend\",this._updateHash),this},ho.prototype.remove=function(){return t.window.removeEventListener(\"hashchange\",this._onHashChange,!1),this._map.off(\"moveend\",this._updateHash),clearTimeout(this._updateHash()),delete this._map,this},ho.prototype.getHashString=function(t){var e=this._map.getCenter(),i=Math.round(100*this._map.getZoom())/100,o=Math.ceil((i*Math.LN2+Math.log(512/360/.5))/Math.LN10),r=Math.pow(10,o),a=Math.round(e.lng*r)/r,n=Math.round(e.lat*r)/r,s=this._map.getBearing(),l=this._map.getPitch(),c=\"\";return c+=t?\"#/\"+a+\"/\"+n+\"/\"+i:\"#\"+i+\"/\"+n+\"/\"+a,(s||l)&&(c+=\"/\"+Math.round(10*s)/10),l&&(c+=\"/\"+Math.round(l)),c},ho.prototype._onHashChange=function(){var e=t.window.location.hash.replace(\"#\",\"\").split(\"/\");return e.length>=3&&(this._map.jumpTo({center:[+e[2],+e[1]],zoom:+e[0],bearing:+(e[3]||0),pitch:+(e[4]||0)}),!0)},ho.prototype._updateHashUnthrottled=function(){var e=this.getHashString();try{t.window.history.replaceState(t.window.history.state,\"\",e);}catch(t){}};var po=function(e){function o(o,r,a,n){void 0===n&&(n={});var s=i.mousePos(r.getCanvasContainer(),a),l=r.unproject(s);e.call(this,o,t.extend({point:s,lngLat:l,originalEvent:a},n)),this._defaultPrevented=!1,this.target=r;}e&&(o.__proto__=e),o.prototype=Object.create(e&&e.prototype),o.prototype.constructor=o;var r={defaultPrevented:{configurable:!0}};return o.prototype.preventDefault=function(){this._defaultPrevented=!0;},r.defaultPrevented.get=function(){return this._defaultPrevented},Object.defineProperties(o.prototype,r),o}(t.Event),_o=function(e){function o(o,r,a){var n=i.touchPos(r.getCanvasContainer(),a),s=n.map(function(t){return r.unproject(t)}),l=n.reduce(function(t,e,i,o){return t.add(e.div(o.length))},new t.Point(0,0)),c=r.unproject(l);e.call(this,o,{points:n,point:l,lngLats:s,lngLat:c,originalEvent:a}),this._defaultPrevented=!1;}e&&(o.__proto__=e),o.prototype=Object.create(e&&e.prototype),o.prototype.constructor=o;var r={defaultPrevented:{configurable:!0}};return o.prototype.preventDefault=function(){this._defaultPrevented=!0;},r.defaultPrevented.get=function(){return this._defaultPrevented},Object.defineProperties(o.prototype,r),o}(t.Event),fo=function(t){function e(e,i,o){t.call(this,e,{originalEvent:o}),this._defaultPrevented=!1;}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={defaultPrevented:{configurable:!0}};return e.prototype.preventDefault=function(){this._defaultPrevented=!0;},i.defaultPrevented.get=function(){return this._defaultPrevented},Object.defineProperties(e.prototype,i),e}(t.Event),mo=function(e){this._map=e,this._el=e.getCanvasContainer(),this._delta=0,this._defaultZoomRate=.01,this._wheelZoomRate=1/450,t.bindAll([\"_onWheel\",\"_onTimeout\",\"_onScrollFrame\",\"_onScrollFinished\"],this);};mo.prototype.setZoomRate=function(t){this._defaultZoomRate=t;},mo.prototype.setWheelZoomRate=function(t){this._wheelZoomRate=t;},mo.prototype.isEnabled=function(){return !!this._enabled},mo.prototype.isActive=function(){return !!this._active},mo.prototype.isZooming=function(){return !!this._zooming},mo.prototype.enable=function(t){this.isEnabled()||(this._enabled=!0,this._aroundCenter=t&&\"center\"===t.around);},mo.prototype.disable=function(){this.isEnabled()&&(this._enabled=!1);},mo.prototype.onWheel=function(e){if(this.isEnabled()){var i=e.deltaMode===t.window.WheelEvent.DOM_DELTA_LINE?40*e.deltaY:e.deltaY,o=t.browser.now(),r=o-(this._lastWheelEventTime||0);this._lastWheelEventTime=o,0!==i&&i%4.000244140625==0?this._type=\"wheel\":0!==i&&Math.abs(i)<4?this._type=\"trackpad\":r>400?(this._type=null,this._lastValue=i,this._timeout=setTimeout(this._onTimeout,40,e)):this._type||(this._type=Math.abs(r*i)<200?\"trackpad\":\"wheel\",this._timeout&&(clearTimeout(this._timeout),this._timeout=null,i+=this._lastValue)),e.shiftKey&&i&&(i/=4),this._type&&(this._lastWheelEvent=e,this._delta-=i,this.isActive()||this._start(e)),e.preventDefault();}},mo.prototype._onTimeout=function(t){this._type=\"wheel\",this._delta-=this._lastValue,this.isActive()||this._start(t);},mo.prototype._start=function(e){if(this._delta){this._frameId&&(this._map._cancelRenderFrame(this._frameId),this._frameId=null),this._active=!0,this.isZooming()||(this._zooming=!0,this._map.fire(new t.Event(\"movestart\",{originalEvent:e})),this._map.fire(new t.Event(\"zoomstart\",{originalEvent:e}))),this._finishTimeout&&clearTimeout(this._finishTimeout);var o=i.mousePos(this._el,e);this._around=t.LngLat.convert(this._aroundCenter?this._map.getCenter():this._map.unproject(o)),this._aroundPoint=this._map.transform.locationPoint(this._around),this._frameId||(this._frameId=this._map._requestRenderFrame(this._onScrollFrame));}},mo.prototype._onScrollFrame=function(){var e=this;if(this._frameId=null,this.isActive()){var i=this._map.transform;if(0!==this._delta){var o=\"wheel\"===this._type&&Math.abs(this._delta)>4.000244140625?this._wheelZoomRate:this._defaultZoomRate,r=2/(1+Math.exp(-Math.abs(this._delta*o)));this._delta<0&&0!==r&&(r=1/r);var a=\"number\"==typeof this._targetZoom?i.zoomScale(this._targetZoom):i.scale;this._targetZoom=Math.min(i.maxZoom,Math.max(i.minZoom,i.scaleZoom(a*r))),\"wheel\"===this._type&&(this._startZoom=i.zoom,this._easing=this._smoothOutEasing(200)),this._delta=0;}var n=\"number\"==typeof this._targetZoom?this._targetZoom:i.zoom,s=this._startZoom,l=this._easing,c=!1;if(\"wheel\"===this._type&&s&&l){var u=Math.min((t.browser.now()-this._lastWheelEventTime)/200,1),h=l(u);i.zoom=t.number(s,n,h),u<1?this._frameId||(this._frameId=this._map._requestRenderFrame(this._onScrollFrame)):c=!0;}else i.zoom=n,c=!0;i.setLocationAtPoint(this._around,this._aroundPoint),this._map.fire(new t.Event(\"move\",{originalEvent:this._lastWheelEvent})),this._map.fire(new t.Event(\"zoom\",{originalEvent:this._lastWheelEvent})),c&&(this._active=!1,this._finishTimeout=setTimeout(function(){e._zooming=!1,e._map.fire(new t.Event(\"zoomend\",{originalEvent:e._lastWheelEvent})),e._map.fire(new t.Event(\"moveend\",{originalEvent:e._lastWheelEvent})),delete e._targetZoom;},200));}},mo.prototype._smoothOutEasing=function(e){var i=t.ease;if(this._prevEase){var o=this._prevEase,r=(t.browser.now()-o.start)/o.duration,a=o.easing(r+.01)-o.easing(r),n=.27/Math.sqrt(a*a+1e-4)*.01,s=Math.sqrt(.0729-n*n);i=t.bezier(n,s,.25,1);}return this._prevEase={start:t.browser.now(),duration:e,easing:i},i};var go=function(e,i){this._map=e,this._el=e.getCanvasContainer(),this._container=e.getContainer(),this._clickTolerance=i.clickTolerance||1,t.bindAll([\"_onMouseMove\",\"_onMouseUp\",\"_onKeyDown\"],this);};go.prototype.isEnabled=function(){return !!this._enabled},go.prototype.isActive=function(){return !!this._active},go.prototype.enable=function(){this.isEnabled()||(this._enabled=!0);},go.prototype.disable=function(){this.isEnabled()&&(this._enabled=!1);},go.prototype.onMouseDown=function(e){this.isEnabled()&&e.shiftKey&&0===e.button&&(t.window.document.addEventListener(\"mousemove\",this._onMouseMove,!1),t.window.document.addEventListener(\"keydown\",this._onKeyDown,!1),t.window.document.addEventListener(\"mouseup\",this._onMouseUp,!1),i.disableDrag(),this._startPos=this._lastPos=i.mousePos(this._el,e),this._active=!0);},go.prototype._onMouseMove=function(t){var e=i.mousePos(this._el,t);if(!(this._lastPos.equals(e)||!this._box&&e.dist(this._startPos)<this._clickTolerance)){var o=this._startPos;this._lastPos=e,this._box||(this._box=i.create(\"div\",\"mapboxgl-boxzoom\",this._container),this._container.classList.add(\"mapboxgl-crosshair\"),this._fireEvent(\"boxzoomstart\",t));var r=Math.min(o.x,e.x),a=Math.max(o.x,e.x),n=Math.min(o.y,e.y),s=Math.max(o.y,e.y);i.setTransform(this._box,\"translate(\"+r+\"px,\"+n+\"px)\"),this._box.style.width=a-r+\"px\",this._box.style.height=s-n+\"px\";}},go.prototype._onMouseUp=function(e){if(0===e.button){var o=this._startPos,r=i.mousePos(this._el,e);this._finish(),i.suppressClick(),o.x===r.x&&o.y===r.y?this._fireEvent(\"boxzoomcancel\",e):this._map.fitScreenCoordinates(o,r,this._map.getBearing(),{linear:!0}).fire(new t.Event(\"boxzoomend\",{originalEvent:e}));}},go.prototype._onKeyDown=function(t){27===t.keyCode&&(this._finish(),this._fireEvent(\"boxzoomcancel\",t));},go.prototype._finish=function(){this._active=!1,t.window.document.removeEventListener(\"mousemove\",this._onMouseMove,!1),t.window.document.removeEventListener(\"keydown\",this._onKeyDown,!1),t.window.document.removeEventListener(\"mouseup\",this._onMouseUp,!1),this._container.classList.remove(\"mapboxgl-crosshair\"),this._box&&(i.remove(this._box),this._box=null),i.enableDrag(),delete this._startPos,delete this._lastPos;},go.prototype._fireEvent=function(e,i){return this._map.fire(new t.Event(e,{originalEvent:i}))};var vo=t.bezier(0,0,.25,1),yo=function(e,i){this._map=e,this._el=i.element||e.getCanvasContainer(),this._state=\"disabled\",this._button=i.button||\"right\",this._bearingSnap=i.bearingSnap||0,this._pitchWithRotate=!1!==i.pitchWithRotate,t.bindAll([\"onMouseDown\",\"_onMouseMove\",\"_onMouseUp\",\"_onBlur\",\"_onDragFrame\"],this);};yo.prototype.isEnabled=function(){return \"disabled\"!==this._state},yo.prototype.isActive=function(){return \"active\"===this._state},yo.prototype.enable=function(){this.isEnabled()||(this._state=\"enabled\");},yo.prototype.disable=function(){if(this.isEnabled())switch(this._state){case\"active\":this._state=\"disabled\",this._unbind(),this._deactivate(),this._fireEvent(\"rotateend\"),this._pitchWithRotate&&this._fireEvent(\"pitchend\"),this._fireEvent(\"moveend\");break;case\"pending\":this._state=\"disabled\",this._unbind();break;default:this._state=\"disabled\";}},yo.prototype.onMouseDown=function(e){if(\"enabled\"===this._state){if(\"right\"===this._button){if(this._eventButton=i.mouseButton(e),this._eventButton!==(e.ctrlKey?0:2))return}else{if(e.ctrlKey||0!==i.mouseButton(e))return;this._eventButton=0;}i.disableDrag(),t.window.document.addEventListener(\"mousemove\",this._onMouseMove,{capture:!0}),t.window.document.addEventListener(\"mouseup\",this._onMouseUp),t.window.addEventListener(\"blur\",this._onBlur),this._state=\"pending\",this._inertia=[[t.browser.now(),this._map.getBearing()]],this._startPos=this._lastPos=i.mousePos(this._el,e),this._center=this._map.transform.centerPoint,e.preventDefault();}},yo.prototype._onMouseMove=function(t){var e=i.mousePos(this._el,t);this._lastPos.equals(e)||(this._lastMoveEvent=t,this._lastPos=e,\"pending\"===this._state&&(this._state=\"active\",this._fireEvent(\"rotatestart\",t),this._fireEvent(\"movestart\",t),this._pitchWithRotate&&this._fireEvent(\"pitchstart\",t)),this._frameId||(this._frameId=this._map._requestRenderFrame(this._onDragFrame)));},yo.prototype._onDragFrame=function(){this._frameId=null;var e=this._lastMoveEvent;if(e){var i=this._map.transform,o=this._startPos,r=this._lastPos,a=.8*(o.x-r.x),n=-.5*(o.y-r.y),s=i.bearing-a,l=i.pitch-n,c=this._inertia,u=c[c.length-1];this._drainInertiaBuffer(),c.push([t.browser.now(),this._map._normalizeBearing(s,u[1])]),i.bearing=s,this._pitchWithRotate&&(this._fireEvent(\"pitch\",e),i.pitch=l),this._fireEvent(\"rotate\",e),this._fireEvent(\"move\",e),delete this._lastMoveEvent,this._startPos=this._lastPos;}},yo.prototype._onMouseUp=function(t){if(i.mouseButton(t)===this._eventButton)switch(this._state){case\"active\":this._state=\"enabled\",i.suppressClick(),this._unbind(),this._deactivate(),this._inertialRotate(t);break;case\"pending\":this._state=\"enabled\",this._unbind();}},yo.prototype._onBlur=function(t){switch(this._state){case\"active\":this._state=\"enabled\",this._unbind(),this._deactivate(),this._fireEvent(\"rotateend\",t),this._pitchWithRotate&&this._fireEvent(\"pitchend\",t),this._fireEvent(\"moveend\",t);break;case\"pending\":this._state=\"enabled\",this._unbind();}},yo.prototype._unbind=function(){t.window.document.removeEventListener(\"mousemove\",this._onMouseMove,{capture:!0}),t.window.document.removeEventListener(\"mouseup\",this._onMouseUp),t.window.removeEventListener(\"blur\",this._onBlur),i.enableDrag();},yo.prototype._deactivate=function(){this._frameId&&(this._map._cancelRenderFrame(this._frameId),this._frameId=null),delete this._lastMoveEvent,delete this._startPos,delete this._lastPos;},yo.prototype._inertialRotate=function(t){var e=this;this._fireEvent(\"rotateend\",t),this._drainInertiaBuffer();var i=this._map,o=i.getBearing(),r=this._inertia,a=function(){Math.abs(o)<e._bearingSnap?i.resetNorth({noMoveStart:!0},{originalEvent:t}):e._fireEvent(\"moveend\",t),e._pitchWithRotate&&e._fireEvent(\"pitchend\",t);};if(r.length<2)a();else{var n=r[0],s=r[r.length-1],l=r[r.length-2],c=i._normalizeBearing(o,l[1]),u=s[1]-n[1],h=u<0?-1:1,p=(s[0]-n[0])/1e3;if(0!==u&&0!==p){var d=Math.abs(u*(.25/p));d>180&&(d=180);var _=d/180;c+=h*d*(_/2),Math.abs(i._normalizeBearing(c,0))<this._bearingSnap&&(c=i._normalizeBearing(0,c)),i.rotateTo(c,{duration:1e3*_,easing:vo,noMoveStart:!0},{originalEvent:t});}else a();}},yo.prototype._fireEvent=function(e,i){return this._map.fire(new t.Event(e,i?{originalEvent:i}:{}))},yo.prototype._drainInertiaBuffer=function(){for(var e=this._inertia,i=t.browser.now();e.length>0&&i-e[0][0]>160;)e.shift();};var xo=t.bezier(0,0,.3,1),bo=function(e,i){this._map=e,this._el=e.getCanvasContainer(),this._state=\"disabled\",this._clickTolerance=i.clickTolerance||1,t.bindAll([\"_onMove\",\"_onMouseUp\",\"_onTouchEnd\",\"_onBlur\",\"_onDragFrame\"],this);};bo.prototype.isEnabled=function(){return \"disabled\"!==this._state},bo.prototype.isActive=function(){return \"active\"===this._state},bo.prototype.enable=function(){this.isEnabled()||(this._el.classList.add(\"mapboxgl-touch-drag-pan\"),this._state=\"enabled\");},bo.prototype.disable=function(){if(this.isEnabled())switch(this._el.classList.remove(\"mapboxgl-touch-drag-pan\"),this._state){case\"active\":this._state=\"disabled\",this._unbind(),this._deactivate(),this._fireEvent(\"dragend\"),this._fireEvent(\"moveend\");break;case\"pending\":this._state=\"disabled\",this._unbind();break;default:this._state=\"disabled\";}},bo.prototype.onMouseDown=function(e){\"enabled\"===this._state&&(e.ctrlKey||0!==i.mouseButton(e)||(i.addEventListener(t.window.document,\"mousemove\",this._onMove,{capture:!0}),i.addEventListener(t.window.document,\"mouseup\",this._onMouseUp),this._start(e)));},bo.prototype.onTouchStart=function(e){\"enabled\"===this._state&&(e.touches.length>1||(i.addEventListener(t.window.document,\"touchmove\",this._onMove,{capture:!0,passive:!1}),i.addEventListener(t.window.document,\"touchend\",this._onTouchEnd),this._start(e)));},bo.prototype._start=function(e){t.window.addEventListener(\"blur\",this._onBlur),this._state=\"pending\",this._startPos=this._mouseDownPos=this._lastPos=i.mousePos(this._el,e),this._inertia=[[t.browser.now(),this._startPos]];},bo.prototype._onMove=function(e){e.preventDefault();var o=i.mousePos(this._el,e);this._lastPos.equals(o)||\"pending\"===this._state&&o.dist(this._mouseDownPos)<this._clickTolerance||(this._lastMoveEvent=e,this._lastPos=o,this._drainInertiaBuffer(),this._inertia.push([t.browser.now(),this._lastPos]),\"pending\"===this._state&&(this._state=\"active\",this._fireEvent(\"dragstart\",e),this._fireEvent(\"movestart\",e)),this._frameId||(this._frameId=this._map._requestRenderFrame(this._onDragFrame)));},bo.prototype._onDragFrame=function(){this._frameId=null;var t=this._lastMoveEvent;if(t){var e=this._map.transform;e.setLocationAtPoint(e.pointLocation(this._startPos),this._lastPos),this._fireEvent(\"drag\",t),this._fireEvent(\"move\",t),this._startPos=this._lastPos,delete this._lastMoveEvent;}},bo.prototype._onMouseUp=function(t){if(0===i.mouseButton(t))switch(this._state){case\"active\":this._state=\"enabled\",i.suppressClick(),this._unbind(),this._deactivate(),this._inertialPan(t);break;case\"pending\":this._state=\"enabled\",this._unbind();}},bo.prototype._onTouchEnd=function(t){switch(this._state){case\"active\":this._state=\"enabled\",this._unbind(),this._deactivate(),this._inertialPan(t);break;case\"pending\":this._state=\"enabled\",this._unbind();}},bo.prototype._onBlur=function(t){switch(this._state){case\"active\":this._state=\"enabled\",this._unbind(),this._deactivate(),this._fireEvent(\"dragend\",t),this._fireEvent(\"moveend\",t);break;case\"pending\":this._state=\"enabled\",this._unbind();}},bo.prototype._unbind=function(){i.removeEventListener(t.window.document,\"touchmove\",this._onMove,{capture:!0,passive:!1}),i.removeEventListener(t.window.document,\"touchend\",this._onTouchEnd),i.removeEventListener(t.window.document,\"mousemove\",this._onMove,{capture:!0}),i.removeEventListener(t.window.document,\"mouseup\",this._onMouseUp),i.removeEventListener(t.window,\"blur\",this._onBlur);},bo.prototype._deactivate=function(){this._frameId&&(this._map._cancelRenderFrame(this._frameId),this._frameId=null),delete this._lastMoveEvent,delete this._startPos,delete this._mouseDownPos,delete this._lastPos;},bo.prototype._inertialPan=function(t){this._fireEvent(\"dragend\",t),this._drainInertiaBuffer();var e=this._inertia;if(e.length<2)this._fireEvent(\"moveend\",t);else{var i=e[e.length-1],o=e[0],r=i[1].sub(o[1]),a=(i[0]-o[0])/1e3;if(0===a||i[1].equals(o[1]))this._fireEvent(\"moveend\",t);else{var n=r.mult(.3/a),s=n.mag();s>1400&&(s=1400,n._unit()._mult(s));var l=s/750,c=n.mult(-l/2);this._map.panBy(c,{duration:1e3*l,easing:xo,noMoveStart:!0},{originalEvent:t});}}},bo.prototype._fireEvent=function(e,i){return this._map.fire(new t.Event(e,i?{originalEvent:i}:{}))},bo.prototype._drainInertiaBuffer=function(){for(var e=this._inertia,i=t.browser.now();e.length>0&&i-e[0][0]>160;)e.shift();};var wo=function(e){this._map=e,this._el=e.getCanvasContainer(),t.bindAll([\"_onKeyDown\"],this);};function Eo(t){return t*(2-t)}wo.prototype.isEnabled=function(){return !!this._enabled},wo.prototype.enable=function(){this.isEnabled()||(this._el.addEventListener(\"keydown\",this._onKeyDown,!1),this._enabled=!0);},wo.prototype.disable=function(){this.isEnabled()&&(this._el.removeEventListener(\"keydown\",this._onKeyDown),this._enabled=!1);},wo.prototype._onKeyDown=function(t){if(!(t.altKey||t.ctrlKey||t.metaKey)){var e=0,i=0,o=0,r=0,a=0;switch(t.keyCode){case 61:case 107:case 171:case 187:e=1;break;case 189:case 109:case 173:e=-1;break;case 37:t.shiftKey?i=-1:(t.preventDefault(),r=-1);break;case 39:t.shiftKey?i=1:(t.preventDefault(),r=1);break;case 38:t.shiftKey?o=1:(t.preventDefault(),a=-1);break;case 40:t.shiftKey?o=-1:(a=1,t.preventDefault());break;default:return}var n=this._map,s=n.getZoom(),l={duration:300,delayEndEvents:500,easing:Eo,zoom:e?Math.round(s)+e*(t.shiftKey?2:1):s,bearing:n.getBearing()+15*i,pitch:n.getPitch()+10*o,offset:[100*-r,100*-a],center:n.getCenter()};n.easeTo(l,{originalEvent:t});}};var To=function(e){this._map=e,t.bindAll([\"_onDblClick\",\"_onZoomEnd\"],this);};To.prototype.isEnabled=function(){return !!this._enabled},To.prototype.isActive=function(){return !!this._active},To.prototype.enable=function(){this.isEnabled()||(this._enabled=!0);},To.prototype.disable=function(){this.isEnabled()&&(this._enabled=!1);},To.prototype.onTouchStart=function(t){var e=this;if(this.isEnabled()&&!(t.points.length>1))if(this._tapped){var i=t.points[0],o=this._tappedPoint;if(o&&o.dist(i)<=30){t.originalEvent.preventDefault();var r=function(){e._tapped&&e._zoom(t),e._map.off(\"touchcancel\",a),e._resetTapped();},a=function(){e._map.off(\"touchend\",r),e._resetTapped();};this._map.once(\"touchend\",r),this._map.once(\"touchcancel\",a);}else this._resetTapped();}else this._tappedPoint=t.points[0],this._tapped=setTimeout(function(){e._tapped=null,e._tappedPoint=null;},300);},To.prototype._resetTapped=function(){clearTimeout(this._tapped),this._tapped=null,this._tappedPoint=null;},To.prototype.onDblClick=function(t){this.isEnabled()&&(t.originalEvent.preventDefault(),this._zoom(t));},To.prototype._zoom=function(t){this._active=!0,this._map.on(\"zoomend\",this._onZoomEnd),this._map.zoomTo(this._map.getZoom()+(t.originalEvent.shiftKey?-1:1),{around:t.lngLat},t);},To.prototype._onZoomEnd=function(){this._active=!1,this._map.off(\"zoomend\",this._onZoomEnd);};var Io=t.bezier(0,0,.15,1),Co=function(e){this._map=e,this._el=e.getCanvasContainer(),t.bindAll([\"_onMove\",\"_onEnd\",\"_onTouchFrame\"],this);};Co.prototype.isEnabled=function(){return !!this._enabled},Co.prototype.enable=function(t){this.isEnabled()||(this._el.classList.add(\"mapboxgl-touch-zoom-rotate\"),this._enabled=!0,this._aroundCenter=!!t&&\"center\"===t.around);},Co.prototype.disable=function(){this.isEnabled()&&(this._el.classList.remove(\"mapboxgl-touch-zoom-rotate\"),this._enabled=!1);},Co.prototype.disableRotation=function(){this._rotationDisabled=!0;},Co.prototype.enableRotation=function(){this._rotationDisabled=!1;},Co.prototype.onStart=function(e){if(this.isEnabled()&&2===e.touches.length){var o=i.mousePos(this._el,e.touches[0]),r=i.mousePos(this._el,e.touches[1]),a=o.add(r).div(2);this._startVec=o.sub(r),this._startAround=this._map.transform.pointLocation(a),this._gestureIntent=void 0,this._inertia=[],i.addEventListener(t.window.document,\"touchmove\",this._onMove,{passive:!1}),i.addEventListener(t.window.document,\"touchend\",this._onEnd);}},Co.prototype._getTouchEventData=function(t){var e=i.mousePos(this._el,t.touches[0]),o=i.mousePos(this._el,t.touches[1]),r=e.sub(o);return {vec:r,center:e.add(o).div(2),scale:r.mag()/this._startVec.mag(),bearing:this._rotationDisabled?0:180*r.angleWith(this._startVec)/Math.PI}},Co.prototype._onMove=function(e){if(2===e.touches.length){var i=this._getTouchEventData(e),o=i.vec,r=i.scale,a=i.bearing;if(!this._gestureIntent){var n=this._rotationDisabled&&1!==r||Math.abs(1-r)>.15;Math.abs(a)>10?this._gestureIntent=\"rotate\":n&&(this._gestureIntent=\"zoom\"),this._gestureIntent&&(this._map.fire(new t.Event(this._gestureIntent+\"start\",{originalEvent:e})),this._map.fire(new t.Event(\"movestart\",{originalEvent:e})),this._startVec=o);}this._lastTouchEvent=e,this._frameId||(this._frameId=this._map._requestRenderFrame(this._onTouchFrame)),e.preventDefault();}},Co.prototype._onTouchFrame=function(){this._frameId=null;var e=this._gestureIntent;if(e){var i=this._map.transform;this._startScale||(this._startScale=i.scale,this._startBearing=i.bearing);var o=this._getTouchEventData(this._lastTouchEvent),r=o.center,a=o.bearing,n=o.scale,s=i.pointLocation(r),l=i.locationPoint(s);\"rotate\"===e&&(i.bearing=this._startBearing+a),i.zoom=i.scaleZoom(this._startScale*n),i.setLocationAtPoint(this._startAround,l),this._map.fire(new t.Event(e,{originalEvent:this._lastTouchEvent})),this._map.fire(new t.Event(\"move\",{originalEvent:this._lastTouchEvent})),this._drainInertiaBuffer(),this._inertia.push([t.browser.now(),n,r]);}},Co.prototype._onEnd=function(e){i.removeEventListener(t.window.document,\"touchmove\",this._onMove,{passive:!1}),i.removeEventListener(t.window.document,\"touchend\",this._onEnd);var o=this._gestureIntent,r=this._startScale;if(this._frameId&&(this._map._cancelRenderFrame(this._frameId),this._frameId=null),delete this._gestureIntent,delete this._startScale,delete this._startBearing,delete this._lastTouchEvent,o){this._map.fire(new t.Event(o+\"end\",{originalEvent:e})),this._drainInertiaBuffer();var a=this._inertia,n=this._map;if(a.length<2)n.snapToNorth({},{originalEvent:e});else{var s=a[a.length-1],l=a[0],c=n.transform.scaleZoom(r*s[1]),u=n.transform.scaleZoom(r*l[1]),h=c-u,p=(s[0]-l[0])/1e3,d=s[2];if(0!==p&&c!==u){var _=.15*h/p;Math.abs(_)>2.5&&(_=_>0?2.5:-2.5);var f=1e3*Math.abs(_/(12*.15)),m=c+_*f/2e3;m<0&&(m=0),n.easeTo({zoom:m,duration:f,easing:Io,around:this._aroundCenter?n.getCenter():n.unproject(d),noMoveStart:!0},{originalEvent:e});}else n.snapToNorth({},{originalEvent:e});}}},Co.prototype._drainInertiaBuffer=function(){for(var e=this._inertia,i=t.browser.now();e.length>2&&i-e[0][0]>160;)e.shift();};var So={scrollZoom:mo,boxZoom:go,dragRotate:yo,dragPan:bo,keyboard:wo,doubleClickZoom:To,touchZoomRotate:Co};var Po=function(e){function i(i,o){e.call(this),this._moving=!1,this._zooming=!1,this.transform=i,this._bearingSnap=o.bearingSnap,t.bindAll([\"_renderFrameCallback\"],this);}return e&&(i.__proto__=e),i.prototype=Object.create(e&&e.prototype),i.prototype.constructor=i,i.prototype.getCenter=function(){return new t.LngLat(this.transform.center.lng,this.transform.center.lat)},i.prototype.setCenter=function(t,e){return this.jumpTo({center:t},e)},i.prototype.panBy=function(e,i,o){return e=t.Point.convert(e).mult(-1),this.panTo(this.transform.center,t.extend({offset:e},i),o)},i.prototype.panTo=function(e,i,o){return this.easeTo(t.extend({center:e},i),o)},i.prototype.getZoom=function(){return this.transform.zoom},i.prototype.setZoom=function(t,e){return this.jumpTo({zoom:t},e),this},i.prototype.zoomTo=function(e,i,o){return this.easeTo(t.extend({zoom:e},i),o)},i.prototype.zoomIn=function(t,e){return this.zoomTo(this.getZoom()+1,t,e),this},i.prototype.zoomOut=function(t,e){return this.zoomTo(this.getZoom()-1,t,e),this},i.prototype.getBearing=function(){return this.transform.bearing},i.prototype.setBearing=function(t,e){return this.jumpTo({bearing:t},e),this},i.prototype.rotateTo=function(e,i,o){return this.easeTo(t.extend({bearing:e},i),o)},i.prototype.resetNorth=function(e,i){return this.rotateTo(0,t.extend({duration:1e3},e),i),this},i.prototype.snapToNorth=function(t,e){return Math.abs(this.getBearing())<this._bearingSnap?this.resetNorth(t,e):this},i.prototype.getPitch=function(){return this.transform.pitch},i.prototype.setPitch=function(t,e){return this.jumpTo({pitch:t},e),this},i.prototype.cameraForBounds=function(e,i){return e=t.LngLatBounds.convert(e),this._cameraForBoxAndBearing(e.getNorthWest(),e.getSouthEast(),0,i)},i.prototype._cameraForBoxAndBearing=function(e,i,o,r){if(\"number\"==typeof(r=t.extend({padding:{top:0,bottom:0,right:0,left:0},offset:[0,0],maxZoom:this.transform.maxZoom},r)).padding){var a=r.padding;r.padding={top:a,bottom:a,right:a,left:a};}if(t.deepEqual(Object.keys(r.padding).sort(function(t,e){return t<e?-1:t>e?1:0}),[\"bottom\",\"left\",\"right\",\"top\"])){var n=this.transform,s=n.project(t.LngLat.convert(e)),l=n.project(t.LngLat.convert(i)),c=s.rotate(-o*Math.PI/180),u=l.rotate(-o*Math.PI/180),h=new t.Point(Math.max(c.x,u.x),Math.max(c.y,u.y)),p=new t.Point(Math.min(c.x,u.x),Math.min(c.y,u.y)),d=h.sub(p),_=(n.width-r.padding.left-r.padding.right)/d.x,f=(n.height-r.padding.top-r.padding.bottom)/d.y;if(!(f<0||_<0)){var m=Math.min(n.scaleZoom(n.scale*Math.min(_,f)),r.maxZoom),g=t.Point.convert(r.offset),v=(r.padding.left-r.padding.right)/2,y=(r.padding.top-r.padding.bottom)/2,x=new t.Point(g.x+v,g.y+y).mult(n.scale/n.zoomScale(m));return {center:n.unproject(s.add(l).div(2).sub(x)),zoom:m,bearing:o}}t.warnOnce(\"Map cannot fit within canvas with the given bounds, padding, and/or offset.\");}else t.warnOnce(\"options.padding must be a positive number, or an Object with keys 'bottom', 'left', 'right', 'top'\");},i.prototype.fitBounds=function(t,e,i){return this._fitInternal(this.cameraForBounds(t,e),e,i)},i.prototype.fitScreenCoordinates=function(e,i,o,r,a){return this._fitInternal(this._cameraForBoxAndBearing(this.transform.pointLocation(t.Point.convert(e)),this.transform.pointLocation(t.Point.convert(i)),o,r),r,a)},i.prototype._fitInternal=function(e,i,o){return e?(i=t.extend(e,i)).linear?this.easeTo(i,o):this.flyTo(i,o):this},i.prototype.jumpTo=function(e,i){this.stop();var o=this.transform,r=!1,a=!1,n=!1;return \"zoom\"in e&&o.zoom!==+e.zoom&&(r=!0,o.zoom=+e.zoom),void 0!==e.center&&(o.center=t.LngLat.convert(e.center)),\"bearing\"in e&&o.bearing!==+e.bearing&&(a=!0,o.bearing=+e.bearing),\"pitch\"in e&&o.pitch!==+e.pitch&&(n=!0,o.pitch=+e.pitch),this.fire(new t.Event(\"movestart\",i)).fire(new t.Event(\"move\",i)),r&&this.fire(new t.Event(\"zoomstart\",i)).fire(new t.Event(\"zoom\",i)).fire(new t.Event(\"zoomend\",i)),a&&this.fire(new t.Event(\"rotatestart\",i)).fire(new t.Event(\"rotate\",i)).fire(new t.Event(\"rotateend\",i)),n&&this.fire(new t.Event(\"pitchstart\",i)).fire(new t.Event(\"pitch\",i)).fire(new t.Event(\"pitchend\",i)),this.fire(new t.Event(\"moveend\",i))},i.prototype.easeTo=function(e,i){var o=this;this.stop(),!1===(e=t.extend({offset:[0,0],duration:500,easing:t.ease},e)).animate&&(e.duration=0);var r=this.transform,a=this.getZoom(),n=this.getBearing(),s=this.getPitch(),l=\"zoom\"in e?+e.zoom:a,c=\"bearing\"in e?this._normalizeBearing(e.bearing,n):n,u=\"pitch\"in e?+e.pitch:s,h=r.centerPoint.add(t.Point.convert(e.offset)),p=r.pointLocation(h),d=t.LngLat.convert(e.center||p);this._normalizeCenter(d);var _,f,m=r.project(p),g=r.project(d).sub(m),v=r.zoomScale(l-a);return e.around&&(_=t.LngLat.convert(e.around),f=r.locationPoint(_)),this._zooming=l!==a,this._rotating=n!==c,this._pitching=u!==s,this._prepareEase(i,e.noMoveStart),clearTimeout(this._easeEndTimeoutID),this._ease(function(e){if(o._zooming&&(r.zoom=t.number(a,l,e)),o._rotating&&(r.bearing=t.number(n,c,e)),o._pitching&&(r.pitch=t.number(s,u,e)),_)r.setLocationAtPoint(_,f);else{var p=r.zoomScale(r.zoom-a),d=l>a?Math.min(2,v):Math.max(.5,v),y=Math.pow(d,1-e),x=r.unproject(m.add(g.mult(e*y)).mult(p));r.setLocationAtPoint(r.renderWorldCopies?x.wrap():x,h);}o._fireMoveEvents(i);},function(){e.delayEndEvents?o._easeEndTimeoutID=setTimeout(function(){return o._afterEase(i)},e.delayEndEvents):o._afterEase(i);},e),this},i.prototype._prepareEase=function(e,i){this._moving=!0,i||this.fire(new t.Event(\"movestart\",e)),this._zooming&&this.fire(new t.Event(\"zoomstart\",e)),this._rotating&&this.fire(new t.Event(\"rotatestart\",e)),this._pitching&&this.fire(new t.Event(\"pitchstart\",e));},i.prototype._fireMoveEvents=function(e){this.fire(new t.Event(\"move\",e)),this._zooming&&this.fire(new t.Event(\"zoom\",e)),this._rotating&&this.fire(new t.Event(\"rotate\",e)),this._pitching&&this.fire(new t.Event(\"pitch\",e));},i.prototype._afterEase=function(e){var i=this._zooming,o=this._rotating,r=this._pitching;this._moving=!1,this._zooming=!1,this._rotating=!1,this._pitching=!1,i&&this.fire(new t.Event(\"zoomend\",e)),o&&this.fire(new t.Event(\"rotateend\",e)),r&&this.fire(new t.Event(\"pitchend\",e)),this.fire(new t.Event(\"moveend\",e));},i.prototype.flyTo=function(e,i){var o=this;this.stop(),e=t.extend({offset:[0,0],speed:1.2,curve:1.42,easing:t.ease},e);var r=this.transform,a=this.getZoom(),n=this.getBearing(),s=this.getPitch(),l=\"zoom\"in e?t.clamp(+e.zoom,r.minZoom,r.maxZoom):a,c=\"bearing\"in e?this._normalizeBearing(e.bearing,n):n,u=\"pitch\"in e?+e.pitch:s,h=r.zoomScale(l-a),p=r.centerPoint.add(t.Point.convert(e.offset)),d=r.pointLocation(p),_=t.LngLat.convert(e.center||d);this._normalizeCenter(_);var f=r.project(d),m=r.project(_).sub(f),g=e.curve,v=Math.max(r.width,r.height),y=v/h,x=m.mag();if(\"minZoom\"in e){var b=t.clamp(Math.min(e.minZoom,a,l),r.minZoom,r.maxZoom),w=v/r.zoomScale(b-a);g=Math.sqrt(w/x*2);}var E=g*g;function T(t){var e=(y*y-v*v+(t?-1:1)*E*E*x*x)/(2*(t?y:v)*E*x);return Math.log(Math.sqrt(e*e+1)-e)}function I(t){return (Math.exp(t)-Math.exp(-t))/2}function C(t){return (Math.exp(t)+Math.exp(-t))/2}var S=T(0),P=function(t){return C(S)/C(S+g*t)},z=function(t){return v*((C(S)*(I(e=S+g*t)/C(e))-I(S))/E)/x;var e;},L=(T(1)-S)/g;if(Math.abs(x)<1e-6||!isFinite(L)){if(Math.abs(v-y)<1e-6)return this.easeTo(e,i);var D=y<v?-1:1;L=Math.abs(Math.log(y/v))/g,z=function(){return 0},P=function(t){return Math.exp(D*g*t)};}if(\"duration\"in e)e.duration=+e.duration;else{var M=\"screenSpeed\"in e?+e.screenSpeed/g:+e.speed;e.duration=1e3*L/M;}return e.maxDuration&&e.duration>e.maxDuration&&(e.duration=0),this._zooming=!0,this._rotating=n!==c,this._pitching=u!==s,this._prepareEase(i,!1),this._ease(function(e){var h=e*L,d=1/P(h);r.zoom=1===e?l:a+r.scaleZoom(d),o._rotating&&(r.bearing=t.number(n,c,e)),o._pitching&&(r.pitch=t.number(s,u,e));var g=1===e?_:r.unproject(f.add(m.mult(z(h))).mult(d));r.setLocationAtPoint(r.renderWorldCopies?g.wrap():g,p),o._fireMoveEvents(i);},function(){return o._afterEase(i)},e),this},i.prototype.isEasing=function(){return !!this._easeFrameId},i.prototype.stop=function(){if(this._easeFrameId&&(this._cancelRenderFrame(this._easeFrameId),delete this._easeFrameId,delete this._onEaseFrame),this._onEaseEnd){var t=this._onEaseEnd;delete this._onEaseEnd,t.call(this);}return this},i.prototype._ease=function(e,i,o){!1===o.animate||0===o.duration?(e(1),i()):(this._easeStart=t.browser.now(),this._easeOptions=o,this._onEaseFrame=e,this._onEaseEnd=i,this._easeFrameId=this._requestRenderFrame(this._renderFrameCallback));},i.prototype._renderFrameCallback=function(){var e=Math.min((t.browser.now()-this._easeStart)/this._easeOptions.duration,1);this._onEaseFrame(this._easeOptions.easing(e)),e<1?this._easeFrameId=this._requestRenderFrame(this._renderFrameCallback):this.stop();},i.prototype._normalizeBearing=function(e,i){e=t.wrap(e,-180,180);var o=Math.abs(e-i);return Math.abs(e-360-i)<o&&(e-=360),Math.abs(e+360-i)<o&&(e+=360),e},i.prototype._normalizeCenter=function(t){var e=this.transform;if(e.renderWorldCopies&&!e.lngRange){var i=t.lng-e.center.lng;t.lng+=i>180?-360:i<-180?360:0;}},i}(t.Evented),zo=function(e){void 0===e&&(e={}),this.options=e,t.bindAll([\"_updateEditLink\",\"_updateData\",\"_updateCompact\"],this);};zo.prototype.getDefaultPosition=function(){return \"bottom-right\"},zo.prototype.onAdd=function(t){var e=this.options&&this.options.compact;return this._map=t,this._container=i.create(\"div\",\"mapboxgl-ctrl mapboxgl-ctrl-attrib\"),this._innerContainer=i.create(\"div\",\"mapboxgl-ctrl-attrib-inner\",this._container),e&&this._container.classList.add(\"mapboxgl-compact\"),this._updateAttributions(),this._updateEditLink(),this._map.on(\"styledata\",this._updateData),this._map.on(\"sourcedata\",this._updateData),this._map.on(\"moveend\",this._updateEditLink),void 0===e&&(this._map.on(\"resize\",this._updateCompact),this._updateCompact()),this._container},zo.prototype.onRemove=function(){i.remove(this._container),this._map.off(\"styledata\",this._updateData),this._map.off(\"sourcedata\",this._updateData),this._map.off(\"moveend\",this._updateEditLink),this._map.off(\"resize\",this._updateCompact),this._map=void 0;},zo.prototype._updateEditLink=function(){var e=this._editLink;e||(e=this._editLink=this._container.querySelector(\".mapbox-improve-map\"));var i=[{key:\"owner\",value:this.styleOwner},{key:\"id\",value:this.styleId},{key:\"access_token\",value:t.config.ACCESS_TOKEN}];if(e){var o=i.reduce(function(t,e,o){return e.value&&(t+=e.key+\"=\"+e.value+(o<i.length-1?\"&\":\"\")),t},\"?\");e.href=t.config.FEEDBACK_URL+\"/\"+o+(this._map._hash?this._map._hash.getHashString(!0):\"\"),e.rel=\"noopener nofollow\";}},zo.prototype._updateData=function(t){!t||\"metadata\"!==t.sourceDataType&&\"style\"!==t.dataType||(this._updateAttributions(),this._updateEditLink());},zo.prototype._updateAttributions=function(){if(this._map.style){var t=[];if(this.options.customAttribution&&(Array.isArray(this.options.customAttribution)?t=t.concat(this.options.customAttribution.map(function(t){return \"string\"!=typeof t?\"\":t})):\"string\"==typeof this.options.customAttribution&&t.push(this.options.customAttribution)),this._map.style.stylesheet){var e=this._map.style.stylesheet;this.styleOwner=e.owner,this.styleId=e.id;}var i=this._map.style.sourceCaches;for(var o in i){var r=i[o];if(r.used){var a=r.getSource();a.attribution&&t.indexOf(a.attribution)<0&&t.push(a.attribution);}}t.sort(function(t,e){return t.length-e.length});var n=(t=t.filter(function(e,i){for(var o=i+1;o<t.length;o++)if(t[o].indexOf(e)>=0)return !1;return !0})).join(\" | \");n!==this._attribHTML&&(this._attribHTML=n,t.length?(this._innerContainer.innerHTML=n,this._container.classList.remove(\"mapboxgl-attrib-empty\")):this._container.classList.add(\"mapboxgl-attrib-empty\"),this._editLink=null);}},zo.prototype._updateCompact=function(){this._map.getCanvasContainer().offsetWidth<=640?this._container.classList.add(\"mapboxgl-compact\"):this._container.classList.remove(\"mapboxgl-compact\");};var Lo=function(){t.bindAll([\"_updateLogo\"],this),t.bindAll([\"_updateCompact\"],this);};Lo.prototype.onAdd=function(t){this._map=t,this._container=i.create(\"div\",\"mapboxgl-ctrl\");var e=i.create(\"a\",\"mapboxgl-ctrl-logo\");return e.target=\"_blank\",e.rel=\"noopener nofollow\",e.href=\"https://www.mapbox.com/\",e.setAttribute(\"aria-label\",\"Mapbox logo\"),e.setAttribute(\"rel\",\"noopener nofollow\"),this._container.appendChild(e),this._container.style.display=\"none\",this._map.on(\"sourcedata\",this._updateLogo),this._updateLogo(),this._map.on(\"resize\",this._updateCompact),this._updateCompact(),this._container},Lo.prototype.onRemove=function(){i.remove(this._container),this._map.off(\"sourcedata\",this._updateLogo),this._map.off(\"resize\",this._updateCompact);},Lo.prototype.getDefaultPosition=function(){return \"bottom-left\"},Lo.prototype._updateLogo=function(t){t&&\"metadata\"!==t.sourceDataType||(this._container.style.display=this._logoRequired()?\"block\":\"none\");},Lo.prototype._logoRequired=function(){if(this._map.style){var t=this._map.style.sourceCaches;for(var e in t){if(t[e].getSource().mapbox_logo)return !0}return !1}},Lo.prototype._updateCompact=function(){var t=this._container.children;if(t.length){var e=t[0];this._map.getCanvasContainer().offsetWidth<250?e.classList.add(\"mapboxgl-compact\"):e.classList.remove(\"mapboxgl-compact\");}};var Do=function(){this._queue=[],this._id=0,this._cleared=!1,this._currentlyRunning=!1;};Do.prototype.add=function(t){var e=++this._id;return this._queue.push({callback:t,id:e,cancelled:!1}),e},Do.prototype.remove=function(t){for(var e=this._currentlyRunning,i=0,o=e?this._queue.concat(e):this._queue;i<o.length;i+=1){var r=o[i];if(r.id===t)return void(r.cancelled=!0)}},Do.prototype.run=function(){var t=this._currentlyRunning=this._queue;this._queue=[];for(var e=0,i=t;e<i.length;e+=1){var o=i[e];if(!o.cancelled&&(o.callback(),this._cleared))break}this._cleared=!1,this._currentlyRunning=!1;},Do.prototype.clear=function(){this._currentlyRunning&&(this._cleared=!0),this._queue=[];};var Mo=t.window.HTMLImageElement,Ro=t.window.HTMLElement,Ao={center:[0,0],zoom:0,bearing:0,pitch:0,minZoom:0,maxZoom:22,interactive:!0,scrollZoom:!0,boxZoom:!0,dragRotate:!0,dragPan:!0,keyboard:!0,doubleClickZoom:!0,touchZoomRotate:!0,bearingSnap:7,clickTolerance:3,hash:!1,attributionControl:!0,failIfMajorPerformanceCaveat:!1,preserveDrawingBuffer:!1,trackResize:!0,renderWorldCopies:!0,refreshExpiredTiles:!0,maxTileCacheSize:null,localIdeographFontFamily:\"sans-serif\",transformRequest:null,fadeDuration:300,crossSourceCollisions:!0},ko=function(o){function r(e){var r=this;if(null!=(e=t.extend({},Ao,e)).minZoom&&null!=e.maxZoom&&e.minZoom>e.maxZoom)throw new Error(\"maxZoom must be greater than minZoom\");var a=new co(e.minZoom,e.maxZoom,e.renderWorldCopies);if(o.call(this,a,e),this._interactive=e.interactive,this._maxTileCacheSize=e.maxTileCacheSize,this._failIfMajorPerformanceCaveat=e.failIfMajorPerformanceCaveat,this._preserveDrawingBuffer=e.preserveDrawingBuffer,this._antialias=e.antialias,this._trackResize=e.trackResize,this._bearingSnap=e.bearingSnap,this._refreshExpiredTiles=e.refreshExpiredTiles,this._fadeDuration=e.fadeDuration,this._crossSourceCollisions=e.crossSourceCollisions,this._crossFadingFactor=1,this._collectResourceTiming=e.collectResourceTiming,this._renderTaskQueue=new Do,this._controls=[],this._mapId=t.uniqueId(),this._requestManager=new t.RequestManager(e.transformRequest),\"string\"==typeof e.container){if(this._container=t.window.document.getElementById(e.container),!this._container)throw new Error(\"Container '\"+e.container+\"' not found.\")}else{if(!(e.container instanceof Ro))throw new Error(\"Invalid type: 'container' must be a String or HTMLElement.\");this._container=e.container;}if(e.maxBounds&&this.setMaxBounds(e.maxBounds),t.bindAll([\"_onWindowOnline\",\"_onWindowResize\",\"_contextLost\",\"_contextRestored\"],this),this._setupContainer(),this._setupPainter(),void 0===this.painter)throw new Error(\"Failed to initialize WebGL.\");this.on(\"move\",function(){return r._update(!1)}),this.on(\"moveend\",function(){return r._update(!1)}),this.on(\"zoom\",function(){return r._update(!0)}),void 0!==t.window&&(t.window.addEventListener(\"online\",this._onWindowOnline,!1),t.window.addEventListener(\"resize\",this._onWindowResize,!1)),function(t,e){var o=t.getCanvasContainer(),r=null,a=!1,n=null;for(var s in So)t[s]=new So[s](t,e),e.interactive&&e[s]&&t[s].enable(e[s]);i.addEventListener(o,\"mouseout\",function(e){t.fire(new po(\"mouseout\",t,e));}),i.addEventListener(o,\"mousedown\",function(r){a=!0,n=i.mousePos(o,r);var s=new po(\"mousedown\",t,r);t.fire(s),s.defaultPrevented||(e.interactive&&!t.doubleClickZoom.isActive()&&t.stop(),t.boxZoom.onMouseDown(r),t.boxZoom.isActive()||t.dragPan.isActive()||t.dragRotate.onMouseDown(r),t.boxZoom.isActive()||t.dragRotate.isActive()||t.dragPan.onMouseDown(r));}),i.addEventListener(o,\"mouseup\",function(e){var i=t.dragRotate.isActive();r&&!i&&t.fire(new po(\"contextmenu\",t,r)),r=null,a=!1,t.fire(new po(\"mouseup\",t,e));}),i.addEventListener(o,\"mousemove\",function(e){if(!t.dragPan.isActive()&&!t.dragRotate.isActive()){for(var i=e.target;i&&i!==o;)i=i.parentNode;i===o&&t.fire(new po(\"mousemove\",t,e));}}),i.addEventListener(o,\"mouseover\",function(e){for(var i=e.target;i&&i!==o;)i=i.parentNode;i===o&&t.fire(new po(\"mouseover\",t,e));}),i.addEventListener(o,\"touchstart\",function(i){var o=new _o(\"touchstart\",t,i);t.fire(o),o.defaultPrevented||(e.interactive&&t.stop(),t.boxZoom.isActive()||t.dragRotate.isActive()||t.dragPan.onTouchStart(i),t.touchZoomRotate.onStart(i),t.doubleClickZoom.onTouchStart(o));},{passive:!1}),i.addEventListener(o,\"touchmove\",function(e){t.fire(new _o(\"touchmove\",t,e));},{passive:!1}),i.addEventListener(o,\"touchend\",function(e){t.fire(new _o(\"touchend\",t,e));}),i.addEventListener(o,\"touchcancel\",function(e){t.fire(new _o(\"touchcancel\",t,e));}),i.addEventListener(o,\"click\",function(r){var a=i.mousePos(o,r);(a.equals(n)||a.dist(n)<e.clickTolerance)&&t.fire(new po(\"click\",t,r));}),i.addEventListener(o,\"dblclick\",function(e){var i=new po(\"dblclick\",t,e);t.fire(i),i.defaultPrevented||t.doubleClickZoom.onDblClick(i);}),i.addEventListener(o,\"contextmenu\",function(e){var i=t.dragRotate.isActive();a||i?a&&(r=e):t.fire(new po(\"contextmenu\",t,e)),(t.dragRotate.isEnabled()||t.listens(\"contextmenu\"))&&e.preventDefault();}),i.addEventListener(o,\"wheel\",function(i){e.interactive&&t.stop();var o=new fo(\"wheel\",t,i);t.fire(o),o.defaultPrevented||t.scrollZoom.onWheel(i);},{passive:!1});}(this,e),this._hash=e.hash&&(new ho).addTo(this),this._hash&&this._hash._onHashChange()||(this.jumpTo({center:e.center,zoom:e.zoom,bearing:e.bearing,pitch:e.pitch}),e.bounds&&(this.resize(),this.fitBounds(e.bounds,t.extend({},e.fitBoundsOptions,{duration:0})))),this.resize(),this._localIdeographFontFamily=e.localIdeographFontFamily,e.style&&this.setStyle(e.style,{localIdeographFontFamily:e.localIdeographFontFamily}),e.attributionControl&&this.addControl(new zo({customAttribution:e.customAttribution})),this.addControl(new Lo,e.logoPosition),this.on(\"style.load\",function(){r.transform.unmodified&&r.jumpTo(r.style.stylesheet);}),this.on(\"data\",function(e){r._update(\"style\"===e.dataType),r.fire(new t.Event(e.dataType+\"data\",e));}),this.on(\"dataloading\",function(e){r.fire(new t.Event(e.dataType+\"dataloading\",e));});}o&&(r.__proto__=o),r.prototype=Object.create(o&&o.prototype),r.prototype.constructor=r;var a={showTileBoundaries:{configurable:!0},showCollisionBoxes:{configurable:!0},showOverdrawInspector:{configurable:!0},repaint:{configurable:!0},vertices:{configurable:!0}};return r.prototype._getMapId=function(){return this._mapId},r.prototype.addControl=function(e,i){if(void 0===i&&e.getDefaultPosition&&(i=e.getDefaultPosition()),void 0===i&&(i=\"top-right\"),!e||!e.onAdd)return this.fire(new t.ErrorEvent(new Error(\"Invalid argument to map.addControl(). Argument must be a control with onAdd and onRemove methods.\")));var o=e.onAdd(this);this._controls.push(e);var r=this._controlPositions[i];return -1!==i.indexOf(\"bottom\")?r.insertBefore(o,r.firstChild):r.appendChild(o),this},r.prototype.removeControl=function(e){if(!e||!e.onRemove)return this.fire(new t.ErrorEvent(new Error(\"Invalid argument to map.removeControl(). Argument must be a control with onAdd and onRemove methods.\")));var i=this._controls.indexOf(e);return i>-1&&this._controls.splice(i,1),e.onRemove(this),this},r.prototype.resize=function(e){var i=this._containerDimensions(),o=i[0],r=i[1];return this._resizeCanvas(o,r),this.transform.resize(o,r),this.painter.resize(o,r),this.fire(new t.Event(\"movestart\",e)).fire(new t.Event(\"move\",e)).fire(new t.Event(\"resize\",e)).fire(new t.Event(\"moveend\",e)),this},r.prototype.getBounds=function(){return this.transform.getBounds()},r.prototype.getMaxBounds=function(){return this.transform.getMaxBounds()},r.prototype.setMaxBounds=function(e){return this.transform.setMaxBounds(t.LngLatBounds.convert(e)),this._update()},r.prototype.setMinZoom=function(t){if((t=null==t?0:t)>=0&&t<=this.transform.maxZoom)return this.transform.minZoom=t,this._update(),this.getZoom()<t&&this.setZoom(t),this;throw new Error(\"minZoom must be between 0 and the current maxZoom, inclusive\")},r.prototype.getMinZoom=function(){return this.transform.minZoom},r.prototype.setMaxZoom=function(t){if((t=null==t?22:t)>=this.transform.minZoom)return this.transform.maxZoom=t,this._update(),this.getZoom()>t&&this.setZoom(t),this;throw new Error(\"maxZoom must be greater than the current minZoom\")},r.prototype.getRenderWorldCopies=function(){return this.transform.renderWorldCopies},r.prototype.setRenderWorldCopies=function(t){return this.transform.renderWorldCopies=t,this._update()},r.prototype.getMaxZoom=function(){return this.transform.maxZoom},r.prototype.project=function(e){return this.transform.locationPoint(t.LngLat.convert(e))},r.prototype.unproject=function(e){return this.transform.pointLocation(t.Point.convert(e))},r.prototype.isMoving=function(){return this._moving||this.dragPan.isActive()||this.dragRotate.isActive()||this.scrollZoom.isActive()},r.prototype.isZooming=function(){return this._zooming||this.scrollZoom.isZooming()},r.prototype.isRotating=function(){return this._rotating||this.dragRotate.isActive()},r.prototype.on=function(t,e,i){var r=this;if(void 0===i)return o.prototype.on.call(this,t,e);var a=function(){var o;if(\"mouseenter\"===t||\"mouseover\"===t){var a=!1;return {layer:e,listener:i,delegates:{mousemove:function(o){var n=r.getLayer(e)?r.queryRenderedFeatures(o.point,{layers:[e]}):[];n.length?a||(a=!0,i.call(r,new po(t,r,o.originalEvent,{features:n}))):a=!1;},mouseout:function(){a=!1;}}}}if(\"mouseleave\"===t||\"mouseout\"===t){var n=!1;return {layer:e,listener:i,delegates:{mousemove:function(o){(r.getLayer(e)?r.queryRenderedFeatures(o.point,{layers:[e]}):[]).length?n=!0:n&&(n=!1,i.call(r,new po(t,r,o.originalEvent)));},mouseout:function(e){n&&(n=!1,i.call(r,new po(t,r,e.originalEvent)));}}}}return {layer:e,listener:i,delegates:(o={},o[t]=function(t){var o=r.getLayer(e)?r.queryRenderedFeatures(t.point,{layers:[e]}):[];o.length&&(t.features=o,i.call(r,t),delete t.features);},o)}}();for(var n in this._delegatedListeners=this._delegatedListeners||{},this._delegatedListeners[t]=this._delegatedListeners[t]||[],this._delegatedListeners[t].push(a),a.delegates)this.on(n,a.delegates[n]);return this},r.prototype.off=function(t,e,i){if(void 0===i)return o.prototype.off.call(this,t,e);if(this._delegatedListeners&&this._delegatedListeners[t])for(var r=this._delegatedListeners[t],a=0;a<r.length;a++){var n=r[a];if(n.layer===e&&n.listener===i){for(var s in n.delegates)this.off(s,n.delegates[s]);return r.splice(a,1),this}}return this},r.prototype.queryRenderedFeatures=function(e,i){if(!this.style)return [];var o;if(void 0!==i||void 0===e||e instanceof t.Point||Array.isArray(e)||(i=e,e=void 0),i=i||{},(e=e||[[0,0],[this.transform.width,this.transform.height]])instanceof t.Point||\"number\"==typeof e[0])o=[t.Point.convert(e)];else{var r=t.Point.convert(e[0]),a=t.Point.convert(e[1]);o=[r,new t.Point(a.x,r.y),a,new t.Point(r.x,a.y),r];}return this.style.queryRenderedFeatures(o,i,this.transform)},r.prototype.querySourceFeatures=function(t,e){return this.style.querySourceFeatures(t,e)},r.prototype.setStyle=function(e,i){return !1!==(i=t.extend({},{localIdeographFontFamily:Ao.localIdeographFontFamily},i)).diff&&i.localIdeographFontFamily===this._localIdeographFontFamily&&this.style&&e?(this._diffStyle(e,i),this):(this._localIdeographFontFamily=i.localIdeographFontFamily,this._updateStyle(e,i))},r.prototype._updateStyle=function(t,e){return this.style&&(this.style.setEventedParent(null),this.style._remove()),t?(this.style=new Be(this,e||{}),this.style.setEventedParent(this,{style:this.style}),\"string\"==typeof t?this.style.loadURL(t):this.style.loadJSON(t),this):(delete this.style,this)},r.prototype._diffStyle=function(e,i){var o=this;if(\"string\"==typeof e){var r=this._requestManager.normalizeStyleURL(e),a=this._requestManager.transformRequest(r,t.ResourceType.Style);t.getJSON(a,function(e,r){e?o.fire(new t.ErrorEvent(e)):r&&o._updateDiff(r,i);});}else\"object\"==typeof e&&this._updateDiff(e,i);},r.prototype._updateDiff=function(e,i){try{this.style.setState(e)&&this._update(!0);}catch(o){t.warnOnce(\"Unable to perform style diff: \"+(o.message||o.error||o)+\".  Rebuilding the style from scratch.\"),this._updateStyle(e,i);}},r.prototype.getStyle=function(){if(this.style)return this.style.serialize()},r.prototype.isStyleLoaded=function(){return this.style?this.style.loaded():t.warnOnce(\"There is no style added to the map.\")},r.prototype.addSource=function(t,e){return this.style.addSource(t,e),this._update(!0)},r.prototype.isSourceLoaded=function(e){var i=this.style&&this.style.sourceCaches[e];if(void 0!==i)return i.loaded();this.fire(new t.ErrorEvent(new Error(\"There is no source with ID '\"+e+\"'\")));},r.prototype.areTilesLoaded=function(){var t=this.style&&this.style.sourceCaches;for(var e in t){var i=t[e]._tiles;for(var o in i){var r=i[o];if(\"loaded\"!==r.state&&\"errored\"!==r.state)return !1}}return !0},r.prototype.addSourceType=function(t,e,i){return this.style.addSourceType(t,e,i)},r.prototype.removeSource=function(t){return this.style.removeSource(t),this._update(!0)},r.prototype.getSource=function(t){return this.style.getSource(t)},r.prototype.addImage=function(e,i,o){void 0===o&&(o={});var r=o.pixelRatio;void 0===r&&(r=1);var a=o.sdf;void 0===a&&(a=!1);if(i instanceof Mo){var n=t.browser.getImageData(i),s=n.width,l=n.height,c=n.data;this.style.addImage(e,{data:new t.RGBAImage({width:s,height:l},c),pixelRatio:r,sdf:a,version:0});}else{if(void 0===i.width||void 0===i.height)return this.fire(new t.ErrorEvent(new Error(\"Invalid arguments to map.addImage(). The second argument must be an `HTMLImageElement`, `ImageData`, or object with `width`, `height`, and `data` properties with the same format as `ImageData`\")));var u=i.width,h=i.height,p=i.data,d=i;this.style.addImage(e,{data:new t.RGBAImage({width:u,height:h},new Uint8Array(p)),pixelRatio:r,sdf:a,version:0,userImage:d}),d.onAdd&&d.onAdd(this,e);}},r.prototype.updateImage=function(e,i){var o=this.style.getImage(e);if(!o)return this.fire(new t.ErrorEvent(new Error(\"The map has no image with that id. If you are adding a new image use `map.addImage(...)` instead.\")));var r=i instanceof Mo?t.browser.getImageData(i):i,a=r.width,n=r.height,s=r.data;if(void 0===a||void 0===n)return this.fire(new t.ErrorEvent(new Error(\"Invalid arguments to map.updateImage(). The second argument must be an `HTMLImageElement`, `ImageData`, or object with `width`, `height`, and `data` properties with the same format as `ImageData`\")));if(a!==o.data.width||n!==o.data.height)return this.fire(new t.ErrorEvent(new Error(\"The width and height of the updated image must be that same as the previous version of the image\")));var l=!(i instanceof Mo);o.data.replace(s,l),this.style.updateImage(e,o);},r.prototype.hasImage=function(e){return e?!!this.style.getImage(e):(this.fire(new t.ErrorEvent(new Error(\"Missing required image id\"))),!1)},r.prototype.removeImage=function(t){this.style.removeImage(t);},r.prototype.loadImage=function(e,i){t.getImage(this._requestManager.transformRequest(e,t.ResourceType.Image),i);},r.prototype.listImages=function(){return this.style.listImages()},r.prototype.addLayer=function(t,e){return this.style.addLayer(t,e),this._update(!0)},r.prototype.moveLayer=function(t,e){return this.style.moveLayer(t,e),this._update(!0)},r.prototype.removeLayer=function(t){return this.style.removeLayer(t),this._update(!0)},r.prototype.getLayer=function(t){return this.style.getLayer(t)},r.prototype.setFilter=function(t,e,i){return void 0===i&&(i={}),this.style.setFilter(t,e,i),this._update(!0)},r.prototype.setLayerZoomRange=function(t,e,i){return this.style.setLayerZoomRange(t,e,i),this._update(!0)},r.prototype.getFilter=function(t){return this.style.getFilter(t)},r.prototype.setPaintProperty=function(t,e,i,o){return void 0===o&&(o={}),this.style.setPaintProperty(t,e,i,o),this._update(!0)},r.prototype.getPaintProperty=function(t,e){return this.style.getPaintProperty(t,e)},r.prototype.setLayoutProperty=function(t,e,i,o){return void 0===o&&(o={}),this.style.setLayoutProperty(t,e,i,o),this._update(!0)},r.prototype.getLayoutProperty=function(t,e){return this.style.getLayoutProperty(t,e)},r.prototype.setLight=function(t,e){return void 0===e&&(e={}),this.style.setLight(t,e),this._update(!0)},r.prototype.getLight=function(){return this.style.getLight()},r.prototype.setFeatureState=function(t,e){return this.style.setFeatureState(t,e),this._update()},r.prototype.removeFeatureState=function(t,e){return this.style.removeFeatureState(t,e),this._update()},r.prototype.getFeatureState=function(t){return this.style.getFeatureState(t)},r.prototype.getContainer=function(){return this._container},r.prototype.getCanvasContainer=function(){return this._canvasContainer},r.prototype.getCanvas=function(){return this._canvas},r.prototype._containerDimensions=function(){var t=0,e=0;return this._container&&(t=this._container.clientWidth||400,e=this._container.clientHeight||300),[t,e]},r.prototype._detectMissingCSS=function(){\"rgb(250, 128, 114)\"!==t.window.getComputedStyle(this._missingCSSCanary).getPropertyValue(\"background-color\")&&t.warnOnce(\"This page appears to be missing CSS declarations for Mapbox GL JS, which may cause the map to display incorrectly. Please ensure your page includes mapbox-gl.css, as described in https://www.mapbox.com/mapbox-gl-js/api/.\");},r.prototype._setupContainer=function(){var t=this._container;t.classList.add(\"mapboxgl-map\"),(this._missingCSSCanary=i.create(\"div\",\"mapboxgl-canary\",t)).style.visibility=\"hidden\",this._detectMissingCSS();var e=this._canvasContainer=i.create(\"div\",\"mapboxgl-canvas-container\",t);this._interactive&&e.classList.add(\"mapboxgl-interactive\"),this._canvas=i.create(\"canvas\",\"mapboxgl-canvas\",e),this._canvas.style.position=\"absolute\",this._canvas.addEventListener(\"webglcontextlost\",this._contextLost,!1),this._canvas.addEventListener(\"webglcontextrestored\",this._contextRestored,!1),this._canvas.setAttribute(\"tabindex\",\"0\"),this._canvas.setAttribute(\"aria-label\",\"Map\");var o=this._containerDimensions();this._resizeCanvas(o[0],o[1]);var r=this._controlContainer=i.create(\"div\",\"mapboxgl-control-container\",t),a=this._controlPositions={};[\"top-left\",\"top-right\",\"bottom-left\",\"bottom-right\"].forEach(function(t){a[t]=i.create(\"div\",\"mapboxgl-ctrl-\"+t,r);});},r.prototype._resizeCanvas=function(e,i){var o=t.window.devicePixelRatio||1;this._canvas.width=o*e,this._canvas.height=o*i,this._canvas.style.width=e+\"px\",this._canvas.style.height=i+\"px\";},r.prototype._setupPainter=function(){var i=t.extend({},e.webGLContextAttributes,{failIfMajorPerformanceCaveat:this._failIfMajorPerformanceCaveat,preserveDrawingBuffer:this._preserveDrawingBuffer,antialias:this._antialias||!1}),o=this._canvas.getContext(\"webgl\",i)||this._canvas.getContext(\"experimental-webgl\",i);o?(this.painter=new ao(o,this.transform),t.webpSupported.testSupport(o)):this.fire(new t.ErrorEvent(new Error(\"Failed to initialize WebGL\")));},r.prototype._contextLost=function(e){e.preventDefault(),this._frame&&(this._frame.cancel(),this._frame=null),this.fire(new t.Event(\"webglcontextlost\",{originalEvent:e}));},r.prototype._contextRestored=function(e){this._setupPainter(),this.resize(),this._update(),this.fire(new t.Event(\"webglcontextrestored\",{originalEvent:e}));},r.prototype.loaded=function(){return !this._styleDirty&&!this._sourcesDirty&&!!this.style&&this.style.loaded()},r.prototype._update=function(t){return this.style?(this._styleDirty=this._styleDirty||t,this._sourcesDirty=!0,this.triggerRepaint(),this):this},r.prototype._requestRenderFrame=function(t){return this._update(),this._renderTaskQueue.add(t)},r.prototype._cancelRenderFrame=function(t){this._renderTaskQueue.remove(t);},r.prototype._render=function(){this.painter.context.setDirty(),this.painter.setBaseState(),this._renderTaskQueue.run();var e=!1;if(this.style&&this._styleDirty){this._styleDirty=!1;var i=this.transform.zoom,o=t.browser.now();this.style.zoomHistory.update(i,o);var r=new t.EvaluationParameters(i,{now:o,fadeDuration:this._fadeDuration,zoomHistory:this.style.zoomHistory,transition:this.style.getTransition()}),a=r.crossFadingFactor();1===a&&a===this._crossFadingFactor||(e=!0,this._crossFadingFactor=a),this.style.update(r);}return this.style&&this._sourcesDirty&&(this._sourcesDirty=!1,this.style._updateSources(this.transform)),this._placementDirty=this.style&&this.style._updatePlacement(this.painter.transform,this.showCollisionBoxes,this._fadeDuration,this._crossSourceCollisions),this.painter.render(this.style,{showTileBoundaries:this.showTileBoundaries,showOverdrawInspector:this._showOverdrawInspector,rotating:this.isRotating(),zooming:this.isZooming(),moving:this.isMoving(),fadeDuration:this._fadeDuration}),this.fire(new t.Event(\"render\")),this.loaded()&&!this._loaded&&(this._loaded=!0,this.fire(new t.Event(\"load\"))),this.style&&(this.style.hasTransitions()||e)&&(this._styleDirty=!0),this.style&&!this._placementDirty&&this.style._releaseSymbolFadeTiles(),this._sourcesDirty||this._repaint||this._styleDirty||this._placementDirty?this.triggerRepaint():!this.isMoving()&&this.loaded()&&this.fire(new t.Event(\"idle\")),this},r.prototype.remove=function(){this._hash&&this._hash.remove();for(var e=0,i=this._controls;e<i.length;e+=1){i[e].onRemove(this);}this._controls=[],this._frame&&(this._frame.cancel(),this._frame=null),this._renderTaskQueue.clear(),this.setStyle(null),void 0!==t.window&&(t.window.removeEventListener(\"resize\",this._onWindowResize,!1),t.window.removeEventListener(\"online\",this._onWindowOnline,!1));var o=this.painter.context.gl.getExtension(\"WEBGL_lose_context\");o&&o.loseContext(),Bo(this._canvasContainer),Bo(this._controlContainer),Bo(this._missingCSSCanary),this._container.classList.remove(\"mapboxgl-map\"),this.fire(new t.Event(\"remove\"));},r.prototype.triggerRepaint=function(){var e=this;this.style&&!this._frame&&(this._frame=t.browser.frame(function(){e._frame=null,e._render();}));},r.prototype._onWindowOnline=function(){this._update();},r.prototype._onWindowResize=function(){this._trackResize&&this.resize()._update();},a.showTileBoundaries.get=function(){return !!this._showTileBoundaries},a.showTileBoundaries.set=function(t){this._showTileBoundaries!==t&&(this._showTileBoundaries=t,this._update());},a.showCollisionBoxes.get=function(){return !!this._showCollisionBoxes},a.showCollisionBoxes.set=function(t){this._showCollisionBoxes!==t&&(this._showCollisionBoxes=t,t?this.style._generateCollisionBoxes():this._update());},a.showOverdrawInspector.get=function(){return !!this._showOverdrawInspector},a.showOverdrawInspector.set=function(t){this._showOverdrawInspector!==t&&(this._showOverdrawInspector=t,this._update());},a.repaint.get=function(){return !!this._repaint},a.repaint.set=function(t){this._repaint!==t&&(this._repaint=t,this.triggerRepaint());},a.vertices.get=function(){return !!this._vertices},a.vertices.set=function(t){this._vertices=t,this._update();},r.prototype._setCacheLimits=function(e,i){t.setCacheLimits(e,i);},Object.defineProperties(r.prototype,a),r}(Po);function Bo(t){t.parentNode&&t.parentNode.removeChild(t);}var Oo={showCompass:!0,showZoom:!0},Fo=function(e){var o=this;this.options=t.extend({},Oo,e),this._container=i.create(\"div\",\"mapboxgl-ctrl mapboxgl-ctrl-group\"),this._container.addEventListener(\"contextmenu\",function(t){return t.preventDefault()}),this.options.showZoom&&(t.bindAll([\"_updateZoomButtons\"],this),this._zoomInButton=this._createButton(\"mapboxgl-ctrl-icon mapboxgl-ctrl-zoom-in\",\"Zoom in\",function(){return o._map.zoomIn()}),this._zoomOutButton=this._createButton(\"mapboxgl-ctrl-icon mapboxgl-ctrl-zoom-out\",\"Zoom out\",function(){return o._map.zoomOut()})),this.options.showCompass&&(t.bindAll([\"_rotateCompassArrow\"],this),this._compass=this._createButton(\"mapboxgl-ctrl-icon mapboxgl-ctrl-compass\",\"Reset bearing to north\",function(){return o._map.resetNorth()}),this._compassArrow=i.create(\"span\",\"mapboxgl-ctrl-compass-arrow\",this._compass));};function Uo(e,i,o){if(e=new t.LngLat(e.lng,e.lat),i){var r=new t.LngLat(e.lng-360,e.lat),a=new t.LngLat(e.lng+360,e.lat),n=o.locationPoint(e).distSqr(i);o.locationPoint(r).distSqr(i)<n?e=r:o.locationPoint(a).distSqr(i)<n&&(e=a);}for(;Math.abs(e.lng-o.center.lng)>180;){var s=o.locationPoint(e);if(s.x>=0&&s.y>=0&&s.x<=o.width&&s.y<=o.height)break;e.lng>o.center.lng?e.lng-=360:e.lng+=360;}return e}Fo.prototype._updateZoomButtons=function(){var t=this._map.getZoom();this._zoomInButton.classList.toggle(\"mapboxgl-ctrl-icon-disabled\",t===this._map.getMaxZoom()),this._zoomOutButton.classList.toggle(\"mapboxgl-ctrl-icon-disabled\",t===this._map.getMinZoom());},Fo.prototype._rotateCompassArrow=function(){var t=\"rotate(\"+this._map.transform.angle*(180/Math.PI)+\"deg)\";this._compassArrow.style.transform=t;},Fo.prototype.onAdd=function(t){return this._map=t,this.options.showZoom&&(this._map.on(\"zoom\",this._updateZoomButtons),this._updateZoomButtons()),this.options.showCompass&&(this._map.on(\"rotate\",this._rotateCompassArrow),this._rotateCompassArrow(),this._handler=new yo(t,{button:\"left\",element:this._compass}),i.addEventListener(this._compass,\"mousedown\",this._handler.onMouseDown),this._handler.enable()),this._container},Fo.prototype.onRemove=function(){i.remove(this._container),this.options.showZoom&&this._map.off(\"zoom\",this._updateZoomButtons),this.options.showCompass&&(this._map.off(\"rotate\",this._rotateCompassArrow),i.removeEventListener(this._compass,\"mousedown\",this._handler.onMouseDown),this._handler.disable(),delete this._handler),delete this._map;},Fo.prototype._createButton=function(t,e,o){var r=i.create(\"button\",t,this._container);return r.type=\"button\",r.title=e,r.setAttribute(\"aria-label\",e),r.addEventListener(\"click\",o),r};var No={center:\"translate(-50%,-50%)\",top:\"translate(-50%,0)\",\"top-left\":\"translate(0,0)\",\"top-right\":\"translate(-100%,0)\",bottom:\"translate(-50%,-100%)\",\"bottom-left\":\"translate(0,-100%)\",\"bottom-right\":\"translate(-100%,-100%)\",left:\"translate(0,-50%)\",right:\"translate(-100%,-50%)\"};function Zo(t,e,i){var o=t.classList;for(var r in No)o.remove(\"mapboxgl-\"+i+\"-anchor-\"+r);o.add(\"mapboxgl-\"+i+\"-anchor-\"+e);}var jo,qo=function(e){function o(o,r){if(e.call(this),(o instanceof t.window.HTMLElement||r)&&(o=t.extend({element:o},r)),t.bindAll([\"_update\",\"_onMove\",\"_onUp\",\"_addDragHandler\",\"_onMapClick\"],this),this._anchor=o&&o.anchor||\"center\",this._color=o&&o.color||\"#3FB1CE\",this._draggable=o&&o.draggable||!1,this._state=\"inactive\",o&&o.element)this._element=o.element,this._offset=t.Point.convert(o&&o.offset||[0,0]);else{this._defaultMarker=!0,this._element=i.create(\"div\");var a=i.createNS(\"http://www.w3.org/2000/svg\",\"svg\");a.setAttributeNS(null,\"display\",\"block\"),a.setAttributeNS(null,\"height\",\"41px\"),a.setAttributeNS(null,\"width\",\"27px\"),a.setAttributeNS(null,\"viewBox\",\"0 0 27 41\");var n=i.createNS(\"http://www.w3.org/2000/svg\",\"g\");n.setAttributeNS(null,\"stroke\",\"none\"),n.setAttributeNS(null,\"stroke-width\",\"1\"),n.setAttributeNS(null,\"fill\",\"none\"),n.setAttributeNS(null,\"fill-rule\",\"evenodd\");var s=i.createNS(\"http://www.w3.org/2000/svg\",\"g\");s.setAttributeNS(null,\"fill-rule\",\"nonzero\");var l=i.createNS(\"http://www.w3.org/2000/svg\",\"g\");l.setAttributeNS(null,\"transform\",\"translate(3.0, 29.0)\"),l.setAttributeNS(null,\"fill\",\"#000000\");for(var c=0,u=[{rx:\"10.5\",ry:\"5.25002273\"},{rx:\"10.5\",ry:\"5.25002273\"},{rx:\"9.5\",ry:\"4.77275007\"},{rx:\"8.5\",ry:\"4.29549936\"},{rx:\"7.5\",ry:\"3.81822308\"},{rx:\"6.5\",ry:\"3.34094679\"},{rx:\"5.5\",ry:\"2.86367051\"},{rx:\"4.5\",ry:\"2.38636864\"}];c<u.length;c+=1){var h=u[c],p=i.createNS(\"http://www.w3.org/2000/svg\",\"ellipse\");p.setAttributeNS(null,\"opacity\",\"0.04\"),p.setAttributeNS(null,\"cx\",\"10.5\"),p.setAttributeNS(null,\"cy\",\"5.80029008\"),p.setAttributeNS(null,\"rx\",h.rx),p.setAttributeNS(null,\"ry\",h.ry),l.appendChild(p);}var d=i.createNS(\"http://www.w3.org/2000/svg\",\"g\");d.setAttributeNS(null,\"fill\",this._color);var _=i.createNS(\"http://www.w3.org/2000/svg\",\"path\");_.setAttributeNS(null,\"d\",\"M27,13.5 C27,19.074644 20.250001,27.000002 14.75,34.500002 C14.016665,35.500004 12.983335,35.500004 12.25,34.500002 C6.7499993,27.000002 0,19.222562 0,13.5 C0,6.0441559 6.0441559,0 13.5,0 C20.955844,0 27,6.0441559 27,13.5 Z\"),d.appendChild(_);var f=i.createNS(\"http://www.w3.org/2000/svg\",\"g\");f.setAttributeNS(null,\"opacity\",\"0.25\"),f.setAttributeNS(null,\"fill\",\"#000000\");var m=i.createNS(\"http://www.w3.org/2000/svg\",\"path\");m.setAttributeNS(null,\"d\",\"M13.5,0 C6.0441559,0 0,6.0441559 0,13.5 C0,19.222562 6.7499993,27 12.25,34.5 C13,35.522727 14.016664,35.500004 14.75,34.5 C20.250001,27 27,19.074644 27,13.5 C27,6.0441559 20.955844,0 13.5,0 Z M13.5,1 C20.415404,1 26,6.584596 26,13.5 C26,15.898657 24.495584,19.181431 22.220703,22.738281 C19.945823,26.295132 16.705119,30.142167 13.943359,33.908203 C13.743445,34.180814 13.612715,34.322738 13.5,34.441406 C13.387285,34.322738 13.256555,34.180814 13.056641,33.908203 C10.284481,30.127985 7.4148684,26.314159 5.015625,22.773438 C2.6163816,19.232715 1,15.953538 1,13.5 C1,6.584596 6.584596,1 13.5,1 Z\"),f.appendChild(m);var g=i.createNS(\"http://www.w3.org/2000/svg\",\"g\");g.setAttributeNS(null,\"transform\",\"translate(6.0, 7.0)\"),g.setAttributeNS(null,\"fill\",\"#FFFFFF\");var v=i.createNS(\"http://www.w3.org/2000/svg\",\"g\");v.setAttributeNS(null,\"transform\",\"translate(8.0, 8.0)\");var y=i.createNS(\"http://www.w3.org/2000/svg\",\"circle\");y.setAttributeNS(null,\"fill\",\"#000000\"),y.setAttributeNS(null,\"opacity\",\"0.25\"),y.setAttributeNS(null,\"cx\",\"5.5\"),y.setAttributeNS(null,\"cy\",\"5.5\"),y.setAttributeNS(null,\"r\",\"5.4999962\");var x=i.createNS(\"http://www.w3.org/2000/svg\",\"circle\");x.setAttributeNS(null,\"fill\",\"#FFFFFF\"),x.setAttributeNS(null,\"cx\",\"5.5\"),x.setAttributeNS(null,\"cy\",\"5.5\"),x.setAttributeNS(null,\"r\",\"5.4999962\"),v.appendChild(y),v.appendChild(x),s.appendChild(l),s.appendChild(d),s.appendChild(f),s.appendChild(g),s.appendChild(v),a.appendChild(s),this._element.appendChild(a),this._offset=t.Point.convert(o&&o.offset||[0,-14]);}this._element.classList.add(\"mapboxgl-marker\"),this._element.addEventListener(\"dragstart\",function(t){t.preventDefault();}),Zo(this._element,this._anchor,\"marker\"),this._popup=null;}return e&&(o.__proto__=e),o.prototype=Object.create(e&&e.prototype),o.prototype.constructor=o,o.prototype.addTo=function(t){return this.remove(),this._map=t,t.getCanvasContainer().appendChild(this._element),t.on(\"move\",this._update),t.on(\"moveend\",this._update),this.setDraggable(this._draggable),this._update(),this._map.on(\"click\",this._onMapClick),this},o.prototype.remove=function(){return this._map&&(this._map.off(\"click\",this._onMapClick),this._map.off(\"move\",this._update),this._map.off(\"moveend\",this._update),this._map.off(\"mousedown\",this._addDragHandler),this._map.off(\"touchstart\",this._addDragHandler),this._map.off(\"mouseup\",this._onUp),this._map.off(\"touchend\",this._onUp),delete this._map),i.remove(this._element),this._popup&&this._popup.remove(),this},o.prototype.getLngLat=function(){return this._lngLat},o.prototype.setLngLat=function(e){return this._lngLat=t.LngLat.convert(e),this._pos=null,this._popup&&this._popup.setLngLat(this._lngLat),this._update(),this},o.prototype.getElement=function(){return this._element},o.prototype.setPopup=function(t){if(this._popup&&(this._popup.remove(),this._popup=null),t){if(!(\"offset\"in t.options)){var e=Math.sqrt(Math.pow(13.5,2)/2);t.options.offset=this._defaultMarker?{top:[0,0],\"top-left\":[0,0],\"top-right\":[0,0],bottom:[0,-38.1],\"bottom-left\":[e,-1*(24.6+e)],\"bottom-right\":[-e,-1*(24.6+e)],left:[13.5,-24.6],right:[-13.5,-24.6]}:this._offset;}this._popup=t,this._lngLat&&this._popup.setLngLat(this._lngLat);}return this},o.prototype._onMapClick=function(t){var e=t.originalEvent.target,i=this._element;this._popup&&(e===i||i.contains(e))&&this.togglePopup();},o.prototype.getPopup=function(){return this._popup},o.prototype.togglePopup=function(){var t=this._popup;return t?(t.isOpen()?t.remove():t.addTo(this._map),this):this},o.prototype._update=function(t){this._map&&(this._map.transform.renderWorldCopies&&(this._lngLat=Uo(this._lngLat,this._pos,this._map.transform)),this._pos=this._map.project(this._lngLat)._add(this._offset),t&&\"moveend\"!==t.type||(this._pos=this._pos.round()),i.setTransform(this._element,No[this._anchor]+\" translate(\"+this._pos.x+\"px, \"+this._pos.y+\"px)\"));},o.prototype.getOffset=function(){return this._offset},o.prototype.setOffset=function(e){return this._offset=t.Point.convert(e),this._update(),this},o.prototype._onMove=function(e){this._pos=e.point.sub(this._positionDelta),this._lngLat=this._map.unproject(this._pos),this.setLngLat(this._lngLat),this._element.style.pointerEvents=\"none\",\"pending\"===this._state&&(this._state=\"active\",this.fire(new t.Event(\"dragstart\"))),this.fire(new t.Event(\"drag\"));},o.prototype._onUp=function(){this._element.style.pointerEvents=\"auto\",this._positionDelta=null,this._map.off(\"mousemove\",this._onMove),this._map.off(\"touchmove\",this._onMove),\"active\"===this._state&&this.fire(new t.Event(\"dragend\")),this._state=\"inactive\";},o.prototype._addDragHandler=function(t){this._element.contains(t.originalEvent.target)&&(t.preventDefault(),this._positionDelta=t.point.sub(this._pos).add(this._offset),this._state=\"pending\",this._map.on(\"mousemove\",this._onMove),this._map.on(\"touchmove\",this._onMove),this._map.once(\"mouseup\",this._onUp),this._map.once(\"touchend\",this._onUp));},o.prototype.setDraggable=function(t){return this._draggable=!!t,this._map&&(t?(this._map.on(\"mousedown\",this._addDragHandler),this._map.on(\"touchstart\",this._addDragHandler)):(this._map.off(\"mousedown\",this._addDragHandler),this._map.off(\"touchstart\",this._addDragHandler))),this},o.prototype.isDraggable=function(){return this._draggable},o}(t.Evented),Vo={positionOptions:{enableHighAccuracy:!1,maximumAge:0,timeout:6e3},fitBoundsOptions:{maxZoom:15},trackUserLocation:!1,showUserLocation:!0};var Go=function(e){function o(i){e.call(this),this.options=t.extend({},Vo,i),t.bindAll([\"_onSuccess\",\"_onError\",\"_finish\",\"_setupUI\",\"_updateCamera\",\"_updateMarker\"],this);}return e&&(o.__proto__=e),o.prototype=Object.create(e&&e.prototype),o.prototype.constructor=o,o.prototype.onAdd=function(e){var o;return this._map=e,this._container=i.create(\"div\",\"mapboxgl-ctrl mapboxgl-ctrl-group\"),o=this._setupUI,void 0!==jo?o(jo):void 0!==t.window.navigator.permissions?t.window.navigator.permissions.query({name:\"geolocation\"}).then(function(t){jo=\"denied\"!==t.state,o(jo);}):(jo=!!t.window.navigator.geolocation,o(jo)),this._container},o.prototype.onRemove=function(){void 0!==this._geolocationWatchID&&(t.window.navigator.geolocation.clearWatch(this._geolocationWatchID),this._geolocationWatchID=void 0),this.options.showUserLocation&&this._userLocationDotMarker&&this._userLocationDotMarker.remove(),i.remove(this._container),this._map=void 0;},o.prototype._onSuccess=function(e){if(this.options.trackUserLocation)switch(this._lastKnownPosition=e,this._watchState){case\"WAITING_ACTIVE\":case\"ACTIVE_LOCK\":case\"ACTIVE_ERROR\":this._watchState=\"ACTIVE_LOCK\",this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-active-error\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-active\");break;case\"BACKGROUND\":case\"BACKGROUND_ERROR\":this._watchState=\"BACKGROUND\",this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-background-error\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-background\");}this.options.showUserLocation&&\"OFF\"!==this._watchState&&this._updateMarker(e),this.options.trackUserLocation&&\"ACTIVE_LOCK\"!==this._watchState||this._updateCamera(e),this.options.showUserLocation&&this._dotElement.classList.remove(\"mapboxgl-user-location-dot-stale\"),this.fire(new t.Event(\"geolocate\",e)),this._finish();},o.prototype._updateCamera=function(e){var i=new t.LngLat(e.coords.longitude,e.coords.latitude),o=e.coords.accuracy,r=this._map.getBearing(),a=t.extend({bearing:r},this.options.fitBoundsOptions);this._map.fitBounds(i.toBounds(o),a,{geolocateSource:!0});},o.prototype._updateMarker=function(t){t?this._userLocationDotMarker.setLngLat([t.coords.longitude,t.coords.latitude]).addTo(this._map):this._userLocationDotMarker.remove();},o.prototype._onError=function(e){if(this.options.trackUserLocation)if(1===e.code)this._watchState=\"OFF\",this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-active\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-active-error\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-background\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-background-error\"),void 0!==this._geolocationWatchID&&this._clearWatch();else switch(this._watchState){case\"WAITING_ACTIVE\":this._watchState=\"ACTIVE_ERROR\",this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-active\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-active-error\");break;case\"ACTIVE_LOCK\":this._watchState=\"ACTIVE_ERROR\",this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-active\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-active-error\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-waiting\");break;case\"BACKGROUND\":this._watchState=\"BACKGROUND_ERROR\",this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-background\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-background-error\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-waiting\");}\"OFF\"!==this._watchState&&this.options.showUserLocation&&this._dotElement.classList.add(\"mapboxgl-user-location-dot-stale\"),this.fire(new t.Event(\"error\",e)),this._finish();},o.prototype._finish=function(){this._timeoutId&&clearTimeout(this._timeoutId),this._timeoutId=void 0;},o.prototype._setupUI=function(e){var o=this;!1!==e?(this._container.addEventListener(\"contextmenu\",function(t){return t.preventDefault()}),this._geolocateButton=i.create(\"button\",\"mapboxgl-ctrl-icon mapboxgl-ctrl-geolocate\",this._container),this._geolocateButton.type=\"button\",this._geolocateButton.setAttribute(\"aria-label\",\"Geolocate\"),this.options.trackUserLocation&&(this._geolocateButton.setAttribute(\"aria-pressed\",\"false\"),this._watchState=\"OFF\"),this.options.showUserLocation&&(this._dotElement=i.create(\"div\",\"mapboxgl-user-location-dot\"),this._userLocationDotMarker=new qo(this._dotElement),this.options.trackUserLocation&&(this._watchState=\"OFF\")),this._geolocateButton.addEventListener(\"click\",this.trigger.bind(this)),this._setup=!0,this.options.trackUserLocation&&this._map.on(\"movestart\",function(e){e.geolocateSource||\"ACTIVE_LOCK\"!==o._watchState||(o._watchState=\"BACKGROUND\",o._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-background\"),o._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-active\"),o.fire(new t.Event(\"trackuserlocationend\")));})):t.warnOnce(\"Geolocation support is not available, the GeolocateControl will not be visible.\");},o.prototype.trigger=function(){if(!this._setup)return t.warnOnce(\"Geolocate control triggered before added to a map\"),!1;if(this.options.trackUserLocation){switch(this._watchState){case\"OFF\":this._watchState=\"WAITING_ACTIVE\",this.fire(new t.Event(\"trackuserlocationstart\"));break;case\"WAITING_ACTIVE\":case\"ACTIVE_LOCK\":case\"ACTIVE_ERROR\":case\"BACKGROUND_ERROR\":this._watchState=\"OFF\",this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-active\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-active-error\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-background\"),this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-background-error\"),this.fire(new t.Event(\"trackuserlocationend\"));break;case\"BACKGROUND\":this._watchState=\"ACTIVE_LOCK\",this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-background\"),this._lastKnownPosition&&this._updateCamera(this._lastKnownPosition),this.fire(new t.Event(\"trackuserlocationstart\"));}switch(this._watchState){case\"WAITING_ACTIVE\":this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-active\");break;case\"ACTIVE_LOCK\":this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-active\");break;case\"ACTIVE_ERROR\":this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-active-error\");break;case\"BACKGROUND\":this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-background\");break;case\"BACKGROUND_ERROR\":this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-background-error\");}\"OFF\"===this._watchState&&void 0!==this._geolocationWatchID?this._clearWatch():void 0===this._geolocationWatchID&&(this._geolocateButton.classList.add(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.setAttribute(\"aria-pressed\",\"true\"),this._geolocationWatchID=t.window.navigator.geolocation.watchPosition(this._onSuccess,this._onError,this.options.positionOptions));}else t.window.navigator.geolocation.getCurrentPosition(this._onSuccess,this._onError,this.options.positionOptions),this._timeoutId=setTimeout(this._finish,1e4);return !0},o.prototype._clearWatch=function(){t.window.navigator.geolocation.clearWatch(this._geolocationWatchID),this._geolocationWatchID=void 0,this._geolocateButton.classList.remove(\"mapboxgl-ctrl-geolocate-waiting\"),this._geolocateButton.setAttribute(\"aria-pressed\",\"false\"),this.options.showUserLocation&&this._updateMarker(null);},o}(t.Evented),Wo={maxWidth:100,unit:\"metric\"},Xo=function(e){this.options=t.extend({},Wo,e),t.bindAll([\"_onMove\",\"setUnit\"],this);};function Ho(t,e,i){var o,r,a,n,s,l,c=i&&i.maxWidth||100,u=t._container.clientHeight/2,h=(o=t.unproject([0,u]),r=t.unproject([c,u]),a=Math.PI/180,n=o.lat*a,s=r.lat*a,l=Math.sin(n)*Math.sin(s)+Math.cos(n)*Math.cos(s)*Math.cos((r.lng-o.lng)*a),6371e3*Math.acos(Math.min(l,1)));if(i&&\"imperial\"===i.unit){var p=3.2808*h;if(p>5280)Ko(e,c,p/5280,\"mi\");else Ko(e,c,p,\"ft\");}else if(i&&\"nautical\"===i.unit){Ko(e,c,h/1852,\"nm\");}else Ko(e,c,h,\"m\");}function Ko(t,e,i,o){var r,a,n,s=(r=i,a=Math.pow(10,(\"\"+Math.floor(r)).length-1),n=(n=r/a)>=10?10:n>=5?5:n>=3?3:n>=2?2:n>=1?1:function(t){var e=Math.pow(10,Math.ceil(-Math.log(t)/Math.LN10));return Math.round(t*e)/e}(n),a*n),l=s/i;\"m\"===o&&s>=1e3&&(s/=1e3,o=\"km\"),t.style.width=e*l+\"px\",t.innerHTML=s+o;}Xo.prototype.getDefaultPosition=function(){return \"bottom-left\"},Xo.prototype._onMove=function(){Ho(this._map,this._container,this.options);},Xo.prototype.onAdd=function(t){return this._map=t,this._container=i.create(\"div\",\"mapboxgl-ctrl mapboxgl-ctrl-scale\",t.getContainer()),this._map.on(\"move\",this._onMove),this._onMove(),this._container},Xo.prototype.onRemove=function(){i.remove(this._container),this._map.off(\"move\",this._onMove),this._map=void 0;},Xo.prototype.setUnit=function(t){this.options.unit=t,Ho(this._map,this._container,this.options);};var Yo=function(e){this._fullscreen=!1,e&&e.container&&(e.container instanceof t.window.HTMLElement?this._container=e.container:t.warnOnce(\"Full screen control 'container' must be a DOM element.\")),t.bindAll([\"_onClickFullscreen\",\"_changeIcon\"],this),\"onfullscreenchange\"in t.window.document?this._fullscreenchange=\"fullscreenchange\":\"onmozfullscreenchange\"in t.window.document?this._fullscreenchange=\"mozfullscreenchange\":\"onwebkitfullscreenchange\"in t.window.document?this._fullscreenchange=\"webkitfullscreenchange\":\"onmsfullscreenchange\"in t.window.document&&(this._fullscreenchange=\"MSFullscreenChange\"),this._className=\"mapboxgl-ctrl\";};Yo.prototype.onAdd=function(e){return this._map=e,this._container||(this._container=this._map.getContainer()),this._controlContainer=i.create(\"div\",this._className+\" mapboxgl-ctrl-group\"),this._checkFullscreenSupport()?this._setupUI():(this._controlContainer.style.display=\"none\",t.warnOnce(\"This device does not support fullscreen mode.\")),this._controlContainer},Yo.prototype.onRemove=function(){i.remove(this._controlContainer),this._map=null,t.window.document.removeEventListener(this._fullscreenchange,this._changeIcon);},Yo.prototype._checkFullscreenSupport=function(){return !!(t.window.document.fullscreenEnabled||t.window.document.mozFullScreenEnabled||t.window.document.msFullscreenEnabled||t.window.document.webkitFullscreenEnabled)},Yo.prototype._setupUI=function(){(this._fullscreenButton=i.create(\"button\",this._className+\"-icon \"+this._className+\"-fullscreen\",this._controlContainer)).type=\"button\",this._updateTitle(),this._fullscreenButton.addEventListener(\"click\",this._onClickFullscreen),t.window.document.addEventListener(this._fullscreenchange,this._changeIcon);},Yo.prototype._updateTitle=function(){var t=this._isFullscreen()?\"Exit fullscreen\":\"Enter fullscreen\";this._fullscreenButton.setAttribute(\"aria-label\",t),this._fullscreenButton.title=t;},Yo.prototype._isFullscreen=function(){return this._fullscreen},Yo.prototype._changeIcon=function(){(t.window.document.fullscreenElement||t.window.document.mozFullScreenElement||t.window.document.webkitFullscreenElement||t.window.document.msFullscreenElement)===this._container!==this._fullscreen&&(this._fullscreen=!this._fullscreen,this._fullscreenButton.classList.toggle(this._className+\"-shrink\"),this._fullscreenButton.classList.toggle(this._className+\"-fullscreen\"),this._updateTitle());},Yo.prototype._onClickFullscreen=function(){this._isFullscreen()?t.window.document.exitFullscreen?t.window.document.exitFullscreen():t.window.document.mozCancelFullScreen?t.window.document.mozCancelFullScreen():t.window.document.msExitFullscreen?t.window.document.msExitFullscreen():t.window.document.webkitCancelFullScreen&&t.window.document.webkitCancelFullScreen():this._container.requestFullscreen?this._container.requestFullscreen():this._container.mozRequestFullScreen?this._container.mozRequestFullScreen():this._container.msRequestFullscreen?this._container.msRequestFullscreen():this._container.webkitRequestFullscreen&&this._container.webkitRequestFullscreen();};var Jo={closeButton:!0,closeOnClick:!0,className:\"\",maxWidth:\"240px\"},Qo=function(e){function o(i){e.call(this),this.options=t.extend(Object.create(Jo),i),t.bindAll([\"_update\",\"_onClickClose\",\"remove\"],this);}return e&&(o.__proto__=e),o.prototype=Object.create(e&&e.prototype),o.prototype.constructor=o,o.prototype.addTo=function(e){var i=this;return this._map=e,this.options.closeOnClick&&this._map.on(\"click\",this._onClickClose),this._map.on(\"remove\",this.remove),this._update(),this._trackPointer?(this._map.on(\"mousemove\",function(t){i._update(t.point);}),this._map.on(\"mouseup\",function(t){i._update(t.point);}),this._container.classList.add(\"mapboxgl-popup-track-pointer\"),this._map._canvasContainer.classList.add(\"mapboxgl-track-pointer\")):this._map.on(\"move\",this._update),this.fire(new t.Event(\"open\")),this},o.prototype.isOpen=function(){return !!this._map},o.prototype.remove=function(){return this._content&&i.remove(this._content),this._container&&(i.remove(this._container),delete this._container),this._map&&(this._map.off(\"move\",this._update),this._map.off(\"click\",this._onClickClose),this._map.off(\"remove\",this.remove),this._map.off(\"mousemove\"),delete this._map),this.fire(new t.Event(\"close\")),this},o.prototype.getLngLat=function(){return this._lngLat},o.prototype.setLngLat=function(e){return this._lngLat=t.LngLat.convert(e),this._pos=null,this._map&&(this._map.on(\"move\",this._update),this._map.off(\"mousemove\"),this._container.classList.remove(\"mapboxgl-popup-track-pointer\"),this._map._canvasContainer.classList.remove(\"mapboxgl-track-pointer\")),this._trackPointer=!1,this._update(),this},o.prototype.trackPointer=function(){var t=this;return this._trackPointer=!0,this._pos=null,this._map&&(this._map.off(\"move\",this._update),this._map.on(\"mousemove\",function(e){t._update(e.point);}),this._map.on(\"drag\",function(e){t._update(e.point);}),this._container.classList.add(\"mapboxgl-popup-track-pointer\"),this._map._canvasContainer.classList.add(\"mapboxgl-track-pointer\")),this},o.prototype.getElement=function(){return this._container},o.prototype.setText=function(e){return this.setDOMContent(t.window.document.createTextNode(e))},o.prototype.setHTML=function(e){var i,o=t.window.document.createDocumentFragment(),r=t.window.document.createElement(\"body\");for(r.innerHTML=e;i=r.firstChild;)o.appendChild(i);return this.setDOMContent(o)},o.prototype.getMaxWidth=function(){return this._container.style.maxWidth},o.prototype.setMaxWidth=function(t){return this.options.maxWidth=t,this._update(),this},o.prototype.setDOMContent=function(t){return this._createContent(),this._content.appendChild(t),this._update(),this},o.prototype._createContent=function(){this._content&&i.remove(this._content),this._content=i.create(\"div\",\"mapboxgl-popup-content\",this._container),this.options.closeButton&&(this._closeButton=i.create(\"button\",\"mapboxgl-popup-close-button\",this._content),this._closeButton.type=\"button\",this._closeButton.setAttribute(\"aria-label\",\"Close popup\"),this._closeButton.innerHTML=\"&#215;\",this._closeButton.addEventListener(\"click\",this._onClickClose));},o.prototype._update=function(e){var o=this,r=this._lngLat||this._trackPointer;if(this._map&&r&&this._content&&(this._container||(this._container=i.create(\"div\",\"mapboxgl-popup\",this._map.getContainer()),this._tip=i.create(\"div\",\"mapboxgl-popup-tip\",this._container),this._container.appendChild(this._content),this.options.className&&this.options.className.split(\" \").forEach(function(t){return o._container.classList.add(t)})),this.options.maxWidth&&this._container.style.maxWidth!==this.options.maxWidth&&(this._container.style.maxWidth=this.options.maxWidth),this._map.transform.renderWorldCopies&&!this._trackPointer&&(this._lngLat=Uo(this._lngLat,this._pos,this._map.transform)),!this._trackPointer||e)){var a=this._pos=this._trackPointer&&e?e:this._map.project(this._lngLat),n=this.options.anchor,s=function e(i){if(i){if(\"number\"==typeof i){var o=Math.round(Math.sqrt(.5*Math.pow(i,2)));return {center:new t.Point(0,0),top:new t.Point(0,i),\"top-left\":new t.Point(o,o),\"top-right\":new t.Point(-o,o),bottom:new t.Point(0,-i),\"bottom-left\":new t.Point(o,-o),\"bottom-right\":new t.Point(-o,-o),left:new t.Point(i,0),right:new t.Point(-i,0)}}if(i instanceof t.Point||Array.isArray(i)){var r=t.Point.convert(i);return {center:r,top:r,\"top-left\":r,\"top-right\":r,bottom:r,\"bottom-left\":r,\"bottom-right\":r,left:r,right:r}}return {center:t.Point.convert(i.center||[0,0]),top:t.Point.convert(i.top||[0,0]),\"top-left\":t.Point.convert(i[\"top-left\"]||[0,0]),\"top-right\":t.Point.convert(i[\"top-right\"]||[0,0]),bottom:t.Point.convert(i.bottom||[0,0]),\"bottom-left\":t.Point.convert(i[\"bottom-left\"]||[0,0]),\"bottom-right\":t.Point.convert(i[\"bottom-right\"]||[0,0]),left:t.Point.convert(i.left||[0,0]),right:t.Point.convert(i.right||[0,0])}}return e(new t.Point(0,0))}(this.options.offset);if(!n){var l,c=this._container.offsetWidth,u=this._container.offsetHeight;l=a.y+s.bottom.y<u?[\"top\"]:a.y>this._map.transform.height-u?[\"bottom\"]:[],a.x<c/2?l.push(\"left\"):a.x>this._map.transform.width-c/2&&l.push(\"right\"),n=0===l.length?\"bottom\":l.join(\"-\");}var h=a.add(s[n]).round();i.setTransform(this._container,No[n]+\" translate(\"+h.x+\"px,\"+h.y+\"px)\"),Zo(this._container,n,\"popup\");}},o.prototype._onClickClose=function(){this.remove();},o}(t.Evented);var $o={version:t.version,supported:e,setRTLTextPlugin:t.setRTLTextPlugin,Map:ko,NavigationControl:Fo,GeolocateControl:Go,AttributionControl:zo,ScaleControl:Xo,FullscreenControl:Yo,Popup:Qo,Marker:qo,Style:Be,LngLat:t.LngLat,LngLatBounds:t.LngLatBounds,Point:t.Point,MercatorCoordinate:t.MercatorCoordinate,Evented:t.Evented,config:t.config,get accessToken(){return t.config.ACCESS_TOKEN},set accessToken(e){t.config.ACCESS_TOKEN=e;},get baseApiUrl(){return t.config.API_URL},set baseApiUrl(e){t.config.API_URL=e;},get workerCount(){return Rt.workerCount},set workerCount(t){Rt.workerCount=t;},get maxParallelImageRequests(){return t.config.MAX_PARALLEL_IMAGE_REQUESTS},set maxParallelImageRequests(e){t.config.MAX_PARALLEL_IMAGE_REQUESTS=e;},clearStorage:function(e){t.clearTileCache(e);},workerUrl:\"\"};return $o});\n\n//\n\nreturn mapboxgl;\n\n}));\n\n\n},{}],427:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createTable\n\nvar chull = _dereq_('convex-hull')\n\nfunction constructVertex(d, a, b) {\n  var x = new Array(d)\n  for(var i=0; i<d; ++i) {\n    x[i] = 0.0\n    if(i === a) {\n      x[i] += 0.5\n    }\n    if(i === b) {\n      x[i] += 0.5\n    }\n  }\n  return x\n}\n\nfunction constructCell(dimension, mask) {\n  if(mask === 0 || mask === (1<<(dimension+1))-1) {\n    return []\n  }\n  var points = []\n  var index  = []\n  for(var i=0; i<=dimension; ++i) {\n    if(mask & (1<<i)) {\n      points.push(constructVertex(dimension, i-1, i-1))\n      index.push(null)\n      for(var j=0; j<=dimension; ++j) {\n        if(~mask & (1<<j)) {\n          points.push(constructVertex(dimension, i-1, j-1))\n          index.push([i,j])\n        }\n      }\n    }\n  }\n  \n  //Preprocess points so first d+1 points are linearly independent\n  var hull = chull(points)\n  var faces = []\ni_loop:\n  for(var i=0; i<hull.length; ++i) {\n    var face = hull[i]\n    var nface = []\n    for(var j=0; j<face.length; ++j) {\n      if(!index[face[j]]) {\n        continue i_loop\n      }\n      nface.push(index[face[j]].slice())\n    }\n    faces.push(nface)\n  }\n  return faces\n}\n\nfunction createTable(dimension) {\n  var numCells = 1<<(dimension+1)\n  var result = new Array(numCells)\n  for(var i=0; i<numCells; ++i) {\n    result[i] = constructCell(dimension, i)\n  }\n  return result\n}\n},{\"convex-hull\":130}],428:[function(_dereq_,module,exports){\n/*jshint unused:true*/\n/*\nInput:  matrix      ; a 4x4 matrix\nOutput: translation ; a 3 component vector\n        scale       ; a 3 component vector\n        skew        ; skew factors XY,XZ,YZ represented as a 3 component vector\n        perspective ; a 4 component vector\n        quaternion  ; a 4 component vector\nReturns false if the matrix cannot be decomposed, true if it can\n\n\nReferences:\nhttps://github.com/kamicane/matrix3d/blob/master/lib/Matrix3d.js\nhttps://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc\nhttp://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix\n*/\n\nvar normalize = _dereq_('./normalize')\n\nvar create = _dereq_('gl-mat4/create')\nvar clone = _dereq_('gl-mat4/clone')\nvar determinant = _dereq_('gl-mat4/determinant')\nvar invert = _dereq_('gl-mat4/invert')\nvar transpose = _dereq_('gl-mat4/transpose')\nvar vec3 = {\n    length: _dereq_('gl-vec3/length'),\n    normalize: _dereq_('gl-vec3/normalize'),\n    dot: _dereq_('gl-vec3/dot'),\n    cross: _dereq_('gl-vec3/cross')\n}\n\nvar tmp = create()\nvar perspectiveMatrix = create()\nvar tmpVec4 = [0, 0, 0, 0]\nvar row = [ [0,0,0], [0,0,0], [0,0,0] ]\nvar pdum3 = [0,0,0]\n\nmodule.exports = function decomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {\n    if (!translation) translation = [0,0,0]\n    if (!scale) scale = [0,0,0]\n    if (!skew) skew = [0,0,0]\n    if (!perspective) perspective = [0,0,0,1]\n    if (!quaternion) quaternion = [0,0,0,1]\n\n    //normalize, if not possible then bail out early\n    if (!normalize(tmp, matrix))\n        return false\n\n    // perspectiveMatrix is used to solve for perspective, but it also provides\n    // an easy way to test for singularity of the upper 3x3 component.\n    clone(perspectiveMatrix, tmp)\n\n    perspectiveMatrix[3] = 0\n    perspectiveMatrix[7] = 0\n    perspectiveMatrix[11] = 0\n    perspectiveMatrix[15] = 1\n\n    // If the perspectiveMatrix is not invertible, we are also unable to\n    // decompose, so we'll bail early. Constant taken from SkMatrix44::invert.\n    if (Math.abs(determinant(perspectiveMatrix) < 1e-8))\n        return false\n\n    var a03 = tmp[3], a13 = tmp[7], a23 = tmp[11],\n            a30 = tmp[12], a31 = tmp[13], a32 = tmp[14], a33 = tmp[15]\n\n    // First, isolate perspective.\n    if (a03 !== 0 || a13 !== 0 || a23 !== 0) {\n        tmpVec4[0] = a03\n        tmpVec4[1] = a13\n        tmpVec4[2] = a23\n        tmpVec4[3] = a33\n\n        // Solve the equation by inverting perspectiveMatrix and multiplying\n        // rightHandSide by the inverse.\n        // resuing the perspectiveMatrix here since it's no longer needed\n        var ret = invert(perspectiveMatrix, perspectiveMatrix)\n        if (!ret) return false\n        transpose(perspectiveMatrix, perspectiveMatrix)\n\n        //multiply by transposed inverse perspective matrix, into perspective vec4\n        vec4multMat4(perspective, tmpVec4, perspectiveMatrix)\n    } else { \n        //no perspective\n        perspective[0] = perspective[1] = perspective[2] = 0\n        perspective[3] = 1\n    }\n\n    // Next take care of translation\n    translation[0] = a30\n    translation[1] = a31\n    translation[2] = a32\n\n    // Now get scale and shear. 'row' is a 3 element array of 3 component vectors\n    mat3from4(row, tmp)\n\n    // Compute X scale factor and normalize first row.\n    scale[0] = vec3.length(row[0])\n    vec3.normalize(row[0], row[0])\n\n    // Compute XY shear factor and make 2nd row orthogonal to 1st.\n    skew[0] = vec3.dot(row[0], row[1])\n    combine(row[1], row[1], row[0], 1.0, -skew[0])\n\n    // Now, compute Y scale and normalize 2nd row.\n    scale[1] = vec3.length(row[1])\n    vec3.normalize(row[1], row[1])\n    skew[0] /= scale[1]\n\n    // Compute XZ and YZ shears, orthogonalize 3rd row\n    skew[1] = vec3.dot(row[0], row[2])\n    combine(row[2], row[2], row[0], 1.0, -skew[1])\n    skew[2] = vec3.dot(row[1], row[2])\n    combine(row[2], row[2], row[1], 1.0, -skew[2])\n\n    // Next, get Z scale and normalize 3rd row.\n    scale[2] = vec3.length(row[2])\n    vec3.normalize(row[2], row[2])\n    skew[1] /= scale[2]\n    skew[2] /= scale[2]\n\n\n    // At this point, the matrix (in rows) is orthonormal.\n    // Check for a coordinate system flip.  If the determinant\n    // is -1, then negate the matrix and the scaling factors.\n    vec3.cross(pdum3, row[1], row[2])\n    if (vec3.dot(row[0], pdum3) < 0) {\n        for (var i = 0; i < 3; i++) {\n            scale[i] *= -1;\n            row[i][0] *= -1\n            row[i][1] *= -1\n            row[i][2] *= -1\n        }\n    }\n\n    // Now, get the rotations out\n    quaternion[0] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] - row[1][1] - row[2][2], 0))\n    quaternion[1] = 0.5 * Math.sqrt(Math.max(1 - row[0][0] + row[1][1] - row[2][2], 0))\n    quaternion[2] = 0.5 * Math.sqrt(Math.max(1 - row[0][0] - row[1][1] + row[2][2], 0))\n    quaternion[3] = 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0))\n\n    if (row[2][1] > row[1][2])\n        quaternion[0] = -quaternion[0]\n    if (row[0][2] > row[2][0])\n        quaternion[1] = -quaternion[1]\n    if (row[1][0] > row[0][1])\n        quaternion[2] = -quaternion[2]\n    return true\n}\n\n//will be replaced by gl-vec4 eventually\nfunction vec4multMat4(out, a, m) {\n    var x = a[0], y = a[1], z = a[2], w = a[3];\n    out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;\n    out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;\n    out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;\n    out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;\n    return out;\n}\n\n//gets upper-left of a 4x4 matrix into a 3x3 of vectors\nfunction mat3from4(out, mat4x4) {\n    out[0][0] = mat4x4[0]\n    out[0][1] = mat4x4[1]\n    out[0][2] = mat4x4[2]\n    \n    out[1][0] = mat4x4[4]\n    out[1][1] = mat4x4[5]\n    out[1][2] = mat4x4[6]\n\n    out[2][0] = mat4x4[8]\n    out[2][1] = mat4x4[9]\n    out[2][2] = mat4x4[10]\n}\n\nfunction combine(out, a, b, scale1, scale2) {\n    out[0] = a[0] * scale1 + b[0] * scale2\n    out[1] = a[1] * scale1 + b[1] * scale2\n    out[2] = a[2] * scale1 + b[2] * scale2\n}\n},{\"./normalize\":429,\"gl-mat4/clone\":259,\"gl-mat4/create\":260,\"gl-mat4/determinant\":261,\"gl-mat4/invert\":265,\"gl-mat4/transpose\":276,\"gl-vec3/cross\":334,\"gl-vec3/dot\":339,\"gl-vec3/length\":349,\"gl-vec3/normalize\":356}],429:[function(_dereq_,module,exports){\nmodule.exports = function normalize(out, mat) {\n    var m44 = mat[15]\n    // Cannot normalize.\n    if (m44 === 0) \n        return false\n    var scale = 1 / m44\n    for (var i=0; i<16; i++)\n        out[i] = mat[i] * scale\n    return true\n}\n},{}],430:[function(_dereq_,module,exports){\nvar lerp = _dereq_('gl-vec3/lerp')\n\nvar recompose = _dereq_('mat4-recompose')\nvar decompose = _dereq_('mat4-decompose')\nvar determinant = _dereq_('gl-mat4/determinant')\nvar slerp = _dereq_('quat-slerp')\n\nvar state0 = state()\nvar state1 = state()\nvar tmp = state()\n\nmodule.exports = interpolate\nfunction interpolate(out, start, end, alpha) {\n    if (determinant(start) === 0 || determinant(end) === 0)\n        return false\n\n    //decompose the start and end matrices into individual components\n    var r0 = decompose(start, state0.translate, state0.scale, state0.skew, state0.perspective, state0.quaternion)\n    var r1 = decompose(end, state1.translate, state1.scale, state1.skew, state1.perspective, state1.quaternion)\n    if (!r0 || !r1)\n        return false    \n\n\n    //now lerp/slerp the start and end components into a temporary     lerp(tmptranslate, state0.translate, state1.translate, alpha)\n    lerp(tmp.translate, state0.translate, state1.translate, alpha)\n    lerp(tmp.skew, state0.skew, state1.skew, alpha)\n    lerp(tmp.scale, state0.scale, state1.scale, alpha)\n    lerp(tmp.perspective, state0.perspective, state1.perspective, alpha)\n    slerp(tmp.quaternion, state0.quaternion, state1.quaternion, alpha)\n\n    //and recompose into our 'out' matrix\n    recompose(out, tmp.translate, tmp.scale, tmp.skew, tmp.perspective, tmp.quaternion)\n    return true\n}\n\nfunction state() {\n    return {\n        translate: vec3(),\n        scale: vec3(1),\n        skew: vec3(),\n        perspective: vec4(),\n        quaternion: vec4()\n    }\n}\n\nfunction vec3(n) {\n    return [n||0,n||0,n||0]\n}\n\nfunction vec4() {\n    return [0,0,0,1]\n}\n},{\"gl-mat4/determinant\":261,\"gl-vec3/lerp\":350,\"mat4-decompose\":428,\"mat4-recompose\":431,\"quat-slerp\":483}],431:[function(_dereq_,module,exports){\n/*\nInput:  translation ; a 3 component vector\n        scale       ; a 3 component vector\n        skew        ; skew factors XY,XZ,YZ represented as a 3 component vector\n        perspective ; a 4 component vector\n        quaternion  ; a 4 component vector\nOutput: matrix      ; a 4x4 matrix\n\nFrom: http://www.w3.org/TR/css3-transforms/#recomposing-to-a-3d-matrix\n*/\n\nvar mat4 = {\n    identity: _dereq_('gl-mat4/identity'),\n    translate: _dereq_('gl-mat4/translate'),\n    multiply: _dereq_('gl-mat4/multiply'),\n    create: _dereq_('gl-mat4/create'),\n    scale: _dereq_('gl-mat4/scale'),\n    fromRotationTranslation: _dereq_('gl-mat4/fromRotationTranslation')\n}\n\nvar rotationMatrix = mat4.create()\nvar temp = mat4.create()\n\nmodule.exports = function recomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {\n    mat4.identity(matrix)\n\n    //apply translation & rotation\n    mat4.fromRotationTranslation(matrix, quaternion, translation)\n\n    //apply perspective\n    matrix[3] = perspective[0]\n    matrix[7] = perspective[1]\n    matrix[11] = perspective[2]\n    matrix[15] = perspective[3]\n        \n    // apply skew\n    // temp is a identity 4x4 matrix initially\n    mat4.identity(temp)\n\n    if (skew[2] !== 0) {\n        temp[9] = skew[2]\n        mat4.multiply(matrix, matrix, temp)\n    }\n\n    if (skew[1] !== 0) {\n        temp[9] = 0\n        temp[8] = skew[1]\n        mat4.multiply(matrix, matrix, temp)\n    }\n\n    if (skew[0] !== 0) {\n        temp[8] = 0\n        temp[4] = skew[0]\n        mat4.multiply(matrix, matrix, temp)\n    }\n\n    //apply scale\n    mat4.scale(matrix, matrix, scale)\n    return matrix\n}\n},{\"gl-mat4/create\":260,\"gl-mat4/fromRotationTranslation\":263,\"gl-mat4/identity\":264,\"gl-mat4/multiply\":267,\"gl-mat4/scale\":274,\"gl-mat4/translate\":275}],432:[function(_dereq_,module,exports){\n'use strict';\nmodule.exports = Math.log2 || function (x) {\n\treturn Math.log(x) * Math.LOG2E;\n};\n\n},{}],433:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar bsearch   = _dereq_('binary-search-bounds')\r\nvar m4interp  = _dereq_('mat4-interpolate')\r\nvar invert44  = _dereq_('gl-mat4/invert')\r\nvar rotateX   = _dereq_('gl-mat4/rotateX')\r\nvar rotateY   = _dereq_('gl-mat4/rotateY')\r\nvar rotateZ   = _dereq_('gl-mat4/rotateZ')\r\nvar lookAt    = _dereq_('gl-mat4/lookAt')\r\nvar translate = _dereq_('gl-mat4/translate')\r\nvar scale     = _dereq_('gl-mat4/scale')\r\nvar normalize = _dereq_('gl-vec3/normalize')\r\n\r\nvar DEFAULT_CENTER = [0,0,0]\r\n\r\nmodule.exports = createMatrixCameraController\r\n\r\nfunction MatrixCameraController(initialMatrix) {\r\n  this._components    = initialMatrix.slice()\r\n  this._time          = [0]\r\n  this.prevMatrix     = initialMatrix.slice()\r\n  this.nextMatrix     = initialMatrix.slice()\r\n  this.computedMatrix = initialMatrix.slice()\r\n  this.computedInverse = initialMatrix.slice()\r\n  this.computedEye    = [0,0,0]\r\n  this.computedUp     = [0,0,0]\r\n  this.computedCenter = [0,0,0]\r\n  this.computedRadius = [0]\r\n  this._limits        = [-Infinity, Infinity]\r\n}\r\n\r\nvar proto = MatrixCameraController.prototype\r\n\r\nproto.recalcMatrix = function(t) {\r\n  var time = this._time\r\n  var tidx = bsearch.le(time, t)\r\n  var mat = this.computedMatrix\r\n  if(tidx < 0) {\r\n    return\r\n  }\r\n  var comps = this._components\r\n  if(tidx === time.length-1) {\r\n    var ptr = 16*tidx\r\n    for(var i=0; i<16; ++i) {\r\n      mat[i] = comps[ptr++]\r\n    }\r\n  } else {\r\n    var dt = (time[tidx+1] - time[tidx])\r\n    var ptr = 16*tidx\r\n    var prev = this.prevMatrix\r\n    var allEqual = true\r\n    for(var i=0; i<16; ++i) {\r\n      prev[i] = comps[ptr++]\r\n    }\r\n    var next = this.nextMatrix\r\n    for(var i=0; i<16; ++i) {\r\n      next[i] = comps[ptr++]\r\n      allEqual = allEqual && (prev[i] === next[i])\r\n    }\r\n    if(dt < 1e-6 || allEqual) {\r\n      for(var i=0; i<16; ++i) {\r\n        mat[i] = prev[i]\r\n      }\r\n    } else {\r\n      m4interp(mat, prev, next, (t - time[tidx])/dt)\r\n    }\r\n  }\r\n\r\n  var up = this.computedUp\r\n  up[0] = mat[1]\r\n  up[1] = mat[5]\r\n  up[2] = mat[9]\r\n  normalize(up, up)\r\n\r\n  var imat = this.computedInverse\r\n  invert44(imat, mat)\r\n  var eye = this.computedEye\r\n  var w = imat[15]\r\n  eye[0] = imat[12]/w\r\n  eye[1] = imat[13]/w\r\n  eye[2] = imat[14]/w\r\n\r\n  var center = this.computedCenter\r\n  var radius = Math.exp(this.computedRadius[0])\r\n  for(var i=0; i<3; ++i) {\r\n    center[i] = eye[i] - mat[2+4*i] * radius\r\n  }\r\n}\r\n\r\nproto.idle = function(t) {\r\n  if(t < this.lastT()) {\r\n    return\r\n  }\r\n  var mc = this._components\r\n  var ptr = mc.length-16\r\n  for(var i=0; i<16; ++i) {\r\n    mc.push(mc[ptr++])\r\n  }\r\n  this._time.push(t)\r\n}\r\n\r\nproto.flush = function(t) {\r\n  var idx = bsearch.gt(this._time, t) - 2\r\n  if(idx < 0) {\r\n    return\r\n  }\r\n  this._time.splice(0, idx)\r\n  this._components.splice(0, 16*idx)\r\n}\r\n\r\nproto.lastT = function() {\r\n  return this._time[this._time.length-1]\r\n}\r\n\r\nproto.lookAt = function(t, eye, center, up) {\r\n  this.recalcMatrix(t)\r\n  eye    = eye || this.computedEye\r\n  center = center || DEFAULT_CENTER\r\n  up     = up || this.computedUp\r\n  this.setMatrix(t, lookAt(this.computedMatrix, eye, center, up))\r\n  var d2 = 0.0\r\n  for(var i=0; i<3; ++i) {\r\n    d2 += Math.pow(center[i] - eye[i], 2)\r\n  }\r\n  d2 = Math.log(Math.sqrt(d2))\r\n  this.computedRadius[0] = d2\r\n}\r\n\r\nproto.rotate = function(t, yaw, pitch, roll) {\r\n  this.recalcMatrix(t)\r\n  var mat = this.computedInverse\r\n  if(yaw)   rotateY(mat, mat, yaw)\r\n  if(pitch) rotateX(mat, mat, pitch)\r\n  if(roll)  rotateZ(mat, mat, roll)\r\n  this.setMatrix(t, invert44(this.computedMatrix, mat))\r\n}\r\n\r\nvar tvec = [0,0,0]\r\n\r\nproto.pan = function(t, dx, dy, dz) {\r\n  tvec[0] = -(dx || 0.0)\r\n  tvec[1] = -(dy || 0.0)\r\n  tvec[2] = -(dz || 0.0)\r\n  this.recalcMatrix(t)\r\n  var mat = this.computedInverse\r\n  translate(mat, mat, tvec)\r\n  this.setMatrix(t, invert44(mat, mat))\r\n}\r\n\r\nproto.translate = function(t, dx, dy, dz) {\r\n  tvec[0] = dx || 0.0\r\n  tvec[1] = dy || 0.0\r\n  tvec[2] = dz || 0.0\r\n  this.recalcMatrix(t)\r\n  var mat = this.computedMatrix\r\n  translate(mat, mat, tvec)\r\n  this.setMatrix(t, mat)\r\n}\r\n\r\nproto.setMatrix = function(t, mat) {\r\n  if(t < this.lastT()) {\r\n    return\r\n  }\r\n  this._time.push(t)\r\n  for(var i=0; i<16; ++i) {\r\n    this._components.push(mat[i])\r\n  }\r\n}\r\n\r\nproto.setDistance = function(t, d) {\r\n  this.computedRadius[0] = d\r\n}\r\n\r\nproto.setDistanceLimits = function(a,b) {\r\n  var lim = this._limits\r\n  lim[0] = a\r\n  lim[1] = b\r\n}\r\n\r\nproto.getDistanceLimits = function(out) {\r\n  var lim = this._limits\r\n  if(out) {\r\n    out[0] = lim[0]\r\n    out[1] = lim[1]\r\n    return out\r\n  }\r\n  return lim\r\n}\r\n\r\nfunction createMatrixCameraController(options) {\r\n  options = options || {}\r\n  var matrix = options.matrix || \r\n              [1,0,0,0,\r\n               0,1,0,0,\r\n               0,0,1,0,\r\n               0,0,0,1]\r\n  return new MatrixCameraController(matrix)\r\n}\r\n\n},{\"binary-search-bounds\":91,\"gl-mat4/invert\":265,\"gl-mat4/lookAt\":266,\"gl-mat4/rotateX\":271,\"gl-mat4/rotateY\":272,\"gl-mat4/rotateZ\":273,\"gl-mat4/scale\":274,\"gl-mat4/translate\":275,\"gl-vec3/normalize\":356,\"mat4-interpolate\":430}],434:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = monotoneConvexHull2D\n\nvar orient = _dereq_('robust-orientation')[3]\n\nfunction monotoneConvexHull2D(points) {\n  var n = points.length\n\n  if(n < 3) {\n    var result = new Array(n)\n    for(var i=0; i<n; ++i) {\n      result[i] = i\n    }\n\n    if(n === 2 &&\n       points[0][0] === points[1][0] &&\n       points[0][1] === points[1][1]) {\n      return [0]\n    }\n\n    return result\n  }\n\n  //Sort point indices along x-axis\n  var sorted = new Array(n)\n  for(var i=0; i<n; ++i) {\n    sorted[i] = i\n  }\n  sorted.sort(function(a,b) {\n    var d = points[a][0]-points[b][0]\n    if(d) {\n      return d\n    }\n    return points[a][1] - points[b][1]\n  })\n\n  //Construct upper and lower hulls\n  var lower = [sorted[0], sorted[1]]\n  var upper = [sorted[0], sorted[1]]\n\n  for(var i=2; i<n; ++i) {\n    var idx = sorted[i]\n    var p   = points[idx]\n\n    //Insert into lower list\n    var m = lower.length\n    while(m > 1 && orient(\n        points[lower[m-2]], \n        points[lower[m-1]], \n        p) <= 0) {\n      m -= 1\n      lower.pop()\n    }\n    lower.push(idx)\n\n    //Insert into upper list\n    m = upper.length\n    while(m > 1 && orient(\n        points[upper[m-2]], \n        points[upper[m-1]], \n        p) >= 0) {\n      m -= 1\n      upper.pop()\n    }\n    upper.push(idx)\n  }\n\n  //Merge lists together\n  var result = new Array(upper.length + lower.length - 2)\n  var ptr    = 0\n  for(var i=0, nl=lower.length; i<nl; ++i) {\n    result[ptr++] = lower[i]\n  }\n  for(var j=upper.length-2; j>0; --j) {\n    result[ptr++] = upper[j]\n  }\n\n  //Return result\n  return result\n}\n},{\"robust-orientation\":510}],435:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = mouseListen\n\nvar mouse = _dereq_('mouse-event')\n\nfunction mouseListen (element, callback) {\n  if (!callback) {\n    callback = element\n    element = window\n  }\n\n  var buttonState = 0\n  var x = 0\n  var y = 0\n  var mods = {\n    shift: false,\n    alt: false,\n    control: false,\n    meta: false\n  }\n  var attached = false\n\n  function updateMods (ev) {\n    var changed = false\n    if ('altKey' in ev) {\n      changed = changed || ev.altKey !== mods.alt\n      mods.alt = !!ev.altKey\n    }\n    if ('shiftKey' in ev) {\n      changed = changed || ev.shiftKey !== mods.shift\n      mods.shift = !!ev.shiftKey\n    }\n    if ('ctrlKey' in ev) {\n      changed = changed || ev.ctrlKey !== mods.control\n      mods.control = !!ev.ctrlKey\n    }\n    if ('metaKey' in ev) {\n      changed = changed || ev.metaKey !== mods.meta\n      mods.meta = !!ev.metaKey\n    }\n    return changed\n  }\n\n  function handleEvent (nextButtons, ev) {\n    var nextX = mouse.x(ev)\n    var nextY = mouse.y(ev)\n    if ('buttons' in ev) {\n      nextButtons = ev.buttons | 0\n    }\n    if (nextButtons !== buttonState ||\n      nextX !== x ||\n      nextY !== y ||\n      updateMods(ev)) {\n      buttonState = nextButtons | 0\n      x = nextX || 0\n      y = nextY || 0\n      callback && callback(buttonState, x, y, mods)\n    }\n  }\n\n  function clearState (ev) {\n    handleEvent(0, ev)\n  }\n\n  function handleBlur () {\n    if (buttonState ||\n      x ||\n      y ||\n      mods.shift ||\n      mods.alt ||\n      mods.meta ||\n      mods.control) {\n      x = y = 0\n      buttonState = 0\n      mods.shift = mods.alt = mods.control = mods.meta = false\n      callback && callback(0, 0, 0, mods)\n    }\n  }\n\n  function handleMods (ev) {\n    if (updateMods(ev)) {\n      callback && callback(buttonState, x, y, mods)\n    }\n  }\n\n  function handleMouseMove (ev) {\n    if (mouse.buttons(ev) === 0) {\n      handleEvent(0, ev)\n    } else {\n      handleEvent(buttonState, ev)\n    }\n  }\n\n  function handleMouseDown (ev) {\n    handleEvent(buttonState | mouse.buttons(ev), ev)\n  }\n\n  function handleMouseUp (ev) {\n    handleEvent(buttonState & ~mouse.buttons(ev), ev)\n  }\n\n  function attachListeners () {\n    if (attached) {\n      return\n    }\n    attached = true\n\n    element.addEventListener('mousemove', handleMouseMove)\n\n    element.addEventListener('mousedown', handleMouseDown)\n\n    element.addEventListener('mouseup', handleMouseUp)\n\n    element.addEventListener('mouseleave', clearState)\n    element.addEventListener('mouseenter', clearState)\n    element.addEventListener('mouseout', clearState)\n    element.addEventListener('mouseover', clearState)\n\n    element.addEventListener('blur', handleBlur)\n\n    element.addEventListener('keyup', handleMods)\n    element.addEventListener('keydown', handleMods)\n    element.addEventListener('keypress', handleMods)\n\n    if (element !== window) {\n      window.addEventListener('blur', handleBlur)\n\n      window.addEventListener('keyup', handleMods)\n      window.addEventListener('keydown', handleMods)\n      window.addEventListener('keypress', handleMods)\n    }\n  }\n\n  function detachListeners () {\n    if (!attached) {\n      return\n    }\n    attached = false\n\n    element.removeEventListener('mousemove', handleMouseMove)\n\n    element.removeEventListener('mousedown', handleMouseDown)\n\n    element.removeEventListener('mouseup', handleMouseUp)\n\n    element.removeEventListener('mouseleave', clearState)\n    element.removeEventListener('mouseenter', clearState)\n    element.removeEventListener('mouseout', clearState)\n    element.removeEventListener('mouseover', clearState)\n\n    element.removeEventListener('blur', handleBlur)\n\n    element.removeEventListener('keyup', handleMods)\n    element.removeEventListener('keydown', handleMods)\n    element.removeEventListener('keypress', handleMods)\n\n    if (element !== window) {\n      window.removeEventListener('blur', handleBlur)\n\n      window.removeEventListener('keyup', handleMods)\n      window.removeEventListener('keydown', handleMods)\n      window.removeEventListener('keypress', handleMods)\n    }\n  }\n\n  // Attach listeners\n  attachListeners()\n\n  var result = {\n    element: element\n  }\n\n  Object.defineProperties(result, {\n    enabled: {\n      get: function () { return attached },\n      set: function (f) {\n        if (f) {\n          attachListeners()\n        } else {\n          detachListeners()\n        }\n      },\n      enumerable: true\n    },\n    buttons: {\n      get: function () { return buttonState },\n      enumerable: true\n    },\n    x: {\n      get: function () { return x },\n      enumerable: true\n    },\n    y: {\n      get: function () { return y },\n      enumerable: true\n    },\n    mods: {\n      get: function () { return mods },\n      enumerable: true\n    }\n  })\n\n  return result\n}\n\n},{\"mouse-event\":437}],436:[function(_dereq_,module,exports){\nvar rootPosition = { left: 0, top: 0 }\n\nmodule.exports = mouseEventOffset\nfunction mouseEventOffset (ev, target, out) {\n  target = target || ev.currentTarget || ev.srcElement\n  if (!Array.isArray(out)) {\n    out = [ 0, 0 ]\n  }\n  var cx = ev.clientX || 0\n  var cy = ev.clientY || 0\n  var rect = getBoundingClientOffset(target)\n  out[0] = cx - rect.left\n  out[1] = cy - rect.top\n  return out\n}\n\nfunction getBoundingClientOffset (element) {\n  if (element === window ||\n      element === document ||\n      element === document.body) {\n    return rootPosition\n  } else {\n    return element.getBoundingClientRect()\n  }\n}\n\n},{}],437:[function(_dereq_,module,exports){\n'use strict'\n\nfunction mouseButtons(ev) {\n  if(typeof ev === 'object') {\n    if('buttons' in ev) {\n      return ev.buttons\n    } else if('which' in ev) {\n      var b = ev.which\n      if(b === 2) {\n        return 4\n      } else if(b === 3) {\n        return 2\n      } else if(b > 0) {\n        return 1<<(b-1)\n      }\n    } else if('button' in ev) {\n      var b = ev.button\n      if(b === 1) {\n        return 4\n      } else if(b === 2) {\n        return 2\n      } else if(b >= 0) {\n        return 1<<b\n      }\n    }\n  }\n  return 0\n}\nexports.buttons = mouseButtons\n\nfunction mouseElement(ev) {\n  return ev.target || ev.srcElement || window\n}\nexports.element = mouseElement\n\nfunction mouseRelativeX(ev) {\n  if(typeof ev === 'object') {\n    if('offsetX' in ev) {\n      return ev.offsetX\n    }\n    var target = mouseElement(ev)\n    var bounds = target.getBoundingClientRect()\n    return ev.clientX - bounds.left\n  }\n  return 0\n}\nexports.x = mouseRelativeX\n\nfunction mouseRelativeY(ev) {\n  if(typeof ev === 'object') {\n    if('offsetY' in ev) {\n      return ev.offsetY\n    }\n    var target = mouseElement(ev)\n    var bounds = target.getBoundingClientRect()\n    return ev.clientY - bounds.top\n  }\n  return 0\n}\nexports.y = mouseRelativeY\n\n},{}],438:[function(_dereq_,module,exports){\n'use strict'\n\nvar toPX = _dereq_('to-px')\n\nmodule.exports = mouseWheelListen\n\nfunction mouseWheelListen(element, callback, noScroll) {\n  if(typeof element === 'function') {\n    noScroll = !!callback\n    callback = element\n    element = window\n  }\n  var lineHeight = toPX('ex', element)\n  var listener = function(ev) {\n    if(noScroll) {\n      ev.preventDefault()\n    }\n    var dx = ev.deltaX || 0\n    var dy = ev.deltaY || 0\n    var dz = ev.deltaZ || 0\n    var mode = ev.deltaMode\n    var scale = 1\n    switch(mode) {\n      case 1:\n        scale = lineHeight\n      break\n      case 2:\n        scale = window.innerHeight\n      break\n    }\n    dx *= scale\n    dy *= scale\n    dz *= scale\n    if(dx || dy || dz) {\n      return callback(dx, dy, dz, ev)\n    }\n  }\n  element.addEventListener('wheel', listener)\n  return listener\n}\n\n},{\"to-px\":539}],439:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar pool = _dereq_(\"typedarray-pool\")\n\nmodule.exports = createSurfaceExtractor\n\n//Helper macros\nfunction array(i) {\n  return \"a\" + i\n}\nfunction data(i) {\n  return \"d\" + i\n}\nfunction cube(i,bitmask) {\n  return \"c\" + i + \"_\" + bitmask\n}\nfunction shape(i) {\n  return \"s\" + i\n}\nfunction stride(i,j) {\n  return \"t\" + i + \"_\" + j\n}\nfunction offset(i) {\n  return \"o\" + i\n}\nfunction scalar(i) {\n  return \"x\" + i\n}\nfunction pointer(i) {\n  return \"p\" + i\n}\nfunction delta(i,bitmask) {\n  return \"d\" + i + \"_\" + bitmask\n}\nfunction index(i) {\n  return \"i\" + i\n}\nfunction step(i,j) {\n  return \"u\" + i + \"_\" + j\n}\nfunction pcube(bitmask) {\n  return \"b\" + bitmask\n}\nfunction qcube(bitmask) {\n  return \"y\" + bitmask\n}\nfunction pdelta(bitmask) {\n  return \"e\" + bitmask\n}\nfunction vert(i) {\n  return \"v\" + i\n}\nvar VERTEX_IDS = \"V\"\nvar PHASES = \"P\"\nvar VERTEX_COUNT = \"N\"\nvar POOL_SIZE = \"Q\"\nvar POINTER = \"X\"\nvar TEMPORARY = \"T\"\n\nfunction permBitmask(dimension, mask, order) {\n  var r = 0\n  for(var i=0; i<dimension; ++i) {\n    if(mask & (1<<i)) {\n      r |= (1<<order[i])\n    }\n  }\n  return r\n}\n\n//Generates the surface procedure\nfunction compileSurfaceProcedure(vertexFunc, faceFunc, phaseFunc, scalarArgs, order, typesig) {\n  var arrayArgs = typesig.length\n  var dimension = order.length\n\n  if(dimension < 2) {\n    throw new Error(\"ndarray-extract-contour: Dimension must be at least 2\")\n  }\n\n  var funcName = \"extractContour\" + order.join(\"_\")\n  var code = []\n  var vars = []\n  var args = []\n\n  //Assemble arguments\n  for(var i=0; i<arrayArgs; ++i) {\n    args.push(array(i))  \n  }\n  for(var i=0; i<scalarArgs; ++i) {\n    args.push(scalar(i))\n  }\n\n  //Shape\n  for(var i=0; i<dimension; ++i) {\n    vars.push(shape(i) + \"=\" + array(0) + \".shape[\" + i + \"]|0\")\n  }\n  //Data, stride, offset pointers\n  for(var i=0; i<arrayArgs; ++i) {\n    vars.push(data(i) + \"=\" + array(i) + \".data\",\n              offset(i) + \"=\" + array(i) + \".offset|0\")\n    for(var j=0; j<dimension; ++j) {\n      vars.push(stride(i,j) + \"=\" + array(i) + \".stride[\" + j + \"]|0\")\n    }\n  }\n  //Pointer, delta and cube variables\n  for(var i=0; i<arrayArgs; ++i) {\n    vars.push(pointer(i) + \"=\" + offset(i))\n    vars.push(cube(i,0))\n    for(var j=1; j<(1<<dimension); ++j) {\n      var ptrStr = []\n      for(var k=0; k<dimension; ++k) {\n        if(j & (1<<k)) {\n          ptrStr.push(\"-\" + stride(i,k))\n        }\n      }\n      vars.push(delta(i,j) + \"=(\" + ptrStr.join(\"\") + \")|0\")\n      vars.push(cube(i,j) + \"=0\")\n    }\n  }\n  //Create step variables\n  for(var i=0; i<arrayArgs; ++i) {\n    for(var j=0; j<dimension; ++j) {\n      var stepVal = [ stride(i,order[j]) ]\n      if(j > 0) {\n        stepVal.push(stride(i, order[j-1]) + \"*\" + shape(order[j-1]) )\n      }\n      vars.push(step(i,order[j]) + \"=(\" + stepVal.join(\"-\") + \")|0\")\n    }\n  }\n  //Create index variables\n  for(var i=0; i<dimension; ++i) {\n    vars.push(index(i) + \"=0\")\n  }\n  //Vertex count\n  vars.push(VERTEX_COUNT + \"=0\")\n  //Compute pool size, initialize pool step\n  var sizeVariable = [\"2\"]\n  for(var i=dimension-2; i>=0; --i) {\n    sizeVariable.push(shape(order[i]))\n  }\n  //Previous phases and vertex_ids\n  vars.push(POOL_SIZE + \"=(\" + sizeVariable.join(\"*\") + \")|0\",\n            PHASES + \"=mallocUint32(\" + POOL_SIZE + \")\",\n            VERTEX_IDS + \"=mallocUint32(\" + POOL_SIZE + \")\",\n            POINTER + \"=0\")\n  //Create cube variables for phases\n  vars.push(pcube(0) + \"=0\")\n  for(var j=1; j<(1<<dimension); ++j) {\n    var cubeDelta = []\n    var cubeStep = [ ]\n    for(var k=0; k<dimension; ++k) {\n      if(j & (1<<k)) {\n        if(cubeStep.length === 0) {\n          cubeDelta.push(\"1\")\n        } else {\n          cubeDelta.unshift(cubeStep.join(\"*\"))\n        }\n      }\n      cubeStep.push(shape(order[k]))\n    }\n    var signFlag = \"\"\n    if(cubeDelta[0].indexOf(shape(order[dimension-2])) < 0) {\n      signFlag = \"-\"\n    }\n    var jperm = permBitmask(dimension, j, order)\n    vars.push(pdelta(jperm) + \"=(-\" + cubeDelta.join(\"-\") + \")|0\",\n              qcube(jperm) + \"=(\" + signFlag + cubeDelta.join(\"-\") + \")|0\",\n              pcube(jperm) + \"=0\")\n  }\n  vars.push(vert(0) + \"=0\", TEMPORARY + \"=0\")\n\n  function forLoopBegin(i, start) {\n    code.push(\"for(\", index(order[i]), \"=\", start, \";\",\n      index(order[i]), \"<\", shape(order[i]), \";\",\n      \"++\", index(order[i]), \"){\")\n  }\n\n  function forLoopEnd(i) {\n    for(var j=0; j<arrayArgs; ++j) {\n      code.push(pointer(j), \"+=\", step(j,order[i]), \";\")\n    }\n    code.push(\"}\")\n  }\n\n  function fillEmptySlice(k) {\n    for(var i=k-1; i>=0; --i) {\n      forLoopBegin(i, 0) \n    }\n    var phaseFuncArgs = []\n    for(var i=0; i<arrayArgs; ++i) {\n      if(typesig[i]) {\n        phaseFuncArgs.push(data(i) + \".get(\" + pointer(i) + \")\")\n      } else {\n        phaseFuncArgs.push(data(i) + \"[\" + pointer(i) + \"]\")\n      }\n    }\n    for(var i=0; i<scalarArgs; ++i) {\n      phaseFuncArgs.push(scalar(i))\n    }\n    code.push(PHASES, \"[\", POINTER, \"++]=phase(\", phaseFuncArgs.join(), \");\")\n    for(var i=0; i<k; ++i) {\n      forLoopEnd(i)\n    }\n    for(var j=0; j<arrayArgs; ++j) {\n      code.push(pointer(j), \"+=\", step(j,order[k]), \";\")\n    }\n  }\n\n  function processGridCell(mask) {\n    //Read in local data\n    for(var i=0; i<arrayArgs; ++i) {\n      if(typesig[i]) {\n        code.push(cube(i,0), \"=\", data(i), \".get(\", pointer(i), \");\")\n      } else {\n        code.push(cube(i,0), \"=\", data(i), \"[\", pointer(i), \"];\")\n      }\n    }\n\n    //Read in phase\n    var phaseFuncArgs = []\n    for(var i=0; i<arrayArgs; ++i) {\n      phaseFuncArgs.push(cube(i,0))\n    }\n    for(var i=0; i<scalarArgs; ++i) {\n      phaseFuncArgs.push(scalar(i))\n    }\n    \n    code.push(pcube(0), \"=\", PHASES, \"[\", POINTER, \"]=phase(\", phaseFuncArgs.join(), \");\")\n    \n    //Read in other cube data\n    for(var j=1; j<(1<<dimension); ++j) {\n      code.push(pcube(j), \"=\", PHASES, \"[\", POINTER, \"+\", pdelta(j), \"];\")\n    }\n\n    //Check for boundary crossing\n    var vertexPredicate = []\n    for(var j=1; j<(1<<dimension); ++j) {\n      vertexPredicate.push(\"(\" + pcube(0) + \"!==\" + pcube(j) + \")\")\n    }\n    code.push(\"if(\", vertexPredicate.join(\"||\"), \"){\")\n\n    //Read in boundary data\n    var vertexArgs = []\n    for(var i=0; i<dimension; ++i) {\n      vertexArgs.push(index(i))\n    }\n    for(var i=0; i<arrayArgs; ++i) {\n      vertexArgs.push(cube(i,0))\n      for(var j=1; j<(1<<dimension); ++j) {\n        if(typesig[i]) {\n          code.push(cube(i,j), \"=\", data(i), \".get(\", pointer(i), \"+\", delta(i,j), \");\")\n        } else {\n          code.push(cube(i,j), \"=\", data(i), \"[\", pointer(i), \"+\", delta(i,j), \"];\")\n        }\n        vertexArgs.push(cube(i,j))\n      }\n    }\n    for(var i=0; i<(1<<dimension); ++i) {\n      vertexArgs.push(pcube(i))\n    }\n    for(var i=0; i<scalarArgs; ++i) {\n      vertexArgs.push(scalar(i))\n    }\n\n    //Generate vertex\n    code.push(\"vertex(\", vertexArgs.join(), \");\",\n      vert(0), \"=\", VERTEX_IDS, \"[\", POINTER, \"]=\", VERTEX_COUNT, \"++;\")\n\n    //Check for face crossings\n    var base = (1<<dimension)-1\n    var corner = pcube(base)\n    for(var j=0; j<dimension; ++j) {\n      if((mask & ~(1<<j))===0) {\n        //Check face\n        var subset = base^(1<<j)\n        var edge = pcube(subset)\n        var faceArgs = [ ]\n        for(var k=subset; k>0; k=(k-1)&subset) {\n          faceArgs.push(VERTEX_IDS + \"[\" + POINTER + \"+\" + pdelta(k) + \"]\")\n        }\n        faceArgs.push(vert(0))\n        for(var k=0; k<arrayArgs; ++k) {\n          if(j&1) {\n            faceArgs.push(cube(k,base), cube(k,subset))\n          } else {\n            faceArgs.push(cube(k,subset), cube(k,base))\n          }\n        }\n        if(j&1) {\n          faceArgs.push(corner, edge)\n        } else {\n          faceArgs.push(edge, corner)\n        }\n        for(var k=0; k<scalarArgs; ++k) {\n          faceArgs.push(scalar(k))\n        }\n        code.push(\"if(\", corner, \"!==\", edge, \"){\",\n          \"face(\", faceArgs.join(), \")}\")\n      }\n    }\n    \n    //Increment pointer, close off if statement\n    code.push(\"}\",\n      POINTER, \"+=1;\")\n  }\n\n  function flip() {\n    for(var j=1; j<(1<<dimension); ++j) {\n      code.push(TEMPORARY, \"=\", pdelta(j), \";\",\n                pdelta(j), \"=\", qcube(j), \";\",\n                qcube(j), \"=\", TEMPORARY, \";\")\n    }\n  }\n\n  function createLoop(i, mask) {\n    if(i < 0) {\n      processGridCell(mask)\n      return\n    }\n    fillEmptySlice(i)\n    code.push(\"if(\", shape(order[i]), \">0){\",\n      index(order[i]), \"=1;\")\n    createLoop(i-1, mask|(1<<order[i]))\n\n    for(var j=0; j<arrayArgs; ++j) {\n      code.push(pointer(j), \"+=\", step(j,order[i]), \";\")\n    }\n    if(i === dimension-1) {\n      code.push(POINTER, \"=0;\")\n      flip()\n    }\n    forLoopBegin(i, 2)\n    createLoop(i-1, mask)\n    if(i === dimension-1) {\n      code.push(\"if(\", index(order[dimension-1]), \"&1){\",\n        POINTER, \"=0;}\")\n      flip()\n    }\n    forLoopEnd(i)\n    code.push(\"}\")\n  }\n\n  createLoop(dimension-1, 0)\n\n  //Release scratch memory\n  code.push(\"freeUint32(\", VERTEX_IDS, \");freeUint32(\", PHASES, \");\")\n\n  //Compile and link procedure\n  var procedureCode = [\n    \"'use strict';\",\n    \"function \", funcName, \"(\", args.join(), \"){\",\n      \"var \", vars.join(), \";\",\n      code.join(\"\"),\n    \"}\",\n    \"return \", funcName ].join(\"\")\n\n  var proc = new Function(\n    \"vertex\", \n    \"face\", \n    \"phase\", \n    \"mallocUint32\", \n    \"freeUint32\",\n    procedureCode)\n  return proc(\n    vertexFunc, \n    faceFunc, \n    phaseFunc, \n    pool.mallocUint32, \n    pool.freeUint32)\n}\n\nfunction createSurfaceExtractor(args) {\n  function error(msg) {\n    throw new Error(\"ndarray-extract-contour: \" + msg)\n  }\n  if(typeof args !== \"object\") {\n    error(\"Must specify arguments\")\n  }\n  var order = args.order\n  if(!Array.isArray(order)) {\n    error(\"Must specify order\")\n  }\n  var arrays = args.arrayArguments||1\n  if(arrays < 1) {\n    error(\"Must have at least one array argument\")\n  }\n  var scalars = args.scalarArguments||0\n  if(scalars < 0) {\n    error(\"Scalar arg count must be > 0\")\n  }\n  if(typeof args.vertex !== \"function\") {\n    error(\"Must specify vertex creation function\")\n  }\n  if(typeof args.cell !== \"function\") {\n    error(\"Must specify cell creation function\")\n  }\n  if(typeof args.phase !== \"function\") {\n    error(\"Must specify phase function\")\n  }\n  var getters = args.getters || []\n  var typesig = new Array(arrays)\n  for(var i=0; i<arrays; ++i) {\n    if(getters.indexOf(i) >= 0) {\n      typesig[i] = true\n    } else {\n      typesig[i] = false\n    }\n  }\n  return compileSurfaceProcedure(\n    args.vertex,\n    args.cell,\n    args.phase,\n    scalars,\n    order,\n    typesig)\n}\n},{\"typedarray-pool\":545}],440:[function(_dereq_,module,exports){\n\"use strict\"\n\n\n\nvar fill = _dereq_('cwise/lib/wrapper')({\"args\":[\"index\",\"array\",\"scalar\"],\"pre\":{\"body\":\"{}\",\"args\":[],\"thisVars\":[],\"localVars\":[]},\"body\":{\"body\":\"{_inline_1_arg1_=_inline_1_arg2_.apply(void 0,_inline_1_arg0_)}\",\"args\":[{\"name\":\"_inline_1_arg0_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_1_arg1_\",\"lvalue\":true,\"rvalue\":false,\"count\":1},{\"name\":\"_inline_1_arg2_\",\"lvalue\":false,\"rvalue\":true,\"count\":1}],\"thisVars\":[],\"localVars\":[]},\"post\":{\"body\":\"{}\",\"args\":[],\"thisVars\":[],\"localVars\":[]},\"debug\":false,\"funcName\":\"cwise\",\"blockSize\":64})\n\nmodule.exports = function(array, f) {\n  fill(array, f)\n  return array\n}\n\n},{\"cwise/lib/wrapper\":149}],441:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports      = gradient\n\nvar dup             = _dereq_('dup')\nvar cwiseCompiler   = _dereq_('cwise-compiler')\n\nvar TEMPLATE_CACHE  = {}\nvar GRADIENT_CACHE  = {}\n\nvar EmptyProc = {\n  body: \"\",\n  args: [],\n  thisVars: [],\n  localVars: []\n}\n\nvar centralDiff = cwiseCompiler({\n  args: [ 'array', 'array', 'array' ],\n  pre: EmptyProc,\n  post: EmptyProc,\n  body: {\n    args: [ {\n      name: 'out', \n      lvalue: true,\n      rvalue: false,\n      count: 1\n    }, {\n      name: 'left', \n      lvalue: false,\n      rvalue: true,\n      count: 1\n    }, {\n      name: 'right', \n      lvalue: false,\n      rvalue: true,\n      count: 1\n    }],\n    body: \"out=0.5*(left-right)\",\n    thisVars: [],\n    localVars: []\n  },\n  funcName: 'cdiff'\n})\n\nvar zeroOut = cwiseCompiler({\n  args: [ 'array' ],\n  pre: EmptyProc,\n  post: EmptyProc,\n  body: {\n    args: [ {\n      name: 'out', \n      lvalue: true,\n      rvalue: false,\n      count: 1\n    }],\n    body: \"out=0\",\n    thisVars: [],\n    localVars: []\n  },\n  funcName: 'zero'\n})\n\nfunction generateTemplate(d) {\n  if(d in TEMPLATE_CACHE) {\n    return TEMPLATE_CACHE[d]\n  }\n  var code = []\n  for(var i=0; i<d; ++i) {\n    code.push('out', i, 's=0.5*(inp', i, 'l-inp', i, 'r);')\n  }\n  var args = [ 'array' ]\n  var names = ['junk']\n  for(var i=0; i<d; ++i) {\n    args.push('array')\n    names.push('out' + i + 's')\n    var o = dup(d)\n    o[i] = -1\n    args.push({\n      array: 0,\n      offset: o.slice()\n    })\n    o[i] = 1\n    args.push({\n      array: 0,\n      offset: o.slice()\n    })\n    names.push('inp' + i + 'l', 'inp' + i + 'r')\n  }\n  return TEMPLATE_CACHE[d] = cwiseCompiler({\n    args: args,\n    pre:  EmptyProc,\n    post: EmptyProc,\n    body: {\n      body: code.join(''),\n      args: names.map(function(n) {\n        return {\n          name: n,\n          lvalue: n.indexOf('out') === 0,\n          rvalue: n.indexOf('inp') === 0,\n          count: (n!=='junk')|0\n        }\n      }),\n      thisVars: [],\n      localVars: []\n    },\n    funcName: 'fdTemplate' + d\n  })\n}\n\nfunction generateGradient(boundaryConditions) {\n  var token = boundaryConditions.join()\n  var proc = GRADIENT_CACHE[token]\n  if(proc) {\n    return proc\n  }\n\n  var d = boundaryConditions.length\n  var code = ['function gradient(dst,src){var s=src.shape.slice();' ]\n  \n  function handleBoundary(facet) {\n    var cod = d - facet.length\n\n    var loStr = []\n    var hiStr = []\n    var pickStr = []\n    for(var i=0; i<d; ++i) {\n      if(facet.indexOf(i+1) >= 0) {\n        pickStr.push('0')\n      } else if(facet.indexOf(-(i+1)) >= 0) {\n        pickStr.push('s['+i+']-1')\n      } else {\n        pickStr.push('-1')\n        loStr.push('1')\n        hiStr.push('s['+i+']-2')\n      }\n    }\n    var boundStr = '.lo(' + loStr.join() + ').hi(' + hiStr.join() + ')'\n    if(loStr.length === 0) {\n      boundStr = ''\n    }\n        \n    if(cod > 0) {\n      code.push('if(1') \n      for(var i=0; i<d; ++i) {\n        if(facet.indexOf(i+1) >= 0 || facet.indexOf(-(i+1)) >= 0) {\n          continue\n        }\n        code.push('&&s[', i, ']>2')\n      }\n      code.push('){grad', cod, '(src.pick(', pickStr.join(), ')', boundStr)\n      for(var i=0; i<d; ++i) {\n        if(facet.indexOf(i+1) >= 0 || facet.indexOf(-(i+1)) >= 0) {\n          continue\n        }\n        code.push(',dst.pick(', pickStr.join(), ',', i, ')', boundStr)\n      }\n      code.push(');')\n    }\n\n    for(var i=0; i<facet.length; ++i) {\n      var bnd = Math.abs(facet[i])-1\n      var outStr = 'dst.pick(' + pickStr.join() + ',' + bnd + ')' + boundStr\n      switch(boundaryConditions[bnd]) {\n\n        case 'clamp':\n          var cPickStr = pickStr.slice()\n          var dPickStr = pickStr.slice()\n          if(facet[i] < 0) {\n            cPickStr[bnd] = 's[' + bnd + ']-2'\n          } else {\n            dPickStr[bnd] = '1'\n          }\n          if(cod === 0) {\n            code.push('if(s[', bnd, ']>1){dst.set(',\n              pickStr.join(), ',', bnd, ',0.5*(src.get(',\n                cPickStr.join(), ')-src.get(',\n                dPickStr.join(), ')))}else{dst.set(',\n              pickStr.join(), ',', bnd, ',0)};')\n          } else {\n            code.push('if(s[', bnd, ']>1){diff(', outStr, \n                ',src.pick(', cPickStr.join(), ')', boundStr, \n                ',src.pick(', dPickStr.join(), ')', boundStr, \n                ');}else{zero(', outStr, ');};')\n          }\n        break\n\n        case 'mirror':\n          if(cod === 0) {\n            code.push('dst.set(', pickStr.join(), ',', bnd, ',0);')\n          } else {\n            code.push('zero(', outStr, ');')\n          }\n        break\n\n        case 'wrap':\n          var aPickStr = pickStr.slice()\n          var bPickStr = pickStr.slice()\n          if(facet[i] < 0) {\n            aPickStr[bnd] = 's[' + bnd + ']-2'\n            bPickStr[bnd] = '0'\n            \n          } else {\n            aPickStr[bnd] = 's[' + bnd + ']-1'\n            bPickStr[bnd] = '1'\n          }\n          if(cod === 0) {\n            code.push('if(s[', bnd, ']>2){dst.set(',\n              pickStr.join(), ',', bnd, ',0.5*(src.get(',\n                aPickStr.join(), ')-src.get(',\n                bPickStr.join(), ')))}else{dst.set(',\n              pickStr.join(), ',', bnd, ',0)};')\n          } else {\n            code.push('if(s[', bnd, ']>2){diff(', outStr, \n                ',src.pick(', aPickStr.join(), ')', boundStr, \n                ',src.pick(', bPickStr.join(), ')', boundStr, \n                ');}else{zero(', outStr, ');};')\n          }\n        break\n\n        default:\n          throw new Error('ndarray-gradient: Invalid boundary condition')\n      }\n    }\n\n    if(cod > 0) {\n      code.push('};')\n    }\n  }\n\n  //Enumerate ridges, facets, etc. of hypercube\n  for(var i=0; i<(1<<d); ++i) {\n    var faces = []\n    for(var j=0; j<d; ++j) {\n      if(i & (1<<j)) {\n        faces.push(j+1)\n      }\n    }\n    for(var k=0; k<(1<<faces.length); ++k) {\n      var sfaces = faces.slice()\n      for(var j=0; j<faces.length; ++j) {\n        if(k & (1<<j)) {\n          sfaces[j] = -sfaces[j]\n        }\n      }\n      handleBoundary(sfaces)\n    }\n  }\n\n  code.push('return dst;};return gradient')\n\n  //Compile and link routine, save cached procedure\n  var linkNames = [ 'diff', 'zero' ]\n  var linkArgs  = [ centralDiff, zeroOut ]\n  for(var i=1; i<=d; ++i) {\n    linkNames.push('grad' + i)\n    linkArgs.push(generateTemplate(i))\n  }\n  linkNames.push(code.join(''))\n\n  var link = Function.apply(void 0, linkNames)\n  var proc = link.apply(void 0, linkArgs)\n  TEMPLATE_CACHE[token] = proc\n  return proc\n}\n\nfunction gradient(out, inp, bc) {\n  if(Array.isArray(bc)) {\n    if(bc.length !== inp.dimension) {\n      throw new Error('ndarray-gradient: invalid boundary conditions')\n    }\n  } else if(typeof bc === 'string') {\n    bc = dup(inp.dimension, bc)\n  } else {\n    bc = dup(inp.dimension, 'clamp')\n  }\n  if(out.dimension !== inp.dimension + 1) {\n    throw new Error('ndarray-gradient: output dimension must be +1 input dimension')\n  }\n  if(out.shape[inp.dimension] !== inp.dimension) {\n    throw new Error('ndarray-gradient: output shape must match input shape')\n  }\n  for(var i=0; i<inp.dimension; ++i) {\n    if(out.shape[i] !== inp.shape[i]) {\n      throw new Error('ndarray-gradient: shape mismatch')\n    }\n  }\n  if(inp.size === 0) {\n    return out\n  }\n  if(inp.dimension <= 0) {\n    out.set(0)\n    return out\n  }\n  var cached = generateGradient(bc)\n  return cached(out, inp)\n}\n},{\"cwise-compiler\":146,\"dup\":170}],442:[function(_dereq_,module,exports){\n'use strict'\n\nvar warp = _dereq_('ndarray-warp')\nvar invert = _dereq_('gl-matrix-invert')\n\nmodule.exports = applyHomography\n\nfunction applyHomography(dest, src, Xi) {\n  var n = src.dimension\n  var X = invert([], Xi)\n  warp(dest, src, function(out_c, inp_c) {\n    for(var i=0; i<n; ++i) {\n      out_c[i] = X[(n+1)*n + i]\n      for(var j=0; j<n; ++j) {\n        out_c[i] += X[(n+1)*j+i] * inp_c[j]\n      }\n    }\n    var w = X[(n+1)*(n+1)-1]\n    for(var j=0; j<n; ++j) {\n      w += X[(n+1)*j+n] * inp_c[j]\n    }\n    var wr = 1.0 / w\n    for(var i=0; i<n; ++i) {\n      out_c[i] *= wr\n    }\n    return out_c\n  })\n  return dest\n}\n},{\"gl-matrix-invert\":277,\"ndarray-warp\":449}],443:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction interp1d(arr, x) {\n  var ix = Math.floor(x)\n    , fx = x - ix\n    , s0 = 0 <= ix   && ix   < arr.shape[0]\n    , s1 = 0 <= ix+1 && ix+1 < arr.shape[0]\n    , w0 = s0 ? +arr.get(ix)   : 0.0\n    , w1 = s1 ? +arr.get(ix+1) : 0.0\n  return (1.0-fx)*w0 + fx*w1\n}\n\nfunction interp2d(arr, x, y) {\n  var ix = Math.floor(x)\n    , fx = x - ix\n    , s0 = 0 <= ix   && ix   < arr.shape[0]\n    , s1 = 0 <= ix+1 && ix+1 < arr.shape[0]\n    , iy = Math.floor(y)\n    , fy = y - iy\n    , t0 = 0 <= iy   && iy   < arr.shape[1]\n    , t1 = 0 <= iy+1 && iy+1 < arr.shape[1]\n    , w00 = s0&&t0 ? arr.get(ix  ,iy  ) : 0.0\n    , w01 = s0&&t1 ? arr.get(ix  ,iy+1) : 0.0\n    , w10 = s1&&t0 ? arr.get(ix+1,iy  ) : 0.0\n    , w11 = s1&&t1 ? arr.get(ix+1,iy+1) : 0.0\n  return (1.0-fy) * ((1.0-fx)*w00 + fx*w10) + fy * ((1.0-fx)*w01 + fx*w11)\n}\n\nfunction interp3d(arr, x, y, z) {\n  var ix = Math.floor(x)\n    , fx = x - ix\n    , s0 = 0 <= ix   && ix   < arr.shape[0]\n    , s1 = 0 <= ix+1 && ix+1 < arr.shape[0]\n    , iy = Math.floor(y)\n    , fy = y - iy\n    , t0 = 0 <= iy   && iy   < arr.shape[1]\n    , t1 = 0 <= iy+1 && iy+1 < arr.shape[1]\n    , iz = Math.floor(z)\n    , fz = z - iz\n    , u0 = 0 <= iz   && iz   < arr.shape[2]\n    , u1 = 0 <= iz+1 && iz+1 < arr.shape[2]\n    , w000 = s0&&t0&&u0 ? arr.get(ix,iy,iz)       : 0.0\n    , w010 = s0&&t1&&u0 ? arr.get(ix,iy+1,iz)     : 0.0\n    , w100 = s1&&t0&&u0 ? arr.get(ix+1,iy,iz)     : 0.0\n    , w110 = s1&&t1&&u0 ? arr.get(ix+1,iy+1,iz)   : 0.0\n    , w001 = s0&&t0&&u1 ? arr.get(ix,iy,iz+1)     : 0.0\n    , w011 = s0&&t1&&u1 ? arr.get(ix,iy+1,iz+1)   : 0.0\n    , w101 = s1&&t0&&u1 ? arr.get(ix+1,iy,iz+1)   : 0.0\n    , w111 = s1&&t1&&u1 ? arr.get(ix+1,iy+1,iz+1) : 0.0\n  return (1.0-fz) * ((1.0-fy) * ((1.0-fx)*w000 + fx*w100) + fy * ((1.0-fx)*w010 + fx*w110)) + fz * ((1.0-fy) * ((1.0-fx)*w001 + fx*w101) + fy * ((1.0-fx)*w011 + fx*w111))\n}\n\nfunction interpNd(arr) {\n  var d = arr.shape.length|0\n    , ix = new Array(d)\n    , fx = new Array(d)\n    , s0 = new Array(d)\n    , s1 = new Array(d)\n    , i, t\n  for(i=0; i<d; ++i) {\n    t = +arguments[i+1]\n    ix[i] = Math.floor(t)\n    fx[i] = t - ix[i]\n    s0[i] = (0 <= ix[i]   && ix[i]   < arr.shape[i])\n    s1[i] = (0 <= ix[i]+1 && ix[i]+1 < arr.shape[i])\n  }\n  var r = 0.0, j, w, idx\ni_loop:\n  for(i=0; i<(1<<d); ++i) {\n    w = 1.0\n    idx = arr.offset\n    for(j=0; j<d; ++j) {\n      if(i & (1<<j)) {\n        if(!s1[j]) {\n          continue i_loop\n        }\n        w *= fx[j]\n        idx += arr.stride[j] * (ix[j] + 1)\n      } else {\n        if(!s0[j]) {\n          continue i_loop\n        }\n        w *= 1.0 - fx[j]\n        idx += arr.stride[j] * ix[j]\n      }\n    }\n    r += w * arr.data[idx]\n  }\n  return r\n}\n\nfunction interpolate(arr, x, y, z) {\n  switch(arr.shape.length) {\n    case 0:\n      return 0.0\n    case 1:\n      return interp1d(arr, x)\n    case 2:\n      return interp2d(arr, x, y)\n    case 3:\n      return interp3d(arr, x, y, z)\n    default:\n      return interpNd.apply(undefined, arguments)\n  }\n}\nmodule.exports = interpolate\nmodule.exports.d1 = interp1d\nmodule.exports.d2 = interp2d\nmodule.exports.d3 = interp3d\n\n},{}],444:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar compile = _dereq_(\"cwise-compiler\")\n\nvar EmptyProc = {\n  body: \"\",\n  args: [],\n  thisVars: [],\n  localVars: []\n}\n\nfunction fixup(x) {\n  if(!x) {\n    return EmptyProc\n  }\n  for(var i=0; i<x.args.length; ++i) {\n    var a = x.args[i]\n    if(i === 0) {\n      x.args[i] = {name: a, lvalue:true, rvalue: !!x.rvalue, count:x.count||1 }\n    } else {\n      x.args[i] = {name: a, lvalue:false, rvalue:true, count: 1}\n    }\n  }\n  if(!x.thisVars) {\n    x.thisVars = []\n  }\n  if(!x.localVars) {\n    x.localVars = []\n  }\n  return x\n}\n\nfunction pcompile(user_args) {\n  return compile({\n    args:     user_args.args,\n    pre:      fixup(user_args.pre),\n    body:     fixup(user_args.body),\n    post:     fixup(user_args.proc),\n    funcName: user_args.funcName\n  })\n}\n\nfunction makeOp(user_args) {\n  var args = []\n  for(var i=0; i<user_args.args.length; ++i) {\n    args.push(\"a\"+i)\n  }\n  var wrapper = new Function(\"P\", [\n    \"return function \", user_args.funcName, \"_ndarrayops(\", args.join(\",\"), \") {P(\", args.join(\",\"), \");return a0}\"\n  ].join(\"\"))\n  return wrapper(pcompile(user_args))\n}\n\nvar assign_ops = {\n  add:  \"+\",\n  sub:  \"-\",\n  mul:  \"*\",\n  div:  \"/\",\n  mod:  \"%\",\n  band: \"&\",\n  bor:  \"|\",\n  bxor: \"^\",\n  lshift: \"<<\",\n  rshift: \">>\",\n  rrshift: \">>>\"\n}\n;(function(){\n  for(var id in assign_ops) {\n    var op = assign_ops[id]\n    exports[id] = makeOp({\n      args: [\"array\",\"array\",\"array\"],\n      body: {args:[\"a\",\"b\",\"c\"],\n             body: \"a=b\"+op+\"c\"},\n      funcName: id\n    })\n    exports[id+\"eq\"] = makeOp({\n      args: [\"array\",\"array\"],\n      body: {args:[\"a\",\"b\"],\n             body:\"a\"+op+\"=b\"},\n      rvalue: true,\n      funcName: id+\"eq\"\n    })\n    exports[id+\"s\"] = makeOp({\n      args: [\"array\", \"array\", \"scalar\"],\n      body: {args:[\"a\",\"b\",\"s\"],\n             body:\"a=b\"+op+\"s\"},\n      funcName: id+\"s\"\n    })\n    exports[id+\"seq\"] = makeOp({\n      args: [\"array\",\"scalar\"],\n      body: {args:[\"a\",\"s\"],\n             body:\"a\"+op+\"=s\"},\n      rvalue: true,\n      funcName: id+\"seq\"\n    })\n  }\n})();\n\nvar unary_ops = {\n  not: \"!\",\n  bnot: \"~\",\n  neg: \"-\",\n  recip: \"1.0/\"\n}\n;(function(){\n  for(var id in unary_ops) {\n    var op = unary_ops[id]\n    exports[id] = makeOp({\n      args: [\"array\", \"array\"],\n      body: {args:[\"a\",\"b\"],\n             body:\"a=\"+op+\"b\"},\n      funcName: id\n    })\n    exports[id+\"eq\"] = makeOp({\n      args: [\"array\"],\n      body: {args:[\"a\"],\n             body:\"a=\"+op+\"a\"},\n      rvalue: true,\n      count: 2,\n      funcName: id+\"eq\"\n    })\n  }\n})();\n\nvar binary_ops = {\n  and: \"&&\",\n  or: \"||\",\n  eq: \"===\",\n  neq: \"!==\",\n  lt: \"<\",\n  gt: \">\",\n  leq: \"<=\",\n  geq: \">=\"\n}\n;(function() {\n  for(var id in binary_ops) {\n    var op = binary_ops[id]\n    exports[id] = makeOp({\n      args: [\"array\",\"array\",\"array\"],\n      body: {args:[\"a\", \"b\", \"c\"],\n             body:\"a=b\"+op+\"c\"},\n      funcName: id\n    })\n    exports[id+\"s\"] = makeOp({\n      args: [\"array\",\"array\",\"scalar\"],\n      body: {args:[\"a\", \"b\", \"s\"],\n             body:\"a=b\"+op+\"s\"},\n      funcName: id+\"s\"\n    })\n    exports[id+\"eq\"] = makeOp({\n      args: [\"array\", \"array\"],\n      body: {args:[\"a\", \"b\"],\n             body:\"a=a\"+op+\"b\"},\n      rvalue:true,\n      count:2,\n      funcName: id+\"eq\"\n    })\n    exports[id+\"seq\"] = makeOp({\n      args: [\"array\", \"scalar\"],\n      body: {args:[\"a\",\"s\"],\n             body:\"a=a\"+op+\"s\"},\n      rvalue:true,\n      count:2,\n      funcName: id+\"seq\"\n    })\n  }\n})();\n\nvar math_unary = [\n  \"abs\",\n  \"acos\",\n  \"asin\",\n  \"atan\",\n  \"ceil\",\n  \"cos\",\n  \"exp\",\n  \"floor\",\n  \"log\",\n  \"round\",\n  \"sin\",\n  \"sqrt\",\n  \"tan\"\n]\n;(function() {\n  for(var i=0; i<math_unary.length; ++i) {\n    var f = math_unary[i]\n    exports[f] = makeOp({\n                    args: [\"array\", \"array\"],\n                    pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                    body: {args:[\"a\",\"b\"], body:\"a=this_f(b)\", thisVars:[\"this_f\"]},\n                    funcName: f\n                  })\n    exports[f+\"eq\"] = makeOp({\n                      args: [\"array\"],\n                      pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                      body: {args: [\"a\"], body:\"a=this_f(a)\", thisVars:[\"this_f\"]},\n                      rvalue: true,\n                      count: 2,\n                      funcName: f+\"eq\"\n                    })\n  }\n})();\n\nvar math_comm = [\n  \"max\",\n  \"min\",\n  \"atan2\",\n  \"pow\"\n]\n;(function(){\n  for(var i=0; i<math_comm.length; ++i) {\n    var f= math_comm[i]\n    exports[f] = makeOp({\n                  args:[\"array\", \"array\", \"array\"],\n                  pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                  body: {args:[\"a\",\"b\",\"c\"], body:\"a=this_f(b,c)\", thisVars:[\"this_f\"]},\n                  funcName: f\n                })\n    exports[f+\"s\"] = makeOp({\n                  args:[\"array\", \"array\", \"scalar\"],\n                  pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                  body: {args:[\"a\",\"b\",\"c\"], body:\"a=this_f(b,c)\", thisVars:[\"this_f\"]},\n                  funcName: f+\"s\"\n                  })\n    exports[f+\"eq\"] = makeOp({ args:[\"array\", \"array\"],\n                  pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                  body: {args:[\"a\",\"b\"], body:\"a=this_f(a,b)\", thisVars:[\"this_f\"]},\n                  rvalue: true,\n                  count: 2,\n                  funcName: f+\"eq\"\n                  })\n    exports[f+\"seq\"] = makeOp({ args:[\"array\", \"scalar\"],\n                  pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                  body: {args:[\"a\",\"b\"], body:\"a=this_f(a,b)\", thisVars:[\"this_f\"]},\n                  rvalue:true,\n                  count:2,\n                  funcName: f+\"seq\"\n                  })\n  }\n})();\n\nvar math_noncomm = [\n  \"atan2\",\n  \"pow\"\n]\n;(function(){\n  for(var i=0; i<math_noncomm.length; ++i) {\n    var f= math_noncomm[i]\n    exports[f+\"op\"] = makeOp({\n                  args:[\"array\", \"array\", \"array\"],\n                  pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                  body: {args:[\"a\",\"b\",\"c\"], body:\"a=this_f(c,b)\", thisVars:[\"this_f\"]},\n                  funcName: f+\"op\"\n                })\n    exports[f+\"ops\"] = makeOp({\n                  args:[\"array\", \"array\", \"scalar\"],\n                  pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                  body: {args:[\"a\",\"b\",\"c\"], body:\"a=this_f(c,b)\", thisVars:[\"this_f\"]},\n                  funcName: f+\"ops\"\n                  })\n    exports[f+\"opeq\"] = makeOp({ args:[\"array\", \"array\"],\n                  pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                  body: {args:[\"a\",\"b\"], body:\"a=this_f(b,a)\", thisVars:[\"this_f\"]},\n                  rvalue: true,\n                  count: 2,\n                  funcName: f+\"opeq\"\n                  })\n    exports[f+\"opseq\"] = makeOp({ args:[\"array\", \"scalar\"],\n                  pre: {args:[], body:\"this_f=Math.\"+f, thisVars:[\"this_f\"]},\n                  body: {args:[\"a\",\"b\"], body:\"a=this_f(b,a)\", thisVars:[\"this_f\"]},\n                  rvalue:true,\n                  count:2,\n                  funcName: f+\"opseq\"\n                  })\n  }\n})();\n\nexports.any = compile({\n  args:[\"array\"],\n  pre: EmptyProc,\n  body: {args:[{name:\"a\", lvalue:false, rvalue:true, count:1}], body: \"if(a){return true}\", localVars: [], thisVars: []},\n  post: {args:[], localVars:[], thisVars:[], body:\"return false\"},\n  funcName: \"any\"\n})\n\nexports.all = compile({\n  args:[\"array\"],\n  pre: EmptyProc,\n  body: {args:[{name:\"x\", lvalue:false, rvalue:true, count:1}], body: \"if(!x){return false}\", localVars: [], thisVars: []},\n  post: {args:[], localVars:[], thisVars:[], body:\"return true\"},\n  funcName: \"all\"\n})\n\nexports.sum = compile({\n  args:[\"array\"],\n  pre: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"this_s=0\"},\n  body: {args:[{name:\"a\", lvalue:false, rvalue:true, count:1}], body: \"this_s+=a\", localVars: [], thisVars: [\"this_s\"]},\n  post: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"return this_s\"},\n  funcName: \"sum\"\n})\n\nexports.prod = compile({\n  args:[\"array\"],\n  pre: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"this_s=1\"},\n  body: {args:[{name:\"a\", lvalue:false, rvalue:true, count:1}], body: \"this_s*=a\", localVars: [], thisVars: [\"this_s\"]},\n  post: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"return this_s\"},\n  funcName: \"prod\"\n})\n\nexports.norm2squared = compile({\n  args:[\"array\"],\n  pre: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"this_s=0\"},\n  body: {args:[{name:\"a\", lvalue:false, rvalue:true, count:2}], body: \"this_s+=a*a\", localVars: [], thisVars: [\"this_s\"]},\n  post: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"return this_s\"},\n  funcName: \"norm2squared\"\n})\n  \nexports.norm2 = compile({\n  args:[\"array\"],\n  pre: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"this_s=0\"},\n  body: {args:[{name:\"a\", lvalue:false, rvalue:true, count:2}], body: \"this_s+=a*a\", localVars: [], thisVars: [\"this_s\"]},\n  post: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"return Math.sqrt(this_s)\"},\n  funcName: \"norm2\"\n})\n  \n\nexports.norminf = compile({\n  args:[\"array\"],\n  pre: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"this_s=0\"},\n  body: {args:[{name:\"a\", lvalue:false, rvalue:true, count:4}], body:\"if(-a>this_s){this_s=-a}else if(a>this_s){this_s=a}\", localVars: [], thisVars: [\"this_s\"]},\n  post: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"return this_s\"},\n  funcName: \"norminf\"\n})\n\nexports.norm1 = compile({\n  args:[\"array\"],\n  pre: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"this_s=0\"},\n  body: {args:[{name:\"a\", lvalue:false, rvalue:true, count:3}], body: \"this_s+=a<0?-a:a\", localVars: [], thisVars: [\"this_s\"]},\n  post: {args:[], localVars:[], thisVars:[\"this_s\"], body:\"return this_s\"},\n  funcName: \"norm1\"\n})\n\nexports.sup = compile({\n  args: [ \"array\" ],\n  pre:\n   { body: \"this_h=-Infinity\",\n     args: [],\n     thisVars: [ \"this_h\" ],\n     localVars: [] },\n  body:\n   { body: \"if(_inline_1_arg0_>this_h)this_h=_inline_1_arg0_\",\n     args: [{\"name\":\"_inline_1_arg0_\",\"lvalue\":false,\"rvalue\":true,\"count\":2} ],\n     thisVars: [ \"this_h\" ],\n     localVars: [] },\n  post:\n   { body: \"return this_h\",\n     args: [],\n     thisVars: [ \"this_h\" ],\n     localVars: [] }\n })\n\nexports.inf = compile({\n  args: [ \"array\" ],\n  pre:\n   { body: \"this_h=Infinity\",\n     args: [],\n     thisVars: [ \"this_h\" ],\n     localVars: [] },\n  body:\n   { body: \"if(_inline_1_arg0_<this_h)this_h=_inline_1_arg0_\",\n     args: [{\"name\":\"_inline_1_arg0_\",\"lvalue\":false,\"rvalue\":true,\"count\":2} ],\n     thisVars: [ \"this_h\" ],\n     localVars: [] },\n  post:\n   { body: \"return this_h\",\n     args: [],\n     thisVars: [ \"this_h\" ],\n     localVars: [] }\n })\n\nexports.argmin = compile({\n  args:[\"index\",\"array\",\"shape\"],\n  pre:{\n    body:\"{this_v=Infinity;this_i=_inline_0_arg2_.slice(0)}\",\n    args:[\n      {name:\"_inline_0_arg0_\",lvalue:false,rvalue:false,count:0},\n      {name:\"_inline_0_arg1_\",lvalue:false,rvalue:false,count:0},\n      {name:\"_inline_0_arg2_\",lvalue:false,rvalue:true,count:1}\n      ],\n    thisVars:[\"this_i\",\"this_v\"],\n    localVars:[]},\n  body:{\n    body:\"{if(_inline_1_arg1_<this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}\",\n    args:[\n      {name:\"_inline_1_arg0_\",lvalue:false,rvalue:true,count:2},\n      {name:\"_inline_1_arg1_\",lvalue:false,rvalue:true,count:2}],\n    thisVars:[\"this_i\",\"this_v\"],\n    localVars:[\"_inline_1_k\"]},\n  post:{\n    body:\"{return this_i}\",\n    args:[],\n    thisVars:[\"this_i\"],\n    localVars:[]}\n})\n\nexports.argmax = compile({\n  args:[\"index\",\"array\",\"shape\"],\n  pre:{\n    body:\"{this_v=-Infinity;this_i=_inline_0_arg2_.slice(0)}\",\n    args:[\n      {name:\"_inline_0_arg0_\",lvalue:false,rvalue:false,count:0},\n      {name:\"_inline_0_arg1_\",lvalue:false,rvalue:false,count:0},\n      {name:\"_inline_0_arg2_\",lvalue:false,rvalue:true,count:1}\n      ],\n    thisVars:[\"this_i\",\"this_v\"],\n    localVars:[]},\n  body:{\n    body:\"{if(_inline_1_arg1_>this_v){this_v=_inline_1_arg1_;for(var _inline_1_k=0;_inline_1_k<_inline_1_arg0_.length;++_inline_1_k){this_i[_inline_1_k]=_inline_1_arg0_[_inline_1_k]}}}\",\n    args:[\n      {name:\"_inline_1_arg0_\",lvalue:false,rvalue:true,count:2},\n      {name:\"_inline_1_arg1_\",lvalue:false,rvalue:true,count:2}],\n    thisVars:[\"this_i\",\"this_v\"],\n    localVars:[\"_inline_1_k\"]},\n  post:{\n    body:\"{return this_i}\",\n    args:[],\n    thisVars:[\"this_i\"],\n    localVars:[]}\n})  \n\nexports.random = makeOp({\n  args: [\"array\"],\n  pre: {args:[], body:\"this_f=Math.random\", thisVars:[\"this_f\"]},\n  body: {args: [\"a\"], body:\"a=this_f()\", thisVars:[\"this_f\"]},\n  funcName: \"random\"\n})\n\nexports.assign = makeOp({\n  args:[\"array\", \"array\"],\n  body: {args:[\"a\", \"b\"], body:\"a=b\"},\n  funcName: \"assign\" })\n\nexports.assigns = makeOp({\n  args:[\"array\", \"scalar\"],\n  body: {args:[\"a\", \"b\"], body:\"a=b\"},\n  funcName: \"assigns\" })\n\n\nexports.equals = compile({\n  args:[\"array\", \"array\"],\n  pre: EmptyProc,\n  body: {args:[{name:\"x\", lvalue:false, rvalue:true, count:1},\n               {name:\"y\", lvalue:false, rvalue:true, count:1}], \n        body: \"if(x!==y){return false}\", \n        localVars: [], \n        thisVars: []},\n  post: {args:[], localVars:[], thisVars:[], body:\"return true\"},\n  funcName: \"equals\"\n})\n\n\n\n},{\"cwise-compiler\":146}],445:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar ndarray = _dereq_(\"ndarray\")\nvar do_convert = _dereq_(\"./doConvert.js\")\n\nmodule.exports = function convert(arr, result) {\n  var shape = [], c = arr, sz = 1\n  while(Array.isArray(c)) {\n    shape.push(c.length)\n    sz *= c.length\n    c = c[0]\n  }\n  if(shape.length === 0) {\n    return ndarray()\n  }\n  if(!result) {\n    result = ndarray(new Float64Array(sz), shape)\n  }\n  do_convert(result, arr)\n  return result\n}\n\n},{\"./doConvert.js\":446,\"ndarray\":450}],446:[function(_dereq_,module,exports){\nmodule.exports=_dereq_('cwise-compiler')({\"args\":[\"array\",\"scalar\",\"index\"],\"pre\":{\"body\":\"{}\",\"args\":[],\"thisVars\":[],\"localVars\":[]},\"body\":{\"body\":\"{\\nvar _inline_1_v=_inline_1_arg1_,_inline_1_i\\nfor(_inline_1_i=0;_inline_1_i<_inline_1_arg2_.length-1;++_inline_1_i) {\\n_inline_1_v=_inline_1_v[_inline_1_arg2_[_inline_1_i]]\\n}\\n_inline_1_arg0_=_inline_1_v[_inline_1_arg2_[_inline_1_arg2_.length-1]]\\n}\",\"args\":[{\"name\":\"_inline_1_arg0_\",\"lvalue\":true,\"rvalue\":false,\"count\":1},{\"name\":\"_inline_1_arg1_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_1_arg2_\",\"lvalue\":false,\"rvalue\":true,\"count\":4}],\"thisVars\":[],\"localVars\":[\"_inline_1_i\",\"_inline_1_v\"]},\"post\":{\"body\":\"{}\",\"args\":[],\"thisVars\":[],\"localVars\":[]},\"funcName\":\"convert\",\"blockSize\":64})\n\n},{\"cwise-compiler\":146}],447:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar pool = _dereq_(\"typedarray-pool\")\n\nvar INSERTION_SORT_THRESHOLD = 32\n\nfunction getMallocFree(dtype) {\n  switch(dtype) {\n    case \"uint8\":\n      return [pool.mallocUint8, pool.freeUint8]\n    case \"uint16\":\n      return [pool.mallocUint16, pool.freeUint16]\n    case \"uint32\":\n      return [pool.mallocUint32, pool.freeUint32]\n    case \"int8\":\n      return [pool.mallocInt8, pool.freeInt8]\n    case \"int16\":\n      return [pool.mallocInt16, pool.freeInt16]\n    case \"int32\":\n      return [pool.mallocInt32, pool.freeInt32]\n    case \"float32\":\n      return [pool.mallocFloat, pool.freeFloat]\n    case \"float64\":\n      return [pool.mallocDouble, pool.freeDouble]\n    default:\n      return null\n  }\n}\n\nfunction shapeArgs(dimension) {\n  var args = []\n  for(var i=0; i<dimension; ++i) {\n    args.push(\"s\"+i)\n  }\n  for(var i=0; i<dimension; ++i) {\n    args.push(\"n\"+i)\n  }\n  for(var i=1; i<dimension; ++i) {\n    args.push(\"d\"+i)\n  }\n  for(var i=1; i<dimension; ++i) {\n    args.push(\"e\"+i)\n  }\n  for(var i=1; i<dimension; ++i) {\n    args.push(\"f\"+i)\n  }\n  return args\n}\n\nfunction createInsertionSort(order, dtype) {\n\n  var code = [\"'use strict'\"]\n  var funcName = [\"ndarrayInsertionSort\", order.join(\"d\"), dtype].join(\"\")\n  var funcArgs = [\"left\", \"right\", \"data\", \"offset\" ].concat(shapeArgs(order.length))\n  var allocator = getMallocFree(dtype)\n  \n  var vars = [ \"i,j,cptr,ptr=left*s0+offset\" ]\n  \n  if(order.length > 1) {\n    var scratch_shape = []\n    for(var i=1; i<order.length; ++i) {\n      vars.push(\"i\"+i)\n      scratch_shape.push(\"n\"+i)\n    }\n    if(allocator) {\n      vars.push(\"scratch=malloc(\" + scratch_shape.join(\"*\") + \")\")\n    } else {\n      vars.push(\"scratch=new Array(\"+scratch_shape.join(\"*\") + \")\")\n    }\n    vars.push(\"dptr\",\"sptr\",\"a\",\"b\")\n  } else {\n    vars.push(\"scratch\")\n  }\n  \n  function dataRead(ptr) {\n    if(dtype === \"generic\") {\n      return [\"data.get(\", ptr, \")\"].join(\"\")\n    }\n    return [\"data[\",ptr,\"]\"].join(\"\")\n  }\n  \n  function dataWrite(ptr, v) {\n    if(dtype === \"generic\") {\n      return [\"data.set(\", ptr, \",\", v, \")\"].join(\"\")\n    }\n    return [\"data[\",ptr,\"]=\",v].join(\"\")\n  }\n  \n  //Create function header\n  code.push(\n    [\"function \", funcName, \"(\", funcArgs.join(\",\"), \"){var \", vars.join(\",\")].join(\"\"),\n      \"for(i=left+1;i<=right;++i){\",\n        \"j=i;ptr+=s0\",\n        \"cptr=ptr\")\n  \n  \n  if(order.length > 1) {\n  \n    //Copy data into scratch\n    code.push(\"dptr=0;sptr=ptr\")\n    for(var i=order.length-1; i>=0; --i) {\n      var j = order[i]\n      if(j === 0) {\n        continue\n      }\n      code.push([\"for(i\",j,\"=0;i\",j,\"<n\",j,\";++i\",j,\"){\"].join(\"\"))\n    }\n    code.push(\"scratch[dptr++]=\",dataRead(\"sptr\"))\n    for(var i=0; i<order.length; ++i) {\n      var j = order[i]\n      if(j === 0) {\n        continue\n      }\n      code.push(\"sptr+=d\"+j,\"}\")\n    }\n\n    \n    //Compare items in outer loop\n    code.push(\"__g:while(j-->left){\",\n              \"dptr=0\",\n              \"sptr=cptr-s0\")\n    for(var i=1; i<order.length; ++i) {\n      if(i === 1) {\n        code.push(\"__l:\")\n      }\n      code.push([\"for(i\",i,\"=0;i\",i,\"<n\",i,\";++i\",i,\"){\"].join(\"\"))\n    }\n    code.push([\"a=\", dataRead(\"sptr\"),\"\\nb=scratch[dptr]\\nif(a<b){break __g}\\nif(a>b){break __l}\"].join(\"\"))\n    for(var i=order.length-1; i>=1; --i) {\n      code.push(\n        \"sptr+=e\"+i,\n        \"dptr+=f\"+i,\n        \"}\")\n    }\n    \n    //Copy data back\n    code.push(\"dptr=cptr;sptr=cptr-s0\")\n    for(var i=order.length-1; i>=0; --i) {\n      var j = order[i]\n      if(j === 0) {\n        continue\n      }\n      code.push([\"for(i\",j,\"=0;i\",j,\"<n\",j,\";++i\",j,\"){\"].join(\"\"))\n    }\n    code.push(dataWrite(\"dptr\", dataRead(\"sptr\")))\n    for(var i=0; i<order.length; ++i) {\n      var j = order[i]\n      if(j === 0) {\n        continue\n      }\n      code.push([\"dptr+=d\",j,\";sptr+=d\",j].join(\"\"),\"}\")\n    }\n    \n    //Close while loop\n    code.push(\"cptr-=s0\\n}\")\n\n    //Copy scratch into cptr\n    code.push(\"dptr=cptr;sptr=0\")\n    for(var i=order.length-1; i>=0; --i) {\n      var j = order[i]\n      if(j === 0) {\n        continue\n      }\n      code.push([\"for(i\",j,\"=0;i\",j,\"<n\",j,\";++i\",j,\"){\"].join(\"\"))\n    }\n    code.push(dataWrite(\"dptr\", \"scratch[sptr++]\"))\n    for(var i=0; i<order.length; ++i) {\n      var j = order[i]\n      if(j === 0) {\n        continue\n      }\n      code.push(\"dptr+=d\"+j,\"}\")\n    }\n  } else {\n    code.push(\"scratch=\" + dataRead(\"ptr\"),\n              \"while((j-->left)&&(\"+dataRead(\"cptr-s0\")+\">scratch)){\",\n                dataWrite(\"cptr\", dataRead(\"cptr-s0\")),\n                \"cptr-=s0\",\n              \"}\",\n              dataWrite(\"cptr\", \"scratch\"))\n  }\n  \n  //Close outer loop body\n  code.push(\"}\")\n  if(order.length > 1 && allocator) {\n    code.push(\"free(scratch)\")\n  }\n  code.push(\"} return \" + funcName)\n  \n  //Compile and link function\n  if(allocator) {\n    var result = new Function(\"malloc\", \"free\", code.join(\"\\n\"))\n    return result(allocator[0], allocator[1])\n  } else {\n    var result = new Function(code.join(\"\\n\"))\n    return result()\n  }\n}\n\nfunction createQuickSort(order, dtype, insertionSort) {\n  var code = [ \"'use strict'\" ]\n  var funcName = [\"ndarrayQuickSort\", order.join(\"d\"), dtype].join(\"\")\n  var funcArgs = [\"left\", \"right\", \"data\", \"offset\" ].concat(shapeArgs(order.length))\n  var allocator = getMallocFree(dtype)\n  var labelCounter=0\n  \n  code.push([\"function \", funcName, \"(\", funcArgs.join(\",\"), \"){\"].join(\"\"))\n  \n  var vars = [\n    \"sixth=((right-left+1)/6)|0\",\n    \"index1=left+sixth\",\n    \"index5=right-sixth\",\n    \"index3=(left+right)>>1\",\n    \"index2=index3-sixth\",\n    \"index4=index3+sixth\",\n    \"el1=index1\",\n    \"el2=index2\",\n    \"el3=index3\",\n    \"el4=index4\",\n    \"el5=index5\",\n    \"less=left+1\",\n    \"great=right-1\",\n    \"pivots_are_equal=true\",\n    \"tmp\",\n    \"tmp0\",\n    \"x\",\n    \"y\",\n    \"z\",\n    \"k\",\n    \"ptr0\",\n    \"ptr1\",\n    \"ptr2\",\n    \"comp_pivot1=0\",\n    \"comp_pivot2=0\",\n    \"comp=0\"\n  ]\n  \n  if(order.length > 1) {\n    var ele_size = []\n    for(var i=1; i<order.length; ++i) {\n      ele_size.push(\"n\"+i)\n      vars.push(\"i\"+i)\n    }\n    for(var i=0; i<8; ++i) {\n      vars.push(\"b_ptr\"+i)\n    }\n    vars.push(\n      \"ptr3\",\n      \"ptr4\",\n      \"ptr5\",\n      \"ptr6\",\n      \"ptr7\",\n      \"pivot_ptr\",\n      \"ptr_shift\",\n      \"elementSize=\"+ele_size.join(\"*\"))\n    if(allocator) {\n      vars.push(\"pivot1=malloc(elementSize)\",\n                \"pivot2=malloc(elementSize)\")\n    } else {\n      vars.push(\"pivot1=new Array(elementSize),pivot2=new Array(elementSize)\")\n    }\n  } else {\n    vars.push(\"pivot1\", \"pivot2\")\n  }\n  \n  //Initialize local variables\n  code.push(\"var \" + vars.join(\",\"))\n  \n  function toPointer(v) {\n    return [\"(offset+\",v,\"*s0)\"].join(\"\")\n  }\n  \n  function dataRead(ptr) {\n    if(dtype === \"generic\") {\n      return [\"data.get(\", ptr, \")\"].join(\"\")\n    }\n    return [\"data[\",ptr,\"]\"].join(\"\")\n  }\n  \n  function dataWrite(ptr, v) {\n    if(dtype === \"generic\") {\n      return [\"data.set(\", ptr, \",\", v, \")\"].join(\"\")\n    }\n    return [\"data[\",ptr,\"]=\",v].join(\"\")\n  }\n  \n  function cacheLoop(ptrs, usePivot, body) {\n    if(ptrs.length === 1) {\n      code.push(\"ptr0=\"+toPointer(ptrs[0]))\n    } else {\n      for(var i=0; i<ptrs.length; ++i) {\n        code.push([\"b_ptr\",i,\"=s0*\",ptrs[i]].join(\"\"))\n      }\n    }\n    if(usePivot) {\n      code.push(\"pivot_ptr=0\")\n    }\n    code.push(\"ptr_shift=offset\")\n    for(var i=order.length-1; i>=0; --i) {\n      var j = order[i]\n      if(j === 0) {\n        continue\n      }\n      code.push([\"for(i\",j,\"=0;i\",j,\"<n\",j,\";++i\",j,\"){\"].join(\"\"))\n    }\n    if(ptrs.length > 1) {\n      for(var i=0; i<ptrs.length; ++i) {\n        code.push([\"ptr\",i,\"=b_ptr\",i,\"+ptr_shift\"].join(\"\"))\n      }\n    }\n    code.push(body)\n    if(usePivot) {\n      code.push(\"++pivot_ptr\")\n    }\n    for(var i=0; i<order.length; ++i) {\n      var j = order[i]\n      if(j === 0) {\n        continue\n      }\n      if(ptrs.length>1) {\n        code.push(\"ptr_shift+=d\"+j)\n      } else {\n        code.push(\"ptr0+=d\"+j)\n      }\n      code.push(\"}\")\n    }\n  }\n  \n  function lexicoLoop(label, ptrs, usePivot, body) {\n    if(ptrs.length === 1) {\n      code.push(\"ptr0=\"+toPointer(ptrs[0]))\n    } else {\n      for(var i=0; i<ptrs.length; ++i) {\n        code.push([\"b_ptr\",i,\"=s0*\",ptrs[i]].join(\"\"))\n      }\n      code.push(\"ptr_shift=offset\")\n    }\n    if(usePivot) {\n      code.push(\"pivot_ptr=0\")\n    }\n    if(label) {\n      code.push(label+\":\")\n    }\n    for(var i=1; i<order.length; ++i) {\n      code.push([\"for(i\",i,\"=0;i\",i,\"<n\",i,\";++i\",i,\"){\"].join(\"\"))\n    }\n    if(ptrs.length > 1) {\n      for(var i=0; i<ptrs.length; ++i) {\n        code.push([\"ptr\",i,\"=b_ptr\",i,\"+ptr_shift\"].join(\"\"))\n      }\n    }\n    code.push(body)\n    for(var i=order.length-1; i>=1; --i) {\n      if(usePivot) {\n        code.push(\"pivot_ptr+=f\"+i)\n      }\n      if(ptrs.length > 1) {\n        code.push(\"ptr_shift+=e\"+i)\n      } else {\n        code.push(\"ptr0+=e\"+i)\n      }\n      code.push(\"}\")\n    }\n  }\n  \n  function cleanUp() {\n    if(order.length > 1 && allocator) {\n      code.push(\"free(pivot1)\", \"free(pivot2)\")\n    }\n  }\n  \n  function compareSwap(a_id, b_id) {\n    var a = \"el\"+a_id\n    var b = \"el\"+b_id\n    if(order.length > 1) {\n      var lbl = \"__l\" + (++labelCounter)\n      lexicoLoop(lbl, [a, b], false, [\n        \"comp=\",dataRead(\"ptr0\"),\"-\",dataRead(\"ptr1\"),\"\\n\",\n        \"if(comp>0){tmp0=\", a, \";\",a,\"=\",b,\";\", b,\"=tmp0;break \", lbl,\"}\\n\",\n        \"if(comp<0){break \", lbl, \"}\"\n      ].join(\"\"))\n    } else {\n      code.push([\"if(\", dataRead(toPointer(a)), \">\", dataRead(toPointer(b)), \"){tmp0=\", a, \";\",a,\"=\",b,\";\", b,\"=tmp0}\"].join(\"\"))\n    }\n  }\n  \n  compareSwap(1, 2)\n  compareSwap(4, 5)\n  compareSwap(1, 3)\n  compareSwap(2, 3)\n  compareSwap(1, 4)\n  compareSwap(3, 4)\n  compareSwap(2, 5)\n  compareSwap(2, 3)\n  compareSwap(4, 5)\n  \n  if(order.length > 1) {\n    cacheLoop([\"el1\", \"el2\", \"el3\", \"el4\", \"el5\", \"index1\", \"index3\", \"index5\"], true, [\n      \"pivot1[pivot_ptr]=\",dataRead(\"ptr1\"),\"\\n\",\n      \"pivot2[pivot_ptr]=\",dataRead(\"ptr3\"),\"\\n\",\n      \"pivots_are_equal=pivots_are_equal&&(pivot1[pivot_ptr]===pivot2[pivot_ptr])\\n\",\n      \"x=\",dataRead(\"ptr0\"),\"\\n\",\n      \"y=\",dataRead(\"ptr2\"),\"\\n\",\n      \"z=\",dataRead(\"ptr4\"),\"\\n\",\n      dataWrite(\"ptr5\", \"x\"),\"\\n\",\n      dataWrite(\"ptr6\", \"y\"),\"\\n\",\n      dataWrite(\"ptr7\", \"z\")\n    ].join(\"\"))\n  } else {\n    code.push([\n      \"pivot1=\", dataRead(toPointer(\"el2\")), \"\\n\",\n      \"pivot2=\", dataRead(toPointer(\"el4\")), \"\\n\",\n      \"pivots_are_equal=pivot1===pivot2\\n\",\n      \"x=\", dataRead(toPointer(\"el1\")), \"\\n\",\n      \"y=\", dataRead(toPointer(\"el3\")), \"\\n\",\n      \"z=\", dataRead(toPointer(\"el5\")), \"\\n\",\n      dataWrite(toPointer(\"index1\"), \"x\"), \"\\n\",\n      dataWrite(toPointer(\"index3\"), \"y\"), \"\\n\",\n      dataWrite(toPointer(\"index5\"), \"z\")\n    ].join(\"\"))\n  }\n  \n\n  function moveElement(dst, src) {\n    if(order.length > 1) {\n      cacheLoop([dst, src], false,\n        dataWrite(\"ptr0\", dataRead(\"ptr1\"))\n      )\n    } else {\n      code.push(dataWrite(toPointer(dst), dataRead(toPointer(src))))\n    }\n  }\n  \n  moveElement(\"index2\", \"left\")\n  moveElement(\"index4\", \"right\")\n  \n  function comparePivot(result, ptr, n) {\n    if(order.length > 1) {\n      var lbl = \"__l\" + (++labelCounter)\n      lexicoLoop(lbl, [ptr], true, [\n        result,\"=\",dataRead(\"ptr0\"),\"-pivot\",n,\"[pivot_ptr]\\n\",\n        \"if(\",result,\"!==0){break \", lbl, \"}\"\n      ].join(\"\"))\n    } else {\n      code.push([result,\"=\", dataRead(toPointer(ptr)), \"-pivot\", n].join(\"\"))\n    }\n  }\n  \n  function swapElements(a, b) {\n    if(order.length > 1) {\n      cacheLoop([a,b],false,[\n        \"tmp=\",dataRead(\"ptr0\"),\"\\n\",\n        dataWrite(\"ptr0\", dataRead(\"ptr1\")),\"\\n\",\n        dataWrite(\"ptr1\", \"tmp\")\n      ].join(\"\"))\n    } else {\n      code.push([\n        \"ptr0=\",toPointer(a),\"\\n\",\n        \"ptr1=\",toPointer(b),\"\\n\",\n        \"tmp=\",dataRead(\"ptr0\"),\"\\n\",\n        dataWrite(\"ptr0\", dataRead(\"ptr1\")),\"\\n\",\n        dataWrite(\"ptr1\", \"tmp\")\n      ].join(\"\"))\n    }\n  }\n  \n  function tripleSwap(k, less, great) {\n    if(order.length > 1) {\n      cacheLoop([k,less,great], false, [\n        \"tmp=\",dataRead(\"ptr0\"),\"\\n\",\n        dataWrite(\"ptr0\", dataRead(\"ptr1\")),\"\\n\",\n        dataWrite(\"ptr1\", dataRead(\"ptr2\")),\"\\n\",\n        dataWrite(\"ptr2\", \"tmp\")\n      ].join(\"\"))\n      code.push(\"++\"+less, \"--\"+great)\n    } else {\n      code.push([\n        \"ptr0=\",toPointer(k),\"\\n\",\n        \"ptr1=\",toPointer(less),\"\\n\",\n        \"ptr2=\",toPointer(great),\"\\n\",\n        \"++\",less,\"\\n\",\n        \"--\",great,\"\\n\",\n        \"tmp=\", dataRead(\"ptr0\"), \"\\n\",\n        dataWrite(\"ptr0\", dataRead(\"ptr1\")), \"\\n\",\n        dataWrite(\"ptr1\", dataRead(\"ptr2\")), \"\\n\",\n        dataWrite(\"ptr2\", \"tmp\")\n      ].join(\"\"))\n    }\n  }\n  \n  function swapAndDecrement(k, great) {\n    swapElements(k, great)\n    code.push(\"--\"+great)\n  }\n    \n  code.push(\"if(pivots_are_equal){\")\n    //Pivots are equal case\n    code.push(\"for(k=less;k<=great;++k){\")\n      comparePivot(\"comp\", \"k\", 1)\n      code.push(\"if(comp===0){continue}\")\n      code.push(\"if(comp<0){\")\n        code.push(\"if(k!==less){\")\n          swapElements(\"k\", \"less\")\n        code.push(\"}\")\n        code.push(\"++less\")\n      code.push(\"}else{\")\n        code.push(\"while(true){\")\n          comparePivot(\"comp\", \"great\", 1)\n          code.push(\"if(comp>0){\")\n            code.push(\"great--\")\n          code.push(\"}else if(comp<0){\")\n            tripleSwap(\"k\", \"less\", \"great\")\n            code.push(\"break\")\n          code.push(\"}else{\")\n            swapAndDecrement(\"k\", \"great\")\n            code.push(\"break\")\n          code.push(\"}\")\n        code.push(\"}\")\n      code.push(\"}\")\n    code.push(\"}\")\n  code.push(\"}else{\")\n    //Pivots not equal case\n    code.push(\"for(k=less;k<=great;++k){\")\n      comparePivot(\"comp_pivot1\", \"k\", 1)\n      code.push(\"if(comp_pivot1<0){\")\n        code.push(\"if(k!==less){\")\n          swapElements(\"k\", \"less\")\n        code.push(\"}\")\n        code.push(\"++less\")\n      code.push(\"}else{\")\n        comparePivot(\"comp_pivot2\", \"k\", 2)\n        code.push(\"if(comp_pivot2>0){\")\n          code.push(\"while(true){\")\n            comparePivot(\"comp\", \"great\", 2)\n            code.push(\"if(comp>0){\")\n              code.push(\"if(--great<k){break}\")\n              code.push(\"continue\")\n            code.push(\"}else{\")\n              comparePivot(\"comp\", \"great\", 1)\n              code.push(\"if(comp<0){\")\n                tripleSwap(\"k\", \"less\", \"great\")\n              code.push(\"}else{\")\n                swapAndDecrement(\"k\", \"great\")\n              code.push(\"}\")\n              code.push(\"break\")\n            code.push(\"}\")\n          code.push(\"}\")\n        code.push(\"}\")\n      code.push(\"}\")\n    code.push(\"}\")\n  code.push(\"}\")\n  \n  //Move pivots to correct place\n  function storePivot(mem_dest, pivot_dest, pivot) {\n    if(order.length>1) {\n      cacheLoop([mem_dest, pivot_dest], true, [\n        dataWrite(\"ptr0\", dataRead(\"ptr1\")), \"\\n\",\n        dataWrite(\"ptr1\", [\"pivot\",pivot,\"[pivot_ptr]\"].join(\"\"))\n      ].join(\"\"))\n    } else {\n      code.push(\n          dataWrite(toPointer(mem_dest), dataRead(toPointer(pivot_dest))),\n          dataWrite(toPointer(pivot_dest), \"pivot\"+pivot))\n    }\n  }\n  \n  storePivot(\"left\", \"(less-1)\", 1)\n  storePivot(\"right\", \"(great+1)\", 2)\n\n  //Recursive sort call\n  function doSort(left, right) {\n    code.push([\n      \"if((\",right,\"-\",left,\")<=\",INSERTION_SORT_THRESHOLD,\"){\\n\",\n        \"insertionSort(\", left, \",\", right, \",data,offset,\", shapeArgs(order.length).join(\",\"), \")\\n\",\n      \"}else{\\n\",\n        funcName, \"(\", left, \",\", right, \",data,offset,\", shapeArgs(order.length).join(\",\"), \")\\n\",\n      \"}\"\n    ].join(\"\"))\n  }\n  doSort(\"left\", \"(less-2)\")\n  doSort(\"(great+2)\", \"right\")\n  \n  //If pivots are equal, then early out\n  code.push(\"if(pivots_are_equal){\")\n    cleanUp()\n    code.push(\"return\")\n  code.push(\"}\")\n  \n  function walkPointer(ptr, pivot, body) {\n    if(order.length > 1) {\n      code.push([\"__l\",++labelCounter,\":while(true){\"].join(\"\"))\n      cacheLoop([ptr], true, [\n        \"if(\", dataRead(\"ptr0\"), \"!==pivot\", pivot, \"[pivot_ptr]){break __l\", labelCounter, \"}\"\n      ].join(\"\"))\n      code.push(body, \"}\")\n    } else {\n      code.push([\"while(\", dataRead(toPointer(ptr)), \"===pivot\", pivot, \"){\", body, \"}\"].join(\"\"))\n    }\n  }\n  \n  //Check bounds\n  code.push(\"if(less<index1&&great>index5){\")\n  \n    walkPointer(\"less\", 1, \"++less\")\n    walkPointer(\"great\", 2, \"--great\")\n  \n    code.push(\"for(k=less;k<=great;++k){\")\n      comparePivot(\"comp_pivot1\", \"k\", 1)\n      code.push(\"if(comp_pivot1===0){\")\n        code.push(\"if(k!==less){\")\n          swapElements(\"k\", \"less\")\n        code.push(\"}\")\n        code.push(\"++less\")\n      code.push(\"}else{\")\n        comparePivot(\"comp_pivot2\", \"k\", 2)\n        code.push(\"if(comp_pivot2===0){\")\n          code.push(\"while(true){\")\n            comparePivot(\"comp\", \"great\", 2)\n            code.push(\"if(comp===0){\")\n              code.push(\"if(--great<k){break}\")\n              code.push(\"continue\")\n            code.push(\"}else{\")\n              comparePivot(\"comp\", \"great\", 1)\n              code.push(\"if(comp<0){\")\n                tripleSwap(\"k\", \"less\", \"great\")\n              code.push(\"}else{\")\n                swapAndDecrement(\"k\", \"great\")\n              code.push(\"}\")\n              code.push(\"break\")\n            code.push(\"}\")\n          code.push(\"}\")\n        code.push(\"}\")\n      code.push(\"}\")\n    code.push(\"}\")\n  code.push(\"}\")\n  \n  //Clean up and do a final sorting pass\n  cleanUp()\n  doSort(\"less\", \"great\")\n \n  //Close off main loop\n  code.push(\"}return \" + funcName)\n  \n  //Compile and link\n  if(order.length > 1 && allocator) {\n    var compiled = new Function(\"insertionSort\", \"malloc\", \"free\", code.join(\"\\n\"))\n    return compiled(insertionSort, allocator[0], allocator[1])\n  }\n  var compiled = new Function(\"insertionSort\", code.join(\"\\n\"))\n  return compiled(insertionSort)\n}\n\nfunction compileSort(order, dtype) {\n  var code = [\"'use strict'\"]\n  var funcName = [\"ndarraySortWrapper\", order.join(\"d\"), dtype].join(\"\")\n  var funcArgs = [ \"array\" ]\n  \n  code.push([\"function \", funcName, \"(\", funcArgs.join(\",\"), \"){\"].join(\"\"))\n  \n  //Unpack local variables from array\n  var vars = [\"data=array.data,offset=array.offset|0,shape=array.shape,stride=array.stride\"]\n  for(var i=0; i<order.length; ++i) {\n    vars.push([\"s\",i,\"=stride[\",i,\"]|0,n\",i,\"=shape[\",i,\"]|0\"].join(\"\"))\n  }\n  \n  var scratch_stride = new Array(order.length)\n  var nprod = []\n  for(var i=0; i<order.length; ++i) {\n    var k = order[i]\n    if(k === 0) {\n      continue\n    }\n    if(nprod.length === 0) {\n      scratch_stride[k] = \"1\"\n    } else {\n      scratch_stride[k] = nprod.join(\"*\")\n    }\n    nprod.push(\"n\"+k)\n  }\n  \n  var p = -1, q = -1\n  for(var i=0; i<order.length; ++i) {\n    var j = order[i]\n    if(j !== 0) {\n      if(p > 0) {\n        vars.push([\"d\",j,\"=s\",j,\"-d\",p,\"*n\",p].join(\"\"))\n      } else {\n        vars.push([\"d\",j,\"=s\",j].join(\"\"))\n      }\n      p = j\n    }\n    var k = order.length-1-i\n    if(k !== 0) {\n      if(q > 0) {\n        vars.push([\"e\",k,\"=s\",k,\"-e\",q,\"*n\",q,\n                  \",f\",k,\"=\",scratch_stride[k],\"-f\",q,\"*n\",q].join(\"\"))\n      } else {\n        vars.push([\"e\",k,\"=s\",k,\",f\",k,\"=\",scratch_stride[k]].join(\"\"))\n      }\n      q = k\n    }\n  }\n  \n  //Declare local variables\n  code.push(\"var \" + vars.join(\",\"))\n  \n  //Create arguments for subroutine\n  var sortArgs = [\"0\", \"n0-1\", \"data\", \"offset\"].concat(shapeArgs(order.length))\n  \n  //Call main sorting routine\n  code.push([\n    \"if(n0<=\",INSERTION_SORT_THRESHOLD,\"){\",\n      \"insertionSort(\", sortArgs.join(\",\"), \")}else{\",\n      \"quickSort(\", sortArgs.join(\",\"),\n    \")}\"\n  ].join(\"\"))\n  \n  //Return\n  code.push(\"}return \" + funcName)\n  \n  //Link everything together\n  var result = new Function(\"insertionSort\", \"quickSort\", code.join(\"\\n\"))\n  var insertionSort = createInsertionSort(order, dtype)\n  var quickSort = createQuickSort(order, dtype, insertionSort)\n  return result(insertionSort, quickSort)\n}\n\nmodule.exports = compileSort\n},{\"typedarray-pool\":545}],448:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar compile = _dereq_(\"./lib/compile_sort.js\")\nvar CACHE = {}\n\nfunction sort(array) {\n  var order = array.order\n  var dtype = array.dtype\n  var typeSig = [order, dtype ]\n  var typeName = typeSig.join(\":\")\n  var compiled = CACHE[typeName]\n  if(!compiled) {\n    CACHE[typeName] = compiled = compile(order, dtype)\n  }\n  compiled(array)\n  return array\n}\n\nmodule.exports = sort\n},{\"./lib/compile_sort.js\":447}],449:[function(_dereq_,module,exports){\n'use strict'\n\nvar interp  = _dereq_('ndarray-linear-interpolate')\n\n\nvar do_warp = _dereq_('cwise/lib/wrapper')({\"args\":[\"index\",\"array\",\"scalar\",\"scalar\",\"scalar\"],\"pre\":{\"body\":\"{this_warped=new Array(_inline_3_arg4_)}\",\"args\":[{\"name\":\"_inline_3_arg0_\",\"lvalue\":false,\"rvalue\":false,\"count\":0},{\"name\":\"_inline_3_arg1_\",\"lvalue\":false,\"rvalue\":false,\"count\":0},{\"name\":\"_inline_3_arg2_\",\"lvalue\":false,\"rvalue\":false,\"count\":0},{\"name\":\"_inline_3_arg3_\",\"lvalue\":false,\"rvalue\":false,\"count\":0},{\"name\":\"_inline_3_arg4_\",\"lvalue\":false,\"rvalue\":true,\"count\":1}],\"thisVars\":[\"this_warped\"],\"localVars\":[]},\"body\":{\"body\":\"{_inline_4_arg2_(this_warped,_inline_4_arg0_),_inline_4_arg1_=_inline_4_arg3_.apply(void 0,this_warped)}\",\"args\":[{\"name\":\"_inline_4_arg0_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_4_arg1_\",\"lvalue\":true,\"rvalue\":false,\"count\":1},{\"name\":\"_inline_4_arg2_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_4_arg3_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_4_arg4_\",\"lvalue\":false,\"rvalue\":false,\"count\":0}],\"thisVars\":[\"this_warped\"],\"localVars\":[]},\"post\":{\"body\":\"{}\",\"args\":[],\"thisVars\":[],\"localVars\":[]},\"debug\":false,\"funcName\":\"warpND\",\"blockSize\":64})\n\nvar do_warp_1 = _dereq_('cwise/lib/wrapper')({\"args\":[\"index\",\"array\",\"scalar\",\"scalar\",\"scalar\"],\"pre\":{\"body\":\"{this_warped=[0]}\",\"args\":[],\"thisVars\":[\"this_warped\"],\"localVars\":[]},\"body\":{\"body\":\"{_inline_7_arg2_(this_warped,_inline_7_arg0_),_inline_7_arg1_=_inline_7_arg3_(_inline_7_arg4_,this_warped[0])}\",\"args\":[{\"name\":\"_inline_7_arg0_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_7_arg1_\",\"lvalue\":true,\"rvalue\":false,\"count\":1},{\"name\":\"_inline_7_arg2_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_7_arg3_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_7_arg4_\",\"lvalue\":false,\"rvalue\":true,\"count\":1}],\"thisVars\":[\"this_warped\"],\"localVars\":[]},\"post\":{\"body\":\"{}\",\"args\":[],\"thisVars\":[],\"localVars\":[]},\"debug\":false,\"funcName\":\"warp1D\",\"blockSize\":64})\n\nvar do_warp_2 = _dereq_('cwise/lib/wrapper')({\"args\":[\"index\",\"array\",\"scalar\",\"scalar\",\"scalar\"],\"pre\":{\"body\":\"{this_warped=[0,0]}\",\"args\":[],\"thisVars\":[\"this_warped\"],\"localVars\":[]},\"body\":{\"body\":\"{_inline_10_arg2_(this_warped,_inline_10_arg0_),_inline_10_arg1_=_inline_10_arg3_(_inline_10_arg4_,this_warped[0],this_warped[1])}\",\"args\":[{\"name\":\"_inline_10_arg0_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_10_arg1_\",\"lvalue\":true,\"rvalue\":false,\"count\":1},{\"name\":\"_inline_10_arg2_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_10_arg3_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_10_arg4_\",\"lvalue\":false,\"rvalue\":true,\"count\":1}],\"thisVars\":[\"this_warped\"],\"localVars\":[]},\"post\":{\"body\":\"{}\",\"args\":[],\"thisVars\":[],\"localVars\":[]},\"debug\":false,\"funcName\":\"warp2D\",\"blockSize\":64})\n\nvar do_warp_3 = _dereq_('cwise/lib/wrapper')({\"args\":[\"index\",\"array\",\"scalar\",\"scalar\",\"scalar\"],\"pre\":{\"body\":\"{this_warped=[0,0,0]}\",\"args\":[],\"thisVars\":[\"this_warped\"],\"localVars\":[]},\"body\":{\"body\":\"{_inline_13_arg2_(this_warped,_inline_13_arg0_),_inline_13_arg1_=_inline_13_arg3_(_inline_13_arg4_,this_warped[0],this_warped[1],this_warped[2])}\",\"args\":[{\"name\":\"_inline_13_arg0_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_13_arg1_\",\"lvalue\":true,\"rvalue\":false,\"count\":1},{\"name\":\"_inline_13_arg2_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_13_arg3_\",\"lvalue\":false,\"rvalue\":true,\"count\":1},{\"name\":\"_inline_13_arg4_\",\"lvalue\":false,\"rvalue\":true,\"count\":1}],\"thisVars\":[\"this_warped\"],\"localVars\":[]},\"post\":{\"body\":\"{}\",\"args\":[],\"thisVars\":[],\"localVars\":[]},\"debug\":false,\"funcName\":\"warp3D\",\"blockSize\":64})\n\nmodule.exports = function warp(dest, src, func) {\n  switch(src.shape.length) {\n    case 1:\n      do_warp_1(dest, func, interp.d1, src)\n      break\n    case 2:\n      do_warp_2(dest, func, interp.d2, src)\n      break\n    case 3:\n      do_warp_3(dest, func, interp.d3, src)\n      break\n    default:\n      do_warp(dest, func, interp.bind(undefined, src), src.shape.length)\n      break\n  }\n  return dest\n}\n\n},{\"cwise/lib/wrapper\":149,\"ndarray-linear-interpolate\":443}],450:[function(_dereq_,module,exports){\nvar iota = _dereq_(\"iota-array\")\nvar isBuffer = _dereq_(\"is-buffer\")\n\nvar hasTypedArrays  = ((typeof Float64Array) !== \"undefined\")\n\nfunction compare1st(a, b) {\n  return a[0] - b[0]\n}\n\nfunction order() {\n  var stride = this.stride\n  var terms = new Array(stride.length)\n  var i\n  for(i=0; i<terms.length; ++i) {\n    terms[i] = [Math.abs(stride[i]), i]\n  }\n  terms.sort(compare1st)\n  var result = new Array(terms.length)\n  for(i=0; i<result.length; ++i) {\n    result[i] = terms[i][1]\n  }\n  return result\n}\n\nfunction compileConstructor(dtype, dimension) {\n  var className = [\"View\", dimension, \"d\", dtype].join(\"\")\n  if(dimension < 0) {\n    className = \"View_Nil\" + dtype\n  }\n  var useGetters = (dtype === \"generic\")\n\n  if(dimension === -1) {\n    //Special case for trivial arrays\n    var code =\n      \"function \"+className+\"(a){this.data=a;};\\\nvar proto=\"+className+\".prototype;\\\nproto.dtype='\"+dtype+\"';\\\nproto.index=function(){return -1};\\\nproto.size=0;\\\nproto.dimension=-1;\\\nproto.shape=proto.stride=proto.order=[];\\\nproto.lo=proto.hi=proto.transpose=proto.step=\\\nfunction(){return new \"+className+\"(this.data);};\\\nproto.get=proto.set=function(){};\\\nproto.pick=function(){return null};\\\nreturn function construct_\"+className+\"(a){return new \"+className+\"(a);}\"\n    var procedure = new Function(code)\n    return procedure()\n  } else if(dimension === 0) {\n    //Special case for 0d arrays\n    var code =\n      \"function \"+className+\"(a,d) {\\\nthis.data = a;\\\nthis.offset = d\\\n};\\\nvar proto=\"+className+\".prototype;\\\nproto.dtype='\"+dtype+\"';\\\nproto.index=function(){return this.offset};\\\nproto.dimension=0;\\\nproto.size=1;\\\nproto.shape=\\\nproto.stride=\\\nproto.order=[];\\\nproto.lo=\\\nproto.hi=\\\nproto.transpose=\\\nproto.step=function \"+className+\"_copy() {\\\nreturn new \"+className+\"(this.data,this.offset)\\\n};\\\nproto.pick=function \"+className+\"_pick(){\\\nreturn TrivialArray(this.data);\\\n};\\\nproto.valueOf=proto.get=function \"+className+\"_get(){\\\nreturn \"+(useGetters ? \"this.data.get(this.offset)\" : \"this.data[this.offset]\")+\n\"};\\\nproto.set=function \"+className+\"_set(v){\\\nreturn \"+(useGetters ? \"this.data.set(this.offset,v)\" : \"this.data[this.offset]=v\")+\"\\\n};\\\nreturn function construct_\"+className+\"(a,b,c,d){return new \"+className+\"(a,d)}\"\n    var procedure = new Function(\"TrivialArray\", code)\n    return procedure(CACHED_CONSTRUCTORS[dtype][0])\n  }\n\n  var code = [\"'use strict'\"]\n\n  //Create constructor for view\n  var indices = iota(dimension)\n  var args = indices.map(function(i) { return \"i\"+i })\n  var index_str = \"this.offset+\" + indices.map(function(i) {\n        return \"this.stride[\" + i + \"]*i\" + i\n      }).join(\"+\")\n  var shapeArg = indices.map(function(i) {\n      return \"b\"+i\n    }).join(\",\")\n  var strideArg = indices.map(function(i) {\n      return \"c\"+i\n    }).join(\",\")\n  code.push(\n    \"function \"+className+\"(a,\" + shapeArg + \",\" + strideArg + \",d){this.data=a\",\n      \"this.shape=[\" + shapeArg + \"]\",\n      \"this.stride=[\" + strideArg + \"]\",\n      \"this.offset=d|0}\",\n    \"var proto=\"+className+\".prototype\",\n    \"proto.dtype='\"+dtype+\"'\",\n    \"proto.dimension=\"+dimension)\n\n  //view.size:\n  code.push(\"Object.defineProperty(proto,'size',{get:function \"+className+\"_size(){\\\nreturn \"+indices.map(function(i) { return \"this.shape[\"+i+\"]\" }).join(\"*\"),\n\"}})\")\n\n  //view.order:\n  if(dimension === 1) {\n    code.push(\"proto.order=[0]\")\n  } else {\n    code.push(\"Object.defineProperty(proto,'order',{get:\")\n    if(dimension < 4) {\n      code.push(\"function \"+className+\"_order(){\")\n      if(dimension === 2) {\n        code.push(\"return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}})\")\n      } else if(dimension === 3) {\n        code.push(\n\"var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);\\\nif(s0>s1){\\\nif(s1>s2){\\\nreturn [2,1,0];\\\n}else if(s0>s2){\\\nreturn [1,2,0];\\\n}else{\\\nreturn [1,0,2];\\\n}\\\n}else if(s0>s2){\\\nreturn [2,0,1];\\\n}else if(s2>s1){\\\nreturn [0,1,2];\\\n}else{\\\nreturn [0,2,1];\\\n}}})\")\n      }\n    } else {\n      code.push(\"ORDER})\")\n    }\n  }\n\n  //view.set(i0, ..., v):\n  code.push(\n\"proto.set=function \"+className+\"_set(\"+args.join(\",\")+\",v){\")\n  if(useGetters) {\n    code.push(\"return this.data.set(\"+index_str+\",v)}\")\n  } else {\n    code.push(\"return this.data[\"+index_str+\"]=v}\")\n  }\n\n  //view.get(i0, ...):\n  code.push(\"proto.get=function \"+className+\"_get(\"+args.join(\",\")+\"){\")\n  if(useGetters) {\n    code.push(\"return this.data.get(\"+index_str+\")}\")\n  } else {\n    code.push(\"return this.data[\"+index_str+\"]}\")\n  }\n\n  //view.index:\n  code.push(\n    \"proto.index=function \"+className+\"_index(\", args.join(), \"){return \"+index_str+\"}\")\n\n  //view.hi():\n  code.push(\"proto.hi=function \"+className+\"_hi(\"+args.join(\",\")+\"){return new \"+className+\"(this.data,\"+\n    indices.map(function(i) {\n      return [\"(typeof i\",i,\"!=='number'||i\",i,\"<0)?this.shape[\", i, \"]:i\", i,\"|0\"].join(\"\")\n    }).join(\",\")+\",\"+\n    indices.map(function(i) {\n      return \"this.stride[\"+i + \"]\"\n    }).join(\",\")+\",this.offset)}\")\n\n  //view.lo():\n  var a_vars = indices.map(function(i) { return \"a\"+i+\"=this.shape[\"+i+\"]\" })\n  var c_vars = indices.map(function(i) { return \"c\"+i+\"=this.stride[\"+i+\"]\" })\n  code.push(\"proto.lo=function \"+className+\"_lo(\"+args.join(\",\")+\"){var b=this.offset,d=0,\"+a_vars.join(\",\")+\",\"+c_vars.join(\",\"))\n  for(var i=0; i<dimension; ++i) {\n    code.push(\n\"if(typeof i\"+i+\"==='number'&&i\"+i+\">=0){\\\nd=i\"+i+\"|0;\\\nb+=c\"+i+\"*d;\\\na\"+i+\"-=d}\")\n  }\n  code.push(\"return new \"+className+\"(this.data,\"+\n    indices.map(function(i) {\n      return \"a\"+i\n    }).join(\",\")+\",\"+\n    indices.map(function(i) {\n      return \"c\"+i\n    }).join(\",\")+\",b)}\")\n\n  //view.step():\n  code.push(\"proto.step=function \"+className+\"_step(\"+args.join(\",\")+\"){var \"+\n    indices.map(function(i) {\n      return \"a\"+i+\"=this.shape[\"+i+\"]\"\n    }).join(\",\")+\",\"+\n    indices.map(function(i) {\n      return \"b\"+i+\"=this.stride[\"+i+\"]\"\n    }).join(\",\")+\",c=this.offset,d=0,ceil=Math.ceil\")\n  for(var i=0; i<dimension; ++i) {\n    code.push(\n\"if(typeof i\"+i+\"==='number'){\\\nd=i\"+i+\"|0;\\\nif(d<0){\\\nc+=b\"+i+\"*(a\"+i+\"-1);\\\na\"+i+\"=ceil(-a\"+i+\"/d)\\\n}else{\\\na\"+i+\"=ceil(a\"+i+\"/d)\\\n}\\\nb\"+i+\"*=d\\\n}\")\n  }\n  code.push(\"return new \"+className+\"(this.data,\"+\n    indices.map(function(i) {\n      return \"a\" + i\n    }).join(\",\")+\",\"+\n    indices.map(function(i) {\n      return \"b\" + i\n    }).join(\",\")+\",c)}\")\n\n  //view.transpose():\n  var tShape = new Array(dimension)\n  var tStride = new Array(dimension)\n  for(var i=0; i<dimension; ++i) {\n    tShape[i] = \"a[i\"+i+\"]\"\n    tStride[i] = \"b[i\"+i+\"]\"\n  }\n  code.push(\"proto.transpose=function \"+className+\"_transpose(\"+args+\"){\"+\n    args.map(function(n,idx) { return n + \"=(\" + n + \"===undefined?\" + idx + \":\" + n + \"|0)\"}).join(\";\"),\n    \"var a=this.shape,b=this.stride;return new \"+className+\"(this.data,\"+tShape.join(\",\")+\",\"+tStride.join(\",\")+\",this.offset)}\")\n\n  //view.pick():\n  code.push(\"proto.pick=function \"+className+\"_pick(\"+args+\"){var a=[],b=[],c=this.offset\")\n  for(var i=0; i<dimension; ++i) {\n    code.push(\"if(typeof i\"+i+\"==='number'&&i\"+i+\">=0){c=(c+this.stride[\"+i+\"]*i\"+i+\")|0}else{a.push(this.shape[\"+i+\"]);b.push(this.stride[\"+i+\"])}\")\n  }\n  code.push(\"var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}\")\n\n  //Add return statement\n  code.push(\"return function construct_\"+className+\"(data,shape,stride,offset){return new \"+className+\"(data,\"+\n    indices.map(function(i) {\n      return \"shape[\"+i+\"]\"\n    }).join(\",\")+\",\"+\n    indices.map(function(i) {\n      return \"stride[\"+i+\"]\"\n    }).join(\",\")+\",offset)}\")\n\n  //Compile procedure\n  var procedure = new Function(\"CTOR_LIST\", \"ORDER\", code.join(\"\\n\"))\n  return procedure(CACHED_CONSTRUCTORS[dtype], order)\n}\n\nfunction arrayDType(data) {\n  if(isBuffer(data)) {\n    return \"buffer\"\n  }\n  if(hasTypedArrays) {\n    switch(Object.prototype.toString.call(data)) {\n      case \"[object Float64Array]\":\n        return \"float64\"\n      case \"[object Float32Array]\":\n        return \"float32\"\n      case \"[object Int8Array]\":\n        return \"int8\"\n      case \"[object Int16Array]\":\n        return \"int16\"\n      case \"[object Int32Array]\":\n        return \"int32\"\n      case \"[object Uint8Array]\":\n        return \"uint8\"\n      case \"[object Uint16Array]\":\n        return \"uint16\"\n      case \"[object Uint32Array]\":\n        return \"uint32\"\n      case \"[object Uint8ClampedArray]\":\n        return \"uint8_clamped\"\n    }\n  }\n  if(Array.isArray(data)) {\n    return \"array\"\n  }\n  return \"generic\"\n}\n\nvar CACHED_CONSTRUCTORS = {\n  \"float32\":[],\n  \"float64\":[],\n  \"int8\":[],\n  \"int16\":[],\n  \"int32\":[],\n  \"uint8\":[],\n  \"uint16\":[],\n  \"uint32\":[],\n  \"array\":[],\n  \"uint8_clamped\":[],\n  \"buffer\":[],\n  \"generic\":[]\n}\n\n;(function() {\n  for(var id in CACHED_CONSTRUCTORS) {\n    CACHED_CONSTRUCTORS[id].push(compileConstructor(id, -1))\n  }\n});\n\nfunction wrappedNDArrayCtor(data, shape, stride, offset) {\n  if(data === undefined) {\n    var ctor = CACHED_CONSTRUCTORS.array[0]\n    return ctor([])\n  } else if(typeof data === \"number\") {\n    data = [data]\n  }\n  if(shape === undefined) {\n    shape = [ data.length ]\n  }\n  var d = shape.length\n  if(stride === undefined) {\n    stride = new Array(d)\n    for(var i=d-1, sz=1; i>=0; --i) {\n      stride[i] = sz\n      sz *= shape[i]\n    }\n  }\n  if(offset === undefined) {\n    offset = 0\n    for(var i=0; i<d; ++i) {\n      if(stride[i] < 0) {\n        offset -= (shape[i]-1)*stride[i]\n      }\n    }\n  }\n  var dtype = arrayDType(data)\n  var ctor_list = CACHED_CONSTRUCTORS[dtype]\n  while(ctor_list.length <= d+1) {\n    ctor_list.push(compileConstructor(dtype, ctor_list.length-1))\n  }\n  var ctor = ctor_list[d+1]\n  return ctor(data, shape, stride, offset)\n}\n\nmodule.exports = wrappedNDArrayCtor\n\n},{\"iota-array\":416,\"is-buffer\":418}],451:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar doubleBits = _dereq_(\"double-bits\")\n\nvar SMALLEST_DENORM = Math.pow(2, -1074)\nvar UINT_MAX = (-1)>>>0\n\nmodule.exports = nextafter\n\nfunction nextafter(x, y) {\n  if(isNaN(x) || isNaN(y)) {\n    return NaN\n  }\n  if(x === y) {\n    return x\n  }\n  if(x === 0) {\n    if(y < 0) {\n      return -SMALLEST_DENORM\n    } else {\n      return SMALLEST_DENORM\n    }\n  }\n  var hi = doubleBits.hi(x)\n  var lo = doubleBits.lo(x)\n  if((y > x) === (x > 0)) {\n    if(lo === UINT_MAX) {\n      hi += 1\n      lo = 0\n    } else {\n      lo += 1\n    }\n  } else {\n    if(lo === 0) {\n      lo = UINT_MAX\n      hi -= 1\n    } else {\n      lo -= 1\n    }\n  }\n  return doubleBits.pack(lo, hi)\n}\n},{\"double-bits\":167}],452:[function(_dereq_,module,exports){\n\nvar π = Math.PI\nvar _120 = radians(120)\n\nmodule.exports = normalize\n\n/**\n * describe `path` in terms of cubic bézier \n * curves and move commands\n *\n * @param {Array} path\n * @return {Array}\n */\n\nfunction normalize(path){\n\t// init state\n\tvar prev\n\tvar result = []\n\tvar bezierX = 0\n\tvar bezierY = 0\n\tvar startX = 0\n\tvar startY = 0\n\tvar quadX = null\n\tvar quadY = null\n\tvar x = 0\n\tvar y = 0\n\n\tfor (var i = 0, len = path.length; i < len; i++) {\n\t\tvar seg = path[i]\n\t\tvar command = seg[0]\n\t\tswitch (command) {\n\t\t\tcase 'M':\n\t\t\t\tstartX = seg[1]\n\t\t\t\tstartY = seg[2]\n\t\t\t\tbreak\n\t\t\tcase 'A':\n\t\t\t\tseg = arc(x, y,seg[1],seg[2],radians(seg[3]),seg[4],seg[5],seg[6],seg[7])\n\t\t\t\t// split multi part\n\t\t\t\tseg.unshift('C')\n\t\t\t\tif (seg.length > 7) {\n\t\t\t\t\tresult.push(seg.splice(0, 7))\n\t\t\t\t\tseg.unshift('C')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase 'S':\n\t\t\t\t// default control point\n\t\t\t\tvar cx = x\n\t\t\t\tvar cy = y\n\t\t\t\tif (prev == 'C' || prev == 'S') {\n\t\t\t\t\tcx += cx - bezierX // reflect the previous command's control\n\t\t\t\t\tcy += cy - bezierY // point relative to the current point\n\t\t\t\t}\n\t\t\t\tseg = ['C', cx, cy, seg[1], seg[2], seg[3], seg[4]]\n\t\t\t\tbreak\n\t\t\tcase 'T':\n\t\t\t\tif (prev == 'Q' || prev == 'T') {\n\t\t\t\t\tquadX = x * 2 - quadX // as with 'S' reflect previous control point\n\t\t\t\t\tquadY = y * 2 - quadY\n\t\t\t\t} else {\n\t\t\t\t\tquadX = x\n\t\t\t\t\tquadY = y\n\t\t\t\t}\n\t\t\t\tseg = quadratic(x, y, quadX, quadY, seg[1], seg[2])\n\t\t\t\tbreak\n\t\t\tcase 'Q':\n\t\t\t\tquadX = seg[1]\n\t\t\t\tquadY = seg[2]\n\t\t\t\tseg = quadratic(x, y, seg[1], seg[2], seg[3], seg[4])\n\t\t\t\tbreak\n\t\t\tcase 'L':\n\t\t\t\tseg = line(x, y, seg[1], seg[2])\n\t\t\t\tbreak\n\t\t\tcase 'H':\n\t\t\t\tseg = line(x, y, seg[1], y)\n\t\t\t\tbreak\n\t\t\tcase 'V':\n\t\t\t\tseg = line(x, y, x, seg[1])\n\t\t\t\tbreak\n\t\t\tcase 'Z':\n\t\t\t\tseg = line(x, y, startX, startY)\n\t\t\t\tbreak\n\t\t}\n\n\t\t// update state\n\t\tprev = command\n\t\tx = seg[seg.length - 2]\n\t\ty = seg[seg.length - 1]\n\t\tif (seg.length > 4) {\n\t\t\tbezierX = seg[seg.length - 4]\n\t\t\tbezierY = seg[seg.length - 3]\n\t\t} else {\n\t\t\tbezierX = x\n\t\t\tbezierY = y\n\t\t}\n\t\tresult.push(seg)\n\t}\n\n\treturn result\n}\n\nfunction line(x1, y1, x2, y2){\n\treturn ['C', x1, y1, x2, y2, x2, y2]\n}\n\nfunction quadratic(x1, y1, cx, cy, x2, y2){\n\treturn [\n\t\t'C',\n\t\tx1/3 + (2/3) * cx,\n\t\ty1/3 + (2/3) * cy,\n\t\tx2/3 + (2/3) * cx,\n\t\ty2/3 + (2/3) * cy,\n\t\tx2,\n\t\ty2\n\t]\n}\n\n// This function is ripped from \n// github.com/DmitryBaranovskiy/raphael/blob/4d97d4/raphael.js#L2216-L2304 \n// which references w3.org/TR/SVG11/implnote.html#ArcImplementationNotes\n// TODO: make it human readable\n\nfunction arc(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {\n\tif (!recursive) {\n\t\tvar xy = rotate(x1, y1, -angle)\n\t\tx1 = xy.x\n\t\ty1 = xy.y\n\t\txy = rotate(x2, y2, -angle)\n\t\tx2 = xy.x\n\t\ty2 = xy.y\n\t\tvar x = (x1 - x2) / 2\n\t\tvar y = (y1 - y2) / 2\n\t\tvar h = (x * x) / (rx * rx) + (y * y) / (ry * ry)\n\t\tif (h > 1) {\n\t\t\th = Math.sqrt(h)\n\t\t\trx = h * rx\n\t\t\try = h * ry\n\t\t}\n\t\tvar rx2 = rx * rx\n\t\tvar ry2 = ry * ry\n\t\tvar k = (large_arc_flag == sweep_flag ? -1 : 1)\n\t\t\t* Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)))\n\t\tif (k == Infinity) k = 1 // neutralize\n\t\tvar cx = k * rx * y / ry + (x1 + x2) / 2\n\t\tvar cy = k * -ry * x / rx + (y1 + y2) / 2\n\t\tvar f1 = Math.asin(((y1 - cy) / ry).toFixed(9))\n\t\tvar f2 = Math.asin(((y2 - cy) / ry).toFixed(9))\n\n\t\tf1 = x1 < cx ? π - f1 : f1\n\t\tf2 = x2 < cx ? π - f2 : f2\n\t\tif (f1 < 0) f1 = π * 2 + f1\n\t\tif (f2 < 0) f2 = π * 2 + f2\n\t\tif (sweep_flag && f1 > f2) f1 = f1 - π * 2\n\t\tif (!sweep_flag && f2 > f1) f2 = f2 - π * 2\n\t} else {\n\t\tf1 = recursive[0]\n\t\tf2 = recursive[1]\n\t\tcx = recursive[2]\n\t\tcy = recursive[3]\n\t}\n\t// greater than 120 degrees requires multiple segments\n\tif (Math.abs(f2 - f1) > _120) {\n\t\tvar f2old = f2\n\t\tvar x2old = x2\n\t\tvar y2old = y2\n\t\tf2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1)\n\t\tx2 = cx + rx * Math.cos(f2)\n\t\ty2 = cy + ry * Math.sin(f2)\n\t\tvar res = arc(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy])\n\t}\n\tvar t = Math.tan((f2 - f1) / 4)\n\tvar hx = 4 / 3 * rx * t\n\tvar hy = 4 / 3 * ry * t\n\tvar curve = [\n\t\t2 * x1 - (x1 + hx * Math.sin(f1)),\n\t\t2 * y1 - (y1 - hy * Math.cos(f1)),\n\t\tx2 + hx * Math.sin(f2),\n\t\ty2 - hy * Math.cos(f2),\n\t\tx2,\n\t\ty2\n\t]\n\tif (recursive) return curve\n\tif (res) curve = curve.concat(res)\n\tfor (var i = 0; i < curve.length;) {\n\t\tvar rot = rotate(curve[i], curve[i+1], angle)\n\t\tcurve[i++] = rot.x\n\t\tcurve[i++] = rot.y\n\t}\n\treturn curve\n}\n\nfunction rotate(x, y, rad){\n\treturn {\n\t\tx: x * Math.cos(rad) - y * Math.sin(rad),\n\t\ty: x * Math.sin(rad) + y * Math.cos(rad)\n\t}\n}\n\nfunction radians(degress){\n\treturn degress * (π / 180)\n}\n\n},{}],453:[function(_dereq_,module,exports){\nvar DEFAULT_NORMALS_EPSILON = 1e-6;\nvar DEFAULT_FACE_EPSILON = 1e-6;\n\n//Estimate the vertex normals of a mesh\nexports.vertexNormals = function(faces, positions, specifiedEpsilon) {\n\n  var N         = positions.length;\n  var normals   = new Array(N);\n  var epsilon   = specifiedEpsilon === void(0) ? DEFAULT_NORMALS_EPSILON : specifiedEpsilon;\n\n  //Initialize normal array\n  for(var i=0; i<N; ++i) {\n    normals[i] = [0.0, 0.0, 0.0];\n  }\n\n  //Walk over all the faces and add per-vertex contribution to normal weights\n  for(var i=0; i<faces.length; ++i) {\n    var f = faces[i];\n    var p = 0;\n    var c = f[f.length-1];\n    var n = f[0];\n    for(var j=0; j<f.length; ++j) {\n\n      //Shift indices back\n      p = c;\n      c = n;\n      n = f[(j+1) % f.length];\n\n      var v0 = positions[p];\n      var v1 = positions[c];\n      var v2 = positions[n];\n\n      //Compute infineteismal arcs\n      var d01 = new Array(3);\n      var m01 = 0.0;\n      var d21 = new Array(3);\n      var m21 = 0.0;\n      for(var k=0; k<3; ++k) {\n        d01[k] = v0[k]  - v1[k];\n        m01   += d01[k] * d01[k];\n        d21[k] = v2[k]  - v1[k];\n        m21   += d21[k] * d21[k];\n      }\n\n      //Accumulate values in normal\n      if(m01 * m21 > epsilon) {\n        var norm = normals[c];\n        var w = 1.0 / Math.sqrt(m01 * m21);\n        for(var k=0; k<3; ++k) {\n          var u = (k+1)%3;\n          var v = (k+2)%3;\n          norm[k] += w * (d21[u] * d01[v] - d21[v] * d01[u]);\n        }\n      }\n    }\n  }\n\n  //Scale all normals to unit length\n  for(var i=0; i<N; ++i) {\n    var norm = normals[i];\n    var m = 0.0;\n    for(var k=0; k<3; ++k) {\n      m += norm[k] * norm[k];\n    }\n    if(m > epsilon) {\n      var w = 1.0 / Math.sqrt(m);\n      for(var k=0; k<3; ++k) {\n        norm[k] *= w;\n      }\n    } else {\n      for(var k=0; k<3; ++k) {\n        norm[k] = 0.0;\n      }\n    }\n  }\n\n  //Return the resulting set of patches\n  return normals;\n}\n\n//Compute face normals of a mesh\nexports.faceNormals = function(faces, positions, specifiedEpsilon) {\n\n  var N         = faces.length;\n  var normals   = new Array(N);\n  var epsilon   = specifiedEpsilon === void(0) ? DEFAULT_FACE_EPSILON : specifiedEpsilon;\n\n  for(var i=0; i<N; ++i) {\n    var f = faces[i];\n    var pos = new Array(3);\n    for(var j=0; j<3; ++j) {\n      pos[j] = positions[f[j]];\n    }\n\n    var d01 = new Array(3);\n    var d21 = new Array(3);\n    for(var j=0; j<3; ++j) {\n      d01[j] = pos[1][j] - pos[0][j];\n      d21[j] = pos[2][j] - pos[0][j];\n    }\n\n    var n = new Array(3);\n    var l = 0.0;\n    for(var j=0; j<3; ++j) {\n      var u = (j+1)%3;\n      var v = (j+2)%3;\n      n[j] = d01[u] * d21[v] - d01[v] * d21[u];\n      l += n[j] * n[j];\n    }\n    if(l > epsilon) {\n      l = 1.0 / Math.sqrt(l);\n    } else {\n      l = 0.0;\n    }\n    for(var j=0; j<3; ++j) {\n      n[j] *= l;\n    }\n    normals[i] = n;\n  }\n  return normals;\n}\n\n\n\n},{}],454:[function(_dereq_,module,exports){\n/*\nobject-assign\n(c) Sindre Sorhus\n@license MIT\n*/\n\n'use strict';\n/* eslint-disable no-unused-vars */\nvar getOwnPropertySymbols = Object.getOwnPropertySymbols;\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar propIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nfunction toObject(val) {\n\tif (val === null || val === undefined) {\n\t\tthrow new TypeError('Object.assign cannot be called with null or undefined');\n\t}\n\n\treturn Object(val);\n}\n\nfunction shouldUseNative() {\n\ttry {\n\t\tif (!Object.assign) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Detect buggy property enumeration order in older V8 versions.\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=4118\n\t\tvar test1 = new String('abc');  // eslint-disable-line no-new-wrappers\n\t\ttest1[5] = 'de';\n\t\tif (Object.getOwnPropertyNames(test1)[0] === '5') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test2 = {};\n\t\tfor (var i = 0; i < 10; i++) {\n\t\t\ttest2['_' + String.fromCharCode(i)] = i;\n\t\t}\n\t\tvar order2 = Object.getOwnPropertyNames(test2).map(function (n) {\n\t\t\treturn test2[n];\n\t\t});\n\t\tif (order2.join('') !== '0123456789') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test3 = {};\n\t\t'abcdefghijklmnopqrst'.split('').forEach(function (letter) {\n\t\t\ttest3[letter] = letter;\n\t\t});\n\t\tif (Object.keys(Object.assign({}, test3)).join('') !==\n\t\t\t\t'abcdefghijklmnopqrst') {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (err) {\n\t\t// We don't expect any of the above to throw, but better to be safe.\n\t\treturn false;\n\t}\n}\n\nmodule.exports = shouldUseNative() ? Object.assign : function (target, source) {\n\tvar from;\n\tvar to = toObject(target);\n\tvar symbols;\n\n\tfor (var s = 1; s < arguments.length; s++) {\n\t\tfrom = Object(arguments[s]);\n\n\t\tfor (var key in from) {\n\t\t\tif (hasOwnProperty.call(from, key)) {\n\t\t\t\tto[key] = from[key];\n\t\t\t}\n\t\t}\n\n\t\tif (getOwnPropertySymbols) {\n\t\t\tsymbols = getOwnPropertySymbols(from);\n\t\t\tfor (var i = 0; i < symbols.length; i++) {\n\t\t\t\tif (propIsEnumerable.call(from, symbols[i])) {\n\t\t\t\t\tto[symbols[i]] = from[symbols[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn to;\n};\n\n},{}],455:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = quatFromFrame\n\nfunction quatFromFrame(\n  out,\n  rx, ry, rz,\n  ux, uy, uz,\n  fx, fy, fz) {\n  var tr = rx + uy + fz\n  if(l > 0) {\n    var l = Math.sqrt(tr + 1.0)\n    out[0] = 0.5 * (uz - fy) / l\n    out[1] = 0.5 * (fx - rz) / l\n    out[2] = 0.5 * (ry - uy) / l\n    out[3] = 0.5 * l\n  } else {\n    var tf = Math.max(rx, uy, fz)\n    var l = Math.sqrt(2 * tf - tr + 1.0)\n    if(rx >= tf) {\n      //x y z  order\n      out[0] = 0.5 * l\n      out[1] = 0.5 * (ux + ry) / l\n      out[2] = 0.5 * (fx + rz) / l\n      out[3] = 0.5 * (uz - fy) / l\n    } else if(uy >= tf) {\n      //y z x  order\n      out[0] = 0.5 * (ry + ux) / l\n      out[1] = 0.5 * l\n      out[2] = 0.5 * (fy + uz) / l\n      out[3] = 0.5 * (fx - rz) / l\n    } else {\n      //z x y  order\n      out[0] = 0.5 * (rz + fx) / l\n      out[1] = 0.5 * (uz + fy) / l\n      out[2] = 0.5 * l\n      out[3] = 0.5 * (ry - ux) / l\n    }\n  }\n  return out\n}\n},{}],456:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createOrbitController\n\nvar filterVector  = _dereq_('filtered-vector')\nvar lookAt        = _dereq_('gl-mat4/lookAt')\nvar mat4FromQuat  = _dereq_('gl-mat4/fromQuat')\nvar invert44      = _dereq_('gl-mat4/invert')\nvar quatFromFrame = _dereq_('./lib/quatFromFrame')\n\nfunction len3(x,y,z) {\n  return Math.sqrt(Math.pow(x,2) + Math.pow(y,2) + Math.pow(z,2))\n}\n\nfunction len4(w,x,y,z) {\n  return Math.sqrt(Math.pow(w,2) + Math.pow(x,2) + Math.pow(y,2) + Math.pow(z,2))\n}\n\nfunction normalize4(out, a) {\n  var ax = a[0]\n  var ay = a[1]\n  var az = a[2]\n  var aw = a[3]\n  var al = len4(ax, ay, az, aw)\n  if(al > 1e-6) {\n    out[0] = ax/al\n    out[1] = ay/al\n    out[2] = az/al\n    out[3] = aw/al\n  } else {\n    out[0] = out[1] = out[2] = 0.0\n    out[3] = 1.0\n  }\n}\n\nfunction OrbitCameraController(initQuat, initCenter, initRadius) {\n  this.radius    = filterVector([initRadius])\n  this.center    = filterVector(initCenter)\n  this.rotation  = filterVector(initQuat)\n\n  this.computedRadius   = this.radius.curve(0)\n  this.computedCenter   = this.center.curve(0)\n  this.computedRotation = this.rotation.curve(0)\n  this.computedUp       = [0.1,0,0]\n  this.computedEye      = [0.1,0,0]\n  this.computedMatrix   = [0.1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n\n  this.recalcMatrix(0)\n}\n\nvar proto = OrbitCameraController.prototype\n\nproto.lastT = function() {\n  return Math.max(\n    this.radius.lastT(),\n    this.center.lastT(),\n    this.rotation.lastT())\n}\n\nproto.recalcMatrix = function(t) {\n  this.radius.curve(t)\n  this.center.curve(t)\n  this.rotation.curve(t)\n\n  var quat = this.computedRotation\n  normalize4(quat, quat)\n\n  var mat = this.computedMatrix\n  mat4FromQuat(mat, quat)\n\n  var center = this.computedCenter\n  var eye    = this.computedEye\n  var up     = this.computedUp\n  var radius = Math.exp(this.computedRadius[0])\n\n  eye[0] = center[0] + radius * mat[2]\n  eye[1] = center[1] + radius * mat[6]\n  eye[2] = center[2] + radius * mat[10]\n  up[0] = mat[1]\n  up[1] = mat[5]\n  up[2] = mat[9]\n\n  for(var i=0; i<3; ++i) {\n    var rr = 0.0\n    for(var j=0; j<3; ++j) {\n      rr += mat[i+4*j] * eye[j]\n    }\n    mat[12+i] = -rr\n  }\n}\n\nproto.getMatrix = function(t, result) {\n  this.recalcMatrix(t)\n  var m = this.computedMatrix\n  if(result) {\n    for(var i=0; i<16; ++i) {\n      result[i] = m[i]\n    }\n    return result\n  }\n  return m\n}\n\nproto.idle = function(t) {\n  this.center.idle(t)\n  this.radius.idle(t)\n  this.rotation.idle(t)\n}\n\nproto.flush = function(t) {\n  this.center.flush(t)\n  this.radius.flush(t)\n  this.rotation.flush(t)\n}\n\nproto.pan = function(t, dx, dy, dz) {\n  dx = dx || 0.0\n  dy = dy || 0.0\n  dz = dz || 0.0\n\n  this.recalcMatrix(t)\n  var mat = this.computedMatrix\n\n  var ux = mat[1]\n  var uy = mat[5]\n  var uz = mat[9]\n  var ul = len3(ux, uy, uz)\n  ux /= ul\n  uy /= ul\n  uz /= ul\n\n  var rx = mat[0]\n  var ry = mat[4]\n  var rz = mat[8]\n  var ru = rx * ux + ry * uy + rz * uz\n  rx -= ux * ru\n  ry -= uy * ru\n  rz -= uz * ru\n  var rl = len3(rx, ry, rz)\n  rx /= rl\n  ry /= rl\n  rz /= rl\n\n  var fx = mat[2]\n  var fy = mat[6]\n  var fz = mat[10]\n  var fu = fx * ux + fy * uy + fz * uz\n  var fr = fx * rx + fy * ry + fz * rz\n  fx -= fu * ux + fr * rx\n  fy -= fu * uy + fr * ry\n  fz -= fu * uz + fr * rz\n  var fl = len3(fx, fy, fz)\n  fx /= fl\n  fy /= fl\n  fz /= fl\n\n  var vx = rx * dx + ux * dy\n  var vy = ry * dx + uy * dy\n  var vz = rz * dx + uz * dy\n\n  this.center.move(t, vx, vy, vz)\n\n  //Update z-component of radius\n  var radius = Math.exp(this.computedRadius[0])\n  radius = Math.max(1e-4, radius + dz)\n  this.radius.set(t, Math.log(radius))\n}\n\nproto.rotate = function(t, dx, dy, dz) {\n  this.recalcMatrix(t)\n\n  dx = dx||0.0\n  dy = dy||0.0\n\n  var mat = this.computedMatrix\n\n  var rx = mat[0]\n  var ry = mat[4]\n  var rz = mat[8]\n\n  var ux = mat[1]\n  var uy = mat[5]\n  var uz = mat[9]\n\n  var fx = mat[2]\n  var fy = mat[6]\n  var fz = mat[10]\n\n  var qx = dx * rx + dy * ux\n  var qy = dx * ry + dy * uy\n  var qz = dx * rz + dy * uz\n\n  var bx = -(fy * qz - fz * qy)\n  var by = -(fz * qx - fx * qz)\n  var bz = -(fx * qy - fy * qx)  \n  var bw = Math.sqrt(Math.max(0.0, 1.0 - Math.pow(bx,2) - Math.pow(by,2) - Math.pow(bz,2)))\n  var bl = len4(bx, by, bz, bw)\n  if(bl > 1e-6) {\n    bx /= bl\n    by /= bl\n    bz /= bl\n    bw /= bl\n  } else {\n    bx = by = bz = 0.0\n    bw = 1.0\n  }\n\n  var rotation = this.computedRotation\n  var ax = rotation[0]\n  var ay = rotation[1]\n  var az = rotation[2]\n  var aw = rotation[3]\n\n  var cx = ax*bw + aw*bx + ay*bz - az*by\n  var cy = ay*bw + aw*by + az*bx - ax*bz\n  var cz = az*bw + aw*bz + ax*by - ay*bx\n  var cw = aw*bw - ax*bx - ay*by - az*bz\n  \n  //Apply roll\n  if(dz) {\n    bx = fx\n    by = fy\n    bz = fz\n    var s = Math.sin(dz) / len3(bx, by, bz)\n    bx *= s\n    by *= s\n    bz *= s\n    bw = Math.cos(dx)\n    cx = cx*bw + cw*bx + cy*bz - cz*by\n    cy = cy*bw + cw*by + cz*bx - cx*bz\n    cz = cz*bw + cw*bz + cx*by - cy*bx\n    cw = cw*bw - cx*bx - cy*by - cz*bz\n  }\n\n  var cl = len4(cx, cy, cz, cw)\n  if(cl > 1e-6) {\n    cx /= cl\n    cy /= cl\n    cz /= cl\n    cw /= cl\n  } else {\n    cx = cy = cz = 0.0\n    cw = 1.0\n  }\n\n  this.rotation.set(t, cx, cy, cz, cw)\n}\n\nproto.lookAt = function(t, eye, center, up) {\n  this.recalcMatrix(t)\n\n  center = center || this.computedCenter\n  eye    = eye    || this.computedEye\n  up     = up     || this.computedUp\n\n  var mat = this.computedMatrix\n  lookAt(mat, eye, center, up)\n\n  var rotation = this.computedRotation\n  quatFromFrame(rotation,\n    mat[0], mat[1], mat[2],\n    mat[4], mat[5], mat[6],\n    mat[8], mat[9], mat[10])\n  normalize4(rotation, rotation)\n  this.rotation.set(t, rotation[0], rotation[1], rotation[2], rotation[3])\n\n  var fl = 0.0\n  for(var i=0; i<3; ++i) {\n    fl += Math.pow(center[i] - eye[i], 2)\n  }\n  this.radius.set(t, 0.5 * Math.log(Math.max(fl, 1e-6)))\n\n  this.center.set(t, center[0], center[1], center[2])\n}\n\nproto.translate = function(t, dx, dy, dz) {\n  this.center.move(t,\n    dx||0.0,\n    dy||0.0,\n    dz||0.0)\n}\n\nproto.setMatrix = function(t, matrix) {\n\n  var rotation = this.computedRotation\n  quatFromFrame(rotation,\n    matrix[0], matrix[1], matrix[2],\n    matrix[4], matrix[5], matrix[6],\n    matrix[8], matrix[9], matrix[10])\n  normalize4(rotation, rotation)\n  this.rotation.set(t, rotation[0], rotation[1], rotation[2], rotation[3])\n\n  var mat = this.computedMatrix\n  invert44(mat, matrix)\n  var w = mat[15]\n  if(Math.abs(w) > 1e-6) {\n    var cx = mat[12]/w\n    var cy = mat[13]/w\n    var cz = mat[14]/w\n\n    this.recalcMatrix(t)  \n    var r = Math.exp(this.computedRadius[0])\n    this.center.set(t, cx-mat[2]*r, cy-mat[6]*r, cz-mat[10]*r)\n    this.radius.idle(t)\n  } else {\n    this.center.idle(t)\n    this.radius.idle(t)\n  }\n}\n\nproto.setDistance = function(t, d) {\n  if(d > 0) {\n    this.radius.set(t, Math.log(d))\n  }\n}\n\nproto.setDistanceLimits = function(lo, hi) {\n  if(lo > 0) {\n    lo = Math.log(lo)\n  } else {\n    lo = -Infinity    \n  }\n  if(hi > 0) {\n    hi = Math.log(hi)\n  } else {\n    hi = Infinity\n  }\n  hi = Math.max(hi, lo)\n  this.radius.bounds[0][0] = lo\n  this.radius.bounds[1][0] = hi\n}\n\nproto.getDistanceLimits = function(out) {\n  var bounds = this.radius.bounds\n  if(out) {\n    out[0] = Math.exp(bounds[0][0])\n    out[1] = Math.exp(bounds[1][0])\n    return out\n  }\n  return [ Math.exp(bounds[0][0]), Math.exp(bounds[1][0]) ]\n}\n\nproto.toJSON = function() {\n  this.recalcMatrix(this.lastT())\n  return {\n    center:   this.computedCenter.slice(),\n    rotation: this.computedRotation.slice(),\n    distance: Math.log(this.computedRadius[0]),\n    zoomMin:  this.radius.bounds[0][0],\n    zoomMax:  this.radius.bounds[1][0]\n  }\n}\n\nproto.fromJSON = function(options) {\n  var t = this.lastT()\n  var c = options.center\n  if(c) {\n    this.center.set(t, c[0], c[1], c[2])\n  }\n  var r = options.rotation\n  if(r) {\n    this.rotation.set(t, r[0], r[1], r[2], r[3])\n  }\n  var d = options.distance\n  if(d && d > 0) {\n    this.radius.set(t, Math.log(d))\n  }\n  this.setDistanceLimits(options.zoomMin, options.zoomMax)\n}\n\nfunction createOrbitController(options) {\n  options = options || {}\n  var center   = options.center   || [0,0,0]\n  var rotation = options.rotation || [0,0,0,1]\n  var radius   = options.radius   || 1.0\n\n  center = [].slice.call(center, 0, 3)\n  rotation = [].slice.call(rotation, 0, 4)\n  normalize4(rotation, rotation)\n\n  var result = new OrbitCameraController(\n    rotation,\n    center,\n    Math.log(radius))\n\n  result.setDistanceLimits(options.zoomMin, options.zoomMax)\n\n  if('eye' in options || 'up' in options) {\n    result.lookAt(0, options.eye, options.center, options.up)\n  }\n\n  return result\n}\n},{\"./lib/quatFromFrame\":455,\"filtered-vector\":226,\"gl-mat4/fromQuat\":262,\"gl-mat4/invert\":265,\"gl-mat4/lookAt\":266}],457:[function(_dereq_,module,exports){\n/*!\n * pad-left <https://github.com/jonschlinkert/pad-left>\n *\n * Copyright (c) 2014-2015, Jon Schlinkert.\n * Licensed under the MIT license.\n */\n\n'use strict';\n\nvar repeat = _dereq_('repeat-string');\n\nmodule.exports = function padLeft(str, num, ch) {\n  ch = typeof ch !== 'undefined' ? (ch + '') : ' ';\n  return repeat(ch, num) + str;\n};\n},{\"repeat-string\":503}],458:[function(_dereq_,module,exports){\n'use strict'\r\n\r\n/**\r\n * @module parenthesis\r\n */\r\n\r\nfunction parse (str, opts) {\r\n\t// pretend non-string parsed per-se\r\n\tif (typeof str !== 'string') return [str]\r\n\r\n\tvar res = [str]\r\n\r\n\tif (typeof opts === 'string' || Array.isArray(opts)) {\r\n\t\topts = {brackets: opts}\r\n\t}\r\n\telse if (!opts) opts = {}\r\n\r\n\tvar brackets = opts.brackets ? (Array.isArray(opts.brackets) ? opts.brackets : [opts.brackets]) : ['{}', '[]', '()']\r\n\r\n\tvar escape = opts.escape || '___'\r\n\r\n\tvar flat = !!opts.flat\r\n\r\n\tbrackets.forEach(function (bracket) {\r\n\t\t// create parenthesis regex\r\n\t\tvar pRE = new RegExp(['\\\\', bracket[0], '[^\\\\', bracket[0], '\\\\', bracket[1], ']*\\\\', bracket[1]].join(''))\r\n\r\n\t\tvar ids = []\r\n\r\n\t\tfunction replaceToken(token, idx, str){\r\n\t\t\t// save token to res\r\n\t\t\tvar refId = res.push(token.slice(bracket[0].length, -bracket[1].length)) - 1\r\n\r\n\t\t\tids.push(refId)\r\n\r\n\t\t\treturn escape + refId + escape\r\n\t\t}\r\n\r\n\t\tres.forEach(function (str, i) {\r\n\t\t\tvar prevStr\r\n\r\n\t\t\t// replace paren tokens till there’s none\r\n\t\t\tvar a = 0\r\n\t\t\twhile (str != prevStr) {\r\n\t\t\t\tprevStr = str\r\n\t\t\t\tstr = str.replace(pRE, replaceToken)\r\n\t\t\t\tif (a++ > 10e3) throw Error('References have circular dependency. Please, check them.')\r\n\t\t\t}\r\n\r\n\t\t\tres[i] = str\r\n\t\t})\r\n\r\n\t\t// wrap found refs to brackets\r\n\t\tids = ids.reverse()\r\n\t\tres = res.map(function (str) {\r\n\t\t\tids.forEach(function (id) {\r\n\t\t\t\tstr = str.replace(new RegExp('(\\\\' + escape + id + '\\\\' + escape + ')', 'g'), bracket[0] + '$1' + bracket[1])\r\n\t\t\t})\r\n\t\t\treturn str\r\n\t\t})\r\n\t})\r\n\r\n\tvar re = new RegExp('\\\\' + escape + '([0-9]+)' + '\\\\' + escape)\r\n\r\n\t// transform references to tree\r\n\tfunction nest (str, refs, escape) {\r\n\t\tvar res = [], match\r\n\r\n\t\tvar a = 0\r\n\t\twhile (match = re.exec(str)) {\r\n\t\t\tif (a++ > 10e3) throw Error('Circular references in parenthesis')\r\n\r\n\t\t\tres.push(str.slice(0, match.index))\r\n\r\n\t\t\tres.push(nest(refs[match[1]], refs))\r\n\r\n\t\t\tstr = str.slice(match.index + match[0].length)\r\n\t\t}\r\n\r\n\t\tres.push(str)\r\n\r\n\t\treturn res\r\n\t}\r\n\r\n\treturn flat ? res : nest(res[0], res)\r\n}\r\n\r\nfunction stringify (arg, opts) {\r\n\tif (opts && opts.flat) {\r\n\t\tvar escape = opts && opts.escape || '___'\r\n\r\n\t\tvar str = arg[0], prevStr\r\n\r\n\t\t// pretend bad string stringified with no parentheses\r\n\t\tif (!str) return ''\r\n\r\n\r\n\t\tvar re = new RegExp('\\\\' + escape + '([0-9]+)' + '\\\\' + escape)\r\n\r\n\t\tvar a = 0\r\n\t\twhile (str != prevStr) {\r\n\t\t\tif (a++ > 10e3) throw Error('Circular references in ' + arg)\r\n\t\t\tprevStr = str\r\n\t\t\tstr = str.replace(re, replaceRef)\r\n\t\t}\r\n\r\n\t\treturn str\r\n\t}\r\n\r\n\treturn arg.reduce(function f (prev, curr) {\r\n\t\tif (Array.isArray(curr)) {\r\n\t\t\tcurr = curr.reduce(f, '')\r\n\t\t}\r\n\t\treturn prev + curr\r\n\t}, '')\r\n\r\n\tfunction replaceRef(match, idx){\r\n\t\tif (arg[idx] == null) throw Error('Reference ' + idx + 'is undefined')\r\n\t\treturn arg[idx]\r\n\t}\r\n}\r\n\r\nfunction parenthesis (arg, opts) {\r\n\tif (Array.isArray(arg)) {\r\n\t\treturn stringify(arg, opts)\r\n\t}\r\n\telse {\r\n\t\treturn parse(arg, opts)\r\n\t}\r\n}\r\n\r\nparenthesis.parse = parse\r\nparenthesis.stringify = stringify\r\n\r\nmodule.exports = parenthesis\r\n\n},{}],459:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar pick = _dereq_('pick-by-alias')\r\n\r\nmodule.exports = parseRect\r\n\r\nfunction parseRect (arg) {\r\n  var rect\r\n\r\n  // direct arguments sequence\r\n  if (arguments.length > 1) {\r\n    arg = arguments\r\n  }\r\n\r\n  // svg viewbox\r\n  if (typeof arg === 'string') {\r\n    arg = arg.split(/\\s/).map(parseFloat)\r\n  }\r\n  else if (typeof arg === 'number') {\r\n    arg = [arg]\r\n  }\r\n\r\n  // 0, 0, 100, 100 - array-like\r\n  if (arg.length && typeof arg[0] === 'number') {\r\n    // [w, w]\r\n    if (arg.length === 1) {\r\n      rect = {\r\n        width: arg[0],\r\n        height: arg[0],\r\n        x: 0, y: 0\r\n      }\r\n    }\r\n    // [w, h]\r\n    else if (arg.length === 2) {\r\n      rect = {\r\n        width: arg[0],\r\n        height: arg[1],\r\n        x: 0, y: 0\r\n      }\r\n    }\r\n    // [l, t, r, b]\r\n    else {\r\n      rect = {\r\n        x: arg[0],\r\n        y: arg[1],\r\n        width: (arg[2] - arg[0]) || 0,\r\n        height: (arg[3] - arg[1]) || 0\r\n      }\r\n    }\r\n  }\r\n  // {x, y, w, h} or {l, t, b, r}\r\n  else if (arg) {\r\n    arg = pick(arg, {\r\n      left: 'x l left Left',\r\n      top: 'y t top Top',\r\n      width: 'w width W Width',\r\n      height: 'h height W Width',\r\n      bottom: 'b bottom Bottom',\r\n      right: 'r right Right'\r\n    })\r\n\r\n    rect = {\r\n      x: arg.left || 0,\r\n      y: arg.top || 0\r\n    }\r\n\r\n    if (arg.width == null) {\r\n      if (arg.right) rect.width = arg.right - rect.x\r\n      else rect.width = 0\r\n    }\r\n    else {\r\n      rect.width = arg.width\r\n    }\r\n\r\n    if (arg.height == null) {\r\n      if (arg.bottom) rect.height = arg.bottom - rect.y\r\n      else rect.height = 0\r\n    }\r\n    else {\r\n      rect.height = arg.height\r\n    }\r\n  }\r\n\r\n  return rect\r\n}\r\n\n},{\"pick-by-alias\":465}],460:[function(_dereq_,module,exports){\n\nmodule.exports = parse\n\n/**\n * expected argument lengths\n * @type {Object}\n */\n\nvar length = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0}\n\n/**\n * segment pattern\n * @type {RegExp}\n */\n\nvar segment = /([astvzqmhlc])([^astvzqmhlc]*)/ig\n\n/**\n * parse an svg path data string. Generates an Array\n * of commands where each command is an Array of the\n * form `[command, arg1, arg2, ...]`\n *\n * @param {String} path\n * @return {Array}\n */\n\nfunction parse(path) {\n\tvar data = []\n\tpath.replace(segment, function(_, command, args){\n\t\tvar type = command.toLowerCase()\n\t\targs = parseValues(args)\n\n\t\t// overloaded moveTo\n\t\tif (type == 'm' && args.length > 2) {\n\t\t\tdata.push([command].concat(args.splice(0, 2)))\n\t\t\ttype = 'l'\n\t\t\tcommand = command == 'm' ? 'l' : 'L'\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (args.length == length[type]) {\n\t\t\t\targs.unshift(command)\n\t\t\t\treturn data.push(args)\n\t\t\t}\n\t\t\tif (args.length < length[type]) throw new Error('malformed path data')\n\t\t\tdata.push([command].concat(args.splice(0, length[type])))\n\t\t}\n\t})\n\treturn data\n}\n\nvar number = /-?[0-9]*\\.?[0-9]+(?:e[-+]?\\d+)?/ig\n\nfunction parseValues(args) {\n\tvar numbers = args.match(number)\n\treturn numbers ? numbers.map(Number) : []\n}\n\n},{}],461:[function(_dereq_,module,exports){\nmodule.exports = function parseUnit(str, out) {\n    if (!out)\n        out = [ 0, '' ]\n\n    str = String(str)\n    var num = parseFloat(str, 10)\n    out[0] = num\n    out[1] = str.match(/[\\d.\\-\\+]*\\s*(.*)/)[1] || ''\n    return out\n}\n},{}],462:[function(_dereq_,module,exports){\n(function (process){\n// Generated by CoffeeScript 1.12.2\n(function() {\n  var getNanoSeconds, hrtime, loadTime, moduleLoadTime, nodeLoadTime, upTime;\n\n  if ((typeof performance !== \"undefined\" && performance !== null) && performance.now) {\n    module.exports = function() {\n      return performance.now();\n    };\n  } else if ((typeof process !== \"undefined\" && process !== null) && process.hrtime) {\n    module.exports = function() {\n      return (getNanoSeconds() - nodeLoadTime) / 1e6;\n    };\n    hrtime = process.hrtime;\n    getNanoSeconds = function() {\n      var hr;\n      hr = hrtime();\n      return hr[0] * 1e9 + hr[1];\n    };\n    moduleLoadTime = getNanoSeconds();\n    upTime = process.uptime() * 1e9;\n    nodeLoadTime = moduleLoadTime - upTime;\n  } else if (Date.now) {\n    module.exports = function() {\n      return Date.now() - loadTime;\n    };\n    loadTime = Date.now();\n  } else {\n    module.exports = function() {\n      return new Date().getTime() - loadTime;\n    };\n    loadTime = new Date().getTime();\n  }\n\n}).call(this);\n\n\n\n}).call(this,_dereq_('_process'))\n},{\"_process\":482}],463:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = permutationSign\n\nvar BRUTE_FORCE_CUTOFF = 32\n\nvar pool = _dereq_(\"typedarray-pool\")\n\nfunction permutationSign(p) {\n  var n = p.length\n  if(n < BRUTE_FORCE_CUTOFF) {\n    //Use quadratic algorithm for small n\n    var sgn = 1\n    for(var i=0; i<n; ++i) {\n      for(var j=0; j<i; ++j) {\n        if(p[i] < p[j]) {\n          sgn = -sgn\n        } else if(p[i] === p[j]) {\n          return 0\n        }\n      }\n    }\n    return sgn\n  } else {\n    //Otherwise use linear time algorithm\n    var visited = pool.mallocUint8(n)\n    for(var i=0; i<n; ++i) {\n      visited[i] = 0\n    }\n    var sgn = 1\n    for(var i=0; i<n; ++i) {\n      if(!visited[i]) {\n        var count = 1\n        visited[i] = 1\n        for(var j=p[i]; j!==i; j=p[j]) {\n          if(visited[j]) {\n            pool.freeUint8(visited)\n            return 0\n          }\n          count += 1\n          visited[j] = 1\n        }\n        if(!(count & 1)) {\n          sgn = -sgn\n        }\n      }\n    }\n    pool.freeUint8(visited)\n    return sgn\n  }\n}\n},{\"typedarray-pool\":545}],464:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar pool = _dereq_(\"typedarray-pool\")\nvar inverse = _dereq_(\"invert-permutation\")\n\nfunction rank(permutation) {\n  var n = permutation.length\n  switch(n) {\n    case 0:\n    case 1:\n      return 0\n    case 2:\n      return permutation[1]\n    default:\n      break\n  }\n  var p = pool.mallocUint32(n)\n  var pinv = pool.mallocUint32(n)\n  var r = 0, s, t, i\n  inverse(permutation, pinv)\n  for(i=0; i<n; ++i) {\n    p[i] = permutation[i]\n  }\n  for(i=n-1; i>0; --i) {\n    t = pinv[i]\n    s = p[i]\n    p[i] = p[t]\n    p[t] = s\n    pinv[i] = pinv[s]\n    pinv[s] = t\n    r = (r + s) * i\n  }\n  pool.freeUint32(pinv)\n  pool.freeUint32(p)\n  return r\n}\n\nfunction unrank(n, r, p) {\n  switch(n) {\n    case 0:\n      if(p) { return p }\n      return []\n    case 1:\n      if(p) {\n        p[0] = 0\n        return p\n      } else {\n        return [0]\n      }\n    case 2:\n      if(p) {\n        if(r) {\n          p[0] = 0\n          p[1] = 1\n        } else {\n          p[0] = 1\n          p[1] = 0\n        }\n        return p\n      } else {\n        return r ? [0,1] : [1,0]\n      }\n    default:\n      break\n  }\n  p = p || new Array(n)\n  var s, t, i, nf=1\n  p[0] = 0\n  for(i=1; i<n; ++i) {\n    p[i] = i\n    nf = (nf*i)|0\n  }\n  for(i=n-1; i>0; --i) {\n    s = (r / nf)|0\n    r = (r - s * nf)|0\n    nf = (nf / i)|0\n    t = p[i]|0\n    p[i] = p[s]|0\n    p[s] = t|0\n  }\n  return p\n}\n\nexports.rank = rank\nexports.unrank = unrank\n\n},{\"invert-permutation\":415,\"typedarray-pool\":545}],465:[function(_dereq_,module,exports){\n'use strict'\r\n\r\n\r\nmodule.exports = function pick (src, props, keepRest) {\r\n\tvar result = {}, prop, i\r\n\r\n\tif (typeof props === 'string') props = toList(props)\r\n\tif (Array.isArray(props)) {\r\n\t\tvar res = {}\r\n\t\tfor (i = 0; i < props.length; i++) {\r\n\t\t\tres[props[i]] = true\r\n\t\t}\r\n\t\tprops = res\r\n\t}\r\n\r\n\t// convert strings to lists\r\n\tfor (prop in props) {\r\n\t\tprops[prop] = toList(props[prop])\r\n\t}\r\n\r\n\t// keep-rest strategy requires unmatched props to be preserved\r\n\tvar occupied = {}\r\n\r\n\tfor (prop in props) {\r\n\t\tvar aliases = props[prop]\r\n\r\n\t\tif (Array.isArray(aliases)) {\r\n\t\t\tfor (i = 0; i < aliases.length; i++) {\r\n\t\t\t\tvar alias = aliases[i]\r\n\r\n\t\t\t\tif (keepRest) {\r\n\t\t\t\t\toccupied[alias] = true\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (alias in src) {\r\n\t\t\t\t\tresult[prop] = src[alias]\r\n\r\n\t\t\t\t\tif (keepRest) {\r\n\t\t\t\t\t\tfor (var j = i; j < aliases.length; j++) {\r\n\t\t\t\t\t\t\toccupied[aliases[j]] = true\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tbreak\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (prop in src) {\r\n\t\t\tif (props[prop]) {\r\n\t\t\t\tresult[prop] = src[prop]\r\n\t\t\t}\r\n\r\n\t\t\tif (keepRest) {\r\n\t\t\t\toccupied[prop] = true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tif (keepRest) {\r\n\t\tfor (prop in src) {\r\n\t\t\tif (occupied[prop]) continue\r\n\t\t\tresult[prop] = src[prop]\r\n\t\t}\r\n\t}\r\n\r\n\treturn result\r\n}\r\n\r\nvar CACHE = {}\r\n\r\nfunction toList(arg) {\r\n\tif (CACHE[arg]) return CACHE[arg]\r\n\tif (typeof arg === 'string') {\r\n\t\targ = CACHE[arg] = arg.split(/\\s*,\\s*|\\s+/)\r\n\t}\r\n\treturn arg\r\n}\r\n\n},{}],466:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = planarDual\n\nvar compareAngle = _dereq_(\"compare-angle\")\n\nfunction planarDual(cells, positions) {\n\n  var numVertices = positions.length|0\n  var numEdges = cells.length\n  var adj = [new Array(numVertices), new Array(numVertices)]\n  for(var i=0; i<numVertices; ++i) {\n    adj[0][i] = []\n    adj[1][i] = []\n  }\n  for(var i=0; i<numEdges; ++i) {\n    var c = cells[i]\n    adj[0][c[0]].push(c)\n    adj[1][c[1]].push(c)\n  }\n\n  var cycles = []\n\n  //Add isolated vertices as trivial case\n  for(var i=0; i<numVertices; ++i) {\n    if(adj[0][i].length + adj[1][i].length === 0) {\n      cycles.push( [i] )\n    }\n  }\n\n  //Remove a half edge\n  function cut(c, i) {\n    var a = adj[i][c[i]]\n    a.splice(a.indexOf(c), 1)\n  }\n\n  //Find next vertex and cut edge\n  function next(a, b, noCut) {\n    var nextCell, nextVertex, nextDir\n    for(var i=0; i<2; ++i) {\n      if(adj[i][b].length > 0) {\n        nextCell = adj[i][b][0]\n        nextDir = i\n        break\n      }\n    }\n    nextVertex = nextCell[nextDir^1]\n\n    for(var dir=0; dir<2; ++dir) {\n      var nbhd = adj[dir][b]\n      for(var k=0; k<nbhd.length; ++k) {\n        var e = nbhd[k]\n        var p = e[dir^1]\n        var cmp = compareAngle(\n            positions[a], \n            positions[b], \n            positions[nextVertex],\n            positions[p])\n        if(cmp > 0) {\n          nextCell = e\n          nextVertex = p\n          nextDir = dir\n        }\n      }\n    }\n    if(noCut) {\n      return nextVertex\n    }\n    if(nextCell) {\n      cut(nextCell, nextDir)\n    }\n    return nextVertex\n  }\n\n  function extractCycle(v, dir) {\n    var e0 = adj[dir][v][0]\n    var cycle = [v]\n    cut(e0, dir)\n    var u = e0[dir^1]\n    var d0 = dir\n    while(true) {\n      while(u !== v) {\n        cycle.push(u)\n        u = next(cycle[cycle.length-2], u, false)\n      }\n      if(adj[0][v].length + adj[1][v].length === 0) {\n        break\n      }\n      var a = cycle[cycle.length-1]\n      var b = v\n      var c = cycle[1]\n      var d = next(a, b, true)\n      if(compareAngle(positions[a], positions[b], positions[c], positions[d]) < 0) {\n        break\n      }\n      cycle.push(v)\n      u = next(a, b)\n    }\n    return cycle\n  }\n\n  function shouldGlue(pcycle, ncycle) {\n    return (ncycle[1] === ncycle[ncycle.length-1])\n  }\n\n  for(var i=0; i<numVertices; ++i) {\n    for(var j=0; j<2; ++j) {\n      var pcycle = []\n      while(adj[j][i].length > 0) {\n        var ni = adj[0][i].length\n        var ncycle = extractCycle(i,j)\n        if(shouldGlue(pcycle, ncycle)) {\n          //Glue together trivial cycles\n          pcycle.push.apply(pcycle, ncycle)\n        } else {\n          if(pcycle.length > 0) {\n            cycles.push(pcycle)\n          }\n          pcycle = ncycle\n        }\n      }\n      if(pcycle.length > 0) {\n        cycles.push(pcycle)\n      }\n    }\n  }\n\n  //Combine paths and loops together\n  return cycles\n}\n},{\"compare-angle\":127}],467:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = trimLeaves\n\nvar e2a = _dereq_('edges-to-adjacency-list')\n\nfunction trimLeaves(edges, positions) {\n  var adj = e2a(edges, positions.length)\n  var live = new Array(positions.length)\n  var nbhd = new Array(positions.length)\n\n  var dead = []\n  for(var i=0; i<positions.length; ++i) {\n    var count = adj[i].length\n    nbhd[i] = count\n    live[i] = true\n    if(count <= 1) {\n      dead.push(i)\n    }\n  }\n\n  while(dead.length > 0) {\n    var v = dead.pop()\n    live[v] = false\n    var n = adj[v]\n    for(var i=0; i<n.length; ++i) {\n      var u = n[i]\n      if(--nbhd[u] === 0) {\n        dead.push(u)\n      }\n    }\n  }\n\n  var newIndex = new Array(positions.length)\n  var npositions = []\n  for(var i=0; i<positions.length; ++i) {\n    if(live[i]) {\n      var v = npositions.length\n      newIndex[i] = v\n      npositions.push(positions[i])\n    } else {\n      newIndex[i] = -1\n    }\n  }\n\n  var nedges = []\n  for(var i=0; i<edges.length; ++i) {\n    var e = edges[i]\n    if(live[e[0]] && live[e[1]]) {\n      nedges.push([ newIndex[e[0]], newIndex[e[1]] ])\n    }\n  }\n  \n  return [ nedges, npositions ]\n}\n},{\"edges-to-adjacency-list\":171}],468:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = planarGraphToPolyline\n\nvar e2a = _dereq_('edges-to-adjacency-list')\nvar planarDual = _dereq_('planar-dual')\nvar preprocessPolygon = _dereq_('point-in-big-polygon')\nvar twoProduct = _dereq_('two-product')\nvar robustSum = _dereq_('robust-sum')\nvar uniq = _dereq_('uniq')\nvar trimLeaves = _dereq_('./lib/trim-leaves')\n\nfunction makeArray(length, fill) {\n  var result = new Array(length)\n  for(var i=0; i<length; ++i) {\n    result[i] = fill\n  }\n  return result\n}\n\nfunction makeArrayOfArrays(length) {\n  var result = new Array(length)\n  for(var i=0; i<length; ++i) {\n    result[i] = []\n  }\n  return result\n}\n\n\nfunction planarGraphToPolyline(edges, positions) {\n\n  //Trim leaves\n  var result = trimLeaves(edges, positions)\n  edges = result[0]\n  positions = result[1]\n\n  var numVertices = positions.length\n  var numEdges = edges.length\n\n  //Calculate adjacency list, check manifold\n  var adj = e2a(edges, positions.length)\n  for(var i=0; i<numVertices; ++i) {\n    if(adj[i].length % 2 === 1) {\n      throw new Error('planar-graph-to-polyline: graph must be manifold')\n    }\n  }\n\n  //Get faces\n  var faces = planarDual(edges, positions)\n\n  //Check orientation of a polygon using exact arithmetic\n  function ccw(c) {\n    var n = c.length\n    var area = [0]\n    for(var j=0; j<n; ++j) {\n      var a = positions[c[j]]\n      var b = positions[c[(j+1)%n]]\n      var t00 = twoProduct(-a[0], a[1])\n      var t01 = twoProduct(-a[0], b[1])\n      var t10 = twoProduct( b[0], a[1])\n      var t11 = twoProduct( b[0], b[1])\n      area = robustSum(area, robustSum(robustSum(t00, t01), robustSum(t10, t11)))\n    }\n    return area[area.length-1] > 0\n  }\n\n  //Extract all clockwise faces\n  faces = faces.filter(ccw)\n\n  //Detect which loops are contained in one another to handle parent-of relation\n  var numFaces = faces.length\n  var parent = new Array(numFaces)\n  var containment = new Array(numFaces)\n  for(var i=0; i<numFaces; ++i) {\n    parent[i] = i\n    var row = new Array(numFaces)\n    var loopVertices = faces[i].map(function(v) {\n      return positions[v]\n    })\n    var pmc = preprocessPolygon([loopVertices])\n    var count = 0\n    outer:\n    for(var j=0; j<numFaces; ++j) {\n      row[j] = 0\n      if(i === j) {\n        continue\n      }\n      var c = faces[j]\n      var n = c.length\n      for(var k=0; k<n; ++k) {\n        var d = pmc(positions[c[k]])\n        if(d !== 0) {\n          if(d < 0) {\n            row[j] = 1\n            count += 1\n          }\n          continue outer\n        }\n      }\n      row[j] = 1\n      count += 1\n    }\n    containment[i] = [count, i, row]\n  }\n  containment.sort(function(a,b) {\n    return b[0] - a[0]\n  })\n  for(var i=0; i<numFaces; ++i) {\n    var row = containment[i]\n    var idx = row[1]\n    var children = row[2]\n    for(var j=0; j<numFaces; ++j) {\n      if(children[j]) {\n        parent[j] = idx\n      }\n    }\n  }\n\n  //Initialize face adjacency list\n  var fadj = makeArrayOfArrays(numFaces)\n  for(var i=0; i<numFaces; ++i) {\n    fadj[i].push(parent[i])\n    fadj[parent[i]].push(i)\n  }\n\n  //Build adjacency matrix for edges\n  var edgeAdjacency = {}\n  var internalVertices = makeArray(numVertices, false)\n  for(var i=0; i<numFaces; ++i) {\n    var c = faces[i]\n    var n = c.length\n    for(var j=0; j<n; ++j) {\n      var a = c[j]\n      var b = c[(j+1)%n]\n      var key = Math.min(a,b) + \":\" + Math.max(a,b)\n      if(key in edgeAdjacency) {\n        var neighbor = edgeAdjacency[key]\n        fadj[neighbor].push(i)\n        fadj[i].push(neighbor)\n        internalVertices[a] = internalVertices[b] = true\n      } else {\n        edgeAdjacency[key] = i\n      }\n    }\n  }\n\n  function sharedBoundary(c) {\n    var n = c.length\n    for(var i=0; i<n; ++i) {\n      if(!internalVertices[c[i]]) {\n        return false\n      }\n    }\n    return true\n  }\n\n  var toVisit = []\n  var parity = makeArray(numFaces, -1)\n  for(var i=0; i<numFaces; ++i) {\n    if(parent[i] === i && !sharedBoundary(faces[i])) {\n      toVisit.push(i)\n      parity[i] = 0\n    } else {\n      parity[i] = -1\n    }\n  }\n\n  //Using face adjacency, classify faces as in/out\n  var result = []\n  while(toVisit.length > 0) {\n    var top = toVisit.pop()\n    var nbhd = fadj[top]\n    uniq(nbhd, function(a,b) {\n      return a-b\n    })\n    var nnbhr = nbhd.length\n    var p = parity[top]\n    var polyline\n    if(p === 0) {\n      var c = faces[top]\n      polyline = [c]\n    }\n    for(var i=0; i<nnbhr; ++i) {\n      var f = nbhd[i]\n      if(parity[f] >= 0) {\n        continue\n      }\n      parity[f] = p^1\n      toVisit.push(f)\n      if(p === 0) {\n        var c = faces[f]\n        if(!sharedBoundary(c)) {\n          c.reverse()\n          polyline.push(c)\n        }\n      }\n    }\n    if(p === 0) {\n      result.push(polyline)\n    }\n  }\n\n  return result\n}\n},{\"./lib/trim-leaves\":467,\"edges-to-adjacency-list\":171,\"planar-dual\":466,\"point-in-big-polygon\":472,\"robust-sum\":515,\"two-product\":543,\"uniq\":547}],469:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nmodule.exports = _dereq_('./quad')\r\n},{\"./quad\":471}],470:[function(_dereq_,module,exports){\narguments[4][111][0].apply(exports,arguments)\n},{\"dup\":111}],471:[function(_dereq_,module,exports){\n/**\r\n * @module  point-cluster/quad\r\n *\r\n * Bucket based quad tree clustering\r\n */\r\n\r\n'use strict'\r\n\r\nvar search = _dereq_('binary-search-bounds')\r\nvar clamp = _dereq_('clamp')\r\nvar rect = _dereq_('parse-rect')\r\nvar getBounds = _dereq_('array-bounds')\r\nvar pick = _dereq_('pick-by-alias')\r\nvar defined = _dereq_('defined')\r\nvar flatten = _dereq_('flatten-vertex-data')\r\nvar isObj = _dereq_('is-obj')\r\nvar dtype = _dereq_('dtype')\r\nvar log2 = _dereq_('math-log2')\r\n\r\n\r\nmodule.exports = function cluster (srcPoints, options) {\r\n\tif (!options) { options = {} }\r\n\r\n\tsrcPoints = flatten(srcPoints, 'float64')\r\n\r\n\toptions = pick(options, {\r\n\t\tbounds: 'range bounds dataBox databox',\r\n\t\tmaxDepth: 'depth maxDepth maxdepth level maxLevel maxlevel levels',\r\n\t\tdtype: 'type dtype format out dst output destination'\r\n\t\t// sort: 'sortBy sortby sort',\r\n\t\t// pick: 'pick levelPoint',\r\n\t\t// nodeSize: 'node nodeSize minNodeSize minSize size'\r\n\t})\r\n\r\n\t// let nodeSize = defined(options.nodeSize, 1)\r\n\tvar maxDepth = defined(options.maxDepth, 255)\r\n\tvar bounds = defined(options.bounds, getBounds(srcPoints, 2))\r\n\tif (bounds[0] === bounds[2]) { bounds[2]++ }\r\n\tif (bounds[1] === bounds[3]) { bounds[3]++ }\r\n\r\n\tvar points = normalize(srcPoints, bounds)\r\n\r\n\t// init variables\r\n\tvar n = srcPoints.length >>> 1\r\n\tvar ids\r\n\tif (!options.dtype) { options.dtype = 'array' }\r\n\r\n\tif (typeof options.dtype === 'string') {\r\n\t\tids = new (dtype(options.dtype))(n)\r\n\t}\r\n\telse if (options.dtype) {\r\n\t\tids = options.dtype\r\n\t\tif (Array.isArray(ids)) { ids.length = n }\r\n\t}\r\n\tfor (var i = 0; i < n; ++i) {\r\n\t\tids[i] = i\r\n\t}\r\n\r\n\t// point indexes for levels [0: [a,b,c,d], 1: [a,b,c,d,e,f,...], ...]\r\n\tvar levels = []\r\n\r\n\t// starting indexes of subranges in sub levels, levels.length * 4\r\n\tvar sublevels = []\r\n\r\n\t// unique group ids, sorted in z-curve fashion within levels\r\n\tvar groups = []\r\n\r\n\t// level offsets in `ids`\r\n\tvar offsets = []\r\n\r\n\r\n\t// sort points\r\n\tsort(0, 0, 1, ids, 0, 1)\r\n\r\n\r\n\t// return reordered ids with provided methods\r\n\t// save level offsets in output buffer\r\n\tvar offset = 0\r\n\tfor (var level = 0; level < levels.length; level++) {\r\n\t\tvar levelItems = levels[level]\r\n\t\tif (ids.set) { ids.set(levelItems, offset) }\r\n\t\telse {\r\n\t\t\tfor (var i$1 = 0, l = levelItems.length; i$1 < l; i$1++) {\r\n\t\t\t\tids[i$1 + offset] = levelItems[i$1]\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar nextOffset = offset + levels[level].length\r\n\t\toffsets[level] = [offset, nextOffset]\r\n\t\toffset = nextOffset\r\n\t}\r\n\r\n\tids.range = range\r\n\r\n\treturn ids\r\n\r\n\r\n\r\n\t// FIXME: it is possible to create one typed array heap and reuse that to avoid memory blow\r\n\tfunction sort (x, y, diam, ids, level, group) {\r\n\t\tif (!ids.length) { return null }\r\n\r\n\t\t// save first point as level representative\r\n\t\tvar levelItems = levels[level] || (levels[level] = [])\r\n\t\tvar levelGroups = groups[level] || (groups[level] = [])\r\n\t\tvar sublevel = sublevels[level] || (sublevels[level] = [])\r\n\t\tvar offset = levelItems.length\r\n\r\n\t\tlevel++\r\n\r\n\t\t// max depth reached - put all items into a first group\r\n\t\tif (level > maxDepth) {\r\n\t\t\tfor (var i = 0; i < ids.length; i++) {\r\n\t\t\t\tlevelItems.push(ids[i])\r\n\t\t\t\tlevelGroups.push(group)\r\n\t\t\t\tsublevel.push(null, null, null, null)\r\n\t\t\t}\r\n\r\n\t\t\treturn offset\r\n\t\t}\r\n\r\n\t\tlevelItems.push(ids[0])\r\n\t\tlevelGroups.push(group)\r\n\r\n\t\tif (ids.length <= 1) {\r\n\t\t\tsublevel.push(null, null, null, null)\r\n\t\t\treturn offset\r\n\t\t}\r\n\r\n\r\n\t\tvar d2 = diam * .5\r\n\t\tvar cx = x + d2, cy = y + d2\r\n\r\n\t\t// distribute points by 4 buckets\r\n\t\tvar lolo = [], lohi = [], hilo = [], hihi = []\r\n\r\n\t\tfor (var i$1 = 1, l = ids.length; i$1 < l; i$1++) {\r\n\t\t\tvar idx = ids[i$1],\r\n\t\t\t\tx$1 = points[idx * 2],\r\n\t\t\t\ty$1 = points[idx * 2 + 1]\r\n\t\t\tx$1 < cx ? (y$1 < cy ? lolo.push(idx) : lohi.push(idx)) : (y$1 < cy ? hilo.push(idx) : hihi.push(idx))\r\n\t\t}\r\n\r\n\t\tgroup <<= 2\r\n\t\tsublevel.push(\r\n\t\t\tsort(x, y, d2, lolo, level, group),\r\n\t\t\tsort(x, cy, d2, lohi, level, group + 1),\r\n\t\t\tsort(cx, y, d2, hilo, level, group + 2),\r\n\t\t\tsort(cx, cy, d2, hihi, level, group + 3)\r\n\t\t)\r\n\r\n\t\treturn offset\r\n\t}\r\n\r\n\t// get all points within the passed range\r\n\tfunction range () {\n\t\tvar args = [], len = arguments.length;\n\t\twhile ( len-- ) args[ len ] = arguments[ len ];\n\r\n\t\tvar options\r\n\r\n\t\tif (isObj(args[args.length - 1])) {\r\n\t\t\tvar arg = args.pop()\r\n\r\n\t\t\t// detect if that was a rect object\r\n\t\t\tif (!args.length && (arg.x != null || arg.l != null || arg.left != null)) {\r\n\t\t\t\targs = [arg]\r\n\t\t\t\toptions = {}\r\n\t\t\t}\r\n\r\n\t\t\toptions = pick(arg, {\r\n\t\t\t\tlevel: 'level maxLevel',\r\n\t\t\t\td: 'd diam diameter r radius px pxSize pixel pixelSize maxD size minSize',\r\n\t\t\t\tlod: 'lod details ranges offsets'\r\n\t\t\t})\r\n\t\t}\r\n\t\telse {\r\n\t\t\toptions = {}\r\n\t\t}\r\n\r\n\t\tif (!args.length) { args = bounds }\r\n\r\n\t\tvar box = rect.apply( void 0, args )\r\n\r\n\t\tvar ref = [\r\n\t\t\tMath.min(box.x, box.x + box.width),\r\n\t\t\tMath.min(box.y, box.y + box.height),\r\n\t\t\tMath.max(box.x, box.x + box.width),\r\n\t\t\tMath.max(box.y, box.y + box.height)\r\n\t\t];\n\t\tvar minX = ref[0];\n\t\tvar minY = ref[1];\n\t\tvar maxX = ref[2];\n\t\tvar maxY = ref[3];\r\n\r\n\t\tvar ref$1 = normalize([minX, minY, maxX, maxY], bounds );\n\t\tvar nminX = ref$1[0];\n\t\tvar nminY = ref$1[1];\n\t\tvar nmaxX = ref$1[2];\n\t\tvar nmaxY = ref$1[3];\r\n\r\n\t\tvar maxLevel = defined(options.level, levels.length)\r\n\r\n\t\t// limit maxLevel by px size\r\n\t\tif (options.d != null) {\r\n\t\t\tvar d\r\n\t\t\tif (typeof options.d === 'number') { d = [options.d, options.d] }\r\n\t\t\telse if (options.d.length) { d = options.d }\r\n\r\n\t\t\tmaxLevel = Math.min(\r\n\t\t\t\tMath.max(\r\n\t\t\t\t\tMath.ceil(-log2(Math.abs(d[0]) / (bounds[2] - bounds[0]))),\r\n\t\t\t\t\tMath.ceil(-log2(Math.abs(d[1]) / (bounds[3] - bounds[1])))\r\n\t\t\t\t),\r\n\t\t\t\tmaxLevel\r\n\t\t\t)\r\n\t\t}\r\n\t\tmaxLevel = Math.min(maxLevel, levels.length)\r\n\r\n\t\t// return levels of details\r\n\t\tif (options.lod) {\r\n\t\t\treturn lod(nminX, nminY, nmaxX, nmaxY, maxLevel)\r\n\t\t}\r\n\r\n\r\n\r\n\t\t// do selection ids\r\n\t\tvar selection = []\r\n\r\n\t\t// FIXME: probably we can do LOD here beforehead\r\n\t\tselect( 0, 0, 1, 0, 0, 1)\r\n\r\n\t\tfunction select ( lox, loy, d, level, from, to ) {\r\n\t\t\tif (from === null || to === null) { return }\r\n\r\n\t\t\tvar hix = lox + d\r\n\t\t\tvar hiy = loy + d\r\n\r\n\t\t\t// if box does not intersect level - ignore\r\n\t\t\tif ( nminX > hix || nminY > hiy || nmaxX < lox || nmaxY < loy ) { return }\r\n\t\t\tif ( level >= maxLevel ) { return }\r\n\t\t\tif ( from === to ) { return }\r\n\r\n\t\t\t// if points fall into box range - take it\r\n\t\t\tvar levelItems = levels[level]\r\n\r\n\t\t\tif (to === undefined) { to = levelItems.length }\r\n\r\n\t\t\tfor (var i = from; i < to; i++) {\r\n\t\t\t\tvar id = levelItems[i]\r\n\r\n\t\t\t\tvar px = srcPoints[ id * 2 ]\r\n\t\t\t\tvar py = srcPoints[ id * 2 + 1 ]\r\n\r\n\t\t\t\tif ( px >= minX && px <= maxX && py >= minY && py <= maxY ) {selection.push(id)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// for every subsection do select\r\n\t\t\tvar offsets = sublevels[ level ]\r\n\t\t\tvar off0 = offsets[ from * 4 + 0 ]\r\n\t\t\tvar off1 = offsets[ from * 4 + 1 ]\r\n\t\t\tvar off2 = offsets[ from * 4 + 2 ]\r\n\t\t\tvar off3 = offsets[ from * 4 + 3 ]\r\n\t\t\tvar end = nextOffset(offsets, from + 1)\r\n\r\n\t\t\tvar d2 = d * .5\r\n\t\t\tvar nextLevel = level + 1\r\n\t\t\tselect( lox, loy, d2, nextLevel, off0, off1 || off2 || off3 || end)\r\n\t\t\tselect( lox, loy + d2, d2, nextLevel, off1, off2 || off3 || end)\r\n\t\t\tselect( lox + d2, loy, d2, nextLevel, off2, off3 || end)\r\n\t\t\tselect( lox + d2, loy + d2, d2, nextLevel, off3, end)\r\n\t\t}\r\n\r\n\t\tfunction nextOffset(offsets, from) {\r\n\t\t\tvar offset = null, i = 0\r\n\t\t\twhile(offset === null) {\r\n\t\t\t\toffset = offsets[ from * 4 + i ]\r\n\t\t\t\ti++\r\n\t\t\t\tif (i > offsets.length) { return null }\r\n\t\t\t}\r\n\t\t\treturn offset\r\n\t\t}\r\n\r\n\t\treturn selection\r\n\t}\r\n\r\n\t// get range offsets within levels to render lods appropriate for zoom level\r\n\t// TODO: it is possible to store minSize of a point to optimize neede level calc\r\n\tfunction lod (lox, loy, hix, hiy, maxLevel) {\r\n\t\tvar ranges = []\r\n\r\n\t\tfor (var level = 0; level < maxLevel; level++) {\r\n\t\t\tvar levelGroups = groups[level]\r\n\t\t\tvar from = offsets[level][0]\r\n\r\n\t\t\tvar levelGroupStart = group(lox, loy, level)\r\n\t\t\tvar levelGroupEnd = group(hix, hiy, level)\r\n\r\n\t\t\t// FIXME: utilize sublevels to speed up search range here\r\n\t\t\tvar startOffset = search.ge(levelGroups, levelGroupStart)\r\n\t\t\tvar endOffset = search.gt(levelGroups, levelGroupEnd, startOffset, levelGroups.length - 1)\r\n\r\n\t\t\tranges[level] = [startOffset + from, endOffset + from]\r\n\t\t}\r\n\r\n\t\treturn ranges\r\n\t}\r\n\r\n\t// get group id closest to the x,y coordinate, corresponding to a level\r\n\tfunction group (x, y, level) {\r\n\t\tvar group = 1\r\n\r\n\t\tvar cx = .5, cy = .5\r\n\t\tvar diam = .5\r\n\r\n\t\tfor (var i = 0; i < level; i++) {\r\n\t\t\tgroup <<= 2\r\n\r\n\t\t\tgroup += x < cx ? (y < cy ? 0 : 1) : (y < cy ? 2 : 3)\r\n\r\n\t\t\tdiam *= .5\r\n\r\n\t\t\tcx += x < cx ? -diam : diam\r\n\t\t\tcy += y < cy ? -diam : diam\r\n\t\t}\r\n\r\n\t\treturn group\r\n\t}\r\n}\r\n\r\n\r\n// normalize points by bounds\r\nfunction normalize (pts, bounds) {\r\n\tvar lox = bounds[0];\n\tvar loy = bounds[1];\n\tvar hix = bounds[2];\n\tvar hiy = bounds[3];\r\n\tvar scaleX = 1.0 / (hix - lox)\r\n\tvar scaleY = 1.0 / (hiy - loy)\r\n\tvar result = new Array(pts.length)\r\n\r\n\tfor (var i = 0, n = pts.length / 2; i < n; i++) {\r\n\t\tresult[2*i] = clamp((pts[2*i] - lox) * scaleX, 0, 1)\r\n\t\tresult[2*i+1] = clamp((pts[2*i+1] - loy) * scaleY, 0, 1)\r\n\t}\r\n\r\n\treturn result\r\n}\r\n},{\"array-bounds\":65,\"binary-search-bounds\":470,\"clamp\":115,\"defined\":164,\"dtype\":169,\"flatten-vertex-data\":227,\"is-obj\":421,\"math-log2\":432,\"parse-rect\":459,\"pick-by-alias\":465}],472:[function(_dereq_,module,exports){\nmodule.exports = preprocessPolygon\n\nvar orient = _dereq_('robust-orientation')[3]\nvar makeSlabs = _dereq_('slab-decomposition')\nvar makeIntervalTree = _dereq_('interval-tree-1d')\nvar bsearch = _dereq_('binary-search-bounds')\n\nfunction visitInterval() {\n  return true\n}\n\nfunction intervalSearch(table) {\n  return function(x, y) {\n    var tree = table[x]\n    if(tree) {\n      return !!tree.queryPoint(y, visitInterval)\n    }\n    return false\n  }\n}\n\nfunction buildVerticalIndex(segments) {\n  var table = {}\n  for(var i=0; i<segments.length; ++i) {\n    var s = segments[i]\n    var x = s[0][0]\n    var y0 = s[0][1]\n    var y1 = s[1][1]\n    var p = [ Math.min(y0, y1), Math.max(y0, y1) ]\n    if(x in table) {\n      table[x].push(p)\n    } else {\n      table[x] = [ p ]\n    }\n  }\n  var intervalTable = {}\n  var keys = Object.keys(table)\n  for(var i=0; i<keys.length; ++i) {\n    var segs = table[keys[i]]\n    intervalTable[keys[i]] = makeIntervalTree(segs)\n  }\n  return intervalSearch(intervalTable)\n}\n\nfunction buildSlabSearch(slabs, coordinates) {\n  return function(p) {\n    var bucket = bsearch.le(coordinates, p[0])\n    if(bucket < 0) {\n      return 1\n    }\n    var root = slabs[bucket]\n    if(!root) {\n      if(bucket > 0 && coordinates[bucket] === p[0]) {\n        root = slabs[bucket-1]\n      } else {\n        return 1\n      }\n    }\n    var lastOrientation = 1\n    while(root) {\n      var s = root.key\n      var o = orient(p, s[0], s[1])\n      if(s[0][0] < s[1][0]) {\n        if(o < 0) {\n          root = root.left\n        } else if(o > 0) {\n          lastOrientation = -1\n          root = root.right\n        } else {\n          return 0\n        }\n      } else {\n        if(o > 0) {\n          root = root.left\n        } else if(o < 0) {\n          lastOrientation = 1\n          root = root.right\n        } else {\n          return 0\n        }\n      }\n    }\n    return lastOrientation\n  }\n}\n\nfunction classifyEmpty(p) {\n  return 1\n}\n\nfunction createClassifyVertical(testVertical) {\n  return function classify(p) {\n    if(testVertical(p[0], p[1])) {\n      return 0\n    }\n    return 1\n  }\n}\n\nfunction createClassifyPointDegen(testVertical, testNormal) {\n  return function classify(p) {\n    if(testVertical(p[0], p[1])) {\n      return 0\n    }\n    return testNormal(p)\n  }\n}\n\nfunction preprocessPolygon(loops) {\n  //Compute number of loops\n  var numLoops = loops.length\n\n  //Unpack segments\n  var segments = []\n  var vsegments = []\n  var ptr = 0\n  for(var i=0; i<numLoops; ++i) {\n    var loop = loops[i]\n    var numVertices = loop.length\n    for(var s=numVertices-1,t=0; t<numVertices; s=(t++)) {\n      var a = loop[s]\n      var b = loop[t]\n      if(a[0] === b[0]) {\n        vsegments.push([a,b])\n      } else {\n        segments.push([a,b])\n      }\n    }\n  }\n\n  //Degenerate case: All loops are empty\n  if(segments.length === 0) {\n    if(vsegments.length === 0) {\n      return classifyEmpty\n    } else {\n      return createClassifyVertical(buildVerticalIndex(vsegments))\n    }\n  }\n\n  //Build slab decomposition\n  var slabs = makeSlabs(segments)\n  var testSlab = buildSlabSearch(slabs.slabs, slabs.coordinates)\n\n  if(vsegments.length === 0) {\n    return testSlab\n  } else {\n    return createClassifyPointDegen(\n      buildVerticalIndex(vsegments),\n      testSlab)\n  }\n}\n},{\"binary-search-bounds\":91,\"interval-tree-1d\":414,\"robust-orientation\":510,\"slab-decomposition\":526}],473:[function(_dereq_,module,exports){\n/*\n * @copyright 2016 Sean Connelly (@voidqk), http://syntheti.cc\n * @license MIT\n * @preserve Project Home: https://github.com/voidqk/polybooljs\n */\n\nvar BuildLog = _dereq_('./lib/build-log');\nvar Epsilon = _dereq_('./lib/epsilon');\nvar Intersecter = _dereq_('./lib/intersecter');\nvar SegmentChainer = _dereq_('./lib/segment-chainer');\nvar SegmentSelector = _dereq_('./lib/segment-selector');\nvar GeoJSON = _dereq_('./lib/geojson');\n\nvar buildLog = false;\nvar epsilon = Epsilon();\n\nvar PolyBool;\nPolyBool = {\n\t// getter/setter for buildLog\n\tbuildLog: function(bl){\n\t\tif (bl === true)\n\t\t\tbuildLog = BuildLog();\n\t\telse if (bl === false)\n\t\t\tbuildLog = false;\n\t\treturn buildLog === false ? false : buildLog.list;\n\t},\n\t// getter/setter for epsilon\n\tepsilon: function(v){\n\t\treturn epsilon.epsilon(v);\n\t},\n\n\t// core API\n\tsegments: function(poly){\n\t\tvar i = Intersecter(true, epsilon, buildLog);\n\t\tpoly.regions.forEach(i.addRegion);\n\t\treturn {\n\t\t\tsegments: i.calculate(poly.inverted),\n\t\t\tinverted: poly.inverted\n\t\t};\n\t},\n\tcombine: function(segments1, segments2){\n\t\tvar i3 = Intersecter(false, epsilon, buildLog);\n\t\treturn {\n\t\t\tcombined: i3.calculate(\n\t\t\t\tsegments1.segments, segments1.inverted,\n\t\t\t\tsegments2.segments, segments2.inverted\n\t\t\t),\n\t\t\tinverted1: segments1.inverted,\n\t\t\tinverted2: segments2.inverted\n\t\t};\n\t},\n\tselectUnion: function(combined){\n\t\treturn {\n\t\t\tsegments: SegmentSelector.union(combined.combined, buildLog),\n\t\t\tinverted: combined.inverted1 || combined.inverted2\n\t\t}\n\t},\n\tselectIntersect: function(combined){\n\t\treturn {\n\t\t\tsegments: SegmentSelector.intersect(combined.combined, buildLog),\n\t\t\tinverted: combined.inverted1 && combined.inverted2\n\t\t}\n\t},\n\tselectDifference: function(combined){\n\t\treturn {\n\t\t\tsegments: SegmentSelector.difference(combined.combined, buildLog),\n\t\t\tinverted: combined.inverted1 && !combined.inverted2\n\t\t}\n\t},\n\tselectDifferenceRev: function(combined){\n\t\treturn {\n\t\t\tsegments: SegmentSelector.differenceRev(combined.combined, buildLog),\n\t\t\tinverted: !combined.inverted1 && combined.inverted2\n\t\t}\n\t},\n\tselectXor: function(combined){\n\t\treturn {\n\t\t\tsegments: SegmentSelector.xor(combined.combined, buildLog),\n\t\t\tinverted: combined.inverted1 !== combined.inverted2\n\t\t}\n\t},\n\tpolygon: function(segments){\n\t\treturn {\n\t\t\tregions: SegmentChainer(segments.segments, epsilon, buildLog),\n\t\t\tinverted: segments.inverted\n\t\t};\n\t},\n\n\t// GeoJSON converters\n\tpolygonFromGeoJSON: function(geojson){\n\t\treturn GeoJSON.toPolygon(PolyBool, geojson);\n\t},\n\tpolygonToGeoJSON: function(poly){\n\t\treturn GeoJSON.fromPolygon(PolyBool, epsilon, poly);\n\t},\n\n\t// helper functions for common operations\n\tunion: function(poly1, poly2){\n\t\treturn operate(poly1, poly2, PolyBool.selectUnion);\n\t},\n\tintersect: function(poly1, poly2){\n\t\treturn operate(poly1, poly2, PolyBool.selectIntersect);\n\t},\n\tdifference: function(poly1, poly2){\n\t\treturn operate(poly1, poly2, PolyBool.selectDifference);\n\t},\n\tdifferenceRev: function(poly1, poly2){\n\t\treturn operate(poly1, poly2, PolyBool.selectDifferenceRev);\n\t},\n\txor: function(poly1, poly2){\n\t\treturn operate(poly1, poly2, PolyBool.selectXor);\n\t}\n};\n\nfunction operate(poly1, poly2, selector){\n\tvar seg1 = PolyBool.segments(poly1);\n\tvar seg2 = PolyBool.segments(poly2);\n\tvar comb = PolyBool.combine(seg1, seg2);\n\tvar seg3 = selector(comb);\n\treturn PolyBool.polygon(seg3);\n}\n\nif (typeof window === 'object')\n\twindow.PolyBool = PolyBool;\n\nmodule.exports = PolyBool;\n\n},{\"./lib/build-log\":474,\"./lib/epsilon\":475,\"./lib/geojson\":476,\"./lib/intersecter\":477,\"./lib/segment-chainer\":479,\"./lib/segment-selector\":480}],474:[function(_dereq_,module,exports){\n// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc\n// MIT License\n// Project Home: https://github.com/voidqk/polybooljs\n\n//\n// used strictly for logging the processing of the algorithm... only useful if you intend on\n// looking under the covers (for pretty UI's or debugging)\n//\n\nfunction BuildLog(){\n\tvar my;\n\tvar nextSegmentId = 0;\n\tvar curVert = false;\n\n\tfunction push(type, data){\n\t\tmy.list.push({\n\t\t\ttype: type,\n\t\t\tdata: data ? JSON.parse(JSON.stringify(data)) : void 0\n\t\t});\n\t\treturn my;\n\t}\n\n\tmy = {\n\t\tlist: [],\n\t\tsegmentId: function(){\n\t\t\treturn nextSegmentId++;\n\t\t},\n\t\tcheckIntersection: function(seg1, seg2){\n\t\t\treturn push('check', { seg1: seg1, seg2: seg2 });\n\t\t},\n\t\tsegmentChop: function(seg, end){\n\t\t\tpush('div_seg', { seg: seg, pt: end });\n\t\t\treturn push('chop', { seg: seg, pt: end });\n\t\t},\n\t\tstatusRemove: function(seg){\n\t\t\treturn push('pop_seg', { seg: seg });\n\t\t},\n\t\tsegmentUpdate: function(seg){\n\t\t\treturn push('seg_update', { seg: seg });\n\t\t},\n\t\tsegmentNew: function(seg, primary){\n\t\t\treturn push('new_seg', { seg: seg, primary: primary });\n\t\t},\n\t\tsegmentRemove: function(seg){\n\t\t\treturn push('rem_seg', { seg: seg });\n\t\t},\n\t\ttempStatus: function(seg, above, below){\n\t\t\treturn push('temp_status', { seg: seg, above: above, below: below });\n\t\t},\n\t\trewind: function(seg){\n\t\t\treturn push('rewind', { seg: seg });\n\t\t},\n\t\tstatus: function(seg, above, below){\n\t\t\treturn push('status', { seg: seg, above: above, below: below });\n\t\t},\n\t\tvert: function(x){\n\t\t\tif (x === curVert)\n\t\t\t\treturn my;\n\t\t\tcurVert = x;\n\t\t\treturn push('vert', { x: x });\n\t\t},\n\t\tlog: function(data){\n\t\t\tif (typeof data !== 'string')\n\t\t\t\tdata = JSON.stringify(data, false, '  ');\n\t\t\treturn push('log', { txt: data });\n\t\t},\n\t\treset: function(){\n\t\t\treturn push('reset');\n\t\t},\n\t\tselected: function(segs){\n\t\t\treturn push('selected', { segs: segs });\n\t\t},\n\t\tchainStart: function(seg){\n\t\t\treturn push('chain_start', { seg: seg });\n\t\t},\n\t\tchainRemoveHead: function(index, pt){\n\t\t\treturn push('chain_rem_head', { index: index, pt: pt });\n\t\t},\n\t\tchainRemoveTail: function(index, pt){\n\t\t\treturn push('chain_rem_tail', { index: index, pt: pt });\n\t\t},\n\t\tchainNew: function(pt1, pt2){\n\t\t\treturn push('chain_new', { pt1: pt1, pt2: pt2 });\n\t\t},\n\t\tchainMatch: function(index){\n\t\t\treturn push('chain_match', { index: index });\n\t\t},\n\t\tchainClose: function(index){\n\t\t\treturn push('chain_close', { index: index });\n\t\t},\n\t\tchainAddHead: function(index, pt){\n\t\t\treturn push('chain_add_head', { index: index, pt: pt });\n\t\t},\n\t\tchainAddTail: function(index, pt){\n\t\t\treturn push('chain_add_tail', { index: index, pt: pt, });\n\t\t},\n\t\tchainConnect: function(index1, index2){\n\t\t\treturn push('chain_con', { index1: index1, index2: index2 });\n\t\t},\n\t\tchainReverse: function(index){\n\t\t\treturn push('chain_rev', { index: index });\n\t\t},\n\t\tchainJoin: function(index1, index2){\n\t\t\treturn push('chain_join', { index1: index1, index2: index2 });\n\t\t},\n\t\tdone: function(){\n\t\t\treturn push('done');\n\t\t}\n\t};\n\treturn my;\n}\n\nmodule.exports = BuildLog;\n\n},{}],475:[function(_dereq_,module,exports){\n// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc\n// MIT License\n// Project Home: https://github.com/voidqk/polybooljs\n\n//\n// provides the raw computation functions that takes epsilon into account\n//\n// zero is defined to be between (-epsilon, epsilon) exclusive\n//\n\nfunction Epsilon(eps){\n\tif (typeof eps !== 'number')\n\t\teps = 0.0000000001; // sane default? sure why not\n\tvar my = {\n\t\tepsilon: function(v){\n\t\t\tif (typeof v === 'number')\n\t\t\t\teps = v;\n\t\t\treturn eps;\n\t\t},\n\t\tpointAboveOrOnLine: function(pt, left, right){\n\t\t\tvar Ax = left[0];\n\t\t\tvar Ay = left[1];\n\t\t\tvar Bx = right[0];\n\t\t\tvar By = right[1];\n\t\t\tvar Cx = pt[0];\n\t\t\tvar Cy = pt[1];\n\t\t\treturn (Bx - Ax) * (Cy - Ay) - (By - Ay) * (Cx - Ax) >= -eps;\n\t\t},\n\t\tpointBetween: function(p, left, right){\n\t\t\t// p must be collinear with left->right\n\t\t\t// returns false if p == left, p == right, or left == right\n\t\t\tvar d_py_ly = p[1] - left[1];\n\t\t\tvar d_rx_lx = right[0] - left[0];\n\t\t\tvar d_px_lx = p[0] - left[0];\n\t\t\tvar d_ry_ly = right[1] - left[1];\n\n\t\t\tvar dot = d_px_lx * d_rx_lx + d_py_ly * d_ry_ly;\n\t\t\t// if `dot` is 0, then `p` == `left` or `left` == `right` (reject)\n\t\t\t// if `dot` is less than 0, then `p` is to the left of `left` (reject)\n\t\t\tif (dot < eps)\n\t\t\t\treturn false;\n\n\t\t\tvar sqlen = d_rx_lx * d_rx_lx + d_ry_ly * d_ry_ly;\n\t\t\t// if `dot` > `sqlen`, then `p` is to the right of `right` (reject)\n\t\t\t// therefore, if `dot - sqlen` is greater than 0, then `p` is to the right of `right` (reject)\n\t\t\tif (dot - sqlen > -eps)\n\t\t\t\treturn false;\n\n\t\t\treturn true;\n\t\t},\n\t\tpointsSameX: function(p1, p2){\n\t\t\treturn Math.abs(p1[0] - p2[0]) < eps;\n\t\t},\n\t\tpointsSameY: function(p1, p2){\n\t\t\treturn Math.abs(p1[1] - p2[1]) < eps;\n\t\t},\n\t\tpointsSame: function(p1, p2){\n\t\t\treturn my.pointsSameX(p1, p2) && my.pointsSameY(p1, p2);\n\t\t},\n\t\tpointsCompare: function(p1, p2){\n\t\t\t// returns -1 if p1 is smaller, 1 if p2 is smaller, 0 if equal\n\t\t\tif (my.pointsSameX(p1, p2))\n\t\t\t\treturn my.pointsSameY(p1, p2) ? 0 : (p1[1] < p2[1] ? -1 : 1);\n\t\t\treturn p1[0] < p2[0] ? -1 : 1;\n\t\t},\n\t\tpointsCollinear: function(pt1, pt2, pt3){\n\t\t\t// does pt1->pt2->pt3 make a straight line?\n\t\t\t// essentially this is just checking to see if the slope(pt1->pt2) === slope(pt2->pt3)\n\t\t\t// if slopes are equal, then they must be collinear, because they share pt2\n\t\t\tvar dx1 = pt1[0] - pt2[0];\n\t\t\tvar dy1 = pt1[1] - pt2[1];\n\t\t\tvar dx2 = pt2[0] - pt3[0];\n\t\t\tvar dy2 = pt2[1] - pt3[1];\n\t\t\treturn Math.abs(dx1 * dy2 - dx2 * dy1) < eps;\n\t\t},\n\t\tlinesIntersect: function(a0, a1, b0, b1){\n\t\t\t// returns false if the lines are coincident (e.g., parallel or on top of each other)\n\t\t\t//\n\t\t\t// returns an object if the lines intersect:\n\t\t\t//   {\n\t\t\t//     pt: [x, y],    where the intersection point is at\n\t\t\t//     alongA: where intersection point is along A,\n\t\t\t//     alongB: where intersection point is along B\n\t\t\t//   }\n\t\t\t//\n\t\t\t//  alongA and alongB will each be one of: -2, -1, 0, 1, 2\n\t\t\t//\n\t\t\t//  with the following meaning:\n\t\t\t//\n\t\t\t//    -2   intersection point is before segment's first point\n\t\t\t//    -1   intersection point is directly on segment's first point\n\t\t\t//     0   intersection point is between segment's first and second points (exclusive)\n\t\t\t//     1   intersection point is directly on segment's second point\n\t\t\t//     2   intersection point is after segment's second point\n\t\t\tvar adx = a1[0] - a0[0];\n\t\t\tvar ady = a1[1] - a0[1];\n\t\t\tvar bdx = b1[0] - b0[0];\n\t\t\tvar bdy = b1[1] - b0[1];\n\n\t\t\tvar axb = adx * bdy - ady * bdx;\n\t\t\tif (Math.abs(axb) < eps)\n\t\t\t\treturn false; // lines are coincident\n\n\t\t\tvar dx = a0[0] - b0[0];\n\t\t\tvar dy = a0[1] - b0[1];\n\n\t\t\tvar A = (bdx * dy - bdy * dx) / axb;\n\t\t\tvar B = (adx * dy - ady * dx) / axb;\n\n\t\t\tvar ret = {\n\t\t\t\talongA: 0,\n\t\t\t\talongB: 0,\n\t\t\t\tpt: [\n\t\t\t\t\ta0[0] + A * adx,\n\t\t\t\t\ta0[1] + A * ady\n\t\t\t\t]\n\t\t\t};\n\n\t\t\t// categorize where intersection point is along A and B\n\n\t\t\tif (A <= -eps)\n\t\t\t\tret.alongA = -2;\n\t\t\telse if (A < eps)\n\t\t\t\tret.alongA = -1;\n\t\t\telse if (A - 1 <= -eps)\n\t\t\t\tret.alongA = 0;\n\t\t\telse if (A - 1 < eps)\n\t\t\t\tret.alongA = 1;\n\t\t\telse\n\t\t\t\tret.alongA = 2;\n\n\t\t\tif (B <= -eps)\n\t\t\t\tret.alongB = -2;\n\t\t\telse if (B < eps)\n\t\t\t\tret.alongB = -1;\n\t\t\telse if (B - 1 <= -eps)\n\t\t\t\tret.alongB = 0;\n\t\t\telse if (B - 1 < eps)\n\t\t\t\tret.alongB = 1;\n\t\t\telse\n\t\t\t\tret.alongB = 2;\n\n\t\t\treturn ret;\n\t\t},\n\t\tpointInsideRegion: function(pt, region){\n\t\t\tvar x = pt[0];\n\t\t\tvar y = pt[1];\n\t\t\tvar last_x = region[region.length - 1][0];\n\t\t\tvar last_y = region[region.length - 1][1];\n\t\t\tvar inside = false;\n\t\t\tfor (var i = 0; i < region.length; i++){\n\t\t\t\tvar curr_x = region[i][0];\n\t\t\t\tvar curr_y = region[i][1];\n\n\t\t\t\t// if y is between curr_y and last_y, and\n\t\t\t\t// x is to the right of the boundary created by the line\n\t\t\t\tif ((curr_y - y > eps) != (last_y - y > eps) &&\n\t\t\t\t\t(last_x - curr_x) * (y - curr_y) / (last_y - curr_y) + curr_x - x > eps)\n\t\t\t\t\tinside = !inside\n\n\t\t\t\tlast_x = curr_x;\n\t\t\t\tlast_y = curr_y;\n\t\t\t}\n\t\t\treturn inside;\n\t\t}\n\t};\n\treturn my;\n}\n\nmodule.exports = Epsilon;\n\n},{}],476:[function(_dereq_,module,exports){\n// (c) Copyright 2017, Sean Connelly (@voidqk), http://syntheti.cc\n// MIT License\n// Project Home: https://github.com/voidqk/polybooljs\n\n//\n// convert between PolyBool polygon format and GeoJSON formats (Polygon and MultiPolygon)\n//\n\nvar GeoJSON = {\n\t// convert a GeoJSON object to a PolyBool polygon\n\ttoPolygon: function(PolyBool, geojson){\n\n\t\t// converts list of LineString's to segments\n\t\tfunction GeoPoly(coords){\n\t\t\t// check for empty coords\n\t\t\tif (coords.length <= 0)\n\t\t\t\treturn PolyBool.segments({ inverted: false, regions: [] });\n\n\t\t\t// convert LineString to segments\n\t\t\tfunction LineString(ls){\n\t\t\t\t// remove tail which should be the same as head\n\t\t\t\tvar reg = ls.slice(0, ls.length - 1);\n\t\t\t\treturn PolyBool.segments({ inverted: false, regions: [reg] });\n\t\t\t}\n\n\t\t\t// the first LineString is considered the outside\n\t\t\tvar out = LineString(coords[0]);\n\n\t\t\t// the rest of the LineStrings are considered interior holes, so subtract them from the\n\t\t\t// current result\n\t\t\tfor (var i = 1; i < coords.length; i++)\n\t\t\t\tout = PolyBool.selectDifference(PolyBool.combine(out, LineString(coords[i])));\n\n\t\t\treturn out;\n\t\t}\n\n\t\tif (geojson.type === 'Polygon'){\n\t\t\t// single polygon, so just convert it and we're done\n\t\t\treturn PolyBool.polygon(GeoPoly(geojson.coordinates));\n\t\t}\n\t\telse if (geojson.type === 'MultiPolygon'){\n\t\t\t// multiple polygons, so union all the polygons together\n\t\t\tvar out = PolyBool.segments({ inverted: false, regions: [] });\n\t\t\tfor (var i = 0; i < geojson.coordinates.length; i++)\n\t\t\t\tout = PolyBool.selectUnion(PolyBool.combine(out, GeoPoly(geojson.coordinates[i])));\n\t\t\treturn PolyBool.polygon(out);\n\t\t}\n\t\tthrow new Error('PolyBool: Cannot convert GeoJSON object to PolyBool polygon');\n\t},\n\n\t// convert a PolyBool polygon to a GeoJSON object\n\tfromPolygon: function(PolyBool, eps, poly){\n\t\t// make sure out polygon is clean\n\t\tpoly = PolyBool.polygon(PolyBool.segments(poly));\n\n\t\t// test if r1 is inside r2\n\t\tfunction regionInsideRegion(r1, r2){\n\t\t\t// we're guaranteed no lines intersect (because the polygon is clean), but a vertex\n\t\t\t// could be on the edge -- so we just average pt[0] and pt[1] to produce a point on the\n\t\t\t// edge of the first line, which cannot be on an edge\n\t\t\treturn eps.pointInsideRegion([\n\t\t\t\t(r1[0][0] + r1[1][0]) * 0.5,\n\t\t\t\t(r1[0][1] + r1[1][1]) * 0.5\n\t\t\t], r2);\n\t\t}\n\n\t\t// calculate inside heirarchy\n\t\t//\n\t\t//  _____________________   _______    roots -> A       -> F\n\t\t// |          A          | |   F   |            |          |\n\t\t// |  _______   _______  | |  ___  |            +-- B      +-- G\n\t\t// | |   B   | |   C   | | | |   | |            |   |\n\t\t// | |  ___  | |  ___  | | | |   | |            |   +-- D\n\t\t// | | | D | | | | E | | | | | G | |            |\n\t\t// | | |___| | | |___| | | | |   | |            +-- C\n\t\t// | |_______| |_______| | | |___| |                |\n\t\t// |_____________________| |_______|                +-- E\n\n\t\tfunction newNode(region){\n\t\t\treturn {\n\t\t\t\tregion: region,\n\t\t\t\tchildren: []\n\t\t\t};\n\t\t}\n\n\t\tvar roots = newNode(null);\n\n\t\tfunction addChild(root, region){\n\t\t\t// first check if we're inside any children\n\t\t\tfor (var i = 0; i < root.children.length; i++){\n\t\t\t\tvar child = root.children[i];\n\t\t\t\tif (regionInsideRegion(region, child.region)){\n\t\t\t\t\t// we are, so insert inside them instead\n\t\t\t\t\taddChild(child, region);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// not inside any children, so check to see if any children are inside us\n\t\t\tvar node = newNode(region);\n\t\t\tfor (var i = 0; i < root.children.length; i++){\n\t\t\t\tvar child = root.children[i];\n\t\t\t\tif (regionInsideRegion(child.region, region)){\n\t\t\t\t\t// oops... move the child beneath us, and remove them from root\n\t\t\t\t\tnode.children.push(child);\n\t\t\t\t\troot.children.splice(i, 1);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// now we can add ourselves\n\t\t\troot.children.push(node);\n\t\t}\n\n\t\t// add all regions to the root\n\t\tfor (var i = 0; i < poly.regions.length; i++){\n\t\t\tvar region = poly.regions[i];\n\t\t\tif (region.length < 3) // regions must have at least 3 points (sanity check)\n\t\t\t\tcontinue;\n\t\t\taddChild(roots, region);\n\t\t}\n\n\t\t// with our heirarchy, we can distinguish between exterior borders, and interior holes\n\t\t// the root nodes are exterior, children are interior, children's children are exterior,\n\t\t// children's children's children are interior, etc\n\n\t\t// while we're at it, exteriors are counter-clockwise, and interiors are clockwise\n\n\t\tfunction forceWinding(region, clockwise){\n\t\t\t// first, see if we're clockwise or counter-clockwise\n\t\t\t// https://en.wikipedia.org/wiki/Shoelace_formula\n\t\t\tvar winding = 0;\n\t\t\tvar last_x = region[region.length - 1][0];\n\t\t\tvar last_y = region[region.length - 1][1];\n\t\t\tvar copy = [];\n\t\t\tfor (var i = 0; i < region.length; i++){\n\t\t\t\tvar curr_x = region[i][0];\n\t\t\t\tvar curr_y = region[i][1];\n\t\t\t\tcopy.push([curr_x, curr_y]); // create a copy while we're at it\n\t\t\t\twinding += curr_y * last_x - curr_x * last_y;\n\t\t\t\tlast_x = curr_x;\n\t\t\t\tlast_y = curr_y;\n\t\t\t}\n\t\t\t// this assumes Cartesian coordinates (Y is positive going up)\n\t\t\tvar isclockwise = winding < 0;\n\t\t\tif (isclockwise !== clockwise)\n\t\t\t\tcopy.reverse();\n\t\t\t// while we're here, the last point must be the first point...\n\t\t\tcopy.push([copy[0][0], copy[0][1]]);\n\t\t\treturn copy;\n\t\t}\n\n\t\tvar geopolys = [];\n\n\t\tfunction addExterior(node){\n\t\t\tvar poly = [forceWinding(node.region, false)];\n\t\t\tgeopolys.push(poly);\n\t\t\t// children of exteriors are interior\n\t\t\tfor (var i = 0; i < node.children.length; i++)\n\t\t\t\tpoly.push(getInterior(node.children[i]));\n\t\t}\n\n\t\tfunction getInterior(node){\n\t\t\t// children of interiors are exterior\n\t\t\tfor (var i = 0; i < node.children.length; i++)\n\t\t\t\taddExterior(node.children[i]);\n\t\t\t// return the clockwise interior\n\t\t\treturn forceWinding(node.region, true);\n\t\t}\n\n\t\t// root nodes are exterior\n\t\tfor (var i = 0; i < roots.children.length; i++)\n\t\t\taddExterior(roots.children[i]);\n\n\t\t// lastly, construct the approrpriate GeoJSON object\n\n\t\tif (geopolys.length <= 0) // empty GeoJSON Polygon\n\t\t\treturn { type: 'Polygon', coordinates: [] };\n\t\tif (geopolys.length == 1) // use a GeoJSON Polygon\n\t\t\treturn { type: 'Polygon', coordinates: geopolys[0] };\n\t\treturn { // otherwise, use a GeoJSON MultiPolygon\n\t\t\ttype: 'MultiPolygon',\n\t\t\tcoordinates: geopolys\n\t\t};\n\t}\n};\n\nmodule.exports = GeoJSON;\n\n},{}],477:[function(_dereq_,module,exports){\n// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc\n// MIT License\n// Project Home: https://github.com/voidqk/polybooljs\n\n//\n// this is the core work-horse\n//\n\nvar LinkedList = _dereq_('./linked-list');\n\nfunction Intersecter(selfIntersection, eps, buildLog){\n\t// selfIntersection is true/false depending on the phase of the overall algorithm\n\n\t//\n\t// segment creation\n\t//\n\n\tfunction segmentNew(start, end){\n\t\treturn {\n\t\t\tid: buildLog ? buildLog.segmentId() : -1,\n\t\t\tstart: start,\n\t\t\tend: end,\n\t\t\tmyFill: {\n\t\t\t\tabove: null, // is there fill above us?\n\t\t\t\tbelow: null  // is there fill below us?\n\t\t\t},\n\t\t\totherFill: null\n\t\t};\n\t}\n\n\tfunction segmentCopy(start, end, seg){\n\t\treturn {\n\t\t\tid: buildLog ? buildLog.segmentId() : -1,\n\t\t\tstart: start,\n\t\t\tend: end,\n\t\t\tmyFill: {\n\t\t\t\tabove: seg.myFill.above,\n\t\t\t\tbelow: seg.myFill.below\n\t\t\t},\n\t\t\totherFill: null\n\t\t};\n\t}\n\n\t//\n\t// event logic\n\t//\n\n\tvar event_root = LinkedList.create();\n\n\tfunction eventCompare(p1_isStart, p1_1, p1_2, p2_isStart, p2_1, p2_2){\n\t\t// compare the selected points first\n\t\tvar comp = eps.pointsCompare(p1_1, p2_1);\n\t\tif (comp !== 0)\n\t\t\treturn comp;\n\t\t// the selected points are the same\n\n\t\tif (eps.pointsSame(p1_2, p2_2)) // if the non-selected points are the same too...\n\t\t\treturn 0; // then the segments are equal\n\n\t\tif (p1_isStart !== p2_isStart) // if one is a start and the other isn't...\n\t\t\treturn p1_isStart ? 1 : -1; // favor the one that isn't the start\n\n\t\t// otherwise, we'll have to calculate which one is below the other manually\n\t\treturn eps.pointAboveOrOnLine(p1_2,\n\t\t\tp2_isStart ? p2_1 : p2_2, // order matters\n\t\t\tp2_isStart ? p2_2 : p2_1\n\t\t) ? 1 : -1;\n\t}\n\n\tfunction eventAdd(ev, other_pt){\n\t\tevent_root.insertBefore(ev, function(here){\n\t\t\t// should ev be inserted before here?\n\t\t\tvar comp = eventCompare(\n\t\t\t\tev  .isStart, ev  .pt,      other_pt,\n\t\t\t\there.isStart, here.pt, here.other.pt\n\t\t\t);\n\t\t\treturn comp < 0;\n\t\t});\n\t}\n\n\tfunction eventAddSegmentStart(seg, primary){\n\t\tvar ev_start = LinkedList.node({\n\t\t\tisStart: true,\n\t\t\tpt: seg.start,\n\t\t\tseg: seg,\n\t\t\tprimary: primary,\n\t\t\tother: null,\n\t\t\tstatus: null\n\t\t});\n\t\teventAdd(ev_start, seg.end);\n\t\treturn ev_start;\n\t}\n\n\tfunction eventAddSegmentEnd(ev_start, seg, primary){\n\t\tvar ev_end = LinkedList.node({\n\t\t\tisStart: false,\n\t\t\tpt: seg.end,\n\t\t\tseg: seg,\n\t\t\tprimary: primary,\n\t\t\tother: ev_start,\n\t\t\tstatus: null\n\t\t});\n\t\tev_start.other = ev_end;\n\t\teventAdd(ev_end, ev_start.pt);\n\t}\n\n\tfunction eventAddSegment(seg, primary){\n\t\tvar ev_start = eventAddSegmentStart(seg, primary);\n\t\teventAddSegmentEnd(ev_start, seg, primary);\n\t\treturn ev_start;\n\t}\n\n\tfunction eventUpdateEnd(ev, end){\n\t\t// slides an end backwards\n\t\t//   (start)------------(end)    to:\n\t\t//   (start)---(end)\n\n\t\tif (buildLog)\n\t\t\tbuildLog.segmentChop(ev.seg, end);\n\n\t\tev.other.remove();\n\t\tev.seg.end = end;\n\t\tev.other.pt = end;\n\t\teventAdd(ev.other, ev.pt);\n\t}\n\n\tfunction eventDivide(ev, pt){\n\t\tvar ns = segmentCopy(pt, ev.seg.end, ev.seg);\n\t\teventUpdateEnd(ev, pt);\n\t\treturn eventAddSegment(ns, ev.primary);\n\t}\n\n\tfunction calculate(primaryPolyInverted, secondaryPolyInverted){\n\t\t// if selfIntersection is true then there is no secondary polygon, so that isn't used\n\n\t\t//\n\t\t// status logic\n\t\t//\n\n\t\tvar status_root = LinkedList.create();\n\n\t\tfunction statusCompare(ev1, ev2){\n\t\t\tvar a1 = ev1.seg.start;\n\t\t\tvar a2 = ev1.seg.end;\n\t\t\tvar b1 = ev2.seg.start;\n\t\t\tvar b2 = ev2.seg.end;\n\n\t\t\tif (eps.pointsCollinear(a1, b1, b2)){\n\t\t\t\tif (eps.pointsCollinear(a2, b1, b2))\n\t\t\t\t\treturn 1;//eventCompare(true, a1, a2, true, b1, b2);\n\t\t\t\treturn eps.pointAboveOrOnLine(a2, b1, b2) ? 1 : -1;\n\t\t\t}\n\t\t\treturn eps.pointAboveOrOnLine(a1, b1, b2) ? 1 : -1;\n\t\t}\n\n\t\tfunction statusFindSurrounding(ev){\n\t\t\treturn status_root.findTransition(function(here){\n\t\t\t\tvar comp = statusCompare(ev, here.ev);\n\t\t\t\treturn comp > 0;\n\t\t\t});\n\t\t}\n\n\t\tfunction checkIntersection(ev1, ev2){\n\t\t\t// returns the segment equal to ev1, or false if nothing equal\n\n\t\t\tvar seg1 = ev1.seg;\n\t\t\tvar seg2 = ev2.seg;\n\t\t\tvar a1 = seg1.start;\n\t\t\tvar a2 = seg1.end;\n\t\t\tvar b1 = seg2.start;\n\t\t\tvar b2 = seg2.end;\n\n\t\t\tif (buildLog)\n\t\t\t\tbuildLog.checkIntersection(seg1, seg2);\n\n\t\t\tvar i = eps.linesIntersect(a1, a2, b1, b2);\n\n\t\t\tif (i === false){\n\t\t\t\t// segments are parallel or coincident\n\n\t\t\t\t// if points aren't collinear, then the segments are parallel, so no intersections\n\t\t\t\tif (!eps.pointsCollinear(a1, a2, b1))\n\t\t\t\t\treturn false;\n\t\t\t\t// otherwise, segments are on top of each other somehow (aka coincident)\n\n\t\t\t\tif (eps.pointsSame(a1, b2) || eps.pointsSame(a2, b1))\n\t\t\t\t\treturn false; // segments touch at endpoints... no intersection\n\n\t\t\t\tvar a1_equ_b1 = eps.pointsSame(a1, b1);\n\t\t\t\tvar a2_equ_b2 = eps.pointsSame(a2, b2);\n\n\t\t\t\tif (a1_equ_b1 && a2_equ_b2)\n\t\t\t\t\treturn ev2; // segments are exactly equal\n\n\t\t\t\tvar a1_between = !a1_equ_b1 && eps.pointBetween(a1, b1, b2);\n\t\t\t\tvar a2_between = !a2_equ_b2 && eps.pointBetween(a2, b1, b2);\n\n\t\t\t\t// handy for debugging:\n\t\t\t\t// buildLog.log({\n\t\t\t\t//\ta1_equ_b1: a1_equ_b1,\n\t\t\t\t//\ta2_equ_b2: a2_equ_b2,\n\t\t\t\t//\ta1_between: a1_between,\n\t\t\t\t//\ta2_between: a2_between\n\t\t\t\t// });\n\n\t\t\t\tif (a1_equ_b1){\n\t\t\t\t\tif (a2_between){\n\t\t\t\t\t\t//  (a1)---(a2)\n\t\t\t\t\t\t//  (b1)----------(b2)\n\t\t\t\t\t\teventDivide(ev2, a2);\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\t//  (a1)----------(a2)\n\t\t\t\t\t\t//  (b1)---(b2)\n\t\t\t\t\t\teventDivide(ev1, b2);\n\t\t\t\t\t}\n\t\t\t\t\treturn ev2;\n\t\t\t\t}\n\t\t\t\telse if (a1_between){\n\t\t\t\t\tif (!a2_equ_b2){\n\t\t\t\t\t\t// make a2 equal to b2\n\t\t\t\t\t\tif (a2_between){\n\t\t\t\t\t\t\t//         (a1)---(a2)\n\t\t\t\t\t\t\t//  (b1)-----------------(b2)\n\t\t\t\t\t\t\teventDivide(ev2, a2);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t//         (a1)----------(a2)\n\t\t\t\t\t\t\t//  (b1)----------(b2)\n\t\t\t\t\t\t\teventDivide(ev1, b2);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t//         (a1)---(a2)\n\t\t\t\t\t//  (b1)----------(b2)\n\t\t\t\t\teventDivide(ev2, a1);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\t// otherwise, lines intersect at i.pt, which may or may not be between the endpoints\n\n\t\t\t\t// is A divided between its endpoints? (exclusive)\n\t\t\t\tif (i.alongA === 0){\n\t\t\t\t\tif (i.alongB === -1) // yes, at exactly b1\n\t\t\t\t\t\teventDivide(ev1, b1);\n\t\t\t\t\telse if (i.alongB === 0) // yes, somewhere between B's endpoints\n\t\t\t\t\t\teventDivide(ev1, i.pt);\n\t\t\t\t\telse if (i.alongB === 1) // yes, at exactly b2\n\t\t\t\t\t\teventDivide(ev1, b2);\n\t\t\t\t}\n\n\t\t\t\t// is B divided between its endpoints? (exclusive)\n\t\t\t\tif (i.alongB === 0){\n\t\t\t\t\tif (i.alongA === -1) // yes, at exactly a1\n\t\t\t\t\t\teventDivide(ev2, a1);\n\t\t\t\t\telse if (i.alongA === 0) // yes, somewhere between A's endpoints (exclusive)\n\t\t\t\t\t\teventDivide(ev2, i.pt);\n\t\t\t\t\telse if (i.alongA === 1) // yes, at exactly a2\n\t\t\t\t\t\teventDivide(ev2, a2);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\t//\n\t\t// main event loop\n\t\t//\n\t\tvar segments = [];\n\t\twhile (!event_root.isEmpty()){\n\t\t\tvar ev = event_root.getHead();\n\n\t\t\tif (buildLog)\n\t\t\t\tbuildLog.vert(ev.pt[0]);\n\n\t\t\tif (ev.isStart){\n\n\t\t\t\tif (buildLog)\n\t\t\t\t\tbuildLog.segmentNew(ev.seg, ev.primary);\n\n\t\t\t\tvar surrounding = statusFindSurrounding(ev);\n\t\t\t\tvar above = surrounding.before ? surrounding.before.ev : null;\n\t\t\t\tvar below = surrounding.after ? surrounding.after.ev : null;\n\n\t\t\t\tif (buildLog){\n\t\t\t\t\tbuildLog.tempStatus(\n\t\t\t\t\t\tev.seg,\n\t\t\t\t\t\tabove ? above.seg : false,\n\t\t\t\t\t\tbelow ? below.seg : false\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tfunction checkBothIntersections(){\n\t\t\t\t\tif (above){\n\t\t\t\t\t\tvar eve = checkIntersection(ev, above);\n\t\t\t\t\t\tif (eve)\n\t\t\t\t\t\t\treturn eve;\n\t\t\t\t\t}\n\t\t\t\t\tif (below)\n\t\t\t\t\t\treturn checkIntersection(ev, below);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tvar eve = checkBothIntersections();\n\t\t\t\tif (eve){\n\t\t\t\t\t// ev and eve are equal\n\t\t\t\t\t// we'll keep eve and throw away ev\n\n\t\t\t\t\t// merge ev.seg's fill information into eve.seg\n\n\t\t\t\t\tif (selfIntersection){\n\t\t\t\t\t\tvar toggle; // are we a toggling edge?\n\t\t\t\t\t\tif (ev.seg.myFill.below === null)\n\t\t\t\t\t\t\ttoggle = true;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\ttoggle = ev.seg.myFill.above !== ev.seg.myFill.below;\n\n\t\t\t\t\t\t// merge two segments that belong to the same polygon\n\t\t\t\t\t\t// think of this as sandwiching two segments together, where `eve.seg` is\n\t\t\t\t\t\t// the bottom -- this will cause the above fill flag to toggle\n\t\t\t\t\t\tif (toggle)\n\t\t\t\t\t\t\teve.seg.myFill.above = !eve.seg.myFill.above;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\t// merge two segments that belong to different polygons\n\t\t\t\t\t\t// each segment has distinct knowledge, so no special logic is needed\n\t\t\t\t\t\t// note that this can only happen once per segment in this phase, because we\n\t\t\t\t\t\t// are guaranteed that all self-intersections are gone\n\t\t\t\t\t\teve.seg.otherFill = ev.seg.myFill;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (buildLog)\n\t\t\t\t\t\tbuildLog.segmentUpdate(eve.seg);\n\n\t\t\t\t\tev.other.remove();\n\t\t\t\t\tev.remove();\n\t\t\t\t}\n\n\t\t\t\tif (event_root.getHead() !== ev){\n\t\t\t\t\t// something was inserted before us in the event queue, so loop back around and\n\t\t\t\t\t// process it before continuing\n\t\t\t\t\tif (buildLog)\n\t\t\t\t\t\tbuildLog.rewind(ev.seg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t//\n\t\t\t\t// calculate fill flags\n\t\t\t\t//\n\t\t\t\tif (selfIntersection){\n\t\t\t\t\tvar toggle; // are we a toggling edge?\n\t\t\t\t\tif (ev.seg.myFill.below === null) // if we are a new segment...\n\t\t\t\t\t\ttoggle = true; // then we toggle\n\t\t\t\t\telse // we are a segment that has previous knowledge from a division\n\t\t\t\t\t\ttoggle = ev.seg.myFill.above !== ev.seg.myFill.below; // calculate toggle\n\n\t\t\t\t\t// next, calculate whether we are filled below us\n\t\t\t\t\tif (!below){ // if nothing is below us...\n\t\t\t\t\t\t// we are filled below us if the polygon is inverted\n\t\t\t\t\t\tev.seg.myFill.below = primaryPolyInverted;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\t// otherwise, we know the answer -- it's the same if whatever is below\n\t\t\t\t\t\t// us is filled above it\n\t\t\t\t\t\tev.seg.myFill.below = below.seg.myFill.above;\n\t\t\t\t\t}\n\n\t\t\t\t\t// since now we know if we're filled below us, we can calculate whether\n\t\t\t\t\t// we're filled above us by applying toggle to whatever is below us\n\t\t\t\t\tif (toggle)\n\t\t\t\t\t\tev.seg.myFill.above = !ev.seg.myFill.below;\n\t\t\t\t\telse\n\t\t\t\t\t\tev.seg.myFill.above = ev.seg.myFill.below;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t// now we fill in any missing transition information, since we are all-knowing\n\t\t\t\t\t// at this point\n\n\t\t\t\t\tif (ev.seg.otherFill === null){\n\t\t\t\t\t\t// if we don't have other information, then we need to figure out if we're\n\t\t\t\t\t\t// inside the other polygon\n\t\t\t\t\t\tvar inside;\n\t\t\t\t\t\tif (!below){\n\t\t\t\t\t\t\t// if nothing is below us, then we're inside if the other polygon is\n\t\t\t\t\t\t\t// inverted\n\t\t\t\t\t\t\tinside =\n\t\t\t\t\t\t\t\tev.primary ? secondaryPolyInverted : primaryPolyInverted;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{ // otherwise, something is below us\n\t\t\t\t\t\t\t// so copy the below segment's other polygon's above\n\t\t\t\t\t\t\tif (ev.primary === below.primary)\n\t\t\t\t\t\t\t\tinside = below.seg.otherFill.above;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tinside = below.seg.myFill.above;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tev.seg.otherFill = {\n\t\t\t\t\t\t\tabove: inside,\n\t\t\t\t\t\t\tbelow: inside\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (buildLog){\n\t\t\t\t\tbuildLog.status(\n\t\t\t\t\t\tev.seg,\n\t\t\t\t\t\tabove ? above.seg : false,\n\t\t\t\t\t\tbelow ? below.seg : false\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// insert the status and remember it for later removal\n\t\t\t\tev.other.status = surrounding.insert(LinkedList.node({ ev: ev }));\n\t\t\t}\n\t\t\telse{\n\t\t\t\tvar st = ev.status;\n\n\t\t\t\tif (st === null){\n\t\t\t\t\tthrow new Error('PolyBool: Zero-length segment detected; your epsilon is ' +\n\t\t\t\t\t\t'probably too small or too large');\n\t\t\t\t}\n\n\t\t\t\t// removing the status will create two new adjacent edges, so we'll need to check\n\t\t\t\t// for those\n\t\t\t\tif (status_root.exists(st.prev) && status_root.exists(st.next))\n\t\t\t\t\tcheckIntersection(st.prev.ev, st.next.ev);\n\n\t\t\t\tif (buildLog)\n\t\t\t\t\tbuildLog.statusRemove(st.ev.seg);\n\n\t\t\t\t// remove the status\n\t\t\t\tst.remove();\n\n\t\t\t\t// if we've reached this point, we've calculated everything there is to know, so\n\t\t\t\t// save the segment for reporting\n\t\t\t\tif (!ev.primary){\n\t\t\t\t\t// make sure `seg.myFill` actually points to the primary polygon though\n\t\t\t\t\tvar s = ev.seg.myFill;\n\t\t\t\t\tev.seg.myFill = ev.seg.otherFill;\n\t\t\t\t\tev.seg.otherFill = s;\n\t\t\t\t}\n\t\t\t\tsegments.push(ev.seg);\n\t\t\t}\n\n\t\t\t// remove the event and continue\n\t\t\tevent_root.getHead().remove();\n\t\t}\n\n\t\tif (buildLog)\n\t\t\tbuildLog.done();\n\n\t\treturn segments;\n\t}\n\n\t// return the appropriate API depending on what we're doing\n\tif (!selfIntersection){\n\t\t// performing combination of polygons, so only deal with already-processed segments\n\t\treturn {\n\t\t\tcalculate: function(segments1, inverted1, segments2, inverted2){\n\t\t\t\t// segmentsX come from the self-intersection API, or this API\n\t\t\t\t// invertedX is whether we treat that list of segments as an inverted polygon or not\n\t\t\t\t// returns segments that can be used for further operations\n\t\t\t\tsegments1.forEach(function(seg){\n\t\t\t\t\teventAddSegment(segmentCopy(seg.start, seg.end, seg), true);\n\t\t\t\t});\n\t\t\t\tsegments2.forEach(function(seg){\n\t\t\t\t\teventAddSegment(segmentCopy(seg.start, seg.end, seg), false);\n\t\t\t\t});\n\t\t\t\treturn calculate(inverted1, inverted2);\n\t\t\t}\n\t\t};\n\t}\n\n\t// otherwise, performing self-intersection, so deal with regions\n\treturn {\n\t\taddRegion: function(region){\n\t\t\t// regions are a list of points:\n\t\t\t//  [ [0, 0], [100, 0], [50, 100] ]\n\t\t\t// you can add multiple regions before running calculate\n\t\t\tvar pt1;\n\t\t\tvar pt2 = region[region.length - 1];\n\t\t\tfor (var i = 0; i < region.length; i++){\n\t\t\t\tpt1 = pt2;\n\t\t\t\tpt2 = region[i];\n\n\t\t\t\tvar forward = eps.pointsCompare(pt1, pt2);\n\t\t\t\tif (forward === 0) // points are equal, so we have a zero-length segment\n\t\t\t\t\tcontinue; // just skip it\n\n\t\t\t\teventAddSegment(\n\t\t\t\t\tsegmentNew(\n\t\t\t\t\t\tforward < 0 ? pt1 : pt2,\n\t\t\t\t\t\tforward < 0 ? pt2 : pt1\n\t\t\t\t\t),\n\t\t\t\t\ttrue\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\tcalculate: function(inverted){\n\t\t\t// is the polygon inverted?\n\t\t\t// returns segments\n\t\t\treturn calculate(inverted, false);\n\t\t}\n\t};\n}\n\nmodule.exports = Intersecter;\n\n},{\"./linked-list\":478}],478:[function(_dereq_,module,exports){\n// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc\n// MIT License\n// Project Home: https://github.com/voidqk/polybooljs\n\n//\n// simple linked list implementation that allows you to traverse down nodes and save positions\n//\n\nvar LinkedList = {\n\tcreate: function(){\n\t\tvar my = {\n\t\t\troot: { root: true, next: null },\n\t\t\texists: function(node){\n\t\t\t\tif (node === null || node === my.root)\n\t\t\t\t\treturn false;\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tisEmpty: function(){\n\t\t\t\treturn my.root.next === null;\n\t\t\t},\n\t\t\tgetHead: function(){\n\t\t\t\treturn my.root.next;\n\t\t\t},\n\t\t\tinsertBefore: function(node, check){\n\t\t\t\tvar last = my.root;\n\t\t\t\tvar here = my.root.next;\n\t\t\t\twhile (here !== null){\n\t\t\t\t\tif (check(here)){\n\t\t\t\t\t\tnode.prev = here.prev;\n\t\t\t\t\t\tnode.next = here;\n\t\t\t\t\t\there.prev.next = node;\n\t\t\t\t\t\there.prev = node;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlast = here;\n\t\t\t\t\there = here.next;\n\t\t\t\t}\n\t\t\t\tlast.next = node;\n\t\t\t\tnode.prev = last;\n\t\t\t\tnode.next = null;\n\t\t\t},\n\t\t\tfindTransition: function(check){\n\t\t\t\tvar prev = my.root;\n\t\t\t\tvar here = my.root.next;\n\t\t\t\twhile (here !== null){\n\t\t\t\t\tif (check(here))\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tprev = here;\n\t\t\t\t\there = here.next;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tbefore: prev === my.root ? null : prev,\n\t\t\t\t\tafter: here,\n\t\t\t\t\tinsert: function(node){\n\t\t\t\t\t\tnode.prev = prev;\n\t\t\t\t\t\tnode.next = here;\n\t\t\t\t\t\tprev.next = node;\n\t\t\t\t\t\tif (here !== null)\n\t\t\t\t\t\t\there.prev = node;\n\t\t\t\t\t\treturn node;\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\t\treturn my;\n\t},\n\tnode: function(data){\n\t\tdata.prev = null;\n\t\tdata.next = null;\n\t\tdata.remove = function(){\n\t\t\tdata.prev.next = data.next;\n\t\t\tif (data.next)\n\t\t\t\tdata.next.prev = data.prev;\n\t\t\tdata.prev = null;\n\t\t\tdata.next = null;\n\t\t};\n\t\treturn data;\n\t}\n};\n\nmodule.exports = LinkedList;\n\n},{}],479:[function(_dereq_,module,exports){\n// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc\n// MIT License\n// Project Home: https://github.com/voidqk/polybooljs\n\n//\n// converts a list of segments into a list of regions, while also removing unnecessary verticies\n//\n\nfunction SegmentChainer(segments, eps, buildLog){\n\tvar chains = [];\n\tvar regions = [];\n\n\tsegments.forEach(function(seg){\n\t\tvar pt1 = seg.start;\n\t\tvar pt2 = seg.end;\n\t\tif (eps.pointsSame(pt1, pt2)){\n\t\t\tconsole.warn('PolyBool: Warning: Zero-length segment detected; your epsilon is ' +\n\t\t\t\t'probably too small or too large');\n\t\t\treturn;\n\t\t}\n\n\t\tif (buildLog)\n\t\t\tbuildLog.chainStart(seg);\n\n\t\t// search for two chains that this segment matches\n\t\tvar first_match = {\n\t\t\tindex: 0,\n\t\t\tmatches_head: false,\n\t\t\tmatches_pt1: false\n\t\t};\n\t\tvar second_match = {\n\t\t\tindex: 0,\n\t\t\tmatches_head: false,\n\t\t\tmatches_pt1: false\n\t\t};\n\t\tvar next_match = first_match;\n\t\tfunction setMatch(index, matches_head, matches_pt1){\n\t\t\t// return true if we've matched twice\n\t\t\tnext_match.index = index;\n\t\t\tnext_match.matches_head = matches_head;\n\t\t\tnext_match.matches_pt1 = matches_pt1;\n\t\t\tif (next_match === first_match){\n\t\t\t\tnext_match = second_match;\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tnext_match = null;\n\t\t\treturn true; // we've matched twice, we're done here\n\t\t}\n\t\tfor (var i = 0; i < chains.length; i++){\n\t\t\tvar chain = chains[i];\n\t\t\tvar head  = chain[0];\n\t\t\tvar head2 = chain[1];\n\t\t\tvar tail  = chain[chain.length - 1];\n\t\t\tvar tail2 = chain[chain.length - 2];\n\t\t\tif (eps.pointsSame(head, pt1)){\n\t\t\t\tif (setMatch(i, true, true))\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (eps.pointsSame(head, pt2)){\n\t\t\t\tif (setMatch(i, true, false))\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (eps.pointsSame(tail, pt1)){\n\t\t\t\tif (setMatch(i, false, true))\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (eps.pointsSame(tail, pt2)){\n\t\t\t\tif (setMatch(i, false, false))\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (next_match === first_match){\n\t\t\t// we didn't match anything, so create a new chain\n\t\t\tchains.push([ pt1, pt2 ]);\n\t\t\tif (buildLog)\n\t\t\t\tbuildLog.chainNew(pt1, pt2);\n\t\t\treturn;\n\t\t}\n\n\t\tif (next_match === second_match){\n\t\t\t// we matched a single chain\n\n\t\t\tif (buildLog)\n\t\t\t\tbuildLog.chainMatch(first_match.index);\n\n\t\t\t// add the other point to the apporpriate end, and check to see if we've closed the\n\t\t\t// chain into a loop\n\n\t\t\tvar index = first_match.index;\n\t\t\tvar pt = first_match.matches_pt1 ? pt2 : pt1; // if we matched pt1, then we add pt2, etc\n\t\t\tvar addToHead = first_match.matches_head; // if we matched at head, then add to the head\n\n\t\t\tvar chain = chains[index];\n\t\t\tvar grow  = addToHead ? chain[0] : chain[chain.length - 1];\n\t\t\tvar grow2 = addToHead ? chain[1] : chain[chain.length - 2];\n\t\t\tvar oppo  = addToHead ? chain[chain.length - 1] : chain[0];\n\t\t\tvar oppo2 = addToHead ? chain[chain.length - 2] : chain[1];\n\n\t\t\tif (eps.pointsCollinear(grow2, grow, pt)){\n\t\t\t\t// grow isn't needed because it's directly between grow2 and pt:\n\t\t\t\t// grow2 ---grow---> pt\n\t\t\t\tif (addToHead){\n\t\t\t\t\tif (buildLog)\n\t\t\t\t\t\tbuildLog.chainRemoveHead(first_match.index, pt);\n\t\t\t\t\tchain.shift();\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif (buildLog)\n\t\t\t\t\t\tbuildLog.chainRemoveTail(first_match.index, pt);\n\t\t\t\t\tchain.pop();\n\t\t\t\t}\n\t\t\t\tgrow = grow2; // old grow is gone... new grow is what grow2 was\n\t\t\t}\n\n\t\t\tif (eps.pointsSame(oppo, pt)){\n\t\t\t\t// we're closing the loop, so remove chain from chains\n\t\t\t\tchains.splice(index, 1);\n\n\t\t\t\tif (eps.pointsCollinear(oppo2, oppo, grow)){\n\t\t\t\t\t// oppo isn't needed because it's directly between oppo2 and grow:\n\t\t\t\t\t// oppo2 ---oppo--->grow\n\t\t\t\t\tif (addToHead){\n\t\t\t\t\t\tif (buildLog)\n\t\t\t\t\t\t\tbuildLog.chainRemoveTail(first_match.index, grow);\n\t\t\t\t\t\tchain.pop();\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tif (buildLog)\n\t\t\t\t\t\t\tbuildLog.chainRemoveHead(first_match.index, grow);\n\t\t\t\t\t\tchain.shift();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (buildLog)\n\t\t\t\t\tbuildLog.chainClose(first_match.index);\n\n\t\t\t\t// we have a closed chain!\n\t\t\t\tregions.push(chain);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// not closing a loop, so just add it to the apporpriate side\n\t\t\tif (addToHead){\n\t\t\t\tif (buildLog)\n\t\t\t\t\tbuildLog.chainAddHead(first_match.index, pt);\n\t\t\t\tchain.unshift(pt);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif (buildLog)\n\t\t\t\t\tbuildLog.chainAddTail(first_match.index, pt);\n\t\t\t\tchain.push(pt);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// otherwise, we matched two chains, so we need to combine those chains together\n\n\t\tfunction reverseChain(index){\n\t\t\tif (buildLog)\n\t\t\t\tbuildLog.chainReverse(index);\n\t\t\tchains[index].reverse(); // gee, that's easy\n\t\t}\n\n\t\tfunction appendChain(index1, index2){\n\t\t\t// index1 gets index2 appended to it, and index2 is removed\n\t\t\tvar chain1 = chains[index1];\n\t\t\tvar chain2 = chains[index2];\n\t\t\tvar tail  = chain1[chain1.length - 1];\n\t\t\tvar tail2 = chain1[chain1.length - 2];\n\t\t\tvar head  = chain2[0];\n\t\t\tvar head2 = chain2[1];\n\n\t\t\tif (eps.pointsCollinear(tail2, tail, head)){\n\t\t\t\t// tail isn't needed because it's directly between tail2 and head\n\t\t\t\t// tail2 ---tail---> head\n\t\t\t\tif (buildLog)\n\t\t\t\t\tbuildLog.chainRemoveTail(index1, tail);\n\t\t\t\tchain1.pop();\n\t\t\t\ttail = tail2; // old tail is gone... new tail is what tail2 was\n\t\t\t}\n\n\t\t\tif (eps.pointsCollinear(tail, head, head2)){\n\t\t\t\t// head isn't needed because it's directly between tail and head2\n\t\t\t\t// tail ---head---> head2\n\t\t\t\tif (buildLog)\n\t\t\t\t\tbuildLog.chainRemoveHead(index2, head);\n\t\t\t\tchain2.shift();\n\t\t\t}\n\n\t\t\tif (buildLog)\n\t\t\t\tbuildLog.chainJoin(index1, index2);\n\t\t\tchains[index1] = chain1.concat(chain2);\n\t\t\tchains.splice(index2, 1);\n\t\t}\n\n\t\tvar F = first_match.index;\n\t\tvar S = second_match.index;\n\n\t\tif (buildLog)\n\t\t\tbuildLog.chainConnect(F, S);\n\n\t\tvar reverseF = chains[F].length < chains[S].length; // reverse the shorter chain, if needed\n\t\tif (first_match.matches_head){\n\t\t\tif (second_match.matches_head){\n\t\t\t\tif (reverseF){\n\t\t\t\t\t// <<<< F <<<< --- >>>> S >>>>\n\t\t\t\t\treverseChain(F);\n\t\t\t\t\t// >>>> F >>>> --- >>>> S >>>>\n\t\t\t\t\tappendChain(F, S);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t// <<<< F <<<< --- >>>> S >>>>\n\t\t\t\t\treverseChain(S);\n\t\t\t\t\t// <<<< F <<<< --- <<<< S <<<<   logically same as:\n\t\t\t\t\t// >>>> S >>>> --- >>>> F >>>>\n\t\t\t\t\tappendChain(S, F);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\t// <<<< F <<<< --- <<<< S <<<<   logically same as:\n\t\t\t\t// >>>> S >>>> --- >>>> F >>>>\n\t\t\t\tappendChain(S, F);\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif (second_match.matches_head){\n\t\t\t\t// >>>> F >>>> --- >>>> S >>>>\n\t\t\t\tappendChain(F, S);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif (reverseF){\n\t\t\t\t\t// >>>> F >>>> --- <<<< S <<<<\n\t\t\t\t\treverseChain(F);\n\t\t\t\t\t// <<<< F <<<< --- <<<< S <<<<   logically same as:\n\t\t\t\t\t// >>>> S >>>> --- >>>> F >>>>\n\t\t\t\t\tappendChain(S, F);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t// >>>> F >>>> --- <<<< S <<<<\n\t\t\t\t\treverseChain(S);\n\t\t\t\t\t// >>>> F >>>> --- >>>> S >>>>\n\t\t\t\t\tappendChain(F, S);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n\n\treturn regions;\n}\n\nmodule.exports = SegmentChainer;\n\n},{}],480:[function(_dereq_,module,exports){\n// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc\n// MIT License\n// Project Home: https://github.com/voidqk/polybooljs\n\n//\n// filter a list of segments based on boolean operations\n//\n\nfunction select(segments, selection, buildLog){\n\tvar result = [];\n\tsegments.forEach(function(seg){\n\t\tvar index =\n\t\t\t(seg.myFill.above ? 8 : 0) +\n\t\t\t(seg.myFill.below ? 4 : 0) +\n\t\t\t((seg.otherFill && seg.otherFill.above) ? 2 : 0) +\n\t\t\t((seg.otherFill && seg.otherFill.below) ? 1 : 0);\n\t\tif (selection[index] !== 0){\n\t\t\t// copy the segment to the results, while also calculating the fill status\n\t\t\tresult.push({\n\t\t\t\tid: buildLog ? buildLog.segmentId() : -1,\n\t\t\t\tstart: seg.start,\n\t\t\t\tend: seg.end,\n\t\t\t\tmyFill: {\n\t\t\t\t\tabove: selection[index] === 1, // 1 if filled above\n\t\t\t\t\tbelow: selection[index] === 2  // 2 if filled below\n\t\t\t\t},\n\t\t\t\totherFill: null\n\t\t\t});\n\t\t}\n\t});\n\n\tif (buildLog)\n\t\tbuildLog.selected(result);\n\n\treturn result;\n}\n\nvar SegmentSelector = {\n\tunion: function(segments, buildLog){ // primary | secondary\n\t\t// above1 below1 above2 below2    Keep?               Value\n\t\t//    0      0      0      0   =>   no                  0\n\t\t//    0      0      0      1   =>   yes filled below    2\n\t\t//    0      0      1      0   =>   yes filled above    1\n\t\t//    0      0      1      1   =>   no                  0\n\t\t//    0      1      0      0   =>   yes filled below    2\n\t\t//    0      1      0      1   =>   yes filled below    2\n\t\t//    0      1      1      0   =>   no                  0\n\t\t//    0      1      1      1   =>   no                  0\n\t\t//    1      0      0      0   =>   yes filled above    1\n\t\t//    1      0      0      1   =>   no                  0\n\t\t//    1      0      1      0   =>   yes filled above    1\n\t\t//    1      0      1      1   =>   no                  0\n\t\t//    1      1      0      0   =>   no                  0\n\t\t//    1      1      0      1   =>   no                  0\n\t\t//    1      1      1      0   =>   no                  0\n\t\t//    1      1      1      1   =>   no                  0\n\t\treturn select(segments, [\n\t\t\t0, 2, 1, 0,\n\t\t\t2, 2, 0, 0,\n\t\t\t1, 0, 1, 0,\n\t\t\t0, 0, 0, 0\n\t\t], buildLog);\n\t},\n\tintersect: function(segments, buildLog){ // primary & secondary\n\t\t// above1 below1 above2 below2    Keep?               Value\n\t\t//    0      0      0      0   =>   no                  0\n\t\t//    0      0      0      1   =>   no                  0\n\t\t//    0      0      1      0   =>   no                  0\n\t\t//    0      0      1      1   =>   no                  0\n\t\t//    0      1      0      0   =>   no                  0\n\t\t//    0      1      0      1   =>   yes filled below    2\n\t\t//    0      1      1      0   =>   no                  0\n\t\t//    0      1      1      1   =>   yes filled below    2\n\t\t//    1      0      0      0   =>   no                  0\n\t\t//    1      0      0      1   =>   no                  0\n\t\t//    1      0      1      0   =>   yes filled above    1\n\t\t//    1      0      1      1   =>   yes filled above    1\n\t\t//    1      1      0      0   =>   no                  0\n\t\t//    1      1      0      1   =>   yes filled below    2\n\t\t//    1      1      1      0   =>   yes filled above    1\n\t\t//    1      1      1      1   =>   no                  0\n\t\treturn select(segments, [\n\t\t\t0, 0, 0, 0,\n\t\t\t0, 2, 0, 2,\n\t\t\t0, 0, 1, 1,\n\t\t\t0, 2, 1, 0\n\t\t], buildLog);\n\t},\n\tdifference: function(segments, buildLog){ // primary - secondary\n\t\t// above1 below1 above2 below2    Keep?               Value\n\t\t//    0      0      0      0   =>   no                  0\n\t\t//    0      0      0      1   =>   no                  0\n\t\t//    0      0      1      0   =>   no                  0\n\t\t//    0      0      1      1   =>   no                  0\n\t\t//    0      1      0      0   =>   yes filled below    2\n\t\t//    0      1      0      1   =>   no                  0\n\t\t//    0      1      1      0   =>   yes filled below    2\n\t\t//    0      1      1      1   =>   no                  0\n\t\t//    1      0      0      0   =>   yes filled above    1\n\t\t//    1      0      0      1   =>   yes filled above    1\n\t\t//    1      0      1      0   =>   no                  0\n\t\t//    1      0      1      1   =>   no                  0\n\t\t//    1      1      0      0   =>   no                  0\n\t\t//    1      1      0      1   =>   yes filled above    1\n\t\t//    1      1      1      0   =>   yes filled below    2\n\t\t//    1      1      1      1   =>   no                  0\n\t\treturn select(segments, [\n\t\t\t0, 0, 0, 0,\n\t\t\t2, 0, 2, 0,\n\t\t\t1, 1, 0, 0,\n\t\t\t0, 1, 2, 0\n\t\t], buildLog);\n\t},\n\tdifferenceRev: function(segments, buildLog){ // secondary - primary\n\t\t// above1 below1 above2 below2    Keep?               Value\n\t\t//    0      0      0      0   =>   no                  0\n\t\t//    0      0      0      1   =>   yes filled below    2\n\t\t//    0      0      1      0   =>   yes filled above    1\n\t\t//    0      0      1      1   =>   no                  0\n\t\t//    0      1      0      0   =>   no                  0\n\t\t//    0      1      0      1   =>   no                  0\n\t\t//    0      1      1      0   =>   yes filled above    1\n\t\t//    0      1      1      1   =>   yes filled above    1\n\t\t//    1      0      0      0   =>   no                  0\n\t\t//    1      0      0      1   =>   yes filled below    2\n\t\t//    1      0      1      0   =>   no                  0\n\t\t//    1      0      1      1   =>   yes filled below    2\n\t\t//    1      1      0      0   =>   no                  0\n\t\t//    1      1      0      1   =>   no                  0\n\t\t//    1      1      1      0   =>   no                  0\n\t\t//    1      1      1      1   =>   no                  0\n\t\treturn select(segments, [\n\t\t\t0, 2, 1, 0,\n\t\t\t0, 0, 1, 1,\n\t\t\t0, 2, 0, 2,\n\t\t\t0, 0, 0, 0\n\t\t], buildLog);\n\t},\n\txor: function(segments, buildLog){ // primary ^ secondary\n\t\t// above1 below1 above2 below2    Keep?               Value\n\t\t//    0      0      0      0   =>   no                  0\n\t\t//    0      0      0      1   =>   yes filled below    2\n\t\t//    0      0      1      0   =>   yes filled above    1\n\t\t//    0      0      1      1   =>   no                  0\n\t\t//    0      1      0      0   =>   yes filled below    2\n\t\t//    0      1      0      1   =>   no                  0\n\t\t//    0      1      1      0   =>   no                  0\n\t\t//    0      1      1      1   =>   yes filled above    1\n\t\t//    1      0      0      0   =>   yes filled above    1\n\t\t//    1      0      0      1   =>   no                  0\n\t\t//    1      0      1      0   =>   no                  0\n\t\t//    1      0      1      1   =>   yes filled below    2\n\t\t//    1      1      0      0   =>   no                  0\n\t\t//    1      1      0      1   =>   yes filled above    1\n\t\t//    1      1      1      0   =>   yes filled below    2\n\t\t//    1      1      1      1   =>   no                  0\n\t\treturn select(segments, [\n\t\t\t0, 2, 1, 0,\n\t\t\t2, 0, 0, 1,\n\t\t\t1, 0, 0, 2,\n\t\t\t0, 1, 2, 0\n\t\t], buildLog);\n\t}\n};\n\nmodule.exports = SegmentSelector;\n\n},{}],481:[function(_dereq_,module,exports){\n//Optimized version for triangle closest point\n// Based on Eberly's WildMagick codes\n// http://www.geometrictools.com/LibMathematics/Distance/Distance.html\n\"use strict\";\n\nvar diff = new Float64Array(4);\nvar edge0 = new Float64Array(4);\nvar edge1 = new Float64Array(4);\n\nfunction closestPoint2d(V0, V1, V2, point, result) {\n  //Reallocate buffers if necessary\n  if(diff.length < point.length) {\n    diff = new Float64Array(point.length);\n    edge0 = new Float64Array(point.length);\n    edge1 = new Float64Array(point.length);\n  }\n  //Compute edges\n  for(var i=0; i<point.length; ++i) {\n    diff[i]  = V0[i] - point[i];\n    edge0[i] = V1[i] - V0[i];\n    edge1[i] = V2[i] - V0[i];\n  }\n  //Compute coefficients for quadratic func\n  var a00 = 0.0\n    , a01 = 0.0\n    , a11 = 0.0\n    , b0  = 0.0\n    , b1  = 0.0\n    , c   = 0.0;\n  for(var i=0; i<point.length; ++i) {\n    var e0 = edge0[i]\n      , e1 = edge1[i]\n      , d  = diff[i];\n    a00 += e0 * e0;\n    a01 += e0 * e1;\n    a11 += e1 * e1;\n    b0  += d * e0;\n    b1  += d * e1;\n    c   += d * d;\n  }\n  //Compute determinant/coeffs\n  var det = Math.abs(a00*a11 - a01*a01);\n  var s   = a01*b1 - a11*b0;\n  var t   = a01*b0 - a00*b1;\n  var sqrDistance;\n  //Hardcoded Voronoi diagram classification\n  if (s + t <= det) {\n    if (s < 0) {\n      if (t < 0) { // region 4\n        if (b0 < 0) {\n          t = 0;\n          if (-b0 >= a00) {\n            s = 1.0;\n            sqrDistance = a00 + 2.0*b0 + c;\n          } else {\n            s = -b0/a00;\n            sqrDistance = b0*s + c;\n          }\n        } else {\n          s = 0;\n          if (b1 >= 0) {\n            t = 0;\n            sqrDistance = c;\n          } else if (-b1 >= a11) {\n            t = 1;\n            sqrDistance = a11 + 2.0*b1 + c;\n          } else {\n            t = -b1/a11;\n            sqrDistance = b1*t + c;\n          }\n        }\n      } else {  // region 3\n        s = 0;\n        if (b1 >= 0) {\n          t = 0;\n          sqrDistance = c;\n        } else if (-b1 >= a11) {\n          t = 1;\n          sqrDistance = a11 + 2.0*b1 + c;\n        } else {\n          t = -b1/a11;\n          sqrDistance = b1*t + c;\n        }\n      }\n    } else if (t < 0) { // region 5\n      t = 0;\n      if (b0 >= 0) {\n        s = 0;\n        sqrDistance = c;\n      } else if (-b0 >= a00) {\n        s = 1;\n        sqrDistance = a00 + 2.0*b0 + c;\n      } else {\n        s = -b0/a00;\n        sqrDistance = b0*s + c;\n      }\n    } else {  // region 0\n      // minimum at interior point\n      var invDet = 1.0 / det;\n      s *= invDet;\n      t *= invDet;\n      sqrDistance = s*(a00*s + a01*t + 2.0*b0) + t*(a01*s + a11*t + 2.0*b1) + c;\n    }\n  } else {\n    var tmp0, tmp1, numer, denom;\n    \n    if (s < 0) {  // region 2\n      tmp0 = a01 + b0;\n      tmp1 = a11 + b1;\n      if (tmp1 > tmp0) {\n        numer = tmp1 - tmp0;\n        denom = a00 - 2.0*a01 + a11;\n        if (numer >= denom) {\n          s = 1;\n          t = 0;\n          sqrDistance = a00 + 2.0*b0 + c;\n        } else {\n          s = numer/denom;\n          t = 1 - s;\n          sqrDistance = s*(a00*s + a01*t + 2.0*b0) +\n          t*(a01*s + a11*t + 2.0*b1) + c;\n        }\n      } else {\n        s = 0;\n        if (tmp1 <= 0) {\n          t = 1;\n          sqrDistance = a11 + 2.0*b1 + c;\n        } else if (b1 >= 0) {\n          t = 0;\n          sqrDistance = c;\n        } else {\n          t = -b1/a11;\n          sqrDistance = b1*t + c;\n        }\n      }\n    } else if (t < 0) {  // region 6\n      tmp0 = a01 + b1;\n      tmp1 = a00 + b0;\n      if (tmp1 > tmp0) {\n        numer = tmp1 - tmp0;\n        denom = a00 - 2.0*a01 + a11;\n        if (numer >= denom) {\n          t = 1;\n          s = 0;\n          sqrDistance = a11 + 2.0*b1 + c;\n        } else {\n          t = numer/denom;\n          s = 1 - t;\n          sqrDistance = s*(a00*s + a01*t + 2.0*b0) +\n          t*(a01*s + a11*t + 2.0*b1) + c;\n        }\n      } else {\n        t = 0;\n        if (tmp1 <= 0) {\n          s = 1;\n          sqrDistance = a00 + 2.0*b0 + c;\n        } else if (b0 >= 0) {\n          s = 0;\n          sqrDistance = c;\n        } else {\n          s = -b0/a00;\n          sqrDistance = b0*s + c;\n        }\n      }\n    } else {  // region 1\n      numer = a11 + b1 - a01 - b0;\n      if (numer <= 0) {\n        s = 0;\n        t = 1;\n        sqrDistance = a11 + 2.0*b1 + c;\n      } else {\n        denom = a00 - 2.0*a01 + a11;\n        if (numer >= denom) {\n          s = 1;\n          t = 0;\n          sqrDistance = a00 + 2.0*b0 + c;\n        } else {\n          s = numer/denom;\n          t = 1 - s;\n          sqrDistance = s*(a00*s + a01*t + 2.0*b0) +\n          t*(a01*s + a11*t + 2.0*b1) + c;\n        }\n      }\n    }\n  }\n  var u = 1.0 - s - t;\n  for(var i=0; i<point.length; ++i) {\n    result[i] = u * V0[i] + s * V1[i] + t * V2[i];\n  }\n  if(sqrDistance < 0) {\n    return 0;\n  }\n  return sqrDistance;\n}\n\nmodule.exports = closestPoint2d;\n\n},{}],482:[function(_dereq_,module,exports){\n// shim for using process in browser\nvar process = module.exports = {};\n\n// cached from whatever global is present so that test runners that stub it\n// don't break things.  But we need to wrap it in a try catch in case it is\n// wrapped in strict mode code which doesn't define any globals.  It's inside a\n// function because try/catches deoptimize in certain engines.\n\nvar cachedSetTimeout;\nvar cachedClearTimeout;\n\nfunction defaultSetTimout() {\n    throw new Error('setTimeout has not been defined');\n}\nfunction defaultClearTimeout () {\n    throw new Error('clearTimeout has not been defined');\n}\n(function () {\n    try {\n        if (typeof setTimeout === 'function') {\n            cachedSetTimeout = setTimeout;\n        } else {\n            cachedSetTimeout = defaultSetTimout;\n        }\n    } catch (e) {\n        cachedSetTimeout = defaultSetTimout;\n    }\n    try {\n        if (typeof clearTimeout === 'function') {\n            cachedClearTimeout = clearTimeout;\n        } else {\n            cachedClearTimeout = defaultClearTimeout;\n        }\n    } catch (e) {\n        cachedClearTimeout = defaultClearTimeout;\n    }\n} ())\nfunction runTimeout(fun) {\n    if (cachedSetTimeout === setTimeout) {\n        //normal enviroments in sane situations\n        return setTimeout(fun, 0);\n    }\n    // if setTimeout wasn't available but was latter defined\n    if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {\n        cachedSetTimeout = setTimeout;\n        return setTimeout(fun, 0);\n    }\n    try {\n        // when when somebody has screwed with setTimeout but no I.E. maddness\n        return cachedSetTimeout(fun, 0);\n    } catch(e){\n        try {\n            // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n            return cachedSetTimeout.call(null, fun, 0);\n        } catch(e){\n            // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error\n            return cachedSetTimeout.call(this, fun, 0);\n        }\n    }\n\n\n}\nfunction runClearTimeout(marker) {\n    if (cachedClearTimeout === clearTimeout) {\n        //normal enviroments in sane situations\n        return clearTimeout(marker);\n    }\n    // if clearTimeout wasn't available but was latter defined\n    if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {\n        cachedClearTimeout = clearTimeout;\n        return clearTimeout(marker);\n    }\n    try {\n        // when when somebody has screwed with setTimeout but no I.E. maddness\n        return cachedClearTimeout(marker);\n    } catch (e){\n        try {\n            // When we are in I.E. but the script has been evaled so I.E. doesn't  trust the global object when called normally\n            return cachedClearTimeout.call(null, marker);\n        } catch (e){\n            // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.\n            // Some versions of I.E. have different rules for clearTimeout vs setTimeout\n            return cachedClearTimeout.call(this, marker);\n        }\n    }\n\n\n\n}\nvar queue = [];\nvar draining = false;\nvar currentQueue;\nvar queueIndex = -1;\n\nfunction cleanUpNextTick() {\n    if (!draining || !currentQueue) {\n        return;\n    }\n    draining = false;\n    if (currentQueue.length) {\n        queue = currentQueue.concat(queue);\n    } else {\n        queueIndex = -1;\n    }\n    if (queue.length) {\n        drainQueue();\n    }\n}\n\nfunction drainQueue() {\n    if (draining) {\n        return;\n    }\n    var timeout = runTimeout(cleanUpNextTick);\n    draining = true;\n\n    var len = queue.length;\n    while(len) {\n        currentQueue = queue;\n        queue = [];\n        while (++queueIndex < len) {\n            if (currentQueue) {\n                currentQueue[queueIndex].run();\n            }\n        }\n        queueIndex = -1;\n        len = queue.length;\n    }\n    currentQueue = null;\n    draining = false;\n    runClearTimeout(timeout);\n}\n\nprocess.nextTick = function (fun) {\n    var args = new Array(arguments.length - 1);\n    if (arguments.length > 1) {\n        for (var i = 1; i < arguments.length; i++) {\n            args[i - 1] = arguments[i];\n        }\n    }\n    queue.push(new Item(fun, args));\n    if (queue.length === 1 && !draining) {\n        runTimeout(drainQueue);\n    }\n};\n\n// v8 likes predictible objects\nfunction Item(fun, array) {\n    this.fun = fun;\n    this.array = array;\n}\nItem.prototype.run = function () {\n    this.fun.apply(null, this.array);\n};\nprocess.title = 'browser';\nprocess.browser = true;\nprocess.env = {};\nprocess.argv = [];\nprocess.version = ''; // empty string to avoid regexp issues\nprocess.versions = {};\n\nfunction noop() {}\n\nprocess.on = noop;\nprocess.addListener = noop;\nprocess.once = noop;\nprocess.off = noop;\nprocess.removeListener = noop;\nprocess.removeAllListeners = noop;\nprocess.emit = noop;\nprocess.prependListener = noop;\nprocess.prependOnceListener = noop;\n\nprocess.listeners = function (name) { return [] }\n\nprocess.binding = function (name) {\n    throw new Error('process.binding is not supported');\n};\n\nprocess.cwd = function () { return '/' };\nprocess.chdir = function (dir) {\n    throw new Error('process.chdir is not supported');\n};\nprocess.umask = function() { return 0; };\n\n},{}],483:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('gl-quat/slerp')\n},{\"gl-quat/slerp\":293}],484:[function(_dereq_,module,exports){\n(function (global){\nvar now = _dereq_('performance-now')\n  , root = typeof window === 'undefined' ? global : window\n  , vendors = ['moz', 'webkit']\n  , suffix = 'AnimationFrame'\n  , raf = root['request' + suffix]\n  , caf = root['cancel' + suffix] || root['cancelRequest' + suffix]\n\nfor(var i = 0; !raf && i < vendors.length; i++) {\n  raf = root[vendors[i] + 'Request' + suffix]\n  caf = root[vendors[i] + 'Cancel' + suffix]\n      || root[vendors[i] + 'CancelRequest' + suffix]\n}\n\n// Some versions of FF have rAF but not cAF\nif(!raf || !caf) {\n  var last = 0\n    , id = 0\n    , queue = []\n    , frameDuration = 1000 / 60\n\n  raf = function(callback) {\n    if(queue.length === 0) {\n      var _now = now()\n        , next = Math.max(0, frameDuration - (_now - last))\n      last = next + _now\n      setTimeout(function() {\n        var cp = queue.slice(0)\n        // Clear queue here to prevent\n        // callbacks from appending listeners\n        // to the current frame's queue\n        queue.length = 0\n        for(var i = 0; i < cp.length; i++) {\n          if(!cp[i].cancelled) {\n            try{\n              cp[i].callback(last)\n            } catch(e) {\n              setTimeout(function() { throw e }, 0)\n            }\n          }\n        }\n      }, Math.round(next))\n    }\n    queue.push({\n      handle: ++id,\n      callback: callback,\n      cancelled: false\n    })\n    return id\n  }\n\n  caf = function(handle) {\n    for(var i = 0; i < queue.length; i++) {\n      if(queue[i].handle === handle) {\n        queue[i].cancelled = true\n      }\n    }\n  }\n}\n\nmodule.exports = function(fn) {\n  // Wrap in a new function to prevent\n  // `cancel` potentially being assigned\n  // to the native rAF function\n  return raf.call(root, fn)\n}\nmodule.exports.cancel = function() {\n  caf.apply(root, arguments)\n}\nmodule.exports.polyfill = function(object) {\n  if (!object) {\n    object = root;\n  }\n  object.requestAnimationFrame = raf\n  object.cancelAnimationFrame = caf\n}\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"performance-now\":462}],485:[function(_dereq_,module,exports){\n'use strict'\n\nvar bnadd = _dereq_('big-rat/add')\n\nmodule.exports = add\n\nfunction add (a, b) {\n  var n = a.length\n  var r = new Array(n)\n  for (var i=0; i<n; ++i) {\n    r[i] = bnadd(a[i], b[i])\n  }\n  return r\n}\n\n},{\"big-rat/add\":75}],486:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = float2rat\n\nvar rat = _dereq_('big-rat')\n\nfunction float2rat(v) {\n  var result = new Array(v.length)\n  for(var i=0; i<v.length; ++i) {\n    result[i] = rat(v[i])\n  }\n  return result\n}\n\n},{\"big-rat\":78}],487:[function(_dereq_,module,exports){\n'use strict'\n\nvar rat = _dereq_('big-rat')\nvar mul = _dereq_('big-rat/mul')\n\nmodule.exports = muls\n\nfunction muls(a, x) {\n  var s = rat(x)\n  var n = a.length\n  var r = new Array(n)\n  for(var i=0; i<n; ++i) {\n    r[i] = mul(a[i], s)\n  }\n  return r\n}\n\n},{\"big-rat\":78,\"big-rat/mul\":87}],488:[function(_dereq_,module,exports){\n'use strict'\n\nvar bnsub = _dereq_('big-rat/sub')\n\nmodule.exports = sub\n\nfunction sub(a, b) {\n  var n = a.length\n  var r = new Array(n)\n    for(var i=0; i<n; ++i) {\n    r[i] = bnsub(a[i], b[i])\n  }\n  return r\n}\n\n},{\"big-rat/sub\":89}],489:[function(_dereq_,module,exports){\n'use strict'\n\nvar compareCell = _dereq_('compare-cell')\nvar compareOrientedCell = _dereq_('compare-oriented-cell')\nvar orientation = _dereq_('cell-orientation')\n\nmodule.exports = reduceCellComplex\n\nfunction reduceCellComplex(cells) {\n  cells.sort(compareOrientedCell)\n  var n = cells.length\n  var ptr = 0\n  for(var i=0; i<n; ++i) {\n    var c = cells[i]\n    var o = orientation(c)\n    if(o === 0) {\n      continue\n    }\n    if(ptr > 0) {\n      var f = cells[ptr-1]\n      if(compareCell(c, f) === 0 &&\n         orientation(f)    !== o) {\n        ptr -= 1\n        continue\n      }\n    }\n    cells[ptr++] = c\n  }\n  cells.length = ptr\n  return cells\n}\n\n},{\"cell-orientation\":112,\"compare-cell\":128,\"compare-oriented-cell\":129}],490:[function(_dereq_,module,exports){\n'use strict'\n\nvar getBounds = _dereq_('array-bounds')\nvar rgba = _dereq_('color-normalize')\nvar updateDiff = _dereq_('update-diff')\nvar pick = _dereq_('pick-by-alias')\nvar extend = _dereq_('object-assign')\nvar flatten = _dereq_('flatten-vertex-data')\nvar ref = _dereq_('to-float32');\nvar float32 = ref.float32;\nvar fract32 = ref.fract32;\n\nmodule.exports = Error2D\n\nvar WEIGHTS = [\n\t//direction, lineWidth shift, capSize shift\n\n\t// x-error bar\n\t[1, 0, 0, 1, 0, 0],\n\t[1, 0, 0, -1, 0, 0],\n\t[-1, 0, 0, -1, 0, 0],\n\n\t[-1, 0, 0, -1, 0, 0],\n\t[-1, 0, 0, 1, 0, 0],\n\t[1, 0, 0, 1, 0, 0],\n\n\t// x-error right cap\n\t[1, 0, -1, 0, 0, 1],\n\t[1, 0, -1, 0, 0, -1],\n\t[1, 0, 1, 0, 0, -1],\n\n\t[1, 0, 1, 0, 0, -1],\n\t[1, 0, 1, 0, 0, 1],\n\t[1, 0, -1, 0, 0, 1],\n\n\t// x-error left cap\n\t[-1, 0, -1, 0, 0, 1],\n\t[-1, 0, -1, 0, 0, -1],\n\t[-1, 0, 1, 0, 0, -1],\n\n\t[-1, 0, 1, 0, 0, -1],\n\t[-1, 0, 1, 0, 0, 1],\n\t[-1, 0, -1, 0, 0, 1],\n\n\t// y-error bar\n\t[0, 1, 1, 0, 0, 0],\n\t[0, 1, -1, 0, 0, 0],\n\t[0, -1, -1, 0, 0, 0],\n\n\t[0, -1, -1, 0, 0, 0],\n\t[0, 1, 1, 0, 0, 0],\n\t[0, -1, 1, 0, 0, 0],\n\n\t// y-error top cap\n\t[0, 1, 0, -1, 1, 0],\n\t[0, 1, 0, -1, -1, 0],\n\t[0, 1, 0, 1, -1, 0],\n\n\t[0, 1, 0, 1, 1, 0],\n\t[0, 1, 0, -1, 1, 0],\n\t[0, 1, 0, 1, -1, 0],\n\n\t// y-error bottom cap\n\t[0, -1, 0, -1, 1, 0],\n\t[0, -1, 0, -1, -1, 0],\n\t[0, -1, 0, 1, -1, 0],\n\n\t[0, -1, 0, 1, 1, 0],\n\t[0, -1, 0, -1, 1, 0],\n\t[0, -1, 0, 1, -1, 0]\n]\n\n\nfunction Error2D (regl, options) {\n\tif (typeof regl === 'function') {\n\t\tif (!options) { options = {} }\n\t\toptions.regl = regl\n\t}\n\telse {\n\t\toptions = regl\n\t}\n\tif (options.length) { options.positions = options }\n\tregl = options.regl\n\n\tif (!regl.hasExtension('ANGLE_instanced_arrays')) {\n\t\tthrow Error('regl-error2d: `ANGLE_instanced_arrays` extension should be enabled');\n\t}\n\n\t// persistent variables\n\tvar gl = regl._gl, drawErrors, positionBuffer, positionFractBuffer, colorBuffer, errorBuffer, meshBuffer,\n\t\t\tdefaults = {\n\t\t\t\tcolor: 'black',\n\t\t\t\tcapSize: 5,\n\t\t\t\tlineWidth: 1,\n\t\t\t\topacity: 1,\n\t\t\t\tviewport: null,\n\t\t\t\trange: null,\n\t\t\t\toffset: 0,\n\t\t\t\tcount: 0,\n\t\t\t\tbounds: null,\n\t\t\t\tpositions: [],\n\t\t\t\terrors: []\n\t\t\t}, groups = []\n\n\t//color per-point\n\tcolorBuffer = regl.buffer({\n\t\tusage: 'dynamic',\n\t\ttype: 'uint8',\n\t\tdata: new Uint8Array(0)\n\t})\n\t//xy-position per-point\n\tpositionBuffer = regl.buffer({\n\t\tusage: 'dynamic',\n\t\ttype: 'float',\n\t\tdata: new Uint8Array(0)\n\t})\n\t//xy-position float32-fraction\n\tpositionFractBuffer = regl.buffer({\n\t\tusage: 'dynamic',\n\t\ttype: 'float',\n\t\tdata: new Uint8Array(0)\n\t})\n\t//4 errors per-point\n\terrorBuffer = regl.buffer({\n\t\tusage: 'dynamic',\n\t\ttype: 'float',\n\t\tdata: new Uint8Array(0)\n\t})\n\t//error bar mesh\n\tmeshBuffer = regl.buffer({\n\t\tusage: 'static',\n\t\ttype: 'float',\n\t\tdata: WEIGHTS\n\t})\n\n\tupdate(options)\n\n\t//drawing method\n\tdrawErrors = regl({\n\t\tvert: \"\\n\\t\\tprecision highp float;\\n\\n\\t\\tattribute vec2 position, positionFract;\\n\\t\\tattribute vec4 error;\\n\\t\\tattribute vec4 color;\\n\\n\\t\\tattribute vec2 direction, lineOffset, capOffset;\\n\\n\\t\\tuniform vec4 viewport;\\n\\t\\tuniform float lineWidth, capSize;\\n\\t\\tuniform vec2 scale, scaleFract, translate, translateFract;\\n\\n\\t\\tvarying vec4 fragColor;\\n\\n\\t\\tvoid main() {\\n\\t\\t\\tfragColor = color / 255.;\\n\\n\\t\\t\\tvec2 pixelOffset = lineWidth * lineOffset + (capSize + lineWidth) * capOffset;\\n\\n\\t\\t\\tvec2 dxy = -step(.5, direction.xy) * error.xz + step(direction.xy, vec2(-.5)) * error.yw;\\n\\n\\t\\t\\tvec2 position = position + dxy;\\n\\n\\t\\t\\tvec2 pos = (position + translate) * scale\\n\\t\\t\\t\\t+ (positionFract + translateFract) * scale\\n\\t\\t\\t\\t+ (position + translate) * scaleFract\\n\\t\\t\\t\\t+ (positionFract + translateFract) * scaleFract;\\n\\n\\t\\t\\tpos += pixelOffset / viewport.zw;\\n\\n\\t\\t\\tgl_Position = vec4(pos * 2. - 1., 0, 1);\\n\\t\\t}\\n\\t\\t\",\n\n\t\tfrag: \"\\n\\t\\tprecision highp float;\\n\\n\\t\\tvarying vec4 fragColor;\\n\\n\\t\\tuniform float opacity;\\n\\n\\t\\tvoid main() {\\n\\t\\t\\tgl_FragColor = fragColor;\\n\\t\\t\\tgl_FragColor.a *= opacity;\\n\\t\\t}\\n\\t\\t\",\n\n\t\tuniforms: {\n\t\t\trange: regl.prop('range'),\n\t\t\tlineWidth: regl.prop('lineWidth'),\n\t\t\tcapSize: regl.prop('capSize'),\n\t\t\topacity: regl.prop('opacity'),\n\t\t\tscale: regl.prop('scale'),\n\t\t\ttranslate: regl.prop('translate'),\n\t\t\tscaleFract: regl.prop('scaleFract'),\n\t\t\ttranslateFract: regl.prop('translateFract'),\n\t\t\tviewport: function (ctx, prop) { return [prop.viewport.x, prop.viewport.y, ctx.viewportWidth, ctx.viewportHeight]; }\n\t\t},\n\n\t\tattributes: {\n\t\t\t//dynamic attributes\n\t\t\tcolor: {\n\t\t\t\tbuffer: colorBuffer,\n\t\t\t\toffset: function (ctx, prop) { return prop.offset * 4; },\n\t\t\t\tdivisor: 1,\n\t\t\t},\n\t\t\tposition: {\n\t\t\t\tbuffer: positionBuffer,\n\t\t\t\toffset: function (ctx, prop) { return prop.offset * 8; },\n\t\t\t\tdivisor: 1\n\t\t\t},\n\t\t\tpositionFract: {\n\t\t\t\tbuffer: positionFractBuffer,\n\t\t\t\toffset: function (ctx, prop) { return prop.offset * 8; },\n\t\t\t\tdivisor: 1\n\t\t\t},\n\t\t\terror: {\n\t\t\t\tbuffer: errorBuffer,\n\t\t\t\toffset: function (ctx, prop) { return prop.offset * 16; },\n\t\t\t\tdivisor: 1\n\t\t\t},\n\n\t\t\t//static attributes\n\t\t\tdirection: {\n\t\t\t\tbuffer: meshBuffer,\n\t\t\t\tstride: 24,\n\t\t\t\toffset: 0\n\t\t\t},\n\t\t\tlineOffset: {\n\t\t\t\tbuffer: meshBuffer,\n\t\t\t\tstride: 24,\n\t\t\t\toffset: 8\n\t\t\t},\n\t\t\tcapOffset: {\n\t\t\t\tbuffer: meshBuffer,\n\t\t\t\tstride: 24,\n\t\t\t\toffset: 16\n\t\t\t}\n\t\t},\n\n\t\tprimitive: 'triangles',\n\n\t\tblend: {\n\t\t\tenable: true,\n\t\t\tcolor: [0,0,0,0],\n\t\t\tequation: {\n\t\t\t\trgb: 'add',\n\t\t\t\talpha: 'add'\n\t\t\t},\n\t\t\tfunc: {\n\t\t\t\tsrcRGB: 'src alpha',\n\t\t\t\tdstRGB: 'one minus src alpha',\n\t\t\t\tsrcAlpha: 'one minus dst alpha',\n\t\t\t\tdstAlpha: 'one'\n\t\t\t}\n\t\t},\n\n\t\tdepth: {\n\t\t\tenable: false\n\t\t},\n\n\t\tscissor: {\n\t\t\tenable: true,\n\t\t\tbox: regl.prop('viewport')\n\t\t},\n\t\tviewport: regl.prop('viewport'),\n\t\tstencil: false,\n\n\t\tinstances: regl.prop('count'),\n\t\tcount: WEIGHTS.length\n\t})\n\n\t//expose API\n\textend(error2d, {\n\t\tupdate: update,\n\t\tdraw: draw,\n\t\tdestroy: destroy,\n\t\tregl: regl,\n\t\tgl: gl,\n\t\tcanvas: gl.canvas,\n\t\tgroups: groups\n\t})\n\n\treturn error2d\n\n\tfunction error2d (opts) {\n\t\t//update\n\t\tif (opts) {\n\t\t\tupdate(opts)\n\t\t}\n\n\t\t//destroy\n\t\telse if (opts === null) {\n\t\t\tdestroy()\n\t\t}\n\n\t\tdraw()\n\t}\n\n\n\t//main draw method\n\tfunction draw (options) {\n\t\tif (typeof options === 'number') { return drawGroup(options) }\n\n\t\t//make options a batch\n\t\tif (options && !Array.isArray(options)) { options = [options] }\n\n\n\t\tregl._refresh()\n\n\t\t//render multiple polylines via regl batch\n\t\tgroups.forEach(function (s, i) {\n\t\t\tif (!s) { return }\n\n\t\t\tif (options) {\n\t\t\t\tif (!options[i]) { s.draw = false }\n\t\t\t\telse { s.draw = true }\n\t\t\t}\n\n\t\t\t//ignore draw flag for one pass\n\t\t\tif (!s.draw) {\n\t\t\t\ts.draw = true;\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tdrawGroup(i)\n\t\t})\n\t}\n\n\t//draw single error group by id\n\tfunction drawGroup (s) {\n\t\tif (typeof s === 'number') { s = groups[s] }\n\t\tif (s == null) { return }\n\n\t\tif (!(s && s.count && s.color && s.opacity && s.positions && s.positions.length > 1)) { return }\n\n\t\ts.scaleRatio = [\n\t\t\ts.scale[0] * s.viewport.width,\n\t\t\ts.scale[1] * s.viewport.height\n\t\t]\n\n\t\tdrawErrors(s)\n\n\t\tif (s.after) { s.after(s) }\n\t}\n\n\tfunction update (options) {\n\t\tif (!options) { return }\n\n\t\t//direct points argument\n\t\tif (options.length != null) {\n\t\t\tif (typeof options[0] === 'number') { options = [{positions: options}] }\n\t\t}\n\n\t\t//make options a batch\n\t\telse if (!Array.isArray(options)) { options = [options] }\n\n\t\t//global count of points\n\t\tvar pointCount = 0, errorCount = 0\n\n\t\terror2d.groups = groups = options.map(function (options, i) {\n\t\t\tvar group = groups[i]\n\n\t\t\tif (!options) { return group }\n\t\t\telse if (typeof options === 'function') { options = {after: options} }\n\t\t\telse if (typeof options[0] === 'number') { options = {positions: options} }\n\n\t\t\t//copy options to avoid mutation & handle aliases\n\t\t\toptions = pick(options, {\n\t\t\t\tcolor: 'color colors fill',\n\t\t\t\tcapSize: 'capSize cap capsize cap-size',\n\t\t\t\tlineWidth: 'lineWidth line-width width line thickness',\n\t\t\t\topacity: 'opacity alpha',\n\t\t\t\trange: 'range dataBox',\n\t\t\t\tviewport: 'viewport viewBox',\n\t\t\t\terrors: 'errors error',\n\t\t\t\tpositions: 'positions position data points'\n\t\t\t})\n\n\t\t\tif (!group) {\n\t\t\t\tgroups[i] = group = {\n\t\t\t\t\tid: i,\n\t\t\t\t\tscale: null,\n\t\t\t\t\ttranslate: null,\n\t\t\t\t\tscaleFract: null,\n\t\t\t\t\ttranslateFract: null,\n\t\t\t\t\tdraw: true\n\t\t\t\t}\n\t\t\t\toptions = extend({}, defaults, options)\n\t\t\t}\n\n\t\t\tupdateDiff(group, options, [{\n\t\t\t\tlineWidth: function (v) { return +v * .5; },\n\t\t\t\tcapSize: function (v) { return +v * .5; },\n\t\t\t\topacity: parseFloat,\n\t\t\t\terrors: function (errors) {\n\t\t\t\t\terrors = flatten(errors)\n\n\t\t\t\t\terrorCount += errors.length\n\t\t\t\t\treturn errors\n\t\t\t\t},\n\t\t\t\tpositions: function (positions, state) {\n\t\t\t\t\tpositions = flatten(positions, 'float64')\n\t\t\t\t\tstate.count = Math.floor(positions.length / 2)\n\t\t\t\t\tstate.bounds = getBounds(positions, 2)\n\t\t\t\t\tstate.offset = pointCount\n\n\t\t\t\t\tpointCount += state.count\n\n\t\t\t\t\treturn positions\n\t\t\t\t}\n\t\t\t}, {\n\t\t\t\tcolor: function (colors, state) {\n\t\t\t\t\tvar count = state.count\n\n\t\t\t\t\tif (!colors) { colors = 'transparent' }\n\n\t\t\t\t\t// 'black' or [0,0,0,0] case\n\t\t\t\t\tif (!Array.isArray(colors) || typeof colors[0] === 'number') {\n\t\t\t\t\t\tvar color = colors\n\t\t\t\t\t\tcolors = Array(count)\n\t\t\t\t\t\tfor (var i = 0; i < count; i++) {\n\t\t\t\t\t\t\tcolors[i] = color\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (colors.length < count) { throw Error('Not enough colors') }\n\n\t\t\t\t\tvar colorData = new Uint8Array(count * 4)\n\n\t\t\t\t\t//convert colors to float arrays\n\t\t\t\t\tfor (var i$1 = 0; i$1 < count; i$1++) {\n\t\t\t\t\t\tvar c = rgba(colors[i$1], 'uint8')\n\t\t\t\t\t\tcolorData.set(c, i$1 * 4)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn colorData\n\t\t\t\t},\n\n\t\t\t\trange: function (range, state, options) {\n\t\t\t\t\tvar bounds = state.bounds\n\t\t\t\t\tif (!range) { range = bounds }\n\n\t\t\t\t\tstate.scale = [1 / (range[2] - range[0]), 1 / (range[3] - range[1])]\n\t\t\t\t\tstate.translate = [-range[0], -range[1]]\n\n\t\t\t\t\tstate.scaleFract = fract32(state.scale)\n\t\t\t\t\tstate.translateFract = fract32(state.translate)\n\n\t\t\t\t\treturn range\n\t\t\t\t},\n\n\t\t\t\tviewport: function (vp) {\n\t\t\t\t\tvar viewport\n\n\t\t\t\t\tif (Array.isArray(vp)) {\n\t\t\t\t\t\tviewport = {\n\t\t\t\t\t\t\tx: vp[0],\n\t\t\t\t\t\t\ty: vp[1],\n\t\t\t\t\t\t\twidth: vp[2] - vp[0],\n\t\t\t\t\t\t\theight: vp[3] - vp[1]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (vp) {\n\t\t\t\t\t\tviewport = {\n\t\t\t\t\t\t\tx: vp.x || vp.left || 0,\n\t\t\t\t\t\t\ty: vp.y || vp.top || 0\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (vp.right) { viewport.width = vp.right - viewport.x }\n\t\t\t\t\t\telse { viewport.width = vp.w || vp.width || 0 }\n\n\t\t\t\t\t\tif (vp.bottom) { viewport.height = vp.bottom - viewport.y }\n\t\t\t\t\t\telse { viewport.height = vp.h || vp.height || 0 }\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tviewport = {\n\t\t\t\t\t\t\tx: 0, y: 0,\n\t\t\t\t\t\t\twidth: gl.drawingBufferWidth,\n\t\t\t\t\t\t\theight: gl.drawingBufferHeight\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn viewport\n\t\t\t\t}\n\t\t\t}])\n\n\t\t\treturn group\n\t\t})\n\n\t\tif (pointCount || errorCount) {\n\t\t\tvar len = groups.reduce(function (acc, group, i) {\n\t\t\t\treturn acc + (group ? group.count : 0)\n\t\t\t}, 0)\n\n\t\t\tvar positionData = new Float64Array(len * 2)\n\t\t\tvar colorData = new Uint8Array(len * 4)\n\t\t\tvar errorData = new Float32Array(len * 4)\n\n\t\t\tgroups.forEach(function (group, i) {\n\t\t\t\tif (!group) { return }\n\t\t\t\tvar positions = group.positions;\n\t\t\t\tvar count = group.count;\n\t\t\t\tvar offset = group.offset;\n\t\t\t\tvar color = group.color;\n\t\t\t\tvar errors = group.errors;\n\t\t\t\tif (!count) { return }\n\n\t\t\t\tcolorData.set(color, offset * 4)\n\t\t\t\terrorData.set(errors, offset * 4)\n\t\t\t\tpositionData.set(positions, offset * 2)\n\t\t\t})\n\n\t\t\tpositionBuffer(float32(positionData))\n\t\t\tpositionFractBuffer(fract32(positionData))\n\t\t\tcolorBuffer(colorData)\n\t\t\terrorBuffer(errorData)\n\t\t}\n\n\t}\n\n\tfunction destroy () {\n\t\tpositionBuffer.destroy()\n\t\tpositionFractBuffer.destroy()\n\t\tcolorBuffer.destroy()\n\t\terrorBuffer.destroy()\n\t\tmeshBuffer.destroy()\n\t}\n}\n\n},{\"array-bounds\":65,\"color-normalize\":120,\"flatten-vertex-data\":227,\"object-assign\":454,\"pick-by-alias\":465,\"to-float32\":538,\"update-diff\":549}],491:[function(_dereq_,module,exports){\n'use strict'\n\n\nvar rgba = _dereq_('color-normalize')\nvar getBounds = _dereq_('array-bounds')\nvar extend = _dereq_('object-assign')\nvar glslify = _dereq_('glslify')\nvar pick = _dereq_('pick-by-alias')\nvar flatten = _dereq_('flatten-vertex-data')\nvar triangulate = _dereq_('earcut')\nvar normalize = _dereq_('array-normalize')\nvar ref = _dereq_('to-float32');\nvar float32 = ref.float32;\nvar fract32 = ref.fract32;\nvar WeakMap = _dereq_('es6-weak-map')\nvar parseRect = _dereq_('parse-rect')\n\n\nmodule.exports = Line2D\n\n\n/** @constructor */\nfunction Line2D (regl, options) {\n\tif (!(this instanceof Line2D)) { return new Line2D(regl, options) }\n\n\tif (typeof regl === 'function') {\n\t\tif (!options) { options = {} }\n\t\toptions.regl = regl\n\t}\n\telse {\n\t\toptions = regl\n\t}\n\tif (options.length) { options.positions = options }\n\tregl = options.regl\n\n\tif (!regl.hasExtension('ANGLE_instanced_arrays')) {\n\t\tthrow Error('regl-error2d: `ANGLE_instanced_arrays` extension should be enabled');\n\t}\n\n\t// persistent variables\n\tthis.gl = regl._gl\n\tthis.regl = regl\n\n\t// list of options for lines\n\tthis.passes = []\n\n\t// cached shaders instance\n\tthis.shaders = Line2D.shaders.has(regl) ? Line2D.shaders.get(regl) : Line2D.shaders.set(regl, Line2D.createShaders(regl)).get(regl)\n\n\n\t// init defaults\n\tthis.update(options)\n}\n\n\nLine2D.dashMult = 2\nLine2D.maxPatternLength = 256\nLine2D.precisionThreshold = 3e6\nLine2D.maxPoints = 1e4\nLine2D.maxLines = 2048\n\n\n// cache of created draw calls per-regl instance\nLine2D.shaders = new WeakMap()\n\n\n// create static shaders once\nLine2D.createShaders = function (regl) {\n\tvar offsetBuffer = regl.buffer({\n\t\tusage: 'static',\n\t\ttype: 'float',\n\t\tdata: [0,1, 0,0, 1,1, 1,0]\n\t})\n\n\tvar shaderOptions = {\n\t\tprimitive: 'triangle strip',\n\t\tinstances: regl.prop('count'),\n\t\tcount: 4,\n\t\toffset: 0,\n\n\t\tuniforms: {\n\t\t\tmiterMode: function (ctx, prop) { return prop.join === 'round' ? 2 : 1; },\n\t\t\tmiterLimit: regl.prop('miterLimit'),\n\t\t\tscale: regl.prop('scale'),\n\t\t\tscaleFract: regl.prop('scaleFract'),\n\t\t\ttranslateFract: regl.prop('translateFract'),\n\t\t\ttranslate: regl.prop('translate'),\n\t\t\tthickness: regl.prop('thickness'),\n\t\t\tdashPattern: regl.prop('dashTexture'),\n\t\t\topacity: regl.prop('opacity'),\n\t\t\tpixelRatio: regl.context('pixelRatio'),\n\t\t\tid: regl.prop('id'),\n\t\t\tdashSize: regl.prop('dashLength'),\n\t\t\tviewport: function (c, p) { return [p.viewport.x, p.viewport.y, c.viewportWidth, c.viewportHeight]; },\n\t\t\tdepth: regl.prop('depth')\n\t\t},\n\n\t\tblend: {\n\t\t\tenable: true,\n\t\t\tcolor: [0,0,0,0],\n\t\t\tequation: {\n\t\t\t\trgb: 'add',\n\t\t\t\talpha: 'add'\n\t\t\t},\n\t\t\tfunc: {\n\t\t\t\tsrcRGB: 'src alpha',\n\t\t\t\tdstRGB: 'one minus src alpha',\n\t\t\t\tsrcAlpha: 'one minus dst alpha',\n\t\t\t\tdstAlpha: 'one'\n\t\t\t}\n\t\t},\n\t\tdepth: {\n\t\t\tenable: function (c, p) {\n\t\t\t\treturn !p.overlay\n\t\t\t}\n\t\t},\n\t\tstencil: {enable: false},\n\t\tscissor: {\n\t\t\tenable: true,\n\t\t\tbox: regl.prop('viewport')\n\t\t},\n\t\tviewport: regl.prop('viewport')\n\t}\n\n\n\t// simplified rectangular line shader\n\tvar drawRectLine = regl(extend({\n\t\tvert: glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec2 aCoord, bCoord, aCoordFract, bCoordFract;\\nattribute vec4 color;\\nattribute float lineEnd, lineTop;\\n\\nuniform vec2 scale, scaleFract, translate, translateFract;\\nuniform float thickness, pixelRatio, id, depth;\\nuniform vec4 viewport;\\n\\nvarying vec4 fragColor;\\nvarying vec2 tangent;\\n\\nvec2 project(vec2 position, vec2 positionFract, vec2 scale, vec2 scaleFract, vec2 translate, vec2 translateFract) {\\n\\t// the order is important\\n\\treturn position * scale + translate\\n       + positionFract * scale + translateFract\\n       + position * scaleFract\\n       + positionFract * scaleFract;\\n}\\n\\nvoid main() {\\n\\tfloat lineStart = 1. - lineEnd;\\n\\tfloat lineOffset = lineTop * 2. - 1.;\\n\\n\\tvec2 diff = (bCoord + bCoordFract - aCoord - aCoordFract);\\n\\ttangent = normalize(diff * scale * viewport.zw);\\n\\tvec2 normal = vec2(-tangent.y, tangent.x);\\n\\n\\tvec2 position = project(aCoord, aCoordFract, scale, scaleFract, translate, translateFract) * lineStart\\n\\t\\t+ project(bCoord, bCoordFract, scale, scaleFract, translate, translateFract) * lineEnd\\n\\n\\t\\t+ thickness * normal * .5 * lineOffset / viewport.zw;\\n\\n\\tgl_Position = vec4(position * 2.0 - 1.0, depth, 1);\\n\\n\\tfragColor = color / 255.;\\n}\\n\"]),\n\t\tfrag: glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nuniform sampler2D dashPattern;\\n\\nuniform float dashSize, pixelRatio, thickness, opacity, id;\\n\\nvarying vec4 fragColor;\\nvarying vec2 tangent;\\n\\nvoid main() {\\n\\tfloat alpha = 1.;\\n\\n\\tfloat t = fract(dot(tangent, gl_FragCoord.xy) / dashSize) * .5 + .25;\\n\\tfloat dash = texture2D(dashPattern, vec2(t, .5)).r;\\n\\n\\tgl_FragColor = fragColor;\\n\\tgl_FragColor.a *= alpha * opacity * dash;\\n}\\n\"]),\n\n\t\tattributes: {\n\t\t\t// if point is at the end of segment\n\t\t\tlineEnd: {\n\t\t\t\tbuffer: offsetBuffer,\n\t\t\t\tdivisor: 0,\n\t\t\t\tstride: 8,\n\t\t\t\toffset: 0\n\t\t\t},\n\t\t\t// if point is at the top of segment\n\t\t\tlineTop: {\n\t\t\t\tbuffer: offsetBuffer,\n\t\t\t\tdivisor: 0,\n\t\t\t\tstride: 8,\n\t\t\t\toffset: 4\n\t\t\t},\n\t\t\t// beginning of line coordinate\n\t\t\taCoord: {\n\t\t\t\tbuffer: regl.prop('positionBuffer'),\n\t\t\t\tstride: 8,\n\t\t\t\toffset: 8,\n\t\t\t\tdivisor: 1\n\t\t\t},\n\t\t\t// end of line coordinate\n\t\t\tbCoord: {\n\t\t\t\tbuffer: regl.prop('positionBuffer'),\n\t\t\t\tstride: 8,\n\t\t\t\toffset: 16,\n\t\t\t\tdivisor: 1\n\t\t\t},\n\t\t\taCoordFract: {\n\t\t\t\tbuffer: regl.prop('positionFractBuffer'),\n\t\t\t\tstride: 8,\n\t\t\t\toffset: 8,\n\t\t\t\tdivisor: 1\n\t\t\t},\n\t\t\tbCoordFract: {\n\t\t\t\tbuffer: regl.prop('positionFractBuffer'),\n\t\t\t\tstride: 8,\n\t\t\t\toffset: 16,\n\t\t\t\tdivisor: 1\n\t\t\t},\n\t\t\tcolor: {\n\t\t\t\tbuffer: regl.prop('colorBuffer'),\n\t\t\t\tstride: 4,\n\t\t\t\toffset: 0,\n\t\t\t\tdivisor: 1\n\t\t\t}\n\t\t}\n\t}, shaderOptions))\n\n\t// create regl draw\n\tvar drawMiterLine\n\n\ttry {\n\t\tdrawMiterLine = regl(extend({\n\t\t\t// culling removes polygon creasing\n\t\t\tcull: {\n\t\t\t\tenable: true,\n\t\t\t\tface: 'back'\n\t\t\t},\n\n\t\t\tvert: glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec2 aCoord, bCoord, nextCoord, prevCoord;\\nattribute vec4 aColor, bColor;\\nattribute float lineEnd, lineTop;\\n\\nuniform vec2 scale, translate;\\nuniform float thickness, pixelRatio, id, depth;\\nuniform vec4 viewport;\\nuniform float miterLimit, miterMode;\\n\\nvarying vec4 fragColor;\\nvarying vec4 startCutoff, endCutoff;\\nvarying vec2 tangent;\\nvarying vec2 startCoord, endCoord;\\nvarying float enableStartMiter, enableEndMiter;\\n\\nconst float REVERSE_THRESHOLD = -.875;\\nconst float MIN_DIFF = 1e-6;\\n\\n// TODO: possible optimizations: avoid overcalculating all for vertices and calc just one instead\\n// TODO: precalculate dot products, normalize things beforehead etc.\\n// TODO: refactor to rectangular algorithm\\n\\nfloat distToLine(vec2 p, vec2 a, vec2 b) {\\n\\tvec2 diff = b - a;\\n\\tvec2 perp = normalize(vec2(-diff.y, diff.x));\\n\\treturn dot(p - a, perp);\\n}\\n\\nbool isNaN( float val ){\\n  return ( val < 0.0 || 0.0 < val || val == 0.0 ) ? false : true;\\n}\\n\\nvoid main() {\\n\\tvec2 aCoord = aCoord, bCoord = bCoord, prevCoord = prevCoord, nextCoord = nextCoord;\\n\\n  vec2 adjustedScale;\\n  adjustedScale.x = (abs(scale.x) < MIN_DIFF) ? MIN_DIFF : scale.x;\\n  adjustedScale.y = (abs(scale.y) < MIN_DIFF) ? MIN_DIFF : scale.y;\\n\\n  vec2 scaleRatio = adjustedScale * viewport.zw;\\n\\tvec2 normalWidth = thickness / scaleRatio;\\n\\n\\tfloat lineStart = 1. - lineEnd;\\n\\tfloat lineBot = 1. - lineTop;\\n\\n\\tfragColor = (lineStart * aColor + lineEnd * bColor) / 255.;\\n\\n\\tif (isNaN(aCoord.x) || isNaN(aCoord.y) || isNaN(bCoord.x) || isNaN(bCoord.y)) return;\\n\\n\\tif (aCoord == prevCoord) prevCoord = aCoord + normalize(bCoord - aCoord);\\n\\tif (bCoord == nextCoord) nextCoord = bCoord - normalize(bCoord - aCoord);\\n\\n\\tvec2 prevDiff = aCoord - prevCoord;\\n\\tvec2 currDiff = bCoord - aCoord;\\n\\tvec2 nextDiff = nextCoord - bCoord;\\n\\n\\tvec2 prevTangent = normalize(prevDiff * scaleRatio);\\n\\tvec2 currTangent = normalize(currDiff * scaleRatio);\\n\\tvec2 nextTangent = normalize(nextDiff * scaleRatio);\\n\\n\\tvec2 prevNormal = vec2(-prevTangent.y, prevTangent.x);\\n\\tvec2 currNormal = vec2(-currTangent.y, currTangent.x);\\n\\tvec2 nextNormal = vec2(-nextTangent.y, nextTangent.x);\\n\\n\\tvec2 startJoinDirection = normalize(prevTangent - currTangent);\\n\\tvec2 endJoinDirection = normalize(currTangent - nextTangent);\\n\\n\\t// collapsed/unidirectional segment cases\\n\\t// FIXME: there should be more elegant solution\\n\\tvec2 prevTanDiff = abs(prevTangent - currTangent);\\n\\tvec2 nextTanDiff = abs(nextTangent - currTangent);\\n\\tif (max(prevTanDiff.x, prevTanDiff.y) < MIN_DIFF) {\\n\\t\\tstartJoinDirection = currNormal;\\n\\t}\\n\\tif (max(nextTanDiff.x, nextTanDiff.y) < MIN_DIFF) {\\n\\t\\tendJoinDirection = currNormal;\\n\\t}\\n\\tif (aCoord == bCoord) {\\n\\t\\tendJoinDirection = startJoinDirection;\\n\\t\\tcurrNormal = prevNormal;\\n\\t\\tcurrTangent = prevTangent;\\n\\t}\\n\\n\\ttangent = currTangent;\\n\\n\\t//calculate join shifts relative to normals\\n\\tfloat startJoinShift = dot(currNormal, startJoinDirection);\\n\\tfloat endJoinShift = dot(currNormal, endJoinDirection);\\n\\n\\tfloat startMiterRatio = abs(1. / startJoinShift);\\n\\tfloat endMiterRatio = abs(1. / endJoinShift);\\n\\n\\tvec2 startJoin = startJoinDirection * startMiterRatio;\\n\\tvec2 endJoin = endJoinDirection * endMiterRatio;\\n\\n\\tvec2 startTopJoin, startBotJoin, endTopJoin, endBotJoin;\\n\\tstartTopJoin = sign(startJoinShift) * startJoin * .5;\\n\\tstartBotJoin = -startTopJoin;\\n\\n\\tendTopJoin = sign(endJoinShift) * endJoin * .5;\\n\\tendBotJoin = -endTopJoin;\\n\\n\\tvec2 aTopCoord = aCoord + normalWidth * startTopJoin;\\n\\tvec2 bTopCoord = bCoord + normalWidth * endTopJoin;\\n\\tvec2 aBotCoord = aCoord + normalWidth * startBotJoin;\\n\\tvec2 bBotCoord = bCoord + normalWidth * endBotJoin;\\n\\n\\t//miter anti-clipping\\n\\tfloat baClipping = distToLine(bCoord, aCoord, aBotCoord) / dot(normalize(normalWidth * endBotJoin), normalize(normalWidth.yx * vec2(-startBotJoin.y, startBotJoin.x)));\\n\\tfloat abClipping = distToLine(aCoord, bCoord, bTopCoord) / dot(normalize(normalWidth * startBotJoin), normalize(normalWidth.yx * vec2(-endBotJoin.y, endBotJoin.x)));\\n\\n\\t//prevent close to reverse direction switch\\n\\tbool prevReverse = dot(currTangent, prevTangent) <= REVERSE_THRESHOLD && abs(dot(currTangent, prevNormal)) * min(length(prevDiff), length(currDiff)) <  length(normalWidth * currNormal);\\n\\tbool nextReverse = dot(currTangent, nextTangent) <= REVERSE_THRESHOLD && abs(dot(currTangent, nextNormal)) * min(length(nextDiff), length(currDiff)) <  length(normalWidth * currNormal);\\n\\n\\tif (prevReverse) {\\n\\t\\t//make join rectangular\\n\\t\\tvec2 miterShift = normalWidth * startJoinDirection * miterLimit * .5;\\n\\t\\tfloat normalAdjust = 1. - min(miterLimit / startMiterRatio, 1.);\\n\\t\\taBotCoord = aCoord + miterShift - normalAdjust * normalWidth * currNormal * .5;\\n\\t\\taTopCoord = aCoord + miterShift + normalAdjust * normalWidth * currNormal * .5;\\n\\t}\\n\\telse if (!nextReverse && baClipping > 0. && baClipping < length(normalWidth * endBotJoin)) {\\n\\t\\t//handle miter clipping\\n\\t\\tbTopCoord -= normalWidth * endTopJoin;\\n\\t\\tbTopCoord += normalize(endTopJoin * normalWidth) * baClipping;\\n\\t}\\n\\n\\tif (nextReverse) {\\n\\t\\t//make join rectangular\\n\\t\\tvec2 miterShift = normalWidth * endJoinDirection * miterLimit * .5;\\n\\t\\tfloat normalAdjust = 1. - min(miterLimit / endMiterRatio, 1.);\\n\\t\\tbBotCoord = bCoord + miterShift - normalAdjust * normalWidth * currNormal * .5;\\n\\t\\tbTopCoord = bCoord + miterShift + normalAdjust * normalWidth * currNormal * .5;\\n\\t}\\n\\telse if (!prevReverse && abClipping > 0. && abClipping < length(normalWidth * startBotJoin)) {\\n\\t\\t//handle miter clipping\\n\\t\\taBotCoord -= normalWidth * startBotJoin;\\n\\t\\taBotCoord += normalize(startBotJoin * normalWidth) * abClipping;\\n\\t}\\n\\n\\tvec2 aTopPosition = (aTopCoord) * adjustedScale + translate;\\n\\tvec2 aBotPosition = (aBotCoord) * adjustedScale + translate;\\n\\n\\tvec2 bTopPosition = (bTopCoord) * adjustedScale + translate;\\n\\tvec2 bBotPosition = (bBotCoord) * adjustedScale + translate;\\n\\n\\t//position is normalized 0..1 coord on the screen\\n\\tvec2 position = (aTopPosition * lineTop + aBotPosition * lineBot) * lineStart + (bTopPosition * lineTop + bBotPosition * lineBot) * lineEnd;\\n\\n\\tstartCoord = aCoord * scaleRatio + translate * viewport.zw + viewport.xy;\\n\\tendCoord = bCoord * scaleRatio + translate * viewport.zw + viewport.xy;\\n\\n\\tgl_Position = vec4(position  * 2.0 - 1.0, depth, 1);\\n\\n\\tenableStartMiter = step(dot(currTangent, prevTangent), .5);\\n\\tenableEndMiter = step(dot(currTangent, nextTangent), .5);\\n\\n\\t//bevel miter cutoffs\\n\\tif (miterMode == 1.) {\\n\\t\\tif (enableStartMiter == 1.) {\\n\\t\\t\\tvec2 startMiterWidth = vec2(startJoinDirection) * thickness * miterLimit * .5;\\n\\t\\t\\tstartCutoff = vec4(aCoord, aCoord);\\n\\t\\t\\tstartCutoff.zw += vec2(-startJoinDirection.y, startJoinDirection.x) / scaleRatio;\\n\\t\\t\\tstartCutoff = startCutoff * scaleRatio.xyxy + translate.xyxy * viewport.zwzw;\\n\\t\\t\\tstartCutoff += viewport.xyxy;\\n\\t\\t\\tstartCutoff += startMiterWidth.xyxy;\\n\\t\\t}\\n\\n\\t\\tif (enableEndMiter == 1.) {\\n\\t\\t\\tvec2 endMiterWidth = vec2(endJoinDirection) * thickness * miterLimit * .5;\\n\\t\\t\\tendCutoff = vec4(bCoord, bCoord);\\n\\t\\t\\tendCutoff.zw += vec2(-endJoinDirection.y, endJoinDirection.x)  / scaleRatio;\\n\\t\\t\\tendCutoff = endCutoff * scaleRatio.xyxy + translate.xyxy * viewport.zwzw;\\n\\t\\t\\tendCutoff += viewport.xyxy;\\n\\t\\t\\tendCutoff += endMiterWidth.xyxy;\\n\\t\\t}\\n\\t}\\n\\n\\t//round miter cutoffs\\n\\telse if (miterMode == 2.) {\\n\\t\\tif (enableStartMiter == 1.) {\\n\\t\\t\\tvec2 startMiterWidth = vec2(startJoinDirection) * thickness * abs(dot(startJoinDirection, currNormal)) * .5;\\n\\t\\t\\tstartCutoff = vec4(aCoord, aCoord);\\n\\t\\t\\tstartCutoff.zw += vec2(-startJoinDirection.y, startJoinDirection.x) / scaleRatio;\\n\\t\\t\\tstartCutoff = startCutoff * scaleRatio.xyxy + translate.xyxy * viewport.zwzw;\\n\\t\\t\\tstartCutoff += viewport.xyxy;\\n\\t\\t\\tstartCutoff += startMiterWidth.xyxy;\\n\\t\\t}\\n\\n\\t\\tif (enableEndMiter == 1.) {\\n\\t\\t\\tvec2 endMiterWidth = vec2(endJoinDirection) * thickness * abs(dot(endJoinDirection, currNormal)) * .5;\\n\\t\\t\\tendCutoff = vec4(bCoord, bCoord);\\n\\t\\t\\tendCutoff.zw += vec2(-endJoinDirection.y, endJoinDirection.x)  / scaleRatio;\\n\\t\\t\\tendCutoff = endCutoff * scaleRatio.xyxy + translate.xyxy * viewport.zwzw;\\n\\t\\t\\tendCutoff += viewport.xyxy;\\n\\t\\t\\tendCutoff += endMiterWidth.xyxy;\\n\\t\\t}\\n\\t}\\n}\\n\"]),\n\t\t\tfrag: glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nuniform sampler2D dashPattern;\\nuniform float dashSize, pixelRatio, thickness, opacity, id, miterMode;\\n\\nvarying vec4 fragColor;\\nvarying vec2 tangent;\\nvarying vec4 startCutoff, endCutoff;\\nvarying vec2 startCoord, endCoord;\\nvarying float enableStartMiter, enableEndMiter;\\n\\nfloat distToLine(vec2 p, vec2 a, vec2 b) {\\n\\tvec2 diff = b - a;\\n\\tvec2 perp = normalize(vec2(-diff.y, diff.x));\\n\\treturn dot(p - a, perp);\\n}\\n\\nvoid main() {\\n\\tfloat alpha = 1., distToStart, distToEnd;\\n\\tfloat cutoff = thickness * .5;\\n\\n\\t//bevel miter\\n\\tif (miterMode == 1.) {\\n\\t\\tif (enableStartMiter == 1.) {\\n\\t\\t\\tdistToStart = distToLine(gl_FragCoord.xy, startCutoff.xy, startCutoff.zw);\\n\\t\\t\\tif (distToStart < -1.) {\\n\\t\\t\\t\\tdiscard;\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\t\\t\\talpha *= min(max(distToStart + 1., 0.), 1.);\\n\\t\\t}\\n\\n\\t\\tif (enableEndMiter == 1.) {\\n\\t\\t\\tdistToEnd = distToLine(gl_FragCoord.xy, endCutoff.xy, endCutoff.zw);\\n\\t\\t\\tif (distToEnd < -1.) {\\n\\t\\t\\t\\tdiscard;\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\t\\t\\talpha *= min(max(distToEnd + 1., 0.), 1.);\\n\\t\\t}\\n\\t}\\n\\n\\t// round miter\\n\\telse if (miterMode == 2.) {\\n\\t\\tif (enableStartMiter == 1.) {\\n\\t\\t\\tdistToStart = distToLine(gl_FragCoord.xy, startCutoff.xy, startCutoff.zw);\\n\\t\\t\\tif (distToStart < 0.) {\\n\\t\\t\\t\\tfloat radius = length(gl_FragCoord.xy - startCoord);\\n\\n\\t\\t\\t\\tif(radius > cutoff + .5) {\\n\\t\\t\\t\\t\\tdiscard;\\n\\t\\t\\t\\t\\treturn;\\n\\t\\t\\t\\t}\\n\\n\\t\\t\\t\\talpha -= smoothstep(cutoff - .5, cutoff + .5, radius);\\n\\t\\t\\t}\\n\\t\\t}\\n\\n\\t\\tif (enableEndMiter == 1.) {\\n\\t\\t\\tdistToEnd = distToLine(gl_FragCoord.xy, endCutoff.xy, endCutoff.zw);\\n\\t\\t\\tif (distToEnd < 0.) {\\n\\t\\t\\t\\tfloat radius = length(gl_FragCoord.xy - endCoord);\\n\\n\\t\\t\\t\\tif(radius > cutoff + .5) {\\n\\t\\t\\t\\t\\tdiscard;\\n\\t\\t\\t\\t\\treturn;\\n\\t\\t\\t\\t}\\n\\n\\t\\t\\t\\talpha -= smoothstep(cutoff - .5, cutoff + .5, radius);\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\n\\tfloat t = fract(dot(tangent, gl_FragCoord.xy) / dashSize) * .5 + .25;\\n\\tfloat dash = texture2D(dashPattern, vec2(t, .5)).r;\\n\\n\\tgl_FragColor = fragColor;\\n\\tgl_FragColor.a *= alpha * opacity * dash;\\n}\\n\"]),\n\n\t\t\tattributes: {\n\t\t\t\t// is line end\n\t\t\t\tlineEnd: {\n\t\t\t\t\tbuffer: offsetBuffer,\n\t\t\t\t\tdivisor: 0,\n\t\t\t\t\tstride: 8,\n\t\t\t\t\toffset: 0\n\t\t\t\t},\n\t\t\t\t// is line top\n\t\t\t\tlineTop: {\n\t\t\t\t\tbuffer: offsetBuffer,\n\t\t\t\t\tdivisor: 0,\n\t\t\t\t\tstride: 8,\n\t\t\t\t\toffset: 4\n\t\t\t\t},\n\t\t\t\t// left color\n\t\t\t\taColor: {\n\t\t\t\t\tbuffer: regl.prop('colorBuffer'),\n\t\t\t\t\tstride: 4,\n\t\t\t\t\toffset: 0,\n\t\t\t\t\tdivisor: 1\n\t\t\t\t},\n\t\t\t\t// right color\n\t\t\t\tbColor: {\n\t\t\t\t\tbuffer: regl.prop('colorBuffer'),\n\t\t\t\t\tstride: 4,\n\t\t\t\t\toffset: 4,\n\t\t\t\t\tdivisor: 1\n\t\t\t\t},\n\t\t\t\tprevCoord: {\n\t\t\t\t\tbuffer: regl.prop('positionBuffer'),\n\t\t\t\t\tstride: 8,\n\t\t\t\t\toffset: 0,\n\t\t\t\t\tdivisor: 1\n\t\t\t\t},\n\t\t\t\taCoord: {\n\t\t\t\t\tbuffer: regl.prop('positionBuffer'),\n\t\t\t\t\tstride: 8,\n\t\t\t\t\toffset: 8,\n\t\t\t\t\tdivisor: 1\n\t\t\t\t},\n\t\t\t\tbCoord: {\n\t\t\t\t\tbuffer: regl.prop('positionBuffer'),\n\t\t\t\t\tstride: 8,\n\t\t\t\t\toffset: 16,\n\t\t\t\t\tdivisor: 1\n\t\t\t\t},\n\t\t\t\tnextCoord: {\n\t\t\t\t\tbuffer: regl.prop('positionBuffer'),\n\t\t\t\t\tstride: 8,\n\t\t\t\t\toffset: 24,\n\t\t\t\t\tdivisor: 1\n\t\t\t\t}\n\t\t\t}\n\t\t}, shaderOptions))\n\t} catch (e) {\n\t\t// IE/bad Webkit fallback\n\t\tdrawMiterLine = drawRectLine\n\t}\n\n\t// fill shader\n\tvar drawFill = regl({\n\t\tprimitive: 'triangle',\n\t\telements: function (ctx, prop) { return prop.triangles; },\n\t\toffset: 0,\n\n\t\tvert: glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute vec2 position, positionFract;\\n\\nuniform vec4 color;\\nuniform vec2 scale, scaleFract, translate, translateFract;\\nuniform float pixelRatio, id;\\nuniform vec4 viewport;\\nuniform float opacity;\\n\\nvarying vec4 fragColor;\\n\\nconst float MAX_LINES = 256.;\\n\\nvoid main() {\\n\\tfloat depth = (MAX_LINES - 4. - id) / (MAX_LINES);\\n\\n\\tvec2 position = position * scale + translate\\n       + positionFract * scale + translateFract\\n       + position * scaleFract\\n       + positionFract * scaleFract;\\n\\n\\tgl_Position = vec4(position * 2.0 - 1.0, depth, 1);\\n\\n\\tfragColor = color / 255.;\\n\\tfragColor.a *= opacity;\\n}\\n\"]),\n\t\tfrag: glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nvarying vec4 fragColor;\\n\\nvoid main() {\\n\\tgl_FragColor = fragColor;\\n}\\n\"]),\n\n\t\tuniforms: {\n\t\t\tscale: regl.prop('scale'),\n\t\t\tcolor: regl.prop('fill'),\n\t\t\tscaleFract: regl.prop('scaleFract'),\n\t\t\ttranslateFract: regl.prop('translateFract'),\n\t\t\ttranslate: regl.prop('translate'),\n\t\t\topacity: regl.prop('opacity'),\n\t\t\tpixelRatio: regl.context('pixelRatio'),\n\t\t\tid: regl.prop('id'),\n\t\t\tviewport: function (ctx, prop) { return [prop.viewport.x, prop.viewport.y, ctx.viewportWidth, ctx.viewportHeight]; }\n\t\t},\n\n\t\tattributes: {\n\t\t\tposition: {\n\t\t\t\tbuffer: regl.prop('positionBuffer'),\n\t\t\t\tstride: 8,\n\t\t\t\toffset: 8\n\t\t\t},\n\t\t\tpositionFract: {\n\t\t\t\tbuffer: regl.prop('positionFractBuffer'),\n\t\t\t\tstride: 8,\n\t\t\t\toffset: 8\n\t\t\t}\n\t\t},\n\n\t\tblend: shaderOptions.blend,\n\n\t\tdepth: { enable: false },\n\t\tscissor: shaderOptions.scissor,\n\t\tstencil: shaderOptions.stencil,\n\t\tviewport: shaderOptions.viewport\n\t})\n\n\treturn {\n\t\tfill: drawFill, rect: drawRectLine, miter: drawMiterLine\n\t}\n}\n\n\n// used to for new lines instances\nLine2D.defaults = {\n\tdashes: null,\n\tjoin: 'miter',\n\tmiterLimit: 1,\n\tthickness: 10,\n\tcap: 'square',\n\tcolor: 'black',\n\topacity: 1,\n\toverlay: false,\n\tviewport: null,\n\trange: null,\n\tclose: false,\n\tfill: null\n}\n\n\nLine2D.prototype.render = function () {\n\tvar ref;\n\n\tvar args = [], len = arguments.length;\n\twhile ( len-- ) args[ len ] = arguments[ len ];\n\tif (args.length) {\n\t\t(ref = this).update.apply(ref, args)\n\t}\n\n\tthis.draw()\n}\n\n\nLine2D.prototype.draw = function () {\n\tvar this$1 = this;\n\tvar args = [], len = arguments.length;\n\twhile ( len-- ) args[ len ] = arguments[ len ];\n\n\t// render multiple polylines via regl batch\n\t(args.length ? args : this.passes).forEach(function (s, i) {\n\t\tvar ref;\n\n\t\t// render array pass as a list of passes\n\t\tif (s && Array.isArray(s)) { return (ref = this$1).draw.apply(ref, s) }\n\n\t\tif (typeof s === 'number') { s = this$1.passes[s] }\n\n\t\tif (!(s && s.count > 1 && s.opacity)) { return }\n\n\t\tthis$1.regl._refresh()\n\n\t\tif (s.fill && s.triangles && s.triangles.length > 2) {\n\t\t\tthis$1.shaders.fill(s)\n\t\t}\n\n\t\tif (!s.thickness) { return }\n\n\t\t// high scale is only available for rect mode with precision\n\t\tif (s.scale[0] * s.viewport.width > Line2D.precisionThreshold || s.scale[1] * s.viewport.height > Line2D.precisionThreshold) {\n\t\t\tthis$1.shaders.rect(s)\n\t\t}\n\n\t\t// thin this.passes or too many points are rendered as simplified rect shader\n\t\telse if (s.join === 'rect' || (!s.join && (s.thickness <= 2 || s.count >= Line2D.maxPoints))) {\n\t\t\tthis$1.shaders.rect(s)\n\t\t}\n\t\telse {\n\t\t\tthis$1.shaders.miter(s)\n\t\t}\n\t})\n\n\treturn this\n}\n\nLine2D.prototype.update = function (options) {\n\tvar this$1 = this;\n\n\tif (!options) { return }\n\n\tif (options.length != null) {\n\t\tif (typeof options[0] === 'number') { options = [{positions: options}] }\n\t}\n\n\t// make options a batch\n\telse if (!Array.isArray(options)) { options = [options] }\n\n\tvar ref = this;\n\tvar regl = ref.regl;\n\tvar gl = ref.gl;\n\n\t// process per-line settings\n\toptions.forEach(function (o, i) {\n\t\tvar state = this$1.passes[i]\n\n\t\tif (o === undefined) { return }\n\n\t\t// null-argument removes pass\n\t\tif (o === null) {\n\t\t\tthis$1.passes[i] = null\n\t\t\treturn\n\t\t}\n\n\t\tif (typeof o[0] === 'number') { o = {positions: o} }\n\n\t\t// handle aliases\n\t\to = pick(o, {\n\t\t\tpositions: 'positions points data coords',\n\t\t\tthickness: 'thickness lineWidth lineWidths line-width linewidth width stroke-width strokewidth strokeWidth',\n\t\t\tjoin: 'lineJoin linejoin join type mode',\n\t\t\tmiterLimit: 'miterlimit miterLimit',\n\t\t\tdashes: 'dash dashes dasharray dash-array dashArray',\n\t\t\tcolor: 'color colour stroke colors colours stroke-color strokeColor',\n\t\t\tfill: 'fill fill-color fillColor',\n\t\t\topacity: 'alpha opacity',\n\t\t\toverlay: 'overlay crease overlap intersect',\n\t\t\tclose: 'closed close closed-path closePath',\n\t\t\trange: 'range dataBox',\n\t\t\tviewport: 'viewport viewBox',\n\t\t\thole: 'holes hole hollow'\n\t\t})\n\n\t\t// init state\n\t\tif (!state) {\n\t\t\tthis$1.passes[i] = state = {\n\t\t\t\tid: i,\n\t\t\t\tscale: null,\n\t\t\t\tscaleFract: null,\n\t\t\t\ttranslate: null,\n\t\t\t\ttranslateFract: null,\n\t\t\t\tcount: 0,\n\t\t\t\thole: [],\n\t\t\t\tdepth: 0,\n\n\t\t\t\tdashLength: 1,\n\t\t\t\tdashTexture: regl.texture({\n\t\t\t\t\tchannels: 1,\n\t\t\t\t\tdata: new Uint8Array([255]),\n\t\t\t\t\twidth: 1,\n\t\t\t\t\theight: 1,\n\t\t\t\t\tmag: 'linear',\n\t\t\t\t\tmin: 'linear'\n\t\t\t\t}),\n\n\t\t\t\tcolorBuffer: regl.buffer({\n\t\t\t\t\tusage: 'dynamic',\n\t\t\t\t\ttype: 'uint8',\n\t\t\t\t\tdata: new Uint8Array()\n\t\t\t\t}),\n\t\t\t\tpositionBuffer: regl.buffer({\n\t\t\t\t\tusage: 'dynamic',\n\t\t\t\t\ttype: 'float',\n\t\t\t\t\tdata: new Uint8Array()\n\t\t\t\t}),\n\t\t\t\tpositionFractBuffer: regl.buffer({\n\t\t\t\t\tusage: 'dynamic',\n\t\t\t\t\ttype: 'float',\n\t\t\t\t\tdata: new Uint8Array()\n\t\t\t\t})\n\t\t\t}\n\n\t\t\to = extend({}, Line2D.defaults, o)\n\t\t}\n\t\tif (o.thickness != null) { state.thickness = parseFloat(o.thickness) }\n\t\tif (o.opacity != null) { state.opacity = parseFloat(o.opacity) }\n\t\tif (o.miterLimit != null) { state.miterLimit = parseFloat(o.miterLimit) }\n\t\tif (o.overlay != null) {\n\t\t\tstate.overlay = !!o.overlay\n\t\t\tif (i < Line2D.maxLines) {\n\t\t\t\tstate.depth = 2 * (Line2D.maxLines - 1 - i % Line2D.maxLines) / Line2D.maxLines - 1.;\n\t\t\t}\n\t\t}\n\t\tif (o.join != null) { state.join = o.join }\n\t\tif (o.hole != null) { state.hole = o.hole }\n\t\tif (o.fill != null) { state.fill = !o.fill ? null : rgba(o.fill, 'uint8') }\n\t\tif (o.viewport != null) { state.viewport = parseRect(o.viewport) }\n\n\t\tif (!state.viewport) {\n\t\t\tstate.viewport = parseRect([\n\t\t\t\tgl.drawingBufferWidth,\n\t\t\t\tgl.drawingBufferHeight\n\t\t\t])\n\t\t}\n\n\t\tif (o.close != null) { state.close = o.close }\n\n\t\t// reset positions\n\t\tif (o.positions === null) { o.positions = [] }\n\t\tif (o.positions) {\n\t\t\tvar positions, count\n\n\t\t\t// if positions are an object with x/y\n\t\t\tif (o.positions.x && o.positions.y) {\n\t\t\t\tvar xPos = o.positions.x\n\t\t\t\tvar yPos = o.positions.y\n\t\t\t\tcount = state.count = Math.max(\n\t\t\t\t\txPos.length,\n\t\t\t\t\tyPos.length\n\t\t\t\t)\n\t\t\t\tpositions = new Float64Array(count * 2)\n\t\t\t\tfor (var i$1 = 0; i$1 < count; i$1++) {\n\t\t\t\t\tpositions[i$1 * 2] = xPos[i$1]\n\t\t\t\t\tpositions[i$1 * 2 + 1] = yPos[i$1]\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tpositions = flatten(o.positions, 'float64')\n\t\t\t\tcount = state.count = Math.floor(positions.length / 2)\n\t\t\t}\n\n\t\t\tvar bounds = state.bounds = getBounds(positions, 2)\n\n\t\t\t// create fill positions\n\t\t\t// FIXME: fill positions can be set only along with positions\n\t\t\tif (state.fill) {\n\t\t\t\tvar pos = []\n\n\t\t\t\t// filter bad vertices and remap triangles to ensure shape\n\t\t\t\tvar ids = {}\n\t\t\t\tvar lastId = 0\n\n\t\t\t\tfor (var i$2 = 0, ptr = 0, l = state.count; i$2 < l; i$2++) {\n\t\t\t\t\tvar x = positions[i$2*2]\n\t\t\t\t\tvar y = positions[i$2*2 + 1]\n\t\t\t\t\tif (isNaN(x) || isNaN(y) || x == null || y == null) {\n\t\t\t\t\t\tx = positions[lastId*2]\n\t\t\t\t\t\ty = positions[lastId*2 + 1]\n\t\t\t\t\t\tids[i$2] = lastId\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tlastId = i$2\n\t\t\t\t\t}\n\t\t\t\t\tpos[ptr++] = x\n\t\t\t\t\tpos[ptr++] = y\n\t\t\t\t}\n\n\t\t\t\tvar triangles = triangulate(pos, state.hole || [])\n\n\t\t\t\tfor (var i$3 = 0, l$1 = triangles.length; i$3 < l$1; i$3++) {\n\t\t\t\t\tif (ids[triangles[i$3]] != null) { triangles[i$3] = ids[triangles[i$3]] }\n\t\t\t\t}\n\n\t\t\t\tstate.triangles = triangles\n\t\t\t}\n\n\t\t\t// update position buffers\n\t\t\tvar npos = new Float64Array(positions)\n\t\t\tnormalize(npos, 2, bounds)\n\n\t\t\tvar positionData = new Float64Array(count * 2 + 6)\n\n\t\t\t// rotate first segment join\n\t\t\tif (state.close) {\n\t\t\t\tif (positions[0] === positions[count*2 - 2] &&\n\t\t\t\t\tpositions[1] === positions[count*2 - 1]) {\n\t\t\t\t\tpositionData[0] = npos[count*2 - 4]\n\t\t\t\t\tpositionData[1] = npos[count*2 - 3]\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tpositionData[0] = npos[count*2 - 2]\n\t\t\t\t\tpositionData[1] = npos[count*2 - 1]\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tpositionData[0] = npos[0]\n\t\t\t\tpositionData[1] = npos[1]\n\t\t\t}\n\n\t\t\tpositionData.set(npos, 2)\n\n\t\t\t// add last segment\n\t\t\tif (state.close) {\n\t\t\t\t// ignore coinciding start/end\n\t\t\t\tif (positions[0] === positions[count*2 - 2] &&\n\t\t\t\t\tpositions[1] === positions[count*2 - 1]) {\n\t\t\t\t\tpositionData[count*2 + 2] = npos[2]\n\t\t\t\t\tpositionData[count*2 + 3] = npos[3]\n\t\t\t\t\tstate.count -= 1\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tpositionData[count*2 + 2] = npos[0]\n\t\t\t\t\tpositionData[count*2 + 3] = npos[1]\n\t\t\t\t\tpositionData[count*2 + 4] = npos[2]\n\t\t\t\t\tpositionData[count*2 + 5] = npos[3]\n\t\t\t\t}\n\t\t\t}\n\t\t\t// add stub\n\t\t\telse {\n\t\t\t\tpositionData[count*2 + 2] = npos[count*2 - 2]\n\t\t\t\tpositionData[count*2 + 3] = npos[count*2 - 1]\n\t\t\t\tpositionData[count*2 + 4] = npos[count*2 - 2]\n\t\t\t\tpositionData[count*2 + 5] = npos[count*2 - 1]\n\t\t\t}\n\n\t\t\tstate.positionBuffer(float32(positionData))\n\t\t\tstate.positionFractBuffer(fract32(positionData))\n\t\t}\n\n\t\tif (o.range) {\n\t\t\tstate.range = o.range\n\t\t} else if (!state.range) {\n\t\t\tstate.range = state.bounds\n\t\t}\n\n\t\tif ((o.range || o.positions) && state.count) {\n\t\t\tvar bounds$1 = state.bounds\n\n\t\t\tvar boundsW = bounds$1[2] - bounds$1[0],\n\t\t\t\tboundsH = bounds$1[3] - bounds$1[1]\n\n\t\t\tvar rangeW = state.range[2] - state.range[0],\n\t\t\t\trangeH = state.range[3] - state.range[1]\n\n\t\t\tstate.scale = [\n\t\t\t\tboundsW / rangeW,\n\t\t\t\tboundsH / rangeH\n\t\t\t]\n\t\t\tstate.translate = [\n\t\t\t\t-state.range[0] / rangeW + bounds$1[0] / rangeW || 0,\n\t\t\t\t-state.range[1] / rangeH + bounds$1[1] / rangeH || 0\n\t\t\t]\n\n\t\t\tstate.scaleFract = fract32(state.scale)\n\t\t\tstate.translateFract = fract32(state.translate)\n\t\t}\n\n\t\tif (o.dashes) {\n\t\t\tvar dashLength = 0., dashData\n\n\t\t\tif (!o.dashes || o.dashes.length < 2) {\n\t\t\t\tdashLength = 1.\n\t\t\t\tdashData = new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255])\n\t\t\t}\n\n\t\t\telse {\n\t\t\t\tdashLength = 0.;\n\t\t\t\tfor(var i$4 = 0; i$4 < o.dashes.length; ++i$4) {\n\t\t\t\t\tdashLength += o.dashes[i$4]\n\t\t\t\t}\n\t\t\t\tdashData = new Uint8Array(dashLength * Line2D.dashMult)\n\t\t\t\tvar ptr$1 = 0\n\t\t\t\tvar fillColor = 255\n\n\t\t\t\t// repeat texture two times to provide smooth 0-step\n\t\t\t\tfor (var k = 0; k < 2; k++) {\n\t\t\t\t\tfor(var i$5 = 0; i$5 < o.dashes.length; ++i$5) {\n\t\t\t\t\t\tfor(var j = 0, l$2 = o.dashes[i$5] * Line2D.dashMult * .5; j < l$2; ++j) {\n\t\t\t\t\t\t\tdashData[ptr$1++] = fillColor\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfillColor ^= 255\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstate.dashLength = dashLength\n\t\t\tstate.dashTexture({\n\t\t\t\tchannels: 1,\n\t\t\t\tdata: dashData,\n\t\t\t\twidth: dashData.length,\n\t\t\t\theight: 1,\n\t\t\t\tmag: 'linear',\n\t\t\t\tmin: 'linear'\n\t\t\t}, 0, 0)\n\t\t}\n\n\t\tif (o.color) {\n\t\t\tvar count$1 = state.count\n\t\t\tvar colors = o.color\n\n\t\t\tif (!colors) { colors = 'transparent' }\n\n\t\t\tvar colorData = new Uint8Array(count$1 * 4 + 4)\n\n\t\t\t// convert colors to typed arrays\n\t\t\tif (!Array.isArray(colors) || typeof colors[0] === 'number') {\n\t\t\t\tvar c = rgba(colors, 'uint8')\n\n\t\t\t\tfor (var i$6 = 0; i$6 < count$1 + 1; i$6++) {\n\t\t\t\t\tcolorData.set(c, i$6 * 4)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (var i$7 = 0; i$7 < count$1; i$7++) {\n\t\t\t\t\tvar c$1 = rgba(colors[i$7], 'uint8')\n\t\t\t\t\tcolorData.set(c$1, i$7 * 4)\n\t\t\t\t}\n\t\t\t\tcolorData.set(rgba(colors[0], 'uint8'), count$1 * 4)\n\t\t\t}\n\n\t\t\tstate.colorBuffer({\n\t\t\t\tusage: 'dynamic',\n\t\t\t\ttype: 'uint8',\n\t\t\t\tdata: colorData\n\t\t\t})\n\t\t}\n\t})\n\n\t// remove unmentioned passes\n\tif (options.length < this.passes.length) {\n\t\tfor (var i = options.length; i < this.passes.length; i++) {\n\t\t\tvar pass = this$1.passes[i]\n\t\t\tif (!pass) { continue }\n\t\t\tpass.colorBuffer.destroy()\n\t\t\tpass.positionBuffer.destroy()\n\t\t\tpass.dashTexture.destroy()\n\t\t}\n\t\tthis.passes.length = options.length\n\t}\n\n\t// remove null items\n\tvar passes = []\n\tfor (var i$1 = 0; i$1 < this.passes.length; i$1++) {\n\t\tif (this$1.passes[i$1] !== null) { passes.push(this$1.passes[i$1]) }\n\t}\n\tthis.passes = passes\n\n\treturn this\n}\n\nLine2D.prototype.destroy = function () {\n\tthis.passes.forEach(function (pass) {\n\t\tpass.colorBuffer.destroy()\n\t\tpass.positionBuffer.destroy()\n\t\tpass.dashTexture.destroy()\n\t})\n\n\tthis.passes.length = 0\n\n\treturn this\n}\n\n},{\"array-bounds\":65,\"array-normalize\":66,\"color-normalize\":120,\"earcut\":492,\"es6-weak-map\":493,\"flatten-vertex-data\":227,\"glslify\":409,\"object-assign\":454,\"parse-rect\":459,\"pick-by-alias\":465,\"to-float32\":538}],492:[function(_dereq_,module,exports){\n'use strict';\n\nmodule.exports = earcut;\nmodule.exports.default = earcut;\n\nfunction earcut(data, holeIndices, dim) {\n\n    dim = dim || 2;\n\n    var hasHoles = holeIndices && holeIndices.length,\n        outerLen = hasHoles ? holeIndices[0] * dim : data.length,\n        outerNode = linkedList(data, 0, outerLen, dim, true),\n        triangles = [];\n\n    if (!outerNode || outerNode.next === outerNode.prev) return triangles;\n\n    var minX, minY, maxX, maxY, x, y, invSize;\n\n    if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);\n\n    // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox\n    if (data.length > 80 * dim) {\n        minX = maxX = data[0];\n        minY = maxY = data[1];\n\n        for (var i = dim; i < outerLen; i += dim) {\n            x = data[i];\n            y = data[i + 1];\n            if (x < minX) minX = x;\n            if (y < minY) minY = y;\n            if (x > maxX) maxX = x;\n            if (y > maxY) maxY = y;\n        }\n\n        // minX, minY and invSize are later used to transform coords into integers for z-order calculation\n        invSize = Math.max(maxX - minX, maxY - minY);\n        invSize = invSize !== 0 ? 1 / invSize : 0;\n    }\n\n    earcutLinked(outerNode, triangles, dim, minX, minY, invSize);\n\n    return triangles;\n}\n\n// create a circular doubly linked list from polygon points in the specified winding order\nfunction linkedList(data, start, end, dim, clockwise) {\n    var i, last;\n\n    if (clockwise === (signedArea(data, start, end, dim) > 0)) {\n        for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last);\n    } else {\n        for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last);\n    }\n\n    if (last && equals(last, last.next)) {\n        removeNode(last);\n        last = last.next;\n    }\n\n    return last;\n}\n\n// eliminate colinear or duplicate points\nfunction filterPoints(start, end) {\n    if (!start) return start;\n    if (!end) end = start;\n\n    var p = start,\n        again;\n    do {\n        again = false;\n\n        if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {\n            removeNode(p);\n            p = end = p.prev;\n            if (p === p.next) break;\n            again = true;\n\n        } else {\n            p = p.next;\n        }\n    } while (again || p !== end);\n\n    return end;\n}\n\n// main ear slicing loop which triangulates a polygon (given as a linked list)\nfunction earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {\n    if (!ear) return;\n\n    // interlink polygon nodes in z-order\n    if (!pass && invSize) indexCurve(ear, minX, minY, invSize);\n\n    var stop = ear,\n        prev, next;\n\n    // iterate through ears, slicing them one by one\n    while (ear.prev !== ear.next) {\n        prev = ear.prev;\n        next = ear.next;\n\n        if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {\n            // cut off the triangle\n            triangles.push(prev.i / dim);\n            triangles.push(ear.i / dim);\n            triangles.push(next.i / dim);\n\n            removeNode(ear);\n\n            // skipping the next vertex leads to less sliver triangles\n            ear = next.next;\n            stop = next.next;\n\n            continue;\n        }\n\n        ear = next;\n\n        // if we looped through the whole remaining polygon and can't find any more ears\n        if (ear === stop) {\n            // try filtering points and slicing again\n            if (!pass) {\n                earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);\n\n            // if this didn't work, try curing all small self-intersections locally\n            } else if (pass === 1) {\n                ear = cureLocalIntersections(ear, triangles, dim);\n                earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);\n\n            // as a last resort, try splitting the remaining polygon into two\n            } else if (pass === 2) {\n                splitEarcut(ear, triangles, dim, minX, minY, invSize);\n            }\n\n            break;\n        }\n    }\n}\n\n// check whether a polygon node forms a valid ear with adjacent nodes\nfunction isEar(ear) {\n    var a = ear.prev,\n        b = ear,\n        c = ear.next;\n\n    if (area(a, b, c) >= 0) return false; // reflex, can't be an ear\n\n    // now make sure we don't have other points inside the potential ear\n    var p = ear.next.next;\n\n    while (p !== ear.prev) {\n        if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&\n            area(p.prev, p, p.next) >= 0) return false;\n        p = p.next;\n    }\n\n    return true;\n}\n\nfunction isEarHashed(ear, minX, minY, invSize) {\n    var a = ear.prev,\n        b = ear,\n        c = ear.next;\n\n    if (area(a, b, c) >= 0) return false; // reflex, can't be an ear\n\n    // triangle bbox; min & max are calculated like this for speed\n    var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x),\n        minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y),\n        maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x),\n        maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);\n\n    // z-order range for the current triangle bbox;\n    var minZ = zOrder(minTX, minTY, minX, minY, invSize),\n        maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);\n\n    var p = ear.prevZ,\n        n = ear.nextZ;\n\n    // look for points inside the triangle in both directions\n    while (p && p.z >= minZ && n && n.z <= maxZ) {\n        if (p !== ear.prev && p !== ear.next &&\n            pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&\n            area(p.prev, p, p.next) >= 0) return false;\n        p = p.prevZ;\n\n        if (n !== ear.prev && n !== ear.next &&\n            pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) &&\n            area(n.prev, n, n.next) >= 0) return false;\n        n = n.nextZ;\n    }\n\n    // look for remaining points in decreasing z-order\n    while (p && p.z >= minZ) {\n        if (p !== ear.prev && p !== ear.next &&\n            pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&\n            area(p.prev, p, p.next) >= 0) return false;\n        p = p.prevZ;\n    }\n\n    // look for remaining points in increasing z-order\n    while (n && n.z <= maxZ) {\n        if (n !== ear.prev && n !== ear.next &&\n            pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) &&\n            area(n.prev, n, n.next) >= 0) return false;\n        n = n.nextZ;\n    }\n\n    return true;\n}\n\n// go through all polygon nodes and cure small local self-intersections\nfunction cureLocalIntersections(start, triangles, dim) {\n    var p = start;\n    do {\n        var a = p.prev,\n            b = p.next.next;\n\n        if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {\n\n            triangles.push(a.i / dim);\n            triangles.push(p.i / dim);\n            triangles.push(b.i / dim);\n\n            // remove two nodes involved\n            removeNode(p);\n            removeNode(p.next);\n\n            p = start = b;\n        }\n        p = p.next;\n    } while (p !== start);\n\n    return p;\n}\n\n// try splitting polygon into two and triangulate them independently\nfunction splitEarcut(start, triangles, dim, minX, minY, invSize) {\n    // look for a valid diagonal that divides the polygon into two\n    var a = start;\n    do {\n        var b = a.next.next;\n        while (b !== a.prev) {\n            if (a.i !== b.i && isValidDiagonal(a, b)) {\n                // split the polygon in two by the diagonal\n                var c = splitPolygon(a, b);\n\n                // filter colinear points around the cuts\n                a = filterPoints(a, a.next);\n                c = filterPoints(c, c.next);\n\n                // run earcut on each half\n                earcutLinked(a, triangles, dim, minX, minY, invSize);\n                earcutLinked(c, triangles, dim, minX, minY, invSize);\n                return;\n            }\n            b = b.next;\n        }\n        a = a.next;\n    } while (a !== start);\n}\n\n// link every hole into the outer loop, producing a single-ring polygon without holes\nfunction eliminateHoles(data, holeIndices, outerNode, dim) {\n    var queue = [],\n        i, len, start, end, list;\n\n    for (i = 0, len = holeIndices.length; i < len; i++) {\n        start = holeIndices[i] * dim;\n        end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;\n        list = linkedList(data, start, end, dim, false);\n        if (list === list.next) list.steiner = true;\n        queue.push(getLeftmost(list));\n    }\n\n    queue.sort(compareX);\n\n    // process holes from left to right\n    for (i = 0; i < queue.length; i++) {\n        eliminateHole(queue[i], outerNode);\n        outerNode = filterPoints(outerNode, outerNode.next);\n    }\n\n    return outerNode;\n}\n\nfunction compareX(a, b) {\n    return a.x - b.x;\n}\n\n// find a bridge between vertices that connects hole with an outer ring and and link it\nfunction eliminateHole(hole, outerNode) {\n    outerNode = findHoleBridge(hole, outerNode);\n    if (outerNode) {\n        var b = splitPolygon(outerNode, hole);\n        filterPoints(b, b.next);\n    }\n}\n\n// David Eberly's algorithm for finding a bridge between hole and outer polygon\nfunction findHoleBridge(hole, outerNode) {\n    var p = outerNode,\n        hx = hole.x,\n        hy = hole.y,\n        qx = -Infinity,\n        m;\n\n    // find a segment intersected by a ray from the hole's leftmost point to the left;\n    // segment's endpoint with lesser x will be potential connection point\n    do {\n        if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {\n            var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);\n            if (x <= hx && x > qx) {\n                qx = x;\n                if (x === hx) {\n                    if (hy === p.y) return p;\n                    if (hy === p.next.y) return p.next;\n                }\n                m = p.x < p.next.x ? p : p.next;\n            }\n        }\n        p = p.next;\n    } while (p !== outerNode);\n\n    if (!m) return null;\n\n    if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint\n\n    // look for points inside the triangle of hole point, segment intersection and endpoint;\n    // if there are no points found, we have a valid connection;\n    // otherwise choose the point of the minimum angle with the ray as connection point\n\n    var stop = m,\n        mx = m.x,\n        my = m.y,\n        tanMin = Infinity,\n        tan;\n\n    p = m.next;\n\n    while (p !== stop) {\n        if (hx >= p.x && p.x >= mx && hx !== p.x &&\n                pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {\n\n            tan = Math.abs(hy - p.y) / (hx - p.x); // tangential\n\n            if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) {\n                m = p;\n                tanMin = tan;\n            }\n        }\n\n        p = p.next;\n    }\n\n    return m;\n}\n\n// interlink polygon nodes in z-order\nfunction indexCurve(start, minX, minY, invSize) {\n    var p = start;\n    do {\n        if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);\n        p.prevZ = p.prev;\n        p.nextZ = p.next;\n        p = p.next;\n    } while (p !== start);\n\n    p.prevZ.nextZ = null;\n    p.prevZ = null;\n\n    sortLinked(p);\n}\n\n// Simon Tatham's linked list merge sort algorithm\n// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html\nfunction sortLinked(list) {\n    var i, p, q, e, tail, numMerges, pSize, qSize,\n        inSize = 1;\n\n    do {\n        p = list;\n        list = null;\n        tail = null;\n        numMerges = 0;\n\n        while (p) {\n            numMerges++;\n            q = p;\n            pSize = 0;\n            for (i = 0; i < inSize; i++) {\n                pSize++;\n                q = q.nextZ;\n                if (!q) break;\n            }\n            qSize = inSize;\n\n            while (pSize > 0 || (qSize > 0 && q)) {\n\n                if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {\n                    e = p;\n                    p = p.nextZ;\n                    pSize--;\n                } else {\n                    e = q;\n                    q = q.nextZ;\n                    qSize--;\n                }\n\n                if (tail) tail.nextZ = e;\n                else list = e;\n\n                e.prevZ = tail;\n                tail = e;\n            }\n\n            p = q;\n        }\n\n        tail.nextZ = null;\n        inSize *= 2;\n\n    } while (numMerges > 1);\n\n    return list;\n}\n\n// z-order of a point given coords and inverse of the longer side of data bbox\nfunction zOrder(x, y, minX, minY, invSize) {\n    // coords are transformed into non-negative 15-bit integer range\n    x = 32767 * (x - minX) * invSize;\n    y = 32767 * (y - minY) * invSize;\n\n    x = (x | (x << 8)) & 0x00FF00FF;\n    x = (x | (x << 4)) & 0x0F0F0F0F;\n    x = (x | (x << 2)) & 0x33333333;\n    x = (x | (x << 1)) & 0x55555555;\n\n    y = (y | (y << 8)) & 0x00FF00FF;\n    y = (y | (y << 4)) & 0x0F0F0F0F;\n    y = (y | (y << 2)) & 0x33333333;\n    y = (y | (y << 1)) & 0x55555555;\n\n    return x | (y << 1);\n}\n\n// find the leftmost node of a polygon ring\nfunction getLeftmost(start) {\n    var p = start,\n        leftmost = start;\n    do {\n        if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) leftmost = p;\n        p = p.next;\n    } while (p !== start);\n\n    return leftmost;\n}\n\n// check if a point lies within a convex triangle\nfunction pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {\n    return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&\n           (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&\n           (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;\n}\n\n// check if a diagonal between two polygon nodes is valid (lies in polygon interior)\nfunction isValidDiagonal(a, b) {\n    return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) &&\n           locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);\n}\n\n// signed area of a triangle\nfunction area(p, q, r) {\n    return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);\n}\n\n// check if two points are equal\nfunction equals(p1, p2) {\n    return p1.x === p2.x && p1.y === p2.y;\n}\n\n// check if two segments intersect\nfunction intersects(p1, q1, p2, q2) {\n    if ((equals(p1, q1) && equals(p2, q2)) ||\n        (equals(p1, q2) && equals(p2, q1))) return true;\n    return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 &&\n           area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;\n}\n\n// check if a polygon diagonal intersects any polygon segments\nfunction intersectsPolygon(a, b) {\n    var p = a;\n    do {\n        if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&\n                intersects(p, p.next, a, b)) return true;\n        p = p.next;\n    } while (p !== a);\n\n    return false;\n}\n\n// check if a polygon diagonal is locally inside the polygon\nfunction locallyInside(a, b) {\n    return area(a.prev, a, a.next) < 0 ?\n        area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :\n        area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;\n}\n\n// check if the middle point of a polygon diagonal is inside the polygon\nfunction middleInside(a, b) {\n    var p = a,\n        inside = false,\n        px = (a.x + b.x) / 2,\n        py = (a.y + b.y) / 2;\n    do {\n        if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&\n                (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))\n            inside = !inside;\n        p = p.next;\n    } while (p !== a);\n\n    return inside;\n}\n\n// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;\n// if one belongs to the outer ring and another to a hole, it merges it into a single ring\nfunction splitPolygon(a, b) {\n    var a2 = new Node(a.i, a.x, a.y),\n        b2 = new Node(b.i, b.x, b.y),\n        an = a.next,\n        bp = b.prev;\n\n    a.next = b;\n    b.prev = a;\n\n    a2.next = an;\n    an.prev = a2;\n\n    b2.next = a2;\n    a2.prev = b2;\n\n    bp.next = b2;\n    b2.prev = bp;\n\n    return b2;\n}\n\n// create a node and optionally link it with previous one (in a circular doubly linked list)\nfunction insertNode(i, x, y, last) {\n    var p = new Node(i, x, y);\n\n    if (!last) {\n        p.prev = p;\n        p.next = p;\n\n    } else {\n        p.next = last.next;\n        p.prev = last;\n        last.next.prev = p;\n        last.next = p;\n    }\n    return p;\n}\n\nfunction removeNode(p) {\n    p.next.prev = p.prev;\n    p.prev.next = p.next;\n\n    if (p.prevZ) p.prevZ.nextZ = p.nextZ;\n    if (p.nextZ) p.nextZ.prevZ = p.prevZ;\n}\n\nfunction Node(i, x, y) {\n    // vertex index in coordinates array\n    this.i = i;\n\n    // vertex coordinates\n    this.x = x;\n    this.y = y;\n\n    // previous and next vertex nodes in a polygon ring\n    this.prev = null;\n    this.next = null;\n\n    // z-order curve value\n    this.z = null;\n\n    // previous and next nodes in z-order\n    this.prevZ = null;\n    this.nextZ = null;\n\n    // indicates whether this is a steiner point\n    this.steiner = false;\n}\n\n// return a percentage difference between the polygon area and its triangulation area;\n// used to verify correctness of triangulation\nearcut.deviation = function (data, holeIndices, dim, triangles) {\n    var hasHoles = holeIndices && holeIndices.length;\n    var outerLen = hasHoles ? holeIndices[0] * dim : data.length;\n\n    var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));\n    if (hasHoles) {\n        for (var i = 0, len = holeIndices.length; i < len; i++) {\n            var start = holeIndices[i] * dim;\n            var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;\n            polygonArea -= Math.abs(signedArea(data, start, end, dim));\n        }\n    }\n\n    var trianglesArea = 0;\n    for (i = 0; i < triangles.length; i += 3) {\n        var a = triangles[i] * dim;\n        var b = triangles[i + 1] * dim;\n        var c = triangles[i + 2] * dim;\n        trianglesArea += Math.abs(\n            (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -\n            (data[a] - data[b]) * (data[c + 1] - data[a + 1]));\n    }\n\n    return polygonArea === 0 && trianglesArea === 0 ? 0 :\n        Math.abs((trianglesArea - polygonArea) / polygonArea);\n};\n\nfunction signedArea(data, start, end, dim) {\n    var sum = 0;\n    for (var i = start, j = end - dim; i < end; i += dim) {\n        sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);\n        j = i;\n    }\n    return sum;\n}\n\n// turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts\nearcut.flatten = function (data) {\n    var dim = data[0][0].length,\n        result = {vertices: [], holes: [], dimensions: dim},\n        holeIndex = 0;\n\n    for (var i = 0; i < data.length; i++) {\n        for (var j = 0; j < data[i].length; j++) {\n            for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]);\n        }\n        if (i > 0) {\n            holeIndex += data[i - 1].length;\n            result.holes.push(holeIndex);\n        }\n    }\n    return result;\n};\n\n},{}],493:[function(_dereq_,module,exports){\narguments[4][318][0].apply(exports,arguments)\n},{\"./is-implemented\":494,\"./polyfill\":496,\"dup\":318}],494:[function(_dereq_,module,exports){\narguments[4][319][0].apply(exports,arguments)\n},{\"dup\":319}],495:[function(_dereq_,module,exports){\narguments[4][320][0].apply(exports,arguments)\n},{\"dup\":320}],496:[function(_dereq_,module,exports){\narguments[4][321][0].apply(exports,arguments)\n},{\"./is-native-implemented\":495,\"d\":151,\"dup\":321,\"es5-ext/object/is-value\":194,\"es5-ext/object/set-prototype-of\":200,\"es5-ext/object/valid-object\":204,\"es5-ext/object/valid-value\":205,\"es5-ext/string/random-uniq\":210,\"es6-iterator/for-of\":212,\"es6-iterator/get\":213,\"es6-symbol\":219}],497:[function(_dereq_,module,exports){\n'use strict';\n\nfunction _slicedToArray(arr, i) {\n  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();\n}\n\nfunction _toConsumableArray(arr) {\n  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();\n}\n\nfunction _arrayWithoutHoles(arr) {\n  if (Array.isArray(arr)) {\n    for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];\n\n    return arr2;\n  }\n}\n\nfunction _arrayWithHoles(arr) {\n  if (Array.isArray(arr)) return arr;\n}\n\nfunction _iterableToArray(iter) {\n  if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nfunction _iterableToArrayLimit(arr, i) {\n  var _arr = [];\n  var _n = true;\n  var _d = false;\n  var _e = undefined;\n\n  try {\n    for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {\n      _arr.push(_s.value);\n\n      if (i && _arr.length === i) break;\n    }\n  } catch (err) {\n    _d = true;\n    _e = err;\n  } finally {\n    try {\n      if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n    } finally {\n      if (_d) throw _e;\n    }\n  }\n\n  return _arr;\n}\n\nfunction _nonIterableSpread() {\n  throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nfunction _nonIterableRest() {\n  throw new TypeError(\"Invalid attempt to destructure non-iterable instance\");\n}\n\nvar rgba = _dereq_('color-normalize');\n\nvar getBounds = _dereq_('array-bounds');\n\nvar colorId = _dereq_('color-id');\n\nvar cluster = _dereq_('point-cluster');\n\nvar extend = _dereq_('object-assign');\n\nvar glslify = _dereq_('glslify');\n\nvar pick = _dereq_('pick-by-alias');\n\nvar updateDiff = _dereq_('update-diff');\n\nvar flatten = _dereq_('flatten-vertex-data');\n\nvar ie = _dereq_('is-iexplorer');\n\nvar f32 = _dereq_('to-float32');\n\nvar parseRect = _dereq_('parse-rect');\n\nvar scatter = Scatter;\n\nfunction Scatter(regl, options) {\n  var _this = this;\n\n  if (!(this instanceof Scatter)) return new Scatter(regl, options);\n\n  if (typeof regl === 'function') {\n    if (!options) options = {};\n    options.regl = regl;\n  } else {\n    options = regl;\n    regl = null;\n  }\n\n  if (options && options.length) options.positions = options;\n  regl = options.regl; // persistent variables\n\n  var gl = regl._gl,\n      paletteTexture,\n      palette = [],\n      paletteIds = {},\n      // state\n  groups = [],\n      // textures for marker keys\n  markerTextures = [null],\n      markerCache = [null];\n  var maxColors = 255,\n      maxSize = 100; // direct color buffer mode\n  // IE does not support palette anyways\n\n  this.tooManyColors = ie; // texture with color palette\n\n  paletteTexture = regl.texture({\n    data: new Uint8Array(maxColors * 4),\n    width: maxColors,\n    height: 1,\n    type: 'uint8',\n    format: 'rgba',\n    wrapS: 'clamp',\n    wrapT: 'clamp',\n    mag: 'nearest',\n    min: 'nearest'\n  });\n  extend(this, {\n    regl: regl,\n    gl: gl,\n    groups: groups,\n    markerCache: markerCache,\n    markerTextures: markerTextures,\n    palette: palette,\n    paletteIds: paletteIds,\n    paletteTexture: paletteTexture,\n    maxColors: maxColors,\n    maxSize: maxSize,\n    canvas: gl.canvas\n  });\n  this.update(options); // common shader options\n\n  var shaderOptions = {\n    uniforms: {\n      pixelRatio: regl.context('pixelRatio'),\n      palette: paletteTexture,\n      paletteSize: function paletteSize(ctx, prop) {\n        return [_this.tooManyColors ? 0 : maxColors, paletteTexture.height];\n      },\n      scale: regl.prop('scale'),\n      scaleFract: regl.prop('scaleFract'),\n      translate: regl.prop('translate'),\n      translateFract: regl.prop('translateFract'),\n      opacity: regl.prop('opacity'),\n      marker: regl.prop('markerTexture')\n    },\n    attributes: {\n      // FIXME: optimize these parts\n      x: function x(ctx, prop) {\n        return prop.xAttr || {\n          buffer: prop.positionBuffer,\n          stride: 8,\n          offset: 0\n        };\n      },\n      y: function y(ctx, prop) {\n        return prop.yAttr || {\n          buffer: prop.positionBuffer,\n          stride: 8,\n          offset: 4\n        };\n      },\n      xFract: function xFract(ctx, prop) {\n        return prop.xAttr ? {\n          constant: [0, 0]\n        } : {\n          buffer: prop.positionFractBuffer,\n          stride: 8,\n          offset: 0\n        };\n      },\n      yFract: function yFract(ctx, prop) {\n        return prop.yAttr ? {\n          constant: [0, 0]\n        } : {\n          buffer: prop.positionFractBuffer,\n          stride: 8,\n          offset: 4\n        };\n      },\n      size: function size(ctx, prop) {\n        return prop.size.length ? {\n          buffer: prop.sizeBuffer,\n          stride: 2,\n          offset: 0\n        } : {\n          constant: [Math.round(prop.size * 255 / _this.maxSize)]\n        };\n      },\n      borderSize: function borderSize(ctx, prop) {\n        return prop.borderSize.length ? {\n          buffer: prop.sizeBuffer,\n          stride: 2,\n          offset: 1\n        } : {\n          constant: [Math.round(prop.borderSize * 255 / _this.maxSize)]\n        };\n      },\n      colorId: function colorId(ctx, prop) {\n        return prop.color.length ? {\n          buffer: prop.colorBuffer,\n          stride: _this.tooManyColors ? 8 : 4,\n          offset: 0\n        } : {\n          constant: _this.tooManyColors ? palette.slice(prop.color * 4, prop.color * 4 + 4) : [prop.color]\n        };\n      },\n      borderColorId: function borderColorId(ctx, prop) {\n        return prop.borderColor.length ? {\n          buffer: prop.colorBuffer,\n          stride: _this.tooManyColors ? 8 : 4,\n          offset: _this.tooManyColors ? 4 : 2\n        } : {\n          constant: _this.tooManyColors ? palette.slice(prop.borderColor * 4, prop.borderColor * 4 + 4) : [prop.borderColor]\n        };\n      },\n      isActive: function isActive(ctx, prop) {\n        return prop.activation === true ? {\n          constant: [1]\n        } : prop.activation ? prop.activation : {\n          constant: [0]\n        };\n      }\n    },\n    blend: {\n      enable: true,\n      color: [0, 0, 0, 1],\n      // photoshop blending\n      func: {\n        srcRGB: 'src alpha',\n        dstRGB: 'one minus src alpha',\n        srcAlpha: 'one minus dst alpha',\n        dstAlpha: 'one'\n      }\n    },\n    scissor: {\n      enable: true,\n      box: regl.prop('viewport')\n    },\n    viewport: regl.prop('viewport'),\n    stencil: {\n      enable: false\n    },\n    depth: {\n      enable: false\n    },\n    elements: regl.prop('elements'),\n    count: regl.prop('count'),\n    offset: regl.prop('offset'),\n    primitive: 'points' // draw sdf-marker\n\n  };\n  var markerOptions = extend({}, shaderOptions);\n  markerOptions.frag = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nvarying vec4 fragColor, fragBorderColor;\\nvarying float fragWidth, fragBorderColorLevel, fragColorLevel;\\n\\nuniform sampler2D marker;\\nuniform float pixelRatio, opacity;\\n\\nfloat smoothStep(float x, float y) {\\n  return 1.0 / (1.0 + exp(50.0*(x - y)));\\n}\\n\\nvoid main() {\\n  float dist = texture2D(marker, gl_PointCoord).r, delta = fragWidth;\\n\\n  // max-distance alpha\\n  if (dist < 0.003) discard;\\n\\n  // null-border case\\n  if (fragBorderColorLevel == fragColorLevel || fragBorderColor.a == 0.) {\\n    float colorAmt = smoothstep(.5 - delta, .5 + delta, dist);\\n    gl_FragColor = vec4(fragColor.rgb, colorAmt * fragColor.a * opacity);\\n  }\\n  else {\\n    float borderColorAmt = smoothstep(fragBorderColorLevel - delta, fragBorderColorLevel + delta, dist);\\n    float colorAmt = smoothstep(fragColorLevel - delta, fragColorLevel + delta, dist);\\n\\n    vec4 color = fragBorderColor;\\n    color.a *= borderColorAmt;\\n    color = mix(color, fragColor, colorAmt);\\n    color.a *= opacity;\\n\\n    gl_FragColor = color;\\n  }\\n\\n}\\n\"]);\n  markerOptions.vert = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute float x, y, xFract, yFract;\\nattribute float size, borderSize;\\nattribute vec4 colorId, borderColorId;\\nattribute float isActive;\\n\\nuniform vec2 scale, scaleFract, translate, translateFract, paletteSize;\\nuniform float pixelRatio;\\nuniform sampler2D palette;\\n\\nconst float maxSize = 100.;\\nconst float borderLevel = .5;\\n\\nvarying vec4 fragColor, fragBorderColor;\\nvarying float fragPointSize, fragBorderRadius, fragWidth, fragBorderColorLevel, fragColorLevel;\\n\\nbool isDirect = (paletteSize.x < 1.);\\n\\nvec4 getColor(vec4 id) {\\n  return isDirect ? id / 255. : texture2D(palette,\\n    vec2(\\n      (id.x + .5) / paletteSize.x,\\n      (id.y + .5) / paletteSize.y\\n    )\\n  );\\n}\\n\\nvoid main() {\\n  if (isActive == 0.) return;\\n\\n  vec2 position = vec2(x, y);\\n  vec2 positionFract = vec2(xFract, yFract);\\n\\n  vec4 color = getColor(colorId);\\n  vec4 borderColor = getColor(borderColorId);\\n\\n  float size = size * maxSize / 255.;\\n  float borderSize = borderSize * maxSize / 255.;\\n\\n  gl_PointSize = 2. * size * pixelRatio;\\n  fragPointSize = size * pixelRatio;\\n\\n  vec2 pos = (position + translate) * scale\\n      + (positionFract + translateFract) * scale\\n      + (position + translate) * scaleFract\\n      + (positionFract + translateFract) * scaleFract;\\n\\n  gl_Position = vec4(pos * 2. - 1., 0, 1);\\n\\n  fragColor = color;\\n  fragBorderColor = borderColor;\\n  fragWidth = 1. / gl_PointSize;\\n\\n  fragBorderColorLevel = clamp(borderLevel - borderLevel * borderSize / size, 0., 1.);\\n  fragColorLevel = clamp(borderLevel + (1. - borderLevel) * borderSize / size, 0., 1.);\\n}\"]);\n  this.drawMarker = regl(markerOptions); // draw circle\n\n  var circleOptions = extend({}, shaderOptions);\n  circleOptions.frag = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nvarying vec4 fragColor, fragBorderColor;\\n\\nuniform float opacity;\\nvarying float fragBorderRadius, fragWidth;\\n\\nfloat smoothStep(float edge0, float edge1, float x) {\\n\\tfloat t;\\n\\tt = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);\\n\\treturn t * t * (3.0 - 2.0 * t);\\n}\\n\\nvoid main() {\\n\\tfloat radius, alpha = 1.0, delta = fragWidth;\\n\\n\\tradius = length(2.0 * gl_PointCoord.xy - 1.0);\\n\\n\\tif (radius > 1.0 + delta) {\\n\\t\\tdiscard;\\n\\t}\\n\\n\\talpha -= smoothstep(1.0 - delta, 1.0 + delta, radius);\\n\\n\\tfloat borderRadius = fragBorderRadius;\\n\\tfloat ratio = smoothstep(borderRadius - delta, borderRadius + delta, radius);\\n\\tvec4 color = mix(fragColor, fragBorderColor, ratio);\\n\\tcolor.a *= alpha * opacity;\\n\\tgl_FragColor = color;\\n}\\n\"]);\n  circleOptions.vert = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nattribute float x, y, xFract, yFract;\\nattribute float size, borderSize;\\nattribute vec4 colorId, borderColorId;\\nattribute float isActive;\\n\\nuniform vec2 scale, scaleFract, translate, translateFract;\\nuniform float pixelRatio;\\nuniform sampler2D palette;\\nuniform vec2 paletteSize;\\n\\nconst float maxSize = 100.;\\n\\nvarying vec4 fragColor, fragBorderColor;\\nvarying float fragBorderRadius, fragWidth;\\n\\nbool isDirect = (paletteSize.x < 1.);\\n\\nvec4 getColor(vec4 id) {\\n  return isDirect ? id / 255. : texture2D(palette,\\n    vec2(\\n      (id.x + .5) / paletteSize.x,\\n      (id.y + .5) / paletteSize.y\\n    )\\n  );\\n}\\n\\nvoid main() {\\n  // ignore inactive points\\n  if (isActive == 0.) return;\\n\\n  vec2 position = vec2(x, y);\\n  vec2 positionFract = vec2(xFract, yFract);\\n\\n  vec4 color = getColor(colorId);\\n  vec4 borderColor = getColor(borderColorId);\\n\\n  float size = size * maxSize / 255.;\\n  float borderSize = borderSize * maxSize / 255.;\\n\\n  gl_PointSize = (size + borderSize) * pixelRatio;\\n\\n  vec2 pos = (position + translate) * scale\\n      + (positionFract + translateFract) * scale\\n      + (position + translate) * scaleFract\\n      + (positionFract + translateFract) * scaleFract;\\n\\n  gl_Position = vec4(pos * 2. - 1., 0, 1);\\n\\n  fragBorderRadius = 1. - 2. * borderSize / (size + borderSize);\\n  fragColor = color;\\n  fragBorderColor = borderColor.a == 0. || borderSize == 0. ? vec4(color.rgb, 0.) : borderColor;\\n  fragWidth = 1. / gl_PointSize;\\n}\\n\"]); // polyfill IE\n\n  if (ie) {\n    circleOptions.frag = circleOptions.frag.replace('smoothstep', 'smoothStep');\n    markerOptions.frag = markerOptions.frag.replace('smoothstep', 'smoothStep');\n  }\n\n  this.drawCircle = regl(circleOptions);\n} // single pass defaults\n\n\nScatter.defaults = {\n  color: 'black',\n  borderColor: 'transparent',\n  borderSize: 0,\n  size: 12,\n  opacity: 1,\n  marker: undefined,\n  viewport: null,\n  range: null,\n  pixelSize: null,\n  count: 0,\n  offset: 0,\n  bounds: null,\n  positions: [],\n  snap: 1e4 // update & redraw\n\n};\n\nScatter.prototype.render = function () {\n  if (arguments.length) {\n    this.update.apply(this, arguments);\n  }\n\n  this.draw();\n  return this;\n}; // draw all groups or only indicated ones\n\n\nScatter.prototype.draw = function () {\n  var _this2 = this;\n\n  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n    args[_key] = arguments[_key];\n  }\n\n  var groups = this.groups; // if directly array passed - treat as passes\n\n  if (args.length === 1 && Array.isArray(args[0]) && (args[0][0] === null || Array.isArray(args[0][0]))) {\n    args = args[0];\n  } // FIXME: remove once https://github.com/regl-project/regl/issues/474 resolved\n\n\n  this.regl._refresh();\n\n  if (args.length) {\n    for (var i = 0; i < args.length; i++) {\n      this.drawItem(i, args[i]);\n    }\n  } // draw all passes\n  else {\n      groups.forEach(function (group, i) {\n        _this2.drawItem(i);\n      });\n    }\n\n  return this;\n}; // draw specific scatter group\n\n\nScatter.prototype.drawItem = function (id, els) {\n  var groups = this.groups;\n  var group = groups[id]; // debug viewport\n  // let { viewport } = group\n  // gl.enable(gl.SCISSOR_TEST);\n  // gl.scissor(viewport.x, viewport.y, viewport.width, viewport.height);\n  // gl.clearColor(0, 0, 0, .5);\n  // gl.clear(gl.COLOR_BUFFER_BIT);\n\n  if (typeof els === 'number') {\n    id = els;\n    group = groups[els];\n    els = null;\n  }\n\n  if (!(group && group.count && group.opacity)) return; // draw circles\n\n  if (group.activation[0]) {\n    // TODO: optimize this performance by making groups and regl.this props\n    this.drawCircle(this.getMarkerDrawOptions(0, group, els));\n  } // draw all other available markers\n\n\n  var batch = [];\n\n  for (var i = 1; i < group.activation.length; i++) {\n    if (!group.activation[i] || group.activation[i] !== true && !group.activation[i].data.length) continue;\n    batch.push.apply(batch, _toConsumableArray(this.getMarkerDrawOptions(i, group, els)));\n  }\n\n  if (batch.length) {\n    this.drawMarker(batch);\n  }\n}; // get options for the marker ids\n\n\nScatter.prototype.getMarkerDrawOptions = function (markerId, group, elements) {\n  var range = group.range,\n      tree = group.tree,\n      viewport = group.viewport,\n      activation = group.activation,\n      selectionBuffer = group.selectionBuffer,\n      count = group.count;\n  var regl = this.regl; // direct points\n\n  if (!tree) {\n    // if elements array - draw unclustered points\n    if (elements) {\n      return [extend({}, group, {\n        markerTexture: this.markerTextures[markerId],\n        activation: activation[markerId],\n        count: elements.length,\n        elements: elements,\n        offset: 0\n      })];\n    }\n\n    return [extend({}, group, {\n      markerTexture: this.markerTextures[markerId],\n      activation: activation[markerId],\n      offset: 0\n    })];\n  } // clustered points\n\n\n  var batch = [];\n  var lod = tree.range(range, {\n    lod: true,\n    px: [(range[2] - range[0]) / viewport.width, (range[3] - range[1]) / viewport.height]\n  }); // enable elements by using selection buffer\n\n  if (elements) {\n    var markerActivation = activation[markerId];\n    var mask = markerActivation.data;\n    var data = new Uint8Array(count);\n\n    for (var i = 0; i < elements.length; i++) {\n      var id = elements[i];\n      data[id] = mask ? mask[id] : 1;\n    }\n\n    selectionBuffer.subdata(data);\n  }\n\n  for (var l = lod.length; l--;) {\n    var _lod$l = _slicedToArray(lod[l], 2),\n        from = _lod$l[0],\n        to = _lod$l[1];\n\n    batch.push(extend({}, group, {\n      markerTexture: this.markerTextures[markerId],\n      activation: elements ? selectionBuffer : activation[markerId],\n      offset: from,\n      count: to - from\n    }));\n  }\n\n  return batch;\n}; // update groups options\n\n\nScatter.prototype.update = function () {\n  var _this3 = this;\n\n  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n    args[_key2] = arguments[_key2];\n  }\n\n  if (!args.length) return; // passes are as single array\n\n  if (args.length === 1 && Array.isArray(args[0])) args = args[0];\n  var groups = this.groups,\n      gl = this.gl,\n      regl = this.regl,\n      maxSize = this.maxSize,\n      maxColors = this.maxColors,\n      palette = this.palette;\n  this.groups = groups = args.map(function (options, i) {\n    var group = groups[i];\n    if (options === undefined) return group;\n    if (options === null) options = {\n      positions: null\n    };else if (typeof options === 'function') options = {\n      ondraw: options\n    };else if (typeof options[0] === 'number') options = {\n      positions: options // copy options to avoid mutation & handle aliases\n\n    };\n    options = pick(options, {\n      positions: 'positions data points',\n      snap: 'snap cluster lod tree',\n      size: 'sizes size radius',\n      borderSize: 'borderSizes borderSize border-size bordersize borderWidth borderWidths border-width borderwidth stroke-width strokeWidth strokewidth outline',\n      color: 'colors color fill fill-color fillColor',\n      borderColor: 'borderColors borderColor stroke stroke-color strokeColor',\n      marker: 'markers marker shape',\n      range: 'range dataBox databox',\n      viewport: 'viewport viewPort viewBox viewbox',\n      opacity: 'opacity alpha transparency',\n      bounds: 'bound bounds boundaries limits',\n      tooManyColors: 'tooManyColors palette paletteMode optimizePalette enablePalette'\n    });\n    if (options.positions === null) options.positions = [];\n    if (options.tooManyColors != null) _this3.tooManyColors = options.tooManyColors;\n\n    if (!group) {\n      groups[i] = group = {\n        id: i,\n        scale: null,\n        translate: null,\n        scaleFract: null,\n        translateFract: null,\n        // buffers for active markers\n        activation: [],\n        // buffer for filtered markers\n        selectionBuffer: regl.buffer({\n          data: new Uint8Array(0),\n          usage: 'stream',\n          type: 'uint8'\n        }),\n        // buffers with data: it is faster to switch them per-pass\n        // than provide one congregate buffer\n        sizeBuffer: regl.buffer({\n          data: new Uint8Array(0),\n          usage: 'dynamic',\n          type: 'uint8'\n        }),\n        colorBuffer: regl.buffer({\n          data: new Uint8Array(0),\n          usage: 'dynamic',\n          type: 'uint8'\n        }),\n        positionBuffer: regl.buffer({\n          data: new Uint8Array(0),\n          usage: 'dynamic',\n          type: 'float'\n        }),\n        positionFractBuffer: regl.buffer({\n          data: new Uint8Array(0),\n          usage: 'dynamic',\n          type: 'float'\n        })\n      };\n      options = extend({}, Scatter.defaults, options);\n    } // force update triggers\n\n\n    if (options.positions && !('marker' in options)) {\n      options.marker = group.marker;\n      delete group.marker;\n    } // updating markers cause recalculating snapping\n\n\n    if (options.marker && !('positions' in options)) {\n      options.positions = group.positions;\n      delete group.positions;\n    } // global count of points\n\n\n    var hasSize = 0,\n        hasColor = 0;\n    updateDiff(group, options, [{\n      snap: true,\n      size: function size(s, group) {\n        if (s == null) s = Scatter.defaults.size;\n        hasSize += s && s.length ? 1 : 0;\n        return s;\n      },\n      borderSize: function borderSize(s, group) {\n        if (s == null) s = Scatter.defaults.borderSize;\n        hasSize += s && s.length ? 1 : 0;\n        return s;\n      },\n      opacity: parseFloat,\n      // add colors to palette, save references\n      color: function color(c, group) {\n        if (c == null) c = Scatter.defaults.color;\n        c = _this3.updateColor(c);\n        hasColor++;\n        return c;\n      },\n      borderColor: function borderColor(c, group) {\n        if (c == null) c = Scatter.defaults.borderColor;\n        c = _this3.updateColor(c);\n        hasColor++;\n        return c;\n      },\n      bounds: function bounds(_bounds, group, options) {\n        if (!('range' in options)) options.range = null;\n        return _bounds;\n      },\n      positions: function positions(_positions, group, options) {\n        var snap = group.snap;\n        var positionBuffer = group.positionBuffer,\n            positionFractBuffer = group.positionFractBuffer,\n            selectionBuffer = group.selectionBuffer; // separate buffers for x/y coordinates\n\n        if (_positions.x || _positions.y) {\n          if (_positions.x.length) {\n            group.xAttr = {\n              buffer: regl.buffer(_positions.x),\n              offset: 0,\n              stride: 4,\n              count: _positions.x.length\n            };\n          } else {\n            group.xAttr = {\n              buffer: _positions.x.buffer,\n              offset: _positions.x.offset * 4 || 0,\n              stride: (_positions.x.stride || 1) * 4,\n              count: _positions.x.count\n            };\n          }\n\n          if (_positions.y.length) {\n            group.yAttr = {\n              buffer: regl.buffer(_positions.y),\n              offset: 0,\n              stride: 4,\n              count: _positions.y.length\n            };\n          } else {\n            group.yAttr = {\n              buffer: _positions.y.buffer,\n              offset: _positions.y.offset * 4 || 0,\n              stride: (_positions.y.stride || 1) * 4,\n              count: _positions.y.count\n            };\n          }\n\n          group.count = Math.max(group.xAttr.count, group.yAttr.count);\n          return _positions;\n        }\n\n        _positions = flatten(_positions, 'float64');\n        var count = group.count = Math.floor(_positions.length / 2);\n        var bounds = group.bounds = count ? getBounds(_positions, 2) : null; // if range is not provided updated - recalc it\n\n        if (!options.range && !group.range) {\n          delete group.range;\n          options.range = bounds;\n        } // reset marker\n\n\n        if (!options.marker && !group.marker) {\n          delete group.marker;\n          options.marker = null;\n        } // build cluster tree if required\n\n\n        if (snap && (snap === true || count > snap)) {\n          group.tree = cluster(_positions, {\n            bounds: bounds\n          });\n        } // existing tree instance\n        else if (snap && snap.length) {\n            group.tree = snap;\n          }\n\n        if (group.tree) {\n          var opts = {\n            primitive: 'points',\n            usage: 'static',\n            data: group.tree,\n            type: 'uint32'\n          };\n          if (group.elements) group.elements(opts);else group.elements = regl.elements(opts);\n        } // update position buffers\n\n\n        positionBuffer({\n          data: f32.float(_positions),\n          usage: 'dynamic'\n        });\n        positionFractBuffer({\n          data: f32.fract(_positions),\n          usage: 'dynamic'\n        }); // expand selectionBuffer\n\n        selectionBuffer({\n          data: new Uint8Array(count),\n          type: 'uint8',\n          usage: 'stream'\n        });\n        return _positions;\n      }\n    }, {\n      // create marker ids corresponding to known marker textures\n      marker: function marker(markers, group, options) {\n        var activation = group.activation; // reset marker elements\n\n        activation.forEach(function (buffer) {\n          return buffer && buffer.destroy && buffer.destroy();\n        });\n        activation.length = 0; // single sdf marker\n\n        if (!markers || typeof markers[0] === 'number') {\n          var id = _this3.addMarker(markers);\n\n          activation[id] = true;\n        } // per-point markers use mask buffers to enable markers in vert shader\n        else {\n            var markerMasks = [];\n\n            for (var _i = 0, l = Math.min(markers.length, group.count); _i < l; _i++) {\n              var _id = _this3.addMarker(markers[_i]);\n\n              if (!markerMasks[_id]) markerMasks[_id] = new Uint8Array(group.count); // enable marker by default\n\n              markerMasks[_id][_i] = 1;\n            }\n\n            for (var _id2 = 0; _id2 < markerMasks.length; _id2++) {\n              if (!markerMasks[_id2]) continue;\n              var opts = {\n                data: markerMasks[_id2],\n                type: 'uint8',\n                usage: 'static'\n              };\n\n              if (!activation[_id2]) {\n                activation[_id2] = regl.buffer(opts);\n              } else {\n                activation[_id2](opts);\n              }\n\n              activation[_id2].data = markerMasks[_id2];\n            }\n          }\n\n        return markers;\n      },\n      range: function range(_range, group, options) {\n        var bounds = group.bounds; // FIXME: why do we need this?\n\n        if (!bounds) return;\n        if (!_range) _range = bounds;\n        group.scale = [1 / (_range[2] - _range[0]), 1 / (_range[3] - _range[1])];\n        group.translate = [-_range[0], -_range[1]];\n        group.scaleFract = f32.fract(group.scale);\n        group.translateFract = f32.fract(group.translate);\n        return _range;\n      },\n      viewport: function viewport(vp) {\n        var rect = parseRect(vp || [gl.drawingBufferWidth, gl.drawingBufferHeight]); // normalize viewport to the canvas coordinates\n        // rect.y = gl.drawingBufferHeight - rect.height - rect.y\n\n        return rect;\n      }\n    }]); // update size buffer, if needed\n\n    if (hasSize) {\n      var _group = group,\n          count = _group.count,\n          size = _group.size,\n          borderSize = _group.borderSize,\n          sizeBuffer = _group.sizeBuffer;\n      var sizes = new Uint8Array(count * 2);\n\n      if (size.length || borderSize.length) {\n        for (var _i2 = 0; _i2 < count; _i2++) {\n          // we downscale size to allow for fractions\n          sizes[_i2 * 2] = Math.round((size[_i2] == null ? size : size[_i2]) * 255 / maxSize);\n          sizes[_i2 * 2 + 1] = Math.round((borderSize[_i2] == null ? borderSize : borderSize[_i2]) * 255 / maxSize);\n        }\n      }\n\n      sizeBuffer({\n        data: sizes,\n        usage: 'dynamic'\n      });\n    } // update color buffer if needed\n\n\n    if (hasColor) {\n      var _group2 = group,\n          _count = _group2.count,\n          color = _group2.color,\n          borderColor = _group2.borderColor,\n          colorBuffer = _group2.colorBuffer;\n      var colors; // if too many colors - put colors to buffer directly\n\n      if (_this3.tooManyColors) {\n        if (color.length || borderColor.length) {\n          colors = new Uint8Array(_count * 8);\n\n          for (var _i3 = 0; _i3 < _count; _i3++) {\n            var _colorId = color[_i3];\n            colors[_i3 * 8] = palette[_colorId * 4];\n            colors[_i3 * 8 + 1] = palette[_colorId * 4 + 1];\n            colors[_i3 * 8 + 2] = palette[_colorId * 4 + 2];\n            colors[_i3 * 8 + 3] = palette[_colorId * 4 + 3];\n            var borderColorId = borderColor[_i3];\n            colors[_i3 * 8 + 4] = palette[borderColorId * 4];\n            colors[_i3 * 8 + 5] = palette[borderColorId * 4 + 1];\n            colors[_i3 * 8 + 6] = palette[borderColorId * 4 + 2];\n            colors[_i3 * 8 + 7] = palette[borderColorId * 4 + 3];\n          }\n        }\n      } // if limited amount of colors - keep palette color picking\n      // that saves significant memory\n      else {\n          if (color.length || borderColor.length) {\n            // we need slight data increase by 2 due to vec4 borderId in shader\n            colors = new Uint8Array(_count * 4 + 2);\n\n            for (var _i4 = 0; _i4 < _count; _i4++) {\n              // put color coords in palette texture\n              if (color[_i4] != null) {\n                colors[_i4 * 4] = color[_i4] % maxColors;\n                colors[_i4 * 4 + 1] = Math.floor(color[_i4] / maxColors);\n              }\n\n              if (borderColor[_i4] != null) {\n                colors[_i4 * 4 + 2] = borderColor[_i4] % maxColors;\n                colors[_i4 * 4 + 3] = Math.floor(borderColor[_i4] / maxColors);\n              }\n            }\n          }\n        }\n\n      colorBuffer({\n        data: colors || new Uint8Array(0),\n        type: 'uint8',\n        usage: 'dynamic'\n      });\n    }\n\n    return group;\n  });\n}; // get (and create) marker texture id\n\n\nScatter.prototype.addMarker = function (sdf) {\n  var markerTextures = this.markerTextures,\n      regl = this.regl,\n      markerCache = this.markerCache;\n  var pos = sdf == null ? 0 : markerCache.indexOf(sdf);\n  if (pos >= 0) return pos; // convert sdf to 0..255 range\n\n  var distArr;\n\n  if (sdf instanceof Uint8Array || sdf instanceof Uint8ClampedArray) {\n    distArr = sdf;\n  } else {\n    distArr = new Uint8Array(sdf.length);\n\n    for (var i = 0, l = sdf.length; i < l; i++) {\n      distArr[i] = sdf[i] * 255;\n    }\n  }\n\n  var radius = Math.floor(Math.sqrt(distArr.length));\n  pos = markerTextures.length;\n  markerCache.push(sdf);\n  markerTextures.push(regl.texture({\n    channels: 1,\n    data: distArr,\n    radius: radius,\n    mag: 'linear',\n    min: 'linear'\n  }));\n  return pos;\n}; // register color to palette, return it's index or list of indexes\n\n\nScatter.prototype.updateColor = function (colors) {\n  var paletteIds = this.paletteIds,\n      palette = this.palette,\n      maxColors = this.maxColors;\n\n  if (!Array.isArray(colors)) {\n    colors = [colors];\n  }\n\n  var idx = []; // if color groups - flatten them\n\n  if (typeof colors[0] === 'number') {\n    var grouped = [];\n\n    if (Array.isArray(colors)) {\n      for (var i = 0; i < colors.length; i += 4) {\n        grouped.push(colors.slice(i, i + 4));\n      }\n    } else {\n      for (var _i5 = 0; _i5 < colors.length; _i5 += 4) {\n        grouped.push(colors.subarray(_i5, _i5 + 4));\n      }\n    }\n\n    colors = grouped;\n  }\n\n  for (var _i6 = 0; _i6 < colors.length; _i6++) {\n    var color = colors[_i6];\n    color = rgba(color, 'uint8');\n    var id = colorId(color, false); // if new color - save it\n\n    if (paletteIds[id] == null) {\n      var pos = palette.length;\n      paletteIds[id] = Math.floor(pos / 4);\n      palette[pos] = color[0];\n      palette[pos + 1] = color[1];\n      palette[pos + 2] = color[2];\n      palette[pos + 3] = color[3];\n    }\n\n    idx[_i6] = paletteIds[id];\n  } // detect if too many colors in palette\n\n\n  if (!this.tooManyColors && palette.length > maxColors * 4) this.tooManyColors = true; // limit max color\n\n  this.updatePalette(palette); // keep static index for single-color property\n\n  return idx.length === 1 ? idx[0] : idx;\n};\n\nScatter.prototype.updatePalette = function (palette) {\n  if (this.tooManyColors) return;\n  var maxColors = this.maxColors,\n      paletteTexture = this.paletteTexture;\n  var requiredHeight = Math.ceil(palette.length * .25 / maxColors); // pad data\n\n  if (requiredHeight > 1) {\n    palette = palette.slice();\n\n    for (var i = palette.length * .25 % maxColors; i < requiredHeight * maxColors; i++) {\n      palette.push(0, 0, 0, 0);\n    }\n  } // ensure height\n\n\n  if (paletteTexture.height < requiredHeight) {\n    paletteTexture.resize(maxColors, requiredHeight);\n  } // update full data\n\n\n  paletteTexture.subimage({\n    width: Math.min(palette.length * .25, maxColors),\n    height: requiredHeight,\n    data: palette\n  }, 0, 0);\n}; // remove unused stuff\n\n\nScatter.prototype.destroy = function () {\n  this.groups.forEach(function (group) {\n    group.sizeBuffer.destroy();\n    group.positionBuffer.destroy();\n    group.positionFractBuffer.destroy();\n    group.colorBuffer.destroy();\n    group.activation.forEach(function (b) {\n      return b && b.destroy && b.destroy();\n    });\n    group.selectionBuffer.destroy();\n    if (group.elements) group.elements.destroy();\n  });\n  this.groups.length = 0;\n  this.paletteTexture.destroy();\n  this.markerTextures.forEach(function (txt) {\n    return txt && txt.destroy && txt.destroy();\n  });\n  return this;\n};\n\nvar extend$1 = _dereq_('object-assign');\n\nvar reglScatter2d = function reglScatter2d(regl, options) {\n  var scatter$$1 = new scatter(regl, options);\n  var render = scatter$$1.render.bind(scatter$$1); // expose API\n\n  extend$1(render, {\n    render: render,\n    update: scatter$$1.update.bind(scatter$$1),\n    draw: scatter$$1.draw.bind(scatter$$1),\n    destroy: scatter$$1.destroy.bind(scatter$$1),\n    regl: scatter$$1.regl,\n    gl: scatter$$1.gl,\n    canvas: scatter$$1.gl.canvas,\n    groups: scatter$$1.groups,\n    markers: scatter$$1.markerCache,\n    palette: scatter$$1.palette\n  });\n  return render;\n};\n\nmodule.exports = reglScatter2d;\n\n},{\"array-bounds\":65,\"color-id\":118,\"color-normalize\":120,\"flatten-vertex-data\":227,\"glslify\":409,\"is-iexplorer\":419,\"object-assign\":454,\"parse-rect\":459,\"pick-by-alias\":465,\"point-cluster\":499,\"to-float32\":538,\"update-diff\":549}],498:[function(_dereq_,module,exports){\narguments[4][111][0].apply(exports,arguments)\n},{\"dup\":111}],499:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nmodule.exports = _dereq_('./quad')\r\n},{\"./quad\":500}],500:[function(_dereq_,module,exports){\n/**\r\n * @module  point-cluster/quad\r\n *\r\n * Bucket based quad tree clustering\r\n */\r\n\r\n'use strict'\r\n\r\nvar search = _dereq_('binary-search-bounds')\r\nvar clamp = _dereq_('clamp')\r\nvar rect = _dereq_('parse-rect')\r\nvar getBounds = _dereq_('array-bounds')\r\nvar pick = _dereq_('pick-by-alias')\r\nvar defined = _dereq_('defined')\r\nvar flatten = _dereq_('flatten-vertex-data')\r\nvar isObj = _dereq_('is-obj')\r\nvar dtype = _dereq_('dtype')\r\nvar log2 = _dereq_('math-log2')\r\n\r\nvar MAX_GROUP_ID = 1073741824\r\n\r\nmodule.exports = function cluster (srcPoints, options) {\r\n\tif (!options) { options = {} }\r\n\r\n\tsrcPoints = flatten(srcPoints, 'float64')\r\n\r\n\toptions = pick(options, {\r\n\t\tbounds: 'range bounds dataBox databox',\r\n\t\tmaxDepth: 'depth maxDepth maxdepth level maxLevel maxlevel levels',\r\n\t\tdtype: 'type dtype format out dst output destination'\r\n\t\t// sort: 'sortBy sortby sort',\r\n\t\t// pick: 'pick levelPoint',\r\n\t\t// nodeSize: 'node nodeSize minNodeSize minSize size'\r\n\t})\r\n\r\n\t// let nodeSize = defined(options.nodeSize, 1)\r\n\tvar maxDepth = defined(options.maxDepth, 255)\r\n\tvar bounds = defined(options.bounds, getBounds(srcPoints, 2))\r\n\tif (bounds[0] === bounds[2]) { bounds[2]++ }\r\n\tif (bounds[1] === bounds[3]) { bounds[3]++ }\r\n\r\n\tvar points = normalize(srcPoints, bounds)\r\n\r\n\t// init variables\r\n\tvar n = srcPoints.length >>> 1\r\n\tvar ids\r\n\tif (!options.dtype) { options.dtype = 'array' }\r\n\r\n\tif (typeof options.dtype === 'string') {\r\n\t\tids = new (dtype(options.dtype))(n)\r\n\t}\r\n\telse if (options.dtype) {\r\n\t\tids = options.dtype\r\n\t\tif (Array.isArray(ids)) { ids.length = n }\r\n\t}\r\n\tfor (var i = 0; i < n; ++i) {\r\n\t\tids[i] = i\r\n\t}\r\n\r\n\t// representative point indexes for levels\r\n\tvar levels = []\r\n\r\n\t// starting indexes of subranges in sub levels, levels.length * 4\r\n\tvar sublevels = []\r\n\r\n\t// unique group ids, sorted in z-curve fashion within levels by shifting bits\r\n\tvar groups = []\r\n\r\n\t// level offsets in `ids`\r\n\tvar offsets = []\r\n\r\n\r\n\t// sort points\r\n\tsort(0, 0, 1, ids, 0, 1)\r\n\r\n\r\n\t// return reordered ids with provided methods\r\n\t// save level offsets in output buffer\r\n\tvar offset = 0\r\n\tfor (var level = 0; level < levels.length; level++) {\r\n\t\tvar levelItems = levels[level]\r\n\t\tif (ids.set) { ids.set(levelItems, offset) }\r\n\t\telse {\r\n\t\t\tfor (var i$1 = 0, l = levelItems.length; i$1 < l; i$1++) {\r\n\t\t\t\tids[i$1 + offset] = levelItems[i$1]\r\n\t\t\t}\r\n\t\t}\r\n\t\tvar nextOffset = offset + levels[level].length\r\n\t\toffsets[level] = [offset, nextOffset]\r\n\t\toffset = nextOffset\r\n\t}\r\n\r\n\tids.range = range\r\n\r\n\treturn ids\r\n\r\n\r\n\r\n\t// FIXME: it is possible to create one typed array heap and reuse that to avoid memory blow\r\n\tfunction sort (x, y, diam, ids, level, group) {\r\n\t\tif (!ids.length) { return null }\r\n\r\n\t\t// save first point as level representative\r\n\t\tvar levelItems = levels[level] || (levels[level] = [])\r\n\t\tvar levelGroups = groups[level] || (groups[level] = [])\r\n\t\tvar sublevel = sublevels[level] || (sublevels[level] = [])\r\n\t\tvar offset = levelItems.length\r\n\r\n\t\tlevel++\r\n\r\n\t\t// max depth reached - put all items into a first group\r\n\t\t// alternatively - if group id overflow - avoid proceeding\r\n\t\tif (level > maxDepth || group > MAX_GROUP_ID) {\r\n\t\t\tfor (var i = 0; i < ids.length; i++) {\r\n\t\t\t\tlevelItems.push(ids[i])\r\n\t\t\t\tlevelGroups.push(group)\r\n\t\t\t\tsublevel.push(null, null, null, null)\r\n\t\t\t}\r\n\r\n\t\t\treturn offset\r\n\t\t}\r\n\r\n\t\tlevelItems.push(ids[0])\r\n\t\tlevelGroups.push(group)\r\n\r\n\t\tif (ids.length <= 1) {\r\n\t\t\tsublevel.push(null, null, null, null)\r\n\t\t\treturn offset\r\n\t\t}\r\n\r\n\r\n\t\tvar d2 = diam * .5\r\n\t\tvar cx = x + d2, cy = y + d2\r\n\r\n\t\t// distribute points by 4 buckets\r\n\t\tvar lolo = [], lohi = [], hilo = [], hihi = []\r\n\r\n\t\tfor (var i$1 = 1, l = ids.length; i$1 < l; i$1++) {\r\n\t\t\tvar idx = ids[i$1],\r\n\t\t\t\tx$1 = points[idx * 2],\r\n\t\t\t\ty$1 = points[idx * 2 + 1]\r\n\t\t\tx$1 < cx ? (y$1 < cy ? lolo.push(idx) : lohi.push(idx)) : (y$1 < cy ? hilo.push(idx) : hihi.push(idx))\r\n\t\t}\r\n\r\n\t\tgroup <<= 2\r\n\r\n\t\tsublevel.push(\r\n\t\t\tsort(x, y, d2, lolo, level, group),\r\n\t\t\tsort(x, cy, d2, lohi, level, group + 1),\r\n\t\t\tsort(cx, y, d2, hilo, level, group + 2),\r\n\t\t\tsort(cx, cy, d2, hihi, level, group + 3)\r\n\t\t)\r\n\r\n\t\treturn offset\r\n\t}\r\n\r\n\t// get all points within the passed range\r\n\tfunction range () {\n\t\tvar args = [], len = arguments.length;\n\t\twhile ( len-- ) args[ len ] = arguments[ len ];\n\r\n\t\tvar options\r\n\r\n\t\tif (isObj(args[args.length - 1])) {\r\n\t\t\tvar arg = args.pop()\r\n\r\n\t\t\t// detect if that was a rect object\r\n\t\t\tif (!args.length && (arg.x != null || arg.l != null || arg.left != null)) {\r\n\t\t\t\targs = [arg]\r\n\t\t\t\toptions = {}\r\n\t\t\t}\r\n\r\n\t\t\toptions = pick(arg, {\r\n\t\t\t\tlevel: 'level maxLevel',\r\n\t\t\t\td: 'd diam diameter r radius px pxSize pixel pixelSize maxD size minSize',\r\n\t\t\t\tlod: 'lod details ranges offsets'\r\n\t\t\t})\r\n\t\t}\r\n\t\telse {\r\n\t\t\toptions = {}\r\n\t\t}\r\n\r\n\t\tif (!args.length) { args = bounds }\r\n\r\n\t\tvar box = rect.apply( void 0, args )\r\n\r\n\t\tvar ref = [\r\n\t\t\tMath.min(box.x, box.x + box.width),\r\n\t\t\tMath.min(box.y, box.y + box.height),\r\n\t\t\tMath.max(box.x, box.x + box.width),\r\n\t\t\tMath.max(box.y, box.y + box.height)\r\n\t\t];\n\t\tvar minX = ref[0];\n\t\tvar minY = ref[1];\n\t\tvar maxX = ref[2];\n\t\tvar maxY = ref[3];\r\n\r\n\t\tvar ref$1 = normalize([minX, minY, maxX, maxY], bounds );\n\t\tvar nminX = ref$1[0];\n\t\tvar nminY = ref$1[1];\n\t\tvar nmaxX = ref$1[2];\n\t\tvar nmaxY = ref$1[3];\r\n\r\n\t\tvar maxLevel = defined(options.level, levels.length)\r\n\r\n\t\t// limit maxLevel by px size\r\n\t\tif (options.d != null) {\r\n\t\t\tvar d\r\n\t\t\tif (typeof options.d === 'number') { d = [options.d, options.d] }\r\n\t\t\telse if (options.d.length) { d = options.d }\r\n\r\n\t\t\tmaxLevel = Math.min(\r\n\t\t\t\tMath.max(\r\n\t\t\t\t\tMath.ceil(-log2(Math.abs(d[0]) / (bounds[2] - bounds[0]))),\r\n\t\t\t\t\tMath.ceil(-log2(Math.abs(d[1]) / (bounds[3] - bounds[1])))\r\n\t\t\t\t),\r\n\t\t\t\tmaxLevel\r\n\t\t\t)\r\n\t\t}\r\n\t\tmaxLevel = Math.min(maxLevel, levels.length)\r\n\r\n\t\t// return levels of details\r\n\t\tif (options.lod) {\r\n\t\t\treturn lod(nminX, nminY, nmaxX, nmaxY, maxLevel)\r\n\t\t}\r\n\r\n\r\n\r\n\t\t// do selection ids\r\n\t\tvar selection = []\r\n\r\n\t\t// FIXME: probably we can do LOD here beforehead\r\n\t\tselect( 0, 0, 1, 0, 0, 1)\r\n\r\n\t\tfunction select ( lox, loy, d, level, from, to ) {\r\n\t\t\tif (from === null || to === null) { return }\r\n\r\n\t\t\tvar hix = lox + d\r\n\t\t\tvar hiy = loy + d\r\n\r\n\t\t\t// if box does not intersect level - ignore\r\n\t\t\tif ( nminX > hix || nminY > hiy || nmaxX < lox || nmaxY < loy ) { return }\r\n\t\t\tif ( level >= maxLevel ) { return }\r\n\t\t\tif ( from === to ) { return }\r\n\r\n\t\t\t// if points fall into box range - take it\r\n\t\t\tvar levelItems = levels[level]\r\n\r\n\t\t\tif (to === undefined) { to = levelItems.length }\r\n\r\n\t\t\tfor (var i = from; i < to; i++) {\r\n\t\t\t\tvar id = levelItems[i]\r\n\r\n\t\t\t\tvar px = srcPoints[ id * 2 ]\r\n\t\t\t\tvar py = srcPoints[ id * 2 + 1 ]\r\n\r\n\t\t\t\tif ( px >= minX && px <= maxX && py >= minY && py <= maxY ) {selection.push(id)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// for every subsection do select\r\n\t\t\tvar offsets = sublevels[ level ]\r\n\t\t\tvar off0 = offsets[ from * 4 + 0 ]\r\n\t\t\tvar off1 = offsets[ from * 4 + 1 ]\r\n\t\t\tvar off2 = offsets[ from * 4 + 2 ]\r\n\t\t\tvar off3 = offsets[ from * 4 + 3 ]\r\n\t\t\tvar end = nextOffset(offsets, from + 1)\r\n\r\n\t\t\tvar d2 = d * .5\r\n\t\t\tvar nextLevel = level + 1\r\n\t\t\tselect( lox, loy, d2, nextLevel, off0, off1 || off2 || off3 || end)\r\n\t\t\tselect( lox, loy + d2, d2, nextLevel, off1, off2 || off3 || end)\r\n\t\t\tselect( lox + d2, loy, d2, nextLevel, off2, off3 || end)\r\n\t\t\tselect( lox + d2, loy + d2, d2, nextLevel, off3, end)\r\n\t\t}\r\n\r\n\t\tfunction nextOffset(offsets, from) {\r\n\t\t\tvar offset = null, i = 0\r\n\t\t\twhile(offset === null) {\r\n\t\t\t\toffset = offsets[ from * 4 + i ]\r\n\t\t\t\ti++\r\n\t\t\t\tif (i > offsets.length) { return null }\r\n\t\t\t}\r\n\t\t\treturn offset\r\n\t\t}\r\n\r\n\t\treturn selection\r\n\t}\r\n\r\n\t// get range offsets within levels to render lods appropriate for zoom level\r\n\t// TODO: it is possible to store minSize of a point to optimize neede level calc\r\n\tfunction lod (lox, loy, hix, hiy, maxLevel) {\r\n\t\tvar ranges = []\r\n\r\n\t\tfor (var level = 0; level < maxLevel; level++) {\r\n\t\t\tvar levelGroups = groups[level]\r\n\t\t\tvar from = offsets[level][0]\r\n\r\n\t\t\tvar levelGroupStart = group(lox, loy, level)\r\n\t\t\tvar levelGroupEnd = group(hix, hiy, level)\r\n\r\n\t\t\t// FIXME: utilize sublevels to speed up search range here\r\n\t\t\tvar startOffset = search.ge(levelGroups, levelGroupStart)\r\n\t\t\tvar endOffset = search.gt(levelGroups, levelGroupEnd, startOffset, levelGroups.length - 1)\r\n\r\n\t\t\tranges[level] = [startOffset + from, endOffset + from]\r\n\t\t}\r\n\r\n\t\treturn ranges\r\n\t}\r\n\r\n\t// get group id closest to the x,y coordinate, corresponding to a level\r\n\tfunction group (x, y, level) {\r\n\t\tvar group = 1\r\n\r\n\t\tvar cx = .5, cy = .5\r\n\t\tvar diam = .5\r\n\r\n\t\tfor (var i = 0; i < level; i++) {\r\n\t\t\tgroup <<= 2\r\n\r\n\t\t\tgroup += x < cx ? (y < cy ? 0 : 1) : (y < cy ? 2 : 3)\r\n\r\n\t\t\tdiam *= .5\r\n\r\n\t\t\tcx += x < cx ? -diam : diam\r\n\t\t\tcy += y < cy ? -diam : diam\r\n\t\t}\r\n\r\n\t\treturn group\r\n\t}\r\n}\r\n\r\n\r\n// normalize points by bounds\r\nfunction normalize (pts, bounds) {\r\n\tvar lox = bounds[0];\n\tvar loy = bounds[1];\n\tvar hix = bounds[2];\n\tvar hiy = bounds[3];\r\n\tvar scaleX = 1.0 / (hix - lox)\r\n\tvar scaleY = 1.0 / (hiy - loy)\r\n\tvar result = new Array(pts.length)\r\n\r\n\tfor (var i = 0, n = pts.length / 2; i < n; i++) {\r\n\t\tresult[2*i] = clamp((pts[2*i] - lox) * scaleX, 0, 1)\r\n\t\tresult[2*i+1] = clamp((pts[2*i+1] - loy) * scaleY, 0, 1)\r\n\t}\r\n\r\n\treturn result\r\n}\r\n},{\"array-bounds\":65,\"binary-search-bounds\":498,\"clamp\":115,\"defined\":164,\"dtype\":169,\"flatten-vertex-data\":227,\"is-obj\":421,\"math-log2\":432,\"parse-rect\":459,\"pick-by-alias\":465}],501:[function(_dereq_,module,exports){\n'use strict'\n\n\nvar createScatter = _dereq_('regl-scatter2d')\nvar pick = _dereq_('pick-by-alias')\nvar getBounds = _dereq_('array-bounds')\nvar raf = _dereq_('raf')\nvar arrRange = _dereq_('array-range')\nvar rect = _dereq_('parse-rect')\nvar flatten = _dereq_('flatten-vertex-data')\n\n\nmodule.exports = SPLOM\n\n\n// @constructor\nfunction SPLOM (regl, options) {\n\tif (!(this instanceof SPLOM)) { return new SPLOM(regl, options) }\n\n\t// render passes\n\tthis.traces = []\n\n\t// passes for scatter, combined across traces\n\tthis.passes = {}\n\n\tthis.regl = regl\n\n\t// main scatter drawing instance\n\tthis.scatter = createScatter(regl)\n\n\tthis.canvas = this.scatter.canvas\n}\n\n\n// update & draw passes once per frame\nSPLOM.prototype.render = function () {\n\tvar this$1 = this;\n\tvar ref;\n\n\tvar args = [], len = arguments.length;\n\twhile ( len-- ) args[ len ] = arguments[ len ];\n\tif (args.length) {\n\t\t(ref = this).update.apply(ref, args)\n\t}\n\n\tif (this.regl.attributes.preserveDrawingBuffer) { return this.draw() }\n\n\t// make sure draw is not called more often than once a frame\n\tif (this.dirty) {\n\t\tif (this.planned == null) {\n\t\t\tthis.planned = raf(function () {\n\t\t\t\tthis$1.draw()\n\t\t\t\tthis$1.dirty = true\n\t\t\t\tthis$1.planned = null\n\t\t\t})\n\t\t}\n\t}\n\telse {\n\t\tthis.draw()\n\t\tthis.dirty = true\n\t\traf(function () {\n\t\t\tthis$1.dirty = false\n\t\t})\n\t}\n\n\treturn this\n}\n\n\n// update passes\nSPLOM.prototype.update = function () {\n\tvar this$1 = this;\n\tvar ref;\n\n\tvar args = [], len = arguments.length;\n\twhile ( len-- ) args[ len ] = arguments[ len ];\n\tif (!args.length) { return }\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tthis$1.updateItem(i, args[i])\n\t}\n\n\t// remove nulled passes\n\tthis.traces = this.traces.filter(Boolean)\n\n\t// FIXME: update passes independently\n\tvar passes = []\n\tvar offset = 0\n\tfor (var i$1 = 0; i$1 < this.traces.length; i$1++) {\n\t\tvar trace = this$1.traces[i$1]\n\t\tvar tracePasses = this$1.traces[i$1].passes\n\t\tfor (var j = 0; j < tracePasses.length; j++) {\n\t\t\tpasses.push(this$1.passes[tracePasses[j]])\n\t\t}\n\t\t// save offset of passes\n\t\ttrace.passOffset = offset\n\t\toffset += trace.passes.length\n\t}\n\n\t(ref = this.scatter).update.apply(ref, passes)\n\n\treturn this\n}\n\n\n// update trace by index, not supposed to be called directly\nSPLOM.prototype.updateItem = function (i, options) {\n\tvar this$1 = this;\n\n\tvar ref = this;\n\tvar regl = ref.regl;\n\n\t// remove pass if null\n\tif (options === null) {\n\t\tthis.traces[i] = null\n\t\treturn this\n\t}\n\n\tif (!options) { return this }\n\n\tvar o = pick(options, {\n\t\tdata: 'data items columns rows values dimensions samples x',\n\t\tsnap: 'snap cluster',\n\t\tsize: 'sizes size radius',\n\t\tcolor: 'colors color fill fill-color fillColor',\n\t\topacity: 'opacity alpha transparency opaque',\n\t\tborderSize: 'borderSizes borderSize border-size bordersize borderWidth borderWidths border-width borderwidth stroke-width strokeWidth strokewidth outline',\n\t\tborderColor: 'borderColors borderColor bordercolor stroke stroke-color strokeColor',\n\t\tmarker: 'markers marker shape',\n\t\trange: 'range ranges databox dataBox',\n\t\tviewport: 'viewport viewBox viewbox',\n\t\tdomain: 'domain domains area areas',\n\t\tpadding: 'pad padding paddings pads margin margins',\n\t\ttranspose: 'transpose transposed',\n\t\tdiagonal: 'diagonal diag showDiagonal',\n\t\tupper: 'upper up top upperhalf upperHalf showupperhalf showUpper showUpperHalf',\n\t\tlower: 'lower low bottom lowerhalf lowerHalf showlowerhalf showLowerHalf showLower'\n\t})\n\n\t// we provide regl buffer per-trace, since trace data can be changed\n\tvar trace = (this.traces[i] || (this.traces[i] = {\n\t\tid: i,\n\t\tbuffer: regl.buffer({\n\t\t\tusage: 'dynamic',\n\t\t\ttype: 'float',\n\t\t\tdata: new Uint8Array()\n\t\t}),\n\t\tcolor: 'black',\n\t\tmarker: null,\n\t\tsize: 12,\n\t\tborderColor: 'transparent',\n\t\tborderSize: 1,\n\t\tviewport:  rect([regl._gl.drawingBufferWidth, regl._gl.drawingBufferHeight]),\n\t\tpadding: [0, 0, 0, 0],\n\t\topacity: 1,\n\t\tdiagonal: true,\n\t\tupper: true,\n\t\tlower: true\n\t}))\n\n\n\t// save styles\n\tif (o.color != null) {\n\t\ttrace.color = o.color\n\t}\n\tif (o.size != null) {\n\t\ttrace.size = o.size\n\t}\n\tif (o.marker != null) {\n\t\ttrace.marker = o.marker\n\t}\n\tif (o.borderColor != null) {\n\t\ttrace.borderColor = o.borderColor\n\t}\n\tif (o.borderSize != null) {\n\t\ttrace.borderSize = o.borderSize\n\t}\n\tif (o.opacity != null) {\n\t\ttrace.opacity = o.opacity\n\t}\n\tif (o.viewport) {\n\t\ttrace.viewport = rect(o.viewport)\n\t}\n\tif (o.diagonal != null) { trace.diagonal = o.diagonal }\n\tif (o.upper != null) { trace.upper = o.upper }\n\tif (o.lower != null) { trace.lower = o.lower }\n\n\t// put flattened data into buffer\n\tif (o.data) {\n\t\ttrace.buffer(flatten(o.data))\n\t\ttrace.columns = o.data.length\n\t\ttrace.count = o.data[0].length\n\n\t\t// detect bounds per-column\n\t\ttrace.bounds = []\n\n\t\tfor (var i$1 = 0; i$1 < trace.columns; i$1++) {\n\t\t\ttrace.bounds[i$1] = getBounds(o.data[i$1], 1)\n\t\t}\n\t}\n\n\t// add proper range updating markers\n\tvar multirange\n\tif (o.range) {\n\t\ttrace.range = o.range\n\t\tmultirange = trace.range && typeof trace.range[0] !== 'number'\n\t}\n\n\tif (o.domain) {\n\t\ttrace.domain = o.domain\n\t}\n\tvar multipadding = false\n\tif (o.padding != null) {\n\t\t// multiple paddings\n\t\tif (Array.isArray(o.padding) && o.padding.length === trace.columns && typeof o.padding[o.padding.length - 1] === 'number') {\n\t\t\ttrace.padding = o.padding.map(getPad)\n\t\t\tmultipadding = true\n\t\t}\n\t\t// single padding\n\t\telse {\n\t\t\ttrace.padding = getPad(o.padding)\n\t\t}\n\t}\n\n\t// create passes\n\tvar m = trace.columns\n\tvar n = trace.count\n\n\tvar w = trace.viewport.width\n\tvar h = trace.viewport.height\n\tvar left = trace.viewport.x\n\tvar top = trace.viewport.y\n\tvar iw = w / m\n\tvar ih = h / m\n\n\ttrace.passes = []\n\n\tfor (var i$2 = 0; i$2 < m; i$2++) {\n\t\tfor (var j = 0; j < m; j++) {\n\t\t\tif (!trace.diagonal && j === i$2) { continue }\n\t\t\tif (!trace.upper && i$2 > j) { continue }\n\t\t\tif (!trace.lower && i$2 < j) { continue }\n\n\t\t\tvar key = passId(trace.id, i$2, j)\n\n\t\t\tvar pass = this$1.passes[key] || (this$1.passes[key] = {})\n\n\t\t\tif (o.data) {\n\t\t\t\tif (o.transpose) {\n\t\t\t\t\tpass.positions = {\n\t\t\t\t\t\tx: {buffer: trace.buffer, offset: j, count: n, stride: m},\n\t\t\t\t\t\ty: {buffer: trace.buffer, offset: i$2, count: n, stride: m}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tpass.positions = {\n\t\t\t\t\t\tx: {buffer: trace.buffer, offset: j * n, count: n},\n\t\t\t\t\t\ty: {buffer: trace.buffer, offset: i$2 * n, count: n}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tpass.bounds = getBox(trace.bounds, i$2, j)\n\t\t\t}\n\n\t\t\tif (o.domain || o.viewport || o.data) {\n\t\t\t\tvar pad = multipadding ? getBox(trace.padding, i$2, j) : trace.padding\n\t\t\t\tif (trace.domain) {\n\t\t\t\t\tvar ref$1 = getBox(trace.domain, i$2, j);\n\t\t\t\t\tvar lox = ref$1[0];\n\t\t\t\t\tvar loy = ref$1[1];\n\t\t\t\t\tvar hix = ref$1[2];\n\t\t\t\t\tvar hiy = ref$1[3];\n\n\t\t\t\t\tpass.viewport = [\n\t\t\t\t\t\tleft + lox * w + pad[0],\n\t\t\t\t\t\ttop + loy * h + pad[1],\n\t\t\t\t\t\tleft + hix * w - pad[2],\n\t\t\t\t\t\ttop + hiy * h - pad[3]\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t\t// consider auto-domain equipartial\n\t\t\t\telse {\n\t\t\t\t\tpass.viewport = [\n\t\t\t\t\t\tleft + j * iw + iw * pad[0],\n\t\t\t\t\t\ttop + i$2 * ih + ih * pad[1],\n\t\t\t\t\t\tleft + (j + 1) * iw - iw * pad[2],\n\t\t\t\t\t\ttop + (i$2 + 1) * ih - ih * pad[3]\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (o.color) { pass.color = trace.color }\n\t\t\tif (o.size) { pass.size = trace.size }\n\t\t\tif (o.marker) { pass.marker = trace.marker }\n\t\t\tif (o.borderSize) { pass.borderSize = trace.borderSize }\n\t\t\tif (o.borderColor) { pass.borderColor = trace.borderColor }\n\t\t\tif (o.opacity) { pass.opacity = trace.opacity }\n\n\t\t\tif (o.range) {\n\t\t\t\tpass.range = multirange ? getBox(trace.range, i$2, j) : trace.range || pass.bounds\n\t\t\t}\n\n\t\t\ttrace.passes.push(key)\n\t\t}\n\t}\n\n\treturn this\n}\n\n\n// draw all or passed passes\nSPLOM.prototype.draw = function () {\n\tvar this$1 = this;\n\tvar ref$2;\n\n\tvar args = [], len = arguments.length;\n\twhile ( len-- ) args[ len ] = arguments[ len ];\n\tif (!args.length) {\n\t\tthis.scatter.draw()\n\t}\n\telse {\n\t\tvar idx = []\n\t\tfor (var i = 0; i < args.length; i++) {\n\t\t\t// draw(0, 2, 5) - draw traces\n\t\t\tif (typeof args[i] === 'number' ) {\n\t\t\t\tvar ref = this$1.traces[args[i]];\n\t\t\t\tvar passes = ref.passes;\n\t\t\t\tvar passOffset = ref.passOffset;\n\t\t\t\tidx.push.apply(idx, arrRange(passOffset, passOffset + passes.length))\n\t\t\t}\n\t\t\t// draw([0, 1, 2 ...], [3, 4, 5]) - draw points\n\t\t\telse if (args[i].length) {\n\t\t\t\tvar els = args[i]\n\t\t\t\tvar ref$1 = this$1.traces[i];\n\t\t\t\tvar passes$1 = ref$1.passes;\n\t\t\t\tvar passOffset$1 = ref$1.passOffset;\n\t\t\t\tpasses$1 = passes$1.map(function (passId, i) {\n\t\t\t\t\tidx[passOffset$1 + i] = els\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\t(ref$2 = this.scatter).draw.apply(ref$2, idx)\n\t}\n\n\treturn this\n}\n\n\n// dispose resources\nSPLOM.prototype.destroy = function () {\n\tthis.traces.forEach(function (trace) {\n\t\tif (trace.buffer && trace.buffer.destroy) { trace.buffer.destroy() }\n\t})\n\tthis.traces = null\n\tthis.passes = null\n\n\tthis.scatter.destroy()\n\n\treturn this\n}\n\n\n// return pass corresponding to trace i- j- square\nfunction passId (trace, i, j) {\n\tvar id = (trace.id != null ? trace.id : trace)\n\tvar n = i\n\tvar m = j\n\tvar key = id << 16 | (n & 0xff) << 8 | m & 0xff\n\n\treturn key\n}\n\n\n// return bounding box corresponding to a pass\nfunction getBox (items, i, j) {\n\tvar ilox, iloy, ihix, ihiy, jlox, jloy, jhix, jhiy\n\tvar iitem = items[i], jitem = items[j]\n\n\tif (iitem.length > 2) {\n\t\tilox = iitem[0]\n\t\tihix = iitem[2]\n\t\tiloy = iitem[1]\n\t\tihiy = iitem[3]\n\t}\n\telse if (iitem.length) {\n\t\tilox = iloy = iitem[0]\n\t\tihix = ihiy = iitem[1]\n\t}\n\telse {\n\t\tilox = iitem.x\n\t\tiloy = iitem.y\n\t\tihix = iitem.x + iitem.width\n\t\tihiy = iitem.y + iitem.height\n\t}\n\n\tif (jitem.length > 2) {\n\t\tjlox = jitem[0]\n\t\tjhix = jitem[2]\n\t\tjloy = jitem[1]\n\t\tjhiy = jitem[3]\n\t}\n\telse if (jitem.length) {\n\t\tjlox = jloy = jitem[0]\n\t\tjhix = jhiy = jitem[1]\n\t}\n\telse {\n\t\tjlox = jitem.x\n\t\tjloy = jitem.y\n\t\tjhix = jitem.x + jitem.width\n\t\tjhiy = jitem.y + jitem.height\n\t}\n\n\treturn [ jlox, iloy, jhix, ihiy ]\n}\n\n\nfunction getPad (arg) {\n\tif (typeof arg === 'number') { return [arg, arg, arg, arg] }\n\telse if (arg.length === 2) { return [arg[0], arg[1], arg[0], arg[1]] }\n\telse {\n\t\tvar box = rect(arg)\n\t\treturn [box.x, box.y, box.x + box.width, box.y + box.height]\n\t}\n}\n\n},{\"array-bounds\":65,\"array-range\":67,\"flatten-vertex-data\":227,\"parse-rect\":459,\"pick-by-alias\":465,\"raf\":484,\"regl-scatter2d\":497}],502:[function(_dereq_,module,exports){\n(function(aa,ia){\"object\"===typeof exports&&\"undefined\"!==typeof module?module.exports=ia():\"function\"===typeof define&&define.amd?define(ia):aa.createREGL=ia()})(this,function(){function aa(a,b){this.id=Ab++;this.type=a;this.data=b}function ia(a){if(0===a.length)return[];var b=a.charAt(0),c=a.charAt(a.length-1);if(1<a.length&&b===c&&('\"'===b||\"'\"===b))return['\"'+a.substr(1,a.length-2).replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,'\\\\\"')+'\"'];if(b=/\\[(false|true|null|\\d+|'[^']*'|\"[^\"]*\")\\]/.exec(a))return ia(a.substr(0,\nb.index)).concat(ia(b[1])).concat(ia(a.substr(b.index+b[0].length)));b=a.split(\".\");if(1===b.length)return['\"'+a.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,'\\\\\"')+'\"'];a=[];for(c=0;c<b.length;++c)a=a.concat(ia(b[c]));return a}function Za(a){return\"[\"+ia(a).join(\"][\")+\"]\"}function Bb(){var a={\"\":0},b=[\"\"];return{id:function(c){var e=a[c];if(e)return e;e=a[c]=b.length;b.push(c);return e},str:function(a){return b[a]}}}function Cb(a,b,c){function e(){var b=window.innerWidth,e=window.innerHeight;a!==document.body&&\n(e=a.getBoundingClientRect(),b=e.right-e.left,e=e.bottom-e.top);g.width=c*b;g.height=c*e;E(g.style,{width:b+\"px\",height:e+\"px\"})}var g=document.createElement(\"canvas\");E(g.style,{border:0,margin:0,padding:0,top:0,left:0});a.appendChild(g);a===document.body&&(g.style.position=\"absolute\",E(a.style,{margin:0,padding:0}));window.addEventListener(\"resize\",e,!1);e();return{canvas:g,onDestroy:function(){window.removeEventListener(\"resize\",e);a.removeChild(g)}}}function Db(a,b){function c(c){try{return a.getContext(c,\nb)}catch(g){return null}}return c(\"webgl\")||c(\"experimental-webgl\")||c(\"webgl-experimental\")}function $a(a){return\"string\"===typeof a?a.split():a}function ab(a){return\"string\"===typeof a?document.querySelector(a):a}function Eb(a){var b=a||{},c,e,g,d;a={};var n=[],f=[],r=\"undefined\"===typeof window?1:window.devicePixelRatio,q=!1,t=function(a){},m=function(){};\"string\"===typeof b?c=document.querySelector(b):\"object\"===typeof b&&(\"string\"===typeof b.nodeName&&\"function\"===typeof b.appendChild&&\"function\"===\ntypeof b.getBoundingClientRect?c=b:\"function\"===typeof b.drawArrays||\"function\"===typeof b.drawElements?(d=b,g=d.canvas):(\"gl\"in b?d=b.gl:\"canvas\"in b?g=ab(b.canvas):\"container\"in b&&(e=ab(b.container)),\"attributes\"in b&&(a=b.attributes),\"extensions\"in b&&(n=$a(b.extensions)),\"optionalExtensions\"in b&&(f=$a(b.optionalExtensions)),\"onDone\"in b&&(t=b.onDone),\"profile\"in b&&(q=!!b.profile),\"pixelRatio\"in b&&(r=+b.pixelRatio)));c&&(\"canvas\"===c.nodeName.toLowerCase()?g=c:e=c);if(!d){if(!g){c=Cb(e||document.body,\nt,r);if(!c)return null;g=c.canvas;m=c.onDestroy}d=Db(g,a)}return d?{gl:d,canvas:g,container:e,extensions:n,optionalExtensions:f,pixelRatio:r,profile:q,onDone:t,onDestroy:m}:(m(),t(\"webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org\"),null)}function Fb(a,b){function c(b){b=b.toLowerCase();var c;try{c=e[b]=a.getExtension(b)}catch(g){}return!!c}for(var e={},g=0;g<b.extensions.length;++g){var d=b.extensions[g];if(!c(d))return b.onDestroy(),b.onDone('\"'+d+'\" extension is not supported by the current WebGL context, try upgrading your system or a different browser'),\nnull}b.optionalExtensions.forEach(c);return{extensions:e,restore:function(){Object.keys(e).forEach(function(a){if(e[a]&&!c(a))throw Error(\"(regl): error restoring extension \"+a);})}}}function J(a,b){for(var c=Array(a),e=0;e<a;++e)c[e]=b(e);return c}function bb(a){var b,c;b=(65535<a)<<4;a>>>=b;c=(255<a)<<3;a>>>=c;b|=c;c=(15<a)<<2;a>>>=c;b|=c;c=(3<a)<<1;return b|c|a>>>c>>1}function cb(){function a(a){a:{for(var b=16;268435456>=b;b*=16)if(a<=b){a=b;break a}a=0}b=c[bb(a)>>2];return 0<b.length?b.pop():\nnew ArrayBuffer(a)}function b(a){c[bb(a.byteLength)>>2].push(a)}var c=J(8,function(){return[]});return{alloc:a,free:b,allocType:function(b,c){var d=null;switch(b){case 5120:d=new Int8Array(a(c),0,c);break;case 5121:d=new Uint8Array(a(c),0,c);break;case 5122:d=new Int16Array(a(2*c),0,c);break;case 5123:d=new Uint16Array(a(2*c),0,c);break;case 5124:d=new Int32Array(a(4*c),0,c);break;case 5125:d=new Uint32Array(a(4*c),0,c);break;case 5126:d=new Float32Array(a(4*c),0,c);break;default:return null}return d.length!==\nc?d.subarray(0,c):d},freeType:function(a){b(a.buffer)}}}function ma(a){return!!a&&\"object\"===typeof a&&Array.isArray(a.shape)&&Array.isArray(a.stride)&&\"number\"===typeof a.offset&&a.shape.length===a.stride.length&&(Array.isArray(a.data)||M(a.data))}function db(a,b,c,e,g,d){for(var n=0;n<b;++n)for(var f=a[n],r=0;r<c;++r)for(var q=f[r],t=0;t<e;++t)g[d++]=q[t]}function eb(a,b,c,e,g){for(var d=1,n=c+1;n<b.length;++n)d*=b[n];var f=b[c];if(4===b.length-c){var r=b[c+1],q=b[c+2];b=b[c+3];for(n=0;n<f;++n)db(a[n],\nr,q,b,e,g),g+=d}else for(n=0;n<f;++n)eb(a[n],b,c+1,e,g),g+=d}function Ha(a){return Ia[Object.prototype.toString.call(a)]|0}function fb(a,b){for(var c=0;c<b.length;++c)a[c]=b[c]}function gb(a,b,c,e,g,d,n){for(var f=0,r=0;r<c;++r)for(var q=0;q<e;++q)a[f++]=b[g*r+d*q+n]}function Gb(a,b,c,e){function g(b){this.id=r++;this.buffer=a.createBuffer();this.type=b;this.usage=35044;this.byteLength=0;this.dimension=1;this.dtype=5121;this.persistentData=null;c.profile&&(this.stats={size:0})}function d(b,c,k){b.byteLength=\nc.byteLength;a.bufferData(b.type,c,k)}function n(a,b,c,h,l,e){a.usage=c;if(Array.isArray(b)){if(a.dtype=h||5126,0<b.length)if(Array.isArray(b[0])){l=hb(b);for(var v=h=1;v<l.length;++v)h*=l[v];a.dimension=h;b=Qa(b,l,a.dtype);d(a,b,c);e?a.persistentData=b:x.freeType(b)}else\"number\"===typeof b[0]?(a.dimension=l,l=x.allocType(a.dtype,b.length),fb(l,b),d(a,l,c),e?a.persistentData=l:x.freeType(l)):M(b[0])&&(a.dimension=b[0].length,a.dtype=h||Ha(b[0])||5126,b=Qa(b,[b.length,b[0].length],a.dtype),d(a,b,c),\ne?a.persistentData=b:x.freeType(b))}else if(M(b))a.dtype=h||Ha(b),a.dimension=l,d(a,b,c),e&&(a.persistentData=new Uint8Array(new Uint8Array(b.buffer)));else if(ma(b)){l=b.shape;var g=b.stride,v=b.offset,f=0,q=0,r=0,t=0;1===l.length?(f=l[0],q=1,r=g[0],t=0):2===l.length&&(f=l[0],q=l[1],r=g[0],t=g[1]);a.dtype=h||Ha(b.data)||5126;a.dimension=q;l=x.allocType(a.dtype,f*q);gb(l,b.data,f,q,r,t,v);d(a,l,c);e?a.persistentData=l:x.freeType(l)}}function f(c){b.bufferCount--;for(var d=0;d<e.state.length;++d){var k=\ne.state[d];k.buffer===c&&(a.disableVertexAttribArray(d),k.buffer=null)}a.deleteBuffer(c.buffer);c.buffer=null;delete q[c.id]}var r=0,q={};g.prototype.bind=function(){a.bindBuffer(this.type,this.buffer)};g.prototype.destroy=function(){f(this)};var t=[];c.profile&&(b.getTotalBufferSize=function(){var a=0;Object.keys(q).forEach(function(b){a+=q[b].stats.size});return a});return{create:function(m,e,d,h){function l(b){var m=35044,e=null,d=0,k=0,g=1;Array.isArray(b)||M(b)||ma(b)?e=b:\"number\"===typeof b?\nd=b|0:b&&(\"data\"in b&&(e=b.data),\"usage\"in b&&(m=jb[b.usage]),\"type\"in b&&(k=Ra[b.type]),\"dimension\"in b&&(g=b.dimension|0),\"length\"in b&&(d=b.length|0));u.bind();e?n(u,e,m,k,g,h):(d&&a.bufferData(u.type,d,m),u.dtype=k||5121,u.usage=m,u.dimension=g,u.byteLength=d);c.profile&&(u.stats.size=u.byteLength*ja[u.dtype]);return l}b.bufferCount++;var u=new g(e);q[u.id]=u;d||l(m);l._reglType=\"buffer\";l._buffer=u;l.subdata=function(b,c){var m=(c||0)|0,e;u.bind();if(M(b))a.bufferSubData(u.type,m,b);else if(Array.isArray(b)){if(0<\nb.length)if(\"number\"===typeof b[0]){var d=x.allocType(u.dtype,b.length);fb(d,b);a.bufferSubData(u.type,m,d);x.freeType(d)}else if(Array.isArray(b[0])||M(b[0]))e=hb(b),d=Qa(b,e,u.dtype),a.bufferSubData(u.type,m,d),x.freeType(d)}else if(ma(b)){e=b.shape;var h=b.stride,k=d=0,g=0,F=0;1===e.length?(d=e[0],k=1,g=h[0],F=0):2===e.length&&(d=e[0],k=e[1],g=h[0],F=h[1]);e=Array.isArray(b.data)?u.dtype:Ha(b.data);e=x.allocType(e,d*k);gb(e,b.data,d,k,g,F,b.offset);a.bufferSubData(u.type,m,e);x.freeType(e)}return l};\nc.profile&&(l.stats=u.stats);l.destroy=function(){f(u)};return l},createStream:function(a,b){var c=t.pop();c||(c=new g(a));c.bind();n(c,b,35040,0,1,!1);return c},destroyStream:function(a){t.push(a)},clear:function(){S(q).forEach(f);t.forEach(f)},getBuffer:function(a){return a&&a._buffer instanceof g?a._buffer:null},restore:function(){S(q).forEach(function(b){b.buffer=a.createBuffer();a.bindBuffer(b.type,b.buffer);a.bufferData(b.type,b.persistentData||b.byteLength,b.usage)})},_initBuffer:n}}function Hb(a,\nb,c,e){function g(a){this.id=r++;f[this.id]=this;this.buffer=a;this.primType=4;this.type=this.vertCount=0}function d(e,d,g,h,l,u,v){e.buffer.bind();if(d){var f=v;v||M(d)&&(!ma(d)||M(d.data))||(f=b.oes_element_index_uint?5125:5123);c._initBuffer(e.buffer,d,g,f,3)}else a.bufferData(34963,u,g),e.buffer.dtype=f||5121,e.buffer.usage=g,e.buffer.dimension=3,e.buffer.byteLength=u;f=v;if(!v){switch(e.buffer.dtype){case 5121:case 5120:f=5121;break;case 5123:case 5122:f=5123;break;case 5125:case 5124:f=5125}e.buffer.dtype=\nf}e.type=f;d=l;0>d&&(d=e.buffer.byteLength,5123===f?d>>=1:5125===f&&(d>>=2));e.vertCount=d;d=h;0>h&&(d=4,h=e.buffer.dimension,1===h&&(d=0),2===h&&(d=1),3===h&&(d=4));e.primType=d}function n(a){e.elementsCount--;delete f[a.id];a.buffer.destroy();a.buffer=null}var f={},r=0,q={uint8:5121,uint16:5123};b.oes_element_index_uint&&(q.uint32=5125);g.prototype.bind=function(){this.buffer.bind()};var t=[];return{create:function(a,b){function k(a){if(a)if(\"number\"===typeof a)h(a),l.primType=4,l.vertCount=a|0,\nl.type=5121;else{var b=null,c=35044,e=-1,g=-1,f=0,m=0;if(Array.isArray(a)||M(a)||ma(a))b=a;else if(\"data\"in a&&(b=a.data),\"usage\"in a&&(c=jb[a.usage]),\"primitive\"in a&&(e=Sa[a.primitive]),\"count\"in a&&(g=a.count|0),\"type\"in a&&(m=q[a.type]),\"length\"in a)f=a.length|0;else if(f=g,5123===m||5122===m)f*=2;else if(5125===m||5124===m)f*=4;d(l,b,c,e,g,f,m)}else h(),l.primType=4,l.vertCount=0,l.type=5121;return k}var h=c.create(null,34963,!0),l=new g(h._buffer);e.elementsCount++;k(a);k._reglType=\"elements\";\nk._elements=l;k.subdata=function(a,b){h.subdata(a,b);return k};k.destroy=function(){n(l)};return k},createStream:function(a){var b=t.pop();b||(b=new g(c.create(null,34963,!0,!1)._buffer));d(b,a,35040,-1,-1,0,0);return b},destroyStream:function(a){t.push(a)},getElements:function(a){return\"function\"===typeof a&&a._elements instanceof g?a._elements:null},clear:function(){S(f).forEach(n)}}}function kb(a){for(var b=x.allocType(5123,a.length),c=0;c<a.length;++c)if(isNaN(a[c]))b[c]=65535;else if(Infinity===\na[c])b[c]=31744;else if(-Infinity===a[c])b[c]=64512;else{lb[0]=a[c];var e=Ib[0],g=e>>>31<<15,d=(e<<1>>>24)-127,e=e>>13&1023;b[c]=-24>d?g:-14>d?g+(e+1024>>-14-d):15<d?g+31744:g+(d+15<<10)+e}return b}function pa(a){return Array.isArray(a)||M(a)}function Ea(a){return\"[object \"+a+\"]\"}function mb(a){return Array.isArray(a)&&(0===a.length||\"number\"===typeof a[0])}function nb(a){return Array.isArray(a)&&0!==a.length&&pa(a[0])?!0:!1}function na(a){return Object.prototype.toString.call(a)}function Ta(a){if(!a)return!1;\nvar b=na(a);return 0<=Jb.indexOf(b)?!0:mb(a)||nb(a)||ma(a)}function ob(a,b){36193===a.type?(a.data=kb(b),x.freeType(b)):a.data=b}function Ja(a,b,c,e,g,d){a=\"undefined\"!==typeof y[a]?y[a]:L[a]*qa[b];d&&(a*=6);if(g){for(e=0;1<=c;)e+=a*c*c,c/=2;return e}return a*c*e}function Kb(a,b,c,e,g,d,n){function f(){this.format=this.internalformat=6408;this.type=5121;this.flipY=this.premultiplyAlpha=this.compressed=!1;this.unpackAlignment=1;this.colorSpace=37444;this.channels=this.height=this.width=0}function r(a,\nb){a.internalformat=b.internalformat;a.format=b.format;a.type=b.type;a.compressed=b.compressed;a.premultiplyAlpha=b.premultiplyAlpha;a.flipY=b.flipY;a.unpackAlignment=b.unpackAlignment;a.colorSpace=b.colorSpace;a.width=b.width;a.height=b.height;a.channels=b.channels}function q(a,b){if(\"object\"===typeof b&&b){\"premultiplyAlpha\"in b&&(a.premultiplyAlpha=b.premultiplyAlpha);\"flipY\"in b&&(a.flipY=b.flipY);\"alignment\"in b&&(a.unpackAlignment=b.alignment);\"colorSpace\"in b&&(a.colorSpace=wa[b.colorSpace]);\n\"type\"in b&&(a.type=G[b.type]);var c=a.width,e=a.height,d=a.channels,h=!1;\"shape\"in b?(c=b.shape[0],e=b.shape[1],3===b.shape.length&&(d=b.shape[2],h=!0)):(\"radius\"in b&&(c=e=b.radius),\"width\"in b&&(c=b.width),\"height\"in b&&(e=b.height),\"channels\"in b&&(d=b.channels,h=!0));a.width=c|0;a.height=e|0;a.channels=d|0;c=!1;\"format\"in b&&(c=b.format,e=a.internalformat=U[c],a.format=Lb[e],c in G&&!(\"type\"in b)&&(a.type=G[c]),c in W&&(a.compressed=!0),c=!0);!h&&c?a.channels=L[a.format]:h&&!c&&a.channels!==\nLa[a.format]&&(a.format=a.internalformat=La[a.channels])}}function t(b){a.pixelStorei(37440,b.flipY);a.pixelStorei(37441,b.premultiplyAlpha);a.pixelStorei(37443,b.colorSpace);a.pixelStorei(3317,b.unpackAlignment)}function m(){f.call(this);this.yOffset=this.xOffset=0;this.data=null;this.needsFree=!1;this.element=null;this.needsCopy=!1}function C(a,b){var c=null;Ta(b)?c=b:b&&(q(a,b),\"x\"in b&&(a.xOffset=b.x|0),\"y\"in b&&(a.yOffset=b.y|0),Ta(b.data)&&(c=b.data));if(b.copy){var e=g.viewportWidth,d=g.viewportHeight;\na.width=a.width||e-a.xOffset;a.height=a.height||d-a.yOffset;a.needsCopy=!0}else if(!c)a.width=a.width||1,a.height=a.height||1,a.channels=a.channels||4;else if(M(c))a.channels=a.channels||4,a.data=c,\"type\"in b||5121!==a.type||(a.type=Ia[Object.prototype.toString.call(c)]|0);else if(mb(c)){a.channels=a.channels||4;e=c;d=e.length;switch(a.type){case 5121:case 5123:case 5125:case 5126:d=x.allocType(a.type,d);d.set(e);a.data=d;break;case 36193:a.data=kb(e)}a.alignment=1;a.needsFree=!0}else if(ma(c)){e=\nc.data;Array.isArray(e)||5121!==a.type||(a.type=Ia[Object.prototype.toString.call(e)]|0);var d=c.shape,h=c.stride,f,l,p,w;3===d.length?(p=d[2],w=h[2]):w=p=1;f=d[0];l=d[1];d=h[0];h=h[1];a.alignment=1;a.width=f;a.height=l;a.channels=p;a.format=a.internalformat=La[p];a.needsFree=!0;f=w;c=c.offset;p=a.width;w=a.height;l=a.channels;for(var z=x.allocType(36193===a.type?5126:a.type,p*w*l),I=0,fa=0;fa<w;++fa)for(var ga=0;ga<p;++ga)for(var xa=0;xa<l;++xa)z[I++]=e[d*ga+h*fa+f*xa+c];ob(a,z)}else if(na(c)===\nUa||na(c)===pb)na(c)===Ua?a.element=c:a.element=c.canvas,a.width=a.element.width,a.height=a.element.height,a.channels=4;else if(na(c)===qb)a.element=c,a.width=c.width,a.height=c.height,a.channels=4;else if(na(c)===rb)a.element=c,a.width=c.naturalWidth,a.height=c.naturalHeight,a.channels=4;else if(na(c)===sb)a.element=c,a.width=c.videoWidth,a.height=c.videoHeight,a.channels=4;else if(nb(c)){e=a.width||c[0].length;d=a.height||c.length;h=a.channels;h=pa(c[0][0])?h||c[0][0].length:h||1;f=Ma.shape(c);\np=1;for(w=0;w<f.length;++w)p*=f[w];p=x.allocType(36193===a.type?5126:a.type,p);Ma.flatten(c,f,\"\",p);ob(a,p);a.alignment=1;a.width=e;a.height=d;a.channels=h;a.format=a.internalformat=La[h];a.needsFree=!0}}function k(b,c,d,h,f){var g=b.element,l=b.data,k=b.internalformat,p=b.format,w=b.type,z=b.width,I=b.height;t(b);g?a.texSubImage2D(c,f,d,h,p,w,g):b.compressed?a.compressedTexSubImage2D(c,f,d,h,k,z,I,l):b.needsCopy?(e(),a.copyTexSubImage2D(c,f,d,h,b.xOffset,b.yOffset,z,I)):a.texSubImage2D(c,f,d,h,z,\nI,p,w,l)}function h(){return P.pop()||new m}function l(a){a.needsFree&&x.freeType(a.data);m.call(a);P.push(a)}function u(){f.call(this);this.genMipmaps=!1;this.mipmapHint=4352;this.mipmask=0;this.images=Array(16)}function v(a,b,c){var d=a.images[0]=h();a.mipmask=1;d.width=a.width=b;d.height=a.height=c;d.channels=a.channels=4}function N(a,b){var c=null;if(Ta(b))c=a.images[0]=h(),r(c,a),C(c,b),a.mipmask=1;else if(q(a,b),Array.isArray(b.mipmap))for(var d=b.mipmap,e=0;e<d.length;++e)c=a.images[e]=h(),\nr(c,a),c.width>>=e,c.height>>=e,C(c,d[e]),a.mipmask|=1<<e;else c=a.images[0]=h(),r(c,a),C(c,b),a.mipmask=1;r(a,a.images[0])}function B(b,c){for(var d=b.images,h=0;h<d.length&&d[h];++h){var f=d[h],g=c,l=h,k=f.element,p=f.data,w=f.internalformat,z=f.format,I=f.type,fa=f.width,ga=f.height,xa=f.channels;t(f);k?a.texImage2D(g,l,z,z,I,k):f.compressed?a.compressedTexImage2D(g,l,w,fa,ga,0,p):f.needsCopy?(e(),a.copyTexImage2D(g,l,z,f.xOffset,f.yOffset,fa,ga,0)):((f=!p)&&(p=x.zero.allocType(I,fa*ga*xa)),a.texImage2D(g,\nl,z,fa,ga,0,z,I,p),f&&p&&x.zero.freeType(p))}}function D(){var a=tb.pop()||new u;f.call(a);for(var b=a.mipmask=0;16>b;++b)a.images[b]=null;return a}function ib(a){for(var b=a.images,c=0;c<b.length;++c)b[c]&&l(b[c]),b[c]=null;tb.push(a)}function y(){this.magFilter=this.minFilter=9728;this.wrapT=this.wrapS=33071;this.anisotropic=1;this.genMipmaps=!1;this.mipmapHint=4352}function O(a,b){\"min\"in b&&(a.minFilter=Va[b.min],0<=Mb.indexOf(a.minFilter)&&!(\"faces\"in b)&&(a.genMipmaps=!0));\"mag\"in b&&(a.magFilter=\nV[b.mag]);var c=a.wrapS,d=a.wrapT;if(\"wrap\"in b){var e=b.wrap;\"string\"===typeof e?c=d=K[e]:Array.isArray(e)&&(c=K[e[0]],d=K[e[1]])}else\"wrapS\"in b&&(c=K[b.wrapS]),\"wrapT\"in b&&(d=K[b.wrapT]);a.wrapS=c;a.wrapT=d;\"anisotropic\"in b&&(a.anisotropic=b.anisotropic);if(\"mipmap\"in b){c=!1;switch(typeof b.mipmap){case \"string\":a.mipmapHint=ua[b.mipmap];c=a.genMipmaps=!0;break;case \"boolean\":c=a.genMipmaps=b.mipmap;break;case \"object\":a.genMipmaps=!1,c=!0}!c||\"min\"in b||(a.minFilter=9984)}}function R(c,d){a.texParameteri(d,\n10241,c.minFilter);a.texParameteri(d,10240,c.magFilter);a.texParameteri(d,10242,c.wrapS);a.texParameteri(d,10243,c.wrapT);b.ext_texture_filter_anisotropic&&a.texParameteri(d,34046,c.anisotropic);c.genMipmaps&&(a.hint(33170,c.mipmapHint),a.generateMipmap(d))}function F(b){f.call(this);this.mipmask=0;this.internalformat=6408;this.id=ya++;this.refCount=1;this.target=b;this.texture=a.createTexture();this.unit=-1;this.bindCount=0;this.texInfo=new y;n.profile&&(this.stats={size:0})}function T(b){a.activeTexture(33984);\na.bindTexture(b.target,b.texture)}function Aa(){var b=ha[0];b?a.bindTexture(b.target,b.texture):a.bindTexture(3553,null)}function A(b){var c=b.texture,e=b.unit,h=b.target;0<=e&&(a.activeTexture(33984+e),a.bindTexture(h,null),ha[e]=null);a.deleteTexture(c);b.texture=null;b.params=null;b.pixels=null;b.refCount=0;delete X[b.id];d.textureCount--}var ua={\"don't care\":4352,\"dont care\":4352,nice:4354,fast:4353},K={repeat:10497,clamp:33071,mirror:33648},V={nearest:9728,linear:9729},Va=E({mipmap:9987,\"nearest mipmap nearest\":9984,\n\"linear mipmap nearest\":9985,\"nearest mipmap linear\":9986,\"linear mipmap linear\":9987},V),wa={none:0,browser:37444},G={uint8:5121,rgba4:32819,rgb565:33635,\"rgb5 a1\":32820},U={alpha:6406,luminance:6409,\"luminance alpha\":6410,rgb:6407,rgba:6408,rgba4:32854,\"rgb5 a1\":32855,rgb565:36194},W={};b.ext_srgb&&(U.srgb=35904,U.srgba=35906);b.oes_texture_float&&(G.float32=G[\"float\"]=5126);b.oes_texture_half_float&&(G.float16=G[\"half float\"]=36193);b.webgl_depth_texture&&(E(U,{depth:6402,\"depth stencil\":34041}),\nE(G,{uint16:5123,uint32:5125,\"depth stencil\":34042}));b.webgl_compressed_texture_s3tc&&E(W,{\"rgb s3tc dxt1\":33776,\"rgba s3tc dxt1\":33777,\"rgba s3tc dxt3\":33778,\"rgba s3tc dxt5\":33779});b.webgl_compressed_texture_atc&&E(W,{\"rgb atc\":35986,\"rgba atc explicit alpha\":35987,\"rgba atc interpolated alpha\":34798});b.webgl_compressed_texture_pvrtc&&E(W,{\"rgb pvrtc 4bppv1\":35840,\"rgb pvrtc 2bppv1\":35841,\"rgba pvrtc 4bppv1\":35842,\"rgba pvrtc 2bppv1\":35843});b.webgl_compressed_texture_etc1&&(W[\"rgb etc1\"]=36196);\nvar Nb=Array.prototype.slice.call(a.getParameter(34467));Object.keys(W).forEach(function(a){var b=W[a];0<=Nb.indexOf(b)&&(U[a]=b)});var ca=Object.keys(U);c.textureFormats=ca;var J=[];Object.keys(U).forEach(function(a){J[U[a]]=a});var da=[];Object.keys(G).forEach(function(a){da[G[a]]=a});var oa=[];Object.keys(V).forEach(function(a){oa[V[a]]=a});var za=[];Object.keys(Va).forEach(function(a){za[Va[a]]=a});var ka=[];Object.keys(K).forEach(function(a){ka[K[a]]=a});var Lb=ca.reduce(function(a,b){var c=\nU[b];6409===c||6406===c||6409===c||6410===c||6402===c||34041===c?a[c]=c:32855===c||0<=b.indexOf(\"rgba\")?a[c]=6408:a[c]=6407;return a},{}),P=[],tb=[],ya=0,X={},ea=c.maxTextureUnits,ha=Array(ea).map(function(){return null});E(F.prototype,{bind:function(){this.bindCount+=1;var b=this.unit;if(0>b){for(var c=0;c<ea;++c){var e=ha[c];if(e){if(0<e.bindCount)continue;e.unit=-1}ha[c]=this;b=c;break}n.profile&&d.maxTextureUnits<b+1&&(d.maxTextureUnits=b+1);this.unit=b;a.activeTexture(33984+b);a.bindTexture(this.target,\nthis.texture)}return b},unbind:function(){--this.bindCount},decRef:function(){0>=--this.refCount&&A(this)}});n.profile&&(d.getTotalTextureSize=function(){var a=0;Object.keys(X).forEach(function(b){a+=X[b].stats.size});return a});return{create2D:function(b,c){function e(a,b){var c=f.texInfo;y.call(c);var d=D();\"number\"===typeof a?\"number\"===typeof b?v(d,a|0,b|0):v(d,a|0,a|0):a?(O(c,a),N(d,a)):v(d,1,1);c.genMipmaps&&(d.mipmask=(d.width<<1)-1);f.mipmask=d.mipmask;r(f,d);f.internalformat=d.internalformat;\ne.width=d.width;e.height=d.height;T(f);B(d,3553);R(c,3553);Aa();ib(d);n.profile&&(f.stats.size=Ja(f.internalformat,f.type,d.width,d.height,c.genMipmaps,!1));e.format=J[f.internalformat];e.type=da[f.type];e.mag=oa[c.magFilter];e.min=za[c.minFilter];e.wrapS=ka[c.wrapS];e.wrapT=ka[c.wrapT];return e}var f=new F(3553);X[f.id]=f;d.textureCount++;e(b,c);e.subimage=function(a,b,c,d){b|=0;c|=0;d|=0;var p=h();r(p,f);p.width=0;p.height=0;C(p,a);p.width=p.width||(f.width>>d)-b;p.height=p.height||(f.height>>d)-\nc;T(f);k(p,3553,b,c,d);Aa();l(p);return e};e.resize=function(b,c){var d=b|0,h=c|0||d;if(d===f.width&&h===f.height)return e;e.width=f.width=d;e.height=f.height=h;T(f);for(var p,w=f.channels,z=f.type,I=0;f.mipmask>>I;++I){var fa=d>>I,ga=h>>I;if(!fa||!ga)break;p=x.zero.allocType(z,fa*ga*w);a.texImage2D(3553,I,f.format,fa,ga,0,f.format,f.type,p);p&&x.zero.freeType(p)}Aa();n.profile&&(f.stats.size=Ja(f.internalformat,f.type,d,h,!1,!1));return e};e._reglType=\"texture2d\";e._texture=f;n.profile&&(e.stats=\nf.stats);e.destroy=function(){f.decRef()};return e},createCube:function(b,c,e,f,g,ua){function A(a,b,c,d,e,f){var H,Y=m.texInfo;y.call(Y);for(H=0;6>H;++H)p[H]=D();if(\"number\"===typeof a||!a)for(a=a|0||1,H=0;6>H;++H)v(p[H],a,a);else if(\"object\"===typeof a)if(b)N(p[0],a),N(p[1],b),N(p[2],c),N(p[3],d),N(p[4],e),N(p[5],f);else if(O(Y,a),q(m,a),\"faces\"in a)for(a=a.faces,H=0;6>H;++H)r(p[H],m),N(p[H],a[H]);else for(H=0;6>H;++H)N(p[H],a);r(m,p[0]);m.mipmask=Y.genMipmaps?(p[0].width<<1)-1:p[0].mipmask;m.internalformat=\np[0].internalformat;A.width=p[0].width;A.height=p[0].height;T(m);for(H=0;6>H;++H)B(p[H],34069+H);R(Y,34067);Aa();n.profile&&(m.stats.size=Ja(m.internalformat,m.type,A.width,A.height,Y.genMipmaps,!0));A.format=J[m.internalformat];A.type=da[m.type];A.mag=oa[Y.magFilter];A.min=za[Y.minFilter];A.wrapS=ka[Y.wrapS];A.wrapT=ka[Y.wrapT];for(H=0;6>H;++H)ib(p[H]);return A}var m=new F(34067);X[m.id]=m;d.cubeCount++;var p=Array(6);A(b,c,e,f,g,ua);A.subimage=function(a,b,c,p,d){c|=0;p|=0;d|=0;var e=h();r(e,m);\ne.width=0;e.height=0;C(e,b);e.width=e.width||(m.width>>d)-c;e.height=e.height||(m.height>>d)-p;T(m);k(e,34069+a,c,p,d);Aa();l(e);return A};A.resize=function(b){b|=0;if(b!==m.width){A.width=m.width=b;A.height=m.height=b;T(m);for(var c=0;6>c;++c)for(var p=0;m.mipmask>>p;++p)a.texImage2D(34069+c,p,m.format,b>>p,b>>p,0,m.format,m.type,null);Aa();n.profile&&(m.stats.size=Ja(m.internalformat,m.type,A.width,A.height,!1,!0));return A}};A._reglType=\"textureCube\";A._texture=m;n.profile&&(A.stats=m.stats);A.destroy=\nfunction(){m.decRef()};return A},clear:function(){for(var b=0;b<ea;++b)a.activeTexture(33984+b),a.bindTexture(3553,null),ha[b]=null;S(X).forEach(A);d.cubeCount=0;d.textureCount=0},getTexture:function(a){return null},restore:function(){for(var b=0;b<ea;++b){var c=ha[b];c&&(c.bindCount=0,c.unit=-1,ha[b]=null)}S(X).forEach(function(b){b.texture=a.createTexture();a.bindTexture(b.target,b.texture);for(var c=0;32>c;++c)if(0!==(b.mipmask&1<<c))if(3553===b.target)a.texImage2D(3553,c,b.internalformat,b.width>>\nc,b.height>>c,0,b.internalformat,b.type,null);else for(var d=0;6>d;++d)a.texImage2D(34069+d,c,b.internalformat,b.width>>c,b.height>>c,0,b.internalformat,b.type,null);R(b.texInfo,b.target)})}}}function Ob(a,b,c,e,g,d){function n(a,b,c){this.target=a;this.texture=b;this.renderbuffer=c;var d=a=0;b?(a=b.width,d=b.height):c&&(a=c.width,d=c.height);this.width=a;this.height=d}function f(a){a&&(a.texture&&a.texture._texture.decRef(),a.renderbuffer&&a.renderbuffer._renderbuffer.decRef())}function r(a,b,c){a&&\n(a.texture?a.texture._texture.refCount+=1:a.renderbuffer._renderbuffer.refCount+=1)}function q(b,c){c&&(c.texture?a.framebufferTexture2D(36160,b,c.target,c.texture._texture.texture,0):a.framebufferRenderbuffer(36160,b,36161,c.renderbuffer._renderbuffer.renderbuffer))}function t(a){var b=3553,c=null,d=null,e=a;\"object\"===typeof a&&(e=a.data,\"target\"in a&&(b=a.target|0));a=e._reglType;\"texture2d\"===a?c=e:\"textureCube\"===a?c=e:\"renderbuffer\"===a&&(d=e,b=36161);return new n(b,c,d)}function m(a,b,c,d,\nf){if(c)return a=e.create2D({width:a,height:b,format:d,type:f}),a._texture.refCount=0,new n(3553,a,null);a=g.create({width:a,height:b,format:d});a._renderbuffer.refCount=0;return new n(36161,null,a)}function C(a){return a&&(a.texture||a.renderbuffer)}function k(a,b,c){a&&(a.texture?a.texture.resize(b,c):a.renderbuffer&&a.renderbuffer.resize(b,c),a.width=b,a.height=c)}function h(){this.id=O++;R[this.id]=this;this.framebuffer=a.createFramebuffer();this.height=this.width=0;this.colorAttachments=[];this.depthStencilAttachment=\nthis.stencilAttachment=this.depthAttachment=null}function l(a){a.colorAttachments.forEach(f);f(a.depthAttachment);f(a.stencilAttachment);f(a.depthStencilAttachment)}function u(b){a.deleteFramebuffer(b.framebuffer);b.framebuffer=null;d.framebufferCount--;delete R[b.id]}function v(b){var d;a.bindFramebuffer(36160,b.framebuffer);var e=b.colorAttachments;for(d=0;d<e.length;++d)q(36064+d,e[d]);for(d=e.length;d<c.maxColorAttachments;++d)a.framebufferTexture2D(36160,36064+d,3553,null,0);a.framebufferTexture2D(36160,\n33306,3553,null,0);a.framebufferTexture2D(36160,36096,3553,null,0);a.framebufferTexture2D(36160,36128,3553,null,0);q(36096,b.depthAttachment);q(36128,b.stencilAttachment);q(33306,b.depthStencilAttachment);a.checkFramebufferStatus(36160);a.isContextLost();a.bindFramebuffer(36160,B.next?B.next.framebuffer:null);B.cur=B.next;a.getError()}function N(a,b){function c(a,b){var d,f=0,h=0,g=!0,k=!0;d=null;var q=!0,u=\"rgba\",n=\"uint8\",N=1,da=null,oa=null,B=null,ka=!1;if(\"number\"===typeof a)f=a|0,h=b|0||f;else if(a){\"shape\"in\na?(h=a.shape,f=h[0],h=h[1]):(\"radius\"in a&&(f=h=a.radius),\"width\"in a&&(f=a.width),\"height\"in a&&(h=a.height));if(\"color\"in a||\"colors\"in a)d=a.color||a.colors,Array.isArray(d);if(!d){\"colorCount\"in a&&(N=a.colorCount|0);\"colorTexture\"in a&&(q=!!a.colorTexture,u=\"rgba4\");if(\"colorType\"in a&&(n=a.colorType,!q))if(\"half float\"===n||\"float16\"===n)u=\"rgba16f\";else if(\"float\"===n||\"float32\"===n)u=\"rgba32f\";\"colorFormat\"in a&&(u=a.colorFormat,0<=x.indexOf(u)?q=!0:0<=D.indexOf(u)&&(q=!1))}if(\"depthTexture\"in\na||\"depthStencilTexture\"in a)ka=!(!a.depthTexture&&!a.depthStencilTexture);\"depth\"in a&&(\"boolean\"===typeof a.depth?g=a.depth:(da=a.depth,k=!1));\"stencil\"in a&&(\"boolean\"===typeof a.stencil?k=a.stencil:(oa=a.stencil,g=!1));\"depthStencil\"in a&&(\"boolean\"===typeof a.depthStencil?g=k=a.depthStencil:(B=a.depthStencil,k=g=!1))}else f=h=1;var F=null,y=null,E=null,T=null;if(Array.isArray(d))F=d.map(t);else if(d)F=[t(d)];else for(F=Array(N),d=0;d<N;++d)F[d]=m(f,h,q,u,n);f=f||F[0].width;h=h||F[0].height;da?\ny=t(da):g&&!k&&(y=m(f,h,ka,\"depth\",\"uint32\"));oa?E=t(oa):k&&!g&&(E=m(f,h,!1,\"stencil\",\"uint8\"));B?T=t(B):!da&&!oa&&k&&g&&(T=m(f,h,ka,\"depth stencil\",\"depth stencil\"));g=null;for(d=0;d<F.length;++d)r(F[d],f,h),F[d]&&F[d].texture&&(k=Wa[F[d].texture._texture.format]*Na[F[d].texture._texture.type],null===g&&(g=k));r(y,f,h);r(E,f,h);r(T,f,h);l(e);e.width=f;e.height=h;e.colorAttachments=F;e.depthAttachment=y;e.stencilAttachment=E;e.depthStencilAttachment=T;c.color=F.map(C);c.depth=C(y);c.stencil=C(E);\nc.depthStencil=C(T);c.width=e.width;c.height=e.height;v(e);return c}var e=new h;d.framebufferCount++;c(a,b);return E(c,{resize:function(a,b){var d=Math.max(a|0,1),f=Math.max(b|0||d,1);if(d===e.width&&f===e.height)return c;for(var h=e.colorAttachments,g=0;g<h.length;++g)k(h[g],d,f);k(e.depthAttachment,d,f);k(e.stencilAttachment,d,f);k(e.depthStencilAttachment,d,f);e.width=c.width=d;e.height=c.height=f;v(e);return c},_reglType:\"framebuffer\",_framebuffer:e,destroy:function(){u(e);l(e)},use:function(a){B.setFBO({framebuffer:c},\na)}})}var B={cur:null,next:null,dirty:!1,setFBO:null},x=[\"rgba\"],D=[\"rgba4\",\"rgb565\",\"rgb5 a1\"];b.ext_srgb&&D.push(\"srgba\");b.ext_color_buffer_half_float&&D.push(\"rgba16f\",\"rgb16f\");b.webgl_color_buffer_float&&D.push(\"rgba32f\");var y=[\"uint8\"];b.oes_texture_half_float&&y.push(\"half float\",\"float16\");b.oes_texture_float&&y.push(\"float\",\"float32\");var O=0,R={};return E(B,{getFramebuffer:function(a){return\"function\"===typeof a&&\"framebuffer\"===a._reglType&&(a=a._framebuffer,a instanceof h)?a:null},create:N,\ncreateCube:function(a){function b(a){var d,f={color:null},h=0,g=null;d=\"rgba\";var l=\"uint8\",m=1;if(\"number\"===typeof a)h=a|0;else if(a){\"shape\"in a?h=a.shape[0]:(\"radius\"in a&&(h=a.radius|0),\"width\"in a?h=a.width|0:\"height\"in a&&(h=a.height|0));if(\"color\"in a||\"colors\"in a)g=a.color||a.colors,Array.isArray(g);g||(\"colorCount\"in a&&(m=a.colorCount|0),\"colorType\"in a&&(l=a.colorType),\"colorFormat\"in a&&(d=a.colorFormat));\"depth\"in a&&(f.depth=a.depth);\"stencil\"in a&&(f.stencil=a.stencil);\"depthStencil\"in\na&&(f.depthStencil=a.depthStencil)}else h=1;if(g)if(Array.isArray(g))for(a=[],d=0;d<g.length;++d)a[d]=g[d];else a=[g];else for(a=Array(m),g={radius:h,format:d,type:l},d=0;d<m;++d)a[d]=e.createCube(g);f.color=Array(a.length);for(d=0;d<a.length;++d)m=a[d],h=h||m.width,f.color[d]={target:34069,data:a[d]};for(d=0;6>d;++d){for(m=0;m<a.length;++m)f.color[m].target=34069+d;0<d&&(f.depth=c[0].depth,f.stencil=c[0].stencil,f.depthStencil=c[0].depthStencil);if(c[d])c[d](f);else c[d]=N(f)}return E(b,{width:h,\nheight:h,color:a})}var c=Array(6);b(a);return E(b,{faces:c,resize:function(a){var d=a|0;if(d===b.width)return b;var e=b.color;for(a=0;a<e.length;++a)e[a].resize(d);for(a=0;6>a;++a)c[a].resize(d);b.width=b.height=d;return b},_reglType:\"framebufferCube\",destroy:function(){c.forEach(function(a){a.destroy()})}})},clear:function(){S(R).forEach(u)},restore:function(){B.cur=null;B.next=null;B.dirty=!0;S(R).forEach(function(b){b.framebuffer=a.createFramebuffer();v(b)})}})}function ub(){this.w=this.z=this.y=\nthis.x=this.state=0;this.buffer=null;this.size=0;this.normalized=!1;this.type=5126;this.divisor=this.stride=this.offset=0}function Pb(a,b,c,e){a=c.maxAttributes;b=Array(a);for(c=0;c<a;++c)b[c]=new ub;return{Record:ub,scope:{},state:b}}function Qb(a,b,c,e){function g(a,b,c,d){this.name=a;this.id=b;this.location=c;this.info=d}function d(a,b){for(var c=0;c<a.length;++c)if(a[c].id===b.id){a[c].location=b.location;return}a.push(b)}function n(c,d,e){e=35632===c?q:t;var f=e[d];if(!f){var g=b.str(d),f=a.createShader(c);\na.shaderSource(f,g);a.compileShader(f);e[d]=f}return f}function f(a,b){this.id=k++;this.fragId=a;this.vertId=b;this.program=null;this.uniforms=[];this.attributes=[];e.profile&&(this.stats={uniformsCount:0,attributesCount:0})}function r(c,f){var m,k;m=n(35632,c.fragId);k=n(35633,c.vertId);var q=c.program=a.createProgram();a.attachShader(q,m);a.attachShader(q,k);a.linkProgram(q);var r=a.getProgramParameter(q,35718);e.profile&&(c.stats.uniformsCount=r);var t=c.uniforms;for(m=0;m<r;++m)if(k=a.getActiveUniform(q,\nm))if(1<k.size)for(var C=0;C<k.size;++C){var y=k.name.replace(\"[0]\",\"[\"+C+\"]\");d(t,new g(y,b.id(y),a.getUniformLocation(q,y),k))}else d(t,new g(k.name,b.id(k.name),a.getUniformLocation(q,k.name),k));r=a.getProgramParameter(q,35721);e.profile&&(c.stats.attributesCount=r);t=c.attributes;for(m=0;m<r;++m)(k=a.getActiveAttrib(q,m))&&d(t,new g(k.name,b.id(k.name),a.getAttribLocation(q,k.name),k))}var q={},t={},m={},C=[],k=0;e.profile&&(c.getMaxUniformsCount=function(){var a=0;C.forEach(function(b){b.stats.uniformsCount>\na&&(a=b.stats.uniformsCount)});return a},c.getMaxAttributesCount=function(){var a=0;C.forEach(function(b){b.stats.attributesCount>a&&(a=b.stats.attributesCount)});return a});return{clear:function(){var b=a.deleteShader.bind(a);S(q).forEach(b);q={};S(t).forEach(b);t={};C.forEach(function(b){a.deleteProgram(b.program)});C.length=0;m={};c.shaderCount=0},program:function(a,b,d){var e=m[b];e||(e=m[b]={});var g=e[a];g||(g=new f(b,a),c.shaderCount++,r(g,d),e[a]=g,C.push(g));return g},restore:function(){q=\n{};t={};for(var a=0;a<C.length;++a)r(C[a])},shader:n,frag:-1,vert:-1}}function Rb(a,b,c,e,g,d,n){function f(d){var f;f=null===b.next?5121:b.next.colorAttachments[0].texture._texture.type;var g=0,r=0,k=e.framebufferWidth,h=e.framebufferHeight,l=null;M(d)?l=d:d&&(g=d.x|0,r=d.y|0,k=(d.width||e.framebufferWidth-g)|0,h=(d.height||e.framebufferHeight-r)|0,l=d.data||null);c();d=k*h*4;l||(5121===f?l=new Uint8Array(d):5126===f&&(l=l||new Float32Array(d)));a.pixelStorei(3333,4);a.readPixels(g,r,k,h,6408,f,\nl);return l}function r(a){var c;b.setFBO({framebuffer:a.framebuffer},function(){c=f(a)});return c}return function(a){return a&&\"framebuffer\"in a?r(a):f(a)}}function Ba(a){return Array.prototype.slice.call(a)}function Ca(a){return Ba(a).join(\"\")}function Sb(){function a(){var a=[],b=[];return E(function(){a.push.apply(a,Ba(arguments))},{def:function(){var d=\"v\"+c++;b.push(d);0<arguments.length&&(a.push(d,\"=\"),a.push.apply(a,Ba(arguments)),a.push(\";\"));return d},toString:function(){return Ca([0<b.length?\n\"var \"+b+\";\":\"\",Ca(a)])}})}function b(){function b(a,e){d(a,e,\"=\",c.def(a,e),\";\")}var c=a(),d=a(),e=c.toString,g=d.toString;return E(function(){c.apply(c,Ba(arguments))},{def:c.def,entry:c,exit:d,save:b,set:function(a,d,e){b(a,d);c(a,d,\"=\",e,\";\")},toString:function(){return e()+g()}})}var c=0,e=[],g=[],d=a(),n={};return{global:d,link:function(a){for(var b=0;b<g.length;++b)if(g[b]===a)return e[b];b=\"g\"+c++;e.push(b);g.push(a);return b},block:a,proc:function(a,c){function d(){var a=\"a\"+e.length;e.push(a);\nreturn a}var e=[];c=c||0;for(var g=0;g<c;++g)d();var g=b(),C=g.toString;return n[a]=E(g,{arg:d,toString:function(){return Ca([\"function(\",e.join(),\"){\",C(),\"}\"])}})},scope:b,cond:function(){var a=Ca(arguments),c=b(),d=b(),e=c.toString,g=d.toString;return E(c,{then:function(){c.apply(c,Ba(arguments));return this},\"else\":function(){d.apply(d,Ba(arguments));return this},toString:function(){var b=g();b&&(b=\"else{\"+b+\"}\");return Ca([\"if(\",a,\"){\",e(),\"}\",b])}})},compile:function(){var a=['\"use strict\";',\nd,\"return {\"];Object.keys(n).forEach(function(b){a.push('\"',b,'\":',n[b].toString(),\",\")});a.push(\"}\");var b=Ca(a).replace(/;/g,\";\\n\").replace(/}/g,\"}\\n\").replace(/{/g,\"{\\n\");return Function.apply(null,e.concat(b)).apply(null,g)}}}function Oa(a){return Array.isArray(a)||M(a)||ma(a)}function vb(a){return a.sort(function(a,c){return\"viewport\"===a?-1:\"viewport\"===c?1:a<c?-1:1})}function Z(a,b,c,e){this.thisDep=a;this.contextDep=b;this.propDep=c;this.append=e}function va(a){return a&&!(a.thisDep||a.contextDep||\na.propDep)}function D(a){return new Z(!1,!1,!1,a)}function P(a,b){var c=a.type;return 0===c?(c=a.data.length,new Z(!0,1<=c,2<=c,b)):4===c?(c=a.data,new Z(c.thisDep,c.contextDep,c.propDep,b)):new Z(3===c,2===c,1===c,b)}function Tb(a,b,c,e,g,d,n,f,r,q,t,m,C,k,h){function l(a){return a.replace(\".\",\"_\")}function u(a,b,c){var d=l(a);Ka.push(a);Fa[d]=ra[d]=!!c;sa[d]=b}function v(a,b,c){var d=l(a);Ka.push(a);Array.isArray(c)?(ra[d]=c.slice(),Fa[d]=c.slice()):ra[d]=Fa[d]=c;ta[d]=b}function N(){var a=Sb(),\nc=a.link,d=a.global;a.id=qa++;a.batchId=\"0\";var e=c(na),f=a.shared={props:\"a0\"};Object.keys(na).forEach(function(a){f[a]=d.def(e,\".\",a)});var g=a.next={},xa=a.current={};Object.keys(ta).forEach(function(a){Array.isArray(ra[a])&&(g[a]=d.def(f.next,\".\",a),xa[a]=d.def(f.current,\".\",a))});var H=a.constants={};Object.keys(aa).forEach(function(a){H[a]=d.def(JSON.stringify(aa[a]))});a.invoke=function(b,d){switch(d.type){case 0:var e=[\"this\",f.context,f.props,a.batchId];return b.def(c(d.data),\".call(\",e.slice(0,\nMath.max(d.data.length+1,4)),\")\");case 1:return b.def(f.props,d.data);case 2:return b.def(f.context,d.data);case 3:return b.def(\"this\",d.data);case 4:return d.data.append(a,b),d.data.ref}};a.attribCache={};var Y={};a.scopeAttrib=function(a){a=b.id(a);if(a in Y)return Y[a];var d=q.scope[a];d||(d=q.scope[a]=new ya);return Y[a]=c(d)};return a}function B(a){var b=a[\"static\"];a=a.dynamic;var c;if(\"profile\"in b){var d=!!b.profile;c=D(function(a,b){return d});c.enable=d}else if(\"profile\"in a){var e=a.profile;\nc=P(e,function(a,b){return a.invoke(b,e)})}return c}function y(a,b){var c=a[\"static\"],d=a.dynamic;if(\"framebuffer\"in c){var e=c.framebuffer;return e?(e=f.getFramebuffer(e),D(function(a,b){var c=a.link(e),d=a.shared;b.set(d.framebuffer,\".next\",c);d=d.context;b.set(d,\".framebufferWidth\",c+\".width\");b.set(d,\".framebufferHeight\",c+\".height\");return c})):D(function(a,b){var c=a.shared;b.set(c.framebuffer,\".next\",\"null\");c=c.context;b.set(c,\".framebufferWidth\",c+\".drawingBufferWidth\");b.set(c,\".framebufferHeight\",\nc+\".drawingBufferHeight\");return\"null\"})}if(\"framebuffer\"in d){var g=d.framebuffer;return P(g,function(a,b){var c=a.invoke(b,g),d=a.shared,e=d.framebuffer,c=b.def(e,\".getFramebuffer(\",c,\")\");b.set(e,\".next\",c);d=d.context;b.set(d,\".framebufferWidth\",c+\"?\"+c+\".width:\"+d+\".drawingBufferWidth\");b.set(d,\".framebufferHeight\",c+\"?\"+c+\".height:\"+d+\".drawingBufferHeight\");return c})}return null}function x(a,b,c){function d(a){if(a in e){var c=e[a];a=!0;var p=c.x|0,ba=c.y|0,g,h;\"width\"in c?g=c.width|0:a=!1;\n\"height\"in c?h=c.height|0:a=!1;return new Z(!a&&b&&b.thisDep,!a&&b&&b.contextDep,!a&&b&&b.propDep,function(a,b){var d=a.shared.context,e=g;\"width\"in c||(e=b.def(d,\".\",\"framebufferWidth\",\"-\",p));var f=h;\"height\"in c||(f=b.def(d,\".\",\"framebufferHeight\",\"-\",ba));return[p,ba,e,f]})}if(a in f){var z=f[a];a=P(z,function(a,b){var c=a.invoke(b,z),d=a.shared.context,e=b.def(c,\".x|0\"),p=b.def(c,\".y|0\"),Y=b.def('\"width\" in ',c,\"?\",c,\".width|0:\",\"(\",d,\".\",\"framebufferWidth\",\"-\",e,\")\"),c=b.def('\"height\" in ',\nc,\"?\",c,\".height|0:\",\"(\",d,\".\",\"framebufferHeight\",\"-\",p,\")\");return[e,p,Y,c]});b&&(a.thisDep=a.thisDep||b.thisDep,a.contextDep=a.contextDep||b.contextDep,a.propDep=a.propDep||b.propDep);return a}return b?new Z(b.thisDep,b.contextDep,b.propDep,function(a,b){var c=a.shared.context;return[0,0,b.def(c,\".\",\"framebufferWidth\"),b.def(c,\".\",\"framebufferHeight\")]}):null}var e=a[\"static\"],f=a.dynamic;if(a=d(\"viewport\")){var g=a;a=new Z(a.thisDep,a.contextDep,a.propDep,function(a,b){var c=g.append(a,b),d=a.shared.context;\nb.set(d,\".viewportWidth\",c[2]);b.set(d,\".viewportHeight\",c[3]);return c})}return{viewport:a,scissor_box:d(\"scissor.box\")}}function E(a){function c(a){if(a in d){var p=b.id(d[a]);a=D(function(){return p});a.id=p;return a}if(a in e){var f=e[a];return P(f,function(a,b){var c=a.invoke(b,f);return b.def(a.shared.strings,\".id(\",c,\")\")})}return null}var d=a[\"static\"],e=a.dynamic,f=c(\"frag\"),g=c(\"vert\"),h=null;va(f)&&va(g)?(h=t.program(g.id,f.id),a=D(function(a,b){return a.link(h)})):a=new Z(f&&f.thisDep||\ng&&g.thisDep,f&&f.contextDep||g&&g.contextDep,f&&f.propDep||g&&g.propDep,function(a,b){var c=a.shared.shader,d;d=f?f.append(a,b):b.def(c,\".\",\"frag\");var e;e=g?g.append(a,b):b.def(c,\".\",\"vert\");return b.def(c+\".program(\"+e+\",\"+d+\")\")});return{frag:f,vert:g,progVar:a,program:h}}function O(a,b){function c(a,b){if(a in e){var d=e[a]|0;return D(function(a,c){b&&(a.OFFSET=d);return d})}if(a in f){var p=f[a];return P(p,function(a,c){var d=a.invoke(c,p);b&&(a.OFFSET=d);return d})}return b&&g?D(function(a,\nb){a.OFFSET=\"0\";return 0}):null}var e=a[\"static\"],f=a.dynamic,g=function(){if(\"elements\"in e){var a=e.elements;Oa(a)?a=d.getElements(d.create(a,!0)):a&&(a=d.getElements(a));var b=D(function(b,c){if(a){var d=b.link(a);return b.ELEMENTS=d}return b.ELEMENTS=null});b.value=a;return b}if(\"elements\"in f){var c=f.elements;return P(c,function(a,b){var d=a.shared,e=d.isBufferArgs,d=d.elements,p=a.invoke(b,c),f=b.def(\"null\"),e=b.def(e,\"(\",p,\")\"),p=a.cond(e).then(f,\"=\",d,\".createStream(\",p,\");\")[\"else\"](f,\"=\",\nd,\".getElements(\",p,\");\");b.entry(p);b.exit(a.cond(e).then(d,\".destroyStream(\",f,\");\"));return a.ELEMENTS=f})}return null}(),h=c(\"offset\",!0);return{elements:g,primitive:function(){if(\"primitive\"in e){var a=e.primitive;return D(function(b,c){return Sa[a]})}if(\"primitive\"in f){var b=f.primitive;return P(b,function(a,c){var d=a.constants.primTypes,e=a.invoke(c,b);return c.def(d,\"[\",e,\"]\")})}return g?va(g)?g.value?D(function(a,b){return b.def(a.ELEMENTS,\".primType\")}):D(function(){return 4}):new Z(g.thisDep,\ng.contextDep,g.propDep,function(a,b){var c=a.ELEMENTS;return b.def(c,\"?\",c,\".primType:\",4)}):null}(),count:function(){if(\"count\"in e){var a=e.count|0;return D(function(){return a})}if(\"count\"in f){var b=f.count;return P(b,function(a,c){return a.invoke(c,b)})}return g?va(g)?g?h?new Z(h.thisDep,h.contextDep,h.propDep,function(a,b){return b.def(a.ELEMENTS,\".vertCount-\",a.OFFSET)}):D(function(a,b){return b.def(a.ELEMENTS,\".vertCount\")}):D(function(){return-1}):new Z(g.thisDep||h.thisDep,g.contextDep||\nh.contextDep,g.propDep||h.propDep,function(a,b){var c=a.ELEMENTS;return a.OFFSET?b.def(c,\"?\",c,\".vertCount-\",a.OFFSET,\":-1\"):b.def(c,\"?\",c,\".vertCount:-1\")}):null}(),instances:c(\"instances\",!1),offset:h}}function R(a,b){var c=a[\"static\"],d=a.dynamic,e={};Ka.forEach(function(a){function b(f,g){if(a in c){var w=f(c[a]);e[p]=D(function(){return w})}else if(a in d){var h=d[a];e[p]=P(h,function(a,b){return g(a,b,a.invoke(b,h))})}}var p=l(a);switch(a){case \"cull.enable\":case \"blend.enable\":case \"dither\":case \"stencil.enable\":case \"depth.enable\":case \"scissor.enable\":case \"polygonOffset.enable\":case \"sample.alpha\":case \"sample.enable\":case \"depth.mask\":return b(function(a){return a},\nfunction(a,b,c){return c});case \"depth.func\":return b(function(a){return Xa[a]},function(a,b,c){return b.def(a.constants.compareFuncs,\"[\",c,\"]\")});case \"depth.range\":return b(function(a){return a},function(a,b,c){a=b.def(\"+\",c,\"[0]\");b=b.def(\"+\",c,\"[1]\");return[a,b]});case \"blend.func\":return b(function(a){return[Ga[\"srcRGB\"in a?a.srcRGB:a.src],Ga[\"dstRGB\"in a?a.dstRGB:a.dst],Ga[\"srcAlpha\"in a?a.srcAlpha:a.src],Ga[\"dstAlpha\"in a?a.dstAlpha:a.dst]]},function(a,b,c){function d(a,e){return b.def('\"',\na,e,'\" in ',c,\"?\",c,\".\",a,e,\":\",c,\".\",a)}a=a.constants.blendFuncs;var e=d(\"src\",\"RGB\"),p=d(\"dst\",\"RGB\"),e=b.def(a,\"[\",e,\"]\"),f=b.def(a,\"[\",d(\"src\",\"Alpha\"),\"]\"),p=b.def(a,\"[\",p,\"]\");a=b.def(a,\"[\",d(\"dst\",\"Alpha\"),\"]\");return[e,p,f,a]});case \"blend.equation\":return b(function(a){if(\"string\"===typeof a)return[X[a],X[a]];if(\"object\"===typeof a)return[X[a.rgb],X[a.alpha]]},function(a,b,c){var d=a.constants.blendEquations,e=b.def(),p=b.def();a=a.cond(\"typeof \",c,'===\"string\"');a.then(e,\"=\",p,\"=\",d,\"[\",\nc,\"];\");a[\"else\"](e,\"=\",d,\"[\",c,\".rgb];\",p,\"=\",d,\"[\",c,\".alpha];\");b(a);return[e,p]});case \"blend.color\":return b(function(a){return J(4,function(b){return+a[b]})},function(a,b,c){return J(4,function(a){return b.def(\"+\",c,\"[\",a,\"]\")})});case \"stencil.mask\":return b(function(a){return a|0},function(a,b,c){return b.def(c,\"|0\")});case \"stencil.func\":return b(function(a){return[Xa[a.cmp||\"keep\"],a.ref||0,\"mask\"in a?a.mask:-1]},function(a,b,c){a=b.def('\"cmp\" in ',c,\"?\",a.constants.compareFuncs,\"[\",c,\".cmp]\",\n\":\",7680);var d=b.def(c,\".ref|0\");b=b.def('\"mask\" in ',c,\"?\",c,\".mask|0:-1\");return[a,d,b]});case \"stencil.opFront\":case \"stencil.opBack\":return b(function(b){return[\"stencil.opBack\"===a?1029:1028,Pa[b.fail||\"keep\"],Pa[b.zfail||\"keep\"],Pa[b.zpass||\"keep\"]]},function(b,c,d){function e(a){return c.def('\"',a,'\" in ',d,\"?\",p,\"[\",d,\".\",a,\"]:\",7680)}var p=b.constants.stencilOps;return[\"stencil.opBack\"===a?1029:1028,e(\"fail\"),e(\"zfail\"),e(\"zpass\")]});case \"polygonOffset.offset\":return b(function(a){return[a.factor|\n0,a.units|0]},function(a,b,c){a=b.def(c,\".factor|0\");b=b.def(c,\".units|0\");return[a,b]});case \"cull.face\":return b(function(a){var b=0;\"front\"===a?b=1028:\"back\"===a&&(b=1029);return b},function(a,b,c){return b.def(c,'===\"front\"?',1028,\":\",1029)});case \"lineWidth\":return b(function(a){return a},function(a,b,c){return c});case \"frontFace\":return b(function(a){return wb[a]},function(a,b,c){return b.def(c+'===\"cw\"?2304:2305')});case \"colorMask\":return b(function(a){return a.map(function(a){return!!a})},\nfunction(a,b,c){return J(4,function(a){return\"!!\"+c+\"[\"+a+\"]\"})});case \"sample.coverage\":return b(function(a){return[\"value\"in a?a.value:1,!!a.invert]},function(a,b,c){a=b.def('\"value\" in ',c,\"?+\",c,\".value:1\");b=b.def(\"!!\",c,\".invert\");return[a,b]})}});return e}function F(a,b){var c=a[\"static\"],d=a.dynamic,e={};Object.keys(c).forEach(function(a){var b=c[a],d;if(\"number\"===typeof b||\"boolean\"===typeof b)d=D(function(){return b});else if(\"function\"===typeof b){var p=b._reglType;if(\"texture2d\"===p||\n\"textureCube\"===p)d=D(function(a){return a.link(b)});else if(\"framebuffer\"===p||\"framebufferCube\"===p)d=D(function(a){return a.link(b.color[0])})}else pa(b)&&(d=D(function(a){return a.global.def(\"[\",J(b.length,function(a){return b[a]}),\"]\")}));d.value=b;e[a]=d});Object.keys(d).forEach(function(a){var b=d[a];e[a]=P(b,function(a,c){return a.invoke(c,b)})});return e}function T(a,c){var d=a[\"static\"],e=a.dynamic,f={};Object.keys(d).forEach(function(a){var c=d[a],e=b.id(a),p=new ya;if(Oa(c))p.state=1,\np.buffer=g.getBuffer(g.create(c,34962,!1,!0)),p.type=0;else{var w=g.getBuffer(c);if(w)p.state=1,p.buffer=w,p.type=0;else if(\"constant\"in c){var h=c.constant;p.buffer=\"null\";p.state=2;\"number\"===typeof h?p.x=h:Da.forEach(function(a,b){b<h.length&&(p[a]=h[b])})}else{var w=Oa(c.buffer)?g.getBuffer(g.create(c.buffer,34962,!1,!0)):g.getBuffer(c.buffer),k=c.offset|0,m=c.stride|0,I=c.size|0,l=!!c.normalized,n=0;\"type\"in c&&(n=Ra[c.type]);c=c.divisor|0;p.buffer=w;p.state=1;p.size=I;p.normalized=l;p.type=\nn||w.dtype;p.offset=k;p.stride=m;p.divisor=c}}f[a]=D(function(a,b){var c=a.attribCache;if(e in c)return c[e];var d={isStream:!1};Object.keys(p).forEach(function(a){d[a]=p[a]});p.buffer&&(d.buffer=a.link(p.buffer),d.type=d.type||d.buffer+\".dtype\");return c[e]=d})});Object.keys(e).forEach(function(a){var b=e[a];f[a]=P(b,function(a,c){function d(a){c(w[a],\"=\",e,\".\",a,\"|0;\")}var e=a.invoke(c,b),p=a.shared,f=p.isBufferArgs,g=p.buffer,w={isStream:c.def(!1)},h=new ya;h.state=1;Object.keys(h).forEach(function(a){w[a]=\nc.def(\"\"+h[a])});var z=w.buffer,k=w.type;c(\"if(\",f,\"(\",e,\")){\",w.isStream,\"=true;\",z,\"=\",g,\".createStream(\",34962,\",\",e,\");\",k,\"=\",z,\".dtype;\",\"}else{\",z,\"=\",g,\".getBuffer(\",e,\");\",\"if(\",z,\"){\",k,\"=\",z,\".dtype;\",'}else if(\"constant\" in ',e,\"){\",w.state,\"=\",2,\";\",\"if(typeof \"+e+'.constant === \"number\"){',w[Da[0]],\"=\",e,\".constant;\",Da.slice(1).map(function(a){return w[a]}).join(\"=\"),\"=0;\",\"}else{\",Da.map(function(a,b){return w[a]+\"=\"+e+\".constant.length>\"+b+\"?\"+e+\".constant[\"+b+\"]:0;\"}).join(\"\"),\"}}else{\",\n\"if(\",f,\"(\",e,\".buffer)){\",z,\"=\",g,\".createStream(\",34962,\",\",e,\".buffer);\",\"}else{\",z,\"=\",g,\".getBuffer(\",e,\".buffer);\",\"}\",k,'=\"type\" in ',e,\"?\",p.glTypes,\"[\",e,\".type]:\",z,\".dtype;\",w.normalized,\"=!!\",e,\".normalized;\");d(\"size\");d(\"offset\");d(\"stride\");d(\"divisor\");c(\"}}\");c.exit(\"if(\",w.isStream,\"){\",g,\".destroyStream(\",z,\");\",\"}\");return w})});return f}function M(a){var b=a[\"static\"],c=a.dynamic,d={};Object.keys(b).forEach(function(a){var c=b[a];d[a]=D(function(a,b){return\"number\"===typeof c||\n\"boolean\"===typeof c?\"\"+c:a.link(c)})});Object.keys(c).forEach(function(a){var b=c[a];d[a]=P(b,function(a,c){return a.invoke(c,b)})});return d}function A(a,b,c,d,e){var f=y(a,e),g=x(a,f,e),h=O(a,e),k=R(a,e),m=E(a,e),ba=g.viewport;ba&&(k.viewport=ba);ba=l(\"scissor.box\");(g=g[ba])&&(k[ba]=g);g=0<Object.keys(k).length;f={framebuffer:f,draw:h,shader:m,state:k,dirty:g};f.profile=B(a,e);f.uniforms=F(c,e);f.attributes=T(b,e);f.context=M(d,e);return f}function ua(a,b,c){var d=a.shared.context,e=a.scope();\nObject.keys(c).forEach(function(f){b.save(d,\".\"+f);e(d,\".\",f,\"=\",c[f].append(a,b),\";\")});b(e)}function K(a,b,c,d){var e=a.shared,f=e.gl,g=e.framebuffer,h;ha&&(h=b.def(e.extensions,\".webgl_draw_buffers\"));var k=a.constants,e=k.drawBuffer,k=k.backBuffer;a=c?c.append(a,b):b.def(g,\".next\");d||b(\"if(\",a,\"!==\",g,\".cur){\");b(\"if(\",a,\"){\",f,\".bindFramebuffer(\",36160,\",\",a,\".framebuffer);\");ha&&b(h,\".drawBuffersWEBGL(\",e,\"[\",a,\".colorAttachments.length]);\");b(\"}else{\",f,\".bindFramebuffer(\",36160,\",null);\");\nha&&b(h,\".drawBuffersWEBGL(\",k,\");\");b(\"}\",g,\".cur=\",a,\";\");d||b(\"}\")}function V(a,b,c){var d=a.shared,e=d.gl,f=a.current,g=a.next,h=d.current,k=d.next,m=a.cond(h,\".dirty\");Ka.forEach(function(b){b=l(b);if(!(b in c.state)){var d,w;if(b in g){d=g[b];w=f[b];var I=J(ra[b].length,function(a){return m.def(d,\"[\",a,\"]\")});m(a.cond(I.map(function(a,b){return a+\"!==\"+w+\"[\"+b+\"]\"}).join(\"||\")).then(e,\".\",ta[b],\"(\",I,\");\",I.map(function(a,b){return w+\"[\"+b+\"]=\"+a}).join(\";\"),\";\"))}else d=m.def(k,\".\",b),I=a.cond(d,\n\"!==\",h,\".\",b),m(I),b in sa?I(a.cond(d).then(e,\".enable(\",sa[b],\");\")[\"else\"](e,\".disable(\",sa[b],\");\"),h,\".\",b,\"=\",d,\";\"):I(e,\".\",ta[b],\"(\",d,\");\",h,\".\",b,\"=\",d,\";\")}});0===Object.keys(c.state).length&&m(h,\".dirty=false;\");b(m)}function Q(a,b,c,d){var e=a.shared,f=a.current,g=e.current,h=e.gl;vb(Object.keys(c)).forEach(function(e){var k=c[e];if(!d||d(k)){var m=k.append(a,b);if(sa[e]){var l=sa[e];va(k)?m?b(h,\".enable(\",l,\");\"):b(h,\".disable(\",l,\");\"):b(a.cond(m).then(h,\".enable(\",l,\");\")[\"else\"](h,\n\".disable(\",l,\");\"));b(g,\".\",e,\"=\",m,\";\")}else if(pa(m)){var n=f[e];b(h,\".\",ta[e],\"(\",m,\");\",m.map(function(a,b){return n+\"[\"+b+\"]=\"+a}).join(\";\"),\";\")}else b(h,\".\",ta[e],\"(\",m,\");\",g,\".\",e,\"=\",m,\";\")}})}function wa(a,b){ea&&(a.instancing=b.def(a.shared.extensions,\".angle_instanced_arrays\"))}function G(a,b,c,d,e){function f(){return\"undefined\"===typeof performance?\"Date.now()\":\"performance.now()\"}function g(a){t=b.def();a(t,\"=\",f(),\";\");\"string\"===typeof e?a(ba,\".count+=\",e,\";\"):a(ba,\".count++;\");\nk&&(d?(r=b.def(),a(r,\"=\",q,\".getNumPendingQueries();\")):a(q,\".beginQuery(\",ba,\");\"))}function h(a){a(ba,\".cpuTime+=\",f(),\"-\",t,\";\");k&&(d?a(q,\".pushScopeStats(\",r,\",\",q,\".getNumPendingQueries(),\",ba,\");\"):a(q,\".endQuery();\"))}function m(a){var c=b.def(n,\".profile\");b(n,\".profile=\",a,\";\");b.exit(n,\".profile=\",c,\";\")}var l=a.shared,ba=a.stats,n=l.current,q=l.timer;c=c.profile;var t,r;if(c){if(va(c)){c.enable?(g(b),h(b.exit),m(\"true\")):m(\"false\");return}c=c.append(a,b);m(c)}else c=b.def(n,\".profile\");\nl=a.block();g(l);b(\"if(\",c,\"){\",l,\"}\");a=a.block();h(a);b.exit(\"if(\",c,\"){\",a,\"}\")}function U(a,b,c,d,e){function f(a){switch(a){case 35664:case 35667:case 35671:return 2;case 35665:case 35668:case 35672:return 3;case 35666:case 35669:case 35673:return 4;default:return 1}}function g(c,d,e){function f(){b(\"if(!\",z,\".buffer){\",k,\".enableVertexAttribArray(\",l,\");}\");var c=e.type,g;g=e.size?b.def(e.size,\"||\",d):d;b(\"if(\",z,\".type!==\",c,\"||\",z,\".size!==\",g,\"||\",q.map(function(a){return z+\".\"+a+\"!==\"+e[a]}).join(\"||\"),\n\"){\",k,\".bindBuffer(\",34962,\",\",I,\".buffer);\",k,\".vertexAttribPointer(\",[l,g,c,e.normalized,e.stride,e.offset],\");\",z,\".type=\",c,\";\",z,\".size=\",g,\";\",q.map(function(a){return z+\".\"+a+\"=\"+e[a]+\";\"}).join(\"\"),\"}\");ea&&(c=e.divisor,b(\"if(\",z,\".divisor!==\",c,\"){\",a.instancing,\".vertexAttribDivisorANGLE(\",[l,c],\");\",z,\".divisor=\",c,\";}\"))}function m(){b(\"if(\",z,\".buffer){\",k,\".disableVertexAttribArray(\",l,\");\",\"}if(\",Da.map(function(a,b){return z+\".\"+a+\"!==\"+n[b]}).join(\"||\"),\"){\",k,\".vertexAttrib4f(\",\nl,\",\",n,\");\",Da.map(function(a,b){return z+\".\"+a+\"=\"+n[b]+\";\"}).join(\"\"),\"}\")}var k=h.gl,l=b.def(c,\".location\"),z=b.def(h.attributes,\"[\",l,\"]\");c=e.state;var I=e.buffer,n=[e.x,e.y,e.z,e.w],q=[\"buffer\",\"normalized\",\"offset\",\"stride\"];1===c?f():2===c?m():(b(\"if(\",c,\"===\",1,\"){\"),f(),b(\"}else{\"),m(),b(\"}\"))}var h=a.shared;d.forEach(function(d){var h=d.name,k=c.attributes[h],m;if(k){if(!e(k))return;m=k.append(a,b)}else{if(!e(xb))return;var l=a.scopeAttrib(h);m={};Object.keys(new ya).forEach(function(a){m[a]=\nb.def(l,\".\",a)})}g(a.link(d),f(d.info.type),m)})}function W(a,c,d,e,f){for(var g=a.shared,h=g.gl,k,m=0;m<e.length;++m){var l=e[m],n=l.name,q=l.info.type,t=d.uniforms[n],l=a.link(l)+\".location\",r;if(t){if(!f(t))continue;if(va(t)){n=t.value;if(35678===q||35680===q)q=a.link(n._texture||n.color[0]._texture),c(h,\".uniform1i(\",l,\",\",q+\".bind());\"),c.exit(q,\".unbind();\");else if(35674===q||35675===q||35676===q)n=a.global.def(\"new Float32Array([\"+Array.prototype.slice.call(n)+\"])\"),t=2,35675===q?t=3:35676===\nq&&(t=4),c(h,\".uniformMatrix\",t,\"fv(\",l,\",false,\",n,\");\");else{switch(q){case 5126:k=\"1f\";break;case 35664:k=\"2f\";break;case 35665:k=\"3f\";break;case 35666:k=\"4f\";break;case 35670:k=\"1i\";break;case 5124:k=\"1i\";break;case 35671:k=\"2i\";break;case 35667:k=\"2i\";break;case 35672:k=\"3i\";break;case 35668:k=\"3i\";break;case 35673:k=\"4i\";break;case 35669:k=\"4i\"}c(h,\".uniform\",k,\"(\",l,\",\",pa(n)?Array.prototype.slice.call(n):n,\");\")}continue}else r=t.append(a,c)}else{if(!f(xb))continue;r=c.def(g.uniforms,\"[\",\nb.id(n),\"]\")}35678===q?c(\"if(\",r,\"&&\",r,'._reglType===\"framebuffer\"){',r,\"=\",r,\".color[0];\",\"}\"):35680===q&&c(\"if(\",r,\"&&\",r,'._reglType===\"framebufferCube\"){',r,\"=\",r,\".color[0];\",\"}\");n=1;switch(q){case 35678:case 35680:q=c.def(r,\"._texture\");c(h,\".uniform1i(\",l,\",\",q,\".bind());\");c.exit(q,\".unbind();\");continue;case 5124:case 35670:k=\"1i\";break;case 35667:case 35671:k=\"2i\";n=2;break;case 35668:case 35672:k=\"3i\";n=3;break;case 35669:case 35673:k=\"4i\";n=4;break;case 5126:k=\"1f\";break;case 35664:k=\n\"2f\";n=2;break;case 35665:k=\"3f\";n=3;break;case 35666:k=\"4f\";n=4;break;case 35674:k=\"Matrix2fv\";break;case 35675:k=\"Matrix3fv\";break;case 35676:k=\"Matrix4fv\"}c(h,\".uniform\",k,\"(\",l,\",\");if(\"M\"===k.charAt(0)){var l=Math.pow(q-35674+2,2),v=a.global.def(\"new Float32Array(\",l,\")\");c(\"false,(Array.isArray(\",r,\")||\",r,\" instanceof Float32Array)?\",r,\":(\",J(l,function(a){return v+\"[\"+a+\"]=\"+r+\"[\"+a+\"]\"}),\",\",v,\")\")}else 1<n?c(J(n,function(a){return r+\"[\"+a+\"]\"})):c(r);c(\");\")}}function S(a,b,c,d){function e(f){var g=\nl[f];return g?g.contextDep&&d.contextDynamic||g.propDep?g.append(a,c):g.append(a,b):b.def(m,\".\",f)}function f(){function a(){c(u,\".drawElementsInstancedANGLE(\",[q,t,C,r+\"<<((\"+C+\"-5121)>>1)\",v],\");\")}function b(){c(u,\".drawArraysInstancedANGLE(\",[q,r,t,v],\");\")}n?da?a():(c(\"if(\",n,\"){\"),a(),c(\"}else{\"),b(),c(\"}\")):b()}function g(){function a(){c(k+\".drawElements(\"+[q,t,C,r+\"<<((\"+C+\"-5121)>>1)\"]+\");\")}function b(){c(k+\".drawArrays(\"+[q,r,t]+\");\")}n?da?a():(c(\"if(\",n,\"){\"),a(),c(\"}else{\"),b(),c(\"}\")):\nb()}var h=a.shared,k=h.gl,m=h.draw,l=d.draw,n=function(){var e=l.elements,f=b;if(e){if(e.contextDep&&d.contextDynamic||e.propDep)f=c;e=e.append(a,f)}else e=f.def(m,\".\",\"elements\");e&&f(\"if(\"+e+\")\"+k+\".bindBuffer(34963,\"+e+\".buffer.buffer);\");return e}(),q=e(\"primitive\"),r=e(\"offset\"),t=function(){var e=l.count,f=b;if(e){if(e.contextDep&&d.contextDynamic||e.propDep)f=c;e=e.append(a,f)}else e=f.def(m,\".\",\"count\");return e}();if(\"number\"===typeof t){if(0===t)return}else c(\"if(\",t,\"){\"),c.exit(\"}\");var v,\nu;ea&&(v=e(\"instances\"),u=a.instancing);var C=n+\".type\",da=l.elements&&va(l.elements);ea&&(\"number\"!==typeof v||0<=v)?\"string\"===typeof v?(c(\"if(\",v,\">0){\"),f(),c(\"}else if(\",v,\"<0){\"),g(),c(\"}\")):f():g()}function ca(a,b,c,d,e){b=N();e=b.proc(\"body\",e);ea&&(b.instancing=e.def(b.shared.extensions,\".angle_instanced_arrays\"));a(b,e,c,d);return b.compile().body}function L(a,b,c,d){wa(a,b);U(a,b,c,d.attributes,function(){return!0});W(a,b,c,d.uniforms,function(){return!0});S(a,b,b,c)}function da(a,b){var c=\na.proc(\"draw\",1);wa(a,c);ua(a,c,b.context);K(a,c,b.framebuffer);V(a,c,b);Q(a,c,b.state);G(a,c,b,!1,!0);var d=b.shader.progVar.append(a,c);c(a.shared.gl,\".useProgram(\",d,\".program);\");if(b.shader.program)L(a,c,b,b.shader.program);else{var e=a.global.def(\"{}\"),f=c.def(d,\".id\"),g=c.def(e,\"[\",f,\"]\");c(a.cond(g).then(g,\".call(this,a0);\")[\"else\"](g,\"=\",e,\"[\",f,\"]=\",a.link(function(c){return ca(L,a,b,c,1)}),\"(\",d,\");\",g,\".call(this,a0);\"))}0<Object.keys(b.state).length&&c(a.shared.current,\".dirty=true;\")}\nfunction oa(a,b,c,d){function e(){return!0}a.batchId=\"a1\";wa(a,b);U(a,b,c,d.attributes,e);W(a,b,c,d.uniforms,e);S(a,b,b,c)}function za(a,b,c,d){function e(a){return a.contextDep&&g||a.propDep}function f(a){return!e(a)}wa(a,b);var g=c.contextDep,h=b.def(),k=b.def();a.shared.props=k;a.batchId=h;var m=a.scope(),l=a.scope();b(m.entry,\"for(\",h,\"=0;\",h,\"<\",\"a1\",\";++\",h,\"){\",k,\"=\",\"a0\",\"[\",h,\"];\",l,\"}\",m.exit);c.needsContext&&ua(a,l,c.context);c.needsFramebuffer&&K(a,l,c.framebuffer);Q(a,l,c.state,e);c.profile&&\ne(c.profile)&&G(a,l,c,!1,!0);d?(U(a,m,c,d.attributes,f),U(a,l,c,d.attributes,e),W(a,m,c,d.uniforms,f),W(a,l,c,d.uniforms,e),S(a,m,l,c)):(b=a.global.def(\"{}\"),d=c.shader.progVar.append(a,l),k=l.def(d,\".id\"),m=l.def(b,\"[\",k,\"]\"),l(a.shared.gl,\".useProgram(\",d,\".program);\",\"if(!\",m,\"){\",m,\"=\",b,\"[\",k,\"]=\",a.link(function(b){return ca(oa,a,c,b,2)}),\"(\",d,\");}\",m,\".call(this,a0[\",h,\"],\",h,\");\"))}function ka(a,b){function c(a){return a.contextDep&&e||a.propDep}var d=a.proc(\"batch\",2);a.batchId=\"0\";wa(a,\nd);var e=!1,f=!0;Object.keys(b.context).forEach(function(a){e=e||b.context[a].propDep});e||(ua(a,d,b.context),f=!1);var g=b.framebuffer,h=!1;g?(g.propDep?e=h=!0:g.contextDep&&e&&(h=!0),h||K(a,d,g)):K(a,d,null);b.state.viewport&&b.state.viewport.propDep&&(e=!0);V(a,d,b);Q(a,d,b.state,function(a){return!c(a)});b.profile&&c(b.profile)||G(a,d,b,!1,\"a1\");b.contextDep=e;b.needsContext=f;b.needsFramebuffer=h;f=b.shader.progVar;if(f.contextDep&&e||f.propDep)za(a,d,b,null);else if(f=f.append(a,d),d(a.shared.gl,\n\".useProgram(\",f,\".program);\"),b.shader.program)za(a,d,b,b.shader.program);else{var g=a.global.def(\"{}\"),h=d.def(f,\".id\"),k=d.def(g,\"[\",h,\"]\");d(a.cond(k).then(k,\".call(this,a0,a1);\")[\"else\"](k,\"=\",g,\"[\",h,\"]=\",a.link(function(c){return ca(za,a,b,c,2)}),\"(\",f,\");\",k,\".call(this,a0,a1);\"))}0<Object.keys(b.state).length&&d(a.shared.current,\".dirty=true;\")}function ia(a,c){function d(b){var g=c.shader[b];g&&e.set(f.shader,\".\"+b,g.append(a,e))}var e=a.proc(\"scope\",3);a.batchId=\"a2\";var f=a.shared,g=f.current;\nua(a,e,c.context);c.framebuffer&&c.framebuffer.append(a,e);vb(Object.keys(c.state)).forEach(function(b){var d=c.state[b].append(a,e);pa(d)?d.forEach(function(c,d){e.set(a.next[b],\"[\"+d+\"]\",c)}):e.set(f.next,\".\"+b,d)});G(a,e,c,!0,!0);[\"elements\",\"offset\",\"count\",\"instances\",\"primitive\"].forEach(function(b){var d=c.draw[b];d&&e.set(f.draw,\".\"+b,\"\"+d.append(a,e))});Object.keys(c.uniforms).forEach(function(d){e.set(f.uniforms,\"[\"+b.id(d)+\"]\",c.uniforms[d].append(a,e))});Object.keys(c.attributes).forEach(function(b){var d=\nc.attributes[b].append(a,e),f=a.scopeAttrib(b);Object.keys(new ya).forEach(function(a){e.set(f,\".\"+a,d[a])})});d(\"vert\");d(\"frag\");0<Object.keys(c.state).length&&(e(g,\".dirty=true;\"),e.exit(g,\".dirty=true;\"));e(\"a1(\",a.shared.context,\",a0,\",a.batchId,\");\")}function ma(a){if(\"object\"===typeof a&&!pa(a)){for(var b=Object.keys(a),c=0;c<b.length;++c)if(la.isDynamic(a[b[c]]))return!0;return!1}}function ja(a,b,c){function d(a,b){g.forEach(function(c){var d=e[c];la.isDynamic(d)&&(d=a.invoke(b,d),b(l,\".\",\nc,\"=\",d,\";\"))})}var e=b[\"static\"][c];if(e&&ma(e)){var f=a.global,g=Object.keys(e),h=!1,k=!1,m=!1,l=a.global.def(\"{}\");g.forEach(function(b){var c=e[b];if(la.isDynamic(c))\"function\"===typeof c&&(c=e[b]=la.unbox(c)),b=P(c,null),h=h||b.thisDep,m=m||b.propDep,k=k||b.contextDep;else{f(l,\".\",b,\"=\");switch(typeof c){case \"number\":f(c);break;case \"string\":f('\"',c,'\"');break;case \"object\":Array.isArray(c)&&f(\"[\",c.join(),\"]\");break;default:f(a.link(c))}f(\";\")}});b.dynamic[c]=new la.DynamicVariable(4,{thisDep:h,\ncontextDep:k,propDep:m,ref:l,append:d});delete b[\"static\"][c]}}var ya=q.Record,X={add:32774,subtract:32778,\"reverse subtract\":32779};c.ext_blend_minmax&&(X.min=32775,X.max=32776);var ea=c.angle_instanced_arrays,ha=c.webgl_draw_buffers,ra={dirty:!0,profile:h.profile},Fa={},Ka=[],sa={},ta={};u(\"dither\",3024);u(\"blend.enable\",3042);v(\"blend.color\",\"blendColor\",[0,0,0,0]);v(\"blend.equation\",\"blendEquationSeparate\",[32774,32774]);v(\"blend.func\",\"blendFuncSeparate\",[1,0,1,0]);u(\"depth.enable\",2929,!0);\nv(\"depth.func\",\"depthFunc\",513);v(\"depth.range\",\"depthRange\",[0,1]);v(\"depth.mask\",\"depthMask\",!0);v(\"colorMask\",\"colorMask\",[!0,!0,!0,!0]);u(\"cull.enable\",2884);v(\"cull.face\",\"cullFace\",1029);v(\"frontFace\",\"frontFace\",2305);v(\"lineWidth\",\"lineWidth\",1);u(\"polygonOffset.enable\",32823);v(\"polygonOffset.offset\",\"polygonOffset\",[0,0]);u(\"sample.alpha\",32926);u(\"sample.enable\",32928);v(\"sample.coverage\",\"sampleCoverage\",[1,!1]);u(\"stencil.enable\",2960);v(\"stencil.mask\",\"stencilMask\",-1);v(\"stencil.func\",\n\"stencilFunc\",[519,0,-1]);v(\"stencil.opFront\",\"stencilOpSeparate\",[1028,7680,7680,7680]);v(\"stencil.opBack\",\"stencilOpSeparate\",[1029,7680,7680,7680]);u(\"scissor.enable\",3089);v(\"scissor.box\",\"scissor\",[0,0,a.drawingBufferWidth,a.drawingBufferHeight]);v(\"viewport\",\"viewport\",[0,0,a.drawingBufferWidth,a.drawingBufferHeight]);var na={gl:a,context:C,strings:b,next:Fa,current:ra,draw:m,elements:d,buffer:g,shader:t,attributes:q.state,uniforms:r,framebuffer:f,extensions:c,timer:k,isBufferArgs:Oa},aa={primTypes:Sa,\ncompareFuncs:Xa,blendFuncs:Ga,blendEquations:X,stencilOps:Pa,glTypes:Ra,orientationType:wb};ha&&(aa.backBuffer=[1029],aa.drawBuffer=J(e.maxDrawbuffers,function(a){return 0===a?[0]:J(a,function(a){return 36064+a})}));var qa=0;return{next:Fa,current:ra,procs:function(){var a=N(),b=a.proc(\"poll\"),c=a.proc(\"refresh\"),d=a.block();b(d);c(d);var f=a.shared,g=f.gl,h=f.next,k=f.current;d(k,\".dirty=false;\");K(a,b);K(a,c,null,!0);var m;ea&&(m=a.link(ea));for(var l=0;l<e.maxAttributes;++l){var n=c.def(f.attributes,\n\"[\",l,\"]\"),q=a.cond(n,\".buffer\");q.then(g,\".enableVertexAttribArray(\",l,\");\",g,\".bindBuffer(\",34962,\",\",n,\".buffer.buffer);\",g,\".vertexAttribPointer(\",l,\",\",n,\".size,\",n,\".type,\",n,\".normalized,\",n,\".stride,\",n,\".offset);\")[\"else\"](g,\".disableVertexAttribArray(\",l,\");\",g,\".vertexAttrib4f(\",l,\",\",n,\".x,\",n,\".y,\",n,\".z,\",n,\".w);\",n,\".buffer=null;\");c(q);ea&&c(m,\".vertexAttribDivisorANGLE(\",l,\",\",n,\".divisor);\")}Object.keys(sa).forEach(function(e){var f=sa[e],m=d.def(h,\".\",e),l=a.block();l(\"if(\",m,\"){\",\ng,\".enable(\",f,\")}else{\",g,\".disable(\",f,\")}\",k,\".\",e,\"=\",m,\";\");c(l);b(\"if(\",m,\"!==\",k,\".\",e,\"){\",l,\"}\")});Object.keys(ta).forEach(function(e){var f=ta[e],m=ra[e],l,n,q=a.block();q(g,\".\",f,\"(\");pa(m)?(f=m.length,l=a.global.def(h,\".\",e),n=a.global.def(k,\".\",e),q(J(f,function(a){return l+\"[\"+a+\"]\"}),\");\",J(f,function(a){return n+\"[\"+a+\"]=\"+l+\"[\"+a+\"];\"}).join(\"\")),b(\"if(\",J(f,function(a){return l+\"[\"+a+\"]!==\"+n+\"[\"+a+\"]\"}).join(\"||\"),\"){\",q,\"}\")):(l=d.def(h,\".\",e),n=d.def(k,\".\",e),q(l,\");\",k,\".\",e,\n\"=\",l,\";\"),b(\"if(\",l,\"!==\",n,\"){\",q,\"}\"));c(q)});return a.compile()}(),compile:function(a,b,c,d,e){var f=N();f.stats=f.link(e);Object.keys(b[\"static\"]).forEach(function(a){ja(f,b,a)});Ub.forEach(function(b){ja(f,a,b)});c=A(a,b,c,d,f);da(f,c);ia(f,c);ka(f,c);return f.compile()}}}function yb(a,b){for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}var E=function(a,b){for(var c=Object.keys(b),e=0;e<c.length;++e)a[c[e]]=b[c[e]];return a},Ab=0,la={DynamicVariable:aa,define:function(a,b){return new aa(a,\nZa(b+\"\"))},isDynamic:function(a){return\"function\"===typeof a&&!a._reglType||a instanceof aa},unbox:function(a,b){return\"function\"===typeof a?new aa(0,a):a},accessor:Za},Ya={next:\"function\"===typeof requestAnimationFrame?function(a){return requestAnimationFrame(a)}:function(a){return setTimeout(a,16)},cancel:\"function\"===typeof cancelAnimationFrame?function(a){return cancelAnimationFrame(a)}:clearTimeout},zb=\"undefined\"!==typeof performance&&performance.now?function(){return performance.now()}:function(){return+new Date},\nx=cb();x.zero=cb();var Vb=function(a,b){var c=1;b.ext_texture_filter_anisotropic&&(c=a.getParameter(34047));var e=1,g=1;b.webgl_draw_buffers&&(e=a.getParameter(34852),g=a.getParameter(36063));var d=!!b.oes_texture_float;if(d){d=a.createTexture();a.bindTexture(3553,d);a.texImage2D(3553,0,6408,1,1,0,6408,5126,null);var n=a.createFramebuffer();a.bindFramebuffer(36160,n);a.framebufferTexture2D(36160,36064,3553,d,0);a.bindTexture(3553,null);if(36053!==a.checkFramebufferStatus(36160))d=!1;else{a.viewport(0,\n0,1,1);a.clearColor(1,0,0,1);a.clear(16384);var f=x.allocType(5126,4);a.readPixels(0,0,1,1,6408,5126,f);a.getError()?d=!1:(a.deleteFramebuffer(n),a.deleteTexture(d),d=1===f[0]);x.freeType(f)}}f=!0;\"undefined\"!==typeof navigator&&(/MSIE/.test(navigator.userAgent)||/Trident\\//.test(navigator.appVersion)||/Edge/.test(navigator.userAgent))||(f=a.createTexture(),n=x.allocType(5121,36),a.activeTexture(33984),a.bindTexture(34067,f),a.texImage2D(34069,0,6408,3,3,0,6408,5121,n),x.freeType(n),a.bindTexture(34067,\nnull),a.deleteTexture(f),f=!a.getError());return{colorBits:[a.getParameter(3410),a.getParameter(3411),a.getParameter(3412),a.getParameter(3413)],depthBits:a.getParameter(3414),stencilBits:a.getParameter(3415),subpixelBits:a.getParameter(3408),extensions:Object.keys(b).filter(function(a){return!!b[a]}),maxAnisotropic:c,maxDrawbuffers:e,maxColorAttachments:g,pointSizeDims:a.getParameter(33901),lineWidthDims:a.getParameter(33902),maxViewportDims:a.getParameter(3386),maxCombinedTextureUnits:a.getParameter(35661),\nmaxCubeMapSize:a.getParameter(34076),maxRenderbufferSize:a.getParameter(34024),maxTextureUnits:a.getParameter(34930),maxTextureSize:a.getParameter(3379),maxAttributes:a.getParameter(34921),maxVertexUniforms:a.getParameter(36347),maxVertexTextureUnits:a.getParameter(35660),maxVaryingVectors:a.getParameter(36348),maxFragmentUniforms:a.getParameter(36349),glsl:a.getParameter(35724),renderer:a.getParameter(7937),vendor:a.getParameter(7936),version:a.getParameter(7938),readFloat:d,npotTextureCube:f}},\nM=function(a){return a instanceof Uint8Array||a instanceof Uint16Array||a instanceof Uint32Array||a instanceof Int8Array||a instanceof Int16Array||a instanceof Int32Array||a instanceof Float32Array||a instanceof Float64Array||a instanceof Uint8ClampedArray},S=function(a){return Object.keys(a).map(function(b){return a[b]})},Ma={shape:function(a){for(var b=[];a.length;a=a[0])b.push(a.length);return b},flatten:function(a,b,c,e){var g=1;if(b.length)for(var d=0;d<b.length;++d)g*=b[d];else g=0;c=e||x.allocType(c,\ng);switch(b.length){case 0:break;case 1:e=b[0];for(b=0;b<e;++b)c[b]=a[b];break;case 2:e=b[0];b=b[1];for(d=g=0;d<e;++d)for(var n=a[d],f=0;f<b;++f)c[g++]=n[f];break;case 3:db(a,b[0],b[1],b[2],c,0);break;default:eb(a,b,0,c,0)}return c}},Ia={\"[object Int8Array]\":5120,\"[object Int16Array]\":5122,\"[object Int32Array]\":5124,\"[object Uint8Array]\":5121,\"[object Uint8ClampedArray]\":5121,\"[object Uint16Array]\":5123,\"[object Uint32Array]\":5125,\"[object Float32Array]\":5126,\"[object Float64Array]\":5121,\"[object ArrayBuffer]\":5121},\nRa={int8:5120,int16:5122,int32:5124,uint8:5121,uint16:5123,uint32:5125,\"float\":5126,float32:5126},jb={dynamic:35048,stream:35040,\"static\":35044},Qa=Ma.flatten,hb=Ma.shape,ja=[];ja[5120]=1;ja[5122]=2;ja[5124]=4;ja[5121]=1;ja[5123]=2;ja[5125]=4;ja[5126]=4;var Sa={points:0,point:0,lines:1,line:1,triangles:4,triangle:4,\"line loop\":2,\"line strip\":3,\"triangle strip\":5,\"triangle fan\":6},lb=new Float32Array(1),Ib=new Uint32Array(lb.buffer),Mb=[9984,9986,9985,9987],La=[0,6409,6410,6407,6408],L={};L[6409]=\nL[6406]=L[6402]=1;L[34041]=L[6410]=2;L[6407]=L[35904]=3;L[6408]=L[35906]=4;var Ua=Ea(\"HTMLCanvasElement\"),pb=Ea(\"CanvasRenderingContext2D\"),qb=Ea(\"ImageBitmap\"),rb=Ea(\"HTMLImageElement\"),sb=Ea(\"HTMLVideoElement\"),Jb=Object.keys(Ia).concat([Ua,pb,qb,rb,sb]),qa=[];qa[5121]=1;qa[5126]=4;qa[36193]=2;qa[5123]=2;qa[5125]=4;var y=[];y[32854]=2;y[32855]=2;y[36194]=2;y[34041]=4;y[33776]=.5;y[33777]=.5;y[33778]=1;y[33779]=1;y[35986]=.5;y[35987]=1;y[34798]=1;y[35840]=.5;y[35841]=.25;y[35842]=.5;y[35843]=.25;\ny[36196]=.5;var Q=[];Q[32854]=2;Q[32855]=2;Q[36194]=2;Q[33189]=2;Q[36168]=1;Q[34041]=4;Q[35907]=4;Q[34836]=16;Q[34842]=8;Q[34843]=6;var Wb=function(a,b,c,e,g){function d(a){this.id=q++;this.refCount=1;this.renderbuffer=a;this.format=32854;this.height=this.width=0;g.profile&&(this.stats={size:0})}function n(b){var c=b.renderbuffer;a.bindRenderbuffer(36161,null);a.deleteRenderbuffer(c);b.renderbuffer=null;b.refCount=0;delete t[b.id];e.renderbufferCount--}var f={rgba4:32854,rgb565:36194,\"rgb5 a1\":32855,\ndepth:33189,stencil:36168,\"depth stencil\":34041};b.ext_srgb&&(f.srgba=35907);b.ext_color_buffer_half_float&&(f.rgba16f=34842,f.rgb16f=34843);b.webgl_color_buffer_float&&(f.rgba32f=34836);var r=[];Object.keys(f).forEach(function(a){r[f[a]]=a});var q=0,t={};d.prototype.decRef=function(){0>=--this.refCount&&n(this)};g.profile&&(e.getTotalRenderbufferSize=function(){var a=0;Object.keys(t).forEach(function(b){a+=t[b].stats.size});return a});return{create:function(b,c){function k(b,c){var d=0,e=0,m=32854;\n\"object\"===typeof b&&b?(\"shape\"in b?(e=b.shape,d=e[0]|0,e=e[1]|0):(\"radius\"in b&&(d=e=b.radius|0),\"width\"in b&&(d=b.width|0),\"height\"in b&&(e=b.height|0)),\"format\"in b&&(m=f[b.format])):\"number\"===typeof b?(d=b|0,e=\"number\"===typeof c?c|0:d):b||(d=e=1);if(d!==h.width||e!==h.height||m!==h.format)return k.width=h.width=d,k.height=h.height=e,h.format=m,a.bindRenderbuffer(36161,h.renderbuffer),a.renderbufferStorage(36161,m,d,e),g.profile&&(h.stats.size=Q[h.format]*h.width*h.height),k.format=r[h.format],\nk}var h=new d(a.createRenderbuffer());t[h.id]=h;e.renderbufferCount++;k(b,c);k.resize=function(b,c){var d=b|0,e=c|0||d;if(d===h.width&&e===h.height)return k;k.width=h.width=d;k.height=h.height=e;a.bindRenderbuffer(36161,h.renderbuffer);a.renderbufferStorage(36161,h.format,d,e);g.profile&&(h.stats.size=Q[h.format]*h.width*h.height);return k};k._reglType=\"renderbuffer\";k._renderbuffer=h;g.profile&&(k.stats=h.stats);k.destroy=function(){h.decRef()};return k},clear:function(){S(t).forEach(n)},restore:function(){S(t).forEach(function(b){b.renderbuffer=\na.createRenderbuffer();a.bindRenderbuffer(36161,b.renderbuffer);a.renderbufferStorage(36161,b.format,b.width,b.height)});a.bindRenderbuffer(36161,null)}}},Wa=[];Wa[6408]=4;Wa[6407]=3;var Na=[];Na[5121]=1;Na[5126]=4;Na[36193]=2;var Da=[\"x\",\"y\",\"z\",\"w\"],Ub=\"blend.func blend.equation stencil.func stencil.opFront stencil.opBack sample.coverage viewport scissor.box polygonOffset.offset\".split(\" \"),Ga={0:0,1:1,zero:0,one:1,\"src color\":768,\"one minus src color\":769,\"src alpha\":770,\"one minus src alpha\":771,\n\"dst color\":774,\"one minus dst color\":775,\"dst alpha\":772,\"one minus dst alpha\":773,\"constant color\":32769,\"one minus constant color\":32770,\"constant alpha\":32771,\"one minus constant alpha\":32772,\"src alpha saturate\":776},Xa={never:512,less:513,\"<\":513,equal:514,\"=\":514,\"==\":514,\"===\":514,lequal:515,\"<=\":515,greater:516,\">\":516,notequal:517,\"!=\":517,\"!==\":517,gequal:518,\">=\":518,always:519},Pa={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,\"increment wrap\":34055,\"decrement wrap\":34056,\ninvert:5386},wb={cw:2304,ccw:2305},xb=new Z(!1,!1,!1,function(){}),Xb=function(a,b){function c(){this.endQueryIndex=this.startQueryIndex=-1;this.sum=0;this.stats=null}function e(a,b,d){var e=n.pop()||new c;e.startQueryIndex=a;e.endQueryIndex=b;e.sum=0;e.stats=d;f.push(e)}if(!b.ext_disjoint_timer_query)return null;var g=[],d=[],n=[],f=[],r=[],q=[];return{beginQuery:function(a){var c=g.pop()||b.ext_disjoint_timer_query.createQueryEXT();b.ext_disjoint_timer_query.beginQueryEXT(35007,c);d.push(c);e(d.length-\n1,d.length,a)},endQuery:function(){b.ext_disjoint_timer_query.endQueryEXT(35007)},pushScopeStats:e,update:function(){var a,c;a=d.length;if(0!==a){q.length=Math.max(q.length,a+1);r.length=Math.max(r.length,a+1);r[0]=0;var e=q[0]=0;for(c=a=0;c<d.length;++c){var k=d[c];b.ext_disjoint_timer_query.getQueryObjectEXT(k,34919)?(e+=b.ext_disjoint_timer_query.getQueryObjectEXT(k,34918),g.push(k)):d[a++]=k;r[c+1]=e;q[c+1]=a}d.length=a;for(c=a=0;c<f.length;++c){var e=f[c],h=e.startQueryIndex,k=e.endQueryIndex;\ne.sum+=r[k]-r[h];h=q[h];k=q[k];k===h?(e.stats.gpuTime+=e.sum/1E6,n.push(e)):(e.startQueryIndex=h,e.endQueryIndex=k,f[a++]=e)}f.length=a}},getNumPendingQueries:function(){return d.length},clear:function(){g.push.apply(g,d);for(var a=0;a<g.length;a++)b.ext_disjoint_timer_query.deleteQueryEXT(g[a]);d.length=0;g.length=0},restore:function(){d.length=0;g.length=0}}};return function(a){function b(){if(0===G.length)B&&B.update(),ca=null;else{ca=Ya.next(b);t();for(var a=G.length-1;0<=a;--a){var c=G[a];c&&\nc(O,null,0)}k.flush();B&&B.update()}}function c(){!ca&&0<G.length&&(ca=Ya.next(b))}function e(){ca&&(Ya.cancel(b),ca=null)}function g(a){a.preventDefault();e();U.forEach(function(a){a()})}function d(a){k.getError();l.restore();Q.restore();F.restore();A.restore();M.restore();K.restore();B&&B.restore();V.procs.refresh();c();W.forEach(function(a){a()})}function n(a){function b(a){var c={},d={};Object.keys(a).forEach(function(b){var e=a[b];la.isDynamic(e)?d[b]=la.unbox(e,b):c[b]=e});return{dynamic:d,\n\"static\":c}}function c(a){for(;m.length<a;)m.push(null);return m}var d=b(a.context||{}),e=b(a.uniforms||{}),f=b(a.attributes||{}),g=b(function(a){function b(a){if(a in c){var d=c[a];delete c[a];Object.keys(d).forEach(function(b){c[a+\".\"+b]=d[b]})}}var c=E({},a);delete c.uniforms;delete c.attributes;delete c.context;\"stencil\"in c&&c.stencil.op&&(c.stencil.opBack=c.stencil.opFront=c.stencil.op,delete c.stencil.op);b(\"blend\");b(\"depth\");b(\"cull\");b(\"stencil\");b(\"polygonOffset\");b(\"scissor\");b(\"sample\");\nreturn c}(a));a={gpuTime:0,cpuTime:0,count:0};var d=V.compile(g,f,e,d,a),h=d.draw,k=d.batch,l=d.scope,m=[];return E(function(a,b){var d;if(\"function\"===typeof a)return l.call(this,null,a,0);if(\"function\"===typeof b)if(\"number\"===typeof a)for(d=0;d<a;++d)l.call(this,null,b,d);else if(Array.isArray(a))for(d=0;d<a.length;++d)l.call(this,a[d],b,d);else return l.call(this,a,b,0);else if(\"number\"===typeof a){if(0<a)return k.call(this,c(a|0),a|0)}else if(Array.isArray(a)){if(a.length)return k.call(this,\na,a.length)}else return h.call(this,a)},{stats:a})}function f(a,b){var c=0;V.procs.poll();var d=b.color;d&&(k.clearColor(+d[0]||0,+d[1]||0,+d[2]||0,+d[3]||0),c|=16384);\"depth\"in b&&(k.clearDepth(+b.depth),c|=256);\"stencil\"in b&&(k.clearStencil(b.stencil|0),c|=1024);k.clear(c)}function r(a){G.push(a);c();return{cancel:function(){function b(){var a=yb(G,b);G[a]=G[G.length-1];--G.length;0>=G.length&&e()}var c=yb(G,a);G[c]=b}}}function q(){var a=S.viewport,b=S.scissor_box;a[0]=a[1]=b[0]=b[1]=0;O.viewportWidth=\nO.framebufferWidth=O.drawingBufferWidth=a[2]=b[2]=k.drawingBufferWidth;O.viewportHeight=O.framebufferHeight=O.drawingBufferHeight=a[3]=b[3]=k.drawingBufferHeight}function t(){O.tick+=1;O.time=y();q();V.procs.poll()}function m(){q();V.procs.refresh();B&&B.update()}function y(){return(zb()-D)/1E3}a=Eb(a);if(!a)return null;var k=a.gl,h=k.getContextAttributes();k.isContextLost();var l=Fb(k,a);if(!l)return null;var u=Bb(),v={bufferCount:0,elementsCount:0,framebufferCount:0,shaderCount:0,textureCount:0,\ncubeCount:0,renderbufferCount:0,maxTextureUnits:0},x=l.extensions,B=Xb(k,x),D=zb(),J=k.drawingBufferWidth,P=k.drawingBufferHeight,O={tick:0,time:0,viewportWidth:J,viewportHeight:P,framebufferWidth:J,framebufferHeight:P,drawingBufferWidth:J,drawingBufferHeight:P,pixelRatio:a.pixelRatio},R=Vb(k,x),J=Pb(k,x,R,u),F=Gb(k,v,a,J),T=Hb(k,x,F,v),Q=Qb(k,u,v,a),A=Kb(k,x,R,function(){V.procs.poll()},O,v,a),M=Wb(k,x,R,v,a),K=Ob(k,x,R,A,M,v),V=Tb(k,u,x,R,F,T,A,K,{},J,Q,{elements:null,primitive:4,count:-1,offset:0,\ninstances:-1},O,B,a),u=Rb(k,K,V.procs.poll,O,h,x,R),S=V.next,L=k.canvas,G=[],U=[],W=[],Z=[a.onDestroy],ca=null;L&&(L.addEventListener(\"webglcontextlost\",g,!1),L.addEventListener(\"webglcontextrestored\",d,!1));var aa=K.setFBO=n({framebuffer:la.define.call(null,1,\"framebuffer\")});m();h=E(n,{clear:function(a){if(\"framebuffer\"in a)if(a.framebuffer&&\"framebufferCube\"===a.framebuffer_reglType)for(var b=0;6>b;++b)aa(E({framebuffer:a.framebuffer.faces[b]},a),f);else aa(a,f);else f(null,a)},prop:la.define.bind(null,\n1),context:la.define.bind(null,2),\"this\":la.define.bind(null,3),draw:n({}),buffer:function(a){return F.create(a,34962,!1,!1)},elements:function(a){return T.create(a,!1)},texture:A.create2D,cube:A.createCube,renderbuffer:M.create,framebuffer:K.create,framebufferCube:K.createCube,attributes:h,frame:r,on:function(a,b){var c;switch(a){case \"frame\":return r(b);case \"lost\":c=U;break;case \"restore\":c=W;break;case \"destroy\":c=Z}c.push(b);return{cancel:function(){for(var a=0;a<c.length;++a)if(c[a]===b){c[a]=\nc[c.length-1];c.pop();break}}}},limits:R,hasExtension:function(a){return 0<=R.extensions.indexOf(a.toLowerCase())},read:u,destroy:function(){G.length=0;e();L&&(L.removeEventListener(\"webglcontextlost\",g),L.removeEventListener(\"webglcontextrestored\",d));Q.clear();K.clear();M.clear();A.clear();T.clear();F.clear();B&&B.clear();Z.forEach(function(a){a()})},_gl:k,_refresh:m,poll:function(){t();B&&B.update()},now:y,stats:v});a.onDone(null,h);return h}});\n\n},{}],503:[function(_dereq_,module,exports){\n/*!\n * repeat-string <https://github.com/jonschlinkert/repeat-string>\n *\n * Copyright (c) 2014-2015, Jon Schlinkert.\n * Licensed under the MIT License.\n */\n\n'use strict';\n\n/**\n * Results cache\n */\n\nvar res = '';\nvar cache;\n\n/**\n * Expose `repeat`\n */\n\nmodule.exports = repeat;\n\n/**\n * Repeat the given `string` the specified `number`\n * of times.\n *\n * **Example:**\n *\n * ```js\n * var repeat = require('repeat-string');\n * repeat('A', 5);\n * //=> AAAAA\n * ```\n *\n * @param {String} `string` The string to repeat\n * @param {Number} `number` The number of times to repeat the string\n * @return {String} Repeated string\n * @api public\n */\n\nfunction repeat(str, num) {\n  if (typeof str !== 'string') {\n    throw new TypeError('expected a string');\n  }\n\n  // cover common, quick use cases\n  if (num === 1) return str;\n  if (num === 2) return str + str;\n\n  var max = str.length * num;\n  if (cache !== str || typeof cache === 'undefined') {\n    cache = str;\n    res = '';\n  } else if (res.length >= max) {\n    return res.substr(0, max);\n  }\n\n  while (max > res.length && num > 1) {\n    if (num & 1) {\n      res += str;\n    }\n\n    num >>= 1;\n    str += str;\n  }\n\n  res += str;\n  res = res.substr(0, max);\n  return res;\n}\n\n},{}],504:[function(_dereq_,module,exports){\n(function (global){\nmodule.exports =\n  global.performance &&\n  global.performance.now ? function now() {\n    return performance.now()\n  } : Date.now || function now() {\n    return +new Date\n  }\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{}],505:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = compressExpansion\n\nfunction compressExpansion(e) {\n  var m = e.length\n  var Q = e[e.length-1]\n  var bottom = m\n  for(var i=m-2; i>=0; --i) {\n    var a = Q\n    var b = e[i]\n    Q = a + b\n    var bv = Q - a\n    var q = b - bv\n    if(q) {\n      e[--bottom] = Q\n      Q = q\n    }\n  }\n  var top = 0\n  for(var i=bottom; i<m; ++i) {\n    var a = e[i]\n    var b = Q\n    Q = a + b\n    var bv = Q - a\n    var q = b - bv\n    if(q) {\n      e[top++] = q\n    }\n  }\n  e[top++] = Q\n  e.length = top\n  return e\n}\n},{}],506:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar twoProduct = _dereq_(\"two-product\")\nvar robustSum = _dereq_(\"robust-sum\")\nvar robustScale = _dereq_(\"robust-scale\")\nvar compress = _dereq_(\"robust-compress\")\n\nvar NUM_EXPANDED = 6\n\nfunction cofactor(m, c) {\n  var result = new Array(m.length-1)\n  for(var i=1; i<m.length; ++i) {\n    var r = result[i-1] = new Array(m.length-1)\n    for(var j=0,k=0; j<m.length; ++j) {\n      if(j === c) {\n        continue\n      }\n      r[k++] = m[i][j]\n    }\n  }\n  return result\n}\n\nfunction matrix(n) {\n  var result = new Array(n)\n  for(var i=0; i<n; ++i) {\n    result[i] = new Array(n)\n    for(var j=0; j<n; ++j) {\n      result[i][j] = [\"m[\", i, \"][\", j, \"]\"].join(\"\")\n    }\n  }\n  return result\n}\n\nfunction sign(n) {\n  if(n & 1) {\n    return \"-\"\n  }\n  return \"\"\n}\n\nfunction generateSum(expr) {\n  if(expr.length === 1) {\n    return expr[0]\n  } else if(expr.length === 2) {\n    return [\"sum(\", expr[0], \",\", expr[1], \")\"].join(\"\")\n  } else {\n    var m = expr.length>>1\n    return [\"sum(\", generateSum(expr.slice(0, m)), \",\", generateSum(expr.slice(m)), \")\"].join(\"\")\n  }\n}\n\nfunction determinant(m) {\n  if(m.length === 2) {\n    return [\"sum(prod(\", m[0][0], \",\", m[1][1], \"),prod(-\", m[0][1], \",\", m[1][0], \"))\"].join(\"\")\n  } else {\n    var expr = []\n    for(var i=0; i<m.length; ++i) {\n      expr.push([\"scale(\", determinant(cofactor(m, i)), \",\", sign(i), m[0][i], \")\"].join(\"\"))\n    }\n    return generateSum(expr)\n  }\n}\n\nfunction compileDeterminant(n) {\n  var proc = new Function(\"sum\", \"scale\", \"prod\", \"compress\", [\n    \"function robustDeterminant\",n, \"(m){return compress(\", \n      determinant(matrix(n)),\n    \")};return robustDeterminant\", n].join(\"\"))\n  return proc(robustSum, robustScale, twoProduct, compress)\n}\n\nvar CACHE = [\n  function robustDeterminant0() { return [0] },\n  function robustDeterminant1(m) { return [m[0][0]] }\n]\n\nfunction generateDispatch() {\n  while(CACHE.length < NUM_EXPANDED) {\n    CACHE.push(compileDeterminant(CACHE.length))\n  }\n  var procArgs = []\n  var code = [\"function robustDeterminant(m){switch(m.length){\"]\n  for(var i=0; i<NUM_EXPANDED; ++i) {\n    procArgs.push(\"det\" + i)\n    code.push(\"case \", i, \":return det\", i, \"(m);\")\n  }\n  code.push(\"}\\\nvar det=CACHE[m.length];\\\nif(!det)\\\ndet=CACHE[m.length]=gen(m.length);\\\nreturn det(m);\\\n}\\\nreturn robustDeterminant\")\n  procArgs.push(\"CACHE\", \"gen\", code.join(\"\"))\n  var proc = Function.apply(undefined, procArgs)\n  module.exports = proc.apply(undefined, CACHE.concat([CACHE, compileDeterminant]))\n  for(var i=0; i<CACHE.length; ++i) {\n    module.exports[i] = CACHE[i]\n  }\n}\n\ngenerateDispatch()\n},{\"robust-compress\":505,\"robust-scale\":512,\"robust-sum\":515,\"two-product\":543}],507:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar twoProduct = _dereq_(\"two-product\")\nvar robustSum = _dereq_(\"robust-sum\")\n\nmodule.exports = robustDotProduct\n\nfunction robustDotProduct(a, b) {\n  var r = twoProduct(a[0], b[0])\n  for(var i=1; i<a.length; ++i) {\n    r = robustSum(r, twoProduct(a[i], b[i]))\n  }\n  return r\n}\n},{\"robust-sum\":515,\"two-product\":543}],508:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar twoProduct = _dereq_(\"two-product\")\nvar robustSum = _dereq_(\"robust-sum\")\nvar robustDiff = _dereq_(\"robust-subtract\")\nvar robustScale = _dereq_(\"robust-scale\")\n\nvar NUM_EXPAND = 6\n\nfunction cofactor(m, c) {\n  var result = new Array(m.length-1)\n  for(var i=1; i<m.length; ++i) {\n    var r = result[i-1] = new Array(m.length-1)\n    for(var j=0,k=0; j<m.length; ++j) {\n      if(j === c) {\n        continue\n      }\n      r[k++] = m[i][j]\n    }\n  }\n  return result\n}\n\nfunction matrix(n) {\n  var result = new Array(n)\n  for(var i=0; i<n; ++i) {\n    result[i] = new Array(n)\n    for(var j=0; j<n; ++j) {\n      result[i][j] = [\"m\", j, \"[\", (n-i-2), \"]\"].join(\"\")\n    }\n  }\n  return result\n}\n\nfunction generateSum(expr) {\n  if(expr.length === 1) {\n    return expr[0]\n  } else if(expr.length === 2) {\n    return [\"sum(\", expr[0], \",\", expr[1], \")\"].join(\"\")\n  } else {\n    var m = expr.length>>1\n    return [\"sum(\", generateSum(expr.slice(0, m)), \",\", generateSum(expr.slice(m)), \")\"].join(\"\")\n  }\n}\n\nfunction makeProduct(a, b) {\n  if(a.charAt(0) === \"m\") {\n    if(b.charAt(0) === \"w\") {\n      var toks = a.split(\"[\")\n      return [\"w\", b.substr(1), \"m\", toks[0].substr(1)].join(\"\")\n    } else {\n      return [\"prod(\", a, \",\", b, \")\"].join(\"\")\n    }\n  } else {\n    return makeProduct(b, a)\n  }\n}\n\nfunction sign(s) {\n  if(s & 1 !== 0) {\n    return \"-\"\n  }\n  return \"\"\n}\n\nfunction determinant(m) {\n  if(m.length === 2) {\n    return [[\"diff(\", makeProduct(m[0][0], m[1][1]), \",\", makeProduct(m[1][0], m[0][1]), \")\"].join(\"\")]\n  } else {\n    var expr = []\n    for(var i=0; i<m.length; ++i) {\n      expr.push([\"scale(\", generateSum(determinant(cofactor(m, i))), \",\", sign(i), m[0][i], \")\"].join(\"\"))\n    }\n    return expr\n  }\n}\n\nfunction makeSquare(d, n) {\n  var terms = []\n  for(var i=0; i<n-2; ++i) {\n    terms.push([\"prod(m\", d, \"[\", i, \"],m\", d, \"[\", i, \"])\"].join(\"\"))\n  }\n  return generateSum(terms)\n}\n\nfunction orientation(n) {\n  var pos = []\n  var neg = []\n  var m = matrix(n)\n  for(var i=0; i<n; ++i) {\n    m[0][i] = \"1\"\n    m[n-1][i] = \"w\"+i\n  } \n  for(var i=0; i<n; ++i) {\n    if((i&1)===0) {\n      pos.push.apply(pos,determinant(cofactor(m, i)))\n    } else {\n      neg.push.apply(neg,determinant(cofactor(m, i)))\n    }\n  }\n  var posExpr = generateSum(pos)\n  var negExpr = generateSum(neg)\n  var funcName = \"exactInSphere\" + n\n  var funcArgs = []\n  for(var i=0; i<n; ++i) {\n    funcArgs.push(\"m\" + i)\n  }\n  var code = [\"function \", funcName, \"(\", funcArgs.join(), \"){\"]\n  for(var i=0; i<n; ++i) {\n    code.push(\"var w\",i,\"=\",makeSquare(i,n),\";\")\n    for(var j=0; j<n; ++j) {\n      if(j !== i) {\n        code.push(\"var w\",i,\"m\",j,\"=scale(w\",i,\",m\",j,\"[0]);\")\n      }\n    }\n  }\n  code.push(\"var p=\", posExpr, \",n=\", negExpr, \",d=diff(p,n);return d[d.length-1];}return \", funcName)\n  var proc = new Function(\"sum\", \"diff\", \"prod\", \"scale\", code.join(\"\"))\n  return proc(robustSum, robustDiff, twoProduct, robustScale)\n}\n\nfunction inSphere0() { return 0 }\nfunction inSphere1() { return 0 }\nfunction inSphere2() { return 0 }\n\nvar CACHED = [\n  inSphere0,\n  inSphere1,\n  inSphere2\n]\n\nfunction slowInSphere(args) {\n  var proc = CACHED[args.length]\n  if(!proc) {\n    proc = CACHED[args.length] = orientation(args.length)\n  }\n  return proc.apply(undefined, args)\n}\n\nfunction generateInSphereTest() {\n  while(CACHED.length <= NUM_EXPAND) {\n    CACHED.push(orientation(CACHED.length))\n  }\n  var args = []\n  var procArgs = [\"slow\"]\n  for(var i=0; i<=NUM_EXPAND; ++i) {\n    args.push(\"a\" + i)\n    procArgs.push(\"o\" + i)\n  }\n  var code = [\n    \"function testInSphere(\", args.join(), \"){switch(arguments.length){case 0:case 1:return 0;\"\n  ]\n  for(var i=2; i<=NUM_EXPAND; ++i) {\n    code.push(\"case \", i, \":return o\", i, \"(\", args.slice(0, i).join(), \");\")\n  }\n  code.push(\"}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return testInSphere\")\n  procArgs.push(code.join(\"\"))\n\n  var proc = Function.apply(undefined, procArgs)\n\n  module.exports = proc.apply(undefined, [slowInSphere].concat(CACHED))\n  for(var i=0; i<=NUM_EXPAND; ++i) {\n    module.exports[i] = CACHED[i]\n  }\n}\n\ngenerateInSphereTest()\n},{\"robust-scale\":512,\"robust-subtract\":514,\"robust-sum\":515,\"two-product\":543}],509:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar determinant = _dereq_(\"robust-determinant\")\n\nvar NUM_EXPAND = 6\n\nfunction generateSolver(n) {\n  var funcName = \"robustLinearSolve\" + n + \"d\"\n  var code = [\"function \", funcName, \"(A,b){return [\"]\n  for(var i=0; i<n; ++i) {\n    code.push(\"det([\")\n    for(var j=0; j<n; ++j) {\n      if(j > 0) {\n        code.push(\",\")\n      }\n      code.push(\"[\")\n      for(var k=0; k<n; ++k) {\n        if(k > 0) {\n          code.push(\",\")\n        }\n        if(k === i) {\n          code.push(\"+b[\", j, \"]\")\n        } else {\n          code.push(\"+A[\", j, \"][\", k, \"]\")\n        }\n      }\n      code.push(\"]\")\n    }\n    code.push(\"]),\")\n  }\n  code.push(\"det(A)]}return \", funcName)\n  var proc = new Function(\"det\", code.join(\"\"))\n  if(n < 6) {\n    return proc(determinant[n])\n  }\n  return proc(determinant)\n}\n\nfunction robustLinearSolve0d() {\n  return [ 0 ]\n}\n\nfunction robustLinearSolve1d(A, b) {\n  return [ [ b[0] ], [ A[0][0] ] ]\n}\n\nvar CACHE = [\n  robustLinearSolve0d,\n  robustLinearSolve1d\n]\n\nfunction generateDispatch() {\n  while(CACHE.length < NUM_EXPAND) {\n    CACHE.push(generateSolver(CACHE.length))\n  }\n  var procArgs = []\n  var code = [\"function dispatchLinearSolve(A,b){switch(A.length){\"]\n  for(var i=0; i<NUM_EXPAND; ++i) {\n    procArgs.push(\"s\" + i)\n    code.push(\"case \", i, \":return s\", i, \"(A,b);\")\n  }\n  code.push(\"}var s=CACHE[A.length];if(!s)s=CACHE[A.length]=g(A.length);return s(A,b)}return dispatchLinearSolve\")\n  procArgs.push(\"CACHE\", \"g\", code.join(\"\"))\n  var proc = Function.apply(undefined, procArgs)\n  module.exports = proc.apply(undefined, CACHE.concat([CACHE, generateSolver]))\n  for(var i=0; i<NUM_EXPAND; ++i) {\n    module.exports[i] = CACHE[i]\n  }\n}\n\ngenerateDispatch()\n},{\"robust-determinant\":506}],510:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar twoProduct = _dereq_(\"two-product\")\nvar robustSum = _dereq_(\"robust-sum\")\nvar robustScale = _dereq_(\"robust-scale\")\nvar robustSubtract = _dereq_(\"robust-subtract\")\n\nvar NUM_EXPAND = 5\n\nvar EPSILON     = 1.1102230246251565e-16\nvar ERRBOUND3   = (3.0 + 16.0 * EPSILON) * EPSILON\nvar ERRBOUND4   = (7.0 + 56.0 * EPSILON) * EPSILON\n\nfunction cofactor(m, c) {\n  var result = new Array(m.length-1)\n  for(var i=1; i<m.length; ++i) {\n    var r = result[i-1] = new Array(m.length-1)\n    for(var j=0,k=0; j<m.length; ++j) {\n      if(j === c) {\n        continue\n      }\n      r[k++] = m[i][j]\n    }\n  }\n  return result\n}\n\nfunction matrix(n) {\n  var result = new Array(n)\n  for(var i=0; i<n; ++i) {\n    result[i] = new Array(n)\n    for(var j=0; j<n; ++j) {\n      result[i][j] = [\"m\", j, \"[\", (n-i-1), \"]\"].join(\"\")\n    }\n  }\n  return result\n}\n\nfunction sign(n) {\n  if(n & 1) {\n    return \"-\"\n  }\n  return \"\"\n}\n\nfunction generateSum(expr) {\n  if(expr.length === 1) {\n    return expr[0]\n  } else if(expr.length === 2) {\n    return [\"sum(\", expr[0], \",\", expr[1], \")\"].join(\"\")\n  } else {\n    var m = expr.length>>1\n    return [\"sum(\", generateSum(expr.slice(0, m)), \",\", generateSum(expr.slice(m)), \")\"].join(\"\")\n  }\n}\n\nfunction determinant(m) {\n  if(m.length === 2) {\n    return [[\"sum(prod(\", m[0][0], \",\", m[1][1], \"),prod(-\", m[0][1], \",\", m[1][0], \"))\"].join(\"\")]\n  } else {\n    var expr = []\n    for(var i=0; i<m.length; ++i) {\n      expr.push([\"scale(\", generateSum(determinant(cofactor(m, i))), \",\", sign(i), m[0][i], \")\"].join(\"\"))\n    }\n    return expr\n  }\n}\n\nfunction orientation(n) {\n  var pos = []\n  var neg = []\n  var m = matrix(n)\n  var args = []\n  for(var i=0; i<n; ++i) {\n    if((i&1)===0) {\n      pos.push.apply(pos, determinant(cofactor(m, i)))\n    } else {\n      neg.push.apply(neg, determinant(cofactor(m, i)))\n    }\n    args.push(\"m\" + i)\n  }\n  var posExpr = generateSum(pos)\n  var negExpr = generateSum(neg)\n  var funcName = \"orientation\" + n + \"Exact\"\n  var code = [\"function \", funcName, \"(\", args.join(), \"){var p=\", posExpr, \",n=\", negExpr, \",d=sub(p,n);\\\nreturn d[d.length-1];};return \", funcName].join(\"\")\n  var proc = new Function(\"sum\", \"prod\", \"scale\", \"sub\", code)\n  return proc(robustSum, twoProduct, robustScale, robustSubtract)\n}\n\nvar orientation3Exact = orientation(3)\nvar orientation4Exact = orientation(4)\n\nvar CACHED = [\n  function orientation0() { return 0 },\n  function orientation1() { return 0 },\n  function orientation2(a, b) { \n    return b[0] - a[0]\n  },\n  function orientation3(a, b, c) {\n    var l = (a[1] - c[1]) * (b[0] - c[0])\n    var r = (a[0] - c[0]) * (b[1] - c[1])\n    var det = l - r\n    var s\n    if(l > 0) {\n      if(r <= 0) {\n        return det\n      } else {\n        s = l + r\n      }\n    } else if(l < 0) {\n      if(r >= 0) {\n        return det\n      } else {\n        s = -(l + r)\n      }\n    } else {\n      return det\n    }\n    var tol = ERRBOUND3 * s\n    if(det >= tol || det <= -tol) {\n      return det\n    }\n    return orientation3Exact(a, b, c)\n  },\n  function orientation4(a,b,c,d) {\n    var adx = a[0] - d[0]\n    var bdx = b[0] - d[0]\n    var cdx = c[0] - d[0]\n    var ady = a[1] - d[1]\n    var bdy = b[1] - d[1]\n    var cdy = c[1] - d[1]\n    var adz = a[2] - d[2]\n    var bdz = b[2] - d[2]\n    var cdz = c[2] - d[2]\n    var bdxcdy = bdx * cdy\n    var cdxbdy = cdx * bdy\n    var cdxady = cdx * ady\n    var adxcdy = adx * cdy\n    var adxbdy = adx * bdy\n    var bdxady = bdx * ady\n    var det = adz * (bdxcdy - cdxbdy) \n            + bdz * (cdxady - adxcdy)\n            + cdz * (adxbdy - bdxady)\n    var permanent = (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz)\n                  + (Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz)\n                  + (Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz)\n    var tol = ERRBOUND4 * permanent\n    if ((det > tol) || (-det > tol)) {\n      return det\n    }\n    return orientation4Exact(a,b,c,d)\n  }\n]\n\nfunction slowOrient(args) {\n  var proc = CACHED[args.length]\n  if(!proc) {\n    proc = CACHED[args.length] = orientation(args.length)\n  }\n  return proc.apply(undefined, args)\n}\n\nfunction generateOrientationProc() {\n  while(CACHED.length <= NUM_EXPAND) {\n    CACHED.push(orientation(CACHED.length))\n  }\n  var args = []\n  var procArgs = [\"slow\"]\n  for(var i=0; i<=NUM_EXPAND; ++i) {\n    args.push(\"a\" + i)\n    procArgs.push(\"o\" + i)\n  }\n  var code = [\n    \"function getOrientation(\", args.join(), \"){switch(arguments.length){case 0:case 1:return 0;\"\n  ]\n  for(var i=2; i<=NUM_EXPAND; ++i) {\n    code.push(\"case \", i, \":return o\", i, \"(\", args.slice(0, i).join(), \");\")\n  }\n  code.push(\"}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation\")\n  procArgs.push(code.join(\"\"))\n\n  var proc = Function.apply(undefined, procArgs)\n  module.exports = proc.apply(undefined, [slowOrient].concat(CACHED))\n  for(var i=0; i<=NUM_EXPAND; ++i) {\n    module.exports[i] = CACHED[i]\n  }\n}\n\ngenerateOrientationProc()\n},{\"robust-scale\":512,\"robust-subtract\":514,\"robust-sum\":515,\"two-product\":543}],511:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar robustSum = _dereq_(\"robust-sum\")\nvar robustScale = _dereq_(\"robust-scale\")\n\nmodule.exports = robustProduct\n\nfunction robustProduct(a, b) {\n  if(a.length === 1) {\n    return robustScale(b, a[0])\n  }\n  if(b.length === 1) {\n    return robustScale(a, b[0])\n  }\n  if(a.length === 0 || b.length === 0) {\n    return [0]\n  }\n  var r = [0]\n  if(a.length < b.length) {\n    for(var i=0; i<a.length; ++i) {\n      r = robustSum(r, robustScale(b, a[i]))\n    }\n  } else {\n    for(var i=0; i<b.length; ++i) {\n      r = robustSum(r, robustScale(a, b[i]))\n    }    \n  }\n  return r\n}\n},{\"robust-scale\":512,\"robust-sum\":515}],512:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar twoProduct = _dereq_(\"two-product\")\nvar twoSum = _dereq_(\"two-sum\")\n\nmodule.exports = scaleLinearExpansion\n\nfunction scaleLinearExpansion(e, scale) {\n  var n = e.length\n  if(n === 1) {\n    var ts = twoProduct(e[0], scale)\n    if(ts[0]) {\n      return ts\n    }\n    return [ ts[1] ]\n  }\n  var g = new Array(2 * n)\n  var q = [0.1, 0.1]\n  var t = [0.1, 0.1]\n  var count = 0\n  twoProduct(e[0], scale, q)\n  if(q[0]) {\n    g[count++] = q[0]\n  }\n  for(var i=1; i<n; ++i) {\n    twoProduct(e[i], scale, t)\n    var pq = q[1]\n    twoSum(pq, t[0], q)\n    if(q[0]) {\n      g[count++] = q[0]\n    }\n    var a = t[1]\n    var b = q[1]\n    var x = a + b\n    var bv = x - a\n    var y = b - bv\n    q[1] = x\n    if(y) {\n      g[count++] = y\n    }\n  }\n  if(q[1]) {\n    g[count++] = q[1]\n  }\n  if(count === 0) {\n    g[count++] = 0.0\n  }\n  g.length = count\n  return g\n}\n},{\"two-product\":543,\"two-sum\":544}],513:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = segmentsIntersect\n\nvar orient = _dereq_(\"robust-orientation\")[3]\n\nfunction checkCollinear(a0, a1, b0, b1) {\n\n  for(var d=0; d<2; ++d) {\n    var x0 = a0[d]\n    var y0 = a1[d]\n    var l0 = Math.min(x0, y0)\n    var h0 = Math.max(x0, y0)    \n\n    var x1 = b0[d]\n    var y1 = b1[d]\n    var l1 = Math.min(x1, y1)\n    var h1 = Math.max(x1, y1)    \n\n    if(h1 < l0 || h0 < l1) {\n      return false\n    }\n  }\n\n  return true\n}\n\nfunction segmentsIntersect(a0, a1, b0, b1) {\n  var x0 = orient(a0, b0, b1)\n  var y0 = orient(a1, b0, b1)\n  if((x0 > 0 && y0 > 0) || (x0 < 0 && y0 < 0)) {\n    return false\n  }\n\n  var x1 = orient(b0, a0, a1)\n  var y1 = orient(b1, a0, a1)\n  if((x1 > 0 && y1 > 0) || (x1 < 0 && y1 < 0)) {\n    return false\n  }\n\n  //Check for degenerate collinear case\n  if(x0 === 0 && y0 === 0 && x1 === 0 && y1 === 0) {\n    return checkCollinear(a0, a1, b0, b1)\n  }\n\n  return true\n}\n},{\"robust-orientation\":510}],514:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = robustSubtract\n\n//Easy case: Add two scalars\nfunction scalarScalar(a, b) {\n  var x = a + b\n  var bv = x - a\n  var av = x - bv\n  var br = b - bv\n  var ar = a - av\n  var y = ar + br\n  if(y) {\n    return [y, x]\n  }\n  return [x]\n}\n\nfunction robustSubtract(e, f) {\n  var ne = e.length|0\n  var nf = f.length|0\n  if(ne === 1 && nf === 1) {\n    return scalarScalar(e[0], -f[0])\n  }\n  var n = ne + nf\n  var g = new Array(n)\n  var count = 0\n  var eptr = 0\n  var fptr = 0\n  var abs = Math.abs\n  var ei = e[eptr]\n  var ea = abs(ei)\n  var fi = -f[fptr]\n  var fa = abs(fi)\n  var a, b\n  if(ea < fa) {\n    b = ei\n    eptr += 1\n    if(eptr < ne) {\n      ei = e[eptr]\n      ea = abs(ei)\n    }\n  } else {\n    b = fi\n    fptr += 1\n    if(fptr < nf) {\n      fi = -f[fptr]\n      fa = abs(fi)\n    }\n  }\n  if((eptr < ne && ea < fa) || (fptr >= nf)) {\n    a = ei\n    eptr += 1\n    if(eptr < ne) {\n      ei = e[eptr]\n      ea = abs(ei)\n    }\n  } else {\n    a = fi\n    fptr += 1\n    if(fptr < nf) {\n      fi = -f[fptr]\n      fa = abs(fi)\n    }\n  }\n  var x = a + b\n  var bv = x - a\n  var y = b - bv\n  var q0 = y\n  var q1 = x\n  var _x, _bv, _av, _br, _ar\n  while(eptr < ne && fptr < nf) {\n    if(ea < fa) {\n      a = ei\n      eptr += 1\n      if(eptr < ne) {\n        ei = e[eptr]\n        ea = abs(ei)\n      }\n    } else {\n      a = fi\n      fptr += 1\n      if(fptr < nf) {\n        fi = -f[fptr]\n        fa = abs(fi)\n      }\n    }\n    b = q0\n    x = a + b\n    bv = x - a\n    y = b - bv\n    if(y) {\n      g[count++] = y\n    }\n    _x = q1 + x\n    _bv = _x - q1\n    _av = _x - _bv\n    _br = x - _bv\n    _ar = q1 - _av\n    q0 = _ar + _br\n    q1 = _x\n  }\n  while(eptr < ne) {\n    a = ei\n    b = q0\n    x = a + b\n    bv = x - a\n    y = b - bv\n    if(y) {\n      g[count++] = y\n    }\n    _x = q1 + x\n    _bv = _x - q1\n    _av = _x - _bv\n    _br = x - _bv\n    _ar = q1 - _av\n    q0 = _ar + _br\n    q1 = _x\n    eptr += 1\n    if(eptr < ne) {\n      ei = e[eptr]\n    }\n  }\n  while(fptr < nf) {\n    a = fi\n    b = q0\n    x = a + b\n    bv = x - a\n    y = b - bv\n    if(y) {\n      g[count++] = y\n    } \n    _x = q1 + x\n    _bv = _x - q1\n    _av = _x - _bv\n    _br = x - _bv\n    _ar = q1 - _av\n    q0 = _ar + _br\n    q1 = _x\n    fptr += 1\n    if(fptr < nf) {\n      fi = -f[fptr]\n    }\n  }\n  if(q0) {\n    g[count++] = q0\n  }\n  if(q1) {\n    g[count++] = q1\n  }\n  if(!count) {\n    g[count++] = 0.0  \n  }\n  g.length = count\n  return g\n}\n},{}],515:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = linearExpansionSum\n\n//Easy case: Add two scalars\nfunction scalarScalar(a, b) {\n  var x = a + b\n  var bv = x - a\n  var av = x - bv\n  var br = b - bv\n  var ar = a - av\n  var y = ar + br\n  if(y) {\n    return [y, x]\n  }\n  return [x]\n}\n\nfunction linearExpansionSum(e, f) {\n  var ne = e.length|0\n  var nf = f.length|0\n  if(ne === 1 && nf === 1) {\n    return scalarScalar(e[0], f[0])\n  }\n  var n = ne + nf\n  var g = new Array(n)\n  var count = 0\n  var eptr = 0\n  var fptr = 0\n  var abs = Math.abs\n  var ei = e[eptr]\n  var ea = abs(ei)\n  var fi = f[fptr]\n  var fa = abs(fi)\n  var a, b\n  if(ea < fa) {\n    b = ei\n    eptr += 1\n    if(eptr < ne) {\n      ei = e[eptr]\n      ea = abs(ei)\n    }\n  } else {\n    b = fi\n    fptr += 1\n    if(fptr < nf) {\n      fi = f[fptr]\n      fa = abs(fi)\n    }\n  }\n  if((eptr < ne && ea < fa) || (fptr >= nf)) {\n    a = ei\n    eptr += 1\n    if(eptr < ne) {\n      ei = e[eptr]\n      ea = abs(ei)\n    }\n  } else {\n    a = fi\n    fptr += 1\n    if(fptr < nf) {\n      fi = f[fptr]\n      fa = abs(fi)\n    }\n  }\n  var x = a + b\n  var bv = x - a\n  var y = b - bv\n  var q0 = y\n  var q1 = x\n  var _x, _bv, _av, _br, _ar\n  while(eptr < ne && fptr < nf) {\n    if(ea < fa) {\n      a = ei\n      eptr += 1\n      if(eptr < ne) {\n        ei = e[eptr]\n        ea = abs(ei)\n      }\n    } else {\n      a = fi\n      fptr += 1\n      if(fptr < nf) {\n        fi = f[fptr]\n        fa = abs(fi)\n      }\n    }\n    b = q0\n    x = a + b\n    bv = x - a\n    y = b - bv\n    if(y) {\n      g[count++] = y\n    }\n    _x = q1 + x\n    _bv = _x - q1\n    _av = _x - _bv\n    _br = x - _bv\n    _ar = q1 - _av\n    q0 = _ar + _br\n    q1 = _x\n  }\n  while(eptr < ne) {\n    a = ei\n    b = q0\n    x = a + b\n    bv = x - a\n    y = b - bv\n    if(y) {\n      g[count++] = y\n    }\n    _x = q1 + x\n    _bv = _x - q1\n    _av = _x - _bv\n    _br = x - _bv\n    _ar = q1 - _av\n    q0 = _ar + _br\n    q1 = _x\n    eptr += 1\n    if(eptr < ne) {\n      ei = e[eptr]\n    }\n  }\n  while(fptr < nf) {\n    a = fi\n    b = q0\n    x = a + b\n    bv = x - a\n    y = b - bv\n    if(y) {\n      g[count++] = y\n    } \n    _x = q1 + x\n    _bv = _x - q1\n    _av = _x - _bv\n    _br = x - _bv\n    _ar = q1 - _av\n    q0 = _ar + _br\n    q1 = _x\n    fptr += 1\n    if(fptr < nf) {\n      fi = f[fptr]\n    }\n  }\n  if(q0) {\n    g[count++] = q0\n  }\n  if(q1) {\n    g[count++] = q1\n  }\n  if(!count) {\n    g[count++] = 0.0  \n  }\n  g.length = count\n  return g\n}\n},{}],516:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = function signum(x) {\n  if(x < 0) { return -1 }\n  if(x > 0) { return 1 }\n  return 0.0\n}\n},{}],517:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = boundary\n\nvar bnd = _dereq_('boundary-cells')\nvar reduce = _dereq_('reduce-simplicial-complex')\n\nfunction boundary(cells) {\n  return reduce(bnd(cells))\n}\n\n},{\"boundary-cells\":95,\"reduce-simplicial-complex\":489}],518:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = extractContour\n\nvar ndarray = _dereq_('ndarray')\nvar pool    = _dereq_('typedarray-pool')\nvar ndsort  = _dereq_('ndarray-sort')\n\nvar contourAlgorithm = _dereq_('./lib/codegen')\n\nfunction getDimension(cells) {\n  var numCells = cells.length\n  var d = 0\n  for(var i=0; i<numCells; ++i) {\n    d = Math.max(d, cells[i].length)|0\n  }\n  return d-1\n}\n\nfunction getSigns(values, level) {\n  var numVerts    = values.length\n  var vertexSigns = pool.mallocUint8(numVerts)\n  for(var i=0; i<numVerts; ++i) {\n    vertexSigns[i] = (values[i] < level)|0\n  }\n  return vertexSigns\n}\n\nfunction getEdges(cells, d) {\n  var numCells = cells.length\n  var maxEdges = ((d * (d+1)/2) * numCells)|0\n  var edges    = pool.mallocUint32(maxEdges*2)\n  var ePtr     = 0\n  for(var i=0; i<numCells; ++i) {\n    var c = cells[i]\n    var d = c.length\n    for(var j=0; j<d; ++j) {\n      for(var k=0; k<j; ++k) {\n        var a = c[k]\n        var b = c[j]\n        edges[ePtr++] = Math.min(a,b)|0\n        edges[ePtr++] = Math.max(a,b)|0\n      }\n    }\n  }\n  var nedges = (ePtr/2)|0\n  ndsort(ndarray(edges, [nedges,2])) \n  var ptr = 2\n  for(var i=2; i<ePtr; i+=2) {\n    if(edges[i-2] === edges[i] &&\n       edges[i-1] === edges[i+1]) {\n      continue\n    }\n    edges[ptr++] = edges[i]\n    edges[ptr++] = edges[i+1]\n  }\n\n  return ndarray(edges, [(ptr/2)|0, 2])\n}\n\nfunction getCrossingWeights(edges, values, signs, level) {\n  var edata     = edges.data\n  var numEdges  = edges.shape[0]\n  var weights   = pool.mallocDouble(numEdges)\n  var ptr       = 0\n  for(var i=0; i<numEdges; ++i) {\n    var a  = edata[2*i]\n    var b  = edata[2*i+1]\n    if(signs[a] === signs[b]) {\n      continue\n    }\n    var va = values[a]\n    var vb = values[b]\n    edata[2*ptr]     = a\n    edata[2*ptr+1]   = b\n    weights[ptr++]   = (vb - level) / (vb - va)\n  }\n  edges.shape[0] = ptr\n  return ndarray(weights, [ptr])\n}\n\nfunction getCascade(edges, numVerts) {\n  var result   = pool.mallocInt32(numVerts*2)\n  var numEdges = edges.shape[0]\n  var edata    = edges.data\n  result[0]    = 0\n  var lastV    = 0\n  for(var i=0; i<numEdges; ++i) {\n    var a = edata[2*i]\n    if(a !== lastV) {\n      result[2*lastV+1] = i\n      while(++lastV < a) {\n        result[2*lastV] = i\n        result[2*lastV+1] = i\n      }\n      result[2*lastV] = i\n    }\n  }\n  result[2*lastV+1] = numEdges\n  while(++lastV < numVerts) {\n    result[2*lastV] = result[2*lastV+1] = numEdges\n  }\n  return result\n}\n\nfunction unpackEdges(edges) {\n  var ne = edges.shape[0]|0\n  var edata = edges.data\n  var result = new Array(ne)\n  for(var i=0; i<ne; ++i) {\n    result[i] = [edata[2*i], edata[2*i+1]]\n  }\n  return result\n}\n\nfunction extractContour(cells, values, level, d) {\n  level = level||0.0\n\n  //If user didn't specify `d`, use brute force scan\n  if(typeof d === 'undefined') {\n    d = getDimension(cells)\n  }\n\n  //Count number of cells\n  var numCells = cells.length\n  if(numCells === 0 || d < 1) {\n    return {\n      cells:         [],\n      vertexIds:     [],\n      vertexWeights: []\n    }\n  }\n\n  //Read in vertex signs\n  var vertexSigns = getSigns(values, +level)\n\n  //First get 1-skeleton, find all crossings\n  var edges   = getEdges(cells, d)\n  var weights = getCrossingWeights(edges, values, vertexSigns, +level)\n\n  //Build vertex cascade to speed up binary search\n  var vcascade = getCascade(edges, values.length|0)\n\n  //Then construct cells\n  var faces = contourAlgorithm(d)(cells, edges.data, vcascade, vertexSigns)\n\n  //Unpack data into pretty format\n  var uedges   = unpackEdges(edges)\n  var uweights = [].slice.call(weights.data, 0, weights.shape[0])\n\n  //Release data\n  pool.free(vertexSigns)\n  pool.free(edges.data)\n  pool.free(weights.data)\n  pool.free(vcascade)\n  \n  return {\n    cells:         faces,\n    vertexIds:     uedges,\n    vertexWeights: uweights\n  }\n}\n},{\"./lib/codegen\":519,\"ndarray\":450,\"ndarray-sort\":448,\"typedarray-pool\":545}],519:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = getPolygonizer\n\nvar pool = _dereq_('typedarray-pool')\nvar createMSTable = _dereq_('marching-simplex-table')\n\nvar CACHE = {}\n\nfunction createCellPolygonizer(d) {\n  var maxCellSize = 0\n  var tables = new Array(d+1)\n  tables[0] = [ [] ]\n  for(var i=1; i<=d; ++i) {\n    var tab = tables[i] = createMSTable(i)\n    for(var j=0; j<tab.length; ++j) {\n      maxCellSize = Math.max(maxCellSize, tab[i].length)\n    }\n  }\n\n  var code  = [\n  'function B(C,E,i,j){',\n    'var a=Math.min(i,j)|0,b=Math.max(i,j)|0,l=C[2*a],h=C[2*a+1];',\n    'while(l<h){',\n      'var m=(l+h)>>1,v=E[2*m+1];',\n      'if(v===b){return m}',\n      'if(b<v){h=m}else{l=m+1}',\n    '}',\n    'return l;',\n  '};',\n  'function getContour', d, 'd(F,E,C,S){',\n    'var n=F.length,R=[];',\n    'for(var i=0;i<n;++i){var c=F[i],l=c.length;'\n  ]\n\n  function generateCase(facets) {\n    if(facets.length <= 0) {\n      return\n    }\n    code.push('R.push(')\n    for(var i=0; i<facets.length; ++i) {\n      var facet = facets[i]\n      if(i > 0) {\n        code.push(',')\n      }\n      code.push('[')\n      for(var j=0; j<facet.length; ++j) {\n        var f = facet[j]\n        if(j > 0) {\n          code.push(',')\n        }\n        code.push('B(C,E,c[', f[0], '],c[', f[1], '])')\n      }\n      code.push(']')\n    }\n    code.push(');')\n  }\n\n  for(var i=d+1; i>1; --i) {\n    if(i < d+1) {\n      code.push('else ')\n    }\n    code.push('if(l===', i, '){')\n\n    //Generate mask\n    var maskStr = []\n    for(var j=0; j<i; ++j) {\n      maskStr.push('(S[c['+j+']]<<'+j+')')\n    }\n\n    //Perform table look up\n    code.push('var M=', maskStr.join('+'), \n      ';if(M===0||M===', (1<<i)-1, \n        '){continue}switch(M){')\n\n    var tab = tables[i-1]\n    for(var j=0; j<tab.length; ++j) {\n      code.push('case ', j, ':')\n      generateCase(tab[j])\n      code.push('break;')\n    }\n    code.push('}}')\n  }\n  code.push('}return R;};return getContour', d, 'd')\n\n  var proc = new Function('pool', code.join(''))\n  return proc(pool)\n}\n\nfunction getPolygonizer(d) {\n  var alg = CACHE[d]\n  if(!alg) {\n    alg = CACHE[d] = createCellPolygonizer(d) \n  }\n  return alg\n}\n},{\"marching-simplex-table\":427,\"typedarray-pool\":545}],520:[function(_dereq_,module,exports){\n\"use strict\"; \"use restrict\";\n\nvar bits      = _dereq_(\"bit-twiddle\")\n  , UnionFind = _dereq_(\"union-find\")\n\n//Returns the dimension of a cell complex\nfunction dimension(cells) {\n  var d = 0\n    , max = Math.max\n  for(var i=0, il=cells.length; i<il; ++i) {\n    d = max(d, cells[i].length)\n  }\n  return d-1\n}\nexports.dimension = dimension\n\n//Counts the number of vertices in faces\nfunction countVertices(cells) {\n  var vc = -1\n    , max = Math.max\n  for(var i=0, il=cells.length; i<il; ++i) {\n    var c = cells[i]\n    for(var j=0, jl=c.length; j<jl; ++j) {\n      vc = max(vc, c[j])\n    }\n  }\n  return vc+1\n}\nexports.countVertices = countVertices\n\n//Returns a deep copy of cells\nfunction cloneCells(cells) {\n  var ncells = new Array(cells.length)\n  for(var i=0, il=cells.length; i<il; ++i) {\n    ncells[i] = cells[i].slice(0)\n  }\n  return ncells\n}\nexports.cloneCells = cloneCells\n\n//Ranks a pair of cells up to permutation\nfunction compareCells(a, b) {\n  var n = a.length\n    , t = a.length - b.length\n    , min = Math.min\n  if(t) {\n    return t\n  }\n  switch(n) {\n    case 0:\n      return 0;\n    case 1:\n      return a[0] - b[0];\n    case 2:\n      var d = a[0]+a[1]-b[0]-b[1]\n      if(d) {\n        return d\n      }\n      return min(a[0],a[1]) - min(b[0],b[1])\n    case 3:\n      var l1 = a[0]+a[1]\n        , m1 = b[0]+b[1]\n      d = l1+a[2] - (m1+b[2])\n      if(d) {\n        return d\n      }\n      var l0 = min(a[0], a[1])\n        , m0 = min(b[0], b[1])\n        , d  = min(l0, a[2]) - min(m0, b[2])\n      if(d) {\n        return d\n      }\n      return min(l0+a[2], l1) - min(m0+b[2], m1)\n    \n    //TODO: Maybe optimize n=4 as well?\n    \n    default:\n      var as = a.slice(0)\n      as.sort()\n      var bs = b.slice(0)\n      bs.sort()\n      for(var i=0; i<n; ++i) {\n        t = as[i] - bs[i]\n        if(t) {\n          return t\n        }\n      }\n      return 0\n  }\n}\nexports.compareCells = compareCells\n\nfunction compareZipped(a, b) {\n  return compareCells(a[0], b[0])\n}\n\n//Puts a cell complex into normal order for the purposes of findCell queries\nfunction normalize(cells, attr) {\n  if(attr) {\n    var len = cells.length\n    var zipped = new Array(len)\n    for(var i=0; i<len; ++i) {\n      zipped[i] = [cells[i], attr[i]]\n    }\n    zipped.sort(compareZipped)\n    for(var i=0; i<len; ++i) {\n      cells[i] = zipped[i][0]\n      attr[i] = zipped[i][1]\n    }\n    return cells\n  } else {\n    cells.sort(compareCells)\n    return cells\n  }\n}\nexports.normalize = normalize\n\n//Removes all duplicate cells in the complex\nfunction unique(cells) {\n  if(cells.length === 0) {\n    return []\n  }\n  var ptr = 1\n    , len = cells.length\n  for(var i=1; i<len; ++i) {\n    var a = cells[i]\n    if(compareCells(a, cells[i-1])) {\n      if(i === ptr) {\n        ptr++\n        continue\n      }\n      cells[ptr++] = a\n    }\n  }\n  cells.length = ptr\n  return cells\n}\nexports.unique = unique;\n\n//Finds a cell in a normalized cell complex\nfunction findCell(cells, c) {\n  var lo = 0\n    , hi = cells.length-1\n    , r  = -1\n  while (lo <= hi) {\n    var mid = (lo + hi) >> 1\n      , s   = compareCells(cells[mid], c)\n    if(s <= 0) {\n      if(s === 0) {\n        r = mid\n      }\n      lo = mid + 1\n    } else if(s > 0) {\n      hi = mid - 1\n    }\n  }\n  return r\n}\nexports.findCell = findCell;\n\n//Builds an index for an n-cell.  This is more general than dual, but less efficient\nfunction incidence(from_cells, to_cells) {\n  var index = new Array(from_cells.length)\n  for(var i=0, il=index.length; i<il; ++i) {\n    index[i] = []\n  }\n  var b = []\n  for(var i=0, n=to_cells.length; i<n; ++i) {\n    var c = to_cells[i]\n    var cl = c.length\n    for(var k=1, kn=(1<<cl); k<kn; ++k) {\n      b.length = bits.popCount(k)\n      var l = 0\n      for(var j=0; j<cl; ++j) {\n        if(k & (1<<j)) {\n          b[l++] = c[j]\n        }\n      }\n      var idx=findCell(from_cells, b)\n      if(idx < 0) {\n        continue\n      }\n      while(true) {\n        index[idx++].push(i)\n        if(idx >= from_cells.length || compareCells(from_cells[idx], b) !== 0) {\n          break\n        }\n      }\n    }\n  }\n  return index\n}\nexports.incidence = incidence\n\n//Computes the dual of the mesh.  This is basically an optimized version of buildIndex for the situation where from_cells is just the list of vertices\nfunction dual(cells, vertex_count) {\n  if(!vertex_count) {\n    return incidence(unique(skeleton(cells, 0)), cells, 0)\n  }\n  var res = new Array(vertex_count)\n  for(var i=0; i<vertex_count; ++i) {\n    res[i] = []\n  }\n  for(var i=0, len=cells.length; i<len; ++i) {\n    var c = cells[i]\n    for(var j=0, cl=c.length; j<cl; ++j) {\n      res[c[j]].push(i)\n    }\n  }\n  return res\n}\nexports.dual = dual\n\n//Enumerates all cells in the complex\nfunction explode(cells) {\n  var result = []\n  for(var i=0, il=cells.length; i<il; ++i) {\n    var c = cells[i]\n      , cl = c.length|0\n    for(var j=1, jl=(1<<cl); j<jl; ++j) {\n      var b = []\n      for(var k=0; k<cl; ++k) {\n        if((j >>> k) & 1) {\n          b.push(c[k])\n        }\n      }\n      result.push(b)\n    }\n  }\n  return normalize(result)\n}\nexports.explode = explode\n\n//Enumerates all of the n-cells of a cell complex\nfunction skeleton(cells, n) {\n  if(n < 0) {\n    return []\n  }\n  var result = []\n    , k0     = (1<<(n+1))-1\n  for(var i=0; i<cells.length; ++i) {\n    var c = cells[i]\n    for(var k=k0; k<(1<<c.length); k=bits.nextCombination(k)) {\n      var b = new Array(n+1)\n        , l = 0\n      for(var j=0; j<c.length; ++j) {\n        if(k & (1<<j)) {\n          b[l++] = c[j]\n        }\n      }\n      result.push(b)\n    }\n  }\n  return normalize(result)\n}\nexports.skeleton = skeleton;\n\n//Computes the boundary of all cells, does not remove duplicates\nfunction boundary(cells) {\n  var res = []\n  for(var i=0,il=cells.length; i<il; ++i) {\n    var c = cells[i]\n    for(var j=0,cl=c.length; j<cl; ++j) {\n      var b = new Array(c.length-1)\n      for(var k=0, l=0; k<cl; ++k) {\n        if(k !== j) {\n          b[l++] = c[k]\n        }\n      }\n      res.push(b)\n    }\n  }\n  return normalize(res)\n}\nexports.boundary = boundary;\n\n//Computes connected components for a dense cell complex\nfunction connectedComponents_dense(cells, vertex_count) {\n  var labels = new UnionFind(vertex_count)\n  for(var i=0; i<cells.length; ++i) {\n    var c = cells[i]\n    for(var j=0; j<c.length; ++j) {\n      for(var k=j+1; k<c.length; ++k) {\n        labels.link(c[j], c[k])\n      }\n    }\n  }\n  var components = []\n    , component_labels = labels.ranks\n  for(var i=0; i<component_labels.length; ++i) {\n    component_labels[i] = -1\n  }\n  for(var i=0; i<cells.length; ++i) {\n    var l = labels.find(cells[i][0])\n    if(component_labels[l] < 0) {\n      component_labels[l] = components.length\n      components.push([cells[i].slice(0)])\n    } else {\n      components[component_labels[l]].push(cells[i].slice(0))\n    }\n  }\n  return components\n}\n\n//Computes connected components for a sparse graph\nfunction connectedComponents_sparse(cells) {\n  var vertices  = unique(normalize(skeleton(cells, 0)))\n    , labels    = new UnionFind(vertices.length)\n  for(var i=0; i<cells.length; ++i) {\n    var c = cells[i]\n    for(var j=0; j<c.length; ++j) {\n      var vj = findCell(vertices, [c[j]])\n      for(var k=j+1; k<c.length; ++k) {\n        labels.link(vj, findCell(vertices, [c[k]]))\n      }\n    }\n  }\n  var components        = []\n    , component_labels  = labels.ranks\n  for(var i=0; i<component_labels.length; ++i) {\n    component_labels[i] = -1\n  }\n  for(var i=0; i<cells.length; ++i) {\n    var l = labels.find(findCell(vertices, [cells[i][0]]));\n    if(component_labels[l] < 0) {\n      component_labels[l] = components.length\n      components.push([cells[i].slice(0)])\n    } else {\n      components[component_labels[l]].push(cells[i].slice(0))\n    }\n  }\n  return components\n}\n\n//Computes connected components for a cell complex\nfunction connectedComponents(cells, vertex_count) {\n  if(vertex_count) {\n    return connectedComponents_dense(cells, vertex_count)\n  }\n  return connectedComponents_sparse(cells)\n}\nexports.connectedComponents = connectedComponents\n\n},{\"bit-twiddle\":92,\"union-find\":546}],521:[function(_dereq_,module,exports){\narguments[4][92][0].apply(exports,arguments)\n},{\"dup\":92}],522:[function(_dereq_,module,exports){\narguments[4][520][0].apply(exports,arguments)\n},{\"bit-twiddle\":521,\"dup\":520,\"union-find\":523}],523:[function(_dereq_,module,exports){\n\"use strict\"; \"use restrict\";\n\nmodule.exports = UnionFind;\n\nfunction UnionFind(count) {\n  this.roots = new Array(count);\n  this.ranks = new Array(count);\n  \n  for(var i=0; i<count; ++i) {\n    this.roots[i] = i;\n    this.ranks[i] = 0;\n  }\n}\n\nUnionFind.prototype.length = function() {\n  return this.roots.length;\n}\n\nUnionFind.prototype.makeSet = function() {\n  var n = this.roots.length;\n  this.roots.push(n);\n  this.ranks.push(0);\n  return n;\n}\n\nUnionFind.prototype.find = function(x) {\n  var roots = this.roots;\n  while(roots[x] !== x) {\n    var y = roots[x];\n    roots[x] = roots[y];\n    x = y;\n  }\n  return x;\n}\n\nUnionFind.prototype.link = function(x, y) {\n  var xr = this.find(x)\n    , yr = this.find(y);\n  if(xr === yr) {\n    return;\n  }\n  var ranks = this.ranks\n    , roots = this.roots\n    , xd    = ranks[xr]\n    , yd    = ranks[yr];\n  if(xd < yd) {\n    roots[xr] = yr;\n  } else if(yd < xd) {\n    roots[yr] = xr;\n  } else {\n    roots[yr] = xr;\n    ++ranks[xr];\n  }\n}\n\n\n},{}],524:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = simplifyPolygon\n\nvar orient = _dereq_(\"robust-orientation\")\nvar sc = _dereq_(\"simplicial-complex\")\n\nfunction errorWeight(base, a, b) {\n  var area = Math.abs(orient(base, a, b))\n  var perim = Math.sqrt(Math.pow(a[0] - b[0], 2) + Math.pow(a[1]-b[1], 2))\n  return area / perim\n}\n\nfunction simplifyPolygon(cells, positions, minArea) {\n\n  var n = positions.length\n  var nc = cells.length\n  var inv = new Array(n)\n  var outv = new Array(n)\n  var weights = new Array(n)\n  var dead = new Array(n)\n  \n  //Initialize tables\n  for(var i=0; i<n; ++i) {\n    inv[i] = outv[i] = -1\n    weights[i] = Infinity\n    dead[i] = false\n  }\n\n  //Compute neighbors\n  for(var i=0; i<nc; ++i) {\n    var c = cells[i]\n    if(c.length !== 2) {\n      throw new Error(\"Input must be a graph\")\n    }\n    var s = c[1]\n    var t = c[0]\n    if(outv[t] !== -1) {\n      outv[t] = -2\n    } else {\n      outv[t] = s\n    }\n    if(inv[s] !== -1) {\n      inv[s] = -2\n    } else {\n      inv[s] = t\n    }\n  }\n\n  //Updates the weight for vertex i\n  function computeWeight(i) {\n    if(dead[i]) {\n      return Infinity\n    }\n    //TODO: Check that the line segment doesn't cross once simplified\n    var s = inv[i]\n    var t = outv[i]\n    if((s<0) || (t<0)) {\n      return Infinity\n    } else {\n      return errorWeight(positions[i], positions[s], positions[t])\n    }\n  }\n\n  //Swaps two nodes on the heap (i,j) are the index of the nodes\n  function heapSwap(i,j) {\n    var a = heap[i]\n    var b = heap[j]\n    heap[i] = b\n    heap[j] = a\n    index[a] = j\n    index[b] = i\n  }\n\n  //Returns the weight of node i on the heap\n  function heapWeight(i) {\n    return weights[heap[i]]\n  }\n\n  function heapParent(i) {\n    if(i & 1) {\n      return (i - 1) >> 1\n    }\n    return (i >> 1) - 1\n  }\n\n  //Bubble element i down the heap\n  function heapDown(i) {\n    var w = heapWeight(i)\n    while(true) {\n      var tw = w\n      var left  = 2*i + 1\n      var right = 2*(i + 1)\n      var next = i\n      if(left < heapCount) {\n        var lw = heapWeight(left)\n        if(lw < tw) {\n          next = left\n          tw = lw\n        }\n      }\n      if(right < heapCount) {\n        var rw = heapWeight(right)\n        if(rw < tw) {\n          next = right\n        }\n      }\n      if(next === i) {\n        return i\n      }\n      heapSwap(i, next)\n      i = next      \n    }\n  }\n\n  //Bubbles element i up the heap\n  function heapUp(i) {\n    var w = heapWeight(i)\n    while(i > 0) {\n      var parent = heapParent(i)\n      if(parent >= 0) {\n        var pw = heapWeight(parent)\n        if(w < pw) {\n          heapSwap(i, parent)\n          i = parent\n          continue\n        }\n      }\n      return i\n    }\n  }\n\n  //Pop minimum element\n  function heapPop() {\n    if(heapCount > 0) {\n      var head = heap[0]\n      heapSwap(0, heapCount-1)\n      heapCount -= 1\n      heapDown(0)\n      return head\n    }\n    return -1\n  }\n\n  //Update heap item i\n  function heapUpdate(i, w) {\n    var a = heap[i]\n    if(weights[a] === w) {\n      return i\n    }\n    weights[a] = -Infinity\n    heapUp(i)\n    heapPop()\n    weights[a] = w\n    heapCount += 1\n    return heapUp(heapCount-1)\n  }\n\n  //Kills a vertex (assume vertex already removed from heap)\n  function kill(i) {\n    if(dead[i]) {\n      return\n    }\n    //Kill vertex\n    dead[i] = true\n    //Fixup topology\n    var s = inv[i]\n    var t = outv[i]\n    if(inv[t] >= 0) {\n      inv[t] = s\n    }\n    if(outv[s] >= 0) {\n      outv[s] = t\n    }\n\n    //Update weights on s and t\n    if(index[s] >= 0) {\n      heapUpdate(index[s], computeWeight(s))\n    }\n    if(index[t] >= 0) {\n      heapUpdate(index[t], computeWeight(t))\n    }\n  }\n\n  //Initialize weights and heap\n  var heap = []\n  var index = new Array(n)\n  for(var i=0; i<n; ++i) {\n    var w = weights[i] = computeWeight(i)\n    if(w < Infinity) {\n      index[i] = heap.length\n      heap.push(i)\n    } else {\n      index[i] = -1\n    }\n  }\n  var heapCount = heap.length\n  for(var i=heapCount>>1; i>=0; --i) {\n    heapDown(i)\n  }\n  \n  //Kill vertices\n  while(true) {\n    var hmin = heapPop()\n    if((hmin < 0) || (weights[hmin] > minArea)) {\n      break\n    }\n    kill(hmin)\n  }\n\n  //Build collapsed vertex table\n  var npositions = []\n  for(var i=0; i<n; ++i) {\n    if(!dead[i]) {\n      index[i] = npositions.length\n      npositions.push(positions[i].slice())\n    }\n  }\n  var nv = npositions.length\n\n  function tortoiseHare(seq, start) {\n    if(seq[start] < 0) {\n      return start\n    }\n    var t = start\n    var h = start\n    do {\n      //Walk two steps with h\n      var nh = seq[h]\n      if(!dead[h] || nh < 0 || nh === h) {\n        break\n      }\n      h = nh\n      nh = seq[h]\n      if(!dead[h] || nh < 0 || nh === h) {\n        break\n      }\n      h = nh\n\n      //Walk one step with t\n      t = seq[t]\n    } while(t !== h)\n    //Compress cycles\n    for(var v=start; v!==h; v = seq[v]) {\n      seq[v] = h\n    }\n    return h\n  }\n\n  var ncells = []\n  cells.forEach(function(c) {\n    var tin = tortoiseHare(inv, c[0])\n    var tout = tortoiseHare(outv, c[1])\n    if(tin >= 0 && tout >= 0 && tin !== tout) {\n      var cin = index[tin]\n      var cout = index[tout]\n      if(cin !== cout) {\n        ncells.push([ cin, cout ])\n      }\n    }\n  })\n\n  //Normalize result\n  sc.unique(sc.normalize(ncells))\n\n  //Return final list of cells\n  return {\n    positions: npositions,\n    edges: ncells\n  }\n}\n},{\"robust-orientation\":510,\"simplicial-complex\":522}],525:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = orderSegments\n\nvar orient = _dereq_(\"robust-orientation\")\n\nfunction horizontalOrder(a, b) {\n  var bl, br\n  if(b[0][0] < b[1][0]) {\n    bl = b[0]\n    br = b[1]\n  } else if(b[0][0] > b[1][0]) {\n    bl = b[1]\n    br = b[0]\n  } else {\n    var alo = Math.min(a[0][1], a[1][1])\n    var ahi = Math.max(a[0][1], a[1][1])\n    var blo = Math.min(b[0][1], b[1][1])\n    var bhi = Math.max(b[0][1], b[1][1])\n    if(ahi < blo) {\n      return ahi - blo\n    }\n    if(alo > bhi) {\n      return alo - bhi\n    }\n    return ahi - bhi\n  }\n  var al, ar\n  if(a[0][1] < a[1][1]) {\n    al = a[0]\n    ar = a[1]\n  } else {\n    al = a[1]\n    ar = a[0]\n  }\n  var d = orient(br, bl, al)\n  if(d) {\n    return d\n  }\n  d = orient(br, bl, ar)\n  if(d) {\n    return d\n  }\n  return ar - br\n}\n\nfunction orderSegments(b, a) {\n  var al, ar\n  if(a[0][0] < a[1][0]) {\n    al = a[0]\n    ar = a[1]\n  } else if(a[0][0] > a[1][0]) {\n    al = a[1]\n    ar = a[0]\n  } else {\n    return horizontalOrder(a, b)\n  }\n  var bl, br\n  if(b[0][0] < b[1][0]) {\n    bl = b[0]\n    br = b[1]\n  } else if(b[0][0] > b[1][0]) {\n    bl = b[1]\n    br = b[0]\n  } else {\n    return -horizontalOrder(b, a)\n  }\n  var d1 = orient(al, ar, br)\n  var d2 = orient(al, ar, bl)\n  if(d1 < 0) {\n    if(d2 <= 0) {\n      return d1\n    }\n  } else if(d1 > 0) {\n    if(d2 >= 0) {\n      return d1\n    }\n  } else if(d2) {\n    return d2\n  }\n  d1 = orient(br, bl, ar)\n  d2 = orient(br, bl, al)\n  if(d1 < 0) {\n    if(d2 <= 0) {\n      return d1\n    }\n  } else if(d1 > 0) {\n    if(d2 >= 0) {\n      return d1\n    }\n  } else if(d2) {\n    return d2\n  }\n  return ar[0] - br[0]\n}\n},{\"robust-orientation\":510}],526:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = createSlabDecomposition\n\nvar bounds = _dereq_(\"binary-search-bounds\")\nvar createRBTree = _dereq_(\"functional-red-black-tree\")\nvar orient = _dereq_(\"robust-orientation\")\nvar orderSegments = _dereq_(\"./lib/order-segments\")\n\nfunction SlabDecomposition(slabs, coordinates, horizontal) {\n  this.slabs = slabs\n  this.coordinates = coordinates\n  this.horizontal = horizontal\n}\n\nvar proto = SlabDecomposition.prototype\n\nfunction compareHorizontal(e, y) {\n  return e.y - y\n}\n\nfunction searchBucket(root, p) {\n  var lastNode = null\n  while(root) {\n    var seg = root.key\n    var l, r\n    if(seg[0][0] < seg[1][0]) {\n      l = seg[0]\n      r = seg[1]\n    } else {\n      l = seg[1]\n      r = seg[0]\n    }\n    var o = orient(l, r, p)\n    if(o < 0) {\n      root = root.left\n    } else if(o > 0) {\n      if(p[0] !== seg[1][0]) {\n        lastNode = root\n        root = root.right\n      } else {\n        var val = searchBucket(root.right, p)\n        if(val) {\n          return val\n        }\n        root = root.left\n      }\n    } else {\n      if(p[0] !== seg[1][0]) {\n        return root\n      } else {\n        var val = searchBucket(root.right, p)\n        if(val) {\n          return val\n        }\n        root = root.left\n      }\n    }\n  }\n  return lastNode\n}\n\nproto.castUp = function(p) {\n  var bucket = bounds.le(this.coordinates, p[0])\n  if(bucket < 0) {\n    return -1\n  }\n  var root = this.slabs[bucket]\n  var hitNode = searchBucket(this.slabs[bucket], p)\n  var lastHit = -1\n  if(hitNode) {\n    lastHit = hitNode.value\n  }\n  //Edge case: need to handle horizontal segments (sucks)\n  if(this.coordinates[bucket] === p[0]) {\n    var lastSegment = null\n    if(hitNode) {\n      lastSegment = hitNode.key\n    }\n    if(bucket > 0) {\n      var otherHitNode = searchBucket(this.slabs[bucket-1], p)\n      if(otherHitNode) {\n        if(lastSegment) {\n          if(orderSegments(otherHitNode.key, lastSegment) > 0) {\n            lastSegment = otherHitNode.key\n            lastHit = otherHitNode.value\n          }\n        } else {\n          lastHit = otherHitNode.value\n          lastSegment = otherHitNode.key\n        }\n      }\n    }\n    var horiz = this.horizontal[bucket]\n    if(horiz.length > 0) {\n      var hbucket = bounds.ge(horiz, p[1], compareHorizontal)\n      if(hbucket < horiz.length) {\n        var e = horiz[hbucket]\n        if(p[1] === e.y) {\n          if(e.closed) {\n            return e.index\n          } else {\n            while(hbucket < horiz.length-1 && horiz[hbucket+1].y === p[1]) {\n              hbucket = hbucket+1\n              e = horiz[hbucket]\n              if(e.closed) {\n                return e.index\n              }\n            }\n            if(e.y === p[1] && !e.start) {\n              hbucket = hbucket+1\n              if(hbucket >= horiz.length) {\n                return lastHit\n              }\n              e = horiz[hbucket]\n            }\n          }\n        }\n        //Check if e is above/below last segment\n        if(e.start) {\n          if(lastSegment) {\n            var o = orient(lastSegment[0], lastSegment[1], [p[0], e.y])\n            if(lastSegment[0][0] > lastSegment[1][0]) {\n              o = -o\n            }\n            if(o > 0) {\n              lastHit = e.index\n            }\n          } else {\n            lastHit = e.index\n          }\n        } else if(e.y !== p[1]) {\n          lastHit = e.index\n        }\n      }\n    }\n  }\n  return lastHit\n}\n\nfunction IntervalSegment(y, index, start, closed) {\n  this.y = y\n  this.index = index\n  this.start = start\n  this.closed = closed\n}\n\nfunction Event(x, segment, create, index) {\n  this.x = x\n  this.segment = segment\n  this.create = create\n  this.index = index\n}\n\n\nfunction createSlabDecomposition(segments) {\n  var numSegments = segments.length\n  var numEvents = 2 * numSegments\n  var events = new Array(numEvents)\n  for(var i=0; i<numSegments; ++i) {\n    var s = segments[i]\n    var f = s[0][0] < s[1][0]\n    events[2*i] = new Event(s[0][0], s, f, i)\n    events[2*i+1] = new Event(s[1][0], s, !f, i)\n  }\n  events.sort(function(a,b) {\n    var d = a.x - b.x\n    if(d) {\n      return d\n    }\n    d = a.create - b.create\n    if(d) {\n      return d\n    }\n    return Math.min(a.segment[0][1], a.segment[1][1]) - Math.min(b.segment[0][1], b.segment[1][1])\n  })\n  var tree = createRBTree(orderSegments)\n  var slabs = []\n  var lines = []\n  var horizontal = []\n  var lastX = -Infinity\n  for(var i=0; i<numEvents; ) {\n    var x = events[i].x\n    var horiz = []\n    while(i < numEvents) {\n      var e = events[i]\n      if(e.x !== x) {\n        break\n      }\n      i += 1\n      if(e.segment[0][0] === e.x && e.segment[1][0] === e.x) {\n        if(e.create) {\n          if(e.segment[0][1] < e.segment[1][1]) {\n            horiz.push(new IntervalSegment(\n                e.segment[0][1],\n                e.index,\n                true,\n                true))\n            horiz.push(new IntervalSegment(\n                e.segment[1][1],\n                e.index,\n                false,\n                false))\n          } else {\n            horiz.push(new IntervalSegment(\n                e.segment[1][1],\n                e.index,\n                true,\n                false))\n            horiz.push(new IntervalSegment(\n                e.segment[0][1],\n                e.index,\n                false,\n                true))\n          }\n        }\n      } else {\n        if(e.create) {\n          tree = tree.insert(e.segment, e.index)\n        } else {\n          tree = tree.remove(e.segment)\n        }\n      }\n    }\n    slabs.push(tree.root)\n    lines.push(x)\n    horizontal.push(horiz)\n  }\n  return new SlabDecomposition(slabs, lines, horizontal)\n}\n},{\"./lib/order-segments\":525,\"binary-search-bounds\":91,\"functional-red-black-tree\":230,\"robust-orientation\":510}],527:[function(_dereq_,module,exports){\n\"use strict\"\n\nvar robustDot = _dereq_(\"robust-dot-product\")\nvar robustSum = _dereq_(\"robust-sum\")\n\nmodule.exports = splitPolygon\nmodule.exports.positive = positive\nmodule.exports.negative = negative\n\nfunction planeT(p, plane) {\n  var r = robustSum(robustDot(p, plane), [plane[plane.length-1]])\n  return r[r.length-1]\n}\n\n\n//Can't do this exactly and emit a floating point result\nfunction lerpW(a, wa, b, wb) {\n  var d = wb - wa\n  var t = -wa / d\n  if(t < 0.0) {\n    t = 0.0\n  } else if(t > 1.0) {\n    t = 1.0\n  }\n  var ti = 1.0 - t\n  var n = a.length\n  var r = new Array(n)\n  for(var i=0; i<n; ++i) {\n    r[i] = t * a[i] + ti * b[i]\n  }\n  return r\n}\n\nfunction splitPolygon(points, plane) {\n  var pos = []\n  var neg = []\n  var a = planeT(points[points.length-1], plane)\n  for(var s=points[points.length-1], t=points[0], i=0; i<points.length; ++i, s=t) {\n    t = points[i]\n    var b = planeT(t, plane)\n    if((a < 0 && b > 0) || (a > 0 && b < 0)) {\n      var p = lerpW(s, b, t, a)\n      pos.push(p)\n      neg.push(p.slice())\n    }\n    if(b < 0) {\n      neg.push(t.slice())\n    } else if(b > 0) {\n      pos.push(t.slice())\n    } else {\n      pos.push(t.slice())\n      neg.push(t.slice())\n    }\n    a = b\n  }\n  return { positive: pos, negative: neg }\n}\n\nfunction positive(points, plane) {\n  var pos = []\n  var a = planeT(points[points.length-1], plane)\n  for(var s=points[points.length-1], t=points[0], i=0; i<points.length; ++i, s=t) {\n    t = points[i]\n    var b = planeT(t, plane)\n    if((a < 0 && b > 0) || (a > 0 && b < 0)) {\n      pos.push(lerpW(s, b, t, a))\n    }\n    if(b >= 0) {\n      pos.push(t.slice())\n    }\n    a = b\n  }\n  return pos\n}\n\nfunction negative(points, plane) {\n  var neg = []\n  var a = planeT(points[points.length-1], plane)\n  for(var s=points[points.length-1], t=points[0], i=0; i<points.length; ++i, s=t) {\n    t = points[i]\n    var b = planeT(t, plane)\n    if((a < 0 && b > 0) || (a > 0 && b < 0)) {\n      neg.push(lerpW(s, b, t, a))\n    }\n    if(b <= 0) {\n      neg.push(t.slice())\n    }\n    a = b\n  }\n  return neg\n}\n},{\"robust-dot-product\":507,\"robust-sum\":515}],528:[function(_dereq_,module,exports){\n/* global window, exports, define */\n\n!function() {\n    'use strict'\n\n    var re = {\n        not_string: /[^s]/,\n        not_bool: /[^t]/,\n        not_type: /[^T]/,\n        not_primitive: /[^v]/,\n        number: /[diefg]/,\n        numeric_arg: /[bcdiefguxX]/,\n        json: /[j]/,\n        not_json: /[^j]/,\n        text: /^[^\\x25]+/,\n        modulo: /^\\x25{2}/,\n        placeholder: /^\\x25(?:([1-9]\\d*)\\$|\\(([^)]+)\\))?(\\+)?(0|'[^$])?(-)?(\\d+)?(?:\\.(\\d+))?([b-gijostTuvxX])/,\n        key: /^([a-z_][a-z_\\d]*)/i,\n        key_access: /^\\.([a-z_][a-z_\\d]*)/i,\n        index_access: /^\\[(\\d+)\\]/,\n        sign: /^[+-]/\n    }\n\n    function sprintf(key) {\n        // `arguments` is not an array, but should be fine for this call\n        return sprintf_format(sprintf_parse(key), arguments)\n    }\n\n    function vsprintf(fmt, argv) {\n        return sprintf.apply(null, [fmt].concat(argv || []))\n    }\n\n    function sprintf_format(parse_tree, argv) {\n        var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign\n        for (i = 0; i < tree_length; i++) {\n            if (typeof parse_tree[i] === 'string') {\n                output += parse_tree[i]\n            }\n            else if (typeof parse_tree[i] === 'object') {\n                ph = parse_tree[i] // convenience purposes only\n                if (ph.keys) { // keyword argument\n                    arg = argv[cursor]\n                    for (k = 0; k < ph.keys.length; k++) {\n                        if (arg == undefined) {\n                            throw new Error(sprintf('[sprintf] Cannot access property \"%s\" of undefined value \"%s\"', ph.keys[k], ph.keys[k-1]))\n                        }\n                        arg = arg[ph.keys[k]]\n                    }\n                }\n                else if (ph.param_no) { // positional argument (explicit)\n                    arg = argv[ph.param_no]\n                }\n                else { // positional argument (implicit)\n                    arg = argv[cursor++]\n                }\n\n                if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {\n                    arg = arg()\n                }\n\n                if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {\n                    throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))\n                }\n\n                if (re.number.test(ph.type)) {\n                    is_positive = arg >= 0\n                }\n\n                switch (ph.type) {\n                    case 'b':\n                        arg = parseInt(arg, 10).toString(2)\n                        break\n                    case 'c':\n                        arg = String.fromCharCode(parseInt(arg, 10))\n                        break\n                    case 'd':\n                    case 'i':\n                        arg = parseInt(arg, 10)\n                        break\n                    case 'j':\n                        arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)\n                        break\n                    case 'e':\n                        arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential()\n                        break\n                    case 'f':\n                        arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg)\n                        break\n                    case 'g':\n                        arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg)\n                        break\n                    case 'o':\n                        arg = (parseInt(arg, 10) >>> 0).toString(8)\n                        break\n                    case 's':\n                        arg = String(arg)\n                        arg = (ph.precision ? arg.substring(0, ph.precision) : arg)\n                        break\n                    case 't':\n                        arg = String(!!arg)\n                        arg = (ph.precision ? arg.substring(0, ph.precision) : arg)\n                        break\n                    case 'T':\n                        arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()\n                        arg = (ph.precision ? arg.substring(0, ph.precision) : arg)\n                        break\n                    case 'u':\n                        arg = parseInt(arg, 10) >>> 0\n                        break\n                    case 'v':\n                        arg = arg.valueOf()\n                        arg = (ph.precision ? arg.substring(0, ph.precision) : arg)\n                        break\n                    case 'x':\n                        arg = (parseInt(arg, 10) >>> 0).toString(16)\n                        break\n                    case 'X':\n                        arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()\n                        break\n                }\n                if (re.json.test(ph.type)) {\n                    output += arg\n                }\n                else {\n                    if (re.number.test(ph.type) && (!is_positive || ph.sign)) {\n                        sign = is_positive ? '+' : '-'\n                        arg = arg.toString().replace(re.sign, '')\n                    }\n                    else {\n                        sign = ''\n                    }\n                    pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' '\n                    pad_length = ph.width - (sign + arg).length\n                    pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''\n                    output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg)\n                }\n            }\n        }\n        return output\n    }\n\n    var sprintf_cache = Object.create(null)\n\n    function sprintf_parse(fmt) {\n        if (sprintf_cache[fmt]) {\n            return sprintf_cache[fmt]\n        }\n\n        var _fmt = fmt, match, parse_tree = [], arg_names = 0\n        while (_fmt) {\n            if ((match = re.text.exec(_fmt)) !== null) {\n                parse_tree.push(match[0])\n            }\n            else if ((match = re.modulo.exec(_fmt)) !== null) {\n                parse_tree.push('%')\n            }\n            else if ((match = re.placeholder.exec(_fmt)) !== null) {\n                if (match[2]) {\n                    arg_names |= 1\n                    var field_list = [], replacement_field = match[2], field_match = []\n                    if ((field_match = re.key.exec(replacement_field)) !== null) {\n                        field_list.push(field_match[1])\n                        while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {\n                            if ((field_match = re.key_access.exec(replacement_field)) !== null) {\n                                field_list.push(field_match[1])\n                            }\n                            else if ((field_match = re.index_access.exec(replacement_field)) !== null) {\n                                field_list.push(field_match[1])\n                            }\n                            else {\n                                throw new SyntaxError('[sprintf] failed to parse named argument key')\n                            }\n                        }\n                    }\n                    else {\n                        throw new SyntaxError('[sprintf] failed to parse named argument key')\n                    }\n                    match[2] = field_list\n                }\n                else {\n                    arg_names |= 2\n                }\n                if (arg_names === 3) {\n                    throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')\n                }\n\n                parse_tree.push(\n                    {\n                        placeholder: match[0],\n                        param_no:    match[1],\n                        keys:        match[2],\n                        sign:        match[3],\n                        pad_char:    match[4],\n                        align:       match[5],\n                        width:       match[6],\n                        precision:   match[7],\n                        type:        match[8]\n                    }\n                )\n            }\n            else {\n                throw new SyntaxError('[sprintf] unexpected placeholder')\n            }\n            _fmt = _fmt.substring(match[0].length)\n        }\n        return sprintf_cache[fmt] = parse_tree\n    }\n\n    /**\n     * export to either browser or node.js\n     */\n    /* eslint-disable quote-props */\n    if (typeof exports !== 'undefined') {\n        exports['sprintf'] = sprintf\n        exports['vsprintf'] = vsprintf\n    }\n    if (typeof window !== 'undefined') {\n        window['sprintf'] = sprintf\n        window['vsprintf'] = vsprintf\n\n        if (typeof define === 'function' && define['amd']) {\n            define(function() {\n                return {\n                    'sprintf': sprintf,\n                    'vsprintf': vsprintf\n                }\n            })\n        }\n    }\n    /* eslint-enable quote-props */\n}(); // eslint-disable-line\n\n},{}],529:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar paren = _dereq_('parenthesis')\r\n\r\nmodule.exports = function splitBy (string, separator, o) {\r\n\tif (string == null) throw Error('First argument should be a string')\r\n\tif (separator == null) throw Error('Separator should be a string or a RegExp')\r\n\r\n\tif (!o) o = {}\r\n\telse if (typeof o === 'string' || Array.isArray(o)) {\r\n\t\to = {ignore: o}\r\n\t}\r\n\r\n\tif (o.escape == null) o.escape = true\r\n\tif (o.ignore == null) o.ignore = ['[]', '()', '{}', '<>', '\"\"', \"''\", '``', '“”', '«»']\r\n\telse {\r\n\t\tif (typeof o.ignore === 'string') {o.ignore = [o.ignore]}\r\n\r\n\t\to.ignore = o.ignore.map(function (pair) {\r\n\t\t\t// '\"' → '\"\"'\r\n\t\t\tif (pair.length === 1) pair = pair + pair\r\n\t\t\treturn pair\r\n\t\t})\r\n\t}\r\n\r\n\tvar tokens = paren.parse(string, {flat: true, brackets: o.ignore})\r\n\tvar str = tokens[0]\r\n\r\n\tvar parts = str.split(separator)\r\n\r\n\t// join parts separated by escape\r\n\tif (o.escape) {\r\n\t\tvar cleanParts = []\r\n\t\tfor (var i = 0; i < parts.length; i++) {\r\n\t\t\tvar prev = parts[i]\r\n\t\t\tvar part = parts[i + 1]\r\n\r\n\t\t\tif (prev[prev.length - 1] === '\\\\' && prev[prev.length - 2] !== '\\\\') {\r\n\t\t\t\tcleanParts.push(prev + separator + part)\r\n\t\t\t\ti++\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tcleanParts.push(prev)\r\n\t\t\t}\r\n\t\t}\r\n\t\tparts = cleanParts\r\n\t}\r\n\r\n\t// open parens pack & apply unquotes, if any\r\n\tfor (var i = 0; i < parts.length; i++) {\r\n\t\ttokens[0] = parts[i]\r\n\t\tparts[i] = paren.stringify(tokens, {flat: true})\r\n\t}\r\n\r\n\treturn parts\r\n}\r\n\n},{\"parenthesis\":458}],530:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = stronglyConnectedComponents\n\nfunction stronglyConnectedComponents(adjList) {\n  var numVertices = adjList.length;\n  var index = new Array(numVertices)\n  var lowValue = new Array(numVertices)\n  var active = new Array(numVertices)\n  var child = new Array(numVertices)\n  var scc = new Array(numVertices)\n  var sccLinks = new Array(numVertices)\n  \n  //Initialize tables\n  for(var i=0; i<numVertices; ++i) {\n    index[i] = -1\n    lowValue[i] = 0\n    active[i] = false\n    child[i] = 0\n    scc[i] = -1\n    sccLinks[i] = []\n  }\n\n  // The strongConnect function\n  var count = 0\n  var components = []\n  var sccAdjList = []\n\n  function strongConnect(v) {\n    // To avoid running out of stack space, this emulates the recursive behaviour of the normal algorithm, effectively using T as the call stack.\n    var S = [v], T = [v]\n    index[v] = lowValue[v] = count\n    active[v] = true\n    count += 1\n    while(T.length > 0) {\n      v = T[T.length-1]\n      var e = adjList[v]\n      if (child[v] < e.length) { // If we're not done iterating over the children, first try finishing that.\n        for(var i=child[v]; i<e.length; ++i) { // Start where we left off.\n          var u = e[i]\n          if(index[u] < 0) {\n            index[u] = lowValue[u] = count\n            active[u] = true\n            count += 1\n            S.push(u)\n            T.push(u)\n            break // First recurse, then continue here (with the same child!).\n            // There is a slight change to Tarjan's algorithm here.\n            // Normally, after having recursed, we set lowValue like we do for an active child (although some variants of the algorithm do it slightly differently).\n            // Here, we only do so if the child we recursed on is still active.\n            // The reasoning is that if it is no longer active, it must have had a lowValue equal to its own index, which means that it is necessarily higher than our lowValue.\n          } else if (active[u]) {\n            lowValue[v] = Math.min(lowValue[v], lowValue[u])|0\n          }\n          if (scc[u] >= 0) {\n            // Node v is not yet assigned an scc, but once it is that scc can apparently reach scc[u].\n            sccLinks[v].push(scc[u])\n          }\n        }\n        child[v] = i // Remember where we left off.\n      } else { // If we're done iterating over the children, check whether we have an scc.\n        if(lowValue[v] === index[v]) { // TODO: It /might/ be true that T is always a prefix of S (at this point!!!), and if so, this could be used here.\n          var component = []\n          var links = [], linkCount = 0\n          for(var i=S.length-1; i>=0; --i) {\n            var w = S[i]\n            active[w] = false\n            component.push(w)\n            links.push(sccLinks[w])\n            linkCount += sccLinks[w].length\n            scc[w] = components.length\n            if(w === v) {\n              S.length = i\n              break\n            }\n          }\n          components.push(component)\n          var allLinks = new Array(linkCount)\n          for(var i=0; i<links.length; i++) {\n            for(var j=0; j<links[i].length; j++) {\n              allLinks[--linkCount] = links[i][j]\n            }\n          }\n          sccAdjList.push(allLinks)\n        }\n        T.pop() // Now we're finished exploring this particular node (normally corresponds to the return statement)\n      }\n    }\n  }\n\n  //Run strong connect starting from each vertex\n  for(var i=0; i<numVertices; ++i) {\n    if(index[i] < 0) {\n      strongConnect(i)\n    }\n  }\n  \n  // Compact sccAdjList\n  var newE\n  for(var i=0; i<sccAdjList.length; i++) {\n    var e = sccAdjList[i]\n    if (e.length === 0) continue\n    e.sort(function (a,b) { return a-b; })\n    newE = [e[0]]\n    for(var j=1; j<e.length; j++) {\n      if (e[j] !== e[j-1]) {\n        newE.push(e[j])\n      }\n    }\n    sccAdjList[i] = newE\n  }  \n\n  return {components: components, adjacencyList: sccAdjList}\n}\n\n},{}],531:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = surfaceNets\n\nvar generateContourExtractor = _dereq_(\"ndarray-extract-contour\")\nvar triangulateCube = _dereq_(\"triangulate-hypercube\")\nvar zeroCrossings = _dereq_(\"zero-crossings\")\n\nfunction buildSurfaceNets(order, dtype) {\n  var dimension = order.length\n  var code = [\"'use strict';\"]\n  var funcName = \"surfaceNets\" + order.join(\"_\") + \"d\" + dtype\n\n  //Contour extraction function\n  code.push(\n    \"var contour=genContour({\",\n      \"order:[\", order.join(), \"],\",\n      \"scalarArguments: 3,\",\n      \"phase:function phaseFunc(p,a,b,c) { return (p > c)|0 },\")\n  if(dtype === \"generic\") {\n    code.push(\"getters:[0],\")\n  }\n\n  //Generate vertex function\n  var cubeArgs = []\n  var extraArgs = []\n  for(var i=0; i<dimension; ++i) {\n    cubeArgs.push(\"d\" + i)\n    extraArgs.push(\"d\" + i)\n  }\n  for(var i=0; i<(1<<dimension); ++i) {\n    cubeArgs.push(\"v\" + i)\n    extraArgs.push(\"v\" + i)\n  }\n  for(var i=0; i<(1<<dimension); ++i) {\n    cubeArgs.push(\"p\" + i)\n    extraArgs.push(\"p\" + i)\n  }\n  cubeArgs.push(\"a\", \"b\", \"c\")\n  extraArgs.push(\"a\", \"c\")\n  code.push(\"vertex:function vertexFunc(\", cubeArgs.join(), \"){\")\n  //Mask args together\n  var maskStr = []\n  for(var i=0; i<(1<<dimension); ++i) {\n    maskStr.push(\"(p\" + i + \"<<\" + i + \")\")\n  }\n  //Generate variables and giganto switch statement\n  code.push(\"var m=(\", maskStr.join(\"+\"), \")|0;if(m===0||m===\", (1<<(1<<dimension))-1, \"){return}\")\n  var extraFuncs = []\n  var currentFunc = []\n  if(1<<(1<<dimension) <= 128) {\n    code.push(\"switch(m){\")\n    currentFunc = code\n  } else {\n    code.push(\"switch(m>>>7){\")\n  }\n  for(var i=0; i<1<<(1<<dimension); ++i) {\n    if(1<<(1<<dimension) > 128) {\n      if((i%128)===0) {\n        if(extraFuncs.length > 0) {\n          currentFunc.push(\"}}\")\n        }\n        var efName = \"vExtra\" + extraFuncs.length\n        code.push(\"case \", (i>>>7), \":\", efName, \"(m&0x7f,\", extraArgs.join(), \");break;\")\n        currentFunc = [\n          \"function \", efName, \"(m,\", extraArgs.join(), \"){switch(m){\"\n        ]\n        extraFuncs.push(currentFunc)\n      }  \n    }\n    currentFunc.push(\"case \", (i&0x7f), \":\")\n    var crossings = new Array(dimension)\n    var denoms = new Array(dimension)\n    var crossingCount = new Array(dimension)\n    var bias = new Array(dimension)\n    var totalCrossings = 0\n    for(var j=0; j<dimension; ++j) {\n      crossings[j] = []\n      denoms[j] = []\n      crossingCount[j] = 0\n      bias[j] = 0\n    }\n    for(var j=0; j<(1<<dimension); ++j) {\n      for(var k=0; k<dimension; ++k) {\n        var u = j ^ (1<<k)\n        if(u > j) {\n          continue\n        }\n        if(!(i&(1<<u)) !== !(i&(1<<j))) {\n          var sign = 1\n          if(i&(1<<u)) {\n            denoms[k].push(\"v\" + u + \"-v\" + j)\n          } else {\n            denoms[k].push(\"v\" + j + \"-v\" + u)\n            sign = -sign\n          }\n          if(sign < 0) {\n            crossings[k].push(\"-v\" + j + \"-v\" + u)\n            crossingCount[k] += 2\n          } else {\n            crossings[k].push(\"v\" + j + \"+v\" + u)\n            crossingCount[k] -= 2            \n          }\n          totalCrossings += 1\n          for(var l=0; l<dimension; ++l) {\n            if(l === k) {\n              continue\n            }\n            if(u&(1<<l)) {\n              bias[l] += 1\n            } else {\n              bias[l] -= 1\n            }\n          }\n        }\n      }\n    }\n    var vertexStr = []\n    for(var k=0; k<dimension; ++k) {\n      if(crossings[k].length === 0) {\n        vertexStr.push(\"d\" + k + \"-0.5\")\n      } else {\n        var cStr = \"\"\n        if(crossingCount[k] < 0) {\n          cStr = crossingCount[k] + \"*c\"\n        } else if(crossingCount[k] > 0) {\n          cStr = \"+\" + crossingCount[k] + \"*c\"\n        }\n        var weight = 0.5 * (crossings[k].length / totalCrossings)\n        var shift = 0.5 + 0.5 * (bias[k] / totalCrossings)\n        vertexStr.push(\"d\" + k + \"-\" + shift + \"-\" + weight + \"*(\" + crossings[k].join(\"+\") + cStr + \")/(\" + denoms[k].join(\"+\") + \")\")\n        \n      }\n    }\n    currentFunc.push(\"a.push([\", vertexStr.join(), \"]);\",\n      \"break;\")\n  }\n  code.push(\"}},\")\n  if(extraFuncs.length > 0) {\n    currentFunc.push(\"}}\")\n  }\n\n  //Create face function\n  var faceArgs = []\n  for(var i=0; i<(1<<(dimension-1)); ++i) {\n    faceArgs.push(\"v\" + i)\n  }\n  faceArgs.push(\"c0\", \"c1\", \"p0\", \"p1\", \"a\", \"b\", \"c\")\n  code.push(\"cell:function cellFunc(\", faceArgs.join(), \"){\")\n\n  var facets = triangulateCube(dimension-1)\n  code.push(\"if(p0){b.push(\",\n    facets.map(function(f) {\n      return \"[\" + f.map(function(v) {\n        return \"v\" + v\n      }) + \"]\"\n    }).join(), \")}else{b.push(\",\n    facets.map(function(f) {\n      var e = f.slice()\n      e.reverse()\n      return \"[\" + e.map(function(v) {\n        return \"v\" + v\n      }) + \"]\"\n    }).join(),\n    \")}}});function \", funcName, \"(array,level){var verts=[],cells=[];contour(array,verts,cells,level);return {positions:verts,cells:cells};} return \", funcName, \";\")\n\n  for(var i=0; i<extraFuncs.length; ++i) {\n    code.push(extraFuncs[i].join(\"\"))\n  }\n\n  //Compile and link\n  var proc = new Function(\"genContour\", code.join(\"\"))\n  return proc(generateContourExtractor)\n}\n\n//1D case: Need to handle specially\nfunction mesh1D(array, level) {\n  var zc = zeroCrossings(array, level)\n  var n = zc.length\n  var npos = new Array(n)\n  var ncel = new Array(n)\n  for(var i=0; i<n; ++i) {\n    npos[i] = [ zc[i] ]\n    ncel[i] = [ i ]\n  }\n  return {\n    positions: npos,\n    cells: ncel\n  }\n}\n\nvar CACHE = {}\n\nfunction surfaceNets(array,level) {\n  if(array.dimension <= 0) {\n    return { positions: [], cells: [] }\n  } else if(array.dimension === 1) {\n    return mesh1D(array, level)\n  }\n  var typesig = array.order.join() + \"-\" + array.dtype\n  var proc = CACHE[typesig]\n  var level = (+level) || 0.0\n  if(!proc) {\n    proc = CACHE[typesig] = buildSurfaceNets(array.order, array.dtype)\n  }\n  return proc(array,level)\n}\n},{\"ndarray-extract-contour\":439,\"triangulate-hypercube\":541,\"zero-crossings\":574}],532:[function(_dereq_,module,exports){\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true\n});\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar TAU = Math.PI * 2;\n\nvar mapToEllipse = function mapToEllipse(_ref, rx, ry, cosphi, sinphi, centerx, centery) {\n  var x = _ref.x,\n      y = _ref.y;\n\n  x *= rx;\n  y *= ry;\n\n  var xp = cosphi * x - sinphi * y;\n  var yp = sinphi * x + cosphi * y;\n\n  return {\n    x: xp + centerx,\n    y: yp + centery\n  };\n};\n\nvar approxUnitArc = function approxUnitArc(ang1, ang2) {\n  // See http://spencermortensen.com/articles/bezier-circle/ for the derivation\n  // of this constant.\n  // Note: We need to keep the sign of ang2, because this determines the\n  //       direction of the arc using the sweep-flag parameter.\n  var c = 0.551915024494 * (ang2 < 0 ? -1 : 1);\n\n  var x1 = Math.cos(ang1);\n  var y1 = Math.sin(ang1);\n  var x2 = Math.cos(ang1 + ang2);\n  var y2 = Math.sin(ang1 + ang2);\n\n  return [{\n    x: x1 - y1 * c,\n    y: y1 + x1 * c\n  }, {\n    x: x2 + y2 * c,\n    y: y2 - x2 * c\n  }, {\n    x: x2,\n    y: y2\n  }];\n};\n\nvar vectorAngle = function vectorAngle(ux, uy, vx, vy) {\n  var sign = ux * vy - uy * vx < 0 ? -1 : 1;\n  var umag = Math.sqrt(ux * ux + uy * uy);\n  var vmag = Math.sqrt(ux * ux + uy * uy);\n  var dot = ux * vx + uy * vy;\n\n  var div = dot / (umag * vmag);\n\n  if (div > 1) {\n    div = 1;\n  }\n\n  if (div < -1) {\n    div = -1;\n  }\n\n  return sign * Math.acos(div);\n};\n\nvar getArcCenter = function getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) {\n  var rxsq = Math.pow(rx, 2);\n  var rysq = Math.pow(ry, 2);\n  var pxpsq = Math.pow(pxp, 2);\n  var pypsq = Math.pow(pyp, 2);\n\n  var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;\n\n  if (radicant < 0) {\n    radicant = 0;\n  }\n\n  radicant /= rxsq * pypsq + rysq * pxpsq;\n  radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);\n\n  var centerxp = radicant * rx / ry * pyp;\n  var centeryp = radicant * -ry / rx * pxp;\n\n  var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;\n  var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;\n\n  var vx1 = (pxp - centerxp) / rx;\n  var vy1 = (pyp - centeryp) / ry;\n  var vx2 = (-pxp - centerxp) / rx;\n  var vy2 = (-pyp - centeryp) / ry;\n\n  var ang1 = vectorAngle(1, 0, vx1, vy1);\n  var ang2 = vectorAngle(vx1, vy1, vx2, vy2);\n\n  if (sweepFlag === 0 && ang2 > 0) {\n    ang2 -= TAU;\n  }\n\n  if (sweepFlag === 1 && ang2 < 0) {\n    ang2 += TAU;\n  }\n\n  return [centerx, centery, ang1, ang2];\n};\n\nvar arcToBezier = function arcToBezier(_ref2) {\n  var px = _ref2.px,\n      py = _ref2.py,\n      cx = _ref2.cx,\n      cy = _ref2.cy,\n      rx = _ref2.rx,\n      ry = _ref2.ry,\n      _ref2$xAxisRotation = _ref2.xAxisRotation,\n      xAxisRotation = _ref2$xAxisRotation === undefined ? 0 : _ref2$xAxisRotation,\n      _ref2$largeArcFlag = _ref2.largeArcFlag,\n      largeArcFlag = _ref2$largeArcFlag === undefined ? 0 : _ref2$largeArcFlag,\n      _ref2$sweepFlag = _ref2.sweepFlag,\n      sweepFlag = _ref2$sweepFlag === undefined ? 0 : _ref2$sweepFlag;\n\n  var curves = [];\n\n  if (rx === 0 || ry === 0) {\n    return [];\n  }\n\n  var sinphi = Math.sin(xAxisRotation * TAU / 360);\n  var cosphi = Math.cos(xAxisRotation * TAU / 360);\n\n  var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2;\n  var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2;\n\n  if (pxp === 0 && pyp === 0) {\n    return [];\n  }\n\n  rx = Math.abs(rx);\n  ry = Math.abs(ry);\n\n  var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);\n\n  if (lambda > 1) {\n    rx *= Math.sqrt(lambda);\n    ry *= Math.sqrt(lambda);\n  }\n\n  var _getArcCenter = getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp),\n      _getArcCenter2 = _slicedToArray(_getArcCenter, 4),\n      centerx = _getArcCenter2[0],\n      centery = _getArcCenter2[1],\n      ang1 = _getArcCenter2[2],\n      ang2 = _getArcCenter2[3];\n\n  // If 'ang2' == 90.0000000001, then `ratio` will evaluate to\n  // 1.0000000001. This causes `segments` to be greater than one, which is an\n  // unecessary split, and adds extra points to the bezier curve. To alleviate\n  // this issue, we round to 1.0 when the ratio is close to 1.0.\n\n\n  var ratio = Math.abs(ang2) / (TAU / 4);\n  if (Math.abs(1.0 - ratio) < 0.0000001) {\n    ratio = 1.0;\n  }\n\n  var segments = Math.max(Math.ceil(ratio), 1);\n\n  ang2 /= segments;\n\n  for (var i = 0; i < segments; i++) {\n    curves.push(approxUnitArc(ang1, ang2));\n    ang1 += ang2;\n  }\n\n  return curves.map(function (curve) {\n    var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery),\n        x1 = _mapToEllipse.x,\n        y1 = _mapToEllipse.y;\n\n    var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery),\n        x2 = _mapToEllipse2.x,\n        y2 = _mapToEllipse2.y;\n\n    var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery),\n        x = _mapToEllipse3.x,\n        y = _mapToEllipse3.y;\n\n    return { x1: x1, y1: y1, x2: x2, y2: y2, x: x, y: y };\n  });\n};\n\nexports.default = arcToBezier;\nmodule.exports = exports.default;\n},{}],533:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar parse = _dereq_('parse-svg-path')\r\nvar abs = _dereq_('abs-svg-path')\r\nvar normalize = _dereq_('normalize-svg-path')\r\nvar isSvgPath = _dereq_('is-svg-path')\r\nvar assert = _dereq_('assert')\r\n\r\nmodule.exports = pathBounds\r\n\r\n\r\nfunction pathBounds(path) {\r\n  // ES6 string tpl call\r\n  if (Array.isArray(path) && path.length === 1 && typeof path[0] === 'string') path = path[0]\r\n\r\n  // svg path string\r\n  if (typeof path === 'string') {\r\n    assert(isSvgPath(path), 'String is not an SVG path.')\r\n    path = parse(path)\r\n  }\r\n\r\n  assert(Array.isArray(path), 'Argument should be a string or an array of path segments.')\r\n\r\n  path = abs(path)\r\n  path = normalize(path)\r\n\r\n  if (!path.length) return [0, 0, 0, 0]\r\n\r\n  var bounds = [Infinity, Infinity, -Infinity, -Infinity]\r\n\r\n  for (var i = 0, l = path.length; i < l; i++) {\r\n    var points = path[i].slice(1)\r\n\r\n    for (var j = 0; j < points.length; j += 2) {\r\n      if (points[j + 0] < bounds[0]) bounds[0] = points[j + 0]\r\n      if (points[j + 1] < bounds[1]) bounds[1] = points[j + 1]\r\n      if (points[j + 0] > bounds[2]) bounds[2] = points[j + 0]\r\n      if (points[j + 1] > bounds[3]) bounds[3] = points[j + 1]\r\n    }\r\n  }\r\n\r\n  return bounds\r\n}\r\n\n},{\"abs-svg-path\":60,\"assert\":68,\"is-svg-path\":424,\"normalize-svg-path\":534,\"parse-svg-path\":460}],534:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nmodule.exports = normalize\r\n\r\nvar arcToCurve = _dereq_('svg-arc-to-cubic-bezier')\r\n\r\nfunction normalize(path){\r\n  // init state\r\n  var prev\r\n  var result = []\r\n  var bezierX = 0\r\n  var bezierY = 0\r\n  var startX = 0\r\n  var startY = 0\r\n  var quadX = null\r\n  var quadY = null\r\n  var x = 0\r\n  var y = 0\r\n\r\n  for (var i = 0, len = path.length; i < len; i++) {\r\n    var seg = path[i]\r\n    var command = seg[0]\r\n\r\n    switch (command) {\r\n      case 'M':\r\n        startX = seg[1]\r\n        startY = seg[2]\r\n        break\r\n      case 'A':\r\n        var curves = arcToCurve({\r\n          px: x,\r\n          py: y,\r\n          cx: seg[6],\r\n          cy:  seg[7],\r\n          rx: seg[1],\r\n          ry: seg[2],\r\n          xAxisRotation: seg[3],\r\n          largeArcFlag: seg[4],\r\n          sweepFlag: seg[5]\r\n        })\r\n\r\n        // null-curves\r\n        if (!curves.length) continue\r\n\r\n        for (var j = 0, c; j < curves.length; j++) {\r\n          c = curves[j]\r\n          seg = ['C', c.x1, c.y1, c.x2, c.y2, c.x, c.y]\r\n          if (j < curves.length - 1) result.push(seg)\r\n        }\r\n\r\n        break\r\n      case 'S':\r\n        // default control point\r\n        var cx = x\r\n        var cy = y\r\n        if (prev == 'C' || prev == 'S') {\r\n          cx += cx - bezierX // reflect the previous command's control\r\n          cy += cy - bezierY // point relative to the current point\r\n        }\r\n        seg = ['C', cx, cy, seg[1], seg[2], seg[3], seg[4]]\r\n        break\r\n      case 'T':\r\n        if (prev == 'Q' || prev == 'T') {\r\n          quadX = x * 2 - quadX // as with 'S' reflect previous control point\r\n          quadY = y * 2 - quadY\r\n        } else {\r\n          quadX = x\r\n          quadY = y\r\n        }\r\n        seg = quadratic(x, y, quadX, quadY, seg[1], seg[2])\r\n        break\r\n      case 'Q':\r\n        quadX = seg[1]\r\n        quadY = seg[2]\r\n        seg = quadratic(x, y, seg[1], seg[2], seg[3], seg[4])\r\n        break\r\n      case 'L':\r\n        seg = line(x, y, seg[1], seg[2])\r\n        break\r\n      case 'H':\r\n        seg = line(x, y, seg[1], y)\r\n        break\r\n      case 'V':\r\n        seg = line(x, y, x, seg[1])\r\n        break\r\n      case 'Z':\r\n        seg = line(x, y, startX, startY)\r\n        break\r\n    }\r\n\r\n    // update state\r\n    prev = command\r\n    x = seg[seg.length - 2]\r\n    y = seg[seg.length - 1]\r\n    if (seg.length > 4) {\r\n      bezierX = seg[seg.length - 4]\r\n      bezierY = seg[seg.length - 3]\r\n    } else {\r\n      bezierX = x\r\n      bezierY = y\r\n    }\r\n    result.push(seg)\r\n  }\r\n\r\n  return result\r\n}\r\n\r\nfunction line(x1, y1, x2, y2){\r\n  return ['C', x1, y1, x2, y2, x2, y2]\r\n}\r\n\r\nfunction quadratic(x1, y1, cx, cy, x2, y2){\r\n  return [\r\n    'C',\r\n    x1/3 + (2/3) * cx,\r\n    y1/3 + (2/3) * cy,\r\n    x2/3 + (2/3) * cx,\r\n    y2/3 + (2/3) * cy,\r\n    x2,\r\n    y2\r\n  ]\r\n}\r\n\n},{\"svg-arc-to-cubic-bezier\":532}],535:[function(_dereq_,module,exports){\n'use strict'\r\n\r\nvar pathBounds = _dereq_('svg-path-bounds')\r\nvar parsePath = _dereq_('parse-svg-path')\r\nvar drawPath = _dereq_('draw-svg-path')\r\nvar isSvgPath = _dereq_('is-svg-path')\r\nvar bitmapSdf = _dereq_('bitmap-sdf')\r\n\r\nvar canvas = document.createElement('canvas')\r\nvar ctx = canvas.getContext('2d')\r\n\r\n\r\nmodule.exports = pathSdf\r\n\r\n\r\nfunction pathSdf (path, options) {\r\n\tif (!isSvgPath(path)) throw Error('Argument should be valid svg path string')\r\n\r\n\tif (!options) options = {}\r\n\r\n\tvar w, h\r\n\tif (options.shape) {\r\n\t\tw = options.shape[0]\r\n\t\th = options.shape[1]\r\n\t}\r\n\telse {\r\n\t\tw = canvas.width = options.w || options.width || 200\r\n\t\th = canvas.height = options.h || options.height || 200\r\n\t}\r\n\tvar size = Math.min(w, h)\r\n\r\n\tvar stroke = options.stroke || 0\r\n\r\n\tvar viewbox = options.viewbox || options.viewBox || pathBounds(path)\r\n\tvar scale = [w / (viewbox[2] - viewbox[0]), h / (viewbox[3] - viewbox[1])]\r\n\tvar maxScale = Math.min(scale[0] || 0, scale[1] || 0) / 2\r\n\r\n\t//clear ctx\r\n\tctx.fillStyle = 'black'\r\n\tctx.fillRect(0, 0, w, h)\r\n\r\n\tctx.fillStyle = 'white'\r\n\r\n\tif (stroke)\t{\r\n\t\tif (typeof stroke != 'number') stroke = 1\r\n\t\tif (stroke > 0) {\r\n\t\t\tctx.strokeStyle = 'white'\r\n\t\t}\r\n\t\telse {\r\n\t\t\tctx.strokeStyle = 'black'\r\n\t\t}\r\n\r\n\t\tctx.lineWidth = Math.abs(stroke)\r\n\t}\r\n\r\n\tctx.translate(w * .5, h * .5)\r\n\tctx.scale(maxScale, maxScale)\r\n\r\n\t//if canvas svg paths api is available\r\n\tif (isPath2DSupported()) {\r\n\t\tvar path2d = new Path2D(path)\r\n\t\tctx.fill(path2d)\r\n\t\tstroke && ctx.stroke(path2d)\r\n\t}\r\n\t//fallback to bezier-curves\r\n\telse {\r\n\t\tvar segments = parsePath(path)\r\n\t\tdrawPath(ctx, segments)\r\n\t\tctx.fill()\r\n\t\tstroke && ctx.stroke()\r\n\t}\r\n\r\n\tctx.setTransform(1, 0, 0, 1, 0, 0);\r\n\r\n\tvar data = bitmapSdf(ctx, {\r\n\t\tcutoff: options.cutoff != null ? options.cutoff : .5,\r\n\t\tradius: options.radius != null ? options.radius : size * .5\r\n\t})\r\n\r\n\treturn data\r\n}\r\n\r\nvar path2DSupported\r\n\r\nfunction isPath2DSupported () {\r\n\tif (path2DSupported != null) return path2DSupported\r\n\r\n\tvar ctx = document.createElement('canvas').getContext('2d')\r\n\tctx.canvas.width = ctx.canvas.height = 1\r\n\r\n\tif (!window.Path2D) return path2DSupported = false\r\n\r\n\tvar path = new Path2D('M0,0h1v1h-1v-1Z')\r\n\r\n\tctx.fillStyle = 'black'\r\n\tctx.fill(path)\r\n\r\n\tvar idata = ctx.getImageData(0,0,1,1)\r\n\r\n\treturn path2DSupported = idata && idata.data && idata.data[3] === 255\r\n}\r\n\n},{\"bitmap-sdf\":93,\"draw-svg-path\":168,\"is-svg-path\":424,\"parse-svg-path\":460,\"svg-path-bounds\":533}],536:[function(_dereq_,module,exports){\n(function (process){\n'use strict'\n\nmodule.exports = textGet\n\nvar vectorizeText = _dereq_('vectorize-text')\n\nvar globals = window || process.global || {}\nvar __TEXT_CACHE  = globals.__TEXT_CACHE || {}\nglobals.__TEXT_CACHE = {}\n\nfunction unwrap(mesh) {\n  var cells     = mesh.cells\n  var positions = mesh.positions\n  var data      = new Float32Array(cells.length * 6)\n  var ptr       = 0\n  var shapeX    = 0\n  for(var i=0; i<cells.length; ++i) {\n    var tri = cells[i]\n    for(var j=0; j<3; ++j) {\n      var point = positions[tri[j]]\n      data[ptr++] = point[0]\n      data[ptr++] = point[1] + 1.4\n      shapeX      = Math.max(point[0], shapeX)\n    }\n  }\n  return {\n    data:  data,\n    shape: shapeX\n  }\n}\n\nfunction textGet(font, text, opts) {\n  var opts = opts || {}\n  var fontcache = __TEXT_CACHE[font]\n  if(!fontcache) {\n    fontcache = __TEXT_CACHE[font] = {\n      ' ': {\n        data:   new Float32Array(0),\n        shape: 0.2\n      }\n    }\n  }\n  var mesh = fontcache[text]\n  if(!mesh) {\n    if(text.length <= 1 || !/\\d/.test(text)) {\n      mesh = fontcache[text] = unwrap(vectorizeText(text, {\n        triangles:     true,\n        font:          font,\n        textAlign:     opts.textAlign || 'left',\n        textBaseline:  'alphabetic',\n        styletags: {\n            breaklines: true,\n                 bolds: true,\n               italics: true,\n            subscripts: true,\n          superscripts: true\n        }\n      }))\n    } else {\n      var parts = text.split(/(\\d|\\s)/)\n      var buffer = new Array(parts.length)\n      var bufferSize = 0\n      var shapeX = 0\n      for(var i=0; i<parts.length; ++i) {\n        buffer[i] = textGet(font, parts[i])\n        bufferSize += buffer[i].data.length\n        shapeX += buffer[i].shape\n        if(i>0) {\n          shapeX += 0.02\n        }\n      }\n\n      var data = new Float32Array(bufferSize)\n      var ptr     = 0\n      var xOffset = -0.5 * shapeX\n      for(var i=0; i<buffer.length; ++i) {\n        var bdata = buffer[i].data\n        for(var j=0; j<bdata.length; j+=2) {\n          data[ptr++] = bdata[j] + xOffset\n          data[ptr++] = bdata[j+1]\n        }\n        xOffset += buffer[i].shape + 0.02\n      }\n\n      mesh = fontcache[text] = {\n        data:  data,\n        shape: shapeX\n      }\n    }\n  }\n\n   return mesh\n}\n\n}).call(this,_dereq_('_process'))\n},{\"_process\":482,\"vectorize-text\":550}],537:[function(_dereq_,module,exports){\n// TinyColor v1.4.1\n// https://github.com/bgrins/TinyColor\n// Brian Grinstead, MIT License\n\n(function(Math) {\n\nvar trimLeft = /^\\s+/,\n    trimRight = /\\s+$/,\n    tinyCounter = 0,\n    mathRound = Math.round,\n    mathMin = Math.min,\n    mathMax = Math.max,\n    mathRandom = Math.random;\n\nfunction tinycolor (color, opts) {\n\n    color = (color) ? color : '';\n    opts = opts || { };\n\n    // If input is already a tinycolor, return itself\n    if (color instanceof tinycolor) {\n       return color;\n    }\n    // If we are called as a function, call using new instead\n    if (!(this instanceof tinycolor)) {\n        return new tinycolor(color, opts);\n    }\n\n    var rgb = inputToRGB(color);\n    this._originalInput = color,\n    this._r = rgb.r,\n    this._g = rgb.g,\n    this._b = rgb.b,\n    this._a = rgb.a,\n    this._roundA = mathRound(100*this._a) / 100,\n    this._format = opts.format || rgb.format;\n    this._gradientType = opts.gradientType;\n\n    // Don't let the range of [0,255] come back in [0,1].\n    // Potentially lose a little bit of precision here, but will fix issues where\n    // .5 gets interpreted as half of the total, instead of half of 1\n    // If it was supposed to be 128, this was already taken care of by `inputToRgb`\n    if (this._r < 1) { this._r = mathRound(this._r); }\n    if (this._g < 1) { this._g = mathRound(this._g); }\n    if (this._b < 1) { this._b = mathRound(this._b); }\n\n    this._ok = rgb.ok;\n    this._tc_id = tinyCounter++;\n}\n\ntinycolor.prototype = {\n    isDark: function() {\n        return this.getBrightness() < 128;\n    },\n    isLight: function() {\n        return !this.isDark();\n    },\n    isValid: function() {\n        return this._ok;\n    },\n    getOriginalInput: function() {\n      return this._originalInput;\n    },\n    getFormat: function() {\n        return this._format;\n    },\n    getAlpha: function() {\n        return this._a;\n    },\n    getBrightness: function() {\n        //http://www.w3.org/TR/AERT#color-contrast\n        var rgb = this.toRgb();\n        return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;\n    },\n    getLuminance: function() {\n        //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef\n        var rgb = this.toRgb();\n        var RsRGB, GsRGB, BsRGB, R, G, B;\n        RsRGB = rgb.r/255;\n        GsRGB = rgb.g/255;\n        BsRGB = rgb.b/255;\n\n        if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}\n        if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}\n        if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}\n        return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);\n    },\n    setAlpha: function(value) {\n        this._a = boundAlpha(value);\n        this._roundA = mathRound(100*this._a) / 100;\n        return this;\n    },\n    toHsv: function() {\n        var hsv = rgbToHsv(this._r, this._g, this._b);\n        return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };\n    },\n    toHsvString: function() {\n        var hsv = rgbToHsv(this._r, this._g, this._b);\n        var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);\n        return (this._a == 1) ?\n          \"hsv(\"  + h + \", \" + s + \"%, \" + v + \"%)\" :\n          \"hsva(\" + h + \", \" + s + \"%, \" + v + \"%, \"+ this._roundA + \")\";\n    },\n    toHsl: function() {\n        var hsl = rgbToHsl(this._r, this._g, this._b);\n        return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };\n    },\n    toHslString: function() {\n        var hsl = rgbToHsl(this._r, this._g, this._b);\n        var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);\n        return (this._a == 1) ?\n          \"hsl(\"  + h + \", \" + s + \"%, \" + l + \"%)\" :\n          \"hsla(\" + h + \", \" + s + \"%, \" + l + \"%, \"+ this._roundA + \")\";\n    },\n    toHex: function(allow3Char) {\n        return rgbToHex(this._r, this._g, this._b, allow3Char);\n    },\n    toHexString: function(allow3Char) {\n        return '#' + this.toHex(allow3Char);\n    },\n    toHex8: function(allow4Char) {\n        return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);\n    },\n    toHex8String: function(allow4Char) {\n        return '#' + this.toHex8(allow4Char);\n    },\n    toRgb: function() {\n        return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };\n    },\n    toRgbString: function() {\n        return (this._a == 1) ?\n          \"rgb(\"  + mathRound(this._r) + \", \" + mathRound(this._g) + \", \" + mathRound(this._b) + \")\" :\n          \"rgba(\" + mathRound(this._r) + \", \" + mathRound(this._g) + \", \" + mathRound(this._b) + \", \" + this._roundA + \")\";\n    },\n    toPercentageRgb: function() {\n        return { r: mathRound(bound01(this._r, 255) * 100) + \"%\", g: mathRound(bound01(this._g, 255) * 100) + \"%\", b: mathRound(bound01(this._b, 255) * 100) + \"%\", a: this._a };\n    },\n    toPercentageRgbString: function() {\n        return (this._a == 1) ?\n          \"rgb(\"  + mathRound(bound01(this._r, 255) * 100) + \"%, \" + mathRound(bound01(this._g, 255) * 100) + \"%, \" + mathRound(bound01(this._b, 255) * 100) + \"%)\" :\n          \"rgba(\" + mathRound(bound01(this._r, 255) * 100) + \"%, \" + mathRound(bound01(this._g, 255) * 100) + \"%, \" + mathRound(bound01(this._b, 255) * 100) + \"%, \" + this._roundA + \")\";\n    },\n    toName: function() {\n        if (this._a === 0) {\n            return \"transparent\";\n        }\n\n        if (this._a < 1) {\n            return false;\n        }\n\n        return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;\n    },\n    toFilter: function(secondColor) {\n        var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);\n        var secondHex8String = hex8String;\n        var gradientType = this._gradientType ? \"GradientType = 1, \" : \"\";\n\n        if (secondColor) {\n            var s = tinycolor(secondColor);\n            secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);\n        }\n\n        return \"progid:DXImageTransform.Microsoft.gradient(\"+gradientType+\"startColorstr=\"+hex8String+\",endColorstr=\"+secondHex8String+\")\";\n    },\n    toString: function(format) {\n        var formatSet = !!format;\n        format = format || this._format;\n\n        var formattedString = false;\n        var hasAlpha = this._a < 1 && this._a >= 0;\n        var needsAlphaFormat = !formatSet && hasAlpha && (format === \"hex\" || format === \"hex6\" || format === \"hex3\" || format === \"hex4\" || format === \"hex8\" || format === \"name\");\n\n        if (needsAlphaFormat) {\n            // Special case for \"transparent\", all other non-alpha formats\n            // will return rgba when there is transparency.\n            if (format === \"name\" && this._a === 0) {\n                return this.toName();\n            }\n            return this.toRgbString();\n        }\n        if (format === \"rgb\") {\n            formattedString = this.toRgbString();\n        }\n        if (format === \"prgb\") {\n            formattedString = this.toPercentageRgbString();\n        }\n        if (format === \"hex\" || format === \"hex6\") {\n            formattedString = this.toHexString();\n        }\n        if (format === \"hex3\") {\n            formattedString = this.toHexString(true);\n        }\n        if (format === \"hex4\") {\n            formattedString = this.toHex8String(true);\n        }\n        if (format === \"hex8\") {\n            formattedString = this.toHex8String();\n        }\n        if (format === \"name\") {\n            formattedString = this.toName();\n        }\n        if (format === \"hsl\") {\n            formattedString = this.toHslString();\n        }\n        if (format === \"hsv\") {\n            formattedString = this.toHsvString();\n        }\n\n        return formattedString || this.toHexString();\n    },\n    clone: function() {\n        return tinycolor(this.toString());\n    },\n\n    _applyModification: function(fn, args) {\n        var color = fn.apply(null, [this].concat([].slice.call(args)));\n        this._r = color._r;\n        this._g = color._g;\n        this._b = color._b;\n        this.setAlpha(color._a);\n        return this;\n    },\n    lighten: function() {\n        return this._applyModification(lighten, arguments);\n    },\n    brighten: function() {\n        return this._applyModification(brighten, arguments);\n    },\n    darken: function() {\n        return this._applyModification(darken, arguments);\n    },\n    desaturate: function() {\n        return this._applyModification(desaturate, arguments);\n    },\n    saturate: function() {\n        return this._applyModification(saturate, arguments);\n    },\n    greyscale: function() {\n        return this._applyModification(greyscale, arguments);\n    },\n    spin: function() {\n        return this._applyModification(spin, arguments);\n    },\n\n    _applyCombination: function(fn, args) {\n        return fn.apply(null, [this].concat([].slice.call(args)));\n    },\n    analogous: function() {\n        return this._applyCombination(analogous, arguments);\n    },\n    complement: function() {\n        return this._applyCombination(complement, arguments);\n    },\n    monochromatic: function() {\n        return this._applyCombination(monochromatic, arguments);\n    },\n    splitcomplement: function() {\n        return this._applyCombination(splitcomplement, arguments);\n    },\n    triad: function() {\n        return this._applyCombination(triad, arguments);\n    },\n    tetrad: function() {\n        return this._applyCombination(tetrad, arguments);\n    }\n};\n\n// If input is an object, force 1 into \"1.0\" to handle ratios properly\n// String input requires \"1.0\" as input, so 1 will be treated as 1\ntinycolor.fromRatio = function(color, opts) {\n    if (typeof color == \"object\") {\n        var newColor = {};\n        for (var i in color) {\n            if (color.hasOwnProperty(i)) {\n                if (i === \"a\") {\n                    newColor[i] = color[i];\n                }\n                else {\n                    newColor[i] = convertToPercentage(color[i]);\n                }\n            }\n        }\n        color = newColor;\n    }\n\n    return tinycolor(color, opts);\n};\n\n// Given a string or object, convert that input to RGB\n// Possible string inputs:\n//\n//     \"red\"\n//     \"#f00\" or \"f00\"\n//     \"#ff0000\" or \"ff0000\"\n//     \"#ff000000\" or \"ff000000\"\n//     \"rgb 255 0 0\" or \"rgb (255, 0, 0)\"\n//     \"rgb 1.0 0 0\" or \"rgb (1, 0, 0)\"\n//     \"rgba (255, 0, 0, 1)\" or \"rgba 255, 0, 0, 1\"\n//     \"rgba (1.0, 0, 0, 1)\" or \"rgba 1.0, 0, 0, 1\"\n//     \"hsl(0, 100%, 50%)\" or \"hsl 0 100% 50%\"\n//     \"hsla(0, 100%, 50%, 1)\" or \"hsla 0 100% 50%, 1\"\n//     \"hsv(0, 100%, 100%)\" or \"hsv 0 100% 100%\"\n//\nfunction inputToRGB(color) {\n\n    var rgb = { r: 0, g: 0, b: 0 };\n    var a = 1;\n    var s = null;\n    var v = null;\n    var l = null;\n    var ok = false;\n    var format = false;\n\n    if (typeof color == \"string\") {\n        color = stringInputToObject(color);\n    }\n\n    if (typeof color == \"object\") {\n        if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {\n            rgb = rgbToRgb(color.r, color.g, color.b);\n            ok = true;\n            format = String(color.r).substr(-1) === \"%\" ? \"prgb\" : \"rgb\";\n        }\n        else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {\n            s = convertToPercentage(color.s);\n            v = convertToPercentage(color.v);\n            rgb = hsvToRgb(color.h, s, v);\n            ok = true;\n            format = \"hsv\";\n        }\n        else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {\n            s = convertToPercentage(color.s);\n            l = convertToPercentage(color.l);\n            rgb = hslToRgb(color.h, s, l);\n            ok = true;\n            format = \"hsl\";\n        }\n\n        if (color.hasOwnProperty(\"a\")) {\n            a = color.a;\n        }\n    }\n\n    a = boundAlpha(a);\n\n    return {\n        ok: ok,\n        format: color.format || format,\n        r: mathMin(255, mathMax(rgb.r, 0)),\n        g: mathMin(255, mathMax(rgb.g, 0)),\n        b: mathMin(255, mathMax(rgb.b, 0)),\n        a: a\n    };\n}\n\n\n// Conversion Functions\n// --------------------\n\n// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:\n// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>\n\n// `rgbToRgb`\n// Handle bounds / percentage checking to conform to CSS color spec\n// <http://www.w3.org/TR/css3-color/>\n// *Assumes:* r, g, b in [0, 255] or [0, 1]\n// *Returns:* { r, g, b } in [0, 255]\nfunction rgbToRgb(r, g, b){\n    return {\n        r: bound01(r, 255) * 255,\n        g: bound01(g, 255) * 255,\n        b: bound01(b, 255) * 255\n    };\n}\n\n// `rgbToHsl`\n// Converts an RGB color value to HSL.\n// *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]\n// *Returns:* { h, s, l } in [0,1]\nfunction rgbToHsl(r, g, b) {\n\n    r = bound01(r, 255);\n    g = bound01(g, 255);\n    b = bound01(b, 255);\n\n    var max = mathMax(r, g, b), min = mathMin(r, g, b);\n    var h, s, l = (max + min) / 2;\n\n    if(max == min) {\n        h = s = 0; // achromatic\n    }\n    else {\n        var d = max - min;\n        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n        switch(max) {\n            case r: h = (g - b) / d + (g < b ? 6 : 0); break;\n            case g: h = (b - r) / d + 2; break;\n            case b: h = (r - g) / d + 4; break;\n        }\n\n        h /= 6;\n    }\n\n    return { h: h, s: s, l: l };\n}\n\n// `hslToRgb`\n// Converts an HSL color value to RGB.\n// *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]\n// *Returns:* { r, g, b } in the set [0, 255]\nfunction hslToRgb(h, s, l) {\n    var r, g, b;\n\n    h = bound01(h, 360);\n    s = bound01(s, 100);\n    l = bound01(l, 100);\n\n    function hue2rgb(p, q, t) {\n        if(t < 0) t += 1;\n        if(t > 1) t -= 1;\n        if(t < 1/6) return p + (q - p) * 6 * t;\n        if(t < 1/2) return q;\n        if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;\n        return p;\n    }\n\n    if(s === 0) {\n        r = g = b = l; // achromatic\n    }\n    else {\n        var q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n        var p = 2 * l - q;\n        r = hue2rgb(p, q, h + 1/3);\n        g = hue2rgb(p, q, h);\n        b = hue2rgb(p, q, h - 1/3);\n    }\n\n    return { r: r * 255, g: g * 255, b: b * 255 };\n}\n\n// `rgbToHsv`\n// Converts an RGB color value to HSV\n// *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]\n// *Returns:* { h, s, v } in [0,1]\nfunction rgbToHsv(r, g, b) {\n\n    r = bound01(r, 255);\n    g = bound01(g, 255);\n    b = bound01(b, 255);\n\n    var max = mathMax(r, g, b), min = mathMin(r, g, b);\n    var h, s, v = max;\n\n    var d = max - min;\n    s = max === 0 ? 0 : d / max;\n\n    if(max == min) {\n        h = 0; // achromatic\n    }\n    else {\n        switch(max) {\n            case r: h = (g - b) / d + (g < b ? 6 : 0); break;\n            case g: h = (b - r) / d + 2; break;\n            case b: h = (r - g) / d + 4; break;\n        }\n        h /= 6;\n    }\n    return { h: h, s: s, v: v };\n}\n\n// `hsvToRgb`\n// Converts an HSV color value to RGB.\n// *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]\n// *Returns:* { r, g, b } in the set [0, 255]\n function hsvToRgb(h, s, v) {\n\n    h = bound01(h, 360) * 6;\n    s = bound01(s, 100);\n    v = bound01(v, 100);\n\n    var i = Math.floor(h),\n        f = h - i,\n        p = v * (1 - s),\n        q = v * (1 - f * s),\n        t = v * (1 - (1 - f) * s),\n        mod = i % 6,\n        r = [v, q, p, p, t, v][mod],\n        g = [t, v, v, q, p, p][mod],\n        b = [p, p, t, v, v, q][mod];\n\n    return { r: r * 255, g: g * 255, b: b * 255 };\n}\n\n// `rgbToHex`\n// Converts an RGB color to hex\n// Assumes r, g, and b are contained in the set [0, 255]\n// Returns a 3 or 6 character hex\nfunction rgbToHex(r, g, b, allow3Char) {\n\n    var hex = [\n        pad2(mathRound(r).toString(16)),\n        pad2(mathRound(g).toString(16)),\n        pad2(mathRound(b).toString(16))\n    ];\n\n    // Return a 3 character hex if possible\n    if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {\n        return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);\n    }\n\n    return hex.join(\"\");\n}\n\n// `rgbaToHex`\n// Converts an RGBA color plus alpha transparency to hex\n// Assumes r, g, b are contained in the set [0, 255] and\n// a in [0, 1]. Returns a 4 or 8 character rgba hex\nfunction rgbaToHex(r, g, b, a, allow4Char) {\n\n    var hex = [\n        pad2(mathRound(r).toString(16)),\n        pad2(mathRound(g).toString(16)),\n        pad2(mathRound(b).toString(16)),\n        pad2(convertDecimalToHex(a))\n    ];\n\n    // Return a 4 character hex if possible\n    if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {\n        return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);\n    }\n\n    return hex.join(\"\");\n}\n\n// `rgbaToArgbHex`\n// Converts an RGBA color to an ARGB Hex8 string\n// Rarely used, but required for \"toFilter()\"\nfunction rgbaToArgbHex(r, g, b, a) {\n\n    var hex = [\n        pad2(convertDecimalToHex(a)),\n        pad2(mathRound(r).toString(16)),\n        pad2(mathRound(g).toString(16)),\n        pad2(mathRound(b).toString(16))\n    ];\n\n    return hex.join(\"\");\n}\n\n// `equals`\n// Can be called with any tinycolor input\ntinycolor.equals = function (color1, color2) {\n    if (!color1 || !color2) { return false; }\n    return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();\n};\n\ntinycolor.random = function() {\n    return tinycolor.fromRatio({\n        r: mathRandom(),\n        g: mathRandom(),\n        b: mathRandom()\n    });\n};\n\n\n// Modification Functions\n// ----------------------\n// Thanks to less.js for some of the basics here\n// <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>\n\nfunction desaturate(color, amount) {\n    amount = (amount === 0) ? 0 : (amount || 10);\n    var hsl = tinycolor(color).toHsl();\n    hsl.s -= amount / 100;\n    hsl.s = clamp01(hsl.s);\n    return tinycolor(hsl);\n}\n\nfunction saturate(color, amount) {\n    amount = (amount === 0) ? 0 : (amount || 10);\n    var hsl = tinycolor(color).toHsl();\n    hsl.s += amount / 100;\n    hsl.s = clamp01(hsl.s);\n    return tinycolor(hsl);\n}\n\nfunction greyscale(color) {\n    return tinycolor(color).desaturate(100);\n}\n\nfunction lighten (color, amount) {\n    amount = (amount === 0) ? 0 : (amount || 10);\n    var hsl = tinycolor(color).toHsl();\n    hsl.l += amount / 100;\n    hsl.l = clamp01(hsl.l);\n    return tinycolor(hsl);\n}\n\nfunction brighten(color, amount) {\n    amount = (amount === 0) ? 0 : (amount || 10);\n    var rgb = tinycolor(color).toRgb();\n    rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));\n    rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));\n    rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));\n    return tinycolor(rgb);\n}\n\nfunction darken (color, amount) {\n    amount = (amount === 0) ? 0 : (amount || 10);\n    var hsl = tinycolor(color).toHsl();\n    hsl.l -= amount / 100;\n    hsl.l = clamp01(hsl.l);\n    return tinycolor(hsl);\n}\n\n// Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.\n// Values outside of this range will be wrapped into this range.\nfunction spin(color, amount) {\n    var hsl = tinycolor(color).toHsl();\n    var hue = (hsl.h + amount) % 360;\n    hsl.h = hue < 0 ? 360 + hue : hue;\n    return tinycolor(hsl);\n}\n\n// Combination Functions\n// ---------------------\n// Thanks to jQuery xColor for some of the ideas behind these\n// <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>\n\nfunction complement(color) {\n    var hsl = tinycolor(color).toHsl();\n    hsl.h = (hsl.h + 180) % 360;\n    return tinycolor(hsl);\n}\n\nfunction triad(color) {\n    var hsl = tinycolor(color).toHsl();\n    var h = hsl.h;\n    return [\n        tinycolor(color),\n        tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),\n        tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })\n    ];\n}\n\nfunction tetrad(color) {\n    var hsl = tinycolor(color).toHsl();\n    var h = hsl.h;\n    return [\n        tinycolor(color),\n        tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),\n        tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),\n        tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })\n    ];\n}\n\nfunction splitcomplement(color) {\n    var hsl = tinycolor(color).toHsl();\n    var h = hsl.h;\n    return [\n        tinycolor(color),\n        tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),\n        tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})\n    ];\n}\n\nfunction analogous(color, results, slices) {\n    results = results || 6;\n    slices = slices || 30;\n\n    var hsl = tinycolor(color).toHsl();\n    var part = 360 / slices;\n    var ret = [tinycolor(color)];\n\n    for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {\n        hsl.h = (hsl.h + part) % 360;\n        ret.push(tinycolor(hsl));\n    }\n    return ret;\n}\n\nfunction monochromatic(color, results) {\n    results = results || 6;\n    var hsv = tinycolor(color).toHsv();\n    var h = hsv.h, s = hsv.s, v = hsv.v;\n    var ret = [];\n    var modification = 1 / results;\n\n    while (results--) {\n        ret.push(tinycolor({ h: h, s: s, v: v}));\n        v = (v + modification) % 1;\n    }\n\n    return ret;\n}\n\n// Utility Functions\n// ---------------------\n\ntinycolor.mix = function(color1, color2, amount) {\n    amount = (amount === 0) ? 0 : (amount || 50);\n\n    var rgb1 = tinycolor(color1).toRgb();\n    var rgb2 = tinycolor(color2).toRgb();\n\n    var p = amount / 100;\n\n    var rgba = {\n        r: ((rgb2.r - rgb1.r) * p) + rgb1.r,\n        g: ((rgb2.g - rgb1.g) * p) + rgb1.g,\n        b: ((rgb2.b - rgb1.b) * p) + rgb1.b,\n        a: ((rgb2.a - rgb1.a) * p) + rgb1.a\n    };\n\n    return tinycolor(rgba);\n};\n\n\n// Readability Functions\n// ---------------------\n// <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)\n\n// `contrast`\n// Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)\ntinycolor.readability = function(color1, color2) {\n    var c1 = tinycolor(color1);\n    var c2 = tinycolor(color2);\n    return (Math.max(c1.getLuminance(),c2.getLuminance())+0.05) / (Math.min(c1.getLuminance(),c2.getLuminance())+0.05);\n};\n\n// `isReadable`\n// Ensure that foreground and background color combinations meet WCAG2 guidelines.\n// The third argument is an optional Object.\n//      the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';\n//      the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.\n// If the entire object is absent, isReadable defaults to {level:\"AA\",size:\"small\"}.\n\n// *Example*\n//    tinycolor.isReadable(\"#000\", \"#111\") => false\n//    tinycolor.isReadable(\"#000\", \"#111\",{level:\"AA\",size:\"large\"}) => false\ntinycolor.isReadable = function(color1, color2, wcag2) {\n    var readability = tinycolor.readability(color1, color2);\n    var wcag2Parms, out;\n\n    out = false;\n\n    wcag2Parms = validateWCAG2Parms(wcag2);\n    switch (wcag2Parms.level + wcag2Parms.size) {\n        case \"AAsmall\":\n        case \"AAAlarge\":\n            out = readability >= 4.5;\n            break;\n        case \"AAlarge\":\n            out = readability >= 3;\n            break;\n        case \"AAAsmall\":\n            out = readability >= 7;\n            break;\n    }\n    return out;\n\n};\n\n// `mostReadable`\n// Given a base color and a list of possible foreground or background\n// colors for that base, returns the most readable color.\n// Optionally returns Black or White if the most readable color is unreadable.\n// *Example*\n//    tinycolor.mostReadable(tinycolor.mostReadable(\"#123\", [\"#124\", \"#125\"],{includeFallbackColors:false}).toHexString(); // \"#112255\"\n//    tinycolor.mostReadable(tinycolor.mostReadable(\"#123\", [\"#124\", \"#125\"],{includeFallbackColors:true}).toHexString();  // \"#ffffff\"\n//    tinycolor.mostReadable(\"#a8015a\", [\"#faf3f3\"],{includeFallbackColors:true,level:\"AAA\",size:\"large\"}).toHexString(); // \"#faf3f3\"\n//    tinycolor.mostReadable(\"#a8015a\", [\"#faf3f3\"],{includeFallbackColors:true,level:\"AAA\",size:\"small\"}).toHexString(); // \"#ffffff\"\ntinycolor.mostReadable = function(baseColor, colorList, args) {\n    var bestColor = null;\n    var bestScore = 0;\n    var readability;\n    var includeFallbackColors, level, size ;\n    args = args || {};\n    includeFallbackColors = args.includeFallbackColors ;\n    level = args.level;\n    size = args.size;\n\n    for (var i= 0; i < colorList.length ; i++) {\n        readability = tinycolor.readability(baseColor, colorList[i]);\n        if (readability > bestScore) {\n            bestScore = readability;\n            bestColor = tinycolor(colorList[i]);\n        }\n    }\n\n    if (tinycolor.isReadable(baseColor, bestColor, {\"level\":level,\"size\":size}) || !includeFallbackColors) {\n        return bestColor;\n    }\n    else {\n        args.includeFallbackColors=false;\n        return tinycolor.mostReadable(baseColor,[\"#fff\", \"#000\"],args);\n    }\n};\n\n\n// Big List of Colors\n// ------------------\n// <http://www.w3.org/TR/css3-color/#svg-color>\nvar names = tinycolor.names = {\n    aliceblue: \"f0f8ff\",\n    antiquewhite: \"faebd7\",\n    aqua: \"0ff\",\n    aquamarine: \"7fffd4\",\n    azure: \"f0ffff\",\n    beige: \"f5f5dc\",\n    bisque: \"ffe4c4\",\n    black: \"000\",\n    blanchedalmond: \"ffebcd\",\n    blue: \"00f\",\n    blueviolet: \"8a2be2\",\n    brown: \"a52a2a\",\n    burlywood: \"deb887\",\n    burntsienna: \"ea7e5d\",\n    cadetblue: \"5f9ea0\",\n    chartreuse: \"7fff00\",\n    chocolate: \"d2691e\",\n    coral: \"ff7f50\",\n    cornflowerblue: \"6495ed\",\n    cornsilk: \"fff8dc\",\n    crimson: \"dc143c\",\n    cyan: \"0ff\",\n    darkblue: \"00008b\",\n    darkcyan: \"008b8b\",\n    darkgoldenrod: \"b8860b\",\n    darkgray: \"a9a9a9\",\n    darkgreen: \"006400\",\n    darkgrey: \"a9a9a9\",\n    darkkhaki: \"bdb76b\",\n    darkmagenta: \"8b008b\",\n    darkolivegreen: \"556b2f\",\n    darkorange: \"ff8c00\",\n    darkorchid: \"9932cc\",\n    darkred: \"8b0000\",\n    darksalmon: \"e9967a\",\n    darkseagreen: \"8fbc8f\",\n    darkslateblue: \"483d8b\",\n    darkslategray: \"2f4f4f\",\n    darkslategrey: \"2f4f4f\",\n    darkturquoise: \"00ced1\",\n    darkviolet: \"9400d3\",\n    deeppink: \"ff1493\",\n    deepskyblue: \"00bfff\",\n    dimgray: \"696969\",\n    dimgrey: \"696969\",\n    dodgerblue: \"1e90ff\",\n    firebrick: \"b22222\",\n    floralwhite: \"fffaf0\",\n    forestgreen: \"228b22\",\n    fuchsia: \"f0f\",\n    gainsboro: \"dcdcdc\",\n    ghostwhite: \"f8f8ff\",\n    gold: \"ffd700\",\n    goldenrod: \"daa520\",\n    gray: \"808080\",\n    green: \"008000\",\n    greenyellow: \"adff2f\",\n    grey: \"808080\",\n    honeydew: \"f0fff0\",\n    hotpink: \"ff69b4\",\n    indianred: \"cd5c5c\",\n    indigo: \"4b0082\",\n    ivory: \"fffff0\",\n    khaki: \"f0e68c\",\n    lavender: \"e6e6fa\",\n    lavenderblush: \"fff0f5\",\n    lawngreen: \"7cfc00\",\n    lemonchiffon: \"fffacd\",\n    lightblue: \"add8e6\",\n    lightcoral: \"f08080\",\n    lightcyan: \"e0ffff\",\n    lightgoldenrodyellow: \"fafad2\",\n    lightgray: \"d3d3d3\",\n    lightgreen: \"90ee90\",\n    lightgrey: \"d3d3d3\",\n    lightpink: \"ffb6c1\",\n    lightsalmon: \"ffa07a\",\n    lightseagreen: \"20b2aa\",\n    lightskyblue: \"87cefa\",\n    lightslategray: \"789\",\n    lightslategrey: \"789\",\n    lightsteelblue: \"b0c4de\",\n    lightyellow: \"ffffe0\",\n    lime: \"0f0\",\n    limegreen: \"32cd32\",\n    linen: \"faf0e6\",\n    magenta: \"f0f\",\n    maroon: \"800000\",\n    mediumaquamarine: \"66cdaa\",\n    mediumblue: \"0000cd\",\n    mediumorchid: \"ba55d3\",\n    mediumpurple: \"9370db\",\n    mediumseagreen: \"3cb371\",\n    mediumslateblue: \"7b68ee\",\n    mediumspringgreen: \"00fa9a\",\n    mediumturquoise: \"48d1cc\",\n    mediumvioletred: \"c71585\",\n    midnightblue: \"191970\",\n    mintcream: \"f5fffa\",\n    mistyrose: \"ffe4e1\",\n    moccasin: \"ffe4b5\",\n    navajowhite: \"ffdead\",\n    navy: \"000080\",\n    oldlace: \"fdf5e6\",\n    olive: \"808000\",\n    olivedrab: \"6b8e23\",\n    orange: \"ffa500\",\n    orangered: \"ff4500\",\n    orchid: \"da70d6\",\n    palegoldenrod: \"eee8aa\",\n    palegreen: \"98fb98\",\n    paleturquoise: \"afeeee\",\n    palevioletred: \"db7093\",\n    papayawhip: \"ffefd5\",\n    peachpuff: \"ffdab9\",\n    peru: \"cd853f\",\n    pink: \"ffc0cb\",\n    plum: \"dda0dd\",\n    powderblue: \"b0e0e6\",\n    purple: \"800080\",\n    rebeccapurple: \"663399\",\n    red: \"f00\",\n    rosybrown: \"bc8f8f\",\n    royalblue: \"4169e1\",\n    saddlebrown: \"8b4513\",\n    salmon: \"fa8072\",\n    sandybrown: \"f4a460\",\n    seagreen: \"2e8b57\",\n    seashell: \"fff5ee\",\n    sienna: \"a0522d\",\n    silver: \"c0c0c0\",\n    skyblue: \"87ceeb\",\n    slateblue: \"6a5acd\",\n    slategray: \"708090\",\n    slategrey: \"708090\",\n    snow: \"fffafa\",\n    springgreen: \"00ff7f\",\n    steelblue: \"4682b4\",\n    tan: \"d2b48c\",\n    teal: \"008080\",\n    thistle: \"d8bfd8\",\n    tomato: \"ff6347\",\n    turquoise: \"40e0d0\",\n    violet: \"ee82ee\",\n    wheat: \"f5deb3\",\n    white: \"fff\",\n    whitesmoke: \"f5f5f5\",\n    yellow: \"ff0\",\n    yellowgreen: \"9acd32\"\n};\n\n// Make it easy to access colors via `hexNames[hex]`\nvar hexNames = tinycolor.hexNames = flip(names);\n\n\n// Utilities\n// ---------\n\n// `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`\nfunction flip(o) {\n    var flipped = { };\n    for (var i in o) {\n        if (o.hasOwnProperty(i)) {\n            flipped[o[i]] = i;\n        }\n    }\n    return flipped;\n}\n\n// Return a valid alpha value [0,1] with all invalid values being set to 1\nfunction boundAlpha(a) {\n    a = parseFloat(a);\n\n    if (isNaN(a) || a < 0 || a > 1) {\n        a = 1;\n    }\n\n    return a;\n}\n\n// Take input from [0, n] and return it as [0, 1]\nfunction bound01(n, max) {\n    if (isOnePointZero(n)) { n = \"100%\"; }\n\n    var processPercent = isPercentage(n);\n    n = mathMin(max, mathMax(0, parseFloat(n)));\n\n    // Automatically convert percentage into number\n    if (processPercent) {\n        n = parseInt(n * max, 10) / 100;\n    }\n\n    // Handle floating point rounding errors\n    if ((Math.abs(n - max) < 0.000001)) {\n        return 1;\n    }\n\n    // Convert into [0, 1] range if it isn't already\n    return (n % max) / parseFloat(max);\n}\n\n// Force a number between 0 and 1\nfunction clamp01(val) {\n    return mathMin(1, mathMax(0, val));\n}\n\n// Parse a base-16 hex value into a base-10 integer\nfunction parseIntFromHex(val) {\n    return parseInt(val, 16);\n}\n\n// Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1\n// <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>\nfunction isOnePointZero(n) {\n    return typeof n == \"string\" && n.indexOf('.') != -1 && parseFloat(n) === 1;\n}\n\n// Check to see if string passed in is a percentage\nfunction isPercentage(n) {\n    return typeof n === \"string\" && n.indexOf('%') != -1;\n}\n\n// Force a hex value to have 2 characters\nfunction pad2(c) {\n    return c.length == 1 ? '0' + c : '' + c;\n}\n\n// Replace a decimal with it's percentage value\nfunction convertToPercentage(n) {\n    if (n <= 1) {\n        n = (n * 100) + \"%\";\n    }\n\n    return n;\n}\n\n// Converts a decimal to a hex value\nfunction convertDecimalToHex(d) {\n    return Math.round(parseFloat(d) * 255).toString(16);\n}\n// Converts a hex value to a decimal\nfunction convertHexToDecimal(h) {\n    return (parseIntFromHex(h) / 255);\n}\n\nvar matchers = (function() {\n\n    // <http://www.w3.org/TR/css3-values/#integers>\n    var CSS_INTEGER = \"[-\\\\+]?\\\\d+%?\";\n\n    // <http://www.w3.org/TR/css3-values/#number-value>\n    var CSS_NUMBER = \"[-\\\\+]?\\\\d*\\\\.\\\\d+%?\";\n\n    // Allow positive/negative integer/number.  Don't capture the either/or, just the entire outcome.\n    var CSS_UNIT = \"(?:\" + CSS_NUMBER + \")|(?:\" + CSS_INTEGER + \")\";\n\n    // Actual matching.\n    // Parentheses and commas are optional, but not required.\n    // Whitespace can take the place of commas or opening paren\n    var PERMISSIVE_MATCH3 = \"[\\\\s|\\\\(]+(\" + CSS_UNIT + \")[,|\\\\s]+(\" + CSS_UNIT + \")[,|\\\\s]+(\" + CSS_UNIT + \")\\\\s*\\\\)?\";\n    var PERMISSIVE_MATCH4 = \"[\\\\s|\\\\(]+(\" + CSS_UNIT + \")[,|\\\\s]+(\" + CSS_UNIT + \")[,|\\\\s]+(\" + CSS_UNIT + \")[,|\\\\s]+(\" + CSS_UNIT + \")\\\\s*\\\\)?\";\n\n    return {\n        CSS_UNIT: new RegExp(CSS_UNIT),\n        rgb: new RegExp(\"rgb\" + PERMISSIVE_MATCH3),\n        rgba: new RegExp(\"rgba\" + PERMISSIVE_MATCH4),\n        hsl: new RegExp(\"hsl\" + PERMISSIVE_MATCH3),\n        hsla: new RegExp(\"hsla\" + PERMISSIVE_MATCH4),\n        hsv: new RegExp(\"hsv\" + PERMISSIVE_MATCH3),\n        hsva: new RegExp(\"hsva\" + PERMISSIVE_MATCH4),\n        hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,\n        hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,\n        hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,\n        hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/\n    };\n})();\n\n// `isValidCSSUnit`\n// Take in a single string / number and check to see if it looks like a CSS unit\n// (see `matchers` above for definition).\nfunction isValidCSSUnit(color) {\n    return !!matchers.CSS_UNIT.exec(color);\n}\n\n// `stringInputToObject`\n// Permissive string parsing.  Take in a number of formats, and output an object\n// based on detected format.  Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`\nfunction stringInputToObject(color) {\n\n    color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();\n    var named = false;\n    if (names[color]) {\n        color = names[color];\n        named = true;\n    }\n    else if (color == 'transparent') {\n        return { r: 0, g: 0, b: 0, a: 0, format: \"name\" };\n    }\n\n    // Try to match string input using regular expressions.\n    // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]\n    // Just return an object and let the conversion functions handle that.\n    // This way the result will be the same whether the tinycolor is initialized with string or object.\n    var match;\n    if ((match = matchers.rgb.exec(color))) {\n        return { r: match[1], g: match[2], b: match[3] };\n    }\n    if ((match = matchers.rgba.exec(color))) {\n        return { r: match[1], g: match[2], b: match[3], a: match[4] };\n    }\n    if ((match = matchers.hsl.exec(color))) {\n        return { h: match[1], s: match[2], l: match[3] };\n    }\n    if ((match = matchers.hsla.exec(color))) {\n        return { h: match[1], s: match[2], l: match[3], a: match[4] };\n    }\n    if ((match = matchers.hsv.exec(color))) {\n        return { h: match[1], s: match[2], v: match[3] };\n    }\n    if ((match = matchers.hsva.exec(color))) {\n        return { h: match[1], s: match[2], v: match[3], a: match[4] };\n    }\n    if ((match = matchers.hex8.exec(color))) {\n        return {\n            r: parseIntFromHex(match[1]),\n            g: parseIntFromHex(match[2]),\n            b: parseIntFromHex(match[3]),\n            a: convertHexToDecimal(match[4]),\n            format: named ? \"name\" : \"hex8\"\n        };\n    }\n    if ((match = matchers.hex6.exec(color))) {\n        return {\n            r: parseIntFromHex(match[1]),\n            g: parseIntFromHex(match[2]),\n            b: parseIntFromHex(match[3]),\n            format: named ? \"name\" : \"hex\"\n        };\n    }\n    if ((match = matchers.hex4.exec(color))) {\n        return {\n            r: parseIntFromHex(match[1] + '' + match[1]),\n            g: parseIntFromHex(match[2] + '' + match[2]),\n            b: parseIntFromHex(match[3] + '' + match[3]),\n            a: convertHexToDecimal(match[4] + '' + match[4]),\n            format: named ? \"name\" : \"hex8\"\n        };\n    }\n    if ((match = matchers.hex3.exec(color))) {\n        return {\n            r: parseIntFromHex(match[1] + '' + match[1]),\n            g: parseIntFromHex(match[2] + '' + match[2]),\n            b: parseIntFromHex(match[3] + '' + match[3]),\n            format: named ? \"name\" : \"hex\"\n        };\n    }\n\n    return false;\n}\n\nfunction validateWCAG2Parms(parms) {\n    // return valid WCAG2 parms for isReadable.\n    // If input parms are invalid, return {\"level\":\"AA\", \"size\":\"small\"}\n    var level, size;\n    parms = parms || {\"level\":\"AA\", \"size\":\"small\"};\n    level = (parms.level || \"AA\").toUpperCase();\n    size = (parms.size || \"small\").toLowerCase();\n    if (level !== \"AA\" && level !== \"AAA\") {\n        level = \"AA\";\n    }\n    if (size !== \"small\" && size !== \"large\") {\n        size = \"small\";\n    }\n    return {\"level\":level, \"size\":size};\n}\n\n// Node: Export function\nif (typeof module !== \"undefined\" && module.exports) {\n    module.exports = tinycolor;\n}\n// AMD/requirejs: Define the module\nelse if (typeof define === 'function' && define.amd) {\n    define(function () {return tinycolor;});\n}\n// Browser: Expose to window\nelse {\n    window.tinycolor = tinycolor;\n}\n\n})(Math);\n\n},{}],538:[function(_dereq_,module,exports){\n/* @module to-float32 */\r\n\r\n'use strict'\r\n\r\nmodule.exports = float32\r\nmodule.exports.float32 =\r\nmodule.exports.float = float32\r\nmodule.exports.fract32 =\r\nmodule.exports.fract = fract32\r\n\r\nvar narr = new Float32Array(1)\r\n\r\n// return fractional part of float32 array\r\nfunction fract32 (arr) {\r\n\tif (arr.length) {\r\n\t\tvar fract = float32(arr)\r\n\t\tfor (var i = 0, l = fract.length; i < l; i++) {\r\n\t\t\tfract[i] = arr[i] - fract[i]\r\n\t\t}\r\n\t\treturn fract\r\n\t}\r\n\r\n\t// number\r\n\treturn float32(arr - float32(arr))\r\n}\r\n\r\n// make sure data is float32 array\r\nfunction float32 (arr) {\r\n\tif (arr.length) {\r\n\t\tif (arr instanceof Float32Array) return arr\r\n\t\tvar float = new Float32Array(arr)\r\n\t\tfloat.set(arr)\r\n\t\treturn float\r\n\t}\r\n\r\n\t// number\r\n\tnarr[0] = arr\r\n\treturn narr[0]\r\n}\r\n\n},{}],539:[function(_dereq_,module,exports){\n'use strict'\n\nvar parseUnit = _dereq_('parse-unit')\n\nmodule.exports = toPX\n\nvar PIXELS_PER_INCH = 96\n\nfunction getPropertyInPX(element, prop) {\n  var parts = parseUnit(getComputedStyle(element).getPropertyValue(prop))\n  return parts[0] * toPX(parts[1], element)\n}\n\n//This brutal hack is needed\nfunction getSizeBrutal(unit, element) {\n  var testDIV = document.createElement('div')\n  testDIV.style['font-size'] = '128' + unit\n  element.appendChild(testDIV)\n  var size = getPropertyInPX(testDIV, 'font-size') / 128\n  element.removeChild(testDIV)\n  return size\n}\n\nfunction toPX(str, element) {\n  element = element || document.body\n  str = (str || 'px').trim().toLowerCase()\n  if(element === window || element === document) {\n    element = document.body \n  }\n  switch(str) {\n    case '%':  //Ambiguous, not sure if we should use width or height\n      return element.clientHeight / 100.0\n    case 'ch':\n    case 'ex':\n      return getSizeBrutal(str, element)\n    case 'em':\n      return getPropertyInPX(element, 'font-size')\n    case 'rem':\n      return getPropertyInPX(document.body, 'font-size')\n    case 'vw':\n      return window.innerWidth/100\n    case 'vh':\n      return window.innerHeight/100\n    case 'vmin':\n      return Math.min(window.innerWidth, window.innerHeight) / 100\n    case 'vmax':\n      return Math.max(window.innerWidth, window.innerHeight) / 100\n    case 'in':\n      return PIXELS_PER_INCH\n    case 'cm':\n      return PIXELS_PER_INCH / 2.54\n    case 'mm':\n      return PIXELS_PER_INCH / 25.4\n    case 'pt':\n      return PIXELS_PER_INCH / 72\n    case 'pc':\n      return PIXELS_PER_INCH / 6\n  }\n  return 1\n}\n},{\"parse-unit\":461}],540:[function(_dereq_,module,exports){\n// https://github.com/topojson/topojson-client Version 2.1.0. Copyright 2016 Mike Bostock.\n(function (global, factory) {\n  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n  typeof define === 'function' && define.amd ? define(['exports'], factory) :\n  (factory((global.topojson = global.topojson || {})));\n}(this, (function (exports) { 'use strict';\n\nvar identity = function(x) {\n  return x;\n};\n\nvar transform = function(topology) {\n  if ((transform = topology.transform) == null) return identity;\n  var transform,\n      x0,\n      y0,\n      kx = transform.scale[0],\n      ky = transform.scale[1],\n      dx = transform.translate[0],\n      dy = transform.translate[1];\n  return function(point, i) {\n    if (!i) x0 = y0 = 0;\n    point[0] = (x0 += point[0]) * kx + dx;\n    point[1] = (y0 += point[1]) * ky + dy;\n    return point;\n  };\n};\n\nvar bbox = function(topology) {\n  var bbox = topology.bbox;\n\n  function bboxPoint(p0) {\n    p1[0] = p0[0], p1[1] = p0[1], t(p1);\n    if (p1[0] < x0) x0 = p1[0];\n    if (p1[0] > x1) x1 = p1[0];\n    if (p1[1] < y0) y0 = p1[1];\n    if (p1[1] > y1) y1 = p1[1];\n  }\n\n  function bboxGeometry(o) {\n    switch (o.type) {\n      case \"GeometryCollection\": o.geometries.forEach(bboxGeometry); break;\n      case \"Point\": bboxPoint(o.coordinates); break;\n      case \"MultiPoint\": o.coordinates.forEach(bboxPoint); break;\n    }\n  }\n\n  if (!bbox) {\n    var t = transform(topology), p0, p1 = new Array(2), name,\n        x0 = Infinity, y0 = x0, x1 = -x0, y1 = -x0;\n\n    topology.arcs.forEach(function(arc) {\n      var i = -1, n = arc.length;\n      while (++i < n) {\n        p0 = arc[i], p1[0] = p0[0], p1[1] = p0[1], t(p1, i);\n        if (p1[0] < x0) x0 = p1[0];\n        if (p1[0] > x1) x1 = p1[0];\n        if (p1[1] < y0) y0 = p1[1];\n        if (p1[1] > y1) y1 = p1[1];\n      }\n    });\n\n    for (name in topology.objects) {\n      bboxGeometry(topology.objects[name]);\n    }\n\n    bbox = topology.bbox = [x0, y0, x1, y1];\n  }\n\n  return bbox;\n};\n\nvar reverse = function(array, n) {\n  var t, j = array.length, i = j - n;\n  while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;\n};\n\nvar feature = function(topology, o) {\n  return o.type === \"GeometryCollection\"\n      ? {type: \"FeatureCollection\", features: o.geometries.map(function(o) { return feature$1(topology, o); })}\n      : feature$1(topology, o);\n};\n\nfunction feature$1(topology, o) {\n  var id = o.id,\n      bbox = o.bbox,\n      properties = o.properties == null ? {} : o.properties,\n      geometry = object(topology, o);\n  return id == null && bbox == null ? {type: \"Feature\", properties: properties, geometry: geometry}\n      : bbox == null ? {type: \"Feature\", id: id, properties: properties, geometry: geometry}\n      : {type: \"Feature\", id: id, bbox: bbox, properties: properties, geometry: geometry};\n}\n\nfunction object(topology, o) {\n  var transformPoint = transform(topology),\n      arcs = topology.arcs;\n\n  function arc(i, points) {\n    if (points.length) points.pop();\n    for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length; k < n; ++k) {\n      points.push(transformPoint(a[k].slice(), k));\n    }\n    if (i < 0) reverse(points, n);\n  }\n\n  function point(p) {\n    return transformPoint(p.slice());\n  }\n\n  function line(arcs) {\n    var points = [];\n    for (var i = 0, n = arcs.length; i < n; ++i) arc(arcs[i], points);\n    if (points.length < 2) points.push(points[0].slice());\n    return points;\n  }\n\n  function ring(arcs) {\n    var points = line(arcs);\n    while (points.length < 4) points.push(points[0].slice());\n    return points;\n  }\n\n  function polygon(arcs) {\n    return arcs.map(ring);\n  }\n\n  function geometry(o) {\n    var type = o.type, coordinates;\n    switch (type) {\n      case \"GeometryCollection\": return {type: type, geometries: o.geometries.map(geometry)};\n      case \"Point\": coordinates = point(o.coordinates); break;\n      case \"MultiPoint\": coordinates = o.coordinates.map(point); break;\n      case \"LineString\": coordinates = line(o.arcs); break;\n      case \"MultiLineString\": coordinates = o.arcs.map(line); break;\n      case \"Polygon\": coordinates = polygon(o.arcs); break;\n      case \"MultiPolygon\": coordinates = o.arcs.map(polygon); break;\n      default: return null;\n    }\n    return {type: type, coordinates: coordinates};\n  }\n\n  return geometry(o);\n}\n\nvar stitch = function(topology, arcs) {\n  var stitchedArcs = {},\n      fragmentByStart = {},\n      fragmentByEnd = {},\n      fragments = [],\n      emptyIndex = -1;\n\n  // Stitch empty arcs first, since they may be subsumed by other arcs.\n  arcs.forEach(function(i, j) {\n    var arc = topology.arcs[i < 0 ? ~i : i], t;\n    if (arc.length < 3 && !arc[1][0] && !arc[1][1]) {\n      t = arcs[++emptyIndex], arcs[emptyIndex] = i, arcs[j] = t;\n    }\n  });\n\n  arcs.forEach(function(i) {\n    var e = ends(i),\n        start = e[0],\n        end = e[1],\n        f, g;\n\n    if (f = fragmentByEnd[start]) {\n      delete fragmentByEnd[f.end];\n      f.push(i);\n      f.end = end;\n      if (g = fragmentByStart[end]) {\n        delete fragmentByStart[g.start];\n        var fg = g === f ? f : f.concat(g);\n        fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;\n      } else {\n        fragmentByStart[f.start] = fragmentByEnd[f.end] = f;\n      }\n    } else if (f = fragmentByStart[end]) {\n      delete fragmentByStart[f.start];\n      f.unshift(i);\n      f.start = start;\n      if (g = fragmentByEnd[start]) {\n        delete fragmentByEnd[g.end];\n        var gf = g === f ? f : g.concat(f);\n        fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;\n      } else {\n        fragmentByStart[f.start] = fragmentByEnd[f.end] = f;\n      }\n    } else {\n      f = [i];\n      fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f;\n    }\n  });\n\n  function ends(i) {\n    var arc = topology.arcs[i < 0 ? ~i : i], p0 = arc[0], p1;\n    if (topology.transform) p1 = [0, 0], arc.forEach(function(dp) { p1[0] += dp[0], p1[1] += dp[1]; });\n    else p1 = arc[arc.length - 1];\n    return i < 0 ? [p1, p0] : [p0, p1];\n  }\n\n  function flush(fragmentByEnd, fragmentByStart) {\n    for (var k in fragmentByEnd) {\n      var f = fragmentByEnd[k];\n      delete fragmentByStart[f.start];\n      delete f.start;\n      delete f.end;\n      f.forEach(function(i) { stitchedArcs[i < 0 ? ~i : i] = 1; });\n      fragments.push(f);\n    }\n  }\n\n  flush(fragmentByEnd, fragmentByStart);\n  flush(fragmentByStart, fragmentByEnd);\n  arcs.forEach(function(i) { if (!stitchedArcs[i < 0 ? ~i : i]) fragments.push([i]); });\n\n  return fragments;\n};\n\nvar mesh = function(topology) {\n  return object(topology, meshArcs.apply(this, arguments));\n};\n\nfunction meshArcs(topology, object$$1, filter) {\n  var arcs, i, n;\n  if (arguments.length > 1) arcs = extractArcs(topology, object$$1, filter);\n  else for (i = 0, arcs = new Array(n = topology.arcs.length); i < n; ++i) arcs[i] = i;\n  return {type: \"MultiLineString\", arcs: stitch(topology, arcs)};\n}\n\nfunction extractArcs(topology, object$$1, filter) {\n  var arcs = [],\n      geomsByArc = [],\n      geom;\n\n  function extract0(i) {\n    var j = i < 0 ? ~i : i;\n    (geomsByArc[j] || (geomsByArc[j] = [])).push({i: i, g: geom});\n  }\n\n  function extract1(arcs) {\n    arcs.forEach(extract0);\n  }\n\n  function extract2(arcs) {\n    arcs.forEach(extract1);\n  }\n\n  function extract3(arcs) {\n    arcs.forEach(extract2);\n  }\n\n  function geometry(o) {\n    switch (geom = o, o.type) {\n      case \"GeometryCollection\": o.geometries.forEach(geometry); break;\n      case \"LineString\": extract1(o.arcs); break;\n      case \"MultiLineString\": case \"Polygon\": extract2(o.arcs); break;\n      case \"MultiPolygon\": extract3(o.arcs); break;\n    }\n  }\n\n  geometry(object$$1);\n\n  geomsByArc.forEach(filter == null\n      ? function(geoms) { arcs.push(geoms[0].i); }\n      : function(geoms) { if (filter(geoms[0].g, geoms[geoms.length - 1].g)) arcs.push(geoms[0].i); });\n\n  return arcs;\n}\n\nfunction planarRingArea(ring) {\n  var i = -1, n = ring.length, a, b = ring[n - 1], area = 0;\n  while (++i < n) a = b, b = ring[i], area += a[0] * b[1] - a[1] * b[0];\n  return Math.abs(area); // Note: doubled area!\n}\n\nvar merge = function(topology) {\n  return object(topology, mergeArcs.apply(this, arguments));\n};\n\nfunction mergeArcs(topology, objects) {\n  var polygonsByArc = {},\n      polygons = [],\n      groups = [];\n\n  objects.forEach(geometry);\n\n  function geometry(o) {\n    switch (o.type) {\n      case \"GeometryCollection\": o.geometries.forEach(geometry); break;\n      case \"Polygon\": extract(o.arcs); break;\n      case \"MultiPolygon\": o.arcs.forEach(extract); break;\n    }\n  }\n\n  function extract(polygon) {\n    polygon.forEach(function(ring) {\n      ring.forEach(function(arc) {\n        (polygonsByArc[arc = arc < 0 ? ~arc : arc] || (polygonsByArc[arc] = [])).push(polygon);\n      });\n    });\n    polygons.push(polygon);\n  }\n\n  function area(ring) {\n    return planarRingArea(object(topology, {type: \"Polygon\", arcs: [ring]}).coordinates[0]);\n  }\n\n  polygons.forEach(function(polygon) {\n    if (!polygon._) {\n      var group = [],\n          neighbors = [polygon];\n      polygon._ = 1;\n      groups.push(group);\n      while (polygon = neighbors.pop()) {\n        group.push(polygon);\n        polygon.forEach(function(ring) {\n          ring.forEach(function(arc) {\n            polygonsByArc[arc < 0 ? ~arc : arc].forEach(function(polygon) {\n              if (!polygon._) {\n                polygon._ = 1;\n                neighbors.push(polygon);\n              }\n            });\n          });\n        });\n      }\n    }\n  });\n\n  polygons.forEach(function(polygon) {\n    delete polygon._;\n  });\n\n  return {\n    type: \"MultiPolygon\",\n    arcs: groups.map(function(polygons) {\n      var arcs = [], n;\n\n      // Extract the exterior (unique) arcs.\n      polygons.forEach(function(polygon) {\n        polygon.forEach(function(ring) {\n          ring.forEach(function(arc) {\n            if (polygonsByArc[arc < 0 ? ~arc : arc].length < 2) {\n              arcs.push(arc);\n            }\n          });\n        });\n      });\n\n      // Stitch the arcs into one or more rings.\n      arcs = stitch(topology, arcs);\n\n      // If more than one ring is returned,\n      // at most one of these rings can be the exterior;\n      // choose the one with the greatest absolute area.\n      if ((n = arcs.length) > 1) {\n        for (var i = 1, k = area(arcs[0]), ki, t; i < n; ++i) {\n          if ((ki = area(arcs[i])) > k) {\n            t = arcs[0], arcs[0] = arcs[i], arcs[i] = t, k = ki;\n          }\n        }\n      }\n\n      return arcs;\n    })\n  };\n}\n\nvar bisect = function(a, x) {\n  var lo = 0, hi = a.length;\n  while (lo < hi) {\n    var mid = lo + hi >>> 1;\n    if (a[mid] < x) lo = mid + 1;\n    else hi = mid;\n  }\n  return lo;\n};\n\nvar neighbors = function(objects) {\n  var indexesByArc = {}, // arc index -> array of object indexes\n      neighbors = objects.map(function() { return []; });\n\n  function line(arcs, i) {\n    arcs.forEach(function(a) {\n      if (a < 0) a = ~a;\n      var o = indexesByArc[a];\n      if (o) o.push(i);\n      else indexesByArc[a] = [i];\n    });\n  }\n\n  function polygon(arcs, i) {\n    arcs.forEach(function(arc) { line(arc, i); });\n  }\n\n  function geometry(o, i) {\n    if (o.type === \"GeometryCollection\") o.geometries.forEach(function(o) { geometry(o, i); });\n    else if (o.type in geometryType) geometryType[o.type](o.arcs, i);\n  }\n\n  var geometryType = {\n    LineString: line,\n    MultiLineString: polygon,\n    Polygon: polygon,\n    MultiPolygon: function(arcs, i) { arcs.forEach(function(arc) { polygon(arc, i); }); }\n  };\n\n  objects.forEach(geometry);\n\n  for (var i in indexesByArc) {\n    for (var indexes = indexesByArc[i], m = indexes.length, j = 0; j < m; ++j) {\n      for (var k = j + 1; k < m; ++k) {\n        var ij = indexes[j], ik = indexes[k], n;\n        if ((n = neighbors[ij])[i = bisect(n, ik)] !== ik) n.splice(i, 0, ik);\n        if ((n = neighbors[ik])[i = bisect(n, ij)] !== ij) n.splice(i, 0, ij);\n      }\n    }\n  }\n\n  return neighbors;\n};\n\nvar quantize = function(topology, n) {\n  if (!((n = Math.floor(n)) >= 2)) throw new Error(\"n must be ≥2\");\n  if (topology.transform) throw new Error(\"already quantized\");\n  var bb = bbox(topology), name,\n      dx = bb[0], kx = (bb[2] - dx) / (n - 1) || 1,\n      dy = bb[1], ky = (bb[3] - dy) / (n - 1) || 1;\n\n  function quantizePoint(p) {\n    p[0] = Math.round((p[0] - dx) / kx);\n    p[1] = Math.round((p[1] - dy) / ky);\n  }\n\n  function quantizeGeometry(o) {\n    switch (o.type) {\n      case \"GeometryCollection\": o.geometries.forEach(quantizeGeometry); break;\n      case \"Point\": quantizePoint(o.coordinates); break;\n      case \"MultiPoint\": o.coordinates.forEach(quantizePoint); break;\n    }\n  }\n\n  topology.arcs.forEach(function(arc) {\n    var i = 1,\n        j = 1,\n        n = arc.length,\n        pi = arc[0],\n        x0 = pi[0] = Math.round((pi[0] - dx) / kx),\n        y0 = pi[1] = Math.round((pi[1] - dy) / ky),\n        pj,\n        x1,\n        y1;\n\n    for (; i < n; ++i) {\n      pi = arc[i];\n      x1 = Math.round((pi[0] - dx) / kx);\n      y1 = Math.round((pi[1] - dy) / ky);\n      if (x1 !== x0 || y1 !== y0) {\n        pj = arc[j++];\n        pj[0] = x1 - x0, x0 = x1;\n        pj[1] = y1 - y0, y0 = y1;\n      }\n    }\n\n    if (j < 2) {\n      pj = arc[j++];\n      pj[0] = 0;\n      pj[1] = 0;\n    }\n\n    arc.length = j;\n  });\n\n  for (name in topology.objects) {\n    quantizeGeometry(topology.objects[name]);\n  }\n\n  topology.transform = {\n    scale: [kx, ky],\n    translate: [dx, dy]\n  };\n\n  return topology;\n};\n\nvar untransform = function(topology) {\n  if ((transform = topology.transform) == null) return identity;\n  var transform,\n      x0,\n      y0,\n      kx = transform.scale[0],\n      ky = transform.scale[1],\n      dx = transform.translate[0],\n      dy = transform.translate[1];\n  return function(point, i) {\n    if (!i) x0 = y0 = 0;\n    var x1 = Math.round((point[0] - dx) / kx),\n        y1 = Math.round((point[1] - dy) / ky);\n    point[0] = x1 - x0, x0 = x1;\n    point[1] = y1 - y0, y0 = y1;\n    return point;\n  };\n};\n\nexports.bbox = bbox;\nexports.feature = feature;\nexports.mesh = mesh;\nexports.meshArcs = meshArcs;\nexports.merge = merge;\nexports.mergeArcs = mergeArcs;\nexports.neighbors = neighbors;\nexports.quantize = quantize;\nexports.transform = transform;\nexports.untransform = untransform;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n\n},{}],541:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = triangulateCube\n\nvar perm = _dereq_(\"permutation-rank\")\nvar sgn = _dereq_(\"permutation-parity\")\nvar gamma = _dereq_(\"gamma\")\n\nfunction triangulateCube(dimension) {\n  if(dimension < 0) {\n    return [ ]\n  }\n  if(dimension === 0) {\n    return [ [0] ]\n  }\n  var dfactorial = Math.round(gamma(dimension+1))|0\n  var result = []\n  for(var i=0; i<dfactorial; ++i) {\n    var p = perm.unrank(dimension, i)\n    var cell = [ 0 ]\n    var v = 0\n    for(var j=0; j<p.length; ++j) {\n      v += (1<<p[j])\n      cell.push(v)\n    }\n    if(sgn(p) < 1) {\n      cell[0] = v\n      cell[dimension] = 0\n    }\n    result.push(cell)\n  }\n  return result\n}\n},{\"gamma\":231,\"permutation-parity\":463,\"permutation-rank\":464}],542:[function(_dereq_,module,exports){\n'use strict'\n\nmodule.exports = createTurntableController\n\nvar filterVector = _dereq_('filtered-vector')\nvar invert44     = _dereq_('gl-mat4/invert')\nvar rotateM      = _dereq_('gl-mat4/rotate')\nvar cross        = _dereq_('gl-vec3/cross')\nvar normalize3   = _dereq_('gl-vec3/normalize')\nvar dot3         = _dereq_('gl-vec3/dot')\n\nfunction len3(x, y, z) {\n  return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2))\n}\n\nfunction clamp1(x) {\n  return Math.min(1.0, Math.max(-1.0, x))\n}\n\nfunction findOrthoPair(v) {\n  var vx = Math.abs(v[0])\n  var vy = Math.abs(v[1])\n  var vz = Math.abs(v[2])\n\n  var u = [0,0,0]\n  if(vx > Math.max(vy, vz)) {\n    u[2] = 1\n  } else if(vy > Math.max(vx, vz)) {\n    u[0] = 1\n  } else {\n    u[1] = 1\n  }\n\n  var vv = 0\n  var uv = 0\n  for(var i=0; i<3; ++i ) {\n    vv += v[i] * v[i]\n    uv += u[i] * v[i]\n  }\n  for(var i=0; i<3; ++i) {\n    u[i] -= (uv / vv) *  v[i]\n  }\n  normalize3(u, u)\n  return u\n}\n\nfunction TurntableController(zoomMin, zoomMax, center, up, right, radius, theta, phi) {\n  this.center = filterVector(center)\n  this.up     = filterVector(up)\n  this.right  = filterVector(right)\n  this.radius = filterVector([radius])\n  this.angle  = filterVector([theta, phi])\n  this.angle.bounds = [[-Infinity,-Math.PI/2], [Infinity,Math.PI/2]]\n  this.setDistanceLimits(zoomMin, zoomMax)\n\n  this.computedCenter = this.center.curve(0)\n  this.computedUp     = this.up.curve(0)\n  this.computedRight  = this.right.curve(0)\n  this.computedRadius = this.radius.curve(0)\n  this.computedAngle  = this.angle.curve(0)\n  this.computedToward = [0,0,0]\n  this.computedEye    = [0,0,0]\n  this.computedMatrix = new Array(16)\n  for(var i=0; i<16; ++i) {\n    this.computedMatrix[i] = 0.5\n  }\n\n  this.recalcMatrix(0)\n}\n\nvar proto = TurntableController.prototype\n\nproto.setDistanceLimits = function(minDist, maxDist) {\n  if(minDist > 0) {\n    minDist = Math.log(minDist)\n  } else {\n    minDist = -Infinity\n  }\n  if(maxDist > 0) {\n    maxDist = Math.log(maxDist)\n  } else {\n    maxDist = Infinity\n  }\n  maxDist = Math.max(maxDist, minDist)\n  this.radius.bounds[0][0] = minDist\n  this.radius.bounds[1][0] = maxDist\n}\n\nproto.getDistanceLimits = function(out) {\n  var bounds = this.radius.bounds[0]\n  if(out) {\n    out[0] = Math.exp(bounds[0][0])\n    out[1] = Math.exp(bounds[1][0])\n    return out\n  }\n  return [ Math.exp(bounds[0][0]), Math.exp(bounds[1][0]) ]\n}\n\nproto.recalcMatrix = function(t) {\n  //Recompute curves\n  this.center.curve(t)\n  this.up.curve(t)\n  this.right.curve(t)\n  this.radius.curve(t)\n  this.angle.curve(t)\n\n  //Compute frame for camera matrix\n  var up     = this.computedUp\n  var right  = this.computedRight\n  var uu = 0.0\n  var ur = 0.0\n  for(var i=0; i<3; ++i) {\n    ur += up[i] * right[i]\n    uu += up[i] * up[i]\n  }\n  var ul = Math.sqrt(uu)\n  var rr = 0.0\n  for(var i=0; i<3; ++i) {\n    right[i] -= up[i] * ur / uu\n    rr       += right[i] * right[i]\n    up[i]    /= ul\n  }\n  var rl = Math.sqrt(rr)\n  for(var i=0; i<3; ++i) {\n    right[i] /= rl\n  }\n\n  //Compute toward vector\n  var toward = this.computedToward\n  cross(toward, up, right)\n  normalize3(toward, toward)\n\n  //Compute angular parameters\n  var radius = Math.exp(this.computedRadius[0])\n  var theta  = this.computedAngle[0]\n  var phi    = this.computedAngle[1]\n\n  var ctheta = Math.cos(theta)\n  var stheta = Math.sin(theta)\n  var cphi   = Math.cos(phi)\n  var sphi   = Math.sin(phi)\n\n  var center = this.computedCenter\n\n  var wx = ctheta * cphi \n  var wy = stheta * cphi\n  var wz = sphi\n\n  var sx = -ctheta * sphi\n  var sy = -stheta * sphi\n  var sz = cphi\n\n  var eye = this.computedEye\n  var mat = this.computedMatrix\n  for(var i=0; i<3; ++i) {\n    var x      = wx * right[i] + wy * toward[i] + wz * up[i]\n    mat[4*i+1] = sx * right[i] + sy * toward[i] + sz * up[i]\n    mat[4*i+2] = x\n    mat[4*i+3] = 0.0\n  }\n\n  var ax = mat[1]\n  var ay = mat[5]\n  var az = mat[9]\n  var bx = mat[2]\n  var by = mat[6]\n  var bz = mat[10]\n  var cx = ay * bz - az * by\n  var cy = az * bx - ax * bz\n  var cz = ax * by - ay * bx\n  var cl = len3(cx, cy, cz)\n  cx /= cl\n  cy /= cl\n  cz /= cl\n  mat[0] = cx\n  mat[4] = cy\n  mat[8] = cz\n\n  for(var i=0; i<3; ++i) {\n    eye[i] = center[i] + mat[2+4*i]*radius\n  }\n\n  for(var i=0; i<3; ++i) {\n    var rr = 0.0\n    for(var j=0; j<3; ++j) {\n      rr += mat[i+4*j] * eye[j]\n    }\n    mat[12+i] = -rr\n  }\n  mat[15] = 1.0\n}\n\nproto.getMatrix = function(t, result) {\n  this.recalcMatrix(t)\n  var mat = this.computedMatrix\n  if(result) {\n    for(var i=0; i<16; ++i) {\n      result[i] = mat[i]\n    }\n    return result\n  }\n  return mat\n}\n\nvar zAxis = [0,0,0]\nproto.rotate = function(t, dtheta, dphi, droll) {\n  this.angle.move(t, dtheta, dphi)\n  if(droll) {\n    this.recalcMatrix(t)\n\n    var mat = this.computedMatrix\n    zAxis[0] = mat[2]\n    zAxis[1] = mat[6]\n    zAxis[2] = mat[10]\n\n    var up     = this.computedUp\n    var right  = this.computedRight\n    var toward = this.computedToward\n\n    for(var i=0; i<3; ++i) {\n      mat[4*i]   = up[i]\n      mat[4*i+1] = right[i]\n      mat[4*i+2] = toward[i]\n    }\n    rotateM(mat, mat, droll, zAxis)\n    for(var i=0; i<3; ++i) {\n      up[i] =    mat[4*i]\n      right[i] = mat[4*i+1]\n    }\n\n    this.up.set(t, up[0], up[1], up[2])\n    this.right.set(t, right[0], right[1], right[2])\n  }\n}\n\nproto.pan = function(t, dx, dy, dz) {\n  dx = dx || 0.0\n  dy = dy || 0.0\n  dz = dz || 0.0\n\n  this.recalcMatrix(t)\n  var mat = this.computedMatrix\n\n  var dist = Math.exp(this.computedRadius[0])\n\n  var ux = mat[1]\n  var uy = mat[5]\n  var uz = mat[9]\n  var ul = len3(ux, uy, uz)\n  ux /= ul\n  uy /= ul\n  uz /= ul\n\n  var rx = mat[0]\n  var ry = mat[4]\n  var rz = mat[8]\n  var ru = rx * ux + ry * uy + rz * uz\n  rx -= ux * ru\n  ry -= uy * ru\n  rz -= uz * ru\n  var rl = len3(rx, ry, rz)\n  rx /= rl\n  ry /= rl\n  rz /= rl\n\n  var vx = rx * dx + ux * dy\n  var vy = ry * dx + uy * dy\n  var vz = rz * dx + uz * dy\n  this.center.move(t, vx, vy, vz)\n\n  //Update z-component of radius\n  var radius = Math.exp(this.computedRadius[0])\n  radius = Math.max(1e-4, radius + dz)\n  this.radius.set(t, Math.log(radius))\n}\n\nproto.translate = function(t, dx, dy, dz) {\n  this.center.move(t,\n    dx||0.0,\n    dy||0.0,\n    dz||0.0)\n}\n\n//Recenters the coordinate axes\nproto.setMatrix = function(t, mat, axes, noSnap) {\n  \n  //Get the axes for tare\n  var ushift = 1\n  if(typeof axes === 'number') {\n    ushift = (axes)|0\n  } \n  if(ushift < 0 || ushift > 3) {\n    ushift = 1\n  }\n  var vshift = (ushift + 2) % 3\n  var fshift = (ushift + 1) % 3\n\n  //Recompute state for new t value\n  if(!mat) { \n    this.recalcMatrix(t)\n    mat = this.computedMatrix\n  }\n\n  //Get right and up vectors\n  var ux = mat[ushift]\n  var uy = mat[ushift+4]\n  var uz = mat[ushift+8]\n  if(!noSnap) {\n    var ul = len3(ux, uy, uz)\n    ux /= ul\n    uy /= ul\n    uz /= ul\n  } else {\n    var ax = Math.abs(ux)\n    var ay = Math.abs(uy)\n    var az = Math.abs(uz)\n    var am = Math.max(ax,ay,az)\n    if(ax === am) {\n      ux = (ux < 0) ? -1 : 1\n      uy = uz = 0\n    } else if(az === am) {\n      uz = (uz < 0) ? -1 : 1\n      ux = uy = 0\n    } else {\n      uy = (uy < 0) ? -1 : 1\n      ux = uz = 0\n    }\n  }\n\n  var rx = mat[vshift]\n  var ry = mat[vshift+4]\n  var rz = mat[vshift+8]\n  var ru = rx * ux + ry * uy + rz * uz\n  rx -= ux * ru\n  ry -= uy * ru\n  rz -= uz * ru\n  var rl = len3(rx, ry, rz)\n  rx /= rl\n  ry /= rl\n  rz /= rl\n  \n  var fx = uy * rz - uz * ry\n  var fy = uz * rx - ux * rz\n  var fz = ux * ry - uy * rx\n  var fl = len3(fx, fy, fz)\n  fx /= fl\n  fy /= fl\n  fz /= fl\n\n  this.center.jump(t, ex, ey, ez)\n  this.radius.idle(t)\n  this.up.jump(t, ux, uy, uz)\n  this.right.jump(t, rx, ry, rz)\n\n  var phi, theta\n  if(ushift === 2) {\n    var cx = mat[1]\n    var cy = mat[5]\n    var cz = mat[9]\n    var cr = cx * rx + cy * ry + cz * rz\n    var cf = cx * fx + cy * fy + cz * fz\n    if(tu < 0) {\n      phi = -Math.PI/2\n    } else {\n      phi = Math.PI/2\n    }\n    theta = Math.atan2(cf, cr)\n  } else {\n    var tx = mat[2]\n    var ty = mat[6]\n    var tz = mat[10]\n    var tu = tx * ux + ty * uy + tz * uz\n    var tr = tx * rx + ty * ry + tz * rz\n    var tf = tx * fx + ty * fy + tz * fz\n\n    phi = Math.asin(clamp1(tu))\n    theta = Math.atan2(tf, tr)\n  }\n\n  this.angle.jump(t, theta, phi)\n\n  this.recalcMatrix(t)\n  var dx = mat[2]\n  var dy = mat[6]\n  var dz = mat[10]\n\n  var imat = this.computedMatrix\n  invert44(imat, mat)\n  var w  = imat[15]\n  var ex = imat[12] / w\n  var ey = imat[13] / w\n  var ez = imat[14] / w\n\n  var gs = Math.exp(this.computedRadius[0])\n  this.center.jump(t, ex-dx*gs, ey-dy*gs, ez-dz*gs)\n}\n\nproto.lastT = function() {\n  return Math.max(\n    this.center.lastT(),\n    this.up.lastT(),\n    this.right.lastT(),\n    this.radius.lastT(),\n    this.angle.lastT())\n}\n\nproto.idle = function(t) {\n  this.center.idle(t)\n  this.up.idle(t)\n  this.right.idle(t)\n  this.radius.idle(t)\n  this.angle.idle(t)\n}\n\nproto.flush = function(t) {\n  this.center.flush(t)\n  this.up.flush(t)\n  this.right.flush(t)\n  this.radius.flush(t)\n  this.angle.flush(t)\n}\n\nproto.setDistance = function(t, d) {\n  if(d > 0) {\n    this.radius.set(t, Math.log(d))\n  }\n}\n\nproto.lookAt = function(t, eye, center, up) {\n  this.recalcMatrix(t)\n\n  eye    = eye    || this.computedEye\n  center = center || this.computedCenter\n  up     = up     || this.computedUp\n\n  var ux = up[0]\n  var uy = up[1]\n  var uz = up[2]\n  var ul = len3(ux, uy, uz)\n  if(ul < 1e-6) {\n    return\n  }\n  ux /= ul\n  uy /= ul\n  uz /= ul\n\n  var tx = eye[0] - center[0]\n  var ty = eye[1] - center[1]\n  var tz = eye[2] - center[2]\n  var tl = len3(tx, ty, tz)\n  if(tl < 1e-6) {\n    return\n  }\n  tx /= tl\n  ty /= tl\n  tz /= tl\n\n  var right = this.computedRight\n  var rx = right[0]\n  var ry = right[1]\n  var rz = right[2]\n  var ru = ux*rx + uy*ry + uz*rz\n  rx -= ru * ux\n  ry -= ru * uy\n  rz -= ru * uz\n  var rl = len3(rx, ry, rz)\n\n  if(rl < 0.01) {\n    rx = uy * tz - uz * ty\n    ry = uz * tx - ux * tz\n    rz = ux * ty - uy * tx\n    rl = len3(rx, ry, rz)\n    if(rl < 1e-6) {\n      return\n    }\n  }\n  rx /= rl\n  ry /= rl\n  rz /= rl\n\n  this.up.set(t, ux, uy, uz)\n  this.right.set(t, rx, ry, rz)\n  this.center.set(t, center[0], center[1], center[2])\n  this.radius.set(t, Math.log(tl))\n\n  var fx = uy * rz - uz * ry\n  var fy = uz * rx - ux * rz\n  var fz = ux * ry - uy * rx\n  var fl = len3(fx, fy, fz)\n  fx /= fl\n  fy /= fl\n  fz /= fl\n\n  var tu = ux*tx + uy*ty + uz*tz\n  var tr = rx*tx + ry*ty + rz*tz\n  var tf = fx*tx + fy*ty + fz*tz\n\n  var phi   = Math.asin(clamp1(tu))\n  var theta = Math.atan2(tf, tr)\n\n  var angleState = this.angle._state\n  var lastTheta  = angleState[angleState.length-1]\n  var lastPhi    = angleState[angleState.length-2]\n  lastTheta      = lastTheta % (2.0 * Math.PI)\n  var dp = Math.abs(lastTheta + 2.0 * Math.PI - theta)\n  var d0 = Math.abs(lastTheta - theta)\n  var dn = Math.abs(lastTheta - 2.0 * Math.PI - theta)\n  if(dp < d0) {\n    lastTheta += 2.0 * Math.PI\n  }\n  if(dn < d0) {\n    lastTheta -= 2.0 * Math.PI\n  }\n\n  this.angle.jump(this.angle.lastT(), lastTheta, lastPhi)\n  this.angle.set(t, theta, phi)\n}\n\nfunction createTurntableController(options) {\n  options = options || {}\n\n  var center = options.center || [0,0,0]\n  var up     = options.up     || [0,1,0]\n  var right  = options.right  || findOrthoPair(up)\n  var radius = options.radius || 1.0\n  var theta  = options.theta  || 0.0\n  var phi    = options.phi    || 0.0\n\n  center = [].slice.call(center, 0, 3)\n\n  up = [].slice.call(up, 0, 3)\n  normalize3(up, up)\n\n  right = [].slice.call(right, 0, 3)\n  normalize3(right, right)\n\n  if('eye' in options) {\n    var eye = options.eye\n    var toward = [\n      eye[0]-center[0],\n      eye[1]-center[1],\n      eye[2]-center[2]\n    ]\n    cross(right, toward, up)\n    if(len3(right[0], right[1], right[2]) < 1e-6) {\n      right = findOrthoPair(up)\n    } else {\n      normalize3(right, right)\n    }\n\n    radius = len3(toward[0], toward[1], toward[2])\n\n    var ut = dot3(up, toward) / radius\n    var rt = dot3(right, toward) / radius\n    phi    = Math.acos(ut)\n    theta  = Math.acos(rt)\n  }\n\n  //Use logarithmic coordinates for radius\n  radius = Math.log(radius)\n\n  //Return the controller\n  return new TurntableController(\n    options.zoomMin,\n    options.zoomMax,\n    center,\n    up,\n    right,\n    radius,\n    theta,\n    phi)\n}\n},{\"filtered-vector\":226,\"gl-mat4/invert\":265,\"gl-mat4/rotate\":270,\"gl-vec3/cross\":334,\"gl-vec3/dot\":339,\"gl-vec3/normalize\":356}],543:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = twoProduct\n\nvar SPLITTER = +(Math.pow(2, 27) + 1.0)\n\nfunction twoProduct(a, b, result) {\n  var x = a * b\n\n  var c = SPLITTER * a\n  var abig = c - a\n  var ahi = c - abig\n  var alo = a - ahi\n\n  var d = SPLITTER * b\n  var bbig = d - b\n  var bhi = d - bbig\n  var blo = b - bhi\n\n  var err1 = x - (ahi * bhi)\n  var err2 = err1 - (alo * bhi)\n  var err3 = err2 - (ahi * blo)\n\n  var y = alo * blo - err3\n\n  if(result) {\n    result[0] = y\n    result[1] = x\n    return result\n  }\n\n  return [ y, x ]\n}\n},{}],544:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = fastTwoSum\n\nfunction fastTwoSum(a, b, result) {\n\tvar x = a + b\n\tvar bv = x - a\n\tvar av = x - bv\n\tvar br = b - bv\n\tvar ar = a - av\n\tif(result) {\n\t\tresult[0] = ar + br\n\t\tresult[1] = x\n\t\treturn result\n\t}\n\treturn [ar+br, x]\n}\n},{}],545:[function(_dereq_,module,exports){\n(function (global,Buffer){\n'use strict'\n\nvar bits = _dereq_('bit-twiddle')\nvar dup = _dereq_('dup')\n\n//Legacy pool support\nif(!global.__TYPEDARRAY_POOL) {\n  global.__TYPEDARRAY_POOL = {\n      UINT8   : dup([32, 0])\n    , UINT16  : dup([32, 0])\n    , UINT32  : dup([32, 0])\n    , INT8    : dup([32, 0])\n    , INT16   : dup([32, 0])\n    , INT32   : dup([32, 0])\n    , FLOAT   : dup([32, 0])\n    , DOUBLE  : dup([32, 0])\n    , DATA    : dup([32, 0])\n    , UINT8C  : dup([32, 0])\n    , BUFFER  : dup([32, 0])\n  }\n}\n\nvar hasUint8C = (typeof Uint8ClampedArray) !== 'undefined'\nvar POOL = global.__TYPEDARRAY_POOL\n\n//Upgrade pool\nif(!POOL.UINT8C) {\n  POOL.UINT8C = dup([32, 0])\n}\nif(!POOL.BUFFER) {\n  POOL.BUFFER = dup([32, 0])\n}\n\n//New technique: Only allocate from ArrayBufferView and Buffer\nvar DATA    = POOL.DATA\n  , BUFFER  = POOL.BUFFER\n\nexports.free = function free(array) {\n  if(Buffer.isBuffer(array)) {\n    BUFFER[bits.log2(array.length)].push(array)\n  } else {\n    if(Object.prototype.toString.call(array) !== '[object ArrayBuffer]') {\n      array = array.buffer\n    }\n    if(!array) {\n      return\n    }\n    var n = array.length || array.byteLength\n    var log_n = bits.log2(n)|0\n    DATA[log_n].push(array)\n  }\n}\n\nfunction freeArrayBuffer(buffer) {\n  if(!buffer) {\n    return\n  }\n  var n = buffer.length || buffer.byteLength\n  var log_n = bits.log2(n)\n  DATA[log_n].push(buffer)\n}\n\nfunction freeTypedArray(array) {\n  freeArrayBuffer(array.buffer)\n}\n\nexports.freeUint8 =\nexports.freeUint16 =\nexports.freeUint32 =\nexports.freeInt8 =\nexports.freeInt16 =\nexports.freeInt32 =\nexports.freeFloat32 = \nexports.freeFloat =\nexports.freeFloat64 = \nexports.freeDouble = \nexports.freeUint8Clamped = \nexports.freeDataView = freeTypedArray\n\nexports.freeArrayBuffer = freeArrayBuffer\n\nexports.freeBuffer = function freeBuffer(array) {\n  BUFFER[bits.log2(array.length)].push(array)\n}\n\nexports.malloc = function malloc(n, dtype) {\n  if(dtype === undefined || dtype === 'arraybuffer') {\n    return mallocArrayBuffer(n)\n  } else {\n    switch(dtype) {\n      case 'uint8':\n        return mallocUint8(n)\n      case 'uint16':\n        return mallocUint16(n)\n      case 'uint32':\n        return mallocUint32(n)\n      case 'int8':\n        return mallocInt8(n)\n      case 'int16':\n        return mallocInt16(n)\n      case 'int32':\n        return mallocInt32(n)\n      case 'float':\n      case 'float32':\n        return mallocFloat(n)\n      case 'double':\n      case 'float64':\n        return mallocDouble(n)\n      case 'uint8_clamped':\n        return mallocUint8Clamped(n)\n      case 'buffer':\n        return mallocBuffer(n)\n      case 'data':\n      case 'dataview':\n        return mallocDataView(n)\n\n      default:\n        return null\n    }\n  }\n  return null\n}\n\nfunction mallocArrayBuffer(n) {\n  var n = bits.nextPow2(n)\n  var log_n = bits.log2(n)\n  var d = DATA[log_n]\n  if(d.length > 0) {\n    return d.pop()\n  }\n  return new ArrayBuffer(n)\n}\nexports.mallocArrayBuffer = mallocArrayBuffer\n\nfunction mallocUint8(n) {\n  return new Uint8Array(mallocArrayBuffer(n), 0, n)\n}\nexports.mallocUint8 = mallocUint8\n\nfunction mallocUint16(n) {\n  return new Uint16Array(mallocArrayBuffer(2*n), 0, n)\n}\nexports.mallocUint16 = mallocUint16\n\nfunction mallocUint32(n) {\n  return new Uint32Array(mallocArrayBuffer(4*n), 0, n)\n}\nexports.mallocUint32 = mallocUint32\n\nfunction mallocInt8(n) {\n  return new Int8Array(mallocArrayBuffer(n), 0, n)\n}\nexports.mallocInt8 = mallocInt8\n\nfunction mallocInt16(n) {\n  return new Int16Array(mallocArrayBuffer(2*n), 0, n)\n}\nexports.mallocInt16 = mallocInt16\n\nfunction mallocInt32(n) {\n  return new Int32Array(mallocArrayBuffer(4*n), 0, n)\n}\nexports.mallocInt32 = mallocInt32\n\nfunction mallocFloat(n) {\n  return new Float32Array(mallocArrayBuffer(4*n), 0, n)\n}\nexports.mallocFloat32 = exports.mallocFloat = mallocFloat\n\nfunction mallocDouble(n) {\n  return new Float64Array(mallocArrayBuffer(8*n), 0, n)\n}\nexports.mallocFloat64 = exports.mallocDouble = mallocDouble\n\nfunction mallocUint8Clamped(n) {\n  if(hasUint8C) {\n    return new Uint8ClampedArray(mallocArrayBuffer(n), 0, n)\n  } else {\n    return mallocUint8(n)\n  }\n}\nexports.mallocUint8Clamped = mallocUint8Clamped\n\nfunction mallocDataView(n) {\n  return new DataView(mallocArrayBuffer(n), 0, n)\n}\nexports.mallocDataView = mallocDataView\n\nfunction mallocBuffer(n) {\n  n = bits.nextPow2(n)\n  var log_n = bits.log2(n)\n  var cache = BUFFER[log_n]\n  if(cache.length > 0) {\n    return cache.pop()\n  }\n  return new Buffer(n)\n}\nexports.mallocBuffer = mallocBuffer\n\nexports.clearCache = function clearCache() {\n  for(var i=0; i<32; ++i) {\n    POOL.UINT8[i].length = 0\n    POOL.UINT16[i].length = 0\n    POOL.UINT32[i].length = 0\n    POOL.INT8[i].length = 0\n    POOL.INT16[i].length = 0\n    POOL.INT32[i].length = 0\n    POOL.FLOAT[i].length = 0\n    POOL.DOUBLE[i].length = 0\n    POOL.UINT8C[i].length = 0\n    DATA[i].length = 0\n    BUFFER[i].length = 0\n  }\n}\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {},_dereq_(\"buffer\").Buffer)\n},{\"bit-twiddle\":92,\"buffer\":105,\"dup\":170}],546:[function(_dereq_,module,exports){\n\"use strict\"; \"use restrict\";\n\nmodule.exports = UnionFind;\n\nfunction UnionFind(count) {\n  this.roots = new Array(count);\n  this.ranks = new Array(count);\n  \n  for(var i=0; i<count; ++i) {\n    this.roots[i] = i;\n    this.ranks[i] = 0;\n  }\n}\n\nvar proto = UnionFind.prototype\n\nObject.defineProperty(proto, \"length\", {\n  \"get\": function() {\n    return this.roots.length\n  }\n})\n\nproto.makeSet = function() {\n  var n = this.roots.length;\n  this.roots.push(n);\n  this.ranks.push(0);\n  return n;\n}\n\nproto.find = function(x) {\n  var x0 = x\n  var roots = this.roots;\n  while(roots[x] !== x) {\n    x = roots[x]\n  }\n  while(roots[x0] !== x) {\n    var y = roots[x0]\n    roots[x0] = x\n    x0 = y\n  }\n  return x;\n}\n\nproto.link = function(x, y) {\n  var xr = this.find(x)\n    , yr = this.find(y);\n  if(xr === yr) {\n    return;\n  }\n  var ranks = this.ranks\n    , roots = this.roots\n    , xd    = ranks[xr]\n    , yd    = ranks[yr];\n  if(xd < yd) {\n    roots[xr] = yr;\n  } else if(yd < xd) {\n    roots[yr] = xr;\n  } else {\n    roots[yr] = xr;\n    ++ranks[xr];\n  }\n}\n},{}],547:[function(_dereq_,module,exports){\n\"use strict\"\n\nfunction unique_pred(list, compare) {\n  var ptr = 1\n    , len = list.length\n    , a=list[0], b=list[0]\n  for(var i=1; i<len; ++i) {\n    b = a\n    a = list[i]\n    if(compare(a, b)) {\n      if(i === ptr) {\n        ptr++\n        continue\n      }\n      list[ptr++] = a\n    }\n  }\n  list.length = ptr\n  return list\n}\n\nfunction unique_eq(list) {\n  var ptr = 1\n    , len = list.length\n    , a=list[0], b = list[0]\n  for(var i=1; i<len; ++i, b=a) {\n    b = a\n    a = list[i]\n    if(a !== b) {\n      if(i === ptr) {\n        ptr++\n        continue\n      }\n      list[ptr++] = a\n    }\n  }\n  list.length = ptr\n  return list\n}\n\nfunction unique(list, compare, sorted) {\n  if(list.length === 0) {\n    return list\n  }\n  if(compare) {\n    if(!sorted) {\n      list.sort(compare)\n    }\n    return unique_pred(list, compare)\n  }\n  if(!sorted) {\n    list.sort()\n  }\n  return unique_eq(list)\n}\n\nmodule.exports = unique\n\n},{}],548:[function(_dereq_,module,exports){\nvar reg = /[\\'\\\"]/\n\nmodule.exports = function unquote(str) {\n  if (!str) {\n    return ''\n  }\n  if (reg.test(str.charAt(0))) {\n    str = str.substr(1)\n  }\n  if (reg.test(str.charAt(str.length - 1))) {\n    str = str.substr(0, str.length - 1)\n  }\n  return str\n}\n\n},{}],549:[function(_dereq_,module,exports){\n/**\r\n * @module update-diff\r\n */\r\n\r\n'use strict'\r\n\r\nmodule.exports = function updateDiff (obj, diff, mappers) {\r\n\tif (!Array.isArray(mappers)) mappers = [].slice.call(arguments, 2)\r\n\r\n\tfor (var i = 0, l = mappers.length; i < l; i++) {\r\n\t\tvar dict = mappers[i]\r\n\t\tfor (var prop in dict) {\r\n\t\t\tif (diff[prop] !== undefined && !Array.isArray(diff[prop]) && obj[prop] === diff[prop]) continue\r\n\r\n\t\t\tif (prop in diff) {\r\n\t\t\t\tvar result\r\n\r\n\t\t\t\tif (dict[prop] === true) result = diff[prop]\r\n\t\t\t\telse if (dict[prop] === false) continue\r\n\t\t\t\telse if (typeof dict[prop] === 'function') {\r\n\t\t\t\t\tresult = dict[prop](diff[prop], obj, diff)\r\n\t\t\t\t\tif (result === undefined) continue\r\n\t\t\t\t}\r\n\r\n\t\t\t\tobj[prop] = result\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn obj\r\n}\r\n\n},{}],550:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = createText\n\nvar vectorizeText = _dereq_(\"./lib/vtext\")\nvar defaultCanvas = null\nvar defaultContext = null\n\nif(typeof document !== 'undefined') {\n  defaultCanvas = document.createElement('canvas')\n  defaultCanvas.width = 8192\n  defaultCanvas.height = 1024\n  defaultContext = defaultCanvas.getContext(\"2d\")\n}\n\nfunction createText(str, options) {\n  if((typeof options !== \"object\") || (options === null)) {\n    options = {}\n  }\n  return vectorizeText(\n    str,\n    options.canvas || defaultCanvas,\n    options.context || defaultContext,\n    options)\n}\n\n},{\"./lib/vtext\":551}],551:[function(_dereq_,module,exports){\nmodule.exports = vectorizeText\nmodule.exports.processPixels = processPixels\n\nvar surfaceNets = _dereq_('surface-nets')\nvar ndarray = _dereq_('ndarray')\nvar simplify = _dereq_('simplify-planar-graph')\nvar cleanPSLG = _dereq_('clean-pslg')\nvar cdt2d = _dereq_('cdt2d')\nvar toPolygonCrappy = _dereq_('planar-graph-to-polyline')\n\nvar TAG_bold = \"b\"\nvar CHR_bold = 'b|'\n\nvar TAG_italic = \"i\"\nvar CHR_italic = 'i|'\n\nvar TAG_super = \"sup\"\nvar CHR_super0 = '+'\nvar CHR_super = '+1'\n\nvar TAG_sub = \"sub\"\nvar CHR_sub0 = '-'\nvar CHR_sub = '-1'\n\nfunction parseTag(tag, TAG_CHR, str, map) {\n\n  var opnTag =  \"<\"  + tag + \">\"\n  var clsTag =  \"</\" + tag + \">\"\n\n  var nOPN = opnTag.length\n  var nCLS = clsTag.length\n\n  var isRecursive = (TAG_CHR[0] === CHR_super0) ||\n                    (TAG_CHR[0] === CHR_sub0);\n\n  var a = 0\n  var b = -nCLS\n  while (a > -1) {\n    a = str.indexOf(opnTag, a)\n    if(a === -1) break\n\n    b = str.indexOf(clsTag, a + nOPN)\n    if(b === -1) break\n\n    if(b <= a) break\n\n    for(var i = a; i < b + nCLS; ++i){\n      if((i < a + nOPN) || (i >= b)) {\n        map[i] = null\n        str = str.substr(0, i) + \" \" + str.substr(i + 1)\n      } else {\n        if(map[i] !== null) {\n          var pos = map[i].indexOf(TAG_CHR[0])\n          if(pos === -1) {\n            map[i] += TAG_CHR\n          } else { // i.e. to handle multiple sub/super-scripts\n            if(isRecursive) {\n              // i.e to increase the sub/sup number\n              map[i] = map[i].substr(0, pos + 1) + (1 + parseInt(map[i][pos + 1])) + map[i].substr(pos + 2)\n            }\n          }\n        }\n      }\n    }\n\n    var start = a + nOPN\n    var remainingStr = str.substr(start, b - start)\n\n    var c = remainingStr.indexOf(opnTag)\n    if(c !== -1) a = c\n    else a = b + nCLS\n  }\n\n  return map\n}\n\nfunction transformPositions(positions, options, size) {\n  var align = options.textAlign || \"start\"\n  var baseline = options.textBaseline || \"alphabetic\"\n\n  var lo = [1<<30, 1<<30]\n  var hi = [0,0]\n  var n = positions.length\n  for(var i=0; i<n; ++i) {\n    var p = positions[i]\n    for(var j=0; j<2; ++j) {\n      lo[j] = Math.min(lo[j], p[j])|0\n      hi[j] = Math.max(hi[j], p[j])|0\n    }\n  }\n\n  var xShift = 0\n  switch(align) {\n    case \"center\":\n      xShift = -0.5 * (lo[0] + hi[0])\n    break\n\n    case \"right\":\n    case \"end\":\n      xShift = -hi[0]\n    break\n\n    case \"left\":\n    case \"start\":\n      xShift = -lo[0]\n    break\n\n    default:\n      throw new Error(\"vectorize-text: Unrecognized textAlign: '\" + align + \"'\")\n  }\n\n  var yShift = 0\n  switch(baseline) {\n    case \"hanging\":\n    case \"top\":\n      yShift = -lo[1]\n    break\n\n    case \"middle\":\n      yShift = -0.5 * (lo[1] + hi[1])\n    break\n\n    case \"alphabetic\":\n    case \"ideographic\":\n      yShift = -3 * size\n    break\n\n    case \"bottom\":\n      yShift = -hi[1]\n    break\n\n    default:\n      throw new Error(\"vectorize-text: Unrecoginized textBaseline: '\" + baseline + \"'\")\n  }\n\n  var scale = 1.0 / size\n  if(\"lineHeight\" in options) {\n    scale *= +options.lineHeight\n  } else if(\"width\" in options) {\n    scale = options.width / (hi[0] - lo[0])\n  } else if(\"height\" in options) {\n    scale = options.height / (hi[1] - lo[1])\n  }\n\n  return positions.map(function(p) {\n    return [ scale * (p[0] + xShift), scale * (p[1] + yShift) ]\n  })\n}\n\nfunction getPixels(canvas, context, rawString, fontSize, lineSpacing, styletags) {\n\n  rawString = rawString.replace(/\\n/g, '') // don't accept \\n in the input\n\n  if(styletags.breaklines === true) {\n    rawString = rawString.replace(/\\<br\\>/g, '\\n') // replace <br> tags with \\n in the string\n  } else {\n    rawString = rawString.replace(/\\<br\\>/g, ' ') // don't accept <br> tags in the input and replace with space in this case\n  }\n\n  var activeStyle = \"\"\n  var map = []\n  for(j = 0; j < rawString.length; ++j) {\n    map[j] = activeStyle\n  }\n\n  if(styletags.bolds === true) map = parseTag(TAG_bold, CHR_bold, rawString, map)\n  if(styletags.italics === true) map = parseTag(TAG_italic, CHR_italic, rawString, map)\n  if(styletags.superscripts === true) map = parseTag(TAG_super, CHR_super, rawString, map)\n  if(styletags.subscripts === true) map = parseTag(TAG_sub, CHR_sub, rawString, map)\n\n  var allStyles = []\n  var plainText = \"\"\n  for(j = 0; j < rawString.length; ++j) {\n    if(map[j] !== null) {\n      plainText += rawString[j]\n      allStyles.push(map[j])\n    }\n  }\n\n  var allTexts = plainText.split('\\n')\n\n  var numberOfLines = allTexts.length\n  var lineHeight = Math.round(lineSpacing * fontSize)\n  var offsetX = fontSize\n  var offsetY = fontSize * 2\n  var maxWidth = 0\n  var minHeight = numberOfLines * lineHeight + offsetY\n\n  if(canvas.height < minHeight) {\n    canvas.height = minHeight\n  }\n\n  context.fillStyle = \"#000\"\n  context.fillRect(0, 0, canvas.width, canvas.height)\n\n  context.fillStyle = \"#fff\"\n  var i, j, xPos, yPos, zPos\n  var nDone = 0\n\n  var buffer = \"\"\n  function writeBuffer() {\n    if(buffer !== \"\") {\n      var delta = context.measureText(buffer).width\n\n      context.fillText(buffer, offsetX + xPos, offsetY + yPos)\n      xPos += delta\n    }\n  }\n\n  function getTextFontSize() {\n    return \"\" + Math.round(zPos) + \"px \";\n  }\n\n  function changeStyle(oldStyle, newStyle) {\n    var ctxFont = \"\" + context.font;\n\n    if(styletags.subscripts === true) {\n      var oldIndex_Sub = oldStyle.indexOf(CHR_sub0);\n      var newIndex_Sub = newStyle.indexOf(CHR_sub0);\n\n      var oldSub = (oldIndex_Sub > -1) ? parseInt(oldStyle[1 + oldIndex_Sub]) : 0;\n      var newSub = (newIndex_Sub > -1) ? parseInt(newStyle[1 + newIndex_Sub]) : 0;\n\n      if(oldSub !== newSub) {\n        ctxFont = ctxFont.replace(getTextFontSize(), \"?px \")\n        zPos *= Math.pow(0.75, (newSub - oldSub))\n        ctxFont = ctxFont.replace(\"?px \", getTextFontSize())\n      }\n      yPos += 0.25 * lineHeight * (newSub - oldSub);\n    }\n\n    if(styletags.superscripts === true) {\n      var oldIndex_Super = oldStyle.indexOf(CHR_super0);\n      var newIndex_Super = newStyle.indexOf(CHR_super0);\n\n      var oldSuper = (oldIndex_Super > -1) ? parseInt(oldStyle[1 + oldIndex_Super]) : 0;\n      var newSuper = (newIndex_Super > -1) ? parseInt(newStyle[1 + newIndex_Super]) : 0;\n\n      if(oldSuper !== newSuper) {\n        ctxFont = ctxFont.replace(getTextFontSize(), \"?px \")\n        zPos *= Math.pow(0.75, (newSuper - oldSuper))\n        ctxFont = ctxFont.replace(\"?px \", getTextFontSize())\n      }\n      yPos -= 0.25 * lineHeight * (newSuper - oldSuper);\n    }\n\n    if(styletags.bolds === true) {\n      var wasBold = (oldStyle.indexOf(CHR_bold) > -1)\n      var is_Bold = (newStyle.indexOf(CHR_bold) > -1)\n\n      if(!wasBold && is_Bold) {\n        if(wasItalic) {\n          ctxFont = ctxFont.replace(\"italic \", \"italic bold \")\n        } else {\n          ctxFont = \"bold \" + ctxFont\n        }\n      }\n      if(wasBold && !is_Bold) {\n        ctxFont = ctxFont.replace(\"bold \", '')\n      }\n    }\n\n    if(styletags.italics === true) {\n      var wasItalic = (oldStyle.indexOf(CHR_italic) > -1)\n      var is_Italic = (newStyle.indexOf(CHR_italic) > -1)\n\n      if(!wasItalic && is_Italic) {\n        ctxFont = \"italic \" + ctxFont\n      }\n      if(wasItalic && !is_Italic) {\n        ctxFont = ctxFont.replace(\"italic \", '')\n      }\n    }\n    context.font = ctxFont\n  }\n\n  for(i = 0; i < numberOfLines; ++i) {\n    var txt = allTexts[i] + '\\n'\n    xPos = 0\n    yPos = i * lineHeight\n    zPos = fontSize\n\n    buffer = \"\"\n    \n    for(j = 0; j < txt.length; ++j) {\n      var style = (j + nDone < allStyles.length) ? allStyles[j + nDone] : allStyles[allStyles.length - 1]\n      if(activeStyle === style) {\n        buffer += txt[j]\n      } else {\n        writeBuffer()\n        buffer = txt[j]\n\n        if(style !== undefined) {\n          changeStyle(activeStyle, style)\n          activeStyle = style\n        }\n      }\n    }\n    writeBuffer()\n\n    nDone += txt.length\n\n    var width = Math.round(xPos + 2 * offsetX) | 0\n    if(maxWidth < width) maxWidth = width\n  }\n\n  //Cut pixels from image\n  var xCut = maxWidth\n  var yCut = offsetY + lineHeight * numberOfLines\n  var pixels = ndarray(context.getImageData(0, 0, xCut, yCut).data, [yCut, xCut, 4])\n  return pixels.pick(-1, -1, 0).transpose(1, 0)\n}\n\nfunction getContour(pixels, doSimplify) {\n  var contour = surfaceNets(pixels, 128)\n  if(doSimplify) {\n    return simplify(contour.cells, contour.positions, 0.25)\n  }\n  return {\n    edges: contour.cells,\n    positions: contour.positions\n  }\n}\n\nfunction processPixelsImpl(pixels, options, size, simplify) {\n  //Extract contour\n  var contour = getContour(pixels, simplify)\n\n  //Apply warp to positions\n  var positions = transformPositions(contour.positions, options, size)\n  var edges     = contour.edges\n  var flip = \"ccw\" === options.orientation\n\n  //Clean up the PSLG, resolve self intersections, etc.\n  cleanPSLG(positions, edges)\n\n  //If triangulate flag passed, triangulate the result\n  if(options.polygons || options.polygon || options.polyline) {\n    var result = toPolygonCrappy(edges, positions)\n    var nresult = new Array(result.length)\n    for(var i=0; i<result.length; ++i) {\n      var loops = result[i]\n      var nloops = new Array(loops.length)\n      for(var j=0; j<loops.length; ++j) {\n        var loop = loops[j]\n        var nloop = new Array(loop.length)\n        for(var k=0; k<loop.length; ++k) {\n          nloop[k] = positions[loop[k]].slice()\n        }\n        if(flip) {\n          nloop.reverse()\n        }\n        nloops[j] = nloop\n      }\n      nresult[i] = nloops\n    }\n    return nresult\n  } else if(options.triangles || options.triangulate || options.triangle) {\n    return {\n      cells: cdt2d(positions, edges, {\n        delaunay: false,\n        exterior: false,\n        interior: true\n      }),\n      positions: positions\n    }\n  } else {\n    return {\n      edges:     edges,\n      positions: positions\n    }\n  }\n}\n\nfunction processPixels(pixels, options, size) {\n  try {\n    return processPixelsImpl(pixels, options, size, true)\n  } catch(e) {}\n  try {\n    return processPixelsImpl(pixels, options, size, false)\n  } catch(e) {}\n  if(options.polygons || options.polyline || options.polygon) {\n    return []\n  }\n  if(options.triangles || options.triangulate || options.triangle) {\n    return {\n      cells: [],\n      positions: []\n    }\n  }\n  return {\n    edges: [],\n    positions: []\n  }\n}\n\nfunction vectorizeText(str, canvas, context, options) {\n  var size = 64\n  var lineSpacing = 1.25\n  var styletags = {\n    breaklines: false,\n    bolds: false,\n    italics: false,\n    subscripts: false,\n    superscripts: false\n  }\n\n  if(options) {\n\n    if(options.size &&\n       options.size > 0) size =\n       options.size\n\n    if(options.lineSpacing &&\n       options.lineSpacing > 0) lineSpacing =\n       options.lineSpacing\n\n    if(options.styletags &&\n       options.styletags.breaklines) styletags.breaklines =\n       options.styletags.breaklines ? true : false\n\n    if(options.styletags &&\n       options.styletags.bolds) styletags.bolds =\n       options.styletags.bolds ? true : false\n\n    if(options.styletags &&\n       options.styletags.italics) styletags.italics =\n       options.styletags.italics ? true : false\n\n    if(options.styletags &&\n       options.styletags.subscripts) styletags.subscripts =\n       options.styletags.subscripts ? true : false\n\n    if(options.styletags &&\n       options.styletags.superscripts) styletags.superscripts =\n       options.styletags.superscripts ? true : false\n  }\n\n  context.font = [\n    options.fontStyle,\n    options.fontVariant,\n    options.fontWeight,\n    size + \"px\",\n    options.font\n  ].filter(function(d) {return d}).join(\" \")\n  context.textAlign = \"start\"\n  context.textBaseline = \"alphabetic\"\n  context.direction = \"ltr\"\n\n  var pixels = getPixels(canvas, context, str, size, lineSpacing, styletags)\n\n  return processPixels(pixels, options, size)\n}\n\n},{\"cdt2d\":106,\"clean-pslg\":116,\"ndarray\":450,\"planar-graph-to-polyline\":468,\"simplify-planar-graph\":524,\"surface-nets\":531}],552:[function(_dereq_,module,exports){\n// Copyright (C) 2011 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * @fileoverview Install a leaky WeakMap emulation on platforms that\n * don't provide a built-in one.\n *\n * <p>Assumes that an ES5 platform where, if {@code WeakMap} is\n * already present, then it conforms to the anticipated ES6\n * specification. To run this file on an ES5 or almost ES5\n * implementation where the {@code WeakMap} specification does not\n * quite conform, run <code>repairES5.js</code> first.\n *\n * <p>Even though WeakMapModule is not global, the linter thinks it\n * is, which is why it is in the overrides list below.\n *\n * <p>NOTE: Before using this WeakMap emulation in a non-SES\n * environment, see the note below about hiddenRecord.\n *\n * @author Mark S. Miller\n * @requires crypto, ArrayBuffer, Uint8Array, navigator, console\n * @overrides WeakMap, ses, Proxy\n * @overrides WeakMapModule\n */\n\n/**\n * This {@code WeakMap} emulation is observably equivalent to the\n * ES-Harmony WeakMap, but with leakier garbage collection properties.\n *\n * <p>As with true WeakMaps, in this emulation, a key does not\n * retain maps indexed by that key and (crucially) a map does not\n * retain the keys it indexes. A map by itself also does not retain\n * the values associated with that map.\n *\n * <p>However, the values associated with a key in some map are\n * retained so long as that key is retained and those associations are\n * not overridden. For example, when used to support membranes, all\n * values exported from a given membrane will live for the lifetime\n * they would have had in the absence of an interposed membrane. Even\n * when the membrane is revoked, all objects that would have been\n * reachable in the absence of revocation will still be reachable, as\n * far as the GC can tell, even though they will no longer be relevant\n * to ongoing computation.\n *\n * <p>The API implemented here is approximately the API as implemented\n * in FF6.0a1 and agreed to by MarkM, Andreas Gal, and Dave Herman,\n * rather than the offially approved proposal page. TODO(erights):\n * upgrade the ecmascript WeakMap proposal page to explain this API\n * change and present to EcmaScript committee for their approval.\n *\n * <p>The first difference between the emulation here and that in\n * FF6.0a1 is the presence of non enumerable {@code get___, has___,\n * set___, and delete___} methods on WeakMap instances to represent\n * what would be the hidden internal properties of a primitive\n * implementation. Whereas the FF6.0a1 WeakMap.prototype methods\n * require their {@code this} to be a genuine WeakMap instance (i.e.,\n * an object of {@code [[Class]]} \"WeakMap}), since there is nothing\n * unforgeable about the pseudo-internal method names used here,\n * nothing prevents these emulated prototype methods from being\n * applied to non-WeakMaps with pseudo-internal methods of the same\n * names.\n *\n * <p>Another difference is that our emulated {@code\n * WeakMap.prototype} is not itself a WeakMap. A problem with the\n * current FF6.0a1 API is that WeakMap.prototype is itself a WeakMap\n * providing ambient mutability and an ambient communications\n * channel. Thus, if a WeakMap is already present and has this\n * problem, repairES5.js wraps it in a safe wrappper in order to\n * prevent access to this channel. (See\n * PATCH_MUTABLE_FROZEN_WEAKMAP_PROTO in repairES5.js).\n */\n\n/**\n * If this is a full <a href=\n * \"http://code.google.com/p/es-lab/wiki/SecureableES5\"\n * >secureable ES5</a> platform and the ES-Harmony {@code WeakMap} is\n * absent, install an approximate emulation.\n *\n * <p>If WeakMap is present but cannot store some objects, use our approximate\n * emulation as a wrapper.\n *\n * <p>If this is almost a secureable ES5 platform, then WeakMap.js\n * should be run after repairES5.js.\n *\n * <p>See {@code WeakMap} for documentation of the garbage collection\n * properties of this WeakMap emulation.\n */\n(function WeakMapModule() {\n  \"use strict\";\n\n  if (typeof ses !== 'undefined' && ses.ok && !ses.ok()) {\n    // already too broken, so give up\n    return;\n  }\n\n  /**\n   * In some cases (current Firefox), we must make a choice betweeen a\n   * WeakMap which is capable of using all varieties of host objects as\n   * keys and one which is capable of safely using proxies as keys. See\n   * comments below about HostWeakMap and DoubleWeakMap for details.\n   *\n   * This function (which is a global, not exposed to guests) marks a\n   * WeakMap as permitted to do what is necessary to index all host\n   * objects, at the cost of making it unsafe for proxies.\n   *\n   * Do not apply this function to anything which is not a genuine\n   * fresh WeakMap.\n   */\n  function weakMapPermitHostObjects(map) {\n    // identity of function used as a secret -- good enough and cheap\n    if (map.permitHostObjects___) {\n      map.permitHostObjects___(weakMapPermitHostObjects);\n    }\n  }\n  if (typeof ses !== 'undefined') {\n    ses.weakMapPermitHostObjects = weakMapPermitHostObjects;\n  }\n\n  // IE 11 has no Proxy but has a broken WeakMap such that we need to patch\n  // it using DoubleWeakMap; this flag tells DoubleWeakMap so.\n  var doubleWeakMapCheckSilentFailure = false;\n\n  // Check if there is already a good-enough WeakMap implementation, and if so\n  // exit without replacing it.\n  if (typeof WeakMap === 'function') {\n    var HostWeakMap = WeakMap;\n    // There is a WeakMap -- is it good enough?\n    if (typeof navigator !== 'undefined' &&\n        /Firefox/.test(navigator.userAgent)) {\n      // We're now *assuming not*, because as of this writing (2013-05-06)\n      // Firefox's WeakMaps have a miscellany of objects they won't accept, and\n      // we don't want to make an exhaustive list, and testing for just one\n      // will be a problem if that one is fixed alone (as they did for Event).\n\n      // If there is a platform that we *can* reliably test on, here's how to\n      // do it:\n      //  var problematic = ... ;\n      //  var testHostMap = new HostWeakMap();\n      //  try {\n      //    testHostMap.set(problematic, 1);  // Firefox 20 will throw here\n      //    if (testHostMap.get(problematic) === 1) {\n      //      return;\n      //    }\n      //  } catch (e) {}\n\n    } else {\n      // IE 11 bug: WeakMaps silently fail to store frozen objects.\n      var testMap = new HostWeakMap();\n      var testObject = Object.freeze({});\n      testMap.set(testObject, 1);\n      if (testMap.get(testObject) !== 1) {\n        doubleWeakMapCheckSilentFailure = true;\n        // Fall through to installing our WeakMap.\n      } else {\n        module.exports = WeakMap;\n        return;\n      }\n    }\n  }\n\n  var hop = Object.prototype.hasOwnProperty;\n  var gopn = Object.getOwnPropertyNames;\n  var defProp = Object.defineProperty;\n  var isExtensible = Object.isExtensible;\n\n  /**\n   * Security depends on HIDDEN_NAME being both <i>unguessable</i> and\n   * <i>undiscoverable</i> by untrusted code.\n   *\n   * <p>Given the known weaknesses of Math.random() on existing\n   * browsers, it does not generate unguessability we can be confident\n   * of.\n   *\n   * <p>It is the monkey patching logic in this file that is intended\n   * to ensure undiscoverability. The basic idea is that there are\n   * three fundamental means of discovering properties of an object:\n   * The for/in loop, Object.keys(), and Object.getOwnPropertyNames(),\n   * as well as some proposed ES6 extensions that appear on our\n   * whitelist. The first two only discover enumerable properties, and\n   * we only use HIDDEN_NAME to name a non-enumerable property, so the\n   * only remaining threat should be getOwnPropertyNames and some\n   * proposed ES6 extensions that appear on our whitelist. We monkey\n   * patch them to remove HIDDEN_NAME from the list of properties they\n   * returns.\n   *\n   * <p>TODO(erights): On a platform with built-in Proxies, proxies\n   * could be used to trap and thereby discover the HIDDEN_NAME, so we\n   * need to monkey patch Proxy.create, Proxy.createFunction, etc, in\n   * order to wrap the provided handler with the real handler which\n   * filters out all traps using HIDDEN_NAME.\n   *\n   * <p>TODO(erights): Revisit Mike Stay's suggestion that we use an\n   * encapsulated function at a not-necessarily-secret name, which\n   * uses the Stiegler shared-state rights amplification pattern to\n   * reveal the associated value only to the WeakMap in which this key\n   * is associated with that value. Since only the key retains the\n   * function, the function can also remember the key without causing\n   * leakage of the key, so this doesn't violate our general gc\n   * goals. In addition, because the name need not be a guarded\n   * secret, we could efficiently handle cross-frame frozen keys.\n   */\n  var HIDDEN_NAME_PREFIX = 'weakmap:';\n  var HIDDEN_NAME = HIDDEN_NAME_PREFIX + 'ident:' + Math.random() + '___';\n\n  if (typeof crypto !== 'undefined' &&\n      typeof crypto.getRandomValues === 'function' &&\n      typeof ArrayBuffer === 'function' &&\n      typeof Uint8Array === 'function') {\n    var ab = new ArrayBuffer(25);\n    var u8s = new Uint8Array(ab);\n    crypto.getRandomValues(u8s);\n    HIDDEN_NAME = HIDDEN_NAME_PREFIX + 'rand:' +\n      Array.prototype.map.call(u8s, function(u8) {\n        return (u8 % 36).toString(36);\n      }).join('') + '___';\n  }\n\n  function isNotHiddenName(name) {\n    return !(\n        name.substr(0, HIDDEN_NAME_PREFIX.length) == HIDDEN_NAME_PREFIX &&\n        name.substr(name.length - 3) === '___');\n  }\n\n  /**\n   * Monkey patch getOwnPropertyNames to avoid revealing the\n   * HIDDEN_NAME.\n   *\n   * <p>The ES5.1 spec requires each name to appear only once, but as\n   * of this writing, this requirement is controversial for ES6, so we\n   * made this code robust against this case. If the resulting extra\n   * search turns out to be expensive, we can probably relax this once\n   * ES6 is adequately supported on all major browsers, iff no browser\n   * versions we support at that time have relaxed this constraint\n   * without providing built-in ES6 WeakMaps.\n   */\n  defProp(Object, 'getOwnPropertyNames', {\n    value: function fakeGetOwnPropertyNames(obj) {\n      return gopn(obj).filter(isNotHiddenName);\n    }\n  });\n\n  /**\n   * getPropertyNames is not in ES5 but it is proposed for ES6 and\n   * does appear in our whitelist, so we need to clean it too.\n   */\n  if ('getPropertyNames' in Object) {\n    var originalGetPropertyNames = Object.getPropertyNames;\n    defProp(Object, 'getPropertyNames', {\n      value: function fakeGetPropertyNames(obj) {\n        return originalGetPropertyNames(obj).filter(isNotHiddenName);\n      }\n    });\n  }\n\n  /**\n   * <p>To treat objects as identity-keys with reasonable efficiency\n   * on ES5 by itself (i.e., without any object-keyed collections), we\n   * need to add a hidden property to such key objects when we\n   * can. This raises several issues:\n   * <ul>\n   * <li>Arranging to add this property to objects before we lose the\n   *     chance, and\n   * <li>Hiding the existence of this new property from most\n   *     JavaScript code.\n   * <li>Preventing <i>certification theft</i>, where one object is\n   *     created falsely claiming to be the key of an association\n   *     actually keyed by another object.\n   * <li>Preventing <i>value theft</i>, where untrusted code with\n   *     access to a key object but not a weak map nevertheless\n   *     obtains access to the value associated with that key in that\n   *     weak map.\n   * </ul>\n   * We do so by\n   * <ul>\n   * <li>Making the name of the hidden property unguessable, so \"[]\"\n   *     indexing, which we cannot intercept, cannot be used to access\n   *     a property without knowing the name.\n   * <li>Making the hidden property non-enumerable, so we need not\n   *     worry about for-in loops or {@code Object.keys},\n   * <li>monkey patching those reflective methods that would\n   *     prevent extensions, to add this hidden property first,\n   * <li>monkey patching those methods that would reveal this\n   *     hidden property.\n   * </ul>\n   * Unfortunately, because of same-origin iframes, we cannot reliably\n   * add this hidden property before an object becomes\n   * non-extensible. Instead, if we encounter a non-extensible object\n   * without a hidden record that we can detect (whether or not it has\n   * a hidden record stored under a name secret to us), then we just\n   * use the key object itself to represent its identity in a brute\n   * force leaky map stored in the weak map, losing all the advantages\n   * of weakness for these.\n   */\n  function getHiddenRecord(key) {\n    if (key !== Object(key)) {\n      throw new TypeError('Not an object: ' + key);\n    }\n    var hiddenRecord = key[HIDDEN_NAME];\n    if (hiddenRecord && hiddenRecord.key === key) { return hiddenRecord; }\n    if (!isExtensible(key)) {\n      // Weak map must brute force, as explained in doc-comment above.\n      return void 0;\n    }\n\n    // The hiddenRecord and the key point directly at each other, via\n    // the \"key\" and HIDDEN_NAME properties respectively. The key\n    // field is for quickly verifying that this hidden record is an\n    // own property, not a hidden record from up the prototype chain.\n    //\n    // NOTE: Because this WeakMap emulation is meant only for systems like\n    // SES where Object.prototype is frozen without any numeric\n    // properties, it is ok to use an object literal for the hiddenRecord.\n    // This has two advantages:\n    // * It is much faster in a performance critical place\n    // * It avoids relying on Object.create(null), which had been\n    //   problematic on Chrome 28.0.1480.0. See\n    //   https://code.google.com/p/google-caja/issues/detail?id=1687\n    hiddenRecord = { key: key };\n\n    // When using this WeakMap emulation on platforms where\n    // Object.prototype might not be frozen and Object.create(null) is\n    // reliable, use the following two commented out lines instead.\n    // hiddenRecord = Object.create(null);\n    // hiddenRecord.key = key;\n\n    // Please contact us if you need this to work on platforms where\n    // Object.prototype might not be frozen and\n    // Object.create(null) might not be reliable.\n\n    try {\n      defProp(key, HIDDEN_NAME, {\n        value: hiddenRecord,\n        writable: false,\n        enumerable: false,\n        configurable: false\n      });\n      return hiddenRecord;\n    } catch (error) {\n      // Under some circumstances, isExtensible seems to misreport whether\n      // the HIDDEN_NAME can be defined.\n      // The circumstances have not been isolated, but at least affect\n      // Node.js v0.10.26 on TravisCI / Linux, but not the same version of\n      // Node.js on OS X.\n      return void 0;\n    }\n  }\n\n  /**\n   * Monkey patch operations that would make their argument\n   * non-extensible.\n   *\n   * <p>The monkey patched versions throw a TypeError if their\n   * argument is not an object, so it should only be done to functions\n   * that should throw a TypeError anyway if their argument is not an\n   * object.\n   */\n  (function(){\n    var oldFreeze = Object.freeze;\n    defProp(Object, 'freeze', {\n      value: function identifyingFreeze(obj) {\n        getHiddenRecord(obj);\n        return oldFreeze(obj);\n      }\n    });\n    var oldSeal = Object.seal;\n    defProp(Object, 'seal', {\n      value: function identifyingSeal(obj) {\n        getHiddenRecord(obj);\n        return oldSeal(obj);\n      }\n    });\n    var oldPreventExtensions = Object.preventExtensions;\n    defProp(Object, 'preventExtensions', {\n      value: function identifyingPreventExtensions(obj) {\n        getHiddenRecord(obj);\n        return oldPreventExtensions(obj);\n      }\n    });\n  })();\n\n  function constFunc(func) {\n    func.prototype = null;\n    return Object.freeze(func);\n  }\n\n  var calledAsFunctionWarningDone = false;\n  function calledAsFunctionWarning() {\n    // Future ES6 WeakMap is currently (2013-09-10) expected to reject WeakMap()\n    // but we used to permit it and do it ourselves, so warn only.\n    if (!calledAsFunctionWarningDone && typeof console !== 'undefined') {\n      calledAsFunctionWarningDone = true;\n      console.warn('WeakMap should be invoked as new WeakMap(), not ' +\n          'WeakMap(). This will be an error in the future.');\n    }\n  }\n\n  var nextId = 0;\n\n  var OurWeakMap = function() {\n    if (!(this instanceof OurWeakMap)) {  // approximate test for new ...()\n      calledAsFunctionWarning();\n    }\n\n    // We are currently (12/25/2012) never encountering any prematurely\n    // non-extensible keys.\n    var keys = []; // brute force for prematurely non-extensible keys.\n    var values = []; // brute force for corresponding values.\n    var id = nextId++;\n\n    function get___(key, opt_default) {\n      var index;\n      var hiddenRecord = getHiddenRecord(key);\n      if (hiddenRecord) {\n        return id in hiddenRecord ? hiddenRecord[id] : opt_default;\n      } else {\n        index = keys.indexOf(key);\n        return index >= 0 ? values[index] : opt_default;\n      }\n    }\n\n    function has___(key) {\n      var hiddenRecord = getHiddenRecord(key);\n      if (hiddenRecord) {\n        return id in hiddenRecord;\n      } else {\n        return keys.indexOf(key) >= 0;\n      }\n    }\n\n    function set___(key, value) {\n      var index;\n      var hiddenRecord = getHiddenRecord(key);\n      if (hiddenRecord) {\n        hiddenRecord[id] = value;\n      } else {\n        index = keys.indexOf(key);\n        if (index >= 0) {\n          values[index] = value;\n        } else {\n          // Since some browsers preemptively terminate slow turns but\n          // then continue computing with presumably corrupted heap\n          // state, we here defensively get keys.length first and then\n          // use it to update both the values and keys arrays, keeping\n          // them in sync.\n          index = keys.length;\n          values[index] = value;\n          // If we crash here, values will be one longer than keys.\n          keys[index] = key;\n        }\n      }\n      return this;\n    }\n\n    function delete___(key) {\n      var hiddenRecord = getHiddenRecord(key);\n      var index, lastIndex;\n      if (hiddenRecord) {\n        return id in hiddenRecord && delete hiddenRecord[id];\n      } else {\n        index = keys.indexOf(key);\n        if (index < 0) {\n          return false;\n        }\n        // Since some browsers preemptively terminate slow turns but\n        // then continue computing with potentially corrupted heap\n        // state, we here defensively get keys.length first and then use\n        // it to update both the keys and the values array, keeping\n        // them in sync. We update the two with an order of assignments,\n        // such that any prefix of these assignments will preserve the\n        // key/value correspondence, either before or after the delete.\n        // Note that this needs to work correctly when index === lastIndex.\n        lastIndex = keys.length - 1;\n        keys[index] = void 0;\n        // If we crash here, there's a void 0 in the keys array, but\n        // no operation will cause a \"keys.indexOf(void 0)\", since\n        // getHiddenRecord(void 0) will always throw an error first.\n        values[index] = values[lastIndex];\n        // If we crash here, values[index] cannot be found here,\n        // because keys[index] is void 0.\n        keys[index] = keys[lastIndex];\n        // If index === lastIndex and we crash here, then keys[index]\n        // is still void 0, since the aliasing killed the previous key.\n        keys.length = lastIndex;\n        // If we crash here, keys will be one shorter than values.\n        values.length = lastIndex;\n        return true;\n      }\n    }\n\n    return Object.create(OurWeakMap.prototype, {\n      get___:    { value: constFunc(get___) },\n      has___:    { value: constFunc(has___) },\n      set___:    { value: constFunc(set___) },\n      delete___: { value: constFunc(delete___) }\n    });\n  };\n\n  OurWeakMap.prototype = Object.create(Object.prototype, {\n    get: {\n      /**\n       * Return the value most recently associated with key, or\n       * opt_default if none.\n       */\n      value: function get(key, opt_default) {\n        return this.get___(key, opt_default);\n      },\n      writable: true,\n      configurable: true\n    },\n\n    has: {\n      /**\n       * Is there a value associated with key in this WeakMap?\n       */\n      value: function has(key) {\n        return this.has___(key);\n      },\n      writable: true,\n      configurable: true\n    },\n\n    set: {\n      /**\n       * Associate value with key in this WeakMap, overwriting any\n       * previous association if present.\n       */\n      value: function set(key, value) {\n        return this.set___(key, value);\n      },\n      writable: true,\n      configurable: true\n    },\n\n    'delete': {\n      /**\n       * Remove any association for key in this WeakMap, returning\n       * whether there was one.\n       *\n       * <p>Note that the boolean return here does not work like the\n       * {@code delete} operator. The {@code delete} operator returns\n       * whether the deletion succeeds at bringing about a state in\n       * which the deleted property is absent. The {@code delete}\n       * operator therefore returns true if the property was already\n       * absent, whereas this {@code delete} method returns false if\n       * the association was already absent.\n       */\n      value: function remove(key) {\n        return this.delete___(key);\n      },\n      writable: true,\n      configurable: true\n    }\n  });\n\n  if (typeof HostWeakMap === 'function') {\n    (function() {\n      // If we got here, then the platform has a WeakMap but we are concerned\n      // that it may refuse to store some key types. Therefore, make a map\n      // implementation which makes use of both as possible.\n\n      // In this mode we are always using double maps, so we are not proxy-safe.\n      // This combination does not occur in any known browser, but we had best\n      // be safe.\n      if (doubleWeakMapCheckSilentFailure && typeof Proxy !== 'undefined') {\n        Proxy = undefined;\n      }\n\n      function DoubleWeakMap() {\n        if (!(this instanceof OurWeakMap)) {  // approximate test for new ...()\n          calledAsFunctionWarning();\n        }\n\n        // Preferable, truly weak map.\n        var hmap = new HostWeakMap();\n\n        // Our hidden-property-based pseudo-weak-map. Lazily initialized in the\n        // 'set' implementation; thus we can avoid performing extra lookups if\n        // we know all entries actually stored are entered in 'hmap'.\n        var omap = undefined;\n\n        // Hidden-property maps are not compatible with proxies because proxies\n        // can observe the hidden name and either accidentally expose it or fail\n        // to allow the hidden property to be set. Therefore, we do not allow\n        // arbitrary WeakMaps to switch to using hidden properties, but only\n        // those which need the ability, and unprivileged code is not allowed\n        // to set the flag.\n        //\n        // (Except in doubleWeakMapCheckSilentFailure mode in which case we\n        // disable proxies.)\n        var enableSwitching = false;\n\n        function dget(key, opt_default) {\n          if (omap) {\n            return hmap.has(key) ? hmap.get(key)\n                : omap.get___(key, opt_default);\n          } else {\n            return hmap.get(key, opt_default);\n          }\n        }\n\n        function dhas(key) {\n          return hmap.has(key) || (omap ? omap.has___(key) : false);\n        }\n\n        var dset;\n        if (doubleWeakMapCheckSilentFailure) {\n          dset = function(key, value) {\n            hmap.set(key, value);\n            if (!hmap.has(key)) {\n              if (!omap) { omap = new OurWeakMap(); }\n              omap.set(key, value);\n            }\n            return this;\n          };\n        } else {\n          dset = function(key, value) {\n            if (enableSwitching) {\n              try {\n                hmap.set(key, value);\n              } catch (e) {\n                if (!omap) { omap = new OurWeakMap(); }\n                omap.set___(key, value);\n              }\n            } else {\n              hmap.set(key, value);\n            }\n            return this;\n          };\n        }\n\n        function ddelete(key) {\n          var result = !!hmap['delete'](key);\n          if (omap) { return omap.delete___(key) || result; }\n          return result;\n        }\n\n        return Object.create(OurWeakMap.prototype, {\n          get___:    { value: constFunc(dget) },\n          has___:    { value: constFunc(dhas) },\n          set___:    { value: constFunc(dset) },\n          delete___: { value: constFunc(ddelete) },\n          permitHostObjects___: { value: constFunc(function(token) {\n            if (token === weakMapPermitHostObjects) {\n              enableSwitching = true;\n            } else {\n              throw new Error('bogus call to permitHostObjects___');\n            }\n          })}\n        });\n      }\n      DoubleWeakMap.prototype = OurWeakMap.prototype;\n      module.exports = DoubleWeakMap;\n\n      // define .constructor to hide OurWeakMap ctor\n      Object.defineProperty(WeakMap.prototype, 'constructor', {\n        value: WeakMap,\n        enumerable: false,  // as default .constructor is\n        configurable: true,\n        writable: true\n      });\n    })();\n  } else {\n    // There is no host WeakMap, so we must use the emulation.\n\n    // Emulated WeakMaps are incompatible with native proxies (because proxies\n    // can observe the hidden name), so we must disable Proxy usage (in\n    // ArrayLike and Domado, currently).\n    if (typeof Proxy !== 'undefined') {\n      Proxy = undefined;\n    }\n\n    module.exports = OurWeakMap;\n  }\n})();\n\n},{}],553:[function(_dereq_,module,exports){\nvar hiddenStore = _dereq_('./hidden-store.js');\n\nmodule.exports = createStore;\n\nfunction createStore() {\n    var key = {};\n\n    return function (obj) {\n        if ((typeof obj !== 'object' || obj === null) &&\n            typeof obj !== 'function'\n        ) {\n            throw new Error('Weakmap-shim: Key must be object')\n        }\n\n        var store = obj.valueOf(key);\n        return store && store.identity === key ?\n            store : hiddenStore(obj, key);\n    };\n}\n\n},{\"./hidden-store.js\":554}],554:[function(_dereq_,module,exports){\nmodule.exports = hiddenStore;\n\nfunction hiddenStore(obj, key) {\n    var store = { identity: key };\n    var valueOf = obj.valueOf;\n\n    Object.defineProperty(obj, \"valueOf\", {\n        value: function (value) {\n            return value !== key ?\n                valueOf.apply(this, arguments) : store;\n        },\n        writable: true\n    });\n\n    return store;\n}\n\n},{}],555:[function(_dereq_,module,exports){\n// Original - @Gozola.\n// https://gist.github.com/Gozala/1269991\n// This is a reimplemented version (with a few bug fixes).\n\nvar createStore = _dereq_('./create-store.js');\n\nmodule.exports = weakMap;\n\nfunction weakMap() {\n    var privates = createStore();\n\n    return {\n        'get': function (key, fallback) {\n            var store = privates(key)\n            return store.hasOwnProperty('value') ?\n                store.value : fallback\n        },\n        'set': function (key, value) {\n            privates(key).value = value;\n            return this;\n        },\n        'has': function(key) {\n            return 'value' in privates(key);\n        },\n        'delete': function (key) {\n            return delete privates(key).value;\n        }\n    }\n}\n\n},{\"./create-store.js\":553}],556:[function(_dereq_,module,exports){\nvar getContext = _dereq_('get-canvas-context')\n\nmodule.exports = function getWebGLContext (opt) {\n  return getContext('webgl', opt)\n}\n\n},{\"get-canvas-context\":232}],557:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Traditional Chinese calendar for jQuery v2.0.2.\n   Written by Nicolas Riesco (enquiries@nicolasriesco.net) December 2016.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\nvar gregorianCalendar = main.instance();\n\n/** Implementation of the traditional Chinese calendar.\n    Source of calendar tables https://github.com/isee15/Lunar-Solar-Calendar-Converter .\n    @class ChineseCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction ChineseCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nChineseCalendar.prototype = new main.baseCalendar;\n\nassign(ChineseCalendar.prototype, {\n    /** The calendar name.\n        @memberof ChineseCalendar */\n    name: 'Chinese',\n     /** Julian date of start of Gregorian epoch: 1 January 0001 CE.\n        @memberof GregorianCalendar */\n    jdEpoch: 1721425.5,\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof ChineseCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        This calendar uses month indices to account for intercalary months. \n        @memberof ChineseCalendar */\n    minMonth: 0,\n    /** The first month in the year.\n        This calendar uses month indices to account for intercalary months. \n        @memberof ChineseCalendar */\n    firstMonth: 0,\n    /** The minimum day number.\n        @memberof ChineseCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof ChineseCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Chinese',\n            epochs: ['BEC', 'EC'],\n            monthNumbers: function(date, padded) {\n                if (typeof date === 'string') {\n                    var match = date.match(MONTH_NUMBER_REGEXP);\n                    return (match) ? match[0] : '';\n                }\n\n                var year = this._validateYear(date);\n                var monthIndex = date.month();\n\n                var month = '' + this.toChineseMonth(year, monthIndex);\n\n                if (padded && month.length < 2) {\n                    month = \"0\" + month;\n                }\n\n                if (this.isIntercalaryMonth(year, monthIndex)) {\n                    month += 'i';\n                }\n\n                return month;\n            },\n            monthNames: function(date) {\n                if (typeof date === 'string') {\n                    var match = date.match(MONTH_NAME_REGEXP);\n                    return (match) ? match[0] : '';\n                }\n\n                var year = this._validateYear(date);\n                var monthIndex = date.month();\n\n                var month = this.toChineseMonth(year, monthIndex);\n\n                var monthName = ['一月','二月','三月','四月','五月','六月',\n                    '七月','八月','九月','十月','十一月','十二月'][month - 1];\n\n                if (this.isIntercalaryMonth(year, monthIndex)) {\n                    monthName = '闰' + monthName;\n                }\n\n                return monthName;\n            },\n            monthNamesShort: function(date) {\n                if (typeof date === 'string') {\n                    var match = date.match(MONTH_SHORT_NAME_REGEXP);\n                    return (match) ? match[0] : '';\n                }\n\n                var year = this._validateYear(date);\n                var monthIndex = date.month();\n\n                var month = this.toChineseMonth(year, monthIndex);\n\n                var monthName = ['一','二','三','四','五','六',\n                    '七','八','九','十','十一','十二'][month - 1];\n\n                if (this.isIntercalaryMonth(year, monthIndex)) {\n                    monthName = '闰' + monthName;\n                }\n\n                return monthName;\n            },\n            parseMonth: function(year, monthString) {\n                year = this._validateYear(year);\n                var month = parseInt(monthString);\n                var isIntercalary;\n\n                if (!isNaN(month)) {\n                    var i = monthString[monthString.length - 1];\n                    isIntercalary = (i === 'i' || i === 'I');\n                } else {\n                    if (monthString[0] === '闰') {\n                        isIntercalary = true;\n                        monthString = monthString.substring(1);\n                    }\n                    if (monthString[monthString.length - 1] === '月') {\n                        monthString = monthString.substring(0, monthString.length - 1);\n                    }\n                    month = 1 +\n                        ['一','二','三','四','五','六',\n                        '七','八','九','十','十一','十二'].indexOf(monthString);\n                }\n\n                var monthIndex = this.toMonthIndex(year, month, isIntercalary);\n                return monthIndex;\n            },\n            dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n            dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n            dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],\n            digits: null,\n            dateFormat: 'yyyy/mm/dd',\n            firstDay: 1,\n            isRTL: false\n        }\n    },\n\n    /** Check that a candidate date is from the same calendar and is valid.\n        @memberof BaseCalendar\n        @private\n        @param year {CDate|number} The date or the year to validate.\n        @param error {string} Error message if invalid.\n        @return {number} The year.\n        @throws Error if year out of range. */\n    _validateYear: function(year, error) {\n        if (year.year) {\n            year = year.year();\n        }\n\n        if (typeof year !== 'number' || year < 1888 || year > 2111) {\n            throw error.replace(/\\{0\\}/, this.local.name);\n        }\n\n        return year;\n    },\n\n    /** Retrieve the month index (i.e. accounting for intercalary months).\n        @memberof ChineseCalendar\n        @param year {number} The year.\n        @param month {number} The month (1 for first month).\n        @param [isIntercalary=false] {boolean} If month is intercalary.\n        @return {number} The month index (0 for first month).\n        @throws Error if an invalid month/year or a different calendar used. */\n    toMonthIndex: function(year, month, isIntercalary) {\n        // compute intercalary month in the year (0 if none)\n        var intercalaryMonth = this.intercalaryMonth(year);\n\n        // validate month\n        var invalidIntercalaryMonth = \n            (isIntercalary && month !== intercalaryMonth);\n        if (invalidIntercalaryMonth || month < 1 || month > 12) {\n            throw main.local.invalidMonth\n                .replace(/\\{0\\}/, this.local.name);\n        }\n\n        // compute month index\n        var monthIndex;\n\n        if (!intercalaryMonth) {\n            monthIndex = month - 1;\n        } else if(!isIntercalary && month <= intercalaryMonth) {\n            monthIndex = month - 1;\n        } else {\n            monthIndex = month;\n        }\n\n        return monthIndex;\n    },\n\n    /** Retrieve the month (i.e. accounting for intercalary months).\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date or the year to examine.\n        @param monthIndex {number} The month index (0 for first month).\n        @return {number} The month (1 for first month).\n        @throws Error if an invalid month/year or a different calendar used. */\n    toChineseMonth: function(year, monthIndex) {\n        if (year.year) {\n            year = year.year();\n            monthIndex = year.month();\n        }\n\n        // compute intercalary month in the year (0 if none)\n        var intercalaryMonth = this.intercalaryMonth(year);\n\n        // validate month\n        var maxMonthIndex = (intercalaryMonth) ? 12 : 11;\n        if (monthIndex < 0 || monthIndex > maxMonthIndex) {\n            throw main.local.invalidMonth\n                .replace(/\\{0\\}/, this.local.name);\n        }\n\n        // compute Chinese month\n        var month;\n\n        if (!intercalaryMonth) {\n            month = monthIndex + 1;\n        } else if(monthIndex < intercalaryMonth) {\n            month = monthIndex + 1;\n        } else {\n            month = monthIndex;\n        }\n\n        return month;\n    },\n\n    /** Determine the intercalary month of a year (if any).\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The intercalary month number, or 0 if none.\n        @throws Error if an invalid year or a different calendar used. */\n    intercalaryMonth: function(year) {\n        year = this._validateYear(year);\n\n        var monthDaysTable = LUNAR_MONTH_DAYS[year - LUNAR_MONTH_DAYS[0]];\n        var intercalaryMonth = monthDaysTable >> 13;\n\n        return intercalaryMonth;\n    },\n\n    /** Determine whether this date is an intercalary month.\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [monthIndex] {number} The month index to examine.\n        @return {boolean} <code>true</code> if this is an intercalary month, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    isIntercalaryMonth: function(year, monthIndex) {\n        if (year.year) {\n            year = year.year();\n            monthIndex = year.month();\n        }\n\n        var intercalaryMonth = this.intercalaryMonth(year);\n\n        return !!intercalaryMonth && intercalaryMonth === monthIndex;\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        return (this.intercalaryMonth(year) !== 0);\n    },\n\n    /** Determine the week of the year for a date - ISO 8601.\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [monthIndex] {number} The month index to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, monthIndex, day) {\n        // compute Chinese new year\n        var validatedYear =\n            this._validateYear(year, main.local.invalidyear);\n        var packedDate =\n            CHINESE_NEW_YEAR[validatedYear - CHINESE_NEW_YEAR[0]];\n\n        var y = (packedDate >> 9) & 0xFFF;\n        var m = (packedDate >> 5) & 0x0F;\n        var d = packedDate & 0x1F;\n        \n        // find first Thrusday of the year\n        var firstThursday;\n        firstThursday = gregorianCalendar.newDate(y, m, d);\n        firstThursday.add(4 - (firstThursday.dayOfWeek() || 7), 'd');\n\n        // compute days from first Thursday\n        var offset =\n            this.toJD(year, monthIndex, day) - firstThursday.toJD();\n        return 1 + Math.floor(offset / 7);\n    },\n\n    /** Retrieve the number of months in a year.\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of months.\n        @throws Error if an invalid year or a different calendar used. */\n    monthsInYear: function(year) {\n        return (this.leapYear(year)) ? 13 : 12;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [monthIndex] {number} The month index.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, monthIndex) {\n        if (year.year) {\n            monthIndex = year.month();\n            year = year.year();\n        }\n\n        year = this._validateYear(year);\n\n        var monthDaysTable = LUNAR_MONTH_DAYS[year - LUNAR_MONTH_DAYS[0]];\n\n        var intercalaryMonth = monthDaysTable >> 13;\n        var maxMonthIndex = (intercalaryMonth) ? 12 : 11;\n        if (monthIndex > maxMonthIndex) {\n            throw main.local.invalidMonth\n                .replace(/\\{0\\}/, this.local.name);\n        }\n\n        var daysInMonth = (monthDaysTable & (1 << (12 - monthIndex))) ?\n            30 : 29;\n\n        return daysInMonth;\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [monthIndex] {number} The month index to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, monthIndex, day) {\n        return (this.dayOfWeek(year, monthIndex, day) || 7) < 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof ChineseCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [monthIndex] {number} The month index to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, monthIndex, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        year = this._validateYear(date.year());\n        monthIndex = date.month();\n        day = date.day();\n\n        var isIntercalary = this.isIntercalaryMonth(year, monthIndex);\n        var month = this.toChineseMonth(year, monthIndex);\n\n        var solar = toSolar(year, month, day, isIntercalary);\n\n        return gregorianCalendar.toJD(solar.year, solar.month, solar.day);\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof ChineseCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        var date = gregorianCalendar.fromJD(jd);\n        var lunar = toLunar(date.year(), date.month(), date.day());\n        var monthIndex = this.toMonthIndex(\n            lunar.year, lunar.month, lunar.isIntercalary);\n        return this.newDate(lunar.year, monthIndex, lunar.day);\n    },\n\n    /** Create a new date from a string.\n        @memberof ChineseCalendar\n        @param dateString {string} String representing a Chinese date\n        @return {CDate} The new date.\n        @throws Error if an invalid date. */\n    fromString: function(dateString) {\n        var match = dateString.match(DATE_REGEXP);\n\n        var year = this._validateYear(+match[1]);\n\n        var month = +match[2];\n        var isIntercalary = !!match[3];\n        var monthIndex = this.toMonthIndex(year, month, isIntercalary);\n\n        var day = +match[4];\n\n        return this.newDate(year, monthIndex, day);\n    },\n\n    /** Add period(s) to a date.\n        Cater for no year zero.\n        @memberof ChineseCalendar\n        @param date {CDate} The starting date.\n        @param offset {number} The number of periods to adjust by.\n        @param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.\n        @return {CDate} The updated date.\n        @throws Error if a different calendar used. */\n    add: function(date, offset, period) {\n        var year = date.year();\n        var monthIndex = date.month();\n        var isIntercalary = this.isIntercalaryMonth(year, monthIndex);\n        var month = this.toChineseMonth(year, monthIndex);\n\n        var cdate = Object.getPrototypeOf(ChineseCalendar.prototype)\n            .add.call(this, date, offset, period);\n\n        if (period === 'y') {\n            // Resync month\n            var resultYear = cdate.year();\n            var resultMonthIndex = cdate.month();\n\n            // Using the fact the month index of an intercalary month\n            // equals its month number:\n            var resultCanBeIntercalaryMonth =\n                this.isIntercalaryMonth(resultYear, month);\n\n            var correctedMonthIndex =\n                (isIntercalary && resultCanBeIntercalaryMonth) ?\n                this.toMonthIndex(resultYear, month, true) :\n                this.toMonthIndex(resultYear, month, false);\n\n            if (correctedMonthIndex !== resultMonthIndex) {\n                cdate.month(correctedMonthIndex);\n            }\n        }\n\n        return cdate;\n    },\n});\n\n// Used by ChineseCalendar.prototype.fromString\nvar DATE_REGEXP = /^\\s*(-?\\d\\d\\d\\d|\\d\\d)[-/](\\d?\\d)([iI]?)[-/](\\d?\\d)/m;\nvar MONTH_NUMBER_REGEXP = /^\\d?\\d[iI]?/m;\nvar MONTH_NAME_REGEXP = /^闰?十?[一二三四五六七八九]?月/m;\nvar MONTH_SHORT_NAME_REGEXP = /^闰?十?[一二三四五六七八九]?/m;\n\n// Chinese calendar implementation\nmain.calendars.chinese = ChineseCalendar;\n\n// Chinese calendar tables from year 1888 to 2111\n//\n// Source:\n// https://github.com/isee15/Lunar-Solar-Calendar-Converter.git\n\n// Table of intercalary months and days per month from year 1888 to 2111\n//\n// bit (12 - i):        days in the i^th month\n//                      (= 0 if i^th lunar month has 29 days)\n//                      (= 1 if i^th lunar month has 30 days)\n//                      (first month in lunar year is i = 0)\n// bits (13,14,15,16):  intercalary month\n//                      (= 0 if lunar year has no intercalary month)\nvar LUNAR_MONTH_DAYS = [1887, 0x1694, 0x16aa, 0x4ad5,\n    0xab6, 0xc4b7, 0x4ae, 0xa56, 0xb52a, 0x1d2a, 0xd54, 0x75aa, 0x156a,\n    0x1096d, 0x95c, 0x14ae, 0xaa4d, 0x1a4c, 0x1b2a, 0x8d55, 0xad4,\n    0x135a, 0x495d, 0x95c, 0xd49b, 0x149a, 0x1a4a, 0xbaa5, 0x16a8,\n    0x1ad4, 0x52da, 0x12b6, 0xe937, 0x92e, 0x1496, 0xb64b, 0xd4a,\n    0xda8, 0x95b5, 0x56c, 0x12ae, 0x492f, 0x92e, 0xcc96, 0x1a94,\n    0x1d4a, 0xada9, 0xb5a, 0x56c, 0x726e, 0x125c, 0xf92d, 0x192a,\n    0x1a94, 0xdb4a, 0x16aa, 0xad4, 0x955b, 0x4ba, 0x125a, 0x592b,\n    0x152a, 0xf695, 0xd94, 0x16aa, 0xaab5, 0x9b4, 0x14b6, 0x6a57,\n    0xa56, 0x1152a, 0x1d2a, 0xd54, 0xd5aa, 0x156a, 0x96c, 0x94ae,\n    0x14ae, 0xa4c, 0x7d26, 0x1b2a, 0xeb55, 0xad4, 0x12da, 0xa95d,\n    0x95a, 0x149a, 0x9a4d, 0x1a4a, 0x11aa5, 0x16a8, 0x16d4, 0xd2da,\n    0x12b6, 0x936, 0x9497, 0x1496, 0x1564b, 0xd4a, 0xda8, 0xd5b4,\n    0x156c, 0x12ae, 0xa92f, 0x92e, 0xc96, 0x6d4a, 0x1d4a, 0x10d65,\n    0xb58, 0x156c, 0xb26d, 0x125c, 0x192c, 0x9a95, 0x1a94, 0x1b4a,\n    0x4b55, 0xad4, 0xf55b, 0x4ba, 0x125a, 0xb92b, 0x152a, 0x1694,\n    0x96aa, 0x15aa, 0x12ab5, 0x974, 0x14b6, 0xca57, 0xa56, 0x1526,\n    0x8e95, 0xd54, 0x15aa, 0x49b5, 0x96c, 0xd4ae, 0x149c, 0x1a4c,\n    0xbd26, 0x1aa6, 0xb54, 0x6d6a, 0x12da, 0x1695d, 0x95a, 0x149a,\n    0xda4b, 0x1a4a, 0x1aa4, 0xbb54, 0x16b4, 0xada, 0x495b, 0x936,\n    0xf497, 0x1496, 0x154a, 0xb6a5, 0xda4, 0x15b4, 0x6ab6, 0x126e,\n    0x1092f, 0x92e, 0xc96, 0xcd4a, 0x1d4a, 0xd64, 0x956c, 0x155c,\n    0x125c, 0x792e, 0x192c, 0xfa95, 0x1a94, 0x1b4a, 0xab55, 0xad4,\n    0x14da, 0x8a5d, 0xa5a, 0x1152b, 0x152a, 0x1694, 0xd6aa, 0x15aa,\n    0xab4, 0x94ba, 0x14b6, 0xa56, 0x7527, 0xd26, 0xee53, 0xd54, 0x15aa,\n    0xa9b5, 0x96c, 0x14ae, 0x8a4e, 0x1a4c, 0x11d26, 0x1aa4, 0x1b54,\n    0xcd6a, 0xada, 0x95c, 0x949d, 0x149a, 0x1a2a, 0x5b25, 0x1aa4,\n    0xfb52, 0x16b4, 0xaba, 0xa95b, 0x936, 0x1496, 0x9a4b, 0x154a,\n    0x136a5, 0xda4, 0x15ac];\n\n// Table of Chinese New Years from year 1888 to 2111\n// \n// bits (0 to 4):   solar day\n// bits (5 to 8):   solar month\n// bits (9 to 20):  solar year\nvar CHINESE_NEW_YEAR = [1887, 0xec04c, 0xec23f, 0xec435, 0xec649,\n    0xec83e, 0xeca51, 0xecc46, 0xece3a, 0xed04d, 0xed242, 0xed436,\n    0xed64a, 0xed83f, 0xeda53, 0xedc48, 0xede3d, 0xee050, 0xee244,\n    0xee439, 0xee64d, 0xee842, 0xeea36, 0xeec4a, 0xeee3e, 0xef052,\n    0xef246, 0xef43a, 0xef64e, 0xef843, 0xefa37, 0xefc4b, 0xefe41,\n    0xf0054, 0xf0248, 0xf043c, 0xf0650, 0xf0845, 0xf0a38, 0xf0c4d,\n    0xf0e42, 0xf1037, 0xf124a, 0xf143e, 0xf1651, 0xf1846, 0xf1a3a,\n    0xf1c4e, 0xf1e44, 0xf2038, 0xf224b, 0xf243f, 0xf2653, 0xf2848,\n    0xf2a3b, 0xf2c4f, 0xf2e45, 0xf3039, 0xf324d, 0xf3442, 0xf3636,\n    0xf384a, 0xf3a3d, 0xf3c51, 0xf3e46, 0xf403b, 0xf424e, 0xf4443,\n    0xf4638, 0xf484c, 0xf4a3f, 0xf4c52, 0xf4e48, 0xf503c, 0xf524f,\n    0xf5445, 0xf5639, 0xf584d, 0xf5a42, 0xf5c35, 0xf5e49, 0xf603e,\n    0xf6251, 0xf6446, 0xf663b, 0xf684f, 0xf6a43, 0xf6c37, 0xf6e4b,\n    0xf703f, 0xf7252, 0xf7447, 0xf763c, 0xf7850, 0xf7a45, 0xf7c39,\n    0xf7e4d, 0xf8042, 0xf8254, 0xf8449, 0xf863d, 0xf8851, 0xf8a46,\n    0xf8c3b, 0xf8e4f, 0xf9044, 0xf9237, 0xf944a, 0xf963f, 0xf9853,\n    0xf9a47, 0xf9c3c, 0xf9e50, 0xfa045, 0xfa238, 0xfa44c, 0xfa641,\n    0xfa836, 0xfaa49, 0xfac3d, 0xfae52, 0xfb047, 0xfb23a, 0xfb44e,\n    0xfb643, 0xfb837, 0xfba4a, 0xfbc3f, 0xfbe53, 0xfc048, 0xfc23c,\n    0xfc450, 0xfc645, 0xfc839, 0xfca4c, 0xfcc41, 0xfce36, 0xfd04a,\n    0xfd23d, 0xfd451, 0xfd646, 0xfd83a, 0xfda4d, 0xfdc43, 0xfde37,\n    0xfe04b, 0xfe23f, 0xfe453, 0xfe648, 0xfe83c, 0xfea4f, 0xfec44,\n    0xfee38, 0xff04c, 0xff241, 0xff436, 0xff64a, 0xff83e, 0xffa51,\n    0xffc46, 0xffe3a, 0x10004e, 0x100242, 0x100437, 0x10064b, 0x100841,\n    0x100a53, 0x100c48, 0x100e3c, 0x10104f, 0x101244, 0x101438,\n    0x10164c, 0x101842, 0x101a35, 0x101c49, 0x101e3d, 0x102051,\n    0x102245, 0x10243a, 0x10264e, 0x102843, 0x102a37, 0x102c4b,\n    0x102e3f, 0x103053, 0x103247, 0x10343b, 0x10364f, 0x103845,\n    0x103a38, 0x103c4c, 0x103e42, 0x104036, 0x104249, 0x10443d,\n    0x104651, 0x104846, 0x104a3a, 0x104c4e, 0x104e43, 0x105038,\n    0x10524a, 0x10543e, 0x105652, 0x105847, 0x105a3b, 0x105c4f,\n    0x105e45, 0x106039, 0x10624c, 0x106441, 0x106635, 0x106849,\n    0x106a3d, 0x106c51, 0x106e47, 0x10703c, 0x10724f, 0x107444,\n    0x107638, 0x10784c, 0x107a3f, 0x107c53, 0x107e48];\n\nfunction toLunar(yearOrDate, monthOrResult, day, result) {\n    var solarDate;\n    var lunarDate;\n\n    if(typeof yearOrDate === 'object') {\n        solarDate = yearOrDate;\n        lunarDate = monthOrResult || {};\n\n    } else {\n        var isValidYear = (typeof yearOrDate === 'number') &&\n            (yearOrDate >= 1888) && (yearOrDate <= 2111);\n        if(!isValidYear)\n            throw new Error(\"Solar year outside range 1888-2111\");\n\n        var isValidMonth = (typeof monthOrResult === 'number') &&\n            (monthOrResult >= 1) && (monthOrResult <= 12);\n        if(!isValidMonth)\n            throw new Error(\"Solar month outside range 1 - 12\");\n\n        var isValidDay = (typeof day === 'number') && (day >= 1) && (day <= 31);\n        if(!isValidDay)\n            throw new Error(\"Solar day outside range 1 - 31\");\n\n        solarDate = {\n            year: yearOrDate,\n            month: monthOrResult,\n            day: day,\n        };\n        lunarDate = result || {};\n    }\n\n    // Compute Chinese new year and lunar year\n    var chineseNewYearPackedDate =\n        CHINESE_NEW_YEAR[solarDate.year - CHINESE_NEW_YEAR[0]];\n\n    var packedDate = (solarDate.year << 9) | (solarDate.month << 5)\n        | solarDate.day;\n\n    lunarDate.year = (packedDate >= chineseNewYearPackedDate) ?\n        solarDate.year :\n        solarDate.year - 1;\n\n    chineseNewYearPackedDate =\n        CHINESE_NEW_YEAR[lunarDate.year - CHINESE_NEW_YEAR[0]];\n\n    var y = (chineseNewYearPackedDate >> 9) & 0xFFF;\n    var m = (chineseNewYearPackedDate >> 5) & 0x0F;\n    var d = chineseNewYearPackedDate & 0x1F;\n\n    // Compute days from new year\n    var daysFromNewYear;\n\n    var chineseNewYearJSDate = new Date(y, m -1, d);\n    var jsDate = new Date(solarDate.year, solarDate.month - 1, solarDate.day);\n\n    daysFromNewYear = Math.round(\n        (jsDate - chineseNewYearJSDate) / (24 * 3600 * 1000));\n\n    // Compute lunar month and day\n    var monthDaysTable = LUNAR_MONTH_DAYS[lunarDate.year - LUNAR_MONTH_DAYS[0]];\n\n    var i;\n    for(i = 0; i < 13; i++) {\n        var daysInMonth = (monthDaysTable & (1 << (12 - i))) ? 30 : 29;\n\n        if (daysFromNewYear < daysInMonth) {\n            break;\n        }\n\n        daysFromNewYear -= daysInMonth;\n    }\n\n    var intercalaryMonth = monthDaysTable >> 13;\n    if (!intercalaryMonth || i < intercalaryMonth) {\n        lunarDate.isIntercalary = false;\n        lunarDate.month = 1 + i;\n    } else if (i === intercalaryMonth) {\n        lunarDate.isIntercalary = true;\n        lunarDate.month = i;\n    } else {\n        lunarDate.isIntercalary = false;\n        lunarDate.month = i;\n    }\n\n    lunarDate.day = 1 + daysFromNewYear;\n\n    return lunarDate;\n}\n\nfunction toSolar(yearOrDate, monthOrResult, day, isIntercalaryOrResult, result) {\n    var solarDate;\n    var lunarDate;\n\n    if(typeof yearOrDate === 'object') {\n        lunarDate = yearOrDate;\n        solarDate = monthOrResult || {};\n\n    } else {\n        var isValidYear = (typeof yearOrDate === 'number') &&\n            (yearOrDate >= 1888) && (yearOrDate <= 2111);\n        if(!isValidYear)\n            throw new Error(\"Lunar year outside range 1888-2111\");\n\n        var isValidMonth = (typeof monthOrResult === 'number') &&\n            (monthOrResult >= 1) && (monthOrResult <= 12);\n        if(!isValidMonth)\n            throw new Error(\"Lunar month outside range 1 - 12\");\n\n        var isValidDay = (typeof day === 'number') && (day >= 1) && (day <= 30);\n        if(!isValidDay)\n            throw new Error(\"Lunar day outside range 1 - 30\");\n\n        var isIntercalary;\n        if(typeof isIntercalaryOrResult === 'object') {\n            isIntercalary = false;\n            solarDate = isIntercalaryOrResult;\n        } else {\n            isIntercalary = !!isIntercalaryOrResult;\n            solarDate = result || {};\n        }\n\n        lunarDate = {\n            year: yearOrDate,\n            month: monthOrResult,\n            day: day,\n            isIntercalary: isIntercalary,\n        };\n    }\n\n    // Compute days from new year\n    var daysFromNewYear;\n\n    daysFromNewYear = lunarDate.day - 1;\n\n    var monthDaysTable = LUNAR_MONTH_DAYS[lunarDate.year - LUNAR_MONTH_DAYS[0]];\n    var intercalaryMonth = monthDaysTable >> 13;\n\n    var monthsFromNewYear;\n    if (!intercalaryMonth) {\n        monthsFromNewYear = lunarDate.month - 1;\n    } else if (lunarDate.month > intercalaryMonth) {\n        monthsFromNewYear = lunarDate.month;\n    } else if (lunarDate.isIntercalary) {\n        monthsFromNewYear = lunarDate.month;\n    } else {\n        monthsFromNewYear = lunarDate.month - 1;\n    }\n\n    for(var i = 0; i < monthsFromNewYear; i++) {\n        var daysInMonth = (monthDaysTable & (1 << (12 - i))) ? 30 : 29;\n        daysFromNewYear += daysInMonth;\n    }\n\n    // Compute Chinese new year\n    var packedDate = CHINESE_NEW_YEAR[lunarDate.year - CHINESE_NEW_YEAR[0]];\n\n    var y = (packedDate >> 9) & 0xFFF;\n    var m = (packedDate >> 5) & 0x0F;\n    var d = packedDate & 0x1F;\n\n    // Compute solar date\n    var jsDate = new Date(y, m - 1, d + daysFromNewYear);\n\n    solarDate.year = jsDate.getFullYear();\n    solarDate.month = 1 + jsDate.getMonth();\n    solarDate.day = jsDate.getDate();\n\n    return solarDate;\n}\n\n\n},{\"../main\":571,\"object-assign\":454}],558:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Coptic calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) February 2010.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Coptic calendar.\n    See <a href=\"http://en.wikipedia.org/wiki/Coptic_calendar\">http://en.wikipedia.org/wiki/Coptic_calendar</a>.\n    See also Calendrical Calculations: The Millennium Edition\n    (<a href=\"http://emr.cs.iit.edu/home/reingold/calendar-book/index.shtml\">http://emr.cs.iit.edu/home/reingold/calendar-book/index.shtml</a>).\n    @class CopticCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction CopticCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nCopticCalendar.prototype = new main.baseCalendar;\n\nassign(CopticCalendar.prototype, {\n    /** The calendar name.\n        @memberof CopticCalendar */\n    name: 'Coptic',\n    /** Julian date of start of Coptic epoch: 29 August 284 CE (Gregorian).\n        @memberof CopticCalendar */\n    jdEpoch: 1825029.5,\n    /** Days per month in a common year.\n        @memberof CopticCalendar */\n    daysPerMonth: [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 5],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof CopticCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof CopticCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof CopticCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof CopticCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof CopticCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Coptic',\n            epochs: ['BAM', 'AM'],\n            monthNames: ['Thout', 'Paopi', 'Hathor', 'Koiak', 'Tobi', 'Meshir',\n            'Paremhat', 'Paremoude', 'Pashons', 'Paoni', 'Epip', 'Mesori', 'Pi Kogi Enavot'],\n            monthNamesShort: ['Tho', 'Pao', 'Hath', 'Koi', 'Tob', 'Mesh',\n            'Pat', 'Pad', 'Pash', 'Pao', 'Epi', 'Meso', 'PiK'],\n            dayNames: ['Tkyriaka', 'Pesnau', 'Pshoment', 'Peftoou', 'Ptiou', 'Psoou', 'Psabbaton'],\n            dayNamesShort: ['Tky', 'Pes', 'Psh', 'Pef', 'Pti', 'Pso', 'Psa'],\n            dayNamesMin: ['Tk', 'Pes', 'Psh', 'Pef', 'Pt', 'Pso', 'Psa'],\n            digits: null,\n            dateFormat: 'dd/mm/yyyy',\n            firstDay: 0,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof CopticCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        var year = date.year() + (date.year() < 0 ? 1 : 0); // No year zero\n        return year % 4 === 3 || year % 4 === -1;\n    },\n\n    /** Retrieve the number of months in a year.\n        @memberof CopticCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of months.\n        @throws Error if an invalid year or a different calendar used. */\n    monthsInYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay,\n            main.local.invalidYear || main.regionalOptions[''].invalidYear);\n        return 13;\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof CopticCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number) the month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Sunday of this week starting on Sunday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(-checkDate.dayOfWeek(), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof CopticCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 13 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof CopticCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param month {number} The month to examine.\n        @param day {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return (this.dayOfWeek(year, month, day) || 7) < 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof CopticCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number) the month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        year = date.year();\n        if (year < 0) { year++; } // No year zero\n        return date.day() + (date.month() - 1) * 30 +\n            (year - 1) * 365 + Math.floor(year / 4) + this.jdEpoch - 1;\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof CopticCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        var c = Math.floor(jd) + 0.5 - this.jdEpoch;\n        var year = Math.floor((c - Math.floor((c + 366) / 1461)) / 365) + 1;\n        if (year <= 0) { year--; } // No year zero\n        c = Math.floor(jd) + 0.5 - this.newDate(year, 1, 1).toJD();\n        var month = Math.floor(c / 30) + 1;\n        var day = c - (month - 1) * 30 + 1;\n        return this.newDate(year, month, day);\n    }\n});\n\n// Coptic calendar implementation\nmain.calendars.coptic = CopticCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],559:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Discworld calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) January 2016.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Discworld calendar - Unseen University version.\n    See also <a href=\"http://wiki.lspace.org/mediawiki/Discworld_calendar\">http://wiki.lspace.org/mediawiki/Discworld_calendar</a>\n    and <a href=\"http://discworld.wikia.com/wiki/Discworld_calendar\">http://discworld.wikia.com/wiki/Discworld_calendar</a>.\n    @class DiscworldCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction DiscworldCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nDiscworldCalendar.prototype = new main.baseCalendar;\n\nassign(DiscworldCalendar.prototype, {\n    /** The calendar name.\n        @memberof DiscworldCalendar */\n    name: 'Discworld',\n    /** Julian date of start of Discworld epoch: 1 January 0001 CE.\n        @memberof DiscworldCalendar */\n    jdEpoch: 1721425.5,\n    /** Days per month in a common year.\n        @memberof DiscworldCalendar */\n    daysPerMonth: [16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof DiscworldCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof DiscworldCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof DiscworldCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof DiscworldCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof DiscworldCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Discworld',\n            epochs: ['BUC', 'UC'],\n            monthNames: ['Ick', 'Offle', 'February', 'March', 'April', 'May', 'June',\n            'Grune', 'August', 'Spune', 'Sektober', 'Ember', 'December'],\n            monthNamesShort: ['Ick', 'Off', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Gru', 'Aug', 'Spu', 'Sek', 'Emb', 'Dec'],\n            dayNames: ['Sunday', 'Octeday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n            dayNamesShort: ['Sun', 'Oct', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n            dayNamesMin: ['Su', 'Oc', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],\n            digits: null,\n            dateFormat: 'yyyy/mm/dd',\n            firstDay: 2,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return false;\n    },\n\n    /** Retrieve the number of months in a year.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of months.\n        @throws Error if an invalid year or a different calendar used. */\n    monthsInYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return 13;\n    },\n\n    /** Retrieve the number of days in a year.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of days.\n        @throws Error if an invalid year or a different calendar used. */\n    daysInYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return 400;\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Sunday of this week starting on Sunday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(-checkDate.dayOfWeek(), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 8) + 1;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1];\n    },\n\n    /** Retrieve the number of days in a week.\n        @memberof DiscworldCalendar\n        @return {number} The number of days. */\n    daysInWeek: function() {\n        return 8;\n    },\n\n    /** Retrieve the day of the week for a date.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The day of the week: 0 to number of days - 1.\n        @throws Error if an invalid date or a different calendar used. */\n    dayOfWeek: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        return (date.day() + 1) % 8;\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        var dow = this.dayOfWeek(year, month, day);\n        return (dow >= 2 && dow <= 6);\n    },\n\n    /** Retrieve additional information about a date.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {object} Additional information - contents depends on calendar.\n        @throws Error if an invalid date or a different calendar used. */\n    extraInfo: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        return {century: centuries[Math.floor((date.year() - 1) / 100) + 1] || ''};\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof DiscworldCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        year = date.year() + (date.year() < 0 ? 1 : 0);\n        month = date.month();\n        day = date.day();\n        return day + (month > 1 ? 16 : 0) + (month > 2 ? (month - 2) * 32 : 0) +\n            (year - 1) * 400 + this.jdEpoch - 1;\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof DiscworldCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        jd = Math.floor(jd + 0.5) - Math.floor(this.jdEpoch) - 1;\n        var year = Math.floor(jd / 400) + 1;\n        jd -= (year - 1) * 400;\n        jd += (jd > 15 ? 16 : 0);\n        var month = Math.floor(jd / 32) + 1;\n        var day = jd - (month - 1) * 32 + 1;\n        return this.newDate(year <= 0 ? year - 1 : year, month, day);\n    }\n});\n\n// Names of the centuries\nvar centuries = {\n    20: 'Fruitbat',\n    21: 'Anchovy'\n};\n\n// Discworld calendar implementation\nmain.calendars.discworld = DiscworldCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],560:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Ethiopian calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) February 2010.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Ethiopian calendar.\n    See <a href=\"http://en.wikipedia.org/wiki/Ethiopian_calendar\">http://en.wikipedia.org/wiki/Ethiopian_calendar</a>.\n    See also Calendrical Calculations: The Millennium Edition\n    (<a href=\"http://emr.cs.iit.edu/home/reingold/calendar-book/index.shtml\">http://emr.cs.iit.edu/home/reingold/calendar-book/index.shtml</a>).\n    @class EthiopianCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction EthiopianCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nEthiopianCalendar.prototype = new main.baseCalendar;\n\nassign(EthiopianCalendar.prototype, {\n    /** The calendar name.\n        @memberof EthiopianCalendar */\n    name: 'Ethiopian',\n    /** Julian date of start of Ethiopian epoch: 27 August 8 CE (Gregorian).\n        @memberof EthiopianCalendar */\n    jdEpoch: 1724220.5,\n    /** Days per month in a common year.\n        @memberof EthiopianCalendar */\n    daysPerMonth: [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 5],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof EthiopianCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof EthiopianCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof EthiopianCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof EthiopianCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof EthiopianCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Ethiopian',\n            epochs: ['BEE', 'EE'],\n            monthNames: ['Meskerem', 'Tikemet', 'Hidar', 'Tahesas', 'Tir', 'Yekatit',\n            'Megabit', 'Miazia', 'Genbot', 'Sene', 'Hamle', 'Nehase', 'Pagume'],\n            monthNamesShort: ['Mes', 'Tik', 'Hid', 'Tah', 'Tir', 'Yek',\n            'Meg', 'Mia', 'Gen', 'Sen', 'Ham', 'Neh', 'Pag'],\n            dayNames: ['Ehud', 'Segno', 'Maksegno', 'Irob', 'Hamus', 'Arb', 'Kidame'],\n            dayNamesShort: ['Ehu', 'Seg', 'Mak', 'Iro', 'Ham', 'Arb', 'Kid'],\n            dayNamesMin: ['Eh', 'Se', 'Ma', 'Ir', 'Ha', 'Ar', 'Ki'],\n            digits: null,\n            dateFormat: 'dd/mm/yyyy',\n            firstDay: 0,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof EthiopianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        var year = date.year() + (date.year() < 0 ? 1 : 0); // No year zero\n        return year % 4 === 3 || year % 4 === -1;\n    },\n\n    /** Retrieve the number of months in a year.\n        @memberof EthiopianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of months.\n        @throws Error if an invalid year or a different calendar used. */\n    monthsInYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay,\n            main.local.invalidYear || main.regionalOptions[''].invalidYear);\n        return 13;\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof EthiopianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Sunday of this week starting on Sunday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(-checkDate.dayOfWeek(), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof EthiopianCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 13 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof EthiopianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return (this.dayOfWeek(year, month, day) || 7) < 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof EthiopianCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        year = date.year();\n        if (year < 0) { year++; } // No year zero\n        return date.day() + (date.month() - 1) * 30 +\n            (year - 1) * 365 + Math.floor(year / 4) + this.jdEpoch - 1;\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof EthiopianCalendar\n        @param jd {number} the Julian date to convert.\n        @return {CDate} the equivalent date. */\n    fromJD: function(jd) {\n        var c = Math.floor(jd) + 0.5 - this.jdEpoch;\n        var year = Math.floor((c - Math.floor((c + 366) / 1461)) / 365) + 1;\n        if (year <= 0) { year--; } // No year zero\n        c = Math.floor(jd) + 0.5 - this.newDate(year, 1, 1).toJD();\n        var month = Math.floor(c / 30) + 1;\n        var day = c - (month - 1) * 30 + 1;\n        return this.newDate(year, month, day);\n    }\n});\n\n// Ethiopian calendar implementation\nmain.calendars.ethiopian = EthiopianCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],561:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Hebrew calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Hebrew civil calendar.\n    Based on code from <a href=\"http://www.fourmilab.ch/documents/calendar/\">http://www.fourmilab.ch/documents/calendar/</a>.\n    See also <a href=\"http://en.wikipedia.org/wiki/Hebrew_calendar\">http://en.wikipedia.org/wiki/Hebrew_calendar</a>.\n    @class HebrewCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction HebrewCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nHebrewCalendar.prototype = new main.baseCalendar;\n\nassign(HebrewCalendar.prototype, {\n    /** The calendar name.\n        @memberof HebrewCalendar */\n    name: 'Hebrew',\n    /** Julian date of start of Hebrew epoch: 7 October 3761 BCE.\n        @memberof HebrewCalendar */\n    jdEpoch: 347995.5,\n    /** Days per month in a common year.\n        @memberof HebrewCalendar */\n    daysPerMonth: [30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 29],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof HebrewCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof HebrewCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof HebrewCalendar */\n    firstMonth: 7,\n    /** The minimum day number.\n        @memberof HebrewCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof HebrewCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Hebrew',\n            epochs: ['BAM', 'AM'],\n            monthNames: ['Nisan', 'Iyar', 'Sivan', 'Tammuz', 'Av', 'Elul',\n            'Tishrei', 'Cheshvan', 'Kislev', 'Tevet', 'Shevat', 'Adar', 'Adar II'],\n            monthNamesShort: ['Nis', 'Iya', 'Siv', 'Tam', 'Av', 'Elu', 'Tis', 'Che', 'Kis', 'Tev', 'She', 'Ada', 'Ad2'],\n            dayNames: ['Yom Rishon', 'Yom Sheni', 'Yom Shlishi', 'Yom Revi\\'i', 'Yom Chamishi', 'Yom Shishi', 'Yom Shabbat'],\n            dayNamesShort: ['Ris', 'She', 'Shl', 'Rev', 'Cha', 'Shi', 'Sha'],\n            dayNamesMin: ['Ri','She','Shl','Re','Ch','Shi','Sha'],\n            digits: null,\n            dateFormat: 'dd/mm/yyyy',\n            firstDay: 0,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof HebrewCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return this._leapYear(date.year());\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof HebrewCalendar\n        @private\n        @param year {number} The year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    _leapYear: function(year) {\n        year = (year < 0 ? year + 1 : year);\n        return mod(year * 7 + 1, 19) < 7;\n    },\n\n    /** Retrieve the number of months in a year.\n        @memberof HebrewCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of months.\n        @throws Error if an invalid year or a different calendar used. */\n    monthsInYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return this._leapYear(year.year ? year.year() : year) ? 13 : 12;\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof HebrewCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Sunday of this week starting on Sunday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(-checkDate.dayOfWeek(), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a year.\n        @memberof HebrewCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of days.\n        @throws Error if an invalid year or a different calendar used. */\n    daysInYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        year = date.year();\n        return this.toJD((year === -1 ? +1 : year + 1), 7, 1) - this.toJD(year, 7, 1);\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof HebrewCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        if (year.year) {\n            month = year.month();\n            year = year.year();\n        }\n        this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return (month === 12 && this.leapYear(year) ? 30 : // Adar I\n                (month === 8 && mod(this.daysInYear(year), 10) === 5 ? 30 : // Cheshvan in shlemah year\n                (month === 9 && mod(this.daysInYear(year), 10) === 3 ? 29 : // Kislev in chaserah year\n                this.daysPerMonth[month - 1])));\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof HebrewCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return this.dayOfWeek(year, month, day) !== 6;\n    },\n\n    /** Retrieve additional information about a date - year type.\n        @memberof HebrewCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {object} Additional information - contents depends on calendar.\n        @throws Error if an invalid date or a different calendar used. */\n    extraInfo: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        return {yearType: (this.leapYear(date) ? 'embolismic' : 'common') + ' ' +\n            ['deficient', 'regular', 'complete'][this.daysInYear(date) % 10 - 3]};\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof HebrewCalendar\n        @param year {CDate)|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        year = date.year();\n        month = date.month();\n        day = date.day();\n        var adjYear = (year <= 0 ? year + 1 : year);\n        var jd = this.jdEpoch + this._delay1(adjYear) +\n            this._delay2(adjYear) + day + 1;\n        if (month < 7) {\n            for (var m = 7; m <= this.monthsInYear(year); m++) {\n                jd += this.daysInMonth(year, m);\n            }\n            for (var m = 1; m < month; m++) {\n                jd += this.daysInMonth(year, m);\n            }\n        }\n        else {\n            for (var m = 7; m < month; m++) {\n                jd += this.daysInMonth(year, m);\n            }\n        }\n        return jd;\n    },\n\n    /** Test for delay of start of new year and to avoid\n        Sunday, Wednesday, or Friday as start of the new year.\n        @memberof HebrewCalendar\n        @private\n        @param year {number} The year to examine.\n        @return {number} The days to offset by. */\n    _delay1: function(year) {\n        var months = Math.floor((235 * year - 234) / 19);\n        var parts = 12084 + 13753 * months;\n        var day = months * 29 + Math.floor(parts / 25920);\n        if (mod(3 * (day + 1), 7) < 3) {\n            day++;\n        }\n        return day;\n    },\n\n    /** Check for delay in start of new year due to length of adjacent years.\n        @memberof HebrewCalendar\n        @private\n        @param year {number} The year to examine.\n        @return {number} The days to offset by. */\n    _delay2: function(year) {\n        var last = this._delay1(year - 1);\n        var present = this._delay1(year);\n        var next = this._delay1(year + 1);\n        return ((next - present) === 356 ? 2 : ((present - last) === 382 ? 1 : 0));\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof HebrewCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        jd = Math.floor(jd) + 0.5;\n        var year = Math.floor(((jd - this.jdEpoch) * 98496.0) / 35975351.0) - 1;\n        while (jd >= this.toJD((year === -1 ? +1 : year + 1), 7, 1)) {\n            year++;\n        }\n        var month = (jd < this.toJD(year, 1, 1)) ? 7 : 1;\n        while (jd > this.toJD(year, month, this.daysInMonth(year, month))) {\n            month++;\n        }\n        var day = jd - this.toJD(year, month, 1) + 1;\n        return this.newDate(year, month, day);\n    }\n});\n\n// Modulus function which works for non-integers.\nfunction mod(a, b) {\n    return a - (b * Math.floor(a / b));\n}\n\n// Hebrew calendar implementation\nmain.calendars.hebrew = HebrewCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],562:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Islamic calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Islamic or '16 civil' calendar.\n    Based on code from <a href=\"http://www.iranchamber.com/calendar/converter/iranian_calendar_converter.php\">http://www.iranchamber.com/calendar/converter/iranian_calendar_converter.php</a>.\n    See also <a href=\"http://en.wikipedia.org/wiki/Islamic_calendar\">http://en.wikipedia.org/wiki/Islamic_calendar</a>.\n    @class IslamicCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction IslamicCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nIslamicCalendar.prototype = new main.baseCalendar;\n\nassign(IslamicCalendar.prototype, {\n    /** The calendar name.\n        @memberof IslamicCalendar */\n    name: 'Islamic',\n    /** Julian date of start of Islamic epoch: 16 July 622 CE.\n        @memberof IslamicCalendar */\n    jdEpoch: 1948439.5,\n    /** Days per month in a common year.\n        @memberof IslamicCalendar */\n    daysPerMonth: [30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof IslamicCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof IslamicCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof IslamicCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof IslamicCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof IslamicCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Islamic',\n            epochs: ['BH', 'AH'],\n            monthNames: ['Muharram', 'Safar', 'Rabi\\' al-awwal', 'Rabi\\' al-thani', 'Jumada al-awwal', 'Jumada al-thani',\n            'Rajab', 'Sha\\'aban', 'Ramadan', 'Shawwal', 'Dhu al-Qi\\'dah', 'Dhu al-Hijjah'],\n            monthNamesShort: ['Muh', 'Saf', 'Rab1', 'Rab2', 'Jum1', 'Jum2', 'Raj', 'Sha\\'', 'Ram', 'Shaw', 'DhuQ', 'DhuH'],\n            dayNames: ['Yawm al-ahad', 'Yawm al-ithnayn', 'Yawm ath-thulaathaa\\'',\n            'Yawm al-arbi\\'aa\\'', 'Yawm al-khamīs', 'Yawm al-jum\\'a', 'Yawm as-sabt'],\n            dayNamesShort: ['Aha', 'Ith', 'Thu', 'Arb', 'Kha', 'Jum', 'Sab'],\n            dayNamesMin: ['Ah','It','Th','Ar','Kh','Ju','Sa'],\n            digits: null,\n            dateFormat: 'yyyy/mm/dd',\n            firstDay: 6,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof IslamicCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return (date.year() * 11 + 14) % 30 < 11;\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof IslamicCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Sunday of this week starting on Sunday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(-checkDate.dayOfWeek(), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a year.\n        @memberof IslamicCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of days.\n        @throws Error if an invalid year or a different calendar used. */\n    daysInYear: function(year) {\n        return (this.leapYear(year) ? 355 : 354);\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof IslamicCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 12 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof IslamicCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return this.dayOfWeek(year, month, day) !== 5;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof IslamicCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        year = date.year();\n        month = date.month();\n        day = date.day();\n        year = (year <= 0 ? year + 1 : year);\n        return day + Math.ceil(29.5 * (month - 1)) + (year - 1) * 354 +\n            Math.floor((3 + (11 * year)) / 30) + this.jdEpoch - 1;\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof IslamicCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        jd = Math.floor(jd) + 0.5;\n        var year = Math.floor((30 * (jd - this.jdEpoch) + 10646) / 10631);\n        year = (year <= 0 ? year - 1 : year);\n        var month = Math.min(12, Math.ceil((jd - 29 - this.toJD(year, 1, 1)) / 29.5) + 1);\n        var day = jd - this.toJD(year, month, 1) + 1;\n        return this.newDate(year, month, day);\n    }\n});\n\n// Islamic (16 civil) calendar implementation\nmain.calendars.islamic = IslamicCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],563:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Julian calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Julian calendar.\n    Based on code from <a href=\"http://www.fourmilab.ch/documents/calendar/\">http://www.fourmilab.ch/documents/calendar/</a>.\n    See also <a href=\"http://en.wikipedia.org/wiki/Julian_calendar\">http://en.wikipedia.org/wiki/Julian_calendar</a>.\n    @class JulianCalendar\n    @augments BaseCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction JulianCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nJulianCalendar.prototype = new main.baseCalendar;\n\nassign(JulianCalendar.prototype, {\n    /** The calendar name.\n        @memberof JulianCalendar */\n    name: 'Julian',\n    /** Julian date of start of Julian epoch: 1 January 0001 AD = 30 December 0001 BCE.\n        @memberof JulianCalendar */\n    jdEpoch: 1721423.5,\n    /** Days per month in a common year.\n        @memberof JulianCalendar */\n    daysPerMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof JulianCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof JulianCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof JulianCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof JulianCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof JulianCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Julian',\n            epochs: ['BC', 'AD'],\n            monthNames: ['January', 'February', 'March', 'April', 'May', 'June',\n            'July', 'August', 'September', 'October', 'November', 'December'],\n            monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n            dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n            dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n            dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],\n            digits: null,\n            dateFormat: 'mm/dd/yyyy',\n            firstDay: 0,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof JulianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        var year = (date.year() < 0 ? date.year() + 1 : date.year()); // No year zero\n        return (year % 4) === 0;\n    },\n\n    /** Determine the week of the year for a date - ISO 8601.\n        @memberof JulianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Thursday of this week starting on Monday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(4 - (checkDate.dayOfWeek() || 7), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof JulianCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 2 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof JulianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} True if a week day, false if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return (this.dayOfWeek(year, month, day) || 7) < 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof JulianCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        year = date.year();\n        month = date.month();\n        day = date.day();\n        if (year < 0) { year++; } // No year zero\n        // Jean Meeus algorithm, \"Astronomical Algorithms\", 1991\n        if (month <= 2) {\n            year--;\n            month += 12;\n        }\n        return Math.floor(365.25 * (year + 4716)) +\n            Math.floor(30.6001 * (month + 1)) + day - 1524.5;\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof JulianCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        // Jean Meeus algorithm, \"Astronomical Algorithms\", 1991\n        var a = Math.floor(jd + 0.5);\n        var b = a + 1524;\n        var c = Math.floor((b - 122.1) / 365.25);\n        var d = Math.floor(365.25 * c);\n        var e = Math.floor((b - d) / 30.6001);\n        var month = e - Math.floor(e < 14 ? 1 : 13);\n        var year = c - Math.floor(month > 2 ? 4716 : 4715);\n        var day = b - d - Math.floor(30.6001 * e);\n        if (year <= 0) { year--; } // No year zero\n        return this.newDate(year, month, day);\n    }\n});\n\n// Julian calendar implementation\nmain.calendars.julian = JulianCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],564:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Mayan calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Mayan Long Count calendar.\n    See also <a href=\"http://en.wikipedia.org/wiki/Mayan_calendar\">http://en.wikipedia.org/wiki/Mayan_calendar</a>.\n    @class MayanCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction MayanCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nMayanCalendar.prototype = new main.baseCalendar;\n\nassign(MayanCalendar.prototype, {\n    /** The calendar name.\n        @memberof MayanCalendar */\n    name: 'Mayan',\n    /** Julian date of start of Mayan epoch: 11 August 3114 BCE.\n        @memberof MayanCalendar */\n    jdEpoch: 584282.5,\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof MayanCalendar */\n    hasYearZero: true,\n    /** The minimum month number.\n        @memberof MayanCalendar */\n    minMonth: 0,\n    /** The first month in the year.\n        @memberof MayanCalendar */\n    firstMonth: 0,\n    /** The minimum day number.\n        @memberof MayanCalendar */\n    minDay: 0,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof MayanCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left.\n        @property haabMonths {string[]} The names of the Haab months.\n        @property tzolkinMonths {string[]} The names of the Tzolkin months. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Mayan',\n            epochs: ['', ''],\n            monthNames: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n            '10', '11', '12', '13', '14', '15', '16', '17'],\n            monthNamesShort: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n            '10', '11', '12', '13', '14', '15', '16', '17'],\n            dayNames: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n            '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'],\n            dayNamesShort: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n            '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'],\n            dayNamesMin: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n            '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'],\n            digits: null,\n            dateFormat: 'YYYY.m.d',\n            firstDay: 0,\n            isRTL: false,\n            haabMonths: ['Pop', 'Uo', 'Zip', 'Zotz', 'Tzec', 'Xul', 'Yaxkin', 'Mol', 'Chen', 'Yax',\n            'Zac', 'Ceh', 'Mac', 'Kankin', 'Muan', 'Pax', 'Kayab', 'Cumku', 'Uayeb'],\n            tzolkinMonths: ['Imix', 'Ik', 'Akbal', 'Kan', 'Chicchan', 'Cimi', 'Manik', 'Lamat', 'Muluc', 'Oc',\n            'Chuen', 'Eb', 'Ben', 'Ix', 'Men', 'Cib', 'Caban', 'Etznab', 'Cauac', 'Ahau']\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return false;\n    },\n\n    /** Format the year, if not a simple sequential number.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to format or the year to format.\n        @return {string} The formatted year.\n        @throws Error if an invalid year or a different calendar used. */\n    formatYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        year = date.year();\n        var baktun = Math.floor(year / 400);\n        year = year % 400;\n        year += (year < 0 ? 400 : 0);\n        var katun = Math.floor(year / 20);\n        return baktun + '.' + katun + '.' + (year % 20);\n    },\n\n    /** Convert from the formatted year back to a single number.\n        @memberof MayanCalendar\n        @param years {string} The year as n.n.n.\n        @return {number} The sequential year.\n        @throws Error if an invalid value is supplied. */\n    forYear: function(years) {\n        years = years.split('.');\n        if (years.length < 3) {\n            throw 'Invalid Mayan year';\n        }\n        var year = 0;\n        for (var i = 0; i < years.length; i++) {\n            var y = parseInt(years[i], 10);\n            if (Math.abs(y) > 19 || (i > 0 && y < 0)) {\n                throw 'Invalid Mayan year';\n            }\n            year = year * 20 + y;\n        }\n        return year;\n    },\n\n    /** Retrieve the number of months in a year.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of months.\n        @throws Error if an invalid year or a different calendar used. */\n    monthsInYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return 18;\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        this._validate(year, month, day, main.local.invalidDate);\n        return 0;\n    },\n\n    /** Retrieve the number of days in a year.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of days.\n        @throws Error if an invalid year or a different calendar used. */\n    daysInYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return 360;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return 20;\n    },\n\n    /** Retrieve the number of days in a week.\n        @memberof MayanCalendar\n        @return {number} The number of days. */\n    daysInWeek: function() {\n        return 5; // Just for formatting\n    },\n\n    /** Retrieve the day of the week for a date.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The day of the week: 0 to number of days - 1.\n        @throws Error if an invalid date or a different calendar used. */\n    dayOfWeek: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        return date.day();\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        this._validate(year, month, day, main.local.invalidDate);\n        return true;\n    },\n\n    /** Retrieve additional information about a date - Haab and Tzolkin equivalents.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {object} Additional information - contents depends on calendar.\n        @throws Error if an invalid date or a different calendar used. */\n    extraInfo: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        var jd = date.toJD();\n        var haab = this._toHaab(jd);\n        var tzolkin = this._toTzolkin(jd);\n        return {haabMonthName: this.local.haabMonths[haab[0] - 1],\n            haabMonth: haab[0], haabDay: haab[1],\n            tzolkinDayName: this.local.tzolkinMonths[tzolkin[0] - 1],\n            tzolkinDay: tzolkin[0], tzolkinTrecena: tzolkin[1]};\n    },\n\n    /** Retrieve Haab date from a Julian date.\n        @memberof MayanCalendar\n        @private\n        @param jd  {number} The Julian date.\n        @return {number[]} Corresponding Haab month and day. */\n    _toHaab: function(jd) {\n        jd -= this.jdEpoch;\n        var day = mod(jd + 8 + ((18 - 1) * 20), 365);\n        return [Math.floor(day / 20) + 1, mod(day, 20)];\n    },\n\n    /** Retrieve Tzolkin date from a Julian date.\n        @memberof MayanCalendar\n        @private\n        @param jd {number} The Julian date.\n        @return {number[]} Corresponding Tzolkin day and trecena. */\n    _toTzolkin: function(jd) {\n        jd -= this.jdEpoch;\n        return [amod(jd + 20, 20), amod(jd + 4, 13)];\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof MayanCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        return date.day() + (date.month() * 20) + (date.year() * 360) + this.jdEpoch;\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof MayanCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        jd = Math.floor(jd) + 0.5 - this.jdEpoch;\n        var year = Math.floor(jd / 360);\n        jd = jd % 360;\n        jd += (jd < 0 ? 360 : 0);\n        var month = Math.floor(jd / 20);\n        var day = jd % 20;\n        return this.newDate(year, month, day);\n    }\n});\n\n// Modulus function which works for non-integers.\nfunction mod(a, b) {\n    return a - (b * Math.floor(a / b));\n}\n\n// Modulus function which returns numerator if modulus is zero.\nfunction amod(a, b) {\n    return mod(a - 1, b) + 1;\n}\n\n// Mayan calendar implementation\nmain.calendars.mayan = MayanCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],565:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/* http://keith-wood.name/calendars.html\n   Nanakshahi calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) January 2016.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Nanakshahi calendar.\n    See also <a href=\"https://en.wikipedia.org/wiki/Nanakshahi_calendar\">https://en.wikipedia.org/wiki/Nanakshahi_calendar</a>.\n    @class NanakshahiCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction NanakshahiCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nNanakshahiCalendar.prototype = new main.baseCalendar;\n\nvar gregorian = main.instance('gregorian');\n\nassign(NanakshahiCalendar.prototype, {\n    /** The calendar name.\n        @memberof NanakshahiCalendar */\n    name: 'Nanakshahi',\n    /** Julian date of start of Nanakshahi epoch: 14 March 1469 CE.\n        @memberof NanakshahiCalendar */\n    jdEpoch: 2257673.5,\n    /** Days per month in a common year.\n        @memberof NanakshahiCalendar */\n    daysPerMonth: [31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30, 30],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof NanakshahiCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof NanakshahiCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof NanakshahiCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof NanakshahiCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof NanakshahiCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Nanakshahi',\n            epochs: ['BN', 'AN'],\n            monthNames: ['Chet', 'Vaisakh', 'Jeth', 'Harh', 'Sawan', 'Bhadon',\n            'Assu', 'Katak', 'Maghar', 'Poh', 'Magh', 'Phagun'],\n            monthNamesShort: ['Che', 'Vai', 'Jet', 'Har', 'Saw', 'Bha', 'Ass', 'Kat', 'Mgr', 'Poh', 'Mgh', 'Pha'],\n            dayNames: ['Somvaar', 'Mangalvar', 'Budhvaar', 'Veervaar', 'Shukarvaar', 'Sanicharvaar', 'Etvaar'],\n            dayNamesShort: ['Som', 'Mangal', 'Budh', 'Veer', 'Shukar', 'Sanichar', 'Et'],\n            dayNamesMin: ['So', 'Ma', 'Bu', 'Ve', 'Sh', 'Sa', 'Et'],\n            digits: null,\n            dateFormat: 'dd-mm-yyyy',\n            firstDay: 0,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof NanakshahiCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay,\n            main.local.invalidYear || main.regionalOptions[''].invalidYear);\n        return gregorian.leapYear(date.year() + (date.year() < 1 ? 1 : 0) + 1469);\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof NanakshahiCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Monday of this week starting on Monday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(1 - (checkDate.dayOfWeek() || 7), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof NanakshahiCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 12 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof NanakshahiCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return (this.dayOfWeek(year, month, day) || 7) < 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof NanakshahiCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidMonth);\n        var year = date.year();\n        if (year < 0) { year++; } // No year zero\n        var doy = date.day();\n        for (var m = 1; m < date.month(); m++) {\n            doy += this.daysPerMonth[m - 1];\n        }\n        return doy + gregorian.toJD(year + 1468, 3, 13);\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof NanakshahiCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        jd = Math.floor(jd + 0.5);\n        var year = Math.floor((jd - (this.jdEpoch - 1)) / 366);\n        while (jd >= this.toJD(year + 1, 1, 1)) {\n            year++;\n        }\n        var day = jd - Math.floor(this.toJD(year, 1, 1) + 0.5) + 1;\n        var month = 1;\n        while (day > this.daysInMonth(year, month)) {\n            day -= this.daysInMonth(year, month);\n            month++;\n        }\n        return this.newDate(year, month, day);\n    }\n});\n\n// Nanakshahi calendar implementation\nmain.calendars.nanakshahi = NanakshahiCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],566:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Nepali calendar for jQuery v2.0.2.\n   Written by Artur Neumann (ict.projects{at}nepal.inf.org) April 2013.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Nepali civil calendar.\n    Based on the ideas from \n    <a href=\"http://codeissue.com/articles/a04e050dea7468f/algorithm-to-convert-english-date-to-nepali-date-using-c-net\">http://codeissue.com/articles/a04e050dea7468f/algorithm-to-convert-english-date-to-nepali-date-using-c-net</a>\n    and <a href=\"http://birenj2ee.blogspot.com/2011/04/nepali-calendar-in-java.html\">http://birenj2ee.blogspot.com/2011/04/nepali-calendar-in-java.html</a>\n    See also <a href=\"http://en.wikipedia.org/wiki/Nepali_calendar\">http://en.wikipedia.org/wiki/Nepali_calendar</a>\n    and <a href=\"https://en.wikipedia.org/wiki/Bikram_Samwat\">https://en.wikipedia.org/wiki/Bikram_Samwat</a>.\n    @class NepaliCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction NepaliCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nNepaliCalendar.prototype = new main.baseCalendar;\n\nassign(NepaliCalendar.prototype, {\n    /** The calendar name.\n        @memberof NepaliCalendar */\n    name: 'Nepali',\n    /** Julian date of start of Nepali epoch: 14 April 57 BCE.\n        @memberof NepaliCalendar */\n    jdEpoch: 1700709.5,\n    /** Days per month in a common year.\n        @memberof NepaliCalendar */\n    daysPerMonth: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof NepaliCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof NepaliCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof NepaliCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof NepaliCalendar */\n    minDay: 1, \n    /** The number of days in the year.\n        @memberof NepaliCalendar */\n    daysPerYear: 365,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof NepaliCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Nepali',\n            epochs: ['BBS', 'ABS'],\n            monthNames: ['Baisakh', 'Jestha', 'Ashadh', 'Shrawan', 'Bhadra', 'Ashwin',\n            'Kartik', 'Mangsir', 'Paush', 'Mangh', 'Falgun', 'Chaitra'],\n            monthNamesShort: ['Bai', 'Je', 'As', 'Shra', 'Bha', 'Ash', 'Kar', 'Mang', 'Pau', 'Ma', 'Fal', 'Chai'],\n            dayNames: ['Aaitabaar', 'Sombaar', 'Manglbaar', 'Budhabaar', 'Bihibaar', 'Shukrabaar', 'Shanibaar'],\n            dayNamesShort: ['Aaita', 'Som', 'Mangl', 'Budha', 'Bihi', 'Shukra', 'Shani'],\n            dayNamesMin: ['Aai', 'So', 'Man', 'Bu', 'Bi', 'Shu', 'Sha'],\n            digits: null,\n            dateFormat: 'dd/mm/yyyy',\n            firstDay: 1,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof NepaliCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        return this.daysInYear(year) !== this.daysPerYear;\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof NepaliCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Sunday of this week starting on Sunday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(-checkDate.dayOfWeek(), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a year.\n        @memberof NepaliCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of days.\n        @throws Error if an invalid year or a different calendar used. */\n    daysInYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        year = date.year();\n        if (typeof this.NEPALI_CALENDAR_DATA[year] === 'undefined') {\n            return this.daysPerYear;\n        }\n        var daysPerYear = 0;\n        for (var month_number = this.minMonth; month_number <= 12; month_number++) {\n            daysPerYear += this.NEPALI_CALENDAR_DATA[year][month_number];\n        }\n        return daysPerYear;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof NepaliCalendar\n        @param year {CDate|number| The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        if (year.year) {\n            month = year.month();\n            year = year.year();\n        }\n        this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return (typeof this.NEPALI_CALENDAR_DATA[year] === 'undefined' ?\n            this.daysPerMonth[month - 1] : this.NEPALI_CALENDAR_DATA[year][month]);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof NepaliCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return this.dayOfWeek(year, month, day) !== 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof NepaliCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(nepaliYear, nepaliMonth, nepaliDay) {\n        var date = this._validate(nepaliYear, nepaliMonth, nepaliDay, main.local.invalidDate);\n        nepaliYear = date.year();\n        nepaliMonth = date.month();\n        nepaliDay = date.day();\n        var gregorianCalendar = main.instance();\n        var gregorianDayOfYear = 0; // We will add all the days that went by since\n        // the 1st. January and then we can get the Gregorian Date\n        var nepaliMonthToCheck = nepaliMonth;\n        var nepaliYearToCheck = nepaliYear;\n        this._createMissingCalendarData(nepaliYear);\n        // Get the correct year\n        var gregorianYear = nepaliYear - (nepaliMonthToCheck > 9 || (nepaliMonthToCheck === 9 &&\n            nepaliDay >= this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][0]) ? 56 : 57);\n        // First we add the amount of days in the actual Nepali month as the day of year in the\n        // Gregorian one because at least this days are gone since the 1st. Jan. \n        if (nepaliMonth !== 9) {\n            gregorianDayOfYear = nepaliDay;\n            nepaliMonthToCheck--;\n        }\n        // Now we loop throw all Nepali month and add the amount of days to gregorianDayOfYear \n        // we do this till we reach Paush (9th month). 1st. January always falls in this month  \n        while (nepaliMonthToCheck !== 9) {\n            if (nepaliMonthToCheck <= 0) {\n                nepaliMonthToCheck = 12;\n                nepaliYearToCheck--;\n            }                \n            gregorianDayOfYear += this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][nepaliMonthToCheck];\n            nepaliMonthToCheck--;\n        }        \n        // If the date that has to be converted is in Paush (month no. 9) we have to do some other calculation\n        if (nepaliMonth === 9) {\n            // Add the days that are passed since the first day of Paush and substract the\n            // amount of days that lie between 1st. Jan and 1st Paush\n            gregorianDayOfYear += nepaliDay - this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][0];\n            // For the first days of Paush we are now in negative values,\n            // because in the end of the gregorian year we substract\n            // 365 / 366 days (P.S. remember math in school + - gives -)\n            if (gregorianDayOfYear < 0) {\n                gregorianDayOfYear += gregorianCalendar.daysInYear(gregorianYear);\n            }\n        }\n        else {\n            gregorianDayOfYear += this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][9] -\n                this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][0];\n        }        \n        return gregorianCalendar.newDate(gregorianYear, 1 ,1).add(gregorianDayOfYear, 'd').toJD();\n    },\n    \n    /** Create a new date from a Julian date.\n        @memberof NepaliCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        var gregorianCalendar =  main.instance();\n        var gregorianDate = gregorianCalendar.fromJD(jd);\n        var gregorianYear = gregorianDate.year();\n        var gregorianDayOfYear = gregorianDate.dayOfYear();\n        var nepaliYear = gregorianYear + 56; //this is not final, it could be also +57 but +56 is always true for 1st Jan.\n        this._createMissingCalendarData(nepaliYear);\n        var nepaliMonth = 9; // Jan 1 always fall in Nepali month Paush which is the 9th month of Nepali calendar.\n        // Get the Nepali day in Paush (month 9) of 1st January \n        var dayOfFirstJanInPaush = this.NEPALI_CALENDAR_DATA[nepaliYear][0];\n        // Check how many days are left of Paush .\n        // Days calculated from 1st Jan till the end of the actual Nepali month, \n        // we use this value to check if the gregorian Date is in the actual Nepali month.\n        var daysSinceJanFirstToEndOfNepaliMonth =\n            this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth] - dayOfFirstJanInPaush + 1;\n        // If the gregorian day-of-year is smaller o equal than the sum of days between the 1st January and \n        // the end of the actual nepali month we found the correct nepali month.\n        // Example: \n        // The 4th February 2011 is the gregorianDayOfYear 35 (31 days of January + 4)\n        // 1st January 2011 is in the nepali year 2067, where 1st. January is in the 17th day of Paush (9th month)\n        // In 2067 Paush has 30days, This means (30-17+1=14) there are 14days between 1st January and end of Paush \n        // (including 17th January)\n        // The gregorianDayOfYear (35) is bigger than 14, so we check the next month\n        // The next nepali month (Mangh) has 29 days \n        // 29+14=43, this is bigger than gregorianDayOfYear(35) so, we found the correct nepali month\n        while (gregorianDayOfYear > daysSinceJanFirstToEndOfNepaliMonth) {\n            nepaliMonth++;\n            if (nepaliMonth > 12) {\n                nepaliMonth = 1;\n                nepaliYear++;\n            }    \n            daysSinceJanFirstToEndOfNepaliMonth += this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth];\n        }\n        // The last step is to calculate the nepali day-of-month\n        // to continue our example from before:\n        // we calculated there are 43 days from 1st. January (17 Paush) till end of Mangh (29 days)\n        // when we subtract from this 43 days the day-of-year of the the Gregorian date (35),\n        // we know how far the searched day is away from the end of the Nepali month.\n        // So we simply subtract this number from the amount of days in this month (30) \n        var nepaliDayOfMonth = this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth] -\n            (daysSinceJanFirstToEndOfNepaliMonth - gregorianDayOfYear);        \n        return this.newDate(nepaliYear, nepaliMonth, nepaliDayOfMonth);\n    },\n    \n    /** Creates missing data in the NEPALI_CALENDAR_DATA table.\n        This data will not be correct but just give an estimated result. Mostly -/+ 1 day\n        @private\n        @param nepaliYear {number} The missing year number. */\n    _createMissingCalendarData: function(nepaliYear) {\n        var tmp_calendar_data = this.daysPerMonth.slice(0);\n        tmp_calendar_data.unshift(17);\n        for (var nepaliYearToCreate = (nepaliYear - 1); nepaliYearToCreate < (nepaliYear + 2); nepaliYearToCreate++) {\n            if (typeof this.NEPALI_CALENDAR_DATA[nepaliYearToCreate] === 'undefined') {\n                this.NEPALI_CALENDAR_DATA[nepaliYearToCreate] = tmp_calendar_data;\n            }\n        }\n    },\n    \n    NEPALI_CALENDAR_DATA:  {\n        // These data are from http://www.ashesh.com.np\n        1970: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        1971: [18, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],\n        1972: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],\n        1973: [19, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        1974: [19, 31, 31, 32, 30, 31, 31, 30, 29, 30, 29, 30, 30],\n        1975: [18, 31, 31, 32, 32, 30, 31, 30, 29, 30, 29, 30, 30],\n        1976: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        1977: [18, 31, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],\n        1978: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        1979: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        1980: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        1981: [18, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],\n        1982: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        1983: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        1984: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        1985: [18, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],\n        1986: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        1987: [18, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        1988: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        1989: [18, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],\n        1990: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        1991: [18, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],    \n        // These data are from http://nepalicalendar.rat32.com/index.php\n        1992: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        1993: [18, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],\n        1994: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        1995: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],\n        1996: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        1997: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        1998: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        1999: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2000: [17, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2001: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2002: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2003: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2004: [17, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2005: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2006: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2007: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2008: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],\n        2009: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2010: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2011: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2012: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],\n        2013: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2014: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2015: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2016: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],\n        2017: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2018: [18, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2019: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2020: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],\n        2021: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2022: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],\n        2023: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2024: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],\n        2025: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2026: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2027: [17, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2028: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2029: [18, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],\n        2030: [17, 31, 32, 31, 32, 31, 30, 30, 30, 30, 30, 30, 31],\n        2031: [17, 31, 32, 31, 32, 31, 31, 31, 31, 31, 31, 31, 31],\n        2032: [17, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32],\n        2033: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2034: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2035: [17, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],\n        2036: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2037: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2038: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2039: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],\n        2040: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2041: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2042: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2043: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],\n        2044: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2045: [18, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2046: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2047: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],\n        2048: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2049: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],\n        2050: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2051: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],\n        2052: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2053: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],\n        2054: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2055: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 29, 30],\n        2056: [17, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],\n        2057: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2058: [17, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2059: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2060: [17, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2061: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2062: [17, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],\n        2063: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2064: [17, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2065: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2066: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],\n        2067: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2068: [17, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2069: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2070: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],\n        2071: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2072: [17, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2073: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],\n        2074: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],\n        2075: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2076: [16, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],\n        2077: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],\n        2078: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],\n        2079: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],\n        2080: [16, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],\n        // These data are from http://www.ashesh.com.np/nepali-calendar/\n        2081: [17, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],\n        2082: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],\n        2083: [17, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],\n        2084: [17, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],\n        2085: [17, 31, 32, 31, 32, 31, 31, 30, 30, 29, 30, 30, 30],\n        2086: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],\n        2087: [16, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],\n        2088: [16, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],\n        2089: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],\n        2090: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],\n        2091: [16, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],\n        2092: [16, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],\n        2093: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],\n        2094: [17, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],\n        2095: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30],\n        2096: [17, 30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],\n        2097: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],\n        2098: [17, 31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 30, 31],\n        2099: [17, 31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30],\n        2100: [17, 31, 32, 31, 32, 30, 31, 30, 29, 30, 29, 30, 30]    \n    }\n});    \n\n// Nepali calendar implementation\nmain.calendars.nepali = NepaliCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],567:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Persian calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the Persian or Jalali calendar.\n    Based on code from <a href=\"http://www.iranchamber.com/calendar/converter/iranian_calendar_converter.php\">http://www.iranchamber.com/calendar/converter/iranian_calendar_converter.php</a>.\n    See also <a href=\"http://en.wikipedia.org/wiki/Iranian_calendar\">http://en.wikipedia.org/wiki/Iranian_calendar</a>.\n    @class PersianCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction PersianCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nPersianCalendar.prototype = new main.baseCalendar;\n\nassign(PersianCalendar.prototype, {\n    /** The calendar name.\n        @memberof PersianCalendar */\n    name: 'Persian',\n    /** Julian date of start of Persian epoch: 19 March 622 CE.\n        @memberof PersianCalendar */\n    jdEpoch: 1948320.5,\n    /** Days per month in a common year.\n        @memberof PersianCalendar */\n    daysPerMonth: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof PersianCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof PersianCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof PersianCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof PersianCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof PersianCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Persian',\n            epochs: ['BP', 'AP'],\n            monthNames: ['Farvardin', 'Ordibehesht', 'Khordad', 'Tir', 'Mordad', 'Shahrivar',\n            'Mehr', 'Aban', 'Azar', 'Day', 'Bahman', 'Esfand'],\n            monthNamesShort: ['Far', 'Ord', 'Kho', 'Tir', 'Mor', 'Sha', 'Meh', 'Aba', 'Aza', 'Day', 'Bah', 'Esf'],\n            dayNames: ['Yekshambe', 'Doshambe', 'Seshambe', 'Chæharshambe', 'Panjshambe', 'Jom\\'e', 'Shambe'],\n            dayNamesShort: ['Yek', 'Do', 'Se', 'Chæ', 'Panj', 'Jom', 'Sha'],\n            dayNamesMin: ['Ye','Do','Se','Ch','Pa','Jo','Sh'],\n            digits: null,\n            dateFormat: 'yyyy/mm/dd',\n            firstDay: 6,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof PersianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return (((((date.year() - (date.year() > 0 ? 474 : 473)) % 2820) +\n            474 + 38) * 682) % 2816) < 682;\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof PersianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Saturday of this week starting on Saturday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(-((checkDate.dayOfWeek() + 1) % 7), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof PersianCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 12 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof PersianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return this.dayOfWeek(year, month, day) !== 5;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof PersianCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        year = date.year();\n        month = date.month();\n        day = date.day();\n        var epBase = year - (year >= 0 ? 474 : 473);\n        var epYear = 474 + mod(epBase, 2820);\n        return day + (month <= 7 ? (month - 1) * 31 : (month - 1) * 30 + 6) +\n            Math.floor((epYear * 682 - 110) / 2816) + (epYear - 1) * 365 +\n            Math.floor(epBase / 2820) * 1029983 + this.jdEpoch - 1;\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof PersianCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        jd = Math.floor(jd) + 0.5;\n        var depoch = jd - this.toJD(475, 1, 1);\n        var cycle = Math.floor(depoch / 1029983);\n        var cyear = mod(depoch, 1029983);\n        var ycycle = 2820;\n        if (cyear !== 1029982) {\n            var aux1 = Math.floor(cyear / 366);\n            var aux2 = mod(cyear, 366);\n            ycycle = Math.floor(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) + aux1 + 1;\n        }\n        var year = ycycle + (2820 * cycle) + 474;\n        year = (year <= 0 ? year - 1 : year);\n        var yday = jd - this.toJD(year, 1, 1) + 1;\n        var month = (yday <= 186 ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30));\n        var day = jd - this.toJD(year, month, 1) + 1;\n        return this.newDate(year, month, day);\n    }\n});\n\n// Modulus function which works for non-integers.\nfunction mod(a, b) {\n    return a - (b * Math.floor(a / b));\n}\n\n// Persian (Jalali) calendar implementation\nmain.calendars.persian = PersianCalendar;\nmain.calendars.jalali = PersianCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],568:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Taiwanese (Minguo) calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) February 2010.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\nvar gregorianCalendar = main.instance();\n\n/** Implementation of the Taiwanese calendar.\n    See http://en.wikipedia.org/wiki/Minguo_calendar.\n    @class TaiwanCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction TaiwanCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nTaiwanCalendar.prototype = new main.baseCalendar;\n\nassign(TaiwanCalendar.prototype, {\n    /** The calendar name.\n        @memberof TaiwanCalendar */\n    name: 'Taiwan',\n    /** Julian date of start of Taiwan epoch: 1 January 1912 CE (Gregorian).\n        @memberof TaiwanCalendar */\n    jdEpoch: 2419402.5,\n    /** Difference in years between Taiwan and Gregorian calendars.\n        @memberof TaiwanCalendar */\n    yearsOffset: 1911,\n    /** Days per month in a common year.\n        @memberof TaiwanCalendar */\n    daysPerMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof TaiwanCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof TaiwanCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof TaiwanCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof TaiwanCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof TaiwanCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Taiwan',\n            epochs: ['BROC', 'ROC'],\n            monthNames: ['January', 'February', 'March', 'April', 'May', 'June',\n            'July', 'August', 'September', 'October', 'November', 'December'],\n            monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n            dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n            dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n            dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],\n            digits: null,\n            dateFormat: 'yyyy/mm/dd',\n            firstDay: 1,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof TaiwanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        var year = this._t2gYear(date.year());\n        return gregorianCalendar.leapYear(year);\n    },\n\n    /** Determine the week of the year for a date - ISO 8601.\n        @memberof TaiwanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        var year = this._t2gYear(date.year());\n        return gregorianCalendar.weekOfYear(year, date.month(), date.day());\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof TaiwanCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 2 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof TaiwanCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return (this.dayOfWeek(year, month, day) || 7) < 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof TaiwanCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        var year = this._t2gYear(date.year());\n        return gregorianCalendar.toJD(year, date.month(), date.day());\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof TaiwanCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        var date = gregorianCalendar.fromJD(jd);\n        var year = this._g2tYear(date.year());\n        return this.newDate(year, date.month(), date.day());\n    },\n\n    /** Convert Taiwanese to Gregorian year.\n        @memberof TaiwanCalendar\n        @private\n        @param year {number} The Taiwanese year.\n        @return {number} The corresponding Gregorian year. */\n    _t2gYear: function(year) {\n        return year + this.yearsOffset + (year >= -this.yearsOffset && year <= -1 ? 1 : 0);\n    },\n\n    /** Convert Gregorian to Taiwanese year.\n        @memberof TaiwanCalendar\n        @private\n        @param year {number} The Gregorian year.\n        @return {number} The corresponding Taiwanese year. */\n    _g2tYear: function(year) {\n        return year - this.yearsOffset - (year >= 1 && year <= this.yearsOffset ? 1 : 0);\n    }\n});\n\n// Taiwan calendar implementation\nmain.calendars.taiwan = TaiwanCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],569:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Thai calendar for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) February 2010.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\nvar gregorianCalendar = main.instance();\n\n/** Implementation of the Thai calendar.\n    See http://en.wikipedia.org/wiki/Thai_calendar.\n    @class ThaiCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction ThaiCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nThaiCalendar.prototype = new main.baseCalendar;\n\nassign(ThaiCalendar.prototype, {\n    /** The calendar name.\n        @memberof ThaiCalendar */\n    name: 'Thai',\n    /** Julian date of start of Thai epoch: 1 January 543 BCE (Gregorian).\n        @memberof ThaiCalendar */\n    jdEpoch: 1523098.5,\n    /** Difference in years between Thai and Gregorian calendars.\n        @memberof ThaiCalendar */\n    yearsOffset: 543, \n    /** Days per month in a common year.\n        @memberof ThaiCalendar */\n    daysPerMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof ThaiCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof ThaiCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof ThaiCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof ThaiCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof ThaiCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Thai',\n            epochs: ['BBE', 'BE'],\n            monthNames: ['January', 'February', 'March', 'April', 'May', 'June',\n            'July', 'August', 'September', 'October', 'November', 'December'],\n            monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n            dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n            dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n            dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],\n            digits: null,\n            dateFormat: 'dd/mm/yyyy',\n            firstDay: 0,\n            isRTL: false\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof ThaiCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        var year = this._t2gYear(date.year());\n        return gregorianCalendar.leapYear(year);\n    },\n\n    /** Determine the week of the year for a date - ISO 8601.\n        @memberof ThaiCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        var year = this._t2gYear(date.year());\n        return gregorianCalendar.weekOfYear(year, date.month(), date.day());\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof ThaiCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 2 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof ThaiCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return (this.dayOfWeek(year, month, day) || 7) < 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof ThaiCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        var year = this._t2gYear(date.year());\n        return gregorianCalendar.toJD(year, date.month(), date.day());\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof ThaiCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        var date = gregorianCalendar.fromJD(jd);\n        var year = this._g2tYear(date.year());\n        return this.newDate(year, date.month(), date.day());\n    },\n\n    /** Convert Thai to Gregorian year.\n        @memberof ThaiCalendar\n        @private\n        @param year {number} The Thai year.\n        @return {number} The corresponding Gregorian year. */\n    _t2gYear: function(year) {\n        return year - this.yearsOffset - (year >= 1 && year <= this.yearsOffset ? 1 : 0);\n    },\n\n    /** Convert Gregorian to Thai year.\n        @memberof ThaiCalendar\n        @private\n        @param year {number} The Gregorian year.\n        @return {number} The corresponding Thai year. */\n    _g2tYear: function(year) {\n        return year + this.yearsOffset + (year >= -this.yearsOffset && year <= -1 ? 1 : 0);\n    }\n});\n\n// Thai calendar implementation\nmain.calendars.thai = ThaiCalendar;\n\n\n},{\"../main\":571,\"object-assign\":454}],570:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   UmmAlQura calendar for jQuery v2.0.2.\n   Written by Amro Osama March 2013.\n   Modified by Binnooh.com & www.elm.sa - 2014 - Added dates back to 1276 Hijri year.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar main = _dereq_('../main');\nvar assign = _dereq_('object-assign');\n\n\n/** Implementation of the UmmAlQura or 'saudi' calendar.\n    See also <a href=\"http://en.wikipedia.org/wiki/Islamic_calendar#Saudi_Arabia.27s_Umm_al-Qura_calendar\">http://en.wikipedia.org/wiki/Islamic_calendar#Saudi_Arabia.27s_Umm_al-Qura_calendar</a>.\n    <a href=\"http://www.ummulqura.org.sa/About.aspx\">http://www.ummulqura.org.sa/About.aspx</a>\n    <a href=\"http://www.staff.science.uu.nl/~gent0113/islam/ummalqura.htm\">http://www.staff.science.uu.nl/~gent0113/islam/ummalqura.htm</a>\n    @class UmmAlQuraCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction UmmAlQuraCalendar(language) {\n    this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];\n}\n\nUmmAlQuraCalendar.prototype = new main.baseCalendar;\n\nassign(UmmAlQuraCalendar.prototype, {\n    /** The calendar name.\n        @memberof UmmAlQuraCalendar */\n    name: 'UmmAlQura',\n    //jdEpoch: 1948440, // Julian date of start of UmmAlQura epoch: 14 March 1937 CE\n    //daysPerMonth: // Days per month in a common year, replaced by a method.\n    /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof UmmAlQuraCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof UmmAlQuraCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof UmmAlQuraCalendar */\n    firstMonth: 1,\n    /** The minimum day number.\n        @memberof UmmAlQuraCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof UmmAlQuraCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Umm al-Qura',\n            epochs: ['BH', 'AH'],\n            monthNames: ['Al-Muharram', 'Safar', 'Rabi\\' al-awwal', 'Rabi\\' Al-Thani', 'Jumada Al-Awwal', 'Jumada Al-Thani',\n            'Rajab', 'Sha\\'aban', 'Ramadan', 'Shawwal', 'Dhu al-Qi\\'dah', 'Dhu al-Hijjah'],\n            monthNamesShort: ['Muh', 'Saf', 'Rab1', 'Rab2', 'Jum1', 'Jum2', 'Raj', 'Sha\\'', 'Ram', 'Shaw', 'DhuQ', 'DhuH'],\n            dayNames: ['Yawm al-Ahad', 'Yawm al-Ithnain', 'Yawm al-Thalāthā’', 'Yawm al-Arba‘ā’', 'Yawm al-Khamīs', 'Yawm al-Jum‘a', 'Yawm al-Sabt'],\n            dayNamesMin: ['Ah', 'Ith', 'Th', 'Ar', 'Kh', 'Ju', 'Sa'],\n            digits: null,\n            dateFormat: 'yyyy/mm/dd',\n            firstDay: 6,\n            isRTL: true\n        }\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof UmmAlQuraCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function (year) {\n        var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);\n        return (this.daysInYear(date.year()) === 355);\n    },\n\n    /** Determine the week of the year for a date.\n        @memberof UmmAlQuraCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function (year, month, day) {\n        // Find Sunday of this week starting on Sunday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(-checkDate.dayOfWeek(), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a year.\n        @memberof UmmAlQuraCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of days.\n        @throws Error if an invalid year or a different calendar used. */\n    daysInYear: function (year) {\n        var daysCount = 0;\n        for (var i = 1; i <= 12; i++) {\n            daysCount += this.daysInMonth(year, i);\n        }\n        return daysCount;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof UmmAlQuraCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function (year, month) {\n        var date = this._validate(year, month, this.minDay, main.local.invalidMonth);\n        var mcjdn = date.toJD() - 2400000 + 0.5; // Modified Chronological Julian Day Number (MCJDN)\n        // the MCJDN's of the start of the lunations in the Umm al-Qura calendar are stored in the 'ummalqura_dat' array\n        var index = 0;\n        for (var i = 0; i < ummalqura_dat.length; i++) {\n            if (ummalqura_dat[i] > mcjdn) {\n                return (ummalqura_dat[index] - ummalqura_dat[index - 1]);\n            }\n            index++;\n        }\n        return 30; // Unknown outside\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof UmmAlQuraCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function (year, month, day) {\n        return this.dayOfWeek(year, month, day) !== 5;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof UmmAlQuraCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function (year, month, day) {\n        var date = this._validate(year, month, day, main.local.invalidDate);\n        var index = (12 * (date.year() - 1)) + date.month() - 15292;\n        var mcjdn = date.day() + ummalqura_dat[index - 1] - 1;\n        return mcjdn + 2400000 - 0.5; // Modified Chronological Julian Day Number (MCJDN)\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof UmmAlQuraCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function (jd) {\n        var mcjdn = jd - 2400000 + 0.5; // Modified Chronological Julian Day Number (MCJDN)\n        // the MCJDN's of the start of the lunations in the Umm al-Qura calendar \n        // are stored in the 'ummalqura_dat' array\n        var index = 0;\n        for (var i = 0; i < ummalqura_dat.length; i++) {\n            if (ummalqura_dat[i] > mcjdn) break;\n            index++;\n        }\n        var lunation = index + 15292; //UmmAlQura Lunation Number\n        var ii = Math.floor((lunation - 1) / 12);\n        var year = ii + 1;\n        var month = lunation - 12 * ii;\n        var day = mcjdn - ummalqura_dat[index - 1] + 1;\n        return this.newDate(year, month, day);\n    },\n\n    /** Determine whether a date is valid for this calendar.\n        @memberof UmmAlQuraCalendar\n        @param year {number} The year to examine.\n        @param month {number} The month to examine.\n        @param day {number} The day to examine.\n        @return {boolean} <code>true</code> if a valid date, <code>false</code> if not. */\n    isValid: function(year, month, day) {\n        var valid = main.baseCalendar.prototype.isValid.apply(this, arguments);\n        if (valid) {\n            year = (year.year != null ? year.year : year);\n            valid = (year >= 1276 && year <= 1500);\n        }\n        return valid;\n    },\n\n    /** Check that a candidate date is from the same calendar and is valid.\n        @memberof UmmAlQuraCalendar\n        @private\n        @param year {CDate|number} The date to validate or the year to validate.\n        @param month {number} The month to validate.\n        @param day {number} The day to validate.\n        @param error {string} Error message if invalid.\n        @throws Error if different calendars used or invalid date. */\n    _validate: function(year, month, day, error) {\n        var date = main.baseCalendar.prototype._validate.apply(this, arguments);\n        if (date.year < 1276 || date.year > 1500) {\n            throw error.replace(/\\{0\\}/, this.local.name);\n        }\n        return date;\n    }\n});\n\n// UmmAlQura calendar implementation\nmain.calendars.ummalqura = UmmAlQuraCalendar;\n\nvar ummalqura_dat = [\n    20,    50,    79,    109,   138,   168,   197,   227,   256,   286,   315,   345,   374,   404,   433,   463,   492,   522,   551,   581, \n    611,   641,   670,   700,   729,   759,   788,   818,   847,   877,   906,   936,   965,   995,   1024,  1054,  1083,  1113,  1142,  1172,\n    1201,  1231,  1260,  1290,  1320,  1350,  1379,  1409,  1438,  1468,  1497,  1527,  1556,  1586,  1615,  1645,  1674,  1704,  1733,  1763,\n    1792,  1822,  1851,  1881,  1910,  1940,  1969,  1999,  2028,  2058,  2087,  2117,  2146,  2176,  2205,  2235,  2264,  2294,  2323,  2353,\n    2383,  2413,  2442,  2472,  2501,  2531,  2560,  2590,  2619,  2649,  2678,  2708,  2737,  2767,  2796,  2826,  2855,  2885,  2914,  2944,\n    2973,  3003,  3032,  3062,  3091,  3121,  3150,  3180,  3209,  3239,  3268,  3298,  3327,  3357,  3386,  3416,  3446,  3476,  3505,  3535,\n    3564,  3594,  3623,  3653,  3682,  3712,  3741,  3771,  3800,  3830,  3859,  3889,  3918,  3948,  3977,  4007,  4036,  4066,  4095,  4125,\n    4155,  4185,  4214,  4244,  4273,  4303,  4332,  4362,  4391,  4421,  4450,  4480,  4509,  4539,  4568,  4598,  4627,  4657,  4686,  4716,\n    4745,  4775,  4804,  4834,  4863,  4893,  4922,  4952,  4981,  5011,  5040,  5070,  5099,  5129,  5158,  5188,  5218,  5248,  5277,  5307,\n    5336,  5366,  5395,  5425,  5454,  5484,  5513,  5543,  5572,  5602,  5631,  5661,  5690,  5720,  5749,  5779,  5808,  5838,  5867,  5897,\n    5926,  5956,  5985,  6015,  6044,  6074,  6103,  6133,  6162,  6192,  6221,  6251,  6281,  6311,  6340,  6370,  6399,  6429,  6458,  6488,\n    6517,  6547,  6576,  6606,  6635,  6665,  6694,  6724,  6753,  6783,  6812,  6842,  6871,  6901,  6930,  6960,  6989,  7019,  7048,  7078,\n    7107,  7137,  7166,  7196,  7225,  7255,  7284,  7314,  7344,  7374,  7403,  7433,  7462,  7492,  7521,  7551,  7580,  7610,  7639,  7669,\n    7698,  7728,  7757,  7787,  7816,  7846,  7875,  7905,  7934,  7964,  7993,  8023,  8053,  8083,  8112,  8142,  8171,  8201,  8230,  8260,\n    8289,  8319,  8348,  8378,  8407,  8437,  8466,  8496,  8525,  8555,  8584,  8614,  8643,  8673,  8702,  8732,  8761,  8791,  8821,  8850,\n    8880,  8909,  8938,  8968,  8997,  9027,  9056,  9086,  9115,  9145,  9175,  9205,  9234,  9264,  9293,  9322,  9352,  9381,  9410,  9440,\n    9470,  9499,  9529,  9559,  9589,  9618,  9648,  9677,  9706,  9736,  9765,  9794,  9824,  9853,  9883,  9913,  9943,  9972,  10002, 10032,\n    10061, 10090, 10120, 10149, 10178, 10208, 10237, 10267, 10297, 10326, 10356, 10386, 10415, 10445, 10474, 10504, 10533, 10562, 10592, 10621,\n    10651, 10680, 10710, 10740, 10770, 10799, 10829, 10858, 10888, 10917, 10947, 10976, 11005, 11035, 11064, 11094, 11124, 11153, 11183, 11213,\n    11242, 11272, 11301, 11331, 11360, 11389, 11419, 11448, 11478, 11507, 11537, 11567, 11596, 11626, 11655, 11685, 11715, 11744, 11774, 11803,\n    11832, 11862, 11891, 11921, 11950, 11980, 12010, 12039, 12069, 12099, 12128, 12158, 12187, 12216, 12246, 12275, 12304, 12334, 12364, 12393,\n    12423, 12453, 12483, 12512, 12542, 12571, 12600, 12630, 12659, 12688, 12718, 12747, 12777, 12807, 12837, 12866, 12896, 12926, 12955, 12984,\n    13014, 13043, 13072, 13102, 13131, 13161, 13191, 13220, 13250, 13280, 13310, 13339, 13368, 13398, 13427, 13456, 13486, 13515, 13545, 13574,\n    13604, 13634, 13664, 13693, 13723, 13752, 13782, 13811, 13840, 13870, 13899, 13929, 13958, 13988, 14018, 14047, 14077, 14107, 14136, 14166,\n    14195, 14224, 14254, 14283, 14313, 14342, 14372, 14401, 14431, 14461, 14490, 14520, 14550, 14579, 14609, 14638, 14667, 14697, 14726, 14756,\n    14785, 14815, 14844, 14874, 14904, 14933, 14963, 14993, 15021, 15051, 15081, 15110, 15140, 15169, 15199, 15228, 15258, 15287, 15317, 15347,\n    15377, 15406, 15436, 15465, 15494, 15524, 15553, 15582, 15612, 15641, 15671, 15701, 15731, 15760, 15790, 15820, 15849, 15878, 15908, 15937,\n    15966, 15996, 16025, 16055, 16085, 16114, 16144, 16174, 16204, 16233, 16262, 16292, 16321, 16350, 16380, 16409, 16439, 16468, 16498, 16528,\n    16558, 16587, 16617, 16646, 16676, 16705, 16734, 16764, 16793, 16823, 16852, 16882, 16912, 16941, 16971, 17001, 17030, 17060, 17089, 17118,\n    17148, 17177, 17207, 17236, 17266, 17295, 17325, 17355, 17384, 17414, 17444, 17473, 17502, 17532, 17561, 17591, 17620, 17650, 17679, 17709,\n    17738, 17768, 17798, 17827, 17857, 17886, 17916, 17945, 17975, 18004, 18034, 18063, 18093, 18122, 18152, 18181, 18211, 18241, 18270, 18300,\n    18330, 18359, 18388, 18418, 18447, 18476, 18506, 18535, 18565, 18595, 18625, 18654, 18684, 18714, 18743, 18772, 18802, 18831, 18860, 18890,\n    18919, 18949, 18979, 19008, 19038, 19068, 19098, 19127, 19156, 19186, 19215, 19244, 19274, 19303, 19333, 19362, 19392, 19422, 19452, 19481,\n    19511, 19540, 19570, 19599, 19628, 19658, 19687, 19717, 19746, 19776, 19806, 19836, 19865, 19895, 19924, 19954, 19983, 20012, 20042, 20071,\n    20101, 20130, 20160, 20190, 20219, 20249, 20279, 20308, 20338, 20367, 20396, 20426, 20455, 20485, 20514, 20544, 20573, 20603, 20633, 20662,\n    20692, 20721, 20751, 20780, 20810, 20839, 20869, 20898, 20928, 20957, 20987, 21016, 21046, 21076, 21105, 21135, 21164, 21194, 21223, 21253,\n    21282, 21312, 21341, 21371, 21400, 21430, 21459, 21489, 21519, 21548, 21578, 21607, 21637, 21666, 21696, 21725, 21754, 21784, 21813, 21843,\n    21873, 21902, 21932, 21962, 21991, 22021, 22050, 22080, 22109, 22138, 22168, 22197, 22227, 22256, 22286, 22316, 22346, 22375, 22405, 22434,\n    22464, 22493, 22522, 22552, 22581, 22611, 22640, 22670, 22700, 22730, 22759, 22789, 22818, 22848, 22877, 22906, 22936, 22965, 22994, 23024,\n    23054, 23083, 23113, 23143, 23173, 23202, 23232, 23261, 23290, 23320, 23349, 23379, 23408, 23438, 23467, 23497, 23527, 23556, 23586, 23616,\n    23645, 23674, 23704, 23733, 23763, 23792, 23822, 23851, 23881, 23910, 23940, 23970, 23999, 24029, 24058, 24088, 24117, 24147, 24176, 24206,\n    24235, 24265, 24294, 24324, 24353, 24383, 24413, 24442, 24472, 24501, 24531, 24560, 24590, 24619, 24648, 24678, 24707, 24737, 24767, 24796,\n    24826, 24856, 24885, 24915, 24944, 24974, 25003, 25032, 25062, 25091, 25121, 25150, 25180, 25210, 25240, 25269, 25299, 25328, 25358, 25387,\n    25416, 25446, 25475, 25505, 25534, 25564, 25594, 25624, 25653, 25683, 25712, 25742, 25771, 25800, 25830, 25859, 25888, 25918, 25948, 25977,\n    26007, 26037, 26067, 26096, 26126, 26155, 26184, 26214, 26243, 26272, 26302, 26332, 26361, 26391, 26421, 26451, 26480, 26510, 26539, 26568,\n    26598, 26627, 26656, 26686, 26715, 26745, 26775, 26805, 26834, 26864, 26893, 26923, 26952, 26982, 27011, 27041, 27070, 27099, 27129, 27159,\n    27188, 27218, 27248, 27277, 27307, 27336, 27366, 27395, 27425, 27454, 27484, 27513, 27542, 27572, 27602, 27631, 27661, 27691, 27720, 27750,\n    27779, 27809, 27838, 27868, 27897, 27926, 27956, 27985, 28015, 28045, 28074, 28104, 28134, 28163, 28193, 28222, 28252, 28281, 28310, 28340,\n    28369, 28399, 28428, 28458, 28488, 28517, 28547, 28577,\n    // From 1356\n    28607, 28636, 28665, 28695, 28724, 28754, 28783, 28813, 28843, 28872, 28901, 28931, 28960, 28990, 29019, 29049, 29078, 29108, 29137, 29167,\n    29196, 29226, 29255, 29285, 29315, 29345, 29375, 29404, 29434, 29463, 29492, 29522, 29551, 29580, 29610, 29640, 29669, 29699, 29729, 29759,\n    29788, 29818, 29847, 29876, 29906, 29935, 29964, 29994, 30023, 30053, 30082, 30112, 30141, 30171, 30200, 30230, 30259, 30289, 30318, 30348,\n    30378, 30408, 30437, 30467, 30496, 30526, 30555, 30585, 30614, 30644, 30673, 30703, 30732, 30762, 30791, 30821, 30850, 30880, 30909, 30939,\n    30968, 30998, 31027, 31057, 31086, 31116, 31145, 31175, 31204, 31234, 31263, 31293, 31322, 31352, 31381, 31411, 31441, 31471, 31500, 31530,\n    31559, 31589, 31618, 31648, 31676, 31706, 31736, 31766, 31795, 31825, 31854, 31884, 31913, 31943, 31972, 32002, 32031, 32061, 32090, 32120,\n    32150, 32180, 32209, 32239, 32268, 32298, 32327, 32357, 32386, 32416, 32445, 32475, 32504, 32534, 32563, 32593, 32622, 32652, 32681, 32711,\n    32740, 32770, 32799, 32829, 32858, 32888, 32917, 32947, 32976, 33006, 33035, 33065, 33094, 33124, 33153, 33183, 33213, 33243, 33272, 33302,\n    33331, 33361, 33390, 33420, 33450, 33479, 33509, 33539, 33568, 33598, 33627, 33657, 33686, 33716, 33745, 33775, 33804, 33834, 33863, 33893,\n    33922, 33952, 33981, 34011, 34040, 34069, 34099, 34128, 34158, 34187, 34217, 34247, 34277, 34306, 34336, 34365, 34395, 34424, 34454, 34483,\n    34512, 34542, 34571, 34601, 34631, 34660, 34690, 34719, 34749, 34778, 34808, 34837, 34867, 34896, 34926, 34955, 34985, 35015, 35044, 35074,\n    35103, 35133, 35162, 35192, 35222, 35251, 35280, 35310, 35340, 35370, 35399, 35429, 35458, 35488, 35517, 35547, 35576, 35605, 35635, 35665,\n    35694, 35723, 35753, 35782, 35811, 35841, 35871, 35901, 35930, 35960, 35989, 36019, 36048, 36078, 36107, 36136, 36166, 36195, 36225, 36254,\n    36284, 36314, 36343, 36373, 36403, 36433, 36462, 36492, 36521, 36551, 36580, 36610, 36639, 36669, 36698, 36728, 36757, 36786, 36816, 36845,\n    36875, 36904, 36934, 36963, 36993, 37022, 37052, 37081, 37111, 37141, 37170, 37200, 37229, 37259, 37288, 37318, 37347, 37377, 37406, 37436,\n    37465, 37495, 37524, 37554, 37584, 37613, 37643, 37672, 37701, 37731, 37760, 37790, 37819, 37849, 37878, 37908, 37938, 37967, 37997, 38027,\n    38056, 38085, 38115, 38144, 38174, 38203, 38233, 38262, 38292, 38322, 38351, 38381, 38410, 38440, 38469, 38499, 38528, 38558, 38587, 38617,\n    38646, 38676, 38705, 38735, 38764, 38794, 38823, 38853, 38882, 38912, 38941, 38971, 39001, 39030, 39059, 39089, 39118, 39148, 39178, 39208,\n    39237, 39267, 39297, 39326, 39355, 39385, 39414, 39444, 39473, 39503, 39532, 39562, 39592, 39621, 39650, 39680, 39709, 39739, 39768, 39798,\n    39827, 39857, 39886, 39916, 39946, 39975, 40005, 40035, 40064, 40094, 40123, 40153, 40182, 40212, 40241, 40271, 40300, 40330, 40359, 40389,\n    40418, 40448, 40477, 40507, 40536, 40566, 40595, 40625, 40655, 40685, 40714, 40744, 40773, 40803, 40832, 40862, 40892, 40921, 40951, 40980,\n    41009, 41039, 41068, 41098, 41127, 41157, 41186, 41216, 41245, 41275, 41304, 41334, 41364, 41393, 41422, 41452, 41481, 41511, 41540, 41570,\n    41599, 41629, 41658, 41688, 41718, 41748, 41777, 41807, 41836, 41865, 41894, 41924, 41953, 41983, 42012, 42042, 42072, 42102, 42131, 42161,\n    42190, 42220, 42249, 42279, 42308, 42337, 42367, 42397, 42426, 42456, 42485, 42515, 42545, 42574, 42604, 42633, 42662, 42692, 42721, 42751,\n    42780, 42810, 42839, 42869, 42899, 42929, 42958, 42988, 43017, 43046, 43076, 43105, 43135, 43164, 43194, 43223, 43253, 43283, 43312, 43342,\n    43371, 43401, 43430, 43460, 43489, 43519, 43548, 43578, 43607, 43637, 43666, 43696, 43726, 43755, 43785, 43814, 43844, 43873, 43903, 43932,\n    43962, 43991, 44021, 44050, 44080, 44109, 44139, 44169, 44198, 44228, 44258, 44287, 44317, 44346, 44375, 44405, 44434, 44464, 44493, 44523,\n    44553, 44582, 44612, 44641, 44671, 44700, 44730, 44759, 44788, 44818, 44847, 44877, 44906, 44936, 44966, 44996, 45025, 45055, 45084, 45114,\n    45143, 45172, 45202, 45231, 45261, 45290, 45320, 45350, 45380, 45409, 45439, 45468, 45498, 45527, 45556, 45586, 45615, 45644, 45674, 45704,\n    45733, 45763, 45793, 45823, 45852, 45882, 45911, 45940, 45970, 45999, 46028, 46058, 46088, 46117, 46147, 46177, 46206, 46236, 46265, 46295,\n    46324, 46354, 46383, 46413, 46442, 46472, 46501, 46531, 46560, 46590, 46620, 46649, 46679, 46708, 46738, 46767, 46797, 46826, 46856, 46885,\n    46915, 46944, 46974, 47003, 47033, 47063, 47092, 47122, 47151, 47181, 47210, 47240, 47269, 47298, 47328, 47357, 47387, 47417, 47446, 47476,\n    47506, 47535, 47565, 47594, 47624, 47653, 47682, 47712, 47741, 47771, 47800, 47830, 47860, 47890, 47919, 47949, 47978, 48008, 48037, 48066,\n    48096, 48125, 48155, 48184, 48214, 48244, 48273, 48303, 48333, 48362, 48392, 48421, 48450, 48480, 48509, 48538, 48568, 48598, 48627, 48657,\n    48687, 48717, 48746, 48776, 48805, 48834, 48864, 48893, 48922, 48952, 48982, 49011, 49041, 49071, 49100, 49130, 49160, 49189, 49218, 49248,\n    49277, 49306, 49336, 49365, 49395, 49425, 49455, 49484, 49514, 49543, 49573, 49602, 49632, 49661, 49690, 49720, 49749, 49779, 49809, 49838,\n    49868, 49898, 49927, 49957, 49986, 50016, 50045, 50075, 50104, 50133, 50163, 50192, 50222, 50252, 50281, 50311, 50340, 50370, 50400, 50429,\n    50459, 50488, 50518, 50547, 50576, 50606, 50635, 50665, 50694, 50724, 50754, 50784, 50813, 50843, 50872, 50902, 50931, 50960, 50990, 51019,\n    51049, 51078, 51108, 51138, 51167, 51197, 51227, 51256, 51286, 51315, 51345, 51374, 51403, 51433, 51462, 51492, 51522, 51552, 51582, 51611,\n    51641, 51670, 51699, 51729, 51758, 51787, 51816, 51846, 51876, 51906, 51936, 51965, 51995, 52025, 52054, 52083, 52113, 52142, 52171, 52200,\n    52230, 52260, 52290, 52319, 52349, 52379, 52408, 52438, 52467, 52497, 52526, 52555, 52585, 52614, 52644, 52673, 52703, 52733, 52762, 52792,\n    52822, 52851, 52881, 52910, 52939, 52969, 52998, 53028, 53057, 53087, 53116, 53146, 53176, 53205, 53235, 53264, 53294, 53324, 53353, 53383,\n    53412, 53441, 53471, 53500, 53530, 53559, 53589, 53619, 53648, 53678, 53708, 53737, 53767, 53796, 53825, 53855, 53884, 53913, 53943, 53973,\n    54003, 54032, 54062, 54092, 54121, 54151, 54180, 54209, 54239, 54268, 54297, 54327, 54357, 54387, 54416, 54446, 54476, 54505, 54535, 54564,\n    54593, 54623, 54652, 54681, 54711, 54741, 54770, 54800, 54830, 54859, 54889, 54919, 54948, 54977, 55007, 55036, 55066, 55095, 55125, 55154,\n    55184, 55213, 55243, 55273, 55302, 55332, 55361, 55391, 55420, 55450, 55479, 55508, 55538, 55567, 55597, 55627, 55657, 55686, 55716, 55745,\n    55775, 55804, 55834, 55863, 55892, 55922, 55951, 55981, 56011, 56040, 56070, 56100, 56129, 56159, 56188, 56218, 56247, 56276, 56306, 56335,\n    56365, 56394, 56424, 56454, 56483, 56513, 56543, 56572, 56601, 56631, 56660, 56690, 56719, 56749, 56778, 56808, 56837, 56867, 56897, 56926,\n    56956, 56985, 57015, 57044, 57074, 57103, 57133, 57162, 57192, 57221, 57251, 57280, 57310, 57340, 57369, 57399, 57429, 57458, 57487, 57517,\n    57546, 57576, 57605, 57634, 57664, 57694, 57723, 57753, 57783, 57813, 57842, 57871, 57901, 57930, 57959, 57989, 58018, 58048, 58077, 58107,\n    58137, 58167, 58196, 58226, 58255, 58285, 58314, 58343, 58373, 58402, 58432, 58461, 58491, 58521, 58551, 58580, 58610, 58639, 58669, 58698,\n    58727, 58757, 58786, 58816, 58845, 58875, 58905, 58934, 58964, 58994, 59023, 59053, 59082, 59111, 59141, 59170, 59200, 59229, 59259, 59288,\n    59318, 59348, 59377, 59407, 59436, 59466, 59495, 59525, 59554, 59584, 59613, 59643, 59672, 59702, 59731, 59761, 59791, 59820, 59850, 59879,\n    59909, 59939, 59968, 59997, 60027, 60056, 60086, 60115, 60145, 60174, 60204, 60234, 60264, 60293, 60323, 60352, 60381, 60411, 60440, 60469,\n    60499, 60528, 60558, 60588, 60618, 60648, 60677, 60707, 60736, 60765, 60795, 60824, 60853, 60883, 60912, 60942, 60972, 61002, 61031, 61061,\n    61090, 61120, 61149, 61179, 61208, 61237, 61267, 61296, 61326, 61356, 61385, 61415, 61445, 61474, 61504, 61533, 61563, 61592, 61621, 61651,\n    61680, 61710, 61739, 61769, 61799, 61828, 61858, 61888, 61917, 61947, 61976, 62006, 62035, 62064, 62094, 62123, 62153, 62182, 62212, 62242,\n    62271, 62301, 62331, 62360, 62390, 62419, 62448, 62478, 62507, 62537, 62566, 62596, 62625, 62655, 62685, 62715, 62744, 62774, 62803, 62832,\n    62862, 62891, 62921, 62950, 62980, 63009, 63039, 63069, 63099, 63128, 63157, 63187, 63216, 63246, 63275, 63305, 63334, 63363, 63393, 63423,\n    63453, 63482, 63512, 63541, 63571, 63600, 63630, 63659, 63689, 63718, 63747, 63777, 63807, 63836, 63866, 63895, 63925, 63955, 63984, 64014,\n    64043, 64073, 64102, 64131, 64161, 64190, 64220, 64249, 64279, 64309, 64339, 64368, 64398, 64427, 64457, 64486, 64515, 64545, 64574, 64603,\n    64633, 64663, 64692, 64722, 64752, 64782, 64811, 64841, 64870, 64899, 64929, 64958, 64987, 65017, 65047, 65076, 65106, 65136, 65166, 65195,\n    65225, 65254, 65283, 65313, 65342, 65371, 65401, 65431, 65460, 65490, 65520, 65549, 65579, 65608, 65638, 65667, 65697, 65726, 65755, 65785,\n    65815, 65844, 65874, 65903, 65933, 65963, 65992, 66022, 66051, 66081, 66110, 66140, 66169, 66199, 66228, 66258, 66287, 66317, 66346, 66376,\n    66405, 66435, 66465, 66494, 66524, 66553, 66583, 66612, 66641, 66671, 66700, 66730, 66760, 66789, 66819, 66849, 66878, 66908, 66937, 66967,\n    66996, 67025, 67055, 67084, 67114, 67143, 67173, 67203, 67233, 67262, 67292, 67321, 67351, 67380, 67409, 67439, 67468, 67497, 67527, 67557,\n    67587, 67617, 67646, 67676, 67705, 67735, 67764, 67793, 67823, 67852, 67882, 67911, 67941, 67971, 68000, 68030, 68060, 68089, 68119, 68148,\n    68177, 68207, 68236, 68266, 68295, 68325, 68354, 68384, 68414, 68443, 68473, 68502, 68532, 68561, 68591, 68620, 68650, 68679, 68708, 68738,\n    68768, 68797, 68827, 68857, 68886, 68916, 68946, 68975, 69004, 69034, 69063, 69092, 69122, 69152, 69181, 69211, 69240, 69270, 69300, 69330,\n    69359, 69388, 69418, 69447, 69476, 69506, 69535, 69565, 69595, 69624, 69654, 69684, 69713, 69743, 69772, 69802, 69831, 69861, 69890, 69919,\n    69949, 69978, 70008, 70038, 70067, 70097, 70126, 70156, 70186, 70215, 70245, 70274, 70303, 70333, 70362, 70392, 70421, 70451, 70481, 70510,\n    70540, 70570, 70599, 70629, 70658, 70687, 70717, 70746, 70776, 70805, 70835, 70864, 70894, 70924, 70954, 70983, 71013, 71042, 71071, 71101,\n    71130, 71159, 71189, 71218, 71248, 71278, 71308, 71337, 71367, 71397, 71426, 71455, 71485, 71514, 71543, 71573, 71602, 71632, 71662, 71691,\n    71721, 71751, 71781, 71810, 71839, 71869, 71898, 71927, 71957, 71986, 72016, 72046, 72075, 72105, 72135, 72164, 72194, 72223, 72253, 72282,\n    72311, 72341, 72370, 72400, 72429, 72459, 72489, 72518, 72548, 72577, 72607, 72637, 72666, 72695, 72725, 72754, 72784, 72813, 72843, 72872,\n    72902, 72931, 72961, 72991, 73020, 73050, 73080, 73109, 73139, 73168, 73197, 73227, 73256, 73286, 73315, 73345, 73375, 73404, 73434, 73464,\n    73493, 73523, 73552, 73581, 73611, 73640, 73669, 73699, 73729, 73758, 73788, 73818, 73848, 73877, 73907, 73936, 73965, 73995, 74024, 74053,\n    74083, 74113, 74142, 74172, 74202, 74231, 74261, 74291, 74320, 74349, 74379, 74408, 74437, 74467, 74497, 74526, 74556, 74586, 74615, 74645,\n    74675, 74704, 74733, 74763, 74792, 74822, 74851, 74881, 74910, 74940, 74969, 74999, 75029, 75058, 75088, 75117, 75147, 75176, 75206, 75235,\n    75264, 75294, 75323, 75353, 75383, 75412, 75442, 75472, 75501, 75531, 75560, 75590, 75619, 75648, 75678, 75707, 75737, 75766, 75796, 75826,\n    75856, 75885, 75915, 75944, 75974, 76003, 76032, 76062, 76091, 76121, 76150, 76180, 76210, 76239, 76269, 76299, 76328, 76358, 76387, 76416,\n    76446, 76475, 76505, 76534, 76564, 76593, 76623, 76653, 76682, 76712, 76741, 76771, 76801, 76830, 76859, 76889, 76918, 76948, 76977, 77007,\n    77036, 77066, 77096, 77125, 77155, 77185, 77214, 77243, 77273, 77302, 77332, 77361, 77390, 77420, 77450, 77479, 77509, 77539, 77569, 77598,\n    77627, 77657, 77686, 77715, 77745, 77774, 77804, 77833, 77863, 77893, 77923, 77952, 77982, 78011, 78041, 78070, 78099, 78129, 78158, 78188,\n    78217, 78247, 78277, 78307, 78336, 78366, 78395, 78425, 78454, 78483, 78513, 78542, 78572, 78601, 78631, 78661, 78690, 78720, 78750, 78779,\n    78808, 78838, 78867, 78897, 78926, 78956, 78985, 79015, 79044, 79074, 79104, 79133, 79163, 79192, 79222, 79251, 79281, 79310, 79340, 79369,\n    79399, 79428, 79458, 79487, 79517, 79546, 79576, 79606, 79635, 79665, 79695, 79724, 79753, 79783, 79812, 79841, 79871, 79900, 79930, 79960,\n    79990];\n\n\n},{\"../main\":571,\"object-assign\":454}],571:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Calendars for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar assign = _dereq_('object-assign');\n\n\nfunction Calendars() {\n    this.regionalOptions = [];\n    this.regionalOptions[''] = {\n        invalidCalendar: 'Calendar {0} not found',\n        invalidDate: 'Invalid {0} date',\n        invalidMonth: 'Invalid {0} month',\n        invalidYear: 'Invalid {0} year',\n        differentCalendars: 'Cannot mix {0} and {1} dates'\n    };\n    this.local = this.regionalOptions[''];\n    this.calendars = {};\n    this._localCals = {};\n}\n\n/** Create the calendars plugin.\n    <p>Provides support for various world calendars in a consistent manner.</p>\n     @class Calendars\n    @example _exports.instance('julian').newDate(2014, 12, 25) */\nassign(Calendars.prototype, {\n\n    /** Obtain a calendar implementation and localisation.\n        @memberof Calendars\n        @param [name='gregorian'] {string} The name of the calendar, e.g. 'gregorian', 'persian', 'islamic'.\n        @param [language=''] {string} The language code to use for localisation (default is English).\n        @return {Calendar} The calendar and localisation.\n        @throws Error if calendar not found. */\n    instance: function(name, language) {\n        name = (name || 'gregorian').toLowerCase();\n        language = language || '';\n        var cal = this._localCals[name + '-' + language];\n        if (!cal && this.calendars[name]) {\n            cal = new this.calendars[name](language);\n            this._localCals[name + '-' + language] = cal;\n        }\n        if (!cal) {\n            throw (this.local.invalidCalendar || this.regionalOptions[''].invalidCalendar).\n                replace(/\\{0\\}/, name);\n        }\n        return cal;\n    },\n\n    /** Create a new date - for today if no other parameters given.\n        @memberof Calendars\n        @param year {CDate|number} The date to copy or the year for the date.\n        @param [month] {number} The month for the date.\n        @param [day] {number} The day for the date.\n        @param [calendar='gregorian'] {BaseCalendar|string} The underlying calendar or the name of the calendar.\n        @param [language=''] {string} The language to use for localisation (default English).\n        @return {CDate} The new date.\n        @throws Error if an invalid date. */\n    newDate: function(year, month, day, calendar, language) {\n        calendar = (year != null && year.year ? year.calendar() : (typeof calendar === 'string' ?\n            this.instance(calendar, language) : calendar)) || this.instance();\n        return calendar.newDate(year, month, day);\n    },\n    \n    /** A simple digit substitution function for localising numbers via the Calendar digits option.\n        @member Calendars\n        @param digits {string[]} The substitute digits, for 0 through 9.\n        @return {function} The substitution function. */\n    substituteDigits: function(digits) {\n        return function(value) {\n            return (value + '').replace(/[0-9]/g, function(digit) {\n                return digits[digit];\n            });\n        }\n    },\n    \n    /** Digit substitution function for localising Chinese style numbers via the Calendar digits option.\n        @member Calendars\n        @param digits {string[]} The substitute digits, for 0 through 9.\n        @param powers {string[]} The characters denoting powers of 10, i.e. 1, 10, 100, 1000.\n        @return {function} The substitution function. */\n    substituteChineseDigits: function(digits, powers) {\n        return function(value) {\n            var localNumber = '';\n            var power = 0;\n            while (value > 0) {\n                var units = value % 10;\n                localNumber = (units === 0 ? '' : digits[units] + powers[power]) + localNumber;\n                power++;\n                value = Math.floor(value / 10);\n            }\n            if (localNumber.indexOf(digits[1] + powers[1]) === 0) {\n                localNumber = localNumber.substr(1);\n            }\n            return localNumber || digits[0];\n        }\n    }\n});\n\n/** Generic date, based on a particular calendar.\n    @class CDate\n    @param calendar {BaseCalendar} The underlying calendar implementation.\n    @param year {number} The year for this date.\n    @param month {number} The month for this date.\n    @param day {number} The day for this date.\n    @return {CDate} The date object.\n    @throws Error if an invalid date. */\nfunction CDate(calendar, year, month, day) {\n    this._calendar = calendar;\n    this._year = year;\n    this._month = month;\n    this._day = day;\n    if (this._calendar._validateLevel === 0 &&\n            !this._calendar.isValid(this._year, this._month, this._day)) {\n        throw (_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate).\n            replace(/\\{0\\}/, this._calendar.local.name);\n    }\n}\n\n/** Pad a numeric value with leading zeroes.\n    @private\n    @param value {number} The number to format.\n    @param length {number} The minimum length.\n    @return {string} The formatted number. */\nfunction pad(value, length) {\n    value = '' + value;\n    return '000000'.substring(0, length - value.length) + value;\n}\n\nassign(CDate.prototype, {\n\n    /** Create a new date.\n        @memberof CDate\n        @param [year] {CDate|number} The date to copy or the year for the date (default this date).\n        @param [month] {number} The month for the date.\n        @param [day] {number} The day for the date.\n        @return {CDate} The new date.\n        @throws Error if an invalid date. */\n    newDate: function(year, month, day) {\n        return this._calendar.newDate((year == null ? this : year), month, day);\n    },\n\n    /** Set or retrieve the year for this date.\n        @memberof CDate\n        @param [year] {number} The year for the date.\n        @return {number|CDate} The date's year (if no parameter) or the updated date.\n        @throws Error if an invalid date. */\n    year: function(year) {\n        return (arguments.length === 0 ? this._year : this.set(year, 'y'));\n    },\n\n    /** Set or retrieve the month for this date.\n        @memberof CDate\n        @param [month] {number} The month for the date.\n        @return {number|CDate} The date's month (if no parameter) or the updated date.\n        @throws Error if an invalid date. */\n    month: function(month) {\n        return (arguments.length === 0 ? this._month : this.set(month, 'm'));\n    },\n\n    /** Set or retrieve the day for this date.\n        @memberof CDate\n        @param [day] {number} The day for the date.\n        @return {number|CData} The date's day (if no parameter) or the updated date.\n        @throws Error if an invalid date. */\n    day: function(day) {\n        return (arguments.length === 0 ? this._day : this.set(day, 'd'));\n    },\n\n    /** Set new values for this date.\n        @memberof CDate\n        @param year {number} The year for the date.\n        @param month {number} The month for the date.\n        @param day {number} The day for the date.\n        @return {CDate} The updated date.\n        @throws Error if an invalid date. */\n    date: function(year, month, day) {\n        if (!this._calendar.isValid(year, month, day)) {\n            throw (_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate).\n                replace(/\\{0\\}/, this._calendar.local.name);\n        }\n        this._year = year;\n        this._month = month;\n        this._day = day;\n        return this;\n    },\n\n    /** Determine whether this date is in a leap year.\n        @memberof CDate\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not. */\n    leapYear: function() {\n        return this._calendar.leapYear(this);\n    },\n\n    /** Retrieve the epoch designator for this date, e.g. BCE or CE.\n        @memberof CDate\n        @return {string} The current epoch. */\n    epoch: function() {\n        return this._calendar.epoch(this);\n    },\n\n    /** Format the year, if not a simple sequential number.\n        @memberof CDate\n        @return {string} The formatted year. */\n    formatYear: function() {\n        return this._calendar.formatYear(this);\n    },\n\n    /** Retrieve the month of the year for this date,\n        i.e. the month's position within a numbered year.\n        @memberof CDate\n        @return {number} The month of the year: <code>minMonth</code> to months per year. */\n    monthOfYear: function() {\n        return this._calendar.monthOfYear(this);\n    },\n\n    /** Retrieve the week of the year for this date.\n        @memberof CDate\n        @return {number} The week of the year: 1 to weeks per year. */\n    weekOfYear: function() {\n        return this._calendar.weekOfYear(this);\n    },\n\n    /** Retrieve the number of days in the year for this date.\n        @memberof CDate\n        @return {number} The number of days in this year. */\n    daysInYear: function() {\n        return this._calendar.daysInYear(this);\n    },\n\n    /** Retrieve the day of the year for this date.\n        @memberof CDate\n        @return {number} The day of the year: 1 to days per year. */\n    dayOfYear: function() {\n        return this._calendar.dayOfYear(this);\n    },\n\n    /** Retrieve the number of days in the month for this date.\n        @memberof CDate\n        @return {number} The number of days. */\n    daysInMonth: function() {\n        return this._calendar.daysInMonth(this);\n    },\n\n    /** Retrieve the day of the week for this date.\n        @memberof CDate\n        @return {number} The day of the week: 0 to number of days - 1. */\n    dayOfWeek: function() {\n        return this._calendar.dayOfWeek(this);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof CDate\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not. */\n    weekDay: function() {\n        return this._calendar.weekDay(this);\n    },\n\n    /** Retrieve additional information about this date.\n        @memberof CDate\n        @return {object} Additional information - contents depends on calendar. */\n    extraInfo: function() {\n        return this._calendar.extraInfo(this);\n    },\n\n    /** Add period(s) to a date.\n        @memberof CDate\n        @param offset {number} The number of periods to adjust by.\n        @param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.\n        @return {CDate} The updated date. */\n    add: function(offset, period) {\n        return this._calendar.add(this, offset, period);\n    },\n\n    /** Set a portion of the date.\n        @memberof CDate\n        @param value {number} The new value for the period.\n        @param period {string} One of 'y' for year, 'm' for month, 'd' for day.\n        @return {CDate} The updated date.\n        @throws Error if not a valid date. */\n    set: function(value, period) {\n        return this._calendar.set(this, value, period);\n    },\n\n    /** Compare this date to another date.\n        @memberof CDate\n        @param date {CDate} The other date.\n        @return {number} -1 if this date is before the other date,\n                0 if they are equal, or +1 if this date is after the other date. */\n    compareTo: function(date) {\n        if (this._calendar.name !== date._calendar.name) {\n            throw (_exports.local.differentCalendars || _exports.regionalOptions[''].differentCalendars).\n                replace(/\\{0\\}/, this._calendar.local.name).replace(/\\{1\\}/, date._calendar.local.name);\n        }\n        var c = (this._year !== date._year ? this._year - date._year :\n            this._month !== date._month ? this.monthOfYear() - date.monthOfYear() :\n            this._day - date._day);\n        return (c === 0 ? 0 : (c < 0 ? -1 : +1));\n    },\n\n    /** Retrieve the calendar backing this date.\n        @memberof CDate\n        @return {BaseCalendar} The calendar implementation. */\n    calendar: function() {\n        return this._calendar;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof CDate\n        @return {number} The equivalent Julian date. */\n    toJD: function() {\n        return this._calendar.toJD(this);\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof CDate\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        return this._calendar.fromJD(jd);\n    },\n\n    /** Convert this date to a standard (Gregorian) JavaScript Date.\n        @memberof CDate\n        @return {Date} The equivalent JavaScript date. */\n    toJSDate: function() {\n        return this._calendar.toJSDate(this);\n    },\n\n    /** Create a new date from a standard (Gregorian) JavaScript Date.\n        @memberof CDate\n        @param jsd {Date} The JavaScript date to convert.\n        @return {CDate} The equivalent date. */\n    fromJSDate: function(jsd) {\n        return this._calendar.fromJSDate(jsd);\n    },\n\n    /** Convert to a string for display.\n        @memberof CDate\n        @return {string} This date as a string. */\n    toString: function() {\n        return (this.year() < 0 ? '-' : '') + pad(Math.abs(this.year()), 4) +\n            '-' + pad(this.month(), 2) + '-' + pad(this.day(), 2);\n    }\n});\n\n/** Basic functionality for all calendars.\n    Other calendars should extend this:\n    <pre>OtherCalendar.prototype = new BaseCalendar;</pre>\n    @class BaseCalendar */\nfunction BaseCalendar() {\n    this.shortYearCutoff = '+10';\n}\n\nassign(BaseCalendar.prototype, {\n    _validateLevel: 0, // \"Stack\" to turn validation on/off\n\n    /** Create a new date within this calendar - today if no parameters given.\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to duplicate or the year for the date.\n        @param [month] {number} The month for the date.\n        @param [day] {number} The day for the date.\n        @return {CDate} The new date.\n        @throws Error if not a valid date or a different calendar used. */\n    newDate: function(year, month, day) {\n        if (year == null) {\n            return this.today();\n        }\n        if (year.year) {\n            this._validate(year, month, day,\n                _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n            day = year.day();\n            month = year.month();\n            year = year.year();\n        }\n        return new CDate(this, year, month, day);\n    },\n\n    /** Create a new date for today.\n        @memberof BaseCalendar\n        @return {CDate} Today's date. */\n    today: function() {\n        return this.fromJSDate(new Date());\n    },\n\n    /** Retrieve the epoch designator for this date.\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {string} The current epoch.\n        @throws Error if an invalid year or a different calendar used. */\n    epoch: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay,\n            _exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);\n        return (date.year() < 0 ? this.local.epochs[0] : this.local.epochs[1]);\n    },\n\n    /** Format the year, if not a simple sequential number\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to format or the year to format.\n        @return {string} The formatted year.\n        @throws Error if an invalid year or a different calendar used. */\n    formatYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay,\n            _exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);\n        return (date.year() < 0 ? '-' : '') + pad(Math.abs(date.year()), 4)\n    },\n\n    /** Retrieve the number of months in a year.\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of months.\n        @throws Error if an invalid year or a different calendar used. */\n    monthsInYear: function(year) {\n        this._validate(year, this.minMonth, this.minDay,\n            _exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);\n        return 12;\n    },\n\n    /** Calculate the month's ordinal position within the year -\n        for those calendars that don't start at month 1!\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param month {number} The month to examine.\n        @return {number} The ordinal position, starting from <code>minMonth</code>.\n        @throws Error if an invalid year/month or a different calendar used. */\n    monthOfYear: function(year, month) {\n        var date = this._validate(year, month, this.minDay,\n            _exports.local.invalidMonth || _exports.regionalOptions[''].invalidMonth);\n        return (date.month() + this.monthsInYear(date) - this.firstMonth) %\n            this.monthsInYear(date) + this.minMonth;\n    },\n\n    /** Calculate actual month from ordinal position, starting from minMonth.\n        @memberof BaseCalendar\n        @param year {number} The year to examine.\n        @param ord {number} The month's ordinal position.\n        @return {number} The month's number.\n        @throws Error if an invalid year/month. */\n    fromMonthOfYear: function(year, ord) {\n        var m = (ord + this.firstMonth - 2 * this.minMonth) %\n            this.monthsInYear(year) + this.minMonth;\n        this._validate(year, m, this.minDay,\n            _exports.local.invalidMonth || _exports.regionalOptions[''].invalidMonth);\n        return m;\n    },\n\n    /** Retrieve the number of days in a year.\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {number} The number of days.\n        @throws Error if an invalid year or a different calendar used. */\n    daysInYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay,\n            _exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);\n        return (this.leapYear(date) ? 366 : 365);\n    },\n\n    /** Retrieve the day of the year for a date.\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The day of the year.\n        @throws Error if an invalid date or a different calendar used. */\n    dayOfYear: function(year, month, day) {\n        var date = this._validate(year, month, day,\n            _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n        return date.toJD() - this.newDate(date.year(),\n            this.fromMonthOfYear(date.year(), this.minMonth), this.minDay).toJD() + 1;\n    },\n\n    /** Retrieve the number of days in a week.\n        @memberof BaseCalendar\n        @return {number} The number of days. */\n    daysInWeek: function() {\n        return 7;\n    },\n\n    /** Retrieve the day of the week for a date.\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The day of the week: 0 to number of days - 1.\n        @throws Error if an invalid date or a different calendar used. */\n    dayOfWeek: function(year, month, day) {\n        var date = this._validate(year, month, day,\n            _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n        return (Math.floor(this.toJD(date)) + 2) % this.daysInWeek();\n    },\n\n    /** Retrieve additional information about a date.\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {object} Additional information - contents depends on calendar.\n        @throws Error if an invalid date or a different calendar used. */\n    extraInfo: function(year, month, day) {\n        this._validate(year, month, day,\n            _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n        return {};\n    },\n\n    /** Add period(s) to a date.\n        Cater for no year zero.\n        @memberof BaseCalendar\n        @param date {CDate} The starting date.\n        @param offset {number} The number of periods to adjust by.\n        @param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.\n        @return {CDate} The updated date.\n        @throws Error if a different calendar used. */\n    add: function(date, offset, period) {\n        this._validate(date, this.minMonth, this.minDay,\n            _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n        return this._correctAdd(date, this._add(date, offset, period), offset, period);\n    },\n\n    /** Add period(s) to a date.\n        @memberof BaseCalendar\n        @private\n        @param date {CDate} The starting date.\n        @param offset {number} The number of periods to adjust by.\n        @param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.\n        @return {CDate} The updated date. */\n    _add: function(date, offset, period) {\n        this._validateLevel++;\n        if (period === 'd' || period === 'w') {\n            var jd = date.toJD() + offset * (period === 'w' ? this.daysInWeek() : 1);\n            var d = date.calendar().fromJD(jd);\n            this._validateLevel--;\n            return [d.year(), d.month(), d.day()];\n        }\n        try {\n            var y = date.year() + (period === 'y' ? offset : 0);\n            var m = date.monthOfYear() + (period === 'm' ? offset : 0);\n            var d = date.day();// + (period === 'd' ? offset : 0) +\n                //(period === 'w' ? offset * this.daysInWeek() : 0);\n            var resyncYearMonth = function(calendar) {\n                while (m < calendar.minMonth) {\n                    y--;\n                    m += calendar.monthsInYear(y);\n                }\n                var yearMonths = calendar.monthsInYear(y);\n                while (m > yearMonths - 1 + calendar.minMonth) {\n                    y++;\n                    m -= yearMonths;\n                    yearMonths = calendar.monthsInYear(y);\n                }\n            };\n            if (period === 'y') {\n                if (date.month() !== this.fromMonthOfYear(y, m)) { // Hebrew\n                    m = this.newDate(y, date.month(), this.minDay).monthOfYear();\n                }\n                m = Math.min(m, this.monthsInYear(y));\n                d = Math.min(d, this.daysInMonth(y, this.fromMonthOfYear(y, m)));\n            }\n            else if (period === 'm') {\n                resyncYearMonth(this);\n                d = Math.min(d, this.daysInMonth(y, this.fromMonthOfYear(y, m)));\n            }\n            var ymd = [y, this.fromMonthOfYear(y, m), d];\n            this._validateLevel--;\n            return ymd;\n        }\n        catch (e) {\n            this._validateLevel--;\n            throw e;\n        }\n    },\n\n    /** Correct a candidate date after adding period(s) to a date.\n        Handle no year zero if necessary.\n        @memberof BaseCalendar\n        @private\n        @param date {CDate} The starting date.\n        @param ymd {number[]} The added date.\n        @param offset {number} The number of periods to adjust by.\n        @param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.\n        @return {CDate} The updated date. */\n    _correctAdd: function(date, ymd, offset, period) {\n        if (!this.hasYearZero && (period === 'y' || period === 'm')) {\n            if (ymd[0] === 0 || // In year zero\n                    (date.year() > 0) !== (ymd[0] > 0)) { // Crossed year zero\n                var adj = {y: [1, 1, 'y'], m: [1, this.monthsInYear(-1), 'm'],\n                    w: [this.daysInWeek(), this.daysInYear(-1), 'd'],\n                    d: [1, this.daysInYear(-1), 'd']}[period];\n                var dir = (offset < 0 ? -1 : +1);\n                ymd = this._add(date, offset * adj[0] + dir * adj[1], adj[2]);\n            }\n        }\n        return date.date(ymd[0], ymd[1], ymd[2]);\n    },\n\n    /** Set a portion of the date.\n        @memberof BaseCalendar\n        @param date {CDate} The starting date.\n        @param value {number} The new value for the period.\n        @param period {string} One of 'y' for year, 'm' for month, 'd' for day.\n        @return {CDate} The updated date.\n        @throws Error if an invalid date or a different calendar used. */\n    set: function(date, value, period) {\n        this._validate(date, this.minMonth, this.minDay,\n            _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n        var y = (period === 'y' ? value : date.year());\n        var m = (period === 'm' ? value : date.month());\n        var d = (period === 'd' ? value : date.day());\n        if (period === 'y' || period === 'm') {\n            d = Math.min(d, this.daysInMonth(y, m));\n        }\n        return date.date(y, m, d);\n    },\n\n    /** Determine whether a date is valid for this calendar.\n        @memberof BaseCalendar\n        @param year {number} The year to examine.\n        @param month {number} The month to examine.\n        @param day {number} The day to examine.\n        @return {boolean} <code>true</code> if a valid date, <code>false</code> if not. */\n    isValid: function(year, month, day) {\n        this._validateLevel++;\n        var valid = (this.hasYearZero || year !== 0);\n        if (valid) {\n            var date = this.newDate(year, month, this.minDay);\n            valid = (month >= this.minMonth && month - this.minMonth < this.monthsInYear(date)) &&\n                (day >= this.minDay && day - this.minDay < this.daysInMonth(date));\n        }\n        this._validateLevel--;\n        return valid;\n    },\n\n    /** Convert the date to a standard (Gregorian) JavaScript Date.\n        @memberof BaseCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {Date} The equivalent JavaScript date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJSDate: function(year, month, day) {\n        var date = this._validate(year, month, day,\n            _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n        return _exports.instance().fromJD(this.toJD(date)).toJSDate();\n    },\n\n    /** Convert the date from a standard (Gregorian) JavaScript Date.\n        @memberof BaseCalendar\n        @param jsd {Date} The JavaScript date.\n        @return {CDate} The equivalent calendar date. */\n    fromJSDate: function(jsd) {\n        return this.fromJD(_exports.instance().fromJSDate(jsd).toJD());\n    },\n\n    /** Check that a candidate date is from the same calendar and is valid.\n        @memberof BaseCalendar\n        @private\n        @param year {CDate|number} The date to validate or the year to validate.\n        @param [month] {number} The month to validate.\n        @param [day] {number} The day to validate.\n        @param error {string} Rrror message if invalid.\n        @throws Error if different calendars used or invalid date. */\n    _validate: function(year, month, day, error) {\n        if (year.year) {\n            if (this._validateLevel === 0 && this.name !== year.calendar().name) {\n                throw (_exports.local.differentCalendars || _exports.regionalOptions[''].differentCalendars).\n                    replace(/\\{0\\}/, this.local.name).replace(/\\{1\\}/, year.calendar().local.name);\n            }\n            return year;\n        }\n        try {\n            this._validateLevel++;\n            if (this._validateLevel === 1 && !this.isValid(year, month, day)) {\n                throw error.replace(/\\{0\\}/, this.local.name);\n            }\n            var date = this.newDate(year, month, day);\n            this._validateLevel--;\n            return date;\n        }\n        catch (e) {\n            this._validateLevel--;\n            throw e;\n        }\n    }\n});\n\n/** Implementation of the Proleptic Gregorian Calendar.\n    See <a href=\":http://en.wikipedia.org/wiki/Gregorian_calendar\">http://en.wikipedia.org/wiki/Gregorian_calendar</a>\n    and <a href=\"http://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar\">http://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar</a>.\n    @class GregorianCalendar\n    @augments BaseCalendar\n    @param [language=''] {string} The language code (default English) for localisation. */\nfunction GregorianCalendar(language) {\n    this.local = this.regionalOptions[language] || this.regionalOptions[''];\n}\n\nGregorianCalendar.prototype = new BaseCalendar;\n\nassign(GregorianCalendar.prototype, {\n    /** The calendar name.\n        @memberof GregorianCalendar */\n    name: 'Gregorian',\n     /** Julian date of start of Gregorian epoch: 1 January 0001 CE.\n        @memberof GregorianCalendar */\n    jdEpoch: 1721425.5,\n     /** Days per month in a common year.\n        @memberof GregorianCalendar */\n    daysPerMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],\n     /** <code>true</code> if has a year zero, <code>false</code> if not.\n        @memberof GregorianCalendar */\n    hasYearZero: false,\n    /** The minimum month number.\n        @memberof GregorianCalendar */\n    minMonth: 1,\n    /** The first month in the year.\n        @memberof GregorianCalendar */\n    firstMonth: 1,\n     /** The minimum day number.\n        @memberof GregorianCalendar */\n    minDay: 1,\n\n    /** Localisations for the plugin.\n        Entries are objects indexed by the language code ('' being the default US/English).\n        Each object has the following attributes.\n        @memberof GregorianCalendar\n        @property name {string} The calendar name.\n        @property epochs {string[]} The epoch names.\n        @property monthNames {string[]} The long names of the months of the year.\n        @property monthNamesShort {string[]} The short names of the months of the year.\n        @property dayNames {string[]} The long names of the days of the week.\n        @property dayNamesShort {string[]} The short names of the days of the week.\n        @property dayNamesMin {string[]} The minimal names of the days of the week.\n        @property dateFormat {string} The date format for this calendar.\n                See the options on <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a> for details.\n        @property firstDay {number} The number of the first day of the week, starting at 0.\n        @property isRTL {number} <code>true</code> if this localisation reads right-to-left. */\n    regionalOptions: { // Localisations\n        '': {\n            name: 'Gregorian',\n            epochs: ['BCE', 'CE'],\n            monthNames: ['January', 'February', 'March', 'April', 'May', 'June',\n            'July', 'August', 'September', 'October', 'November', 'December'],\n            monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n            dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n            dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n            dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],\n            digits: null,\n            dateFormat: 'mm/dd/yyyy',\n            firstDay: 0,\n            isRTL: false\n        }\n    },\n    \n    /** Determine whether this date is in a leap year.\n        @memberof GregorianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @return {boolean} <code>true</code> if this is a leap year, <code>false</code> if not.\n        @throws Error if an invalid year or a different calendar used. */\n    leapYear: function(year) {\n        var date = this._validate(year, this.minMonth, this.minDay,\n            _exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);\n        var year = date.year() + (date.year() < 0 ? 1 : 0); // No year zero\n        return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n    },\n\n    /** Determine the week of the year for a date - ISO 8601.\n        @memberof GregorianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {number} The week of the year, starting from 1.\n        @throws Error if an invalid date or a different calendar used. */\n    weekOfYear: function(year, month, day) {\n        // Find Thursday of this week starting on Monday\n        var checkDate = this.newDate(year, month, day);\n        checkDate.add(4 - (checkDate.dayOfWeek() || 7), 'd');\n        return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;\n    },\n\n    /** Retrieve the number of days in a month.\n        @memberof GregorianCalendar\n        @param year {CDate|number} The date to examine or the year of the month.\n        @param [month] {number} The month.\n        @return {number} The number of days in this month.\n        @throws Error if an invalid month/year or a different calendar used. */\n    daysInMonth: function(year, month) {\n        var date = this._validate(year, month, this.minDay,\n            _exports.local.invalidMonth || _exports.regionalOptions[''].invalidMonth);\n        return this.daysPerMonth[date.month() - 1] +\n            (date.month() === 2 && this.leapYear(date.year()) ? 1 : 0);\n    },\n\n    /** Determine whether this date is a week day.\n        @memberof GregorianCalendar\n        @param year {CDate|number} The date to examine or the year to examine.\n        @param [month] {number} The month to examine.\n        @param [day] {number} The day to examine.\n        @return {boolean} <code>true</code> if a week day, <code>false</code> if not.\n        @throws Error if an invalid date or a different calendar used. */\n    weekDay: function(year, month, day) {\n        return (this.dayOfWeek(year, month, day) || 7) < 6;\n    },\n\n    /** Retrieve the Julian date equivalent for this date,\n        i.e. days since January 1, 4713 BCE Greenwich noon.\n        @memberof GregorianCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {number} The equivalent Julian date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJD: function(year, month, day) {\n        var date = this._validate(year, month, day,\n            _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n        year = date.year();\n        month = date.month();\n        day = date.day();\n        if (year < 0) { year++; } // No year zero\n        // Jean Meeus algorithm, \"Astronomical Algorithms\", 1991\n        if (month < 3) {\n            month += 12;\n            year--;\n        }\n        var a = Math.floor(year / 100);\n        var b = 2 - a + Math.floor(a / 4);\n        return Math.floor(365.25 * (year + 4716)) +\n            Math.floor(30.6001 * (month + 1)) + day + b - 1524.5;\n    },\n\n    /** Create a new date from a Julian date.\n        @memberof GregorianCalendar\n        @param jd {number} The Julian date to convert.\n        @return {CDate} The equivalent date. */\n    fromJD: function(jd) {\n        // Jean Meeus algorithm, \"Astronomical Algorithms\", 1991\n        var z = Math.floor(jd + 0.5);\n        var a = Math.floor((z - 1867216.25) / 36524.25);\n        a = z + 1 + a - Math.floor(a / 4);\n        var b = a + 1524;\n        var c = Math.floor((b - 122.1) / 365.25);\n        var d = Math.floor(365.25 * c);\n        var e = Math.floor((b - d) / 30.6001);\n        var day = b - d - Math.floor(e * 30.6001);\n        var month = e - (e > 13.5 ? 13 : 1);\n        var year = c - (month > 2.5 ? 4716 : 4715);\n        if (year <= 0) { year--; } // No year zero\n        return this.newDate(year, month, day);\n    },\n\n    /** Convert this date to a standard (Gregorian) JavaScript Date.\n        @memberof GregorianCalendar\n        @param year {CDate|number} The date to convert or the year to convert.\n        @param [month] {number} The month to convert.\n        @param [day] {number} The day to convert.\n        @return {Date} The equivalent JavaScript date.\n        @throws Error if an invalid date or a different calendar used. */\n    toJSDate: function(year, month, day) {\n        var date = this._validate(year, month, day,\n            _exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);\n        var jsd = new Date(date.year(), date.month() - 1, date.day());\n        jsd.setHours(0);\n        jsd.setMinutes(0);\n        jsd.setSeconds(0);\n        jsd.setMilliseconds(0);\n        // Hours may be non-zero on daylight saving cut-over:\n        // > 12 when midnight changeover, but then cannot generate\n        // midnight datetime, so jump to 1AM, otherwise reset.\n        jsd.setHours(jsd.getHours() > 12 ? jsd.getHours() + 2 : 0);\n        return jsd;\n    },\n\n    /** Create a new date from a standard (Gregorian) JavaScript Date.\n        @memberof GregorianCalendar\n        @param jsd {Date} The JavaScript date to convert.\n        @return {CDate} The equivalent date. */\n    fromJSDate: function(jsd) {\n        return this.newDate(jsd.getFullYear(), jsd.getMonth() + 1, jsd.getDate());\n    }\n});\n\n// Singleton manager\nvar _exports = module.exports = new Calendars();\n\n// Date template\n_exports.cdate = CDate;\n\n// Base calendar template\n_exports.baseCalendar = BaseCalendar;\n\n// Gregorian calendar implementation\n_exports.calendars.gregorian = GregorianCalendar;\n\n\n},{\"object-assign\":454}],572:[function(_dereq_,module,exports){\n/*\n * World Calendars\n * https://github.com/alexcjohnson/world-calendars\n *\n * Batch-converted from kbwood/calendars\n * Many thanks to Keith Wood and all of the contributors to the original project!\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n﻿/* http://keith-wood.name/calendars.html\n   Calendars extras for jQuery v2.0.2.\n   Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.\n   Available under the MIT (http://keith-wood.name/licence.html) license. \n   Please attribute the author if you use it. */\n\nvar assign = _dereq_('object-assign');\nvar main = _dereq_('./main');\n\n\nassign(main.regionalOptions[''], {\n    invalidArguments: 'Invalid arguments',\n    invalidFormat: 'Cannot format a date from another calendar',\n    missingNumberAt: 'Missing number at position {0}',\n    unknownNameAt: 'Unknown name at position {0}',\n    unexpectedLiteralAt: 'Unexpected literal at position {0}',\n    unexpectedText: 'Additional text found at end'\n});\nmain.local = main.regionalOptions[''];\n\nassign(main.cdate.prototype, {\n\n    /** Format this date.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof CDate\n        @param [format] {string} The date format to use (see <a href=\"BaseCalendar.html#formatDate\"><code>formatDate</code></a>).\n        @param [settings] {object} Options for the <code>formatDate</code> function.\n        @return {string} The formatted date. */\n    formatDate: function(format, settings) {\n        if (typeof format !== 'string') {\n            settings = format;\n            format = '';\n        }\n        return this._calendar.formatDate(format || '', this, settings);\n    }\n});\n\nassign(main.baseCalendar.prototype, {\n\n    UNIX_EPOCH: main.instance().newDate(1970, 1, 1).toJD(),\n    SECS_PER_DAY: 24 * 60 * 60,\n    TICKS_EPOCH: main.instance().jdEpoch, // 1 January 0001 CE\n    TICKS_PER_DAY: 24 * 60 * 60 * 10000000,\n\n    /** Date form for ATOM (RFC 3339/ISO 8601).\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    ATOM: 'yyyy-mm-dd',\n    /** Date form for cookies.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    COOKIE: 'D, dd M yyyy',\n    /** Date form for full date.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    FULL: 'DD, MM d, yyyy',\n    /** Date form for ISO 8601.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    ISO_8601: 'yyyy-mm-dd',\n    /** Date form for Julian date.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    JULIAN: 'J',\n    /** Date form for RFC 822.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    RFC_822: 'D, d M yy',\n    /** Date form for RFC 850.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    RFC_850: 'DD, dd-M-yy',\n    /** Date form for RFC 1036.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    RFC_1036: 'D, d M yy',\n    /** Date form for RFC 1123.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    RFC_1123: 'D, d M yyyy',\n    /** Date form for RFC 2822.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    RFC_2822: 'D, d M yyyy',\n    /** Date form for RSS (RFC 822).\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    RSS: 'D, d M yy',\n    /** Date form for Windows ticks.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    TICKS: '!',\n    /** Date form for Unix timestamp.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    TIMESTAMP: '@',\n    /** Date form for W3c (ISO 8601).\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar */\n    W3C: 'yyyy-mm-dd',\n\n    /** Format a date object into a string value.\n        The format can be combinations of the following:\n        <ul>\n        <li>d  - day of month (no leading zero)</li>\n        <li>dd - day of month (two digit)</li>\n        <li>o  - day of year (no leading zeros)</li>\n        <li>oo - day of year (three digit)</li>\n        <li>D  - day name short</li>\n        <li>DD - day name long</li>\n        <li>w  - week of year (no leading zero)</li>\n        <li>ww - week of year (two digit)</li>\n        <li>m  - month of year (no leading zero)</li>\n        <li>mm - month of year (two digit)</li>\n        <li>M  - month name short</li>\n        <li>MM - month name long</li>\n        <li>yy - year (two digit)</li>\n        <li>yyyy - year (four digit)</li>\n        <li>YYYY - formatted year</li>\n        <li>J  - Julian date (days since January 1, 4713 BCE Greenwich noon)</li>\n        <li>@  - Unix timestamp (s since 01/01/1970)</li>\n        <li>!  - Windows ticks (100ns since 01/01/0001)</li>\n        <li>'...' - literal text</li>\n        <li>'' - single quote</li>\n        </ul>\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar\n        @param [format] {string} The desired format of the date (defaults to calendar format).\n        @param date {CDate} The date value to format.\n        @param [settings] {object} Addition options, whose attributes include:\n        @property [dayNamesShort] {string[]} Abbreviated names of the days from Sunday.\n        @property [dayNames] {string[]} Names of the days from Sunday.\n        @property [monthNamesShort] {string[]} Abbreviated names of the months.\n        @property [monthNames] {string[]} Names of the months.\n        @property [calculateWeek] {CalendarsPickerCalculateWeek} Function that determines week of the year.\n        @property [localNumbers=false] {boolean} <code>true</code> to localise numbers (if available),\n                  <code>false</code> to use normal Arabic numerals.\n        @return {string} The date in the above format.\n        @throws Errors if the date is from a different calendar. */\n    formatDate: function(format, date, settings) {\n        if (typeof format !== 'string') {\n            settings = date;\n            date = format;\n            format = '';\n        }\n        if (!date) {\n            return '';\n        }\n        if (date.calendar() !== this) {\n            throw main.local.invalidFormat || main.regionalOptions[''].invalidFormat;\n        }\n        format = format || this.local.dateFormat;\n        settings = settings || {};\n        var dayNamesShort = settings.dayNamesShort || this.local.dayNamesShort;\n        var dayNames = settings.dayNames || this.local.dayNames;\n        var monthNumbers = settings.monthNumbers || this.local.monthNumbers;\n        var monthNamesShort = settings.monthNamesShort || this.local.monthNamesShort;\n        var monthNames = settings.monthNames || this.local.monthNames;\n        var calculateWeek = settings.calculateWeek || this.local.calculateWeek;\n        // Check whether a format character is doubled\n        var doubled = function(match, step) {\n            var matches = 1;\n            while (iFormat + matches < format.length && format.charAt(iFormat + matches) === match) {\n                matches++;\n            }\n            iFormat += matches - 1;\n            return Math.floor(matches / (step || 1)) > 1;\n        };\n        // Format a number, with leading zeroes if necessary\n        var formatNumber = function(match, value, len, step) {\n            var num = '' + value;\n            if (doubled(match, step)) {\n                while (num.length < len) {\n                    num = '0' + num;\n                }\n            }\n            return num;\n        };\n        // Format a name, short or long as requested\n        var formatName = function(match, value, shortNames, longNames) {\n            return (doubled(match) ? longNames[value] : shortNames[value]);\n        };\n        // Format month number\n        // (e.g. Chinese calendar needs to account for intercalary months)\n        var calendar = this;\n        var formatMonth = function(date) {\n            return (typeof monthNumbers === 'function') ?\n                monthNumbers.call(calendar, date, doubled('m')) :\n                localiseNumbers(formatNumber('m', date.month(), 2));\n        };\n        // Format a month name, short or long as requested\n        var formatMonthName = function(date, useLongName) {\n            if (useLongName) {\n                return (typeof monthNames === 'function') ?\n                    monthNames.call(calendar, date) :\n                    monthNames[date.month() - calendar.minMonth];\n            } else {\n                return (typeof monthNamesShort === 'function') ?\n                    monthNamesShort.call(calendar, date) :\n                    monthNamesShort[date.month() - calendar.minMonth];\n            }\n        };\n        // Localise numbers if requested and available\n        var digits = this.local.digits;\n        var localiseNumbers = function(value) {\n            return (settings.localNumbers && digits ? digits(value) : value);\n        };\n        var output = '';\n        var literal = false;\n        for (var iFormat = 0; iFormat < format.length; iFormat++) {\n            if (literal) {\n                if (format.charAt(iFormat) === \"'\" && !doubled(\"'\")) {\n                    literal = false;\n                }\n                else {\n                    output += format.charAt(iFormat);\n                }\n            }\n            else {\n                switch (format.charAt(iFormat)) {\n                    case 'd': output += localiseNumbers(formatNumber('d', date.day(), 2)); break;\n                    case 'D': output += formatName('D', date.dayOfWeek(),\n                        dayNamesShort, dayNames); break;\n                    case 'o': output += formatNumber('o', date.dayOfYear(), 3); break;\n                    case 'w': output += formatNumber('w', date.weekOfYear(), 2); break;\n                    case 'm': output += formatMonth(date); break;\n                    case 'M': output += formatMonthName(date, doubled('M')); break;\n                    case 'y':\n                        output += (doubled('y', 2) ? date.year() :\n                            (date.year() % 100 < 10 ? '0' : '') + date.year() % 100);\n                        break;\n                    case 'Y':\n                        doubled('Y', 2);\n                        output += date.formatYear();\n                        break;\n                    case 'J': output += date.toJD(); break;\n                    case '@': output += (date.toJD() - this.UNIX_EPOCH) * this.SECS_PER_DAY; break;\n                    case '!': output += (date.toJD() - this.TICKS_EPOCH) * this.TICKS_PER_DAY; break;\n                    case \"'\":\n                        if (doubled(\"'\")) {\n                            output += \"'\";\n                        }\n                        else {\n                            literal = true;\n                        }\n                        break;\n                    default:\n                        output += format.charAt(iFormat);\n                }\n            }\n        }\n        return output;\n    },\n\n    /** Parse a string value into a date object.\n        See <a href=\"#formatDate\"><code>formatDate</code></a> for the possible formats, plus:\n        <ul>\n        <li>* - ignore rest of string</li>\n        </ul>\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar\n        @param format {string} The expected format of the date ('' for default calendar format).\n        @param value {string} The date in the above format.\n        @param [settings] {object} Additional options whose attributes include:\n        @property [shortYearCutoff] {number} The cutoff year for determining the century.\n        @property [dayNamesShort] {string[]} Abbreviated names of the days from Sunday.\n        @property [dayNames] {string[]} Names of the days from Sunday.\n        @property [monthNamesShort] {string[]} Abbreviated names of the months.\n        @property [monthNames] {string[]} Names of the months.\n        @return {CDate} The extracted date value or <code>null</code> if value is blank.\n        @throws Errors if the format and/or value are missing,\n                if the value doesn't match the format, or if the date is invalid. */\n    parseDate: function(format, value, settings) {\n        if (value == null) {\n            throw main.local.invalidArguments || main.regionalOptions[''].invalidArguments;\n        }\n        value = (typeof value === 'object' ? value.toString() : value + '');\n        if (value === '') {\n            return null;\n        }\n        format = format || this.local.dateFormat;\n        settings = settings || {};\n        var shortYearCutoff = settings.shortYearCutoff || this.shortYearCutoff;\n        shortYearCutoff = (typeof shortYearCutoff !== 'string' ? shortYearCutoff :\n            this.today().year() % 100 + parseInt(shortYearCutoff, 10));\n        var dayNamesShort = settings.dayNamesShort || this.local.dayNamesShort;\n        var dayNames = settings.dayNames || this.local.dayNames;\n        var parseMonth = settings.parseMonth || this.local.parseMonth;\n        var monthNumbers = settings.monthNumbers || this.local.monthNumbers;\n        var monthNamesShort = settings.monthNamesShort || this.local.monthNamesShort;\n        var monthNames = settings.monthNames || this.local.monthNames;\n        var jd = -1;\n        var year = -1;\n        var month = -1;\n        var day = -1;\n        var doy = -1;\n        var shortYear = false;\n        var literal = false;\n        // Check whether a format character is doubled\n        var doubled = function(match, step) {\n            var matches = 1;\n            while (iFormat + matches < format.length && format.charAt(iFormat + matches) === match) {\n                matches++;\n            }\n            iFormat += matches - 1;\n            return Math.floor(matches / (step || 1)) > 1;\n        };\n        // Extract a number from the string value\n        var getNumber = function(match, step) {\n            var isDoubled = doubled(match, step);\n            var size = [2, 3, isDoubled ? 4 : 2, isDoubled ? 4 : 2, 10, 11, 20]['oyYJ@!'.indexOf(match) + 1];\n            var digits = new RegExp('^-?\\\\d{1,' + size + '}');\n            var num = value.substring(iValue).match(digits);\n            if (!num) {\n                throw (main.local.missingNumberAt || main.regionalOptions[''].missingNumberAt).\n                    replace(/\\{0\\}/, iValue);\n            }\n            iValue += num[0].length;\n            return parseInt(num[0], 10);\n        };\n        // Extract a month number from the string value\n        var calendar = this;\n        var getMonthNumber = function() {\n            if (typeof monthNumbers === 'function') {\n                doubled('m');  // update iFormat\n                var month = monthNumbers.call(calendar, value.substring(iValue));\n                iValue += month.length;\n                return month;\n            }\n\n            return getNumber('m');\n        };\n        // Extract a name from the string value and convert to an index\n        var getName = function(match, shortNames, longNames, step) {\n            var names = (doubled(match, step) ? longNames : shortNames);\n            for (var i = 0; i < names.length; i++) {\n                if (value.substr(iValue, names[i].length).toLowerCase() === names[i].toLowerCase()) {\n                    iValue += names[i].length;\n                    return i + calendar.minMonth;\n                }\n            }\n            throw (main.local.unknownNameAt || main.regionalOptions[''].unknownNameAt).\n                replace(/\\{0\\}/, iValue);\n        };\n        // Extract a month number from the string value\n        var getMonthName = function() {\n            if (typeof monthNames === 'function') {\n                var month = doubled('M') ?\n                    monthNames.call(calendar, value.substring(iValue)) :\n                    monthNamesShort.call(calendar, value.substring(iValue));\n                iValue += month.length;\n                return month;\n            }\n\n            return getName('M', monthNamesShort, monthNames);\n        };\n        // Confirm that a literal character matches the string value\n        var checkLiteral = function() {\n            if (value.charAt(iValue) !== format.charAt(iFormat)) {\n                throw (main.local.unexpectedLiteralAt ||\n                    main.regionalOptions[''].unexpectedLiteralAt).replace(/\\{0\\}/, iValue);\n            }\n            iValue++;\n        };\n        var iValue = 0;\n        for (var iFormat = 0; iFormat < format.length; iFormat++) {\n            if (literal) {\n                if (format.charAt(iFormat) === \"'\" && !doubled(\"'\")) {\n                    literal = false;\n                }\n                else {\n                    checkLiteral();\n                }\n            }\n            else {\n                switch (format.charAt(iFormat)) {\n                    case 'd': day = getNumber('d'); break;\n                    case 'D': getName('D', dayNamesShort, dayNames); break;\n                    case 'o': doy = getNumber('o'); break;\n                    case 'w': getNumber('w'); break;\n                    case 'm': month = getMonthNumber(); break;\n                    case 'M': month = getMonthName(); break;\n                    case 'y':\n                        var iSave = iFormat;\n                        shortYear = !doubled('y', 2);\n                        iFormat = iSave;\n                        year = getNumber('y', 2);\n                        break;\n                    case 'Y': year = getNumber('Y', 2); break;\n                    case 'J':\n                        jd = getNumber('J') + 0.5;\n                        if (value.charAt(iValue) === '.') {\n                            iValue++;\n                            getNumber('J');\n                        }\n                        break;\n                    case '@': jd = getNumber('@') / this.SECS_PER_DAY + this.UNIX_EPOCH; break;\n                    case '!': jd = getNumber('!') / this.TICKS_PER_DAY + this.TICKS_EPOCH; break;\n                    case '*': iValue = value.length; break;\n                    case \"'\":\n                        if (doubled(\"'\")) {\n                            checkLiteral();\n                        }\n                        else {\n                            literal = true;\n                        }\n                        break;\n                    default: checkLiteral();\n                }\n            }\n        }\n        if (iValue < value.length) {\n            throw main.local.unexpectedText || main.regionalOptions[''].unexpectedText;\n        }\n        if (year === -1) {\n            year = this.today().year();\n        }\n        else if (year < 100 && shortYear) {\n            year += (shortYearCutoff === -1 ? 1900 : this.today().year() -\n                this.today().year() % 100 - (year <= shortYearCutoff ? 0 : 100));\n        }\n        if (typeof month === 'string') {\n            month = parseMonth.call(this, year, month);\n        }\n        if (doy > -1) {\n            month = 1;\n            day = doy;\n            for (var dim = this.daysInMonth(year, month); day > dim; dim = this.daysInMonth(year, month)) {\n                month++;\n                day -= dim;\n            }\n        }\n        return (jd > -1 ? this.fromJD(jd) : this.newDate(year, month, day));\n    },\n\n    /** A date may be specified as an exact value or a relative one.\n        Found in the <code>jquery.calendars.plus.js</code> module.\n        @memberof BaseCalendar\n        @param dateSpec {CDate|number|string} The date as an object or string in the given format or\n                an offset - numeric days from today, or string amounts and periods, e.g. '+1m +2w'.\n        @param defaultDate {CDate} The date to use if no other supplied, may be <code>null</code>.\n        @param currentDate {CDate} The current date as a possible basis for relative dates,\n                if <code>null</code> today is used (optional)\n        @param [dateFormat] {string} The expected date format - see <a href=\"#formatDate\"><code>formatDate</code></a>.\n        @param [settings] {object} Additional options whose attributes include:\n        @property [shortYearCutoff] {number} The cutoff year for determining the century.\n        @property [dayNamesShort] {string[]} Abbreviated names of the days from Sunday.\n        @property [dayNames] {string[]} Names of the days from Sunday.\n        @property [monthNamesShort] {string[]} Abbreviated names of the months.\n        @property [monthNames] {string[]} Names of the months.\n        @return {CDate} The decoded date. */\n    determineDate: function(dateSpec, defaultDate, currentDate, dateFormat, settings) {\n        if (currentDate && typeof currentDate !== 'object') {\n            settings = dateFormat;\n            dateFormat = currentDate;\n            currentDate = null;\n        }\n        if (typeof dateFormat !== 'string') {\n            settings = dateFormat;\n            dateFormat = '';\n        }\n        var calendar = this;\n        var offsetString = function(offset) {\n            try {\n                return calendar.parseDate(dateFormat, offset, settings);\n            }\n            catch (e) {\n                // Ignore\n            }\n            offset = offset.toLowerCase();\n            var date = (offset.match(/^c/) && currentDate ?\n                currentDate.newDate() : null) || calendar.today();\n            var pattern = /([+-]?[0-9]+)\\s*(d|w|m|y)?/g;\n            var matches = pattern.exec(offset);\n            while (matches) {\n                date.add(parseInt(matches[1], 10), matches[2] || 'd');\n                matches = pattern.exec(offset);\n            }\n            return date;\n        };\n        defaultDate = (defaultDate ? defaultDate.newDate() : null);\n        dateSpec = (dateSpec == null ? defaultDate :\n            (typeof dateSpec === 'string' ? offsetString(dateSpec) : (typeof dateSpec === 'number' ?\n            (isNaN(dateSpec) || dateSpec === Infinity || dateSpec === -Infinity ? defaultDate :\n            calendar.today().add(dateSpec, 'd')) : calendar.newDate(dateSpec))));\n        return dateSpec;\n    }\n});\n\n\n},{\"./main\":571,\"object-assign\":454}],573:[function(_dereq_,module,exports){\nmodule.exports = _dereq_('cwise-compiler')({\n    args: ['array', {\n        offset: [1],\n        array: 0\n    }, 'scalar', 'scalar', 'index'],\n    pre: {\n        \"body\": \"{}\",\n        \"args\": [],\n        \"thisVars\": [],\n        \"localVars\": []\n    },\n    post: {\n        \"body\": \"{}\",\n        \"args\": [],\n        \"thisVars\": [],\n        \"localVars\": []\n    },\n    body: {\n        \"body\": \"{\\n        var _inline_1_da = _inline_1_arg0_ - _inline_1_arg3_\\n        var _inline_1_db = _inline_1_arg1_ - _inline_1_arg3_\\n        if((_inline_1_da >= 0) !== (_inline_1_db >= 0)) {\\n          _inline_1_arg2_.push(_inline_1_arg4_[0] + 0.5 + 0.5 * (_inline_1_da + _inline_1_db) / (_inline_1_da - _inline_1_db))\\n        }\\n      }\",\n        \"args\": [{\n            \"name\": \"_inline_1_arg0_\",\n            \"lvalue\": false,\n            \"rvalue\": true,\n            \"count\": 1\n        }, {\n            \"name\": \"_inline_1_arg1_\",\n            \"lvalue\": false,\n            \"rvalue\": true,\n            \"count\": 1\n        }, {\n            \"name\": \"_inline_1_arg2_\",\n            \"lvalue\": false,\n            \"rvalue\": true,\n            \"count\": 1\n        }, {\n            \"name\": \"_inline_1_arg3_\",\n            \"lvalue\": false,\n            \"rvalue\": true,\n            \"count\": 2\n        }, {\n            \"name\": \"_inline_1_arg4_\",\n            \"lvalue\": false,\n            \"rvalue\": true,\n            \"count\": 1\n        }],\n        \"thisVars\": [],\n        \"localVars\": [\"_inline_1_da\", \"_inline_1_db\"]\n    },\n    funcName: 'zeroCrossings'\n})\n\n},{\"cwise-compiler\":146}],574:[function(_dereq_,module,exports){\n\"use strict\"\n\nmodule.exports = findZeroCrossings\n\nvar core = _dereq_(\"./lib/zc-core\")\n\nfunction findZeroCrossings(array, level) {\n  var cross = []\n  level = +level || 0.0\n  core(array.hi(array.shape[0]-1), cross, level)\n  return cross\n}\n},{\"./lib/zc-core\":573}],575:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * All paths are tuned for maximum scalability of the arrowhead,\n * ie throughout arrowwidth=0.3..3 the head is joined smoothly\n * to the line, with the line coming from the left and ending at (0, 0).\n *\n * `backoff` is the distance to move the arrowhead and the end of the line,\n * in order that the arrowhead points to the desired place, either at\n * the tip of the arrow or (in the case of circle or square)\n * the center of the symbol.\n *\n * `noRotate`, if truthy, says that this arrowhead should not rotate with the\n * arrow. That's the case for squares, which should always be straight, and\n * circles, for which it's irrelevant.\n */\n\nmodule.exports = [\n    // no arrow\n    {\n        path: '',\n        backoff: 0\n    },\n    // wide with flat back\n    {\n        path: 'M-2.4,-3V3L0.6,0Z',\n        backoff: 0.6\n    },\n    // narrower with flat back\n    {\n        path: 'M-3.7,-2.5V2.5L1.3,0Z',\n        backoff: 1.3\n    },\n    // barbed\n    {\n        path: 'M-4.45,-3L-1.65,-0.2V0.2L-4.45,3L1.55,0Z',\n        backoff: 1.55\n    },\n    // wide line-drawn\n    {\n        path: 'M-2.2,-2.2L-0.2,-0.2V0.2L-2.2,2.2L-1.4,3L1.6,0L-1.4,-3Z',\n        backoff: 1.6\n    },\n    // narrower line-drawn\n    {\n        path: 'M-4.4,-2.1L-0.6,-0.2V0.2L-4.4,2.1L-4,3L2,0L-4,-3Z',\n        backoff: 2\n    },\n    // circle\n    {\n        path: 'M2,0A2,2 0 1,1 0,-2A2,2 0 0,1 2,0Z',\n        backoff: 0,\n        noRotate: true\n    },\n    // square\n    {\n        path: 'M2,2V-2H-2V2Z',\n        backoff: 0,\n        noRotate: true\n    }\n];\n\n},{}],576:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar ARROWPATHS = _dereq_('./arrow_paths');\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar cartesianConstants = _dereq_('../../plots/cartesian/constants');\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\n\nmodule.exports = templatedArray('annotation', {\n    visible: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'calc+arraydraw',\n        \n    },\n\n    text: {\n        valType: 'string',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    textangle: {\n        valType: 'angle',\n        dflt: 0,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    font: fontAttrs({\n        editType: 'calc+arraydraw',\n        colorEditType: 'arraydraw',\n        \n    }),\n    width: {\n        valType: 'number',\n        min: 1,\n        dflt: null,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    height: {\n        valType: 'number',\n        min: 1,\n        dflt: null,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    opacity: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 1,\n        \n        editType: 'arraydraw',\n        \n    },\n    align: {\n        valType: 'enumerated',\n        values: ['left', 'center', 'right'],\n        dflt: 'center',\n        \n        editType: 'arraydraw',\n        \n    },\n    valign: {\n        valType: 'enumerated',\n        values: ['top', 'middle', 'bottom'],\n        dflt: 'middle',\n        \n        editType: 'arraydraw',\n        \n    },\n    bgcolor: {\n        valType: 'color',\n        dflt: 'rgba(0,0,0,0)',\n        \n        editType: 'arraydraw',\n        \n    },\n    bordercolor: {\n        valType: 'color',\n        dflt: 'rgba(0,0,0,0)',\n        \n        editType: 'arraydraw',\n        \n    },\n    borderpad: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    borderwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    // arrow\n    showarrow: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    arrowcolor: {\n        valType: 'color',\n        \n        editType: 'arraydraw',\n        \n    },\n    arrowhead: {\n        valType: 'integer',\n        min: 0,\n        max: ARROWPATHS.length,\n        dflt: 1,\n        \n        editType: 'arraydraw',\n        \n    },\n    startarrowhead: {\n        valType: 'integer',\n        min: 0,\n        max: ARROWPATHS.length,\n        dflt: 1,\n        \n        editType: 'arraydraw',\n        \n    },\n    arrowside: {\n        valType: 'flaglist',\n        flags: ['end', 'start'],\n        extras: ['none'],\n        dflt: 'end',\n        \n        editType: 'arraydraw',\n        \n    },\n    arrowsize: {\n        valType: 'number',\n        min: 0.3,\n        dflt: 1,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    startarrowsize: {\n        valType: 'number',\n        min: 0.3,\n        dflt: 1,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    arrowwidth: {\n        valType: 'number',\n        min: 0.1,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    standoff: {\n        valType: 'number',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    startstandoff: {\n        valType: 'number',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    ax: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    ay: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    axref: {\n        valType: 'enumerated',\n        dflt: 'pixel',\n        values: [\n            'pixel',\n            cartesianConstants.idRegex.x.toString()\n        ],\n        \n        editType: 'calc',\n        \n    },\n    ayref: {\n        valType: 'enumerated',\n        dflt: 'pixel',\n        values: [\n            'pixel',\n            cartesianConstants.idRegex.y.toString()\n        ],\n        \n        editType: 'calc',\n        \n    },\n    // positioning\n    xref: {\n        valType: 'enumerated',\n        values: [\n            'paper',\n            cartesianConstants.idRegex.x.toString()\n        ],\n        \n        editType: 'calc',\n        \n    },\n    x: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    xanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'left', 'center', 'right'],\n        dflt: 'auto',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    xshift: {\n        valType: 'number',\n        dflt: 0,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    yref: {\n        valType: 'enumerated',\n        values: [\n            'paper',\n            cartesianConstants.idRegex.y.toString()\n        ],\n        \n        editType: 'calc',\n        \n    },\n    y: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    yanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'top', 'middle', 'bottom'],\n        dflt: 'auto',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    yshift: {\n        valType: 'number',\n        dflt: 0,\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    clicktoshow: {\n        valType: 'enumerated',\n        values: [false, 'onoff', 'onout'],\n        dflt: false,\n        \n        editType: 'arraydraw',\n        \n    },\n    xclick: {\n        valType: 'any',\n        \n        editType: 'arraydraw',\n        \n    },\n    yclick: {\n        valType: 'any',\n        \n        editType: 'arraydraw',\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        editType: 'arraydraw',\n        \n    },\n    hoverlabel: {\n        bgcolor: {\n            valType: 'color',\n            \n            editType: 'arraydraw',\n            \n        },\n        bordercolor: {\n            valType: 'color',\n            \n            editType: 'arraydraw',\n            \n        },\n        font: fontAttrs({\n            editType: 'arraydraw',\n            \n        }),\n        editType: 'arraydraw'\n    },\n    captureevents: {\n        valType: 'boolean',\n        \n        editType: 'arraydraw',\n        \n    },\n    editType: 'calc',\n\n    _deprecated: {\n        ref: {\n            valType: 'string',\n            \n            editType: 'calc',\n            \n        }\n    }\n});\n\n},{\"../../plot_api/plot_template\":757,\"../../plots/cartesian/constants\":773,\"../../plots/font_attributes\":793,\"./arrow_paths\":575}],577:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nvar draw = _dereq_('./draw').draw;\n\n\nmodule.exports = function calcAutorange(gd) {\n    var fullLayout = gd._fullLayout;\n    var annotationList = Lib.filterVisible(fullLayout.annotations);\n\n    if(annotationList.length && gd._fullData.length) {\n        return Lib.syncOrAsync([draw, annAutorange], gd);\n    }\n};\n\nfunction annAutorange(gd) {\n    var fullLayout = gd._fullLayout;\n\n    // find the bounding boxes for each of these annotations'\n    // relative to their anchor points\n    // use the arrow and the text bg rectangle,\n    // as the whole anno may include hidden text in its bbox\n    Lib.filterVisible(fullLayout.annotations).forEach(function(ann) {\n        var xa = Axes.getFromId(gd, ann.xref);\n        var ya = Axes.getFromId(gd, ann.yref);\n\n        ann._extremes = {};\n        if(xa) calcAxisExpansion(ann, xa);\n        if(ya) calcAxisExpansion(ann, ya);\n    });\n}\n\nfunction calcAxisExpansion(ann, ax) {\n    var axId = ax._id;\n    var letter = axId.charAt(0);\n    var pos = ann[letter];\n    var apos = ann['a' + letter];\n    var ref = ann[letter + 'ref'];\n    var aref = ann['a' + letter + 'ref'];\n    var padplus = ann['_' + letter + 'padplus'];\n    var padminus = ann['_' + letter + 'padminus'];\n    var shift = {x: 1, y: -1}[letter] * ann[letter + 'shift'];\n    var headSize = 3 * ann.arrowsize * ann.arrowwidth || 0;\n    var headPlus = headSize + shift;\n    var headMinus = headSize - shift;\n    var startHeadSize = 3 * ann.startarrowsize * ann.arrowwidth || 0;\n    var startHeadPlus = startHeadSize + shift;\n    var startHeadMinus = startHeadSize - shift;\n    var extremes;\n\n    if(aref === ref) {\n        // expand for the arrowhead (padded by arrowhead)\n        var extremeArrowHead = Axes.findExtremes(ax, [ax.r2c(pos)], {\n            ppadplus: headPlus,\n            ppadminus: headMinus\n        });\n        // again for the textbox (padded by textbox)\n        var extremeText = Axes.findExtremes(ax, [ax.r2c(apos)], {\n            ppadplus: Math.max(padplus, startHeadPlus),\n            ppadminus: Math.max(padminus, startHeadMinus)\n        });\n        extremes = {\n            min: [extremeArrowHead.min[0], extremeText.min[0]],\n            max: [extremeArrowHead.max[0], extremeText.max[0]]\n        };\n    } else {\n        startHeadPlus = apos ? startHeadPlus + apos : startHeadPlus;\n        startHeadMinus = apos ? startHeadMinus - apos : startHeadMinus;\n        extremes = Axes.findExtremes(ax, [ax.r2c(pos)], {\n            ppadplus: Math.max(padplus, headPlus, startHeadPlus),\n            ppadminus: Math.max(padminus, headMinus, startHeadMinus)\n        });\n    }\n\n    ann._extremes[axId] = extremes;\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"./draw\":582}],578:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\nvar arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;\n\nmodule.exports = {\n    hasClickToShow: hasClickToShow,\n    onClick: onClick\n};\n\n/*\n * hasClickToShow: does the given hoverData have ANY annotations which will\n * turn ON if we click here? (used by hover events to set cursor)\n *\n * gd: graphDiv\n * hoverData: a hoverData array, as included with the *plotly_hover* or\n *     *plotly_click* events in the `points` attribute\n *\n * returns: boolean\n */\nfunction hasClickToShow(gd, hoverData) {\n    var sets = getToggleSets(gd, hoverData);\n    return sets.on.length > 0 || sets.explicitOff.length > 0;\n}\n\n/*\n * onClick: perform the toggling (via Plotly.update) implied by clicking\n * at this hoverData\n *\n * gd: graphDiv\n * hoverData: a hoverData array, as included with the *plotly_hover* or\n *     *plotly_click* events in the `points` attribute\n *\n * returns: Promise that the update is complete\n */\nfunction onClick(gd, hoverData) {\n    var toggleSets = getToggleSets(gd, hoverData);\n    var onSet = toggleSets.on;\n    var offSet = toggleSets.off.concat(toggleSets.explicitOff);\n    var update = {};\n    var annotationsOut = gd._fullLayout.annotations;\n    var i, editHelpers;\n\n    if(!(onSet.length || offSet.length)) return;\n\n    for(i = 0; i < onSet.length; i++) {\n        editHelpers = arrayEditor(gd.layout, 'annotations', annotationsOut[onSet[i]]);\n        editHelpers.modifyItem('visible', true);\n        Lib.extendFlat(update, editHelpers.getUpdateObj());\n    }\n\n    for(i = 0; i < offSet.length; i++) {\n        editHelpers = arrayEditor(gd.layout, 'annotations', annotationsOut[offSet[i]]);\n        editHelpers.modifyItem('visible', false);\n        Lib.extendFlat(update, editHelpers.getUpdateObj());\n    }\n\n    return Registry.call('update', gd, {}, update);\n}\n\n/*\n * getToggleSets: find the annotations which will turn on or off at this\n * hoverData\n *\n * gd: graphDiv\n * hoverData: a hoverData array, as included with the *plotly_hover* or\n *     *plotly_click* events in the `points` attribute\n *\n * returns: {\n *   on: Array (indices of annotations to turn on),\n *   off: Array (indices to turn off because you're not hovering on them),\n *   explicitOff: Array (indices to turn off because you *are* hovering on them)\n * }\n */\nfunction getToggleSets(gd, hoverData) {\n    var annotations = gd._fullLayout.annotations;\n    var onSet = [];\n    var offSet = [];\n    var explicitOffSet = [];\n    var hoverLen = (hoverData || []).length;\n\n    var i, j, anni, showMode, pointj, xa, ya, toggleType;\n\n    for(i = 0; i < annotations.length; i++) {\n        anni = annotations[i];\n        showMode = anni.clicktoshow;\n\n        if(showMode) {\n            for(j = 0; j < hoverLen; j++) {\n                pointj = hoverData[j];\n                xa = pointj.xaxis;\n                ya = pointj.yaxis;\n\n                if(xa._id === anni.xref &&\n                    ya._id === anni.yref &&\n                    xa.d2r(pointj.x) === clickData2r(anni._xclick, xa) &&\n                    ya.d2r(pointj.y) === clickData2r(anni._yclick, ya)\n                ) {\n                    // match! toggle this annotation\n                    // regardless of its clicktoshow mode\n                    // but if it's onout mode, off is implicit\n                    if(anni.visible) {\n                        if(showMode === 'onout') toggleType = offSet;\n                        else toggleType = explicitOffSet;\n                    } else {\n                        toggleType = onSet;\n                    }\n                    toggleType.push(i);\n                    break;\n                }\n            }\n\n            if(j === hoverLen) {\n                // no match - only turn this annotation OFF, and only if\n                // showmode is 'onout'\n                if(anni.visible && showMode === 'onout') offSet.push(i);\n            }\n        }\n    }\n\n    return {on: onSet, off: offSet, explicitOff: explicitOffSet};\n}\n\n// to handle log axes until v2\nfunction clickData2r(d, ax) {\n    return ax.type === 'log' ? ax.l2r(d) : ax.d2r(d);\n}\n\n},{\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../registry\":847}],579:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../color');\n\n// defaults common to 'annotations' and 'annotations3d'\nmodule.exports = function handleAnnotationCommonDefaults(annIn, annOut, fullLayout, coerce) {\n    coerce('opacity');\n    var bgColor = coerce('bgcolor');\n\n    var borderColor = coerce('bordercolor');\n    var borderOpacity = Color.opacity(borderColor);\n\n    coerce('borderpad');\n\n    var borderWidth = coerce('borderwidth');\n    var showArrow = coerce('showarrow');\n\n    coerce('text', showArrow ? ' ' : fullLayout._dfltTitle.annotation);\n    coerce('textangle');\n    Lib.coerceFont(coerce, 'font', fullLayout.font);\n\n    coerce('width');\n    coerce('align');\n\n    var h = coerce('height');\n    if(h) coerce('valign');\n\n    if(showArrow) {\n        var arrowside = coerce('arrowside');\n        var arrowhead;\n        var arrowsize;\n\n        if(arrowside.indexOf('end') !== -1) {\n            arrowhead = coerce('arrowhead');\n            arrowsize = coerce('arrowsize');\n        }\n\n        if(arrowside.indexOf('start') !== -1) {\n            coerce('startarrowhead', arrowhead);\n            coerce('startarrowsize', arrowsize);\n        }\n        coerce('arrowcolor', borderOpacity ? annOut.bordercolor : Color.defaultLine);\n        coerce('arrowwidth', ((borderOpacity && borderWidth) || 1) * 2);\n        coerce('standoff');\n        coerce('startstandoff');\n    }\n\n    var hoverText = coerce('hovertext');\n    var globalHoverLabel = fullLayout.hoverlabel || {};\n\n    if(hoverText) {\n        var hoverBG = coerce('hoverlabel.bgcolor', globalHoverLabel.bgcolor ||\n            (Color.opacity(bgColor) ? Color.rgb(bgColor) : Color.defaultLine)\n        );\n\n        var hoverBorder = coerce('hoverlabel.bordercolor', globalHoverLabel.bordercolor ||\n            Color.contrast(hoverBG)\n        );\n\n        Lib.coerceFont(coerce, 'hoverlabel.font', {\n            family: globalHoverLabel.font.family,\n            size: globalHoverLabel.font.size,\n            color: globalHoverLabel.font.color || hoverBorder\n        });\n    }\n\n    coerce('captureevents', !!hoverText);\n};\n\n},{\"../../lib\":719,\"../color\":593}],580:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar toLogRange = _dereq_('../../lib/to_log_range');\n\n/*\n * convertCoords: when converting an axis between log and linear\n * you need to alter any annotations on that axis to keep them\n * pointing at the same data point.\n * In v2.0 this will become obsolete\n *\n * gd: the plot div\n * ax: the axis being changed\n * newType: the type it's getting\n * doExtra: function(attr, val) from inside relayout that sets the attribute.\n *     Use this to make the changes as it's aware if any other changes in the\n *     same relayout call should override this conversion.\n */\nmodule.exports = function convertCoords(gd, ax, newType, doExtra) {\n    ax = ax || {};\n\n    var toLog = (newType === 'log') && (ax.type === 'linear');\n    var fromLog = (newType === 'linear') && (ax.type === 'log');\n\n    if(!(toLog || fromLog)) return;\n\n    var annotations = gd._fullLayout.annotations;\n    var axLetter = ax._id.charAt(0);\n    var ann;\n    var attrPrefix;\n\n    function convert(attr) {\n        var currentVal = ann[attr];\n        var newVal = null;\n\n        if(toLog) newVal = toLogRange(currentVal, ax.range);\n        else newVal = Math.pow(10, currentVal);\n\n        // if conversion failed, delete the value so it gets a default value\n        if(!isNumeric(newVal)) newVal = null;\n\n        doExtra(attrPrefix + attr, newVal);\n    }\n\n    for(var i = 0; i < annotations.length; i++) {\n        ann = annotations[i];\n        attrPrefix = 'annotations[' + i + '].';\n\n        if(ann[axLetter + 'ref'] === ax._id) convert(axLetter);\n        if(ann['a' + axLetter + 'ref'] === ax._id) convert('a' + axLetter);\n    }\n};\n\n},{\"../../lib/to_log_range\":745,\"fast-isnumeric\":225}],581:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nvar handleAnnotationCommonDefaults = _dereq_('./common_defaults');\nvar attributes = _dereq_('./attributes');\n\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {\n    handleArrayContainerDefaults(layoutIn, layoutOut, {\n        name: 'annotations',\n        handleItemDefaults: handleAnnotationDefaults\n    });\n};\n\nfunction handleAnnotationDefaults(annIn, annOut, fullLayout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(annIn, annOut, attributes, attr, dflt);\n    }\n\n    var visible = coerce('visible');\n    var clickToShow = coerce('clicktoshow');\n\n    if(!(visible || clickToShow)) return;\n\n    handleAnnotationCommonDefaults(annIn, annOut, fullLayout, coerce);\n\n    var showArrow = annOut.showarrow;\n\n    // positioning\n    var axLetters = ['x', 'y'];\n    var arrowPosDflt = [-10, -30];\n    var gdMock = {_fullLayout: fullLayout};\n\n    for(var i = 0; i < 2; i++) {\n        var axLetter = axLetters[i];\n\n        // xref, yref\n        var axRef = Axes.coerceRef(annIn, annOut, gdMock, axLetter, '', 'paper');\n\n        if(axRef !== 'paper') {\n            var ax = Axes.getFromId(gdMock, axRef);\n            ax._annIndices.push(annOut._index);\n        }\n\n        // x, y\n        Axes.coercePosition(annOut, gdMock, coerce, axRef, axLetter, 0.5);\n\n        if(showArrow) {\n            var arrowPosAttr = 'a' + axLetter;\n            // axref, ayref\n            var aaxRef = Axes.coerceRef(annIn, annOut, gdMock, arrowPosAttr, 'pixel');\n\n            // for now the arrow can only be on the same axis or specified as pixels\n            // TODO: sometime it might be interesting to allow it to be on *any* axis\n            // but that would require updates to drawing & autorange code and maybe more\n            if(aaxRef !== 'pixel' && aaxRef !== axRef) {\n                aaxRef = annOut[arrowPosAttr] = 'pixel';\n            }\n\n            // ax, ay\n            var aDflt = (aaxRef === 'pixel') ? arrowPosDflt[i] : 0.4;\n            Axes.coercePosition(annOut, gdMock, coerce, aaxRef, arrowPosAttr, aDflt);\n        }\n\n        // xanchor, yanchor\n        coerce(axLetter + 'anchor');\n\n        // xshift, yshift\n        coerce(axLetter + 'shift');\n    }\n\n    // if you have one coordinate you should have both\n    Lib.noneOrAll(annIn, annOut, ['x', 'y']);\n\n    // if you have one part of arrow length you should have both\n    if(showArrow) {\n        Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);\n    }\n\n    if(clickToShow) {\n        var xClick = coerce('xclick');\n        var yClick = coerce('yclick');\n\n        // put the actual click data to bind to into private attributes\n        // so we don't have to do this little bit of logic on every hover event\n        annOut._xclick = (xClick === undefined) ?\n            annOut.x :\n            Axes.cleanPosition(xClick, gdMock, annOut.xref);\n        annOut._yclick = (yClick === undefined) ?\n            annOut.y :\n            Axes.cleanPosition(yClick, gdMock, annOut.yref);\n    }\n}\n\n},{\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"../../plots/cartesian/axes\":767,\"./attributes\":576,\"./common_defaults\":579}],582:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Registry = _dereq_('../../registry');\nvar Plots = _dereq_('../../plots/plots');\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Color = _dereq_('../color');\nvar Drawing = _dereq_('../drawing');\nvar Fx = _dereq_('../fx');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar setCursor = _dereq_('../../lib/setcursor');\nvar dragElement = _dereq_('../dragelement');\nvar arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;\n\nvar drawArrowHead = _dereq_('./draw_arrow_head');\n\n// Annotations are stored in gd.layout.annotations, an array of objects\n// index can point to one item in this array,\n//  or non-numeric to simply add a new one\n//  or -1 to modify all existing\n// opt can be the full options object, or one key (to be set to value)\n//  or undefined to simply redraw\n// if opt is blank, val can be 'add' or a full options object to add a new\n//  annotation at that point in the array, or 'remove' to delete this one\n\nmodule.exports = {\n    draw: draw,\n    drawOne: drawOne,\n    drawRaw: drawRaw\n};\n\n/*\n * draw: draw all annotations without any new modifications\n */\nfunction draw(gd) {\n    var fullLayout = gd._fullLayout;\n\n    fullLayout._infolayer.selectAll('.annotation').remove();\n\n    for(var i = 0; i < fullLayout.annotations.length; i++) {\n        if(fullLayout.annotations[i].visible) {\n            drawOne(gd, i);\n        }\n    }\n\n    return Plots.previousPromises(gd);\n}\n\n/*\n * drawOne: draw a single cartesian or paper-ref annotation, potentially with modifications\n *\n * index (int): the annotation to draw\n */\nfunction drawOne(gd, index) {\n    var fullLayout = gd._fullLayout;\n    var options = fullLayout.annotations[index] || {};\n    var xa = Axes.getFromId(gd, options.xref);\n    var ya = Axes.getFromId(gd, options.yref);\n\n    if(xa) xa.setScale();\n    if(ya) ya.setScale();\n\n    drawRaw(gd, options, index, false, xa, ya);\n}\n\n/**\n * drawRaw: draw a single annotation, potentially with modifications\n *\n * @param {DOM element} gd\n * @param {object} options : this annotation's fullLayout options\n * @param {integer} index : index in 'annotations' container of the annotation to draw\n * @param {string} subplotId : id of the annotation's subplot\n *  - use false for 2d (i.e. cartesian or paper-ref) annotations\n * @param {object | undefined} xa : full x-axis object to compute subplot pos-to-px\n * @param {object | undefined} ya : ... y-axis\n */\nfunction drawRaw(gd, options, index, subplotId, xa, ya) {\n    var fullLayout = gd._fullLayout;\n    var gs = gd._fullLayout._size;\n    var edits = gd._context.edits;\n\n    var className, containerStr;\n\n    if(subplotId) {\n        className = 'annotation-' + subplotId;\n        containerStr = subplotId + '.annotations';\n    } else {\n        className = 'annotation';\n        containerStr = 'annotations';\n    }\n\n    var editHelpers = arrayEditor(gd.layout, containerStr, options);\n    var modifyBase = editHelpers.modifyBase;\n    var modifyItem = editHelpers.modifyItem;\n    var getUpdateObj = editHelpers.getUpdateObj;\n\n    // remove the existing annotation if there is one\n    fullLayout._infolayer\n        .selectAll('.' + className + '[data-index=\"' + index + '\"]')\n        .remove();\n\n    var annClipID = 'clip' + fullLayout._uid + '_ann' + index;\n\n    // this annotation is gone - quit now after deleting it\n    // TODO: use d3 idioms instead of deleting and redrawing every time\n    if(!options._input || options.visible === false) {\n        d3.selectAll('#' + annClipID).remove();\n        return;\n    }\n\n    // calculated pixel positions\n    // x & y each will get text, head, and tail as appropriate\n    var annPosPx = {x: {}, y: {}};\n    var textangle = +options.textangle || 0;\n\n    // create the components\n    // made a single group to contain all, so opacity can work right\n    // with border/arrow together this could handle a whole bunch of\n    // cleanup at this point, but works for now\n    var annGroup = fullLayout._infolayer.append('g')\n        .classed(className, true)\n        .attr('data-index', String(index))\n        .style('opacity', options.opacity);\n\n    // another group for text+background so that they can rotate together\n    var annTextGroup = annGroup.append('g')\n        .classed('annotation-text-g', true);\n\n    var editTextPosition = edits[options.showarrow ? 'annotationTail' : 'annotationPosition'];\n    var textEvents = options.captureevents || edits.annotationText || editTextPosition;\n\n    function makeEventData(initialEvent) {\n        var eventData = {\n            index: index,\n            annotation: options._input,\n            fullAnnotation: options,\n            event: initialEvent\n        };\n        if(subplotId) {\n            eventData.subplotId = subplotId;\n        }\n        return eventData;\n    }\n\n    var annTextGroupInner = annTextGroup.append('g')\n        .style('pointer-events', textEvents ? 'all' : null)\n        .call(setCursor, 'pointer')\n        .on('click', function() {\n            gd._dragging = false;\n            gd.emit('plotly_clickannotation', makeEventData(d3.event));\n        });\n\n    if(options.hovertext) {\n        annTextGroupInner\n        .on('mouseover', function() {\n            var hoverOptions = options.hoverlabel;\n            var hoverFont = hoverOptions.font;\n            var bBox = this.getBoundingClientRect();\n            var bBoxRef = gd.getBoundingClientRect();\n\n            Fx.loneHover({\n                x0: bBox.left - bBoxRef.left,\n                x1: bBox.right - bBoxRef.left,\n                y: (bBox.top + bBox.bottom) / 2 - bBoxRef.top,\n                text: options.hovertext,\n                color: hoverOptions.bgcolor,\n                borderColor: hoverOptions.bordercolor,\n                fontFamily: hoverFont.family,\n                fontSize: hoverFont.size,\n                fontColor: hoverFont.color\n            }, {\n                container: fullLayout._hoverlayer.node(),\n                outerContainer: fullLayout._paper.node(),\n                gd: gd\n            });\n        })\n        .on('mouseout', function() {\n            Fx.loneUnhover(fullLayout._hoverlayer.node());\n        });\n    }\n\n    var borderwidth = options.borderwidth;\n    var borderpad = options.borderpad;\n    var borderfull = borderwidth + borderpad;\n\n    var annTextBG = annTextGroupInner.append('rect')\n        .attr('class', 'bg')\n        .style('stroke-width', borderwidth + 'px')\n        .call(Color.stroke, options.bordercolor)\n        .call(Color.fill, options.bgcolor);\n\n    var isSizeConstrained = options.width || options.height;\n\n    var annTextClip = fullLayout._topclips\n        .selectAll('#' + annClipID)\n        .data(isSizeConstrained ? [0] : []);\n\n    annTextClip.enter().append('clipPath')\n        .classed('annclip', true)\n        .attr('id', annClipID)\n      .append('rect');\n    annTextClip.exit().remove();\n\n    var font = options.font;\n\n    var text = fullLayout._meta ?\n        Lib.templateString(options.text, fullLayout._meta) :\n        options.text;\n\n    var annText = annTextGroupInner.append('text')\n        .classed('annotation-text', true)\n        .text(text);\n\n    function textLayout(s) {\n        s.call(Drawing.font, font)\n        .attr({\n            'text-anchor': {\n                left: 'start',\n                right: 'end'\n            }[options.align] || 'middle'\n        });\n\n        svgTextUtils.convertToTspans(s, gd, drawGraphicalElements);\n        return s;\n    }\n\n    function drawGraphicalElements() {\n        // if the text has *only* a link, make the whole box into a link\n        var anchor3 = annText.selectAll('a');\n        if(anchor3.size() === 1 && anchor3.text() === annText.text()) {\n            var wholeLink = annTextGroupInner.insert('a', ':first-child').attr({\n                'xlink:xlink:href': anchor3.attr('xlink:href'),\n                'xlink:xlink:show': anchor3.attr('xlink:show')\n            })\n            .style({cursor: 'pointer'});\n\n            wholeLink.node().appendChild(annTextBG.node());\n        }\n\n        var mathjaxGroup = annTextGroupInner.select('.annotation-text-math-group');\n        var hasMathjax = !mathjaxGroup.empty();\n        var anntextBB = Drawing.bBox(\n                (hasMathjax ? mathjaxGroup : annText).node());\n        var textWidth = anntextBB.width;\n        var textHeight = anntextBB.height;\n        var annWidth = options.width || textWidth;\n        var annHeight = options.height || textHeight;\n        var outerWidth = Math.round(annWidth + 2 * borderfull);\n        var outerHeight = Math.round(annHeight + 2 * borderfull);\n\n        function shiftFraction(v, anchor) {\n            if(anchor === 'auto') {\n                if(v < 1 / 3) anchor = 'left';\n                else if(v > 2 / 3) anchor = 'right';\n                else anchor = 'center';\n            }\n            return {\n                center: 0,\n                middle: 0,\n                left: 0.5,\n                bottom: -0.5,\n                right: -0.5,\n                top: 0.5\n            }[anchor];\n        }\n\n        var annotationIsOffscreen = false;\n        var letters = ['x', 'y'];\n\n        for(var i = 0; i < letters.length; i++) {\n            var axLetter = letters[i];\n            var axRef = options[axLetter + 'ref'] || axLetter;\n            var tailRef = options['a' + axLetter + 'ref'];\n            var ax = {x: xa, y: ya}[axLetter];\n            var dimAngle = (textangle + (axLetter === 'x' ? 0 : -90)) * Math.PI / 180;\n            // note that these two can be either positive or negative\n            var annSizeFromWidth = outerWidth * Math.cos(dimAngle);\n            var annSizeFromHeight = outerHeight * Math.sin(dimAngle);\n            // but this one is the positive total size\n            var annSize = Math.abs(annSizeFromWidth) + Math.abs(annSizeFromHeight);\n            var anchor = options[axLetter + 'anchor'];\n            var overallShift = options[axLetter + 'shift'] * (axLetter === 'x' ? 1 : -1);\n            var posPx = annPosPx[axLetter];\n            var basePx;\n            var textPadShift;\n            var alignPosition;\n            var autoAlignFraction;\n            var textShift;\n\n            /*\n             * calculate the *primary* pixel position\n             * which is the arrowhead if there is one,\n             * otherwise the text anchor point\n             */\n            if(ax) {\n                // check if annotation is off screen, to bypass DOM manipulations\n                var posFraction = ax.r2fraction(options[axLetter]);\n                if(posFraction < 0 || posFraction > 1) {\n                    if(tailRef === axRef) {\n                        posFraction = ax.r2fraction(options['a' + axLetter]);\n                        if(posFraction < 0 || posFraction > 1) {\n                            annotationIsOffscreen = true;\n                        }\n                    } else {\n                        annotationIsOffscreen = true;\n                    }\n                }\n                basePx = ax._offset + ax.r2p(options[axLetter]);\n                autoAlignFraction = 0.5;\n            } else {\n                if(axLetter === 'x') {\n                    alignPosition = options[axLetter];\n                    basePx = gs.l + gs.w * alignPosition;\n                } else {\n                    alignPosition = 1 - options[axLetter];\n                    basePx = gs.t + gs.h * alignPosition;\n                }\n                autoAlignFraction = options.showarrow ? 0.5 : alignPosition;\n            }\n\n            // now translate this into pixel positions of head, tail, and text\n            // as well as paddings for autorange\n            if(options.showarrow) {\n                posPx.head = basePx;\n\n                var arrowLength = options['a' + axLetter];\n\n                // with an arrow, the text rotates around the anchor point\n                textShift = annSizeFromWidth * shiftFraction(0.5, options.xanchor) -\n                    annSizeFromHeight * shiftFraction(0.5, options.yanchor);\n\n                if(tailRef === axRef) {\n                    posPx.tail = ax._offset + ax.r2p(arrowLength);\n                    // tail is data-referenced: autorange pads the text in px from the tail\n                    textPadShift = textShift;\n                } else {\n                    posPx.tail = basePx + arrowLength;\n                    // tail is specified in px from head, so autorange also pads vs head\n                    textPadShift = textShift + arrowLength;\n                }\n\n                posPx.text = posPx.tail + textShift;\n\n                // constrain pixel/paper referenced so the draggers are at least\n                // partially visible\n                var maxPx = fullLayout[(axLetter === 'x') ? 'width' : 'height'];\n                if(axRef === 'paper') {\n                    posPx.head = Lib.constrain(posPx.head, 1, maxPx - 1);\n                }\n                if(tailRef === 'pixel') {\n                    var shiftPlus = -Math.max(posPx.tail - 3, posPx.text);\n                    var shiftMinus = Math.min(posPx.tail + 3, posPx.text) - maxPx;\n                    if(shiftPlus > 0) {\n                        posPx.tail += shiftPlus;\n                        posPx.text += shiftPlus;\n                    } else if(shiftMinus > 0) {\n                        posPx.tail -= shiftMinus;\n                        posPx.text -= shiftMinus;\n                    }\n                }\n\n                posPx.tail += overallShift;\n                posPx.head += overallShift;\n            } else {\n                // with no arrow, the text rotates and *then* we put the anchor\n                // relative to the new bounding box\n                textShift = annSize * shiftFraction(autoAlignFraction, anchor);\n                textPadShift = textShift;\n                posPx.text = basePx + textShift;\n            }\n\n            posPx.text += overallShift;\n            textShift += overallShift;\n            textPadShift += overallShift;\n\n            // padplus/minus are used by autorange\n            options['_' + axLetter + 'padplus'] = (annSize / 2) + textPadShift;\n            options['_' + axLetter + 'padminus'] = (annSize / 2) - textPadShift;\n\n            // size/shift are used during dragging\n            options['_' + axLetter + 'size'] = annSize;\n            options['_' + axLetter + 'shift'] = textShift;\n        }\n\n        // We have everything we need for calcAutorange at this point,\n        // we can safely exit - unless we're currently dragging the plot\n        if(!gd._dragging && annotationIsOffscreen) {\n            annTextGroupInner.remove();\n            return;\n        }\n\n        var xShift = 0;\n        var yShift = 0;\n\n        if(options.align !== 'left') {\n            xShift = (annWidth - textWidth) * (options.align === 'center' ? 0.5 : 1);\n        }\n        if(options.valign !== 'top') {\n            yShift = (annHeight - textHeight) * (options.valign === 'middle' ? 0.5 : 1);\n        }\n\n        if(hasMathjax) {\n            mathjaxGroup.select('svg').attr({\n                x: borderfull + xShift - 1,\n                y: borderfull + yShift\n            })\n            .call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null, gd);\n        } else {\n            var texty = borderfull + yShift - anntextBB.top;\n            var textx = borderfull + xShift - anntextBB.left;\n\n            annText.call(svgTextUtils.positionText, textx, texty)\n                .call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null, gd);\n        }\n\n        annTextClip.select('rect').call(Drawing.setRect, borderfull, borderfull,\n            annWidth, annHeight);\n\n        annTextBG.call(Drawing.setRect, borderwidth / 2, borderwidth / 2,\n            outerWidth - borderwidth, outerHeight - borderwidth);\n\n        annTextGroupInner.call(Drawing.setTranslate,\n            Math.round(annPosPx.x.text - outerWidth / 2),\n            Math.round(annPosPx.y.text - outerHeight / 2));\n\n        /*\n         * rotate text and background\n         * we already calculated the text center position *as rotated*\n         * because we needed that for autoranging anyway, so now whether\n         * we have an arrow or not, we rotate about the text center.\n         */\n        annTextGroup.attr({transform: 'rotate(' + textangle + ',' +\n                            annPosPx.x.text + ',' + annPosPx.y.text + ')'});\n\n        /*\n         * add the arrow\n         * uses options[arrowwidth,arrowcolor,arrowhead] for styling\n         * dx and dy are normally zero, but when you are dragging the textbox\n         * while the head stays put, dx and dy are the pixel offsets\n         */\n        var drawArrow = function(dx, dy) {\n            annGroup\n                .selectAll('.annotation-arrow-g')\n                .remove();\n\n            var headX = annPosPx.x.head;\n            var headY = annPosPx.y.head;\n            var tailX = annPosPx.x.tail + dx;\n            var tailY = annPosPx.y.tail + dy;\n            var textX = annPosPx.x.text + dx;\n            var textY = annPosPx.y.text + dy;\n\n            // find the edge of the text box, where we'll start the arrow:\n            // create transform matrix to rotate the text box corners\n            var transform = Lib.rotationXYMatrix(textangle, textX, textY);\n            var applyTransform = Lib.apply2DTransform(transform);\n            var applyTransform2 = Lib.apply2DTransform2(transform);\n\n            // calculate and transform bounding box\n            var width = +annTextBG.attr('width');\n            var height = +annTextBG.attr('height');\n            var xLeft = textX - 0.5 * width;\n            var xRight = xLeft + width;\n            var yTop = textY - 0.5 * height;\n            var yBottom = yTop + height;\n            var edges = [\n                [xLeft, yTop, xLeft, yBottom],\n                [xLeft, yBottom, xRight, yBottom],\n                [xRight, yBottom, xRight, yTop],\n                [xRight, yTop, xLeft, yTop]\n            ].map(applyTransform2);\n\n            // Remove the line if it ends inside the box.  Use ray\n            // casting for rotated boxes: see which edges intersect a\n            // line from the arrowhead to far away and reduce with xor\n            // to get the parity of the number of intersections.\n            if(edges.reduce(function(a, x) {\n                return a ^\n                    !!Lib.segmentsIntersect(headX, headY, headX + 1e6, headY + 1e6,\n                            x[0], x[1], x[2], x[3]);\n            }, false)) {\n                // no line or arrow - so quit drawArrow now\n                return;\n            }\n\n            edges.forEach(function(x) {\n                var p = Lib.segmentsIntersect(tailX, tailY, headX, headY,\n                            x[0], x[1], x[2], x[3]);\n                if(p) {\n                    tailX = p.x;\n                    tailY = p.y;\n                }\n            });\n\n            var strokewidth = options.arrowwidth;\n            var arrowColor = options.arrowcolor;\n            var arrowSide = options.arrowside;\n\n            var arrowGroup = annGroup.append('g')\n                .style({opacity: Color.opacity(arrowColor)})\n                .classed('annotation-arrow-g', true);\n\n            var arrow = arrowGroup.append('path')\n                .attr('d', 'M' + tailX + ',' + tailY + 'L' + headX + ',' + headY)\n                .style('stroke-width', strokewidth + 'px')\n                .call(Color.stroke, Color.rgb(arrowColor));\n\n            drawArrowHead(arrow, arrowSide, options);\n\n            // the arrow dragger is a small square right at the head, then a line to the tail,\n            // all expanded by a stroke width of 6px plus the arrow line width\n            if(edits.annotationPosition && arrow.node().parentNode && !subplotId) {\n                var arrowDragHeadX = headX;\n                var arrowDragHeadY = headY;\n                if(options.standoff) {\n                    var arrowLength = Math.sqrt(Math.pow(headX - tailX, 2) + Math.pow(headY - tailY, 2));\n                    arrowDragHeadX += options.standoff * (tailX - headX) / arrowLength;\n                    arrowDragHeadY += options.standoff * (tailY - headY) / arrowLength;\n                }\n                var arrowDrag = arrowGroup.append('path')\n                    .classed('annotation-arrow', true)\n                    .classed('anndrag', true)\n                    .classed('cursor-move', true)\n                    .attr({\n                        d: 'M3,3H-3V-3H3ZM0,0L' + (tailX - arrowDragHeadX) + ',' + (tailY - arrowDragHeadY),\n                        transform: 'translate(' + arrowDragHeadX + ',' + arrowDragHeadY + ')'\n                    })\n                    .style('stroke-width', (strokewidth + 6) + 'px')\n                    .call(Color.stroke, 'rgba(0,0,0,0)')\n                    .call(Color.fill, 'rgba(0,0,0,0)');\n\n                var annx0, anny0;\n\n                // dragger for the arrow & head: translates the whole thing\n                // (head/tail/text) all together\n                dragElement.init({\n                    element: arrowDrag.node(),\n                    gd: gd,\n                    prepFn: function() {\n                        var pos = Drawing.getTranslate(annTextGroupInner);\n\n                        annx0 = pos.x;\n                        anny0 = pos.y;\n                        if(xa && xa.autorange) {\n                            modifyBase(xa._name + '.autorange', true);\n                        }\n                        if(ya && ya.autorange) {\n                            modifyBase(ya._name + '.autorange', true);\n                        }\n                    },\n                    moveFn: function(dx, dy) {\n                        var annxy0 = applyTransform(annx0, anny0);\n                        var xcenter = annxy0[0] + dx;\n                        var ycenter = annxy0[1] + dy;\n                        annTextGroupInner.call(Drawing.setTranslate, xcenter, ycenter);\n\n                        modifyItem('x', xa ?\n                            xa.p2r(xa.r2p(options.x) + dx) :\n                            (options.x + (dx / gs.w)));\n                        modifyItem('y', ya ?\n                            ya.p2r(ya.r2p(options.y) + dy) :\n                            (options.y - (dy / gs.h)));\n\n                        if(options.axref === options.xref) {\n                            modifyItem('ax', xa.p2r(xa.r2p(options.ax) + dx));\n                        }\n\n                        if(options.ayref === options.yref) {\n                            modifyItem('ay', ya.p2r(ya.r2p(options.ay) + dy));\n                        }\n\n                        arrowGroup.attr('transform', 'translate(' + dx + ',' + dy + ')');\n                        annTextGroup.attr({\n                            transform: 'rotate(' + textangle + ',' +\n                                   xcenter + ',' + ycenter + ')'\n                        });\n                    },\n                    doneFn: function() {\n                        Registry.call('_guiRelayout', gd, getUpdateObj());\n                        var notesBox = document.querySelector('.js-notes-box-panel');\n                        if(notesBox) notesBox.redraw(notesBox.selectedObj);\n                    }\n                });\n            }\n        };\n\n        if(options.showarrow) drawArrow(0, 0);\n\n        // user dragging the annotation (text, not arrow)\n        if(editTextPosition) {\n            var baseTextTransform;\n\n            // dragger for the textbox: if there's an arrow, just drag the\n            // textbox and tail, leave the head untouched\n            dragElement.init({\n                element: annTextGroupInner.node(),\n                gd: gd,\n                prepFn: function() {\n                    baseTextTransform = annTextGroup.attr('transform');\n                },\n                moveFn: function(dx, dy) {\n                    var csr = 'pointer';\n                    if(options.showarrow) {\n                        if(options.axref === options.xref) {\n                            modifyItem('ax', xa.p2r(xa.r2p(options.ax) + dx));\n                        } else {\n                            modifyItem('ax', options.ax + dx);\n                        }\n\n                        if(options.ayref === options.yref) {\n                            modifyItem('ay', ya.p2r(ya.r2p(options.ay) + dy));\n                        } else {\n                            modifyItem('ay', options.ay + dy);\n                        }\n\n                        drawArrow(dx, dy);\n                    } else if(!subplotId) {\n                        var xUpdate, yUpdate;\n                        if(xa) {\n                            xUpdate = xa.p2r(xa.r2p(options.x) + dx);\n                        } else {\n                            var widthFraction = options._xsize / gs.w;\n                            var xLeft = options.x + (options._xshift - options.xshift) / gs.w - widthFraction / 2;\n\n                            xUpdate = dragElement.align(xLeft + dx / gs.w,\n                                widthFraction, 0, 1, options.xanchor);\n                        }\n\n                        if(ya) {\n                            yUpdate = ya.p2r(ya.r2p(options.y) + dy);\n                        } else {\n                            var heightFraction = options._ysize / gs.h;\n                            var yBottom = options.y - (options._yshift + options.yshift) / gs.h - heightFraction / 2;\n\n                            yUpdate = dragElement.align(yBottom - dy / gs.h,\n                                heightFraction, 0, 1, options.yanchor);\n                        }\n                        modifyItem('x', xUpdate);\n                        modifyItem('y', yUpdate);\n                        if(!xa || !ya) {\n                            csr = dragElement.getCursor(\n                                xa ? 0.5 : xUpdate,\n                                ya ? 0.5 : yUpdate,\n                                options.xanchor, options.yanchor\n                            );\n                        }\n                    } else return;\n\n                    annTextGroup.attr({\n                        transform: 'translate(' + dx + ',' + dy + ')' + baseTextTransform\n                    });\n\n                    setCursor(annTextGroupInner, csr);\n                },\n                clickFn: function(_, initialEvent) {\n                    if(options.captureevents) {\n                        gd.emit('plotly_clickannotation', makeEventData(initialEvent));\n                    }\n                },\n                doneFn: function() {\n                    setCursor(annTextGroupInner);\n                    Registry.call('_guiRelayout', gd, getUpdateObj());\n                    var notesBox = document.querySelector('.js-notes-box-panel');\n                    if(notesBox) notesBox.redraw(notesBox.selectedObj);\n                }\n            });\n        }\n    }\n\n    if(edits.annotationText) {\n        annText.call(svgTextUtils.makeEditable, {delegate: annTextGroupInner, gd: gd})\n            .call(textLayout)\n            .on('edit', function(_text) {\n                options.text = _text;\n\n                this.call(textLayout);\n\n                modifyItem('text', _text);\n\n                if(xa && xa.autorange) {\n                    modifyBase(xa._name + '.autorange', true);\n                }\n                if(ya && ya.autorange) {\n                    modifyBase(ya._name + '.autorange', true);\n                }\n\n                Registry.call('_guiRelayout', gd, getUpdateObj());\n            });\n    } else annText.call(textLayout);\n}\n\n},{\"../../lib\":719,\"../../lib/setcursor\":739,\"../../lib/svg_text_utils\":743,\"../../plot_api/plot_template\":757,\"../../plots/cartesian/axes\":767,\"../../plots/plots\":828,\"../../registry\":847,\"../color\":593,\"../dragelement\":611,\"../drawing\":614,\"../fx\":632,\"./draw_arrow_head\":583,\"d3\":163}],583:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Color = _dereq_('../color');\n\nvar ARROWPATHS = _dereq_('./arrow_paths');\n\n/**\n * Add arrowhead(s) to a path or line element\n *\n * @param {d3.selection} el3: a d3-selected line or path element\n *\n * @param {string} ends: 'none', 'start', 'end', or 'start+end' for which ends get arrowheads\n *\n * @param {object} options: style information. Must have all the following:\n * @param {number} options.arrowhead: end head style - see ./arrow_paths\n * @param {number} options.startarrowhead: start head style - see ./arrow_paths\n * @param {number} options.arrowsize: relative size of the end head vs line width\n * @param {number} options.startarrowsize: relative size of the start head vs line width\n * @param {number} options.standoff: distance in px to move the end arrow point from its target\n * @param {number} options.startstandoff: distance in px to move the start arrow point from its target\n * @param {number} options.arrowwidth: width of the arrow line\n * @param {string} options.arrowcolor: color of the arrow line, for the head to match\n *     Note that the opacity of this color is ignored, as it's assumed the container\n *     of both the line and head has opacity applied to it so there isn't greater opacity\n *     where they overlap.\n */\nmodule.exports = function drawArrowHead(el3, ends, options) {\n    var el = el3.node();\n    var headStyle = ARROWPATHS[options.arrowhead || 0];\n    var startHeadStyle = ARROWPATHS[options.startarrowhead || 0];\n    var scale = (options.arrowwidth || 1) * (options.arrowsize || 1);\n    var startScale = (options.arrowwidth || 1) * (options.startarrowsize || 1);\n    var doStart = ends.indexOf('start') >= 0;\n    var doEnd = ends.indexOf('end') >= 0;\n    var backOff = headStyle.backoff * scale + options.standoff;\n    var startBackOff = startHeadStyle.backoff * startScale + options.startstandoff;\n\n    var start, end, startRot, endRot;\n\n    if(el.nodeName === 'line') {\n        start = {x: +el3.attr('x1'), y: +el3.attr('y1')};\n        end = {x: +el3.attr('x2'), y: +el3.attr('y2')};\n\n        var dx = start.x - end.x;\n        var dy = start.y - end.y;\n\n        startRot = Math.atan2(dy, dx);\n        endRot = startRot + Math.PI;\n        if(backOff && startBackOff) {\n            if(backOff + startBackOff > Math.sqrt(dx * dx + dy * dy)) {\n                hideLine();\n                return;\n            }\n        }\n\n        if(backOff) {\n            if(backOff * backOff > dx * dx + dy * dy) {\n                hideLine();\n                return;\n            }\n            var backOffX = backOff * Math.cos(startRot);\n            var backOffY = backOff * Math.sin(startRot);\n\n            end.x += backOffX;\n            end.y += backOffY;\n            el3.attr({x2: end.x, y2: end.y});\n        }\n\n        if(startBackOff) {\n            if(startBackOff * startBackOff > dx * dx + dy * dy) {\n                hideLine();\n                return;\n            }\n            var startBackOffX = startBackOff * Math.cos(startRot);\n            var startbackOffY = startBackOff * Math.sin(startRot);\n\n            start.x -= startBackOffX;\n            start.y -= startbackOffY;\n            el3.attr({x1: start.x, y1: start.y});\n        }\n    } else if(el.nodeName === 'path') {\n        var pathlen = el.getTotalLength();\n        // using dash to hide the backOff region of the path.\n        // if we ever allow dash for the arrow we'll have to\n        // do better than this hack... maybe just manually\n        // combine the two\n        var dashArray = '';\n\n        if(pathlen < backOff + startBackOff) {\n            hideLine();\n            return;\n        }\n\n\n        var start0 = el.getPointAtLength(0);\n        var dstart = el.getPointAtLength(0.1);\n\n        startRot = Math.atan2(start0.y - dstart.y, start0.x - dstart.x);\n        start = el.getPointAtLength(Math.min(startBackOff, pathlen));\n\n        dashArray = '0px,' + startBackOff + 'px,';\n\n        var end0 = el.getPointAtLength(pathlen);\n        var dend = el.getPointAtLength(pathlen - 0.1);\n\n        endRot = Math.atan2(end0.y - dend.y, end0.x - dend.x);\n        end = el.getPointAtLength(Math.max(0, pathlen - backOff));\n\n        var shortening = dashArray ? startBackOff + backOff : backOff;\n        dashArray += (pathlen - shortening) + 'px,' + pathlen + 'px';\n\n        el3.style('stroke-dasharray', dashArray);\n    }\n\n    function hideLine() { el3.style('stroke-dasharray', '0px,100px'); }\n\n    function drawhead(arrowHeadStyle, p, rot, arrowScale) {\n        if(!arrowHeadStyle.path) return;\n        if(arrowHeadStyle.noRotate) rot = 0;\n\n        d3.select(el.parentNode).append('path')\n            .attr({\n                'class': el3.attr('class'),\n                d: arrowHeadStyle.path,\n                transform:\n                    'translate(' + p.x + ',' + p.y + ')' +\n                    (rot ? 'rotate(' + (rot * 180 / Math.PI) + ')' : '') +\n                    'scale(' + arrowScale + ')'\n            })\n            .style({\n                fill: Color.rgb(options.arrowcolor),\n                'stroke-width': 0\n            });\n    }\n\n    if(doStart) drawhead(startHeadStyle, start, startRot, startScale);\n    if(doEnd) drawhead(headStyle, end, endRot, scale);\n};\n\n},{\"../color\":593,\"./arrow_paths\":575,\"d3\":163}],584:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar drawModule = _dereq_('./draw');\nvar clickModule = _dereq_('./click');\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'annotations',\n\n    layoutAttributes: _dereq_('./attributes'),\n    supplyLayoutDefaults: _dereq_('./defaults'),\n    includeBasePlot: _dereq_('../../plots/cartesian/include_components')('annotations'),\n\n    calcAutorange: _dereq_('./calc_autorange'),\n    draw: drawModule.draw,\n    drawOne: drawModule.drawOne,\n    drawRaw: drawModule.drawRaw,\n\n    hasClickToShow: clickModule.hasClickToShow,\n    onClick: clickModule.onClick,\n\n    convertCoords: _dereq_('./convert_coords')\n};\n\n},{\"../../plots/cartesian/include_components\":777,\"./attributes\":576,\"./calc_autorange\":577,\"./click\":578,\"./convert_coords\":580,\"./defaults\":581,\"./draw\":582}],585:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar annAtts = _dereq_('../annotations/attributes');\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\nmodule.exports = overrideAll(templatedArray('annotation', {\n    visible: annAtts.visible,\n    x: {\n        valType: 'any',\n        \n        \n    },\n    y: {\n        valType: 'any',\n        \n        \n    },\n    z: {\n        valType: 'any',\n        \n        \n    },\n    ax: {\n        valType: 'number',\n        \n        \n    },\n    ay: {\n        valType: 'number',\n        \n        \n    },\n\n    xanchor: annAtts.xanchor,\n    xshift: annAtts.xshift,\n    yanchor: annAtts.yanchor,\n    yshift: annAtts.yshift,\n\n    text: annAtts.text,\n    textangle: annAtts.textangle,\n    font: annAtts.font,\n    width: annAtts.width,\n    height: annAtts.height,\n    opacity: annAtts.opacity,\n    align: annAtts.align,\n    valign: annAtts.valign,\n    bgcolor: annAtts.bgcolor,\n    bordercolor: annAtts.bordercolor,\n    borderpad: annAtts.borderpad,\n    borderwidth: annAtts.borderwidth,\n    showarrow: annAtts.showarrow,\n    arrowcolor: annAtts.arrowcolor,\n    arrowhead: annAtts.arrowhead,\n    startarrowhead: annAtts.startarrowhead,\n    arrowside: annAtts.arrowside,\n    arrowsize: annAtts.arrowsize,\n    startarrowsize: annAtts.startarrowsize,\n    arrowwidth: annAtts.arrowwidth,\n    standoff: annAtts.standoff,\n    startstandoff: annAtts.startstandoff,\n    hovertext: annAtts.hovertext,\n    hoverlabel: annAtts.hoverlabel,\n    captureevents: annAtts.captureevents,\n\n    // maybes later?\n    // clicktoshow: annAtts.clicktoshow,\n    // xclick: annAtts.xclick,\n    // yclick: annAtts.yclick,\n\n    // not needed!\n    // axref: 'pixel'\n    // ayref: 'pixel'\n    // xref: 'x'\n    // yref: 'y\n    // zref: 'z'\n}), 'calc', 'from-root');\n\n},{\"../../plot_api/edit_types\":750,\"../../plot_api/plot_template\":757,\"../annotations/attributes\":576}],586:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nmodule.exports = function convert(scene) {\n    var fullSceneLayout = scene.fullSceneLayout;\n    var anns = fullSceneLayout.annotations;\n\n    for(var i = 0; i < anns.length; i++) {\n        mockAnnAxes(anns[i], scene);\n    }\n\n    scene.fullLayout._infolayer\n        .selectAll('.annotation-' + scene.id)\n        .remove();\n};\n\nfunction mockAnnAxes(ann, scene) {\n    var fullSceneLayout = scene.fullSceneLayout;\n    var domain = fullSceneLayout.domain;\n    var size = scene.fullLayout._size;\n\n    var base = {\n        // this gets fill in on render\n        pdata: null,\n\n        // to get setConvert to not execute cleanly\n        type: 'linear',\n\n        // don't try to update them on `editable: true`\n        autorange: false,\n\n        // set infinite range so that annotation draw routine\n        // does not try to remove 'outside-range' annotations,\n        // this case is handled in the render loop\n        range: [-Infinity, Infinity]\n    };\n\n    ann._xa = {};\n    Lib.extendFlat(ann._xa, base);\n    Axes.setConvert(ann._xa);\n    ann._xa._offset = size.l + domain.x[0] * size.w;\n    ann._xa.l2p = function() {\n        return 0.5 * (1 + ann._pdata[0] / ann._pdata[3]) * size.w * (domain.x[1] - domain.x[0]);\n    };\n\n    ann._ya = {};\n    Lib.extendFlat(ann._ya, base);\n    Axes.setConvert(ann._ya);\n    ann._ya._offset = size.t + (1 - domain.y[1]) * size.h;\n    ann._ya.l2p = function() {\n        return 0.5 * (1 - ann._pdata[1] / ann._pdata[3]) * size.h * (domain.y[1] - domain.y[0]);\n    };\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767}],587:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\nvar handleAnnotationCommonDefaults = _dereq_('../annotations/common_defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function handleDefaults(sceneLayoutIn, sceneLayoutOut, opts) {\n    handleArrayContainerDefaults(sceneLayoutIn, sceneLayoutOut, {\n        name: 'annotations',\n        handleItemDefaults: handleAnnotationDefaults,\n        fullLayout: opts.fullLayout\n    });\n};\n\nfunction handleAnnotationDefaults(annIn, annOut, sceneLayout, opts) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(annIn, annOut, attributes, attr, dflt);\n    }\n\n    function coercePosition(axLetter) {\n        var axName = axLetter + 'axis';\n\n        // mock in such way that getFromId grabs correct 3D axis\n        var gdMock = { _fullLayout: {} };\n        gdMock._fullLayout[axName] = sceneLayout[axName];\n\n        return Axes.coercePosition(annOut, gdMock, coerce, axLetter, axLetter, 0.5);\n    }\n\n\n    var visible = coerce('visible');\n    if(!visible) return;\n\n    handleAnnotationCommonDefaults(annIn, annOut, opts.fullLayout, coerce);\n\n    coercePosition('x');\n    coercePosition('y');\n    coercePosition('z');\n\n    // if you have one coordinate you should all three\n    Lib.noneOrAll(annIn, annOut, ['x', 'y', 'z']);\n\n    // hard-set here for completeness\n    annOut.xref = 'x';\n    annOut.yref = 'y';\n    annOut.zref = 'z';\n\n    coerce('xanchor');\n    coerce('yanchor');\n    coerce('xshift');\n    coerce('yshift');\n\n    if(annOut.showarrow) {\n        annOut.axref = 'pixel';\n        annOut.ayref = 'pixel';\n\n        // TODO maybe default values should be bigger than the 2D case?\n        coerce('ax', -10);\n        coerce('ay', -30);\n\n        // if you have one part of arrow length you should have both\n        Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);\n    }\n}\n\n},{\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"../../plots/cartesian/axes\":767,\"../annotations/common_defaults\":579,\"./attributes\":585}],588:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar drawRaw = _dereq_('../annotations/draw').drawRaw;\nvar project = _dereq_('../../plots/gl3d/project');\nvar axLetters = ['x', 'y', 'z'];\n\nmodule.exports = function draw(scene) {\n    var fullSceneLayout = scene.fullSceneLayout;\n    var dataScale = scene.dataScale;\n    var anns = fullSceneLayout.annotations;\n\n    for(var i = 0; i < anns.length; i++) {\n        var ann = anns[i];\n        var annotationIsOffscreen = false;\n\n        for(var j = 0; j < 3; j++) {\n            var axLetter = axLetters[j];\n            var pos = ann[axLetter];\n            var ax = fullSceneLayout[axLetter + 'axis'];\n            var posFraction = ax.r2fraction(pos);\n\n            if(posFraction < 0 || posFraction > 1) {\n                annotationIsOffscreen = true;\n                break;\n            }\n        }\n\n        if(annotationIsOffscreen) {\n            scene.fullLayout._infolayer\n                .select('.annotation-' + scene.id + '[data-index=\"' + i + '\"]')\n                .remove();\n        } else {\n            ann._pdata = project(scene.glplot.cameraParams, [\n                fullSceneLayout.xaxis.r2l(ann.x) * dataScale[0],\n                fullSceneLayout.yaxis.r2l(ann.y) * dataScale[1],\n                fullSceneLayout.zaxis.r2l(ann.z) * dataScale[2]\n            ]);\n\n            drawRaw(scene.graphDiv, ann, i, scene.id, ann._xa, ann._ya);\n        }\n    }\n};\n\n},{\"../../plots/gl3d/project\":816,\"../annotations/draw\":582}],589:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'annotations3d',\n\n    schema: {\n        subplots: {\n            scene: {annotations: _dereq_('./attributes')}\n        }\n    },\n\n    layoutAttributes: _dereq_('./attributes'),\n    handleDefaults: _dereq_('./defaults'),\n    includeBasePlot: includeGL3D,\n\n    convert: _dereq_('./convert'),\n    draw: _dereq_('./draw')\n};\n\nfunction includeGL3D(layoutIn, layoutOut) {\n    var GL3D = Registry.subplotsRegistry.gl3d;\n    if(!GL3D) return;\n\n    var attrRegex = GL3D.attrRegex;\n\n    var keys = Object.keys(layoutIn);\n    for(var i = 0; i < keys.length; i++) {\n        var k = keys[i];\n        if(attrRegex.test(k) && (layoutIn[k].annotations || []).length) {\n            Lib.pushUnique(layoutOut._basePlotModules, GL3D);\n            Lib.pushUnique(layoutOut._subplots.gl3d, k);\n        }\n    }\n}\n\n},{\"../../lib\":719,\"../../registry\":847,\"./attributes\":585,\"./convert\":586,\"./defaults\":587,\"./draw\":588}],590:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// a trimmed down version of:\n// https://github.com/alexcjohnson/world-calendars/blob/master/dist/index.js\n\nmodule.exports = _dereq_('world-calendars/dist/main');\n\n_dereq_('world-calendars/dist/plus');\n\n_dereq_('world-calendars/dist/calendars/chinese');\n_dereq_('world-calendars/dist/calendars/coptic');\n_dereq_('world-calendars/dist/calendars/discworld');\n_dereq_('world-calendars/dist/calendars/ethiopian');\n_dereq_('world-calendars/dist/calendars/hebrew');\n_dereq_('world-calendars/dist/calendars/islamic');\n_dereq_('world-calendars/dist/calendars/julian');\n_dereq_('world-calendars/dist/calendars/mayan');\n_dereq_('world-calendars/dist/calendars/nanakshahi');\n_dereq_('world-calendars/dist/calendars/nepali');\n_dereq_('world-calendars/dist/calendars/persian');\n_dereq_('world-calendars/dist/calendars/taiwan');\n_dereq_('world-calendars/dist/calendars/thai');\n_dereq_('world-calendars/dist/calendars/ummalqura');\n\n},{\"world-calendars/dist/calendars/chinese\":557,\"world-calendars/dist/calendars/coptic\":558,\"world-calendars/dist/calendars/discworld\":559,\"world-calendars/dist/calendars/ethiopian\":560,\"world-calendars/dist/calendars/hebrew\":561,\"world-calendars/dist/calendars/islamic\":562,\"world-calendars/dist/calendars/julian\":563,\"world-calendars/dist/calendars/mayan\":564,\"world-calendars/dist/calendars/nanakshahi\":565,\"world-calendars/dist/calendars/nepali\":566,\"world-calendars/dist/calendars/persian\":567,\"world-calendars/dist/calendars/taiwan\":568,\"world-calendars/dist/calendars/thai\":569,\"world-calendars/dist/calendars/ummalqura\":570,\"world-calendars/dist/main\":571,\"world-calendars/dist/plus\":572}],591:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar calendars = _dereq_('./calendars');\n\nvar Lib = _dereq_('../../lib');\nvar constants = _dereq_('../../constants/numerical');\n\nvar EPOCHJD = constants.EPOCHJD;\nvar ONEDAY = constants.ONEDAY;\n\nvar attributes = {\n    valType: 'enumerated',\n    values: Object.keys(calendars.calendars),\n    \n    editType: 'calc',\n    dflt: 'gregorian'\n};\n\nvar handleDefaults = function(contIn, contOut, attr, dflt) {\n    var attrs = {};\n    attrs[attr] = attributes;\n\n    return Lib.coerce(contIn, contOut, attrs, attr, dflt);\n};\n\nvar handleTraceDefaults = function(traceIn, traceOut, coords, layout) {\n    for(var i = 0; i < coords.length; i++) {\n        handleDefaults(traceIn, traceOut, coords[i] + 'calendar', layout.calendar);\n    }\n};\n\n// each calendar needs its own default canonical tick. I would love to use\n// 2000-01-01 (or even 0000-01-01) for them all but they don't necessarily\n// all support either of those dates. Instead I'll use the most significant\n// number they *do* support, biased toward the present day.\nvar CANONICAL_TICK = {\n    chinese: '2000-01-01',\n    coptic: '2000-01-01',\n    discworld: '2000-01-01',\n    ethiopian: '2000-01-01',\n    hebrew: '5000-01-01',\n    islamic: '1000-01-01',\n    julian: '2000-01-01',\n    mayan: '5000-01-01',\n    nanakshahi: '1000-01-01',\n    nepali: '2000-01-01',\n    persian: '1000-01-01',\n    jalali: '1000-01-01',\n    taiwan: '1000-01-01',\n    thai: '2000-01-01',\n    ummalqura: '1400-01-01'\n};\n\n// Start on a Sunday - for week ticks\n// Discworld and Mayan calendars don't have 7-day weeks but we're going to give them\n// 7-day week ticks so start on our Sundays.\n// If anyone really cares we can customize the auto tick spacings for these calendars.\nvar CANONICAL_SUNDAY = {\n    chinese: '2000-01-02',\n    coptic: '2000-01-03',\n    discworld: '2000-01-03',\n    ethiopian: '2000-01-05',\n    hebrew: '5000-01-01',\n    islamic: '1000-01-02',\n    julian: '2000-01-03',\n    mayan: '5000-01-01',\n    nanakshahi: '1000-01-05',\n    nepali: '2000-01-05',\n    persian: '1000-01-01',\n    jalali: '1000-01-01',\n    taiwan: '1000-01-04',\n    thai: '2000-01-04',\n    ummalqura: '1400-01-06'\n};\n\nvar DFLTRANGE = {\n    chinese: ['2000-01-01', '2001-01-01'],\n    coptic: ['1700-01-01', '1701-01-01'],\n    discworld: ['1800-01-01', '1801-01-01'],\n    ethiopian: ['2000-01-01', '2001-01-01'],\n    hebrew: ['5700-01-01', '5701-01-01'],\n    islamic: ['1400-01-01', '1401-01-01'],\n    julian: ['2000-01-01', '2001-01-01'],\n    mayan: ['5200-01-01', '5201-01-01'],\n    nanakshahi: ['0500-01-01', '0501-01-01'],\n    nepali: ['2000-01-01', '2001-01-01'],\n    persian: ['1400-01-01', '1401-01-01'],\n    jalali: ['1400-01-01', '1401-01-01'],\n    taiwan: ['0100-01-01', '0101-01-01'],\n    thai: ['2500-01-01', '2501-01-01'],\n    ummalqura: ['1400-01-01', '1401-01-01']\n};\n\n/*\n * convert d3 templates to world-calendars templates, so our users only need\n * to know d3's specifiers. Map space padding to no padding, and unknown fields\n * to an ugly placeholder\n */\nvar UNKNOWN = '##';\nvar d3ToWorldCalendars = {\n    'd': {'0': 'dd', '-': 'd'}, // 2-digit or unpadded day of month\n    'e': {'0': 'd', '-': 'd'}, // alternate, always unpadded day of month\n    'a': {'0': 'D', '-': 'D'}, // short weekday name\n    'A': {'0': 'DD', '-': 'DD'}, // full weekday name\n    'j': {'0': 'oo', '-': 'o'}, // 3-digit or unpadded day of the year\n    'W': {'0': 'ww', '-': 'w'}, // 2-digit or unpadded week of the year (Monday first)\n    'm': {'0': 'mm', '-': 'm'}, // 2-digit or unpadded month number\n    'b': {'0': 'M', '-': 'M'}, // short month name\n    'B': {'0': 'MM', '-': 'MM'}, // full month name\n    'y': {'0': 'yy', '-': 'yy'}, // 2-digit year (map unpadded to zero-padded)\n    'Y': {'0': 'yyyy', '-': 'yyyy'}, // 4-digit year (map unpadded to zero-padded)\n    'U': UNKNOWN, // Sunday-first week of the year\n    'w': UNKNOWN, // day of the week [0(sunday),6]\n    // combined format, we replace the date part with the world-calendar version\n    // and the %X stays there for d3 to handle with time parts\n    'c': {'0': 'D M d %X yyyy', '-': 'D M d %X yyyy'},\n    'x': {'0': 'mm/dd/yyyy', '-': 'mm/dd/yyyy'}\n};\n\nfunction worldCalFmt(fmt, x, calendar) {\n    var dateJD = Math.floor((x + 0.05) / ONEDAY) + EPOCHJD;\n    var cDate = getCal(calendar).fromJD(dateJD);\n    var i = 0;\n    var modifier, directive, directiveLen, directiveObj, replacementPart;\n\n    while((i = fmt.indexOf('%', i)) !== -1) {\n        modifier = fmt.charAt(i + 1);\n        if(modifier === '0' || modifier === '-' || modifier === '_') {\n            directiveLen = 3;\n            directive = fmt.charAt(i + 2);\n            if(modifier === '_') modifier = '-';\n        } else {\n            directive = modifier;\n            modifier = '0';\n            directiveLen = 2;\n        }\n        directiveObj = d3ToWorldCalendars[directive];\n        if(!directiveObj) {\n            i += directiveLen;\n        } else {\n            // code is recognized as a date part but world-calendars doesn't support it\n            if(directiveObj === UNKNOWN) replacementPart = UNKNOWN;\n\n            // format the cDate according to the translated directive\n            else replacementPart = cDate.formatDate(directiveObj[modifier]);\n\n            fmt = fmt.substr(0, i) + replacementPart + fmt.substr(i + directiveLen);\n            i += replacementPart.length;\n        }\n    }\n    return fmt;\n}\n\n// cache world calendars, so we don't have to reinstantiate\n// during each date-time conversion\nvar allCals = {};\nfunction getCal(calendar) {\n    var calendarObj = allCals[calendar];\n    if(calendarObj) return calendarObj;\n\n    calendarObj = allCals[calendar] = calendars.instance(calendar);\n    return calendarObj;\n}\n\nfunction makeAttrs(description) {\n    return Lib.extendFlat({}, attributes, { description: description });\n}\n\nfunction makeTraceAttrsDescription(coord) {\n    return 'Sets the calendar system to use with `' + coord + '` date data.';\n}\n\nvar xAttrs = {\n    xcalendar: makeAttrs(makeTraceAttrsDescription('x'))\n};\n\nvar xyAttrs = Lib.extendFlat({}, xAttrs, {\n    ycalendar: makeAttrs(makeTraceAttrsDescription('y'))\n});\n\nvar xyzAttrs = Lib.extendFlat({}, xyAttrs, {\n    zcalendar: makeAttrs(makeTraceAttrsDescription('z'))\n});\n\nvar axisAttrs = makeAttrs([\n    'Sets the calendar system to use for `range` and `tick0`',\n    'if this is a date axis. This does not set the calendar for',\n    'interpreting data on this axis, that\\'s specified in the trace',\n    'or via the global `layout.calendar`'\n].join(' '));\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'calendars',\n\n    schema: {\n        traces: {\n            scatter: xyAttrs,\n            bar: xyAttrs,\n            box: xyAttrs,\n            heatmap: xyAttrs,\n            contour: xyAttrs,\n            histogram: xyAttrs,\n            histogram2d: xyAttrs,\n            histogram2dcontour: xyAttrs,\n            scatter3d: xyzAttrs,\n            surface: xyzAttrs,\n            mesh3d: xyzAttrs,\n            scattergl: xyAttrs,\n            ohlc: xAttrs,\n            candlestick: xAttrs\n        },\n        layout: {\n            calendar: makeAttrs([\n                'Sets the default calendar system to use for interpreting and',\n                'displaying dates throughout the plot.'\n            ].join(' '))\n        },\n        subplots: {\n            xaxis: {calendar: axisAttrs},\n            yaxis: {calendar: axisAttrs},\n            scene: {\n                xaxis: {calendar: axisAttrs},\n                // TODO: it's actually redundant to include yaxis and zaxis here\n                // because in the scene attributes these are the same object so merging\n                // into one merges into them all. However, I left them in for parity with\n                // cartesian, where yaxis is unused until we Plotschema.get() when we\n                // use its presence or absence to determine whether to delete attributes\n                // from yaxis if they only apply to x (rangeselector/rangeslider)\n                yaxis: {calendar: axisAttrs},\n                zaxis: {calendar: axisAttrs}\n            },\n            polar: {\n                radialaxis: {calendar: axisAttrs}\n            }\n        },\n        transforms: {\n            filter: {\n                valuecalendar: makeAttrs([\n                    'Sets the calendar system to use for `value`, if it is a date.'\n                ].join(' ')),\n                targetcalendar: makeAttrs([\n                    'Sets the calendar system to use for `target`, if it is an',\n                    'array of dates. If `target` is a string (eg *x*) we use the',\n                    'corresponding trace attribute (eg `xcalendar`) if it exists,',\n                    'even if `targetcalendar` is provided.'\n                ].join(' '))\n            }\n        }\n    },\n\n    layoutAttributes: attributes,\n\n    handleDefaults: handleDefaults,\n    handleTraceDefaults: handleTraceDefaults,\n\n    CANONICAL_SUNDAY: CANONICAL_SUNDAY,\n    CANONICAL_TICK: CANONICAL_TICK,\n    DFLTRANGE: DFLTRANGE,\n\n    getCal: getCal,\n    worldCalFmt: worldCalFmt\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"./calendars\":590}],592:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\n// IMPORTANT - default colors should be in hex for compatibility\nexports.defaults = [\n    '#1f77b4',  // muted blue\n    '#ff7f0e',  // safety orange\n    '#2ca02c',  // cooked asparagus green\n    '#d62728',  // brick red\n    '#9467bd',  // muted purple\n    '#8c564b',  // chestnut brown\n    '#e377c2',  // raspberry yogurt pink\n    '#7f7f7f',  // middle gray\n    '#bcbd22',  // curry yellow-green\n    '#17becf'   // blue-teal\n];\n\nexports.defaultLine = '#444';\n\nexports.lightLine = '#eee';\n\nexports.background = '#fff';\n\nexports.borderLine = '#BEC8D9';\n\n// with axis.color and Color.interp we aren't using lightLine\n// itself anymore, instead interpolating between axis.color\n// and the background color using tinycolor.mix. lightFraction\n// gives back exactly lightLine if the other colors are defaults.\nexports.lightFraction = 100 * (0xe - 0x4) / (0xf - 0x4);\n\n},{}],593:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar tinycolor = _dereq_('tinycolor2');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar color = module.exports = {};\n\nvar colorAttrs = _dereq_('./attributes');\ncolor.defaults = colorAttrs.defaults;\nvar defaultLine = color.defaultLine = colorAttrs.defaultLine;\ncolor.lightLine = colorAttrs.lightLine;\nvar background = color.background = colorAttrs.background;\n\n/*\n * tinyRGB: turn a tinycolor into an rgb string, but\n * unlike the built-in tinycolor.toRgbString this never includes alpha\n */\ncolor.tinyRGB = function(tc) {\n    var c = tc.toRgb();\n    return 'rgb(' + Math.round(c.r) + ', ' +\n        Math.round(c.g) + ', ' + Math.round(c.b) + ')';\n};\n\ncolor.rgb = function(cstr) { return color.tinyRGB(tinycolor(cstr)); };\n\ncolor.opacity = function(cstr) { return cstr ? tinycolor(cstr).getAlpha() : 0; };\n\ncolor.addOpacity = function(cstr, op) {\n    var c = tinycolor(cstr).toRgb();\n    return 'rgba(' + Math.round(c.r) + ', ' +\n        Math.round(c.g) + ', ' + Math.round(c.b) + ', ' + op + ')';\n};\n\n// combine two colors into one apparent color\n// if back has transparency or is missing,\n// color.background is assumed behind it\ncolor.combine = function(front, back) {\n    var fc = tinycolor(front).toRgb();\n    if(fc.a === 1) return tinycolor(front).toRgbString();\n\n    var bc = tinycolor(back || background).toRgb();\n    var bcflat = bc.a === 1 ? bc : {\n        r: 255 * (1 - bc.a) + bc.r * bc.a,\n        g: 255 * (1 - bc.a) + bc.g * bc.a,\n        b: 255 * (1 - bc.a) + bc.b * bc.a\n    };\n    var fcflat = {\n        r: bcflat.r * (1 - fc.a) + fc.r * fc.a,\n        g: bcflat.g * (1 - fc.a) + fc.g * fc.a,\n        b: bcflat.b * (1 - fc.a) + fc.b * fc.a\n    };\n    return tinycolor(fcflat).toRgbString();\n};\n\n/*\n * Create a color that contrasts with cstr.\n *\n * If cstr is a dark color, we lighten it; if it's light, we darken.\n *\n * If lightAmount / darkAmount are used, we adjust by these percentages,\n * otherwise we go all the way to white or black.\n */\ncolor.contrast = function(cstr, lightAmount, darkAmount) {\n    var tc = tinycolor(cstr);\n\n    if(tc.getAlpha() !== 1) tc = tinycolor(color.combine(cstr, background));\n\n    var newColor = tc.isDark() ?\n        (lightAmount ? tc.lighten(lightAmount) : background) :\n        (darkAmount ? tc.darken(darkAmount) : defaultLine);\n\n    return newColor.toString();\n};\n\ncolor.stroke = function(s, c) {\n    var tc = tinycolor(c);\n    s.style({'stroke': color.tinyRGB(tc), 'stroke-opacity': tc.getAlpha()});\n};\n\ncolor.fill = function(s, c) {\n    var tc = tinycolor(c);\n    s.style({\n        'fill': color.tinyRGB(tc),\n        'fill-opacity': tc.getAlpha()\n    });\n};\n\n// search container for colors with the deprecated rgb(fractions) format\n// and convert them to rgb(0-255 values)\ncolor.clean = function(container) {\n    if(!container || typeof container !== 'object') return;\n\n    var keys = Object.keys(container);\n    var i, j, key, val;\n\n    for(i = 0; i < keys.length; i++) {\n        key = keys[i];\n        val = container[key];\n\n        if(key.substr(key.length - 5) === 'color') {\n            // only sanitize keys that end in \"color\" or \"colorscale\"\n\n            if(Array.isArray(val)) {\n                for(j = 0; j < val.length; j++) val[j] = cleanOne(val[j]);\n            } else container[key] = cleanOne(val);\n        } else if(key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {\n            // colorscales have the format [[0, color1], [frac, color2], ... [1, colorN]]\n\n            for(j = 0; j < val.length; j++) {\n                if(Array.isArray(val[j])) val[j][1] = cleanOne(val[j][1]);\n            }\n        } else if(Array.isArray(val)) {\n            // recurse into arrays of objects, and plain objects\n\n            var el0 = val[0];\n            if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {\n                for(j = 0; j < val.length; j++) color.clean(val[j]);\n            }\n        } else if(val && typeof val === 'object') color.clean(val);\n    }\n};\n\nfunction cleanOne(val) {\n    if(isNumeric(val) || typeof val !== 'string') return val;\n\n    var valTrim = val.trim();\n    if(valTrim.substr(0, 3) !== 'rgb') return val;\n\n    var match = valTrim.match(/^rgba?\\s*\\(([^()]*)\\)$/);\n    if(!match) return val;\n\n    var parts = match[1].trim().split(/\\s*[\\s,]\\s*/);\n    var rgba = valTrim.charAt(3) === 'a' && parts.length === 4;\n    if(!rgba && parts.length !== 3) return val;\n\n    for(var i = 0; i < parts.length; i++) {\n        if(!parts[i].length) return val;\n        parts[i] = Number(parts[i]);\n\n        if(!(parts[i] >= 0)) {\n            // all parts must be non-negative numbers\n\n            return val;\n        }\n\n        if(i === 3) {\n            // alpha>1 gets clipped to 1\n\n            if(parts[i] > 1) parts[i] = 1;\n        } else if(parts[i] >= 1) {\n            // r, g, b must be < 1 (ie 1 itself is not allowed)\n\n            return val;\n        }\n    }\n\n    var rgbStr = Math.round(parts[0] * 255) + ', ' +\n        Math.round(parts[1] * 255) + ', ' +\n        Math.round(parts[2] * 255);\n\n    if(rgba) return 'rgba(' + rgbStr + ', ' + parts[3] + ')';\n    return 'rgb(' + rgbStr + ')';\n}\n\n},{\"./attributes\":592,\"fast-isnumeric\":225,\"tinycolor2\":537}],594:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar axesAttrs = _dereq_('../../plots/cartesian/layout_attributes');\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\n\nmodule.exports = overrideAll({\n// TODO: only right is supported currently\n//     orient: {\n//         valType: 'enumerated',\n//         \n//         values: ['left', 'right', 'top', 'bottom'],\n//         dflt: 'right',\n//         \n//     },\n    thicknessmode: {\n        valType: 'enumerated',\n        values: ['fraction', 'pixels'],\n        \n        dflt: 'pixels',\n        \n    },\n    thickness: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 30,\n        \n    },\n    lenmode: {\n        valType: 'enumerated',\n        values: ['fraction', 'pixels'],\n        \n        dflt: 'fraction',\n        \n    },\n    len: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        \n    },\n    x: {\n        valType: 'number',\n        dflt: 1.02,\n        min: -2,\n        max: 3,\n        \n        \n    },\n    xanchor: {\n        valType: 'enumerated',\n        values: ['left', 'center', 'right'],\n        dflt: 'left',\n        \n        \n    },\n    xpad: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 10,\n        \n    },\n    y: {\n        valType: 'number',\n        \n        dflt: 0.5,\n        min: -2,\n        max: 3,\n        \n    },\n    yanchor: {\n        valType: 'enumerated',\n        values: ['top', 'middle', 'bottom'],\n        \n        dflt: 'middle',\n        \n    },\n    ypad: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 10,\n        \n    },\n    // a possible line around the bar itself\n    outlinecolor: axesAttrs.linecolor,\n    outlinewidth: axesAttrs.linewidth,\n    // Should outlinewidth have {dflt: 0} ?\n    // another possible line outside the padding and tick labels\n    bordercolor: axesAttrs.linecolor,\n    borderwidth: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 0,\n        \n    },\n    bgcolor: {\n        valType: 'color',\n        \n        dflt: 'rgba(0,0,0,0)',\n        \n    },\n    // tick and title properties named and function exactly as in axes\n    tickmode: axesAttrs.tickmode,\n    nticks: axesAttrs.nticks,\n    tick0: axesAttrs.tick0,\n    dtick: axesAttrs.dtick,\n    tickvals: axesAttrs.tickvals,\n    ticktext: axesAttrs.ticktext,\n    ticks: extendFlat({}, axesAttrs.ticks, {dflt: ''}),\n    ticklen: axesAttrs.ticklen,\n    tickwidth: axesAttrs.tickwidth,\n    tickcolor: axesAttrs.tickcolor,\n    showticklabels: axesAttrs.showticklabels,\n    tickfont: fontAttrs({\n        \n    }),\n    tickangle: axesAttrs.tickangle,\n    tickformat: axesAttrs.tickformat,\n    tickformatstops: axesAttrs.tickformatstops,\n    tickprefix: axesAttrs.tickprefix,\n    showtickprefix: axesAttrs.showtickprefix,\n    ticksuffix: axesAttrs.ticksuffix,\n    showticksuffix: axesAttrs.showticksuffix,\n    separatethousands: axesAttrs.separatethousands,\n    exponentformat: axesAttrs.exponentformat,\n    showexponent: axesAttrs.showexponent,\n    title: {\n        text: {\n            valType: 'string',\n            \n            \n        },\n        font: fontAttrs({\n            \n        }),\n        side: {\n            valType: 'enumerated',\n            values: ['right', 'top', 'bottom'],\n            \n            dflt: 'top',\n            \n        }\n    },\n\n    _deprecated: {\n        title: {\n            valType: 'string',\n            \n            \n        },\n        titlefont: fontAttrs({\n            \n        }),\n        titleside: {\n            valType: 'enumerated',\n            values: ['right', 'top', 'bottom'],\n            \n            dflt: 'top',\n            \n        }\n    }\n}, 'colorbars', 'from-root');\n\n},{\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/cartesian/layout_attributes\":779,\"../../plots/font_attributes\":793}],595:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    cn: {\n        colorbar: 'colorbar',\n        cbbg: 'cbbg',\n        cbfill: 'cbfill',\n        cbfills: 'cbfills',\n        cbline: 'cbline',\n        cblines: 'cblines',\n        cbaxis: 'cbaxis',\n        cbtitleunshift: 'cbtitleunshift',\n        cbtitle: 'cbtitle',\n        cboutline: 'cboutline',\n        crisp: 'crisp',\n        jsPlaceholder: 'js-placeholder'\n    }\n};\n\n},{}],596:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Template = _dereq_('../../plot_api/plot_template');\n\nvar handleTickValueDefaults = _dereq_('../../plots/cartesian/tick_value_defaults');\nvar handleTickMarkDefaults = _dereq_('../../plots/cartesian/tick_mark_defaults');\nvar handleTickLabelDefaults = _dereq_('../../plots/cartesian/tick_label_defaults');\n\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function colorbarDefaults(containerIn, containerOut, layout) {\n    var colorbarOut = Template.newContainer(containerOut, 'colorbar');\n    var colorbarIn = containerIn.colorbar || {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(colorbarIn, colorbarOut, attributes, attr, dflt);\n    }\n\n    var thicknessmode = coerce('thicknessmode');\n    coerce('thickness', (thicknessmode === 'fraction') ?\n        30 / (layout.width - layout.margin.l - layout.margin.r) :\n        30\n    );\n\n    var lenmode = coerce('lenmode');\n    coerce('len', (lenmode === 'fraction') ?\n        1 :\n        layout.height - layout.margin.t - layout.margin.b\n    );\n\n    coerce('x');\n    coerce('xanchor');\n    coerce('xpad');\n    coerce('y');\n    coerce('yanchor');\n    coerce('ypad');\n    Lib.noneOrAll(colorbarIn, colorbarOut, ['x', 'y']);\n\n    coerce('outlinecolor');\n    coerce('outlinewidth');\n    coerce('bordercolor');\n    coerce('borderwidth');\n    coerce('bgcolor');\n\n    handleTickValueDefaults(colorbarIn, colorbarOut, coerce, 'linear');\n\n    var opts = {outerTicks: false, font: layout.font};\n    handleTickLabelDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);\n    handleTickMarkDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);\n\n    coerce('title.text', layout._dfltTitle.colorbar);\n    Lib.coerceFont(coerce, 'title.font', layout.font);\n    coerce('title.side');\n};\n\n},{\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../plots/cartesian/tick_label_defaults\":786,\"../../plots/cartesian/tick_mark_defaults\":787,\"../../plots/cartesian/tick_value_defaults\":788,\"./attributes\":594}],597:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar tinycolor = _dereq_('tinycolor2');\n\nvar Plots = _dereq_('../../plots/plots');\nvar Registry = _dereq_('../../registry');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar dragElement = _dereq_('../dragelement');\nvar Lib = _dereq_('../../lib');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar setCursor = _dereq_('../../lib/setcursor');\nvar Drawing = _dereq_('../drawing');\nvar Color = _dereq_('../color');\nvar Titles = _dereq_('../titles');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar flipScale = _dereq_('../colorscale/helpers').flipScale;\n\nvar handleAxisDefaults = _dereq_('../../plots/cartesian/axis_defaults');\nvar handleAxisPositionDefaults = _dereq_('../../plots/cartesian/position_defaults');\nvar axisLayoutAttrs = _dereq_('../../plots/cartesian/layout_attributes');\n\nvar alignmentConstants = _dereq_('../../constants/alignment');\nvar LINE_SPACING = alignmentConstants.LINE_SPACING;\nvar FROM_TL = alignmentConstants.FROM_TL;\nvar FROM_BR = alignmentConstants.FROM_BR;\n\nvar cn = _dereq_('./constants').cn;\n\nfunction draw(gd) {\n    var fullLayout = gd._fullLayout;\n\n    var colorBars = fullLayout._infolayer\n        .selectAll('g.' + cn.colorbar)\n        .data(makeColorBarData(gd), function(opts) { return opts._id; });\n\n    colorBars.enter().append('g')\n        .attr('class', function(opts) { return opts._id; })\n        .classed(cn.colorbar, true);\n\n    colorBars.each(function(opts) {\n        var g = d3.select(this);\n\n        Lib.ensureSingle(g, 'rect', cn.cbbg);\n        Lib.ensureSingle(g, 'g', cn.cbfills);\n        Lib.ensureSingle(g, 'g', cn.cblines);\n        Lib.ensureSingle(g, 'g', cn.cbaxis, function(s) { s.classed(cn.crisp, true); });\n        Lib.ensureSingle(g, 'g', cn.cbtitleunshift, function(s) { s.append('g').classed(cn.cbtitle, true); });\n        Lib.ensureSingle(g, 'rect', cn.cboutline);\n\n        var done = drawColorBar(g, opts, gd);\n        if(done && done.then) (gd._promises || []).push(done);\n\n        if(gd._context.edits.colorbarPosition) {\n            makeEditable(g, opts, gd);\n        }\n    });\n\n    colorBars.exit()\n        .each(function(opts) { Plots.autoMargin(gd, opts._id); })\n        .remove();\n\n    colorBars.order();\n}\n\nfunction makeColorBarData(gd) {\n    var fullLayout = gd._fullLayout;\n    var calcdata = gd.calcdata;\n    var out = [];\n\n    // single out item\n    var opts;\n    // colorbar attr parent container\n    var cont;\n    // trace attr container\n    var trace;\n    // colorbar options\n    var cbOpt;\n\n    function initOpts(opts) {\n        return extendFlat(opts, {\n            // fillcolor can be a d3 scale, domain is z values, range is colors\n            // or leave it out for no fill,\n            // or set to a string constant for single-color fill\n            _fillcolor: null,\n            // line.color has the same options as fillcolor\n            _line: {color: null, width: null, dash: null},\n            // levels of lines to draw.\n            // note that this DOES NOT determine the extent of the bar\n            // that's given by the domain of fillcolor\n            // (or line.color if no fillcolor domain)\n            _levels: {start: null, end: null, size: null},\n            // separate fill levels (for example, heatmap coloring of a\n            // contour map) if this is omitted, fillcolors will be\n            // evaluated halfway between levels\n            _filllevels: null,\n            // for continuous colorscales: fill with a gradient instead of explicit levels\n            // value should be the colorscale [[0, c0], [v1, c1], ..., [1, cEnd]]\n            _fillgradient: null,\n            // when using a gradient, we need the data range specified separately\n            _zrange: null\n        });\n    }\n\n    function calcOpts() {\n        if(typeof cbOpt.calc === 'function') {\n            cbOpt.calc(gd, trace, opts);\n        } else {\n            opts._fillgradient = cont.reversescale ?\n                flipScale(cont.colorscale) :\n                cont.colorscale;\n            opts._zrange = [cont[cbOpt.min], cont[cbOpt.max]];\n        }\n    }\n\n    for(var i = 0; i < calcdata.length; i++) {\n        var cd = calcdata[i];\n        trace = cd[0].trace;\n        var moduleOpts = trace._module.colorbar;\n\n        if(trace.visible === true && moduleOpts) {\n            var allowsMultiplotCbs = Array.isArray(moduleOpts);\n            var cbOpts = allowsMultiplotCbs ? moduleOpts : [moduleOpts];\n\n            for(var j = 0; j < cbOpts.length; j++) {\n                cbOpt = cbOpts[j];\n                var contName = cbOpt.container;\n                cont = contName ? trace[contName] : trace;\n\n                if(cont && cont.showscale) {\n                    opts = initOpts(cont.colorbar);\n                    opts._id = 'cb' + trace.uid + (allowsMultiplotCbs && contName ? '-' + contName : '');\n                    opts._traceIndex = trace.index;\n                    opts._propPrefix = (contName ? contName + '.' : '') + 'colorbar.';\n                    opts._meta = trace._meta;\n                    calcOpts();\n                    out.push(opts);\n                }\n            }\n        }\n    }\n\n    for(var k in fullLayout._colorAxes) {\n        cont = fullLayout[k];\n\n        if(cont.showscale) {\n            var colorAxOpts = fullLayout._colorAxes[k];\n\n            opts = initOpts(cont.colorbar);\n            opts._id = 'cb' + k;\n            opts._propPrefix = k + '.colorbar.';\n            opts._meta = fullLayout._meta;\n\n            cbOpt = {min: 'cmin', max: 'cmax'};\n            if(colorAxOpts[0] !== 'heatmap') {\n                trace = colorAxOpts[1];\n                cbOpt.calc = trace._module.colorbar.calc;\n            }\n\n            calcOpts();\n            out.push(opts);\n        }\n    }\n\n    return out;\n}\n\nfunction drawColorBar(g, opts, gd) {\n    var fullLayout = gd._fullLayout;\n    var gs = fullLayout._size;\n\n    var fillColor = opts._fillcolor;\n    var line = opts._line;\n    var title = opts.title;\n    var titleSide = title.side;\n\n    var zrange = opts._zrange ||\n        d3.extent((typeof fillColor === 'function' ? fillColor : line.color).domain());\n\n    var lineColormap = typeof line.color === 'function' ?\n        line.color :\n        function() { return line.color; };\n    var fillColormap = typeof fillColor === 'function' ?\n        fillColor :\n        function() { return fillColor; };\n\n    var levelsIn = opts._levels;\n    var levelsOut = calcLevels(gd, opts, zrange);\n    var fillLevels = levelsOut.fill;\n    var lineLevels = levelsOut.line;\n\n    // we calculate pixel sizes based on the specified graph size,\n    // not the actual (in case something pushed the margins around)\n    // which is a little odd but avoids an odd iterative effect\n    // when the colorbar itself is pushing the margins.\n    // but then the fractional size is calculated based on the\n    // actual graph size, so that the axes will size correctly.\n    var thickPx = Math.round(opts.thickness * (opts.thicknessmode === 'fraction' ? gs.w : 1));\n    var thickFrac = thickPx / gs.w;\n    var lenPx = Math.round(opts.len * (opts.lenmode === 'fraction' ? gs.h : 1));\n    var lenFrac = lenPx / gs.h;\n    var xpadFrac = opts.xpad / gs.w;\n    var yExtraPx = (opts.borderwidth + opts.outlinewidth) / 2;\n    var ypadFrac = opts.ypad / gs.h;\n\n    // x positioning: do it initially just for left anchor,\n    // then fix at the end (since we don't know the width yet)\n    var xLeft = Math.round(opts.x * gs.w + opts.xpad);\n    // for dragging... this is getting a little muddled...\n    var xLeftFrac = opts.x - thickFrac * ({middle: 0.5, right: 1}[opts.xanchor] || 0);\n\n    // y positioning we can do correctly from the start\n    var yBottomFrac = opts.y + lenFrac * (({top: -0.5, bottom: 0.5}[opts.yanchor] || 0) - 0.5);\n    var yBottomPx = Math.round(gs.h * (1 - yBottomFrac));\n    var yTopPx = yBottomPx - lenPx;\n\n    // stash a few things for makeEditable\n    opts._lenFrac = lenFrac;\n    opts._thickFrac = thickFrac;\n    opts._xLeftFrac = xLeftFrac;\n    opts._yBottomFrac = yBottomFrac;\n\n    var ax = mockColorBarAxis(gd, opts, zrange);\n\n    // position can't go in through supplyDefaults\n    // because that restricts it to [0,1]\n    ax.position = opts.x + xpadFrac + thickFrac;\n\n    if(['top', 'bottom'].indexOf(titleSide) !== -1) {\n        ax.title.side = titleSide;\n        ax.titlex = opts.x + xpadFrac;\n        ax.titley = yBottomFrac + (title.side === 'top' ? lenFrac - ypadFrac : ypadFrac);\n    }\n\n    if(line.color && opts.tickmode === 'auto') {\n        ax.tickmode = 'linear';\n        ax.tick0 = levelsIn.start;\n        var dtick = levelsIn.size;\n        // expand if too many contours, so we don't get too many ticks\n        var autoNtick = Lib.constrain((yBottomPx - yTopPx) / 50, 4, 15) + 1;\n        var dtFactor = (zrange[1] - zrange[0]) / ((opts.nticks || autoNtick) * dtick);\n        if(dtFactor > 1) {\n            var dtexp = Math.pow(10, Math.floor(Math.log(dtFactor) / Math.LN10));\n            dtick *= dtexp * Lib.roundUp(dtFactor / dtexp, [2, 5, 10]);\n            // if the contours are at round multiples, reset tick0\n            // so they're still at round multiples. Otherwise,\n            // keep the first label on the first contour level\n            if((Math.abs(levelsIn.start) / levelsIn.size + 1e-6) % 1 < 2e-6) {\n                ax.tick0 = 0;\n            }\n        }\n        ax.dtick = dtick;\n    }\n\n    // set domain after init, because we may want to\n    // allow it outside [0,1]\n    ax.domain = [\n        yBottomFrac + ypadFrac,\n        yBottomFrac + lenFrac - ypadFrac\n    ];\n\n    ax.setScale();\n\n    g.attr('transform', 'translate(' + Math.round(gs.l) + ',' + Math.round(gs.t) + ')');\n\n    var titleCont = g.select('.' + cn.cbtitleunshift)\n        .attr('transform', 'translate(-' + Math.round(gs.l) + ',-' + Math.round(gs.t) + ')');\n\n    var axLayer = g.select('.' + cn.cbaxis);\n    var titleEl;\n    var titleHeight = 0;\n\n    function drawTitle(titleClass, titleOpts) {\n        var dfltTitleOpts = {\n            propContainer: ax,\n            propName: opts._propPrefix + 'title',\n            traceIndex: opts._traceIndex,\n            _meta: opts._meta,\n            placeholder: fullLayout._dfltTitle.colorbar,\n            containerGroup: g.select('.' + cn.cbtitle)\n        };\n\n        // this class-to-rotate thing with convertToTspans is\n        // getting hackier and hackier... delete groups with the\n        // wrong class (in case earlier the colorbar was drawn on\n        // a different side, I think?)\n        var otherClass = titleClass.charAt(0) === 'h' ?\n            titleClass.substr(1) :\n            'h' + titleClass;\n        g.selectAll('.' + otherClass + ',.' + otherClass + '-math-group').remove();\n\n        Titles.draw(gd, titleClass, extendFlat(dfltTitleOpts, titleOpts || {}));\n    }\n\n    function drawDummyTitle() {\n        if(['top', 'bottom'].indexOf(titleSide) !== -1) {\n            // draw the title so we know how much room it needs\n            // when we squish the axis. This one only applies to\n            // top or bottom titles, not right side.\n            var x = gs.l + (opts.x + xpadFrac) * gs.w;\n            var fontSize = ax.title.font.size;\n            var y;\n\n            if(titleSide === 'top') {\n                y = (1 - (yBottomFrac + lenFrac - ypadFrac)) * gs.h +\n                    gs.t + 3 + fontSize * 0.75;\n            } else {\n                y = (1 - (yBottomFrac + ypadFrac)) * gs.h +\n                    gs.t - 3 - fontSize * 0.25;\n            }\n            drawTitle(ax._id + 'title', {\n                attributes: {x: x, y: y, 'text-anchor': 'start'}\n            });\n        }\n    }\n\n    function drawCbTitle() {\n        if(['top', 'bottom'].indexOf(titleSide) === -1) {\n            var fontSize = ax.title.font.size;\n            var y = ax._offset + ax._length / 2;\n            var x = gs.l + (ax.position || 0) * gs.w + ((ax.side === 'right') ?\n                10 + fontSize * ((ax.showticklabels ? 1 : 0.5)) :\n                -10 - fontSize * ((ax.showticklabels ? 0.5 : 0)));\n\n            // the 'h' + is a hack to get around the fact that\n            // convertToTspans rotates any 'y...' class by 90 degrees.\n            // TODO: find a better way to control this.\n            drawTitle('h' + ax._id + 'title', {\n                avoid: {\n                    selection: d3.select(gd).selectAll('g.' + ax._id + 'tick'),\n                    side: titleSide,\n                    offsetLeft: gs.l,\n                    offsetTop: 0,\n                    maxShift: fullLayout.width\n                },\n                attributes: {x: x, y: y, 'text-anchor': 'middle'},\n                transform: {rotate: '-90', offset: 0}\n            });\n        }\n    }\n\n    function drawAxis() {\n        if(['top', 'bottom'].indexOf(titleSide) !== -1) {\n            // squish the axis top to make room for the title\n            var titleGroup = g.select('.' + cn.cbtitle);\n            var titleText = titleGroup.select('text');\n            var titleTrans = [-opts.outlinewidth / 2, opts.outlinewidth / 2];\n            var mathJaxNode = titleGroup\n                .select('.h' + ax._id + 'title-math-group')\n                .node();\n            var lineSize = 15.6;\n            if(titleText.node()) {\n                lineSize = parseInt(titleText.node().style.fontSize, 10) * LINE_SPACING;\n            }\n            if(mathJaxNode) {\n                titleHeight = Drawing.bBox(mathJaxNode).height;\n                if(titleHeight > lineSize) {\n                    // not entirely sure how mathjax is doing\n                    // vertical alignment, but this seems to work.\n                    titleTrans[1] -= (titleHeight - lineSize) / 2;\n                }\n            } else if(titleText.node() && !titleText.classed(cn.jsPlaceholder)) {\n                titleHeight = Drawing.bBox(titleText.node()).height;\n            }\n            if(titleHeight) {\n                // buffer btwn colorbar and title\n                // TODO: configurable\n                titleHeight += 5;\n\n                if(titleSide === 'top') {\n                    ax.domain[1] -= titleHeight / gs.h;\n                    titleTrans[1] *= -1;\n                } else {\n                    ax.domain[0] += titleHeight / gs.h;\n                    var nlines = svgTextUtils.lineCount(titleText);\n                    titleTrans[1] += (1 - nlines) * lineSize;\n                }\n\n                titleGroup.attr('transform', 'translate(' + titleTrans + ')');\n                ax.setScale();\n            }\n        }\n\n        g.selectAll('.' + cn.cbfills + ',.' + cn.cblines)\n            .attr('transform', 'translate(0,' + Math.round(gs.h * (1 - ax.domain[1])) + ')');\n\n        axLayer.attr('transform', 'translate(0,' + Math.round(-gs.t) + ')');\n\n        var fills = g.select('.' + cn.cbfills)\n            .selectAll('rect.' + cn.cbfill)\n            .data(fillLevels);\n        fills.enter().append('rect')\n            .classed(cn.cbfill, true)\n            .style('stroke', 'none');\n        fills.exit().remove();\n\n        var zBounds = zrange\n            .map(ax.c2p)\n            .map(Math.round)\n            .sort(function(a, b) { return a - b; });\n\n        fills.each(function(d, i) {\n            var z = [\n                (i === 0) ? zrange[0] : (fillLevels[i] + fillLevels[i - 1]) / 2,\n                (i === fillLevels.length - 1) ? zrange[1] : (fillLevels[i] + fillLevels[i + 1]) / 2\n            ]\n            .map(ax.c2p)\n            .map(Math.round);\n\n            // offset the side adjoining the next rectangle so they\n            // overlap, to prevent antialiasing gaps\n            z[1] = Lib.constrain(z[1] + (z[1] > z[0]) ? 1 : -1, zBounds[0], zBounds[1]);\n\n\n            // Colorbar cannot currently support opacities so we\n            // use an opaque fill even when alpha channels present\n            var fillEl = d3.select(this).attr({\n                x: xLeft,\n                width: Math.max(thickPx, 2),\n                y: d3.min(z),\n                height: Math.max(d3.max(z) - d3.min(z), 2),\n            });\n\n            if(opts._fillgradient) {\n                Drawing.gradient(fillEl, gd, opts._id, 'vertical', opts._fillgradient, 'fill');\n            } else {\n                // tinycolor can't handle exponents and\n                // at this scale, removing it makes no difference.\n                var colorString = fillColormap(d).replace('e-', '');\n                fillEl.attr('fill', tinycolor(colorString).toHexString());\n            }\n        });\n\n        var lines = g.select('.' + cn.cblines)\n            .selectAll('path.' + cn.cbline)\n            .data(line.color && line.width ? lineLevels : []);\n        lines.enter().append('path')\n            .classed(cn.cbline, true);\n        lines.exit().remove();\n        lines.each(function(d) {\n            d3.select(this)\n                .attr('d', 'M' + xLeft + ',' +\n                    (Math.round(ax.c2p(d)) + (line.width / 2) % 1) + 'h' + thickPx)\n                .call(Drawing.lineGroupStyle, line.width, lineColormap(d), line.dash);\n        });\n\n        // force full redraw of labels and ticks\n        axLayer.selectAll('g.' + ax._id + 'tick,path').remove();\n\n        var shift = xLeft + thickPx +\n            (opts.outlinewidth || 0) / 2 - (opts.ticks === 'outside' ? 1 : 0);\n\n        var vals = Axes.calcTicks(ax);\n        var transFn = Axes.makeTransFn(ax);\n        var tickSign = Axes.getTickSigns(ax)[2];\n\n        Axes.drawTicks(gd, ax, {\n            vals: ax.ticks === 'inside' ? Axes.clipEnds(ax, vals) : vals,\n            layer: axLayer,\n            path: Axes.makeTickPath(ax, shift, tickSign),\n            transFn: transFn\n        });\n\n        return Axes.drawLabels(gd, ax, {\n            vals: vals,\n            layer: axLayer,\n            transFn: transFn,\n            labelFns: Axes.makeLabelFns(ax, shift)\n        });\n    }\n\n    // wait for the axis & title to finish rendering before\n    // continuing positioning\n    // TODO: why are we redrawing multiple times now with this?\n    // I guess autoMargin doesn't like being post-promise?\n    function positionCB() {\n        var innerWidth = thickPx + opts.outlinewidth / 2 + Drawing.bBox(axLayer.node()).width;\n        titleEl = titleCont.select('text');\n\n        if(titleEl.node() && !titleEl.classed(cn.jsPlaceholder)) {\n            var mathJaxNode = titleCont.select('.h' + ax._id + 'title-math-group').node();\n            var titleWidth;\n            if(mathJaxNode && ['top', 'bottom'].indexOf(titleSide) !== -1) {\n                titleWidth = Drawing.bBox(mathJaxNode).width;\n            } else {\n                // note: the formula below works for all title sides,\n                // (except for top/bottom mathjax, above)\n                // but the weird gs.l is because the titleunshift\n                // transform gets removed by Drawing.bBox\n                titleWidth = Drawing.bBox(titleCont.node()).right - xLeft - gs.l;\n            }\n            innerWidth = Math.max(innerWidth, titleWidth);\n        }\n\n        var outerwidth = 2 * opts.xpad + innerWidth + opts.borderwidth + opts.outlinewidth / 2;\n        var outerheight = yBottomPx - yTopPx;\n\n        g.select('.' + cn.cbbg).attr({\n            x: xLeft - opts.xpad - (opts.borderwidth + opts.outlinewidth) / 2,\n            y: yTopPx - yExtraPx,\n            width: Math.max(outerwidth, 2),\n            height: Math.max(outerheight + 2 * yExtraPx, 2)\n        })\n        .call(Color.fill, opts.bgcolor)\n        .call(Color.stroke, opts.bordercolor)\n        .style('stroke-width', opts.borderwidth);\n\n        g.selectAll('.' + cn.cboutline).attr({\n            x: xLeft,\n            y: yTopPx + opts.ypad + (titleSide === 'top' ? titleHeight : 0),\n            width: Math.max(thickPx, 2),\n            height: Math.max(outerheight - 2 * opts.ypad - titleHeight, 2)\n        })\n        .call(Color.stroke, opts.outlinecolor)\n        .style({\n            fill: 'none',\n            'stroke-width': opts.outlinewidth\n        });\n\n        // fix positioning for xanchor!='left'\n        var xoffset = ({center: 0.5, right: 1}[opts.xanchor] || 0) * outerwidth;\n        g.attr('transform', 'translate(' + (gs.l - xoffset) + ',' + gs.t + ')');\n\n        // auto margin adjustment\n        var marginOpts = {};\n        var tFrac = FROM_TL[opts.yanchor];\n        var bFrac = FROM_BR[opts.yanchor];\n        if(opts.lenmode === 'pixels') {\n            marginOpts.y = opts.y;\n            marginOpts.t = outerheight * tFrac;\n            marginOpts.b = outerheight * bFrac;\n        } else {\n            marginOpts.t = marginOpts.b = 0;\n            marginOpts.yt = opts.y + opts.len * tFrac;\n            marginOpts.yb = opts.y - opts.len * bFrac;\n        }\n\n        var lFrac = FROM_TL[opts.xanchor];\n        var rFrac = FROM_BR[opts.xanchor];\n        if(opts.thicknessmode === 'pixels') {\n            marginOpts.x = opts.x;\n            marginOpts.l = outerwidth * lFrac;\n            marginOpts.r = outerwidth * rFrac;\n        } else {\n            var extraThickness = outerwidth - thickPx;\n            marginOpts.l = extraThickness * lFrac;\n            marginOpts.r = extraThickness * rFrac;\n            marginOpts.xl = opts.x - opts.thickness * lFrac;\n            marginOpts.xr = opts.x + opts.thickness * rFrac;\n        }\n\n        Plots.autoMargin(gd, opts._id, marginOpts);\n    }\n\n    return Lib.syncOrAsync([\n        Plots.previousPromises,\n        drawDummyTitle,\n        drawAxis,\n        drawCbTitle,\n        Plots.previousPromises,\n        positionCB\n    ], gd);\n}\n\nfunction makeEditable(g, opts, gd) {\n    var fullLayout = gd._fullLayout;\n    var gs = fullLayout._size;\n    var t0, xf, yf;\n\n    dragElement.init({\n        element: g.node(),\n        gd: gd,\n        prepFn: function() {\n            t0 = g.attr('transform');\n            setCursor(g);\n        },\n        moveFn: function(dx, dy) {\n            g.attr('transform', t0 + ' ' + 'translate(' + dx + ',' + dy + ')');\n\n            xf = dragElement.align(opts._xLeftFrac + (dx / gs.w), opts._thickFrac,\n                0, 1, opts.xanchor);\n            yf = dragElement.align(opts._yBottomFrac - (dy / gs.h), opts._lenFrac,\n                0, 1, opts.yanchor);\n\n            var csr = dragElement.getCursor(xf, yf, opts.xanchor, opts.yanchor);\n            setCursor(g, csr);\n        },\n        doneFn: function() {\n            setCursor(g);\n\n            if(xf !== undefined && yf !== undefined) {\n                var update = {};\n                update[opts._propPrefix + 'x'] = xf;\n                update[opts._propPrefix + 'y'] = yf;\n                if(opts._traceIndex !== undefined) {\n                    Registry.call('_guiRestyle', gd, update, opts._traceIndex);\n                } else {\n                    Registry.call('_guiRelayout', gd, update);\n                }\n            }\n        }\n    });\n}\n\nfunction calcLevels(gd, opts, zrange) {\n    var levelsIn = opts._levels;\n    var lineLevels = [];\n    var fillLevels = [];\n    var l;\n    var i;\n\n    var l0 = levelsIn.end + levelsIn.size / 100;\n    var ls = levelsIn.size;\n    var zr0 = (1.001 * zrange[0] - 0.001 * zrange[1]);\n    var zr1 = (1.001 * zrange[1] - 0.001 * zrange[0]);\n\n    for(i = 0; i < 1e5; i++) {\n        l = levelsIn.start + i * ls;\n        if(ls > 0 ? (l >= l0) : (l <= l0)) break;\n        if(l > zr0 && l < zr1) lineLevels.push(l);\n    }\n\n    if(opts._fillgradient) {\n        fillLevels = [0];\n    } else if(typeof opts._fillcolor === 'function') {\n        var fillLevelsIn = opts._filllevels;\n\n        if(fillLevelsIn) {\n            l0 = fillLevelsIn.end + fillLevelsIn.size / 100;\n            ls = fillLevelsIn.size;\n            for(i = 0; i < 1e5; i++) {\n                l = fillLevelsIn.start + i * ls;\n                if(ls > 0 ? (l >= l0) : (l <= l0)) break;\n                if(l > zrange[0] && l < zrange[1]) fillLevels.push(l);\n            }\n        } else {\n            fillLevels = lineLevels.map(function(v) {\n                return v - levelsIn.size / 2;\n            });\n            fillLevels.push(fillLevels[fillLevels.length - 1] + levelsIn.size);\n        }\n    } else if(opts._fillcolor && typeof opts._fillcolor === 'string') {\n        // doesn't matter what this value is, with a single value\n        // we'll make a single fill rect covering the whole bar\n        fillLevels = [0];\n    }\n\n    if(levelsIn.size < 0) {\n        lineLevels.reverse();\n        fillLevels.reverse();\n    }\n\n    return {line: lineLevels, fill: fillLevels};\n}\n\nfunction mockColorBarAxis(gd, opts, zrange) {\n    var fullLayout = gd._fullLayout;\n\n    var cbAxisIn = {\n        type: 'linear',\n        range: zrange,\n        tickmode: opts.tickmode,\n        nticks: opts.nticks,\n        tick0: opts.tick0,\n        dtick: opts.dtick,\n        tickvals: opts.tickvals,\n        ticktext: opts.ticktext,\n        ticks: opts.ticks,\n        ticklen: opts.ticklen,\n        tickwidth: opts.tickwidth,\n        tickcolor: opts.tickcolor,\n        showticklabels: opts.showticklabels,\n        tickfont: opts.tickfont,\n        tickangle: opts.tickangle,\n        tickformat: opts.tickformat,\n        exponentformat: opts.exponentformat,\n        separatethousands: opts.separatethousands,\n        showexponent: opts.showexponent,\n        showtickprefix: opts.showtickprefix,\n        tickprefix: opts.tickprefix,\n        showticksuffix: opts.showticksuffix,\n        ticksuffix: opts.ticksuffix,\n        title: opts.title,\n        showline: true,\n        anchor: 'free',\n        side: 'right',\n        position: 1\n    };\n\n    var cbAxisOut = {\n        type: 'linear',\n        _id: 'y' + opts._id\n    };\n\n    var axisOptions = {\n        letter: 'y',\n        font: fullLayout.font,\n        noHover: true,\n        noTickson: true,\n        calendar: fullLayout.calendar  // not really necessary (yet?)\n    };\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(cbAxisIn, cbAxisOut, axisLayoutAttrs, attr, dflt);\n    }\n\n    handleAxisDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions, fullLayout);\n    handleAxisPositionDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions);\n\n    return cbAxisOut;\n}\n\nmodule.exports = {\n    draw: draw\n};\n\n},{\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/extend\":710,\"../../lib/setcursor\":739,\"../../lib/svg_text_utils\":743,\"../../plots/cartesian/axes\":767,\"../../plots/cartesian/axis_defaults\":769,\"../../plots/cartesian/layout_attributes\":779,\"../../plots/cartesian/position_defaults\":782,\"../../plots/plots\":828,\"../../registry\":847,\"../color\":593,\"../colorscale/helpers\":604,\"../dragelement\":611,\"../drawing\":614,\"../titles\":681,\"./constants\":595,\"d3\":163,\"tinycolor2\":537}],598:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n\nmodule.exports = function hasColorbar(container) {\n    return Lib.isPlainObject(container.colorbar);\n};\n\n},{\"../../lib\":719}],599:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'colorbar',\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n\n    draw: _dereq_('./draw').draw,\n    hasColorbar: _dereq_('./has_colorbar')\n};\n\n},{\"./attributes\":594,\"./defaults\":596,\"./draw\":597,\"./has_colorbar\":598}],600:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorbarAttrs = _dereq_('../colorbar/attributes');\nvar counterRegex = _dereq_('../../lib/regex').counter;\n\nvar palettes = _dereq_('./scales.js').scales;\nvar paletteStr = Object.keys(palettes);\n\nfunction code(s) {\n    return '`' + s + '`';\n}\n\n/**\n * Make colorscale attribute declarations for\n *\n * - colorscale,\n * - (c|z)auto, (c|z)min, (c|z)max,\n * - autocolorscale, reversescale,\n * - showscale (optionally)\n * - color (optionally)\n *\n * @param {string} context (dflt: '', i.e. from trace root):\n *     the container this is in ('', *marker*, *marker.line* etc)\n *\n * @param {object} opts:\n *   - cLetter {string} (dflt: 'c'):\n *     leading letter for 'min', 'max and 'auto' attribute (either 'z' or 'c')\n *\n *   - colorAttr {string} (dflt: 'z' if `cLetter: 'z'`, 'color' if `cLetter: 'c'`):\n *     (for descriptions) sets the name of the color attribute that maps to the colorscale.\n *\n *     N.B. if `colorAttr: 'color'`, we include the `color` declaration here.\n *\n *   - onlyIfNumerical {string} (dflt: false' if `cLetter: 'z'`, true if `cLetter: 'c'`):\n *     (for descriptions) set to true if colorscale attribute only\n *\n *   - colorscaleDflt {string}:\n *     overrides the colorscale dflt\n *\n *   - autoColorDflt {boolean} (dflt true):\n *     normally autocolorscale.dflt is `true`, but pass `false` to override\n *\n *   - noScale {boolean} (dflt: true if `context: 'marker.line'`, false otherwise):\n *     set to `false` to not include showscale attribute (e.g. for 'marker.line')\n *\n *   - showScaleDflt {boolean} (dflt: true if `cLetter: 'z'`, false otherwise)\n *\n *   - editTypeOverride {boolean} (dflt: ''):\n *     most of these attributes already require a recalc, but the ones that do not\n *     have editType *style* or *plot* unless you override (presumably with *calc*)\n *\n *   - anim {boolean) (dflt: undefined): is 'color' animatable?\n *\n * @return {object}\n */\nmodule.exports = function colorScaleAttrs(context, opts) {\n    context = context || '';\n    opts = opts || {};\n\n    var cLetter = opts.cLetter || 'c';\n    var onlyIfNumerical = ('onlyIfNumerical' in opts) ? opts.onlyIfNumerical : Boolean(context);\n    var noScale = ('noScale' in opts) ? opts.noScale : context === 'marker.line';\n    var showScaleDflt = ('showScaleDflt' in opts) ? opts.showScaleDflt : cLetter === 'z';\n    var colorscaleDflt = typeof opts.colorscaleDflt === 'string' ? palettes[opts.colorscaleDflt] : null;\n    var editTypeOverride = opts.editTypeOverride || '';\n    var contextHead = context ? (context + '.') : '';\n\n    var colorAttr, colorAttrFull;\n\n    if('colorAttr' in opts) {\n        colorAttr = opts.colorAttr;\n        colorAttrFull = opts.colorAttr;\n    } else {\n        colorAttr = {z: 'z', c: 'color'}[cLetter];\n        colorAttrFull = 'in ' + code(contextHead + colorAttr);\n    }\n\n    var effectDesc = onlyIfNumerical ?\n        ' Has an effect only if ' + colorAttrFull + 'is set to a numerical array.' :\n        '';\n\n    var auto = cLetter + 'auto';\n    var min = cLetter + 'min';\n    var max = cLetter + 'max';\n    var mid = cLetter + 'mid';\n    var autoFull = code(contextHead + auto);\n    var minFull = code(contextHead + min);\n    var maxFull = code(contextHead + max);\n    var minmaxFull = minFull + ' and ' + maxFull;\n    var autoImpliedEdits = {};\n    autoImpliedEdits[min] = autoImpliedEdits[max] = undefined;\n    var minmaxImpliedEdits = {};\n    minmaxImpliedEdits[auto] = false;\n\n    var attrs = {};\n\n    if(colorAttr === 'color') {\n        attrs.color = {\n            valType: 'color',\n            arrayOk: true,\n            \n            editType: editTypeOverride || 'style',\n            \n        };\n\n        if(opts.anim) {\n            attrs.color.anim = true;\n        }\n    }\n\n    attrs[auto] = {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'calc',\n        impliedEdits: autoImpliedEdits,\n        \n    };\n\n    attrs[min] = {\n        valType: 'number',\n        \n        dflt: null,\n        editType: editTypeOverride || 'plot',\n        impliedEdits: minmaxImpliedEdits,\n        \n    };\n\n    attrs[max] = {\n        valType: 'number',\n        \n        dflt: null,\n        editType: editTypeOverride || 'plot',\n        impliedEdits: minmaxImpliedEdits,\n        \n    };\n\n    attrs[mid] = {\n        valType: 'number',\n        \n        dflt: null,\n        editType: 'calc',\n        impliedEdits: autoImpliedEdits,\n        \n    };\n\n    attrs.colorscale = {\n        valType: 'colorscale',\n        \n        editType: 'calc',\n        dflt: colorscaleDflt,\n        impliedEdits: {autocolorscale: false},\n        \n    };\n\n    attrs.autocolorscale = {\n        valType: 'boolean',\n        \n        // gets overrode in 'heatmap' & 'surface' for backwards comp.\n        dflt: opts.autoColorDflt === false ? false : true,\n        editType: 'calc',\n        impliedEdits: {colorscale: undefined},\n        \n    };\n\n    attrs.reversescale = {\n        valType: 'boolean',\n        \n        dflt: false,\n        editType: 'plot',\n        \n    };\n\n    if(!noScale) {\n        attrs.showscale = {\n            valType: 'boolean',\n            \n            dflt: showScaleDflt,\n            editType: 'calc',\n            \n        };\n\n        attrs.colorbar = colorbarAttrs;\n    }\n\n    if(!opts.noColorAxis) {\n        attrs.coloraxis = {\n            valType: 'subplotid',\n            \n            regex: counterRegex('coloraxis'),\n            dflt: null,\n            editType: 'calc',\n            \n        };\n    }\n\n    return attrs;\n};\n\n},{\"../../lib/regex\":735,\"../colorbar/attributes\":594,\"./scales.js\":608}],601:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar extractOpts = _dereq_('./helpers').extractOpts;\n\nmodule.exports = function calc(gd, trace, opts) {\n    var fullLayout = gd._fullLayout;\n    var vals = opts.vals;\n    var containerStr = opts.containerStr;\n\n    var container = containerStr ?\n        Lib.nestedProperty(trace, containerStr).get() :\n        trace;\n\n    var cOpts = extractOpts(container);\n    var auto = cOpts.auto !== false;\n    var min = cOpts.min;\n    var max = cOpts.max;\n    var mid = cOpts.mid;\n\n    var minVal = function() { return Lib.aggNums(Math.min, null, vals); };\n    var maxVal = function() { return Lib.aggNums(Math.max, null, vals); };\n\n    if(min === undefined) {\n        min = minVal();\n    } else if(auto) {\n        if(container._colorAx && isNumeric(min)) {\n            min = Math.min(min, minVal());\n        } else {\n            min = minVal();\n        }\n    }\n\n    if(max === undefined) {\n        max = maxVal();\n    } else if(auto) {\n        if(container._colorAx && isNumeric(max)) {\n            max = Math.max(max, maxVal());\n        } else {\n            max = maxVal();\n        }\n    }\n\n    if(auto && mid !== undefined) {\n        if(max - mid > mid - min) {\n            min = mid - (max - mid);\n        } else if(max - mid < mid - min) {\n            max = mid + (mid - min);\n        }\n    }\n\n    if(min === max) {\n        min -= 0.5;\n        max += 0.5;\n    }\n\n    cOpts._sync('min', min);\n    cOpts._sync('max', max);\n\n    if(cOpts.autocolorscale) {\n        var scl;\n        if(min * max < 0) scl = fullLayout.colorscale.diverging;\n        else if(min >= 0) scl = fullLayout.colorscale.sequential;\n        else scl = fullLayout.colorscale.sequentialminus;\n        cOpts._sync('colorscale', scl);\n    }\n};\n\n},{\"../../lib\":719,\"./helpers\":604,\"fast-isnumeric\":225}],602:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar hasColorscale = _dereq_('./helpers').hasColorscale;\nvar extractOpts = _dereq_('./helpers').extractOpts;\n\nmodule.exports = function crossTraceDefaults(fullData, fullLayout) {\n    function replace(cont, k) {\n        var val = cont['_' + k];\n        if(val !== undefined) {\n            cont[k] = val;\n        }\n    }\n\n    function relinkColorAtts(outerCont, cbOpt) {\n        var cont = cbOpt.container ?\n            Lib.nestedProperty(outerCont, cbOpt.container).get() :\n            outerCont;\n\n        if(cont) {\n            if(cont.coloraxis) {\n                // stash ref to color axis\n                cont._colorAx = fullLayout[cont.coloraxis];\n            } else {\n                var cOpts = extractOpts(cont);\n                var isAuto = cOpts.auto;\n\n                if(isAuto || cOpts.min === undefined) {\n                    replace(cont, cbOpt.min);\n                }\n                if(isAuto || cOpts.max === undefined) {\n                    replace(cont, cbOpt.max);\n                }\n                if(cOpts.autocolorscale) {\n                    replace(cont, 'colorscale');\n                }\n            }\n        }\n    }\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n        var cbOpts = trace._module.colorbar;\n\n        if(cbOpts) {\n            if(Array.isArray(cbOpts)) {\n                for(var j = 0; j < cbOpts.length; j++) {\n                    relinkColorAtts(trace, cbOpts[j]);\n                }\n            } else {\n                relinkColorAtts(trace, cbOpts);\n            }\n        }\n\n        if(hasColorscale(trace, 'marker.line')) {\n            relinkColorAtts(trace, {\n                container: 'marker.line',\n                min: 'cmin',\n                max: 'cmax'\n            });\n        }\n    }\n\n    for(var k in fullLayout._colorAxes) {\n        relinkColorAtts(fullLayout[k], {min: 'cmin', max: 'cmax'});\n    }\n};\n\n},{\"../../lib\":719,\"./helpers\":604}],603:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar hasColorbar = _dereq_('../colorbar/has_colorbar');\nvar colorbarDefaults = _dereq_('../colorbar/defaults');\n\nvar isValidScale = _dereq_('./scales').isValid;\nvar traceIs = _dereq_('../../registry').traceIs;\n\nfunction npMaybe(parentCont, prefix) {\n    var containerStr = prefix.slice(0, prefix.length - 1);\n    return prefix ?\n        Lib.nestedProperty(parentCont, containerStr).get() || {} :\n        parentCont;\n}\n\n/**\n * Colorscale / colorbar default handler\n *\n * @param {object} parentContIn : user (input) parent container (e.g. trace or layout coloraxis object)\n * @param {object} parentContOut : full parent container\n * @param {object} layout : (full) layout object\n * @param {fn} coerce : Lib.coerce wrapper\n * @param {object} opts :\n * - prefix {string} : attr string prefix to colorscale container from parent root\n * - cLetter {string} : 'c or 'z' color letter\n */\nmodule.exports = function colorScaleDefaults(parentContIn, parentContOut, layout, coerce, opts) {\n    var prefix = opts.prefix;\n    var cLetter = opts.cLetter;\n    var inTrace = '_module' in parentContOut;\n    var containerIn = npMaybe(parentContIn, prefix);\n    var containerOut = npMaybe(parentContOut, prefix);\n    var template = npMaybe(parentContOut._template || {}, prefix) || {};\n\n    // colorScaleDefaults wrapper called if-ever we need to reset the colorscale\n    // attributes for containers that were linked to invalid color axes\n    var thisFn = function() {\n        delete parentContIn.coloraxis;\n        delete parentContOut.coloraxis;\n        return colorScaleDefaults(parentContIn, parentContOut, layout, coerce, opts);\n    };\n\n    if(inTrace) {\n        var colorAxes = layout._colorAxes || {};\n        var colorAx = coerce(prefix + 'coloraxis');\n\n        if(colorAx) {\n            var colorbarVisuals = (\n                traceIs(parentContOut, 'contour') &&\n                Lib.nestedProperty(parentContOut, 'contours.coloring').get()\n            ) || 'heatmap';\n\n            var stash = colorAxes[colorAx];\n\n            if(stash) {\n                stash[2].push(thisFn);\n\n                if(stash[0] !== colorbarVisuals) {\n                    stash[0] = false;\n                    Lib.warn([\n                        'Ignoring coloraxis:', colorAx, 'setting',\n                        'as it is linked to incompatible colorscales.'\n                    ].join(' '));\n                }\n            } else {\n                // stash:\n                // - colorbar visual 'type'\n                // - colorbar options to help in Colorbar.draw\n                // - list of colorScaleDefaults wrapper functions\n                colorAxes[colorAx] = [colorbarVisuals, parentContOut, [thisFn]];\n            }\n            return;\n        }\n    }\n\n    var minIn = containerIn[cLetter + 'min'];\n    var maxIn = containerIn[cLetter + 'max'];\n    var validMinMax = isNumeric(minIn) && isNumeric(maxIn) && (minIn < maxIn);\n    var auto = coerce(prefix + cLetter + 'auto', !validMinMax);\n\n    if(auto) {\n        coerce(prefix + cLetter + 'mid');\n    } else {\n        coerce(prefix + cLetter + 'min');\n        coerce(prefix + cLetter + 'max');\n    }\n\n    // handles both the trace case (autocolorscale is false by default) and\n    // the marker and marker.line case (autocolorscale is true by default)\n    var sclIn = containerIn.colorscale;\n    var sclTemplate = template.colorscale;\n    var autoColorscaleDflt;\n    if(sclIn !== undefined) autoColorscaleDflt = !isValidScale(sclIn);\n    if(sclTemplate !== undefined) autoColorscaleDflt = !isValidScale(sclTemplate);\n    coerce(prefix + 'autocolorscale', autoColorscaleDflt);\n\n    coerce(prefix + 'colorscale');\n    coerce(prefix + 'reversescale');\n\n    if(prefix !== 'marker.line.') {\n        // handles both the trace case where the dflt is listed in attributes and\n        // the marker case where the dflt is determined by hasColorbar\n        var showScaleDflt;\n        if(prefix && inTrace) showScaleDflt = hasColorbar(containerIn);\n\n        var showScale = coerce(prefix + 'showscale', showScaleDflt);\n        if(showScale) colorbarDefaults(containerIn, containerOut, layout);\n    }\n};\n\n},{\"../../lib\":719,\"../../registry\":847,\"../colorbar/defaults\":596,\"../colorbar/has_colorbar\":598,\"./scales\":608,\"fast-isnumeric\":225}],604:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar tinycolor = _dereq_('tinycolor2');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../color');\n\nvar isValidScale = _dereq_('./scales').isValid;\n\nfunction hasColorscale(trace, containerStr) {\n    var container = containerStr ?\n        Lib.nestedProperty(trace, containerStr).get() || {} :\n        trace;\n    var color = container.color;\n\n    var isArrayWithOneNumber = false;\n    if(Lib.isArrayOrTypedArray(color)) {\n        for(var i = 0; i < color.length; i++) {\n            if(isNumeric(color[i])) {\n                isArrayWithOneNumber = true;\n                break;\n            }\n        }\n    }\n\n    return (\n        Lib.isPlainObject(container) && (\n            isArrayWithOneNumber ||\n            container.showscale === true ||\n            (isNumeric(container.cmin) && isNumeric(container.cmax)) ||\n            isValidScale(container.colorscale) ||\n            Lib.isPlainObject(container.colorbar)\n        )\n    );\n}\n\nvar constantAttrs = ['showscale', 'autocolorscale', 'colorscale', 'reversescale', 'colorbar'];\nvar letterAttrs = ['min', 'max', 'mid', 'auto'];\n\n/**\n * Extract 'c' / 'z', trace / color axis colorscale options\n *\n * Note that it would be nice to replace all z* with c* equivalents in v2\n *\n * @param {object} cont : attribute container\n * @return {object}:\n *  - min: cmin or zmin\n *  - max: cmax or zmax\n *  - mid: cmid or zmid\n *  - auto: cauto or zauto\n *  - *scale: *scale attrs\n *  - colorbar: colorbar\n *  - _sync: function syncing attr and underscore dual (useful when calc'ing min/max)\n */\nfunction extractOpts(cont) {\n    var colorAx = cont._colorAx;\n    var cont2 = colorAx ? colorAx : cont;\n    var out = {};\n    var cLetter;\n    var i, k;\n\n    for(i = 0; i < constantAttrs.length; i++) {\n        k = constantAttrs[i];\n        out[k] = cont2[k];\n    }\n\n    if(colorAx) {\n        cLetter = 'c';\n        for(i = 0; i < letterAttrs.length; i++) {\n            k = letterAttrs[i];\n            out[k] = cont2['c' + k];\n        }\n    } else {\n        var k2;\n        for(i = 0; i < letterAttrs.length; i++) {\n            k = letterAttrs[i];\n            k2 = 'c' + k;\n            if(k2 in cont2) {\n                out[k] = cont2[k2];\n                continue;\n            }\n            k2 = 'z' + k;\n            if(k2 in cont2) {\n                out[k] = cont2[k2];\n            }\n        }\n        cLetter = k2.charAt(0);\n    }\n\n    out._sync = function(k, v) {\n        var k2 = letterAttrs.indexOf(k) !== -1 ? cLetter + k : k;\n        cont2[k2] = cont2['_' + k2] = v;\n    };\n\n    return out;\n}\n\n/**\n * Extract colorscale into numeric domain and color range.\n *\n * @param {object} cont colorscale container (e.g. trace, marker)\n *  - colorscale {array of arrays}\n *  - cmin/zmin {number}\n *  - cmax/zmax {number}\n *  - reversescale {boolean}\n *\n * @return {object}\n *  - domain {array}\n *  - range {array}\n */\nfunction extractScale(cont) {\n    var cOpts = extractOpts(cont);\n    var cmin = cOpts.min;\n    var cmax = cOpts.max;\n\n    var scl = cOpts.reversescale ?\n        flipScale(cOpts.colorscale) :\n        cOpts.colorscale;\n\n    var N = scl.length;\n    var domain = new Array(N);\n    var range = new Array(N);\n\n    for(var i = 0; i < N; i++) {\n        var si = scl[i];\n        domain[i] = cmin + si[0] * (cmax - cmin);\n        range[i] = si[1];\n    }\n\n    return {domain: domain, range: range};\n}\n\nfunction flipScale(scl) {\n    var N = scl.length;\n    var sclNew = new Array(N);\n\n    for(var i = N - 1, j = 0; i >= 0; i--, j++) {\n        var si = scl[i];\n        sclNew[j] = [1 - si[0], si[1]];\n    }\n    return sclNew;\n}\n\n/**\n * General colorscale function generator.\n *\n * @param {object} specs output of Colorscale.extractScale or precomputed domain, range.\n *  - domain {array}\n *  - range {array}\n *\n * @param {object} opts\n *  - noNumericCheck {boolean} if true, scale func bypasses numeric checks\n *  - returnArray {boolean} if true, scale func return 4-item array instead of color strings\n *\n * @return {function}\n */\nfunction makeColorScaleFunc(specs, opts) {\n    opts = opts || {};\n\n    var domain = specs.domain;\n    var range = specs.range;\n    var N = range.length;\n    var _range = new Array(N);\n\n    for(var i = 0; i < N; i++) {\n        var rgba = tinycolor(range[i]).toRgb();\n        _range[i] = [rgba.r, rgba.g, rgba.b, rgba.a];\n    }\n\n    var _sclFunc = d3.scale.linear()\n        .domain(domain)\n        .range(_range)\n        .clamp(true);\n\n    var noNumericCheck = opts.noNumericCheck;\n    var returnArray = opts.returnArray;\n    var sclFunc;\n\n    if(noNumericCheck && returnArray) {\n        sclFunc = _sclFunc;\n    } else if(noNumericCheck) {\n        sclFunc = function(v) {\n            return colorArray2rbga(_sclFunc(v));\n        };\n    } else if(returnArray) {\n        sclFunc = function(v) {\n            if(isNumeric(v)) return _sclFunc(v);\n            else if(tinycolor(v).isValid()) return v;\n            else return Color.defaultLine;\n        };\n    } else {\n        sclFunc = function(v) {\n            if(isNumeric(v)) return colorArray2rbga(_sclFunc(v));\n            else if(tinycolor(v).isValid()) return v;\n            else return Color.defaultLine;\n        };\n    }\n\n    // colorbar draw looks into the d3 scale closure for domain and range\n    sclFunc.domain = _sclFunc.domain;\n    sclFunc.range = function() { return range; };\n\n    return sclFunc;\n}\n\nfunction makeColorScaleFuncFromTrace(trace, opts) {\n    return makeColorScaleFunc(extractScale(trace), opts);\n}\n\nfunction colorArray2rbga(colorArray) {\n    var colorObj = {\n        r: colorArray[0],\n        g: colorArray[1],\n        b: colorArray[2],\n        a: colorArray[3]\n    };\n\n    return tinycolor(colorObj).toRgbString();\n}\n\nmodule.exports = {\n    hasColorscale: hasColorscale,\n    extractOpts: extractOpts,\n    extractScale: extractScale,\n    flipScale: flipScale,\n    makeColorScaleFunc: makeColorScaleFunc,\n    makeColorScaleFuncFromTrace: makeColorScaleFuncFromTrace\n};\n\n},{\"../../lib\":719,\"../color\":593,\"./scales\":608,\"d3\":163,\"fast-isnumeric\":225,\"tinycolor2\":537}],605:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scales = _dereq_('./scales');\nvar helpers = _dereq_('./helpers');\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'colorscale',\n\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n    handleDefaults: _dereq_('./defaults'),\n    crossTraceDefaults: _dereq_('./cross_trace_defaults'),\n\n    calc: _dereq_('./calc'),\n\n    // ./scales.js is required in lib/coerce.js ;\n    // it needs to be a seperate module to avoid circular a dependency\n    scales: scales.scales,\n    defaultScale: scales.defaultScale,\n    getScale: scales.get,\n    isValidScale: scales.isValid,\n\n    hasColorscale: helpers.hasColorscale,\n    extractOpts: helpers.extractOpts,\n    extractScale: helpers.extractScale,\n    flipScale: helpers.flipScale,\n    makeColorScaleFunc: helpers.makeColorScaleFunc,\n    makeColorScaleFuncFromTrace: helpers.makeColorScaleFuncFromTrace\n};\n\n},{\"./attributes\":600,\"./calc\":601,\"./cross_trace_defaults\":602,\"./defaults\":603,\"./helpers\":604,\"./layout_attributes\":606,\"./layout_defaults\":607,\"./scales\":608}],606:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar colorScaleAttrs = _dereq_('./attributes');\nvar scales = _dereq_('./scales').scales;\n\nvar msg = 'Note that `autocolorscale` must be true for this attribute to work.';\n\nmodule.exports = {\n    editType: 'calc',\n\n    colorscale: {\n        editType: 'calc',\n\n        sequential: {\n            valType: 'colorscale',\n            dflt: scales.Reds,\n            \n            editType: 'calc',\n            \n        },\n        sequentialminus: {\n            valType: 'colorscale',\n            dflt: scales.Blues,\n            \n            editType: 'calc',\n            \n        },\n        diverging: {\n            valType: 'colorscale',\n            dflt: scales.RdBu,\n            \n            editType: 'calc',\n            \n        }\n    },\n\n    coloraxis: extendFlat({\n        // not really a 'subplot' attribute container,\n        // but this is the flag we use to denote attributes that\n        // support yaxis, yaxis2, yaxis3, ... counters\n        _isSubplotObj: true,\n        editType: 'calc',\n        \n    }, colorScaleAttrs('', {\n        colorAttr: 'corresponding trace color array(s)',\n        noColorAxis: true,\n        showScaleDflt: true\n    }))\n};\n\n},{\"../../lib/extend\":710,\"./attributes\":600,\"./scales\":608}],607:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Template = _dereq_('../../plot_api/plot_template');\n\nvar colorScaleAttrs = _dereq_('./layout_attributes');\nvar colorScaleDefaults = _dereq_('./defaults');\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, colorScaleAttrs, attr, dflt);\n    }\n\n    coerce('colorscale.sequential');\n    coerce('colorscale.sequentialminus');\n    coerce('colorscale.diverging');\n\n    var colorAxes = layoutOut._colorAxes;\n    var colorAxIn, colorAxOut;\n\n    function coerceAx(attr, dflt) {\n        return Lib.coerce(colorAxIn, colorAxOut, colorScaleAttrs.coloraxis, attr, dflt);\n    }\n\n    for(var k in colorAxes) {\n        var stash = colorAxes[k];\n\n        if(stash[0]) {\n            colorAxIn = layoutIn[k] || {};\n            colorAxOut = Template.newContainer(layoutOut, k, 'coloraxis');\n            colorAxOut._name = k;\n            colorScaleDefaults(colorAxIn, colorAxOut, layoutOut, coerceAx, {prefix: '', cLetter: 'c'});\n        } else {\n            // re-coerce colorscale attributes w/o coloraxis\n            for(var i = 0; i < stash[2].length; i++) {\n                stash[2][i]();\n            }\n            delete layoutOut._colorAxes[k];\n        }\n    }\n};\n\n},{\"../../lib\":719,\"../../plot_api/plot_template\":757,\"./defaults\":603,\"./layout_attributes\":606}],608:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar tinycolor = _dereq_('tinycolor2');\n\nvar scales = {\n    'Greys': [\n        [0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']\n    ],\n\n    'YlGnBu': [\n        [0, 'rgb(8,29,88)'], [0.125, 'rgb(37,52,148)'],\n        [0.25, 'rgb(34,94,168)'], [0.375, 'rgb(29,145,192)'],\n        [0.5, 'rgb(65,182,196)'], [0.625, 'rgb(127,205,187)'],\n        [0.75, 'rgb(199,233,180)'], [0.875, 'rgb(237,248,217)'],\n        [1, 'rgb(255,255,217)']\n    ],\n\n    'Greens': [\n        [0, 'rgb(0,68,27)'], [0.125, 'rgb(0,109,44)'],\n        [0.25, 'rgb(35,139,69)'], [0.375, 'rgb(65,171,93)'],\n        [0.5, 'rgb(116,196,118)'], [0.625, 'rgb(161,217,155)'],\n        [0.75, 'rgb(199,233,192)'], [0.875, 'rgb(229,245,224)'],\n        [1, 'rgb(247,252,245)']\n    ],\n\n    'YlOrRd': [\n        [0, 'rgb(128,0,38)'], [0.125, 'rgb(189,0,38)'],\n        [0.25, 'rgb(227,26,28)'], [0.375, 'rgb(252,78,42)'],\n        [0.5, 'rgb(253,141,60)'], [0.625, 'rgb(254,178,76)'],\n        [0.75, 'rgb(254,217,118)'], [0.875, 'rgb(255,237,160)'],\n        [1, 'rgb(255,255,204)']\n    ],\n\n    'Bluered': [\n        [0, 'rgb(0,0,255)'], [1, 'rgb(255,0,0)']\n    ],\n\n    // modified RdBu based on\n    // http://www.kennethmoreland.com/color-maps/\n    'RdBu': [\n        [0, 'rgb(5,10,172)'], [0.35, 'rgb(106,137,247)'],\n        [0.5, 'rgb(190,190,190)'], [0.6, 'rgb(220,170,132)'],\n        [0.7, 'rgb(230,145,90)'], [1, 'rgb(178,10,28)']\n    ],\n\n    // Scale for non-negative numeric values\n    'Reds': [\n        [0, 'rgb(220,220,220)'], [0.2, 'rgb(245,195,157)'],\n        [0.4, 'rgb(245,160,105)'], [1, 'rgb(178,10,28)']\n    ],\n\n    // Scale for non-positive numeric values\n    'Blues': [\n        [0, 'rgb(5,10,172)'], [0.35, 'rgb(40,60,190)'],\n        [0.5, 'rgb(70,100,245)'], [0.6, 'rgb(90,120,245)'],\n        [0.7, 'rgb(106,137,247)'], [1, 'rgb(220,220,220)']\n    ],\n\n    'Picnic': [\n        [0, 'rgb(0,0,255)'], [0.1, 'rgb(51,153,255)'],\n        [0.2, 'rgb(102,204,255)'], [0.3, 'rgb(153,204,255)'],\n        [0.4, 'rgb(204,204,255)'], [0.5, 'rgb(255,255,255)'],\n        [0.6, 'rgb(255,204,255)'], [0.7, 'rgb(255,153,255)'],\n        [0.8, 'rgb(255,102,204)'], [0.9, 'rgb(255,102,102)'],\n        [1, 'rgb(255,0,0)']\n    ],\n\n    'Rainbow': [\n        [0, 'rgb(150,0,90)'], [0.125, 'rgb(0,0,200)'],\n        [0.25, 'rgb(0,25,255)'], [0.375, 'rgb(0,152,255)'],\n        [0.5, 'rgb(44,255,150)'], [0.625, 'rgb(151,255,0)'],\n        [0.75, 'rgb(255,234,0)'], [0.875, 'rgb(255,111,0)'],\n        [1, 'rgb(255,0,0)']\n    ],\n\n    'Portland': [\n        [0, 'rgb(12,51,131)'], [0.25, 'rgb(10,136,186)'],\n        [0.5, 'rgb(242,211,56)'], [0.75, 'rgb(242,143,56)'],\n        [1, 'rgb(217,30,30)']\n    ],\n\n    'Jet': [\n        [0, 'rgb(0,0,131)'], [0.125, 'rgb(0,60,170)'],\n        [0.375, 'rgb(5,255,255)'], [0.625, 'rgb(255,255,0)'],\n        [0.875, 'rgb(250,0,0)'], [1, 'rgb(128,0,0)']\n    ],\n\n    'Hot': [\n        [0, 'rgb(0,0,0)'], [0.3, 'rgb(230,0,0)'],\n        [0.6, 'rgb(255,210,0)'], [1, 'rgb(255,255,255)']\n    ],\n\n    'Blackbody': [\n        [0, 'rgb(0,0,0)'], [0.2, 'rgb(230,0,0)'],\n        [0.4, 'rgb(230,210,0)'], [0.7, 'rgb(255,255,255)'],\n        [1, 'rgb(160,200,255)']\n    ],\n\n    'Earth': [\n        [0, 'rgb(0,0,130)'], [0.1, 'rgb(0,180,180)'],\n        [0.2, 'rgb(40,210,40)'], [0.4, 'rgb(230,230,50)'],\n        [0.6, 'rgb(120,70,20)'], [1, 'rgb(255,255,255)']\n    ],\n\n    'Electric': [\n        [0, 'rgb(0,0,0)'], [0.15, 'rgb(30,0,100)'],\n        [0.4, 'rgb(120,0,100)'], [0.6, 'rgb(160,90,0)'],\n        [0.8, 'rgb(230,200,0)'], [1, 'rgb(255,250,220)']\n    ],\n\n    'Viridis': [\n        [0, '#440154'], [0.06274509803921569, '#48186a'],\n        [0.12549019607843137, '#472d7b'], [0.18823529411764706, '#424086'],\n        [0.25098039215686274, '#3b528b'], [0.3137254901960784, '#33638d'],\n        [0.3764705882352941, '#2c728e'], [0.4392156862745098, '#26828e'],\n        [0.5019607843137255, '#21918c'], [0.5647058823529412, '#1fa088'],\n        [0.6274509803921569, '#28ae80'], [0.6901960784313725, '#3fbc73'],\n        [0.7529411764705882, '#5ec962'], [0.8156862745098039, '#84d44b'],\n        [0.8784313725490196, '#addc30'], [0.9411764705882353, '#d8e219'],\n        [1, '#fde725']\n    ],\n\n    'Cividis': [\n        [0.000000, 'rgb(0,32,76)'], [0.058824, 'rgb(0,42,102)'],\n        [0.117647, 'rgb(0,52,110)'], [0.176471, 'rgb(39,63,108)'],\n        [0.235294, 'rgb(60,74,107)'], [0.294118, 'rgb(76,85,107)'],\n        [0.352941, 'rgb(91,95,109)'], [0.411765, 'rgb(104,106,112)'],\n        [0.470588, 'rgb(117,117,117)'], [0.529412, 'rgb(131,129,120)'],\n        [0.588235, 'rgb(146,140,120)'], [0.647059, 'rgb(161,152,118)'],\n        [0.705882, 'rgb(176,165,114)'], [0.764706, 'rgb(192,177,109)'],\n        [0.823529, 'rgb(209,191,102)'], [0.882353, 'rgb(225,204,92)'],\n        [0.941176, 'rgb(243,219,79)'], [1.000000, 'rgb(255,233,69)']\n    ]\n};\n\nvar defaultScale = scales.RdBu;\n\nfunction getScale(scl, dflt) {\n    if(!dflt) dflt = defaultScale;\n    if(!scl) return dflt;\n\n    function parseScale() {\n        try {\n            scl = scales[scl] || JSON.parse(scl);\n        } catch(e) {\n            scl = dflt;\n        }\n    }\n\n    if(typeof scl === 'string') {\n        parseScale();\n        // occasionally scl is double-JSON encoded...\n        if(typeof scl === 'string') parseScale();\n    }\n\n    if(!isValidScaleArray(scl)) return dflt;\n    return scl;\n}\n\n\nfunction isValidScaleArray(scl) {\n    var highestVal = 0;\n\n    if(!Array.isArray(scl) || scl.length < 2) return false;\n\n    if(!scl[0] || !scl[scl.length - 1]) return false;\n\n    if(+scl[0][0] !== 0 || +scl[scl.length - 1][0] !== 1) return false;\n\n    for(var i = 0; i < scl.length; i++) {\n        var si = scl[i];\n\n        if(si.length !== 2 || +si[0] < highestVal || !tinycolor(si[1]).isValid()) {\n            return false;\n        }\n\n        highestVal = +si[0];\n    }\n\n    return true;\n}\n\nfunction isValidScale(scl) {\n    if(scales[scl] !== undefined) return true;\n    else return isValidScaleArray(scl);\n}\n\nmodule.exports = {\n    scales: scales,\n    defaultScale: defaultScale,\n\n    get: getScale,\n    isValid: isValidScale\n};\n\n},{\"tinycolor2\":537}],609:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\n// for automatic alignment on dragging, <1/3 means left align,\n// >2/3 means right, and between is center. Pick the right fraction\n// based on where you are, and return the fraction corresponding to\n// that position on the object\nmodule.exports = function align(v, dv, v0, v1, anchor) {\n    var vmin = (v - v0) / (v1 - v0);\n    var vmax = vmin + dv / (v1 - v0);\n    var vc = (vmin + vmax) / 2;\n\n    // explicitly specified anchor\n    if(anchor === 'left' || anchor === 'bottom') return vmin;\n    if(anchor === 'center' || anchor === 'middle') return vc;\n    if(anchor === 'right' || anchor === 'top') return vmax;\n\n    // automatic based on position\n    if(vmin < (2 / 3) - vc) return vmin;\n    if(vmax > (4 / 3) - vc) return vmax;\n    return vc;\n};\n\n},{}],610:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n\n// set cursors pointing toward the closest corner/side,\n// to indicate alignment\n// x and y are 0-1, fractions of the plot area\nvar cursorset = [\n    ['sw-resize', 's-resize', 'se-resize'],\n    ['w-resize', 'move', 'e-resize'],\n    ['nw-resize', 'n-resize', 'ne-resize']\n];\n\nmodule.exports = function getCursor(x, y, xanchor, yanchor) {\n    if(xanchor === 'left') x = 0;\n    else if(xanchor === 'center') x = 1;\n    else if(xanchor === 'right') x = 2;\n    else x = Lib.constrain(Math.floor(x * 3), 0, 2);\n\n    if(yanchor === 'bottom') y = 0;\n    else if(yanchor === 'middle') y = 1;\n    else if(yanchor === 'top') y = 2;\n    else y = Lib.constrain(Math.floor(y * 3), 0, 2);\n\n    return cursorset[y][x];\n};\n\n},{\"../../lib\":719}],611:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar mouseOffset = _dereq_('mouse-event-offset');\nvar hasHover = _dereq_('has-hover');\nvar supportsPassive = _dereq_('has-passive-events');\n\nvar removeElement = _dereq_('../../lib').removeElement;\nvar constants = _dereq_('../../plots/cartesian/constants');\n\nvar dragElement = module.exports = {};\n\ndragElement.align = _dereq_('./align');\ndragElement.getCursor = _dereq_('./cursor');\n\nvar unhover = _dereq_('./unhover');\ndragElement.unhover = unhover.wrapped;\ndragElement.unhoverRaw = unhover.raw;\n\n/**\n * Abstracts click & drag interactions\n *\n * During the interaction, a \"coverSlip\" element - a transparent\n * div covering the whole page - is created, which has two key effects:\n * - Lets you drag beyond the boundaries of the plot itself without\n *   dropping (but if you drag all the way out of the browser window the\n *   interaction will end)\n * - Freezes the cursor: whatever mouse cursor the drag element had when the\n *   interaction started gets copied to the coverSlip for use until mouseup\n *\n * If the user executes a drag bigger than MINDRAG, callbacks will fire as:\n *      prepFn, moveFn (1 or more times), doneFn\n * If the user does not drag enough, prepFn and clickFn will fire.\n *\n * Note: If you cancel contextmenu, clickFn will fire even with a right click\n * (unlike native events) so you'll get a `plotly_click` event. Cancel context eg:\n *    gd.addEventListener('contextmenu', function(e) { e.preventDefault(); });\n * TODO: we should probably turn this into a `config` parameter, so we can fix it\n * such that if you *don't* cancel contextmenu, we can prevent partial drags, which\n * put you in a weird state.\n *\n * If the user clicks multiple times quickly, clickFn will fire each time\n * but numClicks will increase to help you recognize doubleclicks.\n *\n * @param {object} options with keys:\n *      element (required) the DOM element to drag\n *      prepFn (optional) function(event, startX, startY)\n *          executed on mousedown\n *          startX and startY are the clientX and clientY pixel position\n *          of the mousedown event\n *      moveFn (optional) function(dx, dy)\n *          executed on move, ONLY after we've exceeded MINDRAG\n *          (we keep executing moveFn if you move back to where you started)\n *          dx and dy are the net pixel offset of the drag,\n *          dragged is true/false, has the mouse moved enough to\n *          constitute a drag\n *      doneFn (optional) function(e)\n *          executed on mouseup, ONLY if we exceeded MINDRAG (so you can be\n *          sure that moveFn has been called at least once)\n *          numClicks is how many clicks we've registered within\n *          a doubleclick time\n *          e is the original mouseup event\n *      clickFn (optional) function(numClicks, e)\n *          executed on mouseup if we have NOT exceeded MINDRAG (ie moveFn\n *          has not been called at all)\n *          numClicks is how many clicks we've registered within\n *          a doubleclick time\n *          e is the original mousedown event\n *      clampFn (optional, function(dx, dy) return [dx2, dy2])\n *          Provide custom clamping function for small displacements.\n *          By default, clamping is done using `minDrag` to x and y displacements\n *          independently.\n */\ndragElement.init = function init(options) {\n    var gd = options.gd;\n    var numClicks = 1;\n    var doubleClickDelay = gd._context.doubleClickDelay;\n    var element = options.element;\n\n    var startX,\n        startY,\n        newMouseDownTime,\n        cursor,\n        dragCover,\n        initialEvent,\n        initialTarget,\n        rightClick;\n\n    if(!gd._mouseDownTime) gd._mouseDownTime = 0;\n\n    element.style.pointerEvents = 'all';\n\n    element.onmousedown = onStart;\n\n    if(!supportsPassive) {\n        element.ontouchstart = onStart;\n    } else {\n        if(element._ontouchstart) {\n            element.removeEventListener('touchstart', element._ontouchstart);\n        }\n        element._ontouchstart = onStart;\n        element.addEventListener('touchstart', onStart, {passive: false});\n    }\n\n    function _clampFn(dx, dy, minDrag) {\n        if(Math.abs(dx) < minDrag) dx = 0;\n        if(Math.abs(dy) < minDrag) dy = 0;\n        return [dx, dy];\n    }\n\n    var clampFn = options.clampFn || _clampFn;\n\n    function onStart(e) {\n        // make dragging and dragged into properties of gd\n        // so that others can look at and modify them\n        gd._dragged = false;\n        gd._dragging = true;\n        var offset = pointerOffset(e);\n        startX = offset[0];\n        startY = offset[1];\n        initialTarget = e.target;\n        initialEvent = e;\n        rightClick = e.buttons === 2 || e.ctrlKey;\n\n        // fix Fx.hover for touch events\n        if(typeof e.clientX === 'undefined' && typeof e.clientY === 'undefined') {\n            e.clientX = startX;\n            e.clientY = startY;\n        }\n\n        newMouseDownTime = (new Date()).getTime();\n        if(newMouseDownTime - gd._mouseDownTime < doubleClickDelay) {\n            // in a click train\n            numClicks += 1;\n        } else {\n            // new click train\n            numClicks = 1;\n            gd._mouseDownTime = newMouseDownTime;\n        }\n\n        if(options.prepFn) options.prepFn(e, startX, startY);\n\n        if(hasHover && !rightClick) {\n            dragCover = coverSlip();\n            dragCover.style.cursor = window.getComputedStyle(element).cursor;\n        } else if(!hasHover) {\n            // document acts as a dragcover for mobile, bc we can't create dragcover dynamically\n            dragCover = document;\n            cursor = window.getComputedStyle(document.documentElement).cursor;\n            document.documentElement.style.cursor = window.getComputedStyle(element).cursor;\n        }\n\n        document.addEventListener('mouseup', onDone);\n        document.addEventListener('touchend', onDone);\n\n        if(options.dragmode !== false) {\n            e.preventDefault();\n            document.addEventListener('mousemove', onMove);\n            document.addEventListener('touchmove', onMove);\n        }\n\n        return;\n    }\n\n    function onMove(e) {\n        e.preventDefault();\n\n        var offset = pointerOffset(e);\n        var minDrag = options.minDrag || constants.MINDRAG;\n        var dxdy = clampFn(offset[0] - startX, offset[1] - startY, minDrag);\n        var dx = dxdy[0];\n        var dy = dxdy[1];\n\n        if(dx || dy) {\n            gd._dragged = true;\n            dragElement.unhover(gd);\n        }\n\n        if(gd._dragged && options.moveFn && !rightClick) {\n            gd._dragdata = {\n                element: element,\n                dx: dx,\n                dy: dy\n            };\n            options.moveFn(dx, dy);\n        }\n\n        return;\n    }\n\n    function onDone(e) {\n        delete gd._dragdata;\n\n        if(options.dragmode !== false) {\n            e.preventDefault();\n            document.removeEventListener('mousemove', onMove);\n            document.removeEventListener('touchmove', onMove);\n        }\n\n        document.removeEventListener('mouseup', onDone);\n        document.removeEventListener('touchend', onDone);\n\n        if(hasHover) {\n            removeElement(dragCover);\n        } else if(cursor) {\n            dragCover.documentElement.style.cursor = cursor;\n            cursor = null;\n        }\n\n        if(!gd._dragging) {\n            gd._dragged = false;\n            return;\n        }\n        gd._dragging = false;\n\n        // don't count as a dblClick unless the mouseUp is also within\n        // the dblclick delay\n        if((new Date()).getTime() - gd._mouseDownTime > doubleClickDelay) {\n            numClicks = Math.max(numClicks - 1, 1);\n        }\n\n        if(gd._dragged) {\n            if(options.doneFn) options.doneFn();\n        } else {\n            if(options.clickFn) options.clickFn(numClicks, initialEvent);\n\n            // If we haven't dragged, this should be a click. But because of the\n            // coverSlip changing the element, the natural system might not generate one,\n            // so we need to make our own. But right clicks don't normally generate\n            // click events, only contextmenu events, which happen on mousedown.\n            if(!rightClick) {\n                var e2;\n\n                try {\n                    e2 = new MouseEvent('click', e);\n                } catch(err) {\n                    var offset = pointerOffset(e);\n                    e2 = document.createEvent('MouseEvents');\n                    e2.initMouseEvent('click',\n                        e.bubbles, e.cancelable,\n                        e.view, e.detail,\n                        e.screenX, e.screenY,\n                        offset[0], offset[1],\n                        e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,\n                        e.button, e.relatedTarget);\n                }\n\n                initialTarget.dispatchEvent(e2);\n            }\n        }\n\n        gd._dragging = false;\n        gd._dragged = false;\n        return;\n    }\n};\n\nfunction coverSlip() {\n    var cover = document.createElement('div');\n\n    cover.className = 'dragcover';\n    var cStyle = cover.style;\n    cStyle.position = 'fixed';\n    cStyle.left = 0;\n    cStyle.right = 0;\n    cStyle.top = 0;\n    cStyle.bottom = 0;\n    cStyle.zIndex = 999999999;\n    cStyle.background = 'none';\n\n    document.body.appendChild(cover);\n\n    return cover;\n}\n\ndragElement.coverSlip = coverSlip;\n\nfunction pointerOffset(e) {\n    return mouseOffset(\n        e.changedTouches ? e.changedTouches[0] : e,\n        document.body\n    );\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/constants\":773,\"./align\":609,\"./cursor\":610,\"./unhover\":612,\"has-hover\":410,\"has-passive-events\":411,\"mouse-event-offset\":436}],612:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Events = _dereq_('../../lib/events');\nvar throttle = _dereq_('../../lib/throttle');\nvar getGraphDiv = _dereq_('../../lib/dom').getGraphDiv;\n\nvar hoverConstants = _dereq_('../fx/constants');\n\nvar unhover = module.exports = {};\n\nunhover.wrapped = function(gd, evt, subplot) {\n    gd = getGraphDiv(gd);\n\n    // Important, clear any queued hovers\n    if(gd._fullLayout) {\n        throttle.clear(gd._fullLayout._uid + hoverConstants.HOVERID);\n    }\n\n    unhover.raw(gd, evt, subplot);\n};\n\n\n// remove hover effects on mouse out, and emit unhover event\nunhover.raw = function raw(gd, evt) {\n    var fullLayout = gd._fullLayout;\n    var oldhoverdata = gd._hoverdata;\n\n    if(!evt) evt = {};\n    if(evt.target &&\n       Events.triggerHandler(gd, 'plotly_beforehover', evt) === false) {\n        return;\n    }\n\n    fullLayout._hoverlayer.selectAll('g').remove();\n    fullLayout._hoverlayer.selectAll('line').remove();\n    fullLayout._hoverlayer.selectAll('circle').remove();\n    gd._hoverdata = undefined;\n\n    if(evt.target && oldhoverdata) {\n        gd.emit('plotly_unhover', {\n            event: evt,\n            points: oldhoverdata\n        });\n    }\n};\n\n},{\"../../lib/dom\":708,\"../../lib/events\":709,\"../../lib/throttle\":744,\"../fx/constants\":626}],613:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nexports.dash = {\n    valType: 'string',\n    // string type usually doesn't take values... this one should really be\n    // a special type or at least a special coercion function, from the GUI\n    // you only get these values but elsewhere the user can supply a list of\n    // dash lengths in px, and it will be honored\n    values: ['solid', 'dot', 'dash', 'longdash', 'dashdot', 'longdashdot'],\n    dflt: 'solid',\n    \n    editType: 'style',\n    \n};\n\n},{}],614:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\nvar tinycolor = _dereq_('tinycolor2');\n\nvar Registry = _dereq_('../../registry');\nvar Color = _dereq_('../color');\nvar Colorscale = _dereq_('../colorscale');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\n\nvar xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');\nvar alignment = _dereq_('../../constants/alignment');\nvar LINE_SPACING = alignment.LINE_SPACING;\nvar DESELECTDIM = _dereq_('../../constants/interactions').DESELECTDIM;\n\nvar subTypes = _dereq_('../../traces/scatter/subtypes');\nvar makeBubbleSizeFn = _dereq_('../../traces/scatter/make_bubble_size_func');\n\nvar drawing = module.exports = {};\n\n// -----------------------------------------------------\n// styling functions for plot elements\n// -----------------------------------------------------\n\ndrawing.font = function(s, family, size, color) {\n    // also allow the form font(s, {family, size, color})\n    if(Lib.isPlainObject(family)) {\n        color = family.color;\n        size = family.size;\n        family = family.family;\n    }\n    if(family) s.style('font-family', family);\n    if(size + 1) s.style('font-size', size + 'px');\n    if(color) s.call(Color.fill, color);\n};\n\n/*\n * Positioning helpers\n * Note: do not use `setPosition` with <text> nodes modified by\n * `svgTextUtils.convertToTspans`. Use `svgTextUtils.positionText`\n * instead, so that <tspan.line> elements get updated to match.\n */\ndrawing.setPosition = function(s, x, y) { s.attr('x', x).attr('y', y); };\ndrawing.setSize = function(s, w, h) { s.attr('width', w).attr('height', h); };\ndrawing.setRect = function(s, x, y, w, h) {\n    s.call(drawing.setPosition, x, y).call(drawing.setSize, w, h);\n};\n\n/** Translate node\n *\n * @param {object} d : calcdata point item\n * @param {sel} sel : d3 selction of node to translate\n * @param {object} xa : corresponding full xaxis object\n * @param {object} ya : corresponding full yaxis object\n *\n * @return {boolean} :\n *  true if selection got translated\n *  false if selection could not get translated\n */\ndrawing.translatePoint = function(d, sel, xa, ya) {\n    var x = xa.c2p(d.x);\n    var y = ya.c2p(d.y);\n\n    if(isNumeric(x) && isNumeric(y) && sel.node()) {\n        // for multiline text this works better\n        if(sel.node().nodeName === 'text') {\n            sel.attr('x', x).attr('y', y);\n        } else {\n            sel.attr('transform', 'translate(' + x + ',' + y + ')');\n        }\n    } else {\n        return false;\n    }\n\n    return true;\n};\n\ndrawing.translatePoints = function(s, xa, ya) {\n    s.each(function(d) {\n        var sel = d3.select(this);\n        drawing.translatePoint(d, sel, xa, ya);\n    });\n};\n\ndrawing.hideOutsideRangePoint = function(d, sel, xa, ya, xcalendar, ycalendar) {\n    sel.attr(\n        'display',\n        (xa.isPtWithinRange(d, xcalendar) && ya.isPtWithinRange(d, ycalendar)) ? null : 'none'\n    );\n};\n\ndrawing.hideOutsideRangePoints = function(traceGroups, subplot) {\n    if(!subplot._hasClipOnAxisFalse) return;\n\n    var xa = subplot.xaxis;\n    var ya = subplot.yaxis;\n\n    traceGroups.each(function(d) {\n        var trace = d[0].trace;\n        var xcalendar = trace.xcalendar;\n        var ycalendar = trace.ycalendar;\n        var selector = Registry.traceIs(trace, 'bar-like') ? '.bartext' : '.point,.textpoint';\n\n        traceGroups.selectAll(selector).each(function(d) {\n            drawing.hideOutsideRangePoint(d, d3.select(this), xa, ya, xcalendar, ycalendar);\n        });\n    });\n};\n\ndrawing.crispRound = function(gd, lineWidth, dflt) {\n    // for lines that disable antialiasing we want to\n    // make sure the width is an integer, and at least 1 if it's nonzero\n\n    if(!lineWidth || !isNumeric(lineWidth)) return dflt || 0;\n\n    // but not for static plots - these don't get antialiased anyway.\n    if(gd._context.staticPlot) return lineWidth;\n\n    if(lineWidth < 1) return 1;\n    return Math.round(lineWidth);\n};\n\ndrawing.singleLineStyle = function(d, s, lw, lc, ld) {\n    s.style('fill', 'none');\n    var line = (((d || [])[0] || {}).trace || {}).line || {};\n    var lw1 = lw || line.width || 0;\n    var dash = ld || line.dash || '';\n\n    Color.stroke(s, lc || line.color);\n    drawing.dashLine(s, dash, lw1);\n};\n\ndrawing.lineGroupStyle = function(s, lw, lc, ld) {\n    s.style('fill', 'none')\n    .each(function(d) {\n        var line = (((d || [])[0] || {}).trace || {}).line || {};\n        var lw1 = lw || line.width || 0;\n        var dash = ld || line.dash || '';\n\n        d3.select(this)\n            .call(Color.stroke, lc || line.color)\n            .call(drawing.dashLine, dash, lw1);\n    });\n};\n\ndrawing.dashLine = function(s, dash, lineWidth) {\n    lineWidth = +lineWidth || 0;\n\n    dash = drawing.dashStyle(dash, lineWidth);\n\n    s.style({\n        'stroke-dasharray': dash,\n        'stroke-width': lineWidth + 'px'\n    });\n};\n\ndrawing.dashStyle = function(dash, lineWidth) {\n    lineWidth = +lineWidth || 1;\n    var dlw = Math.max(lineWidth, 3);\n\n    if(dash === 'solid') dash = '';\n    else if(dash === 'dot') dash = dlw + 'px,' + dlw + 'px';\n    else if(dash === 'dash') dash = (3 * dlw) + 'px,' + (3 * dlw) + 'px';\n    else if(dash === 'longdash') dash = (5 * dlw) + 'px,' + (5 * dlw) + 'px';\n    else if(dash === 'dashdot') {\n        dash = (3 * dlw) + 'px,' + dlw + 'px,' + dlw + 'px,' + dlw + 'px';\n    } else if(dash === 'longdashdot') {\n        dash = (5 * dlw) + 'px,' + (2 * dlw) + 'px,' + dlw + 'px,' + (2 * dlw) + 'px';\n    }\n    // otherwise user wrote the dasharray themselves - leave it be\n\n    return dash;\n};\n\n// Same as fillGroupStyle, except in this case the selection may be a transition\ndrawing.singleFillStyle = function(sel) {\n    var node = d3.select(sel.node());\n    var data = node.data();\n    var fillcolor = (((data[0] || [])[0] || {}).trace || {}).fillcolor;\n    if(fillcolor) {\n        sel.call(Color.fill, fillcolor);\n    }\n};\n\ndrawing.fillGroupStyle = function(s) {\n    s.style('stroke-width', 0)\n    .each(function(d) {\n        var shape = d3.select(this);\n        // N.B. 'd' won't be a calcdata item when\n        // fill !== 'none' on a segment-less and marker-less trace\n        if(d[0].trace) {\n            shape.call(Color.fill, d[0].trace.fillcolor);\n        }\n    });\n};\n\nvar SYMBOLDEFS = _dereq_('./symbol_defs');\n\ndrawing.symbolNames = [];\ndrawing.symbolFuncs = [];\ndrawing.symbolNeedLines = {};\ndrawing.symbolNoDot = {};\ndrawing.symbolNoFill = {};\ndrawing.symbolList = [];\n\nObject.keys(SYMBOLDEFS).forEach(function(k) {\n    var symDef = SYMBOLDEFS[k];\n    drawing.symbolList = drawing.symbolList.concat(\n        [symDef.n, k, symDef.n + 100, k + '-open']);\n    drawing.symbolNames[symDef.n] = k;\n    drawing.symbolFuncs[symDef.n] = symDef.f;\n    if(symDef.needLine) {\n        drawing.symbolNeedLines[symDef.n] = true;\n    }\n    if(symDef.noDot) {\n        drawing.symbolNoDot[symDef.n] = true;\n    } else {\n        drawing.symbolList = drawing.symbolList.concat(\n            [symDef.n + 200, k + '-dot', symDef.n + 300, k + '-open-dot']);\n    }\n    if(symDef.noFill) {\n        drawing.symbolNoFill[symDef.n] = true;\n    }\n});\n\nvar MAXSYMBOL = drawing.symbolNames.length;\n// add a dot in the middle of the symbol\nvar DOTPATH = 'M0,0.5L0.5,0L0,-0.5L-0.5,0Z';\n\ndrawing.symbolNumber = function(v) {\n    if(typeof v === 'string') {\n        var vbase = 0;\n        if(v.indexOf('-open') > 0) {\n            vbase = 100;\n            v = v.replace('-open', '');\n        }\n        if(v.indexOf('-dot') > 0) {\n            vbase += 200;\n            v = v.replace('-dot', '');\n        }\n        v = drawing.symbolNames.indexOf(v);\n        if(v >= 0) { v += vbase; }\n    }\n    if((v % 100 >= MAXSYMBOL) || v >= 400) { return 0; }\n    return Math.floor(Math.max(v, 0));\n};\n\nfunction makePointPath(symbolNumber, r) {\n    var base = symbolNumber % 100;\n    return drawing.symbolFuncs[base](r) + (symbolNumber >= 200 ? DOTPATH : '');\n}\n\nvar HORZGRADIENT = {x1: 1, x2: 0, y1: 0, y2: 0};\nvar VERTGRADIENT = {x1: 0, x2: 0, y1: 1, y2: 0};\nvar stopFormatter = d3.format('~.1f');\nvar gradientInfo = {\n    radial: {node: 'radialGradient'},\n    radialreversed: {node: 'radialGradient', reversed: true},\n    horizontal: {node: 'linearGradient', attrs: HORZGRADIENT},\n    horizontalreversed: {node: 'linearGradient', attrs: HORZGRADIENT, reversed: true},\n    vertical: {node: 'linearGradient', attrs: VERTGRADIENT},\n    verticalreversed: {node: 'linearGradient', attrs: VERTGRADIENT, reversed: true}\n};\n\n/**\n * gradient: create and apply a gradient fill\n *\n * @param {object} sel: d3 selection to apply this gradient to\n *     You can use `selection.call(Drawing.gradient, ...)`\n * @param {DOM element} gd: the graph div `sel` is part of\n * @param {string} gradientID: a unique (within this plot) identifier\n *     for this gradient, so that we don't create unnecessary definitions\n * @param {string} type: 'radial', 'horizontal', or 'vertical', optionally with\n *     'reversed' at the end. Normally radial goes center to edge,\n *     horizontal goes right to left, and vertical goes bottom to top\n * @param {array} colorscale: as in attribute values, [[fraction, color], ...]\n * @param {string} prop: the property to apply to, 'fill' or 'stroke'\n */\ndrawing.gradient = function(sel, gd, gradientID, type, colorscale, prop) {\n    var len = colorscale.length;\n    var info = gradientInfo[type];\n    var colorStops = new Array(len);\n    for(var i = 0; i < len; i++) {\n        if(info.reversed) {\n            colorStops[len - 1 - i] = [stopFormatter((1 - colorscale[i][0]) * 100), colorscale[i][1]];\n        } else {\n            colorStops[i] = [stopFormatter(colorscale[i][0] * 100), colorscale[i][1]];\n        }\n    }\n\n    var fullID = 'g' + gd._fullLayout._uid + '-' + gradientID;\n\n    var gradient = gd._fullLayout._defs.select('.gradients')\n        .selectAll('#' + fullID)\n        .data([type + colorStops.join(';')], Lib.identity);\n\n    gradient.exit().remove();\n\n    gradient.enter()\n        .append(info.node)\n        .each(function() {\n            var el = d3.select(this);\n            if(info.attrs) el.attr(info.attrs);\n\n            el.attr('id', fullID);\n\n            var stops = el.selectAll('stop')\n                .data(colorStops);\n            stops.exit().remove();\n            stops.enter().append('stop');\n\n            stops.each(function(d) {\n                var tc = tinycolor(d[1]);\n                d3.select(this).attr({\n                    offset: d[0] + '%',\n                    'stop-color': Color.tinyRGB(tc),\n                    'stop-opacity': tc.getAlpha()\n                });\n            });\n        });\n\n    sel.style(prop, getFullUrl(fullID, gd))\n        .style(prop + '-opacity', null);\n};\n\n/*\n * Make the gradients container and clear out any previous gradients.\n * We never collect all the gradients we need in one place,\n * so we can't ever remove gradients that have stopped being useful,\n * except all at once before a full redraw.\n * The upside of this is arbitrary points can share gradient defs\n */\ndrawing.initGradients = function(gd) {\n    var gradientsGroup = Lib.ensureSingle(gd._fullLayout._defs, 'g', 'gradients');\n    gradientsGroup.selectAll('linearGradient,radialGradient').remove();\n};\n\n\ndrawing.pointStyle = function(s, trace, gd) {\n    if(!s.size()) return;\n\n    var fns = drawing.makePointStyleFns(trace);\n\n    s.each(function(d) {\n        drawing.singlePointStyle(d, d3.select(this), trace, fns, gd);\n    });\n};\n\ndrawing.singlePointStyle = function(d, sel, trace, fns, gd) {\n    var marker = trace.marker;\n    var markerLine = marker.line;\n\n    sel.style('opacity',\n        fns.selectedOpacityFn ? fns.selectedOpacityFn(d) :\n            (d.mo === undefined ? marker.opacity : d.mo)\n    );\n\n    if(fns.ms2mrc) {\n        var r;\n\n        // handle multi-trace graph edit case\n        if(d.ms === 'various' || marker.size === 'various') {\n            r = 3;\n        } else {\n            r = fns.ms2mrc(d.ms);\n        }\n\n        // store the calculated size so hover can use it\n        d.mrc = r;\n\n        if(fns.selectedSizeFn) {\n            r = d.mrc = fns.selectedSizeFn(d);\n        }\n\n        // turn the symbol into a sanitized number\n        var x = drawing.symbolNumber(d.mx || marker.symbol) || 0;\n\n        // save if this marker is open\n        // because that impacts how to handle colors\n        d.om = x % 200 >= 100;\n\n        sel.attr('d', makePointPath(x, r));\n    }\n\n    var perPointGradient = false;\n    var fillColor, lineColor, lineWidth;\n\n    // 'so' is suspected outliers, for box plots\n    if(d.so) {\n        lineWidth = markerLine.outlierwidth;\n        lineColor = markerLine.outliercolor;\n        fillColor = marker.outliercolor;\n    } else {\n        var markerLineWidth = (markerLine || {}).width;\n\n        lineWidth = (\n            d.mlw + 1 ||\n            markerLineWidth + 1 ||\n            // TODO: we need the latter for legends... can we get rid of it?\n            (d.trace ? (d.trace.marker.line || {}).width : 0) + 1\n        ) - 1 || 0;\n\n        if('mlc' in d) lineColor = d.mlcc = fns.lineScale(d.mlc);\n        // weird case: array wasn't long enough to apply to every point\n        else if(Lib.isArrayOrTypedArray(markerLine.color)) lineColor = Color.defaultLine;\n        else lineColor = markerLine.color;\n\n        if(Lib.isArrayOrTypedArray(marker.color)) {\n            fillColor = Color.defaultLine;\n            perPointGradient = true;\n        }\n\n        if('mc' in d) {\n            fillColor = d.mcc = fns.markerScale(d.mc);\n        } else {\n            fillColor = marker.color || 'rgba(0,0,0,0)';\n        }\n\n        if(fns.selectedColorFn) {\n            fillColor = fns.selectedColorFn(d);\n        }\n    }\n\n    if(d.om) {\n        // open markers can't have zero linewidth, default to 1px,\n        // and use fill color as stroke color\n        sel.call(Color.stroke, fillColor)\n            .style({\n                'stroke-width': (lineWidth || 1) + 'px',\n                fill: 'none'\n            });\n    } else {\n        sel.style('stroke-width', lineWidth + 'px');\n\n        var markerGradient = marker.gradient;\n\n        var gradientType = d.mgt;\n        if(gradientType) perPointGradient = true;\n        else gradientType = markerGradient && markerGradient.type;\n\n        // for legend - arrays will propagate through here, but we don't need\n        // to treat it as per-point.\n        if(Array.isArray(gradientType)) {\n            gradientType = gradientType[0];\n            if(!gradientInfo[gradientType]) gradientType = 0;\n        }\n\n        if(gradientType && gradientType !== 'none') {\n            var gradientColor = d.mgc;\n            if(gradientColor) perPointGradient = true;\n            else gradientColor = markerGradient.color;\n\n            var gradientID = trace.uid;\n            if(perPointGradient) gradientID += '-' + d.i;\n\n            drawing.gradient(sel, gd, gradientID, gradientType,\n                [[0, gradientColor], [1, fillColor]], 'fill');\n        } else {\n            Color.fill(sel, fillColor);\n        }\n\n        if(lineWidth) {\n            Color.stroke(sel, lineColor);\n        }\n    }\n};\n\ndrawing.makePointStyleFns = function(trace) {\n    var out = {};\n    var marker = trace.marker;\n\n    // allow array marker and marker line colors to be\n    // scaled by given max and min to colorscales\n    out.markerScale = drawing.tryColorscale(marker, '');\n    out.lineScale = drawing.tryColorscale(marker, 'line');\n\n    if(Registry.traceIs(trace, 'symbols')) {\n        out.ms2mrc = subTypes.isBubble(trace) ?\n            makeBubbleSizeFn(trace) :\n            function() { return (marker.size || 6) / 2; };\n    }\n\n    if(trace.selectedpoints) {\n        Lib.extendFlat(out, drawing.makeSelectedPointStyleFns(trace));\n    }\n\n    return out;\n};\n\ndrawing.makeSelectedPointStyleFns = function(trace) {\n    var out = {};\n\n    var selectedAttrs = trace.selected || {};\n    var unselectedAttrs = trace.unselected || {};\n\n    var marker = trace.marker || {};\n    var selectedMarker = selectedAttrs.marker || {};\n    var unselectedMarker = unselectedAttrs.marker || {};\n\n    var mo = marker.opacity;\n    var smo = selectedMarker.opacity;\n    var usmo = unselectedMarker.opacity;\n    var smoIsDefined = smo !== undefined;\n    var usmoIsDefined = usmo !== undefined;\n\n    if(Lib.isArrayOrTypedArray(mo) || smoIsDefined || usmoIsDefined) {\n        out.selectedOpacityFn = function(d) {\n            var base = d.mo === undefined ? marker.opacity : d.mo;\n\n            if(d.selected) {\n                return smoIsDefined ? smo : base;\n            } else {\n                return usmoIsDefined ? usmo : DESELECTDIM * base;\n            }\n        };\n    }\n\n    var mc = marker.color;\n    var smc = selectedMarker.color;\n    var usmc = unselectedMarker.color;\n\n    if(smc || usmc) {\n        out.selectedColorFn = function(d) {\n            var base = d.mcc || mc;\n\n            if(d.selected) {\n                return smc || base;\n            } else {\n                return usmc || base;\n            }\n        };\n    }\n\n    var ms = marker.size;\n    var sms = selectedMarker.size;\n    var usms = unselectedMarker.size;\n    var smsIsDefined = sms !== undefined;\n    var usmsIsDefined = usms !== undefined;\n\n    if(Registry.traceIs(trace, 'symbols') && (smsIsDefined || usmsIsDefined)) {\n        out.selectedSizeFn = function(d) {\n            var base = d.mrc || ms / 2;\n\n            if(d.selected) {\n                return smsIsDefined ? sms / 2 : base;\n            } else {\n                return usmsIsDefined ? usms / 2 : base;\n            }\n        };\n    }\n\n    return out;\n};\n\ndrawing.makeSelectedTextStyleFns = function(trace) {\n    var out = {};\n\n    var selectedAttrs = trace.selected || {};\n    var unselectedAttrs = trace.unselected || {};\n\n    var textFont = trace.textfont || {};\n    var selectedTextFont = selectedAttrs.textfont || {};\n    var unselectedTextFont = unselectedAttrs.textfont || {};\n\n    var tc = textFont.color;\n    var stc = selectedTextFont.color;\n    var utc = unselectedTextFont.color;\n\n    out.selectedTextColorFn = function(d) {\n        var base = d.tc || tc;\n\n        if(d.selected) {\n            return stc || base;\n        } else {\n            if(utc) return utc;\n            else return stc ? base : Color.addOpacity(base, DESELECTDIM);\n        }\n    };\n\n    return out;\n};\n\ndrawing.selectedPointStyle = function(s, trace) {\n    if(!s.size() || !trace.selectedpoints) return;\n\n    var fns = drawing.makeSelectedPointStyleFns(trace);\n    var marker = trace.marker || {};\n    var seq = [];\n\n    if(fns.selectedOpacityFn) {\n        seq.push(function(pt, d) {\n            pt.style('opacity', fns.selectedOpacityFn(d));\n        });\n    }\n\n    if(fns.selectedColorFn) {\n        seq.push(function(pt, d) {\n            Color.fill(pt, fns.selectedColorFn(d));\n        });\n    }\n\n    if(fns.selectedSizeFn) {\n        seq.push(function(pt, d) {\n            var mx = d.mx || marker.symbol || 0;\n            var mrc2 = fns.selectedSizeFn(d);\n\n            pt.attr('d', makePointPath(drawing.symbolNumber(mx), mrc2));\n\n            // save for Drawing.selectedTextStyle\n            d.mrc2 = mrc2;\n        });\n    }\n\n    if(seq.length) {\n        s.each(function(d) {\n            var pt = d3.select(this);\n            for(var i = 0; i < seq.length; i++) {\n                seq[i](pt, d);\n            }\n        });\n    }\n};\n\ndrawing.tryColorscale = function(marker, prefix) {\n    var cont = prefix ? Lib.nestedProperty(marker, prefix).get() : marker;\n\n    if(cont) {\n        var colorArray = cont.color;\n        if((cont.colorscale || cont._colorAx) && Lib.isArrayOrTypedArray(colorArray)) {\n            return Colorscale.makeColorScaleFuncFromTrace(cont);\n        }\n    }\n    return Lib.identity;\n};\n\nvar TEXTOFFSETSIGN = {\n    start: 1, end: -1, middle: 0, bottom: 1, top: -1\n};\n\nfunction textPointPosition(s, textPosition, fontSize, markerRadius) {\n    var group = d3.select(s.node().parentNode);\n\n    var v = textPosition.indexOf('top') !== -1 ?\n        'top' :\n        textPosition.indexOf('bottom') !== -1 ? 'bottom' : 'middle';\n    var h = textPosition.indexOf('left') !== -1 ?\n        'end' :\n        textPosition.indexOf('right') !== -1 ? 'start' : 'middle';\n\n    // if markers are shown, offset a little more than\n    // the nominal marker size\n    // ie 2/1.6 * nominal, bcs some markers are a bit bigger\n    var r = markerRadius ? markerRadius / 0.8 + 1 : 0;\n\n    var numLines = (svgTextUtils.lineCount(s) - 1) * LINE_SPACING + 1;\n    var dx = TEXTOFFSETSIGN[h] * r;\n    var dy = fontSize * 0.75 + TEXTOFFSETSIGN[v] * r +\n        (TEXTOFFSETSIGN[v] - 1) * numLines * fontSize / 2;\n\n    // fix the overall text group position\n    s.attr('text-anchor', h);\n    group.attr('transform', 'translate(' + dx + ',' + dy + ')');\n}\n\nfunction extracTextFontSize(d, trace) {\n    var fontSize = d.ts || trace.textfont.size;\n    return (isNumeric(fontSize) && fontSize > 0) ? fontSize : 0;\n}\n\n// draw text at points\ndrawing.textPointStyle = function(s, trace, gd) {\n    if(!s.size()) return;\n\n    var selectedTextColorFn;\n\n    if(trace.selectedpoints) {\n        var fns = drawing.makeSelectedTextStyleFns(trace);\n        selectedTextColorFn = fns.selectedTextColorFn;\n    }\n\n    s.each(function(d) {\n        var p = d3.select(this);\n        var text = Lib.extractOption(d, trace, 'tx', 'text');\n\n        if(!text && text !== 0) {\n            p.remove();\n            return;\n        }\n\n        var pos = d.tp || trace.textposition;\n        var fontSize = extracTextFontSize(d, trace);\n        var fontColor = selectedTextColorFn ?\n            selectedTextColorFn(d) :\n            (d.tc || trace.textfont.color);\n\n        p.call(drawing.font,\n                d.tf || trace.textfont.family,\n                fontSize,\n                fontColor)\n            .text(text)\n            .call(svgTextUtils.convertToTspans, gd)\n            .call(textPointPosition, pos, fontSize, d.mrc);\n    });\n};\n\ndrawing.selectedTextStyle = function(s, trace) {\n    if(!s.size() || !trace.selectedpoints) return;\n\n    var fns = drawing.makeSelectedTextStyleFns(trace);\n\n    s.each(function(d) {\n        var tx = d3.select(this);\n        var tc = fns.selectedTextColorFn(d);\n        var tp = d.tp || trace.textposition;\n        var fontSize = extracTextFontSize(d, trace);\n\n        Color.fill(tx, tc);\n        textPointPosition(tx, tp, fontSize, d.mrc2 || d.mrc);\n    });\n};\n\n// generalized Catmull-Rom splines, per\n// http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf\nvar CatmullRomExp = 0.5;\ndrawing.smoothopen = function(pts, smoothness) {\n    if(pts.length < 3) { return 'M' + pts.join('L');}\n    var path = 'M' + pts[0];\n    var tangents = [];\n    var i;\n    for(i = 1; i < pts.length - 1; i++) {\n        tangents.push(makeTangent(pts[i - 1], pts[i], pts[i + 1], smoothness));\n    }\n    path += 'Q' + tangents[0][0] + ' ' + pts[1];\n    for(i = 2; i < pts.length - 1; i++) {\n        path += 'C' + tangents[i - 2][1] + ' ' + tangents[i - 1][0] + ' ' + pts[i];\n    }\n    path += 'Q' + tangents[pts.length - 3][1] + ' ' + pts[pts.length - 1];\n    return path;\n};\n\ndrawing.smoothclosed = function(pts, smoothness) {\n    if(pts.length < 3) { return 'M' + pts.join('L') + 'Z'; }\n    var path = 'M' + pts[0];\n    var pLast = pts.length - 1;\n    var tangents = [makeTangent(pts[pLast], pts[0], pts[1], smoothness)];\n    var i;\n    for(i = 1; i < pLast; i++) {\n        tangents.push(makeTangent(pts[i - 1], pts[i], pts[i + 1], smoothness));\n    }\n    tangents.push(\n        makeTangent(pts[pLast - 1], pts[pLast], pts[0], smoothness)\n    );\n\n    for(i = 1; i <= pLast; i++) {\n        path += 'C' + tangents[i - 1][1] + ' ' + tangents[i][0] + ' ' + pts[i];\n    }\n    path += 'C' + tangents[pLast][1] + ' ' + tangents[0][0] + ' ' + pts[0] + 'Z';\n    return path;\n};\n\nfunction makeTangent(prevpt, thispt, nextpt, smoothness) {\n    var d1x = prevpt[0] - thispt[0];\n    var d1y = prevpt[1] - thispt[1];\n    var d2x = nextpt[0] - thispt[0];\n    var d2y = nextpt[1] - thispt[1];\n    var d1a = Math.pow(d1x * d1x + d1y * d1y, CatmullRomExp / 2);\n    var d2a = Math.pow(d2x * d2x + d2y * d2y, CatmullRomExp / 2);\n    var numx = (d2a * d2a * d1x - d1a * d1a * d2x) * smoothness;\n    var numy = (d2a * d2a * d1y - d1a * d1a * d2y) * smoothness;\n    var denom1 = 3 * d2a * (d1a + d2a);\n    var denom2 = 3 * d1a * (d1a + d2a);\n    return [\n        [\n            d3.round(thispt[0] + (denom1 && numx / denom1), 2),\n            d3.round(thispt[1] + (denom1 && numy / denom1), 2)\n        ], [\n            d3.round(thispt[0] - (denom2 && numx / denom2), 2),\n            d3.round(thispt[1] - (denom2 && numy / denom2), 2)\n        ]\n    ];\n}\n\n// step paths - returns a generator function for paths\n// with the given step shape\nvar STEPPATH = {\n    hv: function(p0, p1) {\n        return 'H' + d3.round(p1[0], 2) + 'V' + d3.round(p1[1], 2);\n    },\n    vh: function(p0, p1) {\n        return 'V' + d3.round(p1[1], 2) + 'H' + d3.round(p1[0], 2);\n    },\n    hvh: function(p0, p1) {\n        return 'H' + d3.round((p0[0] + p1[0]) / 2, 2) + 'V' +\n            d3.round(p1[1], 2) + 'H' + d3.round(p1[0], 2);\n    },\n    vhv: function(p0, p1) {\n        return 'V' + d3.round((p0[1] + p1[1]) / 2, 2) + 'H' +\n            d3.round(p1[0], 2) + 'V' + d3.round(p1[1], 2);\n    }\n};\nvar STEPLINEAR = function(p0, p1) {\n    return 'L' + d3.round(p1[0], 2) + ',' + d3.round(p1[1], 2);\n};\ndrawing.steps = function(shape) {\n    var onestep = STEPPATH[shape] || STEPLINEAR;\n    return function(pts) {\n        var path = 'M' + d3.round(pts[0][0], 2) + ',' + d3.round(pts[0][1], 2);\n        for(var i = 1; i < pts.length; i++) {\n            path += onestep(pts[i - 1], pts[i]);\n        }\n        return path;\n    };\n};\n\n// off-screen svg render testing element, shared by the whole page\n// uses the id 'js-plotly-tester' and stores it in drawing.tester\ndrawing.makeTester = function() {\n    var tester = Lib.ensureSingleById(d3.select('body'), 'svg', 'js-plotly-tester', function(s) {\n        s.attr(xmlnsNamespaces.svgAttrs)\n            .style({\n                position: 'absolute',\n                left: '-10000px',\n                top: '-10000px',\n                width: '9000px',\n                height: '9000px',\n                'z-index': '1'\n            });\n    });\n\n    // browsers differ on how they describe the bounding rect of\n    // the svg if its contents spill over... so make a 1x1px\n    // reference point we can measure off of.\n    var testref = Lib.ensureSingle(tester, 'path', 'js-reference-point', function(s) {\n        s.attr('d', 'M0,0H1V1H0Z')\n            .style({\n                'stroke-width': 0,\n                fill: 'black'\n            });\n    });\n\n    drawing.tester = tester;\n    drawing.testref = testref;\n};\n\n/*\n * use our offscreen tester to get a clientRect for an element,\n * in a reference frame where it isn't translated (or transformed) and\n * its anchor point is at (0,0)\n * always returns a copy of the bbox, so the caller can modify it safely\n *\n * @param {SVGElement} node: the element to measure. If possible this should be\n *   a <text> or MathJax <g> element that's already passed through\n *   `convertToTspans` because in that case we can cache the results, but it's\n *   possible to pass in any svg element.\n *\n * @param {boolean} inTester: is this element already in `drawing.tester`?\n *   If you are measuring a dummy element, rather than one you really intend\n *   to use on the plot, making it in `drawing.tester` in the first place\n *   allows us to test faster because it cuts out cloning and appending it.\n *\n * @param {string} hash: for internal use only, if we already know the cache key\n *   for this element beforehand.\n *\n * @return {object}: a plain object containing the width, height, left, right,\n *   top, and bottom of `node`\n */\ndrawing.savedBBoxes = {};\nvar savedBBoxesCount = 0;\nvar maxSavedBBoxes = 10000;\n\ndrawing.bBox = function(node, inTester, hash) {\n    /*\n     * Cache elements we've already measured so we don't have to\n     * remeasure the same thing many times\n     * We have a few bBox callers though who pass a node larger than\n     * a <text> or a MathJax <g>, such as an axis group containing many labels.\n     * These will not generate a hash (unless we figure out an appropriate\n     * hash key for them) and thus we will not hash them.\n     */\n    if(!hash) hash = nodeHash(node);\n    var out;\n    if(hash) {\n        out = drawing.savedBBoxes[hash];\n        if(out) return Lib.extendFlat({}, out);\n    } else if(node.childNodes.length === 1) {\n        /*\n         * If we have only one child element, which is itself hashable, make\n         * a new hash from this element plus its x,y,transform\n         * These bounding boxes *include* x,y,transform - mostly for use by\n         * callers trying to avoid overlaps (ie titles)\n         */\n        var innerNode = node.childNodes[0];\n\n        hash = nodeHash(innerNode);\n        if(hash) {\n            var x = +innerNode.getAttribute('x') || 0;\n            var y = +innerNode.getAttribute('y') || 0;\n            var transform = innerNode.getAttribute('transform');\n\n            if(!transform) {\n                // in this case, just varying x and y, don't bother caching\n                // the final bBox because the alteration is quick.\n                var innerBB = drawing.bBox(innerNode, false, hash);\n                if(x) {\n                    innerBB.left += x;\n                    innerBB.right += x;\n                }\n                if(y) {\n                    innerBB.top += y;\n                    innerBB.bottom += y;\n                }\n                return innerBB;\n            }\n            /*\n             * else we have a transform - rather than make a complicated\n             * (and error-prone and probably slow) transform parser/calculator,\n             * just continue on calculating the boundingClientRect of the group\n             * and use the new composite hash to cache it.\n             * That said, `innerNode.transform.baseVal` is an array of\n             * `SVGTransform` objects, that *do* seem to have a nice matrix\n             * multiplication interface that we could use to avoid making\n             * another getBoundingClientRect call...\n             */\n            hash += '~' + x + '~' + y + '~' + transform;\n\n            out = drawing.savedBBoxes[hash];\n            if(out) return Lib.extendFlat({}, out);\n        }\n    }\n    var testNode, tester;\n    if(inTester) {\n        testNode = node;\n    } else {\n        tester = drawing.tester.node();\n\n        // copy the node to test into the tester\n        testNode = node.cloneNode(true);\n        tester.appendChild(testNode);\n    }\n\n    // standardize its position (and newline tspans if any)\n    d3.select(testNode)\n        .attr('transform', null)\n        .call(svgTextUtils.positionText, 0, 0);\n\n    var testRect = testNode.getBoundingClientRect();\n    var refRect = drawing.testref\n        .node()\n        .getBoundingClientRect();\n\n    if(!inTester) tester.removeChild(testNode);\n\n    var bb = {\n        height: testRect.height,\n        width: testRect.width,\n        left: testRect.left - refRect.left,\n        top: testRect.top - refRect.top,\n        right: testRect.right - refRect.left,\n        bottom: testRect.bottom - refRect.top\n    };\n\n    // make sure we don't have too many saved boxes,\n    // or a long session could overload on memory\n    // by saving boxes for long-gone elements\n    if(savedBBoxesCount >= maxSavedBBoxes) {\n        drawing.savedBBoxes = {};\n        savedBBoxesCount = 0;\n    }\n\n    // cache this bbox\n    if(hash) drawing.savedBBoxes[hash] = bb;\n    savedBBoxesCount++;\n\n    return Lib.extendFlat({}, bb);\n};\n\n// capture everything about a node (at least in our usage) that\n// impacts its bounding box, given that bBox clears x, y, and transform\nfunction nodeHash(node) {\n    var inputText = node.getAttribute('data-unformatted');\n    if(inputText === null) return;\n    return inputText +\n        node.getAttribute('data-math') +\n        node.getAttribute('text-anchor') +\n        node.getAttribute('style');\n}\n\n/**\n * Set clipPath URL in a way that work for all situations.\n *\n * In details, graphs on pages with <base> HTML tags need to prepend\n * the clip path ids with the page's base url EXCEPT during toImage exports.\n *\n * @param {d3 selection} s : node to add clip-path attribute\n * @param {string} localId : local clip-path (w/o base url) id\n * @param {DOM element || object} gd\n * - context._baseUrl {string}\n * - context._exportedPlot {boolean}\n */\ndrawing.setClipUrl = function(s, localId, gd) {\n    s.attr('clip-path', getFullUrl(localId, gd));\n};\n\nfunction getFullUrl(localId, gd) {\n    if(!localId) return null;\n\n    var context = gd._context;\n    var baseUrl = context._exportedPlot ? '' : (context._baseUrl || '');\n    return 'url(\\'' + baseUrl + '#' + localId + '\\')';\n}\n\ndrawing.getTranslate = function(element) {\n    // Note the separator [^\\d] between x and y in this regex\n    // We generally use ',' but IE will convert it to ' '\n    var re = /.*\\btranslate\\((-?\\d*\\.?\\d*)[^-\\d]*(-?\\d*\\.?\\d*)[^\\d].*/;\n    var getter = element.attr ? 'attr' : 'getAttribute';\n    var transform = element[getter]('transform') || '';\n\n    var translate = transform.replace(re, function(match, p1, p2) {\n        return [p1, p2].join(' ');\n    })\n    .split(' ');\n\n    return {\n        x: +translate[0] || 0,\n        y: +translate[1] || 0\n    };\n};\n\ndrawing.setTranslate = function(element, x, y) {\n    var re = /(\\btranslate\\(.*?\\);?)/;\n    var getter = element.attr ? 'attr' : 'getAttribute';\n    var setter = element.attr ? 'attr' : 'setAttribute';\n    var transform = element[getter]('transform') || '';\n\n    x = x || 0;\n    y = y || 0;\n\n    transform = transform.replace(re, '').trim();\n    transform += ' translate(' + x + ', ' + y + ')';\n    transform = transform.trim();\n\n    element[setter]('transform', transform);\n\n    return transform;\n};\n\ndrawing.getScale = function(element) {\n    var re = /.*\\bscale\\((\\d*\\.?\\d*)[^\\d]*(\\d*\\.?\\d*)[^\\d].*/;\n    var getter = element.attr ? 'attr' : 'getAttribute';\n    var transform = element[getter]('transform') || '';\n\n    var translate = transform.replace(re, function(match, p1, p2) {\n        return [p1, p2].join(' ');\n    })\n    .split(' ');\n\n    return {\n        x: +translate[0] || 1,\n        y: +translate[1] || 1\n    };\n};\n\ndrawing.setScale = function(element, x, y) {\n    var re = /(\\bscale\\(.*?\\);?)/;\n    var getter = element.attr ? 'attr' : 'getAttribute';\n    var setter = element.attr ? 'attr' : 'setAttribute';\n    var transform = element[getter]('transform') || '';\n\n    x = x || 1;\n    y = y || 1;\n\n    transform = transform.replace(re, '').trim();\n    transform += ' scale(' + x + ', ' + y + ')';\n    transform = transform.trim();\n\n    element[setter]('transform', transform);\n\n    return transform;\n};\n\nvar SCALE_RE = /\\s*sc.*/;\n\ndrawing.setPointGroupScale = function(selection, xScale, yScale) {\n    xScale = xScale || 1;\n    yScale = yScale || 1;\n\n    if(!selection) return;\n\n    // The same scale transform for every point:\n    var scale = (xScale === 1 && yScale === 1) ?\n        '' :\n        ' scale(' + xScale + ',' + yScale + ')';\n\n    selection.each(function() {\n        var t = (this.getAttribute('transform') || '').replace(SCALE_RE, '');\n        t += scale;\n        t = t.trim();\n        this.setAttribute('transform', t);\n    });\n};\n\nvar TEXT_POINT_LAST_TRANSLATION_RE = /translate\\([^)]*\\)\\s*$/;\n\ndrawing.setTextPointsScale = function(selection, xScale, yScale) {\n    if(!selection) return;\n\n    selection.each(function() {\n        var transforms;\n        var el = d3.select(this);\n        var text = el.select('text');\n\n        if(!text.node()) return;\n\n        var x = parseFloat(text.attr('x') || 0);\n        var y = parseFloat(text.attr('y') || 0);\n\n        var existingTransform = (el.attr('transform') || '').match(TEXT_POINT_LAST_TRANSLATION_RE);\n\n        if(xScale === 1 && yScale === 1) {\n            transforms = [];\n        } else {\n            transforms = [\n                'translate(' + x + ',' + y + ')',\n                'scale(' + xScale + ',' + yScale + ')',\n                'translate(' + (-x) + ',' + (-y) + ')',\n            ];\n        }\n\n        if(existingTransform) {\n            transforms.push(existingTransform);\n        }\n\n        el.attr('transform', transforms.join(' '));\n    });\n};\n\n},{\"../../constants/alignment\":688,\"../../constants/interactions\":694,\"../../constants/xmlns_namespaces\":696,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../registry\":847,\"../../traces/scatter/make_bubble_size_func\":1128,\"../../traces/scatter/subtypes\":1135,\"../color\":593,\"../colorscale\":605,\"./symbol_defs\":615,\"d3\":163,\"fast-isnumeric\":225,\"tinycolor2\":537}],615:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\n/** Marker symbol definitions\n * users can specify markers either by number or name\n * add 100 (or '-open') and you get an open marker\n *  open markers have no fill and use line color as the stroke color\n * add 200 (or '-dot') and you get a dot in the middle\n * add both and you get both\n */\n\nmodule.exports = {\n    circle: {\n        n: 0,\n        f: function(r) {\n            var rs = d3.round(r, 2);\n            return 'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs +\n                'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z';\n        }\n    },\n    square: {\n        n: 1,\n        f: function(r) {\n            var rs = d3.round(r, 2);\n            return 'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z';\n        }\n    },\n    diamond: {\n        n: 2,\n        f: function(r) {\n            var rd = d3.round(r * 1.3, 2);\n            return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z';\n        }\n    },\n    cross: {\n        n: 3,\n        f: function(r) {\n            var rc = d3.round(r * 0.4, 2);\n            var rc2 = d3.round(r * 1.2, 2);\n            return 'M' + rc2 + ',' + rc + 'H' + rc + 'V' + rc2 + 'H-' + rc +\n                'V' + rc + 'H-' + rc2 + 'V-' + rc + 'H-' + rc + 'V-' + rc2 +\n                'H' + rc + 'V-' + rc + 'H' + rc2 + 'Z';\n        }\n    },\n    x: {\n        n: 4,\n        f: function(r) {\n            var rx = d3.round(r * 0.8 / Math.sqrt(2), 2);\n            var ne = 'l' + rx + ',' + rx;\n            var se = 'l' + rx + ',-' + rx;\n            var sw = 'l-' + rx + ',-' + rx;\n            var nw = 'l-' + rx + ',' + rx;\n            return 'M0,' + rx + ne + se + sw + se + sw + nw + sw + nw + ne + nw + ne + 'Z';\n        }\n    },\n    'triangle-up': {\n        n: 5,\n        f: function(r) {\n            var rt = d3.round(r * 2 / Math.sqrt(3), 2);\n            var r2 = d3.round(r / 2, 2);\n            var rs = d3.round(r, 2);\n            return 'M-' + rt + ',' + r2 + 'H' + rt + 'L0,-' + rs + 'Z';\n        }\n    },\n    'triangle-down': {\n        n: 6,\n        f: function(r) {\n            var rt = d3.round(r * 2 / Math.sqrt(3), 2);\n            var r2 = d3.round(r / 2, 2);\n            var rs = d3.round(r, 2);\n            return 'M-' + rt + ',-' + r2 + 'H' + rt + 'L0,' + rs + 'Z';\n        }\n    },\n    'triangle-left': {\n        n: 7,\n        f: function(r) {\n            var rt = d3.round(r * 2 / Math.sqrt(3), 2);\n            var r2 = d3.round(r / 2, 2);\n            var rs = d3.round(r, 2);\n            return 'M' + r2 + ',-' + rt + 'V' + rt + 'L-' + rs + ',0Z';\n        }\n    },\n    'triangle-right': {\n        n: 8,\n        f: function(r) {\n            var rt = d3.round(r * 2 / Math.sqrt(3), 2);\n            var r2 = d3.round(r / 2, 2);\n            var rs = d3.round(r, 2);\n            return 'M-' + r2 + ',-' + rt + 'V' + rt + 'L' + rs + ',0Z';\n        }\n    },\n    'triangle-ne': {\n        n: 9,\n        f: function(r) {\n            var r1 = d3.round(r * 0.6, 2);\n            var r2 = d3.round(r * 1.2, 2);\n            return 'M-' + r2 + ',-' + r1 + 'H' + r1 + 'V' + r2 + 'Z';\n        }\n    },\n    'triangle-se': {\n        n: 10,\n        f: function(r) {\n            var r1 = d3.round(r * 0.6, 2);\n            var r2 = d3.round(r * 1.2, 2);\n            return 'M' + r1 + ',-' + r2 + 'V' + r1 + 'H-' + r2 + 'Z';\n        }\n    },\n    'triangle-sw': {\n        n: 11,\n        f: function(r) {\n            var r1 = d3.round(r * 0.6, 2);\n            var r2 = d3.round(r * 1.2, 2);\n            return 'M' + r2 + ',' + r1 + 'H-' + r1 + 'V-' + r2 + 'Z';\n        }\n    },\n    'triangle-nw': {\n        n: 12,\n        f: function(r) {\n            var r1 = d3.round(r * 0.6, 2);\n            var r2 = d3.round(r * 1.2, 2);\n            return 'M-' + r1 + ',' + r2 + 'V-' + r1 + 'H' + r2 + 'Z';\n        }\n    },\n    pentagon: {\n        n: 13,\n        f: function(r) {\n            var x1 = d3.round(r * 0.951, 2);\n            var x2 = d3.round(r * 0.588, 2);\n            var y0 = d3.round(-r, 2);\n            var y1 = d3.round(r * -0.309, 2);\n            var y2 = d3.round(r * 0.809, 2);\n            return 'M' + x1 + ',' + y1 + 'L' + x2 + ',' + y2 + 'H-' + x2 +\n                'L-' + x1 + ',' + y1 + 'L0,' + y0 + 'Z';\n        }\n    },\n    hexagon: {\n        n: 14,\n        f: function(r) {\n            var y0 = d3.round(r, 2);\n            var y1 = d3.round(r / 2, 2);\n            var x = d3.round(r * Math.sqrt(3) / 2, 2);\n            return 'M' + x + ',-' + y1 + 'V' + y1 + 'L0,' + y0 +\n                'L-' + x + ',' + y1 + 'V-' + y1 + 'L0,-' + y0 + 'Z';\n        }\n    },\n    hexagon2: {\n        n: 15,\n        f: function(r) {\n            var x0 = d3.round(r, 2);\n            var x1 = d3.round(r / 2, 2);\n            var y = d3.round(r * Math.sqrt(3) / 2, 2);\n            return 'M-' + x1 + ',' + y + 'H' + x1 + 'L' + x0 +\n                ',0L' + x1 + ',-' + y + 'H-' + x1 + 'L-' + x0 + ',0Z';\n        }\n    },\n    octagon: {\n        n: 16,\n        f: function(r) {\n            var a = d3.round(r * 0.924, 2);\n            var b = d3.round(r * 0.383, 2);\n            return 'M-' + b + ',-' + a + 'H' + b + 'L' + a + ',-' + b + 'V' + b +\n                'L' + b + ',' + a + 'H-' + b + 'L-' + a + ',' + b + 'V-' + b + 'Z';\n        }\n    },\n    star: {\n        n: 17,\n        f: function(r) {\n            var rs = r * 1.4;\n            var x1 = d3.round(rs * 0.225, 2);\n            var x2 = d3.round(rs * 0.951, 2);\n            var x3 = d3.round(rs * 0.363, 2);\n            var x4 = d3.round(rs * 0.588, 2);\n            var y0 = d3.round(-rs, 2);\n            var y1 = d3.round(rs * -0.309, 2);\n            var y3 = d3.round(rs * 0.118, 2);\n            var y4 = d3.round(rs * 0.809, 2);\n            var y5 = d3.round(rs * 0.382, 2);\n            return 'M' + x1 + ',' + y1 + 'H' + x2 + 'L' + x3 + ',' + y3 +\n                'L' + x4 + ',' + y4 + 'L0,' + y5 + 'L-' + x4 + ',' + y4 +\n                'L-' + x3 + ',' + y3 + 'L-' + x2 + ',' + y1 + 'H-' + x1 +\n                'L0,' + y0 + 'Z';\n        }\n    },\n    hexagram: {\n        n: 18,\n        f: function(r) {\n            var y = d3.round(r * 0.66, 2);\n            var x1 = d3.round(r * 0.38, 2);\n            var x2 = d3.round(r * 0.76, 2);\n            return 'M-' + x2 + ',0l-' + x1 + ',-' + y + 'h' + x2 +\n                'l' + x1 + ',-' + y + 'l' + x1 + ',' + y + 'h' + x2 +\n                'l-' + x1 + ',' + y + 'l' + x1 + ',' + y + 'h-' + x2 +\n                'l-' + x1 + ',' + y + 'l-' + x1 + ',-' + y + 'h-' + x2 + 'Z';\n        }\n    },\n    'star-triangle-up': {\n        n: 19,\n        f: function(r) {\n            var x = d3.round(r * Math.sqrt(3) * 0.8, 2);\n            var y1 = d3.round(r * 0.8, 2);\n            var y2 = d3.round(r * 1.6, 2);\n            var rc = d3.round(r * 4, 2);\n            var aPart = 'A ' + rc + ',' + rc + ' 0 0 1 ';\n            return 'M-' + x + ',' + y1 + aPart + x + ',' + y1 +\n                aPart + '0,-' + y2 + aPart + '-' + x + ',' + y1 + 'Z';\n        }\n    },\n    'star-triangle-down': {\n        n: 20,\n        f: function(r) {\n            var x = d3.round(r * Math.sqrt(3) * 0.8, 2);\n            var y1 = d3.round(r * 0.8, 2);\n            var y2 = d3.round(r * 1.6, 2);\n            var rc = d3.round(r * 4, 2);\n            var aPart = 'A ' + rc + ',' + rc + ' 0 0 1 ';\n            return 'M' + x + ',-' + y1 + aPart + '-' + x + ',-' + y1 +\n                aPart + '0,' + y2 + aPart + x + ',-' + y1 + 'Z';\n        }\n    },\n    'star-square': {\n        n: 21,\n        f: function(r) {\n            var rp = d3.round(r * 1.1, 2);\n            var rc = d3.round(r * 2, 2);\n            var aPart = 'A ' + rc + ',' + rc + ' 0 0 1 ';\n            return 'M-' + rp + ',-' + rp + aPart + '-' + rp + ',' + rp +\n                aPart + rp + ',' + rp + aPart + rp + ',-' + rp +\n                aPart + '-' + rp + ',-' + rp + 'Z';\n        }\n    },\n    'star-diamond': {\n        n: 22,\n        f: function(r) {\n            var rp = d3.round(r * 1.4, 2);\n            var rc = d3.round(r * 1.9, 2);\n            var aPart = 'A ' + rc + ',' + rc + ' 0 0 1 ';\n            return 'M-' + rp + ',0' + aPart + '0,' + rp +\n                aPart + rp + ',0' + aPart + '0,-' + rp +\n                aPart + '-' + rp + ',0' + 'Z';\n        }\n    },\n    'diamond-tall': {\n        n: 23,\n        f: function(r) {\n            var x = d3.round(r * 0.7, 2);\n            var y = d3.round(r * 1.4, 2);\n            return 'M0,' + y + 'L' + x + ',0L0,-' + y + 'L-' + x + ',0Z';\n        }\n    },\n    'diamond-wide': {\n        n: 24,\n        f: function(r) {\n            var x = d3.round(r * 1.4, 2);\n            var y = d3.round(r * 0.7, 2);\n            return 'M0,' + y + 'L' + x + ',0L0,-' + y + 'L-' + x + ',0Z';\n        }\n    },\n    hourglass: {\n        n: 25,\n        f: function(r) {\n            var rs = d3.round(r, 2);\n            return 'M' + rs + ',' + rs + 'H-' + rs + 'L' + rs + ',-' + rs + 'H-' + rs + 'Z';\n        },\n        noDot: true\n    },\n    bowtie: {\n        n: 26,\n        f: function(r) {\n            var rs = d3.round(r, 2);\n            return 'M' + rs + ',' + rs + 'V-' + rs + 'L-' + rs + ',' + rs + 'V-' + rs + 'Z';\n        },\n        noDot: true\n    },\n    'circle-cross': {\n        n: 27,\n        f: function(r) {\n            var rs = d3.round(r, 2);\n            return 'M0,' + rs + 'V-' + rs + 'M' + rs + ',0H-' + rs +\n                'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs +\n                'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z';\n        },\n        needLine: true,\n        noDot: true\n    },\n    'circle-x': {\n        n: 28,\n        f: function(r) {\n            var rs = d3.round(r, 2);\n            var rc = d3.round(r / Math.sqrt(2), 2);\n            return 'M' + rc + ',' + rc + 'L-' + rc + ',-' + rc +\n                'M' + rc + ',-' + rc + 'L-' + rc + ',' + rc +\n                'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs +\n                'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z';\n        },\n        needLine: true,\n        noDot: true\n    },\n    'square-cross': {\n        n: 29,\n        f: function(r) {\n            var rs = d3.round(r, 2);\n            return 'M0,' + rs + 'V-' + rs + 'M' + rs + ',0H-' + rs +\n                'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z';\n        },\n        needLine: true,\n        noDot: true\n    },\n    'square-x': {\n        n: 30,\n        f: function(r) {\n            var rs = d3.round(r, 2);\n            return 'M' + rs + ',' + rs + 'L-' + rs + ',-' + rs +\n                'M' + rs + ',-' + rs + 'L-' + rs + ',' + rs +\n                'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z';\n        },\n        needLine: true,\n        noDot: true\n    },\n    'diamond-cross': {\n        n: 31,\n        f: function(r) {\n            var rd = d3.round(r * 1.3, 2);\n            return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z' +\n                'M0,-' + rd + 'V' + rd + 'M-' + rd + ',0H' + rd;\n        },\n        needLine: true,\n        noDot: true\n    },\n    'diamond-x': {\n        n: 32,\n        f: function(r) {\n            var rd = d3.round(r * 1.3, 2);\n            var r2 = d3.round(r * 0.65, 2);\n            return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z' +\n                'M-' + r2 + ',-' + r2 + 'L' + r2 + ',' + r2 +\n                'M-' + r2 + ',' + r2 + 'L' + r2 + ',-' + r2;\n        },\n        needLine: true,\n        noDot: true\n    },\n    'cross-thin': {\n        n: 33,\n        f: function(r) {\n            var rc = d3.round(r * 1.4, 2);\n            return 'M0,' + rc + 'V-' + rc + 'M' + rc + ',0H-' + rc;\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    'x-thin': {\n        n: 34,\n        f: function(r) {\n            var rx = d3.round(r, 2);\n            return 'M' + rx + ',' + rx + 'L-' + rx + ',-' + rx +\n                'M' + rx + ',-' + rx + 'L-' + rx + ',' + rx;\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    asterisk: {\n        n: 35,\n        f: function(r) {\n            var rc = d3.round(r * 1.2, 2);\n            var rs = d3.round(r * 0.85, 2);\n            return 'M0,' + rc + 'V-' + rc + 'M' + rc + ',0H-' + rc +\n                'M' + rs + ',' + rs + 'L-' + rs + ',-' + rs +\n                'M' + rs + ',-' + rs + 'L-' + rs + ',' + rs;\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    hash: {\n        n: 36,\n        f: function(r) {\n            var r1 = d3.round(r / 2, 2);\n            var r2 = d3.round(r, 2);\n            return 'M' + r1 + ',' + r2 + 'V-' + r2 +\n                'm-' + r2 + ',0V' + r2 +\n                'M' + r2 + ',' + r1 + 'H-' + r2 +\n                'm0,-' + r2 + 'H' + r2;\n        },\n        needLine: true,\n        noFill: true\n    },\n    'y-up': {\n        n: 37,\n        f: function(r) {\n            var x = d3.round(r * 1.2, 2);\n            var y0 = d3.round(r * 1.6, 2);\n            var y1 = d3.round(r * 0.8, 2);\n            return 'M-' + x + ',' + y1 + 'L0,0M' + x + ',' + y1 + 'L0,0M0,-' + y0 + 'L0,0';\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    'y-down': {\n        n: 38,\n        f: function(r) {\n            var x = d3.round(r * 1.2, 2);\n            var y0 = d3.round(r * 1.6, 2);\n            var y1 = d3.round(r * 0.8, 2);\n            return 'M-' + x + ',-' + y1 + 'L0,0M' + x + ',-' + y1 + 'L0,0M0,' + y0 + 'L0,0';\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    'y-left': {\n        n: 39,\n        f: function(r) {\n            var y = d3.round(r * 1.2, 2);\n            var x0 = d3.round(r * 1.6, 2);\n            var x1 = d3.round(r * 0.8, 2);\n            return 'M' + x1 + ',' + y + 'L0,0M' + x1 + ',-' + y + 'L0,0M-' + x0 + ',0L0,0';\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    'y-right': {\n        n: 40,\n        f: function(r) {\n            var y = d3.round(r * 1.2, 2);\n            var x0 = d3.round(r * 1.6, 2);\n            var x1 = d3.round(r * 0.8, 2);\n            return 'M-' + x1 + ',' + y + 'L0,0M-' + x1 + ',-' + y + 'L0,0M' + x0 + ',0L0,0';\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    'line-ew': {\n        n: 41,\n        f: function(r) {\n            var rc = d3.round(r * 1.4, 2);\n            return 'M' + rc + ',0H-' + rc;\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    'line-ns': {\n        n: 42,\n        f: function(r) {\n            var rc = d3.round(r * 1.4, 2);\n            return 'M0,' + rc + 'V-' + rc;\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    'line-ne': {\n        n: 43,\n        f: function(r) {\n            var rx = d3.round(r, 2);\n            return 'M' + rx + ',-' + rx + 'L-' + rx + ',' + rx;\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    },\n    'line-nw': {\n        n: 44,\n        f: function(r) {\n            var rx = d3.round(r, 2);\n            return 'M' + rx + ',' + rx + 'L-' + rx + ',-' + rx;\n        },\n        needLine: true,\n        noDot: true,\n        noFill: true\n    }\n};\n\n},{\"d3\":163}],616:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n    visible: {\n        valType: 'boolean',\n        \n        editType: 'calc',\n        \n    },\n    type: {\n        valType: 'enumerated',\n        values: ['percent', 'constant', 'sqrt', 'data'],\n        \n        editType: 'calc',\n        \n    },\n    symmetric: {\n        valType: 'boolean',\n        \n        editType: 'calc',\n        \n    },\n    array: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    arrayminus: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    value: {\n        valType: 'number',\n        min: 0,\n        dflt: 10,\n        \n        editType: 'calc',\n        \n    },\n    valueminus: {\n        valType: 'number',\n        min: 0,\n        dflt: 10,\n        \n        editType: 'calc',\n        \n    },\n    traceref: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'style'\n    },\n    tracerefminus: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'style'\n    },\n    copy_ystyle: {\n        valType: 'boolean',\n        \n        editType: 'plot'\n    },\n    copy_zstyle: {\n        valType: 'boolean',\n        \n        editType: 'style'\n    },\n    color: {\n        valType: 'color',\n        \n        editType: 'style',\n        \n    },\n    thickness: {\n        valType: 'number',\n        min: 0,\n        dflt: 2,\n        \n        editType: 'style',\n        \n    },\n    width: {\n        valType: 'number',\n        min: 0,\n        \n        editType: 'plot',\n        \n    },\n    editType: 'calc',\n\n    _deprecated: {\n        opacity: {\n            valType: 'number',\n            \n            editType: 'style',\n            \n        }\n    }\n};\n\n},{}],617:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Registry = _dereq_('../../registry');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Lib = _dereq_('../../lib');\n\nvar makeComputeError = _dereq_('./compute_error');\n\nmodule.exports = function calc(gd) {\n    var calcdata = gd.calcdata;\n\n    for(var i = 0; i < calcdata.length; i++) {\n        var calcTrace = calcdata[i];\n        var trace = calcTrace[0].trace;\n\n        if(trace.visible === true && Registry.traceIs(trace, 'errorBarsOK')) {\n            var xa = Axes.getFromId(gd, trace.xaxis);\n            var ya = Axes.getFromId(gd, trace.yaxis);\n            calcOneAxis(calcTrace, trace, xa, 'x');\n            calcOneAxis(calcTrace, trace, ya, 'y');\n        }\n    }\n};\n\nfunction calcOneAxis(calcTrace, trace, axis, coord) {\n    var opts = trace['error_' + coord] || {};\n    var isVisible = (opts.visible && ['linear', 'log'].indexOf(axis.type) !== -1);\n    var vals = [];\n\n    if(!isVisible) return;\n\n    var computeError = makeComputeError(opts);\n\n    for(var i = 0; i < calcTrace.length; i++) {\n        var calcPt = calcTrace[i];\n\n        var iIn = calcPt.i;\n\n        // for types that don't include `i` in each calcdata point\n        if(iIn === undefined) iIn = i;\n\n        // for stacked area inserted points\n        // TODO: errorbars have been tested cursorily with stacked area,\n        // but not thoroughly. It's not even really clear what you want to do:\n        // Should it just be calculated based on that trace's size data?\n        // Should you add errors from below in quadrature?\n        // And what about normalization, where in principle the errors shrink\n        // again when you get up to the top end?\n        // One option would be to forbid errorbars with stacking until we\n        // decide how to handle these questions.\n        else if(iIn === null) continue;\n\n        var calcCoord = calcPt[coord];\n\n        if(!isNumeric(axis.c2l(calcCoord))) continue;\n\n        var errors = computeError(calcCoord, iIn);\n        if(isNumeric(errors[0]) && isNumeric(errors[1])) {\n            var shoe = calcPt[coord + 's'] = calcCoord - errors[0];\n            var hat = calcPt[coord + 'h'] = calcCoord + errors[1];\n            vals.push(shoe, hat);\n        }\n    }\n\n    var axId = axis._id;\n    var baseExtremes = trace._extremes[axId];\n    var extremes = Axes.findExtremes(\n        axis,\n        vals,\n        Lib.extendFlat({tozero: baseExtremes.opts.tozero}, {padded: true})\n    );\n    baseExtremes.min = baseExtremes.min.concat(extremes.min);\n    baseExtremes.max = baseExtremes.max.concat(extremes.max);\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"./compute_error\":618,\"fast-isnumeric\":225}],618:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\n/**\n * Error bar computing function generator\n *\n * N.B. The generated function does not clean the dataPt entries. Non-numeric\n * entries result in undefined error magnitudes.\n *\n * @param {object} opts error bar attributes\n *\n * @return {function} :\n *      @param {numeric} dataPt data point from where to compute the error magnitude\n *      @param {number} index index of dataPt in its corresponding data array\n *      @return {array}\n *        - error[0] : error magnitude in the negative direction\n *        - error[1] : \" \" \" \" positive \"\n */\nmodule.exports = function makeComputeError(opts) {\n    var type = opts.type;\n    var symmetric = opts.symmetric;\n\n    if(type === 'data') {\n        var array = opts.array || [];\n\n        if(symmetric) {\n            return function computeError(dataPt, index) {\n                var val = +(array[index]);\n                return [val, val];\n            };\n        } else {\n            var arrayminus = opts.arrayminus || [];\n            return function computeError(dataPt, index) {\n                var val = +array[index];\n                var valMinus = +arrayminus[index];\n                // in case one is present and the other is missing, fill in 0\n                // so we still see the present one. Mostly useful during manual\n                // data entry.\n                if(!isNaN(val) || !isNaN(valMinus)) {\n                    return [valMinus || 0, val || 0];\n                }\n                return [NaN, NaN];\n            };\n        }\n    } else {\n        var computeErrorValue = makeComputeErrorValue(type, opts.value);\n        var computeErrorValueMinus = makeComputeErrorValue(type, opts.valueminus);\n\n        if(symmetric || opts.valueminus === undefined) {\n            return function computeError(dataPt) {\n                var val = computeErrorValue(dataPt);\n                return [val, val];\n            };\n        } else {\n            return function computeError(dataPt) {\n                return [\n                    computeErrorValueMinus(dataPt),\n                    computeErrorValue(dataPt)\n                ];\n            };\n        }\n    }\n};\n\n/**\n * Compute error bar magnitude (for all types except data)\n *\n * @param {string} type error bar type\n * @param {numeric} value error bar value\n *\n * @return {function} :\n *      @param {numeric} dataPt\n */\nfunction makeComputeErrorValue(type, value) {\n    if(type === 'percent') {\n        return function(dataPt) {\n            return Math.abs(dataPt * value / 100);\n        };\n    }\n    if(type === 'constant') {\n        return function() {\n            return Math.abs(value);\n        };\n    }\n    if(type === 'sqrt') {\n        return function(dataPt) {\n            return Math.sqrt(Math.abs(dataPt));\n        };\n    }\n}\n\n},{}],619:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Template = _dereq_('../../plot_api/plot_template');\n\nvar attributes = _dereq_('./attributes');\n\n\nmodule.exports = function(traceIn, traceOut, defaultColor, opts) {\n    var objName = 'error_' + opts.axis;\n    var containerOut = Template.newContainer(traceOut, objName);\n    var containerIn = traceIn[objName] || {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);\n    }\n\n    var hasErrorBars = (\n        containerIn.array !== undefined ||\n        containerIn.value !== undefined ||\n        containerIn.type === 'sqrt'\n    );\n\n    var visible = coerce('visible', hasErrorBars);\n\n    if(visible === false) return;\n\n    var type = coerce('type', 'array' in containerIn ? 'data' : 'percent');\n    var symmetric = true;\n\n    if(type !== 'sqrt') {\n        symmetric = coerce('symmetric',\n            !((type === 'data' ? 'arrayminus' : 'valueminus') in containerIn));\n    }\n\n    if(type === 'data') {\n        coerce('array');\n        coerce('traceref');\n        if(!symmetric) {\n            coerce('arrayminus');\n            coerce('tracerefminus');\n        }\n    } else if(type === 'percent' || type === 'constant') {\n        coerce('value');\n        if(!symmetric) coerce('valueminus');\n    }\n\n    var copyAttr = 'copy_' + opts.inherit + 'style';\n    if(opts.inherit) {\n        var inheritObj = traceOut['error_' + opts.inherit];\n        if((inheritObj || {}).visible) {\n            coerce(copyAttr, !(containerIn.color ||\n                               isNumeric(containerIn.thickness) ||\n                               isNumeric(containerIn.width)));\n        }\n    }\n    if(!opts.inherit || !containerOut[copyAttr]) {\n        coerce('color', defaultColor);\n        coerce('thickness');\n        coerce('width', Registry.traceIs(traceOut, 'gl3d') ? 0 : 4);\n    }\n};\n\n},{\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../registry\":847,\"./attributes\":616,\"fast-isnumeric\":225}],620:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar attributes = _dereq_('./attributes');\n\nvar xyAttrs = {\n    error_x: Lib.extendFlat({}, attributes),\n    error_y: Lib.extendFlat({}, attributes)\n};\ndelete xyAttrs.error_x.copy_zstyle;\ndelete xyAttrs.error_y.copy_zstyle;\ndelete xyAttrs.error_y.copy_ystyle;\n\nvar xyzAttrs = {\n    error_x: Lib.extendFlat({}, attributes),\n    error_y: Lib.extendFlat({}, attributes),\n    error_z: Lib.extendFlat({}, attributes)\n};\ndelete xyzAttrs.error_x.copy_ystyle;\ndelete xyzAttrs.error_y.copy_ystyle;\ndelete xyzAttrs.error_z.copy_ystyle;\ndelete xyzAttrs.error_z.copy_zstyle;\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'errorbars',\n\n    schema: {\n        traces: {\n            scatter: xyAttrs,\n            bar: xyAttrs,\n            histogram: xyAttrs,\n            scatter3d: overrideAll(xyzAttrs, 'calc', 'nested'),\n            scattergl: overrideAll(xyAttrs, 'calc', 'nested')\n        }\n    },\n\n    supplyDefaults: _dereq_('./defaults'),\n\n    calc: _dereq_('./calc'),\n    makeComputeError: _dereq_('./compute_error'),\n\n    plot: _dereq_('./plot'),\n    style: _dereq_('./style'),\n    hoverInfo: hoverInfo\n};\n\nfunction hoverInfo(calcPoint, trace, hoverPoint) {\n    if((trace.error_y || {}).visible) {\n        hoverPoint.yerr = calcPoint.yh - calcPoint.y;\n        if(!trace.error_y.symmetric) hoverPoint.yerrneg = calcPoint.y - calcPoint.ys;\n    }\n    if((trace.error_x || {}).visible) {\n        hoverPoint.xerr = calcPoint.xh - calcPoint.x;\n        if(!trace.error_x.symmetric) hoverPoint.xerrneg = calcPoint.x - calcPoint.xs;\n    }\n}\n\n},{\"../../lib\":719,\"../../plot_api/edit_types\":750,\"./attributes\":616,\"./calc\":617,\"./compute_error\":618,\"./defaults\":619,\"./plot\":621,\"./style\":622}],621:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Drawing = _dereq_('../drawing');\nvar subTypes = _dereq_('../../traces/scatter/subtypes');\n\nmodule.exports = function plot(gd, traces, plotinfo, transitionOpts) {\n    var isNew;\n\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    var hasAnimation = transitionOpts && transitionOpts.duration > 0;\n\n    traces.each(function(d) {\n        var trace = d[0].trace;\n        // || {} is in case the trace (specifically scatterternary)\n        // doesn't support error bars at all, but does go through\n        // the scatter.plot mechanics, which calls ErrorBars.plot\n        // internally\n        var xObj = trace.error_x || {};\n        var yObj = trace.error_y || {};\n\n        var keyFunc;\n\n        if(trace.ids) {\n            keyFunc = function(d) {return d.id;};\n        }\n\n        var sparse = (\n            subTypes.hasMarkers(trace) &&\n            trace.marker.maxdisplayed > 0\n        );\n\n        if(!yObj.visible && !xObj.visible) d = [];\n\n        var errorbars = d3.select(this).selectAll('g.errorbar')\n            .data(d, keyFunc);\n\n        errorbars.exit().remove();\n\n        if(!d.length) return;\n\n        if(!xObj.visible) errorbars.selectAll('path.xerror').remove();\n        if(!yObj.visible) errorbars.selectAll('path.yerror').remove();\n\n        errorbars.style('opacity', 1);\n\n        var enter = errorbars.enter().append('g')\n            .classed('errorbar', true);\n\n        if(hasAnimation) {\n            enter.style('opacity', 0).transition()\n                .duration(transitionOpts.duration)\n                .style('opacity', 1);\n        }\n\n        Drawing.setClipUrl(errorbars, plotinfo.layerClipId, gd);\n\n        errorbars.each(function(d) {\n            var errorbar = d3.select(this);\n            var coords = errorCoords(d, xa, ya);\n\n            if(sparse && !d.vis) return;\n\n            var path;\n\n            var yerror = errorbar.select('path.yerror');\n            if(yObj.visible && isNumeric(coords.x) &&\n                    isNumeric(coords.yh) &&\n                    isNumeric(coords.ys)) {\n                var yw = yObj.width;\n\n                path = 'M' + (coords.x - yw) + ',' +\n                    coords.yh + 'h' + (2 * yw) + // hat\n                    'm-' + yw + ',0V' + coords.ys; // bar\n\n\n                if(!coords.noYS) path += 'm-' + yw + ',0h' + (2 * yw); // shoe\n\n                isNew = !yerror.size();\n\n                if(isNew) {\n                    yerror = errorbar.append('path')\n                        .style('vector-effect', 'non-scaling-stroke')\n                        .classed('yerror', true);\n                } else if(hasAnimation) {\n                    yerror = yerror\n                        .transition()\n                            .duration(transitionOpts.duration)\n                            .ease(transitionOpts.easing);\n                }\n\n                yerror.attr('d', path);\n            } else yerror.remove();\n\n            var xerror = errorbar.select('path.xerror');\n            if(xObj.visible && isNumeric(coords.y) &&\n                    isNumeric(coords.xh) &&\n                    isNumeric(coords.xs)) {\n                var xw = (xObj.copy_ystyle ? yObj : xObj).width;\n\n                path = 'M' + coords.xh + ',' +\n                    (coords.y - xw) + 'v' + (2 * xw) + // hat\n                    'm0,-' + xw + 'H' + coords.xs; // bar\n\n                if(!coords.noXS) path += 'm0,-' + xw + 'v' + (2 * xw); // shoe\n\n                isNew = !xerror.size();\n\n                if(isNew) {\n                    xerror = errorbar.append('path')\n                        .style('vector-effect', 'non-scaling-stroke')\n                        .classed('xerror', true);\n                } else if(hasAnimation) {\n                    xerror = xerror\n                        .transition()\n                            .duration(transitionOpts.duration)\n                            .ease(transitionOpts.easing);\n                }\n\n                xerror.attr('d', path);\n            } else xerror.remove();\n        });\n    });\n};\n\n// compute the coordinates of the error-bar objects\nfunction errorCoords(d, xa, ya) {\n    var out = {\n        x: xa.c2p(d.x),\n        y: ya.c2p(d.y)\n    };\n\n    // calculate the error bar size and hat and shoe locations\n    if(d.yh !== undefined) {\n        out.yh = ya.c2p(d.yh);\n        out.ys = ya.c2p(d.ys);\n\n        // if the shoes go off-scale (ie log scale, error bars past zero)\n        // clip the bar and hide the shoes\n        if(!isNumeric(out.ys)) {\n            out.noYS = true;\n            out.ys = ya.c2p(d.ys, true);\n        }\n    }\n\n    if(d.xh !== undefined) {\n        out.xh = xa.c2p(d.xh);\n        out.xs = xa.c2p(d.xs);\n\n        if(!isNumeric(out.xs)) {\n            out.noXS = true;\n            out.xs = xa.c2p(d.xs, true);\n        }\n    }\n\n    return out;\n}\n\n},{\"../../traces/scatter/subtypes\":1135,\"../drawing\":614,\"d3\":163,\"fast-isnumeric\":225}],622:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Color = _dereq_('../color');\n\n\nmodule.exports = function style(traces) {\n    traces.each(function(d) {\n        var trace = d[0].trace;\n        var yObj = trace.error_y || {};\n        var xObj = trace.error_x || {};\n\n        var s = d3.select(this);\n\n        s.selectAll('path.yerror')\n            .style('stroke-width', yObj.thickness + 'px')\n            .call(Color.stroke, yObj.color);\n\n        if(xObj.copy_ystyle) xObj = yObj;\n\n        s.selectAll('path.xerror')\n            .style('stroke-width', xObj.thickness + 'px')\n            .call(Color.stroke, xObj.color);\n    });\n};\n\n},{\"../color\":593,\"d3\":163}],623:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar hoverLabelAttrs = _dereq_('./layout_attributes').hoverlabel;\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = {\n    hoverlabel: {\n        bgcolor: extendFlat({}, hoverLabelAttrs.bgcolor, {\n            arrayOk: true,\n            \n        }),\n        bordercolor: extendFlat({}, hoverLabelAttrs.bordercolor, {\n            arrayOk: true,\n            \n        }),\n        font: fontAttrs({\n            arrayOk: true,\n            editType: 'none',\n            \n        }),\n        align: extendFlat({}, hoverLabelAttrs.align, {arrayOk: true}),\n        namelength: extendFlat({}, hoverLabelAttrs.namelength, {arrayOk: true}),\n        editType: 'none'\n    }\n};\n\n},{\"../../lib/extend\":710,\"../../plots/font_attributes\":793,\"./layout_attributes\":633}],624:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\n\nmodule.exports = function calc(gd) {\n    var calcdata = gd.calcdata;\n    var fullLayout = gd._fullLayout;\n\n    function makeCoerceHoverInfo(trace) {\n        return function(val) {\n            return Lib.coerceHoverinfo({hoverinfo: val}, {_module: trace._module}, fullLayout);\n        };\n    }\n\n    for(var i = 0; i < calcdata.length; i++) {\n        var cd = calcdata[i];\n        var trace = cd[0].trace;\n\n        // don't include hover calc fields for pie traces\n        // as calcdata items might be sorted by value and\n        // won't match the data array order.\n        if(Registry.traceIs(trace, 'pie-like')) continue;\n\n        var fillFn = Registry.traceIs(trace, '2dMap') ? paste : Lib.fillArray;\n\n        fillFn(trace.hoverinfo, cd, 'hi', makeCoerceHoverInfo(trace));\n\n        if(trace.hovertemplate) fillFn(trace.hovertemplate, cd, 'ht');\n\n        if(!trace.hoverlabel) continue;\n\n        fillFn(trace.hoverlabel.bgcolor, cd, 'hbg');\n        fillFn(trace.hoverlabel.bordercolor, cd, 'hbc');\n        fillFn(trace.hoverlabel.font.size, cd, 'hts');\n        fillFn(trace.hoverlabel.font.color, cd, 'htc');\n        fillFn(trace.hoverlabel.font.family, cd, 'htf');\n        fillFn(trace.hoverlabel.namelength, cd, 'hnl');\n        fillFn(trace.hoverlabel.align, cd, 'hta');\n    }\n};\n\nfunction paste(traceAttr, cd, cdAttr, fn) {\n    fn = fn || Lib.identity;\n\n    if(Array.isArray(traceAttr)) {\n        cd[0][cdAttr] = fn(traceAttr);\n    }\n}\n\n},{\"../../lib\":719,\"../../registry\":847}],625:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar hover = _dereq_('./hover').hover;\n\nmodule.exports = function click(gd, evt, subplot) {\n    var annotationsDone = Registry.getComponentMethod('annotations', 'onClick')(gd, gd._hoverdata);\n\n    // fallback to fail-safe in case the plot type's hover method doesn't pass the subplot.\n    // Ternary, for example, didn't, but it was caught because tested.\n    if(subplot !== undefined) {\n        // The true flag at the end causes it to re-run the hover computation to figure out *which*\n        // point is being clicked. Without this, clicking is somewhat unreliable.\n        hover(gd, evt, subplot, true);\n    }\n\n    function emitClick() { gd.emit('plotly_click', {points: gd._hoverdata, event: evt}); }\n\n    if(gd._hoverdata && evt && evt.target) {\n        if(annotationsDone && annotationsDone.then) {\n            annotationsDone.then(emitClick);\n        } else emitClick();\n\n        // why do we get a double event without this???\n        if(evt.stopImmediatePropagation) evt.stopImmediatePropagation();\n    }\n};\n\n},{\"../../registry\":847,\"./hover\":629}],626:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    // hover labels for multiple horizontal bars get tilted by this angle\n    YANGLE: 60,\n\n    // size and display constants for hover text\n\n    // pixel size of hover arrows\n    HOVERARROWSIZE: 6,\n    // pixels padding around text\n    HOVERTEXTPAD: 3,\n    // hover font\n    HOVERFONTSIZE: 13,\n    HOVERFONT: 'Arial, sans-serif',\n\n    // minimum time (msec) between hover calls\n    HOVERMINTIME: 50,\n\n    // ID suffix (with fullLayout._uid) for hover events in the throttle cache\n    HOVERID: '-hover'\n};\n\n},{}],627:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attributes = _dereq_('./attributes');\nvar handleHoverLabelDefaults = _dereq_('./hoverlabel_defaults');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var opts = Lib.extendFlat({}, layout.hoverlabel);\n    if(traceOut.hovertemplate) opts.namelength = -1;\n\n    handleHoverLabelDefaults(traceIn, traceOut, coerce, opts);\n};\n\n},{\"../../lib\":719,\"./attributes\":623,\"./hoverlabel_defaults\":630}],628:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n// look for either subplot or xaxis and yaxis attributes\n// does not handle splom case\nexports.getSubplot = function getSubplot(trace) {\n    return trace.subplot || (trace.xaxis + trace.yaxis) || trace.geo;\n};\n\n// is trace in given list of subplots?\n// does handle splom case\nexports.isTraceInSubplots = function isTraceInSubplots(trace, subplots) {\n    if(trace.type === 'splom') {\n        var xaxes = trace.xaxes || [];\n        var yaxes = trace.yaxes || [];\n        for(var i = 0; i < xaxes.length; i++) {\n            for(var j = 0; j < yaxes.length; j++) {\n                if(subplots.indexOf(xaxes[i] + yaxes[j]) !== -1) {\n                    return true;\n                }\n            }\n        }\n        return false;\n    }\n\n    return subplots.indexOf(exports.getSubplot(trace)) !== -1;\n};\n\n// convenience functions for mapping all relevant axes\nexports.flat = function flat(subplots, v) {\n    var out = new Array(subplots.length);\n    for(var i = 0; i < subplots.length; i++) {\n        out[i] = v;\n    }\n    return out;\n};\n\nexports.p2c = function p2c(axArray, v) {\n    var out = new Array(axArray.length);\n    for(var i = 0; i < axArray.length; i++) {\n        out[i] = axArray[i].p2c(v);\n    }\n    return out;\n};\n\nexports.getDistanceFunction = function getDistanceFunction(mode, dx, dy, dxy) {\n    if(mode === 'closest') return dxy || exports.quadrature(dx, dy);\n    return mode === 'x' ? dx : dy;\n};\n\nexports.getClosest = function getClosest(cd, distfn, pointData) {\n    // do we already have a point number? (array mode only)\n    if(pointData.index !== false) {\n        if(pointData.index >= 0 && pointData.index < cd.length) {\n            pointData.distance = 0;\n        } else pointData.index = false;\n    } else {\n        // apply the distance function to each data point\n        // this is the longest loop... if this bogs down, we may need\n        // to create pre-sorted data (by x or y), not sure how to\n        // do this for 'closest'\n        for(var i = 0; i < cd.length; i++) {\n            var newDistance = distfn(cd[i]);\n            if(newDistance <= pointData.distance) {\n                pointData.index = i;\n                pointData.distance = newDistance;\n            }\n        }\n    }\n    return pointData;\n};\n\n/*\n * pseudo-distance function for hover effects on areas: inside the region\n * distance is finite (`passVal`), outside it's Infinity.\n *\n * @param {number} v0: signed difference between the current position and the left edge\n * @param {number} v1: signed difference between the current position and the right edge\n * @param {number} passVal: the value to return on success\n */\nexports.inbox = function inbox(v0, v1, passVal) {\n    return (v0 * v1 < 0 || v0 === 0) ? passVal : Infinity;\n};\n\nexports.quadrature = function quadrature(dx, dy) {\n    return function(di) {\n        var x = dx(di);\n        var y = dy(di);\n        return Math.sqrt(x * x + y * y);\n    };\n};\n\n/** Fill event data point object for hover and selection.\n *  Invokes _module.eventData if present.\n *\n * N.B. note that point 'index' corresponds to input data array index\n *  whereas 'number' is its post-transform version.\n *\n * If the hovered/selected pt corresponds to an multiple input points\n * (e.g. for histogram and transformed traces), 'pointNumbers` and 'pointIndices'\n * are include in the event data.\n *\n * @param {object} pt\n * @param {object} trace\n * @param {object} cd\n * @return {object}\n */\nexports.makeEventData = function makeEventData(pt, trace, cd) {\n    // hover uses 'index', select uses 'pointNumber'\n    var pointNumber = 'index' in pt ? pt.index : pt.pointNumber;\n\n    var out = {\n        data: trace._input,\n        fullData: trace,\n        curveNumber: trace.index,\n        pointNumber: pointNumber\n    };\n\n    if(trace._indexToPoints) {\n        var pointIndices = trace._indexToPoints[pointNumber];\n\n        if(pointIndices.length === 1) {\n            out.pointIndex = pointIndices[0];\n        } else {\n            out.pointIndices = pointIndices;\n        }\n    } else {\n        out.pointIndex = pointNumber;\n    }\n\n    if(trace._module.eventData) {\n        out = trace._module.eventData(out, pt, trace, cd, pointNumber);\n    } else {\n        if('xVal' in pt) out.x = pt.xVal;\n        else if('x' in pt) out.x = pt.x;\n\n        if('yVal' in pt) out.y = pt.yVal;\n        else if('y' in pt) out.y = pt.y;\n\n        if(pt.xa) out.xaxis = pt.xa;\n        if(pt.ya) out.yaxis = pt.ya;\n        if(pt.zLabelVal !== undefined) out.z = pt.zLabelVal;\n    }\n\n    exports.appendArrayPointValue(out, trace, pointNumber);\n\n    return out;\n};\n\n/** Appends values inside array attributes corresponding to given point number\n *\n * @param {object} pointData : point data object (gets mutated here)\n * @param {object} trace : full trace object\n * @param {number|Array(number)} pointNumber : point number. May be a length-2 array\n *     [row, col] to dig into 2D arrays\n */\nexports.appendArrayPointValue = function(pointData, trace, pointNumber) {\n    var arrayAttrs = trace._arrayAttrs;\n\n    if(!arrayAttrs) {\n        return;\n    }\n\n    for(var i = 0; i < arrayAttrs.length; i++) {\n        var astr = arrayAttrs[i];\n        var key = getPointKey(astr);\n\n        if(pointData[key] === undefined) {\n            var val = Lib.nestedProperty(trace, astr).get();\n            var pointVal = getPointData(val, pointNumber);\n\n            if(pointVal !== undefined) pointData[key] = pointVal;\n        }\n    }\n};\n\n/**\n * Appends values inside array attributes corresponding to given point number array\n * For use when pointData references a plot entity that arose (or potentially arose)\n * from multiple points in the input data\n *\n * @param {object} pointData : point data object (gets mutated here)\n * @param {object} trace : full trace object\n * @param {Array(number)|Array(Array(number))} pointNumbers : Array of point numbers.\n *     Each entry in the array may itself be a length-2 array [row, col] to dig into 2D arrays\n */\nexports.appendArrayMultiPointValues = function(pointData, trace, pointNumbers) {\n    var arrayAttrs = trace._arrayAttrs;\n\n    if(!arrayAttrs) {\n        return;\n    }\n\n    for(var i = 0; i < arrayAttrs.length; i++) {\n        var astr = arrayAttrs[i];\n        var key = getPointKey(astr);\n\n        if(pointData[key] === undefined) {\n            var val = Lib.nestedProperty(trace, astr).get();\n            var keyVal = new Array(pointNumbers.length);\n\n            for(var j = 0; j < pointNumbers.length; j++) {\n                keyVal[j] = getPointData(val, pointNumbers[j]);\n            }\n            pointData[key] = keyVal;\n        }\n    }\n};\n\nvar pointKeyMap = {\n    ids: 'id',\n    locations: 'location',\n    labels: 'label',\n    values: 'value',\n    'marker.colors': 'color',\n    parents: 'parent'\n};\n\nfunction getPointKey(astr) {\n    return pointKeyMap[astr] || astr;\n}\n\nfunction getPointData(val, pointNumber) {\n    if(Array.isArray(pointNumber)) {\n        if(Array.isArray(val) && Array.isArray(val[pointNumber[0]])) {\n            return val[pointNumber[0]][pointNumber[1]];\n        }\n    } else {\n        return val[pointNumber];\n    }\n}\n\n},{\"../../lib\":719}],629:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\nvar tinycolor = _dereq_('tinycolor2');\n\nvar Lib = _dereq_('../../lib');\nvar Events = _dereq_('../../lib/events');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar overrideCursor = _dereq_('../../lib/override_cursor');\nvar Drawing = _dereq_('../drawing');\nvar Color = _dereq_('../color');\nvar dragElement = _dereq_('../dragelement');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Registry = _dereq_('../../registry');\n\nvar helpers = _dereq_('./helpers');\nvar constants = _dereq_('./constants');\n\n// hover labels for multiple horizontal bars get tilted by some angle,\n// then need to be offset differently if they overlap\nvar YANGLE = constants.YANGLE;\nvar YA_RADIANS = Math.PI * YANGLE / 180;\n\n// expansion of projected height\nvar YFACTOR = 1 / Math.sin(YA_RADIANS);\n\n// to make the appropriate post-rotation x offset,\n// you need both x and y offsets\nvar YSHIFTX = Math.cos(YA_RADIANS);\nvar YSHIFTY = Math.sin(YA_RADIANS);\n\n// size and display constants for hover text\nvar HOVERARROWSIZE = constants.HOVERARROWSIZE;\nvar HOVERTEXTPAD = constants.HOVERTEXTPAD;\n\n// fx.hover: highlight data on hover\n// evt can be a mousemove event, or an object with data about what points\n//   to hover on\n//      {xpx,ypx[,hovermode]} - pixel locations from top left\n//          (with optional overriding hovermode)\n//      {xval,yval[,hovermode]} - data values\n//      [{curveNumber,(pointNumber|xval and/or yval)}] -\n//              array of specific points to highlight\n//          pointNumber is a single integer if gd.data[curveNumber] is 1D,\n//              or a two-element array if it's 2D\n//          xval and yval are data values,\n//              1D data may specify either or both,\n//              2D data must specify both\n// subplot is an id string (default \"xy\")\n// makes use of gl.hovermode, which can be:\n//      x (find the points with the closest x values, ie a column),\n//      closest (find the single closest point)\n//    internally there are two more that occasionally get used:\n//      y (pick out a row - only used for multiple horizontal bar charts)\n//      array (used when the user specifies an explicit\n//          array of points to hover on)\n//\n// We wrap the hovers in a timer, to limit their frequency.\n// The actual rendering is done by private function _hover.\nexports.hover = function hover(gd, evt, subplot, noHoverEvent) {\n    gd = Lib.getGraphDiv(gd);\n\n    Lib.throttle(\n        gd._fullLayout._uid + constants.HOVERID,\n        constants.HOVERMINTIME,\n        function() { _hover(gd, evt, subplot, noHoverEvent); }\n    );\n};\n\n/*\n * Draw a single hover item or an array of hover item in a pre-existing svg container somewhere\n * hoverItem should have keys:\n *    - x and y (or x0, x1, y0, and y1):\n *      the pixel position to mark, relative to opts.container\n *    - xLabel, yLabel, zLabel, text, and name:\n *      info to go in the label\n *    - color:\n *      the background color for the label.\n *    - idealAlign (optional):\n *      'left' or 'right' for which side of the x/y box to try to put this on first\n *    - borderColor (optional):\n *      color for the border, defaults to strongest contrast with color\n *    - fontFamily (optional):\n *      string, the font for this label, defaults to constants.HOVERFONT\n *    - fontSize (optional):\n *      the label font size, defaults to constants.HOVERFONTSIZE\n *    - fontColor (optional):\n *      defaults to borderColor\n * opts should have keys:\n *    - bgColor:\n *      the background color this is against, used if the trace is\n *      non-opaque, and for the name, which goes outside the box\n *    - container:\n *      a <svg> or <g> element to add the hover label to\n *    - outerContainer:\n *      normally a parent of `container`, sets the bounding box to use to\n *      constrain the hover label and determine whether to show it on the left or right\n * opts can have optional keys:\n *    - anchorIndex:\n        the index of the hover item used as an anchor for positioning.\n        The other hover items will be pushed up or down to prevent overlap.\n */\nexports.loneHover = function loneHover(hoverItems, opts) {\n    var multiHover = true;\n    if(!Array.isArray(hoverItems)) {\n        multiHover = false;\n        hoverItems = [hoverItems];\n    }\n\n    var pointsData = hoverItems.map(function(hoverItem) {\n        return {\n            color: hoverItem.color || Color.defaultLine,\n            x0: hoverItem.x0 || hoverItem.x || 0,\n            x1: hoverItem.x1 || hoverItem.x || 0,\n            y0: hoverItem.y0 || hoverItem.y || 0,\n            y1: hoverItem.y1 || hoverItem.y || 0,\n            xLabel: hoverItem.xLabel,\n            yLabel: hoverItem.yLabel,\n            zLabel: hoverItem.zLabel,\n            text: hoverItem.text,\n            name: hoverItem.name,\n            idealAlign: hoverItem.idealAlign,\n\n            // optional extra bits of styling\n            borderColor: hoverItem.borderColor,\n            fontFamily: hoverItem.fontFamily,\n            fontSize: hoverItem.fontSize,\n            fontColor: hoverItem.fontColor,\n            nameLength: hoverItem.nameLength,\n            textAlign: hoverItem.textAlign,\n\n            // filler to make createHoverText happy\n            trace: hoverItem.trace || {\n                index: 0,\n                hoverinfo: ''\n            },\n            xa: {_offset: 0},\n            ya: {_offset: 0},\n            index: 0,\n\n            hovertemplate: hoverItem.hovertemplate || false,\n            eventData: hoverItem.eventData || false,\n            hovertemplateLabels: hoverItem.hovertemplateLabels || false,\n        };\n    });\n\n    var container3 = d3.select(opts.container);\n    var outerContainer3 = opts.outerContainer ? d3.select(opts.outerContainer) : container3;\n\n    var fullOpts = {\n        hovermode: 'closest',\n        rotateLabels: false,\n        bgColor: opts.bgColor || Color.background,\n        container: container3,\n        outerContainer: outerContainer3\n    };\n\n    var hoverLabel = createHoverText(pointsData, fullOpts, opts.gd);\n\n    // Fix vertical overlap\n    var tooltipSpacing = 5;\n    var lastBottomY = 0;\n    var anchor = 0;\n    hoverLabel\n        .sort(function(a, b) {return a.y0 - b.y0;})\n        .each(function(d, i) {\n            var topY = d.y0 - d.by / 2;\n\n            if((topY - tooltipSpacing) < lastBottomY) {\n                d.offset = (lastBottomY - topY) + tooltipSpacing;\n            } else {\n                d.offset = 0;\n            }\n\n            lastBottomY = topY + d.by + d.offset;\n\n            if(i === opts.anchorIndex || 0) anchor = d.offset;\n        })\n        .each(function(d) {\n            d.offset -= anchor;\n        });\n\n    alignHoverText(hoverLabel, fullOpts.rotateLabels);\n\n    return multiHover ? hoverLabel : hoverLabel.node();\n};\n\n// The actual implementation is here:\nfunction _hover(gd, evt, subplot, noHoverEvent) {\n    if(!subplot) subplot = 'xy';\n\n    // if the user passed in an array of subplots,\n    // use those instead of finding overlayed plots\n    var subplots = Array.isArray(subplot) ? subplot : [subplot];\n\n    var fullLayout = gd._fullLayout;\n    var plots = fullLayout._plots || [];\n    var plotinfo = plots[subplot];\n    var hasCartesian = fullLayout._has('cartesian');\n\n    // list of all overlaid subplots to look at\n    if(plotinfo) {\n        var overlayedSubplots = plotinfo.overlays.map(function(pi) {\n            return pi.id;\n        });\n\n        subplots = subplots.concat(overlayedSubplots);\n    }\n\n    var len = subplots.length;\n    var xaArray = new Array(len);\n    var yaArray = new Array(len);\n    var supportsCompare = false;\n\n    for(var i = 0; i < len; i++) {\n        var spId = subplots[i];\n\n        // 'cartesian' case\n        var plotObj = plots[spId];\n        if(plotObj) {\n            supportsCompare = true;\n\n            // TODO make sure that fullLayout_plots axis refs\n            // get updated properly so that we don't have\n            // to use Axes.getFromId in general.\n\n            xaArray[i] = Axes.getFromId(gd, plotObj.xaxis._id);\n            yaArray[i] = Axes.getFromId(gd, plotObj.yaxis._id);\n            continue;\n        }\n\n        // other subplot types\n        var _subplot = fullLayout[spId]._subplot;\n        xaArray[i] = _subplot.xaxis;\n        yaArray[i] = _subplot.yaxis;\n    }\n\n    var hovermode = evt.hovermode || fullLayout.hovermode;\n\n    if(hovermode && !supportsCompare) hovermode = 'closest';\n\n    if(['x', 'y', 'closest'].indexOf(hovermode) === -1 || !gd.calcdata ||\n            gd.querySelector('.zoombox') || gd._dragging) {\n        return dragElement.unhoverRaw(gd, evt);\n    }\n\n    var hoverdistance = fullLayout.hoverdistance === -1 ? Infinity : fullLayout.hoverdistance;\n    var spikedistance = fullLayout.spikedistance === -1 ? Infinity : fullLayout.spikedistance;\n\n    // hoverData: the set of candidate points we've found to highlight\n    var hoverData = [];\n\n    // searchData: the data to search in. Mostly this is just a copy of\n    // gd.calcdata, filtered to the subplot and overlays we're on\n    // but if a point array is supplied it will be a mapping\n    // of indicated curves\n    var searchData = [];\n\n    // [x|y]valArray: the axis values of the hover event\n    // mapped onto each of the currently selected overlaid subplots\n    var xvalArray, yvalArray;\n\n    var itemnum, curvenum, cd, trace, subplotId, subploti, mode,\n        xval, yval, pointData, closedataPreviousLength;\n\n    // spikePoints: the set of candidate points we've found to draw spikes to\n    var spikePoints = {\n        hLinePoint: null,\n        vLinePoint: null\n    };\n\n    // does subplot have one (or more) horizontal traces?\n    // This is used to determine whether we rotate the labels or not\n    var hasOneHorizontalTrace = false;\n\n    // Figure out what we're hovering on:\n    // mouse location or user-supplied data\n\n    if(Array.isArray(evt)) {\n        // user specified an array of points to highlight\n        hovermode = 'array';\n        for(itemnum = 0; itemnum < evt.length; itemnum++) {\n            cd = gd.calcdata[evt[itemnum].curveNumber || 0];\n            if(cd) {\n                trace = cd[0].trace;\n                if(cd[0].trace.hoverinfo !== 'skip') {\n                    searchData.push(cd);\n                    if(trace.orientation === 'h') {\n                        hasOneHorizontalTrace = true;\n                    }\n                }\n            }\n        }\n    } else {\n        for(curvenum = 0; curvenum < gd.calcdata.length; curvenum++) {\n            cd = gd.calcdata[curvenum];\n            trace = cd[0].trace;\n            if(trace.hoverinfo !== 'skip' && helpers.isTraceInSubplots(trace, subplots)) {\n                searchData.push(cd);\n                if(trace.orientation === 'h') {\n                    hasOneHorizontalTrace = true;\n                }\n            }\n        }\n\n        // [x|y]px: the pixels (from top left) of the mouse location\n        // on the currently selected plot area\n        // add pointerX|Y property for drawing the spikes in spikesnap 'cursor' situation\n        var hasUserCalledHover = !evt.target;\n        var xpx, ypx;\n\n        if(hasUserCalledHover) {\n            if('xpx' in evt) xpx = evt.xpx;\n            else xpx = xaArray[0]._length / 2;\n\n            if('ypx' in evt) ypx = evt.ypx;\n            else ypx = yaArray[0]._length / 2;\n        } else {\n            // fire the beforehover event and quit if it returns false\n            // note that we're only calling this on real mouse events, so\n            // manual calls to fx.hover will always run.\n            if(Events.triggerHandler(gd, 'plotly_beforehover', evt) === false) {\n                return;\n            }\n\n            var dbb = evt.target.getBoundingClientRect();\n\n            xpx = evt.clientX - dbb.left;\n            ypx = evt.clientY - dbb.top;\n\n            // in case hover was called from mouseout into hovertext,\n            // it's possible you're not actually over the plot anymore\n            if(xpx < 0 || xpx > xaArray[0]._length || ypx < 0 || ypx > yaArray[0]._length) {\n                return dragElement.unhoverRaw(gd, evt);\n            }\n        }\n\n        evt.pointerX = xpx + xaArray[0]._offset;\n        evt.pointerY = ypx + yaArray[0]._offset;\n\n        if('xval' in evt) xvalArray = helpers.flat(subplots, evt.xval);\n        else xvalArray = helpers.p2c(xaArray, xpx);\n\n        if('yval' in evt) yvalArray = helpers.flat(subplots, evt.yval);\n        else yvalArray = helpers.p2c(yaArray, ypx);\n\n        if(!isNumeric(xvalArray[0]) || !isNumeric(yvalArray[0])) {\n            Lib.warn('Fx.hover failed', evt, gd);\n            return dragElement.unhoverRaw(gd, evt);\n        }\n    }\n\n    // the pixel distance to beat as a matching point\n    // in 'x' or 'y' mode this resets for each trace\n    var distance = Infinity;\n\n    // find the closest point in each trace\n    // this is minimum dx and/or dy, depending on mode\n    // and the pixel position for the label (labelXpx, labelYpx)\n    for(curvenum = 0; curvenum < searchData.length; curvenum++) {\n        cd = searchData[curvenum];\n\n        // filter out invisible or broken data\n        if(!cd || !cd[0] || !cd[0].trace) continue;\n\n        trace = cd[0].trace;\n\n        if(trace.visible !== true || trace._length === 0) continue;\n\n        // Explicitly bail out for these two. I don't know how to otherwise prevent\n        // the rest of this function from running and failing\n        if(['carpet', 'contourcarpet'].indexOf(trace._module.name) !== -1) continue;\n\n        if(trace.type === 'splom') {\n            // splom traces do not generate overlay subplots,\n            // it is safe to assume here splom traces correspond to the 0th subplot\n            subploti = 0;\n            subplotId = subplots[subploti];\n        } else {\n            subplotId = helpers.getSubplot(trace);\n            subploti = subplots.indexOf(subplotId);\n        }\n\n        // within one trace mode can sometimes be overridden\n        mode = hovermode;\n\n        // container for new point, also used to pass info into module.hoverPoints\n        pointData = {\n            // trace properties\n            cd: cd,\n            trace: trace,\n            xa: xaArray[subploti],\n            ya: yaArray[subploti],\n\n            // max distances for hover and spikes - for points that want to show but do not\n            // want to override other points, set distance/spikeDistance equal to max*Distance\n            // and it will not get filtered out but it will be guaranteed to have a greater\n            // distance than any point that calculated a real distance.\n            maxHoverDistance: hoverdistance,\n            maxSpikeDistance: spikedistance,\n\n            // point properties - override all of these\n            index: false, // point index in trace - only used by plotly.js hoverdata consumers\n            distance: Math.min(distance, hoverdistance), // pixel distance or pseudo-distance\n\n            // distance/pseudo-distance for spikes. This distance should always be calculated\n            // as if in \"closest\" mode, and should only be set if this point should\n            // generate a spike.\n            spikeDistance: Infinity,\n\n            // in some cases the spikes have different positioning from the hover label\n            // they don't need x0/x1, just one position\n            xSpike: undefined,\n            ySpike: undefined,\n\n            // where and how to display the hover label\n            color: Color.defaultLine, // trace color\n            name: trace.name,\n            x0: undefined,\n            x1: undefined,\n            y0: undefined,\n            y1: undefined,\n            xLabelVal: undefined,\n            yLabelVal: undefined,\n            zLabelVal: undefined,\n            text: undefined\n        };\n\n        // add ref to subplot object (non-cartesian case)\n        if(fullLayout[subplotId]) {\n            pointData.subplot = fullLayout[subplotId]._subplot;\n        }\n        // add ref to splom scene\n        if(fullLayout._splomScenes && fullLayout._splomScenes[trace.uid]) {\n            pointData.scene = fullLayout._splomScenes[trace.uid];\n        }\n\n        closedataPreviousLength = hoverData.length;\n\n        // for a highlighting array, figure out what\n        // we're searching for with this element\n        if(mode === 'array') {\n            var selection = evt[curvenum];\n            if('pointNumber' in selection) {\n                pointData.index = selection.pointNumber;\n                mode = 'closest';\n            } else {\n                mode = '';\n                if('xval' in selection) {\n                    xval = selection.xval;\n                    mode = 'x';\n                }\n                if('yval' in selection) {\n                    yval = selection.yval;\n                    mode = mode ? 'closest' : 'y';\n                }\n            }\n        } else {\n            xval = xvalArray[subploti];\n            yval = yvalArray[subploti];\n        }\n\n        // Now if there is range to look in, find the points to hover.\n        if(hoverdistance !== 0) {\n            if(trace._module && trace._module.hoverPoints) {\n                var newPoints = trace._module.hoverPoints(pointData, xval, yval, mode, fullLayout._hoverlayer);\n                if(newPoints) {\n                    var newPoint;\n                    for(var newPointNum = 0; newPointNum < newPoints.length; newPointNum++) {\n                        newPoint = newPoints[newPointNum];\n                        if(isNumeric(newPoint.x0) && isNumeric(newPoint.y0)) {\n                            hoverData.push(cleanPoint(newPoint, hovermode));\n                        }\n                    }\n                }\n            } else {\n                Lib.log('Unrecognized trace type in hover:', trace);\n            }\n        }\n\n        // in closest mode, remove any existing (farther) points\n        // and don't look any farther than this latest point (or points, some\n        // traces like box & violin make multiple hover labels at once)\n        if(hovermode === 'closest' && hoverData.length > closedataPreviousLength) {\n            hoverData.splice(0, closedataPreviousLength);\n            distance = hoverData[0].distance;\n        }\n\n        // Now if there is range to look in, find the points to draw the spikelines\n        // Do it only if there is no hoverData\n        if(hasCartesian && (spikedistance !== 0)) {\n            if(hoverData.length === 0) {\n                pointData.distance = spikedistance;\n                pointData.index = false;\n                var closestPoints = trace._module.hoverPoints(pointData, xval, yval, 'closest', fullLayout._hoverlayer);\n                if(closestPoints) {\n                    closestPoints = closestPoints.filter(function(point) {\n                        // some hover points, like scatter fills, do not allow spikes,\n                        // so will generate a hover point but without a valid spikeDistance\n                        return point.spikeDistance <= spikedistance;\n                    });\n                }\n                if(closestPoints && closestPoints.length) {\n                    var tmpPoint;\n                    var closestVPoints = closestPoints.filter(function(point) {\n                        return point.xa.showspikes;\n                    });\n                    if(closestVPoints.length) {\n                        var closestVPt = closestVPoints[0];\n                        if(isNumeric(closestVPt.x0) && isNumeric(closestVPt.y0)) {\n                            tmpPoint = fillSpikePoint(closestVPt);\n                            if(!spikePoints.vLinePoint || (spikePoints.vLinePoint.spikeDistance > tmpPoint.spikeDistance)) {\n                                spikePoints.vLinePoint = tmpPoint;\n                            }\n                        }\n                    }\n\n                    var closestHPoints = closestPoints.filter(function(point) {\n                        return point.ya.showspikes;\n                    });\n                    if(closestHPoints.length) {\n                        var closestHPt = closestHPoints[0];\n                        if(isNumeric(closestHPt.x0) && isNumeric(closestHPt.y0)) {\n                            tmpPoint = fillSpikePoint(closestHPt);\n                            if(!spikePoints.hLinePoint || (spikePoints.hLinePoint.spikeDistance > tmpPoint.spikeDistance)) {\n                                spikePoints.hLinePoint = tmpPoint;\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    }\n\n    function selectClosestPoint(pointsData, spikedistance) {\n        var resultPoint = null;\n        var minDistance = Infinity;\n        var thisSpikeDistance;\n        for(var i = 0; i < pointsData.length; i++) {\n            thisSpikeDistance = pointsData[i].spikeDistance;\n            if(thisSpikeDistance < minDistance && thisSpikeDistance <= spikedistance) {\n                resultPoint = pointsData[i];\n                minDistance = thisSpikeDistance;\n            }\n        }\n        return resultPoint;\n    }\n\n    function fillSpikePoint(point) {\n        if(!point) return null;\n        return {\n            xa: point.xa,\n            ya: point.ya,\n            x: point.xSpike !== undefined ? point.xSpike : (point.x0 + point.x1) / 2,\n            y: point.ySpike !== undefined ? point.ySpike : (point.y0 + point.y1) / 2,\n            distance: point.distance,\n            spikeDistance: point.spikeDistance,\n            curveNumber: point.trace.index,\n            color: point.color,\n            pointNumber: point.index\n        };\n    }\n\n    var spikelineOpts = {\n        fullLayout: fullLayout,\n        container: fullLayout._hoverlayer,\n        outerContainer: fullLayout._paperdiv,\n        event: evt\n    };\n    var oldspikepoints = gd._spikepoints;\n    var newspikepoints = {\n        vLinePoint: spikePoints.vLinePoint,\n        hLinePoint: spikePoints.hLinePoint\n    };\n    gd._spikepoints = newspikepoints;\n\n    // Now if it is not restricted by spikedistance option, set the points to draw the spikelines\n    if(hasCartesian && (spikedistance !== 0)) {\n        if(hoverData.length !== 0) {\n            var tmpHPointData = hoverData.filter(function(point) {\n                return point.ya.showspikes;\n            });\n            var tmpHPoint = selectClosestPoint(tmpHPointData, spikedistance);\n            spikePoints.hLinePoint = fillSpikePoint(tmpHPoint);\n\n            var tmpVPointData = hoverData.filter(function(point) {\n                return point.xa.showspikes;\n            });\n            var tmpVPoint = selectClosestPoint(tmpVPointData, spikedistance);\n            spikePoints.vLinePoint = fillSpikePoint(tmpVPoint);\n        }\n    }\n\n    // if hoverData is empty check for the spikes to draw and quit if there are none\n    if(hoverData.length === 0) {\n        var result = dragElement.unhoverRaw(gd, evt);\n        if(hasCartesian && ((spikePoints.hLinePoint !== null) || (spikePoints.vLinePoint !== null))) {\n            if(spikesChanged(oldspikepoints)) {\n                createSpikelines(spikePoints, spikelineOpts);\n            }\n        }\n        return result;\n    }\n\n    if(hasCartesian) {\n        if(spikesChanged(oldspikepoints)) {\n            createSpikelines(spikePoints, spikelineOpts);\n        }\n    }\n\n    hoverData.sort(function(d1, d2) { return d1.distance - d2.distance; });\n\n    // lastly, emit custom hover/unhover events\n    var oldhoverdata = gd._hoverdata;\n    var newhoverdata = [];\n\n    // pull out just the data that's useful to\n    // other people and send it to the event\n    for(itemnum = 0; itemnum < hoverData.length; itemnum++) {\n        var pt = hoverData[itemnum];\n        var eventData = helpers.makeEventData(pt, pt.trace, pt.cd);\n\n        if(pt.hovertemplate !== false) {\n            var ht = false;\n            if(pt.cd[pt.index] && pt.cd[pt.index].ht) {\n                ht = pt.cd[pt.index].ht;\n            }\n            pt.hovertemplate = ht || pt.trace.hovertemplate || false;\n        }\n\n        pt.eventData = [eventData];\n        newhoverdata.push(eventData);\n    }\n\n    gd._hoverdata = newhoverdata;\n\n    var rotateLabels = (\n        (hovermode === 'y' && (searchData.length > 1 || hoverData.length > 1)) ||\n        (hovermode === 'closest' && hasOneHorizontalTrace && hoverData.length > 1)\n    );\n\n    var bgColor = Color.combine(\n        fullLayout.plot_bgcolor || Color.background,\n        fullLayout.paper_bgcolor\n    );\n\n    var labelOpts = {\n        hovermode: hovermode,\n        rotateLabels: rotateLabels,\n        bgColor: bgColor,\n        container: fullLayout._hoverlayer,\n        outerContainer: fullLayout._paperdiv,\n        commonLabelOpts: fullLayout.hoverlabel,\n        hoverdistance: fullLayout.hoverdistance\n    };\n\n    var hoverLabels = createHoverText(hoverData, labelOpts, gd);\n\n    hoverAvoidOverlaps(hoverLabels, rotateLabels ? 'xa' : 'ya', fullLayout);\n\n    alignHoverText(hoverLabels, rotateLabels);\n\n    // TODO: tagName hack is needed to appease geo.js's hack of using evt.target=true\n    // we should improve the \"fx\" API so other plots can use it without these hack.\n    if(evt.target && evt.target.tagName) {\n        var hasClickToShow = Registry.getComponentMethod('annotations', 'hasClickToShow')(gd, newhoverdata);\n        overrideCursor(d3.select(evt.target), hasClickToShow ? 'pointer' : '');\n    }\n\n    // don't emit events if called manually\n    if(!evt.target || noHoverEvent || !hoverChanged(gd, evt, oldhoverdata)) return;\n\n    if(oldhoverdata) {\n        gd.emit('plotly_unhover', {\n            event: evt,\n            points: oldhoverdata\n        });\n    }\n\n    gd.emit('plotly_hover', {\n        event: evt,\n        points: gd._hoverdata,\n        xaxes: xaArray,\n        yaxes: yaArray,\n        xvals: xvalArray,\n        yvals: yvalArray\n    });\n}\n\nvar EXTRA_STRING_REGEX = /<extra>([\\s\\S]*)<\\/extra>/;\n\nfunction createHoverText(hoverData, opts, gd) {\n    var fullLayout = gd._fullLayout;\n    var hovermode = opts.hovermode;\n    var rotateLabels = opts.rotateLabels;\n    var bgColor = opts.bgColor;\n    var container = opts.container;\n    var outerContainer = opts.outerContainer;\n    var commonLabelOpts = opts.commonLabelOpts || {};\n\n    // opts.fontFamily/Size are used for the common label\n    // and as defaults for each hover label, though the individual labels\n    // can override this.\n    var fontFamily = opts.fontFamily || constants.HOVERFONT;\n    var fontSize = opts.fontSize || constants.HOVERFONTSIZE;\n\n    var c0 = hoverData[0];\n    var xa = c0.xa;\n    var ya = c0.ya;\n    var commonAttr = hovermode === 'y' ? 'yLabel' : 'xLabel';\n    var t0 = c0[commonAttr];\n    var t00 = (String(t0) || '').split(' ')[0];\n    var outerContainerBB = outerContainer.node().getBoundingClientRect();\n    var outerTop = outerContainerBB.top;\n    var outerWidth = outerContainerBB.width;\n    var outerHeight = outerContainerBB.height;\n\n    // show the common label, if any, on the axis\n    // never show a common label in array mode,\n    // even if sometimes there could be one\n    var showCommonLabel = (\n        (t0 !== undefined) &&\n        (c0.distance <= opts.hoverdistance) &&\n        (hovermode === 'x' || hovermode === 'y')\n    );\n\n    // all hover traces hoverinfo must contain the hovermode\n    // to have common labels\n    if(showCommonLabel) {\n        var allHaveZ = true;\n        var i, traceHoverinfo;\n        for(i = 0; i < hoverData.length; i++) {\n            if(allHaveZ && hoverData[i].zLabel === undefined) allHaveZ = false;\n\n            traceHoverinfo = hoverData[i].hoverinfo || hoverData[i].trace.hoverinfo;\n            if(traceHoverinfo) {\n                var parts = Array.isArray(traceHoverinfo) ? traceHoverinfo : traceHoverinfo.split('+');\n                if(parts.indexOf('all') === -1 &&\n                    parts.indexOf(hovermode) === -1) {\n                    showCommonLabel = false;\n                    break;\n                }\n            }\n        }\n\n        // xyz labels put all info in their main label, so have no need of a common label\n        if(allHaveZ) showCommonLabel = false;\n    }\n\n    var commonLabel = container.selectAll('g.axistext')\n        .data(showCommonLabel ? [0] : []);\n    commonLabel.enter().append('g')\n        .classed('axistext', true);\n    commonLabel.exit().remove();\n\n    commonLabel.each(function() {\n        var label = d3.select(this);\n        var lpath = Lib.ensureSingle(label, 'path', '', function(s) {\n            s.style({'stroke-width': '1px'});\n        });\n        var ltext = Lib.ensureSingle(label, 'text', '', function(s) {\n            // prohibit tex interpretation until we can handle\n            // tex and regular text together\n            s.attr('data-notex', 1);\n        });\n\n        var commonBgColor = commonLabelOpts.bgcolor || Color.defaultLine;\n        var commonStroke = commonLabelOpts.bordercolor || Color.contrast(commonBgColor);\n        var contrastColor = Color.contrast(commonBgColor);\n\n        lpath.style({\n            fill: commonBgColor,\n            stroke: commonStroke\n        });\n\n        ltext.text(t0)\n            .call(Drawing.font,\n                commonLabelOpts.font.family || fontFamily,\n                commonLabelOpts.font.size || fontSize,\n                commonLabelOpts.font.color || contrastColor\n             )\n            .call(svgTextUtils.positionText, 0, 0)\n            .call(svgTextUtils.convertToTspans, gd);\n\n        label.attr('transform', '');\n\n        var tbb = ltext.node().getBoundingClientRect();\n        if(hovermode === 'x') {\n            ltext.attr('text-anchor', 'middle')\n                .call(svgTextUtils.positionText, 0, (xa.side === 'top' ?\n                    (outerTop - tbb.bottom - HOVERARROWSIZE - HOVERTEXTPAD) :\n                    (outerTop - tbb.top + HOVERARROWSIZE + HOVERTEXTPAD)));\n\n            var topsign = xa.side === 'top' ? '-' : '';\n            lpath.attr('d', 'M0,0' +\n                'L' + HOVERARROWSIZE + ',' + topsign + HOVERARROWSIZE +\n                'H' + (HOVERTEXTPAD + tbb.width / 2) +\n                'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) +\n                'H-' + (HOVERTEXTPAD + tbb.width / 2) +\n                'V' + topsign + HOVERARROWSIZE + 'H-' + HOVERARROWSIZE + 'Z');\n\n            label.attr('transform', 'translate(' +\n                (xa._offset + (c0.x0 + c0.x1) / 2) + ',' +\n                (ya._offset + (xa.side === 'top' ? 0 : ya._length)) + ')');\n        } else {\n            ltext.attr('text-anchor', ya.side === 'right' ? 'start' : 'end')\n                .call(svgTextUtils.positionText,\n                    (ya.side === 'right' ? 1 : -1) * (HOVERTEXTPAD + HOVERARROWSIZE),\n                    outerTop - tbb.top - tbb.height / 2);\n\n            var leftsign = ya.side === 'right' ? '' : '-';\n            lpath.attr('d', 'M0,0' +\n                'L' + leftsign + HOVERARROWSIZE + ',' + HOVERARROWSIZE +\n                'V' + (HOVERTEXTPAD + tbb.height / 2) +\n                'h' + leftsign + (HOVERTEXTPAD * 2 + tbb.width) +\n                'V-' + (HOVERTEXTPAD + tbb.height / 2) +\n                'H' + leftsign + HOVERARROWSIZE + 'V-' + HOVERARROWSIZE + 'Z');\n\n            label.attr('transform', 'translate(' +\n                (xa._offset + (ya.side === 'right' ? xa._length : 0)) + ',' +\n                (ya._offset + (c0.y0 + c0.y1) / 2) + ')');\n        }\n        // remove the \"close but not quite\" points\n        // because of error bars, only take up to a space\n        hoverData = hoverData.filter(function(d) {\n            return (d.zLabelVal !== undefined) ||\n                (d[commonAttr] || '').split(' ')[0] === t00;\n        });\n    });\n\n    // show all the individual labels\n\n    // first create the objects\n    var hoverLabels = container.selectAll('g.hovertext')\n        .data(hoverData, function(d) {\n            // N.B. when multiple items have the same result key-function value,\n            // only the first of those items in hoverData gets rendered\n            return [d.trace.index, d.index, d.x0, d.y0, d.name, d.attr, d.xa, d.ya || ''].join(',');\n        });\n    hoverLabels.enter().append('g')\n        .classed('hovertext', true)\n        .each(function() {\n            var g = d3.select(this);\n            // trace name label (rect and text.name)\n            g.append('rect')\n                .call(Color.fill, Color.addOpacity(bgColor, 0.8));\n            g.append('text').classed('name', true);\n            // trace data label (path and text.nums)\n            g.append('path')\n                .style('stroke-width', '1px');\n            g.append('text').classed('nums', true)\n                .call(Drawing.font, fontFamily, fontSize);\n        });\n    hoverLabels.exit().remove();\n\n    // then put the text in, position the pointer to the data,\n    // and figure out sizes\n    hoverLabels.each(function(d) {\n        var g = d3.select(this).attr('transform', '');\n        var name = '';\n        var text = '';\n\n        // combine possible non-opaque trace color with bgColor\n        var color0 = d.bgcolor || d.color;\n        // color for 'nums' part of the label\n        var numsColor = Color.combine(\n            Color.opacity(color0) ? color0 : Color.defaultLine,\n            bgColor\n        );\n        // color for 'name' part of the label\n        var nameColor = Color.combine(\n            Color.opacity(d.color) ? d.color : Color.defaultLine,\n            bgColor\n        );\n        // find a contrasting color for border and text\n        var contrastColor = d.borderColor || Color.contrast(numsColor);\n\n        // to get custom 'name' labels pass cleanPoint\n        if(d.nameOverride !== undefined) d.name = d.nameOverride;\n\n        if(d.name) {\n            if(d.trace._meta) {\n                d.name = Lib.templateString(d.name, d.trace._meta);\n            }\n            name = plainText(d.name, d.nameLength);\n        }\n\n        if(d.zLabel !== undefined) {\n            if(d.xLabel !== undefined) text += 'x: ' + d.xLabel + '<br>';\n            if(d.yLabel !== undefined) text += 'y: ' + d.yLabel + '<br>';\n            if(d.trace.type !== 'choropleth' && d.trace.type !== 'choroplethmapbox') {\n                text += (text ? 'z: ' : '') + d.zLabel;\n            }\n        } else if(showCommonLabel && d[hovermode + 'Label'] === t0) {\n            text = d[(hovermode === 'x' ? 'y' : 'x') + 'Label'] || '';\n        } else if(d.xLabel === undefined) {\n            if(d.yLabel !== undefined && d.trace.type !== 'scattercarpet') {\n                text = d.yLabel;\n            }\n        } else if(d.yLabel === undefined) text = d.xLabel;\n        else text = '(' + d.xLabel + ', ' + d.yLabel + ')';\n\n        if((d.text || d.text === 0) && !Array.isArray(d.text)) {\n            text += (text ? '<br>' : '') + d.text;\n        }\n\n        // used by other modules (initially just ternary) that\n        // manage their own hoverinfo independent of cleanPoint\n        // the rest of this will still apply, so such modules\n        // can still put things in (x|y|z)Label, text, and name\n        // and hoverinfo will still determine their visibility\n        if(d.extraText !== undefined) text += (text ? '<br>' : '') + d.extraText;\n\n        // if 'text' is empty at this point,\n        // and hovertemplate is not defined,\n        // put 'name' in main label and don't show secondary label\n        if(text === '' && !d.hovertemplate) {\n            // if 'name' is also empty, remove entire label\n            if(name === '') g.remove();\n            text = name;\n        }\n\n        // hovertemplate\n        var d3locale = fullLayout._d3locale;\n        var hovertemplate = d.hovertemplate || false;\n        var hovertemplateLabels = d.hovertemplateLabels || d;\n        var eventData = d.eventData[0] || {};\n        if(hovertemplate) {\n            text = Lib.hovertemplateString(\n                hovertemplate,\n                hovertemplateLabels,\n                d3locale,\n                eventData,\n                d.trace._meta\n            );\n\n            text = text.replace(EXTRA_STRING_REGEX, function(match, extra) {\n                // assign name for secondary text label\n                name = plainText(extra, d.nameLength);\n                // remove from main text label\n                return '';\n            });\n        }\n\n        // main label\n        var tx = g.select('text.nums')\n            .call(Drawing.font,\n                d.fontFamily || fontFamily,\n                d.fontSize || fontSize,\n                d.fontColor || contrastColor)\n            .text(text)\n            .attr('data-notex', 1)\n            .call(svgTextUtils.positionText, 0, 0)\n            .call(svgTextUtils.convertToTspans, gd);\n\n        var tx2 = g.select('text.name');\n        var tx2width = 0;\n        var tx2height = 0;\n\n        // secondary label for non-empty 'name'\n        if(name && name !== text) {\n            tx2.call(Drawing.font,\n                    d.fontFamily || fontFamily,\n                    d.fontSize || fontSize,\n                    nameColor)\n                .text(name)\n                .attr('data-notex', 1)\n                .call(svgTextUtils.positionText, 0, 0)\n                .call(svgTextUtils.convertToTspans, gd);\n\n            var t2bb = tx2.node().getBoundingClientRect();\n            tx2width = t2bb.width + 2 * HOVERTEXTPAD;\n            tx2height = t2bb.height + 2 * HOVERTEXTPAD;\n        } else {\n            tx2.remove();\n            g.select('rect').remove();\n        }\n\n        g.select('path').style({\n            fill: numsColor,\n            stroke: contrastColor\n        });\n\n        var tbb = tx.node().getBoundingClientRect();\n        var htx = d.xa._offset + (d.x0 + d.x1) / 2;\n        var hty = d.ya._offset + (d.y0 + d.y1) / 2;\n        var dx = Math.abs(d.x1 - d.x0);\n        var dy = Math.abs(d.y1 - d.y0);\n        var txTotalWidth = tbb.width + HOVERARROWSIZE + HOVERTEXTPAD + tx2width;\n        var anchorStartOK, anchorEndOK;\n\n        d.ty0 = outerTop - tbb.top;\n        d.bx = tbb.width + 2 * HOVERTEXTPAD;\n        d.by = Math.max(tbb.height + 2 * HOVERTEXTPAD, tx2height);\n        d.anchor = 'start';\n        d.txwidth = tbb.width;\n        d.tx2width = tx2width;\n        d.offset = 0;\n\n        if(rotateLabels) {\n            d.pos = htx;\n            anchorStartOK = hty + dy / 2 + txTotalWidth <= outerHeight;\n            anchorEndOK = hty - dy / 2 - txTotalWidth >= 0;\n            if((d.idealAlign === 'top' || !anchorStartOK) && anchorEndOK) {\n                hty -= dy / 2;\n                d.anchor = 'end';\n            } else if(anchorStartOK) {\n                hty += dy / 2;\n                d.anchor = 'start';\n            } else d.anchor = 'middle';\n        } else {\n            d.pos = hty;\n            anchorStartOK = htx + dx / 2 + txTotalWidth <= outerWidth;\n            anchorEndOK = htx - dx / 2 - txTotalWidth >= 0;\n\n            if((d.idealAlign === 'left' || !anchorStartOK) && anchorEndOK) {\n                htx -= dx / 2;\n                d.anchor = 'end';\n            } else if(anchorStartOK) {\n                htx += dx / 2;\n                d.anchor = 'start';\n            } else {\n                d.anchor = 'middle';\n\n                var txHalfWidth = txTotalWidth / 2;\n                var overflowR = htx + txHalfWidth - outerWidth;\n                var overflowL = htx - txHalfWidth;\n                if(overflowR > 0) htx -= overflowR;\n                if(overflowL < 0) htx += -overflowL;\n            }\n        }\n\n        tx.attr('text-anchor', d.anchor);\n        if(tx2width) tx2.attr('text-anchor', d.anchor);\n        g.attr('transform', 'translate(' + htx + ',' + hty + ')' +\n            (rotateLabels ? 'rotate(' + YANGLE + ')' : ''));\n    });\n\n    return hoverLabels;\n}\n\n// Make groups of touching points, and within each group\n// move each point so that no labels overlap, but the average\n// label position is the same as it was before moving. Indicentally,\n// this is equivalent to saying all the labels are on equal linear\n// springs about their initial position. Initially, each point is\n// its own group, but as we find overlaps we will clump the points.\n//\n// Also, there are hard constraints at the edges of the graphs,\n// that push all groups to the middle so they are visible. I don't\n// know what happens if the group spans all the way from one edge to\n// the other, though it hardly matters - there's just too much\n// information then.\nfunction hoverAvoidOverlaps(hoverLabels, axKey, fullLayout) {\n    var nummoves = 0;\n    var axSign = 1;\n    var nLabels = hoverLabels.size();\n\n    // make groups of touching points\n    var pointgroups = new Array(nLabels);\n    var k = 0;\n\n    hoverLabels.each(function(d) {\n        var ax = d[axKey];\n        var axIsX = ax._id.charAt(0) === 'x';\n        var rng = ax.range;\n\n        if(k === 0 && rng && ((rng[0] > rng[1]) !== axIsX)) {\n            axSign = -1;\n        }\n        pointgroups[k++] = [{\n            datum: d,\n            traceIndex: d.trace.index,\n            dp: 0,\n            pos: d.pos,\n            posref: d.posref,\n            size: d.by * (axIsX ? YFACTOR : 1) / 2,\n            pmin: 0,\n            pmax: (axIsX ? fullLayout.width : fullLayout.height)\n        }];\n    });\n\n    pointgroups.sort(function(a, b) {\n        return (a[0].posref - b[0].posref) ||\n            // for equal positions, sort trace indices increasing or decreasing\n            // depending on whether the axis is reversed or not... so stacked\n            // traces will generally keep their order even if one trace adds\n            // nothing to the stack.\n            (axSign * (b[0].traceIndex - a[0].traceIndex));\n    });\n\n    var donepositioning, topOverlap, bottomOverlap, i, j, pti, sumdp;\n\n    function constrainGroup(grp) {\n        var minPt = grp[0];\n        var maxPt = grp[grp.length - 1];\n\n        // overlap with the top - positive vals are overlaps\n        topOverlap = minPt.pmin - minPt.pos - minPt.dp + minPt.size;\n\n        // overlap with the bottom - positive vals are overlaps\n        bottomOverlap = maxPt.pos + maxPt.dp + maxPt.size - minPt.pmax;\n\n        // check for min overlap first, so that we always\n        // see the largest labels\n        // allow for .01px overlap, so we don't get an\n        // infinite loop from rounding errors\n        if(topOverlap > 0.01) {\n            for(j = grp.length - 1; j >= 0; j--) grp[j].dp += topOverlap;\n            donepositioning = false;\n        }\n        if(bottomOverlap < 0.01) return;\n        if(topOverlap < -0.01) {\n            // make sure we're not pushing back and forth\n            for(j = grp.length - 1; j >= 0; j--) grp[j].dp -= bottomOverlap;\n            donepositioning = false;\n        }\n        if(!donepositioning) return;\n\n        // no room to fix positioning, delete off-screen points\n\n        // first see how many points we need to delete\n        var deleteCount = 0;\n        for(i = 0; i < grp.length; i++) {\n            pti = grp[i];\n            if(pti.pos + pti.dp + pti.size > minPt.pmax) deleteCount++;\n        }\n\n        // start by deleting points whose data is off screen\n        for(i = grp.length - 1; i >= 0; i--) {\n            if(deleteCount <= 0) break;\n            pti = grp[i];\n\n            // pos has already been constrained to [pmin,pmax]\n            // so look for points close to that to delete\n            if(pti.pos > minPt.pmax - 1) {\n                pti.del = true;\n                deleteCount--;\n            }\n        }\n        for(i = 0; i < grp.length; i++) {\n            if(deleteCount <= 0) break;\n            pti = grp[i];\n\n            // pos has already been constrained to [pmin,pmax]\n            // so look for points close to that to delete\n            if(pti.pos < minPt.pmin + 1) {\n                pti.del = true;\n                deleteCount--;\n\n                // shift the whole group minus into this new space\n                bottomOverlap = pti.size * 2;\n                for(j = grp.length - 1; j >= 0; j--) grp[j].dp -= bottomOverlap;\n            }\n        }\n        // then delete points that go off the bottom\n        for(i = grp.length - 1; i >= 0; i--) {\n            if(deleteCount <= 0) break;\n            pti = grp[i];\n            if(pti.pos + pti.dp + pti.size > minPt.pmax) {\n                pti.del = true;\n                deleteCount--;\n            }\n        }\n    }\n\n    // loop through groups, combining them if they overlap,\n    // until nothing moves\n    while(!donepositioning && nummoves <= nLabels) {\n        // to avoid infinite loops, don't move more times\n        // than there are traces\n        nummoves++;\n\n        // assume nothing will move in this iteration,\n        // reverse this if it does\n        donepositioning = true;\n        i = 0;\n        while(i < pointgroups.length - 1) {\n            // the higher (g0) and lower (g1) point group\n            var g0 = pointgroups[i];\n            var g1 = pointgroups[i + 1];\n\n            // the lowest point in the higher group (p0)\n            // the highest point in the lower group (p1)\n            var p0 = g0[g0.length - 1];\n            var p1 = g1[0];\n            topOverlap = p0.pos + p0.dp + p0.size - p1.pos - p1.dp + p1.size;\n\n            // Only group points that lie on the same axes\n            if(topOverlap > 0.01 && (p0.pmin === p1.pmin) && (p0.pmax === p1.pmax)) {\n                // push the new point(s) added to this group out of the way\n                for(j = g1.length - 1; j >= 0; j--) g1[j].dp += topOverlap;\n\n                // add them to the group\n                g0.push.apply(g0, g1);\n                pointgroups.splice(i + 1, 1);\n\n                // adjust for minimum average movement\n                sumdp = 0;\n                for(j = g0.length - 1; j >= 0; j--) sumdp += g0[j].dp;\n                bottomOverlap = sumdp / g0.length;\n                for(j = g0.length - 1; j >= 0; j--) g0[j].dp -= bottomOverlap;\n                donepositioning = false;\n            } else i++;\n        }\n\n        // check if we're going off the plot on either side and fix\n        pointgroups.forEach(constrainGroup);\n    }\n\n    // now put these offsets into hoverData\n    for(i = pointgroups.length - 1; i >= 0; i--) {\n        var grp = pointgroups[i];\n        for(j = grp.length - 1; j >= 0; j--) {\n            var pt = grp[j];\n            var hoverPt = pt.datum;\n            hoverPt.offset = pt.dp;\n            hoverPt.del = pt.del;\n        }\n    }\n}\n\nfunction alignHoverText(hoverLabels, rotateLabels) {\n    // finally set the text positioning relative to the data and draw the\n    // box around it\n    hoverLabels.each(function(d) {\n        var g = d3.select(this);\n        if(d.del) return g.remove();\n\n        var tx = g.select('text.nums');\n        var anchor = d.anchor;\n        var horzSign = anchor === 'end' ? -1 : 1;\n        var alignShift = {start: 1, end: -1, middle: 0}[anchor];\n        var txx = alignShift * (HOVERARROWSIZE + HOVERTEXTPAD);\n        var tx2x = txx + alignShift * (d.txwidth + HOVERTEXTPAD);\n        var offsetX = 0;\n        var offsetY = d.offset;\n\n        if(anchor === 'middle') {\n            txx -= d.tx2width / 2;\n            tx2x += d.txwidth / 2 + HOVERTEXTPAD;\n        }\n        if(rotateLabels) {\n            offsetY *= -YSHIFTY;\n            offsetX = d.offset * YSHIFTX;\n        }\n\n        g.select('path').attr('d', anchor === 'middle' ?\n            // middle aligned: rect centered on data\n            ('M-' + (d.bx / 2 + d.tx2width / 2) + ',' + (offsetY - d.by / 2) +\n              'h' + d.bx + 'v' + d.by + 'h-' + d.bx + 'Z') :\n            // left or right aligned: side rect with arrow to data\n            ('M0,0L' + (horzSign * HOVERARROWSIZE + offsetX) + ',' + (HOVERARROWSIZE + offsetY) +\n                'v' + (d.by / 2 - HOVERARROWSIZE) +\n                'h' + (horzSign * d.bx) +\n                'v-' + d.by +\n                'H' + (horzSign * HOVERARROWSIZE + offsetX) +\n                'V' + (offsetY - HOVERARROWSIZE) +\n                'Z'));\n\n        var posX = txx + offsetX;\n        var posY = offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD;\n        var textAlign = d.textAlign || 'auto';\n\n        if(textAlign !== 'auto') {\n            if(textAlign === 'left' && anchor !== 'start') {\n                tx.attr('text-anchor', 'start');\n                posX = anchor === 'middle' ?\n                    -d.bx / 2 - d.tx2width / 2 + HOVERTEXTPAD :\n                    -d.bx - HOVERTEXTPAD;\n            } else if(textAlign === 'right' && anchor !== 'end') {\n                tx.attr('text-anchor', 'end');\n                posX = anchor === 'middle' ?\n                    d.bx / 2 - d.tx2width / 2 - HOVERTEXTPAD :\n                    d.bx + HOVERTEXTPAD;\n            }\n        }\n\n        tx.call(svgTextUtils.positionText, posX, posY);\n\n        if(d.tx2width) {\n            g.select('text.name')\n                .call(svgTextUtils.positionText,\n                    tx2x + alignShift * HOVERTEXTPAD + offsetX,\n                    offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD);\n            g.select('rect')\n                .call(Drawing.setRect,\n                    tx2x + (alignShift - 1) * d.tx2width / 2 + offsetX,\n                    offsetY - d.by / 2 - 1,\n                    d.tx2width, d.by + 2);\n        }\n    });\n}\n\nfunction cleanPoint(d, hovermode) {\n    var index = d.index;\n    var trace = d.trace || {};\n    var cd0 = d.cd[0];\n    var cd = d.cd[index] || {};\n\n    function pass(v) {\n        return v || (isNumeric(v) && v === 0);\n    }\n\n    var getVal = Array.isArray(index) ?\n        function(calcKey, traceKey) {\n            var v = Lib.castOption(cd0, index, calcKey);\n            return pass(v) ? v : Lib.extractOption({}, trace, '', traceKey);\n        } :\n        function(calcKey, traceKey) {\n            return Lib.extractOption(cd, trace, calcKey, traceKey);\n        };\n\n    function fill(key, calcKey, traceKey) {\n        var val = getVal(calcKey, traceKey);\n        if(pass(val)) d[key] = val;\n    }\n\n    fill('hoverinfo', 'hi', 'hoverinfo');\n    fill('bgcolor', 'hbg', 'hoverlabel.bgcolor');\n    fill('borderColor', 'hbc', 'hoverlabel.bordercolor');\n    fill('fontFamily', 'htf', 'hoverlabel.font.family');\n    fill('fontSize', 'hts', 'hoverlabel.font.size');\n    fill('fontColor', 'htc', 'hoverlabel.font.color');\n    fill('nameLength', 'hnl', 'hoverlabel.namelength');\n    fill('textAlign', 'hta', 'hoverlabel.align');\n\n    d.posref = (hovermode === 'y' || (hovermode === 'closest' && trace.orientation === 'h')) ?\n        (d.xa._offset + (d.x0 + d.x1) / 2) :\n        (d.ya._offset + (d.y0 + d.y1) / 2);\n\n    // then constrain all the positions to be on the plot\n    d.x0 = Lib.constrain(d.x0, 0, d.xa._length);\n    d.x1 = Lib.constrain(d.x1, 0, d.xa._length);\n    d.y0 = Lib.constrain(d.y0, 0, d.ya._length);\n    d.y1 = Lib.constrain(d.y1, 0, d.ya._length);\n\n    // and convert the x and y label values into formatted text\n    if(d.xLabelVal !== undefined) {\n        d.xLabel = ('xLabel' in d) ? d.xLabel : Axes.hoverLabelText(d.xa, d.xLabelVal);\n        d.xVal = d.xa.c2d(d.xLabelVal);\n    }\n    if(d.yLabelVal !== undefined) {\n        d.yLabel = ('yLabel' in d) ? d.yLabel : Axes.hoverLabelText(d.ya, d.yLabelVal);\n        d.yVal = d.ya.c2d(d.yLabelVal);\n    }\n\n    // Traces like heatmaps generate the zLabel in their hoverPoints function\n    if(d.zLabelVal !== undefined && d.zLabel === undefined) {\n        d.zLabel = String(d.zLabelVal);\n    }\n\n    // for box means and error bars, add the range to the label\n    if(!isNaN(d.xerr) && !(d.xa.type === 'log' && d.xerr <= 0)) {\n        var xeText = Axes.tickText(d.xa, d.xa.c2l(d.xerr), 'hover').text;\n        if(d.xerrneg !== undefined) {\n            d.xLabel += ' +' + xeText + ' / -' +\n                Axes.tickText(d.xa, d.xa.c2l(d.xerrneg), 'hover').text;\n        } else d.xLabel += ' ± ' + xeText;\n\n        // small distance penalty for error bars, so that if there are\n        // traces with errors and some without, the error bar label will\n        // hoist up to the point\n        if(hovermode === 'x') d.distance += 1;\n    }\n    if(!isNaN(d.yerr) && !(d.ya.type === 'log' && d.yerr <= 0)) {\n        var yeText = Axes.tickText(d.ya, d.ya.c2l(d.yerr), 'hover').text;\n        if(d.yerrneg !== undefined) {\n            d.yLabel += ' +' + yeText + ' / -' +\n                Axes.tickText(d.ya, d.ya.c2l(d.yerrneg), 'hover').text;\n        } else d.yLabel += ' ± ' + yeText;\n\n        if(hovermode === 'y') d.distance += 1;\n    }\n\n    var infomode = d.hoverinfo || d.trace.hoverinfo;\n\n    if(infomode && infomode !== 'all') {\n        infomode = Array.isArray(infomode) ? infomode : infomode.split('+');\n        if(infomode.indexOf('x') === -1) d.xLabel = undefined;\n        if(infomode.indexOf('y') === -1) d.yLabel = undefined;\n        if(infomode.indexOf('z') === -1) d.zLabel = undefined;\n        if(infomode.indexOf('text') === -1) d.text = undefined;\n        if(infomode.indexOf('name') === -1) d.name = undefined;\n    }\n\n    return d;\n}\n\nfunction createSpikelines(closestPoints, opts) {\n    var container = opts.container;\n    var fullLayout = opts.fullLayout;\n    var evt = opts.event;\n    var showY = !!closestPoints.hLinePoint;\n    var showX = !!closestPoints.vLinePoint;\n\n    var xa, ya;\n\n    // Remove old spikeline items\n    container.selectAll('.spikeline').remove();\n\n    if(!(showX || showY)) return;\n\n    var contrastColor = Color.combine(fullLayout.plot_bgcolor, fullLayout.paper_bgcolor);\n\n    // Horizontal line (to y-axis)\n    if(showY) {\n        var hLinePoint = closestPoints.hLinePoint;\n        var hLinePointX, hLinePointY;\n\n        xa = hLinePoint && hLinePoint.xa;\n        ya = hLinePoint && hLinePoint.ya;\n        var ySnap = ya.spikesnap;\n\n        if(ySnap === 'cursor') {\n            hLinePointX = evt.pointerX;\n            hLinePointY = evt.pointerY;\n        } else {\n            hLinePointX = xa._offset + hLinePoint.x;\n            hLinePointY = ya._offset + hLinePoint.y;\n        }\n        var dfltHLineColor = tinycolor.readability(hLinePoint.color, contrastColor) < 1.5 ?\n            Color.contrast(contrastColor) : hLinePoint.color;\n        var yMode = ya.spikemode;\n        var yThickness = ya.spikethickness;\n        var yColor = ya.spikecolor || dfltHLineColor;\n        var yBB = ya._boundingBox;\n        var xEdge = ((yBB.left + yBB.right) / 2) < hLinePointX ? yBB.right : yBB.left;\n        var xBase, xEndSpike;\n\n        if(yMode.indexOf('toaxis') !== -1 || yMode.indexOf('across') !== -1) {\n            if(yMode.indexOf('toaxis') !== -1) {\n                xBase = xEdge;\n                xEndSpike = hLinePointX;\n            }\n            if(yMode.indexOf('across') !== -1) {\n                xBase = ya._counterSpan[0];\n                xEndSpike = ya._counterSpan[1];\n            }\n\n            // Foreground horizontal line (to y-axis)\n            container.insert('line', ':first-child')\n                .attr({\n                    x1: xBase,\n                    x2: xEndSpike,\n                    y1: hLinePointY,\n                    y2: hLinePointY,\n                    'stroke-width': yThickness,\n                    stroke: yColor,\n                    'stroke-dasharray': Drawing.dashStyle(ya.spikedash, yThickness)\n                })\n                .classed('spikeline', true)\n                .classed('crisp', true);\n\n            // Background horizontal Line (to y-axis)\n            container.insert('line', ':first-child')\n                .attr({\n                    x1: xBase,\n                    x2: xEndSpike,\n                    y1: hLinePointY,\n                    y2: hLinePointY,\n                    'stroke-width': yThickness + 2,\n                    stroke: contrastColor\n                })\n                .classed('spikeline', true)\n                .classed('crisp', true);\n        }\n        // Y axis marker\n        if(yMode.indexOf('marker') !== -1) {\n            container.insert('circle', ':first-child')\n                .attr({\n                    cx: xEdge + (ya.side !== 'right' ? yThickness : -yThickness),\n                    cy: hLinePointY,\n                    r: yThickness,\n                    fill: yColor\n                })\n                .classed('spikeline', true);\n        }\n    }\n\n    if(showX) {\n        var vLinePoint = closestPoints.vLinePoint;\n        var vLinePointX, vLinePointY;\n\n        xa = vLinePoint && vLinePoint.xa;\n        ya = vLinePoint && vLinePoint.ya;\n        var xSnap = xa.spikesnap;\n\n        if(xSnap === 'cursor') {\n            vLinePointX = evt.pointerX;\n            vLinePointY = evt.pointerY;\n        } else {\n            vLinePointX = xa._offset + vLinePoint.x;\n            vLinePointY = ya._offset + vLinePoint.y;\n        }\n        var dfltVLineColor = tinycolor.readability(vLinePoint.color, contrastColor) < 1.5 ?\n            Color.contrast(contrastColor) : vLinePoint.color;\n        var xMode = xa.spikemode;\n        var xThickness = xa.spikethickness;\n        var xColor = xa.spikecolor || dfltVLineColor;\n        var xBB = xa._boundingBox;\n        var yEdge = ((xBB.top + xBB.bottom) / 2) < vLinePointY ? xBB.bottom : xBB.top;\n        var yBase, yEndSpike;\n\n        if(xMode.indexOf('toaxis') !== -1 || xMode.indexOf('across') !== -1) {\n            if(xMode.indexOf('toaxis') !== -1) {\n                yBase = yEdge;\n                yEndSpike = vLinePointY;\n            }\n            if(xMode.indexOf('across') !== -1) {\n                yBase = xa._counterSpan[0];\n                yEndSpike = xa._counterSpan[1];\n            }\n\n            // Foreground vertical line (to x-axis)\n            container.insert('line', ':first-child')\n                .attr({\n                    x1: vLinePointX,\n                    x2: vLinePointX,\n                    y1: yBase,\n                    y2: yEndSpike,\n                    'stroke-width': xThickness,\n                    stroke: xColor,\n                    'stroke-dasharray': Drawing.dashStyle(xa.spikedash, xThickness)\n                })\n                .classed('spikeline', true)\n                .classed('crisp', true);\n\n            // Background vertical line (to x-axis)\n            container.insert('line', ':first-child')\n                .attr({\n                    x1: vLinePointX,\n                    x2: vLinePointX,\n                    y1: yBase,\n                    y2: yEndSpike,\n                    'stroke-width': xThickness + 2,\n                    stroke: contrastColor\n                })\n                .classed('spikeline', true)\n                .classed('crisp', true);\n        }\n\n        // X axis marker\n        if(xMode.indexOf('marker') !== -1) {\n            container.insert('circle', ':first-child')\n                .attr({\n                    cx: vLinePointX,\n                    cy: yEdge - (xa.side !== 'top' ? xThickness : -xThickness),\n                    r: xThickness,\n                    fill: xColor\n                })\n                .classed('spikeline', true);\n        }\n    }\n}\n\nfunction hoverChanged(gd, evt, oldhoverdata) {\n    // don't emit any events if nothing changed\n    if(!oldhoverdata || oldhoverdata.length !== gd._hoverdata.length) return true;\n\n    for(var i = oldhoverdata.length - 1; i >= 0; i--) {\n        var oldPt = oldhoverdata[i];\n        var newPt = gd._hoverdata[i];\n\n        if(oldPt.curveNumber !== newPt.curveNumber ||\n            String(oldPt.pointNumber) !== String(newPt.pointNumber) ||\n            String(oldPt.pointNumbers) !== String(newPt.pointNumbers)\n        ) {\n            return true;\n        }\n    }\n    return false;\n}\n\nfunction spikesChanged(gd, oldspikepoints) {\n    // don't relayout the plot because of new spikelines if spikelines points didn't change\n    if(!oldspikepoints) return true;\n    if(oldspikepoints.vLinePoint !== gd._spikepoints.vLinePoint ||\n        oldspikepoints.hLinePoint !== gd._spikepoints.hLinePoint\n    ) return true;\n    return false;\n}\n\nfunction plainText(s, len) {\n    return svgTextUtils.plainText(s || '', {\n        len: len,\n        allowedTags: ['br', 'sub', 'sup', 'b', 'i', 'em']\n    });\n}\n\n},{\"../../lib\":719,\"../../lib/events\":709,\"../../lib/override_cursor\":730,\"../../lib/svg_text_utils\":743,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"../color\":593,\"../dragelement\":611,\"../drawing\":614,\"./constants\":626,\"./helpers\":628,\"d3\":163,\"fast-isnumeric\":225,\"tinycolor2\":537}],630:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts) {\n    opts = opts || {};\n\n    coerce('hoverlabel.bgcolor', opts.bgcolor);\n    coerce('hoverlabel.bordercolor', opts.bordercolor);\n    coerce('hoverlabel.namelength', opts.namelength);\n    Lib.coerceFont(coerce, 'hoverlabel.font', opts.font);\n    coerce('hoverlabel.align', opts.align);\n};\n\n},{\"../../lib\":719}],631:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar FORMAT_LINK = _dereq_('../../constants/docs').FORMAT_LINK;\n\nmodule.exports = function(opts, extra) {\n    opts = opts || {};\n    extra = extra || {};\n\n    var descPart = extra.description ? ' ' + extra.description : '';\n    var keys = extra.keys || [];\n    if(keys.length > 0) {\n        var quotedKeys = [];\n        for(var i = 0; i < keys.length; i++) {\n            quotedKeys[i] = '`' + keys[i] + '`';\n        }\n        descPart = descPart + 'Finally, the template string has access to ';\n        if(keys.length === 1) {\n            descPart = 'variable ' + quotedKeys[0];\n        } else {\n            descPart = 'variables ' + quotedKeys.slice(0, -1).join(', ') + ' and ' + quotedKeys.slice(-1) + '.';\n        }\n    }\n\n    var hovertemplate = {\n        valType: 'string',\n        \n        dflt: '',\n        editType: opts.editType || 'none',\n        \n    };\n\n    if(opts.arrayOk !== false) {\n        hovertemplate.arrayOk = true;\n    }\n\n    return hovertemplate;\n};\n\n},{\"../../constants/docs\":690}],632:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Lib = _dereq_('../../lib');\nvar dragElement = _dereq_('../dragelement');\nvar helpers = _dereq_('./helpers');\nvar layoutAttributes = _dereq_('./layout_attributes');\nvar hoverModule = _dereq_('./hover');\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'fx',\n\n    constants: _dereq_('./constants'),\n    schema: {\n        layout: layoutAttributes\n    },\n\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: layoutAttributes,\n\n    supplyLayoutGlobalDefaults: _dereq_('./layout_global_defaults'),\n    supplyDefaults: _dereq_('./defaults'),\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n\n    calc: _dereq_('./calc'),\n\n    getDistanceFunction: helpers.getDistanceFunction,\n    getClosest: helpers.getClosest,\n    inbox: helpers.inbox,\n    quadrature: helpers.quadrature,\n    appendArrayPointValue: helpers.appendArrayPointValue,\n\n    castHoverOption: castHoverOption,\n    castHoverinfo: castHoverinfo,\n\n    hover: hoverModule.hover,\n    unhover: dragElement.unhover,\n\n    loneHover: hoverModule.loneHover,\n    loneUnhover: loneUnhover,\n\n    click: _dereq_('./click')\n};\n\nfunction loneUnhover(containerOrSelection) {\n    // duck type whether the arg is a d3 selection because ie9 doesn't\n    // handle instanceof like modern browsers do.\n    var selection = Lib.isD3Selection(containerOrSelection) ?\n            containerOrSelection :\n            d3.select(containerOrSelection);\n\n    selection.selectAll('g.hovertext').remove();\n    selection.selectAll('.spikeline').remove();\n}\n\n// helpers for traces that use Fx.loneHover\n\nfunction castHoverOption(trace, ptNumber, attr) {\n    return Lib.castOption(trace, ptNumber, 'hoverlabel.' + attr);\n}\n\nfunction castHoverinfo(trace, fullLayout, ptNumber) {\n    function _coerce(val) {\n        return Lib.coerceHoverinfo({hoverinfo: val}, {_module: trace._module}, fullLayout);\n    }\n\n    return Lib.castOption(trace, ptNumber, 'hoverinfo', _coerce);\n}\n\n},{\"../../lib\":719,\"../dragelement\":611,\"./attributes\":623,\"./calc\":624,\"./click\":625,\"./constants\":626,\"./defaults\":627,\"./helpers\":628,\"./hover\":629,\"./layout_attributes\":633,\"./layout_defaults\":634,\"./layout_global_defaults\":635,\"d3\":163}],633:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar constants = _dereq_('./constants');\n\nvar fontAttrs = _dereq_('../../plots/font_attributes')({\n    editType: 'none',\n    \n});\nfontAttrs.family.dflt = constants.HOVERFONT;\nfontAttrs.size.dflt = constants.HOVERFONTSIZE;\n\nmodule.exports = {\n    clickmode: {\n        valType: 'flaglist',\n        \n        flags: ['event', 'select'],\n        dflt: 'event',\n        editType: 'plot',\n        extras: ['none'],\n        \n    },\n    dragmode: {\n        valType: 'enumerated',\n        \n        values: ['zoom', 'pan', 'select', 'lasso', 'orbit', 'turntable', false],\n        dflt: 'zoom',\n        editType: 'modebar',\n        \n    },\n    hovermode: {\n        valType: 'enumerated',\n        \n        values: ['x', 'y', 'closest', false],\n        editType: 'modebar',\n        \n    },\n    hoverdistance: {\n        valType: 'integer',\n        min: -1,\n        dflt: 20,\n        \n        editType: 'none',\n        \n    },\n    spikedistance: {\n        valType: 'integer',\n        min: -1,\n        dflt: 20,\n        \n        editType: 'none',\n        \n    },\n    hoverlabel: {\n        bgcolor: {\n            valType: 'color',\n            \n            editType: 'none',\n            \n        },\n        bordercolor: {\n            valType: 'color',\n            \n            editType: 'none',\n            \n        },\n        font: fontAttrs,\n        align: {\n            valType: 'enumerated',\n            values: ['left', 'right', 'auto'],\n            dflt: 'auto',\n            \n            editType: 'none',\n            \n        },\n        namelength: {\n            valType: 'integer',\n            min: -1,\n            dflt: 15,\n            \n            editType: 'none',\n            \n        },\n        editType: 'none'\n    },\n    selectdirection: {\n        valType: 'enumerated',\n        \n        values: ['h', 'v', 'd', 'any'],\n        dflt: 'any',\n        \n        editType: 'none'\n    }\n};\n\n},{\"../../plots/font_attributes\":793,\"./constants\":626}],634:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n\n    var clickmode = coerce('clickmode');\n\n    var dragMode = coerce('dragmode');\n    if(dragMode === 'select') coerce('selectdirection');\n\n    var hovermodeDflt;\n    if(layoutOut._has('cartesian')) {\n        if(clickmode.indexOf('select') > -1) {\n            hovermodeDflt = 'closest';\n        } else {\n            // flag for 'horizontal' plots:\n            // determines the state of the mode bar 'compare' hovermode button\n            layoutOut._isHoriz = isHoriz(fullData, layoutOut);\n            hovermodeDflt = layoutOut._isHoriz ? 'y' : 'x';\n        }\n    } else hovermodeDflt = 'closest';\n\n    var hoverMode = coerce('hovermode', hovermodeDflt);\n    if(hoverMode) {\n        coerce('hoverdistance');\n        coerce('spikedistance');\n    }\n\n    // if only mapbox or geo subplots is present on graph,\n    // reset 'zoom' dragmode to 'pan' until 'zoom' is implemented,\n    // so that the correct modebar button is active\n    var hasMapbox = layoutOut._has('mapbox');\n    var hasGeo = layoutOut._has('geo');\n    var len = layoutOut._basePlotModules.length;\n\n    if(layoutOut.dragmode === 'zoom' && (\n        ((hasMapbox || hasGeo) && len === 1) ||\n        (hasMapbox && hasGeo && len === 2)\n    )) {\n        layoutOut.dragmode = 'pan';\n    }\n};\n\nfunction isHoriz(fullData, fullLayout) {\n    var stackOpts = fullLayout._scatterStackOpts || {};\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n        var subplot = trace.xaxis + trace.yaxis;\n        var subplotStackOpts = stackOpts[subplot] || {};\n        var groupOpts = subplotStackOpts[trace.stackgroup] || {};\n\n        if(trace.orientation !== 'h' && groupOpts.orientation !== 'h') {\n            return false;\n        }\n    }\n\n    return true;\n}\n\n},{\"../../lib\":719,\"./layout_attributes\":633}],635:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar handleHoverLabelDefaults = _dereq_('./hoverlabel_defaults');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nmodule.exports = function supplyLayoutGlobalDefaults(layoutIn, layoutOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n\n    handleHoverLabelDefaults(layoutIn, layoutOut, coerce);\n};\n\n},{\"../../lib\":719,\"./hoverlabel_defaults\":630,\"./layout_attributes\":633}],636:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar counterRegex = _dereq_('../../lib/regex').counter;\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\nvar cartesianIdRegex = _dereq_('../../plots/cartesian/constants').idRegex;\nvar Template = _dereq_('../../plot_api/plot_template');\n\nvar gridAttrs = {\n    rows: {\n        valType: 'integer',\n        min: 1,\n        \n        editType: 'plot',\n        \n    },\n    roworder: {\n        valType: 'enumerated',\n        values: ['top to bottom', 'bottom to top'],\n        dflt: 'top to bottom',\n        \n        editType: 'plot',\n        \n    },\n    columns: {\n        valType: 'integer',\n        min: 1,\n        \n        editType: 'plot',\n        \n    },\n    subplots: {\n        valType: 'info_array',\n        freeLength: true,\n        dimensions: 2,\n        items: {valType: 'enumerated', values: [counterRegex('xy').toString(), ''], editType: 'plot'},\n        \n        editType: 'plot',\n        \n    },\n    xaxes: {\n        valType: 'info_array',\n        freeLength: true,\n        items: {valType: 'enumerated', values: [cartesianIdRegex.x.toString(), ''], editType: 'plot'},\n        \n        editType: 'plot',\n        \n    },\n    yaxes: {\n        valType: 'info_array',\n        freeLength: true,\n        items: {valType: 'enumerated', values: [cartesianIdRegex.y.toString(), ''], editType: 'plot'},\n        \n        editType: 'plot',\n        \n    },\n    pattern: {\n        valType: 'enumerated',\n        values: ['independent', 'coupled'],\n        dflt: 'coupled',\n        \n        editType: 'plot',\n        \n    },\n    xgap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        \n        editType: 'plot',\n        \n    },\n    ygap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        \n        editType: 'plot',\n        \n    },\n    domain: domainAttrs({name: 'grid', editType: 'plot', noGridCell: true}, {\n        \n    }),\n    xside: {\n        valType: 'enumerated',\n        values: ['bottom', 'bottom plot', 'top plot', 'top'],\n        dflt: 'bottom plot',\n        \n        editType: 'plot',\n        \n    },\n    yside: {\n        valType: 'enumerated',\n        values: ['left', 'left plot', 'right plot', 'right'],\n        dflt: 'left plot',\n        \n        editType: 'plot',\n        \n    },\n    editType: 'plot'\n};\n\nfunction getAxes(layout, grid, axLetter) {\n    var gridVal = grid[axLetter + 'axes'];\n    var splomVal = Object.keys((layout._splomAxes || {})[axLetter] || {});\n\n    if(Array.isArray(gridVal)) return gridVal;\n    if(splomVal.length) return splomVal;\n}\n\n// the shape of the grid - this needs to be done BEFORE supplyDataDefaults\n// so that non-subplot traces can place themselves in the grid\nfunction sizeDefaults(layoutIn, layoutOut) {\n    var gridIn = layoutIn.grid || {};\n    var xAxes = getAxes(layoutOut, gridIn, 'x');\n    var yAxes = getAxes(layoutOut, gridIn, 'y');\n\n    if(!layoutIn.grid && !xAxes && !yAxes) return;\n\n    var hasSubplotGrid = Array.isArray(gridIn.subplots) && Array.isArray(gridIn.subplots[0]);\n    var hasXaxes = Array.isArray(xAxes);\n    var hasYaxes = Array.isArray(yAxes);\n    var isSplomGenerated = (\n        hasXaxes && xAxes !== gridIn.xaxes &&\n        hasYaxes && yAxes !== gridIn.yaxes\n    );\n\n    var dfltRows, dfltColumns;\n\n    if(hasSubplotGrid) {\n        dfltRows = gridIn.subplots.length;\n        dfltColumns = gridIn.subplots[0].length;\n    } else {\n        if(hasYaxes) dfltRows = yAxes.length;\n        if(hasXaxes) dfltColumns = xAxes.length;\n    }\n\n    var gridOut = Template.newContainer(layoutOut, 'grid');\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(gridIn, gridOut, gridAttrs, attr, dflt);\n    }\n\n    var rows = coerce('rows', dfltRows);\n    var columns = coerce('columns', dfltColumns);\n\n    if(!(rows * columns > 1)) {\n        delete layoutOut.grid;\n        return;\n    }\n\n    if(!hasSubplotGrid && !hasXaxes && !hasYaxes) {\n        var useDefaultSubplots = coerce('pattern') === 'independent';\n        if(useDefaultSubplots) hasSubplotGrid = true;\n    }\n    gridOut._hasSubplotGrid = hasSubplotGrid;\n\n    var rowOrder = coerce('roworder');\n    var reversed = rowOrder === 'top to bottom';\n\n    var dfltGapX = hasSubplotGrid ? 0.2 : 0.1;\n    var dfltGapY = hasSubplotGrid ? 0.3 : 0.1;\n\n    var dfltSideX, dfltSideY;\n    if(isSplomGenerated && layoutOut._splomGridDflt) {\n        dfltSideX = layoutOut._splomGridDflt.xside;\n        dfltSideY = layoutOut._splomGridDflt.yside;\n    }\n\n    gridOut._domains = {\n        x: fillGridPositions('x', coerce, dfltGapX, dfltSideX, columns),\n        y: fillGridPositions('y', coerce, dfltGapY, dfltSideY, rows, reversed)\n    };\n}\n\n// coerce x or y sizing attributes and return an array of domains for this direction\nfunction fillGridPositions(axLetter, coerce, dfltGap, dfltSide, len, reversed) {\n    var dirGap = coerce(axLetter + 'gap', dfltGap);\n    var domain = coerce('domain.' + axLetter);\n    coerce(axLetter + 'side', dfltSide);\n\n    var out = new Array(len);\n    var start = domain[0];\n    var step = (domain[1] - start) / (len - dirGap);\n    var cellDomain = step * (1 - dirGap);\n    for(var i = 0; i < len; i++) {\n        var cellStart = start + step * i;\n        out[reversed ? (len - 1 - i) : i] = [cellStart, cellStart + cellDomain];\n    }\n    return out;\n}\n\n// the (cartesian) contents of the grid - this needs to happen AFTER supplyDataDefaults\n// so that we know what cartesian subplots are available\nfunction contentDefaults(layoutIn, layoutOut) {\n    var gridOut = layoutOut.grid;\n    // make sure we got to the end of handleGridSizing\n    if(!gridOut || !gridOut._domains) return;\n\n    var gridIn = layoutIn.grid || {};\n    var subplots = layoutOut._subplots;\n    var hasSubplotGrid = gridOut._hasSubplotGrid;\n    var rows = gridOut.rows;\n    var columns = gridOut.columns;\n    var useDefaultSubplots = gridOut.pattern === 'independent';\n\n    var i, j, xId, yId, subplotId, subplotsOut, yPos;\n\n    var axisMap = gridOut._axisMap = {};\n\n    if(hasSubplotGrid) {\n        var subplotsIn = gridIn.subplots || [];\n        subplotsOut = gridOut.subplots = new Array(rows);\n        var index = 1;\n\n        for(i = 0; i < rows; i++) {\n            var rowOut = subplotsOut[i] = new Array(columns);\n            var rowIn = subplotsIn[i] || [];\n            for(j = 0; j < columns; j++) {\n                if(useDefaultSubplots) {\n                    subplotId = (index === 1) ? 'xy' : ('x' + index + 'y' + index);\n                    index++;\n                } else subplotId = rowIn[j];\n\n                rowOut[j] = '';\n\n                if(subplots.cartesian.indexOf(subplotId) !== -1) {\n                    yPos = subplotId.indexOf('y');\n                    xId = subplotId.slice(0, yPos);\n                    yId = subplotId.slice(yPos);\n                    if((axisMap[xId] !== undefined && axisMap[xId] !== j) ||\n                        (axisMap[yId] !== undefined && axisMap[yId] !== i)\n                    ) {\n                        continue;\n                    }\n\n                    rowOut[j] = subplotId;\n                    axisMap[xId] = j;\n                    axisMap[yId] = i;\n                }\n            }\n        }\n    } else {\n        var xAxes = getAxes(layoutOut, gridIn, 'x');\n        var yAxes = getAxes(layoutOut, gridIn, 'y');\n        gridOut.xaxes = fillGridAxes(xAxes, subplots.xaxis, columns, axisMap, 'x');\n        gridOut.yaxes = fillGridAxes(yAxes, subplots.yaxis, rows, axisMap, 'y');\n    }\n\n    var anchors = gridOut._anchors = {};\n    var reversed = gridOut.roworder === 'top to bottom';\n\n    for(var axisId in axisMap) {\n        var axLetter = axisId.charAt(0);\n        var side = gridOut[axLetter + 'side'];\n\n        var i0, inc, iFinal;\n\n        if(side.length < 8) {\n            // grid edge -  ie not \"* plot\" - make these as free axes\n            // since we're not guaranteed to have a subplot there at all\n            anchors[axisId] = 'free';\n        } else if(axLetter === 'x') {\n            if((side.charAt(0) === 't') === reversed) {\n                i0 = 0;\n                inc = 1;\n                iFinal = rows;\n            } else {\n                i0 = rows - 1;\n                inc = -1;\n                iFinal = -1;\n            }\n            if(hasSubplotGrid) {\n                var column = axisMap[axisId];\n                for(i = i0; i !== iFinal; i += inc) {\n                    subplotId = subplotsOut[i][column];\n                    if(!subplotId) continue;\n                    yPos = subplotId.indexOf('y');\n                    if(subplotId.slice(0, yPos) === axisId) {\n                        anchors[axisId] = subplotId.slice(yPos);\n                        break;\n                    }\n                }\n            } else {\n                for(i = i0; i !== iFinal; i += inc) {\n                    yId = gridOut.yaxes[i];\n                    if(subplots.cartesian.indexOf(axisId + yId) !== -1) {\n                        anchors[axisId] = yId;\n                        break;\n                    }\n                }\n            }\n        } else {\n            if((side.charAt(0) === 'l')) {\n                i0 = 0;\n                inc = 1;\n                iFinal = columns;\n            } else {\n                i0 = columns - 1;\n                inc = -1;\n                iFinal = -1;\n            }\n            if(hasSubplotGrid) {\n                var row = axisMap[axisId];\n                for(i = i0; i !== iFinal; i += inc) {\n                    subplotId = subplotsOut[row][i];\n                    if(!subplotId) continue;\n                    yPos = subplotId.indexOf('y');\n                    if(subplotId.slice(yPos) === axisId) {\n                        anchors[axisId] = subplotId.slice(0, yPos);\n                        break;\n                    }\n                }\n            } else {\n                for(i = i0; i !== iFinal; i += inc) {\n                    xId = gridOut.xaxes[i];\n                    if(subplots.cartesian.indexOf(xId + axisId) !== -1) {\n                        anchors[axisId] = xId;\n                        break;\n                    }\n                }\n            }\n        }\n    }\n}\n\nfunction fillGridAxes(axesIn, axesAllowed, len, axisMap, axLetter) {\n    var out = new Array(len);\n    var i;\n\n    function fillOneAxis(i, axisId) {\n        if(axesAllowed.indexOf(axisId) !== -1 && axisMap[axisId] === undefined) {\n            out[i] = axisId;\n            axisMap[axisId] = i;\n        } else out[i] = '';\n    }\n\n    if(Array.isArray(axesIn)) {\n        for(i = 0; i < len; i++) {\n            fillOneAxis(i, axesIn[i]);\n        }\n    } else {\n        // default axis list is the first `len` axis ids\n        fillOneAxis(0, axLetter);\n        for(i = 1; i < len; i++) {\n            fillOneAxis(i, axLetter + (i + 1));\n        }\n    }\n\n    return out;\n}\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'grid',\n\n    schema: {\n        layout: {grid: gridAttrs}\n    },\n\n    layoutAttributes: gridAttrs,\n    sizeDefaults: sizeDefaults,\n    contentDefaults: contentDefaults\n};\n\n},{\"../../lib\":719,\"../../lib/regex\":735,\"../../plot_api/plot_template\":757,\"../../plots/cartesian/constants\":773,\"../../plots/domain\":792}],637:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar cartesianConstants = _dereq_('../../plots/cartesian/constants');\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\n\nmodule.exports = templatedArray('image', {\n    visible: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'arraydraw',\n        \n    },\n\n    source: {\n        valType: 'string',\n        \n        editType: 'arraydraw',\n        \n    },\n\n    layer: {\n        valType: 'enumerated',\n        values: ['below', 'above'],\n        dflt: 'above',\n        \n        editType: 'arraydraw',\n        \n    },\n\n    sizex: {\n        valType: 'number',\n        \n        dflt: 0,\n        editType: 'arraydraw',\n        \n    },\n\n    sizey: {\n        valType: 'number',\n        \n        dflt: 0,\n        editType: 'arraydraw',\n        \n    },\n\n    sizing: {\n        valType: 'enumerated',\n        values: ['fill', 'contain', 'stretch'],\n        dflt: 'contain',\n        \n        editType: 'arraydraw',\n        \n    },\n\n    opacity: {\n        valType: 'number',\n        \n        min: 0,\n        max: 1,\n        dflt: 1,\n        editType: 'arraydraw',\n        \n    },\n\n    x: {\n        valType: 'any',\n        \n        dflt: 0,\n        editType: 'arraydraw',\n        \n    },\n\n    y: {\n        valType: 'any',\n        \n        dflt: 0,\n        editType: 'arraydraw',\n        \n    },\n\n    xanchor: {\n        valType: 'enumerated',\n        values: ['left', 'center', 'right'],\n        dflt: 'left',\n        \n        editType: 'arraydraw',\n        \n    },\n\n    yanchor: {\n        valType: 'enumerated',\n        values: ['top', 'middle', 'bottom'],\n        dflt: 'top',\n        \n        editType: 'arraydraw',\n        \n    },\n\n    xref: {\n        valType: 'enumerated',\n        values: [\n            'paper',\n            cartesianConstants.idRegex.x.toString()\n        ],\n        dflt: 'paper',\n        \n        editType: 'arraydraw',\n        \n    },\n\n    yref: {\n        valType: 'enumerated',\n        values: [\n            'paper',\n            cartesianConstants.idRegex.y.toString()\n        ],\n        dflt: 'paper',\n        \n        editType: 'arraydraw',\n        \n    },\n    editType: 'arraydraw'\n});\n\n},{\"../../plot_api/plot_template\":757,\"../../plots/cartesian/constants\":773}],638:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar toLogRange = _dereq_('../../lib/to_log_range');\n\n/*\n * convertCoords: when converting an axis between log and linear\n * you need to alter any images on that axis to keep them\n * pointing at the same data point.\n * In v2.0 this will become obsolete (or perhaps size will still need conversion?)\n * we convert size by declaring that the maximum extent *in data units* should be\n * the same, assuming the image is anchored by its center (could remove that restriction\n * if we think it's important) even though the actual left and right values will not be\n * quite the same since the scale becomes nonlinear (and central anchor means the pixel\n * center of the image, not the data units center)\n *\n * gd: the plot div\n * ax: the axis being changed\n * newType: the type it's getting\n * doExtra: function(attr, val) from inside relayout that sets the attribute.\n *     Use this to make the changes as it's aware if any other changes in the\n *     same relayout call should override this conversion.\n */\nmodule.exports = function convertCoords(gd, ax, newType, doExtra) {\n    ax = ax || {};\n\n    var toLog = (newType === 'log') && (ax.type === 'linear');\n    var fromLog = (newType === 'linear') && (ax.type === 'log');\n\n    if(!(toLog || fromLog)) return;\n\n    var images = gd._fullLayout.images;\n    var axLetter = ax._id.charAt(0);\n    var image;\n    var attrPrefix;\n\n    for(var i = 0; i < images.length; i++) {\n        image = images[i];\n        attrPrefix = 'images[' + i + '].';\n\n        if(image[axLetter + 'ref'] === ax._id) {\n            var currentPos = image[axLetter];\n            var currentSize = image['size' + axLetter];\n            var newPos = null;\n            var newSize = null;\n\n            if(toLog) {\n                newPos = toLogRange(currentPos, ax.range);\n\n                // this is the inverse of the conversion we do in fromLog below\n                // so that the conversion is reversible (notice the fromLog conversion\n                // is like sinh, and this one looks like arcsinh)\n                var dx = currentSize / Math.pow(10, newPos) / 2;\n                newSize = 2 * Math.log(dx + Math.sqrt(1 + dx * dx)) / Math.LN10;\n            } else {\n                newPos = Math.pow(10, currentPos);\n                newSize = newPos * (Math.pow(10, currentSize / 2) - Math.pow(10, -currentSize / 2));\n            }\n\n            // if conversion failed, delete the value so it can get a default later on\n            if(!isNumeric(newPos)) {\n                newPos = null;\n                newSize = null;\n            } else if(!isNumeric(newSize)) newSize = null;\n\n            doExtra(attrPrefix + axLetter, newPos);\n            doExtra(attrPrefix + 'size' + axLetter, newSize);\n        }\n    }\n};\n\n},{\"../../lib/to_log_range\":745,\"fast-isnumeric\":225}],639:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nvar attributes = _dereq_('./attributes');\nvar name = 'images';\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {\n    var opts = {\n        name: name,\n        handleItemDefaults: imageDefaults\n    };\n\n    handleArrayContainerDefaults(layoutIn, layoutOut, opts);\n};\n\n\nfunction imageDefaults(imageIn, imageOut, fullLayout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(imageIn, imageOut, attributes, attr, dflt);\n    }\n\n    var source = coerce('source');\n    var visible = coerce('visible', !!source);\n\n    if(!visible) return imageOut;\n\n    coerce('layer');\n    coerce('xanchor');\n    coerce('yanchor');\n    coerce('sizex');\n    coerce('sizey');\n    coerce('sizing');\n    coerce('opacity');\n\n    var gdMock = { _fullLayout: fullLayout };\n    var axLetters = ['x', 'y'];\n\n    for(var i = 0; i < 2; i++) {\n        // 'paper' is the fallback axref\n        var axLetter = axLetters[i];\n        var axRef = Axes.coerceRef(imageIn, imageOut, gdMock, axLetter, 'paper');\n\n        if(axRef !== 'paper') {\n            var ax = Axes.getFromId(gdMock, axRef);\n            ax._imgIndices.push(imageOut._index);\n        }\n\n        Axes.coercePosition(imageOut, gdMock, coerce, axRef, axLetter, 0);\n    }\n\n    return imageOut;\n}\n\n},{\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"../../plots/cartesian/axes\":767,\"./attributes\":637}],640:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Drawing = _dereq_('../drawing');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');\n\nmodule.exports = function draw(gd) {\n    var fullLayout = gd._fullLayout;\n    var imageDataAbove = [];\n    var imageDataSubplot = {};\n    var imageDataBelow = [];\n    var subplot;\n    var i;\n\n    // Sort into top, subplot, and bottom layers\n    for(i = 0; i < fullLayout.images.length; i++) {\n        var img = fullLayout.images[i];\n\n        if(img.visible) {\n            if(img.layer === 'below' && img.xref !== 'paper' && img.yref !== 'paper') {\n                subplot = img.xref + img.yref;\n\n                var plotinfo = fullLayout._plots[subplot];\n\n                if(!plotinfo) {\n                    // Fall back to _imageLowerLayer in case the requested subplot doesn't exist.\n                    // This can happen if you reference the image to an x / y axis combination\n                    // that doesn't have any data on it (and layer is below)\n                    imageDataBelow.push(img);\n                    continue;\n                }\n\n                if(plotinfo.mainplot) {\n                    subplot = plotinfo.mainplot.id;\n                }\n\n                if(!imageDataSubplot[subplot]) {\n                    imageDataSubplot[subplot] = [];\n                }\n                imageDataSubplot[subplot].push(img);\n            } else if(img.layer === 'above') {\n                imageDataAbove.push(img);\n            } else {\n                imageDataBelow.push(img);\n            }\n        }\n    }\n\n\n    var anchors = {\n        x: {\n            left: { sizing: 'xMin', offset: 0 },\n            center: { sizing: 'xMid', offset: -1 / 2 },\n            right: { sizing: 'xMax', offset: -1 }\n        },\n        y: {\n            top: { sizing: 'YMin', offset: 0 },\n            middle: { sizing: 'YMid', offset: -1 / 2 },\n            bottom: { sizing: 'YMax', offset: -1 }\n        }\n    };\n\n\n    // Images must be converted to dataURL's for exporting.\n    function setImage(d) {\n        var thisImage = d3.select(this);\n\n        if(this.img && this.img.src === d.source) {\n            return;\n        }\n\n        thisImage.attr('xmlns', xmlnsNamespaces.svg);\n\n        var imagePromise = new Promise(function(resolve) {\n            var img = new Image();\n            this.img = img;\n\n            // If not set, a `tainted canvas` error is thrown\n            img.setAttribute('crossOrigin', 'anonymous');\n            img.onerror = errorHandler;\n            img.onload = function() {\n                var canvas = document.createElement('canvas');\n                canvas.width = this.width;\n                canvas.height = this.height;\n\n                var ctx = canvas.getContext('2d');\n                ctx.drawImage(this, 0, 0);\n\n                var dataURL = canvas.toDataURL('image/png');\n\n                thisImage.attr('xlink:href', dataURL);\n\n                // resolve promise in onload handler instead of on 'load' to support IE11\n                // see https://github.com/plotly/plotly.js/issues/1685\n                // for more details\n                resolve();\n            };\n\n\n            thisImage.on('error', errorHandler);\n\n            img.src = d.source;\n\n            function errorHandler() {\n                thisImage.remove();\n                resolve();\n            }\n        }.bind(this));\n\n        gd._promises.push(imagePromise);\n    }\n\n    function applyAttributes(d) {\n        var thisImage = d3.select(this);\n\n        // Axes if specified\n        var xa = Axes.getFromId(gd, d.xref);\n        var ya = Axes.getFromId(gd, d.yref);\n\n        var size = fullLayout._size;\n        var width = xa ? Math.abs(xa.l2p(d.sizex) - xa.l2p(0)) : d.sizex * size.w;\n        var height = ya ? Math.abs(ya.l2p(d.sizey) - ya.l2p(0)) : d.sizey * size.h;\n\n        // Offsets for anchor positioning\n        var xOffset = width * anchors.x[d.xanchor].offset;\n        var yOffset = height * anchors.y[d.yanchor].offset;\n\n        var sizing = anchors.x[d.xanchor].sizing + anchors.y[d.yanchor].sizing;\n\n        // Final positions\n        var xPos = (xa ? xa.r2p(d.x) + xa._offset : d.x * size.w + size.l) + xOffset;\n        var yPos = (ya ? ya.r2p(d.y) + ya._offset : size.h - d.y * size.h + size.t) + yOffset;\n\n        // Construct the proper aspectRatio attribute\n        switch(d.sizing) {\n            case 'fill':\n                sizing += ' slice';\n                break;\n\n            case 'stretch':\n                sizing = 'none';\n                break;\n        }\n\n        thisImage.attr({\n            x: xPos,\n            y: yPos,\n            width: width,\n            height: height,\n            preserveAspectRatio: sizing,\n            opacity: d.opacity\n        });\n\n\n        // Set proper clipping on images\n        var xId = xa ? xa._id : '';\n        var yId = ya ? ya._id : '';\n        var clipAxes = xId + yId;\n\n        Drawing.setClipUrl(\n            thisImage,\n            clipAxes ? ('clip' + fullLayout._uid + clipAxes) : null,\n            gd\n        );\n    }\n\n    var imagesBelow = fullLayout._imageLowerLayer.selectAll('image')\n        .data(imageDataBelow);\n    var imagesAbove = fullLayout._imageUpperLayer.selectAll('image')\n        .data(imageDataAbove);\n\n    imagesBelow.enter().append('image');\n    imagesAbove.enter().append('image');\n\n    imagesBelow.exit().remove();\n    imagesAbove.exit().remove();\n\n    imagesBelow.each(function(d) {\n        setImage.bind(this)(d);\n        applyAttributes.bind(this)(d);\n    });\n    imagesAbove.each(function(d) {\n        setImage.bind(this)(d);\n        applyAttributes.bind(this)(d);\n    });\n\n    var allSubplots = Object.keys(fullLayout._plots);\n    for(i = 0; i < allSubplots.length; i++) {\n        subplot = allSubplots[i];\n        var subplotObj = fullLayout._plots[subplot];\n\n        // filter out overlaid plots (which havd their images on the main plot)\n        // and gl2d plots (which don't support below images, at least not yet)\n        if(!subplotObj.imagelayer) continue;\n\n        var imagesOnSubplot = subplotObj.imagelayer.selectAll('image')\n            // even if there are no images on this subplot, we need to run\n            // enter and exit in case there were previously\n            .data(imageDataSubplot[subplot] || []);\n\n        imagesOnSubplot.enter().append('image');\n        imagesOnSubplot.exit().remove();\n\n        imagesOnSubplot.each(function(d) {\n            setImage.bind(this)(d);\n            applyAttributes.bind(this)(d);\n        });\n    }\n};\n\n},{\"../../constants/xmlns_namespaces\":696,\"../../plots/cartesian/axes\":767,\"../drawing\":614,\"d3\":163}],641:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'images',\n\n    layoutAttributes: _dereq_('./attributes'),\n    supplyLayoutDefaults: _dereq_('./defaults'),\n    includeBasePlot: _dereq_('../../plots/cartesian/include_components')('images'),\n\n    draw: _dereq_('./draw'),\n\n    convertCoords: _dereq_('./convert_coords')\n};\n\n},{\"../../plots/cartesian/include_components\":777,\"./attributes\":637,\"./convert_coords\":638,\"./defaults\":639,\"./draw\":640}],642:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar colorAttrs = _dereq_('../color/attributes');\n\n\nmodule.exports = {\n    bgcolor: {\n        valType: 'color',\n        \n        editType: 'legend',\n        \n    },\n    bordercolor: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'legend',\n        \n    },\n    borderwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'legend',\n        \n    },\n    font: fontAttrs({\n        editType: 'legend',\n        \n    }),\n    orientation: {\n        valType: 'enumerated',\n        values: ['v', 'h'],\n        dflt: 'v',\n        \n        editType: 'legend',\n        \n    },\n    traceorder: {\n        valType: 'flaglist',\n        flags: ['reversed', 'grouped'],\n        extras: ['normal'],\n        \n        editType: 'legend',\n        \n    },\n    tracegroupgap: {\n        valType: 'number',\n        min: 0,\n        dflt: 10,\n        \n        editType: 'legend',\n        \n    },\n    itemsizing: {\n        valType: 'enumerated',\n        values: ['trace', 'constant'],\n        dflt: 'trace',\n        \n        editType: 'legend',\n        \n    },\n\n    itemclick: {\n        valType: 'enumerated',\n        values: ['toggle', 'toggleothers', false],\n        dflt: 'toggle',\n        \n        editType: 'legend',\n        \n    },\n    itemdoubleclick: {\n        valType: 'enumerated',\n        values: ['toggle', 'toggleothers', false],\n        dflt: 'toggleothers',\n        \n        editType: 'legend',\n        \n    },\n\n    x: {\n        valType: 'number',\n        min: -2,\n        max: 3,\n        dflt: 1.02,\n        \n        editType: 'legend',\n        \n    },\n    xanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'left', 'center', 'right'],\n        dflt: 'left',\n        \n        editType: 'legend',\n        \n    },\n    y: {\n        valType: 'number',\n        min: -2,\n        max: 3,\n        dflt: 1,\n        \n        editType: 'legend',\n        \n    },\n    yanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'top', 'middle', 'bottom'],\n        dflt: 'auto',\n        \n        editType: 'legend',\n        \n    },\n    uirevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n    valign: {\n        valType: 'enumerated',\n        values: ['top', 'middle', 'bottom'],\n        dflt: 'middle',\n        \n        editType: 'legend',\n        \n    },\n    editType: 'legend'\n};\n\n},{\"../../plots/font_attributes\":793,\"../color/attributes\":592}],643:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    scrollBarWidth: 6,\n    scrollBarMinHeight: 20,\n    scrollBarColor: '#808BA4',\n    scrollBarMargin: 4,\n    textOffsetX: 40\n};\n\n},{}],644:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Template = _dereq_('../../plot_api/plot_template');\n\nvar attributes = _dereq_('./attributes');\nvar basePlotLayoutAttributes = _dereq_('../../plots/layout_attributes');\nvar helpers = _dereq_('./helpers');\n\n\nmodule.exports = function legendDefaults(layoutIn, layoutOut, fullData) {\n    var containerIn = layoutIn.legend || {};\n\n    var legendTraceCount = 0;\n    var legendReallyHasATrace = false;\n    var defaultOrder = 'normal';\n\n    var defaultX, defaultY, defaultXAnchor, defaultYAnchor;\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n\n        if(!trace.visible) continue;\n\n        // Note that we explicitly count any trace that is either shown or\n        // *would* be shown by default, toward the two traces you need to\n        // ensure the legend is shown by default, because this can still help\n        // disambiguate.\n        if(trace.showlegend || trace._dfltShowLegend) {\n            legendTraceCount++;\n            if(trace.showlegend) {\n                legendReallyHasATrace = true;\n                // Always show the legend by default if there's a pie,\n                // or if there's only one trace but it's explicitly shown\n                if(Registry.traceIs(trace, 'pie-like') ||\n                    trace._input.showlegend === true\n                ) {\n                    legendTraceCount++;\n                }\n            }\n        }\n\n        if((Registry.traceIs(trace, 'bar') && layoutOut.barmode === 'stack') ||\n                ['tonextx', 'tonexty'].indexOf(trace.fill) !== -1) {\n            defaultOrder = helpers.isGrouped({traceorder: defaultOrder}) ?\n                'grouped+reversed' : 'reversed';\n        }\n\n        if(trace.legendgroup !== undefined && trace.legendgroup !== '') {\n            defaultOrder = helpers.isReversed({traceorder: defaultOrder}) ?\n                'reversed+grouped' : 'grouped';\n        }\n    }\n\n    var showLegend = Lib.coerce(layoutIn, layoutOut,\n        basePlotLayoutAttributes, 'showlegend',\n        legendReallyHasATrace && legendTraceCount > 1);\n\n    if(showLegend === false && !containerIn.uirevision) return;\n\n    var containerOut = Template.newContainer(layoutOut, 'legend');\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);\n    }\n\n    coerce('uirevision', layoutOut.uirevision);\n\n    if(showLegend === false) return;\n\n    coerce('bgcolor', layoutOut.paper_bgcolor);\n    coerce('bordercolor');\n    coerce('borderwidth');\n    Lib.coerceFont(coerce, 'font', layoutOut.font);\n\n    coerce('orientation');\n    if(containerOut.orientation === 'h') {\n        var xaxis = layoutIn.xaxis;\n        if(Registry.getComponentMethod('rangeslider', 'isVisible')(xaxis)) {\n            defaultX = 0;\n            defaultXAnchor = 'left';\n            defaultY = 1.1;\n            defaultYAnchor = 'bottom';\n        } else {\n            defaultX = 0;\n            defaultXAnchor = 'left';\n            defaultY = -0.1;\n            defaultYAnchor = 'top';\n        }\n    }\n\n    coerce('traceorder', defaultOrder);\n    if(helpers.isGrouped(layoutOut.legend)) coerce('tracegroupgap');\n\n    coerce('itemsizing');\n\n    coerce('itemclick');\n    coerce('itemdoubleclick');\n\n    coerce('x', defaultX);\n    coerce('xanchor', defaultXAnchor);\n    coerce('y', defaultY);\n    coerce('yanchor', defaultYAnchor);\n    coerce('valign');\n    Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);\n};\n\n},{\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../plots/layout_attributes\":819,\"../../registry\":847,\"./attributes\":642,\"./helpers\":648}],645:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../../lib');\nvar Plots = _dereq_('../../plots/plots');\nvar Registry = _dereq_('../../registry');\nvar Events = _dereq_('../../lib/events');\nvar dragElement = _dereq_('../dragelement');\nvar Drawing = _dereq_('../drawing');\nvar Color = _dereq_('../color');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar handleClick = _dereq_('./handle_click');\n\nvar constants = _dereq_('./constants');\nvar alignmentConstants = _dereq_('../../constants/alignment');\nvar LINE_SPACING = alignmentConstants.LINE_SPACING;\nvar FROM_TL = alignmentConstants.FROM_TL;\nvar FROM_BR = alignmentConstants.FROM_BR;\n\nvar getLegendData = _dereq_('./get_legend_data');\nvar style = _dereq_('./style');\nvar helpers = _dereq_('./helpers');\n\nmodule.exports = function draw(gd) {\n    var fullLayout = gd._fullLayout;\n    var clipId = 'legend' + fullLayout._uid;\n\n    if(!fullLayout._infolayer || !gd.calcdata) return;\n\n    if(!gd._legendMouseDownTime) gd._legendMouseDownTime = 0;\n\n    var opts = fullLayout.legend;\n    var legendData = fullLayout.showlegend && getLegendData(gd.calcdata, opts);\n    var hiddenSlices = fullLayout.hiddenlabels || [];\n\n    if(!fullLayout.showlegend || !legendData.length) {\n        fullLayout._infolayer.selectAll('.legend').remove();\n        fullLayout._topdefs.select('#' + clipId).remove();\n\n        Plots.autoMargin(gd, 'legend');\n        return;\n    }\n\n    var maxLength = 0;\n    for(var i = 0; i < legendData.length; i++) {\n        for(var j = 0; j < legendData[i].length; j++) {\n            var item = legendData[i][j][0];\n            var trace = item.trace;\n            var isPieLike = Registry.traceIs(trace, 'pie-like');\n            var name = isPieLike ? item.label : trace.name;\n            maxLength = Math.max(maxLength, name && name.length || 0);\n        }\n    }\n\n    var firstRender = false;\n    var legend = Lib.ensureSingle(fullLayout._infolayer, 'g', 'legend', function(s) {\n        s.attr('pointer-events', 'all');\n        firstRender = true;\n    });\n\n    var clipPath = Lib.ensureSingleById(fullLayout._topdefs, 'clipPath', clipId, function(s) {\n        s.append('rect');\n    });\n\n    var bg = Lib.ensureSingle(legend, 'rect', 'bg', function(s) {\n        s.attr('shape-rendering', 'crispEdges');\n    });\n\n    bg.call(Color.stroke, opts.bordercolor)\n        .call(Color.fill, opts.bgcolor)\n        .style('stroke-width', opts.borderwidth + 'px');\n\n    var scrollBox = Lib.ensureSingle(legend, 'g', 'scrollbox');\n\n    var scrollBar = Lib.ensureSingle(legend, 'rect', 'scrollbar', function(s) {\n        s.attr({\n            rx: 20,\n            ry: 3,\n            width: 0,\n            height: 0\n        })\n        .call(Color.fill, '#808BA4');\n    });\n\n    var groups = scrollBox.selectAll('g.groups')\n        .data(legendData);\n\n    groups.enter().append('g')\n        .attr('class', 'groups');\n\n    groups.exit().remove();\n\n    var traces = groups.selectAll('g.traces')\n        .data(Lib.identity);\n\n    traces.enter().append('g').attr('class', 'traces');\n    traces.exit().remove();\n\n    traces.style('opacity', function(d) {\n        var trace = d[0].trace;\n        if(Registry.traceIs(trace, 'pie-like')) {\n            return hiddenSlices.indexOf(d[0].label) !== -1 ? 0.5 : 1;\n        } else {\n            return trace.visible === 'legendonly' ? 0.5 : 1;\n        }\n    })\n    .each(function() {\n        d3.select(this)\n            .call(drawTexts, gd, maxLength);\n    })\n    .call(style, gd)\n    .each(function() {\n        d3.select(this)\n            .call(setupTraceToggle, gd);\n    });\n\n    Lib.syncOrAsync([Plots.previousPromises,\n        function() {\n            if(firstRender) {\n                computeLegendDimensions(gd, groups, traces);\n                expandMargin(gd);\n            }\n\n            // Position and size the legend\n            var lxMin = 0;\n            var lxMax = fullLayout.width;\n            var lyMin = 0;\n            var lyMax = fullLayout.height;\n\n            computeLegendDimensions(gd, groups, traces);\n\n            if(opts._height > lyMax) {\n                // If the legend doesn't fit in the plot area,\n                // do not expand the vertical margins.\n                expandHorizontalMargin(gd);\n            } else {\n                expandMargin(gd);\n            }\n\n            // Scroll section must be executed after repositionLegend.\n            // It requires the legend width, height, x and y to position the scrollbox\n            // and these values are mutated in repositionLegend.\n            var gs = fullLayout._size;\n            var lx = gs.l + gs.w * opts.x;\n            var ly = gs.t + gs.h * (1 - opts.y);\n\n            if(Lib.isRightAnchor(opts)) {\n                lx -= opts._width;\n            } else if(Lib.isCenterAnchor(opts)) {\n                lx -= opts._width / 2;\n            }\n\n            if(Lib.isBottomAnchor(opts)) {\n                ly -= opts._height;\n            } else if(Lib.isMiddleAnchor(opts)) {\n                ly -= opts._height / 2;\n            }\n\n            // Make sure the legend left and right sides are visible\n            var legendWidth = opts._width;\n            var legendWidthMax = gs.w;\n\n            if(legendWidth > legendWidthMax) {\n                lx = gs.l;\n                legendWidth = legendWidthMax;\n            } else {\n                if(lx + legendWidth > lxMax) lx = lxMax - legendWidth;\n                if(lx < lxMin) lx = lxMin;\n                legendWidth = Math.min(lxMax - lx, opts._width);\n            }\n\n            // Make sure the legend top and bottom are visible\n            // (legends with a scroll bar are not allowed to stretch beyond the extended\n            // margins)\n            var legendHeight = opts._height;\n            var legendHeightMax = gs.h;\n\n            if(legendHeight > legendHeightMax) {\n                ly = gs.t;\n                legendHeight = legendHeightMax;\n            } else {\n                if(ly + legendHeight > lyMax) ly = lyMax - legendHeight;\n                if(ly < lyMin) ly = lyMin;\n                legendHeight = Math.min(lyMax - ly, opts._height);\n            }\n\n            // Set size and position of all the elements that make up a legend:\n            // legend, background and border, scroll box and scroll bar\n            Drawing.setTranslate(legend, lx, ly);\n\n            // to be safe, remove previous listeners\n            scrollBar.on('.drag', null);\n            legend.on('wheel', null);\n\n            if(opts._height <= legendHeight || gd._context.staticPlot) {\n                // if scrollbar should not be shown.\n                bg.attr({\n                    width: legendWidth - opts.borderwidth,\n                    height: legendHeight - opts.borderwidth,\n                    x: opts.borderwidth / 2,\n                    y: opts.borderwidth / 2\n                });\n\n                Drawing.setTranslate(scrollBox, 0, 0);\n\n                clipPath.select('rect').attr({\n                    width: legendWidth - 2 * opts.borderwidth,\n                    height: legendHeight - 2 * opts.borderwidth,\n                    x: opts.borderwidth,\n                    y: opts.borderwidth\n                });\n\n                Drawing.setClipUrl(scrollBox, clipId, gd);\n\n                Drawing.setRect(scrollBar, 0, 0, 0, 0);\n                delete opts._scrollY;\n            } else {\n                var scrollBarHeight = Math.max(constants.scrollBarMinHeight,\n                    legendHeight * legendHeight / opts._height);\n                var scrollBarYMax = legendHeight -\n                    scrollBarHeight -\n                    2 * constants.scrollBarMargin;\n                var scrollBoxYMax = opts._height - legendHeight;\n                var scrollRatio = scrollBarYMax / scrollBoxYMax;\n\n                var scrollBoxY = Math.min(opts._scrollY || 0, scrollBoxYMax);\n\n                // increase the background and clip-path width\n                // by the scrollbar width and margin\n                bg.attr({\n                    width: legendWidth -\n                        2 * opts.borderwidth +\n                        constants.scrollBarWidth +\n                        constants.scrollBarMargin,\n                    height: legendHeight - opts.borderwidth,\n                    x: opts.borderwidth / 2,\n                    y: opts.borderwidth / 2\n                });\n\n                clipPath.select('rect').attr({\n                    width: legendWidth -\n                        2 * opts.borderwidth +\n                        constants.scrollBarWidth +\n                        constants.scrollBarMargin,\n                    height: legendHeight - 2 * opts.borderwidth,\n                    x: opts.borderwidth,\n                    y: opts.borderwidth + scrollBoxY\n                });\n\n                Drawing.setClipUrl(scrollBox, clipId, gd);\n\n                scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);\n\n                legend.on('wheel', function() {\n                    scrollBoxY = Lib.constrain(\n                        opts._scrollY +\n                            d3.event.deltaY / scrollBarYMax * scrollBoxYMax,\n                        0, scrollBoxYMax);\n                    scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);\n                    if(scrollBoxY !== 0 && scrollBoxY !== scrollBoxYMax) {\n                        d3.event.preventDefault();\n                    }\n                });\n\n                var eventY0, scrollBoxY0;\n\n                var drag = d3.behavior.drag()\n                .on('dragstart', function() {\n                    eventY0 = d3.event.sourceEvent.clientY;\n                    scrollBoxY0 = scrollBoxY;\n                })\n                .on('drag', function() {\n                    var e = d3.event.sourceEvent;\n                    if(e.buttons === 2 || e.ctrlKey) return;\n\n                    scrollBoxY = Lib.constrain(\n                        (e.clientY - eventY0) / scrollRatio + scrollBoxY0,\n                        0, scrollBoxYMax);\n                    scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);\n                });\n\n                scrollBar.call(drag);\n            }\n\n\n            function scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio) {\n                opts._scrollY = gd._fullLayout.legend._scrollY = scrollBoxY;\n                Drawing.setTranslate(scrollBox, 0, -scrollBoxY);\n\n                Drawing.setRect(\n                    scrollBar,\n                    legendWidth,\n                    constants.scrollBarMargin + scrollBoxY * scrollRatio,\n                    constants.scrollBarWidth,\n                    scrollBarHeight\n                );\n                clipPath.select('rect').attr({\n                    y: opts.borderwidth + scrollBoxY\n                });\n            }\n\n            if(gd._context.edits.legendPosition) {\n                var xf, yf, x0, y0;\n\n                legend.classed('cursor-move', true);\n\n                dragElement.init({\n                    element: legend.node(),\n                    gd: gd,\n                    prepFn: function() {\n                        var transform = Drawing.getTranslate(legend);\n\n                        x0 = transform.x;\n                        y0 = transform.y;\n                    },\n                    moveFn: function(dx, dy) {\n                        var newX = x0 + dx;\n                        var newY = y0 + dy;\n\n                        Drawing.setTranslate(legend, newX, newY);\n\n                        xf = dragElement.align(newX, 0, gs.l, gs.l + gs.w, opts.xanchor);\n                        yf = dragElement.align(newY, 0, gs.t + gs.h, gs.t, opts.yanchor);\n                    },\n                    doneFn: function() {\n                        if(xf !== undefined && yf !== undefined) {\n                            Registry.call('_guiRelayout', gd, {'legend.x': xf, 'legend.y': yf});\n                        }\n                    },\n                    clickFn: function(numClicks, e) {\n                        var clickedTrace = fullLayout._infolayer.selectAll('g.traces').filter(function() {\n                            var bbox = this.getBoundingClientRect();\n                            return (\n                                e.clientX >= bbox.left && e.clientX <= bbox.right &&\n                                e.clientY >= bbox.top && e.clientY <= bbox.bottom\n                            );\n                        });\n                        if(clickedTrace.size() > 0) {\n                            clickOrDoubleClick(gd, legend, clickedTrace, numClicks, e);\n                        }\n                    }\n                });\n            }\n        }], gd);\n};\n\nfunction clickOrDoubleClick(gd, legend, legendItem, numClicks, evt) {\n    var trace = legendItem.data()[0][0].trace;\n    var evtData = {\n        event: evt,\n        node: legendItem.node(),\n        curveNumber: trace.index,\n        expandedIndex: trace._expandedIndex,\n        data: gd.data,\n        layout: gd.layout,\n        frames: gd._transitionData._frames,\n        config: gd._context,\n        fullData: gd._fullData,\n        fullLayout: gd._fullLayout\n    };\n\n    if(trace._group) {\n        evtData.group = trace._group;\n    }\n    if(Registry.traceIs(trace, 'pie-like')) {\n        evtData.label = legendItem.datum()[0].label;\n    }\n\n    var clickVal = Events.triggerHandler(gd, 'plotly_legendclick', evtData);\n    if(clickVal === false) return;\n\n    if(numClicks === 1) {\n        legend._clickTimeout = setTimeout(function() {\n            handleClick(legendItem, gd, numClicks);\n        }, gd._context.doubleClickDelay);\n    } else if(numClicks === 2) {\n        if(legend._clickTimeout) clearTimeout(legend._clickTimeout);\n        gd._legendMouseDownTime = 0;\n\n        var dblClickVal = Events.triggerHandler(gd, 'plotly_legenddoubleclick', evtData);\n        if(dblClickVal !== false) handleClick(legendItem, gd, numClicks);\n    }\n}\n\nfunction drawTexts(g, gd, maxLength) {\n    var legendItem = g.data()[0][0];\n    var fullLayout = gd._fullLayout;\n    var trace = legendItem.trace;\n    var isPieLike = Registry.traceIs(trace, 'pie-like');\n    var traceIndex = trace.index;\n    var isEditable = gd._context.edits.legendText && !isPieLike;\n\n    var name = isPieLike ? legendItem.label : trace.name;\n    if(trace._meta) {\n        name = Lib.templateString(name, trace._meta);\n    }\n\n    var textEl = Lib.ensureSingle(g, 'text', 'legendtext');\n\n    textEl.attr('text-anchor', 'start')\n        .classed('user-select-none', true)\n        .call(Drawing.font, fullLayout.legend.font)\n        .text(isEditable ? ensureLength(name, maxLength) : name);\n\n    svgTextUtils.positionText(textEl, constants.textOffsetX, 0);\n\n    function textLayout(s) {\n        svgTextUtils.convertToTspans(s, gd, function() {\n            computeTextDimensions(g, gd);\n        });\n    }\n\n    if(isEditable) {\n        textEl.call(svgTextUtils.makeEditable, {gd: gd, text: name})\n            .call(textLayout)\n            .on('edit', function(newName) {\n                this.text(ensureLength(newName, maxLength))\n                    .call(textLayout);\n\n                var fullInput = legendItem.trace._fullInput || {};\n                var update = {};\n\n                if(Registry.hasTransform(fullInput, 'groupby')) {\n                    var groupbyIndices = Registry.getTransformIndices(fullInput, 'groupby');\n                    var index = groupbyIndices[groupbyIndices.length - 1];\n\n                    var kcont = Lib.keyedContainer(fullInput, 'transforms[' + index + '].styles', 'target', 'value.name');\n\n                    kcont.set(legendItem.trace._group, newName);\n\n                    update = kcont.constructUpdate();\n                } else {\n                    update.name = newName;\n                }\n\n                return Registry.call('_guiRestyle', gd, update, traceIndex);\n            });\n    } else {\n        textLayout(textEl);\n    }\n}\n\n/*\n * Make sure we have a reasonably clickable region.\n * If this string is missing or very short, pad it with spaces out to at least\n * 4 characters, up to the max length of other labels, on the assumption that\n * most characters are wider than spaces so a string of spaces will usually be\n * no wider than the real labels.\n */\nfunction ensureLength(str, maxLength) {\n    var targetLength = Math.max(4, maxLength);\n    if(str && str.trim().length >= targetLength / 2) return str;\n    str = str || '';\n    for(var i = targetLength - str.length; i > 0; i--) str += ' ';\n    return str;\n}\n\nfunction setupTraceToggle(g, gd) {\n    var doubleClickDelay = gd._context.doubleClickDelay;\n    var newMouseDownTime;\n    var numClicks = 1;\n\n    var traceToggle = Lib.ensureSingle(g, 'rect', 'legendtoggle', function(s) {\n        s.style('cursor', 'pointer')\n            .attr('pointer-events', 'all')\n            .call(Color.fill, 'rgba(0,0,0,0)');\n    });\n\n    traceToggle.on('mousedown', function() {\n        newMouseDownTime = (new Date()).getTime();\n        if(newMouseDownTime - gd._legendMouseDownTime < doubleClickDelay) {\n            // in a click train\n            numClicks += 1;\n        } else {\n            // new click train\n            numClicks = 1;\n            gd._legendMouseDownTime = newMouseDownTime;\n        }\n    });\n    traceToggle.on('mouseup', function() {\n        if(gd._dragged || gd._editing) return;\n        var legend = gd._fullLayout.legend;\n\n        if((new Date()).getTime() - gd._legendMouseDownTime > doubleClickDelay) {\n            numClicks = Math.max(numClicks - 1, 1);\n        }\n\n        clickOrDoubleClick(gd, legend, g, numClicks, d3.event);\n    });\n}\n\nfunction computeTextDimensions(g, gd) {\n    var legendItem = g.data()[0][0];\n\n    if(!legendItem.trace.showlegend) {\n        g.remove();\n        return;\n    }\n\n    var mathjaxGroup = g.select('g[class*=math-group]');\n    var mathjaxNode = mathjaxGroup.node();\n    var opts = gd._fullLayout.legend;\n    var lineHeight = opts.font.size * LINE_SPACING;\n    var height, width;\n\n    if(mathjaxNode) {\n        var mathjaxBB = Drawing.bBox(mathjaxNode);\n\n        height = mathjaxBB.height;\n        width = mathjaxBB.width;\n\n        Drawing.setTranslate(mathjaxGroup, 0, (height / 4));\n    } else {\n        var text = g.select('.legendtext');\n        var textLines = svgTextUtils.lineCount(text);\n        var textNode = text.node();\n\n        height = lineHeight * textLines;\n        width = textNode ? Drawing.bBox(textNode).width : 0;\n\n        // approximation to height offset to center the font\n        // to avoid getBoundingClientRect\n        var textY = lineHeight * (0.3 + (1 - textLines) / 2);\n        svgTextUtils.positionText(text, constants.textOffsetX, textY);\n    }\n\n    legendItem.lineHeight = lineHeight;\n    legendItem.height = Math.max(height, 16) + 3;\n    legendItem.width = width;\n}\n\nfunction computeLegendDimensions(gd, groups, traces) {\n    var fullLayout = gd._fullLayout;\n    var opts = fullLayout.legend;\n    var borderwidth = opts.borderwidth;\n    var isGrouped = helpers.isGrouped(opts);\n\n    var extraWidth = 0;\n\n    var traceGap = 5;\n\n    opts._width = 0;\n    opts._height = 0;\n\n    if(helpers.isVertical(opts)) {\n        if(isGrouped) {\n            groups.each(function(d, i) {\n                Drawing.setTranslate(this, 0, i * opts.tracegroupgap);\n            });\n        }\n\n        traces.each(function(d) {\n            var legendItem = d[0];\n            var textHeight = legendItem.height;\n            var textWidth = legendItem.width;\n\n            Drawing.setTranslate(this,\n                borderwidth,\n                (5 + borderwidth + opts._height + textHeight / 2));\n\n            opts._height += textHeight;\n            opts._width = Math.max(opts._width, textWidth);\n        });\n\n        opts._width += 45 + borderwidth * 2;\n        opts._height += 10 + borderwidth * 2;\n\n        if(isGrouped) {\n            opts._height += (opts._lgroupsLength - 1) * opts.tracegroupgap;\n        }\n\n        extraWidth = 40;\n    } else if(isGrouped) {\n        var maxHeight = 0;\n        var maxWidth = 0;\n        var groupData = groups.data();\n\n        var maxItems = 0;\n\n        var i;\n        for(i = 0; i < groupData.length; i++) {\n            var group = groupData[i];\n            var groupWidths = group.map(function(legendItemArray) {\n                return legendItemArray[0].width;\n            });\n\n            var groupWidth = Lib.aggNums(Math.max, null, groupWidths);\n            var groupHeight = group.reduce(function(a, b) {\n                return a + b[0].height;\n            }, 0);\n\n            maxWidth = Math.max(maxWidth, groupWidth);\n            maxHeight = Math.max(maxHeight, groupHeight);\n            maxItems = Math.max(maxItems, group.length);\n        }\n\n        maxWidth += traceGap;\n        maxWidth += 40;\n\n        var groupXOffsets = [opts._width];\n        var groupYOffsets = [];\n        var rowNum = 0;\n        for(i = 0; i < groupData.length; i++) {\n            if(fullLayout._size.w < (borderwidth + opts._width + traceGap + maxWidth)) {\n                groupXOffsets[groupXOffsets.length - 1] = groupXOffsets[0];\n                opts._width = maxWidth;\n                rowNum++;\n            } else {\n                opts._width += maxWidth + borderwidth;\n            }\n\n            var rowYOffset = (rowNum * maxHeight);\n            rowYOffset += rowNum > 0 ? opts.tracegroupgap : 0;\n\n            groupYOffsets.push(rowYOffset);\n            groupXOffsets.push(opts._width);\n        }\n\n        groups.each(function(d, i) {\n            Drawing.setTranslate(this, groupXOffsets[i], groupYOffsets[i]);\n        });\n\n        groups.each(function() {\n            var group = d3.select(this);\n            var groupTraces = group.selectAll('g.traces');\n            var groupHeight = 0;\n\n            groupTraces.each(function(d) {\n                var legendItem = d[0];\n                var textHeight = legendItem.height;\n\n                Drawing.setTranslate(this,\n                    0,\n                    (5 + borderwidth + groupHeight + textHeight / 2));\n\n                groupHeight += textHeight;\n            });\n        });\n\n        var maxYLegend = groupYOffsets[groupYOffsets.length - 1] + maxHeight;\n        opts._height = 10 + (borderwidth * 2) + maxYLegend;\n\n        var maxOffset = Math.max.apply(null, groupXOffsets);\n        opts._width = maxOffset + maxWidth + 40;\n        opts._width += borderwidth * 2;\n    } else {\n        var rowHeight = 0;\n        var maxTraceHeight = 0;\n        var maxTraceWidth = 0;\n        var offsetX = 0;\n        var fullTracesWidth = 0;\n\n        // calculate largest width for traces and use for width of all legend items\n        traces.each(function(d) {\n            maxTraceWidth = Math.max(40 + d[0].width, maxTraceWidth);\n            fullTracesWidth += 40 + d[0].width + traceGap;\n        });\n\n        // check if legend fits in one row\n        var oneRowLegend = fullLayout._size.w > borderwidth + fullTracesWidth - traceGap;\n\n        traces.each(function(d) {\n            var legendItem = d[0];\n            var traceWidth = oneRowLegend ? 40 + d[0].width : maxTraceWidth;\n\n            if((borderwidth + offsetX + traceGap + traceWidth) > fullLayout._size.w) {\n                offsetX = 0;\n                rowHeight += maxTraceHeight;\n                opts._height += maxTraceHeight;\n                // reset for next row\n                maxTraceHeight = 0;\n            }\n\n            Drawing.setTranslate(this,\n                (borderwidth + offsetX),\n                (5 + borderwidth + legendItem.height / 2) + rowHeight);\n\n            opts._width += traceGap + traceWidth;\n\n            // keep track of tallest trace in group\n            offsetX += traceGap + traceWidth;\n            maxTraceHeight = Math.max(legendItem.height, maxTraceHeight);\n        });\n\n        if(oneRowLegend) {\n            opts._height = maxTraceHeight;\n        } else {\n            opts._height += maxTraceHeight;\n        }\n\n        opts._width += borderwidth * 2;\n        opts._height += 10 + borderwidth * 2;\n    }\n\n    // make sure we're only getting full pixels\n    opts._width = Math.ceil(opts._width);\n    opts._height = Math.ceil(opts._height);\n\n    var isEditable = (\n        gd._context.edits.legendText ||\n        gd._context.edits.legendPosition\n    );\n\n    traces.each(function(d) {\n        var legendItem = d[0];\n        var bg = d3.select(this).select('.legendtoggle');\n\n        Drawing.setRect(bg,\n            0,\n            -legendItem.height / 2,\n            (isEditable ? 0 : opts._width) + extraWidth,\n            legendItem.height\n        );\n    });\n}\n\nfunction expandMargin(gd) {\n    var fullLayout = gd._fullLayout;\n    var opts = fullLayout.legend;\n\n    var xanchor = 'left';\n    if(Lib.isRightAnchor(opts)) {\n        xanchor = 'right';\n    } else if(Lib.isCenterAnchor(opts)) {\n        xanchor = 'center';\n    }\n\n    var yanchor = 'top';\n    if(Lib.isBottomAnchor(opts)) {\n        yanchor = 'bottom';\n    } else if(Lib.isMiddleAnchor(opts)) {\n        yanchor = 'middle';\n    }\n\n    // lastly check if the margin auto-expand has changed\n    Plots.autoMargin(gd, 'legend', {\n        x: opts.x,\n        y: opts.y,\n        l: opts._width * (FROM_TL[xanchor]),\n        r: opts._width * (FROM_BR[xanchor]),\n        b: opts._height * (FROM_BR[yanchor]),\n        t: opts._height * (FROM_TL[yanchor])\n    });\n}\n\nfunction expandHorizontalMargin(gd) {\n    var fullLayout = gd._fullLayout;\n    var opts = fullLayout.legend;\n\n    var xanchor = 'left';\n    if(Lib.isRightAnchor(opts)) {\n        xanchor = 'right';\n    } else if(Lib.isCenterAnchor(opts)) {\n        xanchor = 'center';\n    }\n\n    // lastly check if the margin auto-expand has changed\n    Plots.autoMargin(gd, 'legend', {\n        x: opts.x,\n        y: 0.5,\n        l: opts._width * (FROM_TL[xanchor]),\n        r: opts._width * (FROM_BR[xanchor]),\n        b: 0,\n        t: 0\n    });\n}\n\n},{\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/events\":709,\"../../lib/svg_text_utils\":743,\"../../plots/plots\":828,\"../../registry\":847,\"../color\":593,\"../dragelement\":611,\"../drawing\":614,\"./constants\":643,\"./get_legend_data\":646,\"./handle_click\":647,\"./helpers\":648,\"./style\":650,\"d3\":163}],646:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar helpers = _dereq_('./helpers');\n\nmodule.exports = function getLegendData(calcdata, opts) {\n    var lgroupToTraces = {};\n    var lgroups = [];\n    var hasOneNonBlankGroup = false;\n    var slicesShown = {};\n    var lgroupi = 0;\n    var i, j;\n\n    function addOneItem(legendGroup, legendItem) {\n        // each '' legend group is treated as a separate group\n        if(legendGroup === '' || !helpers.isGrouped(opts)) {\n            var uniqueGroup = '~~i' + lgroupi; // TODO: check this against fullData legendgroups?\n\n            lgroups.push(uniqueGroup);\n            lgroupToTraces[uniqueGroup] = [[legendItem]];\n            lgroupi++;\n        } else if(lgroups.indexOf(legendGroup) === -1) {\n            lgroups.push(legendGroup);\n            hasOneNonBlankGroup = true;\n            lgroupToTraces[legendGroup] = [[legendItem]];\n        } else lgroupToTraces[legendGroup].push([legendItem]);\n    }\n\n    // build an { legendgroup: [cd0, cd0], ... } object\n    for(i = 0; i < calcdata.length; i++) {\n        var cd = calcdata[i];\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n        var lgroup = trace.legendgroup;\n\n        if(!trace.visible || !trace.showlegend) continue;\n\n        if(Registry.traceIs(trace, 'pie-like')) {\n            if(!slicesShown[lgroup]) slicesShown[lgroup] = {};\n\n            for(j = 0; j < cd.length; j++) {\n                var labelj = cd[j].label;\n\n                if(!slicesShown[lgroup][labelj]) {\n                    addOneItem(lgroup, {\n                        label: labelj,\n                        color: cd[j].color,\n                        i: cd[j].i,\n                        trace: trace,\n                        pts: cd[j].pts\n                    });\n\n                    slicesShown[lgroup][labelj] = true;\n                }\n            }\n        } else addOneItem(lgroup, cd0);\n    }\n\n    // won't draw a legend in this case\n    if(!lgroups.length) return [];\n\n    // rearrange lgroupToTraces into a d3-friendly array of arrays\n    var lgroupsLength = lgroups.length;\n    var ltraces;\n    var legendData;\n\n    if(hasOneNonBlankGroup && helpers.isGrouped(opts)) {\n        legendData = new Array(lgroupsLength);\n\n        for(i = 0; i < lgroupsLength; i++) {\n            ltraces = lgroupToTraces[lgroups[i]];\n            legendData[i] = helpers.isReversed(opts) ? ltraces.reverse() : ltraces;\n        }\n    } else {\n        // collapse all groups into one if all groups are blank\n        legendData = [new Array(lgroupsLength)];\n\n        for(i = 0; i < lgroupsLength; i++) {\n            ltraces = lgroupToTraces[lgroups[i]][0];\n            legendData[0][helpers.isReversed(opts) ? lgroupsLength - i - 1 : i] = ltraces;\n        }\n        lgroupsLength = 1;\n    }\n\n    // needed in repositionLegend\n    opts._lgroupsLength = lgroupsLength;\n    return legendData;\n};\n\n},{\"../../registry\":847,\"./helpers\":648}],647:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\n\nvar SHOWISOLATETIP = true;\n\nmodule.exports = function handleClick(g, gd, numClicks) {\n    var fullLayout = gd._fullLayout;\n\n    if(gd._dragged || gd._editing) return;\n\n    var itemClick = fullLayout.legend.itemclick;\n    var itemDoubleClick = fullLayout.legend.itemdoubleclick;\n\n    if(numClicks === 1 && itemClick === 'toggle' && itemDoubleClick === 'toggleothers' &&\n        SHOWISOLATETIP && gd.data && gd._context.showTips\n    ) {\n        Lib.notifier(Lib._(gd, 'Double-click on legend to isolate one trace'), 'long');\n        SHOWISOLATETIP = false;\n    } else {\n        SHOWISOLATETIP = false;\n    }\n\n    var mode;\n    if(numClicks === 1) mode = itemClick;\n    else if(numClicks === 2) mode = itemDoubleClick;\n    if(!mode) return;\n\n    var hiddenSlices = fullLayout.hiddenlabels ?\n        fullLayout.hiddenlabels.slice() :\n        [];\n\n    var legendItem = g.data()[0][0];\n    var fullData = gd._fullData;\n    var fullTrace = legendItem.trace;\n    var legendgroup = fullTrace.legendgroup;\n\n    var i, j, kcont, key, keys, val;\n    var attrUpdate = {};\n    var attrIndices = [];\n    var carrs = [];\n    var carrIdx = [];\n\n    function insertUpdate(traceIndex, key, value) {\n        var attrIndex = attrIndices.indexOf(traceIndex);\n        var valueArray = attrUpdate[key];\n        if(!valueArray) {\n            valueArray = attrUpdate[key] = [];\n        }\n\n        if(attrIndices.indexOf(traceIndex) === -1) {\n            attrIndices.push(traceIndex);\n            attrIndex = attrIndices.length - 1;\n        }\n\n        valueArray[attrIndex] = value;\n\n        return attrIndex;\n    }\n\n    function setVisibility(fullTrace, visibility) {\n        var fullInput = fullTrace._fullInput;\n        if(Registry.hasTransform(fullInput, 'groupby')) {\n            var kcont = carrs[fullInput.index];\n            if(!kcont) {\n                var groupbyIndices = Registry.getTransformIndices(fullInput, 'groupby');\n                var lastGroupbyIndex = groupbyIndices[groupbyIndices.length - 1];\n                kcont = Lib.keyedContainer(fullInput, 'transforms[' + lastGroupbyIndex + '].styles', 'target', 'value.visible');\n                carrs[fullInput.index] = kcont;\n            }\n\n            var curState = kcont.get(fullTrace._group);\n\n            // If not specified, assume visible. This happens if there are other style\n            // properties set for a group but not the visibility. There are many similar\n            // ways to do this (e.g. why not just `curState = fullTrace.visible`??? The\n            // answer is: because it breaks other things like groupby trace names in\n            // subtle ways.)\n            if(curState === undefined) {\n                curState = true;\n            }\n\n            if(curState !== false) {\n                // true -> legendonly. All others toggle to true:\n                kcont.set(fullTrace._group, visibility);\n            }\n            carrIdx[fullInput.index] = insertUpdate(fullInput.index, 'visible', fullInput.visible === false ? false : true);\n        } else {\n            // false -> false (not possible since will not be visible in legend)\n            // true -> legendonly\n            // legendonly -> true\n            var nextVisibility = fullInput.visible === false ? false : visibility;\n\n            insertUpdate(fullInput.index, 'visible', nextVisibility);\n        }\n    }\n\n    if(Registry.traceIs(fullTrace, 'pie-like')) {\n        var thisLabel = legendItem.label;\n        var thisLabelIndex = hiddenSlices.indexOf(thisLabel);\n\n        if(mode === 'toggle') {\n            if(thisLabelIndex === -1) hiddenSlices.push(thisLabel);\n            else hiddenSlices.splice(thisLabelIndex, 1);\n        } else if(mode === 'toggleothers') {\n            hiddenSlices = [];\n            gd.calcdata[0].forEach(function(d) {\n                if(thisLabel !== d.label) {\n                    hiddenSlices.push(d.label);\n                }\n            });\n            if(gd._fullLayout.hiddenlabels && gd._fullLayout.hiddenlabels.length === hiddenSlices.length && thisLabelIndex === -1) {\n                hiddenSlices = [];\n            }\n        }\n\n        Registry.call('_guiRelayout', gd, 'hiddenlabels', hiddenSlices);\n    } else {\n        var hasLegendgroup = legendgroup && legendgroup.length;\n        var traceIndicesInGroup = [];\n        var tracei;\n        if(hasLegendgroup) {\n            for(i = 0; i < fullData.length; i++) {\n                tracei = fullData[i];\n                if(!tracei.visible) continue;\n                if(tracei.legendgroup === legendgroup) {\n                    traceIndicesInGroup.push(i);\n                }\n            }\n        }\n\n        if(mode === 'toggle') {\n            var nextVisibility;\n\n            switch(fullTrace.visible) {\n                case true:\n                    nextVisibility = 'legendonly';\n                    break;\n                case false:\n                    nextVisibility = false;\n                    break;\n                case 'legendonly':\n                    nextVisibility = true;\n                    break;\n            }\n\n            if(hasLegendgroup) {\n                for(i = 0; i < fullData.length; i++) {\n                    if(fullData[i].visible !== false && fullData[i].legendgroup === legendgroup) {\n                        setVisibility(fullData[i], nextVisibility);\n                    }\n                }\n            } else {\n                setVisibility(fullTrace, nextVisibility);\n            }\n        } else if(mode === 'toggleothers') {\n            // Compute the clicked index. expandedIndex does what we want for expanded traces\n            // but also culls hidden traces. That means we have some work to do.\n            var isClicked, isInGroup, otherState;\n            var isIsolated = true;\n            for(i = 0; i < fullData.length; i++) {\n                isClicked = fullData[i] === fullTrace;\n                if(isClicked) continue;\n\n                isInGroup = (hasLegendgroup && fullData[i].legendgroup === legendgroup);\n\n                if(!isInGroup && fullData[i].visible === true && !Registry.traceIs(fullData[i], 'notLegendIsolatable')) {\n                    isIsolated = false;\n                    break;\n                }\n            }\n\n            for(i = 0; i < fullData.length; i++) {\n                // False is sticky; we don't change it.\n                if(fullData[i].visible === false) continue;\n\n                if(Registry.traceIs(fullData[i], 'notLegendIsolatable')) {\n                    continue;\n                }\n\n                switch(fullTrace.visible) {\n                    case 'legendonly':\n                        setVisibility(fullData[i], true);\n                        break;\n                    case true:\n                        otherState = isIsolated ? true : 'legendonly';\n                        isClicked = fullData[i] === fullTrace;\n                        isInGroup = isClicked || (hasLegendgroup && fullData[i].legendgroup === legendgroup);\n                        setVisibility(fullData[i], isInGroup ? true : otherState);\n                        break;\n                }\n            }\n        }\n\n        for(i = 0; i < carrs.length; i++) {\n            kcont = carrs[i];\n            if(!kcont) continue;\n            var update = kcont.constructUpdate();\n\n            var updateKeys = Object.keys(update);\n            for(j = 0; j < updateKeys.length; j++) {\n                key = updateKeys[j];\n                val = attrUpdate[key] = attrUpdate[key] || [];\n                val[carrIdx[i]] = update[key];\n            }\n        }\n\n        // The length of the value arrays should be equal and any unspecified\n        // values should be explicitly undefined for them to get properly culled\n        // as updates and not accidentally reset to the default value. This fills\n        // out sparse arrays with the required number of undefined values:\n        keys = Object.keys(attrUpdate);\n        for(i = 0; i < keys.length; i++) {\n            key = keys[i];\n            for(j = 0; j < attrIndices.length; j++) {\n                // Use hasOwnPropety to protect against falsey values:\n                if(!attrUpdate[key].hasOwnProperty(j)) {\n                    attrUpdate[key][j] = undefined;\n                }\n            }\n        }\n\n        Registry.call('_guiRestyle', gd, attrUpdate, attrIndices);\n    }\n};\n\n},{\"../../lib\":719,\"../../registry\":847}],648:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nexports.isGrouped = function isGrouped(legendLayout) {\n    return (legendLayout.traceorder || '').indexOf('grouped') !== -1;\n};\n\nexports.isVertical = function isVertical(legendLayout) {\n    return legendLayout.orientation !== 'h';\n};\n\nexports.isReversed = function isReversed(legendLayout) {\n    return (legendLayout.traceorder || '').indexOf('reversed') !== -1;\n};\n\n},{}],649:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'legend',\n\n    layoutAttributes: _dereq_('./attributes'),\n    supplyLayoutDefaults: _dereq_('./defaults'),\n\n    draw: _dereq_('./draw'),\n    style: _dereq_('./style')\n};\n\n},{\"./attributes\":642,\"./defaults\":644,\"./draw\":645,\"./style\":650}],650:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../drawing');\nvar Color = _dereq_('../color');\n\nvar subTypes = _dereq_('../../traces/scatter/subtypes');\nvar stylePie = _dereq_('../../traces/pie/style_one');\nvar pieCastOption = _dereq_('../../traces/pie/helpers').castOption;\n\nvar CST_MARKER_SIZE = 12;\nvar CST_LINE_WIDTH = 5;\nvar CST_MARKER_LINE_WIDTH = 2;\nvar MAX_LINE_WIDTH = 10;\nvar MAX_MARKER_LINE_WIDTH = 5;\n\nmodule.exports = function style(s, gd) {\n    var fullLayout = gd._fullLayout;\n    var legend = fullLayout.legend;\n    var constantItemSizing = legend.itemsizing === 'constant';\n\n    function boundLineWidth(mlw, cont, max, cst) {\n        var v;\n        if(mlw + 1) {\n            v = mlw;\n        } else if(cont && cont.width > 0) {\n            v = cont.width;\n        } else {\n            return 0;\n        }\n        return constantItemSizing ? cst : Math.min(v, max);\n    }\n\n    s.each(function(d) {\n        var traceGroup = d3.select(this);\n\n        var layers = Lib.ensureSingle(traceGroup, 'g', 'layers');\n        layers.style('opacity', d[0].trace.opacity);\n\n        var valign = legend.valign;\n        var lineHeight = d[0].lineHeight;\n        var height = d[0].height;\n\n        if(valign === 'middle' || !lineHeight || !height) {\n            layers.attr('transform', null);\n        } else {\n            var factor = {top: 1, bottom: -1}[valign];\n            var markerOffsetY = factor * (0.5 * (lineHeight - height + 3));\n            layers.attr('transform', 'translate(0,' + markerOffsetY + ')');\n        }\n\n        var fill = layers\n            .selectAll('g.legendfill')\n                .data([d]);\n        fill.enter().append('g')\n            .classed('legendfill', true);\n\n        var line = layers\n            .selectAll('g.legendlines')\n                .data([d]);\n        line.enter().append('g')\n            .classed('legendlines', true);\n\n        var symbol = layers\n            .selectAll('g.legendsymbols')\n                .data([d]);\n        symbol.enter().append('g')\n            .classed('legendsymbols', true);\n\n        symbol.selectAll('g.legendpoints')\n            .data([d])\n          .enter().append('g')\n            .classed('legendpoints', true);\n    })\n    .each(styleWaterfalls)\n    .each(styleFunnels)\n    .each(styleBars)\n    .each(styleBoxes)\n    .each(styleFunnelareas)\n    .each(stylePies)\n    .each(styleLines)\n    .each(stylePoints)\n    .each(styleCandles)\n    .each(styleOHLC);\n\n    function styleLines(d) {\n        var d0 = d[0];\n        var trace = d0.trace;\n        var showFill = trace.visible && trace.fill && trace.fill !== 'none';\n        var showLine = subTypes.hasLines(trace);\n        var contours = trace.contours;\n        var showGradientLine = false;\n        var showGradientFill = false;\n        var dMod, tMod;\n\n        if(contours) {\n            var coloring = contours.coloring;\n\n            if(coloring === 'lines') {\n                showGradientLine = true;\n            } else {\n                showLine = coloring === 'none' || coloring === 'heatmap' || contours.showlines;\n            }\n\n            if(contours.type === 'constraint') {\n                showFill = contours._operation !== '=';\n            } else if(coloring === 'fill' || coloring === 'heatmap') {\n                showGradientFill = true;\n            }\n        }\n\n        // with fill and no markers or text, move the line and fill up a bit\n        // so it's more centered\n        var markersOrText = subTypes.hasMarkers(trace) || subTypes.hasText(trace);\n        var anyFill = showFill || showGradientFill;\n        var anyLine = showLine || showGradientLine;\n        var pathStart = (markersOrText || !anyFill) ? 'M5,0' :\n            // with a line leave it slightly below center, to leave room for the\n            // line thickness and because the line is usually more prominent\n            anyLine ? 'M5,-2' : 'M5,-3';\n\n        var this3 = d3.select(this);\n\n        var fill = this3.select('.legendfill').selectAll('path')\n            .data(showFill || showGradientFill ? [d] : []);\n        fill.enter().append('path').classed('js-fill', true);\n        fill.exit().remove();\n        fill.attr('d', pathStart + 'h30v6h-30z')\n            .call(showFill ? Drawing.fillGroupStyle : fillGradient);\n\n        if(showLine || showGradientLine) {\n            var lw = boundLineWidth(undefined, trace.line, MAX_LINE_WIDTH, CST_LINE_WIDTH);\n            tMod = Lib.minExtend(trace, {line: {width: lw}});\n            dMod = [Lib.minExtend(d0, {trace: tMod})];\n        }\n\n        var line = this3.select('.legendlines').selectAll('path')\n            .data(showLine || showGradientLine ? [dMod] : []);\n        line.enter().append('path').classed('js-line', true);\n        line.exit().remove();\n\n        // this is ugly... but you can't apply a gradient to a perfectly\n        // horizontal or vertical line. Presumably because then\n        // the system doesn't know how to scale vertical variation, even\n        // though there *is* no vertical variation in this case.\n        // so add an invisibly small angle to the line\n        // This issue (and workaround) exist across (Mac) Chrome, FF, and Safari\n        line.attr('d', pathStart + (showGradientLine ? 'l30,0.0001' : 'h30'))\n            .call(showLine ? Drawing.lineGroupStyle : lineGradient);\n\n        function fillGradient(s) {\n            if(s.size()) {\n                var gradientID = 'legendfill-' + trace.uid;\n                Drawing.gradient(s, gd, gradientID, 'horizontalreversed',\n                    trace.colorscale, 'fill');\n            }\n        }\n\n        function lineGradient(s) {\n            if(s.size()) {\n                var gradientID = 'legendline-' + trace.uid;\n                Drawing.lineGroupStyle(s);\n                Drawing.gradient(s, gd, gradientID, 'horizontalreversed',\n                    trace.colorscale, 'stroke');\n            }\n        }\n    }\n\n    function stylePoints(d) {\n        var d0 = d[0];\n        var trace = d0.trace;\n        var showMarkers = subTypes.hasMarkers(trace);\n        var showText = subTypes.hasText(trace);\n        var showLines = subTypes.hasLines(trace);\n        var dMod, tMod;\n\n        // 'scatter3d' don't use gd.calcdata,\n        // use d0.trace to infer arrayOk attributes\n\n        function boundVal(attrIn, arrayToValFn, bounds, cst) {\n            var valIn = Lib.nestedProperty(trace, attrIn).get();\n            var valToBound = (Lib.isArrayOrTypedArray(valIn) && arrayToValFn) ?\n                arrayToValFn(valIn) :\n                valIn;\n\n            if(constantItemSizing && valToBound && cst !== undefined) {\n                valToBound = cst;\n            }\n\n            if(bounds) {\n                if(valToBound < bounds[0]) return bounds[0];\n                else if(valToBound > bounds[1]) return bounds[1];\n            }\n            return valToBound;\n        }\n\n        function pickFirst(array) { return array[0]; }\n\n        // constrain text, markers, etc so they'll fit on the legend\n        if(showMarkers || showText || showLines) {\n            var dEdit = {};\n            var tEdit = {};\n\n            if(showMarkers) {\n                dEdit.mc = boundVal('marker.color', pickFirst);\n                dEdit.mx = boundVal('marker.symbol', pickFirst);\n                dEdit.mo = boundVal('marker.opacity', Lib.mean, [0.2, 1]);\n                dEdit.mlc = boundVal('marker.line.color', pickFirst);\n                dEdit.mlw = boundVal('marker.line.width', Lib.mean, [0, 5], CST_MARKER_LINE_WIDTH);\n                tEdit.marker = {\n                    sizeref: 1,\n                    sizemin: 1,\n                    sizemode: 'diameter'\n                };\n\n                var ms = boundVal('marker.size', Lib.mean, [2, 16], CST_MARKER_SIZE);\n                dEdit.ms = ms;\n                tEdit.marker.size = ms;\n            }\n\n            if(showLines) {\n                tEdit.line = {\n                    width: boundVal('line.width', pickFirst, [0, 10], CST_LINE_WIDTH)\n                };\n            }\n\n            if(showText) {\n                dEdit.tx = 'Aa';\n                dEdit.tp = boundVal('textposition', pickFirst);\n                dEdit.ts = 10;\n                dEdit.tc = boundVal('textfont.color', pickFirst);\n                dEdit.tf = boundVal('textfont.family', pickFirst);\n            }\n\n            dMod = [Lib.minExtend(d0, dEdit)];\n            tMod = Lib.minExtend(trace, tEdit);\n\n            // always show legend items in base state\n            tMod.selectedpoints = null;\n        }\n\n        var ptgroup = d3.select(this).select('g.legendpoints');\n\n        var pts = ptgroup.selectAll('path.scatterpts')\n            .data(showMarkers ? dMod : []);\n        // make sure marker is on the bottom, in case it enters after text\n        pts.enter().insert('path', ':first-child')\n            .classed('scatterpts', true)\n            .attr('transform', 'translate(20,0)');\n        pts.exit().remove();\n        pts.call(Drawing.pointStyle, tMod, gd);\n\n        // 'mrc' is set in pointStyle and used in textPointStyle:\n        // constrain it here\n        if(showMarkers) dMod[0].mrc = 3;\n\n        var txt = ptgroup.selectAll('g.pointtext')\n            .data(showText ? dMod : []);\n        txt.enter()\n            .append('g').classed('pointtext', true)\n                .append('text').attr('transform', 'translate(20,0)');\n        txt.exit().remove();\n        txt.selectAll('text').call(Drawing.textPointStyle, tMod, gd);\n    }\n\n    function styleWaterfalls(d) {\n        var trace = d[0].trace;\n\n        var ptsData = [];\n        if(trace.type === 'waterfall' && trace.visible) {\n            ptsData = d[0].hasTotals ?\n                [['increasing', 'M-6,-6V6H0Z'], ['totals', 'M6,6H0L-6,-6H-0Z'], ['decreasing', 'M6,6V-6H0Z']] :\n                [['increasing', 'M-6,-6V6H6Z'], ['decreasing', 'M6,6V-6H-6Z']];\n        }\n\n        var pts = d3.select(this).select('g.legendpoints')\n            .selectAll('path.legendwaterfall')\n            .data(ptsData);\n        pts.enter().append('path').classed('legendwaterfall', true)\n            .attr('transform', 'translate(20,0)')\n            .style('stroke-miterlimit', 1);\n        pts.exit().remove();\n\n        pts.each(function(dd) {\n            var pt = d3.select(this);\n            var cont = trace[dd[0]].marker;\n            var lw = boundLineWidth(undefined, cont.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);\n\n            pt.attr('d', dd[1])\n                .style('stroke-width', lw + 'px')\n                .call(Color.fill, cont.color);\n\n            if(lw) {\n                pt.call(Color.stroke, cont.line.color);\n            }\n        });\n    }\n\n    function styleBars(d) {\n        styleBarLike(d, this);\n    }\n\n    function styleFunnels(d) {\n        styleBarLike(d, this, 'funnel');\n    }\n\n    function styleBarLike(d, lThis, desiredType) {\n        var trace = d[0].trace;\n        var marker = trace.marker || {};\n        var markerLine = marker.line || {};\n\n        var isVisible = (!desiredType) ? Registry.traceIs(trace, 'bar') :\n            (trace.type === desiredType && trace.visible);\n\n        var barpath = d3.select(lThis).select('g.legendpoints')\n            .selectAll('path.legend' + desiredType)\n            .data(isVisible ? [d] : []);\n        barpath.enter().append('path').classed('legend' + desiredType, true)\n            .attr('d', 'M6,6H-6V-6H6Z')\n            .attr('transform', 'translate(20,0)');\n        barpath.exit().remove();\n\n        barpath.each(function(d) {\n            var p = d3.select(this);\n            var d0 = d[0];\n            var w = boundLineWidth(d0.mlw, marker.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);\n\n            p.style('stroke-width', w + 'px')\n                .call(Color.fill, d0.mc || marker.color);\n\n            if(w) Color.stroke(p, d0.mlc || markerLine.color);\n        });\n    }\n\n    function styleBoxes(d) {\n        var trace = d[0].trace;\n\n        var pts = d3.select(this).select('g.legendpoints')\n            .selectAll('path.legendbox')\n            .data(Registry.traceIs(trace, 'box-violin') && trace.visible ? [d] : []);\n        pts.enter().append('path').classed('legendbox', true)\n            // if we want the median bar, prepend M6,0H-6\n            .attr('d', 'M6,6H-6V-6H6Z')\n            .attr('transform', 'translate(20,0)');\n        pts.exit().remove();\n\n        pts.each(function() {\n            var p = d3.select(this);\n\n            if((trace.boxpoints === 'all' || trace.points === 'all') &&\n                Color.opacity(trace.fillcolor) === 0 && Color.opacity((trace.line || {}).color) === 0\n            ) {\n                var tMod = Lib.minExtend(trace, {\n                    marker: {\n                        size: constantItemSizing ? CST_MARKER_SIZE : Lib.constrain(trace.marker.size, 2, 16),\n                        sizeref: 1,\n                        sizemin: 1,\n                        sizemode: 'diameter'\n                    }\n                });\n                pts.call(Drawing.pointStyle, tMod, gd);\n            } else {\n                var w = boundLineWidth(undefined, trace.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);\n\n                p.style('stroke-width', w + 'px')\n                    .call(Color.fill, trace.fillcolor);\n\n                if(w) Color.stroke(p, trace.line.color);\n            }\n        });\n    }\n\n    function styleCandles(d) {\n        var trace = d[0].trace;\n\n        var pts = d3.select(this).select('g.legendpoints')\n            .selectAll('path.legendcandle')\n            .data(trace.type === 'candlestick' && trace.visible ? [d, d] : []);\n        pts.enter().append('path').classed('legendcandle', true)\n            .attr('d', function(_, i) {\n                if(i) return 'M-15,0H-8M-8,6V-6H8Z'; // increasing\n                return 'M15,0H8M8,-6V6H-8Z'; // decreasing\n            })\n            .attr('transform', 'translate(20,0)')\n            .style('stroke-miterlimit', 1);\n        pts.exit().remove();\n\n        pts.each(function(_, i) {\n            var p = d3.select(this);\n            var cont = trace[i ? 'increasing' : 'decreasing'];\n            var w = boundLineWidth(undefined, cont.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);\n\n            p.style('stroke-width', w + 'px')\n                .call(Color.fill, cont.fillcolor);\n\n            if(w) Color.stroke(p, cont.line.color);\n        });\n    }\n\n    function styleOHLC(d) {\n        var trace = d[0].trace;\n\n        var pts = d3.select(this).select('g.legendpoints')\n            .selectAll('path.legendohlc')\n            .data(trace.type === 'ohlc' && trace.visible ? [d, d] : []);\n        pts.enter().append('path').classed('legendohlc', true)\n            .attr('d', function(_, i) {\n                if(i) return 'M-15,0H0M-8,-6V0'; // increasing\n                return 'M15,0H0M8,6V0'; // decreasing\n            })\n            .attr('transform', 'translate(20,0)')\n            .style('stroke-miterlimit', 1);\n        pts.exit().remove();\n\n        pts.each(function(_, i) {\n            var p = d3.select(this);\n            var cont = trace[i ? 'increasing' : 'decreasing'];\n            var w = boundLineWidth(undefined, cont.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);\n\n            p.style('fill', 'none')\n                .call(Drawing.dashLine, cont.line.dash, w);\n\n            if(w) Color.stroke(p, cont.line.color);\n        });\n    }\n\n    function stylePies(d) {\n        stylePieLike(d, this, 'pie');\n    }\n\n    function styleFunnelareas(d) {\n        stylePieLike(d, this, 'funnelarea');\n    }\n\n    function stylePieLike(d, lThis, desiredType) {\n        var d0 = d[0];\n        var trace = d0.trace;\n\n        var isVisible = (!desiredType) ? Registry.traceIs(trace, desiredType) :\n            (trace.type === desiredType && trace.visible);\n\n        var pts = d3.select(lThis).select('g.legendpoints')\n            .selectAll('path.legend' + desiredType)\n            .data(isVisible ? [d] : []);\n        pts.enter().append('path').classed('legend' + desiredType, true)\n            .attr('d', 'M6,6H-6V-6H6Z')\n            .attr('transform', 'translate(20,0)');\n        pts.exit().remove();\n\n        if(pts.size()) {\n            var cont = (trace.marker || {}).line;\n            var lw = boundLineWidth(pieCastOption(cont.width, d0.pts), cont, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);\n\n            var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}});\n            // since minExtend do not slice more than 3 items we need to patch line.color here\n            tMod.marker.line.color = cont.color;\n\n            var d0Mod = Lib.minExtend(d0, {trace: tMod});\n\n            stylePie(pts, d0Mod, tMod);\n        }\n    }\n};\n\n},{\"../../lib\":719,\"../../registry\":847,\"../../traces/pie/helpers\":1091,\"../../traces/pie/style_one\":1097,\"../../traces/scatter/subtypes\":1135,\"../color\":593,\"../drawing\":614,\"d3\":163}],651:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Plots = _dereq_('../../plots/plots');\nvar axisIds = _dereq_('../../plots/cartesian/axis_ids');\nvar Lib = _dereq_('../../lib');\nvar Icons = _dereq_('../../fonts/ploticon');\n\nvar _ = Lib._;\n\nvar modeBarButtons = module.exports = {};\n\n/**\n * ModeBar buttons configuration\n *\n * @param {string} name\n *      name / id of the buttons (for tracking)\n * @param {string} title\n *      text that appears while hovering over the button,\n *      enter null, false or '' for no hover text\n * @param {string} icon\n *      svg icon object associated with the button\n *      can be linked to Plotly.Icons to use the default plotly icons\n * @param {string} [gravity]\n *      icon positioning\n * @param {function} click\n *      click handler associated with the button, a function of\n *      'gd' (the main graph object) and\n *      'ev' (the event object)\n * @param {string} [attr]\n *      attribute associated with button,\n *      use this with 'val' to keep track of the state\n * @param {*} [val]\n *      initial 'attr' value, can be a function of gd\n * @param {boolean} [toggle]\n *      is the button a toggle button?\n */\nmodeBarButtons.toImage = {\n    name: 'toImage',\n    title: function(gd) {\n        var opts = gd._context.toImageButtonOptions || {};\n        var format = opts.format || 'png';\n        return format === 'png' ?\n            _(gd, 'Download plot as a png') : // legacy text\n            _(gd, 'Download plot'); // generic non-PNG text\n    },\n    icon: Icons.camera,\n    click: function(gd) {\n        var toImageButtonOptions = gd._context.toImageButtonOptions;\n        var opts = {format: toImageButtonOptions.format || 'png'};\n\n        Lib.notifier(_(gd, 'Taking snapshot - this may take a few seconds'), 'long');\n\n        if(opts.format !== 'svg' && Lib.isIE()) {\n            Lib.notifier(_(gd, 'IE only supports svg.  Changing format to svg.'), 'long');\n            opts.format = 'svg';\n        }\n\n        ['filename', 'width', 'height', 'scale'].forEach(function(key) {\n            if(key in toImageButtonOptions) {\n                opts[key] = toImageButtonOptions[key];\n            }\n        });\n\n        Registry.call('downloadImage', gd, opts)\n          .then(function(filename) {\n              Lib.notifier(_(gd, 'Snapshot succeeded') + ' - ' + filename, 'long');\n          })\n          .catch(function() {\n              Lib.notifier(_(gd, 'Sorry, there was a problem downloading your snapshot!'), 'long');\n          });\n    }\n};\n\nmodeBarButtons.sendDataToCloud = {\n    name: 'sendDataToCloud',\n    title: function(gd) { return _(gd, 'Edit in Chart Studio'); },\n    icon: Icons.disk,\n    click: function(gd) {\n        Plots.sendDataToCloud(gd);\n    }\n};\n\nmodeBarButtons.editInChartStudio = {\n    name: 'editInChartStudio',\n    title: function(gd) { return _(gd, 'Edit in Chart Studio'); },\n    icon: Icons.pencil,\n    click: function(gd) {\n        Plots.sendDataToCloud(gd);\n    }\n};\n\nmodeBarButtons.zoom2d = {\n    name: 'zoom2d',\n    title: function(gd) { return _(gd, 'Zoom'); },\n    attr: 'dragmode',\n    val: 'zoom',\n    icon: Icons.zoombox,\n    click: handleCartesian\n};\n\nmodeBarButtons.pan2d = {\n    name: 'pan2d',\n    title: function(gd) { return _(gd, 'Pan'); },\n    attr: 'dragmode',\n    val: 'pan',\n    icon: Icons.pan,\n    click: handleCartesian\n};\n\nmodeBarButtons.select2d = {\n    name: 'select2d',\n    title: function(gd) { return _(gd, 'Box Select'); },\n    attr: 'dragmode',\n    val: 'select',\n    icon: Icons.selectbox,\n    click: handleCartesian\n};\n\nmodeBarButtons.lasso2d = {\n    name: 'lasso2d',\n    title: function(gd) { return _(gd, 'Lasso Select'); },\n    attr: 'dragmode',\n    val: 'lasso',\n    icon: Icons.lasso,\n    click: handleCartesian\n};\n\nmodeBarButtons.zoomIn2d = {\n    name: 'zoomIn2d',\n    title: function(gd) { return _(gd, 'Zoom in'); },\n    attr: 'zoom',\n    val: 'in',\n    icon: Icons.zoom_plus,\n    click: handleCartesian\n};\n\nmodeBarButtons.zoomOut2d = {\n    name: 'zoomOut2d',\n    title: function(gd) { return _(gd, 'Zoom out'); },\n    attr: 'zoom',\n    val: 'out',\n    icon: Icons.zoom_minus,\n    click: handleCartesian\n};\n\nmodeBarButtons.autoScale2d = {\n    name: 'autoScale2d',\n    title: function(gd) { return _(gd, 'Autoscale'); },\n    attr: 'zoom',\n    val: 'auto',\n    icon: Icons.autoscale,\n    click: handleCartesian\n};\n\nmodeBarButtons.resetScale2d = {\n    name: 'resetScale2d',\n    title: function(gd) { return _(gd, 'Reset axes'); },\n    attr: 'zoom',\n    val: 'reset',\n    icon: Icons.home,\n    click: handleCartesian\n};\n\nmodeBarButtons.hoverClosestCartesian = {\n    name: 'hoverClosestCartesian',\n    title: function(gd) { return _(gd, 'Show closest data on hover'); },\n    attr: 'hovermode',\n    val: 'closest',\n    icon: Icons.tooltip_basic,\n    gravity: 'ne',\n    click: handleCartesian\n};\n\nmodeBarButtons.hoverCompareCartesian = {\n    name: 'hoverCompareCartesian',\n    title: function(gd) { return _(gd, 'Compare data on hover'); },\n    attr: 'hovermode',\n    val: function(gd) {\n        return gd._fullLayout._isHoriz ? 'y' : 'x';\n    },\n    icon: Icons.tooltip_compare,\n    gravity: 'ne',\n    click: handleCartesian\n};\n\nfunction handleCartesian(gd, ev) {\n    var button = ev.currentTarget;\n    var astr = button.getAttribute('data-attr');\n    var val = button.getAttribute('data-val') || true;\n    var fullLayout = gd._fullLayout;\n    var aobj = {};\n    var axList = axisIds.list(gd, null, true);\n    var allSpikesEnabled = 'on';\n\n    var ax, i;\n\n    if(astr === 'zoom') {\n        var mag = (val === 'in') ? 0.5 : 2;\n        var r0 = (1 + mag) / 2;\n        var r1 = (1 - mag) / 2;\n        var axName;\n\n        for(i = 0; i < axList.length; i++) {\n            ax = axList[i];\n\n            if(!ax.fixedrange) {\n                axName = ax._name;\n                if(val === 'auto') aobj[axName + '.autorange'] = true;\n                else if(val === 'reset') {\n                    if(ax._rangeInitial === undefined) {\n                        aobj[axName + '.autorange'] = true;\n                    } else {\n                        var rangeInitial = ax._rangeInitial.slice();\n                        aobj[axName + '.range[0]'] = rangeInitial[0];\n                        aobj[axName + '.range[1]'] = rangeInitial[1];\n                    }\n                    if(ax._showSpikeInitial !== undefined) {\n                        aobj[axName + '.showspikes'] = ax._showSpikeInitial;\n                        if(allSpikesEnabled === 'on' && !ax._showSpikeInitial) {\n                            allSpikesEnabled = 'off';\n                        }\n                    }\n                } else {\n                    var rangeNow = [\n                        ax.r2l(ax.range[0]),\n                        ax.r2l(ax.range[1]),\n                    ];\n\n                    var rangeNew = [\n                        r0 * rangeNow[0] + r1 * rangeNow[1],\n                        r0 * rangeNow[1] + r1 * rangeNow[0]\n                    ];\n\n                    aobj[axName + '.range[0]'] = ax.l2r(rangeNew[0]);\n                    aobj[axName + '.range[1]'] = ax.l2r(rangeNew[1]);\n                }\n            }\n        }\n        fullLayout._cartesianSpikesEnabled = allSpikesEnabled;\n    } else {\n        // if ALL traces have orientation 'h', 'hovermode': 'x' otherwise: 'y'\n        if(astr === 'hovermode' && (val === 'x' || val === 'y')) {\n            val = fullLayout._isHoriz ? 'y' : 'x';\n            button.setAttribute('data-val', val);\n        } else if(astr === 'hovermode' && val === 'closest') {\n            for(i = 0; i < axList.length; i++) {\n                ax = axList[i];\n                if(allSpikesEnabled === 'on' && !ax.showspikes) {\n                    allSpikesEnabled = 'off';\n                }\n            }\n            fullLayout._cartesianSpikesEnabled = allSpikesEnabled;\n        }\n\n        aobj[astr] = val;\n    }\n\n    Registry.call('_guiRelayout', gd, aobj);\n}\n\nmodeBarButtons.zoom3d = {\n    name: 'zoom3d',\n    title: function(gd) { return _(gd, 'Zoom'); },\n    attr: 'scene.dragmode',\n    val: 'zoom',\n    icon: Icons.zoombox,\n    click: handleDrag3d\n};\n\nmodeBarButtons.pan3d = {\n    name: 'pan3d',\n    title: function(gd) { return _(gd, 'Pan'); },\n    attr: 'scene.dragmode',\n    val: 'pan',\n    icon: Icons.pan,\n    click: handleDrag3d\n};\n\nmodeBarButtons.orbitRotation = {\n    name: 'orbitRotation',\n    title: function(gd) { return _(gd, 'Orbital rotation'); },\n    attr: 'scene.dragmode',\n    val: 'orbit',\n    icon: Icons['3d_rotate'],\n    click: handleDrag3d\n};\n\nmodeBarButtons.tableRotation = {\n    name: 'tableRotation',\n    title: function(gd) { return _(gd, 'Turntable rotation'); },\n    attr: 'scene.dragmode',\n    val: 'turntable',\n    icon: Icons['z-axis'],\n    click: handleDrag3d\n};\n\nfunction handleDrag3d(gd, ev) {\n    var button = ev.currentTarget;\n    var attr = button.getAttribute('data-attr');\n    var val = button.getAttribute('data-val') || true;\n    var sceneIds = gd._fullLayout._subplots.gl3d;\n    var layoutUpdate = {};\n\n    var parts = attr.split('.');\n\n    for(var i = 0; i < sceneIds.length; i++) {\n        layoutUpdate[sceneIds[i] + '.' + parts[1]] = val;\n    }\n\n    // for multi-type subplots\n    var val2d = (val === 'pan') ? val : 'zoom';\n    layoutUpdate.dragmode = val2d;\n\n    Registry.call('_guiRelayout', gd, layoutUpdate);\n}\n\nmodeBarButtons.resetCameraDefault3d = {\n    name: 'resetCameraDefault3d',\n    title: function(gd) { return _(gd, 'Reset camera to default'); },\n    attr: 'resetDefault',\n    icon: Icons.home,\n    click: handleCamera3d\n};\n\nmodeBarButtons.resetCameraLastSave3d = {\n    name: 'resetCameraLastSave3d',\n    title: function(gd) { return _(gd, 'Reset camera to last save'); },\n    attr: 'resetLastSave',\n    icon: Icons.movie,\n    click: handleCamera3d\n};\n\nfunction handleCamera3d(gd, ev) {\n    var button = ev.currentTarget;\n    var attr = button.getAttribute('data-attr');\n    var fullLayout = gd._fullLayout;\n    var sceneIds = fullLayout._subplots.gl3d;\n    var aobj = {};\n\n    for(var i = 0; i < sceneIds.length; i++) {\n        var sceneId = sceneIds[i];\n        var key = sceneId + '.camera';\n        var scene = fullLayout[sceneId]._scene;\n\n        if(attr === 'resetLastSave') {\n            aobj[key + '.up'] = scene.viewInitial.up;\n            aobj[key + '.eye'] = scene.viewInitial.eye;\n            aobj[key + '.center'] = scene.viewInitial.center;\n        } else if(attr === 'resetDefault') {\n            aobj[key + '.up'] = null;\n            aobj[key + '.eye'] = null;\n            aobj[key + '.center'] = null;\n        }\n    }\n\n    Registry.call('_guiRelayout', gd, aobj);\n}\n\nmodeBarButtons.hoverClosest3d = {\n    name: 'hoverClosest3d',\n    title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },\n    attr: 'hovermode',\n    val: null,\n    toggle: true,\n    icon: Icons.tooltip_basic,\n    gravity: 'ne',\n    click: handleHover3d\n};\n\nfunction getNextHover3d(gd, ev) {\n    var button = ev.currentTarget;\n    var val = button._previousVal;\n    var fullLayout = gd._fullLayout;\n    var sceneIds = fullLayout._subplots.gl3d;\n\n    var axes = ['xaxis', 'yaxis', 'zaxis'];\n\n    // initialize 'current spike' object to be stored in the DOM\n    var currentSpikes = {};\n    var layoutUpdate = {};\n\n    if(val) {\n        layoutUpdate = val;\n        button._previousVal = null;\n    } else {\n        for(var i = 0; i < sceneIds.length; i++) {\n            var sceneId = sceneIds[i];\n            var sceneLayout = fullLayout[sceneId];\n\n            var hovermodeAStr = sceneId + '.hovermode';\n            currentSpikes[hovermodeAStr] = sceneLayout.hovermode;\n            layoutUpdate[hovermodeAStr] = false;\n\n            // copy all the current spike attrs\n            for(var j = 0; j < 3; j++) {\n                var axis = axes[j];\n                var spikeAStr = sceneId + '.' + axis + '.showspikes';\n                layoutUpdate[spikeAStr] = false;\n                currentSpikes[spikeAStr] = sceneLayout[axis].showspikes;\n            }\n        }\n\n        button._previousVal = currentSpikes;\n    }\n    return layoutUpdate;\n}\n\nfunction handleHover3d(gd, ev) {\n    var layoutUpdate = getNextHover3d(gd, ev);\n    Registry.call('_guiRelayout', gd, layoutUpdate);\n}\n\nmodeBarButtons.zoomInGeo = {\n    name: 'zoomInGeo',\n    title: function(gd) { return _(gd, 'Zoom in'); },\n    attr: 'zoom',\n    val: 'in',\n    icon: Icons.zoom_plus,\n    click: handleGeo\n};\n\nmodeBarButtons.zoomOutGeo = {\n    name: 'zoomOutGeo',\n    title: function(gd) { return _(gd, 'Zoom out'); },\n    attr: 'zoom',\n    val: 'out',\n    icon: Icons.zoom_minus,\n    click: handleGeo\n};\n\nmodeBarButtons.resetGeo = {\n    name: 'resetGeo',\n    title: function(gd) { return _(gd, 'Reset'); },\n    attr: 'reset',\n    val: null,\n    icon: Icons.autoscale,\n    click: handleGeo\n};\n\nmodeBarButtons.hoverClosestGeo = {\n    name: 'hoverClosestGeo',\n    title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },\n    attr: 'hovermode',\n    val: null,\n    toggle: true,\n    icon: Icons.tooltip_basic,\n    gravity: 'ne',\n    click: toggleHover\n};\n\nfunction handleGeo(gd, ev) {\n    var button = ev.currentTarget;\n    var attr = button.getAttribute('data-attr');\n    var val = button.getAttribute('data-val') || true;\n    var fullLayout = gd._fullLayout;\n    var geoIds = fullLayout._subplots.geo;\n\n    for(var i = 0; i < geoIds.length; i++) {\n        var id = geoIds[i];\n        var geoLayout = fullLayout[id];\n\n        if(attr === 'zoom') {\n            var scale = geoLayout.projection.scale;\n            var newScale = (val === 'in') ? 2 * scale : 0.5 * scale;\n\n            Registry.call('_guiRelayout', gd, id + '.projection.scale', newScale);\n        } else if(attr === 'reset') {\n            resetView(gd, 'geo');\n        }\n    }\n}\n\nmodeBarButtons.hoverClosestGl2d = {\n    name: 'hoverClosestGl2d',\n    title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },\n    attr: 'hovermode',\n    val: null,\n    toggle: true,\n    icon: Icons.tooltip_basic,\n    gravity: 'ne',\n    click: toggleHover\n};\n\nmodeBarButtons.hoverClosestPie = {\n    name: 'hoverClosestPie',\n    title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },\n    attr: 'hovermode',\n    val: 'closest',\n    icon: Icons.tooltip_basic,\n    gravity: 'ne',\n    click: toggleHover\n};\n\nfunction getNextHover(gd) {\n    var fullLayout = gd._fullLayout;\n\n    if(fullLayout.hovermode) return false;\n\n    if(fullLayout._has('cartesian')) {\n        return fullLayout._isHoriz ? 'y' : 'x';\n    }\n    return 'closest';\n}\n\nfunction toggleHover(gd) {\n    var newHover = getNextHover(gd);\n    Registry.call('_guiRelayout', gd, 'hovermode', newHover);\n}\n\nmodeBarButtons.resetViewSankey = {\n    name: 'resetSankeyGroup',\n    title: function(gd) { return _(gd, 'Reset view'); },\n    icon: Icons.home,\n    click: function(gd) {\n        var aObj = {\n            'node.groups': [],\n            'node.x': [],\n            'node.y': []\n        };\n        for(var i = 0; i < gd._fullData.length; i++) {\n            var viewInitial = gd._fullData[i]._viewInitial;\n            aObj['node.groups'].push(viewInitial.node.groups.slice());\n            aObj['node.x'].push(viewInitial.node.x.slice());\n            aObj['node.y'].push(viewInitial.node.y.slice());\n        }\n        Registry.call('restyle', gd, aObj);\n    }\n};\n\n// buttons when more then one plot types are present\n\nmodeBarButtons.toggleHover = {\n    name: 'toggleHover',\n    title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },\n    attr: 'hovermode',\n    val: null,\n    toggle: true,\n    icon: Icons.tooltip_basic,\n    gravity: 'ne',\n    click: function(gd, ev) {\n        var layoutUpdate = getNextHover3d(gd, ev);\n        layoutUpdate.hovermode = getNextHover(gd);\n\n        Registry.call('_guiRelayout', gd, layoutUpdate);\n    }\n};\n\nmodeBarButtons.resetViews = {\n    name: 'resetViews',\n    title: function(gd) { return _(gd, 'Reset views'); },\n    icon: Icons.home,\n    click: function(gd, ev) {\n        var button = ev.currentTarget;\n\n        button.setAttribute('data-attr', 'zoom');\n        button.setAttribute('data-val', 'reset');\n        handleCartesian(gd, ev);\n\n        button.setAttribute('data-attr', 'resetLastSave');\n        handleCamera3d(gd, ev);\n\n        resetView(gd, 'geo');\n        resetView(gd, 'mapbox');\n    }\n};\n\nmodeBarButtons.toggleSpikelines = {\n    name: 'toggleSpikelines',\n    title: function(gd) { return _(gd, 'Toggle Spike Lines'); },\n    icon: Icons.spikeline,\n    attr: '_cartesianSpikesEnabled',\n    val: 'on',\n    click: function(gd) {\n        var fullLayout = gd._fullLayout;\n\n        fullLayout._cartesianSpikesEnabled = fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on';\n\n        var aobj = setSpikelineVisibility(gd);\n\n        Registry.call('_guiRelayout', gd, aobj);\n    }\n};\n\nfunction setSpikelineVisibility(gd) {\n    var fullLayout = gd._fullLayout;\n    var axList = axisIds.list(gd, null, true);\n    var aobj = {};\n\n    var ax, axName;\n\n    for(var i = 0; i < axList.length; i++) {\n        ax = axList[i];\n        axName = ax._name;\n        aobj[axName + '.showspikes'] = fullLayout._cartesianSpikesEnabled === 'on' ? true : ax._showSpikeInitial;\n    }\n\n    return aobj;\n}\n\nmodeBarButtons.resetViewMapbox = {\n    name: 'resetViewMapbox',\n    title: function(gd) { return _(gd, 'Reset view'); },\n    attr: 'reset',\n    icon: Icons.home,\n    click: function(gd) {\n        resetView(gd, 'mapbox');\n    }\n};\n\nfunction resetView(gd, subplotType) {\n    var fullLayout = gd._fullLayout;\n    var subplotIds = fullLayout._subplots[subplotType];\n    var aObj = {};\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var id = subplotIds[i];\n        var subplotObj = fullLayout[id]._subplot;\n        var viewInitial = subplotObj.viewInitial;\n        var viewKeys = Object.keys(viewInitial);\n\n        for(var j = 0; j < viewKeys.length; j++) {\n            var key = viewKeys[j];\n            aObj[id + '.' + key] = viewInitial[key];\n        }\n    }\n\n    Registry.call('_guiRelayout', gd, aObj);\n}\n\n},{\"../../fonts/ploticon\":699,\"../../lib\":719,\"../../plots/cartesian/axis_ids\":770,\"../../plots/plots\":828,\"../../registry\":847}],652:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nexports.manage = _dereq_('./manage');\n\n},{\"./manage\":653}],653:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar axisIds = _dereq_('../../plots/cartesian/axis_ids');\nvar scatterSubTypes = _dereq_('../../traces/scatter/subtypes');\nvar Registry = _dereq_('../../registry');\n\nvar createModeBar = _dereq_('./modebar');\nvar modeBarButtons = _dereq_('./buttons');\n\n/**\n * ModeBar wrapper around 'create' and 'update',\n * chooses buttons to pass to ModeBar constructor based on\n * plot type and plot config.\n *\n * @param {object} gd main plot object\n *\n */\nmodule.exports = function manageModeBar(gd) {\n    var fullLayout = gd._fullLayout;\n    var context = gd._context;\n    var modeBar = fullLayout._modeBar;\n\n    if(!context.displayModeBar && !context.watermark) {\n        if(modeBar) {\n            modeBar.destroy();\n            delete fullLayout._modeBar;\n        }\n        return;\n    }\n\n    if(!Array.isArray(context.modeBarButtonsToRemove)) {\n        throw new Error([\n            '*modeBarButtonsToRemove* configuration options',\n            'must be an array.'\n        ].join(' '));\n    }\n\n    if(!Array.isArray(context.modeBarButtonsToAdd)) {\n        throw new Error([\n            '*modeBarButtonsToAdd* configuration options',\n            'must be an array.'\n        ].join(' '));\n    }\n\n    var customButtons = context.modeBarButtons;\n    var buttonGroups;\n\n    if(Array.isArray(customButtons) && customButtons.length) {\n        buttonGroups = fillCustomButton(customButtons);\n    } else if(!context.displayModeBar && context.watermark) {\n        buttonGroups = [];\n    } else {\n        buttonGroups = getButtonGroups(gd);\n    }\n\n    if(modeBar) modeBar.update(gd, buttonGroups);\n    else fullLayout._modeBar = createModeBar(gd, buttonGroups);\n};\n\n// logic behind which buttons are displayed by default\nfunction getButtonGroups(gd) {\n    var fullLayout = gd._fullLayout;\n    var fullData = gd._fullData;\n    var context = gd._context;\n    var buttonsToRemove = context.modeBarButtonsToRemove;\n    var buttonsToAdd = context.modeBarButtonsToAdd;\n\n    var hasCartesian = fullLayout._has('cartesian');\n    var hasGL3D = fullLayout._has('gl3d');\n    var hasGeo = fullLayout._has('geo');\n    var hasPie = fullLayout._has('pie');\n    var hasFunnelarea = fullLayout._has('funnelarea');\n    var hasGL2D = fullLayout._has('gl2d');\n    var hasTernary = fullLayout._has('ternary');\n    var hasMapbox = fullLayout._has('mapbox');\n    var hasPolar = fullLayout._has('polar');\n    var hasSankey = fullLayout._has('sankey');\n    var allAxesFixed = areAllAxesFixed(fullLayout);\n\n    var groups = [];\n\n    function addGroup(newGroup) {\n        if(!newGroup.length) return;\n\n        var out = [];\n\n        for(var i = 0; i < newGroup.length; i++) {\n            var button = newGroup[i];\n            if(buttonsToRemove.indexOf(button) !== -1) continue;\n            out.push(modeBarButtons[button]);\n        }\n\n        groups.push(out);\n    }\n\n    // buttons common to all plot types\n    var commonGroup = ['toImage'];\n    if(context.showEditInChartStudio) commonGroup.push('editInChartStudio');\n    else if(context.showSendToCloud) commonGroup.push('sendDataToCloud');\n    addGroup(commonGroup);\n\n    var zoomGroup = [];\n    var hoverGroup = [];\n    var resetGroup = [];\n    var dragModeGroup = [];\n\n    if((hasCartesian || hasGL2D || hasPie || hasFunnelarea || hasTernary) + hasGeo + hasGL3D + hasMapbox + hasPolar > 1) {\n        // graphs with more than one plot types get 'union buttons'\n        // which reset the view or toggle hover labels across all subplots.\n        hoverGroup = ['toggleHover'];\n        resetGroup = ['resetViews'];\n    } else if(hasGeo) {\n        zoomGroup = ['zoomInGeo', 'zoomOutGeo'];\n        hoverGroup = ['hoverClosestGeo'];\n        resetGroup = ['resetGeo'];\n    } else if(hasGL3D) {\n        hoverGroup = ['hoverClosest3d'];\n        resetGroup = ['resetCameraDefault3d', 'resetCameraLastSave3d'];\n    } else if(hasMapbox) {\n        hoverGroup = ['toggleHover'];\n        resetGroup = ['resetViewMapbox'];\n    } else if(hasGL2D) {\n        hoverGroup = ['hoverClosestGl2d'];\n    } else if(hasPie) {\n        hoverGroup = ['hoverClosestPie'];\n    } else if(hasSankey) {\n        hoverGroup = ['hoverClosestCartesian', 'hoverCompareCartesian'];\n        resetGroup = ['resetViewSankey'];\n    } else { // hasPolar, hasTernary\n        // always show at least one hover icon.\n        hoverGroup = ['toggleHover'];\n    }\n    // if we have cartesian, allow switching between closest and compare\n    // regardless of what other types are on the plot, since they'll all\n    // just treat any truthy hovermode as 'closest'\n    if(hasCartesian) {\n        hoverGroup = ['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian'];\n    }\n    if(hasNoHover(fullData)) {\n        hoverGroup = [];\n    }\n\n    if((hasCartesian || hasGL2D) && !allAxesFixed) {\n        zoomGroup = ['zoomIn2d', 'zoomOut2d', 'autoScale2d'];\n        if(resetGroup[0] !== 'resetViews') resetGroup = ['resetScale2d'];\n    }\n\n    if(hasGL3D) {\n        dragModeGroup = ['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation'];\n    } else if(((hasCartesian || hasGL2D) && !allAxesFixed) || hasTernary) {\n        dragModeGroup = ['zoom2d', 'pan2d'];\n    } else if(hasMapbox || hasGeo) {\n        dragModeGroup = ['pan2d'];\n    } else if(hasPolar) {\n        dragModeGroup = ['zoom2d'];\n    }\n    if(isSelectable(fullData)) {\n        dragModeGroup.push('select2d', 'lasso2d');\n    }\n\n    addGroup(dragModeGroup);\n    addGroup(zoomGroup.concat(resetGroup));\n    addGroup(hoverGroup);\n\n    return appendButtonsToGroups(groups, buttonsToAdd);\n}\n\nfunction areAllAxesFixed(fullLayout) {\n    var axList = axisIds.list({_fullLayout: fullLayout}, null, true);\n\n    for(var i = 0; i < axList.length; i++) {\n        if(!axList[i].fixedrange) {\n            return false;\n        }\n    }\n\n    return true;\n}\n\n// look for traces that support selection\n// to be updated as we add more selectPoints handlers\nfunction isSelectable(fullData) {\n    var selectable = false;\n\n    for(var i = 0; i < fullData.length; i++) {\n        if(selectable) break;\n\n        var trace = fullData[i];\n\n        if(!trace._module || !trace._module.selectPoints) continue;\n\n        if(Registry.traceIs(trace, 'scatter-like')) {\n            if(scatterSubTypes.hasMarkers(trace) || scatterSubTypes.hasText(trace)) {\n                selectable = true;\n            }\n        } else if(Registry.traceIs(trace, 'box-violin')) {\n            if(trace.boxpoints === 'all' || trace.points === 'all') {\n                selectable = true;\n            }\n        } else {\n            // assume that in general if the trace module has selectPoints,\n            // then it's selectable. Scatter is an exception to this because it must\n            // have markers or text, not just be a scatter type.\n\n            selectable = true;\n        }\n    }\n\n    return selectable;\n}\n\n// check whether all trace are 'noHover'\nfunction hasNoHover(fullData) {\n    for(var i = 0; i < fullData.length; i++) {\n        if(!Registry.traceIs(fullData[i], 'noHover')) return false;\n    }\n    return true;\n}\n\nfunction appendButtonsToGroups(groups, buttons) {\n    if(buttons.length) {\n        if(Array.isArray(buttons[0])) {\n            for(var i = 0; i < buttons.length; i++) {\n                groups.push(buttons[i]);\n            }\n        } else groups.push(buttons);\n    }\n\n    return groups;\n}\n\n// fill in custom buttons referring to default mode bar buttons\nfunction fillCustomButton(customButtons) {\n    for(var i = 0; i < customButtons.length; i++) {\n        var buttonGroup = customButtons[i];\n\n        for(var j = 0; j < buttonGroup.length; j++) {\n            var button = buttonGroup[j];\n\n            if(typeof button === 'string') {\n                if(modeBarButtons[button] !== undefined) {\n                    customButtons[i][j] = modeBarButtons[button];\n                } else {\n                    throw new Error([\n                        '*modeBarButtons* configuration options',\n                        'invalid button name'\n                    ].join(' '));\n                }\n            }\n        }\n    }\n\n    return customButtons;\n}\n\n},{\"../../plots/cartesian/axis_ids\":770,\"../../registry\":847,\"../../traces/scatter/subtypes\":1135,\"./buttons\":651,\"./modebar\":654}],654:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar Icons = _dereq_('../../fonts/ploticon');\nvar Parser = new DOMParser();\n\n/**\n * UI controller for interactive plots\n * @Class\n * @Param {object} opts\n * @Param {object} opts.buttons    nested arrays of grouped buttons config objects\n * @Param {object} opts.container  container div to append modeBar\n * @Param {object} opts.graphInfo  primary plot object containing data and layout\n */\nfunction ModeBar(opts) {\n    this.container = opts.container;\n    this.element = document.createElement('div');\n\n    this.update(opts.graphInfo, opts.buttons);\n\n    this.container.appendChild(this.element);\n}\n\nvar proto = ModeBar.prototype;\n\n/**\n * Update modeBar (buttons and logo)\n *\n * @param {object} graphInfo  primary plot object containing data and layout\n * @param {array of arrays} buttons nested arrays of grouped buttons to initialize\n *\n */\nproto.update = function(graphInfo, buttons) {\n    this.graphInfo = graphInfo;\n\n    var context = this.graphInfo._context;\n    var fullLayout = this.graphInfo._fullLayout;\n    var modeBarId = 'modebar-' + fullLayout._uid;\n\n    this.element.setAttribute('id', modeBarId);\n    this._uid = modeBarId;\n\n    this.element.className = 'modebar';\n    if(context.displayModeBar === 'hover') this.element.className += ' modebar--hover ease-bg';\n\n    if(fullLayout.modebar.orientation === 'v') {\n        this.element.className += ' vertical';\n        buttons = buttons.reverse();\n    }\n\n    var style = fullLayout.modebar;\n    var bgSelector = context.displayModeBar === 'hover' ? '.js-plotly-plot .plotly:hover ' : '';\n\n    Lib.deleteRelatedStyleRule(modeBarId);\n    Lib.addRelatedStyleRule(modeBarId, bgSelector + '#' + modeBarId + ' .modebar-group', 'background-color: ' + style.bgcolor);\n    Lib.addRelatedStyleRule(modeBarId, '#' + modeBarId + ' .modebar-btn .icon path', 'fill: ' + style.color);\n    Lib.addRelatedStyleRule(modeBarId, '#' + modeBarId + ' .modebar-btn:hover .icon path', 'fill: ' + style.activecolor);\n    Lib.addRelatedStyleRule(modeBarId, '#' + modeBarId + ' .modebar-btn.active .icon path', 'fill: ' + style.activecolor);\n\n    // if buttons or logo have changed, redraw modebar interior\n    var needsNewButtons = !this.hasButtons(buttons);\n    var needsNewLogo = (this.hasLogo !== context.displaylogo);\n    var needsNewLocale = (this.locale !== context.locale);\n\n    this.locale = context.locale;\n\n    if(needsNewButtons || needsNewLogo || needsNewLocale) {\n        this.removeAllButtons();\n\n        this.updateButtons(buttons);\n\n        if(context.watermark || context.displaylogo) {\n            var logoGroup = this.getLogo();\n            if(context.watermark) {\n                logoGroup.className = logoGroup.className + ' watermark';\n            }\n\n            if(fullLayout.modebar.orientation === 'v') {\n                this.element.insertBefore(logoGroup, this.element.childNodes[0]);\n            } else {\n                this.element.appendChild(logoGroup);\n            }\n\n            this.hasLogo = true;\n        }\n    }\n\n    this.updateActiveButton();\n};\n\nproto.updateButtons = function(buttons) {\n    var _this = this;\n\n    this.buttons = buttons;\n    this.buttonElements = [];\n    this.buttonsNames = [];\n\n    this.buttons.forEach(function(buttonGroup) {\n        var group = _this.createGroup();\n\n        buttonGroup.forEach(function(buttonConfig) {\n            var buttonName = buttonConfig.name;\n            if(!buttonName) {\n                throw new Error('must provide button \\'name\\' in button config');\n            }\n            if(_this.buttonsNames.indexOf(buttonName) !== -1) {\n                throw new Error('button name \\'' + buttonName + '\\' is taken');\n            }\n            _this.buttonsNames.push(buttonName);\n\n            var button = _this.createButton(buttonConfig);\n            _this.buttonElements.push(button);\n            group.appendChild(button);\n        });\n\n        _this.element.appendChild(group);\n    });\n};\n\n/**\n * Empty div for containing a group of buttons\n * @Return {HTMLelement}\n */\nproto.createGroup = function() {\n    var group = document.createElement('div');\n    group.className = 'modebar-group';\n    return group;\n};\n\n/**\n * Create a new button div and set constant and configurable attributes\n * @Param {object} config (see ./buttons.js for more info)\n * @Return {HTMLelement}\n */\nproto.createButton = function(config) {\n    var _this = this;\n    var button = document.createElement('a');\n\n    button.setAttribute('rel', 'tooltip');\n    button.className = 'modebar-btn';\n\n    var title = config.title;\n    if(title === undefined) title = config.name;\n    // for localization: allow title to be a callable that takes gd as arg\n    else if(typeof title === 'function') title = title(this.graphInfo);\n\n    if(title || title === 0) button.setAttribute('data-title', title);\n\n    if(config.attr !== undefined) button.setAttribute('data-attr', config.attr);\n\n    var val = config.val;\n    if(val !== undefined) {\n        if(typeof val === 'function') val = val(this.graphInfo);\n        button.setAttribute('data-val', val);\n    }\n\n    var click = config.click;\n    if(typeof click !== 'function') {\n        throw new Error('must provide button \\'click\\' function in button config');\n    } else {\n        button.addEventListener('click', function(ev) {\n            config.click(_this.graphInfo, ev);\n\n            // only needed for 'hoverClosestGeo' which does not call relayout\n            _this.updateActiveButton(ev.currentTarget);\n        });\n    }\n\n    button.setAttribute('data-toggle', config.toggle || false);\n    if(config.toggle) d3.select(button).classed('active', true);\n\n    var icon = config.icon;\n    if(typeof icon === 'function') {\n        button.appendChild(icon());\n    } else {\n        button.appendChild(this.createIcon(icon || Icons.question));\n    }\n    button.setAttribute('data-gravity', config.gravity || 'n');\n\n    return button;\n};\n\n/**\n * Add an icon to a button\n * @Param {object} thisIcon\n * @Param {number} thisIcon.width\n * @Param {string} thisIcon.path\n * @Param {string} thisIcon.color\n * @Return {HTMLelement}\n */\nproto.createIcon = function(thisIcon) {\n    var iconHeight = isNumeric(thisIcon.height) ?\n        Number(thisIcon.height) :\n        thisIcon.ascent - thisIcon.descent;\n    var svgNS = 'http://www.w3.org/2000/svg';\n    var icon;\n\n    if(thisIcon.path) {\n        icon = document.createElementNS(svgNS, 'svg');\n        icon.setAttribute('viewBox', [0, 0, thisIcon.width, iconHeight].join(' '));\n        icon.setAttribute('class', 'icon');\n\n        var path = document.createElementNS(svgNS, 'path');\n        path.setAttribute('d', thisIcon.path);\n\n        if(thisIcon.transform) {\n            path.setAttribute('transform', thisIcon.transform);\n        } else if(thisIcon.ascent !== undefined) {\n            // Legacy icon transform calculation\n            path.setAttribute('transform', 'matrix(1 0 0 -1 0 ' + thisIcon.ascent + ')');\n        }\n\n        icon.appendChild(path);\n    }\n\n    if(thisIcon.svg) {\n        var svgDoc = Parser.parseFromString(thisIcon.svg, 'application/xml');\n        icon = svgDoc.childNodes[0];\n    }\n\n    icon.setAttribute('height', '1em');\n    icon.setAttribute('width', '1em');\n\n    return icon;\n};\n\n/**\n * Updates active button with attribute specified in layout\n * @Param {object} graphInfo plot object containing data and layout\n * @Return {HTMLelement}\n */\nproto.updateActiveButton = function(buttonClicked) {\n    var fullLayout = this.graphInfo._fullLayout;\n    var dataAttrClicked = (buttonClicked !== undefined) ?\n        buttonClicked.getAttribute('data-attr') :\n        null;\n\n    this.buttonElements.forEach(function(button) {\n        var thisval = button.getAttribute('data-val') || true;\n        var dataAttr = button.getAttribute('data-attr');\n        var isToggleButton = (button.getAttribute('data-toggle') === 'true');\n        var button3 = d3.select(button);\n\n        // Use 'data-toggle' and 'buttonClicked' to toggle buttons\n        // that have no one-to-one equivalent in fullLayout\n        if(isToggleButton) {\n            if(dataAttr === dataAttrClicked) {\n                button3.classed('active', !button3.classed('active'));\n            }\n        } else {\n            var val = (dataAttr === null) ?\n                dataAttr :\n                Lib.nestedProperty(fullLayout, dataAttr).get();\n\n            button3.classed('active', val === thisval);\n        }\n    });\n};\n\n/**\n * Check if modeBar is configured as button configuration argument\n *\n * @Param {object} buttons 2d array of grouped button config objects\n * @Return {boolean}\n */\nproto.hasButtons = function(buttons) {\n    var currentButtons = this.buttons;\n\n    if(!currentButtons) return false;\n\n    if(buttons.length !== currentButtons.length) return false;\n\n    for(var i = 0; i < buttons.length; ++i) {\n        if(buttons[i].length !== currentButtons[i].length) return false;\n        for(var j = 0; j < buttons[i].length; j++) {\n            if(buttons[i][j].name !== currentButtons[i][j].name) return false;\n        }\n    }\n\n    return true;\n};\n\n/**\n * @return {HTMLDivElement} The logo image wrapped in a group\n */\nproto.getLogo = function() {\n    var group = this.createGroup();\n    var a = document.createElement('a');\n\n    a.href = 'https://plot.ly/';\n    a.target = '_blank';\n    a.setAttribute('data-title', Lib._(this.graphInfo, 'Produced with Plotly'));\n    a.className = 'modebar-btn plotlyjsicon modebar-btn--logo';\n\n    a.appendChild(this.createIcon(Icons.newplotlylogo));\n\n    group.appendChild(a);\n    return group;\n};\n\nproto.removeAllButtons = function() {\n    while(this.element.firstChild) {\n        this.element.removeChild(this.element.firstChild);\n    }\n\n    this.hasLogo = false;\n};\n\nproto.destroy = function() {\n    Lib.removeElement(this.container.querySelector('.modebar'));\n    Lib.deleteRelatedStyleRule(this._uid);\n};\n\nfunction createModeBar(gd, buttons) {\n    var fullLayout = gd._fullLayout;\n\n    var modeBar = new ModeBar({\n        graphInfo: gd,\n        container: fullLayout._modebardiv.node(),\n        buttons: buttons\n    });\n\n    if(fullLayout._privateplot) {\n        d3.select(modeBar.element).append('span')\n            .classed('badge-private float--left', true)\n            .text('PRIVATE');\n    }\n\n    return modeBar;\n}\n\nmodule.exports = createModeBar;\n\n},{\"../../fonts/ploticon\":699,\"../../lib\":719,\"d3\":163,\"fast-isnumeric\":225}],655:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar colorAttrs = _dereq_('../color/attributes');\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\nvar buttonAttrs = templatedArray('button', {\n    visible: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'plot',\n        \n    },\n    step: {\n        valType: 'enumerated',\n        \n        values: ['month', 'year', 'day', 'hour', 'minute', 'second', 'all'],\n        dflt: 'month',\n        editType: 'plot',\n        \n    },\n    stepmode: {\n        valType: 'enumerated',\n        \n        values: ['backward', 'todate'],\n        dflt: 'backward',\n        editType: 'plot',\n        \n    },\n    count: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 1,\n        editType: 'plot',\n        \n    },\n    label: {\n        valType: 'string',\n        \n        editType: 'plot',\n        \n    },\n    editType: 'plot',\n    \n});\n\nmodule.exports = {\n    visible: {\n        valType: 'boolean',\n        \n        editType: 'plot',\n        \n    },\n\n    buttons: buttonAttrs,\n\n    x: {\n        valType: 'number',\n        min: -2,\n        max: 3,\n        \n        editType: 'plot',\n        \n    },\n    xanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'left', 'center', 'right'],\n        dflt: 'left',\n        \n        editType: 'plot',\n        \n    },\n    y: {\n        valType: 'number',\n        min: -2,\n        max: 3,\n        \n        editType: 'plot',\n        \n    },\n    yanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'top', 'middle', 'bottom'],\n        dflt: 'bottom',\n        \n        editType: 'plot',\n        \n    },\n\n    font: fontAttrs({\n        editType: 'plot',\n        \n    }),\n\n    bgcolor: {\n        valType: 'color',\n        dflt: colorAttrs.lightLine,\n        \n        editType: 'plot',\n        \n    },\n    activecolor: {\n        valType: 'color',\n        \n        editType: 'plot',\n        \n    },\n    bordercolor: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'plot',\n        \n    },\n    borderwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'plot',\n        \n    },\n    editType: 'plot'\n};\n\n},{\"../../plot_api/plot_template\":757,\"../../plots/font_attributes\":793,\"../color/attributes\":592}],656:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n\n    // 'y' position pad above counter axis domain\n    yPad: 0.02,\n\n    // minimum button width (regardless of text size)\n    minButtonWidth: 30,\n\n    // buttons rect radii\n    rx: 3,\n    ry: 3,\n\n    // light fraction used to compute the 'activecolor' default\n    lightAmount: 25,\n    darkAmount: 10\n};\n\n},{}],657:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../color');\nvar Template = _dereq_('../../plot_api/plot_template');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nvar attributes = _dereq_('./attributes');\nvar constants = _dereq_('./constants');\n\n\nmodule.exports = function handleDefaults(containerIn, containerOut, layout, counterAxes, calendar) {\n    var selectorIn = containerIn.rangeselector || {};\n    var selectorOut = Template.newContainer(containerOut, 'rangeselector');\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(selectorIn, selectorOut, attributes, attr, dflt);\n    }\n\n    var buttons = handleArrayContainerDefaults(selectorIn, selectorOut, {\n        name: 'buttons',\n        handleItemDefaults: buttonDefaults,\n        calendar: calendar\n    });\n\n    var visible = coerce('visible', buttons.length > 0);\n    if(visible) {\n        var posDflt = getPosDflt(containerOut, layout, counterAxes);\n        coerce('x', posDflt[0]);\n        coerce('y', posDflt[1]);\n        Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);\n\n        coerce('xanchor');\n        coerce('yanchor');\n\n        Lib.coerceFont(coerce, 'font', layout.font);\n\n        var bgColor = coerce('bgcolor');\n        coerce('activecolor', Color.contrast(bgColor, constants.lightAmount, constants.darkAmount));\n        coerce('bordercolor');\n        coerce('borderwidth');\n    }\n};\n\nfunction buttonDefaults(buttonIn, buttonOut, selectorOut, opts) {\n    var calendar = opts.calendar;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(buttonIn, buttonOut, attributes.buttons, attr, dflt);\n    }\n\n    var visible = coerce('visible');\n\n    if(visible) {\n        var step = coerce('step');\n        if(step !== 'all') {\n            if(calendar && calendar !== 'gregorian' && (step === 'month' || step === 'year')) {\n                buttonOut.stepmode = 'backward';\n            } else {\n                coerce('stepmode');\n            }\n\n            coerce('count');\n        }\n\n        coerce('label');\n    }\n}\n\nfunction getPosDflt(containerOut, layout, counterAxes) {\n    var anchoredList = counterAxes.filter(function(ax) {\n        return layout[ax].anchor === containerOut._id;\n    });\n\n    var posY = 0;\n    for(var i = 0; i < anchoredList.length; i++) {\n        var domain = layout[anchoredList[i]].domain;\n        if(domain) posY = Math.max(domain[1], posY);\n    }\n\n    return [containerOut.domain[0], posY + constants.yPad];\n}\n\n},{\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../plots/array_container_defaults\":763,\"../color\":593,\"./attributes\":655,\"./constants\":656}],658:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Registry = _dereq_('../../registry');\nvar Plots = _dereq_('../../plots/plots');\nvar Color = _dereq_('../color');\nvar Drawing = _dereq_('../drawing');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar axisIds = _dereq_('../../plots/cartesian/axis_ids');\n\nvar alignmentConstants = _dereq_('../../constants/alignment');\nvar LINE_SPACING = alignmentConstants.LINE_SPACING;\nvar FROM_TL = alignmentConstants.FROM_TL;\nvar FROM_BR = alignmentConstants.FROM_BR;\n\nvar constants = _dereq_('./constants');\nvar getUpdateObject = _dereq_('./get_update_object');\n\nmodule.exports = function draw(gd) {\n    var fullLayout = gd._fullLayout;\n\n    var selectors = fullLayout._infolayer.selectAll('.rangeselector')\n        .data(makeSelectorData(gd), selectorKeyFunc);\n\n    selectors.enter().append('g')\n        .classed('rangeselector', true);\n\n    selectors.exit().remove();\n\n    selectors.style({\n        cursor: 'pointer',\n        'pointer-events': 'all'\n    });\n\n    selectors.each(function(d) {\n        var selector = d3.select(this);\n        var axisLayout = d;\n        var selectorLayout = axisLayout.rangeselector;\n\n        var buttons = selector.selectAll('g.button')\n            .data(Lib.filterVisible(selectorLayout.buttons));\n\n        buttons.enter().append('g')\n            .classed('button', true);\n\n        buttons.exit().remove();\n\n        buttons.each(function(d) {\n            var button = d3.select(this);\n            var update = getUpdateObject(axisLayout, d);\n\n            d._isActive = isActive(axisLayout, d, update);\n\n            button.call(drawButtonRect, selectorLayout, d);\n            button.call(drawButtonText, selectorLayout, d, gd);\n\n            button.on('click', function() {\n                if(gd._dragged) return;\n\n                Registry.call('_guiRelayout', gd, update);\n            });\n\n            button.on('mouseover', function() {\n                d._isHovered = true;\n                button.call(drawButtonRect, selectorLayout, d);\n            });\n\n            button.on('mouseout', function() {\n                d._isHovered = false;\n                button.call(drawButtonRect, selectorLayout, d);\n            });\n        });\n\n        reposition(gd, buttons, selectorLayout, axisLayout._name, selector);\n    });\n};\n\nfunction makeSelectorData(gd) {\n    var axes = axisIds.list(gd, 'x', true);\n    var data = [];\n\n    for(var i = 0; i < axes.length; i++) {\n        var axis = axes[i];\n\n        if(axis.rangeselector && axis.rangeselector.visible) {\n            data.push(axis);\n        }\n    }\n\n    return data;\n}\n\nfunction selectorKeyFunc(d) {\n    return d._id;\n}\n\nfunction isActive(axisLayout, opts, update) {\n    if(opts.step === 'all') {\n        return axisLayout.autorange === true;\n    } else {\n        var keys = Object.keys(update);\n\n        return (\n            axisLayout.range[0] === update[keys[0]] &&\n            axisLayout.range[1] === update[keys[1]]\n        );\n    }\n}\n\nfunction drawButtonRect(button, selectorLayout, d) {\n    var rect = Lib.ensureSingle(button, 'rect', 'selector-rect', function(s) {\n        s.attr('shape-rendering', 'crispEdges');\n    });\n\n    rect.attr({\n        'rx': constants.rx,\n        'ry': constants.ry\n    });\n\n    rect.call(Color.stroke, selectorLayout.bordercolor)\n        .call(Color.fill, getFillColor(selectorLayout, d))\n        .style('stroke-width', selectorLayout.borderwidth + 'px');\n}\n\nfunction getFillColor(selectorLayout, d) {\n    return (d._isActive || d._isHovered) ?\n        selectorLayout.activecolor :\n        selectorLayout.bgcolor;\n}\n\nfunction drawButtonText(button, selectorLayout, d, gd) {\n    function textLayout(s) {\n        svgTextUtils.convertToTspans(s, gd);\n    }\n\n    var text = Lib.ensureSingle(button, 'text', 'selector-text', function(s) {\n        s.classed('user-select-none', true)\n            .attr('text-anchor', 'middle');\n    });\n\n    text.call(Drawing.font, selectorLayout.font)\n        .text(getLabel(d, gd._fullLayout._meta))\n        .call(textLayout);\n}\n\nfunction getLabel(opts, _meta) {\n    if(opts.label) {\n        return _meta ?\n            Lib.templateString(opts.label, _meta) :\n            opts.label;\n    }\n\n    if(opts.step === 'all') return 'all';\n\n    return opts.count + opts.step.charAt(0);\n}\n\nfunction reposition(gd, buttons, opts, axName, selector) {\n    var width = 0;\n    var height = 0;\n\n    var borderWidth = opts.borderwidth;\n\n    buttons.each(function() {\n        var button = d3.select(this);\n        var text = button.select('.selector-text');\n\n        var tHeight = opts.font.size * LINE_SPACING;\n        var hEff = Math.max(tHeight * svgTextUtils.lineCount(text), 16) + 3;\n\n        height = Math.max(height, hEff);\n    });\n\n    buttons.each(function() {\n        var button = d3.select(this);\n        var rect = button.select('.selector-rect');\n        var text = button.select('.selector-text');\n\n        var tWidth = text.node() && Drawing.bBox(text.node()).width;\n        var tHeight = opts.font.size * LINE_SPACING;\n        var tLines = svgTextUtils.lineCount(text);\n\n        var wEff = Math.max(tWidth + 10, constants.minButtonWidth);\n\n        // TODO add MathJax support\n\n        // TODO add buttongap attribute\n\n        button.attr('transform', 'translate(' +\n            (borderWidth + width) + ',' + borderWidth +\n        ')');\n\n        rect.attr({\n            x: 0,\n            y: 0,\n            width: wEff,\n            height: height\n        });\n\n        svgTextUtils.positionText(text, wEff / 2,\n            height / 2 - ((tLines - 1) * tHeight / 2) + 3);\n\n        width += wEff + 5;\n    });\n\n    var graphSize = gd._fullLayout._size;\n    var lx = graphSize.l + graphSize.w * opts.x;\n    var ly = graphSize.t + graphSize.h * (1 - opts.y);\n\n    var xanchor = 'left';\n    if(Lib.isRightAnchor(opts)) {\n        lx -= width;\n        xanchor = 'right';\n    }\n    if(Lib.isCenterAnchor(opts)) {\n        lx -= width / 2;\n        xanchor = 'center';\n    }\n\n    var yanchor = 'top';\n    if(Lib.isBottomAnchor(opts)) {\n        ly -= height;\n        yanchor = 'bottom';\n    }\n    if(Lib.isMiddleAnchor(opts)) {\n        ly -= height / 2;\n        yanchor = 'middle';\n    }\n\n    width = Math.ceil(width);\n    height = Math.ceil(height);\n    lx = Math.round(lx);\n    ly = Math.round(ly);\n\n    Plots.autoMargin(gd, axName + '-range-selector', {\n        x: opts.x,\n        y: opts.y,\n        l: width * FROM_TL[xanchor],\n        r: width * FROM_BR[xanchor],\n        b: height * FROM_BR[yanchor],\n        t: height * FROM_TL[yanchor]\n    });\n\n    selector.attr('transform', 'translate(' + lx + ',' + ly + ')');\n}\n\n},{\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plots/cartesian/axis_ids\":770,\"../../plots/plots\":828,\"../../registry\":847,\"../color\":593,\"../drawing\":614,\"./constants\":656,\"./get_update_object\":659,\"d3\":163}],659:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nmodule.exports = function getUpdateObject(axisLayout, buttonLayout) {\n    var axName = axisLayout._name;\n    var update = {};\n\n    if(buttonLayout.step === 'all') {\n        update[axName + '.autorange'] = true;\n    } else {\n        var xrange = getXRange(axisLayout, buttonLayout);\n\n        update[axName + '.range[0]'] = xrange[0];\n        update[axName + '.range[1]'] = xrange[1];\n    }\n\n    return update;\n};\n\nfunction getXRange(axisLayout, buttonLayout) {\n    var currentRange = axisLayout.range;\n    var base = new Date(axisLayout.r2l(currentRange[1]));\n    var step = buttonLayout.step;\n    var count = buttonLayout.count;\n    var range0;\n\n    switch(buttonLayout.stepmode) {\n        case 'backward':\n            range0 = axisLayout.l2r(+d3.time[step].utc.offset(base, -count));\n            break;\n\n        case 'todate':\n            var base2 = d3.time[step].utc.offset(base, -count);\n\n            range0 = axisLayout.l2r(+d3.time[step].utc.ceil(base2));\n            break;\n    }\n\n    var range1 = currentRange[1];\n\n    return [range0, range1];\n}\n\n},{\"d3\":163}],660:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'rangeselector',\n\n    schema: {\n        subplots: {\n            xaxis: {rangeselector: _dereq_('./attributes')}\n        }\n    },\n\n    layoutAttributes: _dereq_('./attributes'),\n    handleDefaults: _dereq_('./defaults'),\n\n    draw: _dereq_('./draw')\n};\n\n},{\"./attributes\":655,\"./defaults\":657,\"./draw\":658}],661:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorAttributes = _dereq_('../color/attributes');\n\nmodule.exports = {\n    bgcolor: {\n        valType: 'color',\n        dflt: colorAttributes.background,\n        \n        editType: 'plot',\n        \n    },\n    bordercolor: {\n        valType: 'color',\n        dflt: colorAttributes.defaultLine,\n        \n        editType: 'plot',\n        \n    },\n    borderwidth: {\n        valType: 'integer',\n        dflt: 0,\n        min: 0,\n        \n        editType: 'plot',\n        \n    },\n    autorange: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        impliedEdits: {'range[0]': undefined, 'range[1]': undefined},\n        \n    },\n    range: {\n        valType: 'info_array',\n        \n        items: [\n            {valType: 'any', editType: 'calc', impliedEdits: {'^autorange': false}},\n            {valType: 'any', editType: 'calc', impliedEdits: {'^autorange': false}}\n        ],\n        editType: 'calc',\n        impliedEdits: {'autorange': false},\n        \n    },\n    thickness: {\n        valType: 'number',\n        dflt: 0.15,\n        min: 0,\n        max: 1,\n        \n        editType: 'plot',\n        \n    },\n    visible: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        \n    },\n    editType: 'calc'\n};\n\n},{\"../color/attributes\":592}],662:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar listAxes = _dereq_('../../plots/cartesian/axis_ids').list;\nvar getAutoRange = _dereq_('../../plots/cartesian/autorange').getAutoRange;\nvar constants = _dereq_('./constants');\n\nmodule.exports = function calcAutorange(gd) {\n    var axes = listAxes(gd, 'x', true);\n\n    // Compute new slider range using axis autorange if necessary.\n    //\n    // Copy back range to input range slider container to skip\n    // this step in subsequent draw calls.\n\n    for(var i = 0; i < axes.length; i++) {\n        var ax = axes[i];\n        var opts = ax[constants.name];\n\n        if(opts && opts.visible && opts.autorange) {\n            opts._input.autorange = true;\n            opts._input.range = opts.range = getAutoRange(gd, ax);\n        }\n    }\n};\n\n},{\"../../plots/cartesian/autorange\":766,\"../../plots/cartesian/axis_ids\":770,\"./constants\":663}],663:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n\n    // attribute container name\n    name: 'rangeslider',\n\n    // class names\n\n    containerClassName: 'rangeslider-container',\n    bgClassName: 'rangeslider-bg',\n    rangePlotClassName: 'rangeslider-rangeplot',\n\n    maskMinClassName: 'rangeslider-mask-min',\n    maskMaxClassName: 'rangeslider-mask-max',\n    slideBoxClassName: 'rangeslider-slidebox',\n\n    grabberMinClassName: 'rangeslider-grabber-min',\n    grabAreaMinClassName: 'rangeslider-grabarea-min',\n    handleMinClassName: 'rangeslider-handle-min',\n\n    grabberMaxClassName: 'rangeslider-grabber-max',\n    grabAreaMaxClassName: 'rangeslider-grabarea-max',\n    handleMaxClassName: 'rangeslider-handle-max',\n\n    maskMinOppAxisClassName: 'rangeslider-mask-min-opp-axis',\n    maskMaxOppAxisClassName: 'rangeslider-mask-max-opp-axis',\n\n    // style constants\n\n    maskColor: 'rgba(0,0,0,0.4)',\n    maskOppAxisColor: 'rgba(0,0,0,0.2)',\n\n    slideBoxFill: 'transparent',\n    slideBoxCursor: 'ew-resize',\n\n    grabAreaFill: 'transparent',\n    grabAreaCursor: 'col-resize',\n    grabAreaWidth: 10,\n\n    handleWidth: 4,\n    handleRadius: 1,\n    handleStrokeWidth: 1,\n\n    extraPad: 15\n};\n\n},{}],664:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Template = _dereq_('../../plot_api/plot_template');\nvar axisIds = _dereq_('../../plots/cartesian/axis_ids');\n\nvar attributes = _dereq_('./attributes');\nvar oppAxisAttrs = _dereq_('./oppaxis_attributes');\n\nmodule.exports = function handleDefaults(layoutIn, layoutOut, axName) {\n    var axIn = layoutIn[axName];\n    var axOut = layoutOut[axName];\n\n    if(!(axIn.rangeslider || layoutOut._requestRangeslider[axOut._id])) return;\n\n    // not super proud of this (maybe store _ in axis object instead\n    if(!Lib.isPlainObject(axIn.rangeslider)) {\n        axIn.rangeslider = {};\n    }\n\n    var containerIn = axIn.rangeslider;\n    var containerOut = Template.newContainer(axOut, 'rangeslider');\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);\n    }\n\n    var rangeContainerIn, rangeContainerOut;\n    function coerceRange(attr, dflt) {\n        return Lib.coerce(rangeContainerIn, rangeContainerOut, oppAxisAttrs, attr, dflt);\n    }\n\n    var visible = coerce('visible');\n    if(!visible) return;\n\n    coerce('bgcolor', layoutOut.plot_bgcolor);\n    coerce('bordercolor');\n    coerce('borderwidth');\n    coerce('thickness');\n\n    coerce('autorange', !axOut.isValidRange(containerIn.range));\n    coerce('range');\n\n    var subplots = layoutOut._subplots;\n    if(subplots) {\n        var yIds = subplots.cartesian\n            .filter(function(subplotId) {\n                return subplotId.substr(0, subplotId.indexOf('y')) === axisIds.name2id(axName);\n            })\n            .map(function(subplotId) {\n                return subplotId.substr(subplotId.indexOf('y'), subplotId.length);\n            });\n        var yNames = Lib.simpleMap(yIds, axisIds.id2name);\n        for(var i = 0; i < yNames.length; i++) {\n            var yName = yNames[i];\n\n            rangeContainerIn = containerIn[yName] || {};\n            rangeContainerOut = Template.newContainer(containerOut, yName, 'yaxis');\n\n            var yAxOut = layoutOut[yName];\n\n            var rangemodeDflt;\n            if(rangeContainerIn.range && yAxOut.isValidRange(rangeContainerIn.range)) {\n                rangemodeDflt = 'fixed';\n            }\n\n            var rangeMode = coerceRange('rangemode', rangemodeDflt);\n            if(rangeMode !== 'match') {\n                coerceRange('range', yAxOut.range.slice());\n            }\n        }\n    }\n\n    // to map back range slider (auto) range\n    containerOut._input = containerIn;\n};\n\n},{\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../plots/cartesian/axis_ids\":770,\"./attributes\":661,\"./oppaxis_attributes\":668}],665:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Registry = _dereq_('../../registry');\nvar Plots = _dereq_('../../plots/plots');\n\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../drawing');\nvar Color = _dereq_('../color');\nvar Titles = _dereq_('../titles');\n\nvar Cartesian = _dereq_('../../plots/cartesian');\nvar axisIDs = _dereq_('../../plots/cartesian/axis_ids');\n\nvar dragElement = _dereq_('../dragelement');\nvar setCursor = _dereq_('../../lib/setcursor');\n\nvar constants = _dereq_('./constants');\n\nmodule.exports = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var rangeSliderData = fullLayout._rangeSliderData;\n    for(var i = 0; i < rangeSliderData.length; i++) {\n        var opts = rangeSliderData[i][constants.name];\n        // fullLayout._uid may not exist when we call makeData\n        opts._clipId = opts._id + '-' + fullLayout._uid;\n    }\n\n    /*\n     * <g container />\n     *  <rect bg />\n     *  < .... range plot />\n     *  <rect mask-min />\n     *  <rect mask-max />\n     *  <rect slidebox />\n     *  <g grabber-min />\n     *      <rect handle-min />\n     *      <rect grabare-min />\n     *  <g grabber-max />\n     *      <rect handle-max />\n     *      <rect grabare-max />\n     *\n     *  ...\n     */\n\n    function keyFunction(axisOpts) {\n        return axisOpts._name;\n    }\n\n    var rangeSliders = fullLayout._infolayer\n        .selectAll('g.' + constants.containerClassName)\n        .data(rangeSliderData, keyFunction);\n\n    // remove exiting sliders and their corresponding clip paths\n    rangeSliders.exit().each(function(axisOpts) {\n        var opts = axisOpts[constants.name];\n        fullLayout._topdefs.select('#' + opts._clipId).remove();\n    }).remove();\n\n    // return early if no range slider is visible\n    if(rangeSliderData.length === 0) return;\n\n    rangeSliders.enter().append('g')\n        .classed(constants.containerClassName, true)\n        .attr('pointer-events', 'all');\n\n    // for all present range sliders\n    rangeSliders.each(function(axisOpts) {\n        var rangeSlider = d3.select(this);\n        var opts = axisOpts[constants.name];\n        var oppAxisOpts = fullLayout[axisIDs.id2name(axisOpts.anchor)];\n        var oppAxisRangeOpts = opts[axisIDs.id2name(axisOpts.anchor)];\n\n        // update range\n        // Expand slider range to the axis range\n        if(opts.range) {\n            var rng = Lib.simpleMap(opts.range, axisOpts.r2l);\n            var axRng = Lib.simpleMap(axisOpts.range, axisOpts.r2l);\n            var newRng;\n\n            if(axRng[0] < axRng[1]) {\n                newRng = [\n                    Math.min(rng[0], axRng[0]),\n                    Math.max(rng[1], axRng[1])\n                ];\n            } else {\n                newRng = [\n                    Math.max(rng[0], axRng[0]),\n                    Math.min(rng[1], axRng[1])\n                ];\n            }\n\n            opts.range = opts._input.range = Lib.simpleMap(newRng, axisOpts.l2r);\n        }\n\n        axisOpts.cleanRange('rangeslider.range');\n\n        // update range slider dimensions\n\n        var margin = fullLayout.margin;\n        var graphSize = fullLayout._size;\n        var domain = axisOpts.domain;\n        var tickHeight = opts._tickHeight;\n\n        var oppBottom = opts._oppBottom;\n\n        opts._width = graphSize.w * (domain[1] - domain[0]);\n\n        var x = Math.round(margin.l + (graphSize.w * domain[0]));\n\n        var y = Math.round(\n            graphSize.t + graphSize.h * (1 - oppBottom) +\n            tickHeight +\n            opts._offsetShift + constants.extraPad\n        );\n\n        rangeSlider.attr('transform', 'translate(' + x + ',' + y + ')');\n\n        // update data <--> pixel coordinate conversion methods\n\n        var range0 = axisOpts.r2l(opts.range[0]);\n        var range1 = axisOpts.r2l(opts.range[1]);\n        var dist = range1 - range0;\n\n        opts.p2d = function(v) {\n            return (v / opts._width) * dist + range0;\n        };\n\n        opts.d2p = function(v) {\n            return (v - range0) / dist * opts._width;\n        };\n\n        opts._rl = [range0, range1];\n\n        if(oppAxisRangeOpts.rangemode !== 'match') {\n            var range0OppAxis = oppAxisOpts.r2l(oppAxisRangeOpts.range[0]);\n            var range1OppAxis = oppAxisOpts.r2l(oppAxisRangeOpts.range[1]);\n            var distOppAxis = range1OppAxis - range0OppAxis;\n\n            opts.d2pOppAxis = function(v) {\n                return (v - range0OppAxis) / distOppAxis * opts._height;\n            };\n        }\n\n        // update inner nodes\n\n        rangeSlider\n            .call(drawBg, gd, axisOpts, opts)\n            .call(addClipPath, gd, axisOpts, opts)\n            .call(drawRangePlot, gd, axisOpts, opts)\n            .call(drawMasks, gd, axisOpts, opts, oppAxisRangeOpts)\n            .call(drawSlideBox, gd, axisOpts, opts)\n            .call(drawGrabbers, gd, axisOpts, opts);\n\n        // setup drag element\n        setupDragElement(rangeSlider, gd, axisOpts, opts);\n\n        // update current range\n        setPixelRange(rangeSlider, gd, axisOpts, opts, oppAxisOpts, oppAxisRangeOpts);\n\n        // title goes next to range slider instead of tick labels, so\n        // just take it over and draw it from here\n        if(axisOpts.side === 'bottom') {\n            Titles.draw(gd, axisOpts._id + 'title', {\n                propContainer: axisOpts,\n                propName: axisOpts._name + '.title',\n                placeholder: fullLayout._dfltTitle.x,\n                attributes: {\n                    x: axisOpts._offset + axisOpts._length / 2,\n                    y: y + opts._height + opts._offsetShift + 10 + 1.5 * axisOpts.title.font.size,\n                    'text-anchor': 'middle'\n                }\n            });\n        }\n    });\n};\n\nfunction setupDragElement(rangeSlider, gd, axisOpts, opts) {\n    var slideBox = rangeSlider.select('rect.' + constants.slideBoxClassName).node();\n    var grabAreaMin = rangeSlider.select('rect.' + constants.grabAreaMinClassName).node();\n    var grabAreaMax = rangeSlider.select('rect.' + constants.grabAreaMaxClassName).node();\n\n    rangeSlider.on('mousedown', function() {\n        var event = d3.event;\n        var target = event.target;\n        var startX = event.clientX;\n        var offsetX = startX - rangeSlider.node().getBoundingClientRect().left;\n        var minVal = opts.d2p(axisOpts._rl[0]);\n        var maxVal = opts.d2p(axisOpts._rl[1]);\n\n        var dragCover = dragElement.coverSlip();\n\n        dragCover.addEventListener('mousemove', mouseMove);\n        dragCover.addEventListener('mouseup', mouseUp);\n\n        function mouseMove(e) {\n            var delta = +e.clientX - startX;\n            var pixelMin, pixelMax, cursor;\n\n            switch(target) {\n                case slideBox:\n                    cursor = 'ew-resize';\n                    pixelMin = minVal + delta;\n                    pixelMax = maxVal + delta;\n                    break;\n\n                case grabAreaMin:\n                    cursor = 'col-resize';\n                    pixelMin = minVal + delta;\n                    pixelMax = maxVal;\n                    break;\n\n                case grabAreaMax:\n                    cursor = 'col-resize';\n                    pixelMin = minVal;\n                    pixelMax = maxVal + delta;\n                    break;\n\n                default:\n                    cursor = 'ew-resize';\n                    pixelMin = offsetX;\n                    pixelMax = offsetX + delta;\n                    break;\n            }\n\n            if(pixelMax < pixelMin) {\n                var tmp = pixelMax;\n                pixelMax = pixelMin;\n                pixelMin = tmp;\n            }\n\n            opts._pixelMin = pixelMin;\n            opts._pixelMax = pixelMax;\n\n            setCursor(d3.select(dragCover), cursor);\n            setDataRange(rangeSlider, gd, axisOpts, opts);\n        }\n\n        function mouseUp() {\n            dragCover.removeEventListener('mousemove', mouseMove);\n            dragCover.removeEventListener('mouseup', mouseUp);\n            Lib.removeElement(dragCover);\n        }\n    });\n}\n\nfunction setDataRange(rangeSlider, gd, axisOpts, opts) {\n    function clamp(v) {\n        return axisOpts.l2r(Lib.constrain(v, opts._rl[0], opts._rl[1]));\n    }\n\n    var dataMin = clamp(opts.p2d(opts._pixelMin));\n    var dataMax = clamp(opts.p2d(opts._pixelMax));\n\n    window.requestAnimationFrame(function() {\n        Registry.call('_guiRelayout', gd, axisOpts._name + '.range', [dataMin, dataMax]);\n    });\n}\n\nfunction setPixelRange(rangeSlider, gd, axisOpts, opts, oppAxisOpts, oppAxisRangeOpts) {\n    var hw2 = constants.handleWidth / 2;\n\n    function clamp(v) {\n        return Lib.constrain(v, 0, opts._width);\n    }\n\n    function clampOppAxis(v) {\n        return Lib.constrain(v, 0, opts._height);\n    }\n\n    function clampHandle(v) {\n        return Lib.constrain(v, -hw2, opts._width + hw2);\n    }\n\n    var pixelMin = clamp(opts.d2p(axisOpts._rl[0]));\n    var pixelMax = clamp(opts.d2p(axisOpts._rl[1]));\n\n    rangeSlider.select('rect.' + constants.slideBoxClassName)\n        .attr('x', pixelMin)\n        .attr('width', pixelMax - pixelMin);\n\n    rangeSlider.select('rect.' + constants.maskMinClassName)\n        .attr('width', pixelMin);\n\n    rangeSlider.select('rect.' + constants.maskMaxClassName)\n        .attr('x', pixelMax)\n        .attr('width', opts._width - pixelMax);\n\n    if(oppAxisRangeOpts.rangemode !== 'match') {\n        var pixelMinOppAxis = opts._height - clampOppAxis(opts.d2pOppAxis(oppAxisOpts._rl[1]));\n        var pixelMaxOppAxis = opts._height - clampOppAxis(opts.d2pOppAxis(oppAxisOpts._rl[0]));\n\n        rangeSlider.select('rect.' + constants.maskMinOppAxisClassName)\n            .attr('x', pixelMin)\n            .attr('height', pixelMinOppAxis)\n            .attr('width', pixelMax - pixelMin);\n\n        rangeSlider.select('rect.' + constants.maskMaxOppAxisClassName)\n            .attr('x', pixelMin)\n            .attr('y', pixelMaxOppAxis)\n            .attr('height', opts._height - pixelMaxOppAxis)\n            .attr('width', pixelMax - pixelMin);\n\n        rangeSlider.select('rect.' + constants.slideBoxClassName)\n            .attr('y', pixelMinOppAxis)\n            .attr('height', pixelMaxOppAxis - pixelMinOppAxis);\n    }\n\n    // add offset for crispier corners\n    // https://github.com/plotly/plotly.js/pull/1409\n    var offset = 0.5;\n\n    var xMin = Math.round(clampHandle(pixelMin - hw2)) - offset;\n    var xMax = Math.round(clampHandle(pixelMax - hw2)) + offset;\n\n    rangeSlider.select('g.' + constants.grabberMinClassName)\n        .attr('transform', 'translate(' + xMin + ',' + offset + ')');\n\n    rangeSlider.select('g.' + constants.grabberMaxClassName)\n        .attr('transform', 'translate(' + xMax + ',' + offset + ')');\n}\n\nfunction drawBg(rangeSlider, gd, axisOpts, opts) {\n    var bg = Lib.ensureSingle(rangeSlider, 'rect', constants.bgClassName, function(s) {\n        s.attr({\n            x: 0,\n            y: 0,\n            'shape-rendering': 'crispEdges'\n        });\n    });\n\n    var borderCorrect = (opts.borderwidth % 2) === 0 ?\n        opts.borderwidth :\n        opts.borderwidth - 1;\n\n    var offsetShift = -opts._offsetShift;\n    var lw = Drawing.crispRound(gd, opts.borderwidth);\n\n    bg.attr({\n        width: opts._width + borderCorrect,\n        height: opts._height + borderCorrect,\n        transform: 'translate(' + offsetShift + ',' + offsetShift + ')',\n        fill: opts.bgcolor,\n        stroke: opts.bordercolor,\n        'stroke-width': lw\n    });\n}\n\nfunction addClipPath(rangeSlider, gd, axisOpts, opts) {\n    var fullLayout = gd._fullLayout;\n\n    var clipPath = Lib.ensureSingleById(fullLayout._topdefs, 'clipPath', opts._clipId, function(s) {\n        s.append('rect').attr({ x: 0, y: 0 });\n    });\n\n    clipPath.select('rect').attr({\n        width: opts._width,\n        height: opts._height\n    });\n}\n\nfunction drawRangePlot(rangeSlider, gd, axisOpts, opts) {\n    var calcData = gd.calcdata;\n\n    var rangePlots = rangeSlider.selectAll('g.' + constants.rangePlotClassName)\n        .data(axisOpts._subplotsWith, Lib.identity);\n\n    rangePlots.enter().append('g')\n        .attr('class', function(id) { return constants.rangePlotClassName + ' ' + id; })\n        .call(Drawing.setClipUrl, opts._clipId, gd);\n\n    rangePlots.order();\n\n    rangePlots.exit().remove();\n\n    var mainplotinfo;\n\n    rangePlots.each(function(id, i) {\n        var plotgroup = d3.select(this);\n        var isMainPlot = (i === 0);\n\n        var oppAxisOpts = axisIDs.getFromId(gd, id, 'y');\n        var oppAxisName = oppAxisOpts._name;\n        var oppAxisRangeOpts = opts[oppAxisName];\n\n        var mockFigure = {\n            data: [],\n            layout: {\n                xaxis: {\n                    type: axisOpts.type,\n                    domain: [0, 1],\n                    range: opts.range.slice(),\n                    calendar: axisOpts.calendar\n                },\n                width: opts._width,\n                height: opts._height,\n                margin: { t: 0, b: 0, l: 0, r: 0 }\n            },\n            _context: gd._context\n        };\n\n        mockFigure.layout[oppAxisName] = {\n            type: oppAxisOpts.type,\n            domain: [0, 1],\n            range: oppAxisRangeOpts.rangemode !== 'match' ? oppAxisRangeOpts.range.slice() : oppAxisOpts.range.slice(),\n            calendar: oppAxisOpts.calendar\n        };\n\n        Plots.supplyDefaults(mockFigure);\n\n        var xa = mockFigure._fullLayout.xaxis;\n        var ya = mockFigure._fullLayout[oppAxisName];\n\n        xa.clearCalc();\n        xa.setScale();\n        ya.clearCalc();\n        ya.setScale();\n\n        var plotinfo = {\n            id: id,\n            plotgroup: plotgroup,\n            xaxis: xa,\n            yaxis: ya,\n            isRangePlot: true\n        };\n\n        if(isMainPlot) mainplotinfo = plotinfo;\n        else {\n            plotinfo.mainplot = 'xy';\n            plotinfo.mainplotinfo = mainplotinfo;\n        }\n\n        Cartesian.rangePlot(gd, plotinfo, filterRangePlotCalcData(calcData, id));\n    });\n}\n\nfunction filterRangePlotCalcData(calcData, subplotId) {\n    var out = [];\n\n    for(var i = 0; i < calcData.length; i++) {\n        var calcTrace = calcData[i];\n        var trace = calcTrace[0].trace;\n\n        if(trace.xaxis + trace.yaxis === subplotId) {\n            out.push(calcTrace);\n        }\n    }\n\n    return out;\n}\n\nfunction drawMasks(rangeSlider, gd, axisOpts, opts, oppAxisRangeOpts) {\n    var maskMin = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMinClassName, function(s) {\n        s.attr({\n            x: 0,\n            y: 0,\n            'shape-rendering': 'crispEdges'\n        });\n    });\n\n    maskMin\n        .attr('height', opts._height)\n        .call(Color.fill, constants.maskColor);\n\n    var maskMax = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMaxClassName, function(s) {\n        s.attr({\n            y: 0,\n            'shape-rendering': 'crispEdges'\n        });\n    });\n\n    maskMax\n        .attr('height', opts._height)\n        .call(Color.fill, constants.maskColor);\n\n    // masks used for oppAxis zoom\n    if(oppAxisRangeOpts.rangemode !== 'match') {\n        var maskMinOppAxis = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMinOppAxisClassName, function(s) {\n            s.attr({\n                y: 0,\n                'shape-rendering': 'crispEdges'\n            });\n        });\n\n        maskMinOppAxis\n            .attr('width', opts._width)\n            .call(Color.fill, constants.maskOppAxisColor);\n\n        var maskMaxOppAxis = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMaxOppAxisClassName, function(s) {\n            s.attr({\n                y: 0,\n                'shape-rendering': 'crispEdges'\n            });\n        });\n\n        maskMaxOppAxis\n            .attr('width', opts._width)\n            .style('border-top', constants.maskOppBorder)\n            .call(Color.fill, constants.maskOppAxisColor);\n    }\n}\n\nfunction drawSlideBox(rangeSlider, gd, axisOpts, opts) {\n    if(gd._context.staticPlot) return;\n\n    var slideBox = Lib.ensureSingle(rangeSlider, 'rect', constants.slideBoxClassName, function(s) {\n        s.attr({\n            y: 0,\n            cursor: constants.slideBoxCursor,\n            'shape-rendering': 'crispEdges'\n        });\n    });\n\n    slideBox.attr({\n        height: opts._height,\n        fill: constants.slideBoxFill\n    });\n}\n\nfunction drawGrabbers(rangeSlider, gd, axisOpts, opts) {\n    // <g grabber />\n    var grabberMin = Lib.ensureSingle(rangeSlider, 'g', constants.grabberMinClassName);\n    var grabberMax = Lib.ensureSingle(rangeSlider, 'g', constants.grabberMaxClassName);\n\n    // <g handle />\n    var handleFixAttrs = {\n        x: 0,\n        width: constants.handleWidth,\n        rx: constants.handleRadius,\n        fill: Color.background,\n        stroke: Color.defaultLine,\n        'stroke-width': constants.handleStrokeWidth,\n        'shape-rendering': 'crispEdges'\n    };\n    var handleDynamicAttrs = {\n        y: Math.round(opts._height / 4),\n        height: Math.round(opts._height / 2),\n    };\n    var handleMin = Lib.ensureSingle(grabberMin, 'rect', constants.handleMinClassName, function(s) {\n        s.attr(handleFixAttrs);\n    });\n    handleMin.attr(handleDynamicAttrs);\n\n    var handleMax = Lib.ensureSingle(grabberMax, 'rect', constants.handleMaxClassName, function(s) {\n        s.attr(handleFixAttrs);\n    });\n    handleMax.attr(handleDynamicAttrs);\n\n    // <g grabarea />\n    if(gd._context.staticPlot) return;\n\n    var grabAreaFixAttrs = {\n        width: constants.grabAreaWidth,\n        x: 0,\n        y: 0,\n        fill: constants.grabAreaFill,\n        cursor: constants.grabAreaCursor\n    };\n\n    var grabAreaMin = Lib.ensureSingle(grabberMin, 'rect', constants.grabAreaMinClassName, function(s) {\n        s.attr(grabAreaFixAttrs);\n    });\n    grabAreaMin.attr('height', opts._height);\n\n    var grabAreaMax = Lib.ensureSingle(grabberMax, 'rect', constants.grabAreaMaxClassName, function(s) {\n        s.attr(grabAreaFixAttrs);\n    });\n    grabAreaMax.attr('height', opts._height);\n}\n\n},{\"../../lib\":719,\"../../lib/setcursor\":739,\"../../plots/cartesian\":778,\"../../plots/cartesian/axis_ids\":770,\"../../plots/plots\":828,\"../../registry\":847,\"../color\":593,\"../dragelement\":611,\"../drawing\":614,\"../titles\":681,\"./constants\":663,\"d3\":163}],666:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar axisIDs = _dereq_('../../plots/cartesian/axis_ids');\nvar constants = _dereq_('./constants');\nvar name = constants.name;\n\nfunction isVisible(ax) {\n    var rangeSlider = ax && ax[name];\n    return rangeSlider && rangeSlider.visible;\n}\nexports.isVisible = isVisible;\n\nexports.makeData = function(fullLayout) {\n    var axes = axisIDs.list({ _fullLayout: fullLayout }, 'x', true);\n    var margin = fullLayout.margin;\n    var rangeSliderData = [];\n\n    if(!fullLayout._has('gl2d')) {\n        for(var i = 0; i < axes.length; i++) {\n            var ax = axes[i];\n\n            if(isVisible(ax)) {\n                rangeSliderData.push(ax);\n\n                var opts = ax[name];\n                opts._id = name + ax._id;\n                opts._height = (fullLayout.height - margin.b - margin.t) * opts.thickness;\n                opts._offsetShift = Math.floor(opts.borderwidth / 2);\n            }\n        }\n    }\n\n    fullLayout._rangeSliderData = rangeSliderData;\n};\n\nexports.autoMarginOpts = function(gd, ax) {\n    var opts = ax[name];\n\n    var oppBottom = Infinity;\n    var counterAxes = ax._counterAxes;\n    for(var j = 0; j < counterAxes.length; j++) {\n        var counterId = counterAxes[j];\n        var oppAxis = axisIDs.getFromId(gd, counterId);\n        oppBottom = Math.min(oppBottom, oppAxis.domain[0]);\n    }\n    opts._oppBottom = oppBottom;\n\n    var tickHeight = (ax.side === 'bottom' && ax._boundingBox.height) || 0;\n    opts._tickHeight = tickHeight;\n\n    return {\n        x: 0,\n        y: oppBottom,\n        l: 0,\n        r: 0,\n        t: 0,\n        b: opts._height + gd._fullLayout.margin.b + tickHeight,\n        pad: constants.extraPad + opts._offsetShift * 2\n    };\n};\n\n},{\"../../plots/cartesian/axis_ids\":770,\"./constants\":663}],667:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attrs = _dereq_('./attributes');\nvar oppAxisAttrs = _dereq_('./oppaxis_attributes');\nvar helpers = _dereq_('./helpers');\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'rangeslider',\n\n    schema: {\n        subplots: {\n            xaxis: {\n                rangeslider: Lib.extendFlat({}, attrs, {\n                    yaxis: oppAxisAttrs\n                })\n            }\n        }\n    },\n\n    layoutAttributes: _dereq_('./attributes'),\n    handleDefaults: _dereq_('./defaults'),\n    calcAutorange: _dereq_('./calc_autorange'),\n    draw: _dereq_('./draw'),\n    isVisible: helpers.isVisible,\n    makeData: helpers.makeData,\n    autoMarginOpts: helpers.autoMarginOpts\n};\n\n},{\"../../lib\":719,\"./attributes\":661,\"./calc_autorange\":662,\"./defaults\":664,\"./draw\":665,\"./helpers\":666,\"./oppaxis_attributes\":668}],668:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    // not really a 'subplot' attribute container,\n    // but this is the flag we use to denote attributes that\n    // support yaxis, yaxis2, yaxis3, ... counters\n    _isSubplotObj: true,\n\n    rangemode: {\n        valType: 'enumerated',\n        values: ['auto', 'fixed', 'match'],\n        dflt: 'match',\n        \n        editType: 'calc',\n        \n    },\n    range: {\n        valType: 'info_array',\n        \n        items: [\n            {valType: 'any', editType: 'plot'},\n            {valType: 'any', editType: 'plot'}\n        ],\n        editType: 'plot',\n        \n    },\n    editType: 'calc'\n};\n\n},{}],669:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar annAttrs = _dereq_('../annotations/attributes');\nvar scatterLineAttrs = _dereq_('../../traces/scatter/attributes').line;\nvar dash = _dereq_('../drawing/attributes').dash;\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\nmodule.exports = templatedArray('shape', {\n    visible: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'calc+arraydraw',\n        \n    },\n\n    type: {\n        valType: 'enumerated',\n        values: ['circle', 'rect', 'path', 'line'],\n        \n        editType: 'calc+arraydraw',\n        \n    },\n\n    layer: {\n        valType: 'enumerated',\n        values: ['below', 'above'],\n        dflt: 'above',\n        \n        editType: 'arraydraw',\n        \n    },\n\n    xref: extendFlat({}, annAttrs.xref, {\n        \n    }),\n    xsizemode: {\n        valType: 'enumerated',\n        values: ['scaled', 'pixel'],\n        dflt: 'scaled',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    xanchor: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    x0: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    x1: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n\n    yref: extendFlat({}, annAttrs.yref, {\n        \n    }),\n    ysizemode: {\n        valType: 'enumerated',\n        values: ['scaled', 'pixel'],\n        dflt: 'scaled',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    yanchor: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    y0: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n    y1: {\n        valType: 'any',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n\n    path: {\n        valType: 'string',\n        \n        editType: 'calc+arraydraw',\n        \n    },\n\n    opacity: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 1,\n        \n        editType: 'arraydraw',\n        \n    },\n    line: {\n        color: extendFlat({}, scatterLineAttrs.color, {editType: 'arraydraw'}),\n        width: extendFlat({}, scatterLineAttrs.width, {editType: 'calc+arraydraw'}),\n        dash: extendFlat({}, dash, {editType: 'arraydraw'}),\n        \n        editType: 'calc+arraydraw'\n    },\n    fillcolor: {\n        valType: 'color',\n        dflt: 'rgba(0,0,0,0)',\n        \n        editType: 'arraydraw',\n        \n    },\n    editType: 'arraydraw'\n});\n\n},{\"../../lib/extend\":710,\"../../plot_api/plot_template\":757,\"../../traces/scatter/attributes\":1112,\"../annotations/attributes\":576,\"../drawing/attributes\":613}],670:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nvar constants = _dereq_('./constants');\nvar helpers = _dereq_('./helpers');\n\n\nmodule.exports = function calcAutorange(gd) {\n    var fullLayout = gd._fullLayout;\n    var shapeList = Lib.filterVisible(fullLayout.shapes);\n\n    if(!shapeList.length || !gd._fullData.length) return;\n\n    for(var i = 0; i < shapeList.length; i++) {\n        var shape = shapeList[i];\n        shape._extremes = {};\n\n        var ax, bounds;\n\n        if(shape.xref !== 'paper') {\n            var vx0 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x0;\n            var vx1 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x1;\n            ax = Axes.getFromId(gd, shape.xref);\n\n            bounds = shapeBounds(ax, vx0, vx1, shape.path, constants.paramIsX);\n            if(bounds) {\n                shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcXPaddingOptions(shape));\n            }\n        }\n\n        if(shape.yref !== 'paper') {\n            var vy0 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y0;\n            var vy1 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y1;\n            ax = Axes.getFromId(gd, shape.yref);\n\n            bounds = shapeBounds(ax, vy0, vy1, shape.path, constants.paramIsY);\n            if(bounds) {\n                shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcYPaddingOptions(shape));\n            }\n        }\n    }\n};\n\nfunction calcXPaddingOptions(shape) {\n    return calcPaddingOptions(shape.line.width, shape.xsizemode, shape.x0, shape.x1, shape.path, false);\n}\n\nfunction calcYPaddingOptions(shape) {\n    return calcPaddingOptions(shape.line.width, shape.ysizemode, shape.y0, shape.y1, shape.path, true);\n}\n\nfunction calcPaddingOptions(lineWidth, sizeMode, v0, v1, path, isYAxis) {\n    var ppad = lineWidth / 2;\n    var axisDirectionReverted = isYAxis;\n\n    if(sizeMode === 'pixel') {\n        var coords = path ?\n            helpers.extractPathCoords(path, isYAxis ? constants.paramIsY : constants.paramIsX) :\n            [v0, v1];\n        var maxValue = Lib.aggNums(Math.max, null, coords);\n        var minValue = Lib.aggNums(Math.min, null, coords);\n        var beforePad = minValue < 0 ? Math.abs(minValue) + ppad : ppad;\n        var afterPad = maxValue > 0 ? maxValue + ppad : ppad;\n\n        return {\n            ppad: ppad,\n            ppadplus: axisDirectionReverted ? beforePad : afterPad,\n            ppadminus: axisDirectionReverted ? afterPad : beforePad\n        };\n    } else {\n        return {ppad: ppad};\n    }\n}\n\nfunction shapeBounds(ax, v0, v1, path, paramsToUse) {\n    var convertVal = (ax.type === 'category' || ax.type === 'multicategory') ? ax.r2c : ax.d2c;\n\n    if(v0 !== undefined) return [convertVal(v0), convertVal(v1)];\n    if(!path) return;\n\n    var min = Infinity;\n    var max = -Infinity;\n    var segments = path.match(constants.segmentRE);\n    var i;\n    var segment;\n    var drawnParam;\n    var params;\n    var val;\n\n    if(ax.type === 'date') convertVal = helpers.decodeDate(convertVal);\n\n    for(i = 0; i < segments.length; i++) {\n        segment = segments[i];\n        drawnParam = paramsToUse[segment.charAt(0)].drawn;\n        if(drawnParam === undefined) continue;\n\n        params = segments[i].substr(1).match(constants.paramRE);\n        if(!params || params.length < drawnParam) continue;\n\n        val = convertVal(params[drawnParam]);\n        if(val < min) min = val;\n        if(val > max) max = val;\n    }\n    if(max >= min) return [min, max];\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"./constants\":671,\"./helpers\":674}],671:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nmodule.exports = {\n    segmentRE: /[MLHVQCTSZ][^MLHVQCTSZ]*/g,\n    paramRE: /[^\\s,]+/g,\n\n    // which numbers in each path segment are x (or y) values\n    // drawn is which param is a drawn point, as opposed to a\n    // control point (which doesn't count toward autorange.\n    // TODO: this means curved paths could extend beyond the\n    // autorange bounds. This is a bit tricky to get right\n    // unless we revert to bounding boxes, but perhaps there's\n    // a calculation we could do...)\n    paramIsX: {\n        M: {0: true, drawn: 0},\n        L: {0: true, drawn: 0},\n        H: {0: true, drawn: 0},\n        V: {},\n        Q: {0: true, 2: true, drawn: 2},\n        C: {0: true, 2: true, 4: true, drawn: 4},\n        T: {0: true, drawn: 0},\n        S: {0: true, 2: true, drawn: 2},\n        // A: {0: true, 5: true},\n        Z: {}\n    },\n\n    paramIsY: {\n        M: {1: true, drawn: 1},\n        L: {1: true, drawn: 1},\n        H: {},\n        V: {0: true, drawn: 0},\n        Q: {1: true, 3: true, drawn: 3},\n        C: {1: true, 3: true, 5: true, drawn: 5},\n        T: {1: true, drawn: 1},\n        S: {1: true, 3: true, drawn: 5},\n        // A: {1: true, 6: true},\n        Z: {}\n    },\n\n    numParams: {\n        M: 2,\n        L: 2,\n        H: 1,\n        V: 1,\n        Q: 4,\n        C: 6,\n        T: 2,\n        S: 4,\n        // A: 7,\n        Z: 0\n    }\n};\n\n},{}],672:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nvar attributes = _dereq_('./attributes');\nvar helpers = _dereq_('./helpers');\n\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {\n    handleArrayContainerDefaults(layoutIn, layoutOut, {\n        name: 'shapes',\n        handleItemDefaults: handleShapeDefaults\n    });\n};\n\nfunction handleShapeDefaults(shapeIn, shapeOut, fullLayout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(shapeIn, shapeOut, attributes, attr, dflt);\n    }\n\n    var visible = coerce('visible');\n\n    if(!visible) return;\n\n    coerce('layer');\n    coerce('opacity');\n    coerce('fillcolor');\n    coerce('line.color');\n    coerce('line.width');\n    coerce('line.dash');\n\n    var dfltType = shapeIn.path ? 'path' : 'rect';\n    var shapeType = coerce('type', dfltType);\n    var xSizeMode = coerce('xsizemode');\n    var ySizeMode = coerce('ysizemode');\n\n    // positioning\n    var axLetters = ['x', 'y'];\n    for(var i = 0; i < 2; i++) {\n        var axLetter = axLetters[i];\n        var attrAnchor = axLetter + 'anchor';\n        var sizeMode = axLetter === 'x' ? xSizeMode : ySizeMode;\n        var gdMock = {_fullLayout: fullLayout};\n        var ax;\n        var pos2r;\n        var r2pos;\n\n        // xref, yref\n        var axRef = Axes.coerceRef(shapeIn, shapeOut, gdMock, axLetter, '', 'paper');\n\n        if(axRef !== 'paper') {\n            ax = Axes.getFromId(gdMock, axRef);\n            ax._shapeIndices.push(shapeOut._index);\n            r2pos = helpers.rangeToShapePosition(ax);\n            pos2r = helpers.shapePositionToRange(ax);\n        } else {\n            pos2r = r2pos = Lib.identity;\n        }\n\n        // Coerce x0, x1, y0, y1\n        if(shapeType !== 'path') {\n            var dflt0 = 0.25;\n            var dflt1 = 0.75;\n\n            // hack until V2.0 when log has regular range behavior - make it look like other\n            // ranges to send to coerce, then put it back after\n            // this is all to give reasonable default position behavior on log axes, which is\n            // a pretty unimportant edge case so we could just ignore this.\n            var attr0 = axLetter + '0';\n            var attr1 = axLetter + '1';\n            var in0 = shapeIn[attr0];\n            var in1 = shapeIn[attr1];\n            shapeIn[attr0] = pos2r(shapeIn[attr0], true);\n            shapeIn[attr1] = pos2r(shapeIn[attr1], true);\n\n            if(sizeMode === 'pixel') {\n                coerce(attr0, 0);\n                coerce(attr1, 10);\n            } else {\n                Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr0, dflt0);\n                Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr1, dflt1);\n            }\n\n            // hack part 2\n            shapeOut[attr0] = r2pos(shapeOut[attr0]);\n            shapeOut[attr1] = r2pos(shapeOut[attr1]);\n            shapeIn[attr0] = in0;\n            shapeIn[attr1] = in1;\n        }\n\n        // Coerce xanchor and yanchor\n        if(sizeMode === 'pixel') {\n            // Hack for log axis described above\n            var inAnchor = shapeIn[attrAnchor];\n            shapeIn[attrAnchor] = pos2r(shapeIn[attrAnchor], true);\n\n            Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attrAnchor, 0.25);\n\n            // Hack part 2\n            shapeOut[attrAnchor] = r2pos(shapeOut[attrAnchor]);\n            shapeIn[attrAnchor] = inAnchor;\n        }\n    }\n\n    if(shapeType === 'path') {\n        coerce('path');\n    } else {\n        Lib.noneOrAll(shapeIn, shapeOut, ['x0', 'x1', 'y0', 'y1']);\n    }\n}\n\n},{\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"../../plots/cartesian/axes\":767,\"./attributes\":669,\"./helpers\":674}],673:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Color = _dereq_('../color');\nvar Drawing = _dereq_('../drawing');\nvar arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;\n\nvar dragElement = _dereq_('../dragelement');\nvar setCursor = _dereq_('../../lib/setcursor');\n\nvar constants = _dereq_('./constants');\nvar helpers = _dereq_('./helpers');\n\n\n// Shapes are stored in gd.layout.shapes, an array of objects\n// index can point to one item in this array,\n//  or non-numeric to simply add a new one\n//  or -1 to modify all existing\n// opt can be the full options object, or one key (to be set to value)\n//  or undefined to simply redraw\n// if opt is blank, val can be 'add' or a full options object to add a new\n//  annotation at that point in the array, or 'remove' to delete this one\n\nmodule.exports = {\n    draw: draw,\n    drawOne: drawOne\n};\n\nfunction draw(gd) {\n    var fullLayout = gd._fullLayout;\n\n    // Remove previous shapes before drawing new in shapes in fullLayout.shapes\n    fullLayout._shapeUpperLayer.selectAll('path').remove();\n    fullLayout._shapeLowerLayer.selectAll('path').remove();\n\n    for(var k in fullLayout._plots) {\n        var shapelayer = fullLayout._plots[k].shapelayer;\n        if(shapelayer) shapelayer.selectAll('path').remove();\n    }\n\n    for(var i = 0; i < fullLayout.shapes.length; i++) {\n        if(fullLayout.shapes[i].visible) {\n            drawOne(gd, i);\n        }\n    }\n\n    // may need to resurrect this if we put text (LaTeX) in shapes\n    // return Plots.previousPromises(gd);\n}\n\nfunction drawOne(gd, index) {\n    // remove the existing shape if there is one.\n    // because indices can change, we need to look in all shape layers\n    gd._fullLayout._paperdiv\n        .selectAll('.shapelayer [data-index=\"' + index + '\"]')\n        .remove();\n\n    var options = gd._fullLayout.shapes[index] || {};\n\n    // this shape is gone - quit now after deleting it\n    // TODO: use d3 idioms instead of deleting and redrawing every time\n    if(!options._input || options.visible === false) return;\n\n    if(options.layer !== 'below') {\n        drawShape(gd._fullLayout._shapeUpperLayer);\n    } else if(options.xref === 'paper' || options.yref === 'paper') {\n        drawShape(gd._fullLayout._shapeLowerLayer);\n    } else {\n        var plotinfo = gd._fullLayout._plots[options.xref + options.yref];\n        if(plotinfo) {\n            var mainPlot = plotinfo.mainplotinfo || plotinfo;\n            drawShape(mainPlot.shapelayer);\n        } else {\n            // Fall back to _shapeLowerLayer in case the requested subplot doesn't exist.\n            // This can happen if you reference the shape to an x / y axis combination\n            // that doesn't have any data on it (and layer is below)\n            drawShape(gd._fullLayout._shapeLowerLayer);\n        }\n    }\n\n    function drawShape(shapeLayer) {\n        var attrs = {\n            'data-index': index,\n            'fill-rule': 'evenodd',\n            d: getPathString(gd, options)\n        };\n        var lineColor = options.line.width ? options.line.color : 'rgba(0,0,0,0)';\n\n        var path = shapeLayer.append('path')\n            .attr(attrs)\n            .style('opacity', options.opacity)\n            .call(Color.stroke, lineColor)\n            .call(Color.fill, options.fillcolor)\n            .call(Drawing.dashLine, options.line.dash, options.line.width);\n\n        setClipPath(path, gd, options);\n\n        if(gd._context.edits.shapePosition) setupDragElement(gd, path, options, index, shapeLayer);\n    }\n}\n\nfunction setClipPath(shapePath, gd, shapeOptions) {\n    // note that for layer=\"below\" the clipAxes can be different from the\n    // subplot we're drawing this in. This could cause problems if the shape\n    // spans two subplots. See https://github.com/plotly/plotly.js/issues/1452\n    var clipAxes = (shapeOptions.xref + shapeOptions.yref).replace(/paper/g, '');\n\n    Drawing.setClipUrl(\n        shapePath,\n        clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null,\n        gd\n    );\n}\n\nfunction setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) {\n    var MINWIDTH = 10;\n    var MINHEIGHT = 10;\n\n    var xPixelSized = shapeOptions.xsizemode === 'pixel';\n    var yPixelSized = shapeOptions.ysizemode === 'pixel';\n    var isLine = shapeOptions.type === 'line';\n    var isPath = shapeOptions.type === 'path';\n\n    var editHelpers = arrayEditor(gd.layout, 'shapes', shapeOptions);\n    var modifyItem = editHelpers.modifyItem;\n\n    var x0, y0, x1, y1, xAnchor, yAnchor;\n    var n0, s0, w0, e0, optN, optS, optW, optE;\n    var pathIn;\n\n    // setup conversion functions\n    var xa = Axes.getFromId(gd, shapeOptions.xref);\n    var ya = Axes.getFromId(gd, shapeOptions.yref);\n    var x2p = helpers.getDataToPixel(gd, xa);\n    var y2p = helpers.getDataToPixel(gd, ya, true);\n    var p2x = helpers.getPixelToData(gd, xa);\n    var p2y = helpers.getPixelToData(gd, ya, true);\n\n    var sensoryElement = obtainSensoryElement();\n    var dragOptions = {\n        element: sensoryElement.node(),\n        gd: gd,\n        prepFn: startDrag,\n        doneFn: endDrag,\n        clickFn: abortDrag\n    };\n    var dragMode;\n\n    dragElement.init(dragOptions);\n\n    sensoryElement.node().onmousemove = updateDragMode;\n\n    function obtainSensoryElement() {\n        return isLine ? createLineDragHandles() : shapePath;\n    }\n\n    function createLineDragHandles() {\n        var minSensoryWidth = 10;\n        var sensoryWidth = Math.max(shapeOptions.line.width, minSensoryWidth);\n\n        // Helper shapes group\n        // Note that by setting the `data-index` attr, it is ensured that\n        // the helper group is purged in this modules `draw` function\n        var g = shapeLayer.append('g')\n          .attr('data-index', index);\n\n        // Helper path for moving\n        g.append('path')\n          .attr('d', shapePath.attr('d'))\n          .style({\n              'cursor': 'move',\n              'stroke-width': sensoryWidth,\n              'stroke-opacity': '0' // ensure not visible\n          });\n\n        // Helper circles for resizing\n        var circleStyle = {\n            'fill-opacity': '0' // ensure not visible\n        };\n        var circleRadius = sensoryWidth / 2 > minSensoryWidth ? sensoryWidth / 2 : minSensoryWidth;\n\n        g.append('circle')\n          .attr({\n              'data-line-point': 'start-point',\n              'cx': xPixelSized ? x2p(shapeOptions.xanchor) + shapeOptions.x0 : x2p(shapeOptions.x0),\n              'cy': yPixelSized ? y2p(shapeOptions.yanchor) - shapeOptions.y0 : y2p(shapeOptions.y0),\n              'r': circleRadius\n          })\n          .style(circleStyle)\n          .classed('cursor-grab', true);\n\n        g.append('circle')\n          .attr({\n              'data-line-point': 'end-point',\n              'cx': xPixelSized ? x2p(shapeOptions.xanchor) + shapeOptions.x1 : x2p(shapeOptions.x1),\n              'cy': yPixelSized ? y2p(shapeOptions.yanchor) - shapeOptions.y1 : y2p(shapeOptions.y1),\n              'r': circleRadius\n          })\n          .style(circleStyle)\n          .classed('cursor-grab', true);\n\n        return g;\n    }\n\n    function updateDragMode(evt) {\n        if(isLine) {\n            if(evt.target.tagName === 'path') {\n                dragMode = 'move';\n            } else {\n                dragMode = evt.target.attributes['data-line-point'].value === 'start-point' ?\n                  'resize-over-start-point' : 'resize-over-end-point';\n            }\n        } else {\n            // element might not be on screen at time of setup,\n            // so obtain bounding box here\n            var dragBBox = dragOptions.element.getBoundingClientRect();\n\n            // choose 'move' or 'resize'\n            // based on initial position of cursor within the drag element\n            var w = dragBBox.right - dragBBox.left;\n            var h = dragBBox.bottom - dragBBox.top;\n            var x = evt.clientX - dragBBox.left;\n            var y = evt.clientY - dragBBox.top;\n            var cursor = (!isPath && w > MINWIDTH && h > MINHEIGHT && !evt.shiftKey) ?\n                dragElement.getCursor(x / w, 1 - y / h) :\n                'move';\n\n            setCursor(shapePath, cursor);\n\n            // possible values 'move', 'sw', 'w', 'se', 'e', 'ne', 'n', 'nw' and 'w'\n            dragMode = cursor.split('-')[0];\n        }\n    }\n\n    function startDrag(evt) {\n        // setup update strings and initial values\n        if(xPixelSized) {\n            xAnchor = x2p(shapeOptions.xanchor);\n        }\n        if(yPixelSized) {\n            yAnchor = y2p(shapeOptions.yanchor);\n        }\n\n        if(shapeOptions.type === 'path') {\n            pathIn = shapeOptions.path;\n        } else {\n            x0 = xPixelSized ? shapeOptions.x0 : x2p(shapeOptions.x0);\n            y0 = yPixelSized ? shapeOptions.y0 : y2p(shapeOptions.y0);\n            x1 = xPixelSized ? shapeOptions.x1 : x2p(shapeOptions.x1);\n            y1 = yPixelSized ? shapeOptions.y1 : y2p(shapeOptions.y1);\n        }\n\n        if(x0 < x1) {\n            w0 = x0;\n            optW = 'x0';\n            e0 = x1;\n            optE = 'x1';\n        } else {\n            w0 = x1;\n            optW = 'x1';\n            e0 = x0;\n            optE = 'x0';\n        }\n\n        // For fixed size shapes take opposing direction of y-axis into account.\n        // Hint: For data sized shapes this is done by the y2p function.\n        if((!yPixelSized && y0 < y1) || (yPixelSized && y0 > y1)) {\n            n0 = y0;\n            optN = 'y0';\n            s0 = y1;\n            optS = 'y1';\n        } else {\n            n0 = y1;\n            optN = 'y1';\n            s0 = y0;\n            optS = 'y0';\n        }\n\n        // setup dragMode and the corresponding handler\n        updateDragMode(evt);\n        renderVisualCues(shapeLayer, shapeOptions);\n        deactivateClipPathTemporarily(shapePath, shapeOptions, gd);\n        dragOptions.moveFn = (dragMode === 'move') ? moveShape : resizeShape;\n    }\n\n    function endDrag() {\n        setCursor(shapePath);\n        removeVisualCues(shapeLayer);\n\n        // Don't rely on clipPath being activated during re-layout\n        setClipPath(shapePath, gd, shapeOptions);\n        Registry.call('_guiRelayout', gd, editHelpers.getUpdateObj());\n    }\n\n    function abortDrag() {\n        removeVisualCues(shapeLayer);\n    }\n\n    function moveShape(dx, dy) {\n        if(shapeOptions.type === 'path') {\n            var noOp = function(coord) { return coord; };\n            var moveX = noOp;\n            var moveY = noOp;\n\n            if(xPixelSized) {\n                modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));\n            } else {\n                moveX = function moveX(x) { return p2x(x2p(x) + dx); };\n                if(xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);\n            }\n\n            if(yPixelSized) {\n                modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));\n            } else {\n                moveY = function moveY(y) { return p2y(y2p(y) + dy); };\n                if(ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);\n            }\n\n            modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));\n        } else {\n            if(xPixelSized) {\n                modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));\n            } else {\n                modifyItem('x0', shapeOptions.x0 = p2x(x0 + dx));\n                modifyItem('x1', shapeOptions.x1 = p2x(x1 + dx));\n            }\n\n            if(yPixelSized) {\n                modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));\n            } else {\n                modifyItem('y0', shapeOptions.y0 = p2y(y0 + dy));\n                modifyItem('y1', shapeOptions.y1 = p2y(y1 + dy));\n            }\n        }\n\n        shapePath.attr('d', getPathString(gd, shapeOptions));\n        renderVisualCues(shapeLayer, shapeOptions);\n    }\n\n    function resizeShape(dx, dy) {\n        if(isPath) {\n            // TODO: implement path resize, don't forget to update dragMode code\n            var noOp = function(coord) { return coord; };\n            var moveX = noOp;\n            var moveY = noOp;\n\n            if(xPixelSized) {\n                modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));\n            } else {\n                moveX = function moveX(x) { return p2x(x2p(x) + dx); };\n                if(xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);\n            }\n\n            if(yPixelSized) {\n                modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));\n            } else {\n                moveY = function moveY(y) { return p2y(y2p(y) + dy); };\n                if(ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);\n            }\n\n            modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));\n        } else if(isLine) {\n            if(dragMode === 'resize-over-start-point') {\n                var newX0 = x0 + dx;\n                var newY0 = yPixelSized ? y0 - dy : y0 + dy;\n                modifyItem('x0', shapeOptions.x0 = xPixelSized ? newX0 : p2x(newX0));\n                modifyItem('y0', shapeOptions.y0 = yPixelSized ? newY0 : p2y(newY0));\n            } else if(dragMode === 'resize-over-end-point') {\n                var newX1 = x1 + dx;\n                var newY1 = yPixelSized ? y1 - dy : y1 + dy;\n                modifyItem('x1', shapeOptions.x1 = xPixelSized ? newX1 : p2x(newX1));\n                modifyItem('y1', shapeOptions.y1 = yPixelSized ? newY1 : p2y(newY1));\n            }\n        } else {\n            var newN = (~dragMode.indexOf('n')) ? n0 + dy : n0;\n            var newS = (~dragMode.indexOf('s')) ? s0 + dy : s0;\n            var newW = (~dragMode.indexOf('w')) ? w0 + dx : w0;\n            var newE = (~dragMode.indexOf('e')) ? e0 + dx : e0;\n\n            // Do things in opposing direction for y-axis.\n            // Hint: for data-sized shapes the reversal of axis direction is done in p2y.\n            if(~dragMode.indexOf('n') && yPixelSized) newN = n0 - dy;\n            if(~dragMode.indexOf('s') && yPixelSized) newS = s0 - dy;\n\n            // Update shape eventually. Again, be aware of the\n            // opposing direction of the y-axis of fixed size shapes.\n            if((!yPixelSized && newS - newN > MINHEIGHT) ||\n              (yPixelSized && newN - newS > MINHEIGHT)) {\n                modifyItem(optN, shapeOptions[optN] = yPixelSized ? newN : p2y(newN));\n                modifyItem(optS, shapeOptions[optS] = yPixelSized ? newS : p2y(newS));\n            }\n            if(newE - newW > MINWIDTH) {\n                modifyItem(optW, shapeOptions[optW] = xPixelSized ? newW : p2x(newW));\n                modifyItem(optE, shapeOptions[optE] = xPixelSized ? newE : p2x(newE));\n            }\n        }\n\n        shapePath.attr('d', getPathString(gd, shapeOptions));\n        renderVisualCues(shapeLayer, shapeOptions);\n    }\n\n    function renderVisualCues(shapeLayer, shapeOptions) {\n        if(xPixelSized || yPixelSized) {\n            renderAnchor();\n        }\n\n        function renderAnchor() {\n            var isNotPath = shapeOptions.type !== 'path';\n\n            // d3 join with dummy data to satisfy d3 data-binding\n            var visualCues = shapeLayer.selectAll('.visual-cue').data([0]);\n\n            // Enter\n            var strokeWidth = 1;\n            visualCues.enter()\n              .append('path')\n              .attr({\n                  'fill': '#fff',\n                  'fill-rule': 'evenodd',\n                  'stroke': '#000',\n                  'stroke-width': strokeWidth\n              })\n              .classed('visual-cue', true);\n\n            // Update\n            var posX = x2p(\n              xPixelSized ?\n                shapeOptions.xanchor :\n                Lib.midRange(\n                  isNotPath ?\n                    [shapeOptions.x0, shapeOptions.x1] :\n                    helpers.extractPathCoords(shapeOptions.path, constants.paramIsX))\n            );\n            var posY = y2p(\n              yPixelSized ?\n                shapeOptions.yanchor :\n                Lib.midRange(\n                  isNotPath ?\n                    [shapeOptions.y0, shapeOptions.y1] :\n                    helpers.extractPathCoords(shapeOptions.path, constants.paramIsY))\n            );\n\n            posX = helpers.roundPositionForSharpStrokeRendering(posX, strokeWidth);\n            posY = helpers.roundPositionForSharpStrokeRendering(posY, strokeWidth);\n\n            if(xPixelSized && yPixelSized) {\n                var crossPath = 'M' + (posX - 1 - strokeWidth) + ',' + (posY - 1 - strokeWidth) +\n                  'h-8v2h8 v8h2v-8 h8v-2h-8 v-8h-2 Z';\n                visualCues.attr('d', crossPath);\n            } else if(xPixelSized) {\n                var vBarPath = 'M' + (posX - 1 - strokeWidth) + ',' + (posY - 9 - strokeWidth) +\n                  'v18 h2 v-18 Z';\n                visualCues.attr('d', vBarPath);\n            } else {\n                var hBarPath = 'M' + (posX - 9 - strokeWidth) + ',' + (posY - 1 - strokeWidth) +\n                  'h18 v2 h-18 Z';\n                visualCues.attr('d', hBarPath);\n            }\n        }\n    }\n\n    function removeVisualCues(shapeLayer) {\n        shapeLayer.selectAll('.visual-cue').remove();\n    }\n\n    function deactivateClipPathTemporarily(shapePath, shapeOptions, gd) {\n        var xref = shapeOptions.xref;\n        var yref = shapeOptions.yref;\n        var xa = Axes.getFromId(gd, xref);\n        var ya = Axes.getFromId(gd, yref);\n\n        var clipAxes = '';\n        if(xref !== 'paper' && !xa.autorange) clipAxes += xref;\n        if(yref !== 'paper' && !ya.autorange) clipAxes += yref;\n\n        Drawing.setClipUrl(\n            shapePath,\n            clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null,\n            gd\n        );\n    }\n}\n\nfunction getPathString(gd, options) {\n    var type = options.type;\n    var xa = Axes.getFromId(gd, options.xref);\n    var ya = Axes.getFromId(gd, options.yref);\n    var gs = gd._fullLayout._size;\n    var x2r, x2p, y2r, y2p;\n    var x0, x1, y0, y1;\n\n    if(xa) {\n        x2r = helpers.shapePositionToRange(xa);\n        x2p = function(v) { return xa._offset + xa.r2p(x2r(v, true)); };\n    } else {\n        x2p = function(v) { return gs.l + gs.w * v; };\n    }\n\n    if(ya) {\n        y2r = helpers.shapePositionToRange(ya);\n        y2p = function(v) { return ya._offset + ya.r2p(y2r(v, true)); };\n    } else {\n        y2p = function(v) { return gs.t + gs.h * (1 - v); };\n    }\n\n    if(type === 'path') {\n        if(xa && xa.type === 'date') x2p = helpers.decodeDate(x2p);\n        if(ya && ya.type === 'date') y2p = helpers.decodeDate(y2p);\n        return convertPath(options, x2p, y2p);\n    }\n\n    if(options.xsizemode === 'pixel') {\n        var xAnchorPos = x2p(options.xanchor);\n        x0 = xAnchorPos + options.x0;\n        x1 = xAnchorPos + options.x1;\n    } else {\n        x0 = x2p(options.x0);\n        x1 = x2p(options.x1);\n    }\n\n    if(options.ysizemode === 'pixel') {\n        var yAnchorPos = y2p(options.yanchor);\n        y0 = yAnchorPos - options.y0;\n        y1 = yAnchorPos - options.y1;\n    } else {\n        y0 = y2p(options.y0);\n        y1 = y2p(options.y1);\n    }\n\n    if(type === 'line') return 'M' + x0 + ',' + y0 + 'L' + x1 + ',' + y1;\n    if(type === 'rect') return 'M' + x0 + ',' + y0 + 'H' + x1 + 'V' + y1 + 'H' + x0 + 'Z';\n\n    // circle\n    var cx = (x0 + x1) / 2;\n    var cy = (y0 + y1) / 2;\n    var rx = Math.abs(cx - x0);\n    var ry = Math.abs(cy - y0);\n    var rArc = 'A' + rx + ',' + ry;\n    var rightPt = (cx + rx) + ',' + cy;\n    var topPt = cx + ',' + (cy - ry);\n    return 'M' + rightPt + rArc + ' 0 1,1 ' + topPt +\n        rArc + ' 0 0,1 ' + rightPt + 'Z';\n}\n\n\nfunction convertPath(options, x2p, y2p) {\n    var pathIn = options.path;\n    var xSizemode = options.xsizemode;\n    var ySizemode = options.ysizemode;\n    var xAnchor = options.xanchor;\n    var yAnchor = options.yanchor;\n\n    return pathIn.replace(constants.segmentRE, function(segment) {\n        var paramNumber = 0;\n        var segmentType = segment.charAt(0);\n        var xParams = constants.paramIsX[segmentType];\n        var yParams = constants.paramIsY[segmentType];\n        var nParams = constants.numParams[segmentType];\n\n        var paramString = segment.substr(1).replace(constants.paramRE, function(param) {\n            if(xParams[paramNumber]) {\n                if(xSizemode === 'pixel') param = x2p(xAnchor) + Number(param);\n                else param = x2p(param);\n            } else if(yParams[paramNumber]) {\n                if(ySizemode === 'pixel') param = y2p(yAnchor) - Number(param);\n                else param = y2p(param);\n            }\n            paramNumber++;\n\n            if(paramNumber > nParams) param = 'X';\n            return param;\n        });\n\n        if(paramNumber > nParams) {\n            paramString = paramString.replace(/[\\s,]*X.*/, '');\n            Lib.log('Ignoring extra params in segment ' + segment);\n        }\n\n        return segmentType + paramString;\n    });\n}\n\nfunction movePath(pathIn, moveX, moveY) {\n    return pathIn.replace(constants.segmentRE, function(segment) {\n        var paramNumber = 0;\n        var segmentType = segment.charAt(0);\n        var xParams = constants.paramIsX[segmentType];\n        var yParams = constants.paramIsY[segmentType];\n        var nParams = constants.numParams[segmentType];\n\n        var paramString = segment.substr(1).replace(constants.paramRE, function(param) {\n            if(paramNumber >= nParams) return param;\n\n            if(xParams[paramNumber]) param = moveX(param);\n            else if(yParams[paramNumber]) param = moveY(param);\n\n            paramNumber++;\n\n            return param;\n        });\n\n        return segmentType + paramString;\n    });\n}\n\n},{\"../../lib\":719,\"../../lib/setcursor\":739,\"../../plot_api/plot_template\":757,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"../color\":593,\"../dragelement\":611,\"../drawing\":614,\"./constants\":671,\"./helpers\":674}],674:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar constants = _dereq_('./constants');\n\nvar Lib = _dereq_('../../lib');\n\n// special position conversion functions... category axis positions can't be\n// specified by their data values, because they don't make a continuous mapping.\n// so these have to be specified in terms of the category serial numbers,\n// but can take fractional values. Other axis types we specify position based on\n// the actual data values.\n// TODO: in V2.0 (when log axis ranges are in data units) range and shape position\n// will be identical, so rangeToShapePosition and shapePositionToRange can be\n// removed entirely.\n\nexports.rangeToShapePosition = function(ax) {\n    return (ax.type === 'log') ? ax.r2d : function(v) { return v; };\n};\n\nexports.shapePositionToRange = function(ax) {\n    return (ax.type === 'log') ? ax.d2r : function(v) { return v; };\n};\n\nexports.decodeDate = function(convertToPx) {\n    return function(v) {\n        if(v.replace) v = v.replace('_', ' ');\n        return convertToPx(v);\n    };\n};\n\nexports.encodeDate = function(convertToDate) {\n    return function(v) { return convertToDate(v).replace(' ', '_'); };\n};\n\nexports.extractPathCoords = function(path, paramsToUse) {\n    var extractedCoordinates = [];\n\n    var segments = path.match(constants.segmentRE);\n    segments.forEach(function(segment) {\n        var relevantParamIdx = paramsToUse[segment.charAt(0)].drawn;\n        if(relevantParamIdx === undefined) return;\n\n        var params = segment.substr(1).match(constants.paramRE);\n        if(!params || params.length < relevantParamIdx) return;\n\n        extractedCoordinates.push(Lib.cleanNumber(params[relevantParamIdx]));\n    });\n\n    return extractedCoordinates;\n};\n\nexports.getDataToPixel = function(gd, axis, isVertical) {\n    var gs = gd._fullLayout._size;\n    var dataToPixel;\n\n    if(axis) {\n        var d2r = exports.shapePositionToRange(axis);\n\n        dataToPixel = function(v) {\n            return axis._offset + axis.r2p(d2r(v, true));\n        };\n\n        if(axis.type === 'date') dataToPixel = exports.decodeDate(dataToPixel);\n    } else if(isVertical) {\n        dataToPixel = function(v) { return gs.t + gs.h * (1 - v); };\n    } else {\n        dataToPixel = function(v) { return gs.l + gs.w * v; };\n    }\n\n    return dataToPixel;\n};\n\nexports.getPixelToData = function(gd, axis, isVertical) {\n    var gs = gd._fullLayout._size;\n    var pixelToData;\n\n    if(axis) {\n        var r2d = exports.rangeToShapePosition(axis);\n        pixelToData = function(p) { return r2d(axis.p2r(p - axis._offset)); };\n    } else if(isVertical) {\n        pixelToData = function(p) { return 1 - (p - gs.t) / gs.h; };\n    } else {\n        pixelToData = function(p) { return (p - gs.l) / gs.w; };\n    }\n\n    return pixelToData;\n};\n\n/**\n * Based on the given stroke width, rounds the passed\n * position value to represent either a full or half pixel.\n *\n * In case of an odd stroke width (e.g. 1), this measure ensures\n * that a stroke positioned at the returned position isn't rendered\n * blurry due to anti-aliasing.\n *\n * In case of an even stroke width (e.g. 2), this measure ensures\n * that the position value is transformed to a full pixel value\n * so that anti-aliasing doesn't take effect either.\n *\n * @param {number} pos The raw position value to be transformed\n * @param {number} strokeWidth The stroke width\n * @returns {number} either an integer or a .5 decimal number\n */\nexports.roundPositionForSharpStrokeRendering = function(pos, strokeWidth) {\n    var strokeWidthIsOdd = Math.round(strokeWidth % 2) === 1;\n    var posValAsInt = Math.round(pos);\n\n    return strokeWidthIsOdd ? posValAsInt + 0.5 : posValAsInt;\n};\n\n},{\"../../lib\":719,\"./constants\":671}],675:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar drawModule = _dereq_('./draw');\n\nmodule.exports = {\n    moduleType: 'component',\n    name: 'shapes',\n\n    layoutAttributes: _dereq_('./attributes'),\n    supplyLayoutDefaults: _dereq_('./defaults'),\n    includeBasePlot: _dereq_('../../plots/cartesian/include_components')('shapes'),\n\n    calcAutorange: _dereq_('./calc_autorange'),\n    draw: drawModule.draw,\n    drawOne: drawModule.drawOne\n};\n\n},{\"../../plots/cartesian/include_components\":777,\"./attributes\":669,\"./calc_autorange\":670,\"./defaults\":672,\"./draw\":673}],676:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar padAttrs = _dereq_('../../plots/pad_attributes');\nvar extendDeepAll = _dereq_('../../lib/extend').extendDeepAll;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar animationAttrs = _dereq_('../../plots/animation_attributes');\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\nvar constants = _dereq_('./constants');\n\nvar stepsAttrs = templatedArray('step', {\n    visible: {\n        valType: 'boolean',\n        \n        dflt: true,\n        \n    },\n    method: {\n        valType: 'enumerated',\n        values: ['restyle', 'relayout', 'animate', 'update', 'skip'],\n        dflt: 'restyle',\n        \n        \n    },\n    args: {\n        valType: 'info_array',\n        \n        freeLength: true,\n        items: [\n            { valType: 'any' },\n            { valType: 'any' },\n            { valType: 'any' }\n        ],\n        \n    },\n    label: {\n        valType: 'string',\n        \n        \n    },\n    value: {\n        valType: 'string',\n        \n        \n    },\n    execute: {\n        valType: 'boolean',\n        \n        dflt: true,\n        \n    }\n});\n\nmodule.exports = overrideAll(templatedArray('slider', {\n    visible: {\n        valType: 'boolean',\n        \n        dflt: true,\n        \n    },\n\n    active: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 0,\n        \n    },\n\n    steps: stepsAttrs,\n\n    lenmode: {\n        valType: 'enumerated',\n        values: ['fraction', 'pixels'],\n        \n        dflt: 'fraction',\n        \n    },\n    len: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        \n    },\n    x: {\n        valType: 'number',\n        min: -2,\n        max: 3,\n        dflt: 0,\n        \n        \n    },\n    pad: extendDeepAll(padAttrs({editType: 'arraydraw'}), {\n        \n    }, {t: {dflt: 20}}),\n    xanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'left', 'center', 'right'],\n        dflt: 'left',\n        \n        \n    },\n    y: {\n        valType: 'number',\n        min: -2,\n        max: 3,\n        dflt: 0,\n        \n        \n    },\n    yanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'top', 'middle', 'bottom'],\n        dflt: 'top',\n        \n        \n    },\n\n    transition: {\n        duration: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 150,\n            \n        },\n        easing: {\n            valType: 'enumerated',\n            values: animationAttrs.transition.easing.values,\n            \n            dflt: 'cubic-in-out',\n            \n        }\n    },\n\n    currentvalue: {\n        visible: {\n            valType: 'boolean',\n            \n            dflt: true,\n            \n        },\n\n        xanchor: {\n            valType: 'enumerated',\n            values: ['left', 'center', 'right'],\n            dflt: 'left',\n            \n            \n        },\n\n        offset: {\n            valType: 'number',\n            dflt: 10,\n            \n            \n        },\n\n        prefix: {\n            valType: 'string',\n            \n            \n        },\n\n        suffix: {\n            valType: 'string',\n            \n            \n        },\n\n        font: fontAttrs({\n            \n        })\n    },\n\n    font: fontAttrs({\n        \n    }),\n\n    activebgcolor: {\n        valType: 'color',\n        \n        dflt: constants.gripBgActiveColor,\n        \n    },\n    bgcolor: {\n        valType: 'color',\n        \n        dflt: constants.railBgColor,\n        \n    },\n    bordercolor: {\n        valType: 'color',\n        dflt: constants.railBorderColor,\n        \n        \n    },\n    borderwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: constants.railBorderWidth,\n        \n        \n    },\n    ticklen: {\n        valType: 'number',\n        min: 0,\n        dflt: constants.tickLength,\n        \n        \n    },\n    tickcolor: {\n        valType: 'color',\n        dflt: constants.tickColor,\n        \n        \n    },\n    tickwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        \n    },\n    minorticklen: {\n        valType: 'number',\n        min: 0,\n        dflt: constants.minorTickLength,\n        \n        \n    }\n}), 'arraydraw', 'from-root');\n\n},{\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plot_api/plot_template\":757,\"../../plots/animation_attributes\":762,\"../../plots/font_attributes\":793,\"../../plots/pad_attributes\":827,\"./constants\":677}],677:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nmodule.exports = {\n\n    // layout attribute name\n    name: 'sliders',\n\n    // class names\n    containerClassName: 'slider-container',\n    groupClassName: 'slider-group',\n    inputAreaClass: 'slider-input-area',\n    railRectClass: 'slider-rail-rect',\n    railTouchRectClass: 'slider-rail-touch-rect',\n    gripRectClass: 'slider-grip-rect',\n    tickRectClass: 'slider-tick-rect',\n    inputProxyClass: 'slider-input-proxy',\n    labelsClass: 'slider-labels',\n    labelGroupClass: 'slider-label-group',\n    labelClass: 'slider-label',\n    currentValueClass: 'slider-current-value',\n\n    railHeight: 5,\n\n    // DOM attribute name in button group keeping track\n    // of active update menu\n    menuIndexAttrName: 'slider-active-index',\n\n    // id root pass to Plots.autoMargin\n    autoMarginIdRoot: 'slider-',\n\n    // min item width / height\n    minWidth: 30,\n    minHeight: 30,\n\n    // padding around item text\n    textPadX: 40,\n\n    // arrow offset off right edge\n    arrowOffsetX: 4,\n\n    railRadius: 2,\n    railWidth: 5,\n    railBorder: 4,\n    railBorderWidth: 1,\n    railBorderColor: '#bec8d9',\n    railBgColor: '#f8fafc',\n\n    // The distance of the rail from the edge of the touchable area\n    // Slightly less than the step inset because of the curved edges\n    // of the rail\n    railInset: 8,\n\n    // The distance from the extremal tick marks to the edge of the\n    // touchable area. This is basically the same as the grip radius,\n    // but for other styles it wouldn't really need to be.\n    stepInset: 10,\n\n    gripRadius: 10,\n    gripWidth: 20,\n    gripHeight: 20,\n    gripBorder: 20,\n    gripBorderWidth: 1,\n    gripBorderColor: '#bec8d9',\n    gripBgColor: '#f6f8fa',\n    gripBgActiveColor: '#dbdde0',\n\n    labelPadding: 8,\n    labelOffset: 0,\n\n    tickWidth: 1,\n    tickColor: '#333',\n    tickOffset: 25,\n    tickLength: 7,\n\n    minorTickOffset: 25,\n    minorTickColor: '#333',\n    minorTickLength: 4,\n\n    // Extra space below the current value label:\n    currentValuePadding: 8,\n    currentValueInset: 0,\n};\n\n},{}],678:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nvar attributes = _dereq_('./attributes');\nvar constants = _dereq_('./constants');\n\nvar name = constants.name;\nvar stepAttrs = attributes.steps;\n\n\nmodule.exports = function slidersDefaults(layoutIn, layoutOut) {\n    handleArrayContainerDefaults(layoutIn, layoutOut, {\n        name: name,\n        handleItemDefaults: sliderDefaults\n    });\n};\n\nfunction sliderDefaults(sliderIn, sliderOut, layoutOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(sliderIn, sliderOut, attributes, attr, dflt);\n    }\n\n    var steps = handleArrayContainerDefaults(sliderIn, sliderOut, {\n        name: 'steps',\n        handleItemDefaults: stepDefaults\n    });\n\n    var stepCount = 0;\n    for(var i = 0; i < steps.length; i++) {\n        if(steps[i].visible) stepCount++;\n    }\n\n    var visible;\n    // If it has fewer than two options, it's not really a slider\n    if(stepCount < 2) visible = sliderOut.visible = false;\n    else visible = coerce('visible');\n    if(!visible) return;\n\n    sliderOut._stepCount = stepCount;\n    var visSteps = sliderOut._visibleSteps = Lib.filterVisible(steps);\n\n    var active = coerce('active');\n    if(!(steps[active] || {}).visible) sliderOut.active = visSteps[0]._index;\n\n    coerce('x');\n    coerce('y');\n    Lib.noneOrAll(sliderIn, sliderOut, ['x', 'y']);\n\n    coerce('xanchor');\n    coerce('yanchor');\n\n    coerce('len');\n    coerce('lenmode');\n\n    coerce('pad.t');\n    coerce('pad.r');\n    coerce('pad.b');\n    coerce('pad.l');\n\n    Lib.coerceFont(coerce, 'font', layoutOut.font);\n\n    var currentValueIsVisible = coerce('currentvalue.visible');\n\n    if(currentValueIsVisible) {\n        coerce('currentvalue.xanchor');\n        coerce('currentvalue.prefix');\n        coerce('currentvalue.suffix');\n        coerce('currentvalue.offset');\n\n        Lib.coerceFont(coerce, 'currentvalue.font', sliderOut.font);\n    }\n\n    coerce('transition.duration');\n    coerce('transition.easing');\n\n    coerce('bgcolor');\n    coerce('activebgcolor');\n    coerce('bordercolor');\n    coerce('borderwidth');\n    coerce('ticklen');\n    coerce('tickwidth');\n    coerce('tickcolor');\n    coerce('minorticklen');\n}\n\nfunction stepDefaults(valueIn, valueOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(valueIn, valueOut, stepAttrs, attr, dflt);\n    }\n\n    var visible;\n    if(valueIn.method !== 'skip' && !Array.isArray(valueIn.args)) {\n        visible = valueOut.visible = false;\n    } else visible = coerce('visible');\n\n    if(visible) {\n        coerce('method');\n        coerce('args');\n        var label = coerce('label', 'step-' + valueOut._index);\n        coerce('value', label);\n        coerce('execute');\n    }\n}\n\n},{\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"./attributes\":676,\"./constants\":677}],679:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Plots = _dereq_('../../plots/plots');\nvar Color = _dereq_('../color');\nvar Drawing = _dereq_('../drawing');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;\n\nvar constants = _dereq_('./constants');\nvar alignmentConstants = _dereq_('../../constants/alignment');\nvar LINE_SPACING = alignmentConstants.LINE_SPACING;\nvar FROM_TL = alignmentConstants.FROM_TL;\nvar FROM_BR = alignmentConstants.FROM_BR;\n\nmodule.exports = function draw(gd) {\n    var fullLayout = gd._fullLayout;\n    var sliderData = makeSliderData(fullLayout, gd);\n\n    // draw a container for *all* sliders:\n    var sliders = fullLayout._infolayer\n        .selectAll('g.' + constants.containerClassName)\n        .data(sliderData.length > 0 ? [0] : []);\n\n    sliders.enter().append('g')\n        .classed(constants.containerClassName, true)\n        .style('cursor', 'ew-resize');\n\n    function clearSlider(sliderOpts) {\n        if(sliderOpts._commandObserver) {\n            sliderOpts._commandObserver.remove();\n            delete sliderOpts._commandObserver;\n        }\n\n        // Most components don't need to explicitly remove autoMargin, because\n        // marginPushers does this - but slider updates don't go through\n        // a full replot so we need to explicitly remove it.\n        Plots.autoMargin(gd, autoMarginId(sliderOpts));\n    }\n\n    sliders.exit().each(function() {\n        d3.select(this).selectAll('g.' + constants.groupClassName)\n            .each(clearSlider);\n    })\n    .remove();\n\n    // Return early if no menus visible:\n    if(sliderData.length === 0) return;\n\n    var sliderGroups = sliders.selectAll('g.' + constants.groupClassName)\n        .data(sliderData, keyFunction);\n\n    sliderGroups.enter().append('g')\n        .classed(constants.groupClassName, true);\n\n    sliderGroups.exit()\n        .each(clearSlider)\n        .remove();\n\n    // Find the dimensions of the sliders:\n    for(var i = 0; i < sliderData.length; i++) {\n        var sliderOpts = sliderData[i];\n        findDimensions(gd, sliderOpts);\n    }\n\n    sliderGroups.each(function(sliderOpts) {\n        var gSlider = d3.select(this);\n\n        computeLabelSteps(sliderOpts);\n\n        Plots.manageCommandObserver(gd, sliderOpts, sliderOpts._visibleSteps, function(data) {\n            // NB: Same as below. This is *not* always the same as sliderOpts since\n            // if a new set of steps comes in, the reference in this callback would\n            // be invalid. We need to refetch it from the slider group, which is\n            // the join data that creates this slider. So if this slider still exists,\n            // the group should be valid, *to the best of my knowledge.* If not,\n            // we'd have to look it up by d3 data join index/key.\n            var opts = gSlider.data()[0];\n\n            if(opts.active === data.index) return;\n            if(opts._dragging) return;\n\n            setActive(gd, gSlider, opts, data.index, false, true);\n        });\n\n        drawSlider(gd, d3.select(this), sliderOpts);\n    });\n};\n\nfunction autoMarginId(sliderOpts) {\n    return constants.autoMarginIdRoot + sliderOpts._index;\n}\n\n// This really only just filters by visibility:\nfunction makeSliderData(fullLayout, gd) {\n    var contOpts = fullLayout[constants.name];\n    var sliderData = [];\n\n    for(var i = 0; i < contOpts.length; i++) {\n        var item = contOpts[i];\n        if(!item.visible) continue;\n        item._gd = gd;\n        sliderData.push(item);\n    }\n\n    return sliderData;\n}\n\n// This is set in the defaults step:\nfunction keyFunction(opts) {\n    return opts._index;\n}\n\n// Compute the dimensions (mutates sliderOpts):\nfunction findDimensions(gd, sliderOpts) {\n    var sliderLabels = Drawing.tester.selectAll('g.' + constants.labelGroupClass)\n        .data(sliderOpts._visibleSteps);\n\n    sliderLabels.enter().append('g')\n        .classed(constants.labelGroupClass, true);\n\n    // loop over fake buttons to find width / height\n    var maxLabelWidth = 0;\n    var labelHeight = 0;\n    sliderLabels.each(function(stepOpts) {\n        var labelGroup = d3.select(this);\n\n        var text = drawLabel(labelGroup, {step: stepOpts}, sliderOpts);\n\n        var textNode = text.node();\n        if(textNode) {\n            var bBox = Drawing.bBox(textNode);\n            labelHeight = Math.max(labelHeight, bBox.height);\n            maxLabelWidth = Math.max(maxLabelWidth, bBox.width);\n        }\n    });\n\n    sliderLabels.remove();\n\n    var dims = sliderOpts._dims = {};\n\n    dims.inputAreaWidth = Math.max(\n        constants.railWidth,\n        constants.gripHeight\n    );\n\n    // calculate some overall dimensions - some of these are needed for\n    // calculating the currentValue dimensions\n    var graphSize = gd._fullLayout._size;\n    dims.lx = graphSize.l + graphSize.w * sliderOpts.x;\n    dims.ly = graphSize.t + graphSize.h * (1 - sliderOpts.y);\n\n    if(sliderOpts.lenmode === 'fraction') {\n        // fraction:\n        dims.outerLength = Math.round(graphSize.w * sliderOpts.len);\n    } else {\n        // pixels:\n        dims.outerLength = sliderOpts.len;\n    }\n\n    // The length of the rail, *excluding* padding on either end:\n    dims.inputAreaStart = 0;\n    dims.inputAreaLength = Math.round(dims.outerLength - sliderOpts.pad.l - sliderOpts.pad.r);\n\n    var textableInputLength = dims.inputAreaLength - 2 * constants.stepInset;\n    var availableSpacePerLabel = textableInputLength / (sliderOpts._stepCount - 1);\n    var computedSpacePerLabel = maxLabelWidth + constants.labelPadding;\n    dims.labelStride = Math.max(1, Math.ceil(computedSpacePerLabel / availableSpacePerLabel));\n    dims.labelHeight = labelHeight;\n\n    // loop over all possible values for currentValue to find the\n    // area we need for it\n    dims.currentValueMaxWidth = 0;\n    dims.currentValueHeight = 0;\n    dims.currentValueTotalHeight = 0;\n    dims.currentValueMaxLines = 1;\n\n    if(sliderOpts.currentvalue.visible) {\n        // Get the dimensions of the current value label:\n        var dummyGroup = Drawing.tester.append('g');\n\n        sliderLabels.each(function(stepOpts) {\n            var curValPrefix = drawCurrentValue(dummyGroup, sliderOpts, stepOpts.label);\n            var curValSize = (curValPrefix.node() && Drawing.bBox(curValPrefix.node())) || {width: 0, height: 0};\n            var lines = svgTextUtils.lineCount(curValPrefix);\n            dims.currentValueMaxWidth = Math.max(dims.currentValueMaxWidth, Math.ceil(curValSize.width));\n            dims.currentValueHeight = Math.max(dims.currentValueHeight, Math.ceil(curValSize.height));\n            dims.currentValueMaxLines = Math.max(dims.currentValueMaxLines, lines);\n        });\n\n        dims.currentValueTotalHeight = dims.currentValueHeight + sliderOpts.currentvalue.offset;\n\n        dummyGroup.remove();\n    }\n\n    dims.height = dims.currentValueTotalHeight + constants.tickOffset + sliderOpts.ticklen + constants.labelOffset + dims.labelHeight + sliderOpts.pad.t + sliderOpts.pad.b;\n\n    var xanchor = 'left';\n    if(Lib.isRightAnchor(sliderOpts)) {\n        dims.lx -= dims.outerLength;\n        xanchor = 'right';\n    }\n    if(Lib.isCenterAnchor(sliderOpts)) {\n        dims.lx -= dims.outerLength / 2;\n        xanchor = 'center';\n    }\n\n    var yanchor = 'top';\n    if(Lib.isBottomAnchor(sliderOpts)) {\n        dims.ly -= dims.height;\n        yanchor = 'bottom';\n    }\n    if(Lib.isMiddleAnchor(sliderOpts)) {\n        dims.ly -= dims.height / 2;\n        yanchor = 'middle';\n    }\n\n    dims.outerLength = Math.ceil(dims.outerLength);\n    dims.height = Math.ceil(dims.height);\n    dims.lx = Math.round(dims.lx);\n    dims.ly = Math.round(dims.ly);\n\n    var marginOpts = {\n        y: sliderOpts.y,\n        b: dims.height * FROM_BR[yanchor],\n        t: dims.height * FROM_TL[yanchor]\n    };\n\n    if(sliderOpts.lenmode === 'fraction') {\n        marginOpts.l = 0;\n        marginOpts.xl = sliderOpts.x - sliderOpts.len * FROM_TL[xanchor];\n        marginOpts.r = 0;\n        marginOpts.xr = sliderOpts.x + sliderOpts.len * FROM_BR[xanchor];\n    } else {\n        marginOpts.x = sliderOpts.x;\n        marginOpts.l = dims.outerLength * FROM_TL[xanchor];\n        marginOpts.r = dims.outerLength * FROM_BR[xanchor];\n    }\n\n    Plots.autoMargin(gd, autoMarginId(sliderOpts), marginOpts);\n}\n\nfunction drawSlider(gd, sliderGroup, sliderOpts) {\n    // This is related to the other long notes in this file regarding what happens\n    // when slider steps disappear. This particular fix handles what happens when\n    // the *current* slider step is removed. The drawing functions will error out\n    // when they fail to find it, so the fix for now is that it will just draw the\n    // slider in the first position but will not execute the command.\n    if(!((sliderOpts.steps[sliderOpts.active] || {}).visible)) {\n        sliderOpts.active = sliderOpts._visibleSteps[0]._index;\n    }\n\n    // These are carefully ordered for proper z-ordering:\n    sliderGroup\n        .call(drawCurrentValue, sliderOpts)\n        .call(drawRail, sliderOpts)\n        .call(drawLabelGroup, sliderOpts)\n        .call(drawTicks, sliderOpts)\n        .call(drawTouchRect, gd, sliderOpts)\n        .call(drawGrip, gd, sliderOpts);\n\n    var dims = sliderOpts._dims;\n\n    // Position the rectangle:\n    Drawing.setTranslate(sliderGroup, dims.lx + sliderOpts.pad.l, dims.ly + sliderOpts.pad.t);\n\n    sliderGroup.call(setGripPosition, sliderOpts, false);\n    sliderGroup.call(drawCurrentValue, sliderOpts);\n}\n\nfunction drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {\n    if(!sliderOpts.currentvalue.visible) return;\n\n    var dims = sliderOpts._dims;\n    var x0, textAnchor;\n\n    switch(sliderOpts.currentvalue.xanchor) {\n        case 'right':\n            // This is anchored left and adjusted by the width of the longest label\n            // so that the prefix doesn't move. The goal of this is to emphasize\n            // what's actually changing and make the update less distracting.\n            x0 = dims.inputAreaLength - constants.currentValueInset - dims.currentValueMaxWidth;\n            textAnchor = 'left';\n            break;\n        case 'center':\n            x0 = dims.inputAreaLength * 0.5;\n            textAnchor = 'middle';\n            break;\n        default:\n            x0 = constants.currentValueInset;\n            textAnchor = 'left';\n    }\n\n    var text = Lib.ensureSingle(sliderGroup, 'text', constants.labelClass, function(s) {\n        s.classed('user-select-none', true)\n            .attr({\n                'text-anchor': textAnchor,\n                'data-notex': 1\n            });\n    });\n\n    var str = sliderOpts.currentvalue.prefix ? sliderOpts.currentvalue.prefix : '';\n\n    if(typeof valueOverride === 'string') {\n        str += valueOverride;\n    } else {\n        var curVal = sliderOpts.steps[sliderOpts.active].label;\n        var _meta = sliderOpts._gd._fullLayout._meta;\n        if(_meta) curVal = Lib.templateString(curVal, _meta);\n        str += curVal;\n    }\n\n    if(sliderOpts.currentvalue.suffix) {\n        str += sliderOpts.currentvalue.suffix;\n    }\n\n    text.call(Drawing.font, sliderOpts.currentvalue.font)\n        .text(str)\n        .call(svgTextUtils.convertToTspans, sliderOpts._gd);\n\n    var lines = svgTextUtils.lineCount(text);\n\n    var y0 = (dims.currentValueMaxLines + 1 - lines) *\n        sliderOpts.currentvalue.font.size * LINE_SPACING;\n\n    svgTextUtils.positionText(text, x0, y0);\n\n    return text;\n}\n\nfunction drawGrip(sliderGroup, gd, sliderOpts) {\n    var grip = Lib.ensureSingle(sliderGroup, 'rect', constants.gripRectClass, function(s) {\n        s.call(attachGripEvents, gd, sliderGroup, sliderOpts)\n            .style('pointer-events', 'all');\n    });\n\n    grip.attr({\n        width: constants.gripWidth,\n        height: constants.gripHeight,\n        rx: constants.gripRadius,\n        ry: constants.gripRadius,\n    })\n    .call(Color.stroke, sliderOpts.bordercolor)\n    .call(Color.fill, sliderOpts.bgcolor)\n    .style('stroke-width', sliderOpts.borderwidth + 'px');\n}\n\nfunction drawLabel(item, data, sliderOpts) {\n    var text = Lib.ensureSingle(item, 'text', constants.labelClass, function(s) {\n        s.classed('user-select-none', true)\n            .attr({\n                'text-anchor': 'middle',\n                'data-notex': 1\n            });\n    });\n\n    var tx = data.step.label;\n    var _meta = sliderOpts._gd._fullLayout._meta;\n    if(_meta) tx = Lib.templateString(tx, _meta);\n\n    text.call(Drawing.font, sliderOpts.font)\n        .text(tx)\n        .call(svgTextUtils.convertToTspans, sliderOpts._gd);\n\n    return text;\n}\n\nfunction drawLabelGroup(sliderGroup, sliderOpts) {\n    var labels = Lib.ensureSingle(sliderGroup, 'g', constants.labelsClass);\n    var dims = sliderOpts._dims;\n\n    var labelItems = labels.selectAll('g.' + constants.labelGroupClass)\n        .data(dims.labelSteps);\n\n    labelItems.enter().append('g')\n        .classed(constants.labelGroupClass, true);\n\n    labelItems.exit().remove();\n\n    labelItems.each(function(d) {\n        var item = d3.select(this);\n\n        item.call(drawLabel, d, sliderOpts);\n\n        Drawing.setTranslate(item,\n            normalizedValueToPosition(sliderOpts, d.fraction),\n            constants.tickOffset +\n                sliderOpts.ticklen +\n                // position is the baseline of the top line of text only, even\n                // if the label spans multiple lines\n                sliderOpts.font.size * LINE_SPACING +\n                constants.labelOffset +\n                dims.currentValueTotalHeight\n        );\n    });\n}\n\nfunction handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, doTransition) {\n    var quantizedPosition = Math.round(normalizedPosition * (sliderOpts._stepCount - 1));\n    var quantizedIndex = sliderOpts._visibleSteps[quantizedPosition]._index;\n\n    if(quantizedIndex !== sliderOpts.active) {\n        setActive(gd, sliderGroup, sliderOpts, quantizedIndex, true, doTransition);\n    }\n}\n\nfunction setActive(gd, sliderGroup, sliderOpts, index, doCallback, doTransition) {\n    var previousActive = sliderOpts.active;\n    sliderOpts.active = index;\n\n    // due to templating, it's possible this slider doesn't even exist yet\n    arrayEditor(gd.layout, constants.name, sliderOpts)\n        .applyUpdate('active', index);\n\n    var step = sliderOpts.steps[sliderOpts.active];\n\n    sliderGroup.call(setGripPosition, sliderOpts, doTransition);\n    sliderGroup.call(drawCurrentValue, sliderOpts);\n\n    gd.emit('plotly_sliderchange', {\n        slider: sliderOpts,\n        step: sliderOpts.steps[sliderOpts.active],\n        interaction: doCallback,\n        previousActive: previousActive\n    });\n\n    if(step && step.method && doCallback) {\n        if(sliderGroup._nextMethod) {\n            // If we've already queued up an update, just overwrite it with the most recent:\n            sliderGroup._nextMethod.step = step;\n            sliderGroup._nextMethod.doCallback = doCallback;\n            sliderGroup._nextMethod.doTransition = doTransition;\n        } else {\n            sliderGroup._nextMethod = {step: step, doCallback: doCallback, doTransition: doTransition};\n            sliderGroup._nextMethodRaf = window.requestAnimationFrame(function() {\n                var _step = sliderGroup._nextMethod.step;\n                if(!_step.method) return;\n\n                if(_step.execute) {\n                    Plots.executeAPICommand(gd, _step.method, _step.args);\n                }\n\n                sliderGroup._nextMethod = null;\n                sliderGroup._nextMethodRaf = null;\n            });\n        }\n    }\n}\n\nfunction attachGripEvents(item, gd, sliderGroup) {\n    var node = sliderGroup.node();\n    var $gd = d3.select(gd);\n\n    // NB: This is *not* the same as sliderOpts itself! These callbacks\n    // are in a closure so this array won't actually be correct if the\n    // steps have changed since this was initialized. The sliderGroup,\n    // however, has not changed since that *is* the slider, so it must\n    // be present to receive mouse events.\n    function getSliderOpts() {\n        return sliderGroup.data()[0];\n    }\n\n    item.on('mousedown', function() {\n        var sliderOpts = getSliderOpts();\n        gd.emit('plotly_sliderstart', {slider: sliderOpts});\n\n        var grip = sliderGroup.select('.' + constants.gripRectClass);\n\n        d3.event.stopPropagation();\n        d3.event.preventDefault();\n        grip.call(Color.fill, sliderOpts.activebgcolor);\n\n        var normalizedPosition = positionToNormalizedValue(sliderOpts, d3.mouse(node)[0]);\n        handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, true);\n        sliderOpts._dragging = true;\n\n        $gd.on('mousemove', function() {\n            var sliderOpts = getSliderOpts();\n            var normalizedPosition = positionToNormalizedValue(sliderOpts, d3.mouse(node)[0]);\n            handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, false);\n        });\n\n        $gd.on('mouseup', function() {\n            var sliderOpts = getSliderOpts();\n            sliderOpts._dragging = false;\n            grip.call(Color.fill, sliderOpts.bgcolor);\n            $gd.on('mouseup', null);\n            $gd.on('mousemove', null);\n\n            gd.emit('plotly_sliderend', {\n                slider: sliderOpts,\n                step: sliderOpts.steps[sliderOpts.active]\n            });\n        });\n    });\n}\n\nfunction drawTicks(sliderGroup, sliderOpts) {\n    var tick = sliderGroup.selectAll('rect.' + constants.tickRectClass)\n        .data(sliderOpts._visibleSteps);\n    var dims = sliderOpts._dims;\n\n    tick.enter().append('rect')\n        .classed(constants.tickRectClass, true);\n\n    tick.exit().remove();\n\n    tick.attr({\n        width: sliderOpts.tickwidth + 'px',\n        'shape-rendering': 'crispEdges'\n    });\n\n    tick.each(function(d, i) {\n        var isMajor = i % dims.labelStride === 0;\n        var item = d3.select(this);\n\n        item\n            .attr({height: isMajor ? sliderOpts.ticklen : sliderOpts.minorticklen})\n            .call(Color.fill, isMajor ? sliderOpts.tickcolor : sliderOpts.tickcolor);\n\n        Drawing.setTranslate(item,\n            normalizedValueToPosition(sliderOpts, i / (sliderOpts._stepCount - 1)) - 0.5 * sliderOpts.tickwidth,\n            (isMajor ? constants.tickOffset : constants.minorTickOffset) + dims.currentValueTotalHeight\n        );\n    });\n}\n\nfunction computeLabelSteps(sliderOpts) {\n    var dims = sliderOpts._dims;\n    dims.labelSteps = [];\n    var nsteps = sliderOpts._stepCount;\n\n    for(var i = 0; i < nsteps; i += dims.labelStride) {\n        dims.labelSteps.push({\n            fraction: i / (nsteps - 1),\n            step: sliderOpts._visibleSteps[i]\n        });\n    }\n}\n\nfunction setGripPosition(sliderGroup, sliderOpts, doTransition) {\n    var grip = sliderGroup.select('rect.' + constants.gripRectClass);\n\n    var quantizedIndex = 0;\n    for(var i = 0; i < sliderOpts._stepCount; i++) {\n        if(sliderOpts._visibleSteps[i]._index === sliderOpts.active) {\n            quantizedIndex = i;\n            break;\n        }\n    }\n\n    var x = normalizedValueToPosition(sliderOpts, quantizedIndex / (sliderOpts._stepCount - 1));\n\n    // If this is true, then *this component* is already invoking its own command\n    // and has triggered its own animation.\n    if(sliderOpts._invokingCommand) return;\n\n    var el = grip;\n    if(doTransition && sliderOpts.transition.duration > 0) {\n        el = el.transition()\n            .duration(sliderOpts.transition.duration)\n            .ease(sliderOpts.transition.easing);\n    }\n\n    // Drawing.setTranslate doesn't work here becasue of the transition duck-typing.\n    // It's also not necessary because there are no other transitions to preserve.\n    el.attr('transform', 'translate(' + (x - constants.gripWidth * 0.5) + ',' + (sliderOpts._dims.currentValueTotalHeight) + ')');\n}\n\n// Convert a number from [0-1] to a pixel position relative to the slider group container:\nfunction normalizedValueToPosition(sliderOpts, normalizedPosition) {\n    var dims = sliderOpts._dims;\n    return dims.inputAreaStart + constants.stepInset +\n        (dims.inputAreaLength - 2 * constants.stepInset) * Math.min(1, Math.max(0, normalizedPosition));\n}\n\n// Convert a position relative to the slider group to a nubmer in [0, 1]\nfunction positionToNormalizedValue(sliderOpts, position) {\n    var dims = sliderOpts._dims;\n    return Math.min(1, Math.max(0, (position - constants.stepInset - dims.inputAreaStart) / (dims.inputAreaLength - 2 * constants.stepInset - 2 * dims.inputAreaStart)));\n}\n\nfunction drawTouchRect(sliderGroup, gd, sliderOpts) {\n    var dims = sliderOpts._dims;\n    var rect = Lib.ensureSingle(sliderGroup, 'rect', constants.railTouchRectClass, function(s) {\n        s.call(attachGripEvents, gd, sliderGroup, sliderOpts)\n            .style('pointer-events', 'all');\n    });\n\n    rect.attr({\n        width: dims.inputAreaLength,\n        height: Math.max(dims.inputAreaWidth, constants.tickOffset + sliderOpts.ticklen + dims.labelHeight)\n    })\n        .call(Color.fill, sliderOpts.bgcolor)\n        .attr('opacity', 0);\n\n    Drawing.setTranslate(rect, 0, dims.currentValueTotalHeight);\n}\n\nfunction drawRail(sliderGroup, sliderOpts) {\n    var dims = sliderOpts._dims;\n    var computedLength = dims.inputAreaLength - constants.railInset * 2;\n    var rect = Lib.ensureSingle(sliderGroup, 'rect', constants.railRectClass);\n\n    rect.attr({\n        width: computedLength,\n        height: constants.railWidth,\n        rx: constants.railRadius,\n        ry: constants.railRadius,\n        'shape-rendering': 'crispEdges'\n    })\n    .call(Color.stroke, sliderOpts.bordercolor)\n    .call(Color.fill, sliderOpts.bgcolor)\n    .style('stroke-width', sliderOpts.borderwidth + 'px');\n\n    Drawing.setTranslate(rect,\n        constants.railInset,\n        (dims.inputAreaWidth - constants.railWidth) * 0.5 + dims.currentValueTotalHeight\n    );\n}\n\n},{\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plot_api/plot_template\":757,\"../../plots/plots\":828,\"../color\":593,\"../drawing\":614,\"./constants\":677,\"d3\":163}],680:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar constants = _dereq_('./constants');\n\nmodule.exports = {\n    moduleType: 'component',\n    name: constants.name,\n\n    layoutAttributes: _dereq_('./attributes'),\n    supplyLayoutDefaults: _dereq_('./defaults'),\n\n    draw: _dereq_('./draw')\n};\n\n},{\"./attributes\":676,\"./constants\":677,\"./defaults\":678,\"./draw\":679}],681:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Plots = _dereq_('../../plots/plots');\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../drawing');\nvar Color = _dereq_('../color');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar interactConstants = _dereq_('../../constants/interactions');\n\nmodule.exports = {\n    draw: draw\n};\n\nvar numStripRE = / [XY][0-9]* /;\n\n/**\n * Titles - (re)draw titles on the axes and plot:\n * @param {DOM element} gd - the graphDiv\n * @param {string} titleClass - the css class of this title\n * @param {object} options - how and what to draw\n *      propContainer - the layout object containing `title` and `titlefont`\n *          attributes that apply to this title\n *      propName - the full name of the title property (for Plotly.relayout)\n *      [traceIndex] - include only if this property applies to one trace\n *          (such as a colorbar title) - then editing pipes to Plotly.restyle\n *          instead of Plotly.relayout\n *      placeholder - placeholder text for an empty editable title\n *      [avoid] {object} - include if this title should move to avoid other elements\n *          selection - d3 selection of elements to avoid\n *          side - which direction to move if there is a conflict\n *          [offsetLeft] - if these elements are subject to a translation\n *              wrt the title element\n *          [offsetTop]\n *      attributes {object} - position and alignment attributes\n *          x - pixels\n *          y - pixels\n *          text-anchor - start|middle|end\n *      transform {object} - how to transform the title after positioning\n *          rotate - degrees\n *          offset - shift up/down in the rotated frame (unused?)\n *      containerGroup - if an svg <g> element already exists to hold this\n *          title, include here. Otherwise it will go in fullLayout._infolayer\n *      _meta {object (optional} - meta key-value to for title with\n *          Lib.templateString, default to fullLayout._meta, if not provided\n *\n *  @return {selection} d3 selection of title container group\n */\nfunction draw(gd, titleClass, options) {\n    var cont = options.propContainer;\n    var prop = options.propName;\n    var placeholder = options.placeholder;\n    var traceIndex = options.traceIndex;\n    var avoid = options.avoid || {};\n    var attributes = options.attributes;\n    var transform = options.transform;\n    var group = options.containerGroup;\n\n    var fullLayout = gd._fullLayout;\n\n    var opacity = 1;\n    var isplaceholder = false;\n    var title = cont.title;\n    var txt = (title && title.text ? title.text : '').trim();\n\n    var font = title && title.font ? title.font : {};\n    var fontFamily = font.family;\n    var fontSize = font.size;\n    var fontColor = font.color;\n\n    // only make this title editable if we positively identify its property\n    // as one that has editing enabled.\n    var editAttr;\n    if(prop === 'title.text') editAttr = 'titleText';\n    else if(prop.indexOf('axis') !== -1) editAttr = 'axisTitleText';\n    else if(prop.indexOf('colorbar' !== -1)) editAttr = 'colorbarTitleText';\n    var editable = gd._context.edits[editAttr];\n\n    if(txt === '') opacity = 0;\n    // look for placeholder text while stripping out numbers from eg X2, Y3\n    // this is just for backward compatibility with the old version that had\n    // \"Click to enter X2 title\" and may have gotten saved in some old plots,\n    // we don't want this to show up when these are displayed.\n    else if(txt.replace(numStripRE, ' % ') === placeholder.replace(numStripRE, ' % ')) {\n        opacity = 0.2;\n        isplaceholder = true;\n        if(!editable) txt = '';\n    }\n\n    if(options._meta) {\n        txt = Lib.templateString(txt, options._meta);\n    } else if(fullLayout._meta) {\n        txt = Lib.templateString(txt, fullLayout._meta);\n    }\n\n    var elShouldExist = txt || editable;\n\n    if(!group) {\n        group = Lib.ensureSingle(fullLayout._infolayer, 'g', 'g-' + titleClass);\n    }\n\n    var el = group.selectAll('text')\n        .data(elShouldExist ? [0] : []);\n    el.enter().append('text');\n    el.text(txt)\n        // this is hacky, but convertToTspans uses the class\n        // to determine whether to rotate mathJax...\n        // so we need to clear out any old class and put the\n        // correct one (only relevant for colorbars, at least\n        // for now) - ie don't use .classed\n        .attr('class', titleClass);\n    el.exit().remove();\n\n    if(!elShouldExist) return group;\n\n    function titleLayout(titleEl) {\n        Lib.syncOrAsync([drawTitle, scootTitle], titleEl);\n    }\n\n    function drawTitle(titleEl) {\n        var transformVal;\n\n        if(transform) {\n            transformVal = '';\n            if(transform.rotate) {\n                transformVal += 'rotate(' + [transform.rotate, attributes.x, attributes.y] + ')';\n            }\n            if(transform.offset) {\n                transformVal += 'translate(0, ' + transform.offset + ')';\n            }\n        } else {\n            transformVal = null;\n        }\n\n        titleEl.attr('transform', transformVal);\n\n        titleEl.style({\n            'font-family': fontFamily,\n            'font-size': d3.round(fontSize, 2) + 'px',\n            fill: Color.rgb(fontColor),\n            opacity: opacity * Color.opacity(fontColor),\n            'font-weight': Plots.fontWeight\n        })\n        .attr(attributes)\n        .call(svgTextUtils.convertToTspans, gd);\n\n        return Plots.previousPromises(gd);\n    }\n\n    function scootTitle(titleElIn) {\n        var titleGroup = d3.select(titleElIn.node().parentNode);\n\n        if(avoid && avoid.selection && avoid.side && txt) {\n            titleGroup.attr('transform', null);\n\n            // move toward avoid.side (= left, right, top, bottom) if needed\n            // can include pad (pixels, default 2)\n            var shift = 0;\n            var backside = {\n                left: 'right',\n                right: 'left',\n                top: 'bottom',\n                bottom: 'top'\n            }[avoid.side];\n            var shiftSign = (['left', 'top'].indexOf(avoid.side) !== -1) ?\n                    -1 : 1;\n            var pad = isNumeric(avoid.pad) ? avoid.pad : 2;\n            var titlebb = Drawing.bBox(titleGroup.node());\n            var paperbb = {\n                left: 0,\n                top: 0,\n                right: fullLayout.width,\n                bottom: fullLayout.height\n            };\n            var maxshift = avoid.maxShift || (\n                (paperbb[avoid.side] - titlebb[avoid.side]) *\n                ((avoid.side === 'left' || avoid.side === 'top') ? -1 : 1));\n            // Prevent the title going off the paper\n            if(maxshift < 0) shift = maxshift;\n            else {\n                // so we don't have to offset each avoided element,\n                // give the title the opposite offset\n                var offsetLeft = avoid.offsetLeft || 0;\n                var offsetTop = avoid.offsetTop || 0;\n                titlebb.left -= offsetLeft;\n                titlebb.right -= offsetLeft;\n                titlebb.top -= offsetTop;\n                titlebb.bottom -= offsetTop;\n\n                // iterate over a set of elements (avoid.selection)\n                // to avoid collisions with\n                avoid.selection.each(function() {\n                    var avoidbb = Drawing.bBox(this);\n\n                    if(Lib.bBoxIntersect(titlebb, avoidbb, pad)) {\n                        shift = Math.max(shift, shiftSign * (\n                            avoidbb[avoid.side] - titlebb[backside]) + pad);\n                    }\n                });\n                shift = Math.min(maxshift, shift);\n            }\n            if(shift > 0 || maxshift < 0) {\n                var shiftTemplate = {\n                    left: [-shift, 0],\n                    right: [shift, 0],\n                    top: [0, -shift],\n                    bottom: [0, shift]\n                }[avoid.side];\n                titleGroup.attr('transform',\n                    'translate(' + shiftTemplate + ')');\n            }\n        }\n    }\n\n    el.call(titleLayout);\n\n    function setPlaceholder() {\n        opacity = 0;\n        isplaceholder = true;\n        el.text(placeholder)\n            .on('mouseover.opacity', function() {\n                d3.select(this).transition()\n                    .duration(interactConstants.SHOW_PLACEHOLDER).style('opacity', 1);\n            })\n            .on('mouseout.opacity', function() {\n                d3.select(this).transition()\n                    .duration(interactConstants.HIDE_PLACEHOLDER).style('opacity', 0);\n            });\n    }\n\n    if(editable) {\n        if(!txt) setPlaceholder();\n        else el.on('.opacity', null);\n\n        el.call(svgTextUtils.makeEditable, {gd: gd})\n            .on('edit', function(text) {\n                if(traceIndex !== undefined) {\n                    Registry.call('_guiRestyle', gd, prop, text, traceIndex);\n                } else {\n                    Registry.call('_guiRelayout', gd, prop, text);\n                }\n            })\n            .on('cancel', function() {\n                this.text(this.attr('data-unformatted'))\n                    .call(titleLayout);\n            })\n            .on('input', function(d) {\n                this.text(d || ' ')\n                    .call(svgTextUtils.positionText, attributes.x, attributes.y);\n            });\n    }\n    el.classed('js-placeholder', isplaceholder);\n\n    return group;\n}\n\n},{\"../../constants/interactions\":694,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plots/plots\":828,\"../../registry\":847,\"../color\":593,\"../drawing\":614,\"d3\":163,\"fast-isnumeric\":225}],682:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar colorAttrs = _dereq_('../color/attributes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar padAttrs = _dereq_('../../plots/pad_attributes');\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\nvar buttonsAttrs = templatedArray('button', {\n    visible: {\n        valType: 'boolean',\n        \n        \n    },\n    method: {\n        valType: 'enumerated',\n        values: ['restyle', 'relayout', 'animate', 'update', 'skip'],\n        dflt: 'restyle',\n        \n        \n    },\n    args: {\n        valType: 'info_array',\n        \n        freeLength: true,\n        items: [\n            {valType: 'any'},\n            {valType: 'any'},\n            {valType: 'any'}\n        ],\n        \n    },\n    label: {\n        valType: 'string',\n        \n        dflt: '',\n        \n    },\n    execute: {\n        valType: 'boolean',\n        \n        dflt: true,\n        \n    }\n});\n\nmodule.exports = overrideAll(templatedArray('updatemenu', {\n    _arrayAttrRegexps: [/^updatemenus\\[(0|[1-9][0-9]+)\\]\\.buttons/],\n\n    visible: {\n        valType: 'boolean',\n        \n        \n    },\n\n    type: {\n        valType: 'enumerated',\n        values: ['dropdown', 'buttons'],\n        dflt: 'dropdown',\n        \n        \n    },\n\n    direction: {\n        valType: 'enumerated',\n        values: ['left', 'right', 'up', 'down'],\n        dflt: 'down',\n        \n        \n    },\n\n    active: {\n        valType: 'integer',\n        \n        min: -1,\n        dflt: 0,\n        \n    },\n\n    showactive: {\n        valType: 'boolean',\n        \n        dflt: true,\n        \n    },\n\n    buttons: buttonsAttrs,\n\n    x: {\n        valType: 'number',\n        min: -2,\n        max: 3,\n        dflt: -0.05,\n        \n        \n    },\n    xanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'left', 'center', 'right'],\n        dflt: 'right',\n        \n        \n    },\n    y: {\n        valType: 'number',\n        min: -2,\n        max: 3,\n        dflt: 1,\n        \n        \n    },\n    yanchor: {\n        valType: 'enumerated',\n        values: ['auto', 'top', 'middle', 'bottom'],\n        dflt: 'top',\n        \n        \n    },\n\n    pad: extendFlat(padAttrs({editType: 'arraydraw'}), {\n        \n    }),\n\n    font: fontAttrs({\n        \n    }),\n\n    bgcolor: {\n        valType: 'color',\n        \n        \n    },\n    bordercolor: {\n        valType: 'color',\n        dflt: colorAttrs.borderLine,\n        \n        \n    },\n    borderwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'arraydraw',\n        \n    }\n}), 'arraydraw', 'from-root');\n\n},{\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plot_api/plot_template\":757,\"../../plots/font_attributes\":793,\"../../plots/pad_attributes\":827,\"../color/attributes\":592}],683:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nmodule.exports = {\n\n    // layout attribute name\n    name: 'updatemenus',\n\n    // class names\n    containerClassName: 'updatemenu-container',\n    headerGroupClassName: 'updatemenu-header-group',\n    headerClassName: 'updatemenu-header',\n    headerArrowClassName: 'updatemenu-header-arrow',\n    dropdownButtonGroupClassName: 'updatemenu-dropdown-button-group',\n    dropdownButtonClassName: 'updatemenu-dropdown-button',\n    buttonClassName: 'updatemenu-button',\n    itemRectClassName: 'updatemenu-item-rect',\n    itemTextClassName: 'updatemenu-item-text',\n\n    // DOM attribute name in button group keeping track\n    // of active update menu\n    menuIndexAttrName: 'updatemenu-active-index',\n\n    // id root pass to Plots.autoMargin\n    autoMarginIdRoot: 'updatemenu-',\n\n    // options when 'active: -1'\n    blankHeaderOpts: { label: '  ' },\n\n    // min item width / height\n    minWidth: 30,\n    minHeight: 30,\n\n    // padding around item text\n    textPadX: 24,\n    arrowPadX: 16,\n\n    // item rect radii\n    rx: 2,\n    ry: 2,\n\n    // item  text x offset off left edge\n    textOffsetX: 12,\n\n    // item  text y offset (w.r.t. middle)\n    textOffsetY: 3,\n\n    // arrow offset off right edge\n    arrowOffsetX: 4,\n\n    // gap between header and buttons\n    gapButtonHeader: 5,\n\n    // gap between between buttons\n    gapButton: 2,\n\n    // color given to active buttons\n    activeColor: '#F4FAFF',\n\n    // color given to hovered buttons\n    hoverColor: '#F4FAFF',\n\n    // symbol for menu open arrow\n    arrowSymbol: {\n        left: '◄',\n        right: '►',\n        up: '▲',\n        down: '▼'\n    }\n};\n\n},{}],684:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nvar attributes = _dereq_('./attributes');\nvar constants = _dereq_('./constants');\n\nvar name = constants.name;\nvar buttonAttrs = attributes.buttons;\n\n\nmodule.exports = function updateMenusDefaults(layoutIn, layoutOut) {\n    var opts = {\n        name: name,\n        handleItemDefaults: menuDefaults\n    };\n\n    handleArrayContainerDefaults(layoutIn, layoutOut, opts);\n};\n\nfunction menuDefaults(menuIn, menuOut, layoutOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(menuIn, menuOut, attributes, attr, dflt);\n    }\n\n    var buttons = handleArrayContainerDefaults(menuIn, menuOut, {\n        name: 'buttons',\n        handleItemDefaults: buttonDefaults\n    });\n\n    var visible = coerce('visible', buttons.length > 0);\n    if(!visible) return;\n\n    coerce('active');\n    coerce('direction');\n    coerce('type');\n    coerce('showactive');\n\n    coerce('x');\n    coerce('y');\n    Lib.noneOrAll(menuIn, menuOut, ['x', 'y']);\n\n    coerce('xanchor');\n    coerce('yanchor');\n\n    coerce('pad.t');\n    coerce('pad.r');\n    coerce('pad.b');\n    coerce('pad.l');\n\n    Lib.coerceFont(coerce, 'font', layoutOut.font);\n\n    coerce('bgcolor', layoutOut.paper_bgcolor);\n    coerce('bordercolor');\n    coerce('borderwidth');\n}\n\nfunction buttonDefaults(buttonIn, buttonOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(buttonIn, buttonOut, buttonAttrs, attr, dflt);\n    }\n\n    var visible = coerce('visible',\n        (buttonIn.method === 'skip' || Array.isArray(buttonIn.args)));\n    if(visible) {\n        coerce('method');\n        coerce('args');\n        coerce('label');\n        coerce('execute');\n    }\n}\n\n},{\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"./attributes\":682,\"./constants\":683}],685:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Plots = _dereq_('../../plots/plots');\nvar Color = _dereq_('../color');\nvar Drawing = _dereq_('../drawing');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;\n\nvar LINE_SPACING = _dereq_('../../constants/alignment').LINE_SPACING;\n\nvar constants = _dereq_('./constants');\nvar ScrollBox = _dereq_('./scrollbox');\n\nmodule.exports = function draw(gd) {\n    var fullLayout = gd._fullLayout;\n    var menuData = Lib.filterVisible(fullLayout[constants.name]);\n\n    /* Update menu data is bound to the header-group.\n     * The items in the header group are always present.\n     *\n     * Upon clicking on a header its corresponding button\n     * data is bound to the button-group.\n     *\n     * We draw all headers in one group before all buttons\n     * so that the buttons *always* appear above the headers.\n     *\n     * Note that only one set of buttons are visible at once.\n     *\n     * <g container />\n     *\n     *     <g header-group />\n     *         <g item header />\n     *         <text item header-arrow />\n     *     <g header-group />\n     *         <g item header />\n     *         <text item header-arrow />\n     *     ...\n     *\n     *     <g button-group />\n     *         <g item button />\n     *         <g item button />\n     *         ...\n     */\n\n    function clearAutoMargin(menuOpts) {\n        Plots.autoMargin(gd, autoMarginId(menuOpts));\n    }\n\n    // draw update menu container\n    var menus = fullLayout._menulayer\n        .selectAll('g.' + constants.containerClassName)\n        .data(menuData.length > 0 ? [0] : []);\n\n    menus.enter().append('g')\n        .classed(constants.containerClassName, true)\n        .style('cursor', 'pointer');\n\n    menus.exit().each(function() {\n        // Most components don't need to explicitly remove autoMargin, because\n        // marginPushers does this - but updatemenu updates don't go through\n        // a full replot so we need to explicitly remove it.\n        // This is for removing *all* updatemenus, removing individuals is\n        // handled below, in headerGroups.exit\n        d3.select(this).selectAll('g.' + constants.headerGroupClassName)\n            .each(clearAutoMargin);\n    }).remove();\n\n    // return early if no update menus are visible\n    if(menuData.length === 0) return;\n\n    // join header group\n    var headerGroups = menus.selectAll('g.' + constants.headerGroupClassName)\n        .data(menuData, keyFunction);\n\n    headerGroups.enter().append('g')\n        .classed(constants.headerGroupClassName, true);\n\n    // draw dropdown button container\n    var gButton = Lib.ensureSingle(menus, 'g', constants.dropdownButtonGroupClassName, function(s) {\n        s.style('pointer-events', 'all');\n    });\n\n    // find dimensions before plotting anything (this mutates menuOpts)\n    for(var i = 0; i < menuData.length; i++) {\n        var menuOpts = menuData[i];\n        findDimensions(gd, menuOpts);\n    }\n\n    // setup scrollbox\n    var scrollBoxId = 'updatemenus' + fullLayout._uid;\n    var scrollBox = new ScrollBox(gd, gButton, scrollBoxId);\n\n    // remove exiting header, remove dropped buttons and reset margins\n    if(headerGroups.enter().size()) {\n        // make sure gButton is on top of all headers\n        gButton.node().parentNode.appendChild(gButton.node());\n        gButton.call(removeAllButtons);\n    }\n\n    headerGroups.exit().each(function(menuOpts) {\n        gButton.call(removeAllButtons);\n        clearAutoMargin(menuOpts);\n    }).remove();\n\n    // draw headers!\n    headerGroups.each(function(menuOpts) {\n        var gHeader = d3.select(this);\n\n        var _gButton = menuOpts.type === 'dropdown' ? gButton : null;\n        Plots.manageCommandObserver(gd, menuOpts, menuOpts.buttons, function(data) {\n            setActive(gd, menuOpts, menuOpts.buttons[data.index], gHeader, _gButton, scrollBox, data.index, true);\n        });\n\n        if(menuOpts.type === 'dropdown') {\n            drawHeader(gd, gHeader, gButton, scrollBox, menuOpts);\n\n            // if this menu is active, update the dropdown container\n            if(isActive(gButton, menuOpts)) {\n                drawButtons(gd, gHeader, gButton, scrollBox, menuOpts);\n            }\n        } else {\n            drawButtons(gd, gHeader, null, null, menuOpts);\n        }\n    });\n};\n\n// Note that '_index' is set at the default step,\n// it corresponds to the menu index in the user layout update menu container.\n// Because a menu can be set invisible,\n// this is a more 'consistent' field than the index in the menuData.\nfunction keyFunction(menuOpts) {\n    return menuOpts._index;\n}\n\nfunction isFolded(gButton) {\n    return +gButton.attr(constants.menuIndexAttrName) === -1;\n}\n\nfunction isActive(gButton, menuOpts) {\n    return +gButton.attr(constants.menuIndexAttrName) === menuOpts._index;\n}\n\nfunction setActive(gd, menuOpts, buttonOpts, gHeader, gButton, scrollBox, buttonIndex, isSilentUpdate) {\n    // update 'active' attribute in menuOpts\n    menuOpts.active = buttonIndex;\n\n    // due to templating, it's possible this slider doesn't even exist yet\n    arrayEditor(gd.layout, constants.name, menuOpts)\n        .applyUpdate('active', buttonIndex);\n\n    if(menuOpts.type === 'buttons') {\n        drawButtons(gd, gHeader, null, null, menuOpts);\n    } else if(menuOpts.type === 'dropdown') {\n        // fold up buttons and redraw header\n        gButton.attr(constants.menuIndexAttrName, '-1');\n\n        drawHeader(gd, gHeader, gButton, scrollBox, menuOpts);\n\n        if(!isSilentUpdate) {\n            drawButtons(gd, gHeader, gButton, scrollBox, menuOpts);\n        }\n    }\n}\n\nfunction drawHeader(gd, gHeader, gButton, scrollBox, menuOpts) {\n    var header = Lib.ensureSingle(gHeader, 'g', constants.headerClassName, function(s) {\n        s.style('pointer-events', 'all');\n    });\n\n    var dims = menuOpts._dims;\n    var active = menuOpts.active;\n    var headerOpts = menuOpts.buttons[active] || constants.blankHeaderOpts;\n    var posOpts = { y: menuOpts.pad.t, yPad: 0, x: menuOpts.pad.l, xPad: 0, index: 0 };\n    var positionOverrides = {\n        width: dims.headerWidth,\n        height: dims.headerHeight\n    };\n\n    header\n        .call(drawItem, menuOpts, headerOpts, gd)\n        .call(setItemPosition, menuOpts, posOpts, positionOverrides);\n\n    // draw drop arrow at the right edge\n    var arrow = Lib.ensureSingle(gHeader, 'text', constants.headerArrowClassName, function(s) {\n        s.classed('user-select-none', true)\n            .attr('text-anchor', 'end')\n            .call(Drawing.font, menuOpts.font)\n            .text(constants.arrowSymbol[menuOpts.direction]);\n    });\n\n    arrow.attr({\n        x: dims.headerWidth - constants.arrowOffsetX + menuOpts.pad.l,\n        y: dims.headerHeight / 2 + constants.textOffsetY + menuOpts.pad.t\n    });\n\n    header.on('click', function() {\n        gButton.call(removeAllButtons,\n            String(isActive(gButton, menuOpts) ? -1 : menuOpts._index)\n        );\n\n        drawButtons(gd, gHeader, gButton, scrollBox, menuOpts);\n    });\n\n    header.on('mouseover', function() {\n        header.call(styleOnMouseOver);\n    });\n\n    header.on('mouseout', function() {\n        header.call(styleOnMouseOut, menuOpts);\n    });\n\n    // translate header group\n    Drawing.setTranslate(gHeader, dims.lx, dims.ly);\n}\n\nfunction drawButtons(gd, gHeader, gButton, scrollBox, menuOpts) {\n    // If this is a set of buttons, set pointer events = all since we play\n    // some minor games with which container is which in order to simplify\n    // the drawing of *either* buttons or menus\n    if(!gButton) {\n        gButton = gHeader;\n        gButton.attr('pointer-events', 'all');\n    }\n\n    var buttonData = (!isFolded(gButton) || menuOpts.type === 'buttons') ?\n        menuOpts.buttons :\n        [];\n\n    var klass = menuOpts.type === 'dropdown' ? constants.dropdownButtonClassName : constants.buttonClassName;\n\n    var buttons = gButton.selectAll('g.' + klass)\n        .data(Lib.filterVisible(buttonData));\n\n    var enter = buttons.enter().append('g')\n        .classed(klass, true);\n\n    var exit = buttons.exit();\n\n    if(menuOpts.type === 'dropdown') {\n        enter.attr('opacity', '0')\n            .transition()\n            .attr('opacity', '1');\n\n        exit.transition()\n            .attr('opacity', '0')\n            .remove();\n    } else {\n        exit.remove();\n    }\n\n    var x0 = 0;\n    var y0 = 0;\n    var dims = menuOpts._dims;\n\n    var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;\n\n    if(menuOpts.type === 'dropdown') {\n        if(isVertical) {\n            y0 = dims.headerHeight + constants.gapButtonHeader;\n        } else {\n            x0 = dims.headerWidth + constants.gapButtonHeader;\n        }\n    }\n\n    if(menuOpts.type === 'dropdown' && menuOpts.direction === 'up') {\n        y0 = -constants.gapButtonHeader + constants.gapButton - dims.openHeight;\n    }\n\n    if(menuOpts.type === 'dropdown' && menuOpts.direction === 'left') {\n        x0 = -constants.gapButtonHeader + constants.gapButton - dims.openWidth;\n    }\n\n    var posOpts = {\n        x: dims.lx + x0 + menuOpts.pad.l,\n        y: dims.ly + y0 + menuOpts.pad.t,\n        yPad: constants.gapButton,\n        xPad: constants.gapButton,\n        index: 0,\n    };\n\n    var scrollBoxPosition = {\n        l: posOpts.x + menuOpts.borderwidth,\n        t: posOpts.y + menuOpts.borderwidth\n    };\n\n    buttons.each(function(buttonOpts, buttonIndex) {\n        var button = d3.select(this);\n\n        button\n            .call(drawItem, menuOpts, buttonOpts, gd)\n            .call(setItemPosition, menuOpts, posOpts);\n\n        button.on('click', function() {\n            // skip `dragend` events\n            if(d3.event.defaultPrevented) return;\n\n            setActive(gd, menuOpts, buttonOpts, gHeader, gButton, scrollBox, buttonIndex);\n\n            if(buttonOpts.execute) {\n                Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args);\n            }\n\n            gd.emit('plotly_buttonclicked', {menu: menuOpts, button: buttonOpts, active: menuOpts.active});\n        });\n\n        button.on('mouseover', function() {\n            button.call(styleOnMouseOver);\n        });\n\n        button.on('mouseout', function() {\n            button.call(styleOnMouseOut, menuOpts);\n            buttons.call(styleButtons, menuOpts);\n        });\n    });\n\n    buttons.call(styleButtons, menuOpts);\n\n    if(isVertical) {\n        scrollBoxPosition.w = Math.max(dims.openWidth, dims.headerWidth);\n        scrollBoxPosition.h = posOpts.y - scrollBoxPosition.t;\n    } else {\n        scrollBoxPosition.w = posOpts.x - scrollBoxPosition.l;\n        scrollBoxPosition.h = Math.max(dims.openHeight, dims.headerHeight);\n    }\n\n    scrollBoxPosition.direction = menuOpts.direction;\n\n    if(scrollBox) {\n        if(buttons.size()) {\n            drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, scrollBoxPosition);\n        } else {\n            hideScrollBox(scrollBox);\n        }\n    }\n}\n\nfunction drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, position) {\n    // enable the scrollbox\n    var direction = menuOpts.direction;\n    var isVertical = (direction === 'up' || direction === 'down');\n    var dims = menuOpts._dims;\n\n    var active = menuOpts.active;\n    var translateX, translateY;\n    var i;\n    if(isVertical) {\n        translateY = 0;\n        for(i = 0; i < active; i++) {\n            translateY += dims.heights[i] + constants.gapButton;\n        }\n    } else {\n        translateX = 0;\n        for(i = 0; i < active; i++) {\n            translateX += dims.widths[i] + constants.gapButton;\n        }\n    }\n\n    scrollBox.enable(position, translateX, translateY);\n\n    if(scrollBox.hbar) {\n        scrollBox.hbar\n            .attr('opacity', '0')\n            .transition()\n            .attr('opacity', '1');\n    }\n\n    if(scrollBox.vbar) {\n        scrollBox.vbar\n            .attr('opacity', '0')\n            .transition()\n            .attr('opacity', '1');\n    }\n}\n\nfunction hideScrollBox(scrollBox) {\n    var hasHBar = !!scrollBox.hbar;\n    var hasVBar = !!scrollBox.vbar;\n\n    if(hasHBar) {\n        scrollBox.hbar\n            .transition()\n            .attr('opacity', '0')\n            .each('end', function() {\n                hasHBar = false;\n                if(!hasVBar) scrollBox.disable();\n            });\n    }\n\n    if(hasVBar) {\n        scrollBox.vbar\n            .transition()\n            .attr('opacity', '0')\n            .each('end', function() {\n                hasVBar = false;\n                if(!hasHBar) scrollBox.disable();\n            });\n    }\n}\n\nfunction drawItem(item, menuOpts, itemOpts, gd) {\n    item.call(drawItemRect, menuOpts)\n        .call(drawItemText, menuOpts, itemOpts, gd);\n}\n\nfunction drawItemRect(item, menuOpts) {\n    var rect = Lib.ensureSingle(item, 'rect', constants.itemRectClassName, function(s) {\n        s.attr({\n            rx: constants.rx,\n            ry: constants.ry,\n            'shape-rendering': 'crispEdges'\n        });\n    });\n\n    rect.call(Color.stroke, menuOpts.bordercolor)\n        .call(Color.fill, menuOpts.bgcolor)\n        .style('stroke-width', menuOpts.borderwidth + 'px');\n}\n\nfunction drawItemText(item, menuOpts, itemOpts, gd) {\n    var text = Lib.ensureSingle(item, 'text', constants.itemTextClassName, function(s) {\n        s.classed('user-select-none', true)\n            .attr({\n                'text-anchor': 'start',\n                'data-notex': 1\n            });\n    });\n\n    var tx = itemOpts.label;\n    var _meta = gd._fullLayout._meta;\n    if(_meta) tx = Lib.templateString(tx, _meta);\n\n    text.call(Drawing.font, menuOpts.font)\n        .text(tx)\n        .call(svgTextUtils.convertToTspans, gd);\n}\n\nfunction styleButtons(buttons, menuOpts) {\n    var active = menuOpts.active;\n\n    buttons.each(function(buttonOpts, i) {\n        var button = d3.select(this);\n\n        if(i === active && menuOpts.showactive) {\n            button.select('rect.' + constants.itemRectClassName)\n                .call(Color.fill, constants.activeColor);\n        }\n    });\n}\n\nfunction styleOnMouseOver(item) {\n    item.select('rect.' + constants.itemRectClassName)\n        .call(Color.fill, constants.hoverColor);\n}\n\nfunction styleOnMouseOut(item, menuOpts) {\n    item.select('rect.' + constants.itemRectClassName)\n        .call(Color.fill, menuOpts.bgcolor);\n}\n\n// find item dimensions (this mutates menuOpts)\nfunction findDimensions(gd, menuOpts) {\n    var dims = menuOpts._dims = {\n        width1: 0,\n        height1: 0,\n        heights: [],\n        widths: [],\n        totalWidth: 0,\n        totalHeight: 0,\n        openWidth: 0,\n        openHeight: 0,\n        lx: 0,\n        ly: 0\n    };\n\n    var fakeButtons = Drawing.tester.selectAll('g.' + constants.dropdownButtonClassName)\n        .data(Lib.filterVisible(menuOpts.buttons));\n\n    fakeButtons.enter().append('g')\n        .classed(constants.dropdownButtonClassName, true);\n\n    var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;\n\n    // loop over fake buttons to find width / height\n    fakeButtons.each(function(buttonOpts, i) {\n        var button = d3.select(this);\n\n        button.call(drawItem, menuOpts, buttonOpts, gd);\n\n        var text = button.select('.' + constants.itemTextClassName);\n\n        // width is given by max width of all buttons\n        var tWidth = text.node() && Drawing.bBox(text.node()).width;\n        var wEff = Math.max(tWidth + constants.textPadX, constants.minWidth);\n\n        // height is determined by item text\n        var tHeight = menuOpts.font.size * LINE_SPACING;\n        var tLines = svgTextUtils.lineCount(text);\n        var hEff = Math.max(tHeight * tLines, constants.minHeight) + constants.textOffsetY;\n\n        hEff = Math.ceil(hEff);\n        wEff = Math.ceil(wEff);\n\n        // Store per-item sizes since a row of horizontal buttons, for example,\n        // don't all need to be the same width:\n        dims.widths[i] = wEff;\n        dims.heights[i] = hEff;\n\n        // Height and width of individual element:\n        dims.height1 = Math.max(dims.height1, hEff);\n        dims.width1 = Math.max(dims.width1, wEff);\n\n        if(isVertical) {\n            dims.totalWidth = Math.max(dims.totalWidth, wEff);\n            dims.openWidth = dims.totalWidth;\n            dims.totalHeight += hEff + constants.gapButton;\n            dims.openHeight += hEff + constants.gapButton;\n        } else {\n            dims.totalWidth += wEff + constants.gapButton;\n            dims.openWidth += wEff + constants.gapButton;\n            dims.totalHeight = Math.max(dims.totalHeight, hEff);\n            dims.openHeight = dims.totalHeight;\n        }\n    });\n\n    if(isVertical) {\n        dims.totalHeight -= constants.gapButton;\n    } else {\n        dims.totalWidth -= constants.gapButton;\n    }\n\n\n    dims.headerWidth = dims.width1 + constants.arrowPadX;\n    dims.headerHeight = dims.height1;\n\n    if(menuOpts.type === 'dropdown') {\n        if(isVertical) {\n            dims.width1 += constants.arrowPadX;\n            dims.totalHeight = dims.height1;\n        } else {\n            dims.totalWidth = dims.width1;\n        }\n        dims.totalWidth += constants.arrowPadX;\n    }\n\n    fakeButtons.remove();\n\n    var paddedWidth = dims.totalWidth + menuOpts.pad.l + menuOpts.pad.r;\n    var paddedHeight = dims.totalHeight + menuOpts.pad.t + menuOpts.pad.b;\n\n    var graphSize = gd._fullLayout._size;\n    dims.lx = graphSize.l + graphSize.w * menuOpts.x;\n    dims.ly = graphSize.t + graphSize.h * (1 - menuOpts.y);\n\n    var xanchor = 'left';\n    if(Lib.isRightAnchor(menuOpts)) {\n        dims.lx -= paddedWidth;\n        xanchor = 'right';\n    }\n    if(Lib.isCenterAnchor(menuOpts)) {\n        dims.lx -= paddedWidth / 2;\n        xanchor = 'center';\n    }\n\n    var yanchor = 'top';\n    if(Lib.isBottomAnchor(menuOpts)) {\n        dims.ly -= paddedHeight;\n        yanchor = 'bottom';\n    }\n    if(Lib.isMiddleAnchor(menuOpts)) {\n        dims.ly -= paddedHeight / 2;\n        yanchor = 'middle';\n    }\n\n    dims.totalWidth = Math.ceil(dims.totalWidth);\n    dims.totalHeight = Math.ceil(dims.totalHeight);\n    dims.lx = Math.round(dims.lx);\n    dims.ly = Math.round(dims.ly);\n\n    Plots.autoMargin(gd, autoMarginId(menuOpts), {\n        x: menuOpts.x,\n        y: menuOpts.y,\n        l: paddedWidth * ({right: 1, center: 0.5}[xanchor] || 0),\n        r: paddedWidth * ({left: 1, center: 0.5}[xanchor] || 0),\n        b: paddedHeight * ({top: 1, middle: 0.5}[yanchor] || 0),\n        t: paddedHeight * ({bottom: 1, middle: 0.5}[yanchor] || 0)\n    });\n}\n\nfunction autoMarginId(menuOpts) {\n    return constants.autoMarginIdRoot + menuOpts._index;\n}\n\n// set item positions (mutates posOpts)\nfunction setItemPosition(item, menuOpts, posOpts, overrideOpts) {\n    overrideOpts = overrideOpts || {};\n    var rect = item.select('.' + constants.itemRectClassName);\n    var text = item.select('.' + constants.itemTextClassName);\n    var borderWidth = menuOpts.borderwidth;\n    var index = posOpts.index;\n    var dims = menuOpts._dims;\n\n    Drawing.setTranslate(item, borderWidth + posOpts.x, borderWidth + posOpts.y);\n\n    var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;\n    var finalHeight = overrideOpts.height || (isVertical ? dims.heights[index] : dims.height1);\n\n    rect.attr({\n        x: 0,\n        y: 0,\n        width: overrideOpts.width || (isVertical ? dims.width1 : dims.widths[index]),\n        height: finalHeight\n    });\n\n    var tHeight = menuOpts.font.size * LINE_SPACING;\n    var tLines = svgTextUtils.lineCount(text);\n    var spanOffset = ((tLines - 1) * tHeight / 2);\n\n    svgTextUtils.positionText(text, constants.textOffsetX,\n        finalHeight / 2 - spanOffset + constants.textOffsetY);\n\n    if(isVertical) {\n        posOpts.y += dims.heights[index] + posOpts.yPad;\n    } else {\n        posOpts.x += dims.widths[index] + posOpts.xPad;\n    }\n\n    posOpts.index++;\n}\n\nfunction removeAllButtons(gButton, newMenuIndexAttr) {\n    gButton\n        .attr(constants.menuIndexAttrName, newMenuIndexAttr || '-1')\n        .selectAll('g.' + constants.dropdownButtonClassName).remove();\n}\n\n},{\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plot_api/plot_template\":757,\"../../plots/plots\":828,\"../color\":593,\"../drawing\":614,\"./constants\":683,\"./scrollbox\":687,\"d3\":163}],686:[function(_dereq_,module,exports){\narguments[4][680][0].apply(exports,arguments)\n},{\"./attributes\":682,\"./constants\":683,\"./defaults\":684,\"./draw\":685,\"dup\":680}],687:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = ScrollBox;\n\nvar d3 = _dereq_('d3');\n\nvar Color = _dereq_('../color');\nvar Drawing = _dereq_('../drawing');\n\nvar Lib = _dereq_('../../lib');\n\n/**\n * Helper class to setup a scroll box\n *\n * @class\n * @param           gd          Plotly's graph div\n * @param           container   Container to be scroll-boxed (as a D3 selection)\n * @param {string}  id          Id for the clip path to implement the scroll box\n */\nfunction ScrollBox(gd, container, id) {\n    this.gd = gd;\n    this.container = container;\n    this.id = id;\n\n    // See ScrollBox.prototype.enable for further definition\n    this.position = null;  // scrollbox position\n    this.translateX = null;  // scrollbox horizontal translation\n    this.translateY = null;  // scrollbox vertical translation\n    this.hbar = null;  // horizontal scrollbar D3 selection\n    this.vbar = null;  // vertical scrollbar D3 selection\n\n    // <rect> element to capture pointer events\n    this.bg = this.container.selectAll('rect.scrollbox-bg').data([0]);\n\n    this.bg.exit()\n        .on('.drag', null)\n        .on('wheel', null)\n        .remove();\n\n    this.bg.enter().append('rect')\n        .classed('scrollbox-bg', true)\n        .style('pointer-events', 'all')\n        .attr({\n            opacity: 0,\n            x: 0,\n            y: 0,\n            width: 0,\n            height: 0\n        });\n}\n\n// scroll bar dimensions\nScrollBox.barWidth = 2;\nScrollBox.barLength = 20;\nScrollBox.barRadius = 2;\nScrollBox.barPad = 1;\nScrollBox.barColor = '#808BA4';\n\n/**\n * If needed, setup a clip path and scrollbars\n *\n * @method\n * @param {Object}  position\n * @param {number}  position.l  Left side position (in pixels)\n * @param {number}  position.t  Top side (in pixels)\n * @param {number}  position.w  Width (in pixels)\n * @param {number}  position.h  Height (in pixels)\n * @param {string}  [position.direction='down']\n *                  Either 'down', 'left', 'right' or 'up'\n * @param {number}  [translateX=0]  Horizontal offset (in pixels)\n * @param {number}  [translateY=0]  Vertical offset (in pixels)\n */\nScrollBox.prototype.enable = function enable(position, translateX, translateY) {\n    var fullLayout = this.gd._fullLayout;\n    var fullWidth = fullLayout.width;\n    var fullHeight = fullLayout.height;\n\n    // compute position of scrollbox\n    this.position = position;\n\n    var l = this.position.l;\n    var w = this.position.w;\n    var t = this.position.t;\n    var h = this.position.h;\n    var direction = this.position.direction;\n    var isDown = (direction === 'down');\n    var isLeft = (direction === 'left');\n    var isRight = (direction === 'right');\n    var isUp = (direction === 'up');\n    var boxW = w;\n    var boxH = h;\n    var boxL, boxR;\n    var boxT, boxB;\n\n    if(!isDown && !isLeft && !isRight && !isUp) {\n        this.position.direction = 'down';\n        isDown = true;\n    }\n\n    var isVertical = isDown || isUp;\n    if(isVertical) {\n        boxL = l;\n        boxR = boxL + boxW;\n\n        if(isDown) {\n            // anchor to top side\n            boxT = t;\n            boxB = Math.min(boxT + boxH, fullHeight);\n            boxH = boxB - boxT;\n        } else {\n            // anchor to bottom side\n            boxB = t + boxH;\n            boxT = Math.max(boxB - boxH, 0);\n            boxH = boxB - boxT;\n        }\n    } else {\n        boxT = t;\n        boxB = boxT + boxH;\n\n        if(isLeft) {\n            // anchor to right side\n            boxR = l + boxW;\n            boxL = Math.max(boxR - boxW, 0);\n            boxW = boxR - boxL;\n        } else {\n            // anchor to left side\n            boxL = l;\n            boxR = Math.min(boxL + boxW, fullWidth);\n            boxW = boxR - boxL;\n        }\n    }\n\n    this._box = {\n        l: boxL,\n        t: boxT,\n        w: boxW,\n        h: boxH\n    };\n\n    // compute position of horizontal scroll bar\n    var needsHorizontalScrollBar = (w > boxW);\n    var hbarW = ScrollBox.barLength + 2 * ScrollBox.barPad;\n    var hbarH = ScrollBox.barWidth + 2 * ScrollBox.barPad;\n    // draw horizontal scrollbar on the bottom side\n    var hbarL = l;\n    var hbarT = t + h;\n\n    if(hbarT + hbarH > fullHeight) hbarT = fullHeight - hbarH;\n\n    var hbar = this.container.selectAll('rect.scrollbar-horizontal').data(\n            (needsHorizontalScrollBar) ? [0] : []);\n\n    hbar.exit()\n        .on('.drag', null)\n        .remove();\n\n    hbar.enter().append('rect')\n        .classed('scrollbar-horizontal', true)\n        .call(Color.fill, ScrollBox.barColor);\n\n    if(needsHorizontalScrollBar) {\n        this.hbar = hbar.attr({\n            'rx': ScrollBox.barRadius,\n            'ry': ScrollBox.barRadius,\n            'x': hbarL,\n            'y': hbarT,\n            'width': hbarW,\n            'height': hbarH\n        });\n\n        // hbar center moves between hbarXMin and hbarXMin + hbarTranslateMax\n        this._hbarXMin = hbarL + hbarW / 2;\n        this._hbarTranslateMax = boxW - hbarW;\n    } else {\n        delete this.hbar;\n        delete this._hbarXMin;\n        delete this._hbarTranslateMax;\n    }\n\n    // compute position of vertical scroll bar\n    var needsVerticalScrollBar = (h > boxH);\n    var vbarW = ScrollBox.barWidth + 2 * ScrollBox.barPad;\n    var vbarH = ScrollBox.barLength + 2 * ScrollBox.barPad;\n    // draw vertical scrollbar on the right side\n    var vbarL = l + w;\n    var vbarT = t;\n\n    if(vbarL + vbarW > fullWidth) vbarL = fullWidth - vbarW;\n\n    var vbar = this.container.selectAll('rect.scrollbar-vertical').data(\n            (needsVerticalScrollBar) ? [0] : []);\n\n    vbar.exit()\n        .on('.drag', null)\n        .remove();\n\n    vbar.enter().append('rect')\n        .classed('scrollbar-vertical', true)\n        .call(Color.fill, ScrollBox.barColor);\n\n    if(needsVerticalScrollBar) {\n        this.vbar = vbar.attr({\n            'rx': ScrollBox.barRadius,\n            'ry': ScrollBox.barRadius,\n            'x': vbarL,\n            'y': vbarT,\n            'width': vbarW,\n            'height': vbarH\n        });\n\n        // vbar center moves between vbarYMin and vbarYMin + vbarTranslateMax\n        this._vbarYMin = vbarT + vbarH / 2;\n        this._vbarTranslateMax = boxH - vbarH;\n    } else {\n        delete this.vbar;\n        delete this._vbarYMin;\n        delete this._vbarTranslateMax;\n    }\n\n    // setup a clip path (if scroll bars are needed)\n    var clipId = this.id;\n    var clipL = boxL - 0.5;\n    var clipR = (needsVerticalScrollBar) ? boxR + vbarW + 0.5 : boxR + 0.5;\n    var clipT = boxT - 0.5;\n    var clipB = (needsHorizontalScrollBar) ? boxB + hbarH + 0.5 : boxB + 0.5;\n\n    var clipPath = fullLayout._topdefs.selectAll('#' + clipId)\n        .data((needsHorizontalScrollBar || needsVerticalScrollBar) ? [0] : []);\n\n    clipPath.exit().remove();\n\n    clipPath.enter()\n        .append('clipPath').attr('id', clipId)\n        .append('rect');\n\n    if(needsHorizontalScrollBar || needsVerticalScrollBar) {\n        this._clipRect = clipPath.select('rect').attr({\n            x: Math.floor(clipL),\n            y: Math.floor(clipT),\n            width: Math.ceil(clipR) - Math.floor(clipL),\n            height: Math.ceil(clipB) - Math.floor(clipT)\n        });\n\n        this.container.call(Drawing.setClipUrl, clipId, this.gd);\n\n        this.bg.attr({\n            x: l,\n            y: t,\n            width: w,\n            height: h\n        });\n    } else {\n        this.bg.attr({\n            width: 0,\n            height: 0\n        });\n        this.container\n            .on('wheel', null)\n            .on('.drag', null)\n            .call(Drawing.setClipUrl, null);\n        delete this._clipRect;\n    }\n\n    // set up drag listeners (if scroll bars are needed)\n    if(needsHorizontalScrollBar || needsVerticalScrollBar) {\n        var onBoxDrag = d3.behavior.drag()\n            .on('dragstart', function() {\n                d3.event.sourceEvent.preventDefault();\n            })\n            .on('drag', this._onBoxDrag.bind(this));\n\n        this.container\n            .on('wheel', null)\n            .on('wheel', this._onBoxWheel.bind(this))\n            .on('.drag', null)\n            .call(onBoxDrag);\n\n        var onBarDrag = d3.behavior.drag()\n            .on('dragstart', function() {\n                d3.event.sourceEvent.preventDefault();\n                d3.event.sourceEvent.stopPropagation();\n            })\n            .on('drag', this._onBarDrag.bind(this));\n\n        if(needsHorizontalScrollBar) {\n            this.hbar\n                .on('.drag', null)\n                .call(onBarDrag);\n        }\n\n        if(needsVerticalScrollBar) {\n            this.vbar\n                .on('.drag', null)\n                .call(onBarDrag);\n        }\n    }\n\n    // set scrollbox translation\n    this.setTranslate(translateX, translateY);\n};\n\n/**\n * If present, remove clip-path and scrollbars\n *\n * @method\n */\nScrollBox.prototype.disable = function disable() {\n    if(this.hbar || this.vbar) {\n        this.bg.attr({\n            width: 0,\n            height: 0\n        });\n        this.container\n            .on('wheel', null)\n            .on('.drag', null)\n            .call(Drawing.setClipUrl, null);\n        delete this._clipRect;\n    }\n\n    if(this.hbar) {\n        this.hbar.on('.drag', null);\n        this.hbar.remove();\n        delete this.hbar;\n        delete this._hbarXMin;\n        delete this._hbarTranslateMax;\n    }\n\n    if(this.vbar) {\n        this.vbar.on('.drag', null);\n        this.vbar.remove();\n        delete this.vbar;\n        delete this._vbarYMin;\n        delete this._vbarTranslateMax;\n    }\n};\n\n/**\n * Handles scroll box drag events\n *\n * @method\n */\nScrollBox.prototype._onBoxDrag = function _onBoxDrag() {\n    var translateX = this.translateX;\n    var translateY = this.translateY;\n\n    if(this.hbar) {\n        translateX -= d3.event.dx;\n    }\n\n    if(this.vbar) {\n        translateY -= d3.event.dy;\n    }\n\n    this.setTranslate(translateX, translateY);\n};\n\n/**\n * Handles scroll box wheel events\n *\n * @method\n */\nScrollBox.prototype._onBoxWheel = function _onBoxWheel() {\n    var translateX = this.translateX;\n    var translateY = this.translateY;\n\n    if(this.hbar) {\n        translateX += d3.event.deltaY;\n    }\n\n    if(this.vbar) {\n        translateY += d3.event.deltaY;\n    }\n\n    this.setTranslate(translateX, translateY);\n};\n\n/**\n * Handles scroll bar drag events\n *\n * @method\n */\nScrollBox.prototype._onBarDrag = function _onBarDrag() {\n    var translateX = this.translateX;\n    var translateY = this.translateY;\n\n    if(this.hbar) {\n        var xMin = translateX + this._hbarXMin;\n        var xMax = xMin + this._hbarTranslateMax;\n        var x = Lib.constrain(d3.event.x, xMin, xMax);\n        var xf = (x - xMin) / (xMax - xMin);\n\n        var translateXMax = this.position.w - this._box.w;\n\n        translateX = xf * translateXMax;\n    }\n\n    if(this.vbar) {\n        var yMin = translateY + this._vbarYMin;\n        var yMax = yMin + this._vbarTranslateMax;\n        var y = Lib.constrain(d3.event.y, yMin, yMax);\n        var yf = (y - yMin) / (yMax - yMin);\n\n        var translateYMax = this.position.h - this._box.h;\n\n        translateY = yf * translateYMax;\n    }\n\n    this.setTranslate(translateX, translateY);\n};\n\n/**\n * Set clip path and scroll bar translate transform\n *\n * @method\n * @param {number}  [translateX=0]  Horizontal offset (in pixels)\n * @param {number}  [translateY=0]  Vertical offset (in pixels)\n */\nScrollBox.prototype.setTranslate = function setTranslate(translateX, translateY) {\n    // store translateX and translateY (needed by mouse event handlers)\n    var translateXMax = this.position.w - this._box.w;\n    var translateYMax = this.position.h - this._box.h;\n\n    translateX = Lib.constrain(translateX || 0, 0, translateXMax);\n    translateY = Lib.constrain(translateY || 0, 0, translateYMax);\n\n    this.translateX = translateX;\n    this.translateY = translateY;\n\n    this.container.call(Drawing.setTranslate,\n        this._box.l - this.position.l - translateX,\n        this._box.t - this.position.t - translateY);\n\n    if(this._clipRect) {\n        this._clipRect.attr({\n            x: Math.floor(this.position.l + translateX - 0.5),\n            y: Math.floor(this.position.t + translateY - 0.5)\n        });\n    }\n\n    if(this.hbar) {\n        var xf = translateX / translateXMax;\n\n        this.hbar.call(Drawing.setTranslate,\n            translateX + xf * this._hbarTranslateMax,\n            translateY);\n    }\n\n    if(this.vbar) {\n        var yf = translateY / translateYMax;\n\n        this.vbar.call(Drawing.setTranslate,\n            translateX,\n            translateY + yf * this._vbarTranslateMax);\n    }\n};\n\n},{\"../../lib\":719,\"../color\":593,\"../drawing\":614,\"d3\":163}],688:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// fraction of some size to get to a named position\nmodule.exports = {\n    // from bottom left: this is the origin of our paper-reference\n    // positioning system\n    FROM_BL: {\n        left: 0,\n        center: 0.5,\n        right: 1,\n        bottom: 0,\n        middle: 0.5,\n        top: 1\n    },\n    // from top left: this is the screen pixel positioning origin\n    FROM_TL: {\n        left: 0,\n        center: 0.5,\n        right: 1,\n        bottom: 1,\n        middle: 0.5,\n        top: 0\n    },\n    // from bottom right: sometimes you just need the opposite of ^^\n    FROM_BR: {\n        left: 1,\n        center: 0.5,\n        right: 0,\n        bottom: 0,\n        middle: 0.5,\n        top: 1\n    },\n    // multiple of fontSize to get the vertical offset between lines\n    LINE_SPACING: 1.3,\n\n    // multiple of fontSize to shift from the baseline\n    // to the cap (captical letter) line\n    // (to use when we don't calculate this shift from Drawing.bBox)\n    // This is an approximation since in reality cap height can differ\n    // from font to font. However, according to Wikipedia\n    //   an \"average\" font might have a cap height of 70% of the em\n    // https://en.wikipedia.org/wiki/Em_(typography)#History\n    CAP_SHIFT: 0.70,\n\n    // half the cap height (distance between baseline and cap line)\n    // of an \"average\" font (for more info see above).\n    MID_SHIFT: 0.35,\n\n    OPPOSITE_SIDE: {\n        left: 'right',\n        right: 'left',\n        top: 'bottom',\n        bottom: 'top'\n    }\n};\n\n},{}],689:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    INCREASING: {\n        COLOR: '#3D9970',\n        SYMBOL: '▲'\n    },\n    DECREASING: {\n        COLOR: '#FF4136',\n        SYMBOL: '▼'\n    }\n};\n\n},{}],690:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format',\n    DATE_FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format'\n};\n\n},{}],691:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    COMPARISON_OPS: ['=', '!=', '<', '>=', '>', '<='],\n    COMPARISON_OPS2: ['=', '<', '>=', '>', '<='],\n    INTERVAL_OPS: ['[]', '()', '[)', '(]', '][', ')(', '](', ')['],\n    SET_OPS: ['{}', '}{'],\n    CONSTRAINT_REDUCTION: {\n        // for contour constraints, open/closed endpoints are equivalent\n        '=': '=',\n\n        '<': '<',\n        '<=': '<',\n\n        '>': '>',\n        '>=': '>',\n\n        '[]': '[]',\n        '()': '[]',\n        '[)': '[]',\n        '(]': '[]',\n\n        '][': '][',\n        ')(': '][',\n        '](': '][',\n        ')[': ']['\n    }\n};\n\n},{}],692:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = {\n    solid: [[], 0],\n    dot: [[0.5, 1], 200],\n    dash: [[0.5, 1], 50],\n    longdash: [[0.5, 1], 10],\n    dashdot: [[0.5, 0.625, 0.875, 1], 50],\n    longdashdot: [[0.5, 0.7, 0.8, 1], 10]\n};\n\n},{}],693:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = {\n    circle: '●',\n    'circle-open': '○',\n    square: '■',\n    'square-open': '□',\n    diamond: '◆',\n    'diamond-open': '◇',\n    cross: '+',\n    x: '❌'\n};\n\n},{}],694:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n    /**\n     * Timing information for interactive elements\n     */\n    SHOW_PLACEHOLDER: 100,\n    HIDE_PLACEHOLDER: 1000,\n\n    // opacity dimming fraction for points that are not in selection\n    DESELECTDIM: 0.2\n};\n\n},{}],695:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n    /**\n     * Standardize all missing data in calcdata to use undefined\n     * never null or NaN.\n     * That way we can use !==undefined, or !== BADNUM,\n     * to test for real data\n     */\n    BADNUM: undefined,\n\n    /*\n     * Limit certain operations to well below floating point max value\n     * to avoid glitches: Make sure that even when you multiply it by the\n     * number of pixels on a giant screen it still works\n     */\n    FP_SAFE: Number.MAX_VALUE / 10000,\n\n    /*\n     * conversion of date units to milliseconds\n     * year and month constants are marked \"AVG\"\n     * to remind us that not all years and months\n     * have the same length\n     */\n    ONEAVGYEAR: 31557600000, // 365.25 days\n    ONEAVGMONTH: 2629800000, // 1/12 of ONEAVGYEAR\n    ONEDAY: 86400000,\n    ONEHOUR: 3600000,\n    ONEMIN: 60000,\n    ONESEC: 1000,\n\n    /*\n     * For fast conversion btwn world calendars and epoch ms, the Julian Day Number\n     * of the unix epoch. From calendars.instance().newDate(1970, 1, 1).toJD()\n     */\n    EPOCHJD: 2440587.5,\n\n    /*\n     * Are two values nearly equal? Compare to 1PPM\n     */\n    ALMOST_EQUAL: 1 - 1e-6,\n\n    /*\n     * If we're asked to clip a non-positive log value, how far off-screen\n     * do we put it?\n     */\n    LOG_CLIP: 10,\n\n    /*\n     * not a number, but for displaying numbers: the \"minus sign\" symbol is\n     * wider than the regular ascii dash \"-\"\n     */\n    MINUS_SIGN: '\\u2212'\n};\n\n},{}],696:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nexports.xmlns = 'http://www.w3.org/2000/xmlns/';\nexports.svg = 'http://www.w3.org/2000/svg';\nexports.xlink = 'http://www.w3.org/1999/xlink';\n\n// the 'old' d3 quirk got fix in v3.5.7\n// https://github.com/mbostock/d3/commit/a6f66e9dd37f764403fc7c1f26be09ab4af24fed\nexports.svgAttrs = {\n    xmlns: exports.svg,\n    'xmlns:xlink': exports.xlink\n};\n\n},{}],697:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// package version injected by `npm run preprocess`\nexports.version = '1.49.0';\n\n// inject promise polyfill\n_dereq_('es6-promise').polyfill();\n\n// inject plot css\n_dereq_('../build/plotcss');\n\n// inject default MathJax config\n_dereq_('./fonts/mathjax_config')();\n\n// include registry module and expose register method\nvar Registry = _dereq_('./registry');\nvar register = exports.register = Registry.register;\n\n// expose plot api methods\nvar plotApi = _dereq_('./plot_api');\nvar methodNames = Object.keys(plotApi);\nfor(var i = 0; i < methodNames.length; i++) {\n    var name = methodNames[i];\n    // _ -> private API methods, but still registered for internal use\n    if(name.charAt(0) !== '_') exports[name] = plotApi[name];\n    register({\n        moduleType: 'apiMethod',\n        name: name,\n        fn: plotApi[name]\n    });\n}\n\n// scatter is the only trace included by default\nregister(_dereq_('./traces/scatter'));\n\n// register all registrable components modules\nregister([\n    _dereq_('./components/fx'),\n    _dereq_('./components/legend'),\n    _dereq_('./components/annotations'),\n    _dereq_('./components/annotations3d'),\n    _dereq_('./components/shapes'),\n    _dereq_('./components/images'),\n    _dereq_('./components/updatemenus'),\n    _dereq_('./components/sliders'),\n    _dereq_('./components/rangeslider'),\n    _dereq_('./components/rangeselector'),\n    _dereq_('./components/grid'),\n    _dereq_('./components/errorbars'),\n    _dereq_('./components/colorscale'),\n    _dereq_('./components/colorbar')\n]);\n\n// locales en and en-US are required for default behavior\nregister([\n    _dereq_('./locale-en'),\n    _dereq_('./locale-en-us')\n]);\n\n// plot icons\nexports.Icons = _dereq_('./fonts/ploticon');\n\n// unofficial 'beta' plot methods, use at your own risk\nexports.Plots = _dereq_('./plots/plots');\nexports.Fx = _dereq_('./components/fx');\nexports.Snapshot = _dereq_('./snapshot');\nexports.PlotSchema = _dereq_('./plot_api/plot_schema');\nexports.Queue = _dereq_('./lib/queue');\n\n// export d3 used in the bundle\nexports.d3 = _dereq_('d3');\n\n},{\"../build/plotcss\":1,\"./components/annotations\":584,\"./components/annotations3d\":589,\"./components/colorbar\":599,\"./components/colorscale\":605,\"./components/errorbars\":620,\"./components/fx\":632,\"./components/grid\":636,\"./components/images\":641,\"./components/legend\":649,\"./components/rangeselector\":660,\"./components/rangeslider\":667,\"./components/shapes\":675,\"./components/sliders\":680,\"./components/updatemenus\":686,\"./fonts/mathjax_config\":698,\"./fonts/ploticon\":699,\"./lib/queue\":734,\"./locale-en\":748,\"./locale-en-us\":747,\"./plot_api\":752,\"./plot_api/plot_schema\":756,\"./plots/plots\":828,\"./registry\":847,\"./snapshot\":852,\"./traces/scatter\":1123,\"d3\":163,\"es6-promise\":218}],698:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/* global MathJax:false */\n\nmodule.exports = function() {\n    if(typeof MathJax !== 'undefined') {\n        var globalConfig = (window.PlotlyConfig || {}).MathJaxConfig !== 'local';\n\n        if(globalConfig) {\n            MathJax.Hub.Config({\n                messageStyle: 'none',\n                skipStartupTypeset: true,\n                displayAlign: 'left',\n                tex2jax: {\n                    inlineMath: [['$', '$'], ['\\\\(', '\\\\)']]\n                }\n            });\n            MathJax.Hub.Configured();\n        }\n    }\n};\n\n},{}],699:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    'undo': {\n        'width': 857.1,\n        'height': 1000,\n        'path': 'm857 350q0-87-34-166t-91-137-137-92-166-34q-96 0-183 41t-147 114q-4 6-4 13t5 11l76 77q6 5 14 5 9-1 13-7 41-53 100-82t126-29q58 0 110 23t92 61 61 91 22 111-22 111-61 91-92 61-110 23q-55 0-105-20t-90-57l77-77q17-16 8-38-10-23-33-23h-250q-15 0-25 11t-11 25v250q0 24 22 33 22 10 39-8l72-72q60 57 137 88t159 31q87 0 166-34t137-92 91-137 34-166z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'home': {\n        'width': 928.6,\n        'height': 1000,\n        'path': 'm786 296v-267q0-15-11-26t-25-10h-214v214h-143v-214h-214q-15 0-25 10t-11 26v267q0 1 0 2t0 2l321 264 321-264q1-1 1-4z m124 39l-34-41q-5-5-12-6h-2q-7 0-12 3l-386 322-386-322q-7-4-13-4-7 2-12 7l-35 41q-4 5-3 13t6 12l401 334q18 15 42 15t43-15l136-114v109q0 8 5 13t13 5h107q8 0 13-5t5-13v-227l122-102q5-5 6-12t-4-13z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'camera-retro': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm518 386q0 8-5 13t-13 5q-37 0-63-27t-26-63q0-8 5-13t13-5 12 5 5 13q0 23 16 38t38 16q8 0 13 5t5 13z m125-73q0-59-42-101t-101-42-101 42-42 101 42 101 101 42 101-42 42-101z m-572-320h858v71h-858v-71z m643 320q0 89-62 152t-152 62-151-62-63-152 63-151 151-63 152 63 62 151z m-571 358h214v72h-214v-72z m-72-107h858v143h-462l-36-71h-360v-72z m929 143v-714q0-30-21-51t-50-21h-858q-29 0-50 21t-21 51v714q0 30 21 51t50 21h858q29 0 50-21t21-51z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'zoombox': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm1000-25l-250 251c40 63 63 138 63 218 0 224-182 406-407 406-224 0-406-182-406-406s183-406 407-406c80 0 155 22 218 62l250-250 125 125z m-812 250l0 438 437 0 0-438-437 0z m62 375l313 0 0-312-313 0 0 312z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'pan': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm1000 350l-187 188 0-125-250 0 0 250 125 0-188 187-187-187 125 0 0-250-250 0 0 125-188-188 186-187 0 125 252 0 0-250-125 0 187-188 188 188-125 0 0 250 250 0 0-126 187 188z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'zoom_plus': {\n        'width': 875,\n        'height': 1000,\n        'path': 'm1 787l0-875 875 0 0 875-875 0z m687-500l-187 0 0-187-125 0 0 187-188 0 0 125 188 0 0 187 125 0 0-187 187 0 0-125z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'zoom_minus': {\n        'width': 875,\n        'height': 1000,\n        'path': 'm0 788l0-876 875 0 0 876-875 0z m688-500l-500 0 0 125 500 0 0-125z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'autoscale': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm250 850l-187 0-63 0 0-62 0-188 63 0 0 188 187 0 0 62z m688 0l-188 0 0-62 188 0 0-188 62 0 0 188 0 62-62 0z m-875-938l0 188-63 0 0-188 0-62 63 0 187 0 0 62-187 0z m875 188l0-188-188 0 0-62 188 0 62 0 0 62 0 188-62 0z m-125 188l-1 0-93-94-156 156 156 156 92-93 2 0 0 250-250 0 0-2 93-92-156-156-156 156 94 92 0 2-250 0 0-250 0 0 93 93 157-156-157-156-93 94 0 0 0-250 250 0 0 0-94 93 156 157 156-157-93-93 0 0 250 0 0 250z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'tooltip_basic': {\n        'width': 1500,\n        'height': 1000,\n        'path': 'm375 725l0 0-375-375 375-374 0-1 1125 0 0 750-1125 0z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'tooltip_compare': {\n        'width': 1125,\n        'height': 1000,\n        'path': 'm187 786l0 2-187-188 188-187 0 0 937 0 0 373-938 0z m0-499l0 1-187-188 188-188 0 0 937 0 0 376-938-1z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'plotlylogo': {\n        'width': 1542,\n        'height': 1000,\n        'path': 'm0-10h182v-140h-182v140z m228 146h183v-286h-183v286z m225 714h182v-1000h-182v1000z m225-285h182v-715h-182v715z m225 142h183v-857h-183v857z m231-428h182v-429h-182v429z m225-291h183v-138h-183v138z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'z-axis': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm833 5l-17 108v41l-130-65 130-66c0 0 0 38 0 39 0-1 36-14 39-25 4-15-6-22-16-30-15-12-39-16-56-20-90-22-187-23-279-23-261 0-341 34-353 59 3 60 228 110 228 110-140-8-351-35-351-116 0-120 293-142 474-142 155 0 477 22 477 142 0 50-74 79-163 96z m-374 94c-58-5-99-21-99-40 0-24 65-43 144-43 79 0 143 19 143 43 0 19-42 34-98 40v216h87l-132 135-133-135h88v-216z m167 515h-136v1c16 16 31 34 46 52l84 109v54h-230v-71h124v-1c-16-17-28-32-44-51l-89-114v-51h245v72z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    '3d_rotate': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm922 660c-5 4-9 7-14 11-359 263-580-31-580-31l-102 28 58-400c0 1 1 1 2 2 118 108 351 249 351 249s-62 27-100 42c88 83 222 183 347 122 16-8 30-17 44-27-2 1-4 2-6 4z m36-329c0 0 64 229-88 296-62 27-124 14-175-11 157-78 225-208 249-266 8-19 11-31 11-31 2 5 6 15 11 32-5-13-8-20-8-20z m-775-239c70-31 117-50 198-32-121 80-199 346-199 346l-96-15-58-12c0 0 55-226 155-287z m603 133l-317-139c0 0 4-4 19-14 7-5 24-15 24-15s-177-147-389 4c235-287 536-112 536-112l31-22 100 299-4-1z m-298-153c6-4 14-9 24-15 0 0-17 10-24 15z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'camera': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm500 450c-83 0-150-67-150-150 0-83 67-150 150-150 83 0 150 67 150 150 0 83-67 150-150 150z m400 150h-120c-16 0-34 13-39 29l-31 93c-6 15-23 28-40 28h-340c-16 0-34-13-39-28l-31-94c-6-15-23-28-40-28h-120c-55 0-100-45-100-100v-450c0-55 45-100 100-100h800c55 0 100 45 100 100v450c0 55-45 100-100 100z m-400-550c-138 0-250 112-250 250 0 138 112 250 250 250 138 0 250-112 250-250 0-138-112-250-250-250z m365 380c-19 0-35 16-35 35 0 19 16 35 35 35 19 0 35-16 35-35 0-19-16-35-35-35z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'movie': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm938 413l-188-125c0 37-17 71-44 94 64 38 107 107 107 187 0 121-98 219-219 219-121 0-219-98-219-219 0-61 25-117 66-156h-115c30 33 49 76 49 125 0 103-84 187-187 187s-188-84-188-187c0-57 26-107 65-141-38-22-65-62-65-109v-250c0-70 56-126 125-126h500c69 0 125 56 125 126l188-126c34 0 62 28 62 63v375c0 35-28 63-62 63z m-750 0c-69 0-125 56-125 125s56 125 125 125 125-56 125-125-56-125-125-125z m406-1c-87 0-157 70-157 157 0 86 70 156 157 156s156-70 156-156-70-157-156-157z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'question': {\n        'width': 857.1,\n        'height': 1000,\n        'path': 'm500 82v107q0 8-5 13t-13 5h-107q-8 0-13-5t-5-13v-107q0-8 5-13t13-5h107q8 0 13 5t5 13z m143 375q0 49-31 91t-77 65-95 23q-136 0-207-119-9-14 4-24l74-55q4-4 10-4 9 0 14 7 30 38 48 51 19 14 48 14 27 0 48-15t21-33q0-21-11-34t-38-25q-35-16-65-48t-29-70v-20q0-8 5-13t13-5h107q8 0 13 5t5 13q0 10 12 27t30 28q18 10 28 16t25 19 25 27 16 34 7 45z m214-107q0-117-57-215t-156-156-215-58-216 58-155 156-58 215 58 215 155 156 216 58 215-58 156-156 57-215z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'disk': {\n        'width': 857.1,\n        'height': 1000,\n        'path': 'm214-7h429v214h-429v-214z m500 0h72v500q0 8-6 21t-11 20l-157 156q-5 6-19 12t-22 5v-232q0-22-15-38t-38-16h-322q-22 0-37 16t-16 38v232h-72v-714h72v232q0 22 16 38t37 16h465q22 0 38-16t15-38v-232z m-214 518v178q0 8-5 13t-13 5h-107q-7 0-13-5t-5-13v-178q0-8 5-13t13-5h107q7 0 13 5t5 13z m357-18v-518q0-22-15-38t-38-16h-750q-23 0-38 16t-16 38v750q0 22 16 38t38 16h517q23 0 50-12t42-26l156-157q16-15 27-42t11-49z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'lasso': {\n        'width': 1031,\n        'height': 1000,\n        'path': 'm1018 538c-36 207-290 336-568 286-277-48-473-256-436-463 10-57 36-108 76-151-13-66 11-137 68-183 34-28 75-41 114-42l-55-70 0 0c-2-1-3-2-4-3-10-14-8-34 5-45 14-11 34-8 45 4 1 1 2 3 2 5l0 0 113 140c16 11 31 24 45 40 4 3 6 7 8 11 48-3 100 0 151 9 278 48 473 255 436 462z m-624-379c-80 14-149 48-197 96 42 42 109 47 156 9 33-26 47-66 41-105z m-187-74c-19 16-33 37-39 60 50-32 109-55 174-68-42-25-95-24-135 8z m360 75c-34-7-69-9-102-8 8 62-16 128-68 170-73 59-175 54-244-5-9 20-16 40-20 61-28 159 121 317 333 354s407-60 434-217c28-159-121-318-333-355z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'selectbox': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'm0 850l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m285 0l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m-857-286l0-143 143 0 0 143-143 0z m857 0l0-143 143 0 0 143-143 0z m-857-285l0-143 143 0 0 143-143 0z m857 0l0-143 143 0 0 143-143 0z m-857-286l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m285 0l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z',\n        'transform': 'matrix(1 0 0 -1 0 850)'\n    },\n    'spikeline': {\n        'width': 1000,\n        'height': 1000,\n        'path': 'M512 409c0-57-46-104-103-104-57 0-104 47-104 104 0 57 47 103 104 103 57 0 103-46 103-103z m-327-39l92 0 0 92-92 0z m-185 0l92 0 0 92-92 0z m370-186l92 0 0 93-92 0z m0-184l92 0 0 92-92 0z',\n        'transform': 'matrix(1.5 0 0 -1.5 0 850)'\n    },\n    'pencil': {\n        'width': 1792,\n        'height': 1792,\n        'path': 'M491 1536l91-91-235-235-91 91v107h128v128h107zm523-928q0-22-22-22-10 0-17 7l-542 542q-7 7-7 17 0 22 22 22 10 0 17-7l542-542q7-7 7-17zm-54-192l416 416-832 832h-416v-416zm683 96q0 53-37 90l-166 166-416-416 166-165q36-38 90-38 53 0 91 38l235 234q37 39 37 91z',\n        'transform': 'matrix(1 0 0 1 0 1)'\n    },\n    'newplotlylogo': {\n        'name': 'newplotlylogo',\n        'svg': '<svg xmlns=\\'http://www.w3.org/2000/svg\\' viewBox=\\'0 0 132 132\\'><defs><style>.cls-1 {fill: #119dff;} .cls-2 {fill: #25fefd;} .cls-3 {fill: #fff;}</style></defs><title>plotly-logomark</title><g id=\\'symbol\\'><rect class=\\'cls-1\\' width=\\'132\\' height=\\'132\\' rx=\\'6\\' ry=\\'6\\'/><circle class=\\'cls-2\\' cx=\\'78\\' cy=\\'54\\' r=\\'6\\'/><circle class=\\'cls-2\\' cx=\\'102\\' cy=\\'30\\' r=\\'6\\'/><circle class=\\'cls-2\\' cx=\\'78\\' cy=\\'30\\' r=\\'6\\'/><circle class=\\'cls-2\\' cx=\\'54\\' cy=\\'30\\' r=\\'6\\'/><circle class=\\'cls-2\\' cx=\\'30\\' cy=\\'30\\' r=\\'6\\'/><circle class=\\'cls-2\\' cx=\\'30\\' cy=\\'54\\' r=\\'6\\'/><path class=\\'cls-3\\' d=\\'M30,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,30,72Z\\'/><path class=\\'cls-3\\' d=\\'M78,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,78,72Z\\'/><path class=\\'cls-3\\' d=\\'M54,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,54,48Z\\'/><path class=\\'cls-3\\' d=\\'M102,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,102,48Z\\'/></g></svg>'\n    }\n};\n\n},{}],700:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\n/**\n * Determine the position anchor property of x/y xanchor/yanchor components.\n *\n * - values < 1/3 align the low side at that fraction,\n * - values [1/3, 2/3] align the center at that fraction,\n * - values > 2/3 align the right at that fraction.\n */\n\n\nexports.isLeftAnchor = function isLeftAnchor(opts) {\n    return (\n      opts.xanchor === 'left' ||\n      (opts.xanchor === 'auto' && opts.x <= 1 / 3)\n    );\n};\n\nexports.isCenterAnchor = function isCenterAnchor(opts) {\n    return (\n        opts.xanchor === 'center' ||\n        (opts.xanchor === 'auto' && opts.x > 1 / 3 && opts.x < 2 / 3)\n    );\n};\n\nexports.isRightAnchor = function isRightAnchor(opts) {\n    return (\n      opts.xanchor === 'right' ||\n      (opts.xanchor === 'auto' && opts.x >= 2 / 3)\n    );\n};\n\nexports.isTopAnchor = function isTopAnchor(opts) {\n    return (\n        opts.yanchor === 'top' ||\n        (opts.yanchor === 'auto' && opts.y >= 2 / 3)\n    );\n};\n\nexports.isMiddleAnchor = function isMiddleAnchor(opts) {\n    return (\n        opts.yanchor === 'middle' ||\n        (opts.yanchor === 'auto' && opts.y > 1 / 3 && opts.y < 2 / 3)\n    );\n};\n\nexports.isBottomAnchor = function isBottomAnchor(opts) {\n    return (\n      opts.yanchor === 'bottom' ||\n      (opts.yanchor === 'auto' && opts.y <= 1 / 3)\n    );\n};\n\n},{}],701:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar modModule = _dereq_('./mod');\nvar mod = modModule.mod;\nvar modHalf = modModule.modHalf;\n\nvar PI = Math.PI;\nvar twoPI = 2 * PI;\n\nfunction deg2rad(deg) { return deg / 180 * PI; }\n\nfunction rad2deg(rad) { return rad / PI * 180; }\n\n/**\n * is sector a full circle?\n * ... this comes up a lot in SVG path-drawing routines\n *\n * N.B. we consider all sectors that span more that 2pi 'full' circles\n *\n * @param {2-item array} aBnds : angular bounds in *radians*\n * @return {boolean}\n */\nfunction isFullCircle(aBnds) {\n    return Math.abs(aBnds[1] - aBnds[0]) > twoPI - 1e-14;\n}\n\n/**\n * angular delta between angle 'a' and 'b'\n * solution taken from: https://stackoverflow.com/a/2007279\n *\n * @param {number} a : first angle in *radians*\n * @param {number} b : second angle in *radians*\n * @return {number} angular delta in *radians*\n */\nfunction angleDelta(a, b) {\n    return modHalf(b - a, twoPI);\n}\n\n/**\n * angular distance between angle 'a' and 'b'\n *\n * @param {number} a : first angle in *radians*\n * @param {number} b : second angle in *radians*\n * @return {number} angular distance in *radians*\n */\nfunction angleDist(a, b) {\n    return Math.abs(angleDelta(a, b));\n}\n\n/**\n * is angle inside sector?\n *\n * @param {number} a : angle to test in *radians*\n * @param {2-item array} aBnds : sector's angular bounds in *radians*\n * @param {boolean}\n */\nfunction isAngleInsideSector(a, aBnds) {\n    if(isFullCircle(aBnds)) return true;\n\n    var s0, s1;\n\n    if(aBnds[0] < aBnds[1]) {\n        s0 = aBnds[0];\n        s1 = aBnds[1];\n    } else {\n        s0 = aBnds[1];\n        s1 = aBnds[0];\n    }\n\n    s0 = mod(s0, twoPI);\n    s1 = mod(s1, twoPI);\n    if(s0 > s1) s1 += twoPI;\n\n    var a0 = mod(a, twoPI);\n    var a1 = a0 + twoPI;\n\n    return (a0 >= s0 && a0 <= s1) || (a1 >= s0 && a1 <= s1);\n}\n\n/**\n * is pt (r,a) inside sector?\n *\n * @param {number} r : pt's radial coordinate\n * @param {number} a : pt's angular coordinate in *radians*\n * @param {2-item array} rBnds : sector's radial bounds\n * @param {2-item array} aBnds : sector's angular bounds in *radians*\n * @return {boolean}\n */\nfunction isPtInsideSector(r, a, rBnds, aBnds) {\n    if(!isAngleInsideSector(a, aBnds)) return false;\n\n    var r0, r1;\n\n    if(rBnds[0] < rBnds[1]) {\n        r0 = rBnds[0];\n        r1 = rBnds[1];\n    } else {\n        r0 = rBnds[1];\n        r1 = rBnds[0];\n    }\n\n    return r >= r0 && r <= r1;\n}\n\n// common to pathArc, pathSector and pathAnnulus\nfunction _path(r0, r1, a0, a1, cx, cy, isClosed) {\n    cx = cx || 0;\n    cy = cy || 0;\n\n    var isCircle = isFullCircle([a0, a1]);\n    var aStart, aMid, aEnd;\n    var rStart, rEnd;\n\n    if(isCircle) {\n        aStart = 0;\n        aMid = PI;\n        aEnd = twoPI;\n    } else {\n        if(a0 < a1) {\n            aStart = a0;\n            aEnd = a1;\n        } else {\n            aStart = a1;\n            aEnd = a0;\n        }\n    }\n\n    if(r0 < r1) {\n        rStart = r0;\n        rEnd = r1;\n    } else {\n        rStart = r1;\n        rEnd = r0;\n    }\n\n    // N.B. svg coordinates here, where y increases downward\n    function pt(r, a) {\n        return [r * Math.cos(a) + cx, cy - r * Math.sin(a)];\n    }\n\n    var largeArc = Math.abs(aEnd - aStart) <= PI ? 0 : 1;\n    function arc(r, a, cw) {\n        return 'A' + [r, r] + ' ' + [0, largeArc, cw] + ' ' + pt(r, a);\n    }\n\n    var p;\n\n    if(isCircle) {\n        if(rStart === null) {\n            p = 'M' + pt(rEnd, aStart) +\n                arc(rEnd, aMid, 0) +\n                arc(rEnd, aEnd, 0) + 'Z';\n        } else {\n            p = 'M' + pt(rStart, aStart) +\n                arc(rStart, aMid, 0) +\n                arc(rStart, aEnd, 0) + 'Z' +\n                'M' + pt(rEnd, aStart) +\n                arc(rEnd, aMid, 1) +\n                arc(rEnd, aEnd, 1) + 'Z';\n        }\n    } else {\n        if(rStart === null) {\n            p = 'M' + pt(rEnd, aStart) + arc(rEnd, aEnd, 0);\n            if(isClosed) p += 'L0,0Z';\n        } else {\n            p = 'M' + pt(rStart, aStart) +\n                'L' + pt(rEnd, aStart) +\n                arc(rEnd, aEnd, 0) +\n                'L' + pt(rStart, aEnd) +\n                arc(rStart, aStart, 1) + 'Z';\n        }\n    }\n\n    return p;\n}\n\n/**\n * path an arc\n *\n * @param {number} r : radius\n * @param {number} a0 : first angular coordinate in *radians*\n * @param {number} a1 : second angular coordinate in *radians*\n * @param {number (optional)} cx : x coordinate of center\n * @param {number (optional)} cy : y coordinate of center\n * @return {string} svg path\n */\nfunction pathArc(r, a0, a1, cx, cy) {\n    return _path(null, r, a0, a1, cx, cy, 0);\n}\n\n/**\n * path a sector\n *\n * @param {number} r : radius\n * @param {number} a0 : first angular coordinate in *radians*\n * @param {number} a1 : second angular coordinate in *radians*\n * @param {number (optional)} cx : x coordinate of center\n * @param {number (optional)} cy : y coordinate of center\n * @return {string} svg path\n */\nfunction pathSector(r, a0, a1, cx, cy) {\n    return _path(null, r, a0, a1, cx, cy, 1);\n}\n\n/**\n * path an annulus\n *\n * @param {number} r0 : first radial coordinate\n * @param {number} r1 : second radial coordinate\n * @param {number} a0 : first angular coordinate in *radians*\n * @param {number} a1 : second angular coordinate in *radians*\n * @param {number (optional)} cx : x coordinate of center\n * @param {number (optional)} cy : y coordinate of center\n * @return {string} svg path\n */\nfunction pathAnnulus(r0, r1, a0, a1, cx, cy) {\n    return _path(r0, r1, a0, a1, cx, cy, 1);\n}\n\nmodule.exports = {\n    deg2rad: deg2rad,\n    rad2deg: rad2deg,\n    angleDelta: angleDelta,\n    angleDist: angleDist,\n    isFullCircle: isFullCircle,\n    isAngleInsideSector: isAngleInsideSector,\n    isPtInsideSector: isPtInsideSector,\n    pathArc: pathArc,\n    pathSector: pathSector,\n    pathAnnulus: pathAnnulus\n};\n\n},{\"./mod\":726}],702:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isArray = Array.isArray;\n\n// IE9 fallbacks\n\nvar ab = (typeof ArrayBuffer === 'undefined' || !ArrayBuffer.isView) ?\n    {isView: function() { return false; }} :\n    ArrayBuffer;\n\nvar dv = (typeof DataView === 'undefined') ?\n    function() {} :\n    DataView;\n\nfunction isTypedArray(a) {\n    return ab.isView(a) && !(a instanceof dv);\n}\nexports.isTypedArray = isTypedArray;\n\nfunction isArrayOrTypedArray(a) {\n    return isArray(a) || isTypedArray(a);\n}\nexports.isArrayOrTypedArray = isArrayOrTypedArray;\n\n/*\n * Test whether an input object is 1D.\n *\n * Assumes we already know the object is an array.\n *\n * Looks only at the first element, if the dimensionality is\n * not consistent we won't figure that out here.\n */\nfunction isArray1D(a) {\n    return !isArrayOrTypedArray(a[0]);\n}\nexports.isArray1D = isArray1D;\n\n/*\n * Ensures an array has the right amount of storage space. If it doesn't\n * exist, it creates an array. If it does exist, it returns it if too\n * short or truncates it in-place.\n *\n * The goal is to just reuse memory to avoid a bit of excessive garbage\n * collection.\n */\nexports.ensureArray = function(out, n) {\n    // TODO: typed array support here? This is only used in\n    // traces/carpet/compute_control_points\n    if(!isArray(out)) out = [];\n\n    // If too long, truncate. (If too short, it will grow\n    // automatically so we don't care about that case)\n    out.length = n;\n\n    return out;\n};\n\n/*\n * TypedArray-compatible concatenation of n arrays\n * if all arrays are the same type it will preserve that type,\n * otherwise it falls back on Array.\n * Also tries to avoid copying, in case one array has zero length\n * But never mutates an existing array\n */\nexports.concat = function() {\n    var args = [];\n    var allArray = true;\n    var totalLen = 0;\n\n    var _constructor, arg0, i, argi, posi, leni, out, j;\n\n    for(i = 0; i < arguments.length; i++) {\n        argi = arguments[i];\n        leni = argi.length;\n        if(leni) {\n            if(arg0) args.push(argi);\n            else {\n                arg0 = argi;\n                posi = leni;\n            }\n\n            if(isArray(argi)) {\n                _constructor = false;\n            } else {\n                allArray = false;\n                if(!totalLen) {\n                    _constructor = argi.constructor;\n                } else if(_constructor !== argi.constructor) {\n                    // TODO: in principle we could upgrade here,\n                    // ie keep typed array but convert all to Float64Array?\n                    _constructor = false;\n                }\n            }\n\n            totalLen += leni;\n        }\n    }\n\n    if(!totalLen) return [];\n    if(!args.length) return arg0;\n\n    if(allArray) return arg0.concat.apply(arg0, args);\n    if(_constructor) {\n        // matching typed arrays\n        out = new _constructor(totalLen);\n        out.set(arg0);\n        for(i = 0; i < args.length; i++) {\n            argi = args[i];\n            out.set(argi, posi);\n            posi += argi.length;\n        }\n        return out;\n    }\n\n    // mismatched types or Array + typed\n    out = new Array(totalLen);\n    for(j = 0; j < arg0.length; j++) out[j] = arg0[j];\n    for(i = 0; i < args.length; i++) {\n        argi = args[i];\n        for(j = 0; j < argi.length; j++) out[posi + j] = argi[j];\n        posi += j;\n    }\n    return out;\n};\n\nexports.maxRowLength = function(z) {\n    return _rowLength(z, Math.max, 0);\n};\n\nexports.minRowLength = function(z) {\n    return _rowLength(z, Math.min, Infinity);\n};\n\nfunction _rowLength(z, fn, len0) {\n    if(isArrayOrTypedArray(z)) {\n        if(isArrayOrTypedArray(z[0])) {\n            var len = len0;\n            for(var i = 0; i < z.length; i++) {\n                len = fn(len, z[i].length);\n            }\n            return len;\n        } else {\n            return z.length;\n        }\n    }\n    return 0;\n}\n\n},{}],703:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar BADNUM = _dereq_('../constants/numerical').BADNUM;\n\n// precompile for speed\nvar JUNK = /^['\"%,$#\\s']+|[, ]|['\"%,$#\\s']+$/g;\n\n/**\n * cleanNumber: remove common leading and trailing cruft\n * Always returns either a number or BADNUM.\n */\nmodule.exports = function cleanNumber(v) {\n    if(typeof v === 'string') {\n        v = v.replace(JUNK, '');\n    }\n\n    if(isNumeric(v)) return Number(v);\n\n    return BADNUM;\n};\n\n},{\"../constants/numerical\":695,\"fast-isnumeric\":225}],704:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * Clear gl frame (if any). This is a common pattern as\n * we usually set `preserveDrawingBuffer: true` during\n * gl context creation (e.g. via `reglUtils.prepare`).\n *\n * @param {DOM node or object} gd : graph div object\n */\nmodule.exports = function clearGlCanvases(gd) {\n    var fullLayout = gd._fullLayout;\n\n    if(fullLayout._glcanvas && fullLayout._glcanvas.size()) {\n        fullLayout._glcanvas.each(function(d) {\n            if(d.regl) d.regl.clear({color: true, depth: true});\n        });\n    }\n};\n\n},{}],705:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * Clear responsive handlers (if any).\n *\n * @param {DOM node or object} gd : graph div object\n */\nmodule.exports = function clearResponsive(gd) {\n    if(gd._responsiveChartHandler) {\n        window.removeEventListener('resize', gd._responsiveChartHandler);\n        delete gd._responsiveChartHandler;\n    }\n};\n\n},{}],706:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar tinycolor = _dereq_('tinycolor2');\n\nvar baseTraceAttrs = _dereq_('../plots/attributes');\nvar colorscales = _dereq_('../components/colorscale/scales');\nvar DESELECTDIM = _dereq_('../constants/interactions').DESELECTDIM;\n\nvar nestedProperty = _dereq_('./nested_property');\nvar counterRegex = _dereq_('./regex').counter;\nvar modHalf = _dereq_('./mod').modHalf;\nvar isArrayOrTypedArray = _dereq_('./array').isArrayOrTypedArray;\n\nexports.valObjectMeta = {\n    data_array: {\n        // You can use *dflt=[] to force said array to exist though.\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt) {\n            // TODO maybe `v: {type: 'float32', vals: [/* ... */]}` also\n            if(isArrayOrTypedArray(v)) propOut.set(v);\n            else if(dflt !== undefined) propOut.set(dflt);\n        }\n    },\n    enumerated: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt, opts) {\n            if(opts.coerceNumber) v = +v;\n            if(opts.values.indexOf(v) === -1) propOut.set(dflt);\n            else propOut.set(v);\n        },\n        validateFunction: function(v, opts) {\n            if(opts.coerceNumber) v = +v;\n\n            var values = opts.values;\n            for(var i = 0; i < values.length; i++) {\n                var k = String(values[i]);\n\n                if((k.charAt(0) === '/' && k.charAt(k.length - 1) === '/')) {\n                    var regex = new RegExp(k.substr(1, k.length - 2));\n                    if(regex.test(v)) return true;\n                } else if(v === values[i]) return true;\n            }\n            return false;\n        }\n    },\n    'boolean': {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt) {\n            if(v === true || v === false) propOut.set(v);\n            else propOut.set(dflt);\n        }\n    },\n    number: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt, opts) {\n            if(!isNumeric(v) ||\n                    (opts.min !== undefined && v < opts.min) ||\n                    (opts.max !== undefined && v > opts.max)) {\n                propOut.set(dflt);\n            } else propOut.set(+v);\n        }\n    },\n    integer: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt, opts) {\n            if(v % 1 || !isNumeric(v) ||\n                    (opts.min !== undefined && v < opts.min) ||\n                    (opts.max !== undefined && v > opts.max)) {\n                propOut.set(dflt);\n            } else propOut.set(+v);\n        }\n    },\n    string: {\n        \n        \n        // TODO 'values shouldn't be in there (edge case: 'dash' in Scatter)\n        \n        coerceFunction: function(v, propOut, dflt, opts) {\n            if(typeof v !== 'string') {\n                var okToCoerce = (typeof v === 'number');\n\n                if(opts.strict === true || !okToCoerce) propOut.set(dflt);\n                else propOut.set(String(v));\n            } else if(opts.noBlank && !v) propOut.set(dflt);\n            else propOut.set(v);\n        }\n    },\n    color: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt) {\n            if(tinycolor(v).isValid()) propOut.set(v);\n            else propOut.set(dflt);\n        }\n    },\n    colorlist: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt) {\n            function isColor(color) {\n                return tinycolor(color).isValid();\n            }\n            if(!Array.isArray(v) || !v.length) propOut.set(dflt);\n            else if(v.every(isColor)) propOut.set(v);\n            else propOut.set(dflt);\n        }\n    },\n    colorscale: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt) {\n            propOut.set(colorscales.get(v, dflt));\n        }\n    },\n    angle: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt) {\n            if(v === 'auto') propOut.set('auto');\n            else if(!isNumeric(v)) propOut.set(dflt);\n            else propOut.set(modHalf(+v, 360));\n        }\n    },\n    subplotid: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt, opts) {\n            var regex = opts.regex || counterRegex(dflt);\n            if(typeof v === 'string' && regex.test(v)) {\n                propOut.set(v);\n                return;\n            }\n            propOut.set(dflt);\n        },\n        validateFunction: function(v, opts) {\n            var dflt = opts.dflt;\n\n            if(v === dflt) return true;\n            if(typeof v !== 'string') return false;\n            if(counterRegex(dflt).test(v)) return true;\n\n            return false;\n        }\n    },\n    flaglist: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt, opts) {\n            if(typeof v !== 'string') {\n                propOut.set(dflt);\n                return;\n            }\n            if((opts.extras || []).indexOf(v) !== -1) {\n                propOut.set(v);\n                return;\n            }\n            var vParts = v.split('+');\n            var i = 0;\n            while(i < vParts.length) {\n                var vi = vParts[i];\n                if(opts.flags.indexOf(vi) === -1 || vParts.indexOf(vi) < i) {\n                    vParts.splice(i, 1);\n                } else i++;\n            }\n            if(!vParts.length) propOut.set(dflt);\n            else propOut.set(vParts.join('+'));\n        }\n    },\n    any: {\n        \n        \n        \n        coerceFunction: function(v, propOut, dflt) {\n            if(v === undefined) propOut.set(dflt);\n            else propOut.set(v);\n        }\n    },\n    info_array: {\n        \n        \n        // set `dimensions=2` for a 2D array or '1-2' for either\n        // `items` may be a single object instead of an array, in which case\n        // `freeLength` must be true.\n        // if `dimensions='1-2'` and items is a 1D array, then the value can\n        // either be a matching 1D array or an array of such matching 1D arrays\n        \n        coerceFunction: function(v, propOut, dflt, opts) {\n            // simplified coerce function just for array items\n            function coercePart(v, opts, dflt) {\n                var out;\n                var propPart = {set: function(v) { out = v; }};\n\n                if(dflt === undefined) dflt = opts.dflt;\n\n                exports.valObjectMeta[opts.valType].coerceFunction(v, propPart, dflt, opts);\n\n                return out;\n            }\n\n            var twoD = opts.dimensions === 2 || (opts.dimensions === '1-2' && Array.isArray(v) && Array.isArray(v[0]));\n\n            if(!Array.isArray(v)) {\n                propOut.set(dflt);\n                return;\n            }\n\n            var items = opts.items;\n            var vOut = [];\n            var arrayItems = Array.isArray(items);\n            var arrayItems2D = arrayItems && twoD && Array.isArray(items[0]);\n            var innerItemsOnly = twoD && arrayItems && !arrayItems2D;\n            var len = (arrayItems && !innerItemsOnly) ? items.length : v.length;\n\n            var i, j, row, item, len2, vNew;\n\n            dflt = Array.isArray(dflt) ? dflt : [];\n\n            if(twoD) {\n                for(i = 0; i < len; i++) {\n                    vOut[i] = [];\n                    row = Array.isArray(v[i]) ? v[i] : [];\n                    if(innerItemsOnly) len2 = items.length;\n                    else if(arrayItems) len2 = items[i].length;\n                    else len2 = row.length;\n\n                    for(j = 0; j < len2; j++) {\n                        if(innerItemsOnly) item = items[j];\n                        else if(arrayItems) item = items[i][j];\n                        else item = items;\n\n                        vNew = coercePart(row[j], item, (dflt[i] || [])[j]);\n                        if(vNew !== undefined) vOut[i][j] = vNew;\n                    }\n                }\n            } else {\n                for(i = 0; i < len; i++) {\n                    vNew = coercePart(v[i], arrayItems ? items[i] : items, dflt[i]);\n                    if(vNew !== undefined) vOut[i] = vNew;\n                }\n            }\n\n            propOut.set(vOut);\n        },\n        validateFunction: function(v, opts) {\n            if(!Array.isArray(v)) return false;\n\n            var items = opts.items;\n            var arrayItems = Array.isArray(items);\n            var twoD = opts.dimensions === 2;\n\n            // when free length is off, input and declared lengths must match\n            if(!opts.freeLength && v.length !== items.length) return false;\n\n            // valid when all input items are valid\n            for(var i = 0; i < v.length; i++) {\n                if(twoD) {\n                    if(!Array.isArray(v[i]) || (!opts.freeLength && v[i].length !== items[i].length)) {\n                        return false;\n                    }\n                    for(var j = 0; j < v[i].length; j++) {\n                        if(!validate(v[i][j], arrayItems ? items[i][j] : items)) {\n                            return false;\n                        }\n                    }\n                } else if(!validate(v[i], arrayItems ? items[i] : items)) return false;\n            }\n\n            return true;\n        }\n    }\n};\n\n/**\n * Ensures that container[attribute] has a valid value.\n *\n * attributes[attribute] is an object with possible keys:\n * - valType: data_array, enumerated, boolean, ... as in valObjectMeta\n * - values: (enumerated only) array of allowed vals\n * - min, max: (number, integer only) inclusive bounds on allowed vals\n *      either or both may be omitted\n * - dflt: if attribute is invalid or missing, use this default\n *      if dflt is provided as an argument to lib.coerce it takes precedence\n *      as a convenience, returns the value it finally set\n */\nexports.coerce = function(containerIn, containerOut, attributes, attribute, dflt) {\n    var opts = nestedProperty(attributes, attribute).get();\n    var propIn = nestedProperty(containerIn, attribute);\n    var propOut = nestedProperty(containerOut, attribute);\n    var v = propIn.get();\n\n    var template = containerOut._template;\n    if(v === undefined && template) {\n        v = nestedProperty(template, attribute).get();\n        // already used the template value, so short-circuit the second check\n        template = 0;\n    }\n\n    if(dflt === undefined) dflt = opts.dflt;\n\n    /**\n     * arrayOk: value MAY be an array, then we do no value checking\n     * at this point, because it can be more complicated than the\n     * individual form (eg. some array vals can be numbers, even if the\n     * single values must be color strings)\n     */\n    if(opts.arrayOk && isArrayOrTypedArray(v)) {\n        propOut.set(v);\n        return v;\n    }\n\n    var coerceFunction = exports.valObjectMeta[opts.valType].coerceFunction;\n    coerceFunction(v, propOut, dflt, opts);\n\n    var out = propOut.get();\n    // in case v was provided but invalid, try the template again so it still\n    // overrides the regular default\n    if(template && out === dflt && !validate(v, opts)) {\n        v = nestedProperty(template, attribute).get();\n        coerceFunction(v, propOut, dflt, opts);\n        out = propOut.get();\n    }\n    return out;\n};\n\n/**\n * Variation on coerce\n *\n * Uses coerce to get attribute value if user input is valid,\n * returns attribute default if user input it not valid or\n * returns false if there is no user input.\n */\nexports.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) {\n    var propIn = nestedProperty(containerIn, attribute);\n    var propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt);\n    var valIn = propIn.get();\n\n    return (valIn !== undefined && valIn !== null) ? propOut : false;\n};\n\n/*\n * Shortcut to coerce the three font attributes\n *\n * 'coerce' is a lib.coerce wrapper with implied first three arguments\n */\nexports.coerceFont = function(coerce, attr, dfltObj) {\n    var out = {};\n\n    dfltObj = dfltObj || {};\n\n    out.family = coerce(attr + '.family', dfltObj.family);\n    out.size = coerce(attr + '.size', dfltObj.size);\n    out.color = coerce(attr + '.color', dfltObj.color);\n\n    return out;\n};\n\n/** Coerce shortcut for 'hoverinfo'\n * handling 1-vs-multi-trace dflt logic\n *\n * @param {object} traceIn : user trace object\n * @param {object} traceOut : full trace object (requires _module ref)\n * @param {object} layoutOut : full layout object (require _dataLength ref)\n * @return {any} : the coerced value\n */\nexports.coerceHoverinfo = function(traceIn, traceOut, layoutOut) {\n    var moduleAttrs = traceOut._module.attributes;\n    var attrs = moduleAttrs.hoverinfo ? moduleAttrs : baseTraceAttrs;\n\n    var valObj = attrs.hoverinfo;\n    var dflt;\n\n    if(layoutOut._dataLength === 1) {\n        var flags = valObj.dflt === 'all' ?\n            valObj.flags.slice() :\n            valObj.dflt.split('+');\n\n        flags.splice(flags.indexOf('name'), 1);\n        dflt = flags.join('+');\n    }\n\n    return exports.coerce(traceIn, traceOut, attrs, 'hoverinfo', dflt);\n};\n\n/** Coerce shortcut for [un]selected.marker.opacity,\n *  which has special default logic, to ensure that it corresponds to the\n *  default selection behavior while allowing to be overtaken by any other\n *  [un]selected attribute.\n *\n *  N.B. This must be called *after* coercing all the other [un]selected attrs,\n *  to give the intended result.\n *\n * @param {object} traceOut : fullData item\n * @param {function} coerce : lib.coerce wrapper with implied first three arguments\n */\nexports.coerceSelectionMarkerOpacity = function(traceOut, coerce) {\n    if(!traceOut.marker) return;\n\n    var mo = traceOut.marker.opacity;\n    // you can still have a `marker` container with no markers if there's text\n    if(mo === undefined) return;\n\n    var smoDflt;\n    var usmoDflt;\n\n    // Don't give [un]selected.marker.opacity a default value if\n    // marker.opacity is an array: handle this during style step.\n    //\n    // Only give [un]selected.marker.opacity a default value if you don't\n    // set any other [un]selected attributes.\n    if(!isArrayOrTypedArray(mo) && !traceOut.selected && !traceOut.unselected) {\n        smoDflt = mo;\n        usmoDflt = DESELECTDIM * mo;\n    }\n\n    coerce('selected.marker.opacity', smoDflt);\n    coerce('unselected.marker.opacity', usmoDflt);\n};\n\nfunction validate(value, opts) {\n    var valObjectDef = exports.valObjectMeta[opts.valType];\n\n    if(opts.arrayOk && isArrayOrTypedArray(value)) return true;\n\n    if(valObjectDef.validateFunction) {\n        return valObjectDef.validateFunction(value, opts);\n    }\n\n    var failed = {};\n    var out = failed;\n    var propMock = { set: function(v) { out = v; } };\n\n    // 'failed' just something mutable that won't be === anything else\n\n    valObjectDef.coerceFunction(value, propMock, failed, opts);\n    return out !== failed;\n}\nexports.validate = validate;\n\n},{\"../components/colorscale/scales\":608,\"../constants/interactions\":694,\"../plots/attributes\":764,\"./array\":702,\"./mod\":726,\"./nested_property\":727,\"./regex\":735,\"fast-isnumeric\":225,\"tinycolor2\":537}],707:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Loggers = _dereq_('./loggers');\nvar mod = _dereq_('./mod').mod;\n\nvar constants = _dereq_('../constants/numerical');\nvar BADNUM = constants.BADNUM;\nvar ONEDAY = constants.ONEDAY;\nvar ONEHOUR = constants.ONEHOUR;\nvar ONEMIN = constants.ONEMIN;\nvar ONESEC = constants.ONESEC;\nvar EPOCHJD = constants.EPOCHJD;\n\nvar Registry = _dereq_('../registry');\n\nvar utcFormat = d3.time.format.utc;\n\nvar DATETIME_REGEXP = /^\\s*(-?\\d\\d\\d\\d|\\d\\d)(-(\\d?\\d)(-(\\d?\\d)([ Tt]([01]?\\d|2[0-3])(:([0-5]\\d)(:([0-5]\\d(\\.\\d+)?))?(Z|z|[+\\-]\\d\\d:?\\d\\d)?)?)?)?)?\\s*$/m;\n// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months\nvar DATETIME_REGEXP_CN = /^\\s*(-?\\d\\d\\d\\d|\\d\\d)(-(\\d?\\di?)(-(\\d?\\d)([ Tt]([01]?\\d|2[0-3])(:([0-5]\\d)(:([0-5]\\d(\\.\\d+)?))?(Z|z|[+\\-]\\d\\d:?\\d\\d)?)?)?)?)?\\s*$/m;\n\n// for 2-digit years, the first year we map them onto\nvar YFIRST = new Date().getFullYear() - 70;\n\nfunction isWorldCalendar(calendar) {\n    return (\n        calendar &&\n        Registry.componentsRegistry.calendars &&\n        typeof calendar === 'string' && calendar !== 'gregorian'\n    );\n}\n\n/*\n * dateTick0: get the canonical tick for this calendar\n *\n * bool sunday is for week ticks, shift it to a Sunday.\n */\nexports.dateTick0 = function(calendar, sunday) {\n    if(isWorldCalendar(calendar)) {\n        return sunday ?\n            Registry.getComponentMethod('calendars', 'CANONICAL_SUNDAY')[calendar] :\n            Registry.getComponentMethod('calendars', 'CANONICAL_TICK')[calendar];\n    } else {\n        return sunday ? '2000-01-02' : '2000-01-01';\n    }\n};\n\n/*\n * dfltRange: for each calendar, give a valid default range\n */\nexports.dfltRange = function(calendar) {\n    if(isWorldCalendar(calendar)) {\n        return Registry.getComponentMethod('calendars', 'DFLTRANGE')[calendar];\n    } else {\n        return ['2000-01-01', '2001-01-01'];\n    }\n};\n\n// is an object a javascript date?\nexports.isJSDate = function(v) {\n    return typeof v === 'object' && v !== null && typeof v.getTime === 'function';\n};\n\n// The absolute limits of our date-time system\n// This is a little weird: we use MIN_MS and MAX_MS in dateTime2ms\n// but we use dateTime2ms to calculate them (after defining it!)\nvar MIN_MS, MAX_MS;\n\n/**\n * dateTime2ms - turn a date object or string s into milliseconds\n * (relative to 1970-01-01, per javascript standard)\n * optional calendar (string) to use a non-gregorian calendar\n *\n * Returns BADNUM if it doesn't find a date\n *\n * strings should have the form:\n *\n *    -?YYYY-mm-dd<sep>HH:MM:SS.sss<tzInfo>?\n *\n * <sep>: space (our normal standard) or T or t (ISO-8601)\n * <tzInfo>: Z, z, or [+\\-]HH:?MM and we THROW IT AWAY\n * this format comes from https://tools.ietf.org/html/rfc3339#section-5.6\n * but we allow it even with a space as the separator\n *\n * May truncate after any full field, and sss can be any length\n * even >3 digits, though javascript dates truncate to milliseconds,\n * we keep as much as javascript numeric precision can hold, but we only\n * report back up to 100 microsecond precision, because most dates support\n * this precision (close to 1970 support more, very far away support less)\n *\n * Expanded to support negative years to -9999 but you must always\n * give 4 digits, except for 2-digit positive years which we assume are\n * near the present time.\n * Note that we follow ISO 8601:2004: there *is* a year 0, which\n * is 1BC/BCE, and -1===2BC etc.\n *\n * World calendars: not all of these *have* agreed extensions to this full range,\n * if you have another calendar system but want a date range outside its validity,\n * you can use a gregorian date string prefixed with 'G' or 'g'.\n *\n * Where to cut off 2-digit years between 1900s and 2000s?\n * from http://support.microsoft.com/kb/244664:\n *   1930-2029 (the most retro of all...)\n * but in my mac chrome from eg. d=new Date(Date.parse('8/19/50')):\n *   1950-2049\n * by Java, from http://stackoverflow.com/questions/2024273/:\n *   now-80 - now+19\n * or FileMaker Pro, from\n *      http://www.filemaker.com/12help/html/add_view_data.4.21.html:\n *   now-70 - now+29\n * but python strptime etc, via\n *      http://docs.python.org/py3k/library/time.html:\n *   1969-2068 (super forward-looking, but static, not sliding!)\n *\n * lets go with now-70 to now+29, and if anyone runs into this problem\n * they can learn the hard way not to use 2-digit years, as no choice we\n * make now will cover all possibilities. mostly this will all be taken\n * care of in initial parsing, should only be an issue for hand-entered data\n * currently (2016) this range is:\n *   1946-2045\n */\nexports.dateTime2ms = function(s, calendar) {\n    // first check if s is a date object\n    if(exports.isJSDate(s)) {\n        // Convert to the UTC milliseconds that give the same\n        // hours as this date has in the local timezone\n        var tzOffset = s.getTimezoneOffset() * ONEMIN;\n        var offsetTweak = (s.getUTCMinutes() - s.getMinutes()) * ONEMIN +\n            (s.getUTCSeconds() - s.getSeconds()) * ONESEC +\n            (s.getUTCMilliseconds() - s.getMilliseconds());\n\n        if(offsetTweak) {\n            var comb = 3 * ONEMIN;\n            tzOffset = tzOffset - comb / 2 + mod(offsetTweak - tzOffset + comb / 2, comb);\n        }\n        s = Number(s) - tzOffset;\n        if(s >= MIN_MS && s <= MAX_MS) return s;\n        return BADNUM;\n    }\n    // otherwise only accept strings and numbers\n    if(typeof s !== 'string' && typeof s !== 'number') return BADNUM;\n\n    s = String(s);\n\n    var isWorld = isWorldCalendar(calendar);\n\n    // to handle out-of-range dates in international calendars, accept\n    // 'G' as a prefix to force the built-in gregorian calendar.\n    var s0 = s.charAt(0);\n    if(isWorld && (s0 === 'G' || s0 === 'g')) {\n        s = s.substr(1);\n        calendar = '';\n    }\n\n    var isChinese = isWorld && calendar.substr(0, 7) === 'chinese';\n\n    var match = s.match(isChinese ? DATETIME_REGEXP_CN : DATETIME_REGEXP);\n    if(!match) return BADNUM;\n    var y = match[1];\n    var m = match[3] || '1';\n    var d = Number(match[5] || 1);\n    var H = Number(match[7] || 0);\n    var M = Number(match[9] || 0);\n    var S = Number(match[11] || 0);\n\n    if(isWorld) {\n        // disallow 2-digit years for world calendars\n        if(y.length === 2) return BADNUM;\n        y = Number(y);\n\n        var cDate;\n        try {\n            var calInstance = Registry.getComponentMethod('calendars', 'getCal')(calendar);\n            if(isChinese) {\n                var isIntercalary = m.charAt(m.length - 1) === 'i';\n                m = parseInt(m, 10);\n                cDate = calInstance.newDate(y, calInstance.toMonthIndex(y, m, isIntercalary), d);\n            } else {\n                cDate = calInstance.newDate(y, Number(m), d);\n            }\n        } catch(e) { return BADNUM; } // Invalid ... date\n\n        if(!cDate) return BADNUM;\n\n        return ((cDate.toJD() - EPOCHJD) * ONEDAY) +\n            (H * ONEHOUR) + (M * ONEMIN) + (S * ONESEC);\n    }\n\n    if(y.length === 2) {\n        y = (Number(y) + 2000 - YFIRST) % 100 + YFIRST;\n    } else y = Number(y);\n\n    // new Date uses months from 0; subtract 1 here just so we\n    // don't have to do it again during the validity test below\n    m -= 1;\n\n    // javascript takes new Date(0..99,m,d) to mean 1900-1999, so\n    // to support years 0-99 we need to use setFullYear explicitly\n    // Note that 2000 is a leap year.\n    var date = new Date(Date.UTC(2000, m, d, H, M));\n    date.setUTCFullYear(y);\n\n    if(date.getUTCMonth() !== m) return BADNUM;\n    if(date.getUTCDate() !== d) return BADNUM;\n\n    return date.getTime() + S * ONESEC;\n};\n\nMIN_MS = exports.MIN_MS = exports.dateTime2ms('-9999');\nMAX_MS = exports.MAX_MS = exports.dateTime2ms('9999-12-31 23:59:59.9999');\n\n// is string s a date? (see above)\nexports.isDateTime = function(s, calendar) {\n    return (exports.dateTime2ms(s, calendar) !== BADNUM);\n};\n\n// pad a number with zeroes, to given # of digits before the decimal point\nfunction lpad(val, digits) {\n    return String(val + Math.pow(10, digits)).substr(1);\n}\n\n/**\n * Turn ms into string of the form YYYY-mm-dd HH:MM:SS.ssss\n * Crop any trailing zeros in time, except never stop right after hours\n * (we could choose to crop '-01' from date too but for now we always\n * show the whole date)\n * Optional range r is the data range that applies, also in ms.\n * If rng is big, the later parts of time will be omitted\n */\nvar NINETYDAYS = 90 * ONEDAY;\nvar THREEHOURS = 3 * ONEHOUR;\nvar FIVEMIN = 5 * ONEMIN;\nexports.ms2DateTime = function(ms, r, calendar) {\n    if(typeof ms !== 'number' || !(ms >= MIN_MS && ms <= MAX_MS)) return BADNUM;\n\n    if(!r) r = 0;\n\n    var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);\n    var msRounded = Math.round(ms - msecTenths / 10);\n    var dateStr, h, m, s, msec10, d;\n\n    if(isWorldCalendar(calendar)) {\n        var dateJD = Math.floor(msRounded / ONEDAY) + EPOCHJD;\n        var timeMs = Math.floor(mod(ms, ONEDAY));\n        try {\n            dateStr = Registry.getComponentMethod('calendars', 'getCal')(calendar)\n                .fromJD(dateJD).formatDate('yyyy-mm-dd');\n        } catch(e) {\n            // invalid date in this calendar - fall back to Gyyyy-mm-dd\n            dateStr = utcFormat('G%Y-%m-%d')(new Date(msRounded));\n        }\n\n        // yyyy does NOT guarantee 4-digit years. YYYY mostly does, but does\n        // other things for a few calendars, so we can't trust it. Just pad\n        // it manually (after the '-' if there is one)\n        if(dateStr.charAt(0) === '-') {\n            while(dateStr.length < 11) dateStr = '-0' + dateStr.substr(1);\n        } else {\n            while(dateStr.length < 10) dateStr = '0' + dateStr;\n        }\n\n        // TODO: if this is faster, we could use this block for extracting\n        // the time components of regular gregorian too\n        h = (r < NINETYDAYS) ? Math.floor(timeMs / ONEHOUR) : 0;\n        m = (r < NINETYDAYS) ? Math.floor((timeMs % ONEHOUR) / ONEMIN) : 0;\n        s = (r < THREEHOURS) ? Math.floor((timeMs % ONEMIN) / ONESEC) : 0;\n        msec10 = (r < FIVEMIN) ? (timeMs % ONESEC) * 10 + msecTenths : 0;\n    } else {\n        d = new Date(msRounded);\n\n        dateStr = utcFormat('%Y-%m-%d')(d);\n\n        // <90 days: add hours and minutes - never *only* add hours\n        h = (r < NINETYDAYS) ? d.getUTCHours() : 0;\n        m = (r < NINETYDAYS) ? d.getUTCMinutes() : 0;\n        // <3 hours: add seconds\n        s = (r < THREEHOURS) ? d.getUTCSeconds() : 0;\n        // <5 minutes: add ms (plus one extra digit, this is msec*10)\n        msec10 = (r < FIVEMIN) ? d.getUTCMilliseconds() * 10 + msecTenths : 0;\n    }\n\n    return includeTime(dateStr, h, m, s, msec10);\n};\n\n// For converting old-style milliseconds to date strings,\n// we use the local timezone rather than UTC like we use\n// everywhere else, both for backward compatibility and\n// because that's how people mostly use javasript date objects.\n// Clip one extra day off our date range though so we can't get\n// thrown beyond the range by the timezone shift.\nexports.ms2DateTimeLocal = function(ms) {\n    if(!(ms >= MIN_MS + ONEDAY && ms <= MAX_MS - ONEDAY)) return BADNUM;\n\n    var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);\n    var d = new Date(Math.round(ms - msecTenths / 10));\n    var dateStr = d3.time.format('%Y-%m-%d')(d);\n    var h = d.getHours();\n    var m = d.getMinutes();\n    var s = d.getSeconds();\n    var msec10 = d.getUTCMilliseconds() * 10 + msecTenths;\n\n    return includeTime(dateStr, h, m, s, msec10);\n};\n\nfunction includeTime(dateStr, h, m, s, msec10) {\n    // include each part that has nonzero data in or after it\n    if(h || m || s || msec10) {\n        dateStr += ' ' + lpad(h, 2) + ':' + lpad(m, 2);\n        if(s || msec10) {\n            dateStr += ':' + lpad(s, 2);\n            if(msec10) {\n                var digits = 4;\n                while(msec10 % 10 === 0) {\n                    digits -= 1;\n                    msec10 /= 10;\n                }\n                dateStr += '.' + lpad(msec10, digits);\n            }\n        }\n    }\n    return dateStr;\n}\n\n// normalize date format to date string, in case it starts as\n// a Date object or milliseconds\n// optional dflt is the return value if cleaning fails\nexports.cleanDate = function(v, dflt, calendar) {\n    // let us use cleanDate to provide a missing default without an error\n    if(v === BADNUM) return dflt;\n    if(exports.isJSDate(v) || (typeof v === 'number' && isFinite(v))) {\n        // do not allow milliseconds (old) or jsdate objects (inherently\n        // described as gregorian dates) with world calendars\n        if(isWorldCalendar(calendar)) {\n            Loggers.error('JS Dates and milliseconds are incompatible with world calendars', v);\n            return dflt;\n        }\n\n        // NOTE: if someone puts in a year as a number rather than a string,\n        // this will mistakenly convert it thinking it's milliseconds from 1970\n        // that is: '2012' -> Jan. 1, 2012, but 2012 -> 2012 epoch milliseconds\n        v = exports.ms2DateTimeLocal(+v);\n        if(!v && dflt !== undefined) return dflt;\n    } else if(!exports.isDateTime(v, calendar)) {\n        Loggers.error('unrecognized date', v);\n        return dflt;\n    }\n    return v;\n};\n\n/*\n *  Date formatting for ticks and hovertext\n */\n\n/*\n * modDateFormat: Support world calendars, and add one item to\n * d3's vocabulary:\n * %{n}f where n is the max number of digits of fractional seconds\n */\nvar fracMatch = /%\\d?f/g;\nfunction modDateFormat(fmt, x, formatter, calendar) {\n    fmt = fmt.replace(fracMatch, function(match) {\n        var digits = Math.min(+(match.charAt(1)) || 6, 6);\n        var fracSecs = ((x / 1000 % 1) + 2)\n            .toFixed(digits)\n            .substr(2).replace(/0+$/, '') || '0';\n        return fracSecs;\n    });\n\n    var d = new Date(Math.floor(x + 0.05));\n\n    if(isWorldCalendar(calendar)) {\n        try {\n            fmt = Registry.getComponentMethod('calendars', 'worldCalFmt')(fmt, x, calendar);\n        } catch(e) {\n            return 'Invalid';\n        }\n    }\n    return formatter(fmt)(d);\n}\n\n/*\n * formatTime: create a time string from:\n *   x: milliseconds\n *   tr: tickround ('M', 'S', or # digits)\n * only supports UTC times (where every day is 24 hours and 0 is at midnight)\n */\nvar MAXSECONDS = [59, 59.9, 59.99, 59.999, 59.9999];\nfunction formatTime(x, tr) {\n    var timePart = mod(x + 0.05, ONEDAY);\n\n    var timeStr = lpad(Math.floor(timePart / ONEHOUR), 2) + ':' +\n        lpad(mod(Math.floor(timePart / ONEMIN), 60), 2);\n\n    if(tr !== 'M') {\n        if(!isNumeric(tr)) tr = 0; // should only be 'S'\n\n        /*\n         * this is a weird one - and shouldn't come up unless people\n         * monkey with tick0 in weird ways, but we need to do something!\n         * IN PARTICULAR we had better not display garbage (see below)\n         * for numbers we always round to the nearest increment of the\n         * precision we're showing, and this seems like the right way to\n         * handle seconds and milliseconds, as they have a decimal point\n         * and people will interpret that to mean rounding like numbers.\n         * but for larger increments we floor the value: it's always\n         * 2013 until the ball drops on the new year. We could argue about\n         * which field it is where we start rounding (should 12:08:59\n         * round to 12:09 if we're stopping at minutes?) but for now I'll\n         * say we round seconds but floor everything else. BUT that means\n         * we need to never round up to 60 seconds, ie 23:59:60\n         */\n        var sec = Math.min(mod(x / ONESEC, 60), MAXSECONDS[tr]);\n\n        var secStr = (100 + sec).toFixed(tr).substr(1);\n        if(tr > 0) {\n            secStr = secStr.replace(/0+$/, '').replace(/[\\.]$/, '');\n        }\n\n        timeStr += ':' + secStr;\n    }\n    return timeStr;\n}\n\n/*\n * formatDate: turn a date into tick or hover label text.\n *\n *   x: milliseconds, the value to convert\n *   fmt: optional, an explicit format string (d3 format, even for world calendars)\n *   tr: tickround ('y', 'm', 'd', 'M', 'S', or # digits)\n *      used if no explicit fmt is provided\n *   formatter: locale-aware d3 date formatter for standard gregorian calendars\n *      should be the result of exports.getD3DateFormat(gd)\n *   calendar: optional string, the world calendar system to use\n *\n * returns the date/time as a string, potentially with the leading portion\n * on a separate line (after '\\n')\n * Note that this means if you provide an explicit format which includes '\\n'\n * the axis may choose to strip things after it when they don't change from\n * one tick to the next (as it does with automatic formatting)\n */\nexports.formatDate = function(x, fmt, tr, formatter, calendar, extraFormat) {\n    calendar = isWorldCalendar(calendar) && calendar;\n\n    if(!fmt) {\n        if(tr === 'y') fmt = extraFormat.year;\n        else if(tr === 'm') fmt = extraFormat.month;\n        else if(tr === 'd') {\n            fmt = extraFormat.dayMonth + '\\n' + extraFormat.year;\n        } else {\n            return formatTime(x, tr) + '\\n' + modDateFormat(extraFormat.dayMonthYear, x, formatter, calendar);\n        }\n    }\n\n    return modDateFormat(fmt, x, formatter, calendar);\n};\n\n/*\n * incrementMonth: make a new milliseconds value from the given one,\n * having changed the month\n *\n * special case for world calendars: multiples of 12 are treated as years,\n * even for calendar systems that don't have (always or ever) 12 months/year\n * TODO: perhaps we need a different code for year increments to support this?\n *\n * ms (number): the initial millisecond value\n * dMonth (int): the (signed) number of months to shift\n * calendar (string): the calendar system to use\n *\n * changing month does not (and CANNOT) always preserve day, since\n * months have different lengths. The worst example of this is:\n *   d = new Date(1970,0,31); d.setMonth(1) -> Feb 31 turns into Mar 3\n *\n * But we want to be able to iterate over the last day of each month,\n * regardless of what its number is.\n * So shift 3 days forward, THEN set the new month, then unshift:\n *   1/31 -> 2/28 (or 29) -> 3/31 -> 4/30 -> ...\n *\n * Note that odd behavior still exists if you start from the 26th-28th:\n *   1/28 -> 2/28 -> 3/31\n * but at least you can't shift any dates into the wrong month,\n * and ticks on these days incrementing by month would be very unusual\n */\nvar THREEDAYS = 3 * ONEDAY;\nexports.incrementMonth = function(ms, dMonth, calendar) {\n    calendar = isWorldCalendar(calendar) && calendar;\n\n    // pull time out and operate on pure dates, then add time back at the end\n    // this gives maximum precision - not that we *normally* care if we're\n    // incrementing by month, but better to be safe!\n    var timeMs = mod(ms, ONEDAY);\n    ms = Math.round(ms - timeMs);\n\n    if(calendar) {\n        try {\n            var dateJD = Math.round(ms / ONEDAY) + EPOCHJD;\n            var calInstance = Registry.getComponentMethod('calendars', 'getCal')(calendar);\n            var cDate = calInstance.fromJD(dateJD);\n\n            if(dMonth % 12) calInstance.add(cDate, dMonth, 'm');\n            else calInstance.add(cDate, dMonth / 12, 'y');\n\n            return (cDate.toJD() - EPOCHJD) * ONEDAY + timeMs;\n        } catch(e) {\n            Loggers.error('invalid ms ' + ms + ' in calendar ' + calendar);\n            // then keep going in gregorian even though the result will be 'Invalid'\n        }\n    }\n\n    var y = new Date(ms + THREEDAYS);\n    return y.setUTCMonth(y.getUTCMonth() + dMonth) + timeMs - THREEDAYS;\n};\n\n/*\n * findExactDates: what fraction of data is exact days, months, or years?\n *\n * data: array of millisecond values\n * calendar (string) the calendar to test against\n */\nexports.findExactDates = function(data, calendar) {\n    var exactYears = 0;\n    var exactMonths = 0;\n    var exactDays = 0;\n    var blankCount = 0;\n    var d;\n    var di;\n\n    var calInstance = (\n        isWorldCalendar(calendar) &&\n        Registry.getComponentMethod('calendars', 'getCal')(calendar)\n    );\n\n    for(var i = 0; i < data.length; i++) {\n        di = data[i];\n\n        // not date data at all\n        if(!isNumeric(di)) {\n            blankCount ++;\n            continue;\n        }\n\n        // not an exact date\n        if(di % ONEDAY) continue;\n\n        if(calInstance) {\n            try {\n                d = calInstance.fromJD(di / ONEDAY + EPOCHJD);\n                if(d.day() === 1) {\n                    if(d.month() === 1) exactYears++;\n                    else exactMonths++;\n                } else exactDays++;\n            } catch(e) {\n                // invalid date in this calendar - ignore it here.\n            }\n        } else {\n            d = new Date(di);\n            if(d.getUTCDate() === 1) {\n                if(d.getUTCMonth() === 0) exactYears++;\n                else exactMonths++;\n            } else exactDays++;\n        }\n    }\n    exactMonths += exactYears;\n    exactDays += exactMonths;\n\n    var dataCount = data.length - blankCount;\n\n    return {\n        exactYears: exactYears / dataCount,\n        exactMonths: exactMonths / dataCount,\n        exactDays: exactDays / dataCount\n    };\n};\n\n},{\"../constants/numerical\":695,\"../registry\":847,\"./loggers\":723,\"./mod\":726,\"d3\":163,\"fast-isnumeric\":225}],708:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar loggers = _dereq_('./loggers');\n\n/**\n * Allow referencing a graph DOM element either directly\n * or by its id string\n *\n * @param {HTMLDivElement|string} gd: a graph element or its id\n *\n * @returns {HTMLDivElement} the DOM element of the graph\n */\nfunction getGraphDiv(gd) {\n    var gdElement;\n\n    if(typeof gd === 'string') {\n        gdElement = document.getElementById(gd);\n\n        if(gdElement === null) {\n            throw new Error('No DOM element with id \\'' + gd + '\\' exists on the page.');\n        }\n\n        return gdElement;\n    } else if(gd === null || gd === undefined) {\n        throw new Error('DOM element provided is null or undefined');\n    }\n\n    // otherwise assume that gd is a DOM element\n    return gd;\n}\n\nfunction isPlotDiv(el) {\n    var el3 = d3.select(el);\n    return el3.node() instanceof HTMLElement &&\n        el3.size() &&\n        el3.classed('js-plotly-plot');\n}\n\nfunction removeElement(el) {\n    var elParent = el && el.parentNode;\n    if(elParent) elParent.removeChild(el);\n}\n\n/**\n * for dynamically adding style rules\n * makes one stylesheet that contains all rules added\n * by all calls to this function\n */\nfunction addStyleRule(selector, styleString) {\n    addRelatedStyleRule('global', selector, styleString);\n}\n\n/**\n * for dynamically adding style rules\n * to a stylesheet uniquely identified by a uid\n */\nfunction addRelatedStyleRule(uid, selector, styleString) {\n    var id = 'plotly.js-style-' + uid;\n    var style = document.getElementById(id);\n    if(!style) {\n        style = document.createElement('style');\n        style.setAttribute('id', id);\n        // WebKit hack :(\n        style.appendChild(document.createTextNode(''));\n        document.head.appendChild(style);\n    }\n    var styleSheet = style.sheet;\n\n    if(styleSheet.insertRule) {\n        styleSheet.insertRule(selector + '{' + styleString + '}', 0);\n    } else if(styleSheet.addRule) {\n        styleSheet.addRule(selector, styleString, 0);\n    } else loggers.warn('addStyleRule failed');\n}\n\n/**\n * to remove from the page a stylesheet identified by a given uid\n */\nfunction deleteRelatedStyleRule(uid) {\n    var id = 'plotly.js-style-' + uid;\n    var style = document.getElementById(id);\n    if(style) removeElement(style);\n}\n\nmodule.exports = {\n    getGraphDiv: getGraphDiv,\n    isPlotDiv: isPlotDiv,\n    removeElement: removeElement,\n    addStyleRule: addStyleRule,\n    addRelatedStyleRule: addRelatedStyleRule,\n    deleteRelatedStyleRule: deleteRelatedStyleRule\n};\n\n},{\"./loggers\":723,\"d3\":163}],709:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n/* global jQuery:false */\n\nvar EventEmitter = _dereq_('events').EventEmitter;\n\nvar Events = {\n\n    init: function(plotObj) {\n        /*\n         * If we have already instantiated an emitter for this plot\n         * return early.\n         */\n        if(plotObj._ev instanceof EventEmitter) return plotObj;\n\n        var ev = new EventEmitter();\n        var internalEv = new EventEmitter();\n\n        /*\n         * Assign to plot._ev while we still live in a land\n         * where plot is a DOM element with stuff attached to it.\n         * In the future we can make plot the event emitter itself.\n         */\n        plotObj._ev = ev;\n\n        /*\n         * Create a second event handler that will manage events *internally*.\n         * This allows parts of plotly to respond to thing like relayout without\n         * having to use the user-facing event handler. They cannot peacefully\n         * coexist on the same handler because a user invoking\n         * plotObj.removeAllListeners() would detach internal events, breaking\n         * plotly.\n         */\n        plotObj._internalEv = internalEv;\n\n        /*\n         * Assign bound methods from the ev to the plot object. These methods\n         * will reference the 'this' of plot._ev even though they are methods\n         * of plot. This will keep the event machinery away from the plot object\n         * which currently is often a DOM element but presents an API that will\n         * continue to function when plot becomes an emitter. Not all EventEmitter\n         * methods have been bound to `plot` as some do not currently add value to\n         * the Plotly event API.\n         */\n        plotObj.on = ev.on.bind(ev);\n        plotObj.once = ev.once.bind(ev);\n        plotObj.removeListener = ev.removeListener.bind(ev);\n        plotObj.removeAllListeners = ev.removeAllListeners.bind(ev);\n\n        /*\n         * Create functions for managing internal events. These are *only* triggered\n         * by the mirroring of external events via the emit function.\n         */\n        plotObj._internalOn = internalEv.on.bind(internalEv);\n        plotObj._internalOnce = internalEv.once.bind(internalEv);\n        plotObj._removeInternalListener = internalEv.removeListener.bind(internalEv);\n        plotObj._removeAllInternalListeners = internalEv.removeAllListeners.bind(internalEv);\n\n        /*\n         * We must wrap emit to continue to support JQuery events. The idea\n         * is to check to see if the user is using JQuery events, if they are\n         * we emit JQuery events to trigger user handlers as well as the EventEmitter\n         * events.\n         */\n        plotObj.emit = function(event, data) {\n            if(typeof jQuery !== 'undefined') {\n                jQuery(plotObj).trigger(event, data);\n            }\n\n            ev.emit(event, data);\n            internalEv.emit(event, data);\n        };\n\n        return plotObj;\n    },\n\n    /*\n     * This function behaves like jQuery's triggerHandler. It calls\n     * all handlers for a particular event and returns the return value\n     * of the LAST handler. This function also triggers jQuery's\n     * triggerHandler for backwards compatibility.\n     */\n    triggerHandler: function(plotObj, event, data) {\n        var jQueryHandlerValue;\n        var nodeEventHandlerValue;\n\n        /*\n         * If jQuery exists run all its handlers for this event and\n         * collect the return value of the LAST handler function\n         */\n        if(typeof jQuery !== 'undefined') {\n            jQueryHandlerValue = jQuery(plotObj).triggerHandler(event, data);\n        }\n\n        /*\n         * Now run all the node style event handlers\n         */\n        var ev = plotObj._ev;\n        if(!ev) return jQueryHandlerValue;\n\n        var handlers = ev._events[event];\n        if(!handlers) return jQueryHandlerValue;\n\n        // making sure 'this' is the EventEmitter instance\n        function apply(handler) {\n            // The 'once' case, we can't just call handler() as we need\n            // the return value here. So,\n            // - remove handler\n            // - call listener and grab return value!\n            // - stash 'fired' key to not call handler twice\n            if(handler.listener) {\n                ev.removeListener(event, handler.listener);\n                if(!handler.fired) {\n                    handler.fired = true;\n                    return handler.listener.apply(ev, [data]);\n                }\n            } else {\n                return handler.apply(ev, [data]);\n            }\n        }\n\n        // handlers can be function or an array of functions\n        handlers = Array.isArray(handlers) ? handlers : [handlers];\n\n        var i;\n        for(i = 0; i < handlers.length - 1; i++) {\n            apply(handlers[i]);\n        }\n        // now call the final handler and collect its value\n        nodeEventHandlerValue = apply(handlers[i]);\n\n        /*\n         * Return either the jQuery handler value if it exists or the\n         * nodeEventHandler value. jQuery event value supersedes nodejs\n         * events for backwards compatibility reasons.\n         */\n        return jQueryHandlerValue !== undefined ?\n            jQueryHandlerValue :\n            nodeEventHandlerValue;\n    },\n\n    purge: function(plotObj) {\n        delete plotObj._ev;\n        delete plotObj.on;\n        delete plotObj.once;\n        delete plotObj.removeListener;\n        delete plotObj.removeAllListeners;\n        delete plotObj.emit;\n\n        delete plotObj._ev;\n        delete plotObj._internalEv;\n        delete plotObj._internalOn;\n        delete plotObj._internalOnce;\n        delete plotObj._removeInternalListener;\n        delete plotObj._removeAllInternalListeners;\n\n        return plotObj;\n    }\n\n};\n\nmodule.exports = Events;\n\n},{\"events\":104}],710:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isPlainObject = _dereq_('./is_plain_object.js');\nvar isArray = Array.isArray;\n\nfunction primitivesLoopSplice(source, target) {\n    var i, value;\n    for(i = 0; i < source.length; i++) {\n        value = source[i];\n        if(value !== null && typeof(value) === 'object') {\n            return false;\n        }\n        if(value !== void(0)) {\n            target[i] = value;\n        }\n    }\n    return true;\n}\n\nexports.extendFlat = function() {\n    return _extend(arguments, false, false, false);\n};\n\nexports.extendDeep = function() {\n    return _extend(arguments, true, false, false);\n};\n\nexports.extendDeepAll = function() {\n    return _extend(arguments, true, true, false);\n};\n\nexports.extendDeepNoArrays = function() {\n    return _extend(arguments, true, false, true);\n};\n\n/*\n * Inspired by https://github.com/justmoon/node-extend/blob/master/index.js\n * All credit to the jQuery authors for perfecting this amazing utility.\n *\n * API difference with jQuery version:\n * - No optional boolean (true -> deep extend) first argument,\n *   use `extendFlat` for first-level only extend and\n *   use `extendDeep` for a deep extend.\n *\n * Other differences with jQuery version:\n * - Uses a modern (and faster) isPlainObject routine.\n * - Expected to work with object {} and array [] arguments only.\n * - Does not check for circular structure.\n *   FYI: jQuery only does a check across one level.\n *   Warning: this might result in infinite loops.\n *\n */\nfunction _extend(inputs, isDeep, keepAllKeys, noArrayCopies) {\n    var target = inputs[0];\n    var length = inputs.length;\n\n    var input, key, src, copy, copyIsArray, clone, allPrimitives;\n\n    // TODO does this do the right thing for typed arrays?\n\n    if(length === 2 && isArray(target) && isArray(inputs[1]) && target.length === 0) {\n        allPrimitives = primitivesLoopSplice(inputs[1], target);\n\n        if(allPrimitives) {\n            return target;\n        } else {\n            target.splice(0, target.length); // reset target and continue to next block\n        }\n    }\n\n    for(var i = 1; i < length; i++) {\n        input = inputs[i];\n\n        for(key in input) {\n            src = target[key];\n            copy = input[key];\n\n            if(noArrayCopies && isArray(copy)) {\n                // Stop early and just transfer the array if array copies are disallowed:\n\n                target[key] = copy;\n            } else if(isDeep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {\n                // recurse if we're merging plain objects or arrays\n\n                if(copyIsArray) {\n                    copyIsArray = false;\n                    clone = src && isArray(src) ? src : [];\n                } else {\n                    clone = src && isPlainObject(src) ? src : {};\n                }\n\n                // never move original objects, clone them\n                target[key] = _extend([clone, copy], isDeep, keepAllKeys, noArrayCopies);\n            } else if(typeof copy !== 'undefined' || keepAllKeys) {\n                // don't bring in undefined values, except for extendDeepAll\n\n                target[key] = copy;\n            }\n        }\n    }\n\n    return target;\n}\n\n},{\"./is_plain_object.js\":720}],711:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\n/**\n * Return news array containing only the unique items\n * found in input array.\n *\n * IMPORTANT: Note that items are considered unique\n * if `String({})` is unique. For example;\n *\n *  Lib.filterUnique([ { a: 1 }, { b: 2 } ])\n *\n *  returns [{ a: 1 }]\n *\n * and\n *\n *  Lib.filterUnique([ '1', 1 ])\n *\n *  returns ['1']\n *\n *\n * @param {array} array base array\n * @return {array} new filtered array\n */\nmodule.exports = function filterUnique(array) {\n    var seen = {};\n    var out = [];\n    var j = 0;\n\n    for(var i = 0; i < array.length; i++) {\n        var item = array[i];\n\n        if(seen[item] !== 1) {\n            seen[item] = 1;\n            out[j++] = item;\n        }\n    }\n\n    return out;\n};\n\n},{}],712:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/** Filter out object items with visible !== true\n *  insider array container.\n *\n *  @param {array of objects} container\n *  @return {array of objects} of length <= container\n *\n */\nmodule.exports = function filterVisible(container) {\n    var filterFn = isCalcData(container) ? calcDataFilter : baseFilter;\n    var out = [];\n\n    for(var i = 0; i < container.length; i++) {\n        var item = container[i];\n        if(filterFn(item)) out.push(item);\n    }\n\n    return out;\n};\n\nfunction baseFilter(item) {\n    return item.visible === true;\n}\n\nfunction calcDataFilter(item) {\n    var trace = item[0].trace;\n    return trace.visible === true && trace._length !== 0;\n}\n\nfunction isCalcData(cont) {\n    return (\n        Array.isArray(cont) &&\n        Array.isArray(cont[0]) &&\n        cont[0][0] &&\n        cont[0][0].trace\n    );\n}\n\n},{}],713:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar countryRegex = _dereq_('country-regex');\nvar Lib = _dereq_('../lib');\n\n// make list of all country iso3 ids from at runtime\nvar countryIds = Object.keys(countryRegex);\n\nvar locationmodeToIdFinder = {\n    'ISO-3': Lib.identity,\n    'USA-states': Lib.identity,\n    'country names': countryNameToISO3\n};\n\nfunction countryNameToISO3(countryName) {\n    for(var i = 0; i < countryIds.length; i++) {\n        var iso3 = countryIds[i];\n        var regex = new RegExp(countryRegex[iso3]);\n\n        if(regex.test(countryName.trim().toLowerCase())) return iso3;\n    }\n\n    Lib.log('Unrecognized country name: ' + countryName + '.');\n\n    return false;\n}\n\nfunction locationToFeature(locationmode, location, features) {\n    if(!location || typeof location !== 'string') return false;\n\n    var locationId = locationmodeToIdFinder[locationmode](location);\n    var filteredFeatures;\n    var f, i;\n\n    if(locationId) {\n        if(locationmode === 'USA-states') {\n            // Filter out features out in USA\n            //\n            // This is important as the Natural Earth files\n            // include state/provinces from USA, Canada, Australia and Brazil\n            // which have some overlay in their two-letter ids. For example,\n            // 'WA' is used for both Washington state and Western Australia.\n            filteredFeatures = [];\n            for(i = 0; i < features.length; i++) {\n                f = features[i];\n                if(f.properties && f.properties.gu && f.properties.gu === 'USA') {\n                    filteredFeatures.push(f);\n                }\n            }\n        } else {\n            filteredFeatures = features;\n        }\n\n        for(i = 0; i < filteredFeatures.length; i++) {\n            f = filteredFeatures[i];\n            if(f.id === locationId) return f;\n        }\n\n        Lib.log([\n            'Location with id', locationId,\n            'does not have a matching topojson feature at this resolution.'\n        ].join(' '));\n    }\n\n    return false;\n}\n\nmodule.exports = {\n    locationToFeature: locationToFeature\n};\n\n},{\"../lib\":719,\"country-regex\":134}],714:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar BADNUM = _dereq_('../constants/numerical').BADNUM;\n\n/**\n * Convert calcTrace to GeoJSON 'MultiLineString' coordinate arrays\n *\n * @param {object} calcTrace\n *  gd.calcdata item.\n *  Note that calcTrace[i].lonlat is assumed to be defined\n *\n * @return {array}\n *  return line coords array (or array of arrays)\n *\n */\nexports.calcTraceToLineCoords = function(calcTrace) {\n    var trace = calcTrace[0].trace;\n    var connectgaps = trace.connectgaps;\n\n    var coords = [];\n    var lineString = [];\n\n    for(var i = 0; i < calcTrace.length; i++) {\n        var calcPt = calcTrace[i];\n        var lonlat = calcPt.lonlat;\n\n        if(lonlat[0] !== BADNUM) {\n            lineString.push(lonlat);\n        } else if(!connectgaps && lineString.length > 0) {\n            coords.push(lineString);\n            lineString = [];\n        }\n    }\n\n    if(lineString.length > 0) {\n        coords.push(lineString);\n    }\n\n    return coords;\n};\n\n\n/**\n * Make line ('LineString' or 'MultiLineString') GeoJSON\n *\n * @param {array} coords\n *  results form calcTraceToLineCoords\n * @return {object} out\n *  GeoJSON object\n *\n */\nexports.makeLine = function(coords) {\n    if(coords.length === 1) {\n        return {\n            type: 'LineString',\n            coordinates: coords[0]\n        };\n    } else {\n        return {\n            type: 'MultiLineString',\n            coordinates: coords\n        };\n    }\n};\n\n/**\n * Make polygon ('Polygon' or 'MultiPolygon') GeoJSON\n *\n * @param {array} coords\n *  results form calcTraceToLineCoords\n * @return {object} out\n *  GeoJSON object\n */\nexports.makePolygon = function(coords) {\n    if(coords.length === 1) {\n        return {\n            type: 'Polygon',\n            coordinates: coords\n        };\n    } else {\n        var _coords = new Array(coords.length);\n\n        for(var i = 0; i < coords.length; i++) {\n            _coords[i] = [coords[i]];\n        }\n\n        return {\n            type: 'MultiPolygon',\n            coordinates: _coords\n        };\n    }\n};\n\n/**\n * Make blank GeoJSON\n *\n * @return {object}\n *  Blank GeoJSON object\n *\n */\nexports.makeBlank = function() {\n    return {\n        type: 'Point',\n        coordinates: []\n    };\n};\n\n},{\"../constants/numerical\":695}],715:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar mod = _dereq_('./mod').mod;\n\n/*\n * look for intersection of two line segments\n *   (1->2 and 3->4) - returns array [x,y] if they do, null if not\n */\nexports.segmentsIntersect = segmentsIntersect;\nfunction segmentsIntersect(x1, y1, x2, y2, x3, y3, x4, y4) {\n    var a = x2 - x1;\n    var b = x3 - x1;\n    var c = x4 - x3;\n    var d = y2 - y1;\n    var e = y3 - y1;\n    var f = y4 - y3;\n    var det = a * f - c * d;\n    // parallel lines? intersection is undefined\n    // ignore the case where they are colinear\n    if(det === 0) return null;\n    var t = (b * f - c * e) / det;\n    var u = (b * d - a * e) / det;\n    // segments do not intersect?\n    if(u < 0 || u > 1 || t < 0 || t > 1) return null;\n\n    return {x: x1 + a * t, y: y1 + d * t};\n}\n\n/*\n * find the minimum distance between two line segments (1->2 and 3->4)\n */\nexports.segmentDistance = function segmentDistance(x1, y1, x2, y2, x3, y3, x4, y4) {\n    if(segmentsIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) return 0;\n\n    // the two segments and their lengths squared\n    var x12 = x2 - x1;\n    var y12 = y2 - y1;\n    var x34 = x4 - x3;\n    var y34 = y4 - y3;\n    var ll12 = x12 * x12 + y12 * y12;\n    var ll34 = x34 * x34 + y34 * y34;\n\n    // calculate distance squared, then take the sqrt at the very end\n    var dist2 = Math.min(\n        perpDistance2(x12, y12, ll12, x3 - x1, y3 - y1),\n        perpDistance2(x12, y12, ll12, x4 - x1, y4 - y1),\n        perpDistance2(x34, y34, ll34, x1 - x3, y1 - y3),\n        perpDistance2(x34, y34, ll34, x2 - x3, y2 - y3)\n    );\n\n    return Math.sqrt(dist2);\n};\n\n/*\n * distance squared from segment ab to point c\n * [xab, yab] is the vector b-a\n * [xac, yac] is the vector c-a\n * llab is the length squared of (b-a), just to simplify calculation\n */\nfunction perpDistance2(xab, yab, llab, xac, yac) {\n    var fcAB = (xac * xab + yac * yab);\n    if(fcAB < 0) {\n        // point c is closer to point a\n        return xac * xac + yac * yac;\n    } else if(fcAB > llab) {\n        // point c is closer to point b\n        var xbc = xac - xab;\n        var ybc = yac - yab;\n        return xbc * xbc + ybc * ybc;\n    } else {\n        // perpendicular distance is the shortest\n        var crossProduct = xac * yab - yac * xab;\n        return crossProduct * crossProduct / llab;\n    }\n}\n\n// a very short-term cache for getTextLocation, just because\n// we're often looping over the same locations multiple times\n// invalidated as soon as we look at a different path\nvar locationCache, workingPath, workingTextWidth;\n\n// turn a path and position along it into x, y, and angle for the given text\nexports.getTextLocation = function getTextLocation(path, totalPathLen, positionOnPath, textWidth) {\n    if(path !== workingPath || textWidth !== workingTextWidth) {\n        locationCache = {};\n        workingPath = path;\n        workingTextWidth = textWidth;\n    }\n    if(locationCache[positionOnPath]) {\n        return locationCache[positionOnPath];\n    }\n\n    // for the angle, use points on the path separated by the text width\n    // even though due to curvature, the text will cover a bit more than that\n    var p0 = path.getPointAtLength(mod(positionOnPath - textWidth / 2, totalPathLen));\n    var p1 = path.getPointAtLength(mod(positionOnPath + textWidth / 2, totalPathLen));\n    // note: atan handles 1/0 nicely\n    var theta = Math.atan((p1.y - p0.y) / (p1.x - p0.x));\n    // center the text at 2/3 of the center position plus 1/3 the p0/p1 midpoint\n    // that's the average position of this segment, assuming it's roughly quadratic\n    var pCenter = path.getPointAtLength(mod(positionOnPath, totalPathLen));\n    var x = (pCenter.x * 4 + p0.x + p1.x) / 6;\n    var y = (pCenter.y * 4 + p0.y + p1.y) / 6;\n\n    var out = {x: x, y: y, theta: theta};\n    locationCache[positionOnPath] = out;\n    return out;\n};\n\nexports.clearLocationCache = function() {\n    workingPath = null;\n};\n\n/*\n * Find the segment of `path` that's within the visible area\n * given by `bounds` {left, right, top, bottom}, to within a\n * precision of `buffer` px\n *\n * returns: undefined if nothing is visible, else object:\n * {\n *   min: position where the path first enters bounds, or 0 if it\n *        starts within bounds\n *   max: position where the path last exits bounds, or the path length\n *        if it finishes within bounds\n *   len: max - min, ie the length of visible path\n *   total: the total path length - just included so the caller doesn't\n *        need to call path.getTotalLength() again\n *   isClosed: true iff the start and end points of the path are both visible\n *        and are at the same point\n * }\n *\n * Works by starting from either end and repeatedly finding the distance from\n * that point to the plot area, and if it's outside the plot, moving along the\n * path by that distance (because the plot must be at least that far away on\n * the path). Note that if a path enters, exits, and re-enters the plot, we\n * will not capture this behavior.\n */\nexports.getVisibleSegment = function getVisibleSegment(path, bounds, buffer) {\n    var left = bounds.left;\n    var right = bounds.right;\n    var top = bounds.top;\n    var bottom = bounds.bottom;\n\n    var pMin = 0;\n    var pTotal = path.getTotalLength();\n    var pMax = pTotal;\n\n    var pt0, ptTotal;\n\n    function getDistToPlot(len) {\n        var pt = path.getPointAtLength(len);\n\n        // hold on to the start and end points for `closed`\n        if(len === 0) pt0 = pt;\n        else if(len === pTotal) ptTotal = pt;\n\n        var dx = (pt.x < left) ? left - pt.x : (pt.x > right ? pt.x - right : 0);\n        var dy = (pt.y < top) ? top - pt.y : (pt.y > bottom ? pt.y - bottom : 0);\n        return Math.sqrt(dx * dx + dy * dy);\n    }\n\n    var distToPlot = getDistToPlot(pMin);\n    while(distToPlot) {\n        pMin += distToPlot + buffer;\n        if(pMin > pMax) return;\n        distToPlot = getDistToPlot(pMin);\n    }\n\n    distToPlot = getDistToPlot(pMax);\n    while(distToPlot) {\n        pMax -= distToPlot + buffer;\n        if(pMin > pMax) return;\n        distToPlot = getDistToPlot(pMax);\n    }\n\n    return {\n        min: pMin,\n        max: pMax,\n        len: pMax - pMin,\n        total: pTotal,\n        isClosed: pMin === 0 && pMax === pTotal &&\n            Math.abs(pt0.x - ptTotal.x) < 0.1 &&\n            Math.abs(pt0.y - ptTotal.y) < 0.1\n    };\n};\n\n/**\n * Find point on SVG path corresponding to a given constraint coordinate\n *\n * @param {SVGPathElement} path\n * @param {Number} val : constraint coordinate value\n * @param {String} coord : 'x' or 'y' the constraint coordinate\n * @param {Object} opts :\n *  - {Number} pathLength : supply total path length before hand\n *  - {Number} tolerance\n *  - {Number} iterationLimit\n * @return {SVGPoint}\n */\nexports.findPointOnPath = function findPointOnPath(path, val, coord, opts) {\n    opts = opts || {};\n\n    var pathLength = opts.pathLength || path.getTotalLength();\n    var tolerance = opts.tolerance || 1e-3;\n    var iterationLimit = opts.iterationLimit || 30;\n\n    // if path starts at a val greater than the path tail (like on vertical violins),\n    // we must flip the sign of the computed diff.\n    var mul = path.getPointAtLength(0)[coord] > path.getPointAtLength(pathLength)[coord] ? -1 : 1;\n\n    var i = 0;\n    var b0 = 0;\n    var b1 = pathLength;\n    var mid;\n    var pt;\n    var diff;\n\n    while(i < iterationLimit) {\n        mid = (b0 + b1) / 2;\n        pt = path.getPointAtLength(mid);\n        diff = pt[coord] - val;\n\n        if(Math.abs(diff) < tolerance) {\n            return pt;\n        } else {\n            if(mul * diff > 0) {\n                b1 = mid;\n            } else {\n                b0 = mid;\n            }\n            i++;\n        }\n    }\n    return pt;\n};\n\n},{\"./mod\":726}],716:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar tinycolor = _dereq_('tinycolor2');\nvar rgba = _dereq_('color-normalize');\n\nvar Colorscale = _dereq_('../components/colorscale');\nvar colorDflt = _dereq_('../components/color/attributes').defaultLine;\nvar isArrayOrTypedArray = _dereq_('./array').isArrayOrTypedArray;\n\nvar colorDfltRgba = rgba(colorDflt);\nvar opacityDflt = 1;\n\nfunction calculateColor(colorIn, opacityIn) {\n    var colorOut = colorIn;\n    colorOut[3] *= opacityIn;\n    return colorOut;\n}\n\nfunction validateColor(colorIn) {\n    if(isNumeric(colorIn)) return colorDfltRgba;\n\n    var colorOut = rgba(colorIn);\n\n    return colorOut.length ? colorOut : colorDfltRgba;\n}\n\nfunction validateOpacity(opacityIn) {\n    return isNumeric(opacityIn) ? opacityIn : opacityDflt;\n}\n\nfunction formatColor(containerIn, opacityIn, len) {\n    var colorIn = containerIn.color;\n    var isArrayColorIn = isArrayOrTypedArray(colorIn);\n    var isArrayOpacityIn = isArrayOrTypedArray(opacityIn);\n    var cOpts = Colorscale.extractOpts(containerIn);\n    var colorOut = [];\n\n    var sclFunc, getColor, getOpacity, colori, opacityi;\n\n    if(cOpts.colorscale !== undefined) {\n        sclFunc = Colorscale.makeColorScaleFuncFromTrace(containerIn);\n    } else {\n        sclFunc = validateColor;\n    }\n\n    if(isArrayColorIn) {\n        getColor = function(c, i) {\n            // FIXME: there is double work, considering that sclFunc does the opposite\n            return c[i] === undefined ? colorDfltRgba : rgba(sclFunc(c[i]));\n        };\n    } else getColor = validateColor;\n\n    if(isArrayOpacityIn) {\n        getOpacity = function(o, i) {\n            return o[i] === undefined ? opacityDflt : validateOpacity(o[i]);\n        };\n    } else getOpacity = validateOpacity;\n\n    if(isArrayColorIn || isArrayOpacityIn) {\n        for(var i = 0; i < len; i++) {\n            colori = getColor(colorIn, i);\n            opacityi = getOpacity(opacityIn, i);\n            colorOut[i] = calculateColor(colori, opacityi);\n        }\n    } else colorOut = calculateColor(rgba(colorIn), opacityIn);\n\n    return colorOut;\n}\n\nfunction parseColorScale(cont, alpha) {\n    if(alpha === undefined) alpha = 1;\n\n    var cOpts = Colorscale.extractOpts(cont);\n\n    var colorscale = cOpts.reversescale ?\n        Colorscale.flipScale(cOpts.colorscale) :\n        cOpts.colorscale;\n\n    return colorscale.map(function(elem) {\n        var index = elem[0];\n        var color = tinycolor(elem[1]);\n        var rgb = color.toRgb();\n        return {\n            index: index,\n            rgb: [rgb.r, rgb.g, rgb.b, alpha]\n        };\n    });\n}\n\nmodule.exports = {\n    formatColor: formatColor,\n    parseColorScale: parseColorScale\n};\n\n},{\"../components/color/attributes\":592,\"../components/colorscale\":605,\"./array\":702,\"color-normalize\":120,\"fast-isnumeric\":225,\"tinycolor2\":537}],717:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar identity = _dereq_('./identity');\n\nfunction wrap(d) {return [d];}\n\nmodule.exports = {\n\n    // The D3 data binding concept and the General Update Pattern promotes the idea of\n    // traversing into the scenegraph by using the `.data(fun, keyFun)` call.\n    // The `fun` is most often a `repeat`, ie. the elements beneath a `<g>` element need\n    // access to the same data, or a `descend`, which fans a scenegraph node into a bunch of\n    // of elements, e.g. points, lines, rows, requiring an array as input.\n    // The role of the `keyFun` is to identify what elements are being entered/exited/updated,\n    // otherwise D3 reverts to using a plain index which would screw up `transition`s.\n    keyFun: function(d) {return d.key;},\n    repeat: wrap,\n    descend: identity,\n\n    // Plotly.js uses a convention of storing the actual contents of the `calcData` as the\n    // element zero of a container array. These helpers are just used for clarity as a\n    // newcomer to the codebase may not know what the `[0]` is, and whether there can be further\n    // elements (not atm).\n    wrap: wrap,\n    unwrap: function(d) {return d[0];}\n};\n\n},{\"./identity\":718}],718:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// Simple helper functions\n// none of these need any external deps\n\nmodule.exports = function identity(d) { return d; };\n\n},{}],719:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar numConstants = _dereq_('../constants/numerical');\nvar FP_SAFE = numConstants.FP_SAFE;\nvar BADNUM = numConstants.BADNUM;\n\nvar lib = module.exports = {};\n\nlib.nestedProperty = _dereq_('./nested_property');\nlib.keyedContainer = _dereq_('./keyed_container');\nlib.relativeAttr = _dereq_('./relative_attr');\nlib.isPlainObject = _dereq_('./is_plain_object');\nlib.toLogRange = _dereq_('./to_log_range');\nlib.relinkPrivateKeys = _dereq_('./relink_private');\n\nvar arrayModule = _dereq_('./array');\nlib.isTypedArray = arrayModule.isTypedArray;\nlib.isArrayOrTypedArray = arrayModule.isArrayOrTypedArray;\nlib.isArray1D = arrayModule.isArray1D;\nlib.ensureArray = arrayModule.ensureArray;\nlib.concat = arrayModule.concat;\nlib.maxRowLength = arrayModule.maxRowLength;\nlib.minRowLength = arrayModule.minRowLength;\n\nvar modModule = _dereq_('./mod');\nlib.mod = modModule.mod;\nlib.modHalf = modModule.modHalf;\n\nvar coerceModule = _dereq_('./coerce');\nlib.valObjectMeta = coerceModule.valObjectMeta;\nlib.coerce = coerceModule.coerce;\nlib.coerce2 = coerceModule.coerce2;\nlib.coerceFont = coerceModule.coerceFont;\nlib.coerceHoverinfo = coerceModule.coerceHoverinfo;\nlib.coerceSelectionMarkerOpacity = coerceModule.coerceSelectionMarkerOpacity;\nlib.validate = coerceModule.validate;\n\nvar datesModule = _dereq_('./dates');\nlib.dateTime2ms = datesModule.dateTime2ms;\nlib.isDateTime = datesModule.isDateTime;\nlib.ms2DateTime = datesModule.ms2DateTime;\nlib.ms2DateTimeLocal = datesModule.ms2DateTimeLocal;\nlib.cleanDate = datesModule.cleanDate;\nlib.isJSDate = datesModule.isJSDate;\nlib.formatDate = datesModule.formatDate;\nlib.incrementMonth = datesModule.incrementMonth;\nlib.dateTick0 = datesModule.dateTick0;\nlib.dfltRange = datesModule.dfltRange;\nlib.findExactDates = datesModule.findExactDates;\nlib.MIN_MS = datesModule.MIN_MS;\nlib.MAX_MS = datesModule.MAX_MS;\n\nvar searchModule = _dereq_('./search');\nlib.findBin = searchModule.findBin;\nlib.sorterAsc = searchModule.sorterAsc;\nlib.sorterDes = searchModule.sorterDes;\nlib.distinctVals = searchModule.distinctVals;\nlib.roundUp = searchModule.roundUp;\nlib.sort = searchModule.sort;\nlib.findIndexOfMin = searchModule.findIndexOfMin;\n\nvar statsModule = _dereq_('./stats');\nlib.aggNums = statsModule.aggNums;\nlib.len = statsModule.len;\nlib.mean = statsModule.mean;\nlib.median = statsModule.median;\nlib.midRange = statsModule.midRange;\nlib.variance = statsModule.variance;\nlib.stdev = statsModule.stdev;\nlib.interp = statsModule.interp;\n\nvar matrixModule = _dereq_('./matrix');\nlib.init2dArray = matrixModule.init2dArray;\nlib.transposeRagged = matrixModule.transposeRagged;\nlib.dot = matrixModule.dot;\nlib.translationMatrix = matrixModule.translationMatrix;\nlib.rotationMatrix = matrixModule.rotationMatrix;\nlib.rotationXYMatrix = matrixModule.rotationXYMatrix;\nlib.apply2DTransform = matrixModule.apply2DTransform;\nlib.apply2DTransform2 = matrixModule.apply2DTransform2;\n\nvar anglesModule = _dereq_('./angles');\nlib.deg2rad = anglesModule.deg2rad;\nlib.rad2deg = anglesModule.rad2deg;\nlib.angleDelta = anglesModule.angleDelta;\nlib.angleDist = anglesModule.angleDist;\nlib.isFullCircle = anglesModule.isFullCircle;\nlib.isAngleInsideSector = anglesModule.isAngleInsideSector;\nlib.isPtInsideSector = anglesModule.isPtInsideSector;\nlib.pathArc = anglesModule.pathArc;\nlib.pathSector = anglesModule.pathSector;\nlib.pathAnnulus = anglesModule.pathAnnulus;\n\nvar anchorUtils = _dereq_('./anchor_utils');\nlib.isLeftAnchor = anchorUtils.isLeftAnchor;\nlib.isCenterAnchor = anchorUtils.isCenterAnchor;\nlib.isRightAnchor = anchorUtils.isRightAnchor;\nlib.isTopAnchor = anchorUtils.isTopAnchor;\nlib.isMiddleAnchor = anchorUtils.isMiddleAnchor;\nlib.isBottomAnchor = anchorUtils.isBottomAnchor;\n\nvar geom2dModule = _dereq_('./geometry2d');\nlib.segmentsIntersect = geom2dModule.segmentsIntersect;\nlib.segmentDistance = geom2dModule.segmentDistance;\nlib.getTextLocation = geom2dModule.getTextLocation;\nlib.clearLocationCache = geom2dModule.clearLocationCache;\nlib.getVisibleSegment = geom2dModule.getVisibleSegment;\nlib.findPointOnPath = geom2dModule.findPointOnPath;\n\nvar extendModule = _dereq_('./extend');\nlib.extendFlat = extendModule.extendFlat;\nlib.extendDeep = extendModule.extendDeep;\nlib.extendDeepAll = extendModule.extendDeepAll;\nlib.extendDeepNoArrays = extendModule.extendDeepNoArrays;\n\nvar loggersModule = _dereq_('./loggers');\nlib.log = loggersModule.log;\nlib.warn = loggersModule.warn;\nlib.error = loggersModule.error;\n\nvar regexModule = _dereq_('./regex');\nlib.counterRegex = regexModule.counter;\n\nvar throttleModule = _dereq_('./throttle');\nlib.throttle = throttleModule.throttle;\nlib.throttleDone = throttleModule.done;\nlib.clearThrottle = throttleModule.clear;\n\nvar domModule = _dereq_('./dom');\nlib.getGraphDiv = domModule.getGraphDiv;\nlib.isPlotDiv = domModule.isPlotDiv;\nlib.removeElement = domModule.removeElement;\nlib.addStyleRule = domModule.addStyleRule;\nlib.addRelatedStyleRule = domModule.addRelatedStyleRule;\nlib.deleteRelatedStyleRule = domModule.deleteRelatedStyleRule;\n\nlib.clearResponsive = _dereq_('./clear_responsive');\n\nlib.makeTraceGroups = _dereq_('./make_trace_groups');\n\nlib._ = _dereq_('./localize');\n\nlib.notifier = _dereq_('./notifier');\n\nlib.filterUnique = _dereq_('./filter_unique');\nlib.filterVisible = _dereq_('./filter_visible');\nlib.pushUnique = _dereq_('./push_unique');\n\nlib.cleanNumber = _dereq_('./clean_number');\n\nlib.ensureNumber = function ensureNumber(v) {\n    if(!isNumeric(v)) return BADNUM;\n    v = Number(v);\n    if(v < -FP_SAFE || v > FP_SAFE) return BADNUM;\n    return isNumeric(v) ? Number(v) : BADNUM;\n};\n\n/**\n * Is v a valid array index? Accepts numeric strings as well as numbers.\n *\n * @param {any} v: the value to test\n * @param {Optional[integer]} len: the array length we are indexing\n *\n * @return {bool}: v is a valid array index\n */\nlib.isIndex = function(v, len) {\n    if(len !== undefined && v >= len) return false;\n    return isNumeric(v) && (v >= 0) && (v % 1 === 0);\n};\n\nlib.noop = _dereq_('./noop');\nlib.identity = _dereq_('./identity');\n\n/**\n * create an array of length 'cnt' filled with 'v' at all indices\n *\n * @param {any} v\n * @param {number} cnt\n * @return {array}\n */\nlib.repeat = function(v, cnt) {\n    var out = new Array(cnt);\n    for(var i = 0; i < cnt; i++) {\n        out[i] = v;\n    }\n    return out;\n};\n\n/**\n * swap x and y of the same attribute in container cont\n * specify attr with a ? in place of x/y\n * you can also swap other things than x/y by providing part1 and part2\n */\nlib.swapAttrs = function(cont, attrList, part1, part2) {\n    if(!part1) part1 = 'x';\n    if(!part2) part2 = 'y';\n    for(var i = 0; i < attrList.length; i++) {\n        var attr = attrList[i];\n        var xp = lib.nestedProperty(cont, attr.replace('?', part1));\n        var yp = lib.nestedProperty(cont, attr.replace('?', part2));\n        var temp = xp.get();\n        xp.set(yp.get());\n        yp.set(temp);\n    }\n};\n\n/**\n * SVG painter's algo worked around with reinsertion\n */\nlib.raiseToTop = function raiseToTop(elem) {\n    elem.parentNode.appendChild(elem);\n};\n\n/**\n * cancel a possibly pending transition; returned selection may be used by caller\n */\nlib.cancelTransition = function(selection) {\n    return selection.transition().duration(0);\n};\n\n// constrain - restrict a number v to be between v0 and v1\nlib.constrain = function(v, v0, v1) {\n    if(v0 > v1) return Math.max(v1, Math.min(v0, v));\n    return Math.max(v0, Math.min(v1, v));\n};\n\n/**\n * do two bounding boxes from getBoundingClientRect,\n * ie {left,right,top,bottom,width,height}, overlap?\n * takes optional padding pixels\n */\nlib.bBoxIntersect = function(a, b, pad) {\n    pad = pad || 0;\n    return (a.left <= b.right + pad &&\n            b.left <= a.right + pad &&\n            a.top <= b.bottom + pad &&\n            b.top <= a.bottom + pad);\n};\n\n/*\n * simpleMap: alternative to Array.map that only\n * passes on the element and up to 2 extra args you\n * provide (but not the array index or the whole array)\n *\n * array: the array to map it to\n * func: the function to apply\n * x1, x2: optional extra args\n */\nlib.simpleMap = function(array, func, x1, x2) {\n    var len = array.length;\n    var out = new Array(len);\n    for(var i = 0; i < len; i++) out[i] = func(array[i], x1, x2);\n    return out;\n};\n\n/**\n * Random string generator\n *\n * @param {object} existing\n *     pass in strings to avoid as keys with truthy values\n * @param {int} bits\n *     bits of information in the output string, default 24\n * @param {int} base\n *     base of string representation, default 16. Should be a power of 2.\n */\nlib.randstr = function randstr(existing, bits, base, _recursion) {\n    if(!base) base = 16;\n    if(bits === undefined) bits = 24;\n    if(bits <= 0) return '0';\n\n    var digits = Math.log(Math.pow(2, bits)) / Math.log(base);\n    var res = '';\n    var i, b, x;\n\n    for(i = 2; digits === Infinity; i *= 2) {\n        digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;\n    }\n\n    var rem = digits - Math.floor(digits);\n\n    for(i = 0; i < Math.floor(digits); i++) {\n        x = Math.floor(Math.random() * base).toString(base);\n        res = x + res;\n    }\n\n    if(rem) {\n        b = Math.pow(base, rem);\n        x = Math.floor(Math.random() * b).toString(base);\n        res = x + res;\n    }\n\n    var parsed = parseInt(res, base);\n    if((existing && existing[res]) ||\n         (parsed !== Infinity && parsed >= Math.pow(2, bits))) {\n        if(_recursion > 10) {\n            lib.warn('randstr failed uniqueness');\n            return res;\n        }\n        return randstr(existing, bits, base, (_recursion || 0) + 1);\n    } else return res;\n};\n\nlib.OptionControl = function(opt, optname) {\n    /*\n     * An environment to contain all option setters and\n     * getters that collectively modify opts.\n     *\n     * You can call up opts from any function in new object\n     * as this.optname || this.opt\n     *\n     * See FitOpts for example of usage\n     */\n    if(!opt) opt = {};\n    if(!optname) optname = 'opt';\n\n    var self = {};\n    self.optionList = [];\n\n    self._newoption = function(optObj) {\n        optObj[optname] = opt;\n        self[optObj.name] = optObj;\n        self.optionList.push(optObj);\n    };\n\n    self['_' + optname] = opt;\n    return self;\n};\n\n/**\n * lib.smooth: smooth arrayIn by convolving with\n * a hann window with given full width at half max\n * bounce the ends in, so the output has the same length as the input\n */\nlib.smooth = function(arrayIn, FWHM) {\n    FWHM = Math.round(FWHM) || 0; // only makes sense for integers\n    if(FWHM < 2) return arrayIn;\n\n    var alen = arrayIn.length;\n    var alen2 = 2 * alen;\n    var wlen = 2 * FWHM - 1;\n    var w = new Array(wlen);\n    var arrayOut = new Array(alen);\n    var i;\n    var j;\n    var k;\n    var v;\n\n    // first make the window array\n    for(i = 0; i < wlen; i++) {\n        w[i] = (1 - Math.cos(Math.PI * (i + 1) / FWHM)) / (2 * FWHM);\n    }\n\n    // now do the convolution\n    for(i = 0; i < alen; i++) {\n        v = 0;\n        for(j = 0; j < wlen; j++) {\n            k = i + j + 1 - FWHM;\n\n            // multibounce\n            if(k < -alen) k -= alen2 * Math.round(k / alen2);\n            else if(k >= alen2) k -= alen2 * Math.floor(k / alen2);\n\n            // single bounce\n            if(k < 0) k = - 1 - k;\n            else if(k >= alen) k = alen2 - 1 - k;\n\n            v += arrayIn[k] * w[j];\n        }\n        arrayOut[i] = v;\n    }\n\n    return arrayOut;\n};\n\n/**\n * syncOrAsync: run a sequence of functions synchronously\n * as long as its returns are not promises (ie have no .then)\n * includes one argument arg to send to all functions...\n * this is mainly just to prevent us having to make wrapper functions\n * when the only purpose of the wrapper is to reference gd\n * and a final step to be executed at the end\n * TODO: if there's an error and everything is sync,\n * this doesn't happen yet because we want to make sure\n * that it gets reported\n */\nlib.syncOrAsync = function(sequence, arg, finalStep) {\n    var ret, fni;\n\n    function continueAsync() {\n        return lib.syncOrAsync(sequence, arg, finalStep);\n    }\n\n    while(sequence.length) {\n        fni = sequence.splice(0, 1)[0];\n        ret = fni(arg);\n\n        if(ret && ret.then) {\n            return ret.then(continueAsync)\n                .then(undefined, lib.promiseError);\n        }\n    }\n\n    return finalStep && finalStep(arg);\n};\n\n\n/**\n * Helper to strip trailing slash, from\n * http://stackoverflow.com/questions/6680825/return-string-without-trailing-slash\n */\nlib.stripTrailingSlash = function(str) {\n    if(str.substr(-1) === '/') return str.substr(0, str.length - 1);\n    return str;\n};\n\nlib.noneOrAll = function(containerIn, containerOut, attrList) {\n    /**\n     * some attributes come together, so if you have one of them\n     * in the input, you should copy the default values of the others\n     * to the input as well.\n     */\n    if(!containerIn) return;\n\n    var hasAny = false;\n    var hasAll = true;\n    var i;\n    var val;\n\n    for(i = 0; i < attrList.length; i++) {\n        val = containerIn[attrList[i]];\n        if(val !== undefined && val !== null) hasAny = true;\n        else hasAll = false;\n    }\n\n    if(hasAny && !hasAll) {\n        for(i = 0; i < attrList.length; i++) {\n            containerIn[attrList[i]] = containerOut[attrList[i]];\n        }\n    }\n};\n\n/** merges calcdata field (given by cdAttr) with traceAttr values\n *\n * N.B. Loop over minimum of cd.length and traceAttr.length\n * i.e. it does not try to fill in beyond traceAttr.length-1\n *\n * @param {array} traceAttr : trace attribute\n * @param {object} cd : calcdata trace\n * @param {string} cdAttr : calcdata key\n */\nlib.mergeArray = function(traceAttr, cd, cdAttr, fn) {\n    var hasFn = typeof fn === 'function';\n    if(lib.isArrayOrTypedArray(traceAttr)) {\n        var imax = Math.min(traceAttr.length, cd.length);\n        for(var i = 0; i < imax; i++) {\n            var v = traceAttr[i];\n            cd[i][cdAttr] = hasFn ? fn(v) : v;\n        }\n    }\n};\n\n// cast numbers to positive numbers, returns 0 if not greater than 0\nlib.mergeArrayCastPositive = function(traceAttr, cd, cdAttr) {\n    return lib.mergeArray(traceAttr, cd, cdAttr, function(v) {\n        var w = +v;\n        return !isFinite(w) ? 0 : w > 0 ? w : 0;\n    });\n};\n\n/** fills calcdata field (given by cdAttr) with traceAttr values\n *  or function of traceAttr values (e.g. some fallback)\n *\n * N.B. Loops over all cd items.\n *\n * @param {array} traceAttr : trace attribute\n * @param {object} cd : calcdata trace\n * @param {string} cdAttr : calcdata key\n * @param {function} [fn] : optional function to apply to each array item\n */\nlib.fillArray = function(traceAttr, cd, cdAttr, fn) {\n    fn = fn || lib.identity;\n\n    if(lib.isArrayOrTypedArray(traceAttr)) {\n        for(var i = 0; i < cd.length; i++) {\n            cd[i][cdAttr] = fn(traceAttr[i]);\n        }\n    }\n};\n\n/** Handler for trace-wide vs per-point options\n *\n * @param {object} trace : (full) trace object\n * @param {number} ptNumber : index of the point in question\n * @param {string} astr : attribute string\n * @param {function} [fn] : optional function to apply to each array item\n *\n * @return {any}\n */\nlib.castOption = function(trace, ptNumber, astr, fn) {\n    fn = fn || lib.identity;\n\n    var val = lib.nestedProperty(trace, astr).get();\n\n    if(lib.isArrayOrTypedArray(val)) {\n        if(Array.isArray(ptNumber) && lib.isArrayOrTypedArray(val[ptNumber[0]])) {\n            return fn(val[ptNumber[0]][ptNumber[1]]);\n        } else {\n            return fn(val[ptNumber]);\n        }\n    } else {\n        return val;\n    }\n};\n\n/** Extract option from calcdata item, correctly falling back to\n *  trace value if not found.\n *\n *  @param {object} calcPt : calcdata[i][j] item\n *  @param {object} trace : (full) trace object\n *  @param {string} calcKey : calcdata key\n *  @param {string} traceKey : aka trace attribute string\n *  @return {any}\n */\nlib.extractOption = function(calcPt, trace, calcKey, traceKey) {\n    if(calcKey in calcPt) return calcPt[calcKey];\n\n    // fallback to trace value,\n    //   must check if value isn't itself an array\n    //   which means the trace attribute has a corresponding\n    //   calcdata key, but its value is falsy\n    var traceVal = lib.nestedProperty(trace, traceKey).get();\n    if(!Array.isArray(traceVal)) return traceVal;\n};\n\nfunction makePtIndex2PtNumber(indexToPoints) {\n    var ptIndex2ptNumber = {};\n    for(var k in indexToPoints) {\n        var pts = indexToPoints[k];\n        for(var j = 0; j < pts.length; j++) {\n            ptIndex2ptNumber[pts[j]] = +k;\n        }\n    }\n    return ptIndex2ptNumber;\n}\n\n/** Tag selected calcdata items\n *\n * N.B. note that point 'index' corresponds to input data array index\n *  whereas 'number' is its post-transform version.\n *\n * @param {array} calcTrace\n * @param {object} trace\n *  - selectedpoints {array}\n *  - _indexToPoints {object}\n * @param {ptNumber2cdIndex} ptNumber2cdIndex (optional)\n *  optional map object for trace types that do not have 1-to-1 point number to\n *  calcdata item index correspondence (e.g. histogram)\n */\nlib.tagSelected = function(calcTrace, trace, ptNumber2cdIndex) {\n    var selectedpoints = trace.selectedpoints;\n    var indexToPoints = trace._indexToPoints;\n    var ptIndex2ptNumber;\n\n    // make pt index-to-number map object, which takes care of transformed traces\n    if(indexToPoints) {\n        ptIndex2ptNumber = makePtIndex2PtNumber(indexToPoints);\n    }\n\n    function isCdIndexValid(v) {\n        return v !== undefined && v < calcTrace.length;\n    }\n\n    for(var i = 0; i < selectedpoints.length; i++) {\n        var ptIndex = selectedpoints[i];\n\n        if(lib.isIndex(ptIndex)) {\n            var ptNumber = ptIndex2ptNumber ? ptIndex2ptNumber[ptIndex] : ptIndex;\n            var cdIndex = ptNumber2cdIndex ? ptNumber2cdIndex[ptNumber] : ptNumber;\n\n            if(isCdIndexValid(cdIndex)) {\n                calcTrace[cdIndex].selected = 1;\n            }\n        }\n    }\n};\n\nlib.selIndices2selPoints = function(trace) {\n    var selectedpoints = trace.selectedpoints;\n    var indexToPoints = trace._indexToPoints;\n\n    if(indexToPoints) {\n        var ptIndex2ptNumber = makePtIndex2PtNumber(indexToPoints);\n        var out = [];\n\n        for(var i = 0; i < selectedpoints.length; i++) {\n            var ptIndex = selectedpoints[i];\n            if(lib.isIndex(ptIndex)) {\n                var ptNumber = ptIndex2ptNumber[ptIndex];\n                if(lib.isIndex(ptNumber)) {\n                    out.push(ptNumber);\n                }\n            }\n        }\n\n        return out;\n    } else {\n        return selectedpoints;\n    }\n};\n\n/** Returns target as set by 'target' transform attribute\n *\n * @param {object} trace : full trace object\n * @param {object} transformOpts : transform option object\n *  - target (string} :\n *      either an attribute string referencing an array in the trace object, or\n *      a set array.\n *\n * @return {array or false} : the target array (NOT a copy!!) or false if invalid\n */\nlib.getTargetArray = function(trace, transformOpts) {\n    var target = transformOpts.target;\n\n    if(typeof target === 'string' && target) {\n        var array = lib.nestedProperty(trace, target).get();\n        return Array.isArray(array) ? array : false;\n    } else if(Array.isArray(target)) {\n        return target;\n    }\n\n    return false;\n};\n\n/**\n * modified version of jQuery's extend to strip out private objs and functions,\n * and cut arrays down to first <arraylen> or 1 elements\n * because extend-like algorithms are hella slow\n * obj2 is assumed to already be clean of these things (including no arrays)\n */\nlib.minExtend = function(obj1, obj2) {\n    var objOut = {};\n    if(typeof obj2 !== 'object') obj2 = {};\n    var arrayLen = 3;\n    var keys = Object.keys(obj1);\n    var i, k, v;\n\n    for(i = 0; i < keys.length; i++) {\n        k = keys[i];\n        v = obj1[k];\n        if(k.charAt(0) === '_' || typeof v === 'function') continue;\n        else if(k === 'module') objOut[k] = v;\n        else if(Array.isArray(v)) {\n            if(k === 'colorscale') {\n                objOut[k] = v.slice();\n            } else {\n                objOut[k] = v.slice(0, arrayLen);\n            }\n        } else if(v && (typeof v === 'object')) objOut[k] = lib.minExtend(obj1[k], obj2[k]);\n        else objOut[k] = v;\n    }\n\n    keys = Object.keys(obj2);\n    for(i = 0; i < keys.length; i++) {\n        k = keys[i];\n        v = obj2[k];\n        if(typeof v !== 'object' || !(k in objOut) || typeof objOut[k] !== 'object') {\n            objOut[k] = v;\n        }\n    }\n\n    return objOut;\n};\n\nlib.titleCase = function(s) {\n    return s.charAt(0).toUpperCase() + s.substr(1);\n};\n\nlib.containsAny = function(s, fragments) {\n    for(var i = 0; i < fragments.length; i++) {\n        if(s.indexOf(fragments[i]) !== -1) return true;\n    }\n    return false;\n};\n\nlib.isIE = function() {\n    return typeof window.navigator.msSaveBlob !== 'undefined';\n};\n\nvar IS_IE9_OR_BELOW_REGEX = /MSIE [1-9]\\./;\nlib.isIE9orBelow = function() {\n    return lib.isIE() && IS_IE9_OR_BELOW_REGEX.test(window.navigator.userAgent);\n};\n\nvar IS_SAFARI_REGEX = /Version\\/[\\d\\.]+.*Safari/;\nlib.isSafari = function() {\n    return IS_SAFARI_REGEX.test(window.navigator.userAgent);\n};\n\n/**\n * Duck typing to recognize a d3 selection, mostly for IE9's benefit\n * because it doesn't handle instanceof like modern browsers\n */\nlib.isD3Selection = function(obj) {\n    return obj && (typeof obj.classed === 'function');\n};\n\n/**\n * Append element to DOM only if not present.\n *\n * @param {d3 selection} parent : parent selection of the element in question\n * @param {string} nodeType : node type of element to append\n * @param {string} className (optional) : class name of element in question\n * @param {fn} enterFn (optional) : optional fn applied to entering elements only\n * @return {d3 selection} selection of new layer\n *\n * Previously, we were using the following pattern:\n *\n * ```\n * var sel = parent.selectAll('.' + className)\n *     .data([0]);\n *\n * sel.enter().append(nodeType)\n *     .classed(className, true);\n *\n * return sel;\n * ```\n *\n * in numerous places in our codebase to achieve the same behavior.\n *\n * The logic below performs much better, mostly as we are using\n * `.select` instead `.selectAll` that is `querySelector` instead of\n * `querySelectorAll`.\n *\n */\nlib.ensureSingle = function(parent, nodeType, className, enterFn) {\n    var sel = parent.select(nodeType + (className ? '.' + className : ''));\n    if(sel.size()) return sel;\n\n    var layer = parent.append(nodeType);\n    if(className) layer.classed(className, true);\n    if(enterFn) layer.call(enterFn);\n\n    return layer;\n};\n\n/**\n * Same as Lib.ensureSingle, but using id as selector.\n * This version is mostly used for clipPath nodes.\n *\n * @param {d3 selection} parent : parent selection of the element in question\n * @param {string} nodeType : node type of element to append\n * @param {string} id : id of element in question\n * @param {fn} enterFn (optional) : optional fn applied to entering elements only\n * @return {d3 selection} selection of new layer\n */\nlib.ensureSingleById = function(parent, nodeType, id, enterFn) {\n    var sel = parent.select(nodeType + '#' + id);\n    if(sel.size()) return sel;\n\n    var layer = parent.append(nodeType).attr('id', id);\n    if(enterFn) layer.call(enterFn);\n\n    return layer;\n};\n\n/**\n * Converts a string path to an object.\n *\n * When given a string containing an array element, it will create a `null`\n * filled array of the given size.\n *\n * @example\n * lib.objectFromPath('nested.test[2].path', 'value');\n * // returns { nested: { test: [null, null, { path: 'value' }]}\n *\n * @param   {string}    path to nested value\n * @param   {*}         any value to be set\n *\n * @return {Object} the constructed object with a full nested path\n */\nlib.objectFromPath = function(path, value) {\n    var keys = path.split('.');\n    var tmpObj;\n    var obj = tmpObj = {};\n\n    for(var i = 0; i < keys.length; i++) {\n        var key = keys[i];\n        var el = null;\n\n        var parts = keys[i].match(/(.*)\\[([0-9]+)\\]/);\n\n        if(parts) {\n            key = parts[1];\n            el = parts[2];\n\n            tmpObj = tmpObj[key] = [];\n\n            if(i === keys.length - 1) {\n                tmpObj[el] = value;\n            } else {\n                tmpObj[el] = {};\n            }\n\n            tmpObj = tmpObj[el];\n        } else {\n            if(i === keys.length - 1) {\n                tmpObj[key] = value;\n            } else {\n                tmpObj[key] = {};\n            }\n\n            tmpObj = tmpObj[key];\n        }\n    }\n\n    return obj;\n};\n\n/**\n * Iterate through an object in-place, converting dotted properties to objects.\n *\n * Examples:\n *\n *   lib.expandObjectPaths({'nested.test.path': 'value'});\n *     => { nested: { test: {path: 'value'}}}\n *\n * It also handles array notation, e.g.:\n *\n *   lib.expandObjectPaths({'foo[1].bar': 'value'});\n *     => { foo: [null, {bar: value}] }\n *\n * It handles merges the results when two properties are specified in parallel:\n *\n *   lib.expandObjectPaths({'foo[1].bar': 10, 'foo[0].bar': 20});\n *     => { foo: [{bar: 10}, {bar: 20}] }\n *\n * It does NOT, however, merge mulitple mutliply-nested arrays::\n *\n *   lib.expandObjectPaths({'marker[1].range[1]': 5, 'marker[1].range[0]': 4})\n *     => { marker: [null, {range: 4}] }\n */\n\n// Store this to avoid recompiling regex on *every* prop since this may happen many\n// many times for animations. Could maybe be inside the function. Not sure about\n// scoping vs. recompilation tradeoff, but at least it's not just inlining it into\n// the inner loop.\nvar dottedPropertyRegex = /^([^\\[\\.]+)\\.(.+)?/;\nvar indexedPropertyRegex = /^([^\\.]+)\\[([0-9]+)\\](\\.)?(.+)?/;\n\nlib.expandObjectPaths = function(data) {\n    var match, key, prop, datum, idx, dest, trailingPath;\n    if(typeof data === 'object' && !Array.isArray(data)) {\n        for(key in data) {\n            if(data.hasOwnProperty(key)) {\n                if((match = key.match(dottedPropertyRegex))) {\n                    datum = data[key];\n                    prop = match[1];\n\n                    delete data[key];\n\n                    data[prop] = lib.extendDeepNoArrays(data[prop] || {}, lib.objectFromPath(key, lib.expandObjectPaths(datum))[prop]);\n                } else if((match = key.match(indexedPropertyRegex))) {\n                    datum = data[key];\n\n                    prop = match[1];\n                    idx = parseInt(match[2]);\n\n                    delete data[key];\n\n                    data[prop] = data[prop] || [];\n\n                    if(match[3] === '.') {\n                        // This is the case where theere are subsequent properties into which\n                        // we must recurse, e.g. transforms[0].value\n                        trailingPath = match[4];\n                        dest = data[prop][idx] = data[prop][idx] || {};\n\n                        // NB: Extend deep no arrays prevents this from working on multiple\n                        // nested properties in the same object, e.g.\n                        //\n                        // {\n                        //   foo[0].bar[1].range\n                        //   foo[0].bar[0].range\n                        // }\n                        //\n                        // In this case, the extendDeepNoArrays will overwrite one array with\n                        // the other, so that both properties *will not* be present in the\n                        // result. Fixing this would require a more intelligent tracking\n                        // of changes and merging than extendDeepNoArrays currently accomplishes.\n                        lib.extendDeepNoArrays(dest, lib.objectFromPath(trailingPath, lib.expandObjectPaths(datum)));\n                    } else {\n                        // This is the case where this property is the end of the line,\n                        // e.g. xaxis.range[0]\n                        data[prop][idx] = lib.expandObjectPaths(datum);\n                    }\n                } else {\n                    data[key] = lib.expandObjectPaths(data[key]);\n                }\n            }\n        }\n    }\n\n    return data;\n};\n\n/**\n * Converts value to string separated by the provided separators.\n *\n * @example\n * lib.numSeparate(2016, '.,');\n * // returns '2016'\n *\n * @example\n * lib.numSeparate(3000, '.,', true);\n * // returns '3,000'\n *\n * @example\n * lib.numSeparate(1234.56, '|,')\n * // returns '1,234|56'\n *\n * @param   {string|number} value       the value to be converted\n * @param   {string}    separators  string of decimal, then thousands separators\n * @param   {boolean}    separatethousands  boolean, 4-digit integers are separated if true\n *\n * @return  {string}    the value that has been separated\n */\nlib.numSeparate = function(value, separators, separatethousands) {\n    if(!separatethousands) separatethousands = false;\n\n    if(typeof separators !== 'string' || separators.length === 0) {\n        throw new Error('Separator string required for formatting!');\n    }\n\n    if(typeof value === 'number') {\n        value = String(value);\n    }\n\n    var thousandsRe = /(\\d+)(\\d{3})/;\n    var decimalSep = separators.charAt(0);\n    var thouSep = separators.charAt(1);\n\n    var x = value.split('.');\n    var x1 = x[0];\n    var x2 = x.length > 1 ? decimalSep + x[1] : '';\n\n    // Years are ignored for thousands separators\n    if(thouSep && (x.length > 1 || x1.length > 4 || separatethousands)) {\n        while(thousandsRe.test(x1)) {\n            x1 = x1.replace(thousandsRe, '$1' + thouSep + '$2');\n        }\n    }\n\n    return x1 + x2;\n};\n\nlib.TEMPLATE_STRING_REGEX = /%{([^\\s%{}:]*)(:[^}]*)?}/g;\nvar SIMPLE_PROPERTY_REGEX = /^\\w*$/;\n\n/**\n * Substitute values from an object into a string\n *\n * Examples:\n *  Lib.templateString('name: %{trace}', {trace: 'asdf'}) --> 'name: asdf'\n *  Lib.templateString('name: %{trace[0].name}', {trace: [{name: 'asdf'}]}) --> 'name: asdf'\n *\n * @param {string}  input string containing %{...} template strings\n * @param {obj}     data object containing substitution values\n *\n * @return {string} templated string\n */\nlib.templateString = function(string, obj) {\n    // Not all that useful, but cache nestedProperty instantiation\n    // just in case it speeds things up *slightly*:\n    var getterCache = {};\n\n    return string.replace(lib.TEMPLATE_STRING_REGEX, function(dummy, key) {\n        if(SIMPLE_PROPERTY_REGEX.test(key)) {\n            return obj[key] || '';\n        }\n        getterCache[key] = getterCache[key] || lib.nestedProperty(obj, key).get;\n        return getterCache[key]() || '';\n    });\n};\n\nvar TEMPLATE_STRING_FORMAT_SEPARATOR = /^:/;\nvar numberOfHoverTemplateWarnings = 0;\nvar maximumNumberOfHoverTemplateWarnings = 10;\n/**\n * Substitute values from an object into a string and optionally formats them using d3-format,\n * or fallback to associated labels.\n *\n * Examples:\n *  Lib.hovertemplateString('name: %{trace}', {trace: 'asdf'}) --> 'name: asdf'\n *  Lib.hovertemplateString('name: %{trace[0].name}', {trace: [{name: 'asdf'}]}) --> 'name: asdf'\n *  Lib.hovertemplateString('price: %{y:$.2f}', {y: 1}) --> 'price: $1.00'\n *\n * @param {obj}     d3 locale\n * @param {string}  input string containing %{...:...} template strings\n * @param {obj}     data object containing fallback text when no formatting is specified, ex.: {yLabel: 'formattedYValue'}\n * @param {obj}     data objects containing substitution values\n *\n * @return {string} templated string\n */\nlib.hovertemplateString = function(string, labels, d3locale) {\n    var args = arguments;\n    // Not all that useful, but cache nestedProperty instantiation\n    // just in case it speeds things up *slightly*:\n    var getterCache = {};\n\n    return string.replace(lib.TEMPLATE_STRING_REGEX, function(match, key, format) {\n        var obj, value, i;\n        for(i = 3; i < args.length; i++) {\n            obj = args[i];\n            if(obj.hasOwnProperty(key)) {\n                value = obj[key];\n                break;\n            }\n\n            if(!SIMPLE_PROPERTY_REGEX.test(key)) {\n                value = getterCache[key] || lib.nestedProperty(obj, key).get();\n                if(value) getterCache[key] = value;\n            }\n            if(value !== undefined) break;\n        }\n\n        if(value === undefined) {\n            if(numberOfHoverTemplateWarnings < maximumNumberOfHoverTemplateWarnings) {\n                lib.warn('Variable \\'' + key + '\\' in hovertemplate could not be found!');\n                value = match;\n            }\n\n            if(numberOfHoverTemplateWarnings === maximumNumberOfHoverTemplateWarnings) {\n                lib.warn('Too many hovertemplate warnings - additional warnings will be suppressed');\n            }\n            numberOfHoverTemplateWarnings++;\n        }\n\n        if(format) {\n            var fmt;\n            if(d3locale) {\n                fmt = d3locale.numberFormat;\n            } else {\n                fmt = d3.format;\n            }\n            value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);\n        } else {\n            if(labels.hasOwnProperty(key + 'Label')) value = labels[key + 'Label'];\n        }\n        return value;\n    });\n};\n\n/*\n * alphanumeric string sort, tailored for subplot IDs like scene2, scene10, x10y13 etc\n */\nvar char0 = 48;\nvar char9 = 57;\nlib.subplotSort = function(a, b) {\n    var l = Math.min(a.length, b.length) + 1;\n    var numA = 0;\n    var numB = 0;\n    for(var i = 0; i < l; i++) {\n        var charA = a.charCodeAt(i) || 0;\n        var charB = b.charCodeAt(i) || 0;\n        var isNumA = charA >= char0 && charA <= char9;\n        var isNumB = charB >= char0 && charB <= char9;\n\n        if(isNumA) numA = 10 * numA + charA - char0;\n        if(isNumB) numB = 10 * numB + charB - char0;\n\n        if(!isNumA || !isNumB) {\n            if(numA !== numB) return numA - numB;\n            if(charA !== charB) return charA - charB;\n        }\n    }\n    return numB - numA;\n};\n\n// repeatable pseudorandom generator\nvar randSeed = 2000000000;\n\nlib.seedPseudoRandom = function() {\n    randSeed = 2000000000;\n};\n\nlib.pseudoRandom = function() {\n    var lastVal = randSeed;\n    randSeed = (69069 * randSeed + 1) % 4294967296;\n    // don't let consecutive vals be too close together\n    // gets away from really trying to be random, in favor of better local uniformity\n    if(Math.abs(randSeed - lastVal) < 429496729) return lib.pseudoRandom();\n    return randSeed / 4294967296;\n};\n\n\n/** Fill hover 'pointData' container with 'correct' hover text value\n *\n * - If trace hoverinfo contains a 'text' flag and hovertext is not set,\n *   the text elements will be seen in the hover labels.\n *\n * - If trace hoverinfo contains a 'text' flag and hovertext is set,\n *   hovertext takes precedence over text\n *   i.e. the hoverinfo elements will be seen in the hover labels\n *\n *  @param {object} calcPt\n *  @param {object} trace\n *  @param {object || array} contOut (mutated here)\n */\nlib.fillText = function(calcPt, trace, contOut) {\n    var fill = Array.isArray(contOut) ?\n        function(v) { contOut.push(v); } :\n        function(v) { contOut.text = v; };\n\n    var htx = lib.extractOption(calcPt, trace, 'htx', 'hovertext');\n    if(lib.isValidTextValue(htx)) return fill(htx);\n\n    var tx = lib.extractOption(calcPt, trace, 'tx', 'text');\n    if(lib.isValidTextValue(tx)) return fill(tx);\n};\n\n// accept all truthy values and 0 (which gets cast to '0' in the hover labels)\nlib.isValidTextValue = function(v) {\n    return v || v === 0;\n};\n\nlib.formatPercent = function(ratio, n) {\n    n = n || 0;\n    var str = (Math.round(100 * ratio * Math.pow(10, n)) * Math.pow(0.1, n)).toFixed(n) + '%';\n    for(var i = 0; i < n; i++) {\n        if(str.indexOf('.') !== -1) {\n            str = str.replace('0%', '%');\n            str = str.replace('.%', '%');\n        }\n    }\n    return str;\n};\n\nlib.isHidden = function(gd) {\n    var display = window.getComputedStyle(gd).display;\n    return !display || display === 'none';\n};\n\n},{\"../constants/numerical\":695,\"./anchor_utils\":700,\"./angles\":701,\"./array\":702,\"./clean_number\":703,\"./clear_responsive\":705,\"./coerce\":706,\"./dates\":707,\"./dom\":708,\"./extend\":710,\"./filter_unique\":711,\"./filter_visible\":712,\"./geometry2d\":715,\"./identity\":718,\"./is_plain_object\":720,\"./keyed_container\":721,\"./localize\":722,\"./loggers\":723,\"./make_trace_groups\":724,\"./matrix\":725,\"./mod\":726,\"./nested_property\":727,\"./noop\":728,\"./notifier\":729,\"./push_unique\":733,\"./regex\":735,\"./relative_attr\":736,\"./relink_private\":737,\"./search\":738,\"./stats\":741,\"./throttle\":744,\"./to_log_range\":745,\"d3\":163,\"fast-isnumeric\":225}],720:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n// more info: http://stackoverflow.com/questions/18531624/isplainobject-thing\nmodule.exports = function isPlainObject(obj) {\n    // We need to be a little less strict in the `imagetest` container because\n    // of how async image requests are handled.\n    //\n    // N.B. isPlainObject(new Constructor()) will return true in `imagetest`\n    if(window && window.process && window.process.versions) {\n        return Object.prototype.toString.call(obj) === '[object Object]';\n    }\n\n    return (\n        Object.prototype.toString.call(obj) === '[object Object]' &&\n        Object.getPrototypeOf(obj) === Object.prototype\n    );\n};\n\n},{}],721:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar nestedProperty = _dereq_('./nested_property');\n\nvar SIMPLE_PROPERTY_REGEX = /^\\w*$/;\n\n// bitmask for deciding what's updated. Sometimes the name needs to be updated,\n// sometimes the value needs to be updated, and sometimes both do. This is just\n// a simple way to track what's updated such that it's a simple OR operation to\n// assimilate new updates.\n//\n// The only exception is the UNSET bit that tracks when we need to explicitly\n// unset and remove the property. This concrn arises because of the special\n// way in which nestedProperty handles null/undefined. When you specify `null`,\n// it prunes any unused items in the tree. I ran into some issues with it getting\n// null vs undefined confused, so UNSET is just a bit that forces the property\n// update to send `null`, removing the property explicitly rather than setting\n// it to undefined.\nvar NONE = 0;\nvar NAME = 1;\nvar VALUE = 2;\nvar BOTH = 3;\nvar UNSET = 4;\n\nmodule.exports = function keyedContainer(baseObj, path, keyName, valueName) {\n    keyName = keyName || 'name';\n    valueName = valueName || 'value';\n    var i, arr, baseProp;\n    var changeTypes = {};\n\n    if(path && path.length) {\n        baseProp = nestedProperty(baseObj, path);\n        arr = baseProp.get();\n    } else {\n        arr = baseObj;\n    }\n\n    path = path || '';\n\n    // Construct an index:\n    var indexLookup = {};\n    if(arr) {\n        for(i = 0; i < arr.length; i++) {\n            indexLookup[arr[i][keyName]] = i;\n        }\n    }\n\n    var isSimpleValueProp = SIMPLE_PROPERTY_REGEX.test(valueName);\n\n    var obj = {\n        set: function(name, value) {\n            var changeType = value === null ? UNSET : NONE;\n\n            // create the base array if necessary\n            if(!arr) {\n                if(!baseProp || changeType === UNSET) return;\n\n                arr = [];\n                baseProp.set(arr);\n            }\n\n            var idx = indexLookup[name];\n            if(idx === undefined) {\n                if(changeType === UNSET) return;\n\n                changeType = changeType | BOTH;\n                idx = arr.length;\n                indexLookup[name] = idx;\n            } else if(value !== (isSimpleValueProp ? arr[idx][valueName] : nestedProperty(arr[idx], valueName).get())) {\n                changeType = changeType | VALUE;\n            }\n\n            var newValue = arr[idx] = arr[idx] || {};\n            newValue[keyName] = name;\n\n            if(isSimpleValueProp) {\n                newValue[valueName] = value;\n            } else {\n                nestedProperty(newValue, valueName).set(value);\n            }\n\n            // If it's not an unset, force that bit to be unset. This is all related to the fact\n            // that undefined and null are a bit specially implemented in nestedProperties.\n            if(value !== null) {\n                changeType = changeType & ~UNSET;\n            }\n\n            changeTypes[idx] = changeTypes[idx] | changeType;\n\n            return obj;\n        },\n        get: function(name) {\n            if(!arr) return;\n\n            var idx = indexLookup[name];\n\n            if(idx === undefined) {\n                return undefined;\n            } else if(isSimpleValueProp) {\n                return arr[idx][valueName];\n            } else {\n                return nestedProperty(arr[idx], valueName).get();\n            }\n        },\n        rename: function(name, newName) {\n            var idx = indexLookup[name];\n\n            if(idx === undefined) return obj;\n            changeTypes[idx] = changeTypes[idx] | NAME;\n\n            indexLookup[newName] = idx;\n            delete indexLookup[name];\n\n            arr[idx][keyName] = newName;\n\n            return obj;\n        },\n        remove: function(name) {\n            var idx = indexLookup[name];\n\n            if(idx === undefined) return obj;\n\n            var object = arr[idx];\n            if(Object.keys(object).length > 2) {\n                // This object contains more than just the key/value, so unset\n                // the value without modifying the entry otherwise:\n                changeTypes[idx] = changeTypes[idx] | VALUE;\n                return obj.set(name, null);\n            }\n\n            if(isSimpleValueProp) {\n                for(i = idx; i < arr.length; i++) {\n                    changeTypes[i] = changeTypes[i] | BOTH;\n                }\n                for(i = idx; i < arr.length; i++) {\n                    indexLookup[arr[i][keyName]]--;\n                }\n                arr.splice(idx, 1);\n                delete(indexLookup[name]);\n            } else {\n                // Perform this update *strictly* so we can check whether the result's\n                // been pruned. If so, it's a removal. If not, it's a value unset only.\n                nestedProperty(object, valueName).set(null);\n\n                // Now check if the top level nested property has any keys left. If so,\n                // the object still has values so we only want to unset the key. If not,\n                // the entire object can be removed since there's no other data.\n                // var topLevelKeys = Object.keys(object[valueName.split('.')[0]] || []);\n\n                changeTypes[idx] = changeTypes[idx] | VALUE | UNSET;\n            }\n\n            return obj;\n        },\n        constructUpdate: function() {\n            var astr, idx;\n            var update = {};\n            var changed = Object.keys(changeTypes);\n            for(var i = 0; i < changed.length; i++) {\n                idx = changed[i];\n                astr = path + '[' + idx + ']';\n                if(arr[idx]) {\n                    if(changeTypes[idx] & NAME) {\n                        update[astr + '.' + keyName] = arr[idx][keyName];\n                    }\n                    if(changeTypes[idx] & VALUE) {\n                        if(isSimpleValueProp) {\n                            update[astr + '.' + valueName] = (changeTypes[idx] & UNSET) ? null : arr[idx][valueName];\n                        } else {\n                            update[astr + '.' + valueName] = (changeTypes[idx] & UNSET) ? null : nestedProperty(arr[idx], valueName).get();\n                        }\n                    }\n                } else {\n                    update[astr] = null;\n                }\n            }\n\n            return update;\n        }\n    };\n\n    return obj;\n};\n\n},{\"./nested_property\":727}],722:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Registry = _dereq_('../registry');\n\n/**\n * localize: translate a string for the current locale\n *\n * @param {object} gd: the graphDiv for context\n *  gd._context.locale determines the language (& optional region/country)\n *  the dictionary for each locale may either be supplied in\n *  gd._context.locales or globally via Plotly.register\n * @param {string} s: the string to translate\n */\nmodule.exports = function localize(gd, s) {\n    var locale = gd._context.locale;\n\n    /*\n     * Priority of lookup:\n     *     contextDicts[locale],\n     *     registeredDicts[locale],\n     *     contextDicts[baseLocale], (if baseLocale is distinct)\n     *     registeredDicts[baseLocale]\n     * Return the first translation we find.\n     * This way if you have a regionalization you are allowed to specify\n     * only what's different from the base locale, everything else will\n     * fall back on the base.\n     */\n    for(var i = 0; i < 2; i++) {\n        var locales = gd._context.locales;\n        for(var j = 0; j < 2; j++) {\n            var dict = (locales[locale] || {}).dictionary;\n            if(dict) {\n                var out = dict[s];\n                if(out) return out;\n            }\n            locales = Registry.localeRegistry;\n        }\n\n        var baseLocale = locale.split('-')[0];\n        if(baseLocale === locale) break;\n        locale = baseLocale;\n    }\n\n    return s;\n};\n\n},{\"../registry\":847}],723:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/* eslint-disable no-console */\n\nvar dfltConfig = _dereq_('../plot_api/plot_config').dfltConfig;\n\nvar loggers = module.exports = {};\n\n/**\n * ------------------------------------------\n * debugging tools\n * ------------------------------------------\n */\n\nloggers.log = function() {\n    if(dfltConfig.logging > 1) {\n        var messages = ['LOG:'];\n\n        for(var i = 0; i < arguments.length; i++) {\n            messages.push(arguments[i]);\n        }\n\n        apply(console.trace || console.log, messages);\n    }\n};\n\nloggers.warn = function() {\n    if(dfltConfig.logging > 0) {\n        var messages = ['WARN:'];\n\n        for(var i = 0; i < arguments.length; i++) {\n            messages.push(arguments[i]);\n        }\n\n        apply(console.trace || console.log, messages);\n    }\n};\n\nloggers.error = function() {\n    if(dfltConfig.logging > 0) {\n        var messages = ['ERROR:'];\n\n        for(var i = 0; i < arguments.length; i++) {\n            messages.push(arguments[i]);\n        }\n\n        apply(console.error, messages);\n    }\n};\n\n/*\n * Robust apply, for IE9 where console.log doesn't support\n * apply like other functions do\n */\nfunction apply(f, args) {\n    if(f && f.apply) {\n        try {\n            // `this` should always be console, since here we're always\n            // applying a method of the console object.\n            f.apply(console, args);\n            return;\n        } catch(e) { /* in case apply failed, fall back on the code below */ }\n    }\n\n    // no apply - just try calling the function on each arg independently\n    for(var i = 0; i < args.length; i++) {\n        try {\n            f(args[i]);\n        } catch(e) {\n            // still fails - last resort simple console.log\n            console.log(args[i]);\n        }\n    }\n}\n\n},{\"../plot_api/plot_config\":755}],724:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\n/**\n * General helper to manage trace groups based on calcdata\n *\n * @param {d3.selection} traceLayer: a selection containing a single group\n *     to draw these traces into\n * @param {array} cdModule: array of calcdata items for this\n *     module and subplot combination. Assumes the calcdata item for each\n *     trace is an array with the fullData trace attached to the first item.\n * @param {string} cls: the class attribute to give each trace group\n *     so you can give multiple classes separated by spaces\n */\nmodule.exports = function makeTraceGroups(traceLayer, cdModule, cls) {\n    var traces = traceLayer.selectAll('g.' + cls.replace(/\\s/g, '.'))\n        .data(cdModule, function(cd) { return cd[0].trace.uid; });\n\n    traces.exit().remove();\n\n    traces.enter().append('g')\n        .attr('class', cls);\n\n    traces.order();\n\n    // stash ref node to trace group in calcdata,\n    // useful for (fast) styleOnSelect\n    var k = traceLayer.classed('rangeplot') ? 'nodeRangePlot3' : 'node3';\n    traces.each(function(cd) { cd[0][k] = d3.select(this); });\n\n    return traces;\n};\n\n},{\"d3\":163}],725:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nexports.init2dArray = function(rowLength, colLength) {\n    var array = new Array(rowLength);\n    for(var i = 0; i < rowLength; i++) array[i] = new Array(colLength);\n    return array;\n};\n\n/**\n * transpose a (possibly ragged) 2d array z. inspired by\n * http://stackoverflow.com/questions/17428587/\n * transposing-a-2d-array-in-javascript\n */\nexports.transposeRagged = function(z) {\n    var maxlen = 0;\n    var zlen = z.length;\n    var i, j;\n    // Maximum row length:\n    for(i = 0; i < zlen; i++) maxlen = Math.max(maxlen, z[i].length);\n\n    var t = new Array(maxlen);\n    for(i = 0; i < maxlen; i++) {\n        t[i] = new Array(zlen);\n        for(j = 0; j < zlen; j++) t[i][j] = z[j][i];\n    }\n\n    return t;\n};\n\n// our own dot function so that we don't need to include numeric\nexports.dot = function(x, y) {\n    if(!(x.length && y.length) || x.length !== y.length) return null;\n\n    var len = x.length;\n    var out;\n    var i;\n\n    if(x[0].length) {\n        // mat-vec or mat-mat\n        out = new Array(len);\n        for(i = 0; i < len; i++) out[i] = exports.dot(x[i], y);\n    } else if(y[0].length) {\n        // vec-mat\n        var yTranspose = exports.transposeRagged(y);\n        out = new Array(yTranspose.length);\n        for(i = 0; i < yTranspose.length; i++) out[i] = exports.dot(x, yTranspose[i]);\n    } else {\n        // vec-vec\n        out = 0;\n        for(i = 0; i < len; i++) out += x[i] * y[i];\n    }\n\n    return out;\n};\n\n// translate by (x,y)\nexports.translationMatrix = function(x, y) {\n    return [[1, 0, x], [0, 1, y], [0, 0, 1]];\n};\n\n// rotate by alpha around (0,0)\nexports.rotationMatrix = function(alpha) {\n    var a = alpha * Math.PI / 180;\n    return [[Math.cos(a), -Math.sin(a), 0],\n            [Math.sin(a), Math.cos(a), 0],\n            [0, 0, 1]];\n};\n\n// rotate by alpha around (x,y)\nexports.rotationXYMatrix = function(a, x, y) {\n    return exports.dot(\n        exports.dot(exports.translationMatrix(x, y),\n                    exports.rotationMatrix(a)),\n        exports.translationMatrix(-x, -y));\n};\n\n// applies a 2D transformation matrix to either x and y params or an [x,y] array\nexports.apply2DTransform = function(transform) {\n    return function() {\n        var args = arguments;\n        if(args.length === 3) {\n            args = args[0];\n        }// from map\n        var xy = arguments.length === 1 ? args[0] : [args[0], args[1]];\n        return exports.dot(transform, [xy[0], xy[1], 1]).slice(0, 2);\n    };\n};\n\n// applies a 2D transformation matrix to an [x1,y1,x2,y2] array (to transform a segment)\nexports.apply2DTransform2 = function(transform) {\n    var at = exports.apply2DTransform(transform);\n    return function(xys) {\n        return at(xys.slice(0, 2)).concat(at(xys.slice(2, 4)));\n    };\n};\n\n},{}],726:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * sanitized modulus function that always returns in the range [0, d)\n * rather than (-d, 0] if v is negative\n */\nfunction mod(v, d) {\n    var out = v % d;\n    return out < 0 ? out + d : out;\n}\n\n/**\n * sanitized modulus function that always returns in the range [-d/2, d/2]\n * rather than (-d, 0] if v is negative\n */\nfunction modHalf(v, d) {\n    return Math.abs(v) > (d / 2) ?\n        v - Math.round(v / d) * d :\n        v;\n}\n\nmodule.exports = {\n    mod: mod,\n    modHalf: modHalf\n};\n\n},{}],727:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar isArrayOrTypedArray = _dereq_('./array').isArrayOrTypedArray;\n\n/**\n * convert a string s (such as 'xaxis.range[0]')\n * representing a property of nested object into set and get methods\n * also return the string and object so we don't have to keep track of them\n * allows [-1] for an array index, to set a property inside all elements\n * of an array\n * eg if obj = {arr: [{a: 1}, {a: 2}]}\n * you can do p = nestedProperty(obj, 'arr[-1].a')\n * but you cannot set the array itself this way, to do that\n * just set the whole array.\n * eg if obj = {arr: [1, 2, 3]}\n * you can't do nestedProperty(obj, 'arr[-1]').set(5)\n * but you can do nestedProperty(obj, 'arr').set([5, 5, 5])\n */\nmodule.exports = function nestedProperty(container, propStr) {\n    if(isNumeric(propStr)) propStr = String(propStr);\n    else if(typeof propStr !== 'string' ||\n            propStr.substr(propStr.length - 4) === '[-1]') {\n        throw 'bad property string';\n    }\n\n    var j = 0;\n    var propParts = propStr.split('.');\n    var indexed;\n    var indices;\n    var i;\n\n    // check for parts of the nesting hierarchy that are numbers (ie array elements)\n    while(j < propParts.length) {\n        // look for non-bracket chars, then any number of [##] blocks\n        indexed = String(propParts[j]).match(/^([^\\[\\]]*)((\\[\\-?[0-9]*\\])+)$/);\n        if(indexed) {\n            if(indexed[1]) propParts[j] = indexed[1];\n            // allow propStr to start with bracketed array indices\n            else if(j === 0) propParts.splice(0, 1);\n            else throw 'bad property string';\n\n            indices = indexed[2]\n                .substr(1, indexed[2].length - 2)\n                .split('][');\n\n            for(i = 0; i < indices.length; i++) {\n                j++;\n                propParts.splice(j, 0, Number(indices[i]));\n            }\n        }\n        j++;\n    }\n\n    if(typeof container !== 'object') {\n        return badContainer(container, propStr, propParts);\n    }\n\n    return {\n        set: npSet(container, propParts, propStr),\n        get: npGet(container, propParts),\n        astr: propStr,\n        parts: propParts,\n        obj: container\n    };\n};\n\nfunction npGet(cont, parts) {\n    return function() {\n        var curCont = cont;\n        var curPart;\n        var allSame;\n        var out;\n        var i;\n        var j;\n\n        for(i = 0; i < parts.length - 1; i++) {\n            curPart = parts[i];\n            if(curPart === -1) {\n                allSame = true;\n                out = [];\n                for(j = 0; j < curCont.length; j++) {\n                    out[j] = npGet(curCont[j], parts.slice(i + 1))();\n                    if(out[j] !== out[0]) allSame = false;\n                }\n                return allSame ? out[0] : out;\n            }\n            if(typeof curPart === 'number' && !isArrayOrTypedArray(curCont)) {\n                return undefined;\n            }\n            curCont = curCont[curPart];\n            if(typeof curCont !== 'object' || curCont === null) {\n                return undefined;\n            }\n        }\n\n        // only hit this if parts.length === 1\n        if(typeof curCont !== 'object' || curCont === null) return undefined;\n\n        out = curCont[parts[i]];\n        if(out === null) return undefined;\n        return out;\n    };\n}\n\n/*\n * Can this value be deleted? We can delete `undefined`, and `null` except INSIDE an\n * *args* array.\n *\n * Previously we also deleted some `{}` and `[]`, in order to try and make set/unset\n * a net noop; but this causes far more complication than it's worth, and still had\n * lots of exceptions. See https://github.com/plotly/plotly.js/issues/1410\n *\n * *args* arrays get passed directly to API methods and we should respect null if\n * the user put it there, but otherwise null is deleted as we use it as code\n * in restyle/relayout/update for \"delete this value\" whereas undefined means\n * \"ignore this edit\"\n */\nvar ARGS_PATTERN = /(^|\\.)args\\[/;\nfunction isDeletable(val, propStr) {\n    return (val === undefined) || (val === null && !propStr.match(ARGS_PATTERN));\n}\n\nfunction npSet(cont, parts, propStr) {\n    return function(val) {\n        var curCont = cont;\n        var propPart = '';\n        var containerLevels = [[cont, propPart]];\n        var toDelete = isDeletable(val, propStr);\n        var curPart;\n        var i;\n\n        for(i = 0; i < parts.length - 1; i++) {\n            curPart = parts[i];\n\n            if(typeof curPart === 'number' && !isArrayOrTypedArray(curCont)) {\n                throw 'array index but container is not an array';\n            }\n\n            // handle special -1 array index\n            if(curPart === -1) {\n                toDelete = !setArrayAll(curCont, parts.slice(i + 1), val, propStr);\n                if(toDelete) break;\n                else return;\n            }\n\n            if(!checkNewContainer(curCont, curPart, parts[i + 1], toDelete)) {\n                break;\n            }\n\n            curCont = curCont[curPart];\n\n            if(typeof curCont !== 'object' || curCont === null) {\n                throw 'container is not an object';\n            }\n\n            propPart = joinPropStr(propPart, curPart);\n\n            containerLevels.push([curCont, propPart]);\n        }\n\n        if(toDelete) {\n            if(i === parts.length - 1) {\n                delete curCont[parts[i]];\n\n                // The one bit of pruning we still do: drop `undefined` from the end of arrays.\n                // In case someone has already unset previous items, continue until we hit a\n                // non-undefined value.\n                if(Array.isArray(curCont) && +parts[i] === curCont.length - 1) {\n                    while(curCont.length && curCont[curCont.length - 1] === undefined) {\n                        curCont.pop();\n                    }\n                }\n            }\n        } else curCont[parts[i]] = val;\n    };\n}\n\nfunction joinPropStr(propStr, newPart) {\n    var toAdd = newPart;\n    if(isNumeric(newPart)) toAdd = '[' + newPart + ']';\n    else if(propStr) toAdd = '.' + newPart;\n\n    return propStr + toAdd;\n}\n\n// handle special -1 array index\nfunction setArrayAll(containerArray, innerParts, val, propStr) {\n    var arrayVal = isArrayOrTypedArray(val);\n    var allSet = true;\n    var thisVal = val;\n    var thisPropStr = propStr.replace('-1', 0);\n    var deleteThis = arrayVal ? false : isDeletable(val, thisPropStr);\n    var firstPart = innerParts[0];\n    var i;\n\n    for(i = 0; i < containerArray.length; i++) {\n        thisPropStr = propStr.replace('-1', i);\n        if(arrayVal) {\n            thisVal = val[i % val.length];\n            deleteThis = isDeletable(thisVal, thisPropStr);\n        }\n        if(deleteThis) allSet = false;\n        if(!checkNewContainer(containerArray, i, firstPart, deleteThis)) {\n            continue;\n        }\n        npSet(containerArray[i], innerParts, propStr.replace('-1', i))(thisVal);\n    }\n    return allSet;\n}\n\n/**\n * make new sub-container as needed.\n * returns false if there's no container and none is needed\n * because we're only deleting an attribute\n */\nfunction checkNewContainer(container, part, nextPart, toDelete) {\n    if(container[part] === undefined) {\n        if(toDelete) return false;\n\n        if(typeof nextPart === 'number') container[part] = [];\n        else container[part] = {};\n    }\n    return true;\n}\n\nfunction badContainer(container, propStr, propParts) {\n    return {\n        set: function() { throw 'bad container'; },\n        get: function() {},\n        astr: propStr,\n        parts: propParts,\n        obj: container\n    };\n}\n\n},{\"./array\":702,\"fast-isnumeric\":225}],728:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// Simple helper functions\n// none of these need any external deps\n\nmodule.exports = function noop() {};\n\n},{}],729:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar NOTEDATA = [];\n\n/**\n * notifier\n * @param {String} text The person's user name\n * @param {Number} [delay=1000] The delay time in milliseconds\n *          or 'long' which provides 2000 ms delay time.\n * @return {undefined} this function does not return a value\n */\nmodule.exports = function(text, displayLength) {\n    if(NOTEDATA.indexOf(text) !== -1) return;\n\n    NOTEDATA.push(text);\n\n    var ts = 1000;\n    if(isNumeric(displayLength)) ts = displayLength;\n    else if(displayLength === 'long') ts = 3000;\n\n    var notifierContainer = d3.select('body')\n        .selectAll('.plotly-notifier')\n        .data([0]);\n    notifierContainer.enter()\n        .append('div')\n        .classed('plotly-notifier', true);\n\n    var notes = notifierContainer.selectAll('.notifier-note').data(NOTEDATA);\n\n    function killNote(transition) {\n        transition\n            .duration(700)\n            .style('opacity', 0)\n            .each('end', function(thisText) {\n                var thisIndex = NOTEDATA.indexOf(thisText);\n                if(thisIndex !== -1) NOTEDATA.splice(thisIndex, 1);\n                d3.select(this).remove();\n            });\n    }\n\n    notes.enter().append('div')\n        .classed('notifier-note', true)\n        .style('opacity', 0)\n        .each(function(thisText) {\n            var note = d3.select(this);\n\n            note.append('button')\n                .classed('notifier-close', true)\n                .html('&times;')\n                .on('click', function() {\n                    note.transition().call(killNote);\n                });\n\n            var p = note.append('p');\n            var lines = thisText.split(/<br\\s*\\/?>/g);\n            for(var i = 0; i < lines.length; i++) {\n                if(i) p.append('br');\n                p.append('span').text(lines[i]);\n            }\n\n            note.transition()\n                    .duration(700)\n                    .style('opacity', 1)\n                .transition()\n                    .delay(ts)\n                    .call(killNote);\n        });\n};\n\n},{\"d3\":163,\"fast-isnumeric\":225}],730:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar setCursor = _dereq_('./setcursor');\n\nvar STASHATTR = 'data-savedcursor';\nvar NO_CURSOR = '!!';\n\n/*\n * works with our CSS cursor classes (see css/_cursor.scss)\n * to override a previous cursor set on d3 single-element selections,\n * by moving the name of the original cursor to the data-savedcursor attr.\n * omit cursor to revert to the previously set value.\n */\nmodule.exports = function overrideCursor(el3, csr) {\n    var savedCursor = el3.attr(STASHATTR);\n    if(csr) {\n        if(!savedCursor) {\n            var classes = (el3.attr('class') || '').split(' ');\n            for(var i = 0; i < classes.length; i++) {\n                var cls = classes[i];\n                if(cls.indexOf('cursor-') === 0) {\n                    el3.attr(STASHATTR, cls.substr(7))\n                        .classed(cls, false);\n                }\n            }\n            if(!el3.attr(STASHATTR)) {\n                el3.attr(STASHATTR, NO_CURSOR);\n            }\n        }\n        setCursor(el3, csr);\n    } else if(savedCursor) {\n        el3.attr(STASHATTR, null);\n\n        if(savedCursor === NO_CURSOR) setCursor(el3);\n        else setCursor(el3, savedCursor);\n    }\n};\n\n},{\"./setcursor\":739}],731:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar dot = _dereq_('./matrix').dot;\nvar BADNUM = _dereq_('../constants/numerical').BADNUM;\n\nvar polygon = module.exports = {};\n\n/**\n * Turn an array of [x, y] pairs into a polygon object\n * that can test if points are inside it\n *\n * @param ptsIn Array of [x, y] pairs\n *\n * @returns polygon Object {xmin, xmax, ymin, ymax, pts, contains}\n *      (x|y)(min|max) are the bounding rect of the polygon\n *      pts is the original array, with the first pair repeated at the end\n *      contains is a function: (pt, omitFirstEdge)\n *          pt is the [x, y] pair to test\n *          omitFirstEdge truthy means points exactly on the first edge don't\n *              count. This is for use adding one polygon to another so we\n *              don't double-count the edge where they meet.\n *          returns boolean: is pt inside the polygon (including on its edges)\n */\npolygon.tester = function tester(ptsIn) {\n    var pts = ptsIn.slice();\n    var xmin = pts[0][0];\n    var xmax = xmin;\n    var ymin = pts[0][1];\n    var ymax = ymin;\n    var i;\n\n    pts.push(pts[0]);\n    for(i = 1; i < pts.length; i++) {\n        xmin = Math.min(xmin, pts[i][0]);\n        xmax = Math.max(xmax, pts[i][0]);\n        ymin = Math.min(ymin, pts[i][1]);\n        ymax = Math.max(ymax, pts[i][1]);\n    }\n\n    // do we have a rectangle? Handle this here, so we can use the same\n    // tester for the rectangular case without sacrificing speed\n\n    var isRect = false;\n    var rectFirstEdgeTest;\n\n    if(pts.length === 5) {\n        if(pts[0][0] === pts[1][0]) { // vert, horz, vert, horz\n            if(pts[2][0] === pts[3][0] &&\n                    pts[0][1] === pts[3][1] &&\n                    pts[1][1] === pts[2][1]) {\n                isRect = true;\n                rectFirstEdgeTest = function(pt) { return pt[0] === pts[0][0]; };\n            }\n        } else if(pts[0][1] === pts[1][1]) { // horz, vert, horz, vert\n            if(pts[2][1] === pts[3][1] &&\n                    pts[0][0] === pts[3][0] &&\n                    pts[1][0] === pts[2][0]) {\n                isRect = true;\n                rectFirstEdgeTest = function(pt) { return pt[1] === pts[0][1]; };\n            }\n        }\n    }\n\n    function rectContains(pt, omitFirstEdge) {\n        var x = pt[0];\n        var y = pt[1];\n\n        if(x === BADNUM || x < xmin || x > xmax || y === BADNUM || y < ymin || y > ymax) {\n            // pt is outside the bounding box of polygon\n            return false;\n        }\n        if(omitFirstEdge && rectFirstEdgeTest(pt)) return false;\n\n        return true;\n    }\n\n    function contains(pt, omitFirstEdge) {\n        var x = pt[0];\n        var y = pt[1];\n\n        if(x === BADNUM || x < xmin || x > xmax || y === BADNUM || y < ymin || y > ymax) {\n            // pt is outside the bounding box of polygon\n            return false;\n        }\n\n        var imax = pts.length;\n        var x1 = pts[0][0];\n        var y1 = pts[0][1];\n        var crossings = 0;\n        var i;\n        var x0;\n        var y0;\n        var xmini;\n        var ycross;\n\n        for(i = 1; i < imax; i++) {\n            // find all crossings of a vertical line upward from pt with\n            // polygon segments\n            // crossings exactly at xmax don't count, unless the point is\n            // exactly on the segment, then it counts as inside.\n            x0 = x1;\n            y0 = y1;\n            x1 = pts[i][0];\n            y1 = pts[i][1];\n            xmini = Math.min(x0, x1);\n\n            if(x < xmini || x > Math.max(x0, x1) || y > Math.max(y0, y1)) {\n                // outside the bounding box of this segment, it's only a crossing\n                // if it's below the box.\n\n                continue;\n            } else if(y < Math.min(y0, y1)) {\n                // don't count the left-most point of the segment as a crossing\n                // because we don't want to double-count adjacent crossings\n                // UNLESS the polygon turns past vertical at exactly this x\n                // Note that this is repeated below, but we can't factor it out\n                // because\n                if(x !== xmini) crossings++;\n            } else {\n                // inside the bounding box, check the actual line intercept\n\n                // vertical segment - we know already that the point is exactly\n                // on the segment, so mark the crossing as exactly at the point.\n                if(x1 === x0) ycross = y;\n                // any other angle\n                else ycross = y0 + (x - x0) * (y1 - y0) / (x1 - x0);\n\n                // exactly on the edge: counts as inside the polygon, unless it's the\n                // first edge and we're omitting it.\n                if(y === ycross) {\n                    if(i === 1 && omitFirstEdge) return false;\n                    return true;\n                }\n\n                if(y <= ycross && x !== xmini) crossings++;\n            }\n        }\n\n        // if we've gotten this far, odd crossings means inside, even is outside\n        return crossings % 2 === 1;\n    }\n\n    // detect if poly is degenerate\n    var degenerate = true;\n    var lastPt = pts[0];\n    for(i = 1; i < pts.length; i++) {\n        if(lastPt[0] !== pts[i][0] || lastPt[1] !== pts[i][1]) {\n            degenerate = false;\n            break;\n        }\n    }\n\n    return {\n        xmin: xmin,\n        xmax: xmax,\n        ymin: ymin,\n        ymax: ymax,\n        pts: pts,\n        contains: isRect ? rectContains : contains,\n        isRect: isRect,\n        degenerate: degenerate\n    };\n};\n\n/**\n * Test if a segment of a points array is bent or straight\n *\n * @param pts Array of [x, y] pairs\n * @param start the index of the proposed start of the straight section\n * @param end the index of the proposed end point\n * @param tolerance the max distance off the line connecting start and end\n *      before the line counts as bent\n * @returns boolean: true means this segment is bent, false means straight\n */\npolygon.isSegmentBent = function isSegmentBent(pts, start, end, tolerance) {\n    var startPt = pts[start];\n    var segment = [pts[end][0] - startPt[0], pts[end][1] - startPt[1]];\n    var segmentSquared = dot(segment, segment);\n    var segmentLen = Math.sqrt(segmentSquared);\n    var unitPerp = [-segment[1] / segmentLen, segment[0] / segmentLen];\n    var i;\n    var part;\n    var partParallel;\n\n    for(i = start + 1; i < end; i++) {\n        part = [pts[i][0] - startPt[0], pts[i][1] - startPt[1]];\n        partParallel = dot(part, segment);\n\n        if(partParallel < 0 || partParallel > segmentSquared ||\n            Math.abs(dot(part, unitPerp)) > tolerance) return true;\n    }\n    return false;\n};\n\n/**\n * Make a filtering polygon, to minimize the number of segments\n *\n * @param pts Array of [x, y] pairs (must start with at least 1 pair)\n * @param tolerance the maximum deviation from straight allowed for\n *      removing points to simplify the polygon\n *\n * @returns Object {addPt, raw, filtered}\n *      addPt is a function(pt: [x, y] pair) to add a raw point and\n *          continue filtering\n *      raw is all the input points\n *      filtered is the resulting filtered Array of [x, y] pairs\n */\npolygon.filter = function filter(pts, tolerance) {\n    var ptsFiltered = [pts[0]];\n    var doneRawIndex = 0;\n    var doneFilteredIndex = 0;\n\n    function addPt(pt) {\n        pts.push(pt);\n        var prevFilterLen = ptsFiltered.length;\n        var iLast = doneRawIndex;\n        ptsFiltered.splice(doneFilteredIndex + 1);\n\n        for(var i = iLast + 1; i < pts.length; i++) {\n            if(i === pts.length - 1 || polygon.isSegmentBent(pts, iLast, i + 1, tolerance)) {\n                ptsFiltered.push(pts[i]);\n                if(ptsFiltered.length < prevFilterLen - 2) {\n                    doneRawIndex = i;\n                    doneFilteredIndex = ptsFiltered.length - 1;\n                }\n                iLast = i;\n            }\n        }\n    }\n\n    if(pts.length > 1) {\n        var lastPt = pts.pop();\n        addPt(lastPt);\n    }\n\n    return {\n        addPt: addPt,\n        raw: pts,\n        filtered: ptsFiltered\n    };\n};\n\n},{\"../constants/numerical\":695,\"./matrix\":725}],732:[function(_dereq_,module,exports){\n(function (global){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar showNoWebGlMsg = _dereq_('./show_no_webgl_msg');\n\n// Note that this module should be ONLY required into\n// files corresponding to regl trace modules\n// so that bundles with non-regl only don't include\n// regl and all its bytes.\nvar createRegl = _dereq_('regl');\n\n/**\n * Idempotent version of createRegl. Create regl instances\n * in the correct canvases with the correct attributes and\n * options\n *\n * @param {DOM node or object} gd : graph div object\n * @param {array} extensions : list of extension to pass to createRegl\n *\n * @return {boolean} true if all createRegl calls succeeded, false otherwise\n */\nmodule.exports = function prepareRegl(gd, extensions) {\n    var fullLayout = gd._fullLayout;\n    var success = true;\n\n    fullLayout._glcanvas.each(function(d) {\n        if(d.regl) return;\n        // only parcoords needs pick layer\n        if(d.pick && !fullLayout._has('parcoords')) return;\n\n        try {\n            d.regl = createRegl({\n                canvas: this,\n                attributes: {\n                    antialias: !d.pick,\n                    preserveDrawingBuffer: true\n                },\n                pixelRatio: gd._context.plotGlPixelRatio || global.devicePixelRatio,\n                extensions: extensions || []\n            });\n        } catch(e) {\n            success = false;\n        }\n\n        if(success) {\n            this.addEventListener('webglcontextlost', function(event) {\n                if(gd && gd.emit) {\n                    gd.emit('plotly_webglcontextlost', {\n                        event: event,\n                        layer: d.key\n                    });\n                }\n            }, false);\n        }\n    });\n\n    if(!success) {\n        showNoWebGlMsg({container: fullLayout._glcontainer.node()});\n    }\n    return success;\n};\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"./show_no_webgl_msg\":740,\"regl\":502}],733:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * Push array with unique items\n *\n * Ignores falsy items, except 0 so we can use it to construct arrays of indices.\n *\n * @param {array} array\n *  array to be filled\n * @param {any} item\n *  item to be or not to be inserted\n * @return {array}\n *  ref to array (now possibly containing one more item)\n *\n */\nmodule.exports = function pushUnique(array, item) {\n    if(item instanceof RegExp) {\n        var itemStr = item.toString();\n        for(var i = 0; i < array.length; i++) {\n            if(array[i] instanceof RegExp && array[i].toString() === itemStr) {\n                return array;\n            }\n        }\n        array.push(item);\n    } else if((item || item === 0) && array.indexOf(item) === -1) array.push(item);\n\n    return array;\n};\n\n},{}],734:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar dfltConfig = _dereq_('../plot_api/plot_config').dfltConfig;\n\n/**\n * Copy arg array *without* removing `undefined` values from objects.\n *\n * @param gd\n * @param args\n * @returns {Array}\n */\nfunction copyArgArray(gd, args) {\n    var copy = [];\n    var arg;\n\n    for(var i = 0; i < args.length; i++) {\n        arg = args[i];\n\n        if(arg === gd) copy[i] = arg;\n        else if(typeof arg === 'object') {\n            copy[i] = Array.isArray(arg) ?\n                Lib.extendDeep([], arg) :\n                Lib.extendDeepAll({}, arg);\n        } else copy[i] = arg;\n    }\n\n    return copy;\n}\n\n\n// -----------------------------------------------------\n// Undo/Redo queue for plots\n// -----------------------------------------------------\n\n\nvar queue = {};\n\n// TODO: disable/enable undo and redo buttons appropriately\n\n/**\n * Add an item to the undoQueue for a graphDiv\n *\n * @param gd\n * @param undoFunc Function undo this operation\n * @param undoArgs Args to supply undoFunc with\n * @param redoFunc Function to redo this operation\n * @param redoArgs Args to supply redoFunc with\n */\nqueue.add = function(gd, undoFunc, undoArgs, redoFunc, redoArgs) {\n    var queueObj,\n        queueIndex;\n\n    // make sure we have the queue and our position in it\n    gd.undoQueue = gd.undoQueue || {index: 0, queue: [], sequence: false};\n    queueIndex = gd.undoQueue.index;\n\n    // if we're already playing an undo or redo, or if this is an auto operation\n    // (like pane resize... any others?) then we don't save this to the undo queue\n    if(gd.autoplay) {\n        if(!gd.undoQueue.inSequence) gd.autoplay = false;\n        return;\n    }\n\n    // if we're not in a sequence or are just starting, we need a new queue item\n    if(!gd.undoQueue.sequence || gd.undoQueue.beginSequence) {\n        queueObj = {undo: {calls: [], args: []}, redo: {calls: [], args: []}};\n        gd.undoQueue.queue.splice(queueIndex, gd.undoQueue.queue.length - queueIndex, queueObj);\n        gd.undoQueue.index += 1;\n    } else {\n        queueObj = gd.undoQueue.queue[queueIndex - 1];\n    }\n    gd.undoQueue.beginSequence = false;\n\n    // we unshift to handle calls for undo in a forward for loop later\n    if(queueObj) {\n        queueObj.undo.calls.unshift(undoFunc);\n        queueObj.undo.args.unshift(undoArgs);\n        queueObj.redo.calls.push(redoFunc);\n        queueObj.redo.args.push(redoArgs);\n    }\n\n    if(gd.undoQueue.queue.length > dfltConfig.queueLength) {\n        gd.undoQueue.queue.shift();\n        gd.undoQueue.index--;\n    }\n};\n\n/**\n * Begin a sequence of undoQueue changes\n *\n * @param gd\n */\nqueue.startSequence = function(gd) {\n    gd.undoQueue = gd.undoQueue || {index: 0, queue: [], sequence: false};\n    gd.undoQueue.sequence = true;\n    gd.undoQueue.beginSequence = true;\n};\n\n/**\n * Stop a sequence of undoQueue changes\n *\n * Call this *after* you're sure your undo chain has ended\n *\n * @param gd\n */\nqueue.stopSequence = function(gd) {\n    gd.undoQueue = gd.undoQueue || {index: 0, queue: [], sequence: false};\n    gd.undoQueue.sequence = false;\n    gd.undoQueue.beginSequence = false;\n};\n\n/**\n * Move one step back in the undo queue, and undo the object there.\n *\n * @param gd\n */\nqueue.undo = function undo(gd) {\n    var queueObj, i;\n\n    if(gd.framework && gd.framework.isPolar) {\n        gd.framework.undo();\n        return;\n    }\n    if(gd.undoQueue === undefined ||\n            isNaN(gd.undoQueue.index) ||\n            gd.undoQueue.index <= 0) {\n        return;\n    }\n\n    // index is pointing to next *forward* queueObj, point to the one we're undoing\n    gd.undoQueue.index--;\n\n    // get the queueObj for instructions on how to undo\n    queueObj = gd.undoQueue.queue[gd.undoQueue.index];\n\n    // this sequence keeps things from adding to the queue during undo/redo\n    gd.undoQueue.inSequence = true;\n    for(i = 0; i < queueObj.undo.calls.length; i++) {\n        queue.plotDo(gd, queueObj.undo.calls[i], queueObj.undo.args[i]);\n    }\n    gd.undoQueue.inSequence = false;\n    gd.autoplay = false;\n};\n\n/**\n * Redo the current object in the undo, then move forward in the queue.\n *\n * @param gd\n */\nqueue.redo = function redo(gd) {\n    var queueObj, i;\n\n    if(gd.framework && gd.framework.isPolar) {\n        gd.framework.redo();\n        return;\n    }\n    if(gd.undoQueue === undefined ||\n            isNaN(gd.undoQueue.index) ||\n            gd.undoQueue.index >= gd.undoQueue.queue.length) {\n        return;\n    }\n\n    // get the queueObj for instructions on how to undo\n    queueObj = gd.undoQueue.queue[gd.undoQueue.index];\n\n    // this sequence keeps things from adding to the queue during undo/redo\n    gd.undoQueue.inSequence = true;\n    for(i = 0; i < queueObj.redo.calls.length; i++) {\n        queue.plotDo(gd, queueObj.redo.calls[i], queueObj.redo.args[i]);\n    }\n    gd.undoQueue.inSequence = false;\n    gd.autoplay = false;\n\n    // index is pointing to the thing we just redid, move it\n    gd.undoQueue.index++;\n};\n\n/**\n * Called by undo/redo to make the actual changes.\n *\n * Not meant to be called publically, but included for mocking out in tests.\n *\n * @param gd\n * @param func\n * @param args\n */\nqueue.plotDo = function(gd, func, args) {\n    gd.autoplay = true;\n\n    // this *won't* copy gd and it preserves `undefined` properties!\n    args = copyArgArray(gd, args);\n\n    // call the supplied function\n    func.apply(null, args);\n};\n\nmodule.exports = queue;\n\n},{\"../lib\":719,\"../plot_api/plot_config\":755}],735:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/*\n * make a regex for matching counter ids/names ie xaxis, xaxis2, xaxis10...\n *\n * @param {string} head: the head of the pattern, eg 'x' matches 'x', 'x2', 'x10' etc.\n *      'xy' is a special case for cartesian subplots: it matches 'x2y3' etc\n * @param {Optional(string)} tail: a fixed piece after the id\n *      eg counterRegex('scene', '.annotations') for scene2.annotations etc.\n * @param {boolean} openEnded: if true, the string may continue past the match.\n * @param {boolean} matchBeginning: if false, the string may start before the match.\n */\nexports.counter = function(head, tail, openEnded, matchBeginning) {\n    var fullTail = (tail || '') + (openEnded ? '' : '$');\n    var startWithPrefix = matchBeginning === false ? '' : '^';\n    if(head === 'xy') {\n        return new RegExp(startWithPrefix + 'x([2-9]|[1-9][0-9]+)?y([2-9]|[1-9][0-9]+)?' + fullTail);\n    }\n    return new RegExp(startWithPrefix + head + '([2-9]|[1-9][0-9]+)?' + fullTail);\n};\n\n},{}],736:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n// ASCEND: chop off the last nesting level - either [<n>] or .<key> - to ascend\n// the attribute tree. the remaining attrString is in match[1]\nvar ASCEND = /^(.*)(\\.[^\\.\\[\\]]+|\\[\\d\\])$/;\n\n// SIMPLEATTR: is this an un-nested attribute? (no dots or brackets)\nvar SIMPLEATTR = /^[^\\.\\[\\]]+$/;\n\n/*\n * calculate a relative attribute string, similar to a relative path\n *\n * @param {string} baseAttr:\n *   an attribute string, such as 'annotations[3].x'. The \"current location\"\n *   is the attribute string minus the last component ('annotations[3]')\n * @param {string} relativeAttr:\n *   a route to the desired attribute string, using '^' to ascend\n *\n * @return {string} attrString:\n *   for example:\n *     relativeAttr('annotations[3].x', 'y') = 'annotations[3].y'\n *     relativeAttr('annotations[3].x', '^[2].z') = 'annotations[2].z'\n *     relativeAttr('annotations[3].x', '^^margin') = 'margin'\n *     relativeAttr('annotations[3].x', '^^margin.r') = 'margin.r'\n */\nmodule.exports = function(baseAttr, relativeAttr) {\n    while(relativeAttr) {\n        var match = baseAttr.match(ASCEND);\n\n        if(match) baseAttr = match[1];\n        else if(baseAttr.match(SIMPLEATTR)) baseAttr = '';\n        else throw new Error('bad relativeAttr call:' + [baseAttr, relativeAttr]);\n\n        if(relativeAttr.charAt(0) === '^') relativeAttr = relativeAttr.slice(1);\n        else break;\n    }\n\n    if(baseAttr && relativeAttr.charAt(0) !== '[') {\n        return baseAttr + '.' + relativeAttr;\n    }\n    return baseAttr + relativeAttr;\n};\n\n},{}],737:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isArrayOrTypedArray = _dereq_('./array').isArrayOrTypedArray;\nvar isPlainObject = _dereq_('./is_plain_object');\n\n/**\n * Relink private _keys and keys with a function value from one container\n * to the new container.\n * Relink means copying if object is pass-by-value and adding a reference\n * if object is pass-by-ref.\n * This prevents deepCopying massive structures like a webgl context.\n */\nmodule.exports = function relinkPrivateKeys(toContainer, fromContainer) {\n    for(var k in fromContainer) {\n        var fromVal = fromContainer[k];\n        var toVal = toContainer[k];\n\n        if(toVal === fromVal) {\n            continue;\n        }\n        if(k.charAt(0) === '_' || typeof fromVal === 'function') {\n            // if it already exists at this point, it's something\n            // that we recreate each time around, so ignore it\n            if(k in toContainer) continue;\n\n            toContainer[k] = fromVal;\n        } else if(isArrayOrTypedArray(fromVal) && isArrayOrTypedArray(toVal) && isPlainObject(fromVal[0])) {\n            // filter out data_array items that can contain user objects\n            // most of the time the toVal === fromVal check will catch these early\n            // but if the user makes new ones we also don't want to recurse in.\n            if(k === 'customdata' || k === 'ids') continue;\n\n            // recurse into arrays containers\n            var minLen = Math.min(fromVal.length, toVal.length);\n            for(var j = 0; j < minLen; j++) {\n                if((toVal[j] !== fromVal[j]) && isPlainObject(fromVal[j]) && isPlainObject(toVal[j])) {\n                    relinkPrivateKeys(toVal[j], fromVal[j]);\n                }\n            }\n        } else if(isPlainObject(fromVal) && isPlainObject(toVal)) {\n            // recurse into objects, but only if they still exist\n            relinkPrivateKeys(toVal, fromVal);\n\n            if(!Object.keys(toVal).length) delete toContainer[k];\n        }\n    }\n};\n\n},{\"./array\":702,\"./is_plain_object\":720}],738:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar loggers = _dereq_('./loggers');\nvar identity = _dereq_('./identity');\n\n// don't trust floating point equality - fraction of bin size to call\n// \"on the line\" and ensure that they go the right way specified by\n// linelow\nvar roundingError = 1e-9;\n\n\n/**\n * findBin - find the bin for val - note that it can return outside the\n * bin range any pos. or neg. integer for linear bins, or -1 or\n * bins.length-1 for explicit.\n * bins is either an object {start,size,end} or an array length #bins+1\n * bins can be either increasing or decreasing but must be monotonic\n * for linear bins, we can just calculate. For listed bins, run a binary\n * search linelow (truthy) says the bin boundary should be attributed to\n * the lower bin rather than the default upper bin\n */\nexports.findBin = function(val, bins, linelow) {\n    if(isNumeric(bins.start)) {\n        return linelow ?\n            Math.ceil((val - bins.start) / bins.size - roundingError) - 1 :\n            Math.floor((val - bins.start) / bins.size + roundingError);\n    } else {\n        var n1 = 0;\n        var n2 = bins.length;\n        var c = 0;\n        var binSize = (n2 > 1) ? (bins[n2 - 1] - bins[0]) / (n2 - 1) : 1;\n        var n, test;\n        if(binSize >= 0) {\n            test = linelow ? lessThan : lessOrEqual;\n        } else {\n            test = linelow ? greaterOrEqual : greaterThan;\n        }\n        val += binSize * roundingError * (linelow ? -1 : 1) * (binSize >= 0 ? 1 : -1);\n        // c is just to avoid infinite loops if there's an error\n        while(n1 < n2 && c++ < 100) {\n            n = Math.floor((n1 + n2) / 2);\n            if(test(bins[n], val)) n1 = n + 1;\n            else n2 = n;\n        }\n        if(c > 90) loggers.log('Long binary search...');\n        return n1 - 1;\n    }\n};\n\nfunction lessThan(a, b) { return a < b; }\nfunction lessOrEqual(a, b) { return a <= b; }\nfunction greaterThan(a, b) { return a > b; }\nfunction greaterOrEqual(a, b) { return a >= b; }\n\nexports.sorterAsc = function(a, b) { return a - b; };\nexports.sorterDes = function(a, b) { return b - a; };\n\n/**\n * find distinct values in an array, lumping together ones that appear to\n * just be off by a rounding error\n * return the distinct values and the minimum difference between any two\n */\nexports.distinctVals = function(valsIn) {\n    var vals = valsIn.slice();  // otherwise we sort the original array...\n    vals.sort(exports.sorterAsc);\n\n    var l = vals.length - 1;\n    var minDiff = (vals[l] - vals[0]) || 1;\n    var errDiff = minDiff / (l || 1) / 10000;\n    var v2 = [vals[0]];\n\n    for(var i = 0; i < l; i++) {\n        // make sure values aren't just off by a rounding error\n        if(vals[i + 1] > vals[i] + errDiff) {\n            minDiff = Math.min(minDiff, vals[i + 1] - vals[i]);\n            v2.push(vals[i + 1]);\n        }\n    }\n\n    return {vals: v2, minDiff: minDiff};\n};\n\n/**\n * return the smallest element from (sorted) array arrayIn that's bigger than val,\n * or (reverse) the largest element smaller than val\n * used to find the best tick given the minimum (non-rounded) tick\n * particularly useful for date/time where things are not powers of 10\n * binary search is probably overkill here...\n */\nexports.roundUp = function(val, arrayIn, reverse) {\n    var low = 0;\n    var high = arrayIn.length - 1;\n    var mid;\n    var c = 0;\n    var dlow = reverse ? 0 : 1;\n    var dhigh = reverse ? 1 : 0;\n    var rounded = reverse ? Math.ceil : Math.floor;\n    // c is just to avoid infinite loops if there's an error\n    while(low < high && c++ < 100) {\n        mid = rounded((low + high) / 2);\n        if(arrayIn[mid] <= val) low = mid + dlow;\n        else high = mid - dhigh;\n    }\n    return arrayIn[low];\n};\n\n/**\n * Tweak to Array.sort(sortFn) that improves performance for pre-sorted arrays\n *\n * Note that newer browsers (such as Chrome v70+) are starting to pick up\n * on pre-sorted arrays which may render the following optimization unnecessary\n * in the future.\n *\n * Motivation: sometimes we need to sort arrays but the input is likely to\n * already be sorted. Browsers don't seem to pick up on pre-sorted arrays,\n * and in fact Chrome is actually *slower* sorting pre-sorted arrays than purely\n * random arrays. FF is at least faster if the array is pre-sorted, but still\n * not as fast as it could be.\n * Here's how this plays out sorting a length-1e6 array:\n *\n * Calls to Sort FN  |  Chrome bare  |  FF bare  |  Chrome tweak  |  FF tweak\n *                   |  v68.0 Mac    |  v61.0 Mac|                |\n * ------------------+---------------+-----------+----------------+------------\n * ordered           |  30.4e6       |  10.1e6   |  1e6           |  1e6\n * reversed          |  29.4e6       |  9.9e6    |  1e6 + reverse |  1e6 + reverse\n * random            |  ~21e6        |  ~18.7e6  |  ~21e6         |  ~18.7e6\n *\n * So this is a substantial win for pre-sorted (ordered or exactly reversed)\n * arrays. Including this wrapper on an unsorted array adds a penalty that will\n * in general be only a few calls to the sort function. The only case this\n * penalty will be significant is if the array is mostly sorted but there are\n * a few unsorted items near the end, but the penalty is still at most N calls\n * out of (for N=1e6) ~20N total calls\n *\n * @param {Array} array: the array, to be sorted in place\n * @param {function} sortFn: As in Array.sort, function(a, b) that puts\n *     item a before item b if the return is negative, a after b if positive,\n *     and no change if zero.\n * @return {Array}: the original array, sorted in place.\n */\nexports.sort = function(array, sortFn) {\n    var notOrdered = 0;\n    var notReversed = 0;\n    for(var i = 1; i < array.length; i++) {\n        var pairOrder = sortFn(array[i], array[i - 1]);\n        if(pairOrder < 0) notOrdered = 1;\n        else if(pairOrder > 0) notReversed = 1;\n        if(notOrdered && notReversed) return array.sort(sortFn);\n    }\n    return notReversed ? array : array.reverse();\n};\n\n/**\n * find index in array 'arr' that minimizes 'fn'\n *\n * @param {array} arr : array where to search\n * @param {fn (optional)} fn : function to minimize,\n *   if not given, fn is the identity function\n * @return {integer}\n */\nexports.findIndexOfMin = function(arr, fn) {\n    fn = fn || identity;\n\n    var min = Infinity;\n    var ind;\n\n    for(var i = 0; i < arr.length; i++) {\n        var v = fn(arr[i]);\n        if(v < min) {\n            min = v;\n            ind = i;\n        }\n    }\n    return ind;\n};\n\n},{\"./identity\":718,\"./loggers\":723,\"fast-isnumeric\":225}],739:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n// works with our CSS cursor classes (see css/_cursor.scss)\n// to apply cursors to d3 single-element selections.\n// omit cursor to revert to the default.\nmodule.exports = function setCursor(el3, csr) {\n    (el3.attr('class') || '').split(' ').forEach(function(cls) {\n        if(cls.indexOf('cursor-') === 0) el3.classed(cls, false);\n    });\n\n    if(csr) el3.classed('cursor-' + csr, true);\n};\n\n},{}],740:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Color = _dereq_('../components/color');\n\nvar noop = function() {};\n\n\n/**\n * Prints a no webgl error message into the scene container\n * @param {scene instance} scene\n *\n * Expects 'scene' to have property 'container'\n *\n */\nmodule.exports = function showNoWebGlMsg(scene) {\n    for(var prop in scene) {\n        if(typeof scene[prop] === 'function') scene[prop] = noop;\n    }\n\n    scene.destroy = function() {\n        scene.container.parentNode.removeChild(scene.container);\n    };\n\n    var div = document.createElement('div');\n    div.className = 'no-webgl';\n    div.style.cursor = 'pointer';\n    div.style.fontSize = '24px';\n    div.style.color = Color.defaults[0];\n    div.style.position = 'absolute';\n    div.style.left = div.style.top = '0px';\n    div.style.width = div.style.height = '100%';\n    div.style['background-color'] = Color.lightLine;\n    div.style['z-index'] = 30;\n\n    var p = document.createElement('p');\n    p.textContent = 'WebGL is not supported by your browser - visit https://get.webgl.org for more info';\n    p.style.position = 'relative';\n    p.style.top = '50%';\n    p.style.left = '50%';\n    p.style.height = '30%';\n    p.style.width = '50%';\n    p.style.margin = '-15% 0 0 -25%';\n\n    div.appendChild(p);\n    scene.container.appendChild(div);\n    scene.container.style.background = '#FFFFFF';\n    scene.container.onclick = function() {\n        window.open('https://get.webgl.org');\n    };\n\n    // return before setting up camera and onrender methods\n    return false;\n};\n\n},{\"../components/color\":593}],741:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar isArrayOrTypedArray = _dereq_('./array').isArrayOrTypedArray;\n\n/**\n * aggNums() returns the result of an aggregate function applied to an array of\n * values, where non-numerical values have been tossed out.\n *\n * @param {function} f - aggregation function (e.g., Math.min)\n * @param {Number} v - initial value (continuing from previous calls)\n *      if there's no continuing value, use null for selector-type\n *      functions (max,min), or 0 for summations\n * @param {Array} a - array to aggregate (may be nested, we will recurse,\n *                    but all elements must have the same dimension)\n * @param {Number} len - maximum length of a to aggregate\n * @return {Number} - result of f applied to a starting from v\n */\nexports.aggNums = function(f, v, a, len) {\n    var i,\n        b;\n    if(!len || len > a.length) len = a.length;\n    if(!isNumeric(v)) v = false;\n    if(isArrayOrTypedArray(a[0])) {\n        b = new Array(len);\n        for(i = 0; i < len; i++) b[i] = exports.aggNums(f, v, a[i]);\n        a = b;\n    }\n\n    for(i = 0; i < len; i++) {\n        if(!isNumeric(v)) v = a[i];\n        else if(isNumeric(a[i])) v = f(+v, +a[i]);\n    }\n    return v;\n};\n\n/**\n * mean & std dev functions using aggNums, so it handles non-numerics nicely\n * even need to use aggNums instead of .length, to toss out non-numerics\n */\nexports.len = function(data) {\n    return exports.aggNums(function(a) { return a + 1; }, 0, data);\n};\n\nexports.mean = function(data, len) {\n    if(!len) len = exports.len(data);\n    return exports.aggNums(function(a, b) { return a + b; }, 0, data) / len;\n};\n\nexports.midRange = function(numArr) {\n    if(numArr === undefined || numArr.length === 0) return undefined;\n    return (exports.aggNums(Math.max, null, numArr) + exports.aggNums(Math.min, null, numArr)) / 2;\n};\n\nexports.variance = function(data, len, mean) {\n    if(!len) len = exports.len(data);\n    if(!isNumeric(mean)) mean = exports.mean(data, len);\n\n    return exports.aggNums(function(a, b) {\n        return a + Math.pow(b - mean, 2);\n    }, 0, data) / len;\n};\n\nexports.stdev = function(data, len, mean) {\n    return Math.sqrt(exports.variance(data, len, mean));\n};\n\n/**\n * median of a finite set of numbers\n * reference page: https://en.wikipedia.org/wiki/Median#Finite_set_of_numbers\n**/\nexports.median = function(data) {\n    var b = data.slice().sort();\n    return exports.interp(b, 0.5);\n};\n\n/**\n * interp() computes a percentile (quantile) for a given distribution.\n * We interpolate the distribution (to compute quantiles, we follow method #10 here:\n * http://www.amstat.org/publications/jse/v14n3/langford.html).\n * Typically the index or rank (n * arr.length) may be non-integer.\n * For reference: ends are clipped to the extreme values in the array;\n * For box plots: index you get is half a point too high (see\n * http://en.wikipedia.org/wiki/Percentile#Nearest_rank) but note that this definition\n * indexes from 1 rather than 0, so we subtract 1/2 (instead of add).\n *\n * @param {Array} arr - This array contains the values that make up the distribution.\n * @param {Number} n - Between 0 and 1, n = p/100 is such that we compute the p^th percentile.\n * For example, the 50th percentile (or median) corresponds to n = 0.5\n * @return {Number} - percentile\n */\nexports.interp = function(arr, n) {\n    if(!isNumeric(n)) throw 'n should be a finite number';\n    n = n * arr.length - 0.5;\n    if(n < 0) return arr[0];\n    if(n > arr.length - 1) return arr[arr.length - 1];\n    var frac = n % 1;\n    return frac * arr[Math.ceil(n)] + (1 - frac) * arr[Math.floor(n)];\n};\n\n},{\"./array\":702,\"fast-isnumeric\":225}],742:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar rgba = _dereq_('color-normalize');\n\nfunction str2RgbaArray(color) {\n    if(!color) return [0, 0, 0, 1];\n    return rgba(color);\n}\n\nmodule.exports = str2RgbaArray;\n\n},{\"color-normalize\":120}],743:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n/* global MathJax:false */\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../lib');\nvar xmlnsNamespaces = _dereq_('../constants/xmlns_namespaces');\nvar LINE_SPACING = _dereq_('../constants/alignment').LINE_SPACING;\n\n// text converter\n\nfunction getSize(_selection, _dimension) {\n    return _selection.node().getBoundingClientRect()[_dimension];\n}\n\nvar FIND_TEX = /([^$]*)([$]+[^$]*[$]+)([^$]*)/;\n\nexports.convertToTspans = function(_context, gd, _callback) {\n    var str = _context.text();\n\n    // Until we get tex integrated more fully (so it can be used along with non-tex)\n    // allow some elements to prohibit it by attaching 'data-notex' to the original\n    var tex = (!_context.attr('data-notex')) &&\n        (typeof MathJax !== 'undefined') &&\n        str.match(FIND_TEX);\n\n    var parent = d3.select(_context.node().parentNode);\n    if(parent.empty()) return;\n    var svgClass = (_context.attr('class')) ? _context.attr('class').split(' ')[0] : 'text';\n    svgClass += '-math';\n    parent.selectAll('svg.' + svgClass).remove();\n    parent.selectAll('g.' + svgClass + '-group').remove();\n    _context.style('display', null)\n        .attr({\n            // some callers use data-unformatted *from the <text> element* in 'cancel'\n            // so we need it here even if we're going to turn it into math\n            // these two (plus style and text-anchor attributes) form the key we're\n            // going to use for Drawing.bBox\n            'data-unformatted': str,\n            'data-math': 'N'\n        });\n\n    function showText() {\n        if(!parent.empty()) {\n            svgClass = _context.attr('class') + '-math';\n            parent.select('svg.' + svgClass).remove();\n        }\n        _context.text('')\n            .style('white-space', 'pre');\n\n        var hasLink = buildSVGText(_context.node(), str);\n\n        if(hasLink) {\n            // at least in Chrome, pointer-events does not seem\n            // to be honored in children of <text> elements\n            // so if we have an anchor, we have to make the\n            // whole element respond\n            _context.style('pointer-events', 'all');\n        }\n\n        exports.positionText(_context);\n\n        if(_callback) _callback.call(_context);\n    }\n\n    if(tex) {\n        ((gd && gd._promises) || []).push(new Promise(function(resolve) {\n            _context.style('display', 'none');\n            var fontSize = parseInt(_context.node().style.fontSize, 10);\n            var config = {fontSize: fontSize};\n\n            texToSVG(tex[2], config, function(_svgEl, _glyphDefs, _svgBBox) {\n                parent.selectAll('svg.' + svgClass).remove();\n                parent.selectAll('g.' + svgClass + '-group').remove();\n\n                var newSvg = _svgEl && _svgEl.select('svg');\n                if(!newSvg || !newSvg.node()) {\n                    showText();\n                    resolve();\n                    return;\n                }\n\n                var mathjaxGroup = parent.append('g')\n                    .classed(svgClass + '-group', true)\n                    .attr({\n                        'pointer-events': 'none',\n                        'data-unformatted': str,\n                        'data-math': 'Y'\n                    });\n\n                mathjaxGroup.node().appendChild(newSvg.node());\n\n                // stitch the glyph defs\n                if(_glyphDefs && _glyphDefs.node()) {\n                    newSvg.node().insertBefore(_glyphDefs.node().cloneNode(true),\n                                               newSvg.node().firstChild);\n                }\n\n                newSvg.attr({\n                    'class': svgClass,\n                    height: _svgBBox.height,\n                    preserveAspectRatio: 'xMinYMin meet'\n                })\n                .style({overflow: 'visible', 'pointer-events': 'none'});\n\n                var fill = _context.node().style.fill || 'black';\n                var g = newSvg.select('g');\n                g.attr({fill: fill, stroke: fill});\n\n                var newSvgW = getSize(g, 'width');\n                var newSvgH = getSize(g, 'height');\n                var newX = +_context.attr('x') - newSvgW *\n                    {start: 0, middle: 0.5, end: 1}[_context.attr('text-anchor') || 'start'];\n                // font baseline is about 1/4 fontSize below centerline\n                var textHeight = fontSize || getSize(_context, 'height');\n                var dy = -textHeight / 4;\n\n                if(svgClass[0] === 'y') {\n                    mathjaxGroup.attr({\n                        transform: 'rotate(' + [-90, +_context.attr('x'), +_context.attr('y')] +\n                        ') translate(' + [-newSvgW / 2, dy - newSvgH / 2] + ')'\n                    });\n                    newSvg.attr({x: +_context.attr('x'), y: +_context.attr('y')});\n                } else if(svgClass[0] === 'l') {\n                    newSvg.attr({x: _context.attr('x'), y: dy - (newSvgH / 2)});\n                } else if(svgClass[0] === 'a' && svgClass.indexOf('atitle') !== 0) {\n                    newSvg.attr({x: 0, y: dy});\n                } else {\n                    newSvg.attr({x: newX, y: (+_context.attr('y') + dy - newSvgH / 2)});\n                }\n\n                if(_callback) _callback.call(_context, mathjaxGroup);\n                resolve(mathjaxGroup);\n            });\n        }));\n    } else showText();\n\n    return _context;\n};\n\n\n// MathJax\n\nvar LT_MATCH = /(<|&lt;|&#60;)/g;\nvar GT_MATCH = /(>|&gt;|&#62;)/g;\n\nfunction cleanEscapesForTex(s) {\n    return s.replace(LT_MATCH, '\\\\lt ')\n        .replace(GT_MATCH, '\\\\gt ');\n}\n\nfunction texToSVG(_texString, _config, _callback) {\n    var originalRenderer,\n        originalConfig,\n        originalProcessSectionDelay,\n        tmpDiv;\n\n    MathJax.Hub.Queue(\n    function() {\n        originalConfig = Lib.extendDeepAll({}, MathJax.Hub.config);\n\n        originalProcessSectionDelay = MathJax.Hub.processSectionDelay;\n        if(MathJax.Hub.processSectionDelay !== undefined) {\n            // MathJax 2.5+\n            MathJax.Hub.processSectionDelay = 0;\n        }\n\n        return MathJax.Hub.Config({\n            messageStyle: 'none',\n            tex2jax: {\n                inlineMath: [['$', '$'], ['\\\\(', '\\\\)']]\n            },\n            displayAlign: 'left',\n        });\n    },\n    function() {\n        // Get original renderer\n        originalRenderer = MathJax.Hub.config.menuSettings.renderer;\n        if(originalRenderer !== 'SVG') {\n            return MathJax.Hub.setRenderer('SVG');\n        }\n    },\n    function() {\n        var randomID = 'math-output-' + Lib.randstr({}, 64);\n        tmpDiv = d3.select('body').append('div')\n            .attr({id: randomID})\n            .style({visibility: 'hidden', position: 'absolute'})\n            .style({'font-size': _config.fontSize + 'px'})\n            .text(cleanEscapesForTex(_texString));\n\n        return MathJax.Hub.Typeset(tmpDiv.node());\n    },\n    function() {\n        var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');\n\n        if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) {\n            Lib.log('There was an error in the tex syntax.', _texString);\n            _callback();\n        } else {\n            var svgBBox = tmpDiv.select('svg').node().getBoundingClientRect();\n            _callback(tmpDiv.select('.MathJax_SVG'), glyphDefs, svgBBox);\n        }\n\n        tmpDiv.remove();\n\n        if(originalRenderer !== 'SVG') {\n            return MathJax.Hub.setRenderer(originalRenderer);\n        }\n    },\n    function() {\n        if(originalProcessSectionDelay !== undefined) {\n            MathJax.Hub.processSectionDelay = originalProcessSectionDelay;\n        }\n        return MathJax.Hub.Config(originalConfig);\n    });\n}\n\nvar TAG_STYLES = {\n    // would like to use baseline-shift for sub/sup but FF doesn't support it\n    // so we need to use dy along with the uber hacky shift-back-to\n    // baseline below\n    sup: 'font-size:70%',\n    sub: 'font-size:70%',\n    b: 'font-weight:bold',\n    i: 'font-style:italic',\n    a: 'cursor:pointer',\n    span: '',\n    em: 'font-style:italic;font-weight:bold'\n};\n\n// baseline shifts for sub and sup\nvar SHIFT_DY = {\n    sub: '0.3em',\n    sup: '-0.6em'\n};\n// reset baseline by adding a tspan (empty except for a zero-width space)\n// with dy of -70% * SHIFT_DY (because font-size=70%)\nvar RESET_DY = {\n    sub: '-0.21em',\n    sup: '0.42em'\n};\nvar ZERO_WIDTH_SPACE = '\\u200b';\n\n/*\n * Whitelist of protocols in user-supplied urls. Mostly we want to avoid javascript\n * and related attack vectors. The empty items are there for IE, that in various\n * versions treats relative paths as having different flavors of no protocol, while\n * other browsers have these explicitly inherit the protocol of the page they're in.\n */\nvar PROTOCOLS = ['http:', 'https:', 'mailto:', '', undefined, ':'];\n\nvar NEWLINES = /(\\r\\n?|\\n)/g;\n\nvar SPLIT_TAGS = /(<[^<>]*>)/;\n\nvar ONE_TAG = /<(\\/?)([^ >]*)(\\s+(.*))?>/i;\n\nvar BR_TAG = /<br(\\s+.*)?>/i;\n\n/*\n * style and href: pull them out of either single or double quotes. Also\n * - target: (_blank|_self|_parent|_top|framename)\n *     note that you can't use target to get a popup but if you use popup,\n *     a `framename` will be passed along as the name of the popup window.\n *     per the spec, cannot contain whitespace.\n *     for backward compatibility we default to '_blank'\n * - popup: a custom one for us to enable popup (new window) links. String\n *     for window.open -> strWindowFeatures, like 'menubar=yes,width=500,height=550'\n *     note that at least in Chrome, you need to give at least one property\n *     in this string or the page will open in a new tab anyway. We follow this\n *     convention and will not make a popup if this string is empty.\n *     per the spec, cannot contain whitespace.\n *\n * Because we hack in other attributes with style (sub & sup), drop any trailing\n * semicolon in user-supplied styles so we can consistently append the tag-dependent style\n *\n * These are for tag attributes; Chrome anyway will convert entities in\n * attribute values, but not in attribute names\n * you can test this by for example:\n * > p = document.createElement('p')\n * > p.innerHTML = '<span styl&#x65;=\"font-color:r&#x65;d;\">Hi</span>'\n * > p.innerHTML\n * <- '<span styl&#x65;=\"font-color:red;\">Hi</span>'\n */\nvar STYLEMATCH = /(^|[\\s\"'])style\\s*=\\s*(\"([^\"]*);?\"|'([^']*);?')/i;\nvar HREFMATCH = /(^|[\\s\"'])href\\s*=\\s*(\"([^\"]*)\"|'([^']*)')/i;\nvar TARGETMATCH = /(^|[\\s\"'])target\\s*=\\s*(\"([^\"\\s]*)\"|'([^'\\s]*)')/i;\nvar POPUPMATCH = /(^|[\\s\"'])popup\\s*=\\s*(\"([\\w=,]*)\"|'([\\w=,]*)')/i;\n\n// dedicated matcher for these quoted regexes, that can return their results\n// in two different places\nfunction getQuotedMatch(_str, re) {\n    if(!_str) return null;\n    var match = _str.match(re);\n    var result = match && (match[3] || match[4]);\n    return result && convertEntities(result);\n}\n\nvar COLORMATCH = /(^|;)\\s*color:/;\n\n/**\n * Strip string of tags\n *\n * @param {string} _str : input string\n * @param {object} opts :\n * - len {number} max length of output string\n * - allowedTags {array} list of pseudo-html tags to NOT strip\n * @return {string}\n */\nexports.plainText = function(_str, opts) {\n    opts = opts || {};\n\n    var len = (opts.len !== undefined && opts.len !== -1) ? opts.len : Infinity;\n    var allowedTags = opts.allowedTags !== undefined ? opts.allowedTags : ['br'];\n\n    var ellipsis = '...';\n    var eLen = ellipsis.length;\n\n    var oldParts = _str.split(SPLIT_TAGS);\n    var newParts = [];\n    var prevTag = '';\n    var l = 0;\n\n    for(var i = 0; i < oldParts.length; i++) {\n        var p = oldParts[i];\n        var match = p.match(ONE_TAG);\n        var tagType = match && match[2].toLowerCase();\n\n        if(tagType) {\n            // N.B. tags do not count towards string length\n            if(allowedTags.indexOf(tagType) !== -1) {\n                newParts.push(p);\n                prevTag = tagType;\n            }\n        } else {\n            var pLen = p.length;\n\n            if((l + pLen) < len) {\n                newParts.push(p);\n                l += pLen;\n            } else if(l < len) {\n                var pLen2 = len - l;\n\n                if(prevTag && (prevTag !== 'br' || pLen2 <= eLen || pLen <= eLen)) {\n                    newParts.pop();\n                }\n\n                if(len > eLen) {\n                    newParts.push(p.substr(0, pLen2 - eLen) + ellipsis);\n                } else {\n                    newParts.push(p.substr(0, pLen2));\n                }\n                break;\n            }\n\n            prevTag = '';\n        }\n    }\n\n    return newParts.join('');\n};\n\n/*\n * N.B. HTML entities are listed without the leading '&' and trailing ';'\n * https://www.freeformatter.com/html-entities.html\n *\n * FWIW if we wanted to support the full set, it has 2261 entries:\n * https://www.w3.org/TR/html5/entities.json\n * though I notice that some of these are duplicates and/or are missing \";\"\n * eg: \"&amp;\", \"&amp\", \"&AMP;\", and \"&AMP\" all map to \"&\"\n * We no longer need to include numeric entities here, these are now handled\n * by String.fromCodePoint/fromCharCode\n *\n * Anyway the only ones that are really important to allow are the HTML special\n * chars <, >, and &, because these ones can trigger special processing if not\n * replaced by the corresponding entity.\n */\nvar entityToUnicode = {\n    mu: 'μ',\n    amp: '&',\n    lt: '<',\n    gt: '>',\n    nbsp: ' ',\n    times: '×',\n    plusmn: '±',\n    deg: '°'\n};\n\n// NOTE: in general entities can contain uppercase too (so [a-zA-Z]) but all the\n// ones we support use only lowercase. If we ever change that, update the regex.\nvar ENTITY_MATCH = /&(#\\d+|#x[\\da-fA-F]+|[a-z]+);/g;\nfunction convertEntities(_str) {\n    return _str.replace(ENTITY_MATCH, function(fullMatch, innerMatch) {\n        var outChar;\n        if(innerMatch.charAt(0) === '#') {\n            // cannot use String.fromCodePoint in IE\n            outChar = fromCodePoint(\n                innerMatch.charAt(1) === 'x' ?\n                    parseInt(innerMatch.substr(2), 16) :\n                    parseInt(innerMatch.substr(1), 10)\n            );\n        } else outChar = entityToUnicode[innerMatch];\n\n        // as in regular HTML, if we didn't decode the entity just\n        // leave the raw text in place.\n        return outChar || fullMatch;\n    });\n}\nexports.convertEntities = convertEntities;\n\nfunction fromCodePoint(code) {\n    // Don't allow overflow. In Chrome this turns into � but I feel like it's\n    // more useful to just not convert it at all.\n    if(code > 0x10FFFF) return;\n    var stringFromCodePoint = String.fromCodePoint;\n    if(stringFromCodePoint) return stringFromCodePoint(code);\n\n    // IE doesn't have String.fromCodePoint\n    // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint\n    var stringFromCharCode = String.fromCharCode;\n    if(code <= 0xFFFF) return stringFromCharCode(code);\n    return stringFromCharCode(\n        (code >> 10) + 0xD7C0,\n        (code % 0x400) + 0xDC00\n    );\n}\n\n/*\n * buildSVGText: convert our pseudo-html into SVG tspan elements, and attach these\n * to containerNode\n *\n * @param {svg text element} containerNode: the <text> node to insert this text into\n * @param {string} str: the pseudo-html string to convert to svg\n *\n * @returns {bool}: does the result contain any links? We need to handle the text element\n *   somewhat differently if it does, so just keep track of this when it happens.\n */\nfunction buildSVGText(containerNode, str) {\n    /*\n     * Normalize behavior between IE and others wrt newlines and whitespace:pre\n     * this combination makes IE barf https://github.com/plotly/plotly.js/issues/746\n     * Chrome and FF display \\n, \\r, or \\r\\n as a space in this mode.\n     * I feel like at some point we turned these into <br> but currently we don't so\n     * I'm just going to cement what we do now in Chrome and FF\n     */\n    str = str.replace(NEWLINES, ' ');\n\n    var hasLink = false;\n\n    // as we're building the text, keep track of what elements we're nested inside\n    // nodeStack will be an array of {node, type, style, href, target, popup}\n    // where only type: 'a' gets the last 3 and node is only added when it's created\n    var nodeStack = [];\n    var currentNode;\n    var currentLine = -1;\n\n    function newLine() {\n        currentLine++;\n\n        var lineNode = document.createElementNS(xmlnsNamespaces.svg, 'tspan');\n        d3.select(lineNode).attr({\n            class: 'line',\n            dy: (currentLine * LINE_SPACING) + 'em'\n        });\n        containerNode.appendChild(lineNode);\n\n        currentNode = lineNode;\n\n        var oldNodeStack = nodeStack;\n        nodeStack = [{node: lineNode}];\n\n        if(oldNodeStack.length > 1) {\n            for(var i = 1; i < oldNodeStack.length; i++) {\n                enterNode(oldNodeStack[i]);\n            }\n        }\n    }\n\n    function enterNode(nodeSpec) {\n        var type = nodeSpec.type;\n        var nodeAttrs = {};\n        var nodeType;\n\n        if(type === 'a') {\n            nodeType = 'a';\n            var target = nodeSpec.target;\n            var href = nodeSpec.href;\n            var popup = nodeSpec.popup;\n            if(href) {\n                nodeAttrs = {\n                    'xlink:xlink:show': (target === '_blank' || target.charAt(0) !== '_') ? 'new' : 'replace',\n                    target: target,\n                    'xlink:xlink:href': href\n                };\n                if(popup) {\n                    // security: href and target are not inserted as code but\n                    // as attributes. popup is, but limited to /[A-Za-z0-9_=,]/\n                    nodeAttrs.onclick = 'window.open(this.href.baseVal,this.target.baseVal,\"' +\n                        popup + '\");return false;';\n                }\n            }\n        } else nodeType = 'tspan';\n\n        if(nodeSpec.style) nodeAttrs.style = nodeSpec.style;\n\n        var newNode = document.createElementNS(xmlnsNamespaces.svg, nodeType);\n\n        if(type === 'sup' || type === 'sub') {\n            addTextNode(currentNode, ZERO_WIDTH_SPACE);\n            currentNode.appendChild(newNode);\n\n            var resetter = document.createElementNS(xmlnsNamespaces.svg, 'tspan');\n            addTextNode(resetter, ZERO_WIDTH_SPACE);\n            d3.select(resetter).attr('dy', RESET_DY[type]);\n            nodeAttrs.dy = SHIFT_DY[type];\n\n            currentNode.appendChild(newNode);\n            currentNode.appendChild(resetter);\n        } else {\n            currentNode.appendChild(newNode);\n        }\n\n        d3.select(newNode).attr(nodeAttrs);\n\n        currentNode = nodeSpec.node = newNode;\n        nodeStack.push(nodeSpec);\n    }\n\n    function addTextNode(node, text) {\n        node.appendChild(document.createTextNode(text));\n    }\n\n    function exitNode(type) {\n        // A bare closing tag can't close the root node. If we encounter this it\n        // means there's an extra closing tag that can just be ignored:\n        if(nodeStack.length === 1) {\n            Lib.log('Ignoring unexpected end tag </' + type + '>.', str);\n            return;\n        }\n\n        var innerNode = nodeStack.pop();\n\n        if(type !== innerNode.type) {\n            Lib.log('Start tag <' + innerNode.type + '> doesnt match end tag <' +\n                type + '>. Pretending it did match.', str);\n        }\n        currentNode = nodeStack[nodeStack.length - 1].node;\n    }\n\n    var hasLines = BR_TAG.test(str);\n\n    if(hasLines) newLine();\n    else {\n        currentNode = containerNode;\n        nodeStack = [{node: containerNode}];\n    }\n\n    var parts = str.split(SPLIT_TAGS);\n    for(var i = 0; i < parts.length; i++) {\n        var parti = parts[i];\n        var match = parti.match(ONE_TAG);\n        var tagType = match && match[2].toLowerCase();\n        var tagStyle = TAG_STYLES[tagType];\n\n        if(tagType === 'br') {\n            newLine();\n        } else if(tagStyle === undefined) {\n            addTextNode(currentNode, convertEntities(parti));\n        } else {\n            // tag - open or close\n            if(match[1]) {\n                exitNode(tagType);\n            } else {\n                var extra = match[4];\n\n                var nodeSpec = {type: tagType};\n\n                // now add style, from both the tag name and any extra css\n                // Most of the svg css that users will care about is just like html,\n                // but font color is different (uses fill). Let our users ignore this.\n                var css = getQuotedMatch(extra, STYLEMATCH);\n                if(css) {\n                    css = css.replace(COLORMATCH, '$1 fill:');\n                    if(tagStyle) css += ';' + tagStyle;\n                } else if(tagStyle) css = tagStyle;\n\n                if(css) nodeSpec.style = css;\n\n                if(tagType === 'a') {\n                    hasLink = true;\n\n                    var href = getQuotedMatch(extra, HREFMATCH);\n\n                    if(href) {\n                        // check safe protocols\n                        var dummyAnchor = document.createElement('a');\n                        dummyAnchor.href = href;\n                        if(PROTOCOLS.indexOf(dummyAnchor.protocol) !== -1) {\n                            // Decode href to allow both already encoded and not encoded\n                            // URIs. Without decoding prior encoding, an already encoded\n                            // URI would be encoded twice producing a semantically different URI.\n                            nodeSpec.href = encodeURI(decodeURI(href));\n                            nodeSpec.target = getQuotedMatch(extra, TARGETMATCH) || '_blank';\n                            nodeSpec.popup = getQuotedMatch(extra, POPUPMATCH);\n                        }\n                    }\n                }\n\n                enterNode(nodeSpec);\n            }\n        }\n    }\n\n    return hasLink;\n}\n\nexports.lineCount = function lineCount(s) {\n    return s.selectAll('tspan.line').size() || 1;\n};\n\nexports.positionText = function positionText(s, x, y) {\n    return s.each(function() {\n        var text = d3.select(this);\n\n        function setOrGet(attr, val) {\n            if(val === undefined) {\n                val = text.attr(attr);\n                if(val === null) {\n                    text.attr(attr, 0);\n                    val = 0;\n                }\n            } else text.attr(attr, val);\n            return val;\n        }\n\n        var thisX = setOrGet('x', x);\n        var thisY = setOrGet('y', y);\n\n        if(this.nodeName === 'text') {\n            text.selectAll('tspan.line').attr({x: thisX, y: thisY});\n        }\n    });\n};\n\nfunction alignHTMLWith(_base, container, options) {\n    var alignH = options.horizontalAlign;\n    var alignV = options.verticalAlign || 'top';\n    var bRect = _base.node().getBoundingClientRect();\n    var cRect = container.node().getBoundingClientRect();\n    var thisRect;\n    var getTop;\n    var getLeft;\n\n    if(alignV === 'bottom') {\n        getTop = function() { return bRect.bottom - thisRect.height; };\n    } else if(alignV === 'middle') {\n        getTop = function() { return bRect.top + (bRect.height - thisRect.height) / 2; };\n    } else { // default: top\n        getTop = function() { return bRect.top; };\n    }\n\n    if(alignH === 'right') {\n        getLeft = function() { return bRect.right - thisRect.width; };\n    } else if(alignH === 'center') {\n        getLeft = function() { return bRect.left + (bRect.width - thisRect.width) / 2; };\n    } else { // default: left\n        getLeft = function() { return bRect.left; };\n    }\n\n    return function() {\n        thisRect = this.node().getBoundingClientRect();\n        this.style({\n            top: (getTop() - cRect.top) + 'px',\n            left: (getLeft() - cRect.left) + 'px',\n            'z-index': 1000\n        });\n        return this;\n    };\n}\n\n/*\n * Editable title\n * @param {d3.selection} context: the element being edited. Normally text,\n *   but if it isn't, you should provide the styling options\n * @param {object} options:\n *   @param {div} options.gd: graphDiv\n *   @param {d3.selection} options.delegate: item to bind events to if not this\n *   @param {boolean} options.immediate: start editing now (true) or on click (false, default)\n *   @param {string} options.fill: font color if not as shown\n *   @param {string} options.background: background color if not as shown\n *   @param {string} options.text: initial text, if not as shown\n *   @param {string} options.horizontalAlign: alignment of the edit box wrt. the bound element\n *   @param {string} options.verticalAlign: alignment of the edit box wrt. the bound element\n */\n\nexports.makeEditable = function(context, options) {\n    var gd = options.gd;\n    var _delegate = options.delegate;\n    var dispatch = d3.dispatch('edit', 'input', 'cancel');\n    var handlerElement = _delegate || context;\n\n    context.style({'pointer-events': _delegate ? 'none' : 'all'});\n\n    if(context.size() !== 1) throw new Error('boo');\n\n    function handleClick() {\n        appendEditable();\n        context.style({opacity: 0});\n        // also hide any mathjax svg\n        var svgClass = handlerElement.attr('class');\n        var mathjaxClass;\n        if(svgClass) mathjaxClass = '.' + svgClass.split(' ')[0] + '-math-group';\n        else mathjaxClass = '[class*=-math-group]';\n        if(mathjaxClass) {\n            d3.select(context.node().parentNode).select(mathjaxClass).style({opacity: 0});\n        }\n    }\n\n    function selectElementContents(_el) {\n        var el = _el.node();\n        var range = document.createRange();\n        range.selectNodeContents(el);\n        var sel = window.getSelection();\n        sel.removeAllRanges();\n        sel.addRange(range);\n        el.focus();\n    }\n\n    function appendEditable() {\n        var plotDiv = d3.select(gd);\n        var container = plotDiv.select('.svg-container');\n        var div = container.append('div');\n        var cStyle = context.node().style;\n        var fontSize = parseFloat(cStyle.fontSize || 12);\n\n        var initialText = options.text;\n        if(initialText === undefined) initialText = context.attr('data-unformatted');\n\n        div.classed('plugin-editable editable', true)\n            .style({\n                position: 'absolute',\n                'font-family': cStyle.fontFamily || 'Arial',\n                'font-size': fontSize,\n                color: options.fill || cStyle.fill || 'black',\n                opacity: 1,\n                'background-color': options.background || 'transparent',\n                outline: '#ffffff33 1px solid',\n                margin: [-fontSize / 8 + 1, 0, 0, -1].join('px ') + 'px',\n                padding: '0',\n                'box-sizing': 'border-box'\n            })\n            .attr({contenteditable: true})\n            .text(initialText)\n            .call(alignHTMLWith(context, container, options))\n            .on('blur', function() {\n                gd._editing = false;\n                context.text(this.textContent)\n                    .style({opacity: 1});\n                var svgClass = d3.select(this).attr('class');\n                var mathjaxClass;\n                if(svgClass) mathjaxClass = '.' + svgClass.split(' ')[0] + '-math-group';\n                else mathjaxClass = '[class*=-math-group]';\n                if(mathjaxClass) {\n                    d3.select(context.node().parentNode).select(mathjaxClass).style({opacity: 0});\n                }\n                var text = this.textContent;\n                d3.select(this).transition().duration(0).remove();\n                d3.select(document).on('mouseup', null);\n                dispatch.edit.call(context, text);\n            })\n            .on('focus', function() {\n                var editDiv = this;\n                gd._editing = true;\n                d3.select(document).on('mouseup', function() {\n                    if(d3.event.target === editDiv) return false;\n                    if(document.activeElement === div.node()) div.node().blur();\n                });\n            })\n            .on('keyup', function() {\n                if(d3.event.which === 27) {\n                    gd._editing = false;\n                    context.style({opacity: 1});\n                    d3.select(this)\n                        .style({opacity: 0})\n                        .on('blur', function() { return false; })\n                        .transition().remove();\n                    dispatch.cancel.call(context, this.textContent);\n                } else {\n                    dispatch.input.call(context, this.textContent);\n                    d3.select(this).call(alignHTMLWith(context, container, options));\n                }\n            })\n            .on('keydown', function() {\n                if(d3.event.which === 13) this.blur();\n            })\n            .call(selectElementContents);\n    }\n\n    if(options.immediate) handleClick();\n    else handlerElement.on('click', handleClick);\n\n    return d3.rebind(context, dispatch, 'on');\n};\n\n},{\"../constants/alignment\":688,\"../constants/xmlns_namespaces\":696,\"../lib\":719,\"d3\":163}],744:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar timerCache = {};\n\n/**\n * Throttle a callback. `callback` executes synchronously only if\n * more than `minInterval` milliseconds have already elapsed since the latest\n * call (if any). Otherwise we wait until `minInterval` is over and execute the\n * last callback received while waiting.\n * So the first and last events in a train are always executed (eventually)\n * but some of the events in the middle can be dropped.\n *\n * @param {string} id: an identifier to mark events to throttle together\n * @param {number} minInterval: minimum time, in milliseconds, between\n *   invocations of `callback`\n * @param {function} callback: the function to throttle. `callback` itself\n *   should be a purely synchronous function.\n */\nexports.throttle = function throttle(id, minInterval, callback) {\n    var cache = timerCache[id];\n    var now = Date.now();\n\n    if(!cache) {\n        /*\n         * Throw out old items before making a new one, to prevent the cache\n         * getting overgrown, for example from old plots that have been replaced.\n         * 1 minute age is arbitrary.\n         */\n        for(var idi in timerCache) {\n            if(timerCache[idi].ts < now - 60000) {\n                delete timerCache[idi];\n            }\n        }\n        cache = timerCache[id] = {ts: 0, timer: null};\n    }\n\n    _clearTimeout(cache);\n\n    function exec() {\n        callback();\n        cache.ts = Date.now();\n        if(cache.onDone) {\n            cache.onDone();\n            cache.onDone = null;\n        }\n    }\n\n    if(now > cache.ts + minInterval) {\n        exec();\n        return;\n    }\n\n    cache.timer = setTimeout(function() {\n        exec();\n        cache.timer = null;\n    }, minInterval);\n};\n\nexports.done = function(id) {\n    var cache = timerCache[id];\n    if(!cache || !cache.timer) return Promise.resolve();\n\n    return new Promise(function(resolve) {\n        var previousOnDone = cache.onDone;\n        cache.onDone = function onDone() {\n            if(previousOnDone) previousOnDone();\n            resolve();\n            cache.onDone = null;\n        };\n    });\n};\n\n/**\n * Clear the throttle cache for one or all timers\n * @param {optional string} id:\n *   if provided, clear just this timer\n *   if omitted, clear all timers (mainly useful for testing)\n */\nexports.clear = function(id) {\n    if(id) {\n        _clearTimeout(timerCache[id]);\n        delete timerCache[id];\n    } else {\n        for(var idi in timerCache) exports.clear(idi);\n    }\n};\n\nfunction _clearTimeout(cache) {\n    if(cache && cache.timer !== null) {\n        clearTimeout(cache.timer);\n        cache.timer = null;\n    }\n}\n\n},{}],745:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\n/**\n * convert a linear value into a logged value, folding negative numbers into\n * the given range\n */\nmodule.exports = function toLogRange(val, range) {\n    if(val > 0) return Math.log(val) / Math.LN10;\n\n    // move a negative value reference to a log axis - just put the\n    // result at the lowest range value on the plot (or if the range also went negative,\n    // one millionth of the top of the range)\n    var newVal = Math.log(Math.min(range[0], range[1])) / Math.LN10;\n    if(!isNumeric(newVal)) newVal = Math.log(Math.max(range[0], range[1])) / Math.LN10 - 6;\n    return newVal;\n};\n\n},{\"fast-isnumeric\":225}],746:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar topojsonUtils = module.exports = {};\n\nvar locationmodeToLayer = _dereq_('../plots/geo/constants').locationmodeToLayer;\nvar topojsonFeature = _dereq_('topojson-client').feature;\n\ntopojsonUtils.getTopojsonName = function(geoLayout) {\n    return [\n        geoLayout.scope.replace(/ /g, '-'), '_',\n        geoLayout.resolution.toString(), 'm'\n    ].join('');\n};\n\ntopojsonUtils.getTopojsonPath = function(topojsonURL, topojsonName) {\n    return topojsonURL + topojsonName + '.json';\n};\n\ntopojsonUtils.getTopojsonFeatures = function(trace, topojson) {\n    var layer = locationmodeToLayer[trace.locationmode];\n    var obj = topojson.objects[layer];\n\n    return topojsonFeature(topojson, obj).features;\n};\n\n},{\"../plots/geo/constants\":795,\"topojson-client\":540}],747:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'locale',\n    name: 'en-US',\n    dictionary: {\n        'Click to enter Colorscale title': 'Click to enter Colorscale title'\n    },\n    format: {\n        date: '%m/%d/%Y'\n    }\n};\n\n},{}],748:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'locale',\n    name: 'en',\n    dictionary: {\n        'Click to enter Colorscale title': 'Click to enter Colourscale title'\n    },\n    format: {\n        days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n        shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n        months: [\n            'January', 'February', 'March', 'April', 'May', 'June',\n            'July', 'August', 'September', 'October', 'November', 'December'\n        ],\n        shortMonths: [\n            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',\n            'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'\n        ],\n        periods: ['AM', 'PM'],\n        dateTime: '%a %b %e %X %Y',\n        date: '%d/%m/%Y',\n        time: '%H:%M:%S',\n        decimal: '.',\n        thousands: ',',\n        grouping: [3],\n        currency: ['$', ''],\n        year: '%Y',\n        month: '%b %Y',\n        dayMonth: '%b %-d',\n        dayMonthYear: '%b %-d, %Y'\n    }\n};\n\n},{}],749:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Registry = _dereq_('../registry');\n\n/*\n * containerArrayMatch: does this attribute string point into a\n * layout container array?\n *\n * @param {String} astr: an attribute string, like *annotations[2].text*\n *\n * @returns {Object | false} Returns false if `astr` doesn't match a container\n *  array. If it does, returns:\n *     {array: {String}, index: {Number}, property: {String}}\n *  ie the attribute string for the array, the index within the array (or ''\n *  if the whole array) and the property within that (or '' if the whole array\n *  or the whole object)\n */\nmodule.exports = function containerArrayMatch(astr) {\n    var rootContainers = Registry.layoutArrayContainers;\n    var regexpContainers = Registry.layoutArrayRegexes;\n    var rootPart = astr.split('[')[0];\n    var arrayStr;\n    var match;\n\n    // look for regexp matches first, because they may be nested inside root matches\n    // eg updatemenus[i].buttons is nested inside updatemenus\n    for(var i = 0; i < regexpContainers.length; i++) {\n        match = astr.match(regexpContainers[i]);\n        if(match && match.index === 0) {\n            arrayStr = match[0];\n            break;\n        }\n    }\n\n    // now look for root matches\n    if(!arrayStr) arrayStr = rootContainers[rootContainers.indexOf(rootPart)];\n\n    if(!arrayStr) return false;\n\n    var tail = astr.substr(arrayStr.length);\n    if(!tail) return {array: arrayStr, index: '', property: ''};\n\n    match = tail.match(/^\\[(0|[1-9][0-9]*)\\](\\.(.+))?$/);\n    if(!match) return false;\n\n    return {array: arrayStr, index: Number(match[1]), property: match[3] || ''};\n};\n\n},{\"../registry\":847}],750:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar extendFlat = Lib.extendFlat;\nvar isPlainObject = Lib.isPlainObject;\n\nvar traceOpts = {\n    valType: 'flaglist',\n    extras: ['none'],\n    flags: ['calc', 'clearAxisTypes', 'plot', 'style', 'markerSize', 'colorbars'],\n    \n};\n\nvar layoutOpts = {\n    valType: 'flaglist',\n    extras: ['none'],\n    flags: [\n        'calc', 'plot', 'legend', 'ticks', 'axrange',\n        'layoutstyle', 'modebar', 'camera', 'arraydraw', 'colorbars'\n    ],\n    \n};\n\n// flags for inside restyle/relayout include a few extras\n// that shouldn't be used in attributes, to deal with certain\n// combinations and conditionals efficiently\nvar traceEditTypeFlags = traceOpts.flags.slice()\n    .concat(['fullReplot']);\n\nvar layoutEditTypeFlags = layoutOpts.flags.slice()\n    .concat('layoutReplot');\n\nmodule.exports = {\n    traces: traceOpts,\n    layout: layoutOpts,\n    /*\n     * default (all false) edit flags for restyle (traces)\n     * creates a new object each call, so the caller can mutate freely\n     */\n    traceFlags: function() { return falseObj(traceEditTypeFlags); },\n\n    /*\n     * default (all false) edit flags for relayout\n     * creates a new object each call, so the caller can mutate freely\n     */\n    layoutFlags: function() { return falseObj(layoutEditTypeFlags); },\n\n    /*\n     * update `flags` with the `editType` values found in `attr`\n     */\n    update: function(flags, attr) {\n        var editType = attr.editType;\n        if(editType && editType !== 'none') {\n            var editTypeParts = editType.split('+');\n            for(var i = 0; i < editTypeParts.length; i++) {\n                flags[editTypeParts[i]] = true;\n            }\n        }\n    },\n\n    overrideAll: overrideAll\n};\n\nfunction falseObj(keys) {\n    var out = {};\n    for(var i = 0; i < keys.length; i++) out[keys[i]] = false;\n    return out;\n}\n\n/**\n * For attributes that are largely copied from elsewhere into a plot type that doesn't\n * support partial redraws - overrides the editType field of all attributes in the object\n *\n * @param {object} attrs: the attributes to override. Will not be mutated.\n * @param {string} editTypeOverride: the new editType to use\n * @param {'nested'|'from-root'} overrideContainers:\n *   - 'nested' will override editType for nested containers but not the root.\n *   - 'from-root' will also override editType of the root container.\n *   Containers below the absolute top level (trace or layout root) DO need an\n *   editType even if they are not `valObject`s themselves (eg `scatter.marker`)\n *   to handle the case where you edit the whole container.\n *\n * @return {object} a new attributes object with `editType` modified as directed\n */\nfunction overrideAll(attrs, editTypeOverride, overrideContainers) {\n    var out = extendFlat({}, attrs);\n    for(var key in out) {\n        var attr = out[key];\n        if(isPlainObject(attr)) {\n            out[key] = overrideOne(attr, editTypeOverride, overrideContainers, key);\n        }\n    }\n    if(overrideContainers === 'from-root') out.editType = editTypeOverride;\n\n    return out;\n}\n\nfunction overrideOne(attr, editTypeOverride, overrideContainers, key) {\n    if(attr.valType) {\n        var out = extendFlat({}, attr);\n        out.editType = editTypeOverride;\n\n        if(Array.isArray(attr.items)) {\n            out.items = new Array(attr.items.length);\n            for(var i = 0; i < attr.items.length; i++) {\n                out.items[i] = overrideOne(attr.items[i], editTypeOverride, 'from-root');\n            }\n        }\n        return out;\n    } else {\n        // don't provide an editType for the _deprecated container\n        return overrideAll(attr, editTypeOverride,\n            (key.charAt(0) === '_') ? 'nested' : 'from-root');\n    }\n}\n\n},{\"../lib\":719}],751:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar m4FromQuat = _dereq_('gl-mat4/fromQuat');\n\nvar Registry = _dereq_('../registry');\nvar Lib = _dereq_('../lib');\nvar Plots = _dereq_('../plots/plots');\nvar AxisIds = _dereq_('../plots/cartesian/axis_ids');\nvar Color = _dereq_('../components/color');\n\nvar cleanId = AxisIds.cleanId;\nvar getFromTrace = AxisIds.getFromTrace;\nvar traceIs = Registry.traceIs;\n\n// clear the promise queue if one of them got rejected\nexports.clearPromiseQueue = function(gd) {\n    if(Array.isArray(gd._promises) && gd._promises.length > 0) {\n        Lib.log('Clearing previous rejected promises from queue.');\n    }\n\n    gd._promises = [];\n};\n\n// make a few changes to the layout right away\n// before it gets used for anything\n// backward compatibility and cleanup of nonstandard options\nexports.cleanLayout = function(layout) {\n    var i, j;\n\n    if(!layout) layout = {};\n\n    // cannot have (x|y)axis1, numbering goes axis, axis2, axis3...\n    if(layout.xaxis1) {\n        if(!layout.xaxis) layout.xaxis = layout.xaxis1;\n        delete layout.xaxis1;\n    }\n    if(layout.yaxis1) {\n        if(!layout.yaxis) layout.yaxis = layout.yaxis1;\n        delete layout.yaxis1;\n    }\n    if(layout.scene1) {\n        if(!layout.scene) layout.scene = layout.scene1;\n        delete layout.scene1;\n    }\n\n    var axisAttrRegex = (Plots.subplotsRegistry.cartesian || {}).attrRegex;\n    var polarAttrRegex = (Plots.subplotsRegistry.polar || {}).attrRegex;\n    var ternaryAttrRegex = (Plots.subplotsRegistry.ternary || {}).attrRegex;\n    var sceneAttrRegex = (Plots.subplotsRegistry.gl3d || {}).attrRegex;\n\n    var keys = Object.keys(layout);\n    for(i = 0; i < keys.length; i++) {\n        var key = keys[i];\n\n        if(axisAttrRegex && axisAttrRegex.test(key)) {\n            // modifications to cartesian axes\n\n            var ax = layout[key];\n            if(ax.anchor && ax.anchor !== 'free') {\n                ax.anchor = cleanId(ax.anchor);\n            }\n            if(ax.overlaying) ax.overlaying = cleanId(ax.overlaying);\n\n            // old method of axis type - isdate and islog (before category existed)\n            if(!ax.type) {\n                if(ax.isdate) ax.type = 'date';\n                else if(ax.islog) ax.type = 'log';\n                else if(ax.isdate === false && ax.islog === false) ax.type = 'linear';\n            }\n            if(ax.autorange === 'withzero' || ax.autorange === 'tozero') {\n                ax.autorange = true;\n                ax.rangemode = 'tozero';\n            }\n            delete ax.islog;\n            delete ax.isdate;\n            delete ax.categories; // replaced by _categories\n\n            // prune empty domain arrays made before the new nestedProperty\n            if(emptyContainer(ax, 'domain')) delete ax.domain;\n\n            // autotick -> tickmode\n            if(ax.autotick !== undefined) {\n                if(ax.tickmode === undefined) {\n                    ax.tickmode = ax.autotick ? 'auto' : 'linear';\n                }\n                delete ax.autotick;\n            }\n\n            cleanTitle(ax);\n        } else if(polarAttrRegex && polarAttrRegex.test(key)) {\n            // modifications for polar\n\n            var polar = layout[key];\n            cleanTitle(polar.radialaxis);\n        } else if(ternaryAttrRegex && ternaryAttrRegex.test(key)) {\n            // modifications for ternary\n\n            var ternary = layout[key];\n            cleanTitle(ternary.aaxis);\n            cleanTitle(ternary.baxis);\n            cleanTitle(ternary.caxis);\n        } else if(sceneAttrRegex && sceneAttrRegex.test(key)) {\n            // modifications for 3D scenes\n\n            var scene = layout[key];\n\n            // clean old Camera coords\n            var cameraposition = scene.cameraposition;\n\n            if(Array.isArray(cameraposition) && cameraposition[0].length === 4) {\n                var rotation = cameraposition[0];\n                var center = cameraposition[1];\n                var radius = cameraposition[2];\n                var mat = m4FromQuat([], rotation);\n                var eye = [];\n\n                for(j = 0; j < 3; ++j) {\n                    eye[j] = center[j] + radius * mat[2 + 4 * j];\n                }\n\n                scene.camera = {\n                    eye: {x: eye[0], y: eye[1], z: eye[2]},\n                    center: {x: center[0], y: center[1], z: center[2]},\n                    up: {x: 0, y: 0, z: 1} // we just ignore calculating camera z up in this case\n                };\n\n                delete scene.cameraposition;\n            }\n\n            // clean axis titles\n            cleanTitle(scene.xaxis);\n            cleanTitle(scene.yaxis);\n            cleanTitle(scene.zaxis);\n        }\n    }\n\n    var annotationsLen = Array.isArray(layout.annotations) ? layout.annotations.length : 0;\n    for(i = 0; i < annotationsLen; i++) {\n        var ann = layout.annotations[i];\n\n        if(!Lib.isPlainObject(ann)) continue;\n\n        if(ann.ref) {\n            if(ann.ref === 'paper') {\n                ann.xref = 'paper';\n                ann.yref = 'paper';\n            } else if(ann.ref === 'data') {\n                ann.xref = 'x';\n                ann.yref = 'y';\n            }\n            delete ann.ref;\n        }\n\n        cleanAxRef(ann, 'xref');\n        cleanAxRef(ann, 'yref');\n    }\n\n    var shapesLen = Array.isArray(layout.shapes) ? layout.shapes.length : 0;\n    for(i = 0; i < shapesLen; i++) {\n        var shape = layout.shapes[i];\n\n        if(!Lib.isPlainObject(shape)) continue;\n\n        cleanAxRef(shape, 'xref');\n        cleanAxRef(shape, 'yref');\n    }\n\n    var legend = layout.legend;\n    if(legend) {\n        // check for old-style legend positioning (x or y is +/- 100)\n        if(legend.x > 3) {\n            legend.x = 1.02;\n            legend.xanchor = 'left';\n        } else if(legend.x < -2) {\n            legend.x = -0.02;\n            legend.xanchor = 'right';\n        }\n\n        if(legend.y > 3) {\n            legend.y = 1.02;\n            legend.yanchor = 'bottom';\n        } else if(legend.y < -2) {\n            legend.y = -0.02;\n            legend.yanchor = 'top';\n        }\n    }\n\n    // clean plot title\n    cleanTitle(layout);\n\n    /*\n     * Moved from rotate -> orbit for dragmode\n     */\n    if(layout.dragmode === 'rotate') layout.dragmode = 'orbit';\n\n    // sanitize rgb(fractions) and rgba(fractions) that old tinycolor\n    // supported, but new tinycolor does not because they're not valid css\n    Color.clean(layout);\n\n    // clean the layout container in layout.template\n    if(layout.template && layout.template.layout) {\n        exports.cleanLayout(layout.template.layout);\n    }\n\n    return layout;\n};\n\nfunction cleanAxRef(container, attr) {\n    var valIn = container[attr];\n    var axLetter = attr.charAt(0);\n    if(valIn && valIn !== 'paper') {\n        container[attr] = cleanId(valIn, axLetter);\n    }\n}\n\n/**\n * Cleans up old title attribute structure (flat) in favor of the new one (nested).\n *\n * @param {Object} titleContainer - an object potentially including deprecated title attributes\n */\nfunction cleanTitle(titleContainer) {\n    if(titleContainer) {\n        // title -> title.text\n        // (although title used to be a string attribute,\n        // numbers are accepted as well)\n        if(typeof titleContainer.title === 'string' || typeof titleContainer.title === 'number') {\n            titleContainer.title = {\n                text: titleContainer.title\n            };\n        }\n\n        rewireAttr('titlefont', 'font');\n        rewireAttr('titleposition', 'position');\n        rewireAttr('titleside', 'side');\n        rewireAttr('titleoffset', 'offset');\n    }\n\n    function rewireAttr(oldAttrName, newAttrName) {\n        var oldAttrSet = titleContainer[oldAttrName];\n        var newAttrSet = titleContainer.title && titleContainer.title[newAttrName];\n\n        if(oldAttrSet && !newAttrSet) {\n            // Ensure title object exists\n            if(!titleContainer.title) {\n                titleContainer.title = {};\n            }\n\n            titleContainer.title[newAttrName] = titleContainer[oldAttrName];\n            delete titleContainer[oldAttrName];\n        }\n    }\n}\n\n/*\n * cleanData: Make a few changes to the data for backward compatibility\n * before it gets used for anything. Modifies the data traces users provide.\n *\n * Important: if you're going to add something here that modifies a data array,\n * update it in place so the new array === the old one.\n */\nexports.cleanData = function(data) {\n    for(var tracei = 0; tracei < data.length; tracei++) {\n        var trace = data[tracei];\n        var i;\n\n        // use xbins to bin data in x, and ybins to bin data in y\n        if(trace.type === 'histogramy' && 'xbins' in trace && !('ybins' in trace)) {\n            trace.ybins = trace.xbins;\n            delete trace.xbins;\n        }\n\n        // error_y.opacity is obsolete - merge into color\n        if(trace.error_y && 'opacity' in trace.error_y) {\n            var dc = Color.defaults;\n            var yeColor = trace.error_y.color || (traceIs(trace, 'bar') ?\n                Color.defaultLine :\n                dc[tracei % dc.length]);\n            trace.error_y.color = Color.addOpacity(\n                Color.rgb(yeColor),\n                Color.opacity(yeColor) * trace.error_y.opacity);\n            delete trace.error_y.opacity;\n        }\n\n        // convert bardir to orientation, and put the data into\n        // the axes it's eventually going to be used with\n        if('bardir' in trace) {\n            if(trace.bardir === 'h' && (traceIs(trace, 'bar') ||\n                trace.type.substr(0, 9) === 'histogram')) {\n                trace.orientation = 'h';\n                exports.swapXYData(trace);\n            }\n            delete trace.bardir;\n        }\n\n        // now we have only one 1D histogram type, and whether\n        // it uses x or y data depends on trace.orientation\n        if(trace.type === 'histogramy') exports.swapXYData(trace);\n        if(trace.type === 'histogramx' || trace.type === 'histogramy') {\n            trace.type = 'histogram';\n        }\n\n        // scl->scale, reversescl->reversescale\n        if('scl' in trace && !('colorscale' in trace)) {\n            trace.colorscale = trace.scl;\n            delete trace.scl;\n        }\n        if('reversescl' in trace && !('reversescale' in trace)) {\n            trace.reversescale = trace.reversescl;\n            delete trace.reversescl;\n        }\n\n        // axis ids x1 -> x, y1-> y\n        if(trace.xaxis) trace.xaxis = cleanId(trace.xaxis, 'x');\n        if(trace.yaxis) trace.yaxis = cleanId(trace.yaxis, 'y');\n\n        // scene ids scene1 -> scene\n        if(traceIs(trace, 'gl3d') && trace.scene) {\n            trace.scene = Plots.subplotsRegistry.gl3d.cleanId(trace.scene);\n        }\n\n        if(!traceIs(trace, 'pie-like') && !traceIs(trace, 'bar-like')) {\n            if(Array.isArray(trace.textposition)) {\n                for(i = 0; i < trace.textposition.length; i++) {\n                    trace.textposition[i] = cleanTextPosition(trace.textposition[i]);\n                }\n            } else if(trace.textposition) {\n                trace.textposition = cleanTextPosition(trace.textposition);\n            }\n        }\n\n        // fix typo in colorscale definition\n        var _module = Registry.getModule(trace);\n        if(_module && _module.colorbar) {\n            var containerName = _module.colorbar.container;\n            var container = containerName ? trace[containerName] : trace;\n            if(container && container.colorscale) {\n                if(container.colorscale === 'YIGnBu') container.colorscale = 'YlGnBu';\n                if(container.colorscale === 'YIOrRd') container.colorscale = 'YlOrRd';\n            }\n        }\n\n        // fix typo in surface 'highlight*' definitions\n        if(trace.type === 'surface' && Lib.isPlainObject(trace.contours)) {\n            var dims = ['x', 'y', 'z'];\n\n            for(i = 0; i < dims.length; i++) {\n                var opts = trace.contours[dims[i]];\n\n                if(!Lib.isPlainObject(opts)) continue;\n\n                if(opts.highlightColor) {\n                    opts.highlightcolor = opts.highlightColor;\n                    delete opts.highlightColor;\n                }\n\n                if(opts.highlightWidth) {\n                    opts.highlightwidth = opts.highlightWidth;\n                    delete opts.highlightWidth;\n                }\n            }\n        }\n\n        // fixes from converting finance from transforms to real trace types\n        if(trace.type === 'candlestick' || trace.type === 'ohlc') {\n            var increasingShowlegend = (trace.increasing || {}).showlegend !== false;\n            var decreasingShowlegend = (trace.decreasing || {}).showlegend !== false;\n            var increasingName = cleanFinanceDir(trace.increasing);\n            var decreasingName = cleanFinanceDir(trace.decreasing);\n\n            // now figure out something smart to do with the separate direction\n            // names we removed\n            if((increasingName !== false) && (decreasingName !== false)) {\n                // both sub-names existed: base name previously had no effect\n                // so ignore it and try to find a shared part of the sub-names\n\n                var newName = commonPrefix(\n                    increasingName, decreasingName,\n                    increasingShowlegend, decreasingShowlegend\n                );\n                // if no common part, leave whatever name was (or wasn't) there\n                if(newName) trace.name = newName;\n            } else if((increasingName || decreasingName) && !trace.name) {\n                // one sub-name existed but not the base name - just use the sub-name\n                trace.name = increasingName || decreasingName;\n            }\n        }\n\n        // transforms backward compatibility fixes\n        if(Array.isArray(trace.transforms)) {\n            var transforms = trace.transforms;\n\n            for(i = 0; i < transforms.length; i++) {\n                var transform = transforms[i];\n\n                if(!Lib.isPlainObject(transform)) continue;\n\n                switch(transform.type) {\n                    case 'filter':\n                        if(transform.filtersrc) {\n                            transform.target = transform.filtersrc;\n                            delete transform.filtersrc;\n                        }\n\n                        if(transform.calendar) {\n                            if(!transform.valuecalendar) {\n                                transform.valuecalendar = transform.calendar;\n                            }\n                            delete transform.calendar;\n                        }\n                        break;\n\n                    case 'groupby':\n                        // Name has changed from `style` to `styles`, so use `style` but prefer `styles`:\n                        transform.styles = transform.styles || transform.style;\n\n                        if(transform.styles && !Array.isArray(transform.styles)) {\n                            var prevStyles = transform.styles;\n                            var styleKeys = Object.keys(prevStyles);\n\n                            transform.styles = [];\n                            for(var j = 0; j < styleKeys.length; j++) {\n                                transform.styles.push({\n                                    target: styleKeys[j],\n                                    value: prevStyles[styleKeys[j]]\n                                });\n                            }\n                        }\n                        break;\n                }\n            }\n        }\n\n        // prune empty containers made before the new nestedProperty\n        if(emptyContainer(trace, 'line')) delete trace.line;\n        if('marker' in trace) {\n            if(emptyContainer(trace.marker, 'line')) delete trace.marker.line;\n            if(emptyContainer(trace, 'marker')) delete trace.marker;\n        }\n\n        // sanitize rgb(fractions) and rgba(fractions) that old tinycolor\n        // supported, but new tinycolor does not because they're not valid css\n        Color.clean(trace);\n\n        // remove obsolete autobin(x|y) attributes, but only if true\n        // if false, this needs to happen in Histogram.calc because it\n        // can be a one-time autobin so we need to know the results before\n        // we can push them back into the trace.\n        if(trace.autobinx) {\n            delete trace.autobinx;\n            delete trace.xbins;\n        }\n        if(trace.autobiny) {\n            delete trace.autobiny;\n            delete trace.ybins;\n        }\n\n        cleanTitle(trace);\n        if(trace.colorbar) cleanTitle(trace.colorbar);\n        if(trace.marker && trace.marker.colorbar) cleanTitle(trace.marker.colorbar);\n        if(trace.line && trace.line.colorbar) cleanTitle(trace.line.colorbar);\n        if(trace.aaxis) cleanTitle(trace.aaxis);\n        if(trace.baxis) cleanTitle(trace.baxis);\n    }\n};\n\nfunction cleanFinanceDir(dirContainer) {\n    if(!Lib.isPlainObject(dirContainer)) return false;\n\n    var dirName = dirContainer.name;\n\n    delete dirContainer.name;\n    delete dirContainer.showlegend;\n\n    return (typeof dirName === 'string' || typeof dirName === 'number') && String(dirName);\n}\n\nfunction commonPrefix(name1, name2, show1, show2) {\n    // if only one is shown in the legend, use that\n    if(show1 && !show2) return name1;\n    if(show2 && !show1) return name2;\n\n    // if both or neither are in the legend, check if one is blank (or whitespace)\n    // and use the other one\n    // note that hover labels can still use the name even if the legend doesn't\n    if(!name1.trim()) return name2;\n    if(!name2.trim()) return name1;\n\n    var minLen = Math.min(name1.length, name2.length);\n    var i;\n    for(i = 0; i < minLen; i++) {\n        if(name1.charAt(i) !== name2.charAt(i)) break;\n    }\n\n    var out = name1.substr(0, i);\n    return out.trim();\n}\n\n// textposition - support partial attributes (ie just 'top')\n// and incorrect use of middle / center etc.\nfunction cleanTextPosition(textposition) {\n    var posY = 'middle';\n    var posX = 'center';\n\n    if(typeof textposition === 'string') {\n        if(textposition.indexOf('top') !== -1) posY = 'top';\n        else if(textposition.indexOf('bottom') !== -1) posY = 'bottom';\n\n        if(textposition.indexOf('left') !== -1) posX = 'left';\n        else if(textposition.indexOf('right') !== -1) posX = 'right';\n    }\n\n    return posY + ' ' + posX;\n}\n\nfunction emptyContainer(outer, innerStr) {\n    return (innerStr in outer) &&\n        (typeof outer[innerStr] === 'object') &&\n        (Object.keys(outer[innerStr]).length === 0);\n}\n\n\n// swap all the data and data attributes associated with x and y\nexports.swapXYData = function(trace) {\n    var i;\n    Lib.swapAttrs(trace, ['?', '?0', 'd?', '?bins', 'nbins?', 'autobin?', '?src', 'error_?']);\n    if(Array.isArray(trace.z) && Array.isArray(trace.z[0])) {\n        if(trace.transpose) delete trace.transpose;\n        else trace.transpose = true;\n    }\n    if(trace.error_x && trace.error_y) {\n        var errorY = trace.error_y;\n        var copyYstyle = ('copy_ystyle' in errorY) ?\n            errorY.copy_ystyle :\n            !(errorY.color || errorY.thickness || errorY.width);\n        Lib.swapAttrs(trace, ['error_?.copy_ystyle']);\n        if(copyYstyle) {\n            Lib.swapAttrs(trace, ['error_?.color', 'error_?.thickness', 'error_?.width']);\n        }\n    }\n    if(typeof trace.hoverinfo === 'string') {\n        var hoverInfoParts = trace.hoverinfo.split('+');\n        for(i = 0; i < hoverInfoParts.length; i++) {\n            if(hoverInfoParts[i] === 'x') hoverInfoParts[i] = 'y';\n            else if(hoverInfoParts[i] === 'y') hoverInfoParts[i] = 'x';\n        }\n        trace.hoverinfo = hoverInfoParts.join('+');\n    }\n};\n\n// coerce traceIndices input to array of trace indices\nexports.coerceTraceIndices = function(gd, traceIndices) {\n    if(isNumeric(traceIndices)) {\n        return [traceIndices];\n    } else if(!Array.isArray(traceIndices) || !traceIndices.length) {\n        return gd.data.map(function(_, i) { return i; });\n    } else if(Array.isArray(traceIndices)) {\n        var traceIndicesOut = [];\n        for(var i = 0; i < traceIndices.length; i++) {\n            if(Lib.isIndex(traceIndices[i], gd.data.length)) {\n                traceIndicesOut.push(traceIndices[i]);\n            } else {\n                Lib.warn('trace index (', traceIndices[i], ') is not a number or is out of bounds');\n            }\n        }\n        return traceIndicesOut;\n    }\n\n    return traceIndices;\n};\n\n/**\n * Manages logic around array container item creation / deletion / update\n * that nested property alone can't handle.\n *\n * @param {Object} np\n *  nested property of update attribute string about trace or layout object\n * @param {*} newVal\n *  update value passed to restyle / relayout / update\n * @param {Object} undoit\n *  undo hash (N.B. undoit may be mutated here).\n *\n */\nexports.manageArrayContainers = function(np, newVal, undoit) {\n    var obj = np.obj;\n    var parts = np.parts;\n    var pLength = parts.length;\n    var pLast = parts[pLength - 1];\n\n    var pLastIsNumber = isNumeric(pLast);\n\n    if(pLastIsNumber && newVal === null) {\n        // delete item\n\n        // Clear item in array container when new value is null\n        var contPath = parts.slice(0, pLength - 1).join('.');\n        var cont = Lib.nestedProperty(obj, contPath).get();\n        cont.splice(pLast, 1);\n\n        // Note that nested property clears null / undefined at end of\n        // array container, but not within them.\n    } else if(pLastIsNumber && np.get() === undefined) {\n        // create item\n\n        // When adding a new item, make sure undo command will remove it\n        if(np.get() === undefined) undoit[np.astr] = null;\n\n        np.set(newVal);\n    } else {\n        // update item\n\n        // If the last part of attribute string isn't a number,\n        // np.set is all we need.\n        np.set(newVal);\n    }\n};\n\n/*\n * Match the part to strip off to turn an attribute into its parent\n * really it should be either '.some_characters' or '[number]'\n * but we're a little more permissive here and match either\n * '.not_brackets_or_dot' or '[not_brackets_or_dot]'\n */\nvar ATTR_TAIL_RE = /(\\.[^\\[\\]\\.]+|\\[[^\\[\\]\\.]+\\])$/;\n\nfunction getParent(attr) {\n    var tail = attr.search(ATTR_TAIL_RE);\n    if(tail > 0) return attr.substr(0, tail);\n}\n\n/*\n * hasParent: does an attribute object contain a parent of the given attribute?\n * for example, given 'images[2].x' do we also have 'images' or 'images[2]'?\n *\n * @param {Object} aobj\n *  update object, whose keys are attribute strings and values are their new settings\n * @param {string} attr\n *  the attribute string to test against\n * @returns {Boolean}\n *  is a parent of attr present in aobj?\n */\nexports.hasParent = function(aobj, attr) {\n    var attrParent = getParent(attr);\n    while(attrParent) {\n        if(attrParent in aobj) return true;\n        attrParent = getParent(attrParent);\n    }\n    return false;\n};\n\n/**\n * Empty out types for all axes containing these traces so we auto-set them again\n *\n * @param {object} gd\n * @param {[integer]} traces: trace indices to search for axes to clear the types of\n * @param {object} layoutUpdate: any update being done concurrently to the layout,\n *   which may supercede clearing the axis types\n */\nvar axLetters = ['x', 'y', 'z'];\nexports.clearAxisTypes = function(gd, traces, layoutUpdate) {\n    for(var i = 0; i < traces.length; i++) {\n        var trace = gd._fullData[i];\n        for(var j = 0; j < 3; j++) {\n            var ax = getFromTrace(gd, trace, axLetters[j]);\n\n            // do not clear log type - that's never an auto result so must have been intentional\n            if(ax && ax.type !== 'log') {\n                var axAttr = ax._name;\n                var sceneName = ax._id.substr(1);\n                if(sceneName.substr(0, 5) === 'scene') {\n                    if(layoutUpdate[sceneName] !== undefined) continue;\n                    axAttr = sceneName + '.' + axAttr;\n                }\n                var typeAttr = axAttr + '.type';\n\n                if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {\n                    Lib.nestedProperty(gd.layout, typeAttr).set(null);\n                }\n            }\n        }\n    }\n};\n\n},{\"../components/color\":593,\"../lib\":719,\"../plots/cartesian/axis_ids\":770,\"../plots/plots\":828,\"../registry\":847,\"fast-isnumeric\":225,\"gl-mat4/fromQuat\":262}],752:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar main = _dereq_('./plot_api');\n\nexports.plot = main.plot;\nexports.newPlot = main.newPlot;\nexports.restyle = main.restyle;\nexports.relayout = main.relayout;\nexports.redraw = main.redraw;\nexports.update = main.update;\nexports._guiRestyle = main._guiRestyle;\nexports._guiRelayout = main._guiRelayout;\nexports._guiUpdate = main._guiUpdate;\nexports._storeDirectGUIEdit = main._storeDirectGUIEdit;\nexports.react = main.react;\nexports.extendTraces = main.extendTraces;\nexports.prependTraces = main.prependTraces;\nexports.addTraces = main.addTraces;\nexports.deleteTraces = main.deleteTraces;\nexports.moveTraces = main.moveTraces;\nexports.purge = main.purge;\nexports.addFrames = main.addFrames;\nexports.deleteFrames = main.deleteFrames;\nexports.animate = main.animate;\nexports.setPlotConfig = main.setPlotConfig;\n\nexports.toImage = _dereq_('./to_image');\nexports.validate = _dereq_('./validate');\nexports.downloadImage = _dereq_('../snapshot/download');\n\nvar templateApi = _dereq_('./template_api');\nexports.makeTemplate = templateApi.makeTemplate;\nexports.validateTemplate = templateApi.validateTemplate;\n\n},{\"../snapshot/download\":849,\"./plot_api\":754,\"./template_api\":759,\"./to_image\":760,\"./validate\":761}],753:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isPlainObject = _dereq_('../lib/is_plain_object');\nvar noop = _dereq_('../lib/noop');\nvar Loggers = _dereq_('../lib/loggers');\nvar sorterAsc = _dereq_('../lib/search').sorterAsc;\nvar Registry = _dereq_('../registry');\n\n\nexports.containerArrayMatch = _dereq_('./container_array_match');\n\nvar isAddVal = exports.isAddVal = function isAddVal(val) {\n    return val === 'add' || isPlainObject(val);\n};\n\nvar isRemoveVal = exports.isRemoveVal = function isRemoveVal(val) {\n    return val === null || val === 'remove';\n};\n\n/*\n * applyContainerArrayChanges: for managing arrays of layout components in relayout\n * handles them all with a consistent interface.\n *\n * Here are the supported actions -> relayout calls -> edits we get here\n * (as prepared in _relayout):\n *\n * add an empty obj -> {'annotations[2]': 'add'} -> {2: {'': 'add'}}\n * add a specific obj -> {'annotations[2]': {attrs}} -> {2: {'': {attrs}}}\n * delete an obj -> {'annotations[2]': 'remove'} -> {2: {'': 'remove'}}\n *               -> {'annotations[2]': null} -> {2: {'': null}}\n * delete the whole array -> {'annotations': 'remove'} -> {'': {'': 'remove'}}\n *                        -> {'annotations': null} -> {'': {'': null}}\n * edit an object -> {'annotations[2].text': 'boo'} -> {2: {'text': 'boo'}}\n *\n * You can combine many edits to different objects. Objects are added and edited\n * in ascending order, then removed in descending order.\n * For example, starting with [a, b, c], if you want to:\n * - replace b with d:\n *   {'annotations[1]': d, 'annotations[2]': null} (b is item 2 after adding d)\n * - add a new item d between a and b, and edit b:\n *    {'annotations[1]': d, 'annotations[2].x': newX} (b is item 2 after adding d)\n * - delete b and edit c:\n *    {'annotations[1]': null, 'annotations[2].x': newX} (c is edited before b is removed)\n *\n * You CANNOT combine adding/deleting an item at index `i` with edits to the same index `i`\n * You CANNOT combine replacing/deleting the whole array with anything else (for the same array).\n *\n * @param {HTMLDivElement} gd\n *  the DOM element of the graph container div\n * @param {Lib.nestedProperty} componentType: the array we are editing\n * @param {Object} edits\n *  the changes to make; keys are indices to edit, values are themselves objects:\n *  {attr: newValue} of changes to make to that index (with add/remove behavior\n *  in special values of the empty attr)\n * @param {Object} flags\n *  the flags for which actions we're going to perform to display these (and\n *  any other) changes. If we're already `recalc`ing, we don't need to redraw\n *  individual items\n * @param {function} _nestedProperty\n *  a (possibly modified for gui edits) nestedProperty constructor\n *  The modified version takes a 3rd argument, for a prefix to the attribute\n *  string necessary for storing GUI edits\n *\n * @returns {bool} `true` if it managed to complete drawing of the changes\n *  `false` would mean the parent should replot.\n */\nexports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np, edits, flags, _nestedProperty) {\n    var componentType = np.astr;\n    var supplyComponentDefaults = Registry.getComponentMethod(componentType, 'supplyLayoutDefaults');\n    var draw = Registry.getComponentMethod(componentType, 'draw');\n    var drawOne = Registry.getComponentMethod(componentType, 'drawOne');\n    var replotLater = flags.replot || flags.recalc || (supplyComponentDefaults === noop) || (draw === noop);\n    var layout = gd.layout;\n    var fullLayout = gd._fullLayout;\n\n    if(edits['']) {\n        if(Object.keys(edits).length > 1) {\n            Loggers.warn('Full array edits are incompatible with other edits',\n                componentType);\n        }\n\n        var fullVal = edits[''][''];\n\n        if(isRemoveVal(fullVal)) np.set(null);\n        else if(Array.isArray(fullVal)) np.set(fullVal);\n        else {\n            Loggers.warn('Unrecognized full array edit value', componentType, fullVal);\n            return true;\n        }\n\n        if(replotLater) return false;\n\n        supplyComponentDefaults(layout, fullLayout);\n        draw(gd);\n        return true;\n    }\n\n    var componentNums = Object.keys(edits).map(Number).sort(sorterAsc);\n    var componentArrayIn = np.get();\n    var componentArray = componentArrayIn || [];\n    // componentArrayFull is used just to keep splices in line between\n    // full and input arrays, so private keys can be copied over after\n    // redoing supplyDefaults\n    // TODO: this assumes componentArray is in gd.layout - which will not be\n    // true after we extend this to restyle\n    var componentArrayFull = _nestedProperty(fullLayout, componentType).get();\n\n    var deletes = [];\n    var firstIndexChange = -1;\n    var maxIndex = componentArray.length;\n    var i;\n    var j;\n    var componentNum;\n    var objEdits;\n    var objKeys;\n    var objVal;\n    var adding, prefix;\n\n    // first make the add and edit changes\n    for(i = 0; i < componentNums.length; i++) {\n        componentNum = componentNums[i];\n        objEdits = edits[componentNum];\n        objKeys = Object.keys(objEdits);\n        objVal = objEdits[''],\n        adding = isAddVal(objVal);\n\n        if(componentNum < 0 || componentNum > componentArray.length - (adding ? 0 : 1)) {\n            Loggers.warn('index out of range', componentType, componentNum);\n            continue;\n        }\n\n        if(objVal !== undefined) {\n            if(objKeys.length > 1) {\n                Loggers.warn(\n                    'Insertion & removal are incompatible with edits to the same index.',\n                    componentType, componentNum);\n            }\n\n            if(isRemoveVal(objVal)) {\n                deletes.push(componentNum);\n            } else if(adding) {\n                if(objVal === 'add') objVal = {};\n                componentArray.splice(componentNum, 0, objVal);\n                if(componentArrayFull) componentArrayFull.splice(componentNum, 0, {});\n            } else {\n                Loggers.warn('Unrecognized full object edit value',\n                    componentType, componentNum, objVal);\n            }\n\n            if(firstIndexChange === -1) firstIndexChange = componentNum;\n        } else {\n            for(j = 0; j < objKeys.length; j++) {\n                prefix = componentType + '[' + componentNum + '].';\n                _nestedProperty(componentArray[componentNum], objKeys[j], prefix)\n                    .set(objEdits[objKeys[j]]);\n            }\n        }\n    }\n\n    // now do deletes\n    for(i = deletes.length - 1; i >= 0; i--) {\n        componentArray.splice(deletes[i], 1);\n        // TODO: this drops private keys that had been stored in componentArrayFull\n        // does this have any ill effects?\n        if(componentArrayFull) componentArrayFull.splice(deletes[i], 1);\n    }\n\n    if(!componentArray.length) np.set(null);\n    else if(!componentArrayIn) np.set(componentArray);\n\n    if(replotLater) return false;\n\n    supplyComponentDefaults(layout, fullLayout);\n\n    // finally draw all the components we need to\n    // if we added or removed any, redraw all after it\n    if(drawOne !== noop) {\n        var indicesToDraw;\n        if(firstIndexChange === -1) {\n            // there's no re-indexing to do, so only redraw components that changed\n            indicesToDraw = componentNums;\n        } else {\n            // in case the component array was shortened, we still need do call\n            // drawOne on the latter items so they get properly removed\n            maxIndex = Math.max(componentArray.length, maxIndex);\n            indicesToDraw = [];\n            for(i = 0; i < componentNums.length; i++) {\n                componentNum = componentNums[i];\n                if(componentNum >= firstIndexChange) break;\n                indicesToDraw.push(componentNum);\n            }\n            for(i = firstIndexChange; i < maxIndex; i++) {\n                indicesToDraw.push(i);\n            }\n        }\n        for(i = 0; i < indicesToDraw.length; i++) {\n            drawOne(gd, indicesToDraw[i]);\n        }\n    } else draw(gd);\n\n    return true;\n};\n\n},{\"../lib/is_plain_object\":720,\"../lib/loggers\":723,\"../lib/noop\":728,\"../lib/search\":738,\"../registry\":847,\"./container_array_match\":749}],754:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\nvar hasHover = _dereq_('has-hover');\n\nvar Lib = _dereq_('../lib');\nvar nestedProperty = Lib.nestedProperty;\n\nvar Events = _dereq_('../lib/events');\nvar Queue = _dereq_('../lib/queue');\n\nvar Registry = _dereq_('../registry');\nvar PlotSchema = _dereq_('./plot_schema');\nvar Plots = _dereq_('../plots/plots');\nvar Polar = _dereq_('../plots/polar/legacy');\n\nvar Axes = _dereq_('../plots/cartesian/axes');\nvar Drawing = _dereq_('../components/drawing');\nvar Color = _dereq_('../components/color');\nvar initInteractions = _dereq_('../plots/cartesian/graph_interact').initInteractions;\nvar xmlnsNamespaces = _dereq_('../constants/xmlns_namespaces');\nvar svgTextUtils = _dereq_('../lib/svg_text_utils');\nvar clearSelect = _dereq_('../plots/cartesian/select').clearSelect;\n\nvar dfltConfig = _dereq_('./plot_config').dfltConfig;\nvar manageArrays = _dereq_('./manage_arrays');\nvar helpers = _dereq_('./helpers');\nvar subroutines = _dereq_('./subroutines');\nvar editTypes = _dereq_('./edit_types');\n\nvar AX_NAME_PATTERN = _dereq_('../plots/cartesian/constants').AX_NAME_PATTERN;\n\nvar numericNameWarningCount = 0;\nvar numericNameWarningCountLimit = 5;\n\n/**\n * Main plot-creation function\n *\n * @param {string id or DOM element} gd\n *      the id or DOM element of the graph container div\n * @param {array of objects} data\n *      array of traces, containing the data and display information for each trace\n * @param {object} layout\n *      object describing the overall display of the plot,\n *      all the stuff that doesn't pertain to any individual trace\n * @param {object} config\n *      configuration options (see ./plot_config.js for more info)\n *\n * OR\n *\n * @param {string id or DOM element} gd\n *      the id or DOM element of the graph container div\n * @param {object} figure\n *      object containing `data`, `layout`, `config`, and `frames` members\n *\n */\nfunction plot(gd, data, layout, config) {\n    var frames;\n\n    gd = Lib.getGraphDiv(gd);\n\n    // Events.init is idempotent and bails early if gd has already been init'd\n    Events.init(gd);\n\n    if(Lib.isPlainObject(data)) {\n        var obj = data;\n        data = obj.data;\n        layout = obj.layout;\n        config = obj.config;\n        frames = obj.frames;\n    }\n\n    var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]);\n    if(okToPlot === false) return Promise.reject();\n\n    // if there's no data or layout, and this isn't yet a plotly plot\n    // container, log a warning to help plotly.js users debug\n    if(!data && !layout && !Lib.isPlotDiv(gd)) {\n        Lib.warn('Calling Plotly.plot as if redrawing ' +\n            'but this container doesn\\'t yet have a plot.', gd);\n    }\n\n    function addFrames() {\n        if(frames) {\n            return exports.addFrames(gd, frames);\n        }\n    }\n\n    // transfer configuration options to gd until we move over to\n    // a more OO like model\n    setPlotContext(gd, config);\n\n    if(!layout) layout = {};\n\n    // hook class for plots main container (in case of plotly.js\n    // this won't be #embedded-graph or .js-tab-contents)\n    d3.select(gd).classed('js-plotly-plot', true);\n\n    // off-screen getBoundingClientRect testing space,\n    // in #js-plotly-tester (and stored as Drawing.tester)\n    // so we can share cached text across tabs\n    Drawing.makeTester();\n\n    // collect promises for any async actions during plotting\n    // any part of the plotting code can push to gd._promises, then\n    // before we move to the next step, we check that they're all\n    // complete, and empty out the promise list again.\n    if(!Array.isArray(gd._promises)) gd._promises = [];\n\n    var graphWasEmpty = ((gd.data || []).length === 0 && Array.isArray(data));\n\n    // if there is already data on the graph, append the new data\n    // if you only want to redraw, pass a non-array for data\n    if(Array.isArray(data)) {\n        helpers.cleanData(data);\n\n        if(graphWasEmpty) gd.data = data;\n        else gd.data.push.apply(gd.data, data);\n\n        // for routines outside graph_obj that want a clean tab\n        // (rather than appending to an existing one) gd.empty\n        // is used to determine whether to make a new tab\n        gd.empty = false;\n    }\n\n    if(!gd.layout || graphWasEmpty) {\n        gd.layout = helpers.cleanLayout(layout);\n    }\n\n    Plots.supplyDefaults(gd);\n\n    var fullLayout = gd._fullLayout;\n    var hasCartesian = fullLayout._has('cartesian');\n\n    // Legacy polar plots\n    if(!fullLayout._has('polar') && data && data[0] && data[0].r) {\n        Lib.log('Legacy polar charts are deprecated!');\n        return plotLegacyPolar(gd, data, layout);\n    }\n\n    // so we don't try to re-call Plotly.plot from inside\n    // legend and colorbar, if margins changed\n    fullLayout._replotting = true;\n\n    // make or remake the framework if we need to\n    if(graphWasEmpty) makePlotFramework(gd);\n\n    // polar need a different framework\n    if(gd.framework !== makePlotFramework) {\n        gd.framework = makePlotFramework;\n        makePlotFramework(gd);\n    }\n\n    // clear gradient defs on each .plot call, because we know we'll loop through all traces\n    Drawing.initGradients(gd);\n\n    // save initial show spikes once per graph\n    if(graphWasEmpty) Axes.saveShowSpikeInitial(gd);\n\n    // prepare the data and find the autorange\n\n    // generate calcdata, if we need to\n    // to force redoing calcdata, just delete it before calling Plotly.plot\n    var recalc = !gd.calcdata || gd.calcdata.length !== (gd._fullData || []).length;\n    if(recalc) Plots.doCalcdata(gd);\n\n    // in case it has changed, attach fullData traces to calcdata\n    for(var i = 0; i < gd.calcdata.length; i++) {\n        gd.calcdata[i][0].trace = gd._fullData[i];\n    }\n\n    // make the figure responsive\n    if(gd._context.responsive) {\n        if(!gd._responsiveChartHandler) {\n            // Keep a reference to the resize handler to purge it down the road\n            gd._responsiveChartHandler = function() { if(!Lib.isHidden(gd)) Plots.resize(gd); };\n\n            // Listen to window resize\n            window.addEventListener('resize', gd._responsiveChartHandler);\n        }\n    } else {\n        Lib.clearResponsive(gd);\n    }\n\n    /*\n     * start async-friendly code - now we're actually drawing things\n     */\n\n    var oldMargins = Lib.extendFlat({}, fullLayout._size);\n\n    // draw framework first so that margin-pushing\n    // components can position themselves correctly\n    var drawFrameworkCalls = 0;\n    function drawFramework() {\n        var basePlotModules = fullLayout._basePlotModules;\n\n        for(var i = 0; i < basePlotModules.length; i++) {\n            if(basePlotModules[i].drawFramework) {\n                basePlotModules[i].drawFramework(gd);\n            }\n        }\n\n        if(!fullLayout._glcanvas && fullLayout._has('gl')) {\n            fullLayout._glcanvas = fullLayout._glcontainer.selectAll('.gl-canvas').data([{\n                key: 'contextLayer',\n                context: true,\n                pick: false\n            }, {\n                key: 'focusLayer',\n                context: false,\n                pick: false\n            }, {\n                key: 'pickLayer',\n                context: false,\n                pick: true\n            }], function(d) { return d.key; });\n\n            fullLayout._glcanvas.enter().append('canvas')\n                .attr('class', function(d) {\n                    return 'gl-canvas gl-canvas-' + d.key.replace('Layer', '');\n                })\n                .style({\n                    position: 'absolute',\n                    top: 0,\n                    left: 0,\n                    overflow: 'visible',\n                    'pointer-events': 'none'\n                });\n        }\n\n        if(fullLayout._glcanvas) {\n            fullLayout._glcanvas\n                .attr('width', fullLayout.width)\n                .attr('height', fullLayout.height);\n\n            var regl = fullLayout._glcanvas.data()[0].regl;\n            if(regl) {\n                // Unfortunately, this can happen when relayouting to large\n                // width/height on some browsers.\n                if(Math.floor(fullLayout.width) !== regl._gl.drawingBufferWidth ||\n                    Math.floor(fullLayout.height) !== regl._gl.drawingBufferHeight\n                 ) {\n                    var msg = 'WebGL context buffer and canvas dimensions do not match due to browser/WebGL bug.';\n                    if(drawFrameworkCalls) {\n                        Lib.error(msg);\n                    } else {\n                        Lib.log(msg + ' Clearing graph and plotting again.');\n                        Plots.cleanPlot([], {}, gd._fullData, fullLayout);\n                        Plots.supplyDefaults(gd);\n                        fullLayout = gd._fullLayout;\n                        Plots.doCalcdata(gd);\n                        drawFrameworkCalls++;\n                        return drawFramework();\n                    }\n                }\n            }\n        }\n\n        if(fullLayout.modebar.orientation === 'h') {\n            fullLayout._modebardiv\n              .style('height', null)\n              .style('width', '100%');\n        } else {\n            fullLayout._modebardiv\n              .style('width', null)\n              .style('height', fullLayout.height + 'px');\n        }\n\n        return Plots.previousPromises(gd);\n    }\n\n    // draw anything that can affect margins.\n    function marginPushers() {\n        // First reset the list of things that are allowed to change the margins\n        // So any deleted traces or components will be wiped out of the\n        // automargin calculation.\n        // This means *every* margin pusher must be listed here, even if it\n        // doesn't actually try to push the margins until later.\n        Plots.clearAutoMarginIds(gd);\n\n        subroutines.drawMarginPushers(gd);\n        Axes.allowAutoMargin(gd);\n\n        Plots.doAutoMargin(gd);\n        return Plots.previousPromises(gd);\n    }\n\n    // in case the margins changed, draw margin pushers again\n    function marginPushersAgain() {\n        if(!Plots.didMarginChange(oldMargins, fullLayout._size)) return;\n\n        return Lib.syncOrAsync([\n            marginPushers,\n            subroutines.layoutStyles\n        ], gd);\n    }\n\n    function positionAndAutorange() {\n        if(!recalc) {\n            doAutoRangeAndConstraints();\n            return;\n        }\n\n        // TODO: autosize extra for text markers and images\n        // see https://github.com/plotly/plotly.js/issues/1111\n        return Lib.syncOrAsync([\n            Registry.getComponentMethod('shapes', 'calcAutorange'),\n            Registry.getComponentMethod('annotations', 'calcAutorange'),\n            doAutoRangeAndConstraints\n        ], gd);\n    }\n\n    function doAutoRangeAndConstraints() {\n        if(gd._transitioning) return;\n\n        subroutines.doAutoRangeAndConstraints(gd);\n\n        // store initial ranges *after* enforcing constraints, otherwise\n        // we will never look like we're at the initial ranges\n        if(graphWasEmpty) Axes.saveRangeInitial(gd);\n\n        // this one is different from shapes/annotations calcAutorange\n        // the others incorporate those components into ax._extremes,\n        // this one actually sets the ranges in rangesliders.\n        Registry.getComponentMethod('rangeslider', 'calcAutorange')(gd);\n    }\n\n    // draw ticks, titles, and calculate axis scaling (._b, ._m)\n    function drawAxes() {\n        return Axes.draw(gd, graphWasEmpty ? '' : 'redraw');\n    }\n\n    var seq = [\n        Plots.previousPromises,\n        addFrames,\n        drawFramework,\n        marginPushers,\n        marginPushersAgain\n    ];\n\n    if(hasCartesian) seq.push(positionAndAutorange);\n\n    seq.push(subroutines.layoutStyles);\n    if(hasCartesian) seq.push(drawAxes);\n\n    seq.push(\n        subroutines.drawData,\n        subroutines.finalDraw,\n        initInteractions,\n        Plots.addLinks,\n        Plots.rehover,\n        Plots.redrag,\n        // TODO: doAutoMargin is only needed here for axis automargin, which\n        // happens outside of marginPushers where all the other automargins are\n        // calculated. Would be much better to separate margin calculations from\n        // component drawing - see https://github.com/plotly/plotly.js/issues/2704\n        Plots.doAutoMargin,\n        Plots.previousPromises\n    );\n\n    // even if everything we did was synchronous, return a promise\n    // so that the caller doesn't care which route we took\n    var plotDone = Lib.syncOrAsync(seq, gd);\n    if(!plotDone || !plotDone.then) plotDone = Promise.resolve();\n\n    return plotDone.then(function() {\n        emitAfterPlot(gd);\n        return gd;\n    });\n}\n\nfunction emitAfterPlot(gd) {\n    var fullLayout = gd._fullLayout;\n\n    if(fullLayout._redrawFromAutoMarginCount) {\n        fullLayout._redrawFromAutoMarginCount--;\n    } else {\n        gd.emit('plotly_afterplot');\n    }\n}\n\nfunction setPlotConfig(obj) {\n    return Lib.extendFlat(dfltConfig, obj);\n}\n\nfunction setBackground(gd, bgColor) {\n    try {\n        gd._fullLayout._paper.style('background', bgColor);\n    } catch(e) {\n        Lib.error(e);\n    }\n}\n\nfunction opaqueSetBackground(gd, bgColor) {\n    var blend = Color.combine(bgColor, 'white');\n    setBackground(gd, blend);\n}\n\nfunction setPlotContext(gd, config) {\n    if(!gd._context) {\n        gd._context = Lib.extendDeep({}, dfltConfig);\n\n        // stash <base> href, used to make robust clipPath URLs\n        var base = d3.select('base');\n        gd._context._baseUrl = base.size() && base.attr('href') ?\n            window.location.href.split('#')[0] :\n            '';\n    }\n\n    var context = gd._context;\n\n    var i, keys, key;\n\n    if(config) {\n        keys = Object.keys(config);\n        for(i = 0; i < keys.length; i++) {\n            key = keys[i];\n            if(key === 'editable' || key === 'edits') continue;\n            if(key in context) {\n                if(key === 'setBackground' && config[key] === 'opaque') {\n                    context[key] = opaqueSetBackground;\n                } else {\n                    context[key] = config[key];\n                }\n            }\n        }\n\n        // map plot3dPixelRatio to plotGlPixelRatio for backward compatibility\n        if(config.plot3dPixelRatio && !context.plotGlPixelRatio) {\n            context.plotGlPixelRatio = context.plot3dPixelRatio;\n        }\n\n        // now deal with editable and edits - first editable overrides\n        // everything, then edits refines\n        var editable = config.editable;\n        if(editable !== undefined) {\n            // we're not going to *use* context.editable, we're only going to\n            // use context.edits... but keep it for the record\n            context.editable = editable;\n\n            keys = Object.keys(context.edits);\n            for(i = 0; i < keys.length; i++) {\n                context.edits[keys[i]] = editable;\n            }\n        }\n        if(config.edits) {\n            keys = Object.keys(config.edits);\n            for(i = 0; i < keys.length; i++) {\n                key = keys[i];\n                if(key in context.edits) {\n                    context.edits[key] = config.edits[key];\n                }\n            }\n        }\n\n        // not part of the user-facing config options\n        context._exportedPlot = config._exportedPlot;\n    }\n\n    // staticPlot forces a bunch of others:\n    if(context.staticPlot) {\n        context.editable = false;\n        context.edits = {};\n        context.autosizable = false;\n        context.scrollZoom = false;\n        context.doubleClick = false;\n        context.showTips = false;\n        context.showLink = false;\n        context.displayModeBar = false;\n    }\n\n    // make sure hover-only devices have mode bar visible\n    if(context.displayModeBar === 'hover' && !hasHover) {\n        context.displayModeBar = true;\n    }\n\n    // default and fallback for setBackground\n    if(context.setBackground === 'transparent' || typeof context.setBackground !== 'function') {\n        context.setBackground = setBackground;\n    }\n\n    // Check if gd has a specified widht/height to begin with\n    context._hasZeroHeight = context._hasZeroHeight || gd.clientHeight === 0;\n    context._hasZeroWidth = context._hasZeroWidth || gd.clientWidth === 0;\n\n    // fill context._scrollZoom helper to help manage scrollZoom flaglist\n    var szIn = context.scrollZoom;\n    var szOut = context._scrollZoom = {};\n    if(szIn === true) {\n        szOut.cartesian = 1;\n        szOut.gl3d = 1;\n        szOut.geo = 1;\n        szOut.mapbox = 1;\n    } else if(typeof szIn === 'string') {\n        var parts = szIn.split('+');\n        for(i = 0; i < parts.length; i++) {\n            szOut[parts[i]] = 1;\n        }\n    } else if(szIn !== false) {\n        szOut.gl3d = 1;\n        szOut.geo = 1;\n        szOut.mapbox = 1;\n    }\n}\n\nfunction plotLegacyPolar(gd, data, layout) {\n    // build or reuse the container skeleton\n    var plotContainer = d3.select(gd).selectAll('.plot-container')\n        .data([0]);\n    plotContainer.enter()\n        .insert('div', ':first-child')\n        .classed('plot-container plotly', true);\n    var paperDiv = plotContainer.selectAll('.svg-container')\n        .data([0]);\n    paperDiv.enter().append('div')\n        .classed('svg-container', true)\n        .style('position', 'relative');\n\n    // empty it everytime for now\n    paperDiv.html('');\n\n    // fulfill gd requirements\n    if(data) gd.data = data;\n    if(layout) gd.layout = layout;\n    Polar.manager.fillLayout(gd);\n\n    // resize canvas\n    paperDiv.style({\n        width: gd._fullLayout.width + 'px',\n        height: gd._fullLayout.height + 'px'\n    });\n\n    // instantiate framework\n    gd.framework = Polar.manager.framework(gd);\n\n    // plot\n    gd.framework({data: gd.data, layout: gd.layout}, paperDiv.node());\n\n    // set undo point\n    gd.framework.setUndoPoint();\n\n    // get the resulting svg for extending it\n    var polarPlotSVG = gd.framework.svg();\n\n    // editable title\n    var opacity = 1;\n    var txt = gd._fullLayout.title ? gd._fullLayout.title.text : '';\n    if(txt === '' || !txt) opacity = 0;\n\n    var titleLayout = function() {\n        this.call(svgTextUtils.convertToTspans, gd);\n        // TODO: html/mathjax\n        // TODO: center title\n    };\n\n    var title = polarPlotSVG.select('.title-group text')\n        .call(titleLayout);\n\n    if(gd._context.edits.titleText) {\n        var placeholderText = Lib._(gd, 'Click to enter Plot title');\n        if(!txt || txt === placeholderText) {\n            opacity = 0.2;\n            // placeholder is not going through convertToTspans\n            // so needs explicit data-unformatted\n            title.attr({'data-unformatted': placeholderText})\n                .text(placeholderText)\n                .style({opacity: opacity})\n                .on('mouseover.opacity', function() {\n                    d3.select(this).transition().duration(100)\n                        .style('opacity', 1);\n                })\n                .on('mouseout.opacity', function() {\n                    d3.select(this).transition().duration(1000)\n                        .style('opacity', 0);\n                });\n        }\n\n        var setContenteditable = function() {\n            this.call(svgTextUtils.makeEditable, {gd: gd})\n                .on('edit', function(text) {\n                    gd.framework({layout: {title: {text: text}}});\n                    this.text(text)\n                        .call(titleLayout);\n                    this.call(setContenteditable);\n                })\n                .on('cancel', function() {\n                    var txt = this.attr('data-unformatted');\n                    this.text(txt).call(titleLayout);\n                });\n        };\n        title.call(setContenteditable);\n    }\n\n    gd._context.setBackground(gd, gd._fullLayout.paper_bgcolor);\n    Plots.addLinks(gd);\n\n    return Promise.resolve();\n}\n\n// convenience function to force a full redraw, mostly for use by plotly.js\nfunction redraw(gd) {\n    gd = Lib.getGraphDiv(gd);\n\n    if(!Lib.isPlotDiv(gd)) {\n        throw new Error('This element is not a Plotly plot: ' + gd);\n    }\n\n    helpers.cleanData(gd.data);\n    helpers.cleanLayout(gd.layout);\n\n    gd.calcdata = undefined;\n    return exports.plot(gd).then(function() {\n        gd.emit('plotly_redraw');\n        return gd;\n    });\n}\n\n/**\n * Convenience function to make idempotent plot option obvious to users.\n *\n * @param gd\n * @param {Object[]} data\n * @param {Object} layout\n * @param {Object} config\n */\nfunction newPlot(gd, data, layout, config) {\n    gd = Lib.getGraphDiv(gd);\n\n    // remove gl contexts\n    Plots.cleanPlot([], {}, gd._fullData || [], gd._fullLayout || {});\n\n    Plots.purge(gd);\n    return exports.plot(gd, data, layout, config);\n}\n\n/**\n * Wrap negative indicies to their positive counterparts.\n *\n * @param {Number[]} indices An array of indices\n * @param {Number} maxIndex The maximum index allowable (arr.length - 1)\n */\nfunction positivifyIndices(indices, maxIndex) {\n    var parentLength = maxIndex + 1;\n    var positiveIndices = [];\n    var i;\n    var index;\n\n    for(i = 0; i < indices.length; i++) {\n        index = indices[i];\n        if(index < 0) {\n            positiveIndices.push(parentLength + index);\n        } else {\n            positiveIndices.push(index);\n        }\n    }\n    return positiveIndices;\n}\n\n/**\n * Ensures that an index array for manipulating gd.data is valid.\n *\n * Intended for use with addTraces, deleteTraces, and moveTraces.\n *\n * @param gd\n * @param indices\n * @param arrayName\n */\nfunction assertIndexArray(gd, indices, arrayName) {\n    var i,\n        index;\n\n    for(i = 0; i < indices.length; i++) {\n        index = indices[i];\n\n        // validate that indices are indeed integers\n        if(index !== parseInt(index, 10)) {\n            throw new Error('all values in ' + arrayName + ' must be integers');\n        }\n\n        // check that all indices are in bounds for given gd.data array length\n        if(index >= gd.data.length || index < -gd.data.length) {\n            throw new Error(arrayName + ' must be valid indices for gd.data.');\n        }\n\n        // check that indices aren't repeated\n        if(indices.indexOf(index, i + 1) > -1 ||\n                index >= 0 && indices.indexOf(-gd.data.length + index) > -1 ||\n                index < 0 && indices.indexOf(gd.data.length + index) > -1) {\n            throw new Error('each index in ' + arrayName + ' must be unique.');\n        }\n    }\n}\n\n/**\n * Private function used by Plotly.moveTraces to check input args\n *\n * @param gd\n * @param currentIndices\n * @param newIndices\n */\nfunction checkMoveTracesArgs(gd, currentIndices, newIndices) {\n    // check that gd has attribute 'data' and 'data' is array\n    if(!Array.isArray(gd.data)) {\n        throw new Error('gd.data must be an array.');\n    }\n\n    // validate currentIndices array\n    if(typeof currentIndices === 'undefined') {\n        throw new Error('currentIndices is a required argument.');\n    } else if(!Array.isArray(currentIndices)) {\n        currentIndices = [currentIndices];\n    }\n    assertIndexArray(gd, currentIndices, 'currentIndices');\n\n    // validate newIndices array if it exists\n    if(typeof newIndices !== 'undefined' && !Array.isArray(newIndices)) {\n        newIndices = [newIndices];\n    }\n    if(typeof newIndices !== 'undefined') {\n        assertIndexArray(gd, newIndices, 'newIndices');\n    }\n\n    // check currentIndices and newIndices are the same length if newIdices exists\n    if(typeof newIndices !== 'undefined' && currentIndices.length !== newIndices.length) {\n        throw new Error('current and new indices must be of equal length.');\n    }\n}\n/**\n * A private function to reduce the type checking clutter in addTraces.\n *\n * @param gd\n * @param traces\n * @param newIndices\n */\nfunction checkAddTracesArgs(gd, traces, newIndices) {\n    var i, value;\n\n    // check that gd has attribute 'data' and 'data' is array\n    if(!Array.isArray(gd.data)) {\n        throw new Error('gd.data must be an array.');\n    }\n\n    // make sure traces exists\n    if(typeof traces === 'undefined') {\n        throw new Error('traces must be defined.');\n    }\n\n    // make sure traces is an array\n    if(!Array.isArray(traces)) {\n        traces = [traces];\n    }\n\n    // make sure each value in traces is an object\n    for(i = 0; i < traces.length; i++) {\n        value = traces[i];\n        if(typeof value !== 'object' || (Array.isArray(value) || value === null)) {\n            throw new Error('all values in traces array must be non-array objects');\n        }\n    }\n\n    // make sure we have an index for each trace\n    if(typeof newIndices !== 'undefined' && !Array.isArray(newIndices)) {\n        newIndices = [newIndices];\n    }\n    if(typeof newIndices !== 'undefined' && newIndices.length !== traces.length) {\n        throw new Error(\n            'if indices is specified, traces.length must equal indices.length'\n        );\n    }\n}\n\n/**\n * A private function to reduce the type checking clutter in spliceTraces.\n * Get all update Properties from gd.data. Validate inputs and outputs.\n * Used by prependTrace and extendTraces\n *\n * @param gd\n * @param update\n * @param indices\n * @param maxPoints\n */\nfunction assertExtendTracesArgs(gd, update, indices, maxPoints) {\n    var maxPointsIsObject = Lib.isPlainObject(maxPoints);\n\n    if(!Array.isArray(gd.data)) {\n        throw new Error('gd.data must be an array');\n    }\n    if(!Lib.isPlainObject(update)) {\n        throw new Error('update must be a key:value object');\n    }\n\n    if(typeof indices === 'undefined') {\n        throw new Error('indices must be an integer or array of integers');\n    }\n\n    assertIndexArray(gd, indices, 'indices');\n\n    for(var key in update) {\n        /*\n         * Verify that the attribute to be updated contains as many trace updates\n         * as indices. Failure must result in throw and no-op\n         */\n        if(!Array.isArray(update[key]) || update[key].length !== indices.length) {\n            throw new Error('attribute ' + key + ' must be an array of length equal to indices array length');\n        }\n\n        /*\n         * if maxPoints is an object it must match keys and array lengths of 'update' 1:1\n         */\n        if(maxPointsIsObject &&\n            (!(key in maxPoints) || !Array.isArray(maxPoints[key]) ||\n            maxPoints[key].length !== update[key].length)) {\n            throw new Error('when maxPoints is set as a key:value object it must contain a 1:1 ' +\n                            'corrispondence with the keys and number of traces in the update object');\n        }\n    }\n}\n\n/**\n * A private function to reduce the type checking clutter in spliceTraces.\n *\n * @param {Object|HTMLDivElement} gd\n * @param {Object} update\n * @param {Number[]} indices\n * @param {Number||Object} maxPoints\n * @return {Object[]}\n */\nfunction getExtendProperties(gd, update, indices, maxPoints) {\n    var maxPointsIsObject = Lib.isPlainObject(maxPoints);\n    var updateProps = [];\n    var trace, target, prop, insert, maxp;\n\n    // allow scalar index to represent a single trace position\n    if(!Array.isArray(indices)) indices = [indices];\n\n    // negative indices are wrapped around to their positive value. Equivalent to python indexing.\n    indices = positivifyIndices(indices, gd.data.length - 1);\n\n    // loop through all update keys and traces and harvest validated data.\n    for(var key in update) {\n        for(var j = 0; j < indices.length; j++) {\n            /*\n             * Choose the trace indexed by the indices map argument and get the prop setter-getter\n             * instance that references the key and value for this particular trace.\n             */\n            trace = gd.data[indices[j]];\n            prop = nestedProperty(trace, key);\n\n            /*\n             * Target is the existing gd.data.trace.dataArray value like \"x\" or \"marker.size\"\n             * Target must exist as an Array to allow the extend operation to be performed.\n             */\n            target = prop.get();\n            insert = update[key][j];\n\n            if(!Lib.isArrayOrTypedArray(insert)) {\n                throw new Error('attribute: ' + key + ' index: ' + j + ' must be an array');\n            }\n            if(!Lib.isArrayOrTypedArray(target)) {\n                throw new Error('cannot extend missing or non-array attribute: ' + key);\n            }\n            if(target.constructor !== insert.constructor) {\n                throw new Error('cannot extend array with an array of a different type: ' + key);\n            }\n\n            /*\n             * maxPoints may be an object map or a scalar. If object select the key:value, else\n             * Use the scalar maxPoints for all key and trace combinations.\n             */\n            maxp = maxPointsIsObject ? maxPoints[key][j] : maxPoints;\n\n            // could have chosen null here, -1 just tells us to not take a window\n            if(!isNumeric(maxp)) maxp = -1;\n\n            /*\n             * Wrap the nestedProperty in an object containing required data\n             * for lengthening and windowing this particular trace - key combination.\n             * Flooring maxp mirrors the behaviour of floats in the Array.slice JSnative function.\n             */\n            updateProps.push({\n                prop: prop,\n                target: target,\n                insert: insert,\n                maxp: Math.floor(maxp)\n            });\n        }\n    }\n\n    // all target and insertion data now validated\n    return updateProps;\n}\n\n/**\n * A private function to key Extend and Prepend traces DRY\n *\n * @param {Object|HTMLDivElement} gd\n * @param {Object} update\n * @param {Number[]} indices\n * @param {Number||Object} maxPoints\n * @param {Function} updateArray\n * @return {Object}\n */\nfunction spliceTraces(gd, update, indices, maxPoints, updateArray) {\n    assertExtendTracesArgs(gd, update, indices, maxPoints);\n\n    var updateProps = getExtendProperties(gd, update, indices, maxPoints);\n    var undoUpdate = {};\n    var undoPoints = {};\n\n    for(var i = 0; i < updateProps.length; i++) {\n        var prop = updateProps[i].prop;\n        var maxp = updateProps[i].maxp;\n\n        // return new array and remainder\n        var out = updateArray(updateProps[i].target, updateProps[i].insert, maxp);\n        prop.set(out[0]);\n\n        // build the inverse update object for the undo operation\n        if(!Array.isArray(undoUpdate[prop.astr])) undoUpdate[prop.astr] = [];\n        undoUpdate[prop.astr].push(out[1]);\n\n         // build the matching maxPoints undo object containing original trace lengths\n        if(!Array.isArray(undoPoints[prop.astr])) undoPoints[prop.astr] = [];\n        undoPoints[prop.astr].push(updateProps[i].target.length);\n    }\n\n    return {update: undoUpdate, maxPoints: undoPoints};\n}\n\nfunction concatTypedArray(arr0, arr1) {\n    var arr2 = new arr0.constructor(arr0.length + arr1.length);\n    arr2.set(arr0);\n    arr2.set(arr1, arr0.length);\n    return arr2;\n}\n\n/**\n * extend && prepend traces at indices with update arrays, window trace lengths to maxPoints\n *\n * Extend and Prepend have identical APIs. Prepend inserts an array at the head while Extend\n * inserts an array off the tail. Prepend truncates the tail of the array - counting maxPoints\n * from the head, whereas Extend truncates the head of the array, counting backward maxPoints\n * from the tail.\n *\n * If maxPoints is undefined, nonNumeric, negative or greater than extended trace length no\n * truncation / windowing will be performed. If its zero, well the whole trace is truncated.\n *\n * @param {Object|HTMLDivElement} gd The graph div\n * @param {Object} update The key:array map of target attributes to extend\n * @param {Number|Number[]} indices The locations of traces to be extended\n * @param {Number|Object} [maxPoints] Number of points for trace window after lengthening.\n *\n */\nfunction extendTraces(gd, update, indices, maxPoints) {\n    gd = Lib.getGraphDiv(gd);\n\n    function updateArray(target, insert, maxp) {\n        var newArray, remainder;\n\n        if(Lib.isTypedArray(target)) {\n            if(maxp < 0) {\n                var none = new target.constructor(0);\n                var both = concatTypedArray(target, insert);\n\n                if(maxp < 0) {\n                    newArray = both;\n                    remainder = none;\n                } else {\n                    newArray = none;\n                    remainder = both;\n                }\n            } else {\n                newArray = new target.constructor(maxp);\n                remainder = new target.constructor(target.length + insert.length - maxp);\n\n                if(maxp === insert.length) {\n                    newArray.set(insert);\n                    remainder.set(target);\n                } else if(maxp < insert.length) {\n                    var numberOfItemsFromInsert = insert.length - maxp;\n\n                    newArray.set(insert.subarray(numberOfItemsFromInsert));\n                    remainder.set(target);\n                    remainder.set(insert.subarray(0, numberOfItemsFromInsert), target.length);\n                } else {\n                    var numberOfItemsFromTarget = maxp - insert.length;\n                    var targetBegin = target.length - numberOfItemsFromTarget;\n\n                    newArray.set(target.subarray(targetBegin));\n                    newArray.set(insert, numberOfItemsFromTarget);\n                    remainder.set(target.subarray(0, targetBegin));\n                }\n            }\n        } else {\n            newArray = target.concat(insert);\n            remainder = (maxp >= 0 && maxp < newArray.length) ?\n                newArray.splice(0, newArray.length - maxp) :\n                [];\n        }\n\n        return [newArray, remainder];\n    }\n\n    var undo = spliceTraces(gd, update, indices, maxPoints, updateArray);\n    var promise = exports.redraw(gd);\n    var undoArgs = [gd, undo.update, indices, undo.maxPoints];\n    Queue.add(gd, exports.prependTraces, undoArgs, extendTraces, arguments);\n\n    return promise;\n}\n\nfunction prependTraces(gd, update, indices, maxPoints) {\n    gd = Lib.getGraphDiv(gd);\n\n    function updateArray(target, insert, maxp) {\n        var newArray, remainder;\n\n        if(Lib.isTypedArray(target)) {\n            if(maxp <= 0) {\n                var none = new target.constructor(0);\n                var both = concatTypedArray(insert, target);\n\n                if(maxp < 0) {\n                    newArray = both;\n                    remainder = none;\n                } else {\n                    newArray = none;\n                    remainder = both;\n                }\n            } else {\n                newArray = new target.constructor(maxp);\n                remainder = new target.constructor(target.length + insert.length - maxp);\n\n                if(maxp === insert.length) {\n                    newArray.set(insert);\n                    remainder.set(target);\n                } else if(maxp < insert.length) {\n                    var numberOfItemsFromInsert = insert.length - maxp;\n\n                    newArray.set(insert.subarray(0, numberOfItemsFromInsert));\n                    remainder.set(insert.subarray(numberOfItemsFromInsert));\n                    remainder.set(target, numberOfItemsFromInsert);\n                } else {\n                    var numberOfItemsFromTarget = maxp - insert.length;\n\n                    newArray.set(insert);\n                    newArray.set(target.subarray(0, numberOfItemsFromTarget), insert.length);\n                    remainder.set(target.subarray(numberOfItemsFromTarget));\n                }\n            }\n        } else {\n            newArray = insert.concat(target);\n            remainder = (maxp >= 0 && maxp < newArray.length) ?\n                newArray.splice(maxp, newArray.length) :\n                [];\n        }\n\n        return [newArray, remainder];\n    }\n\n    var undo = spliceTraces(gd, update, indices, maxPoints, updateArray);\n    var promise = exports.redraw(gd);\n    var undoArgs = [gd, undo.update, indices, undo.maxPoints];\n    Queue.add(gd, exports.extendTraces, undoArgs, prependTraces, arguments);\n\n    return promise;\n}\n\n/**\n * Add data traces to an existing graph div.\n *\n * @param {Object|HTMLDivElement} gd The graph div\n * @param {Object[]} gd.data The array of traces we're adding to\n * @param {Object[]|Object} traces The object or array of objects to add\n * @param {Number[]|Number} [newIndices=[gd.data.length]] Locations to add traces\n *\n */\nfunction addTraces(gd, traces, newIndices) {\n    gd = Lib.getGraphDiv(gd);\n\n    var currentIndices = [];\n    var undoFunc = exports.deleteTraces;\n    var redoFunc = addTraces;\n    var undoArgs = [gd, currentIndices];\n    var redoArgs = [gd, traces];  // no newIndices here\n    var i;\n    var promise;\n\n    // all validation is done elsewhere to remove clutter here\n    checkAddTracesArgs(gd, traces, newIndices);\n\n    // make sure traces is an array\n    if(!Array.isArray(traces)) {\n        traces = [traces];\n    }\n\n    // make sure traces do not repeat existing ones\n    traces = traces.map(function(trace) {\n        return Lib.extendFlat({}, trace);\n    });\n\n    helpers.cleanData(traces);\n\n    // add the traces to gd.data (no redrawing yet!)\n    for(i = 0; i < traces.length; i++) {\n        gd.data.push(traces[i]);\n    }\n\n    // to continue, we need to call moveTraces which requires currentIndices\n    for(i = 0; i < traces.length; i++) {\n        currentIndices.push(-traces.length + i);\n    }\n\n    // if the user didn't define newIndices, they just want the traces appended\n    // i.e., we can simply redraw and be done\n    if(typeof newIndices === 'undefined') {\n        promise = exports.redraw(gd);\n        Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);\n        return promise;\n    }\n\n    // make sure indices is property defined\n    if(!Array.isArray(newIndices)) {\n        newIndices = [newIndices];\n    }\n\n    try {\n        // this is redundant, but necessary to not catch later possible errors!\n        checkMoveTracesArgs(gd, currentIndices, newIndices);\n    } catch(error) {\n        // something went wrong, reset gd to be safe and rethrow error\n        gd.data.splice(gd.data.length - traces.length, traces.length);\n        throw error;\n    }\n\n    // if we're here, the user has defined specific places to place the new traces\n    // this requires some extra work that moveTraces will do\n    Queue.startSequence(gd);\n    Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);\n    promise = exports.moveTraces(gd, currentIndices, newIndices);\n    Queue.stopSequence(gd);\n    return promise;\n}\n\n/**\n * Delete traces at `indices` from gd.data array.\n *\n * @param {Object|HTMLDivElement} gd The graph div\n * @param {Object[]} gd.data The array of traces we're removing from\n * @param {Number|Number[]} indices The indices\n */\nfunction deleteTraces(gd, indices) {\n    gd = Lib.getGraphDiv(gd);\n\n    var traces = [];\n    var undoFunc = exports.addTraces;\n    var redoFunc = deleteTraces;\n    var undoArgs = [gd, traces, indices];\n    var redoArgs = [gd, indices];\n    var i;\n    var deletedTrace;\n\n    // make sure indices are defined\n    if(typeof indices === 'undefined') {\n        throw new Error('indices must be an integer or array of integers.');\n    } else if(!Array.isArray(indices)) {\n        indices = [indices];\n    }\n    assertIndexArray(gd, indices, 'indices');\n\n    // convert negative indices to positive indices\n    indices = positivifyIndices(indices, gd.data.length - 1);\n\n    // we want descending here so that splicing later doesn't affect indexing\n    indices.sort(Lib.sorterDes);\n    for(i = 0; i < indices.length; i += 1) {\n        deletedTrace = gd.data.splice(indices[i], 1)[0];\n        traces.push(deletedTrace);\n    }\n\n    var promise = exports.redraw(gd);\n    Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);\n\n    return promise;\n}\n\n/**\n * Move traces at currentIndices array to locations in newIndices array.\n *\n * If newIndices is omitted, currentIndices will be moved to the end. E.g.,\n * these are equivalent:\n *\n * Plotly.moveTraces(gd, [1, 2, 3], [-3, -2, -1])\n * Plotly.moveTraces(gd, [1, 2, 3])\n *\n * @param {Object|HTMLDivElement} gd The graph div\n * @param {Object[]} gd.data The array of traces we're removing from\n * @param {Number|Number[]} currentIndices The locations of traces to be moved\n * @param {Number|Number[]} [newIndices] The locations to move traces to\n *\n * Example calls:\n *\n *      // move trace i to location x\n *      Plotly.moveTraces(gd, i, x)\n *\n *      // move trace i to end of array\n *      Plotly.moveTraces(gd, i)\n *\n *      // move traces i, j, k to end of array (i != j != k)\n *      Plotly.moveTraces(gd, [i, j, k])\n *\n *      // move traces [i, j, k] to [x, y, z] (i != j != k) (x != y != z)\n *      Plotly.moveTraces(gd, [i, j, k], [x, y, z])\n *\n *      // reorder all traces (assume there are 5--a, b, c, d, e)\n *      Plotly.moveTraces(gd, [b, d, e, a, c])  // same as 'move to end'\n */\nfunction moveTraces(gd, currentIndices, newIndices) {\n    gd = Lib.getGraphDiv(gd);\n\n    var newData = [];\n    var movingTraceMap = [];\n    var undoFunc = moveTraces;\n    var redoFunc = moveTraces;\n    var undoArgs = [gd, newIndices, currentIndices];\n    var redoArgs = [gd, currentIndices, newIndices];\n    var i;\n\n    // to reduce complexity here, check args elsewhere\n    // this throws errors where appropriate\n    checkMoveTracesArgs(gd, currentIndices, newIndices);\n\n    // make sure currentIndices is an array\n    currentIndices = Array.isArray(currentIndices) ? currentIndices : [currentIndices];\n\n    // if undefined, define newIndices to point to the end of gd.data array\n    if(typeof newIndices === 'undefined') {\n        newIndices = [];\n        for(i = 0; i < currentIndices.length; i++) {\n            newIndices.push(-currentIndices.length + i);\n        }\n    }\n\n    // make sure newIndices is an array if it's user-defined\n    newIndices = Array.isArray(newIndices) ? newIndices : [newIndices];\n\n    // convert negative indices to positive indices (they're the same length)\n    currentIndices = positivifyIndices(currentIndices, gd.data.length - 1);\n    newIndices = positivifyIndices(newIndices, gd.data.length - 1);\n\n    // at this point, we've coerced the index arrays into predictable forms\n\n    // get the traces that aren't being moved around\n    for(i = 0; i < gd.data.length; i++) {\n        // if index isn't in currentIndices, include it in ignored!\n        if(currentIndices.indexOf(i) === -1) {\n            newData.push(gd.data[i]);\n        }\n    }\n\n    // get a mapping of indices to moving traces\n    for(i = 0; i < currentIndices.length; i++) {\n        movingTraceMap.push({newIndex: newIndices[i], trace: gd.data[currentIndices[i]]});\n    }\n\n    // reorder this mapping by newIndex, ascending\n    movingTraceMap.sort(function(a, b) {\n        return a.newIndex - b.newIndex;\n    });\n\n    // now, add the moving traces back in, in order!\n    for(i = 0; i < movingTraceMap.length; i += 1) {\n        newData.splice(movingTraceMap[i].newIndex, 0, movingTraceMap[i].trace);\n    }\n\n    gd.data = newData;\n\n    var promise = exports.redraw(gd);\n    Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);\n\n    return promise;\n}\n\n/**\n * restyle: update trace attributes of an existing plot\n *\n * Can be called two ways.\n *\n * Signature 1:\n * @param {String | HTMLDivElement} gd\n *  the id or DOM element of the graph container div\n * @param {String} astr\n *  attribute string (like `'marker.symbol'`) to update\n * @param {*} val\n *  value to give this attribute\n * @param {Number[] | Number} [traces]\n *  integer or array of integers for the traces to alter (all if omitted)\n *\n * Signature 2:\n * @param {String | HTMLDivElement} gd\n *  (as in signature 1)\n * @param {Object} aobj\n *  attribute object `{astr1: val1, astr2: val2 ...}`\n *  allows setting multiple attributes simultaneously\n * @param {Number[] | Number} [traces]\n *  (as in signature 1)\n *\n * `val` (or `val1`, `val2` ... in the object form) can be an array,\n * to apply different values to each trace.\n *\n * If the array is too short, it will wrap around (useful for\n * style files that want to specify cyclical default values).\n */\nfunction restyle(gd, astr, val, _traces) {\n    gd = Lib.getGraphDiv(gd);\n    helpers.clearPromiseQueue(gd);\n\n    var aobj = {};\n    if(typeof astr === 'string') aobj[astr] = val;\n    else if(Lib.isPlainObject(astr)) {\n        // the 3-arg form\n        aobj = Lib.extendFlat({}, astr);\n        if(_traces === undefined) _traces = val;\n    } else {\n        Lib.warn('Restyle fail.', astr, val, _traces);\n        return Promise.reject();\n    }\n\n    if(Object.keys(aobj).length) gd.changed = true;\n\n    var traces = helpers.coerceTraceIndices(gd, _traces);\n\n    var specs = _restyle(gd, aobj, traces);\n    var flags = specs.flags;\n\n    // clear calcdata and/or axis types if required so they get regenerated\n    if(flags.calc) gd.calcdata = undefined;\n    if(flags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, {});\n\n    // fill in redraw sequence\n    var seq = [];\n\n    if(flags.fullReplot) {\n        seq.push(exports.plot);\n    } else {\n        seq.push(Plots.previousPromises);\n\n        // maybe only call Plots.supplyDataDefaults in the splom case,\n        // to skip over long and slow axes defaults\n        Plots.supplyDefaults(gd);\n\n        if(flags.markerSize) {\n            Plots.doCalcdata(gd);\n            addAxRangeSequence(seq);\n\n            // TODO\n            // if all axes have autorange:false, then\n            // proceed to subroutines.doTraceStyle(),\n            // otherwise we must go through addAxRangeSequence,\n            // which in general must redraws 'all' axes\n        }\n\n        if(flags.style) seq.push(subroutines.doTraceStyle);\n        if(flags.colorbars) seq.push(subroutines.doColorBars);\n\n        seq.push(emitAfterPlot);\n    }\n\n    seq.push(Plots.rehover, Plots.redrag);\n\n    Queue.add(gd,\n        restyle, [gd, specs.undoit, specs.traces],\n        restyle, [gd, specs.redoit, specs.traces]\n    );\n\n    var plotDone = Lib.syncOrAsync(seq, gd);\n    if(!plotDone || !plotDone.then) plotDone = Promise.resolve();\n\n    return plotDone.then(function() {\n        gd.emit('plotly_restyle', specs.eventData);\n        return gd;\n    });\n}\n\n// for undo: undefined initial vals must be turned into nulls\n// so that we unset rather than ignore them\nfunction undefinedToNull(val) {\n    if(val === undefined) return null;\n    return val;\n}\n\n/**\n * Factory function to wrap nestedProperty with GUI edits if necessary\n * with GUI edits we add an optional prefix to the nestedProperty constructor\n * to prepend to the attribute string in the preGUI store.\n */\nfunction makeNP(preGUI, guiEditFlag) {\n    if(!guiEditFlag) return nestedProperty;\n\n    return function(container, attr, prefix) {\n        var np = nestedProperty(container, attr);\n        var npSet = np.set;\n        np.set = function(val) {\n            var fullAttr = (prefix || '') + attr;\n            storeCurrent(fullAttr, np.get(), val, preGUI);\n            npSet(val);\n        };\n        return np;\n    };\n}\n\nfunction storeCurrent(attr, val, newVal, preGUI) {\n    if(Array.isArray(val) || Array.isArray(newVal)) {\n        var arrayVal = Array.isArray(val) ? val : [];\n        var arrayNew = Array.isArray(newVal) ? newVal : [];\n        var maxLen = Math.max(arrayVal.length, arrayNew.length);\n        for(var i = 0; i < maxLen; i++) {\n            storeCurrent(attr + '[' + i + ']', arrayVal[i], arrayNew[i], preGUI);\n        }\n    } else if(Lib.isPlainObject(val) || Lib.isPlainObject(newVal)) {\n        var objVal = Lib.isPlainObject(val) ? val : {};\n        var objNew = Lib.isPlainObject(newVal) ? newVal : {};\n        var objBoth = Lib.extendFlat({}, objVal, objNew);\n        for(var key in objBoth) {\n            storeCurrent(attr + '.' + key, objVal[key], objNew[key], preGUI);\n        }\n    } else if(preGUI[attr] === undefined) {\n        preGUI[attr] = undefinedToNull(val);\n    }\n}\n\n/**\n * storeDirectGUIEdit: for routines that skip restyle/relayout and mock it\n * by emitting a plotly_restyle or plotly_relayout event, this routine\n * keeps track of the initial state in _preGUI for use by uirevision\n * Does *not* apply these changes to data/layout - that's the responsibility\n * of the calling routine.\n *\n * @param {object} container: the input attributes container (eg `layout` or a `trace`)\n * @param {object} preGUI: where original values should be stored, either\n *     `layout._preGUI` or `layout._tracePreGUI[uid]`\n * @param {object} edits: the {attr: val} object as normally passed to `relayout` etc\n */\nfunction _storeDirectGUIEdit(container, preGUI, edits) {\n    for(var attr in edits) {\n        var np = nestedProperty(container, attr);\n        storeCurrent(attr, np.get(), edits[attr], preGUI);\n    }\n}\n\nfunction _restyle(gd, aobj, traces) {\n    var fullLayout = gd._fullLayout;\n    var fullData = gd._fullData;\n    var data = gd.data;\n    var guiEditFlag = fullLayout._guiEditing;\n    var layoutNP = makeNP(fullLayout._preGUI, guiEditFlag);\n    var eventData = Lib.extendDeepAll({}, aobj);\n    var i;\n\n    cleanDeprecatedAttributeKeys(aobj);\n\n    // initialize flags\n    var flags = editTypes.traceFlags();\n\n    // copies of the change (and previous values of anything affected)\n    // for the undo / redo queue\n    var redoit = {};\n    var undoit = {};\n    var axlist;\n\n    // make a new empty vals array for undoit\n    function a0() { return traces.map(function() { return undefined; }); }\n\n    // for autoranging multiple axes\n    function addToAxlist(axid) {\n        var axName = Axes.id2name(axid);\n        if(axlist.indexOf(axName) === -1) axlist.push(axName);\n    }\n\n    function autorangeAttr(axName) { return 'LAYOUT' + axName + '.autorange'; }\n\n    function rangeAttr(axName) { return 'LAYOUT' + axName + '.range'; }\n\n    function getFullTrace(traceIndex) {\n        // usually fullData maps 1:1 onto data, but with groupby transforms\n        // the fullData index can be greater. Take the *first* matching trace.\n        for(var j = traceIndex; j < fullData.length; j++) {\n            if(fullData[j]._input === data[traceIndex]) return fullData[j];\n        }\n        // should never get here - and if we *do* it should cause an error\n        // later on undefined fullTrace is passed to nestedProperty.\n    }\n\n    // for attrs that interact (like scales & autoscales), save the\n    // old vals before making the change\n    // val=undefined will not set a value, just record what the value was.\n    // val=null will delete the attribute\n    // attr can be an array to set several at once (all to the same val)\n    function doextra(attr, val, i) {\n        if(Array.isArray(attr)) {\n            attr.forEach(function(a) { doextra(a, val, i); });\n            return;\n        }\n        // quit if explicitly setting this elsewhere\n        if(attr in aobj || helpers.hasParent(aobj, attr)) return;\n\n        var extraparam;\n        if(attr.substr(0, 6) === 'LAYOUT') {\n            extraparam = layoutNP(gd.layout, attr.replace('LAYOUT', ''));\n        } else {\n            var tracei = traces[i];\n            var preGUI = fullLayout._tracePreGUI[getFullTrace(tracei)._fullInput.uid];\n            extraparam = makeNP(preGUI, guiEditFlag)(data[tracei], attr);\n        }\n\n        if(!(attr in undoit)) {\n            undoit[attr] = a0();\n        }\n        if(undoit[attr][i] === undefined) {\n            undoit[attr][i] = undefinedToNull(extraparam.get());\n        }\n        if(val !== undefined) {\n            extraparam.set(val);\n        }\n    }\n\n    function allBins(binAttr) {\n        return function(j) {\n            return fullData[j][binAttr];\n        };\n    }\n\n    function arrayBins(binAttr) {\n        return function(vij, j) {\n            return vij === false ? fullData[traces[j]][binAttr] : null;\n        };\n    }\n\n    // now make the changes to gd.data (and occasionally gd.layout)\n    // and figure out what kind of graphics update we need to do\n    for(var ai in aobj) {\n        if(helpers.hasParent(aobj, ai)) {\n            throw new Error('cannot set ' + ai + ' and a parent attribute simultaneously');\n        }\n\n        var vi = aobj[ai];\n        var cont;\n        var contFull;\n        var param;\n        var oldVal;\n        var newVal;\n        var valObject;\n\n        // Backward compatibility shim for turning histogram autobin on,\n        // or freezing previous autobinned values.\n        // Replace obsolete `autobin(x|y): true` with `(x|y)bins: null`\n        // and `autobin(x|y): false` with the `(x|y)bins` in `fullData`\n        if(ai === 'autobinx' || ai === 'autobiny') {\n            ai = ai.charAt(ai.length - 1) + 'bins';\n            if(Array.isArray(vi)) vi = vi.map(arrayBins(ai));\n            else if(vi === false) vi = traces.map(allBins(ai));\n            else vi = null;\n        }\n\n        redoit[ai] = vi;\n\n        if(ai.substr(0, 6) === 'LAYOUT') {\n            param = layoutNP(gd.layout, ai.replace('LAYOUT', ''));\n            undoit[ai] = [undefinedToNull(param.get())];\n            // since we're allowing val to be an array, allow it here too,\n            // even though that's meaningless\n            param.set(Array.isArray(vi) ? vi[0] : vi);\n            // ironically, the layout attrs in restyle only require replot,\n            // not relayout\n            flags.calc = true;\n            continue;\n        }\n\n        // set attribute in gd.data\n        undoit[ai] = a0();\n        for(i = 0; i < traces.length; i++) {\n            cont = data[traces[i]];\n            contFull = getFullTrace(traces[i]);\n            var preGUI = fullLayout._tracePreGUI[contFull._fullInput.uid];\n            param = makeNP(preGUI, guiEditFlag)(cont, ai);\n            oldVal = param.get();\n            newVal = Array.isArray(vi) ? vi[i % vi.length] : vi;\n\n            if(newVal === undefined) continue;\n\n            var finalPart = param.parts[param.parts.length - 1];\n            var prefix = ai.substr(0, ai.length - finalPart.length - 1);\n            var prefixDot = prefix ? prefix + '.' : '';\n            var innerContFull = prefix ?\n                nestedProperty(contFull, prefix).get() : contFull;\n\n            valObject = PlotSchema.getTraceValObject(contFull, param.parts);\n\n            if(valObject && valObject.impliedEdits && newVal !== null) {\n                for(var impliedKey in valObject.impliedEdits) {\n                    doextra(Lib.relativeAttr(ai, impliedKey), valObject.impliedEdits[impliedKey], i);\n                }\n            } else if((finalPart === 'thicknessmode' || finalPart === 'lenmode') &&\n                    oldVal !== newVal &&\n                    (newVal === 'fraction' || newVal === 'pixels') &&\n                    innerContFull\n            ) {\n                // changing colorbar size modes,\n                // make the resulting size not change\n                // note that colorbar fractional sizing is based on the\n                // original plot size, before anything (like a colorbar)\n                // increases the margins\n\n                var gs = fullLayout._size;\n                var orient = innerContFull.orient;\n                var topOrBottom = (orient === 'top') || (orient === 'bottom');\n                if(finalPart === 'thicknessmode') {\n                    var thicknorm = topOrBottom ? gs.h : gs.w;\n                    doextra(prefixDot + 'thickness', innerContFull.thickness *\n                        (newVal === 'fraction' ? 1 / thicknorm : thicknorm), i);\n                } else {\n                    var lennorm = topOrBottom ? gs.w : gs.h;\n                    doextra(prefixDot + 'len', innerContFull.len *\n                        (newVal === 'fraction' ? 1 / lennorm : lennorm), i);\n                }\n            } else if(ai === 'type' && (\n                (newVal === 'pie') !== (oldVal === 'pie') ||\n                (newVal === 'funnelarea') !== (oldVal === 'funnelarea')\n            )) {\n                var labelsTo = 'x';\n                var valuesTo = 'y';\n                if((newVal === 'bar' || oldVal === 'bar') && cont.orientation === 'h') {\n                    labelsTo = 'y';\n                    valuesTo = 'x';\n                }\n                Lib.swapAttrs(cont, ['?', '?src'], 'labels', labelsTo);\n                Lib.swapAttrs(cont, ['d?', '?0'], 'label', labelsTo);\n                Lib.swapAttrs(cont, ['?', '?src'], 'values', valuesTo);\n\n                if(oldVal === 'pie' || oldVal === 'funnelarea') {\n                    nestedProperty(cont, 'marker.color')\n                        .set(nestedProperty(cont, 'marker.colors').get());\n\n                    // super kludgy - but if all pies are gone we won't remove them otherwise\n                    fullLayout._pielayer.selectAll('g.trace').remove();\n                } else if(Registry.traceIs(cont, 'cartesian')) {\n                    nestedProperty(cont, 'marker.colors')\n                        .set(nestedProperty(cont, 'marker.color').get());\n                }\n            }\n\n            undoit[ai][i] = undefinedToNull(oldVal);\n            // set the new value - if val is an array, it's one el per trace\n            // first check for attributes that get more complex alterations\n            var swapAttrs = [\n                'swapxy', 'swapxyaxes', 'orientation', 'orientationaxes'\n            ];\n            if(swapAttrs.indexOf(ai) !== -1) {\n                // setting an orientation: make sure it's changing\n                // before we swap everything else\n                if(ai === 'orientation') {\n                    param.set(newVal);\n                    // obnoxious that we need this level of coupling... but in order to\n                    // properly handle setting orientation to `null` we need to mimic\n                    // the logic inside Bars.supplyDefaults for default orientation\n                    var defaultOrientation = (cont.x && !cont.y) ? 'h' : 'v';\n                    if((param.get() || defaultOrientation) === contFull.orientation) {\n                        continue;\n                    }\n                } else if(ai === 'orientationaxes') {\n                    // orientationaxes has no value,\n                    // it flips everything and the axes\n\n                    cont.orientation =\n                        {v: 'h', h: 'v'}[contFull.orientation];\n                }\n                helpers.swapXYData(cont);\n                flags.calc = flags.clearAxisTypes = true;\n            } else if(Plots.dataArrayContainers.indexOf(param.parts[0]) !== -1) {\n                // TODO: use manageArrays.applyContainerArrayChanges here too\n                helpers.manageArrayContainers(param, newVal, undoit);\n                flags.calc = true;\n            } else {\n                if(valObject) {\n                    // must redo calcdata when restyling array values of arrayOk attributes\n                    // ... but no need to this for regl-based traces\n                    if(valObject.arrayOk &&\n                        !Registry.traceIs(contFull, 'regl') &&\n                        (Lib.isArrayOrTypedArray(newVal) || Lib.isArrayOrTypedArray(oldVal))\n                    ) {\n                        flags.calc = true;\n                    } else editTypes.update(flags, valObject);\n                } else {\n                    /*\n                     * if we couldn't find valObject,  assume a full recalc.\n                     * This can happen if you're changing type and making\n                     * some other edits too, so the modules we're\n                     * looking at don't have these attributes in them.\n                     */\n                    flags.calc = true;\n                }\n\n                // all the other ones, just modify that one attribute\n                param.set(newVal);\n            }\n        }\n\n        // swap the data attributes of the relevant x and y axes?\n        if(['swapxyaxes', 'orientationaxes'].indexOf(ai) !== -1) {\n            Axes.swap(gd, traces);\n        }\n\n        // swap hovermode if set to \"compare x/y data\"\n        if(ai === 'orientationaxes') {\n            var hovermode = nestedProperty(gd.layout, 'hovermode');\n            if(hovermode.get() === 'x') {\n                hovermode.set('y');\n            } else if(hovermode.get() === 'y') {\n                hovermode.set('x');\n            }\n        }\n\n        // Major enough changes deserve autoscale and\n        // non-reversed axes so people don't get confused\n        //\n        // Note: autobin (or its new analog bin clearing) is not included here\n        // since we're not pushing bins back to gd.data, so if we have bin\n        // info it was explicitly provided by the user.\n        if(['orientation', 'type'].indexOf(ai) !== -1) {\n            axlist = [];\n            for(i = 0; i < traces.length; i++) {\n                var trace = data[traces[i]];\n\n                if(Registry.traceIs(trace, 'cartesian')) {\n                    addToAxlist(trace.xaxis || 'x');\n                    addToAxlist(trace.yaxis || 'y');\n                }\n            }\n\n            doextra(axlist.map(autorangeAttr), true, 0);\n            doextra(axlist.map(rangeAttr), [0, 1], 0);\n        }\n    }\n\n    if(flags.calc || flags.plot) {\n        flags.fullReplot = true;\n    }\n\n    return {\n        flags: flags,\n        undoit: undoit,\n        redoit: redoit,\n        traces: traces,\n        eventData: Lib.extendDeepNoArrays([], [eventData, traces])\n    };\n}\n\n/**\n * Converts deprecated attribute keys to\n * the current API to ensure backwards compatibility.\n *\n * This is needed for the update mechanism to determine which\n * subroutines to run based on the actual attribute\n * definitions (that don't include the deprecated ones).\n *\n * E.g. Maps {'xaxis.title': 'A chart'} to {'xaxis.title.text': 'A chart'}\n * and {titlefont: {...}} to {'title.font': {...}}.\n *\n * @param aobj\n */\nfunction cleanDeprecatedAttributeKeys(aobj) {\n    var oldAxisTitleRegex = Lib.counterRegex('axis', '\\.title', false, false);\n    var colorbarRegex = /colorbar\\.title$/;\n    var keys = Object.keys(aobj);\n    var i, key, value;\n\n    for(i = 0; i < keys.length; i++) {\n        key = keys[i];\n        value = aobj[key];\n\n        if((key === 'title' || oldAxisTitleRegex.test(key) || colorbarRegex.test(key)) &&\n          (typeof value === 'string' || typeof value === 'number')) {\n            replace(key, key.replace('title', 'title.text'));\n        } else if(key.indexOf('titlefont') > -1) {\n            replace(key, key.replace('titlefont', 'title.font'));\n        } else if(key.indexOf('titleposition') > -1) {\n            replace(key, key.replace('titleposition', 'title.position'));\n        } else if(key.indexOf('titleside') > -1) {\n            replace(key, key.replace('titleside', 'title.side'));\n        } else if(key.indexOf('titleoffset') > -1) {\n            replace(key, key.replace('titleoffset', 'title.offset'));\n        }\n    }\n\n    function replace(oldAttrStr, newAttrStr) {\n        aobj[newAttrStr] = aobj[oldAttrStr];\n        delete aobj[oldAttrStr];\n    }\n}\n\n/**\n * relayout: update layout attributes of an existing plot\n *\n * Can be called two ways:\n *\n * Signature 1:\n * @param {String | HTMLDivElement} gd\n *  the id or dom element of the graph container div\n * @param {String} astr\n *  attribute string (like `'xaxis.range[0]'`) to update\n * @param {*} val\n *  value to give this attribute\n *\n * Signature 2:\n * @param {String | HTMLDivElement} gd\n *  (as in signature 1)\n * @param {Object} aobj\n *  attribute object `{astr1: val1, astr2: val2 ...}`\n *  allows setting multiple attributes simultaneously\n */\nfunction relayout(gd, astr, val) {\n    gd = Lib.getGraphDiv(gd);\n    helpers.clearPromiseQueue(gd);\n\n    if(gd.framework && gd.framework.isPolar) {\n        return Promise.resolve(gd);\n    }\n\n    var aobj = {};\n    if(typeof astr === 'string') {\n        aobj[astr] = val;\n    } else if(Lib.isPlainObject(astr)) {\n        aobj = Lib.extendFlat({}, astr);\n    } else {\n        Lib.warn('Relayout fail.', astr, val);\n        return Promise.reject();\n    }\n\n    if(Object.keys(aobj).length) gd.changed = true;\n\n    var specs = _relayout(gd, aobj);\n    var flags = specs.flags;\n\n    // clear calcdata if required\n    if(flags.calc) gd.calcdata = undefined;\n\n    // fill in redraw sequence\n\n    // even if we don't have anything left in aobj,\n    // something may have happened within relayout that we\n    // need to wait for\n    var seq = [Plots.previousPromises];\n\n    if(flags.layoutReplot) {\n        seq.push(subroutines.layoutReplot);\n    } else if(Object.keys(aobj).length) {\n        axRangeSupplyDefaultsByPass(gd, flags, specs) || Plots.supplyDefaults(gd);\n\n        if(flags.legend) seq.push(subroutines.doLegend);\n        if(flags.layoutstyle) seq.push(subroutines.layoutStyles);\n        if(flags.axrange) addAxRangeSequence(seq, specs.rangesAltered);\n        if(flags.ticks) seq.push(subroutines.doTicksRelayout);\n        if(flags.modebar) seq.push(subroutines.doModeBar);\n        if(flags.camera) seq.push(subroutines.doCamera);\n        if(flags.colorbars) seq.push(subroutines.doColorBars);\n\n        seq.push(emitAfterPlot);\n    }\n\n    seq.push(Plots.rehover, Plots.redrag);\n\n    Queue.add(gd,\n        relayout, [gd, specs.undoit],\n        relayout, [gd, specs.redoit]\n    );\n\n    var plotDone = Lib.syncOrAsync(seq, gd);\n    if(!plotDone || !plotDone.then) plotDone = Promise.resolve(gd);\n\n    return plotDone.then(function() {\n        gd.emit('plotly_relayout', specs.eventData);\n        return gd;\n    });\n}\n\n// Optimization mostly for large splom traces where\n// Plots.supplyDefaults can take > 100ms\nfunction axRangeSupplyDefaultsByPass(gd, flags, specs) {\n    var fullLayout = gd._fullLayout;\n\n    if(!flags.axrange) return false;\n\n    for(var k in flags) {\n        if(k !== 'axrange' && flags[k]) return false;\n    }\n\n    for(var axId in specs.rangesAltered) {\n        var axName = Axes.id2name(axId);\n        var axIn = gd.layout[axName];\n        var axOut = fullLayout[axName];\n        axOut.autorange = axIn.autorange;\n        axOut.range = axIn.range.slice();\n        axOut.cleanRange();\n\n        if(axOut._matchGroup) {\n            for(var axId2 in axOut._matchGroup) {\n                if(axId2 !== axId) {\n                    var ax2 = fullLayout[Axes.id2name(axId2)];\n                    ax2.autorange = axOut.autorange;\n                    ax2.range = axOut.range.slice();\n                    ax2._input.range = axOut.range.slice();\n                }\n            }\n        }\n    }\n\n    return true;\n}\n\nfunction addAxRangeSequence(seq, rangesAltered) {\n    // N.B. leave as sequence of subroutines (for now) instead of\n    // subroutine of its own so that finalDraw always gets\n    // executed after drawData\n    var drawAxes = rangesAltered ?\n        function(gd) {\n            var axIds = [];\n            var skipTitle = true;\n\n            for(var id in rangesAltered) {\n                var ax = Axes.getFromId(gd, id);\n                axIds.push(id);\n\n                if(ax._matchGroup) {\n                    for(var id2 in ax._matchGroup) {\n                        if(!rangesAltered[id2]) {\n                            axIds.push(id2);\n                        }\n                    }\n                }\n\n                if(ax.automargin) skipTitle = false;\n            }\n\n            return Axes.draw(gd, axIds, {skipTitle: skipTitle});\n        } :\n        function(gd) {\n            return Axes.draw(gd, 'redraw');\n        };\n\n    seq.push(\n        clearSelect,\n        subroutines.doAutoRangeAndConstraints,\n        drawAxes,\n        subroutines.drawData,\n        subroutines.finalDraw\n    );\n}\n\nvar AX_RANGE_RE = /^[xyz]axis[0-9]*\\.range(\\[[0|1]\\])?$/;\nvar AX_AUTORANGE_RE = /^[xyz]axis[0-9]*\\.autorange$/;\nvar AX_DOMAIN_RE = /^[xyz]axis[0-9]*\\.domain(\\[[0|1]\\])?$/;\n\nfunction _relayout(gd, aobj) {\n    var layout = gd.layout;\n    var fullLayout = gd._fullLayout;\n    var guiEditFlag = fullLayout._guiEditing;\n    var layoutNP = makeNP(fullLayout._preGUI, guiEditFlag);\n    var keys = Object.keys(aobj);\n    var axes = Axes.list(gd);\n    var eventData = Lib.extendDeepAll({}, aobj);\n    var arrayEdits = {};\n\n    var arrayStr, i, j;\n\n    cleanDeprecatedAttributeKeys(aobj);\n    keys = Object.keys(aobj);\n\n    // look for 'allaxes', split out into all axes\n    // in case of 3D the axis are nested within a scene which is held in _id\n    for(i = 0; i < keys.length; i++) {\n        if(keys[i].indexOf('allaxes') === 0) {\n            for(j = 0; j < axes.length; j++) {\n                var scene = axes[j]._id.substr(1);\n                var axisAttr = (scene.indexOf('scene') !== -1) ? (scene + '.') : '';\n                var newkey = keys[i].replace('allaxes', axisAttr + axes[j]._name);\n\n                if(!aobj[newkey]) aobj[newkey] = aobj[keys[i]];\n            }\n\n            delete aobj[keys[i]];\n        }\n    }\n\n    // initialize flags\n    var flags = editTypes.layoutFlags();\n\n    // copies of the change (and previous values of anything affected)\n    // for the undo / redo queue\n    var redoit = {};\n    var undoit = {};\n\n    // for attrs that interact (like scales & autoscales), save the\n    // old vals before making the change\n    // val=undefined will not set a value, just record what the value was.\n    // attr can be an array to set several at once (all to the same val)\n    function doextra(attr, val) {\n        if(Array.isArray(attr)) {\n            attr.forEach(function(a) { doextra(a, val); });\n            return;\n        }\n\n        // if we have another value for this attribute (explicitly or\n        // via a parent) do not override with this auto-generated extra\n        if(attr in aobj || helpers.hasParent(aobj, attr)) return;\n\n        var p = layoutNP(layout, attr);\n        if(!(attr in undoit)) {\n            undoit[attr] = undefinedToNull(p.get());\n        }\n        if(val !== undefined) p.set(val);\n    }\n\n    // for constraint enforcement: keep track of all axes (as {id: name})\n    // we're editing the (auto)range of, so we can tell the others constrained\n    // to scale with them that it's OK for them to shrink\n    var rangesAltered = {};\n    var axId;\n\n    function recordAlteredAxis(pleafPlus) {\n        var axId = Axes.name2id(pleafPlus.split('.')[0]);\n        rangesAltered[axId] = 1;\n        return axId;\n    }\n\n    // alter gd.layout\n    for(var ai in aobj) {\n        if(helpers.hasParent(aobj, ai)) {\n            throw new Error('cannot set ' + ai + ' and a parent attribute simultaneously');\n        }\n\n        var p = layoutNP(layout, ai);\n        var vi = aobj[ai];\n        var plen = p.parts.length;\n        // p.parts may end with an index integer if the property is an array\n        var pend = plen - 1;\n        while(pend > 0 && typeof p.parts[pend] !== 'string') pend--;\n        // last property in chain (leaf node)\n        var pleaf = p.parts[pend];\n        // leaf plus immediate parent\n        var pleafPlus = p.parts[pend - 1] + '.' + pleaf;\n        // trunk nodes (everything except the leaf)\n        var ptrunk = p.parts.slice(0, pend).join('.');\n        var parentIn = nestedProperty(gd.layout, ptrunk).get();\n        var parentFull = nestedProperty(fullLayout, ptrunk).get();\n        var vOld = p.get();\n\n        if(vi === undefined) continue;\n\n        redoit[ai] = vi;\n\n        // axis reverse is special - it is its own inverse\n        // op and has no flag.\n        undoit[ai] = (pleaf === 'reverse') ? vi : undefinedToNull(vOld);\n\n        var valObject = PlotSchema.getLayoutValObject(fullLayout, p.parts);\n\n        if(valObject && valObject.impliedEdits && vi !== null) {\n            for(var impliedKey in valObject.impliedEdits) {\n                doextra(Lib.relativeAttr(ai, impliedKey), valObject.impliedEdits[impliedKey]);\n            }\n        }\n\n        // Setting width or height to null must reset the graph's width / height\n        // back to its initial value as computed during the first pass in Plots.plotAutoSize.\n        //\n        // To do so, we must manually set them back here using the _initialAutoSize cache.\n        // can't use impliedEdits for this because behavior depends on vi\n        if(['width', 'height'].indexOf(ai) !== -1) {\n            if(vi) {\n                doextra('autosize', null);\n                // currently we don't support autosize one dim only - so\n                // explicitly set the other one. Note that doextra will\n                // ignore this if the same relayout call also provides oppositeAttr\n                var oppositeAttr = ai === 'height' ? 'width' : 'height';\n                doextra(oppositeAttr, fullLayout[oppositeAttr]);\n            } else {\n                fullLayout[ai] = gd._initialAutoSize[ai];\n            }\n        } else if(ai === 'autosize') {\n            // depends on vi here too, so again can't use impliedEdits\n            doextra('width', vi ? null : fullLayout.width);\n            doextra('height', vi ? null : fullLayout.height);\n        } else if(pleafPlus.match(AX_RANGE_RE)) {\n            // check autorange vs range\n\n            recordAlteredAxis(pleafPlus);\n            nestedProperty(fullLayout, ptrunk + '._inputRange').set(null);\n        } else if(pleafPlus.match(AX_AUTORANGE_RE)) {\n            recordAlteredAxis(pleafPlus);\n            nestedProperty(fullLayout, ptrunk + '._inputRange').set(null);\n            var axFull = nestedProperty(fullLayout, ptrunk).get();\n            if(axFull._inputDomain) {\n                // if we're autoranging and this axis has a constrained domain,\n                // reset it so we don't get locked into a shrunken size\n                axFull._input.domain = axFull._inputDomain.slice();\n            }\n        } else if(pleafPlus.match(AX_DOMAIN_RE)) {\n            nestedProperty(fullLayout, ptrunk + '._inputDomain').set(null);\n        }\n\n        // toggling axis type between log and linear: we need to convert\n        // positions for components that are still using linearized values,\n        // not data values like newer components.\n        // previously we did this for log <-> not-log, but now only do it\n        // for log <-> linear\n        if(pleaf === 'type') {\n            var ax = parentIn;\n            var toLog = parentFull.type === 'linear' && vi === 'log';\n            var fromLog = parentFull.type === 'log' && vi === 'linear';\n\n            if(toLog || fromLog) {\n                if(!ax || !ax.range) {\n                    // 2D never gets here, but 3D does\n                    // I don't think this is needed, but left here in case there\n                    // are edge cases I'm not thinking of.\n                    doextra(ptrunk + '.autorange', true);\n                } else if(!parentFull.autorange) {\n                    // toggling log without autorange: need to also recalculate ranges\n                    // because log axes use linearized values for range endpoints\n                    var r0 = ax.range[0];\n                    var r1 = ax.range[1];\n                    if(toLog) {\n                        // if both limits are negative, autorange\n                        if(r0 <= 0 && r1 <= 0) {\n                            doextra(ptrunk + '.autorange', true);\n                        }\n                        // if one is negative, set it 6 orders below the other.\n                        if(r0 <= 0) r0 = r1 / 1e6;\n                        else if(r1 <= 0) r1 = r0 / 1e6;\n                        // now set the range values as appropriate\n                        doextra(ptrunk + '.range[0]', Math.log(r0) / Math.LN10);\n                        doextra(ptrunk + '.range[1]', Math.log(r1) / Math.LN10);\n                    } else {\n                        doextra(ptrunk + '.range[0]', Math.pow(10, r0));\n                        doextra(ptrunk + '.range[1]', Math.pow(10, r1));\n                    }\n                } else if(toLog) {\n                    // just make sure the range is positive and in the right\n                    // order, it'll get recalculated later\n                    ax.range = (ax.range[1] > ax.range[0]) ? [1, 2] : [2, 1];\n                }\n\n                // clear polar view initial stash for radial range so that\n                // value get recomputed in correct units\n                if(Array.isArray(fullLayout._subplots.polar) &&\n                    fullLayout._subplots.polar.length &&\n                    fullLayout[p.parts[0]] &&\n                    p.parts[1] === 'radialaxis'\n                ) {\n                    delete fullLayout[p.parts[0]]._subplot.viewInitial['radialaxis.range'];\n                }\n\n                // Annotations and images also need to convert to/from linearized coords\n                // Shapes do not need this :)\n                Registry.getComponentMethod('annotations', 'convertCoords')(gd, parentFull, vi, doextra);\n                Registry.getComponentMethod('images', 'convertCoords')(gd, parentFull, vi, doextra);\n            } else {\n                // any other type changes: the range from the previous type\n                // will not make sense, so autorange it.\n                doextra(ptrunk + '.autorange', true);\n                doextra(ptrunk + '.range', null);\n            }\n            nestedProperty(fullLayout, ptrunk + '._inputRange').set(null);\n        } else if(pleaf.match(AX_NAME_PATTERN)) {\n            var fullProp = nestedProperty(fullLayout, ai).get();\n            var newType = (vi || {}).type;\n\n            // This can potentially cause strange behavior if the autotype is not\n            // numeric (linear, because we don't auto-log) but the previous type\n            // was log. That's a very strange edge case though\n            if(!newType || newType === '-') newType = 'linear';\n            Registry.getComponentMethod('annotations', 'convertCoords')(gd, fullProp, newType, doextra);\n            Registry.getComponentMethod('images', 'convertCoords')(gd, fullProp, newType, doextra);\n        }\n\n        // alter gd.layout\n\n        // collect array component edits for execution all together\n        // so we can ensure consistent behavior adding/removing items\n        // and order-independence for add/remove/edit all together in\n        // one relayout call\n        var containerArrayMatch = manageArrays.containerArrayMatch(ai);\n        if(containerArrayMatch) {\n            arrayStr = containerArrayMatch.array;\n            i = containerArrayMatch.index;\n            var propStr = containerArrayMatch.property;\n            var updateValObject = valObject || {editType: 'calc'};\n\n            if(i !== '' && propStr === '') {\n                // special handling of undoit if we're adding or removing an element\n                // ie 'annotations[2]' which can be {...} (add) or null,\n                // does not work when replacing the entire array\n                if(manageArrays.isAddVal(vi)) {\n                    undoit[ai] = null;\n                } else if(manageArrays.isRemoveVal(vi)) {\n                    undoit[ai] = (nestedProperty(layout, arrayStr).get() || [])[i];\n                } else {\n                    Lib.warn('unrecognized full object value', aobj);\n                }\n            }\n            editTypes.update(flags, updateValObject);\n\n            // prepare the edits object we'll send to applyContainerArrayChanges\n            if(!arrayEdits[arrayStr]) arrayEdits[arrayStr] = {};\n            var objEdits = arrayEdits[arrayStr][i];\n            if(!objEdits) objEdits = arrayEdits[arrayStr][i] = {};\n            objEdits[propStr] = vi;\n\n            delete aobj[ai];\n        } else if(pleaf === 'reverse') {\n            // handle axis reversal explicitly, as there's no 'reverse' attribute\n\n            if(parentIn.range) parentIn.range.reverse();\n            else {\n                doextra(ptrunk + '.autorange', true);\n                parentIn.range = [1, 0];\n            }\n\n            if(parentFull.autorange) flags.calc = true;\n            else flags.plot = true;\n        } else {\n            if((fullLayout._has('scatter-like') && fullLayout._has('regl')) &&\n                (ai === 'dragmode' &&\n                (vi === 'lasso' || vi === 'select') &&\n                !(vOld === 'lasso' || vOld === 'select'))\n            ) {\n                flags.plot = true;\n            } else if(fullLayout._has('gl2d')) {\n                flags.plot = true;\n            } else if(valObject) editTypes.update(flags, valObject);\n            else flags.calc = true;\n\n            p.set(vi);\n        }\n    }\n\n    // now we've collected component edits - execute them all together\n    for(arrayStr in arrayEdits) {\n        var finished = manageArrays.applyContainerArrayChanges(gd,\n            layoutNP(layout, arrayStr), arrayEdits[arrayStr], flags, layoutNP);\n        if(!finished) flags.plot = true;\n    }\n\n    // figure out if we need to recalculate axis constraints\n    var constraints = fullLayout._axisConstraintGroups || [];\n    for(axId in rangesAltered) {\n        for(i = 0; i < constraints.length; i++) {\n            var group = constraints[i];\n            if(group[axId]) {\n                // Always recalc if we're changing constrained ranges.\n                // Otherwise it's possible to violate the constraints by\n                // specifying arbitrary ranges for all axes in the group.\n                // this way some ranges may expand beyond what's specified,\n                // as they do at first draw, to satisfy the constraints.\n                flags.calc = true;\n                for(var groupAxId in group) {\n                    if(!rangesAltered[groupAxId]) {\n                        Axes.getFromId(gd, groupAxId)._constraintShrinkable = true;\n                    }\n                }\n            }\n        }\n    }\n\n    // If the autosize changed or height or width was explicitly specified,\n    // this triggers a redraw\n    // TODO: do we really need special aobj.height/width handling here?\n    // couldn't editType do this?\n    if(updateAutosize(gd) || aobj.height || aobj.width) flags.plot = true;\n\n    if(flags.plot || flags.calc) {\n        flags.layoutReplot = true;\n    }\n\n    // now all attribute mods are done, as are\n    // redo and undo so we can save them\n\n    return {\n        flags: flags,\n        rangesAltered: rangesAltered,\n        undoit: undoit,\n        redoit: redoit,\n        eventData: eventData\n    };\n}\n\n/*\n * updateAutosize: we made a change, does it change the autosize result?\n * puts the new size into fullLayout\n * returns true if either height or width changed\n */\nfunction updateAutosize(gd) {\n    var fullLayout = gd._fullLayout;\n    var oldWidth = fullLayout.width;\n    var oldHeight = fullLayout.height;\n\n    // calculate autosizing\n    if(gd.layout.autosize) Plots.plotAutoSize(gd, gd.layout, fullLayout);\n\n    return (fullLayout.width !== oldWidth) || (fullLayout.height !== oldHeight);\n}\n\n/**\n * update: update trace and layout attributes of an existing plot\n *\n * @param {String | HTMLDivElement} gd\n *  the id or DOM element of the graph container div\n * @param {Object} traceUpdate\n *  attribute object `{astr1: val1, astr2: val2 ...}`\n *  corresponding to updates in the plot's traces\n * @param {Object} layoutUpdate\n *  attribute object `{astr1: val1, astr2: val2 ...}`\n *  corresponding to updates in the plot's layout\n * @param {Number[] | Number} [traces]\n *  integer or array of integers for the traces to alter (all if omitted)\n *\n */\nfunction update(gd, traceUpdate, layoutUpdate, _traces) {\n    gd = Lib.getGraphDiv(gd);\n    helpers.clearPromiseQueue(gd);\n\n    if(gd.framework && gd.framework.isPolar) {\n        return Promise.resolve(gd);\n    }\n\n    if(!Lib.isPlainObject(traceUpdate)) traceUpdate = {};\n    if(!Lib.isPlainObject(layoutUpdate)) layoutUpdate = {};\n\n    if(Object.keys(traceUpdate).length) gd.changed = true;\n    if(Object.keys(layoutUpdate).length) gd.changed = true;\n\n    var traces = helpers.coerceTraceIndices(gd, _traces);\n\n    var restyleSpecs = _restyle(gd, Lib.extendFlat({}, traceUpdate), traces);\n    var restyleFlags = restyleSpecs.flags;\n\n    var relayoutSpecs = _relayout(gd, Lib.extendFlat({}, layoutUpdate));\n    var relayoutFlags = relayoutSpecs.flags;\n\n    // clear calcdata and/or axis types if required\n    if(restyleFlags.calc || relayoutFlags.calc) gd.calcdata = undefined;\n    if(restyleFlags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, layoutUpdate);\n\n    // fill in redraw sequence\n    var seq = [];\n\n    if(relayoutFlags.layoutReplot) {\n        // N.B. works fine when both\n        // relayoutFlags.layoutReplot and restyleFlags.fullReplot are true\n        seq.push(subroutines.layoutReplot);\n    } else if(restyleFlags.fullReplot) {\n        seq.push(exports.plot);\n    } else {\n        seq.push(Plots.previousPromises);\n        axRangeSupplyDefaultsByPass(gd, relayoutFlags, relayoutSpecs) || Plots.supplyDefaults(gd);\n\n        if(restyleFlags.style) seq.push(subroutines.doTraceStyle);\n        if(restyleFlags.colorbars || relayoutFlags.colorbars) seq.push(subroutines.doColorBars);\n        if(relayoutFlags.legend) seq.push(subroutines.doLegend);\n        if(relayoutFlags.layoutstyle) seq.push(subroutines.layoutStyles);\n        if(relayoutFlags.axrange) addAxRangeSequence(seq, relayoutSpecs.rangesAltered);\n        if(relayoutFlags.ticks) seq.push(subroutines.doTicksRelayout);\n        if(relayoutFlags.modebar) seq.push(subroutines.doModeBar);\n        if(relayoutFlags.camera) seq.push(subroutines.doCamera);\n\n        seq.push(emitAfterPlot);\n    }\n\n    seq.push(Plots.rehover, Plots.redrag);\n\n    Queue.add(gd,\n        update, [gd, restyleSpecs.undoit, relayoutSpecs.undoit, restyleSpecs.traces],\n        update, [gd, restyleSpecs.redoit, relayoutSpecs.redoit, restyleSpecs.traces]\n    );\n\n    var plotDone = Lib.syncOrAsync(seq, gd);\n    if(!plotDone || !plotDone.then) plotDone = Promise.resolve(gd);\n\n    return plotDone.then(function() {\n        gd.emit('plotly_update', {\n            data: restyleSpecs.eventData,\n            layout: relayoutSpecs.eventData\n        });\n\n        return gd;\n    });\n}\n\n/*\n * internal-use-only restyle/relayout/update variants that record the initial\n * values in (fullLayout|fullTrace)._preGUI so changes can be persisted across\n * Plotly.react data updates, dependent on uirevision attributes\n */\nfunction guiEdit(func) {\n    return function wrappedEdit(gd) {\n        gd._fullLayout._guiEditing = true;\n        var p = func.apply(null, arguments);\n        gd._fullLayout._guiEditing = false;\n        return p;\n    };\n}\n\n// For connecting edited layout attributes to uirevision attrs\n// If no `attr` we use `match[1] + '.uirevision'`\n// Ordered by most common edits first, to minimize our search time\nvar layoutUIControlPatterns = [\n    {pattern: /^hiddenlabels/, attr: 'legend.uirevision'},\n    {pattern: /^((x|y)axis\\d*)\\.((auto)?range|title\\.text)/},\n\n    // showspikes and modes include those nested inside scenes\n    {pattern: /axis\\d*\\.showspikes$/, attr: 'modebar.uirevision'},\n    {pattern: /(hover|drag)mode$/, attr: 'modebar.uirevision'},\n\n    {pattern: /^(scene\\d*)\\.camera/},\n    {pattern: /^(geo\\d*)\\.(projection|center)/},\n    {pattern: /^(ternary\\d*\\.[abc]axis)\\.(min|title\\.text)$/},\n    {pattern: /^(polar\\d*\\.radialaxis)\\.((auto)?range|angle|title\\.text)/},\n    {pattern: /^(polar\\d*\\.angularaxis)\\.rotation/},\n    {pattern: /^(mapbox\\d*)\\.(center|zoom|bearing|pitch)/},\n\n    {pattern: /^legend\\.(x|y)$/, attr: 'editrevision'},\n    {pattern: /^(shapes|annotations)/, attr: 'editrevision'},\n    {pattern: /^title\\.text$/, attr: 'editrevision'}\n];\n\n// same for trace attributes: if `attr` is given it's in layout,\n// or with no `attr` we use `trace.uirevision`\nvar traceUIControlPatterns = [\n    {pattern: /^selectedpoints$/, attr: 'selectionrevision'},\n    // \"visible\" includes trace.transforms[i].styles[j].value.visible\n    {pattern: /(^|value\\.)visible$/, attr: 'legend.uirevision'},\n    {pattern: /^dimensions\\[\\d+\\]\\.constraintrange/},\n    {pattern: /^node\\.(x|y|groups)/}, // for Sankey nodes\n    {pattern: /^level$/}, // for Sunburst traces\n\n    // below this you must be in editable: true mode\n    // TODO: I still put name and title with `trace.uirevision`\n    // reasonable or should these be `editrevision`?\n    // Also applies to axis titles up in the layout section\n\n    // \"name\" also includes transform.styles\n    {pattern: /(^|value\\.)name$/},\n    // including nested colorbar attributes (ie marker.colorbar)\n    {pattern: /colorbar\\.title\\.text$/},\n    {pattern: /colorbar\\.(x|y)$/, attr: 'editrevision'}\n];\n\nfunction findUIPattern(key, patternSpecs) {\n    for(var i = 0; i < patternSpecs.length; i++) {\n        var spec = patternSpecs[i];\n        var match = key.match(spec.pattern);\n        if(match) {\n            return {head: match[1], attr: spec.attr};\n        }\n    }\n}\n\n// We're finding the new uirevision before supplyDefaults, so do the\n// inheritance manually. Note that only `undefined` inherits - other\n// falsy values are returned.\nfunction getNewRev(revAttr, container) {\n    var newRev = nestedProperty(container, revAttr).get();\n    if(newRev !== undefined) return newRev;\n\n    var parts = revAttr.split('.');\n    parts.pop();\n    while(parts.length > 1) {\n        parts.pop();\n        newRev = nestedProperty(container, parts.join('.') + '.uirevision').get();\n        if(newRev !== undefined) return newRev;\n    }\n\n    return container.uirevision;\n}\n\nfunction getFullTraceIndexFromUid(uid, fullData) {\n    for(var i = 0; i < fullData.length; i++) {\n        if(fullData[i]._fullInput.uid === uid) return i;\n    }\n    return -1;\n}\n\nfunction getTraceIndexFromUid(uid, data, tracei) {\n    for(var i = 0; i < data.length; i++) {\n        if(data[i].uid === uid) return i;\n    }\n    // fall back on trace order, but only if user didn't provide a uid for that trace\n    return (!data[tracei] || data[tracei].uid) ? -1 : tracei;\n}\n\nfunction valsMatch(v1, v2) {\n    var v1IsObj = Lib.isPlainObject(v1);\n    var v1IsArray = Array.isArray(v1);\n    if(v1IsObj || v1IsArray) {\n        return (\n            (v1IsObj && Lib.isPlainObject(v2)) ||\n            (v1IsArray && Array.isArray(v2))\n        ) && JSON.stringify(v1) === JSON.stringify(v2);\n    }\n    return v1 === v2;\n}\n\nfunction applyUIRevisions(data, layout, oldFullData, oldFullLayout) {\n    var layoutPreGUI = oldFullLayout._preGUI;\n    var key, revAttr, oldRev, newRev, match, preGUIVal, newNP, newVal;\n    var bothInheritAutorange = [];\n    var newRangeAccepted = {};\n    for(key in layoutPreGUI) {\n        match = findUIPattern(key, layoutUIControlPatterns);\n        if(match) {\n            revAttr = match.attr || (match.head + '.uirevision');\n            oldRev = nestedProperty(oldFullLayout, revAttr).get();\n            newRev = oldRev && getNewRev(revAttr, layout);\n            if(newRev && (newRev === oldRev)) {\n                preGUIVal = layoutPreGUI[key];\n                if(preGUIVal === null) preGUIVal = undefined;\n                newNP = nestedProperty(layout, key);\n                newVal = newNP.get();\n                if(valsMatch(newVal, preGUIVal)) {\n                    if(newVal === undefined && key.substr(key.length - 9) === 'autorange') {\n                        bothInheritAutorange.push(key.substr(0, key.length - 10));\n                    }\n                    newNP.set(undefinedToNull(nestedProperty(oldFullLayout, key).get()));\n                    continue;\n                }\n            }\n        } else {\n            Lib.warn('unrecognized GUI edit: ' + key);\n        }\n        // if we got this far, the new value was accepted as the new starting\n        // point (either because it changed or revision changed)\n        // so remove it from _preGUI for next time.\n        delete layoutPreGUI[key];\n\n        if(key.substr(key.length - 8, 6) === 'range[') {\n            newRangeAccepted[key.substr(0, key.length - 9)] = 1;\n        }\n    }\n\n    // Special logic for `autorange`, since it interacts with `range`:\n    // If the new figure's matching `range` was kept, and `autorange`\n    // wasn't supplied explicitly in either the original or the new figure,\n    // we shouldn't alter that - but we may just have done that, so fix it.\n    for(var i = 0; i < bothInheritAutorange.length; i++) {\n        var axAttr = bothInheritAutorange[i];\n        if(newRangeAccepted[axAttr]) {\n            var newAx = nestedProperty(layout, axAttr).get();\n            if(newAx) delete newAx.autorange;\n        }\n    }\n\n    // Now traces - try to match them up by uid (in case we added/deleted in\n    // the middle), then fall back on index.\n    var allTracePreGUI = oldFullLayout._tracePreGUI;\n    for(var uid in allTracePreGUI) {\n        var tracePreGUI = allTracePreGUI[uid];\n        var newTrace = null;\n        var fullInput;\n        for(key in tracePreGUI) {\n            // wait until we know we have preGUI values to look for traces\n            // but if we don't find both, stop looking at this uid\n            if(!newTrace) {\n                var fulli = getFullTraceIndexFromUid(uid, oldFullData);\n                if(fulli < 0) {\n                    // Somehow we didn't even have this trace in oldFullData...\n                    // I guess this could happen with `deleteTraces` or something\n                    delete allTracePreGUI[uid];\n                    break;\n                }\n                var fullTrace = oldFullData[fulli];\n                fullInput = fullTrace._fullInput;\n\n                var newTracei = getTraceIndexFromUid(uid, data, fullInput.index);\n                if(newTracei < 0) {\n                    // No match in new data\n                    delete allTracePreGUI[uid];\n                    break;\n                }\n                newTrace = data[newTracei];\n            }\n\n            match = findUIPattern(key, traceUIControlPatterns);\n            if(match) {\n                if(match.attr) {\n                    oldRev = nestedProperty(oldFullLayout, match.attr).get();\n                    newRev = oldRev && getNewRev(match.attr, layout);\n                } else {\n                    oldRev = fullInput.uirevision;\n                    // inheritance for trace.uirevision is simple, just layout.uirevision\n                    newRev = newTrace.uirevision;\n                    if(newRev === undefined) newRev = layout.uirevision;\n                }\n\n                if(newRev && newRev === oldRev) {\n                    preGUIVal = tracePreGUI[key];\n                    if(preGUIVal === null) preGUIVal = undefined;\n                    newNP = nestedProperty(newTrace, key);\n                    newVal = newNP.get();\n                    if(valsMatch(newVal, preGUIVal)) {\n                        newNP.set(undefinedToNull(nestedProperty(fullInput, key).get()));\n                        continue;\n                    }\n                }\n            } else {\n                Lib.warn('unrecognized GUI edit: ' + key + ' in trace uid ' + uid);\n            }\n            delete tracePreGUI[key];\n        }\n    }\n}\n\n/**\n * Plotly.react:\n * A plot/update method that takes the full plot state (same API as plot/newPlot)\n * and diffs to determine the minimal update pathway\n *\n * @param {string id or DOM element} gd\n *      the id or DOM element of the graph container div\n * @param {array of objects} data\n *      array of traces, containing the data and display information for each trace\n * @param {object} layout\n *      object describing the overall display of the plot,\n *      all the stuff that doesn't pertain to any individual trace\n * @param {object} config\n *      configuration options (see ./plot_config.js for more info)\n *\n * OR\n *\n * @param {string id or DOM element} gd\n *      the id or DOM element of the graph container div\n * @param {object} figure\n *      object containing `data`, `layout`, `config`, and `frames` members\n *\n */\nfunction react(gd, data, layout, config) {\n    var frames, plotDone;\n\n    function addFrames() { return exports.addFrames(gd, frames); }\n\n    gd = Lib.getGraphDiv(gd);\n\n    var oldFullData = gd._fullData;\n    var oldFullLayout = gd._fullLayout;\n\n    // you can use this as the initial draw as well as to update\n    if(!Lib.isPlotDiv(gd) || !oldFullData || !oldFullLayout) {\n        plotDone = exports.newPlot(gd, data, layout, config);\n    } else {\n        if(Lib.isPlainObject(data)) {\n            var obj = data;\n            data = obj.data;\n            layout = obj.layout;\n            config = obj.config;\n            frames = obj.frames;\n        }\n\n        var configChanged = false;\n        // assume that if there's a config at all, we're reacting to it too,\n        // and completely replace the previous config\n        if(config) {\n            var oldConfig = Lib.extendDeep({}, gd._context);\n            gd._context = undefined;\n            setPlotContext(gd, config);\n            configChanged = diffConfig(oldConfig, gd._context);\n        }\n\n        gd.data = data || [];\n        helpers.cleanData(gd.data);\n        gd.layout = layout || {};\n        helpers.cleanLayout(gd.layout);\n\n        applyUIRevisions(gd.data, gd.layout, oldFullData, oldFullLayout);\n\n        // \"true\" skips updating calcdata and remapping arrays from calcTransforms,\n        // which supplyDefaults usually does at the end, but we may need to NOT do\n        // if the diff (which we haven't determined yet) says we'll recalc\n        Plots.supplyDefaults(gd, {skipUpdateCalc: true});\n\n        var newFullData = gd._fullData;\n        var newFullLayout = gd._fullLayout;\n        var immutable = newFullLayout.datarevision === undefined;\n        var transition = newFullLayout.transition;\n\n        var relayoutFlags = diffLayout(gd, oldFullLayout, newFullLayout, immutable, transition);\n        var newDataRevision = relayoutFlags.newDataRevision;\n        var restyleFlags = diffData(gd, oldFullData, newFullData, immutable, transition, newDataRevision);\n\n        // TODO: how to translate this part of relayout to Plotly.react?\n        // // Setting width or height to null must reset the graph's width / height\n        // // back to its initial value as computed during the first pass in Plots.plotAutoSize.\n        // //\n        // // To do so, we must manually set them back here using the _initialAutoSize cache.\n        // if(['width', 'height'].indexOf(ai) !== -1 && vi === null) {\n        //     fullLayout[ai] = gd._initialAutoSize[ai];\n        // }\n\n        if(updateAutosize(gd)) relayoutFlags.layoutReplot = true;\n\n        // clear calcdata if required\n        if(restyleFlags.calc || relayoutFlags.calc) gd.calcdata = undefined;\n        // otherwise do the calcdata updates and calcTransform array remaps that we skipped earlier\n        else Plots.supplyDefaultsUpdateCalc(gd.calcdata, newFullData);\n\n        // Note: what restyle/relayout use impliedEdits and clearAxisTypes for\n        // must be handled by the user when using Plotly.react.\n\n        // fill in redraw sequence\n        var seq = [];\n\n        if(frames) {\n            gd._transitionData = {};\n            Plots.createTransitionData(gd);\n            seq.push(addFrames);\n        }\n\n        // Transition pathway,\n        // only used when 'transition' is set by user and\n        // when at least one animatable attribute has changed,\n        // N.B. config changed aren't animatable\n        if(newFullLayout.transition && !configChanged && (restyleFlags.anim || relayoutFlags.anim)) {\n            Plots.doCalcdata(gd);\n            subroutines.doAutoRangeAndConstraints(gd);\n\n            seq.push(function() {\n                return Plots.transitionFromReact(gd, restyleFlags, relayoutFlags, oldFullLayout);\n            });\n        } else if(restyleFlags.fullReplot || relayoutFlags.layoutReplot || configChanged) {\n            gd._fullLayout._skipDefaults = true;\n            seq.push(exports.plot);\n        } else {\n            for(var componentType in relayoutFlags.arrays) {\n                var indices = relayoutFlags.arrays[componentType];\n                if(indices.length) {\n                    var drawOne = Registry.getComponentMethod(componentType, 'drawOne');\n                    if(drawOne !== Lib.noop) {\n                        for(var i = 0; i < indices.length; i++) {\n                            drawOne(gd, indices[i]);\n                        }\n                    } else {\n                        var draw = Registry.getComponentMethod(componentType, 'draw');\n                        if(draw === Lib.noop) {\n                            throw new Error('cannot draw components: ' + componentType);\n                        }\n                        draw(gd);\n                    }\n                }\n            }\n\n            seq.push(Plots.previousPromises);\n            if(restyleFlags.style) seq.push(subroutines.doTraceStyle);\n            if(restyleFlags.colorbars || relayoutFlags.colorbars) seq.push(subroutines.doColorBars);\n            if(relayoutFlags.legend) seq.push(subroutines.doLegend);\n            if(relayoutFlags.layoutstyle) seq.push(subroutines.layoutStyles);\n            if(relayoutFlags.axrange) addAxRangeSequence(seq);\n            if(relayoutFlags.ticks) seq.push(subroutines.doTicksRelayout);\n            if(relayoutFlags.modebar) seq.push(subroutines.doModeBar);\n            if(relayoutFlags.camera) seq.push(subroutines.doCamera);\n            seq.push(emitAfterPlot);\n        }\n\n        seq.push(Plots.rehover, Plots.redrag);\n\n        plotDone = Lib.syncOrAsync(seq, gd);\n        if(!plotDone || !plotDone.then) plotDone = Promise.resolve(gd);\n    }\n\n    return plotDone.then(function() {\n        gd.emit('plotly_react', {\n            data: data,\n            layout: layout\n        });\n\n        return gd;\n    });\n}\n\nfunction diffData(gd, oldFullData, newFullData, immutable, transition, newDataRevision) {\n    var sameTraceLength = oldFullData.length === newFullData.length;\n\n    if(!transition && !sameTraceLength) {\n        return {\n            fullReplot: true,\n            calc: true\n        };\n    }\n\n    var flags = editTypes.traceFlags();\n    flags.arrays = {};\n    flags.nChanges = 0;\n    flags.nChangesAnim = 0;\n\n    var i, trace;\n\n    function getTraceValObject(parts) {\n        var out = PlotSchema.getTraceValObject(trace, parts);\n        if(!trace._module.animatable && out.anim) {\n            out.anim = false;\n        }\n        return out;\n    }\n\n    var diffOpts = {\n        getValObject: getTraceValObject,\n        flags: flags,\n        immutable: immutable,\n        transition: transition,\n        newDataRevision: newDataRevision,\n        gd: gd\n    };\n\n    var seenUIDs = {};\n\n    for(i = 0; i < oldFullData.length; i++) {\n        if(newFullData[i]) {\n            trace = newFullData[i]._fullInput;\n            if(Plots.hasMakesDataTransform(trace)) trace = newFullData[i];\n            if(seenUIDs[trace.uid]) continue;\n            seenUIDs[trace.uid] = 1;\n\n            getDiffFlags(oldFullData[i]._fullInput, trace, [], diffOpts);\n        }\n    }\n\n    if(flags.calc || flags.plot) {\n        flags.fullReplot = true;\n    }\n\n    if(transition && flags.nChanges && flags.nChangesAnim) {\n        flags.anim = (flags.nChanges === flags.nChangesAnim) && sameTraceLength ? 'all' : 'some';\n    }\n\n    return flags;\n}\n\nfunction diffLayout(gd, oldFullLayout, newFullLayout, immutable, transition) {\n    var flags = editTypes.layoutFlags();\n    flags.arrays = {};\n    flags.rangesAltered = {};\n    flags.nChanges = 0;\n    flags.nChangesAnim = 0;\n\n    function getLayoutValObject(parts) {\n        return PlotSchema.getLayoutValObject(newFullLayout, parts);\n    }\n\n    var diffOpts = {\n        getValObject: getLayoutValObject,\n        flags: flags,\n        immutable: immutable,\n        transition: transition,\n        gd: gd\n    };\n\n    getDiffFlags(oldFullLayout, newFullLayout, [], diffOpts);\n\n    if(flags.plot || flags.calc) {\n        flags.layoutReplot = true;\n    }\n\n    if(transition && flags.nChanges && flags.nChangesAnim) {\n        flags.anim = flags.nChanges === flags.nChangesAnim ? 'all' : 'some';\n    }\n\n    return flags;\n}\n\nfunction getDiffFlags(oldContainer, newContainer, outerparts, opts) {\n    var valObject, key, astr;\n\n    var getValObject = opts.getValObject;\n    var flags = opts.flags;\n    var immutable = opts.immutable;\n    var inArray = opts.inArray;\n    var arrayIndex = opts.arrayIndex;\n\n    function changed() {\n        var editType = valObject.editType;\n        if(inArray && editType.indexOf('arraydraw') !== -1) {\n            Lib.pushUnique(flags.arrays[inArray], arrayIndex);\n            return;\n        }\n        editTypes.update(flags, valObject);\n\n        if(editType !== 'none') {\n            flags.nChanges++;\n        }\n\n        // track animatable changes\n        if(opts.transition && valObject.anim) {\n            flags.nChangesAnim++;\n        }\n\n        // track cartesian axes with altered ranges\n        if(AX_RANGE_RE.test(astr) || AX_AUTORANGE_RE.test(astr)) {\n            flags.rangesAltered[outerparts[0]] = 1;\n        }\n\n        // clear _inputDomain on cartesian axes with altered domains\n        if(AX_DOMAIN_RE.test(astr)) {\n            nestedProperty(newContainer, '_inputDomain').set(null);\n        }\n\n        // track datarevision changes\n        if(key === 'datarevision') {\n            flags.newDataRevision = 1;\n        }\n    }\n\n    function valObjectCanBeDataArray(valObject) {\n        return valObject.valType === 'data_array' || valObject.arrayOk;\n    }\n\n    for(key in oldContainer) {\n        // short-circuit based on previous calls or previous keys that already maximized the pathway\n        if(flags.calc && !opts.transition) return;\n\n        var oldVal = oldContainer[key];\n        var newVal = newContainer[key];\n        var parts = outerparts.concat(key);\n        astr = parts.join('.');\n\n        if(key.charAt(0) === '_' || typeof oldVal === 'function' || oldVal === newVal) continue;\n\n        // FIXME: ax.tick0 and dtick get filled in during plotting (except for geo subplots),\n        // and unlike other auto values they don't make it back into the input,\n        // so newContainer won't have them.\n        if((key === 'tick0' || key === 'dtick') && outerparts[0] !== 'geo') {\n            var tickMode = newContainer.tickmode;\n            if(tickMode === 'auto' || tickMode === 'array' || !tickMode) continue;\n        }\n        // FIXME: Similarly for axis ranges for 3D\n        // contourcarpet doesn't HAVE zmin/zmax, they're just auto-added. It needs them.\n        if(key === 'range' && newContainer.autorange) continue;\n        if((key === 'zmin' || key === 'zmax') && newContainer.type === 'contourcarpet') continue;\n\n        valObject = getValObject(parts);\n\n        // in case type changed, we may not even *have* a valObject.\n        if(!valObject) continue;\n\n        if(valObject._compareAsJSON && JSON.stringify(oldVal) === JSON.stringify(newVal)) continue;\n\n        var valType = valObject.valType;\n        var i;\n\n        var canBeDataArray = valObjectCanBeDataArray(valObject);\n        var wasArray = Array.isArray(oldVal);\n        var nowArray = Array.isArray(newVal);\n\n        // hack for traces that modify the data in supplyDefaults, like\n        // converting 1D to 2D arrays, which will always create new objects\n        if(wasArray && nowArray) {\n            var inputKey = '_input_' + key;\n            var oldValIn = oldContainer[inputKey];\n            var newValIn = newContainer[inputKey];\n            if(Array.isArray(oldValIn) && oldValIn === newValIn) continue;\n        }\n\n        if(newVal === undefined) {\n            if(canBeDataArray && wasArray) flags.calc = true;\n            else changed();\n        } else if(valObject._isLinkedToArray) {\n            var arrayEditIndices = [];\n            var extraIndices = false;\n            if(!inArray) flags.arrays[key] = arrayEditIndices;\n\n            var minLen = Math.min(oldVal.length, newVal.length);\n            var maxLen = Math.max(oldVal.length, newVal.length);\n            if(minLen !== maxLen) {\n                if(valObject.editType === 'arraydraw') {\n                    extraIndices = true;\n                } else {\n                    changed();\n                    continue;\n                }\n            }\n\n            for(i = 0; i < minLen; i++) {\n                getDiffFlags(oldVal[i], newVal[i], parts.concat(i),\n                    // add array indices, but not if we're already in an array\n                    Lib.extendFlat({inArray: key, arrayIndex: i}, opts));\n            }\n\n            // put this at the end so that we know our collected array indices are sorted\n            // but the check for length changes happens up front so we can short-circuit\n            // diffing if appropriate\n            if(extraIndices) {\n                for(i = minLen; i < maxLen; i++) {\n                    arrayEditIndices.push(i);\n                }\n            }\n        } else if(!valType && Lib.isPlainObject(oldVal)) {\n            getDiffFlags(oldVal, newVal, parts, opts);\n        } else if(canBeDataArray) {\n            if(wasArray && nowArray) {\n                // don't try to diff two data arrays. If immutable we know the data changed,\n                // if not, assume it didn't and let `layout.datarevision` tell us if it did\n                if(immutable) {\n                    flags.calc = true;\n                }\n\n                // look for animatable attributes when the data changed\n                if(immutable || opts.newDataRevision) {\n                    changed();\n                }\n            } else if(wasArray !== nowArray) {\n                flags.calc = true;\n            } else changed();\n        } else if(wasArray && nowArray) {\n            // info array, colorscale, 'any' - these are short, just stringify.\n            // I don't *think* that covers up any real differences post-validation, does it?\n            // otherwise we need to dive in 1 (info_array) or 2 (colorscale) levels and compare\n            // all elements.\n            if(oldVal.length !== newVal.length || String(oldVal) !== String(newVal)) {\n                changed();\n            }\n        } else {\n            changed();\n        }\n    }\n\n    for(key in newContainer) {\n        if(!(key in oldContainer || key.charAt(0) === '_' || typeof newContainer[key] === 'function')) {\n            valObject = getValObject(outerparts.concat(key));\n\n            if(valObjectCanBeDataArray(valObject) && Array.isArray(newContainer[key])) {\n                flags.calc = true;\n                return;\n            } else changed();\n        }\n    }\n}\n\n/*\n * simple diff for config - for now, just treat all changes as equivalent\n */\nfunction diffConfig(oldConfig, newConfig) {\n    var key;\n\n    for(key in oldConfig) {\n        if(key.charAt(0) === '_') continue;\n        var oldVal = oldConfig[key];\n        var newVal = newConfig[key];\n        if(oldVal !== newVal) {\n            if(Lib.isPlainObject(oldVal) && Lib.isPlainObject(newVal)) {\n                if(diffConfig(oldVal, newVal)) {\n                    return true;\n                }\n            } else if(Array.isArray(oldVal) && Array.isArray(newVal)) {\n                if(oldVal.length !== newVal.length) {\n                    return true;\n                }\n                for(var i = 0; i < oldVal.length; i++) {\n                    if(oldVal[i] !== newVal[i]) {\n                        if(Lib.isPlainObject(oldVal[i]) && Lib.isPlainObject(newVal[i])) {\n                            if(diffConfig(oldVal[i], newVal[i])) {\n                                return true;\n                            }\n                        } else {\n                            return true;\n                        }\n                    }\n                }\n            } else {\n                return true;\n            }\n        }\n    }\n}\n\n/**\n * Animate to a frame, sequence of frame, frame group, or frame definition\n *\n * @param {string id or DOM element} gd\n *      the id or DOM element of the graph container div\n *\n * @param {string or object or array of strings or array of objects} frameOrGroupNameOrFrameList\n *      a single frame, array of frames, or group to which to animate. The intent is\n *      inferred by the type of the input. Valid inputs are:\n *\n *      - string, e.g. 'groupname': animate all frames of a given `group` in the order\n *            in which they are defined via `Plotly.addFrames`.\n *\n *      - array of strings, e.g. ['frame1', frame2']: a list of frames by name to which\n *            to animate in sequence\n *\n *      - object: {data: ...}: a frame definition to which to animate. The frame is not\n *            and does not need to be added via `Plotly.addFrames`. It may contain any of\n *            the properties of a frame, including `data`, `layout`, and `traces`. The\n *            frame is used as provided and does not use the `baseframe` property.\n *\n *      - array of objects, e.g. [{data: ...}, {data: ...}]: a list of frame objects,\n *            each following the same rules as a single `object`.\n *\n * @param {object} animationOpts\n *      configuration for the animation\n */\nfunction animate(gd, frameOrGroupNameOrFrameList, animationOpts) {\n    gd = Lib.getGraphDiv(gd);\n\n    if(!Lib.isPlotDiv(gd)) {\n        throw new Error(\n            'This element is not a Plotly plot: ' + gd + '. It\\'s likely that you\\'ve failed ' +\n            'to create a plot before animating it. For more details, see ' +\n            'https://plot.ly/javascript/animations/'\n        );\n    }\n\n    var trans = gd._transitionData;\n\n    // This is the queue of frames that will be animated as soon as possible. They\n    // are popped immediately upon the *start* of a transition:\n    if(!trans._frameQueue) {\n        trans._frameQueue = [];\n    }\n\n    animationOpts = Plots.supplyAnimationDefaults(animationOpts);\n    var transitionOpts = animationOpts.transition;\n    var frameOpts = animationOpts.frame;\n\n    // Since frames are popped immediately, an empty queue only means all frames have\n    // *started* to transition, not that the animation is complete. To solve that,\n    // track a separate counter that increments at the same time as frames are added\n    // to the queue, but decrements only when the transition is complete.\n    if(trans._frameWaitingCnt === undefined) {\n        trans._frameWaitingCnt = 0;\n    }\n\n    function getTransitionOpts(i) {\n        if(Array.isArray(transitionOpts)) {\n            if(i >= transitionOpts.length) {\n                return transitionOpts[0];\n            } else {\n                return transitionOpts[i];\n            }\n        } else {\n            return transitionOpts;\n        }\n    }\n\n    function getFrameOpts(i) {\n        if(Array.isArray(frameOpts)) {\n            if(i >= frameOpts.length) {\n                return frameOpts[0];\n            } else {\n                return frameOpts[i];\n            }\n        } else {\n            return frameOpts;\n        }\n    }\n\n    // Execute a callback after the wrapper function has been called n times.\n    // This is used to defer the resolution until a transition has resovled *and*\n    // the frame has completed. If it's not done this way, then we get a race\n    // condition in which the animation might resolve before a transition is complete\n    // or vice versa.\n    function callbackOnNthTime(cb, n) {\n        var cnt = 0;\n        return function() {\n            if(cb && ++cnt === n) {\n                return cb();\n            }\n        };\n    }\n\n    return new Promise(function(resolve, reject) {\n        function discardExistingFrames() {\n            if(trans._frameQueue.length === 0) {\n                return;\n            }\n\n            while(trans._frameQueue.length) {\n                var next = trans._frameQueue.pop();\n                if(next.onInterrupt) {\n                    next.onInterrupt();\n                }\n            }\n\n            gd.emit('plotly_animationinterrupted', []);\n        }\n\n        function queueFrames(frameList) {\n            if(frameList.length === 0) return;\n\n            for(var i = 0; i < frameList.length; i++) {\n                var computedFrame;\n\n                if(frameList[i].type === 'byname') {\n                    // If it's a named frame, compute it:\n                    computedFrame = Plots.computeFrame(gd, frameList[i].name);\n                } else {\n                    // Otherwise we must have been given a simple object, so treat\n                    // the input itself as the computed frame.\n                    computedFrame = frameList[i].data;\n                }\n\n                var frameOpts = getFrameOpts(i);\n                var transitionOpts = getTransitionOpts(i);\n\n                // It doesn't make much sense for the transition duration to be greater than\n                // the frame duration, so limit it:\n                transitionOpts.duration = Math.min(transitionOpts.duration, frameOpts.duration);\n\n                var nextFrame = {\n                    frame: computedFrame,\n                    name: frameList[i].name,\n                    frameOpts: frameOpts,\n                    transitionOpts: transitionOpts,\n                };\n                if(i === frameList.length - 1) {\n                    // The last frame in this .animate call stores the promise resolve\n                    // and reject callbacks. This is how we ensure that the animation\n                    // loop (which may exist as a result of a *different* .animate call)\n                    // still resolves or rejecdts this .animate call's promise. once it's\n                    // complete.\n                    nextFrame.onComplete = callbackOnNthTime(resolve, 2);\n                    nextFrame.onInterrupt = reject;\n                }\n\n                trans._frameQueue.push(nextFrame);\n            }\n\n            // Set it as never having transitioned to a frame. This will cause the animation\n            // loop to immediately transition to the next frame (which, for immediate mode,\n            // is the first frame in the list since all others would have been discarded\n            // below)\n            if(animationOpts.mode === 'immediate') {\n                trans._lastFrameAt = -Infinity;\n            }\n\n            // Only it's not already running, start a RAF loop. This could be avoided in the\n            // case that there's only one frame, but it significantly complicated the logic\n            // and only sped things up by about 5% or so for a lorenz attractor simulation.\n            // It would be a fine thing to implement, but the benefit of that optimization\n            // doesn't seem worth the extra complexity.\n            if(!trans._animationRaf) {\n                beginAnimationLoop();\n            }\n        }\n\n        function stopAnimationLoop() {\n            gd.emit('plotly_animated');\n\n            // Be sure to unset also since it's how we know whether a loop is already running:\n            window.cancelAnimationFrame(trans._animationRaf);\n            trans._animationRaf = null;\n        }\n\n        function nextFrame() {\n            if(trans._currentFrame && trans._currentFrame.onComplete) {\n                // Execute the callback and unset it to ensure it doesn't\n                // accidentally get called twice\n                trans._currentFrame.onComplete();\n            }\n\n            var newFrame = trans._currentFrame = trans._frameQueue.shift();\n\n            if(newFrame) {\n                // Since it's sometimes necessary to do deep digging into frame data,\n                // we'll consider it not 100% impossible for nulls or numbers to sneak through,\n                // so check when casting the name, just to be absolutely certain:\n                var stringName = newFrame.name ? newFrame.name.toString() : null;\n                gd._fullLayout._currentFrame = stringName;\n\n                trans._lastFrameAt = Date.now();\n                trans._timeToNext = newFrame.frameOpts.duration;\n\n                // This is simply called and it's left to .transition to decide how to manage\n                // interrupting current transitions. That means we don't need to worry about\n                // how it resolves or what happens after this:\n                Plots.transition(gd,\n                    newFrame.frame.data,\n                    newFrame.frame.layout,\n                    helpers.coerceTraceIndices(gd, newFrame.frame.traces),\n                    newFrame.frameOpts,\n                    newFrame.transitionOpts\n                ).then(function() {\n                    if(newFrame.onComplete) {\n                        newFrame.onComplete();\n                    }\n                });\n\n                gd.emit('plotly_animatingframe', {\n                    name: stringName,\n                    frame: newFrame.frame,\n                    animation: {\n                        frame: newFrame.frameOpts,\n                        transition: newFrame.transitionOpts,\n                    }\n                });\n            } else {\n                // If there are no more frames, then stop the RAF loop:\n                stopAnimationLoop();\n            }\n        }\n\n        function beginAnimationLoop() {\n            gd.emit('plotly_animating');\n\n            // If no timer is running, then set last frame = long ago so that the next\n            // frame is immediately transitioned:\n            trans._lastFrameAt = -Infinity;\n            trans._timeToNext = 0;\n            trans._runningTransitions = 0;\n            trans._currentFrame = null;\n\n            var doFrame = function() {\n                // This *must* be requested before nextFrame since nextFrame may decide\n                // to cancel it if there's nothing more to animated:\n                trans._animationRaf = window.requestAnimationFrame(doFrame);\n\n                // Check if we're ready for a new frame:\n                if(Date.now() - trans._lastFrameAt > trans._timeToNext) {\n                    nextFrame();\n                }\n            };\n\n            doFrame();\n        }\n\n        // This is an animate-local counter that helps match up option input list\n        // items with the particular frame.\n        var configCounter = 0;\n        function setTransitionConfig(frame) {\n            if(Array.isArray(transitionOpts)) {\n                if(configCounter >= transitionOpts.length) {\n                    frame.transitionOpts = transitionOpts[configCounter];\n                } else {\n                    frame.transitionOpts = transitionOpts[0];\n                }\n            } else {\n                frame.transitionOpts = transitionOpts;\n            }\n            configCounter++;\n            return frame;\n        }\n\n        // Disambiguate what's sort of frames have been received\n        var i, frame;\n        var frameList = [];\n        var allFrames = frameOrGroupNameOrFrameList === undefined || frameOrGroupNameOrFrameList === null;\n        var isFrameArray = Array.isArray(frameOrGroupNameOrFrameList);\n        var isSingleFrame = !allFrames && !isFrameArray && Lib.isPlainObject(frameOrGroupNameOrFrameList);\n\n        if(isSingleFrame) {\n            // In this case, a simple object has been passed to animate.\n            frameList.push({\n                type: 'object',\n                data: setTransitionConfig(Lib.extendFlat({}, frameOrGroupNameOrFrameList))\n            });\n        } else if(allFrames || ['string', 'number'].indexOf(typeof frameOrGroupNameOrFrameList) !== -1) {\n            // In this case, null or undefined has been passed so that we want to\n            // animate *all* currently defined frames\n            for(i = 0; i < trans._frames.length; i++) {\n                frame = trans._frames[i];\n\n                if(!frame) continue;\n\n                if(allFrames || String(frame.group) === String(frameOrGroupNameOrFrameList)) {\n                    frameList.push({\n                        type: 'byname',\n                        name: String(frame.name),\n                        data: setTransitionConfig({name: frame.name})\n                    });\n                }\n            }\n        } else if(isFrameArray) {\n            for(i = 0; i < frameOrGroupNameOrFrameList.length; i++) {\n                var frameOrName = frameOrGroupNameOrFrameList[i];\n                if(['number', 'string'].indexOf(typeof frameOrName) !== -1) {\n                    frameOrName = String(frameOrName);\n                    // In this case, there's an array and this frame is a string name:\n                    frameList.push({\n                        type: 'byname',\n                        name: frameOrName,\n                        data: setTransitionConfig({name: frameOrName})\n                    });\n                } else if(Lib.isPlainObject(frameOrName)) {\n                    frameList.push({\n                        type: 'object',\n                        data: setTransitionConfig(Lib.extendFlat({}, frameOrName))\n                    });\n                }\n            }\n        }\n\n        // Verify that all of these frames actually exist; return and reject if not:\n        for(i = 0; i < frameList.length; i++) {\n            frame = frameList[i];\n            if(frame.type === 'byname' && !trans._frameHash[frame.data.name]) {\n                Lib.warn('animate failure: frame not found: \"' + frame.data.name + '\"');\n                reject();\n                return;\n            }\n        }\n\n        // If the mode is either next or immediate, then all currently queued frames must\n        // be dumped and the corresponding .animate promises rejected.\n        if(['next', 'immediate'].indexOf(animationOpts.mode) !== -1) {\n            discardExistingFrames();\n        }\n\n        if(animationOpts.direction === 'reverse') {\n            frameList.reverse();\n        }\n\n        var currentFrame = gd._fullLayout._currentFrame;\n        if(currentFrame && animationOpts.fromcurrent) {\n            var idx = -1;\n            for(i = 0; i < frameList.length; i++) {\n                frame = frameList[i];\n                if(frame.type === 'byname' && frame.name === currentFrame) {\n                    idx = i;\n                    break;\n                }\n            }\n\n            if(idx > 0 && idx < frameList.length - 1) {\n                var filteredFrameList = [];\n                for(i = 0; i < frameList.length; i++) {\n                    frame = frameList[i];\n                    if(frameList[i].type !== 'byname' || i > idx) {\n                        filteredFrameList.push(frame);\n                    }\n                }\n                frameList = filteredFrameList;\n            }\n        }\n\n        if(frameList.length > 0) {\n            queueFrames(frameList);\n        } else {\n            // This is the case where there were simply no frames. It's a little strange\n            // since there's not much to do:\n            gd.emit('plotly_animated');\n            resolve();\n        }\n    });\n}\n\n/**\n * Register new frames\n *\n * @param {string id or DOM element} gd\n *      the id or DOM element of the graph container div\n *\n * @param {array of objects} frameList\n *      list of frame definitions, in which each object includes any of:\n *      - name: {string} name of frame to add\n *      - data: {array of objects} trace data\n *      - layout {object} layout definition\n *      - traces {array} trace indices\n *      - baseframe {string} name of frame from which this frame gets defaults\n *\n *  @param {array of integers} indices\n *      an array of integer indices matching the respective frames in `frameList`. If not\n *      provided, an index will be provided in serial order. If already used, the frame\n *      will be overwritten.\n */\nfunction addFrames(gd, frameList, indices) {\n    gd = Lib.getGraphDiv(gd);\n\n    if(frameList === null || frameList === undefined) {\n        return Promise.resolve();\n    }\n\n    if(!Lib.isPlotDiv(gd)) {\n        throw new Error(\n            'This element is not a Plotly plot: ' + gd + '. It\\'s likely that you\\'ve failed ' +\n            'to create a plot before adding frames. For more details, see ' +\n            'https://plot.ly/javascript/animations/'\n        );\n    }\n\n    var i, frame, j, idx;\n    var _frames = gd._transitionData._frames;\n    var _frameHash = gd._transitionData._frameHash;\n\n\n    if(!Array.isArray(frameList)) {\n        throw new Error('addFrames failure: frameList must be an Array of frame definitions' + frameList);\n    }\n\n    // Create a sorted list of insertions since we run into lots of problems if these\n    // aren't in ascending order of index:\n    //\n    // Strictly for sorting. Make sure this is guaranteed to never collide with any\n    // already-exisisting indices:\n    var bigIndex = _frames.length + frameList.length * 2;\n\n    var insertions = [];\n    var _frameHashLocal = {};\n    for(i = frameList.length - 1; i >= 0; i--) {\n        if(!Lib.isPlainObject(frameList[i])) continue;\n\n        // The entire logic for checking for this type of name collision can be removed once we migrate to ES6 and\n        // use a Map instead of an Object instance, as Map keys aren't converted to strings.\n        var lookupName = frameList[i].name;\n        var name = (_frameHash[lookupName] || _frameHashLocal[lookupName] || {}).name;\n        var newName = frameList[i].name;\n        var collisionPresent = _frameHash[name] || _frameHashLocal[name];\n\n        if(name && newName && typeof newName === 'number' && collisionPresent && numericNameWarningCount < numericNameWarningCountLimit) {\n            numericNameWarningCount++;\n\n            Lib.warn('addFrames: overwriting frame \"' + (_frameHash[name] || _frameHashLocal[name]).name +\n                '\" with a frame whose name of type \"number\" also equates to \"' +\n                name + '\". This is valid but may potentially lead to unexpected ' +\n                'behavior since all plotly.js frame names are stored internally ' +\n                'as strings.');\n\n            if(numericNameWarningCount === numericNameWarningCountLimit) {\n                Lib.warn('addFrames: This API call has yielded too many of these warnings. ' +\n                    'For the rest of this call, further warnings about numeric frame ' +\n                    'names will be suppressed.');\n            }\n        }\n\n        _frameHashLocal[lookupName] = {name: lookupName};\n\n        insertions.push({\n            frame: Plots.supplyFrameDefaults(frameList[i]),\n            index: (indices && indices[i] !== undefined && indices[i] !== null) ? indices[i] : bigIndex + i\n        });\n    }\n\n    // Sort this, taking note that undefined insertions end up at the end:\n    insertions.sort(function(a, b) {\n        if(a.index > b.index) return -1;\n        if(a.index < b.index) return 1;\n        return 0;\n    });\n\n    var ops = [];\n    var revops = [];\n    var frameCount = _frames.length;\n\n    for(i = insertions.length - 1; i >= 0; i--) {\n        frame = insertions[i].frame;\n\n        if(typeof frame.name === 'number') {\n            Lib.warn('Warning: addFrames accepts frames with numeric names, but the numbers are' +\n                'implicitly cast to strings');\n        }\n\n        if(!frame.name) {\n            // Repeatedly assign a default name, incrementing the counter each time until\n            // we get a name that's not in the hashed lookup table:\n            while(_frameHash[(frame.name = 'frame ' + gd._transitionData._counter++)]);\n        }\n\n        if(_frameHash[frame.name]) {\n            // If frame is present, overwrite its definition:\n            for(j = 0; j < _frames.length; j++) {\n                if((_frames[j] || {}).name === frame.name) break;\n            }\n            ops.push({type: 'replace', index: j, value: frame});\n            revops.unshift({type: 'replace', index: j, value: _frames[j]});\n        } else {\n            // Otherwise insert it at the end of the list:\n            idx = Math.max(0, Math.min(insertions[i].index, frameCount));\n\n            ops.push({type: 'insert', index: idx, value: frame});\n            revops.unshift({type: 'delete', index: idx});\n            frameCount++;\n        }\n    }\n\n    var undoFunc = Plots.modifyFrames;\n    var redoFunc = Plots.modifyFrames;\n    var undoArgs = [gd, revops];\n    var redoArgs = [gd, ops];\n\n    if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);\n\n    return Plots.modifyFrames(gd, ops);\n}\n\n/**\n * Delete frame\n *\n * @param {string id or DOM element} gd\n *      the id or DOM element of the graph container div\n *\n * @param {array of integers} frameList\n *      list of integer indices of frames to be deleted\n */\nfunction deleteFrames(gd, frameList) {\n    gd = Lib.getGraphDiv(gd);\n\n    if(!Lib.isPlotDiv(gd)) {\n        throw new Error('This element is not a Plotly plot: ' + gd);\n    }\n\n    var i, idx;\n    var _frames = gd._transitionData._frames;\n    var ops = [];\n    var revops = [];\n\n    if(!frameList) {\n        frameList = [];\n        for(i = 0; i < _frames.length; i++) {\n            frameList.push(i);\n        }\n    }\n\n    frameList = frameList.slice();\n    frameList.sort();\n\n    for(i = frameList.length - 1; i >= 0; i--) {\n        idx = frameList[i];\n        ops.push({type: 'delete', index: idx});\n        revops.unshift({type: 'insert', index: idx, value: _frames[idx]});\n    }\n\n    var undoFunc = Plots.modifyFrames;\n    var redoFunc = Plots.modifyFrames;\n    var undoArgs = [gd, revops];\n    var redoArgs = [gd, ops];\n\n    if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);\n\n    return Plots.modifyFrames(gd, ops);\n}\n\n/**\n * Purge a graph container div back to its initial pre-Plotly.plot state\n *\n * @param {string id or DOM element} gd\n *      the id or DOM element of the graph container div\n */\nfunction purge(gd) {\n    gd = Lib.getGraphDiv(gd);\n\n    var fullLayout = gd._fullLayout || {};\n    var fullData = gd._fullData || [];\n\n    // remove gl contexts\n    Plots.cleanPlot([], {}, fullData, fullLayout);\n\n    // purge properties\n    Plots.purge(gd);\n\n    // purge event emitter methods\n    Events.purge(gd);\n\n    // remove plot container\n    if(fullLayout._container) fullLayout._container.remove();\n\n    // in contrast to Plotly.Plots.purge which does NOT clear _context!\n    delete gd._context;\n\n    return gd;\n}\n\n// -------------------------------------------------------\n// makePlotFramework: Create the plot container and axes\n// -------------------------------------------------------\nfunction makePlotFramework(gd) {\n    var gd3 = d3.select(gd);\n    var fullLayout = gd._fullLayout;\n\n    // Plot container\n    fullLayout._container = gd3.selectAll('.plot-container').data([0]);\n    fullLayout._container.enter().insert('div', ':first-child')\n        .classed('plot-container', true)\n        .classed('plotly', true);\n\n    // Make the svg container\n    fullLayout._paperdiv = fullLayout._container.selectAll('.svg-container').data([0]);\n    fullLayout._paperdiv.enter().append('div')\n        .classed('svg-container', true)\n        .style('position', 'relative');\n\n    // Make the graph containers\n    // start fresh each time we get here, so we know the order comes out\n    // right, rather than enter/exit which can muck up the order\n    // TODO: sort out all the ordering so we don't have to\n    // explicitly delete anything\n    // FIXME: parcoords reuses this object, not the best pattern\n    fullLayout._glcontainer = fullLayout._paperdiv.selectAll('.gl-container')\n        .data([{}]);\n\n    fullLayout._glcontainer.enter().append('div')\n        .classed('gl-container', true);\n\n    fullLayout._paperdiv.selectAll('.main-svg').remove();\n    fullLayout._paperdiv.select('.modebar-container').remove();\n\n    fullLayout._paper = fullLayout._paperdiv.insert('svg', ':first-child')\n        .classed('main-svg', true);\n\n    fullLayout._toppaper = fullLayout._paperdiv.append('svg')\n        .classed('main-svg', true);\n\n    fullLayout._modebardiv = fullLayout._paperdiv.append('div');\n\n    fullLayout._hoverpaper = fullLayout._paperdiv.append('svg')\n        .classed('main-svg', true);\n\n    if(!fullLayout._uid) {\n        var otherUids = {};\n        d3.selectAll('defs').each(function() {\n            if(this.id) otherUids[this.id.split('-')[1]] = 1;\n        });\n        fullLayout._uid = Lib.randstr(otherUids);\n    }\n\n    fullLayout._paperdiv.selectAll('.main-svg')\n        .attr(xmlnsNamespaces.svgAttrs);\n\n    fullLayout._defs = fullLayout._paper.append('defs')\n        .attr('id', 'defs-' + fullLayout._uid);\n\n    fullLayout._clips = fullLayout._defs.append('g')\n        .classed('clips', true);\n\n    fullLayout._topdefs = fullLayout._toppaper.append('defs')\n        .attr('id', 'topdefs-' + fullLayout._uid);\n\n    fullLayout._topclips = fullLayout._topdefs.append('g')\n        .classed('clips', true);\n\n    fullLayout._bgLayer = fullLayout._paper.append('g')\n        .classed('bglayer', true);\n\n    fullLayout._draggers = fullLayout._paper.append('g')\n        .classed('draglayer', true);\n\n    // lower shape/image layer - note that this is behind\n    // all subplots data/grids but above the backgrounds\n    // except inset subplots, whose backgrounds are drawn\n    // inside their own group so that they appear above\n    // the data for the main subplot\n    // lower shapes and images which are fully referenced to\n    // a subplot still get drawn within the subplot's group\n    // so they will work correctly on insets\n    var layerBelow = fullLayout._paper.append('g')\n        .classed('layer-below', true);\n    fullLayout._imageLowerLayer = layerBelow.append('g')\n        .classed('imagelayer', true);\n    fullLayout._shapeLowerLayer = layerBelow.append('g')\n        .classed('shapelayer', true);\n\n    // single cartesian layer for the whole plot\n    fullLayout._cartesianlayer = fullLayout._paper.append('g').classed('cartesianlayer', true);\n\n    // single polar layer for the whole plot\n    fullLayout._polarlayer = fullLayout._paper.append('g').classed('polarlayer', true);\n\n    // single ternary layer for the whole plot\n    fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true);\n\n    // single geo layer for the whole plot\n    fullLayout._geolayer = fullLayout._paper.append('g').classed('geolayer', true);\n\n    // single funnelarea layer for the whole plot\n    fullLayout._funnelarealayer = fullLayout._paper.append('g').classed('funnelarealayer', true);\n\n    // single pie layer for the whole plot\n    fullLayout._pielayer = fullLayout._paper.append('g').classed('pielayer', true);\n\n    // single sunburst layer for the whole plot\n    fullLayout._sunburstlayer = fullLayout._paper.append('g').classed('sunburstlayer', true);\n\n    // single indicator layer for the whole plot\n    fullLayout._indicatorlayer = fullLayout._toppaper.append('g').classed('indicatorlayer', true);\n\n    // fill in image server scrape-svg\n    fullLayout._glimages = fullLayout._paper.append('g').classed('glimages', true);\n\n    // lastly upper shapes, info (legend, annotations) and hover layers go on top\n    // these are in a different svg element normally, but get collapsed into a single\n    // svg when exporting (after inserting 3D)\n    // upper shapes/images are only those drawn above the whole plot, including subplots\n    var layerAbove = fullLayout._toppaper.append('g')\n        .classed('layer-above', true);\n    fullLayout._imageUpperLayer = layerAbove.append('g')\n        .classed('imagelayer', true);\n    fullLayout._shapeUpperLayer = layerAbove.append('g')\n        .classed('shapelayer', true);\n\n    fullLayout._infolayer = fullLayout._toppaper.append('g').classed('infolayer', true);\n    fullLayout._menulayer = fullLayout._toppaper.append('g').classed('menulayer', true);\n    fullLayout._zoomlayer = fullLayout._toppaper.append('g').classed('zoomlayer', true);\n    fullLayout._hoverlayer = fullLayout._hoverpaper.append('g').classed('hoverlayer', true);\n\n    // Make the modebar container\n    fullLayout._modebardiv\n        .classed('modebar-container', true)\n        .style('position', 'absolute')\n        .style('top', '0px')\n        .style('right', '0px');\n\n    gd.emit('plotly_framework');\n}\n\nexports.animate = animate;\nexports.addFrames = addFrames;\nexports.deleteFrames = deleteFrames;\n\nexports.addTraces = addTraces;\nexports.deleteTraces = deleteTraces;\nexports.extendTraces = extendTraces;\nexports.moveTraces = moveTraces;\nexports.prependTraces = prependTraces;\n\nexports.newPlot = newPlot;\nexports.plot = plot;\nexports.purge = purge;\n\nexports.react = react;\nexports.redraw = redraw;\nexports.relayout = relayout;\nexports.restyle = restyle;\n\nexports.setPlotConfig = setPlotConfig;\n\nexports.update = update;\n\nexports._guiRelayout = guiEdit(relayout);\nexports._guiRestyle = guiEdit(restyle);\nexports._guiUpdate = guiEdit(update);\n\nexports._storeDirectGUIEdit = _storeDirectGUIEdit;\n\n},{\"../components/color\":593,\"../components/drawing\":614,\"../constants/xmlns_namespaces\":696,\"../lib\":719,\"../lib/events\":709,\"../lib/queue\":734,\"../lib/svg_text_utils\":743,\"../plots/cartesian/axes\":767,\"../plots/cartesian/constants\":773,\"../plots/cartesian/graph_interact\":776,\"../plots/cartesian/select\":784,\"../plots/plots\":828,\"../plots/polar/legacy\":836,\"../registry\":847,\"./edit_types\":750,\"./helpers\":751,\"./manage_arrays\":753,\"./plot_config\":755,\"./plot_schema\":756,\"./subroutines\":758,\"d3\":163,\"fast-isnumeric\":225,\"has-hover\":410}],755:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * This will be transferred over to gd and overridden by\n * config args to Plotly.plot.\n *\n * The defaults are the appropriate settings for plotly.js,\n * so we get the right experience without any config argument.\n *\n * N.B. the config options are not coerced using Lib.coerce so keys\n * like `valType` and `values` are only set for documentation purposes\n * at the moment.\n */\n\nvar configAttributes = {\n    staticPlot: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n\n    plotlyServerURL: {\n        valType: 'string',\n        dflt: 'https://plot.ly',\n        \n    },\n\n    editable: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n    edits: {\n        annotationPosition: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        annotationTail: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        annotationText: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        axisTitleText: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        colorbarPosition: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        colorbarTitleText: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        legendPosition: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        legendText: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        shapePosition: {\n            valType: 'boolean',\n            dflt: false,\n            \n        },\n        titleText: {\n            valType: 'boolean',\n            dflt: false,\n            \n        }\n    },\n\n    autosizable: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n    responsive: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n    fillFrame: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n    frameMargins: {\n        valType: 'number',\n        dflt: 0,\n        min: 0,\n        max: 0.5,\n        \n    },\n\n    scrollZoom: {\n        valType: 'flaglist',\n        flags: ['cartesian', 'gl3d', 'geo', 'mapbox'],\n        extras: [true, false],\n        dflt: 'gl3d+geo+mapbox',\n        \n    },\n    doubleClick: {\n        valType: 'enumerated',\n        values: [false, 'reset', 'autosize', 'reset+autosize'],\n        dflt: 'reset+autosize',\n        \n    },\n    doubleClickDelay: {\n        valType: 'number',\n        dflt: 300,\n        min: 0,\n        \n    },\n\n    showAxisDragHandles: {\n        valType: 'boolean',\n        dflt: true,\n        \n    },\n    showAxisRangeEntryBoxes: {\n        valType: 'boolean',\n        dflt: true,\n        \n    },\n\n    showTips: {\n        valType: 'boolean',\n        dflt: true,\n        \n    },\n\n    showLink: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n    linkText: {\n        valType: 'string',\n        dflt: 'Edit chart',\n        noBlank: true,\n        \n    },\n    sendData: {\n        valType: 'boolean',\n        dflt: true,\n        \n    },\n    showSources: {\n        valType: 'any',\n        dflt: false,\n        \n    },\n\n    displayModeBar: {\n        valType: 'enumerated',\n        values: ['hover', true, false],\n        dflt: 'hover',\n        \n    },\n    showSendToCloud: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n    showEditInChartStudio: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n    modeBarButtonsToRemove: {\n        valType: 'any',\n        dflt: [],\n        \n    },\n    modeBarButtonsToAdd: {\n        valType: 'any',\n        dflt: [],\n        \n    },\n    modeBarButtons: {\n        valType: 'any',\n        dflt: false,\n        \n    },\n    toImageButtonOptions: {\n        valType: 'any',\n        dflt: {},\n        \n    },\n    displaylogo: {\n        valType: 'boolean',\n        dflt: true,\n        \n    },\n    watermark: {\n        valType: 'boolean',\n        dflt: false,\n        \n    },\n\n    plotGlPixelRatio: {\n        valType: 'number',\n        dflt: 2,\n        min: 1,\n        max: 4,\n        \n    },\n\n    setBackground: {\n        valType: 'any',\n        dflt: 'transparent',\n        \n    },\n\n    topojsonURL: {\n        valType: 'string',\n        noBlank: true,\n        dflt: 'https://cdn.plot.ly/',\n        \n    },\n\n    mapboxAccessToken: {\n        valType: 'string',\n        dflt: null,\n        \n    },\n\n    logging: {\n        valType: 'boolean',\n        dflt: 1,\n        \n    },\n\n    queueLength: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n    },\n\n    globalTransforms: {\n        valType: 'any',\n        dflt: [],\n        \n    },\n\n    locale: {\n        valType: 'string',\n        dflt: 'en-US',\n        \n    },\n\n    locales: {\n        valType: 'any',\n        dflt: {},\n        \n    }\n};\n\nvar dfltConfig = {};\n\nfunction crawl(src, target) {\n    for(var k in src) {\n        var obj = src[k];\n        if(obj.valType) {\n            target[k] = obj.dflt;\n        } else {\n            if(!target[k]) {\n                target[k] = {};\n            }\n            crawl(obj, target[k]);\n        }\n    }\n}\n\ncrawl(configAttributes, dfltConfig);\n\nmodule.exports = {\n    configAttributes: configAttributes,\n    dfltConfig: dfltConfig\n};\n\n},{}],756:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../registry');\nvar Lib = _dereq_('../lib');\n\nvar baseAttributes = _dereq_('../plots/attributes');\nvar baseLayoutAttributes = _dereq_('../plots/layout_attributes');\nvar frameAttributes = _dereq_('../plots/frame_attributes');\nvar animationAttributes = _dereq_('../plots/animation_attributes');\nvar configAttributes = _dereq_('./plot_config').configAttributes;\n\n// polar attributes are not part of the Registry yet\nvar polarAreaAttrs = _dereq_('../plots/polar/legacy/area_attributes');\nvar polarAxisAttrs = _dereq_('../plots/polar/legacy/axis_attributes');\n\nvar editTypes = _dereq_('./edit_types');\n\nvar extendFlat = Lib.extendFlat;\nvar extendDeepAll = Lib.extendDeepAll;\nvar isPlainObject = Lib.isPlainObject;\nvar isArrayOrTypedArray = Lib.isArrayOrTypedArray;\nvar nestedProperty = Lib.nestedProperty;\nvar valObjectMeta = Lib.valObjectMeta;\n\nvar IS_SUBPLOT_OBJ = '_isSubplotObj';\nvar IS_LINKED_TO_ARRAY = '_isLinkedToArray';\nvar ARRAY_ATTR_REGEXPS = '_arrayAttrRegexps';\nvar DEPRECATED = '_deprecated';\nvar UNDERSCORE_ATTRS = [IS_SUBPLOT_OBJ, IS_LINKED_TO_ARRAY, ARRAY_ATTR_REGEXPS, DEPRECATED];\n\nexports.IS_SUBPLOT_OBJ = IS_SUBPLOT_OBJ;\nexports.IS_LINKED_TO_ARRAY = IS_LINKED_TO_ARRAY;\nexports.DEPRECATED = DEPRECATED;\nexports.UNDERSCORE_ATTRS = UNDERSCORE_ATTRS;\n\n/** Outputs the full plotly.js plot schema\n *\n * @return {object}\n *  - defs\n *  - traces\n *  - layout\n *  - transforms\n *  - frames\n *  - animations\n *  - config\n */\nexports.get = function() {\n    var traces = {};\n\n    Registry.allTypes.concat('area').forEach(function(type) {\n        traces[type] = getTraceAttributes(type);\n    });\n\n    var transforms = {};\n\n    Object.keys(Registry.transformsRegistry).forEach(function(type) {\n        transforms[type] = getTransformAttributes(type);\n    });\n\n    return {\n        defs: {\n            valObjects: valObjectMeta,\n            metaKeys: UNDERSCORE_ATTRS.concat(['description', 'role', 'editType', 'impliedEdits']),\n            editType: {\n                traces: editTypes.traces,\n                layout: editTypes.layout\n            },\n            impliedEdits: {\n                \n            }\n        },\n\n        traces: traces,\n        layout: getLayoutAttributes(),\n\n        transforms: transforms,\n\n        frames: getFramesAttributes(),\n        animation: formatAttributes(animationAttributes),\n\n        config: formatAttributes(configAttributes)\n    };\n};\n\n/**\n * Crawl the attribute tree, recursively calling a callback function\n *\n * @param {object} attrs\n *  The node of the attribute tree (e.g. the root) from which recursion originates\n * @param {Function} callback\n *  A callback function with the signature:\n *          @callback callback\n *          @param {object} attr an attribute\n *          @param {String} attrName name string\n *          @param {object[]} attrs all the attributes\n *          @param {Number} level the recursion level, 0 at the root\n *          @param {String} fullAttrString full attribute name (ie 'marker.line')\n * @param {Number} [specifiedLevel]\n *  The level in the tree, in order to let the callback function detect descend or backtrack,\n *  typically unsupplied (implied 0), just used by the self-recursive call.\n *  The necessity arises because the tree traversal is not controlled by callback return values.\n *  The decision to not use callback return values for controlling tree pruning arose from\n *  the goal of keeping the crawler backwards compatible. Observe that one of the pruning conditions\n *  precedes the callback call.\n * @param {string} [attrString]\n *  the path to the current attribute, as an attribute string (ie 'marker.line')\n *  typically unsupplied, but you may supply it if you want to disambiguate which attrs tree you\n *  are starting from\n *\n * @return {object} transformOut\n *  copy of transformIn that contains attribute defaults\n */\nexports.crawl = function(attrs, callback, specifiedLevel, attrString) {\n    var level = specifiedLevel || 0;\n    attrString = attrString || '';\n\n    Object.keys(attrs).forEach(function(attrName) {\n        var attr = attrs[attrName];\n\n        if(UNDERSCORE_ATTRS.indexOf(attrName) !== -1) return;\n\n        var fullAttrString = (attrString ? attrString + '.' : '') + attrName;\n        callback(attr, attrName, attrs, level, fullAttrString);\n\n        if(exports.isValObject(attr)) return;\n\n        if(isPlainObject(attr) && attrName !== 'impliedEdits') {\n            exports.crawl(attr, callback, level + 1, fullAttrString);\n        }\n    });\n};\n\n/** Is object a value object (or a container object)?\n *\n * @param {object} obj\n * @return {boolean}\n *  returns true for a valid value object and\n *  false for tree nodes in the attribute hierarchy\n */\nexports.isValObject = function(obj) {\n    return obj && obj.valType !== undefined;\n};\n\n/**\n * Find all data array attributes in a given trace object - including\n * `arrayOk` attributes.\n *\n * @param {object} trace\n *  full trace object that contains a reference to `_module.attributes`\n *\n * @return {array} arrayAttributes\n *  list of array attributes for the given trace\n */\nexports.findArrayAttributes = function(trace) {\n    var arrayAttributes = [];\n    var stack = [];\n    var isArrayStack = [];\n    var baseContainer, baseAttrName;\n\n    function callback(attr, attrName, attrs, level) {\n        stack = stack.slice(0, level).concat([attrName]);\n        isArrayStack = isArrayStack.slice(0, level).concat([attr && attr._isLinkedToArray]);\n\n        var splittableAttr = (\n            attr &&\n            (attr.valType === 'data_array' || attr.arrayOk === true) &&\n            !(stack[level - 1] === 'colorbar' && (attrName === 'ticktext' || attrName === 'tickvals'))\n        );\n\n        // Manually exclude 'colorbar.tickvals' and 'colorbar.ticktext' for now\n        // which are declared as `valType: 'data_array'` but scale independently of\n        // the coordinate arrays.\n        //\n        // Down the road, we might want to add a schema field (e.g `uncorrelatedArray: true`)\n        // to distinguish attributes of the likes.\n\n        if(!splittableAttr) return;\n\n        crawlIntoTrace(baseContainer, 0, '');\n    }\n\n    function crawlIntoTrace(container, i, astrPartial) {\n        var item = container[stack[i]];\n        var newAstrPartial = astrPartial + stack[i];\n        if(i === stack.length - 1) {\n            if(isArrayOrTypedArray(item)) {\n                arrayAttributes.push(baseAttrName + newAstrPartial);\n            }\n        } else {\n            if(isArrayStack[i]) {\n                if(Array.isArray(item)) {\n                    for(var j = 0; j < item.length; j++) {\n                        if(isPlainObject(item[j])) {\n                            crawlIntoTrace(item[j], i + 1, newAstrPartial + '[' + j + '].');\n                        }\n                    }\n                }\n            } else if(isPlainObject(item)) {\n                crawlIntoTrace(item, i + 1, newAstrPartial + '.');\n            }\n        }\n    }\n\n    baseContainer = trace;\n    baseAttrName = '';\n    exports.crawl(baseAttributes, callback);\n    if(trace._module && trace._module.attributes) {\n        exports.crawl(trace._module.attributes, callback);\n    }\n\n    var transforms = trace.transforms;\n    if(transforms) {\n        for(var i = 0; i < transforms.length; i++) {\n            var transform = transforms[i];\n            var module = transform._module;\n\n            if(module) {\n                baseAttrName = 'transforms[' + i + '].';\n                baseContainer = transform;\n\n                exports.crawl(module.attributes, callback);\n            }\n        }\n    }\n\n    return arrayAttributes;\n};\n\n/*\n * Find the valObject for one attribute in an existing trace\n *\n * @param {object} trace\n *  full trace object that contains a reference to `_module.attributes`\n * @param {object} parts\n *  an array of parts, like ['transforms', 1, 'value']\n *  typically from nestedProperty(...).parts\n *\n * @return {object|false}\n *  the valObject for this attribute, or the last found parent\n *  in some cases the innermost valObject will not exist, for example\n *  `valType: 'any'` attributes where we might set a part of the attribute.\n *  In that case, stop at the deepest valObject we *do* find.\n */\nexports.getTraceValObject = function(trace, parts) {\n    var head = parts[0];\n    var i = 1; // index to start recursing from\n    var moduleAttrs, valObject;\n\n    if(head === 'transforms') {\n        if(parts.length === 1) {\n            return baseAttributes.transforms;\n        }\n        var transforms = trace.transforms;\n        if(!Array.isArray(transforms) || !transforms.length) return false;\n        var tNum = parts[1];\n        if(!isIndex(tNum) || tNum >= transforms.length) {\n            return false;\n        }\n        moduleAttrs = (Registry.transformsRegistry[transforms[tNum].type] || {}).attributes;\n        valObject = moduleAttrs && moduleAttrs[parts[2]];\n        i = 3; // start recursing only inside the transform\n    } else if(trace.type === 'area') {\n        valObject = polarAreaAttrs[head];\n    } else {\n        // first look in the module for this trace\n        // components have already merged their trace attributes in here\n        var _module = trace._module;\n        if(!_module) _module = (Registry.modules[trace.type || baseAttributes.type.dflt] || {})._module;\n        if(!_module) return false;\n\n        moduleAttrs = _module.attributes;\n        valObject = moduleAttrs && moduleAttrs[head];\n\n        // then look in the subplot attributes\n        if(!valObject) {\n            var subplotModule = _module.basePlotModule;\n            if(subplotModule && subplotModule.attributes) {\n                valObject = subplotModule.attributes[head];\n            }\n        }\n\n        // finally look in the global attributes\n        if(!valObject) valObject = baseAttributes[head];\n    }\n\n    return recurseIntoValObject(valObject, parts, i);\n};\n\n/*\n * Find the valObject for one layout attribute\n *\n * @param {array} parts\n *  an array of parts, like ['annotations', 1, 'x']\n *  typically from nestedProperty(...).parts\n *\n * @return {object|false}\n *  the valObject for this attribute, or the last found parent\n *  in some cases the innermost valObject will not exist, for example\n *  `valType: 'any'` attributes where we might set a part of the attribute.\n *  In that case, stop at the deepest valObject we *do* find.\n */\nexports.getLayoutValObject = function(fullLayout, parts) {\n    var valObject = layoutHeadAttr(fullLayout, parts[0]);\n\n    return recurseIntoValObject(valObject, parts, 1);\n};\n\nfunction layoutHeadAttr(fullLayout, head) {\n    var i, key, _module, attributes;\n\n    // look for attributes of the subplot types used on the plot\n    var basePlotModules = fullLayout._basePlotModules;\n    if(basePlotModules) {\n        var out;\n        for(i = 0; i < basePlotModules.length; i++) {\n            _module = basePlotModules[i];\n            if(_module.attrRegex && _module.attrRegex.test(head)) {\n                // if a module defines overrides, these take precedence\n                // initially this is to allow gl2d different editTypes from svg cartesian\n                if(_module.layoutAttrOverrides) return _module.layoutAttrOverrides;\n\n                // otherwise take the first attributes we find\n                if(!out && _module.layoutAttributes) out = _module.layoutAttributes;\n            }\n\n            // a module can also override the behavior of base (and component) module layout attrs\n            // again see gl2d for initial use case\n            var baseOverrides = _module.baseLayoutAttrOverrides;\n            if(baseOverrides && head in baseOverrides) return baseOverrides[head];\n        }\n        if(out) return out;\n    }\n\n    // look for layout attributes contributed by traces on the plot\n    var modules = fullLayout._modules;\n    if(modules) {\n        for(i = 0; i < modules.length; i++) {\n            attributes = modules[i].layoutAttributes;\n            if(attributes && head in attributes) {\n                return attributes[head];\n            }\n        }\n    }\n\n    /*\n     * Next look in components.\n     * Components that define a schema have already merged this into\n     * base and subplot attribute defs, so ignore these.\n     * Others (older style) all put all their attributes\n     * inside a container matching the module `name`\n     * eg `attributes` (array) or `legend` (object)\n     */\n    for(key in Registry.componentsRegistry) {\n        _module = Registry.componentsRegistry[key];\n        if(_module.name === 'colorscale' && head.indexOf('coloraxis') === 0) {\n            return _module.layoutAttributes[head];\n        } else if(!_module.schema && (head === _module.name)) {\n            return _module.layoutAttributes;\n        }\n    }\n\n    if(head in baseLayoutAttributes) return baseLayoutAttributes[head];\n\n    // Polar doesn't populate _modules or _basePlotModules\n    // just fall back on these when the others fail\n    if(head === 'radialaxis' || head === 'angularaxis') {\n        return polarAxisAttrs[head];\n    }\n    return polarAxisAttrs.layout[head] || false;\n}\n\nfunction recurseIntoValObject(valObject, parts, i) {\n    if(!valObject) return false;\n\n    if(valObject._isLinkedToArray) {\n        // skip array index, abort if we try to dive into an array without an index\n        if(isIndex(parts[i])) i++;\n        else if(i < parts.length) return false;\n    }\n\n    // now recurse as far as we can. Occasionally we have an attribute\n    // setting an internal part below what's in the schema; just return\n    // the innermost schema item we find.\n    for(; i < parts.length; i++) {\n        var newValObject = valObject[parts[i]];\n        if(isPlainObject(newValObject)) valObject = newValObject;\n        else break;\n\n        if(i === parts.length - 1) break;\n\n        if(valObject._isLinkedToArray) {\n            i++;\n            if(!isIndex(parts[i])) return false;\n        } else if(valObject.valType === 'info_array') {\n            i++;\n            var index = parts[i];\n            if(!isIndex(index)) return false;\n\n            var items = valObject.items;\n            if(Array.isArray(items)) {\n                if(index >= items.length) return false;\n                if(valObject.dimensions === 2) {\n                    i++;\n                    if(parts.length === i) return valObject;\n                    var index2 = parts[i];\n                    if(!isIndex(index2)) return false;\n                    valObject = items[index][index2];\n                } else valObject = items[index];\n            } else {\n                valObject = items;\n            }\n        }\n    }\n\n    return valObject;\n}\n\n// note: this is different from Lib.isIndex, this one doesn't accept numeric\n// strings, only actual numbers.\nfunction isIndex(val) {\n    return val === Math.round(val) && val >= 0;\n}\n\nfunction getTraceAttributes(type) {\n    var _module, basePlotModule;\n\n    if(type === 'area') {\n        _module = { attributes: polarAreaAttrs };\n        basePlotModule = {};\n    } else {\n        _module = Registry.modules[type]._module,\n        basePlotModule = _module.basePlotModule;\n    }\n\n    var attributes = {};\n\n    // make 'type' the first attribute in the object\n    attributes.type = null;\n\n    var copyBaseAttributes = extendDeepAll({}, baseAttributes);\n    var copyModuleAttributes = extendDeepAll({}, _module.attributes);\n\n    // prune global-level trace attributes that are already defined in a trace\n    exports.crawl(copyModuleAttributes, function(attr, attrName, attrs, level, fullAttrString) {\n        nestedProperty(copyBaseAttributes, fullAttrString).set(undefined);\n        // Prune undefined attributes\n        if(attr === undefined) nestedProperty(copyModuleAttributes, fullAttrString).set(undefined);\n    });\n\n    // base attributes (same for all trace types)\n    extendDeepAll(attributes, copyBaseAttributes);\n\n    // prune-out base attributes based on trace module categories\n    if(Registry.traceIs(type, 'noOpacity')) {\n        delete attributes.opacity;\n    }\n    if(!Registry.traceIs(type, 'showLegend')) {\n        delete attributes.showlegend;\n        delete attributes.legendgroup;\n    }\n    if(Registry.traceIs(type, 'noHover')) {\n        delete attributes.hoverinfo;\n        delete attributes.hoverlabel;\n    }\n    if(!_module.selectPoints) {\n        delete attributes.selectedpoints;\n    }\n\n    // module attributes\n    extendDeepAll(attributes, copyModuleAttributes);\n\n    // subplot attributes\n    if(basePlotModule.attributes) {\n        extendDeepAll(attributes, basePlotModule.attributes);\n    }\n\n    // 'type' gets overwritten by baseAttributes; reset it here\n    attributes.type = type;\n\n    var out = {\n        meta: _module.meta || {},\n        categories: _module.categories || {},\n        animatable: Boolean(_module.animatable),\n        type: type,\n        attributes: formatAttributes(attributes),\n    };\n\n    // trace-specific layout attributes\n    if(_module.layoutAttributes) {\n        var layoutAttributes = {};\n\n        extendDeepAll(layoutAttributes, _module.layoutAttributes);\n        out.layoutAttributes = formatAttributes(layoutAttributes);\n    }\n\n    // drop anim:true in non-animatable modules\n    if(!_module.animatable) {\n        exports.crawl(out, function(attr) {\n            if(exports.isValObject(attr) && 'anim' in attr) {\n                delete attr.anim;\n            }\n        });\n    }\n\n    return out;\n}\n\nfunction getLayoutAttributes() {\n    var layoutAttributes = {};\n    var key, _module;\n\n    // global layout attributes\n    extendDeepAll(layoutAttributes, baseLayoutAttributes);\n\n    // add base plot module layout attributes\n    for(key in Registry.subplotsRegistry) {\n        _module = Registry.subplotsRegistry[key];\n\n        if(!_module.layoutAttributes) continue;\n\n        if(Array.isArray(_module.attr)) {\n            for(var i = 0; i < _module.attr.length; i++) {\n                handleBasePlotModule(layoutAttributes, _module, _module.attr[i]);\n            }\n        } else {\n            var astr = _module.attr === 'subplot' ? _module.name : _module.attr;\n            handleBasePlotModule(layoutAttributes, _module, astr);\n        }\n    }\n\n    // polar layout attributes\n    layoutAttributes = assignPolarLayoutAttrs(layoutAttributes);\n\n    // add registered components layout attributes\n    for(key in Registry.componentsRegistry) {\n        _module = Registry.componentsRegistry[key];\n        var schema = _module.schema;\n\n        if(schema && (schema.subplots || schema.layout)) {\n            /*\n             * Components with defined schema have already been merged in at register time\n             * but a few components define attributes that apply only to xaxis\n             * not yaxis (rangeselector, rangeslider) - delete from y schema.\n             * Note that the input attributes for xaxis/yaxis are the same object\n             * so it's not possible to only add them to xaxis from the start.\n             * If we ever have such asymmetry the other way, or anywhere else,\n             * we will need to extend both this code and mergeComponentAttrsToSubplot\n             * (which will not find yaxis only for example)\n             */\n            var subplots = schema.subplots;\n            if(subplots && subplots.xaxis && !subplots.yaxis) {\n                for(var xkey in subplots.xaxis) {\n                    delete layoutAttributes.yaxis[xkey];\n                }\n            }\n        } else if(_module.name === 'colorscale') {\n            extendDeepAll(layoutAttributes, _module.layoutAttributes);\n        } else if(_module.layoutAttributes) {\n            // older style without schema need to be explicitly merged in now\n            insertAttrs(layoutAttributes, _module.layoutAttributes, _module.name);\n        }\n    }\n\n    return {\n        layoutAttributes: formatAttributes(layoutAttributes)\n    };\n}\n\nfunction getTransformAttributes(type) {\n    var _module = Registry.transformsRegistry[type];\n    var attributes = extendDeepAll({}, _module.attributes);\n\n    // add registered components transform attributes\n    Object.keys(Registry.componentsRegistry).forEach(function(k) {\n        var _module = Registry.componentsRegistry[k];\n\n        if(_module.schema && _module.schema.transforms && _module.schema.transforms[type]) {\n            Object.keys(_module.schema.transforms[type]).forEach(function(v) {\n                insertAttrs(attributes, _module.schema.transforms[type][v], v);\n            });\n        }\n    });\n\n    return {\n        attributes: formatAttributes(attributes)\n    };\n}\n\nfunction getFramesAttributes() {\n    var attrs = {\n        frames: extendDeepAll({}, frameAttributes)\n    };\n\n    formatAttributes(attrs);\n\n    return attrs.frames;\n}\n\nfunction formatAttributes(attrs) {\n    mergeValTypeAndRole(attrs);\n    formatArrayContainers(attrs);\n    stringify(attrs);\n\n    return attrs;\n}\n\nfunction mergeValTypeAndRole(attrs) {\n    function makeSrcAttr(attrName) {\n        return {\n            valType: 'string',\n            \n            \n            editType: 'none'\n        };\n    }\n\n    function callback(attr, attrName, attrs) {\n        if(exports.isValObject(attr)) {\n            if(attr.valType === 'data_array') {\n                // all 'data_array' attrs have role 'data'\n                attr.role = 'data';\n                // all 'data_array' attrs have a corresponding 'src' attr\n                attrs[attrName + 'src'] = makeSrcAttr(attrName);\n            } else if(attr.arrayOk === true) {\n                // all 'arrayOk' attrs have a corresponding 'src' attr\n                attrs[attrName + 'src'] = makeSrcAttr(attrName);\n            }\n        } else if(isPlainObject(attr)) {\n            // all attrs container objects get role 'object'\n            attr.role = 'object';\n        }\n    }\n\n    exports.crawl(attrs, callback);\n}\n\nfunction formatArrayContainers(attrs) {\n    function callback(attr, attrName, attrs) {\n        if(!attr) return;\n\n        var itemName = attr[IS_LINKED_TO_ARRAY];\n\n        if(!itemName) return;\n\n        delete attr[IS_LINKED_TO_ARRAY];\n\n        attrs[attrName] = { items: {} };\n        attrs[attrName].items[itemName] = attr;\n        attrs[attrName].role = 'object';\n    }\n\n    exports.crawl(attrs, callback);\n}\n\n// this can take around 10ms and should only be run from PlotSchema.get(),\n// to ensure JSON.stringify(PlotSchema.get()) gives the intended result.\nfunction stringify(attrs) {\n    function walk(attr) {\n        for(var k in attr) {\n            if(isPlainObject(attr[k])) {\n                walk(attr[k]);\n            } else if(Array.isArray(attr[k])) {\n                for(var i = 0; i < attr[k].length; i++) {\n                    walk(attr[k][i]);\n                }\n            } else {\n                // as JSON.stringify(/test/) // => {}\n                if(attr[k] instanceof RegExp) {\n                    attr[k] = attr[k].toString();\n                }\n            }\n        }\n    }\n\n    walk(attrs);\n}\n\nfunction assignPolarLayoutAttrs(layoutAttributes) {\n    extendFlat(layoutAttributes, {\n        radialaxis: polarAxisAttrs.radialaxis,\n        angularaxis: polarAxisAttrs.angularaxis\n    });\n\n    extendFlat(layoutAttributes, polarAxisAttrs.layout);\n\n    return layoutAttributes;\n}\n\nfunction handleBasePlotModule(layoutAttributes, _module, astr) {\n    var np = nestedProperty(layoutAttributes, astr);\n    var attrs = extendDeepAll({}, _module.layoutAttributes);\n\n    attrs[IS_SUBPLOT_OBJ] = true;\n    np.set(attrs);\n}\n\nfunction insertAttrs(baseAttrs, newAttrs, astr) {\n    var np = nestedProperty(baseAttrs, astr);\n\n    np.set(extendDeepAll(np.get() || {}, newAttrs));\n}\n\n},{\"../lib\":719,\"../plots/animation_attributes\":762,\"../plots/attributes\":764,\"../plots/frame_attributes\":794,\"../plots/layout_attributes\":819,\"../plots/polar/legacy/area_attributes\":834,\"../plots/polar/legacy/axis_attributes\":835,\"../registry\":847,\"./edit_types\":750,\"./plot_config\":755}],757:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar plotAttributes = _dereq_('../plots/attributes');\n\nvar TEMPLATEITEMNAME = 'templateitemname';\n\nvar templateAttrs = {\n    name: {\n        valType: 'string',\n        \n        editType: 'none',\n        \n    }\n};\ntemplateAttrs[TEMPLATEITEMNAME] = {\n    valType: 'string',\n    \n    editType: 'calc',\n    \n};\n\n/**\n * templatedArray: decorate an attributes object with templating (and array)\n * properties.\n *\n * @param {string} name: the singular form of the array name. Sets\n *     `_isLinkedToArray` to this, so the schema knows to treat this as an array.\n * @param {object} attrs: the item attributes. Since all callers are expected\n *     to be constructing this object on the spot, we mutate it here for\n *     performance, rather than extending a new object with it.\n *\n * @returns {object}: the decorated `attrs` object\n */\nexports.templatedArray = function(name, attrs) {\n    attrs._isLinkedToArray = name;\n    attrs.name = templateAttrs.name;\n    attrs[TEMPLATEITEMNAME] = templateAttrs[TEMPLATEITEMNAME];\n    return attrs;\n};\n\n/**\n * traceTemplater: logic for matching traces to trace templates\n *\n * @param {object} dataTemplate: collection of {traceType: [{template}, ...]}\n *     ie each type the template applies to contains a list of template objects,\n *     to be provided cyclically to data traces of that type.\n *\n * @returns {object}: {newTrace}, a function:\n *     newTrace(traceIn): that takes the input traceIn, coerces its type, then\n *         uses that type to find the next template to apply. returns the output\n *         traceOut with template attached, ready to continue supplyDefaults.\n */\nexports.traceTemplater = function(dataTemplate) {\n    var traceCounts = {};\n    var traceType, typeTemplates;\n\n    for(traceType in dataTemplate) {\n        typeTemplates = dataTemplate[traceType];\n        if(Array.isArray(typeTemplates) && typeTemplates.length) {\n            traceCounts[traceType] = 0;\n        }\n    }\n\n    function newTrace(traceIn) {\n        traceType = Lib.coerce(traceIn, {}, plotAttributes, 'type');\n        var traceOut = {type: traceType, _template: null};\n        if(traceType in traceCounts) {\n            typeTemplates = dataTemplate[traceType];\n            // cycle through traces in the template set for this type\n            var typei = traceCounts[traceType] % typeTemplates.length;\n            traceCounts[traceType]++;\n            traceOut._template = typeTemplates[typei];\n        } else {\n            // TODO: anything we should do for types missing from the template?\n            // try to apply some other type? Or just bail as we do here?\n            // Actually I think yes, we should apply other types; would be nice\n            // if all scatter* could inherit from each other, and if histogram\n            // could inherit from bar, etc... but how to specify this? And do we\n            // compose them, or if a type is present require it to be complete?\n            // Actually this could apply to layout too - 3D annotations\n            // inheriting from 2D, axes of different types inheriting from each\n            // other...\n        }\n        return traceOut;\n    }\n\n    return {\n        newTrace: newTrace\n        // TODO: function to figure out what's left & what didn't work\n    };\n};\n\n/**\n * newContainer: Create a new sub-container inside `container` and propagate any\n * applicable template to it. If there's no template, still propagates\n * `undefined` so relinkPrivate will not retain an old template!\n *\n * @param {object} container: the outer container, should already have _template\n *     if there *is* a template for this plot\n * @param {string} name: the key of the new container to make\n * @param {string} baseName: if applicable, a base attribute to take the\n *     template from, ie for xaxis3 the base would be xaxis\n *\n * @returns {object}: an object for inclusion _full*, empty except for the\n *     appropriate template piece\n */\nexports.newContainer = function(container, name, baseName) {\n    var template = container._template;\n    var part = template && (template[name] || (baseName && template[baseName]));\n    if(!Lib.isPlainObject(part)) part = null;\n\n    var out = container[name] = {_template: part};\n    return out;\n};\n\n/**\n * arrayTemplater: special logic for templating both defaults and specific items\n * in a container array (annotations etc)\n *\n * @param {object} container: the outer container, should already have _template\n *     if there *is* a template for this plot\n * @param {string} name: the name of the array to template (ie 'annotations')\n *     will be used to find default ('annotationdefaults' object) and specific\n *     ('annotations' array) template specs.\n * @param {string} inclusionAttr: the attribute determining this item's\n *     inclusion in the output, usually 'visible' or 'enabled'\n *\n * @returns {object}: {newItem, defaultItems}, both functions:\n *     newItem(itemIn): create an output item, bare except for the correct\n *         template and name(s), as the base for supplyDefaults\n *     defaultItems(): to be called after all newItem calls, return any\n *         specific template items that have not already beeen included,\n *         also as bare output items ready for supplyDefaults.\n */\nexports.arrayTemplater = function(container, name, inclusionAttr) {\n    var template = container._template;\n    var defaultsTemplate = template && template[arrayDefaultKey(name)];\n    var templateItems = template && template[name];\n    if(!Array.isArray(templateItems) || !templateItems.length) {\n        templateItems = [];\n    }\n\n    var usedNames = {};\n\n    function newItem(itemIn) {\n        // include name and templateitemname in the output object for ALL\n        // container array items. Note: you could potentially use different\n        // name and templateitemname, if you're using one template to make\n        // another template. templateitemname would be the name in the original\n        // template, and name is the new \"subclassed\" item name.\n        var out = {name: itemIn.name, _input: itemIn};\n        var templateItemName = out[TEMPLATEITEMNAME] = itemIn[TEMPLATEITEMNAME];\n\n        // no itemname: use the default template\n        if(!validItemName(templateItemName)) {\n            out._template = defaultsTemplate;\n            return out;\n        }\n\n        // look for an item matching this itemname\n        // note these do not inherit from the default template, only the item.\n        for(var i = 0; i < templateItems.length; i++) {\n            var templateItem = templateItems[i];\n            if(templateItem.name === templateItemName) {\n                // Note: it's OK to use a template item more than once\n                // but using it at least once will stop it from generating\n                // a default item at the end.\n                usedNames[templateItemName] = 1;\n                out._template = templateItem;\n                return out;\n            }\n        }\n\n        // Didn't find a matching template item, so since this item is intended\n        // to only be modifications it's most likely broken. Hide it unless\n        // it's explicitly marked visible - in which case it gets NO template,\n        // not even the default.\n        out[inclusionAttr] = itemIn[inclusionAttr] || false;\n        // special falsy value we can look for in validateTemplate\n        out._template = false;\n        return out;\n    }\n\n    function defaultItems() {\n        var out = [];\n        for(var i = 0; i < templateItems.length; i++) {\n            var templateItem = templateItems[i];\n            var name = templateItem.name;\n            // only allow named items to be added as defaults,\n            // and only allow each name once\n            if(validItemName(name) && !usedNames[name]) {\n                var outi = {\n                    _template: templateItem,\n                    name: name,\n                    _input: {_templateitemname: name}\n                };\n                outi[TEMPLATEITEMNAME] = templateItem[TEMPLATEITEMNAME];\n                out.push(outi);\n                usedNames[name] = 1;\n            }\n        }\n        return out;\n    }\n\n    return {\n        newItem: newItem,\n        defaultItems: defaultItems\n    };\n};\n\nfunction validItemName(name) {\n    return name && typeof name === 'string';\n}\n\nfunction arrayDefaultKey(name) {\n    var lastChar = name.length - 1;\n    if(name.charAt(lastChar) !== 's') {\n        Lib.warn('bad argument to arrayDefaultKey: ' + name);\n    }\n    return name.substr(0, name.length - 1) + 'defaults';\n}\nexports.arrayDefaultKey = arrayDefaultKey;\n\n/**\n * arrayEditor: helper for editing array items that may have come from\n *     template defaults (in which case they will not exist in the input yet)\n *\n * @param {object} parentIn: the input container (eg gd.layout)\n * @param {string} containerStr: the attribute string for the container inside\n *     `parentIn`.\n * @param {object} itemOut: the _full* item (eg gd._fullLayout.annotations[0])\n *     that we'll be editing. Assumed to have been created by `arrayTemplater`.\n *\n * @returns {object}: {modifyBase, modifyItem, getUpdateObj, applyUpdate}, all functions:\n *     modifyBase(attr, value): Add an update that's *not* related to the item.\n *         `attr` is the full attribute string.\n *     modifyItem(attr, value): Add an update to the item. `attr` is just the\n *         portion of the attribute string inside the item.\n *     getUpdateObj(): Get the final constructed update object, to use in\n *         `restyle` or `relayout`. Also resets the update object in case this\n *         update was canceled.\n *     applyUpdate(attr, value): optionally add an update `attr: value`,\n *         then apply it to `parent` which should be the parent of `containerIn`,\n *         ie the object to which `containerStr` is the attribute string.\n */\nexports.arrayEditor = function(parentIn, containerStr, itemOut) {\n    var lengthIn = (Lib.nestedProperty(parentIn, containerStr).get() || []).length;\n    var index = itemOut._index;\n    // Check that we are indeed off the end of this container.\n    // Otherwise a devious user could put a key `_templateitemname` in their\n    // own input and break lots of things.\n    var templateItemName = (index >= lengthIn) && (itemOut._input || {})._templateitemname;\n    if(templateItemName) index = lengthIn;\n    var itemStr = containerStr + '[' + index + ']';\n\n    var update;\n    function resetUpdate() {\n        update = {};\n        if(templateItemName) {\n            update[itemStr] = {};\n            update[itemStr][TEMPLATEITEMNAME] = templateItemName;\n        }\n    }\n    resetUpdate();\n\n    function modifyBase(attr, value) {\n        update[attr] = value;\n    }\n\n    function modifyItem(attr, value) {\n        if(templateItemName) {\n            // we're making a new object: edit that object\n            Lib.nestedProperty(update[itemStr], attr).set(value);\n        } else {\n            // we're editing an existing object: include *just* the edit\n            update[itemStr + '.' + attr] = value;\n        }\n    }\n\n    function getUpdateObj() {\n        var updateOut = update;\n        resetUpdate();\n        return updateOut;\n    }\n\n    function applyUpdate(attr, value) {\n        if(attr) modifyItem(attr, value);\n        var updateToApply = getUpdateObj();\n        for(var key in updateToApply) {\n            Lib.nestedProperty(parentIn, key).set(updateToApply[key]);\n        }\n    }\n\n    return {\n        modifyBase: modifyBase,\n        modifyItem: modifyItem,\n        getUpdateObj: getUpdateObj,\n        applyUpdate: applyUpdate\n    };\n};\n\n},{\"../lib\":719,\"../plots/attributes\":764}],758:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Registry = _dereq_('../registry');\nvar Plots = _dereq_('../plots/plots');\n\nvar Lib = _dereq_('../lib');\nvar clearGlCanvases = _dereq_('../lib/clear_gl_canvases');\n\nvar Color = _dereq_('../components/color');\nvar Drawing = _dereq_('../components/drawing');\nvar Titles = _dereq_('../components/titles');\nvar ModeBar = _dereq_('../components/modebar');\n\nvar Axes = _dereq_('../plots/cartesian/axes');\nvar alignmentConstants = _dereq_('../constants/alignment');\nvar axisConstraints = _dereq_('../plots/cartesian/constraints');\nvar enforceAxisConstraints = axisConstraints.enforce;\nvar cleanAxisConstraints = axisConstraints.clean;\nvar doAutoRange = _dereq_('../plots/cartesian/autorange').doAutoRange;\n\nvar SVG_TEXT_ANCHOR_START = 'start';\nvar SVG_TEXT_ANCHOR_MIDDLE = 'middle';\nvar SVG_TEXT_ANCHOR_END = 'end';\n\nexports.layoutStyles = function(gd) {\n    return Lib.syncOrAsync([Plots.doAutoMargin, lsInner], gd);\n};\n\nfunction overlappingDomain(xDomain, yDomain, domains) {\n    for(var i = 0; i < domains.length; i++) {\n        var existingX = domains[i][0];\n        var existingY = domains[i][1];\n\n        if(existingX[0] >= xDomain[1] || existingX[1] <= xDomain[0]) {\n            continue;\n        }\n        if(existingY[0] < yDomain[1] && existingY[1] > yDomain[0]) {\n            return true;\n        }\n    }\n    return false;\n}\n\nfunction lsInner(gd) {\n    var fullLayout = gd._fullLayout;\n    var gs = fullLayout._size;\n    var pad = gs.p;\n    var axList = Axes.list(gd, '', true);\n    var i, subplot, plotinfo, ax, xa, ya;\n\n    fullLayout._paperdiv.style({\n        width: (gd._context.responsive && fullLayout.autosize && !gd._context._hasZeroWidth && !gd.layout.width) ? '100%' : fullLayout.width + 'px',\n        height: (gd._context.responsive && fullLayout.autosize && !gd._context._hasZeroHeight && !gd.layout.height) ? '100%' : fullLayout.height + 'px'\n    })\n    .selectAll('.main-svg')\n    .call(Drawing.setSize, fullLayout.width, fullLayout.height);\n    gd._context.setBackground(gd, fullLayout.paper_bgcolor);\n\n    exports.drawMainTitle(gd);\n    ModeBar.manage(gd);\n\n    // _has('cartesian') means SVG specifically, not GL2D - but GL2D\n    // can still get here because it makes some of the SVG structure\n    // for shared features like selections.\n    if(!fullLayout._has('cartesian')) {\n        return gd._promises.length && Promise.all(gd._promises);\n    }\n\n    function getLinePosition(ax, counterAx, side) {\n        var lwHalf = ax._lw / 2;\n\n        if(ax._id.charAt(0) === 'x') {\n            if(!counterAx) return gs.t + gs.h * (1 - (ax.position || 0)) + (lwHalf % 1);\n            else if(side === 'top') return counterAx._offset - pad - lwHalf;\n            return counterAx._offset + counterAx._length + pad + lwHalf;\n        }\n\n        if(!counterAx) return gs.l + gs.w * (ax.position || 0) + (lwHalf % 1);\n        else if(side === 'right') return counterAx._offset + counterAx._length + pad + lwHalf;\n        return counterAx._offset - pad - lwHalf;\n    }\n\n    // some preparation of axis position info\n    for(i = 0; i < axList.length; i++) {\n        ax = axList[i];\n\n        var counterAx = ax._anchorAxis;\n\n        // clear axis line positions, to be set in the subplot loop below\n        ax._linepositions = {};\n\n        // stash crispRounded linewidth so we don't need to pass gd all over the place\n        ax._lw = Drawing.crispRound(gd, ax.linewidth, 1);\n\n        // figure out the main axis line and main mirror line position.\n        // it's easier to follow the logic if we handle these separately from\n        // ax._linepositions, which are only used by mirror=allticks\n        // for non-main-subplot ticks, and mirror=all(ticks)? for zero line\n        // hiding logic\n        ax._mainLinePosition = getLinePosition(ax, counterAx, ax.side);\n        ax._mainMirrorPosition = (ax.mirror && counterAx) ?\n            getLinePosition(ax, counterAx,\n                alignmentConstants.OPPOSITE_SIDE[ax.side]) : null;\n    }\n\n    // figure out which backgrounds we need to draw,\n    // and in which layers to put them\n    var lowerBackgroundIDs = [];\n    var backgroundIds = [];\n    var lowerDomains = [];\n    // no need to draw background when paper and plot color are the same color,\n    // activate mode just for large splom (which benefit the most from this\n    // optimization), but this could apply to all cartesian subplots.\n    var noNeedForBg = (\n        Color.opacity(fullLayout.paper_bgcolor) === 1 &&\n        Color.opacity(fullLayout.plot_bgcolor) === 1 &&\n        fullLayout.paper_bgcolor === fullLayout.plot_bgcolor\n    );\n\n    for(subplot in fullLayout._plots) {\n        plotinfo = fullLayout._plots[subplot];\n\n        if(plotinfo.mainplot) {\n            // mainplot is a reference to the main plot this one is overlaid on\n            // so if it exists, this is an overlaid plot and we don't need to\n            // give it its own background\n            if(plotinfo.bg) {\n                plotinfo.bg.remove();\n            }\n            plotinfo.bg = undefined;\n        } else {\n            var xDomain = plotinfo.xaxis.domain;\n            var yDomain = plotinfo.yaxis.domain;\n            var plotgroup = plotinfo.plotgroup;\n\n            if(overlappingDomain(xDomain, yDomain, lowerDomains)) {\n                var pgNode = plotgroup.node();\n                var plotgroupBg = plotinfo.bg = Lib.ensureSingle(plotgroup, 'rect', 'bg');\n                pgNode.insertBefore(plotgroupBg.node(), pgNode.childNodes[0]);\n                backgroundIds.push(subplot);\n            } else {\n                plotgroup.select('rect.bg').remove();\n                lowerDomains.push([xDomain, yDomain]);\n                if(!noNeedForBg) {\n                    lowerBackgroundIDs.push(subplot);\n                    backgroundIds.push(subplot);\n                }\n            }\n        }\n    }\n\n    // now create all the lower-layer backgrounds at once now that\n    // we have the list of subplots that need them\n    var lowerBackgrounds = fullLayout._bgLayer.selectAll('.bg')\n        .data(lowerBackgroundIDs);\n\n    lowerBackgrounds.enter().append('rect')\n        .classed('bg', true);\n\n    lowerBackgrounds.exit().remove();\n\n    lowerBackgrounds.each(function(subplot) {\n        fullLayout._plots[subplot].bg = d3.select(this);\n    });\n\n    // style all backgrounds\n    for(i = 0; i < backgroundIds.length; i++) {\n        plotinfo = fullLayout._plots[backgroundIds[i]];\n        xa = plotinfo.xaxis;\n        ya = plotinfo.yaxis;\n\n        if(plotinfo.bg) {\n            plotinfo.bg\n                .call(Drawing.setRect,\n                    xa._offset - pad, ya._offset - pad,\n                    xa._length + 2 * pad, ya._length + 2 * pad)\n                .call(Color.fill, fullLayout.plot_bgcolor)\n                .style('stroke-width', 0);\n        }\n    }\n\n    if(!fullLayout._hasOnlyLargeSploms) {\n        for(subplot in fullLayout._plots) {\n            plotinfo = fullLayout._plots[subplot];\n            xa = plotinfo.xaxis;\n            ya = plotinfo.yaxis;\n\n            // Clip so that data only shows up on the plot area.\n            var clipId = plotinfo.clipId = 'clip' + fullLayout._uid + subplot + 'plot';\n\n            var plotClip = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipId, function(s) {\n                s.classed('plotclip', true)\n                    .append('rect');\n            });\n\n            plotinfo.clipRect = plotClip.select('rect').attr({\n                width: xa._length,\n                height: ya._length\n            });\n\n            Drawing.setTranslate(plotinfo.plot, xa._offset, ya._offset);\n\n            var plotClipId;\n            var layerClipId;\n\n            if(plotinfo._hasClipOnAxisFalse) {\n                plotClipId = null;\n                layerClipId = clipId;\n            } else {\n                plotClipId = clipId;\n                layerClipId = null;\n            }\n\n            Drawing.setClipUrl(plotinfo.plot, plotClipId, gd);\n\n            // stash layer clipId value (null or same as clipId)\n            // to DRY up Drawing.setClipUrl calls on trace-module and trace layers\n            // downstream\n            plotinfo.layerClipId = layerClipId;\n        }\n    }\n\n    var xLinesXLeft, xLinesXRight, xLinesYBottom, xLinesYTop,\n        leftYLineWidth, rightYLineWidth;\n    var yLinesYBottom, yLinesYTop, yLinesXLeft, yLinesXRight,\n        connectYBottom, connectYTop;\n    var extraSubplot;\n\n    function xLinePath(y) {\n        return 'M' + xLinesXLeft + ',' + y + 'H' + xLinesXRight;\n    }\n\n    function xLinePathFree(y) {\n        return 'M' + xa._offset + ',' + y + 'h' + xa._length;\n    }\n\n    function yLinePath(x) {\n        return 'M' + x + ',' + yLinesYTop + 'V' + yLinesYBottom;\n    }\n\n    function yLinePathFree(x) {\n        return 'M' + x + ',' + ya._offset + 'v' + ya._length;\n    }\n\n    function mainPath(ax, pathFn, pathFnFree) {\n        if(!ax.showline || subplot !== ax._mainSubplot) return '';\n        if(!ax._anchorAxis) return pathFnFree(ax._mainLinePosition);\n        var out = pathFn(ax._mainLinePosition);\n        if(ax.mirror) out += pathFn(ax._mainMirrorPosition);\n        return out;\n    }\n\n    for(subplot in fullLayout._plots) {\n        plotinfo = fullLayout._plots[subplot];\n        xa = plotinfo.xaxis;\n        ya = plotinfo.yaxis;\n\n        /*\n         * x lines get longer where they meet y lines, to make a crisp corner.\n         * The x lines get the padding (margin.pad) plus the y line width to\n         * fill up the corner nicely. Free x lines are excluded - they always\n         * span exactly the data area of the plot\n         *\n         *  | XXXXX\n         *  | XXXXX\n         *  |\n         *  +------\n         *     x1\n         *    -----\n         *     x2\n         */\n        var xPath = 'M0,0';\n        if(shouldShowLinesOrTicks(xa, subplot)) {\n            leftYLineWidth = findCounterAxisLineWidth(xa, 'left', ya, axList);\n            xLinesXLeft = xa._offset - (leftYLineWidth ? (pad + leftYLineWidth) : 0);\n            rightYLineWidth = findCounterAxisLineWidth(xa, 'right', ya, axList);\n            xLinesXRight = xa._offset + xa._length + (rightYLineWidth ? (pad + rightYLineWidth) : 0);\n            xLinesYBottom = getLinePosition(xa, ya, 'bottom');\n            xLinesYTop = getLinePosition(xa, ya, 'top');\n\n            // save axis line positions for extra ticks to reference\n            // each subplot that gets ticks from \"allticks\" gets an entry:\n            //    [left or bottom, right or top]\n            extraSubplot = (!xa._anchorAxis || subplot !== xa._mainSubplot);\n            if(extraSubplot && (xa.mirror === 'allticks' || xa.mirror === 'all')) {\n                xa._linepositions[subplot] = [xLinesYBottom, xLinesYTop];\n            }\n\n            xPath = mainPath(xa, xLinePath, xLinePathFree);\n            if(extraSubplot && xa.showline && (xa.mirror === 'all' || xa.mirror === 'allticks')) {\n                xPath += xLinePath(xLinesYBottom) + xLinePath(xLinesYTop);\n            }\n\n            plotinfo.xlines\n                .style('stroke-width', xa._lw + 'px')\n                .call(Color.stroke, xa.showline ?\n                    xa.linecolor : 'rgba(0,0,0,0)');\n        }\n        plotinfo.xlines.attr('d', xPath);\n\n        /*\n         * y lines that meet x axes get longer only by margin.pad, because\n         * the x axes fill in the corner space. Free y axes, like free x axes,\n         * always span exactly the data area of the plot\n         *\n         *   |   | XXXX\n         * y2| y1| XXXX\n         *   |   | XXXX\n         *       |\n         *       +-----\n         */\n        var yPath = 'M0,0';\n        if(shouldShowLinesOrTicks(ya, subplot)) {\n            connectYBottom = findCounterAxisLineWidth(ya, 'bottom', xa, axList);\n            yLinesYBottom = ya._offset + ya._length + (connectYBottom ? pad : 0);\n            connectYTop = findCounterAxisLineWidth(ya, 'top', xa, axList);\n            yLinesYTop = ya._offset - (connectYTop ? pad : 0);\n            yLinesXLeft = getLinePosition(ya, xa, 'left');\n            yLinesXRight = getLinePosition(ya, xa, 'right');\n\n            extraSubplot = (!ya._anchorAxis || subplot !== ya._mainSubplot);\n            if(extraSubplot && (ya.mirror === 'allticks' || ya.mirror === 'all')) {\n                ya._linepositions[subplot] = [yLinesXLeft, yLinesXRight];\n            }\n\n            yPath = mainPath(ya, yLinePath, yLinePathFree);\n            if(extraSubplot && ya.showline && (ya.mirror === 'all' || ya.mirror === 'allticks')) {\n                yPath += yLinePath(yLinesXLeft) + yLinePath(yLinesXRight);\n            }\n\n            plotinfo.ylines\n                .style('stroke-width', ya._lw + 'px')\n                .call(Color.stroke, ya.showline ?\n                    ya.linecolor : 'rgba(0,0,0,0)');\n        }\n        plotinfo.ylines.attr('d', yPath);\n    }\n\n    Axes.makeClipPaths(gd);\n\n    return gd._promises.length && Promise.all(gd._promises);\n}\n\nfunction shouldShowLinesOrTicks(ax, subplot) {\n    return (ax.ticks || ax.showline) &&\n        (subplot === ax._mainSubplot || ax.mirror === 'all' || ax.mirror === 'allticks');\n}\n\n/*\n * should we draw a line on counterAx at this side of ax?\n * It's assumed that counterAx is known to overlay the subplot we're working on\n * but it may not be its main axis.\n */\nfunction shouldShowLineThisSide(ax, side, counterAx) {\n    // does counterAx get a line at all?\n    if(!counterAx.showline || !counterAx._lw) return false;\n\n    // are we drawing *all* lines for counterAx?\n    if(counterAx.mirror === 'all' || counterAx.mirror === 'allticks') return true;\n\n    var anchorAx = counterAx._anchorAxis;\n\n    // is this a free axis? free axes can only have a subplot side-line with all(ticks)? mirroring\n    if(!anchorAx) return false;\n\n    // in order to handle cases where the user forgot to anchor this axis correctly\n    // (because its default anchor has the same domain on the relevant end)\n    // check whether the relevant position is the same.\n    var sideIndex = alignmentConstants.FROM_BL[side];\n    if(counterAx.side === side) {\n        return anchorAx.domain[sideIndex] === ax.domain[sideIndex];\n    }\n    return counterAx.mirror && anchorAx.domain[1 - sideIndex] === ax.domain[1 - sideIndex];\n}\n\n/*\n * Is there another axis intersecting `side` end of `ax`?\n * First look at `counterAx` (the axis for this subplot),\n * then at all other potential counteraxes on or overlaying this subplot.\n * Take the line width from the first one that has a line.\n */\nfunction findCounterAxisLineWidth(ax, side, counterAx, axList) {\n    if(shouldShowLineThisSide(ax, side, counterAx)) {\n        return counterAx._lw;\n    }\n    for(var i = 0; i < axList.length; i++) {\n        var axi = axList[i];\n        if(axi._mainAxis === counterAx._mainAxis && shouldShowLineThisSide(ax, side, axi)) {\n            return axi._lw;\n        }\n    }\n    return 0;\n}\n\nexports.drawMainTitle = function(gd) {\n    var fullLayout = gd._fullLayout;\n\n    var textAnchor = getMainTitleTextAnchor(fullLayout);\n    var dy = getMainTitleDy(fullLayout);\n\n    Titles.draw(gd, 'gtitle', {\n        propContainer: fullLayout,\n        propName: 'title.text',\n        placeholder: fullLayout._dfltTitle.plot,\n        attributes: {\n            x: getMainTitleX(fullLayout, textAnchor),\n            y: getMainTitleY(fullLayout, dy),\n            'text-anchor': textAnchor,\n            dy: dy\n        }\n    });\n};\n\nfunction getMainTitleX(fullLayout, textAnchor) {\n    var title = fullLayout.title;\n    var gs = fullLayout._size;\n    var hPadShift = 0;\n\n    if(textAnchor === SVG_TEXT_ANCHOR_START) {\n        hPadShift = title.pad.l;\n    } else if(textAnchor === SVG_TEXT_ANCHOR_END) {\n        hPadShift = -title.pad.r;\n    }\n\n    switch(title.xref) {\n        case 'paper':\n            return gs.l + gs.w * title.x + hPadShift;\n        case 'container':\n        default:\n            return fullLayout.width * title.x + hPadShift;\n    }\n}\n\nfunction getMainTitleY(fullLayout, dy) {\n    var title = fullLayout.title;\n    var gs = fullLayout._size;\n    var vPadShift = 0;\n\n    if(dy === '0em' || !dy) {\n        vPadShift = -title.pad.b;\n    } else if(dy === alignmentConstants.CAP_SHIFT + 'em') {\n        vPadShift = title.pad.t;\n    }\n\n    if(title.y === 'auto') {\n        return gs.t / 2;\n    } else {\n        switch(title.yref) {\n            case 'paper':\n                return gs.t + gs.h - gs.h * title.y + vPadShift;\n            case 'container':\n            default:\n                return fullLayout.height - fullLayout.height * title.y + vPadShift;\n        }\n    }\n}\n\nfunction getMainTitleTextAnchor(fullLayout) {\n    var title = fullLayout.title;\n\n    var textAnchor = SVG_TEXT_ANCHOR_MIDDLE;\n    if(Lib.isRightAnchor(title)) {\n        textAnchor = SVG_TEXT_ANCHOR_END;\n    } else if(Lib.isLeftAnchor(title)) {\n        textAnchor = SVG_TEXT_ANCHOR_START;\n    }\n\n    return textAnchor;\n}\n\nfunction getMainTitleDy(fullLayout) {\n    var title = fullLayout.title;\n\n    var dy = '0em';\n    if(Lib.isTopAnchor(title)) {\n        dy = alignmentConstants.CAP_SHIFT + 'em';\n    } else if(Lib.isMiddleAnchor(title)) {\n        dy = alignmentConstants.MID_SHIFT + 'em';\n    }\n\n    return dy;\n}\n\nexports.doTraceStyle = function(gd) {\n    var calcdata = gd.calcdata;\n    var editStyleCalls = [];\n    var i;\n\n    for(i = 0; i < calcdata.length; i++) {\n        var cd = calcdata[i];\n        var cd0 = cd[0] || {};\n        var trace = cd0.trace || {};\n        var _module = trace._module || {};\n\n        // See if we need to do arraysToCalcdata\n        // call it regardless of what change we made, in case\n        // supplyDefaults brought in an array that was already\n        // in gd.data but not in gd._fullData previously\n        var arraysToCalcdata = _module.arraysToCalcdata;\n        if(arraysToCalcdata) arraysToCalcdata(cd, trace);\n\n        var editStyle = _module.editStyle;\n        if(editStyle) editStyleCalls.push({fn: editStyle, cd0: cd0});\n    }\n\n    if(editStyleCalls.length) {\n        for(i = 0; i < editStyleCalls.length; i++) {\n            var edit = editStyleCalls[i];\n            edit.fn(gd, edit.cd0);\n        }\n        clearGlCanvases(gd);\n        exports.redrawReglTraces(gd);\n    }\n\n    Plots.style(gd);\n    Registry.getComponentMethod('legend', 'draw')(gd);\n\n    return Plots.previousPromises(gd);\n};\n\nexports.doColorBars = function(gd) {\n    Registry.getComponentMethod('colorbar', 'draw')(gd);\n    return Plots.previousPromises(gd);\n};\n\n// force plot() to redo the layout and replot with the modified layout\nexports.layoutReplot = function(gd) {\n    var layout = gd.layout;\n    gd.layout = undefined;\n    return Registry.call('plot', gd, '', layout);\n};\n\nexports.doLegend = function(gd) {\n    Registry.getComponentMethod('legend', 'draw')(gd);\n    return Plots.previousPromises(gd);\n};\n\nexports.doTicksRelayout = function(gd) {\n    Axes.draw(gd, 'redraw');\n\n    if(gd._fullLayout._hasOnlyLargeSploms) {\n        Registry.subplotsRegistry.splom.updateGrid(gd);\n        clearGlCanvases(gd);\n        exports.redrawReglTraces(gd);\n    }\n\n    exports.drawMainTitle(gd);\n    return Plots.previousPromises(gd);\n};\n\nexports.doModeBar = function(gd) {\n    var fullLayout = gd._fullLayout;\n\n    ModeBar.manage(gd);\n\n    for(var i = 0; i < fullLayout._basePlotModules.length; i++) {\n        var updateFx = fullLayout._basePlotModules[i].updateFx;\n        if(updateFx) updateFx(gd);\n    }\n\n    return Plots.previousPromises(gd);\n};\n\nexports.doCamera = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var sceneIds = fullLayout._subplots.gl3d;\n\n    for(var i = 0; i < sceneIds.length; i++) {\n        var sceneLayout = fullLayout[sceneIds[i]];\n        var scene = sceneLayout._scene;\n\n        var cameraData = sceneLayout.camera;\n        scene.setCamera(cameraData);\n    }\n};\n\nexports.drawData = function(gd) {\n    var fullLayout = gd._fullLayout;\n\n    clearGlCanvases(gd);\n\n    // loop over the base plot modules present on graph\n    var basePlotModules = fullLayout._basePlotModules;\n    for(var i = 0; i < basePlotModules.length; i++) {\n        basePlotModules[i].plot(gd);\n    }\n\n    exports.redrawReglTraces(gd);\n\n    // styling separate from drawing\n    Plots.style(gd);\n\n    // show annotations and shapes\n    Registry.getComponentMethod('shapes', 'draw')(gd);\n    Registry.getComponentMethod('annotations', 'draw')(gd);\n\n    // Mark the first render as complete\n    fullLayout._replotting = false;\n\n    return Plots.previousPromises(gd);\n};\n\n// Draw (or redraw) all regl-based traces in one go,\n// useful during drag and selection where buffers of targeted traces are updated,\n// but all traces need to be redrawn following clearGlCanvases.\n//\n// Note that _module.plot for regl trace does NOT draw things\n// on the canvas, they only update the buffers.\n// Drawing is perform here.\n//\n// TODO try adding per-subplot option using gl.SCISSOR_TEST for\n// non-overlaying, disjoint subplots.\n//\n// TODO try to include parcoords in here.\n// https://github.com/plotly/plotly.js/issues/3069\nexports.redrawReglTraces = function(gd) {\n    var fullLayout = gd._fullLayout;\n\n    if(fullLayout._has('regl')) {\n        var fullData = gd._fullData;\n        var cartesianIds = [];\n        var polarIds = [];\n        var i, sp;\n\n        if(fullLayout._hasOnlyLargeSploms) {\n            fullLayout._splomGrid.draw();\n        }\n\n        // N.B.\n        // - Loop over fullData (not _splomScenes) to preserve splom trace-to-trace ordering\n        // - Fill list if subplot ids (instead of fullLayout._subplots) to handle cases where all traces\n        //   of a given module are `visible !== true`\n        for(i = 0; i < fullData.length; i++) {\n            var trace = fullData[i];\n\n            if(trace.visible === true && trace._length !== 0) {\n                if(trace.type === 'splom') {\n                    fullLayout._splomScenes[trace.uid].draw();\n                } else if(trace.type === 'scattergl') {\n                    Lib.pushUnique(cartesianIds, trace.xaxis + trace.yaxis);\n                } else if(trace.type === 'scatterpolargl') {\n                    Lib.pushUnique(polarIds, trace.subplot);\n                }\n            }\n        }\n\n        for(i = 0; i < cartesianIds.length; i++) {\n            sp = fullLayout._plots[cartesianIds[i]];\n            if(sp._scene) sp._scene.draw();\n        }\n\n        for(i = 0; i < polarIds.length; i++) {\n            sp = fullLayout[polarIds[i]]._subplot;\n            if(sp._scene) sp._scene.draw();\n        }\n    }\n};\n\nexports.doAutoRangeAndConstraints = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var axList = Axes.list(gd, '', true);\n    var matchGroups = fullLayout._axisMatchGroups || [];\n    var ax;\n    var axRng;\n\n    for(var i = 0; i < axList.length; i++) {\n        ax = axList[i];\n        cleanAxisConstraints(gd, ax);\n        doAutoRange(gd, ax);\n    }\n\n    enforceAxisConstraints(gd);\n\n    groupLoop:\n    for(var j = 0; j < matchGroups.length; j++) {\n        var group = matchGroups[j];\n        var rng = null;\n        var id;\n\n        for(id in group) {\n            ax = Axes.getFromId(gd, id);\n            if(ax.autorange === false) continue groupLoop;\n\n            axRng = Lib.simpleMap(ax.range, ax.r2l);\n            if(rng) {\n                if(rng[0] < rng[1]) {\n                    rng[0] = Math.min(rng[0], axRng[0]);\n                    rng[1] = Math.max(rng[1], axRng[1]);\n                } else {\n                    rng[0] = Math.max(rng[0], axRng[0]);\n                    rng[1] = Math.min(rng[1], axRng[1]);\n                }\n            } else {\n                rng = axRng;\n            }\n        }\n\n        for(id in group) {\n            ax = Axes.getFromId(gd, id);\n            ax.range = Lib.simpleMap(rng, ax.l2r);\n            ax._input.range = ax.range.slice();\n            ax.setScale();\n        }\n    }\n};\n\n// An initial paint must be completed before these components can be\n// correctly sized and the whole plot re-margined. fullLayout._replotting must\n// be set to false before these will work properly.\nexports.finalDraw = function(gd) {\n    Registry.getComponentMethod('shapes', 'draw')(gd);\n    Registry.getComponentMethod('images', 'draw')(gd);\n    Registry.getComponentMethod('annotations', 'draw')(gd);\n    // TODO: rangesliders really belong in marginPushers but they need to be\n    // drawn after data - can we at least get the margin pushing part separated\n    // out and done earlier?\n    Registry.getComponentMethod('rangeslider', 'draw')(gd);\n    // TODO: rangeselector only needs to be here (in addition to drawMarginPushers)\n    // because the margins need to be fully determined before we can call\n    // autorange and update axis ranges (which rangeselector needs to know which\n    // button is active). Can we break out its automargin step from its draw step?\n    Registry.getComponentMethod('rangeselector', 'draw')(gd);\n};\n\nexports.drawMarginPushers = function(gd) {\n    Registry.getComponentMethod('legend', 'draw')(gd);\n    Registry.getComponentMethod('rangeselector', 'draw')(gd);\n    Registry.getComponentMethod('sliders', 'draw')(gd);\n    Registry.getComponentMethod('updatemenus', 'draw')(gd);\n    Registry.getComponentMethod('colorbar', 'draw')(gd);\n};\n\n},{\"../components/color\":593,\"../components/drawing\":614,\"../components/modebar\":652,\"../components/titles\":681,\"../constants/alignment\":688,\"../lib\":719,\"../lib/clear_gl_canvases\":704,\"../plots/cartesian/autorange\":766,\"../plots/cartesian/axes\":767,\"../plots/cartesian/constraints\":774,\"../plots/plots\":828,\"../registry\":847,\"d3\":163}],759:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar isPlainObject = Lib.isPlainObject;\nvar PlotSchema = _dereq_('./plot_schema');\nvar Plots = _dereq_('../plots/plots');\nvar plotAttributes = _dereq_('../plots/attributes');\nvar Template = _dereq_('./plot_template');\nvar dfltConfig = _dereq_('./plot_config').dfltConfig;\n\n/**\n * Plotly.makeTemplate: create a template off an existing figure to reuse\n * style attributes on other figures.\n *\n * Note: separated from the rest of templates because otherwise we get circular\n * references due to PlotSchema.\n *\n * @param {object|DOM element|string} figure: The figure to base the template on\n *     should contain a trace array `figure.data`\n *     and a layout object `figure.layout`\n * @returns {object} template: the extracted template - can then be used as\n *     `layout.template` in another figure.\n */\nexports.makeTemplate = function(figure) {\n    figure = Lib.isPlainObject(figure) ? figure : Lib.getGraphDiv(figure);\n    figure = Lib.extendDeep({_context: dfltConfig}, {data: figure.data, layout: figure.layout});\n    Plots.supplyDefaults(figure);\n    var data = figure.data || [];\n    var layout = figure.layout || {};\n    // copy over a few items to help follow the schema\n    layout._basePlotModules = figure._fullLayout._basePlotModules;\n    layout._modules = figure._fullLayout._modules;\n\n    var template = {\n        data: {},\n        layout: {}\n    };\n\n    /*\n     * Note: we do NOT validate template values, we just take what's in the\n     * user inputs data and layout, not the validated values in fullData and\n     * fullLayout. Even if we were to validate here, there's no guarantee that\n     * these values would still be valid when applied to a new figure, which\n     * may contain different trace modes, different axes, etc. So it's\n     * important that when applying a template we still validate the template\n     * values, rather than just using them as defaults.\n     */\n\n    data.forEach(function(trace) {\n        // TODO: What if no style info is extracted for this trace. We may\n        // not want an empty object as the null value.\n        // TODO: allow transforms to contribute to templates?\n        // as it stands they are ignored, which may be for the best...\n\n        var traceTemplate = {};\n        walkStyleKeys(trace, traceTemplate, getTraceInfo.bind(null, trace));\n\n        var traceType = Lib.coerce(trace, {}, plotAttributes, 'type');\n        var typeTemplates = template.data[traceType];\n        if(!typeTemplates) typeTemplates = template.data[traceType] = [];\n        typeTemplates.push(traceTemplate);\n    });\n\n    walkStyleKeys(layout, template.layout, getLayoutInfo.bind(null, layout));\n\n    /*\n     * Compose the new template with an existing one to the same effect\n     *\n     * NOTE: there's a possibility of slightly different behavior: if the plot\n     * has an invalid value and the old template has a valid value for the same\n     * attribute, the plot will use the old template value but this routine\n     * will pull the invalid value (resulting in the original default).\n     * In the general case it's not possible to solve this with a single value,\n     * since valid options can be context-dependent. It could be solved with\n     * a *list* of values, but that would be huge complexity for little gain.\n     */\n    delete template.layout.template;\n    var oldTemplate = layout.template;\n    if(isPlainObject(oldTemplate)) {\n        var oldLayoutTemplate = oldTemplate.layout;\n\n        var i, traceType, oldTypeTemplates, oldTypeLen, typeTemplates, typeLen;\n\n        if(isPlainObject(oldLayoutTemplate)) {\n            mergeTemplates(oldLayoutTemplate, template.layout);\n        }\n        var oldDataTemplate = oldTemplate.data;\n        if(isPlainObject(oldDataTemplate)) {\n            for(traceType in template.data) {\n                oldTypeTemplates = oldDataTemplate[traceType];\n                if(Array.isArray(oldTypeTemplates)) {\n                    typeTemplates = template.data[traceType];\n                    typeLen = typeTemplates.length;\n                    oldTypeLen = oldTypeTemplates.length;\n                    for(i = 0; i < typeLen; i++) {\n                        mergeTemplates(oldTypeTemplates[i % oldTypeLen], typeTemplates[i]);\n                    }\n                    for(i = typeLen; i < oldTypeLen; i++) {\n                        typeTemplates.push(Lib.extendDeep({}, oldTypeTemplates[i]));\n                    }\n                }\n            }\n            for(traceType in oldDataTemplate) {\n                if(!(traceType in template.data)) {\n                    template.data[traceType] = Lib.extendDeep([], oldDataTemplate[traceType]);\n                }\n            }\n        }\n    }\n\n    return template;\n};\n\nfunction mergeTemplates(oldTemplate, newTemplate) {\n    // we don't care about speed here, just make sure we have a totally\n    // distinct object from the previous template\n    oldTemplate = Lib.extendDeep({}, oldTemplate);\n\n    // sort keys so we always get annotationdefaults before annotations etc\n    // so arrayTemplater will work right\n    var oldKeys = Object.keys(oldTemplate).sort();\n    var i, j;\n\n    function mergeOne(oldVal, newVal, key) {\n        if(isPlainObject(newVal) && isPlainObject(oldVal)) {\n            mergeTemplates(oldVal, newVal);\n        } else if(Array.isArray(newVal) && Array.isArray(oldVal)) {\n            // Note: omitted `inclusionAttr` from arrayTemplater here,\n            // it's irrelevant as we only want the resulting `_template`.\n            var templater = Template.arrayTemplater({_template: oldTemplate}, key);\n            for(j = 0; j < newVal.length; j++) {\n                var item = newVal[j];\n                var oldItem = templater.newItem(item)._template;\n                if(oldItem) mergeTemplates(oldItem, item);\n            }\n            var defaultItems = templater.defaultItems();\n            for(j = 0; j < defaultItems.length; j++) newVal.push(defaultItems[j]._template);\n\n            // templateitemname only applies to receiving plots\n            for(j = 0; j < newVal.length; j++) delete newVal[j].templateitemname;\n        }\n    }\n\n    for(i = 0; i < oldKeys.length; i++) {\n        var key = oldKeys[i];\n        var oldVal = oldTemplate[key];\n        if(key in newTemplate) {\n            mergeOne(oldVal, newTemplate[key], key);\n        } else newTemplate[key] = oldVal;\n\n        // if this is a base key from the old template (eg xaxis), look for\n        // extended keys (eg xaxis2) in the new template to merge into\n        if(getBaseKey(key) === key) {\n            for(var key2 in newTemplate) {\n                var baseKey2 = getBaseKey(key2);\n                if(key2 !== baseKey2 && baseKey2 === key && !(key2 in oldTemplate)) {\n                    mergeOne(oldVal, newTemplate[key2], key);\n                }\n            }\n        }\n    }\n}\n\nfunction getBaseKey(key) {\n    return key.replace(/[0-9]+$/, '');\n}\n\nfunction walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) {\n    var pathAttr = basePath && getAttributeInfo(basePath);\n    for(var key in parent) {\n        var child = parent[key];\n        var nextPath = getNextPath(parent, key, path);\n        var nextBasePath = getNextPath(parent, key, basePath);\n        var attr = getAttributeInfo(nextBasePath);\n        if(!attr) {\n            var baseKey = getBaseKey(key);\n            if(baseKey !== key) {\n                nextBasePath = getNextPath(parent, baseKey, basePath);\n                attr = getAttributeInfo(nextBasePath);\n            }\n        }\n\n        // we'll get an attr if path starts with a valid part, then has an\n        // invalid ending. Make sure we got all the way to the end.\n        if(pathAttr && (pathAttr === attr)) continue;\n\n        if(!attr || attr._noTemplating ||\n            attr.valType === 'data_array' ||\n            (attr.arrayOk && Array.isArray(child))\n        ) {\n            continue;\n        }\n\n        if(!attr.valType && isPlainObject(child)) {\n            walkStyleKeys(child, templateOut, getAttributeInfo, nextPath, nextBasePath);\n        } else if(attr._isLinkedToArray && Array.isArray(child)) {\n            var dfltDone = false;\n            var namedIndex = 0;\n            var usedNames = {};\n            for(var i = 0; i < child.length; i++) {\n                var item = child[i];\n                if(isPlainObject(item)) {\n                    var name = item.name;\n                    if(name) {\n                        if(!usedNames[name]) {\n                            // named array items: allow all attributes except data arrays\n                            walkStyleKeys(item, templateOut, getAttributeInfo,\n                                getNextPath(child, namedIndex, nextPath),\n                                getNextPath(child, namedIndex, nextBasePath));\n                            namedIndex++;\n                            usedNames[name] = 1;\n                        }\n                    } else if(!dfltDone) {\n                        var dfltKey = Template.arrayDefaultKey(key);\n                        var dfltPath = getNextPath(parent, dfltKey, path);\n\n                        // getAttributeInfo will fail if we try to use dfltKey directly.\n                        // Instead put this item into the next array element, then\n                        // pull it out and move it to dfltKey.\n                        var pathInArray = getNextPath(child, namedIndex, nextPath);\n                        walkStyleKeys(item, templateOut, getAttributeInfo, pathInArray,\n                            getNextPath(child, namedIndex, nextBasePath));\n                        var itemPropInArray = Lib.nestedProperty(templateOut, pathInArray);\n                        var dfltProp = Lib.nestedProperty(templateOut, dfltPath);\n                        dfltProp.set(itemPropInArray.get());\n                        itemPropInArray.set(null);\n\n                        dfltDone = true;\n                    }\n                }\n            }\n        } else {\n            var templateProp = Lib.nestedProperty(templateOut, nextPath);\n            templateProp.set(child);\n        }\n    }\n}\n\nfunction getLayoutInfo(layout, path) {\n    return PlotSchema.getLayoutValObject(\n        layout, Lib.nestedProperty({}, path).parts\n    );\n}\n\nfunction getTraceInfo(trace, path) {\n    return PlotSchema.getTraceValObject(\n        trace, Lib.nestedProperty({}, path).parts\n    );\n}\n\nfunction getNextPath(parent, key, path) {\n    var nextPath;\n    if(!path) nextPath = key;\n    else if(Array.isArray(parent)) nextPath = path + '[' + key + ']';\n    else nextPath = path + '.' + key;\n\n    return nextPath;\n}\n\n/**\n * validateTemplate: Test for consistency between the given figure and\n * a template, either already included in the figure or given separately.\n * Note that not every issue we identify here is necessarily a problem,\n * it depends on what you're using the template for.\n *\n * @param {object|DOM element} figure: the plot, with {data, layout} members,\n *     to test the template against\n * @param {Optional(object)} template: the template, with its own {data, layout},\n *     to test. If omitted, we will look for a template already attached as the\n *     plot's `layout.template` attribute.\n *\n * @returns {array} array of error objects each containing:\n *  - {string} code\n *      error code ('missing', 'unused', 'reused', 'noLayout', 'noData')\n *  - {string} msg\n *      a full readable description of the issue.\n */\nexports.validateTemplate = function(figureIn, template) {\n    var figure = Lib.extendDeep({}, {\n        _context: dfltConfig,\n        data: figureIn.data,\n        layout: figureIn.layout\n    });\n    var layout = figure.layout || {};\n    if(!isPlainObject(template)) template = layout.template || {};\n    var layoutTemplate = template.layout;\n    var dataTemplate = template.data;\n    var errorList = [];\n\n    figure.layout = layout;\n    figure.layout.template = template;\n    Plots.supplyDefaults(figure);\n\n    var fullLayout = figure._fullLayout;\n    var fullData = figure._fullData;\n\n    var layoutPaths = {};\n    function crawlLayoutForContainers(obj, paths) {\n        for(var key in obj) {\n            if(key.charAt(0) !== '_' && isPlainObject(obj[key])) {\n                var baseKey = getBaseKey(key);\n                var nextPaths = [];\n                var i;\n                for(i = 0; i < paths.length; i++) {\n                    nextPaths.push(getNextPath(obj, key, paths[i]));\n                    if(baseKey !== key) nextPaths.push(getNextPath(obj, baseKey, paths[i]));\n                }\n                for(i = 0; i < nextPaths.length; i++) {\n                    layoutPaths[nextPaths[i]] = 1;\n                }\n                crawlLayoutForContainers(obj[key], nextPaths);\n            }\n        }\n    }\n\n    function crawlLayoutTemplateForContainers(obj, path) {\n        for(var key in obj) {\n            if(key.indexOf('defaults') === -1 && isPlainObject(obj[key])) {\n                var nextPath = getNextPath(obj, key, path);\n                if(layoutPaths[nextPath]) {\n                    crawlLayoutTemplateForContainers(obj[key], nextPath);\n                } else {\n                    errorList.push({code: 'unused', path: nextPath});\n                }\n            }\n        }\n    }\n\n    if(!isPlainObject(layoutTemplate)) {\n        errorList.push({code: 'layout'});\n    } else {\n        crawlLayoutForContainers(fullLayout, ['layout']);\n        crawlLayoutTemplateForContainers(layoutTemplate, 'layout');\n    }\n\n    if(!isPlainObject(dataTemplate)) {\n        errorList.push({code: 'data'});\n    } else {\n        var typeCount = {};\n        var traceType;\n        for(var i = 0; i < fullData.length; i++) {\n            var fullTrace = fullData[i];\n            traceType = fullTrace.type;\n            typeCount[traceType] = (typeCount[traceType] || 0) + 1;\n            if(!fullTrace._fullInput._template) {\n                // this takes care of the case of traceType in the data but not\n                // the template\n                errorList.push({\n                    code: 'missing',\n                    index: fullTrace._fullInput.index,\n                    traceType: traceType\n                });\n            }\n        }\n        for(traceType in dataTemplate) {\n            var templateCount = dataTemplate[traceType].length;\n            var dataCount = typeCount[traceType] || 0;\n            if(templateCount > dataCount) {\n                errorList.push({\n                    code: 'unused',\n                    traceType: traceType,\n                    templateCount: templateCount,\n                    dataCount: dataCount\n                });\n            } else if(dataCount > templateCount) {\n                errorList.push({\n                    code: 'reused',\n                    traceType: traceType,\n                    templateCount: templateCount,\n                    dataCount: dataCount\n                });\n            }\n        }\n    }\n\n    // _template: false is when someone tried to modify an array item\n    // but there was no template with matching name\n    function crawlForMissingTemplates(obj, path) {\n        for(var key in obj) {\n            if(key.charAt(0) === '_') continue;\n            var val = obj[key];\n            var nextPath = getNextPath(obj, key, path);\n            if(isPlainObject(val)) {\n                if(Array.isArray(obj) && val._template === false && val.templateitemname) {\n                    errorList.push({\n                        code: 'missing',\n                        path: nextPath,\n                        templateitemname: val.templateitemname\n                    });\n                }\n                crawlForMissingTemplates(val, nextPath);\n            } else if(Array.isArray(val) && hasPlainObject(val)) {\n                crawlForMissingTemplates(val, nextPath);\n            }\n        }\n    }\n    crawlForMissingTemplates({data: fullData, layout: fullLayout}, '');\n\n    if(errorList.length) return errorList.map(format);\n};\n\nfunction hasPlainObject(arr) {\n    for(var i = 0; i < arr.length; i++) {\n        if(isPlainObject(arr[i])) return true;\n    }\n}\n\nfunction format(opts) {\n    var msg;\n    switch(opts.code) {\n        case 'data':\n            msg = 'The template has no key data.';\n            break;\n        case 'layout':\n            msg = 'The template has no key layout.';\n            break;\n        case 'missing':\n            if(opts.path) {\n                msg = 'There are no templates for item ' + opts.path +\n                    ' with name ' + opts.templateitemname;\n            } else {\n                msg = 'There are no templates for trace ' + opts.index +\n                    ', of type ' + opts.traceType + '.';\n            }\n            break;\n        case 'unused':\n            if(opts.path) {\n                msg = 'The template item at ' + opts.path +\n                    ' was not used in constructing the plot.';\n            } else if(opts.dataCount) {\n                msg = 'Some of the templates of type ' + opts.traceType +\n                    ' were not used. The template has ' + opts.templateCount +\n                    ' traces, the data only has ' + opts.dataCount +\n                    ' of this type.';\n            } else {\n                msg = 'The template has ' + opts.templateCount +\n                    ' traces of type ' + opts.traceType +\n                    ' but there are none in the data.';\n            }\n            break;\n        case 'reused':\n            msg = 'Some of the templates of type ' + opts.traceType +\n                ' were used more than once. The template has ' +\n                opts.templateCount + ' traces, the data has ' +\n                opts.dataCount + ' of this type.';\n            break;\n    }\n    opts.msg = msg;\n\n    return opts;\n}\n\n},{\"../lib\":719,\"../plots/attributes\":764,\"../plots/plots\":828,\"./plot_config\":755,\"./plot_schema\":756,\"./plot_template\":757}],760:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar plotApi = _dereq_('./plot_api');\nvar Lib = _dereq_('../lib');\n\nvar helpers = _dereq_('../snapshot/helpers');\nvar toSVG = _dereq_('../snapshot/tosvg');\nvar svgToImg = _dereq_('../snapshot/svgtoimg');\n\nvar attrs = {\n    format: {\n        valType: 'enumerated',\n        values: ['png', 'jpeg', 'webp', 'svg'],\n        dflt: 'png',\n        \n    },\n    width: {\n        valType: 'number',\n        min: 1,\n        \n    },\n    height: {\n        valType: 'number',\n        min: 1,\n        \n    },\n    scale: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n    },\n    setBackground: {\n        valType: 'any',\n        dflt: false,\n        \n    },\n    imageDataOnly: {\n        valType: 'boolean',\n        dflt: false,\n        \n    }\n};\n\n/** Plotly.toImage\n *\n * @param {object | string | HTML div} gd\n *   can either be a data/layout/config object\n *   or an existing graph <div>\n *   or an id to an existing graph <div>\n * @param {object} opts (see above)\n * @return {promise}\n */\nfunction toImage(gd, opts) {\n    opts = opts || {};\n\n    var data;\n    var layout;\n    var config;\n    var fullLayout;\n\n    if(Lib.isPlainObject(gd)) {\n        data = gd.data || [];\n        layout = gd.layout || {};\n        config = gd.config || {};\n        fullLayout = {};\n    } else {\n        gd = Lib.getGraphDiv(gd);\n        data = Lib.extendDeep([], gd.data);\n        layout = Lib.extendDeep({}, gd.layout);\n        config = gd._context;\n        fullLayout = gd._fullLayout || {};\n    }\n\n    function isImpliedOrValid(attr) {\n        return !(attr in opts) || Lib.validate(opts[attr], attrs[attr]);\n    }\n\n    if((!isImpliedOrValid('width') && opts.width !== null) ||\n        (!isImpliedOrValid('height') && opts.height !== null)) {\n        throw new Error('Height and width should be pixel values.');\n    }\n\n    if(!isImpliedOrValid('format')) {\n        throw new Error('Image format is not jpeg, png, svg or webp.');\n    }\n\n    var fullOpts = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(opts, fullOpts, attrs, attr, dflt);\n    }\n\n    var format = coerce('format');\n    var width = coerce('width');\n    var height = coerce('height');\n    var scale = coerce('scale');\n    var setBackground = coerce('setBackground');\n    var imageDataOnly = coerce('imageDataOnly');\n\n    // put the cloned div somewhere off screen before attaching to DOM\n    var clonedGd = document.createElement('div');\n    clonedGd.style.position = 'absolute';\n    clonedGd.style.left = '-5000px';\n    document.body.appendChild(clonedGd);\n\n    // extend layout with image options\n    var layoutImage = Lib.extendFlat({}, layout);\n    if(width) {\n        layoutImage.width = width;\n    } else if(opts.width === null && isNumeric(fullLayout.width)) {\n        layoutImage.width = fullLayout.width;\n    }\n    if(height) {\n        layoutImage.height = height;\n    } else if(opts.height === null && isNumeric(fullLayout.height)) {\n        layoutImage.height = fullLayout.height;\n    }\n\n    // extend config for static plot\n    var configImage = Lib.extendFlat({}, config, {\n        _exportedPlot: true,\n        staticPlot: true,\n        setBackground: setBackground\n    });\n\n    var redrawFunc = helpers.getRedrawFunc(clonedGd);\n\n    function wait() {\n        return new Promise(function(resolve) {\n            setTimeout(resolve, helpers.getDelay(clonedGd._fullLayout));\n        });\n    }\n\n    function convert() {\n        return new Promise(function(resolve, reject) {\n            var svg = toSVG(clonedGd, format, scale);\n            var width = clonedGd._fullLayout.width;\n            var height = clonedGd._fullLayout.height;\n\n            plotApi.purge(clonedGd);\n            document.body.removeChild(clonedGd);\n\n            if(format === 'svg') {\n                if(imageDataOnly) {\n                    return resolve(svg);\n                } else {\n                    return resolve(helpers.encodeSVG(svg));\n                }\n            }\n\n            var canvas = document.createElement('canvas');\n            canvas.id = Lib.randstr();\n\n            svgToImg({\n                format: format,\n                width: width,\n                height: height,\n                scale: scale,\n                canvas: canvas,\n                svg: svg,\n                // ask svgToImg to return a Promise\n                //  rather than EventEmitter\n                //  leave EventEmitter for backward\n                //  compatibility\n                promise: true\n            })\n            .then(resolve)\n            .catch(reject);\n        });\n    }\n\n    function urlToImageData(url) {\n        if(imageDataOnly) {\n            return url.replace(helpers.IMAGE_URL_PREFIX, '');\n        } else {\n            return url;\n        }\n    }\n\n    return new Promise(function(resolve, reject) {\n        plotApi.plot(clonedGd, data, layoutImage, configImage)\n            .then(redrawFunc)\n            .then(wait)\n            .then(convert)\n            .then(function(url) { resolve(urlToImageData(url)); })\n            .catch(function(err) { reject(err); });\n    });\n}\n\nmodule.exports = toImage;\n\n},{\"../lib\":719,\"../snapshot/helpers\":851,\"../snapshot/svgtoimg\":853,\"../snapshot/tosvg\":855,\"./plot_api\":754,\"fast-isnumeric\":225}],761:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar Plots = _dereq_('../plots/plots');\nvar PlotSchema = _dereq_('./plot_schema');\nvar dfltConfig = _dereq_('./plot_config').dfltConfig;\n\nvar isPlainObject = Lib.isPlainObject;\nvar isArray = Array.isArray;\nvar isArrayOrTypedArray = Lib.isArrayOrTypedArray;\n\n/**\n * Validate a data array and layout object.\n *\n * @param {array} data\n * @param {object} layout\n *\n * @return {array} array of error objects each containing:\n *  - {string} code\n *      error code ('object', 'array', 'schema', 'unused', 'invisible' or 'value')\n *  - {string} container\n *      container where the error occurs ('data' or 'layout')\n *  - {number} trace\n *      trace index of the 'data' container where the error occurs\n *  - {array} path\n *      nested path to the key that causes the error\n *  - {string} astr\n *      attribute string variant of 'path' compatible with Plotly.restyle and\n *      Plotly.relayout.\n *  - {string} msg\n *      error message (shown in console in logger config argument is enable)\n */\nmodule.exports = function validate(data, layout) {\n    var schema = PlotSchema.get();\n    var errorList = [];\n    var gd = {_context: Lib.extendFlat({}, dfltConfig)};\n\n    var dataIn, layoutIn;\n\n    if(isArray(data)) {\n        gd.data = Lib.extendDeep([], data);\n        dataIn = data;\n    } else {\n        gd.data = [];\n        dataIn = [];\n        errorList.push(format('array', 'data'));\n    }\n\n    if(isPlainObject(layout)) {\n        gd.layout = Lib.extendDeep({}, layout);\n        layoutIn = layout;\n    } else {\n        gd.layout = {};\n        layoutIn = {};\n        if(arguments.length > 1) {\n            errorList.push(format('object', 'layout'));\n        }\n    }\n\n    // N.B. dataIn and layoutIn are in general not the same as\n    // gd.data and gd.layout after supplyDefaults as some attributes\n    // in gd.data and gd.layout (still) get mutated during this step.\n\n    Plots.supplyDefaults(gd);\n\n    var dataOut = gd._fullData;\n    var len = dataIn.length;\n\n    for(var i = 0; i < len; i++) {\n        var traceIn = dataIn[i];\n        var base = ['data', i];\n\n        if(!isPlainObject(traceIn)) {\n            errorList.push(format('object', base));\n            continue;\n        }\n\n        var traceOut = dataOut[i];\n        var traceType = traceOut.type;\n        var traceSchema = schema.traces[traceType].attributes;\n\n        // PlotSchema does something fancy with trace 'type', reset it here\n        // to make the trace schema compatible with Lib.validate.\n        traceSchema.type = {\n            valType: 'enumerated',\n            values: [traceType]\n        };\n\n        if(traceOut.visible === false && traceIn.visible !== false) {\n            errorList.push(format('invisible', base));\n        }\n\n        crawl(traceIn, traceOut, traceSchema, errorList, base);\n\n        var transformsIn = traceIn.transforms;\n        var transformsOut = traceOut.transforms;\n\n        if(transformsIn) {\n            if(!isArray(transformsIn)) {\n                errorList.push(format('array', base, ['transforms']));\n            }\n\n            base.push('transforms');\n\n            for(var j = 0; j < transformsIn.length; j++) {\n                var path = ['transforms', j];\n                var transformType = transformsIn[j].type;\n\n                if(!isPlainObject(transformsIn[j])) {\n                    errorList.push(format('object', base, path));\n                    continue;\n                }\n\n                var transformSchema = schema.transforms[transformType] ?\n                    schema.transforms[transformType].attributes :\n                    {};\n\n                // add 'type' to transform schema to validate the transform type\n                transformSchema.type = {\n                    valType: 'enumerated',\n                    values: Object.keys(schema.transforms)\n                };\n\n                crawl(transformsIn[j], transformsOut[j], transformSchema, errorList, base, path);\n            }\n        }\n    }\n\n    var layoutOut = gd._fullLayout;\n    var layoutSchema = fillLayoutSchema(schema, dataOut);\n\n    crawl(layoutIn, layoutOut, layoutSchema, errorList, 'layout');\n\n    // return undefined if no validation errors were found\n    return (errorList.length === 0) ? void(0) : errorList;\n};\n\nfunction crawl(objIn, objOut, schema, list, base, path) {\n    path = path || [];\n\n    var keys = Object.keys(objIn);\n\n    for(var i = 0; i < keys.length; i++) {\n        var k = keys[i];\n\n        // transforms are handled separately\n        if(k === 'transforms') continue;\n\n        var p = path.slice();\n        p.push(k);\n\n        var valIn = objIn[k];\n        var valOut = objOut[k];\n\n        var nestedSchema = getNestedSchema(schema, k);\n        var isInfoArray = (nestedSchema || {}).valType === 'info_array';\n        var isColorscale = (nestedSchema || {}).valType === 'colorscale';\n        var items = (nestedSchema || {}).items;\n\n        if(!isInSchema(schema, k)) {\n            list.push(format('schema', base, p));\n        } else if(isPlainObject(valIn) && isPlainObject(valOut)) {\n            crawl(valIn, valOut, nestedSchema, list, base, p);\n        } else if(isInfoArray && isArray(valIn)) {\n            if(valIn.length > valOut.length) {\n                list.push(format('unused', base, p.concat(valOut.length)));\n            }\n            var len = valOut.length;\n            var arrayItems = Array.isArray(items);\n            if(arrayItems) len = Math.min(len, items.length);\n            var m, n, item, valInPart, valOutPart;\n            if(nestedSchema.dimensions === 2) {\n                for(n = 0; n < len; n++) {\n                    if(isArray(valIn[n])) {\n                        if(valIn[n].length > valOut[n].length) {\n                            list.push(format('unused', base, p.concat(n, valOut[n].length)));\n                        }\n                        var len2 = valOut[n].length;\n                        for(m = 0; m < (arrayItems ? Math.min(len2, items[n].length) : len2); m++) {\n                            item = arrayItems ? items[n][m] : items;\n                            valInPart = valIn[n][m];\n                            valOutPart = valOut[n][m];\n                            if(!Lib.validate(valInPart, item)) {\n                                list.push(format('value', base, p.concat(n, m), valInPart));\n                            } else if(valOutPart !== valInPart && valOutPart !== +valInPart) {\n                                list.push(format('dynamic', base, p.concat(n, m), valInPart, valOutPart));\n                            }\n                        }\n                    } else {\n                        list.push(format('array', base, p.concat(n), valIn[n]));\n                    }\n                }\n            } else {\n                for(n = 0; n < len; n++) {\n                    item = arrayItems ? items[n] : items;\n                    valInPart = valIn[n];\n                    valOutPart = valOut[n];\n                    if(!Lib.validate(valInPart, item)) {\n                        list.push(format('value', base, p.concat(n), valInPart));\n                    } else if(valOutPart !== valInPart && valOutPart !== +valInPart) {\n                        list.push(format('dynamic', base, p.concat(n), valInPart, valOutPart));\n                    }\n                }\n            }\n        } else if(nestedSchema.items && !isInfoArray && isArray(valIn)) {\n            var _nestedSchema = items[Object.keys(items)[0]];\n            var indexList = [];\n\n            var j, _p;\n\n            // loop over valOut items while keeping track of their\n            // corresponding input container index (given by _index)\n            for(j = 0; j < valOut.length; j++) {\n                var _index = valOut[j]._index || j;\n\n                _p = p.slice();\n                _p.push(_index);\n\n                if(isPlainObject(valIn[_index]) && isPlainObject(valOut[j])) {\n                    indexList.push(_index);\n                    var valInj = valIn[_index];\n                    var valOutj = valOut[j];\n                    if(isPlainObject(valInj) && valInj.visible !== false && valOutj.visible === false) {\n                        list.push(format('invisible', base, _p));\n                    } else crawl(valInj, valOutj, _nestedSchema, list, base, _p);\n                }\n            }\n\n            // loop over valIn to determine where it went wrong for some items\n            for(j = 0; j < valIn.length; j++) {\n                _p = p.slice();\n                _p.push(j);\n\n                if(!isPlainObject(valIn[j])) {\n                    list.push(format('object', base, _p, valIn[j]));\n                } else if(indexList.indexOf(j) === -1) {\n                    list.push(format('unused', base, _p));\n                }\n            }\n        } else if(!isPlainObject(valIn) && isPlainObject(valOut)) {\n            list.push(format('object', base, p, valIn));\n        } else if(!isArrayOrTypedArray(valIn) && isArrayOrTypedArray(valOut) && !isInfoArray && !isColorscale) {\n            list.push(format('array', base, p, valIn));\n        } else if(!(k in objOut)) {\n            list.push(format('unused', base, p, valIn));\n        } else if(!Lib.validate(valIn, nestedSchema)) {\n            list.push(format('value', base, p, valIn));\n        } else if(nestedSchema.valType === 'enumerated' &&\n            ((nestedSchema.coerceNumber && valIn !== +valOut) || valIn !== valOut)\n        ) {\n            list.push(format('dynamic', base, p, valIn, valOut));\n        }\n    }\n\n    return list;\n}\n\n// the 'full' layout schema depends on the traces types presents\nfunction fillLayoutSchema(schema, dataOut) {\n    var layoutSchema = schema.layout.layoutAttributes;\n\n    for(var i = 0; i < dataOut.length; i++) {\n        var traceOut = dataOut[i];\n        var traceSchema = schema.traces[traceOut.type];\n        var traceLayoutAttr = traceSchema.layoutAttributes;\n\n        if(traceLayoutAttr) {\n            if(traceOut.subplot) {\n                Lib.extendFlat(layoutSchema[traceSchema.attributes.subplot.dflt], traceLayoutAttr);\n            } else {\n                Lib.extendFlat(layoutSchema, traceLayoutAttr);\n            }\n        }\n    }\n\n    return layoutSchema;\n}\n\n// validation error codes\nvar code2msgFunc = {\n    object: function(base, astr) {\n        var prefix;\n\n        if(base === 'layout' && astr === '') prefix = 'The layout argument';\n        else if(base[0] === 'data' && astr === '') {\n            prefix = 'Trace ' + base[1] + ' in the data argument';\n        } else prefix = inBase(base) + 'key ' + astr;\n\n        return prefix + ' must be linked to an object container';\n    },\n    array: function(base, astr) {\n        var prefix;\n\n        if(base === 'data') prefix = 'The data argument';\n        else prefix = inBase(base) + 'key ' + astr;\n\n        return prefix + ' must be linked to an array container';\n    },\n    schema: function(base, astr) {\n        return inBase(base) + 'key ' + astr + ' is not part of the schema';\n    },\n    unused: function(base, astr, valIn) {\n        var target = isPlainObject(valIn) ? 'container' : 'key';\n\n        return inBase(base) + target + ' ' + astr + ' did not get coerced';\n    },\n    dynamic: function(base, astr, valIn, valOut) {\n        return [\n            inBase(base) + 'key',\n            astr,\n            '(set to \\'' + valIn + '\\')',\n            'got reset to',\n            '\\'' + valOut + '\\'',\n            'during defaults.'\n        ].join(' ');\n    },\n    invisible: function(base, astr) {\n        return (\n            astr ? (inBase(base) + 'item ' + astr) : ('Trace ' + base[1])\n        ) + ' got defaulted to be not visible';\n    },\n    value: function(base, astr, valIn) {\n        return [\n            inBase(base) + 'key ' + astr,\n            'is set to an invalid value (' + valIn + ')'\n        ].join(' ');\n    }\n};\n\nfunction inBase(base) {\n    if(isArray(base)) return 'In data trace ' + base[1] + ', ';\n\n    return 'In ' + base + ', ';\n}\n\nfunction format(code, base, path, valIn, valOut) {\n    path = path || '';\n\n    var container, trace;\n\n    // container is either 'data' or 'layout\n    // trace is the trace index if 'data', null otherwise\n\n    if(isArray(base)) {\n        container = base[0];\n        trace = base[1];\n    } else {\n        container = base;\n        trace = null;\n    }\n\n    var astr = convertPathToAttributeString(path);\n    var msg = code2msgFunc[code](base, astr, valIn, valOut);\n\n    // log to console if logger config option is enabled\n    Lib.log(msg);\n\n    return {\n        code: code,\n        container: container,\n        trace: trace,\n        path: path,\n        astr: astr,\n        msg: msg\n    };\n}\n\nfunction isInSchema(schema, key) {\n    var parts = splitKey(key);\n    var keyMinusId = parts.keyMinusId;\n    var id = parts.id;\n\n    if((keyMinusId in schema) && schema[keyMinusId]._isSubplotObj && id) {\n        return true;\n    }\n\n    return (key in schema);\n}\n\nfunction getNestedSchema(schema, key) {\n    if(key in schema) return schema[key];\n\n    var parts = splitKey(key);\n\n    return schema[parts.keyMinusId];\n}\n\nvar idRegex = Lib.counterRegex('([a-z]+)');\n\nfunction splitKey(key) {\n    var idMatch = key.match(idRegex);\n\n    return {\n        keyMinusId: idMatch && idMatch[1],\n        id: idMatch && idMatch[2]\n    };\n}\n\nfunction convertPathToAttributeString(path) {\n    if(!isArray(path)) return String(path);\n\n    var astr = '';\n\n    for(var i = 0; i < path.length; i++) {\n        var p = path[i];\n\n        if(typeof p === 'number') {\n            astr = astr.substr(0, astr.length - 1) + '[' + p + ']';\n        } else {\n            astr += p;\n        }\n\n        if(i < path.length - 1) astr += '.';\n    }\n\n    return astr;\n}\n\n},{\"../lib\":719,\"../plots/plots\":828,\"./plot_config\":755,\"./plot_schema\":756}],762:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    mode: {\n        valType: 'enumerated',\n        dflt: 'afterall',\n        \n        values: ['immediate', 'next', 'afterall'],\n        \n    },\n    direction: {\n        valType: 'enumerated',\n        \n        values: ['forward', 'reverse'],\n        dflt: 'forward',\n        \n    },\n    fromcurrent: {\n        valType: 'boolean',\n        dflt: false,\n        \n        \n    },\n    frame: {\n        duration: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 500,\n            \n        },\n        redraw: {\n            valType: 'boolean',\n            \n            dflt: true,\n            \n        },\n    },\n    transition: {\n        duration: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 500,\n            editType: 'none',\n            \n        },\n        easing: {\n            valType: 'enumerated',\n            dflt: 'cubic-in-out',\n            values: [\n                'linear',\n                'quad',\n                'cubic',\n                'sin',\n                'exp',\n                'circle',\n                'elastic',\n                'back',\n                'bounce',\n                'linear-in',\n                'quad-in',\n                'cubic-in',\n                'sin-in',\n                'exp-in',\n                'circle-in',\n                'elastic-in',\n                'back-in',\n                'bounce-in',\n                'linear-out',\n                'quad-out',\n                'cubic-out',\n                'sin-out',\n                'exp-out',\n                'circle-out',\n                'elastic-out',\n                'back-out',\n                'bounce-out',\n                'linear-in-out',\n                'quad-in-out',\n                'cubic-in-out',\n                'sin-in-out',\n                'exp-in-out',\n                'circle-in-out',\n                'elastic-in-out',\n                'back-in-out',\n                'bounce-in-out'\n            ],\n            \n            editType: 'none',\n            \n        },\n        ordering: {\n            valType: 'enumerated',\n            values: ['layout first', 'traces first'],\n            dflt: 'layout first',\n            \n            editType: 'none',\n            \n        }\n    }\n};\n\n},{}],763:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar Template = _dereq_('../plot_api/plot_template');\n\n/** Convenience wrapper for making array container logic DRY and consistent\n *\n * @param {object} parentObjIn\n *  user input object where the container in question is linked\n *  (i.e. either a user trace object or the user layout object)\n *\n * @param {object} parentObjOut\n *  full object where the coerced container will be linked\n *  (i.e. either a full trace object or the full layout object)\n *\n * @param {object} opts\n *  options object:\n *   - name {string}\n *      name of the key linking the container in question\n *   - inclusionAttr {string}\n *      name of the item attribute for inclusion/exclusion. Default is 'visible'.\n *      Since inclusion is true, use eg 'enabled' instead of 'disabled'.\n *   - handleItemDefaults {function}\n *      defaults method to be called on each item in the array container in question\n *\n *      Its arguments are:\n *          - itemIn {object} item in user layout\n *          - itemOut {object} item in full layout\n *          - parentObj {object} (as in closure)\n *          - opts {object} (as in closure)\n * N.B.\n *\n *  - opts is passed to handleItemDefaults so it can also store\n *    links to supplementary data (e.g. fullData for layout components)\n *\n */\nmodule.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut, opts) {\n    var name = opts.name;\n    var inclusionAttr = opts.inclusionAttr || 'visible';\n\n    var previousContOut = parentObjOut[name];\n\n    var contIn = Lib.isArrayOrTypedArray(parentObjIn[name]) ? parentObjIn[name] : [];\n    var contOut = parentObjOut[name] = [];\n    var templater = Template.arrayTemplater(parentObjOut, name, inclusionAttr);\n    var i, itemOut;\n\n    for(i = 0; i < contIn.length; i++) {\n        var itemIn = contIn[i];\n\n        if(!Lib.isPlainObject(itemIn)) {\n            itemOut = templater.newItem({});\n            itemOut[inclusionAttr] = false;\n        } else {\n            itemOut = templater.newItem(itemIn);\n        }\n\n        itemOut._index = i;\n\n        if(itemOut[inclusionAttr] !== false) {\n            opts.handleItemDefaults(itemIn, itemOut, parentObjOut, opts);\n        }\n\n        contOut.push(itemOut);\n    }\n\n    var defaultItems = templater.defaultItems();\n    for(i = 0; i < defaultItems.length; i++) {\n        itemOut = defaultItems[i];\n        itemOut._index = contOut.length;\n        opts.handleItemDefaults({}, itemOut, parentObjOut, opts, {});\n        contOut.push(itemOut);\n    }\n\n    // in case this array gets its defaults rebuilt independent of the whole layout,\n    // relink the private keys just for this array.\n    if(Lib.isArrayOrTypedArray(previousContOut)) {\n        var len = Math.min(previousContOut.length, contOut.length);\n        for(i = 0; i < len; i++) {\n            Lib.relinkPrivateKeys(contOut[i], previousContOut[i]);\n        }\n    }\n\n    return contOut;\n};\n\n},{\"../lib\":719,\"../plot_api/plot_template\":757}],764:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fxAttrs = _dereq_('../components/fx/attributes');\n\nmodule.exports = {\n    type: {\n        valType: 'enumerated',\n        \n        values: [],     // listed dynamically\n        dflt: 'scatter',\n        editType: 'calc+clearAxisTypes',\n        _noTemplating: true // we handle this at a higher level\n    },\n    visible: {\n        valType: 'enumerated',\n        values: [true, false, 'legendonly'],\n        \n        dflt: true,\n        editType: 'calc',\n        \n    },\n    showlegend: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'style',\n        \n    },\n    legendgroup: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'style',\n        \n    },\n    opacity: {\n        valType: 'number',\n        \n        min: 0,\n        max: 1,\n        dflt: 1,\n        editType: 'style',\n        \n    },\n    name: {\n        valType: 'string',\n        \n        editType: 'style',\n        \n    },\n    uid: {\n        valType: 'string',\n        \n        editType: 'plot',\n        anim: true,\n        \n    },\n    ids: {\n        valType: 'data_array',\n        editType: 'calc',\n        anim: true,\n        \n    },\n    customdata: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    meta: {\n        valType: 'any',\n        arrayOk: true,\n        \n        editType: 'plot',\n        \n    },\n\n    // N.B. these cannot be 'data_array' as they do not have the same length as\n    // other data arrays and arrayOk attributes in general\n    //\n    // Maybe add another valType:\n    // https://github.com/plotly/plotly.js/issues/1894\n    selectedpoints: {\n        valType: 'any',\n        \n        editType: 'calc',\n        \n    },\n\n    hoverinfo: {\n        valType: 'flaglist',\n        \n        flags: ['x', 'y', 'z', 'text', 'name'],\n        extras: ['all', 'none', 'skip'],\n        arrayOk: true,\n        dflt: 'all',\n        editType: 'none',\n        \n    },\n    hoverlabel: fxAttrs.hoverlabel,\n    stream: {\n        token: {\n            valType: 'string',\n            noBlank: true,\n            strict: true,\n            \n            editType: 'calc',\n            \n        },\n        maxpoints: {\n            valType: 'number',\n            min: 0,\n            max: 10000,\n            dflt: 500,\n            \n            editType: 'calc',\n            \n        },\n        editType: 'calc'\n    },\n    transforms: {\n        _isLinkedToArray: 'transform',\n        editType: 'calc',\n        \n    },\n    uirevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    }\n};\n\n},{\"../components/fx/attributes\":623}],765:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n    xaxis: {\n        valType: 'subplotid',\n        \n        dflt: 'x',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n    yaxis: {\n        valType: 'subplotid',\n        \n        dflt: 'y',\n        editType: 'calc+clearAxisTypes',\n        \n    }\n};\n\n},{}],766:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar FP_SAFE = _dereq_('../../constants/numerical').FP_SAFE;\nvar Registry = _dereq_('../../registry');\n\nmodule.exports = {\n    getAutoRange: getAutoRange,\n    makePadFn: makePadFn,\n    doAutoRange: doAutoRange,\n    findExtremes: findExtremes,\n    concatExtremes: concatExtremes\n};\n\n/**\n * getAutoRange\n *\n * Collects all _extremes values corresponding to a given axis\n * and computes its auto range.\n *\n * Note that getAutoRange uses return values from findExtremes.\n *\n * @param {object} gd:\n *   graph div object with filled-in fullData and fullLayout, in particular\n *   with filled-in '_extremes' containers:\n *   {\n *      val: calcdata value,\n *      pad: extra pixels beyond this value,\n *      extrapad: bool, does this point want 5% extra padding\n *   }\n * @param {object} ax:\n *   full axis object, in particular with filled-in '_traceIndices'\n *   and '_annIndices' / '_shapeIndices' if applicable\n * @return {array}\n *   an array of [min, max]. These are calcdata for log and category axes\n *   and data for linear and date axes.\n *\n * TODO: we want to change log to data as well, but it's hard to do this\n * maintaining backward compatibility. category will always have to use calcdata\n * though, because otherwise values between categories (or outside all categories)\n * would be impossible.\n */\nfunction getAutoRange(gd, ax) {\n    var i, j;\n    var newRange = [];\n\n    var getPad = makePadFn(ax);\n    var extremes = concatExtremes(gd, ax);\n    var minArray = extremes.min;\n    var maxArray = extremes.max;\n\n    if(minArray.length === 0 || maxArray.length === 0) {\n        return Lib.simpleMap(ax.range, ax.r2l);\n    }\n\n    var minmin = minArray[0].val;\n    var maxmax = maxArray[0].val;\n\n    for(i = 1; i < minArray.length; i++) {\n        if(minmin !== maxmax) break;\n        minmin = Math.min(minmin, minArray[i].val);\n    }\n    for(i = 1; i < maxArray.length; i++) {\n        if(minmin !== maxmax) break;\n        maxmax = Math.max(maxmax, maxArray[i].val);\n    }\n\n    var axReverse = false;\n\n    if(ax.range) {\n        var rng = Lib.simpleMap(ax.range, ax.r2l);\n        axReverse = rng[1] < rng[0];\n    }\n    // one-time setting to easily reverse the axis\n    // when plotting from code\n    if(ax.autorange === 'reversed') {\n        axReverse = true;\n        ax.autorange = true;\n    }\n\n    var rangeMode = ax.rangemode;\n    var toZero = rangeMode === 'tozero';\n    var nonNegative = rangeMode === 'nonnegative';\n    var axLen = ax._length;\n    // don't allow padding to reduce the data to < 10% of the length\n    var minSpan = axLen / 10;\n\n    var mbest = 0;\n    var minpt, maxpt, minbest, maxbest, dp, dv;\n\n    for(i = 0; i < minArray.length; i++) {\n        minpt = minArray[i];\n        for(j = 0; j < maxArray.length; j++) {\n            maxpt = maxArray[j];\n            dv = maxpt.val - minpt.val;\n            if(dv > 0) {\n                dp = axLen - getPad(minpt) - getPad(maxpt);\n                if(dp > minSpan) {\n                    if(dv / dp > mbest) {\n                        minbest = minpt;\n                        maxbest = maxpt;\n                        mbest = dv / dp;\n                    }\n                } else if(dv / axLen > mbest) {\n                    // in case of padding longer than the axis\n                    // at least include the unpadded data values.\n                    minbest = {val: minpt.val, pad: 0};\n                    maxbest = {val: maxpt.val, pad: 0};\n                    mbest = dv / axLen;\n                }\n            }\n        }\n    }\n\n    function getMaxPad(prev, pt) {\n        return Math.max(prev, getPad(pt));\n    }\n\n    if(minmin === maxmax) {\n        var lower = minmin - 1;\n        var upper = minmin + 1;\n        if(toZero) {\n            if(minmin === 0) {\n                // The only value we have on this axis is 0, and we want to\n                // autorange so zero is one end.\n                // In principle this could be [0, 1] or [-1, 0] but usually\n                // 'tozero' pins 0 to the low end, so follow that.\n                newRange = [0, 1];\n            } else {\n                var maxPad = (minmin > 0 ? maxArray : minArray).reduce(getMaxPad, 0);\n                // we're pushing a single value away from the edge due to its\n                // padding, with the other end clamped at zero\n                // 0.5 means don't push it farther than the center.\n                var rangeEnd = minmin / (1 - Math.min(0.5, maxPad / axLen));\n                newRange = minmin > 0 ? [0, rangeEnd] : [rangeEnd, 0];\n            }\n        } else if(nonNegative) {\n            newRange = [Math.max(0, lower), Math.max(1, upper)];\n        } else {\n            newRange = [lower, upper];\n        }\n    } else {\n        if(toZero) {\n            if(minbest.val >= 0) {\n                minbest = {val: 0, pad: 0};\n            }\n            if(maxbest.val <= 0) {\n                maxbest = {val: 0, pad: 0};\n            }\n        } else if(nonNegative) {\n            if(minbest.val - mbest * getPad(minbest) < 0) {\n                minbest = {val: 0, pad: 0};\n            }\n            if(maxbest.val <= 0) {\n                maxbest = {val: 1, pad: 0};\n            }\n        }\n\n        // in case it changed again...\n        mbest = (maxbest.val - minbest.val) /\n            (axLen - getPad(minbest) - getPad(maxbest));\n\n        newRange = [\n            minbest.val - mbest * getPad(minbest),\n            maxbest.val + mbest * getPad(maxbest)\n        ];\n    }\n\n    // maintain reversal\n    if(axReverse) newRange.reverse();\n\n    return Lib.simpleMap(newRange, ax.l2r || Number);\n}\n\n/*\n * calculate the pixel padding for ax._min and ax._max entries with\n * optional extrapad as 5% of the total axis length\n */\nfunction makePadFn(ax) {\n    // 5% padding for points that specify extrapad: true\n    var extrappad = ax._length / 20;\n\n    // domain-constrained axes: base extrappad on the unconstrained\n    // domain so it's consistent as the domain changes\n    if((ax.constrain === 'domain') && ax._inputDomain) {\n        extrappad *= (ax._inputDomain[1] - ax._inputDomain[0]) /\n            (ax.domain[1] - ax.domain[0]);\n    }\n\n    return function getPad(pt) { return pt.pad + (pt.extrapad ? extrappad : 0); };\n}\n\nfunction concatExtremes(gd, ax) {\n    var axId = ax._id;\n    var fullData = gd._fullData;\n    var fullLayout = gd._fullLayout;\n    var minArray = [];\n    var maxArray = [];\n    var i, j, d;\n\n    function _concat(cont, indices) {\n        for(i = 0; i < indices.length; i++) {\n            var item = cont[indices[i]];\n            var extremes = (item._extremes || {})[axId];\n            if(item.visible === true && extremes) {\n                for(j = 0; j < extremes.min.length; j++) {\n                    d = extremes.min[j];\n                    collapseMinArray(minArray, d.val, d.pad, {extrapad: d.extrapad});\n                }\n                for(j = 0; j < extremes.max.length; j++) {\n                    d = extremes.max[j];\n                    collapseMaxArray(maxArray, d.val, d.pad, {extrapad: d.extrapad});\n                }\n            }\n        }\n    }\n\n    _concat(fullData, ax._traceIndices);\n    _concat(fullLayout.annotations || [], ax._annIndices || []);\n    _concat(fullLayout.shapes || [], ax._shapeIndices || []);\n\n    return {min: minArray, max: maxArray};\n}\n\nfunction doAutoRange(gd, ax) {\n    ax.setScale();\n\n    if(ax.autorange) {\n        ax.range = getAutoRange(gd, ax);\n\n        ax._r = ax.range.slice();\n        ax._rl = Lib.simpleMap(ax._r, ax.r2l);\n\n        // doAutoRange will get called on fullLayout,\n        // but we want to report its results back to layout\n\n        var axIn = ax._input;\n\n        // before we edit _input, store preGUI values\n        var edits = {};\n        edits[ax._attr + '.range'] = ax.range;\n        edits[ax._attr + '.autorange'] = ax.autorange;\n        Registry.call('_storeDirectGUIEdit', gd.layout, gd._fullLayout._preGUI, edits);\n\n        axIn.range = ax.range.slice();\n        axIn.autorange = ax.autorange;\n    }\n\n    var anchorAx = ax._anchorAxis;\n\n    if(anchorAx && anchorAx.rangeslider) {\n        var axeRangeOpts = anchorAx.rangeslider[ax._name];\n        if(axeRangeOpts) {\n            if(axeRangeOpts.rangemode === 'auto') {\n                axeRangeOpts.range = getAutoRange(gd, ax);\n            }\n        }\n        anchorAx._input.rangeslider[ax._name] = Lib.extendFlat({}, axeRangeOpts);\n    }\n}\n\n/**\n * findExtremes\n *\n * Find min/max extremes of an array of coordinates on a given axis.\n *\n * Note that findExtremes is called during `calc`, when we don't yet know the axis\n * length; all the inputs should be based solely on the trace data, nothing\n * about the axis layout.\n *\n * Note that `ppad` and `vpad` as well as their asymmetric variants refer to\n * the before and after padding of the passed `data` array, not to the whole axis.\n *\n * @param {object} ax: full axis object\n *   relies on\n *   - ax.type\n *   - ax._m (just its sign)\n *   - ax.d2l\n * @param {array} data:\n *  array of numbers (i.e. already run though ax.d2c)\n * @param {object} opts:\n *  available keys are:\n *      vpad: (number or number array) pad values (data value +-vpad)\n *      ppad: (number or number array) pad pixels (pixel location +-ppad)\n *      ppadplus, ppadminus, vpadplus, vpadminus:\n *          separate padding for each side, overrides symmetric\n *      padded: (boolean) add 5% padding to both ends\n *          (unless one end is overridden by tozero)\n *      tozero: (boolean) make sure to include zero if axis is linear,\n *          and make it a tight bound if possible\n *\n * @return {object}\n *  - min {array of objects}\n *  - max {array of objects}\n *  each object item has fields:\n *    - val {number}\n *    - pad {number}\n *    - extrappad {number}\n *  - opts {object}: a ref to the passed \"options\" object\n */\nfunction findExtremes(ax, data, opts) {\n    if(!opts) opts = {};\n    if(!ax._m) ax.setScale();\n\n    var minArray = [];\n    var maxArray = [];\n\n    var len = data.length;\n    var extrapad = opts.padded || false;\n    var tozero = opts.tozero && (ax.type === 'linear' || ax.type === '-');\n    var isLog = ax.type === 'log';\n    var hasArrayOption = false;\n    var i, v, di, dmin, dmax, ppadiplus, ppadiminus, vmin, vmax;\n\n    function makePadAccessor(item) {\n        if(Array.isArray(item)) {\n            hasArrayOption = true;\n            return function(i) { return Math.max(Number(item[i]||0), 0); };\n        } else {\n            var v = Math.max(Number(item||0), 0);\n            return function() { return v; };\n        }\n    }\n\n    var ppadplus = makePadAccessor((ax._m > 0 ?\n        opts.ppadplus : opts.ppadminus) || opts.ppad || 0);\n    var ppadminus = makePadAccessor((ax._m > 0 ?\n        opts.ppadminus : opts.ppadplus) || opts.ppad || 0);\n    var vpadplus = makePadAccessor(opts.vpadplus || opts.vpad);\n    var vpadminus = makePadAccessor(opts.vpadminus || opts.vpad);\n\n    if(!hasArrayOption) {\n        // with no arrays other than `data` we don't need to consider\n        // every point, only the extreme data points\n        vmin = Infinity;\n        vmax = -Infinity;\n\n        if(isLog) {\n            for(i = 0; i < len; i++) {\n                v = data[i];\n                // data is not linearized yet so we still have to filter out negative logs\n                if(v < vmin && v > 0) vmin = v;\n                if(v > vmax && v < FP_SAFE) vmax = v;\n            }\n        } else {\n            for(i = 0; i < len; i++) {\n                v = data[i];\n                if(v < vmin && v > -FP_SAFE) vmin = v;\n                if(v > vmax && v < FP_SAFE) vmax = v;\n            }\n        }\n\n        data = [vmin, vmax];\n        len = 2;\n    }\n\n    var collapseOpts = {tozero: tozero, extrapad: extrapad};\n\n    function addItem(i) {\n        di = data[i];\n        if(!isNumeric(di)) return;\n        ppadiplus = ppadplus(i);\n        ppadiminus = ppadminus(i);\n        vmin = di - vpadminus(i);\n        vmax = di + vpadplus(i);\n        // special case for log axes: if vpad makes this object span\n        // more than an order of mag, clip it to one order. This is so\n        // we don't have non-positive errors or absurdly large lower\n        // range due to rounding errors\n        if(isLog && vmin < vmax / 10) vmin = vmax / 10;\n\n        dmin = ax.c2l(vmin);\n        dmax = ax.c2l(vmax);\n\n        if(tozero) {\n            dmin = Math.min(0, dmin);\n            dmax = Math.max(0, dmax);\n        }\n        if(goodNumber(dmin)) {\n            collapseMinArray(minArray, dmin, ppadiminus, collapseOpts);\n        }\n        if(goodNumber(dmax)) {\n            collapseMaxArray(maxArray, dmax, ppadiplus, collapseOpts);\n        }\n    }\n\n    // For efficiency covering monotonic or near-monotonic data,\n    // check a few points at both ends first and then sweep\n    // through the middle\n    var iMax = Math.min(6, len);\n    for(i = 0; i < iMax; i++) addItem(i);\n    for(i = len - 1; i >= iMax; i--) addItem(i);\n\n    return {\n        min: minArray,\n        max: maxArray,\n        opts: opts\n    };\n}\n\nfunction collapseMinArray(array, newVal, newPad, opts) {\n    collapseArray(array, newVal, newPad, opts, lessOrEqual);\n}\n\nfunction collapseMaxArray(array, newVal, newPad, opts) {\n    collapseArray(array, newVal, newPad, opts, greaterOrEqual);\n}\n\n/**\n * collapseArray\n *\n * Takes items from 'array' and compares them to 'newVal', 'newPad'.\n *\n * @param {array} array:\n *  current set of min or max extremes\n * @param {number} newVal:\n *  new value to compare against\n * @param {number} newPad:\n *  pad value associated with 'newVal'\n * @param {object} opts:\n *  - tozero {boolean}\n *  - extrapad {number}\n * @param {function} atLeastAsExtreme:\n *  comparison function, use\n *  - lessOrEqual for min 'array' and\n *  - greaterOrEqual for max 'array'\n *\n * In practice, 'array' is either\n *  - 'extremes[ax._id].min' or\n *  - 'extremes[ax._id].max\n *  found in traces and layout items that affect autorange.\n *\n * Since we don't yet know the relationship between pixels and values\n * (that's what we're trying to figure out!) AND we don't yet know how\n * many pixels `extrapad` represents (it's going to be 5% of the length,\n * but we don't want to have to redo calc just because length changed)\n * two point must satisfy three criteria simultaneously for one to supersede the other:\n *  - at least as extreme a `val`\n *  - at least as big a `pad`\n *  - an unpadded point cannot supersede a padded point, but any other combination can\n *\n * Then:\n * - If the item supersedes the new point, set includeThis false\n * - If the new pt supersedes the item, delete it from 'array'\n */\nfunction collapseArray(array, newVal, newPad, opts, atLeastAsExtreme) {\n    var tozero = opts.tozero;\n    var extrapad = opts.extrapad;\n    var includeThis = true;\n\n    for(var j = 0; j < array.length && includeThis; j++) {\n        var v = array[j];\n        if(atLeastAsExtreme(v.val, newVal) && v.pad >= newPad && (v.extrapad || !extrapad)) {\n            includeThis = false;\n            break;\n        } else if(atLeastAsExtreme(newVal, v.val) && v.pad <= newPad && (extrapad || !v.extrapad)) {\n            array.splice(j, 1);\n            j--;\n        }\n    }\n    if(includeThis) {\n        var clipAtZero = (tozero && newVal === 0);\n        array.push({\n            val: newVal,\n            pad: clipAtZero ? 0 : newPad,\n            extrapad: clipAtZero ? false : extrapad\n        });\n    }\n}\n\n// In order to stop overflow errors, don't consider points\n// too close to the limits of js floating point\nfunction goodNumber(v) {\n    return isNumeric(v) && Math.abs(v) < FP_SAFE;\n}\n\nfunction lessOrEqual(v0, v1) { return v0 <= v1; }\nfunction greaterOrEqual(v0, v1) { return v0 >= v1; }\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../registry\":847,\"fast-isnumeric\":225}],767:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\nvar Plots = _dereq_('../../plots/plots');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar Titles = _dereq_('../../components/titles');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\n\nvar axAttrs = _dereq_('./layout_attributes');\nvar cleanTicks = _dereq_('./clean_ticks');\n\nvar constants = _dereq_('../../constants/numerical');\nvar ONEAVGYEAR = constants.ONEAVGYEAR;\nvar ONEAVGMONTH = constants.ONEAVGMONTH;\nvar ONEDAY = constants.ONEDAY;\nvar ONEHOUR = constants.ONEHOUR;\nvar ONEMIN = constants.ONEMIN;\nvar ONESEC = constants.ONESEC;\nvar MINUS_SIGN = constants.MINUS_SIGN;\nvar BADNUM = constants.BADNUM;\n\nvar MID_SHIFT = _dereq_('../../constants/alignment').MID_SHIFT;\nvar LINE_SPACING = _dereq_('../../constants/alignment').LINE_SPACING;\n\nvar axes = module.exports = {};\n\naxes.setConvert = _dereq_('./set_convert');\nvar autoType = _dereq_('./axis_autotype');\n\nvar axisIds = _dereq_('./axis_ids');\naxes.id2name = axisIds.id2name;\naxes.name2id = axisIds.name2id;\naxes.cleanId = axisIds.cleanId;\naxes.list = axisIds.list;\naxes.listIds = axisIds.listIds;\naxes.getFromId = axisIds.getFromId;\naxes.getFromTrace = axisIds.getFromTrace;\n\nvar autorange = _dereq_('./autorange');\naxes.getAutoRange = autorange.getAutoRange;\naxes.findExtremes = autorange.findExtremes;\n\n/*\n * find the list of possible axes to reference with an xref or yref attribute\n * and coerce it to that list\n *\n * attr: the attribute we're generating a reference for. Should end in 'x' or 'y'\n *     but can be prefixed, like 'ax' for annotation's arrow x\n * dflt: the default to coerce to, or blank to use the first axis (falling back on\n *     extraOption if there is no axis)\n * extraOption: aside from existing axes with this letter, what non-axis value is allowed?\n *     Only required if it's different from `dflt`\n */\naxes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption) {\n    var axLetter = attr.charAt(attr.length - 1);\n    var axlist = gd._fullLayout._subplots[axLetter + 'axis'];\n    var refAttr = attr + 'ref';\n    var attrDef = {};\n\n    if(!dflt) dflt = axlist[0] || extraOption;\n    if(!extraOption) extraOption = dflt;\n\n    // data-ref annotations are not supported in gl2d yet\n\n    attrDef[refAttr] = {\n        valType: 'enumerated',\n        values: axlist.concat(extraOption ? [extraOption] : []),\n        dflt: dflt\n    };\n\n    // xref, yref\n    return Lib.coerce(containerIn, containerOut, attrDef, refAttr);\n};\n\n/*\n * coerce position attributes (range-type) that can be either on axes or absolute\n * (paper or pixel) referenced. The biggest complication here is that we don't know\n * before looking at the axis whether the value must be a number or not (it may be\n * a date string), so we can't use the regular valType='number' machinery\n *\n * axRef (string): the axis this position is referenced to, or:\n *     paper: fraction of the plot area\n *     pixel: pixels relative to some starting position\n * attr (string): the attribute in containerOut we are coercing\n * dflt (number): the default position, as a fraction or pixels. If the attribute\n *     is to be axis-referenced, this will be converted to an axis data value\n *\n * Also cleans the values, since the attribute definition itself has to say\n * valType: 'any' to handle date axes. This allows us to accept:\n * - for category axes: category names, and convert them here into serial numbers.\n *   Note that this will NOT work for axis range endpoints, because we don't know\n *   the category list yet (it's set by ax.makeCalcdata during calc)\n *   but it works for component (note, shape, images) positions.\n * - for date axes: JS Dates or milliseconds, and convert to date strings\n * - for other types: coerce them to numbers\n */\naxes.coercePosition = function(containerOut, gd, coerce, axRef, attr, dflt) {\n    var cleanPos, pos;\n\n    if(axRef === 'paper' || axRef === 'pixel') {\n        cleanPos = Lib.ensureNumber;\n        pos = coerce(attr, dflt);\n    } else {\n        var ax = axes.getFromId(gd, axRef);\n        dflt = ax.fraction2r(dflt);\n        pos = coerce(attr, dflt);\n        cleanPos = ax.cleanPos;\n    }\n\n    containerOut[attr] = cleanPos(pos);\n};\n\naxes.cleanPosition = function(pos, gd, axRef) {\n    var cleanPos = (axRef === 'paper' || axRef === 'pixel') ?\n        Lib.ensureNumber :\n        axes.getFromId(gd, axRef).cleanPos;\n\n    return cleanPos(pos);\n};\n\naxes.redrawComponents = function(gd, axIds) {\n    axIds = axIds ? axIds : axes.listIds(gd);\n\n    var fullLayout = gd._fullLayout;\n\n    function _redrawOneComp(moduleName, methodName, stashName, shortCircuit) {\n        var method = Registry.getComponentMethod(moduleName, methodName);\n        var stash = {};\n\n        for(var i = 0; i < axIds.length; i++) {\n            var ax = fullLayout[axes.id2name(axIds[i])];\n            var indices = ax[stashName];\n\n            for(var j = 0; j < indices.length; j++) {\n                var ind = indices[j];\n\n                if(!stash[ind]) {\n                    method(gd, ind);\n                    stash[ind] = 1;\n                    // once is enough for images (which doesn't use the `i` arg anyway)\n                    if(shortCircuit) return;\n                }\n            }\n        }\n    }\n\n    // annotations and shapes 'draw' method is slow,\n    // use the finer-grained 'drawOne' method instead\n    _redrawOneComp('annotations', 'drawOne', '_annIndices');\n    _redrawOneComp('shapes', 'drawOne', '_shapeIndices');\n    _redrawOneComp('images', 'draw', '_imgIndices', true);\n};\n\nvar getDataConversions = axes.getDataConversions = function(gd, trace, target, targetArray) {\n    var ax;\n\n    // If target points to an axis, use the type we already have for that\n    // axis to find the data type. Otherwise use the values to autotype.\n    var d2cTarget = (target === 'x' || target === 'y' || target === 'z') ?\n        target :\n        targetArray;\n\n    // In the case of an array target, make a mock data array\n    // and call supplyDefaults to the data type and\n    // setup the data-to-calc method.\n    if(Array.isArray(d2cTarget)) {\n        ax = {\n            type: autoType(targetArray),\n            _categories: []\n        };\n        axes.setConvert(ax);\n\n        // build up ax._categories (usually done during ax.makeCalcdata()\n        if(ax.type === 'category') {\n            for(var i = 0; i < targetArray.length; i++) {\n                ax.d2c(targetArray[i]);\n            }\n        }\n        // TODO what to do for transforms?\n    } else {\n        ax = axes.getFromTrace(gd, trace, d2cTarget);\n    }\n\n    // if 'target' has corresponding axis\n    // -> use setConvert method\n    if(ax) return {d2c: ax.d2c, c2d: ax.c2d};\n\n    // special case for 'ids'\n    // -> cast to String\n    if(d2cTarget === 'ids') return {d2c: toString, c2d: toString};\n\n    // otherwise (e.g. numeric-array of 'marker.color' or 'marker.size')\n    // -> cast to Number\n\n    return {d2c: toNum, c2d: toNum};\n};\n\nfunction toNum(v) { return +v; }\nfunction toString(v) { return String(v); }\n\naxes.getDataToCoordFunc = function(gd, trace, target, targetArray) {\n    return getDataConversions(gd, trace, target, targetArray).d2c;\n};\n\n// get counteraxis letter for this axis (name or id)\n// this can also be used as the id for default counter axis\naxes.counterLetter = function(id) {\n    var axLetter = id.charAt(0);\n    if(axLetter === 'x') return 'y';\n    if(axLetter === 'y') return 'x';\n};\n\n// incorporate a new minimum difference and first tick into\n// forced\n// note that _forceTick0 is linearized, so needs to be turned into\n// a range value for setting tick0\naxes.minDtick = function(ax, newDiff, newFirst, allow) {\n    // doesn't make sense to do forced min dTick on log or category axes,\n    // and the plot itself may decide to cancel (ie non-grouped bars)\n    if(['log', 'category', 'multicategory'].indexOf(ax.type) !== -1 || !allow) {\n        ax._minDtick = 0;\n    } else if(ax._minDtick === undefined) {\n        // undefined means there's nothing there yet\n\n        ax._minDtick = newDiff;\n        ax._forceTick0 = newFirst;\n    } else if(ax._minDtick) {\n        if((ax._minDtick / newDiff + 1e-6) % 1 < 2e-6 &&\n            // existing minDtick is an integer multiple of newDiff\n            // (within rounding err)\n            // and forceTick0 can be shifted to newFirst\n\n                (((newFirst - ax._forceTick0) / newDiff % 1) +\n                    1.000001) % 1 < 2e-6) {\n            ax._minDtick = newDiff;\n            ax._forceTick0 = newFirst;\n        } else if((newDiff / ax._minDtick + 1e-6) % 1 > 2e-6 ||\n            // if the converse is true (newDiff is a multiple of minDtick and\n            // newFirst can be shifted to forceTick0) then do nothing - same\n            // forcing stands. Otherwise, cancel forced minimum\n\n                (((newFirst - ax._forceTick0) / ax._minDtick % 1) +\n                    1.000001) % 1 > 2e-6) {\n            ax._minDtick = 0;\n        }\n    }\n};\n\n// save a copy of the initial axis ranges in fullLayout\n// use them in mode bar and dblclick events\naxes.saveRangeInitial = function(gd, overwrite) {\n    var axList = axes.list(gd, '', true);\n    var hasOneAxisChanged = false;\n\n    for(var i = 0; i < axList.length; i++) {\n        var ax = axList[i];\n        var isNew = (ax._rangeInitial === undefined);\n        var hasChanged = isNew || !(\n            ax.range[0] === ax._rangeInitial[0] &&\n            ax.range[1] === ax._rangeInitial[1]\n        );\n\n        if((isNew && ax.autorange === false) || (overwrite && hasChanged)) {\n            ax._rangeInitial = ax.range.slice();\n            hasOneAxisChanged = true;\n        }\n    }\n\n    return hasOneAxisChanged;\n};\n\n// save a copy of the initial spike visibility\naxes.saveShowSpikeInitial = function(gd, overwrite) {\n    var axList = axes.list(gd, '', true);\n    var hasOneAxisChanged = false;\n    var allSpikesEnabled = 'on';\n\n    for(var i = 0; i < axList.length; i++) {\n        var ax = axList[i];\n        var isNew = (ax._showSpikeInitial === undefined);\n        var hasChanged = isNew || !(ax.showspikes === ax._showspikes);\n\n        if(isNew || (overwrite && hasChanged)) {\n            ax._showSpikeInitial = ax.showspikes;\n            hasOneAxisChanged = true;\n        }\n\n        if(allSpikesEnabled === 'on' && !ax.showspikes) {\n            allSpikesEnabled = 'off';\n        }\n    }\n    gd._fullLayout._cartesianSpikesEnabled = allSpikesEnabled;\n    return hasOneAxisChanged;\n};\n\naxes.autoBin = function(data, ax, nbins, is2d, calendar, size) {\n    var dataMin = Lib.aggNums(Math.min, null, data);\n    var dataMax = Lib.aggNums(Math.max, null, data);\n\n    if(ax.type === 'category' || ax.type === 'multicategory') {\n        return {\n            start: dataMin - 0.5,\n            end: dataMax + 0.5,\n            size: Math.max(1, Math.round(size) || 1),\n            _dataSpan: dataMax - dataMin,\n        };\n    }\n\n    if(!calendar) calendar = ax.calendar;\n\n    // piggyback off tick code to make \"nice\" bin sizes and edges\n    var dummyAx;\n    if(ax.type === 'log') {\n        dummyAx = {\n            type: 'linear',\n            range: [dataMin, dataMax]\n        };\n    } else {\n        dummyAx = {\n            type: ax.type,\n            range: Lib.simpleMap([dataMin, dataMax], ax.c2r, 0, calendar),\n            calendar: calendar\n        };\n    }\n    axes.setConvert(dummyAx);\n\n    size = size && cleanTicks.dtick(size, dummyAx.type);\n\n    if(size) {\n        dummyAx.dtick = size;\n        dummyAx.tick0 = cleanTicks.tick0(undefined, dummyAx.type, calendar);\n    } else {\n        var size0;\n        if(nbins) size0 = ((dataMax - dataMin) / nbins);\n        else {\n            // totally auto: scale off std deviation so the highest bin is\n            // somewhat taller than the total number of bins, but don't let\n            // the size get smaller than the 'nice' rounded down minimum\n            // difference between values\n            var distinctData = Lib.distinctVals(data);\n            var msexp = Math.pow(10, Math.floor(\n                Math.log(distinctData.minDiff) / Math.LN10));\n            var minSize = msexp * Lib.roundUp(\n                distinctData.minDiff / msexp, [0.9, 1.9, 4.9, 9.9], true);\n            size0 = Math.max(minSize, 2 * Lib.stdev(data) /\n                Math.pow(data.length, is2d ? 0.25 : 0.4));\n\n            // fallback if ax.d2c output BADNUMs\n            // e.g. when user try to plot categorical bins\n            // on a layout.xaxis.type: 'linear'\n            if(!isNumeric(size0)) size0 = 1;\n        }\n\n        axes.autoTicks(dummyAx, size0);\n    }\n\n    var finalSize = dummyAx.dtick;\n    var binStart = axes.tickIncrement(\n            axes.tickFirst(dummyAx), finalSize, 'reverse', calendar);\n    var binEnd, bincount;\n\n    // check for too many data points right at the edges of bins\n    // (>50% within 1% of bin edges) or all data points integral\n    // and offset the bins accordingly\n    if(typeof finalSize === 'number') {\n        binStart = autoShiftNumericBins(binStart, data, dummyAx, dataMin, dataMax);\n\n        bincount = 1 + Math.floor((dataMax - binStart) / finalSize);\n        binEnd = binStart + bincount * finalSize;\n    } else {\n        // month ticks - should be the only nonlinear kind we have at this point.\n        // dtick (as supplied by axes.autoTick) only has nonlinear values on\n        // date and log axes, but even if you display a histogram on a log axis\n        // we bin it on a linear axis (which one could argue against, but that's\n        // a separate issue)\n        if(dummyAx.dtick.charAt(0) === 'M') {\n            binStart = autoShiftMonthBins(binStart, data, finalSize, dataMin, calendar);\n        }\n\n        // calculate the endpoint for nonlinear ticks - you have to\n        // just increment until you're done\n        binEnd = binStart;\n        bincount = 0;\n        while(binEnd <= dataMax) {\n            binEnd = axes.tickIncrement(binEnd, finalSize, false, calendar);\n            bincount++;\n        }\n    }\n\n    return {\n        start: ax.c2r(binStart, 0, calendar),\n        end: ax.c2r(binEnd, 0, calendar),\n        size: finalSize,\n        _dataSpan: dataMax - dataMin\n    };\n};\n\n\nfunction autoShiftNumericBins(binStart, data, ax, dataMin, dataMax) {\n    var edgecount = 0;\n    var midcount = 0;\n    var intcount = 0;\n    var blankCount = 0;\n\n    function nearEdge(v) {\n        // is a value within 1% of a bin edge?\n        return (1 + (v - binStart) * 100 / ax.dtick) % 100 < 2;\n    }\n\n    for(var i = 0; i < data.length; i++) {\n        if(data[i] % 1 === 0) intcount++;\n        else if(!isNumeric(data[i])) blankCount++;\n\n        if(nearEdge(data[i])) edgecount++;\n        if(nearEdge(data[i] + ax.dtick / 2)) midcount++;\n    }\n    var dataCount = data.length - blankCount;\n\n    if(intcount === dataCount && ax.type !== 'date') {\n        if(ax.dtick < 1) {\n            // all integers: if bin size is <1, it's because\n            // that was specifically requested (large nbins)\n            // so respect that... but center the bins containing\n            // integers on those integers\n\n            binStart = dataMin - 0.5 * ax.dtick;\n        } else {\n            // otherwise start half an integer down regardless of\n            // the bin size, just enough to clear up endpoint\n            // ambiguity about which integers are in which bins.\n\n            binStart -= 0.5;\n            if(binStart + ax.dtick < dataMin) binStart += ax.dtick;\n        }\n    } else if(midcount < dataCount * 0.1) {\n        if(edgecount > dataCount * 0.3 ||\n                nearEdge(dataMin) || nearEdge(dataMax)) {\n            // lots of points at the edge, not many in the middle\n            // shift half a bin\n            var binshift = ax.dtick / 2;\n            binStart += (binStart + binshift < dataMin) ? binshift : -binshift;\n        }\n    }\n    return binStart;\n}\n\n\nfunction autoShiftMonthBins(binStart, data, dtick, dataMin, calendar) {\n    var stats = Lib.findExactDates(data, calendar);\n    // number of data points that needs to be an exact value\n    // to shift that increment to (near) the bin center\n    var threshold = 0.8;\n\n    if(stats.exactDays > threshold) {\n        var numMonths = Number(dtick.substr(1));\n\n        if((stats.exactYears > threshold) && (numMonths % 12 === 0)) {\n            // The exact middle of a non-leap-year is 1.5 days into July\n            // so if we start the bins here, all but leap years will\n            // get hover-labeled as exact years.\n            binStart = axes.tickIncrement(binStart, 'M6', 'reverse') + ONEDAY * 1.5;\n        } else if(stats.exactMonths > threshold) {\n            // Months are not as clean, but if we shift half the *longest*\n            // month (31/2 days) then 31-day months will get labeled exactly\n            // and shorter months will get labeled with the correct month\n            // but shifted 12-36 hours into it.\n            binStart = axes.tickIncrement(binStart, 'M1', 'reverse') + ONEDAY * 15.5;\n        } else {\n            // Shifting half a day is exact, but since these are month bins it\n            // will always give a somewhat odd-looking label, until we do something\n            // smarter like showing the bin boundaries (or the bounds of the actual\n            // data in each bin)\n            binStart -= ONEDAY / 2;\n        }\n        var nextBinStart = axes.tickIncrement(binStart, dtick);\n\n        if(nextBinStart <= dataMin) return nextBinStart;\n    }\n    return binStart;\n}\n\n// ----------------------------------------------------\n// Ticks and grids\n// ----------------------------------------------------\n\n// ensure we have tick0, dtick, and tick rounding calculated\naxes.prepTicks = function(ax) {\n    var rng = Lib.simpleMap(ax.range, ax.r2l);\n\n    // calculate max number of (auto) ticks to display based on plot size\n    if(ax.tickmode === 'auto' || !ax.dtick) {\n        var nt = ax.nticks;\n        var minPx;\n\n        if(!nt) {\n            if(ax.type === 'category' || ax.type === 'multicategory') {\n                minPx = ax.tickfont ? (ax.tickfont.size || 12) * 1.2 : 15;\n                nt = ax._length / minPx;\n            } else {\n                minPx = ax._id.charAt(0) === 'y' ? 40 : 80;\n                nt = Lib.constrain(ax._length / minPx, 4, 9) + 1;\n            }\n\n            // radial axes span half their domain,\n            // multiply nticks value by two to get correct number of auto ticks.\n            if(ax._name === 'radialaxis') nt *= 2;\n        }\n\n        // add a couple of extra digits for filling in ticks when we\n        // have explicit tickvals without tick text\n        if(ax.tickmode === 'array') nt *= 100;\n\n        axes.autoTicks(ax, Math.abs(rng[1] - rng[0]) / nt);\n        // check for a forced minimum dtick\n        if(ax._minDtick > 0 && ax.dtick < ax._minDtick * 2) {\n            ax.dtick = ax._minDtick;\n            ax.tick0 = ax.l2r(ax._forceTick0);\n        }\n    }\n\n    // check for missing tick0\n    if(!ax.tick0) {\n        ax.tick0 = (ax.type === 'date') ? '2000-01-01' : 0;\n    }\n\n    // ensure we don't try to make ticks below our minimum precision\n    // see https://github.com/plotly/plotly.js/issues/2892\n    if(ax.type === 'date' && ax.dtick < 0.1) ax.dtick = 0.1;\n\n    // now figure out rounding of tick values\n    autoTickRound(ax);\n};\n\n// calculate the ticks: text, values, positioning\n// if ticks are set to automatic, determine the right values (tick0,dtick)\n// in any case, set tickround to # of digits to round tick labels to,\n// or codes to this effect for log and date scales\naxes.calcTicks = function calcTicks(ax) {\n    axes.prepTicks(ax);\n    var rng = Lib.simpleMap(ax.range, ax.r2l);\n\n    // now that we've figured out the auto values for formatting\n    // in case we're missing some ticktext, we can break out for array ticks\n    if(ax.tickmode === 'array') return arrayTicks(ax);\n\n    // find the first tick\n    ax._tmin = axes.tickFirst(ax);\n\n    // add a tiny bit so we get ticks which may have rounded out\n    var startTick = rng[0] * 1.0001 - rng[1] * 0.0001;\n    var endTick = rng[1] * 1.0001 - rng[0] * 0.0001;\n    // check for reversed axis\n    var axrev = (rng[1] < rng[0]);\n\n    // No visible ticks? Quit.\n    // I've only seen this on category axes with all categories off the edge.\n    if((ax._tmin < startTick) !== axrev) return [];\n\n    // return the full set of tick vals\n    var tickVals = [];\n    if(ax.type === 'category' || ax.type === 'multicategory') {\n        endTick = (axrev) ? Math.max(-0.5, endTick) :\n            Math.min(ax._categories.length - 0.5, endTick);\n    }\n\n    var isDLog = (ax.type === 'log') && !(isNumeric(ax.dtick) || ax.dtick.charAt(0) === 'L');\n\n    var xPrevious = null;\n    var maxTicks = Math.max(1000, ax._length || 0);\n    for(var x = ax._tmin;\n            (axrev) ? (x >= endTick) : (x <= endTick);\n            x = axes.tickIncrement(x, ax.dtick, axrev, ax.calendar)) {\n        // prevent infinite loops - no more than one tick per pixel,\n        // and make sure each value is different from the previous\n        if(tickVals.length > maxTicks || x === xPrevious) break;\n        xPrevious = x;\n\n        var minor = false;\n        if(isDLog && (x !== (x | 0))) {\n            minor = true;\n        }\n\n        tickVals.push({\n            minor: minor,\n            value: x\n        });\n    }\n\n    // If same angle over a full circle, the last tick vals is a duplicate.\n    // TODO must do something similar for angular date axes.\n    if(isAngular(ax) && Math.abs(rng[1] - rng[0]) === 360) {\n        tickVals.pop();\n    }\n\n    // save the last tick as well as first, so we can\n    // show the exponent only on the last one\n    ax._tmax = (tickVals[tickVals.length - 1] || {}).value;\n\n    // for showing the rest of a date when the main tick label is only the\n    // latter part: ax._prevDateHead holds what we showed most recently.\n    // Start with it cleared and mark that we're in calcTicks (ie calculating a\n    // whole string of these so we should care what the previous date head was!)\n    ax._prevDateHead = '';\n    ax._inCalcTicks = true;\n\n    var ticksOut = new Array(tickVals.length);\n    for(var i = 0; i < tickVals.length; i++) {\n        ticksOut[i] = axes.tickText(\n            ax,\n            tickVals[i].value,\n            false, // hover\n            tickVals[i].minor // noSuffixPrefix\n        );\n    }\n\n    ax._inCalcTicks = false;\n\n    return ticksOut;\n};\n\nfunction arrayTicks(ax) {\n    var vals = ax.tickvals;\n    var text = ax.ticktext;\n    var ticksOut = new Array(vals.length);\n    var rng = Lib.simpleMap(ax.range, ax.r2l);\n    var r0expanded = rng[0] * 1.0001 - rng[1] * 0.0001;\n    var r1expanded = rng[1] * 1.0001 - rng[0] * 0.0001;\n    var tickMin = Math.min(r0expanded, r1expanded);\n    var tickMax = Math.max(r0expanded, r1expanded);\n    var j = 0;\n\n    // without a text array, just format the given values as any other ticks\n    // except with more precision to the numbers\n    if(!Array.isArray(text)) text = [];\n\n    // make sure showing ticks doesn't accidentally add new categories\n    // TODO multicategory, if we allow ticktext / tickvals\n    var tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;\n\n    // array ticks on log axes always show the full number\n    // (if no explicit ticktext overrides it)\n    if(ax.type === 'log' && String(ax.dtick).charAt(0) !== 'L') {\n        ax.dtick = 'L' + Math.pow(10, Math.floor(Math.min(ax.range[0], ax.range[1])) - 1);\n    }\n\n    for(var i = 0; i < vals.length; i++) {\n        var vali = tickVal2l(vals[i]);\n        if(vali > tickMin && vali < tickMax) {\n            if(text[i] === undefined) ticksOut[j] = axes.tickText(ax, vali);\n            else ticksOut[j] = tickTextObj(ax, vali, String(text[i]));\n            j++;\n        }\n    }\n\n    if(j < vals.length) ticksOut.splice(j, vals.length - j);\n\n    return ticksOut;\n}\n\nvar roundBase10 = [2, 5, 10];\nvar roundBase24 = [1, 2, 3, 6, 12];\nvar roundBase60 = [1, 2, 5, 10, 15, 30];\n// 2&3 day ticks are weird, but need something btwn 1&7\nvar roundDays = [1, 2, 3, 7, 14];\n// approx. tick positions for log axes, showing all (1) and just 1, 2, 5 (2)\n// these don't have to be exact, just close enough to round to the right value\nvar roundLog1 = [-0.046, 0, 0.301, 0.477, 0.602, 0.699, 0.778, 0.845, 0.903, 0.954, 1];\nvar roundLog2 = [-0.301, 0, 0.301, 0.699, 1];\n// N.B. `thetaunit; 'radians' angular axes must be converted to degrees\nvar roundAngles = [15, 30, 45, 90, 180];\n\nfunction roundDTick(roughDTick, base, roundingSet) {\n    return base * Lib.roundUp(roughDTick / base, roundingSet);\n}\n\n// autoTicks: calculate best guess at pleasant ticks for this axis\n// inputs:\n//      ax - an axis object\n//      roughDTick - rough tick spacing (to be turned into a nice round number)\n// outputs (into ax):\n//   tick0: starting point for ticks (not necessarily on the graph)\n//      usually 0 for numeric (=10^0=1 for log) or jan 1, 2000 for dates\n//   dtick: the actual, nice round tick spacing, usually a little larger than roughDTick\n//      if the ticks are spaced linearly (linear scale, categories,\n//          log with only full powers, date ticks < month),\n//          this will just be a number\n//      months: M#\n//      years: M# where # is 12*number of years\n//      log with linear ticks: L# where # is the linear tick spacing\n//      log showing powers plus some intermediates:\n//          D1 shows all digits, D2 shows 2 and 5\naxes.autoTicks = function(ax, roughDTick) {\n    var base;\n\n    function getBase(v) {\n        return Math.pow(v, Math.floor(Math.log(roughDTick) / Math.LN10));\n    }\n\n    if(ax.type === 'date') {\n        ax.tick0 = Lib.dateTick0(ax.calendar);\n        // the criteria below are all based on the rough spacing we calculate\n        // being > half of the final unit - so precalculate twice the rough val\n        var roughX2 = 2 * roughDTick;\n\n        if(roughX2 > ONEAVGYEAR) {\n            roughDTick /= ONEAVGYEAR;\n            base = getBase(10);\n            ax.dtick = 'M' + (12 * roundDTick(roughDTick, base, roundBase10));\n        } else if(roughX2 > ONEAVGMONTH) {\n            roughDTick /= ONEAVGMONTH;\n            ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);\n        } else if(roughX2 > ONEDAY) {\n            ax.dtick = roundDTick(roughDTick, ONEDAY, roundDays);\n            // get week ticks on sunday\n            // this will also move the base tick off 2000-01-01 if dtick is\n            // 2 or 3 days... but that's a weird enough case that we'll ignore it.\n            ax.tick0 = Lib.dateTick0(ax.calendar, true);\n        } else if(roughX2 > ONEHOUR) {\n            ax.dtick = roundDTick(roughDTick, ONEHOUR, roundBase24);\n        } else if(roughX2 > ONEMIN) {\n            ax.dtick = roundDTick(roughDTick, ONEMIN, roundBase60);\n        } else if(roughX2 > ONESEC) {\n            ax.dtick = roundDTick(roughDTick, ONESEC, roundBase60);\n        } else {\n            // milliseconds\n            base = getBase(10);\n            ax.dtick = roundDTick(roughDTick, base, roundBase10);\n        }\n    } else if(ax.type === 'log') {\n        ax.tick0 = 0;\n        var rng = Lib.simpleMap(ax.range, ax.r2l);\n\n        if(roughDTick > 0.7) {\n            // only show powers of 10\n            ax.dtick = Math.ceil(roughDTick);\n        } else if(Math.abs(rng[1] - rng[0]) < 1) {\n            // span is less than one power of 10\n            var nt = 1.5 * Math.abs((rng[1] - rng[0]) / roughDTick);\n\n            // ticks on a linear scale, labeled fully\n            roughDTick = Math.abs(Math.pow(10, rng[1]) -\n                Math.pow(10, rng[0])) / nt;\n            base = getBase(10);\n            ax.dtick = 'L' + roundDTick(roughDTick, base, roundBase10);\n        } else {\n            // include intermediates between powers of 10,\n            // labeled with small digits\n            // ax.dtick = \"D2\" (show 2 and 5) or \"D1\" (show all digits)\n            ax.dtick = (roughDTick > 0.3) ? 'D2' : 'D1';\n        }\n    } else if(ax.type === 'category' || ax.type === 'multicategory') {\n        ax.tick0 = 0;\n        ax.dtick = Math.ceil(Math.max(roughDTick, 1));\n    } else if(isAngular(ax)) {\n        ax.tick0 = 0;\n        base = 1;\n        ax.dtick = roundDTick(roughDTick, base, roundAngles);\n    } else {\n        // auto ticks always start at 0\n        ax.tick0 = 0;\n        base = getBase(10);\n        ax.dtick = roundDTick(roughDTick, base, roundBase10);\n    }\n\n    // prevent infinite loops\n    if(ax.dtick === 0) ax.dtick = 1;\n\n    // TODO: this is from log axis histograms with autorange off\n    if(!isNumeric(ax.dtick) && typeof ax.dtick !== 'string') {\n        var olddtick = ax.dtick;\n        ax.dtick = 1;\n        throw 'ax.dtick error: ' + String(olddtick);\n    }\n};\n\n// after dtick is already known, find tickround = precision\n// to display in tick labels\n//   for numeric ticks, integer # digits after . to round to\n//   for date ticks, the last date part to show (y,m,d,H,M,S)\n//      or an integer # digits past seconds\nfunction autoTickRound(ax) {\n    var dtick = ax.dtick;\n\n    ax._tickexponent = 0;\n    if(!isNumeric(dtick) && typeof dtick !== 'string') {\n        dtick = 1;\n    }\n\n    if(ax.type === 'category' || ax.type === 'multicategory') {\n        ax._tickround = null;\n    }\n    if(ax.type === 'date') {\n        // If tick0 is unusual, give tickround a bit more information\n        // not necessarily *all* the information in tick0 though, if it's really odd\n        // minimal string length for tick0: 'd' is 10, 'M' is 16, 'S' is 19\n        // take off a leading minus (year < 0) and i (intercalary month) so length is consistent\n        var tick0ms = ax.r2l(ax.tick0);\n        var tick0str = ax.l2r(tick0ms).replace(/(^-|i)/g, '');\n        var tick0len = tick0str.length;\n\n        if(String(dtick).charAt(0) === 'M') {\n            // any tick0 more specific than a year: alway show the full date\n            if(tick0len > 10 || tick0str.substr(5) !== '01-01') ax._tickround = 'd';\n            // show the month unless ticks are full multiples of a year\n            else ax._tickround = (+(dtick.substr(1)) % 12 === 0) ? 'y' : 'm';\n        } else if((dtick >= ONEDAY && tick0len <= 10) || (dtick >= ONEDAY * 15)) ax._tickround = 'd';\n        else if((dtick >= ONEMIN && tick0len <= 16) || (dtick >= ONEHOUR)) ax._tickround = 'M';\n        else if((dtick >= ONESEC && tick0len <= 19) || (dtick >= ONEMIN)) ax._tickround = 'S';\n        else {\n            // tickround is a number of digits of fractional seconds\n            // of any two adjacent ticks, at least one will have the maximum fractional digits\n            // of all possible ticks - so take the max. length of tick0 and the next one\n            var tick1len = ax.l2r(tick0ms + dtick).replace(/^-/, '').length;\n            ax._tickround = Math.max(tick0len, tick1len) - 20;\n\n            // We shouldn't get here... but in case there's a situation I'm\n            // not thinking of where tick0str and tick1str are identical or\n            // something, fall back on maximum precision\n            if(ax._tickround < 0) ax._tickround = 4;\n        }\n    } else if(isNumeric(dtick) || dtick.charAt(0) === 'L') {\n        // linear or log (except D1, D2)\n        var rng = ax.range.map(ax.r2d || Number);\n        if(!isNumeric(dtick)) dtick = Number(dtick.substr(1));\n        // 2 digits past largest digit of dtick\n        ax._tickround = 2 - Math.floor(Math.log(dtick) / Math.LN10 + 0.01);\n\n        var maxend = Math.max(Math.abs(rng[0]), Math.abs(rng[1]));\n\n        var rangeexp = Math.floor(Math.log(maxend) / Math.LN10 + 0.01);\n        if(Math.abs(rangeexp) > 3) {\n            if(isSIFormat(ax.exponentformat) && !beyondSI(rangeexp)) {\n                ax._tickexponent = 3 * Math.round((rangeexp - 1) / 3);\n            } else ax._tickexponent = rangeexp;\n        }\n    } else {\n        // D1 or D2 (log)\n        ax._tickround = null;\n    }\n}\n\n// months and years don't have constant millisecond values\n// (but a year is always 12 months so we only need months)\n// log-scale ticks are also not consistently spaced, except\n// for pure powers of 10\n// numeric ticks always have constant differences, other datetime ticks\n// can all be calculated as constant number of milliseconds\naxes.tickIncrement = function(x, dtick, axrev, calendar) {\n    var axSign = axrev ? -1 : 1;\n\n    // includes linear, all dates smaller than month, and pure 10^n in log\n    if(isNumeric(dtick)) return x + axSign * dtick;\n\n    // everything else is a string, one character plus a number\n    var tType = dtick.charAt(0);\n    var dtSigned = axSign * Number(dtick.substr(1));\n\n    // Dates: months (or years - see Lib.incrementMonth)\n    if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);\n\n    // Log scales: Linear, Digits\n    else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;\n\n    // log10 of 2,5,10, or all digits (logs just have to be\n    // close enough to round)\n    else if(tType === 'D') {\n        var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;\n        var x2 = x + axSign * 0.01;\n        var frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);\n\n        return Math.floor(x2) +\n            Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;\n    } else throw 'unrecognized dtick ' + String(dtick);\n};\n\n// calculate the first tick on an axis\naxes.tickFirst = function(ax) {\n    var r2l = ax.r2l || Number;\n    var rng = Lib.simpleMap(ax.range, r2l);\n    var axrev = rng[1] < rng[0];\n    var sRound = axrev ? Math.floor : Math.ceil;\n    // add a tiny extra bit to make sure we get ticks\n    // that may have been rounded out\n    var r0 = rng[0] * 1.0001 - rng[1] * 0.0001;\n    var dtick = ax.dtick;\n    var tick0 = r2l(ax.tick0);\n\n    if(isNumeric(dtick)) {\n        var tmin = sRound((r0 - tick0) / dtick) * dtick + tick0;\n\n        // make sure no ticks outside the category list\n        if(ax.type === 'category' || ax.type === 'multicategory') {\n            tmin = Lib.constrain(tmin, 0, ax._categories.length - 1);\n        }\n        return tmin;\n    }\n\n    var tType = dtick.charAt(0);\n    var dtNum = Number(dtick.substr(1));\n\n    // Dates: months (or years)\n    if(tType === 'M') {\n        var cnt = 0;\n        var t0 = tick0;\n        var t1, mult, newDTick;\n\n        // This algorithm should work for *any* nonlinear (but close to linear!)\n        // tick spacing. Limit to 10 iterations, for gregorian months it's normally <=3.\n        while(cnt < 10) {\n            t1 = axes.tickIncrement(t0, dtick, axrev, ax.calendar);\n            if((t1 - r0) * (t0 - r0) <= 0) {\n                // t1 and t0 are on opposite sides of r0! we've succeeded!\n                if(axrev) return Math.min(t0, t1);\n                return Math.max(t0, t1);\n            }\n            mult = (r0 - ((t0 + t1) / 2)) / (t1 - t0);\n            newDTick = tType + ((Math.abs(Math.round(mult)) || 1) * dtNum);\n            t0 = axes.tickIncrement(t0, newDTick, mult < 0 ? !axrev : axrev, ax.calendar);\n            cnt++;\n        }\n        Lib.error('tickFirst did not converge', ax);\n        return t0;\n    } else if(tType === 'L') {\n        // Log scales: Linear, Digits\n\n        return Math.log(sRound(\n            (Math.pow(10, r0) - tick0) / dtNum) * dtNum + tick0) / Math.LN10;\n    } else if(tType === 'D') {\n        var tickset = (dtick === 'D2') ? roundLog2 : roundLog1;\n        var frac = Lib.roundUp(Lib.mod(r0, 1), tickset, axrev);\n\n        return Math.floor(r0) +\n            Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;\n    } else throw 'unrecognized dtick ' + String(dtick);\n};\n\n// draw the text for one tick.\n// px,py are the location on gd.paper\n// prefix is there so the x axis ticks can be dropped a line\n// ax is the axis layout, x is the tick value\n// hover is a (truthy) flag for whether to show numbers with a bit\n// more precision for hovertext\naxes.tickText = function(ax, x, hover, noSuffixPrefix) {\n    var out = tickTextObj(ax, x);\n    var arrayMode = ax.tickmode === 'array';\n    var extraPrecision = hover || arrayMode;\n    var axType = ax.type;\n    // TODO multicategory, if we allow ticktext / tickvals\n    var tickVal2l = axType === 'category' ? ax.d2l_noadd : ax.d2l;\n    var i;\n\n    if(arrayMode && Array.isArray(ax.ticktext)) {\n        var rng = Lib.simpleMap(ax.range, ax.r2l);\n        var minDiff = Math.abs(rng[1] - rng[0]) / 10000;\n\n        for(i = 0; i < ax.ticktext.length; i++) {\n            if(Math.abs(x - tickVal2l(ax.tickvals[i])) < minDiff) break;\n        }\n        if(i < ax.ticktext.length) {\n            out.text = String(ax.ticktext[i]);\n            return out;\n        }\n    }\n\n    function isHidden(showAttr) {\n        if(showAttr === undefined) return true;\n        if(hover) return showAttr === 'none';\n\n        var firstOrLast = {\n            first: ax._tmin,\n            last: ax._tmax\n        }[showAttr];\n\n        return showAttr !== 'all' && x !== firstOrLast;\n    }\n\n    var hideexp = hover ?\n        'never' :\n        ax.exponentformat !== 'none' && isHidden(ax.showexponent) ? 'hide' : '';\n\n    if(axType === 'date') formatDate(ax, out, hover, extraPrecision);\n    else if(axType === 'log') formatLog(ax, out, hover, extraPrecision, hideexp);\n    else if(axType === 'category') formatCategory(ax, out);\n    else if(axType === 'multicategory') formatMultiCategory(ax, out, hover);\n    else if(isAngular(ax)) formatAngle(ax, out, hover, extraPrecision, hideexp);\n    else formatLinear(ax, out, hover, extraPrecision, hideexp);\n\n    // add prefix and suffix\n    if(!noSuffixPrefix) {\n        if(ax.tickprefix && !isHidden(ax.showtickprefix)) out.text = ax.tickprefix + out.text;\n        if(ax.ticksuffix && !isHidden(ax.showticksuffix)) out.text += ax.ticksuffix;\n    }\n\n    // Setup ticks and grid lines boundaries\n    // at 1/2 a 'category' to the left/bottom\n    if(ax.tickson === 'boundaries' || ax.showdividers) {\n        var inbounds = function(v) {\n            var p = ax.l2p(v);\n            return p >= 0 && p <= ax._length ? v : null;\n        };\n\n        out.xbnd = [\n            inbounds(out.x - 0.5),\n            inbounds(out.x + ax.dtick - 0.5)\n        ];\n    }\n\n    return out;\n};\n\n/**\n * create text for a hover label on this axis, with special handling of\n * log axes (where negative values can't be displayed but can appear in hover text)\n *\n * @param {object} ax: the axis to format text for\n * @param {number} val: calcdata value to format\n * @param {Optional(number)} val2: a second value to display\n *\n * @returns {string} `val` formatted as a string appropriate to this axis, or\n *     `val` and `val2` as a range (ie '<val> - <val2>') if `val2` is provided and\n *     it's different from `val`.\n */\naxes.hoverLabelText = function(ax, val, val2) {\n    if(val2 !== BADNUM && val2 !== val) {\n        return axes.hoverLabelText(ax, val) + ' - ' + axes.hoverLabelText(ax, val2);\n    }\n\n    var logOffScale = (ax.type === 'log' && val <= 0);\n    var tx = axes.tickText(ax, ax.c2l(logOffScale ? -val : val), 'hover').text;\n\n    if(logOffScale) {\n        return val === 0 ? '0' : MINUS_SIGN + tx;\n    }\n\n    // TODO: should we do something special if the axis calendar and\n    // the data calendar are different? Somehow display both dates with\n    // their system names? Right now it will just display in the axis calendar\n    // but users could add the other one as text.\n    return tx;\n};\n\nfunction tickTextObj(ax, x, text) {\n    var tf = ax.tickfont || {};\n\n    return {\n        x: x,\n        dx: 0,\n        dy: 0,\n        text: text || '',\n        fontSize: tf.size,\n        font: tf.family,\n        fontColor: tf.color\n    };\n}\n\nfunction formatDate(ax, out, hover, extraPrecision) {\n    var tr = ax._tickround;\n    var fmt = (hover && ax.hoverformat) || axes.getTickFormat(ax);\n\n    if(extraPrecision) {\n        // second or sub-second precision: extra always shows max digits.\n        // for other fields, extra precision just adds one field.\n        if(isNumeric(tr)) tr = 4;\n        else tr = {y: 'm', m: 'd', d: 'M', M: 'S', S: 4}[tr];\n    }\n\n    var dateStr = Lib.formatDate(out.x, fmt, tr, ax._dateFormat, ax.calendar, ax._extraFormat);\n    var headStr;\n\n    var splitIndex = dateStr.indexOf('\\n');\n    if(splitIndex !== -1) {\n        headStr = dateStr.substr(splitIndex + 1);\n        dateStr = dateStr.substr(0, splitIndex);\n    }\n\n    if(extraPrecision) {\n        // if extraPrecision led to trailing zeros, strip them off\n        // actually, this can lead to removing even more zeros than\n        // in the original rounding, but that's fine because in these\n        // contexts uniformity is not so important (if there's even\n        // anything to be uniform with!)\n\n        // can we remove the whole time part?\n        if(dateStr === '00:00:00' || dateStr === '00:00') {\n            dateStr = headStr;\n            headStr = '';\n        } else if(dateStr.length === 8) {\n            // strip off seconds if they're zero (zero fractional seconds\n            // are already omitted)\n            // but we never remove minutes and leave just hours\n            dateStr = dateStr.replace(/:00$/, '');\n        }\n    }\n\n    if(headStr) {\n        if(hover) {\n            // hover puts it all on one line, so headPart works best up front\n            // except for year headPart: turn this into \"Jan 1, 2000\" etc.\n            if(tr === 'd') dateStr += ', ' + headStr;\n            else dateStr = headStr + (dateStr ? ', ' + dateStr : '');\n        } else if(!ax._inCalcTicks || (headStr !== ax._prevDateHead)) {\n            dateStr += '<br>' + headStr;\n            ax._prevDateHead = headStr;\n        }\n    }\n\n    out.text = dateStr;\n}\n\nfunction formatLog(ax, out, hover, extraPrecision, hideexp) {\n    var dtick = ax.dtick;\n    var x = out.x;\n    var tickformat = ax.tickformat;\n    var dtChar0 = typeof dtick === 'string' && dtick.charAt(0);\n\n    if(hideexp === 'never') {\n        // If this is a hover label, then we must *never* hide the exponent\n        // for the sake of display, which could give the wrong value by\n        // potentially many orders of magnitude. If hideexp was 'never', then\n        // it's now succeeded by preventing the other condition from automating\n        // this choice. Thus we can unset it so that the axis formatting takes\n        // precedence.\n        hideexp = '';\n    }\n\n    if(extraPrecision && (dtChar0 !== 'L')) {\n        dtick = 'L3';\n        dtChar0 = 'L';\n    }\n\n    if(tickformat || (dtChar0 === 'L')) {\n        out.text = numFormat(Math.pow(10, x), ax, hideexp, extraPrecision);\n    } else if(isNumeric(dtick) || ((dtChar0 === 'D') && (Lib.mod(x + 0.01, 1) < 0.1))) {\n        var p = Math.round(x);\n        var absP = Math.abs(p);\n        var exponentFormat = ax.exponentformat;\n        if(exponentFormat === 'power' || (isSIFormat(exponentFormat) && beyondSI(p))) {\n            if(p === 0) out.text = 1;\n            else if(p === 1) out.text = '10';\n            else out.text = '10<sup>' + (p > 1 ? '' : MINUS_SIGN) + absP + '</sup>';\n\n            out.fontSize *= 1.25;\n        } else if((exponentFormat === 'e' || exponentFormat === 'E') && absP > 2) {\n            out.text = '1' + exponentFormat + (p > 0 ? '+' : MINUS_SIGN) + absP;\n        } else {\n            out.text = numFormat(Math.pow(10, x), ax, '', 'fakehover');\n            if(dtick === 'D1' && ax._id.charAt(0) === 'y') {\n                out.dy -= out.fontSize / 6;\n            }\n        }\n    } else if(dtChar0 === 'D') {\n        out.text = String(Math.round(Math.pow(10, Lib.mod(x, 1))));\n        out.fontSize *= 0.75;\n    } else throw 'unrecognized dtick ' + String(dtick);\n\n    // if 9's are printed on log scale, move the 10's away a bit\n    if(ax.dtick === 'D1') {\n        var firstChar = String(out.text).charAt(0);\n        if(firstChar === '0' || firstChar === '1') {\n            if(ax._id.charAt(0) === 'y') {\n                out.dx -= out.fontSize / 4;\n            } else {\n                out.dy += out.fontSize / 2;\n                out.dx += (ax.range[1] > ax.range[0] ? 1 : -1) *\n                    out.fontSize * (x < 0 ? 0.5 : 0.25);\n            }\n        }\n    }\n}\n\nfunction formatCategory(ax, out) {\n    var tt = ax._categories[Math.round(out.x)];\n    if(tt === undefined) tt = '';\n    out.text = String(tt);\n}\n\nfunction formatMultiCategory(ax, out, hover) {\n    var v = Math.round(out.x);\n    var cats = ax._categories[v] || [];\n    var tt = cats[1] === undefined ? '' : String(cats[1]);\n    var tt2 = cats[0] === undefined ? '' : String(cats[0]);\n\n    if(hover) {\n        // TODO is this what we want?\n        out.text = tt2 + ' - ' + tt;\n    } else {\n        // setup for secondary labels\n        out.text = tt;\n        out.text2 = tt2;\n    }\n}\n\nfunction formatLinear(ax, out, hover, extraPrecision, hideexp) {\n    if(hideexp === 'never') {\n        // If this is a hover label, then we must *never* hide the exponent\n        // for the sake of display, which could give the wrong value by\n        // potentially many orders of magnitude. If hideexp was 'never', then\n        // it's now succeeded by preventing the other condition from automating\n        // this choice. Thus we can unset it so that the axis formatting takes\n        // precedence.\n        hideexp = '';\n    } else if(ax.showexponent === 'all' && Math.abs(out.x / ax.dtick) < 1e-6) {\n        // don't add an exponent to zero if we're showing all exponents\n        // so the only reason you'd show an exponent on zero is if it's the\n        // ONLY tick to get an exponent (first or last)\n        hideexp = 'hide';\n    }\n    out.text = numFormat(out.x, ax, hideexp, extraPrecision);\n}\n\nfunction formatAngle(ax, out, hover, extraPrecision, hideexp) {\n    if(ax.thetaunit === 'radians' && !hover) {\n        var num = out.x / 180;\n\n        if(num === 0) {\n            out.text = '0';\n        } else {\n            var frac = num2frac(num);\n\n            if(frac[1] >= 100) {\n                out.text = numFormat(Lib.deg2rad(out.x), ax, hideexp, extraPrecision);\n            } else {\n                var isNeg = out.x < 0;\n\n                if(frac[1] === 1) {\n                    if(frac[0] === 1) out.text = 'π';\n                    else out.text = frac[0] + 'π';\n                } else {\n                    out.text = [\n                        '<sup>', frac[0], '</sup>',\n                        '⁄',\n                        '<sub>', frac[1], '</sub>',\n                        'π'\n                    ].join('');\n                }\n\n                if(isNeg) out.text = MINUS_SIGN + out.text;\n            }\n        }\n    } else {\n        out.text = numFormat(out.x, ax, hideexp, extraPrecision);\n    }\n}\n\n// inspired by\n// https://github.com/yisibl/num2fraction/blob/master/index.js\nfunction num2frac(num) {\n    function almostEq(a, b) {\n        return Math.abs(a - b) <= 1e-6;\n    }\n\n    function findGCD(a, b) {\n        return almostEq(b, 0) ? a : findGCD(b, a % b);\n    }\n\n    function findPrecision(n) {\n        var e = 1;\n        while(!almostEq(Math.round(n * e) / e, n)) {\n            e *= 10;\n        }\n        return e;\n    }\n\n    var precision = findPrecision(num);\n    var number = num * precision;\n    var gcd = Math.abs(findGCD(number, precision));\n\n    return [\n        // numerator\n        Math.round(number / gcd),\n        // denominator\n        Math.round(precision / gcd)\n    ];\n}\n\n// format a number (tick value) according to the axis settings\n// new, more reliable procedure than d3.round or similar:\n// add half the rounding increment, then stringify and truncate\n// also automatically switch to sci. notation\nvar SIPREFIXES = ['f', 'p', 'n', 'μ', 'm', '', 'k', 'M', 'G', 'T'];\n\nfunction isSIFormat(exponentFormat) {\n    return exponentFormat === 'SI' || exponentFormat === 'B';\n}\n\n// are we beyond the range of common SI prefixes?\n// 10^-16 -> 1x10^-16\n// 10^-15 -> 1f\n// ...\n// 10^14 -> 100T\n// 10^15 -> 1x10^15\n// 10^16 -> 1x10^16\nfunction beyondSI(exponent) {\n    return exponent > 14 || exponent < -15;\n}\n\nfunction numFormat(v, ax, fmtoverride, hover) {\n    var isNeg = v < 0;\n    // max number of digits past decimal point to show\n    var tickRound = ax._tickround;\n    var exponentFormat = fmtoverride || ax.exponentformat || 'B';\n    var exponent = ax._tickexponent;\n    var tickformat = axes.getTickFormat(ax);\n    var separatethousands = ax.separatethousands;\n\n    // special case for hover: set exponent just for this value, and\n    // add a couple more digits of precision over tick labels\n    if(hover) {\n        // make a dummy axis obj to get the auto rounding and exponent\n        var ah = {\n            exponentformat: exponentFormat,\n            dtick: ax.showexponent === 'none' ? ax.dtick :\n                (isNumeric(v) ? Math.abs(v) || 1 : 1),\n            // if not showing any exponents, don't change the exponent\n            // from what we calculate\n            range: ax.showexponent === 'none' ? ax.range.map(ax.r2d) : [0, v || 1]\n        };\n        autoTickRound(ah);\n        tickRound = (Number(ah._tickround) || 0) + 4;\n        exponent = ah._tickexponent;\n        if(ax.hoverformat) tickformat = ax.hoverformat;\n    }\n\n    if(tickformat) return ax._numFormat(tickformat)(v).replace(/-/g, MINUS_SIGN);\n\n    // 'epsilon' - rounding increment\n    var e = Math.pow(10, -tickRound) / 2;\n\n    // exponentFormat codes:\n    // 'e' (1.2e+6, default)\n    // 'E' (1.2E+6)\n    // 'SI' (1.2M)\n    // 'B' (same as SI except 10^9=B not G)\n    // 'none' (1200000)\n    // 'power' (1.2x10^6)\n    // 'hide' (1.2, use 3rd argument=='hide' to eg\n    //      only show exponent on last tick)\n    if(exponentFormat === 'none') exponent = 0;\n\n    // take the sign out, put it back manually at the end\n    // - makes cases easier\n    v = Math.abs(v);\n    if(v < e) {\n        // 0 is just 0, but may get exponent if it's the last tick\n        v = '0';\n        isNeg = false;\n    } else {\n        v += e;\n        // take out a common exponent, if any\n        if(exponent) {\n            v *= Math.pow(10, -exponent);\n            tickRound += exponent;\n        }\n        // round the mantissa\n        if(tickRound === 0) v = String(Math.floor(v));\n        else if(tickRound < 0) {\n            v = String(Math.round(v));\n            v = v.substr(0, v.length + tickRound);\n            for(var i = tickRound; i < 0; i++) v += '0';\n        } else {\n            v = String(v);\n            var dp = v.indexOf('.') + 1;\n            if(dp) v = v.substr(0, dp + tickRound).replace(/\\.?0+$/, '');\n        }\n        // insert appropriate decimal point and thousands separator\n        v = Lib.numSeparate(v, ax._separators, separatethousands);\n    }\n\n    // add exponent\n    if(exponent && exponentFormat !== 'hide') {\n        if(isSIFormat(exponentFormat) && beyondSI(exponent)) exponentFormat = 'power';\n\n        var signedExponent;\n        if(exponent < 0) signedExponent = MINUS_SIGN + -exponent;\n        else if(exponentFormat !== 'power') signedExponent = '+' + exponent;\n        else signedExponent = String(exponent);\n\n        if(exponentFormat === 'e' || exponentFormat === 'E') {\n            v += exponentFormat + signedExponent;\n        } else if(exponentFormat === 'power') {\n            v += '×10<sup>' + signedExponent + '</sup>';\n        } else if(exponentFormat === 'B' && exponent === 9) {\n            v += 'B';\n        } else if(isSIFormat(exponentFormat)) {\n            v += SIPREFIXES[exponent / 3 + 5];\n        }\n    }\n\n    // put sign back in and return\n    // replace standard minus character (which is technically a hyphen)\n    // with a true minus sign\n    if(isNeg) return MINUS_SIGN + v;\n    return v;\n}\n\naxes.getTickFormat = function(ax) {\n    var i;\n\n    function convertToMs(dtick) {\n        return typeof dtick !== 'string' ? dtick : Number(dtick.replace('M', '')) * ONEAVGMONTH;\n    }\n\n    function compareLogTicks(left, right) {\n        var priority = ['L', 'D'];\n        if(typeof left === typeof right) {\n            if(typeof left === 'number') {\n                return left - right;\n            } else {\n                var leftPriority = priority.indexOf(left.charAt(0));\n                var rightPriority = priority.indexOf(right.charAt(0));\n                if(leftPriority === rightPriority) {\n                    return Number(left.replace(/(L|D)/g, '')) - Number(right.replace(/(L|D)/g, ''));\n                } else {\n                    return leftPriority - rightPriority;\n                }\n            }\n        } else {\n            return typeof left === 'number' ? 1 : -1;\n        }\n    }\n\n    function isProperStop(dtick, range, convert) {\n        var convertFn = convert || function(x) { return x;};\n        var leftDtick = range[0];\n        var rightDtick = range[1];\n        return ((!leftDtick && typeof leftDtick !== 'number') || convertFn(leftDtick) <= convertFn(dtick)) &&\n               ((!rightDtick && typeof rightDtick !== 'number') || convertFn(rightDtick) >= convertFn(dtick));\n    }\n\n    function isProperLogStop(dtick, range) {\n        var isLeftDtickNull = range[0] === null;\n        var isRightDtickNull = range[1] === null;\n        var isDtickInRangeLeft = compareLogTicks(dtick, range[0]) >= 0;\n        var isDtickInRangeRight = compareLogTicks(dtick, range[1]) <= 0;\n        return (isLeftDtickNull || isDtickInRangeLeft) && (isRightDtickNull || isDtickInRangeRight);\n    }\n\n    var tickstop, stopi;\n    if(ax.tickformatstops && ax.tickformatstops.length > 0) {\n        switch(ax.type) {\n            case 'date':\n            case 'linear': {\n                for(i = 0; i < ax.tickformatstops.length; i++) {\n                    stopi = ax.tickformatstops[i];\n                    if(stopi.enabled && isProperStop(ax.dtick, stopi.dtickrange, convertToMs)) {\n                        tickstop = stopi;\n                        break;\n                    }\n                }\n                break;\n            }\n            case 'log': {\n                for(i = 0; i < ax.tickformatstops.length; i++) {\n                    stopi = ax.tickformatstops[i];\n                    if(stopi.enabled && isProperLogStop(ax.dtick, stopi.dtickrange)) {\n                        tickstop = stopi;\n                        break;\n                    }\n                }\n                break;\n            }\n            default:\n        }\n    }\n    return tickstop ? tickstop.value : ax.tickformat;\n};\n\n// getSubplots - extract all subplot IDs we need\n// as an array of items like 'xy', 'x2y', 'x2y2'...\n// sorted by x (x,x2,x3...) then y\n// optionally restrict to only subplots containing axis object ax\n//\n// NOTE: this is currently only used OUTSIDE plotly.js (toolpanel, webapp)\n// ideally we get rid of it there (or just copy this there) and remove it here\naxes.getSubplots = function(gd, ax) {\n    var subplotObj = gd._fullLayout._subplots;\n    var allSubplots = subplotObj.cartesian.concat(subplotObj.gl2d || []);\n\n    var out = ax ? axes.findSubplotsWithAxis(allSubplots, ax) : allSubplots;\n\n    out.sort(function(a, b) {\n        var aParts = a.substr(1).split('y');\n        var bParts = b.substr(1).split('y');\n\n        if(aParts[0] === bParts[0]) return +aParts[1] - +bParts[1];\n        return +aParts[0] - +bParts[0];\n    });\n\n    return out;\n};\n\n// find all subplots with axis 'ax'\n// NOTE: this is only used in axes.getSubplots (only used outside plotly.js) and\n// gl2d/convert (where it restricts axis subplots to only those with gl2d)\naxes.findSubplotsWithAxis = function(subplots, ax) {\n    var axMatch = new RegExp(\n        (ax._id.charAt(0) === 'x') ? ('^' + ax._id + 'y') : (ax._id + '$')\n    );\n    var subplotsWithAx = [];\n\n    for(var i = 0; i < subplots.length; i++) {\n        var sp = subplots[i];\n        if(axMatch.test(sp)) subplotsWithAx.push(sp);\n    }\n\n    return subplotsWithAx;\n};\n\n// makeClipPaths: prepare clipPaths for all single axes and all possible xy pairings\naxes.makeClipPaths = function(gd) {\n    var fullLayout = gd._fullLayout;\n\n    // for more info: https://github.com/plotly/plotly.js/issues/2595\n    if(fullLayout._hasOnlyLargeSploms) return;\n\n    var fullWidth = {_offset: 0, _length: fullLayout.width, _id: ''};\n    var fullHeight = {_offset: 0, _length: fullLayout.height, _id: ''};\n    var xaList = axes.list(gd, 'x', true);\n    var yaList = axes.list(gd, 'y', true);\n    var clipList = [];\n    var i, j;\n\n    for(i = 0; i < xaList.length; i++) {\n        clipList.push({x: xaList[i], y: fullHeight});\n        for(j = 0; j < yaList.length; j++) {\n            if(i === 0) clipList.push({x: fullWidth, y: yaList[j]});\n            clipList.push({x: xaList[i], y: yaList[j]});\n        }\n    }\n\n    // selectors don't work right with camelCase tags,\n    // have to use class instead\n    // https://groups.google.com/forum/#!topic/d3-js/6EpAzQ2gU9I\n    var axClips = fullLayout._clips.selectAll('.axesclip')\n        .data(clipList, function(d) { return d.x._id + d.y._id; });\n\n    axClips.enter().append('clipPath')\n        .classed('axesclip', true)\n        .attr('id', function(d) { return 'clip' + fullLayout._uid + d.x._id + d.y._id; })\n      .append('rect');\n\n    axClips.exit().remove();\n\n    axClips.each(function(d) {\n        d3.select(this).select('rect').attr({\n            x: d.x._offset || 0,\n            y: d.y._offset || 0,\n            width: d.x._length || 1,\n            height: d.y._length || 1\n        });\n    });\n};\n\n/**\n * Main multi-axis drawing routine!\n *\n * @param {DOM element} gd : graph div\n * @param {string or array of strings} arg : polymorphic argument\n * @param {object} opts:\n * - @param {boolean} skipTitle : optional flag to skip axis title draw/update\n *\n * Signature 1: Axes.draw(gd, 'redraw')\n *   use this to clear and redraw all axes on graph\n *\n * Signature 2: Axes.draw(gd, '')\n *   use this to draw all axes on graph w/o the selectAll().remove()\n *   of the 'redraw' signature\n *\n * Signature 3: Axes.draw(gd, [axId, axId2, ...])\n *   where the items are axis id string,\n *   use this to update multiple axes in one call\n *\n * N.B draw updates:\n * - ax._r (stored range for use by zoom/pan)\n * - ax._rl (stored linearized range for use by zoom/pan)\n */\naxes.draw = function(gd, arg, opts) {\n    var fullLayout = gd._fullLayout;\n\n    if(arg === 'redraw') {\n        fullLayout._paper.selectAll('g.subplot').each(function(d) {\n            var id = d[0];\n            var plotinfo = fullLayout._plots[id];\n            var xa = plotinfo.xaxis;\n            var ya = plotinfo.yaxis;\n\n            plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick').remove();\n            plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick').remove();\n            plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick2').remove();\n            plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick2').remove();\n            plotinfo.xaxislayer.selectAll('.' + xa._id + 'divider').remove();\n            plotinfo.yaxislayer.selectAll('.' + ya._id + 'divider').remove();\n\n            if(plotinfo.gridlayer) plotinfo.gridlayer.selectAll('path').remove();\n            if(plotinfo.zerolinelayer) plotinfo.zerolinelayer.selectAll('path').remove();\n\n            fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();\n            fullLayout._infolayer.select('.g-' + ya._id + 'title').remove();\n        });\n    }\n\n    var axList = (!arg || arg === 'redraw') ? axes.listIds(gd) : arg;\n\n    return Lib.syncOrAsync(axList.map(function(axId) {\n        return function() {\n            if(!axId) return;\n\n            var ax = axes.getFromId(gd, axId);\n            var axDone = axes.drawOne(gd, ax, opts);\n\n            ax._r = ax.range.slice();\n            ax._rl = Lib.simpleMap(ax._r, ax.r2l);\n\n            return axDone;\n        };\n    }));\n};\n\n/**\n * Draw one cartesian axis\n *\n * @param {DOM element} gd\n * @param {object} ax (full) axis object\n * @param {object} opts\n * - @param {boolean} skipTitle (set to true to skip axis title draw call)\n */\naxes.drawOne = function(gd, ax, opts) {\n    opts = opts || {};\n\n    var i, sp, plotinfo;\n\n    ax.setScale();\n\n    var fullLayout = gd._fullLayout;\n    var axId = ax._id;\n    var axLetter = axId.charAt(0);\n    var counterLetter = axes.counterLetter(axId);\n    var mainSubplot = ax._mainSubplot;\n    var mainLinePosition = ax._mainLinePosition;\n    var mainMirrorPosition = ax._mainMirrorPosition;\n    var mainPlotinfo = fullLayout._plots[mainSubplot];\n    var mainAxLayer = mainPlotinfo[axLetter + 'axislayer'];\n    var subplotsWithAx = ax._subplotsWith;\n\n    var vals = ax._vals = axes.calcTicks(ax);\n\n    // Add a couple of axis properties that should cause us to recreate\n    // elements. Used in d3 data function.\n    var axInfo = [ax.mirror, mainLinePosition, mainMirrorPosition].join('_');\n    for(i = 0; i < vals.length; i++) {\n        vals[i].axInfo = axInfo;\n    }\n\n    if(!ax.visible) return;\n\n    // stash selections to avoid DOM queries e.g.\n    // - stash tickLabels selection, so that drawTitle can use it to scoot title\n    ax._selections = {};\n    // stash tick angle (including the computed 'auto' values) per tick-label class\n    ax._tickAngles = {};\n\n    var transFn = axes.makeTransFn(ax);\n    var tickVals;\n    // We remove zero lines, grid lines, and inside ticks if they're within 1px of the end\n    // The key case here is removing zero lines when the axis bound is zero\n    var valsClipped;\n\n    if(ax.tickson === 'boundaries') {\n        var boundaryVals = getBoundaryVals(ax, vals);\n        valsClipped = axes.clipEnds(ax, boundaryVals);\n        tickVals = ax.ticks === 'inside' ? valsClipped : boundaryVals;\n    } else {\n        valsClipped = axes.clipEnds(ax, vals);\n        tickVals = ax.ticks === 'inside' ? valsClipped : vals;\n    }\n\n    var gridVals = ax._gridVals = valsClipped;\n    var dividerVals = getDividerVals(ax, vals);\n\n    if(!fullLayout._hasOnlyLargeSploms) {\n        // keep track of which subplots (by main conteraxis) we've already\n        // drawn grids for, so we don't overdraw overlaying subplots\n        var finishedGrids = {};\n\n        for(i = 0; i < subplotsWithAx.length; i++) {\n            sp = subplotsWithAx[i];\n            plotinfo = fullLayout._plots[sp];\n\n            var counterAxis = plotinfo[counterLetter + 'axis'];\n            var mainCounterID = counterAxis._mainAxis._id;\n            if(finishedGrids[mainCounterID]) continue;\n            finishedGrids[mainCounterID] = 1;\n\n            var gridPath = axLetter === 'x' ?\n                'M0,' + counterAxis._offset + 'v' + counterAxis._length :\n                'M' + counterAxis._offset + ',0h' + counterAxis._length;\n\n            axes.drawGrid(gd, ax, {\n                vals: gridVals,\n                counterAxis: counterAxis,\n                layer: plotinfo.gridlayer.select('.' + axId),\n                path: gridPath,\n                transFn: transFn\n            });\n            axes.drawZeroLine(gd, ax, {\n                counterAxis: counterAxis,\n                layer: plotinfo.zerolinelayer,\n                path: gridPath,\n                transFn: transFn\n            });\n        }\n    }\n\n    var tickSigns = axes.getTickSigns(ax);\n    var tickSubplots = [];\n\n    if(ax.ticks) {\n        var mainTickPath = axes.makeTickPath(ax, mainLinePosition, tickSigns[2]);\n        var mirrorTickPath;\n        var fullTickPath;\n        if(ax._anchorAxis && ax.mirror && ax.mirror !== true) {\n            mirrorTickPath = axes.makeTickPath(ax, mainMirrorPosition, tickSigns[3]);\n            fullTickPath = mainTickPath + mirrorTickPath;\n        } else {\n            mirrorTickPath = '';\n            fullTickPath = mainTickPath;\n        }\n\n        var tickPath;\n        if(ax.showdividers && ax.ticks === 'outside' && ax.tickson === 'boundaries') {\n            var dividerLookup = {};\n            for(i = 0; i < dividerVals.length; i++) {\n                dividerLookup[dividerVals[i].x] = 1;\n            }\n            tickPath = function(d) {\n                return dividerLookup[d.x] ? mirrorTickPath : fullTickPath;\n            };\n        } else {\n            tickPath = fullTickPath;\n        }\n\n        axes.drawTicks(gd, ax, {\n            vals: tickVals,\n            layer: mainAxLayer,\n            path: tickPath,\n            transFn: transFn\n        });\n\n        tickSubplots = Object.keys(ax._linepositions || {});\n    }\n\n    for(i = 0; i < tickSubplots.length; i++) {\n        sp = tickSubplots[i];\n        plotinfo = fullLayout._plots[sp];\n        // [bottom or left, top or right], free and main are handled above\n        var linepositions = ax._linepositions[sp] || [];\n        var spTickPath = axes.makeTickPath(ax, linepositions[0], tickSigns[0]) +\n            axes.makeTickPath(ax, linepositions[1], tickSigns[1]);\n\n        axes.drawTicks(gd, ax, {\n            vals: tickVals,\n            layer: plotinfo[axLetter + 'axislayer'],\n            path: spTickPath,\n            transFn: transFn\n        });\n    }\n\n    var seq = [];\n\n    // tick labels - for now just the main labels.\n    // TODO: mirror labels, esp for subplots\n\n    seq.push(function() {\n        return axes.drawLabels(gd, ax, {\n            vals: vals,\n            layer: mainAxLayer,\n            transFn: transFn,\n            labelFns: axes.makeLabelFns(ax, mainLinePosition)\n        });\n    });\n\n    if(ax.type === 'multicategory') {\n        var labelLength = 0;\n        var pad = {x: 2, y: 10}[axLetter];\n        var sgn = tickSigns[2] * (ax.ticks === 'inside' ? -1 : 1);\n\n        seq.push(function() {\n            labelLength += getLabelLevelSpan(ax, axId + 'tick') + pad;\n            labelLength += ax._tickAngles[axId + 'tick'] ? ax.tickfont.size * LINE_SPACING : 0;\n\n            return axes.drawLabels(gd, ax, {\n                vals: getSecondaryLabelVals(ax, vals),\n                layer: mainAxLayer,\n                cls: axId + 'tick2',\n                repositionOnUpdate: true,\n                secondary: true,\n                transFn: transFn,\n                labelFns: axes.makeLabelFns(ax, mainLinePosition + labelLength * sgn)\n            });\n        });\n\n        seq.push(function() {\n            labelLength += getLabelLevelSpan(ax, axId + 'tick2');\n            ax._labelLength = labelLength;\n\n            return drawDividers(gd, ax, {\n                vals: dividerVals,\n                layer: mainAxLayer,\n                path: axes.makeTickPath(ax, mainLinePosition, sgn, labelLength),\n                transFn: transFn\n            });\n        });\n    }\n\n    function extendRange(range, newRange) {\n        range[0] = Math.min(range[0], newRange[0]);\n        range[1] = Math.max(range[1], newRange[1]);\n    }\n\n    function calcBoundingBox() {\n        if(ax.showticklabels) {\n            var gdBB = gd.getBoundingClientRect();\n            var bBox = mainAxLayer.node().getBoundingClientRect();\n\n            /*\n             * the way we're going to use this, the positioning that matters\n             * is relative to the origin of gd. This is important particularly\n             * if gd is scrollable, and may have been scrolled between the time\n             * we calculate this and the time we use it\n             */\n\n            ax._boundingBox = {\n                width: bBox.width,\n                height: bBox.height,\n                left: bBox.left - gdBB.left,\n                right: bBox.right - gdBB.left,\n                top: bBox.top - gdBB.top,\n                bottom: bBox.bottom - gdBB.top\n            };\n        } else {\n            var gs = fullLayout._size;\n            var pos;\n\n            // set dummy bbox for ticklabel-less axes\n\n            if(axLetter === 'x') {\n                pos = ax.anchor === 'free' ?\n                    gs.t + gs.h * (1 - ax.position) :\n                    gs.t + gs.h * (1 - ax._anchorAxis.domain[{bottom: 0, top: 1}[ax.side]]);\n\n                ax._boundingBox = {\n                    top: pos,\n                    bottom: pos,\n                    left: ax._offset,\n                    right: ax._offset + ax._length,\n                    width: ax._length,\n                    height: 0\n                };\n            } else {\n                pos = ax.anchor === 'free' ?\n                    gs.l + gs.w * ax.position :\n                    gs.l + gs.w * ax._anchorAxis.domain[{left: 0, right: 1}[ax.side]];\n\n                ax._boundingBox = {\n                    left: pos,\n                    right: pos,\n                    bottom: ax._offset + ax._length,\n                    top: ax._offset,\n                    height: ax._length,\n                    width: 0\n                };\n            }\n        }\n\n        /*\n         * for spikelines: what's the full domain of positions in the\n         * opposite direction that are associated with this axis?\n         * This means any axes that we make a subplot with, plus the\n         * position of the axis itself if it's free.\n         */\n        if(subplotsWithAx) {\n            var fullRange = ax._counterSpan = [Infinity, -Infinity];\n\n            for(var i = 0; i < subplotsWithAx.length; i++) {\n                var plotinfo = fullLayout._plots[subplotsWithAx[i]];\n                var counterAxis = plotinfo[(axLetter === 'x') ? 'yaxis' : 'xaxis'];\n\n                extendRange(fullRange, [\n                    counterAxis._offset,\n                    counterAxis._offset + counterAxis._length\n                ]);\n            }\n\n            if(ax.anchor === 'free') {\n                extendRange(fullRange, (axLetter === 'x') ?\n                    [ax._boundingBox.bottom, ax._boundingBox.top] :\n                    [ax._boundingBox.right, ax._boundingBox.left]);\n            }\n        }\n    }\n\n    var hasRangeSlider = Registry.getComponentMethod('rangeslider', 'isVisible')(ax);\n\n    function doAutoMargins() {\n        var s = ax.side.charAt(0);\n        var push;\n        var rangeSliderPush;\n\n        if(hasRangeSlider) {\n            rangeSliderPush = Registry.getComponentMethod('rangeslider', 'autoMarginOpts')(gd, ax);\n        }\n        Plots.autoMargin(gd, rangeSliderAutoMarginID(ax), rangeSliderPush);\n\n        if(ax.automargin && (!hasRangeSlider || s !== 'b')) {\n            push = {x: 0, y: 0, r: 0, l: 0, t: 0, b: 0};\n\n            var bbox = ax._boundingBox;\n            var titleOffset = getTitleOffset(gd, ax);\n            var anchorAxDomainIndex;\n            var offset;\n\n            switch(axLetter + s) {\n                case 'xb':\n                    anchorAxDomainIndex = 0;\n                    offset = bbox.top - titleOffset;\n                    push[s] = bbox.height;\n                    break;\n                case 'xt':\n                    anchorAxDomainIndex = 1;\n                    offset = titleOffset - bbox.bottom;\n                    push[s] = bbox.height;\n                    break;\n                case 'yl':\n                    anchorAxDomainIndex = 0;\n                    offset = titleOffset - bbox.right;\n                    push[s] = bbox.width;\n                    break;\n                case 'yr':\n                    anchorAxDomainIndex = 1;\n                    offset = bbox.left - titleOffset;\n                    push[s] = bbox.width;\n                    break;\n            }\n\n            push[counterLetter] = ax.anchor === 'free' ?\n                ax.position :\n                ax._anchorAxis.domain[anchorAxDomainIndex];\n\n            if(push[s] > 0) {\n                push[s] += offset;\n            }\n\n            if(ax.title.text !== fullLayout._dfltTitle[axLetter]) {\n                push[s] += ax.title.font.size;\n            }\n\n            if(axLetter === 'x' && bbox.width > 0) {\n                var rExtra = bbox.right - (ax._offset + ax._length);\n                if(rExtra > 0) {\n                    push.x = 1;\n                    push.r = rExtra;\n                }\n                var lExtra = ax._offset - bbox.left;\n                if(lExtra > 0) {\n                    push.x = 0;\n                    push.l = lExtra;\n                }\n            } else if(axLetter === 'y' && bbox.height > 0) {\n                var bExtra = bbox.bottom - (ax._offset + ax._length);\n                if(bExtra > 0) {\n                    push.y = 0;\n                    push.b = bExtra;\n                }\n                var tExtra = ax._offset - bbox.top;\n                if(tExtra > 0) {\n                    push.y = 1;\n                    push.t = tExtra;\n                }\n            }\n        }\n\n        Plots.autoMargin(gd, axAutoMarginID(ax), push);\n    }\n\n    seq.push(calcBoundingBox, doAutoMargins);\n\n    if(!opts.skipTitle &&\n        !(hasRangeSlider && ax._boundingBox && ax.side === 'bottom')\n    ) {\n        seq.push(function() { return drawTitle(gd, ax); });\n    }\n\n    return Lib.syncOrAsync(seq);\n};\n\nfunction getBoundaryVals(ax, vals) {\n    var out = [];\n    var i;\n\n    // boundaryVals are never used for labels;\n    // no need to worry about the other tickTextObj keys\n    var _push = function(d, bndIndex) {\n        var xb = d.xbnd[bndIndex];\n        if(xb !== null) {\n            out.push(Lib.extendFlat({}, d, {x: xb}));\n        }\n    };\n\n    if(vals.length) {\n        for(i = 0; i < vals.length; i++) {\n            _push(vals[i], 0);\n        }\n        _push(vals[i - 1], 1);\n    }\n\n    return out;\n}\n\nfunction getSecondaryLabelVals(ax, vals) {\n    var out = [];\n    var lookup = {};\n\n    for(var i = 0; i < vals.length; i++) {\n        var d = vals[i];\n        if(lookup[d.text2]) {\n            lookup[d.text2].push(d.x);\n        } else {\n            lookup[d.text2] = [d.x];\n        }\n    }\n\n    for(var k in lookup) {\n        out.push(tickTextObj(ax, Lib.interp(lookup[k], 0.5), k));\n    }\n\n    return out;\n}\n\nfunction getDividerVals(ax, vals) {\n    var out = [];\n    var i, current;\n\n    // never used for labels;\n    // no need to worry about the other tickTextObj keys\n    var _push = function(d, bndIndex) {\n        var xb = d.xbnd[bndIndex];\n        if(xb !== null) {\n            out.push(Lib.extendFlat({}, d, {x: xb}));\n        }\n    };\n\n    if(ax.showdividers && vals.length) {\n        for(i = 0; i < vals.length; i++) {\n            var d = vals[i];\n            if(d.text2 !== current) {\n                _push(d, 0);\n            }\n            current = d.text2;\n        }\n        _push(vals[i - 1], 1);\n    }\n\n    return out;\n}\n\nfunction getLabelLevelSpan(ax, cls) {\n    var axLetter = ax._id.charAt(0);\n    var angle = ax._tickAngles[cls] || 0;\n    var rad = Lib.deg2rad(angle);\n    var sinA = Math.sin(rad);\n    var cosA = Math.cos(rad);\n    var maxX = 0;\n    var maxY = 0;\n\n    // N.B. Drawing.bBox does not take into account rotate transforms\n\n    ax._selections[cls].each(function() {\n        var thisLabel = selectTickLabel(this);\n        var bb = Drawing.bBox(thisLabel.node());\n        var w = bb.width;\n        var h = bb.height;\n        maxX = Math.max(maxX, cosA * w, sinA * h);\n        maxY = Math.max(maxY, sinA * w, cosA * h);\n    });\n\n    return {x: maxY, y: maxX}[axLetter];\n}\n\n/**\n * Which direction do the 'ax.side' values, and free ticks go?\n *\n * @param {object} ax (full) axis object\n *  - {string} _id (starting with 'x' or 'y')\n *  - {string} side\n *  - {string} ticks\n * @return {array} all entries are either -1 or 1\n *  - [0]: sign for top/right ticks (i.e. negative SVG direction)\n *  - [1]: sign for bottom/left ticks (i.e. positive SVG direction)\n *  - [2]: sign for ticks corresponding to 'ax.side'\n *  - [3]: sign for ticks mirroring 'ax.side'\n */\naxes.getTickSigns = function(ax) {\n    var axLetter = ax._id.charAt(0);\n    var sideOpposite = {x: 'top', y: 'right'}[axLetter];\n    var main = ax.side === sideOpposite ? 1 : -1;\n    var out = [-1, 1, main, -main];\n    // then we flip if outside XOR y axis\n    if((ax.ticks !== 'inside') === (axLetter === 'x')) {\n        out = out.map(function(v) { return -v; });\n    }\n    return out;\n};\n\n/**\n * Make axis translate transform function\n *\n * @param {object} ax (full) axis object\n *  - {string} _id\n *  - {number} _offset\n *  - {fn} l2p\n * @return {fn} function of calcTicks items\n */\naxes.makeTransFn = function(ax) {\n    var axLetter = ax._id.charAt(0);\n    var offset = ax._offset;\n    return axLetter === 'x' ?\n        function(d) { return 'translate(' + (offset + ax.l2p(d.x)) + ',0)'; } :\n        function(d) { return 'translate(0,' + (offset + ax.l2p(d.x)) + ')'; };\n};\n\n/**\n * Make axis tick path string\n *\n * @param {object} ax (full) axis object\n *  - {string} _id\n *  - {number} ticklen\n *  - {number} linewidth\n * @param {number} shift along direction of ticklen\n * @param {1 or -1} sng tick sign\n * @param {number (optional)} len tick length\n * @return {string}\n */\naxes.makeTickPath = function(ax, shift, sgn, len) {\n    len = len !== undefined ? len : ax.ticklen;\n\n    var axLetter = ax._id.charAt(0);\n    var pad = (ax.linewidth || 1) / 2;\n\n    return axLetter === 'x' ?\n        'M0,' + (shift + pad * sgn) + 'v' + (len * sgn) :\n        'M' + (shift + pad * sgn) + ',0h' + (len * sgn);\n};\n\n/**\n * Make axis tick label x, y and anchor functions\n *\n * @param {object} ax (full) axis object\n *  - {string} _id\n *  - {string} ticks\n *  - {number} ticklen\n *  - {string} side\n *  - {number} linewidth\n *  - {number} tickfont.size\n *  - {boolean} showline\n * @param {number} shift\n * @param {number} angle [in degrees] ...\n * @return {object}\n *  - {fn} xFn\n *  - {fn} yFn\n *  - {fn} anchorFn\n *  - {fn} heightFn\n *  - {number} labelStandoff (gap parallel to ticks)\n *  - {number} labelShift (gap perpendicular to ticks)\n */\naxes.makeLabelFns = function(ax, shift, angle) {\n    var axLetter = ax._id.charAt(0);\n    var ticksOnOutsideLabels = ax.tickson !== 'boundaries' && ax.ticks === 'outside';\n\n    var labelStandoff = 0;\n    var labelShift = 0;\n\n    if(ticksOnOutsideLabels) {\n        labelStandoff += ax.ticklen;\n    }\n    if(angle && ax.ticks === 'outside') {\n        var rad = Lib.deg2rad(angle);\n        labelStandoff = ax.ticklen * Math.cos(rad) + 1;\n        labelShift = ax.ticklen * Math.sin(rad);\n    }\n    if(ax.showticklabels && (ticksOnOutsideLabels || ax.showline)) {\n        labelStandoff += 0.2 * ax.tickfont.size;\n    }\n    labelStandoff += (ax.linewidth || 1) / 2;\n\n    var out = {\n        labelStandoff: labelStandoff,\n        labelShift: labelShift\n    };\n\n    var x0, y0, ff, flipIt;\n\n    if(axLetter === 'x') {\n        flipIt = ax.side === 'bottom' ? 1 : -1;\n        x0 = labelShift * flipIt;\n        y0 = shift + labelStandoff * flipIt;\n        ff = ax.side === 'bottom' ? 1 : -0.2;\n\n        out.xFn = function(d) { return d.dx + x0; };\n        out.yFn = function(d) { return d.dy + y0 + d.fontSize * ff; };\n        out.anchorFn = function(d, a) {\n            if(!isNumeric(a) || a === 0 || a === 180) {\n                return 'middle';\n            }\n            return (a * flipIt < 0) ? 'end' : 'start';\n        };\n        out.heightFn = function(d, a, h) {\n            return (a < -60 || a > 60) ? -0.5 * h :\n                ax.side === 'top' ? -h :\n                0;\n        };\n    } else if(axLetter === 'y') {\n        flipIt = ax.side === 'right' ? 1 : -1;\n        x0 = labelStandoff;\n        y0 = -labelShift * flipIt;\n        ff = Math.abs(ax.tickangle) === 90 ? 0.5 : 0;\n\n        out.xFn = function(d) { return d.dx + shift + (x0 + d.fontSize * ff) * flipIt; };\n        out.yFn = function(d) { return d.dy + y0 + d.fontSize * MID_SHIFT; };\n        out.anchorFn = function(d, a) {\n            if(isNumeric(a) && Math.abs(a) === 90) {\n                return 'middle';\n            }\n            return ax.side === 'right' ? 'start' : 'end';\n        };\n        out.heightFn = function(d, a, h) {\n            a *= ax.side === 'left' ? 1 : -1;\n            return a < -30 ? -h :\n                a < 30 ? -0.5 * h :\n                0;\n        };\n    }\n\n    return out;\n};\n\nfunction tickDataFn(d) {\n    return [d.text, d.x, d.axInfo, d.font, d.fontSize, d.fontColor].join('_');\n}\n\n/**\n * Draw axis ticks\n *\n * @param {DOM element} gd\n * @param {object} ax (full) axis object\n *  - {string} _id\n *  - {string} ticks\n *  - {number} linewidth\n *  - {string} tickcolor\n * @param {object} opts\n * - {array of object} vals (calcTicks output-like)\n * - {d3 selection} layer\n * - {string or fn} path\n * - {fn} transFn\n * - {boolean} crisp (set to false to unset crisp-edge SVG rendering)\n */\naxes.drawTicks = function(gd, ax, opts) {\n    opts = opts || {};\n\n    var cls = ax._id + 'tick';\n\n    var ticks = opts.layer.selectAll('path.' + cls)\n        .data(ax.ticks ? opts.vals : [], tickDataFn);\n\n    ticks.exit().remove();\n\n    ticks.enter().append('path')\n        .classed(cls, 1)\n        .classed('ticks', 1)\n        .classed('crisp', opts.crisp !== false)\n        .call(Color.stroke, ax.tickcolor)\n        .style('stroke-width', Drawing.crispRound(gd, ax.tickwidth, 1) + 'px')\n        .attr('d', opts.path);\n\n    ticks.attr('transform', opts.transFn);\n};\n\n/**\n * Draw axis grid\n *\n * @param {DOM element} gd\n * @param {object} ax (full) axis object\n *  - {string} _id\n *  - {boolean} showgrid\n *  - {string} gridcolor\n *  - {string} gridwidth\n *  - {boolean} zeroline\n *  - {string} type\n *  - {string} dtick\n * @param {object} opts\n * - {array of object} vals (calcTicks output-like)\n * - {d3 selection} layer\n * - {object} counterAxis (full axis object corresponding to counter axis)\n *     optional - only required if this axis supports zero lines\n * - {string or fn} path\n * - {fn} transFn\n * - {boolean} crisp (set to false to unset crisp-edge SVG rendering)\n */\naxes.drawGrid = function(gd, ax, opts) {\n    opts = opts || {};\n\n    var cls = ax._id + 'grid';\n    var vals = opts.vals;\n    var counterAx = opts.counterAxis;\n    if(ax.showgrid === false) {\n        vals = [];\n    } else if(counterAx && axes.shouldShowZeroLine(gd, ax, counterAx)) {\n        var isArrayMode = ax.tickmode === 'array';\n        for(var i = 0; i < vals.length; i++) {\n            var xi = vals[i].x;\n            if(isArrayMode ? !xi : (Math.abs(xi) < ax.dtick / 100)) {\n                vals = vals.slice(0, i).concat(vals.slice(i + 1));\n                // In array mode you can in principle have multiple\n                // ticks at 0, so test them all. Otherwise once we found\n                // one we can stop.\n                if(isArrayMode) i--;\n                else break;\n            }\n        }\n    }\n\n    var grid = opts.layer.selectAll('path.' + cls)\n        .data(vals, tickDataFn);\n\n    grid.exit().remove();\n\n    grid.enter().append('path')\n        .classed(cls, 1)\n        .classed('crisp', opts.crisp !== false);\n\n    ax._gw = Drawing.crispRound(gd, ax.gridwidth, 1);\n\n    grid.attr('transform', opts.transFn)\n        .attr('d', opts.path)\n        .call(Color.stroke, ax.gridcolor || '#ddd')\n        .style('stroke-width', ax._gw + 'px');\n\n    if(typeof opts.path === 'function') grid.attr('d', opts.path);\n};\n\n/**\n * Draw axis zero-line\n *\n * @param {DOM element} gd\n * @param {object} ax (full) axis object\n *  - {string} _id\n *  - {boolean} zeroline\n *  - {number} zerolinewidth\n *  - {string} zerolinecolor\n *  - {number (optional)} _gridWidthCrispRound\n * @param {object} opts\n * - {d3 selection} layer\n * - {object} counterAxis (full axis object corresponding to counter axis)\n * - {string or fn} path\n * - {fn} transFn\n * - {boolean} crisp (set to false to unset crisp-edge SVG rendering)\n */\naxes.drawZeroLine = function(gd, ax, opts) {\n    opts = opts || opts;\n\n    var cls = ax._id + 'zl';\n    var show = axes.shouldShowZeroLine(gd, ax, opts.counterAxis);\n\n    var zl = opts.layer.selectAll('path.' + cls)\n        .data(show ? [{x: 0, id: ax._id}] : []);\n\n    zl.exit().remove();\n\n    zl.enter().append('path')\n        .classed(cls, 1)\n        .classed('zl', 1)\n        .classed('crisp', opts.crisp !== false)\n        .each(function() {\n            // use the fact that only one element can enter to trigger a sort.\n            // If several zerolines enter at the same time we will sort once per,\n            // but generally this should be a minimal overhead.\n            opts.layer.selectAll('path').sort(function(da, db) {\n                return axisIds.idSort(da.id, db.id);\n            });\n        });\n\n    zl.attr('transform', opts.transFn)\n        .attr('d', opts.path)\n        .call(Color.stroke, ax.zerolinecolor || Color.defaultLine)\n        .style('stroke-width', Drawing.crispRound(gd, ax.zerolinewidth, ax._gw || 1) + 'px');\n};\n\n/**\n * Draw axis tick labels\n *\n * @param {DOM element} gd\n * @param {object} ax (full) axis object\n *  - {string} _id\n *  - {boolean} showticklabels\n *  - {number} tickangle\n *  - {object (optional)} _selections\n *  - {object} (optional)} _tickAngles\n * @param {object} opts\n * - {array of object} vals (calcTicks output-like)\n * - {d3 selection} layer\n * - {string (optional)} cls (node className)\n * - {boolean} repositionOnUpdate (set to true to reposition update selection)\n * - {boolean} secondary\n * - {fn} transFn\n * - {object} labelFns\n *  + {fn} xFn\n *  + {fn} yFn\n *  + {fn} anchorFn\n *  + {fn} heightFn\n */\naxes.drawLabels = function(gd, ax, opts) {\n    opts = opts || {};\n\n    var axId = ax._id;\n    var axLetter = axId.charAt(0);\n    var cls = opts.cls || axId + 'tick';\n    var vals = opts.vals;\n    var labelFns = opts.labelFns;\n    var tickAngle = opts.secondary ? 0 : ax.tickangle;\n    var lastAngle = (ax._tickAngles || {})[cls];\n\n    var tickLabels = opts.layer.selectAll('g.' + cls)\n        .data(ax.showticklabels ? vals : [], tickDataFn);\n\n    var labelsReady = [];\n\n    tickLabels.enter().append('g')\n        .classed(cls, 1)\n        .append('text')\n            // only so tex has predictable alignment that we can\n            // alter later\n            .attr('text-anchor', 'middle')\n            .each(function(d) {\n                var thisLabel = d3.select(this);\n                var newPromise = gd._promises.length;\n\n                thisLabel\n                    .call(svgTextUtils.positionText, labelFns.xFn(d), labelFns.yFn(d))\n                    .call(Drawing.font, d.font, d.fontSize, d.fontColor)\n                    .text(d.text)\n                    .call(svgTextUtils.convertToTspans, gd);\n\n                if(gd._promises[newPromise]) {\n                    // if we have an async label, we'll deal with that\n                    // all here so take it out of gd._promises and\n                    // instead position the label and promise this in\n                    // labelsReady\n                    labelsReady.push(gd._promises.pop().then(function() {\n                        positionLabels(thisLabel, tickAngle);\n                    }));\n                } else {\n                    // sync label: just position it now.\n                    positionLabels(thisLabel, tickAngle);\n                }\n            });\n\n    tickLabels.exit().remove();\n\n    if(opts.repositionOnUpdate) {\n        tickLabels.each(function(d) {\n            d3.select(this).select('text')\n                .call(svgTextUtils.positionText, labelFns.xFn(d), labelFns.yFn(d));\n        });\n    }\n\n    function positionLabels(s, angle) {\n        s.each(function(d) {\n            var thisLabel = d3.select(this);\n            var mathjaxGroup = thisLabel.select('.text-math-group');\n            var anchor = labelFns.anchorFn(d, angle);\n\n            var transform = opts.transFn.call(thisLabel.node(), d) +\n                ((isNumeric(angle) && +angle !== 0) ?\n                (' rotate(' + angle + ',' + labelFns.xFn(d) + ',' +\n                    (labelFns.yFn(d) - d.fontSize / 2) + ')') :\n                '');\n\n            // how much to shift a multi-line label to center it vertically.\n            var nLines = svgTextUtils.lineCount(thisLabel);\n            var lineHeight = LINE_SPACING * d.fontSize;\n            var anchorHeight = labelFns.heightFn(d, isNumeric(angle) ? +angle : 0, (nLines - 1) * lineHeight);\n\n            if(anchorHeight) {\n                transform += ' translate(0, ' + anchorHeight + ')';\n            }\n\n            if(mathjaxGroup.empty()) {\n                thisLabel.select('text').attr({\n                    transform: transform,\n                    'text-anchor': anchor\n                });\n            } else {\n                var mjWidth = Drawing.bBox(mathjaxGroup.node()).width;\n                var mjShift = mjWidth * {end: -0.5, start: 0.5}[anchor];\n                mathjaxGroup.attr('transform', transform + (mjShift ? 'translate(' + mjShift + ',0)' : ''));\n            }\n        });\n    }\n\n    // make sure all labels are correctly positioned at their base angle\n    // the positionLabels call above is only for newly drawn labels.\n    // do this without waiting, using the last calculated angle to\n    // minimize flicker, then do it again when we know all labels are\n    // there, putting back the prescribed angle to check for overlaps.\n    positionLabels(tickLabels, lastAngle || tickAngle);\n\n    function allLabelsReady() {\n        return labelsReady.length && Promise.all(labelsReady);\n    }\n\n    function fixLabelOverlaps() {\n        positionLabels(tickLabels, tickAngle);\n\n        var autoangle = null;\n\n        // check for auto-angling if x labels overlap\n        // don't auto-angle at all for log axes with\n        // base and digit format\n        if(vals.length && axLetter === 'x' && !isNumeric(tickAngle) &&\n            (ax.type !== 'log' || String(ax.dtick).charAt(0) !== 'D')\n        ) {\n            autoangle = 0;\n\n            var maxFontSize = 0;\n            var lbbArray = [];\n            var i;\n\n            tickLabels.each(function(d) {\n                maxFontSize = Math.max(maxFontSize, d.fontSize);\n\n                var x = ax.l2p(d.x);\n                var thisLabel = selectTickLabel(this);\n                var bb = Drawing.bBox(thisLabel.node());\n\n                lbbArray.push({\n                    // ignore about y, just deal with x overlaps\n                    top: 0,\n                    bottom: 10,\n                    height: 10,\n                    left: x - bb.width / 2,\n                    // impose a 2px gap\n                    right: x + bb.width / 2 + 2,\n                    width: bb.width + 2\n                });\n            });\n\n            if((ax.tickson === 'boundaries' || ax.showdividers) && !opts.secondary) {\n                var gap = 2;\n                if(ax.ticks) gap += ax.tickwidth / 2;\n\n                // TODO should secondary labels also fall into this fix-overlap regime?\n\n                for(i = 0; i < lbbArray.length; i++) {\n                    var xbnd = vals[i].xbnd;\n                    var lbb = lbbArray[i];\n                    if(\n                        (xbnd[0] !== null && (lbb.left - ax.l2p(xbnd[0])) < gap) ||\n                        (xbnd[1] !== null && (ax.l2p(xbnd[1]) - lbb.right) < gap)\n                    ) {\n                        autoangle = 90;\n                        break;\n                    }\n                }\n            } else {\n                var vLen = vals.length;\n                var tickSpacing = Math.abs((vals[vLen - 1].x - vals[0].x) * ax._m) / (vLen - 1);\n                var rotate90 = (tickSpacing < maxFontSize * 2.5) || ax.type === 'multicategory';\n\n                // any overlap at all - set 30 degrees or 90 degrees\n                for(i = 0; i < lbbArray.length - 1; i++) {\n                    if(Lib.bBoxIntersect(lbbArray[i], lbbArray[i + 1])) {\n                        autoangle = rotate90 ? 90 : 30;\n                        break;\n                    }\n                }\n            }\n\n            if(autoangle) {\n                positionLabels(tickLabels, autoangle);\n            }\n        }\n\n        if(ax._tickAngles) {\n            ax._tickAngles[cls] = autoangle === null ?\n                (isNumeric(tickAngle) ? tickAngle : 0) :\n                autoangle;\n        }\n    }\n\n    if(ax._selections) {\n        ax._selections[cls] = tickLabels;\n    }\n\n    var done = Lib.syncOrAsync([allLabelsReady, fixLabelOverlaps]);\n    if(done && done.then) gd._promises.push(done);\n    return done;\n};\n\n/**\n * Draw axis dividers\n *\n * @param {DOM element} gd\n * @param {object} ax (full) axis object\n *  - {string} _id\n *  - {string} showdividers\n *  - {number} dividerwidth\n *  - {string} dividercolor\n * @param {object} opts\n * - {array of object} vals (calcTicks output-like)\n * - {d3 selection} layer\n * - {fn} path\n * - {fn} transFn\n */\nfunction drawDividers(gd, ax, opts) {\n    var cls = ax._id + 'divider';\n    var vals = opts.vals;\n\n    var dividers = opts.layer.selectAll('path.' + cls)\n        .data(vals, tickDataFn);\n\n    dividers.exit().remove();\n\n    dividers.enter().insert('path', ':first-child')\n        .classed(cls, 1)\n        .classed('crisp', 1)\n        .call(Color.stroke, ax.dividercolor)\n        .style('stroke-width', Drawing.crispRound(gd, ax.dividerwidth, 1) + 'px');\n\n    dividers\n        .attr('transform', opts.transFn)\n        .attr('d', opts.path);\n}\n\nfunction getTitleOffset(gd, ax) {\n    var gs = gd._fullLayout._size;\n    var axLetter = ax._id.charAt(0);\n    var side = ax.side;\n    var anchorAxis;\n\n    if(ax.anchor !== 'free') {\n        anchorAxis = axisIds.getFromId(gd, ax.anchor);\n    } else if(axLetter === 'x') {\n        anchorAxis = {\n            _offset: gs.t + (1 - (ax.position || 0)) * gs.h,\n            _length: 0\n        };\n    } else if(axLetter === 'y') {\n        anchorAxis = {\n            _offset: gs.l + (ax.position || 0) * gs.w,\n            _length: 0\n        };\n    }\n\n    if(side === 'top' || side === 'left') {\n        return anchorAxis._offset;\n    } else if(side === 'bottom' || side === 'right') {\n        return anchorAxis._offset + anchorAxis._length;\n    }\n}\n\nfunction drawTitle(gd, ax) {\n    var fullLayout = gd._fullLayout;\n    var axId = ax._id;\n    var axLetter = axId.charAt(0);\n    var fontSize = ax.title.font.size;\n\n    var titleStandoff;\n    if(ax.type === 'multicategory') {\n        titleStandoff = ax._labelLength;\n    } else {\n        var offsetBase = 1.5;\n        titleStandoff = 10 + fontSize * offsetBase + (ax.linewidth ? ax.linewidth - 1 : 0);\n    }\n\n    var titleOffset = getTitleOffset(gd, ax);\n\n    var transform, x, y;\n\n    if(axLetter === 'x') {\n        x = ax._offset + ax._length / 2;\n\n        if(ax.side === 'top') {\n            y = -titleStandoff - fontSize * (ax.showticklabels ? 1 : 0);\n        } else {\n            y = titleStandoff + fontSize * (ax.showticklabels ? 1.5 : 0.5);\n        }\n        y += titleOffset;\n    } else {\n        y = ax._offset + ax._length / 2;\n\n        if(ax.side === 'right') {\n            x = titleStandoff + fontSize * (ax.showticklabels ? 1 : 0.5);\n        } else {\n            x = -titleStandoff - fontSize * (ax.showticklabels ? 0.5 : 0);\n        }\n        x += titleOffset;\n\n        transform = {rotate: '-90', offset: 0};\n    }\n\n    var avoid;\n\n    if(ax.type !== 'multicategory') {\n        var tickLabels = ax._selections[ax._id + 'tick'];\n\n        avoid = {\n            selection: tickLabels,\n            side: ax.side\n        };\n\n        if(tickLabels && tickLabels.node() && tickLabels.node().parentNode) {\n            var translation = Drawing.getTranslate(tickLabels.node().parentNode);\n            avoid.offsetLeft = translation.x;\n            avoid.offsetTop = translation.y;\n        }\n    }\n\n    return Titles.draw(gd, axId + 'title', {\n        propContainer: ax,\n        propName: ax._name + '.title.text',\n        placeholder: fullLayout._dfltTitle[axLetter],\n        avoid: avoid,\n        transform: transform,\n        attributes: {x: x, y: y, 'text-anchor': 'middle'}\n    });\n}\n\naxes.shouldShowZeroLine = function(gd, ax, counterAxis) {\n    var rng = Lib.simpleMap(ax.range, ax.r2l);\n    return (\n        (rng[0] * rng[1] <= 0) &&\n        ax.zeroline &&\n        (ax.type === 'linear' || ax.type === '-') &&\n        ax._gridVals.length &&\n        (\n            clipEnds(ax, 0) ||\n            !anyCounterAxLineAtZero(gd, ax, counterAxis, rng) ||\n            hasBarsOrFill(gd, ax)\n        )\n    );\n};\n\naxes.clipEnds = function(ax, vals) {\n    return vals.filter(function(d) { return clipEnds(ax, d.x); });\n};\n\nfunction clipEnds(ax, l) {\n    var p = ax.l2p(l);\n    return (p > 1 && p < ax._length - 1);\n}\n\nfunction anyCounterAxLineAtZero(gd, ax, counterAxis, rng) {\n    var mainCounterAxis = counterAxis._mainAxis;\n    if(!mainCounterAxis) return;\n\n    var fullLayout = gd._fullLayout;\n    var axLetter = ax._id.charAt(0);\n    var counterLetter = axes.counterLetter(ax._id);\n\n    var zeroPosition = ax._offset + (\n        ((Math.abs(rng[0]) < Math.abs(rng[1])) === (axLetter === 'x')) ?\n        0 : ax._length\n    );\n\n    function lineNearZero(ax2) {\n        if(!ax2.showline || !ax2.linewidth) return false;\n        var tolerance = Math.max((ax2.linewidth + ax.zerolinewidth) / 2, 1);\n\n        function closeEnough(pos2) {\n            return typeof pos2 === 'number' && Math.abs(pos2 - zeroPosition) < tolerance;\n        }\n\n        if(closeEnough(ax2._mainLinePosition) || closeEnough(ax2._mainMirrorPosition)) {\n            return true;\n        }\n        var linePositions = ax2._linepositions || {};\n        for(var k in linePositions) {\n            if(closeEnough(linePositions[k][0]) || closeEnough(linePositions[k][1])) {\n                return true;\n            }\n        }\n    }\n\n    var plotinfo = fullLayout._plots[counterAxis._mainSubplot];\n    if(!(plotinfo.mainplotinfo || plotinfo).overlays.length) {\n        return lineNearZero(counterAxis, zeroPosition);\n    }\n\n    var counterLetterAxes = axes.list(gd, counterLetter);\n    for(var i = 0; i < counterLetterAxes.length; i++) {\n        var counterAxis2 = counterLetterAxes[i];\n        if(\n            counterAxis2._mainAxis === mainCounterAxis &&\n            lineNearZero(counterAxis2, zeroPosition)\n        ) {\n            return true;\n        }\n    }\n}\n\nfunction hasBarsOrFill(gd, ax) {\n    var fullData = gd._fullData;\n    var subplot = ax._mainSubplot;\n    var axLetter = ax._id.charAt(0);\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n\n        if(trace.visible === true && (trace.xaxis + trace.yaxis) === subplot) {\n            if(\n                Registry.traceIs(trace, 'bar-like') &&\n                trace.orientation === {x: 'h', y: 'v'}[axLetter]\n            ) return true;\n\n            if(\n                trace.fill &&\n                trace.fill.charAt(trace.fill.length - 1) === axLetter\n            ) return true;\n        }\n    }\n    return false;\n}\n\nfunction selectTickLabel(gTick) {\n    var s = d3.select(gTick);\n    var mj = s.select('.text-math-group');\n    return mj.empty() ? s.select('text') : mj;\n}\n\n/**\n * Find all margin pushers for 2D axes and reserve them for later use\n * Both label and rangeslider automargin calculations happen later so\n * we need to explicitly allow their ids in order to not delete them.\n *\n * TODO: can we pull the actual automargin calls forward to avoid this hack?\n * We're probably also doing multiple redraws in this case, would be faster\n * if we can just do the whole calculation ahead of time and draw once.\n */\naxes.allowAutoMargin = function(gd) {\n    var axList = axes.list(gd, '', true);\n    for(var i = 0; i < axList.length; i++) {\n        var ax = axList[i];\n        if(ax.automargin) {\n            Plots.allowAutoMargin(gd, axAutoMarginID(ax));\n        }\n        if(Registry.getComponentMethod('rangeslider', 'isVisible')(ax)) {\n            Plots.allowAutoMargin(gd, rangeSliderAutoMarginID(ax));\n        }\n    }\n};\n\nfunction axAutoMarginID(ax) { return ax._id + '.automargin'; }\nfunction rangeSliderAutoMarginID(ax) { return ax._id + '.rangeslider'; }\n\n// swap all the presentation attributes of the axes showing these traces\naxes.swap = function(gd, traces) {\n    var axGroups = makeAxisGroups(gd, traces);\n\n    for(var i = 0; i < axGroups.length; i++) {\n        swapAxisGroup(gd, axGroups[i].x, axGroups[i].y);\n    }\n};\n\nfunction makeAxisGroups(gd, traces) {\n    var groups = [];\n    var i, j;\n\n    for(i = 0; i < traces.length; i++) {\n        var groupsi = [];\n        var xi = gd._fullData[traces[i]].xaxis;\n        var yi = gd._fullData[traces[i]].yaxis;\n        if(!xi || !yi) continue; // not a 2D cartesian trace?\n\n        for(j = 0; j < groups.length; j++) {\n            if(groups[j].x.indexOf(xi) !== -1 || groups[j].y.indexOf(yi) !== -1) {\n                groupsi.push(j);\n            }\n        }\n\n        if(!groupsi.length) {\n            groups.push({x: [xi], y: [yi]});\n            continue;\n        }\n\n        var group0 = groups[groupsi[0]];\n        var groupj;\n\n        if(groupsi.length > 1) {\n            for(j = 1; j < groupsi.length; j++) {\n                groupj = groups[groupsi[j]];\n                mergeAxisGroups(group0.x, groupj.x);\n                mergeAxisGroups(group0.y, groupj.y);\n            }\n        }\n        mergeAxisGroups(group0.x, [xi]);\n        mergeAxisGroups(group0.y, [yi]);\n    }\n\n    return groups;\n}\n\nfunction mergeAxisGroups(intoSet, fromSet) {\n    for(var i = 0; i < fromSet.length; i++) {\n        if(intoSet.indexOf(fromSet[i]) === -1) intoSet.push(fromSet[i]);\n    }\n}\n\nfunction swapAxisGroup(gd, xIds, yIds) {\n    var xFullAxes = [];\n    var yFullAxes = [];\n    var layout = gd.layout;\n    var i, j;\n\n    for(i = 0; i < xIds.length; i++) xFullAxes.push(axes.getFromId(gd, xIds[i]));\n    for(i = 0; i < yIds.length; i++) yFullAxes.push(axes.getFromId(gd, yIds[i]));\n\n    var allAxKeys = Object.keys(axAttrs);\n\n    var noSwapAttrs = [\n        'anchor', 'domain', 'overlaying', 'position', 'side', 'tickangle', 'editType'\n    ];\n    var numericTypes = ['linear', 'log'];\n\n    for(i = 0; i < allAxKeys.length; i++) {\n        var keyi = allAxKeys[i];\n        var xVal = xFullAxes[0][keyi];\n        var yVal = yFullAxes[0][keyi];\n        var allEqual = true;\n        var coerceLinearX = false;\n        var coerceLinearY = false;\n        if(keyi.charAt(0) === '_' || typeof xVal === 'function' ||\n                noSwapAttrs.indexOf(keyi) !== -1) {\n            continue;\n        }\n        for(j = 1; j < xFullAxes.length && allEqual; j++) {\n            var xVali = xFullAxes[j][keyi];\n            if(keyi === 'type' && numericTypes.indexOf(xVal) !== -1 &&\n                    numericTypes.indexOf(xVali) !== -1 && xVal !== xVali) {\n                // type is special - if we find a mixture of linear and log,\n                // coerce them all to linear on flipping\n                coerceLinearX = true;\n            } else if(xVali !== xVal) allEqual = false;\n        }\n        for(j = 1; j < yFullAxes.length && allEqual; j++) {\n            var yVali = yFullAxes[j][keyi];\n            if(keyi === 'type' && numericTypes.indexOf(yVal) !== -1 &&\n                    numericTypes.indexOf(yVali) !== -1 && yVal !== yVali) {\n                // type is special - if we find a mixture of linear and log,\n                // coerce them all to linear on flipping\n                coerceLinearY = true;\n            } else if(yFullAxes[j][keyi] !== yVal) allEqual = false;\n        }\n        if(allEqual) {\n            if(coerceLinearX) layout[xFullAxes[0]._name].type = 'linear';\n            if(coerceLinearY) layout[yFullAxes[0]._name].type = 'linear';\n            swapAxisAttrs(layout, keyi, xFullAxes, yFullAxes, gd._fullLayout._dfltTitle);\n        }\n    }\n\n    // now swap x&y for any annotations anchored to these x & y\n    for(i = 0; i < gd._fullLayout.annotations.length; i++) {\n        var ann = gd._fullLayout.annotations[i];\n        if(xIds.indexOf(ann.xref) !== -1 &&\n                yIds.indexOf(ann.yref) !== -1) {\n            Lib.swapAttrs(layout.annotations[i], ['?']);\n        }\n    }\n}\n\nfunction swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {\n    // in case the value is the default for either axis,\n    // look at the first axis in each list and see if\n    // this key's value is undefined\n    var np = Lib.nestedProperty;\n    var xVal = np(layout[xFullAxes[0]._name], key).get();\n    var yVal = np(layout[yFullAxes[0]._name], key).get();\n    var i;\n\n    if(key === 'title') {\n        // special handling of placeholder titles\n        if(xVal && xVal.text === dfltTitle.x) {\n            xVal.text = dfltTitle.y;\n        }\n        if(yVal && yVal.text === dfltTitle.y) {\n            yVal.text = dfltTitle.x;\n        }\n    }\n\n    for(i = 0; i < xFullAxes.length; i++) {\n        np(layout, xFullAxes[i]._name + '.' + key).set(yVal);\n    }\n    for(i = 0; i < yFullAxes.length; i++) {\n        np(layout, yFullAxes[i]._name + '.' + key).set(xVal);\n    }\n}\n\nfunction isAngular(ax) {\n    return ax._id === 'angularaxis';\n}\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../components/titles\":681,\"../../constants/alignment\":688,\"../../constants/numerical\":695,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plots/plots\":828,\"../../registry\":847,\"./autorange\":766,\"./axis_autotype\":768,\"./axis_ids\":770,\"./clean_ticks\":772,\"./layout_attributes\":779,\"./set_convert\":785,\"d3\":163,\"fast-isnumeric\":225}],768:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function autoType(array, calendar, opts) {\n    opts = opts || {};\n\n    if(!opts.noMultiCategory && multiCategory(array)) return 'multicategory';\n    if(moreDates(array, calendar)) return 'date';\n    if(category(array)) return 'category';\n    if(linearOK(array)) return 'linear';\n    else return '-';\n};\n\n// is there at least one number in array? If not, we should leave\n// ax.type empty so it can be autoset later\nfunction linearOK(array) {\n    if(!array) return false;\n\n    for(var i = 0; i < array.length; i++) {\n        if(isNumeric(array[i])) return true;\n    }\n\n    return false;\n}\n\n// does the array a have mostly dates rather than numbers?\n// note: some values can be neither (such as blanks, text)\n// 2- or 4-digit integers can be both, so require twice as many\n// dates as non-dates, to exclude cases with mostly 2 & 4 digit\n// numbers and a few dates\n// as with categories, consider DISTINCT values only.\nfunction moreDates(a, calendar) {\n    // test at most 1000 points, evenly spaced\n    var inc = Math.max(1, (a.length - 1) / 1000);\n    var dcnt = 0;\n    var ncnt = 0;\n    var seen = {};\n\n    for(var i = 0; i < a.length; i += inc) {\n        var ai = a[Math.round(i)];\n        var stri = String(ai);\n        if(seen[stri]) continue;\n        seen[stri] = 1;\n\n        if(Lib.isDateTime(ai, calendar)) dcnt += 1;\n        if(isNumeric(ai)) ncnt += 1;\n    }\n\n    return (dcnt > ncnt * 2);\n}\n\n// are the (x,y)-values in gd.data mostly text?\n// require twice as many DISTINCT categories as distinct numbers\nfunction category(a) {\n    // test at most 1000 points\n    var inc = Math.max(1, (a.length - 1) / 1000);\n    var curvenums = 0;\n    var curvecats = 0;\n    var seen = {};\n\n    for(var i = 0; i < a.length; i += inc) {\n        var ai = a[Math.round(i)];\n        var stri = String(ai);\n        if(seen[stri]) continue;\n        seen[stri] = 1;\n\n        if(typeof ai === 'boolean') curvecats++;\n        else if(Lib.cleanNumber(ai) !== BADNUM) curvenums++;\n        else if(typeof ai === 'string') curvecats++;\n    }\n\n    return curvecats > curvenums * 2;\n}\n\n// very-loose requirements for multicategory,\n// trace modules that should never auto-type to multicategory\n// should be declared with 'noMultiCategory'\nfunction multiCategory(a) {\n    return Lib.isArrayOrTypedArray(a[0]) && Lib.isArrayOrTypedArray(a[1]);\n}\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"fast-isnumeric\":225}],769:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\n\nvar layoutAttributes = _dereq_('./layout_attributes');\nvar handleTickValueDefaults = _dereq_('./tick_value_defaults');\nvar handleTickMarkDefaults = _dereq_('./tick_mark_defaults');\nvar handleTickLabelDefaults = _dereq_('./tick_label_defaults');\nvar handleCategoryOrderDefaults = _dereq_('./category_order_defaults');\nvar handleLineGridDefaults = _dereq_('./line_grid_defaults');\nvar setConvert = _dereq_('./set_convert');\n\n/**\n * options: object containing:\n *\n *  letter: 'x' or 'y'\n *  title: name of the axis (ie 'Colorbar') to go in default title\n *  font: the default font to inherit\n *  outerTicks: boolean, should ticks default to outside?\n *  showGrid: boolean, should gridlines be shown by default?\n *  noHover: boolean, this axis doesn't support hover effects?\n *  noTickson: boolean, this axis doesn't support 'tickson'\n *  data: the plot data, used to manage categories\n *  bgColor: the plot background color, to calculate default gridline colors\n *  calendar:\n *  splomStash:\n *  visibleDflt: boolean\n *  reverseDflt: boolean\n *  automargin: boolean\n */\nmodule.exports = function handleAxisDefaults(containerIn, containerOut, coerce, options, layoutOut) {\n    var letter = options.letter;\n    var font = options.font || {};\n    var splomStash = options.splomStash || {};\n\n    var visible = coerce('visible', !options.visibleDflt);\n\n    var axType = containerOut.type;\n\n    if(axType === 'date') {\n        var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');\n        handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);\n    }\n\n    setConvert(containerOut, layoutOut);\n\n    var autorangeDflt = !containerOut.isValidRange(containerIn.range);\n    if(autorangeDflt && options.reverseDflt) autorangeDflt = 'reversed';\n    var autoRange = coerce('autorange', autorangeDflt);\n    if(autoRange && (axType === 'linear' || axType === '-')) coerce('rangemode');\n\n    coerce('range');\n    containerOut.cleanRange();\n\n    handleCategoryOrderDefaults(containerIn, containerOut, coerce, options);\n\n    if(axType !== 'category' && !options.noHover) coerce('hoverformat');\n\n    var dfltColor = coerce('color');\n    // if axis.color was provided, use it for fonts too; otherwise,\n    // inherit from global font color in case that was provided.\n    // Compare to dflt rather than to containerIn, so we can provide color via\n    // template too.\n    var dfltFontColor = (dfltColor !== layoutAttributes.color.dflt) ? dfltColor : font.color;\n    // try to get default title from splom trace, fallback to graph-wide value\n    var dfltTitle = splomStash.label || layoutOut._dfltTitle[letter];\n\n    handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options, {pass: 1});\n    if(!visible) return containerOut;\n\n    coerce('title.text', dfltTitle);\n    Lib.coerceFont(coerce, 'title.font', {\n        family: font.family,\n        size: Math.round(font.size * 1.2),\n        color: dfltFontColor\n    });\n\n    handleTickValueDefaults(containerIn, containerOut, coerce, axType);\n    handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options, {pass: 2});\n    handleTickMarkDefaults(containerIn, containerOut, coerce, options);\n    handleLineGridDefaults(containerIn, containerOut, coerce, {\n        dfltColor: dfltColor,\n        bgColor: options.bgColor,\n        showGrid: options.showGrid,\n        attributes: layoutAttributes\n    });\n\n    if(containerOut.showline || containerOut.ticks) coerce('mirror');\n\n    if(options.automargin) coerce('automargin');\n\n    var isMultiCategory = containerOut.type === 'multicategory';\n\n    if(!options.noTickson &&\n        (containerOut.type === 'category' || isMultiCategory) &&\n        (containerOut.ticks || containerOut.showgrid)\n    ) {\n        var ticksonDflt;\n        if(isMultiCategory) ticksonDflt = 'boundaries';\n        coerce('tickson', ticksonDflt);\n    }\n\n    if(isMultiCategory) {\n        var showDividers = coerce('showdividers');\n        if(showDividers) {\n            coerce('dividercolor');\n            coerce('dividerwidth');\n        }\n    }\n\n    return containerOut;\n};\n\n},{\"../../lib\":719,\"../../registry\":847,\"./category_order_defaults\":771,\"./layout_attributes\":779,\"./line_grid_defaults\":781,\"./set_convert\":785,\"./tick_label_defaults\":786,\"./tick_mark_defaults\":787,\"./tick_value_defaults\":788}],770:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\n\nvar constants = _dereq_('./constants');\n\n\n// convert between axis names (xaxis, xaxis2, etc, elements of gd.layout)\n// and axis id's (x, x2, etc). Would probably have ditched 'xaxis'\n// completely in favor of just 'x' if it weren't ingrained in the API etc.\nexports.id2name = function id2name(id) {\n    if(typeof id !== 'string' || !id.match(constants.AX_ID_PATTERN)) return;\n    var axNum = id.substr(1);\n    if(axNum === '1') axNum = '';\n    return id.charAt(0) + 'axis' + axNum;\n};\n\nexports.name2id = function name2id(name) {\n    if(!name.match(constants.AX_NAME_PATTERN)) return;\n    var axNum = name.substr(5);\n    if(axNum === '1') axNum = '';\n    return name.charAt(0) + axNum;\n};\n\nexports.cleanId = function cleanId(id, axLetter) {\n    if(!id.match(constants.AX_ID_PATTERN)) return;\n    if(axLetter && id.charAt(0) !== axLetter) return;\n\n    var axNum = id.substr(1).replace(/^0+/, '');\n    if(axNum === '1') axNum = '';\n    return id.charAt(0) + axNum;\n};\n\n// get all axis objects, as restricted in listNames\nexports.list = function(gd, axLetter, only2d) {\n    var fullLayout = gd._fullLayout;\n    if(!fullLayout) return [];\n\n    var idList = exports.listIds(gd, axLetter);\n    var out = new Array(idList.length);\n    var i;\n\n    for(i = 0; i < idList.length; i++) {\n        var idi = idList[i];\n        out[i] = fullLayout[idi.charAt(0) + 'axis' + idi.substr(1)];\n    }\n\n    if(!only2d) {\n        var sceneIds3D = fullLayout._subplots.gl3d || [];\n\n        for(i = 0; i < sceneIds3D.length; i++) {\n            var scene = fullLayout[sceneIds3D[i]];\n\n            if(axLetter) out.push(scene[axLetter + 'axis']);\n            else out.push(scene.xaxis, scene.yaxis, scene.zaxis);\n        }\n    }\n\n    return out;\n};\n\n// get all axis ids, optionally restricted by letter\n// this only makes sense for 2d axes\nexports.listIds = function(gd, axLetter) {\n    var fullLayout = gd._fullLayout;\n    if(!fullLayout) return [];\n\n    var subplotLists = fullLayout._subplots;\n    if(axLetter) return subplotLists[axLetter + 'axis'];\n    return subplotLists.xaxis.concat(subplotLists.yaxis);\n};\n\n// get an axis object from its id 'x','x2' etc\n// optionally, id can be a subplot (ie 'x2y3') and type gets x or y from it\nexports.getFromId = function(gd, id, type) {\n    var fullLayout = gd._fullLayout;\n\n    if(type === 'x') id = id.replace(/y[0-9]*/, '');\n    else if(type === 'y') id = id.replace(/x[0-9]*/, '');\n\n    return fullLayout[exports.id2name(id)];\n};\n\n// get an axis object of specified type from the containing trace\nexports.getFromTrace = function(gd, fullTrace, type) {\n    var fullLayout = gd._fullLayout;\n    var ax = null;\n\n    if(Registry.traceIs(fullTrace, 'gl3d')) {\n        var scene = fullTrace.scene;\n        if(scene.substr(0, 5) === 'scene') {\n            ax = fullLayout[scene][type + 'axis'];\n        }\n    } else {\n        ax = exports.getFromId(gd, fullTrace[type + 'axis'] || type);\n    }\n\n    return ax;\n};\n\n// sort x, x2, x10, y, y2, y10...\nexports.idSort = function(id1, id2) {\n    var letter1 = id1.charAt(0);\n    var letter2 = id2.charAt(0);\n    if(letter1 !== letter2) return letter1 > letter2 ? 1 : -1;\n    return +(id1.substr(1) || 1) - +(id2.substr(1) || 1);\n};\n\nexports.getAxisGroup = function getAxisGroup(fullLayout, axId) {\n    var matchGroups = fullLayout._axisMatchGroups;\n\n    for(var i = 0; i < matchGroups.length; i++) {\n        var group = matchGroups[i];\n        if(group[axId]) return 'g' + i;\n    }\n    return axId;\n};\n\n},{\"../../registry\":847,\"./constants\":773}],771:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nfunction findCategories(ax, opts) {\n    var dataAttr = opts.dataAttr || ax._id.charAt(0);\n    var lookup = {};\n    var axData;\n    var i, j;\n\n    if(opts.axData) {\n        // non-x/y case\n        axData = opts.axData;\n    } else {\n        // x/y case\n        axData = [];\n        for(i = 0; i < opts.data.length; i++) {\n            var trace = opts.data[i];\n            if(trace[dataAttr + 'axis'] === ax._id) {\n                axData.push(trace);\n            }\n        }\n    }\n\n    for(i = 0; i < axData.length; i++) {\n        var vals = axData[i][dataAttr];\n        for(j = 0; j < vals.length; j++) {\n            var v = vals[j];\n            if(v !== null && v !== undefined) {\n                lookup[v] = 1;\n            }\n        }\n    }\n\n    return Object.keys(lookup);\n}\n\n/**\n * Fills in category* default and initial categories.\n *\n * @param {object} containerIn : input axis object\n * @param {object} containerOut : full axis object\n * @param {function} coerce : Lib.coerce fn wrapper\n * @param {object} opts :\n *   - data {array} : (full) data trace\n * OR\n *   - axData {array} : (full) data associated with axis being coerced here\n *   - dataAttr {string} : attribute name corresponding to coordinate array\n */\nmodule.exports = function handleCategoryOrderDefaults(containerIn, containerOut, coerce, opts) {\n    if(containerOut.type !== 'category') return;\n\n    var arrayIn = containerIn.categoryarray;\n    var isValidArray = (Array.isArray(arrayIn) && arrayIn.length > 0);\n\n    // override default 'categoryorder' value when non-empty array is supplied\n    var orderDefault;\n    if(isValidArray) orderDefault = 'array';\n\n    var order = coerce('categoryorder', orderDefault);\n    var array;\n\n    // coerce 'categoryarray' only in array order case\n    if(order === 'array') {\n        array = coerce('categoryarray');\n    }\n\n    // cannot set 'categoryorder' to 'array' with an invalid 'categoryarray'\n    if(!isValidArray && order === 'array') {\n        order = containerOut.categoryorder = 'trace';\n    }\n\n    // set up things for makeCalcdata\n    if(order === 'trace') {\n        containerOut._initialCategories = [];\n    } else if(order === 'array') {\n        containerOut._initialCategories = array.slice();\n    } else {\n        array = findCategories(containerOut, opts).sort();\n        if(order === 'category ascending') {\n            containerOut._initialCategories = array;\n        } else if(order === 'category descending') {\n            containerOut._initialCategories = array.reverse();\n        }\n    }\n};\n\n},{}],772:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar Lib = _dereq_('../../lib');\nvar ONEDAY = _dereq_('../../constants/numerical').ONEDAY;\n\n/**\n * Return a validated dtick value for this axis\n *\n * @param {any} dtick: the candidate dtick. valid values are numbers and strings,\n *     and further constrained depending on the axis type.\n * @param {string} axType: the axis type\n */\nexports.dtick = function(dtick, axType) {\n    var isLog = axType === 'log';\n    var isDate = axType === 'date';\n    var isCat = axType === 'category';\n    var dtickDflt = isDate ? ONEDAY : 1;\n\n    if(!dtick) return dtickDflt;\n\n    if(isNumeric(dtick)) {\n        dtick = Number(dtick);\n        if(dtick <= 0) return dtickDflt;\n        if(isCat) {\n            // category dtick must be positive integers\n            return Math.max(1, Math.round(dtick));\n        }\n        if(isDate) {\n            // date dtick must be at least 0.1ms (our current precision)\n            return Math.max(0.1, dtick);\n        }\n        return dtick;\n    }\n\n    if(typeof dtick !== 'string' || !(isDate || isLog)) {\n        return dtickDflt;\n    }\n\n    var prefix = dtick.charAt(0);\n    var dtickNum = dtick.substr(1);\n    dtickNum = isNumeric(dtickNum) ? Number(dtickNum) : 0;\n\n    if((dtickNum <= 0) || !(\n            // \"M<n>\" gives ticks every (integer) n months\n            (isDate && prefix === 'M' && dtickNum === Math.round(dtickNum)) ||\n            // \"L<f>\" gives ticks linearly spaced in data (not in position) every (float) f\n            (isLog && prefix === 'L') ||\n            // \"D1\" gives powers of 10 with all small digits between, \"D2\" gives only 2 and 5\n            (isLog && prefix === 'D' && (dtickNum === 1 || dtickNum === 2))\n        )) {\n        return dtickDflt;\n    }\n\n    return dtick;\n};\n\n/**\n * Return a validated tick0 for this axis\n *\n * @param {any} tick0: the candidate tick0. Valid values are numbers and strings,\n *     further constrained depending on the axis type\n * @param {string} axType: the axis type\n * @param {string} calendar: for date axes, the calendar to validate/convert with\n * @param {any} dtick: an already valid dtick. Only used for D1 and D2 log dticks,\n *     which do not support tick0 at all.\n */\nexports.tick0 = function(tick0, axType, calendar, dtick) {\n    if(axType === 'date') {\n        return Lib.cleanDate(tick0, Lib.dateTick0(calendar));\n    }\n    if(dtick === 'D1' || dtick === 'D2') {\n        // D1 and D2 modes ignore tick0 entirely\n        return undefined;\n    }\n    // Aside from date axes, tick0 must be numeric\n    return isNumeric(tick0) ? Number(tick0) : 0;\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"fast-isnumeric\":225}],773:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\nvar counterRegex = _dereq_('../../lib/regex').counter;\n\n\nmodule.exports = {\n\n    idRegex: {\n        x: counterRegex('x'),\n        y: counterRegex('y')\n    },\n\n    attrRegex: counterRegex('[xy]axis'),\n\n    // axis match regular expression\n    xAxisMatch: counterRegex('xaxis'),\n    yAxisMatch: counterRegex('yaxis'),\n\n    // pattern matching axis ids and names\n    // note that this is more permissive than counterRegex, as\n    // id2name, name2id, and cleanId accept \"x1\" etc\n    AX_ID_PATTERN: /^[xyz][0-9]*$/,\n    AX_NAME_PATTERN: /^[xyz]axis[0-9]*$/,\n\n    // and for 2D subplots\n    SUBPLOT_PATTERN: /^x([0-9]*)y([0-9]*)$/,\n\n    // pixels to move mouse before you stop clamping to starting point\n    MINDRAG: 8,\n\n    // smallest dimension allowed for a select box\n    MINSELECT: 12,\n\n    // smallest dimension allowed for a zoombox\n    MINZOOM: 20,\n\n    // width of axis drag regions\n    DRAGGERSIZE: 20,\n\n    // max pixels off straight before a lasso select line counts as bent\n    BENDPX: 1.5,\n\n    // delay before a redraw (relayout) after smooth panning and zooming\n    REDRAWDELAY: 50,\n\n    // throttling limit (ms) for selectPoints calls\n    SELECTDELAY: 100,\n\n    // cache ID suffix for throttle\n    SELECTID: '-select',\n\n    // last resort axis ranges for x and y axes if we have no data\n    DFLTRANGEX: [-1, 6],\n    DFLTRANGEY: [-1, 4],\n\n    // Layers to keep trace types in the right order\n    // N.B. each  'unique' plot method must have its own layer\n    traceLayerClasses: [\n        'heatmaplayer',\n        'contourcarpetlayer', 'contourlayer',\n        'funnellayer', 'waterfalllayer', 'barlayer',\n        'carpetlayer',\n        'violinlayer',\n        'boxlayer',\n        'ohlclayer',\n        'scattercarpetlayer', 'scatterlayer'\n    ],\n\n    clipOnAxisFalseQuery: [\n        '.scatterlayer',\n        '.barlayer',\n        '.funnellayer',\n        '.waterfalllayer'\n    ],\n\n    layerValue2layerClass: {\n        'above traces': 'above',\n        'below traces': 'below'\n    }\n};\n\n},{\"../../lib/regex\":735}],774:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar id2name = _dereq_('./axis_ids').id2name;\nvar scaleZoom = _dereq_('./scale_zoom');\nvar makePadFn = _dereq_('./autorange').makePadFn;\nvar concatExtremes = _dereq_('./autorange').concatExtremes;\n\nvar ALMOST_EQUAL = _dereq_('../../constants/numerical').ALMOST_EQUAL;\nvar FROM_BL = _dereq_('../../constants/alignment').FROM_BL;\n\nexports.handleConstraintDefaults = function(containerIn, containerOut, coerce, allAxisIds, layoutOut) {\n    var constraintGroups = layoutOut._axisConstraintGroups;\n    var matchGroups = layoutOut._axisMatchGroups;\n    var axId = containerOut._id;\n    var axLetter = axId.charAt(0);\n    var splomStash = ((layoutOut._splomAxes || {})[axLetter] || {})[axId] || {};\n    var thisID = containerOut._id;\n    var letter = thisID.charAt(0);\n\n    // coerce the constraint mechanics even if this axis has no scaleanchor\n    // because it may be the anchor of another axis.\n    var constrain = coerce('constrain');\n    Lib.coerce(containerIn, containerOut, {\n        constraintoward: {\n            valType: 'enumerated',\n            values: letter === 'x' ? ['left', 'center', 'right'] : ['bottom', 'middle', 'top'],\n            dflt: letter === 'x' ? 'center' : 'middle'\n        }\n    }, 'constraintoward');\n\n    var matches, matchOpts;\n\n    if((containerIn.matches || splomStash.matches) && !containerOut.fixedrange) {\n        matchOpts = getConstraintOpts(matchGroups, thisID, allAxisIds, layoutOut);\n        matches = Lib.coerce(containerIn, containerOut, {\n            matches: {\n                valType: 'enumerated',\n                values: matchOpts.linkableAxes || [],\n                dflt: splomStash.matches\n            }\n        }, 'matches');\n    }\n\n    // 'matches' wins over 'scaleanchor' (for now)\n    var scaleanchor, scaleOpts;\n\n    if(!matches && containerIn.scaleanchor && !(containerOut.fixedrange && constrain !== 'domain')) {\n        scaleOpts = getConstraintOpts(constraintGroups, thisID, allAxisIds, layoutOut, constrain);\n        scaleanchor = Lib.coerce(containerIn, containerOut, {\n            scaleanchor: {\n                valType: 'enumerated',\n                values: scaleOpts.linkableAxes || []\n            }\n        }, 'scaleanchor');\n    }\n\n    if(matches) {\n        delete containerOut.constrain;\n        updateConstraintGroups(matchGroups, matchOpts.thisGroup, thisID, matches, 1);\n    } else if(allAxisIds.indexOf(containerIn.matches) !== -1) {\n        Lib.warn('ignored ' + containerOut._name + '.matches: \"' +\n            containerIn.matches + '\" to avoid either an infinite loop ' +\n            'or because the target axis has fixed range.');\n    }\n\n    if(scaleanchor) {\n        var scaleratio = coerce('scaleratio');\n\n        // TODO: I suppose I could do attribute.min: Number.MIN_VALUE to avoid zero,\n        // but that seems hacky. Better way to say \"must be a positive number\"?\n        // Of course if you use several super-tiny values you could eventually\n        // force a product of these to zero and all hell would break loose...\n        // Likewise with super-huge values.\n        if(!scaleratio) scaleratio = containerOut.scaleratio = 1;\n\n        updateConstraintGroups(constraintGroups, scaleOpts.thisGroup, thisID, scaleanchor, scaleratio);\n    } else if(allAxisIds.indexOf(containerIn.scaleanchor) !== -1) {\n        Lib.warn('ignored ' + containerOut._name + '.scaleanchor: \"' +\n            containerIn.scaleanchor + '\" to avoid either an infinite loop ' +\n            'and possibly inconsistent scaleratios, or because the target ' +\n            'axis has fixed range or this axis declares a *matches* constraint.');\n    }\n};\n\n// If this axis is already part of a constraint group, we can't\n// scaleanchor any other axis in that group, or we'd make a loop.\n// Filter allAxisIds to enforce this, also matching axis types.\nfunction getConstraintOpts(groups, thisID, allAxisIds, layoutOut, constrain) {\n    var doesNotConstrainRange = constrain !== 'range';\n    var thisType = layoutOut[id2name(thisID)].type;\n    var i, j, idj, axj;\n\n    var linkableAxes = [];\n    for(j = 0; j < allAxisIds.length; j++) {\n        idj = allAxisIds[j];\n        if(idj === thisID) continue;\n\n        axj = layoutOut[id2name(idj)];\n        if(axj.type === thisType) {\n            if(!axj.fixedrange) {\n                linkableAxes.push(idj);\n            } else if(doesNotConstrainRange && axj.anchor) {\n                // allow domain constraints on subplots where\n                // BOTH axes have fixedrange:true and constrain:domain\n                var counterAxj = layoutOut[id2name(axj.anchor)];\n                if(counterAxj.fixedrange) {\n                    linkableAxes.push(idj);\n                }\n            }\n        }\n    }\n\n    for(i = 0; i < groups.length; i++) {\n        if(groups[i][thisID]) {\n            var thisGroup = groups[i];\n\n            var linkableAxesNoLoops = [];\n            for(j = 0; j < linkableAxes.length; j++) {\n                idj = linkableAxes[j];\n                if(!thisGroup[idj]) linkableAxesNoLoops.push(idj);\n            }\n            return {linkableAxes: linkableAxesNoLoops, thisGroup: thisGroup};\n        }\n    }\n\n    return {linkableAxes: linkableAxes, thisGroup: null};\n}\n\n/*\n * Add this axis to the axis constraint groups, which is the collection\n * of axes that are all constrained together on scale.\n *\n * constraintGroups: a list of objects. each object is\n * {axis_id: scale_within_group}, where scale_within_group is\n * only important relative to the rest of the group, and defines\n * the relative scales between all axes in the group\n *\n * thisGroup: the group the current axis is already in\n * thisID: the id if the current axis\n * scaleanchor: the id of the axis to scale it with\n * scaleratio: the ratio of this axis to the scaleanchor axis\n */\nfunction updateConstraintGroups(constraintGroups, thisGroup, thisID, scaleanchor, scaleratio) {\n    var i, j, groupi, keyj, thisGroupIndex;\n\n    if(thisGroup === null) {\n        thisGroup = {};\n        thisGroup[thisID] = 1;\n        thisGroupIndex = constraintGroups.length;\n        constraintGroups.push(thisGroup);\n    } else {\n        thisGroupIndex = constraintGroups.indexOf(thisGroup);\n    }\n\n    var thisGroupKeys = Object.keys(thisGroup);\n\n    // we know that this axis isn't in any other groups, but we don't know\n    // about the scaleanchor axis. If it is, we need to merge the groups.\n    for(i = 0; i < constraintGroups.length; i++) {\n        groupi = constraintGroups[i];\n        if(i !== thisGroupIndex && groupi[scaleanchor]) {\n            var baseScale = groupi[scaleanchor];\n            for(j = 0; j < thisGroupKeys.length; j++) {\n                keyj = thisGroupKeys[j];\n                groupi[keyj] = baseScale * scaleratio * thisGroup[keyj];\n            }\n            constraintGroups.splice(thisGroupIndex, 1);\n            return;\n        }\n    }\n\n    // otherwise, we insert the new scaleanchor axis as the base scale (1)\n    // in its group, and scale the rest of the group to it\n    if(scaleratio !== 1) {\n        for(j = 0; j < thisGroupKeys.length; j++) {\n            thisGroup[thisGroupKeys[j]] *= scaleratio;\n        }\n    }\n    thisGroup[scaleanchor] = 1;\n}\n\nexports.enforce = function enforce(gd) {\n    var fullLayout = gd._fullLayout;\n    var constraintGroups = fullLayout._axisConstraintGroups || [];\n\n    var i, j, axisID, ax, normScale, mode, factor;\n\n    for(i = 0; i < constraintGroups.length; i++) {\n        var group = constraintGroups[i];\n        var axisIDs = Object.keys(group);\n\n        var minScale = Infinity;\n        var maxScale = 0;\n        // mostly matchScale will be the same as minScale\n        // ie we expand axis ranges to encompass *everything*\n        // that's currently in any of their ranges, but during\n        // autorange of a subset of axes we will ignore other\n        // axes for this purpose.\n        var matchScale = Infinity;\n        var normScales = {};\n        var axes = {};\n        var hasAnyDomainConstraint = false;\n\n        // find the (normalized) scale of each axis in the group\n        for(j = 0; j < axisIDs.length; j++) {\n            axisID = axisIDs[j];\n            axes[axisID] = ax = fullLayout[id2name(axisID)];\n\n            if(ax._inputDomain) ax.domain = ax._inputDomain.slice();\n            else ax._inputDomain = ax.domain.slice();\n\n            if(!ax._inputRange) ax._inputRange = ax.range.slice();\n\n            // set axis scale here so we can use _m rather than\n            // having to calculate it from length and range\n            ax.setScale();\n\n            // abs: inverted scales still satisfy the constraint\n            normScales[axisID] = normScale = Math.abs(ax._m) / group[axisID];\n            minScale = Math.min(minScale, normScale);\n            if(ax.constrain === 'domain' || !ax._constraintShrinkable) {\n                matchScale = Math.min(matchScale, normScale);\n            }\n\n            // this has served its purpose, so remove it\n            delete ax._constraintShrinkable;\n            maxScale = Math.max(maxScale, normScale);\n\n            if(ax.constrain === 'domain') hasAnyDomainConstraint = true;\n        }\n\n        // Do we have a constraint mismatch? Give a small buffer for rounding errors\n        if(minScale > ALMOST_EQUAL * maxScale && !hasAnyDomainConstraint) continue;\n\n        // now increase any ranges we need to until all normalized scales are equal\n        for(j = 0; j < axisIDs.length; j++) {\n            axisID = axisIDs[j];\n            normScale = normScales[axisID];\n            ax = axes[axisID];\n            mode = ax.constrain;\n\n            // even if the scale didn't change, if we're shrinking domain\n            // we need to recalculate in case `constraintoward` changed\n            if(normScale !== matchScale || mode === 'domain') {\n                factor = normScale / matchScale;\n\n                if(mode === 'range') {\n                    scaleZoom(ax, factor);\n                } else {\n                    // mode === 'domain'\n\n                    var inputDomain = ax._inputDomain;\n                    var domainShrunk = (ax.domain[1] - ax.domain[0]) /\n                        (inputDomain[1] - inputDomain[0]);\n                    var rangeShrunk = (ax.r2l(ax.range[1]) - ax.r2l(ax.range[0])) /\n                        (ax.r2l(ax._inputRange[1]) - ax.r2l(ax._inputRange[0]));\n\n                    factor /= domainShrunk;\n\n                    if(factor * rangeShrunk < 1) {\n                        // we've asked to magnify the axis more than we can just by\n                        // enlarging the domain - so we need to constrict range\n                        ax.domain = ax._input.domain = inputDomain.slice();\n                        scaleZoom(ax, factor);\n                        continue;\n                    }\n\n                    if(rangeShrunk < 1) {\n                        // the range has previously been constricted by ^^, but we've\n                        // switched to the domain-constricted regime, so reset range\n                        ax.range = ax._input.range = ax._inputRange.slice();\n                        factor *= rangeShrunk;\n                    }\n\n                    if(ax.autorange) {\n                        /*\n                         * range & factor may need to change because range was\n                         * calculated for the larger scaling, so some pixel\n                         * paddings may get cut off when we reduce the domain.\n                         *\n                         * This is easier than the regular autorange calculation\n                         * because we already know the scaling `m`, but we still\n                         * need to cut out impossible constraints (like\n                         * annotations with super-long arrows). That's what\n                         * outerMin/Max are for - if the expansion was going to\n                         * go beyond the original domain, it must be impossible\n                         */\n                        var rl0 = ax.r2l(ax.range[0]);\n                        var rl1 = ax.r2l(ax.range[1]);\n                        var rangeCenter = (rl0 + rl1) / 2;\n                        var rangeMin = rangeCenter;\n                        var rangeMax = rangeCenter;\n                        var halfRange = Math.abs(rl1 - rangeCenter);\n                        // extra tiny bit for rounding errors, in case we actually\n                        // *are* expanding to the full domain\n                        var outerMin = rangeCenter - halfRange * factor * 1.0001;\n                        var outerMax = rangeCenter + halfRange * factor * 1.0001;\n                        var getPad = makePadFn(ax);\n\n                        updateDomain(ax, factor);\n                        var m = Math.abs(ax._m);\n                        var extremes = concatExtremes(gd, ax);\n                        var minArray = extremes.min;\n                        var maxArray = extremes.max;\n                        var newVal;\n                        var k;\n\n                        for(k = 0; k < minArray.length; k++) {\n                            newVal = minArray[k].val - getPad(minArray[k]) / m;\n                            if(newVal > outerMin && newVal < rangeMin) {\n                                rangeMin = newVal;\n                            }\n                        }\n\n                        for(k = 0; k < maxArray.length; k++) {\n                            newVal = maxArray[k].val + getPad(maxArray[k]) / m;\n                            if(newVal < outerMax && newVal > rangeMax) {\n                                rangeMax = newVal;\n                            }\n                        }\n\n                        var domainExpand = (rangeMax - rangeMin) / (2 * halfRange);\n                        factor /= domainExpand;\n\n                        rangeMin = ax.l2r(rangeMin);\n                        rangeMax = ax.l2r(rangeMax);\n                        ax.range = ax._input.range = (rl0 < rl1) ?\n                            [rangeMin, rangeMax] : [rangeMax, rangeMin];\n                    }\n\n                    updateDomain(ax, factor);\n                }\n            }\n        }\n    }\n};\n\n// For use before autoranging, check if this axis was previously constrained\n// by domain but no longer is\nexports.clean = function clean(gd, ax) {\n    if(ax._inputDomain) {\n        var isConstrained = false;\n        var axId = ax._id;\n        var constraintGroups = gd._fullLayout._axisConstraintGroups;\n        for(var j = 0; j < constraintGroups.length; j++) {\n            if(constraintGroups[j][axId]) {\n                isConstrained = true;\n                break;\n            }\n        }\n        if(!isConstrained || ax.constrain !== 'domain') {\n            ax._input.domain = ax.domain = ax._inputDomain;\n            delete ax._inputDomain;\n        }\n    }\n};\n\nfunction updateDomain(ax, factor) {\n    var inputDomain = ax._inputDomain;\n    var centerFraction = FROM_BL[ax.constraintoward];\n    var center = inputDomain[0] + (inputDomain[1] - inputDomain[0]) * centerFraction;\n\n    ax.domain = ax._input.domain = [\n        center + (inputDomain[0] - center) / factor,\n        center + (inputDomain[1] - center) / factor\n    ];\n    ax.setScale();\n}\n\n},{\"../../constants/alignment\":688,\"../../constants/numerical\":695,\"../../lib\":719,\"./autorange\":766,\"./axis_ids\":770,\"./scale_zoom\":783}],775:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar tinycolor = _dereq_('tinycolor2');\nvar supportsPassive = _dereq_('has-passive-events');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar Fx = _dereq_('../../components/fx');\nvar Axes = _dereq_('./axes');\nvar setCursor = _dereq_('../../lib/setcursor');\nvar dragElement = _dereq_('../../components/dragelement');\nvar FROM_TL = _dereq_('../../constants/alignment').FROM_TL;\nvar clearGlCanvases = _dereq_('../../lib/clear_gl_canvases');\nvar redrawReglTraces = _dereq_('../../plot_api/subroutines').redrawReglTraces;\n\nvar Plots = _dereq_('../plots');\n\nvar getFromId = _dereq_('./axis_ids').getFromId;\nvar prepSelect = _dereq_('./select').prepSelect;\nvar clearSelect = _dereq_('./select').clearSelect;\nvar selectOnClick = _dereq_('./select').selectOnClick;\nvar scaleZoom = _dereq_('./scale_zoom');\n\nvar constants = _dereq_('./constants');\nvar MINDRAG = constants.MINDRAG;\nvar MINZOOM = constants.MINZOOM;\n\n// flag for showing \"doubleclick to zoom out\" only at the beginning\nvar SHOWZOOMOUTTIP = true;\n\n// dragBox: create an element to drag one or more axis ends\n// inputs:\n//      plotinfo - which subplot are we making dragboxes on?\n//      x,y,w,h - left, top, width, height of the box\n//      ns - how does this drag the vertical axis?\n//          'n' - top only\n//          's' - bottom only\n//          'ns' - top and bottom together, difference unchanged\n//      ew - same for horizontal axis\nfunction makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {\n    // mouseDown stores ms of first mousedown event in the last\n    // `gd._context.doubleClickDelay` ms on the drag bars\n    // numClicks stores how many mousedowns have been seen\n    // within `gd._context.doubleClickDelay` so we can check for click or doubleclick events\n    // dragged stores whether a drag has occurred, so we don't have to\n    // redraw unnecessarily, ie if no move bigger than MINDRAG or MINZOOM px\n    var zoomlayer = gd._fullLayout._zoomlayer;\n    var isMainDrag = (ns + ew === 'nsew');\n    var singleEnd = (ns + ew).length === 1;\n\n    // main subplot x and y (i.e. found in plotinfo - the main ones)\n    var xa0, ya0;\n    // {ax._id: ax} hash objects\n    var xaHash, yaHash;\n    // xaHash/yaHash values (arrays)\n    var xaxes, yaxes;\n    // main axis offsets\n    var xs, ys;\n    // main axis lengths\n    var pw, ph;\n    // contains keys 'xaHash', 'yaHash', 'xaxes', and 'yaxes'\n    // which are the x/y {ax._id: ax} hash objects and their values\n    // for linked axis relative to this subplot\n    var links;\n    // similar to `links` but for matching axes\n    var matches;\n    // set to ew/ns val when active, set to '' when inactive\n    var xActive, yActive;\n    // are all axes in this subplot are fixed?\n    var allFixedRanges;\n    // do we need to edit x/y ranges?\n    var editX, editY;\n    // graph-wide optimization flags\n    var hasScatterGl, hasSplom, hasSVG;\n    // collected changes to be made to the plot by relayout at the end\n    var updates;\n\n    function recomputeAxisLists() {\n        xa0 = plotinfo.xaxis;\n        ya0 = plotinfo.yaxis;\n        pw = xa0._length;\n        ph = ya0._length;\n        xs = xa0._offset;\n        ys = ya0._offset;\n\n        xaHash = {};\n        xaHash[xa0._id] = xa0;\n        yaHash = {};\n        yaHash[ya0._id] = ya0;\n\n        // if we're dragging two axes at once, also drag overlays\n        if(ns && ew) {\n            var overlays = plotinfo.overlays;\n            for(var i = 0; i < overlays.length; i++) {\n                var xa = overlays[i].xaxis;\n                xaHash[xa._id] = xa;\n                var ya = overlays[i].yaxis;\n                yaHash[ya._id] = ya;\n            }\n        }\n\n        xaxes = hashValues(xaHash);\n        yaxes = hashValues(yaHash);\n        xActive = isDirectionActive(xaxes, ew);\n        yActive = isDirectionActive(yaxes, ns);\n        allFixedRanges = !yActive && !xActive;\n\n        links = calcLinks(gd, gd._fullLayout._axisConstraintGroups, xaHash, yaHash);\n        matches = calcLinks(gd, gd._fullLayout._axisMatchGroups, xaHash, yaHash);\n        editX = ew || links.isSubplotConstrained || matches.isSubplotConstrained;\n        editY = ns || links.isSubplotConstrained || matches.isSubplotConstrained;\n\n        var fullLayout = gd._fullLayout;\n        hasScatterGl = fullLayout._has('scattergl');\n        hasSplom = fullLayout._has('splom');\n        hasSVG = fullLayout._has('svg');\n    }\n\n    recomputeAxisLists();\n\n    var cursor = getDragCursor(yActive + xActive, gd._fullLayout.dragmode, isMainDrag);\n    var dragger = makeRectDragger(plotinfo, ns + ew + 'drag', cursor, x, y, w, h);\n\n    // still need to make the element if the axes are disabled\n    // but nuke its events (except for maindrag which needs them for hover)\n    // and stop there\n    if(allFixedRanges && !isMainDrag) {\n        dragger.onmousedown = null;\n        dragger.style.pointerEvents = 'none';\n        return dragger;\n    }\n\n    var dragOptions = {\n        element: dragger,\n        gd: gd,\n        plotinfo: plotinfo\n    };\n\n    dragOptions.prepFn = function(e, startX, startY) {\n        var dragModePrev = dragOptions.dragmode;\n        var dragModeNow = gd._fullLayout.dragmode;\n        if(dragModeNow !== dragModePrev) {\n            dragOptions.dragmode = dragModeNow;\n        }\n\n        recomputeAxisLists();\n\n        if(!allFixedRanges) {\n            if(isMainDrag) {\n                // main dragger handles all drag modes, and changes\n                // to pan (or to zoom if it already is pan) on shift\n                if(e.shiftKey) {\n                    if(dragModeNow === 'pan') dragModeNow = 'zoom';\n                    else if(!isSelectOrLasso(dragModeNow)) dragModeNow = 'pan';\n                } else if(e.ctrlKey) {\n                    dragModeNow = 'pan';\n                }\n            } else {\n                // all other draggers just pan\n                dragModeNow = 'pan';\n            }\n        }\n\n        if(dragModeNow === 'lasso') dragOptions.minDrag = 1;\n        else dragOptions.minDrag = undefined;\n\n        if(isSelectOrLasso(dragModeNow)) {\n            dragOptions.xaxes = xaxes;\n            dragOptions.yaxes = yaxes;\n            // this attaches moveFn, clickFn, doneFn on dragOptions\n            prepSelect(e, startX, startY, dragOptions, dragModeNow);\n        } else {\n            dragOptions.clickFn = clickFn;\n            if(isSelectOrLasso(dragModePrev)) {\n                // TODO Fix potential bug\n                // Note: clearing / resetting selection state only happens, when user\n                // triggers at least one interaction in pan/zoom mode. Otherwise, the\n                // select/lasso outlines are deleted (in plots.js.cleanPlot) but the selection\n                // cache isn't cleared. So when the user switches back to select/lasso and\n                // 'adds to a selection' with Shift, the \"old\", seemingly removed outlines\n                // are redrawn again because the selection cache still holds their coordinates.\n                // However, this isn't easily solved, since plots.js would need\n                // to have a reference to the dragOptions object (which holds the\n                // selection cache).\n                clearAndResetSelect();\n            }\n\n            if(!allFixedRanges) {\n                if(dragModeNow === 'zoom') {\n                    dragOptions.moveFn = zoomMove;\n                    dragOptions.doneFn = zoomDone;\n\n                    // zoomMove takes care of the threshold, but we need to\n                    // minimize this so that constrained zoom boxes will flip\n                    // orientation at the right place\n                    dragOptions.minDrag = 1;\n\n                    zoomPrep(e, startX, startY);\n                } else if(dragModeNow === 'pan') {\n                    dragOptions.moveFn = plotDrag;\n                    dragOptions.doneFn = dragTail;\n                }\n            }\n        }\n\n        gd._fullLayout._redrag = function() {\n            var dragDataNow = gd._dragdata;\n\n            if(dragDataNow && dragDataNow.element === dragger) {\n                var dragModeNow = gd._fullLayout.dragmode;\n\n                if(!isSelectOrLasso(dragModeNow)) {\n                    recomputeAxisLists();\n                    updateSubplots([0, 0, pw, ph]);\n                    dragOptions.moveFn(dragDataNow.dx, dragDataNow.dy);\n                }\n\n                // TODO should we try to \"re-select\" under select/lasso modes?\n                // probably best to wait for https://github.com/plotly/plotly.js/issues/1851\n            }\n        };\n    };\n\n    function clearAndResetSelect() {\n        // clear selection polygon cache (if any)\n        dragOptions.plotinfo.selection = false;\n        // clear selection outlines\n        clearSelect(gd);\n    }\n\n    function clickFn(numClicks, evt) {\n        var clickmode = gd._fullLayout.clickmode;\n\n        removeZoombox(gd);\n\n        if(numClicks === 2 && !singleEnd) doubleClick();\n\n        if(isMainDrag) {\n            if(clickmode.indexOf('select') > -1) {\n                selectOnClick(evt, gd, xaxes, yaxes, plotinfo.id, dragOptions);\n            }\n\n            if(clickmode.indexOf('event') > -1) {\n                Fx.click(gd, evt, plotinfo.id);\n            }\n        } else if(numClicks === 1 && singleEnd) {\n            var ax = ns ? ya0 : xa0;\n            var end = (ns === 's' || ew === 'w') ? 0 : 1;\n            var attrStr = ax._name + '.range[' + end + ']';\n            var initialText = getEndText(ax, end);\n            var hAlign = 'left';\n            var vAlign = 'middle';\n\n            if(ax.fixedrange) return;\n\n            if(ns) {\n                vAlign = (ns === 'n') ? 'top' : 'bottom';\n                if(ax.side === 'right') hAlign = 'right';\n            } else if(ew === 'e') hAlign = 'right';\n\n            if(gd._context.showAxisRangeEntryBoxes) {\n                d3.select(dragger)\n                    .call(svgTextUtils.makeEditable, {\n                        gd: gd,\n                        immediate: true,\n                        background: gd._fullLayout.paper_bgcolor,\n                        text: String(initialText),\n                        fill: ax.tickfont ? ax.tickfont.color : '#444',\n                        horizontalAlign: hAlign,\n                        verticalAlign: vAlign\n                    })\n                    .on('edit', function(text) {\n                        var v = ax.d2r(text);\n                        if(v !== undefined) {\n                            Registry.call('_guiRelayout', gd, attrStr, v);\n                        }\n                    });\n            }\n        }\n    }\n\n    dragElement.init(dragOptions);\n\n    // x/y px position at start of drag\n    var x0, y0;\n    // bbox object of the zoombox\n    var box;\n    // luminance of bg behind zoombox\n    var lum;\n    // zoombox path outline\n    var path0;\n    // is zoombox dimmed (during drag)\n    var dimmed;\n    // 'x'-only, 'y' or 'xy' zooming\n    var zoomMode;\n    // zoombox d3 selection\n    var zb;\n    // zoombox corner d3 selection\n    var corners;\n    // zoom takes over minDrag, so it also has to take over gd._dragged\n    var zoomDragged;\n\n    function zoomPrep(e, startX, startY) {\n        var dragBBox = dragger.getBoundingClientRect();\n        x0 = startX - dragBBox.left;\n        y0 = startY - dragBBox.top;\n        box = {l: x0, r: x0, w: 0, t: y0, b: y0, h: 0};\n        lum = gd._hmpixcount ?\n            (gd._hmlumcount / gd._hmpixcount) :\n            tinycolor(gd._fullLayout.plot_bgcolor).getLuminance();\n        path0 = 'M0,0H' + pw + 'V' + ph + 'H0V0';\n        dimmed = false;\n        zoomMode = 'xy';\n        zoomDragged = false;\n        zb = makeZoombox(zoomlayer, lum, xs, ys, path0);\n        corners = makeCorners(zoomlayer, xs, ys);\n    }\n\n    function zoomMove(dx0, dy0) {\n        if(gd._transitioningWithDuration) {\n            return false;\n        }\n\n        var x1 = Math.max(0, Math.min(pw, dx0 + x0));\n        var y1 = Math.max(0, Math.min(ph, dy0 + y0));\n        var dx = Math.abs(x1 - x0);\n        var dy = Math.abs(y1 - y0);\n\n        box.l = Math.min(x0, x1);\n        box.r = Math.max(x0, x1);\n        box.t = Math.min(y0, y1);\n        box.b = Math.max(y0, y1);\n\n        function noZoom() {\n            zoomMode = '';\n            box.r = box.l;\n            box.t = box.b;\n            corners.attr('d', 'M0,0Z');\n        }\n\n        if(links.isSubplotConstrained) {\n            if(dx > MINZOOM || dy > MINZOOM) {\n                zoomMode = 'xy';\n                if(dx / pw > dy / ph) {\n                    dy = dx * ph / pw;\n                    if(y0 > y1) box.t = y0 - dy;\n                    else box.b = y0 + dy;\n                } else {\n                    dx = dy * pw / ph;\n                    if(x0 > x1) box.l = x0 - dx;\n                    else box.r = x0 + dx;\n                }\n                corners.attr('d', xyCorners(box));\n            } else {\n                noZoom();\n            }\n        } else if(matches.isSubplotConstrained) {\n            if(dx > MINZOOM || dy > MINZOOM) {\n                zoomMode = 'xy';\n\n                var r0 = Math.min(box.l / pw, (ph - box.b) / ph);\n                var r1 = Math.max(box.r / pw, (ph - box.t) / ph);\n\n                box.l = r0 * pw;\n                box.r = r1 * pw;\n                box.b = (1 - r0) * ph;\n                box.t = (1 - r1) * ph;\n                corners.attr('d', xyCorners(box));\n            } else {\n                noZoom();\n            }\n        } else if(!yActive || dy < Math.min(Math.max(dx * 0.6, MINDRAG), MINZOOM)) {\n            // look for small drags in one direction or the other,\n            // and only drag the other axis\n\n            if(dx < MINDRAG || !xActive) {\n                noZoom();\n            } else {\n                box.t = 0;\n                box.b = ph;\n                zoomMode = 'x';\n                corners.attr('d', xCorners(box, y0));\n            }\n        } else if(!xActive || dx < Math.min(dy * 0.6, MINZOOM)) {\n            box.l = 0;\n            box.r = pw;\n            zoomMode = 'y';\n            corners.attr('d', yCorners(box, x0));\n        } else {\n            zoomMode = 'xy';\n            corners.attr('d', xyCorners(box));\n        }\n        box.w = box.r - box.l;\n        box.h = box.b - box.t;\n\n        if(zoomMode) zoomDragged = true;\n        gd._dragged = zoomDragged;\n\n        updateZoombox(zb, corners, box, path0, dimmed, lum);\n        computeZoomUpdates();\n        gd.emit('plotly_relayouting', updates);\n        dimmed = true;\n    }\n\n    function computeZoomUpdates() {\n        updates = {};\n\n        // TODO: edit linked axes in zoomAxRanges and in dragTail\n        if(zoomMode === 'xy' || zoomMode === 'x') {\n            zoomAxRanges(xaxes, box.l / pw, box.r / pw, updates, links.xaxes);\n            updateMatchedAxRange('x', updates);\n        }\n        if(zoomMode === 'xy' || zoomMode === 'y') {\n            zoomAxRanges(yaxes, (ph - box.b) / ph, (ph - box.t) / ph, updates, links.yaxes);\n            updateMatchedAxRange('y', updates);\n        }\n    }\n\n    function zoomDone() {\n        // more strict than dragged, which allows you to come back to where you started\n        // and still count as dragged\n        if(Math.min(box.h, box.w) < MINDRAG * 2) {\n            return removeZoombox(gd);\n        }\n\n        computeZoomUpdates();\n\n        removeZoombox(gd);\n        dragTail();\n        showDoubleClickNotifier(gd);\n    }\n\n    // scroll zoom, on all draggers except corners\n    var scrollViewBox = [0, 0, pw, ph];\n    // wait a little after scrolling before redrawing\n    var redrawTimer = null;\n    var REDRAWDELAY = constants.REDRAWDELAY;\n    var mainplot = plotinfo.mainplot ? gd._fullLayout._plots[plotinfo.mainplot] : plotinfo;\n\n    function zoomWheel(e) {\n        // deactivate mousewheel scrolling on embedded graphs\n        // devs can override this with layout._enablescrollzoom,\n        // but _ ensures this setting won't leave their page\n        if(!gd._context._scrollZoom.cartesian && !gd._fullLayout._enablescrollzoom) {\n            return;\n        }\n\n        clearAndResetSelect();\n\n        // If a transition is in progress, then disable any behavior:\n        if(gd._transitioningWithDuration) {\n            e.preventDefault();\n            e.stopPropagation();\n            return;\n        }\n\n        recomputeAxisLists();\n\n        clearTimeout(redrawTimer);\n\n        var wheelDelta = -e.deltaY;\n        if(!isFinite(wheelDelta)) wheelDelta = e.wheelDelta / 10;\n        if(!isFinite(wheelDelta)) {\n            Lib.log('Did not find wheel motion attributes: ', e);\n            return;\n        }\n\n        var zoom = Math.exp(-Math.min(Math.max(wheelDelta, -20), 20) / 200);\n        var gbb = mainplot.draglayer.select('.nsewdrag').node().getBoundingClientRect();\n        var xfrac = (e.clientX - gbb.left) / gbb.width;\n        var yfrac = (gbb.bottom - e.clientY) / gbb.height;\n        var i;\n\n        function zoomWheelOneAxis(ax, centerFraction, zoom) {\n            if(ax.fixedrange) return;\n\n            var axRange = Lib.simpleMap(ax.range, ax.r2l);\n            var v0 = axRange[0] + (axRange[1] - axRange[0]) * centerFraction;\n            function doZoom(v) { return ax.l2r(v0 + (v - v0) * zoom); }\n            ax.range = axRange.map(doZoom);\n        }\n\n        if(editX) {\n            // if we're only zooming this axis because of constraints,\n            // zoom it about the center\n            if(!ew) xfrac = 0.5;\n\n            for(i = 0; i < xaxes.length; i++) {\n                zoomWheelOneAxis(xaxes[i], xfrac, zoom);\n            }\n            updateMatchedAxRange('x');\n\n            scrollViewBox[2] *= zoom;\n            scrollViewBox[0] += scrollViewBox[2] * xfrac * (1 / zoom - 1);\n        }\n        if(editY) {\n            if(!ns) yfrac = 0.5;\n\n            for(i = 0; i < yaxes.length; i++) {\n                zoomWheelOneAxis(yaxes[i], yfrac, zoom);\n            }\n            updateMatchedAxRange('y');\n\n            scrollViewBox[3] *= zoom;\n            scrollViewBox[1] += scrollViewBox[3] * (1 - yfrac) * (1 / zoom - 1);\n        }\n\n        // viewbox redraw at first\n        updateSubplots(scrollViewBox);\n        ticksAndAnnotations();\n\n        gd.emit('plotly_relayouting', updates);\n\n        // then replot after a delay to make sure\n        // no more scrolling is coming\n        redrawTimer = setTimeout(function() {\n            scrollViewBox = [0, 0, pw, ph];\n            dragTail();\n        }, REDRAWDELAY);\n\n        e.preventDefault();\n        return;\n    }\n\n    // everything but the corners gets wheel zoom\n    if(ns.length * ew.length !== 1) {\n        attachWheelEventHandler(dragger, zoomWheel);\n    }\n\n    // plotDrag: move the plot in response to a drag\n    function plotDrag(dx, dy) {\n        // If a transition is in progress, then disable any behavior:\n        if(gd._transitioningWithDuration) {\n            return;\n        }\n\n        // prevent axis drawing from monkeying with margins until we're done\n        gd._fullLayout._replotting = true;\n\n        if(xActive === 'ew' || yActive === 'ns') {\n            if(xActive) {\n                dragAxList(xaxes, dx);\n                updateMatchedAxRange('x');\n            }\n            if(yActive) {\n                dragAxList(yaxes, dy);\n                updateMatchedAxRange('y');\n            }\n            updateSubplots([xActive ? -dx : 0, yActive ? -dy : 0, pw, ph]);\n            ticksAndAnnotations();\n            gd.emit('plotly_relayouting', updates);\n            return;\n        }\n\n        // dz: set a new value for one end (0 or 1) of an axis array axArray,\n        // and return a pixel shift for that end for the viewbox\n        // based on pixel drag distance d\n        // TODO: this makes (generally non-fatal) errors when you get\n        // near floating point limits\n        function dz(axArray, end, d) {\n            var otherEnd = 1 - end;\n            var movedAx;\n            var newLinearizedEnd;\n            for(var i = 0; i < axArray.length; i++) {\n                var axi = axArray[i];\n                if(axi.fixedrange) continue;\n                movedAx = axi;\n                newLinearizedEnd = axi._rl[otherEnd] +\n                    (axi._rl[end] - axi._rl[otherEnd]) / dZoom(d / axi._length);\n                var newEnd = axi.l2r(newLinearizedEnd);\n\n                // if l2r comes back false or undefined, it means we've dragged off\n                // the end of valid ranges - so stop.\n                if(newEnd !== false && newEnd !== undefined) axi.range[end] = newEnd;\n            }\n            return movedAx._length * (movedAx._rl[end] - newLinearizedEnd) /\n                (movedAx._rl[end] - movedAx._rl[otherEnd]);\n        }\n\n        if(links.isSubplotConstrained && xActive && yActive) {\n            // dragging a corner of a constrained subplot:\n            // respect the fixed corner, but harmonize dx and dy\n            var dxySign = ((xActive === 'w') === (yActive === 'n')) ? 1 : -1;\n            var dxyFraction = (dx / pw + dxySign * dy / ph) / 2;\n            dx = dxyFraction * pw;\n            dy = dxySign * dxyFraction * ph;\n        }\n\n        if(xActive === 'w') dx = dz(xaxes, 0, dx);\n        else if(xActive === 'e') dx = dz(xaxes, 1, -dx);\n        else if(!xActive) dx = 0;\n\n        if(yActive === 'n') dy = dz(yaxes, 1, dy);\n        else if(yActive === 's') dy = dz(yaxes, 0, -dy);\n        else if(!yActive) dy = 0;\n\n        var xStart = (xActive === 'w') ? dx : 0;\n        var yStart = (yActive === 'n') ? dy : 0;\n\n        if(links.isSubplotConstrained) {\n            var i;\n            if(!xActive && yActive.length === 1) {\n                // dragging one end of the y axis of a constrained subplot\n                // scale the other axis the same about its middle\n                for(i = 0; i < xaxes.length; i++) {\n                    xaxes[i].range = xaxes[i]._r.slice();\n                    scaleZoom(xaxes[i], 1 - dy / ph);\n                }\n                dx = dy * pw / ph;\n                xStart = dx / 2;\n            }\n            if(!yActive && xActive.length === 1) {\n                for(i = 0; i < yaxes.length; i++) {\n                    yaxes[i].range = yaxes[i]._r.slice();\n                    scaleZoom(yaxes[i], 1 - dx / pw);\n                }\n                dy = dx * ph / pw;\n                yStart = dy / 2;\n            }\n        }\n\n        updateMatchedAxRange('x');\n        updateMatchedAxRange('y');\n        updateSubplots([xStart, yStart, pw - dx, ph - dy]);\n        ticksAndAnnotations();\n        gd.emit('plotly_relayouting', updates);\n    }\n\n    function updateMatchedAxRange(axLetter, out) {\n        var matchedAxes = matches.isSubplotConstrained ?\n            {x: yaxes, y: xaxes}[axLetter] :\n            matches[axLetter + 'axes'];\n\n        var constrainedAxes = matches.isSubplotConstrained ?\n            {x: xaxes, y: yaxes}[axLetter] :\n            [];\n\n        for(var i = 0; i < matchedAxes.length; i++) {\n            var ax = matchedAxes[i];\n            var axId = ax._id;\n            var axId2 = matches.xLinks[axId] || matches.yLinks[axId];\n            var ax2 = constrainedAxes[0] || xaHash[axId2] || yaHash[axId2];\n\n            if(ax2) {\n                if(out) {\n                    // zoombox case - don't mutate 'range', just add keys in 'updates'\n                    out[ax._name + '.range[0]'] = out[ax2._name + '.range[0]'];\n                    out[ax._name + '.range[1]'] = out[ax2._name + '.range[1]'];\n                } else {\n                    ax.range = ax2.range.slice();\n                }\n            }\n        }\n    }\n\n    // Draw ticks and annotations (and other components) when ranges change.\n    // Also records the ranges that have changed for use by update at the end.\n    function ticksAndAnnotations() {\n        var activeAxIds = [];\n        var i;\n\n        function pushActiveAxIds(axList) {\n            for(i = 0; i < axList.length; i++) {\n                if(!axList[i].fixedrange) activeAxIds.push(axList[i]._id);\n            }\n        }\n\n        if(editX) {\n            pushActiveAxIds(xaxes);\n            pushActiveAxIds(links.xaxes);\n            pushActiveAxIds(matches.xaxes);\n        }\n        if(editY) {\n            pushActiveAxIds(yaxes);\n            pushActiveAxIds(links.yaxes);\n            pushActiveAxIds(matches.yaxes);\n        }\n\n        updates = {};\n        for(i = 0; i < activeAxIds.length; i++) {\n            var axId = activeAxIds[i];\n            var ax = getFromId(gd, axId);\n            Axes.drawOne(gd, ax, {skipTitle: true});\n            updates[ax._name + '.range[0]'] = ax.range[0];\n            updates[ax._name + '.range[1]'] = ax.range[1];\n        }\n\n        Axes.redrawComponents(gd, activeAxIds);\n    }\n\n    function doubleClick() {\n        if(gd._transitioningWithDuration) return;\n\n        var doubleClickConfig = gd._context.doubleClick;\n\n        var axList = [];\n        if(xActive) axList = axList.concat(xaxes);\n        if(yActive) axList = axList.concat(yaxes);\n        if(matches.xaxes) axList = axList.concat(matches.xaxes);\n        if(matches.yaxes) axList = axList.concat(matches.yaxes);\n\n        var attrs = {};\n        var ax, i, rangeInitial;\n\n        // For reset+autosize mode:\n        // If *any* of the main axes is not at its initial range\n        // (or autoranged, if we have no initial range, to match the logic in\n        // doubleClickConfig === 'reset' below), we reset.\n        // If they are *all* at their initial ranges, then we autosize.\n        if(doubleClickConfig === 'reset+autosize') {\n            doubleClickConfig = 'autosize';\n\n            for(i = 0; i < axList.length; i++) {\n                ax = axList[i];\n                if((ax._rangeInitial && (\n                        ax.range[0] !== ax._rangeInitial[0] ||\n                        ax.range[1] !== ax._rangeInitial[1]\n                    )) ||\n                    (!ax._rangeInitial && !ax.autorange)\n                ) {\n                    doubleClickConfig = 'reset';\n                    break;\n                }\n            }\n        }\n\n        if(doubleClickConfig === 'autosize') {\n            // don't set the linked axes here, so relayout marks them as shrinkable\n            // and we autosize just to the requested axis/axes\n            for(i = 0; i < axList.length; i++) {\n                ax = axList[i];\n                if(!ax.fixedrange) attrs[ax._name + '.autorange'] = true;\n            }\n        } else if(doubleClickConfig === 'reset') {\n            // when we're resetting, reset all linked axes too, so we get back\n            // to the fully-auto-with-constraints situation\n            if(xActive || links.isSubplotConstrained) axList = axList.concat(links.xaxes);\n            if(yActive && !links.isSubplotConstrained) axList = axList.concat(links.yaxes);\n\n            if(links.isSubplotConstrained) {\n                if(!xActive) axList = axList.concat(xaxes);\n                else if(!yActive) axList = axList.concat(yaxes);\n            }\n\n            for(i = 0; i < axList.length; i++) {\n                ax = axList[i];\n\n                if(!ax.fixedrange) {\n                    if(!ax._rangeInitial) {\n                        attrs[ax._name + '.autorange'] = true;\n                    } else {\n                        rangeInitial = ax._rangeInitial;\n                        attrs[ax._name + '.range[0]'] = rangeInitial[0];\n                        attrs[ax._name + '.range[1]'] = rangeInitial[1];\n                    }\n                }\n            }\n        }\n\n        gd.emit('plotly_doubleclick', null);\n        Registry.call('_guiRelayout', gd, attrs);\n    }\n\n    // dragTail - finish a drag event with a redraw\n    function dragTail() {\n        // put the subplot viewboxes back to default (Because we're going to)\n        // be repositioning the data in the relayout. But DON'T call\n        // ticksAndAnnotations again - it's unnecessary and would overwrite `updates`\n        updateSubplots([0, 0, pw, ph]);\n\n        // since we may have been redrawing some things during the drag, we may have\n        // accumulated MathJax promises - wait for them before we relayout.\n        Lib.syncOrAsync([\n            Plots.previousPromises,\n            function() {\n                gd._fullLayout._replotting = false;\n                Registry.call('_guiRelayout', gd, updates);\n            }\n        ], gd);\n    }\n\n    // updateSubplots - find all plot viewboxes that should be\n    // affected by this drag, and update them. look for all plots\n    // sharing an affected axis (including the one being dragged),\n    // includes also scattergl and splom logic.\n    function updateSubplots(viewBox) {\n        var fullLayout = gd._fullLayout;\n        var plotinfos = fullLayout._plots;\n        var subplots = fullLayout._subplots.cartesian;\n        var i, sp, xa, ya;\n\n        if(hasSplom) {\n            Registry.subplotsRegistry.splom.drag(gd);\n        }\n\n        if(hasScatterGl) {\n            for(i = 0; i < subplots.length; i++) {\n                sp = plotinfos[subplots[i]];\n                xa = sp.xaxis;\n                ya = sp.yaxis;\n\n                if(sp._scene) {\n                    var xrng = Lib.simpleMap(xa.range, xa.r2l);\n                    var yrng = Lib.simpleMap(ya.range, ya.r2l);\n                    sp._scene.update({range: [xrng[0], yrng[0], xrng[1], yrng[1]]});\n                }\n            }\n        }\n\n        if(hasSplom || hasScatterGl) {\n            clearGlCanvases(gd);\n            redrawReglTraces(gd);\n        }\n\n        if(hasSVG) {\n            var xScaleFactor = viewBox[2] / xa0._length;\n            var yScaleFactor = viewBox[3] / ya0._length;\n\n            for(i = 0; i < subplots.length; i++) {\n                sp = plotinfos[subplots[i]];\n                xa = sp.xaxis;\n                ya = sp.yaxis;\n\n                var editX2 = editX && !xa.fixedrange && xaHash[xa._id];\n                var editY2 = editY && !ya.fixedrange && yaHash[ya._id];\n\n                var xScaleFactor2, yScaleFactor2;\n                var clipDx, clipDy;\n\n                if(editX2) {\n                    xScaleFactor2 = xScaleFactor;\n                    clipDx = ew ? viewBox[0] : getShift(xa, xScaleFactor2);\n                } else if(matches.xaHash[xa._id]) {\n                    xScaleFactor2 = xScaleFactor;\n                    clipDx = viewBox[0] * xa._length / xa0._length;\n                } else if(matches.yaHash[xa._id]) {\n                    xScaleFactor2 = yScaleFactor;\n                    clipDx = yActive === 'ns' ?\n                        -viewBox[1] * xa._length / ya0._length :\n                        getShift(xa, xScaleFactor2, {n: 'top', s: 'bottom'}[yActive]);\n                } else {\n                    xScaleFactor2 = getLinkedScaleFactor(xa, xScaleFactor, yScaleFactor);\n                    clipDx = scaleAndGetShift(xa, xScaleFactor2);\n                }\n\n                if(editY2) {\n                    yScaleFactor2 = yScaleFactor;\n                    clipDy = ns ? viewBox[1] : getShift(ya, yScaleFactor2);\n                } else if(matches.yaHash[ya._id]) {\n                    yScaleFactor2 = yScaleFactor;\n                    clipDy = viewBox[1] * ya._length / ya0._length;\n                } else if(matches.xaHash[ya._id]) {\n                    yScaleFactor2 = xScaleFactor;\n                    clipDy = xActive === 'ew' ?\n                        -viewBox[0] * ya._length / xa0._length :\n                        getShift(ya, yScaleFactor2, {e: 'right', w: 'left'}[xActive]);\n                } else {\n                    yScaleFactor2 = getLinkedScaleFactor(ya, xScaleFactor, yScaleFactor);\n                    clipDy = scaleAndGetShift(ya, yScaleFactor2);\n                }\n\n                // don't scale at all if neither axis is scalable here\n                if(!xScaleFactor2 && !yScaleFactor2) {\n                    continue;\n                }\n\n                // but if only one is, reset the other axis scaling\n                if(!xScaleFactor2) xScaleFactor2 = 1;\n                if(!yScaleFactor2) yScaleFactor2 = 1;\n\n                var plotDx = xa._offset - clipDx / xScaleFactor2;\n                var plotDy = ya._offset - clipDy / yScaleFactor2;\n\n                // TODO could be more efficient here:\n                // setTranslate and setScale do a lot of extra work\n                // when working independently, should perhaps combine\n                // them into a single routine.\n                sp.clipRect\n                    .call(Drawing.setTranslate, clipDx, clipDy)\n                    .call(Drawing.setScale, xScaleFactor2, yScaleFactor2);\n\n                sp.plot\n                    .call(Drawing.setTranslate, plotDx, plotDy)\n                    .call(Drawing.setScale, 1 / xScaleFactor2, 1 / yScaleFactor2);\n\n                // apply an inverse scale to individual points to counteract\n                // the scale of the trace group.\n                // apply only when scale changes, as adjusting the scale of\n                // all the points can be expansive.\n                if(xScaleFactor2 !== sp.xScaleFactor || yScaleFactor2 !== sp.yScaleFactor) {\n                    Drawing.setPointGroupScale(sp.zoomScalePts, xScaleFactor2, yScaleFactor2);\n                    Drawing.setTextPointsScale(sp.zoomScaleTxt, xScaleFactor2, yScaleFactor2);\n                }\n\n                Drawing.hideOutsideRangePoints(sp.clipOnAxisFalseTraces, sp);\n\n                // update x/y scaleFactor stash\n                sp.xScaleFactor = xScaleFactor2;\n                sp.yScaleFactor = yScaleFactor2;\n            }\n        }\n    }\n\n    // Find the appropriate scaling for this axis, if it's linked to the\n    // dragged axes by constraints. 0 is special, it means this axis shouldn't\n    // ever be scaled (will be converted to 1 if the other axis is scaled)\n    function getLinkedScaleFactor(ax, xScaleFactor, yScaleFactor) {\n        if(ax.fixedrange) return 0;\n\n        if(editX && links.xaHash[ax._id]) {\n            return xScaleFactor;\n        }\n        if(editY && (links.isSubplotConstrained ? links.xaHash : links.yaHash)[ax._id]) {\n            return yScaleFactor;\n        }\n        return 0;\n    }\n\n    function scaleAndGetShift(ax, scaleFactor) {\n        if(scaleFactor) {\n            ax.range = ax._r.slice();\n            scaleZoom(ax, scaleFactor);\n            return getShift(ax, scaleFactor);\n        }\n        return 0;\n    }\n\n    function getShift(ax, scaleFactor, from) {\n        return ax._length * (1 - scaleFactor) * FROM_TL[from || ax.constraintoward || 'middle'];\n    }\n\n    return dragger;\n}\n\nfunction makeDragger(plotinfo, nodeName, dragClass, cursor) {\n    var dragger3 = Lib.ensureSingle(plotinfo.draglayer, nodeName, dragClass, function(s) {\n        s.classed('drag', true)\n            .style({fill: 'transparent', 'stroke-width': 0})\n            .attr('data-subplot', plotinfo.id);\n    });\n\n    dragger3.call(setCursor, cursor);\n\n    return dragger3.node();\n}\n\nfunction makeRectDragger(plotinfo, dragClass, cursor, x, y, w, h) {\n    var dragger = makeDragger(plotinfo, 'rect', dragClass, cursor);\n    d3.select(dragger).call(Drawing.setRect, x, y, w, h);\n    return dragger;\n}\n\nfunction isDirectionActive(axList, activeVal) {\n    for(var i = 0; i < axList.length; i++) {\n        if(!axList[i].fixedrange) return activeVal;\n    }\n    return '';\n}\n\nfunction getEndText(ax, end) {\n    var initialVal = ax.range[end];\n    var diff = Math.abs(initialVal - ax.range[1 - end]);\n    var dig;\n\n    // TODO: this should basically be ax.r2d but we're doing extra\n    // rounding here... can we clean up at all?\n    if(ax.type === 'date') {\n        return initialVal;\n    } else if(ax.type === 'log') {\n        dig = Math.ceil(Math.max(0, -Math.log(diff) / Math.LN10)) + 3;\n        return d3.format('.' + dig + 'g')(Math.pow(10, initialVal));\n    } else { // linear numeric (or category... but just show numbers here)\n        dig = Math.floor(Math.log(Math.abs(initialVal)) / Math.LN10) -\n            Math.floor(Math.log(diff) / Math.LN10) + 4;\n        return d3.format('.' + String(dig) + 'g')(initialVal);\n    }\n}\n\nfunction zoomAxRanges(axList, r0Fraction, r1Fraction, updates, linkedAxes) {\n    for(var i = 0; i < axList.length; i++) {\n        var axi = axList[i];\n        if(axi.fixedrange) continue;\n\n        var axRangeLinear0 = axi._rl[0];\n        var axRangeLinearSpan = axi._rl[1] - axRangeLinear0;\n        updates[axi._name + '.range[0]'] = axi.l2r(axRangeLinear0 + axRangeLinearSpan * r0Fraction);\n        updates[axi._name + '.range[1]'] = axi.l2r(axRangeLinear0 + axRangeLinearSpan * r1Fraction);\n    }\n\n    // zoom linked axes about their centers\n    if(linkedAxes && linkedAxes.length) {\n        var linkedR0Fraction = (r0Fraction + (1 - r1Fraction)) / 2;\n        zoomAxRanges(linkedAxes, linkedR0Fraction, 1 - linkedR0Fraction, updates, []);\n    }\n}\n\nfunction dragAxList(axList, pix) {\n    for(var i = 0; i < axList.length; i++) {\n        var axi = axList[i];\n        if(!axi.fixedrange) {\n            axi.range = [\n                axi.l2r(axi._rl[0] - pix / axi._m),\n                axi.l2r(axi._rl[1] - pix / axi._m)\n            ];\n        }\n    }\n}\n\n// common transform for dragging one end of an axis\n// d>0 is compressing scale (cursor is over the plot,\n//  the axis end should move with the cursor)\n// d<0 is expanding (cursor is off the plot, axis end moves\n//  nonlinearly so you can expand far)\nfunction dZoom(d) {\n    return 1 - ((d >= 0) ? Math.min(d, 0.9) :\n        1 / (1 / Math.max(d, -0.3) + 3.222));\n}\n\nfunction getDragCursor(nsew, dragmode, isMainDrag) {\n    if(!nsew) return 'pointer';\n    if(nsew === 'nsew') {\n        // in this case here, clear cursor and\n        // use the cursor style set on <g .draglayer>\n        if(isMainDrag) return '';\n        if(dragmode === 'pan') return 'move';\n        return 'crosshair';\n    }\n    return nsew.toLowerCase() + '-resize';\n}\n\nfunction makeZoombox(zoomlayer, lum, xs, ys, path0) {\n    return zoomlayer.append('path')\n        .attr('class', 'zoombox')\n        .style({\n            'fill': lum > 0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)',\n            'stroke-width': 0\n        })\n        .attr('transform', 'translate(' + xs + ', ' + ys + ')')\n        .attr('d', path0 + 'Z');\n}\n\nfunction makeCorners(zoomlayer, xs, ys) {\n    return zoomlayer.append('path')\n        .attr('class', 'zoombox-corners')\n        .style({\n            fill: Color.background,\n            stroke: Color.defaultLine,\n            'stroke-width': 1,\n            opacity: 0\n        })\n        .attr('transform', 'translate(' + xs + ', ' + ys + ')')\n        .attr('d', 'M0,0Z');\n}\n\nfunction updateZoombox(zb, corners, box, path0, dimmed, lum) {\n    zb.attr('d',\n        path0 + 'M' + (box.l) + ',' + (box.t) + 'v' + (box.h) +\n        'h' + (box.w) + 'v-' + (box.h) + 'h-' + (box.w) + 'Z');\n    transitionZoombox(zb, corners, dimmed, lum);\n}\n\nfunction transitionZoombox(zb, corners, dimmed, lum) {\n    if(!dimmed) {\n        zb.transition()\n            .style('fill', lum > 0.2 ? 'rgba(0,0,0,0.4)' :\n                'rgba(255,255,255,0.3)')\n            .duration(200);\n        corners.transition()\n            .style('opacity', 1)\n            .duration(200);\n    }\n}\n\nfunction removeZoombox(gd) {\n    d3.select(gd)\n        .selectAll('.zoombox,.js-zoombox-backdrop,.js-zoombox-menu,.zoombox-corners')\n        .remove();\n}\n\nfunction showDoubleClickNotifier(gd) {\n    if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {\n        Lib.notifier(Lib._(gd, 'Double-click to zoom back out'), 'long');\n        SHOWZOOMOUTTIP = false;\n    }\n}\n\nfunction isSelectOrLasso(dragmode) {\n    return dragmode === 'lasso' || dragmode === 'select';\n}\n\nfunction xCorners(box, y0) {\n    return 'M' +\n        (box.l - 0.5) + ',' + (y0 - MINZOOM - 0.5) +\n        'h-3v' + (2 * MINZOOM + 1) + 'h3ZM' +\n        (box.r + 0.5) + ',' + (y0 - MINZOOM - 0.5) +\n        'h3v' + (2 * MINZOOM + 1) + 'h-3Z';\n}\n\nfunction yCorners(box, x0) {\n    return 'M' +\n        (x0 - MINZOOM - 0.5) + ',' + (box.t - 0.5) +\n        'v-3h' + (2 * MINZOOM + 1) + 'v3ZM' +\n        (x0 - MINZOOM - 0.5) + ',' + (box.b + 0.5) +\n        'v3h' + (2 * MINZOOM + 1) + 'v-3Z';\n}\n\nfunction xyCorners(box) {\n    var clen = Math.floor(Math.min(box.b - box.t, box.r - box.l, MINZOOM) / 2);\n    return 'M' +\n        (box.l - 3.5) + ',' + (box.t - 0.5 + clen) + 'h3v' + (-clen) +\n            'h' + clen + 'v-3h-' + (clen + 3) + 'ZM' +\n        (box.r + 3.5) + ',' + (box.t - 0.5 + clen) + 'h-3v' + (-clen) +\n            'h' + (-clen) + 'v-3h' + (clen + 3) + 'ZM' +\n        (box.r + 3.5) + ',' + (box.b + 0.5 - clen) + 'h-3v' + clen +\n            'h' + (-clen) + 'v3h' + (clen + 3) + 'ZM' +\n        (box.l - 3.5) + ',' + (box.b + 0.5 - clen) + 'h3v' + clen +\n            'h' + clen + 'v3h-' + (clen + 3) + 'Z';\n}\n\nfunction calcLinks(gd, groups, xaHash, yaHash) {\n    var isSubplotConstrained = false;\n    var xLinks = {};\n    var yLinks = {};\n    var xID, yID, xLinkID, yLinkID;\n\n    for(var i = 0; i < groups.length; i++) {\n        var group = groups[i];\n        // check if any of the x axes we're dragging is in this constraint group\n        for(xID in xaHash) {\n            if(group[xID]) {\n                // put the rest of these axes into xLinks, if we're not already\n                // dragging them, so we know to scale these axes automatically too\n                // to match the changes in the dragged x axes\n                for(xLinkID in group) {\n                    if(!(xLinkID.charAt(0) === 'x' ? xaHash : yaHash)[xLinkID]) {\n                        xLinks[xLinkID] = xID;\n                    }\n                }\n\n                // check if the x and y axes of THIS drag are linked\n                for(yID in yaHash) {\n                    if(group[yID]) isSubplotConstrained = true;\n                }\n            }\n        }\n\n        // now check if any of the y axes we're dragging is in this constraint group\n        // only look for outside links, as we've already checked for links within the dragger\n        for(yID in yaHash) {\n            if(group[yID]) {\n                for(yLinkID in group) {\n                    if(!(yLinkID.charAt(0) === 'x' ? xaHash : yaHash)[yLinkID]) {\n                        yLinks[yLinkID] = yID;\n                    }\n                }\n            }\n        }\n    }\n\n    if(isSubplotConstrained) {\n        // merge xLinks and yLinks if the subplot is constrained,\n        // since we'll always apply both anyway and the two will contain\n        // duplicates\n        Lib.extendFlat(xLinks, yLinks);\n        yLinks = {};\n    }\n\n    var xaHashLinked = {};\n    var xaxesLinked = [];\n    for(xLinkID in xLinks) {\n        var xa = getFromId(gd, xLinkID);\n        xaxesLinked.push(xa);\n        xaHashLinked[xa._id] = xa;\n    }\n\n    var yaHashLinked = {};\n    var yaxesLinked = [];\n    for(yLinkID in yLinks) {\n        var ya = getFromId(gd, yLinkID);\n        yaxesLinked.push(ya);\n        yaHashLinked[ya._id] = ya;\n    }\n\n    return {\n        xaHash: xaHashLinked,\n        yaHash: yaHashLinked,\n        xaxes: xaxesLinked,\n        yaxes: yaxesLinked,\n        xLinks: xLinks,\n        yLinks: yLinks,\n        isSubplotConstrained: isSubplotConstrained\n    };\n}\n\n// still seems to be some confusion about onwheel vs onmousewheel...\nfunction attachWheelEventHandler(element, handler) {\n    if(!supportsPassive) {\n        if(element.onwheel !== undefined) element.onwheel = handler;\n        else if(element.onmousewheel !== undefined) element.onmousewheel = handler;\n    } else {\n        var wheelEventName = element.onwheel !== undefined ? 'wheel' : 'mousewheel';\n\n        if(element._onwheel) {\n            element.removeEventListener(wheelEventName, element._onwheel);\n        }\n        element._onwheel = handler;\n\n        element.addEventListener(wheelEventName, handler, {passive: false});\n    }\n}\n\nfunction hashValues(hash) {\n    var out = [];\n    for(var k in hash) out.push(hash[k]);\n    return out;\n}\n\nmodule.exports = {\n    makeDragBox: makeDragBox,\n\n    makeDragger: makeDragger,\n    makeRectDragger: makeRectDragger,\n    makeZoombox: makeZoombox,\n    makeCorners: makeCorners,\n\n    updateZoombox: updateZoombox,\n    xyCorners: xyCorners,\n    transitionZoombox: transitionZoombox,\n    removeZoombox: removeZoombox,\n    showDoubleClickNotifier: showDoubleClickNotifier,\n\n    attachWheelEventHandler: attachWheelEventHandler\n};\n\n},{\"../../components/color\":593,\"../../components/dragelement\":611,\"../../components/drawing\":614,\"../../components/fx\":632,\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/clear_gl_canvases\":704,\"../../lib/setcursor\":739,\"../../lib/svg_text_utils\":743,\"../../plot_api/subroutines\":758,\"../../registry\":847,\"../plots\":828,\"./axes\":767,\"./axis_ids\":770,\"./constants\":773,\"./scale_zoom\":783,\"./select\":784,\"d3\":163,\"has-passive-events\":411,\"tinycolor2\":537}],776:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Fx = _dereq_('../../components/fx');\nvar dragElement = _dereq_('../../components/dragelement');\nvar setCursor = _dereq_('../../lib/setcursor');\n\nvar makeDragBox = _dereq_('./dragbox').makeDragBox;\nvar DRAGGERSIZE = _dereq_('./constants').DRAGGERSIZE;\n\nexports.initInteractions = function initInteractions(gd) {\n    var fullLayout = gd._fullLayout;\n\n    if(gd._context.staticPlot) {\n        // this sweeps up more than just cartesian drag elements...\n        d3.select(gd).selectAll('.drag').remove();\n        return;\n    }\n\n    if(!fullLayout._has('cartesian') && !fullLayout._has('splom')) return;\n\n    var subplots = Object.keys(fullLayout._plots || {}).sort(function(a, b) {\n        // sort overlays last, then by x axis number, then y axis number\n        if((fullLayout._plots[a].mainplot && true) ===\n            (fullLayout._plots[b].mainplot && true)) {\n            var aParts = a.split('y');\n            var bParts = b.split('y');\n            return (aParts[0] === bParts[0]) ?\n                (Number(aParts[1] || 1) - Number(bParts[1] || 1)) :\n                (Number(aParts[0] || 1) - Number(bParts[0] || 1));\n        }\n        return fullLayout._plots[a].mainplot ? 1 : -1;\n    });\n\n    subplots.forEach(function(subplot) {\n        var plotinfo = fullLayout._plots[subplot];\n        var xa = plotinfo.xaxis;\n        var ya = plotinfo.yaxis;\n\n        // main and corner draggers need not be repeated for\n        // overlaid subplots - these draggers drag them all\n        if(!plotinfo.mainplot) {\n            // main dragger goes over the grids and data, so we use its\n            // mousemove events for all data hover effects\n            var maindrag = makeDragBox(gd, plotinfo, xa._offset, ya._offset,\n                xa._length, ya._length, 'ns', 'ew');\n\n            maindrag.onmousemove = function(evt) {\n                // This is on `gd._fullLayout`, *not* fullLayout because the reference\n                // changes by the time this is called again.\n                gd._fullLayout._rehover = function() {\n                    if(gd._fullLayout._hoversubplot === subplot) {\n                        Fx.hover(gd, evt, subplot);\n                    }\n                };\n\n                Fx.hover(gd, evt, subplot);\n\n                // Note that we have *not* used the cached fullLayout variable here\n                // since that may be outdated when this is called as a callback later on\n                gd._fullLayout._lasthover = maindrag;\n                gd._fullLayout._hoversubplot = subplot;\n            };\n\n            /*\n             * IMPORTANT:\n             * We must check for the presence of the drag cover here.\n             * If we don't, a 'mouseout' event is triggered on the\n             * maindrag before each 'click' event, which has the effect\n             * of clearing the hoverdata; thus, cancelling the click event.\n             */\n            maindrag.onmouseout = function(evt) {\n                if(gd._dragging) return;\n\n                // When the mouse leaves this maindrag, unset the hovered subplot.\n                // This may cause problems if it leaves the subplot directly *onto*\n                // another subplot, but that's a tiny corner case at the moment.\n                gd._fullLayout._hoversubplot = null;\n\n                dragElement.unhover(gd, evt);\n            };\n\n            // corner draggers\n            if(gd._context.showAxisDragHandles) {\n                makeDragBox(gd, plotinfo, xa._offset - DRAGGERSIZE, ya._offset - DRAGGERSIZE,\n                    DRAGGERSIZE, DRAGGERSIZE, 'n', 'w');\n                makeDragBox(gd, plotinfo, xa._offset + xa._length, ya._offset - DRAGGERSIZE,\n                    DRAGGERSIZE, DRAGGERSIZE, 'n', 'e');\n                makeDragBox(gd, plotinfo, xa._offset - DRAGGERSIZE, ya._offset + ya._length,\n                    DRAGGERSIZE, DRAGGERSIZE, 's', 'w');\n                makeDragBox(gd, plotinfo, xa._offset + xa._length, ya._offset + ya._length,\n                    DRAGGERSIZE, DRAGGERSIZE, 's', 'e');\n            }\n        }\n        if(gd._context.showAxisDragHandles) {\n            // x axis draggers - if you have overlaid plots,\n            // these drag each axis separately\n            if(subplot === xa._mainSubplot) {\n                // the y position of the main x axis line\n                var y0 = xa._mainLinePosition;\n                if(xa.side === 'top') y0 -= DRAGGERSIZE;\n                makeDragBox(gd, plotinfo, xa._offset + xa._length * 0.1, y0,\n                    xa._length * 0.8, DRAGGERSIZE, '', 'ew');\n                makeDragBox(gd, plotinfo, xa._offset, y0,\n                    xa._length * 0.1, DRAGGERSIZE, '', 'w');\n                makeDragBox(gd, plotinfo, xa._offset + xa._length * 0.9, y0,\n                    xa._length * 0.1, DRAGGERSIZE, '', 'e');\n            }\n            // y axis draggers\n            if(subplot === ya._mainSubplot) {\n                // the x position of the main y axis line\n                var x0 = ya._mainLinePosition;\n                if(ya.side !== 'right') x0 -= DRAGGERSIZE;\n                makeDragBox(gd, plotinfo, x0, ya._offset + ya._length * 0.1,\n                    DRAGGERSIZE, ya._length * 0.8, 'ns', '');\n                makeDragBox(gd, plotinfo, x0, ya._offset + ya._length * 0.9,\n                    DRAGGERSIZE, ya._length * 0.1, 's', '');\n                makeDragBox(gd, plotinfo, x0, ya._offset,\n                    DRAGGERSIZE, ya._length * 0.1, 'n', '');\n            }\n        }\n    });\n\n    // In case you mousemove over some hovertext, send it to Fx.hover too\n    // we do this so that we can put the hover text in front of everything,\n    // but still be able to interact with everything as if it isn't there\n    var hoverLayer = fullLayout._hoverlayer.node();\n\n    hoverLayer.onmousemove = function(evt) {\n        evt.target = gd._fullLayout._lasthover;\n        Fx.hover(gd, evt, fullLayout._hoversubplot);\n    };\n\n    hoverLayer.onclick = function(evt) {\n        evt.target = gd._fullLayout._lasthover;\n        Fx.click(gd, evt);\n    };\n\n    // also delegate mousedowns... TODO: does this actually work?\n    hoverLayer.onmousedown = function(evt) {\n        gd._fullLayout._lasthover.onmousedown(evt);\n    };\n\n    exports.updateFx(gd);\n};\n\n// Minimal set of update needed on 'modebar' edits.\n// We only need to update the <g .draglayer> cursor style.\n//\n// Note that changing the axis configuration and/or the fixedrange attribute\n// should trigger a full initInteractions.\nexports.updateFx = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var cursor = fullLayout.dragmode === 'pan' ? 'move' : 'crosshair';\n    setCursor(fullLayout._draggers, cursor);\n};\n\n},{\"../../components/dragelement\":611,\"../../components/fx\":632,\"../../lib/setcursor\":739,\"./constants\":773,\"./dragbox\":775,\"d3\":163}],777:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\n\n/**\n * Factory function for checking component arrays for subplot references.\n *\n * @param {string} containerArrayName: the top-level array in gd.layout to check\n *   If an item in this container is found that references a cartesian x and/or y axis,\n *   ensure cartesian is marked as a base plot module and record the axes (and subplot\n *   if both refs are axes) in gd._fullLayout\n *\n * @return {function}: with args layoutIn (gd.layout) and layoutOut (gd._fullLayout)\n * as expected of a component includeBasePlot method\n */\nmodule.exports = function makeIncludeComponents(containerArrayName) {\n    return function includeComponents(layoutIn, layoutOut) {\n        var array = layoutIn[containerArrayName];\n        if(!Array.isArray(array)) return;\n\n        var Cartesian = Registry.subplotsRegistry.cartesian;\n        var idRegex = Cartesian.idRegex;\n        var subplots = layoutOut._subplots;\n        var xaList = subplots.xaxis;\n        var yaList = subplots.yaxis;\n        var cartesianList = subplots.cartesian;\n        var hasCartesianOrGL2D = layoutOut._has('cartesian') || layoutOut._has('gl2d');\n\n        for(var i = 0; i < array.length; i++) {\n            var itemi = array[i];\n            if(!Lib.isPlainObject(itemi)) continue;\n\n            var xref = itemi.xref;\n            var yref = itemi.yref;\n\n            var hasXref = idRegex.x.test(xref);\n            var hasYref = idRegex.y.test(yref);\n            if(hasXref || hasYref) {\n                if(!hasCartesianOrGL2D) Lib.pushUnique(layoutOut._basePlotModules, Cartesian);\n\n                var newAxis = false;\n                if(hasXref && xaList.indexOf(xref) === -1) {\n                    xaList.push(xref);\n                    newAxis = true;\n                }\n                if(hasYref && yaList.indexOf(yref) === -1) {\n                    yaList.push(yref);\n                    newAxis = true;\n                }\n\n                /*\n                 * Notice the logic here: only add a subplot for a component if\n                 * it's referencing both x and y axes AND it's creating a new axis\n                 * so for example if your plot already has xy and x2y2, an annotation\n                 * on x2y or xy2 will not create a new subplot.\n                 */\n                if(newAxis && hasXref && hasYref) {\n                    cartesianList.push(xref + yref);\n                }\n            }\n        }\n    };\n};\n\n},{\"../../lib\":719,\"../../registry\":847}],778:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Plots = _dereq_('../plots');\nvar Drawing = _dereq_('../../components/drawing');\n\nvar getModuleCalcData = _dereq_('../get_data').getModuleCalcData;\nvar axisIds = _dereq_('./axis_ids');\nvar constants = _dereq_('./constants');\nvar xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');\n\nvar ensureSingle = Lib.ensureSingle;\n\nfunction ensureSingleAndAddDatum(parent, nodeType, className) {\n    return Lib.ensureSingle(parent, nodeType, className, function(s) {\n        s.datum(className);\n    });\n}\n\nexports.name = 'cartesian';\n\nexports.attr = ['xaxis', 'yaxis'];\n\nexports.idRoot = ['x', 'y'];\n\nexports.idRegex = constants.idRegex;\n\nexports.attrRegex = constants.attrRegex;\n\nexports.attributes = _dereq_('./attributes');\n\nexports.layoutAttributes = _dereq_('./layout_attributes');\n\nexports.supplyLayoutDefaults = _dereq_('./layout_defaults');\n\nexports.transitionAxes = _dereq_('./transition_axes');\n\nexports.finalizeSubplots = function(layoutIn, layoutOut) {\n    var subplots = layoutOut._subplots;\n    var xList = subplots.xaxis;\n    var yList = subplots.yaxis;\n    var spSVG = subplots.cartesian;\n    var spAll = spSVG.concat(subplots.gl2d || []);\n    var allX = {};\n    var allY = {};\n    var i, xi, yi;\n\n    for(i = 0; i < spAll.length; i++) {\n        var parts = spAll[i].split('y');\n        allX[parts[0]] = 1;\n        allY['y' + parts[1]] = 1;\n    }\n\n    // check for x axes with no subplot, and make one from the anchor of that x axis\n    for(i = 0; i < xList.length; i++) {\n        xi = xList[i];\n        if(!allX[xi]) {\n            yi = (layoutIn[axisIds.id2name(xi)] || {}).anchor;\n            if(!constants.idRegex.y.test(yi)) yi = 'y';\n            spSVG.push(xi + yi);\n            spAll.push(xi + yi);\n\n            if(!allY[yi]) {\n                allY[yi] = 1;\n                Lib.pushUnique(yList, yi);\n            }\n        }\n    }\n\n    // same for y axes with no subplot\n    for(i = 0; i < yList.length; i++) {\n        yi = yList[i];\n        if(!allY[yi]) {\n            xi = (layoutIn[axisIds.id2name(yi)] || {}).anchor;\n            if(!constants.idRegex.x.test(xi)) xi = 'x';\n            spSVG.push(xi + yi);\n            spAll.push(xi + yi);\n\n            if(!allX[xi]) {\n                allX[xi] = 1;\n                Lib.pushUnique(xList, xi);\n            }\n        }\n    }\n\n    // finally, if we've gotten here we're supposed to show cartesian...\n    // so if there are NO subplots at all, make one from the first\n    // x & y axes in the input layout\n    if(!spAll.length) {\n        xi = '';\n        yi = '';\n        for(var ki in layoutIn) {\n            if(constants.attrRegex.test(ki)) {\n                var axLetter = ki.charAt(0);\n                if(axLetter === 'x') {\n                    if(!xi || (+ki.substr(5) < +xi.substr(5))) {\n                        xi = ki;\n                    }\n                } else if(!yi || (+ki.substr(5) < +yi.substr(5))) {\n                    yi = ki;\n                }\n            }\n        }\n        xi = xi ? axisIds.name2id(xi) : 'x';\n        yi = yi ? axisIds.name2id(yi) : 'y';\n        xList.push(xi);\n        yList.push(yi);\n        spSVG.push(xi + yi);\n    }\n};\n\n/**\n * Cartesian.plot\n *\n * @param {DOM div | object} gd\n * @param {array (optional)} traces\n *  array of traces indices to plot\n *  if undefined, plots all cartesian traces,\n * @param {object} (optional) transitionOpts\n *  transition option object\n * @param {function} (optional) makeOnCompleteCallback\n *  transition make callback function from Plots.transition\n */\nexports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {\n    var fullLayout = gd._fullLayout;\n    var subplots = fullLayout._subplots.cartesian;\n    var calcdata = gd.calcdata;\n    var i;\n\n    if(!Array.isArray(traces)) {\n        // If traces is not provided, then it's a complete replot and missing\n        // traces are removed\n        traces = [];\n        for(i = 0; i < calcdata.length; i++) traces.push(i);\n    }\n\n    for(i = 0; i < subplots.length; i++) {\n        var subplot = subplots[i];\n        var subplotInfo = fullLayout._plots[subplot];\n\n        // Get all calcdata for this subplot:\n        var cdSubplot = [];\n        var pcd;\n\n        for(var j = 0; j < calcdata.length; j++) {\n            var cd = calcdata[j];\n            var trace = cd[0].trace;\n\n            // Skip trace if whitelist provided and it's not whitelisted:\n            // if (Array.isArray(traces) && traces.indexOf(i) === -1) continue;\n            if(trace.xaxis + trace.yaxis === subplot) {\n                // XXX: Should trace carpet dependencies. Only replot all carpet plots if the carpet\n                // axis has actually changed:\n                //\n                // If this trace is specifically requested, add it to the list:\n                if(traces.indexOf(trace.index) !== -1 || trace.carpet) {\n                    // Okay, so example: traces 0, 1, and 2 have fill = tonext. You animate\n                    // traces 0 and 2. Trace 1 also needs to be updated, otherwise its fill\n                    // is outdated. So this retroactively adds the previous trace if the\n                    // traces are interdependent.\n                    if(\n                        pcd &&\n                        pcd[0].trace.xaxis + pcd[0].trace.yaxis === subplot &&\n                        ['tonextx', 'tonexty', 'tonext'].indexOf(trace.fill) !== -1 &&\n                        cdSubplot.indexOf(pcd) === -1\n                    ) {\n                        cdSubplot.push(pcd);\n                    }\n\n                    cdSubplot.push(cd);\n                }\n\n                // Track the previous trace on this subplot for the retroactive-add step\n                // above:\n                pcd = cd;\n            }\n        }\n\n        plotOne(gd, subplotInfo, cdSubplot, transitionOpts, makeOnCompleteCallback);\n    }\n};\n\nfunction plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback) {\n    var traceLayerClasses = constants.traceLayerClasses;\n    var fullLayout = gd._fullLayout;\n    var modules = fullLayout._modules;\n    var _module, cdModuleAndOthers, cdModule;\n\n    var layerData = [];\n    var zoomScaleQueryParts = [];\n\n    for(var i = 0; i < modules.length; i++) {\n        _module = modules[i];\n        var name = _module.name;\n        var categories = Registry.modules[name].categories;\n\n        if(categories.svg) {\n            var className = (_module.layerName || name + 'layer');\n            var plotMethod = _module.plot;\n\n            // plot all visible traces of this type on this subplot at once\n            cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod);\n            cdModule = cdModuleAndOthers[0];\n            // don't need to search the found traces again - in fact we need to NOT\n            // so that if two modules share the same plotter we don't double-plot\n            cdSubplot = cdModuleAndOthers[1];\n\n            if(cdModule.length) {\n                layerData.push({\n                    i: traceLayerClasses.indexOf(className),\n                    className: className,\n                    plotMethod: plotMethod,\n                    cdModule: cdModule\n                });\n            }\n\n            if(categories.zoomScale) {\n                zoomScaleQueryParts.push('.' + className);\n            }\n        }\n    }\n\n    layerData.sort(function(a, b) { return a.i - b.i; });\n\n    var layers = plotinfo.plot.selectAll('g.mlayer')\n        .data(layerData, function(d) { return d.className; });\n\n    layers.enter().append('g')\n        .attr('class', function(d) { return d.className; })\n        .classed('mlayer', true)\n        .classed('rangeplot', plotinfo.isRangePlot);\n\n    layers.exit().remove();\n\n    layers.order();\n\n    layers.each(function(d) {\n        var sel = d3.select(this);\n        var className = d.className;\n\n        d.plotMethod(\n            gd, plotinfo, d.cdModule, sel,\n            transitionOpts, makeOnCompleteCallback\n        );\n\n        // layers that allow `cliponaxis: false`\n        if(constants.clipOnAxisFalseQuery.indexOf('.' + className) === -1) {\n            Drawing.setClipUrl(sel, plotinfo.layerClipId, gd);\n        }\n    });\n\n    // call Scattergl.plot separately\n    if(fullLayout._has('scattergl')) {\n        _module = Registry.getModule('scattergl');\n        cdModule = getModuleCalcData(cdSubplot, _module)[0];\n        _module.plot(gd, plotinfo, cdModule);\n    }\n\n    // stash \"hot\" selections for faster interaction on drag and scroll\n    if(!gd._context.staticPlot) {\n        if(plotinfo._hasClipOnAxisFalse) {\n            plotinfo.clipOnAxisFalseTraces = plotinfo.plot\n                .selectAll(constants.clipOnAxisFalseQuery.join(','))\n                .selectAll('.trace');\n        }\n\n        if(zoomScaleQueryParts.length) {\n            var traces = plotinfo.plot\n                .selectAll(zoomScaleQueryParts.join(','))\n                .selectAll('.trace');\n\n            plotinfo.zoomScalePts = traces.selectAll('path.point');\n            plotinfo.zoomScaleTxt = traces.selectAll('.textpoint');\n        }\n    }\n}\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var oldPlots = oldFullLayout._plots || {};\n    var newPlots = newFullLayout._plots || {};\n    var oldSubplotList = oldFullLayout._subplots || {};\n    var plotinfo;\n    var i, k;\n\n    // when going from a large splom graph to something else,\n    // we need to clear <g subplot> so that the new cartesian subplot\n    // can have the correct layer ordering\n    if(oldFullLayout._hasOnlyLargeSploms && !newFullLayout._hasOnlyLargeSploms) {\n        for(k in oldPlots) {\n            plotinfo = oldPlots[k];\n            if(plotinfo.plotgroup) plotinfo.plotgroup.remove();\n        }\n    }\n\n    var hadGl = (oldFullLayout._has && oldFullLayout._has('gl'));\n    var hasGl = (newFullLayout._has && newFullLayout._has('gl'));\n\n    if(hadGl && !hasGl) {\n        for(k in oldPlots) {\n            plotinfo = oldPlots[k];\n            if(plotinfo._scene) plotinfo._scene.destroy();\n        }\n    }\n\n    // delete any titles we don't need anymore\n    // check if axis list has changed, and if so clear old titles\n    if(oldSubplotList.xaxis && oldSubplotList.yaxis) {\n        var oldAxIDs = axisIds.listIds({_fullLayout: oldFullLayout});\n        for(i = 0; i < oldAxIDs.length; i++) {\n            var oldAxId = oldAxIDs[i];\n            if(!newFullLayout[axisIds.id2name(oldAxId)]) {\n                oldFullLayout._infolayer.selectAll('.g-' + oldAxId + 'title').remove();\n            }\n        }\n    }\n\n    var hadCartesian = (oldFullLayout._has && oldFullLayout._has('cartesian'));\n    var hasCartesian = (newFullLayout._has && newFullLayout._has('cartesian'));\n\n    if(hadCartesian && !hasCartesian) {\n        // if we've gotten rid of all cartesian traces, remove all the subplot svg items\n\n        purgeSubplotLayers(oldFullLayout._cartesianlayer.selectAll('.subplot'), oldFullLayout);\n        oldFullLayout._defs.selectAll('.axesclip').remove();\n        delete oldFullLayout._axisConstraintGroups;\n    } else if(oldSubplotList.cartesian) {\n        // otherwise look for subplots we need to remove\n\n        for(i = 0; i < oldSubplotList.cartesian.length; i++) {\n            var oldSubplotId = oldSubplotList.cartesian[i];\n            if(!newPlots[oldSubplotId]) {\n                var selector = '.' + oldSubplotId + ',.' + oldSubplotId + '-x,.' + oldSubplotId + '-y';\n                oldFullLayout._cartesianlayer.selectAll(selector).remove();\n                removeSubplotExtras(oldSubplotId, oldFullLayout);\n            }\n        }\n    }\n};\n\nexports.drawFramework = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var subplotData = makeSubplotData(gd);\n\n    var subplotLayers = fullLayout._cartesianlayer.selectAll('.subplot')\n        .data(subplotData, String);\n\n    subplotLayers.enter().append('g')\n        .attr('class', function(d) { return 'subplot ' + d[0]; });\n\n    subplotLayers.order();\n\n    subplotLayers.exit()\n        .call(purgeSubplotLayers, fullLayout);\n\n    subplotLayers.each(function(d) {\n        var id = d[0];\n        var plotinfo = fullLayout._plots[id];\n\n        plotinfo.plotgroup = d3.select(this);\n        makeSubplotLayer(gd, plotinfo);\n\n        // make separate drag layers for each subplot,\n        // but append them to paper rather than the plot groups,\n        // so they end up on top of the rest\n        plotinfo.draglayer = ensureSingle(fullLayout._draggers, 'g', id);\n    });\n};\n\nexports.rangePlot = function(gd, plotinfo, cdSubplot) {\n    makeSubplotLayer(gd, plotinfo);\n    plotOne(gd, plotinfo, cdSubplot);\n    Plots.style(gd);\n};\n\nfunction makeSubplotData(gd) {\n    var fullLayout = gd._fullLayout;\n    var ids = fullLayout._subplots.cartesian;\n    var len = ids.length;\n    var i, j, id, plotinfo, xa, ya;\n\n    // split 'regular' and 'overlaying' subplots\n    var regulars = [];\n    var overlays = [];\n\n    for(i = 0; i < len; i++) {\n        id = ids[i];\n        plotinfo = fullLayout._plots[id];\n        xa = plotinfo.xaxis;\n        ya = plotinfo.yaxis;\n\n        var xa2 = xa._mainAxis;\n        var ya2 = ya._mainAxis;\n        var mainplot = xa2._id + ya2._id;\n        var mainplotinfo = fullLayout._plots[mainplot];\n        plotinfo.overlays = [];\n\n        if(mainplot !== id && mainplotinfo) {\n            plotinfo.mainplot = mainplot;\n            plotinfo.mainplotinfo = mainplotinfo;\n            overlays.push(id);\n        } else {\n            plotinfo.mainplot = undefined;\n            plotinfo.mainPlotinfo = undefined;\n            regulars.push(id);\n        }\n    }\n\n    // fill in list of overlaying subplots in 'main plot'\n    for(i = 0; i < overlays.length; i++) {\n        id = overlays[i];\n        plotinfo = fullLayout._plots[id];\n        plotinfo.mainplotinfo.overlays.push(plotinfo);\n    }\n\n    // put 'regular' subplot data before 'overlaying'\n    var subplotIds = regulars.concat(overlays);\n    var subplotData = new Array(len);\n\n    for(i = 0; i < len; i++) {\n        id = subplotIds[i];\n        plotinfo = fullLayout._plots[id];\n        xa = plotinfo.xaxis;\n        ya = plotinfo.yaxis;\n\n        // use info about axis layer and overlaying pattern\n        // to clean what need to be cleaned up in exit selection\n        var d = [id, xa.layer, ya.layer, xa.overlaying || '', ya.overlaying || ''];\n        for(j = 0; j < plotinfo.overlays.length; j++) {\n            d.push(plotinfo.overlays[j].id);\n        }\n        subplotData[i] = d;\n    }\n\n    return subplotData;\n}\n\nfunction makeSubplotLayer(gd, plotinfo) {\n    var plotgroup = plotinfo.plotgroup;\n    var id = plotinfo.id;\n    var xLayer = constants.layerValue2layerClass[plotinfo.xaxis.layer];\n    var yLayer = constants.layerValue2layerClass[plotinfo.yaxis.layer];\n    var hasOnlyLargeSploms = gd._fullLayout._hasOnlyLargeSploms;\n\n    if(!plotinfo.mainplot) {\n        if(hasOnlyLargeSploms) {\n            // TODO could do even better\n            // - we don't need plot (but we would have to mock it in lsInner\n            //   and other places\n            // - we don't (x|y)lines and (x|y)axislayer for most subplots\n            //   usually just the bottom x and left y axes.\n            plotinfo.xlines = ensureSingle(plotgroup, 'path', 'xlines-above');\n            plotinfo.ylines = ensureSingle(plotgroup, 'path', 'ylines-above');\n            plotinfo.xaxislayer = ensureSingle(plotgroup, 'g', 'xaxislayer-above');\n            plotinfo.yaxislayer = ensureSingle(plotgroup, 'g', 'yaxislayer-above');\n        } else {\n            var backLayer = ensureSingle(plotgroup, 'g', 'layer-subplot');\n            plotinfo.shapelayer = ensureSingle(backLayer, 'g', 'shapelayer');\n            plotinfo.imagelayer = ensureSingle(backLayer, 'g', 'imagelayer');\n\n            plotinfo.gridlayer = ensureSingle(plotgroup, 'g', 'gridlayer');\n            plotinfo.zerolinelayer = ensureSingle(plotgroup, 'g', 'zerolinelayer');\n\n            ensureSingle(plotgroup, 'path', 'xlines-below');\n            ensureSingle(plotgroup, 'path', 'ylines-below');\n            plotinfo.overlinesBelow = ensureSingle(plotgroup, 'g', 'overlines-below');\n\n            ensureSingle(plotgroup, 'g', 'xaxislayer-below');\n            ensureSingle(plotgroup, 'g', 'yaxislayer-below');\n            plotinfo.overaxesBelow = ensureSingle(plotgroup, 'g', 'overaxes-below');\n\n            plotinfo.plot = ensureSingle(plotgroup, 'g', 'plot');\n            plotinfo.overplot = ensureSingle(plotgroup, 'g', 'overplot');\n\n            plotinfo.xlines = ensureSingle(plotgroup, 'path', 'xlines-above');\n            plotinfo.ylines = ensureSingle(plotgroup, 'path', 'ylines-above');\n            plotinfo.overlinesAbove = ensureSingle(plotgroup, 'g', 'overlines-above');\n\n            ensureSingle(plotgroup, 'g', 'xaxislayer-above');\n            ensureSingle(plotgroup, 'g', 'yaxislayer-above');\n            plotinfo.overaxesAbove = ensureSingle(plotgroup, 'g', 'overaxes-above');\n\n            // set refs to correct layers as determined by 'axis.layer'\n            plotinfo.xlines = plotgroup.select('.xlines-' + xLayer);\n            plotinfo.ylines = plotgroup.select('.ylines-' + yLayer);\n            plotinfo.xaxislayer = plotgroup.select('.xaxislayer-' + xLayer);\n            plotinfo.yaxislayer = plotgroup.select('.yaxislayer-' + yLayer);\n        }\n    } else {\n        var mainplotinfo = plotinfo.mainplotinfo;\n        var mainplotgroup = mainplotinfo.plotgroup;\n        var xId = id + '-x';\n        var yId = id + '-y';\n\n        // now make the components of overlaid subplots\n        // overlays don't have backgrounds, and append all\n        // their other components to the corresponding\n        // extra groups of their main plots.\n\n        plotinfo.gridlayer = mainplotinfo.gridlayer;\n        plotinfo.zerolinelayer = mainplotinfo.zerolinelayer;\n\n        ensureSingle(mainplotinfo.overlinesBelow, 'path', xId);\n        ensureSingle(mainplotinfo.overlinesBelow, 'path', yId);\n        ensureSingle(mainplotinfo.overaxesBelow, 'g', xId);\n        ensureSingle(mainplotinfo.overaxesBelow, 'g', yId);\n\n        plotinfo.plot = ensureSingle(mainplotinfo.overplot, 'g', id);\n\n        ensureSingle(mainplotinfo.overlinesAbove, 'path', xId);\n        ensureSingle(mainplotinfo.overlinesAbove, 'path', yId);\n        ensureSingle(mainplotinfo.overaxesAbove, 'g', xId);\n        ensureSingle(mainplotinfo.overaxesAbove, 'g', yId);\n\n        // set refs to correct layers as determined by 'abovetraces'\n        plotinfo.xlines = mainplotgroup.select('.overlines-' + xLayer).select('.' + xId);\n        plotinfo.ylines = mainplotgroup.select('.overlines-' + yLayer).select('.' + yId);\n        plotinfo.xaxislayer = mainplotgroup.select('.overaxes-' + xLayer).select('.' + xId);\n        plotinfo.yaxislayer = mainplotgroup.select('.overaxes-' + yLayer).select('.' + yId);\n    }\n\n    // common attributes for all subplots, overlays or not\n\n    if(!hasOnlyLargeSploms) {\n        ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.xaxis._id);\n        ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.yaxis._id);\n        plotinfo.gridlayer.selectAll('g')\n            .map(function(d) { return d[0]; })\n            .sort(axisIds.idSort);\n    }\n\n    plotinfo.xlines\n        .style('fill', 'none')\n        .classed('crisp', true);\n\n    plotinfo.ylines\n        .style('fill', 'none')\n        .classed('crisp', true);\n}\n\nfunction purgeSubplotLayers(layers, fullLayout) {\n    if(!layers) return;\n\n    var overlayIdsToRemove = {};\n\n    layers.each(function(d) {\n        var id = d[0];\n        var plotgroup = d3.select(this);\n\n        plotgroup.remove();\n        removeSubplotExtras(id, fullLayout);\n        overlayIdsToRemove[id] = true;\n\n        // do not remove individual axis <clipPath>s here\n        // as other subplots may need them\n    });\n\n    // must remove overlaid subplot trace layers 'manually'\n\n    for(var k in fullLayout._plots) {\n        var subplotInfo = fullLayout._plots[k];\n        var overlays = subplotInfo.overlays || [];\n\n        for(var j = 0; j < overlays.length; j++) {\n            var overlayInfo = overlays[j];\n\n            if(overlayIdsToRemove[overlayInfo.id]) {\n                overlayInfo.plot.selectAll('.trace').remove();\n            }\n        }\n    }\n}\n\nfunction removeSubplotExtras(subplotId, fullLayout) {\n    fullLayout._draggers.selectAll('g.' + subplotId).remove();\n    fullLayout._defs.select('#clip' + fullLayout._uid + subplotId + 'plot').remove();\n}\n\nexports.toSVG = function(gd) {\n    var imageRoot = gd._fullLayout._glimages;\n    var root = d3.select(gd).selectAll('.svg-container');\n    var canvases = root.filter(function(d, i) {return i === root.size() - 1;})\n        .selectAll('.gl-canvas-context, .gl-canvas-focus');\n\n    function canvasToImage() {\n        var canvas = this;\n        var imageData = canvas.toDataURL('image/png');\n        var image = imageRoot.append('svg:image');\n\n        image.attr({\n            xmlns: xmlnsNamespaces.svg,\n            'xlink:href': imageData,\n            preserveAspectRatio: 'none',\n            x: 0,\n            y: 0,\n            width: canvas.width,\n            height: canvas.height\n        });\n    }\n\n    canvases.each(canvasToImage);\n};\n\nexports.updateFx = _dereq_('./graph_interact').updateFx;\n\n},{\"../../components/drawing\":614,\"../../constants/xmlns_namespaces\":696,\"../../lib\":719,\"../../registry\":847,\"../get_data\":802,\"../plots\":828,\"./attributes\":765,\"./axis_ids\":770,\"./constants\":773,\"./graph_interact\":776,\"./layout_attributes\":779,\"./layout_defaults\":780,\"./transition_axes\":789,\"d3\":163}],779:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../font_attributes');\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar dash = _dereq_('../../components/drawing/attributes').dash;\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\nvar FORMAT_LINK = _dereq_('../../constants/docs').FORMAT_LINK;\nvar DATE_FORMAT_LINK = _dereq_('../../constants/docs').DATE_FORMAT_LINK;\n\nvar constants = _dereq_('./constants');\n\nmodule.exports = {\n    visible: {\n        valType: 'boolean',\n        \n        editType: 'plot',\n        \n    },\n    color: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'ticks',\n        \n    },\n    title: {\n        text: {\n            valType: 'string',\n            \n            editType: 'ticks',\n            \n        },\n        font: fontAttrs({\n            editType: 'ticks',\n            \n        }),\n        editType: 'ticks'\n    },\n    type: {\n        valType: 'enumerated',\n        // '-' means we haven't yet run autotype or couldn't find any data\n        // it gets turned into linear in gd._fullLayout but not copied back\n        // to gd.data like the others are.\n        values: ['-', 'linear', 'log', 'date', 'category', 'multicategory'],\n        dflt: '-',\n        \n        editType: 'calc',\n        // we forget when an axis has been autotyped, just writing the auto\n        // value back to the input - so it doesn't make sense to template this.\n        // Note: we do NOT prohibit this in `coerce`, so if someone enters a\n        // type in the template explicitly it will be honored as the default.\n        _noTemplating: true,\n        \n    },\n    autorange: {\n        valType: 'enumerated',\n        values: [true, false, 'reversed'],\n        dflt: true,\n        \n        editType: 'axrange',\n        impliedEdits: {'range[0]': undefined, 'range[1]': undefined},\n        \n    },\n    rangemode: {\n        valType: 'enumerated',\n        values: ['normal', 'tozero', 'nonnegative'],\n        dflt: 'normal',\n        \n        editType: 'plot',\n        \n    },\n    range: {\n        valType: 'info_array',\n        \n        items: [\n            {valType: 'any', editType: 'axrange', impliedEdits: {'^autorange': false}, anim: true},\n            {valType: 'any', editType: 'axrange', impliedEdits: {'^autorange': false}, anim: true}\n        ],\n        editType: 'axrange',\n        impliedEdits: {'autorange': false},\n        anim: true,\n        \n    },\n    fixedrange: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    // scaleanchor: not used directly, just put here for reference\n    // values are any opposite-letter axis id\n    scaleanchor: {\n        valType: 'enumerated',\n        values: [\n            constants.idRegex.x.toString(),\n            constants.idRegex.y.toString()\n        ],\n        \n        editType: 'plot',\n        \n    },\n    scaleratio: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'plot',\n        \n    },\n    constrain: {\n        valType: 'enumerated',\n        values: ['range', 'domain'],\n        dflt: 'range',\n        \n        editType: 'plot',\n        \n    },\n    // constraintoward: not used directly, just put here for reference\n    constraintoward: {\n        valType: 'enumerated',\n        values: ['left', 'center', 'right', 'top', 'middle', 'bottom'],\n        \n        editType: 'plot',\n        \n    },\n    matches: {\n        valType: 'enumerated',\n        values: [\n            constants.idRegex.x.toString(),\n            constants.idRegex.y.toString()\n        ],\n        \n        editType: 'calc',\n        \n    },\n    // ticks\n    tickmode: {\n        valType: 'enumerated',\n        values: ['auto', 'linear', 'array'],\n        \n        editType: 'ticks',\n        impliedEdits: {tick0: undefined, dtick: undefined},\n        \n    },\n    nticks: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'ticks',\n        \n    },\n    tick0: {\n        valType: 'any',\n        \n        editType: 'ticks',\n        impliedEdits: {tickmode: 'linear'},\n        \n    },\n    dtick: {\n        valType: 'any',\n        \n        editType: 'ticks',\n        impliedEdits: {tickmode: 'linear'},\n        \n    },\n    tickvals: {\n        valType: 'data_array',\n        editType: 'ticks',\n        \n    },\n    ticktext: {\n        valType: 'data_array',\n        editType: 'ticks',\n        \n    },\n    ticks: {\n        valType: 'enumerated',\n        values: ['outside', 'inside', ''],\n        \n        editType: 'ticks',\n        \n    },\n    tickson: {\n        valType: 'enumerated',\n        values: ['labels', 'boundaries'],\n        \n        dflt: 'labels',\n        editType: 'ticks',\n        \n    },\n    mirror: {\n        valType: 'enumerated',\n        values: [true, 'ticks', false, 'all', 'allticks'],\n        dflt: false,\n        \n        editType: 'ticks+layoutstyle',\n        \n    },\n    ticklen: {\n        valType: 'number',\n        min: 0,\n        dflt: 5,\n        \n        editType: 'ticks',\n        \n    },\n    tickwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'ticks',\n        \n    },\n    tickcolor: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'ticks',\n        \n    },\n    showticklabels: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'ticks',\n        \n    },\n    automargin: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'ticks',\n        \n    },\n    showspikes: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'modebar',\n        \n    },\n    spikecolor: {\n        valType: 'color',\n        dflt: null,\n        \n        editType: 'none',\n        \n    },\n    spikethickness: {\n        valType: 'number',\n        dflt: 3,\n        \n        editType: 'none',\n        \n    },\n    spikedash: extendFlat({}, dash, {dflt: 'dash', editType: 'none'}),\n    spikemode: {\n        valType: 'flaglist',\n        flags: ['toaxis', 'across', 'marker'],\n        \n        dflt: 'toaxis',\n        editType: 'none',\n        \n    },\n    spikesnap: {\n        valType: 'enumerated',\n        values: ['data', 'cursor'],\n        dflt: 'data',\n        \n        editType: 'none',\n        \n    },\n    tickfont: fontAttrs({\n        editType: 'ticks',\n        \n    }),\n    tickangle: {\n        valType: 'angle',\n        dflt: 'auto',\n        \n        editType: 'ticks',\n        \n    },\n    tickprefix: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'ticks',\n        \n    },\n    showtickprefix: {\n        valType: 'enumerated',\n        values: ['all', 'first', 'last', 'none'],\n        dflt: 'all',\n        \n        editType: 'ticks',\n        \n    },\n    ticksuffix: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'ticks',\n        \n    },\n    showticksuffix: {\n        valType: 'enumerated',\n        values: ['all', 'first', 'last', 'none'],\n        dflt: 'all',\n        \n        editType: 'ticks',\n        \n    },\n    showexponent: {\n        valType: 'enumerated',\n        values: ['all', 'first', 'last', 'none'],\n        dflt: 'all',\n        \n        editType: 'ticks',\n        \n    },\n    exponentformat: {\n        valType: 'enumerated',\n        values: ['none', 'e', 'E', 'power', 'SI', 'B'],\n        dflt: 'B',\n        \n        editType: 'ticks',\n        \n    },\n    separatethousands: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'ticks',\n        \n    },\n    tickformat: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'ticks',\n        \n    },\n    tickformatstops: templatedArray('tickformatstop', {\n        enabled: {\n            valType: 'boolean',\n            \n            dflt: true,\n            editType: 'ticks',\n            \n        },\n        dtickrange: {\n            valType: 'info_array',\n            \n            items: [\n                {valType: 'any', editType: 'ticks'},\n                {valType: 'any', editType: 'ticks'}\n            ],\n            editType: 'ticks',\n            \n        },\n        value: {\n            valType: 'string',\n            dflt: '',\n            \n            editType: 'ticks',\n            \n        },\n        editType: 'ticks'\n    }),\n    hoverformat: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'none',\n        \n    },\n    // lines and grids\n    showline: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'ticks+layoutstyle',\n        \n    },\n    linecolor: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'layoutstyle',\n        \n    },\n    linewidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'ticks+layoutstyle',\n        \n    },\n    showgrid: {\n        valType: 'boolean',\n        \n        editType: 'ticks',\n        \n    },\n    gridcolor: {\n        valType: 'color',\n        dflt: colorAttrs.lightLine,\n        \n        editType: 'ticks',\n        \n    },\n    gridwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'ticks',\n        \n    },\n    zeroline: {\n        valType: 'boolean',\n        \n        editType: 'ticks',\n        \n    },\n    zerolinecolor: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'ticks',\n        \n    },\n    zerolinewidth: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'ticks',\n        \n    },\n\n    showdividers: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'ticks',\n        \n    },\n    dividercolor: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'ticks',\n        \n    },\n    dividerwidth: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'ticks',\n        \n    },\n    // TODO dividerlen: that would override \"to label base\" length?\n\n    // positioning attributes\n    // anchor: not used directly, just put here for reference\n    // values are any opposite-letter axis id\n    anchor: {\n        valType: 'enumerated',\n        values: [\n            'free',\n            constants.idRegex.x.toString(),\n            constants.idRegex.y.toString()\n        ],\n        \n        editType: 'plot',\n        \n    },\n    // side: not used directly, as values depend on direction\n    // values are top, bottom for x axes, and left, right for y\n    side: {\n        valType: 'enumerated',\n        values: ['top', 'bottom', 'left', 'right'],\n        \n        editType: 'plot',\n        \n    },\n    // overlaying: not used directly, just put here for reference\n    // values are false and any other same-letter axis id that's not\n    // itself overlaying anything\n    overlaying: {\n        valType: 'enumerated',\n        values: [\n            'free',\n            constants.idRegex.x.toString(),\n            constants.idRegex.y.toString()\n        ],\n        \n        editType: 'plot',\n        \n    },\n    layer: {\n        valType: 'enumerated',\n        values: ['above traces', 'below traces'],\n        dflt: 'above traces',\n        \n        editType: 'plot',\n        \n    },\n    domain: {\n        valType: 'info_array',\n        \n        items: [\n            {valType: 'number', min: 0, max: 1, editType: 'plot'},\n            {valType: 'number', min: 0, max: 1, editType: 'plot'}\n        ],\n        dflt: [0, 1],\n        editType: 'plot',\n        \n    },\n    position: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 0,\n        \n        editType: 'plot',\n        \n    },\n    categoryorder: {\n        valType: 'enumerated',\n        values: [\n            'trace', 'category ascending', 'category descending', 'array',\n            'total ascending', 'total descending',\n            'min ascending', 'min descending',\n            'max ascending', 'max descending',\n            'sum ascending', 'sum descending',\n            'mean ascending', 'mean descending',\n            'median ascending', 'median descending'\n        ],\n        dflt: 'trace',\n        \n        editType: 'calc',\n        \n    },\n    categoryarray: {\n        valType: 'data_array',\n        \n        editType: 'calc',\n        \n    },\n    uirevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n    editType: 'calc',\n\n    _deprecated: {\n        autotick: {\n            valType: 'boolean',\n            \n            editType: 'ticks',\n            \n        },\n        title: {\n            valType: 'string',\n            \n            editType: 'ticks',\n            \n        },\n        titlefont: fontAttrs({\n            editType: 'ticks',\n            \n        })\n    }\n};\n\n},{\"../../components/color/attributes\":592,\"../../components/drawing/attributes\":613,\"../../constants/docs\":690,\"../../lib/extend\":710,\"../../plot_api/plot_template\":757,\"../font_attributes\":793,\"./constants\":773}],780:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\nvar Template = _dereq_('../../plot_api/plot_template');\nvar basePlotLayoutAttributes = _dereq_('../layout_attributes');\n\nvar layoutAttributes = _dereq_('./layout_attributes');\nvar handleTypeDefaults = _dereq_('./type_defaults');\nvar handleAxisDefaults = _dereq_('./axis_defaults');\nvar handleConstraintDefaults = _dereq_('./constraints').handleConstraintDefaults;\nvar handlePositionDefaults = _dereq_('./position_defaults');\n\nvar axisIds = _dereq_('./axis_ids');\nvar id2name = axisIds.id2name;\nvar name2id = axisIds.name2id;\n\nvar Registry = _dereq_('../../registry');\nvar traceIs = Registry.traceIs;\nvar getComponentMethod = Registry.getComponentMethod;\n\nfunction appendList(cont, k, item) {\n    if(Array.isArray(cont[k])) cont[k].push(item);\n    else cont[k] = [item];\n}\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    var ax2traces = {};\n    var xaMayHide = {};\n    var yaMayHide = {};\n    var xaMustDisplay = {};\n    var yaMustDisplay = {};\n    var yaMustForward = {};\n    var yaMayBackward = {};\n    var outerTicks = {};\n    var noGrids = {};\n    var i, j;\n\n    // look for axes in the data\n    for(i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n        if(!traceIs(trace, 'cartesian') && !traceIs(trace, 'gl2d')) continue;\n\n        var xaName;\n        if(trace.xaxis) {\n            xaName = id2name(trace.xaxis);\n            appendList(ax2traces, xaName, trace);\n        } else if(trace.xaxes) {\n            for(j = 0; j < trace.xaxes.length; j++) {\n                appendList(ax2traces, id2name(trace.xaxes[j]), trace);\n            }\n        }\n\n        var yaName;\n        if(trace.yaxis) {\n            yaName = id2name(trace.yaxis);\n            appendList(ax2traces, yaName, trace);\n        } else if(trace.yaxes) {\n            for(j = 0; j < trace.yaxes.length; j++) {\n                appendList(ax2traces, id2name(trace.yaxes[j]), trace);\n            }\n        }\n\n        // logic for funnels\n        if(trace.type === 'funnel') {\n            if(trace.orientation === 'h') {\n                if(xaName) xaMayHide[xaName] = true;\n                if(yaName) yaMayBackward[yaName] = true;\n            } else {\n                if(yaName) yaMayHide[yaName] = true;\n            }\n        } else {\n            if(yaName) {\n                yaMustDisplay[yaName] = true;\n                yaMustForward[yaName] = true;\n            }\n\n            if(!traceIs(trace, 'carpet') || (trace.type === 'carpet' && !trace._cheater)) {\n                if(xaName) xaMustDisplay[xaName] = true;\n            }\n        }\n\n        // Two things trigger axis visibility:\n        // 1. is not carpet\n        // 2. carpet that's not cheater\n\n        // The above check for definitely-not-cheater is not adequate. This\n        // second list tracks which axes *could* be a cheater so that the\n        // full condition triggering hiding is:\n        //   *could* be a cheater and *is not definitely visible*\n        if(trace.type === 'carpet' && trace._cheater) {\n            if(xaName) xaMayHide[xaName] = true;\n        }\n\n        // check for default formatting tweaks\n        if(traceIs(trace, '2dMap')) {\n            outerTicks[xaName] = true;\n            outerTicks[yaName] = true;\n        }\n\n        if(traceIs(trace, 'oriented')) {\n            var positionAxis = trace.orientation === 'h' ? yaName : xaName;\n            noGrids[positionAxis] = true;\n        }\n    }\n\n    var subplots = layoutOut._subplots;\n    var xIds = subplots.xaxis;\n    var yIds = subplots.yaxis;\n    var xNames = Lib.simpleMap(xIds, id2name);\n    var yNames = Lib.simpleMap(yIds, id2name);\n    var axNames = xNames.concat(yNames);\n\n    // plot_bgcolor only makes sense if there's a (2D) plot!\n    // TODO: bgcolor for each subplot, to inherit from the main one\n    var plotBgColor = Color.background;\n    if(xIds.length && yIds.length) {\n        plotBgColor = Lib.coerce(layoutIn, layoutOut, basePlotLayoutAttributes, 'plot_bgcolor');\n    }\n\n    var bgColor = Color.combine(plotBgColor, layoutOut.paper_bgcolor);\n\n    var axName, axLetter, axLayoutIn, axLayoutOut;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(axLayoutIn, axLayoutOut, layoutAttributes, attr, dflt);\n    }\n\n    function coerce2(attr, dflt) {\n        return Lib.coerce2(axLayoutIn, axLayoutOut, layoutAttributes, attr, dflt);\n    }\n\n    function getCounterAxes(axLetter) {\n        return (axLetter === 'x') ? yIds : xIds;\n    }\n\n    var counterAxes = {x: getCounterAxes('x'), y: getCounterAxes('y')};\n    var allAxisIds = counterAxes.x.concat(counterAxes.y);\n\n    function getOverlayableAxes(axLetter, axName) {\n        var list = (axLetter === 'x') ? xNames : yNames;\n        var out = [];\n\n        for(var j = 0; j < list.length; j++) {\n            var axName2 = list[j];\n\n            if(axName2 !== axName && !(layoutIn[axName2] || {}).overlaying) {\n                out.push(name2id(axName2));\n            }\n        }\n\n        return out;\n    }\n\n    // first pass creates the containers, determines types, and handles most of the settings\n    for(i = 0; i < axNames.length; i++) {\n        axName = axNames[i];\n        axLetter = axName.charAt(0);\n\n        if(!Lib.isPlainObject(layoutIn[axName])) {\n            layoutIn[axName] = {};\n        }\n\n        axLayoutIn = layoutIn[axName];\n        axLayoutOut = Template.newContainer(layoutOut, axName, axLetter + 'axis');\n\n        var traces = ax2traces[axName] || [];\n        axLayoutOut._traceIndices = traces.map(function(t) { return t._expandedIndex; });\n        axLayoutOut._annIndices = [];\n        axLayoutOut._shapeIndices = [];\n        axLayoutOut._imgIndices = [];\n        axLayoutOut._subplotsWith = [];\n        axLayoutOut._counterAxes = [];\n\n        // set up some private properties\n        axLayoutOut._name = axLayoutOut._attr = axName;\n        var id = axLayoutOut._id = name2id(axName);\n\n        var overlayableAxes = getOverlayableAxes(axLetter, axName);\n\n        var visibleDflt =\n            (axLetter === 'x' && !xaMustDisplay[axName] && xaMayHide[axName]) ||\n            (axLetter === 'y' && !yaMustDisplay[axName] && yaMayHide[axName]);\n\n        var reverseDflt =\n            (axLetter === 'y' && !yaMustForward[axName] && yaMayBackward[axName]);\n\n        var defaultOptions = {\n            letter: axLetter,\n            font: layoutOut.font,\n            outerTicks: outerTicks[axName],\n            showGrid: !noGrids[axName],\n            data: traces,\n            bgColor: bgColor,\n            calendar: layoutOut.calendar,\n            automargin: true,\n            visibleDflt: visibleDflt,\n            reverseDflt: reverseDflt,\n            splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[id]\n        };\n\n        coerce('uirevision', layoutOut.uirevision);\n\n        handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions);\n        handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);\n\n        var spikecolor = coerce2('spikecolor');\n        var spikethickness = coerce2('spikethickness');\n        var spikedash = coerce2('spikedash');\n        var spikemode = coerce2('spikemode');\n        var spikesnap = coerce2('spikesnap');\n        var showSpikes = coerce('showspikes', !!spikecolor || !!spikethickness || !!spikedash || !!spikemode || !!spikesnap);\n\n        if(!showSpikes) {\n            delete axLayoutOut.spikecolor;\n            delete axLayoutOut.spikethickness;\n            delete axLayoutOut.spikedash;\n            delete axLayoutOut.spikemode;\n            delete axLayoutOut.spikesnap;\n        }\n\n        handlePositionDefaults(axLayoutIn, axLayoutOut, coerce, {\n            letter: axLetter,\n            counterAxes: counterAxes[axLetter],\n            overlayableAxes: overlayableAxes,\n            grid: layoutOut.grid\n        });\n\n        axLayoutOut._input = axLayoutIn;\n    }\n\n    // quick second pass for range slider and selector defaults\n    var rangeSliderDefaults = getComponentMethod('rangeslider', 'handleDefaults');\n    var rangeSelectorDefaults = getComponentMethod('rangeselector', 'handleDefaults');\n\n    for(i = 0; i < xNames.length; i++) {\n        axName = xNames[i];\n        axLayoutIn = layoutIn[axName];\n        axLayoutOut = layoutOut[axName];\n\n        rangeSliderDefaults(layoutIn, layoutOut, axName);\n\n        if(axLayoutOut.type === 'date') {\n            rangeSelectorDefaults(\n                axLayoutIn,\n                axLayoutOut,\n                layoutOut,\n                yNames,\n                axLayoutOut.calendar\n            );\n        }\n\n        coerce('fixedrange');\n    }\n\n    for(i = 0; i < yNames.length; i++) {\n        axName = yNames[i];\n        axLayoutIn = layoutIn[axName];\n        axLayoutOut = layoutOut[axName];\n\n        var anchoredAxis = layoutOut[id2name(axLayoutOut.anchor)];\n\n        var fixedRangeDflt = getComponentMethod('rangeslider', 'isVisible')(anchoredAxis);\n\n        coerce('fixedrange', fixedRangeDflt);\n    }\n\n    // Finally, handle scale constraints and matching axes.\n    //\n    // We need to do this after all axes have coerced both `type`\n    // (so we link only axes of the same type) and\n    // `fixedrange` (so we can avoid linking from OR TO a fixed axis).\n\n    // sets of axes linked by `scaleanchor` along with the scaleratios compounded\n    // together, populated in handleConstraintDefaults\n    var constraintGroups = layoutOut._axisConstraintGroups = [];\n    // similar to _axisConstraintGroups, but for matching axes\n    var matchGroups = layoutOut._axisMatchGroups = [];\n\n    for(i = 0; i < axNames.length; i++) {\n        axName = axNames[i];\n        axLetter = axName.charAt(0);\n        axLayoutIn = layoutIn[axName];\n        axLayoutOut = layoutOut[axName];\n\n        handleConstraintDefaults(axLayoutIn, axLayoutOut, coerce, allAxisIds, layoutOut);\n    }\n\n    for(i = 0; i < matchGroups.length; i++) {\n        var group = matchGroups[i];\n        var rng = null;\n        var autorange = null;\n        var axId;\n\n        // find 'matching' range attrs\n        for(axId in group) {\n            axLayoutOut = layoutOut[id2name(axId)];\n            if(!axLayoutOut.matches) {\n                rng = axLayoutOut.range;\n                autorange = axLayoutOut.autorange;\n            }\n        }\n        // if `ax.matches` values are reciprocal,\n        // pick values of first axis in group\n        if(rng === null || autorange === null) {\n            for(axId in group) {\n                axLayoutOut = layoutOut[id2name(axId)];\n                rng = axLayoutOut.range;\n                autorange = axLayoutOut.autorange;\n                break;\n            }\n        }\n        // apply matching range attrs\n        for(axId in group) {\n            axLayoutOut = layoutOut[id2name(axId)];\n            if(axLayoutOut.matches) {\n                axLayoutOut.range = rng.slice();\n                axLayoutOut.autorange = autorange;\n            }\n            axLayoutOut._matchGroup = group;\n        }\n\n        // remove matching axis from scaleanchor constraint groups (for now)\n        if(constraintGroups.length) {\n            for(axId in group) {\n                for(j = 0; j < constraintGroups.length; j++) {\n                    var group2 = constraintGroups[j];\n                    for(var axId2 in group2) {\n                        if(axId === axId2) {\n                            Lib.warn('Axis ' + axId2 + ' is set with both ' +\n                                'a *scaleanchor* and *matches* constraint; ' +\n                                'ignoring the scale constraint.');\n\n                            delete group2[axId2];\n                            if(Object.keys(group2).length < 2) {\n                                constraintGroups.splice(j, 1);\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    }\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../registry\":847,\"../layout_attributes\":819,\"./axis_defaults\":769,\"./axis_ids\":770,\"./constraints\":774,\"./layout_attributes\":779,\"./position_defaults\":782,\"./type_defaults\":790}],781:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorMix = _dereq_('tinycolor2').mix;\nvar lightFraction = _dereq_('../../components/color/attributes').lightFraction;\nvar Lib = _dereq_('../../lib');\n\n/**\n * @param {object} opts :\n *   - dfltColor {string} : default axis color\n *   - bgColor {string} : combined subplot bg color\n *   - blend {number, optional} : blend percentage (to compute dflt grid color)\n *   - showLine {boolean} : show line by default\n *   - showGrid {boolean} : show grid by default\n *   - noZeroLine {boolean} : don't coerce zeroline* attributes\n *   - attributes {object} : attribute object associated with input containers\n */\nmodule.exports = function handleLineGridDefaults(containerIn, containerOut, coerce, opts) {\n    opts = opts || {};\n\n    var dfltColor = opts.dfltColor;\n\n    function coerce2(attr, dflt) {\n        return Lib.coerce2(containerIn, containerOut, opts.attributes, attr, dflt);\n    }\n\n    var lineColor = coerce2('linecolor', dfltColor);\n    var lineWidth = coerce2('linewidth');\n    var showLine = coerce('showline', opts.showLine || !!lineColor || !!lineWidth);\n\n    if(!showLine) {\n        delete containerOut.linecolor;\n        delete containerOut.linewidth;\n    }\n\n    var gridColorDflt = colorMix(dfltColor, opts.bgColor, opts.blend || lightFraction).toRgbString();\n    var gridColor = coerce2('gridcolor', gridColorDflt);\n    var gridWidth = coerce2('gridwidth');\n    var showGridLines = coerce('showgrid', opts.showGrid || !!gridColor || !!gridWidth);\n\n    if(!showGridLines) {\n        delete containerOut.gridcolor;\n        delete containerOut.gridwidth;\n    }\n\n    if(!opts.noZeroLine) {\n        var zeroLineColor = coerce2('zerolinecolor', dfltColor);\n        var zeroLineWidth = coerce2('zerolinewidth');\n        var showZeroLine = coerce('zeroline', opts.showGrid || !!zeroLineColor || !!zeroLineWidth);\n\n        if(!showZeroLine) {\n            delete containerOut.zerolinecolor;\n            delete containerOut.zerolinewidth;\n        }\n    }\n};\n\n},{\"../../components/color/attributes\":592,\"../../lib\":719,\"tinycolor2\":537}],782:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\n\n\nmodule.exports = function handlePositionDefaults(containerIn, containerOut, coerce, options) {\n    var counterAxes = options.counterAxes || [];\n    var overlayableAxes = options.overlayableAxes || [];\n    var letter = options.letter;\n    var grid = options.grid;\n\n    var dfltAnchor, dfltDomain, dfltSide, dfltPosition;\n\n    if(grid) {\n        dfltDomain = grid._domains[letter][grid._axisMap[containerOut._id]];\n        dfltAnchor = grid._anchors[containerOut._id];\n        if(dfltDomain) {\n            dfltSide = grid[letter + 'side'].split(' ')[0];\n            dfltPosition = grid.domain[letter][dfltSide === 'right' || dfltSide === 'top' ? 1 : 0];\n        }\n    }\n\n    // Even if there's a grid, this axis may not be in it - fall back on non-grid defaults\n    dfltDomain = dfltDomain || [0, 1];\n    dfltAnchor = dfltAnchor || (isNumeric(containerIn.position) ? 'free' : (counterAxes[0] || 'free'));\n    dfltSide = dfltSide || (letter === 'x' ? 'bottom' : 'left');\n    dfltPosition = dfltPosition || 0;\n\n    var anchor = Lib.coerce(containerIn, containerOut, {\n        anchor: {\n            valType: 'enumerated',\n            values: ['free'].concat(counterAxes),\n            dflt: dfltAnchor\n        }\n    }, 'anchor');\n\n    if(anchor === 'free') coerce('position', dfltPosition);\n\n    Lib.coerce(containerIn, containerOut, {\n        side: {\n            valType: 'enumerated',\n            values: letter === 'x' ? ['bottom', 'top'] : ['left', 'right'],\n            dflt: dfltSide\n        }\n    }, 'side');\n\n    var overlaying = false;\n    if(overlayableAxes.length) {\n        overlaying = Lib.coerce(containerIn, containerOut, {\n            overlaying: {\n                valType: 'enumerated',\n                values: [false].concat(overlayableAxes),\n                dflt: false\n            }\n        }, 'overlaying');\n    }\n\n    if(!overlaying) {\n        // TODO: right now I'm copying this domain over to overlaying axes\n        // in ax.setscale()... but this means we still need (imperfect) logic\n        // in the axes popover to hide domain for the overlaying axis.\n        // perhaps I should make a private version _domain that all axes get???\n        var domain = coerce('domain', dfltDomain);\n\n        // according to https://www.npmjs.com/package/canvas-size\n        // the minimum value of max canvas width across browsers and devices is 4096\n        // which applied in the calculation below:\n        if(domain[0] > domain[1] - 1 / 4096) containerOut.domain = dfltDomain;\n        Lib.noneOrAll(containerIn.domain, containerOut.domain, dfltDomain);\n    }\n\n    coerce('layer');\n\n    return containerOut;\n};\n\n},{\"../../lib\":719,\"fast-isnumeric\":225}],783:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar FROM_BL = _dereq_('../../constants/alignment').FROM_BL;\n\nmodule.exports = function scaleZoom(ax, factor, centerFraction) {\n    if(centerFraction === undefined) {\n        centerFraction = FROM_BL[ax.constraintoward || 'center'];\n    }\n\n    var rangeLinear = [ax.r2l(ax.range[0]), ax.r2l(ax.range[1])];\n    var center = rangeLinear[0] + (rangeLinear[1] - rangeLinear[0]) * centerFraction;\n\n    ax.range = ax._input.range = [\n        ax.l2r(center + (rangeLinear[0] - center) * factor),\n        ax.l2r(center + (rangeLinear[1] - center) * factor)\n    ];\n};\n\n},{\"../../constants/alignment\":688}],784:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar polybool = _dereq_('polybooljs');\n\nvar Registry = _dereq_('../../registry');\nvar Color = _dereq_('../../components/color');\nvar Fx = _dereq_('../../components/fx');\n\nvar Lib = _dereq_('../../lib');\nvar polygon = _dereq_('../../lib/polygon');\nvar throttle = _dereq_('../../lib/throttle');\nvar makeEventData = _dereq_('../../components/fx/helpers').makeEventData;\nvar getFromId = _dereq_('./axis_ids').getFromId;\nvar clearGlCanvases = _dereq_('../../lib/clear_gl_canvases');\n\nvar redrawReglTraces = _dereq_('../../plot_api/subroutines').redrawReglTraces;\n\nvar constants = _dereq_('./constants');\nvar MINSELECT = constants.MINSELECT;\n\nvar filteredPolygon = polygon.filter;\nvar polygonTester = polygon.tester;\n\nfunction getAxId(ax) { return ax._id; }\n\nfunction prepSelect(e, startX, startY, dragOptions, mode) {\n    var gd = dragOptions.gd;\n    var fullLayout = gd._fullLayout;\n    var zoomLayer = fullLayout._zoomlayer;\n    var dragBBox = dragOptions.element.getBoundingClientRect();\n    var plotinfo = dragOptions.plotinfo;\n    var xs = plotinfo.xaxis._offset;\n    var ys = plotinfo.yaxis._offset;\n    var x0 = startX - dragBBox.left;\n    var y0 = startY - dragBBox.top;\n    var x1 = x0;\n    var y1 = y0;\n    var path0 = 'M' + x0 + ',' + y0;\n    var pw = dragOptions.xaxes[0]._length;\n    var ph = dragOptions.yaxes[0]._length;\n    var allAxes = dragOptions.xaxes.concat(dragOptions.yaxes);\n    var subtract = e.altKey;\n\n    var filterPoly, selectionTester, mergedPolygons, currentPolygon;\n    var i, searchInfo, eventData;\n\n    coerceSelectionsCache(e, gd, dragOptions);\n\n    if(mode === 'lasso') {\n        filterPoly = filteredPolygon([[x0, y0]], constants.BENDPX);\n    }\n\n    var outlines = zoomLayer.selectAll('path.select-outline-' + plotinfo.id).data([1, 2]);\n\n    outlines.enter()\n        .append('path')\n        .attr('class', function(d) { return 'select-outline select-outline-' + d + ' select-outline-' + plotinfo.id; })\n        .attr('transform', 'translate(' + xs + ', ' + ys + ')')\n        .attr('d', path0 + 'Z');\n\n    var corners = zoomLayer.append('path')\n        .attr('class', 'zoombox-corners')\n        .style({\n            fill: Color.background,\n            stroke: Color.defaultLine,\n            'stroke-width': 1\n        })\n        .attr('transform', 'translate(' + xs + ', ' + ys + ')')\n        .attr('d', 'M0,0Z');\n\n\n    var throttleID = fullLayout._uid + constants.SELECTID;\n    var selection = [];\n\n    // find the traces to search for selection points\n    var searchTraces = determineSearchTraces(gd, dragOptions.xaxes,\n      dragOptions.yaxes, dragOptions.subplot);\n\n    // in v2 (once log ranges are fixed),\n    // we'll be able to p2r here for all axis types\n    function p2r(ax, v) {\n        return ax.type === 'log' ? ax.p2d(v) : ax.p2r(v);\n    }\n\n    function axValue(ax) {\n        var index = (ax._id.charAt(0) === 'y') ? 1 : 0;\n        return function(v) { return p2r(ax, v[index]); };\n    }\n\n    function ascending(a, b) { return a - b; }\n\n    // allow subplots to override fillRangeItems routine\n    var fillRangeItems;\n\n    if(plotinfo.fillRangeItems) {\n        fillRangeItems = plotinfo.fillRangeItems;\n    } else {\n        if(mode === 'select') {\n            fillRangeItems = function(eventData, poly) {\n                var ranges = eventData.range = {};\n\n                for(i = 0; i < allAxes.length; i++) {\n                    var ax = allAxes[i];\n                    var axLetter = ax._id.charAt(0);\n\n                    ranges[ax._id] = [\n                        p2r(ax, poly[axLetter + 'min']),\n                        p2r(ax, poly[axLetter + 'max'])\n                    ].sort(ascending);\n                }\n            };\n        } else {\n            fillRangeItems = function(eventData, poly, filterPoly) {\n                var dataPts = eventData.lassoPoints = {};\n\n                for(i = 0; i < allAxes.length; i++) {\n                    var ax = allAxes[i];\n                    dataPts[ax._id] = filterPoly.filtered.map(axValue(ax));\n                }\n            };\n        }\n    }\n\n    dragOptions.moveFn = function(dx0, dy0) {\n        x1 = Math.max(0, Math.min(pw, dx0 + x0));\n        y1 = Math.max(0, Math.min(ph, dy0 + y0));\n\n        var dx = Math.abs(x1 - x0);\n        var dy = Math.abs(y1 - y0);\n\n        if(mode === 'select') {\n            var direction = fullLayout.selectdirection;\n\n            if(fullLayout.selectdirection === 'any') {\n                if(dy < Math.min(dx * 0.6, MINSELECT)) direction = 'h';\n                else if(dx < Math.min(dy * 0.6, MINSELECT)) direction = 'v';\n                else direction = 'd';\n            } else {\n                direction = fullLayout.selectdirection;\n            }\n\n            if(direction === 'h') {\n                // horizontal motion: make a vertical box\n                currentPolygon = [[x0, 0], [x0, ph], [x1, ph], [x1, 0]];\n                currentPolygon.xmin = Math.min(x0, x1);\n                currentPolygon.xmax = Math.max(x0, x1);\n                currentPolygon.ymin = Math.min(0, ph);\n                currentPolygon.ymax = Math.max(0, ph);\n                // extras to guide users in keeping a straight selection\n                corners.attr('d', 'M' + currentPolygon.xmin + ',' + (y0 - MINSELECT) +\n                    'h-4v' + (2 * MINSELECT) + 'h4Z' +\n                    'M' + (currentPolygon.xmax - 1) + ',' + (y0 - MINSELECT) +\n                    'h4v' + (2 * MINSELECT) + 'h-4Z');\n            } else if(direction === 'v') {\n                // vertical motion: make a horizontal box\n                currentPolygon = [[0, y0], [0, y1], [pw, y1], [pw, y0]];\n                currentPolygon.xmin = Math.min(0, pw);\n                currentPolygon.xmax = Math.max(0, pw);\n                currentPolygon.ymin = Math.min(y0, y1);\n                currentPolygon.ymax = Math.max(y0, y1);\n                corners.attr('d', 'M' + (x0 - MINSELECT) + ',' + currentPolygon.ymin +\n                    'v-4h' + (2 * MINSELECT) + 'v4Z' +\n                    'M' + (x0 - MINSELECT) + ',' + (currentPolygon.ymax - 1) +\n                    'v4h' + (2 * MINSELECT) + 'v-4Z');\n            } else if(direction === 'd') {\n                // diagonal motion\n                currentPolygon = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]];\n                currentPolygon.xmin = Math.min(x0, x1);\n                currentPolygon.xmax = Math.max(x0, x1);\n                currentPolygon.ymin = Math.min(y0, y1);\n                currentPolygon.ymax = Math.max(y0, y1);\n                corners.attr('d', 'M0,0Z');\n            }\n        } else if(mode === 'lasso') {\n            filterPoly.addPt([x1, y1]);\n            currentPolygon = filterPoly.filtered;\n        }\n\n        // create outline & tester\n        if(dragOptions.selectionDefs && dragOptions.selectionDefs.length) {\n            mergedPolygons = mergePolygons(dragOptions.mergedPolygons, currentPolygon, subtract);\n            currentPolygon.subtract = subtract;\n            selectionTester = multiTester(dragOptions.selectionDefs.concat([currentPolygon]));\n        } else {\n            mergedPolygons = [currentPolygon];\n            selectionTester = polygonTester(currentPolygon);\n        }\n\n        // draw selection\n        drawSelection(mergedPolygons, outlines);\n\n\n        throttle.throttle(\n            throttleID,\n            constants.SELECTDELAY,\n            function() {\n                selection = [];\n\n                var thisSelection;\n                var traceSelections = [];\n                var traceSelection;\n                for(i = 0; i < searchTraces.length; i++) {\n                    searchInfo = searchTraces[i];\n\n                    traceSelection = searchInfo._module.selectPoints(searchInfo, selectionTester);\n                    traceSelections.push(traceSelection);\n\n                    thisSelection = fillSelectionItem(traceSelection, searchInfo);\n\n                    if(selection.length) {\n                        for(var j = 0; j < thisSelection.length; j++) {\n                            selection.push(thisSelection[j]);\n                        }\n                    } else selection = thisSelection;\n                }\n\n                eventData = {points: selection};\n                updateSelectedState(gd, searchTraces, eventData);\n                fillRangeItems(eventData, currentPolygon, filterPoly);\n                dragOptions.gd.emit('plotly_selecting', eventData);\n            }\n        );\n    };\n\n    dragOptions.clickFn = function(numClicks, evt) {\n        var clickmode = fullLayout.clickmode;\n\n        corners.remove();\n\n        throttle.done(throttleID).then(function() {\n            throttle.clear(throttleID);\n            if(numClicks === 2) {\n                // clear selection on doubleclick\n                outlines.remove();\n                for(i = 0; i < searchTraces.length; i++) {\n                    searchInfo = searchTraces[i];\n                    searchInfo._module.selectPoints(searchInfo, false);\n                }\n\n                updateSelectedState(gd, searchTraces);\n\n                clearSelectionsCache(dragOptions);\n\n                gd.emit('plotly_deselect', null);\n            } else {\n                if(clickmode.indexOf('select') > -1) {\n                    selectOnClick(evt, gd, dragOptions.xaxes, dragOptions.yaxes,\n                      dragOptions.subplot, dragOptions, outlines);\n                }\n\n                if(clickmode === 'event') {\n                    // TODO: remove in v2 - this was probably never intended to work as it does,\n                    // but in case anyone depends on it we don't want to break it now.\n                    // Note that click-to-select introduced pre v2 also emitts proper\n                    // event data when clickmode is having 'select' in its flag list.\n                    gd.emit('plotly_selected', undefined);\n                }\n            }\n\n            Fx.click(gd, evt);\n        }).catch(Lib.error);\n    };\n\n    dragOptions.doneFn = function() {\n        corners.remove();\n\n        throttle.done(throttleID).then(function() {\n            throttle.clear(throttleID);\n            dragOptions.gd.emit('plotly_selected', eventData);\n\n            if(currentPolygon && dragOptions.selectionDefs) {\n                // save last polygons\n                currentPolygon.subtract = subtract;\n                dragOptions.selectionDefs.push(currentPolygon);\n\n                // we have to keep reference to arrays container\n                dragOptions.mergedPolygons.length = 0;\n                [].push.apply(dragOptions.mergedPolygons, mergedPolygons);\n            }\n\n            if(dragOptions.doneFnCompleted) {\n                dragOptions.doneFnCompleted(selection);\n            }\n        }).catch(Lib.error);\n    };\n}\n\nfunction selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutlines) {\n    var hoverData = gd._hoverdata;\n    var clickmode = gd._fullLayout.clickmode;\n    var sendEvents = clickmode.indexOf('event') > -1;\n    var selection = [];\n    var searchTraces, searchInfo, currentSelectionDef, selectionTester, traceSelection;\n    var thisTracesSelection, pointOrBinSelected, subtract, eventData, i;\n\n    if(isHoverDataSet(hoverData)) {\n        coerceSelectionsCache(evt, gd, dragOptions);\n        searchTraces = determineSearchTraces(gd, xAxes, yAxes, subplot);\n        var clickedPtInfo = extractClickedPtInfo(hoverData, searchTraces);\n        var isBinnedTrace = clickedPtInfo.pointNumbers.length > 0;\n\n\n        // Note: potentially costly operation isPointOrBinSelected is\n        // called as late as possible through the use of an assignment\n        // in an if condition.\n        if(isBinnedTrace ?\n            isOnlyThisBinSelected(searchTraces, clickedPtInfo) :\n            isOnlyOnePointSelected(searchTraces) &&\n                (pointOrBinSelected = isPointOrBinSelected(clickedPtInfo))) {\n            if(polygonOutlines) polygonOutlines.remove();\n            for(i = 0; i < searchTraces.length; i++) {\n                searchInfo = searchTraces[i];\n                searchInfo._module.selectPoints(searchInfo, false);\n            }\n\n            updateSelectedState(gd, searchTraces);\n\n            clearSelectionsCache(dragOptions);\n\n            if(sendEvents) {\n                gd.emit('plotly_deselect', null);\n            }\n        } else {\n            subtract = evt.shiftKey &&\n              (pointOrBinSelected !== undefined ?\n                pointOrBinSelected :\n                isPointOrBinSelected(clickedPtInfo));\n            currentSelectionDef = newPointSelectionDef(clickedPtInfo.pointNumber, clickedPtInfo.searchInfo, subtract);\n\n            var allSelectionDefs = dragOptions.selectionDefs.concat([currentSelectionDef]);\n            selectionTester = multiTester(allSelectionDefs);\n\n            for(i = 0; i < searchTraces.length; i++) {\n                traceSelection = searchTraces[i]._module.selectPoints(searchTraces[i], selectionTester);\n                thisTracesSelection = fillSelectionItem(traceSelection, searchTraces[i]);\n\n                if(selection.length) {\n                    for(var j = 0; j < thisTracesSelection.length; j++) {\n                        selection.push(thisTracesSelection[j]);\n                    }\n                } else selection = thisTracesSelection;\n            }\n\n            eventData = {points: selection};\n            updateSelectedState(gd, searchTraces, eventData);\n\n            if(currentSelectionDef && dragOptions) {\n                dragOptions.selectionDefs.push(currentSelectionDef);\n            }\n\n            if(polygonOutlines) drawSelection(dragOptions.mergedPolygons, polygonOutlines);\n\n            if(sendEvents) {\n                gd.emit('plotly_selected', eventData);\n            }\n        }\n    }\n}\n\n/**\n * Constructs a new point selection definition object.\n */\nfunction newPointSelectionDef(pointNumber, searchInfo, subtract) {\n    return {\n        pointNumber: pointNumber,\n        searchInfo: searchInfo,\n        subtract: subtract\n    };\n}\n\nfunction isPointSelectionDef(o) {\n    return 'pointNumber' in o && 'searchInfo' in o;\n}\n\n/*\n * Constructs a new point number tester.\n */\nfunction newPointNumTester(pointSelectionDef) {\n    return {\n        xmin: 0,\n        xmax: 0,\n        ymin: 0,\n        ymax: 0,\n        pts: [],\n        contains: function(pt, omitFirstEdge, pointNumber, searchInfo) {\n            var idxWantedTrace = pointSelectionDef.searchInfo.cd[0].trace._expandedIndex;\n            var idxActualTrace = searchInfo.cd[0].trace._expandedIndex;\n            return idxActualTrace === idxWantedTrace &&\n              pointNumber === pointSelectionDef.pointNumber;\n        },\n        isRect: false,\n        degenerate: false,\n        subtract: pointSelectionDef.subtract\n    };\n}\n\n/**\n * Wraps multiple selection testers.\n *\n * @param {Array} list - An array of selection testers.\n *\n * @return a selection tester object with a contains function\n * that can be called to evaluate a point against all wrapped\n * selection testers that were passed in list.\n */\nfunction multiTester(list) {\n    var testers = [];\n    var xmin = isPointSelectionDef(list[0]) ? 0 : list[0][0][0];\n    var xmax = xmin;\n    var ymin = isPointSelectionDef(list[0]) ? 0 : list[0][0][1];\n    var ymax = ymin;\n\n    for(var i = 0; i < list.length; i++) {\n        if(isPointSelectionDef(list[i])) {\n            testers.push(newPointNumTester(list[i]));\n        } else {\n            var tester = polygon.tester(list[i]);\n            tester.subtract = list[i].subtract;\n            testers.push(tester);\n            xmin = Math.min(xmin, tester.xmin);\n            xmax = Math.max(xmax, tester.xmax);\n            ymin = Math.min(ymin, tester.ymin);\n            ymax = Math.max(ymax, tester.ymax);\n        }\n    }\n\n    /**\n     * Tests if the given point is within this tester.\n     *\n     * @param {Array} pt - [0] is the x coordinate, [1] is the y coordinate of the point.\n     * @param {*} arg - An optional parameter to pass down to wrapped testers.\n     * @param {number} pointNumber - The point number of the point within the underlying data array.\n     * @param {number} searchInfo - An object identifying the trace the point is contained in.\n     *\n     * @return {boolean} true if point is considered to be selected, false otherwise.\n     */\n    function contains(pt, arg, pointNumber, searchInfo) {\n        var contained = false;\n        for(var i = 0; i < testers.length; i++) {\n            if(testers[i].contains(pt, arg, pointNumber, searchInfo)) {\n                // if contained by subtract tester - exclude the point\n                contained = testers[i].subtract === false;\n            }\n        }\n\n        return contained;\n    }\n\n    return {\n        xmin: xmin,\n        xmax: xmax,\n        ymin: ymin,\n        ymax: ymax,\n        pts: [],\n        contains: contains,\n        isRect: false,\n        degenerate: false\n    };\n}\n\nfunction coerceSelectionsCache(evt, gd, dragOptions) {\n    var fullLayout = gd._fullLayout;\n    var plotinfo = dragOptions.plotinfo;\n\n    var selectingOnSameSubplot = (\n        fullLayout._lastSelectedSubplot &&\n        fullLayout._lastSelectedSubplot === plotinfo.id\n    );\n    var hasModifierKey = evt.shiftKey || evt.altKey;\n\n    if(selectingOnSameSubplot && hasModifierKey &&\n      (plotinfo.selection && plotinfo.selection.selectionDefs) && !dragOptions.selectionDefs) {\n        // take over selection definitions from prev mode, if any\n        dragOptions.selectionDefs = plotinfo.selection.selectionDefs;\n        dragOptions.mergedPolygons = plotinfo.selection.mergedPolygons;\n    } else if(!hasModifierKey || !plotinfo.selection) {\n        clearSelectionsCache(dragOptions);\n    }\n\n    // clear selection outline when selecting a different subplot\n    if(!selectingOnSameSubplot) {\n        clearSelect(gd);\n        fullLayout._lastSelectedSubplot = plotinfo.id;\n    }\n}\n\nfunction clearSelectionsCache(dragOptions) {\n    var plotinfo = dragOptions.plotinfo;\n\n    plotinfo.selection = {};\n    plotinfo.selection.selectionDefs = dragOptions.selectionDefs = [];\n    plotinfo.selection.mergedPolygons = dragOptions.mergedPolygons = [];\n}\n\nfunction determineSearchTraces(gd, xAxes, yAxes, subplot) {\n    var searchTraces = [];\n    var xAxisIds = xAxes.map(getAxId);\n    var yAxisIds = yAxes.map(getAxId);\n    var cd, trace, i;\n\n    for(i = 0; i < gd.calcdata.length; i++) {\n        cd = gd.calcdata[i];\n        trace = cd[0].trace;\n\n        if(trace.visible !== true || !trace._module || !trace._module.selectPoints) continue;\n\n        if(subplot && (trace.subplot === subplot || trace.geo === subplot)) {\n            searchTraces.push(createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]));\n        } else if(\n          trace.type === 'splom' &&\n          // FIXME: make sure we don't have more than single axis for splom\n          trace._xaxes[xAxisIds[0]] && trace._yaxes[yAxisIds[0]]\n        ) {\n            var info = createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]);\n            info.scene = gd._fullLayout._splomScenes[trace.uid];\n            searchTraces.push(info);\n        } else if(\n          trace.type === 'sankey'\n        ) {\n            var sankeyInfo = createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]);\n            searchTraces.push(sankeyInfo);\n        } else {\n            if(xAxisIds.indexOf(trace.xaxis) === -1) continue;\n            if(yAxisIds.indexOf(trace.yaxis) === -1) continue;\n\n            searchTraces.push(createSearchInfo(trace._module, cd,\n              getFromId(gd, trace.xaxis), getFromId(gd, trace.yaxis)));\n        }\n    }\n\n    return searchTraces;\n\n    function createSearchInfo(module, calcData, xaxis, yaxis) {\n        return {\n            _module: module,\n            cd: calcData,\n            xaxis: xaxis,\n            yaxis: yaxis\n        };\n    }\n}\n\nfunction drawSelection(polygons, outlines) {\n    var paths = [];\n    var i, d;\n\n    for(i = 0; i < polygons.length; i++) {\n        var ppts = polygons[i];\n        paths.push(ppts.join('L') + 'L' + ppts[0]);\n    }\n\n    d = polygons.length > 0 ?\n      'M' + paths.join('M') + 'Z' :\n      'M0,0Z';\n    outlines.attr('d', d);\n}\n\nfunction isHoverDataSet(hoverData) {\n    return hoverData &&\n      Array.isArray(hoverData) &&\n      hoverData[0].hoverOnBox !== true;\n}\n\nfunction extractClickedPtInfo(hoverData, searchTraces) {\n    var hoverDatum = hoverData[0];\n    var pointNumber = -1;\n    var pointNumbers = [];\n    var searchInfo, i;\n\n    for(i = 0; i < searchTraces.length; i++) {\n        searchInfo = searchTraces[i];\n        if(hoverDatum.fullData._expandedIndex === searchInfo.cd[0].trace._expandedIndex) {\n            // Special case for box (and violin)\n            if(hoverDatum.hoverOnBox === true) {\n                break;\n            }\n\n            // Hint: in some traces like histogram, one graphical element\n            // doesn't correspond to one particular data point, but to\n            // bins of data points. Thus, hoverDatum can have a binNumber\n            // property instead of pointNumber.\n            if(hoverDatum.pointNumber !== undefined) {\n                pointNumber = hoverDatum.pointNumber;\n            } else if(hoverDatum.binNumber !== undefined) {\n                pointNumber = hoverDatum.binNumber;\n                pointNumbers = hoverDatum.pointNumbers;\n            }\n\n            break;\n        }\n    }\n\n    return {\n        pointNumber: pointNumber,\n        pointNumbers: pointNumbers,\n        searchInfo: searchInfo\n    };\n}\n\nfunction isPointOrBinSelected(clickedPtInfo) {\n    var trace = clickedPtInfo.searchInfo.cd[0].trace;\n    var ptNum = clickedPtInfo.pointNumber;\n    var ptNums = clickedPtInfo.pointNumbers;\n    var ptNumsSet = ptNums.length > 0;\n\n    // When pointsNumbers is set (e.g. histogram's binning),\n    // it is assumed that when the first point of\n    // a bin is selected, all others are as well\n    var ptNumToTest = ptNumsSet ? ptNums[0] : ptNum;\n\n    // TODO potential performance improvement\n    // Primarily we need this function to determine if a click adds\n    // or subtracts from a selection.\n    // In cases `trace.selectedpoints` is a huge array, indexOf\n    // might be slow. One remedy would be to introduce a hash somewhere.\n    return trace.selectedpoints ? trace.selectedpoints.indexOf(ptNumToTest) > -1 : false;\n}\n\nfunction isOnlyThisBinSelected(searchTraces, clickedPtInfo) {\n    var tracesWithSelectedPts = [];\n    var searchInfo, trace, isSameTrace, i;\n\n    for(i = 0; i < searchTraces.length; i++) {\n        searchInfo = searchTraces[i];\n        if(searchInfo.cd[0].trace.selectedpoints && searchInfo.cd[0].trace.selectedpoints.length > 0) {\n            tracesWithSelectedPts.push(searchInfo);\n        }\n    }\n\n    if(tracesWithSelectedPts.length === 1) {\n        isSameTrace = tracesWithSelectedPts[0] === clickedPtInfo.searchInfo;\n        if(isSameTrace) {\n            trace = clickedPtInfo.searchInfo.cd[0].trace;\n            if(trace.selectedpoints.length === clickedPtInfo.pointNumbers.length) {\n                for(i = 0; i < clickedPtInfo.pointNumbers.length; i++) {\n                    if(trace.selectedpoints.indexOf(clickedPtInfo.pointNumbers[i]) < 0) {\n                        return false;\n                    }\n                }\n                return true;\n            }\n        }\n    }\n\n    return false;\n}\n\nfunction isOnlyOnePointSelected(searchTraces) {\n    var len = 0;\n    var searchInfo, trace, i;\n\n    for(i = 0; i < searchTraces.length; i++) {\n        searchInfo = searchTraces[i];\n        trace = searchInfo.cd[0].trace;\n        if(trace.selectedpoints) {\n            if(trace.selectedpoints.length > 1) return false;\n\n            len += trace.selectedpoints.length;\n            if(len > 1) return false;\n        }\n    }\n\n    return len === 1;\n}\n\nfunction updateSelectedState(gd, searchTraces, eventData) {\n    var i, searchInfo, cd, trace;\n\n    // before anything else, update preGUI if necessary\n    for(i = 0; i < searchTraces.length; i++) {\n        var fullInputTrace = searchTraces[i].cd[0].trace._fullInput;\n        var tracePreGUI = gd._fullLayout._tracePreGUI[fullInputTrace.uid] || {};\n        if(tracePreGUI.selectedpoints === undefined) {\n            tracePreGUI.selectedpoints = fullInputTrace._input.selectedpoints || null;\n        }\n    }\n\n    if(eventData) {\n        var pts = eventData.points || [];\n\n        for(i = 0; i < searchTraces.length; i++) {\n            trace = searchTraces[i].cd[0].trace;\n            trace._input.selectedpoints = trace._fullInput.selectedpoints = [];\n            if(trace._fullInput !== trace) trace.selectedpoints = [];\n        }\n\n        for(i = 0; i < pts.length; i++) {\n            var pt = pts[i];\n            var data = pt.data;\n            var fullData = pt.fullData;\n\n            if(pt.pointIndices) {\n                [].push.apply(data.selectedpoints, pt.pointIndices);\n                if(trace._fullInput !== trace) {\n                    [].push.apply(fullData.selectedpoints, pt.pointIndices);\n                }\n            } else {\n                data.selectedpoints.push(pt.pointIndex);\n                if(trace._fullInput !== trace) {\n                    fullData.selectedpoints.push(pt.pointIndex);\n                }\n            }\n        }\n    } else {\n        for(i = 0; i < searchTraces.length; i++) {\n            trace = searchTraces[i].cd[0].trace;\n            delete trace.selectedpoints;\n            delete trace._input.selectedpoints;\n            if(trace._fullInput !== trace) {\n                delete trace._fullInput.selectedpoints;\n            }\n        }\n    }\n\n    var hasRegl = false;\n\n    for(i = 0; i < searchTraces.length; i++) {\n        searchInfo = searchTraces[i];\n        cd = searchInfo.cd;\n        trace = cd[0].trace;\n\n        if(Registry.traceIs(trace, 'regl')) {\n            hasRegl = true;\n        }\n\n        var _module = searchInfo._module;\n        var fn = _module.styleOnSelect || _module.style;\n        if(fn) {\n            fn(gd, cd, cd[0].node3);\n            if(cd[0].nodeRangePlot3) fn(gd, cd, cd[0].nodeRangePlot3);\n        }\n    }\n\n    if(hasRegl) {\n        clearGlCanvases(gd);\n        redrawReglTraces(gd);\n    }\n}\n\nfunction mergePolygons(list, poly, subtract) {\n    var res;\n\n    if(subtract) {\n        res = polybool.difference({\n            regions: list,\n            inverted: false\n        }, {\n            regions: [poly],\n            inverted: false\n        });\n\n        return res.regions;\n    }\n\n    res = polybool.union({\n        regions: list,\n        inverted: false\n    }, {\n        regions: [poly],\n        inverted: false\n    });\n\n    return res.regions;\n}\n\nfunction fillSelectionItem(selection, searchInfo) {\n    if(Array.isArray(selection)) {\n        var cd = searchInfo.cd;\n        var trace = searchInfo.cd[0].trace;\n\n        for(var i = 0; i < selection.length; i++) {\n            selection[i] = makeEventData(selection[i], trace, cd);\n        }\n    }\n\n    return selection;\n}\n\n// until we get around to persistent selections, remove the outline\n// here. The selection itself will be removed when the plot redraws\n// at the end.\nfunction clearSelect(gd) {\n    var fullLayout = gd._fullLayout || {};\n    var zoomlayer = fullLayout._zoomlayer;\n    if(zoomlayer) {\n        zoomlayer.selectAll('.select-outline').remove();\n    }\n}\n\nmodule.exports = {\n    prepSelect: prepSelect,\n    clearSelect: clearSelect,\n    selectOnClick: selectOnClick\n};\n\n},{\"../../components/color\":593,\"../../components/fx\":632,\"../../components/fx/helpers\":628,\"../../lib\":719,\"../../lib/clear_gl_canvases\":704,\"../../lib/polygon\":731,\"../../lib/throttle\":744,\"../../plot_api/subroutines\":758,\"../../registry\":847,\"./axis_ids\":770,\"./constants\":773,\"polybooljs\":473}],785:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar cleanNumber = Lib.cleanNumber;\nvar ms2DateTime = Lib.ms2DateTime;\nvar dateTime2ms = Lib.dateTime2ms;\nvar ensureNumber = Lib.ensureNumber;\nvar isArrayOrTypedArray = Lib.isArrayOrTypedArray;\n\nvar numConstants = _dereq_('../../constants/numerical');\nvar FP_SAFE = numConstants.FP_SAFE;\nvar BADNUM = numConstants.BADNUM;\nvar LOG_CLIP = numConstants.LOG_CLIP;\n\nvar constants = _dereq_('./constants');\nvar axisIds = _dereq_('./axis_ids');\n\nfunction fromLog(v) {\n    return Math.pow(10, v);\n}\n\nfunction isValidCategory(v) {\n    return v !== null && v !== undefined;\n}\n\n/**\n * Define the conversion functions for an axis data is used in 5 ways:\n *\n *  d: data, in whatever form it's provided\n *  c: calcdata: turned into numbers, but not linearized\n *  l: linearized - same as c except for log axes (and other nonlinear\n *      mappings later?) this is used when we need to know if it's\n *      *possible* to show some data on this axis, without caring about\n *      the current range\n *  p: pixel value - mapped to the screen with current size and zoom\n *  r: ranges, tick0, and annotation positions match one of the above\n *     but are handled differently for different types:\n *     - linear and date: data format (d)\n *     - category: calcdata format (c), and will stay that way because\n *       the data format has no continuous mapping\n *     - log: linearized (l) format\n *       TODO: in v2.0 we plan to change it to data format. At that point\n *       shapes will work the same way as ranges, tick0, and annotations\n *       so they can use this conversion too.\n *\n * Creates/updates these conversion functions, and a few more utilities\n * like cleanRange, and makeCalcdata\n *\n * also clears the autotick constraints ._minDtick, ._forceTick0\n */\nmodule.exports = function setConvert(ax, fullLayout) {\n    fullLayout = fullLayout || {};\n\n    var axId = (ax._id || 'x');\n    var axLetter = axId.charAt(0);\n\n    function toLog(v, clip) {\n        if(v > 0) return Math.log(v) / Math.LN10;\n\n        else if(v <= 0 && clip && ax.range && ax.range.length === 2) {\n            // clip NaN (ie past negative infinity) to LOG_CLIP axis\n            // length past the negative edge\n            var r0 = ax.range[0];\n            var r1 = ax.range[1];\n            return 0.5 * (r0 + r1 - 2 * LOG_CLIP * Math.abs(r0 - r1));\n        } else return BADNUM;\n    }\n\n    /*\n     * wrapped dateTime2ms that:\n     * - accepts ms numbers for backward compatibility\n     * - inserts a dummy arg so calendar is the 3rd arg (see notes below).\n     * - defaults to ax.calendar\n     */\n    function dt2ms(v, _, calendar) {\n        // NOTE: Changed this behavior: previously we took any numeric value\n        // to be a ms, even if it was a string that could be a bare year.\n        // Now we convert it as a date if at all possible, and only try\n        // as (local) ms if that fails.\n        var ms = dateTime2ms(v, calendar || ax.calendar);\n        if(ms === BADNUM) {\n            if(isNumeric(v)) {\n                v = +v;\n                // keep track of tenths of ms, that `new Date` will drop\n                // same logic as in Lib.ms2DateTime\n                var msecTenths = Math.floor(Lib.mod(v + 0.05, 1) * 10);\n                var msRounded = Math.round(v - msecTenths / 10);\n                ms = dateTime2ms(new Date(msRounded)) + msecTenths / 10;\n            } else return BADNUM;\n        }\n        return ms;\n    }\n\n    // wrapped ms2DateTime to insert default ax.calendar\n    function ms2dt(v, r, calendar) {\n        return ms2DateTime(v, r, calendar || ax.calendar);\n    }\n\n    function getCategoryName(v) {\n        return ax._categories[Math.round(v)];\n    }\n\n    /*\n     * setCategoryIndex: return the index of category v,\n     * inserting it in the list if it's not already there\n     *\n     * this will enter the categories in the order it\n     * encounters them, ie all the categories from the\n     * first data set, then all the ones from the second\n     * that aren't in the first etc.\n     *\n     * it is assumed that this function is being invoked in the\n     * already sorted category order; otherwise there would be\n     * a disconnect between the array and the index returned\n     */\n    function setCategoryIndex(v) {\n        if(isValidCategory(v)) {\n            if(ax._categoriesMap === undefined) {\n                ax._categoriesMap = {};\n            }\n\n            if(ax._categoriesMap[v] !== undefined) {\n                return ax._categoriesMap[v];\n            } else {\n                ax._categories.push(typeof v === 'number' ? String(v) : v);\n\n                var curLength = ax._categories.length - 1;\n                ax._categoriesMap[v] = curLength;\n\n                return curLength;\n            }\n        }\n        return BADNUM;\n    }\n\n    function setMultiCategoryIndex(arrayIn, len) {\n        var arrayOut = new Array(len);\n\n        for(var i = 0; i < len; i++) {\n            var v0 = (arrayIn[0] || [])[i];\n            var v1 = (arrayIn[1] || [])[i];\n            arrayOut[i] = getCategoryIndex([v0, v1]);\n        }\n\n        return arrayOut;\n    }\n\n    function getCategoryIndex(v) {\n        if(ax._categoriesMap) {\n            return ax._categoriesMap[v];\n        }\n    }\n\n    function getCategoryPosition(v) {\n        // d2l/d2c variant that that won't add categories but will also\n        // allow numbers to be mapped to the linearized axis positions\n        var index = getCategoryIndex(v);\n        if(index !== undefined) return index;\n        if(isNumeric(v)) return +v;\n    }\n\n    function l2p(v) {\n        if(!isNumeric(v)) return BADNUM;\n\n        // include 2 fractional digits on pixel, for PDF zooming etc\n        return d3.round(ax._b + ax._m * v, 2);\n    }\n\n    function p2l(px) { return (px - ax._b) / ax._m; }\n\n    // conversions among c/l/p are fairly simple - do them together for all axis types\n    ax.c2l = (ax.type === 'log') ? toLog : ensureNumber;\n    ax.l2c = (ax.type === 'log') ? fromLog : ensureNumber;\n\n    ax.l2p = l2p;\n    ax.p2l = p2l;\n\n    ax.c2p = (ax.type === 'log') ? function(v, clip) { return l2p(toLog(v, clip)); } : l2p;\n    ax.p2c = (ax.type === 'log') ? function(px) { return fromLog(p2l(px)); } : p2l;\n\n    /*\n     * now type-specific conversions for **ALL** other combinations\n     * they're all written out, instead of being combinations of each other, for\n     * both clarity and speed.\n     */\n    if(['linear', '-'].indexOf(ax.type) !== -1) {\n        // all are data vals, but d and r need cleaning\n        ax.d2r = ax.r2d = ax.d2c = ax.r2c = ax.d2l = ax.r2l = cleanNumber;\n        ax.c2d = ax.c2r = ax.l2d = ax.l2r = ensureNumber;\n\n        ax.d2p = ax.r2p = function(v) { return ax.l2p(cleanNumber(v)); };\n        ax.p2d = ax.p2r = p2l;\n\n        ax.cleanPos = ensureNumber;\n    } else if(ax.type === 'log') {\n        // d and c are data vals, r and l are logged (but d and r need cleaning)\n        ax.d2r = ax.d2l = function(v, clip) { return toLog(cleanNumber(v), clip); };\n        ax.r2d = ax.r2c = function(v) { return fromLog(cleanNumber(v)); };\n\n        ax.d2c = ax.r2l = cleanNumber;\n        ax.c2d = ax.l2r = ensureNumber;\n\n        ax.c2r = toLog;\n        ax.l2d = fromLog;\n\n        ax.d2p = function(v, clip) { return ax.l2p(ax.d2r(v, clip)); };\n        ax.p2d = function(px) { return fromLog(p2l(px)); };\n\n        ax.r2p = function(v) { return ax.l2p(cleanNumber(v)); };\n        ax.p2r = p2l;\n\n        ax.cleanPos = ensureNumber;\n    } else if(ax.type === 'date') {\n        // r and d are date strings, l and c are ms\n\n        /*\n         * Any of these functions with r and d on either side, calendar is the\n         * **3rd** argument. log has reserved the second argument.\n         *\n         * Unless you need the special behavior of the second arg (ms2DateTime\n         * uses this to limit precision, toLog uses true to clip negatives\n         * to offscreen low rather than undefined), it's safe to pass 0.\n         */\n        ax.d2r = ax.r2d = Lib.identity;\n\n        ax.d2c = ax.r2c = ax.d2l = ax.r2l = dt2ms;\n        ax.c2d = ax.c2r = ax.l2d = ax.l2r = ms2dt;\n\n        ax.d2p = ax.r2p = function(v, _, calendar) { return ax.l2p(dt2ms(v, 0, calendar)); };\n        ax.p2d = ax.p2r = function(px, r, calendar) { return ms2dt(p2l(px), r, calendar); };\n\n        ax.cleanPos = function(v) { return Lib.cleanDate(v, BADNUM, ax.calendar); };\n    } else if(ax.type === 'category') {\n        // d is categories (string)\n        // c and l are indices (numbers)\n        // r is categories or numbers\n\n        ax.d2c = ax.d2l = setCategoryIndex;\n        ax.r2d = ax.c2d = ax.l2d = getCategoryName;\n\n        ax.d2r = ax.d2l_noadd = getCategoryPosition;\n\n        ax.r2c = function(v) {\n            var index = getCategoryPosition(v);\n            return index !== undefined ? index : ax.fraction2r(0.5);\n        };\n\n        ax.l2r = ax.c2r = ensureNumber;\n        ax.r2l = getCategoryPosition;\n\n        ax.d2p = function(v) { return ax.l2p(ax.r2c(v)); };\n        ax.p2d = function(px) { return getCategoryName(p2l(px)); };\n        ax.r2p = ax.d2p;\n        ax.p2r = p2l;\n\n        ax.cleanPos = function(v) {\n            if(typeof v === 'string' && v !== '') return v;\n            return ensureNumber(v);\n        };\n    } else if(ax.type === 'multicategory') {\n        // N.B. multicategory axes don't define d2c and d2l,\n        // as 'data-to-calcdata' conversion needs to take into\n        // account all data array items as in ax.makeCalcdata.\n\n        ax.r2d = ax.c2d = ax.l2d = getCategoryName;\n        ax.d2r = ax.d2l_noadd = getCategoryPosition;\n\n        ax.r2c = function(v) {\n            var index = getCategoryPosition(v);\n            return index !== undefined ? index : ax.fraction2r(0.5);\n        };\n\n        ax.r2c_just_indices = getCategoryIndex;\n\n        ax.l2r = ax.c2r = ensureNumber;\n        ax.r2l = getCategoryPosition;\n\n        ax.d2p = function(v) { return ax.l2p(ax.r2c(v)); };\n        ax.p2d = function(px) { return getCategoryName(p2l(px)); };\n        ax.r2p = ax.d2p;\n        ax.p2r = p2l;\n\n        ax.cleanPos = function(v) {\n            if(Array.isArray(v) || (typeof v === 'string' && v !== '')) return v;\n            return ensureNumber(v);\n        };\n\n        ax.setupMultiCategory = function(fullData) {\n            var traceIndices = ax._traceIndices;\n            var i, j;\n\n            var matchGroups = fullLayout._axisMatchGroups;\n            if(matchGroups && matchGroups.length && ax._categories.length === 0) {\n                for(i = 0; i < matchGroups.length; i++) {\n                    var group = matchGroups[i];\n                    if(group[axId]) {\n                        for(var axId2 in group) {\n                            if(axId2 !== axId) {\n                                var ax2 = fullLayout[axisIds.id2name(axId2)];\n                                traceIndices = traceIndices.concat(ax2._traceIndices);\n                            }\n                        }\n                    }\n                }\n            }\n\n            // [ [cnt, {$cat: index}], for 1,2 ]\n            var seen = [[0, {}], [0, {}]];\n            // [ [arrayIn[0][i], arrayIn[1][i]], for i .. N ]\n            var list = [];\n\n            for(i = 0; i < traceIndices.length; i++) {\n                var trace = fullData[traceIndices[i]];\n\n                if(axLetter in trace) {\n                    var arrayIn = trace[axLetter];\n                    var len = trace._length || Lib.minRowLength(arrayIn);\n\n                    if(isArrayOrTypedArray(arrayIn[0]) && isArrayOrTypedArray(arrayIn[1])) {\n                        for(j = 0; j < len; j++) {\n                            var v0 = arrayIn[0][j];\n                            var v1 = arrayIn[1][j];\n\n                            if(isValidCategory(v0) && isValidCategory(v1)) {\n                                list.push([v0, v1]);\n\n                                if(!(v0 in seen[0][1])) {\n                                    seen[0][1][v0] = seen[0][0]++;\n                                }\n                                if(!(v1 in seen[1][1])) {\n                                    seen[1][1][v1] = seen[1][0]++;\n                                }\n                            }\n                        }\n                    }\n                }\n            }\n\n            list.sort(function(a, b) {\n                var ind0 = seen[0][1];\n                var d = ind0[a[0]] - ind0[b[0]];\n                if(d) return d;\n\n                var ind1 = seen[1][1];\n                return ind1[a[1]] - ind1[b[1]];\n            });\n\n            for(i = 0; i < list.length; i++) {\n                setCategoryIndex(list[i]);\n            }\n        };\n    }\n\n    // find the range value at the specified (linear) fraction of the axis\n    ax.fraction2r = function(v) {\n        var rl0 = ax.r2l(ax.range[0]);\n        var rl1 = ax.r2l(ax.range[1]);\n        return ax.l2r(rl0 + v * (rl1 - rl0));\n    };\n\n    // find the fraction of the range at the specified range value\n    ax.r2fraction = function(v) {\n        var rl0 = ax.r2l(ax.range[0]);\n        var rl1 = ax.r2l(ax.range[1]);\n        return (ax.r2l(v) - rl0) / (rl1 - rl0);\n    };\n\n    /*\n     * cleanRange: make sure range is a couplet of valid & distinct values\n     * keep numbers away from the limits of floating point numbers,\n     * and dates away from the ends of our date system (+/- 9999 years)\n     *\n     * optional param rangeAttr: operate on a different attribute, like\n     * ax._r, rather than ax.range\n     */\n    ax.cleanRange = function(rangeAttr, opts) {\n        if(!opts) opts = {};\n        if(!rangeAttr) rangeAttr = 'range';\n\n        var range = Lib.nestedProperty(ax, rangeAttr).get();\n        var i, dflt;\n\n        if(ax.type === 'date') dflt = Lib.dfltRange(ax.calendar);\n        else if(axLetter === 'y') dflt = constants.DFLTRANGEY;\n        else dflt = opts.dfltRange || constants.DFLTRANGEX;\n\n        // make sure we don't later mutate the defaults\n        dflt = dflt.slice();\n\n        if(!range || range.length !== 2) {\n            Lib.nestedProperty(ax, rangeAttr).set(dflt);\n            return;\n        }\n\n        if(ax.type === 'date' && !ax.autorange) {\n            // check if milliseconds or js date objects are provided for range\n            // and convert to date strings\n            range[0] = Lib.cleanDate(range[0], BADNUM, ax.calendar);\n            range[1] = Lib.cleanDate(range[1], BADNUM, ax.calendar);\n        }\n\n        for(i = 0; i < 2; i++) {\n            if(ax.type === 'date') {\n                if(!Lib.isDateTime(range[i], ax.calendar)) {\n                    ax[rangeAttr] = dflt;\n                    break;\n                }\n\n                if(ax.r2l(range[0]) === ax.r2l(range[1])) {\n                    // split by +/- 1 second\n                    var linCenter = Lib.constrain(ax.r2l(range[0]),\n                        Lib.MIN_MS + 1000, Lib.MAX_MS - 1000);\n                    range[0] = ax.l2r(linCenter - 1000);\n                    range[1] = ax.l2r(linCenter + 1000);\n                    break;\n                }\n            } else {\n                if(!isNumeric(range[i])) {\n                    if(isNumeric(range[1 - i])) {\n                        range[i] = range[1 - i] * (i ? 10 : 0.1);\n                    } else {\n                        ax[rangeAttr] = dflt;\n                        break;\n                    }\n                }\n\n                if(range[i] < -FP_SAFE) range[i] = -FP_SAFE;\n                else if(range[i] > FP_SAFE) range[i] = FP_SAFE;\n\n                if(range[0] === range[1]) {\n                    // somewhat arbitrary: split by 1 or 1ppm, whichever is bigger\n                    var inc = Math.max(1, Math.abs(range[0] * 1e-6));\n                    range[0] -= inc;\n                    range[1] += inc;\n                }\n            }\n        }\n    };\n\n    // set scaling to pixels\n    ax.setScale = function(usePrivateRange) {\n        var gs = fullLayout._size;\n\n        // make sure we have a domain (pull it in from the axis\n        // this one is overlaying if necessary)\n        if(ax.overlaying) {\n            var ax2 = axisIds.getFromId({ _fullLayout: fullLayout }, ax.overlaying);\n            ax.domain = ax2.domain;\n        }\n\n        // While transitions are occuring, occurring, we get a double-transform\n        // issue if we transform the drawn layer *and* use the new axis range to\n        // draw the data. This allows us to construct setConvert using the pre-\n        // interaction values of the range:\n        var rangeAttr = (usePrivateRange && ax._r) ? '_r' : 'range';\n        var calendar = ax.calendar;\n        ax.cleanRange(rangeAttr);\n\n        var rl0 = ax.r2l(ax[rangeAttr][0], calendar);\n        var rl1 = ax.r2l(ax[rangeAttr][1], calendar);\n\n        if(axLetter === 'y') {\n            ax._offset = gs.t + (1 - ax.domain[1]) * gs.h;\n            ax._length = gs.h * (ax.domain[1] - ax.domain[0]);\n            ax._m = ax._length / (rl0 - rl1);\n            ax._b = -ax._m * rl1;\n        } else {\n            ax._offset = gs.l + ax.domain[0] * gs.w;\n            ax._length = gs.w * (ax.domain[1] - ax.domain[0]);\n            ax._m = ax._length / (rl1 - rl0);\n            ax._b = -ax._m * rl0;\n        }\n\n        if(!isFinite(ax._m) || !isFinite(ax._b) || ax._length < 0) {\n            fullLayout._replotting = false;\n            throw new Error('Something went wrong with axis scaling');\n        }\n    };\n\n    // makeCalcdata: takes an x or y array and converts it\n    // to a position on the axis object \"ax\"\n    // inputs:\n    //      trace - a data object from gd.data\n    //      axLetter - a string, either 'x' or 'y', for which item\n    //          to convert (TODO: is this now always the same as\n    //          the first letter of ax._id?)\n    // in case the expected data isn't there, make a list of\n    // integers based on the opposite data\n    ax.makeCalcdata = function(trace, axLetter) {\n        var arrayIn, arrayOut, i, len;\n\n        var axType = ax.type;\n        var cal = axType === 'date' && trace[axLetter + 'calendar'];\n\n        if(axLetter in trace) {\n            arrayIn = trace[axLetter];\n            len = trace._length || Lib.minRowLength(arrayIn);\n\n            if(Lib.isTypedArray(arrayIn) && (axType === 'linear' || axType === 'log')) {\n                if(len === arrayIn.length) {\n                    return arrayIn;\n                } else if(arrayIn.subarray) {\n                    return arrayIn.subarray(0, len);\n                }\n            }\n\n            if(axType === 'multicategory') {\n                return setMultiCategoryIndex(arrayIn, len);\n            }\n\n            arrayOut = new Array(len);\n            for(i = 0; i < len; i++) {\n                arrayOut[i] = ax.d2c(arrayIn[i], 0, cal);\n            }\n        } else {\n            var v0 = ((axLetter + '0') in trace) ? ax.d2c(trace[axLetter + '0'], 0, cal) : 0;\n            var dv = (trace['d' + axLetter]) ? Number(trace['d' + axLetter]) : 1;\n\n            // the opposing data, for size if we have x and dx etc\n            arrayIn = trace[{x: 'y', y: 'x'}[axLetter]];\n            len = trace._length || arrayIn.length;\n            arrayOut = new Array(len);\n\n            for(i = 0; i < len; i++) {\n                arrayOut[i] = v0 + i * dv;\n            }\n        }\n\n        return arrayOut;\n    };\n\n    ax.isValidRange = function(range) {\n        return (\n            Array.isArray(range) &&\n            range.length === 2 &&\n            isNumeric(ax.r2l(range[0])) &&\n            isNumeric(ax.r2l(range[1]))\n        );\n    };\n\n    ax.isPtWithinRange = function(d, calendar) {\n        var coord = ax.c2l(d[axLetter], null, calendar);\n        var r0 = ax.r2l(ax.range[0]);\n        var r1 = ax.r2l(ax.range[1]);\n\n        if(r0 < r1) {\n            return r0 <= coord && coord <= r1;\n        } else {\n            // Reversed axis case.\n            return r1 <= coord && coord <= r0;\n        }\n    };\n\n    // should skip if not category nor multicategory\n    ax.clearCalc = function() {\n        var emptyCategories = function() {\n            ax._categories = [];\n            ax._categoriesMap = {};\n        };\n\n        var matchGroups = fullLayout._axisMatchGroups;\n\n        if(matchGroups && matchGroups.length) {\n            var found = false;\n\n            for(var i = 0; i < matchGroups.length; i++) {\n                var group = matchGroups[i];\n\n                if(group[axId]) {\n                    found = true;\n                    var categories = null;\n                    var categoriesMap = null;\n\n                    for(var axId2 in group) {\n                        var ax2 = fullLayout[axisIds.id2name(axId2)];\n                        if(ax2._categories) {\n                            categories = ax2._categories;\n                            categoriesMap = ax2._categoriesMap;\n                            break;\n                        }\n                    }\n\n                    if(categories && categoriesMap) {\n                        ax._categories = categories;\n                        ax._categoriesMap = categoriesMap;\n                    } else {\n                        emptyCategories();\n                    }\n                    break;\n                }\n            }\n            if(!found) emptyCategories();\n        } else {\n            emptyCategories();\n        }\n\n        if(ax._initialCategories) {\n            for(var j = 0; j < ax._initialCategories.length; j++) {\n                setCategoryIndex(ax._initialCategories[j]);\n            }\n        }\n    };\n\n    // sort the axis (and all the matching ones) by _initialCategories\n    // returns the indices of the traces affected by the reordering\n    ax.sortByInitialCategories = function() {\n        var affectedTraces = [];\n        var emptyCategories = function() {\n            ax._categories = [];\n            ax._categoriesMap = {};\n        };\n\n        emptyCategories();\n\n        if(ax._initialCategories) {\n            for(var j = 0; j < ax._initialCategories.length; j++) {\n                setCategoryIndex(ax._initialCategories[j]);\n            }\n        }\n\n        affectedTraces = affectedTraces.concat(ax._traceIndices);\n\n        // Propagate to matching axes\n        var group = ax._matchGroup;\n        for(var axId2 in group) {\n            if(axId === axId2) continue;\n            var ax2 = fullLayout[axisIds.id2name(axId2)];\n            ax2._categories = ax._categories;\n            ax2._categoriesMap = ax._categoriesMap;\n            affectedTraces = affectedTraces.concat(ax2._traceIndices);\n        }\n        return affectedTraces;\n    };\n\n    // Propagate localization into the axis so that\n    // methods in Axes can use it w/o having to pass fullLayout\n    // Default (non-d3) number formatting uses separators directly\n    // dates and d3-formatted numbers use the d3 locale\n    // Fall back on default format for dummy axes that don't care about formatting\n    var locale = fullLayout._d3locale;\n    if(ax.type === 'date') {\n        ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;\n        ax._extraFormat = fullLayout._extraFormat;\n    }\n    // occasionally we need _numFormat to pass through\n    // even though it won't be needed by this axis\n    ax._separators = fullLayout.separators;\n    ax._numFormat = locale ? locale.numberFormat : d3.format;\n\n    // and for bar charts and box plots: reset forced minimum tick spacing\n    delete ax._minDtick;\n    delete ax._forceTick0;\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"./axis_ids\":770,\"./constants\":773,\"d3\":163,\"fast-isnumeric\":225}],786:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar layoutAttributes = _dereq_('./layout_attributes');\nvar handleArrayContainerDefaults = _dereq_('../array_container_defaults');\n\nmodule.exports = function handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options, config) {\n    if(!config || config.pass === 1) {\n        handlePrefixSuffix(containerIn, containerOut, coerce, axType, options);\n    }\n\n    if(!config || config.pass === 2) {\n        handleOtherDefaults(containerIn, containerOut, coerce, axType, options);\n    }\n};\n\nfunction handlePrefixSuffix(containerIn, containerOut, coerce, axType, options) {\n    var showAttrDflt = getShowAttrDflt(containerIn);\n\n    var tickPrefix = coerce('tickprefix');\n    if(tickPrefix) coerce('showtickprefix', showAttrDflt);\n\n    var tickSuffix = coerce('ticksuffix', options.tickSuffixDflt);\n    if(tickSuffix) coerce('showticksuffix', showAttrDflt);\n}\n\nfunction handleOtherDefaults(containerIn, containerOut, coerce, axType, options) {\n    var showAttrDflt = getShowAttrDflt(containerIn);\n\n    var tickPrefix = coerce('tickprefix');\n    if(tickPrefix) coerce('showtickprefix', showAttrDflt);\n\n    var tickSuffix = coerce('ticksuffix', options.tickSuffixDflt);\n    if(tickSuffix) coerce('showticksuffix', showAttrDflt);\n\n    var showTickLabels = coerce('showticklabels');\n    if(showTickLabels) {\n        var font = options.font || {};\n        var contColor = containerOut.color;\n        // as with titlefont.color, inherit axis.color only if one was\n        // explicitly provided\n        var dfltFontColor = (contColor && contColor !== layoutAttributes.color.dflt) ?\n            contColor : font.color;\n        Lib.coerceFont(coerce, 'tickfont', {\n            family: font.family,\n            size: font.size,\n            color: dfltFontColor\n        });\n        coerce('tickangle');\n\n        if(axType !== 'category') {\n            var tickFormat = coerce('tickformat');\n            var tickformatStops = containerIn.tickformatstops;\n            if(Array.isArray(tickformatStops) && tickformatStops.length) {\n                handleArrayContainerDefaults(containerIn, containerOut, {\n                    name: 'tickformatstops',\n                    inclusionAttr: 'enabled',\n                    handleItemDefaults: tickformatstopDefaults\n                });\n            }\n            if(!tickFormat && axType !== 'date') {\n                coerce('showexponent', showAttrDflt);\n                coerce('exponentformat');\n                coerce('separatethousands');\n            }\n        }\n    }\n}\n\n/*\n * Attributes 'showexponent', 'showtickprefix' and 'showticksuffix'\n * share values.\n *\n * If only 1 attribute is set,\n * the remaining attributes inherit that value.\n *\n * If 2 attributes are set to the same value,\n * the remaining attribute inherits that value.\n *\n * If 2 attributes are set to different values,\n * the remaining is set to its dflt value.\n *\n */\nfunction getShowAttrDflt(containerIn) {\n    var showAttrsAll = ['showexponent', 'showtickprefix', 'showticksuffix'];\n    var showAttrs = showAttrsAll.filter(function(a) {\n        return containerIn[a] !== undefined;\n    });\n    var sameVal = function(a) {\n        return containerIn[a] === containerIn[showAttrs[0]];\n    };\n\n    if(showAttrs.every(sameVal) || showAttrs.length === 1) {\n        return containerIn[showAttrs[0]];\n    }\n}\n\nfunction tickformatstopDefaults(valueIn, valueOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(valueIn, valueOut, layoutAttributes.tickformatstops, attr, dflt);\n    }\n\n    var enabled = coerce('enabled');\n    if(enabled) {\n        coerce('dtickrange');\n        coerce('value');\n    }\n}\n\n},{\"../../lib\":719,\"../array_container_defaults\":763,\"./layout_attributes\":779}],787:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar layoutAttributes = _dereq_('./layout_attributes');\n\n\n/**\n * options: inherits outerTicks from axes.handleAxisDefaults\n */\nmodule.exports = function handleTickDefaults(containerIn, containerOut, coerce, options) {\n    var tickLen = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'ticklen');\n    var tickWidth = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickwidth');\n    var tickColor = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickcolor', containerOut.color);\n    var showTicks = coerce('ticks', (options.outerTicks || tickLen || tickWidth || tickColor) ? 'outside' : '');\n\n    if(!showTicks) {\n        delete containerOut.ticklen;\n        delete containerOut.tickwidth;\n        delete containerOut.tickcolor;\n    }\n};\n\n},{\"../../lib\":719,\"./layout_attributes\":779}],788:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar cleanTicks = _dereq_('./clean_ticks');\n\nmodule.exports = function handleTickValueDefaults(containerIn, containerOut, coerce, axType) {\n    var tickmode;\n\n    if(containerIn.tickmode === 'array' &&\n            (axType === 'log' || axType === 'date')) {\n        tickmode = containerOut.tickmode = 'auto';\n    } else {\n        var tickmodeDefault = Array.isArray(containerIn.tickvals) ? 'array' :\n            containerIn.dtick ? 'linear' :\n            'auto';\n        tickmode = coerce('tickmode', tickmodeDefault);\n    }\n\n    if(tickmode === 'auto') coerce('nticks');\n    else if(tickmode === 'linear') {\n        // dtick is usually a positive number, but there are some\n        // special strings available for log or date axes\n        // tick0 also has special logic\n        var dtick = containerOut.dtick = cleanTicks.dtick(\n            containerIn.dtick, axType);\n        containerOut.tick0 = cleanTicks.tick0(\n            containerIn.tick0, axType, containerOut.calendar, dtick);\n    } else if(axType !== 'multicategory') {\n        var tickvals = coerce('tickvals');\n        if(tickvals === undefined) containerOut.tickmode = 'auto';\n        else coerce('ticktext');\n    }\n};\n\n},{\"./clean_ticks\":772}],789:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Registry = _dereq_('../../registry');\nvar Drawing = _dereq_('../../components/drawing');\nvar Axes = _dereq_('./axes');\n\n/**\n * transitionAxes\n *\n * transition axes from one set of ranges to another, using a svg\n * transformations, similar to during panning.\n *\n * @param {DOM element | object} gd\n * @param {array} edits : array of 'edits', each item with\n * - plotinfo {object} subplot object\n * - xr0 {array} initial x-range\n * - xr1 {array} end x-range\n * - yr0 {array} initial y-range\n * - yr1 {array} end y-range\n * @param {object} transitionOpts\n * @param {function} makeOnCompleteCallback\n */\nmodule.exports = function transitionAxes(gd, edits, transitionOpts, makeOnCompleteCallback) {\n    var fullLayout = gd._fullLayout;\n\n    // special case for redraw:false Plotly.animate that relies on this\n    // to update axis-referenced layout components\n    if(edits.length === 0) {\n        Axes.redrawComponents(gd);\n        return;\n    }\n\n    function unsetSubplotTransform(subplot) {\n        var xa = subplot.xaxis;\n        var ya = subplot.yaxis;\n\n        fullLayout._defs.select('#' + subplot.clipId + '> rect')\n            .call(Drawing.setTranslate, 0, 0)\n            .call(Drawing.setScale, 1, 1);\n\n        subplot.plot\n            .call(Drawing.setTranslate, xa._offset, ya._offset)\n            .call(Drawing.setScale, 1, 1);\n\n        var traceGroups = subplot.plot.selectAll('.scatterlayer .trace');\n\n        // This is specifically directed at scatter traces, applying an inverse\n        // scale to individual points to counteract the scale of the trace\n        // as a whole:\n        traceGroups.selectAll('.point')\n            .call(Drawing.setPointGroupScale, 1, 1);\n        traceGroups.selectAll('.textpoint')\n            .call(Drawing.setTextPointsScale, 1, 1);\n        traceGroups\n            .call(Drawing.hideOutsideRangePoints, subplot);\n    }\n\n    function updateSubplot(edit, progress) {\n        var plotinfo = edit.plotinfo;\n        var xa = plotinfo.xaxis;\n        var ya = plotinfo.yaxis;\n\n        var xr0 = edit.xr0;\n        var xr1 = edit.xr1;\n        var xlen = xa._length;\n        var yr0 = edit.yr0;\n        var yr1 = edit.yr1;\n        var ylen = ya._length;\n\n        var editX = !!xr1;\n        var editY = !!yr1;\n        var viewBox = [];\n\n        if(editX) {\n            var dx0 = xr0[1] - xr0[0];\n            var dx1 = xr1[1] - xr1[0];\n            viewBox[0] = (xr0[0] * (1 - progress) + progress * xr1[0] - xr0[0]) / (xr0[1] - xr0[0]) * xlen;\n            viewBox[2] = xlen * ((1 - progress) + progress * dx1 / dx0);\n            xa.range[0] = xr0[0] * (1 - progress) + progress * xr1[0];\n            xa.range[1] = xr0[1] * (1 - progress) + progress * xr1[1];\n        } else {\n            viewBox[0] = 0;\n            viewBox[2] = xlen;\n        }\n\n        if(editY) {\n            var dy0 = yr0[1] - yr0[0];\n            var dy1 = yr1[1] - yr1[0];\n            viewBox[1] = (yr0[1] * (1 - progress) + progress * yr1[1] - yr0[1]) / (yr0[0] - yr0[1]) * ylen;\n            viewBox[3] = ylen * ((1 - progress) + progress * dy1 / dy0);\n            ya.range[0] = yr0[0] * (1 - progress) + progress * yr1[0];\n            ya.range[1] = yr0[1] * (1 - progress) + progress * yr1[1];\n        } else {\n            viewBox[1] = 0;\n            viewBox[3] = ylen;\n        }\n\n        Axes.drawOne(gd, xa, {skipTitle: true});\n        Axes.drawOne(gd, ya, {skipTitle: true});\n        Axes.redrawComponents(gd, [xa._id, ya._id]);\n\n        var xScaleFactor = editX ? xlen / viewBox[2] : 1;\n        var yScaleFactor = editY ? ylen / viewBox[3] : 1;\n        var clipDx = editX ? viewBox[0] : 0;\n        var clipDy = editY ? viewBox[1] : 0;\n        var fracDx = editX ? (viewBox[0] / viewBox[2] * xlen) : 0;\n        var fracDy = editY ? (viewBox[1] / viewBox[3] * ylen) : 0;\n        var plotDx = xa._offset - fracDx;\n        var plotDy = ya._offset - fracDy;\n\n        plotinfo.clipRect\n            .call(Drawing.setTranslate, clipDx, clipDy)\n            .call(Drawing.setScale, 1 / xScaleFactor, 1 / yScaleFactor);\n\n        plotinfo.plot\n            .call(Drawing.setTranslate, plotDx, plotDy)\n            .call(Drawing.setScale, xScaleFactor, yScaleFactor);\n\n        // apply an inverse scale to individual points to counteract\n        // the scale of the trace group.\n        Drawing.setPointGroupScale(plotinfo.zoomScalePts, 1 / xScaleFactor, 1 / yScaleFactor);\n        Drawing.setTextPointsScale(plotinfo.zoomScaleTxt, 1 / xScaleFactor, 1 / yScaleFactor);\n    }\n\n    var onComplete;\n    if(makeOnCompleteCallback) {\n        // This module makes the choice whether or not it notifies Plotly.transition\n        // about completion:\n        onComplete = makeOnCompleteCallback();\n    }\n\n    function transitionComplete() {\n        var aobj = {};\n\n        for(var i = 0; i < edits.length; i++) {\n            var edit = edits[i];\n            if(edit.xr1) aobj[edit.plotinfo.xaxis._name + '.range'] = edit.xr1.slice();\n            if(edit.yr1) aobj[edit.plotinfo.yaxis._name + '.range'] = edit.yr1.slice();\n        }\n\n        // Signal that this transition has completed:\n        onComplete && onComplete();\n\n        return Registry.call('relayout', gd, aobj).then(function() {\n            for(var i = 0; i < edits.length; i++) {\n                unsetSubplotTransform(edits[i].plotinfo);\n            }\n        });\n    }\n\n    function transitionInterrupt() {\n        var aobj = {};\n\n        for(var i = 0; i < edits.length; i++) {\n            var edit = edits[i];\n            if(edit.xr0) aobj[edit.plotinfo.xaxis._name + '.range'] = edit.xr0.slice();\n            if(edit.yr0) aobj[edit.plotinfo.yaxis._name + '.range'] = edit.yr0.slice();\n        }\n\n        return Registry.call('relayout', gd, aobj).then(function() {\n            for(var i = 0; i < edits.length; i++) {\n                unsetSubplotTransform(edits[i].plotinfo);\n            }\n        });\n    }\n\n    var t1, t2, raf;\n    var easeFn = d3.ease(transitionOpts.easing);\n\n    gd._transitionData._interruptCallbacks.push(function() {\n        window.cancelAnimationFrame(raf);\n        raf = null;\n        return transitionInterrupt();\n    });\n\n    function doFrame() {\n        t2 = Date.now();\n\n        var tInterp = Math.min(1, (t2 - t1) / transitionOpts.duration);\n        var progress = easeFn(tInterp);\n\n        for(var i = 0; i < edits.length; i++) {\n            updateSubplot(edits[i], progress);\n        }\n\n        if(t2 - t1 > transitionOpts.duration) {\n            transitionComplete();\n            raf = window.cancelAnimationFrame(doFrame);\n        } else {\n            raf = window.requestAnimationFrame(doFrame);\n        }\n    }\n\n    t1 = Date.now();\n    raf = window.requestAnimationFrame(doFrame);\n\n    return Promise.resolve();\n};\n\n},{\"../../components/drawing\":614,\"../../registry\":847,\"./axes\":767,\"d3\":163}],790:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar traceIs = _dereq_('../../registry').traceIs;\nvar autoType = _dereq_('./axis_autotype');\n\n/*\n *  data: the plot data to use in choosing auto type\n *  name: axis object name (ie 'xaxis') if one should be stored\n */\nmodule.exports = function handleTypeDefaults(containerIn, containerOut, coerce, options) {\n    var axType = coerce('type', (options.splomStash || {}).type);\n\n    if(axType === '-') {\n        setAutoType(containerOut, options.data);\n\n        if(containerOut.type === '-') {\n            containerOut.type = 'linear';\n        } else {\n            // copy autoType back to input axis\n            // note that if this object didn't exist\n            // in the input layout, we have to put it in\n            // this happens in the main supplyDefaults function\n            containerIn.type = containerOut.type;\n        }\n    }\n};\n\nfunction setAutoType(ax, data) {\n    // new logic: let people specify any type they want,\n    // only autotype if type is '-'\n    if(ax.type !== '-') return;\n\n    var id = ax._id;\n    var axLetter = id.charAt(0);\n\n    // support 3d\n    if(id.indexOf('scene') !== -1) id = axLetter;\n\n    var d0 = getFirstNonEmptyTrace(data, id, axLetter);\n    if(!d0) return;\n\n    // first check for histograms, as the count direction\n    // should always default to a linear axis\n    if(d0.type === 'histogram' &&\n            axLetter === {v: 'y', h: 'x'}[d0.orientation || 'v']) {\n        ax.type = 'linear';\n        return;\n    }\n\n    var calAttr = axLetter + 'calendar';\n    var calendar = d0[calAttr];\n    var opts = {noMultiCategory: !traceIs(d0, 'cartesian') || traceIs(d0, 'noMultiCategory')};\n    var i;\n\n    // check all boxes on this x axis to see\n    // if they're dates, numbers, or categories\n    if(isBoxWithoutPositionCoords(d0, axLetter)) {\n        var posLetter = getBoxPosLetter(d0);\n        var boxPositions = [];\n\n        for(i = 0; i < data.length; i++) {\n            var trace = data[i];\n            if(!traceIs(trace, 'box-violin') || (trace[axLetter + 'axis'] || axLetter) !== id) continue;\n\n            if(trace[posLetter] !== undefined) boxPositions.push(trace[posLetter][0]);\n            else if(trace.name !== undefined) boxPositions.push(trace.name);\n            else boxPositions.push('text');\n\n            if(trace[calAttr] !== calendar) calendar = undefined;\n        }\n\n        ax.type = autoType(boxPositions, calendar, opts);\n    } else if(d0.type === 'splom') {\n        var dimensions = d0.dimensions;\n        var dim = dimensions[d0._axesDim[id]];\n        if(dim.visible) ax.type = autoType(dim.values, calendar, opts);\n    } else {\n        ax.type = autoType(d0[axLetter] || [d0[axLetter + '0']], calendar, opts);\n    }\n}\n\nfunction getFirstNonEmptyTrace(data, id, axLetter) {\n    for(var i = 0; i < data.length; i++) {\n        var trace = data[i];\n\n        if(trace.type === 'splom' &&\n                trace._length > 0 &&\n                (trace['_' + axLetter + 'axes'] || {})[id]\n        ) {\n            return trace;\n        }\n\n        if((trace[axLetter + 'axis'] || axLetter) === id) {\n            if(isBoxWithoutPositionCoords(trace, axLetter)) {\n                return trace;\n            } else if((trace[axLetter] || []).length || trace[axLetter + '0']) {\n                return trace;\n            }\n        }\n    }\n}\n\nfunction getBoxPosLetter(trace) {\n    return {v: 'x', h: 'y'}[trace.orientation || 'v'];\n}\n\nfunction isBoxWithoutPositionCoords(trace, axLetter) {\n    var posLetter = getBoxPosLetter(trace);\n    var isBox = traceIs(trace, 'box-violin');\n    var isCandlestick = traceIs(trace._fullInput || {}, 'candlestick');\n\n    return (\n        isBox &&\n        !isCandlestick &&\n        axLetter === posLetter &&\n        trace[posLetter] === undefined &&\n        trace[posLetter + '0'] === undefined\n    );\n}\n\n},{\"../../registry\":847,\"./axis_autotype\":768}],791:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../registry');\nvar Lib = _dereq_('../lib');\n\n/*\n * Create or update an observer. This function is designed to be\n * idempotent so that it can be called over and over as the component\n * updates, and will attach and detach listeners as needed.\n *\n * @param {optional object} container\n *      An object on which the observer is stored. This is the mechanism\n *      by which it is idempotent. If it already exists, another won't be\n *      added. Each time it's called, the value lookup table is updated.\n * @param {array} commandList\n *      An array of commands, following either `buttons` of `updatemenus`\n *      or `steps` of `sliders`.\n * @param {function} onchange\n *      A listener called when the value is changed. Receives data object\n *      with information about the new state.\n */\nexports.manageCommandObserver = function(gd, container, commandList, onchange) {\n    var ret = {};\n    var enabled = true;\n\n    if(container && container._commandObserver) {\n        ret = container._commandObserver;\n    }\n\n    if(!ret.cache) {\n        ret.cache = {};\n    }\n\n    // Either create or just recompute this:\n    ret.lookupTable = {};\n\n    var binding = exports.hasSimpleAPICommandBindings(gd, commandList, ret.lookupTable);\n\n    if(container && container._commandObserver) {\n        if(!binding) {\n            // If container exists and there are no longer any bindings,\n            // remove existing:\n            if(container._commandObserver.remove) {\n                container._commandObserver.remove();\n                container._commandObserver = null;\n                return ret;\n            }\n        } else {\n            // If container exists and there *are* bindings, then the lookup\n            // table should have been updated and check is already attached,\n            // so there's nothing to be done:\n            return ret;\n        }\n    }\n\n    // Determine whether there's anything to do for this binding:\n\n    if(binding) {\n        // Build the cache:\n        bindingValueHasChanged(gd, binding, ret.cache);\n\n        ret.check = function check() {\n            if(!enabled) return;\n\n            var update = bindingValueHasChanged(gd, binding, ret.cache);\n\n            if(update.changed && onchange) {\n                // Disable checks for the duration of this command in order to avoid\n                // infinite loops:\n                if(ret.lookupTable[update.value] !== undefined) {\n                    ret.disable();\n                    Promise.resolve(onchange({\n                        value: update.value,\n                        type: binding.type,\n                        prop: binding.prop,\n                        traces: binding.traces,\n                        index: ret.lookupTable[update.value]\n                    })).then(ret.enable, ret.enable);\n                }\n            }\n\n            return update.changed;\n        };\n\n        var checkEvents = [\n            'plotly_relayout',\n            'plotly_redraw',\n            'plotly_restyle',\n            'plotly_update',\n            'plotly_animatingframe',\n            'plotly_afterplot'\n        ];\n\n        for(var i = 0; i < checkEvents.length; i++) {\n            gd._internalOn(checkEvents[i], ret.check);\n        }\n\n        ret.remove = function() {\n            for(var i = 0; i < checkEvents.length; i++) {\n                gd._removeInternalListener(checkEvents[i], ret.check);\n            }\n        };\n    } else {\n        // TODO: It'd be really neat to actually give a *reason* for this, but at least a warning\n        // is a start\n        Lib.log('Unable to automatically bind plot updates to API command');\n\n        ret.lookupTable = {};\n        ret.remove = function() {};\n    }\n\n    ret.disable = function disable() {\n        enabled = false;\n    };\n\n    ret.enable = function enable() {\n        enabled = true;\n    };\n\n    if(container) {\n        container._commandObserver = ret;\n    }\n\n    return ret;\n};\n\n/*\n * This function checks to see if an array of objects containing\n * method and args properties is compatible with automatic two-way\n * binding. The criteria right now are that\n *\n *   1. multiple traces may be affected\n *   2. only one property may be affected\n *   3. the same property must be affected by all commands\n */\nexports.hasSimpleAPICommandBindings = function(gd, commandList, bindingsByValue) {\n    var i;\n    var n = commandList.length;\n\n    var refBinding;\n\n    for(i = 0; i < n; i++) {\n        var binding;\n        var command = commandList[i];\n        var method = command.method;\n        var args = command.args;\n\n        if(!Array.isArray(args)) args = [];\n\n        // If any command has no method, refuse to bind:\n        if(!method) {\n            return false;\n        }\n        var bindings = exports.computeAPICommandBindings(gd, method, args);\n\n        // Right now, handle one and *only* one property being set:\n        if(bindings.length !== 1) {\n            return false;\n        }\n\n        if(!refBinding) {\n            refBinding = bindings[0];\n            if(Array.isArray(refBinding.traces)) {\n                refBinding.traces.sort();\n            }\n        } else {\n            binding = bindings[0];\n            if(binding.type !== refBinding.type) {\n                return false;\n            }\n            if(binding.prop !== refBinding.prop) {\n                return false;\n            }\n            if(Array.isArray(refBinding.traces)) {\n                if(Array.isArray(binding.traces)) {\n                    binding.traces.sort();\n                    for(var j = 0; j < refBinding.traces.length; j++) {\n                        if(refBinding.traces[j] !== binding.traces[j]) {\n                            return false;\n                        }\n                    }\n                } else {\n                    return false;\n                }\n            } else {\n                if(binding.prop !== refBinding.prop) {\n                    return false;\n                }\n            }\n        }\n\n        binding = bindings[0];\n        var value = binding.value;\n        if(Array.isArray(value)) {\n            if(value.length === 1) {\n                value = value[0];\n            } else {\n                return false;\n            }\n        }\n        if(bindingsByValue) {\n            bindingsByValue[value] = i;\n        }\n    }\n\n    return refBinding;\n};\n\nfunction bindingValueHasChanged(gd, binding, cache) {\n    var container, value, obj;\n    var changed = false;\n\n    if(binding.type === 'data') {\n        // If it's data, we need to get a trace. Based on the limited scope\n        // of what we cover, we can just take the first trace from the list,\n        // or otherwise just the first trace:\n        container = gd._fullData[binding.traces !== null ? binding.traces[0] : 0];\n    } else if(binding.type === 'layout') {\n        container = gd._fullLayout;\n    } else {\n        return false;\n    }\n\n    value = Lib.nestedProperty(container, binding.prop).get();\n\n    obj = cache[binding.type] = cache[binding.type] || {};\n\n    if(obj.hasOwnProperty(binding.prop)) {\n        if(obj[binding.prop] !== value) {\n            changed = true;\n        }\n    }\n\n    obj[binding.prop] = value;\n\n    return {\n        changed: changed,\n        value: value\n    };\n}\n\n/*\n * Execute an API command. There's really not much to this; it just provides\n * a common hook so that implementations don't need to be synchronized across\n * multiple components with the ability to invoke API commands.\n *\n * @param {string} method\n *      The name of the plotly command to execute. Must be one of 'animate',\n *      'restyle', 'relayout', 'update'.\n * @param {array} args\n *      A list of arguments passed to the API command\n */\nexports.executeAPICommand = function(gd, method, args) {\n    if(method === 'skip') return Promise.resolve();\n\n    var _method = Registry.apiMethodRegistry[method];\n    var allArgs = [gd];\n    if(!Array.isArray(args)) args = [];\n\n    for(var i = 0; i < args.length; i++) {\n        allArgs.push(args[i]);\n    }\n\n    return _method.apply(null, allArgs).catch(function(err) {\n        Lib.warn('API call to Plotly.' + method + ' rejected.', err);\n        return Promise.reject(err);\n    });\n};\n\nexports.computeAPICommandBindings = function(gd, method, args) {\n    var bindings;\n\n    if(!Array.isArray(args)) args = [];\n\n    switch(method) {\n        case 'restyle':\n            bindings = computeDataBindings(gd, args);\n            break;\n        case 'relayout':\n            bindings = computeLayoutBindings(gd, args);\n            break;\n        case 'update':\n            bindings = computeDataBindings(gd, [args[0], args[2]])\n                .concat(computeLayoutBindings(gd, [args[1]]));\n            break;\n        case 'animate':\n            bindings = computeAnimateBindings(gd, args);\n            break;\n        default:\n            // This is the case where intelligent logic about what affects\n            // this command is not implemented. It causes no ill effects.\n            // For example, addFrames simply won't bind to a control component.\n            bindings = [];\n    }\n    return bindings;\n};\n\nfunction computeAnimateBindings(gd, args) {\n    // We'll assume that the only relevant modification an animation\n    // makes that's meaningfully tracked is the frame:\n    if(Array.isArray(args[0]) && args[0].length === 1 && ['string', 'number'].indexOf(typeof args[0][0]) !== -1) {\n        return [{type: 'layout', prop: '_currentFrame', value: args[0][0].toString()}];\n    } else {\n        return [];\n    }\n}\n\nfunction computeLayoutBindings(gd, args) {\n    var bindings = [];\n\n    var astr = args[0];\n    var aobj = {};\n    if(typeof astr === 'string') {\n        aobj[astr] = args[1];\n    } else if(Lib.isPlainObject(astr)) {\n        aobj = astr;\n    } else {\n        return bindings;\n    }\n\n    crawl(aobj, function(path, attrName, attr) {\n        bindings.push({type: 'layout', prop: path, value: attr});\n    }, '', 0);\n\n    return bindings;\n}\n\nfunction computeDataBindings(gd, args) {\n    var traces, astr, val, aobj;\n    var bindings = [];\n\n    // Logic copied from Plotly.restyle:\n    astr = args[0];\n    val = args[1];\n    traces = args[2];\n    aobj = {};\n    if(typeof astr === 'string') {\n        aobj[astr] = val;\n    } else if(Lib.isPlainObject(astr)) {\n        // the 3-arg form\n        aobj = astr;\n\n        if(traces === undefined) {\n            traces = val;\n        }\n    } else {\n        return bindings;\n    }\n\n    if(traces === undefined) {\n        // Explicitly assign this to null instead of undefined:\n        traces = null;\n    }\n\n    crawl(aobj, function(path, attrName, _attr) {\n        var thisTraces;\n        var attr;\n\n        if(Array.isArray(_attr)) {\n            attr = _attr.slice();\n\n            var nAttr = Math.min(attr.length, gd.data.length);\n            if(traces) {\n                nAttr = Math.min(nAttr, traces.length);\n            }\n            thisTraces = [];\n            for(var j = 0; j < nAttr; j++) {\n                thisTraces[j] = traces ? traces[j] : j;\n            }\n        } else {\n            attr = _attr;\n            thisTraces = traces ? traces.slice() : null;\n        }\n\n        // Convert [7] to just 7 when traces is null:\n        if(thisTraces === null) {\n            if(Array.isArray(attr)) {\n                attr = attr[0];\n            }\n        } else if(Array.isArray(thisTraces)) {\n            if(!Array.isArray(attr)) {\n                var tmp = attr;\n                attr = [];\n                for(var i = 0; i < thisTraces.length; i++) {\n                    attr[i] = tmp;\n                }\n            }\n            attr.length = Math.min(thisTraces.length, attr.length);\n        }\n\n        bindings.push({\n            type: 'data',\n            prop: path,\n            traces: thisTraces,\n            value: attr\n        });\n    }, '', 0);\n\n    return bindings;\n}\n\nfunction crawl(attrs, callback, path, depth) {\n    Object.keys(attrs).forEach(function(attrName) {\n        var attr = attrs[attrName];\n\n        if(attrName[0] === '_') return;\n\n        var thisPath = path + (depth > 0 ? '.' : '') + attrName;\n\n        if(Lib.isPlainObject(attr)) {\n            crawl(attr, callback, thisPath, depth + 1);\n        } else {\n            // Only execute the callback on leaf nodes:\n            callback(thisPath, attrName, attr);\n        }\n    });\n}\n\n},{\"../lib\":719,\"../registry\":847}],792:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar extendFlat = _dereq_('../lib/extend').extendFlat;\n\n/**\n * Make a xy domain attribute group\n *\n * @param {object} opts\n *   @param {string}\n *     opts.name: name to be inserted in the default description\n *   @param {boolean}\n *     opts.trace: set to true for trace containers\n *   @param {string}\n *     opts.editType: editType for all pieces\n *   @param {boolean}\n *     opts.noGridCell: set to true to omit `row` and `column`\n *\n * @param {object} extra\n *   @param {string}\n *     extra.description: extra description. N.B we use\n *     a separate extra container to make it compatible with\n *     the compress_attributes transform.\n *\n * @return {object} attributes object containing {x,y} as specified\n */\nexports.attributes = function(opts, extra) {\n    opts = opts || {};\n    extra = extra || {};\n\n    var base = {\n        valType: 'info_array',\n        \n        editType: opts.editType,\n        items: [\n            {valType: 'number', min: 0, max: 1, editType: opts.editType},\n            {valType: 'number', min: 0, max: 1, editType: opts.editType}\n        ],\n        dflt: [0, 1]\n    };\n\n    var namePart = opts.name ? opts.name + ' ' : '';\n    var contPart = opts.trace ? 'trace ' : 'subplot ';\n    var descPart = extra.description ? ' ' + extra.description : '';\n\n    var out = {\n        x: extendFlat({}, base, {\n            \n        }),\n        y: extendFlat({}, base, {\n            \n        }),\n        editType: opts.editType\n    };\n\n    if(!opts.noGridCell) {\n        out.row = {\n            valType: 'integer',\n            min: 0,\n            dflt: 0,\n            \n            editType: opts.editType,\n            \n        };\n        out.column = {\n            valType: 'integer',\n            min: 0,\n            dflt: 0,\n            \n            editType: opts.editType,\n            \n        };\n    }\n\n    return out;\n};\n\nexports.defaults = function(containerOut, layout, coerce, dfltDomains) {\n    var dfltX = (dfltDomains && dfltDomains.x) || [0, 1];\n    var dfltY = (dfltDomains && dfltDomains.y) || [0, 1];\n\n    var grid = layout.grid;\n    if(grid) {\n        var column = coerce('domain.column');\n        if(column !== undefined) {\n            if(column < grid.columns) dfltX = grid._domains.x[column];\n            else delete containerOut.domain.column;\n        }\n\n        var row = coerce('domain.row');\n        if(row !== undefined) {\n            if(row < grid.rows) dfltY = grid._domains.y[row];\n            else delete containerOut.domain.row;\n        }\n    }\n\n    coerce('domain.x', dfltX);\n    coerce('domain.y', dfltY);\n};\n\n},{\"../lib/extend\":710}],793:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/*\n * make a font attribute group\n *\n * @param {object} opts\n *   @param {string}\n *     opts.description: where & how this font is used\n *   @param {optional bool} arrayOk:\n *     should each part (family, size, color) be arrayOk? default false.\n *   @param {string} editType:\n *     the editType for all pieces of this font\n *   @param {optional string} colorEditType:\n *     a separate editType just for color\n *\n * @return {object} attributes object containing {family, size, color} as specified\n */\nmodule.exports = function(opts) {\n    var editType = opts.editType;\n    var colorEditType = opts.colorEditType;\n    if(colorEditType === undefined) colorEditType = editType;\n    var attrs = {\n        family: {\n            valType: 'string',\n            \n            noBlank: true,\n            strict: true,\n            editType: editType,\n            \n        },\n        size: {\n            valType: 'number',\n            \n            min: 1,\n            editType: editType\n        },\n        color: {\n            valType: 'color',\n            \n            editType: colorEditType\n        },\n        editType: editType,\n        // blank strings so compress_attributes can remove\n        // TODO - that's uber hacky... better solution?\n        \n    };\n\n    if(opts.arrayOk) {\n        attrs.family.arrayOk = true;\n        attrs.size.arrayOk = true;\n        attrs.color.arrayOk = true;\n    }\n\n    return attrs;\n};\n\n},{}],794:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    _isLinkedToArray: 'frames_entry',\n\n    group: {\n        valType: 'string',\n        \n        \n    },\n    name: {\n        valType: 'string',\n        \n        \n    },\n    traces: {\n        valType: 'any',\n        \n        \n    },\n    baseframe: {\n        valType: 'string',\n        \n        \n    },\n    data: {\n        valType: 'any',\n        \n        \n    },\n    layout: {\n        valType: 'any',\n        \n        \n    }\n};\n\n},{}],795:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// projection names to d3 function name\nexports.projNames = {\n    // d3.geo.projection\n    'equirectangular': 'equirectangular',\n    'mercator': 'mercator',\n    'orthographic': 'orthographic',\n    'natural earth': 'naturalEarth',\n    'kavrayskiy7': 'kavrayskiy7',\n    'miller': 'miller',\n    'robinson': 'robinson',\n    'eckert4': 'eckert4',\n    'azimuthal equal area': 'azimuthalEqualArea',\n    'azimuthal equidistant': 'azimuthalEquidistant',\n    'conic equal area': 'conicEqualArea',\n    'conic conformal': 'conicConformal',\n    'conic equidistant': 'conicEquidistant',\n    'gnomonic': 'gnomonic',\n    'stereographic': 'stereographic',\n    'mollweide': 'mollweide',\n    'hammer': 'hammer',\n    'transverse mercator': 'transverseMercator',\n    'albers usa': 'albersUsa',\n    'winkel tripel': 'winkel3',\n    'aitoff': 'aitoff',\n    'sinusoidal': 'sinusoidal'\n};\n\n// name of the axes\nexports.axesNames = ['lonaxis', 'lataxis'];\n\n// max longitudinal angular span (EXPERIMENTAL)\nexports.lonaxisSpan = {\n    'orthographic': 180,\n    'azimuthal equal area': 360,\n    'azimuthal equidistant': 360,\n    'conic conformal': 180,\n    'gnomonic': 160,\n    'stereographic': 180,\n    'transverse mercator': 180,\n    '*': 360\n};\n\n// max latitudinal angular span (EXPERIMENTAL)\nexports.lataxisSpan = {\n    'conic conformal': 150,\n    'stereographic': 179.5,\n    '*': 180\n};\n\n// defaults for each scope\nexports.scopeDefaults = {\n    world: {\n        lonaxisRange: [-180, 180],\n        lataxisRange: [-90, 90],\n        projType: 'equirectangular',\n        projRotate: [0, 0, 0]\n    },\n    usa: {\n        lonaxisRange: [-180, -50],\n        lataxisRange: [15, 80],\n        projType: 'albers usa'\n    },\n    europe: {\n        lonaxisRange: [-30, 60],\n        lataxisRange: [30, 85],\n        projType: 'conic conformal',\n        projRotate: [15, 0, 0],\n        projParallels: [0, 60]\n    },\n    asia: {\n        lonaxisRange: [22, 160],\n        lataxisRange: [-15, 55],\n        projType: 'mercator',\n        projRotate: [0, 0, 0]\n    },\n    africa: {\n        lonaxisRange: [-30, 60],\n        lataxisRange: [-40, 40],\n        projType: 'mercator',\n        projRotate: [0, 0, 0]\n    },\n    'north america': {\n        lonaxisRange: [-180, -45],\n        lataxisRange: [5, 85],\n        projType: 'conic conformal',\n        projRotate: [-100, 0, 0],\n        projParallels: [29.5, 45.5]\n    },\n    'south america': {\n        lonaxisRange: [-100, -30],\n        lataxisRange: [-60, 15],\n        projType: 'mercator',\n        projRotate: [0, 0, 0]\n    }\n};\n\n// angular pad to avoid rounding error around clip angles\nexports.clipPad = 1e-3;\n\n// map projection precision\nexports.precision = 0.1;\n\n// default land and water fill colors\nexports.landColor = '#F0DC82';\nexports.waterColor = '#3399FF';\n\n// locationmode to layer name\nexports.locationmodeToLayer = {\n    'ISO-3': 'countries',\n    'USA-states': 'subunits',\n    'country names': 'countries'\n};\n\n// SVG element for a sphere (use to frame maps)\nexports.sphereSVG = {type: 'Sphere'};\n\n// N.B. base layer names must be the same as in the topojson files\n\n// base layer with a fill color\nexports.fillLayers = {\n    ocean: 1,\n    land: 1,\n    lakes: 1\n};\n\n// base layer with a only a line color\nexports.lineLayers = {\n    subunits: 1,\n    countries: 1,\n    coastlines: 1,\n    rivers: 1,\n    frame: 1\n};\n\nexports.layers = [\n    'bg',\n    'ocean', 'land', 'lakes',\n    'subunits', 'countries', 'coastlines', 'rivers',\n    'lataxis', 'lonaxis', 'frame',\n    'backplot',\n    'frontplot'\n];\n\nexports.layersForChoropleth = [\n    'bg',\n    'ocean', 'land',\n    'subunits', 'countries', 'coastlines',\n    'lataxis', 'lonaxis', 'frame',\n    'backplot',\n    'rivers', 'lakes',\n    'frontplot'\n];\n\nexports.layerNameToAdjective = {\n    ocean: 'ocean',\n    land: 'land',\n    lakes: 'lake',\n    subunits: 'subunit',\n    countries: 'country',\n    coastlines: 'coastline',\n    rivers: 'river',\n    frame: 'frame'\n};\n\n},{}],796:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/* global PlotlyGeoAssets:false */\n\nvar d3 = _dereq_('d3');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar Fx = _dereq_('../../components/fx');\nvar Plots = _dereq_('../plots');\nvar Axes = _dereq_('../cartesian/axes');\nvar dragElement = _dereq_('../../components/dragelement');\nvar prepSelect = _dereq_('../cartesian/select').prepSelect;\nvar selectOnClick = _dereq_('../cartesian/select').selectOnClick;\n\nvar createGeoZoom = _dereq_('./zoom');\nvar constants = _dereq_('./constants');\n\nvar topojsonUtils = _dereq_('../../lib/topojson_utils');\nvar topojsonFeature = _dereq_('topojson-client').feature;\n\n_dereq_('./projections')(d3);\n\nfunction Geo(opts) {\n    this.id = opts.id;\n    this.graphDiv = opts.graphDiv;\n    this.container = opts.container;\n    this.topojsonURL = opts.topojsonURL;\n    this.isStatic = opts.staticPlot;\n\n    this.topojsonName = null;\n    this.topojson = null;\n\n    this.projection = null;\n    this.scope = null;\n    this.viewInitial = null;\n    this.fitScale = null;\n    this.bounds = null;\n    this.midPt = null;\n\n    this.hasChoropleth = false;\n    this.traceHash = {};\n\n    this.layers = {};\n    this.basePaths = {};\n    this.dataPaths = {};\n    this.dataPoints = {};\n\n    this.clipDef = null;\n    this.clipRect = null;\n    this.bgRect = null;\n\n    this.makeFramework();\n}\n\nvar proto = Geo.prototype;\n\nmodule.exports = function createGeo(opts) {\n    return new Geo(opts);\n};\n\nproto.plot = function(geoCalcData, fullLayout, promises) {\n    var _this = this;\n    var geoLayout = fullLayout[this.id];\n\n    var needsTopojson = false;\n    for(var k in constants.layerNameToAdjective) {\n        if(k !== 'frame' && geoLayout['show' + k]) {\n            needsTopojson = true;\n            break;\n        }\n    }\n    for(var i = 0; i < geoCalcData.length; i++) {\n        if(geoCalcData[0][0].trace.locationmode) {\n            needsTopojson = true;\n            break;\n        }\n    }\n    if(!needsTopojson) {\n        return _this.update(geoCalcData, fullLayout);\n    }\n\n    var topojsonNameNew = topojsonUtils.getTopojsonName(geoLayout);\n\n    if(_this.topojson === null || topojsonNameNew !== _this.topojsonName) {\n        _this.topojsonName = topojsonNameNew;\n\n        if(PlotlyGeoAssets.topojson[_this.topojsonName] === undefined) {\n            promises.push(_this.fetchTopojson().then(function(topojson) {\n                PlotlyGeoAssets.topojson[_this.topojsonName] = topojson;\n                _this.topojson = topojson;\n                _this.update(geoCalcData, fullLayout);\n            }));\n        } else {\n            _this.topojson = PlotlyGeoAssets.topojson[_this.topojsonName];\n            _this.update(geoCalcData, fullLayout);\n        }\n    } else {\n        _this.update(geoCalcData, fullLayout);\n    }\n};\n\nproto.fetchTopojson = function() {\n    var topojsonPath = topojsonUtils.getTopojsonPath(\n        this.topojsonURL,\n        this.topojsonName\n    );\n    return new Promise(function(resolve, reject) {\n        d3.json(topojsonPath, function(err, topojson) {\n            if(err) {\n                if(err.status === 404) {\n                    return reject(new Error([\n                        'plotly.js could not find topojson file at',\n                        topojsonPath, '.',\n                        'Make sure the *topojsonURL* plot config option',\n                        'is set properly.'\n                    ].join(' ')));\n                } else {\n                    return reject(new Error([\n                        'unexpected error while fetching topojson file at',\n                        topojsonPath\n                    ].join(' ')));\n                }\n            }\n            resolve(topojson);\n        });\n    });\n};\n\nproto.update = function(geoCalcData, fullLayout) {\n    var geoLayout = fullLayout[this.id];\n\n    var hasInvalidBounds = this.updateProjection(fullLayout, geoLayout);\n    if(hasInvalidBounds) return;\n\n    // important: maps with choropleth traces have a different layer order\n    this.hasChoropleth = false;\n    for(var i = 0; i < geoCalcData.length; i++) {\n        if(geoCalcData[i][0].trace.type === 'choropleth') {\n            this.hasChoropleth = true;\n            break;\n        }\n    }\n\n    if(!this.viewInitial || this.scope !== geoLayout.scope) {\n        this.saveViewInitial(geoLayout);\n    }\n    this.scope = geoLayout.scope;\n\n    this.updateBaseLayers(fullLayout, geoLayout);\n    this.updateDims(fullLayout, geoLayout);\n    this.updateFx(fullLayout, geoLayout);\n\n    Plots.generalUpdatePerTraceModule(this.graphDiv, this, geoCalcData, geoLayout);\n\n    var scatterLayer = this.layers.frontplot.select('.scatterlayer');\n    this.dataPoints.point = scatterLayer.selectAll('.point');\n    this.dataPoints.text = scatterLayer.selectAll('text');\n    this.dataPaths.line = scatterLayer.selectAll('.js-line');\n\n    var choroplethLayer = this.layers.backplot.select('.choroplethlayer');\n    this.dataPaths.choropleth = choroplethLayer.selectAll('path');\n\n    this.render();\n};\n\nproto.updateProjection = function(fullLayout, geoLayout) {\n    var gs = fullLayout._size;\n    var domain = geoLayout.domain;\n    var projLayout = geoLayout.projection;\n    var rotation = projLayout.rotation || {};\n    var center = geoLayout.center || {};\n\n    var projection = this.projection = getProjection(geoLayout);\n\n    // set 'pre-fit' projection\n    projection\n        .center([center.lon - rotation.lon, center.lat - rotation.lat])\n        .rotate([-rotation.lon, -rotation.lat, rotation.roll])\n        .parallels(projLayout.parallels);\n\n    // setup subplot extent [[x0,y0], [x1,y1]]\n    var extent = [[\n        gs.l + gs.w * domain.x[0],\n        gs.t + gs.h * (1 - domain.y[1])\n    ], [\n        gs.l + gs.w * domain.x[1],\n        gs.t + gs.h * (1 - domain.y[0])\n    ]];\n\n    var lonaxis = geoLayout.lonaxis;\n    var lataxis = geoLayout.lataxis;\n    var rangeBox = makeRangeBox(lonaxis.range, lataxis.range);\n\n    // fit projection 'scale' and 'translate' to set lon/lat ranges\n    projection.fitExtent(extent, rangeBox);\n\n    var b = this.bounds = projection.getBounds(rangeBox);\n    var s = this.fitScale = projection.scale();\n    var t = projection.translate();\n\n    if(\n        !isFinite(b[0][0]) || !isFinite(b[0][1]) ||\n        !isFinite(b[1][0]) || !isFinite(b[1][1]) ||\n        isNaN(t[0]) || isNaN(t[0])\n    ) {\n        var gd = this.graphDiv;\n        var attrToUnset = ['projection.rotation', 'center', 'lonaxis.range', 'lataxis.range'];\n        var msg = 'Invalid geo settings, relayout\\'ing to default view.';\n        var updateObj = {};\n\n        // clear all attribute that could cause invalid bounds,\n        // clear viewInitial to update reset-view behavior\n\n        for(var i = 0; i < attrToUnset.length; i++) {\n            updateObj[this.id + '.' + attrToUnset[i]] = null;\n        }\n\n        this.viewInitial = null;\n\n        Lib.warn(msg);\n        gd._promises.push(Registry.call('relayout', gd, updateObj));\n        return msg;\n    }\n\n    // px coordinates of view mid-point,\n    // useful to update `geo.center` after interactions\n    var midPt = this.midPt = [\n        (b[0][0] + b[1][0]) / 2,\n        (b[0][1] + b[1][1]) / 2\n    ];\n\n    // adjust projection to user setting\n    projection\n        .scale(projLayout.scale * s)\n        .translate([t[0] + (midPt[0] - t[0]), t[1] + (midPt[1] - t[1])])\n        .clipExtent(b);\n\n    // the 'albers usa' projection does not expose a 'center' method\n    // so here's this hack to make it respond to 'geoLayout.center'\n    if(geoLayout._isAlbersUsa) {\n        var centerPx = projection([center.lon, center.lat]);\n        var tt = projection.translate();\n\n        projection.translate([\n            tt[0] - (centerPx[0] - tt[0]),\n            tt[1] - (centerPx[1] - tt[1])\n        ]);\n    }\n};\n\nproto.updateBaseLayers = function(fullLayout, geoLayout) {\n    var _this = this;\n    var topojson = _this.topojson;\n    var layers = _this.layers;\n    var basePaths = _this.basePaths;\n\n    function isAxisLayer(d) {\n        return (d === 'lonaxis' || d === 'lataxis');\n    }\n\n    function isLineLayer(d) {\n        return Boolean(constants.lineLayers[d]);\n    }\n\n    function isFillLayer(d) {\n        return Boolean(constants.fillLayers[d]);\n    }\n\n    var allLayers = this.hasChoropleth ?\n        constants.layersForChoropleth :\n        constants.layers;\n\n    var layerData = allLayers.filter(function(d) {\n        return (isLineLayer(d) || isFillLayer(d)) ? geoLayout['show' + d] :\n            isAxisLayer(d) ? geoLayout[d].showgrid :\n            true;\n    });\n\n    var join = _this.framework.selectAll('.layer')\n        .data(layerData, String);\n\n    join.exit().each(function(d) {\n        delete layers[d];\n        delete basePaths[d];\n        d3.select(this).remove();\n    });\n\n    join.enter().append('g')\n        .attr('class', function(d) { return 'layer ' + d; })\n        .each(function(d) {\n            var layer = layers[d] = d3.select(this);\n\n            if(d === 'bg') {\n                _this.bgRect = layer.append('rect')\n                    .style('pointer-events', 'all');\n            } else if(isAxisLayer(d)) {\n                basePaths[d] = layer.append('path')\n                    .style('fill', 'none');\n            } else if(d === 'backplot') {\n                layer.append('g')\n                    .classed('choroplethlayer', true);\n            } else if(d === 'frontplot') {\n                layer.append('g')\n                    .classed('scatterlayer', true);\n            } else if(isLineLayer(d)) {\n                basePaths[d] = layer.append('path')\n                    .style('fill', 'none')\n                    .style('stroke-miterlimit', 2);\n            } else if(isFillLayer(d)) {\n                basePaths[d] = layer.append('path')\n                    .style('stroke', 'none');\n            }\n        });\n\n    join.order();\n\n    join.each(function(d) {\n        var path = basePaths[d];\n        var adj = constants.layerNameToAdjective[d];\n\n        if(d === 'frame') {\n            path.datum(constants.sphereSVG);\n        } else if(isLineLayer(d) || isFillLayer(d)) {\n            path.datum(topojsonFeature(topojson, topojson.objects[d]));\n        } else if(isAxisLayer(d)) {\n            path.datum(makeGraticule(d, geoLayout, fullLayout))\n                .call(Color.stroke, geoLayout[d].gridcolor)\n                .call(Drawing.dashLine, '', geoLayout[d].gridwidth);\n        }\n\n        if(isLineLayer(d)) {\n            path.call(Color.stroke, geoLayout[adj + 'color'])\n                .call(Drawing.dashLine, '', geoLayout[adj + 'width']);\n        } else if(isFillLayer(d)) {\n            path.call(Color.fill, geoLayout[adj + 'color']);\n        }\n    });\n};\n\nproto.updateDims = function(fullLayout, geoLayout) {\n    var b = this.bounds;\n    var hFrameWidth = (geoLayout.framewidth || 0) / 2;\n\n    var l = b[0][0] - hFrameWidth;\n    var t = b[0][1] - hFrameWidth;\n    var w = b[1][0] - l + hFrameWidth;\n    var h = b[1][1] - t + hFrameWidth;\n\n    Drawing.setRect(this.clipRect, l, t, w, h);\n\n    this.bgRect\n        .call(Drawing.setRect, l, t, w, h)\n        .call(Color.fill, geoLayout.bgcolor);\n\n    this.xaxis._offset = l;\n    this.xaxis._length = w;\n\n    this.yaxis._offset = t;\n    this.yaxis._length = h;\n};\n\nproto.updateFx = function(fullLayout, geoLayout) {\n    var _this = this;\n    var gd = _this.graphDiv;\n    var bgRect = _this.bgRect;\n    var dragMode = fullLayout.dragmode;\n    var clickMode = fullLayout.clickmode;\n\n    if(_this.isStatic) return;\n\n    function zoomReset() {\n        var viewInitial = _this.viewInitial;\n        var updateObj = {};\n\n        for(var k in viewInitial) {\n            updateObj[_this.id + '.' + k] = viewInitial[k];\n        }\n\n        Registry.call('_guiRelayout', gd, updateObj);\n        gd.emit('plotly_doubleclick', null);\n    }\n\n    function invert(lonlat) {\n        return _this.projection.invert([\n            lonlat[0] + _this.xaxis._offset,\n            lonlat[1] + _this.yaxis._offset\n        ]);\n    }\n\n    var fillRangeItems;\n\n    if(dragMode === 'select') {\n        fillRangeItems = function(eventData, poly) {\n            var ranges = eventData.range = {};\n            ranges[_this.id] = [\n                invert([poly.xmin, poly.ymin]),\n                invert([poly.xmax, poly.ymax])\n            ];\n        };\n    } else if(dragMode === 'lasso') {\n        fillRangeItems = function(eventData, poly, pts) {\n            var dataPts = eventData.lassoPoints = {};\n            dataPts[_this.id] = pts.filtered.map(invert);\n        };\n    }\n\n    // Note: dragOptions is needed to be declared for all dragmodes because\n    // it's the object that holds persistent selection state.\n    var dragOptions = {\n        element: _this.bgRect.node(),\n        gd: gd,\n        plotinfo: {\n            id: _this.id,\n            xaxis: _this.xaxis,\n            yaxis: _this.yaxis,\n            fillRangeItems: fillRangeItems\n        },\n        xaxes: [_this.xaxis],\n        yaxes: [_this.yaxis],\n        subplot: _this.id,\n        clickFn: function(numClicks) {\n            if(numClicks === 2) {\n                fullLayout._zoomlayer.selectAll('.select-outline').remove();\n            }\n        }\n    };\n\n    if(dragMode === 'pan') {\n        bgRect.node().onmousedown = null;\n        bgRect.call(createGeoZoom(_this, geoLayout));\n        bgRect.on('dblclick.zoom', zoomReset);\n        if(!gd._context._scrollZoom.geo) {\n            bgRect.on('wheel.zoom', null);\n        }\n    } else if(dragMode === 'select' || dragMode === 'lasso') {\n        bgRect.on('.zoom', null);\n\n        dragOptions.prepFn = function(e, startX, startY) {\n            prepSelect(e, startX, startY, dragOptions, dragMode);\n        };\n\n        dragElement.init(dragOptions);\n    }\n\n    bgRect.on('mousemove', function() {\n        var lonlat = _this.projection.invert(d3.mouse(this));\n\n        if(!lonlat || isNaN(lonlat[0]) || isNaN(lonlat[1])) {\n            return dragElement.unhover(gd, d3.event);\n        }\n\n        _this.xaxis.p2c = function() { return lonlat[0]; };\n        _this.yaxis.p2c = function() { return lonlat[1]; };\n\n        Fx.hover(gd, d3.event, _this.id);\n    });\n\n    bgRect.on('mouseout', function() {\n        if(gd._dragging) return;\n        dragElement.unhover(gd, d3.event);\n    });\n\n    bgRect.on('click', function() {\n        // For select and lasso the dragElement is handling clicks\n        if(dragMode !== 'select' && dragMode !== 'lasso') {\n            if(clickMode.indexOf('select') > -1) {\n                selectOnClick(d3.event, gd, [_this.xaxis], [_this.yaxis],\n                  _this.id, dragOptions);\n            }\n\n            if(clickMode.indexOf('event') > -1) {\n                // TODO: like pie and mapbox, this doesn't support right-click\n                // actually this one is worse, as right-click starts a pan, or leaves\n                // select in a weird state.\n                // Also, only tangentially related, we should cancel hover during pan\n                Fx.click(gd, d3.event);\n            }\n        }\n    });\n};\n\nproto.makeFramework = function() {\n    var _this = this;\n    var gd = _this.graphDiv;\n    var fullLayout = gd._fullLayout;\n    var clipId = 'clip' + fullLayout._uid + _this.id;\n\n    _this.clipDef = fullLayout._clips.append('clipPath')\n        .attr('id', clipId);\n\n    _this.clipRect = _this.clipDef.append('rect');\n\n    _this.framework = d3.select(_this.container).append('g')\n        .attr('class', 'geo ' + _this.id)\n        .call(Drawing.setClipUrl, clipId, gd);\n\n    // sane lonlat to px\n    _this.project = function(v) {\n        var px = _this.projection(v);\n        return px ?\n            [px[0] - _this.xaxis._offset, px[1] - _this.yaxis._offset] :\n            [null, null];\n    };\n\n    _this.xaxis = {\n        _id: 'x',\n        c2p: function(v) { return _this.project(v)[0]; }\n    };\n\n    _this.yaxis = {\n        _id: 'y',\n        c2p: function(v) { return _this.project(v)[1]; }\n    };\n\n    // mock axis for hover formatting\n    _this.mockAxis = {\n        type: 'linear',\n        showexponent: 'all',\n        exponentformat: 'B'\n    };\n    Axes.setConvert(_this.mockAxis, fullLayout);\n};\n\nproto.saveViewInitial = function(geoLayout) {\n    var center = geoLayout.center || {};\n    var projLayout = geoLayout.projection;\n    var rotation = projLayout.rotation || {};\n\n    if(geoLayout._isScoped) {\n        this.viewInitial = {\n            'center.lon': center.lon,\n            'center.lat': center.lat,\n            'projection.scale': projLayout.scale\n        };\n    } else if(geoLayout._isClipped) {\n        this.viewInitial = {\n            'projection.scale': projLayout.scale,\n            'projection.rotation.lon': rotation.lon,\n            'projection.rotation.lat': rotation.lat\n        };\n    } else {\n        this.viewInitial = {\n            'center.lon': center.lon,\n            'center.lat': center.lat,\n            'projection.scale': projLayout.scale,\n            'projection.rotation.lon': rotation.lon\n        };\n    }\n};\n\n// [hot code path] (re)draw all paths which depend on the projection\nproto.render = function() {\n    var projection = this.projection;\n    var pathFn = projection.getPath();\n    var k;\n\n    function translatePoints(d) {\n        var lonlatPx = projection(d.lonlat);\n        return lonlatPx ?\n            'translate(' + lonlatPx[0] + ',' + lonlatPx[1] + ')' :\n             null;\n    }\n\n    function hideShowPoints(d) {\n        return projection.isLonLatOverEdges(d.lonlat) ? 'none' : null;\n    }\n\n    for(k in this.basePaths) {\n        this.basePaths[k].attr('d', pathFn);\n    }\n\n    for(k in this.dataPaths) {\n        this.dataPaths[k].attr('d', function(d) { return pathFn(d.geojson); });\n    }\n\n    for(k in this.dataPoints) {\n        this.dataPoints[k]\n            .attr('display', hideShowPoints)\n            .attr('transform', translatePoints);\n    }\n};\n\n// Helper that wraps d3.geo[/* projection name /*]() which:\n//\n// - adds 'fitExtent' (available in d3 v4)\n// - adds 'getPath', 'getBounds' convenience methods\n// - scopes logic related to 'clipAngle'\n// - adds 'isLonLatOverEdges' method\n// - sets projection precision\n// - sets methods that aren't always defined depending\n//   on the projection type to a dummy 'd3-esque' function,\n//\n// This wrapper alleviates subsequent code of (many) annoying if-statements.\nfunction getProjection(geoLayout) {\n    var projLayout = geoLayout.projection;\n    var projType = projLayout.type;\n\n    var projection = d3.geo[constants.projNames[projType]]();\n\n    var clipAngle = geoLayout._isClipped ?\n        constants.lonaxisSpan[projType] / 2 :\n        null;\n\n    var methods = ['center', 'rotate', 'parallels', 'clipExtent'];\n    var dummyFn = function(_) { return _ ? projection : []; };\n\n    for(var i = 0; i < methods.length; i++) {\n        var m = methods[i];\n        if(typeof projection[m] !== 'function') {\n            projection[m] = dummyFn;\n        }\n    }\n\n    projection.isLonLatOverEdges = function(lonlat) {\n        if(projection(lonlat) === null) {\n            return true;\n        }\n\n        if(clipAngle) {\n            var r = projection.rotate();\n            var angle = d3.geo.distance(lonlat, [-r[0], -r[1]]);\n            var maxAngle = clipAngle * Math.PI / 180;\n            return angle > maxAngle;\n        } else {\n            return false;\n        }\n    };\n\n    projection.getPath = function() {\n        return d3.geo.path().projection(projection);\n    };\n\n    projection.getBounds = function(object) {\n        return projection.getPath().bounds(object);\n    };\n\n    // adapted from d3 v4:\n    // https://github.com/d3/d3-geo/blob/master/src/projection/fit.js\n    projection.fitExtent = function(extent, object) {\n        var w = extent[1][0] - extent[0][0];\n        var h = extent[1][1] - extent[0][1];\n        var clip = projection.clipExtent && projection.clipExtent();\n\n        projection\n            .scale(150)\n            .translate([0, 0]);\n\n        if(clip) projection.clipExtent(null);\n\n        var b = projection.getBounds(object);\n        var k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1]));\n        var x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2;\n        var y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;\n\n        if(clip) projection.clipExtent(clip);\n\n        return projection\n            .scale(k * 150)\n            .translate([x, y]);\n    };\n\n    projection.precision(constants.precision);\n\n    if(clipAngle) {\n        projection.clipAngle(clipAngle - constants.clipPad);\n    }\n\n    return projection;\n}\n\nfunction makeGraticule(axisName, geoLayout, fullLayout) {\n    // equivalent to the d3 \"ε\"\n    var epsilon = 1e-6;\n    // same as the geoGraticule default\n    var precision = 2.5;\n\n    var axLayout = geoLayout[axisName];\n    var scopeDefaults = constants.scopeDefaults[geoLayout.scope];\n    var rng;\n    var oppRng;\n    var coordFn;\n\n    if(axisName === 'lonaxis') {\n        rng = scopeDefaults.lonaxisRange;\n        oppRng = scopeDefaults.lataxisRange;\n        coordFn = function(v, l) { return [v, l]; };\n    } else if(axisName === 'lataxis') {\n        rng = scopeDefaults.lataxisRange;\n        oppRng = scopeDefaults.lonaxisRange;\n        coordFn = function(v, l) { return [l, v]; };\n    }\n\n    var dummyAx = {\n        type: 'linear',\n        range: [rng[0], rng[1] - epsilon],\n        tick0: axLayout.tick0,\n        dtick: axLayout.dtick\n    };\n\n    Axes.setConvert(dummyAx, fullLayout);\n    var vals = Axes.calcTicks(dummyAx);\n\n    // remove duplicate on antimeridian\n    if(!geoLayout.isScoped && axisName === 'lonaxis') {\n        vals.pop();\n    }\n\n    var len = vals.length;\n    var coords = new Array(len);\n\n    for(var i = 0; i < len; i++) {\n        var v = vals[i].x;\n        var line = coords[i] = [];\n        for(var l = oppRng[0]; l < oppRng[1] + precision; l += precision) {\n            line.push(coordFn(v, l));\n        }\n    }\n\n    return {\n        type: 'MultiLineString',\n        coordinates: coords\n    };\n}\n\n// Returns polygon GeoJSON corresponding to lon/lat range box\n// with well-defined direction\n//\n// Note that clipPad padding is added around range to avoid aliasing.\nfunction makeRangeBox(lon, lat) {\n    var clipPad = constants.clipPad;\n    var lon0 = lon[0] + clipPad;\n    var lon1 = lon[1] - clipPad;\n    var lat0 = lat[0] + clipPad;\n    var lat1 = lat[1] - clipPad;\n\n    // to cross antimeridian w/o ambiguity\n    if(lon0 > 0 && lon1 < 0) lon1 += 360;\n\n    var dlon4 = (lon1 - lon0) / 4;\n\n    return {\n        type: 'Polygon',\n        coordinates: [[\n            [lon0, lat0],\n            [lon0, lat1],\n            [lon0 + dlon4, lat1],\n            [lon0 + 2 * dlon4, lat1],\n            [lon0 + 3 * dlon4, lat1],\n            [lon1, lat1],\n            [lon1, lat0],\n            [lon1 - dlon4, lat0],\n            [lon1 - 2 * dlon4, lat0],\n            [lon1 - 3 * dlon4, lat0],\n            [lon0, lat0]\n        ]]\n    };\n}\n\n},{\"../../components/color\":593,\"../../components/dragelement\":611,\"../../components/drawing\":614,\"../../components/fx\":632,\"../../lib\":719,\"../../lib/topojson_utils\":746,\"../../registry\":847,\"../cartesian/axes\":767,\"../cartesian/select\":784,\"../plots\":828,\"./constants\":795,\"./projections\":800,\"./zoom\":801,\"d3\":163,\"topojson-client\":540}],797:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar getSubplotCalcData = _dereq_('../../plots/get_data').getSubplotCalcData;\nvar counterRegex = _dereq_('../../lib').counterRegex;\n\nvar createGeo = _dereq_('./geo');\n\nvar GEO = 'geo';\nvar counter = counterRegex(GEO);\n\nvar attributes = {};\nattributes[GEO] = {\n    valType: 'subplotid',\n    \n    dflt: GEO,\n    editType: 'calc',\n    \n};\n\nfunction plotGeo(gd) {\n    var fullLayout = gd._fullLayout;\n    var calcData = gd.calcdata;\n    var geoIds = fullLayout._subplots[GEO];\n\n    for(var i = 0; i < geoIds.length; i++) {\n        var geoId = geoIds[i];\n        var geoCalcData = getSubplotCalcData(calcData, GEO, geoId);\n        var geoLayout = fullLayout[geoId];\n        var geo = geoLayout._subplot;\n\n        if(!geo) {\n            geo = createGeo({\n                id: geoId,\n                graphDiv: gd,\n                container: fullLayout._geolayer.node(),\n                topojsonURL: gd._context.topojsonURL,\n                staticPlot: gd._context.staticPlot\n            });\n\n            fullLayout[geoId]._subplot = geo;\n        }\n\n        geo.plot(geoCalcData, fullLayout, gd._promises);\n    }\n}\n\nfunction clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var oldGeoKeys = oldFullLayout._subplots[GEO] || [];\n\n    for(var i = 0; i < oldGeoKeys.length; i++) {\n        var oldGeoKey = oldGeoKeys[i];\n        var oldGeo = oldFullLayout[oldGeoKey]._subplot;\n\n        if(!newFullLayout[oldGeoKey] && !!oldGeo) {\n            oldGeo.framework.remove();\n            oldGeo.clipDef.remove();\n        }\n    }\n}\n\nfunction updateFx(gd) {\n    var fullLayout = gd._fullLayout;\n    var subplotIds = fullLayout._subplots[GEO];\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var subplotLayout = fullLayout[subplotIds[i]];\n        var subplotObj = subplotLayout._subplot;\n        subplotObj.updateFx(fullLayout, subplotLayout);\n    }\n}\n\nmodule.exports = {\n    attr: GEO,\n    name: GEO,\n    idRoot: GEO,\n    idRegex: counter,\n    attrRegex: counter,\n    attributes: attributes,\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n    plot: plotGeo,\n    updateFx: updateFx,\n    clean: clean\n};\n\n},{\"../../lib\":719,\"../../plots/get_data\":802,\"./geo\":796,\"./layout_attributes\":798,\"./layout_defaults\":799}],798:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar domainAttrs = _dereq_('../domain').attributes;\nvar constants = _dereq_('./constants');\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar geoAxesAttrs = {\n    range: {\n        valType: 'info_array',\n        \n        items: [\n            {valType: 'number'},\n            {valType: 'number'}\n        ],\n        \n    },\n    showgrid: {\n        valType: 'boolean',\n        \n        dflt: false,\n        \n    },\n    tick0: {\n        valType: 'number',\n        \n        dflt: 0,\n        \n    },\n    dtick: {\n        valType: 'number',\n        \n        \n    },\n    gridcolor: {\n        valType: 'color',\n        \n        dflt: colorAttrs.lightLine,\n        \n    },\n    gridwidth: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 1,\n        \n    }\n};\n\nvar attrs = module.exports = overrideAll({\n    domain: domainAttrs({name: 'geo'}, {\n        \n    }),\n\n    resolution: {\n        valType: 'enumerated',\n        values: [110, 50],\n        \n        dflt: 110,\n        coerceNumber: true,\n        \n    },\n    scope: {\n        valType: 'enumerated',\n        \n        values: Object.keys(constants.scopeDefaults),\n        dflt: 'world',\n        \n    },\n    projection: {\n        type: {\n            valType: 'enumerated',\n            \n            values: Object.keys(constants.projNames),\n            \n        },\n        rotation: {\n            lon: {\n                valType: 'number',\n                \n                \n            },\n            lat: {\n                valType: 'number',\n                \n                \n            },\n            roll: {\n                valType: 'number',\n                \n                \n            }\n        },\n        parallels: {\n            valType: 'info_array',\n            \n            items: [\n                {valType: 'number'},\n                {valType: 'number'}\n            ],\n            \n        },\n        scale: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 1,\n            \n        },\n    },\n    center: {\n        lon: {\n            valType: 'number',\n            \n            \n        },\n        lat: {\n            valType: 'number',\n            \n            \n        }\n    },\n    showcoastlines: {\n        valType: 'boolean',\n        \n        \n    },\n    coastlinecolor: {\n        valType: 'color',\n        \n        dflt: colorAttrs.defaultLine,\n        \n    },\n    coastlinewidth: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 1,\n        \n    },\n    showland: {\n        valType: 'boolean',\n        \n        dflt: false,\n        \n    },\n    landcolor: {\n        valType: 'color',\n        \n        dflt: constants.landColor,\n        \n    },\n    showocean: {\n        valType: 'boolean',\n        \n        dflt: false,\n        \n    },\n    oceancolor: {\n        valType: 'color',\n        \n        dflt: constants.waterColor,\n        \n    },\n    showlakes: {\n        valType: 'boolean',\n        \n        dflt: false,\n        \n    },\n    lakecolor: {\n        valType: 'color',\n        \n        dflt: constants.waterColor,\n        \n    },\n    showrivers: {\n        valType: 'boolean',\n        \n        dflt: false,\n        \n    },\n    rivercolor: {\n        valType: 'color',\n        \n        dflt: constants.waterColor,\n        \n    },\n    riverwidth: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 1,\n        \n    },\n    showcountries: {\n        valType: 'boolean',\n        \n        \n    },\n    countrycolor: {\n        valType: 'color',\n        \n        dflt: colorAttrs.defaultLine,\n        \n    },\n    countrywidth: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 1,\n        \n    },\n    showsubunits: {\n        valType: 'boolean',\n        \n        \n    },\n    subunitcolor: {\n        valType: 'color',\n        \n        dflt: colorAttrs.defaultLine,\n        \n    },\n    subunitwidth: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 1,\n        \n    },\n    showframe: {\n        valType: 'boolean',\n        \n        \n    },\n    framecolor: {\n        valType: 'color',\n        \n        dflt: colorAttrs.defaultLine,\n        \n    },\n    framewidth: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 1,\n        \n    },\n    bgcolor: {\n        valType: 'color',\n        \n        dflt: colorAttrs.background,\n        \n    },\n    lonaxis: geoAxesAttrs,\n    lataxis: geoAxesAttrs\n}, 'plot', 'from-root');\n\n// set uirevision outside of overrideAll so it can be `editType: 'none'`\nattrs.uirevision = {\n    valType: 'any',\n    \n    editType: 'none',\n    \n};\n\n},{\"../../components/color/attributes\":592,\"../../plot_api/edit_types\":750,\"../domain\":792,\"./constants\":795}],799:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar handleSubplotDefaults = _dereq_('../subplot_defaults');\nvar constants = _dereq_('./constants');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nvar axesNames = constants.axesNames;\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    handleSubplotDefaults(layoutIn, layoutOut, fullData, {\n        type: 'geo',\n        attributes: layoutAttributes,\n        handleDefaults: handleGeoDefaults,\n        partition: 'y'\n    });\n};\n\nfunction handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) {\n    var show;\n\n    var resolution = coerce('resolution');\n    var scope = coerce('scope');\n    var scopeParams = constants.scopeDefaults[scope];\n\n    var projType = coerce('projection.type', scopeParams.projType);\n    var isAlbersUsa = geoLayoutOut._isAlbersUsa = projType === 'albers usa';\n\n    // no other scopes are allowed for 'albers usa' projection\n    if(isAlbersUsa) scope = geoLayoutOut.scope = 'usa';\n\n    var isScoped = geoLayoutOut._isScoped = (scope !== 'world');\n    var isConic = geoLayoutOut._isConic = projType.indexOf('conic') !== -1;\n    geoLayoutOut._isClipped = !!constants.lonaxisSpan[projType];\n\n    for(var i = 0; i < axesNames.length; i++) {\n        var axisName = axesNames[i];\n        var dtickDflt = [30, 10][i];\n        var rangeDflt;\n\n        if(isScoped) {\n            rangeDflt = scopeParams[axisName + 'Range'];\n        } else {\n            var dfltSpans = constants[axisName + 'Span'];\n            var hSpan = (dfltSpans[projType] || dfltSpans['*']) / 2;\n            var rot = coerce(\n                'projection.rotation.' + axisName.substr(0, 3),\n                scopeParams.projRotate[i]\n            );\n            rangeDflt = [rot - hSpan, rot + hSpan];\n        }\n\n        coerce(axisName + '.range', rangeDflt);\n        coerce(axisName + '.tick0');\n        coerce(axisName + '.dtick', dtickDflt);\n\n        show = coerce(axisName + '.showgrid');\n        if(show) {\n            coerce(axisName + '.gridcolor');\n            coerce(axisName + '.gridwidth');\n        }\n    }\n\n    var lonRange = geoLayoutOut.lonaxis.range;\n    var latRange = geoLayoutOut.lataxis.range;\n\n    // to cross antimeridian w/o ambiguity\n    var lon0 = lonRange[0];\n    var lon1 = lonRange[1];\n    if(lon0 > 0 && lon1 < 0) lon1 += 360;\n\n    var centerLon = (lon0 + lon1) / 2;\n    var projLon;\n\n    if(!isAlbersUsa) {\n        var dfltProjRotate = isScoped ? scopeParams.projRotate : [centerLon, 0, 0];\n\n        projLon = coerce('projection.rotation.lon', dfltProjRotate[0]);\n        coerce('projection.rotation.lat', dfltProjRotate[1]);\n        coerce('projection.rotation.roll', dfltProjRotate[2]);\n\n        show = coerce('showcoastlines', !isScoped);\n        if(show) {\n            coerce('coastlinecolor');\n            coerce('coastlinewidth');\n        }\n\n        show = coerce('showocean');\n        if(show) coerce('oceancolor');\n    }\n\n    var centerLonDflt;\n    var centerLatDflt;\n\n    if(isAlbersUsa) {\n        // 'albers usa' does not have a 'center',\n        // these values were found using via:\n        //   projection.invert([geoLayout.center.lon, geoLayoutIn.center.lat])\n        centerLonDflt = -96.6;\n        centerLatDflt = 38.7;\n    } else {\n        centerLonDflt = isScoped ? centerLon : projLon;\n        centerLatDflt = (latRange[0] + latRange[1]) / 2;\n    }\n\n    coerce('center.lon', centerLonDflt);\n    coerce('center.lat', centerLatDflt);\n\n    if(isConic) {\n        var dfltProjParallels = scopeParams.projParallels || [0, 60];\n        coerce('projection.parallels', dfltProjParallels);\n    }\n\n    coerce('projection.scale');\n\n    show = coerce('showland');\n    if(show) coerce('landcolor');\n\n    show = coerce('showlakes');\n    if(show) coerce('lakecolor');\n\n    show = coerce('showrivers');\n    if(show) {\n        coerce('rivercolor');\n        coerce('riverwidth');\n    }\n\n    show = coerce('showcountries', isScoped && scope !== 'usa');\n    if(show) {\n        coerce('countrycolor');\n        coerce('countrywidth');\n    }\n\n    if(scope === 'usa' || (scope === 'north america' && resolution === 50)) {\n        // Only works for:\n        //   USA states at 110m\n        //   USA states + Canada provinces at 50m\n        coerce('showsubunits', true);\n        coerce('subunitcolor');\n        coerce('subunitwidth');\n    }\n\n    if(!isScoped) {\n        // Does not work in non-world scopes\n        show = coerce('showframe', true);\n        if(show) {\n            coerce('framecolor');\n            coerce('framewidth');\n        }\n    }\n\n    coerce('bgcolor');\n}\n\n},{\"../subplot_defaults\":842,\"./constants\":795,\"./layout_attributes\":798}],800:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n/*\n * Generated by https://github.com/etpinard/d3-geo-projection-picker\n *\n * which is hand-picks projection from https://github.com/d3/d3-geo-projection\n *\n * into a CommonJS require-able module.\n */\n\n'use strict';\n\n/* eslint-disable */\n\nfunction addProjectionsToD3(d3) {\n  d3.geo.project = function(object, projection) {\n    var stream = projection.stream;\n    if (!stream) throw new Error(\"not yet supported\");\n    return (object && d3_geo_projectObjectType.hasOwnProperty(object.type) ? d3_geo_projectObjectType[object.type] : d3_geo_projectGeometry)(object, stream);\n  };\n  function d3_geo_projectFeature(object, stream) {\n    return {\n      type: \"Feature\",\n      id: object.id,\n      properties: object.properties,\n      geometry: d3_geo_projectGeometry(object.geometry, stream)\n    };\n  }\n  function d3_geo_projectGeometry(geometry, stream) {\n    if (!geometry) return null;\n    if (geometry.type === \"GeometryCollection\") return {\n      type: \"GeometryCollection\",\n      geometries: object.geometries.map(function(geometry) {\n        return d3_geo_projectGeometry(geometry, stream);\n      })\n    };\n    if (!d3_geo_projectGeometryType.hasOwnProperty(geometry.type)) return null;\n    var sink = d3_geo_projectGeometryType[geometry.type];\n    d3.geo.stream(geometry, stream(sink));\n    return sink.result();\n  }\n  var d3_geo_projectObjectType = {\n    Feature: d3_geo_projectFeature,\n    FeatureCollection: function(object, stream) {\n      return {\n        type: \"FeatureCollection\",\n        features: object.features.map(function(feature) {\n          return d3_geo_projectFeature(feature, stream);\n        })\n      };\n    }\n  };\n  var d3_geo_projectPoints = [], d3_geo_projectLines = [];\n  var d3_geo_projectPoint = {\n    point: function(x, y) {\n      d3_geo_projectPoints.push([ x, y ]);\n    },\n    result: function() {\n      var result = !d3_geo_projectPoints.length ? null : d3_geo_projectPoints.length < 2 ? {\n        type: \"Point\",\n        coordinates: d3_geo_projectPoints[0]\n      } : {\n        type: \"MultiPoint\",\n        coordinates: d3_geo_projectPoints\n      };\n      d3_geo_projectPoints = [];\n      return result;\n    }\n  };\n  var d3_geo_projectLine = {\n    lineStart: d3_geo_projectNoop,\n    point: function(x, y) {\n      d3_geo_projectPoints.push([ x, y ]);\n    },\n    lineEnd: function() {\n      if (d3_geo_projectPoints.length) d3_geo_projectLines.push(d3_geo_projectPoints),\n      d3_geo_projectPoints = [];\n    },\n    result: function() {\n      var result = !d3_geo_projectLines.length ? null : d3_geo_projectLines.length < 2 ? {\n        type: \"LineString\",\n        coordinates: d3_geo_projectLines[0]\n      } : {\n        type: \"MultiLineString\",\n        coordinates: d3_geo_projectLines\n      };\n      d3_geo_projectLines = [];\n      return result;\n    }\n  };\n  var d3_geo_projectPolygon = {\n    polygonStart: d3_geo_projectNoop,\n    lineStart: d3_geo_projectNoop,\n    point: function(x, y) {\n      d3_geo_projectPoints.push([ x, y ]);\n    },\n    lineEnd: function() {\n      var n = d3_geo_projectPoints.length;\n      if (n) {\n        do d3_geo_projectPoints.push(d3_geo_projectPoints[0].slice()); while (++n < 4);\n        d3_geo_projectLines.push(d3_geo_projectPoints), d3_geo_projectPoints = [];\n      }\n    },\n    polygonEnd: d3_geo_projectNoop,\n    result: function() {\n      if (!d3_geo_projectLines.length) return null;\n      var polygons = [], holes = [];\n      d3_geo_projectLines.forEach(function(ring) {\n        if (d3_geo_projectClockwise(ring)) polygons.push([ ring ]); else holes.push(ring);\n      });\n      holes.forEach(function(hole) {\n        var point = hole[0];\n        polygons.some(function(polygon) {\n          if (d3_geo_projectContains(polygon[0], point)) {\n            polygon.push(hole);\n            return true;\n          }\n        }) || polygons.push([ hole ]);\n      });\n      d3_geo_projectLines = [];\n      return !polygons.length ? null : polygons.length > 1 ? {\n        type: \"MultiPolygon\",\n        coordinates: polygons\n      } : {\n        type: \"Polygon\",\n        coordinates: polygons[0]\n      };\n    }\n  };\n  var d3_geo_projectGeometryType = {\n    Point: d3_geo_projectPoint,\n    MultiPoint: d3_geo_projectPoint,\n    LineString: d3_geo_projectLine,\n    MultiLineString: d3_geo_projectLine,\n    Polygon: d3_geo_projectPolygon,\n    MultiPolygon: d3_geo_projectPolygon,\n    Sphere: d3_geo_projectPolygon\n  };\n  function d3_geo_projectNoop() {}\n  function d3_geo_projectClockwise(ring) {\n    if ((n = ring.length) < 4) return false;\n    var i = 0, n, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];\n    while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];\n    return area <= 0;\n  }\n  function d3_geo_projectContains(ring, point) {\n    var x = point[0], y = point[1], contains = false;\n    for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {\n      var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];\n      if (yi > y ^ yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) contains = !contains;\n    }\n    return contains;\n  }\n  var ε = 1e-6, ε2 = ε * ε, π = Math.PI, halfπ = π / 2, sqrtπ = Math.sqrt(π), radians = π / 180, degrees = 180 / π;\n  function sinci(x) {\n    return x ? x / Math.sin(x) : 1;\n  }\n  function sgn(x) {\n    return x > 0 ? 1 : x < 0 ? -1 : 0;\n  }\n  function asin(x) {\n    return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);\n  }\n  function acos(x) {\n    return x > 1 ? 0 : x < -1 ? π : Math.acos(x);\n  }\n  function asqrt(x) {\n    return x > 0 ? Math.sqrt(x) : 0;\n  }\n  var projection = d3.geo.projection, projectionMutator = d3.geo.projectionMutator;\n  d3.geo.interrupt = function(project) {\n    var lobes = [ [ [ [ -π, 0 ], [ 0, halfπ ], [ π, 0 ] ] ], [ [ [ -π, 0 ], [ 0, -halfπ ], [ π, 0 ] ] ] ];\n    var bounds;\n    function forward(λ, φ) {\n      var sign = φ < 0 ? -1 : +1, hemilobes = lobes[+(φ < 0)];\n      for (var i = 0, n = hemilobes.length - 1; i < n && λ > hemilobes[i][2][0]; ++i) ;\n      var coordinates = project(λ - hemilobes[i][1][0], φ);\n      coordinates[0] += project(hemilobes[i][1][0], sign * φ > sign * hemilobes[i][0][1] ? hemilobes[i][0][1] : φ)[0];\n      return coordinates;\n    }\n    function reset() {\n      bounds = lobes.map(function(hemilobes) {\n        return hemilobes.map(function(lobe) {\n          var x0 = project(lobe[0][0], lobe[0][1])[0], x1 = project(lobe[2][0], lobe[2][1])[0], y0 = project(lobe[1][0], lobe[0][1])[1], y1 = project(lobe[1][0], lobe[1][1])[1], t;\n          if (y0 > y1) t = y0, y0 = y1, y1 = t;\n          return [ [ x0, y0 ], [ x1, y1 ] ];\n        });\n      });\n    }\n    if (project.invert) forward.invert = function(x, y) {\n      var hemibounds = bounds[+(y < 0)], hemilobes = lobes[+(y < 0)];\n      for (var i = 0, n = hemibounds.length; i < n; ++i) {\n        var b = hemibounds[i];\n        if (b[0][0] <= x && x < b[1][0] && b[0][1] <= y && y < b[1][1]) {\n          var coordinates = project.invert(x - project(hemilobes[i][1][0], 0)[0], y);\n          coordinates[0] += hemilobes[i][1][0];\n          return pointEqual(forward(coordinates[0], coordinates[1]), [ x, y ]) ? coordinates : null;\n        }\n      }\n    };\n    var projection = d3.geo.projection(forward), stream_ = projection.stream;\n    projection.stream = function(stream) {\n      var rotate = projection.rotate(), rotateStream = stream_(stream), sphereStream = (projection.rotate([ 0, 0 ]),\n      stream_(stream));\n      projection.rotate(rotate);\n      rotateStream.sphere = function() {\n        d3.geo.stream(sphere(), sphereStream);\n      };\n      return rotateStream;\n    };\n    projection.lobes = function(_) {\n      if (!arguments.length) return lobes.map(function(lobes) {\n        return lobes.map(function(lobe) {\n          return [ [ lobe[0][0] * 180 / π, lobe[0][1] * 180 / π ], [ lobe[1][0] * 180 / π, lobe[1][1] * 180 / π ], [ lobe[2][0] * 180 / π, lobe[2][1] * 180 / π ] ];\n        });\n      });\n      lobes = _.map(function(lobes) {\n        return lobes.map(function(lobe) {\n          return [ [ lobe[0][0] * π / 180, lobe[0][1] * π / 180 ], [ lobe[1][0] * π / 180, lobe[1][1] * π / 180 ], [ lobe[2][0] * π / 180, lobe[2][1] * π / 180 ] ];\n        });\n      });\n      reset();\n      return projection;\n    };\n    function sphere() {\n      var ε = 1e-6, coordinates = [];\n      for (var i = 0, n = lobes[0].length; i < n; ++i) {\n        var lobe = lobes[0][i], λ0 = lobe[0][0] * 180 / π, φ0 = lobe[0][1] * 180 / π, φ1 = lobe[1][1] * 180 / π, λ2 = lobe[2][0] * 180 / π, φ2 = lobe[2][1] * 180 / π;\n        coordinates.push(resample([ [ λ0 + ε, φ0 + ε ], [ λ0 + ε, φ1 - ε ], [ λ2 - ε, φ1 - ε ], [ λ2 - ε, φ2 + ε ] ], 30));\n      }\n      for (var i = lobes[1].length - 1; i >= 0; --i) {\n        var lobe = lobes[1][i], λ0 = lobe[0][0] * 180 / π, φ0 = lobe[0][1] * 180 / π, φ1 = lobe[1][1] * 180 / π, λ2 = lobe[2][0] * 180 / π, φ2 = lobe[2][1] * 180 / π;\n        coordinates.push(resample([ [ λ2 - ε, φ2 - ε ], [ λ2 - ε, φ1 + ε ], [ λ0 + ε, φ1 + ε ], [ λ0 + ε, φ0 - ε ] ], 30));\n      }\n      return {\n        type: \"Polygon\",\n        coordinates: [ d3.merge(coordinates) ]\n      };\n    }\n    function resample(coordinates, m) {\n      var i = -1, n = coordinates.length, p0 = coordinates[0], p1, dx, dy, resampled = [];\n      while (++i < n) {\n        p1 = coordinates[i];\n        dx = (p1[0] - p0[0]) / m;\n        dy = (p1[1] - p0[1]) / m;\n        for (var j = 0; j < m; ++j) resampled.push([ p0[0] + j * dx, p0[1] + j * dy ]);\n        p0 = p1;\n      }\n      resampled.push(p1);\n      return resampled;\n    }\n    function pointEqual(a, b) {\n      return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;\n    }\n    return projection;\n  };\n  function eckert4(λ, φ) {\n    var k = (2 + halfπ) * Math.sin(φ);\n    φ /= 2;\n    for (var i = 0, δ = Infinity; i < 10 && Math.abs(δ) > ε; i++) {\n      var cosφ = Math.cos(φ);\n      φ -= δ = (φ + Math.sin(φ) * (cosφ + 2) - k) / (2 * cosφ * (1 + cosφ));\n    }\n    return [ 2 / Math.sqrt(π * (4 + π)) * λ * (1 + Math.cos(φ)), 2 * Math.sqrt(π / (4 + π)) * Math.sin(φ) ];\n  }\n  eckert4.invert = function(x, y) {\n    var A = .5 * y * Math.sqrt((4 + π) / π), k = asin(A), c = Math.cos(k);\n    return [ x / (2 / Math.sqrt(π * (4 + π)) * (1 + c)), asin((k + A * (c + 2)) / (2 + halfπ)) ];\n  };\n  (d3.geo.eckert4 = function() {\n    return projection(eckert4);\n  }).raw = eckert4;\n  var hammerAzimuthalEqualArea = d3.geo.azimuthalEqualArea.raw;\n  function hammer(A, B) {\n    if (arguments.length < 2) B = A;\n    if (B === 1) return hammerAzimuthalEqualArea;\n    if (B === Infinity) return hammerQuarticAuthalic;\n    function forward(λ, φ) {\n      var coordinates = hammerAzimuthalEqualArea(λ / B, φ);\n      coordinates[0] *= A;\n      return coordinates;\n    }\n    forward.invert = function(x, y) {\n      var coordinates = hammerAzimuthalEqualArea.invert(x / A, y);\n      coordinates[0] *= B;\n      return coordinates;\n    };\n    return forward;\n  }\n  function hammerProjection() {\n    var B = 2, m = projectionMutator(hammer), p = m(B);\n    p.coefficient = function(_) {\n      if (!arguments.length) return B;\n      return m(B = +_);\n    };\n    return p;\n  }\n  function hammerQuarticAuthalic(λ, φ) {\n    return [ λ * Math.cos(φ) / Math.cos(φ /= 2), 2 * Math.sin(φ) ];\n  }\n  hammerQuarticAuthalic.invert = function(x, y) {\n    var φ = 2 * asin(y / 2);\n    return [ x * Math.cos(φ / 2) / Math.cos(φ), φ ];\n  };\n  (d3.geo.hammer = hammerProjection).raw = hammer;\n  function kavrayskiy7(λ, φ) {\n    return [ 3 * λ / (2 * π) * Math.sqrt(π * π / 3 - φ * φ), φ ];\n  }\n  kavrayskiy7.invert = function(x, y) {\n    return [ 2 / 3 * π * x / Math.sqrt(π * π / 3 - y * y), y ];\n  };\n  (d3.geo.kavrayskiy7 = function() {\n    return projection(kavrayskiy7);\n  }).raw = kavrayskiy7;\n  function miller(λ, φ) {\n    return [ λ, 1.25 * Math.log(Math.tan(π / 4 + .4 * φ)) ];\n  }\n  miller.invert = function(x, y) {\n    return [ x, 2.5 * Math.atan(Math.exp(.8 * y)) - .625 * π ];\n  };\n  (d3.geo.miller = function() {\n    return projection(miller);\n  }).raw = miller;\n  function mollweideBromleyθ(Cp) {\n    return function(θ) {\n      var Cpsinθ = Cp * Math.sin(θ), i = 30, δ;\n      do θ -= δ = (θ + Math.sin(θ) - Cpsinθ) / (1 + Math.cos(θ)); while (Math.abs(δ) > ε && --i > 0);\n      return θ / 2;\n    };\n  }\n  function mollweideBromley(Cx, Cy, Cp) {\n    var θ = mollweideBromleyθ(Cp);\n    function forward(λ, φ) {\n      return [ Cx * λ * Math.cos(φ = θ(φ)), Cy * Math.sin(φ) ];\n    }\n    forward.invert = function(x, y) {\n      var θ = asin(y / Cy);\n      return [ x / (Cx * Math.cos(θ)), asin((2 * θ + Math.sin(2 * θ)) / Cp) ];\n    };\n    return forward;\n  }\n  var mollweideθ = mollweideBromleyθ(π), mollweide = mollweideBromley(Math.SQRT2 / halfπ, Math.SQRT2, π);\n  (d3.geo.mollweide = function() {\n    return projection(mollweide);\n  }).raw = mollweide;\n  function naturalEarth(λ, φ) {\n    var φ2 = φ * φ, φ4 = φ2 * φ2;\n    return [ λ * (.8707 - .131979 * φ2 + φ4 * (-.013791 + φ4 * (.003971 * φ2 - .001529 * φ4))), φ * (1.007226 + φ2 * (.015085 + φ4 * (-.044475 + .028874 * φ2 - .005916 * φ4))) ];\n  }\n  naturalEarth.invert = function(x, y) {\n    var φ = y, i = 25, δ;\n    do {\n      var φ2 = φ * φ, φ4 = φ2 * φ2;\n      φ -= δ = (φ * (1.007226 + φ2 * (.015085 + φ4 * (-.044475 + .028874 * φ2 - .005916 * φ4))) - y) / (1.007226 + φ2 * (.015085 * 3 + φ4 * (-.044475 * 7 + .028874 * 9 * φ2 - .005916 * 11 * φ4)));\n    } while (Math.abs(δ) > ε && --i > 0);\n    return [ x / (.8707 + (φ2 = φ * φ) * (-.131979 + φ2 * (-.013791 + φ2 * φ2 * φ2 * (.003971 - .001529 * φ2)))), φ ];\n  };\n  (d3.geo.naturalEarth = function() {\n    return projection(naturalEarth);\n  }).raw = naturalEarth;\n  var robinsonConstants = [ [ .9986, -.062 ], [ 1, 0 ], [ .9986, .062 ], [ .9954, .124 ], [ .99, .186 ], [ .9822, .248 ], [ .973, .31 ], [ .96, .372 ], [ .9427, .434 ], [ .9216, .4958 ], [ .8962, .5571 ], [ .8679, .6176 ], [ .835, .6769 ], [ .7986, .7346 ], [ .7597, .7903 ], [ .7186, .8435 ], [ .6732, .8936 ], [ .6213, .9394 ], [ .5722, .9761 ], [ .5322, 1 ] ];\n  robinsonConstants.forEach(function(d) {\n    d[1] *= 1.0144;\n  });\n  function robinson(λ, φ) {\n    var i = Math.min(18, Math.abs(φ) * 36 / π), i0 = Math.floor(i), di = i - i0, ax = (k = robinsonConstants[i0])[0], ay = k[1], bx = (k = robinsonConstants[++i0])[0], by = k[1], cx = (k = robinsonConstants[Math.min(19, ++i0)])[0], cy = k[1], k;\n    return [ λ * (bx + di * (cx - ax) / 2 + di * di * (cx - 2 * bx + ax) / 2), (φ > 0 ? halfπ : -halfπ) * (by + di * (cy - ay) / 2 + di * di * (cy - 2 * by + ay) / 2) ];\n  }\n  robinson.invert = function(x, y) {\n    var yy = y / halfπ, φ = yy * 90, i = Math.min(18, Math.abs(φ / 5)), i0 = Math.max(0, Math.floor(i));\n    do {\n      var ay = robinsonConstants[i0][1], by = robinsonConstants[i0 + 1][1], cy = robinsonConstants[Math.min(19, i0 + 2)][1], u = cy - ay, v = cy - 2 * by + ay, t = 2 * (Math.abs(yy) - by) / u, c = v / u, di = t * (1 - c * t * (1 - 2 * c * t));\n      if (di >= 0 || i0 === 1) {\n        φ = (y >= 0 ? 5 : -5) * (di + i);\n        var j = 50, δ;\n        do {\n          i = Math.min(18, Math.abs(φ) / 5);\n          i0 = Math.floor(i);\n          di = i - i0;\n          ay = robinsonConstants[i0][1];\n          by = robinsonConstants[i0 + 1][1];\n          cy = robinsonConstants[Math.min(19, i0 + 2)][1];\n          φ -= (δ = (y >= 0 ? halfπ : -halfπ) * (by + di * (cy - ay) / 2 + di * di * (cy - 2 * by + ay) / 2) - y) * degrees;\n        } while (Math.abs(δ) > ε2 && --j > 0);\n        break;\n      }\n    } while (--i0 >= 0);\n    var ax = robinsonConstants[i0][0], bx = robinsonConstants[i0 + 1][0], cx = robinsonConstants[Math.min(19, i0 + 2)][0];\n    return [ x / (bx + di * (cx - ax) / 2 + di * di * (cx - 2 * bx + ax) / 2), φ * radians ];\n  };\n  (d3.geo.robinson = function() {\n    return projection(robinson);\n  }).raw = robinson;\n  function sinusoidal(λ, φ) {\n    return [ λ * Math.cos(φ), φ ];\n  }\n  sinusoidal.invert = function(x, y) {\n    return [ x / Math.cos(y), y ];\n  };\n  (d3.geo.sinusoidal = function() {\n    return projection(sinusoidal);\n  }).raw = sinusoidal;\n  function aitoff(λ, φ) {\n    var cosφ = Math.cos(φ), sinciα = sinci(acos(cosφ * Math.cos(λ /= 2)));\n    return [ 2 * cosφ * Math.sin(λ) * sinciα, Math.sin(φ) * sinciα ];\n  }\n  aitoff.invert = function(x, y) {\n    if (x * x + 4 * y * y > π * π + ε) return;\n    var λ = x, φ = y, i = 25;\n    do {\n      var sinλ = Math.sin(λ), sinλ_2 = Math.sin(λ / 2), cosλ_2 = Math.cos(λ / 2), sinφ = Math.sin(φ), cosφ = Math.cos(φ), sin_2φ = Math.sin(2 * φ), sin2φ = sinφ * sinφ, cos2φ = cosφ * cosφ, sin2λ_2 = sinλ_2 * sinλ_2, C = 1 - cos2φ * cosλ_2 * cosλ_2, E = C ? acos(cosφ * cosλ_2) * Math.sqrt(F = 1 / C) : F = 0, F, fx = 2 * E * cosφ * sinλ_2 - x, fy = E * sinφ - y, δxδλ = F * (cos2φ * sin2λ_2 + E * cosφ * cosλ_2 * sin2φ), δxδφ = F * (.5 * sinλ * sin_2φ - E * 2 * sinφ * sinλ_2), δyδλ = F * .25 * (sin_2φ * sinλ_2 - E * sinφ * cos2φ * sinλ), δyδφ = F * (sin2φ * cosλ_2 + E * sin2λ_2 * cosφ), denominator = δxδφ * δyδλ - δyδφ * δxδλ;\n      if (!denominator) break;\n      var δλ = (fy * δxδφ - fx * δyδφ) / denominator, δφ = (fx * δyδλ - fy * δxδλ) / denominator;\n      λ -= δλ, φ -= δφ;\n    } while ((Math.abs(δλ) > ε || Math.abs(δφ) > ε) && --i > 0);\n    return [ λ, φ ];\n  };\n  (d3.geo.aitoff = function() {\n    return projection(aitoff);\n  }).raw = aitoff;\n  function winkel3(λ, φ) {\n    var coordinates = aitoff(λ, φ);\n    return [ (coordinates[0] + λ / halfπ) / 2, (coordinates[1] + φ) / 2 ];\n  }\n  winkel3.invert = function(x, y) {\n    var λ = x, φ = y, i = 25;\n    do {\n      var cosφ = Math.cos(φ), sinφ = Math.sin(φ), sin_2φ = Math.sin(2 * φ), sin2φ = sinφ * sinφ, cos2φ = cosφ * cosφ, sinλ = Math.sin(λ), cosλ_2 = Math.cos(λ / 2), sinλ_2 = Math.sin(λ / 2), sin2λ_2 = sinλ_2 * sinλ_2, C = 1 - cos2φ * cosλ_2 * cosλ_2, E = C ? acos(cosφ * cosλ_2) * Math.sqrt(F = 1 / C) : F = 0, F, fx = .5 * (2 * E * cosφ * sinλ_2 + λ / halfπ) - x, fy = .5 * (E * sinφ + φ) - y, δxδλ = .5 * F * (cos2φ * sin2λ_2 + E * cosφ * cosλ_2 * sin2φ) + .5 / halfπ, δxδφ = F * (sinλ * sin_2φ / 4 - E * sinφ * sinλ_2), δyδλ = .125 * F * (sin_2φ * sinλ_2 - E * sinφ * cos2φ * sinλ), δyδφ = .5 * F * (sin2φ * cosλ_2 + E * sin2λ_2 * cosφ) + .5, denominator = δxδφ * δyδλ - δyδφ * δxδλ, δλ = (fy * δxδφ - fx * δyδφ) / denominator, δφ = (fx * δyδλ - fy * δxδλ) / denominator;\n      λ -= δλ, φ -= δφ;\n    } while ((Math.abs(δλ) > ε || Math.abs(δφ) > ε) && --i > 0);\n    return [ λ, φ ];\n  };\n  (d3.geo.winkel3 = function() {\n    return projection(winkel3);\n  }).raw = winkel3;\n}\n\nmodule.exports = addProjectionsToD3;\n\n},{}],801:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\n\nvar radians = Math.PI / 180;\nvar degrees = 180 / Math.PI;\nvar zoomstartStyle = {cursor: 'pointer'};\nvar zoomendStyle = {cursor: 'auto'};\n\nfunction createGeoZoom(geo, geoLayout) {\n    var projection = geo.projection;\n    var zoomConstructor;\n\n    if(geoLayout._isScoped) {\n        zoomConstructor = zoomScoped;\n    } else if(geoLayout._isClipped) {\n        zoomConstructor = zoomClipped;\n    } else {\n        zoomConstructor = zoomNonClipped;\n    }\n\n    // TODO add a conic-specific zoom\n\n    return zoomConstructor(geo, projection);\n}\n\nmodule.exports = createGeoZoom;\n\n// common to all zoom types\nfunction initZoom(geo, projection) {\n    return d3.behavior.zoom()\n        .translate(projection.translate())\n        .scale(projection.scale());\n}\n\n// sync zoom updates with user & full layout\nfunction sync(geo, projection, cb) {\n    var id = geo.id;\n    var gd = geo.graphDiv;\n    var layout = gd.layout;\n    var userOpts = layout[id];\n    var fullLayout = gd._fullLayout;\n    var fullOpts = fullLayout[id];\n\n    var preGUI = {};\n    var eventData = {};\n\n    function set(propStr, val) {\n        preGUI[id + '.' + propStr] = Lib.nestedProperty(userOpts, propStr).get();\n        Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, preGUI);\n\n        var fullNp = Lib.nestedProperty(fullOpts, propStr);\n        if(fullNp.get() !== val) {\n            fullNp.set(val);\n            Lib.nestedProperty(userOpts, propStr).set(val);\n            eventData[id + '.' + propStr] = val;\n        }\n    }\n\n    cb(set);\n    set('projection.scale', projection.scale() / geo.fitScale);\n    gd.emit('plotly_relayout', eventData);\n}\n\n// zoom for scoped projections\nfunction zoomScoped(geo, projection) {\n    var zoom = initZoom(geo, projection);\n\n    function handleZoomstart() {\n        d3.select(this).style(zoomstartStyle);\n    }\n\n    function handleZoom() {\n        projection\n            .scale(d3.event.scale)\n            .translate(d3.event.translate);\n        geo.render();\n\n        var center = projection.invert(geo.midPt);\n        geo.graphDiv.emit('plotly_relayouting', {\n            'geo.projection.scale': projection.scale() / geo.fitScale,\n            'geo.center.lon': center[0],\n            'geo.center.lat': center[1]\n        });\n    }\n\n    function syncCb(set) {\n        var center = projection.invert(geo.midPt);\n\n        set('center.lon', center[0]);\n        set('center.lat', center[1]);\n    }\n\n    function handleZoomend() {\n        d3.select(this).style(zoomendStyle);\n        sync(geo, projection, syncCb);\n    }\n\n    zoom\n        .on('zoomstart', handleZoomstart)\n        .on('zoom', handleZoom)\n        .on('zoomend', handleZoomend);\n\n    return zoom;\n}\n\n// zoom for non-clipped projections\nfunction zoomNonClipped(geo, projection) {\n    var zoom = initZoom(geo, projection);\n\n    var INSIDETOLORANCEPXS = 2;\n\n    var mouse0, rotate0, translate0, lastRotate, zoomPoint,\n        mouse1, rotate1, point1, didZoom;\n\n    function position(x) { return projection.invert(x); }\n\n    function outside(x) {\n        var pos = position(x);\n        if(!pos) return true;\n\n        var pt = projection(pos);\n        return (\n            Math.abs(pt[0] - x[0]) > INSIDETOLORANCEPXS ||\n            Math.abs(pt[1] - x[1]) > INSIDETOLORANCEPXS\n        );\n    }\n\n    function handleZoomstart() {\n        d3.select(this).style(zoomstartStyle);\n\n        mouse0 = d3.mouse(this);\n        rotate0 = projection.rotate();\n        translate0 = projection.translate();\n        lastRotate = rotate0;\n        zoomPoint = position(mouse0);\n    }\n\n    function handleZoom() {\n        mouse1 = d3.mouse(this);\n\n        if(outside(mouse0)) {\n            zoom.scale(projection.scale());\n            zoom.translate(projection.translate());\n            return;\n        }\n\n        projection.scale(d3.event.scale);\n        projection.translate([translate0[0], d3.event.translate[1]]);\n\n        if(!zoomPoint) {\n            mouse0 = mouse1;\n            zoomPoint = position(mouse0);\n        } else if(position(mouse1)) {\n            point1 = position(mouse1);\n            rotate1 = [lastRotate[0] + (point1[0] - zoomPoint[0]), rotate0[1], rotate0[2]];\n            projection.rotate(rotate1);\n            lastRotate = rotate1;\n        }\n\n        didZoom = true;\n        geo.render();\n\n        var rotate = projection.rotate();\n        var center = projection.invert(geo.midPt);\n        geo.graphDiv.emit('plotly_relayouting', {\n            'geo.projection.scale': projection.scale() / geo.fitScale,\n            'geo.center.lon': center[0],\n            'geo.center.lat': center[1],\n            'geo.projection.rotation.lon': -rotate[0]\n\n        });\n    }\n\n    function handleZoomend() {\n        d3.select(this).style(zoomendStyle);\n        if(didZoom) sync(geo, projection, syncCb);\n    }\n\n    function syncCb(set) {\n        var rotate = projection.rotate();\n        var center = projection.invert(geo.midPt);\n\n        set('projection.rotation.lon', -rotate[0]);\n        set('center.lon', center[0]);\n        set('center.lat', center[1]);\n    }\n\n    zoom\n        .on('zoomstart', handleZoomstart)\n        .on('zoom', handleZoom)\n        .on('zoomend', handleZoomend);\n\n    return zoom;\n}\n\n// zoom for clipped projections\n// inspired by https://www.jasondavies.com/maps/d3.geo.zoom.js\nfunction zoomClipped(geo, projection) {\n    var view = {r: projection.rotate(), k: projection.scale()};\n    var zoom = initZoom(geo, projection);\n    var event = d3eventDispatch(zoom, 'zoomstart', 'zoom', 'zoomend');\n    var zooming = 0;\n    var zoomOn = zoom.on;\n\n    var zoomPoint;\n\n    zoom.on('zoomstart', function() {\n        d3.select(this).style(zoomstartStyle);\n\n        var mouse0 = d3.mouse(this);\n        var rotate0 = projection.rotate();\n        var lastRotate = rotate0;\n        var translate0 = projection.translate();\n        var q = quaternionFromEuler(rotate0);\n\n        zoomPoint = position(projection, mouse0);\n\n        zoomOn.call(zoom, 'zoom', function() {\n            var mouse1 = d3.mouse(this);\n\n            projection.scale(view.k = d3.event.scale);\n\n            if(!zoomPoint) {\n                // if no zoomPoint, the mouse wasn't over the actual geography yet\n                // maybe this point is the start... we'll find out next time!\n                mouse0 = mouse1;\n                zoomPoint = position(projection, mouse0);\n            } else if(position(projection, mouse1)) {\n                // check if the point is on the map\n                // if not, don't do anything new but scale\n                // if it is, then we can assume between will exist below\n                // so we don't need the 'bank' function, whatever that is.\n\n                // go back to original projection temporarily\n                // except for scale... that's kind of independent?\n                projection\n                    .rotate(rotate0)\n                    .translate(translate0);\n\n                // calculate the new params\n                var point1 = position(projection, mouse1);\n                var between = rotateBetween(zoomPoint, point1);\n                var newEuler = eulerFromQuaternion(multiply(q, between));\n                var rotateAngles = view.r = unRoll(newEuler, zoomPoint, lastRotate);\n\n                if(!isFinite(rotateAngles[0]) || !isFinite(rotateAngles[1]) ||\n                   !isFinite(rotateAngles[2])) {\n                    rotateAngles = lastRotate;\n                }\n\n                // update the projection\n                projection.rotate(rotateAngles);\n                lastRotate = rotateAngles;\n            }\n\n            zoomed(event.of(this, arguments));\n        });\n\n        zoomstarted(event.of(this, arguments));\n    })\n    .on('zoomend', function() {\n        d3.select(this).style(zoomendStyle);\n        zoomOn.call(zoom, 'zoom', null);\n        zoomended(event.of(this, arguments));\n        sync(geo, projection, syncCb);\n    })\n    .on('zoom.redraw', function() {\n        geo.render();\n\n        var _rotate = projection.rotate();\n        geo.graphDiv.emit('plotly_relayouting', {\n            'geo.projection.scale': projection.scale() / geo.fitScale,\n            'geo.projection.rotation.lon': -_rotate[0],\n            'geo.projection.rotation.lat': -_rotate[1]\n        });\n    });\n\n    function zoomstarted(dispatch) {\n        if(!zooming++) dispatch({type: 'zoomstart'});\n    }\n\n    function zoomed(dispatch) {\n        dispatch({type: 'zoom'});\n    }\n\n    function zoomended(dispatch) {\n        if(!--zooming) dispatch({type: 'zoomend'});\n    }\n\n    function syncCb(set) {\n        var _rotate = projection.rotate();\n        set('projection.rotation.lon', -_rotate[0]);\n        set('projection.rotation.lat', -_rotate[1]);\n    }\n\n    return d3.rebind(zoom, event, 'on');\n}\n\n// -- helper functions for zoomClipped\n\nfunction position(projection, point) {\n    var spherical = projection.invert(point);\n    return spherical && isFinite(spherical[0]) && isFinite(spherical[1]) && cartesian(spherical);\n}\n\nfunction quaternionFromEuler(euler) {\n    var lambda = 0.5 * euler[0] * radians;\n    var phi = 0.5 * euler[1] * radians;\n    var gamma = 0.5 * euler[2] * radians;\n    var sinLambda = Math.sin(lambda);\n    var cosLambda = Math.cos(lambda);\n    var sinPhi = Math.sin(phi);\n    var cosPhi = Math.cos(phi);\n    var sinGamma = Math.sin(gamma);\n    var cosGamma = Math.cos(gamma);\n    return [\n        cosLambda * cosPhi * cosGamma + sinLambda * sinPhi * sinGamma,\n        sinLambda * cosPhi * cosGamma - cosLambda * sinPhi * sinGamma,\n        cosLambda * sinPhi * cosGamma + sinLambda * cosPhi * sinGamma,\n        cosLambda * cosPhi * sinGamma - sinLambda * sinPhi * cosGamma\n    ];\n}\n\nfunction multiply(a, b) {\n    var a0 = a[0];\n    var a1 = a[1];\n    var a2 = a[2];\n    var a3 = a[3];\n    var b0 = b[0];\n    var b1 = b[1];\n    var b2 = b[2];\n    var b3 = b[3];\n    return [\n        a0 * b0 - a1 * b1 - a2 * b2 - a3 * b3,\n        a0 * b1 + a1 * b0 + a2 * b3 - a3 * b2,\n        a0 * b2 - a1 * b3 + a2 * b0 + a3 * b1,\n        a0 * b3 + a1 * b2 - a2 * b1 + a3 * b0\n    ];\n}\n\nfunction rotateBetween(a, b) {\n    if(!a || !b) return;\n    var axis = cross(a, b);\n    var norm = Math.sqrt(dot(axis, axis));\n    var halfgamma = 0.5 * Math.acos(Math.max(-1, Math.min(1, dot(a, b))));\n    var k = Math.sin(halfgamma) / norm;\n    return norm && [Math.cos(halfgamma), axis[2] * k, -axis[1] * k, axis[0] * k];\n}\n\n// input:\n//   rotateAngles: a calculated set of Euler angles\n//   pt: a point (cartesian in 3-space) to keep fixed\n//   roll0: an initial roll, to be preserved\n// output:\n//   a set of Euler angles that preserve the projection of pt\n//     but set roll (output[2]) equal to roll0\n//     note that this doesn't depend on the particular projection,\n//     just on the rotation angles\nfunction unRoll(rotateAngles, pt, lastRotate) {\n    // calculate the fixed point transformed by these Euler angles\n    // but with the desired roll undone\n    var ptRotated = rotateCartesian(pt, 2, rotateAngles[0]);\n    ptRotated = rotateCartesian(ptRotated, 1, rotateAngles[1]);\n    ptRotated = rotateCartesian(ptRotated, 0, rotateAngles[2] - lastRotate[2]);\n\n    var x = pt[0];\n    var y = pt[1];\n    var z = pt[2];\n    var f = ptRotated[0];\n    var g = ptRotated[1];\n    var h = ptRotated[2];\n\n    // the following essentially solves:\n    // ptRotated = rotateCartesian(rotateCartesian(pt, 2, newYaw), 1, newPitch)\n    // for newYaw and newPitch, as best it can\n    var theta = Math.atan2(y, x) * degrees;\n    var a = Math.sqrt(x * x + y * y);\n    var b;\n    var newYaw1;\n\n    if(Math.abs(g) > a) {\n        newYaw1 = (g > 0 ? 90 : -90) - theta;\n        b = 0;\n    } else {\n        newYaw1 = Math.asin(g / a) * degrees - theta;\n        b = Math.sqrt(a * a - g * g);\n    }\n\n    var newYaw2 = 180 - newYaw1 - 2 * theta;\n    var newPitch1 = (Math.atan2(h, f) - Math.atan2(z, b)) * degrees;\n    var newPitch2 = (Math.atan2(h, f) - Math.atan2(z, -b)) * degrees;\n\n    // which is closest to lastRotate[0,1]: newYaw/Pitch or newYaw2/Pitch2?\n    var dist1 = angleDistance(lastRotate[0], lastRotate[1], newYaw1, newPitch1);\n    var dist2 = angleDistance(lastRotate[0], lastRotate[1], newYaw2, newPitch2);\n\n    if(dist1 <= dist2) return [newYaw1, newPitch1, lastRotate[2]];\n    else return [newYaw2, newPitch2, lastRotate[2]];\n}\n\nfunction angleDistance(yaw0, pitch0, yaw1, pitch1) {\n    var dYaw = angleMod(yaw1 - yaw0);\n    var dPitch = angleMod(pitch1 - pitch0);\n    return Math.sqrt(dYaw * dYaw + dPitch * dPitch);\n}\n\n// reduce an angle in degrees to [-180,180]\nfunction angleMod(angle) {\n    return (angle % 360 + 540) % 360 - 180;\n}\n\n// rotate a cartesian vector\n// axis is 0 (x), 1 (y), or 2 (z)\n// angle is in degrees\nfunction rotateCartesian(vector, axis, angle) {\n    var angleRads = angle * radians;\n    var vectorOut = vector.slice();\n    var ax1 = (axis === 0) ? 1 : 0;\n    var ax2 = (axis === 2) ? 1 : 2;\n    var cosa = Math.cos(angleRads);\n    var sina = Math.sin(angleRads);\n\n    vectorOut[ax1] = vector[ax1] * cosa - vector[ax2] * sina;\n    vectorOut[ax2] = vector[ax2] * cosa + vector[ax1] * sina;\n\n    return vectorOut;\n}\nfunction eulerFromQuaternion(q) {\n    return [\n        Math.atan2(2 * (q[0] * q[1] + q[2] * q[3]), 1 - 2 * (q[1] * q[1] + q[2] * q[2])) * degrees,\n        Math.asin(Math.max(-1, Math.min(1, 2 * (q[0] * q[2] - q[3] * q[1])))) * degrees,\n        Math.atan2(2 * (q[0] * q[3] + q[1] * q[2]), 1 - 2 * (q[2] * q[2] + q[3] * q[3])) * degrees\n    ];\n}\n\nfunction cartesian(spherical) {\n    var lambda = spherical[0] * radians;\n    var phi = spherical[1] * radians;\n    var cosPhi = Math.cos(phi);\n    return [\n        cosPhi * Math.cos(lambda),\n        cosPhi * Math.sin(lambda),\n        Math.sin(phi)\n    ];\n}\n\nfunction dot(a, b) {\n    var s = 0;\n    for(var i = 0, n = a.length; i < n; ++i) s += a[i] * b[i];\n    return s;\n}\n\nfunction cross(a, b) {\n    return [\n        a[1] * b[2] - a[2] * b[1],\n        a[2] * b[0] - a[0] * b[2],\n        a[0] * b[1] - a[1] * b[0]\n    ];\n}\n\n// Like d3.dispatch, but for custom events abstracting native UI events. These\n// events have a target component (such as a brush), a target element (such as\n// the svg:g element containing the brush) and the standard arguments `d` (the\n// target element's data) and `i` (the selection index of the target element).\nfunction d3eventDispatch(target) {\n    var i = 0;\n    var n = arguments.length;\n    var argumentz = [];\n\n    while(++i < n) argumentz.push(arguments[i]);\n\n    var dispatch = d3.dispatch.apply(null, argumentz);\n\n    // Creates a dispatch context for the specified `thiz` (typically, the target\n    // DOM element that received the source event) and `argumentz` (typically, the\n    // data `d` and index `i` of the target element). The returned function can be\n    // used to dispatch an event to any registered listeners; the function takes a\n    // single argument as input, being the event to dispatch. The event must have\n    // a \"type\" attribute which corresponds to a type registered in the\n    // constructor. This context will automatically populate the \"sourceEvent\" and\n    // \"target\" attributes of the event, as well as setting the `d3.event` global\n    // for the duration of the notification.\n    dispatch.of = function(thiz, argumentz) {\n        return function(e1) {\n            var e0;\n            try {\n                e0 = e1.sourceEvent = d3.event;\n                e1.target = target;\n                d3.event = e1;\n                dispatch[e1.type].apply(thiz, argumentz);\n            } finally {\n                d3.event = e0;\n            }\n        };\n    };\n\n    return dispatch;\n}\n\n},{\"../../lib\":719,\"../../registry\":847,\"d3\":163}],802:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../registry');\nvar SUBPLOT_PATTERN = _dereq_('./cartesian/constants').SUBPLOT_PATTERN;\n\n/**\n * Get calcdata trace(s) associated with a given subplot\n *\n * @param {array} calcData: as in gd.calcdata\n * @param {string} type: subplot type\n * @param {string} subplotId: subplot id to look for\n *\n * @return {array} array of calcdata traces\n */\nexports.getSubplotCalcData = function(calcData, type, subplotId) {\n    var basePlotModule = Registry.subplotsRegistry[type];\n    if(!basePlotModule) return [];\n\n    var attr = basePlotModule.attr;\n    var subplotCalcData = [];\n\n    for(var i = 0; i < calcData.length; i++) {\n        var calcTrace = calcData[i];\n        var trace = calcTrace[0].trace;\n\n        if(trace[attr] === subplotId) subplotCalcData.push(calcTrace);\n    }\n\n    return subplotCalcData;\n};\n/**\n * Get calcdata trace(s) that can be plotted with a given module\n * NOTE: this isn't necessarily just exactly matching trace type,\n * if multiple trace types use the same plotting routine, they will be\n * collected here.\n * In order to not plot the same thing multiple times, we return two arrays,\n * the calcdata we *will* plot with this module, and the ones we *won't*\n *\n * @param {array} calcdata: as in gd.calcdata\n * @param {object|string|fn} arg1:\n *  the plotting module, or its name, or its plot method\n *\n * @return {array[array]} [foundCalcdata, remainingCalcdata]\n */\nexports.getModuleCalcData = function(calcdata, arg1) {\n    var moduleCalcData = [];\n    var remainingCalcData = [];\n\n    var plotMethod;\n    if(typeof arg1 === 'string') {\n        plotMethod = Registry.getModule(arg1).plot;\n    } else if(typeof arg1 === 'function') {\n        plotMethod = arg1;\n    } else {\n        plotMethod = arg1.plot;\n    }\n    if(!plotMethod) {\n        return [moduleCalcData, calcdata];\n    }\n\n    for(var i = 0; i < calcdata.length; i++) {\n        var cd = calcdata[i];\n        var trace = cd[0].trace;\n        // N.B.\n        // - 'legendonly' traces do not make it past here\n        // - skip over 'visible' traces that got trimmed completely during calc transforms\n        if(trace.visible !== true || trace._length === 0) continue;\n\n        // group calcdata trace not by 'module' (as the name of this function\n        // would suggest), but by 'module plot method' so that if some traces\n        // share the same module plot method (e.g. bar and histogram), we\n        // only call it one!\n        if(trace._module.plot === plotMethod) {\n            moduleCalcData.push(cd);\n        } else {\n            remainingCalcData.push(cd);\n        }\n    }\n\n    return [moduleCalcData, remainingCalcData];\n};\n\n/**\n * Get the data trace(s) associated with a given subplot.\n *\n * @param {array} data  plotly full data array.\n * @param {string} type subplot type to look for.\n * @param {string} subplotId subplot id to look for.\n *\n * @return {array} list of trace objects.\n *\n */\nexports.getSubplotData = function getSubplotData(data, type, subplotId) {\n    if(!Registry.subplotsRegistry[type]) return [];\n\n    var attr = Registry.subplotsRegistry[type].attr;\n    var subplotData = [];\n    var trace, subplotX, subplotY;\n\n    if(type === 'gl2d') {\n        var spmatch = subplotId.match(SUBPLOT_PATTERN);\n        subplotX = 'x' + spmatch[1];\n        subplotY = 'y' + spmatch[2];\n    }\n\n    for(var i = 0; i < data.length; i++) {\n        trace = data[i];\n\n        if(type === 'gl2d' && Registry.traceIs(trace, 'gl2d')) {\n            if(trace[attr[0]] === subplotX && trace[attr[1]] === subplotY) {\n                subplotData.push(trace);\n            }\n        } else {\n            if(trace[attr] === subplotId) subplotData.push(trace);\n        }\n    }\n\n    return subplotData;\n};\n\n},{\"../registry\":847,\"./cartesian/constants\":773}],803:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar mouseChange = _dereq_('mouse-change');\nvar mouseWheel = _dereq_('mouse-wheel');\nvar mouseOffset = _dereq_('mouse-event-offset');\nvar cartesianConstants = _dereq_('../cartesian/constants');\nvar hasPassive = _dereq_('has-passive-events');\n\nmodule.exports = createCamera;\n\nfunction Camera2D(element, plot) {\n    this.element = element;\n    this.plot = plot;\n    this.mouseListener = null;\n    this.wheelListener = null;\n    this.lastInputTime = Date.now();\n    this.lastPos = [0, 0];\n    this.boxEnabled = false;\n    this.boxInited = false;\n    this.boxStart = [0, 0];\n    this.boxEnd = [0, 0];\n    this.dragStart = [0, 0];\n}\n\n\nfunction createCamera(scene) {\n    var element = scene.mouseContainer;\n    var plot = scene.glplot;\n    var result = new Camera2D(element, plot);\n\n    function unSetAutoRange() {\n        scene.xaxis.autorange = false;\n        scene.yaxis.autorange = false;\n    }\n\n    function getSubplotConstraint() {\n        // note: this assumes we only have one x and one y axis on this subplot\n        // when this constraint is lifted this block won't make sense\n        var constraints = scene.graphDiv._fullLayout._axisConstraintGroups;\n        var xaId = scene.xaxis._id;\n        var yaId = scene.yaxis._id;\n        for(var i = 0; i < constraints.length; i++) {\n            if(constraints[i][xaId] !== -1) {\n                if(constraints[i][yaId] !== -1) return true;\n                break;\n            }\n        }\n        return false;\n    }\n\n    result.mouseListener = mouseChange(element, handleInteraction);\n\n    // enable simple touch interactions\n    element.addEventListener('touchstart', function(ev) {\n        var xy = mouseOffset(ev.changedTouches[0], element);\n        handleInteraction(0, xy[0], xy[1]);\n        handleInteraction(1, xy[0], xy[1]);\n\n        ev.preventDefault();\n    }, hasPassive ? {passive: false} : false);\n    element.addEventListener('touchmove', function(ev) {\n        ev.preventDefault();\n        var xy = mouseOffset(ev.changedTouches[0], element);\n        handleInteraction(1, xy[0], xy[1]);\n\n        ev.preventDefault();\n    }, hasPassive ? {passive: false} : false);\n    element.addEventListener('touchend', function(ev) {\n        handleInteraction(0, result.lastPos[0], result.lastPos[1]);\n\n        ev.preventDefault();\n    }, hasPassive ? {passive: false} : false);\n\n    function handleInteraction(buttons, x, y) {\n        var dataBox = scene.calcDataBox();\n        var viewBox = plot.viewBox;\n\n        var lastX = result.lastPos[0];\n        var lastY = result.lastPos[1];\n\n        var MINDRAG = cartesianConstants.MINDRAG * plot.pixelRatio;\n        var MINZOOM = cartesianConstants.MINZOOM * plot.pixelRatio;\n\n        var dx, dy;\n\n        x *= plot.pixelRatio;\n        y *= plot.pixelRatio;\n\n        // mouseChange gives y about top; convert to about bottom\n        y = (viewBox[3] - viewBox[1]) - y;\n\n        function updateRange(i0, start, end) {\n            var range0 = Math.min(start, end);\n            var range1 = Math.max(start, end);\n\n            if(range0 !== range1) {\n                dataBox[i0] = range0;\n                dataBox[i0 + 2] = range1;\n                result.dataBox = dataBox;\n                scene.setRanges(dataBox);\n            } else {\n                scene.selectBox.selectBox = [0, 0, 1, 1];\n                scene.glplot.setDirty();\n            }\n        }\n\n        switch(scene.fullLayout.dragmode) {\n            case 'zoom':\n                if(buttons) {\n                    var dataX = x /\n                            (viewBox[2] - viewBox[0]) * (dataBox[2] - dataBox[0]) +\n                        dataBox[0];\n                    var dataY = y /\n                            (viewBox[3] - viewBox[1]) * (dataBox[3] - dataBox[1]) +\n                        dataBox[1];\n\n                    if(!result.boxInited) {\n                        result.boxStart[0] = dataX;\n                        result.boxStart[1] = dataY;\n                        result.dragStart[0] = x;\n                        result.dragStart[1] = y;\n                    }\n\n                    result.boxEnd[0] = dataX;\n                    result.boxEnd[1] = dataY;\n\n                    // we need to mark the box as initialized right away\n                    // so that we can tell the start and end points apart\n                    result.boxInited = true;\n\n                    // but don't actually enable the box until the cursor moves\n                    if(!result.boxEnabled && (\n                        result.boxStart[0] !== result.boxEnd[0] ||\n                        result.boxStart[1] !== result.boxEnd[1])\n                    ) {\n                        result.boxEnabled = true;\n                    }\n\n                    // constrain aspect ratio if the axes require it\n                    var smallDx = Math.abs(result.dragStart[0] - x) < MINZOOM;\n                    var smallDy = Math.abs(result.dragStart[1] - y) < MINZOOM;\n                    if(getSubplotConstraint() && !(smallDx && smallDy)) {\n                        dx = result.boxEnd[0] - result.boxStart[0];\n                        dy = result.boxEnd[1] - result.boxStart[1];\n                        var dydx = (dataBox[3] - dataBox[1]) / (dataBox[2] - dataBox[0]);\n\n                        if(Math.abs(dx * dydx) > Math.abs(dy)) {\n                            result.boxEnd[1] = result.boxStart[1] +\n                                Math.abs(dx) * dydx * (dy >= 0 ? 1 : -1);\n\n                            // gl-select-box clips to the plot area bounds,\n                            // which breaks the axis constraint, so don't allow\n                            // this box to go out of bounds\n                            if(result.boxEnd[1] < dataBox[1]) {\n                                result.boxEnd[1] = dataBox[1];\n                                result.boxEnd[0] = result.boxStart[0] +\n                                    (dataBox[1] - result.boxStart[1]) / Math.abs(dydx);\n                            } else if(result.boxEnd[1] > dataBox[3]) {\n                                result.boxEnd[1] = dataBox[3];\n                                result.boxEnd[0] = result.boxStart[0] +\n                                    (dataBox[3] - result.boxStart[1]) / Math.abs(dydx);\n                            }\n                        } else {\n                            result.boxEnd[0] = result.boxStart[0] +\n                                Math.abs(dy) / dydx * (dx >= 0 ? 1 : -1);\n\n                            if(result.boxEnd[0] < dataBox[0]) {\n                                result.boxEnd[0] = dataBox[0];\n                                result.boxEnd[1] = result.boxStart[1] +\n                                    (dataBox[0] - result.boxStart[0]) * Math.abs(dydx);\n                            } else if(result.boxEnd[0] > dataBox[2]) {\n                                result.boxEnd[0] = dataBox[2];\n                                result.boxEnd[1] = result.boxStart[1] +\n                                    (dataBox[2] - result.boxStart[0]) * Math.abs(dydx);\n                            }\n                        }\n                    } else {\n                        // otherwise clamp small changes to the origin so we get 1D zoom\n\n                        if(smallDx) result.boxEnd[0] = result.boxStart[0];\n                        if(smallDy) result.boxEnd[1] = result.boxStart[1];\n                    }\n                } else if(result.boxEnabled) {\n                    dx = result.boxStart[0] !== result.boxEnd[0];\n                    dy = result.boxStart[1] !== result.boxEnd[1];\n                    if(dx || dy) {\n                        if(dx) {\n                            updateRange(0, result.boxStart[0], result.boxEnd[0]);\n                            scene.xaxis.autorange = false;\n                        }\n                        if(dy) {\n                            updateRange(1, result.boxStart[1], result.boxEnd[1]);\n                            scene.yaxis.autorange = false;\n                        }\n                        scene.relayoutCallback();\n                    } else {\n                        scene.glplot.setDirty();\n                    }\n                    result.boxEnabled = false;\n                    result.boxInited = false;\n                } else if(result.boxInited) {\n                    // if box was inited but button released then - reset the box\n\n                    result.boxInited = false;\n                }\n                break;\n\n            case 'pan':\n                result.boxEnabled = false;\n                result.boxInited = false;\n\n                if(buttons) {\n                    if(!result.panning) {\n                        result.dragStart[0] = x;\n                        result.dragStart[1] = y;\n                    }\n\n                    if(Math.abs(result.dragStart[0] - x) < MINDRAG) x = result.dragStart[0];\n                    if(Math.abs(result.dragStart[1] - y) < MINDRAG) y = result.dragStart[1];\n\n                    dx = (lastX - x) * (dataBox[2] - dataBox[0]) /\n                        (plot.viewBox[2] - plot.viewBox[0]);\n                    dy = (lastY - y) * (dataBox[3] - dataBox[1]) /\n                        (plot.viewBox[3] - plot.viewBox[1]);\n\n                    dataBox[0] += dx;\n                    dataBox[2] += dx;\n                    dataBox[1] += dy;\n                    dataBox[3] += dy;\n\n                    scene.setRanges(dataBox);\n\n                    result.panning = true;\n                    result.lastInputTime = Date.now();\n                    unSetAutoRange();\n                    scene.cameraChanged();\n                    scene.handleAnnotations();\n                } else if(result.panning) {\n                    result.panning = false;\n                    scene.relayoutCallback();\n                }\n                break;\n        }\n\n        result.lastPos[0] = x;\n        result.lastPos[1] = y;\n    }\n\n    result.wheelListener = mouseWheel(element, function(dx, dy) {\n        if(!scene.scrollZoom) return false;\n\n        var dataBox = scene.calcDataBox();\n        var viewBox = plot.viewBox;\n\n        var lastX = result.lastPos[0];\n        var lastY = result.lastPos[1];\n\n        var scale = Math.exp(5.0 * dy / (viewBox[3] - viewBox[1]));\n\n        var cx = lastX /\n                (viewBox[2] - viewBox[0]) * (dataBox[2] - dataBox[0]) +\n            dataBox[0];\n        var cy = lastY /\n                (viewBox[3] - viewBox[1]) * (dataBox[3] - dataBox[1]) +\n            dataBox[1];\n\n        dataBox[0] = (dataBox[0] - cx) * scale + cx;\n        dataBox[2] = (dataBox[2] - cx) * scale + cx;\n        dataBox[1] = (dataBox[1] - cy) * scale + cy;\n        dataBox[3] = (dataBox[3] - cy) * scale + cy;\n\n        scene.setRanges(dataBox);\n\n        result.lastInputTime = Date.now();\n        unSetAutoRange();\n        scene.cameraChanged();\n        scene.handleAnnotations();\n        scene.relayoutCallback();\n\n        return true;\n    }, true);\n\n    return result;\n}\n\n},{\"../cartesian/constants\":773,\"has-passive-events\":411,\"mouse-change\":435,\"mouse-event-offset\":436,\"mouse-wheel\":438}],804:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Axes = _dereq_('../cartesian/axes');\n\nvar str2RGBArray = _dereq_('../../lib/str2rgbarray');\n\nfunction Axes2DOptions(scene) {\n    this.scene = scene;\n    this.gl = scene.gl;\n    this.pixelRatio = scene.pixelRatio;\n\n    this.screenBox = [0, 0, 1, 1];\n    this.viewBox = [0, 0, 1, 1];\n    this.dataBox = [-1, -1, 1, 1];\n\n    this.borderLineEnable = [false, false, false, false];\n    this.borderLineWidth = [1, 1, 1, 1];\n    this.borderLineColor = [\n        [0, 0, 0, 1],\n        [0, 0, 0, 1],\n        [0, 0, 0, 1],\n        [0, 0, 0, 1]\n    ];\n\n    this.ticks = [[], []];\n    this.tickEnable = [true, true, false, false];\n    this.tickPad = [15, 15, 15, 15];\n    this.tickAngle = [0, 0, 0, 0];\n    this.tickColor = [\n        [0, 0, 0, 1],\n        [0, 0, 0, 1],\n        [0, 0, 0, 1],\n        [0, 0, 0, 1]\n    ];\n    this.tickMarkLength = [0, 0, 0, 0];\n    this.tickMarkWidth = [0, 0, 0, 0];\n    this.tickMarkColor = [\n        [0, 0, 0, 1],\n        [0, 0, 0, 1],\n        [0, 0, 0, 1],\n        [0, 0, 0, 1]\n    ];\n\n    this.labels = ['x', 'y'];\n    this.labelEnable = [true, true, false, false];\n    this.labelAngle = [0, Math.PI / 2, 0, 3.0 * Math.PI / 2];\n    this.labelPad = [15, 15, 15, 15];\n    this.labelSize = [12, 12];\n    this.labelFont = ['sans-serif', 'sans-serif'];\n    this.labelColor = [\n        [0, 0, 0, 1],\n        [0, 0, 0, 1],\n        [0, 0, 0, 1],\n        [0, 0, 0, 1]\n    ];\n\n    this.title = '';\n    this.titleEnable = true;\n    this.titleCenter = [0, 0, 0, 0];\n    this.titleAngle = 0;\n    this.titleColor = [0, 0, 0, 1];\n    this.titleFont = 'sans-serif';\n    this.titleSize = 18;\n\n    this.gridLineEnable = [true, true];\n    this.gridLineColor = [\n        [0, 0, 0, 0.5],\n        [0, 0, 0, 0.5]\n    ];\n    this.gridLineWidth = [1, 1];\n\n    this.zeroLineEnable = [true, true];\n    this.zeroLineWidth = [1, 1];\n    this.zeroLineColor = [\n        [0, 0, 0, 1],\n        [0, 0, 0, 1]\n    ];\n\n    this.borderColor = [0, 0, 0, 0];\n    this.backgroundColor = [0, 0, 0, 0];\n\n    this.static = this.scene.staticPlot;\n}\n\nvar proto = Axes2DOptions.prototype;\n\nvar AXES = ['xaxis', 'yaxis'];\n\nproto.merge = function(options) {\n    // titles are rendered in SVG\n    this.titleEnable = false;\n    this.backgroundColor = str2RGBArray(options.plot_bgcolor);\n\n    var axisName, ax, axTitle, axMirror;\n    var hasAxisInDfltPos, hasAxisInAltrPos, hasSharedAxis, mirrorLines, mirrorTicks;\n    var i, j;\n\n    for(i = 0; i < 2; ++i) {\n        axisName = AXES[i];\n        var axisLetter = axisName.charAt(0);\n\n        // get options relevant to this subplot,\n        // '_name' is e.g. xaxis, xaxis2, yaxis, yaxis4 ...\n        ax = options[this.scene[axisName]._name];\n\n        axTitle = ax.title.text === this.scene.fullLayout._dfltTitle[axisLetter] ? '' : ax.title.text;\n\n        for(j = 0; j <= 2; j += 2) {\n            this.labelEnable[i + j] = false;\n            this.labels[i + j] = axTitle;\n            this.labelColor[i + j] = str2RGBArray(ax.title.font.color);\n            this.labelFont[i + j] = ax.title.font.family;\n            this.labelSize[i + j] = ax.title.font.size;\n            this.labelPad[i + j] = this.getLabelPad(axisName, ax);\n\n            this.tickEnable[i + j] = false;\n            this.tickColor[i + j] = str2RGBArray((ax.tickfont || {}).color);\n            this.tickAngle[i + j] = (ax.tickangle === 'auto') ?\n                0 :\n                Math.PI * -ax.tickangle / 180;\n            this.tickPad[i + j] = this.getTickPad(ax);\n\n            this.tickMarkLength[i + j] = 0;\n            this.tickMarkWidth[i + j] = ax.tickwidth || 0;\n            this.tickMarkColor[i + j] = str2RGBArray(ax.tickcolor);\n\n            this.borderLineEnable[i + j] = false;\n            this.borderLineColor[i + j] = str2RGBArray(ax.linecolor);\n            this.borderLineWidth[i + j] = ax.linewidth || 0;\n        }\n\n        hasSharedAxis = this.hasSharedAxis(ax);\n        hasAxisInDfltPos = this.hasAxisInDfltPos(axisName, ax) && !hasSharedAxis;\n        hasAxisInAltrPos = this.hasAxisInAltrPos(axisName, ax) && !hasSharedAxis;\n\n        axMirror = ax.mirror || false;\n        mirrorLines = hasSharedAxis ?\n            (String(axMirror).indexOf('all') !== -1) :  // 'all' or 'allticks'\n            !!axMirror;                                 // all but false\n        mirrorTicks = hasSharedAxis ?\n            (axMirror === 'allticks') :\n            (String(axMirror).indexOf('ticks') !== -1); // 'ticks' or 'allticks'\n\n        // Axis titles and tick labels can only appear of one side of the scene\n        //  and are never show on subplots that share existing axes.\n\n        if(hasAxisInDfltPos) this.labelEnable[i] = true;\n        else if(hasAxisInAltrPos) this.labelEnable[i + 2] = true;\n\n        if(hasAxisInDfltPos) this.tickEnable[i] = ax.showticklabels;\n        else if(hasAxisInAltrPos) this.tickEnable[i + 2] = ax.showticklabels;\n\n        // Grid lines and ticks can appear on both sides of the scene\n        //  and can appear on subplot that share existing axes via `ax.mirror`.\n\n        if(hasAxisInDfltPos || mirrorLines) this.borderLineEnable[i] = ax.showline;\n        if(hasAxisInAltrPos || mirrorLines) this.borderLineEnable[i + 2] = ax.showline;\n\n        if(hasAxisInDfltPos || mirrorTicks) this.tickMarkLength[i] = this.getTickMarkLength(ax);\n        if(hasAxisInAltrPos || mirrorTicks) this.tickMarkLength[i + 2] = this.getTickMarkLength(ax);\n\n        this.gridLineEnable[i] = ax.showgrid;\n        this.gridLineColor[i] = str2RGBArray(ax.gridcolor);\n        this.gridLineWidth[i] = ax.gridwidth;\n\n        this.zeroLineEnable[i] = ax.zeroline;\n        this.zeroLineColor[i] = str2RGBArray(ax.zerolinecolor);\n        this.zeroLineWidth[i] = ax.zerolinewidth;\n    }\n};\n\n// is an axis shared with an already-drawn subplot ?\nproto.hasSharedAxis = function(ax) {\n    var scene = this.scene;\n    var subplotIds = scene.fullLayout._subplots.gl2d;\n    var list = Axes.findSubplotsWithAxis(subplotIds, ax);\n\n    // if index === 0, then the subplot is already drawn as subplots\n    // are drawn in order.\n    return (list.indexOf(scene.id) !== 0);\n};\n\n// has an axis in default position (i.e. bottom/left) ?\nproto.hasAxisInDfltPos = function(axisName, ax) {\n    var axSide = ax.side;\n\n    if(axisName === 'xaxis') return (axSide === 'bottom');\n    else if(axisName === 'yaxis') return (axSide === 'left');\n};\n\n// has an axis in alternate position (i.e. top/right) ?\nproto.hasAxisInAltrPos = function(axisName, ax) {\n    var axSide = ax.side;\n\n    if(axisName === 'xaxis') return (axSide === 'top');\n    else if(axisName === 'yaxis') return (axSide === 'right');\n};\n\nproto.getLabelPad = function(axisName, ax) {\n    var offsetBase = 1.5;\n    var fontSize = ax.title.font.size;\n    var showticklabels = ax.showticklabels;\n\n    if(axisName === 'xaxis') {\n        return (ax.side === 'top') ?\n            -10 + fontSize * (offsetBase + (showticklabels ? 1 : 0)) :\n            -10 + fontSize * (offsetBase + (showticklabels ? 0.5 : 0));\n    } else if(axisName === 'yaxis') {\n        return (ax.side === 'right') ?\n            10 + fontSize * (offsetBase + (showticklabels ? 1 : 0.5)) :\n            10 + fontSize * (offsetBase + (showticklabels ? 0.5 : 0));\n    }\n};\n\nproto.getTickPad = function(ax) {\n    return (ax.ticks === 'outside') ? 10 + ax.ticklen : 15;\n};\n\nproto.getTickMarkLength = function(ax) {\n    if(!ax.ticks) return 0;\n\n    var ticklen = ax.ticklen;\n\n    return (ax.ticks === 'inside') ? -ticklen : ticklen;\n};\n\n\nfunction createAxes2D(scene) {\n    return new Axes2DOptions(scene);\n}\n\nmodule.exports = createAxes2D;\n\n},{\"../../lib/str2rgbarray\":742,\"../cartesian/axes\":767}],805:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar Scene2D = _dereq_('./scene2d');\nvar layoutGlobalAttrs = _dereq_('../layout_attributes');\nvar xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');\nvar constants = _dereq_('../cartesian/constants');\nvar Cartesian = _dereq_('../cartesian');\nvar fxAttrs = _dereq_('../../components/fx/layout_attributes');\nvar getSubplotData = _dereq_('../get_data').getSubplotData;\n\nexports.name = 'gl2d';\n\nexports.attr = ['xaxis', 'yaxis'];\n\nexports.idRoot = ['x', 'y'];\n\nexports.idRegex = constants.idRegex;\n\nexports.attrRegex = constants.attrRegex;\n\nexports.attributes = _dereq_('../cartesian/attributes');\n\nexports.supplyLayoutDefaults = function(layoutIn, layoutOut, fullData) {\n    if(!layoutOut._has('cartesian')) {\n        Cartesian.supplyLayoutDefaults(layoutIn, layoutOut, fullData);\n    }\n};\n\n// gl2d uses svg axis attributes verbatim, but overrides editType\n// this could potentially be just `layoutAttributes` but it would\n// still need special handling somewhere to give it precedence over\n// the svg version when both are in use on one plot\nexports.layoutAttrOverrides = overrideAll(Cartesian.layoutAttributes, 'plot', 'from-root');\n\n// similar overrides for base plot attributes (and those added by components)\nexports.baseLayoutAttrOverrides = overrideAll({\n    plot_bgcolor: layoutGlobalAttrs.plot_bgcolor,\n    hoverlabel: fxAttrs.hoverlabel\n    // dragmode needs calc but only when transitioning TO lasso or select\n    // so for now it's left inside _relayout\n    // dragmode: fxAttrs.dragmode\n}, 'plot', 'nested');\n\nexports.plot = function plot(gd) {\n    var fullLayout = gd._fullLayout;\n    var fullData = gd._fullData;\n    var subplotIds = fullLayout._subplots.gl2d;\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var subplotId = subplotIds[i];\n        var subplotObj = fullLayout._plots[subplotId];\n        var fullSubplotData = getSubplotData(fullData, 'gl2d', subplotId);\n\n        // ref. to corresp. Scene instance\n        var scene = subplotObj._scene2d;\n\n        // If Scene is not instantiated, create one!\n        if(scene === undefined) {\n            scene = new Scene2D({\n                id: subplotId,\n                graphDiv: gd,\n                container: gd.querySelector('.gl-container'),\n                staticPlot: gd._context.staticPlot,\n                plotGlPixelRatio: gd._context.plotGlPixelRatio\n            },\n                fullLayout\n            );\n\n            // set ref to Scene instance\n            subplotObj._scene2d = scene;\n        }\n\n        scene.plot(fullSubplotData, gd.calcdata, fullLayout, gd.layout);\n    }\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var oldSceneKeys = oldFullLayout._subplots.gl2d || [];\n\n    for(var i = 0; i < oldSceneKeys.length; i++) {\n        var id = oldSceneKeys[i];\n        var oldSubplot = oldFullLayout._plots[id];\n\n        // old subplot wasn't gl2d; nothing to do\n        if(!oldSubplot._scene2d) continue;\n\n        // if no traces are present, delete gl2d subplot\n        var subplotData = getSubplotData(newFullData, 'gl2d', id);\n        if(subplotData.length === 0) {\n            oldSubplot._scene2d.destroy();\n            delete oldFullLayout._plots[id];\n        }\n    }\n\n    // since we use cartesian interactions, do cartesian clean\n    Cartesian.clean.apply(this, arguments);\n};\n\nexports.drawFramework = function(gd) {\n    if(!gd._context.staticPlot) {\n        Cartesian.drawFramework(gd);\n    }\n};\n\nexports.toSVG = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var subplotIds = fullLayout._subplots.gl2d;\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var subplot = fullLayout._plots[subplotIds[i]];\n        var scene = subplot._scene2d;\n\n        var imageData = scene.toImage('png');\n        var image = fullLayout._glimages.append('svg:image');\n\n        image.attr({\n            xmlns: xmlnsNamespaces.svg,\n            'xlink:href': imageData,\n            x: 0,\n            y: 0,\n            width: '100%',\n            height: '100%',\n            preserveAspectRatio: 'none'\n        });\n\n        scene.destroy();\n    }\n};\n\nexports.updateFx = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var subplotIds = fullLayout._subplots.gl2d;\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var subplotObj = fullLayout._plots[subplotIds[i]]._scene2d;\n        subplotObj.updateFx(fullLayout.dragmode);\n    }\n};\n\n},{\"../../components/fx/layout_attributes\":633,\"../../constants/xmlns_namespaces\":696,\"../../plot_api/edit_types\":750,\"../cartesian\":778,\"../cartesian/attributes\":765,\"../cartesian/constants\":773,\"../get_data\":802,\"../layout_attributes\":819,\"./scene2d\":806}],806:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Fx = _dereq_('../../components/fx');\n\nvar createPlot2D = _dereq_('gl-plot2d');\nvar createSpikes = _dereq_('gl-spikes2d');\nvar createSelectBox = _dereq_('gl-select-box');\nvar getContext = _dereq_('webgl-context');\n\nvar createOptions = _dereq_('./convert');\nvar createCamera = _dereq_('./camera');\nvar showNoWebGlMsg = _dereq_('../../lib/show_no_webgl_msg');\nvar axisConstraints = _dereq_('../cartesian/constraints');\nvar enforceAxisConstraints = axisConstraints.enforce;\nvar cleanAxisConstraints = axisConstraints.clean;\nvar doAutoRange = _dereq_('../cartesian/autorange').doAutoRange;\n\nvar AXES = ['xaxis', 'yaxis'];\nvar STATIC_CANVAS, STATIC_CONTEXT;\n\nvar SUBPLOT_PATTERN = _dereq_('../cartesian/constants').SUBPLOT_PATTERN;\n\n\nfunction Scene2D(options, fullLayout) {\n    this.container = options.container;\n    this.graphDiv = options.graphDiv;\n    this.pixelRatio = options.plotGlPixelRatio || window.devicePixelRatio;\n    this.id = options.id;\n    this.staticPlot = !!options.staticPlot;\n    this.scrollZoom = this.graphDiv._context._scrollZoom.cartesian;\n\n    this.fullData = null;\n    this.updateRefs(fullLayout);\n\n    this.makeFramework();\n    if(this.stopped) return;\n\n    // update options\n    this.glplotOptions = createOptions(this);\n    this.glplotOptions.merge(fullLayout);\n\n    // create the plot\n    this.glplot = createPlot2D(this.glplotOptions);\n\n    // create camera\n    this.camera = createCamera(this);\n\n    // trace set\n    this.traces = {};\n\n    // create axes spikes\n    this.spikes = createSpikes(this.glplot);\n\n    this.selectBox = createSelectBox(this.glplot, {\n        innerFill: false,\n        outerFill: true\n    });\n\n    // last button state\n    this.lastButtonState = 0;\n\n    // last pick result\n    this.pickResult = null;\n\n    // is the mouse over the plot?\n    // it's OK if this says true when it's not, so long as\n    // when we get a mouseout we set it to false before handling\n    this.isMouseOver = true;\n\n    // flag to stop render loop\n    this.stopped = false;\n\n    // redraw the plot\n    this.redraw = this.draw.bind(this);\n    this.redraw();\n}\n\nmodule.exports = Scene2D;\n\nvar proto = Scene2D.prototype;\n\nproto.makeFramework = function() {\n    // create canvas and gl context\n    if(this.staticPlot) {\n        if(!STATIC_CONTEXT) {\n            STATIC_CANVAS = document.createElement('canvas');\n\n            STATIC_CONTEXT = getContext({\n                canvas: STATIC_CANVAS,\n                preserveDrawingBuffer: false,\n                premultipliedAlpha: true,\n                antialias: true\n            });\n\n            if(!STATIC_CONTEXT) {\n                throw new Error('Error creating static canvas/context for image server');\n            }\n        }\n\n        this.canvas = STATIC_CANVAS;\n        this.gl = STATIC_CONTEXT;\n    } else {\n        var liveCanvas = this.container.querySelector('.gl-canvas-focus');\n\n        var gl = getContext({\n            canvas: liveCanvas,\n            preserveDrawingBuffer: true,\n            premultipliedAlpha: true\n        });\n\n        if(!gl) {\n            showNoWebGlMsg(this);\n            this.stopped = true;\n            return;\n        }\n\n        this.canvas = liveCanvas;\n        this.gl = gl;\n    }\n\n    // position the canvas\n    var canvas = this.canvas;\n\n    canvas.style.width = '100%';\n    canvas.style.height = '100%';\n    canvas.style.position = 'absolute';\n    canvas.style.top = '0px';\n    canvas.style.left = '0px';\n    canvas.style['pointer-events'] = 'none';\n\n    this.updateSize(canvas);\n\n    // disabling user select on the canvas\n    // sanitizes double-clicks interactions\n    // ref: https://github.com/plotly/plotly.js/issues/744\n    canvas.className += ' user-select-none';\n\n    // create SVG container for hover text\n    var svgContainer = this.svgContainer = document.createElementNS(\n        'http://www.w3.org/2000/svg',\n        'svg');\n    svgContainer.style.position = 'absolute';\n    svgContainer.style.top = svgContainer.style.left = '0px';\n    svgContainer.style.width = svgContainer.style.height = '100%';\n    svgContainer.style['z-index'] = 20;\n    svgContainer.style['pointer-events'] = 'none';\n\n    // create div to catch the mouse event\n    var mouseContainer = this.mouseContainer = document.createElement('div');\n    mouseContainer.style.position = 'absolute';\n    mouseContainer.style['pointer-events'] = 'auto';\n\n    this.pickCanvas = this.container.querySelector('.gl-canvas-pick');\n\n\n    // append canvas, hover svg and mouse div to container\n    var container = this.container;\n    container.appendChild(svgContainer);\n    container.appendChild(mouseContainer);\n\n    var self = this;\n    mouseContainer.addEventListener('mouseout', function() {\n        self.isMouseOver = false;\n        self.unhover();\n    });\n    mouseContainer.addEventListener('mouseover', function() {\n        self.isMouseOver = true;\n    });\n};\n\nproto.toImage = function(format) {\n    if(!format) format = 'png';\n\n    this.stopped = true;\n\n    if(this.staticPlot) this.container.appendChild(STATIC_CANVAS);\n\n    // update canvas size\n    this.updateSize(this.canvas);\n\n\n    // grab context and yank out pixels\n    var gl = this.glplot.gl;\n    var w = gl.drawingBufferWidth;\n    var h = gl.drawingBufferHeight;\n\n    // force redraw\n    gl.clearColor(1, 1, 1, 0);\n    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);\n    this.glplot.setDirty();\n    this.glplot.draw();\n\n    gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n\n    var pixels = new Uint8Array(w * h * 4);\n    gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels);\n\n    // flip pixels\n    for(var j = 0, k = h - 1; j < k; ++j, --k) {\n        for(var i = 0; i < w; ++i) {\n            for(var l = 0; l < 4; ++l) {\n                var tmp = pixels[4 * (w * j + i) + l];\n                pixels[4 * (w * j + i) + l] = pixels[4 * (w * k + i) + l];\n                pixels[4 * (w * k + i) + l] = tmp;\n            }\n        }\n    }\n\n    var canvas = document.createElement('canvas');\n    canvas.width = w;\n    canvas.height = h;\n\n    var context = canvas.getContext('2d');\n    var imageData = context.createImageData(w, h);\n    imageData.data.set(pixels);\n    context.putImageData(imageData, 0, 0);\n\n    var dataURL;\n\n    switch(format) {\n        case 'jpeg':\n            dataURL = canvas.toDataURL('image/jpeg');\n            break;\n        case 'webp':\n            dataURL = canvas.toDataURL('image/webp');\n            break;\n        default:\n            dataURL = canvas.toDataURL('image/png');\n    }\n\n    if(this.staticPlot) this.container.removeChild(STATIC_CANVAS);\n\n    return dataURL;\n};\n\nproto.updateSize = function(canvas) {\n    if(!canvas) canvas = this.canvas;\n\n    var pixelRatio = this.pixelRatio;\n    var fullLayout = this.fullLayout;\n\n    var width = fullLayout.width;\n    var height = fullLayout.height;\n    var pixelWidth = Math.ceil(pixelRatio * width) |0;\n    var pixelHeight = Math.ceil(pixelRatio * height) |0;\n\n    // check for resize\n    if(canvas.width !== pixelWidth || canvas.height !== pixelHeight) {\n        canvas.width = pixelWidth;\n        canvas.height = pixelHeight;\n    }\n\n    return canvas;\n};\n\nproto.computeTickMarks = function() {\n    this.xaxis.setScale();\n    this.yaxis.setScale();\n\n    var nextTicks = [\n        Axes.calcTicks(this.xaxis),\n        Axes.calcTicks(this.yaxis)\n    ];\n\n    for(var j = 0; j < 2; ++j) {\n        for(var i = 0; i < nextTicks[j].length; ++i) {\n            // coercing tick value (may not be a string) to a string\n            nextTicks[j][i].text = nextTicks[j][i].text + '';\n        }\n    }\n\n    return nextTicks;\n};\n\nfunction compareTicks(a, b) {\n    for(var i = 0; i < 2; ++i) {\n        var aticks = a[i];\n        var bticks = b[i];\n\n        if(aticks.length !== bticks.length) return true;\n\n        for(var j = 0; j < aticks.length; ++j) {\n            if(aticks[j].x !== bticks[j].x) return true;\n        }\n    }\n\n    return false;\n}\n\nproto.updateRefs = function(newFullLayout) {\n    this.fullLayout = newFullLayout;\n\n    var spmatch = this.id.match(SUBPLOT_PATTERN);\n    var xaxisName = 'xaxis' + spmatch[1];\n    var yaxisName = 'yaxis' + spmatch[2];\n\n    this.xaxis = this.fullLayout[xaxisName];\n    this.yaxis = this.fullLayout[yaxisName];\n};\n\nproto.relayoutCallback = function() {\n    var graphDiv = this.graphDiv;\n    var xaxis = this.xaxis;\n    var yaxis = this.yaxis;\n    var layout = graphDiv.layout;\n\n    // make a meaningful value to be passed on to possible 'plotly_relayout' subscriber(s)\n    var update = {};\n    var xrange = update[xaxis._name + '.range'] = xaxis.range.slice();\n    var yrange = update[yaxis._name + '.range'] = yaxis.range.slice();\n    update[xaxis._name + '.autorange'] = xaxis.autorange;\n    update[yaxis._name + '.autorange'] = yaxis.autorange;\n\n    Registry.call('_storeDirectGUIEdit', graphDiv.layout, graphDiv._fullLayout._preGUI, update);\n\n    // update the input layout\n    var xaIn = layout[xaxis._name];\n    xaIn.range = xrange;\n    xaIn.autorange = xaxis.autorange;\n\n    var yaIn = layout[yaxis._name];\n    yaIn.range = yrange;\n    yaIn.autorange = yaxis.autorange;\n\n    // lastInputTime helps determine which one is the latest input (if async)\n    update.lastInputTime = this.camera.lastInputTime;\n    graphDiv.emit('plotly_relayout', update);\n};\n\nproto.cameraChanged = function() {\n    var camera = this.camera;\n\n    this.glplot.setDataBox(this.calcDataBox());\n\n    var nextTicks = this.computeTickMarks();\n    var curTicks = this.glplotOptions.ticks;\n\n    if(compareTicks(nextTicks, curTicks)) {\n        this.glplotOptions.ticks = nextTicks;\n        this.glplotOptions.dataBox = camera.dataBox;\n        this.glplot.update(this.glplotOptions);\n        this.handleAnnotations();\n    }\n};\n\nproto.handleAnnotations = function() {\n    var gd = this.graphDiv;\n    var annotations = this.fullLayout.annotations;\n\n    for(var i = 0; i < annotations.length; i++) {\n        var ann = annotations[i];\n\n        if(ann.xref === this.xaxis._id && ann.yref === this.yaxis._id) {\n            Registry.getComponentMethod('annotations', 'drawOne')(gd, i);\n        }\n    }\n};\n\nproto.destroy = function() {\n    if(!this.glplot) return;\n\n    var traces = this.traces;\n\n    if(traces) {\n        Object.keys(traces).map(function(key) {\n            traces[key].dispose();\n            delete traces[key];\n        });\n    }\n\n    this.glplot.dispose();\n\n    this.container.removeChild(this.svgContainer);\n    this.container.removeChild(this.mouseContainer);\n\n    this.fullData = null;\n    this.glplot = null;\n    this.stopped = true;\n    this.camera.mouseListener.enabled = false;\n    this.mouseContainer.removeEventListener('wheel', this.camera.wheelListener);\n    this.camera = null;\n};\n\nproto.plot = function(fullData, calcData, fullLayout) {\n    var glplot = this.glplot;\n\n    this.updateRefs(fullLayout);\n    this.xaxis.clearCalc();\n    this.yaxis.clearCalc();\n    this.updateTraces(fullData, calcData);\n    this.updateFx(fullLayout.dragmode);\n\n    var width = fullLayout.width;\n    var height = fullLayout.height;\n\n    this.updateSize(this.canvas);\n\n    var options = this.glplotOptions;\n    options.merge(fullLayout);\n    options.screenBox = [0, 0, width, height];\n\n    var mockGraphDiv = {_fullLayout: {\n        _axisConstraintGroups: this.graphDiv._fullLayout._axisConstraintGroups,\n        xaxis: this.xaxis,\n        yaxis: this.yaxis\n    }};\n\n    cleanAxisConstraints(mockGraphDiv, this.xaxis);\n    cleanAxisConstraints(mockGraphDiv, this.yaxis);\n\n    var size = fullLayout._size;\n    var domainX = this.xaxis.domain;\n    var domainY = this.yaxis.domain;\n\n    options.viewBox = [\n        size.l + domainX[0] * size.w,\n        size.b + domainY[0] * size.h,\n        (width - size.r) - (1 - domainX[1]) * size.w,\n        (height - size.t) - (1 - domainY[1]) * size.h\n    ];\n\n    this.mouseContainer.style.width = size.w * (domainX[1] - domainX[0]) + 'px';\n    this.mouseContainer.style.height = size.h * (domainY[1] - domainY[0]) + 'px';\n    this.mouseContainer.height = size.h * (domainY[1] - domainY[0]);\n    this.mouseContainer.style.left = size.l + domainX[0] * size.w + 'px';\n    this.mouseContainer.style.top = size.t + (1 - domainY[1]) * size.h + 'px';\n\n    var ax, i;\n\n    for(i = 0; i < 2; ++i) {\n        ax = this[AXES[i]];\n        ax._length = options.viewBox[i + 2] - options.viewBox[i];\n\n        doAutoRange(this.graphDiv, ax);\n        ax.setScale();\n    }\n\n    enforceAxisConstraints(mockGraphDiv);\n\n    options.ticks = this.computeTickMarks();\n\n    options.dataBox = this.calcDataBox();\n\n    options.merge(fullLayout);\n    glplot.update(options);\n\n    // force redraw so that promise is returned when rendering is completed\n    this.glplot.draw();\n};\n\nproto.calcDataBox = function() {\n    var xaxis = this.xaxis;\n    var yaxis = this.yaxis;\n    var xrange = xaxis.range;\n    var yrange = yaxis.range;\n    var xr2l = xaxis.r2l;\n    var yr2l = yaxis.r2l;\n\n    return [xr2l(xrange[0]), yr2l(yrange[0]), xr2l(xrange[1]), yr2l(yrange[1])];\n};\n\nproto.setRanges = function(dataBox) {\n    var xaxis = this.xaxis;\n    var yaxis = this.yaxis;\n    var xl2r = xaxis.l2r;\n    var yl2r = yaxis.l2r;\n\n    xaxis.range = [xl2r(dataBox[0]), xl2r(dataBox[2])];\n    yaxis.range = [yl2r(dataBox[1]), yl2r(dataBox[3])];\n};\n\nproto.updateTraces = function(fullData, calcData) {\n    var traceIds = Object.keys(this.traces);\n    var i, j, fullTrace;\n\n    this.fullData = fullData;\n\n    // remove empty traces\n    traceIdLoop:\n    for(i = 0; i < traceIds.length; i++) {\n        var oldUid = traceIds[i];\n        var oldTrace = this.traces[oldUid];\n\n        for(j = 0; j < fullData.length; j++) {\n            fullTrace = fullData[j];\n\n            if(fullTrace.uid === oldUid && fullTrace.type === oldTrace.type) {\n                continue traceIdLoop;\n            }\n        }\n\n        oldTrace.dispose();\n        delete this.traces[oldUid];\n    }\n\n    // update / create trace objects\n    for(i = 0; i < fullData.length; i++) {\n        fullTrace = fullData[i];\n        var calcTrace = calcData[i];\n        var traceObj = this.traces[fullTrace.uid];\n\n        if(traceObj) traceObj.update(fullTrace, calcTrace);\n        else {\n            traceObj = fullTrace._module.plot(this, fullTrace, calcTrace);\n            this.traces[fullTrace.uid] = traceObj;\n        }\n    }\n\n    // order object per traces\n    this.glplot.objects.sort(function(a, b) {\n        return a._trace.index - b._trace.index;\n    });\n};\n\nproto.updateFx = function(dragmode) {\n    // switch to svg interactions in lasso/select mode\n    if(dragmode === 'lasso' || dragmode === 'select') {\n        this.pickCanvas.style['pointer-events'] = 'none';\n        this.mouseContainer.style['pointer-events'] = 'none';\n    } else {\n        this.pickCanvas.style['pointer-events'] = 'auto';\n        this.mouseContainer.style['pointer-events'] = 'auto';\n    }\n\n    // set proper cursor\n    if(dragmode === 'pan') {\n        this.mouseContainer.style.cursor = 'move';\n    } else if(dragmode === 'zoom') {\n        this.mouseContainer.style.cursor = 'crosshair';\n    } else {\n        this.mouseContainer.style.cursor = null;\n    }\n};\n\nproto.emitPointAction = function(nextSelection, eventType) {\n    var uid = nextSelection.trace.uid;\n    var ptNumber = nextSelection.pointIndex;\n    var trace;\n\n    for(var i = 0; i < this.fullData.length; i++) {\n        if(this.fullData[i].uid === uid) {\n            trace = this.fullData[i];\n        }\n    }\n\n    var pointData = {\n        x: nextSelection.traceCoord[0],\n        y: nextSelection.traceCoord[1],\n        curveNumber: trace.index,\n        pointNumber: ptNumber,\n        data: trace._input,\n        fullData: this.fullData,\n        xaxis: this.xaxis,\n        yaxis: this.yaxis\n    };\n\n    Fx.appendArrayPointValue(pointData, trace, ptNumber);\n\n    this.graphDiv.emit(eventType, {points: [pointData]});\n};\n\nproto.draw = function() {\n    if(this.stopped) return;\n\n    requestAnimationFrame(this.redraw);\n\n    var glplot = this.glplot;\n    var camera = this.camera;\n    var mouseListener = camera.mouseListener;\n    var mouseUp = this.lastButtonState === 1 && mouseListener.buttons === 0;\n    var fullLayout = this.fullLayout;\n\n    this.lastButtonState = mouseListener.buttons;\n\n    this.cameraChanged();\n\n    var x = mouseListener.x * glplot.pixelRatio;\n    var y = this.canvas.height - glplot.pixelRatio * mouseListener.y;\n\n    var result;\n\n    if(camera.boxEnabled && fullLayout.dragmode === 'zoom') {\n        this.selectBox.enabled = true;\n\n        var selectBox = this.selectBox.selectBox = [\n            Math.min(camera.boxStart[0], camera.boxEnd[0]),\n            Math.min(camera.boxStart[1], camera.boxEnd[1]),\n            Math.max(camera.boxStart[0], camera.boxEnd[0]),\n            Math.max(camera.boxStart[1], camera.boxEnd[1])\n        ];\n\n        // 1D zoom\n        for(var i = 0; i < 2; i++) {\n            if(camera.boxStart[i] === camera.boxEnd[i]) {\n                selectBox[i] = glplot.dataBox[i];\n                selectBox[i + 2] = glplot.dataBox[i + 2];\n            }\n        }\n\n        glplot.setDirty();\n    } else if(!camera.panning && this.isMouseOver) {\n        this.selectBox.enabled = false;\n\n        var size = fullLayout._size;\n        var domainX = this.xaxis.domain;\n        var domainY = this.yaxis.domain;\n\n        result = glplot.pick(\n            (x / glplot.pixelRatio) + size.l + domainX[0] * size.w,\n            (y / glplot.pixelRatio) - (size.t + (1 - domainY[1]) * size.h)\n        );\n\n        var nextSelection = result && result.object._trace.handlePick(result);\n\n        if(nextSelection && mouseUp) {\n            this.emitPointAction(nextSelection, 'plotly_click');\n        }\n\n        if(result && result.object._trace.hoverinfo !== 'skip' && fullLayout.hovermode) {\n            if(nextSelection && (\n                !this.lastPickResult ||\n                this.lastPickResult.traceUid !== nextSelection.trace.uid ||\n                this.lastPickResult.dataCoord[0] !== nextSelection.dataCoord[0] ||\n                this.lastPickResult.dataCoord[1] !== nextSelection.dataCoord[1])\n            ) {\n                var selection = nextSelection;\n\n                this.lastPickResult = {\n                    traceUid: nextSelection.trace ? nextSelection.trace.uid : null,\n                    dataCoord: nextSelection.dataCoord.slice()\n                };\n                this.spikes.update({ center: result.dataCoord });\n\n                selection.screenCoord = [\n                    ((glplot.viewBox[2] - glplot.viewBox[0]) *\n                    (result.dataCoord[0] - glplot.dataBox[0]) /\n                        (glplot.dataBox[2] - glplot.dataBox[0]) + glplot.viewBox[0]) /\n                            glplot.pixelRatio,\n                    (this.canvas.height - (glplot.viewBox[3] - glplot.viewBox[1]) *\n                    (result.dataCoord[1] - glplot.dataBox[1]) /\n                        (glplot.dataBox[3] - glplot.dataBox[1]) - glplot.viewBox[1]) /\n                            glplot.pixelRatio\n                ];\n\n                // this needs to happen before the next block that deletes traceCoord data\n                // also it's important to copy, otherwise data is lost by the time event data is read\n                this.emitPointAction(nextSelection, 'plotly_hover');\n\n                var trace = this.fullData[selection.trace.index] || {};\n                var ptNumber = selection.pointIndex;\n                var hoverinfo = Fx.castHoverinfo(trace, fullLayout, ptNumber);\n\n                if(hoverinfo && hoverinfo !== 'all') {\n                    var parts = hoverinfo.split('+');\n                    if(parts.indexOf('x') === -1) selection.traceCoord[0] = undefined;\n                    if(parts.indexOf('y') === -1) selection.traceCoord[1] = undefined;\n                    if(parts.indexOf('z') === -1) selection.traceCoord[2] = undefined;\n                    if(parts.indexOf('text') === -1) selection.textLabel = undefined;\n                    if(parts.indexOf('name') === -1) selection.name = undefined;\n                }\n\n                Fx.loneHover({\n                    x: selection.screenCoord[0],\n                    y: selection.screenCoord[1],\n                    xLabel: this.hoverFormatter('xaxis', selection.traceCoord[0]),\n                    yLabel: this.hoverFormatter('yaxis', selection.traceCoord[1]),\n                    zLabel: selection.traceCoord[2],\n                    text: selection.textLabel,\n                    name: selection.name,\n                    color: Fx.castHoverOption(trace, ptNumber, 'bgcolor') || selection.color,\n                    borderColor: Fx.castHoverOption(trace, ptNumber, 'bordercolor'),\n                    fontFamily: Fx.castHoverOption(trace, ptNumber, 'font.family'),\n                    fontSize: Fx.castHoverOption(trace, ptNumber, 'font.size'),\n                    fontColor: Fx.castHoverOption(trace, ptNumber, 'font.color'),\n                    nameLength: Fx.castHoverOption(trace, ptNumber, 'namelength'),\n                    textAlign: Fx.castHoverOption(trace, ptNumber, 'align')\n                }, {\n                    container: this.svgContainer,\n                    gd: this.graphDiv\n                });\n            }\n        }\n    }\n\n    // Remove hover effects if we're not over a point OR\n    // if we're zooming or panning (in which case result is not set)\n    if(!result) {\n        this.unhover();\n    }\n\n    glplot.draw();\n};\n\nproto.unhover = function() {\n    if(this.lastPickResult) {\n        this.spikes.update({});\n        this.lastPickResult = null;\n        this.graphDiv.emit('plotly_unhover');\n        Fx.loneUnhover(this.svgContainer);\n    }\n};\n\nproto.hoverFormatter = function(axisName, val) {\n    if(val === undefined) return undefined;\n\n    var axis = this[axisName];\n    return Axes.tickText(axis, axis.c2l(val), 'hover').text;\n};\n\n},{\"../../components/fx\":632,\"../../lib/show_no_webgl_msg\":740,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"../cartesian/autorange\":766,\"../cartesian/constants\":773,\"../cartesian/constraints\":774,\"./camera\":803,\"./convert\":804,\"gl-plot2d\":287,\"gl-select-box\":299,\"gl-spikes2d\":308,\"webgl-context\":556}],807:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar fxAttrs = _dereq_('../../components/fx/layout_attributes');\n\nvar Scene = _dereq_('./scene');\nvar getSubplotData = _dereq_('../get_data').getSubplotData;\nvar Lib = _dereq_('../../lib');\nvar xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');\n\nvar GL3D = 'gl3d';\nvar SCENE = 'scene';\n\n\nexports.name = GL3D;\n\nexports.attr = SCENE;\n\nexports.idRoot = SCENE;\n\nexports.idRegex = exports.attrRegex = Lib.counterRegex('scene');\n\nexports.attributes = _dereq_('./layout/attributes');\n\nexports.layoutAttributes = _dereq_('./layout/layout_attributes');\n\nexports.baseLayoutAttrOverrides = overrideAll({\n    hoverlabel: fxAttrs.hoverlabel\n}, 'plot', 'nested');\n\nexports.supplyLayoutDefaults = _dereq_('./layout/defaults');\n\nexports.plot = function plot(gd) {\n    var fullLayout = gd._fullLayout;\n    var fullData = gd._fullData;\n    var sceneIds = fullLayout._subplots[GL3D];\n\n    for(var i = 0; i < sceneIds.length; i++) {\n        var sceneId = sceneIds[i];\n        var fullSceneData = getSubplotData(fullData, GL3D, sceneId);\n        var sceneLayout = fullLayout[sceneId];\n        var camera = sceneLayout.camera;\n        var scene = sceneLayout._scene;\n\n        if(!scene) {\n            scene = new Scene({\n                id: sceneId,\n                graphDiv: gd,\n                container: gd.querySelector('.gl-container'),\n                staticPlot: gd._context.staticPlot,\n                plotGlPixelRatio: gd._context.plotGlPixelRatio,\n                camera: camera\n            },\n                fullLayout\n            );\n\n            // set ref to Scene instance\n            sceneLayout._scene = scene;\n        }\n\n        // save 'initial' camera view settings for modebar button\n        if(!scene.viewInitial) {\n            scene.viewInitial = {\n                up: {\n                    x: camera.up.x,\n                    y: camera.up.y,\n                    z: camera.up.z\n                },\n                eye: {\n                    x: camera.eye.x,\n                    y: camera.eye.y,\n                    z: camera.eye.z\n                },\n                center: {\n                    x: camera.center.x,\n                    y: camera.center.y,\n                    z: camera.center.z\n                }\n            };\n        }\n\n        scene.plot(fullSceneData, fullLayout, gd.layout);\n    }\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var oldSceneKeys = oldFullLayout._subplots[GL3D] || [];\n\n    for(var i = 0; i < oldSceneKeys.length; i++) {\n        var oldSceneKey = oldSceneKeys[i];\n\n        if(!newFullLayout[oldSceneKey] && !!oldFullLayout[oldSceneKey]._scene) {\n            oldFullLayout[oldSceneKey]._scene.destroy();\n\n            if(oldFullLayout._infolayer) {\n                oldFullLayout._infolayer\n                    .selectAll('.annotation-' + oldSceneKey)\n                    .remove();\n            }\n        }\n    }\n};\n\nexports.toSVG = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var sceneIds = fullLayout._subplots[GL3D];\n    var size = fullLayout._size;\n\n    for(var i = 0; i < sceneIds.length; i++) {\n        var sceneLayout = fullLayout[sceneIds[i]];\n        var domain = sceneLayout.domain;\n        var scene = sceneLayout._scene;\n\n        var imageData = scene.toImage('png');\n        var image = fullLayout._glimages.append('svg:image');\n\n        image.attr({\n            xmlns: xmlnsNamespaces.svg,\n            'xlink:href': imageData,\n            x: size.l + size.w * domain.x[0],\n            y: size.t + size.h * (1 - domain.y[1]),\n            width: size.w * (domain.x[1] - domain.x[0]),\n            height: size.h * (domain.y[1] - domain.y[0]),\n            preserveAspectRatio: 'none'\n        });\n\n        scene.destroy();\n    }\n};\n\n// clean scene ids, 'scene1' -> 'scene'\nexports.cleanId = function cleanId(id) {\n    if(!id.match(/^scene[0-9]*$/)) return;\n\n    var sceneNum = id.substr(5);\n    if(sceneNum === '1') sceneNum = '';\n\n    return SCENE + sceneNum;\n};\n\nexports.updateFx = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var subplotIds = fullLayout._subplots[GL3D];\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var subplotObj = fullLayout[subplotIds[i]]._scene;\n        subplotObj.updateFx(fullLayout.dragmode, fullLayout.hovermode);\n    }\n};\n\n},{\"../../components/fx/layout_attributes\":633,\"../../constants/xmlns_namespaces\":696,\"../../lib\":719,\"../../plot_api/edit_types\":750,\"../get_data\":802,\"./layout/attributes\":808,\"./layout/defaults\":812,\"./layout/layout_attributes\":813,\"./scene\":817}],808:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n    scene: {\n        valType: 'subplotid',\n        \n        dflt: 'scene',\n        editType: 'calc+clearAxisTypes',\n        \n    }\n};\n\n},{}],809:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Color = _dereq_('../../../components/color');\nvar axesAttrs = _dereq_('../../cartesian/layout_attributes');\nvar extendFlat = _dereq_('../../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../../plot_api/edit_types').overrideAll;\n\nmodule.exports = overrideAll({\n    visible: axesAttrs.visible,\n    showspikes: {\n        valType: 'boolean',\n        \n        dflt: true,\n        \n    },\n    spikesides: {\n        valType: 'boolean',\n        \n        dflt: true,\n        \n    },\n    spikethickness: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 2,\n        \n    },\n    spikecolor: {\n        valType: 'color',\n        \n        dflt: Color.defaultLine,\n        \n    },\n    showbackground: {\n        valType: 'boolean',\n        \n        dflt: false,\n        \n    },\n    backgroundcolor: {\n        valType: 'color',\n        \n        dflt: 'rgba(204, 204, 204, 0.5)',\n        \n    },\n    showaxeslabels: {\n        valType: 'boolean',\n        \n        dflt: true,\n        \n    },\n    color: axesAttrs.color,\n    categoryorder: axesAttrs.categoryorder,\n    categoryarray: axesAttrs.categoryarray,\n    title: axesAttrs.title,\n    type: extendFlat({}, axesAttrs.type, {\n        values: ['-', 'linear', 'log', 'date', 'category']\n    }),\n    autorange: axesAttrs.autorange,\n    rangemode: axesAttrs.rangemode,\n    range: extendFlat({}, axesAttrs.range, {\n        items: [\n            {valType: 'any', editType: 'plot', impliedEdits: {'^autorange': false}},\n            {valType: 'any', editType: 'plot', impliedEdits: {'^autorange': false}}\n        ],\n        anim: false\n    }),\n    // ticks\n    tickmode: axesAttrs.tickmode,\n    nticks: axesAttrs.nticks,\n    tick0: axesAttrs.tick0,\n    dtick: axesAttrs.dtick,\n    tickvals: axesAttrs.tickvals,\n    ticktext: axesAttrs.ticktext,\n    ticks: axesAttrs.ticks,\n    mirror: axesAttrs.mirror,\n    ticklen: axesAttrs.ticklen,\n    tickwidth: axesAttrs.tickwidth,\n    tickcolor: axesAttrs.tickcolor,\n    showticklabels: axesAttrs.showticklabels,\n    tickfont: axesAttrs.tickfont,\n    tickangle: axesAttrs.tickangle,\n    tickprefix: axesAttrs.tickprefix,\n    showtickprefix: axesAttrs.showtickprefix,\n    ticksuffix: axesAttrs.ticksuffix,\n    showticksuffix: axesAttrs.showticksuffix,\n    showexponent: axesAttrs.showexponent,\n    exponentformat: axesAttrs.exponentformat,\n    separatethousands: axesAttrs.separatethousands,\n    tickformat: axesAttrs.tickformat,\n    tickformatstops: axesAttrs.tickformatstops,\n    hoverformat: axesAttrs.hoverformat,\n    // lines and grids\n    showline: axesAttrs.showline,\n    linecolor: axesAttrs.linecolor,\n    linewidth: axesAttrs.linewidth,\n    showgrid: axesAttrs.showgrid,\n    gridcolor: extendFlat({}, axesAttrs.gridcolor,  // shouldn't this be on-par with 2D?\n        {dflt: 'rgb(204, 204, 204)'}),\n    gridwidth: axesAttrs.gridwidth,\n    zeroline: axesAttrs.zeroline,\n    zerolinecolor: axesAttrs.zerolinecolor,\n    zerolinewidth: axesAttrs.zerolinewidth,\n    _deprecated: {\n        title: axesAttrs._deprecated.title,\n        titlefont: axesAttrs._deprecated.titlefont\n    }\n}, 'plot', 'from-root');\n\n},{\"../../../components/color\":593,\"../../../lib/extend\":710,\"../../../plot_api/edit_types\":750,\"../../cartesian/layout_attributes\":779}],810:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar colorMix = _dereq_('tinycolor2').mix;\n\nvar Lib = _dereq_('../../../lib');\nvar Template = _dereq_('../../../plot_api/plot_template');\n\nvar layoutAttributes = _dereq_('./axis_attributes');\nvar handleTypeDefaults = _dereq_('../../cartesian/type_defaults');\nvar handleAxisDefaults = _dereq_('../../cartesian/axis_defaults');\n\nvar axesNames = ['xaxis', 'yaxis', 'zaxis'];\n\n// TODO: hard-coded lightness fraction based on gridline default colors\n// that differ from other subplot types.\nvar gridLightness = 100 * (204 - 0x44) / (255 - 0x44);\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {\n    var containerIn, containerOut;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(containerIn, containerOut, layoutAttributes, attr, dflt);\n    }\n\n    for(var j = 0; j < axesNames.length; j++) {\n        var axName = axesNames[j];\n        containerIn = layoutIn[axName] || {};\n\n        containerOut = Template.newContainer(layoutOut, axName);\n        containerOut._id = axName[0] + options.scene;\n        containerOut._name = axName;\n\n        handleTypeDefaults(containerIn, containerOut, coerce, options);\n\n        handleAxisDefaults(\n            containerIn,\n            containerOut,\n            coerce,\n            {\n                font: options.font,\n                letter: axName[0],\n                data: options.data,\n                showGrid: true,\n                noTickson: true,\n                bgColor: options.bgColor,\n                calendar: options.calendar\n            },\n            options.fullLayout);\n\n        coerce('gridcolor', colorMix(containerOut.color, options.bgColor, gridLightness).toRgbString());\n        coerce('title.text', axName[0]);  // shouldn't this be on-par with 2D?\n\n        containerOut.setScale = Lib.noop;\n\n        if(coerce('showspikes')) {\n            coerce('spikesides');\n            coerce('spikethickness');\n            coerce('spikecolor', containerOut.color);\n        }\n\n        coerce('showaxeslabels');\n        if(coerce('showbackground')) coerce('backgroundcolor');\n    }\n};\n\n},{\"../../../lib\":719,\"../../../plot_api/plot_template\":757,\"../../cartesian/axis_defaults\":769,\"../../cartesian/type_defaults\":790,\"./axis_attributes\":809,\"tinycolor2\":537}],811:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar str2RgbaArray = _dereq_('../../../lib/str2rgbarray');\nvar Lib = _dereq_('../../../lib');\n\nvar AXES_NAMES = ['xaxis', 'yaxis', 'zaxis'];\n\nfunction AxesOptions() {\n    this.bounds = [\n        [-10, -10, -10],\n        [10, 10, 10]\n    ];\n\n    this.ticks = [ [], [], [] ];\n    this.tickEnable = [ true, true, true ];\n    this.tickFont = [ 'sans-serif', 'sans-serif', 'sans-serif' ];\n    this.tickSize = [ 12, 12, 12 ];\n    this.tickAngle = [ 0, 0, 0 ];\n    this.tickColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ];\n    this.tickPad = [ 18, 18, 18 ];\n\n    this.labels = [ 'x', 'y', 'z' ];\n    this.labelEnable = [ true, true, true ];\n    this.labelFont = ['Open Sans', 'Open Sans', 'Open Sans'];\n    this.labelSize = [ 20, 20, 20 ];\n    this.labelColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ];\n    this.labelPad = [ 30, 30, 30 ];\n\n    this.lineEnable = [ true, true, true ];\n    this.lineMirror = [ false, false, false ];\n    this.lineWidth = [ 1, 1, 1 ];\n    this.lineColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ];\n\n    this.lineTickEnable = [ true, true, true ];\n    this.lineTickMirror = [ false, false, false ];\n    this.lineTickLength = [ 10, 10, 10 ];\n    this.lineTickWidth = [ 1, 1, 1 ];\n    this.lineTickColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ];\n\n    this.gridEnable = [ true, true, true ];\n    this.gridWidth = [ 1, 1, 1 ];\n    this.gridColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ];\n\n    this.zeroEnable = [ true, true, true ];\n    this.zeroLineColor = [ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1] ];\n    this.zeroLineWidth = [ 2, 2, 2 ];\n\n    this.backgroundEnable = [ true, true, true ];\n    this.backgroundColor = [ [0.8, 0.8, 0.8, 0.5],\n                              [0.8, 0.8, 0.8, 0.5],\n                              [0.8, 0.8, 0.8, 0.5] ];\n\n    // some default values are stored for applying model transforms\n    this._defaultTickPad = this.tickPad.slice();\n    this._defaultLabelPad = this.labelPad.slice();\n    this._defaultLineTickLength = this.lineTickLength.slice();\n}\n\nvar proto = AxesOptions.prototype;\n\nproto.merge = function(fullLayout, sceneLayout) {\n    var opts = this;\n    for(var i = 0; i < 3; ++i) {\n        var axes = sceneLayout[AXES_NAMES[i]];\n\n        if(!axes.visible) {\n            opts.tickEnable[i] = false;\n            opts.labelEnable[i] = false;\n            opts.lineEnable[i] = false;\n            opts.lineTickEnable[i] = false;\n            opts.gridEnable[i] = false;\n            opts.zeroEnable[i] = false;\n            opts.backgroundEnable[i] = false;\n            continue;\n        }\n\n        // Axes labels\n        opts.labels[i] = fullLayout._meta ?\n            Lib.templateString(axes.title.text, fullLayout._meta) :\n            axes.title.text;\n\n        if('font' in axes.title) {\n            if(axes.title.font.color) opts.labelColor[i] = str2RgbaArray(axes.title.font.color);\n            if(axes.title.font.family) opts.labelFont[i] = axes.title.font.family;\n            if(axes.title.font.size) opts.labelSize[i] = axes.title.font.size;\n        }\n\n        // Lines\n        if('showline' in axes) opts.lineEnable[i] = axes.showline;\n        if('linecolor' in axes) opts.lineColor[i] = str2RgbaArray(axes.linecolor);\n        if('linewidth' in axes) opts.lineWidth[i] = axes.linewidth;\n\n        if('showgrid' in axes) opts.gridEnable[i] = axes.showgrid;\n        if('gridcolor' in axes) opts.gridColor[i] = str2RgbaArray(axes.gridcolor);\n        if('gridwidth' in axes) opts.gridWidth[i] = axes.gridwidth;\n\n        // Remove zeroline if axis type is log\n        // otherwise the zeroline is incorrectly drawn at 1 on log axes\n        if(axes.type === 'log') opts.zeroEnable[i] = false;\n        else if('zeroline' in axes) opts.zeroEnable[i] = axes.zeroline;\n        if('zerolinecolor' in axes) opts.zeroLineColor[i] = str2RgbaArray(axes.zerolinecolor);\n        if('zerolinewidth' in axes) opts.zeroLineWidth[i] = axes.zerolinewidth;\n\n        // tick lines\n        if('ticks' in axes && !!axes.ticks) opts.lineTickEnable[i] = true;\n        else opts.lineTickEnable[i] = false;\n\n        if('ticklen' in axes) {\n            opts.lineTickLength[i] = opts._defaultLineTickLength[i] = axes.ticklen;\n        }\n        if('tickcolor' in axes) opts.lineTickColor[i] = str2RgbaArray(axes.tickcolor);\n        if('tickwidth' in axes) opts.lineTickWidth[i] = axes.tickwidth;\n        if('tickangle' in axes) {\n            opts.tickAngle[i] = (axes.tickangle === 'auto') ?\n                -3600 : // i.e. special number to set auto option\n                Math.PI * -axes.tickangle / 180;\n        }\n\n        // tick labels\n        if('showticklabels' in axes) opts.tickEnable[i] = axes.showticklabels;\n        if('tickfont' in axes) {\n            if(axes.tickfont.color) opts.tickColor[i] = str2RgbaArray(axes.tickfont.color);\n            if(axes.tickfont.family) opts.tickFont[i] = axes.tickfont.family;\n            if(axes.tickfont.size) opts.tickSize[i] = axes.tickfont.size;\n        }\n\n        if('mirror' in axes) {\n            if(['ticks', 'all', 'allticks'].indexOf(axes.mirror) !== -1) {\n                opts.lineTickMirror[i] = true;\n                opts.lineMirror[i] = true;\n            } else if(axes.mirror === true) {\n                opts.lineTickMirror[i] = false;\n                opts.lineMirror[i] = true;\n            } else {\n                opts.lineTickMirror[i] = false;\n                opts.lineMirror[i] = false;\n            }\n        } else opts.lineMirror[i] = false;\n\n        // grid background\n        if('showbackground' in axes && axes.showbackground !== false) {\n            opts.backgroundEnable[i] = true;\n            opts.backgroundColor[i] = str2RgbaArray(axes.backgroundcolor);\n        } else opts.backgroundEnable[i] = false;\n    }\n};\n\n\nfunction createAxesOptions(fullLayout, sceneLayout) {\n    var result = new AxesOptions();\n    result.merge(fullLayout, sceneLayout);\n    return result;\n}\n\nmodule.exports = createAxesOptions;\n\n},{\"../../../lib\":719,\"../../../lib/str2rgbarray\":742}],812:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../../lib');\nvar Color = _dereq_('../../../components/color');\nvar Registry = _dereq_('../../../registry');\n\nvar handleSubplotDefaults = _dereq_('../../subplot_defaults');\nvar supplyGl3dAxisLayoutDefaults = _dereq_('./axis_defaults');\nvar layoutAttributes = _dereq_('./layout_attributes');\nvar getSubplotData = _dereq_('../../get_data').getSubplotData;\n\nvar GL3D = 'gl3d';\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    var hasNon3D = layoutOut._basePlotModules.length > 1;\n\n    // some layout-wide attribute are used in all scenes\n    // if 3D is the only visible plot type\n    function getDfltFromLayout(attr) {\n        if(hasNon3D) return;\n\n        var isValid = Lib.validate(layoutIn[attr], layoutAttributes[attr]);\n        if(isValid) return layoutIn[attr];\n    }\n\n    handleSubplotDefaults(layoutIn, layoutOut, fullData, {\n        type: GL3D,\n        attributes: layoutAttributes,\n        handleDefaults: handleGl3dDefaults,\n        fullLayout: layoutOut,\n        font: layoutOut.font,\n        fullData: fullData,\n        getDfltFromLayout: getDfltFromLayout,\n        paper_bgcolor: layoutOut.paper_bgcolor,\n        calendar: layoutOut.calendar\n    });\n};\n\nfunction handleGl3dDefaults(sceneLayoutIn, sceneLayoutOut, coerce, opts) {\n    /*\n     * Scene numbering proceeds as follows\n     * scene\n     * scene2\n     * scene3\n     *\n     * and d.scene will be undefined or some number or number string\n     *\n     * Also write back a blank scene object to user layout so that some\n     * attributes like aspectratio can be written back dynamically.\n     */\n\n    var bgcolor = coerce('bgcolor');\n    var bgColorCombined = Color.combine(bgcolor, opts.paper_bgcolor);\n\n    var cameraKeys = ['up', 'center', 'eye'];\n\n    for(var j = 0; j < cameraKeys.length; j++) {\n        coerce('camera.' + cameraKeys[j] + '.x');\n        coerce('camera.' + cameraKeys[j] + '.y');\n        coerce('camera.' + cameraKeys[j] + '.z');\n    }\n\n    coerce('camera.projection.type');\n\n    /*\n     * coerce to positive number (min 0) but also do not accept 0 (>0 not >=0)\n     * note that 0's go false with the !! call\n     */\n    var hasAspect = !!coerce('aspectratio.x') &&\n                    !!coerce('aspectratio.y') &&\n                    !!coerce('aspectratio.z');\n\n    var defaultAspectMode = hasAspect ? 'manual' : 'auto';\n    var aspectMode = coerce('aspectmode', defaultAspectMode);\n\n    /*\n     * We need aspectratio object in all the Layouts as it is dynamically set\n     * in the calculation steps, ie, we cant set the correct data now, it happens later.\n     * We must also account for the case the user sends bad ratio data with 'manual' set\n     * for the mode. In this case we must force change it here as the default coerce\n     * misses it above.\n     */\n    if(!hasAspect) {\n        sceneLayoutIn.aspectratio = sceneLayoutOut.aspectratio = {x: 1, y: 1, z: 1};\n\n        if(aspectMode === 'manual') sceneLayoutOut.aspectmode = 'auto';\n\n        /*\n         * kind of like autorange - we need the calculated aspectmode back in\n         * the input layout or relayout can cause problems later\n         */\n        sceneLayoutIn.aspectmode = sceneLayoutOut.aspectmode;\n    }\n\n    var fullGl3dData = getSubplotData(opts.fullData, GL3D, opts.id);\n\n    supplyGl3dAxisLayoutDefaults(sceneLayoutIn, sceneLayoutOut, {\n        font: opts.font,\n        scene: opts.id,\n        data: fullGl3dData,\n        bgColor: bgColorCombined,\n        calendar: opts.calendar,\n        fullLayout: opts.fullLayout\n    });\n\n    Registry.getComponentMethod('annotations3d', 'handleDefaults')(\n        sceneLayoutIn, sceneLayoutOut, opts\n    );\n\n    var dragmode = opts.getDfltFromLayout('dragmode');\n\n    if(dragmode !== false) {\n        if(!dragmode) {\n            dragmode = 'orbit';\n\n            if(sceneLayoutIn.camera &&\n                sceneLayoutIn.camera.up) {\n                var x = sceneLayoutIn.camera.up.x;\n                var y = sceneLayoutIn.camera.up.y;\n                var z = sceneLayoutIn.camera.up.z;\n\n                if(z !== 0) {\n                    if(!x || !y || !z) {\n                        dragmode = 'turntable';\n                    } else if(z / Math.sqrt(x * x + y * y + z * z) > 0.999) {\n                        dragmode = 'turntable';\n                    }\n                }\n            } else {\n                dragmode = 'turntable';\n            }\n        }\n    }\n\n    coerce('dragmode', dragmode);\n    coerce('hovermode', opts.getDfltFromLayout('hovermode'));\n}\n\n},{\"../../../components/color\":593,\"../../../lib\":719,\"../../../registry\":847,\"../../get_data\":802,\"../../subplot_defaults\":842,\"./axis_defaults\":810,\"./layout_attributes\":813}],813:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar gl3dAxisAttrs = _dereq_('./axis_attributes');\nvar domainAttrs = _dereq_('../../domain').attributes;\nvar extendFlat = _dereq_('../../../lib/extend').extendFlat;\nvar counterRegex = _dereq_('../../../lib').counterRegex;\n\nfunction makeCameraVector(x, y, z) {\n    return {\n        x: {\n            valType: 'number',\n            \n            dflt: x,\n            editType: 'camera'\n        },\n        y: {\n            valType: 'number',\n            \n            dflt: y,\n            editType: 'camera'\n        },\n        z: {\n            valType: 'number',\n            \n            dflt: z,\n            editType: 'camera'\n        },\n        editType: 'camera'\n    };\n}\n\nmodule.exports = {\n    _arrayAttrRegexps: [counterRegex('scene', '.annotations', true)],\n\n    bgcolor: {\n        valType: 'color',\n        \n        dflt: 'rgba(0,0,0,0)',\n        editType: 'plot'\n    },\n    camera: {\n        up: extendFlat(makeCameraVector(0, 0, 1), {\n            \n        }),\n        center: extendFlat(makeCameraVector(0, 0, 0), {\n            \n        }),\n        eye: extendFlat(makeCameraVector(1.25, 1.25, 1.25), {\n            \n        }),\n        projection: {\n            type: {\n                valType: 'enumerated',\n                \n                values: ['perspective', 'orthographic'],\n                dflt: 'perspective',\n                editType: 'calc',\n                \n            },\n            editType: 'calc'\n        },\n        editType: 'camera'\n    },\n    domain: domainAttrs({name: 'scene', editType: 'plot'}),\n    aspectmode: {\n        valType: 'enumerated',\n        \n        values: ['auto', 'cube', 'data', 'manual'],\n        dflt: 'auto',\n        editType: 'plot',\n        impliedEdits: {\n            'aspectratio.x': undefined,\n            'aspectratio.y': undefined,\n            'aspectratio.z': undefined\n        },\n        \n    },\n    aspectratio: { // must be positive (0's are coerced to 1)\n        x: {\n            valType: 'number',\n            \n            min: 0,\n            editType: 'plot',\n            impliedEdits: {'^aspectmode': 'manual'}\n        },\n        y: {\n            valType: 'number',\n            \n            min: 0,\n            editType: 'plot',\n            impliedEdits: {'^aspectmode': 'manual'}\n        },\n        z: {\n            valType: 'number',\n            \n            min: 0,\n            editType: 'plot',\n            impliedEdits: {'^aspectmode': 'manual'}\n        },\n        editType: 'plot',\n        impliedEdits: {aspectmode: 'manual'},\n        \n    },\n\n    xaxis: gl3dAxisAttrs,\n    yaxis: gl3dAxisAttrs,\n    zaxis: gl3dAxisAttrs,\n\n    dragmode: {\n        valType: 'enumerated',\n        \n        values: ['orbit', 'turntable', 'zoom', 'pan', false],\n        editType: 'plot',\n        \n    },\n    hovermode: {\n        valType: 'enumerated',\n        \n        values: ['closest', false],\n        dflt: 'closest',\n        editType: 'modebar',\n        \n    },\n    uirevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n    editType: 'plot',\n\n    _deprecated: {\n        cameraposition: {\n            valType: 'info_array',\n            \n            editType: 'camera',\n            \n        }\n    }\n};\n\n},{\"../../../lib\":719,\"../../../lib/extend\":710,\"../../domain\":792,\"./axis_attributes\":809}],814:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar str2RGBArray = _dereq_('../../../lib/str2rgbarray');\n\nvar AXES_NAMES = ['xaxis', 'yaxis', 'zaxis'];\n\nfunction SpikeOptions() {\n    this.enabled = [true, true, true];\n    this.colors = [[0, 0, 0, 1],\n                   [0, 0, 0, 1],\n                   [0, 0, 0, 1]];\n    this.drawSides = [true, true, true];\n    this.lineWidth = [1, 1, 1];\n}\n\nvar proto = SpikeOptions.prototype;\n\nproto.merge = function(sceneLayout) {\n    for(var i = 0; i < 3; ++i) {\n        var axes = sceneLayout[AXES_NAMES[i]];\n\n        if(!axes.visible) {\n            this.enabled[i] = false;\n            this.drawSides[i] = false;\n            continue;\n        }\n\n        this.enabled[i] = axes.showspikes;\n        this.colors[i] = str2RGBArray(axes.spikecolor);\n        this.drawSides[i] = axes.spikesides;\n        this.lineWidth[i] = axes.spikethickness;\n    }\n};\n\nfunction createSpikeOptions(layout) {\n    var result = new SpikeOptions();\n    result.merge(layout);\n    return result;\n}\n\nmodule.exports = createSpikeOptions;\n\n},{\"../../../lib/str2rgbarray\":742}],815:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n/* eslint block-scoped-var: 0*/\n/* eslint no-redeclare: 0*/\n\n'use strict';\n\nmodule.exports = computeTickMarks;\n\nvar Axes = _dereq_('../../cartesian/axes');\nvar Lib = _dereq_('../../../lib');\n\nvar AXES_NAMES = ['xaxis', 'yaxis', 'zaxis'];\n\nvar centerPoint = [0, 0, 0];\n\nfunction contourLevelsFromTicks(ticks) {\n    var result = new Array(3);\n    for(var i = 0; i < 3; ++i) {\n        var tlevel = ticks[i];\n        var clevel = new Array(tlevel.length);\n        for(var j = 0; j < tlevel.length; ++j) {\n            clevel[j] = tlevel[j].x;\n        }\n        result[i] = clevel;\n    }\n    return result;\n}\n\nfunction computeTickMarks(scene) {\n    var axesOptions = scene.axesOptions;\n    var glRange = scene.glplot.axesPixels;\n    var sceneLayout = scene.fullSceneLayout;\n\n    var ticks = [[], [], []];\n\n    for(var i = 0; i < 3; ++i) {\n        var axes = sceneLayout[AXES_NAMES[i]];\n\n        axes._length = (glRange[i].hi - glRange[i].lo) *\n            glRange[i].pixelsPerDataUnit / scene.dataScale[i];\n\n        if(Math.abs(axes._length) === Infinity ||\n           isNaN(axes._length)) {\n            ticks[i] = [];\n        } else {\n            axes._input_range = axes.range.slice();\n            axes.range[0] = (glRange[i].lo) / scene.dataScale[i];\n            axes.range[1] = (glRange[i].hi) / scene.dataScale[i];\n            axes._m = 1.0 / (scene.dataScale[i] * glRange[i].pixelsPerDataUnit);\n\n            if(axes.range[0] === axes.range[1]) {\n                axes.range[0] -= 1;\n                axes.range[1] += 1;\n            }\n            // this is necessary to short-circuit the 'y' handling\n            // in autotick part of calcTicks... Treating all axes as 'y' in this case\n            // running the autoticks here, then setting\n            // autoticks to false to get around the 2D handling in calcTicks.\n            var tickModeCached = axes.tickmode;\n            if(axes.tickmode === 'auto') {\n                axes.tickmode = 'linear';\n                var nticks = axes.nticks || Lib.constrain((axes._length / 40), 4, 9);\n                Axes.autoTicks(axes, Math.abs(axes.range[1] - axes.range[0]) / nticks);\n            }\n            var dataTicks = Axes.calcTicks(axes);\n            for(var j = 0; j < dataTicks.length; ++j) {\n                dataTicks[j].x = dataTicks[j].x * scene.dataScale[i];\n\n                if(axes.type === 'date') {\n                    dataTicks[j].text =\n                    dataTicks[j].text.replace(/\\<br\\>/g, ' ');\n                }\n            }\n            ticks[i] = dataTicks;\n\n\n            axes.tickmode = tickModeCached;\n        }\n    }\n\n    axesOptions.ticks = ticks;\n\n    // Calculate tick lengths dynamically\n    for(var i = 0; i < 3; ++i) {\n        centerPoint[i] = 0.5 * (scene.glplot.bounds[0][i] + scene.glplot.bounds[1][i]);\n        for(var j = 0; j < 2; ++j) {\n            axesOptions.bounds[j][i] = scene.glplot.bounds[j][i];\n        }\n    }\n\n    scene.contourLevels = contourLevelsFromTicks(ticks);\n}\n\n},{\"../../../lib\":719,\"../../cartesian/axes\":767}],816:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nfunction xformMatrix(m, v) {\n    var out = [0, 0, 0, 0];\n    var i, j;\n\n    for(i = 0; i < 4; ++i) {\n        for(j = 0; j < 4; ++j) {\n            out[j] += m[4 * i + j] * v[i];\n        }\n    }\n\n    return out;\n}\n\nfunction project(camera, v) {\n    var p = xformMatrix(camera.projection,\n        xformMatrix(camera.view,\n        xformMatrix(camera.model, [v[0], v[1], v[2], 1])));\n    return p;\n}\n\nmodule.exports = project;\n\n},{}],817:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar createCamera = _dereq_('gl-plot3d').createCamera;\nvar createPlot = _dereq_('gl-plot3d').createScene;\nvar getContext = _dereq_('webgl-context');\nvar passiveSupported = _dereq_('has-passive-events');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Fx = _dereq_('../../components/fx');\n\nvar str2RGBAarray = _dereq_('../../lib/str2rgbarray');\nvar showNoWebGlMsg = _dereq_('../../lib/show_no_webgl_msg');\n\nvar project = _dereq_('./project');\nvar createAxesOptions = _dereq_('./layout/convert');\nvar createSpikeOptions = _dereq_('./layout/spikes');\nvar computeTickMarks = _dereq_('./layout/tick_marks');\n\n\nvar STATIC_CANVAS, STATIC_CONTEXT;\n\nfunction render(scene) {\n    var gd = scene.graphDiv;\n    var trace;\n\n    // update size of svg container\n    var svgContainer = scene.svgContainer;\n    var clientRect = scene.container.getBoundingClientRect();\n    var width = clientRect.width;\n    var height = clientRect.height;\n    svgContainer.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);\n    svgContainer.setAttributeNS(null, 'width', width);\n    svgContainer.setAttributeNS(null, 'height', height);\n\n    computeTickMarks(scene);\n    scene.glplot.axes.update(scene.axesOptions);\n\n    // check if pick has changed\n    var keys = Object.keys(scene.traces);\n    var lastPicked = null;\n    var selection = scene.glplot.selection;\n    for(var i = 0; i < keys.length; ++i) {\n        trace = scene.traces[keys[i]];\n        if(trace.data.hoverinfo !== 'skip' && trace.handlePick(selection)) {\n            lastPicked = trace;\n        }\n\n        if(trace.setContourLevels) trace.setContourLevels();\n    }\n\n    function formatter(axisName, val) {\n        var axis = scene.fullSceneLayout[axisName];\n\n        return Axes.tickText(axis, axis.d2l(val), 'hover').text;\n    }\n\n    var oldEventData;\n\n    if(lastPicked !== null) {\n        var pdata = project(scene.glplot.cameraParams, selection.dataCoordinate);\n        trace = lastPicked.data;\n        var traceNow = gd._fullData[trace.index];\n        var ptNumber = selection.index;\n\n        var labels = {\n            xLabel: formatter('xaxis', selection.traceCoordinate[0]),\n            yLabel: formatter('yaxis', selection.traceCoordinate[1]),\n            zLabel: formatter('zaxis', selection.traceCoordinate[2])\n        };\n\n        var hoverinfo = Fx.castHoverinfo(traceNow, scene.fullLayout, ptNumber);\n        var hoverinfoParts = (hoverinfo || '').split('+');\n        var isHoverinfoAll = hoverinfo && hoverinfo === 'all';\n\n        if(!traceNow.hovertemplate && !isHoverinfoAll) {\n            if(hoverinfoParts.indexOf('x') === -1) labels.xLabel = undefined;\n            if(hoverinfoParts.indexOf('y') === -1) labels.yLabel = undefined;\n            if(hoverinfoParts.indexOf('z') === -1) labels.zLabel = undefined;\n            if(hoverinfoParts.indexOf('text') === -1) selection.textLabel = undefined;\n            if(hoverinfoParts.indexOf('name') === -1) lastPicked.name = undefined;\n        }\n\n        var tx;\n        var vectorTx = [];\n\n        if(trace.type === 'cone' || trace.type === 'streamtube') {\n            labels.uLabel = formatter('xaxis', selection.traceCoordinate[3]);\n            if(isHoverinfoAll || hoverinfoParts.indexOf('u') !== -1) {\n                vectorTx.push('u: ' + labels.uLabel);\n            }\n\n            labels.vLabel = formatter('yaxis', selection.traceCoordinate[4]);\n            if(isHoverinfoAll || hoverinfoParts.indexOf('v') !== -1) {\n                vectorTx.push('v: ' + labels.vLabel);\n            }\n\n            labels.wLabel = formatter('zaxis', selection.traceCoordinate[5]);\n            if(isHoverinfoAll || hoverinfoParts.indexOf('w') !== -1) {\n                vectorTx.push('w: ' + labels.wLabel);\n            }\n\n            labels.normLabel = selection.traceCoordinate[6].toPrecision(3);\n            if(isHoverinfoAll || hoverinfoParts.indexOf('norm') !== -1) {\n                vectorTx.push('norm: ' + labels.normLabel);\n            }\n            if(trace.type === 'streamtube') {\n                labels.divergenceLabel = selection.traceCoordinate[7].toPrecision(3);\n                if(isHoverinfoAll || hoverinfoParts.indexOf('divergence') !== -1) {\n                    vectorTx.push('divergence: ' + labels.divergenceLabel);\n                }\n            }\n            if(selection.textLabel) {\n                vectorTx.push(selection.textLabel);\n            }\n            tx = vectorTx.join('<br>');\n        } else if(trace.type === 'isosurface' || trace.type === 'volume') {\n            labels.valueLabel = Axes.tickText(scene.mockAxis, scene.mockAxis.d2l(selection.traceCoordinate[3]), 'hover').text;\n            vectorTx.push('value: ' + labels.valueLabel);\n            if(selection.textLabel) {\n                vectorTx.push(selection.textLabel);\n            }\n            tx = vectorTx.join('<br>');\n        } else {\n            tx = selection.textLabel;\n        }\n\n        var pointData = {\n            x: selection.traceCoordinate[0],\n            y: selection.traceCoordinate[1],\n            z: selection.traceCoordinate[2],\n            data: traceNow._input,\n            fullData: traceNow,\n            curveNumber: traceNow.index,\n            pointNumber: ptNumber\n        };\n\n        Fx.appendArrayPointValue(pointData, traceNow, ptNumber);\n\n        if(trace._module.eventData) {\n            pointData = traceNow._module.eventData(pointData, selection, traceNow, {}, ptNumber);\n        }\n\n        var eventData = {points: [pointData]};\n\n        if(scene.fullSceneLayout.hovermode) {\n            Fx.loneHover({\n                trace: traceNow,\n                x: (0.5 + 0.5 * pdata[0] / pdata[3]) * width,\n                y: (0.5 - 0.5 * pdata[1] / pdata[3]) * height,\n                xLabel: labels.xLabel,\n                yLabel: labels.yLabel,\n                zLabel: labels.zLabel,\n                text: tx,\n                name: lastPicked.name,\n                color: Fx.castHoverOption(traceNow, ptNumber, 'bgcolor') || lastPicked.color,\n                borderColor: Fx.castHoverOption(traceNow, ptNumber, 'bordercolor'),\n                fontFamily: Fx.castHoverOption(traceNow, ptNumber, 'font.family'),\n                fontSize: Fx.castHoverOption(traceNow, ptNumber, 'font.size'),\n                fontColor: Fx.castHoverOption(traceNow, ptNumber, 'font.color'),\n                nameLength: Fx.castHoverOption(traceNow, ptNumber, 'namelength'),\n                textAlign: Fx.castHoverOption(traceNow, ptNumber, 'align'),\n                hovertemplate: Lib.castOption(traceNow, ptNumber, 'hovertemplate'),\n                hovertemplateLabels: Lib.extendFlat({}, pointData, labels),\n                eventData: [pointData]\n            }, {\n                container: svgContainer,\n                gd: gd\n            });\n        }\n\n        if(selection.buttons && selection.distance < 5) {\n            gd.emit('plotly_click', eventData);\n        } else {\n            gd.emit('plotly_hover', eventData);\n        }\n\n        oldEventData = eventData;\n    } else {\n        Fx.loneUnhover(svgContainer);\n        gd.emit('plotly_unhover', oldEventData);\n    }\n\n    scene.drawAnnotations(scene);\n}\n\nfunction tryCreatePlot(scene, cameraObject, pixelRatio, canvas, gl) {\n    var glplotOptions = {\n        canvas: canvas,\n        gl: gl,\n        container: scene.container,\n        axes: scene.axesOptions,\n        spikes: scene.spikeOptions,\n        pickRadius: 10,\n        snapToData: true,\n        autoScale: true,\n        autoBounds: false,\n        cameraObject: cameraObject,\n        pixelRatio: pixelRatio\n    };\n\n    // for static plots, we reuse the WebGL context\n    //  as WebKit doesn't collect them reliably\n    if(scene.staticMode) {\n        if(!STATIC_CONTEXT) {\n            STATIC_CANVAS = document.createElement('canvas');\n            STATIC_CONTEXT = getContext({\n                canvas: STATIC_CANVAS,\n                preserveDrawingBuffer: true,\n                premultipliedAlpha: true,\n                antialias: true\n            });\n            if(!STATIC_CONTEXT) {\n                throw new Error('error creating static canvas/context for image server');\n            }\n        }\n        glplotOptions.pixelRatio = scene.pixelRatio;\n        glplotOptions.gl = STATIC_CONTEXT;\n        glplotOptions.canvas = STATIC_CANVAS;\n    }\n\n    try {\n        scene.glplot = createPlot(glplotOptions);\n    } catch(e) {\n        return false;\n    }\n\n    return true;\n}\n\nfunction initializeGLPlot(scene, pixelRatio, canvas, gl) {\n    scene.initializeGLCamera();\n\n    var success = tryCreatePlot(scene, scene.camera, pixelRatio, canvas, gl);\n    /*\n    * createPlot will throw when webgl is not enabled in the client.\n    * Lets return an instance of the module with all functions noop'd.\n    * The destroy method - which will remove the container from the DOM\n    * is overridden with a function that removes the container only.\n    */\n    if(!success) return showNoWebGlMsg(scene);\n\n    var gd = scene.graphDiv;\n\n    var relayoutCallback = function(scene) {\n        if(scene.fullSceneLayout.dragmode === false) return;\n\n        var update = {};\n        update[scene.id + '.camera'] = getLayoutCamera(scene.camera);\n        scene.saveCamera(gd.layout);\n        scene.graphDiv.emit('plotly_relayout', update);\n    };\n\n    scene.glplot.canvas.addEventListener('mouseup', function() {\n        relayoutCallback(scene);\n    });\n\n    scene.glplot.canvas.addEventListener('wheel', function() {\n        if(gd._context._scrollZoom.gl3d) {\n            relayoutCallback(scene);\n        }\n    }, passiveSupported ? {passive: false} : false);\n\n    scene.glplot.canvas.addEventListener('mousemove', function() {\n        if(scene.fullSceneLayout.dragmode === false) return;\n        if(scene.camera.mouseListener.buttons === 0) return;\n\n        var update = {};\n        update[scene.id + '.camera'] = getLayoutCamera(scene.camera);\n        scene.graphDiv.emit('plotly_relayouting', update);\n    });\n\n    if(!scene.staticMode) {\n        scene.glplot.canvas.addEventListener('webglcontextlost', function(event) {\n            if(gd && gd.emit) {\n                gd.emit('plotly_webglcontextlost', {\n                    event: event,\n                    layer: scene.id\n                });\n            }\n        }, false);\n    }\n\n    scene.glplot.camera = scene.camera;\n\n    scene.glplot.oncontextloss = function() {\n        scene.recoverContext();\n    };\n\n    scene.glplot.onrender = render.bind(null, scene);\n\n    // List of scene objects\n    scene.traces = {};\n\n    scene.make4thDimension();\n\n    return true;\n}\n\nfunction Scene(options, fullLayout) {\n    // create sub container for plot\n    var sceneContainer = document.createElement('div');\n    var plotContainer = options.container;\n\n    // keep a ref to the graph div to fire hover+click events\n    this.graphDiv = options.graphDiv;\n\n    // create SVG container for hover text\n    var svgContainer = document.createElementNS(\n        'http://www.w3.org/2000/svg',\n        'svg');\n    svgContainer.style.position = 'absolute';\n    svgContainer.style.top = svgContainer.style.left = '0px';\n    svgContainer.style.width = svgContainer.style.height = '100%';\n    svgContainer.style['z-index'] = 20;\n    svgContainer.style['pointer-events'] = 'none';\n    sceneContainer.appendChild(svgContainer);\n    this.svgContainer = svgContainer;\n\n    // Tag the container with the sceneID\n    sceneContainer.id = options.id;\n    sceneContainer.style.position = 'absolute';\n    sceneContainer.style.top = sceneContainer.style.left = '0px';\n    sceneContainer.style.width = sceneContainer.style.height = '100%';\n    plotContainer.appendChild(sceneContainer);\n\n    this.fullLayout = fullLayout;\n    this.id = options.id || 'scene';\n    this.fullSceneLayout = fullLayout[this.id];\n\n    // Saved from last call to plot()\n    this.plotArgs = [ [], {}, {} ];\n\n    /*\n     * Move this to calc step? Why does it work here?\n     */\n    this.axesOptions = createAxesOptions(fullLayout, fullLayout[this.id]);\n    this.spikeOptions = createSpikeOptions(fullLayout[this.id]);\n    this.container = sceneContainer;\n    this.staticMode = !!options.staticPlot;\n    this.pixelRatio = this.pixelRatio || options.plotGlPixelRatio || 2;\n\n    // Coordinate rescaling\n    this.dataScale = [1, 1, 1];\n\n    this.contourLevels = [ [], [], [] ];\n\n    this.convertAnnotations = Registry.getComponentMethod('annotations3d', 'convert');\n    this.drawAnnotations = Registry.getComponentMethod('annotations3d', 'draw');\n\n    initializeGLPlot(this, this.pixelRatio);\n}\n\nvar proto = Scene.prototype;\n\nproto.initializeGLCamera = function() {\n    var cameraData = this.fullSceneLayout.camera;\n    var isOrtho = (cameraData.projection.type === 'orthographic');\n\n    this.camera = createCamera(this.container, {\n        center: [cameraData.center.x, cameraData.center.y, cameraData.center.z],\n        eye: [cameraData.eye.x, cameraData.eye.y, cameraData.eye.z],\n        up: [cameraData.up.x, cameraData.up.y, cameraData.up.z],\n        _ortho: isOrtho,\n        zoomMin: 0.01,\n        zoomMax: 100,\n        mode: 'orbit'\n    });\n};\n\nproto.recoverContext = function() {\n    var scene = this;\n    var gl = this.glplot.gl;\n    var canvas = this.glplot.canvas;\n    var camera = this.glplot.camera;\n    var pixelRatio = this.glplot.pixelRatio;\n    this.glplot.dispose();\n\n    function tryRecover() {\n        if(gl.isContextLost()) {\n            requestAnimationFrame(tryRecover);\n            return;\n        }\n        if(!initializeGLPlot(scene, camera, pixelRatio, canvas, gl)) {\n            Lib.error('Catastrophic and unrecoverable WebGL error. Context lost.');\n            return;\n        }\n        scene.plot.apply(scene, scene.plotArgs);\n    }\n    requestAnimationFrame(tryRecover);\n};\n\nvar axisProperties = [ 'xaxis', 'yaxis', 'zaxis' ];\n\nfunction computeTraceBounds(scene, trace, bounds) {\n    var sceneLayout = scene.fullSceneLayout;\n\n    for(var d = 0; d < 3; d++) {\n        var axisName = axisProperties[d];\n        var axLetter = axisName.charAt(0);\n        var ax = sceneLayout[axisName];\n        var coords = trace[axLetter];\n        var calendar = trace[axLetter + 'calendar'];\n        var len = trace['_' + axLetter + 'length'];\n\n        if(!Lib.isArrayOrTypedArray(coords)) {\n            bounds[0][d] = Math.min(bounds[0][d], 0);\n            bounds[1][d] = Math.max(bounds[1][d], len - 1);\n        } else {\n            var v;\n\n            for(var i = 0; i < (len || coords.length); i++) {\n                if(Lib.isArrayOrTypedArray(coords[i])) {\n                    for(var j = 0; j < coords[i].length; ++j) {\n                        v = ax.d2l(coords[i][j], 0, calendar);\n                        if(!isNaN(v) && isFinite(v)) {\n                            bounds[0][d] = Math.min(bounds[0][d], v);\n                            bounds[1][d] = Math.max(bounds[1][d], v);\n                        }\n                    }\n                } else {\n                    v = ax.d2l(coords[i], 0, calendar);\n                    if(!isNaN(v) && isFinite(v)) {\n                        bounds[0][d] = Math.min(bounds[0][d], v);\n                        bounds[1][d] = Math.max(bounds[1][d], v);\n                    }\n                }\n            }\n        }\n    }\n}\n\nfunction computeAnnotationBounds(scene, bounds) {\n    var sceneLayout = scene.fullSceneLayout;\n    var annotations = sceneLayout.annotations || [];\n\n    for(var d = 0; d < 3; d++) {\n        var axisName = axisProperties[d];\n        var axLetter = axisName.charAt(0);\n        var ax = sceneLayout[axisName];\n\n        for(var j = 0; j < annotations.length; j++) {\n            var ann = annotations[j];\n\n            if(ann.visible) {\n                var pos = ax.r2l(ann[axLetter]);\n                if(!isNaN(pos) && isFinite(pos)) {\n                    bounds[0][d] = Math.min(bounds[0][d], pos);\n                    bounds[1][d] = Math.max(bounds[1][d], pos);\n                }\n            }\n        }\n    }\n}\n\nproto.plot = function(sceneData, fullLayout, layout) {\n    // Save parameters\n    this.plotArgs = [sceneData, fullLayout, layout];\n\n    if(this.glplot.contextLost) return;\n\n    var data, trace;\n    var i, j, axis, axisType;\n    var fullSceneLayout = fullLayout[this.id];\n    var sceneLayout = layout[this.id];\n\n    if(fullSceneLayout.bgcolor) this.glplot.clearColor = str2RGBAarray(fullSceneLayout.bgcolor);\n    else this.glplot.clearColor = [0, 0, 0, 0];\n\n    this.glplot.snapToData = true;\n\n    // Update layout\n    this.fullLayout = fullLayout;\n    this.fullSceneLayout = fullSceneLayout;\n\n    this.glplotLayout = fullSceneLayout;\n    this.axesOptions.merge(fullLayout, fullSceneLayout);\n    this.spikeOptions.merge(fullSceneLayout);\n\n    // Update camera and camera mode\n    this.setCamera(fullSceneLayout.camera);\n    this.updateFx(fullSceneLayout.dragmode, fullSceneLayout.hovermode);\n    this.camera.enableWheel = this.graphDiv._context._scrollZoom.gl3d;\n\n    // Update scene\n    this.glplot.update({});\n\n    // Update axes functions BEFORE updating traces\n    this.setConvert(axis);\n\n    // Convert scene data\n    if(!sceneData) sceneData = [];\n    else if(!Array.isArray(sceneData)) sceneData = [sceneData];\n\n    // Compute trace bounding box\n    var dataBounds = [\n        [Infinity, Infinity, Infinity],\n        [-Infinity, -Infinity, -Infinity]\n    ];\n\n    for(i = 0; i < sceneData.length; ++i) {\n        data = sceneData[i];\n        if(data.visible !== true || data._length === 0) continue;\n\n        computeTraceBounds(this, data, dataBounds);\n    }\n    computeAnnotationBounds(this, dataBounds);\n\n    var dataScale = [1, 1, 1];\n    for(j = 0; j < 3; ++j) {\n        if(dataBounds[1][j] === dataBounds[0][j]) {\n            dataScale[j] = 1.0;\n        } else {\n            dataScale[j] = 1.0 / (dataBounds[1][j] - dataBounds[0][j]);\n        }\n    }\n\n    // Save scale\n    this.dataScale = dataScale;\n\n    // after computeTraceBounds where ax._categories are filled in\n    this.convertAnnotations(this);\n\n    // Update traces\n    for(i = 0; i < sceneData.length; ++i) {\n        data = sceneData[i];\n        if(data.visible !== true || data._length === 0) {\n            continue;\n        }\n        trace = this.traces[data.uid];\n        if(trace) {\n            if(trace.data.type === data.type) {\n                trace.update(data);\n            } else {\n                trace.dispose();\n                trace = data._module.plot(this, data);\n                this.traces[data.uid] = trace;\n            }\n        } else {\n            trace = data._module.plot(this, data);\n            this.traces[data.uid] = trace;\n        }\n        trace.name = data.name;\n    }\n\n    // Remove empty traces\n    var traceIds = Object.keys(this.traces);\n\n    traceIdLoop:\n    for(i = 0; i < traceIds.length; ++i) {\n        for(j = 0; j < sceneData.length; ++j) {\n            if(sceneData[j].uid === traceIds[i] &&\n                (sceneData[j].visible === true && sceneData[j]._length !== 0)) {\n                continue traceIdLoop;\n            }\n        }\n        trace = this.traces[traceIds[i]];\n        trace.dispose();\n        delete this.traces[traceIds[i]];\n    }\n\n    // order object per trace index\n    this.glplot.objects.sort(function(a, b) {\n        return a._trace.data.index - b._trace.data.index;\n    });\n\n    // Update ranges (needs to be called *after* objects are added due to updates)\n    var sceneBounds = [[0, 0, 0], [0, 0, 0]];\n    var axisDataRange = [];\n    var axisTypeRatios = {};\n\n    for(i = 0; i < 3; ++i) {\n        axis = fullSceneLayout[axisProperties[i]];\n        axisType = axis.type;\n\n        if(axisType in axisTypeRatios) {\n            axisTypeRatios[axisType].acc *= dataScale[i];\n            axisTypeRatios[axisType].count += 1;\n        } else {\n            axisTypeRatios[axisType] = {\n                acc: dataScale[i],\n                count: 1\n            };\n        }\n\n        if(axis.autorange) {\n            sceneBounds[0][i] = Infinity;\n            sceneBounds[1][i] = -Infinity;\n\n            var objects = this.glplot.objects;\n            var annotations = this.fullSceneLayout.annotations || [];\n            var axLetter = axis._name.charAt(0);\n\n            for(j = 0; j < objects.length; j++) {\n                var obj = objects[j];\n                var objBounds = obj.bounds;\n                var pad = obj._trace.data._pad || 0;\n\n                if(obj.constructor.name === 'ErrorBars' && axis._lowerLogErrorBound) {\n                    sceneBounds[0][i] = Math.min(sceneBounds[0][i], axis._lowerLogErrorBound);\n                } else {\n                    sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i] - pad);\n                }\n                sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i] / dataScale[i] + pad);\n            }\n\n            for(j = 0; j < annotations.length; j++) {\n                var ann = annotations[j];\n\n                // N.B. not taking into consideration the arrowhead\n                if(ann.visible) {\n                    var pos = axis.r2l(ann[axLetter]);\n                    sceneBounds[0][i] = Math.min(sceneBounds[0][i], pos);\n                    sceneBounds[1][i] = Math.max(sceneBounds[1][i], pos);\n                }\n            }\n\n            if('rangemode' in axis && axis.rangemode === 'tozero') {\n                sceneBounds[0][i] = Math.min(sceneBounds[0][i], 0);\n                sceneBounds[1][i] = Math.max(sceneBounds[1][i], 0);\n            }\n            if(sceneBounds[0][i] > sceneBounds[1][i]) {\n                sceneBounds[0][i] = -1;\n                sceneBounds[1][i] = 1;\n            } else {\n                var d = sceneBounds[1][i] - sceneBounds[0][i];\n                sceneBounds[0][i] -= d / 32.0;\n                sceneBounds[1][i] += d / 32.0;\n            }\n\n            if(axis.autorange === 'reversed') {\n                // swap bounds:\n                var tmp = sceneBounds[0][i];\n                sceneBounds[0][i] = sceneBounds[1][i];\n                sceneBounds[1][i] = tmp;\n            }\n        } else {\n            var range = axis.range;\n            sceneBounds[0][i] = axis.r2l(range[0]);\n            sceneBounds[1][i] = axis.r2l(range[1]);\n        }\n        if(sceneBounds[0][i] === sceneBounds[1][i]) {\n            sceneBounds[0][i] -= 1;\n            sceneBounds[1][i] += 1;\n        }\n        axisDataRange[i] = sceneBounds[1][i] - sceneBounds[0][i];\n\n        // Update plot bounds\n        this.glplot.bounds[0][i] = sceneBounds[0][i] * dataScale[i];\n        this.glplot.bounds[1][i] = sceneBounds[1][i] * dataScale[i];\n    }\n\n    var axesScaleRatio = [1, 1, 1];\n\n    // Compute axis scale per category\n    for(i = 0; i < 3; ++i) {\n        axis = fullSceneLayout[axisProperties[i]];\n        axisType = axis.type;\n        var axisRatio = axisTypeRatios[axisType];\n        axesScaleRatio[i] = Math.pow(axisRatio.acc, 1.0 / axisRatio.count) / dataScale[i];\n    }\n\n    /*\n     * Dynamically set the aspect ratio depending on the users aspect settings\n     */\n    var axisAutoScaleFactor = 4;\n    var aspectRatio;\n\n    if(fullSceneLayout.aspectmode === 'auto') {\n        if(Math.max.apply(null, axesScaleRatio) / Math.min.apply(null, axesScaleRatio) <= axisAutoScaleFactor) {\n            /*\n             * USE DATA MODE WHEN AXIS RANGE DIMENSIONS ARE RELATIVELY EQUAL\n             */\n\n            aspectRatio = axesScaleRatio;\n        } else {\n            /*\n             * USE EQUAL MODE WHEN AXIS RANGE DIMENSIONS ARE HIGHLY UNEQUAL\n             */\n            aspectRatio = [1, 1, 1];\n        }\n    } else if(fullSceneLayout.aspectmode === 'cube') {\n        aspectRatio = [1, 1, 1];\n    } else if(fullSceneLayout.aspectmode === 'data') {\n        aspectRatio = axesScaleRatio;\n    } else if(fullSceneLayout.aspectmode === 'manual') {\n        var userRatio = fullSceneLayout.aspectratio;\n        aspectRatio = [userRatio.x, userRatio.y, userRatio.z];\n    } else {\n        throw new Error('scene.js aspectRatio was not one of the enumerated types');\n    }\n\n    /*\n     * Write aspect Ratio back to user data and fullLayout so that it is modifies as user\n     * manipulates the aspectmode settings and the fullLayout is up-to-date.\n     */\n    fullSceneLayout.aspectratio.x = sceneLayout.aspectratio.x = aspectRatio[0];\n    fullSceneLayout.aspectratio.y = sceneLayout.aspectratio.y = aspectRatio[1];\n    fullSceneLayout.aspectratio.z = sceneLayout.aspectratio.z = aspectRatio[2];\n\n    /*\n     * Finally assign the computed aspecratio to the glplot module. This will have an effect\n     * on the next render cycle.\n     */\n    this.glplot.aspect = aspectRatio;\n\n\n    // Update frame position for multi plots\n    var domain = fullSceneLayout.domain || null;\n    var size = fullLayout._size || null;\n\n    if(domain && size) {\n        var containerStyle = this.container.style;\n        containerStyle.position = 'absolute';\n        containerStyle.left = (size.l + domain.x[0] * size.w) + 'px';\n        containerStyle.top = (size.t + (1 - domain.y[1]) * size.h) + 'px';\n        containerStyle.width = (size.w * (domain.x[1] - domain.x[0])) + 'px';\n        containerStyle.height = (size.h * (domain.y[1] - domain.y[0])) + 'px';\n    }\n\n    // force redraw so that promise is returned when rendering is completed\n    this.glplot.redraw();\n};\n\nproto.destroy = function() {\n    if(!this.glplot) return;\n\n    this.camera.mouseListener.enabled = false;\n    this.container.removeEventListener('wheel', this.camera.wheelListener);\n    this.camera = this.glplot.camera = null;\n    this.glplot.dispose();\n    this.container.parentNode.removeChild(this.container);\n    this.glplot = null;\n};\n\n// getOrbitCamera :: plotly_coords -> orbit_camera_coords\n// inverse of getLayoutCamera\nfunction getOrbitCamera(camera) {\n    return [\n        [camera.eye.x, camera.eye.y, camera.eye.z],\n        [camera.center.x, camera.center.y, camera.center.z],\n        [camera.up.x, camera.up.y, camera.up.z]\n    ];\n}\n\n// getLayoutCamera :: orbit_camera_coords -> plotly_coords\n// inverse of getOrbitCamera\nfunction getLayoutCamera(camera) {\n    return {\n        up: {x: camera.up[0], y: camera.up[1], z: camera.up[2]},\n        center: {x: camera.center[0], y: camera.center[1], z: camera.center[2]},\n        eye: {x: camera.eye[0], y: camera.eye[1], z: camera.eye[2]},\n        projection: {type: (camera._ortho === true) ? 'orthographic' : 'perspective'}\n    };\n}\n\n// get camera position in plotly coords from 'orbit-camera' coords\nproto.getCamera = function getCamera() {\n    this.glplot.camera.view.recalcMatrix(this.camera.view.lastT());\n    return getLayoutCamera(this.glplot.camera);\n};\n\n// set camera position with a set of plotly coords\nproto.setCamera = function setCamera(cameraData) {\n    this.glplot.camera.lookAt.apply(this, getOrbitCamera(cameraData));\n\n    var newOrtho = (cameraData.projection.type === 'orthographic');\n    var oldOrtho = this.glplot.camera._ortho;\n\n    if(newOrtho !== oldOrtho) {\n        this.glplot.redraw();\n\n        var pixelRatio = this.glplot.pixelRatio;\n\n        var RGBA = this.glplot.clearColor;\n        this.glplot.gl.clearColor(\n            RGBA[0], RGBA[1], RGBA[2], RGBA[3]\n        );\n        this.glplot.gl.clear(\n            this.glplot.gl.DEPTH_BUFFER_BIT |\n            this.glplot.gl.COLOR_BUFFER_BIT\n        );\n\n        this.glplot.dispose();\n\n        initializeGLPlot(this, pixelRatio);\n        this.glplot.camera._ortho = newOrtho;\n    }\n};\n\n// save camera to user layout (i.e. gd.layout)\nproto.saveCamera = function saveCamera(layout) {\n    var fullLayout = this.fullLayout;\n    var cameraData = this.getCamera();\n    var cameraNestedProp = Lib.nestedProperty(layout, this.id + '.camera');\n    var cameraDataLastSave = cameraNestedProp.get();\n    var hasChanged = false;\n\n    function same(x, y, i, j) {\n        var vectors = ['up', 'center', 'eye'];\n        var components = ['x', 'y', 'z'];\n        return y[vectors[i]] && (x[vectors[i]][components[j]] === y[vectors[i]][components[j]]);\n    }\n\n    if(cameraDataLastSave === undefined) {\n        hasChanged = true;\n    } else {\n        for(var i = 0; i < 3; i++) {\n            for(var j = 0; j < 3; j++) {\n                if(!same(cameraData, cameraDataLastSave, i, j)) {\n                    hasChanged = true;\n                    break;\n                }\n            }\n        }\n\n        if(!cameraDataLastSave.projection || (\n            cameraData.projection &&\n            cameraData.projection.type !== cameraDataLastSave.projection.type)) {\n            hasChanged = true;\n        }\n    }\n\n    if(hasChanged) {\n        var preGUI = {};\n        preGUI[this.id + '.camera'] = cameraDataLastSave;\n        Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, preGUI);\n\n        cameraNestedProp.set(cameraData);\n\n        var cameraFullNP = Lib.nestedProperty(fullLayout, this.id + '.camera');\n        cameraFullNP.set(cameraData);\n    }\n\n    return hasChanged;\n};\n\nproto.updateFx = function(dragmode, hovermode) {\n    var camera = this.camera;\n    if(camera) {\n        // rotate and orbital are synonymous\n        if(dragmode === 'orbit') {\n            camera.mode = 'orbit';\n            camera.keyBindingMode = 'rotate';\n        } else if(dragmode === 'turntable') {\n            camera.up = [0, 0, 1];\n            camera.mode = 'turntable';\n            camera.keyBindingMode = 'rotate';\n\n            // The setter for camera.mode animates the transition to z-up,\n            // but only if we *don't* explicitly set z-up earlier via the\n            // relayout. So push `up` back to layout & fullLayout manually now.\n            var gd = this.graphDiv;\n            var fullLayout = gd._fullLayout;\n            var fullCamera = this.fullSceneLayout.camera;\n            var x = fullCamera.up.x;\n            var y = fullCamera.up.y;\n            var z = fullCamera.up.z;\n            // only push `up` back to (full)layout if it's going to change\n            if(z / Math.sqrt(x * x + y * y + z * z) < 0.999) {\n                var attr = this.id + '.camera.up';\n                var zUp = {x: 0, y: 0, z: 1};\n                var edits = {};\n                edits[attr] = zUp;\n                var layout = gd.layout;\n                Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, edits);\n                fullCamera.up = zUp;\n                Lib.nestedProperty(layout, attr).set(zUp);\n            }\n        } else {\n            // none rotation modes [pan or zoom]\n            camera.keyBindingMode = dragmode;\n        }\n    }\n\n    // to put dragmode and hovermode on the same grounds from relayout\n    this.fullSceneLayout.hovermode = hovermode;\n};\n\nproto.toImage = function(format) {\n    if(!format) format = 'png';\n\n    if(this.staticMode) this.container.appendChild(STATIC_CANVAS);\n\n    // Force redraw\n    this.glplot.redraw();\n\n    // Grab context and yank out pixels\n    var gl = this.glplot.gl;\n    var w = gl.drawingBufferWidth;\n    var h = gl.drawingBufferHeight;\n\n    gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n\n    var pixels = new Uint8Array(w * h * 4);\n    gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels);\n\n    // Flip pixels\n    for(var j = 0, k = h - 1; j < k; ++j, --k) {\n        for(var i = 0; i < w; ++i) {\n            for(var l = 0; l < 4; ++l) {\n                var tmp = pixels[4 * (w * j + i) + l];\n                pixels[4 * (w * j + i) + l] = pixels[4 * (w * k + i) + l];\n                pixels[4 * (w * k + i) + l] = tmp;\n            }\n        }\n    }\n\n    var canvas = document.createElement('canvas');\n    canvas.width = w;\n    canvas.height = h;\n    var context = canvas.getContext('2d');\n    var imageData = context.createImageData(w, h);\n    imageData.data.set(pixels);\n    context.putImageData(imageData, 0, 0);\n\n    var dataURL;\n\n    switch(format) {\n        case 'jpeg':\n            dataURL = canvas.toDataURL('image/jpeg');\n            break;\n        case 'webp':\n            dataURL = canvas.toDataURL('image/webp');\n            break;\n        default:\n            dataURL = canvas.toDataURL('image/png');\n    }\n\n    if(this.staticMode) this.container.removeChild(STATIC_CANVAS);\n\n    return dataURL;\n};\n\nproto.setConvert = function() {\n    for(var i = 0; i < 3; i++) {\n        var ax = this.fullSceneLayout[axisProperties[i]];\n        Axes.setConvert(ax, this.fullLayout);\n        ax.setScale = Lib.noop;\n    }\n};\n\nproto.make4thDimension = function() {\n    var _this = this;\n    var gd = _this.graphDiv;\n    var fullLayout = gd._fullLayout;\n\n    // mock axis for hover formatting\n    _this.mockAxis = {\n        type: 'linear',\n        showexponent: 'all',\n        exponentformat: 'B'\n    };\n    Axes.setConvert(_this.mockAxis, fullLayout);\n};\n\nmodule.exports = Scene;\n\n},{\"../../components/fx\":632,\"../../lib\":719,\"../../lib/show_no_webgl_msg\":740,\"../../lib/str2rgbarray\":742,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"./layout/convert\":811,\"./layout/spikes\":814,\"./layout/tick_marks\":815,\"./project\":816,\"gl-plot3d\":290,\"has-passive-events\":411,\"webgl-context\":556}],818:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function zip3(x, y, z, len) {\n    len = len || x.length;\n\n    var result = new Array(len);\n    for(var i = 0; i < len; i++) {\n        result[i] = [x[i], y[i], z[i]];\n    }\n    return result;\n};\n\n},{}],819:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('./font_attributes');\nvar animationAttrs = _dereq_('./animation_attributes');\nvar colorAttrs = _dereq_('../components/color/attributes');\nvar padAttrs = _dereq_('./pad_attributes');\nvar extendFlat = _dereq_('../lib/extend').extendFlat;\n\nvar globalFont = fontAttrs({\n    editType: 'calc',\n    \n});\nglobalFont.family.dflt = '\"Open Sans\", verdana, arial, sans-serif';\nglobalFont.size.dflt = 12;\nglobalFont.color.dflt = colorAttrs.defaultLine;\n\nmodule.exports = {\n    font: globalFont,\n    title: {\n        text: {\n            valType: 'string',\n            \n            editType: 'layoutstyle',\n            \n        },\n        font: fontAttrs({\n            editType: 'layoutstyle',\n            \n        }),\n        xref: {\n            valType: 'enumerated',\n            dflt: 'container',\n            values: ['container', 'paper'],\n            \n            editType: 'layoutstyle',\n            \n        },\n        yref: {\n            valType: 'enumerated',\n            dflt: 'container',\n            values: ['container', 'paper'],\n            \n            editType: 'layoutstyle',\n            \n        },\n        x: {\n            valType: 'number',\n            min: 0,\n            max: 1,\n            dflt: 0.5,\n            \n            editType: 'layoutstyle',\n            \n        },\n        y: {\n            valType: 'number',\n            min: 0,\n            max: 1,\n            dflt: 'auto',\n            \n            editType: 'layoutstyle',\n            \n        },\n        xanchor: {\n            valType: 'enumerated',\n            dflt: 'auto',\n            values: ['auto', 'left', 'center', 'right'],\n            \n            editType: 'layoutstyle',\n            \n        },\n        yanchor: {\n            valType: 'enumerated',\n            dflt: 'auto',\n            values: ['auto', 'top', 'middle', 'bottom'],\n            \n            editType: 'layoutstyle',\n            \n        },\n        pad: extendFlat(padAttrs({editType: 'layoutstyle'}), {\n            \n        }),\n        editType: 'layoutstyle'\n    },\n    autosize: {\n        valType: 'boolean',\n        \n        dflt: false,\n        // autosize, width, and height get special editType treatment in _relayout\n        // so we can handle noop resizes more efficiently\n        editType: 'none',\n        \n    },\n    width: {\n        valType: 'number',\n        \n        min: 10,\n        dflt: 700,\n        editType: 'plot',\n        \n    },\n    height: {\n        valType: 'number',\n        \n        min: 10,\n        dflt: 450,\n        editType: 'plot',\n        \n    },\n    margin: {\n        l: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 80,\n            editType: 'plot',\n            \n        },\n        r: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 80,\n            editType: 'plot',\n            \n        },\n        t: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 100,\n            editType: 'plot',\n            \n        },\n        b: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 80,\n            editType: 'plot',\n            \n        },\n        pad: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 0,\n            editType: 'plot',\n            \n        },\n        autoexpand: {\n            valType: 'boolean',\n            \n            dflt: true,\n            editType: 'plot'\n        },\n        editType: 'plot'\n    },\n    paper_bgcolor: {\n        valType: 'color',\n        \n        dflt: colorAttrs.background,\n        editType: 'plot',\n        \n    },\n    plot_bgcolor: {\n        // defined here, but set in cartesian.supplyLayoutDefaults\n        // because it needs to know if there are (2D) axes or not\n        valType: 'color',\n        \n        dflt: colorAttrs.background,\n        editType: 'layoutstyle',\n        \n    },\n    separators: {\n        valType: 'string',\n        \n        editType: 'plot',\n        \n    },\n    hidesources: {\n        valType: 'boolean',\n        \n        dflt: false,\n        editType: 'plot',\n        \n    },\n    showlegend: {\n        // handled in legend.supplyLayoutDefaults\n        // but included here because it's not in the legend object\n        valType: 'boolean',\n        \n        editType: 'legend',\n        \n    },\n    colorway: {\n        valType: 'colorlist',\n        dflt: colorAttrs.defaults,\n        \n        editType: 'calc',\n        \n    },\n    datarevision: {\n        valType: 'any',\n        \n        editType: 'calc',\n        \n    },\n    uirevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n    editrevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n    selectionrevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n    template: {\n        valType: 'any',\n        \n        editType: 'calc',\n        \n    },\n    modebar: {\n        orientation: {\n            valType: 'enumerated',\n            values: ['v', 'h'],\n            dflt: 'h',\n            \n            editType: 'modebar',\n            \n        },\n        bgcolor: {\n            valType: 'color',\n            \n            editType: 'modebar',\n            \n        },\n        color: {\n            valType: 'color',\n            \n            editType: 'modebar',\n            \n        },\n        activecolor: {\n            valType: 'color',\n            \n            editType: 'modebar',\n            \n        },\n        uirevision: {\n            valType: 'any',\n            \n            editType: 'none',\n            \n        },\n        editType: 'modebar'\n    },\n\n    meta: {\n        valType: 'any',\n        arrayOk: true,\n        \n        editType: 'plot',\n        \n    },\n\n    transition: extendFlat({}, animationAttrs.transition, {\n        \n        editType: 'none'\n    }),\n    _deprecated: {\n        title: {\n            valType: 'string',\n            \n            editType: 'layoutstyle',\n            \n        },\n        titlefont: fontAttrs({\n            editType: 'layoutstyle',\n            \n        })\n    }\n};\n\n},{\"../components/color/attributes\":592,\"../lib/extend\":710,\"./animation_attributes\":762,\"./font_attributes\":793,\"./pad_attributes\":827}],820:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar requiredVersion = '1.1.1';\n\nvar stylesNonMapbox = {\n    'open-street-map': {\n        id: 'osm',\n        version: 8,\n        sources: {\n            'plotly-osm-tiles': {\n                type: 'raster',\n                attribution: '<a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">© OpenStreetMap</a>',\n                tiles: [\n                    'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',\n                    'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png'\n                ],\n                tileSize: 256\n            }\n        },\n        layers: [{\n            id: 'plotly-osm-tiles',\n            type: 'raster',\n            source: 'plotly-osm-tiles',\n            minzoom: 0,\n            maxzoom: 22\n        }]\n    },\n    'white-bg': {\n        id: 'white-bg',\n        version: 8,\n        sources: {},\n        layers: [{\n            id: 'white-bg',\n            type: 'background',\n            paint: {'background-color': '#FFFFFF'},\n            minzoom: 0,\n            maxzoom: 22\n        }]\n    },\n    'carto-positron': {\n        id: 'carto-positron',\n        version: 8,\n        sources: {\n            'plotly-carto-positron': {\n                type: 'raster',\n                attribution: '<a href=\"https://carto.com/\" target=\"_blank\">© CARTO</a>',\n                tiles: ['https://cartodb-basemaps-c.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png'],\n                tileSize: 256\n            }\n        },\n        layers: [{\n            id: 'plotly-carto-positron',\n            type: 'raster',\n            source: 'plotly-carto-positron',\n            minzoom: 0,\n            maxzoom: 22\n        }]\n    },\n    'carto-darkmatter': {\n        id: 'carto-darkmatter',\n        version: 8,\n        sources: {\n            'plotly-carto-darkmatter': {\n                type: 'raster',\n                attribution: '<a href=\"https://carto.com/\" target=\"_blank\">© CARTO</a>',\n                tiles: ['https://cartodb-basemaps-c.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png'],\n                tileSize: 256\n            }\n        },\n        layers: [{\n            id: 'plotly-carto-darkmatter',\n            type: 'raster',\n            source: 'plotly-carto-darkmatter',\n            minzoom: 0,\n            maxzoom: 22\n        }]\n    },\n    'stamen-terrain': {\n        id: 'stamen-terrain',\n        version: 8,\n        sources: {\n            'plotly-stamen-terrain': {\n                type: 'raster',\n                attribution: 'Map tiles by <a href=\"http://stamen.com\">Stamen Design</a>, under <a href=\"http://creativecommons.org/licenses/by/3.0\">CC BY 3.0</a> | Data by <a href=\"http://openstreetmap.org\">OpenStreetMap</a>, under <a href=\"http://www.openstreetmap.org/copyright\">ODbL</a>.',\n                tiles: ['https://stamen-tiles.a.ssl.fastly.net/terrain/{z}/{x}/{y}.png'],\n                tileSize: 256\n            }\n        },\n        layers: [{\n            id: 'plotly-stamen-terrain',\n            type: 'raster',\n            source: 'plotly-stamen-terrain',\n            minzoom: 0,\n            maxzoom: 22\n        }]\n    },\n    'stamen-toner': {\n        id: 'stamen-toner',\n        version: 8,\n        sources: {\n            'plotly-stamen-toner': {\n                type: 'raster',\n                attribution: 'Map tiles by <a href=\"http://stamen.com\">Stamen Design</a>, under <a href=\"http://creativecommons.org/licenses/by/3.0\">CC BY 3.0</a> | Data by <a href=\"http://openstreetmap.org\">OpenStreetMap</a>, under <a href=\"http://www.openstreetmap.org/copyright\">ODbL</a>.',\n                tiles: ['https://stamen-tiles.a.ssl.fastly.net/toner/{z}/{x}/{y}.png'],\n                tileSize: 256\n            }\n        },\n        layers: [{\n            id: 'plotly-stamen-toner',\n            type: 'raster',\n            source: 'plotly-stamen-toner',\n            minzoom: 0,\n            maxzoom: 22\n        }]\n    },\n    'stamen-watercolor': {\n        id: 'stamen-watercolor',\n        version: 8,\n        sources: {\n            'plotly-stamen-watercolor': {\n                type: 'raster',\n                attribution: 'Map tiles by <a href=\"http://stamen.com\">Stamen Design</a>, under <a href=\"http://creativecommons.org/licenses/by/3.0\">CC BY 3.0</a> | Data by <a href=\"http://openstreetmap.org\">OpenStreetMap</a>, under <a href=\"http://creativecommons.org/licenses/by-sa/3.0\">CC BY SA</a>.',\n                tiles: ['https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png'],\n                tileSize: 256\n            }\n        },\n        layers: [{\n            id: 'plotly-stamen-watercolor',\n            type: 'raster',\n            source: 'plotly-stamen-watercolor',\n            minzoom: 0,\n            maxzoom: 22\n        }]\n    }\n};\n\nvar styleValuesNonMapbox = Object.keys(stylesNonMapbox);\n\nmodule.exports = {\n    requiredVersion: requiredVersion,\n\n    styleUrlPrefix: 'mapbox://styles/mapbox/',\n    styleUrlSuffix: 'v9',\n\n    styleValuesMapbox: ['basic', 'streets', 'outdoors', 'light', 'dark', 'satellite', 'satellite-streets'],\n    styleValueDflt: 'basic',\n    stylesNonMapbox: stylesNonMapbox,\n    styleValuesNonMapbox: styleValuesNonMapbox,\n\n    traceLayerPrefix: 'plotly-trace-layer-',\n    layoutLayerPrefix: 'plotly-layout-layer-',\n\n    wrongVersionErrorMsg: [\n        'Your custom plotly.js bundle is not using the correct mapbox-gl version',\n        'Please install mapbox-gl@' + requiredVersion + '.'\n    ].join('\\n'),\n\n    noAccessTokenErrorMsg: [\n        'Missing Mapbox access token.',\n        'Mapbox trace type require a Mapbox access token to be registered.',\n        'For example:',\n        '  Plotly.plot(gd, data, layout, { mapboxAccessToken: \\'my-access-token\\' });',\n        'More info here: https://www.mapbox.com/help/define-access-token/'\n    ].join('\\n'),\n\n    missingStyleErrorMsg: [\n        'No valid mapbox style found, please set `mapbox.style` to one of:',\n        styleValuesNonMapbox.join(', '),\n        'or register a Mapbox access token to use a Mapbox-served style.'\n    ].join('\\n'),\n\n    multipleTokensErrorMsg: [\n        'Set multiple mapbox access token across different mapbox subplot,',\n        'using first token found as mapbox-gl does not allow multiple' +\n        'access tokens on the same page.'\n    ].join('\\n'),\n\n    mapOnErrorMsg: 'Mapbox error.',\n\n    // Mapbox logo for static export\n    mapboxLogo: {\n        path0: 'm 10.5,1.24 c -5.11,0 -9.25,4.15 -9.25,9.25 0,5.1 4.15,9.25 9.25,9.25 5.1,0 9.25,-4.15 9.25,-9.25 0,-5.11 -4.14,-9.25 -9.25,-9.25 z m 4.39,11.53 c -1.93,1.93 -4.78,2.31 -6.7,2.31 -0.7,0 -1.41,-0.05 -2.1,-0.16 0,0 -1.02,-5.64 2.14,-8.81 0.83,-0.83 1.95,-1.28 3.13,-1.28 1.27,0 2.49,0.51 3.39,1.42 1.84,1.84 1.89,4.75 0.14,6.52 z',\n        path1: 'M 10.5,-0.01 C 4.7,-0.01 0,4.7 0,10.49 c 0,5.79 4.7,10.5 10.5,10.5 5.8,0 10.5,-4.7 10.5,-10.5 C 20.99,4.7 16.3,-0.01 10.5,-0.01 Z m 0,19.75 c -5.11,0 -9.25,-4.15 -9.25,-9.25 0,-5.1 4.14,-9.26 9.25,-9.26 5.11,0 9.25,4.15 9.25,9.25 0,5.13 -4.14,9.26 -9.25,9.26 z',\n        path2: 'M 14.74,6.25 C 12.9,4.41 9.98,4.35 8.23,6.1 5.07,9.27 6.09,14.91 6.09,14.91 c 0,0 5.64,1.02 8.81,-2.14 C 16.64,11 16.59,8.09 14.74,6.25 Z m -2.27,4.09 -0.91,1.87 -0.9,-1.87 -1.86,-0.91 1.86,-0.9 0.9,-1.87 0.91,1.87 1.86,0.9 z',\n        polygon: '11.56,12.21 10.66,10.34 8.8,9.43 10.66,8.53 11.56,6.66 12.47,8.53 14.33,9.43 12.47,10.34'\n    },\n\n    // a subset of node_modules/mapbox-gl/dist/mapbox-gl.css\n    styleRules: {\n        map: 'overflow:hidden;position:relative;',\n        'missing-css': 'display:none;',\n        'canary': 'background-color:salmon;',\n\n        // Reusing CSS directives from: https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css\n        'ctrl-bottom-left': 'position: absolute; pointer-events: none; z-index: 2; bottom: 0; left: 0;',\n        'ctrl-bottom-right': 'position: absolute; pointer-events: none; z-index: 2; right: 0; bottom: 0;',\n        'ctrl': 'clear: both; pointer-events: auto; transform: translate(0, 0);',\n\n        // Compact ctrl\n        'ctrl-attrib.mapboxgl-compact .mapboxgl-ctrl-attrib-inner': 'display: none;',\n        'ctrl-attrib.mapboxgl-compact:hover .mapboxgl-ctrl-attrib-inner': 'display: block; margin-top:2px',\n        'ctrl-attrib.mapboxgl-compact:hover': 'padding: 2px 24px 2px 4px; visibility: visible; margin-top: 6px;',\n        'ctrl-attrib.mapboxgl-compact::after': 'content: \"\"; cursor: pointer; position: absolute; background-image: url(\\'data:image/svg+xml;charset=utf-8,%3Csvg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2000/svg\"%3E %3Cpath fill=\"%23333333\" fill-rule=\"evenodd\" d=\"M4,10a6,6 0 1,0 12,0a6,6 0 1,0 -12,0 M9,7a1,1 0 1,0 2,0a1,1 0 1,0 -2,0 M9,10a1,1 0 1,1 2,0l0,3a1,1 0 1,1 -2,0\"/%3E %3C/svg%3E\\'); background-color: rgba(255, 255, 255, 0.5); width: 24px; height: 24px; box-sizing: border-box; border-radius: 12px;',\n        'ctrl-attrib.mapboxgl-compact': 'min-height: 20px; padding: 0; margin: 10px; position: relative; background-color: #fff; border-radius: 3px 12px 12px 3px;',\n        'ctrl-bottom-right > .mapboxgl-ctrl-attrib.mapboxgl-compact::after': 'bottom: 0; right: 0',\n        'ctrl-bottom-left > .mapboxgl-ctrl-attrib.mapboxgl-compact::after': 'bottom: 0; left: 0',\n\n        'ctrl-bottom-left .mapboxgl-ctrl': 'margin: 0 0 10px 10px; float: left;',\n        'ctrl-bottom-right .mapboxgl-ctrl': 'margin: 0 10px 10px 0; float: right;',\n\n        'ctrl-attrib': 'color: rgba(0, 0, 0, 0.75); text-decoration: none; font-size: 12px',\n        'ctrl-attrib a': 'color: rgba(0, 0, 0, 0.75); text-decoration: none; font-size: 12px',\n        'ctrl-attrib a:hover': 'color: inherit; text-decoration: underline;',\n\n        'ctrl-attrib .mapbox-improve-map': 'font-weight: bold; margin-left: 2px;',\n        'attrib-empty': 'display: none;',\n\n        // Compact Mapbox logo without text\n        'ctrl-logo': 'display:block; width: 21px; height: 21px; background-image: url(\\'data:image/svg+xml;charset=utf-8,%3C?xml version=\"1.0\" encoding=\"utf-8\"?%3E %3Csvg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" viewBox=\"0 0 21 21\" style=\"enable-background:new 0 0 21 21;\" xml:space=\"preserve\"%3E%3Cg transform=\"translate(0,0.01)\"%3E%3Cpath d=\"m 10.5,1.24 c -5.11,0 -9.25,4.15 -9.25,9.25 0,5.1 4.15,9.25 9.25,9.25 5.1,0 9.25,-4.15 9.25,-9.25 0,-5.11 -4.14,-9.25 -9.25,-9.25 z m 4.39,11.53 c -1.93,1.93 -4.78,2.31 -6.7,2.31 -0.7,0 -1.41,-0.05 -2.1,-0.16 0,0 -1.02,-5.64 2.14,-8.81 0.83,-0.83 1.95,-1.28 3.13,-1.28 1.27,0 2.49,0.51 3.39,1.42 1.84,1.84 1.89,4.75 0.14,6.52 z\" style=\"opacity:0.9;fill:%23ffffff;enable-background:new\" class=\"st0\"/%3E%3Cpath d=\"M 10.5,-0.01 C 4.7,-0.01 0,4.7 0,10.49 c 0,5.79 4.7,10.5 10.5,10.5 5.8,0 10.5,-4.7 10.5,-10.5 C 20.99,4.7 16.3,-0.01 10.5,-0.01 Z m 0,19.75 c -5.11,0 -9.25,-4.15 -9.25,-9.25 0,-5.1 4.14,-9.26 9.25,-9.26 5.11,0 9.25,4.15 9.25,9.25 0,5.13 -4.14,9.26 -9.25,9.26 z\" style=\"opacity:0.35;enable-background:new\" class=\"st1\"/%3E%3Cpath d=\"M 14.74,6.25 C 12.9,4.41 9.98,4.35 8.23,6.1 5.07,9.27 6.09,14.91 6.09,14.91 c 0,0 5.64,1.02 8.81,-2.14 C 16.64,11 16.59,8.09 14.74,6.25 Z m -2.27,4.09 -0.91,1.87 -0.9,-1.87 -1.86,-0.91 1.86,-0.9 0.9,-1.87 0.91,1.87 1.86,0.9 z\" style=\"opacity:0.35;enable-background:new\" class=\"st1\"/%3E%3Cpolygon points=\"11.56,12.21 10.66,10.34 8.8,9.43 10.66,8.53 11.56,6.66 12.47,8.53 14.33,9.43 12.47,10.34 \" style=\"opacity:0.9;fill:%23ffffff;enable-background:new\" class=\"st0\"/%3E%3C/g%3E%3C/svg%3E\\')'\n\n        // Mapbox logo WITH text below (commented out for now)\n        // 'ctrl-logo': 'width: 85px; height: 21px; margin: 0 0 -3px -3px; display: block; background-repeat: no-repeat; cursor: pointer; background-image: url(\\'data:image/svg+xml;charset=utf-8,%3C?xml version=\"1.0\" encoding=\"utf-8\"?%3E%3Csvg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" viewBox=\"0 0 84.49 21\" style=\"enable-background:new 0 0 84.49 21;\" xml:space=\"preserve\"%3E%3Cg%3E %3Cpath class=\"st0\" style=\"opacity:0.9; fill: %23FFFFFF; enable-background: new;\" d=\"M83.25,14.26c0,0.12-0.09,0.21-0.21,0.21h-1.61c-0.13,0-0.24-0.06-0.3-0.17l-1.44-2.39l-1.44,2.39 c-0.06,0.11-0.18,0.17-0.3,0.17h-1.61c-0.04,0-0.08-0.01-0.12-0.03c-0.09-0.06-0.13-0.19-0.06-0.28l0,0l2.43-3.68L76.2,6.84 c-0.02-0.03-0.03-0.07-0.03-0.12c0-0.12,0.09-0.21,0.21-0.21h1.61c0.13,0,0.24,0.06,0.3,0.17l1.41,2.36l1.4-2.35 c0.06-0.11,0.18-0.17,0.3-0.17H83c0.04,0,0.08,0.01,0.12,0.03c0.09,0.06,0.13,0.19,0.06,0.28l0,0l-2.37,3.63l2.43,3.67 C83.24,14.18,83.25,14.22,83.25,14.26z\"/%3E %3Cpath class=\"st0\" style=\"opacity:0.9; fill: %23FFFFFF; enable-background: new;\" d=\"M66.24,9.59c-0.39-1.88-1.96-3.28-3.84-3.28c-1.03,0-2.03,0.42-2.73,1.18V3.51c0-0.13-0.1-0.23-0.23-0.23h-1.4 c-0.13,0-0.23,0.11-0.23,0.23v10.72c0,0.13,0.1,0.23,0.23,0.23h1.4c0.13,0,0.23-0.11,0.23-0.23V13.5c0.71,0.75,1.7,1.18,2.73,1.18 c1.88,0,3.45-1.41,3.84-3.29C66.37,10.79,66.37,10.18,66.24,9.59L66.24,9.59z M62.08,13c-1.32,0-2.39-1.11-2.41-2.48v-0.06 c0.02-1.38,1.09-2.48,2.41-2.48s2.42,1.12,2.42,2.51S63.41,13,62.08,13z\"/%3E %3Cpath class=\"st0\" style=\"opacity:0.9; fill: %23FFFFFF; enable-background: new;\" d=\"M71.67,6.32c-1.98-0.01-3.72,1.35-4.16,3.29c-0.13,0.59-0.13,1.19,0,1.77c0.44,1.94,2.17,3.32,4.17,3.3 c2.35,0,4.26-1.87,4.26-4.19S74.04,6.32,71.67,6.32z M71.65,13.01c-1.33,0-2.42-1.12-2.42-2.51s1.08-2.52,2.42-2.52 c1.33,0,2.42,1.12,2.42,2.51S72.99,13,71.65,13.01L71.65,13.01z\"/%3E %3Cpath class=\"st1\" style=\"opacity:0.35; enable-background:new;\" d=\"M62.08,7.98c-1.32,0-2.39,1.11-2.41,2.48v0.06C59.68,11.9,60.75,13,62.08,13s2.42-1.12,2.42-2.51 S63.41,7.98,62.08,7.98z M62.08,11.76c-0.63,0-1.14-0.56-1.17-1.25v-0.04c0.01-0.69,0.54-1.25,1.17-1.25 c0.63,0,1.17,0.57,1.17,1.27C63.24,11.2,62.73,11.76,62.08,11.76z\"/%3E %3Cpath class=\"st1\" style=\"opacity:0.35; enable-background:new;\" d=\"M71.65,7.98c-1.33,0-2.42,1.12-2.42,2.51S70.32,13,71.65,13s2.42-1.12,2.42-2.51S72.99,7.98,71.65,7.98z M71.65,11.76c-0.64,0-1.17-0.57-1.17-1.27c0-0.7,0.53-1.26,1.17-1.26s1.17,0.57,1.17,1.27C72.82,11.21,72.29,11.76,71.65,11.76z\"/%3E %3Cpath class=\"st0\" style=\"opacity:0.9; fill: %23FFFFFF; enable-background: new;\" d=\"M45.74,6.53h-1.4c-0.13,0-0.23,0.11-0.23,0.23v0.73c-0.71-0.75-1.7-1.18-2.73-1.18 c-2.17,0-3.94,1.87-3.94,4.19s1.77,4.19,3.94,4.19c1.04,0,2.03-0.43,2.73-1.19v0.73c0,0.13,0.1,0.23,0.23,0.23h1.4 c0.13,0,0.23-0.11,0.23-0.23V6.74c0-0.12-0.09-0.22-0.22-0.22C45.75,6.53,45.75,6.53,45.74,6.53z M44.12,10.53 C44.11,11.9,43.03,13,41.71,13s-2.42-1.12-2.42-2.51s1.08-2.52,2.4-2.52c1.33,0,2.39,1.11,2.41,2.48L44.12,10.53z\"/%3E %3Cpath class=\"st1\" style=\"opacity:0.35; enable-background:new;\" d=\"M41.71,7.98c-1.33,0-2.42,1.12-2.42,2.51S40.37,13,41.71,13s2.39-1.11,2.41-2.48v-0.06 C44.1,9.09,43.03,7.98,41.71,7.98z M40.55,10.49c0-0.7,0.52-1.27,1.17-1.27c0.64,0,1.14,0.56,1.17,1.25v0.04 c-0.01,0.68-0.53,1.24-1.17,1.24C41.08,11.75,40.55,11.19,40.55,10.49z\"/%3E %3Cpath class=\"st0\" style=\"opacity:0.9; fill: %23FFFFFF; enable-background: new;\" d=\"M52.41,6.32c-1.03,0-2.03,0.42-2.73,1.18V6.75c0-0.13-0.1-0.23-0.23-0.23h-1.4c-0.13,0-0.23,0.11-0.23,0.23 v10.72c0,0.13,0.1,0.23,0.23,0.23h1.4c0.13,0,0.23-0.1,0.23-0.23V13.5c0.71,0.75,1.7,1.18,2.74,1.18c2.17,0,3.94-1.87,3.94-4.19 S54.58,6.32,52.41,6.32z M52.08,13.01c-1.32,0-2.39-1.11-2.42-2.48v-0.07c0.02-1.38,1.09-2.49,2.4-2.49c1.32,0,2.41,1.12,2.41,2.51 S53.4,13,52.08,13.01L52.08,13.01z\"/%3E %3Cpath class=\"st1\" style=\"opacity:0.35; enable-background:new;\" d=\"M52.08,7.98c-1.32,0-2.39,1.11-2.42,2.48v0.06c0.03,1.38,1.1,2.48,2.42,2.48s2.41-1.12,2.41-2.51 S53.4,7.98,52.08,7.98z M52.08,11.76c-0.63,0-1.14-0.56-1.17-1.25v-0.04c0.01-0.69,0.54-1.25,1.17-1.25c0.63,0,1.17,0.58,1.17,1.27 S52.72,11.76,52.08,11.76z\"/%3E %3Cpath class=\"st0\" style=\"opacity:0.9; fill: %23FFFFFF; enable-background: new;\" d=\"M36.08,14.24c0,0.13-0.1,0.23-0.23,0.23h-1.41c-0.13,0-0.23-0.11-0.23-0.23V9.68c0-0.98-0.74-1.71-1.62-1.71 c-0.8,0-1.46,0.7-1.59,1.62l0.01,4.66c0,0.13-0.11,0.23-0.23,0.23h-1.41c-0.13,0-0.23-0.11-0.23-0.23V9.68 c0-0.98-0.74-1.71-1.62-1.71c-0.85,0-1.54,0.79-1.6,1.8v4.48c0,0.13-0.1,0.23-0.23,0.23h-1.4c-0.13,0-0.23-0.11-0.23-0.23V6.74 c0.01-0.13,0.1-0.22,0.23-0.22h1.4c0.13,0,0.22,0.11,0.23,0.22V7.4c0.5-0.68,1.3-1.09,2.16-1.1h0.03c1.09,0,2.09,0.6,2.6,1.55 c0.45-0.95,1.4-1.55,2.44-1.56c1.62,0,2.93,1.25,2.9,2.78L36.08,14.24z\"/%3E %3Cpath class=\"st1\" style=\"opacity:0.35; enable-background:new;\" d=\"M84.34,13.59l-0.07-0.13l-1.96-2.99l1.94-2.95c0.44-0.67,0.26-1.56-0.41-2.02c-0.02,0-0.03,0-0.04-0.01 c-0.23-0.15-0.5-0.22-0.78-0.22h-1.61c-0.56,0-1.08,0.29-1.37,0.78L79.72,6.6l-0.34-0.56C79.09,5.56,78.57,5.27,78,5.27h-1.6 c-0.6,0-1.13,0.37-1.35,0.92c-2.19-1.66-5.28-1.47-7.26,0.45c-0.35,0.34-0.65,0.72-0.89,1.14c-0.9-1.62-2.58-2.72-4.5-2.72 c-0.5,0-1.01,0.07-1.48,0.23V3.51c0-0.82-0.66-1.48-1.47-1.48h-1.4c-0.81,0-1.47,0.66-1.47,1.47v3.75 c-0.95-1.36-2.5-2.18-4.17-2.19c-0.74,0-1.46,0.16-2.12,0.47c-0.24-0.17-0.54-0.26-0.84-0.26h-1.4c-0.45,0-0.87,0.21-1.15,0.56 c-0.02-0.03-0.04-0.05-0.07-0.08c-0.28-0.3-0.68-0.47-1.09-0.47h-1.39c-0.3,0-0.6,0.09-0.84,0.26c-0.67-0.3-1.39-0.46-2.12-0.46 c-1.83,0-3.43,1-4.37,2.5c-0.2-0.46-0.48-0.89-0.83-1.25c-0.8-0.81-1.89-1.25-3.02-1.25h-0.01c-0.89,0.01-1.75,0.33-2.46,0.88 c-0.74-0.57-1.64-0.88-2.57-0.88H28.1c-0.29,0-0.58,0.03-0.86,0.11c-0.28,0.06-0.56,0.16-0.82,0.28c-0.21-0.12-0.45-0.18-0.7-0.18 h-1.4c-0.82,0-1.47,0.66-1.47,1.47v7.5c0,0.82,0.66,1.47,1.47,1.47h1.4c0.82,0,1.48-0.66,1.48-1.48l0,0V9.79 c0.03-0.36,0.23-0.59,0.36-0.59c0.18,0,0.38,0.18,0.38,0.47v4.57c0,0.82,0.66,1.47,1.47,1.47h1.41c0.82,0,1.47-0.66,1.47-1.47 l-0.01-4.57c0.06-0.32,0.25-0.47,0.35-0.47c0.18,0,0.38,0.18,0.38,0.47v4.57c0,0.82,0.66,1.47,1.47,1.47h1.41 c0.82,0,1.47-0.66,1.47-1.47v-0.38c0.96,1.29,2.46,2.06,4.06,2.06c0.74,0,1.46-0.16,2.12-0.47c0.24,0.17,0.54,0.26,0.84,0.26h1.39 c0.3,0,0.6-0.09,0.84-0.26v2.01c0,0.82,0.66,1.47,1.47,1.47h1.4c0.82,0,1.47-0.66,1.47-1.47v-1.77c0.48,0.15,0.99,0.23,1.49,0.22 c1.7,0,3.22-0.87,4.17-2.2v0.52c0,0.82,0.66,1.47,1.47,1.47h1.4c0.3,0,0.6-0.09,0.84-0.26c0.66,0.31,1.39,0.47,2.12,0.47 c1.92,0,3.6-1.1,4.49-2.73c1.54,2.65,4.95,3.53,7.58,1.98c0.18-0.11,0.36-0.22,0.53-0.36c0.22,0.55,0.76,0.91,1.35,0.9H78 c0.56,0,1.08-0.29,1.37-0.78l0.37-0.61l0.37,0.61c0.29,0.48,0.81,0.78,1.38,0.78h1.6c0.81,0,1.46-0.66,1.45-1.46 C84.49,14.02,84.44,13.8,84.34,13.59L84.34,13.59z M35.86,14.47h-1.41c-0.13,0-0.23-0.11-0.23-0.23V9.68 c0-0.98-0.74-1.71-1.62-1.71c-0.8,0-1.46,0.7-1.59,1.62l0.01,4.66c0,0.13-0.1,0.23-0.23,0.23h-1.41c-0.13,0-0.23-0.11-0.23-0.23 V9.68c0-0.98-0.74-1.71-1.62-1.71c-0.85,0-1.54,0.79-1.6,1.8v4.48c0,0.13-0.1,0.23-0.23,0.23h-1.4c-0.13,0-0.23-0.11-0.23-0.23 V6.74c0.01-0.13,0.11-0.22,0.23-0.22h1.4c0.13,0,0.22,0.11,0.23,0.22V7.4c0.5-0.68,1.3-1.09,2.16-1.1h0.03 c1.09,0,2.09,0.6,2.6,1.55c0.45-0.95,1.4-1.55,2.44-1.56c1.62,0,2.93,1.25,2.9,2.78l0.01,5.16C36.09,14.36,35.98,14.46,35.86,14.47 L35.86,14.47z M45.97,14.24c0,0.13-0.1,0.23-0.23,0.23h-1.4c-0.13,0-0.23-0.11-0.23-0.23V13.5c-0.7,0.76-1.69,1.18-2.72,1.18 c-2.17,0-3.94-1.87-3.94-4.19s1.77-4.19,3.94-4.19c1.03,0,2.02,0.43,2.73,1.18V6.74c0-0.13,0.1-0.23,0.23-0.23h1.4 c0.12-0.01,0.22,0.08,0.23,0.21c0,0.01,0,0.01,0,0.02v7.51h-0.01V14.24z M52.41,14.67c-1.03,0-2.02-0.43-2.73-1.18v3.97 c0,0.13-0.1,0.23-0.23,0.23h-1.4c-0.13,0-0.23-0.1-0.23-0.23V6.75c0-0.13,0.1-0.22,0.23-0.22h1.4c0.13,0,0.23,0.11,0.23,0.23v0.73 c0.71-0.76,1.7-1.18,2.73-1.18c2.17,0,3.94,1.86,3.94,4.18S54.58,14.67,52.41,14.67z M66.24,11.39c-0.39,1.87-1.96,3.29-3.84,3.29 c-1.03,0-2.02-0.43-2.73-1.18v0.73c0,0.13-0.1,0.23-0.23,0.23h-1.4c-0.13,0-0.23-0.11-0.23-0.23V3.51c0-0.13,0.1-0.23,0.23-0.23 h1.4c0.13,0,0.23,0.11,0.23,0.23v3.97c0.71-0.75,1.7-1.18,2.73-1.17c1.88,0,3.45,1.4,3.84,3.28C66.37,10.19,66.37,10.8,66.24,11.39 L66.24,11.39L66.24,11.39z M71.67,14.68c-2,0.01-3.73-1.35-4.17-3.3c-0.13-0.59-0.13-1.19,0-1.77c0.44-1.94,2.17-3.31,4.17-3.3 c2.36,0,4.26,1.87,4.26,4.19S74.03,14.68,71.67,14.68L71.67,14.68z M83.04,14.47h-1.61c-0.13,0-0.24-0.06-0.3-0.17l-1.44-2.39 l-1.44,2.39c-0.06,0.11-0.18,0.17-0.3,0.17h-1.61c-0.04,0-0.08-0.01-0.12-0.03c-0.09-0.06-0.13-0.19-0.06-0.28l0,0l2.43-3.68 L76.2,6.84c-0.02-0.03-0.03-0.07-0.03-0.12c0-0.12,0.09-0.21,0.21-0.21h1.61c0.13,0,0.24,0.06,0.3,0.17l1.41,2.36l1.41-2.36 c0.06-0.11,0.18-0.17,0.3-0.17h1.61c0.04,0,0.08,0.01,0.12,0.03c0.09,0.06,0.13,0.19,0.06,0.28l0,0l-2.38,3.64l2.43,3.67 c0.02,0.03,0.03,0.07,0.03,0.12C83.25,14.38,83.16,14.47,83.04,14.47L83.04,14.47L83.04,14.47z\"/%3E %3Cpath class=\"st0\" style=\"opacity:0.9; fill: %23FFFFFF; enable-background: new;\" d=\"M10.5,1.24c-5.11,0-9.25,4.15-9.25,9.25s4.15,9.25,9.25,9.25s9.25-4.15,9.25-9.25 C19.75,5.38,15.61,1.24,10.5,1.24z M14.89,12.77c-1.93,1.93-4.78,2.31-6.7,2.31c-0.7,0-1.41-0.05-2.1-0.16c0,0-1.02-5.64,2.14-8.81 c0.83-0.83,1.95-1.28,3.13-1.28c1.27,0,2.49,0.51,3.39,1.42C16.59,8.09,16.64,11,14.89,12.77z\"/%3E %3Cpath class=\"st1\" style=\"opacity:0.35; enable-background:new;\" d=\"M10.5-0.01C4.7-0.01,0,4.7,0,10.49s4.7,10.5,10.5,10.5S21,16.29,21,10.49C20.99,4.7,16.3-0.01,10.5-0.01z M10.5,19.74c-5.11,0-9.25-4.15-9.25-9.25s4.14-9.26,9.25-9.26s9.25,4.15,9.25,9.25C19.75,15.61,15.61,19.74,10.5,19.74z\"/%3E %3Cpath class=\"st1\" style=\"opacity:0.35; enable-background:new;\" d=\"M14.74,6.25C12.9,4.41,9.98,4.35,8.23,6.1c-3.16,3.17-2.14,8.81-2.14,8.81s5.64,1.02,8.81-2.14 C16.64,11,16.59,8.09,14.74,6.25z M12.47,10.34l-0.91,1.87l-0.9-1.87L8.8,9.43l1.86-0.9l0.9-1.87l0.91,1.87l1.86,0.9L12.47,10.34z\"/%3E %3Cpolygon class=\"st0\" style=\"opacity:0.9; fill: %23FFFFFF; enable-background: new;\" points=\"14.33,9.43 12.47,10.34 11.56,12.21 10.66,10.34 8.8,9.43 10.66,8.53 11.56,6.66 12.47,8.53 \"/%3E%3C/g%3E%3C/svg%3E\\');'\n    }\n};\n\n},{}],821:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n/**\n * Convert plotly.js 'textposition' to mapbox-gl 'anchor' and 'offset'\n * (with the help of the icon size).\n *\n * @param {string} textpostion : plotly.js textposition value\n * @param {number} iconSize : plotly.js icon size (e.g. marker.size for traces)\n *\n * @return {object}\n *      - anchor\n *      - offset\n */\nmodule.exports = function convertTextOpts(textposition, iconSize) {\n    var parts = textposition.split(' ');\n    var vPos = parts[0];\n    var hPos = parts[1];\n\n    // ballpack values\n    var factor = Lib.isArrayOrTypedArray(iconSize) ? Lib.mean(iconSize) : iconSize;\n    var xInc = 0.5 + (factor / 100);\n    var yInc = 1.5 + (factor / 100);\n\n    var anchorVals = ['', ''];\n    var offset = [0, 0];\n\n    switch(vPos) {\n        case 'top':\n            anchorVals[0] = 'top';\n            offset[1] = -yInc;\n            break;\n        case 'bottom':\n            anchorVals[0] = 'bottom';\n            offset[1] = yInc;\n            break;\n    }\n\n    switch(hPos) {\n        case 'left':\n            anchorVals[1] = 'right';\n            offset[0] = -xInc;\n            break;\n        case 'right':\n            anchorVals[1] = 'left';\n            offset[0] = xInc;\n            break;\n    }\n\n    // Mapbox text-anchor must be one of:\n    //  center, left, right, top, bottom,\n    //  top-left, top-right, bottom-left, bottom-right\n\n    var anchor;\n    if(anchorVals[0] && anchorVals[1]) anchor = anchorVals.join('-');\n    else if(anchorVals[0]) anchor = anchorVals[0];\n    else if(anchorVals[1]) anchor = anchorVals[1];\n    else anchor = 'center';\n\n    return { anchor: anchor, offset: offset };\n};\n\n},{\"../../lib\":719}],822:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar mapboxgl = _dereq_('mapbox-gl');\n\nvar Lib = _dereq_('../../lib');\nvar getSubplotCalcData = _dereq_('../../plots/get_data').getSubplotCalcData;\nvar xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');\nvar d3 = _dereq_('d3');\nvar Drawing = _dereq_('../../components/drawing');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\n\nvar Mapbox = _dereq_('./mapbox');\n\nvar MAPBOX = 'mapbox';\n\nvar constants = exports.constants = _dereq_('./constants');\n\nexports.name = MAPBOX;\n\nexports.attr = 'subplot';\n\nexports.idRoot = MAPBOX;\n\nexports.idRegex = exports.attrRegex = Lib.counterRegex(MAPBOX);\n\nexports.attributes = {\n    subplot: {\n        valType: 'subplotid',\n        \n        dflt: 'mapbox',\n        editType: 'calc',\n        \n    }\n};\n\nexports.layoutAttributes = _dereq_('./layout_attributes');\n\nexports.supplyLayoutDefaults = _dereq_('./layout_defaults');\n\nexports.plot = function plot(gd) {\n    var fullLayout = gd._fullLayout;\n    var calcData = gd.calcdata;\n    var mapboxIds = fullLayout._subplots[MAPBOX];\n\n    if(mapboxgl.version !== constants.requiredVersion) {\n        throw new Error(constants.wrongVersionErrorMsg);\n    }\n\n    var accessToken = findAccessToken(gd, mapboxIds);\n    mapboxgl.accessToken = accessToken;\n\n    for(var i = 0; i < mapboxIds.length; i++) {\n        var id = mapboxIds[i];\n        var subplotCalcData = getSubplotCalcData(calcData, MAPBOX, id);\n        var opts = fullLayout[id];\n        var mapbox = opts._subplot;\n\n        if(!mapbox) {\n            mapbox = new Mapbox(gd, id);\n            fullLayout[id]._subplot = mapbox;\n        }\n\n        if(!mapbox.viewInitial) {\n            mapbox.viewInitial = {\n                center: Lib.extendFlat({}, opts.center),\n                zoom: opts.zoom,\n                bearing: opts.bearing,\n                pitch: opts.pitch\n            };\n        }\n\n        mapbox.plot(subplotCalcData, fullLayout, gd._promises);\n    }\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var oldMapboxKeys = oldFullLayout._subplots[MAPBOX] || [];\n\n    for(var i = 0; i < oldMapboxKeys.length; i++) {\n        var oldMapboxKey = oldMapboxKeys[i];\n\n        if(!newFullLayout[oldMapboxKey] && !!oldFullLayout[oldMapboxKey]._subplot) {\n            oldFullLayout[oldMapboxKey]._subplot.destroy();\n        }\n    }\n};\n\nexports.toSVG = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var subplotIds = fullLayout._subplots[MAPBOX];\n    var size = fullLayout._size;\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var opts = fullLayout[subplotIds[i]];\n        var domain = opts.domain;\n        var mapbox = opts._subplot;\n\n        var imageData = mapbox.toImage('png');\n        var image = fullLayout._glimages.append('svg:image');\n\n        image.attr({\n            xmlns: xmlnsNamespaces.svg,\n            'xlink:href': imageData,\n            x: size.l + size.w * domain.x[0],\n            y: size.t + size.h * (1 - domain.y[1]),\n            width: size.w * (domain.x[1] - domain.x[0]),\n            height: size.h * (domain.y[1] - domain.y[0]),\n            preserveAspectRatio: 'none'\n        });\n\n        var subplotDiv = d3.select(opts._subplot.div);\n\n        // Append logo if visible\n        var hidden = subplotDiv.select('.mapboxgl-ctrl-logo').node().offsetParent === null;\n        if(!hidden) {\n            var logo = fullLayout._glimages.append('g');\n            logo.attr('transform', 'translate(' + (size.l + size.w * domain.x[0] + 10) + ', ' + (size.t + size.h * (1 - domain.y[0]) - 31) + ')');\n            logo.append('path')\n              .attr('d', constants.mapboxLogo.path0)\n              .style({\n                  opacity: 0.9,\n                  fill: '#ffffff',\n                  'enable-background': 'new'\n              });\n\n            logo.append('path')\n              .attr('d', constants.mapboxLogo.path1)\n              .style('opacity', 0.35)\n              .style('enable-background', 'new');\n\n            logo.append('path')\n              .attr('d', constants.mapboxLogo.path2)\n              .style('opacity', 0.35)\n              .style('enable-background', 'new');\n\n            logo.append('polygon')\n              .attr('points', constants.mapboxLogo.polygon)\n              .style({\n                  opacity: 0.9,\n                  fill: '#ffffff',\n                  'enable-background': 'new'\n              });\n        }\n\n        // Add attributions\n        var attributions = subplotDiv\n                              .select('.mapboxgl-ctrl-attrib').text()\n                              .replace('Improve this map', '');\n\n        var attributionGroup = fullLayout._glimages.append('g');\n\n        var attributionText = attributionGroup.append('text');\n        attributionText\n          .text(attributions)\n          .classed('static-attribution', true)\n          .attr({\n              'font-size': 12,\n              'font-family': 'Arial',\n              'color': 'rgba(0, 0, 0, 0.75)',\n              'text-anchor': 'end',\n              'data-unformatted': attributions\n          });\n\n        var bBox = Drawing.bBox(attributionText.node());\n\n        // Break into multiple lines twice larger than domain\n        var maxWidth = size.w * (domain.x[1] - domain.x[0]);\n        if((bBox.width > maxWidth / 2)) {\n            var multilineAttributions = attributions.split('|').join('<br>');\n            attributionText\n              .text(multilineAttributions)\n              .attr('data-unformatted', multilineAttributions)\n              .call(svgTextUtils.convertToTspans, gd);\n\n            bBox = Drawing.bBox(attributionText.node());\n        }\n        attributionText.attr('transform', 'translate(-3, ' + (-bBox.height + 8) + ')');\n\n        // Draw white rectangle behind text\n        attributionGroup\n          .insert('rect', '.static-attribution')\n          .attr({\n              x: -bBox.width - 6,\n              y: -bBox.height - 3,\n              width: bBox.width + 6,\n              height: bBox.height + 3,\n              fill: 'rgba(255, 255, 255, 0.75)'\n          });\n\n        // Scale down if larger than domain\n        var scaleRatio = 1;\n        if((bBox.width + 6) > maxWidth) scaleRatio = maxWidth / (bBox.width + 6);\n\n        var offset = [(size.l + size.w * domain.x[1]), (size.t + size.h * (1 - domain.y[0]))];\n        attributionGroup.attr('transform', 'translate(' + offset[0] + ',' + offset[1] + ') scale(' + scaleRatio + ')');\n    }\n};\n\n// N.B. mapbox-gl only allows one accessToken to be set per page:\n// https://github.com/mapbox/mapbox-gl-js/issues/6331\nfunction findAccessToken(gd, mapboxIds) {\n    var fullLayout = gd._fullLayout;\n    var context = gd._context;\n\n    // special case for Mapbox Atlas users\n    if(context.mapboxAccessToken === '') return '';\n\n    var tokensUseful = [];\n    var tokensListed = [];\n    var hasOneSetMapboxStyle = false;\n    var wontWork = false;\n\n    // Take the first token we find in a mapbox subplot.\n    // These default to the context value but may be overridden.\n    for(var i = 0; i < mapboxIds.length; i++) {\n        var opts = fullLayout[mapboxIds[i]];\n        var token = opts.accesstoken;\n\n        if(isMapboxStyle(opts.style)) {\n            if(token) {\n                Lib.pushUnique(tokensUseful, token);\n            } else {\n                if(isMapboxStyle(opts._input.style)) {\n                    Lib.error('Uses Mapbox map style, but did not set an access token.');\n                    hasOneSetMapboxStyle = true;\n                }\n                wontWork = true;\n            }\n        }\n\n        if(token) {\n            Lib.pushUnique(tokensListed, token);\n        }\n    }\n\n    if(wontWork) {\n        var msg = hasOneSetMapboxStyle ?\n            constants.noAccessTokenErrorMsg :\n            constants.missingStyleErrorMsg;\n        throw new Error(msg);\n    }\n\n    if(tokensUseful.length) {\n        if(tokensUseful.length > 1) {\n            Lib.warn(constants.multipleTokensErrorMsg);\n        }\n        return tokensUseful[0];\n    } else {\n        if(tokensListed.length) {\n            Lib.log([\n                'Listed mapbox access token(s)', tokensListed.join(','),\n                'but did not use a Mapbox map style, ignoring token(s).'\n            ].join(' '));\n        }\n        return '';\n    }\n}\n\nfunction isMapboxStyle(s) {\n    return typeof s === 'string' && constants.styleValuesMapbox.indexOf(s) !== -1;\n}\n\nexports.updateFx = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var subplotIds = fullLayout._subplots[MAPBOX];\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var subplotObj = fullLayout[subplotIds[i]]._subplot;\n        subplotObj.updateFx(fullLayout);\n    }\n};\n\n},{\"../../components/drawing\":614,\"../../constants/xmlns_namespaces\":696,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plots/get_data\":802,\"./constants\":820,\"./layout_attributes\":824,\"./layout_defaults\":825,\"./mapbox\":826,\"d3\":163,\"mapbox-gl\":426}],823:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar convertTextOpts = _dereq_('./convert_text_opts');\nvar constants = _dereq_('./constants');\n\nfunction MapboxLayer(subplot, index) {\n    this.subplot = subplot;\n\n    this.uid = subplot.uid + '-' + index;\n    this.index = index;\n\n    this.idSource = 'source-' + this.uid;\n    this.idLayer = constants.layoutLayerPrefix + this.uid;\n\n    // some state variable to check if a remove/add step is needed\n    this.sourceType = null;\n    this.source = null;\n    this.layerType = null;\n    this.below = null;\n\n    // is layer currently visible\n    this.visible = false;\n}\n\nvar proto = MapboxLayer.prototype;\n\nproto.update = function update(opts) {\n    if(!this.visible) {\n        // IMPORTANT: must create source before layer to not cause errors\n        this.updateSource(opts);\n        this.updateLayer(opts);\n    } else if(this.needsNewSource(opts)) {\n        // IMPORTANT: must delete layer before source to not cause errors\n        this.removeLayer();\n        this.updateSource(opts);\n        this.updateLayer(opts);\n    } else if(this.needsNewLayer(opts)) {\n        this.updateLayer(opts);\n    } else {\n        this.updateStyle(opts);\n    }\n\n    this.visible = isVisible(opts);\n};\n\nproto.needsNewSource = function(opts) {\n    // for some reason changing layer to 'fill' or 'symbol'\n    // w/o changing the source throws an exception in mapbox-gl 0.18 ;\n    // stay safe and make new source on type changes\n    return (\n        this.sourceType !== opts.sourcetype ||\n        this.source !== opts.source ||\n        this.layerType !== opts.type\n    );\n};\n\nproto.needsNewLayer = function(opts) {\n    return (\n        this.layerType !== opts.type ||\n        this.below !== this.subplot.belowLookup['layout-' + this.index]\n    );\n};\n\nproto.updateSource = function(opts) {\n    var map = this.subplot.map;\n\n    if(map.getSource(this.idSource)) map.removeSource(this.idSource);\n\n    this.sourceType = opts.sourcetype;\n    this.source = opts.source;\n\n    if(!isVisible(opts)) return;\n\n    var sourceOpts = convertSourceOpts(opts);\n\n    map.addSource(this.idSource, sourceOpts);\n};\n\nproto.updateLayer = function(opts) {\n    var subplot = this.subplot;\n    var convertedOpts = convertOpts(opts);\n\n    var below = this.subplot.belowLookup['layout-' + this.index];\n    var _below;\n\n    if(below === 'traces') {\n        var mapLayers = subplot.getMapLayers();\n\n        // find id of first plotly trace layer\n        for(var i = 0; i < mapLayers.length; i++) {\n            var layerId = mapLayers[i].id;\n            if(typeof layerId === 'string' &&\n                layerId.indexOf(constants.traceLayerPrefix) === 0\n            ) {\n                _below = layerId;\n                break;\n            }\n        }\n    } else {\n        _below = below;\n    }\n\n    this.removeLayer();\n\n    if(isVisible(opts)) {\n        subplot.addLayer({\n            id: this.idLayer,\n            source: this.idSource,\n            'source-layer': opts.sourcelayer || '',\n            type: opts.type,\n            minzoom: opts.minzoom,\n            maxzoom: opts.maxzoom,\n            layout: convertedOpts.layout,\n            paint: convertedOpts.paint\n        }, _below);\n    }\n\n    this.layerType = opts.type;\n    this.below = below;\n};\n\nproto.updateStyle = function(opts) {\n    if(isVisible(opts)) {\n        var convertedOpts = convertOpts(opts);\n        this.subplot.setOptions(this.idLayer, 'setLayoutProperty', convertedOpts.layout);\n        this.subplot.setOptions(this.idLayer, 'setPaintProperty', convertedOpts.paint);\n    }\n};\n\nproto.removeLayer = function() {\n    var map = this.subplot.map;\n    if(map.getLayer(this.idLayer)) {\n        map.removeLayer(this.idLayer);\n    }\n};\n\nproto.dispose = function() {\n    var map = this.subplot.map;\n    map.removeLayer(this.idLayer);\n    map.removeSource(this.idSource);\n};\n\nfunction isVisible(opts) {\n    var source = opts.source;\n\n    return opts.visible && (\n        Lib.isPlainObject(source) ||\n        ((typeof source === 'string' || Array.isArray(source)) && source.length > 0)\n    );\n}\n\nfunction convertOpts(opts) {\n    var layout = {};\n    var paint = {};\n\n    switch(opts.type) {\n        case 'circle':\n            Lib.extendFlat(paint, {\n                'circle-radius': opts.circle.radius,\n                'circle-color': opts.color,\n                'circle-opacity': opts.opacity\n            });\n            break;\n\n        case 'line':\n            Lib.extendFlat(paint, {\n                'line-width': opts.line.width,\n                'line-color': opts.color,\n                'line-opacity': opts.opacity,\n                'line-dasharray': opts.line.dash\n            });\n            break;\n\n        case 'fill':\n            Lib.extendFlat(paint, {\n                'fill-color': opts.color,\n                'fill-outline-color': opts.fill.outlinecolor,\n                'fill-opacity': opts.opacity\n\n                // no way to pass specify outline width at the moment\n            });\n            break;\n\n        case 'symbol':\n            var symbol = opts.symbol;\n            var textOpts = convertTextOpts(symbol.textposition, symbol.iconsize);\n\n            Lib.extendFlat(layout, {\n                'icon-image': symbol.icon + '-15',\n                'icon-size': symbol.iconsize / 10,\n\n                'text-field': symbol.text,\n                'text-size': symbol.textfont.size,\n                'text-anchor': textOpts.anchor,\n                'text-offset': textOpts.offset,\n                'symbol-placement': symbol.placement,\n\n                // TODO font family\n                // 'text-font': symbol.textfont.family.split(', '),\n            });\n\n            Lib.extendFlat(paint, {\n                'icon-color': opts.color,\n                'text-color': symbol.textfont.color,\n                'text-opacity': opts.opacity\n            });\n            break;\n    }\n\n    return {\n        layout: layout,\n        paint: paint\n    };\n}\n\nfunction convertSourceOpts(opts) {\n    var sourceType = opts.sourcetype;\n    var source = opts.source;\n    var sourceOpts = {type: sourceType};\n    var field;\n\n    if(sourceType === 'geojson') {\n        field = 'data';\n    } else if(sourceType === 'vector') {\n        field = typeof source === 'string' ? 'url' : 'tiles';\n    } else if(sourceType === 'raster') {\n        field = 'tiles';\n        sourceOpts.tileSize = 256;\n    } else if(sourceType === 'image') {\n        field = 'url';\n        sourceOpts.coordinates = opts.coordinates;\n    }\n\n    sourceOpts[field] = source;\n\n    if(opts.sourceattribution) sourceOpts.attribution = opts.sourceattribution;\n\n    return sourceOpts;\n}\n\nmodule.exports = function createMapboxLayer(subplot, index, opts) {\n    var mapboxLayer = new MapboxLayer(subplot, index);\n\n    mapboxLayer.update(opts);\n\n    return mapboxLayer;\n};\n\n},{\"../../lib\":719,\"./constants\":820,\"./convert_text_opts\":821}],824:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar defaultLine = _dereq_('../../components/color').defaultLine;\nvar domainAttrs = _dereq_('../domain').attributes;\nvar fontAttrs = _dereq_('../font_attributes');\nvar textposition = _dereq_('../../traces/scatter/attributes').textposition;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\nvar constants = _dereq_('./constants');\n\nvar fontAttr = fontAttrs({\n    \n});\nfontAttr.family.dflt = 'Open Sans Regular, Arial Unicode MS Regular';\n\nvar attrs = module.exports = overrideAll({\n    _arrayAttrRegexps: [Lib.counterRegex('mapbox', '.layers', true)],\n\n    domain: domainAttrs({name: 'mapbox'}),\n\n    accesstoken: {\n        valType: 'string',\n        noBlank: true,\n        strict: true,\n        \n        \n    },\n    style: {\n        valType: 'any',\n        values: constants.styleValuesMapbox.concat(Object.keys(constants.styleValuesNonMapbox)),\n        dflt: constants.styleValueDflt,\n        \n        \n    },\n\n    center: {\n        lon: {\n            valType: 'number',\n            dflt: 0,\n            \n            \n        },\n        lat: {\n            valType: 'number',\n            dflt: 0,\n            \n            \n        }\n    },\n    zoom: {\n        valType: 'number',\n        dflt: 1,\n        \n        \n    },\n    bearing: {\n        valType: 'number',\n        dflt: 0,\n        \n        \n    },\n    pitch: {\n        valType: 'number',\n        dflt: 0,\n        \n        \n    },\n\n    layers: templatedArray('layer', {\n        visible: {\n            valType: 'boolean',\n            \n            dflt: true,\n            \n        },\n        sourcetype: {\n            valType: 'enumerated',\n            values: ['geojson', 'vector', 'raster', 'image'],\n            dflt: 'geojson',\n            \n            \n        },\n\n        source: {\n            valType: 'any',\n            \n            \n        },\n\n        sourcelayer: {\n            valType: 'string',\n            dflt: '',\n            \n            \n        },\n\n        sourceattribution: {\n            valType: 'string',\n            \n            \n        },\n\n        type: {\n            valType: 'enumerated',\n            values: ['circle', 'line', 'fill', 'symbol', 'raster'],\n            dflt: 'circle',\n            \n            \n        },\n\n        coordinates: {\n            valType: 'any',\n            \n            \n        },\n\n        // attributes shared between all types\n        below: {\n            valType: 'string',\n            \n            \n        },\n        color: {\n            valType: 'color',\n            dflt: defaultLine,\n            \n            \n        },\n        opacity: {\n            valType: 'number',\n            min: 0,\n            max: 1,\n            dflt: 1,\n            \n            \n        },\n        minzoom: {\n            valType: 'number',\n            min: 0,\n            max: 24,\n            dflt: 0,\n            \n            \n        },\n        maxzoom: {\n            valType: 'number',\n            min: 0,\n            max: 24,\n            dflt: 24,\n            \n            \n        },\n\n        // type-specific style attributes\n        circle: {\n            radius: {\n                valType: 'number',\n                dflt: 15,\n                \n                \n            }\n        },\n\n        line: {\n            width: {\n                valType: 'number',\n                dflt: 2,\n                \n                \n            },\n            dash: {\n                valType: 'data_array',\n                \n                \n            }\n        },\n\n        fill: {\n            outlinecolor: {\n                valType: 'color',\n                dflt: defaultLine,\n                \n                \n            }\n        },\n\n        symbol: {\n            icon: {\n                valType: 'string',\n                dflt: 'marker',\n                \n                \n            },\n            iconsize: {\n                valType: 'number',\n                dflt: 10,\n                \n                \n            },\n            text: {\n                valType: 'string',\n                dflt: '',\n                \n                \n            },\n            placement: {\n                valType: 'enumerated',\n                values: ['point', 'line', 'line-center'],\n                dflt: 'point',\n                \n                \n            },\n            textfont: fontAttr,\n            textposition: Lib.extendFlat({}, textposition, { arrayOk: false })\n        }\n    })\n}, 'plot', 'from-root');\n\n// set uirevision outside of overrideAll so it can be `editType: 'none'`\nattrs.uirevision = {\n    valType: 'any',\n    \n    editType: 'none',\n    \n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../../plot_api/edit_types\":750,\"../../plot_api/plot_template\":757,\"../../traces/scatter/attributes\":1112,\"../domain\":792,\"../font_attributes\":793,\"./constants\":820}],825:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleSubplotDefaults = _dereq_('../subplot_defaults');\nvar handleArrayContainerDefaults = _dereq_('../array_container_defaults');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    handleSubplotDefaults(layoutIn, layoutOut, fullData, {\n        type: 'mapbox',\n        attributes: layoutAttributes,\n        handleDefaults: handleDefaults,\n        partition: 'y',\n        accessToken: layoutOut._mapboxAccessToken\n    });\n};\n\nfunction handleDefaults(containerIn, containerOut, coerce, opts) {\n    coerce('accesstoken', opts.accessToken);\n    coerce('style');\n    coerce('center.lon');\n    coerce('center.lat');\n    coerce('zoom');\n    coerce('bearing');\n    coerce('pitch');\n\n    handleArrayContainerDefaults(containerIn, containerOut, {\n        name: 'layers',\n        handleItemDefaults: handleLayerDefaults\n    });\n\n    // copy ref to input container to update 'center' and 'zoom' on map move\n    containerOut._input = containerIn;\n}\n\nfunction handleLayerDefaults(layerIn, layerOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layerIn, layerOut, layoutAttributes.layers, attr, dflt);\n    }\n\n    var visible = coerce('visible');\n    if(visible) {\n        var sourceType = coerce('sourcetype');\n        var mustBeRasterLayer = sourceType === 'raster' || sourceType === 'image';\n\n        coerce('source');\n        coerce('sourceattribution');\n\n        if(sourceType === 'vector') {\n            coerce('sourcelayer');\n        }\n\n        if(sourceType === 'image') {\n            coerce('coordinates');\n        }\n\n        var typeDflt;\n        if(mustBeRasterLayer) typeDflt = 'raster';\n\n        var type = coerce('type', typeDflt);\n\n        if(mustBeRasterLayer && type !== 'raster') {\n            type = layerOut.type = 'raster';\n            Lib.log('Source types *raster* and *image* must drawn *raster* layer type.');\n        }\n\n        coerce('below');\n        coerce('color');\n        coerce('opacity');\n        coerce('minzoom');\n        coerce('maxzoom');\n\n        if(type === 'circle') {\n            coerce('circle.radius');\n        }\n\n        if(type === 'line') {\n            coerce('line.width');\n            coerce('line.dash');\n        }\n\n        if(type === 'fill') {\n            coerce('fill.outlinecolor');\n        }\n\n        if(type === 'symbol') {\n            coerce('symbol.icon');\n            coerce('symbol.iconsize');\n\n            coerce('symbol.text');\n            Lib.coerceFont(coerce, 'symbol.textfont');\n            coerce('symbol.textposition');\n            coerce('symbol.placement');\n        }\n    }\n}\n\n},{\"../../lib\":719,\"../array_container_defaults\":763,\"../subplot_defaults\":842,\"./layout_attributes\":824}],826:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/* global PlotlyGeoAssets:false */\n\nvar mapboxgl = _dereq_('mapbox-gl');\nvar d3 = _dereq_('d3');\n\nvar Fx = _dereq_('../../components/fx');\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\nvar Axes = _dereq_('../cartesian/axes');\nvar dragElement = _dereq_('../../components/dragelement');\nvar prepSelect = _dereq_('../cartesian/select').prepSelect;\nvar selectOnClick = _dereq_('../cartesian/select').selectOnClick;\nvar constants = _dereq_('./constants');\nvar createMapboxLayer = _dereq_('./layers');\n\nfunction Mapbox(gd, id) {\n    this.id = id;\n    this.gd = gd;\n\n    var fullLayout = gd._fullLayout;\n    var context = gd._context;\n\n    this.container = fullLayout._glcontainer.node();\n    this.isStatic = context.staticPlot;\n\n    // unique id for this Mapbox instance\n    this.uid = fullLayout._uid + '-' + this.id;\n\n    // create framework on instantiation for a smoother first plot call\n    this.div = null;\n    this.xaxis = null;\n    this.yaxis = null;\n    this.createFramework(fullLayout);\n\n    // state variables used to infer how and what to update\n    this.map = null;\n    this.accessToken = null;\n    this.styleObj = null;\n    this.traceHash = {};\n    this.layerList = [];\n    this.belowLookup = {};\n}\n\nvar proto = Mapbox.prototype;\n\nproto.plot = function(calcData, fullLayout, promises) {\n    var self = this;\n    var opts = fullLayout[self.id];\n\n    // remove map and create a new map if access token has change\n    if(self.map && (opts.accesstoken !== self.accessToken)) {\n        self.map.remove();\n        self.map = null;\n        self.styleObj = null;\n        self.traceHash = [];\n        self.layerList = {};\n    }\n\n    var promise;\n\n    if(!self.map) {\n        promise = new Promise(function(resolve, reject) {\n            self.createMap(calcData, fullLayout, resolve, reject);\n        });\n    } else {\n        promise = new Promise(function(resolve, reject) {\n            self.updateMap(calcData, fullLayout, resolve, reject);\n        });\n    }\n\n    promises.push(promise);\n};\n\nproto.createMap = function(calcData, fullLayout, resolve, reject) {\n    var self = this;\n    var opts = fullLayout[self.id];\n\n    // store style id and URL or object\n    var styleObj = self.styleObj = getStyleObj(opts.style);\n\n    // store access token associated with this map\n    self.accessToken = opts.accesstoken;\n\n    // create the map!\n    var map = self.map = new mapboxgl.Map({\n        container: self.div,\n\n        style: styleObj.style,\n        center: convertCenter(opts.center),\n        zoom: opts.zoom,\n        bearing: opts.bearing,\n        pitch: opts.pitch,\n\n        interactive: !self.isStatic,\n        preserveDrawingBuffer: self.isStatic,\n\n        doubleClickZoom: false,\n        boxZoom: false,\n\n        attributionControl: false\n    })\n    .addControl(new mapboxgl.AttributionControl({\n        compact: true\n    }));\n\n\n    // make sure canvas does not inherit left and top css\n    map._canvas.style.left = '0px';\n    map._canvas.style.top = '0px';\n\n    self.rejectOnError(reject);\n\n    if(!self.isStatic) {\n        self.initFx(calcData, fullLayout);\n    }\n\n    var promises = [];\n\n    promises.push(new Promise(function(resolve) {\n        map.once('load', resolve);\n    }));\n\n    promises = promises.concat(self.fetchMapData(calcData, fullLayout));\n\n    Promise.all(promises).then(function() {\n        self.fillBelowLookup(calcData, fullLayout);\n        self.updateData(calcData);\n        self.updateLayout(fullLayout);\n        self.resolveOnRender(resolve);\n    }).catch(reject);\n};\n\nproto.fetchMapData = function(calcData) {\n    var promises = [];\n\n    function fetch(url) {\n        return new Promise(function(resolve, reject) {\n            d3.json(url, function(err, d) {\n                if(err) {\n                    delete PlotlyGeoAssets[url];\n                    var msg = err.status === 404 ?\n                        ('GeoJSON at URL \"' + url + '\" does not exist.') :\n                        ('Unexpected error while fetching from ' + url);\n                    return reject(new Error(msg));\n                }\n\n                PlotlyGeoAssets[url] = d;\n                resolve(d);\n            });\n        });\n    }\n\n    for(var i = 0; i < calcData.length; i++) {\n        var trace = calcData[i][0].trace;\n        var url = trace.geojson;\n\n        if(typeof url === 'string' && !PlotlyGeoAssets[url]) {\n            PlotlyGeoAssets[url] = 'pending';\n            promises.push(fetch(url));\n        }\n    }\n\n    return promises;\n};\n\nproto.updateMap = function(calcData, fullLayout, resolve, reject) {\n    var self = this;\n    var map = self.map;\n    var opts = fullLayout[this.id];\n\n    self.rejectOnError(reject);\n\n    var promises = [];\n    var styleObj = getStyleObj(opts.style);\n\n    if(self.styleObj.id !== styleObj.id) {\n        self.styleObj = styleObj;\n        map.setStyle(styleObj.style);\n\n        // need to rebuild trace layers on reload\n        // to avoid 'lost event' errors\n        self.traceHash = {};\n\n        promises.push(new Promise(function(resolve) {\n            map.once('styledata', resolve);\n        }));\n    }\n\n    promises = promises.concat(self.fetchMapData(calcData, fullLayout));\n\n    Promise.all(promises).then(function() {\n        self.fillBelowLookup(calcData, fullLayout);\n        self.updateData(calcData);\n        self.updateLayout(fullLayout);\n        self.resolveOnRender(resolve);\n    }).catch(reject);\n};\n\nproto.fillBelowLookup = function(calcData, fullLayout) {\n    var opts = fullLayout[this.id];\n    var layers = opts.layers;\n    var i, val;\n\n    var belowLookup = this.belowLookup = {};\n    var hasTraceAtTop = false;\n\n    for(i = 0; i < calcData.length; i++) {\n        var trace = calcData[i][0].trace;\n        var _module = trace._module;\n\n        if(typeof trace.below === 'string') {\n            val = trace.below;\n        } else if(_module.getBelow) {\n            // 'smart' default that depend the map's base layers\n            val = _module.getBelow(trace, this);\n        }\n\n        if(val === '') {\n            hasTraceAtTop = true;\n        }\n\n        belowLookup['trace-' + trace.uid] = val || '';\n    }\n\n    for(i = 0; i < layers.length; i++) {\n        var item = layers[i];\n\n        if(typeof item.below === 'string') {\n            val = item.below;\n        } else if(hasTraceAtTop) {\n            // if one or more trace(s) set `below:''` and\n            // layers[i].below is unset,\n            // place layer below traces\n            val = 'traces';\n        } else {\n            val = '';\n        }\n\n        belowLookup['layout-' + i] = val;\n    }\n\n    // N.B. If multiple layers have the 'below' value,\n    // we must clear the stashed 'below' field in order\n    // to make `traceHash[k].update()` and `layerList[i].update()`\n    // remove/add the all those layers to have preserve\n    // the correct layer ordering\n    var val2list = {};\n    var k, id;\n\n    for(k in belowLookup) {\n        val = belowLookup[k];\n        if(val2list[val]) {\n            val2list[val].push(k);\n        } else {\n            val2list[val] = [k];\n        }\n    }\n\n    for(val in val2list) {\n        var list = val2list[val];\n        if(list.length > 1) {\n            for(i = 0; i < list.length; i++) {\n                k = list[i];\n                if(k.indexOf('trace-') === 0) {\n                    id = k.split('trace-')[1];\n                    if(this.traceHash[id]) {\n                        this.traceHash[id].below = null;\n                    }\n                } else if(k.indexOf('layout-') === 0) {\n                    id = k.split('layout-')[1];\n                    if(this.layerList[id]) {\n                        this.layerList[id].below = null;\n                    }\n                }\n            }\n        }\n    }\n};\n\nvar traceType2orderIndex = {\n    choroplethmapbox: 0,\n    densitymapbox: 1,\n    scattermapbox: 2\n};\n\nproto.updateData = function(calcData) {\n    var traceHash = this.traceHash;\n    var traceObj, trace, i, j;\n\n    // Need to sort here by trace type here,\n    // in case traces with different `type` have the same\n    // below value, but sorting we ensure that\n    // e.g. choroplethmapbox traces will be below scattermapbox traces\n    var calcDataSorted = calcData.slice().sort(function(a, b) {\n        return (\n            traceType2orderIndex[a[0].trace.type] -\n            traceType2orderIndex[b[0].trace.type]\n        );\n    });\n\n    // update or create trace objects\n    for(i = 0; i < calcDataSorted.length; i++) {\n        var calcTrace = calcDataSorted[i];\n\n        trace = calcTrace[0].trace;\n        traceObj = traceHash[trace.uid];\n\n        if(traceObj) {\n            traceObj.update(calcTrace);\n        } else if(trace._module) {\n            traceHash[trace.uid] = trace._module.plot(this, calcTrace);\n        }\n    }\n\n    // remove empty trace objects\n    var ids = Object.keys(traceHash);\n    idLoop:\n    for(i = 0; i < ids.length; i++) {\n        var id = ids[i];\n\n        for(j = 0; j < calcData.length; j++) {\n            trace = calcData[j][0].trace;\n            if(id === trace.uid) continue idLoop;\n        }\n\n        traceObj = traceHash[id];\n        traceObj.dispose();\n        delete traceHash[id];\n    }\n};\n\nproto.updateLayout = function(fullLayout) {\n    var map = this.map;\n    var opts = fullLayout[this.id];\n\n    map.setCenter(convertCenter(opts.center));\n    map.setZoom(opts.zoom);\n    map.setBearing(opts.bearing);\n    map.setPitch(opts.pitch);\n\n    this.updateLayers(fullLayout);\n    this.updateFramework(fullLayout);\n    this.updateFx(fullLayout);\n    this.map.resize();\n\n    if(this.gd._context._scrollZoom.mapbox) {\n        map.scrollZoom.enable();\n    } else {\n        map.scrollZoom.disable();\n    }\n};\n\nproto.resolveOnRender = function(resolve) {\n    var map = this.map;\n\n    map.on('render', function onRender() {\n        if(map.loaded()) {\n            map.off('render', onRender);\n            // resolve at end of render loop\n            setTimeout(resolve, 0);\n        }\n    });\n};\n\nproto.rejectOnError = function(reject) {\n    var map = this.map;\n\n    function handler() {\n        reject(new Error(constants.mapOnErrorMsg));\n    }\n\n    map.once('error', handler);\n    map.once('style.error', handler);\n    map.once('source.error', handler);\n    map.once('tile.error', handler);\n    map.once('layer.error', handler);\n};\n\nproto.createFramework = function(fullLayout) {\n    var self = this;\n\n    var div = self.div = document.createElement('div');\n    div.id = self.uid;\n    div.style.position = 'absolute';\n    self.container.appendChild(div);\n\n    // create mock x/y axes for hover routine\n    self.xaxis = {\n        _id: 'x',\n        c2p: function(v) { return self.project(v).x; }\n    };\n    self.yaxis = {\n        _id: 'y',\n        c2p: function(v) { return self.project(v).y; }\n    };\n\n    self.updateFramework(fullLayout);\n\n    // mock axis for hover formatting\n    self.mockAxis = {\n        type: 'linear',\n        showexponent: 'all',\n        exponentformat: 'B'\n    };\n    Axes.setConvert(self.mockAxis, fullLayout);\n};\n\nproto.initFx = function(calcData, fullLayout) {\n    var self = this;\n    var gd = self.gd;\n    var map = self.map;\n\n    var wheeling = false;\n\n    // keep track of pan / zoom in user layout and emit relayout event\n    map.on('moveend', function(evt) {\n        if(!self.map) return;\n\n        var fullLayoutNow = gd._fullLayout;\n\n        // 'moveend' gets triggered by map.setCenter, map.setZoom,\n        // map.setBearing and map.setPitch.\n        //\n        // Here, we make sure that state updates amd 'plotly_relayout'\n        // are triggered only when the 'moveend' originates from a\n        // mouse target (filtering out API calls) to not\n        // duplicate 'plotly_relayout' events.\n\n        if(evt.originalEvent || wheeling) {\n            var optsNow = fullLayoutNow[self.id];\n            Registry.call('_storeDirectGUIEdit', gd.layout, fullLayoutNow._preGUI, self.getViewEdits(optsNow));\n\n            var viewNow = self.getView();\n            optsNow._input.center = optsNow.center = viewNow.center;\n            optsNow._input.zoom = optsNow.zoom = viewNow.zoom;\n            optsNow._input.bearing = optsNow.bearing = viewNow.bearing;\n            optsNow._input.pitch = optsNow.pitch = viewNow.pitch;\n\n            gd.emit('plotly_relayout', self.getViewEdits(viewNow));\n        }\n        wheeling = false;\n\n        if(fullLayoutNow._rehover) {\n            fullLayoutNow._rehover();\n        }\n    });\n\n    map.on('wheel', function() {\n        wheeling = true;\n    });\n\n    map.on('mousemove', function(evt) {\n        var bb = self.div.getBoundingClientRect();\n\n        // some hackery to get Fx.hover to work\n        evt.clientX = evt.point.x + bb.left;\n        evt.clientY = evt.point.y + bb.top;\n\n        evt.target.getBoundingClientRect = function() { return bb; };\n\n        self.xaxis.p2c = function() { return evt.lngLat.lng; };\n        self.yaxis.p2c = function() { return evt.lngLat.lat; };\n\n        gd._fullLayout._rehover = function() {\n            if(gd._fullLayout._hoversubplot === self.id) {\n                Fx.hover(gd, evt, self.id);\n            }\n        };\n\n        Fx.hover(gd, evt, self.id);\n        gd._fullLayout._hoversubplot = self.id;\n    });\n\n    function unhover() {\n        Fx.loneUnhover(fullLayout._hoverlayer);\n    }\n\n    map.on('dragstart', unhover);\n    map.on('zoomstart', unhover);\n\n    map.on('mouseout', function() {\n        gd._fullLayout._hoversubplot = null;\n    });\n\n    function emitUpdate() {\n        var viewNow = self.getView();\n        gd.emit('plotly_relayouting', self.getViewEdits(viewNow));\n    }\n\n    map.on('drag', emitUpdate);\n    map.on('zoom', emitUpdate);\n\n    map.on('dblclick', function() {\n        var optsNow = gd._fullLayout[self.id];\n        Registry.call('_storeDirectGUIEdit', gd.layout, gd._fullLayout._preGUI, self.getViewEdits(optsNow));\n\n        var viewInitial = self.viewInitial;\n        map.setCenter(convertCenter(viewInitial.center));\n        map.setZoom(viewInitial.zoom);\n        map.setBearing(viewInitial.bearing);\n        map.setPitch(viewInitial.pitch);\n\n        var viewNow = self.getView();\n        optsNow._input.center = optsNow.center = viewNow.center;\n        optsNow._input.zoom = optsNow.zoom = viewNow.zoom;\n        optsNow._input.bearing = optsNow.bearing = viewNow.bearing;\n        optsNow._input.pitch = optsNow.pitch = viewNow.pitch;\n\n        gd.emit('plotly_doubleclick', null);\n        gd.emit('plotly_relayout', self.getViewEdits(viewNow));\n    });\n\n    // define event handlers on map creation, to keep one ref per map,\n    // so that map.on / map.off in updateFx works as expected\n    self.clearSelect = function() {\n        gd._fullLayout._zoomlayer.selectAll('.select-outline').remove();\n    };\n\n    /**\n     * Returns a click handler function that is supposed\n     * to handle clicks in pan mode.\n     */\n    self.onClickInPanFn = function(dragOptions) {\n        return function(evt) {\n            var clickMode = gd._fullLayout.clickmode;\n\n            if(clickMode.indexOf('select') > -1) {\n                selectOnClick(evt.originalEvent, gd, [self.xaxis], [self.yaxis], self.id, dragOptions);\n            }\n\n            if(clickMode.indexOf('event') > -1) {\n                // TODO: this does not support right-click. If we want to support it, we\n                // would likely need to change mapbox to use dragElement instead of straight\n                // mapbox event binding. Or perhaps better, make a simple wrapper with the\n                // right mousedown, mousemove, and mouseup handlers just for a left/right click\n                // pie would use this too.\n                Fx.click(gd, evt.originalEvent);\n            }\n        };\n    };\n};\n\nproto.updateFx = function(fullLayout) {\n    var self = this;\n    var map = self.map;\n    var gd = self.gd;\n\n    if(self.isStatic) return;\n\n    function invert(pxpy) {\n        var obj = self.map.unproject(pxpy);\n        return [obj.lng, obj.lat];\n    }\n\n    var dragMode = fullLayout.dragmode;\n    var fillRangeItems;\n\n    if(dragMode === 'select') {\n        fillRangeItems = function(eventData, poly) {\n            var ranges = eventData.range = {};\n            ranges[self.id] = [\n                invert([poly.xmin, poly.ymin]),\n                invert([poly.xmax, poly.ymax])\n            ];\n        };\n    } else {\n        fillRangeItems = function(eventData, poly, pts) {\n            var dataPts = eventData.lassoPoints = {};\n            dataPts[self.id] = pts.filtered.map(invert);\n        };\n    }\n\n    // Note: dragOptions is needed to be declared for all dragmodes because\n    // it's the object that holds persistent selection state.\n    // Merge old dragOptions with new to keep possibly initialized\n    // persistent selection state.\n    var oldDragOptions = self.dragOptions;\n    self.dragOptions = Lib.extendDeep(oldDragOptions || {}, {\n        element: self.div,\n        gd: gd,\n        plotinfo: {\n            id: self.id,\n            xaxis: self.xaxis,\n            yaxis: self.yaxis,\n            fillRangeItems: fillRangeItems\n        },\n        xaxes: [self.xaxis],\n        yaxes: [self.yaxis],\n        subplot: self.id\n    });\n\n    // Unregister the old handler before potentially registering\n    // a new one. Otherwise multiple click handlers might\n    // be registered resulting in unwanted behavior.\n    map.off('click', self.onClickInPanHandler);\n    if(dragMode === 'select' || dragMode === 'lasso') {\n        map.dragPan.disable();\n        map.on('zoomstart', self.clearSelect);\n\n        self.dragOptions.prepFn = function(e, startX, startY) {\n            prepSelect(e, startX, startY, self.dragOptions, dragMode);\n        };\n\n        dragElement.init(self.dragOptions);\n    } else {\n        map.dragPan.enable();\n        map.off('zoomstart', self.clearSelect);\n        self.div.onmousedown = null;\n\n        // TODO: this does not support right-click. If we want to support it, we\n        // would likely need to change mapbox to use dragElement instead of straight\n        // mapbox event binding. Or perhaps better, make a simple wrapper with the\n        // right mousedown, mousemove, and mouseup handlers just for a left/right click\n        // pie would use this too.\n        self.onClickInPanHandler = self.onClickInPanFn(self.dragOptions);\n        map.on('click', self.onClickInPanHandler);\n    }\n};\n\nproto.updateFramework = function(fullLayout) {\n    var domain = fullLayout[this.id].domain;\n    var size = fullLayout._size;\n\n    var style = this.div.style;\n    style.width = size.w * (domain.x[1] - domain.x[0]) + 'px';\n    style.height = size.h * (domain.y[1] - domain.y[0]) + 'px';\n    style.left = size.l + domain.x[0] * size.w + 'px';\n    style.top = size.t + (1 - domain.y[1]) * size.h + 'px';\n\n    this.xaxis._offset = size.l + domain.x[0] * size.w;\n    this.xaxis._length = size.w * (domain.x[1] - domain.x[0]);\n\n    this.yaxis._offset = size.t + (1 - domain.y[1]) * size.h;\n    this.yaxis._length = size.h * (domain.y[1] - domain.y[0]);\n};\n\nproto.updateLayers = function(fullLayout) {\n    var opts = fullLayout[this.id];\n    var layers = opts.layers;\n    var layerList = this.layerList;\n    var i;\n\n    // if the layer arrays don't match,\n    // don't try to be smart,\n    // delete them all, and start all over.\n\n    if(layers.length !== layerList.length) {\n        for(i = 0; i < layerList.length; i++) {\n            layerList[i].dispose();\n        }\n\n        layerList = this.layerList = [];\n\n        for(i = 0; i < layers.length; i++) {\n            layerList.push(createMapboxLayer(this, i, layers[i]));\n        }\n    } else {\n        for(i = 0; i < layers.length; i++) {\n            layerList[i].update(layers[i]);\n        }\n    }\n};\n\nproto.destroy = function() {\n    if(this.map) {\n        this.map.remove();\n        this.map = null;\n        this.container.removeChild(this.div);\n    }\n};\n\nproto.toImage = function() {\n    this.map.stop();\n    return this.map.getCanvas().toDataURL();\n};\n\n// convenience wrapper to create set multiple layer\n// 'layout' or 'paint options at once.\nproto.setOptions = function(id, methodName, opts) {\n    for(var k in opts) {\n        this.map[methodName](id, k, opts[k]);\n    }\n};\n\nproto.getMapLayers = function() {\n    return this.map.getStyle().layers;\n};\n\n// convenience wrapper that first check in 'below' references\n// a layer that exist and then add the layer to the map,\nproto.addLayer = function(opts, below) {\n    var map = this.map;\n\n    if(typeof below === 'string') {\n        if(below === '') {\n            map.addLayer(opts, below);\n            return;\n        }\n\n        var mapLayers = this.getMapLayers();\n        for(var i = 0; i < mapLayers.length; i++) {\n            if(below === mapLayers[i].id) {\n                map.addLayer(opts, below);\n                return;\n            }\n        }\n\n        Lib.warn([\n            'Trying to add layer with *below* value',\n            below,\n            'referencing a layer that does not exist',\n            'or that does not yet exist.'\n        ].join(' '));\n    }\n\n    map.addLayer(opts);\n};\n\n// convenience method to project a [lon, lat] array to pixel coords\nproto.project = function(v) {\n    return this.map.project(new mapboxgl.LngLat(v[0], v[1]));\n};\n\n// get map's current view values in plotly.js notation\nproto.getView = function() {\n    var map = this.map;\n    var mapCenter = map.getCenter();\n    var center = { lon: mapCenter.lng, lat: mapCenter.lat };\n\n    return {\n        center: center,\n        zoom: map.getZoom(),\n        bearing: map.getBearing(),\n        pitch: map.getPitch()\n    };\n};\n\nproto.getViewEdits = function(cont) {\n    var id = this.id;\n    var keys = ['center', 'zoom', 'bearing', 'pitch'];\n    var obj = {};\n\n    for(var i = 0; i < keys.length; i++) {\n        var k = keys[i];\n        obj[id + '.' + k] = cont[k];\n    }\n\n    return obj;\n};\n\nfunction getStyleObj(val) {\n    var styleObj = {};\n\n    if(Lib.isPlainObject(val)) {\n        styleObj.id = val.id;\n        styleObj.style = val;\n    } else if(typeof val === 'string') {\n        styleObj.id = val;\n\n        if(constants.styleValuesMapbox.indexOf(val) !== -1) {\n            styleObj.style = convertStyleVal(val);\n        } else if(constants.stylesNonMapbox[val]) {\n            styleObj.style = constants.stylesNonMapbox[val];\n        } else {\n            styleObj.style = val;\n        }\n    } else {\n        styleObj.id = constants.styleValueDflt;\n        styleObj.style = convertStyleVal(constants.styleValueDflt);\n    }\n\n    styleObj.transition = {duration: 0, delay: 0};\n\n    return styleObj;\n}\n\n// if style is part of the 'official' mapbox values, add URL prefix and suffix\nfunction convertStyleVal(val) {\n    return constants.styleUrlPrefix + val + '-' + constants.styleUrlSuffix;\n}\n\nfunction convertCenter(center) {\n    return [center.lon, center.lat];\n}\n\nmodule.exports = Mapbox;\n\n},{\"../../components/dragelement\":611,\"../../components/fx\":632,\"../../lib\":719,\"../../registry\":847,\"../cartesian/axes\":767,\"../cartesian/select\":784,\"./constants\":820,\"./layers\":823,\"d3\":163,\"mapbox-gl\":426}],827:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * Creates a set of padding attributes.\n *\n * @param {object} opts\n *   @param {string} editType:\n *     the editType for all pieces of this padding definition\n *\n * @return {object} attributes object containing {t, r, b, l} as specified\n */\nmodule.exports = function(opts) {\n    var editType = opts.editType;\n    return {\n        t: {\n            valType: 'number',\n            dflt: 0,\n            \n            editType: editType,\n            \n        },\n        r: {\n            valType: 'number',\n            dflt: 0,\n            \n            editType: editType,\n            \n        },\n        b: {\n            valType: 'number',\n            dflt: 0,\n            \n            editType: editType,\n            \n        },\n        l: {\n            valType: 'number',\n            dflt: 0,\n            \n            editType: editType,\n            \n        },\n        editType: editType\n    };\n};\n\n},{}],828:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Registry = _dereq_('../registry');\nvar PlotSchema = _dereq_('../plot_api/plot_schema');\nvar Template = _dereq_('../plot_api/plot_template');\nvar Lib = _dereq_('../lib');\nvar Color = _dereq_('../components/color');\nvar BADNUM = _dereq_('../constants/numerical').BADNUM;\n\nvar axisIDs = _dereq_('./cartesian/axis_ids');\n\nvar animationAttrs = _dereq_('./animation_attributes');\nvar frameAttrs = _dereq_('./frame_attributes');\n\nvar relinkPrivateKeys = Lib.relinkPrivateKeys;\nvar _ = Lib._;\n\nvar plots = module.exports = {};\n\n// Expose registry methods on Plots for backward-compatibility\nLib.extendFlat(plots, Registry);\n\nplots.attributes = _dereq_('./attributes');\nplots.attributes.type.values = plots.allTypes;\nplots.fontAttrs = _dereq_('./font_attributes');\nplots.layoutAttributes = _dereq_('./layout_attributes');\n\n// TODO make this a plot attribute?\nplots.fontWeight = 'normal';\n\nvar transformsRegistry = plots.transformsRegistry;\n\nvar commandModule = _dereq_('./command');\nplots.executeAPICommand = commandModule.executeAPICommand;\nplots.computeAPICommandBindings = commandModule.computeAPICommandBindings;\nplots.manageCommandObserver = commandModule.manageCommandObserver;\nplots.hasSimpleAPICommandBindings = commandModule.hasSimpleAPICommandBindings;\n\n// in some cases the browser doesn't seem to know how big\n// the text is at first, so it needs to draw it,\n// then wait a little, then draw it again\nplots.redrawText = function(gd) {\n    gd = Lib.getGraphDiv(gd);\n\n    var fullLayout = gd._fullLayout || {};\n    var hasPolar = fullLayout._has && fullLayout._has('polar');\n    var hasLegacyPolar = !hasPolar && gd.data && gd.data[0] && gd.data[0].r;\n\n    // do not work if polar is present\n    if(hasLegacyPolar) return;\n\n    return new Promise(function(resolve) {\n        setTimeout(function() {\n            Registry.getComponentMethod('annotations', 'draw')(gd);\n            Registry.getComponentMethod('legend', 'draw')(gd);\n            Registry.getComponentMethod('colorbar', 'draw')(gd);\n            resolve(plots.previousPromises(gd));\n        }, 300);\n    });\n};\n\n// resize plot about the container size\nplots.resize = function(gd) {\n    gd = Lib.getGraphDiv(gd);\n\n    return new Promise(function(resolve, reject) {\n        if(!gd || Lib.isHidden(gd)) {\n            reject(new Error('Resize must be passed a displayed plot div element.'));\n        }\n\n        if(gd._redrawTimer) clearTimeout(gd._redrawTimer);\n\n        gd._redrawTimer = setTimeout(function() {\n            // return if there is nothing to resize or is hidden\n            if(!gd.layout || (gd.layout.width && gd.layout.height) || Lib.isHidden(gd)) {\n                resolve(gd);\n                return;\n            }\n\n            delete gd.layout.width;\n            delete gd.layout.height;\n\n            // autosizing doesn't count as a change that needs saving\n            var oldchanged = gd.changed;\n\n            // nor should it be included in the undo queue\n            gd.autoplay = true;\n\n            Registry.call('relayout', gd, {autosize: true}).then(function() {\n                gd.changed = oldchanged;\n                resolve(gd);\n            });\n        }, 100);\n    });\n};\n\n\n// for use in Lib.syncOrAsync, check if there are any\n// pending promises in this plot and wait for them\nplots.previousPromises = function(gd) {\n    if((gd._promises || []).length) {\n        return Promise.all(gd._promises)\n            .then(function() { gd._promises = []; });\n    }\n};\n\n/**\n * Adds the 'Edit chart' link.\n * Note that now Plotly.plot() calls this so it can regenerate whenever it replots\n *\n * Add source links to your graph inside the 'showSources' config argument.\n */\nplots.addLinks = function(gd) {\n    // Do not do anything if showLink and showSources are not set to true in config\n    if(!gd._context.showLink && !gd._context.showSources) return;\n\n    var fullLayout = gd._fullLayout;\n\n    var linkContainer = Lib.ensureSingle(fullLayout._paper, 'text', 'js-plot-link-container', function(s) {\n        s.style({\n            'font-family': '\"Open Sans\", Arial, sans-serif',\n            'font-size': '12px',\n            'fill': Color.defaultLine,\n            'pointer-events': 'all'\n        })\n        .each(function() {\n            var links = d3.select(this);\n            links.append('tspan').classed('js-link-to-tool', true);\n            links.append('tspan').classed('js-link-spacer', true);\n            links.append('tspan').classed('js-sourcelinks', true);\n        });\n    });\n\n    // The text node inside svg\n    var text = linkContainer.node();\n    var attrs = {y: fullLayout._paper.attr('height') - 9};\n\n    // If text's width is bigger than the layout\n    // Check that text is a child node or document.body\n    // because otherwise IE/Edge might throw an exception\n    // when calling getComputedTextLength().\n    // Apparently offsetParent is null for invisibles.\n    if(document.body.contains(text) && text.getComputedTextLength() >= (fullLayout.width - 20)) {\n        // Align the text at the left\n        attrs['text-anchor'] = 'start';\n        attrs.x = 5;\n    } else {\n        // Align the text at the right\n        attrs['text-anchor'] = 'end';\n        attrs.x = fullLayout._paper.attr('width') - 7;\n    }\n\n    linkContainer.attr(attrs);\n\n    var toolspan = linkContainer.select('.js-link-to-tool');\n    var spacespan = linkContainer.select('.js-link-spacer');\n    var sourcespan = linkContainer.select('.js-sourcelinks');\n\n    if(gd._context.showSources) gd._context.showSources(gd);\n\n    // 'view in plotly' link for embedded plots\n    if(gd._context.showLink) positionPlayWithData(gd, toolspan);\n\n    // separator if we have both sources and tool link\n    spacespan.text((toolspan.text() && sourcespan.text()) ? ' - ' : '');\n};\n\n// note that now this function is only adding the brand in\n// iframes and 3rd-party apps\nfunction positionPlayWithData(gd, container) {\n    container.text('');\n    var link = container.append('a')\n        .attr({\n            'xlink:xlink:href': '#',\n            'class': 'link--impt link--embedview',\n            'font-weight': 'bold'\n        })\n        .text(gd._context.linkText + ' ' + String.fromCharCode(187));\n\n    if(gd._context.sendData) {\n        link.on('click', function() {\n            plots.sendDataToCloud(gd);\n        });\n    } else {\n        var path = window.location.pathname.split('/');\n        var query = window.location.search;\n        link.attr({\n            'xlink:xlink:show': 'new',\n            'xlink:xlink:href': '/' + path[2].split('.')[0] + '/' + path[1] + query\n        });\n    }\n}\n\nplots.sendDataToCloud = function(gd) {\n    gd.emit('plotly_beforeexport');\n\n    var baseUrl = (window.PLOTLYENV || {}).BASE_URL || gd._context.plotlyServerURL;\n\n    var hiddenformDiv = d3.select(gd)\n        .append('div')\n        .attr('id', 'hiddenform')\n        .style('display', 'none');\n\n    var hiddenform = hiddenformDiv\n        .append('form')\n        .attr({\n            action: baseUrl + '/external',\n            method: 'post',\n            target: '_blank'\n        });\n\n    var hiddenformInput = hiddenform\n        .append('input')\n        .attr({\n            type: 'text',\n            name: 'data'\n        });\n\n    hiddenformInput.node().value = plots.graphJson(gd, false, 'keepdata');\n    hiddenform.node().submit();\n    hiddenformDiv.remove();\n\n    gd.emit('plotly_afterexport');\n    return false;\n};\n\nvar d3FormatKeys = [\n    'days', 'shortDays', 'months', 'shortMonths', 'periods',\n    'dateTime', 'date', 'time',\n    'decimal', 'thousands', 'grouping', 'currency'\n];\n\nvar extraFormatKeys = [\n    'year', 'month', 'dayMonth', 'dayMonthYear'\n];\n\n/*\n * Fill in default values\n * @param {DOM element} gd\n * @param {object} opts\n * @param {boolean} opts.skipUpdateCalc: normally if the existing gd.calcdata looks\n *   compatible with the new gd._fullData we finish by linking the new _fullData traces\n *   to the old gd.calcdata, so it's correctly set if we're not going to recalc. But also,\n *   if there are calcTransforms on the trace, we first remap data arrays from the old full\n *   trace into the new one. Use skipUpdateCalc to defer this (needed by Plotly.react)\n *\n * gd.data, gd.layout:\n *   are precisely what the user specified (except as modified by cleanData/cleanLayout),\n *   these fields shouldn't be modified (except for filling in some auto values)\n *   nor used directly after the supply defaults step.\n *\n * gd._fullData, gd._fullLayout:\n *   are complete descriptions of how to draw the plot,\n *   use these fields in all required computations.\n *\n * gd._fullLayout._modules\n *   is a list of all the trace modules required to draw the plot.\n *\n * gd._fullLayout._visibleModules\n *   subset of _modules, a list of modules corresponding to visible:true traces.\n *\n * gd._fullLayout._basePlotModules\n *   is a list of all the plot modules required to draw the plot.\n *\n * gd._fullLayout._transformModules\n *   is a list of all the transform modules invoked.\n *\n */\nplots.supplyDefaults = function(gd, opts) {\n    var skipUpdateCalc = opts && opts.skipUpdateCalc;\n    var oldFullLayout = gd._fullLayout || {};\n\n    if(oldFullLayout._skipDefaults) {\n        delete oldFullLayout._skipDefaults;\n        return;\n    }\n\n    var newFullLayout = gd._fullLayout = {};\n    var newLayout = gd.layout || {};\n\n    var oldFullData = gd._fullData || [];\n    var newFullData = gd._fullData = [];\n    var newData = gd.data || [];\n\n    var oldCalcdata = gd.calcdata || [];\n\n    var context = gd._context || {};\n\n    var i;\n\n    // Create all the storage space for frames, but only if doesn't already exist\n    if(!gd._transitionData) plots.createTransitionData(gd);\n\n    // So we only need to do this once (and since we have gd here)\n    // get the translated placeholder titles.\n    // These ones get used as default values so need to be known at supplyDefaults\n    // others keep their blank defaults but render the placeholder as desired later\n    // TODO: make these work the same way, only inserting the placeholder text at draw time?\n    // The challenge is that this has slightly different behavior right now in editable mode:\n    // using the placeholder as default makes this text permanently (but lightly) visible,\n    // but explicit '' for these titles gives you a placeholder that's hidden until you mouse\n    // over it - so you're not distracted by it if you really don't want a title, but if you do\n    // and you're new to plotly you may not be able to find it.\n    // When editable=false the two behave the same, no title is drawn.\n    newFullLayout._dfltTitle = {\n        plot: _(gd, 'Click to enter Plot title'),\n        x: _(gd, 'Click to enter X axis title'),\n        y: _(gd, 'Click to enter Y axis title'),\n        colorbar: _(gd, 'Click to enter Colorscale title'),\n        annotation: _(gd, 'new text')\n    };\n    newFullLayout._traceWord = _(gd, 'trace');\n\n    var formatObj = getFormatObj(gd, d3FormatKeys);\n\n    // stash the token from context so mapbox subplots can use it as default\n    newFullLayout._mapboxAccessToken = context.mapboxAccessToken;\n\n    // first fill in what we can of layout without looking at data\n    // because fullData needs a few things from layout\n    if(oldFullLayout._initialAutoSizeIsDone) {\n        // coerce the updated layout while preserving width and height\n        var oldWidth = oldFullLayout.width;\n        var oldHeight = oldFullLayout.height;\n\n        plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout, formatObj);\n\n        if(!newLayout.width) newFullLayout.width = oldWidth;\n        if(!newLayout.height) newFullLayout.height = oldHeight;\n        plots.sanitizeMargins(newFullLayout);\n    } else {\n        // coerce the updated layout and autosize if needed\n        plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout, formatObj);\n\n        var missingWidthOrHeight = (!newLayout.width || !newLayout.height);\n        var autosize = newFullLayout.autosize;\n        var autosizable = context.autosizable;\n        var initialAutoSize = missingWidthOrHeight && (autosize || autosizable);\n\n        if(initialAutoSize) plots.plotAutoSize(gd, newLayout, newFullLayout);\n        else if(missingWidthOrHeight) plots.sanitizeMargins(newFullLayout);\n\n        // for backwards-compatibility with Plotly v1.x.x\n        if(!autosize && missingWidthOrHeight) {\n            newLayout.width = newFullLayout.width;\n            newLayout.height = newFullLayout.height;\n        }\n    }\n\n    newFullLayout._d3locale = getFormatter(formatObj, newFullLayout.separators);\n    newFullLayout._extraFormat = getFormatObj(gd, extraFormatKeys);\n\n    newFullLayout._initialAutoSizeIsDone = true;\n\n    // keep track of how many traces are inputted\n    newFullLayout._dataLength = newData.length;\n\n    // clear the lists of trace and baseplot modules, and subplots\n    newFullLayout._modules = [];\n    newFullLayout._visibleModules = [];\n    newFullLayout._basePlotModules = [];\n    var subplots = newFullLayout._subplots = emptySubplotLists();\n\n    // initialize axis and subplot hash objects for splom-generated grids\n    var splomAxes = newFullLayout._splomAxes = {x: {}, y: {}};\n    var splomSubplots = newFullLayout._splomSubplots = {};\n    // initialize splom grid defaults\n    newFullLayout._splomGridDflt = {};\n\n    // for stacked area traces to share config across traces\n    newFullLayout._scatterStackOpts = {};\n    // for the first scatter trace on each subplot (so it knows tonext->tozero)\n    newFullLayout._firstScatter = {};\n    // for grouped bar/box/violin trace to share config across traces\n    newFullLayout._alignmentOpts = {};\n    // track color axes referenced in the data\n    newFullLayout._colorAxes = {};\n\n    // for traces to request a default rangeslider on their x axes\n    // eg set `_requestRangeslider.x2 = true` for xaxis2\n    newFullLayout._requestRangeslider = {};\n\n    // pull uids from old data to use as new defaults\n    newFullLayout._traceUids = getTraceUids(oldFullData, newData);\n\n    // then do the data\n    newFullLayout._globalTransforms = (gd._context || {}).globalTransforms;\n    plots.supplyDataDefaults(newData, newFullData, newLayout, newFullLayout);\n\n    // redo grid size defaults with info about splom x/y axes,\n    // and fill in generated cartesian axes and subplots\n    var splomXa = Object.keys(splomAxes.x);\n    var splomYa = Object.keys(splomAxes.y);\n    if(splomXa.length > 1 && splomYa.length > 1) {\n        Registry.getComponentMethod('grid', 'sizeDefaults')(newLayout, newFullLayout);\n\n        for(i = 0; i < splomXa.length; i++) {\n            Lib.pushUnique(subplots.xaxis, splomXa[i]);\n        }\n        for(i = 0; i < splomYa.length; i++) {\n            Lib.pushUnique(subplots.yaxis, splomYa[i]);\n        }\n        for(var k in splomSubplots) {\n            Lib.pushUnique(subplots.cartesian, k);\n        }\n    }\n\n    // attach helper method to check whether a plot type is present on graph\n    newFullLayout._has = plots._hasPlotType.bind(newFullLayout);\n\n    if(oldFullData.length === newFullData.length) {\n        for(i = 0; i < newFullData.length; i++) {\n            relinkPrivateKeys(newFullData[i], oldFullData[i]);\n        }\n    }\n\n    // finally, fill in the pieces of layout that may need to look at data\n    plots.supplyLayoutModuleDefaults(newLayout, newFullLayout, newFullData, gd._transitionData);\n\n    // Special cases that introduce interactions between traces.\n    // This is after relinkPrivateKeys so we can use those in crossTraceDefaults\n    // and after layout module defaults, so we can use eg barmode\n    var _modules = newFullLayout._visibleModules;\n    var crossTraceDefaultsFuncs = [];\n    for(i = 0; i < _modules.length; i++) {\n        var funci = _modules[i].crossTraceDefaults;\n        // some trace types share crossTraceDefaults (ie histogram2d, histogram2dcontour)\n        if(funci) Lib.pushUnique(crossTraceDefaultsFuncs, funci);\n    }\n    for(i = 0; i < crossTraceDefaultsFuncs.length; i++) {\n        crossTraceDefaultsFuncs[i](newFullData, newFullLayout);\n    }\n\n    // turn on flag to optimize large splom-only graphs\n    // mostly by omitting SVG layers during Cartesian.drawFramework\n    newFullLayout._hasOnlyLargeSploms = (\n        newFullLayout._basePlotModules.length === 1 &&\n        newFullLayout._basePlotModules[0].name === 'splom' &&\n        splomXa.length > 15 &&\n        splomYa.length > 15 &&\n        newFullLayout.shapes.length === 0 &&\n        newFullLayout.images.length === 0\n    );\n\n    // TODO remove in v2.0.0\n    // add has-plot-type refs to fullLayout for backward compatibility\n    newFullLayout._hasCartesian = newFullLayout._has('cartesian');\n    newFullLayout._hasGeo = newFullLayout._has('geo');\n    newFullLayout._hasGL3D = newFullLayout._has('gl3d');\n    newFullLayout._hasGL2D = newFullLayout._has('gl2d');\n    newFullLayout._hasTernary = newFullLayout._has('ternary');\n    newFullLayout._hasPie = newFullLayout._has('pie');\n\n    // relink / initialize subplot axis objects\n    plots.linkSubplots(newFullData, newFullLayout, oldFullData, oldFullLayout);\n\n    // clean subplots and other artifacts from previous plot calls\n    plots.cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout);\n\n    // clear selection outline until we implement persistent selection,\n    // don't clear them though when drag handlers (e.g. listening to\n    // `plotly_selecting`) update the graph.\n    // we should try to come up with a better solution when implementing\n    // https://github.com/plotly/plotly.js/issues/1851\n    if(oldFullLayout._zoomlayer && !gd._dragging) {\n        oldFullLayout._zoomlayer.selectAll('.select-outline').remove();\n    }\n\n\n    // fill in meta helpers\n    fillMetaTextHelpers(newFullData, newFullLayout);\n\n    // relink functions and _ attributes to promote consistency between plots\n    relinkPrivateKeys(newFullLayout, oldFullLayout);\n\n    // colorscale crossTraceDefaults needs newFullLayout with relinked keys\n    Registry.getComponentMethod('colorscale', 'crossTraceDefaults')(newFullData, newFullLayout);\n\n    // For persisting GUI-driven changes in layout\n    // _preGUI and _tracePreGUI were already copied over in relinkPrivateKeys\n    if(!newFullLayout._preGUI) newFullLayout._preGUI = {};\n    // track trace GUI changes by uid rather than by trace index\n    if(!newFullLayout._tracePreGUI) newFullLayout._tracePreGUI = {};\n    var tracePreGUI = newFullLayout._tracePreGUI;\n    var uids = {};\n    var uid;\n    for(uid in tracePreGUI) uids[uid] = 'old';\n    for(i = 0; i < newFullData.length; i++) {\n        uid = newFullData[i]._fullInput.uid;\n        if(!uids[uid]) tracePreGUI[uid] = {};\n        uids[uid] = 'new';\n    }\n    for(uid in uids) {\n        if(uids[uid] === 'old') delete tracePreGUI[uid];\n    }\n\n    // set up containers for margin calculations\n    initMargins(newFullLayout);\n\n    // collect and do some initial calculations for rangesliders\n    Registry.getComponentMethod('rangeslider', 'makeData')(newFullLayout);\n\n    // update object references in calcdata\n    if(!skipUpdateCalc && oldCalcdata.length === newFullData.length) {\n        plots.supplyDefaultsUpdateCalc(oldCalcdata, newFullData);\n    }\n};\n\nplots.supplyDefaultsUpdateCalc = function(oldCalcdata, newFullData) {\n    for(var i = 0; i < newFullData.length; i++) {\n        var newTrace = newFullData[i];\n        var cd0 = (oldCalcdata[i] || [])[0];\n        if(cd0 && cd0.trace) {\n            var oldTrace = cd0.trace;\n            if(oldTrace._hasCalcTransform) {\n                var arrayAttrs = oldTrace._arrayAttrs;\n                var j, astr, oldArrayVal;\n\n                for(j = 0; j < arrayAttrs.length; j++) {\n                    astr = arrayAttrs[j];\n                    oldArrayVal = Lib.nestedProperty(oldTrace, astr).get().slice();\n                    Lib.nestedProperty(newTrace, astr).set(oldArrayVal);\n                }\n            }\n            cd0.trace = newTrace;\n        }\n    }\n};\n\n/**\n * Create a list of uid strings satisfying (in this order of importance):\n * 1. all unique, all strings\n * 2. matches input uids if provided\n * 3. matches previous data uids\n */\nfunction getTraceUids(oldFullData, newData) {\n    var len = newData.length;\n    var oldFullInput = [];\n    var i, prevFullInput;\n    for(i = 0; i < oldFullData.length; i++) {\n        var thisFullInput = oldFullData[i]._fullInput;\n        if(thisFullInput !== prevFullInput) oldFullInput.push(thisFullInput);\n        prevFullInput = thisFullInput;\n    }\n    var oldLen = oldFullInput.length;\n    var out = new Array(len);\n    var seenUids = {};\n\n    function setUid(uid, i) {\n        out[i] = uid;\n        seenUids[uid] = 1;\n    }\n\n    function tryUid(uid, i) {\n        if(uid && typeof uid === 'string' && !seenUids[uid]) {\n            setUid(uid, i);\n            return true;\n        }\n    }\n\n    for(i = 0; i < len; i++) {\n        var newUid = newData[i].uid;\n        if(typeof newUid === 'number') newUid = String(newUid);\n\n        if(tryUid(newUid, i)) continue;\n        if(i < oldLen && tryUid(oldFullInput[i].uid, i)) continue;\n        setUid(Lib.randstr(seenUids), i);\n    }\n\n    return out;\n}\n\n/**\n * Make a container for collecting subplots we need to display.\n *\n * Finds all subplot types we need to enumerate once and caches it,\n * but makes a new output object each time.\n * Single-trace subplots (which have no `id`) such as pie, table, etc\n * do not need to be collected because we just draw all visible traces.\n */\nfunction emptySubplotLists() {\n    var collectableSubplotTypes = Registry.collectableSubplotTypes;\n    var out = {};\n    var i, j;\n\n    if(!collectableSubplotTypes) {\n        collectableSubplotTypes = [];\n\n        var subplotsRegistry = Registry.subplotsRegistry;\n\n        for(var subplotType in subplotsRegistry) {\n            var subplotModule = subplotsRegistry[subplotType];\n            var subplotAttr = subplotModule.attr;\n\n            if(subplotAttr) {\n                collectableSubplotTypes.push(subplotType);\n\n                // special case, currently just for cartesian:\n                // we need to enumerate axes, not just subplots\n                if(Array.isArray(subplotAttr)) {\n                    for(j = 0; j < subplotAttr.length; j++) {\n                        Lib.pushUnique(collectableSubplotTypes, subplotAttr[j]);\n                    }\n                }\n            }\n        }\n    }\n\n    for(i = 0; i < collectableSubplotTypes.length; i++) {\n        out[collectableSubplotTypes[i]] = [];\n    }\n    return out;\n}\n\n/**\n * getFormatObj: use _context to get the format object from locale.\n * Used to get d3.locale argument object and extraFormat argument object\n *\n * Regarding d3.locale argument :\n * decimal and thousands can be overridden later by layout.separators\n * grouping and currency are not presently used by our automatic number\n * formatting system but can be used by custom formats.\n *\n * @returns {object} d3.locale format object\n */\nfunction getFormatObj(gd, formatKeys) {\n    var locale = gd._context.locale;\n    if(!locale) locale === 'en-US';\n\n    var formatDone = false;\n    var formatObj = {};\n\n    function includeFormat(newFormat) {\n        var formatFinished = true;\n        for(var i = 0; i < formatKeys.length; i++) {\n            var formatKey = formatKeys[i];\n            if(!formatObj[formatKey]) {\n                if(newFormat[formatKey]) {\n                    formatObj[formatKey] = newFormat[formatKey];\n                } else formatFinished = false;\n            }\n        }\n        if(formatFinished) formatDone = true;\n    }\n\n    // same as localize, look for format parts in each format spec in the chain\n    for(var i = 0; i < 2; i++) {\n        var locales = gd._context.locales;\n        for(var j = 0; j < 2; j++) {\n            var formatj = (locales[locale] || {}).format;\n            if(formatj) {\n                includeFormat(formatj);\n                if(formatDone) break;\n            }\n            locales = Registry.localeRegistry;\n        }\n\n        var baseLocale = locale.split('-')[0];\n        if(formatDone || baseLocale === locale) break;\n        locale = baseLocale;\n    }\n\n    // lastly pick out defaults from english (non-US, as DMY is so much more common)\n    if(!formatDone) includeFormat(Registry.localeRegistry.en.format);\n\n    return formatObj;\n}\n\n/**\n * getFormatter: combine the final separators with the locale formatting object\n * we pulled earlier to generate number and time formatters\n * TODO: remove separators in v2, only use locale, so we don't need this step?\n *\n * @param {object} formatObj: d3.locale format object\n * @param {string} separators: length-2 string to override decimal and thousands\n *   separators in number formatting\n *\n * @returns {object} {numberFormat, timeFormat} d3 formatter factory functions\n *   for numbers and time\n */\nfunction getFormatter(formatObj, separators) {\n    formatObj.decimal = separators.charAt(0);\n    formatObj.thousands = separators.charAt(1);\n\n    return d3.locale(formatObj);\n}\n\nfunction fillMetaTextHelpers(newFullData, newFullLayout) {\n    var _meta;\n    var meta4data = [];\n\n    if(newFullLayout.meta) {\n        _meta = newFullLayout._meta = {\n            meta: newFullLayout.meta,\n            layout: {meta: newFullLayout.meta}\n        };\n    }\n\n    for(var i = 0; i < newFullData.length; i++) {\n        var trace = newFullData[i];\n\n        if(trace.meta) {\n            meta4data[trace.index] = trace._meta = {meta: trace.meta};\n        } else if(newFullLayout.meta) {\n            trace._meta = {meta: newFullLayout.meta};\n        }\n        if(newFullLayout.meta) {\n            trace._meta.layout = {meta: newFullLayout.meta};\n        }\n    }\n\n    if(meta4data.length) {\n        if(!_meta) {\n            _meta = newFullLayout._meta = {};\n        }\n        _meta.data = meta4data;\n    }\n}\n\n// Create storage for all of the data related to frames and transitions:\nplots.createTransitionData = function(gd) {\n    // Set up the default keyframe if it doesn't exist:\n    if(!gd._transitionData) {\n        gd._transitionData = {};\n    }\n\n    if(!gd._transitionData._frames) {\n        gd._transitionData._frames = [];\n    }\n\n    if(!gd._transitionData._frameHash) {\n        gd._transitionData._frameHash = {};\n    }\n\n    if(!gd._transitionData._counter) {\n        gd._transitionData._counter = 0;\n    }\n\n    if(!gd._transitionData._interruptCallbacks) {\n        gd._transitionData._interruptCallbacks = [];\n    }\n};\n\n// helper function to be bound to fullLayout to check\n// whether a certain plot type is present on plot\n// or trace has a category\nplots._hasPlotType = function(category) {\n    var i;\n\n    // check base plot modules\n    var basePlotModules = this._basePlotModules || [];\n    for(i = 0; i < basePlotModules.length; i++) {\n        if(basePlotModules[i].name === category) return true;\n    }\n\n    // check trace modules (including non-visible:true)\n    var modules = this._modules || [];\n    for(i = 0; i < modules.length; i++) {\n        var name = modules[i].name;\n        if(name === category) return true;\n        // N.B. this is modules[i] along with 'categories' as a hash object\n        var _module = Registry.modules[name];\n        if(_module && _module.categories[category]) return true;\n    }\n\n    return false;\n};\n\nplots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var i, j;\n\n    var basePlotModules = oldFullLayout._basePlotModules || [];\n    for(i = 0; i < basePlotModules.length; i++) {\n        var _module = basePlotModules[i];\n\n        if(_module.clean) {\n            _module.clean(newFullData, newFullLayout, oldFullData, oldFullLayout);\n        }\n    }\n\n    var hadGl = oldFullLayout._has && oldFullLayout._has('gl');\n    var hasGl = newFullLayout._has && newFullLayout._has('gl');\n\n    if(hadGl && !hasGl) {\n        if(oldFullLayout._glcontainer !== undefined) {\n            oldFullLayout._glcontainer.selectAll('.gl-canvas').remove();\n            oldFullLayout._glcontainer.selectAll('.no-webgl').remove();\n            oldFullLayout._glcanvas = null;\n        }\n    }\n\n    var hasInfoLayer = !!oldFullLayout._infolayer;\n\n    oldLoop:\n    for(i = 0; i < oldFullData.length; i++) {\n        var oldTrace = oldFullData[i];\n        var oldUid = oldTrace.uid;\n\n        for(j = 0; j < newFullData.length; j++) {\n            var newTrace = newFullData[j];\n\n            if(oldUid === newTrace.uid) continue oldLoop;\n        }\n\n        // clean old colorbars\n        if(hasInfoLayer) {\n            oldFullLayout._infolayer.select('.cb' + oldUid).remove();\n        }\n    }\n};\n\nplots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var i, j;\n\n    var oldSubplots = oldFullLayout._plots || {};\n    var newSubplots = newFullLayout._plots = {};\n    var newSubplotList = newFullLayout._subplots;\n\n    var mockGd = {\n        _fullData: newFullData,\n        _fullLayout: newFullLayout\n    };\n\n    var ids = newSubplotList.cartesian.concat(newSubplotList.gl2d || []);\n\n    for(i = 0; i < ids.length; i++) {\n        var id = ids[i];\n        var oldSubplot = oldSubplots[id];\n        var xaxis = axisIDs.getFromId(mockGd, id, 'x');\n        var yaxis = axisIDs.getFromId(mockGd, id, 'y');\n        var plotinfo;\n\n        // link or create subplot object\n        if(oldSubplot) {\n            plotinfo = newSubplots[id] = oldSubplot;\n        } else {\n            plotinfo = newSubplots[id] = {};\n            plotinfo.id = id;\n        }\n\n        // add these axis ids to each others' subplot lists\n        xaxis._counterAxes.push(yaxis._id);\n        yaxis._counterAxes.push(xaxis._id);\n        xaxis._subplotsWith.push(id);\n        yaxis._subplotsWith.push(id);\n\n        // update x and y axis layout object refs\n        plotinfo.xaxis = xaxis;\n        plotinfo.yaxis = yaxis;\n\n        // By default, we clip at the subplot level,\n        // but if one trace on a given subplot has *cliponaxis* set to false,\n        // we need to clip at the trace module layer level;\n        // find this out here, once of for all.\n        plotinfo._hasClipOnAxisFalse = false;\n\n        for(j = 0; j < newFullData.length; j++) {\n            var trace = newFullData[j];\n\n            if(\n                trace.xaxis === plotinfo.xaxis._id &&\n                trace.yaxis === plotinfo.yaxis._id &&\n                trace.cliponaxis === false\n            ) {\n                plotinfo._hasClipOnAxisFalse = true;\n                break;\n            }\n        }\n    }\n\n    // while we're at it, link overlaying axes to their main axes and\n    // anchored axes to the axes they're anchored to\n    var axList = axisIDs.list(mockGd, null, true);\n    var ax;\n    for(i = 0; i < axList.length; i++) {\n        ax = axList[i];\n        var mainAx = null;\n\n        if(ax.overlaying) {\n            mainAx = axisIDs.getFromId(mockGd, ax.overlaying);\n\n            // you cannot overlay an axis that's already overlaying another\n            if(mainAx && mainAx.overlaying) {\n                ax.overlaying = false;\n                mainAx = null;\n            }\n        }\n        ax._mainAxis = mainAx || ax;\n\n        /*\n         * For now force overlays to overlay completely... so they\n         * can drag together correctly and share backgrounds.\n         * Later perhaps we make separate axis domain and\n         * tick/line domain or something, so they can still share\n         * the (possibly larger) dragger and background but don't\n         * have to both be drawn over that whole domain\n         */\n        if(mainAx) ax.domain = mainAx.domain.slice();\n\n        ax._anchorAxis = ax.anchor === 'free' ?\n            null :\n            axisIDs.getFromId(mockGd, ax.anchor);\n    }\n\n    // finally, we can find the main subplot for each axis\n    // (on which the ticks & labels are drawn)\n    for(i = 0; i < axList.length; i++) {\n        ax = axList[i];\n        ax._counterAxes.sort(axisIDs.idSort);\n        ax._subplotsWith.sort(Lib.subplotSort);\n        ax._mainSubplot = findMainSubplot(ax, newFullLayout);\n    }\n};\n\nfunction findMainSubplot(ax, fullLayout) {\n    var mockGd = {_fullLayout: fullLayout};\n\n    var isX = ax._id.charAt(0) === 'x';\n    var anchorAx = ax._mainAxis._anchorAxis;\n    var mainSubplotID = '';\n    var nextBestMainSubplotID = '';\n    var anchorID = '';\n\n    // First try the main ID with the anchor\n    if(anchorAx) {\n        anchorID = anchorAx._mainAxis._id;\n        mainSubplotID = isX ? (ax._id + anchorID) : (anchorID + ax._id);\n    }\n\n    // Then look for a subplot with the counteraxis overlaying the anchor\n    // If that fails just use the first subplot including this axis\n    if(!mainSubplotID || !fullLayout._plots[mainSubplotID]) {\n        mainSubplotID = '';\n\n        var counterIDs = ax._counterAxes;\n        for(var j = 0; j < counterIDs.length; j++) {\n            var counterPart = counterIDs[j];\n            var id = isX ? (ax._id + counterPart) : (counterPart + ax._id);\n            if(!nextBestMainSubplotID) nextBestMainSubplotID = id;\n            var counterAx = axisIDs.getFromId(mockGd, counterPart);\n            if(anchorID && counterAx.overlaying === anchorID) {\n                mainSubplotID = id;\n                break;\n            }\n        }\n    }\n\n    return mainSubplotID || nextBestMainSubplotID;\n}\n\n// This function clears any trace attributes with valType: color and\n// no set dflt filed in the plot schema. This is needed because groupby (which\n// is the only transform for which this currently applies) supplies parent\n// trace defaults, then expanded trace defaults. The result is that `null`\n// colors are default-supplied and inherited as a color instead of a null.\n// The result is that expanded trace default colors have no effect, with\n// the final result that groups are indistinguishable. This function clears\n// those colors so that individual groupby groups get unique colors.\nplots.clearExpandedTraceDefaultColors = function(trace) {\n    var colorAttrs, path, i;\n\n    // This uses weird closure state in order to satisfy the linter rule\n    // that we can't create functions in a loop.\n    function locateColorAttrs(attr, attrName, attrs, level) {\n        path[level] = attrName;\n        path.length = level + 1;\n        if(attr.valType === 'color' && attr.dflt === undefined) {\n            colorAttrs.push(path.join('.'));\n        }\n    }\n\n    path = [];\n\n    // Get the cached colorAttrs:\n    colorAttrs = trace._module._colorAttrs;\n\n    // Or else compute and cache the colorAttrs on the module:\n    if(!colorAttrs) {\n        trace._module._colorAttrs = colorAttrs = [];\n        PlotSchema.crawl(\n            trace._module.attributes,\n            locateColorAttrs\n        );\n    }\n\n    for(i = 0; i < colorAttrs.length; i++) {\n        var origprop = Lib.nestedProperty(trace, '_input.' + colorAttrs[i]);\n\n        if(!origprop.get()) {\n            Lib.nestedProperty(trace, colorAttrs[i]).set(null);\n        }\n    }\n};\n\n\nplots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {\n    var modules = fullLayout._modules;\n    var visibleModules = fullLayout._visibleModules;\n    var basePlotModules = fullLayout._basePlotModules;\n    var cnt = 0;\n    var colorCnt = 0;\n\n    var i, fullTrace, trace;\n\n    fullLayout._transformModules = [];\n\n    function pushModule(fullTrace) {\n        dataOut.push(fullTrace);\n\n        var _module = fullTrace._module;\n        if(!_module) return;\n\n        Lib.pushUnique(modules, _module);\n        if(fullTrace.visible === true) Lib.pushUnique(visibleModules, _module);\n        Lib.pushUnique(basePlotModules, fullTrace._module.basePlotModule);\n        cnt++;\n\n        // TODO: do we really want color not to increment for explicitly invisible traces?\n        // This logic is weird, but matches previous behavior: traces that you explicitly\n        // set to visible:false do not increment the color, but traces WE determine to be\n        // empty or invalid (and thus set to visible:false) DO increment color.\n        // I kind of think we should just let all traces increment color, visible or not.\n        // see mock: axes-autotype-empty vs. a test of restyling visible: false that\n        // I can't find right now...\n        if(fullTrace._input.visible !== false) colorCnt++;\n    }\n\n    var carpetIndex = {};\n    var carpetDependents = [];\n    var dataTemplate = (layout.template || {}).data || {};\n    var templater = Template.traceTemplater(dataTemplate);\n\n    for(i = 0; i < dataIn.length; i++) {\n        trace = dataIn[i];\n\n        // reuse uid we may have pulled out of oldFullData\n        // Note: templater supplies trace type\n        fullTrace = templater.newTrace(trace);\n        fullTrace.uid = fullLayout._traceUids[i];\n        plots.supplyTraceDefaults(trace, fullTrace, colorCnt, fullLayout, i);\n\n        fullTrace.index = i;\n        fullTrace._input = trace;\n        fullTrace._expandedIndex = cnt;\n\n        if(fullTrace.transforms && fullTrace.transforms.length) {\n            var sdInvisible = trace.visible !== false && fullTrace.visible === false;\n\n            var expandedTraces = applyTransforms(fullTrace, dataOut, layout, fullLayout);\n\n            for(var j = 0; j < expandedTraces.length; j++) {\n                var expandedTrace = expandedTraces[j];\n\n                // No further templating during transforms.\n                var fullExpandedTrace = {\n                    _template: fullTrace._template,\n                    type: fullTrace.type,\n                    // set uid using parent uid and expanded index\n                    // to promote consistency between update calls\n                    uid: fullTrace.uid + j\n                };\n\n                // If the first supplyDefaults created `visible: false`,\n                // clear it before running supplyDefaults a second time,\n                // because sometimes there are items we still want to coerce\n                // inside trace modules before determining that the trace is\n                // again `visible: false`, for example partial visibilities\n                // in `splom` traces.\n                if(sdInvisible && expandedTrace.visible === false) {\n                    delete expandedTrace.visible;\n                }\n\n                plots.supplyTraceDefaults(expandedTrace, fullExpandedTrace, cnt, fullLayout, i);\n\n                // relink private (i.e. underscore) keys expanded trace to full expanded trace so\n                // that transform supply-default methods can set _ keys for future use.\n                relinkPrivateKeys(fullExpandedTrace, expandedTrace);\n\n                // add info about parent data trace\n                fullExpandedTrace.index = i;\n                fullExpandedTrace._input = trace;\n                fullExpandedTrace._fullInput = fullTrace;\n\n                // add info about the expanded data\n                fullExpandedTrace._expandedIndex = cnt;\n                fullExpandedTrace._expandedInput = expandedTrace;\n\n                pushModule(fullExpandedTrace);\n            }\n        } else {\n            // add identify refs for consistency with transformed traces\n            fullTrace._fullInput = fullTrace;\n            fullTrace._expandedInput = fullTrace;\n\n            pushModule(fullTrace);\n        }\n\n        if(Registry.traceIs(fullTrace, 'carpetAxis')) {\n            carpetIndex[fullTrace.carpet] = fullTrace;\n        }\n\n        if(Registry.traceIs(fullTrace, 'carpetDependent')) {\n            carpetDependents.push(i);\n        }\n    }\n\n    for(i = 0; i < carpetDependents.length; i++) {\n        fullTrace = dataOut[carpetDependents[i]];\n\n        if(!fullTrace.visible) continue;\n\n        var carpetAxis = carpetIndex[fullTrace.carpet];\n        fullTrace._carpet = carpetAxis;\n\n        if(!carpetAxis || !carpetAxis.visible) {\n            fullTrace.visible = false;\n            continue;\n        }\n\n        fullTrace.xaxis = carpetAxis.xaxis;\n        fullTrace.yaxis = carpetAxis.yaxis;\n    }\n};\n\nplots.supplyAnimationDefaults = function(opts) {\n    opts = opts || {};\n    var i;\n    var optsOut = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(opts || {}, optsOut, animationAttrs, attr, dflt);\n    }\n\n    coerce('mode');\n    coerce('direction');\n    coerce('fromcurrent');\n\n    if(Array.isArray(opts.frame)) {\n        optsOut.frame = [];\n        for(i = 0; i < opts.frame.length; i++) {\n            optsOut.frame[i] = plots.supplyAnimationFrameDefaults(opts.frame[i] || {});\n        }\n    } else {\n        optsOut.frame = plots.supplyAnimationFrameDefaults(opts.frame || {});\n    }\n\n    if(Array.isArray(opts.transition)) {\n        optsOut.transition = [];\n        for(i = 0; i < opts.transition.length; i++) {\n            optsOut.transition[i] = plots.supplyAnimationTransitionDefaults(opts.transition[i] || {});\n        }\n    } else {\n        optsOut.transition = plots.supplyAnimationTransitionDefaults(opts.transition || {});\n    }\n\n    return optsOut;\n};\n\nplots.supplyAnimationFrameDefaults = function(opts) {\n    var optsOut = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(opts || {}, optsOut, animationAttrs.frame, attr, dflt);\n    }\n\n    coerce('duration');\n    coerce('redraw');\n\n    return optsOut;\n};\n\nplots.supplyAnimationTransitionDefaults = function(opts) {\n    var optsOut = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(opts || {}, optsOut, animationAttrs.transition, attr, dflt);\n    }\n\n    coerce('duration');\n    coerce('easing');\n\n    return optsOut;\n};\n\nplots.supplyFrameDefaults = function(frameIn) {\n    var frameOut = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(frameIn, frameOut, frameAttrs, attr, dflt);\n    }\n\n    coerce('group');\n    coerce('name');\n    coerce('traces');\n    coerce('baseframe');\n    coerce('data');\n    coerce('layout');\n\n    return frameOut;\n};\n\nplots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, traceInIndex) {\n    var colorway = layout.colorway || Color.defaults;\n    var defaultColor = colorway[colorIndex % colorway.length];\n\n    var i;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, plots.attributes, attr, dflt);\n    }\n\n    var visible = coerce('visible');\n\n    coerce('type');\n    coerce('name', layout._traceWord + ' ' + traceInIndex);\n\n    coerce('uirevision', layout.uirevision);\n\n    // we want even invisible traces to make their would-be subplots visible\n    // so coerce the subplot id(s) now no matter what\n    var _module = plots.getModule(traceOut);\n\n    traceOut._module = _module;\n    if(_module) {\n        var basePlotModule = _module.basePlotModule;\n        var subplotAttr = basePlotModule.attr;\n        var subplotAttrs = basePlotModule.attributes;\n        if(subplotAttr && subplotAttrs) {\n            var subplots = layout._subplots;\n            var subplotId = '';\n\n            // TODO - currently if we draw an empty gl2d subplot, it draws\n            // nothing then gets stuck and you can't get it back without newPlot\n            // sort this out in the regl refactor? but for now just drop empty gl2d subplots\n            if(basePlotModule.name !== 'gl2d' || visible) {\n                if(Array.isArray(subplotAttr)) {\n                    for(i = 0; i < subplotAttr.length; i++) {\n                        var attri = subplotAttr[i];\n                        var vali = Lib.coerce(traceIn, traceOut, subplotAttrs, attri);\n\n                        if(subplots[attri]) Lib.pushUnique(subplots[attri], vali);\n                        subplotId += vali;\n                    }\n                } else {\n                    subplotId = Lib.coerce(traceIn, traceOut, subplotAttrs, subplotAttr);\n                }\n\n                if(subplots[basePlotModule.name]) {\n                    Lib.pushUnique(subplots[basePlotModule.name], subplotId);\n                }\n            }\n        }\n    }\n\n    if(visible) {\n        coerce('customdata');\n        coerce('ids');\n        coerce('meta');\n\n        if(Registry.traceIs(traceOut, 'showLegend')) {\n            traceOut._dfltShowLegend = true;\n            coerce('showlegend');\n            coerce('legendgroup');\n        } else {\n            traceOut._dfltShowLegend = false;\n        }\n\n        if(_module) {\n            _module.supplyDefaults(traceIn, traceOut, defaultColor, layout);\n        }\n\n        if(!Registry.traceIs(traceOut, 'noOpacity')) {\n            coerce('opacity');\n        }\n\n        if(Registry.traceIs(traceOut, 'notLegendIsolatable')) {\n            // This clears out the legendonly state for traces like carpet that\n            // cannot be isolated in the legend\n            traceOut.visible = !!traceOut.visible;\n        }\n\n        if(!Registry.traceIs(traceOut, 'noHover')) {\n            if(!traceOut.hovertemplate) Lib.coerceHoverinfo(traceIn, traceOut, layout);\n\n            // parcats support hover, but not hoverlabel stylings (yet)\n            if(traceOut.type !== 'parcats') {\n                Registry.getComponentMethod('fx', 'supplyDefaults')(traceIn, traceOut, defaultColor, layout);\n            }\n        }\n\n        if(_module && _module.selectPoints) {\n            coerce('selectedpoints');\n        }\n\n        plots.supplyTransformDefaults(traceIn, traceOut, layout);\n    }\n\n    return traceOut;\n};\n\n/**\n * hasMakesDataTransform: does this trace have a transform that makes its own\n * data, either by grabbing it from somewhere else or by creating it from input\n * parameters? If so, we should still keep going with supplyDefaults\n * even if the trace is invisible, which may just be because it has no data yet.\n */\nfunction hasMakesDataTransform(trace) {\n    var transforms = trace.transforms;\n    if(Array.isArray(transforms) && transforms.length) {\n        for(var i = 0; i < transforms.length; i++) {\n            var ti = transforms[i];\n            var _module = ti._module || transformsRegistry[ti.type];\n            if(_module && _module.makesData) return true;\n        }\n    }\n    return false;\n}\n\nplots.hasMakesDataTransform = hasMakesDataTransform;\n\nplots.supplyTransformDefaults = function(traceIn, traceOut, layout) {\n    // For now we only allow transforms on 1D traces, ie those that specify a _length.\n    // If we were to implement 2D transforms, we'd need to have each transform\n    // describe its own applicability and disable itself when it doesn't apply.\n    // Also allow transforms that make their own data, but not in globalTransforms\n    if(!(traceOut._length || hasMakesDataTransform(traceIn))) return;\n\n    var globalTransforms = layout._globalTransforms || [];\n    var transformModules = layout._transformModules || [];\n\n    if(!Array.isArray(traceIn.transforms) && globalTransforms.length === 0) return;\n\n    var containerIn = traceIn.transforms || [];\n    var transformList = globalTransforms.concat(containerIn);\n    var containerOut = traceOut.transforms = [];\n\n    for(var i = 0; i < transformList.length; i++) {\n        var transformIn = transformList[i];\n        var type = transformIn.type;\n        var _module = transformsRegistry[type];\n        var transformOut;\n\n        /*\n         * Supply defaults may run twice. First pass runs all supply defaults steps\n         * and adds the _module to any output transforms.\n         * If transforms exist another pass is run so that any generated traces also\n         * go through supply defaults. This has the effect of rerunning\n         * supplyTransformDefaults. If the transform does not have a `transform`\n         * function it could not have generated any new traces and the second stage\n         * is unnecessary. We detect this case with the following variables.\n         */\n        var isFirstStage = !(transformIn._module && transformIn._module === _module);\n        var doLaterStages = _module && typeof _module.transform === 'function';\n\n        if(!_module) Lib.warn('Unrecognized transform type ' + type + '.');\n\n        if(_module && _module.supplyDefaults && (isFirstStage || doLaterStages)) {\n            transformOut = _module.supplyDefaults(transformIn, traceOut, layout, traceIn);\n            transformOut.type = type;\n            transformOut._module = _module;\n\n            Lib.pushUnique(transformModules, _module);\n        } else {\n            transformOut = Lib.extendFlat({}, transformIn);\n        }\n\n        containerOut.push(transformOut);\n    }\n};\n\nfunction applyTransforms(fullTrace, fullData, layout, fullLayout) {\n    var container = fullTrace.transforms;\n    var dataOut = [fullTrace];\n\n    for(var i = 0; i < container.length; i++) {\n        var transform = container[i];\n        var _module = transformsRegistry[transform.type];\n\n        if(_module && _module.transform) {\n            dataOut = _module.transform(dataOut, {\n                transform: transform,\n                fullTrace: fullTrace,\n                fullData: fullData,\n                layout: layout,\n                fullLayout: fullLayout,\n                transformIndex: i\n            });\n        }\n    }\n\n    return dataOut;\n}\n\nplots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, plots.layoutAttributes, attr, dflt);\n    }\n\n    var template = layoutIn.template;\n    if(Lib.isPlainObject(template)) {\n        layoutOut.template = template;\n        layoutOut._template = template.layout;\n        layoutOut._dataTemplate = template.data;\n    }\n\n    var globalFont = Lib.coerceFont(coerce, 'font');\n\n    coerce('title.text', layoutOut._dfltTitle.plot);\n\n    Lib.coerceFont(coerce, 'title.font', {\n        family: globalFont.family,\n        size: Math.round(globalFont.size * 1.4),\n        color: globalFont.color\n    });\n\n    coerce('title.xref');\n    coerce('title.yref');\n    coerce('title.x');\n    coerce('title.y');\n    coerce('title.xanchor');\n    coerce('title.yanchor');\n    coerce('title.pad.t');\n    coerce('title.pad.r');\n    coerce('title.pad.b');\n    coerce('title.pad.l');\n\n    // Make sure that autosize is defaulted to *true*\n    // on layouts with no set width and height for backward compatibly,\n    // in particular https://plot.ly/javascript/responsive-fluid-layout/\n    //\n    // Before https://github.com/plotly/plotly.js/pull/635 ,\n    // layouts with no set width and height were set temporary set to 'initial'\n    // to pass through the autosize routine\n    //\n    // This behavior is subject to change in v2.\n    coerce('autosize', !(layoutIn.width && layoutIn.height));\n\n    coerce('width');\n    coerce('height');\n    coerce('margin.l');\n    coerce('margin.r');\n    coerce('margin.t');\n    coerce('margin.b');\n    coerce('margin.pad');\n    coerce('margin.autoexpand');\n\n    if(layoutIn.width && layoutIn.height) plots.sanitizeMargins(layoutOut);\n\n    Registry.getComponentMethod('grid', 'sizeDefaults')(layoutIn, layoutOut);\n\n    coerce('paper_bgcolor');\n\n    coerce('separators', formatObj.decimal + formatObj.thousands);\n    coerce('hidesources');\n\n    coerce('colorway');\n\n    coerce('datarevision');\n    var uirevision = coerce('uirevision');\n    coerce('editrevision', uirevision);\n    coerce('selectionrevision', uirevision);\n\n    coerce('modebar.orientation');\n    coerce('modebar.bgcolor', Color.addOpacity(layoutOut.paper_bgcolor, 0.5));\n    var modebarDefaultColor = Color.contrast(Color.rgb(layoutOut.modebar.bgcolor));\n    coerce('modebar.color', Color.addOpacity(modebarDefaultColor, 0.3));\n    coerce('modebar.activecolor', Color.addOpacity(modebarDefaultColor, 0.7));\n    coerce('modebar.uirevision', uirevision);\n\n    coerce('meta');\n\n    // do not include defaults in fullLayout when users do not set transition\n    if(Lib.isPlainObject(layoutIn.transition)) {\n        coerce('transition.duration');\n        coerce('transition.easing');\n        coerce('transition.ordering');\n    }\n\n    Registry.getComponentMethod(\n        'calendars',\n        'handleDefaults'\n    )(layoutIn, layoutOut, 'calendar');\n\n    Registry.getComponentMethod(\n        'fx',\n        'supplyLayoutGlobalDefaults'\n    )(layoutIn, layoutOut, coerce);\n};\n\nplots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) {\n    var context = gd._context || {};\n    var frameMargins = context.frameMargins;\n    var newWidth;\n    var newHeight;\n\n    var isPlotDiv = Lib.isPlotDiv(gd);\n\n    if(isPlotDiv) gd.emit('plotly_autosize');\n\n    // embedded in an iframe - just take the full iframe size\n    // if we get to this point, with no aspect ratio restrictions\n    if(context.fillFrame) {\n        newWidth = window.innerWidth;\n        newHeight = window.innerHeight;\n\n        // somehow we get a few extra px height sometimes...\n        // just hide it\n        document.body.style.overflow = 'hidden';\n    } else {\n        // plotly.js - let the developers do what they want, either\n        // provide height and width for the container div,\n        // specify size in layout, or take the defaults,\n        // but don't enforce any ratio restrictions\n        var computedStyle = isPlotDiv ? window.getComputedStyle(gd) : {};\n\n        newWidth = parseFloat(computedStyle.width) || parseFloat(computedStyle.maxWidth) || fullLayout.width;\n        newHeight = parseFloat(computedStyle.height) || parseFloat(computedStyle.maxHeight) || fullLayout.height;\n\n        if(isNumeric(frameMargins) && frameMargins > 0) {\n            var factor = 1 - 2 * frameMargins;\n            newWidth = Math.round(factor * newWidth);\n            newHeight = Math.round(factor * newHeight);\n        }\n    }\n\n    var minWidth = plots.layoutAttributes.width.min;\n    var minHeight = plots.layoutAttributes.height.min;\n    if(newWidth < minWidth) newWidth = minWidth;\n    if(newHeight < minHeight) newHeight = minHeight;\n\n    var widthHasChanged = !layout.width &&\n        (Math.abs(fullLayout.width - newWidth) > 1);\n    var heightHasChanged = !layout.height &&\n        (Math.abs(fullLayout.height - newHeight) > 1);\n\n    if(heightHasChanged || widthHasChanged) {\n        if(widthHasChanged) fullLayout.width = newWidth;\n        if(heightHasChanged) fullLayout.height = newHeight;\n    }\n\n    // cache initial autosize value, used in relayout when\n    // width or height values are set to null\n    if(!gd._initialAutoSize) {\n        gd._initialAutoSize = { width: newWidth, height: newHeight };\n    }\n\n    plots.sanitizeMargins(fullLayout);\n};\n\nplots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, transitionData) {\n    var componentsRegistry = Registry.componentsRegistry;\n    var basePlotModules = layoutOut._basePlotModules;\n    var component, i, _module;\n\n    var Cartesian = Registry.subplotsRegistry.cartesian;\n\n    // check if any components need to add more base plot modules\n    // that weren't captured by traces\n    for(component in componentsRegistry) {\n        _module = componentsRegistry[component];\n\n        if(_module.includeBasePlot) {\n            _module.includeBasePlot(layoutIn, layoutOut);\n        }\n    }\n\n    // make sure we *at least* have some cartesian axes\n    if(!basePlotModules.length) {\n        basePlotModules.push(Cartesian);\n    }\n\n    // ensure all cartesian axes have at least one subplot\n    if(layoutOut._has('cartesian')) {\n        Registry.getComponentMethod('grid', 'contentDefaults')(layoutIn, layoutOut);\n        Cartesian.finalizeSubplots(layoutIn, layoutOut);\n    }\n\n    // sort subplot lists\n    for(var subplotType in layoutOut._subplots) {\n        layoutOut._subplots[subplotType].sort(Lib.subplotSort);\n    }\n\n    // base plot module layout defaults\n    for(i = 0; i < basePlotModules.length; i++) {\n        _module = basePlotModules[i];\n\n        // e.g. pie does not have a layout-defaults step\n        if(_module.supplyLayoutDefaults) {\n            _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);\n        }\n    }\n\n    // trace module layout defaults\n    // use _modules rather than _visibleModules so that even\n    // legendonly traces can include settings - eg barmode, which affects\n    // legend.traceorder default value.\n    var modules = layoutOut._modules;\n    for(i = 0; i < modules.length; i++) {\n        _module = modules[i];\n\n        if(_module.supplyLayoutDefaults) {\n            _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);\n        }\n    }\n\n    // transform module layout defaults\n    var transformModules = layoutOut._transformModules;\n    for(i = 0; i < transformModules.length; i++) {\n        _module = transformModules[i];\n\n        if(_module.supplyLayoutDefaults) {\n            _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData, transitionData);\n        }\n    }\n\n    for(component in componentsRegistry) {\n        _module = componentsRegistry[component];\n\n        if(_module.supplyLayoutDefaults) {\n            _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);\n        }\n    }\n};\n\n// Remove all plotly attributes from a div so it can be replotted fresh\n// TODO: these really need to be encapsulated into a much smaller set...\nplots.purge = function(gd) {\n    // note: we DO NOT remove _context because it doesn't change when we insert\n    // a new plot, and may have been set outside of our scope.\n\n    var fullLayout = gd._fullLayout || {};\n    if(fullLayout._glcontainer !== undefined) {\n        fullLayout._glcontainer.selectAll('.gl-canvas').remove();\n        fullLayout._glcontainer.remove();\n        fullLayout._glcanvas = null;\n    }\n    if(fullLayout._geocontainer !== undefined) fullLayout._geocontainer.remove();\n\n    // remove modebar\n    if(fullLayout._modeBar) fullLayout._modeBar.destroy();\n\n    if(gd._transitionData) {\n        // Ensure any dangling callbacks are simply dropped if the plot is purged.\n        // This is more or less only actually important for testing.\n        if(gd._transitionData._interruptCallbacks) {\n            gd._transitionData._interruptCallbacks.length = 0;\n        }\n\n        if(gd._transitionData._animationRaf) {\n            window.cancelAnimationFrame(gd._transitionData._animationRaf);\n        }\n    }\n\n    // remove any planned throttles\n    Lib.clearThrottle();\n\n    // remove responsive handler\n    Lib.clearResponsive(gd);\n\n    // data and layout\n    delete gd.data;\n    delete gd.layout;\n    delete gd._fullData;\n    delete gd._fullLayout;\n    delete gd.calcdata;\n    delete gd.framework;\n    delete gd.empty;\n\n    delete gd.fid;\n\n    delete gd.undoqueue; // action queue\n    delete gd.undonum;\n    delete gd.autoplay; // are we doing an action that doesn't go in undo queue?\n    delete gd.changed;\n\n    // these get recreated on Plotly.plot anyway, but just to be safe\n    // (and to have a record of them...)\n    delete gd._promises;\n    delete gd._redrawTimer;\n    delete gd._hmlumcount;\n    delete gd._hmpixcount;\n    delete gd._transitionData;\n    delete gd._transitioning;\n    delete gd._initialAutoSize;\n    delete gd._transitioningWithDuration;\n\n    // created during certain events, that *should* clean them up\n    // themselves, but may not if there was an error\n    delete gd._dragging;\n    delete gd._dragged;\n    delete gd._dragdata;\n    delete gd._hoverdata;\n    delete gd._snapshotInProgress;\n    delete gd._editing;\n    delete gd._mouseDownTime;\n    delete gd._legendMouseDownTime;\n\n    // remove all event listeners\n    if(gd.removeAllListeners) gd.removeAllListeners();\n};\n\nplots.style = function(gd) {\n    var _modules = gd._fullLayout._visibleModules;\n    var styleModules = [];\n    var i;\n\n    // some trace modules reuse the same style method,\n    // make sure to not unnecessary call them multiple times.\n\n    for(i = 0; i < _modules.length; i++) {\n        var _module = _modules[i];\n        if(_module.style) {\n            Lib.pushUnique(styleModules, _module.style);\n        }\n    }\n\n    for(i = 0; i < styleModules.length; i++) {\n        styleModules[i](gd);\n    }\n};\n\nplots.sanitizeMargins = function(fullLayout) {\n    // polar doesn't do margins...\n    if(!fullLayout || !fullLayout.margin) return;\n\n    var width = fullLayout.width;\n    var height = fullLayout.height;\n    var margin = fullLayout.margin;\n    var plotWidth = width - (margin.l + margin.r);\n    var plotHeight = height - (margin.t + margin.b);\n    var correction;\n\n    // if margin.l + margin.r = 0 then plotWidth > 0\n    // as width >= 10 by supplyDefaults\n    // similarly for margin.t + margin.b\n\n    if(plotWidth < 0) {\n        correction = (width - 1) / (margin.l + margin.r);\n        margin.l = Math.floor(correction * margin.l);\n        margin.r = Math.floor(correction * margin.r);\n    }\n\n    if(plotHeight < 0) {\n        correction = (height - 1) / (margin.t + margin.b);\n        margin.t = Math.floor(correction * margin.t);\n        margin.b = Math.floor(correction * margin.b);\n    }\n};\n\nplots.clearAutoMarginIds = function(gd) {\n    gd._fullLayout._pushmarginIds = {};\n};\n\nplots.allowAutoMargin = function(gd, id) {\n    gd._fullLayout._pushmarginIds[id] = 1;\n};\n\nfunction initMargins(fullLayout) {\n    var margin = fullLayout.margin;\n\n    if(!fullLayout._size) {\n        var gs = fullLayout._size = {\n            l: Math.round(margin.l),\n            r: Math.round(margin.r),\n            t: Math.round(margin.t),\n            b: Math.round(margin.b),\n            p: Math.round(margin.pad)\n        };\n        gs.w = Math.round(fullLayout.width) - gs.l - gs.r;\n        gs.h = Math.round(fullLayout.height) - gs.t - gs.b;\n    }\n    if(!fullLayout._pushmargin) fullLayout._pushmargin = {};\n    if(!fullLayout._pushmarginIds) fullLayout._pushmarginIds = {};\n}\n\n/**\n * autoMargin: called by components that may need to expand the margins to\n * be rendered on-plot.\n *\n * @param {DOM element} gd\n * @param {string} id - an identifier unique (within this plot) to this object,\n *     so we can remove a previous margin expansion from the same object.\n * @param {object} o - the margin requirements of this object, or omit to delete\n *     this entry (like if it's hidden). Keys are:\n *     x, y: plot fraction of the anchor point.\n *     xl, xr, yt, yb: if the object has an extent defined in plot fraction,\n *         you can specify both edges as plot fractions in each dimension\n *     l, r, t, b: the pixels to pad past the plot fraction x[l|r] and y[t|b]\n *     pad: extra pixels to add in all directions, default 12 (why?)\n */\nplots.autoMargin = function(gd, id, o) {\n    var fullLayout = gd._fullLayout;\n\n    var pushMargin = fullLayout._pushmargin;\n    var pushMarginIds = fullLayout._pushmarginIds;\n\n    if(fullLayout.margin.autoexpand !== false) {\n        if(!o) {\n            delete pushMargin[id];\n            delete pushMarginIds[id];\n        } else {\n            var pad = o.pad;\n            if(pad === undefined) {\n                var margin = fullLayout.margin;\n                // if no explicit pad is given, use 12px unless there's a\n                // specified margin that's smaller than that\n                pad = Math.min(12, margin.l, margin.r, margin.t, margin.b);\n            }\n\n            // if the item is too big, just give it enough automargin to\n            // make sure you can still grab it and bring it back\n            if(o.l + o.r > fullLayout.width * 0.5) o.l = o.r = 0;\n            if(o.b + o.t > fullLayout.height * 0.5) o.b = o.t = 0;\n\n            var xl = o.xl !== undefined ? o.xl : o.x;\n            var xr = o.xr !== undefined ? o.xr : o.x;\n            var yt = o.yt !== undefined ? o.yt : o.y;\n            var yb = o.yb !== undefined ? o.yb : o.y;\n\n            pushMargin[id] = {\n                l: {val: xl, size: o.l + pad},\n                r: {val: xr, size: o.r + pad},\n                b: {val: yb, size: o.b + pad},\n                t: {val: yt, size: o.t + pad}\n            };\n            pushMarginIds[id] = 1;\n        }\n\n        if(!fullLayout._replotting) {\n            plots.doAutoMargin(gd);\n        }\n    }\n};\n\nplots.doAutoMargin = function(gd) {\n    var fullLayout = gd._fullLayout;\n    if(!fullLayout._size) fullLayout._size = {};\n    initMargins(fullLayout);\n\n    var gs = fullLayout._size;\n    var margin = fullLayout.margin;\n    var oldMargins = Lib.extendFlat({}, gs);\n\n    // adjust margins for outside components\n    // fullLayout.margin is the requested margin,\n    // fullLayout._size has margins and plotsize after adjustment\n    var ml = margin.l;\n    var mr = margin.r;\n    var mt = margin.t;\n    var mb = margin.b;\n    var width = fullLayout.width;\n    var height = fullLayout.height;\n    var pushMargin = fullLayout._pushmargin;\n    var pushMarginIds = fullLayout._pushmarginIds;\n\n    if(fullLayout.margin.autoexpand !== false) {\n        for(var k in pushMargin) {\n            if(!pushMarginIds[k]) delete pushMargin[k];\n        }\n\n        // fill in the requested margins\n        pushMargin.base = {\n            l: {val: 0, size: ml},\n            r: {val: 1, size: mr},\n            t: {val: 1, size: mt},\n            b: {val: 0, size: mb}\n        };\n\n        // now cycle through all the combinations of l and r\n        // (and t and b) to find the required margins\n\n        for(var k1 in pushMargin) {\n            var pushleft = pushMargin[k1].l || {};\n            var pushbottom = pushMargin[k1].b || {};\n            var fl = pushleft.val;\n            var pl = pushleft.size;\n            var fb = pushbottom.val;\n            var pb = pushbottom.size;\n\n            for(var k2 in pushMargin) {\n                if(isNumeric(pl) && pushMargin[k2].r) {\n                    var fr = pushMargin[k2].r.val;\n                    var pr = pushMargin[k2].r.size;\n\n                    if(fr > fl) {\n                        var newL = (pl * fr + (pr - width) * fl) / (fr - fl);\n                        var newR = (pr * (1 - fl) + (pl - width) * (1 - fr)) / (fr - fl);\n                        if(newL >= 0 && newR >= 0 && width - (newL + newR) > 0 && newL + newR > ml + mr) {\n                            ml = newL;\n                            mr = newR;\n                        }\n                    }\n                }\n\n                if(isNumeric(pb) && pushMargin[k2].t) {\n                    var ft = pushMargin[k2].t.val;\n                    var pt = pushMargin[k2].t.size;\n\n                    if(ft > fb) {\n                        var newB = (pb * ft + (pt - height) * fb) / (ft - fb);\n                        var newT = (pt * (1 - fb) + (pb - height) * (1 - ft)) / (ft - fb);\n                        if(newB >= 0 && newT >= 0 && height - (newT + newB) > 0 && newB + newT > mb + mt) {\n                            mb = newB;\n                            mt = newT;\n                        }\n                    }\n                }\n            }\n        }\n    }\n\n    gs.l = Math.round(ml);\n    gs.r = Math.round(mr);\n    gs.t = Math.round(mt);\n    gs.b = Math.round(mb);\n    gs.p = Math.round(margin.pad);\n    gs.w = Math.round(width) - gs.l - gs.r;\n    gs.h = Math.round(height) - gs.t - gs.b;\n\n    // if things changed and we're not already redrawing, trigger a redraw\n    if(!fullLayout._replotting && plots.didMarginChange(oldMargins, gs)) {\n        if('_redrawFromAutoMarginCount' in fullLayout) {\n            fullLayout._redrawFromAutoMarginCount++;\n        } else {\n            fullLayout._redrawFromAutoMarginCount = 1;\n        }\n        return Registry.call('plot', gd);\n    }\n};\n\nvar marginKeys = ['l', 'r', 't', 'b', 'p', 'w', 'h'];\n\nplots.didMarginChange = function(margin0, margin1) {\n    for(var i = 0; i < marginKeys.length; i++) {\n        var k = marginKeys[i];\n        var m0 = margin0[k];\n        var m1 = margin1[k];\n        // use 1px tolerance in case we old/new differ only\n        // by rounding errors, which can lead to infinite loops\n        if(!isNumeric(m0) || Math.abs(m1 - m0) > 1) {\n            return true;\n        }\n    }\n    return false;\n};\n\n/**\n * JSONify the graph data and layout\n *\n * This function needs to recurse because some src can be inside\n * sub-objects.\n *\n * It also strips out functions and private (starts with _) elements.\n * Therefore, we can add temporary things to data and layout that don't\n * get saved.\n *\n * @param gd The graphDiv\n * @param {Boolean} dataonly If true, don't return layout.\n * @param {'keepref'|'keepdata'|'keepall'} [mode='keepref'] Filter what's kept\n *      keepref: remove data for which there's a src present\n *          eg if there's xsrc present (and xsrc is well-formed,\n *          ie has : and some chars before it), strip out x\n *      keepdata: remove all src tags, don't remove the data itself\n *      keepall: keep data and src\n * @param {String} output If you specify 'object', the result will not be stringified\n * @param {Boolean} useDefaults If truthy, use _fullLayout and _fullData\n * @returns {Object|String}\n */\nplots.graphJson = function(gd, dataonly, mode, output, useDefaults) {\n    // if the defaults aren't supplied yet, we need to do that...\n    if((useDefaults && dataonly && !gd._fullData) ||\n            (useDefaults && !dataonly && !gd._fullLayout)) {\n        plots.supplyDefaults(gd);\n    }\n\n    var data = (useDefaults) ? gd._fullData : gd.data;\n    var layout = (useDefaults) ? gd._fullLayout : gd.layout;\n    var frames = (gd._transitionData || {})._frames;\n\n    function stripObj(d) {\n        if(typeof d === 'function') {\n            return null;\n        }\n        if(Lib.isPlainObject(d)) {\n            var o = {};\n            var v, src;\n            for(v in d) {\n                // remove private elements and functions\n                // _ is for private, [ is a mistake ie [object Object]\n                if(typeof d[v] === 'function' ||\n                        ['_', '['].indexOf(v.charAt(0)) !== -1) {\n                    continue;\n                }\n\n                // look for src/data matches and remove the appropriate one\n                if(mode === 'keepdata') {\n                    // keepdata: remove all ...src tags\n                    if(v.substr(v.length - 3) === 'src') {\n                        continue;\n                    }\n                } else if(mode === 'keepstream') {\n                    // keep sourced data if it's being streamed.\n                    // similar to keepref, but if the 'stream' object exists\n                    // in a trace, we will keep the data array.\n                    src = d[v + 'src'];\n                    if(typeof src === 'string' && src.indexOf(':') > 0) {\n                        if(!Lib.isPlainObject(d.stream)) {\n                            continue;\n                        }\n                    }\n                } else if(mode !== 'keepall') {\n                    // keepref: remove sourced data but only\n                    // if the source tag is well-formed\n                    src = d[v + 'src'];\n                    if(typeof src === 'string' && src.indexOf(':') > 0) {\n                        continue;\n                    }\n                }\n\n                // OK, we're including this... recurse into it\n                o[v] = stripObj(d[v]);\n            }\n            return o;\n        }\n\n        if(Array.isArray(d)) {\n            return d.map(stripObj);\n        }\n\n        if(Lib.isTypedArray(d)) {\n            return Lib.simpleMap(d, Lib.identity);\n        }\n\n        // convert native dates to date strings...\n        // mostly for external users exporting to plotly\n        if(Lib.isJSDate(d)) return Lib.ms2DateTimeLocal(+d);\n\n        return d;\n    }\n\n    var obj = {\n        data: (data || []).map(function(v) {\n            var d = stripObj(v);\n            // fit has some little arrays in it that don't contain data,\n            // just fit params and meta\n            if(dataonly) { delete d.fit; }\n            return d;\n        })\n    };\n    if(!dataonly) { obj.layout = stripObj(layout); }\n\n    if(gd.framework && gd.framework.isPolar) obj = gd.framework.getConfig();\n\n    if(frames) obj.frames = stripObj(frames);\n\n    return (output === 'object') ? obj : JSON.stringify(obj);\n};\n\n/**\n * Modify a keyframe using a list of operations:\n *\n * @param {array of objects} operations\n *      Sequence of operations to be performed on the keyframes\n */\nplots.modifyFrames = function(gd, operations) {\n    var i, op, frame;\n    var _frames = gd._transitionData._frames;\n    var _frameHash = gd._transitionData._frameHash;\n\n    for(i = 0; i < operations.length; i++) {\n        op = operations[i];\n\n        switch(op.type) {\n            // No reason this couldn't exist, but is currently unused/untested:\n            /* case 'rename':\n                frame = _frames[op.index];\n                delete _frameHash[frame.name];\n                _frameHash[op.name] = frame;\n                frame.name = op.name;\n                break;*/\n            case 'replace':\n                frame = op.value;\n                var oldName = (_frames[op.index] || {}).name;\n                var newName = frame.name;\n                _frames[op.index] = _frameHash[newName] = frame;\n\n                if(newName !== oldName) {\n                    // If name has changed in addition to replacement, then update\n                    // the lookup table:\n                    delete _frameHash[oldName];\n                    _frameHash[newName] = frame;\n                }\n\n                break;\n            case 'insert':\n                frame = op.value;\n                _frameHash[frame.name] = frame;\n                _frames.splice(op.index, 0, frame);\n                break;\n            case 'delete':\n                frame = _frames[op.index];\n                delete _frameHash[frame.name];\n                _frames.splice(op.index, 1);\n                break;\n        }\n    }\n\n    return Promise.resolve();\n};\n\n/*\n * Compute a keyframe. Merge a keyframe into its base frame(s) and\n * expand properties.\n *\n * @param {object} frameLookup\n *      An object containing frames keyed by name (i.e. gd._transitionData._frameHash)\n * @param {string} frame\n *      The name of the keyframe to be computed\n *\n * Returns: a new object with the merged content\n */\nplots.computeFrame = function(gd, frameName) {\n    var frameLookup = gd._transitionData._frameHash;\n    var i, traceIndices, traceIndex, destIndex;\n\n    // Null or undefined will fail on .toString(). We'll allow numbers since we\n    // make it clear frames must be given string names, but we'll allow numbers\n    // here since they're otherwise fine for looking up frames as long as they're\n    // properly cast to strings. We really just want to ensure here that this\n    // 1) doesn't fail, and\n    // 2) doens't give an incorrect answer (which String(frameName) would)\n    if(!frameName) {\n        throw new Error('computeFrame must be given a string frame name');\n    }\n\n    var framePtr = frameLookup[frameName.toString()];\n\n    // Return false if the name is invalid:\n    if(!framePtr) {\n        return false;\n    }\n\n    var frameStack = [framePtr];\n    var frameNameStack = [framePtr.name];\n\n    // Follow frame pointers:\n    while(framePtr.baseframe && (framePtr = frameLookup[framePtr.baseframe.toString()])) {\n        // Avoid infinite loops:\n        if(frameNameStack.indexOf(framePtr.name) !== -1) break;\n\n        frameStack.push(framePtr);\n        frameNameStack.push(framePtr.name);\n    }\n\n    // A new object for the merged result:\n    var result = {};\n\n    // Merge, starting with the last and ending with the desired frame:\n    while((framePtr = frameStack.pop())) {\n        if(framePtr.layout) {\n            result.layout = plots.extendLayout(result.layout, framePtr.layout);\n        }\n\n        if(framePtr.data) {\n            if(!result.data) {\n                result.data = [];\n            }\n            traceIndices = framePtr.traces;\n\n            if(!traceIndices) {\n                // If not defined, assume serial order starting at zero\n                traceIndices = [];\n                for(i = 0; i < framePtr.data.length; i++) {\n                    traceIndices[i] = i;\n                }\n            }\n\n            if(!result.traces) {\n                result.traces = [];\n            }\n\n            for(i = 0; i < framePtr.data.length; i++) {\n                // Loop through this frames data, find out where it should go,\n                // and merge it!\n                traceIndex = traceIndices[i];\n                if(traceIndex === undefined || traceIndex === null) {\n                    continue;\n                }\n\n                destIndex = result.traces.indexOf(traceIndex);\n                if(destIndex === -1) {\n                    destIndex = result.data.length;\n                    result.traces[destIndex] = traceIndex;\n                }\n\n                result.data[destIndex] = plots.extendTrace(result.data[destIndex], framePtr.data[i]);\n            }\n        }\n    }\n\n    return result;\n};\n\n/*\n * Recompute the lookup table that maps frame name -> frame object. addFrames/\n * deleteFrames already manages this data one at a time, so the only time this\n * is necessary is if you poke around manually in `gd._transitionData._frames`\n * and create and haven't updated the lookup table.\n */\nplots.recomputeFrameHash = function(gd) {\n    var hash = gd._transitionData._frameHash = {};\n    var frames = gd._transitionData._frames;\n    for(var i = 0; i < frames.length; i++) {\n        var frame = frames[i];\n        if(frame && frame.name) {\n            hash[frame.name] = frame;\n        }\n    }\n};\n\n/**\n * Extend an object, treating container arrays very differently by extracting\n * their contents and merging them separately.\n *\n * This exists so that we can extendDeepNoArrays and avoid stepping into data\n * arrays without knowledge of the plot schema, but so that we may also manually\n * recurse into known container arrays, such as transforms.\n *\n * See extendTrace and extendLayout below for usage.\n */\nplots.extendObjectWithContainers = function(dest, src, containerPaths) {\n    var containerProp, containerVal, i, j, srcProp, destProp, srcContainer, destContainer;\n    var copy = Lib.extendDeepNoArrays({}, src || {});\n    var expandedObj = Lib.expandObjectPaths(copy);\n    var containerObj = {};\n\n    // Step through and extract any container properties. Otherwise extendDeepNoArrays\n    // will clobber any existing properties with an empty array and then supplyDefaults\n    // will reset everything to defaults.\n    if(containerPaths && containerPaths.length) {\n        for(i = 0; i < containerPaths.length; i++) {\n            containerProp = Lib.nestedProperty(expandedObj, containerPaths[i]);\n            containerVal = containerProp.get();\n\n            if(containerVal === undefined) {\n                Lib.nestedProperty(containerObj, containerPaths[i]).set(null);\n            } else {\n                containerProp.set(null);\n                Lib.nestedProperty(containerObj, containerPaths[i]).set(containerVal);\n            }\n        }\n    }\n\n    dest = Lib.extendDeepNoArrays(dest || {}, expandedObj);\n\n    if(containerPaths && containerPaths.length) {\n        for(i = 0; i < containerPaths.length; i++) {\n            srcProp = Lib.nestedProperty(containerObj, containerPaths[i]);\n            srcContainer = srcProp.get();\n\n            if(!srcContainer) continue;\n\n            destProp = Lib.nestedProperty(dest, containerPaths[i]);\n            destContainer = destProp.get();\n\n            if(!Array.isArray(destContainer)) {\n                destContainer = [];\n                destProp.set(destContainer);\n            }\n\n            for(j = 0; j < srcContainer.length; j++) {\n                var srcObj = srcContainer[j];\n\n                if(srcObj === null) destContainer[j] = null;\n                else {\n                    destContainer[j] = plots.extendObjectWithContainers(destContainer[j], srcObj);\n                }\n            }\n\n            destProp.set(destContainer);\n        }\n    }\n\n    return dest;\n};\n\nplots.dataArrayContainers = ['transforms', 'dimensions'];\nplots.layoutArrayContainers = Registry.layoutArrayContainers;\n\n/*\n * Extend a trace definition. This method:\n *\n *  1. directly transfers any array references\n *  2. manually recurses into container arrays like transforms\n *\n * The result is the original object reference with the new contents merged in.\n */\nplots.extendTrace = function(destTrace, srcTrace) {\n    return plots.extendObjectWithContainers(destTrace, srcTrace, plots.dataArrayContainers);\n};\n\n/*\n * Extend a layout definition. This method:\n *\n *  1. directly transfers any array references (not critically important for\n *     layout since there aren't really data arrays)\n *  2. manually recurses into container arrays like annotations\n *\n * The result is the original object reference with the new contents merged in.\n */\nplots.extendLayout = function(destLayout, srcLayout) {\n    return plots.extendObjectWithContainers(destLayout, srcLayout, plots.layoutArrayContainers);\n};\n\n/**\n * Transition to a set of new data and layout properties from Plotly.animate\n *\n * @param {DOM element} gd\n * @param {Object[]} data\n *      an array of data objects following the normal Plotly data definition format\n * @param {Object} layout\n *      a layout object, following normal Plotly layout format\n * @param {Number[]} traces\n *      indices of the corresponding traces specified in `data`\n * @param {Object} frameOpts\n *      options for the frame (i.e. whether to redraw post-transition)\n * @param {Object} transitionOpts\n *      options for the transition\n */\nplots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts) {\n    var opts = {redraw: frameOpts.redraw};\n    var transitionedTraces = {};\n    var axEdits = [];\n\n    opts.prepareFn = function() {\n        var dataLength = Array.isArray(data) ? data.length : 0;\n        var traceIndices = traces.slice(0, dataLength);\n\n        for(var i = 0; i < traceIndices.length; i++) {\n            var traceIdx = traceIndices[i];\n            var trace = gd._fullData[traceIdx];\n            var _module = trace._module;\n\n            // There's nothing to do if this module is not defined:\n            if(!_module) continue;\n\n            // Don't register the trace as transitioned if it doesn't know what to do.\n            // If it *is* registered, it will receive a callback that it's responsible\n            // for calling in order to register the transition as having completed.\n            if(_module.animatable) {\n                var n = _module.basePlotModule.name;\n                if(!transitionedTraces[n]) transitionedTraces[n] = [];\n                transitionedTraces[n].push(traceIdx);\n            }\n\n            gd.data[traceIndices[i]] = plots.extendTrace(gd.data[traceIndices[i]], data[i]);\n        }\n\n        // Follow the same procedure. Clone it so we don't mangle the input, then\n        // expand any object paths so we can merge deep into gd.layout:\n        var layoutUpdate = Lib.expandObjectPaths(Lib.extendDeepNoArrays({}, layout));\n\n        // Before merging though, we need to modify the incoming layout. We only\n        // know how to *transition* layout ranges, so it's imperative that a new\n        // range not be sent to the layout before the transition has started. So\n        // we must remove the things we can transition:\n        var axisAttrRe = /^[xy]axis[0-9]*$/;\n        for(var attr in layoutUpdate) {\n            if(!axisAttrRe.test(attr)) continue;\n            delete layoutUpdate[attr].range;\n        }\n\n        plots.extendLayout(gd.layout, layoutUpdate);\n\n        // Supply defaults after applying the incoming properties. Note that any attempt\n        // to simplify this step and reduce the amount of work resulted in the reconstruction\n        // of essentially the whole supplyDefaults step, so that it seems sensible to just use\n        // supplyDefaults even though it's heavier than would otherwise be desired for\n        // transitions:\n\n        // first delete calcdata so supplyDefaults knows a calc step is coming\n        delete gd.calcdata;\n\n        plots.supplyDefaults(gd);\n        plots.doCalcdata(gd);\n\n        var newLayout = Lib.expandObjectPaths(layout);\n\n        if(newLayout) {\n            var subplots = gd._fullLayout._plots;\n\n            for(var k in subplots) {\n                var plotinfo = subplots[k];\n                var xa = plotinfo.xaxis;\n                var ya = plotinfo.yaxis;\n                var xr0 = xa.range.slice();\n                var yr0 = ya.range.slice();\n\n                var xr1;\n                if(Array.isArray(newLayout[xa._name + '.range'])) {\n                    xr1 = newLayout[xa._name + '.range'].slice();\n                } else if(Array.isArray((newLayout[xa._name] || {}).range)) {\n                    xr1 = newLayout[xa._name].range.slice();\n                }\n\n                var yr1;\n                if(Array.isArray(newLayout[ya._name + '.range'])) {\n                    yr1 = newLayout[ya._name + '.range'].slice();\n                } else if(Array.isArray((newLayout[ya._name] || {}).range)) {\n                    yr1 = newLayout[ya._name].range.slice();\n                }\n\n                var editX;\n                if(xr0 && xr1 && (xr0[0] !== xr1[0] || xr0[1] !== xr1[1])) {\n                    editX = {xr0: xr0, xr1: xr1};\n                }\n\n                var editY;\n                if(yr0 && yr1 && (yr0[0] !== yr1[0] || yr0[1] !== yr1[1])) {\n                    editY = {yr0: yr0, yr1: yr1};\n                }\n\n                if(editX || editY) {\n                    axEdits.push(Lib.extendFlat({plotinfo: plotinfo}, editX, editY));\n                }\n            }\n        }\n\n        return Promise.resolve();\n    };\n\n    opts.runFn = function(makeCallback) {\n        var traceTransitionOpts;\n        var basePlotModules = gd._fullLayout._basePlotModules;\n        var hasAxisTransition = axEdits.length;\n        var i;\n\n        if(layout) {\n            for(i = 0; i < basePlotModules.length; i++) {\n                if(basePlotModules[i].transitionAxes) {\n                    basePlotModules[i].transitionAxes(gd, axEdits, transitionOpts, makeCallback);\n                }\n            }\n        }\n\n        // Here handle the exception that we refuse to animate scales and axes at the same\n        // time. In other words, if there's an axis transition, then set the data transition\n        // to instantaneous.\n        if(hasAxisTransition) {\n            traceTransitionOpts = Lib.extendFlat({}, transitionOpts);\n            traceTransitionOpts.duration = 0;\n            // This means do not transition cartesian traces,\n            // this happens on layout-only (e.g. axis range) animations\n            delete transitionedTraces.cartesian;\n        } else {\n            traceTransitionOpts = transitionOpts;\n        }\n\n        // Note that we pass a callback to *create* the callback that must be invoked on completion.\n        // This is since not all traces know about transitions, so it greatly simplifies matters if\n        // the trace is responsible for creating a callback, if needed, and then executing it when\n        // the time is right.\n        for(var n in transitionedTraces) {\n            var traceIndices = transitionedTraces[n];\n            var _module = gd._fullData[traceIndices[0]]._module;\n            _module.basePlotModule.plot(gd, traceIndices, traceTransitionOpts, makeCallback);\n        }\n    };\n\n    return _transition(gd, transitionOpts, opts);\n};\n\n/**\n * Transition to a set of new data and layout properties from Plotly.react\n *\n * @param {DOM element} gd\n * @param {object} restyleFlags\n * - anim {'all'|'some'}\n * @param {object} relayoutFlags\n * - anim {'all'|'some'}\n * @param {object} oldFullLayout : old (pre Plotly.react) fullLayout\n */\nplots.transitionFromReact = function(gd, restyleFlags, relayoutFlags, oldFullLayout) {\n    var fullLayout = gd._fullLayout;\n    var transitionOpts = fullLayout.transition;\n    var opts = {};\n    var axEdits = [];\n\n    opts.prepareFn = function() {\n        var subplots = fullLayout._plots;\n\n        // no need to redraw at end of transition,\n        // if all changes are animatable\n        opts.redraw = false;\n        if(restyleFlags.anim === 'some') opts.redraw = true;\n        if(relayoutFlags.anim === 'some') opts.redraw = true;\n\n        for(var k in subplots) {\n            var plotinfo = subplots[k];\n            var xa = plotinfo.xaxis;\n            var ya = plotinfo.yaxis;\n            var xr0 = oldFullLayout[xa._name].range.slice();\n            var yr0 = oldFullLayout[ya._name].range.slice();\n            var xr1 = xa.range.slice();\n            var yr1 = ya.range.slice();\n\n            xa.setScale();\n            ya.setScale();\n\n            var editX;\n            if(xr0[0] !== xr1[0] || xr0[1] !== xr1[1]) {\n                editX = {xr0: xr0, xr1: xr1};\n            }\n\n            var editY;\n            if(yr0[0] !== yr1[0] || yr0[1] !== yr1[1]) {\n                editY = {yr0: yr0, yr1: yr1};\n            }\n\n            if(editX || editY) {\n                axEdits.push(Lib.extendFlat({plotinfo: plotinfo}, editX, editY));\n            }\n        }\n\n        return Promise.resolve();\n    };\n\n    opts.runFn = function(makeCallback) {\n        var fullData = gd._fullData;\n        var fullLayout = gd._fullLayout;\n        var basePlotModules = fullLayout._basePlotModules;\n\n        var axisTransitionOpts;\n        var traceTransitionOpts;\n        var transitionedTraces;\n\n        var allTraceIndices = [];\n        for(var i = 0; i < fullData.length; i++) {\n            allTraceIndices.push(i);\n        }\n\n        function transitionAxes() {\n            for(var j = 0; j < basePlotModules.length; j++) {\n                if(basePlotModules[j].transitionAxes) {\n                    basePlotModules[j].transitionAxes(gd, axEdits, axisTransitionOpts, makeCallback);\n                }\n            }\n        }\n\n        function transitionTraces() {\n            for(var j = 0; j < basePlotModules.length; j++) {\n                basePlotModules[j].plot(gd, transitionedTraces, traceTransitionOpts, makeCallback);\n            }\n        }\n\n        if(axEdits.length && restyleFlags.anim) {\n            if(transitionOpts.ordering === 'traces first') {\n                axisTransitionOpts = Lib.extendFlat({}, transitionOpts, {duration: 0});\n                transitionedTraces = allTraceIndices;\n                traceTransitionOpts = transitionOpts;\n                transitionTraces();\n                setTimeout(transitionAxes, transitionOpts.duration);\n            } else {\n                axisTransitionOpts = transitionOpts;\n                transitionedTraces = null;\n                traceTransitionOpts = Lib.extendFlat({}, transitionOpts, {duration: 0});\n                transitionAxes();\n                transitionTraces();\n            }\n        } else if(axEdits.length) {\n            axisTransitionOpts = transitionOpts;\n            transitionAxes();\n        } else if(restyleFlags.anim) {\n            transitionedTraces = allTraceIndices;\n            traceTransitionOpts = transitionOpts;\n            transitionTraces();\n        }\n    };\n\n    return _transition(gd, transitionOpts, opts);\n};\n\n/**\n * trace/layout transition wrapper that works\n * for transitions initiated by Plotly.animate and Plotly.react.\n *\n * @param {DOM element} gd\n * @param {object} transitionOpts\n * @param {object} opts\n * - redraw {boolean}\n * - prepareFn {function} *should return a Promise*\n * - runFn {function} ran inside executeTransitions\n */\nfunction _transition(gd, transitionOpts, opts) {\n    var aborted = false;\n\n    function executeCallbacks(list) {\n        var p = Promise.resolve();\n        if(!list) return p;\n        while(list.length) {\n            p = p.then((list.shift()));\n        }\n        return p;\n    }\n\n    function flushCallbacks(list) {\n        if(!list) return;\n        while(list.length) {\n            list.shift();\n        }\n    }\n\n    function executeTransitions() {\n        gd.emit('plotly_transitioning', []);\n\n        return new Promise(function(resolve) {\n            // This flag is used to disabled things like autorange:\n            gd._transitioning = true;\n\n            // When instantaneous updates are coming through quickly, it's too much to simply disable\n            // all interaction, so store this flag so we can disambiguate whether mouse interactions\n            // should be fully disabled or not:\n            if(transitionOpts.duration > 0) {\n                gd._transitioningWithDuration = true;\n            }\n\n            // If another transition is triggered, this callback will be executed simply because it's\n            // in the interruptCallbacks queue. If this transition completes, it will instead flush\n            // that queue and forget about this callback.\n            gd._transitionData._interruptCallbacks.push(function() {\n                aborted = true;\n            });\n\n            if(opts.redraw) {\n                gd._transitionData._interruptCallbacks.push(function() {\n                    return Registry.call('redraw', gd);\n                });\n            }\n\n            // Emit this and make sure it happens last:\n            gd._transitionData._interruptCallbacks.push(function() {\n                gd.emit('plotly_transitioninterrupted', []);\n            });\n\n            // Construct callbacks that are executed on transition end. This ensures the d3 transitions\n            // are *complete* before anything else is done.\n            var numCallbacks = 0;\n            var numCompleted = 0;\n            function makeCallback() {\n                numCallbacks++;\n                return function() {\n                    numCompleted++;\n                    // When all are complete, perform a redraw:\n                    if(!aborted && numCompleted === numCallbacks) {\n                        completeTransition(resolve);\n                    }\n                };\n            }\n\n            opts.runFn(makeCallback);\n\n            // If nothing else creates a callback, then this will trigger the completion in the next tick:\n            setTimeout(makeCallback());\n        });\n    }\n\n    function completeTransition(callback) {\n        // This a simple workaround for tests which purge the graph before animations\n        // have completed. That's not a very common case, so this is the simplest\n        // fix.\n        if(!gd._transitionData) return;\n\n        flushCallbacks(gd._transitionData._interruptCallbacks);\n\n        return Promise.resolve().then(function() {\n            if(opts.redraw) {\n                return Registry.call('redraw', gd);\n            }\n        }).then(function() {\n            // Set transitioning false again once the redraw has occurred. This is used, for example,\n            // to prevent the trailing redraw from autoranging:\n            gd._transitioning = false;\n            gd._transitioningWithDuration = false;\n\n            gd.emit('plotly_transitioned', []);\n        }).then(callback);\n    }\n\n    function interruptPreviousTransitions() {\n        // Fail-safe against purged plot:\n        if(!gd._transitionData) return;\n\n        // If a transition is interrupted, set this to false. At the moment, the only thing that would\n        // interrupt a transition is another transition, so that it will momentarily be set to true\n        // again, but this determines whether autorange or dragbox work, so it's for the sake of\n        // cleanliness:\n        gd._transitioning = false;\n\n        return executeCallbacks(gd._transitionData._interruptCallbacks);\n    }\n\n    var seq = [\n        plots.previousPromises,\n        interruptPreviousTransitions,\n        opts.prepareFn,\n        plots.rehover,\n        executeTransitions\n    ];\n\n    var transitionStarting = Lib.syncOrAsync(seq, gd);\n\n    if(!transitionStarting || !transitionStarting.then) {\n        transitionStarting = Promise.resolve();\n    }\n\n    return transitionStarting.then(function() { return gd; });\n}\n\nplots.doCalcdata = function(gd, traces) {\n    var axList = axisIDs.list(gd);\n    var fullData = gd._fullData;\n    var fullLayout = gd._fullLayout;\n\n    var trace, _module, i, j;\n\n    // XXX: Is this correct? Needs a closer look so that *some* traces can be recomputed without\n    // *all* needing doCalcdata:\n    var calcdata = new Array(fullData.length);\n    var oldCalcdata = (gd.calcdata || []).slice();\n    gd.calcdata = calcdata;\n\n    // extra helper variables\n\n    // how many box/violins plots do we have (in case they're grouped)\n    fullLayout._numBoxes = 0;\n    fullLayout._numViolins = 0;\n\n    // initialize violin per-scale-group stats container\n    fullLayout._violinScaleGroupStats = {};\n\n    // for calculating avg luminosity of heatmaps\n    gd._hmpixcount = 0;\n    gd._hmlumcount = 0;\n\n    // for sharing colors across pies / sunbursts / funnelarea (and for legend)\n    fullLayout._piecolormap = {};\n    fullLayout._sunburstcolormap = {};\n    fullLayout._funnelareacolormap = {};\n\n    // If traces were specified and this trace was not included,\n    // then transfer it over from the old calcdata:\n    for(i = 0; i < fullData.length; i++) {\n        if(Array.isArray(traces) && traces.indexOf(i) === -1) {\n            calcdata[i] = oldCalcdata[i];\n            continue;\n        }\n    }\n\n    for(i = 0; i < fullData.length; i++) {\n        trace = fullData[i];\n\n        trace._arrayAttrs = PlotSchema.findArrayAttributes(trace);\n\n        // keep track of trace extremes (for autorange) in here\n        trace._extremes = {};\n    }\n\n    // add polar axes to axis list\n    var polarIds = fullLayout._subplots.polar || [];\n    for(i = 0; i < polarIds.length; i++) {\n        axList.push(\n            fullLayout[polarIds[i]].radialaxis,\n            fullLayout[polarIds[i]].angularaxis\n        );\n    }\n\n    var hasCalcTransform = false;\n\n    function transformCalci(i) {\n        trace = fullData[i];\n        _module = trace._module;\n\n        if(trace.visible === true && trace.transforms) {\n            // we need one round of trace module calc before\n            // the calc transform to 'fill in' the categories list\n            // used for example in the data-to-coordinate method\n            if(_module && _module.calc) {\n                var cdi = _module.calc(gd, trace);\n\n                // must clear scene 'batches', so that 2nd\n                // _module.calc call starts from scratch\n                if(cdi[0] && cdi[0].t && cdi[0].t._scene) {\n                    delete cdi[0].t._scene.dirty;\n                }\n            }\n\n            for(j = 0; j < trace.transforms.length; j++) {\n                var transform = trace.transforms[j];\n\n                _module = transformsRegistry[transform.type];\n                if(_module && _module.calcTransform) {\n                    trace._hasCalcTransform = true;\n                    hasCalcTransform = true;\n                    _module.calcTransform(gd, trace, transform);\n                }\n            }\n        }\n    }\n\n    function calci(i, isContainer) {\n        trace = fullData[i];\n        _module = trace._module;\n\n        if(!!_module.isContainer !== isContainer) return;\n\n        var cd = [];\n\n        if(trace.visible === true && trace._length !== 0) {\n            // clear existing ref in case it got relinked\n            delete trace._indexToPoints;\n            // keep ref of index-to-points map object of the *last* enabled transform,\n            // this index-to-points map object is required to determine the calcdata indices\n            // that correspond to input indices (e.g. from 'selectedpoints')\n            var transforms = trace.transforms || [];\n            for(j = transforms.length - 1; j >= 0; j--) {\n                if(transforms[j].enabled) {\n                    trace._indexToPoints = transforms[j]._indexToPoints;\n                    break;\n                }\n            }\n\n            if(_module && _module.calc) {\n                cd = _module.calc(gd, trace);\n            }\n        }\n\n        // Make sure there is a first point.\n        //\n        // This ensures there is a calcdata item for every trace,\n        // even if cartesian logic doesn't handle it (for things like legends).\n        if(!Array.isArray(cd) || !cd[0]) {\n            cd = [{x: BADNUM, y: BADNUM}];\n        }\n\n        // add the trace-wide properties to the first point,\n        // per point properties to every point\n        // t is the holder for trace-wide properties\n        if(!cd[0].t) cd[0].t = {};\n        cd[0].trace = trace;\n\n        calcdata[i] = cd;\n    }\n\n    setupAxisCategories(axList, fullData);\n\n    // 'transform' loop - must calc container traces first\n    // so that if their dependent traces can get transform properly\n    for(i = 0; i < fullData.length; i++) calci(i, true);\n    for(i = 0; i < fullData.length; i++) transformCalci(i);\n\n    // clear stuff that should recomputed in 'regular' loop\n    if(hasCalcTransform) setupAxisCategories(axList, fullData);\n\n    // 'regular' loop - make sure container traces (eg carpet) calc before\n    // contained traces (eg contourcarpet)\n    for(i = 0; i < fullData.length; i++) calci(i, true);\n    for(i = 0; i < fullData.length; i++) calci(i, false);\n\n    doCrossTraceCalc(gd);\n\n    // Sort axis categories per value if specified\n    var sorted = sortAxisCategoriesByValue(axList, gd);\n    if(sorted.length) {\n        // how many box/violins plots do we have (in case they're grouped)\n        fullLayout._numBoxes = 0;\n        fullLayout._numViolins = 0;\n        // If a sort operation was performed, run calc() again\n        for(i = 0; i < sorted.length; i++) calci(sorted[i], true);\n        for(i = 0; i < sorted.length; i++) calci(sorted[i], false);\n        doCrossTraceCalc(gd);\n    }\n\n    Registry.getComponentMethod('fx', 'calc')(gd);\n    Registry.getComponentMethod('errorbars', 'calc')(gd);\n};\n\nvar sortAxisCategoriesByValueRegex = /(total|sum|min|max|mean|median) (ascending|descending)/;\n\nfunction sortAxisCategoriesByValue(axList, gd) {\n    var affectedTraces = [];\n    var i, j, k, l, o;\n\n    function zMapCategory(type, ax, value) {\n        var axLetter = ax._id.charAt(0);\n        if(type === 'histogram2dcontour') {\n            var counterAxLetter = ax._counterAxes[0];\n            var counterAx = axisIDs.getFromId(gd, counterAxLetter);\n\n            var xCategorical = axLetter === 'x' || (counterAxLetter === 'x' && counterAx.type === 'category');\n            var yCategorical = axLetter === 'y' || (counterAxLetter === 'y' && counterAx.type === 'category');\n\n            return function(o, l) {\n                if(o === 0 || l === 0) return -1; // Skip first row and column\n                if(xCategorical && o === value[l].length - 1) return -1;\n                if(yCategorical && l === value.length - 1) return -1;\n\n                return (axLetter === 'y' ? l : o) - 1;\n            };\n        } else {\n            return function(o, l) {\n                return axLetter === 'y' ? l : o;\n            };\n        }\n    }\n\n    var aggFn = {\n        'min': function(values) {return Lib.aggNums(Math.min, null, values);},\n        'max': function(values) {return Lib.aggNums(Math.max, null, values);},\n        'sum': function(values) {return Lib.aggNums(function(a, b) { return a + b;}, null, values);},\n        'total': function(values) {return Lib.aggNums(function(a, b) { return a + b;}, null, values);},\n        'mean': function(values) {return Lib.mean(values);},\n        'median': function(values) {return Lib.median(values);}\n    };\n\n    for(i = 0; i < axList.length; i++) {\n        var ax = axList[i];\n        if(ax.type !== 'category') continue;\n\n        // Order by value\n        var match = ax.categoryorder.match(sortAxisCategoriesByValueRegex);\n        if(match) {\n            var aggregator = match[1];\n            var order = match[2];\n\n            // Store values associated with each category\n            var categoriesValue = [];\n            for(j = 0; j < ax._categories.length; j++) {\n                categoriesValue.push([ax._categories[j], []]);\n            }\n\n            // Collect values across traces\n            for(j = 0; j < ax._traceIndices.length; j++) {\n                var traceIndex = ax._traceIndices[j];\n                var fullTrace = gd._fullData[traceIndex];\n                var axLetter = ax._id.charAt(0);\n\n                // Skip over invisible traces\n                if(fullTrace.visible !== true) continue;\n\n                var type = fullTrace.type;\n                if(Registry.traceIs(fullTrace, 'histogram')) {\n                    delete fullTrace._xautoBinFinished;\n                    delete fullTrace._yautoBinFinished;\n                }\n\n                var cd = gd.calcdata[traceIndex];\n                for(k = 0; k < cd.length; k++) {\n                    var cdi = cd[k];\n                    var cat, catIndex, value;\n\n                    if(type === 'splom') {\n                        // If `splom`, collect values across dimensions\n                        // Find which dimension the current axis is representing\n                        var currentDimensionIndex = fullTrace._axesDim[ax._id];\n\n                        // Apply logic to associated x axis if it's defined\n                        if(axLetter === 'y') {\n                            var associatedXAxisID = fullTrace._diag[currentDimensionIndex][0];\n                            if(associatedXAxisID) ax = gd._fullLayout[axisIDs.id2name(associatedXAxisID)];\n                        }\n\n                        var categories = cdi.trace.dimensions[currentDimensionIndex].values;\n                        for(l = 0; l < categories.length; l++) {\n                            cat = categories[l];\n                            catIndex = ax._categoriesMap[cat];\n\n                            // Collect associated values at index `l` over all other dimensions\n                            for(o = 0; o < cdi.trace.dimensions.length; o++) {\n                                if(o === currentDimensionIndex) continue;\n                                var dimension = cdi.trace.dimensions[o];\n                                categoriesValue[catIndex][1].push(dimension.values[l]);\n                            }\n                        }\n                    } else if(type === 'scattergl') {\n                        // If `scattergl`, collect all values stashed under cdi.t\n                        for(l = 0; l < cdi.t.x.length; l++) {\n                            if(axLetter === 'x') {\n                                cat = cdi.t.x[l];\n                                catIndex = cat;\n                                value = cdi.t.y[l];\n                            }\n\n                            if(axLetter === 'y') {\n                                cat = cdi.t.y[l];\n                                catIndex = cat;\n                                value = cdi.t.x[l];\n                            }\n                            categoriesValue[catIndex][1].push(value);\n                        }\n                        // must clear scene 'batches', so that 2nd\n                        // _module.calc call starts from scratch\n                        if(cdi.t && cdi.t._scene) {\n                            delete cdi.t._scene.dirty;\n                        }\n                    } else if(cdi.hasOwnProperty('z')) {\n                        // If 2dMap, collect values in `z`\n                        value = cdi.z;\n                        var mapping = zMapCategory(fullTrace.type, ax, value);\n\n                        for(l = 0; l < value.length; l++) {\n                            for(o = 0; o < value[l].length; o++) {\n                                catIndex = mapping(o, l);\n                                if(catIndex + 1) categoriesValue[catIndex][1].push(value[l][o]);\n                            }\n                        }\n                    } else {\n                        // For all other 2d cartesian traces\n                        if(axLetter === 'x') {\n                            cat = cdi.p + 1 ? cdi.p : cdi.x;\n                            value = cdi.s || cdi.v || cdi.y;\n                        } else if(axLetter === 'y') {\n                            cat = cdi.p + 1 ? cdi.p : cdi.y;\n                            value = cdi.s || cdi.v || cdi.x;\n                        }\n                        if(!Array.isArray(value)) value = [value];\n                        for(l = 0; l < value.length; l++) {\n                            categoriesValue[cat][1].push(value[l]);\n                        }\n                    }\n                }\n            }\n\n            ax._categoriesValue = categoriesValue;\n\n            var categoriesAggregatedValue = [];\n            for(j = 0; j < categoriesValue.length; j++) {\n                categoriesAggregatedValue.push([\n                    categoriesValue[j][0],\n                    aggFn[aggregator](categoriesValue[j][1])\n                ]);\n            }\n\n            // Sort by aggregated value\n            categoriesAggregatedValue.sort(function(a, b) {\n                return a[1] - b[1];\n            });\n\n            ax._categoriesAggregatedValue = categoriesAggregatedValue;\n\n            // Set new category order\n            ax._initialCategories = categoriesAggregatedValue.map(function(c) {\n                return c[0];\n            });\n\n            // Reverse if descending\n            if(order === 'descending') {\n                ax._initialCategories.reverse();\n            }\n\n            // Sort all matching axes\n            affectedTraces = affectedTraces.concat(ax.sortByInitialCategories());\n        }\n    }\n    return affectedTraces;\n}\n\nfunction setupAxisCategories(axList, fullData) {\n    for(var i = 0; i < axList.length; i++) {\n        var ax = axList[i];\n        ax.clearCalc();\n        if(ax.type === 'multicategory') {\n            ax.setupMultiCategory(fullData);\n        }\n    }\n}\n\nfunction doCrossTraceCalc(gd) {\n    var fullLayout = gd._fullLayout;\n    var modules = fullLayout._visibleModules;\n    var hash = {};\n    var i, j, k;\n\n    // position and range calculations for traces that\n    // depend on each other ie bars (stacked or grouped)\n    // and boxes (grouped) push each other out of the way\n\n    for(j = 0; j < modules.length; j++) {\n        var _module = modules[j];\n        var fn = _module.crossTraceCalc;\n        if(fn) {\n            var spType = _module.basePlotModule.name;\n            if(hash[spType]) {\n                Lib.pushUnique(hash[spType], fn);\n            } else {\n                hash[spType] = [fn];\n            }\n        }\n    }\n\n    for(k in hash) {\n        var methods = hash[k];\n        var subplots = fullLayout._subplots[k];\n\n        if(Array.isArray(subplots)) {\n            for(i = 0; i < subplots.length; i++) {\n                var sp = subplots[i];\n                var spInfo = k === 'cartesian' ?\n                    fullLayout._plots[sp] :\n                    fullLayout[sp];\n\n                for(j = 0; j < methods.length; j++) {\n                    methods[j](gd, spInfo, sp);\n                }\n            }\n        } else {\n            for(j = 0; j < methods.length; j++) {\n                methods[j](gd);\n            }\n        }\n    }\n}\n\nplots.rehover = function(gd) {\n    if(gd._fullLayout._rehover) {\n        gd._fullLayout._rehover();\n    }\n};\n\nplots.redrag = function(gd) {\n    if(gd._fullLayout._redrag) {\n        gd._fullLayout._redrag();\n    }\n};\n\nplots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subplotLayout) {\n    var traceHashOld = subplot.traceHash;\n    var traceHash = {};\n    var i;\n\n    // build up moduleName -> calcData hash\n    for(i = 0; i < subplotCalcData.length; i++) {\n        var calcTraces = subplotCalcData[i];\n        var trace = calcTraces[0].trace;\n\n        // skip over visible === false traces\n        // as they don't have `_module` ref\n        if(trace.visible) {\n            traceHash[trace.type] = traceHash[trace.type] || [];\n            traceHash[trace.type].push(calcTraces);\n        }\n    }\n\n    // when a trace gets deleted, make sure that its module's\n    // plot method is called so that it is properly\n    // removed from the DOM.\n    for(var moduleNameOld in traceHashOld) {\n        if(!traceHash[moduleNameOld]) {\n            var fakeCalcTrace = traceHashOld[moduleNameOld][0];\n            var fakeTrace = fakeCalcTrace[0].trace;\n\n            fakeTrace.visible = false;\n            traceHash[moduleNameOld] = [fakeCalcTrace];\n        }\n    }\n\n    // call module plot method\n    for(var moduleName in traceHash) {\n        var moduleCalcData = traceHash[moduleName];\n        var _module = moduleCalcData[0][0].trace._module;\n\n        _module.plot(gd, subplot, Lib.filterVisible(moduleCalcData), subplotLayout);\n    }\n\n    // update moduleName -> calcData hash\n    subplot.traceHash = traceHash;\n};\n\n},{\"../components/color\":593,\"../constants/numerical\":695,\"../lib\":719,\"../plot_api/plot_schema\":756,\"../plot_api/plot_template\":757,\"../registry\":847,\"./animation_attributes\":762,\"./attributes\":764,\"./cartesian/axis_ids\":770,\"./command\":791,\"./font_attributes\":793,\"./frame_attributes\":794,\"./layout_attributes\":819,\"d3\":163,\"fast-isnumeric\":225}],829:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attr: 'subplot',\n    name: 'polar',\n\n    axisNames: ['angularaxis', 'radialaxis'],\n    axisName2dataArray: {angularaxis: 'theta', radialaxis: 'r'},\n\n    layerNames: [\n        'draglayer',\n        'plotbg',\n        'backplot',\n        'angular-grid',\n        'radial-grid',\n        'frontplot',\n        'angular-line',\n        'radial-line',\n        'angular-axis',\n        'radial-axis'\n    ],\n\n    radialDragBoxSize: 50,\n    angularDragBoxSize: 30,\n    cornerLen: 25,\n    cornerHalfWidth: 2,\n\n    // pixels to move mouse before you stop clamping to starting point\n    MINDRAG: 8,\n    // smallest radial distance [px] allowed for a zoombox\n    MINZOOM: 20,\n    // distance [px] off (r=0) or (r=radius) where we transition\n    // from single-sided to two-sided radial zoom\n    OFFEDGE: 20\n};\n\n},{}],830:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar polygonTester = _dereq_('../../lib/polygon').tester;\n\nvar findIndexOfMin = Lib.findIndexOfMin;\nvar isAngleInsideSector = Lib.isAngleInsideSector;\nvar angleDelta = Lib.angleDelta;\nvar angleDist = Lib.angleDist;\n\n/**\n * is pt (r,a) inside polygon made up vertices at angles 'vangles'\n * inside a given polar sector\n *\n * @param {number} r : pt's radial coordinate\n * @param {number} a : pt's angular coordinate in *radians*\n * @param {2-item array} rBnds : sector's radial bounds\n * @param {2-item array} aBnds : sector's angular bounds *radians*\n * @param {array} vangles : angles of polygon vertices in *radians*\n * @return {boolean}\n */\nfunction isPtInsidePolygon(r, a, rBnds, aBnds, vangles) {\n    if(!isAngleInsideSector(a, aBnds)) return false;\n\n    var r0, r1;\n\n    if(rBnds[0] < rBnds[1]) {\n        r0 = rBnds[0];\n        r1 = rBnds[1];\n    } else {\n        r0 = rBnds[1];\n        r1 = rBnds[0];\n    }\n\n    var polygonIn = polygonTester(makePolygon(r0, aBnds[0], aBnds[1], vangles));\n    var polygonOut = polygonTester(makePolygon(r1, aBnds[0], aBnds[1], vangles));\n    var xy = [r * Math.cos(a), r * Math.sin(a)];\n    return polygonOut.contains(xy) && !polygonIn.contains(xy);\n}\n\n// find intersection of 'v0' <-> 'v1' edge with a ray at angle 'a'\n// (i.e. a line that starts from the origin at angle 'a')\n// given an (xp,yp) pair on the 'v0' <-> 'v1' line\n// (N.B. 'v0' and 'v1' are angles in radians)\nfunction findIntersectionXY(v0, v1, a, xpyp) {\n    var xstar, ystar;\n\n    var xp = xpyp[0];\n    var yp = xpyp[1];\n    var dsin = clampTiny(Math.sin(v1) - Math.sin(v0));\n    var dcos = clampTiny(Math.cos(v1) - Math.cos(v0));\n    var tanA = Math.tan(a);\n    var cotanA = clampTiny(1 / tanA);\n    var m = dsin / dcos;\n    var b = yp - m * xp;\n\n    if(cotanA) {\n        if(dsin && dcos) {\n            // given\n            //  g(x) := v0 -> v1 line = m*x + b\n            //  h(x) := ray at angle 'a' = m*x = tanA*x\n            // solve g(xstar) = h(xstar)\n            xstar = b / (tanA - m);\n            ystar = tanA * xstar;\n        } else if(dcos) {\n            // horizontal v0 -> v1\n            xstar = yp * cotanA;\n            ystar = yp;\n        } else {\n            // vertical v0 -> v1\n            xstar = xp;\n            ystar = xp * tanA;\n        }\n    } else {\n        // vertical ray\n        if(dsin && dcos) {\n            xstar = 0;\n            ystar = b;\n        } else if(dcos) {\n            xstar = 0;\n            ystar = yp;\n        } else {\n            // does this case exists?\n            xstar = ystar = NaN;\n        }\n    }\n\n    return [xstar, ystar];\n}\n\n// solves l^2 = (f(x)^2 - yp)^2 + (x - xp)^2\n// rearranged into 0 = a*x^2 + b * x + c\n//\n// where f(x) = m*x + t + yp\n// and   (x0, x1) = (-b +/- del) / (2*a)\nfunction findXYatLength(l, m, xp, yp) {\n    var t = -m * xp;\n    var a = m * m + 1;\n    var b = 2 * (m * t - xp);\n    var c = t * t + xp * xp - l * l;\n    var del = Math.sqrt(b * b - 4 * a * c);\n    var x0 = (-b + del) / (2 * a);\n    var x1 = (-b - del) / (2 * a);\n    return [\n        [x0, m * x0 + t + yp],\n        [x1, m * x1 + t + yp]\n    ];\n}\n\nfunction makeRegularPolygon(r, vangles) {\n    var len = vangles.length;\n    var vertices = new Array(len + 1);\n    var i;\n    for(i = 0; i < len; i++) {\n        var va = vangles[i];\n        vertices[i] = [r * Math.cos(va), r * Math.sin(va)];\n    }\n    vertices[i] = vertices[0].slice();\n    return vertices;\n}\n\nfunction makeClippedPolygon(r, a0, a1, vangles) {\n    var len = vangles.length;\n    var vertices = [];\n    var i, j;\n\n    function a2xy(a) {\n        return [r * Math.cos(a), r * Math.sin(a)];\n    }\n\n    function findXY(va0, va1, s) {\n        return findIntersectionXY(va0, va1, s, a2xy(va0));\n    }\n\n    function cycleIndex(ind) {\n        return Lib.mod(ind, len);\n    }\n\n    function isInside(v) {\n        return isAngleInsideSector(v, [a0, a1]);\n    }\n\n    // find index in sector closest to a0\n    // use it to find intersection of v[i0] <-> v[i0-1] edge with sector radius\n    var i0 = findIndexOfMin(vangles, function(v) {\n        return isInside(v) ? angleDist(v, a0) : Infinity;\n    });\n    var xy0 = findXY(vangles[i0], vangles[cycleIndex(i0 - 1)], a0);\n    vertices.push(xy0);\n\n    // fill in in-sector vertices\n    for(i = i0, j = 0; j < len; i++, j++) {\n        var va = vangles[cycleIndex(i)];\n        if(!isInside(va)) break;\n        vertices.push(a2xy(va));\n    }\n\n    // find index in sector closest to a1,\n    // use it to find intersection of v[iN] <-> v[iN+1] edge with sector radius\n    var iN = findIndexOfMin(vangles, function(v) {\n        return isInside(v) ? angleDist(v, a1) : Infinity;\n    });\n    var xyN = findXY(vangles[iN], vangles[cycleIndex(iN + 1)], a1);\n    vertices.push(xyN);\n\n    vertices.push([0, 0]);\n    vertices.push(vertices[0].slice());\n\n    return vertices;\n}\n\nfunction makePolygon(r, a0, a1, vangles) {\n    return Lib.isFullCircle([a0, a1]) ?\n        makeRegularPolygon(r, vangles) :\n        makeClippedPolygon(r, a0, a1, vangles);\n}\n\nfunction findPolygonOffset(r, a0, a1, vangles) {\n    var minX = Infinity;\n    var minY = Infinity;\n    var vertices = makePolygon(r, a0, a1, vangles);\n\n    for(var i = 0; i < vertices.length; i++) {\n        var v = vertices[i];\n        minX = Math.min(minX, v[0]);\n        minY = Math.min(minY, -v[1]);\n    }\n    return [minX, minY];\n}\n\n/**\n * find vertex angles (in 'vangles') the enclose angle 'a'\n *\n * @param {number} a : angle in *radians*\n * @param {array} vangles : angles of polygon vertices in *radians*\n * @return {2-item array}\n */\nfunction findEnclosingVertexAngles(a, vangles) {\n    var minFn = function(v) {\n        var adelta = angleDelta(v, a);\n        return adelta > 0 ? adelta : Infinity;\n    };\n    var i0 = findIndexOfMin(vangles, minFn);\n    var i1 = Lib.mod(i0 + 1, vangles.length);\n    return [vangles[i0], vangles[i1]];\n}\n\n// to more easily catch 'almost zero' numbers in if-else blocks\nfunction clampTiny(v) {\n    return Math.abs(v) > 1e-10 ? v : 0;\n}\n\nfunction transformForSVG(pts0, cx, cy) {\n    cx = cx || 0;\n    cy = cy || 0;\n\n    var len = pts0.length;\n    var pts1 = new Array(len);\n\n    for(var i = 0; i < len; i++) {\n        var pt = pts0[i];\n        pts1[i] = [cx + pt[0], cy - pt[1]];\n    }\n    return pts1;\n}\n\n/**\n * path polygon\n *\n * @param {number} r : polygon 'radius'\n * @param {number} a0 : first angular coordinate in *radians*\n * @param {number} a1 : second angular coordinate in *radians*\n * @param {array} vangles : angles of polygon vertices in *radians*\n * @param {number (optional)} cx : x coordinate of center\n * @param {number (optional)} cy : y coordinate of center\n * @return {string} svg path\n *\n */\nfunction pathPolygon(r, a0, a1, vangles, cx, cy) {\n    var poly = makePolygon(r, a0, a1, vangles);\n    return 'M' + transformForSVG(poly, cx, cy).join('L');\n}\n\n/**\n * path a polygon 'annulus'\n * i.e. a polygon with a concentric hole\n *\n * N.B. this routine uses the evenodd SVG rule\n *\n * @param {number} r0 : first radial coordinate\n * @param {number} r1 : second radial coordinate\n * @param {number} a0 : first angular coordinate in *radians*\n * @param {number} a1 : second angular coordinate in *radians*\n * @param {array} vangles : angles of polygon vertices in *radians*\n * @param {number (optional)} cx : x coordinate of center\n * @param {number (optional)} cy : y coordinate of center\n * @return {string} svg path\n *\n */\nfunction pathPolygonAnnulus(r0, r1, a0, a1, vangles, cx, cy) {\n    var rStart, rEnd;\n\n    if(r0 < r1) {\n        rStart = r0;\n        rEnd = r1;\n    } else {\n        rStart = r1;\n        rEnd = r0;\n    }\n\n    var inner = transformForSVG(makePolygon(rStart, a0, a1, vangles), cx, cy);\n    var outer = transformForSVG(makePolygon(rEnd, a0, a1, vangles), cx, cy);\n    return 'M' + outer.reverse().join('L') + 'M' + inner.join('L');\n}\n\nmodule.exports = {\n    isPtInsidePolygon: isPtInsidePolygon,\n    findPolygonOffset: findPolygonOffset,\n    findEnclosingVertexAngles: findEnclosingVertexAngles,\n    findIntersectionXY: findIntersectionXY,\n    findXYatLength: findXYatLength,\n    clampTiny: clampTiny,\n    pathPolygon: pathPolygon,\n    pathPolygonAnnulus: pathPolygonAnnulus\n};\n\n},{\"../../lib\":719,\"../../lib/polygon\":731}],831:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar getSubplotCalcData = _dereq_('../get_data').getSubplotCalcData;\nvar counterRegex = _dereq_('../../lib').counterRegex;\n\nvar createPolar = _dereq_('./polar');\nvar constants = _dereq_('./constants');\n\nvar attr = constants.attr;\nvar name = constants.name;\nvar counter = counterRegex(name);\n\nvar attributes = {};\nattributes[attr] = {\n    valType: 'subplotid',\n    \n    dflt: name,\n    editType: 'calc',\n    \n};\n\nfunction plot(gd) {\n    var fullLayout = gd._fullLayout;\n    var calcData = gd.calcdata;\n    var subplotIds = fullLayout._subplots[name];\n\n    for(var i = 0; i < subplotIds.length; i++) {\n        var id = subplotIds[i];\n        var subplotCalcData = getSubplotCalcData(calcData, name, id);\n        var subplot = fullLayout[id]._subplot;\n\n        if(!subplot) {\n            subplot = createPolar(gd, id);\n            fullLayout[id]._subplot = subplot;\n        }\n\n        subplot.plot(subplotCalcData, fullLayout, gd._promises);\n    }\n}\n\nfunction clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var oldIds = oldFullLayout._subplots[name] || [];\n    var hadGl = (oldFullLayout._has && oldFullLayout._has('gl'));\n    var hasGl = (newFullLayout._has && newFullLayout._has('gl'));\n    var mustCleanScene = hadGl && !hasGl;\n\n    for(var i = 0; i < oldIds.length; i++) {\n        var id = oldIds[i];\n        var oldSubplot = oldFullLayout[id]._subplot;\n\n        if(!newFullLayout[id] && !!oldSubplot) {\n            oldSubplot.framework.remove();\n            oldSubplot.layers['radial-axis-title'].remove();\n\n            for(var k in oldSubplot.clipPaths) {\n                oldSubplot.clipPaths[k].remove();\n            }\n        }\n\n        if(mustCleanScene && oldSubplot._scene) {\n            oldSubplot._scene.destroy();\n            oldSubplot._scene = null;\n        }\n    }\n}\n\nmodule.exports = {\n    attr: attr,\n    name: name,\n    idRoot: name,\n    idRegex: counter,\n    attrRegex: counter,\n    attributes: attributes,\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n    plot: plot,\n    clean: clean,\n    toSVG: _dereq_('../cartesian').toSVG\n};\n\n},{\"../../lib\":719,\"../cartesian\":778,\"../get_data\":802,\"./constants\":829,\"./layout_attributes\":832,\"./layout_defaults\":833,\"./polar\":840}],832:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar axesAttrs = _dereq_('../cartesian/layout_attributes');\nvar domainAttrs = _dereq_('../domain').attributes;\nvar extendFlat = _dereq_('../../lib').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar axisLineGridAttr = overrideAll({\n    color: axesAttrs.color,\n    showline: extendFlat({}, axesAttrs.showline, {dflt: true}),\n    linecolor: axesAttrs.linecolor,\n    linewidth: axesAttrs.linewidth,\n    showgrid: extendFlat({}, axesAttrs.showgrid, {dflt: true}),\n    gridcolor: axesAttrs.gridcolor,\n    gridwidth: axesAttrs.gridwidth\n\n    // TODO add spike* attributes down the road\n\n    // should we add zeroline* attributes?\n\n}, 'plot', 'from-root');\n\nvar axisTickAttrs = overrideAll({\n    tickmode: axesAttrs.tickmode,\n    nticks: axesAttrs.nticks,\n    tick0: axesAttrs.tick0,\n    dtick: axesAttrs.dtick,\n    tickvals: axesAttrs.tickvals,\n    ticktext: axesAttrs.ticktext,\n    ticks: axesAttrs.ticks,\n    ticklen: axesAttrs.ticklen,\n    tickwidth: axesAttrs.tickwidth,\n    tickcolor: axesAttrs.tickcolor,\n    showticklabels: axesAttrs.showticklabels,\n    showtickprefix: axesAttrs.showtickprefix,\n    tickprefix: axesAttrs.tickprefix,\n    showticksuffix: axesAttrs.showticksuffix,\n    ticksuffix: axesAttrs.ticksuffix,\n    showexponent: axesAttrs.showexponent,\n    exponentformat: axesAttrs.exponentformat,\n    separatethousands: axesAttrs.separatethousands,\n    tickfont: axesAttrs.tickfont,\n    tickangle: axesAttrs.tickangle,\n    tickformat: axesAttrs.tickformat,\n    tickformatstops: axesAttrs.tickformatstops,\n    layer: axesAttrs.layer\n}, 'plot', 'from-root');\n\nvar radialAxisAttrs = {\n    visible: extendFlat({}, axesAttrs.visible, {dflt: true}),\n    type: extendFlat({}, axesAttrs.type, {\n        values: ['-', 'linear', 'log', 'date', 'category']\n    }),\n\n    autorange: extendFlat({}, axesAttrs.autorange, {editType: 'plot'}),\n    rangemode: {\n        valType: 'enumerated',\n        values: ['tozero', 'nonnegative', 'normal'],\n        dflt: 'tozero',\n        \n        editType: 'calc',\n        \n    },\n    range: extendFlat({}, axesAttrs.range, {\n        items: [\n            {valType: 'any', editType: 'plot', impliedEdits: {'^autorange': false}},\n            {valType: 'any', editType: 'plot', impliedEdits: {'^autorange': false}}\n        ],\n        editType: 'plot'\n    }),\n\n    categoryorder: axesAttrs.categoryorder,\n    categoryarray: axesAttrs.categoryarray,\n\n    angle: {\n        valType: 'angle',\n        editType: 'plot',\n        \n        \n    },\n\n    side: {\n        valType: 'enumerated',\n        // TODO add 'center' for `showline: false` radial axes\n        values: ['clockwise', 'counterclockwise'],\n        dflt: 'clockwise',\n        editType: 'plot',\n        \n        \n    },\n\n\n    title: overrideAll(axesAttrs.title, 'plot', 'from-root'),\n    // might need a 'titleside' and even 'titledirection' down the road\n\n    hoverformat: axesAttrs.hoverformat,\n\n    uirevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n\n    editType: 'calc',\n\n    _deprecated: {\n        title: axesAttrs._deprecated.title,\n        titlefont: axesAttrs._deprecated.titlefont\n    }\n};\n\n// radial title is not gui-editable, so it needs dflt: '', similar to carpet axes.\nradialAxisAttrs.title.text.dflt = '';\n\nextendFlat(\n    radialAxisAttrs,\n\n    // N.B. radialaxis grid lines are circular,\n    // but radialaxis lines are straight from circle center to outer bound\n    axisLineGridAttr,\n    axisTickAttrs\n);\n\nvar angularAxisAttrs = {\n    visible: extendFlat({}, axesAttrs.visible, {dflt: true}),\n    type: {\n        valType: 'enumerated',\n        // 'linear' should maybe be called 'angle' or 'angular' here\n        // to make clear that axis here is periodic and more tightly match\n        // `thetaunit`?\n        //\n        // skip 'date' for first push\n        // no 'log' for now\n        values: ['-', 'linear', 'category'],\n        dflt: '-',\n        \n        editType: 'calc',\n        _noTemplating: true,\n        \n    },\n\n    categoryorder: axesAttrs.categoryorder,\n    categoryarray: axesAttrs.categoryarray,\n\n    thetaunit: {\n        valType: 'enumerated',\n        values: ['radians', 'degrees'],\n        dflt: 'degrees',\n        \n        editType: 'calc',\n        \n    },\n\n    period: {\n        valType: 'number',\n        editType: 'calc',\n        min: 0,\n        \n        \n        // Examples for date axes:\n        //\n        // - period that equals the timeseries length\n        //  http://flowingdata.com/2017/01/24/one-dataset-visualized-25-ways/18-polar-coordinates/\n        // - and 1-year periods (focusing on seasonal change0\n        //  http://otexts.org/fpp2/seasonal-plots.html\n        //  https://blogs.scientificamerican.com/sa-visual/why-are-so-many-babies-born-around-8-00-a-m/\n        //  http://www.seasonaladjustment.com/2012/09/05/clock-plot-visualising-seasonality-using-r-and-ggplot2-part-3/\n        //  https://i.pinimg.com/736x/49/b9/72/49b972ccb3206a1a6d6f870dac543280.jpg\n        //  https://www.climate-lab-book.ac.uk/spirals/\n    },\n\n    direction: {\n        valType: 'enumerated',\n        values: ['counterclockwise', 'clockwise'],\n        dflt: 'counterclockwise',\n        \n        editType: 'calc',\n        \n    },\n\n    rotation: {\n        valType: 'angle',\n        editType: 'calc',\n        \n        \n    },\n\n    hoverformat: axesAttrs.hoverformat,\n\n    uirevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n\n    editType: 'calc'\n};\n\nextendFlat(\n    angularAxisAttrs,\n\n    // N.B. angular grid lines are straight lines from circle center to outer bound\n    // the angular line is circular bounding the polar plot area.\n    axisLineGridAttr,\n\n    // N.B. ticksuffix defaults to '°' for angular axes with `thetaunit: 'degrees'`\n    axisTickAttrs\n);\n\nmodule.exports = {\n    // TODO for x/y/zoom system for paper-based zooming:\n    // x: {},\n    // y: {},\n    // zoom: {},\n\n    domain: domainAttrs({name: 'polar', editType: 'plot'}),\n\n    sector: {\n        valType: 'info_array',\n        items: [\n            {valType: 'number', editType: 'plot'},\n            {valType: 'number', editType: 'plot'}\n        ],\n        dflt: [0, 360],\n        \n        editType: 'plot',\n        \n    },\n    hole: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 0,\n        editType: 'plot',\n        \n        \n    },\n\n    bgcolor: {\n        valType: 'color',\n        \n        editType: 'plot',\n        dflt: colorAttrs.background,\n        \n    },\n\n    radialaxis: radialAxisAttrs,\n    angularaxis: angularAxisAttrs,\n\n    gridshape: {\n        valType: 'enumerated',\n        values: ['circular', 'linear'],\n        dflt: 'circular',\n        \n        editType: 'plot',\n        \n    },\n\n    // TODO maybe?\n    // annotations:\n\n    uirevision: {\n        valType: 'any',\n        \n        editType: 'none',\n        \n    },\n\n    editType: 'calc'\n};\n\n},{\"../../components/color/attributes\":592,\"../../lib\":719,\"../../plot_api/edit_types\":750,\"../cartesian/layout_attributes\":779,\"../domain\":792}],833:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\nvar Template = _dereq_('../../plot_api/plot_template');\n\nvar handleSubplotDefaults = _dereq_('../subplot_defaults');\nvar getSubplotData = _dereq_('../get_data').getSubplotData;\n\nvar handleTickValueDefaults = _dereq_('../cartesian/tick_value_defaults');\nvar handleTickMarkDefaults = _dereq_('../cartesian/tick_mark_defaults');\nvar handleTickLabelDefaults = _dereq_('../cartesian/tick_label_defaults');\nvar handleCategoryOrderDefaults = _dereq_('../cartesian/category_order_defaults');\nvar handleLineGridDefaults = _dereq_('../cartesian/line_grid_defaults');\nvar autoType = _dereq_('../cartesian/axis_autotype');\n\nvar layoutAttributes = _dereq_('./layout_attributes');\nvar setConvert = _dereq_('./set_convert');\nvar constants = _dereq_('./constants');\nvar axisNames = constants.axisNames;\n\nfunction handleDefaults(contIn, contOut, coerce, opts) {\n    var bgColor = coerce('bgcolor');\n    opts.bgColor = Color.combine(bgColor, opts.paper_bgcolor);\n\n    var sector = coerce('sector');\n    coerce('hole');\n\n    // could optimize, subplotData is not always needed!\n    var subplotData = getSubplotData(opts.fullData, constants.name, opts.id);\n    var layoutOut = opts.layoutOut;\n    var axName;\n\n    function coerceAxis(attr, dflt) {\n        return coerce(axName + '.' + attr, dflt);\n    }\n\n    for(var i = 0; i < axisNames.length; i++) {\n        axName = axisNames[i];\n\n        if(!Lib.isPlainObject(contIn[axName])) {\n            contIn[axName] = {};\n        }\n\n        var axIn = contIn[axName];\n        var axOut = Template.newContainer(contOut, axName);\n        axOut._id = axOut._name = axName;\n        axOut._attr = opts.id + '.' + axName;\n        axOut._traceIndices = subplotData.map(function(t) { return t._expandedIndex; });\n\n        var dataAttr = constants.axisName2dataArray[axName];\n        var axType = handleAxisTypeDefaults(axIn, axOut, coerceAxis, subplotData, dataAttr);\n\n        handleCategoryOrderDefaults(axIn, axOut, coerceAxis, {\n            axData: subplotData,\n            dataAttr: dataAttr\n        });\n\n        var visible = coerceAxis('visible');\n        setConvert(axOut, contOut, layoutOut);\n\n        coerceAxis('uirevision', contOut.uirevision);\n\n        var dfltColor;\n        var dfltFontColor;\n\n        if(visible) {\n            dfltColor = coerceAxis('color');\n            dfltFontColor = (dfltColor === axIn.color) ? dfltColor : opts.font.color;\n        }\n\n        // We don't want to make downstream code call ax.setScale,\n        // as both radial and angular axes don't have a set domain.\n        // Furthermore, angular axes don't have a set range.\n        //\n        // Mocked domains and ranges are set by the polar subplot instances,\n        // but Axes.findExtremes uses the sign of _m to determine which padding value\n        // to use.\n        //\n        // By setting, _m to 1 here, we make Axes.findExtremes think that\n        // range[1] > range[0], and vice-versa for `autorange: 'reversed'` below.\n        axOut._m = 1;\n\n        switch(axName) {\n            case 'radialaxis':\n                var autoRange = coerceAxis('autorange', !axOut.isValidRange(axIn.range));\n                axIn.autorange = autoRange;\n                if(autoRange && (axType === 'linear' || axType === '-')) coerceAxis('rangemode');\n                if(autoRange === 'reversed') axOut._m = -1;\n\n                coerceAxis('range');\n                axOut.cleanRange('range', {dfltRange: [0, 1]});\n\n                if(visible) {\n                    coerceAxis('side');\n                    coerceAxis('angle', sector[0]);\n\n                    coerceAxis('title.text');\n                    Lib.coerceFont(coerceAxis, 'title.font', {\n                        family: opts.font.family,\n                        size: Math.round(opts.font.size * 1.2),\n                        color: dfltFontColor\n                    });\n                }\n                break;\n\n            case 'angularaxis':\n                // We do not support 'true' date angular axes yet,\n                // users can still plot dates on angular axes by setting\n                // `angularaxis.type: 'category'`.\n                //\n                // Here, if a date angular axes is detected, we make\n                // all its corresponding traces invisible, so that\n                // when we do add support for data angular axes, the new\n                // behavior won't conflict with existing behavior\n                if(axType === 'date') {\n                    Lib.log('Polar plots do not support date angular axes yet.');\n\n                    for(var j = 0; j < subplotData.length; j++) {\n                        subplotData[j].visible = false;\n                    }\n\n                    // turn this into a 'dummy' linear axis so that\n                    // the subplot still renders ok\n                    axType = axIn.type = axOut.type = 'linear';\n                }\n\n                if(axType === 'linear') {\n                    coerceAxis('thetaunit');\n                } else {\n                    coerceAxis('period');\n                }\n\n                var direction = coerceAxis('direction');\n                coerceAxis('rotation', {counterclockwise: 0, clockwise: 90}[direction]);\n                break;\n        }\n\n        if(visible) {\n            handleTickValueDefaults(axIn, axOut, coerceAxis, axOut.type);\n            handleTickLabelDefaults(axIn, axOut, coerceAxis, axOut.type, {\n                tickSuffixDflt: axOut.thetaunit === 'degrees' ? '°' : undefined\n            });\n            handleTickMarkDefaults(axIn, axOut, coerceAxis, {outerTicks: true});\n\n            var showTickLabels = coerceAxis('showticklabels');\n            if(showTickLabels) {\n                Lib.coerceFont(coerceAxis, 'tickfont', {\n                    family: opts.font.family,\n                    size: opts.font.size,\n                    color: dfltFontColor\n                });\n                coerceAxis('tickangle');\n                coerceAxis('tickformat');\n            }\n\n            handleLineGridDefaults(axIn, axOut, coerceAxis, {\n                dfltColor: dfltColor,\n                bgColor: opts.bgColor,\n                // default grid color is darker here (60%, vs cartesian default ~91%)\n                // because the grid is not square so the eye needs heavier cues to follow\n                blend: 60,\n                showLine: true,\n                showGrid: true,\n                noZeroLine: true,\n                attributes: layoutAttributes[axName]\n            });\n\n            coerceAxis('layer');\n        }\n\n        if(axType !== 'category') coerceAxis('hoverformat');\n\n        axOut._input = axIn;\n    }\n\n    if(contOut.angularaxis.type === 'category') {\n        coerce('gridshape');\n    }\n}\n\nfunction handleAxisTypeDefaults(axIn, axOut, coerce, subplotData, dataAttr) {\n    var axType = coerce('type');\n\n    if(axType === '-') {\n        var trace;\n\n        for(var i = 0; i < subplotData.length; i++) {\n            if(subplotData[i].visible) {\n                trace = subplotData[i];\n                break;\n            }\n        }\n\n        if(trace && trace[dataAttr]) {\n            axOut.type = autoType(trace[dataAttr], 'gregorian');\n        }\n\n        if(axOut.type === '-') {\n            axOut.type = 'linear';\n        } else {\n            // copy autoType back to input axis\n            // note that if this object didn't exist\n            // in the input layout, we have to put it in\n            // this happens in the main supplyDefaults function\n            axIn.type = axOut.type;\n        }\n    }\n\n    return axOut.type;\n}\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    handleSubplotDefaults(layoutIn, layoutOut, fullData, {\n        type: constants.name,\n        attributes: layoutAttributes,\n        handleDefaults: handleDefaults,\n        font: layoutOut.font,\n        paper_bgcolor: layoutOut.paper_bgcolor,\n        fullData: fullData,\n        layoutOut: layoutOut\n    });\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../cartesian/axis_autotype\":768,\"../cartesian/category_order_defaults\":771,\"../cartesian/line_grid_defaults\":781,\"../cartesian/tick_label_defaults\":786,\"../cartesian/tick_mark_defaults\":787,\"../cartesian/tick_value_defaults\":788,\"../get_data\":802,\"../subplot_defaults\":842,\"./constants\":829,\"./layout_attributes\":832,\"./set_convert\":841}],834:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterAttrs = _dereq_('../../../traces/scatter/attributes');\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar extendFlat = _dereq_('../../../lib/extend').extendFlat;\n\nvar deprecationWarning = [\n    'Area traces are deprecated!',\n    'Please switch to the *barpolar* trace type.'\n].join(' ');\n\nmodule.exports = {\n    r: extendFlat({}, scatterAttrs.r, {\n        \n    }),\n    t: extendFlat({}, scatterAttrs.t, {\n        \n    }),\n    marker: {\n        color: extendFlat({}, scatterMarkerAttrs.color, {\n            \n        }),\n        size: extendFlat({}, scatterMarkerAttrs.size, {\n            \n        }),\n        symbol: extendFlat({}, scatterMarkerAttrs.symbol, {\n            \n        }),\n        opacity: extendFlat({}, scatterMarkerAttrs.opacity, {\n            \n        }),\n        editType: 'calc'\n    }\n};\n\n},{\"../../../lib/extend\":710,\"../../../traces/scatter/attributes\":1112}],835:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar axesAttrs = _dereq_('../../cartesian/layout_attributes');\nvar extendFlat = _dereq_('../../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../../plot_api/edit_types').overrideAll;\n\nvar deprecationWarning = [\n    'Legacy polar charts are deprecated!',\n    'Please switch to *polar* subplots.'\n].join(' ');\n\nvar domainAttr = extendFlat({}, axesAttrs.domain, {\n    \n});\n\nfunction mergeAttrs(axisName, nonCommonAttrs) {\n    var commonAttrs = {\n        showline: {\n            valType: 'boolean',\n            \n            \n        },\n        showticklabels: {\n            valType: 'boolean',\n            \n            \n        },\n        tickorientation: {\n            valType: 'enumerated',\n            values: ['horizontal', 'vertical'],\n            \n            \n        },\n        ticklen: {\n            valType: 'number',\n            min: 0,\n            \n            \n        },\n        tickcolor: {\n            valType: 'color',\n            \n            \n        },\n        ticksuffix: {\n            valType: 'string',\n            \n            \n        },\n        endpadding: {\n            valType: 'number',\n            \n            description: deprecationWarning,\n        },\n        visible: {\n            valType: 'boolean',\n            \n            \n        }\n    };\n\n    return extendFlat({}, nonCommonAttrs, commonAttrs);\n}\n\nmodule.exports = overrideAll({\n    radialaxis: mergeAttrs('radial', {\n        range: {\n            valType: 'info_array',\n            \n            items: [\n                { valType: 'number' },\n                { valType: 'number' }\n            ],\n            \n        },\n        domain: domainAttr,\n        orientation: {\n            valType: 'number',\n            \n            \n        }\n    }),\n\n    angularaxis: mergeAttrs('angular', {\n        range: {\n            valType: 'info_array',\n            \n            items: [\n                { valType: 'number', dflt: 0 },\n                { valType: 'number', dflt: 360 }\n            ],\n            \n        },\n        domain: domainAttr\n    }),\n\n    // attributes that appear at layout root\n    layout: {\n        direction: {\n            valType: 'enumerated',\n            values: ['clockwise', 'counterclockwise'],\n            \n            \n        },\n        orientation: {\n            valType: 'angle',\n            \n            \n        }\n    }\n}, 'plot', 'nested');\n\n},{\"../../../lib/extend\":710,\"../../../plot_api/edit_types\":750,\"../../cartesian/layout_attributes\":779}],836:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Polar = module.exports = _dereq_('./micropolar');\n\nPolar.manager = _dereq_('./micropolar_manager');\n\n},{\"./micropolar\":837,\"./micropolar_manager\":838}],837:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\nvar d3 = _dereq_('d3');\nvar Lib = _dereq_('../../../lib');\nvar extendDeepAll = Lib.extendDeepAll;\nvar MID_SHIFT = _dereq_('../../../constants/alignment').MID_SHIFT;\n\nvar µ = module.exports = { version: '0.2.2' };\n\nµ.Axis = function module() {\n    var config = {\n        data: [],\n        layout: {}\n    }, inputConfig = {}, liveConfig = {};\n    var svg, container, dispatch = d3.dispatch('hover'), radialScale, angularScale;\n    var exports = {};\n    function render(_container) {\n        container = _container || container;\n        var data = config.data;\n        var axisConfig = config.layout;\n        if (typeof container == 'string' || container.nodeName) container = d3.select(container);\n        container.datum(data).each(function(_data, _index) {\n            var dataOriginal = _data.slice();\n            liveConfig = {\n                data: µ.util.cloneJson(dataOriginal),\n                layout: µ.util.cloneJson(axisConfig)\n            };\n            var colorIndex = 0;\n            dataOriginal.forEach(function(d, i) {\n                if (!d.color) {\n                    d.color = axisConfig.defaultColorRange[colorIndex];\n                    colorIndex = (colorIndex + 1) % axisConfig.defaultColorRange.length;\n                }\n                if (!d.strokeColor) {\n                    d.strokeColor = d.geometry === 'LinePlot' ? d.color : d3.rgb(d.color).darker().toString();\n                }\n                liveConfig.data[i].color = d.color;\n                liveConfig.data[i].strokeColor = d.strokeColor;\n                liveConfig.data[i].strokeDash = d.strokeDash;\n                liveConfig.data[i].strokeSize = d.strokeSize;\n            });\n            var data = dataOriginal.filter(function(d, i) {\n                var visible = d.visible;\n                return typeof visible === 'undefined' || visible === true;\n            });\n            var isStacked = false;\n            var dataWithGroupId = data.map(function(d, i) {\n                isStacked = isStacked || typeof d.groupId !== 'undefined';\n                return d;\n            });\n            if (isStacked) {\n                var grouped = d3.nest().key(function(d, i) {\n                    return typeof d.groupId != 'undefined' ? d.groupId : 'unstacked';\n                }).entries(dataWithGroupId);\n                var dataYStack = [];\n                var stacked = grouped.map(function(d, i) {\n                    if (d.key === 'unstacked') return d.values; else {\n                        var prevArray = d.values[0].r.map(function(d, i) {\n                            return 0;\n                        });\n                        d.values.forEach(function(d, i, a) {\n                            d.yStack = [ prevArray ];\n                            dataYStack.push(prevArray);\n                            prevArray = µ.util.sumArrays(d.r, prevArray);\n                        });\n                        return d.values;\n                    }\n                });\n                data = d3.merge(stacked);\n            }\n            data.forEach(function(d, i) {\n                d.t = Array.isArray(d.t[0]) ? d.t : [ d.t ];\n                d.r = Array.isArray(d.r[0]) ? d.r : [ d.r ];\n            });\n            var radius = Math.min(axisConfig.width - axisConfig.margin.left - axisConfig.margin.right, axisConfig.height - axisConfig.margin.top - axisConfig.margin.bottom) / 2;\n            radius = Math.max(10, radius);\n            var chartCenter = [ axisConfig.margin.left + radius, axisConfig.margin.top + radius ];\n            var extent;\n            if (isStacked) {\n                var highestStackedValue = d3.max(µ.util.sumArrays(µ.util.arrayLast(data).r[0], µ.util.arrayLast(dataYStack)));\n                extent = [ 0, highestStackedValue ];\n            } else extent = d3.extent(µ.util.flattenArray(data.map(function(d, i) {\n                return d.r;\n            })));\n            if (axisConfig.radialAxis.domain != µ.DATAEXTENT) extent[0] = 0;\n            radialScale = d3.scale.linear().domain(axisConfig.radialAxis.domain != µ.DATAEXTENT && axisConfig.radialAxis.domain ? axisConfig.radialAxis.domain : extent).range([ 0, radius ]);\n            liveConfig.layout.radialAxis.domain = radialScale.domain();\n            var angularDataMerged = µ.util.flattenArray(data.map(function(d, i) {\n                return d.t;\n            }));\n            var isOrdinal = typeof angularDataMerged[0] === 'string';\n            var ticks;\n            if (isOrdinal) {\n                angularDataMerged = µ.util.deduplicate(angularDataMerged);\n                ticks = angularDataMerged.slice();\n                angularDataMerged = d3.range(angularDataMerged.length);\n                data = data.map(function(d, i) {\n                    var result = d;\n                    d.t = [ angularDataMerged ];\n                    if (isStacked) result.yStack = d.yStack;\n                    return result;\n                });\n            }\n            var hasOnlyLineOrDotPlot = data.filter(function(d, i) {\n                return d.geometry === 'LinePlot' || d.geometry === 'DotPlot';\n            }).length === data.length;\n            var needsEndSpacing = axisConfig.needsEndSpacing === null ? isOrdinal || !hasOnlyLineOrDotPlot : axisConfig.needsEndSpacing;\n            var useProvidedDomain = axisConfig.angularAxis.domain && axisConfig.angularAxis.domain != µ.DATAEXTENT && !isOrdinal && axisConfig.angularAxis.domain[0] >= 0;\n            var angularDomain = useProvidedDomain ? axisConfig.angularAxis.domain : d3.extent(angularDataMerged);\n            var angularDomainStep = Math.abs(angularDataMerged[1] - angularDataMerged[0]);\n            if (hasOnlyLineOrDotPlot && !isOrdinal) angularDomainStep = 0;\n            var angularDomainWithPadding = angularDomain.slice();\n            if (needsEndSpacing && isOrdinal) angularDomainWithPadding[1] += angularDomainStep;\n            var tickCount = axisConfig.angularAxis.ticksCount || 4;\n            if (tickCount > 8) tickCount = tickCount / (tickCount / 8) + tickCount % 8;\n            if (axisConfig.angularAxis.ticksStep) {\n                tickCount = (angularDomainWithPadding[1] - angularDomainWithPadding[0]) / tickCount;\n            }\n            var angularTicksStep = axisConfig.angularAxis.ticksStep || (angularDomainWithPadding[1] - angularDomainWithPadding[0]) / (tickCount * (axisConfig.minorTicks + 1));\n            if (ticks) angularTicksStep = Math.max(Math.round(angularTicksStep), 1);\n            if (!angularDomainWithPadding[2]) angularDomainWithPadding[2] = angularTicksStep;\n            var angularAxisRange = d3.range.apply(this, angularDomainWithPadding);\n            angularAxisRange = angularAxisRange.map(function(d, i) {\n                return parseFloat(d.toPrecision(12));\n            });\n            angularScale = d3.scale.linear().domain(angularDomainWithPadding.slice(0, 2)).range(axisConfig.direction === 'clockwise' ? [ 0, 360 ] : [ 360, 0 ]);\n            liveConfig.layout.angularAxis.domain = angularScale.domain();\n            liveConfig.layout.angularAxis.endPadding = needsEndSpacing ? angularDomainStep : 0;\n            svg = d3.select(this).select('svg.chart-root');\n            if (typeof svg === 'undefined' || svg.empty()) {\n                var skeleton = \"<svg xmlns='http://www.w3.org/2000/svg' class='chart-root'>' + '<g class='outer-group'>' + '<g class='chart-group'>' + '<circle class='background-circle'></circle>' + '<g class='geometry-group'></g>' + '<g class='radial axis-group'>' + '<circle class='outside-circle'></circle>' + '</g>' + '<g class='angular axis-group'></g>' + '<g class='guides-group'><line></line><circle r='0'></circle></g>' + '</g>' + '<g class='legend-group'></g>' + '<g class='tooltips-group'></g>' + '<g class='title-group'><text></text></g>' + '</g>' + '</svg>\";\n                var doc = new DOMParser().parseFromString(skeleton, 'application/xml');\n                var newSvg = this.appendChild(this.ownerDocument.importNode(doc.documentElement, true));\n                svg = d3.select(newSvg);\n            }\n            svg.select('.guides-group').style({\n                'pointer-events': 'none'\n            });\n            svg.select('.angular.axis-group').style({\n                'pointer-events': 'none'\n            });\n            svg.select('.radial.axis-group').style({\n                'pointer-events': 'none'\n            });\n            var chartGroup = svg.select('.chart-group');\n            var lineStyle = {\n                fill: 'none',\n                stroke: axisConfig.tickColor\n            };\n            var fontStyle = {\n                'font-size': axisConfig.font.size,\n                'font-family': axisConfig.font.family,\n                fill: axisConfig.font.color,\n                'text-shadow': [ '-1px 0px', '1px -1px', '-1px 1px', '1px 1px' ].map(function(d, i) {\n                    return ' ' + d + ' 0 ' + axisConfig.font.outlineColor;\n                }).join(',')\n            };\n            var legendContainer;\n            if (axisConfig.showLegend) {\n                legendContainer = svg.select('.legend-group').attr({\n                    transform: 'translate(' + [ radius, axisConfig.margin.top ] + ')'\n                }).style({\n                    display: 'block'\n                });\n                var elements = data.map(function(d, i) {\n                    var datumClone = µ.util.cloneJson(d);\n                    datumClone.symbol = d.geometry === 'DotPlot' ? d.dotType || 'circle' : d.geometry != 'LinePlot' ? 'square' : 'line';\n                    datumClone.visibleInLegend = typeof d.visibleInLegend === 'undefined' || d.visibleInLegend;\n                    datumClone.color = d.geometry === 'LinePlot' ? d.strokeColor : d.color;\n                    return datumClone;\n                });\n\n                µ.Legend().config({\n                    data: data.map(function(d, i) {\n                        return d.name || 'Element' + i;\n                    }),\n                    legendConfig: extendDeepAll({},\n                        µ.Legend.defaultConfig().legendConfig,\n                        {\n                            container: legendContainer,\n                            elements: elements,\n                            reverseOrder: axisConfig.legend.reverseOrder\n                        }\n                    )\n                })();\n\n                var legendBBox = legendContainer.node().getBBox();\n                radius = Math.min(axisConfig.width - legendBBox.width - axisConfig.margin.left - axisConfig.margin.right, axisConfig.height - axisConfig.margin.top - axisConfig.margin.bottom) / 2;\n                radius = Math.max(10, radius);\n                chartCenter = [ axisConfig.margin.left + radius, axisConfig.margin.top + radius ];\n                radialScale.range([ 0, radius ]);\n                liveConfig.layout.radialAxis.domain = radialScale.domain();\n                legendContainer.attr('transform', 'translate(' + [ chartCenter[0] + radius, chartCenter[1] - radius ] + ')');\n            } else {\n                legendContainer = svg.select('.legend-group').style({\n                    display: 'none'\n                });\n            }\n            svg.attr({\n                width: axisConfig.width,\n                height: axisConfig.height\n            }).style({\n                opacity: axisConfig.opacity\n            });\n            chartGroup.attr('transform', 'translate(' + chartCenter + ')').style({\n                cursor: 'crosshair'\n            });\n            var centeringOffset = [ (axisConfig.width - (axisConfig.margin.left + axisConfig.margin.right + radius * 2 + (legendBBox ? legendBBox.width : 0))) / 2, (axisConfig.height - (axisConfig.margin.top + axisConfig.margin.bottom + radius * 2)) / 2 ];\n            centeringOffset[0] = Math.max(0, centeringOffset[0]);\n            centeringOffset[1] = Math.max(0, centeringOffset[1]);\n            svg.select('.outer-group').attr('transform', 'translate(' + centeringOffset + ')');\n            if (axisConfig.title && axisConfig.title.text) {\n                var title = svg.select('g.title-group text').style(fontStyle).text(axisConfig.title.text);\n                var titleBBox = title.node().getBBox();\n                title.attr({\n                    x: chartCenter[0] - titleBBox.width / 2,\n                    y: chartCenter[1] - radius - 20\n                });\n            }\n            var radialAxis = svg.select('.radial.axis-group');\n            if (axisConfig.radialAxis.gridLinesVisible) {\n                var gridCircles = radialAxis.selectAll('circle.grid-circle').data(radialScale.ticks(5));\n                gridCircles.enter().append('circle').attr({\n                    'class': 'grid-circle'\n                }).style(lineStyle);\n                gridCircles.attr('r', radialScale);\n                gridCircles.exit().remove();\n            }\n            radialAxis.select('circle.outside-circle').attr({\n                r: radius\n            }).style(lineStyle);\n            var backgroundCircle = svg.select('circle.background-circle').attr({\n                r: radius\n            }).style({\n                fill: axisConfig.backgroundColor,\n                stroke: axisConfig.stroke\n            });\n            function currentAngle(d, i) {\n                return angularScale(d) % 360 + axisConfig.orientation;\n            }\n            if (axisConfig.radialAxis.visible) {\n                var axis = d3.svg.axis().scale(radialScale).ticks(5).tickSize(5);\n                radialAxis.call(axis).attr({\n                    transform: 'rotate(' + axisConfig.radialAxis.orientation + ')'\n                });\n                radialAxis.selectAll('.domain').style(lineStyle);\n                radialAxis.selectAll('g>text').text(function(d, i) {\n                    return this.textContent + axisConfig.radialAxis.ticksSuffix;\n                }).style(fontStyle).style({\n                    'text-anchor': 'start'\n                }).attr({\n                    x: 0,\n                    y: 0,\n                    dx: 0,\n                    dy: 0,\n                    transform: function(d, i) {\n                        if (axisConfig.radialAxis.tickOrientation === 'horizontal') {\n                            return 'rotate(' + -axisConfig.radialAxis.orientation + ') translate(' + [ 0, fontStyle['font-size'] ] + ')';\n                        } else return 'translate(' + [ 0, fontStyle['font-size'] ] + ')';\n                    }\n                });\n                radialAxis.selectAll('g>line').style({\n                    stroke: 'black'\n                });\n            }\n            var angularAxis = svg.select('.angular.axis-group').selectAll('g.angular-tick').data(angularAxisRange);\n            var angularAxisEnter = angularAxis.enter().append('g').classed('angular-tick', true);\n            angularAxis.attr({\n                transform: function(d, i) {\n                    return 'rotate(' + currentAngle(d, i) + ')';\n                }\n            }).style({\n                display: axisConfig.angularAxis.visible ? 'block' : 'none'\n            });\n            angularAxis.exit().remove();\n            angularAxisEnter.append('line').classed('grid-line', true).classed('major', function(d, i) {\n                return i % (axisConfig.minorTicks + 1) == 0;\n            }).classed('minor', function(d, i) {\n                return !(i % (axisConfig.minorTicks + 1) == 0);\n            }).style(lineStyle);\n            angularAxisEnter.selectAll('.minor').style({\n                stroke: axisConfig.minorTickColor\n            });\n            angularAxis.select('line.grid-line').attr({\n                x1: axisConfig.tickLength ? radius - axisConfig.tickLength : 0,\n                x2: radius\n            }).style({\n                display: axisConfig.angularAxis.gridLinesVisible ? 'block' : 'none'\n            });\n            angularAxisEnter.append('text').classed('axis-text', true).style(fontStyle);\n            var ticksText = angularAxis.select('text.axis-text').attr({\n                x: radius + axisConfig.labelOffset,\n                dy: MID_SHIFT + 'em',\n                transform: function(d, i) {\n                    var angle = currentAngle(d, i);\n                    var rad = radius + axisConfig.labelOffset;\n                    var orient = axisConfig.angularAxis.tickOrientation;\n                    if (orient == 'horizontal') return 'rotate(' + -angle + ' ' + rad + ' 0)'; else if (orient == 'radial') return angle < 270 && angle > 90 ? 'rotate(180 ' + rad + ' 0)' : null; else return 'rotate(' + (angle <= 180 && angle > 0 ? -90 : 90) + ' ' + rad + ' 0)';\n                }\n            }).style({\n                'text-anchor': 'middle',\n                display: axisConfig.angularAxis.labelsVisible ? 'block' : 'none'\n            }).text(function(d, i) {\n                if (i % (axisConfig.minorTicks + 1) != 0) return '';\n                if (ticks) {\n                    return ticks[d] + axisConfig.angularAxis.ticksSuffix;\n                } else return d + axisConfig.angularAxis.ticksSuffix;\n            }).style(fontStyle);\n            if (axisConfig.angularAxis.rewriteTicks) ticksText.text(function(d, i) {\n                if (i % (axisConfig.minorTicks + 1) != 0) return '';\n                return axisConfig.angularAxis.rewriteTicks(this.textContent, i);\n            });\n            var rightmostTickEndX = d3.max(chartGroup.selectAll('.angular-tick text')[0].map(function(d, i) {\n                return d.getCTM().e + d.getBBox().width;\n            }));\n            legendContainer.attr({\n                transform: 'translate(' + [ radius + rightmostTickEndX, axisConfig.margin.top ] + ')'\n            });\n            var hasGeometry = svg.select('g.geometry-group').selectAll('g').size() > 0;\n            var geometryContainer = svg.select('g.geometry-group').selectAll('g.geometry').data(data);\n            geometryContainer.enter().append('g').attr({\n                'class': function(d, i) {\n                    return 'geometry geometry' + i;\n                }\n            });\n            geometryContainer.exit().remove();\n            if (data[0] || hasGeometry) {\n                var geometryConfigs = [];\n                data.forEach(function(d, i) {\n                    var geometryConfig = {};\n                    geometryConfig.radialScale = radialScale;\n                    geometryConfig.angularScale = angularScale;\n                    geometryConfig.container = geometryContainer.filter(function(dB, iB) {\n                        return iB == i;\n                    });\n                    geometryConfig.geometry = d.geometry;\n                    geometryConfig.orientation = axisConfig.orientation;\n                    geometryConfig.direction = axisConfig.direction;\n                    geometryConfig.index = i;\n                    geometryConfigs.push({\n                        data: d,\n                        geometryConfig: geometryConfig\n                    });\n                });\n                var geometryConfigsGrouped = d3.nest().key(function(d, i) {\n                    return typeof d.data.groupId != 'undefined' || 'unstacked';\n                }).entries(geometryConfigs);\n                var geometryConfigsGrouped2 = [];\n                geometryConfigsGrouped.forEach(function(d, i) {\n                    if (d.key === 'unstacked') geometryConfigsGrouped2 = geometryConfigsGrouped2.concat(d.values.map(function(d, i) {\n                        return [ d ];\n                    })); else geometryConfigsGrouped2.push(d.values);\n                });\n                geometryConfigsGrouped2.forEach(function(d, i) {\n                    var geometry;\n                    if (Array.isArray(d)) geometry = d[0].geometryConfig.geometry; else geometry = d.geometryConfig.geometry;\n                    var finalGeometryConfig = d.map(function(dB, iB) {\n                        return extendDeepAll(µ[geometry].defaultConfig(), dB);\n                    });\n                    µ[geometry]().config(finalGeometryConfig)();\n                });\n            }\n            var guides = svg.select('.guides-group');\n            var tooltipContainer = svg.select('.tooltips-group');\n            var angularTooltip = µ.tooltipPanel().config({\n                container: tooltipContainer,\n                fontSize: 8\n            })();\n            var radialTooltip = µ.tooltipPanel().config({\n                container: tooltipContainer,\n                fontSize: 8\n            })();\n            var geometryTooltip = µ.tooltipPanel().config({\n                container: tooltipContainer,\n                hasTick: true\n            })();\n            var angularValue, radialValue;\n            if (!isOrdinal) {\n                var angularGuideLine = guides.select('line').attr({\n                    x1: 0,\n                    y1: 0,\n                    y2: 0\n                }).style({\n                    stroke: 'grey',\n                    'pointer-events': 'none'\n                });\n                chartGroup.on('mousemove.angular-guide', function(d, i) {\n                    var mouseAngle = µ.util.getMousePos(backgroundCircle).angle;\n                    angularGuideLine.attr({\n                        x2: -radius,\n                        transform: 'rotate(' + mouseAngle + ')'\n                    }).style({\n                        opacity: .5\n                    });\n                    var angleWithOriginOffset = (mouseAngle + 180 + 360 - axisConfig.orientation) % 360;\n                    angularValue = angularScale.invert(angleWithOriginOffset);\n                    var pos = µ.util.convertToCartesian(radius + 12, mouseAngle + 180);\n                    angularTooltip.text(µ.util.round(angularValue)).move([ pos[0] + chartCenter[0], pos[1] + chartCenter[1] ]);\n                }).on('mouseout.angular-guide', function(d, i) {\n                    guides.select('line').style({\n                        opacity: 0\n                    });\n                });\n            }\n            var angularGuideCircle = guides.select('circle').style({\n                stroke: 'grey',\n                fill: 'none'\n            });\n            chartGroup.on('mousemove.radial-guide', function(d, i) {\n                var r = µ.util.getMousePos(backgroundCircle).radius;\n                angularGuideCircle.attr({\n                    r: r\n                }).style({\n                    opacity: .5\n                });\n                radialValue = radialScale.invert(µ.util.getMousePos(backgroundCircle).radius);\n                var pos = µ.util.convertToCartesian(r, axisConfig.radialAxis.orientation);\n                radialTooltip.text(µ.util.round(radialValue)).move([ pos[0] + chartCenter[0], pos[1] + chartCenter[1] ]);\n            }).on('mouseout.radial-guide', function(d, i) {\n                angularGuideCircle.style({\n                    opacity: 0\n                });\n                geometryTooltip.hide();\n                angularTooltip.hide();\n                radialTooltip.hide();\n            });\n            svg.selectAll('.geometry-group .mark').on('mouseover.tooltip', function(d, i) {\n                var el = d3.select(this);\n                var color = this.style.fill;\n                var newColor = 'black';\n                var opacity = this.style.opacity || 1;\n                el.attr({\n                    'data-opacity': opacity\n                });\n                if (color && color !== 'none') {\n                    el.attr({\n                        'data-fill': color\n                    });\n                    newColor = d3.hsl(color).darker().toString();\n                    el.style({\n                        fill: newColor,\n                        opacity: 1\n                    });\n                    var textData = {\n                        t: µ.util.round(d[0]),\n                        r: µ.util.round(d[1])\n                    };\n                    if (isOrdinal) textData.t = ticks[d[0]];\n                    var text = 't: ' + textData.t + ', r: ' + textData.r;\n                    var bbox = this.getBoundingClientRect();\n                    var svgBBox = svg.node().getBoundingClientRect();\n                    var pos = [ bbox.left + bbox.width / 2 - centeringOffset[0] - svgBBox.left, bbox.top + bbox.height / 2 - centeringOffset[1] - svgBBox.top ];\n                    geometryTooltip.config({\n                        color: newColor\n                    }).text(text);\n                    geometryTooltip.move(pos);\n                } else {\n                    color = this.style.stroke || 'black';\n                    el.attr({\n                        'data-stroke': color\n                    });\n                    newColor = d3.hsl(color).darker().toString();\n                    el.style({\n                        stroke: newColor,\n                        opacity: 1\n                    });\n                }\n            }).on('mousemove.tooltip', function(d, i) {\n                if (d3.event.which != 0) return false;\n                if (d3.select(this).attr('data-fill')) geometryTooltip.show();\n            }).on('mouseout.tooltip', function(d, i) {\n                geometryTooltip.hide();\n                var el = d3.select(this);\n                var fillColor = el.attr('data-fill');\n                if (fillColor) el.style({\n                    fill: fillColor,\n                    opacity: el.attr('data-opacity')\n                }); else el.style({\n                    stroke: el.attr('data-stroke'),\n                    opacity: el.attr('data-opacity')\n                });\n            });\n        });\n        return exports;\n    }\n    exports.render = function(_container) {\n        render(_container);\n        return this;\n    };\n    exports.config = function(_x) {\n        if (!arguments.length) return config;\n        var xClone = µ.util.cloneJson(_x);\n        xClone.data.forEach(function(d, i) {\n            if (!config.data[i]) config.data[i] = {};\n            extendDeepAll(config.data[i], µ.Axis.defaultConfig().data[0]);\n            extendDeepAll(config.data[i], d);\n        });\n        extendDeepAll(config.layout, µ.Axis.defaultConfig().layout);\n        extendDeepAll(config.layout, xClone.layout);\n        return this;\n    };\n    exports.getLiveConfig = function() {\n        return liveConfig;\n    };\n    exports.getinputConfig = function() {\n        return inputConfig;\n    };\n    exports.radialScale = function(_x) {\n        return radialScale;\n    };\n    exports.angularScale = function(_x) {\n        return angularScale;\n    };\n    exports.svg = function() {\n        return svg;\n    };\n    d3.rebind(exports, dispatch, 'on');\n    return exports;\n};\n\nµ.Axis.defaultConfig = function(d, i) {\n    var config = {\n        data: [ {\n            t: [ 1, 2, 3, 4 ],\n            r: [ 10, 11, 12, 13 ],\n            name: 'Line1',\n            geometry: 'LinePlot',\n            color: null,\n            strokeDash: 'solid',\n            strokeColor: null,\n            strokeSize: '1',\n            visibleInLegend: true,\n            opacity: 1\n        } ],\n        layout: {\n            defaultColorRange: d3.scale.category10().range(),\n            title: null,\n            height: 450,\n            width: 500,\n            margin: {\n                top: 40,\n                right: 40,\n                bottom: 40,\n                left: 40\n            },\n            font: {\n                size: 12,\n                color: 'gray',\n                outlineColor: 'white',\n                family: 'Tahoma, sans-serif'\n            },\n            direction: 'clockwise',\n            orientation: 0,\n            labelOffset: 10,\n            radialAxis: {\n                domain: null,\n                orientation: -45,\n                ticksSuffix: '',\n                visible: true,\n                gridLinesVisible: true,\n                tickOrientation: 'horizontal',\n                rewriteTicks: null\n            },\n            angularAxis: {\n                domain: [ 0, 360 ],\n                ticksSuffix: '',\n                visible: true,\n                gridLinesVisible: true,\n                labelsVisible: true,\n                tickOrientation: 'horizontal',\n                rewriteTicks: null,\n                ticksCount: null,\n                ticksStep: null\n            },\n            minorTicks: 0,\n            tickLength: null,\n            tickColor: 'silver',\n            minorTickColor: '#eee',\n            backgroundColor: 'none',\n            needsEndSpacing: null,\n            showLegend: true,\n            legend: {\n                reverseOrder: false\n            },\n            opacity: 1\n        }\n    };\n    return config;\n};\n\nµ.util = {};\n\nµ.DATAEXTENT = 'dataExtent';\n\nµ.AREA = 'AreaChart';\n\nµ.LINE = 'LinePlot';\n\nµ.DOT = 'DotPlot';\n\nµ.BAR = 'BarChart';\n\nµ.util._override = function(_objA, _objB) {\n    for (var x in _objA) if (x in _objB) _objB[x] = _objA[x];\n};\n\nµ.util._extend = function(_objA, _objB) {\n    for (var x in _objA) _objB[x] = _objA[x];\n};\n\nµ.util._rndSnd = function() {\n    return Math.random() * 2 - 1 + (Math.random() * 2 - 1) + (Math.random() * 2 - 1);\n};\n\nµ.util.dataFromEquation2 = function(_equation, _step) {\n    var step = _step || 6;\n    var data = d3.range(0, 360 + step, step).map(function(deg, index) {\n        var theta = deg * Math.PI / 180;\n        var radius = _equation(theta);\n        return [ deg, radius ];\n    });\n    return data;\n};\n\nµ.util.dataFromEquation = function(_equation, _step, _name) {\n    var step = _step || 6;\n    var t = [], r = [];\n    d3.range(0, 360 + step, step).forEach(function(deg, index) {\n        var theta = deg * Math.PI / 180;\n        var radius = _equation(theta);\n        t.push(deg);\n        r.push(radius);\n    });\n    var result = {\n        t: t,\n        r: r\n    };\n    if (_name) result.name = _name;\n    return result;\n};\n\nµ.util.ensureArray = function(_val, _count) {\n    if (typeof _val === 'undefined') return null;\n    var arr = [].concat(_val);\n    return d3.range(_count).map(function(d, i) {\n        return arr[i] || arr[0];\n    });\n};\n\nµ.util.fillArrays = function(_obj, _valueNames, _count) {\n    _valueNames.forEach(function(d, i) {\n        _obj[d] = µ.util.ensureArray(_obj[d], _count);\n    });\n    return _obj;\n};\n\nµ.util.cloneJson = function(json) {\n    return JSON.parse(JSON.stringify(json));\n};\n\nµ.util.validateKeys = function(obj, keys) {\n    if (typeof keys === 'string') keys = keys.split('.');\n    var next = keys.shift();\n    return obj[next] && (!keys.length || objHasKeys(obj[next], keys));\n};\n\nµ.util.sumArrays = function(a, b) {\n    return d3.zip(a, b).map(function(d, i) {\n        return d3.sum(d);\n    });\n};\n\nµ.util.arrayLast = function(a) {\n    return a[a.length - 1];\n};\n\nµ.util.arrayEqual = function(a, b) {\n    var i = Math.max(a.length, b.length, 1);\n    while (i-- >= 0 && a[i] === b[i]) ;\n    return i === -2;\n};\n\nµ.util.flattenArray = function(arr) {\n    var r = [];\n    while (!µ.util.arrayEqual(r, arr)) {\n        r = arr;\n        arr = [].concat.apply([], arr);\n    }\n    return arr;\n};\n\nµ.util.deduplicate = function(arr) {\n    return arr.filter(function(v, i, a) {\n        return a.indexOf(v) == i;\n    });\n};\n\nµ.util.convertToCartesian = function(radius, theta) {\n    var thetaRadians = theta * Math.PI / 180;\n    var x = radius * Math.cos(thetaRadians);\n    var y = radius * Math.sin(thetaRadians);\n    return [ x, y ];\n};\n\nµ.util.round = function(_value, _digits) {\n    var digits = _digits || 2;\n    var mult = Math.pow(10, digits);\n    return Math.round(_value * mult) / mult;\n};\n\nµ.util.getMousePos = function(_referenceElement) {\n    var mousePos = d3.mouse(_referenceElement.node());\n    var mouseX = mousePos[0];\n    var mouseY = mousePos[1];\n    var mouse = {};\n    mouse.x = mouseX;\n    mouse.y = mouseY;\n    mouse.pos = mousePos;\n    mouse.angle = (Math.atan2(mouseY, mouseX) + Math.PI) * 180 / Math.PI;\n    mouse.radius = Math.sqrt(mouseX * mouseX + mouseY * mouseY);\n    return mouse;\n};\n\nµ.util.duplicatesCount = function(arr) {\n    var uniques = {}, val;\n    var dups = {};\n    for (var i = 0, len = arr.length; i < len; i++) {\n        val = arr[i];\n        if (val in uniques) {\n            uniques[val]++;\n            dups[val] = uniques[val];\n        } else {\n            uniques[val] = 1;\n        }\n    }\n    return dups;\n};\n\nµ.util.duplicates = function(arr) {\n    return Object.keys(µ.util.duplicatesCount(arr));\n};\n\nµ.util.translator = function(obj, sourceBranch, targetBranch, reverse) {\n    if (reverse) {\n        var targetBranchCopy = targetBranch.slice();\n        targetBranch = sourceBranch;\n        sourceBranch = targetBranchCopy;\n    }\n    var value = sourceBranch.reduce(function(previousValue, currentValue) {\n        if (typeof previousValue != 'undefined') return previousValue[currentValue];\n    }, obj);\n    if (typeof value === 'undefined') return;\n    sourceBranch.reduce(function(previousValue, currentValue, index) {\n        if (typeof previousValue == 'undefined') return;\n        if (index === sourceBranch.length - 1) delete previousValue[currentValue];\n        return previousValue[currentValue];\n    }, obj);\n    targetBranch.reduce(function(previousValue, currentValue, index) {\n        if (typeof previousValue[currentValue] === 'undefined') previousValue[currentValue] = {};\n        if (index === targetBranch.length - 1) previousValue[currentValue] = value;\n        return previousValue[currentValue];\n    }, obj);\n};\n\nµ.PolyChart = function module() {\n    var config = [ µ.PolyChart.defaultConfig() ];\n    var dispatch = d3.dispatch('hover');\n    var dashArray = {\n        solid: 'none',\n        dash: [ 5, 2 ],\n        dot: [ 2, 5 ]\n    };\n    var colorScale;\n    function exports() {\n        var geometryConfig = config[0].geometryConfig;\n        var container = geometryConfig.container;\n        if (typeof container == 'string') container = d3.select(container);\n        container.datum(config).each(function(_config, _index) {\n            var isStack = !!_config[0].data.yStack;\n            var data = _config.map(function(d, i) {\n                if (isStack) return d3.zip(d.data.t[0], d.data.r[0], d.data.yStack[0]); else return d3.zip(d.data.t[0], d.data.r[0]);\n            });\n            var angularScale = geometryConfig.angularScale;\n            var domainMin = geometryConfig.radialScale.domain()[0];\n            var generator = {};\n            generator.bar = function(d, i, pI) {\n                var dataConfig = _config[pI].data;\n                var h = geometryConfig.radialScale(d[1]) - geometryConfig.radialScale(0);\n                var stackTop = geometryConfig.radialScale(d[2] || 0);\n                var w = dataConfig.barWidth;\n                d3.select(this).attr({\n                    'class': 'mark bar',\n                    d: 'M' + [ [ h + stackTop, -w / 2 ], [ h + stackTop, w / 2 ], [ stackTop, w / 2 ], [ stackTop, -w / 2 ] ].join('L') + 'Z',\n                    transform: function(d, i) {\n                        return 'rotate(' + (geometryConfig.orientation + angularScale(d[0])) + ')';\n                    }\n                });\n            };\n            generator.dot = function(d, i, pI) {\n                var stackedData = d[2] ? [ d[0], d[1] + d[2] ] : d;\n                var symbol = d3.svg.symbol().size(_config[pI].data.dotSize).type(_config[pI].data.dotType)(d, i);\n                d3.select(this).attr({\n                    'class': 'mark dot',\n                    d: symbol,\n                    transform: function(d, i) {\n                        var coord = convertToCartesian(getPolarCoordinates(stackedData));\n                        return 'translate(' + [ coord.x, coord.y ] + ')';\n                    }\n                });\n            };\n            var line = d3.svg.line.radial().interpolate(_config[0].data.lineInterpolation).radius(function(d) {\n                return geometryConfig.radialScale(d[1]);\n            }).angle(function(d) {\n                return geometryConfig.angularScale(d[0]) * Math.PI / 180;\n            });\n            generator.line = function(d, i, pI) {\n                var lineData = d[2] ? data[pI].map(function(d, i) {\n                    return [ d[0], d[1] + d[2] ];\n                }) : data[pI];\n                d3.select(this).each(generator['dot']).style({\n                    opacity: function(dB, iB) {\n                        return +_config[pI].data.dotVisible;\n                    },\n                    fill: markStyle.stroke(d, i, pI)\n                }).attr({\n                    'class': 'mark dot'\n                });\n                if (i > 0) return;\n                var lineSelection = d3.select(this.parentNode).selectAll('path.line').data([ 0 ]);\n                lineSelection.enter().insert('path');\n                lineSelection.attr({\n                    'class': 'line',\n                    d: line(lineData),\n                    transform: function(dB, iB) {\n                        return 'rotate(' + (geometryConfig.orientation + 90) + ')';\n                    },\n                    'pointer-events': 'none'\n                }).style({\n                    fill: function(dB, iB) {\n                        return markStyle.fill(d, i, pI);\n                    },\n                    'fill-opacity': 0,\n                    stroke: function(dB, iB) {\n                        return markStyle.stroke(d, i, pI);\n                    },\n                    'stroke-width': function(dB, iB) {\n                        return markStyle['stroke-width'](d, i, pI);\n                    },\n                    'stroke-dasharray': function(dB, iB) {\n                        return markStyle['stroke-dasharray'](d, i, pI);\n                    },\n                    opacity: function(dB, iB) {\n                        return markStyle.opacity(d, i, pI);\n                    },\n                    display: function(dB, iB) {\n                        return markStyle.display(d, i, pI);\n                    }\n                });\n            };\n            var angularRange = geometryConfig.angularScale.range();\n            var triangleAngle = Math.abs(angularRange[1] - angularRange[0]) / data[0].length * Math.PI / 180;\n            var arc = d3.svg.arc().startAngle(function(d) {\n                return -triangleAngle / 2;\n            }).endAngle(function(d) {\n                return triangleAngle / 2;\n            }).innerRadius(function(d) {\n                return geometryConfig.radialScale(domainMin + (d[2] || 0));\n            }).outerRadius(function(d) {\n                return geometryConfig.radialScale(domainMin + (d[2] || 0)) + geometryConfig.radialScale(d[1]);\n            });\n            generator.arc = function(d, i, pI) {\n                d3.select(this).attr({\n                    'class': 'mark arc',\n                    d: arc,\n                    transform: function(d, i) {\n                        return 'rotate(' + (geometryConfig.orientation + angularScale(d[0]) + 90) + ')';\n                    }\n                });\n            };\n            var markStyle = {\n                fill: function(d, i, pI) {\n                    return _config[pI].data.color;\n                },\n                stroke: function(d, i, pI) {\n                    return _config[pI].data.strokeColor;\n                },\n                'stroke-width': function(d, i, pI) {\n                    return _config[pI].data.strokeSize + 'px';\n                },\n                'stroke-dasharray': function(d, i, pI) {\n                    return dashArray[_config[pI].data.strokeDash];\n                },\n                opacity: function(d, i, pI) {\n                    return _config[pI].data.opacity;\n                },\n                display: function(d, i, pI) {\n                    return typeof _config[pI].data.visible === 'undefined' || _config[pI].data.visible ? 'block' : 'none';\n                }\n            };\n            var geometryLayer = d3.select(this).selectAll('g.layer').data(data);\n            geometryLayer.enter().append('g').attr({\n                'class': 'layer'\n            });\n            var geometry = geometryLayer.selectAll('path.mark').data(function(d, i) {\n                return d;\n            });\n            geometry.enter().append('path').attr({\n                'class': 'mark'\n            });\n            geometry.style(markStyle).each(generator[geometryConfig.geometryType]);\n            geometry.exit().remove();\n            geometryLayer.exit().remove();\n            function getPolarCoordinates(d, i) {\n                var r = geometryConfig.radialScale(d[1]);\n                var t = (geometryConfig.angularScale(d[0]) + geometryConfig.orientation) * Math.PI / 180;\n                return {\n                    r: r,\n                    t: t\n                };\n            }\n            function convertToCartesian(polarCoordinates) {\n                var x = polarCoordinates.r * Math.cos(polarCoordinates.t);\n                var y = polarCoordinates.r * Math.sin(polarCoordinates.t);\n                return {\n                    x: x,\n                    y: y\n                };\n            }\n        });\n    }\n    exports.config = function(_x) {\n        if (!arguments.length) return config;\n        _x.forEach(function(d, i) {\n            if (!config[i]) config[i] = {};\n            extendDeepAll(config[i], µ.PolyChart.defaultConfig());\n            extendDeepAll(config[i], d);\n        });\n        return this;\n    };\n    exports.getColorScale = function() {\n        return colorScale;\n    };\n    d3.rebind(exports, dispatch, 'on');\n    return exports;\n};\n\nµ.PolyChart.defaultConfig = function() {\n    var config = {\n        data: {\n            name: 'geom1',\n            t: [ [ 1, 2, 3, 4 ] ],\n            r: [ [ 1, 2, 3, 4 ] ],\n            dotType: 'circle',\n            dotSize: 64,\n            dotVisible: false,\n            barWidth: 20,\n            color: '#ffa500',\n            strokeSize: 1,\n            strokeColor: 'silver',\n            strokeDash: 'solid',\n            opacity: 1,\n            index: 0,\n            visible: true,\n            visibleInLegend: true\n        },\n        geometryConfig: {\n            geometry: 'LinePlot',\n            geometryType: 'arc',\n            direction: 'clockwise',\n            orientation: 0,\n            container: 'body',\n            radialScale: null,\n            angularScale: null,\n            colorScale: d3.scale.category20()\n        }\n    };\n    return config;\n};\n\nµ.BarChart = function module() {\n    return µ.PolyChart();\n};\n\nµ.BarChart.defaultConfig = function() {\n    var config = {\n        geometryConfig: {\n            geometryType: 'bar'\n        }\n    };\n    return config;\n};\n\nµ.AreaChart = function module() {\n    return µ.PolyChart();\n};\n\nµ.AreaChart.defaultConfig = function() {\n    var config = {\n        geometryConfig: {\n            geometryType: 'arc'\n        }\n    };\n    return config;\n};\n\nµ.DotPlot = function module() {\n    return µ.PolyChart();\n};\n\nµ.DotPlot.defaultConfig = function() {\n    var config = {\n        geometryConfig: {\n            geometryType: 'dot',\n            dotType: 'circle'\n        }\n    };\n    return config;\n};\n\nµ.LinePlot = function module() {\n    return µ.PolyChart();\n};\n\nµ.LinePlot.defaultConfig = function() {\n    var config = {\n        geometryConfig: {\n            geometryType: 'line'\n        }\n    };\n    return config;\n};\n\nµ.Legend = function module() {\n    var config = µ.Legend.defaultConfig();\n    var dispatch = d3.dispatch('hover');\n    function exports() {\n        var legendConfig = config.legendConfig;\n        var flattenData = config.data.map(function(d, i) {\n            return [].concat(d).map(function(dB, iB) {\n                var element = extendDeepAll({}, legendConfig.elements[i]);\n                element.name = dB;\n                element.color = [].concat(legendConfig.elements[i].color)[iB];\n                return element;\n            });\n        });\n        var data = d3.merge(flattenData);\n        data = data.filter(function(d, i) {\n            return legendConfig.elements[i] && (legendConfig.elements[i].visibleInLegend || typeof legendConfig.elements[i].visibleInLegend === 'undefined');\n        });\n        if (legendConfig.reverseOrder) data = data.reverse();\n        var container = legendConfig.container;\n        if (typeof container == 'string' || container.nodeName) container = d3.select(container);\n        var colors = data.map(function(d, i) {\n            return d.color;\n        });\n        var lineHeight = legendConfig.fontSize;\n        var isContinuous = legendConfig.isContinuous == null ? typeof data[0] === 'number' : legendConfig.isContinuous;\n        var height = isContinuous ? legendConfig.height : lineHeight * data.length;\n        var legendContainerGroup = container.classed('legend-group', true);\n        var svg = legendContainerGroup.selectAll('svg').data([ 0 ]);\n        var svgEnter = svg.enter().append('svg').attr({\n            width: 300,\n            height: height + lineHeight,\n            xmlns: 'http://www.w3.org/2000/svg',\n            'xmlns:xlink': 'http://www.w3.org/1999/xlink',\n            version: '1.1'\n        });\n        svgEnter.append('g').classed('legend-axis', true);\n        svgEnter.append('g').classed('legend-marks', true);\n        var dataNumbered = d3.range(data.length);\n        var colorScale = d3.scale[isContinuous ? 'linear' : 'ordinal']().domain(dataNumbered).range(colors);\n        var dataScale = d3.scale[isContinuous ? 'linear' : 'ordinal']().domain(dataNumbered)[isContinuous ? 'range' : 'rangePoints']([ 0, height ]);\n        var shapeGenerator = function(_type, _size) {\n            var squareSize = _size * 3;\n            if (_type === 'line') {\n                return 'M' + [ [ -_size / 2, -_size / 12 ], [ _size / 2, -_size / 12 ], [ _size / 2, _size / 12 ], [ -_size / 2, _size / 12 ] ] + 'Z';\n            } else if (d3.svg.symbolTypes.indexOf(_type) != -1) return d3.svg.symbol().type(_type).size(squareSize)(); else return d3.svg.symbol().type('square').size(squareSize)();\n        };\n        if (isContinuous) {\n            var gradient = svg.select('.legend-marks').append('defs').append('linearGradient').attr({\n                id: 'grad1',\n                x1: '0%',\n                y1: '0%',\n                x2: '0%',\n                y2: '100%'\n            }).selectAll('stop').data(colors);\n            gradient.enter().append('stop');\n            gradient.attr({\n                offset: function(d, i) {\n                    return i / (colors.length - 1) * 100 + '%';\n                }\n            }).style({\n                'stop-color': function(d, i) {\n                    return d;\n                }\n            });\n            svg.append('rect').classed('legend-mark', true).attr({\n                height: legendConfig.height,\n                width: legendConfig.colorBandWidth,\n                fill: 'url(#grad1)'\n            });\n        } else {\n            var legendElement = svg.select('.legend-marks').selectAll('path.legend-mark').data(data);\n            legendElement.enter().append('path').classed('legend-mark', true);\n            legendElement.attr({\n                transform: function(d, i) {\n                    return 'translate(' + [ lineHeight / 2, dataScale(i) + lineHeight / 2 ] + ')';\n                },\n                d: function(d, i) {\n                    var symbolType = d.symbol;\n                    return shapeGenerator(symbolType, lineHeight);\n                },\n                fill: function(d, i) {\n                    return colorScale(i);\n                }\n            });\n            legendElement.exit().remove();\n        }\n        var legendAxis = d3.svg.axis().scale(dataScale).orient('right');\n        var axis = svg.select('g.legend-axis').attr({\n            transform: 'translate(' + [ isContinuous ? legendConfig.colorBandWidth : lineHeight, lineHeight / 2 ] + ')'\n        }).call(legendAxis);\n        axis.selectAll('.domain').style({\n            fill: 'none',\n            stroke: 'none'\n        });\n        axis.selectAll('line').style({\n            fill: 'none',\n            stroke: isContinuous ? legendConfig.textColor : 'none'\n        });\n        axis.selectAll('text').style({\n            fill: legendConfig.textColor,\n            'font-size': legendConfig.fontSize\n        }).text(function(d, i) {\n            return data[i].name;\n        });\n        return exports;\n    }\n    exports.config = function(_x) {\n        if (!arguments.length) return config;\n        extendDeepAll(config, _x);\n        return this;\n    };\n    d3.rebind(exports, dispatch, 'on');\n    return exports;\n};\n\nµ.Legend.defaultConfig = function(d, i) {\n    var config = {\n        data: [ 'a', 'b', 'c' ],\n        legendConfig: {\n            elements: [ {\n                symbol: 'line',\n                color: 'red'\n            }, {\n                symbol: 'square',\n                color: 'yellow'\n            }, {\n                symbol: 'diamond',\n                color: 'limegreen'\n            } ],\n            height: 150,\n            colorBandWidth: 30,\n            fontSize: 12,\n            container: 'body',\n            isContinuous: null,\n            textColor: 'grey',\n            reverseOrder: false\n        }\n    };\n    return config;\n};\n\nµ.tooltipPanel = function() {\n    var tooltipEl, tooltipTextEl, backgroundEl;\n    var config = {\n        container: null,\n        hasTick: false,\n        fontSize: 12,\n        color: 'white',\n        padding: 5\n    };\n    var id = 'tooltip-' + µ.tooltipPanel.uid++;\n    var tickSize = 10;\n    var exports = function() {\n        tooltipEl = config.container.selectAll('g.' + id).data([ 0 ]);\n        var tooltipEnter = tooltipEl.enter().append('g').classed(id, true).style({\n            'pointer-events': 'none',\n            display: 'none'\n        });\n        backgroundEl = tooltipEnter.append('path').style({\n            fill: 'white',\n            'fill-opacity': .9\n        }).attr({\n            d: 'M0 0'\n        });\n        tooltipTextEl = tooltipEnter.append('text').attr({\n            dx: config.padding + tickSize,\n            dy: +config.fontSize * .3\n        });\n        return exports;\n    };\n    exports.text = function(_text) {\n        var l = d3.hsl(config.color).l;\n        var strokeColor = l >= .5 ? '#aaa' : 'white';\n        var fillColor = l >= .5 ? 'black' : 'white';\n        var text = _text || '';\n        tooltipTextEl.style({\n            fill: fillColor,\n            'font-size': config.fontSize + 'px'\n        }).text(text);\n        var padding = config.padding;\n        var bbox = tooltipTextEl.node().getBBox();\n        var boxStyle = {\n            fill: config.color,\n            stroke: strokeColor,\n            'stroke-width': '2px'\n        };\n        var backGroundW = bbox.width + padding * 2 + tickSize;\n        var backGroundH = bbox.height + padding * 2;\n        backgroundEl.attr({\n            d: 'M' + [ [ tickSize, -backGroundH / 2 ], [ tickSize, -backGroundH / 4 ], [ config.hasTick ? 0 : tickSize, 0 ], [ tickSize, backGroundH / 4 ], [ tickSize, backGroundH / 2 ], [ backGroundW, backGroundH / 2 ], [ backGroundW, -backGroundH / 2 ] ].join('L') + 'Z'\n        }).style(boxStyle);\n        tooltipEl.attr({\n            transform: 'translate(' + [ tickSize, -backGroundH / 2 + padding * 2 ] + ')'\n        });\n        tooltipEl.style({\n            display: 'block'\n        });\n        return exports;\n    };\n    exports.move = function(_pos) {\n        if (!tooltipEl) return;\n        tooltipEl.attr({\n            transform: 'translate(' + [ _pos[0], _pos[1] ] + ')'\n        }).style({\n            display: 'block'\n        });\n        return exports;\n    };\n    exports.hide = function() {\n        if (!tooltipEl) return;\n        tooltipEl.style({\n            display: 'none'\n        });\n        return exports;\n    };\n    exports.show = function() {\n        if (!tooltipEl) return;\n        tooltipEl.style({\n            display: 'block'\n        });\n        return exports;\n    };\n    exports.config = function(_x) {\n        extendDeepAll(config, _x);\n        return exports;\n    };\n    return exports;\n};\n\nµ.tooltipPanel.uid = 1;\n\nµ.adapter = {};\n\nµ.adapter.plotly = function module() {\n    var exports = {};\n    exports.convert = function(_inputConfig, reverse) {\n        var outputConfig = {};\n        if (_inputConfig.data) {\n            outputConfig.data = _inputConfig.data.map(function(d, i) {\n                var r = extendDeepAll({}, d);\n                var toTranslate = [\n                    [ r, [ 'marker', 'color' ], [ 'color' ] ],\n                    [ r, [ 'marker', 'opacity' ], [ 'opacity' ] ],\n                    [ r, [ 'marker', 'line', 'color' ], [ 'strokeColor' ] ],\n                    [ r, [ 'marker', 'line', 'dash' ], [ 'strokeDash' ] ],\n                    [ r, [ 'marker', 'line', 'width' ], [ 'strokeSize' ] ],\n                    [ r, [ 'marker', 'symbol' ], [ 'dotType' ] ],\n                    [ r, [ 'marker', 'size' ], [ 'dotSize' ] ],\n                    [ r, [ 'marker', 'barWidth' ], [ 'barWidth' ] ],\n                    [ r, [ 'line', 'interpolation' ], [ 'lineInterpolation' ] ],\n                    [ r, [ 'showlegend' ], [ 'visibleInLegend' ] ]\n                ];\n                toTranslate.forEach(function(d, i) {\n                    µ.util.translator.apply(null, d.concat(reverse));\n                });\n\n                if (!reverse) delete r.marker;\n                if (reverse) delete r.groupId;\n                if (!reverse) {\n                    if (r.type === 'scatter') {\n                        if (r.mode === 'lines') r.geometry = 'LinePlot'; else if (r.mode === 'markers') r.geometry = 'DotPlot'; else if (r.mode === 'lines+markers') {\n                            r.geometry = 'LinePlot';\n                            r.dotVisible = true;\n                        }\n                    } else if (r.type === 'area') r.geometry = 'AreaChart'; else if (r.type === 'bar') r.geometry = 'BarChart';\n                    delete r.mode;\n                    delete r.type;\n                } else {\n                    if (r.geometry === 'LinePlot') {\n                        r.type = 'scatter';\n                        if (r.dotVisible === true) {\n                            delete r.dotVisible;\n                            r.mode = 'lines+markers';\n                        } else r.mode = 'lines';\n                    } else if (r.geometry === 'DotPlot') {\n                        r.type = 'scatter';\n                        r.mode = 'markers';\n                    } else if (r.geometry === 'AreaChart') r.type = 'area'; else if (r.geometry === 'BarChart') r.type = 'bar';\n                    delete r.geometry;\n                }\n                return r;\n            });\n            if (!reverse && _inputConfig.layout && _inputConfig.layout.barmode === 'stack') {\n                var duplicates = µ.util.duplicates(outputConfig.data.map(function(d, i) {\n                    return d.geometry;\n                }));\n                outputConfig.data.forEach(function(d, i) {\n                    var idx = duplicates.indexOf(d.geometry);\n                    if (idx != -1) outputConfig.data[i].groupId = idx;\n                });\n            }\n        }\n        if (_inputConfig.layout) {\n            var r = extendDeepAll({}, _inputConfig.layout);\n            var toTranslate = [\n                [ r, [ 'plot_bgcolor' ], [ 'backgroundColor' ] ],\n                [ r, [ 'showlegend' ], [ 'showLegend' ] ],\n                [ r, [ 'radialaxis' ], [ 'radialAxis' ] ],\n                [ r, [ 'angularaxis' ], [ 'angularAxis' ] ],\n                [ r.angularaxis, [ 'showline' ], [ 'gridLinesVisible' ] ],\n                [ r.angularaxis, [ 'showticklabels' ], [ 'labelsVisible' ] ],\n                [ r.angularaxis, [ 'nticks' ], [ 'ticksCount' ] ],\n                [ r.angularaxis, [ 'tickorientation' ], [ 'tickOrientation' ] ],\n                [ r.angularaxis, [ 'ticksuffix' ], [ 'ticksSuffix' ] ],\n                [ r.angularaxis, [ 'range' ], [ 'domain' ] ],\n                [ r.angularaxis, [ 'endpadding' ], [ 'endPadding' ] ],\n                [ r.radialaxis, [ 'showline' ], [ 'gridLinesVisible' ] ],\n                [ r.radialaxis, [ 'tickorientation' ], [ 'tickOrientation' ] ],\n                [ r.radialaxis, [ 'ticksuffix' ], [ 'ticksSuffix' ] ],\n                [ r.radialaxis, [ 'range' ], [ 'domain' ] ],\n                [ r.angularAxis, [ 'showline' ], [ 'gridLinesVisible' ] ],\n                [ r.angularAxis, [ 'showticklabels' ], [ 'labelsVisible' ] ],\n                [ r.angularAxis, [ 'nticks' ], [ 'ticksCount' ] ],\n                [ r.angularAxis, [ 'tickorientation' ], [ 'tickOrientation' ] ],\n                [ r.angularAxis, [ 'ticksuffix' ], [ 'ticksSuffix' ] ],\n                [ r.angularAxis, [ 'range' ], [ 'domain' ] ],\n                [ r.angularAxis, [ 'endpadding' ], [ 'endPadding' ] ],\n                [ r.radialAxis, [ 'showline' ], [ 'gridLinesVisible' ] ],\n                [ r.radialAxis, [ 'tickorientation' ], [ 'tickOrientation' ] ],\n                [ r.radialAxis, [ 'ticksuffix' ], [ 'ticksSuffix' ] ],\n                [ r.radialAxis, [ 'range' ], [ 'domain' ] ],\n                [ r.font, [ 'outlinecolor' ], [ 'outlineColor' ] ],\n                [ r.legend, [ 'traceorder' ], [ 'reverseOrder' ] ],\n                [ r, [ 'labeloffset' ], [ 'labelOffset' ] ],\n                [ r, [ 'defaultcolorrange' ], [ 'defaultColorRange' ] ]\n            ];\n            toTranslate.forEach(function(d, i) {\n                µ.util.translator.apply(null, d.concat(reverse));\n            });\n\n            if (!reverse) {\n                if (r.angularAxis && typeof r.angularAxis.ticklen !== 'undefined') r.tickLength = r.angularAxis.ticklen;\n                if (r.angularAxis && typeof r.angularAxis.tickcolor !== 'undefined') r.tickColor = r.angularAxis.tickcolor;\n            } else {\n                if (typeof r.tickLength !== 'undefined') {\n                    r.angularaxis.ticklen = r.tickLength;\n                    delete r.tickLength;\n                }\n                if (r.tickColor) {\n                    r.angularaxis.tickcolor = r.tickColor;\n                    delete r.tickColor;\n                }\n            }\n            if (r.legend && typeof r.legend.reverseOrder != 'boolean') {\n                r.legend.reverseOrder = r.legend.reverseOrder != 'normal';\n            }\n            if (r.legend && typeof r.legend.traceorder == 'boolean') {\n                r.legend.traceorder = r.legend.traceorder ? 'reversed' : 'normal';\n                delete r.legend.reverseOrder;\n            }\n            if (r.margin && typeof r.margin.t != 'undefined') {\n                var source = [ 't', 'r', 'b', 'l', 'pad' ];\n                var target = [ 'top', 'right', 'bottom', 'left', 'pad' ];\n                var margin = {};\n                d3.entries(r.margin).forEach(function(dB, iB) {\n                    margin[target[source.indexOf(dB.key)]] = dB.value;\n                });\n                r.margin = margin;\n            }\n            if (reverse) {\n                delete r.needsEndSpacing;\n                delete r.minorTickColor;\n                delete r.minorTicks;\n                delete r.angularaxis.ticksCount;\n                delete r.angularaxis.ticksCount;\n                delete r.angularaxis.ticksStep;\n                delete r.angularaxis.rewriteTicks;\n                delete r.angularaxis.nticks;\n                delete r.radialaxis.ticksCount;\n                delete r.radialaxis.ticksCount;\n                delete r.radialaxis.ticksStep;\n                delete r.radialaxis.rewriteTicks;\n                delete r.radialaxis.nticks;\n            }\n            outputConfig.layout = r;\n        }\n        return outputConfig;\n    };\n    return exports;\n};\n\n},{\"../../../constants/alignment\":688,\"../../../lib\":719,\"d3\":163}],838:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n/* eslint-disable new-cap */\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Lib = _dereq_('../../../lib');\nvar Color = _dereq_('../../../components/color');\n\nvar micropolar = _dereq_('./micropolar');\nvar UndoManager = _dereq_('./undo_manager');\nvar extendDeepAll = Lib.extendDeepAll;\n\nvar manager = module.exports = {};\n\nmanager.framework = function(_gd) {\n    var config, previousConfigClone, plot, convertedInput, container;\n    var undoManager = new UndoManager();\n\n    function exports(_inputConfig, _container) {\n        if(_container) container = _container;\n        d3.select(d3.select(container).node().parentNode).selectAll('.svg-container>*:not(.chart-root)').remove();\n\n        config = (!config) ?\n            _inputConfig :\n            extendDeepAll(config, _inputConfig);\n\n        if(!plot) plot = micropolar.Axis();\n        convertedInput = micropolar.adapter.plotly().convert(config);\n        plot.config(convertedInput).render(container);\n        _gd.data = config.data;\n        _gd.layout = config.layout;\n        manager.fillLayout(_gd);\n        return config;\n    }\n    exports.isPolar = true;\n    exports.svg = function() { return plot.svg(); };\n    exports.getConfig = function() { return config; };\n    exports.getLiveConfig = function() {\n        return micropolar.adapter.plotly().convert(plot.getLiveConfig(), true);\n    };\n    exports.getLiveScales = function() { return {t: plot.angularScale(), r: plot.radialScale()}; };\n    exports.setUndoPoint = function() {\n        var that = this;\n        var configClone = micropolar.util.cloneJson(config);\n        (function(_configClone, _previousConfigClone) {\n            undoManager.add({\n                undo: function() {\n                    if(_previousConfigClone) that(_previousConfigClone);\n                },\n                redo: function() {\n                    that(_configClone);\n                }\n            });\n        })(configClone, previousConfigClone);\n        previousConfigClone = micropolar.util.cloneJson(configClone);\n    };\n    exports.undo = function() { undoManager.undo(); };\n    exports.redo = function() { undoManager.redo(); };\n    return exports;\n};\n\nmanager.fillLayout = function(_gd) {\n    var container = d3.select(_gd).selectAll('.plot-container');\n    var paperDiv = container.selectAll('.svg-container');\n    var paper = _gd.framework && _gd.framework.svg && _gd.framework.svg();\n    var dflts = {\n        width: 800,\n        height: 600,\n        paper_bgcolor: Color.background,\n        _container: container,\n        _paperdiv: paperDiv,\n        _paper: paper\n    };\n\n    _gd._fullLayout = extendDeepAll(dflts, _gd.layout);\n};\n\n},{\"../../../components/color\":593,\"../../../lib\":719,\"./micropolar\":837,\"./undo_manager\":839,\"d3\":163}],839:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// Modified from https://github.com/ArthurClemens/Javascript-Undo-Manager\n// Copyright (c) 2010-2013 Arthur Clemens, arthur@visiblearea.com\nmodule.exports = function UndoManager() {\n    var undoCommands = [];\n    var index = -1;\n    var isExecuting = false;\n    var callback;\n\n    function execute(command, action) {\n        if(!command) return this;\n\n        isExecuting = true;\n        command[action]();\n        isExecuting = false;\n\n        return this;\n    }\n\n    return {\n        add: function(command) {\n            if(isExecuting) return this;\n            undoCommands.splice(index + 1, undoCommands.length - index);\n            undoCommands.push(command);\n            index = undoCommands.length - 1;\n            return this;\n        },\n        setCallback: function(callbackFunc) { callback = callbackFunc; },\n        undo: function() {\n            var command = undoCommands[index];\n            if(!command) return this;\n            execute(command, 'undo');\n            index -= 1;\n            if(callback) callback(command.undo);\n            return this;\n        },\n        redo: function() {\n            var command = undoCommands[index + 1];\n            if(!command) return this;\n            execute(command, 'redo');\n            index += 1;\n            if(callback) callback(command.redo);\n            return this;\n        },\n        clear: function() {\n            undoCommands = [];\n            index = -1;\n        },\n        hasUndo: function() { return index !== -1; },\n        hasRedo: function() { return index < (undoCommands.length - 1); },\n        getCommands: function() { return undoCommands; },\n        getPreviousCommand: function() { return undoCommands[index - 1]; },\n        getIndex: function() { return index; }\n    };\n};\n\n},{}],840:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar tinycolor = _dereq_('tinycolor2');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar Plots = _dereq_('../plots');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar setConvertCartesian = _dereq_('../cartesian/set_convert');\nvar setConvertPolar = _dereq_('./set_convert');\nvar doAutoRange = _dereq_('../cartesian/autorange').doAutoRange;\nvar dragBox = _dereq_('../cartesian/dragbox');\nvar dragElement = _dereq_('../../components/dragelement');\nvar Fx = _dereq_('../../components/fx');\nvar Titles = _dereq_('../../components/titles');\nvar prepSelect = _dereq_('../cartesian/select').prepSelect;\nvar selectOnClick = _dereq_('../cartesian/select').selectOnClick;\nvar clearSelect = _dereq_('../cartesian/select').clearSelect;\nvar setCursor = _dereq_('../../lib/setcursor');\nvar clearGlCanvases = _dereq_('../../lib/clear_gl_canvases');\nvar redrawReglTraces = _dereq_('../../plot_api/subroutines').redrawReglTraces;\n\nvar MID_SHIFT = _dereq_('../../constants/alignment').MID_SHIFT;\nvar constants = _dereq_('./constants');\nvar helpers = _dereq_('./helpers');\n\nvar _ = Lib._;\nvar mod = Lib.mod;\nvar deg2rad = Lib.deg2rad;\nvar rad2deg = Lib.rad2deg;\n\nfunction Polar(gd, id) {\n    this.id = id;\n    this.gd = gd;\n\n    this._hasClipOnAxisFalse = null;\n    this.vangles = null;\n    this.radialAxisAngle = null;\n    this.traceHash = {};\n    this.layers = {};\n    this.clipPaths = {};\n    this.clipIds = {};\n    this.viewInitial = {};\n\n    var fullLayout = gd._fullLayout;\n    var clipIdBase = 'clip' + fullLayout._uid + id;\n\n    this.clipIds.forTraces = clipIdBase + '-for-traces';\n    this.clipPaths.forTraces = fullLayout._clips.append('clipPath')\n        .attr('id', this.clipIds.forTraces);\n    this.clipPaths.forTraces.append('path');\n\n    this.framework = fullLayout._polarlayer.append('g')\n        .attr('class', id);\n\n    // unfortunately, we have to keep track of some axis tick settings\n    // as polar subplots do not implement the 'ticks' editType\n    this.radialTickLayout = null;\n    this.angularTickLayout = null;\n}\n\nvar proto = Polar.prototype;\n\nmodule.exports = function createPolar(gd, id) {\n    return new Polar(gd, id);\n};\n\nproto.plot = function(polarCalcData, fullLayout) {\n    var _this = this;\n    var polarLayout = fullLayout[_this.id];\n\n    _this._hasClipOnAxisFalse = false;\n    for(var i = 0; i < polarCalcData.length; i++) {\n        var trace = polarCalcData[i][0].trace;\n        if(trace.cliponaxis === false) {\n            _this._hasClipOnAxisFalse = true;\n            break;\n        }\n    }\n\n    _this.updateLayers(fullLayout, polarLayout);\n    _this.updateLayout(fullLayout, polarLayout);\n    Plots.generalUpdatePerTraceModule(_this.gd, _this, polarCalcData, polarLayout);\n    _this.updateFx(fullLayout, polarLayout);\n};\n\nproto.updateLayers = function(fullLayout, polarLayout) {\n    var _this = this;\n    var layers = _this.layers;\n    var radialLayout = polarLayout.radialaxis;\n    var angularLayout = polarLayout.angularaxis;\n    var layerNames = constants.layerNames;\n\n    var frontPlotIndex = layerNames.indexOf('frontplot');\n    var layerData = layerNames.slice(0, frontPlotIndex);\n    var isAngularAxisBelowTraces = angularLayout.layer === 'below traces';\n    var isRadialAxisBelowTraces = radialLayout.layer === 'below traces';\n\n    if(isAngularAxisBelowTraces) layerData.push('angular-line');\n    if(isRadialAxisBelowTraces) layerData.push('radial-line');\n    if(isAngularAxisBelowTraces) layerData.push('angular-axis');\n    if(isRadialAxisBelowTraces) layerData.push('radial-axis');\n\n    layerData.push('frontplot');\n\n    if(!isAngularAxisBelowTraces) layerData.push('angular-line');\n    if(!isRadialAxisBelowTraces) layerData.push('radial-line');\n    if(!isAngularAxisBelowTraces) layerData.push('angular-axis');\n    if(!isRadialAxisBelowTraces) layerData.push('radial-axis');\n\n    var join = _this.framework.selectAll('.polarsublayer')\n        .data(layerData, String);\n\n    join.enter().append('g')\n        .attr('class', function(d) { return 'polarsublayer ' + d;})\n        .each(function(d) {\n            var sel = layers[d] = d3.select(this);\n\n            switch(d) {\n                case 'frontplot':\n                    // TODO add option to place in 'backplot' layer??\n                    sel.append('g').classed('barlayer', true);\n                    sel.append('g').classed('scatterlayer', true);\n                    break;\n                case 'backplot':\n                    sel.append('g').classed('maplayer', true);\n                    break;\n                case 'plotbg':\n                    layers.bg = sel.append('path');\n                    break;\n                case 'radial-grid':\n                    sel.style('fill', 'none');\n                    break;\n                case 'angular-grid':\n                    sel.style('fill', 'none');\n                    break;\n                case 'radial-line':\n                    sel.append('line').style('fill', 'none');\n                    break;\n                case 'angular-line':\n                    sel.append('path').style('fill', 'none');\n                    break;\n            }\n        });\n\n    join.order();\n};\n\n/* Polar subplots juggle with 6 'axis objects' (!), these are:\n *\n * - polarLayout.radialaxis (aka radialLayout in this file):\n * - polarLayout.angularaxis (aka angularLayout in this file):\n *   used for data -> calcdata conversions (aka d2c) during the calc step\n *\n * - this.radialAxis\n *   extends polarLayout.radialaxis, adds mocked 'domain' and\n *   few other keys in order to reuse Cartesian doAutoRange and the Axes\n *   drawing routines.\n *   used for calcdata -> geometric conversions (aka c2g) during the plot step\n *   + setGeometry setups ax.c2g for given ax.range\n *   + setScale setups ax._m,ax._b for given ax.range\n *\n * - this.angularAxis\n *   extends polarLayout.angularaxis, adds mocked 'range' and 'domain' and\n *   a few other keys in order to reuse the Axes drawing routines.\n *   used for calcdata -> geometric conversions (aka c2g) during the plot step\n *   + setGeometry setups ax.c2g given ax.rotation, ax.direction & ax._categories,\n *                 and mocks ax.range\n *   + setScale setups ax._m,ax._b with that mocked ax.range\n *\n * - this.xaxis\n * - this.yaxis\n *   setup so that polar traces can reuse plot methods of Cartesian traces\n *   which mostly rely on 2pixel methods (e.g ax.c2p)\n */\nproto.updateLayout = function(fullLayout, polarLayout) {\n    var _this = this;\n    var layers = _this.layers;\n    var gs = fullLayout._size;\n\n    // axis attributes\n    var radialLayout = polarLayout.radialaxis;\n    var angularLayout = polarLayout.angularaxis;\n    // layout domains\n    var xDomain = polarLayout.domain.x;\n    var yDomain = polarLayout.domain.y;\n    // offsets from paper edge to layout domain box\n    _this.xOffset = gs.l + gs.w * xDomain[0];\n    _this.yOffset = gs.t + gs.h * (1 - yDomain[1]);\n    // lengths of the layout domain box\n    var xLength = _this.xLength = gs.w * (xDomain[1] - xDomain[0]);\n    var yLength = _this.yLength = gs.h * (yDomain[1] - yDomain[0]);\n    // sector to plot\n    var sector = polarLayout.sector;\n    _this.sectorInRad = sector.map(deg2rad);\n    var sectorBBox = _this.sectorBBox = computeSectorBBox(sector);\n    var dxSectorBBox = sectorBBox[2] - sectorBBox[0];\n    var dySectorBBox = sectorBBox[3] - sectorBBox[1];\n    // aspect ratios\n    var arDomain = yLength / xLength;\n    var arSector = Math.abs(dySectorBBox / dxSectorBBox);\n    // actual lengths and domains of subplot box\n    var xLength2, yLength2;\n    var xDomain2, yDomain2;\n    var gap;\n    if(arDomain > arSector) {\n        xLength2 = xLength;\n        yLength2 = xLength * arSector;\n        gap = (yLength - yLength2) / gs.h / 2;\n        xDomain2 = [xDomain[0], xDomain[1]];\n        yDomain2 = [yDomain[0] + gap, yDomain[1] - gap];\n    } else {\n        xLength2 = yLength / arSector;\n        yLength2 = yLength;\n        gap = (xLength - xLength2) / gs.w / 2;\n        xDomain2 = [xDomain[0] + gap, xDomain[1] - gap];\n        yDomain2 = [yDomain[0], yDomain[1]];\n    }\n    _this.xLength2 = xLength2;\n    _this.yLength2 = yLength2;\n    _this.xDomain2 = xDomain2;\n    _this.yDomain2 = yDomain2;\n    // actual offsets from paper edge to the subplot box top-left corner\n    var xOffset2 = _this.xOffset2 = gs.l + gs.w * xDomain2[0];\n    var yOffset2 = _this.yOffset2 = gs.t + gs.h * (1 - yDomain2[1]);\n    // circle radius in px\n    var radius = _this.radius = xLength2 / dxSectorBBox;\n    // 'inner' radius in px (when polar.hole is set)\n    var innerRadius = _this.innerRadius = polarLayout.hole * radius;\n    // circle center position in px\n    var cx = _this.cx = xOffset2 - radius * sectorBBox[0];\n    var cy = _this.cy = yOffset2 + radius * sectorBBox[3];\n    // circle center in the coordinate system of plot area\n    var cxx = _this.cxx = cx - xOffset2;\n    var cyy = _this.cyy = cy - yOffset2;\n\n    _this.radialAxis = _this.mockAxis(fullLayout, polarLayout, radialLayout, {\n        // make this an 'x' axis to make positioning (especially rotation) easier\n        _id: 'x',\n        // convert to 'x' axis equivalent\n        side: {\n            counterclockwise: 'top',\n            clockwise: 'bottom'\n        }[radialLayout.side],\n        // spans length 1 radius\n        domain: [innerRadius / gs.w, radius / gs.w]\n    });\n\n    _this.angularAxis = _this.mockAxis(fullLayout, polarLayout, angularLayout, {\n        side: 'right',\n        // to get auto nticks right\n        domain: [0, Math.PI],\n        // don't pass through autorange logic\n        autorange: false\n    });\n\n    _this.doAutoRange(fullLayout, polarLayout);\n    // N.B. this sets _this.vangles\n    _this.updateAngularAxis(fullLayout, polarLayout);\n    // N.B. this sets _this.radialAxisAngle\n    _this.updateRadialAxis(fullLayout, polarLayout);\n    _this.updateRadialAxisTitle(fullLayout, polarLayout);\n\n    _this.xaxis = _this.mockCartesianAxis(fullLayout, polarLayout, {\n        _id: 'x',\n        domain: xDomain2\n    });\n\n    _this.yaxis = _this.mockCartesianAxis(fullLayout, polarLayout, {\n        _id: 'y',\n        domain: yDomain2\n    });\n\n    var dPath = _this.pathSubplot();\n\n    _this.clipPaths.forTraces.select('path')\n        .attr('d', dPath)\n        .attr('transform', strTranslate(cxx, cyy));\n\n    layers.frontplot\n        .attr('transform', strTranslate(xOffset2, yOffset2))\n        .call(Drawing.setClipUrl, _this._hasClipOnAxisFalse ? null : _this.clipIds.forTraces, _this.gd);\n\n    layers.bg\n        .attr('d', dPath)\n        .attr('transform', strTranslate(cx, cy))\n        .call(Color.fill, polarLayout.bgcolor);\n};\n\nproto.mockAxis = function(fullLayout, polarLayout, axLayout, opts) {\n    var commonOpts = {\n        // to get _boundingBox computation right when showticklabels is false\n        anchor: 'free',\n        position: 0\n    };\n\n    var ax = Lib.extendFlat(commonOpts, axLayout, opts);\n    setConvertPolar(ax, polarLayout, fullLayout);\n    return ax;\n};\n\nproto.mockCartesianAxis = function(fullLayout, polarLayout, opts) {\n    var _this = this;\n    var axId = opts._id;\n\n    var ax = Lib.extendFlat({type: 'linear'}, opts);\n    setConvertCartesian(ax, fullLayout);\n\n    var bboxIndices = {\n        x: [0, 2],\n        y: [1, 3]\n    };\n\n    ax.setRange = function() {\n        var sectorBBox = _this.sectorBBox;\n        var ind = bboxIndices[axId];\n        var rl = _this.radialAxis._rl;\n        var drl = (rl[1] - rl[0]) / (1 - polarLayout.hole);\n        ax.range = [sectorBBox[ind[0]] * drl, sectorBBox[ind[1]] * drl];\n    };\n\n    ax.isPtWithinRange = axId === 'x' ?\n        function(d) { return _this.isPtInside(d); } :\n        function() { return true; };\n\n    ax.setRange();\n    ax.setScale();\n    return ax;\n};\n\nproto.doAutoRange = function(fullLayout, polarLayout) {\n    var gd = this.gd;\n    var radialAxis = this.radialAxis;\n    var radialLayout = polarLayout.radialaxis;\n\n    radialAxis.setScale();\n    doAutoRange(gd, radialAxis);\n\n    var rng = radialAxis.range;\n    radialLayout.range = rng.slice();\n    radialLayout._input.range = rng.slice();\n\n    radialAxis._rl = [\n        radialAxis.r2l(rng[0], null, 'gregorian'),\n        radialAxis.r2l(rng[1], null, 'gregorian')\n    ];\n};\n\nproto.updateRadialAxis = function(fullLayout, polarLayout) {\n    var _this = this;\n    var gd = _this.gd;\n    var layers = _this.layers;\n    var radius = _this.radius;\n    var innerRadius = _this.innerRadius;\n    var cx = _this.cx;\n    var cy = _this.cy;\n    var radialLayout = polarLayout.radialaxis;\n    var a0 = mod(polarLayout.sector[0], 360);\n    var ax = _this.radialAxis;\n    var hasRoomForIt = innerRadius < radius;\n\n    _this.fillViewInitialKey('radialaxis.angle', radialLayout.angle);\n    _this.fillViewInitialKey('radialaxis.range', ax.range.slice());\n\n    ax.setGeometry();\n\n    // rotate auto tick labels by 180 if in quadrant II and III to make them\n    // readable from left-to-right\n    //\n    // TODO try moving deeper in Axes.drawLabels for better results?\n    if(ax.tickangle === 'auto' && (a0 > 90 && a0 <= 270)) {\n        ax.tickangle = 180;\n    }\n\n    // easier to set rotate angle with custom translate function\n    var transFn = function(d) {\n        return 'translate(' + (ax.l2p(d.x) + innerRadius) + ',0)';\n    };\n\n    // set special grid path function\n    var gridPathFn = function(d) {\n        return _this.pathArc(ax.r2p(d.x) + innerRadius);\n    };\n\n    var newTickLayout = strTickLayout(radialLayout);\n    if(_this.radialTickLayout !== newTickLayout) {\n        layers['radial-axis'].selectAll('.xtick').remove();\n        _this.radialTickLayout = newTickLayout;\n    }\n\n    if(hasRoomForIt) {\n        ax.setScale();\n\n        var vals = Axes.calcTicks(ax);\n        var valsClipped = Axes.clipEnds(ax, vals);\n        var tickSign = Axes.getTickSigns(ax)[2];\n\n        Axes.drawTicks(gd, ax, {\n            vals: vals,\n            layer: layers['radial-axis'],\n            path: Axes.makeTickPath(ax, 0, tickSign),\n            transFn: transFn,\n            crisp: false\n        });\n\n        Axes.drawGrid(gd, ax, {\n            vals: valsClipped,\n            layer: layers['radial-grid'],\n            path: gridPathFn,\n            transFn: Lib.noop,\n            crisp: false\n        });\n\n        Axes.drawLabels(gd, ax, {\n            vals: vals,\n            layer: layers['radial-axis'],\n            transFn: transFn,\n            labelFns: Axes.makeLabelFns(ax, 0)\n        });\n    }\n\n    // stash 'actual' radial axis angle for drag handlers (in degrees)\n    var angle = _this.radialAxisAngle = _this.vangles ?\n        rad2deg(snapToVertexAngle(deg2rad(radialLayout.angle), _this.vangles)) :\n        radialLayout.angle;\n\n    var tLayer = strTranslate(cx, cy);\n    var tLayer2 = tLayer + strRotate(-angle);\n\n    updateElement(\n        layers['radial-axis'],\n        hasRoomForIt && (radialLayout.showticklabels || radialLayout.ticks),\n        {transform: tLayer2}\n    );\n\n    updateElement(\n        layers['radial-grid'],\n        hasRoomForIt && radialLayout.showgrid,\n        {transform: tLayer}\n    );\n\n    updateElement(\n        layers['radial-line'].select('line'),\n        hasRoomForIt && radialLayout.showline,\n        {\n            x1: innerRadius,\n            y1: 0,\n            x2: radius,\n            y2: 0,\n            transform: tLayer2\n        }\n    )\n    .attr('stroke-width', radialLayout.linewidth)\n    .call(Color.stroke, radialLayout.linecolor);\n};\n\nproto.updateRadialAxisTitle = function(fullLayout, polarLayout, _angle) {\n    var _this = this;\n    var gd = _this.gd;\n    var radius = _this.radius;\n    var cx = _this.cx;\n    var cy = _this.cy;\n    var radialLayout = polarLayout.radialaxis;\n    var titleClass = _this.id + 'title';\n\n    var angle = _angle !== undefined ? _angle : _this.radialAxisAngle;\n    var angleRad = deg2rad(angle);\n    var cosa = Math.cos(angleRad);\n    var sina = Math.sin(angleRad);\n\n    var pad = 0;\n\n    // Hint: no need to check if there is in fact a title.text set\n    // because if plot is editable, pad needs to be calculated anyways\n    // to properly show placeholder text when title is empty.\n    if(radialLayout.title) {\n        var h = Drawing.bBox(_this.layers['radial-axis'].node()).height;\n        var ts = radialLayout.title.font.size;\n        pad = radialLayout.side === 'counterclockwise' ?\n            -h - ts * 0.4 :\n            h + ts * 0.8;\n    }\n\n    _this.layers['radial-axis-title'] = Titles.draw(gd, titleClass, {\n        propContainer: radialLayout,\n        propName: _this.id + '.radialaxis.title',\n        placeholder: _(gd, 'Click to enter radial axis title'),\n        attributes: {\n            x: cx + (radius / 2) * cosa + pad * sina,\n            y: cy - (radius / 2) * sina + pad * cosa,\n            'text-anchor': 'middle'\n        },\n        transform: {rotate: -angle}\n    });\n};\n\nproto.updateAngularAxis = function(fullLayout, polarLayout) {\n    var _this = this;\n    var gd = _this.gd;\n    var layers = _this.layers;\n    var radius = _this.radius;\n    var innerRadius = _this.innerRadius;\n    var cx = _this.cx;\n    var cy = _this.cy;\n    var angularLayout = polarLayout.angularaxis;\n    var ax = _this.angularAxis;\n\n    _this.fillViewInitialKey('angularaxis.rotation', angularLayout.rotation);\n\n    ax.setGeometry();\n    ax.setScale();\n\n    // 't'ick to 'g'eometric radians is used all over the place here\n    var t2g = function(d) { return ax.t2g(d.x); };\n\n    // run rad2deg on tick0 and ditck for thetaunit: 'radians' axes\n    if(ax.type === 'linear' && ax.thetaunit === 'radians') {\n        ax.tick0 = rad2deg(ax.tick0);\n        ax.dtick = rad2deg(ax.dtick);\n    }\n\n    var _transFn = function(rad) {\n        return strTranslate(cx + radius * Math.cos(rad), cy - radius * Math.sin(rad));\n    };\n\n    var transFn = function(d) {\n        return _transFn(t2g(d));\n    };\n\n    var transFn2 = function(d) {\n        var rad = t2g(d);\n        return _transFn(rad) + strRotate(-rad2deg(rad));\n    };\n\n    var gridPathFn = function(d) {\n        var rad = t2g(d);\n        var cosRad = Math.cos(rad);\n        var sinRad = Math.sin(rad);\n        return 'M' + [cx + innerRadius * cosRad, cy - innerRadius * sinRad] +\n            'L' + [cx + radius * cosRad, cy - radius * sinRad];\n    };\n\n    var out = Axes.makeLabelFns(ax, 0);\n    var labelStandoff = out.labelStandoff;\n    var labelFns = {};\n\n    labelFns.xFn = function(d) {\n        var rad = t2g(d);\n        return Math.cos(rad) * labelStandoff;\n    };\n\n    labelFns.yFn = function(d) {\n        var rad = t2g(d);\n        var ff = Math.sin(rad) > 0 ? 0.2 : 1;\n        return -Math.sin(rad) * (labelStandoff + d.fontSize * ff) +\n            Math.abs(Math.cos(rad)) * (d.fontSize * MID_SHIFT);\n    };\n\n    labelFns.anchorFn = function(d) {\n        var rad = t2g(d);\n        var cos = Math.cos(rad);\n        return Math.abs(cos) < 0.1 ?\n            'middle' :\n            (cos > 0 ? 'start' : 'end');\n    };\n\n    labelFns.heightFn = function(d, a, h) {\n        var rad = t2g(d);\n        return -0.5 * (1 + Math.sin(rad)) * h;\n    };\n\n    var newTickLayout = strTickLayout(angularLayout);\n    if(_this.angularTickLayout !== newTickLayout) {\n        layers['angular-axis'].selectAll('.' + ax._id + 'tick').remove();\n        _this.angularTickLayout = newTickLayout;\n    }\n\n    var vals = Axes.calcTicks(ax);\n\n    // angle of polygon vertices in geometric radians (null means circles)\n    // TODO what to do when ax.period > ax._categories ??\n    var vangles;\n    if(polarLayout.gridshape === 'linear') {\n        vangles = vals.map(t2g);\n\n        // ax._vals should be always ordered, make them\n        // always turn counterclockwise for convenience here\n        if(Lib.angleDelta(vangles[0], vangles[1]) < 0) {\n            vangles = vangles.slice().reverse();\n        }\n    } else {\n        vangles = null;\n    }\n    _this.vangles = vangles;\n\n    // Use tickval filter for category axes instead of tweaking\n    // the range w.r.t sector, so that sectors that cross 360 can\n    // show all their ticks.\n    if(ax.type === 'category') {\n        vals = vals.filter(function(d) {\n            return Lib.isAngleInsideSector(t2g(d), _this.sectorInRad);\n        });\n    }\n\n    if(ax.visible) {\n        var tickSign = ax.ticks === 'inside' ? -1 : 1;\n        var pad = (ax.linewidth || 1) / 2;\n\n        Axes.drawTicks(gd, ax, {\n            vals: vals,\n            layer: layers['angular-axis'],\n            path: 'M' + (tickSign * pad) + ',0h' + (tickSign * ax.ticklen),\n            transFn: transFn2,\n            crisp: false\n        });\n\n        Axes.drawGrid(gd, ax, {\n            vals: vals,\n            layer: layers['angular-grid'],\n            path: gridPathFn,\n            transFn: Lib.noop,\n            crisp: false\n        });\n\n        Axes.drawLabels(gd, ax, {\n            vals: vals,\n            layer: layers['angular-axis'],\n            repositionOnUpdate: true,\n            transFn: transFn,\n            labelFns: labelFns\n        });\n    }\n\n    // TODO maybe two arcs is better here?\n    // maybe split style attributes between inner and outer angular axes?\n\n    updateElement(layers['angular-line'].select('path'), angularLayout.showline, {\n        d: _this.pathSubplot(),\n        transform: strTranslate(cx, cy)\n    })\n    .attr('stroke-width', angularLayout.linewidth)\n    .call(Color.stroke, angularLayout.linecolor);\n};\n\nproto.updateFx = function(fullLayout, polarLayout) {\n    if(!this.gd._context.staticPlot) {\n        this.updateAngularDrag(fullLayout);\n        this.updateRadialDrag(fullLayout, polarLayout, 0);\n        this.updateRadialDrag(fullLayout, polarLayout, 1);\n        this.updateMainDrag(fullLayout);\n    }\n};\n\nproto.updateMainDrag = function(fullLayout) {\n    var _this = this;\n    var gd = _this.gd;\n    var layers = _this.layers;\n    var zoomlayer = fullLayout._zoomlayer;\n    var MINZOOM = constants.MINZOOM;\n    var OFFEDGE = constants.OFFEDGE;\n    var radius = _this.radius;\n    var innerRadius = _this.innerRadius;\n    var cx = _this.cx;\n    var cy = _this.cy;\n    var cxx = _this.cxx;\n    var cyy = _this.cyy;\n    var sectorInRad = _this.sectorInRad;\n    var vangles = _this.vangles;\n    var radialAxis = _this.radialAxis;\n    var clampTiny = helpers.clampTiny;\n    var findXYatLength = helpers.findXYatLength;\n    var findEnclosingVertexAngles = helpers.findEnclosingVertexAngles;\n    var chw = constants.cornerHalfWidth;\n    var chl = constants.cornerLen / 2;\n\n    var mainDrag = dragBox.makeDragger(layers, 'path', 'maindrag', 'crosshair');\n\n    d3.select(mainDrag)\n        .attr('d', _this.pathSubplot())\n        .attr('transform', strTranslate(cx, cy));\n\n    var dragOpts = {\n        element: mainDrag,\n        gd: gd,\n        subplot: _this.id,\n        plotinfo: {\n            id: _this.id,\n            xaxis: _this.xaxis,\n            yaxis: _this.yaxis\n        },\n        xaxes: [_this.xaxis],\n        yaxes: [_this.yaxis]\n    };\n\n    // mouse px position at drag start (0), move (1)\n    var x0, y0;\n    // radial distance from circle center at drag start (0), move (1)\n    var r0, r1;\n    // zoombox persistent quantities\n    var path0, dimmed, lum;\n    // zoombox, corners elements\n    var zb, corners;\n\n    function norm(x, y) {\n        return Math.sqrt(x * x + y * y);\n    }\n\n    function xy2r(x, y) {\n        return norm(x - cxx, y - cyy);\n    }\n\n    function xy2a(x, y) {\n        return Math.atan2(cyy - y, x - cxx);\n    }\n\n    function ra2xy(r, a) {\n        return [r * Math.cos(a), r * Math.sin(-a)];\n    }\n\n    function pathCorner(r, a) {\n        if(r === 0) return _this.pathSector(2 * chw);\n\n        var da = chl / r;\n        var am = a - da;\n        var ap = a + da;\n        var rb = Math.max(0, Math.min(r, radius));\n        var rm = rb - chw;\n        var rp = rb + chw;\n\n        return 'M' + ra2xy(rm, am) +\n            'A' + [rm, rm] + ' 0,0,0 ' + ra2xy(rm, ap) +\n            'L' + ra2xy(rp, ap) +\n            'A' + [rp, rp] + ' 0,0,1 ' + ra2xy(rp, am) +\n            'Z';\n    }\n\n    // (x,y) is the pt at middle of the va0 <-> va1 edge\n    //\n    // ... we could eventually add another mode for cursor\n    // angles 'close to' enough to a particular vertex.\n    function pathCornerForPolygons(r, va0, va1) {\n        if(r === 0) return _this.pathSector(2 * chw);\n\n        var xy0 = ra2xy(r, va0);\n        var xy1 = ra2xy(r, va1);\n        var x = clampTiny((xy0[0] + xy1[0]) / 2);\n        var y = clampTiny((xy0[1] + xy1[1]) / 2);\n        var innerPts, outerPts;\n\n        if(x && y) {\n            var m = y / x;\n            var mperp = -1 / m;\n            var midPts = findXYatLength(chw, m, x, y);\n            innerPts = findXYatLength(chl, mperp, midPts[0][0], midPts[0][1]);\n            outerPts = findXYatLength(chl, mperp, midPts[1][0], midPts[1][1]);\n        } else {\n            var dx, dy;\n            if(y) {\n                // horizontal handles\n                dx = chl;\n                dy = chw;\n            } else {\n                // vertical handles\n                dx = chw;\n                dy = chl;\n            }\n            innerPts = [[x - dx, y - dy], [x + dx, y - dy]];\n            outerPts = [[x - dx, y + dy], [x + dx, y + dy]];\n        }\n\n        return 'M' + innerPts.join('L') +\n            'L' + outerPts.reverse().join('L') + 'Z';\n    }\n\n    function zoomPrep() {\n        r0 = null;\n        r1 = null;\n        path0 = _this.pathSubplot();\n        dimmed = false;\n\n        var polarLayoutNow = gd._fullLayout[_this.id];\n        lum = tinycolor(polarLayoutNow.bgcolor).getLuminance();\n\n        zb = dragBox.makeZoombox(zoomlayer, lum, cx, cy, path0);\n        zb.attr('fill-rule', 'evenodd');\n        corners = dragBox.makeCorners(zoomlayer, cx, cy);\n        clearSelect(gd);\n    }\n\n    // N.B. this sets scoped 'r0' and 'r1'\n    // return true if 'valid' zoom distance, false otherwise\n    function clampAndSetR0R1(rr0, rr1) {\n        rr1 = Math.max(Math.min(rr1, radius), innerRadius);\n\n        // starting or ending drag near center (outer edge),\n        // clamps radial distance at origin (at r=radius)\n        if(rr0 < OFFEDGE) rr0 = 0;\n        else if((radius - rr0) < OFFEDGE) rr0 = radius;\n        else if(rr1 < OFFEDGE) rr1 = 0;\n        else if((radius - rr1) < OFFEDGE) rr1 = radius;\n\n        // make sure r0 < r1,\n        // to get correct fill pattern in path1 below\n        if(Math.abs(rr1 - rr0) > MINZOOM) {\n            if(rr0 < rr1) {\n                r0 = rr0;\n                r1 = rr1;\n            } else {\n                r0 = rr1;\n                r1 = rr0;\n            }\n            return true;\n        } else {\n            r0 = null;\n            r1 = null;\n            return false;\n        }\n    }\n\n    function applyZoomMove(path1, cpath) {\n        path1 = path1 || path0;\n        cpath = cpath || 'M0,0Z';\n\n        zb.attr('d', path1);\n        corners.attr('d', cpath);\n        dragBox.transitionZoombox(zb, corners, dimmed, lum);\n        dimmed = true;\n\n        var updateObj = {};\n        computeZoomUpdates(updateObj);\n        gd.emit('plotly_relayouting', updateObj);\n    }\n\n    function zoomMove(dx, dy) {\n        var x1 = x0 + dx;\n        var y1 = y0 + dy;\n        var rr0 = xy2r(x0, y0);\n        var rr1 = Math.min(xy2r(x1, y1), radius);\n        var a0 = xy2a(x0, y0);\n        var path1;\n        var cpath;\n\n        if(clampAndSetR0R1(rr0, rr1)) {\n            path1 = path0 + _this.pathSector(r1);\n            if(r0) path1 += _this.pathSector(r0);\n            // keep 'starting' angle\n            cpath = pathCorner(r0, a0) + pathCorner(r1, a0);\n        }\n        applyZoomMove(path1, cpath);\n    }\n\n    function findPolygonRadius(x, y, va0, va1) {\n        var xy = helpers.findIntersectionXY(va0, va1, va0, [x - cxx, cyy - y]);\n        return norm(xy[0], xy[1]);\n    }\n\n    function zoomMoveForPolygons(dx, dy) {\n        var x1 = x0 + dx;\n        var y1 = y0 + dy;\n        var a0 = xy2a(x0, y0);\n        var a1 = xy2a(x1, y1);\n        var vangles0 = findEnclosingVertexAngles(a0, vangles);\n        var vangles1 = findEnclosingVertexAngles(a1, vangles);\n        var rr0 = findPolygonRadius(x0, y0, vangles0[0], vangles0[1]);\n        var rr1 = Math.min(findPolygonRadius(x1, y1, vangles1[0], vangles1[1]), radius);\n        var path1;\n        var cpath;\n\n        if(clampAndSetR0R1(rr0, rr1)) {\n            path1 = path0 + _this.pathSector(r1);\n            if(r0) path1 += _this.pathSector(r0);\n            // keep 'starting' angle here too\n            cpath = [\n                pathCornerForPolygons(r0, vangles0[0], vangles0[1]),\n                pathCornerForPolygons(r1, vangles0[0], vangles0[1])\n            ].join(' ');\n        }\n        applyZoomMove(path1, cpath);\n    }\n\n    function zoomDone() {\n        dragBox.removeZoombox(gd);\n\n        if(r0 === null || r1 === null) return;\n        var updateObj = {};\n        computeZoomUpdates(updateObj);\n\n        dragBox.showDoubleClickNotifier(gd);\n\n        Registry.call('_guiRelayout', gd, updateObj);\n    }\n\n    function computeZoomUpdates(update) {\n        var rl = radialAxis._rl;\n        var m = (rl[1] - rl[0]) / (1 - innerRadius / radius) / radius;\n        var newRng = [\n            rl[0] + (r0 - innerRadius) * m,\n            rl[0] + (r1 - innerRadius) * m\n        ];\n        update[_this.id + '.radialaxis.range'] = newRng;\n    }\n\n    function zoomClick(numClicks, evt) {\n        var clickMode = gd._fullLayout.clickmode;\n\n        dragBox.removeZoombox(gd);\n\n        // TODO double once vs twice logic (autorange vs fixed range)\n        if(numClicks === 2) {\n            var updateObj = {};\n            for(var k in _this.viewInitial) {\n                updateObj[_this.id + '.' + k] = _this.viewInitial[k];\n            }\n\n            gd.emit('plotly_doubleclick', null);\n            Registry.call('_guiRelayout', gd, updateObj);\n        }\n\n        if(clickMode.indexOf('select') > -1 && numClicks === 1) {\n            selectOnClick(evt, gd, [_this.xaxis], [_this.yaxis], _this.id, dragOpts);\n        }\n\n        if(clickMode.indexOf('event') > -1) {\n            Fx.click(gd, evt, _this.id);\n        }\n    }\n\n    dragOpts.prepFn = function(evt, startX, startY) {\n        var dragModeNow = gd._fullLayout.dragmode;\n\n        var bbox = mainDrag.getBoundingClientRect();\n        x0 = startX - bbox.left;\n        y0 = startY - bbox.top;\n\n        // need to offset x/y as bbox center does not\n        // match origin for asymmetric polygons\n        if(vangles) {\n            var offset = helpers.findPolygonOffset(radius, sectorInRad[0], sectorInRad[1], vangles);\n            x0 += cxx + offset[0];\n            y0 += cyy + offset[1];\n        }\n\n        switch(dragModeNow) {\n            case 'zoom':\n                if(vangles) {\n                    dragOpts.moveFn = zoomMoveForPolygons;\n                } else {\n                    dragOpts.moveFn = zoomMove;\n                }\n                dragOpts.clickFn = zoomClick;\n                dragOpts.doneFn = zoomDone;\n                zoomPrep(evt, startX, startY);\n                break;\n            case 'select':\n            case 'lasso':\n                prepSelect(evt, startX, startY, dragOpts, dragModeNow);\n                break;\n        }\n    };\n\n    mainDrag.onmousemove = function(evt) {\n        Fx.hover(gd, evt, _this.id);\n        gd._fullLayout._lasthover = mainDrag;\n        gd._fullLayout._hoversubplot = _this.id;\n    };\n\n    mainDrag.onmouseout = function(evt) {\n        if(gd._dragging) return;\n        dragElement.unhover(gd, evt);\n    };\n\n    dragElement.init(dragOpts);\n};\n\nproto.updateRadialDrag = function(fullLayout, polarLayout, rngIndex) {\n    var _this = this;\n    var gd = _this.gd;\n    var layers = _this.layers;\n    var radius = _this.radius;\n    var innerRadius = _this.innerRadius;\n    var cx = _this.cx;\n    var cy = _this.cy;\n    var radialAxis = _this.radialAxis;\n    var bl = constants.radialDragBoxSize;\n    var bl2 = bl / 2;\n\n    if(!radialAxis.visible) return;\n\n    var angle0 = deg2rad(_this.radialAxisAngle);\n    var rl = radialAxis._rl;\n    var rl0 = rl[0];\n    var rl1 = rl[1];\n    var rbase = rl[rngIndex];\n    var m = 0.75 * (rl[1] - rl[0]) / (1 - polarLayout.hole) / radius;\n\n    var tx, ty, className;\n    if(rngIndex) {\n        tx = cx + (radius + bl2) * Math.cos(angle0);\n        ty = cy - (radius + bl2) * Math.sin(angle0);\n        className = 'radialdrag';\n    } else {\n        // the 'inner' box can get called:\n        // - when polar.hole>0\n        // - when polar.sector isn't a full circle\n        // otherwise it is hidden behind the main drag.\n        tx = cx + (innerRadius - bl2) * Math.cos(angle0);\n        ty = cy - (innerRadius - bl2) * Math.sin(angle0);\n        className = 'radialdrag-inner';\n    }\n\n    var radialDrag = dragBox.makeRectDragger(layers, className, 'crosshair', -bl2, -bl2, bl, bl);\n    var dragOpts = {element: radialDrag, gd: gd};\n\n    updateElement(d3.select(radialDrag), radialAxis.visible && innerRadius < radius, {\n        transform: strTranslate(tx, ty)\n    });\n\n    // move function (either rotate or re-range flavor)\n    var moveFn2;\n    // rotate angle on done\n    var angle1;\n    // re-range range[1] (or range[0]) on done\n    var rprime;\n\n    function moveFn(dx, dy) {\n        if(moveFn2) {\n            moveFn2(dx, dy);\n        } else {\n            var dvec = [dx, -dy];\n            var rvec = [Math.cos(angle0), Math.sin(angle0)];\n            var comp = Math.abs(Lib.dot(dvec, rvec) / Math.sqrt(Lib.dot(dvec, dvec)));\n\n            // mostly perpendicular motions rotate,\n            // mostly parallel motions re-range\n            if(!isNaN(comp)) {\n                moveFn2 = comp < 0.5 ? rotateMove : rerangeMove;\n            }\n        }\n\n        var update = {};\n        computeRadialAxisUpdates(update);\n        gd.emit('plotly_relayouting', update);\n    }\n\n    function computeRadialAxisUpdates(update) {\n        if(angle1 !== null) {\n            update[_this.id + '.radialaxis.angle'] = angle1;\n        } else if(rprime !== null) {\n            update[_this.id + '.radialaxis.range[' + rngIndex + ']'] = rprime;\n        }\n    }\n\n    function doneFn() {\n        if(angle1 !== null) {\n            Registry.call('_guiRelayout', gd, _this.id + '.radialaxis.angle', angle1);\n        } else if(rprime !== null) {\n            Registry.call('_guiRelayout', gd, _this.id + '.radialaxis.range[' + rngIndex + ']', rprime);\n        }\n    }\n\n    function rotateMove(dx, dy) {\n        // disable for inner drag boxes\n        if(rngIndex === 0) return;\n\n        var x1 = tx + dx;\n        var y1 = ty + dy;\n\n        angle1 = Math.atan2(cy - y1, x1 - cx);\n        if(_this.vangles) angle1 = snapToVertexAngle(angle1, _this.vangles);\n        angle1 = rad2deg(angle1);\n\n        var transform = strTranslate(cx, cy) + strRotate(-angle1);\n        layers['radial-axis'].attr('transform', transform);\n        layers['radial-line'].select('line').attr('transform', transform);\n\n        var fullLayoutNow = _this.gd._fullLayout;\n        var polarLayoutNow = fullLayoutNow[_this.id];\n        _this.updateRadialAxisTitle(fullLayoutNow, polarLayoutNow, angle1);\n    }\n\n    function rerangeMove(dx, dy) {\n        // project (dx, dy) unto unit radial axis vector\n        var dr = Lib.dot([dx, -dy], [Math.cos(angle0), Math.sin(angle0)]);\n        rprime = rbase - m * dr;\n\n        // make sure rprime does not change the range[0] -> range[1] sign\n        if((m > 0) !== (rngIndex ? rprime > rl0 : rprime < rl1)) {\n            rprime = null;\n            return;\n        }\n\n        var fullLayoutNow = gd._fullLayout;\n        var polarLayoutNow = fullLayoutNow[_this.id];\n\n        // update radial range -> update c2g -> update _m,_b\n        radialAxis.range[rngIndex] = rprime;\n        radialAxis._rl[rngIndex] = rprime;\n        _this.updateRadialAxis(fullLayoutNow, polarLayoutNow);\n\n        _this.xaxis.setRange();\n        _this.xaxis.setScale();\n        _this.yaxis.setRange();\n        _this.yaxis.setScale();\n\n        var hasRegl = false;\n\n        for(var traceType in _this.traceHash) {\n            var moduleCalcData = _this.traceHash[traceType];\n            var moduleCalcDataVisible = Lib.filterVisible(moduleCalcData);\n            var _module = moduleCalcData[0][0].trace._module;\n            _module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);\n            if(Registry.traceIs(traceType, 'gl') && moduleCalcDataVisible.length) hasRegl = true;\n        }\n\n        if(hasRegl) {\n            clearGlCanvases(gd);\n            redrawReglTraces(gd);\n        }\n    }\n\n    dragOpts.prepFn = function() {\n        moveFn2 = null;\n        angle1 = null;\n        rprime = null;\n\n        dragOpts.moveFn = moveFn;\n        dragOpts.doneFn = doneFn;\n\n        clearSelect(gd);\n    };\n\n    dragOpts.clampFn = function(dx, dy) {\n        if(Math.sqrt(dx * dx + dy * dy) < constants.MINDRAG) {\n            dx = 0;\n            dy = 0;\n        }\n        return [dx, dy];\n    };\n\n    dragElement.init(dragOpts);\n};\n\nproto.updateAngularDrag = function(fullLayout) {\n    var _this = this;\n    var gd = _this.gd;\n    var layers = _this.layers;\n    var radius = _this.radius;\n    var angularAxis = _this.angularAxis;\n    var cx = _this.cx;\n    var cy = _this.cy;\n    var cxx = _this.cxx;\n    var cyy = _this.cyy;\n    var dbs = constants.angularDragBoxSize;\n\n    var angularDrag = dragBox.makeDragger(layers, 'path', 'angulardrag', 'move');\n    var dragOpts = {element: angularDrag, gd: gd};\n\n    d3.select(angularDrag)\n        .attr('d', _this.pathAnnulus(radius, radius + dbs))\n        .attr('transform', strTranslate(cx, cy))\n        .call(setCursor, 'move');\n\n    function xy2a(x, y) {\n        return Math.atan2(cyy + dbs - y, x - cxx - dbs);\n    }\n\n    // scatter trace, points and textpoints selections\n    var scatterTraces = layers.frontplot.select('.scatterlayer').selectAll('.trace');\n    var scatterPoints = scatterTraces.selectAll('.point');\n    var scatterTextPoints = scatterTraces.selectAll('.textpoint');\n\n    // mouse px position at drag start (0), move (1)\n    var x0, y0;\n    // angular axis angle rotation at drag start (0), move (1)\n    var rot0, rot1;\n    // induced radial axis rotation (only used on polygon grids)\n    var rrot1;\n    // angle about circle center at drag start\n    var a0;\n\n    function moveFn(dx, dy) {\n        var fullLayoutNow = _this.gd._fullLayout;\n        var polarLayoutNow = fullLayoutNow[_this.id];\n\n        var x1 = x0 + dx;\n        var y1 = y0 + dy;\n        var a1 = xy2a(x1, y1);\n        var da = rad2deg(a1 - a0);\n        rot1 = rot0 + da;\n\n        layers.frontplot.attr('transform',\n            strTranslate(_this.xOffset2, _this.yOffset2) + strRotate([-da, cxx, cyy])\n        );\n\n        if(_this.vangles) {\n            rrot1 = _this.radialAxisAngle + da;\n\n            var trans = strTranslate(cx, cy) + strRotate(-da);\n            var trans2 = strTranslate(cx, cy) + strRotate(-rrot1);\n\n            layers.bg.attr('transform', trans);\n            layers['radial-grid'].attr('transform', trans);\n            layers['radial-axis'].attr('transform', trans2);\n            layers['radial-line'].select('line').attr('transform', trans2);\n            _this.updateRadialAxisTitle(fullLayoutNow, polarLayoutNow, rrot1);\n        } else {\n            _this.clipPaths.forTraces.select('path').attr('transform',\n                strTranslate(cxx, cyy) + strRotate(da)\n            );\n        }\n\n        // 'un-rotate' marker and text points\n        scatterPoints.each(function() {\n            var sel = d3.select(this);\n            var xy = Drawing.getTranslate(sel);\n            sel.attr('transform', strTranslate(xy.x, xy.y) + strRotate([da]));\n        });\n        scatterTextPoints.each(function() {\n            var sel = d3.select(this);\n            var tx = sel.select('text');\n            var xy = Drawing.getTranslate(sel);\n            // N.B rotate -> translate ordering matters\n            sel.attr('transform', strRotate([da, tx.attr('x'), tx.attr('y')]) + strTranslate(xy.x, xy.y));\n        });\n\n        // update rotation -> range -> _m,_b\n        angularAxis.rotation = Lib.modHalf(rot1, 360);\n        _this.updateAngularAxis(fullLayoutNow, polarLayoutNow);\n\n        if(_this._hasClipOnAxisFalse && !Lib.isFullCircle(_this.sectorInRad)) {\n            scatterTraces.call(Drawing.hideOutsideRangePoints, _this);\n        }\n\n        var hasRegl = false;\n\n        for(var traceType in _this.traceHash) {\n            if(Registry.traceIs(traceType, 'gl')) {\n                var moduleCalcData = _this.traceHash[traceType];\n                var moduleCalcDataVisible = Lib.filterVisible(moduleCalcData);\n                var _module = moduleCalcData[0][0].trace._module;\n                _module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);\n                if(moduleCalcDataVisible.length) hasRegl = true;\n            }\n        }\n\n        if(hasRegl) {\n            clearGlCanvases(gd);\n            redrawReglTraces(gd);\n        }\n\n        var update = {};\n        computeRotationUpdates(update);\n        gd.emit('plotly_relayouting', update);\n    }\n\n    function computeRotationUpdates(updateObj) {\n        updateObj[_this.id + '.angularaxis.rotation'] = rot1;\n\n        if(_this.vangles) {\n            updateObj[_this.id + '.radialaxis.angle'] = rrot1;\n        }\n    }\n\n    function doneFn() {\n        scatterTextPoints.select('text').attr('transform', null);\n\n        var updateObj = {};\n        computeRotationUpdates(updateObj);\n        Registry.call('_guiRelayout', gd, updateObj);\n    }\n\n    dragOpts.prepFn = function(evt, startX, startY) {\n        var polarLayoutNow = fullLayout[_this.id];\n        rot0 = polarLayoutNow.angularaxis.rotation;\n\n        var bbox = angularDrag.getBoundingClientRect();\n        x0 = startX - bbox.left;\n        y0 = startY - bbox.top;\n        a0 = xy2a(x0, y0);\n\n        dragOpts.moveFn = moveFn;\n        dragOpts.doneFn = doneFn;\n\n        clearSelect(gd);\n    };\n\n    // I don't what we should do in this case, skip we now\n    if(_this.vangles && !Lib.isFullCircle(_this.sectorInRad)) {\n        dragOpts.prepFn = Lib.noop;\n        setCursor(d3.select(angularDrag), null);\n    }\n\n    dragElement.init(dragOpts);\n};\n\nproto.isPtInside = function(d) {\n    var sectorInRad = this.sectorInRad;\n    var vangles = this.vangles;\n    var thetag = this.angularAxis.c2g(d.theta);\n    var radialAxis = this.radialAxis;\n    var r = radialAxis.c2l(d.r);\n    var rl = radialAxis._rl;\n\n    var fn = vangles ? helpers.isPtInsidePolygon : Lib.isPtInsideSector;\n    return fn(r, thetag, rl, sectorInRad, vangles);\n};\n\nproto.pathArc = function(r) {\n    var sectorInRad = this.sectorInRad;\n    var vangles = this.vangles;\n    var fn = vangles ? helpers.pathPolygon : Lib.pathArc;\n    return fn(r, sectorInRad[0], sectorInRad[1], vangles);\n};\n\nproto.pathSector = function(r) {\n    var sectorInRad = this.sectorInRad;\n    var vangles = this.vangles;\n    var fn = vangles ? helpers.pathPolygon : Lib.pathSector;\n    return fn(r, sectorInRad[0], sectorInRad[1], vangles);\n};\n\nproto.pathAnnulus = function(r0, r1) {\n    var sectorInRad = this.sectorInRad;\n    var vangles = this.vangles;\n    var fn = vangles ? helpers.pathPolygonAnnulus : Lib.pathAnnulus;\n    return fn(r0, r1, sectorInRad[0], sectorInRad[1], vangles);\n};\n\nproto.pathSubplot = function() {\n    var r0 = this.innerRadius;\n    var r1 = this.radius;\n    return r0 ? this.pathAnnulus(r0, r1) : this.pathSector(r1);\n};\n\nproto.fillViewInitialKey = function(key, val) {\n    if(!(key in this.viewInitial)) {\n        this.viewInitial[key] = val;\n    }\n};\n\nfunction strTickLayout(axLayout) {\n    var out = axLayout.ticks + String(axLayout.ticklen) + String(axLayout.showticklabels);\n    if('side' in axLayout) out += axLayout.side;\n    return out;\n}\n\n// Finds the bounding box of a given circle sector,\n// inspired by https://math.stackexchange.com/q/1852703\n//\n// assumes:\n// - sector[0] < sector[1]\n// - counterclockwise rotation\nfunction computeSectorBBox(sector) {\n    var s0 = sector[0];\n    var s1 = sector[1];\n    var arc = s1 - s0;\n    var a0 = mod(s0, 360);\n    var a1 = a0 + arc;\n\n    var ax0 = Math.cos(deg2rad(a0));\n    var ay0 = Math.sin(deg2rad(a0));\n    var ax1 = Math.cos(deg2rad(a1));\n    var ay1 = Math.sin(deg2rad(a1));\n\n    var x0, y0, x1, y1;\n\n    if((a0 <= 90 && a1 >= 90) || (a0 > 90 && a1 >= 450)) {\n        y1 = 1;\n    } else if(ay0 <= 0 && ay1 <= 0) {\n        y1 = 0;\n    } else {\n        y1 = Math.max(ay0, ay1);\n    }\n\n    if((a0 <= 180 && a1 >= 180) || (a0 > 180 && a1 >= 540)) {\n        x0 = -1;\n    } else if(ax0 >= 0 && ax1 >= 0) {\n        x0 = 0;\n    } else {\n        x0 = Math.min(ax0, ax1);\n    }\n\n    if((a0 <= 270 && a1 >= 270) || (a0 > 270 && a1 >= 630)) {\n        y0 = -1;\n    } else if(ay0 >= 0 && ay1 >= 0) {\n        y0 = 0;\n    } else {\n        y0 = Math.min(ay0, ay1);\n    }\n\n    if(a1 >= 360) {\n        x1 = 1;\n    } else if(ax0 <= 0 && ax1 <= 0) {\n        x1 = 0;\n    } else {\n        x1 = Math.max(ax0, ax1);\n    }\n\n    return [x0, y0, x1, y1];\n}\n\nfunction snapToVertexAngle(a, vangles) {\n    var fn = function(v) { return Lib.angleDist(a, v); };\n    var ind = Lib.findIndexOfMin(vangles, fn);\n    return vangles[ind];\n}\n\nfunction updateElement(sel, showAttr, attrs) {\n    if(showAttr) {\n        sel.attr('display', null);\n        sel.attr(attrs);\n    } else if(sel) {\n        sel.attr('display', 'none');\n    }\n    return sel;\n}\n\nfunction strTranslate(x, y) {\n    return 'translate(' + x + ',' + y + ')';\n}\n\nfunction strRotate(angle) {\n    return 'rotate(' + angle + ')';\n}\n\n},{\"../../components/color\":593,\"../../components/dragelement\":611,\"../../components/drawing\":614,\"../../components/fx\":632,\"../../components/titles\":681,\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/clear_gl_canvases\":704,\"../../lib/setcursor\":739,\"../../plot_api/subroutines\":758,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"../cartesian/autorange\":766,\"../cartesian/dragbox\":775,\"../cartesian/select\":784,\"../cartesian/set_convert\":785,\"../plots\":828,\"./constants\":829,\"./helpers\":830,\"./set_convert\":841,\"d3\":163,\"tinycolor2\":537}],841:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar setConvertCartesian = _dereq_('../cartesian/set_convert');\n\nvar deg2rad = Lib.deg2rad;\nvar rad2deg = Lib.rad2deg;\n\n/**\n * setConvert for polar axes!\n *\n * @param {object} ax\n *   axis in question (works for both radial and angular axes)\n * @param {object} polarLayout\n *   full polar layout of the subplot associated with 'ax'\n * @param {object} fullLayout\n *   full layout\n *\n * Here, reuse some of the Cartesian setConvert logic,\n * but we must extend some of it, as both radial and angular axes\n * don't have domains and angular axes don't have _true_ ranges.\n *\n * Moreover, we introduce two new coordinate systems:\n * - 'g' for geometric coordinates and\n * - 't' for angular ticks\n *\n * Radial axis coordinate systems:\n * - d, c and l: same as for cartesian axes\n * - g: like calcdata but translated about `radialaxis.range[0]` & `polar.hole`\n *\n * Angular axis coordinate systems:\n * - d: data, in whatever form it's provided\n * - c: calcdata, turned into radians (for linear axes)\n *      or category indices (category axes)\n * - t: tick calcdata, just like 'c' but in degrees for linear axes\n * - g: geometric calcdata, radians coordinates that take into account\n *      axis rotation and direction\n *\n * Then, 'g'eometric data is ready to be converted to (x,y).\n */\nmodule.exports = function setConvert(ax, polarLayout, fullLayout) {\n    setConvertCartesian(ax, fullLayout);\n\n    switch(ax._id) {\n        case 'x':\n        case 'radialaxis':\n            setConvertRadial(ax, polarLayout);\n            break;\n        case 'angularaxis':\n            setConvertAngular(ax, polarLayout);\n            break;\n    }\n};\n\nfunction setConvertRadial(ax, polarLayout) {\n    var subplot = polarLayout._subplot;\n\n    ax.setGeometry = function() {\n        var rl0 = ax._rl[0];\n        var rl1 = ax._rl[1];\n\n        var b = subplot.innerRadius;\n        var m = (subplot.radius - b) / (rl1 - rl0);\n        var b2 = b / m;\n\n        var rFilter = rl0 > rl1 ?\n            function(v) { return v <= 0; } :\n            function(v) { return v >= 0; };\n\n        ax.c2g = function(v) {\n            var r = ax.c2l(v) - rl0;\n            return (rFilter(r) ? r : 0) + b2;\n        };\n\n        ax.g2c = function(v) {\n            return ax.l2c(v + rl0 - b2);\n        };\n\n        ax.g2p = function(v) { return v * m; };\n        ax.c2p = function(v) { return ax.g2p(ax.c2g(v)); };\n    };\n}\n\nfunction toRadians(v, unit) {\n    return unit === 'degrees' ? deg2rad(v) : v;\n}\n\nfunction fromRadians(v, unit) {\n    return unit === 'degrees' ? rad2deg(v) : v;\n}\n\nfunction setConvertAngular(ax, polarLayout) {\n    var axType = ax.type;\n\n    if(axType === 'linear') {\n        var _d2c = ax.d2c;\n        var _c2d = ax.c2d;\n\n        ax.d2c = function(v, unit) { return toRadians(_d2c(v), unit); };\n        ax.c2d = function(v, unit) { return _c2d(fromRadians(v, unit)); };\n    }\n\n    // override makeCalcdata to handle thetaunit and special theta0/dtheta logic\n    ax.makeCalcdata = function(trace, coord) {\n        var arrayIn = trace[coord];\n        var len = trace._length;\n        var arrayOut, i;\n\n        var _d2c = function(v) { return ax.d2c(v, trace.thetaunit); };\n\n        if(arrayIn) {\n            if(Lib.isTypedArray(arrayIn) && axType === 'linear') {\n                if(len === arrayIn.length) {\n                    return arrayIn;\n                } else if(arrayIn.subarray) {\n                    return arrayIn.subarray(0, len);\n                }\n            }\n\n            arrayOut = new Array(len);\n            for(i = 0; i < len; i++) {\n                arrayOut[i] = _d2c(arrayIn[i]);\n            }\n        } else {\n            var coord0 = coord + '0';\n            var dcoord = 'd' + coord;\n            var v0 = (coord0 in trace) ? _d2c(trace[coord0]) : 0;\n            var dv = (trace[dcoord]) ? _d2c(trace[dcoord]) : (ax.period || 2 * Math.PI) / len;\n\n            arrayOut = new Array(len);\n            for(i = 0; i < len; i++) {\n                arrayOut[i] = v0 + i * dv;\n            }\n        }\n\n        return arrayOut;\n    };\n\n    // N.B. we mock the axis 'range' here\n    ax.setGeometry = function() {\n        var sector = polarLayout.sector;\n        var sectorInRad = sector.map(deg2rad);\n        var dir = {clockwise: -1, counterclockwise: 1}[ax.direction];\n        var rot = deg2rad(ax.rotation);\n\n        var rad2g = function(v) { return dir * v + rot; };\n        var g2rad = function(v) { return (v - rot) / dir; };\n\n        var rad2c, c2rad;\n        var rad2t, t2rad;\n\n        switch(axType) {\n            case 'linear':\n                c2rad = rad2c = Lib.identity;\n                t2rad = deg2rad;\n                rad2t = rad2deg;\n\n                // Set the angular range in degrees to make auto-tick computation cleaner,\n                // changing rotation/direction should not affect the angular tick value.\n                ax.range = Lib.isFullCircle(sectorInRad) ?\n                    [sector[0], sector[0] + 360] :\n                    sectorInRad.map(g2rad).map(rad2deg);\n                break;\n\n            case 'category':\n                var catLen = ax._categories.length;\n                var _period = ax.period ? Math.max(ax.period, catLen) : catLen;\n\n                // fallback in case all categories have been filtered out\n                if(_period === 0) _period = 1;\n\n                c2rad = t2rad = function(v) { return v * 2 * Math.PI / _period; };\n                rad2c = rad2t = function(v) { return v * _period / Math.PI / 2; };\n\n                ax.range = [0, _period];\n                break;\n        }\n\n        ax.c2g = function(v) { return rad2g(c2rad(v)); };\n        ax.g2c = function(v) { return rad2c(g2rad(v)); };\n\n        ax.t2g = function(v) { return rad2g(t2rad(v)); };\n        ax.g2t = function(v) { return rad2t(g2rad(v)); };\n    };\n}\n\n},{\"../../lib\":719,\"../cartesian/set_convert\":785}],842:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar Template = _dereq_('../plot_api/plot_template');\nvar handleDomainDefaults = _dereq_('./domain').defaults;\n\n\n/**\n * Find and supply defaults to all subplots of a given type\n * This handles subplots that are contained within one container - so\n * gl3d, geo, ternary... but not 2d axes which have separate x and y axes\n * finds subplots, coerces their `domain` attributes, then calls the\n * given handleDefaults function to fill in everything else.\n *\n * layoutIn: the complete user-supplied input layout\n * layoutOut: the complete finished layout\n * fullData: the finished data array, used only to find subplots\n * opts: {\n *  type: subplot type string\n *  attributes: subplot attributes object\n *  partition: 'x' or 'y', which direction to divide domain space by default\n *      (default 'x', ie side-by-side subplots)\n *      TODO: this option is only here because 3D and geo made opposite\n *      choices in this regard previously and I didn't want to change it.\n *      Instead we should do:\n *      - something consistent\n *      - something more square (4 cuts 2x2, 5/6 cuts 2x3, etc.)\n *      - something that includes all subplot types in one arrangement,\n *        now that we can have them together!\n *  handleDefaults: function of (subplotLayoutIn, subplotLayoutOut, coerce, opts)\n *      this opts object is passed through to handleDefaults, so attach any\n *      additional items needed by this function here as well\n * }\n */\nmodule.exports = function handleSubplotDefaults(layoutIn, layoutOut, fullData, opts) {\n    var subplotType = opts.type;\n    var subplotAttributes = opts.attributes;\n    var handleDefaults = opts.handleDefaults;\n    var partition = opts.partition || 'x';\n\n    var ids = layoutOut._subplots[subplotType];\n    var idsLength = ids.length;\n\n    var baseId = idsLength && ids[0].replace(/\\d+$/, '');\n\n    var subplotLayoutIn, subplotLayoutOut;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(subplotLayoutIn, subplotLayoutOut, subplotAttributes, attr, dflt);\n    }\n\n    for(var i = 0; i < idsLength; i++) {\n        var id = ids[i];\n\n        // ternary traces get a layout ternary for free!\n        if(layoutIn[id]) subplotLayoutIn = layoutIn[id];\n        else subplotLayoutIn = layoutIn[id] = {};\n\n        subplotLayoutOut = Template.newContainer(layoutOut, id, baseId);\n\n        // All subplot containers get a `uirevision` inheriting from the base.\n        // Currently all subplots containers have some user interaction\n        // attributes, but if we ever add one that doesn't, we would need an\n        // option to skip this step.\n        coerce('uirevision', layoutOut.uirevision);\n\n        var dfltDomains = {};\n        dfltDomains[partition] = [i / idsLength, (i + 1) / idsLength];\n        handleDomainDefaults(subplotLayoutOut, layoutOut, coerce, dfltDomains);\n\n        opts.id = id;\n        handleDefaults(subplotLayoutIn, subplotLayoutOut, coerce, opts);\n    }\n};\n\n},{\"../lib\":719,\"../plot_api/plot_template\":757,\"./domain\":792}],843:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Ternary = _dereq_('./ternary');\n\nvar getSubplotCalcData = _dereq_('../../plots/get_data').getSubplotCalcData;\nvar counterRegex = _dereq_('../../lib').counterRegex;\nvar TERNARY = 'ternary';\n\nexports.name = TERNARY;\n\nvar attr = exports.attr = 'subplot';\n\nexports.idRoot = TERNARY;\n\nexports.idRegex = exports.attrRegex = counterRegex(TERNARY);\n\nvar attributes = exports.attributes = {};\nattributes[attr] = {\n    valType: 'subplotid',\n    \n    dflt: 'ternary',\n    editType: 'calc',\n    \n};\n\nexports.layoutAttributes = _dereq_('./layout_attributes');\n\nexports.supplyLayoutDefaults = _dereq_('./layout_defaults');\n\nexports.plot = function plot(gd) {\n    var fullLayout = gd._fullLayout;\n    var calcData = gd.calcdata;\n    var ternaryIds = fullLayout._subplots[TERNARY];\n\n    for(var i = 0; i < ternaryIds.length; i++) {\n        var ternaryId = ternaryIds[i];\n        var ternaryCalcData = getSubplotCalcData(calcData, TERNARY, ternaryId);\n        var ternary = fullLayout[ternaryId]._subplot;\n\n        // If ternary is not instantiated, create one!\n        if(!ternary) {\n            ternary = new Ternary({\n                id: ternaryId,\n                graphDiv: gd,\n                container: fullLayout._ternarylayer.node()\n            },\n                fullLayout\n            );\n\n            fullLayout[ternaryId]._subplot = ternary;\n        }\n\n        ternary.plot(ternaryCalcData, fullLayout, gd._promises);\n    }\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var oldTernaryKeys = oldFullLayout._subplots[TERNARY] || [];\n\n    for(var i = 0; i < oldTernaryKeys.length; i++) {\n        var oldTernaryKey = oldTernaryKeys[i];\n        var oldTernary = oldFullLayout[oldTernaryKey]._subplot;\n\n        if(!newFullLayout[oldTernaryKey] && !!oldTernary) {\n            oldTernary.plotContainer.remove();\n            oldTernary.clipDef.remove();\n            oldTernary.clipDefRelative.remove();\n            oldTernary.layers['a-title'].remove();\n            oldTernary.layers['b-title'].remove();\n            oldTernary.layers['c-title'].remove();\n        }\n    }\n};\n\n},{\"../../lib\":719,\"../../plots/get_data\":802,\"./layout_attributes\":844,\"./layout_defaults\":845,\"./ternary\":846}],844:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar domainAttrs = _dereq_('../domain').attributes;\nvar axesAttrs = _dereq_('../cartesian/layout_attributes');\n\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar ternaryAxesAttrs = {\n    title: axesAttrs.title,\n    color: axesAttrs.color,\n    // ticks\n    tickmode: axesAttrs.tickmode,\n    nticks: extendFlat({}, axesAttrs.nticks, {dflt: 6, min: 1}),\n    tick0: axesAttrs.tick0,\n    dtick: axesAttrs.dtick,\n    tickvals: axesAttrs.tickvals,\n    ticktext: axesAttrs.ticktext,\n    ticks: axesAttrs.ticks,\n    ticklen: axesAttrs.ticklen,\n    tickwidth: axesAttrs.tickwidth,\n    tickcolor: axesAttrs.tickcolor,\n    showticklabels: axesAttrs.showticklabels,\n    showtickprefix: axesAttrs.showtickprefix,\n    tickprefix: axesAttrs.tickprefix,\n    showticksuffix: axesAttrs.showticksuffix,\n    ticksuffix: axesAttrs.ticksuffix,\n    showexponent: axesAttrs.showexponent,\n    exponentformat: axesAttrs.exponentformat,\n    separatethousands: axesAttrs.separatethousands,\n    tickfont: axesAttrs.tickfont,\n    tickangle: axesAttrs.tickangle,\n    tickformat: axesAttrs.tickformat,\n    tickformatstops: axesAttrs.tickformatstops,\n    hoverformat: axesAttrs.hoverformat,\n    // lines and grids\n    showline: extendFlat({}, axesAttrs.showline, {dflt: true}),\n    linecolor: axesAttrs.linecolor,\n    linewidth: axesAttrs.linewidth,\n    showgrid: extendFlat({}, axesAttrs.showgrid, {dflt: true}),\n    gridcolor: axesAttrs.gridcolor,\n    gridwidth: axesAttrs.gridwidth,\n    layer: axesAttrs.layer,\n    // range\n    min: {\n        valType: 'number',\n        dflt: 0,\n        \n        min: 0,\n        \n    },\n    _deprecated: {\n        title: axesAttrs._deprecated.title,\n        titlefont: axesAttrs._deprecated.titlefont\n    }\n};\n\nvar attrs = module.exports = overrideAll({\n    domain: domainAttrs({name: 'ternary'}),\n\n    bgcolor: {\n        valType: 'color',\n        \n        dflt: colorAttrs.background,\n        \n    },\n    sum: {\n        valType: 'number',\n        \n        dflt: 1,\n        min: 0,\n        \n    },\n    aaxis: ternaryAxesAttrs,\n    baxis: ternaryAxesAttrs,\n    caxis: ternaryAxesAttrs\n}, 'plot', 'from-root');\n\n// set uirevisions outside of `overrideAll` so we can get `editType: none`\nattrs.uirevision = {\n    valType: 'any',\n    \n    editType: 'none',\n    \n};\n\nattrs.aaxis.uirevision = attrs.baxis.uirevision = attrs.caxis.uirevision = {\n    valType: 'any',\n    \n    editType: 'none',\n    \n};\n\n},{\"../../components/color/attributes\":592,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../cartesian/layout_attributes\":779,\"../domain\":792}],845:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Color = _dereq_('../../components/color');\nvar Template = _dereq_('../../plot_api/plot_template');\nvar Lib = _dereq_('../../lib');\n\nvar handleSubplotDefaults = _dereq_('../subplot_defaults');\nvar handleTickLabelDefaults = _dereq_('../cartesian/tick_label_defaults');\nvar handleTickMarkDefaults = _dereq_('../cartesian/tick_mark_defaults');\nvar handleTickValueDefaults = _dereq_('../cartesian/tick_value_defaults');\nvar handleLineGridDefaults = _dereq_('../cartesian/line_grid_defaults');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nvar axesNames = ['aaxis', 'baxis', 'caxis'];\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    handleSubplotDefaults(layoutIn, layoutOut, fullData, {\n        type: 'ternary',\n        attributes: layoutAttributes,\n        handleDefaults: handleTernaryDefaults,\n        font: layoutOut.font,\n        paper_bgcolor: layoutOut.paper_bgcolor\n    });\n};\n\nfunction handleTernaryDefaults(ternaryLayoutIn, ternaryLayoutOut, coerce, options) {\n    var bgColor = coerce('bgcolor');\n    var sum = coerce('sum');\n    options.bgColor = Color.combine(bgColor, options.paper_bgcolor);\n    var axName, containerIn, containerOut;\n\n    // TODO: allow most (if not all) axis attributes to be set\n    // in the outer container and used as defaults in the individual axes?\n\n    for(var j = 0; j < axesNames.length; j++) {\n        axName = axesNames[j];\n        containerIn = ternaryLayoutIn[axName] || {};\n        containerOut = Template.newContainer(ternaryLayoutOut, axName);\n        containerOut._name = axName;\n\n        handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut);\n    }\n\n    // if the min values contradict each other, set them all to default (0)\n    // and delete *all* the inputs so the user doesn't get confused later by\n    // changing one and having them all change.\n    var aaxis = ternaryLayoutOut.aaxis;\n    var baxis = ternaryLayoutOut.baxis;\n    var caxis = ternaryLayoutOut.caxis;\n    if(aaxis.min + baxis.min + caxis.min >= sum) {\n        aaxis.min = 0;\n        baxis.min = 0;\n        caxis.min = 0;\n        if(ternaryLayoutIn.aaxis) delete ternaryLayoutIn.aaxis.min;\n        if(ternaryLayoutIn.baxis) delete ternaryLayoutIn.baxis.min;\n        if(ternaryLayoutIn.caxis) delete ternaryLayoutIn.caxis.min;\n    }\n}\n\nfunction handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut) {\n    var axAttrs = layoutAttributes[containerOut._name];\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(containerIn, containerOut, axAttrs, attr, dflt);\n    }\n\n    coerce('uirevision', ternaryLayoutOut.uirevision);\n\n    containerOut.type = 'linear'; // no other types allowed for ternary\n\n    var dfltColor = coerce('color');\n    // if axis.color was provided, use it for fonts too; otherwise,\n    // inherit from global font color in case that was provided.\n    var dfltFontColor = (dfltColor !== axAttrs.color.dflt) ? dfltColor : options.font.color;\n\n    var axName = containerOut._name;\n    var letterUpper = axName.charAt(0).toUpperCase();\n    var dfltTitle = 'Component ' + letterUpper;\n\n    var title = coerce('title.text', dfltTitle);\n    containerOut._hovertitle = title === dfltTitle ? title : letterUpper;\n\n    Lib.coerceFont(coerce, 'title.font', {\n        family: options.font.family,\n        size: Math.round(options.font.size * 1.2),\n        color: dfltFontColor\n    });\n\n    // range is just set by 'min' - max is determined by the other axes mins\n    coerce('min');\n\n    handleTickValueDefaults(containerIn, containerOut, coerce, 'linear');\n    handleTickLabelDefaults(containerIn, containerOut, coerce, 'linear', {});\n    handleTickMarkDefaults(containerIn, containerOut, coerce,\n        { outerTicks: true });\n\n    var showTickLabels = coerce('showticklabels');\n    if(showTickLabels) {\n        Lib.coerceFont(coerce, 'tickfont', {\n            family: options.font.family,\n            size: options.font.size,\n            color: dfltFontColor\n        });\n        coerce('tickangle');\n        coerce('tickformat');\n    }\n\n    handleLineGridDefaults(containerIn, containerOut, coerce, {\n        dfltColor: dfltColor,\n        bgColor: options.bgColor,\n        // default grid color is darker here (60%, vs cartesian default ~91%)\n        // because the grid is not square so the eye needs heavier cues to follow\n        blend: 60,\n        showLine: true,\n        showGrid: true,\n        noZeroLine: true,\n        attributes: axAttrs\n    });\n\n    coerce('hoverformat');\n    coerce('layer');\n}\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../cartesian/line_grid_defaults\":781,\"../cartesian/tick_label_defaults\":786,\"../cartesian/tick_mark_defaults\":787,\"../cartesian/tick_value_defaults\":788,\"../subplot_defaults\":842,\"./layout_attributes\":844}],846:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar tinycolor = _dereq_('tinycolor2');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar _ = Lib._;\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar setConvert = _dereq_('../cartesian/set_convert');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar Plots = _dereq_('../plots');\nvar Axes = _dereq_('../cartesian/axes');\nvar dragElement = _dereq_('../../components/dragelement');\nvar Fx = _dereq_('../../components/fx');\nvar Titles = _dereq_('../../components/titles');\nvar prepSelect = _dereq_('../cartesian/select').prepSelect;\nvar selectOnClick = _dereq_('../cartesian/select').selectOnClick;\nvar clearSelect = _dereq_('../cartesian/select').clearSelect;\nvar constants = _dereq_('../cartesian/constants');\n\nfunction Ternary(options, fullLayout) {\n    this.id = options.id;\n    this.graphDiv = options.graphDiv;\n    this.init(fullLayout);\n    this.makeFramework(fullLayout);\n\n    // unfortunately, we have to keep track of some axis tick settings\n    // as ternary subplots do not implement the 'ticks' editType\n    this.aTickLayout = null;\n    this.bTickLayout = null;\n    this.cTickLayout = null;\n}\n\nmodule.exports = Ternary;\n\nvar proto = Ternary.prototype;\n\nproto.init = function(fullLayout) {\n    this.container = fullLayout._ternarylayer;\n    this.defs = fullLayout._defs;\n    this.layoutId = fullLayout._uid;\n    this.traceHash = {};\n    this.layers = {};\n};\n\nproto.plot = function(ternaryCalcData, fullLayout) {\n    var _this = this;\n    var ternaryLayout = fullLayout[_this.id];\n    var graphSize = fullLayout._size;\n\n    _this._hasClipOnAxisFalse = false;\n    for(var i = 0; i < ternaryCalcData.length; i++) {\n        var trace = ternaryCalcData[i][0].trace;\n\n        if(trace.cliponaxis === false) {\n            _this._hasClipOnAxisFalse = true;\n            break;\n        }\n    }\n\n    _this.updateLayers(ternaryLayout);\n    _this.adjustLayout(ternaryLayout, graphSize);\n    Plots.generalUpdatePerTraceModule(_this.graphDiv, _this, ternaryCalcData, ternaryLayout);\n    _this.layers.plotbg.select('path').call(Color.fill, ternaryLayout.bgcolor);\n};\n\nproto.makeFramework = function(fullLayout) {\n    var _this = this;\n    var gd = _this.graphDiv;\n    var ternaryLayout = fullLayout[_this.id];\n\n    var clipId = _this.clipId = 'clip' + _this.layoutId + _this.id;\n    var clipIdRelative = _this.clipIdRelative = 'clip-relative' + _this.layoutId + _this.id;\n\n    // clippath for this ternary subplot\n    _this.clipDef = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipId, function(s) {\n        s.append('path').attr('d', 'M0,0Z');\n    });\n\n    // 'relative' clippath (i.e. no translation) for this ternary subplot\n    _this.clipDefRelative = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipIdRelative, function(s) {\n        s.append('path').attr('d', 'M0,0Z');\n    });\n\n    // container for everything in this ternary subplot\n    _this.plotContainer = Lib.ensureSingle(_this.container, 'g', _this.id);\n    _this.updateLayers(ternaryLayout);\n\n    Drawing.setClipUrl(_this.layers.backplot, clipId, gd);\n    Drawing.setClipUrl(_this.layers.grids, clipId, gd);\n};\n\nproto.updateLayers = function(ternaryLayout) {\n    var _this = this;\n    var layers = _this.layers;\n\n    // inside that container, we have one container for the data, and\n    // one each for the three axes around it.\n\n    var plotLayers = ['draglayer', 'plotbg', 'backplot', 'grids'];\n\n    if(ternaryLayout.aaxis.layer === 'below traces') {\n        plotLayers.push('aaxis', 'aline');\n    }\n    if(ternaryLayout.baxis.layer === 'below traces') {\n        plotLayers.push('baxis', 'bline');\n    }\n    if(ternaryLayout.caxis.layer === 'below traces') {\n        plotLayers.push('caxis', 'cline');\n    }\n\n    plotLayers.push('frontplot');\n\n    if(ternaryLayout.aaxis.layer === 'above traces') {\n        plotLayers.push('aaxis', 'aline');\n    }\n    if(ternaryLayout.baxis.layer === 'above traces') {\n        plotLayers.push('baxis', 'bline');\n    }\n    if(ternaryLayout.caxis.layer === 'above traces') {\n        plotLayers.push('caxis', 'cline');\n    }\n\n    var toplevel = _this.plotContainer.selectAll('g.toplevel')\n        .data(plotLayers, String);\n\n    var grids = ['agrid', 'bgrid', 'cgrid'];\n\n    toplevel.enter().append('g')\n        .attr('class', function(d) { return 'toplevel ' + d; })\n        .each(function(d) {\n            var s = d3.select(this);\n            layers[d] = s;\n\n            // containers for different trace types.\n            // NOTE - this is different from cartesian, where all traces\n            // are in front of grids. Here I'm putting maps behind the grids\n            // so the grids will always be visible if they're requested.\n            // Perhaps we want that for cartesian too?\n            if(d === 'frontplot') {\n                s.append('g').classed('scatterlayer', true);\n            } else if(d === 'backplot') {\n                s.append('g').classed('maplayer', true);\n            } else if(d === 'plotbg') {\n                s.append('path').attr('d', 'M0,0Z');\n            } else if(d === 'aline' || d === 'bline' || d === 'cline') {\n                s.append('path');\n            } else if(d === 'grids') {\n                grids.forEach(function(d) {\n                    layers[d] = s.append('g').classed('grid ' + d, true);\n                });\n            }\n        });\n\n    toplevel.order();\n};\n\nvar whRatio = Math.sqrt(4 / 3);\n\nproto.adjustLayout = function(ternaryLayout, graphSize) {\n    var _this = this;\n    var domain = ternaryLayout.domain;\n    var xDomainCenter = (domain.x[0] + domain.x[1]) / 2;\n    var yDomainCenter = (domain.y[0] + domain.y[1]) / 2;\n    var xDomain = domain.x[1] - domain.x[0];\n    var yDomain = domain.y[1] - domain.y[0];\n    var wmax = xDomain * graphSize.w;\n    var hmax = yDomain * graphSize.h;\n    var sum = ternaryLayout.sum;\n    var amin = ternaryLayout.aaxis.min;\n    var bmin = ternaryLayout.baxis.min;\n    var cmin = ternaryLayout.caxis.min;\n\n    var x0, y0, w, h, xDomainFinal, yDomainFinal;\n\n    if(wmax > whRatio * hmax) {\n        h = hmax;\n        w = h * whRatio;\n    } else {\n        w = wmax;\n        h = w / whRatio;\n    }\n\n    xDomainFinal = xDomain * w / wmax;\n    yDomainFinal = yDomain * h / hmax;\n\n    x0 = graphSize.l + graphSize.w * xDomainCenter - w / 2;\n    y0 = graphSize.t + graphSize.h * (1 - yDomainCenter) - h / 2;\n\n    _this.x0 = x0;\n    _this.y0 = y0;\n    _this.w = w;\n    _this.h = h;\n    _this.sum = sum;\n\n    // set up the x and y axis objects we'll use to lay out the points\n    _this.xaxis = {\n        type: 'linear',\n        range: [amin + 2 * cmin - sum, sum - amin - 2 * bmin],\n        domain: [\n            xDomainCenter - xDomainFinal / 2,\n            xDomainCenter + xDomainFinal / 2\n        ],\n        _id: 'x'\n    };\n    setConvert(_this.xaxis, _this.graphDiv._fullLayout);\n    _this.xaxis.setScale();\n    _this.xaxis.isPtWithinRange = function(d) {\n        return (\n            d.a >= _this.aaxis.range[0] &&\n            d.a <= _this.aaxis.range[1] &&\n            d.b >= _this.baxis.range[1] &&\n            d.b <= _this.baxis.range[0] &&\n            d.c >= _this.caxis.range[1] &&\n            d.c <= _this.caxis.range[0]\n        );\n    };\n\n    _this.yaxis = {\n        type: 'linear',\n        range: [amin, sum - bmin - cmin],\n        domain: [\n            yDomainCenter - yDomainFinal / 2,\n            yDomainCenter + yDomainFinal / 2\n        ],\n        _id: 'y'\n    };\n    setConvert(_this.yaxis, _this.graphDiv._fullLayout);\n    _this.yaxis.setScale();\n    _this.yaxis.isPtWithinRange = function() { return true; };\n\n    // set up the modified axes for tick drawing\n    var yDomain0 = _this.yaxis.domain[0];\n\n    // aaxis goes up the left side. Set it up as a y axis, but with\n    // fictitious angles and domain, but then rotate and translate\n    // it into place at the end\n    var aaxis = _this.aaxis = extendFlat({}, ternaryLayout.aaxis, {\n        range: [amin, sum - bmin - cmin],\n        side: 'left',\n        // tickangle = 'auto' means 0 anyway for a y axis, need to coerce to 0 here\n        // so we can shift by 30.\n        tickangle: (+ternaryLayout.aaxis.tickangle || 0) - 30,\n        domain: [yDomain0, yDomain0 + yDomainFinal * whRatio],\n        anchor: 'free',\n        position: 0,\n        _id: 'y',\n        _length: w\n    });\n    setConvert(aaxis, _this.graphDiv._fullLayout);\n    aaxis.setScale();\n\n    // baxis goes across the bottom (backward). We can set it up as an x axis\n    // without any enclosing transformation.\n    var baxis = _this.baxis = extendFlat({}, ternaryLayout.baxis, {\n        range: [sum - amin - cmin, bmin],\n        side: 'bottom',\n        domain: _this.xaxis.domain,\n        anchor: 'free',\n        position: 0,\n        _id: 'x',\n        _length: w\n    });\n    setConvert(baxis, _this.graphDiv._fullLayout);\n    baxis.setScale();\n\n    // caxis goes down the right side. Set it up as a y axis, with\n    // post-transformation similar to aaxis\n    var caxis = _this.caxis = extendFlat({}, ternaryLayout.caxis, {\n        range: [sum - amin - bmin, cmin],\n        side: 'right',\n        tickangle: (+ternaryLayout.caxis.tickangle || 0) + 30,\n        domain: [yDomain0, yDomain0 + yDomainFinal * whRatio],\n        anchor: 'free',\n        position: 0,\n        _id: 'y',\n        _length: w\n    });\n    setConvert(caxis, _this.graphDiv._fullLayout);\n    caxis.setScale();\n\n    var triangleClip = 'M' + x0 + ',' + (y0 + h) + 'h' + w + 'l-' + (w / 2) + ',-' + h + 'Z';\n    _this.clipDef.select('path').attr('d', triangleClip);\n    _this.layers.plotbg.select('path').attr('d', triangleClip);\n\n    var triangleClipRelative = 'M0,' + h + 'h' + w + 'l-' + (w / 2) + ',-' + h + 'Z';\n    _this.clipDefRelative.select('path').attr('d', triangleClipRelative);\n\n    var plotTransform = 'translate(' + x0 + ',' + y0 + ')';\n    _this.plotContainer.selectAll('.scatterlayer,.maplayer')\n        .attr('transform', plotTransform);\n\n    _this.clipDefRelative.select('path').attr('transform', null);\n\n    // TODO: shift axes to accommodate linewidth*sin(30) tick mark angle\n\n    // TODO: there's probably an easier way to handle these translations/offsets now...\n    var bTransform = 'translate(' + (x0 - baxis._offset) + ',' + (y0 + h) + ')';\n\n    _this.layers.baxis.attr('transform', bTransform);\n    _this.layers.bgrid.attr('transform', bTransform);\n\n    var aTransform = 'translate(' + (x0 + w / 2) + ',' + y0 +\n        ')rotate(30)translate(0,' + -aaxis._offset + ')';\n    _this.layers.aaxis.attr('transform', aTransform);\n    _this.layers.agrid.attr('transform', aTransform);\n\n    var cTransform = 'translate(' + (x0 + w / 2) + ',' + y0 +\n        ')rotate(-30)translate(0,' + -caxis._offset + ')';\n    _this.layers.caxis.attr('transform', cTransform);\n    _this.layers.cgrid.attr('transform', cTransform);\n\n    _this.drawAxes(true);\n\n    _this.layers.aline.select('path')\n        .attr('d', aaxis.showline ?\n            'M' + x0 + ',' + (y0 + h) + 'l' + (w / 2) + ',-' + h : 'M0,0')\n        .call(Color.stroke, aaxis.linecolor || '#000')\n        .style('stroke-width', (aaxis.linewidth || 0) + 'px');\n    _this.layers.bline.select('path')\n        .attr('d', baxis.showline ?\n            'M' + x0 + ',' + (y0 + h) + 'h' + w : 'M0,0')\n        .call(Color.stroke, baxis.linecolor || '#000')\n        .style('stroke-width', (baxis.linewidth || 0) + 'px');\n    _this.layers.cline.select('path')\n        .attr('d', caxis.showline ?\n            'M' + (x0 + w / 2) + ',' + y0 + 'l' + (w / 2) + ',' + h : 'M0,0')\n        .call(Color.stroke, caxis.linecolor || '#000')\n        .style('stroke-width', (caxis.linewidth || 0) + 'px');\n\n    if(!_this.graphDiv._context.staticPlot) {\n        _this.initInteractions();\n    }\n\n    Drawing.setClipUrl(\n        _this.layers.frontplot,\n        _this._hasClipOnAxisFalse ? null : _this.clipId,\n        _this.graphDiv\n    );\n};\n\nproto.drawAxes = function(doTitles) {\n    var _this = this;\n    var gd = _this.graphDiv;\n    var titlesuffix = _this.id.substr(7) + 'title';\n    var layers = _this.layers;\n    var aaxis = _this.aaxis;\n    var baxis = _this.baxis;\n    var caxis = _this.caxis;\n\n    _this.drawAx(aaxis);\n    _this.drawAx(baxis);\n    _this.drawAx(caxis);\n\n    if(doTitles) {\n        var apad = Math.max(aaxis.showticklabels ? aaxis.tickfont.size / 2 : 0,\n            (caxis.showticklabels ? caxis.tickfont.size * 0.75 : 0) +\n            (caxis.ticks === 'outside' ? caxis.ticklen * 0.87 : 0));\n        var bpad = (baxis.showticklabels ? baxis.tickfont.size : 0) +\n            (baxis.ticks === 'outside' ? baxis.ticklen : 0) + 3;\n\n        layers['a-title'] = Titles.draw(gd, 'a' + titlesuffix, {\n            propContainer: aaxis,\n            propName: _this.id + '.aaxis.title',\n            placeholder: _(gd, 'Click to enter Component A title'),\n            attributes: {\n                x: _this.x0 + _this.w / 2,\n                y: _this.y0 - aaxis.title.font.size / 3 - apad,\n                'text-anchor': 'middle'\n            }\n        });\n        layers['b-title'] = Titles.draw(gd, 'b' + titlesuffix, {\n            propContainer: baxis,\n            propName: _this.id + '.baxis.title',\n            placeholder: _(gd, 'Click to enter Component B title'),\n            attributes: {\n                x: _this.x0 - bpad,\n                y: _this.y0 + _this.h + baxis.title.font.size * 0.83 + bpad,\n                'text-anchor': 'middle'\n            }\n        });\n        layers['c-title'] = Titles.draw(gd, 'c' + titlesuffix, {\n            propContainer: caxis,\n            propName: _this.id + '.caxis.title',\n            placeholder: _(gd, 'Click to enter Component C title'),\n            attributes: {\n                x: _this.x0 + _this.w + bpad,\n                y: _this.y0 + _this.h + caxis.title.font.size * 0.83 + bpad,\n                'text-anchor': 'middle'\n            }\n        });\n    }\n};\n\nproto.drawAx = function(ax) {\n    var _this = this;\n    var gd = _this.graphDiv;\n    var axName = ax._name;\n    var axLetter = axName.charAt(0);\n    var axId = ax._id;\n    var axLayer = _this.layers[axName];\n    var counterAngle = 30;\n\n    var stashKey = axLetter + 'tickLayout';\n    var newTickLayout = strTickLayout(ax);\n    if(_this[stashKey] !== newTickLayout) {\n        axLayer.selectAll('.' + axId + 'tick').remove();\n        _this[stashKey] = newTickLayout;\n    }\n\n    ax.setScale();\n\n    var vals = Axes.calcTicks(ax);\n    var valsClipped = Axes.clipEnds(ax, vals);\n    var transFn = Axes.makeTransFn(ax);\n    var tickSign = Axes.getTickSigns(ax)[2];\n\n    var caRad = Lib.deg2rad(counterAngle);\n    var pad = tickSign * (ax.linewidth || 1) / 2;\n    var len = tickSign * ax.ticklen;\n    var w = _this.w;\n    var h = _this.h;\n\n    var tickPath = axLetter === 'b' ?\n        'M0,' + pad + 'l' + (Math.sin(caRad) * len) + ',' + (Math.cos(caRad) * len) :\n        'M' + pad + ',0l' + (Math.cos(caRad) * len) + ',' + (-Math.sin(caRad) * len);\n\n    var gridPath = {\n        a: 'M0,0l' + h + ',-' + (w / 2),\n        b: 'M0,0l-' + (w / 2) + ',-' + h,\n        c: 'M0,0l-' + h + ',' + (w / 2)\n    }[axLetter];\n\n    Axes.drawTicks(gd, ax, {\n        vals: ax.ticks === 'inside' ? valsClipped : vals,\n        layer: axLayer,\n        path: tickPath,\n        transFn: transFn,\n        crisp: false\n    });\n\n    Axes.drawGrid(gd, ax, {\n        vals: valsClipped,\n        layer: _this.layers[axLetter + 'grid'],\n        path: gridPath,\n        transFn: transFn,\n        crisp: false\n    });\n\n    Axes.drawLabels(gd, ax, {\n        vals: vals,\n        layer: axLayer,\n        transFn: transFn,\n        labelFns: Axes.makeLabelFns(ax, 0, counterAngle)\n    });\n};\n\nfunction strTickLayout(axLayout) {\n    return axLayout.ticks + String(axLayout.ticklen) + String(axLayout.showticklabels);\n}\n\n// hard coded paths for zoom corners\n// uses the same sizing as cartesian, length is MINZOOM/2, width is 3px\nvar CLEN = constants.MINZOOM / 2 + 0.87;\nvar BLPATH = 'm-0.87,.5h' + CLEN + 'v3h-' + (CLEN + 5.2) +\n    'l' + (CLEN / 2 + 2.6) + ',-' + (CLEN * 0.87 + 4.5) +\n    'l2.6,1.5l-' + (CLEN / 2) + ',' + (CLEN * 0.87) + 'Z';\nvar BRPATH = 'm0.87,.5h-' + CLEN + 'v3h' + (CLEN + 5.2) +\n    'l-' + (CLEN / 2 + 2.6) + ',-' + (CLEN * 0.87 + 4.5) +\n    'l-2.6,1.5l' + (CLEN / 2) + ',' + (CLEN * 0.87) + 'Z';\nvar TOPPATH = 'm0,1l' + (CLEN / 2) + ',' + (CLEN * 0.87) +\n    'l2.6,-1.5l-' + (CLEN / 2 + 2.6) + ',-' + (CLEN * 0.87 + 4.5) +\n    'l-' + (CLEN / 2 + 2.6) + ',' + (CLEN * 0.87 + 4.5) +\n    'l2.6,1.5l' + (CLEN / 2) + ',-' + (CLEN * 0.87) + 'Z';\nvar STARTMARKER = 'm0.5,0.5h5v-2h-5v-5h-2v5h-5v2h5v5h2Z';\n\n// I guess this could be shared with cartesian... but for now it's separate.\nvar SHOWZOOMOUTTIP = true;\n\nproto.initInteractions = function() {\n    var _this = this;\n    var dragger = _this.layers.plotbg.select('path').node();\n    var gd = _this.graphDiv;\n    var zoomLayer = gd._fullLayout._zoomlayer;\n\n    // use plotbg for the main interactions\n    var dragOptions = {\n        element: dragger,\n        gd: gd,\n        plotinfo: {\n            id: _this.id,\n            xaxis: _this.xaxis,\n            yaxis: _this.yaxis\n        },\n        subplot: _this.id,\n        prepFn: function(e, startX, startY) {\n            // these aren't available yet when initInteractions\n            // is called\n            dragOptions.xaxes = [_this.xaxis];\n            dragOptions.yaxes = [_this.yaxis];\n            var dragModeNow = gd._fullLayout.dragmode;\n\n            if(dragModeNow === 'lasso') dragOptions.minDrag = 1;\n            else dragOptions.minDrag = undefined;\n\n            if(dragModeNow === 'zoom') {\n                dragOptions.moveFn = zoomMove;\n                dragOptions.clickFn = clickZoomPan;\n                dragOptions.doneFn = zoomDone;\n                zoomPrep(e, startX, startY);\n            } else if(dragModeNow === 'pan') {\n                dragOptions.moveFn = plotDrag;\n                dragOptions.clickFn = clickZoomPan;\n                dragOptions.doneFn = dragDone;\n                panPrep();\n                clearSelect(gd);\n            } else if(dragModeNow === 'select' || dragModeNow === 'lasso') {\n                prepSelect(e, startX, startY, dragOptions, dragModeNow);\n            }\n        }\n    };\n\n    var x0, y0, mins0, span0, mins, lum, path0, dimmed, zb, corners;\n\n    function makeUpdate(_mins) {\n        var attrs = {};\n        attrs[_this.id + '.aaxis.min'] = _mins.a;\n        attrs[_this.id + '.baxis.min'] = _mins.b;\n        attrs[_this.id + '.caxis.min'] = _mins.c;\n        return attrs;\n    }\n\n    function clickZoomPan(numClicks, evt) {\n        var clickMode = gd._fullLayout.clickmode;\n\n        removeZoombox(gd);\n\n        if(numClicks === 2) {\n            gd.emit('plotly_doubleclick', null);\n            Registry.call('_guiRelayout', gd, makeUpdate({a: 0, b: 0, c: 0}));\n        }\n\n        if(clickMode.indexOf('select') > -1 && numClicks === 1) {\n            selectOnClick(evt, gd, [_this.xaxis], [_this.yaxis], _this.id, dragOptions);\n        }\n\n        if(clickMode.indexOf('event') > -1) {\n            Fx.click(gd, evt, _this.id);\n        }\n    }\n\n    function zoomPrep(e, startX, startY) {\n        var dragBBox = dragger.getBoundingClientRect();\n        x0 = startX - dragBBox.left;\n        y0 = startY - dragBBox.top;\n        mins0 = {\n            a: _this.aaxis.range[0],\n            b: _this.baxis.range[1],\n            c: _this.caxis.range[1]\n        };\n        mins = mins0;\n        span0 = _this.aaxis.range[1] - mins0.a;\n        lum = tinycolor(_this.graphDiv._fullLayout[_this.id].bgcolor).getLuminance();\n        path0 = 'M0,' + _this.h + 'L' + (_this.w / 2) + ', 0L' + _this.w + ',' + _this.h + 'Z';\n        dimmed = false;\n\n        zb = zoomLayer.append('path')\n            .attr('class', 'zoombox')\n            .attr('transform', 'translate(' + _this.x0 + ', ' + _this.y0 + ')')\n            .style({\n                'fill': lum > 0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)',\n                'stroke-width': 0\n            })\n            .attr('d', path0);\n\n        corners = zoomLayer.append('path')\n            .attr('class', 'zoombox-corners')\n            .attr('transform', 'translate(' + _this.x0 + ', ' + _this.y0 + ')')\n            .style({\n                fill: Color.background,\n                stroke: Color.defaultLine,\n                'stroke-width': 1,\n                opacity: 0\n            })\n            .attr('d', 'M0,0Z');\n\n        clearSelect(gd);\n    }\n\n    function getAFrac(x, y) { return 1 - (y / _this.h); }\n    function getBFrac(x, y) { return 1 - ((x + (_this.h - y) / Math.sqrt(3)) / _this.w); }\n    function getCFrac(x, y) { return ((x - (_this.h - y) / Math.sqrt(3)) / _this.w); }\n\n    function zoomMove(dx0, dy0) {\n        var x1 = x0 + dx0;\n        var y1 = y0 + dy0;\n        var afrac = Math.max(0, Math.min(1, getAFrac(x0, y0), getAFrac(x1, y1)));\n        var bfrac = Math.max(0, Math.min(1, getBFrac(x0, y0), getBFrac(x1, y1)));\n        var cfrac = Math.max(0, Math.min(1, getCFrac(x0, y0), getCFrac(x1, y1)));\n        var xLeft = ((afrac / 2) + cfrac) * _this.w;\n        var xRight = (1 - (afrac / 2) - bfrac) * _this.w;\n        var xCenter = (xLeft + xRight) / 2;\n        var xSpan = xRight - xLeft;\n        var yBottom = (1 - afrac) * _this.h;\n        var yTop = yBottom - xSpan / whRatio;\n\n        if(xSpan < constants.MINZOOM) {\n            mins = mins0;\n            zb.attr('d', path0);\n            corners.attr('d', 'M0,0Z');\n        } else {\n            mins = {\n                a: mins0.a + afrac * span0,\n                b: mins0.b + bfrac * span0,\n                c: mins0.c + cfrac * span0\n            };\n            zb.attr('d', path0 + 'M' + xLeft + ',' + yBottom +\n                'H' + xRight + 'L' + xCenter + ',' + yTop +\n                'L' + xLeft + ',' + yBottom + 'Z');\n            corners.attr('d', 'M' + x0 + ',' + y0 + STARTMARKER +\n                'M' + xLeft + ',' + yBottom + BLPATH +\n                'M' + xRight + ',' + yBottom + BRPATH +\n                'M' + xCenter + ',' + yTop + TOPPATH);\n        }\n\n        if(!dimmed) {\n            zb.transition()\n                .style('fill', lum > 0.2 ? 'rgba(0,0,0,0.4)' :\n                    'rgba(255,255,255,0.3)')\n                .duration(200);\n            corners.transition()\n                .style('opacity', 1)\n                .duration(200);\n            dimmed = true;\n        }\n\n        gd.emit('plotly_relayouting', makeUpdate(mins));\n    }\n\n    function zoomDone() {\n        removeZoombox(gd);\n\n        if(mins === mins0) return;\n\n        Registry.call('_guiRelayout', gd, makeUpdate(mins));\n\n        if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {\n            Lib.notifier(_(gd, 'Double-click to zoom back out'), 'long');\n            SHOWZOOMOUTTIP = false;\n        }\n    }\n\n    function panPrep() {\n        mins0 = {\n            a: _this.aaxis.range[0],\n            b: _this.baxis.range[1],\n            c: _this.caxis.range[1]\n        };\n        mins = mins0;\n    }\n\n    function plotDrag(dx, dy) {\n        var dxScaled = dx / _this.xaxis._m;\n        var dyScaled = dy / _this.yaxis._m;\n        mins = {\n            a: mins0.a - dyScaled,\n            b: mins0.b + (dxScaled + dyScaled) / 2,\n            c: mins0.c - (dxScaled - dyScaled) / 2\n        };\n        var minsorted = [mins.a, mins.b, mins.c].sort();\n        var minindices = {\n            a: minsorted.indexOf(mins.a),\n            b: minsorted.indexOf(mins.b),\n            c: minsorted.indexOf(mins.c)\n        };\n        if(minsorted[0] < 0) {\n            if(minsorted[1] + minsorted[0] / 2 < 0) {\n                minsorted[2] += minsorted[0] + minsorted[1];\n                minsorted[0] = minsorted[1] = 0;\n            } else {\n                minsorted[2] += minsorted[0] / 2;\n                minsorted[1] += minsorted[0] / 2;\n                minsorted[0] = 0;\n            }\n            mins = {\n                a: minsorted[minindices.a],\n                b: minsorted[minindices.b],\n                c: minsorted[minindices.c]\n            };\n            dy = (mins0.a - mins.a) * _this.yaxis._m;\n            dx = (mins0.c - mins.c - mins0.b + mins.b) * _this.xaxis._m;\n        }\n\n        // move the data (translate, don't redraw)\n        var plotTransform = 'translate(' + (_this.x0 + dx) + ',' + (_this.y0 + dy) + ')';\n        _this.plotContainer.selectAll('.scatterlayer,.maplayer')\n            .attr('transform', plotTransform);\n\n        var plotTransform2 = 'translate(' + -dx + ',' + -dy + ')';\n        _this.clipDefRelative.select('path').attr('transform', plotTransform2);\n\n        // move the ticks\n        _this.aaxis.range = [mins.a, _this.sum - mins.b - mins.c];\n        _this.baxis.range = [_this.sum - mins.a - mins.c, mins.b];\n        _this.caxis.range = [_this.sum - mins.a - mins.b, mins.c];\n\n        _this.drawAxes(false);\n\n        if(_this._hasClipOnAxisFalse) {\n            _this.plotContainer\n                .select('.scatterlayer').selectAll('.trace')\n                .call(Drawing.hideOutsideRangePoints, _this);\n        }\n\n        gd.emit('plotly_relayouting', makeUpdate(mins));\n    }\n\n    function dragDone() {\n        Registry.call('_guiRelayout', gd, makeUpdate(mins));\n    }\n\n    // finally, set up hover and click\n    // these event handlers must already be set before dragElement.init\n    // so it can stash them and override them.\n    dragger.onmousemove = function(evt) {\n        Fx.hover(gd, evt, _this.id);\n        gd._fullLayout._lasthover = dragger;\n        gd._fullLayout._hoversubplot = _this.id;\n    };\n\n    dragger.onmouseout = function(evt) {\n        if(gd._dragging) return;\n\n        dragElement.unhover(gd, evt);\n    };\n\n    dragElement.init(dragOptions);\n};\n\nfunction removeZoombox(gd) {\n    d3.select(gd)\n        .selectAll('.zoombox,.js-zoombox-backdrop,.js-zoombox-menu,.zoombox-corners')\n        .remove();\n}\n\n},{\"../../components/color\":593,\"../../components/dragelement\":611,\"../../components/drawing\":614,\"../../components/fx\":632,\"../../components/titles\":681,\"../../lib\":719,\"../../lib/extend\":710,\"../../registry\":847,\"../cartesian/axes\":767,\"../cartesian/constants\":773,\"../cartesian/select\":784,\"../cartesian/set_convert\":785,\"../plots\":828,\"d3\":163,\"tinycolor2\":537}],847:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Loggers = _dereq_('./lib/loggers');\nvar noop = _dereq_('./lib/noop');\nvar pushUnique = _dereq_('./lib/push_unique');\nvar isPlainObject = _dereq_('./lib/is_plain_object');\nvar addStyleRule = _dereq_('./lib/dom').addStyleRule;\nvar ExtendModule = _dereq_('./lib/extend');\n\nvar basePlotAttributes = _dereq_('./plots/attributes');\nvar baseLayoutAttributes = _dereq_('./plots/layout_attributes');\n\nvar extendFlat = ExtendModule.extendFlat;\nvar extendDeepAll = ExtendModule.extendDeepAll;\n\nexports.modules = {};\nexports.allCategories = {};\nexports.allTypes = [];\nexports.subplotsRegistry = {};\nexports.transformsRegistry = {};\nexports.componentsRegistry = {};\nexports.layoutArrayContainers = [];\nexports.layoutArrayRegexes = [];\nexports.traceLayoutAttributes = {};\nexports.localeRegistry = {};\nexports.apiMethodRegistry = {};\nexports.collectableSubplotTypes = null;\n\n/**\n * Top-level register routine, exported as Plotly.register\n *\n * @param {object array or array of objects} _modules :\n *  module object or list of module object to register.\n *\n *  A valid `moduleType: 'trace'` module has fields:\n *  - name {string} : the trace type\n *  - categories {array} : categories associated with this trace type,\n *                         tested with Register.traceIs()\n *  - meta {object} : meta info (mostly for plot-schema)\n *\n *  A valid `moduleType: 'locale'` module has fields:\n *  - name {string} : the locale name. Should be a 2-digit language string ('en', 'de')\n *                    optionally with a country/region code ('en-GB', 'de-CH'). If a country\n *                    code is used but the base language locale has not yet been supplied,\n *                    we will use this locale for the base as well.\n *  - dictionary {object} : the dictionary mapping input strings to localized strings\n *                          generally the keys should be the literal input strings, but\n *                          if default translations are provided you can use any string as a key.\n *  - format {object} : a `d3.locale` format specifier for this locale\n *                      any omitted keys we'll fall back on en-US.\n *\n *  A valid `moduleType: 'transform'` module has fields:\n *  - name {string} : transform name\n *  - transform {function} : default-level transform function\n *  - calcTransform {function} : calc-level transform function\n *  - attributes {object} : transform attributes declarations\n *  - supplyDefaults {function} : attributes default-supply function\n *\n *  A valid `moduleType: 'component'` module has fields:\n *  - name {string} : the component name, used it with Register.getComponentMethod()\n *                    to employ component method.\n *\n *  A valid `moduleType: 'apiMethod'` module has fields:\n *  - name {string} : the api method name.\n *  - fn {function} : the api method called with Register.call();\n *\n */\nexports.register = function register(_modules) {\n    exports.collectableSubplotTypes = null;\n\n    if(!_modules) {\n        throw new Error('No argument passed to Plotly.register.');\n    } else if(_modules && !Array.isArray(_modules)) {\n        _modules = [_modules];\n    }\n\n    for(var i = 0; i < _modules.length; i++) {\n        var newModule = _modules[i];\n\n        if(!newModule) {\n            throw new Error('Invalid module was attempted to be registered!');\n        }\n\n        switch(newModule.moduleType) {\n            case 'trace':\n                registerTraceModule(newModule);\n                break;\n            case 'transform':\n                registerTransformModule(newModule);\n                break;\n            case 'component':\n                registerComponentModule(newModule);\n                break;\n            case 'locale':\n                registerLocale(newModule);\n                break;\n            case 'apiMethod':\n                var name = newModule.name;\n                exports.apiMethodRegistry[name] = newModule.fn;\n                break;\n            default:\n                throw new Error('Invalid module was attempted to be registered!');\n        }\n    }\n};\n\n/**\n * Get registered module using trace object or trace type\n *\n * @param {object||string} trace\n *  trace object with prop 'type' or trace type as a string\n * @return {object}\n *  module object corresponding to trace type\n */\nexports.getModule = function(trace) {\n    var _module = exports.modules[getTraceType(trace)];\n    if(!_module) return false;\n    return _module._module;\n};\n\n/**\n * Determine if this trace type is in a given category\n *\n * @param {object||string} traceType\n *  a trace (object) or trace type (string)\n * @param {string} category\n *  category in question\n * @return {boolean}\n */\nexports.traceIs = function(traceType, category) {\n    traceType = getTraceType(traceType);\n\n    // old plot.ly workspace hack, nothing to see here\n    if(traceType === 'various') return false;\n\n    var _module = exports.modules[traceType];\n\n    if(!_module) {\n        if(traceType && traceType !== 'area') {\n            Loggers.log('Unrecognized trace type ' + traceType + '.');\n        }\n\n        _module = exports.modules[basePlotAttributes.type.dflt];\n    }\n\n    return !!_module.categories[category];\n};\n\n/**\n * Determine if this trace has a transform of the given type and return\n * array of matching indices.\n *\n * @param {object} data\n *  a trace object (member of data or fullData)\n * @param {string} type\n *  type of trace to test\n * @return {array}\n *  array of matching indices. If none found, returns []\n */\nexports.getTransformIndices = function(data, type) {\n    var indices = [];\n    var transforms = data.transforms || [];\n    for(var i = 0; i < transforms.length; i++) {\n        if(transforms[i].type === type) {\n            indices.push(i);\n        }\n    }\n    return indices;\n};\n\n/**\n * Determine if this trace has a transform of the given type\n *\n * @param {object} data\n *  a trace object (member of data or fullData)\n * @param {string} type\n *  type of trace to test\n * @return {boolean}\n */\nexports.hasTransform = function(data, type) {\n    var transforms = data.transforms || [];\n    for(var i = 0; i < transforms.length; i++) {\n        if(transforms[i].type === type) {\n            return true;\n        }\n    }\n    return false;\n};\n\n/**\n * Retrieve component module method. Falls back on noop if either the\n * module or the method is missing, so the result can always be safely called\n *\n * @param {string} name\n *  name of component (as declared in component module)\n * @param {string} method\n *  name of component module method\n * @return {function}\n */\nexports.getComponentMethod = function(name, method) {\n    var _module = exports.componentsRegistry[name];\n\n    if(!_module) return noop;\n    return _module[method] || noop;\n};\n\n/**\n * Call registered api method.\n *\n * @param {string} name : api method name\n * @param {...array} args : arguments passed to api method\n * @return {any} : returns api method output\n */\nexports.call = function() {\n    var name = arguments[0];\n    var args = [].slice.call(arguments, 1);\n    return exports.apiMethodRegistry[name].apply(null, args);\n};\n\nfunction registerTraceModule(_module) {\n    var thisType = _module.name;\n    var categoriesIn = _module.categories;\n    var meta = _module.meta;\n\n    if(exports.modules[thisType]) {\n        Loggers.log('Type ' + thisType + ' already registered');\n        return;\n    }\n\n    if(!exports.subplotsRegistry[_module.basePlotModule.name]) {\n        registerSubplot(_module.basePlotModule);\n    }\n\n    var categoryObj = {};\n    for(var i = 0; i < categoriesIn.length; i++) {\n        categoryObj[categoriesIn[i]] = true;\n        exports.allCategories[categoriesIn[i]] = true;\n    }\n\n    exports.modules[thisType] = {\n        _module: _module,\n        categories: categoryObj\n    };\n\n    if(meta && Object.keys(meta).length) {\n        exports.modules[thisType].meta = meta;\n    }\n\n    exports.allTypes.push(thisType);\n\n    for(var componentName in exports.componentsRegistry) {\n        mergeComponentAttrsToTrace(componentName, thisType);\n    }\n\n    /*\n     * Collect all trace layout attributes in one place for easier lookup later\n     * but don't merge them into the base schema as it would confuse the docs\n     * (at least after https://github.com/plotly/documentation/issues/202 gets done!)\n     */\n    if(_module.layoutAttributes) {\n        extendFlat(exports.traceLayoutAttributes, _module.layoutAttributes);\n    }\n\n    var basePlotModule = _module.basePlotModule;\n    var bpmName = basePlotModule.name;\n\n    // add mapbox-gl CSS here to avoid console warning on instantiation\n    if(bpmName === 'mapbox') {\n        var styleRules = basePlotModule.constants.styleRules;\n        for(var k in styleRules) {\n            addStyleRule('.js-plotly-plot .plotly .mapboxgl-' + k, styleRules[k]);\n        }\n    }\n\n    // if `plotly-geo-assets.js` is not included,\n    // add `PlotlyGeoAssets` global to stash references to all fetched\n    // topojson / geojson data\n    if((bpmName === 'geo' || bpmName === 'mapbox') &&\n        (typeof window !== undefined && window.PlotlyGeoAssets === undefined)\n    ) {\n        window.PlotlyGeoAssets = {topojson: {}};\n    }\n}\n\nfunction registerSubplot(_module) {\n    var plotType = _module.name;\n\n    if(exports.subplotsRegistry[plotType]) {\n        Loggers.log('Plot type ' + plotType + ' already registered.');\n        return;\n    }\n\n    // relayout array handling will look for component module methods with this\n    // name and won't find them because this is a subplot module... but that\n    // should be fine, it will just fall back on redrawing the plot.\n    findArrayRegexps(_module);\n\n    // not sure what's best for the 'cartesian' type at this point\n    exports.subplotsRegistry[plotType] = _module;\n\n    for(var componentName in exports.componentsRegistry) {\n        mergeComponentAttrsToSubplot(componentName, _module.name);\n    }\n}\n\nfunction registerComponentModule(_module) {\n    if(typeof _module.name !== 'string') {\n        throw new Error('Component module *name* must be a string.');\n    }\n\n    var name = _module.name;\n    exports.componentsRegistry[name] = _module;\n\n    if(_module.layoutAttributes) {\n        if(_module.layoutAttributes._isLinkedToArray) {\n            pushUnique(exports.layoutArrayContainers, name);\n        }\n        findArrayRegexps(_module);\n    }\n\n    for(var traceType in exports.modules) {\n        mergeComponentAttrsToTrace(name, traceType);\n    }\n\n    for(var subplotName in exports.subplotsRegistry) {\n        mergeComponentAttrsToSubplot(name, subplotName);\n    }\n\n    for(var transformType in exports.transformsRegistry) {\n        mergeComponentAttrsToTransform(name, transformType);\n    }\n\n    if(_module.schema && _module.schema.layout) {\n        extendDeepAll(baseLayoutAttributes, _module.schema.layout);\n    }\n}\n\nfunction registerTransformModule(_module) {\n    if(typeof _module.name !== 'string') {\n        throw new Error('Transform module *name* must be a string.');\n    }\n\n    var prefix = 'Transform module ' + _module.name;\n    var hasTransform = typeof _module.transform === 'function';\n    var hasCalcTransform = typeof _module.calcTransform === 'function';\n\n    if(!hasTransform && !hasCalcTransform) {\n        throw new Error(prefix + ' is missing a *transform* or *calcTransform* method.');\n    }\n    if(hasTransform && hasCalcTransform) {\n        Loggers.log([\n            prefix + ' has both a *transform* and *calcTransform* methods.',\n            'Please note that all *transform* methods are executed',\n            'before all *calcTransform* methods.'\n        ].join(' '));\n    }\n    if(!isPlainObject(_module.attributes)) {\n        Loggers.log(prefix + ' registered without an *attributes* object.');\n    }\n    if(typeof _module.supplyDefaults !== 'function') {\n        Loggers.log(prefix + ' registered without a *supplyDefaults* method.');\n    }\n\n    exports.transformsRegistry[_module.name] = _module;\n\n    for(var componentName in exports.componentsRegistry) {\n        mergeComponentAttrsToTransform(componentName, _module.name);\n    }\n}\n\nfunction registerLocale(_module) {\n    var locale = _module.name;\n    var baseLocale = locale.split('-')[0];\n\n    var newDict = _module.dictionary;\n    var newFormat = _module.format;\n    var hasDict = newDict && Object.keys(newDict).length;\n    var hasFormat = newFormat && Object.keys(newFormat).length;\n\n    var locales = exports.localeRegistry;\n\n    var localeObj = locales[locale];\n    if(!localeObj) locales[locale] = localeObj = {};\n\n    // Should we use this dict for the base locale?\n    // In case we're overwriting a previous dict for this locale, check\n    // whether the base matches the full locale dict now. If we're not\n    // overwriting, locales[locale] is undefined so this just checks if\n    // baseLocale already had a dict or not.\n    // Same logic for dateFormats\n    if(baseLocale !== locale) {\n        var baseLocaleObj = locales[baseLocale];\n        if(!baseLocaleObj) locales[baseLocale] = baseLocaleObj = {};\n\n        if(hasDict && baseLocaleObj.dictionary === localeObj.dictionary) {\n            baseLocaleObj.dictionary = newDict;\n        }\n        if(hasFormat && baseLocaleObj.format === localeObj.format) {\n            baseLocaleObj.format = newFormat;\n        }\n    }\n\n    if(hasDict) localeObj.dictionary = newDict;\n    if(hasFormat) localeObj.format = newFormat;\n}\n\nfunction findArrayRegexps(_module) {\n    if(_module.layoutAttributes) {\n        var arrayAttrRegexps = _module.layoutAttributes._arrayAttrRegexps;\n        if(arrayAttrRegexps) {\n            for(var i = 0; i < arrayAttrRegexps.length; i++) {\n                pushUnique(exports.layoutArrayRegexes, arrayAttrRegexps[i]);\n            }\n        }\n    }\n}\n\nfunction mergeComponentAttrsToTrace(componentName, traceType) {\n    var componentSchema = exports.componentsRegistry[componentName].schema;\n    if(!componentSchema || !componentSchema.traces) return;\n\n    var traceAttrs = componentSchema.traces[traceType];\n    if(traceAttrs) {\n        extendDeepAll(exports.modules[traceType]._module.attributes, traceAttrs);\n    }\n}\n\nfunction mergeComponentAttrsToTransform(componentName, transformType) {\n    var componentSchema = exports.componentsRegistry[componentName].schema;\n    if(!componentSchema || !componentSchema.transforms) return;\n\n    var transformAttrs = componentSchema.transforms[transformType];\n    if(transformAttrs) {\n        extendDeepAll(exports.transformsRegistry[transformType].attributes, transformAttrs);\n    }\n}\n\nfunction mergeComponentAttrsToSubplot(componentName, subplotName) {\n    var componentSchema = exports.componentsRegistry[componentName].schema;\n    if(!componentSchema || !componentSchema.subplots) return;\n\n    var subplotModule = exports.subplotsRegistry[subplotName];\n    var subplotAttrs = subplotModule.layoutAttributes;\n    var subplotAttr = subplotModule.attr === 'subplot' ? subplotModule.name : subplotModule.attr;\n    if(Array.isArray(subplotAttr)) subplotAttr = subplotAttr[0];\n\n    var componentLayoutAttrs = componentSchema.subplots[subplotAttr];\n    if(subplotAttrs && componentLayoutAttrs) {\n        extendDeepAll(subplotAttrs, componentLayoutAttrs);\n    }\n}\n\nfunction getTraceType(traceType) {\n    if(typeof traceType === 'object') traceType = traceType.type;\n    return traceType;\n}\n\n},{\"./lib/dom\":708,\"./lib/extend\":710,\"./lib/is_plain_object\":720,\"./lib/loggers\":723,\"./lib/noop\":728,\"./lib/push_unique\":733,\"./plots/attributes\":764,\"./plots/layout_attributes\":819}],848:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../registry');\nvar Lib = _dereq_('../lib');\n\nvar extendFlat = Lib.extendFlat;\nvar extendDeep = Lib.extendDeep;\n\n// Put default plotTile layouts here\nfunction cloneLayoutOverride(tileClass) {\n    var override;\n\n    switch(tileClass) {\n        case 'themes__thumb':\n            override = {\n                autosize: true,\n                width: 150,\n                height: 150,\n                title: {text: ''},\n                showlegend: false,\n                margin: {l: 5, r: 5, t: 5, b: 5, pad: 0},\n                annotations: []\n            };\n            break;\n\n        case 'thumbnail':\n            override = {\n                title: {text: ''},\n                hidesources: true,\n                showlegend: false,\n                borderwidth: 0,\n                bordercolor: '',\n                margin: {l: 1, r: 1, t: 1, b: 1, pad: 0},\n                annotations: []\n            };\n            break;\n\n        default:\n            override = {};\n    }\n\n\n    return override;\n}\n\nfunction keyIsAxis(keyName) {\n    var types = ['xaxis', 'yaxis', 'zaxis'];\n    return (types.indexOf(keyName.slice(0, 5)) > -1);\n}\n\n\nmodule.exports = function clonePlot(graphObj, options) {\n    // Polar plot compatibility\n    if(graphObj.framework && graphObj.framework.isPolar) {\n        graphObj = graphObj.framework.getConfig();\n    }\n\n    var i;\n    var oldData = graphObj.data;\n    var oldLayout = graphObj.layout;\n    var newData = extendDeep([], oldData);\n    var newLayout = extendDeep({}, oldLayout, cloneLayoutOverride(options.tileClass));\n    var context = graphObj._context || {};\n\n    if(options.width) newLayout.width = options.width;\n    if(options.height) newLayout.height = options.height;\n\n    if(options.tileClass === 'thumbnail' || options.tileClass === 'themes__thumb') {\n        // kill annotations\n        newLayout.annotations = [];\n        var keys = Object.keys(newLayout);\n\n        for(i = 0; i < keys.length; i++) {\n            if(keyIsAxis(keys[i])) {\n                newLayout[keys[i]].title = {text: ''};\n            }\n        }\n\n        // kill colorbar and pie labels\n        for(i = 0; i < newData.length; i++) {\n            var trace = newData[i];\n            trace.showscale = false;\n            if(trace.marker) trace.marker.showscale = false;\n            if(Registry.traceIs(trace, 'pie-like')) trace.textposition = 'none';\n        }\n    }\n\n    if(Array.isArray(options.annotations)) {\n        for(i = 0; i < options.annotations.length; i++) {\n            newLayout.annotations.push(options.annotations[i]);\n        }\n    }\n\n    // TODO: does this scene modification really belong here?\n    // If we still need it, can it move into the gl3d module?\n    var sceneIds = Object.keys(newLayout).filter(function(key) {\n        return key.match(/^scene\\d*$/);\n    });\n    if(sceneIds.length) {\n        var axesImageOverride = {};\n        if(options.tileClass === 'thumbnail') {\n            axesImageOverride = {\n                title: {text: ''},\n                showaxeslabels: false,\n                showticklabels: false,\n                linetickenable: false\n            };\n        }\n        for(i = 0; i < sceneIds.length; i++) {\n            var scene = newLayout[sceneIds[i]];\n\n            if(!scene.xaxis) {\n                scene.xaxis = {};\n            }\n\n            if(!scene.yaxis) {\n                scene.yaxis = {};\n            }\n\n            if(!scene.zaxis) {\n                scene.zaxis = {};\n            }\n\n            extendFlat(scene.xaxis, axesImageOverride);\n            extendFlat(scene.yaxis, axesImageOverride);\n            extendFlat(scene.zaxis, axesImageOverride);\n\n            // TODO what does this do?\n            scene._scene = null;\n        }\n    }\n\n    var gd = document.createElement('div');\n    if(options.tileClass) gd.className = options.tileClass;\n\n    var plotTile = {\n        gd: gd,\n        td: gd, // for external (image server) compatibility\n        layout: newLayout,\n        data: newData,\n        config: {\n            staticPlot: (options.staticPlot === undefined) ?\n                true :\n                options.staticPlot,\n            plotGlPixelRatio: (options.plotGlPixelRatio === undefined) ?\n                2 :\n                options.plotGlPixelRatio,\n            displaylogo: options.displaylogo || false,\n            showLink: options.showLink || false,\n            showTips: options.showTips || false,\n            mapboxAccessToken: context.mapboxAccessToken\n        }\n    };\n\n    if(options.setBackground !== 'transparent') {\n        plotTile.config.setBackground = options.setBackground || 'opaque';\n    }\n\n    // attaching the default Layout the gd, so you can grab it later\n    plotTile.gd.defaultLayout = cloneLayoutOverride(options.tileClass);\n\n    return plotTile;\n};\n\n},{\"../lib\":719,\"../registry\":847}],849:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\n\nvar toImage = _dereq_('../plot_api/to_image');\n\nvar fileSaver = _dereq_('./filesaver');\nvar helpers = _dereq_('./helpers');\n\n/**\n * Plotly.downloadImage\n *\n * @param {object | string | HTML div} gd\n *   can either be a data/layout/config object\n *   or an existing graph <div>\n *   or an id to an existing graph <div>\n * @param {object} opts (see Plotly.toImage in ../plot_api/to_image)\n * @return {promise}\n */\nfunction downloadImage(gd, opts) {\n    var _gd;\n    if(!Lib.isPlainObject(gd)) _gd = Lib.getGraphDiv(gd);\n\n    opts = opts || {};\n    opts.format = opts.format || 'png';\n    opts.imageDataOnly = true;\n\n    return new Promise(function(resolve, reject) {\n        if(_gd && _gd._snapshotInProgress) {\n            reject(new Error('Snapshotting already in progress.'));\n        }\n\n        // see comments within svgtoimg for additional\n        //   discussion of problems with IE\n        //   can now draw to canvas, but CORS tainted canvas\n        //   does not allow toDataURL\n        //   svg format will work though\n        if(Lib.isIE() && opts.format !== 'svg') {\n            reject(new Error(helpers.MSG_IE_BAD_FORMAT));\n        }\n\n        if(_gd) _gd._snapshotInProgress = true;\n        var promise = toImage(gd, opts);\n\n        var filename = opts.filename || gd.fn || 'newplot';\n        filename += '.' + opts.format;\n\n        promise.then(function(result) {\n            if(_gd) _gd._snapshotInProgress = false;\n            return fileSaver(result, filename, opts.format);\n        }).then(function(name) {\n            resolve(name);\n        }).catch(function(err) {\n            if(_gd) _gd._snapshotInProgress = false;\n            reject(err);\n        });\n    });\n}\n\nmodule.exports = downloadImage;\n\n},{\"../lib\":719,\"../plot_api/to_image\":760,\"./filesaver\":850,\"./helpers\":851}],850:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar helpers = _dereq_('./helpers');\n\n/*\n* substantial portions of this code from FileSaver.js\n* https://github.com/eligrey/FileSaver.js\n* License: https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md\n* FileSaver.js\n* A saveAs() FileSaver implementation.\n* 1.1.20160328\n*\n* By Eli Grey, http://eligrey.com\n* License: MIT\n*   See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md\n*/\nfunction fileSaver(url, name, format) {\n    var saveLink = document.createElement('a');\n    var canUseSaveLink = 'download' in saveLink;\n\n    var promise = new Promise(function(resolve, reject) {\n        var blob;\n        var objectUrl;\n\n        if(Lib.isIE9orBelow()) {\n            reject(new Error('IE < 10 unsupported'));\n        }\n\n        // Safari doesn't allow downloading of blob urls\n        if(Lib.isSafari()) {\n            var prefix = format === 'svg' ? ',' : ';base64,';\n            helpers.octetStream(prefix + encodeURIComponent(url));\n            return resolve(name);\n        }\n\n        // IE 10+ (native saveAs)\n        if(Lib.isIE()) {\n            // At this point we are only dealing with a decoded SVG as\n            // a data URL (since IE only supports SVG)\n            blob = helpers.createBlob(url, 'svg');\n            window.navigator.msSaveBlob(blob, name);\n            blob = null;\n            return resolve(name);\n        }\n\n        if(canUseSaveLink) {\n            blob = helpers.createBlob(url, format);\n            objectUrl = helpers.createObjectURL(blob);\n\n            saveLink.href = objectUrl;\n            saveLink.download = name;\n            document.body.appendChild(saveLink);\n            saveLink.click();\n\n            document.body.removeChild(saveLink);\n            helpers.revokeObjectURL(objectUrl);\n            blob = null;\n\n            return resolve(name);\n        }\n\n        reject(new Error('download error'));\n    });\n\n    return promise;\n}\n\n\nmodule.exports = fileSaver;\n\n},{\"../lib\":719,\"./helpers\":851}],851:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../registry');\n\nexports.getDelay = function(fullLayout) {\n    if(!fullLayout._has) return 0;\n\n    return (\n        fullLayout._has('gl3d') ||\n        fullLayout._has('gl2d') ||\n        fullLayout._has('mapbox')\n    ) ? 500 : 0;\n};\n\nexports.getRedrawFunc = function(gd) {\n    return function() {\n        var fullLayout = gd._fullLayout || {};\n        var hasPolar = fullLayout._has && fullLayout._has('polar');\n        var hasLegacyPolar = !hasPolar && gd.data && gd.data[0] && gd.data[0].r;\n\n        if(!hasLegacyPolar) {\n            Registry.getComponentMethod('colorbar', 'draw')(gd);\n        }\n    };\n};\n\nexports.encodeSVG = function(svg) {\n    return 'data:image/svg+xml,' + encodeURIComponent(svg);\n};\n\nvar DOM_URL = window.URL || window.webkitURL;\n\nexports.createObjectURL = function(blob) {\n    return DOM_URL.createObjectURL(blob);\n};\n\nexports.revokeObjectURL = function(url) {\n    return DOM_URL.revokeObjectURL(url);\n};\n\nexports.createBlob = function(url, format) {\n    if(format === 'svg') {\n        return new window.Blob([url], {type: 'image/svg+xml;charset=utf-8'});\n    } else {\n        var binary = fixBinary(window.atob(url));\n        return new window.Blob([binary], {type: 'image/' + format});\n    }\n};\n\nexports.octetStream = function(s) {\n    document.location.href = 'data:application/octet-stream' + s;\n};\n\n// Taken from https://bl.ocks.org/nolanlawson/0eac306e4dac2114c752\nfunction fixBinary(b) {\n    var len = b.length;\n    var buf = new ArrayBuffer(len);\n    var arr = new Uint8Array(buf);\n    for(var i = 0; i < len; i++) {\n        arr[i] = b.charCodeAt(i);\n    }\n    return buf;\n}\n\nexports.IMAGE_URL_PREFIX = /^data:image\\/\\w+;base64,/;\n\nexports.MSG_IE_BAD_FORMAT = 'Sorry IE does not support downloading from canvas. Try {format:\\'svg\\'} instead.';\n\n},{\"../registry\":847}],852:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar helpers = _dereq_('./helpers');\n\nvar Snapshot = {\n    getDelay: helpers.getDelay,\n    getRedrawFunc: helpers.getRedrawFunc,\n    clone: _dereq_('./cloneplot'),\n    toSVG: _dereq_('./tosvg'),\n    svgToImg: _dereq_('./svgtoimg'),\n    toImage: _dereq_('./toimage'),\n    downloadImage: _dereq_('./download')\n};\n\nmodule.exports = Snapshot;\n\n},{\"./cloneplot\":848,\"./download\":849,\"./helpers\":851,\"./svgtoimg\":853,\"./toimage\":854,\"./tosvg\":855}],853:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar EventEmitter = _dereq_('events').EventEmitter;\n\nvar helpers = _dereq_('./helpers');\n\nfunction svgToImg(opts) {\n    var ev = opts.emitter || new EventEmitter();\n\n    var promise = new Promise(function(resolve, reject) {\n        var Image = window.Image;\n        var svg = opts.svg;\n        var format = opts.format || 'png';\n\n        // IE only support svg\n        if(Lib.isIE() && format !== 'svg') {\n            var ieSvgError = new Error(helpers.MSG_IE_BAD_FORMAT);\n            reject(ieSvgError);\n            // eventually remove the ev\n            //  in favor of promises\n            if(!opts.promise) {\n                return ev.emit('error', ieSvgError);\n            } else {\n                return promise;\n            }\n        }\n\n        var canvas = opts.canvas;\n        var scale = opts.scale || 1;\n        var w0 = opts.width || 300;\n        var h0 = opts.height || 150;\n        var w1 = scale * w0;\n        var h1 = scale * h0;\n\n        var ctx = canvas.getContext('2d');\n        var img = new Image();\n        var svgBlob, url;\n\n        if(format === 'svg' || Lib.isIE9orBelow() || Lib.isSafari()) {\n            url = helpers.encodeSVG(svg);\n        } else {\n            svgBlob = helpers.createBlob(svg, 'svg');\n            url = helpers.createObjectURL(svgBlob);\n        }\n\n        canvas.width = w1;\n        canvas.height = h1;\n\n        img.onload = function() {\n            var imgData;\n\n            svgBlob = null;\n            helpers.revokeObjectURL(url);\n\n            // don't need to draw to canvas if svg\n            //  save some time and also avoid failure on IE\n            if(format !== 'svg') {\n                ctx.drawImage(img, 0, 0, w1, h1);\n            }\n\n            switch(format) {\n                case 'jpeg':\n                    imgData = canvas.toDataURL('image/jpeg');\n                    break;\n                case 'png':\n                    imgData = canvas.toDataURL('image/png');\n                    break;\n                case 'webp':\n                    imgData = canvas.toDataURL('image/webp');\n                    break;\n                case 'svg':\n                    imgData = url;\n                    break;\n                default:\n                    var errorMsg = 'Image format is not jpeg, png, svg or webp.';\n                    reject(new Error(errorMsg));\n                    // eventually remove the ev\n                    //  in favor of promises\n                    if(!opts.promise) {\n                        return ev.emit('error', errorMsg);\n                    }\n            }\n            resolve(imgData);\n            // eventually remove the ev\n            //  in favor of promises\n            if(!opts.promise) {\n                ev.emit('success', imgData);\n            }\n        };\n\n        img.onerror = function(err) {\n            svgBlob = null;\n            helpers.revokeObjectURL(url);\n\n            reject(err);\n            // eventually remove the ev\n            //  in favor of promises\n            if(!opts.promise) {\n                return ev.emit('error', err);\n            }\n        };\n\n        img.src = url;\n    });\n\n    // temporary for backward compatibility\n    //  move to only Promise in 2.0.0\n    //  and eliminate the EventEmitter\n    if(opts.promise) {\n        return promise;\n    }\n\n    return ev;\n}\n\nmodule.exports = svgToImg;\n\n},{\"../lib\":719,\"./helpers\":851,\"events\":104}],854:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar EventEmitter = _dereq_('events').EventEmitter;\n\nvar Registry = _dereq_('../registry');\nvar Lib = _dereq_('../lib');\n\nvar helpers = _dereq_('./helpers');\nvar clonePlot = _dereq_('./cloneplot');\nvar toSVG = _dereq_('./tosvg');\nvar svgToImg = _dereq_('./svgtoimg');\n\n/**\n * @param {object} gd figure Object\n * @param {object} opts option object\n * @param opts.format 'jpeg' | 'png' | 'webp' | 'svg'\n */\nfunction toImage(gd, opts) {\n    // first clone the GD so we can operate in a clean environment\n    var ev = new EventEmitter();\n\n    var clone = clonePlot(gd, {format: 'png'});\n    var clonedGd = clone.gd;\n\n    // put the cloned div somewhere off screen before attaching to DOM\n    clonedGd.style.position = 'absolute';\n    clonedGd.style.left = '-5000px';\n    document.body.appendChild(clonedGd);\n\n    function wait() {\n        var delay = helpers.getDelay(clonedGd._fullLayout);\n\n        setTimeout(function() {\n            var svg = toSVG(clonedGd);\n\n            var canvas = document.createElement('canvas');\n            canvas.id = Lib.randstr();\n\n            ev = svgToImg({\n                format: opts.format,\n                width: clonedGd._fullLayout.width,\n                height: clonedGd._fullLayout.height,\n                canvas: canvas,\n                emitter: ev,\n                svg: svg\n            });\n\n            ev.clean = function() {\n                if(clonedGd) document.body.removeChild(clonedGd);\n            };\n        }, delay);\n    }\n\n    var redrawFunc = helpers.getRedrawFunc(clonedGd);\n\n    Registry.call('plot', clonedGd, clone.data, clone.layout, clone.config)\n        .then(redrawFunc)\n        .then(wait)\n        .catch(function(err) {\n            ev.emit('error', err);\n        });\n\n\n    return ev;\n}\n\nmodule.exports = toImage;\n\n},{\"../lib\":719,\"../registry\":847,\"./cloneplot\":848,\"./helpers\":851,\"./svgtoimg\":853,\"./tosvg\":855,\"events\":104}],855:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../lib');\nvar Drawing = _dereq_('../components/drawing');\nvar Color = _dereq_('../components/color');\n\nvar xmlnsNamespaces = _dereq_('../constants/xmlns_namespaces');\nvar DOUBLEQUOTE_REGEX = /\"/g;\nvar DUMMY_SUB = 'TOBESTRIPPED';\nvar DUMMY_REGEX = new RegExp('(\"' + DUMMY_SUB + ')|(' + DUMMY_SUB + '\")', 'g');\n\nfunction htmlEntityDecode(s) {\n    var hiddenDiv = d3.select('body').append('div').style({display: 'none'}).html('');\n    var replaced = s.replace(/(&[^;]*;)/gi, function(d) {\n        if(d === '&lt;') { return '&#60;'; } // special handling for brackets\n        if(d === '&rt;') { return '&#62;'; }\n        if(d.indexOf('<') !== -1 || d.indexOf('>') !== -1) { return ''; }\n        return hiddenDiv.html(d).text(); // everything else, let the browser decode it to unicode\n    });\n    hiddenDiv.remove();\n    return replaced;\n}\n\nfunction xmlEntityEncode(str) {\n    return str.replace(/&(?!\\w+;|\\#[0-9]+;| \\#x[0-9A-F]+;)/g, '&amp;');\n}\n\nmodule.exports = function toSVG(gd, format, scale) {\n    var fullLayout = gd._fullLayout;\n    var svg = fullLayout._paper;\n    var toppaper = fullLayout._toppaper;\n    var width = fullLayout.width;\n    var height = fullLayout.height;\n    var i;\n\n    // make background color a rect in the svg, then revert after scraping\n    // all other alterations have been dealt with by properly preparing the svg\n    // in the first place... like setting cursors with css classes so we don't\n    // have to remove them, and providing the right namespaces in the svg to\n    // begin with\n    svg.insert('rect', ':first-child')\n        .call(Drawing.setRect, 0, 0, width, height)\n        .call(Color.fill, fullLayout.paper_bgcolor);\n\n    // subplot-specific to-SVG methods\n    // which notably add the contents of the gl-container\n    // into the main svg node\n    var basePlotModules = fullLayout._basePlotModules || [];\n    for(i = 0; i < basePlotModules.length; i++) {\n        var _module = basePlotModules[i];\n\n        if(_module.toSVG) _module.toSVG(gd);\n    }\n\n    // add top items above them assumes everything in toppaper is either\n    // a group or a defs, and if it's empty (like hoverlayer) we can ignore it.\n    if(toppaper) {\n        var nodes = toppaper.node().childNodes;\n\n        // make copy of nodes as childNodes prop gets mutated in loop below\n        var topGroups = Array.prototype.slice.call(nodes);\n\n        for(i = 0; i < topGroups.length; i++) {\n            var topGroup = topGroups[i];\n\n            if(topGroup.childNodes.length) svg.node().appendChild(topGroup);\n        }\n    }\n\n    // remove draglayer for Adobe Illustrator compatibility\n    if(fullLayout._draggers) {\n        fullLayout._draggers.remove();\n    }\n\n    // in case the svg element had an explicit background color, remove this\n    // we want the rect to get the color so it's the right size; svg bg will\n    // fill whatever container it's displayed in regardless of plot size.\n    svg.node().style.background = '';\n\n    svg.selectAll('text')\n        .attr({'data-unformatted': null, 'data-math': null})\n        .each(function() {\n            var txt = d3.select(this);\n\n            // hidden text is pre-formatting mathjax, the browser ignores it\n            // but in a static plot it's useless and it can confuse batik\n            // we've tried to standardize on display:none but make sure we still\n            // catch visibility:hidden if it ever arises\n            if(this.style.visibility === 'hidden' || this.style.display === 'none') {\n                txt.remove();\n                return;\n            } else {\n                // clear other visibility/display values to default\n                // to not potentially confuse non-browser SVG implementations\n                txt.style({visibility: null, display: null});\n            }\n\n            // Font family styles break things because of quotation marks,\n            // so we must remove them *after* the SVG DOM has been serialized\n            // to a string (browsers convert singles back)\n            var ff = this.style.fontFamily;\n            if(ff && ff.indexOf('\"') !== -1) {\n                txt.style('font-family', ff.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));\n            }\n        });\n\n    svg.selectAll('.point, .scatterpts, .legendfill>path, .legendlines>path, .cbfill').each(function() {\n        var pt = d3.select(this);\n\n        // similar to font family styles above,\n        // we must remove \" after the SVG DOM has been serialized\n        var fill = this.style.fill;\n        if(fill && fill.indexOf('url(') !== -1) {\n            pt.style('fill', fill.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));\n        }\n\n        var stroke = this.style.stroke;\n        if(stroke && stroke.indexOf('url(') !== -1) {\n            pt.style('stroke', stroke.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));\n        }\n    });\n\n    if(format === 'pdf' || format === 'eps') {\n        // these formats make the extra line MathJax adds around symbols look super thick in some cases\n        // it looks better if this is removed entirely.\n        svg.selectAll('#MathJax_SVG_glyphs path')\n            .attr('stroke-width', 0);\n    }\n\n    // fix for IE namespacing quirk?\n    // http://stackoverflow.com/questions/19610089/unwanted-namespaces-on-svg-markup-when-using-xmlserializer-in-javascript-with-ie\n    svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns', xmlnsNamespaces.svg);\n    svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns:xlink', xmlnsNamespaces.xlink);\n\n    if(format === 'svg' && scale) {\n        svg.attr('width', scale * width);\n        svg.attr('height', scale * height);\n        svg.attr('viewBox', '0 0 ' + width + ' ' + height);\n    }\n\n    var s = new window.XMLSerializer().serializeToString(svg.node());\n    s = htmlEntityDecode(s);\n    s = xmlEntityEncode(s);\n\n    // Fix quotations around font strings and gradient URLs\n    s = s.replace(DUMMY_REGEX, '\\'');\n\n    // IE is very strict, so we will need to clean\n    //  svg with the following regex\n    //  yes this is messy, but do not know a better way\n    // Even with this IE will not work due to tainted canvas\n    //  see https://github.com/kangax/fabric.js/issues/1957\n    //      http://stackoverflow.com/questions/18112047/canvas-todataurl-working-in-all-browsers-except-ie10\n    // Leave here just in case the CORS/tainted IE issue gets resolved\n    if(Lib.isIE()) {\n        // replace double quote with single quote\n        s = s.replace(/\"/gi, '\\'');\n        // url in svg are single quoted\n        //   since we changed double to single\n        //   we'll need to change these to double-quoted\n        s = s.replace(/(\\('#)([^']*)('\\))/gi, '(\\\"#$2\\\")');\n        // font names with spaces will be escaped single-quoted\n        //   we'll need to change these to double-quoted\n        s = s.replace(/(\\\\')/gi, '\\\"');\n    }\n\n    return s;\n};\n\n},{\"../components/color\":593,\"../components/drawing\":614,\"../constants/xmlns_namespaces\":696,\"../lib\":719,\"d3\":163}],856:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n// arrayOk attributes, merge them into calcdata array\nmodule.exports = function arraysToCalcdata(cd, trace) {\n    for(var i = 0; i < cd.length; i++) cd[i].i = i;\n\n    Lib.mergeArray(trace.text, cd, 'tx');\n    Lib.mergeArray(trace.hovertext, cd, 'htx');\n\n    var marker = trace.marker;\n    if(marker) {\n        Lib.mergeArray(marker.opacity, cd, 'mo', true);\n        Lib.mergeArray(marker.color, cd, 'mc');\n\n        var markerLine = marker.line;\n        if(markerLine) {\n            Lib.mergeArray(markerLine.color, cd, 'mlc');\n            Lib.mergeArrayCastPositive(markerLine.width, cd, 'mlw');\n        }\n    }\n};\n\n},{\"../../lib\":719}],857:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar constants = _dereq_('./constants.js');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar textFontAttrs = fontAttrs({\n    editType: 'calc',\n    arrayOk: true,\n    colorEditType: 'style',\n    \n});\n\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar scatterMarkerLineAttrs = scatterMarkerAttrs.line;\n\nvar markerLineWidth = extendFlat({},\n    scatterMarkerLineAttrs.width, { dflt: 0 });\n\nvar markerLine = extendFlat({\n    width: markerLineWidth,\n    editType: 'calc'\n}, colorScaleAttrs('marker.line'));\n\nvar marker = extendFlat({\n    line: markerLine,\n    editType: 'calc'\n}, colorScaleAttrs('marker'), {\n    opacity: {\n        valType: 'number',\n        arrayOk: true,\n        dflt: 1,\n        min: 0,\n        max: 1,\n        \n        editType: 'style',\n        \n    }\n});\n\nmodule.exports = {\n    x: scatterAttrs.x,\n    x0: scatterAttrs.x0,\n    dx: scatterAttrs.dx,\n    y: scatterAttrs.y,\n    y0: scatterAttrs.y0,\n    dy: scatterAttrs.dy,\n\n    text: scatterAttrs.text,\n    hovertext: scatterAttrs.hovertext,\n    hovertemplate: hovertemplateAttrs({}, {\n        keys: constants.eventDataKeys\n    }),\n\n    textposition: {\n        valType: 'enumerated',\n        \n        values: ['inside', 'outside', 'auto', 'none'],\n        dflt: 'none',\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n\n    insidetextanchor: {\n        valType: 'enumerated',\n        values: ['end', 'middle', 'start'],\n        dflt: 'end',\n        \n        editType: 'plot',\n        \n    },\n\n    textangle: {\n        valType: 'angle',\n        dflt: 'auto',\n        \n        editType: 'plot',\n        \n    },\n\n    textfont: extendFlat({}, textFontAttrs, {\n        \n    }),\n\n    insidetextfont: extendFlat({}, textFontAttrs, {\n        \n    }),\n\n    outsidetextfont: extendFlat({}, textFontAttrs, {\n        \n    }),\n\n    constraintext: {\n        valType: 'enumerated',\n        values: ['inside', 'outside', 'both', 'none'],\n        \n        dflt: 'both',\n        editType: 'calc',\n        \n    },\n\n    cliponaxis: extendFlat({}, scatterAttrs.cliponaxis, {\n        \n    }),\n\n    orientation: {\n        valType: 'enumerated',\n        \n        values: ['v', 'h'],\n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    base: {\n        valType: 'any',\n        dflt: null,\n        arrayOk: true,\n        \n        editType: 'calc',\n        \n    },\n\n    offset: {\n        valType: 'number',\n        dflt: null,\n        arrayOk: true,\n        \n        editType: 'calc',\n        \n    },\n\n    width: {\n        valType: 'number',\n        dflt: null,\n        min: 0,\n        arrayOk: true,\n        \n        editType: 'calc',\n        \n    },\n\n    marker: marker,\n\n    offsetgroup: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'calc',\n        \n    },\n    alignmentgroup: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'calc',\n        \n    },\n\n    selected: {\n        marker: {\n            opacity: scatterAttrs.selected.marker.opacity,\n            color: scatterAttrs.selected.marker.color,\n            editType: 'style'\n        },\n        textfont: scatterAttrs.selected.textfont,\n        editType: 'style'\n    },\n    unselected: {\n        marker: {\n            opacity: scatterAttrs.unselected.marker.opacity,\n            color: scatterAttrs.unselected.marker.color,\n            editType: 'style'\n        },\n        textfont: scatterAttrs.unselected.textfont,\n        editType: 'style'\n    },\n\n    r: scatterAttrs.r,\n    t: scatterAttrs.t,\n\n    _deprecated: {\n        bardir: {\n            valType: 'enumerated',\n            \n            editType: 'calc',\n            values: ['v', 'h'],\n            \n        }\n    }\n};\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/font_attributes\":793,\"../scatter/attributes\":1112,\"./constants.js\":859}],858:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\nvar arraysToCalcdata = _dereq_('./arrays_to_calcdata');\nvar calcSelection = _dereq_('../scatter/calc_selection');\n\nmodule.exports = function calc(gd, trace) {\n    var xa = Axes.getFromId(gd, trace.xaxis || 'x');\n    var ya = Axes.getFromId(gd, trace.yaxis || 'y');\n    var size, pos;\n\n    if(trace.orientation === 'h') {\n        size = xa.makeCalcdata(trace, 'x');\n        pos = ya.makeCalcdata(trace, 'y');\n    } else {\n        size = ya.makeCalcdata(trace, 'y');\n        pos = xa.makeCalcdata(trace, 'x');\n    }\n\n    // create the \"calculated data\" to plot\n    var serieslen = Math.min(pos.length, size.length);\n    var cd = new Array(serieslen);\n\n    // set position and size\n    for(var i = 0; i < serieslen; i++) {\n        cd[i] = { p: pos[i], s: size[i] };\n\n        if(trace.ids) {\n            cd[i].id = String(trace.ids[i]);\n        }\n    }\n\n    // auto-z and autocolorscale if applicable\n    if(hasColorscale(trace, 'marker')) {\n        colorscaleCalc(gd, trace, {\n            vals: trace.marker.color,\n            containerStr: 'marker',\n            cLetter: 'c'\n        });\n    }\n    if(hasColorscale(trace, 'marker.line')) {\n        colorscaleCalc(gd, trace, {\n            vals: trace.marker.line.color,\n            containerStr: 'marker.line',\n            cLetter: 'c'\n        });\n    }\n\n    arraysToCalcdata(cd, trace);\n    calcSelection(cd, trace);\n\n    return cd;\n};\n\n},{\"../../components/colorscale/calc\":601,\"../../components/colorscale/helpers\":604,\"../../plots/cartesian/axes\":767,\"../scatter/calc_selection\":1114,\"./arrays_to_calcdata\":856}],859:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = {\n    eventDataKeys: []\n};\n\n},{}],860:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nvar Registry = _dereq_('../../registry');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar getAxisGroup = _dereq_('../../plots/cartesian/axis_ids').getAxisGroup;\nvar Sieve = _dereq_('./sieve.js');\n\n/*\n * Bar chart stacking/grouping positioning and autoscaling calculations\n * for each direction separately calculate the ranges and positions\n * note that this handles histograms too\n * now doing this one subplot at a time\n */\n\nfunction crossTraceCalc(gd, plotinfo) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    var fullLayout = gd._fullLayout;\n    var fullTraces = gd._fullData;\n    var calcTraces = gd.calcdata;\n    var calcTracesHorz = [];\n    var calcTracesVert = [];\n\n    for(var i = 0; i < fullTraces.length; i++) {\n        var fullTrace = fullTraces[i];\n        if(\n            fullTrace.visible === true &&\n            Registry.traceIs(fullTrace, 'bar') &&\n            fullTrace.xaxis === xa._id &&\n            fullTrace.yaxis === ya._id\n        ) {\n            if(fullTrace.orientation === 'h') {\n                calcTracesHorz.push(calcTraces[i]);\n            } else {\n                calcTracesVert.push(calcTraces[i]);\n            }\n        }\n    }\n\n    var opts = {\n        mode: fullLayout.barmode,\n        norm: fullLayout.barnorm,\n        gap: fullLayout.bargap,\n        groupgap: fullLayout.bargroupgap\n    };\n\n    setGroupPositions(gd, xa, ya, calcTracesVert, opts);\n    setGroupPositions(gd, ya, xa, calcTracesHorz, opts);\n}\n\nfunction setGroupPositions(gd, pa, sa, calcTraces, opts) {\n    if(!calcTraces.length) return;\n\n    var excluded;\n    var included;\n    var i, calcTrace, fullTrace;\n\n    initBase(sa, calcTraces);\n\n    switch(opts.mode) {\n        case 'overlay':\n            setGroupPositionsInOverlayMode(pa, sa, calcTraces, opts);\n            break;\n\n        case 'group':\n            // exclude from the group those traces for which the user set an offset\n            excluded = [];\n            included = [];\n            for(i = 0; i < calcTraces.length; i++) {\n                calcTrace = calcTraces[i];\n                fullTrace = calcTrace[0].trace;\n\n                if(fullTrace.offset === undefined) included.push(calcTrace);\n                else excluded.push(calcTrace);\n            }\n\n            if(included.length) {\n                setGroupPositionsInGroupMode(gd, pa, sa, included, opts);\n            }\n            if(excluded.length) {\n                setGroupPositionsInOverlayMode(pa, sa, excluded, opts);\n            }\n            break;\n\n        case 'stack':\n        case 'relative':\n            // exclude from the stack those traces for which the user set a base\n            excluded = [];\n            included = [];\n            for(i = 0; i < calcTraces.length; i++) {\n                calcTrace = calcTraces[i];\n                fullTrace = calcTrace[0].trace;\n\n                if(fullTrace.base === undefined) included.push(calcTrace);\n                else excluded.push(calcTrace);\n            }\n\n            if(included.length) {\n                setGroupPositionsInStackOrRelativeMode(gd, pa, sa, included, opts);\n            }\n            if(excluded.length) {\n                setGroupPositionsInOverlayMode(pa, sa, excluded, opts);\n            }\n            break;\n    }\n\n    collectExtents(calcTraces, pa);\n}\n\nfunction initBase(sa, calcTraces) {\n    var i, j;\n\n    for(i = 0; i < calcTraces.length; i++) {\n        var cd = calcTraces[i];\n        var trace = cd[0].trace;\n        var base = (trace.type === 'funnel') ? trace._base : trace.base;\n        var b;\n\n        // not sure if it really makes sense to have dates for bar size data...\n        // ideally if we want to make gantt charts or something we'd treat\n        // the actual size (trace.x or y) as time delta but base as absolute\n        // time. But included here for completeness.\n        var scalendar = trace.orientation === 'h' ? trace.xcalendar : trace.ycalendar;\n\n        // 'base' on categorical axes makes no sense\n        var d2c = sa.type === 'category' || sa.type === 'multicategory' ?\n            function() { return null; } :\n            sa.d2c;\n\n        if(isArrayOrTypedArray(base)) {\n            for(j = 0; j < Math.min(base.length, cd.length); j++) {\n                b = d2c(base[j], 0, scalendar);\n                if(isNumeric(b)) {\n                    cd[j].b = +b;\n                    cd[j].hasB = 1;\n                } else cd[j].b = 0;\n            }\n            for(; j < cd.length; j++) {\n                cd[j].b = 0;\n            }\n        } else {\n            b = d2c(base, 0, scalendar);\n            var hasBase = isNumeric(b);\n            b = hasBase ? b : 0;\n            for(j = 0; j < cd.length; j++) {\n                cd[j].b = b;\n                if(hasBase) cd[j].hasB = 1;\n            }\n        }\n    }\n}\n\nfunction setGroupPositionsInOverlayMode(pa, sa, calcTraces, opts) {\n    // update position axis and set bar offsets and widths\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n\n        var sieve = new Sieve([calcTrace], {\n            sepNegVal: false,\n            overlapNoMerge: !opts.norm\n        });\n\n        // set bar offsets and widths, and update position axis\n        setOffsetAndWidth(pa, sieve, opts);\n\n        // set bar bases and sizes, and update size axis\n        //\n        // (note that `setGroupPositionsInOverlayMode` handles the case barnorm\n        // is defined, because this function is also invoked for traces that\n        // can't be grouped or stacked)\n        if(opts.norm) {\n            sieveBars(sieve);\n            normalizeBars(sa, sieve, opts);\n        } else {\n            setBaseAndTop(sa, sieve);\n        }\n    }\n}\n\nfunction setGroupPositionsInGroupMode(gd, pa, sa, calcTraces, opts) {\n    var sieve = new Sieve(calcTraces, {\n        sepNegVal: false,\n        overlapNoMerge: !opts.norm\n    });\n\n    // set bar offsets and widths, and update position axis\n    setOffsetAndWidthInGroupMode(gd, pa, sieve, opts);\n\n    // relative-stack bars within the same trace that would otherwise\n    // be hidden\n    unhideBarsWithinTrace(sieve);\n\n    // set bar bases and sizes, and update size axis\n    if(opts.norm) {\n        sieveBars(sieve);\n        normalizeBars(sa, sieve, opts);\n    } else {\n        setBaseAndTop(sa, sieve);\n    }\n}\n\nfunction setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces, opts) {\n    var sieve = new Sieve(calcTraces, {\n        sepNegVal: opts.mode === 'relative',\n        overlapNoMerge: !(opts.norm || opts.mode === 'stack' || opts.mode === 'relative')\n    });\n\n    // set bar offsets and widths, and update position axis\n    setOffsetAndWidth(pa, sieve, opts);\n\n    // set bar bases and sizes, and update size axis\n    stackBars(sa, sieve, opts);\n\n    // flag the outmost bar (for text display purposes)\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n\n        for(var j = 0; j < calcTrace.length; j++) {\n            var bar = calcTrace[j];\n\n            if(bar.s !== BADNUM) {\n                var isOutmostBar = ((bar.b + bar.s) === sieve.get(bar.p, bar.s));\n                if(isOutmostBar) bar._outmost = true;\n            }\n        }\n    }\n\n    // Note that marking the outmost bars has to be done\n    // before `normalizeBars` changes `bar.b` and `bar.s`.\n    if(opts.norm) normalizeBars(sa, sieve, opts);\n}\n\nfunction setOffsetAndWidth(pa, sieve, opts) {\n    var minDiff = sieve.minDiff;\n    var calcTraces = sieve.traces;\n\n    // set bar offsets and widths\n    var barGroupWidth = minDiff * (1 - opts.gap);\n    var barWidthPlusGap = barGroupWidth;\n    var barWidth = barWidthPlusGap * (1 - (opts.groupgap || 0));\n\n    // computer bar group center and bar offset\n    var offsetFromCenter = -barWidth / 2;\n\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n        var t = calcTrace[0].t;\n\n        // store bar width and offset for this trace\n        t.barwidth = barWidth;\n        t.poffset = offsetFromCenter;\n        t.bargroupwidth = barGroupWidth;\n        t.bardelta = minDiff;\n    }\n\n    // stack bars that only differ by rounding\n    sieve.binWidth = calcTraces[0][0].t.barwidth / 100;\n\n    // if defined, apply trace offset and width\n    applyAttributes(sieve);\n\n    // store the bar center in each calcdata item\n    setBarCenterAndWidth(pa, sieve);\n\n    // update position axes\n    updatePositionAxis(pa, sieve);\n}\n\nfunction setOffsetAndWidthInGroupMode(gd, pa, sieve, opts) {\n    var fullLayout = gd._fullLayout;\n    var positions = sieve.positions;\n    var distinctPositions = sieve.distinctPositions;\n    var minDiff = sieve.minDiff;\n    var calcTraces = sieve.traces;\n    var nTraces = calcTraces.length;\n\n    // if there aren't any overlapping positions,\n    // let them have full width even if mode is group\n    var overlap = (positions.length !== distinctPositions.length);\n    var barGroupWidth = minDiff * (1 - opts.gap);\n\n    var groupId = getAxisGroup(fullLayout, pa._id) + calcTraces[0][0].trace.orientation;\n    var alignmentGroups = fullLayout._alignmentOpts[groupId] || {};\n\n    for(var i = 0; i < nTraces; i++) {\n        var calcTrace = calcTraces[i];\n        var trace = calcTrace[0].trace;\n\n        var alignmentGroupOpts = alignmentGroups[trace.alignmentgroup] || {};\n        var nOffsetGroups = Object.keys(alignmentGroupOpts.offsetGroups || {}).length;\n\n        var barWidthPlusGap;\n        if(nOffsetGroups) {\n            barWidthPlusGap = barGroupWidth / nOffsetGroups;\n        } else {\n            barWidthPlusGap = overlap ? barGroupWidth / nTraces : barGroupWidth;\n        }\n\n        var barWidth = barWidthPlusGap * (1 - (opts.groupgap || 0));\n\n        var offsetFromCenter;\n        if(nOffsetGroups) {\n            offsetFromCenter = ((2 * trace._offsetIndex + 1 - nOffsetGroups) * barWidthPlusGap - barWidth) / 2;\n        } else {\n            offsetFromCenter = overlap ?\n                ((2 * i + 1 - nTraces) * barWidthPlusGap - barWidth) / 2 :\n                -barWidth / 2;\n        }\n\n        var t = calcTrace[0].t;\n        t.barwidth = barWidth;\n        t.poffset = offsetFromCenter;\n        t.bargroupwidth = barGroupWidth;\n        t.bardelta = minDiff;\n    }\n\n    // stack bars that only differ by rounding\n    sieve.binWidth = calcTraces[0][0].t.barwidth / 100;\n\n    // if defined, apply trace width\n    applyAttributes(sieve);\n\n    // store the bar center in each calcdata item\n    setBarCenterAndWidth(pa, sieve);\n\n    // update position axes\n    updatePositionAxis(pa, sieve, overlap);\n}\n\nfunction applyAttributes(sieve) {\n    var calcTraces = sieve.traces;\n    var i, j;\n\n    for(i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n        var calcTrace0 = calcTrace[0];\n        var fullTrace = calcTrace0.trace;\n        var t = calcTrace0.t;\n        var offset = fullTrace._offset || fullTrace.offset;\n        var initialPoffset = t.poffset;\n        var newPoffset;\n\n        if(isArrayOrTypedArray(offset)) {\n            // if offset is an array, then clone it into t.poffset.\n            newPoffset = Array.prototype.slice.call(offset, 0, calcTrace.length);\n\n            // guard against non-numeric items\n            for(j = 0; j < newPoffset.length; j++) {\n                if(!isNumeric(newPoffset[j])) {\n                    newPoffset[j] = initialPoffset;\n                }\n            }\n\n            // if the length of the array is too short,\n            // then extend it with the initial value of t.poffset\n            for(j = newPoffset.length; j < calcTrace.length; j++) {\n                newPoffset.push(initialPoffset);\n            }\n\n            t.poffset = newPoffset;\n        } else if(offset !== undefined) {\n            t.poffset = offset;\n        }\n\n        var width = fullTrace._width || fullTrace.width;\n        var initialBarwidth = t.barwidth;\n\n        if(isArrayOrTypedArray(width)) {\n            // if width is an array, then clone it into t.barwidth.\n            var newBarwidth = Array.prototype.slice.call(width, 0, calcTrace.length);\n\n            // guard against non-numeric items\n            for(j = 0; j < newBarwidth.length; j++) {\n                if(!isNumeric(newBarwidth[j])) newBarwidth[j] = initialBarwidth;\n            }\n\n            // if the length of the array is too short,\n            // then extend it with the initial value of t.barwidth\n            for(j = newBarwidth.length; j < calcTrace.length; j++) {\n                newBarwidth.push(initialBarwidth);\n            }\n\n            t.barwidth = newBarwidth;\n\n            // if user didn't set offset,\n            // then correct t.poffset to ensure bars remain centered\n            if(offset === undefined) {\n                newPoffset = [];\n                for(j = 0; j < calcTrace.length; j++) {\n                    newPoffset.push(\n                        initialPoffset + (initialBarwidth - newBarwidth[j]) / 2\n                    );\n                }\n                t.poffset = newPoffset;\n            }\n        } else if(width !== undefined) {\n            t.barwidth = width;\n\n            // if user didn't set offset,\n            // then correct t.poffset to ensure bars remain centered\n            if(offset === undefined) {\n                t.poffset = initialPoffset + (initialBarwidth - width) / 2;\n            }\n        }\n    }\n}\n\nfunction setBarCenterAndWidth(pa, sieve) {\n    var calcTraces = sieve.traces;\n    var pLetter = getAxisLetter(pa);\n\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n        var t = calcTrace[0].t;\n        var poffset = t.poffset;\n        var poffsetIsArray = Array.isArray(poffset);\n        var barwidth = t.barwidth;\n        var barwidthIsArray = Array.isArray(barwidth);\n\n        for(var j = 0; j < calcTrace.length; j++) {\n            var calcBar = calcTrace[j];\n\n            // store the actual bar width and position, for use by hover\n            var width = calcBar.w = barwidthIsArray ? barwidth[j] : barwidth;\n            calcBar[pLetter] = calcBar.p + (poffsetIsArray ? poffset[j] : poffset) + width / 2;\n        }\n    }\n}\n\nfunction updatePositionAxis(pa, sieve, allowMinDtick) {\n    var calcTraces = sieve.traces;\n    var minDiff = sieve.minDiff;\n    var vpad = minDiff / 2;\n\n    Axes.minDtick(pa, sieve.minDiff, sieve.distinctPositions[0], allowMinDtick);\n\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n        var calcTrace0 = calcTrace[0];\n        var fullTrace = calcTrace0.trace;\n        var pts = [];\n        var bar, l, r, j;\n\n        for(j = 0; j < calcTrace.length; j++) {\n            bar = calcTrace[j];\n            l = bar.p - vpad;\n            r = bar.p + vpad;\n            pts.push(l, r);\n        }\n\n        if(fullTrace.width || fullTrace.offset) {\n            var t = calcTrace0.t;\n            var poffset = t.poffset;\n            var barwidth = t.barwidth;\n            var poffsetIsArray = Array.isArray(poffset);\n            var barwidthIsArray = Array.isArray(barwidth);\n\n            for(j = 0; j < calcTrace.length; j++) {\n                bar = calcTrace[j];\n                var calcBarOffset = poffsetIsArray ? poffset[j] : poffset;\n                var calcBarWidth = barwidthIsArray ? barwidth[j] : barwidth;\n                l = bar.p + calcBarOffset;\n                r = l + calcBarWidth;\n                pts.push(l, r);\n            }\n        }\n\n        fullTrace._extremes[pa._id] = Axes.findExtremes(pa, pts, {padded: false});\n    }\n}\n\n// store these bar bases and tops in calcdata\n// and make sure the size axis includes zero,\n// along with the bases and tops of each bar.\nfunction setBaseAndTop(sa, sieve) {\n    var calcTraces = sieve.traces;\n    var sLetter = getAxisLetter(sa);\n\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n        var fullTrace = calcTrace[0].trace;\n        var pts = [];\n        var allBaseAboveZero = true;\n\n        for(var j = 0; j < calcTrace.length; j++) {\n            var bar = calcTrace[j];\n            var base = bar.b;\n            var top = base + bar.s;\n\n            bar[sLetter] = top;\n            pts.push(top);\n            if(bar.hasB) pts.push(base);\n\n            if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {\n                allBaseAboveZero = false;\n            }\n        }\n\n        fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {\n            tozero: !allBaseAboveZero,\n            padded: true\n        });\n    }\n}\n\nfunction stackBars(sa, sieve, opts) {\n    var sLetter = getAxisLetter(sa);\n    var calcTraces = sieve.traces;\n    var calcTrace;\n    var fullTrace;\n    var isFunnel;\n    var i, j;\n    var bar;\n\n    for(i = 0; i < calcTraces.length; i++) {\n        calcTrace = calcTraces[i];\n        fullTrace = calcTrace[0].trace;\n\n        if(fullTrace.type === 'funnel') {\n            for(j = 0; j < calcTrace.length; j++) {\n                bar = calcTrace[j];\n\n                if(bar.s !== BADNUM) {\n                    // create base of funnels\n                    sieve.put(bar.p, -0.5 * bar.s);\n                }\n            }\n        }\n    }\n\n    for(i = 0; i < calcTraces.length; i++) {\n        calcTrace = calcTraces[i];\n        fullTrace = calcTrace[0].trace;\n\n        isFunnel = (fullTrace.type === 'funnel');\n\n        var pts = [];\n\n        for(j = 0; j < calcTrace.length; j++) {\n            bar = calcTrace[j];\n\n            if(bar.s !== BADNUM) {\n                // stack current bar and get previous sum\n                var value;\n                if(isFunnel) {\n                    value = bar.s;\n                } else {\n                    value = bar.s + bar.b;\n                }\n\n                var base = sieve.put(bar.p, value);\n\n                var top = base + value;\n\n                // store the bar base and top in each calcdata item\n                bar.b = base;\n                bar[sLetter] = top;\n\n                if(!opts.norm) {\n                    pts.push(top);\n                    if(bar.hasB) {\n                        pts.push(base);\n                    }\n                }\n            }\n        }\n\n        // if barnorm is set, let normalizeBars update the axis range\n        if(!opts.norm) {\n            fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {\n                // N.B. we don't stack base with 'base',\n                // so set tozero:true always!\n                tozero: true,\n                padded: true\n            });\n        }\n    }\n}\n\nfunction sieveBars(sieve) {\n    var calcTraces = sieve.traces;\n\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n\n        for(var j = 0; j < calcTrace.length; j++) {\n            var bar = calcTrace[j];\n\n            if(bar.s !== BADNUM) {\n                sieve.put(bar.p, bar.b + bar.s);\n            }\n        }\n    }\n}\n\nfunction unhideBarsWithinTrace(sieve) {\n    var calcTraces = sieve.traces;\n\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n        var fullTrace = calcTrace[0].trace;\n\n        if(fullTrace.base === undefined) {\n            var inTraceSieve = new Sieve([calcTrace], {\n                sepNegVal: true,\n                overlapNoMerge: true\n            });\n\n            for(var j = 0; j < calcTrace.length; j++) {\n                var bar = calcTrace[j];\n\n                if(bar.p !== BADNUM) {\n                    // stack current bar and get previous sum\n                    var base = inTraceSieve.put(bar.p, bar.b + bar.s);\n\n                    // if previous sum if non-zero, this means:\n                    // multiple bars have same starting point are potentially hidden,\n                    // shift them vertically so that all bars are visible by default\n                    if(base) bar.b = base;\n                }\n            }\n        }\n    }\n}\n\n// Note:\n//\n// normalizeBars requires that either sieveBars or stackBars has been\n// previously invoked.\nfunction normalizeBars(sa, sieve, opts) {\n    var calcTraces = sieve.traces;\n    var sLetter = getAxisLetter(sa);\n    var sTop = opts.norm === 'fraction' ? 1 : 100;\n    var sTiny = sTop / 1e9; // in case of rounding error in sum\n    var sMin = sa.l2c(sa.c2l(0));\n    var sMax = opts.mode === 'stack' ? sTop : sMin;\n\n    function needsPadding(v) {\n        return (\n            isNumeric(sa.c2l(v)) &&\n            ((v < sMin - sTiny) || (v > sMax + sTiny) || !isNumeric(sMin))\n        );\n    }\n\n    for(var i = 0; i < calcTraces.length; i++) {\n        var calcTrace = calcTraces[i];\n        var fullTrace = calcTrace[0].trace;\n        var pts = [];\n        var allBaseAboveZero = true;\n        var padded = false;\n\n        for(var j = 0; j < calcTrace.length; j++) {\n            var bar = calcTrace[j];\n\n            if(bar.s !== BADNUM) {\n                var scale = Math.abs(sTop / sieve.get(bar.p, bar.s));\n                bar.b *= scale;\n                bar.s *= scale;\n\n                var base = bar.b;\n                var top = base + bar.s;\n\n                bar[sLetter] = top;\n                pts.push(top);\n                padded = padded || needsPadding(top);\n\n                if(bar.hasB) {\n                    pts.push(base);\n                    padded = padded || needsPadding(base);\n                }\n\n                if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {\n                    allBaseAboveZero = false;\n                }\n            }\n        }\n\n        fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {\n            tozero: !allBaseAboveZero,\n            padded: padded\n        });\n    }\n}\n\n// find the full position span of bars at each position\n// for use by hover, to ensure labels move in if bars are\n// narrower than the space they're in.\n// run once per trace group (subplot & direction) and\n// the same mapping is attached to all calcdata traces\nfunction collectExtents(calcTraces, pa) {\n    var pLetter = getAxisLetter(pa);\n    var extents = {};\n    var i, j, cd;\n\n    var pMin = Infinity;\n    var pMax = -Infinity;\n\n    for(i = 0; i < calcTraces.length; i++) {\n        cd = calcTraces[i];\n        for(j = 0; j < cd.length; j++) {\n            var p = cd[j].p;\n            if(isNumeric(p)) {\n                pMin = Math.min(pMin, p);\n                pMax = Math.max(pMax, p);\n            }\n        }\n    }\n\n    // this is just for positioning of hover labels, and nobody will care if\n    // the label is 1px too far out; so round positions to 1/10K in case\n    // position values don't exactly match from trace to trace\n    var roundFactor = 10000 / (pMax - pMin);\n    var round = extents.round = function(p) {\n        return String(Math.round(roundFactor * (p - pMin)));\n    };\n\n    for(i = 0; i < calcTraces.length; i++) {\n        cd = calcTraces[i];\n        cd[0].t.extents = extents;\n\n        var poffset = cd[0].t.poffset;\n        var poffsetIsArray = Array.isArray(poffset);\n\n        for(j = 0; j < cd.length; j++) {\n            var di = cd[j];\n            var p0 = di[pLetter] - di.w / 2;\n\n            if(isNumeric(p0)) {\n                var p1 = di[pLetter] + di.w / 2;\n                var pVal = round(di.p);\n                if(extents[pVal]) {\n                    extents[pVal] = [Math.min(p0, extents[pVal][0]), Math.max(p1, extents[pVal][1])];\n                } else {\n                    extents[pVal] = [p0, p1];\n                }\n            }\n\n            di.p0 = di.p + (poffsetIsArray ? poffset[j] : poffset);\n            di.p1 = di.p0 + di.w;\n            di.s0 = di.b;\n            di.s1 = di.s0 + di.s;\n        }\n    }\n}\n\nfunction getAxisLetter(ax) {\n    return ax._id.charAt(0);\n}\n\nmodule.exports = {\n    crossTraceCalc: crossTraceCalc,\n    setGroupPositions: setGroupPositions\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../../plots/cartesian/axis_ids\":770,\"../../registry\":847,\"./sieve.js\":869,\"fast-isnumeric\":225}],861:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\nvar Registry = _dereq_('../../registry');\n\nvar handleXYDefaults = _dereq_('../scatter/xy_defaults');\nvar handleStyleDefaults = _dereq_('./style_defaults');\nvar getAxisGroup = _dereq_('../../plots/cartesian/axis_ids').getAxisGroup;\nvar attributes = _dereq_('./attributes');\n\nvar coerceFont = Lib.coerceFont;\n\nfunction supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleXYDefaults(traceIn, traceOut, layout, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('orientation', (traceOut.x && !traceOut.y) ? 'h' : 'v');\n    coerce('base');\n    coerce('offset');\n    coerce('width');\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    var textposition = coerce('textposition');\n    handleText(traceIn, traceOut, layout, coerce, textposition, {\n        moduleHasSelected: true,\n        moduleHasUnselected: true,\n        moduleHasConstrain: true,\n        moduleHasCliponaxis: true,\n        moduleHasTextangle: true,\n        moduleHasInsideanchor: true\n    });\n\n    handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);\n\n    var lineColor = (traceOut.marker.line || {}).color;\n\n    // override defaultColor for error bars with defaultLine\n    var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || Color.defaultLine, {axis: 'y'});\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || Color.defaultLine, {axis: 'x', inherit: 'y'});\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n}\n\nfunction handleGroupingDefaults(traceIn, traceOut, fullLayout, coerce) {\n    var orientation = traceOut.orientation;\n    // N.B. grouping is done across all trace types that support it\n    var posAxId = traceOut[{v: 'x', h: 'y'}[orientation] + 'axis'];\n    var groupId = getAxisGroup(fullLayout, posAxId) + orientation;\n\n    var alignmentOpts = fullLayout._alignmentOpts || {};\n    var alignmentgroup = coerce('alignmentgroup');\n\n    var alignmentGroups = alignmentOpts[groupId];\n    if(!alignmentGroups) alignmentGroups = alignmentOpts[groupId] = {};\n\n    var alignmentGroupOpts = alignmentGroups[alignmentgroup];\n\n    if(alignmentGroupOpts) {\n        alignmentGroupOpts.traces.push(traceOut);\n    } else {\n        alignmentGroupOpts = alignmentGroups[alignmentgroup] = {\n            traces: [traceOut],\n            alignmentIndex: Object.keys(alignmentGroups).length,\n            offsetGroups: {}\n        };\n    }\n\n    var offsetgroup = coerce('offsetgroup');\n    var offsetGroups = alignmentGroupOpts.offsetGroups;\n    var offsetGroupOpts = offsetGroups[offsetgroup];\n\n    if(offsetgroup) {\n        if(!offsetGroupOpts) {\n            offsetGroupOpts = offsetGroups[offsetgroup] = {\n                offsetIndex: Object.keys(offsetGroups).length\n            };\n        }\n\n        traceOut._offsetIndex = offsetGroupOpts.offsetIndex;\n    }\n}\n\nfunction crossTraceDefaults(fullData, fullLayout) {\n    var traceIn, traceOut;\n\n    function coerce(attr) {\n        return Lib.coerce(traceOut._input, traceOut, attributes, attr);\n    }\n\n    if(fullLayout.barmode === 'group') {\n        for(var i = 0; i < fullData.length; i++) {\n            traceOut = fullData[i];\n\n            if(traceOut.type === 'bar') {\n                traceIn = traceOut._input;\n                handleGroupingDefaults(traceIn, traceOut, fullLayout, coerce);\n            }\n        }\n    }\n}\n\nfunction handleText(traceIn, traceOut, layout, coerce, textposition, opts) {\n    opts = opts || {};\n    var moduleHasSelected = !(opts.moduleHasSelected === false);\n    var moduleHasUnselected = !(opts.moduleHasUnselected === false);\n    var moduleHasConstrain = !(opts.moduleHasConstrain === false);\n    var moduleHasCliponaxis = !(opts.moduleHasCliponaxis === false);\n    var moduleHasTextangle = !(opts.moduleHasTextangle === false);\n    var moduleHasInsideanchor = !(opts.moduleHasInsideanchor === false);\n\n    var hasBoth = Array.isArray(textposition) || textposition === 'auto';\n    var hasInside = hasBoth || textposition === 'inside';\n    var hasOutside = hasBoth || textposition === 'outside';\n\n    if(hasInside || hasOutside) {\n        var dfltFont = coerceFont(coerce, 'textfont', layout.font);\n\n        // Note that coercing `insidetextfont` is always needed –\n        // even if `textposition` is `outside` for each trace – since\n        // an outside label can become an inside one, for example because\n        // of a bar being stacked on top of it.\n        var insideTextFontDefault = Lib.extendFlat({}, dfltFont);\n        var isTraceTextfontColorSet = traceIn.textfont && traceIn.textfont.color;\n        var isColorInheritedFromLayoutFont = !isTraceTextfontColorSet;\n        if(isColorInheritedFromLayoutFont) {\n            delete insideTextFontDefault.color;\n        }\n        coerceFont(coerce, 'insidetextfont', insideTextFontDefault);\n\n        if(hasOutside) coerceFont(coerce, 'outsidetextfont', dfltFont);\n\n\n        if(moduleHasSelected) coerce('selected.textfont.color');\n        if(moduleHasUnselected) coerce('unselected.textfont.color');\n        if(moduleHasConstrain) coerce('constraintext');\n        if(moduleHasCliponaxis) coerce('cliponaxis');\n        if(moduleHasTextangle) coerce('textangle');\n    }\n\n    if(hasInside) {\n        if(moduleHasInsideanchor) coerce('insidetextanchor');\n    }\n}\n\nmodule.exports = {\n    supplyDefaults: supplyDefaults,\n    crossTraceDefaults: crossTraceDefaults,\n    handleGroupingDefaults: handleGroupingDefaults,\n    handleText: handleText\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../../plots/cartesian/axis_ids\":770,\"../../registry\":847,\"../scatter/xy_defaults\":1137,\"./attributes\":857,\"./style_defaults\":871}],862:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar tinycolor = _dereq_('tinycolor2');\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\n\nexports.coerceString = function(attributeDefinition, value, defaultValue) {\n    if(typeof value === 'string') {\n        if(value || !attributeDefinition.noBlank) return value;\n    } else if(typeof value === 'number' || value === true) {\n        if(!attributeDefinition.strict) return String(value);\n    }\n\n    return (defaultValue !== undefined) ?\n      defaultValue :\n      attributeDefinition.dflt;\n};\n\nexports.coerceNumber = function(attributeDefinition, value, defaultValue) {\n    if(isNumeric(value)) {\n        value = +value;\n\n        var min = attributeDefinition.min;\n        var max = attributeDefinition.max;\n        var isOutOfBounds = (min !== undefined && value < min) ||\n              (max !== undefined && value > max);\n\n        if(!isOutOfBounds) return value;\n    }\n\n    return (defaultValue !== undefined) ?\n      defaultValue :\n      attributeDefinition.dflt;\n};\n\nexports.coerceColor = function(attributeDefinition, value, defaultValue) {\n    if(tinycolor(value).isValid()) return value;\n\n    return (defaultValue !== undefined) ?\n      defaultValue :\n      attributeDefinition.dflt;\n};\n\nexports.coerceEnumerated = function(attributeDefinition, value, defaultValue) {\n    if(attributeDefinition.coerceNumber) value = +value;\n\n    if(attributeDefinition.values.indexOf(value) !== -1) return value;\n\n    return (defaultValue !== undefined) ?\n      defaultValue :\n      attributeDefinition.dflt;\n};\n\nexports.getValue = function(arrayOrScalar, index) {\n    var value;\n    if(!Array.isArray(arrayOrScalar)) value = arrayOrScalar;\n    else if(index < arrayOrScalar.length) value = arrayOrScalar[index];\n    return value;\n};\n\nexports.getLineWidth = function(trace, di) {\n    var w =\n        (0 < di.mlw) ? di.mlw :\n        !isArrayOrTypedArray(trace.marker.line.width) ? trace.marker.line.width :\n        0;\n\n    return w;\n};\n\n},{\"../../lib\":719,\"fast-isnumeric\":225,\"tinycolor2\":537}],863:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Fx = _dereq_('../../components/fx');\nvar Registry = _dereq_('../../registry');\nvar Color = _dereq_('../../components/color');\n\nvar fillText = _dereq_('../../lib').fillText;\nvar getLineWidth = _dereq_('./helpers').getLineWidth;\n\nfunction hoverPoints(pointData, xval, yval, hovermode) {\n    var barPointData = hoverOnBars(pointData, xval, yval, hovermode);\n\n    if(barPointData) {\n        var cd = barPointData.cd;\n        var trace = cd[0].trace;\n        var di = cd[barPointData.index];\n\n        barPointData.color = getTraceColor(trace, di);\n        Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, barPointData);\n\n        return [barPointData];\n    }\n}\n\nfunction hoverOnBars(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n    var t = cd[0].t;\n    var isClosest = (hovermode === 'closest');\n    var isWaterfall = (trace.type === 'waterfall');\n    var maxHoverDistance = pointData.maxHoverDistance;\n    var maxSpikeDistance = pointData.maxSpikeDistance;\n\n    var posVal, sizeVal, posLetter, sizeLetter, dx, dy, pRangeCalc;\n\n    function thisBarMinPos(di) { return di[posLetter] - di.w / 2; }\n    function thisBarMaxPos(di) { return di[posLetter] + di.w / 2; }\n\n    var minPos = isClosest ?\n        thisBarMinPos :\n        function(di) {\n            /*\n             * In compare mode, accept a bar if you're on it *or* its group.\n             * Nearly always it's the group that matters, but in case the bar\n             * was explicitly set wider than its group we'd better accept the\n             * whole bar.\n             *\n             * use `bardelta` instead of `bargroupwidth` so we accept hover\n             * in the gap. That way hover doesn't flash on and off as you\n             * mouse over the plot in compare modes.\n             * In 'closest' mode though the flashing seems inevitable,\n             * without far more complex logic\n             */\n            return Math.min(thisBarMinPos(di), di.p - t.bardelta / 2);\n        };\n\n    var maxPos = isClosest ?\n        thisBarMaxPos :\n        function(di) {\n            return Math.max(thisBarMaxPos(di), di.p + t.bardelta / 2);\n        };\n\n    function _positionFn(_minPos, _maxPos) {\n        // add a little to the pseudo-distance for wider bars, so that like scatter,\n        // if you are over two overlapping bars, the narrower one wins.\n        return Fx.inbox(_minPos - posVal, _maxPos - posVal,\n            maxHoverDistance + Math.min(1, Math.abs(_maxPos - _minPos) / pRangeCalc) - 1);\n    }\n\n    function positionFn(di) {\n        return _positionFn(minPos(di), maxPos(di));\n    }\n\n    function thisBarPositionFn(di) {\n        return _positionFn(thisBarMinPos(di), thisBarMaxPos(di));\n    }\n\n    function sizeFn(di) {\n        var v = sizeVal;\n        var b = di.b;\n        var s = di[sizeLetter];\n\n        if(isWaterfall) {\n            s += Math.abs(di.rawS || 0);\n        }\n\n        // add a gradient so hovering near the end of a\n        // bar makes it a little closer match\n        return Fx.inbox(b - v, s - v, maxHoverDistance + (s - v) / (s - b) - 1);\n    }\n\n    if(trace.orientation === 'h') {\n        posVal = yval;\n        sizeVal = xval;\n        posLetter = 'y';\n        sizeLetter = 'x';\n        dx = sizeFn;\n        dy = positionFn;\n    } else {\n        posVal = xval;\n        sizeVal = yval;\n        posLetter = 'x';\n        sizeLetter = 'y';\n        dy = sizeFn;\n        dx = positionFn;\n    }\n\n    var pa = pointData[posLetter + 'a'];\n    var sa = pointData[sizeLetter + 'a'];\n\n    pRangeCalc = Math.abs(pa.r2c(pa.range[1]) - pa.r2c(pa.range[0]));\n\n    function dxy(di) { return (dx(di) + dy(di)) / 2; }\n    var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);\n    Fx.getClosest(cd, distfn, pointData);\n\n    // skip the rest (for this trace) if we didn't find a close point\n    if(pointData.index === false) return;\n\n    // if we get here and we're not in 'closest' mode, push min/max pos back\n    // onto the group - even though that means occasionally the mouse will be\n    // over the hover label.\n    if(!isClosest) {\n        minPos = function(di) {\n            return Math.min(thisBarMinPos(di), di.p - t.bargroupwidth / 2);\n        };\n        maxPos = function(di) {\n            return Math.max(thisBarMaxPos(di), di.p + t.bargroupwidth / 2);\n        };\n    }\n\n    // the closest data point\n    var index = pointData.index;\n    var di = cd[index];\n\n    var size = (trace.base) ? di.b + di.s : di.s;\n    pointData[sizeLetter + '0'] = pointData[sizeLetter + '1'] = sa.c2p(di[sizeLetter], true);\n    pointData[sizeLetter + 'LabelVal'] = size;\n\n    var extent = t.extents[t.extents.round(di.p)];\n    pointData[posLetter + '0'] = pa.c2p(isClosest ? minPos(di) : extent[0], true);\n    pointData[posLetter + '1'] = pa.c2p(isClosest ? maxPos(di) : extent[1], true);\n    pointData[posLetter + 'LabelVal'] = di.p;\n\n    // spikelines always want \"closest\" distance regardless of hovermode\n    pointData.spikeDistance = (sizeFn(di) + thisBarPositionFn(di)) / 2 + maxSpikeDistance - maxHoverDistance;\n    // they also want to point to the data value, regardless of where the label goes\n    // in case of bars shifted within groups\n    pointData[posLetter + 'Spike'] = pa.c2p(di.p, true);\n\n    fillText(di, trace, pointData);\n    pointData.hovertemplate = trace.hovertemplate;\n\n    return pointData;\n}\n\nfunction getTraceColor(trace, di) {\n    var mc = di.mcc || trace.marker.color;\n    var mlc = di.mlcc || trace.marker.line.color;\n    var mlw = getLineWidth(trace, di);\n\n    if(Color.opacity(mc)) return mc;\n    else if(Color.opacity(mlc) && mlw) return mlc;\n}\n\nmodule.exports = {\n    hoverPoints: hoverPoints,\n    hoverOnBars: hoverOnBars,\n    getTraceColor: getTraceColor\n};\n\n},{\"../../components/color\":593,\"../../components/fx\":632,\"../../lib\":719,\"../../registry\":847,\"./helpers\":862}],864:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyDefaults: _dereq_('./defaults').supplyDefaults,\n    crossTraceDefaults: _dereq_('./defaults').crossTraceDefaults,\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n    calc: _dereq_('./calc'),\n    crossTraceCalc: _dereq_('./cross_trace_calc').crossTraceCalc,\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n    arraysToCalcdata: _dereq_('./arrays_to_calcdata'),\n    plot: _dereq_('./plot').plot,\n    style: _dereq_('./style').style,\n    styleOnSelect: _dereq_('./style').styleOnSelect,\n    hoverPoints: _dereq_('./hover').hoverPoints,\n    selectPoints: _dereq_('./select'),\n\n    moduleType: 'trace',\n    name: 'bar',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['bar-like', 'cartesian', 'svg', 'bar', 'oriented', 'errorBarsOK', 'showLegend', 'zoomScale'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../scatter/marker_colorbar\":1129,\"./arrays_to_calcdata\":856,\"./attributes\":857,\"./calc\":858,\"./cross_trace_calc\":860,\"./defaults\":861,\"./hover\":863,\"./layout_attributes\":865,\"./layout_defaults\":866,\"./plot\":867,\"./select\":868,\"./style\":870}],865:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n    barmode: {\n        valType: 'enumerated',\n        values: ['stack', 'group', 'overlay', 'relative'],\n        dflt: 'group',\n        \n        editType: 'calc',\n        \n    },\n    barnorm: {\n        valType: 'enumerated',\n        values: ['', 'fraction', 'percent'],\n        dflt: '',\n        \n        editType: 'calc',\n        \n    },\n    bargap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        \n        editType: 'calc',\n        \n    },\n    bargroupgap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    }\n};\n\n},{}],866:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Lib = _dereq_('../../lib');\n\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nmodule.exports = function(layoutIn, layoutOut, fullData) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n\n    var hasBars = false;\n    var shouldBeGapless = false;\n    var gappedAnyway = false;\n    var usedSubplots = {};\n\n    var mode = coerce('barmode');\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n        if(Registry.traceIs(trace, 'bar') && trace.visible) hasBars = true;\n        else continue;\n\n        // if we have at least 2 grouped bar traces on the same subplot,\n        // we should default to a gap anyway, even if the data is histograms\n        if(mode === 'group') {\n            var subploti = trace.xaxis + trace.yaxis;\n            if(usedSubplots[subploti]) gappedAnyway = true;\n            usedSubplots[subploti] = true;\n        }\n\n        if(trace.visible && trace.type === 'histogram') {\n            var pa = Axes.getFromId({_fullLayout: layoutOut},\n                        trace[trace.orientation === 'v' ? 'xaxis' : 'yaxis']);\n            if(pa.type !== 'category') shouldBeGapless = true;\n        }\n    }\n\n    if(!hasBars) {\n        delete layoutOut.barmode;\n        return;\n    }\n\n    if(mode !== 'overlay') coerce('barnorm');\n\n    coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);\n    coerce('bargroupgap');\n};\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"./layout_attributes\":865}],867:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\n\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar Registry = _dereq_('../../registry');\nvar tickText = _dereq_('../../plots/cartesian/axes').tickText;\n\nvar style = _dereq_('./style');\nvar helpers = _dereq_('./helpers');\nvar attributes = _dereq_('./attributes');\n\nvar attributeText = attributes.text;\nvar attributeTextPosition = attributes.textposition;\n\n// padding in pixels around text\nvar TEXTPAD = 3;\n\nfunction dirSign(a, b) {\n    return (a < b) ? 1 : -1;\n}\n\nfunction getXY(di, xa, ya, isHorizontal) {\n    var s = [];\n    var p = [];\n\n    var sAxis = isHorizontal ? xa : ya;\n    var pAxis = isHorizontal ? ya : xa;\n\n    s[0] = sAxis.c2p(di.s0, true);\n    p[0] = pAxis.c2p(di.p0, true);\n\n    s[1] = sAxis.c2p(di.s1, true);\n    p[1] = pAxis.c2p(di.p1, true);\n\n    return isHorizontal ? [s, p] : [p, s];\n}\n\nfunction plot(gd, plotinfo, cdModule, traceLayer, opts) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n    var fullLayout = gd._fullLayout;\n\n    if(!opts) {\n        opts = {\n            mode: fullLayout.barmode,\n            norm: fullLayout.barmode,\n            gap: fullLayout.bargap,\n            groupgap: fullLayout.bargroupgap\n        };\n    }\n\n    var bartraces = Lib.makeTraceGroups(traceLayer, cdModule, 'trace bars').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var trace = cd[0].trace;\n        var isWaterfall = (trace.type === 'waterfall');\n        var isFunnel = (trace.type === 'funnel');\n        var isBar = (trace.type === 'bar');\n        var shouldDisplayZeros = (isBar || isFunnel);\n\n        var adjustPixel = 0;\n        if(isWaterfall && trace.connector.visible && trace.connector.mode === 'between') {\n            adjustPixel = trace.connector.line.width / 2;\n        }\n\n        var isHorizontal = (trace.orientation === 'h');\n\n        var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');\n\n        var bars = pointGroup.selectAll('g.point').data(Lib.identity);\n\n        bars.enter().append('g')\n            .classed('point', true);\n\n        bars.exit().remove();\n\n        bars.each(function(di, i) {\n            var bar = d3.select(this);\n\n            // now display the bar\n            // clipped xf/yf (2nd arg true): non-positive\n            // log values go off-screen by plotwidth\n            // so you see them continue if you drag the plot\n\n            var xy = getXY(di, xa, ya, isHorizontal);\n\n            var x0 = xy[0][0];\n            var x1 = xy[0][1];\n            var y0 = xy[1][0];\n            var y1 = xy[1][1];\n\n            var isBlank = (\n                x0 === x1 ||\n                y0 === y1 ||\n                !isNumeric(x0) ||\n                !isNumeric(x1) ||\n                !isNumeric(y0) ||\n                !isNumeric(y1)\n            );\n            // display zeros if line.width > 0\n            if(isBlank && shouldDisplayZeros && helpers.getLineWidth(trace, di) && (isHorizontal ? x1 - x0 === 0 : y1 - y0 === 0)) {\n                isBlank = false;\n            }\n            di.isBlank = isBlank;\n\n            // in waterfall mode `between` we need to adjust bar end points to match the connector width\n            if(adjustPixel) {\n                if(isHorizontal) {\n                    x0 -= dirSign(x0, x1) * adjustPixel;\n                    x1 += dirSign(x0, x1) * adjustPixel;\n                } else {\n                    y0 -= dirSign(y0, y1) * adjustPixel;\n                    y1 += dirSign(y0, y1) * adjustPixel;\n                }\n            }\n\n            var lw;\n            var mc;\n\n            if(trace.type === 'waterfall') {\n                if(!isBlank) {\n                    var cont = trace[di.dir].marker;\n                    lw = cont.line.width;\n                    mc = cont.color;\n                }\n            } else {\n                lw = helpers.getLineWidth(trace, di);\n                mc = di.mc || trace.marker.color;\n            }\n\n            var offset = d3.round((lw / 2) % 1, 2);\n\n            function roundWithLine(v) {\n                // if there are explicit gaps, don't round,\n                // it can make the gaps look crappy\n                return (opts.gap === 0 && opts.groupgap === 0) ?\n                    d3.round(Math.round(v) - offset, 2) : v;\n            }\n\n            function expandToVisible(v, vc) {\n                // if it's not in danger of disappearing entirely,\n                // round more precisely\n                return Math.abs(v - vc) >= 2 ? roundWithLine(v) :\n                // but if it's very thin, expand it so it's\n                // necessarily visible, even if it might overlap\n                // its neighbor\n                (v > vc ? Math.ceil(v) : Math.floor(v));\n            }\n\n            if(!gd._context.staticPlot) {\n                // if bars are not fully opaque or they have a line\n                // around them, round to integer pixels, mainly for\n                // safari so we prevent overlaps from its expansive\n                // pixelation. if the bars ARE fully opaque and have\n                // no line, expand to a full pixel to make sure we\n                // can see them\n\n                var op = Color.opacity(mc);\n                var fixpx = (op < 1 || lw > 0.01) ? roundWithLine : expandToVisible;\n                x0 = fixpx(x0, x1);\n                x1 = fixpx(x1, x0);\n                y0 = fixpx(y0, y1);\n                y1 = fixpx(y1, y0);\n            }\n\n            Lib.ensureSingle(bar, 'path')\n                .style('vector-effect', 'non-scaling-stroke')\n                .attr('d', isBlank ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z')\n                .call(Drawing.setClipUrl, plotinfo.layerClipId, gd);\n\n            appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, opts);\n\n            if(plotinfo.layerClipId) {\n                Drawing.hideOutsideRangePoint(di, bar.select('text'), xa, ya, trace.xcalendar, trace.ycalendar);\n            }\n        });\n\n        // lastly, clip points groups of `cliponaxis !== false` traces\n        // on `plotinfo._hasClipOnAxisFalse === true` subplots\n        var hasClipOnAxisFalse = trace.cliponaxis === false;\n        Drawing.setClipUrl(plotGroup, hasClipOnAxisFalse ? null : plotinfo.layerClipId, gd);\n    });\n\n    // error bars are on the top\n    Registry.getComponentMethod('errorbars', 'plot')(gd, bartraces, plotinfo);\n}\n\nfunction appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    var fullLayout = gd._fullLayout;\n    var textPosition;\n\n    function appendTextNode(bar, text, textFont) {\n        var textSelection = Lib.ensureSingle(bar, 'text')\n            .text(text)\n            .attr({\n                'class': 'bartext bartext-' + textPosition,\n                transform: '',\n                'text-anchor': 'middle',\n                // prohibit tex interpretation until we can handle\n                // tex and regular text together\n                'data-notex': 1\n            })\n            .call(Drawing.font, textFont)\n            .call(svgTextUtils.convertToTspans, gd);\n\n        return textSelection;\n    }\n\n    // get trace attributes\n    var trace = calcTrace[0].trace;\n    var isHorizontal = (trace.orientation === 'h');\n\n    var text = getText(calcTrace, i, xa, ya);\n    textPosition = getTextPosition(trace, i);\n\n    // compute text position\n    var inStackOrRelativeMode =\n        opts.mode === 'stack' ||\n        opts.mode === 'relative';\n\n    var calcBar = calcTrace[i];\n    var isOutmostBar = !inStackOrRelativeMode || calcBar._outmost;\n\n    if(!text ||\n        textPosition === 'none' ||\n        ((calcBar.isBlank || x0 === x1 || y0 === y1) && (\n            textPosition === 'auto' ||\n            textPosition === 'inside'))) {\n        bar.select('text').remove();\n        return;\n    }\n\n    var layoutFont = fullLayout.font;\n    var barColor = style.getBarColor(calcTrace[i], trace);\n    var insideTextFont = style.getInsideTextFont(trace, i, layoutFont, barColor);\n    var outsideTextFont = style.getOutsideTextFont(trace, i, layoutFont);\n\n    // Special case: don't use the c2p(v, true) value on log size axes,\n    // so that we can get correctly inside text scaling\n    var di = bar.datum();\n    if(isHorizontal) {\n        if(xa.type === 'log' && di.s0 <= 0) {\n            if(xa.range[0] < xa.range[1]) {\n                x0 = 0;\n            } else {\n                x0 = xa._length;\n            }\n        }\n    } else {\n        if(ya.type === 'log' && di.s0 <= 0) {\n            if(ya.range[0] < ya.range[1]) {\n                y0 = ya._length;\n            } else {\n                y0 = 0;\n            }\n        }\n    }\n\n    // padding excluded\n    var barWidth = Math.abs(x1 - x0) - 2 * TEXTPAD;\n    var barHeight = Math.abs(y1 - y0) - 2 * TEXTPAD;\n\n    var textSelection;\n    var textBB;\n    var textWidth;\n    var textHeight;\n\n    if(textPosition === 'outside') {\n        if(!isOutmostBar && !calcBar.hasB) textPosition = 'inside';\n    }\n\n    if(textPosition === 'auto') {\n        if(isOutmostBar) {\n            // draw text using insideTextFont and check if it fits inside bar\n            textPosition = 'inside';\n            textSelection = appendTextNode(bar, text, insideTextFont);\n\n            textBB = Drawing.bBox(textSelection.node()),\n            textWidth = textBB.width,\n            textHeight = textBB.height;\n\n            var textHasSize = (textWidth > 0 && textHeight > 0);\n            var fitsInside = (textWidth <= barWidth && textHeight <= barHeight);\n            var fitsInsideIfRotated = (textWidth <= barHeight && textHeight <= barWidth);\n            var fitsInsideIfShrunk = (isHorizontal) ?\n                (barWidth >= textWidth * (barHeight / textHeight)) :\n                (barHeight >= textHeight * (barWidth / textWidth));\n\n            if(textHasSize && (\n                fitsInside ||\n                fitsInsideIfRotated ||\n                fitsInsideIfShrunk)\n            ) {\n                textPosition = 'inside';\n            } else {\n                textPosition = 'outside';\n                textSelection.remove();\n                textSelection = null;\n            }\n        } else {\n            textPosition = 'inside';\n        }\n    }\n\n    if(!textSelection) {\n        textSelection = appendTextNode(bar, text,\n                (textPosition === 'outside') ?\n                outsideTextFont : insideTextFont);\n\n        textBB = Drawing.bBox(textSelection.node()),\n        textWidth = textBB.width,\n        textHeight = textBB.height;\n\n        if(textWidth <= 0 || textHeight <= 0) {\n            textSelection.remove();\n            return;\n        }\n    }\n\n    // compute text transform\n    var transform, constrained;\n    if(textPosition === 'outside') {\n        constrained =\n            trace.constraintext === 'both' ||\n            trace.constraintext === 'outside';\n\n        transform = getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, {\n            isHorizontal: isHorizontal,\n            constrained: constrained,\n            angle: trace.textangle\n        });\n    } else {\n        constrained =\n            trace.constraintext === 'both' ||\n            trace.constraintext === 'inside';\n\n        transform = getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, {\n            isHorizontal: isHorizontal,\n            constrained: constrained,\n            angle: trace.textangle,\n            anchor: trace.insidetextanchor\n        });\n    }\n\n    textSelection.attr('transform', transform);\n}\n\nfunction getRotationFromAngle(angle) {\n    return (angle === 'auto') ? 0 : angle;\n}\n\nfunction getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, opts) {\n    var isHorizontal = !!opts.isHorizontal;\n    var constrained = !!opts.constrained;\n    var angle = opts.angle || 0;\n    var anchor = opts.anchor || 0;\n\n    var textWidth = textBB.width;\n    var textHeight = textBB.height;\n    var lx = Math.abs(x1 - x0);\n    var ly = Math.abs(y1 - y0);\n\n    var textpad = (\n        lx > (2 * TEXTPAD) &&\n        ly > (2 * TEXTPAD)\n    ) ? TEXTPAD : 0;\n\n    lx -= 2 * textpad;\n    ly -= 2 * textpad;\n\n    var autoRotate = (angle === 'auto');\n    var isAutoRotated = false;\n    if(autoRotate &&\n        !(textWidth <= lx && textHeight <= ly) &&\n        (textWidth > lx || textHeight > ly) && (\n        !(textWidth > ly || textHeight > lx) ||\n        ((textWidth < textHeight) !== (lx < ly))\n    )) {\n        isAutoRotated = true;\n    }\n\n    if(isAutoRotated) {\n        // don't rotate yet only swap bar width with height\n        var tmp = ly;\n        ly = lx;\n        lx = tmp;\n    }\n\n    var rotation = getRotationFromAngle(angle);\n    var absSin = Math.abs(Math.sin(Math.PI / 180 * rotation));\n    var absCos = Math.abs(Math.cos(Math.PI / 180 * rotation));\n\n    // compute and apply text padding\n    var dx = Math.max(lx * absCos, ly * absSin);\n    var dy = Math.max(lx * absSin, ly * absCos);\n\n    var scale = (constrained) ?\n        Math.min(dx / textWidth, dy / textHeight) :\n        Math.max(absCos, absSin);\n\n    scale = Math.min(1, scale);\n\n    // compute text and target positions\n    var targetX = (x0 + x1) / 2;\n    var targetY = (y0 + y1) / 2;\n\n    if(anchor !== 'middle') { // case of 'start' or 'end'\n        var targetWidth = scale * (isHorizontal !== isAutoRotated ? textHeight : textWidth);\n        var targetHeight = scale * (isHorizontal !== isAutoRotated ? textWidth : textHeight);\n        textpad += 0.5 * (targetWidth * absSin + targetHeight * absCos);\n\n        if(isHorizontal) {\n            textpad *= dirSign(x0, x1);\n            targetX = (anchor === 'start') ? x0 + textpad : x1 - textpad;\n        } else {\n            textpad *= dirSign(y0, y1);\n            targetY = (anchor === 'start') ? y0 + textpad : y1 - textpad;\n        }\n    }\n\n    var textX = (textBB.left + textBB.right) / 2;\n    var textY = (textBB.top + textBB.bottom) / 2;\n\n    // lastly apply auto rotation\n    if(isAutoRotated) rotation += 90;\n\n    return getTransform(textX, textY, targetX, targetY, scale, rotation);\n}\n\nfunction getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, opts) {\n    var isHorizontal = !!opts.isHorizontal;\n    var constrained = !!opts.constrained;\n    var angle = opts.angle || 0;\n\n    var textWidth = textBB.width;\n    var textHeight = textBB.height;\n    var lx = Math.abs(x1 - x0);\n    var ly = Math.abs(y1 - y0);\n\n    var textpad;\n    // Keep the padding so the text doesn't sit right against\n    // the bars, but don't factor it into barWidth\n    if(isHorizontal) {\n        textpad = (ly > 2 * TEXTPAD) ? TEXTPAD : 0;\n    } else {\n        textpad = (lx > 2 * TEXTPAD) ? TEXTPAD : 0;\n    }\n\n    // compute rotation and scale\n    var scale = 1;\n    if(constrained) {\n        scale = (isHorizontal) ?\n            Math.min(1, ly / textHeight) :\n            Math.min(1, lx / textWidth);\n    }\n\n    var rotation = getRotationFromAngle(angle);\n    var absSin = Math.abs(Math.sin(Math.PI / 180 * rotation));\n    var absCos = Math.abs(Math.cos(Math.PI / 180 * rotation));\n\n    // compute text and target positions\n    var targetWidth = scale * (isHorizontal ? textHeight : textWidth);\n    var targetHeight = scale * (isHorizontal ? textWidth : textHeight);\n    textpad += 0.5 * (targetWidth * absSin + targetHeight * absCos);\n\n    var targetX = (x0 + x1) / 2;\n    var targetY = (y0 + y1) / 2;\n\n    if(isHorizontal) {\n        targetX = x1 - textpad * dirSign(x1, x0);\n    } else {\n        targetY = y1 + textpad * dirSign(y0, y1);\n    }\n\n    var textX = (textBB.left + textBB.right) / 2;\n    var textY = (textBB.top + textBB.bottom) / 2;\n\n    return getTransform(textX, textY, targetX, targetY, scale, rotation);\n}\n\nfunction getTransform(textX, textY, targetX, targetY, scale, rotation) {\n    var transformScale;\n    var transformRotate;\n    var transformTranslate;\n\n    if(scale < 1) transformScale = 'scale(' + scale + ') ';\n    else {\n        scale = 1;\n        transformScale = '';\n    }\n\n    transformRotate = (rotation) ?\n        'rotate(' + rotation + ' ' + textX + ' ' + textY + ') ' : '';\n\n    // Note that scaling also affects the center of the text box\n    var translateX = (targetX - scale * textX);\n    var translateY = (targetY - scale * textY);\n    transformTranslate = 'translate(' + translateX + ' ' + translateY + ')';\n\n    return transformTranslate + transformScale + transformRotate;\n}\n\nfunction getText(calcTrace, index, xa, ya) {\n    var trace = calcTrace[0].trace;\n\n    var value;\n    if(!trace.textinfo) {\n        value = helpers.getValue(trace.text, index);\n    } else {\n        value = calcTextinfo(calcTrace, index, xa, ya);\n    }\n\n    return helpers.coerceString(attributeText, value);\n}\n\nfunction getTextPosition(trace, index) {\n    var value = helpers.getValue(trace.textposition, index);\n    return helpers.coerceEnumerated(attributeTextPosition, value);\n}\n\nfunction calcTextinfo(calcTrace, index, xa, ya) {\n    var trace = calcTrace[0].trace;\n    var isHorizontal = (trace.orientation === 'h');\n    var isWaterfall = (trace.type === 'waterfall');\n    var isFunnel = (trace.type === 'funnel');\n\n    function formatLabel(u) {\n        var pAxis = isHorizontal ? ya : xa;\n        return tickText(pAxis, u, true).text;\n    }\n\n    function formatNumber(v) {\n        var sAxis = isHorizontal ? xa : ya;\n        return tickText(sAxis, +v, true).text;\n    }\n\n    var textinfo = trace.textinfo;\n    var cdi = calcTrace[index];\n\n    var parts = textinfo.split('+');\n    var text = [];\n    var tx;\n\n    var hasFlag = function(flag) { return parts.indexOf(flag) !== -1; };\n\n    if(hasFlag('label')) {\n        text.push(formatLabel(calcTrace[index].p));\n    }\n\n    if(hasFlag('text')) {\n        tx = Lib.castOption(trace, cdi.i, 'text');\n        if(tx === 0 || tx) text.push(tx);\n    }\n\n    if(isWaterfall) {\n        var delta = +cdi.rawS || cdi.s;\n        var final = cdi.v;\n        var initial = final - delta;\n\n        if(hasFlag('initial')) text.push(formatNumber(initial));\n        if(hasFlag('delta')) text.push(formatNumber(delta));\n        if(hasFlag('final')) text.push(formatNumber(final));\n    }\n\n    if(isFunnel) {\n        if(hasFlag('value')) text.push(formatNumber(cdi.s));\n\n        var nPercent = 0;\n        if(hasFlag('percent initial')) nPercent++;\n        if(hasFlag('percent previous')) nPercent++;\n        if(hasFlag('percent total')) nPercent++;\n\n        var hasMultiplePercents = nPercent > 1;\n\n        if(hasFlag('percent initial')) {\n            tx = Lib.formatPercent(cdi.begR);\n            if(hasMultiplePercents) tx += ' of initial';\n            text.push(tx);\n        }\n        if(hasFlag('percent previous')) {\n            tx = Lib.formatPercent(cdi.difR);\n            if(hasMultiplePercents) tx += ' of previous';\n            text.push(tx);\n        }\n        if(hasFlag('percent total')) {\n            tx = Lib.formatPercent(cdi.sumR);\n            if(hasMultiplePercents) tx += ' of total';\n            text.push(tx);\n        }\n    }\n\n    return text.join('<br>');\n}\n\nmodule.exports = {\n    plot: plot,\n    getTransformToMoveInsideBar: getTransformToMoveInsideBar,\n    getTransformToMoveOutsideBar: getTransformToMoveOutsideBar\n};\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"./attributes\":857,\"./helpers\":862,\"./style\":870,\"d3\":163,\"fast-isnumeric\":225}],868:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function selectPoints(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var xa = searchInfo.xaxis;\n    var ya = searchInfo.yaxis;\n    var trace = cd[0].trace;\n    var isFunnel = (trace.type === 'funnel');\n    var isHorizontal = (trace.orientation === 'h');\n    var selection = [];\n    var i;\n\n    if(selectionTester === false) {\n        // clear selection\n        for(i = 0; i < cd.length; i++) {\n            cd[i].selected = 0;\n        }\n    } else {\n        for(i = 0; i < cd.length; i++) {\n            var di = cd[i];\n            var ct = 'ct' in di ? di.ct : getCentroid(di, xa, ya, isHorizontal, isFunnel);\n\n            if(selectionTester.contains(ct, false, i, searchInfo)) {\n                selection.push({\n                    pointNumber: i,\n                    x: xa.c2d(di.x),\n                    y: ya.c2d(di.y)\n                });\n                di.selected = 1;\n            } else {\n                di.selected = 0;\n            }\n        }\n    }\n\n    return selection;\n};\n\nfunction getCentroid(d, xa, ya, isHorizontal, isFunnel) {\n    var x0 = xa.c2p(isHorizontal ? d.s0 : d.p0, true);\n    var x1 = xa.c2p(isHorizontal ? d.s1 : d.p1, true);\n    var y0 = ya.c2p(isHorizontal ? d.p0 : d.s0, true);\n    var y1 = ya.c2p(isHorizontal ? d.p1 : d.s1, true);\n\n    if(isFunnel) {\n        return [(x0 + x1) / 2, (y0 + y1) / 2];\n    } else {\n        if(isHorizontal) {\n            return [x1, (y0 + y1) / 2];\n        } else {\n            return [(x0 + x1) / 2, y1];\n        }\n    }\n}\n\n},{}],869:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = Sieve;\n\nvar distinctVals = _dereq_('../../lib').distinctVals;\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\n/**\n * Helper class to sieve data from traces into bins\n *\n * @class\n *\n * @param {Array} traces\n*   Array of calculated traces\n * @param {object} opts\n *  - @param {boolean} [sepNegVal]\n *      If true, then split data at the same position into a bar\n *      for positive values and another for negative values\n *  - @param {boolean} [overlapNoMerge]\n *     If true, then don't merge overlapping bars into a single bar\n */\nfunction Sieve(traces, opts) {\n    this.traces = traces;\n    this.sepNegVal = opts.sepNegVal;\n    this.overlapNoMerge = opts.overlapNoMerge;\n\n    // for single-bin histograms - see histogram/calc\n    var width1 = Infinity;\n\n    var positions = [];\n    for(var i = 0; i < traces.length; i++) {\n        var trace = traces[i];\n        for(var j = 0; j < trace.length; j++) {\n            var bar = trace[j];\n            if(bar.p !== BADNUM) positions.push(bar.p);\n        }\n        if(trace[0] && trace[0].width1) {\n            width1 = Math.min(trace[0].width1, width1);\n        }\n    }\n    this.positions = positions;\n\n    var dv = distinctVals(positions);\n    this.distinctPositions = dv.vals;\n    if(dv.vals.length === 1 && width1 !== Infinity) this.minDiff = width1;\n    else this.minDiff = Math.min(dv.minDiff, width1);\n\n    this.binWidth = this.minDiff;\n\n    this.bins = {};\n}\n\n/**\n * Sieve datum\n *\n * @method\n * @param {number} position\n * @param {number} value\n * @returns {number} Previous bin value\n */\nSieve.prototype.put = function put(position, value) {\n    var label = this.getLabel(position, value);\n    var oldValue = this.bins[label] || 0;\n\n    this.bins[label] = oldValue + value;\n\n    return oldValue;\n};\n\n/**\n * Get current bin value for a given datum\n *\n * @method\n * @param {number} position  Position of datum\n * @param {number} [value]   Value of datum\n *                           (required if this.sepNegVal is true)\n * @returns {number} Current bin value\n */\nSieve.prototype.get = function get(position, value) {\n    var label = this.getLabel(position, value);\n    return this.bins[label] || 0;\n};\n\n/**\n * Get bin label for a given datum\n *\n * @method\n * @param {number} position  Position of datum\n * @param {number} [value]   Value of datum\n *                           (required if this.sepNegVal is true)\n * @returns {string} Bin label\n * (prefixed with a 'v' if value is negative and this.sepNegVal is\n * true; otherwise prefixed with '^')\n */\nSieve.prototype.getLabel = function getLabel(position, value) {\n    var prefix = (value < 0 && this.sepNegVal) ? 'v' : '^';\n    var label = (this.overlapNoMerge) ?\n        position :\n        Math.round(position / this.binWidth);\n    return prefix + label;\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719}],870:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\n\nvar attributes = _dereq_('./attributes');\nvar attributeTextFont = attributes.textfont;\nvar attributeInsideTextFont = attributes.insidetextfont;\nvar attributeOutsideTextFont = attributes.outsidetextfont;\nvar helpers = _dereq_('./helpers');\n\nfunction style(gd) {\n    var s = d3.select(gd).selectAll('g.barlayer').selectAll('g.trace');\n    var barcount = s.size();\n    var fullLayout = gd._fullLayout;\n\n    // trace styling\n    s.style('opacity', function(d) { return d[0].trace.opacity; })\n\n    // for gapless (either stacked or neighboring grouped) bars use\n    // crispEdges to turn off antialiasing so an artificial gap\n    // isn't introduced.\n    .each(function(d) {\n        if((fullLayout.barmode === 'stack' && barcount > 1) ||\n                (fullLayout.bargap === 0 &&\n                 fullLayout.bargroupgap === 0 &&\n                 !d[0].trace.marker.line.width)) {\n            d3.select(this).attr('shape-rendering', 'crispEdges');\n        }\n    });\n\n    s.selectAll('g.points').each(function(d) {\n        var sel = d3.select(this);\n        var trace = d[0].trace;\n        stylePoints(sel, trace, gd);\n    });\n\n    Registry.getComponentMethod('errorbars', 'style')(s);\n}\n\nfunction stylePoints(sel, trace, gd) {\n    Drawing.pointStyle(sel.selectAll('path'), trace, gd);\n    styleTextPoints(sel, trace, gd);\n}\n\nfunction styleTextPoints(sel, trace, gd) {\n    sel.selectAll('text').each(function(d) {\n        var tx = d3.select(this);\n        var font = determineFont(tx, d, trace, gd);\n        Drawing.font(tx, font);\n    });\n}\n\nfunction styleOnSelect(gd, cd, sel) {\n    var trace = cd[0].trace;\n\n    if(trace.selectedpoints) {\n        stylePointsInSelectionMode(sel, trace, gd);\n    } else {\n        stylePoints(sel, trace, gd);\n        Registry.getComponentMethod('errorbars', 'style')(sel);\n    }\n}\n\nfunction stylePointsInSelectionMode(s, trace, gd) {\n    Drawing.selectedPointStyle(s.selectAll('path'), trace);\n    styleTextInSelectionMode(s.selectAll('text'), trace, gd);\n}\n\nfunction styleTextInSelectionMode(txs, trace, gd) {\n    txs.each(function(d) {\n        var tx = d3.select(this);\n        var font;\n\n        if(d.selected) {\n            font = Lib.extendFlat({}, determineFont(tx, d, trace, gd));\n\n            var selectedFontColor = trace.selected.textfont && trace.selected.textfont.color;\n            if(selectedFontColor) {\n                font.color = selectedFontColor;\n            }\n\n            Drawing.font(tx, font);\n        } else {\n            Drawing.selectedTextStyle(tx, trace);\n        }\n    });\n}\n\nfunction determineFont(tx, d, trace, gd) {\n    var layoutFont = gd._fullLayout.font;\n    var textFont = trace.textfont;\n\n    if(tx.classed('bartext-inside')) {\n        var barColor = getBarColor(d, trace);\n        textFont = getInsideTextFont(trace, d.i, layoutFont, barColor);\n    } else if(tx.classed('bartext-outside')) {\n        textFont = getOutsideTextFont(trace, d.i, layoutFont);\n    }\n\n    return textFont;\n}\n\nfunction getTextFont(trace, index, defaultValue) {\n    return getFontValue(\n      attributeTextFont, trace.textfont, index, defaultValue);\n}\n\nfunction getInsideTextFont(trace, index, layoutFont, barColor) {\n    var defaultFont = getTextFont(trace, index, layoutFont);\n\n    var wouldFallBackToLayoutFont =\n      (trace._input.textfont === undefined || trace._input.textfont.color === undefined) ||\n      (Array.isArray(trace.textfont.color) && trace.textfont.color[index] === undefined);\n    if(wouldFallBackToLayoutFont) {\n        defaultFont = {\n            color: Color.contrast(barColor),\n            family: defaultFont.family,\n            size: defaultFont.size\n        };\n    }\n\n    return getFontValue(\n      attributeInsideTextFont, trace.insidetextfont, index, defaultFont);\n}\n\nfunction getOutsideTextFont(trace, index, layoutFont) {\n    var defaultFont = getTextFont(trace, index, layoutFont);\n    return getFontValue(\n      attributeOutsideTextFont, trace.outsidetextfont, index, defaultFont);\n}\n\nfunction getFontValue(attributeDefinition, attributeValue, index, defaultValue) {\n    attributeValue = attributeValue || {};\n\n    var familyValue = helpers.getValue(attributeValue.family, index);\n    var sizeValue = helpers.getValue(attributeValue.size, index);\n    var colorValue = helpers.getValue(attributeValue.color, index);\n\n    return {\n        family: helpers.coerceString(\n          attributeDefinition.family, familyValue, defaultValue.family),\n        size: helpers.coerceNumber(\n          attributeDefinition.size, sizeValue, defaultValue.size),\n        color: helpers.coerceColor(\n          attributeDefinition.color, colorValue, defaultValue.color)\n    };\n}\n\nfunction getBarColor(cd, trace) {\n    if(trace.type === 'waterfall') {\n        return trace[cd.dir].marker.color;\n    }\n    return cd.mc || trace.marker.color;\n}\n\nmodule.exports = {\n    style: style,\n    styleTextPoints: styleTextPoints,\n    styleOnSelect: styleOnSelect,\n    getInsideTextFont: getInsideTextFont,\n    getOutsideTextFont: getOutsideTextFont,\n    getBarColor: getBarColor\n};\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../lib\":719,\"../../registry\":847,\"./attributes\":857,\"./helpers\":862,\"d3\":163}],871:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Color = _dereq_('../../components/color');\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\n\nmodule.exports = function handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout) {\n    coerce('marker.color', defaultColor);\n\n    if(hasColorscale(traceIn, 'marker')) {\n        colorscaleDefaults(\n            traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}\n        );\n    }\n\n    coerce('marker.line.color', Color.defaultLine);\n\n    if(hasColorscale(traceIn, 'marker.line')) {\n        colorscaleDefaults(\n            traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}\n        );\n    }\n\n    coerce('marker.line.width');\n    coerce('marker.opacity');\n    coerce('selected.marker.color');\n    coerce('unselected.marker.color');\n};\n\n},{\"../../components/color\":593,\"../../components/colorscale/defaults\":603,\"../../components/colorscale/helpers\":604}],872:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar scatterPolarAttrs = _dereq_('../scatterpolar/attributes');\nvar barAttrs = _dereq_('../bar/attributes');\n\nmodule.exports = {\n    r: scatterPolarAttrs.r,\n    theta: scatterPolarAttrs.theta,\n    r0: scatterPolarAttrs.r0,\n    dr: scatterPolarAttrs.dr,\n    theta0: scatterPolarAttrs.theta0,\n    dtheta: scatterPolarAttrs.dtheta,\n    thetaunit: scatterPolarAttrs.thetaunit,\n\n    // orientation: {\n    //     valType: 'enumerated',\n    //     \n    //     values: ['radial', 'angular'],\n    //     editType: 'calc+clearAxisTypes',\n    //     \n    // },\n\n    base: extendFlat({}, barAttrs.base, {\n        \n    }),\n    offset: extendFlat({}, barAttrs.offset, {\n        \n    }),\n    width: extendFlat({}, barAttrs.width, {\n        \n    }),\n\n    text: extendFlat({}, barAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, barAttrs.hovertext, {\n        \n    }),\n\n    // textposition: {},\n    // textfont: {},\n    // insidetextfont: {},\n    // outsidetextfont: {},\n    // constraintext: {},\n    // cliponaxis: extendFlat({}, barAttrs.cliponaxis, {dflt: false}),\n\n    marker: barAttrs.marker,\n\n    hoverinfo: scatterPolarAttrs.hoverinfo,\n    hovertemplate: hovertemplateAttrs(),\n\n    selected: barAttrs.selected,\n    unselected: barAttrs.unselected\n\n    // error_x (error_r, error_theta)\n    // error_y\n};\n\n},{\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../bar/attributes\":857,\"../scatterpolar/attributes\":1179}],873:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\nvar arraysToCalcdata = _dereq_('../bar/arrays_to_calcdata');\nvar setGroupPositions = _dereq_('../bar/cross_trace_calc').setGroupPositions;\nvar calcSelection = _dereq_('../scatter/calc_selection');\nvar traceIs = _dereq_('../../registry').traceIs;\nvar extendFlat = _dereq_('../../lib').extendFlat;\n\nfunction calc(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var subplotId = trace.subplot;\n    var radialAxis = fullLayout[subplotId].radialaxis;\n    var angularAxis = fullLayout[subplotId].angularaxis;\n    var rArray = radialAxis.makeCalcdata(trace, 'r');\n    var thetaArray = angularAxis.makeCalcdata(trace, 'theta');\n    var len = trace._length;\n    var cd = new Array(len);\n\n    // 'size' axis variables\n    var sArray = rArray;\n    // 'pos' axis variables\n    var pArray = thetaArray;\n\n    for(var i = 0; i < len; i++) {\n        cd[i] = {p: pArray[i], s: sArray[i]};\n    }\n\n    // convert width and offset in 'c' coordinate,\n    // set 'c' value(s) in trace._width and trace._offset,\n    // to make Bar.crossTraceCalc \"just work\"\n    function d2c(attr) {\n        var val = trace[attr];\n        if(val !== undefined) {\n            trace['_' + attr] = Array.isArray(val) ?\n                angularAxis.makeCalcdata(trace, attr) :\n                angularAxis.d2c(val, trace.thetaunit);\n        }\n    }\n\n    if(angularAxis.type === 'linear') {\n        d2c('width');\n        d2c('offset');\n    }\n\n    if(hasColorscale(trace, 'marker')) {\n        colorscaleCalc(gd, trace, {\n            vals: trace.marker.color,\n            containerStr: 'marker',\n            cLetter: 'c'\n        });\n    }\n    if(hasColorscale(trace, 'marker.line')) {\n        colorscaleCalc(gd, trace, {\n            vals: trace.marker.line.color,\n            containerStr: 'marker.line',\n            cLetter: 'c'\n        });\n    }\n\n    arraysToCalcdata(cd, trace);\n    calcSelection(cd, trace);\n\n    return cd;\n}\n\nfunction crossTraceCalc(gd, polarLayout, subplotId) {\n    var calcdata = gd.calcdata;\n    var barPolarCd = [];\n\n    for(var i = 0; i < calcdata.length; i++) {\n        var cdi = calcdata[i];\n        var trace = cdi[0].trace;\n\n        if(trace.visible === true && traceIs(trace, 'bar') &&\n            trace.subplot === subplotId\n        ) {\n            barPolarCd.push(cdi);\n        }\n    }\n\n    // to make _extremes is filled in correctly so that\n    // polar._subplot.radialAxis can get auotrange'd\n    // TODO clean up!\n    // I think we want to call getAutorange on polar.radialaxis\n    // NOT on polar._subplot.radialAxis\n    var rAxis = extendFlat({}, polarLayout.radialaxis, {_id: 'x'});\n    var aAxis = polarLayout.angularaxis;\n\n    setGroupPositions(gd, aAxis, rAxis, barPolarCd, {\n        mode: polarLayout.barmode,\n        norm: polarLayout.barnorm,\n        gap: polarLayout.bargap,\n        groupgap: polarLayout.bargroupgap\n    });\n}\n\nmodule.exports = {\n    calc: calc,\n    crossTraceCalc: crossTraceCalc\n};\n\n},{\"../../components/colorscale/calc\":601,\"../../components/colorscale/helpers\":604,\"../../lib\":719,\"../../registry\":847,\"../bar/arrays_to_calcdata\":856,\"../bar/cross_trace_calc\":860,\"../scatter/calc_selection\":1114}],874:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleRThetaDefaults = _dereq_('../scatterpolar/defaults').handleRThetaDefaults;\nvar handleStyleDefaults = _dereq_('../bar/style_defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleRThetaDefaults(traceIn, traceOut, layout, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    // coerce('orientation', (traceOut.theta && !traceOut.r) ? 'angular' : 'radial');\n\n    coerce('thetaunit');\n    coerce('base');\n    coerce('offset');\n    coerce('width');\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    // var textPosition = coerce('textposition');\n    // var hasBoth = Array.isArray(textPosition) || textPosition === 'auto';\n    // var hasInside = hasBoth || textPosition === 'inside';\n    // var hasOutside = hasBoth || textPosition === 'outside';\n\n    // if(hasInside || hasOutside) {\n    //     var textFont = coerceFont(coerce, 'textfont', layout.font);\n    //     if(hasInside) coerceFont(coerce, 'insidetextfont', textFont);\n    //     if(hasOutside) coerceFont(coerce, 'outsidetextfont', textFont);\n    //     coerce('constraintext');\n    //     coerce('selected.textfont.color');\n    //     coerce('unselected.textfont.color');\n    //     coerce('cliponaxis');\n    // }\n\n    handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\n},{\"../../lib\":719,\"../bar/style_defaults\":871,\"../scatterpolar/defaults\":1181,\"./attributes\":872}],875:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Fx = _dereq_('../../components/fx');\nvar Lib = _dereq_('../../lib');\nvar getTraceColor = _dereq_('../bar/hover').getTraceColor;\nvar fillText = Lib.fillText;\nvar makeHoverPointText = _dereq_('../scatterpolar/hover').makeHoverPointText;\nvar isPtInsidePolygon = _dereq_('../../plots/polar/helpers').isPtInsidePolygon;\n\nmodule.exports = function hoverPoints(pointData, xval, yval) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n\n    var subplot = pointData.subplot;\n    var radialAxis = subplot.radialAxis;\n    var angularAxis = subplot.angularAxis;\n    var vangles = subplot.vangles;\n    var inboxFn = vangles ? isPtInsidePolygon : Lib.isPtInsideSector;\n    var maxHoverDistance = pointData.maxHoverDistance;\n    var period = angularAxis._period || 2 * Math.PI;\n\n    var rVal = Math.abs(radialAxis.g2p(Math.sqrt(xval * xval + yval * yval)));\n    var thetaVal = Math.atan2(yval, xval);\n\n    // polar.(x|y)axis.p2c doesn't get the reversed radial axis range case right\n    if(radialAxis.range[0] > radialAxis.range[1]) {\n        thetaVal += Math.PI;\n    }\n\n    var distFn = function(di) {\n        if(inboxFn(rVal, thetaVal, [di.rp0, di.rp1], [di.thetag0, di.thetag1], vangles)) {\n            return maxHoverDistance +\n                // add a little to the pseudo-distance for wider bars, so that like scatter,\n                // if you are over two overlapping bars, the narrower one wins.\n                Math.min(1, Math.abs(di.thetag1 - di.thetag0) / period) - 1 +\n                // add a gradient so hovering near the end of a\n                // bar makes it a little closer match\n                (di.rp1 - rVal) / (di.rp1 - di.rp0) - 1;\n        } else {\n            return Infinity;\n        }\n    };\n\n    Fx.getClosest(cd, distFn, pointData);\n    if(pointData.index === false) return;\n\n    var index = pointData.index;\n    var cdi = cd[index];\n\n    pointData.x0 = pointData.x1 = cdi.ct[0];\n    pointData.y0 = pointData.y1 = cdi.ct[1];\n\n    var _cdi = Lib.extendFlat({}, cdi, {r: cdi.s, theta: cdi.p});\n    fillText(cdi, trace, pointData);\n    makeHoverPointText(_cdi, trace, subplot, pointData);\n    pointData.hovertemplate = trace.hovertemplate;\n    pointData.color = getTraceColor(trace, cdi);\n    pointData.xLabelVal = pointData.yLabelVal = undefined;\n\n    if(cdi.s < 0) {\n        pointData.idealAlign = 'left';\n    }\n\n    return [pointData];\n};\n\n},{\"../../components/fx\":632,\"../../lib\":719,\"../../plots/polar/helpers\":830,\"../bar/hover\":863,\"../scatterpolar/hover\":1182}],876:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'barpolar',\n    basePlotModule: _dereq_('../../plots/polar'),\n    categories: ['polar', 'bar', 'showLegend'],\n\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n\n    calc: _dereq_('./calc').calc,\n    crossTraceCalc: _dereq_('./calc').crossTraceCalc,\n\n    plot: _dereq_('./plot'),\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n\n    style: _dereq_('../bar/style').style,\n    styleOnSelect: _dereq_('../bar/style').styleOnSelect,\n\n    hoverPoints: _dereq_('./hover'),\n    selectPoints: _dereq_('../bar/select'),\n\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/polar\":831,\"../bar/select\":868,\"../bar/style\":870,\"../scatter/marker_colorbar\":1129,\"./attributes\":872,\"./calc\":873,\"./defaults\":874,\"./hover\":875,\"./layout_attributes\":877,\"./layout_defaults\":878,\"./plot\":879}],877:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    barmode: {\n        valType: 'enumerated',\n        values: ['stack', 'overlay'],\n        dflt: 'stack',\n        \n        editType: 'calc',\n        \n    },\n    bargap: {\n        valType: 'number',\n        dflt: 0.1,\n        min: 0,\n        max: 1,\n        \n        editType: 'calc',\n        \n    }\n};\n\n},{}],878:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attrs = _dereq_('./layout_attributes');\n\nmodule.exports = function(layoutIn, layoutOut, fullData) {\n    var subplotsDone = {};\n    var sp;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn[sp] || {}, layoutOut[sp], attrs, attr, dflt);\n    }\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n        if(trace.type === 'barpolar' && trace.visible === true) {\n            sp = trace.subplot;\n            if(!subplotsDone[sp]) {\n                coerce('barmode');\n                coerce('bargap');\n                subplotsDone[sp] = 1;\n            }\n        }\n    }\n};\n\n},{\"../../lib\":719,\"./layout_attributes\":877}],879:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../../components/drawing');\nvar helpers = _dereq_('../../plots/polar/helpers');\n\nmodule.exports = function plot(gd, subplot, cdbar) {\n    var xa = subplot.xaxis;\n    var ya = subplot.yaxis;\n    var radialAxis = subplot.radialAxis;\n    var angularAxis = subplot.angularAxis;\n    var pathFn = makePathFn(subplot);\n    var barLayer = subplot.layers.frontplot.select('g.barlayer');\n\n    Lib.makeTraceGroups(barLayer, cdbar, 'trace bars').each(function() {\n        var plotGroup = d3.select(this);\n        var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');\n        var bars = pointGroup.selectAll('g.point').data(Lib.identity);\n\n        bars.enter().append('g')\n            .style('vector-effect', 'non-scaling-stroke')\n            .style('stroke-miterlimit', 2)\n            .classed('point', true);\n\n        bars.exit().remove();\n\n        bars.each(function(di) {\n            var bar = d3.select(this);\n\n            var rp0 = di.rp0 = radialAxis.c2p(di.s0);\n            var rp1 = di.rp1 = radialAxis.c2p(di.s1);\n            var thetag0 = di.thetag0 = angularAxis.c2g(di.p0);\n            var thetag1 = di.thetag1 = angularAxis.c2g(di.p1);\n\n            var dPath;\n\n            if(!isNumeric(rp0) || !isNumeric(rp1) ||\n                !isNumeric(thetag0) || !isNumeric(thetag1) ||\n                rp0 === rp1 || thetag0 === thetag1\n            ) {\n                // do not remove blank bars, to keep data-to-node\n                // mapping intact during radial drag, that we\n                // can skip calling _module.style during interactions\n                dPath = 'M0,0Z';\n            } else {\n                // this 'center' pt is used for selections and hover labels\n                var rg1 = radialAxis.c2g(di.s1);\n                var thetagMid = (thetag0 + thetag1) / 2;\n                di.ct = [\n                    xa.c2p(rg1 * Math.cos(thetagMid)),\n                    ya.c2p(rg1 * Math.sin(thetagMid))\n                ];\n\n                dPath = pathFn(rp0, rp1, thetag0, thetag1);\n            }\n\n            Lib.ensureSingle(bar, 'path').attr('d', dPath);\n        });\n\n        // clip plotGroup, when trace layer isn't clipped\n        Drawing.setClipUrl(\n            plotGroup,\n            subplot._hasClipOnAxisFalse ? subplot.clipIds.forTraces : null,\n            gd\n        );\n    });\n};\n\nfunction makePathFn(subplot) {\n    var cxx = subplot.cxx;\n    var cyy = subplot.cyy;\n\n    if(subplot.vangles) {\n        return function(r0, r1, _a0, _a1) {\n            var a0, a1;\n\n            if(Lib.angleDelta(_a0, _a1) > 0) {\n                a0 = _a0;\n                a1 = _a1;\n            } else {\n                a0 = _a1;\n                a1 = _a0;\n            }\n\n            var va0 = helpers.findEnclosingVertexAngles(a0, subplot.vangles)[0];\n            var va1 = helpers.findEnclosingVertexAngles(a1, subplot.vangles)[1];\n            var vaBar = [va0, (a0 + a1) / 2, va1];\n            return helpers.pathPolygonAnnulus(r0, r1, a0, a1, vaBar, cxx, cyy);\n        };\n    }\n\n    return function(r0, r1, a0, a1) {\n        return Lib.pathAnnulus(r0, r1, a0, a1, cxx, cyy);\n    };\n}\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../../plots/polar/helpers\":830,\"d3\":163,\"fast-isnumeric\":225}],880:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar barAttrs = _dereq_('../bar/attributes');\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar scatterMarkerLineAttrs = scatterMarkerAttrs.line;\n\nmodule.exports = {\n    y: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n    x: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n    x0: {\n        valType: 'any',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    y0: {\n        valType: 'any',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    name: {\n        valType: 'string',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    text: extendFlat({}, scatterAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, scatterAttrs.hovertext, {\n        \n    }),\n    hovertemplate: hovertemplateAttrs({\n        \n    }),\n    whiskerwidth: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 0.5,\n        \n        editType: 'calc',\n        \n    },\n    notched: {\n        valType: 'boolean',\n        \n        editType: 'calc',\n        \n    },\n    notchwidth: {\n        valType: 'number',\n        min: 0,\n        max: 0.5,\n        dflt: 0.25,\n        \n        editType: 'calc',\n        \n    },\n    boxpoints: {\n        valType: 'enumerated',\n        values: ['all', 'outliers', 'suspectedoutliers', false],\n        dflt: 'outliers',\n        \n        editType: 'calc',\n        \n    },\n    boxmean: {\n        valType: 'enumerated',\n        values: [true, 'sd', false],\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    jitter: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        \n        editType: 'calc',\n        \n    },\n    pointpos: {\n        valType: 'number',\n        min: -2,\n        max: 2,\n        \n        editType: 'calc',\n        \n    },\n    orientation: {\n        valType: 'enumerated',\n        values: ['v', 'h'],\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    width: {\n        valType: 'number',\n        min: 0,\n        \n        dflt: 0,\n        editType: 'calc',\n        \n    },\n\n    marker: {\n        outliercolor: {\n            valType: 'color',\n            dflt: 'rgba(0, 0, 0, 0)',\n            \n            editType: 'style',\n            \n        },\n        symbol: extendFlat({}, scatterMarkerAttrs.symbol,\n            {arrayOk: false, editType: 'plot'}),\n        opacity: extendFlat({}, scatterMarkerAttrs.opacity,\n            {arrayOk: false, dflt: 1, editType: 'style'}),\n        size: extendFlat({}, scatterMarkerAttrs.size,\n            {arrayOk: false, editType: 'calc'}),\n        color: extendFlat({}, scatterMarkerAttrs.color,\n            {arrayOk: false, editType: 'style'}),\n        line: {\n            color: extendFlat({}, scatterMarkerLineAttrs.color,\n                {arrayOk: false, dflt: colorAttrs.defaultLine, editType: 'style'}\n            ),\n            width: extendFlat({}, scatterMarkerLineAttrs.width,\n                {arrayOk: false, dflt: 0, editType: 'style'}\n            ),\n            outliercolor: {\n                valType: 'color',\n                \n                editType: 'style',\n                \n            },\n            outlierwidth: {\n                valType: 'number',\n                min: 0,\n                dflt: 1,\n                \n                editType: 'style',\n                \n            },\n            editType: 'style'\n        },\n        editType: 'plot'\n    },\n    line: {\n        color: {\n            valType: 'color',\n            \n            editType: 'style',\n            \n        },\n        width: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 2,\n            editType: 'style',\n            \n        },\n        editType: 'plot'\n    },\n    fillcolor: scatterAttrs.fillcolor,\n\n    offsetgroup: barAttrs.offsetgroup,\n    alignmentgroup: barAttrs.alignmentgroup,\n\n    selected: {\n        marker: scatterAttrs.selected.marker,\n        editType: 'style'\n    },\n    unselected: {\n        marker: scatterAttrs.unselected.marker,\n        editType: 'style'\n    },\n    hoveron: {\n        valType: 'flaglist',\n        flags: ['boxes', 'points'],\n        dflt: 'boxes+points',\n        \n        editType: 'style',\n        \n    }\n};\n\n},{\"../../components/color/attributes\":592,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../bar/attributes\":857,\"../scatter/attributes\":1112}],881:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar _ = Lib._;\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\n// outlier definition based on http://www.physics.csbsju.edu/stats/box2.html\nmodule.exports = function calc(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var xa = Axes.getFromId(gd, trace.xaxis || 'x');\n    var ya = Axes.getFromId(gd, trace.yaxis || 'y');\n    var cd = [];\n\n    // N.B. violin reuses same Box.calc\n    var numKey = trace.type === 'violin' ? '_numViolins' : '_numBoxes';\n\n    var i;\n    var valAxis, valLetter;\n    var posAxis, posLetter;\n\n    if(trace.orientation === 'h') {\n        valAxis = xa;\n        valLetter = 'x';\n        posAxis = ya;\n        posLetter = 'y';\n    } else {\n        valAxis = ya;\n        valLetter = 'y';\n        posAxis = xa;\n        posLetter = 'x';\n    }\n\n    var val = valAxis.makeCalcdata(trace, valLetter);\n    var pos = getPos(trace, posLetter, posAxis, val, fullLayout[numKey]);\n\n    var dv = Lib.distinctVals(pos);\n    var posDistinct = dv.vals;\n    var dPos = dv.minDiff / 2;\n    var posBins = makeBins(posDistinct, dPos);\n\n    var pLen = posDistinct.length;\n    var ptsPerBin = initNestedArray(pLen);\n\n    // bin pts info per position bins\n    for(i = 0; i < trace._length; i++) {\n        var v = val[i];\n        if(!isNumeric(v)) continue;\n\n        var n = Lib.findBin(pos[i], posBins);\n        if(n >= 0 && n < pLen) {\n            var pt = {v: v, i: i};\n            arraysToCalcdata(pt, trace, i);\n            ptsPerBin[n].push(pt);\n        }\n    }\n\n    var cdi;\n    var ptFilterFn = (trace.boxpoints || trace.points) === 'all' ?\n        Lib.identity :\n        function(pt) { return (pt.v < cdi.lf || pt.v > cdi.uf); };\n\n    // build calcdata trace items, one item per distinct position\n    for(i = 0; i < pLen; i++) {\n        if(ptsPerBin[i].length > 0) {\n            var pts = ptsPerBin[i].sort(sortByVal);\n            var boxVals = pts.map(extractVal);\n            var bvLen = boxVals.length;\n\n            cdi = {};\n            cdi.pos = posDistinct[i];\n            cdi.pts = pts;\n\n            // Sort categories by values\n            cdi[posLetter] = cdi.pos;\n            cdi[valLetter] = cdi.pts.map(function(pt) { return pt.v; });\n\n            cdi.min = boxVals[0];\n            cdi.max = boxVals[bvLen - 1];\n            cdi.mean = Lib.mean(boxVals, bvLen);\n            cdi.sd = Lib.stdev(boxVals, bvLen, cdi.mean);\n\n            // first quartile\n            cdi.q1 = Lib.interp(boxVals, 0.25);\n             // median\n            cdi.med = Lib.interp(boxVals, 0.5);\n            // third quartile\n            cdi.q3 = Lib.interp(boxVals, 0.75);\n\n            // lower and upper fences - last point inside\n            // 1.5 interquartile ranges from quartiles\n            cdi.lf = Math.min(\n                cdi.q1,\n                boxVals[Math.min(\n                    Lib.findBin(2.5 * cdi.q1 - 1.5 * cdi.q3, boxVals, true) + 1,\n                    bvLen - 1\n                )]\n            );\n            cdi.uf = Math.max(\n                cdi.q3,\n                boxVals[Math.max(\n                    Lib.findBin(2.5 * cdi.q3 - 1.5 * cdi.q1, boxVals),\n                    0\n                )]\n            );\n\n            // lower and upper outliers - 3 IQR out (don't clip to max/min,\n            // this is only for discriminating suspected & far outliers)\n            cdi.lo = 4 * cdi.q1 - 3 * cdi.q3;\n            cdi.uo = 4 * cdi.q3 - 3 * cdi.q1;\n\n            // lower and upper notches ~95% Confidence Intervals for median\n            var iqr = cdi.q3 - cdi.q1;\n            var mci = 1.57 * iqr / Math.sqrt(bvLen);\n            cdi.ln = cdi.med - mci;\n            cdi.un = cdi.med + mci;\n\n            cdi.pts2 = pts.filter(ptFilterFn);\n\n            cd.push(cdi);\n        }\n    }\n\n    calcSelection(cd, trace);\n    var extremes = Axes.findExtremes(valAxis, val, {padded: true});\n    trace._extremes[valAxis._id] = extremes;\n\n    if(cd.length > 0) {\n        cd[0].t = {\n            num: fullLayout[numKey],\n            dPos: dPos,\n            posLetter: posLetter,\n            valLetter: valLetter,\n            labels: {\n                med: _(gd, 'median:'),\n                min: _(gd, 'min:'),\n                q1: _(gd, 'q1:'),\n                q3: _(gd, 'q3:'),\n                max: _(gd, 'max:'),\n                mean: trace.boxmean === 'sd' ? _(gd, 'mean ± σ:') : _(gd, 'mean:'),\n                lf: _(gd, 'lower fence:'),\n                uf: _(gd, 'upper fence:')\n            }\n        };\n\n        fullLayout[numKey]++;\n        return cd;\n    } else {\n        return [{t: {empty: true}}];\n    }\n};\n\n// In vertical (horizontal) box plots:\n// if no x (y) data, use x0 (y0), or name\n// so if you want one box\n// per trace, set x0 (y0) to the x (y) value or category for this trace\n// (or set x (y) to a constant array matching y (x))\nfunction getPos(trace, posLetter, posAxis, val, num) {\n    if(posLetter in trace) {\n        return posAxis.makeCalcdata(trace, posLetter);\n    }\n\n    var pos0;\n\n    if(posLetter + '0' in trace) {\n        pos0 = trace[posLetter + '0'];\n    } else if('name' in trace && (\n        posAxis.type === 'category' || (\n            isNumeric(trace.name) &&\n            ['linear', 'log'].indexOf(posAxis.type) !== -1\n        ) || (\n            Lib.isDateTime(trace.name) &&\n            posAxis.type === 'date'\n        )\n    )) {\n        pos0 = trace.name;\n    } else {\n        pos0 = num;\n    }\n\n    var pos0c = posAxis.type === 'multicategory' ?\n        posAxis.r2c_just_indices(pos0) :\n        posAxis.d2c(pos0, 0, trace[posLetter + 'calendar']);\n\n    return val.map(function() { return pos0c; });\n}\n\nfunction makeBins(x, dx) {\n    var len = x.length;\n    var bins = new Array(len + 1);\n\n    for(var i = 0; i < len; i++) {\n        bins[i] = x[i] - dx;\n    }\n    bins[len] = x[len - 1] + dx;\n\n    return bins;\n}\n\nfunction initNestedArray(len) {\n    var arr = new Array(len);\n    for(var i = 0; i < len; i++) {\n        arr[i] = [];\n    }\n    return arr;\n}\n\nfunction arraysToCalcdata(pt, trace, i) {\n    var trace2calc = {\n        text: 'tx',\n        hovertext: 'htx'\n    };\n\n    for(var k in trace2calc) {\n        if(Array.isArray(trace[k])) {\n            pt[trace2calc[k]] = trace[k][i];\n        }\n    }\n}\n\nfunction calcSelection(cd, trace) {\n    if(Lib.isArrayOrTypedArray(trace.selectedpoints)) {\n        for(var i = 0; i < cd.length; i++) {\n            var pts = cd[i].pts || [];\n            var ptNumber2cdIndex = {};\n\n            for(var j = 0; j < pts.length; j++) {\n                ptNumber2cdIndex[pts[j].i] = j;\n            }\n\n            Lib.tagSelected(pts, trace, ptNumber2cdIndex);\n        }\n    }\n}\n\nfunction sortByVal(a, b) { return a.v - b.v; }\n\nfunction extractVal(o) { return o.v; }\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"fast-isnumeric\":225}],882:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Lib = _dereq_('../../lib');\nvar getAxisGroup = _dereq_('../../plots/cartesian/axis_ids').getAxisGroup;\n\nvar orientations = ['v', 'h'];\n\nfunction crossTraceCalc(gd, plotinfo) {\n    var calcdata = gd.calcdata;\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    for(var i = 0; i < orientations.length; i++) {\n        var orientation = orientations[i];\n        var posAxis = orientation === 'h' ? ya : xa;\n        var boxList = [];\n\n        // make list of boxes / candlesticks\n        // For backward compatibility, candlesticks are treated as if they *are* box traces here\n        for(var j = 0; j < calcdata.length; j++) {\n            var cd = calcdata[j];\n            var t = cd[0].t;\n            var trace = cd[0].trace;\n\n            if(trace.visible === true &&\n                    (trace.type === 'box' || trace.type === 'candlestick') &&\n                    !t.empty &&\n                    (trace.orientation || 'v') === orientation &&\n                    trace.xaxis === xa._id &&\n                    trace.yaxis === ya._id\n              ) {\n                boxList.push(j);\n            }\n        }\n\n        setPositionOffset('box', gd, boxList, posAxis);\n    }\n}\n\nfunction setPositionOffset(traceType, gd, boxList, posAxis) {\n    var calcdata = gd.calcdata;\n    var fullLayout = gd._fullLayout;\n    var axId = posAxis._id;\n    var axLetter = axId.charAt(0);\n\n    var i, j, calcTrace;\n    var pointList = [];\n    var shownPts = 0;\n\n    // make list of box points\n    for(i = 0; i < boxList.length; i++) {\n        calcTrace = calcdata[boxList[i]];\n        for(j = 0; j < calcTrace.length; j++) {\n            pointList.push(calcTrace[j].pos);\n            shownPts += (calcTrace[j].pts2 || []).length;\n        }\n    }\n\n    if(!pointList.length) return;\n\n    // box plots - update dPos based on multiple traces\n    var boxdv = Lib.distinctVals(pointList);\n    var dPos0 = boxdv.minDiff / 2;\n\n    // check for forced minimum dtick\n    Axes.minDtick(posAxis, boxdv.minDiff, boxdv.vals[0], true);\n\n    var numKey = traceType === 'violin' ? '_numViolins' : '_numBoxes';\n    var numTotal = fullLayout[numKey];\n    var group = fullLayout[traceType + 'mode'] === 'group' && numTotal > 1;\n    var groupFraction = 1 - fullLayout[traceType + 'gap'];\n    var groupGapFraction = 1 - fullLayout[traceType + 'groupgap'];\n\n    for(i = 0; i < boxList.length; i++) {\n        calcTrace = calcdata[boxList[i]];\n\n        var trace = calcTrace[0].trace;\n        var t = calcTrace[0].t;\n        var width = trace.width;\n        var side = trace.side;\n\n        // position coordinate delta\n        var dPos;\n        // box half width;\n        var bdPos;\n        // box center offset\n        var bPos;\n        // half-width within which to accept hover for this box/violin\n        // always split the distance to the closest box/violin\n        var wHover;\n\n        if(width) {\n            dPos = bdPos = wHover = width / 2;\n            bPos = 0;\n        } else {\n            dPos = dPos0;\n\n            if(group) {\n                var groupId = getAxisGroup(fullLayout, posAxis._id) + trace.orientation;\n                var alignmentGroups = fullLayout._alignmentOpts[groupId] || {};\n                var alignmentGroupOpts = alignmentGroups[trace.alignmentgroup] || {};\n                var nOffsetGroups = Object.keys(alignmentGroupOpts.offsetGroups || {}).length;\n                var num = nOffsetGroups || numTotal;\n                var shift = nOffsetGroups ? trace._offsetIndex : t.num;\n\n                bdPos = dPos * groupFraction * groupGapFraction / num;\n                bPos = 2 * dPos * (-0.5 + (shift + 0.5) / num) * groupFraction;\n                wHover = dPos * groupFraction / num;\n            } else {\n                bdPos = dPos * groupFraction * groupGapFraction;\n                bPos = 0;\n                wHover = dPos;\n            }\n        }\n        t.dPos = dPos;\n        t.bPos = bPos;\n        t.bdPos = bdPos;\n        t.wHover = wHover;\n\n        // box/violin-only value-space push value\n        var pushplus;\n        var pushminus;\n        // edge of box/violin\n        var edge = bPos + bdPos;\n        var edgeplus;\n        var edgeminus;\n        // value-space padding\n        var vpadplus;\n        var vpadminus;\n        // pixel-space padding\n        var ppadplus;\n        var ppadminus;\n        // do we add 5% of both sides (more logic for points beyond box/violin below)\n        var padded = Boolean(width);\n        // does this trace show points?\n        var hasPts = (trace.boxpoints || trace.points) && (shownPts > 0);\n\n        if(side === 'positive') {\n            pushplus = dPos * (width ? 1 : 0.5);\n            edgeplus = edge;\n            pushminus = edgeplus = bPos;\n        } else if(side === 'negative') {\n            pushplus = edgeplus = bPos;\n            pushminus = dPos * (width ? 1 : 0.5);\n            edgeminus = edge;\n        } else {\n            pushplus = pushminus = dPos;\n            edgeplus = edgeminus = edge;\n        }\n\n        if(hasPts) {\n            var pointpos = trace.pointpos;\n            var jitter = trace.jitter;\n            var ms = trace.marker.size / 2;\n\n            var pp = 0;\n            if((pointpos + jitter) >= 0) {\n                pp = edge * (pointpos + jitter);\n                if(pp > pushplus) {\n                    // (++) beyond plus-value, use pp\n                    padded = true;\n                    ppadplus = ms;\n                    vpadplus = pp;\n                } else if(pp > edgeplus) {\n                    // (+), use push-value (it's bigger), but add px-pad\n                    ppadplus = ms;\n                    vpadplus = pushplus;\n                }\n            }\n            if(pp <= pushplus) {\n                // (->) fallback to push value\n                vpadplus = pushplus;\n            }\n\n            var pm = 0;\n            if((pointpos - jitter) <= 0) {\n                pm = -edge * (pointpos - jitter);\n                if(pm > pushminus) {\n                    // (--) beyond plus-value, use pp\n                    padded = true;\n                    ppadminus = ms;\n                    vpadminus = pm;\n                } else if(pm > edgeminus) {\n                    // (-), use push-value (it's bigger), but add px-pad\n                    ppadminus = ms;\n                    vpadminus = pushminus;\n                }\n            }\n            if(pm <= pushminus) {\n                // (<-) fallback to push value\n                vpadminus = pushminus;\n            }\n        } else {\n            vpadplus = pushplus;\n            vpadminus = pushminus;\n        }\n\n        var pos = new Array(calcTrace.length);\n        for(j = 0; j < calcTrace.length; j++) {\n            pos[j] = calcTrace[j].pos;\n        }\n\n        trace._extremes[axId] = Axes.findExtremes(posAxis, pos, {\n            padded: padded,\n            vpadminus: vpadminus,\n            vpadplus: vpadplus,\n            // N.B. SVG px-space positive/negative\n            ppadminus: {x: ppadminus, y: ppadplus}[axLetter],\n            ppadplus: {x: ppadplus, y: ppadminus}[axLetter],\n        });\n    }\n}\n\nmodule.exports = {\n    crossTraceCalc: crossTraceCalc,\n    setPositionOffset: setPositionOffset\n};\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../../plots/cartesian/axis_ids\":770}],883:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\nvar Color = _dereq_('../../components/color');\nvar handleGroupingDefaults = _dereq_('../bar/defaults').handleGroupingDefaults;\nvar attributes = _dereq_('./attributes');\n\nfunction supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    handleSampleDefaults(traceIn, traceOut, coerce, layout);\n    if(traceOut.visible === false) return;\n\n    coerce('line.color', (traceIn.marker || {}).color || defaultColor);\n    coerce('line.width');\n    coerce('fillcolor', Color.addOpacity(traceOut.line.color, 0.5));\n\n    coerce('whiskerwidth');\n    coerce('boxmean');\n    coerce('width');\n\n    var notched = coerce('notched', traceIn.notchwidth !== undefined);\n    if(notched) coerce('notchwidth');\n\n    handlePointsDefaults(traceIn, traceOut, coerce, {prefix: 'box'});\n}\n\nfunction handleSampleDefaults(traceIn, traceOut, coerce, layout) {\n    var y = coerce('y');\n    var x = coerce('x');\n    var hasX = x && x.length;\n\n    var defaultOrientation, len;\n\n    if(y && y.length) {\n        defaultOrientation = 'v';\n        if(hasX) {\n            len = Math.min(Lib.minRowLength(x), Lib.minRowLength(y));\n        } else {\n            coerce('x0');\n            len = Lib.minRowLength(y);\n        }\n    } else if(hasX) {\n        defaultOrientation = 'h';\n        coerce('y0');\n        len = Lib.minRowLength(x);\n    } else {\n        traceOut.visible = false;\n        return;\n    }\n    traceOut._length = len;\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);\n\n    coerce('orientation', defaultOrientation);\n}\n\nfunction handlePointsDefaults(traceIn, traceOut, coerce, opts) {\n    var prefix = opts.prefix;\n\n    var outlierColorDflt = Lib.coerce2(traceIn, traceOut, attributes, 'marker.outliercolor');\n    var lineoutliercolor = coerce('marker.line.outliercolor');\n\n    var points = coerce(\n        prefix + 'points',\n        (outlierColorDflt || lineoutliercolor) ? 'suspectedoutliers' : undefined\n    );\n\n    if(points) {\n        coerce('jitter', points === 'all' ? 0.3 : 0);\n        coerce('pointpos', points === 'all' ? -1.5 : 0);\n\n        coerce('marker.symbol');\n        coerce('marker.opacity');\n        coerce('marker.size');\n        coerce('marker.color', traceOut.line.color);\n        coerce('marker.line.color');\n        coerce('marker.line.width');\n\n        if(points === 'suspectedoutliers') {\n            coerce('marker.line.outliercolor', traceOut.marker.color);\n            coerce('marker.line.outlierwidth');\n        }\n\n        coerce('selected.marker.color');\n        coerce('unselected.marker.color');\n        coerce('selected.marker.size');\n        coerce('unselected.marker.size');\n\n        coerce('text');\n        coerce('hovertext');\n    } else {\n        delete traceOut.marker;\n    }\n\n    var hoveron = coerce('hoveron');\n    if(hoveron === 'all' || hoveron.indexOf('points') !== -1) {\n        coerce('hovertemplate');\n    }\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n}\n\nfunction crossTraceDefaults(fullData, fullLayout) {\n    var traceIn, traceOut;\n\n    function coerce(attr) {\n        return Lib.coerce(traceOut._input, traceOut, attributes, attr);\n    }\n\n    for(var i = 0; i < fullData.length; i++) {\n        traceOut = fullData[i];\n        var traceType = traceOut.type;\n\n        if(traceType === 'box' || traceType === 'violin') {\n            traceIn = traceOut._input;\n            if(fullLayout[traceType + 'mode'] === 'group') {\n                handleGroupingDefaults(traceIn, traceOut, fullLayout, coerce);\n            }\n        }\n    }\n}\n\nmodule.exports = {\n    supplyDefaults: supplyDefaults,\n    crossTraceDefaults: crossTraceDefaults,\n\n    handleSampleDefaults: handleSampleDefaults,\n    handlePointsDefaults: handlePointsDefaults\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../../registry\":847,\"../bar/defaults\":861,\"./attributes\":880}],884:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function eventData(out, pt) {\n    // Note: hoverOnBox property is needed for click-to-select\n    // to ignore when a box was clicked. This is the reason box\n    // implements this custom eventData function.\n    if(pt.hoverOnBox) out.hoverOnBox = pt.hoverOnBox;\n\n    if('xVal' in pt) out.x = pt.xVal;\n    if('yVal' in pt) out.y = pt.yVal;\n    if(pt.xa) out.xaxis = pt.xa;\n    if(pt.ya) out.yaxis = pt.ya;\n\n    return out;\n};\n\n},{}],885:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Lib = _dereq_('../../lib');\nvar Fx = _dereq_('../../components/fx');\nvar Color = _dereq_('../../components/color');\nvar fillText = Lib.fillText;\n\nfunction hoverPoints(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n    var hoveron = trace.hoveron;\n    var closeBoxData = [];\n    var closePtData;\n\n    if(hoveron.indexOf('boxes') !== -1) {\n        closeBoxData = closeBoxData.concat(hoverOnBoxes(pointData, xval, yval, hovermode));\n    }\n\n    if(hoveron.indexOf('points') !== -1) {\n        closePtData = hoverOnPoints(pointData, xval, yval);\n    }\n\n    // If there's a point in range and hoveron has points, show the best single point only.\n    // If hoveron has boxes and there's no point in range (or hoveron doesn't have points), show the box stats.\n    if(hovermode === 'closest') {\n        if(closePtData) return [closePtData];\n        return closeBoxData;\n    }\n\n    // Otherwise in compare mode, allow a point AND the box stats to be labeled\n    // If there are multiple boxes in range (ie boxmode = 'overlay') we'll see stats for all of them.\n    if(closePtData) {\n        closeBoxData.push(closePtData);\n        return closeBoxData;\n    }\n    return closeBoxData;\n}\n\nfunction hoverOnBoxes(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var trace = cd[0].trace;\n    var t = cd[0].t;\n    var isViolin = trace.type === 'violin';\n    var closeBoxData = [];\n\n    var pLetter, vLetter, pAxis, vAxis, vVal, pVal, dx, dy, dPos,\n        hoverPseudoDistance, spikePseudoDistance;\n\n    var boxDelta = t.bdPos;\n    var boxDeltaPos, boxDeltaNeg;\n    var posAcceptance = t.wHover;\n    var shiftPos = function(di) { return di.pos + t.bPos - pVal; };\n\n    if(isViolin && trace.side !== 'both') {\n        if(trace.side === 'positive') {\n            dPos = function(di) {\n                var pos = shiftPos(di);\n                return Fx.inbox(pos, pos + posAcceptance, hoverPseudoDistance);\n            };\n            boxDeltaPos = boxDelta;\n            boxDeltaNeg = 0;\n        }\n        if(trace.side === 'negative') {\n            dPos = function(di) {\n                var pos = shiftPos(di);\n                return Fx.inbox(pos - posAcceptance, pos, hoverPseudoDistance);\n            };\n            boxDeltaPos = 0;\n            boxDeltaNeg = boxDelta;\n        }\n    } else {\n        dPos = function(di) {\n            var pos = shiftPos(di);\n            return Fx.inbox(pos - posAcceptance, pos + posAcceptance, hoverPseudoDistance);\n        };\n        boxDeltaPos = boxDeltaNeg = boxDelta;\n    }\n\n    var dVal;\n\n    if(isViolin) {\n        dVal = function(di) {\n            return Fx.inbox(di.span[0] - vVal, di.span[1] - vVal, hoverPseudoDistance);\n        };\n    } else {\n        dVal = function(di) {\n            return Fx.inbox(di.min - vVal, di.max - vVal, hoverPseudoDistance);\n        };\n    }\n\n    if(trace.orientation === 'h') {\n        vVal = xval;\n        pVal = yval;\n        dx = dVal;\n        dy = dPos;\n        pLetter = 'y';\n        pAxis = ya;\n        vLetter = 'x';\n        vAxis = xa;\n    } else {\n        vVal = yval;\n        pVal = xval;\n        dx = dPos;\n        dy = dVal;\n        pLetter = 'x';\n        pAxis = xa;\n        vLetter = 'y';\n        vAxis = ya;\n    }\n\n    // if two boxes are overlaying, let the narrowest one win\n    var pseudoDistance = Math.min(1, boxDelta / Math.abs(pAxis.r2c(pAxis.range[1]) - pAxis.r2c(pAxis.range[0])));\n    hoverPseudoDistance = pointData.maxHoverDistance - pseudoDistance;\n    spikePseudoDistance = pointData.maxSpikeDistance - pseudoDistance;\n\n    function dxy(di) { return (dx(di) + dy(di)) / 2; }\n    var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);\n    Fx.getClosest(cd, distfn, pointData);\n\n    // skip the rest (for this trace) if we didn't find a close point\n    // and create the item(s) in closedata for this point\n    if(pointData.index === false) return [];\n\n    var di = cd[pointData.index];\n    var lc = trace.line.color;\n    var mc = (trace.marker || {}).color;\n\n    if(Color.opacity(lc) && trace.line.width) pointData.color = lc;\n    else if(Color.opacity(mc) && trace.boxpoints) pointData.color = mc;\n    else pointData.color = trace.fillcolor;\n\n    pointData[pLetter + '0'] = pAxis.c2p(di.pos + t.bPos - boxDeltaNeg, true);\n    pointData[pLetter + '1'] = pAxis.c2p(di.pos + t.bPos + boxDeltaPos, true);\n\n    pointData[pLetter + 'LabelVal'] = di.pos;\n\n    var spikePosAttr = pLetter + 'Spike';\n    pointData.spikeDistance = dxy(di) * spikePseudoDistance / hoverPseudoDistance;\n    pointData[spikePosAttr] = pAxis.c2p(di.pos, true);\n\n    // box plots: each \"point\" gets many labels\n    var usedVals = {};\n    var attrs = ['med', 'q1', 'q3', 'min', 'max'];\n\n    if(trace.boxmean || (trace.meanline || {}).visible) {\n        attrs.push('mean');\n    }\n    if(trace.boxpoints || trace.points) {\n        attrs.push('lf', 'uf');\n    }\n\n    for(var i = 0; i < attrs.length; i++) {\n        var attr = attrs[i];\n\n        if(!(attr in di) || (di[attr] in usedVals)) continue;\n        usedVals[di[attr]] = true;\n\n        // copy out to a new object for each value to label\n        var val = di[attr];\n        var valPx = vAxis.c2p(val, true);\n        var pointData2 = Lib.extendFlat({}, pointData);\n\n        pointData2.attr = attr;\n        pointData2[vLetter + '0'] = pointData2[vLetter + '1'] = valPx;\n        pointData2[vLetter + 'LabelVal'] = val;\n        pointData2[vLetter + 'Label'] = (t.labels ? t.labels[attr] + ' ' : '') + Axes.hoverLabelText(vAxis, val);\n\n        // Note: introduced to be able to distinguish a\n        // clicked point from a box during click-to-select\n        pointData2.hoverOnBox = true;\n\n        if(attr === 'mean' && ('sd' in di) && trace.boxmean === 'sd') {\n            pointData2[vLetter + 'err'] = di.sd;\n        }\n\n        // only keep name and spikes on the first item (median)\n        pointData.name = '';\n        pointData.spikeDistance = undefined;\n        pointData[spikePosAttr] = undefined;\n\n        // no hovertemplate support yet\n        pointData2.hovertemplate = false;\n\n        closeBoxData.push(pointData2);\n    }\n\n    return closeBoxData;\n}\n\nfunction hoverOnPoints(pointData, xval, yval) {\n    var cd = pointData.cd;\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var trace = cd[0].trace;\n    var xPx = xa.c2p(xval);\n    var yPx = ya.c2p(yval);\n    var closePtData;\n\n    var dx = function(di) {\n        var rad = Math.max(3, di.mrc || 0);\n        return Math.max(Math.abs(xa.c2p(di.x) - xPx) - rad, 1 - 3 / rad);\n    };\n    var dy = function(di) {\n        var rad = Math.max(3, di.mrc || 0);\n        return Math.max(Math.abs(ya.c2p(di.y) - yPx) - rad, 1 - 3 / rad);\n    };\n    var distfn = Fx.quadrature(dx, dy);\n\n    // show one point per trace\n    var ijClosest = false;\n    var di, pt;\n\n    for(var i = 0; i < cd.length; i++) {\n        di = cd[i];\n\n        for(var j = 0; j < (di.pts || []).length; j++) {\n            pt = di.pts[j];\n\n            var newDistance = distfn(pt);\n            if(newDistance <= pointData.distance) {\n                pointData.distance = newDistance;\n                ijClosest = [i, j];\n            }\n        }\n    }\n\n    if(!ijClosest) return false;\n\n    di = cd[ijClosest[0]];\n    pt = di.pts[ijClosest[1]];\n\n    var xc = xa.c2p(pt.x, true);\n    var yc = ya.c2p(pt.y, true);\n    var rad = pt.mrc || 1;\n\n    closePtData = Lib.extendFlat({}, pointData, {\n        // corresponds to index in x/y input data array\n        index: pt.i,\n        color: (trace.marker || {}).color,\n        name: trace.name,\n        x0: xc - rad,\n        x1: xc + rad,\n        y0: yc - rad,\n        y1: yc + rad,\n        spikeDistance: pointData.distance,\n        hovertemplate: trace.hovertemplate\n    });\n\n    var pa;\n    if(trace.orientation === 'h') {\n        pa = ya;\n        closePtData.xLabelVal = pt.x;\n        closePtData.yLabelVal = di.pos;\n    } else {\n        pa = xa;\n        closePtData.xLabelVal = di.pos;\n        closePtData.yLabelVal = pt.y;\n    }\n\n    var pLetter = pa._id.charAt(0);\n    closePtData[pLetter + 'Spike'] = pa.c2p(di.pos, true);\n\n    fillText(pt, trace, closePtData);\n\n    return closePtData;\n}\n\nmodule.exports = {\n    hoverPoints: hoverPoints,\n    hoverOnBoxes: hoverOnBoxes,\n    hoverOnPoints: hoverOnPoints\n};\n\n},{\"../../components/color\":593,\"../../components/fx\":632,\"../../lib\":719,\"../../plots/cartesian/axes\":767}],886:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyDefaults: _dereq_('./defaults').supplyDefaults,\n    crossTraceDefaults: _dereq_('./defaults').crossTraceDefaults,\n    supplyLayoutDefaults: _dereq_('./layout_defaults').supplyLayoutDefaults,\n    calc: _dereq_('./calc'),\n    crossTraceCalc: _dereq_('./cross_trace_calc').crossTraceCalc,\n    plot: _dereq_('./plot').plot,\n    style: _dereq_('./style').style,\n    styleOnSelect: _dereq_('./style').styleOnSelect,\n    hoverPoints: _dereq_('./hover').hoverPoints,\n    eventData: _dereq_('./event_data'),\n    selectPoints: _dereq_('./select'),\n\n    moduleType: 'trace',\n    name: 'box',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', 'symbols', 'oriented', 'box-violin', 'showLegend', 'boxLayout', 'zoomScale'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"./attributes\":880,\"./calc\":881,\"./cross_trace_calc\":882,\"./defaults\":883,\"./event_data\":884,\"./hover\":885,\"./layout_attributes\":887,\"./layout_defaults\":888,\"./plot\":889,\"./select\":890,\"./style\":891}],887:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n    boxmode: {\n        valType: 'enumerated',\n        values: ['group', 'overlay'],\n        dflt: 'overlay',\n        \n        editType: 'calc',\n        \n    },\n    boxgap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 0.3,\n        \n        editType: 'calc',\n        \n    },\n    boxgroupgap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 0.3,\n        \n        editType: 'calc',\n        \n    }\n};\n\n},{}],888:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nfunction _supply(layoutIn, layoutOut, fullData, coerce, traceType) {\n    var category = traceType + 'Layout';\n    var hasTraceType = false;\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n\n        if(Registry.traceIs(trace, category)) {\n            hasTraceType = true;\n            break;\n        }\n    }\n    if(!hasTraceType) return;\n\n    coerce(traceType + 'mode');\n    coerce(traceType + 'gap');\n    coerce(traceType + 'groupgap');\n}\n\nfunction supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n    _supply(layoutIn, layoutOut, fullData, coerce, 'box');\n}\n\nmodule.exports = {\n    supplyLayoutDefaults: supplyLayoutDefaults,\n    _supply: _supply\n};\n\n},{\"../../lib\":719,\"../../registry\":847,\"./layout_attributes\":887}],889:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../../components/drawing');\n\n// constants for dynamic jitter (ie less jitter for sparser points)\nvar JITTERCOUNT = 5; // points either side of this to include\nvar JITTERSPREAD = 0.01; // fraction of IQR to count as \"dense\"\n\nfunction plot(gd, plotinfo, cdbox, boxLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    Lib.makeTraceGroups(boxLayer, cdbox, 'trace boxes').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var cd0 = cd[0];\n        var t = cd0.t;\n        var trace = cd0.trace;\n\n        // whisker width\n        t.wdPos = t.bdPos * trace.whiskerwidth;\n\n        if(trace.visible !== true || t.empty) {\n            plotGroup.remove();\n            return;\n        }\n\n        var posAxis, valAxis;\n\n        if(trace.orientation === 'h') {\n            posAxis = ya;\n            valAxis = xa;\n        } else {\n            posAxis = xa;\n            valAxis = ya;\n        }\n\n        plotBoxAndWhiskers(plotGroup, {pos: posAxis, val: valAxis}, trace, t);\n        plotPoints(plotGroup, {x: xa, y: ya}, trace, t);\n        plotBoxMean(plotGroup, {pos: posAxis, val: valAxis}, trace, t);\n    });\n}\n\nfunction plotBoxAndWhiskers(sel, axes, trace, t) {\n    var posAxis = axes.pos;\n    var valAxis = axes.val;\n    var bPos = t.bPos;\n    var wdPos = t.wdPos || 0;\n    var bPosPxOffset = t.bPosPxOffset || 0;\n    var whiskerWidth = trace.whiskerwidth || 0;\n    var notched = trace.notched || false;\n    var nw = notched ? 1 - 2 * trace.notchwidth : 1;\n\n    // to support for one-sided box\n    var bdPos0;\n    var bdPos1;\n    if(Array.isArray(t.bdPos)) {\n        bdPos0 = t.bdPos[0];\n        bdPos1 = t.bdPos[1];\n    } else {\n        bdPos0 = t.bdPos;\n        bdPos1 = t.bdPos;\n    }\n\n    var paths = sel.selectAll('path.box').data((\n        trace.type !== 'violin' ||\n        trace.box.visible\n    ) ? Lib.identity : []);\n\n    paths.enter().append('path')\n        .style('vector-effect', 'non-scaling-stroke')\n        .attr('class', 'box');\n\n    paths.exit().remove();\n\n    paths.each(function(d) {\n        if(d.empty) return 'M0,0Z';\n\n        var pos = d.pos;\n        var posc = posAxis.c2p(pos + bPos, true) + bPosPxOffset;\n        var pos0 = posAxis.c2p(pos + bPos - bdPos0, true) + bPosPxOffset;\n        var pos1 = posAxis.c2p(pos + bPos + bdPos1, true) + bPosPxOffset;\n        var posw0 = posAxis.c2p(pos + bPos - wdPos, true) + bPosPxOffset;\n        var posw1 = posAxis.c2p(pos + bPos + wdPos, true) + bPosPxOffset;\n        var posm0 = posAxis.c2p(pos + bPos - bdPos0 * nw, true) + bPosPxOffset;\n        var posm1 = posAxis.c2p(pos + bPos + bdPos1 * nw, true) + bPosPxOffset;\n        var q1 = valAxis.c2p(d.q1, true);\n        var q3 = valAxis.c2p(d.q3, true);\n        // make sure median isn't identical to either of the\n        // quartiles, so we can see it\n        var m = Lib.constrain(\n            valAxis.c2p(d.med, true),\n            Math.min(q1, q3) + 1, Math.max(q1, q3) - 1\n        );\n\n        // for compatibility with box, violin, and candlestick\n        // perhaps we should put this into cd0.t instead so it's more explicit,\n        // but what we have now is:\n        // - box always has d.lf, but boxpoints can be anything\n        // - violin has d.lf and should always use it (boxpoints is undefined)\n        // - candlestick has only min/max\n        var useExtremes = (d.lf === undefined) || (trace.boxpoints === false);\n        var lf = valAxis.c2p(useExtremes ? d.min : d.lf, true);\n        var uf = valAxis.c2p(useExtremes ? d.max : d.uf, true);\n        var ln = valAxis.c2p(d.ln, true);\n        var un = valAxis.c2p(d.un, true);\n\n        if(trace.orientation === 'h') {\n            d3.select(this).attr('d',\n                'M' + m + ',' + posm0 + 'V' + posm1 + // median line\n                'M' + q1 + ',' + pos0 + 'V' + pos1 + // left edge\n                (notched ? 'H' + ln + 'L' + m + ',' + posm1 + 'L' + un + ',' + pos1 : '') + // top notched edge\n                'H' + q3 + // end of the top edge\n                'V' + pos0 + // right edge\n                (notched ? 'H' + un + 'L' + m + ',' + posm0 + 'L' + ln + ',' + pos0 : '') + // bottom notched edge\n                'Z' + // end of the box\n                'M' + q1 + ',' + posc + 'H' + lf + 'M' + q3 + ',' + posc + 'H' + uf + // whiskers\n                ((whiskerWidth === 0) ? '' : // whisker caps\n                    'M' + lf + ',' + posw0 + 'V' + posw1 + 'M' + uf + ',' + posw0 + 'V' + posw1));\n        } else {\n            d3.select(this).attr('d',\n                'M' + posm0 + ',' + m + 'H' + posm1 + // median line\n                'M' + pos0 + ',' + q1 + 'H' + pos1 + // top of the box\n                (notched ? 'V' + ln + 'L' + posm1 + ',' + m + 'L' + pos1 + ',' + un : '') + // notched right edge\n                'V' + q3 + // end of the right edge\n                'H' + pos0 + // bottom of the box\n                (notched ? 'V' + un + 'L' + posm0 + ',' + m + 'L' + pos0 + ',' + ln : '') + // notched left edge\n                'Z' + // end of the box\n                'M' + posc + ',' + q1 + 'V' + lf + 'M' + posc + ',' + q3 + 'V' + uf + // whiskers\n                ((whiskerWidth === 0) ? '' : // whisker caps\n                    'M' + posw0 + ',' + lf + 'H' + posw1 + 'M' + posw0 + ',' + uf + 'H' + posw1));\n        }\n    });\n}\n\nfunction plotPoints(sel, axes, trace, t) {\n    var xa = axes.x;\n    var ya = axes.y;\n    var bdPos = t.bdPos;\n    var bPos = t.bPos;\n\n    // to support violin points\n    var mode = trace.boxpoints || trace.points;\n\n    // repeatable pseudo-random number generator\n    Lib.seedPseudoRandom();\n\n    // since box plot points get an extra level of nesting, each\n    // box needs the trace styling info\n    var fn = function(d) {\n        d.forEach(function(v) {\n            v.t = t;\n            v.trace = trace;\n        });\n        return d;\n    };\n\n    var gPoints = sel.selectAll('g.points')\n        .data(mode ? fn : []);\n\n    gPoints.enter().append('g')\n        .attr('class', 'points');\n\n    gPoints.exit().remove();\n\n    var paths = gPoints.selectAll('path')\n        .data(function(d) {\n            var i;\n            var pts = d.pts2;\n\n            // normally use IQR, but if this is 0 or too small, use max-min\n            var typicalSpread = Math.max((d.max - d.min) / 10, d.q3 - d.q1);\n            var minSpread = typicalSpread * 1e-9;\n            var spreadLimit = typicalSpread * JITTERSPREAD;\n            var jitterFactors = [];\n            var maxJitterFactor = 0;\n            var newJitter;\n\n            // dynamic jitter\n            if(trace.jitter) {\n                if(typicalSpread === 0) {\n                    // edge case of no spread at all: fall back to max jitter\n                    maxJitterFactor = 1;\n                    jitterFactors = new Array(pts.length);\n                    for(i = 0; i < pts.length; i++) {\n                        jitterFactors[i] = 1;\n                    }\n                } else {\n                    for(i = 0; i < pts.length; i++) {\n                        var i0 = Math.max(0, i - JITTERCOUNT);\n                        var pmin = pts[i0].v;\n                        var i1 = Math.min(pts.length - 1, i + JITTERCOUNT);\n                        var pmax = pts[i1].v;\n\n                        if(mode !== 'all') {\n                            if(pts[i].v < d.lf) pmax = Math.min(pmax, d.lf);\n                            else pmin = Math.max(pmin, d.uf);\n                        }\n\n                        var jitterFactor = Math.sqrt(spreadLimit * (i1 - i0) / (pmax - pmin + minSpread)) || 0;\n                        jitterFactor = Lib.constrain(Math.abs(jitterFactor), 0, 1);\n\n                        jitterFactors.push(jitterFactor);\n                        maxJitterFactor = Math.max(jitterFactor, maxJitterFactor);\n                    }\n                }\n                newJitter = trace.jitter * 2 / (maxJitterFactor || 1);\n            }\n\n            // fills in 'x' and 'y' in calcdata 'pts' item\n            for(i = 0; i < pts.length; i++) {\n                var pt = pts[i];\n                var v = pt.v;\n\n                var jitterOffset = trace.jitter ?\n                    (newJitter * jitterFactors[i] * (Lib.pseudoRandom() - 0.5)) :\n                    0;\n\n                var posPx = d.pos + bPos + bdPos * (trace.pointpos + jitterOffset);\n\n                if(trace.orientation === 'h') {\n                    pt.y = posPx;\n                    pt.x = v;\n                } else {\n                    pt.x = posPx;\n                    pt.y = v;\n                }\n\n                // tag suspected outliers\n                if(mode === 'suspectedoutliers' && v < d.uo && v > d.lo) {\n                    pt.so = true;\n                }\n            }\n\n            return pts;\n        });\n\n    paths.enter().append('path')\n        .classed('point', true);\n\n    paths.exit().remove();\n\n    paths.call(Drawing.translatePoints, xa, ya);\n}\n\nfunction plotBoxMean(sel, axes, trace, t) {\n    var posAxis = axes.pos;\n    var valAxis = axes.val;\n    var bPos = t.bPos;\n    var bPosPxOffset = t.bPosPxOffset || 0;\n\n    // to support violin mean lines\n    var mode = trace.boxmean || (trace.meanline || {}).visible;\n\n    // to support for one-sided box\n    var bdPos0;\n    var bdPos1;\n    if(Array.isArray(t.bdPos)) {\n        bdPos0 = t.bdPos[0];\n        bdPos1 = t.bdPos[1];\n    } else {\n        bdPos0 = t.bdPos;\n        bdPos1 = t.bdPos;\n    }\n\n    var paths = sel.selectAll('path.mean').data((\n        (trace.type === 'box' && trace.boxmean) ||\n        (trace.type === 'violin' && trace.box.visible && trace.meanline.visible)\n    ) ? Lib.identity : []);\n\n    paths.enter().append('path')\n        .attr('class', 'mean')\n        .style({\n            fill: 'none',\n            'vector-effect': 'non-scaling-stroke'\n        });\n\n    paths.exit().remove();\n\n    paths.each(function(d) {\n        var posc = posAxis.c2p(d.pos + bPos, true) + bPosPxOffset;\n        var pos0 = posAxis.c2p(d.pos + bPos - bdPos0, true) + bPosPxOffset;\n        var pos1 = posAxis.c2p(d.pos + bPos + bdPos1, true) + bPosPxOffset;\n        var m = valAxis.c2p(d.mean, true);\n        var sl = valAxis.c2p(d.mean - d.sd, true);\n        var sh = valAxis.c2p(d.mean + d.sd, true);\n\n        if(trace.orientation === 'h') {\n            d3.select(this).attr('d',\n                'M' + m + ',' + pos0 + 'V' + pos1 +\n                (mode === 'sd' ?\n                    'm0,0L' + sl + ',' + posc + 'L' + m + ',' + pos0 + 'L' + sh + ',' + posc + 'Z' :\n                    '')\n            );\n        } else {\n            d3.select(this).attr('d',\n                'M' + pos0 + ',' + m + 'H' + pos1 +\n                (mode === 'sd' ?\n                    'm0,0L' + posc + ',' + sl + 'L' + pos0 + ',' + m + 'L' + posc + ',' + sh + 'Z' :\n                    '')\n            );\n        }\n    });\n}\n\nmodule.exports = {\n    plot: plot,\n    plotBoxAndWhiskers: plotBoxAndWhiskers,\n    plotPoints: plotPoints,\n    plotBoxMean: plotBoxMean\n};\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"d3\":163}],890:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function selectPoints(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var xa = searchInfo.xaxis;\n    var ya = searchInfo.yaxis;\n    var selection = [];\n    var i, j;\n\n    if(selectionTester === false) {\n        for(i = 0; i < cd.length; i++) {\n            for(j = 0; j < (cd[i].pts || []).length; j++) {\n                // clear selection\n                cd[i].pts[j].selected = 0;\n            }\n        }\n    } else {\n        for(i = 0; i < cd.length; i++) {\n            for(j = 0; j < (cd[i].pts || []).length; j++) {\n                var pt = cd[i].pts[j];\n                var x = xa.c2p(pt.x);\n                var y = ya.c2p(pt.y);\n\n                if(selectionTester.contains([x, y], null, pt.i, searchInfo)) {\n                    selection.push({\n                        pointNumber: pt.i,\n                        x: xa.c2d(pt.x),\n                        y: ya.c2d(pt.y)\n                    });\n                    pt.selected = 1;\n                } else {\n                    pt.selected = 0;\n                }\n            }\n        }\n    }\n\n    return selection;\n};\n\n},{}],891:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\n\nfunction style(gd, cd, sel) {\n    var s = sel ? sel : d3.select(gd).selectAll('g.trace.boxes');\n\n    s.style('opacity', function(d) { return d[0].trace.opacity; });\n\n    s.each(function(d) {\n        var el = d3.select(this);\n        var trace = d[0].trace;\n        var lineWidth = trace.line.width;\n\n        function styleBox(boxSel, lineWidth, lineColor, fillColor) {\n            boxSel.style('stroke-width', lineWidth + 'px')\n                .call(Color.stroke, lineColor)\n                .call(Color.fill, fillColor);\n        }\n\n        var allBoxes = el.selectAll('path.box');\n\n        if(trace.type === 'candlestick') {\n            allBoxes.each(function(boxData) {\n                if(boxData.empty) return;\n\n                var thisBox = d3.select(this);\n                var container = trace[boxData.dir]; // dir = 'increasing' or 'decreasing'\n                styleBox(thisBox, container.line.width, container.line.color, container.fillcolor);\n                // TODO: custom selection style for candlesticks\n                thisBox.style('opacity', trace.selectedpoints && !boxData.selected ? 0.3 : 1);\n            });\n        } else {\n            styleBox(allBoxes, lineWidth, trace.line.color, trace.fillcolor);\n            el.selectAll('path.mean')\n                .style({\n                    'stroke-width': lineWidth,\n                    'stroke-dasharray': (2 * lineWidth) + 'px,' + lineWidth + 'px'\n                })\n                .call(Color.stroke, trace.line.color);\n\n            var pts = el.selectAll('path.point');\n            Drawing.pointStyle(pts, trace, gd);\n        }\n    });\n}\n\nfunction styleOnSelect(gd, cd, sel) {\n    var trace = cd[0].trace;\n    var pts = sel.selectAll('path.point');\n\n    if(trace.selectedpoints) {\n        Drawing.selectedPointStyle(pts, trace);\n    } else {\n        Drawing.pointStyle(pts, trace, gd);\n    }\n}\n\nmodule.exports = {\n    style: style,\n    styleOnSelect: styleOnSelect\n};\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"d3\":163}],892:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar extendFlat = _dereq_('../../lib').extendFlat;\nvar OHLCattrs = _dereq_('../ohlc/attributes');\nvar boxAttrs = _dereq_('../box/attributes');\n\nfunction directionAttrs(lineColorDefault) {\n    return {\n        line: {\n            color: extendFlat({}, boxAttrs.line.color, {dflt: lineColorDefault}),\n            width: boxAttrs.line.width,\n            editType: 'style'\n        },\n\n        fillcolor: boxAttrs.fillcolor,\n        editType: 'style'\n    };\n}\n\nmodule.exports = {\n    x: OHLCattrs.x,\n    open: OHLCattrs.open,\n    high: OHLCattrs.high,\n    low: OHLCattrs.low,\n    close: OHLCattrs.close,\n\n    line: {\n        width: extendFlat({}, boxAttrs.line.width, {\n            \n        }),\n        editType: 'style'\n    },\n\n    increasing: directionAttrs(OHLCattrs.increasing.line.color.dflt),\n\n    decreasing: directionAttrs(OHLCattrs.decreasing.line.color.dflt),\n\n    text: OHLCattrs.text,\n    hovertext: OHLCattrs.hovertext,\n    whiskerwidth: extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 }),\n\n    hoverlabel: OHLCattrs.hoverlabel,\n};\n\n},{\"../../lib\":719,\"../box/attributes\":880,\"../ohlc/attributes\":1058}],893:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nvar calcCommon = _dereq_('../ohlc/calc').calcCommon;\n\nmodule.exports = function(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var xa = Axes.getFromId(gd, trace.xaxis);\n    var ya = Axes.getFromId(gd, trace.yaxis);\n\n    var x = xa.makeCalcdata(trace, 'x');\n\n    var cd = calcCommon(gd, trace, x, ya, ptFunc);\n\n    if(cd.length) {\n        Lib.extendFlat(cd[0].t, {\n            num: fullLayout._numBoxes,\n            dPos: Lib.distinctVals(x).minDiff / 2,\n            posLetter: 'x',\n            valLetter: 'y',\n        });\n\n        fullLayout._numBoxes++;\n        return cd;\n    } else {\n        return [{t: {empty: true}}];\n    }\n};\n\nfunction ptFunc(o, h, l, c) {\n    return {\n        min: l,\n        q1: Math.min(o, c),\n        med: c,\n        q3: Math.max(o, c),\n        max: h,\n    };\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../ohlc/calc\":1059}],894:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\nvar handleOHLC = _dereq_('../ohlc/ohlc_defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleOHLC(traceIn, traceOut, coerce, layout);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('line.width');\n\n    handleDirection(traceIn, traceOut, coerce, 'increasing');\n    handleDirection(traceIn, traceOut, coerce, 'decreasing');\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('whiskerwidth');\n\n    layout._requestRangeslider[traceOut.xaxis] = true;\n};\n\nfunction handleDirection(traceIn, traceOut, coerce, direction) {\n    var lineColor = coerce(direction + '.line.color');\n    coerce(direction + '.line.width', traceOut.line.width);\n    coerce(direction + '.fillcolor', Color.addOpacity(lineColor, 0.5));\n}\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../ohlc/ohlc_defaults\":1063,\"./attributes\":892}],895:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'candlestick',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', 'showLegend', 'candlestick', 'boxLayout'],\n    meta: {\n        \n    },\n\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('../box/layout_attributes'),\n    supplyLayoutDefaults: _dereq_('../box/layout_defaults').supplyLayoutDefaults,\n    crossTraceCalc: _dereq_('../box/cross_trace_calc').crossTraceCalc,\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('../box/plot').plot,\n    layerName: 'boxlayer',\n    style: _dereq_('../box/style').style,\n    hoverPoints: _dereq_('../ohlc/hover').hoverPoints,\n    selectPoints: _dereq_('../ohlc/select')\n};\n\n},{\"../../plots/cartesian\":778,\"../box/cross_trace_calc\":882,\"../box/layout_attributes\":887,\"../box/layout_defaults\":888,\"../box/plot\":889,\"../box/style\":891,\"../ohlc/hover\":1061,\"../ohlc/select\":1065,\"./attributes\":892,\"./calc\":893,\"./defaults\":894}],896:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar handleAxisDefaults = _dereq_('./axis_defaults');\nvar Template = _dereq_('../../plot_api/plot_template');\n\nmodule.exports = function handleABDefaults(traceIn, traceOut, fullLayout, coerce, dfltColor) {\n    var a = coerce('a');\n\n    if(!a) {\n        coerce('da');\n        coerce('a0');\n    }\n\n    var b = coerce('b');\n\n    if(!b) {\n        coerce('db');\n        coerce('b0');\n    }\n\n    mimickAxisDefaults(traceIn, traceOut, fullLayout, dfltColor);\n};\n\nfunction mimickAxisDefaults(traceIn, traceOut, fullLayout, dfltColor) {\n    var axesList = ['aaxis', 'baxis'];\n\n    axesList.forEach(function(axName) {\n        var axLetter = axName.charAt(0);\n        var axIn = traceIn[axName] || {};\n        var axOut = Template.newContainer(traceOut, axName);\n\n        var defaultOptions = {\n            tickfont: 'x',\n            id: axLetter + 'axis',\n            letter: axLetter,\n            font: traceOut.font,\n            name: axName,\n            data: traceIn[axLetter],\n            calendar: traceOut.calendar,\n            dfltColor: dfltColor,\n            bgColor: fullLayout.paper_bgcolor,\n            fullLayout: fullLayout\n        };\n\n        handleAxisDefaults(axIn, axOut, defaultOptions);\n        axOut._categories = axOut._categories || [];\n\n        // so we don't have to repeat autotype unnecessarily,\n        // copy an autotype back to traceIn\n        if(!traceIn[axName] && axIn.type !== '-') {\n            traceIn[axName] = {type: axIn.type};\n        }\n    });\n}\n\n},{\"../../plot_api/plot_template\":757,\"./axis_defaults\":901}],897:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\n\nmodule.exports = function(a) {\n    return minMax(a, 0);\n};\n\nfunction minMax(a, depth) {\n    // Limit to ten dimensional datasets. This seems *exceedingly* unlikely to\n    // ever cause problems or even be a concern. It's include strictly so that\n    // circular arrays could never cause this to loop.\n    if(!isArrayOrTypedArray(a) || depth >= 10) {\n        return null;\n    }\n\n    var min = Infinity;\n    var max = -Infinity;\n    var n = a.length;\n    for(var i = 0; i < n; i++) {\n        var datum = a[i];\n\n        if(isArrayOrTypedArray(datum)) {\n            var result = minMax(datum, depth + 1);\n\n            if(result) {\n                min = Math.min(result[0], min);\n                max = Math.max(result[1], max);\n            }\n        } else {\n            min = Math.min(datum, min);\n            max = Math.max(datum, max);\n        }\n    }\n\n    return [min, max];\n}\n\n},{\"../../lib\":719}],898:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar axisAttrs = _dereq_('./axis_attributes');\nvar colorAttrs = _dereq_('../../components/color/attributes');\n\nvar carpetFont = fontAttrs({\n    editType: 'calc',\n    \n});\n// TODO: inherit from global font\ncarpetFont.family.dflt = '\"Open Sans\", verdana, arial, sans-serif';\ncarpetFont.size.dflt = 12;\ncarpetFont.color.dflt = colorAttrs.defaultLine;\n\nmodule.exports = {\n    carpet: {\n        valType: 'string',\n        \n        editType: 'calc',\n        \n    },\n    x: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n    y: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n    a: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    a0: {\n        valType: 'number',\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    da: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n    b: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    b0: {\n        valType: 'number',\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    db: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n    cheaterslope: {\n        valType: 'number',\n        \n        dflt: 1,\n        editType: 'calc',\n        \n    },\n    aaxis: axisAttrs,\n    baxis: axisAttrs,\n    font: carpetFont,\n    color: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'plot',\n        \n    },\n    transforms: undefined\n};\n\n},{\"../../components/color/attributes\":592,\"../../plots/font_attributes\":793,\"./axis_attributes\":900}],899:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\n\n/* This function retrns a set of control points that define a curve aligned along\n * either the a or b axis. Exactly one of a or b must be an array defining the range\n * spanned.\n *\n * Honestly this is the most complicated function I've implemente here so far because\n * of the way it handles knot insertion and direction/axis-agnostic slices.\n */\nmodule.exports = function(carpet, carpetcd, a, b) {\n    var idx, tangent, tanIsoIdx, tanIsoPar, segment, refidx;\n    var p0, p1, v0, v1, start, end, range;\n\n    var axis = isArrayOrTypedArray(a) ? 'a' : 'b';\n    var ax = axis === 'a' ? carpet.aaxis : carpet.baxis;\n    var smoothing = ax.smoothing;\n    var toIdx = axis === 'a' ? carpet.a2i : carpet.b2j;\n    var pt = axis === 'a' ? a : b;\n    var iso = axis === 'a' ? b : a;\n    var n = axis === 'a' ? carpetcd.a.length : carpetcd.b.length;\n    var m = axis === 'a' ? carpetcd.b.length : carpetcd.a.length;\n    var isoIdx = Math.floor(axis === 'a' ? carpet.b2j(iso) : carpet.a2i(iso));\n\n    var xy = axis === 'a' ? function(value) {\n        return carpet.evalxy([], value, isoIdx);\n    } : function(value) {\n        return carpet.evalxy([], isoIdx, value);\n    };\n\n    if(smoothing) {\n        tanIsoIdx = Math.max(0, Math.min(m - 2, isoIdx));\n        tanIsoPar = isoIdx - tanIsoIdx;\n        tangent = axis === 'a' ? function(i, ti) {\n            return carpet.dxydi([], i, tanIsoIdx, ti, tanIsoPar);\n        } : function(j, tj) {\n            return carpet.dxydj([], tanIsoIdx, j, tanIsoPar, tj);\n        };\n    }\n\n    var vstart = toIdx(pt[0]);\n    var vend = toIdx(pt[1]);\n\n    // So that we can make this work in two directions, flip all of the\n    // math functions if the direction is from higher to lower indices:\n    //\n    // Note that the tolerance is directional!\n    var dir = vstart < vend ? 1 : -1;\n    var tol = (vend - vstart) * 1e-8;\n    var dirfloor = dir > 0 ? Math.floor : Math.ceil;\n    var dirceil = dir > 0 ? Math.ceil : Math.floor;\n    var dirmin = dir > 0 ? Math.min : Math.max;\n    var dirmax = dir > 0 ? Math.max : Math.min;\n\n    var idx0 = dirfloor(vstart + tol);\n    var idx1 = dirceil(vend - tol);\n\n    p0 = xy(vstart);\n    var segments = [[p0]];\n\n    for(idx = idx0; idx * dir < idx1 * dir; idx += dir) {\n        segment = [];\n        start = dirmax(vstart, idx);\n        end = dirmin(vend, idx + dir);\n        range = end - start;\n\n        // In order to figure out which cell we're in for the derivative (remember,\n        // the derivatives are *not* constant across grid lines), let's just average\n        // the start and end points. This cuts out just a tiny bit of logic and\n        // there's really no computational difference:\n        refidx = Math.max(0, Math.min(n - 2, Math.floor(0.5 * (start + end))));\n\n        p1 = xy(end);\n        if(smoothing) {\n            v0 = tangent(refidx, start - refidx);\n            v1 = tangent(refidx, end - refidx);\n\n            segment.push([\n                p0[0] + v0[0] / 3 * range,\n                p0[1] + v0[1] / 3 * range\n            ]);\n\n            segment.push([\n                p1[0] - v1[0] / 3 * range,\n                p1[1] - v1[1] / 3 * range\n            ]);\n        }\n\n        segment.push(p1);\n\n        segments.push(segment);\n        p0 = p1;\n    }\n\n    return segments;\n};\n\n},{\"../../lib\":719}],900:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar axesAttrs = _dereq_('../../plots/cartesian/layout_attributes');\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar FORMAT_LINK = _dereq_('../../constants/docs').FORMAT_LINK;\nvar DATE_FORMAT_LINK = _dereq_('../../constants/docs').TIME_FORMAT_LINK;\n\nmodule.exports = {\n    color: {\n        valType: 'color',\n        \n        editType: 'calc',\n        \n    },\n    smoothing: {\n        valType: 'number',\n        dflt: 1,\n        min: 0,\n        max: 1.3,\n        \n        editType: 'calc'\n    },\n    title: {\n        text: {\n            valType: 'string',\n            dflt: '',\n            \n            editType: 'calc',\n            \n        },\n        font: fontAttrs({\n            editType: 'calc',\n            \n        }),\n        offset: {\n            valType: 'number',\n            \n            dflt: 10,\n            editType: 'calc',\n            \n        },\n        editType: 'calc',\n    },\n    type: {\n        valType: 'enumerated',\n        // '-' means we haven't yet run autotype or couldn't find any data\n        // it gets turned into linear in gd._fullLayout but not copied back\n        // to gd.data like the others are.\n        values: ['-', 'linear', 'date', 'category'],\n        dflt: '-',\n        \n        editType: 'calc',\n        \n    },\n    autorange: {\n        valType: 'enumerated',\n        values: [true, false, 'reversed'],\n        dflt: true,\n        \n        editType: 'calc',\n        \n    },\n    rangemode: {\n        valType: 'enumerated',\n        values: ['normal', 'tozero', 'nonnegative'],\n        dflt: 'normal',\n        \n        editType: 'calc',\n        \n    },\n    range: {\n        valType: 'info_array',\n        \n        editType: 'calc',\n        items: [\n            {valType: 'any', editType: 'calc'},\n            {valType: 'any', editType: 'calc'}\n        ],\n        \n    },\n\n    fixedrange: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    cheatertype: {\n        valType: 'enumerated',\n        values: ['index', 'value'],\n        dflt: 'value',\n        \n        editType: 'calc'\n    },\n    tickmode: {\n        valType: 'enumerated',\n        values: ['linear', 'array'],\n        dflt: 'array',\n        \n        editType: 'calc'\n    },\n    nticks: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    tickvals: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    ticktext: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    showticklabels: {\n        valType: 'enumerated',\n        values: ['start', 'end', 'both', 'none'],\n        dflt: 'start',\n        \n        editType: 'calc',\n        \n    },\n    tickfont: fontAttrs({\n        editType: 'calc',\n        \n    }),\n    tickangle: {\n        valType: 'angle',\n        dflt: 'auto',\n        \n        editType: 'calc',\n        \n    },\n    tickprefix: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'calc',\n        \n    },\n    showtickprefix: {\n        valType: 'enumerated',\n        values: ['all', 'first', 'last', 'none'],\n        dflt: 'all',\n        \n        editType: 'calc',\n        \n    },\n    ticksuffix: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'calc',\n        \n    },\n    showticksuffix: {\n        valType: 'enumerated',\n        values: ['all', 'first', 'last', 'none'],\n        dflt: 'all',\n        \n        editType: 'calc',\n        \n    },\n    showexponent: {\n        valType: 'enumerated',\n        values: ['all', 'first', 'last', 'none'],\n        dflt: 'all',\n        \n        editType: 'calc',\n        \n    },\n    exponentformat: {\n        valType: 'enumerated',\n        values: ['none', 'e', 'E', 'power', 'SI', 'B'],\n        dflt: 'B',\n        \n        editType: 'calc',\n        \n    },\n    separatethousands: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    tickformat: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'calc',\n        \n    },\n    tickformatstops: overrideAll(axesAttrs.tickformatstops, 'calc', 'from-root'),\n    categoryorder: {\n        valType: 'enumerated',\n        values: [\n            'trace', 'category ascending', 'category descending', 'array'\n            /* , 'value ascending', 'value descending'*/ // value ascending / descending to be implemented later\n        ],\n        dflt: 'trace',\n        \n        editType: 'calc',\n        \n    },\n    categoryarray: {\n        valType: 'data_array',\n        \n        editType: 'calc',\n        \n    },\n    labelpadding: {\n        valType: 'integer',\n        \n        dflt: 10,\n        editType: 'calc',\n        \n    },\n    labelprefix: {\n        valType: 'string',\n        \n        editType: 'calc',\n        \n    },\n    labelsuffix: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'calc',\n        \n    },\n    // lines and grids\n    showline: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    linecolor: {\n        valType: 'color',\n        dflt: colorAttrs.defaultLine,\n        \n        editType: 'calc',\n        \n    },\n    linewidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n    gridcolor: {\n        valType: 'color',\n        \n        editType: 'calc',\n        \n    },\n    gridwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n    showgrid: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'calc',\n        \n    },\n    minorgridcount: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    minorgridwidth: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n    minorgridcolor: {\n        valType: 'color',\n        dflt: colorAttrs.lightLine,\n        \n        editType: 'calc',\n        \n    },\n    startline: {\n        valType: 'boolean',\n        \n        editType: 'calc',\n        \n    },\n    startlinecolor: {\n        valType: 'color',\n        \n        editType: 'calc',\n        \n    },\n    startlinewidth: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n    endline: {\n        valType: 'boolean',\n        \n        editType: 'calc',\n        \n    },\n    endlinewidth: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n    endlinecolor: {\n        valType: 'color',\n        \n        editType: 'calc',\n        \n    },\n    tick0: {\n        valType: 'number',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    dtick: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n    arraytick0: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    arraydtick: {\n        valType: 'integer',\n        min: 1,\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n\n    _deprecated: {\n        title: {\n            valType: 'string',\n            \n            editType: 'calc',\n            \n        },\n        titlefont: fontAttrs({\n            editType: 'calc',\n            \n        }),\n        titleoffset: {\n            valType: 'number',\n            \n            dflt: 10,\n            editType: 'calc',\n            \n        }\n    },\n\n    editType: 'calc'\n};\n\n},{\"../../components/color/attributes\":592,\"../../constants/docs\":690,\"../../plot_api/edit_types\":750,\"../../plots/cartesian/layout_attributes\":779,\"../../plots/font_attributes\":793}],901:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar carpetAttrs = _dereq_('./attributes');\n\nvar addOpacity = _dereq_('../../components/color').addOpacity;\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar handleTickValueDefaults = _dereq_('../../plots/cartesian/tick_value_defaults');\nvar handleTickLabelDefaults = _dereq_('../../plots/cartesian/tick_label_defaults');\nvar handleCategoryOrderDefaults = _dereq_('../../plots/cartesian/category_order_defaults');\nvar setConvert = _dereq_('../../plots/cartesian/set_convert');\nvar autoType = _dereq_('../../plots/cartesian/axis_autotype');\n\n/**\n * options: object containing:\n *\n *  letter: 'a' or 'b'\n *  title: name of the axis (ie 'Colorbar') to go in default title\n *  name: axis object name (ie 'xaxis') if one should be stored\n *  font: the default font to inherit\n *  outerTicks: boolean, should ticks default to outside?\n *  showGrid: boolean, should gridlines be shown by default?\n *  data: the plot data to use in choosing auto type\n *  bgColor: the plot background color, to calculate default gridline colors\n */\nmodule.exports = function handleAxisDefaults(containerIn, containerOut, options) {\n    var letter = options.letter;\n    var font = options.font || {};\n    var attributes = carpetAttrs[letter + 'axis'];\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);\n    }\n\n    function coerce2(attr, dflt) {\n        return Lib.coerce2(containerIn, containerOut, attributes, attr, dflt);\n    }\n\n    // set up some private properties\n    if(options.name) {\n        containerOut._name = options.name;\n        containerOut._id = options.name;\n    }\n\n    // now figure out type and do some more initialization\n    var axType = coerce('type');\n    if(axType === '-') {\n        if(options.data) setAutoType(containerOut, options.data);\n\n        if(containerOut.type === '-') {\n            containerOut.type = 'linear';\n        } else {\n            // copy autoType back to input axis\n            // note that if this object didn't exist\n            // in the input layout, we have to put it in\n            // this happens in the main supplyDefaults function\n            axType = containerIn.type = containerOut.type;\n        }\n    }\n\n    coerce('smoothing');\n    coerce('cheatertype');\n\n    coerce('showticklabels');\n    coerce('labelprefix', letter + ' = ');\n    coerce('labelsuffix');\n    coerce('showtickprefix');\n    coerce('showticksuffix');\n\n    coerce('separatethousands');\n    coerce('tickformat');\n    coerce('exponentformat');\n    coerce('showexponent');\n    coerce('categoryorder');\n\n    coerce('tickmode');\n    coerce('tickvals');\n    coerce('ticktext');\n    coerce('tick0');\n    coerce('dtick');\n\n    if(containerOut.tickmode === 'array') {\n        coerce('arraytick0');\n        coerce('arraydtick');\n    }\n\n    coerce('labelpadding');\n\n    containerOut._hovertitle = letter;\n\n\n    if(axType === 'date') {\n        var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');\n        handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);\n    }\n\n    // we need some of the other functions setConvert attaches, but for\n    // path finding, override pixel scaling to simple passthrough (identity)\n    setConvert(containerOut, options.fullLayout);\n    containerOut.c2p = Lib.identity;\n\n    var dfltColor = coerce('color', options.dfltColor);\n    // if axis.color was provided, use it for fonts too; otherwise,\n    // inherit from global font color in case that was provided.\n    var dfltFontColor = (dfltColor === containerIn.color) ? dfltColor : font.color;\n\n    var title = coerce('title.text');\n    if(title) {\n        Lib.coerceFont(coerce, 'title.font', {\n            family: font.family,\n            size: Math.round(font.size * 1.2),\n            color: dfltFontColor\n        });\n        coerce('title.offset');\n    }\n\n    coerce('tickangle');\n\n    var autoRange = coerce('autorange', !containerOut.isValidRange(containerIn.range));\n\n    if(autoRange) coerce('rangemode');\n\n    coerce('range');\n    containerOut.cleanRange();\n\n    coerce('fixedrange');\n\n    handleTickValueDefaults(containerIn, containerOut, coerce, axType);\n    handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options);\n    handleCategoryOrderDefaults(containerIn, containerOut, coerce, {\n        data: options.data,\n        dataAttr: letter\n    });\n\n    var gridColor = coerce2('gridcolor', addOpacity(dfltColor, 0.3));\n    var gridWidth = coerce2('gridwidth');\n    var showGrid = coerce('showgrid');\n\n    if(!showGrid) {\n        delete containerOut.gridcolor;\n        delete containerOut.gridwidth;\n    }\n\n    var startLineColor = coerce2('startlinecolor', dfltColor);\n    var startLineWidth = coerce2('startlinewidth', gridWidth);\n    var showStartLine = coerce('startline', containerOut.showgrid || !!startLineColor || !!startLineWidth);\n\n    if(!showStartLine) {\n        delete containerOut.startlinecolor;\n        delete containerOut.startlinewidth;\n    }\n\n    var endLineColor = coerce2('endlinecolor', dfltColor);\n    var endLineWidth = coerce2('endlinewidth', gridWidth);\n    var showEndLine = coerce('endline', containerOut.showgrid || !!endLineColor || !!endLineWidth);\n\n    if(!showEndLine) {\n        delete containerOut.endlinecolor;\n        delete containerOut.endlinewidth;\n    }\n\n    if(!showGrid) {\n        delete containerOut.gridcolor;\n        delete containerOut.gridWidth;\n    } else {\n        coerce('minorgridcount');\n        coerce('minorgridwidth', gridWidth);\n        coerce('minorgridcolor', addOpacity(gridColor, 0.06));\n\n        if(!containerOut.minorgridcount) {\n            delete containerOut.minorgridwidth;\n            delete containerOut.minorgridcolor;\n        }\n    }\n\n    if(containerOut.showticklabels === 'none') {\n        delete containerOut.tickfont;\n        delete containerOut.tickangle;\n        delete containerOut.showexponent;\n        delete containerOut.exponentformat;\n        delete containerOut.tickformat;\n        delete containerOut.showticksuffix;\n        delete containerOut.showtickprefix;\n    }\n\n    if(!containerOut.showticksuffix) {\n        delete containerOut.ticksuffix;\n    }\n\n    if(!containerOut.showtickprefix) {\n        delete containerOut.tickprefix;\n    }\n\n    // It needs to be coerced, then something above overrides this deep in the axis code,\n    // but no, we *actually* want to coerce this.\n    coerce('tickmode');\n\n    return containerOut;\n};\n\nfunction setAutoType(ax, data) {\n    // new logic: let people specify any type they want,\n    // only autotype if type is '-'\n    if(ax.type !== '-') return;\n\n    var id = ax._id;\n    var axLetter = id.charAt(0);\n\n    var calAttr = axLetter + 'calendar';\n    var calendar = ax[calAttr];\n\n    ax.type = autoType(data, calendar);\n}\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../../plots/cartesian/axis_autotype\":768,\"../../plots/cartesian/category_order_defaults\":771,\"../../plots/cartesian/set_convert\":785,\"../../plots/cartesian/tick_label_defaults\":786,\"../../plots/cartesian/tick_value_defaults\":788,\"../../registry\":847,\"./attributes\":898}],902:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar isArray1D = _dereq_('../../lib').isArray1D;\nvar cheaterBasis = _dereq_('./cheater_basis');\nvar arrayMinmax = _dereq_('./array_minmax');\nvar calcGridlines = _dereq_('./calc_gridlines');\nvar calcLabels = _dereq_('./calc_labels');\nvar calcClipPath = _dereq_('./calc_clippath');\nvar clean2dArray = _dereq_('../heatmap/clean_2d_array');\nvar smoothFill2dArray = _dereq_('./smooth_fill_2d_array');\nvar convertColumnData = _dereq_('../heatmap/convert_column_xyz');\nvar setConvert = _dereq_('./set_convert');\n\nmodule.exports = function calc(gd, trace) {\n    var xa = Axes.getFromId(gd, trace.xaxis);\n    var ya = Axes.getFromId(gd, trace.yaxis);\n    var aax = trace.aaxis;\n    var bax = trace.baxis;\n\n    var x = trace.x;\n    var y = trace.y;\n    var cols = [];\n    if(x && isArray1D(x)) cols.push('x');\n    if(y && isArray1D(y)) cols.push('y');\n\n    if(cols.length) {\n        convertColumnData(trace, aax, bax, 'a', 'b', cols);\n    }\n\n    var a = trace._a = trace._a || trace.a;\n    var b = trace._b = trace._b || trace.b;\n    x = trace._x || trace.x;\n    y = trace._y || trace.y;\n\n    var t = {};\n\n    if(trace._cheater) {\n        var avals = aax.cheatertype === 'index' ? a.length : a;\n        var bvals = bax.cheatertype === 'index' ? b.length : b;\n        x = cheaterBasis(avals, bvals, trace.cheaterslope);\n    }\n\n    trace._x = x = clean2dArray(x);\n    trace._y = y = clean2dArray(y);\n\n    // Fill in any undefined values with elliptic smoothing. This doesn't take\n    // into account the spacing of the values. That is, the derivatives should\n    // be modified to use a and b values. It's not that hard, but this is already\n    // moderate overkill for just filling in missing values.\n    smoothFill2dArray(x, a, b);\n    smoothFill2dArray(y, a, b);\n\n    setConvert(trace);\n\n    // create conversion functions that depend on the data\n    trace.setScale();\n\n    // This is a rather expensive scan. Nothing guarantees monotonicity,\n    // so we need to scan through all data to get proper ranges:\n    var xrange = arrayMinmax(x);\n    var yrange = arrayMinmax(y);\n\n    var dx = 0.5 * (xrange[1] - xrange[0]);\n    var xc = 0.5 * (xrange[1] + xrange[0]);\n\n    var dy = 0.5 * (yrange[1] - yrange[0]);\n    var yc = 0.5 * (yrange[1] + yrange[0]);\n\n    // Expand the axes to fit the plot, except just grow it by a factor of 1.3\n    // because the labels should be taken into account except that's difficult\n    // hence 1.3.\n    var grow = 1.3;\n    xrange = [xc - dx * grow, xc + dx * grow];\n    yrange = [yc - dy * grow, yc + dy * grow];\n\n    trace._extremes[xa._id] = Axes.findExtremes(xa, xrange, {padded: true});\n    trace._extremes[ya._id] = Axes.findExtremes(ya, yrange, {padded: true});\n\n    // Enumerate the gridlines, both major and minor, and store them on the trace\n    // object:\n    calcGridlines(trace, 'a', 'b');\n    calcGridlines(trace, 'b', 'a');\n\n    // Calculate the text labels for each major gridline and store them on the\n    // trace object:\n    calcLabels(trace, aax);\n    calcLabels(trace, bax);\n\n    // Tabulate points for the four segments that bound the axes so that we can\n    // map to pixel coordinates in the plot function and create a clip rect:\n    t.clipsegments = calcClipPath(trace._xctrl, trace._yctrl, aax, bax);\n\n    t.x = x;\n    t.y = y;\n    t.a = a;\n    t.b = b;\n\n    return [t];\n};\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../heatmap/clean_2d_array\":1003,\"../heatmap/convert_column_xyz\":1005,\"./array_minmax\":897,\"./calc_clippath\":903,\"./calc_gridlines\":904,\"./calc_labels\":905,\"./cheater_basis\":907,\"./set_convert\":920,\"./smooth_fill_2d_array\":921}],903:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = function makeClipPath(xctrl, yctrl, aax, bax) {\n    var i, x, y;\n    var segments = [];\n\n    var asmoothing = !!aax.smoothing;\n    var bsmoothing = !!bax.smoothing;\n    var nea1 = xctrl[0].length - 1;\n    var neb1 = xctrl.length - 1;\n\n    // Along the lower a axis:\n    for(i = 0, x = [], y = []; i <= nea1; i++) {\n        x[i] = xctrl[0][i];\n        y[i] = yctrl[0][i];\n    }\n    segments.push({x: x, y: y, bicubic: asmoothing});\n\n    // Along the upper b axis:\n    for(i = 0, x = [], y = []; i <= neb1; i++) {\n        x[i] = xctrl[i][nea1];\n        y[i] = yctrl[i][nea1];\n    }\n    segments.push({x: x, y: y, bicubic: bsmoothing});\n\n    // Backwards along the upper a axis:\n    for(i = nea1, x = [], y = []; i >= 0; i--) {\n        x[nea1 - i] = xctrl[neb1][i];\n        y[nea1 - i] = yctrl[neb1][i];\n    }\n    segments.push({x: x, y: y, bicubic: asmoothing});\n\n    // Backwards along the lower b axis:\n    for(i = neb1, x = [], y = []; i >= 0; i--) {\n        x[neb1 - i] = xctrl[i][0];\n        y[neb1 - i] = yctrl[i][0];\n    }\n    segments.push({x: x, y: y, bicubic: bsmoothing});\n\n    return segments;\n};\n\n},{}],904:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = function calcGridlines(trace, axisLetter, crossAxisLetter) {\n    var i, j, j0;\n    var eps, bounds, n1, n2, n, value, v;\n    var j1, v0, v1, d;\n\n    var data = trace['_' + axisLetter];\n    var axis = trace[axisLetter + 'axis'];\n\n    var gridlines = axis._gridlines = [];\n    var minorgridlines = axis._minorgridlines = [];\n    var boundarylines = axis._boundarylines = [];\n\n    var crossData = trace['_' + crossAxisLetter];\n    var crossAxis = trace[crossAxisLetter + 'axis'];\n\n    if(axis.tickmode === 'array') {\n        axis.tickvals = data.slice();\n    }\n\n    var xcp = trace._xctrl;\n    var ycp = trace._yctrl;\n    var nea = xcp[0].length;\n    var neb = xcp.length;\n    var na = trace._a.length;\n    var nb = trace._b.length;\n\n    Axes.prepTicks(axis);\n\n    // don't leave tickvals in axis looking like an attribute\n    if(axis.tickmode === 'array') delete axis.tickvals;\n\n    // The default is an empty array that will cause the join to remove the gridline if\n    // it's just disappeared:\n    // axis._startline = axis._endline = [];\n\n    // If the cross axis uses bicubic interpolation, then the grid\n    // lines fall once every three expanded grid row/cols:\n    var stride = axis.smoothing ? 3 : 1;\n\n    function constructValueGridline(value) {\n        var i, j, j0, tj, pxy, i0, ti, xy, dxydi0, dxydi1, dxydj0, dxydj1;\n        var xpoints = [];\n        var ypoints = [];\n        var ret = {};\n        // Search for the fractional grid index giving this line:\n        if(axisLetter === 'b') {\n            // For the position we use just the i-j coordinates:\n            j = trace.b2j(value);\n\n            // The derivatives for catmull-rom splines are discontinuous across cell\n            // boundaries though, so we need to provide both the cell and the position\n            // within the cell separately:\n            j0 = Math.floor(Math.max(0, Math.min(nb - 2, j)));\n            tj = j - j0;\n\n            ret.length = nb;\n            ret.crossLength = na;\n\n            ret.xy = function(i) {\n                return trace.evalxy([], i, j);\n            };\n\n            ret.dxy = function(i0, ti) {\n                return trace.dxydi([], i0, j0, ti, tj);\n            };\n\n            for(i = 0; i < na; i++) {\n                i0 = Math.min(na - 2, i);\n                ti = i - i0;\n                xy = trace.evalxy([], i, j);\n\n                if(crossAxis.smoothing && i > 0) {\n                    // First control point:\n                    dxydi0 = trace.dxydi([], i - 1, j0, 0, tj);\n                    xpoints.push(pxy[0] + dxydi0[0] / 3);\n                    ypoints.push(pxy[1] + dxydi0[1] / 3);\n\n                    // Second control point:\n                    dxydi1 = trace.dxydi([], i - 1, j0, 1, tj);\n                    xpoints.push(xy[0] - dxydi1[0] / 3);\n                    ypoints.push(xy[1] - dxydi1[1] / 3);\n                }\n\n                xpoints.push(xy[0]);\n                ypoints.push(xy[1]);\n\n                pxy = xy;\n            }\n        } else {\n            i = trace.a2i(value);\n            i0 = Math.floor(Math.max(0, Math.min(na - 2, i)));\n            ti = i - i0;\n\n            ret.length = na;\n            ret.crossLength = nb;\n\n            ret.xy = function(j) {\n                return trace.evalxy([], i, j);\n            };\n\n            ret.dxy = function(j0, tj) {\n                return trace.dxydj([], i0, j0, ti, tj);\n            };\n\n            for(j = 0; j < nb; j++) {\n                j0 = Math.min(nb - 2, j);\n                tj = j - j0;\n                xy = trace.evalxy([], i, j);\n\n                if(crossAxis.smoothing && j > 0) {\n                    // First control point:\n                    dxydj0 = trace.dxydj([], i0, j - 1, ti, 0);\n                    xpoints.push(pxy[0] + dxydj0[0] / 3);\n                    ypoints.push(pxy[1] + dxydj0[1] / 3);\n\n                    // Second control point:\n                    dxydj1 = trace.dxydj([], i0, j - 1, ti, 1);\n                    xpoints.push(xy[0] - dxydj1[0] / 3);\n                    ypoints.push(xy[1] - dxydj1[1] / 3);\n                }\n\n                xpoints.push(xy[0]);\n                ypoints.push(xy[1]);\n\n                pxy = xy;\n            }\n        }\n\n        ret.axisLetter = axisLetter;\n        ret.axis = axis;\n        ret.crossAxis = crossAxis;\n        ret.value = value;\n        ret.constvar = crossAxisLetter;\n        ret.index = n;\n        ret.x = xpoints;\n        ret.y = ypoints;\n        ret.smoothing = crossAxis.smoothing;\n\n        return ret;\n    }\n\n    function constructArrayGridline(idx) {\n        var j, i0, j0, ti, tj;\n        var xpoints = [];\n        var ypoints = [];\n        var ret = {};\n        ret.length = data.length;\n        ret.crossLength = crossData.length;\n\n        if(axisLetter === 'b') {\n            j0 = Math.max(0, Math.min(nb - 2, idx));\n            tj = Math.min(1, Math.max(0, idx - j0));\n\n            ret.xy = function(i) {\n                return trace.evalxy([], i, idx);\n            };\n\n            ret.dxy = function(i0, ti) {\n                return trace.dxydi([], i0, j0, ti, tj);\n            };\n\n            // In the tickmode: array case, this operation is a simple\n            // transfer of data:\n            for(j = 0; j < nea; j++) {\n                xpoints[j] = xcp[idx * stride][j];\n                ypoints[j] = ycp[idx * stride][j];\n            }\n        } else {\n            i0 = Math.max(0, Math.min(na - 2, idx));\n            ti = Math.min(1, Math.max(0, idx - i0));\n\n            ret.xy = function(j) {\n                return trace.evalxy([], idx, j);\n            };\n\n            ret.dxy = function(j0, tj) {\n                return trace.dxydj([], i0, j0, ti, tj);\n            };\n\n            // In the tickmode: array case, this operation is a simple\n            // transfer of data:\n            for(j = 0; j < neb; j++) {\n                xpoints[j] = xcp[j][idx * stride];\n                ypoints[j] = ycp[j][idx * stride];\n            }\n        }\n\n        ret.axisLetter = axisLetter;\n        ret.axis = axis;\n        ret.crossAxis = crossAxis;\n        ret.value = data[idx];\n        ret.constvar = crossAxisLetter;\n        ret.index = idx;\n        ret.x = xpoints;\n        ret.y = ypoints;\n        ret.smoothing = crossAxis.smoothing;\n\n        return ret;\n    }\n\n    if(axis.tickmode === 'array') {\n        // var j0 = axis.startline ? 1 : 0;\n        // var j1 = data.length - (axis.endline ? 1 : 0);\n\n        eps = 5e-15;\n        bounds = [\n            Math.floor(((data.length - 1) - axis.arraytick0) / axis.arraydtick * (1 + eps)),\n            Math.ceil((- axis.arraytick0) / axis.arraydtick / (1 + eps))\n        ].sort(function(a, b) {return a - b;});\n\n        // Unpack sorted values so we can be sure to avoid infinite loops if something\n        // is backwards:\n        n1 = bounds[0] - 1;\n        n2 = bounds[1] + 1;\n\n        // If the axes fall along array lines, then this is a much simpler process since\n        // we already have all the control points we need\n        for(n = n1; n < n2; n++) {\n            j = axis.arraytick0 + axis.arraydtick * n;\n            if(j < 0 || j > data.length - 1) continue;\n            gridlines.push(extendFlat(constructArrayGridline(j), {\n                color: axis.gridcolor,\n                width: axis.gridwidth\n            }));\n        }\n\n        for(n = n1; n < n2; n++) {\n            j0 = axis.arraytick0 + axis.arraydtick * n;\n            j1 = Math.min(j0 + axis.arraydtick, data.length - 1);\n\n            // TODO: fix the bounds computation so we don't have to do a large range and then throw\n            // out unneeded numbers\n            if(j0 < 0 || j0 > data.length - 1) continue;\n            if(j1 < 0 || j1 > data.length - 1) continue;\n\n            v0 = data[j0];\n            v1 = data[j1];\n\n            for(i = 0; i < axis.minorgridcount; i++) {\n                d = j1 - j0;\n\n                // TODO: fix the bounds computation so we don't have to do a large range and then throw\n                // out unneeded numbers\n                if(d <= 0) continue;\n\n                // XXX: This calculation isn't quite right. Off by one somewhere?\n                v = v0 + (v1 - v0) * (i + 1) / (axis.minorgridcount + 1) * (axis.arraydtick / d);\n\n                // TODO: fix the bounds computation so we don't have to do a large range and then throw\n                // out unneeded numbers\n                if(v < data[0] || v > data[data.length - 1]) continue;\n                minorgridlines.push(extendFlat(constructValueGridline(v), {\n                    color: axis.minorgridcolor,\n                    width: axis.minorgridwidth\n                }));\n            }\n        }\n\n        if(axis.startline) {\n            boundarylines.push(extendFlat(constructArrayGridline(0), {\n                color: axis.startlinecolor,\n                width: axis.startlinewidth\n            }));\n        }\n\n        if(axis.endline) {\n            boundarylines.push(extendFlat(constructArrayGridline(data.length - 1), {\n                color: axis.endlinecolor,\n                width: axis.endlinewidth\n            }));\n        }\n    } else {\n        // If the lines do not fall along the axes, then we have to interpolate\n        // the contro points and so some math to figure out where the lines are\n        // in the first place.\n\n        // Compute the integer boudns of tick0 + n * dtick that fall within the range\n        // (roughly speaking):\n        // Give this a nice generous epsilon. We use at as * (1 + eps) in order to make\n        // inequalities a little tolerant in a more or less correct manner:\n        eps = 5e-15;\n        bounds = [\n            Math.floor((data[data.length - 1] - axis.tick0) / axis.dtick * (1 + eps)),\n            Math.ceil((data[0] - axis.tick0) / axis.dtick / (1 + eps))\n        ].sort(function(a, b) {return a - b;});\n\n        // Unpack sorted values so we can be sure to avoid infinite loops if something\n        // is backwards:\n        n1 = bounds[0];\n        n2 = bounds[1];\n\n        for(n = n1; n <= n2; n++) {\n            value = axis.tick0 + axis.dtick * n;\n\n            gridlines.push(extendFlat(constructValueGridline(value), {\n                color: axis.gridcolor,\n                width: axis.gridwidth\n            }));\n        }\n\n        for(n = n1 - 1; n < n2 + 1; n++) {\n            value = axis.tick0 + axis.dtick * n;\n\n            for(i = 0; i < axis.minorgridcount; i++) {\n                v = value + axis.dtick * (i + 1) / (axis.minorgridcount + 1);\n                if(v < data[0] || v > data[data.length - 1]) continue;\n                minorgridlines.push(extendFlat(constructValueGridline(v), {\n                    color: axis.minorgridcolor,\n                    width: axis.minorgridwidth\n                }));\n            }\n        }\n\n        if(axis.startline) {\n            boundarylines.push(extendFlat(constructValueGridline(data[0]), {\n                color: axis.startlinecolor,\n                width: axis.startlinewidth\n            }));\n        }\n\n        if(axis.endline) {\n            boundarylines.push(extendFlat(constructValueGridline(data[data.length - 1]), {\n                color: axis.endlinecolor,\n                width: axis.endlinewidth\n            }));\n        }\n    }\n};\n\n},{\"../../lib/extend\":710,\"../../plots/cartesian/axes\":767}],905:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = function calcLabels(trace, axis) {\n    var i, tobj, prefix, suffix, gridline;\n\n    var labels = axis._labels = [];\n    var gridlines = axis._gridlines;\n\n    for(i = 0; i < gridlines.length; i++) {\n        gridline = gridlines[i];\n\n        if(['start', 'both'].indexOf(axis.showticklabels) !== -1) {\n            tobj = Axes.tickText(axis, gridline.value);\n\n            extendFlat(tobj, {\n                prefix: prefix,\n                suffix: suffix,\n                endAnchor: true,\n                xy: gridline.xy(0),\n                dxy: gridline.dxy(0, 0),\n                axis: gridline.axis,\n                length: gridline.crossAxis.length,\n                font: gridline.axis.tickfont,\n                isFirst: i === 0,\n                isLast: i === gridlines.length - 1\n            });\n\n            labels.push(tobj);\n        }\n\n        if(['end', 'both'].indexOf(axis.showticklabels) !== -1) {\n            tobj = Axes.tickText(axis, gridline.value);\n\n            extendFlat(tobj, {\n                endAnchor: false,\n                xy: gridline.xy(gridline.crossLength - 1),\n                dxy: gridline.dxy(gridline.crossLength - 2, 1),\n                axis: gridline.axis,\n                length: gridline.crossAxis.length,\n                font: gridline.axis.tickfont,\n                isFirst: i === 0,\n                isLast: i === gridlines.length - 1\n            });\n\n            labels.push(tobj);\n        }\n    }\n};\n\n},{\"../../lib/extend\":710,\"../../plots/cartesian/axes\":767}],906:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/*\n * Compute the tangent vector according to catmull-rom cubic splines (centripetal,\n * I think). That differs from the control point in two ways:\n *   1. It is a vector, not a position relative to the point\n *   2. the vector is longer than the position relative to p1 by a factor of 3\n *\n * Close to the boundaries, we'll use these as *quadratic control points, so that\n * to make a nice grid, we'll need to divide the tangent by 2 instead of 3. (The\n * math works out this way if you work through the bezier derivatives)\n */\nvar CatmullRomExp = 0.5;\nmodule.exports = function makeControlPoints(p0, p1, p2, smoothness) {\n    var d1x = p0[0] - p1[0];\n    var d1y = p0[1] - p1[1];\n    var d2x = p2[0] - p1[0];\n    var d2y = p2[1] - p1[1];\n    var d1a = Math.pow(d1x * d1x + d1y * d1y, CatmullRomExp / 2);\n    var d2a = Math.pow(d2x * d2x + d2y * d2y, CatmullRomExp / 2);\n    var numx = (d2a * d2a * d1x - d1a * d1a * d2x) * smoothness;\n    var numy = (d2a * d2a * d1y - d1a * d1a * d2y) * smoothness;\n    var denom1 = d2a * (d1a + d2a) * 3;\n    var denom2 = d1a * (d1a + d2a) * 3;\n\n    return [[\n        p1[0] + (denom1 && numx / denom1),\n        p1[1] + (denom1 && numy / denom1)\n    ], [\n        p1[0] - (denom2 && numx / denom2),\n        p1[1] - (denom2 && numy / denom2)\n    ]];\n};\n\n},{}],907:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\n\n/*\n * Construct a 2D array of cheater values given a, b, and a slope.\n * If\n */\nmodule.exports = function(a, b, cheaterslope) {\n    var i, j, ascal, bscal, aval, bval;\n    var data = [];\n\n    var na = isArrayOrTypedArray(a) ? a.length : a;\n    var nb = isArrayOrTypedArray(b) ? b.length : b;\n    var adata = isArrayOrTypedArray(a) ? a : null;\n    var bdata = isArrayOrTypedArray(b) ? b : null;\n\n    // If we're using data, scale it so that for data that's just barely\n    // not evenly spaced, the switch to value-based indexing is continuous.\n    // This means evenly spaced data should look the same whether value\n    // or index cheatertype.\n    if(adata) {\n        ascal = (adata.length - 1) / (adata[adata.length - 1] - adata[0]) / (na - 1);\n    }\n\n    if(bdata) {\n        bscal = (bdata.length - 1) / (bdata[bdata.length - 1] - bdata[0]) / (nb - 1);\n    }\n\n    var xval;\n    var xmin = Infinity;\n    var xmax = -Infinity;\n    for(j = 0; j < nb; j++) {\n        data[j] = [];\n        bval = bdata ? (bdata[j] - bdata[0]) * bscal : j / (nb - 1);\n        for(i = 0; i < na; i++) {\n            aval = adata ? (adata[i] - adata[0]) * ascal : i / (na - 1);\n            xval = aval - bval * cheaterslope;\n            xmin = Math.min(xval, xmin);\n            xmax = Math.max(xval, xmax);\n            data[j][i] = xval;\n        }\n    }\n\n    // Normalize cheater values to the 0-1 range. This comes into play when you have\n    // multiple cheater plots. After careful consideration, it seems better if cheater\n    // values are normalized to a consistent range. Otherwise one cheater affects the\n    // layout of other cheaters on the same axis.\n    var slope = 1.0 / (xmax - xmin);\n    var offset = -xmin * slope;\n    for(j = 0; j < nb; j++) {\n        for(i = 0; i < na; i++) {\n            data[j][i] = slope * data[j][i] + offset;\n        }\n    }\n\n    return data;\n};\n\n},{\"../../lib\":719}],908:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar makeControlPoints = _dereq_('./catmull_rom');\nvar ensureArray = _dereq_('../../lib').ensureArray;\n\n/*\n * Turns a coarse grid into a fine grid with control points.\n *\n * Here's an ASCII representation:\n *\n *       o ----- o ----- o ----- o\n *       |       |       |       |\n *       |       |       |       |\n *       |       |       |       |\n *       o ----- o ----- o ----- o\n *       |       |       |       |\n *       |       |       |       |\n *    ^  |       |       |       |\n *    |  o ----- o ----- o ----- o\n *  b |  |       |       |       |\n *    |  |       |       |       |\n *    |  |       |       |       |\n *       o ----- o ----- o ----- o\n *         ------>\n *           a\n *\n * First of all, note that we want to do this in *cartesian* space. This means\n * we might run into problems when there are extreme differences in x/y scaling,\n * but the alternative is that the topology of the contours might actually be\n * view-dependent, which seems worse. As a fallback, the only parameter that\n * actually affects the result is the *aspect ratio*, so that we can at least\n * improve the situation a bit without going all the way to screen coordinates.\n *\n * This function flattens the points + tangents  into a slightly denser grid of\n * *control points*. The resulting grid looks like this:\n *\n *       9 +--o-o--+ -o-o--+--o-o--+\n *       8 o  o o  o  o o  o  o o  o\n *         |       |       |       |\n *       7 o  o o  o  o o  o  o o  o\n *       6 +--o-o--+ -o-o--+--o-o--+\n *       5 o  o o  o  o o  o  o o  o\n *         |       |       |       |\n *    ^  4 o  o o  o  o o  o  o o  o\n *    |  3 +--o-o--+ -o-o--+--o-o--+\n *  b |  2 o  o o  o  o o  o  o o  o\n *    |    |       |       |       |\n *    |  1 o  o o  o  o o  o  o o  o\n *       0 +--o-o--+ -o-o--+--o-o--+\n *         0  1 2  3  4 5  6  7 8  9\n *         ------>\n *           a\n *\n * where `o`s represent newly-computed control points. the resulting dimension is\n *\n *     (m - 1) * 3 + 1\n *   = 3 * m - 2\n *\n * We could simply store the tangents separately, but that's a nightmare to organize\n * in two dimensions since we'll be slicing grid lines in both directions and since\n * that basically requires very nearly just as much storage as just storing the dense\n * grid.\n *\n * Wow!\n */\n\n\n/*\n * Catmull-rom is biased at the boundaries toward the interior and we actually\n * can't use catmull-rom to compute the control point closest to (but inside)\n * the boundary.\n *\n * A note on plotly's spline interpolation. It uses the catmull rom control point\n * closest to the boundary *as* a quadratic control point. This seems incorrect,\n * so I've elected not to follow that. Given control points 0 and 1, regular plotly\n * splines give *equivalent* cubic control points:\n *\n * Input:\n *\n *   boundary\n *     |                    |\n *     p0           p2      p3    --> interior\n *     0.0          0.667   1.0\n *     |                    |\n *\n * Cubic-equivalent of what plotly splines draw::\n *\n *   boundary\n *     |                    |\n *     p0   p1      p2      p3    --> interior\n *     0.0  0.4444  0.8888  1.0\n *     |                    |\n *\n * What this function fills in:\n *\n *   boundary\n *     |                    |\n *     p0    p1     p2      p3    --> interior\n *     0.0   0.333  0.667   1.0\n *     |                    |\n *\n * Parameters:\n *   p0: boundary point\n *   p2: catmull rom point based on computation at p3\n *   p3: first grid point\n *\n * Of course it works whichever way it's oriented; you just need to interpret the\n * input/output accordingly.\n */\nfunction inferCubicControlPoint(p0, p2, p3) {\n    // Extend p1 away from p0 by 50%. This is the equivalent quadratic point that\n    // would give the same slope as catmull rom at p0.\n    var p2e0 = -0.5 * p3[0] + 1.5 * p2[0];\n    var p2e1 = -0.5 * p3[1] + 1.5 * p2[1];\n\n    return [\n        (2 * p2e0 + p0[0]) / 3,\n        (2 * p2e1 + p0[1]) / 3,\n    ];\n}\n\nmodule.exports = function computeControlPoints(xe, ye, x, y, asmoothing, bsmoothing) {\n    var i, j, ie, je, xej, yej, xj, yj, cp, p1;\n    // At this point, we know these dimensions are correct and representative of\n    // the whole 2D arrays:\n    var na = x[0].length;\n    var nb = x.length;\n\n    // (n)umber of (e)xpanded points:\n    var nea = asmoothing ? 3 * na - 2 : na;\n    var neb = bsmoothing ? 3 * nb - 2 : nb;\n\n    xe = ensureArray(xe, neb);\n    ye = ensureArray(ye, neb);\n\n    for(ie = 0; ie < neb; ie++) {\n        xe[ie] = ensureArray(xe[ie], nea);\n        ye[ie] = ensureArray(ye[ie], nea);\n    }\n\n    // This loop fills in the X'd points:\n    //\n    //    .       .       .       .\n    //    .       .       .       .\n    //    |       |       |       |\n    //    |       |       |       |\n    //    X ----- X ----- X ----- X\n    //    |       |       |       |\n    //    |       |       |       |\n    //    |       |       |       |\n    //    X ----- X ----- X ----- X\n    //\n    //\n    // ie = (i) (e)xpanded:\n    for(j = 0, je = 0; j < nb; j++, je += bsmoothing ? 3 : 1) {\n        xej = xe[je];\n        yej = ye[je];\n        xj = x[j];\n        yj = y[j];\n\n        // je = (j) (e)xpanded:\n        for(i = 0, ie = 0; i < na; i++, ie += asmoothing ? 3 : 1) {\n            xej[ie] = xj[i];\n            yej[ie] = yj[i];\n        }\n    }\n\n    if(asmoothing) {\n        // If there's a-smoothing, this loop fills in the X'd points with catmull-rom\n        // control points computed along the a-axis:\n        //     .       .       .       .\n        //     .       .       .       .\n        //     |       |       |       |\n        //     |       |       |       |\n        //     o -Y-X- o -X-X- o -X-Y- o\n        //     |       |       |       |\n        //     |       |       |       |\n        //     |       |       |       |\n        //     o -Y-X- o -X-X- o -X-Y- o\n        //\n        // i:  0       1       2       3\n        // ie: 0  1 3  3  4 5  6  7 8  9\n        //\n        //           ------>\n        //             a\n        //\n        for(j = 0, je = 0; j < nb; j++, je += bsmoothing ? 3 : 1) {\n            // Fill in the points marked X for this a-row:\n            for(i = 1, ie = 3; i < na - 1; i++, ie += 3) {\n                cp = makeControlPoints(\n                    [x[j][i - 1], y[j][i - 1]],\n                    [x[j][i ], y[j][i]],\n                    [x[j][i + 1], y[j][i + 1]],\n                    asmoothing\n                );\n\n                xe[je][ie - 1] = cp[0][0];\n                ye[je][ie - 1] = cp[0][1];\n                xe[je][ie + 1] = cp[1][0];\n                ye[je][ie + 1] = cp[1][1];\n            }\n\n            // The very first cubic interpolation point (to the left for i = 1 above) is\n            // used as a *quadratic* interpolation point by the spline drawing function\n            // which isn't really correct. But for the sake of consistency, we'll use it\n            // as such. Since we're using cubic splines, that means we need to shorten the\n            // tangent by 1/3 and also construct a new cubic spline control point 1/3 from\n            // the original to the i = 0 point.\n            p1 = inferCubicControlPoint(\n                [xe[je][0], ye[je][0]],\n                [xe[je][2], ye[je][2]],\n                [xe[je][3], ye[je][3]]\n            );\n            xe[je][1] = p1[0];\n            ye[je][1] = p1[1];\n\n            // Ditto last points, sans explanation:\n            p1 = inferCubicControlPoint(\n                [xe[je][nea - 1], ye[je][nea - 1]],\n                [xe[je][nea - 3], ye[je][nea - 3]],\n                [xe[je][nea - 4], ye[je][nea - 4]]\n            );\n            xe[je][nea - 2] = p1[0];\n            ye[je][nea - 2] = p1[1];\n        }\n    }\n\n    if(bsmoothing) {\n        // If there's a-smoothing, this loop fills in the X'd points with catmull-rom\n        // control points computed along the b-axis:\n        //     .       .       .       .\n        //     X  X X  X  X X  X  X X  X\n        //     |       |       |       |\n        //     X  X X  X  X X  X  X X  X\n        //     o -o-o- o -o-o- o -o-o- o\n        //     X  X X  X  X X  X  X X  X\n        //     |       |       |       |\n        //     Y  Y Y  Y  Y Y  Y  Y Y  Y\n        //     o -o-o- o -o-o- o -o-o- o\n        //\n        // i:  0       1       2       3\n        // ie: 0  1 3  3  4 5  6  7 8  9\n        //\n        //           ------>\n        //             a\n        //\n        for(ie = 0; ie < nea; ie++) {\n            for(je = 3; je < neb - 3; je += 3) {\n                cp = makeControlPoints(\n                    [xe[je - 3][ie], ye[je - 3][ie]],\n                    [xe[je][ie], ye[je][ie]],\n                    [xe[je + 3][ie], ye[je + 3][ie]],\n                    bsmoothing\n                );\n\n                xe[je - 1][ie] = cp[0][0];\n                ye[je - 1][ie] = cp[0][1];\n                xe[je + 1][ie] = cp[1][0];\n                ye[je + 1][ie] = cp[1][1];\n            }\n            // Do the same boundary condition magic for these control points marked Y above:\n            p1 = inferCubicControlPoint(\n                [xe[0][ie], ye[0][ie]],\n                [xe[2][ie], ye[2][ie]],\n                [xe[3][ie], ye[3][ie]]\n            );\n            xe[1][ie] = p1[0];\n            ye[1][ie] = p1[1];\n\n            p1 = inferCubicControlPoint(\n                [xe[neb - 1][ie], ye[neb - 1][ie]],\n                [xe[neb - 3][ie], ye[neb - 3][ie]],\n                [xe[neb - 4][ie], ye[neb - 4][ie]]\n            );\n            xe[neb - 2][ie] = p1[0];\n            ye[neb - 2][ie] = p1[1];\n        }\n    }\n\n    if(asmoothing && bsmoothing) {\n        // Do one more pass, this time recomputing exactly what we just computed.\n        // It's overdetermined since we're peforming catmull-rom in two directions,\n        // so we'll just average the overdetermined. These points don't lie along the\n        // grid lines, so note that only grid lines will follow normal plotly spline\n        // interpolation.\n        //\n        // Unless of course there was no b smoothing. Then these intermediate points\n        // don't actually exist and this section is bypassed.\n        //     .       .       .       .\n        //     o  X X  o  X X  o  X X  o\n        //     |       |       |       |\n        //     o  X X  o  X X  o  X X  o\n        //     o -o-o- o -o-o- o -o-o- o\n        //     o  X X  o  X X  o  X X  o\n        //     |       |       |       |\n        //     o  Y Y  o  Y Y  o  Y Y  o\n        //     o -o-o- o -o-o- o -o-o- o\n        //\n        // i:  0       1       2       3\n        // ie: 0  1 3  3  4 5  6  7 8  9\n        //\n        //           ------>\n        //             a\n        //\n        for(je = 1; je < neb; je += (je + 1) % 3 === 0 ? 2 : 1) {\n            // Fill in the points marked X for this a-row:\n            for(ie = 3; ie < nea - 3; ie += 3) {\n                cp = makeControlPoints(\n                    [xe[je][ie - 3], ye[je][ie - 3]],\n                    [xe[je][ie], ye[je][ie]],\n                    [xe[je][ie + 3], ye[je][ie + 3]],\n                    asmoothing\n                );\n\n                xe[je][ie - 1] = 0.5 * (xe[je][ie - 1] + cp[0][0]);\n                ye[je][ie - 1] = 0.5 * (ye[je][ie - 1] + cp[0][1]);\n                xe[je][ie + 1] = 0.5 * (xe[je][ie + 1] + cp[1][0]);\n                ye[je][ie + 1] = 0.5 * (ye[je][ie + 1] + cp[1][1]);\n            }\n\n            // This case is just slightly different. The computation is the same,\n            // but having computed this, we'll average with the existing result.\n            p1 = inferCubicControlPoint(\n                [xe[je][0], ye[je][0]],\n                [xe[je][2], ye[je][2]],\n                [xe[je][3], ye[je][3]]\n            );\n            xe[je][1] = 0.5 * (xe[je][1] + p1[0]);\n            ye[je][1] = 0.5 * (ye[je][1] + p1[1]);\n\n            p1 = inferCubicControlPoint(\n                [xe[je][nea - 1], ye[je][nea - 1]],\n                [xe[je][nea - 3], ye[je][nea - 3]],\n                [xe[je][nea - 4], ye[je][nea - 4]]\n            );\n            xe[je][nea - 2] = 0.5 * (xe[je][nea - 2] + p1[0]);\n            ye[je][nea - 2] = 0.5 * (ye[je][nea - 2] + p1[1]);\n        }\n    }\n\n    return [xe, ye];\n};\n\n},{\"../../lib\":719,\"./catmull_rom\":906}],909:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = {\n    RELATIVE_CULL_TOLERANCE: 1e-6\n};\n\n},{}],910:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/*\n * Evaluates the derivative of a list of control point arrays. That is, it expects an array or arrays\n * that are expanded relative to the raw data to include the bicubic control points, if applicable. If\n * only linear interpolation is desired, then the data points correspond 1-1 along that axis to the\n * data itself. Since it's catmull-rom splines in either direction note in particular that the\n * derivatives are discontinuous across cell boundaries. That's the reason you need both the *cell*\n * and the *point within the cell*.\n *\n * Also note that the discontinuity of the derivative is in magnitude only. The direction *is*\n * continuous across cell boundaries.\n *\n * For example, to compute the derivative of the xcoordinate halfway betwen the 7 and 8th i-gridpoints\n * and the 10th and 11th j-gridpoints given bicubic smoothing in both dimensions, you'd write:\n *\n *     var deriv = createIDerivativeEvaluator([x], 1, 1);\n *\n *     var dxdi = deriv([], 7, 10, 0.5, 0.5);\n *     // => [0.12345]\n *\n * Since there'd be a bunch of duplicate computation to compute multiple derivatives, you can double\n * this up by providing more arrays:\n *\n *     var deriv = createIDerivativeEvaluator([x, y], 1, 1);\n *\n *     var dxdi = deriv([], 7, 10, 0.5, 0.5);\n *     // => [0.12345, 0.78910]\n *\n * NB: It's presumed that at this point all data has been sanitized and is valid numerical data arrays\n * of the correct dimension.\n */\nmodule.exports = function(arrays, asmoothing, bsmoothing) {\n    if(asmoothing && bsmoothing) {\n        return function(out, i0, j0, u, v) {\n            if(!out) out = [];\n            var f0, f1, f2, f3, ak, k;\n\n            // Since it's a grid of control points, the actual indices are * 3:\n            i0 *= 3;\n            j0 *= 3;\n\n            // Precompute some numbers:\n            var u2 = u * u;\n            var ou = 1 - u;\n            var ou2 = ou * ou;\n            var ouu2 = ou * u * 2;\n            var a = -3 * ou2;\n            var b = 3 * (ou2 - ouu2);\n            var c = 3 * (ouu2 - u2);\n            var d = 3 * u2;\n\n            var v2 = v * v;\n            var v3 = v2 * v;\n            var ov = 1 - v;\n            var ov2 = ov * ov;\n            var ov3 = ov2 * ov;\n\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                // Compute the derivatives in the u-direction:\n                f0 = a * ak[j0 ][i0] + b * ak[j0 ][i0 + 1] + c * ak[j0 ][i0 + 2] + d * ak[j0 ][i0 + 3];\n                f1 = a * ak[j0 + 1][i0] + b * ak[j0 + 1][i0 + 1] + c * ak[j0 + 1][i0 + 2] + d * ak[j0 + 1][i0 + 3];\n                f2 = a * ak[j0 + 2][i0] + b * ak[j0 + 2][i0 + 1] + c * ak[j0 + 2][i0 + 2] + d * ak[j0 + 2][i0 + 3];\n                f3 = a * ak[j0 + 3][i0] + b * ak[j0 + 3][i0 + 1] + c * ak[j0 + 3][i0 + 2] + d * ak[j0 + 3][i0 + 3];\n\n                // Now just interpolate in the v-direction since it's all separable:\n                out[k] = ov3 * f0 + 3 * (ov2 * v * f1 + ov * v2 * f2) + v3 * f3;\n            }\n\n            return out;\n        };\n    } else if(asmoothing) {\n        // Handle smooth in the a-direction but linear in the b-direction by performing four\n        // linear interpolations followed by one cubic interpolation of the result\n        return function(out, i0, j0, u, v) {\n            if(!out) out = [];\n            var f0, f1, k, ak;\n            i0 *= 3;\n            var u2 = u * u;\n            var ou = 1 - u;\n            var ou2 = ou * ou;\n            var ouu2 = ou * u * 2;\n            var a = -3 * ou2;\n            var b = 3 * (ou2 - ouu2);\n            var c = 3 * (ouu2 - u2);\n            var d = 3 * u2;\n            var ov = 1 - v;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = a * ak[j0 ][i0] + b * ak[j0 ][i0 + 1] + c * ak[j0 ][i0 + 2] + d * ak[j0 ][i0 + 3];\n                f1 = a * ak[j0 + 1][i0] + b * ak[j0 + 1][i0 + 1] + c * ak[j0 + 1][i0 + 2] + d * ak[j0 + 1][i0 + 3];\n\n                out[k] = ov * f0 + v * f1;\n            }\n            return out;\n        };\n    } else if(bsmoothing) {\n        // Same as the above case, except reversed. I've disabled the no-unused vars rule\n        // so that this function is fully interpolation-agnostic. Otherwise it would need\n        // to be called differently in different cases. Which wouldn't be the worst, but\n        /* eslint-disable no-unused-vars */\n        return function(out, i0, j0, u, v) {\n        /* eslint-enable no-unused-vars */\n            if(!out) out = [];\n            var f0, f1, f2, f3, k, ak;\n            j0 *= 3;\n            var v2 = v * v;\n            var v3 = v2 * v;\n            var ov = 1 - v;\n            var ov2 = ov * ov;\n            var ov3 = ov2 * ov;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = ak[j0][i0 + 1] - ak[j0][i0];\n                f1 = ak[j0 + 1][i0 + 1] - ak[j0 + 1][i0];\n                f2 = ak[j0 + 2][i0 + 1] - ak[j0 + 2][i0];\n                f3 = ak[j0 + 3][i0 + 1] - ak[j0 + 3][i0];\n\n                out[k] = ov3 * f0 + 3 * (ov2 * v * f1 + ov * v2 * f2) + v3 * f3;\n            }\n            return out;\n        };\n    } else {\n        // Finally, both directions are linear:\n        /* eslint-disable no-unused-vars */\n        return function(out, i0, j0, u, v) {\n        /* eslint-enable no-unused-vars */\n            if(!out) out = [];\n            var f0, f1, k, ak;\n            var ov = 1 - v;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = ak[j0][i0 + 1] - ak[j0][i0];\n                f1 = ak[j0 + 1][i0 + 1] - ak[j0 + 1][i0];\n\n                out[k] = ov * f0 + v * f1;\n            }\n            return out;\n        };\n    }\n};\n\n},{}],911:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function(arrays, asmoothing, bsmoothing) {\n    if(asmoothing && bsmoothing) {\n        return function(out, i0, j0, u, v) {\n            if(!out) out = [];\n            var f0, f1, f2, f3, ak, k;\n\n            // Since it's a grid of control points, the actual indices are * 3:\n            i0 *= 3;\n            j0 *= 3;\n\n            // Precompute some numbers:\n            var u2 = u * u;\n            var u3 = u2 * u;\n            var ou = 1 - u;\n            var ou2 = ou * ou;\n            var ou3 = ou2 * ou;\n\n            var v2 = v * v;\n            var ov = 1 - v;\n            var ov2 = ov * ov;\n            var ovv2 = ov * v * 2;\n            var a = -3 * ov2;\n            var b = 3 * (ov2 - ovv2);\n            var c = 3 * (ovv2 - v2);\n            var d = 3 * v2;\n\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n\n                // Compute the derivatives in the v-direction:\n                f0 = a * ak[j0][i0] + b * ak[j0 + 1][i0] + c * ak[j0 + 2][i0] + d * ak[j0 + 3][i0];\n                f1 = a * ak[j0][i0 + 1] + b * ak[j0 + 1][i0 + 1] + c * ak[j0 + 2][i0 + 1] + d * ak[j0 + 3][i0 + 1];\n                f2 = a * ak[j0][i0 + 2] + b * ak[j0 + 1][i0 + 2] + c * ak[j0 + 2][i0 + 2] + d * ak[j0 + 3][i0 + 2];\n                f3 = a * ak[j0][i0 + 3] + b * ak[j0 + 1][i0 + 3] + c * ak[j0 + 2][i0 + 3] + d * ak[j0 + 3][i0 + 3];\n\n                // Now just interpolate in the v-direction since it's all separable:\n                out[k] = ou3 * f0 + 3 * (ou2 * u * f1 + ou * u2 * f2) + u3 * f3;\n            }\n\n            return out;\n        };\n    } else if(asmoothing) {\n        // Handle smooth in the a-direction but linear in the b-direction by performing four\n        // linear interpolations followed by one cubic interpolation of the result\n        return function(out, i0, j0, v, u) {\n            if(!out) out = [];\n            var f0, f1, f2, f3, k, ak;\n            i0 *= 3;\n            var u2 = u * u;\n            var u3 = u2 * u;\n            var ou = 1 - u;\n            var ou2 = ou * ou;\n            var ou3 = ou2 * ou;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n\n                f0 = ak[j0 + 1][i0] - ak[j0][i0];\n                f1 = ak[j0 + 1][i0 + 1] - ak[j0][i0 + 1];\n                f2 = ak[j0 + 1][i0 + 2] - ak[j0][i0 + 2];\n                f3 = ak[j0 + 1][i0 + 3] - ak[j0][i0 + 3];\n\n                out[k] = ou3 * f0 + 3 * (ou2 * u * f1 + ou * u2 * f2) + u3 * f3;\n\n                // mathematically equivalent:\n                // f0 = ou3 * ak[j0    ][i0] + 3 * (ou2 * u * ak[j0    ][i0 + 1] + ou * u2 * ak[j0    ][i0 + 2]) + u3 * ak[j0    ][i0 + 3];\n                // f1 = ou3 * ak[j0 + 1][i0] + 3 * (ou2 * u * ak[j0 + 1][i0 + 1] + ou * u2 * ak[j0 + 1][i0 + 2]) + u3 * ak[j0 + 1][i0 + 3];\n                // out[k] = f1 - f0;\n            }\n            return out;\n        };\n    } else if(bsmoothing) {\n        // Same as the above case, except reversed:\n        /* eslint-disable no-unused-vars */\n        return function(out, i0, j0, u, v) {\n        /* eslint-enable no-unused-vars */\n            if(!out) out = [];\n            var f0, f1, k, ak;\n            j0 *= 3;\n            var ou = 1 - u;\n            var v2 = v * v;\n            var ov = 1 - v;\n            var ov2 = ov * ov;\n            var ovv2 = ov * v * 2;\n            var a = -3 * ov2;\n            var b = 3 * (ov2 - ovv2);\n            var c = 3 * (ovv2 - v2);\n            var d = 3 * v2;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = a * ak[j0][i0] + b * ak[j0 + 1][i0] + c * ak[j0 + 2][i0] + d * ak[j0 + 3][i0];\n                f1 = a * ak[j0][i0 + 1] + b * ak[j0 + 1][i0 + 1] + c * ak[j0 + 2][i0 + 1] + d * ak[j0 + 3][i0 + 1];\n\n                out[k] = ou * f0 + u * f1;\n            }\n            return out;\n        };\n    } else {\n        // Finally, both directions are linear:\n        /* eslint-disable no-unused-vars */\n        return function(out, i0, j0, v, u) {\n        /* eslint-enable no-unused-vars */\n            if(!out) out = [];\n            var f0, f1, k, ak;\n            var ov = 1 - v;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = ak[j0 + 1][i0] - ak[j0][i0];\n                f1 = ak[j0 + 1][i0 + 1] - ak[j0][i0 + 1];\n\n                out[k] = ov * f0 + v * f1;\n            }\n            return out;\n        };\n    }\n};\n\n},{}],912:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/*\n * Return a function that evaluates a set of linear or bicubic control points.\n * This will get evaluated a lot, so we'll at least do a bit of extra work to\n * flatten some of the choices. In particular, we'll unroll the linear/bicubic\n * combinations and we'll allow computing results in parallel to cut down\n * on repeated arithmetic.\n *\n * Take note that we don't search for the correct range in this function. The\n * reason is for consistency due to the corrresponding derivative function. In\n * particular, the derivatives aren't continuous across cells, so it's important\n * to be able control whether the derivative at a cell boundary is approached\n * from one side or the other.\n */\nmodule.exports = function(arrays, na, nb, asmoothing, bsmoothing) {\n    var imax = na - 2;\n    var jmax = nb - 2;\n\n    if(asmoothing && bsmoothing) {\n        return function(out, i, j) {\n            if(!out) out = [];\n            var f0, f1, f2, f3, ak, k;\n\n            var i0 = Math.max(0, Math.min(Math.floor(i), imax));\n            var j0 = Math.max(0, Math.min(Math.floor(j), jmax));\n            var u = Math.max(0, Math.min(1, i - i0));\n            var v = Math.max(0, Math.min(1, j - j0));\n\n            // Since it's a grid of control points, the actual indices are * 3:\n            i0 *= 3;\n            j0 *= 3;\n\n            // Precompute some numbers:\n            var u2 = u * u;\n            var u3 = u2 * u;\n            var ou = 1 - u;\n            var ou2 = ou * ou;\n            var ou3 = ou2 * ou;\n\n            var v2 = v * v;\n            var v3 = v2 * v;\n            var ov = 1 - v;\n            var ov2 = ov * ov;\n            var ov3 = ov2 * ov;\n\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = ou3 * ak[j0][i0] + 3 * (ou2 * u * ak[j0][i0 + 1] + ou * u2 * ak[j0][i0 + 2]) + u3 * ak[j0][i0 + 3];\n                f1 = ou3 * ak[j0 + 1][i0] + 3 * (ou2 * u * ak[j0 + 1][i0 + 1] + ou * u2 * ak[j0 + 1][i0 + 2]) + u3 * ak[j0 + 1][i0 + 3];\n                f2 = ou3 * ak[j0 + 2][i0] + 3 * (ou2 * u * ak[j0 + 2][i0 + 1] + ou * u2 * ak[j0 + 2][i0 + 2]) + u3 * ak[j0 + 2][i0 + 3];\n                f3 = ou3 * ak[j0 + 3][i0] + 3 * (ou2 * u * ak[j0 + 3][i0 + 1] + ou * u2 * ak[j0 + 3][i0 + 2]) + u3 * ak[j0 + 3][i0 + 3];\n                out[k] = ov3 * f0 + 3 * (ov2 * v * f1 + ov * v2 * f2) + v3 * f3;\n            }\n\n            return out;\n        };\n    } else if(asmoothing) {\n        // Handle smooth in the a-direction but linear in the b-direction by performing four\n        // linear interpolations followed by one cubic interpolation of the result\n        return function(out, i, j) {\n            if(!out) out = [];\n\n            var i0 = Math.max(0, Math.min(Math.floor(i), imax));\n            var j0 = Math.max(0, Math.min(Math.floor(j), jmax));\n            var u = Math.max(0, Math.min(1, i - i0));\n            var v = Math.max(0, Math.min(1, j - j0));\n\n            var f0, f1, f2, f3, k, ak;\n            i0 *= 3;\n            var u2 = u * u;\n            var u3 = u2 * u;\n            var ou = 1 - u;\n            var ou2 = ou * ou;\n            var ou3 = ou2 * ou;\n            var ov = 1 - v;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = ov * ak[j0][i0] + v * ak[j0 + 1][i0];\n                f1 = ov * ak[j0][i0 + 1] + v * ak[j0 + 1][i0 + 1];\n                f2 = ov * ak[j0][i0 + 2] + v * ak[j0 + 1][i0 + 1];\n                f3 = ov * ak[j0][i0 + 3] + v * ak[j0 + 1][i0 + 1];\n\n                out[k] = ou3 * f0 + 3 * (ou2 * u * f1 + ou * u2 * f2) + u3 * f3;\n            }\n            return out;\n        };\n    } else if(bsmoothing) {\n        // Same as the above case, except reversed:\n        return function(out, i, j) {\n            if(!out) out = [];\n\n            var i0 = Math.max(0, Math.min(Math.floor(i), imax));\n            var j0 = Math.max(0, Math.min(Math.floor(j), jmax));\n            var u = Math.max(0, Math.min(1, i - i0));\n            var v = Math.max(0, Math.min(1, j - j0));\n\n            var f0, f1, f2, f3, k, ak;\n            j0 *= 3;\n            var v2 = v * v;\n            var v3 = v2 * v;\n            var ov = 1 - v;\n            var ov2 = ov * ov;\n            var ov3 = ov2 * ov;\n            var ou = 1 - u;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = ou * ak[j0][i0] + u * ak[j0][i0 + 1];\n                f1 = ou * ak[j0 + 1][i0] + u * ak[j0 + 1][i0 + 1];\n                f2 = ou * ak[j0 + 2][i0] + u * ak[j0 + 2][i0 + 1];\n                f3 = ou * ak[j0 + 3][i0] + u * ak[j0 + 3][i0 + 1];\n\n                out[k] = ov3 * f0 + 3 * (ov2 * v * f1 + ov * v2 * f2) + v3 * f3;\n            }\n            return out;\n        };\n    } else {\n        // Finally, both directions are linear:\n        return function(out, i, j) {\n            if(!out) out = [];\n\n            var i0 = Math.max(0, Math.min(Math.floor(i), imax));\n            var j0 = Math.max(0, Math.min(Math.floor(j), jmax));\n            var u = Math.max(0, Math.min(1, i - i0));\n            var v = Math.max(0, Math.min(1, j - j0));\n\n            var f0, f1, k, ak;\n            var ov = 1 - v;\n            var ou = 1 - u;\n            for(k = 0; k < arrays.length; k++) {\n                ak = arrays[k];\n                f0 = ou * ak[j0][i0] + u * ak[j0][i0 + 1];\n                f1 = ou * ak[j0 + 1][i0] + u * ak[j0 + 1][i0 + 1];\n\n                out[k] = ov * f0 + v * f1;\n            }\n            return out;\n        };\n    }\n};\n\n},{}],913:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar handleXYDefaults = _dereq_('./xy_defaults');\nvar handleABDefaults = _dereq_('./ab_defaults');\nvar attributes = _dereq_('./attributes');\nvar colorAttrs = _dereq_('../../components/color/attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, dfltColor, fullLayout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    traceOut._clipPathId = 'clip' + traceOut.uid + 'carpet';\n\n    var defaultColor = coerce('color', colorAttrs.defaultLine);\n    Lib.coerceFont(coerce, 'font');\n\n    coerce('carpet');\n\n    handleABDefaults(traceIn, traceOut, fullLayout, coerce, defaultColor);\n\n    if(!traceOut.a || !traceOut.b) {\n        traceOut.visible = false;\n        return;\n    }\n\n    if(traceOut.a.length < 3) {\n        traceOut.aaxis.smoothing = 0;\n    }\n\n    if(traceOut.b.length < 3) {\n        traceOut.baxis.smoothing = 0;\n    }\n\n    // NB: the input is x/y arrays. You should know that the *first* dimension of x and y\n    // corresponds to b and the second to a. This sounds backwards but ends up making sense\n    // the important part to know is that when you write y[j][i], j goes from 0 to b.length - 1\n    // and i goes from 0 to a.length - 1.\n    var validData = handleXYDefaults(traceIn, traceOut, coerce);\n    if(!validData) {\n        traceOut.visible = false;\n    }\n\n    if(traceOut._cheater) {\n        coerce('cheaterslope');\n    }\n};\n\n},{\"../../components/color/attributes\":592,\"../../lib\":719,\"./ab_defaults\":896,\"./attributes\":898,\"./xy_defaults\":922}],914:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    plot: _dereq_('./plot'),\n    calc: _dereq_('./calc'),\n    animatable: true,\n    isContainer: true, // so carpet traces get `calc` before other traces\n\n    moduleType: 'trace',\n    name: 'carpet',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', 'carpet', 'carpetAxis', 'notLegendIsolatable', 'noMultiCategory'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"./attributes\":898,\"./calc\":902,\"./defaults\":913,\"./plot\":919}],915:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/*\n * Given a trace, look up the carpet axis by carpet.\n */\nmodule.exports = function(gd, trace) {\n    var n = gd._fullData.length;\n    var firstAxis;\n    for(var i = 0; i < n; i++) {\n        var maybeCarpet = gd._fullData[i];\n\n        if(maybeCarpet.index === trace.index) continue;\n\n        if(maybeCarpet.type === 'carpet') {\n            if(!firstAxis) {\n                firstAxis = maybeCarpet;\n            }\n\n            if(maybeCarpet.carpet === trace.carpet) {\n                return maybeCarpet;\n            }\n        }\n    }\n\n    return firstAxis;\n};\n\n},{}],916:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function makePath(xp, yp, isBicubic) {\n    // Prevent d3 errors that would result otherwise:\n    if(xp.length === 0) return '';\n\n    var i;\n    var path = [];\n    var stride = isBicubic ? 3 : 1;\n    for(i = 0; i < xp.length; i += stride) {\n        path.push(xp[i] + ',' + yp[i]);\n\n        if(isBicubic && i < xp.length - stride) {\n            path.push('C');\n            path.push([\n                xp[i + 1] + ',' + yp[i + 1],\n                xp[i + 2] + ',' + yp[i + 2] + ' ',\n            ].join(' '));\n        }\n    }\n    return path.join(isBicubic ? '' : 'L');\n};\n\n},{}],917:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\n\n/*\n * Map an array of x or y coordinates (c) to screen-space pixel coordinates (p).\n * The output array is optional, but if provided, it will be reused without\n * reallocation to the extent possible.\n */\nmodule.exports = function mapArray(out, data, func) {\n    var i;\n\n    if(!isArrayOrTypedArray(out)) {\n        // If not an array, make it an array:\n        out = [];\n    } else if(out.length > data.length) {\n        // If too long, truncate. (If too short, it will grow\n        // automatically so we don't care about that case)\n        out = out.slice(0, data.length);\n    }\n\n    for(i = 0; i < data.length; i++) {\n        out[i] = func(data[i]);\n    }\n\n    return out;\n};\n\n},{\"../../lib\":719}],918:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = function orientText(trace, xaxis, yaxis, xy, dxy, refDxy) {\n    var dx = dxy[0] * trace.dpdx(xaxis);\n    var dy = dxy[1] * trace.dpdy(yaxis);\n    var flip = 1;\n\n    var offsetMultiplier = 1.0;\n    if(refDxy) {\n        var l1 = Math.sqrt(dxy[0] * dxy[0] + dxy[1] * dxy[1]);\n        var l2 = Math.sqrt(refDxy[0] * refDxy[0] + refDxy[1] * refDxy[1]);\n        var dot = (dxy[0] * refDxy[0] + dxy[1] * refDxy[1]) / l1 / l2;\n        offsetMultiplier = Math.max(0.0, dot);\n    }\n\n    var angle = Math.atan2(dy, dx) * 180 / Math.PI;\n    if(angle < -90) {\n        angle += 180;\n        flip = -flip;\n    } else if(angle > 90) {\n        angle -= 180;\n        flip = -flip;\n    }\n\n    return {\n        angle: angle,\n        flip: flip,\n        p: trace.c2p(xy, xaxis, yaxis),\n        offsetMultplier: offsetMultiplier\n    };\n};\n\n},{}],919:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Drawing = _dereq_('../../components/drawing');\nvar map1dArray = _dereq_('./map_1d_array');\nvar makepath = _dereq_('./makepath');\nvar orientText = _dereq_('./orient_text');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar Lib = _dereq_('../../lib');\nvar alignmentConstants = _dereq_('../../constants/alignment');\n\nmodule.exports = function plot(gd, plotinfo, cdcarpet, carpetLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n    var fullLayout = gd._fullLayout;\n    var clipLayer = fullLayout._clips;\n\n    Lib.makeTraceGroups(carpetLayer, cdcarpet, 'trace').each(function(cd) {\n        var axisLayer = d3.select(this);\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n        var aax = trace.aaxis;\n        var bax = trace.baxis;\n\n        var minorLayer = Lib.ensureSingle(axisLayer, 'g', 'minorlayer');\n        var majorLayer = Lib.ensureSingle(axisLayer, 'g', 'majorlayer');\n        var boundaryLayer = Lib.ensureSingle(axisLayer, 'g', 'boundarylayer');\n        var labelLayer = Lib.ensureSingle(axisLayer, 'g', 'labellayer');\n\n        axisLayer.style('opacity', trace.opacity);\n\n        drawGridLines(xa, ya, majorLayer, aax, 'a', aax._gridlines, true);\n        drawGridLines(xa, ya, majorLayer, bax, 'b', bax._gridlines, true);\n        drawGridLines(xa, ya, minorLayer, aax, 'a', aax._minorgridlines, true);\n        drawGridLines(xa, ya, minorLayer, bax, 'b', bax._minorgridlines, true);\n\n        // NB: These are not ommitted if the lines are not active. The joins must be executed\n        // in order for them to get cleaned up without a full redraw\n        drawGridLines(xa, ya, boundaryLayer, aax, 'a-boundary', aax._boundarylines);\n        drawGridLines(xa, ya, boundaryLayer, bax, 'b-boundary', bax._boundarylines);\n\n        var labelOrientationA = drawAxisLabels(gd, xa, ya, trace, cd0, labelLayer, aax._labels, 'a-label');\n        var labelOrientationB = drawAxisLabels(gd, xa, ya, trace, cd0, labelLayer, bax._labels, 'b-label');\n\n        drawAxisTitles(gd, labelLayer, trace, cd0, xa, ya, labelOrientationA, labelOrientationB);\n\n        drawClipPath(trace, cd0, clipLayer, xa, ya);\n    });\n};\n\nfunction drawClipPath(trace, t, layer, xaxis, yaxis) {\n    var seg, xp, yp, i;\n\n    var clip = layer.select('#' + trace._clipPathId);\n\n    if(!clip.size()) {\n        clip = layer.append('clipPath')\n            .classed('carpetclip', true);\n    }\n\n    var path = Lib.ensureSingle(clip, 'path', 'carpetboundary');\n    var segments = t.clipsegments;\n    var segs = [];\n\n    for(i = 0; i < segments.length; i++) {\n        seg = segments[i];\n        xp = map1dArray([], seg.x, xaxis.c2p);\n        yp = map1dArray([], seg.y, yaxis.c2p);\n        segs.push(makepath(xp, yp, seg.bicubic));\n    }\n\n    // This could be optimized ever so slightly to avoid no-op L segments\n    // at the corners, but it's so negligible that I don't think it's worth\n    // the extra complexity\n    var clipPathData = 'M' + segs.join('L') + 'Z';\n    clip.attr('id', trace._clipPathId);\n    path.attr('d', clipPathData);\n}\n\nfunction drawGridLines(xaxis, yaxis, layer, axis, axisLetter, gridlines) {\n    var lineClass = 'const-' + axisLetter + '-lines';\n    var gridJoin = layer.selectAll('.' + lineClass).data(gridlines);\n\n    gridJoin.enter().append('path')\n        .classed(lineClass, true)\n        .style('vector-effect', 'non-scaling-stroke');\n\n    gridJoin.each(function(d) {\n        var gridline = d;\n        var x = gridline.x;\n        var y = gridline.y;\n\n        var xp = map1dArray([], x, xaxis.c2p);\n        var yp = map1dArray([], y, yaxis.c2p);\n\n        var path = 'M' + makepath(xp, yp, gridline.smoothing);\n\n        var el = d3.select(this);\n\n        el.attr('d', path)\n            .style('stroke-width', gridline.width)\n            .style('stroke', gridline.color)\n            .style('fill', 'none');\n    });\n\n    gridJoin.exit().remove();\n}\n\nfunction drawAxisLabels(gd, xaxis, yaxis, trace, t, layer, labels, labelClass) {\n    var labelJoin = layer.selectAll('text.' + labelClass).data(labels);\n\n    labelJoin.enter().append('text')\n        .classed(labelClass, true);\n\n    var maxExtent = 0;\n    var labelOrientation = {};\n\n    labelJoin.each(function(label, i) {\n        // Most of the positioning is done in calc_labels. Only the parts that depend upon\n        // the screen space representation of the x and y axes are here:\n        var orientation;\n        if(label.axis.tickangle === 'auto') {\n            orientation = orientText(trace, xaxis, yaxis, label.xy, label.dxy);\n        } else {\n            var angle = (label.axis.tickangle + 180.0) * Math.PI / 180.0;\n            orientation = orientText(trace, xaxis, yaxis, label.xy, [Math.cos(angle), Math.sin(angle)]);\n        }\n\n        if(!i) {\n            // TODO: offsetMultiplier? Not currently used anywhere...\n            labelOrientation = {angle: orientation.angle, flip: orientation.flip};\n        }\n        var direction = (label.endAnchor ? -1 : 1) * orientation.flip;\n\n        var labelEl = d3.select(this)\n            .attr({\n                'text-anchor': direction > 0 ? 'start' : 'end',\n                'data-notex': 1\n            })\n            .call(Drawing.font, label.font)\n            .text(label.text)\n            .call(svgTextUtils.convertToTspans, gd);\n\n        var bbox = Drawing.bBox(this);\n\n        labelEl.attr('transform',\n                // Translate to the correct point:\n                'translate(' + orientation.p[0] + ',' + orientation.p[1] + ') ' +\n                // Rotate to line up with grid line tangent:\n                'rotate(' + orientation.angle + ')' +\n                // Adjust the baseline and indentation:\n                'translate(' + label.axis.labelpadding * direction + ',' + bbox.height * 0.3 + ')'\n            );\n\n        maxExtent = Math.max(maxExtent, bbox.width + label.axis.labelpadding);\n    });\n\n    labelJoin.exit().remove();\n\n    labelOrientation.maxExtent = maxExtent;\n    return labelOrientation;\n}\n\nfunction drawAxisTitles(gd, layer, trace, t, xa, ya, labelOrientationA, labelOrientationB) {\n    var a, b, xy, dxy;\n\n    var aMin = Lib.aggNums(Math.min, null, trace.a);\n    var aMax = Lib.aggNums(Math.max, null, trace.a);\n    var bMin = Lib.aggNums(Math.min, null, trace.b);\n    var bMax = Lib.aggNums(Math.max, null, trace.b);\n\n    a = 0.5 * (aMin + aMax);\n    b = bMin;\n    xy = trace.ab2xy(a, b, true);\n    dxy = trace.dxyda_rough(a, b);\n    if(labelOrientationA.angle === undefined) {\n        Lib.extendFlat(labelOrientationA, orientText(trace, xa, ya, xy, trace.dxydb_rough(a, b)));\n    }\n    drawAxisTitle(gd, layer, trace, t, xy, dxy, trace.aaxis, xa, ya, labelOrientationA, 'a-title');\n\n    a = aMin;\n    b = 0.5 * (bMin + bMax);\n    xy = trace.ab2xy(a, b, true);\n    dxy = trace.dxydb_rough(a, b);\n    if(labelOrientationB.angle === undefined) {\n        Lib.extendFlat(labelOrientationB, orientText(trace, xa, ya, xy, trace.dxyda_rough(a, b)));\n    }\n    drawAxisTitle(gd, layer, trace, t, xy, dxy, trace.baxis, xa, ya, labelOrientationB, 'b-title');\n}\n\nvar lineSpacing = alignmentConstants.LINE_SPACING;\nvar midShift = ((1 - alignmentConstants.MID_SHIFT) / lineSpacing) + 1;\n\nfunction drawAxisTitle(gd, layer, trace, t, xy, dxy, axis, xa, ya, labelOrientation, labelClass) {\n    var data = [];\n    if(axis.title.text) data.push(axis.title.text);\n    var titleJoin = layer.selectAll('text.' + labelClass).data(data);\n    var offset = labelOrientation.maxExtent;\n\n    titleJoin.enter().append('text')\n        .classed(labelClass, true);\n\n    // There's only one, but we'll do it as a join so it's updated nicely:\n    titleJoin.each(function() {\n        var orientation = orientText(trace, xa, ya, xy, dxy);\n\n        if(['start', 'both'].indexOf(axis.showticklabels) === -1) {\n            offset = 0;\n        }\n\n        // In addition to the size of the labels, add on some extra padding:\n        var titleSize = axis.title.font.size;\n        offset += titleSize + axis.title.offset;\n\n        var labelNorm = labelOrientation.angle + (labelOrientation.flip < 0 ? 180 : 0);\n        var angleDiff = (labelNorm - orientation.angle + 450) % 360;\n        var reverseTitle = angleDiff > 90 && angleDiff < 270;\n\n        var el = d3.select(this);\n\n        el.text(axis.title.text)\n            .call(svgTextUtils.convertToTspans, gd);\n\n        if(reverseTitle) {\n            offset = (-svgTextUtils.lineCount(el) + midShift) * lineSpacing * titleSize - offset;\n        }\n\n        el.attr('transform',\n                'translate(' + orientation.p[0] + ',' + orientation.p[1] + ') ' +\n                'rotate(' + orientation.angle + ') ' +\n                'translate(0,' + offset + ')'\n            )\n            .classed('user-select-none', true)\n            .attr('text-anchor', 'middle')\n            .call(Drawing.font, axis.title.font);\n    });\n\n    titleJoin.exit().remove();\n}\n\n},{\"../../components/drawing\":614,\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"./makepath\":916,\"./map_1d_array\":917,\"./orient_text\":918,\"d3\":163}],920:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar constants = _dereq_('./constants');\nvar search = _dereq_('../../lib/search').findBin;\nvar computeControlPoints = _dereq_('./compute_control_points');\nvar createSplineEvaluator = _dereq_('./create_spline_evaluator');\nvar createIDerivativeEvaluator = _dereq_('./create_i_derivative_evaluator');\nvar createJDerivativeEvaluator = _dereq_('./create_j_derivative_evaluator');\n\n/*\n * Create conversion functions to go from one basis to another. In particular the letter\n * abbreviations are:\n *\n *   i: i/j coordinates along the grid. Integer values correspond to data points\n *   a: real-valued coordinates along the a/b axes\n *   c: cartesian x-y coordinates\n *   p: screen-space pixel coordinates\n */\nmodule.exports = function setConvert(trace) {\n    var a = trace._a;\n    var b = trace._b;\n    var na = a.length;\n    var nb = b.length;\n    var aax = trace.aaxis;\n    var bax = trace.baxis;\n\n    // Grab the limits once rather than recomputing the bounds for every point\n    // independently:\n    var amin = a[0];\n    var amax = a[na - 1];\n    var bmin = b[0];\n    var bmax = b[nb - 1];\n    var arange = a[a.length - 1] - a[0];\n    var brange = b[b.length - 1] - b[0];\n\n    // Compute the tolerance so that points are visible slightly outside the\n    // defined carpet axis:\n    var atol = arange * constants.RELATIVE_CULL_TOLERANCE;\n    var btol = brange * constants.RELATIVE_CULL_TOLERANCE;\n\n    // Expand the limits to include the relative tolerance:\n    amin -= atol;\n    amax += atol;\n    bmin -= btol;\n    bmax += btol;\n\n    trace.isVisible = function(a, b) {\n        return a > amin && a < amax && b > bmin && b < bmax;\n    };\n\n    trace.isOccluded = function(a, b) {\n        return a < amin || a > amax || b < bmin || b > bmax;\n    };\n\n    trace.setScale = function() {\n        var x = trace._x;\n        var y = trace._y;\n\n        // This is potentially a very expensive step! It does the bulk of the work of constructing\n        // an expanded basis of control points. Note in particular that it overwrites the existing\n        // basis without creating a new array since that would potentially thrash the garbage\n        // collector.\n        var result = computeControlPoints(trace._xctrl, trace._yctrl, x, y, aax.smoothing, bax.smoothing);\n        trace._xctrl = result[0];\n        trace._yctrl = result[1];\n\n        // This step is the second step in the process, but it's somewhat simpler. It just unrolls\n        // some logic since it would be unnecessarily expensive to compute both interpolations\n        // nearly identically but separately and to include a bunch of linear vs. bicubic logic in\n        // every single call.\n        trace.evalxy = createSplineEvaluator([trace._xctrl, trace._yctrl], na, nb, aax.smoothing, bax.smoothing);\n\n        trace.dxydi = createIDerivativeEvaluator([trace._xctrl, trace._yctrl], aax.smoothing, bax.smoothing);\n        trace.dxydj = createJDerivativeEvaluator([trace._xctrl, trace._yctrl], aax.smoothing, bax.smoothing);\n    };\n\n    /*\n     * Convert from i/j data grid coordinates to a/b values. Note in particular that this\n     * is *linear* interpolation, even if the data is interpolated bicubically.\n     */\n    trace.i2a = function(i) {\n        var i0 = Math.max(0, Math.floor(i[0]), na - 2);\n        var ti = i[0] - i0;\n        return (1 - ti) * a[i0] + ti * a[i0 + 1];\n    };\n\n    trace.j2b = function(j) {\n        var j0 = Math.max(0, Math.floor(j[1]), na - 2);\n        var tj = j[1] - j0;\n        return (1 - tj) * b[j0] + tj * b[j0 + 1];\n    };\n\n    trace.ij2ab = function(ij) {\n        return [trace.i2a(ij[0]), trace.j2b(ij[1])];\n    };\n\n    /*\n     * Convert from a/b coordinates to i/j grid-numbered coordinates. This requires searching\n     * through the a/b data arrays and assumes they are monotonic, which is presumed to have\n     * been enforced already.\n     */\n    trace.a2i = function(aval) {\n        var i0 = Math.max(0, Math.min(search(aval, a), na - 2));\n        var a0 = a[i0];\n        var a1 = a[i0 + 1];\n        return Math.max(0, Math.min(na - 1, i0 + (aval - a0) / (a1 - a0)));\n    };\n\n    trace.b2j = function(bval) {\n        var j0 = Math.max(0, Math.min(search(bval, b), nb - 2));\n        var b0 = b[j0];\n        var b1 = b[j0 + 1];\n        return Math.max(0, Math.min(nb - 1, j0 + (bval - b0) / (b1 - b0)));\n    };\n\n    trace.ab2ij = function(ab) {\n        return [trace.a2i(ab[0]), trace.b2j(ab[1])];\n    };\n\n    /*\n     * Convert from i/j coordinates to x/y caretesian coordinates. This means either bilinear\n     * or bicubic spline evaluation, but the hard part is already done at this point.\n     */\n    trace.i2c = function(i, j) {\n        return trace.evalxy([], i, j);\n    };\n\n    trace.ab2xy = function(aval, bval, extrapolate) {\n        if(!extrapolate && (aval < a[0] || aval > a[na - 1] | bval < b[0] || bval > b[nb - 1])) {\n            return [false, false];\n        }\n        var i = trace.a2i(aval);\n        var j = trace.b2j(bval);\n\n        var pt = trace.evalxy([], i, j);\n\n        if(extrapolate) {\n            // This section uses the boundary derivatives to extrapolate linearly outside\n            // the defined range. Consider a scatter line with one point inside the carpet\n            // axis and one point outside. If we don't extrapolate, we can't draw the line\n            // at all.\n            var iex = 0;\n            var jex = 0;\n            var der = [];\n\n            var i0, ti, j0, tj;\n            if(aval < a[0]) {\n                i0 = 0;\n                ti = 0;\n                iex = (aval - a[0]) / (a[1] - a[0]);\n            } else if(aval > a[na - 1]) {\n                i0 = na - 2;\n                ti = 1;\n                iex = (aval - a[na - 1]) / (a[na - 1] - a[na - 2]);\n            } else {\n                i0 = Math.max(0, Math.min(na - 2, Math.floor(i)));\n                ti = i - i0;\n            }\n\n            if(bval < b[0]) {\n                j0 = 0;\n                tj = 0;\n                jex = (bval - b[0]) / (b[1] - b[0]);\n            } else if(bval > b[nb - 1]) {\n                j0 = nb - 2;\n                tj = 1;\n                jex = (bval - b[nb - 1]) / (b[nb - 1] - b[nb - 2]);\n            } else {\n                j0 = Math.max(0, Math.min(nb - 2, Math.floor(j)));\n                tj = j - j0;\n            }\n\n            if(iex) {\n                trace.dxydi(der, i0, j0, ti, tj);\n                pt[0] += der[0] * iex;\n                pt[1] += der[1] * iex;\n            }\n\n            if(jex) {\n                trace.dxydj(der, i0, j0, ti, tj);\n                pt[0] += der[0] * jex;\n                pt[1] += der[1] * jex;\n            }\n        }\n\n        return pt;\n    };\n\n\n    trace.c2p = function(xy, xa, ya) {\n        return [xa.c2p(xy[0]), ya.c2p(xy[1])];\n    };\n\n    trace.p2x = function(p, xa, ya) {\n        return [xa.p2c(p[0]), ya.p2c(p[1])];\n    };\n\n    trace.dadi = function(i /* , u*/) {\n        // Right now only a piecewise linear a or b basis is permitted since smoother interpolation\n        // would cause monotonicity problems. As a retult, u is entirely disregarded in this\n        // computation, though we'll specify it as a parameter for the sake of completeness and\n        // future-proofing. It would be possible to use monotonic cubic interpolation, for example.\n        //\n        // See: https://en.wikipedia.org/wiki/Monotone_cubic_interpolation\n\n        // u = u || 0;\n\n        var i0 = Math.max(0, Math.min(a.length - 2, i));\n\n        // The step (demoninator) is implicitly 1 since that's the grid spacing.\n        return a[i0 + 1] - a[i0];\n    };\n\n    trace.dbdj = function(j /* , v*/) {\n        // See above caveats for dadi which also apply here\n        var j0 = Math.max(0, Math.min(b.length - 2, j));\n\n        // The step (demoninator) is implicitly 1 since that's the grid spacing.\n        return b[j0 + 1] - b[j0];\n    };\n\n    // Takes: grid cell coordinate (i, j) and fractional grid cell coordinates (u, v)\n    // Returns: (dx/da, dy/db)\n    //\n    // NB: separate grid cell + fractional grid cell coordinate format is due to the discontinuous\n    // derivative, as described better in create_i_derivative_evaluator.js\n    trace.dxyda = function(i0, j0, u, v) {\n        var dxydi = trace.dxydi(null, i0, j0, u, v);\n        var dadi = trace.dadi(i0, u);\n\n        return [dxydi[0] / dadi, dxydi[1] / dadi];\n    };\n\n    trace.dxydb = function(i0, j0, u, v) {\n        var dxydj = trace.dxydj(null, i0, j0, u, v);\n        var dbdj = trace.dbdj(j0, v);\n\n        return [dxydj[0] / dbdj, dxydj[1] / dbdj];\n    };\n\n    // Sometimes we don't care about precision and all we really want is decent rough\n    // directions (as is the case with labels). In that case, we can do a very rough finite\n    // difference and spare having to worry about precise grid coordinates:\n    trace.dxyda_rough = function(a, b, reldiff) {\n        var h = arange * (reldiff || 0.1);\n        var plus = trace.ab2xy(a + h, b, true);\n        var minus = trace.ab2xy(a - h, b, true);\n\n        return [\n            (plus[0] - minus[0]) * 0.5 / h,\n            (plus[1] - minus[1]) * 0.5 / h\n        ];\n    };\n\n    trace.dxydb_rough = function(a, b, reldiff) {\n        var h = brange * (reldiff || 0.1);\n        var plus = trace.ab2xy(a, b + h, true);\n        var minus = trace.ab2xy(a, b - h, true);\n\n        return [\n            (plus[0] - minus[0]) * 0.5 / h,\n            (plus[1] - minus[1]) * 0.5 / h\n        ];\n    };\n\n    trace.dpdx = function(xa) {\n        return xa._m;\n    };\n\n    trace.dpdy = function(ya) {\n        return ya._m;\n    };\n};\n\n},{\"../../lib/search\":738,\"./compute_control_points\":908,\"./constants\":909,\"./create_i_derivative_evaluator\":910,\"./create_j_derivative_evaluator\":911,\"./create_spline_evaluator\":912}],921:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n/*\n * Given a 2D array as well as a basis in either direction, this function fills in the\n * 2D array using a combination of smoothing and extrapolation. This is rather important\n * for carpet plots since it's used for layout so that we can't simply omit or blank out\n * points. We need a reasonable guess so that the interpolation puts points somewhere\n * even if we were to somehow represent that the data was missing later on.\n *\n * input:\n *  - data: 2D array of arrays\n *  - a: array such that a.length === data[0].length\n *  - b: array such that b.length === data.length\n */\nmodule.exports = function smoothFill2dArray(data, a, b) {\n    var i, j, k;\n    var ip = [];\n    var jp = [];\n    // var neighborCnts = [];\n\n    var ni = data[0].length;\n    var nj = data.length;\n\n    function avgSurrounding(i, j) {\n        // As a low-quality start, we can simply average surrounding points (in a not\n        // non-uniform grid aware manner):\n        var sum = 0.0;\n        var val;\n        var cnt = 0;\n        if(i > 0 && (val = data[j][i - 1]) !== undefined) {\n            cnt++;\n            sum += val;\n        }\n        if(i < ni - 1 && (val = data[j][i + 1]) !== undefined) {\n            cnt++;\n            sum += val;\n        }\n        if(j > 0 && (val = data[j - 1][i]) !== undefined) {\n            cnt++;\n            sum += val;\n        }\n        if(j < nj - 1 && (val = data[j + 1][i]) !== undefined) {\n            cnt++;\n            sum += val;\n        }\n        return sum / Math.max(1, cnt);\n    }\n\n    // This loop iterates over all cells. Any cells that are null will be noted and those\n    // are the only points we will loop over and update via laplace's equation. Points with\n    // any neighbors will receive the average. If there are no neighboring points, then they\n    // will be set to zero. Also as we go, track the maximum magnitude so that we can scale\n    // our tolerance accordingly.\n    var dmax = 0.0;\n    for(i = 0; i < ni; i++) {\n        for(j = 0; j < nj; j++) {\n            if(data[j][i] === undefined) {\n                ip.push(i);\n                jp.push(j);\n\n                data[j][i] = avgSurrounding(i, j);\n                // neighborCnts.push(result.neighbors);\n            }\n            dmax = Math.max(dmax, Math.abs(data[j][i]));\n        }\n    }\n\n    if(!ip.length) return data;\n\n    // The tolerance doesn't need to be excessive. It's just for display positioning\n    var dxp, dxm, dap, dam, dbp, dbm, c, d, diff, reldiff, overrelaxation;\n    var tol = 1e-5;\n    var resid = 0;\n    var itermax = 100;\n    var iter = 0;\n    var n = ip.length;\n    do {\n        resid = 0;\n        // Normally we'd loop in two dimensions, but not all points are blank and need\n        // an update, so we instead loop only over the points that were tabulated above\n        for(k = 0; k < n; k++) {\n            i = ip[k];\n            j = jp[k];\n            // neighborCnt = neighborCnts[k];\n\n            // Track a counter for how many contributions there are. We'll use this counter\n            // to average at the end, which reduces to laplace's equation with neumann boundary\n            // conditions on the first derivative (second derivative is zero so that we get\n            // a nice linear extrapolation at the boundaries).\n            var boundaryCnt = 0;\n            var newVal = 0;\n\n            var d0, d1, x0, x1, i0, j0;\n            if(i === 0) {\n                // If this lies along the i = 0 boundary, extrapolate from the two points\n                // to the right of this point. Note that the finite differences take into\n                // account non-uniform grid spacing:\n                i0 = Math.min(ni - 1, 2);\n                x0 = a[i0];\n                x1 = a[1];\n                d0 = data[j][i0];\n                d1 = data[j][1];\n                newVal += d1 + (d1 - d0) * (a[0] - x1) / (x1 - x0);\n                boundaryCnt++;\n            } else if(i === ni - 1) {\n                // If along the high i boundary, extrapolate from the two points to the\n                // left of this point\n                i0 = Math.max(0, ni - 3);\n                x0 = a[i0];\n                x1 = a[ni - 2];\n                d0 = data[j][i0];\n                d1 = data[j][ni - 2];\n                newVal += d1 + (d1 - d0) * (a[ni - 1] - x1) / (x1 - x0);\n                boundaryCnt++;\n            }\n\n            if((i === 0 || i === ni - 1) && (j > 0 && j < nj - 1)) {\n                // If along the min(i) or max(i) boundaries, also smooth vertically as long\n                // as we're not in a corner. Note that the finite differences used here\n                // are also aware of nonuniform grid spacing:\n                dxp = b[j + 1] - b[j];\n                dxm = b[j] - b[j - 1];\n                newVal += (dxm * data[j + 1][i] + dxp * data[j - 1][i]) / (dxm + dxp);\n                boundaryCnt++;\n            }\n\n            if(j === 0) {\n                // If along the j = 0 boundary, extrpolate this point from the two points\n                // above it\n                j0 = Math.min(nj - 1, 2);\n                x0 = b[j0];\n                x1 = b[1];\n                d0 = data[j0][i];\n                d1 = data[1][i];\n                newVal += d1 + (d1 - d0) * (b[0] - x1) / (x1 - x0);\n                boundaryCnt++;\n            } else if(j === nj - 1) {\n                // Same for the max j boundary from the cells below it:\n                j0 = Math.max(0, nj - 3);\n                x0 = b[j0];\n                x1 = b[nj - 2];\n                d0 = data[j0][i];\n                d1 = data[nj - 2][i];\n                newVal += d1 + (d1 - d0) * (b[nj - 1] - x1) / (x1 - x0);\n                boundaryCnt++;\n            }\n\n            if((j === 0 || j === nj - 1) && (i > 0 && i < ni - 1)) {\n                // Now average points to the left/right as long as not in a corner:\n                dxp = a[i + 1] - a[i];\n                dxm = a[i] - a[i - 1];\n                newVal += (dxm * data[j][i + 1] + dxp * data[j][i - 1]) / (dxm + dxp);\n                boundaryCnt++;\n            }\n\n            if(!boundaryCnt) {\n                // If none of the above conditions were triggered, then this is an interior\n                // point and we can just do a laplace equation update. As above, these differences\n                // are aware of nonuniform grid spacing:\n                dap = a[i + 1] - a[i];\n                dam = a[i] - a[i - 1];\n                dbp = b[j + 1] - b[j];\n                dbm = b[j] - b[j - 1];\n\n                // These are just some useful constants for the iteration, which is perfectly\n                // straightforward but a little long to derive from f_xx + f_yy = 0.\n                c = dap * dam * (dap + dam);\n                d = dbp * dbm * (dbp + dbm);\n\n                newVal = (c * (dbm * data[j + 1][i] + dbp * data[j - 1][i]) +\n                          d * (dam * data[j][i + 1] + dap * data[j][i - 1])) /\n                          (d * (dam + dap) + c * (dbm + dbp));\n            } else {\n                // If we did have contributions from the boundary conditions, then average\n                // the result from the various contributions:\n                newVal /= boundaryCnt;\n            }\n\n            // Jacobi updates are ridiculously slow to converge, so this approach uses a\n            // Gauss-seidel iteration which is dramatically faster.\n            diff = newVal - data[j][i];\n            reldiff = diff / dmax;\n            resid += reldiff * reldiff;\n\n            // Gauss-Seidel-ish iteration, omega chosen based on heuristics and some\n            // quick tests.\n            //\n            // NB: Don't overrelax the boundarie. Otherwise set an overrelaxation factor\n            // which is a little low but safely optimal-ish:\n            overrelaxation = boundaryCnt ? 0 : 0.85;\n\n            // If there are four non-null neighbors, then we want a simple average without\n            // overrelaxation. If all the surrouding points are null, then we want the full\n            // overrelaxation\n            //\n            // Based on experiments, this actually seems to slow down convergence just a bit.\n            // I'll leave it here for reference in case this needs to be revisited, but\n            // it seems to work just fine without this.\n            // if (overrelaxation) overrelaxation *= (4 - neighborCnt) / 4;\n\n            data[j][i] += diff * (1 + overrelaxation);\n        }\n\n        resid = Math.sqrt(resid);\n    } while(iter++ < itermax && resid > tol);\n\n    Lib.log('Smoother converged to', resid, 'after', iter, 'iterations');\n\n    return data;\n};\n\n},{\"../../lib\":719}],922:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isArray1D = _dereq_('../../lib').isArray1D;\n\nmodule.exports = function handleXYDefaults(traceIn, traceOut, coerce) {\n    var x = coerce('x');\n    var hasX = x && x.length;\n    var y = coerce('y');\n    var hasY = y && y.length;\n    if(!hasX && !hasY) return false;\n\n    traceOut._cheater = !x;\n\n    if((!hasX || isArray1D(x)) && (!hasY || isArray1D(y))) {\n        var len = hasX ? x.length : Infinity;\n        if(hasY) len = Math.min(len, y.length);\n        if(traceOut.a && traceOut.a.length) len = Math.min(len, traceOut.a.length);\n        if(traceOut.b && traceOut.b.length) len = Math.min(len, traceOut.b.length);\n        traceOut._length = len;\n    } else traceOut._length = null;\n\n    return true;\n};\n\n},{\"../../lib\":719}],923:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar scatterGeoAttrs = _dereq_('../scattergeo/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar defaultLine = _dereq_('../../components/color/attributes').defaultLine;\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar scatterGeoMarkerLineAttrs = scatterGeoAttrs.marker.line;\n\nmodule.exports = extendFlat({\n    locations: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    locationmode: scatterGeoAttrs.locationmode,\n    z: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    text: extendFlat({}, scatterGeoAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, scatterGeoAttrs.hovertext, {\n        \n    }),\n    marker: {\n        line: {\n            color: extendFlat({}, scatterGeoMarkerLineAttrs.color, {dflt: defaultLine}),\n            width: extendFlat({}, scatterGeoMarkerLineAttrs.width, {dflt: 1}),\n            editType: 'calc'\n        },\n        opacity: {\n            valType: 'number',\n            arrayOk: true,\n            min: 0,\n            max: 1,\n            dflt: 1,\n            \n            editType: 'style',\n            \n        },\n        editType: 'calc'\n    },\n\n    selected: {\n        marker: {\n            opacity: scatterGeoAttrs.selected.marker.opacity,\n            editType: 'plot'\n        },\n        editType: 'plot'\n    },\n    unselected: {\n        marker: {\n            opacity: scatterGeoAttrs.unselected.marker.opacity,\n            editType: 'plot'\n        },\n        editType: 'plot'\n    },\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        editType: 'calc',\n        flags: ['location', 'z', 'text', 'name']\n    }),\n    hovertemplate: hovertemplateAttrs(),\n},\n\n    colorScaleAttrs('', {\n        cLetter: 'z',\n        editTypeOverride: 'calc'\n    })\n);\n\n},{\"../../components/color/attributes\":592,\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../scattergeo/attributes\":1151}],924:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\nvar arraysToCalcdata = _dereq_('../scatter/arrays_to_calcdata');\nvar calcSelection = _dereq_('../scatter/calc_selection');\n\nfunction isNonBlankString(v) {\n    return v && typeof v === 'string';\n}\n\nmodule.exports = function calc(gd, trace) {\n    var len = trace._length;\n    var calcTrace = new Array(len);\n\n    var isValidLoc;\n\n    if(trace.geojson) {\n        isValidLoc = function(v) { return isNonBlankString(v) || isNumeric(v); };\n    } else {\n        isValidLoc = isNonBlankString;\n    }\n\n    for(var i = 0; i < len; i++) {\n        var calcPt = calcTrace[i] = {};\n        var loc = trace.locations[i];\n        var z = trace.z[i];\n\n        if(isValidLoc(loc) && isNumeric(z)) {\n            calcPt.loc = loc;\n            calcPt.z = z;\n        } else {\n            calcPt.loc = null;\n            calcPt.z = BADNUM;\n        }\n\n        calcPt.index = i;\n    }\n\n    arraysToCalcdata(calcTrace, trace);\n    colorscaleCalc(gd, trace, {\n        vals: trace.z,\n        containerStr: '',\n        cLetter: 'z'\n    });\n    calcSelection(calcTrace, trace);\n\n    return calcTrace;\n};\n\n},{\"../../components/colorscale/calc\":601,\"../../constants/numerical\":695,\"../scatter/arrays_to_calcdata\":1111,\"../scatter/calc_selection\":1114,\"fast-isnumeric\":225}],925:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var locations = coerce('locations');\n    var z = coerce('z');\n\n    if(!(locations && locations.length && Lib.isArrayOrTypedArray(z) && z.length)) {\n        traceOut.visible = false;\n        return;\n    }\n\n    traceOut._length = Math.min(locations.length, z.length);\n\n    coerce('locationmode');\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    var mlw = coerce('marker.line.width');\n    if(mlw) coerce('marker.line.color');\n    coerce('marker.opacity');\n\n    colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"./attributes\":923}],926:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function eventData(out, pt, trace, cd, pointNumber) {\n    out.location = pt.location;\n    out.z = pt.z;\n\n    var cdi = cd[pointNumber];\n    if(cdi.fIn) {\n        out.properties = cdi.fIn.properties;\n    }\n\n    return out;\n};\n\n},{}],927:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar attributes = _dereq_('./attributes');\nvar fillText = _dereq_('../../lib').fillText;\n\nmodule.exports = function hoverPoints(pointData, xval, yval) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n    var geo = pointData.subplot;\n\n    var pt, i, j, isInside;\n\n    for(i = 0; i < cd.length; i++) {\n        pt = cd[i];\n        isInside = false;\n\n        if(pt._polygons) {\n            for(j = 0; j < pt._polygons.length; j++) {\n                if(pt._polygons[j].contains([xval, yval])) {\n                    isInside = !isInside;\n                }\n                // for polygons that cross antimeridian as xval is in [-180, 180]\n                if(pt._polygons[j].contains([xval + 360, yval])) {\n                    isInside = !isInside;\n                }\n            }\n\n            if(isInside) break;\n        }\n    }\n\n    if(!isInside || !pt) return;\n\n    pointData.x0 = pointData.x1 = pointData.xa.c2p(pt.ct);\n    pointData.y0 = pointData.y1 = pointData.ya.c2p(pt.ct);\n\n    pointData.index = pt.index;\n    pointData.location = pt.loc;\n    pointData.z = pt.z;\n    pointData.zLabel = Axes.tickText(geo.mockAxis, geo.mockAxis.c2l(pt.z), 'hover').text;\n    pointData.hovertemplate = pt.hovertemplate;\n\n    makeHoverInfo(pointData, trace, pt, geo.mockAxis);\n\n    return [pointData];\n};\n\nfunction makeHoverInfo(pointData, trace, pt) {\n    if(trace.hovertemplate) return;\n\n    var hoverinfo = pt.hi || trace.hoverinfo;\n\n    var parts = (hoverinfo === 'all') ?\n        attributes.hoverinfo.flags :\n        hoverinfo.split('+');\n\n    var hasName = (parts.indexOf('name') !== -1);\n    var hasLocation = (parts.indexOf('location') !== -1);\n    var hasZ = (parts.indexOf('z') !== -1);\n    var hasText = (parts.indexOf('text') !== -1);\n    var hasIdAsNameLabel = !hasName && hasLocation;\n\n    var text = [];\n\n    if(hasIdAsNameLabel) {\n        pointData.nameOverride = pt.loc;\n    } else {\n        if(hasName) pointData.nameOverride = trace.name;\n        if(hasLocation) text.push(pt.loc);\n    }\n\n    if(hasZ) {\n        text.push(pointData.zLabel);\n    }\n    if(hasText) {\n        fillText(pt, trace, text);\n    }\n\n    pointData.extraText = text.join('<br>');\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"./attributes\":923}],928:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../heatmap/colorbar'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot').plot,\n    style: _dereq_('./style').style,\n    styleOnSelect: _dereq_('./style').styleOnSelect,\n    hoverPoints: _dereq_('./hover'),\n    eventData: _dereq_('./event_data'),\n    selectPoints: _dereq_('./select'),\n\n    moduleType: 'trace',\n    name: 'choropleth',\n    basePlotModule: _dereq_('../../plots/geo'),\n    categories: ['geo', 'noOpacity'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/geo\":797,\"../heatmap/colorbar\":1004,\"./attributes\":923,\"./calc\":924,\"./defaults\":925,\"./event_data\":926,\"./hover\":927,\"./plot\":929,\"./select\":930,\"./style\":931}],929:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../../lib');\nvar polygon = _dereq_('../../lib/polygon');\n\nvar getTopojsonFeatures = _dereq_('../../lib/topojson_utils').getTopojsonFeatures;\nvar locationToFeature = _dereq_('../../lib/geo_location_utils').locationToFeature;\nvar style = _dereq_('./style').style;\n\nfunction plot(gd, geo, calcData) {\n    for(var i = 0; i < calcData.length; i++) {\n        calcGeoJSON(calcData[i], geo.topojson);\n    }\n\n    var choroplethLayer = geo.layers.backplot.select('.choroplethlayer');\n    Lib.makeTraceGroups(choroplethLayer, calcData, 'trace choropleth').each(function(calcTrace) {\n        var sel = d3.select(this);\n\n        var paths = sel.selectAll('path.choroplethlocation')\n            .data(Lib.identity);\n\n        paths.enter().append('path')\n            .classed('choroplethlocation', true);\n\n        paths.exit().remove();\n\n        // call style here within topojson request callback\n        style(gd, calcTrace);\n    });\n}\n\nfunction calcGeoJSON(calcTrace, topojson) {\n    var trace = calcTrace[0].trace;\n    var len = calcTrace.length;\n    var features = getTopojsonFeatures(trace, topojson);\n\n    for(var i = 0; i < len; i++) {\n        var calcPt = calcTrace[i];\n        var feature = locationToFeature(trace.locationmode, calcPt.loc, features);\n\n        if(!feature) {\n            calcPt.geojson = null;\n            continue;\n        }\n\n        calcPt.geojson = feature;\n        calcPt.ct = feature.properties.ct;\n        calcPt._polygons = feature2polygons(feature);\n    }\n}\n\nfunction feature2polygons(feature) {\n    var geometry = feature.geometry;\n    var coords = geometry.coordinates;\n    var loc = feature.id;\n\n    var polygons = [];\n    var appendPolygon, j, k, m;\n\n    function doesCrossAntiMerdian(pts) {\n        for(var l = 0; l < pts.length - 1; l++) {\n            if(pts[l][0] > 0 && pts[l + 1][0] < 0) return l;\n        }\n        return null;\n    }\n\n    if(loc === 'RUS' || loc === 'FJI') {\n        // Russia and Fiji have landmasses that cross the antimeridian,\n        // we need to add +360 to their longitude coordinates, so that\n        // polygon 'contains' doesn't get confused when crossing the antimeridian.\n        //\n        // Note that other countries have polygons on either side of the antimeridian\n        // (e.g. some Aleutian island for the USA), but those don't confuse\n        // the 'contains' method; these are skipped here.\n        appendPolygon = function(_pts) {\n            var pts;\n\n            if(doesCrossAntiMerdian(_pts) === null) {\n                pts = _pts;\n            } else {\n                pts = new Array(_pts.length);\n                for(m = 0; m < _pts.length; m++) {\n                    // do nut mutate calcdata[i][j].geojson !!\n                    pts[m] = [\n                        _pts[m][0] < 0 ? _pts[m][0] + 360 : _pts[m][0],\n                        _pts[m][1]\n                    ];\n                }\n            }\n\n            polygons.push(polygon.tester(pts));\n        };\n    } else if(loc === 'ATA') {\n        // Antarctica has a landmass that wraps around every longitudes which\n        // confuses the 'contains' methods.\n        appendPolygon = function(pts) {\n            var crossAntiMeridianIndex = doesCrossAntiMerdian(pts);\n\n            // polygon that do not cross anti-meridian need no special handling\n            if(crossAntiMeridianIndex === null) {\n                return polygons.push(polygon.tester(pts));\n            }\n\n            // stitch polygon by adding pt over South Pole,\n            // so that it covers the projected region covers all latitudes\n            //\n            // Note that the algorithm below only works for polygons that\n            // start and end on longitude -180 (like the ones built by\n            // https://github.com/etpinard/sane-topojson).\n            var stitch = new Array(pts.length + 1);\n            var si = 0;\n\n            for(m = 0; m < pts.length; m++) {\n                if(m > crossAntiMeridianIndex) {\n                    stitch[si++] = [pts[m][0] + 360, pts[m][1]];\n                } else if(m === crossAntiMeridianIndex) {\n                    stitch[si++] = pts[m];\n                    stitch[si++] = [pts[m][0], -90];\n                } else {\n                    stitch[si++] = pts[m];\n                }\n            }\n\n            // polygon.tester by default appends pt[0] to the points list,\n            // we must remove it here, to avoid a jump in longitude from 180 to -180,\n            // that would confuse the 'contains' method\n            var tester = polygon.tester(stitch);\n            tester.pts.pop();\n            polygons.push(tester);\n        };\n    } else {\n        // otherwise using same array ref is fine\n        appendPolygon = function(pts) {\n            polygons.push(polygon.tester(pts));\n        };\n    }\n\n    switch(geometry.type) {\n        case 'MultiPolygon':\n            for(j = 0; j < coords.length; j++) {\n                for(k = 0; k < coords[j].length; k++) {\n                    appendPolygon(coords[j][k]);\n                }\n            }\n            break;\n        case 'Polygon':\n            for(j = 0; j < coords.length; j++) {\n                appendPolygon(coords[j]);\n            }\n            break;\n    }\n\n    return polygons;\n}\n\nmodule.exports = {\n    plot: plot,\n    feature2polygons: feature2polygons\n};\n\n},{\"../../lib\":719,\"../../lib/geo_location_utils\":713,\"../../lib/polygon\":731,\"../../lib/topojson_utils\":746,\"./style\":931,\"d3\":163}],930:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function selectPoints(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var xa = searchInfo.xaxis;\n    var ya = searchInfo.yaxis;\n    var selection = [];\n\n    var i, di, ct, x, y;\n\n    if(selectionTester === false) {\n        for(i = 0; i < cd.length; i++) {\n            cd[i].selected = 0;\n        }\n    } else {\n        for(i = 0; i < cd.length; i++) {\n            di = cd[i];\n            ct = di.ct;\n\n            if(!ct) continue;\n\n            x = xa.c2p(ct);\n            y = ya.c2p(ct);\n\n            if(selectionTester.contains([x, y], null, i, searchInfo)) {\n                selection.push({\n                    pointNumber: i,\n                    lon: ct[0],\n                    lat: ct[1]\n                });\n                di.selected = 1;\n            } else {\n                di.selected = 0;\n            }\n        }\n    }\n\n    return selection;\n};\n\n},{}],931:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar Colorscale = _dereq_('../../components/colorscale');\n\nfunction style(gd, calcTrace) {\n    if(calcTrace) styleTrace(gd, calcTrace);\n}\n\nfunction styleTrace(gd, calcTrace) {\n    var trace = calcTrace[0].trace;\n    var s = calcTrace[0].node3;\n    var locs = s.selectAll('.choroplethlocation');\n    var marker = trace.marker || {};\n    var markerLine = marker.line || {};\n\n    var sclFunc = Colorscale.makeColorScaleFuncFromTrace(trace);\n\n    locs.each(function(d) {\n        d3.select(this)\n            .attr('fill', sclFunc(d.z))\n            .call(Color.stroke, d.mlc || markerLine.color)\n            .call(Drawing.dashLine, '', d.mlw || markerLine.width || 0)\n            .style('opacity', marker.opacity);\n    });\n\n    Drawing.selectedPointStyle(locs, trace, gd);\n}\n\nfunction styleOnSelect(gd, calcTrace) {\n    var s = calcTrace[0].node3;\n    var trace = calcTrace[0].trace;\n\n    if(trace.selectedpoints) {\n        Drawing.selectedPointStyle(s.selectAll('.choroplethlocation'), trace, gd);\n    } else {\n        styleTrace(gd, calcTrace);\n    }\n}\n\nmodule.exports = {\n    style: style,\n    styleOnSelect: styleOnSelect\n};\n\n},{\"../../components/color\":593,\"../../components/colorscale\":605,\"../../components/drawing\":614,\"d3\":163}],932:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar choroplethAttrs = _dereq_('../choropleth/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = extendFlat({\n    locations: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    // TODO\n    // Maybe start with only one value (that we could name e.g. 'geojson-id'),\n    // but eventually:\n    // - we could also support for our own dist/topojson/*\n    // - some people might want `geojson-properties-name` to map data arrays to\n    //   GeoJSON features\n    // locationmode: choroplethAttrs.locationmode,\n\n    z: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    // TODO maybe we could also set a \"key\" to dig out values out of the\n    // GeoJSON feature `properties` fields?\n\n    geojson: {\n        valType: 'any',\n        \n        editType: 'calc',\n        \n    },\n\n    // TODO agree on name / behaviour\n    //\n    // 'below' is used currently for layout.mapbox.layers,\n    // even though it's not very plotly-esque.\n    //\n    // Note also, that the mapbox-gl style don't all have the same layers,\n    // see https://codepen.io/etpinard/pen/ydVMwM for full list\n    below: {\n        valType: 'string',\n        \n        editType: 'plot',\n        \n    },\n\n    text: choroplethAttrs.text,\n    hovertext: choroplethAttrs.hovertext,\n\n    marker: {\n        line: {\n            color: extendFlat({}, choroplethAttrs.marker.line.color, {editType: 'plot'}),\n            width: extendFlat({}, choroplethAttrs.marker.line.width, {editType: 'plot'}),\n            editType: 'calc'\n        },\n        // TODO maybe having a dflt less than 1, together with `below:''` would be better?\n        opacity: extendFlat({}, choroplethAttrs.marker.opacity, {editType: 'plot'}),\n        editType: 'calc'\n    },\n\n    selected: {\n        marker: {\n            opacity: extendFlat({}, choroplethAttrs.selected.marker.opacity, {editType: 'plot'}),\n            editType: 'plot'\n        },\n        editType: 'plot'\n    },\n    unselected: {\n        marker: {\n            opacity: extendFlat({}, choroplethAttrs.unselected.marker.opacity, {editType: 'plot'}),\n            editType: 'plot'\n        },\n        editType: 'plot'\n    },\n\n    hoverinfo: choroplethAttrs.hoverinfo,\n    hovertemplate: hovertemplateAttrs({}, {keys: ['properties']})\n},\n\n    colorScaleAttrs('', {\n        cLetter: 'z',\n        editTypeOverride: 'calc'\n    })\n);\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../choropleth/attributes\":923}],933:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar turfArea = _dereq_('@turf/area');\nvar turfCentroid = _dereq_('@turf/centroid');\n\nvar Lib = _dereq_('../../lib');\nvar Colorscale = _dereq_('../../components/colorscale');\nvar Drawing = _dereq_('../../components/drawing');\n\nvar makeBlank = _dereq_('../../lib/geojson_utils').makeBlank;\nvar feature2polygons = _dereq_('../choropleth/plot').feature2polygons;\n\n/* N.B.\n *\n * We fetch the GeoJSON files \"ourselves\" (during\n * mapbox.prototype.fetchMapData) where they are stored in a global object\n * named `PlotlyGeoAssets` (same as for topojson files in `geo` subplots).\n *\n * Mapbox does allow using URLs as geojson sources, but does NOT allow filtering\n * features by feature `id` that are not numbers (more info in:\n * https://github.com/mapbox/mapbox-gl-js/issues/8088).\n */\n\nfunction convert(calcTrace) {\n    var trace = calcTrace[0].trace;\n    var isVisible = trace.visible === true && trace._length !== 0;\n\n    var fill = {\n        layout: {visibility: 'none'},\n        paint: {}\n    };\n\n    var line = {\n        layout: {visibility: 'none'},\n        paint: {}\n    };\n\n    var opts = trace._opts = {\n        fill: fill,\n        line: line,\n        geojson: makeBlank()\n    };\n\n    if(!isVisible) return opts;\n\n    var geojsonIn = typeof trace.geojson === 'string' ?\n        (window.PlotlyGeoAssets || {})[trace.geojson] :\n        trace.geojson;\n\n    // This should not happen, but just in case something goes\n    // really wrong when fetching the GeoJSON\n    if(!Lib.isPlainObject(geojsonIn)) {\n        Lib.error('Oops ... something when wrong when fetching ' + trace.geojson);\n        return opts;\n    }\n\n    var lookup = {};\n    var featuresOut = [];\n    var i;\n\n    for(i = 0; i < calcTrace.length; i++) {\n        var cdi = calcTrace[i];\n        if(cdi.loc) lookup[cdi.loc] = cdi;\n    }\n\n    var sclFunc = Colorscale.makeColorScaleFuncFromTrace(trace);\n    var marker = trace.marker;\n    var markerLine = marker.line || {};\n\n    var opacityFn;\n    if(Lib.isArrayOrTypedArray(marker.opacity)) {\n        opacityFn = function(d) {\n            var mo = d.mo;\n            return isNumeric(mo) ? +Lib.constrain(mo, 0, 1) : 0;\n        };\n    }\n\n    var lineColorFn;\n    if(Lib.isArrayOrTypedArray(markerLine.color)) {\n        lineColorFn = function(d) { return d.mlc; };\n    }\n\n    var lineWidthFn;\n    if(Lib.isArrayOrTypedArray(markerLine.width)) {\n        lineWidthFn = function(d) { return d.mlw; };\n    }\n\n    function appendFeature(fIn) {\n        var cdi = lookup[fIn.id];\n\n        if(cdi) {\n            var geometry = fIn.geometry;\n\n            if(geometry.type === 'Polygon' || geometry.type === 'MultiPolygon') {\n                var props = {fc: sclFunc(cdi.z)};\n\n                if(opacityFn) props.mo = opacityFn(cdi);\n                if(lineColorFn) props.mlc = lineColorFn(cdi);\n                if(lineWidthFn) props.mlw = lineWidthFn(cdi);\n\n                var fOut = {\n                    type: 'Feature',\n                    geometry: geometry,\n                    properties: props\n                };\n\n                cdi._polygons = feature2polygons(fOut);\n                cdi.ct = findCentroid(fOut);\n                cdi.fIn = fIn;\n                cdi.fOut = fOut;\n                featuresOut.push(fOut);\n            } else {\n                Lib.log([\n                    'Location with id', cdi.loc, 'does not have a valid GeoJSON geometry,',\n                    'choroplethmapbox traces only support *Polygon* and *MultiPolygon* geometries.'\n                ].join(' '));\n            }\n        }\n\n        // remove key from lookup, so that we can track (if any)\n        // the locations that did not have a corresponding GeoJSON feature\n        delete lookup[fIn.id];\n    }\n\n    switch(geojsonIn.type) {\n        case 'FeatureCollection':\n            var featuresIn = geojsonIn.features;\n            for(i = 0; i < featuresIn.length; i++) {\n                appendFeature(featuresIn[i]);\n            }\n            break;\n        case 'Feature':\n            appendFeature(geojsonIn);\n            break;\n        default:\n            Lib.warn([\n                'Invalid GeoJSON type', (geojsonIn.type || 'none') + ',',\n                'choroplethmapbox traces only support *FeatureCollection* and *Feature* types.'\n            ].join(' '));\n            return opts;\n    }\n\n    for(var loc in lookup) {\n        Lib.log('Location with id ' + loc + ' does not have a matching feature');\n    }\n\n    var opacitySetting = opacityFn ?\n        {type: 'identity', property: 'mo'} :\n        marker.opacity;\n\n    Lib.extendFlat(fill.paint, {\n        'fill-color': {type: 'identity', property: 'fc'},\n        'fill-opacity': opacitySetting\n    });\n\n    Lib.extendFlat(line.paint, {\n        'line-color': lineColorFn ?\n            {type: 'identity', property: 'mlc'} :\n            markerLine.color,\n        'line-width': lineWidthFn ?\n            {type: 'identity', property: 'mlw'} :\n            markerLine.width,\n        'line-opacity': opacitySetting\n    });\n\n    fill.layout.visibility = 'visible';\n    line.layout.visibility = 'visible';\n\n    opts.geojson = {type: 'FeatureCollection', features: featuresOut};\n\n    convertOnSelect(calcTrace);\n\n    return opts;\n}\n\nfunction convertOnSelect(calcTrace) {\n    var trace = calcTrace[0].trace;\n    var opts = trace._opts;\n    var opacitySetting;\n\n    if(trace.selectedpoints) {\n        var fns = Drawing.makeSelectedPointStyleFns(trace);\n\n        for(var i = 0; i < calcTrace.length; i++) {\n            var cdi = calcTrace[i];\n            if(cdi.fOut) {\n                cdi.fOut.properties.mo2 = fns.selectedOpacityFn(cdi);\n            }\n        }\n\n        opacitySetting = {type: 'identity', property: 'mo2'};\n    } else {\n        opacitySetting = Lib.isArrayOrTypedArray(trace.marker.opacity) ?\n            {type: 'identity', property: 'mo'} :\n            trace.marker.opacity;\n    }\n\n    Lib.extendFlat(opts.fill.paint, {'fill-opacity': opacitySetting});\n    Lib.extendFlat(opts.line.paint, {'line-opacity': opacitySetting});\n\n    return opts;\n}\n\n// TODO this find the centroid of the polygon of maxArea\n// (just like we currently do for geo choropleth polygons),\n// maybe instead it would make more sense to compute the centroid\n// of each polygon and consider those on hover/select\nfunction findCentroid(feature) {\n    var geometry = feature.geometry;\n    var poly;\n\n    if(geometry.type === 'MultiPolygon') {\n        var coords = geometry.coordinates;\n        var maxArea = 0;\n\n        for(var i = 0; i < coords.length; i++) {\n            var polyi = {type: 'Polygon', coordinates: coords[i]};\n            var area = turfArea.default(polyi);\n            if(area > maxArea) {\n                maxArea = area;\n                poly = polyi;\n            }\n        }\n    } else {\n        poly = geometry;\n    }\n\n    return turfCentroid.default(poly).geometry.coordinates;\n}\n\nmodule.exports = {\n    convert: convert,\n    convertOnSelect: convertOnSelect\n};\n\n},{\"../../components/colorscale\":605,\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/geojson_utils\":714,\"../choropleth/plot\":929,\"@turf/area\":55,\"@turf/centroid\":56,\"fast-isnumeric\":225}],934:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var locations = coerce('locations');\n    var z = coerce('z');\n    var geojson = coerce('geojson');\n\n    if(!Lib.isArrayOrTypedArray(locations) || !locations.length ||\n        !Lib.isArrayOrTypedArray(z) || !z.length ||\n        !((typeof geojson === 'string' && geojson !== '') || Lib.isPlainObject(geojson))\n    ) {\n        traceOut.visible = false;\n        return;\n    }\n\n    traceOut._length = Math.min(locations.length, z.length);\n\n    coerce('below');\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    var mlw = coerce('marker.line.width');\n    if(mlw) coerce('marker.line.color');\n    coerce('marker.opacity');\n\n    colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"./attributes\":932}],935:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../heatmap/colorbar'),\n    calc: _dereq_('../choropleth/calc'),\n    plot: _dereq_('./plot'),\n    hoverPoints: _dereq_('../choropleth/hover'),\n    eventData: _dereq_('../choropleth/event_data'),\n    selectPoints: _dereq_('../choropleth/select'),\n\n    styleOnSelect: function(_, cd) {\n        if(cd) {\n            var trace = cd[0].trace;\n            trace._glTrace.updateOnSelect(cd);\n        }\n    },\n\n    getBelow: function(trace, subplot) {\n        var mapLayers = subplot.getMapLayers();\n\n        // find layer just above top-most \"water\" layer\n        // that is not a plotly layer\n        for(var i = mapLayers.length - 2; i >= 0; i--) {\n            var layerId = mapLayers[i].id;\n\n            if(typeof layerId === 'string' &&\n                layerId.indexOf('water') === 0\n             ) {\n                for(var j = i + 1; j < mapLayers.length; j++) {\n                    layerId = mapLayers[j].id;\n\n                    if(typeof layerId === 'string' &&\n                        layerId.indexOf('plotly-') === -1\n                    ) {\n                        return layerId;\n                    }\n                }\n            }\n        }\n    },\n\n    moduleType: 'trace',\n    name: 'choroplethmapbox',\n    basePlotModule: _dereq_('../../plots/mapbox'),\n    categories: ['mapbox', 'gl', 'noOpacity'],\n    meta: {\n        hr_name: 'choropleth_mapbox',\n        \n    }\n};\n\n},{\"../../plots/mapbox\":822,\"../choropleth/calc\":924,\"../choropleth/event_data\":926,\"../choropleth/hover\":927,\"../choropleth/select\":930,\"../heatmap/colorbar\":1004,\"./attributes\":932,\"./defaults\":934,\"./plot\":936}],936:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar convert = _dereq_('./convert').convert;\nvar convertOnSelect = _dereq_('./convert').convertOnSelect;\nvar LAYER_PREFIX = _dereq_('../../plots/mapbox/constants').traceLayerPrefix;\n\nfunction ChoroplethMapbox(subplot, uid) {\n    this.subplot = subplot;\n    this.uid = uid;\n\n    // N.B. fill and line layers share same source\n    this.sourceId = 'source-' + uid;\n\n    this.layerList = [\n        ['fill', LAYER_PREFIX + uid + '-fill'],\n        ['line', LAYER_PREFIX + uid + '-line']\n    ];\n\n    // previous 'below' value,\n    // need this to update it properly\n    this.below = null;\n}\n\nvar proto = ChoroplethMapbox.prototype;\n\nproto.update = function(calcTrace) {\n    this._update(convert(calcTrace));\n};\n\nproto.updateOnSelect = function(calcTrace) {\n    this._update(convertOnSelect(calcTrace));\n};\n\nproto._update = function(optsAll) {\n    var subplot = this.subplot;\n    var layerList = this.layerList;\n    var below = subplot.belowLookup['trace-' + this.uid];\n\n    subplot.map\n        .getSource(this.sourceId)\n        .setData(optsAll.geojson);\n\n    if(below !== this.below) {\n        this._removeLayers();\n        this._addLayers(optsAll, below);\n        this.below = below;\n    }\n\n    for(var i = 0; i < layerList.length; i++) {\n        var item = layerList[i];\n        var k = item[0];\n        var id = item[1];\n        var opts = optsAll[k];\n\n        subplot.setOptions(id, 'setLayoutProperty', opts.layout);\n\n        if(opts.layout.visibility === 'visible') {\n            subplot.setOptions(id, 'setPaintProperty', opts.paint);\n        }\n    }\n};\n\nproto._addLayers = function(optsAll, below) {\n    var subplot = this.subplot;\n    var layerList = this.layerList;\n    var sourceId = this.sourceId;\n\n    for(var i = 0; i < layerList.length; i++) {\n        var item = layerList[i];\n        var k = item[0];\n        var opts = optsAll[k];\n\n        subplot.addLayer({\n            type: k,\n            id: item[1],\n            source: sourceId,\n            layout: opts.layout,\n            paint: opts.paint\n        }, below);\n    }\n};\n\nproto._removeLayers = function() {\n    var map = this.subplot.map;\n    var layerList = this.layerList;\n\n    for(var i = layerList.length - 1; i >= 0; i--) {\n        map.removeLayer(layerList[i][1]);\n    }\n};\n\nproto.dispose = function() {\n    var map = this.subplot.map;\n    this._removeLayers();\n    map.removeSource(this.sourceId);\n};\n\nmodule.exports = function createChoroplethMapbox(subplot, calcTrace) {\n    var trace = calcTrace[0].trace;\n    var choroplethMapbox = new ChoroplethMapbox(subplot, trace.uid);\n    var sourceId = choroplethMapbox.sourceId;\n    var optsAll = convert(calcTrace);\n    var below = choroplethMapbox.below = subplot.belowLookup['trace-' + trace.uid];\n\n    subplot.map.addSource(sourceId, {\n        type: 'geojson',\n        data: optsAll.geojson\n    });\n\n    choroplethMapbox._addLayers(optsAll, below);\n\n    // link ref for quick update during selections\n    calcTrace[0].trace._glTrace = choroplethMapbox;\n\n    return choroplethMapbox;\n};\n\n},{\"../../plots/mapbox/constants\":820,\"./convert\":933}],937:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar mesh3dAttrs = _dereq_('../mesh3d/attributes');\nvar baseAttrs = _dereq_('../../plots/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar attrs = {\n    x: {\n        valType: 'data_array',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    y: {\n        valType: 'data_array',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    z: {\n        valType: 'data_array',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    u: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    v: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    w: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    // TODO add way to specify cone positions independently of the vector field\n    // provided, similar to MATLAB's coneplot Cx/Cy/Cz meshgrids,\n    // see https://www.mathworks.com/help/matlab/ref/coneplot.html\n    //\n    // Alternatively, if our goal is only to 'fill in gaps' in the vector data,\n    // we could try to extend the heatmap 'connectgaps' algorithm to 3D.\n    // From AJ: this particular algorithm which amounts to a Poisson equation,\n    // both for interpolation and extrapolation - is the right one to use for\n    // cones too.  It makes a field with zero divergence, which is a good\n    // baseline assumption for vector fields.\n    //\n    // cones: {\n    //     // potential attributes to add:\n    //     //\n    //     // - meshmode: 'cartesian-product', 'pts', 'grid'\n    //     //\n    //     // under `meshmode: 'grid'`\n    //     // - (x|y|z)grid.start\n    //     // - (x|y|z)grid.end\n    //     // - (x|y|z)grid.size\n    //\n    //     x: {\n    //         valType: 'data_array',\n    //         editType: 'calc',\n    //         \n    //     },\n    //     y: {\n    //         valType: 'data_array',\n    //         editType: 'calc',\n    //         \n    //     },\n    //     z: {\n    //         valType: 'data_array',\n    //         editType: 'calc',\n    //         \n    //     },\n    //\n    //     editType: 'calc',\n    //     \n    // },\n\n    sizemode: {\n        valType: 'enumerated',\n        values: ['scaled', 'absolute'],\n        \n        editType: 'calc',\n        dflt: 'scaled',\n        \n    },\n    sizeref: {\n        valType: 'number',\n        \n        editType: 'calc',\n        min: 0,\n        \n    },\n\n    anchor: {\n        valType: 'enumerated',\n        \n        editType: 'calc',\n        values: ['tip', 'tail', 'cm', 'center'],\n        dflt: 'cm',\n        \n    },\n\n    text: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n    hovertemplate: hovertemplateAttrs({editType: 'calc'}, {keys: ['norm']})\n};\n\nextendFlat(attrs, colorScaleAttrs('', {\n    colorAttr: 'u/v/w norm',\n    showScaleDflt: true,\n    editTypeOverride: 'calc'\n}));\n\nvar fromMesh3d = ['opacity', 'lightposition', 'lighting'];\n\nfromMesh3d.forEach(function(k) {\n    attrs[k] = mesh3dAttrs[k];\n});\n\nattrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {\n    editType: 'calc',\n    flags: ['x', 'y', 'z', 'u', 'v', 'w', 'norm', 'text', 'name'],\n    dflt: 'x+y+z+norm+text+name'\n});\n\nattrs.transforms = undefined;\n\nmodule.exports = attrs;\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../mesh3d/attributes\":1053}],938:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\n\nmodule.exports = function calc(gd, trace) {\n    var u = trace.u;\n    var v = trace.v;\n    var w = trace.w;\n    var len = Math.min(\n        trace.x.length, trace.y.length, trace.z.length,\n        u.length, v.length, w.length\n    );\n    var normMax = -Infinity;\n    var normMin = Infinity;\n\n    for(var i = 0; i < len; i++) {\n        var uu = u[i];\n        var vv = v[i];\n        var ww = w[i];\n        var norm = Math.sqrt(uu * uu + vv * vv + ww * ww);\n\n        normMax = Math.max(normMax, norm);\n        normMin = Math.min(normMin, norm);\n    }\n\n    trace._len = len;\n    trace._normMax = normMax;\n\n    colorscaleCalc(gd, trace, {\n        vals: [normMin, normMax],\n        containerStr: '',\n        cLetter: 'c'\n    });\n};\n\n},{\"../../components/colorscale/calc\":601}],939:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar conePlot = _dereq_('gl-cone3d');\nvar createConeMesh = _dereq_('gl-cone3d').createConeMesh;\n\nvar simpleMap = _dereq_('../../lib').simpleMap;\nvar parseColorScale = _dereq_('../../lib/gl_format_color').parseColorScale;\nvar extractOpts = _dereq_('../../components/colorscale').extractOpts;\nvar zip3 = _dereq_('../../plots/gl3d/zip3');\n\nfunction Cone(scene, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.mesh = null;\n    this.data = null;\n}\n\nvar proto = Cone.prototype;\n\nproto.handlePick = function(selection) {\n    if(selection.object === this.mesh) {\n        var selectIndex = selection.index = selection.data.index;\n        var xx = this.data.x[selectIndex];\n        var yy = this.data.y[selectIndex];\n        var zz = this.data.z[selectIndex];\n        var uu = this.data.u[selectIndex];\n        var vv = this.data.v[selectIndex];\n        var ww = this.data.w[selectIndex];\n\n        selection.traceCoordinate = [\n            xx, yy, zz,\n            uu, vv, ww,\n            Math.sqrt(uu * uu + vv * vv + ww * ww)\n        ];\n\n        var text = this.data.hovertext || this.data.text;\n        if(Array.isArray(text) && text[selectIndex] !== undefined) {\n            selection.textLabel = text[selectIndex];\n        } else if(text) {\n            selection.textLabel = text;\n        }\n\n        return true;\n    }\n};\n\nvar axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2};\nvar anchor2coneOffset = {tip: 1, tail: 0, cm: 0.25, center: 0.5};\nvar anchor2coneSpan = {tip: 1, tail: 1, cm: 0.75, center: 0.5};\n\nfunction convert(scene, trace) {\n    var sceneLayout = scene.fullSceneLayout;\n    var dataScale = scene.dataScale;\n    var coneOpts = {};\n\n    function toDataCoords(arr, axisName) {\n        var ax = sceneLayout[axisName];\n        var scale = dataScale[axisName2scaleIndex[axisName]];\n        return simpleMap(arr, function(v) { return ax.d2l(v) * scale; });\n    }\n\n    coneOpts.vectors = zip3(\n        toDataCoords(trace.u, 'xaxis'),\n        toDataCoords(trace.v, 'yaxis'),\n        toDataCoords(trace.w, 'zaxis'),\n        trace._len\n    );\n\n    coneOpts.positions = zip3(\n        toDataCoords(trace.x, 'xaxis'),\n        toDataCoords(trace.y, 'yaxis'),\n        toDataCoords(trace.z, 'zaxis'),\n        trace._len\n    );\n\n    var cOpts = extractOpts(trace);\n    coneOpts.colormap = parseColorScale(trace);\n    coneOpts.vertexIntensityBounds = [cOpts.min / trace._normMax, cOpts.max / trace._normMax];\n    coneOpts.coneOffset = anchor2coneOffset[trace.anchor];\n\n    if(trace.sizemode === 'scaled') {\n        // unitless sizeref\n        coneOpts.coneSize = trace.sizeref || 0.5;\n    } else {\n        // sizeref here has unit of velocity\n        coneOpts.coneSize = trace.sizeref && trace._normMax ?\n            trace.sizeref / trace._normMax :\n            0.5;\n    }\n\n    var meshData = conePlot(coneOpts);\n\n    // pass gl-mesh3d lighting attributes\n    var lp = trace.lightposition;\n    meshData.lightPosition = [lp.x, lp.y, lp.z];\n    meshData.ambient = trace.lighting.ambient;\n    meshData.diffuse = trace.lighting.diffuse;\n    meshData.specular = trace.lighting.specular;\n    meshData.roughness = trace.lighting.roughness;\n    meshData.fresnel = trace.lighting.fresnel;\n    meshData.opacity = trace.opacity;\n\n    // stash autorange pad value\n    trace._pad = anchor2coneSpan[trace.anchor] * meshData.vectorScale * meshData.coneScale * trace._normMax;\n\n    return meshData;\n}\n\nproto.update = function(data) {\n    this.data = data;\n\n    var meshData = convert(this.scene, data);\n    this.mesh.update(meshData);\n};\n\nproto.dispose = function() {\n    this.scene.glplot.remove(this.mesh);\n    this.mesh.dispose();\n};\n\nfunction createConeTrace(scene, data) {\n    var gl = scene.glplot.gl;\n\n    var meshData = convert(scene, data);\n    var mesh = createConeMesh(gl, meshData);\n\n    var cone = new Cone(scene, data.uid);\n    cone.mesh = mesh;\n    cone.data = data;\n    mesh._trace = cone;\n\n    scene.glplot.add(mesh);\n\n    return cone;\n}\n\nmodule.exports = createConeTrace;\n\n},{\"../../components/colorscale\":605,\"../../lib\":719,\"../../lib/gl_format_color\":716,\"../../plots/gl3d/zip3\":818,\"gl-cone3d\":242}],940:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var u = coerce('u');\n    var v = coerce('v');\n    var w = coerce('w');\n\n    var x = coerce('x');\n    var y = coerce('y');\n    var z = coerce('z');\n\n    if(\n        !u || !u.length || !v || !v.length || !w || !w.length ||\n        !x || !x.length || !y || !y.length || !z || !z.length\n    ) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('sizeref');\n    coerce('sizemode');\n\n    coerce('anchor');\n\n    coerce('lighting.ambient');\n    coerce('lighting.diffuse');\n    coerce('lighting.specular');\n    coerce('lighting.roughness');\n    coerce('lighting.fresnel');\n    coerce('lightposition.x');\n    coerce('lightposition.y');\n    coerce('lightposition.z');\n\n    colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    // disable 1D transforms (for now)\n    traceOut._length = null;\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"./attributes\":937}],941:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'cone',\n    basePlotModule: _dereq_('../../plots/gl3d'),\n    categories: ['gl3d'],\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: {\n        min: 'cmin',\n        max: 'cmax'\n    },\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./convert'),\n    eventData: function(out, pt) {\n        out.norm = pt.traceCoordinate[6];\n        return out;\n    },\n\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/gl3d\":807,\"./attributes\":937,\"./calc\":938,\"./convert\":939,\"./defaults\":940}],942:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar heatmapAttrs = _dereq_('../heatmap/attributes');\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar dash = _dereq_('../../components/drawing/attributes').dash;\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar filterOps = _dereq_('../../constants/filter_ops');\nvar COMPARISON_OPS2 = filterOps.COMPARISON_OPS2;\nvar INTERVAL_OPS = filterOps.INTERVAL_OPS;\n\nvar FORMAT_LINK = _dereq_('../../constants/docs').FORMAT_LINK;\n\nvar scatterLineAttrs = scatterAttrs.line;\n\nmodule.exports = extendFlat({\n    z: heatmapAttrs.z,\n    x: heatmapAttrs.x,\n    x0: heatmapAttrs.x0,\n    dx: heatmapAttrs.dx,\n    y: heatmapAttrs.y,\n    y0: heatmapAttrs.y0,\n    dy: heatmapAttrs.dy,\n    text: heatmapAttrs.text,\n    hovertext: heatmapAttrs.hovertext,\n    transpose: heatmapAttrs.transpose,\n    xtype: heatmapAttrs.xtype,\n    ytype: heatmapAttrs.ytype,\n    zhoverformat: heatmapAttrs.zhoverformat,\n    hovertemplate: heatmapAttrs.hovertemplate,\n\n    connectgaps: heatmapAttrs.connectgaps,\n\n    fillcolor: {\n        valType: 'color',\n        \n        editType: 'calc',\n        \n    },\n\n    autocontour: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        impliedEdits: {\n            'contours.start': undefined,\n            'contours.end': undefined,\n            'contours.size': undefined\n        },\n        \n    },\n    ncontours: {\n        valType: 'integer',\n        dflt: 15,\n        min: 1,\n        \n        editType: 'calc',\n        \n    },\n\n    contours: {\n        type: {\n            valType: 'enumerated',\n            values: ['levels', 'constraint'],\n            dflt: 'levels',\n            \n            editType: 'calc',\n            \n        },\n        start: {\n            valType: 'number',\n            dflt: null,\n            \n            editType: 'plot',\n            impliedEdits: {'^autocontour': false},\n            \n        },\n        end: {\n            valType: 'number',\n            dflt: null,\n            \n            editType: 'plot',\n            impliedEdits: {'^autocontour': false},\n            \n        },\n        size: {\n            valType: 'number',\n            dflt: null,\n            min: 0,\n            \n            editType: 'plot',\n            impliedEdits: {'^autocontour': false},\n            \n        },\n        coloring: {\n            valType: 'enumerated',\n            values: ['fill', 'heatmap', 'lines', 'none'],\n            dflt: 'fill',\n            \n            editType: 'calc',\n            \n        },\n        showlines: {\n            valType: 'boolean',\n            dflt: true,\n            \n            editType: 'plot',\n            \n        },\n        showlabels: {\n            valType: 'boolean',\n            dflt: false,\n            \n            editType: 'plot',\n            \n        },\n        labelfont: fontAttrs({\n            editType: 'plot',\n            colorEditType: 'style',\n            \n        }),\n        labelformat: {\n            valType: 'string',\n            dflt: '',\n            \n            editType: 'plot',\n            \n        },\n        operation: {\n            valType: 'enumerated',\n            values: [].concat(COMPARISON_OPS2).concat(INTERVAL_OPS),\n            \n            dflt: '=',\n            editType: 'calc',\n            \n        },\n        value: {\n            valType: 'any',\n            dflt: 0,\n            \n            editType: 'calc',\n            \n        },\n        editType: 'calc',\n        impliedEdits: {'autocontour': false}\n    },\n\n    line: {\n        color: extendFlat({}, scatterLineAttrs.color, {\n            editType: 'style+colorbars',\n            \n        }),\n        width: extendFlat({}, scatterLineAttrs.width, {\n            editType: 'style+colorbars'\n        }),\n        dash: dash,\n        smoothing: extendFlat({}, scatterLineAttrs.smoothing, {\n            \n        }),\n        editType: 'plot'\n    }\n},\n    colorScaleAttrs('', {\n        cLetter: 'z',\n        autoColorDflt: false,\n        editTypeOverride: 'calc'\n    })\n);\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/drawing/attributes\":613,\"../../constants/docs\":690,\"../../constants/filter_ops\":691,\"../../lib/extend\":710,\"../../plots/font_attributes\":793,\"../heatmap/attributes\":1001,\"../scatter/attributes\":1112}],943:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Colorscale = _dereq_('../../components/colorscale');\n\nvar heatmapCalc = _dereq_('../heatmap/calc');\nvar setContours = _dereq_('./set_contours');\nvar endPlus = _dereq_('./end_plus');\n\n// most is the same as heatmap calc, then adjust it\n// though a few things inside heatmap calc still look for\n// contour maps, because the makeBoundArray calls are too entangled\nmodule.exports = function calc(gd, trace) {\n    var cd = heatmapCalc(gd, trace);\n\n    var zOut = cd[0].z;\n    setContours(trace, zOut);\n\n    var contours = trace.contours;\n    var cOpts = Colorscale.extractOpts(trace);\n    var cVals;\n\n    if(contours.coloring === 'heatmap' && cOpts.auto && trace.autocontour === false) {\n        var start = contours.start;\n        var end = endPlus(contours);\n        var cs = contours.size || 1;\n        var nc = Math.floor((end - start) / cs) + 1;\n\n        if(!isFinite(cs)) {\n            cs = 1;\n            nc = 1;\n        }\n\n        var min0 = start - cs / 2;\n        var max0 = min0 + nc * cs;\n        cVals = [min0, max0];\n    } else {\n        cVals = zOut;\n    }\n\n    Colorscale.calc(gd, trace, {vals: cVals, cLetter: 'z'});\n\n    return cd;\n};\n\n},{\"../../components/colorscale\":605,\"../heatmap/calc\":1002,\"./end_plus\":953,\"./set_contours\":961}],944:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function(pathinfo, operation, perimeter, trace) {\n    // Abandon all hope, ye who enter here.\n    var i, v1, v2;\n    var pi0 = pathinfo[0];\n    var na = pi0.x.length;\n    var nb = pi0.y.length;\n    var z = pi0.z;\n    var contours = trace.contours;\n\n    var boundaryMax = -Infinity;\n    var boundaryMin = Infinity;\n\n    for(i = 0; i < nb; i++) {\n        boundaryMin = Math.min(boundaryMin, z[i][0]);\n        boundaryMin = Math.min(boundaryMin, z[i][na - 1]);\n        boundaryMax = Math.max(boundaryMax, z[i][0]);\n        boundaryMax = Math.max(boundaryMax, z[i][na - 1]);\n    }\n\n    for(i = 1; i < na - 1; i++) {\n        boundaryMin = Math.min(boundaryMin, z[0][i]);\n        boundaryMin = Math.min(boundaryMin, z[nb - 1][i]);\n        boundaryMax = Math.max(boundaryMax, z[0][i]);\n        boundaryMax = Math.max(boundaryMax, z[nb - 1][i]);\n    }\n\n    pi0.prefixBoundary = false;\n\n    switch(operation) {\n        case '>':\n            if(contours.value > boundaryMax) {\n                pi0.prefixBoundary = true;\n            }\n            break;\n        case '<':\n            if(contours.value < boundaryMin) {\n                pi0.prefixBoundary = true;\n            }\n            break;\n        case '[]':\n            v1 = Math.min.apply(null, contours.value);\n            v2 = Math.max.apply(null, contours.value);\n            if(v2 < boundaryMin || v1 > boundaryMax) {\n                pi0.prefixBoundary = true;\n            }\n            break;\n        case '][':\n            v1 = Math.min.apply(null, contours.value);\n            v2 = Math.max.apply(null, contours.value);\n            if(v1 < boundaryMin && v2 > boundaryMax) {\n                pi0.prefixBoundary = true;\n            }\n            break;\n    }\n};\n\n},{}],945:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar extractOpts = _dereq_('../../components/colorscale').extractOpts;\nvar makeColorMap = _dereq_('./make_color_map');\nvar endPlus = _dereq_('./end_plus');\n\nfunction calc(gd, trace, opts) {\n    var contours = trace.contours;\n    var line = trace.line;\n    var cs = contours.size || 1;\n    var coloring = contours.coloring;\n    var colorMap = makeColorMap(trace, {isColorbar: true});\n\n    if(coloring === 'heatmap') {\n        var cOpts = extractOpts(trace);\n        opts._fillgradient = trace.colorscale;\n        opts._zrange = [cOpts.min, cOpts.max];\n    } else if(coloring === 'fill') {\n        opts._fillcolor = colorMap;\n    }\n\n    opts._line = {\n        color: coloring === 'lines' ? colorMap : line.color,\n        width: contours.showlines !== false ? line.width : 0,\n        dash: line.dash\n    };\n\n    opts._levels = {\n        start: contours.start,\n        end: endPlus(contours),\n        size: cs\n    };\n}\n\nmodule.exports = {\n    min: 'zmin',\n    max: 'zmax',\n    calc: calc\n};\n\n},{\"../../components/colorscale\":605,\"./end_plus\":953,\"./make_color_map\":958}],946:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\nmodule.exports = {\n    // some constants to help with marching squares algorithm\n    // where does the path start for each index?\n    BOTTOMSTART: [1, 9, 13, 104, 713],\n    TOPSTART: [4, 6, 7, 104, 713],\n    LEFTSTART: [8, 12, 14, 208, 1114],\n    RIGHTSTART: [2, 3, 11, 208, 1114],\n\n    // which way [dx,dy] do we leave a given index?\n    // saddles are already disambiguated\n    NEWDELTA: [\n        null, [-1, 0], [0, -1], [-1, 0],\n        [1, 0], null, [0, -1], [-1, 0],\n        [0, 1], [0, 1], null, [0, 1],\n        [1, 0], [1, 0], [0, -1]\n    ],\n\n    // for each saddle, the first index here is used\n    // for dx||dy<0, the second for dx||dy>0\n    CHOOSESADDLE: {\n        104: [4, 1],\n        208: [2, 8],\n        713: [7, 13],\n        1114: [11, 14]\n    },\n\n    // after one index has been used for a saddle, which do we\n    // substitute to be used up later?\n    SADDLEREMAINDER: {1: 4, 2: 8, 4: 1, 7: 13, 8: 2, 11: 14, 13: 7, 14: 11},\n\n    // length of a contour, as a multiple of the plot area diagonal, per label\n    LABELDISTANCE: 2,\n\n    // number of contour levels after which we start increasing the number of\n    // labels we draw. Many contours means they will generally be close\n    // together, so it will be harder to follow a long way to find a label\n    LABELINCREASE: 10,\n\n    // minimum length of a contour line, as a multiple of the label length,\n    // at which we draw *any* labels\n    LABELMIN: 3,\n\n    // max number of labels to draw on a single contour path, no matter how long\n    LABELMAX: 10,\n\n    // constants for the label position cost function\n    LABELOPTIMIZER: {\n        // weight given to edge proximity\n        EDGECOST: 1,\n        // weight given to the angle off horizontal\n        ANGLECOST: 1,\n        // weight given to distance from already-placed labels\n        NEIGHBORCOST: 5,\n        // cost multiplier for labels on the same level\n        SAMELEVELFACTOR: 10,\n        // minimum distance (as a multiple of the label length)\n        // for labels on the same level\n        SAMELEVELDISTANCE: 5,\n        // maximum cost before we won't even place the label\n        MAXCOST: 100,\n        // number of evenly spaced points to look at in the first\n        // iteration of the search\n        INITIALSEARCHPOINTS: 10,\n        // number of binary search iterations after the initial wide search\n        ITERATIONS: 5\n    }\n};\n\n},{}],947:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar handleLabelDefaults = _dereq_('./label_defaults');\n\nvar Color = _dereq_('../../components/color');\nvar addOpacity = Color.addOpacity;\nvar opacity = Color.opacity;\n\nvar filterOps = _dereq_('../../constants/filter_ops');\nvar CONSTRAINT_REDUCTION = filterOps.CONSTRAINT_REDUCTION;\nvar COMPARISON_OPS2 = filterOps.COMPARISON_OPS2;\n\nmodule.exports = function handleConstraintDefaults(traceIn, traceOut, coerce, layout, defaultColor, opts) {\n    var contours = traceOut.contours;\n    var showLines, lineColor, fillColor;\n\n    var operation = coerce('contours.operation');\n    contours._operation = CONSTRAINT_REDUCTION[operation];\n\n    handleConstraintValueDefaults(coerce, contours);\n\n    if(operation === '=') {\n        showLines = contours.showlines = true;\n    } else {\n        showLines = coerce('contours.showlines');\n        fillColor = coerce('fillcolor', addOpacity(\n            (traceIn.line || {}).color || defaultColor, 0.5\n        ));\n    }\n\n    if(showLines) {\n        var lineDfltColor = fillColor && opacity(fillColor) ?\n            addOpacity(traceOut.fillcolor, 1) :\n            defaultColor;\n        lineColor = coerce('line.color', lineDfltColor);\n        coerce('line.width', 2);\n        coerce('line.dash');\n    }\n\n    coerce('line.smoothing');\n\n    handleLabelDefaults(coerce, layout, lineColor, opts);\n};\n\nfunction handleConstraintValueDefaults(coerce, contours) {\n    var zvalue;\n\n    if(COMPARISON_OPS2.indexOf(contours.operation) === -1) {\n        // Requires an array of two numbers:\n        coerce('contours.value', [0, 1]);\n\n        if(!Array.isArray(contours.value)) {\n            if(isNumeric(contours.value)) {\n                zvalue = parseFloat(contours.value);\n                contours.value = [zvalue, zvalue + 1];\n            }\n        } else if(contours.value.length > 2) {\n            contours.value = contours.value.slice(2);\n        } else if(contours.length === 0) {\n            contours.value = [0, 1];\n        } else if(contours.length < 2) {\n            zvalue = parseFloat(contours.value[0]);\n            contours.value = [zvalue, zvalue + 1];\n        } else {\n            contours.value = [\n                parseFloat(contours.value[0]),\n                parseFloat(contours.value[1])\n            ];\n        }\n    } else {\n        // Requires a single scalar:\n        coerce('contours.value', 0);\n\n        if(!isNumeric(contours.value)) {\n            if(Array.isArray(contours.value)) {\n                contours.value = parseFloat(contours.value[0]);\n            } else {\n                contours.value = 0;\n            }\n        }\n    }\n}\n\n},{\"../../components/color\":593,\"../../constants/filter_ops\":691,\"./label_defaults\":957,\"fast-isnumeric\":225}],948:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar filterOps = _dereq_('../../constants/filter_ops');\nvar isNumeric = _dereq_('fast-isnumeric');\n\n// This syntax conforms to the existing filter transform syntax, but we don't care\n// about open vs. closed intervals for simply drawing contours constraints:\nmodule.exports = {\n    '[]': makeRangeSettings('[]'),\n    '][': makeRangeSettings(']['),\n    '>': makeInequalitySettings('>'),\n    '<': makeInequalitySettings('<'),\n    '=': makeInequalitySettings('=')\n};\n\n// This does not in any way shape or form support calendars. It's adapted from\n// transforms/filter.js.\nfunction coerceValue(operation, value) {\n    var hasArrayValue = Array.isArray(value);\n\n    var coercedValue;\n\n    function coerce(value) {\n        return isNumeric(value) ? (+value) : null;\n    }\n\n    if(filterOps.COMPARISON_OPS2.indexOf(operation) !== -1) {\n        coercedValue = hasArrayValue ? coerce(value[0]) : coerce(value);\n    } else if(filterOps.INTERVAL_OPS.indexOf(operation) !== -1) {\n        coercedValue = hasArrayValue ?\n            [coerce(value[0]), coerce(value[1])] :\n            [coerce(value), coerce(value)];\n    } else if(filterOps.SET_OPS.indexOf(operation) !== -1) {\n        coercedValue = hasArrayValue ? value.map(coerce) : [coerce(value)];\n    }\n\n    return coercedValue;\n}\n\n// Returns a parabola scaled so that the min/max is either +/- 1 and zero at the two values\n// provided. The data is mapped by this function when constructing intervals so that it's\n// very easy to construct contours as normal.\nfunction makeRangeSettings(operation) {\n    return function(value) {\n        value = coerceValue(operation, value);\n\n        // Ensure proper ordering:\n        var min = Math.min(value[0], value[1]);\n        var max = Math.max(value[0], value[1]);\n\n        return {\n            start: min,\n            end: max,\n            size: max - min\n        };\n    };\n}\n\nfunction makeInequalitySettings(operation) {\n    return function(value) {\n        value = coerceValue(operation, value);\n\n        return {\n            start: value,\n            end: Infinity,\n            size: Infinity\n        };\n    };\n}\n\n},{\"../../constants/filter_ops\":691,\"fast-isnumeric\":225}],949:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function handleContourDefaults(traceIn, traceOut, coerce, coerce2) {\n    var contourStart = coerce2('contours.start');\n    var contourEnd = coerce2('contours.end');\n    var missingEnd = (contourStart === false) || (contourEnd === false);\n\n    // normally we only need size if autocontour is off. But contour.calc\n    // pushes its calculated contour size back to the input trace, so for\n    // things like restyle that can call supplyDefaults without calc\n    // after the initial draw, we can just reuse the previous calculation\n    var contourSize = coerce('contours.size');\n    var autoContour;\n\n    if(missingEnd) autoContour = traceOut.autocontour = true;\n    else autoContour = coerce('autocontour', false);\n\n    if(autoContour || !contourSize) coerce('ncontours');\n};\n\n},{}],950:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n// The contour extraction is great, except it totally fails for constraints because we\n// need weird range loops and flipped contours instead of the usual format. This function\n// does some weird manipulation of the extracted pathinfo data such that it magically\n// draws contours correctly *as* constraints.\nmodule.exports = function(pathinfo, operation) {\n    var i, pi0, pi1;\n\n    var op0 = function(arr) { return arr.reverse(); };\n    var op1 = function(arr) { return arr; };\n\n    switch(operation) {\n        case '=':\n        case '<':\n            return pathinfo;\n        case '>':\n            if(pathinfo.length !== 1) {\n                Lib.warn('Contour data invalid for the specified inequality operation.');\n            }\n\n            // In this case there should be exactly two contour levels in pathinfo. We\n            // simply concatenate the info into one pathinfo and flip all of the data\n            // in one. This will draw the contour as closed.\n            pi0 = pathinfo[0];\n\n            for(i = 0; i < pi0.edgepaths.length; i++) {\n                pi0.edgepaths[i] = op0(pi0.edgepaths[i]);\n            }\n\n            for(i = 0; i < pi0.paths.length; i++) {\n                pi0.paths[i] = op0(pi0.paths[i]);\n            }\n            return pathinfo;\n        case '][':\n            var tmp = op0;\n            op0 = op1;\n            op1 = tmp;\n            // It's a nice rule, except this definitely *is* what's intended here.\n            /* eslint-disable: no-fallthrough */\n        case '[]':\n            /* eslint-enable: no-fallthrough */\n            if(pathinfo.length !== 2) {\n                Lib.warn('Contour data invalid for the specified inequality range operation.');\n            }\n\n            // In this case there should be exactly two contour levels in pathinfo. We\n            // simply concatenate the info into one pathinfo and flip all of the data\n            // in one. This will draw the contour as closed.\n            pi0 = copyPathinfo(pathinfo[0]);\n            pi1 = copyPathinfo(pathinfo[1]);\n\n            for(i = 0; i < pi0.edgepaths.length; i++) {\n                pi0.edgepaths[i] = op0(pi0.edgepaths[i]);\n            }\n\n            for(i = 0; i < pi0.paths.length; i++) {\n                pi0.paths[i] = op0(pi0.paths[i]);\n            }\n\n            while(pi1.edgepaths.length) {\n                pi0.edgepaths.push(op1(pi1.edgepaths.shift()));\n            }\n            while(pi1.paths.length) {\n                pi0.paths.push(op1(pi1.paths.shift()));\n            }\n            return [pi0];\n    }\n};\n\nfunction copyPathinfo(pi) {\n    return Lib.extendFlat({}, pi, {\n        edgepaths: Lib.extendDeep([], pi.edgepaths),\n        paths: Lib.extendDeep([], pi.paths)\n    });\n}\n\n},{\"../../lib\":719}],951:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleXYZDefaults = _dereq_('../heatmap/xyz_defaults');\nvar handleConstraintDefaults = _dereq_('./constraint_defaults');\nvar handleContoursDefaults = _dereq_('./contours_defaults');\nvar handleStyleDefaults = _dereq_('./style_defaults');\nvar attributes = _dereq_('./attributes');\n\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    function coerce2(attr) {\n        return Lib.coerce2(traceIn, traceOut, attributes, attr);\n    }\n\n    var len = handleXYZDefaults(traceIn, traceOut, coerce, layout);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    var isConstraint = (coerce('contours.type') === 'constraint');\n    coerce('connectgaps', Lib.isArray1D(traceOut.z));\n\n    if(isConstraint) {\n        handleConstraintDefaults(traceIn, traceOut, coerce, layout, defaultColor);\n    } else {\n        handleContoursDefaults(traceIn, traceOut, coerce, coerce2);\n        handleStyleDefaults(traceIn, traceOut, coerce, layout);\n    }\n};\n\n},{\"../../lib\":719,\"../heatmap/xyz_defaults\":1015,\"./attributes\":942,\"./constraint_defaults\":947,\"./contours_defaults\":949,\"./style_defaults\":963}],952:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar constraintMapping = _dereq_('./constraint_mapping');\nvar endPlus = _dereq_('./end_plus');\n\nmodule.exports = function emptyPathinfo(contours, plotinfo, cd0) {\n    var contoursFinal = (contours.type === 'constraint') ?\n        constraintMapping[contours._operation](contours.value) :\n        contours;\n\n    var cs = contoursFinal.size;\n    var pathinfo = [];\n    var end = endPlus(contoursFinal);\n\n    var carpet = cd0.trace._carpetTrace;\n\n    var basePathinfo = carpet ? {\n        // store axes so we can convert to px\n        xaxis: carpet.aaxis,\n        yaxis: carpet.baxis,\n        // full data arrays to use for interpolation\n        x: cd0.a,\n        y: cd0.b\n    } : {\n        xaxis: plotinfo.xaxis,\n        yaxis: plotinfo.yaxis,\n        x: cd0.x,\n        y: cd0.y\n    };\n\n    for(var ci = contoursFinal.start; ci < end; ci += cs) {\n        pathinfo.push(Lib.extendFlat({\n            level: ci,\n            // all the cells with nontrivial marching index\n            crossings: {},\n            // starting points on the edges of the lattice for each contour\n            starts: [],\n            // all unclosed paths (may have less items than starts,\n            // if a path is closed by rounding)\n            edgepaths: [],\n            // all closed paths\n            paths: [],\n            z: cd0.z,\n            smoothing: cd0.trace.line.smoothing\n        }, basePathinfo));\n\n        if(pathinfo.length > 1000) {\n            Lib.warn('Too many contours, clipping at 1000', contours);\n            break;\n        }\n    }\n    return pathinfo;\n};\n\n},{\"../../lib\":719,\"./constraint_mapping\":948,\"./end_plus\":953}],953:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n/*\n * tiny helper to move the end of the contours a little to prevent\n * losing the last contour to rounding errors\n */\nmodule.exports = function endPlus(contours) {\n    return contours.end + contours.size / 1e6;\n};\n\n},{}],954:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar constants = _dereq_('./constants');\n\nmodule.exports = function findAllPaths(pathinfo, xtol, ytol) {\n    var cnt,\n        startLoc,\n        i,\n        pi,\n        j;\n\n    // Default just passes these values through as they were before:\n    xtol = xtol || 0.01;\n    ytol = ytol || 0.01;\n\n    for(i = 0; i < pathinfo.length; i++) {\n        pi = pathinfo[i];\n\n        for(j = 0; j < pi.starts.length; j++) {\n            startLoc = pi.starts[j];\n            makePath(pi, startLoc, 'edge', xtol, ytol);\n        }\n\n        cnt = 0;\n        while(Object.keys(pi.crossings).length && cnt < 10000) {\n            cnt++;\n            startLoc = Object.keys(pi.crossings)[0].split(',').map(Number);\n            makePath(pi, startLoc, undefined, xtol, ytol);\n        }\n        if(cnt === 10000) Lib.log('Infinite loop in contour?');\n    }\n};\n\nfunction equalPts(pt1, pt2, xtol, ytol) {\n    return Math.abs(pt1[0] - pt2[0]) < xtol &&\n           Math.abs(pt1[1] - pt2[1]) < ytol;\n}\n\n// distance in index units - uses the 3rd and 4th items in points\nfunction ptDist(pt1, pt2) {\n    var dx = pt1[2] - pt2[2];\n    var dy = pt1[3] - pt2[3];\n    return Math.sqrt(dx * dx + dy * dy);\n}\n\nfunction makePath(pi, loc, edgeflag, xtol, ytol) {\n    var startLocStr = loc.join(',');\n    var locStr = startLocStr;\n    var mi = pi.crossings[locStr];\n    var marchStep = startStep(mi, edgeflag, loc);\n    // start by going backward a half step and finding the crossing point\n    var pts = [getInterpPx(pi, loc, [-marchStep[0], -marchStep[1]])];\n    var startStepStr = marchStep.join(',');\n    var m = pi.z.length;\n    var n = pi.z[0].length;\n    var cnt;\n\n    // now follow the path\n    for(cnt = 0; cnt < 10000; cnt++) { // just to avoid infinite loops\n        if(mi > 20) {\n            mi = constants.CHOOSESADDLE[mi][(marchStep[0] || marchStep[1]) < 0 ? 0 : 1];\n            pi.crossings[locStr] = constants.SADDLEREMAINDER[mi];\n        } else {\n            delete pi.crossings[locStr];\n        }\n\n        marchStep = constants.NEWDELTA[mi];\n        if(!marchStep) {\n            Lib.log('Found bad marching index:', mi, loc, pi.level);\n            break;\n        }\n\n        // find the crossing a half step forward, and then take the full step\n        pts.push(getInterpPx(pi, loc, marchStep));\n        loc[0] += marchStep[0];\n        loc[1] += marchStep[1];\n\n        // don't include the same point multiple times\n        if(equalPts(pts[pts.length - 1], pts[pts.length - 2], xtol, ytol)) pts.pop();\n        locStr = loc.join(',');\n\n        var atEdge = (marchStep[0] && (loc[0] < 0 || loc[0] > n - 2)) ||\n                (marchStep[1] && (loc[1] < 0 || loc[1] > m - 2));\n        var closedLoop = (locStr === startLocStr) && (marchStep.join(',') === startStepStr);\n\n        // have we completed a loop, or reached an edge?\n        if((closedLoop) || (edgeflag && atEdge)) break;\n\n        mi = pi.crossings[locStr];\n    }\n\n    if(cnt === 10000) {\n        Lib.log('Infinite loop in contour?');\n    }\n    var closedpath = equalPts(pts[0], pts[pts.length - 1], xtol, ytol);\n    var totaldist = 0;\n    var distThresholdFactor = 0.2 * pi.smoothing;\n    var alldists = [];\n    var cropstart = 0;\n    var distgroup, cnt2, cnt3, newpt, ptcnt, ptavg, thisdist,\n        i, j, edgepathi, edgepathj;\n\n    /*\n     * Check for points that are too close together (<1/5 the average dist\n     * *in grid index units* (important for log axes and nonuniform grids),\n     * less if less smoothed) and just take the center (or avg of center 2).\n     * This cuts down on funny behavior when a point is very close to a\n     * contour level.\n     */\n    for(cnt = 1; cnt < pts.length; cnt++) {\n        thisdist = ptDist(pts[cnt], pts[cnt - 1]);\n        totaldist += thisdist;\n        alldists.push(thisdist);\n    }\n\n    var distThreshold = totaldist / alldists.length * distThresholdFactor;\n\n    function getpt(i) { return pts[i % pts.length]; }\n\n    for(cnt = pts.length - 2; cnt >= cropstart; cnt--) {\n        distgroup = alldists[cnt];\n        if(distgroup < distThreshold) {\n            cnt3 = 0;\n            for(cnt2 = cnt - 1; cnt2 >= cropstart; cnt2--) {\n                if(distgroup + alldists[cnt2] < distThreshold) {\n                    distgroup += alldists[cnt2];\n                } else break;\n            }\n\n            // closed path with close points wrapping around the boundary?\n            if(closedpath && cnt === pts.length - 2) {\n                for(cnt3 = 0; cnt3 < cnt2; cnt3++) {\n                    if(distgroup + alldists[cnt3] < distThreshold) {\n                        distgroup += alldists[cnt3];\n                    } else break;\n                }\n            }\n            ptcnt = cnt - cnt2 + cnt3 + 1;\n            ptavg = Math.floor((cnt + cnt2 + cnt3 + 2) / 2);\n\n            // either endpoint included: keep the endpoint\n            if(!closedpath && cnt === pts.length - 2) newpt = pts[pts.length - 1];\n            else if(!closedpath && cnt2 === -1) newpt = pts[0];\n\n            // odd # of points - just take the central one\n            else if(ptcnt % 2) newpt = getpt(ptavg);\n\n            // even # of pts - average central two\n            else {\n                newpt = [(getpt(ptavg)[0] + getpt(ptavg + 1)[0]) / 2,\n                    (getpt(ptavg)[1] + getpt(ptavg + 1)[1]) / 2];\n            }\n\n            pts.splice(cnt2 + 1, cnt - cnt2 + 1, newpt);\n            cnt = cnt2 + 1;\n            if(cnt3) cropstart = cnt3;\n            if(closedpath) {\n                if(cnt === pts.length - 2) pts[cnt3] = pts[pts.length - 1];\n                else if(cnt === 0) pts[pts.length - 1] = pts[0];\n            }\n        }\n    }\n    pts.splice(0, cropstart);\n\n    // done with the index parts - remove them so path generation works right\n    // because it depends on only having [xpx, ypx]\n    for(cnt = 0; cnt < pts.length; cnt++) pts[cnt].length = 2;\n\n    // don't return single-point paths (ie all points were the same\n    // so they got deleted?)\n    if(pts.length < 2) return;\n    else if(closedpath) {\n        pts.pop();\n        pi.paths.push(pts);\n    } else {\n        if(!edgeflag) {\n            Lib.log('Unclosed interior contour?',\n                pi.level, startLocStr, pts.join('L'));\n        }\n\n        // edge path - does it start where an existing edge path ends, or vice versa?\n        var merged = false;\n        for(i = 0; i < pi.edgepaths.length; i++) {\n            edgepathi = pi.edgepaths[i];\n            if(!merged && equalPts(edgepathi[0], pts[pts.length - 1], xtol, ytol)) {\n                pts.pop();\n                merged = true;\n\n                // now does it ALSO meet the end of another (or the same) path?\n                var doublemerged = false;\n                for(j = 0; j < pi.edgepaths.length; j++) {\n                    edgepathj = pi.edgepaths[j];\n                    if(equalPts(edgepathj[edgepathj.length - 1], pts[0], xtol, ytol)) {\n                        doublemerged = true;\n                        pts.shift();\n                        pi.edgepaths.splice(i, 1);\n                        if(j === i) {\n                            // the path is now closed\n                            pi.paths.push(pts.concat(edgepathj));\n                        } else {\n                            if(j > i) j--;\n                            pi.edgepaths[j] = edgepathj.concat(pts, edgepathi);\n                        }\n                        break;\n                    }\n                }\n                if(!doublemerged) {\n                    pi.edgepaths[i] = pts.concat(edgepathi);\n                }\n            }\n        }\n        for(i = 0; i < pi.edgepaths.length; i++) {\n            if(merged) break;\n            edgepathi = pi.edgepaths[i];\n            if(equalPts(edgepathi[edgepathi.length - 1], pts[0], xtol, ytol)) {\n                pts.shift();\n                pi.edgepaths[i] = edgepathi.concat(pts);\n                merged = true;\n            }\n        }\n\n        if(!merged) pi.edgepaths.push(pts);\n    }\n}\n\n// special function to get the marching step of the\n// first point in the path (leading to loc)\nfunction startStep(mi, edgeflag, loc) {\n    var dx = 0;\n    var dy = 0;\n    if(mi > 20 && edgeflag) {\n        // these saddles start at +/- x\n        if(mi === 208 || mi === 1114) {\n            // if we're starting at the left side, we must be going right\n            dx = loc[0] === 0 ? 1 : -1;\n        } else {\n            // if we're starting at the bottom, we must be going up\n            dy = loc[1] === 0 ? 1 : -1;\n        }\n    } else if(constants.BOTTOMSTART.indexOf(mi) !== -1) dy = 1;\n    else if(constants.LEFTSTART.indexOf(mi) !== -1) dx = 1;\n    else if(constants.TOPSTART.indexOf(mi) !== -1) dy = -1;\n    else dx = -1;\n    return [dx, dy];\n}\n\n/*\n * Find the pixel coordinates of a particular crossing\n *\n * @param {object} pi: the pathinfo object at this level\n * @param {array} loc: the grid index [x, y] of the crossing\n * @param {array} step: the direction [dx, dy] we're moving on the grid\n *\n * @return {array} [xpx, ypx, xi, yi]: the first two are the pixel location,\n *   the next two are the interpolated grid indices, which we use for\n *   distance calculations to delete points that are too close together.\n *   This is important when the grid is nonuniform (and most dramatically when\n *   we're on log axes and include invalid (0 or negative) values.\n *   It's crucial to delete these extra two before turning an array of these\n *   points into a path, because those routines require length-2 points.\n */\nfunction getInterpPx(pi, loc, step) {\n    var locx = loc[0] + Math.max(step[0], 0);\n    var locy = loc[1] + Math.max(step[1], 0);\n    var zxy = pi.z[locy][locx];\n    var xa = pi.xaxis;\n    var ya = pi.yaxis;\n\n    if(step[1]) {\n        var dx = (pi.level - zxy) / (pi.z[locy][locx + 1] - zxy);\n\n        return [xa.c2p((1 - dx) * pi.x[locx] + dx * pi.x[locx + 1], true),\n            ya.c2p(pi.y[locy], true),\n            locx + dx, locy];\n    } else {\n        var dy = (pi.level - zxy) / (pi.z[locy + 1][locx] - zxy);\n        return [xa.c2p(pi.x[locx], true),\n            ya.c2p((1 - dy) * pi.y[locy] + dy * pi.y[locy + 1], true),\n            locx, locy + dy];\n    }\n}\n\n},{\"../../lib\":719,\"./constants\":946}],955:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Color = _dereq_('../../components/color');\n\nvar heatmapHoverPoints = _dereq_('../heatmap/hover');\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer) {\n    var hoverData = heatmapHoverPoints(pointData, xval, yval, hovermode, hoverLayer, true);\n\n    if(hoverData) {\n        hoverData.forEach(function(hoverPt) {\n            var trace = hoverPt.trace;\n            if(trace.contours.type === 'constraint') {\n                if(trace.fillcolor && Color.opacity(trace.fillcolor)) {\n                    hoverPt.color = Color.addOpacity(trace.fillcolor, 1);\n                } else if(trace.contours.showlines && Color.opacity(trace.line.color)) {\n                    hoverPt.color = Color.addOpacity(trace.line.color, 1);\n                }\n            }\n        });\n    }\n\n    return hoverData;\n};\n\n},{\"../../components/color\":593,\"../heatmap/hover\":1008}],956:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot').plot,\n    style: _dereq_('./style'),\n    colorbar: _dereq_('./colorbar'),\n    hoverPoints: _dereq_('./hover'),\n\n    moduleType: 'trace',\n    name: 'contour',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', '2dMap', 'contour', 'showLegend'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"./attributes\":942,\"./calc\":943,\"./colorbar\":945,\"./defaults\":951,\"./hover\":955,\"./plot\":960,\"./style\":962}],957:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function handleLabelDefaults(coerce, layout, lineColor, opts) {\n    if(!opts) opts = {};\n    var showLabels = coerce('contours.showlabels');\n    if(showLabels) {\n        var globalFont = layout.font;\n        Lib.coerceFont(coerce, 'contours.labelfont', {\n            family: globalFont.family,\n            size: globalFont.size,\n            color: lineColor\n        });\n        coerce('contours.labelformat');\n    }\n\n    if(opts.hasHover !== false) coerce('zhoverformat');\n};\n\n},{\"../../lib\":719}],958:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Colorscale = _dereq_('../../components/colorscale');\nvar endPlus = _dereq_('./end_plus');\n\nmodule.exports = function makeColorMap(trace) {\n    var contours = trace.contours;\n    var start = contours.start;\n    var end = endPlus(contours);\n    var cs = contours.size || 1;\n    var nc = Math.floor((end - start) / cs) + 1;\n    var extra = contours.coloring === 'lines' ? 0 : 1;\n    var cOpts = Colorscale.extractOpts(trace);\n\n    if(!isFinite(cs)) {\n        cs = 1;\n        nc = 1;\n    }\n\n    var scl = cOpts.reversescale ?\n        Colorscale.flipScale(cOpts.colorscale) :\n        cOpts.colorscale;\n\n    var len = scl.length;\n    var domain = new Array(len);\n    var range = new Array(len);\n\n    var si, i;\n\n    if(contours.coloring === 'heatmap') {\n        var zmin0 = cOpts.min;\n        var zmax0 = cOpts.max;\n\n        for(i = 0; i < len; i++) {\n            si = scl[i];\n            domain[i] = si[0] * (zmax0 - zmin0) + zmin0;\n            range[i] = si[1];\n        }\n\n        // do the contours extend beyond the colorscale?\n        // if so, extend the colorscale with constants\n        var zRange = d3.extent([\n            zmin0,\n            zmax0,\n            contours.start,\n            contours.start + cs * (nc - 1)\n        ]);\n        var zmin = zRange[zmin0 < zmax0 ? 0 : 1];\n        var zmax = zRange[zmin0 < zmax0 ? 1 : 0];\n\n        if(zmin !== zmin0) {\n            domain.splice(0, 0, zmin);\n            range.splice(0, 0, range[0]);\n        }\n\n        if(zmax !== zmax0) {\n            domain.push(zmax);\n            range.push(range[range.length - 1]);\n        }\n    } else {\n        for(i = 0; i < len; i++) {\n            si = scl[i];\n            domain[i] = (si[0] * (nc + extra - 1) - (extra / 2)) * cs + start;\n            range[i] = si[1];\n        }\n    }\n\n    return Colorscale.makeColorScaleFunc(\n        {domain: domain, range: range},\n        {noNumericCheck: true}\n    );\n};\n\n},{\"../../components/colorscale\":605,\"./end_plus\":953,\"d3\":163}],959:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar constants = _dereq_('./constants');\n\n// Calculate all the marching indices, for ALL levels at once.\n// since we want to be exhaustive we'll check for contour crossings\n// at every intersection, rather than just following a path\n// TODO: shorten the inner loop to only the relevant levels\nmodule.exports = function makeCrossings(pathinfo) {\n    var z = pathinfo[0].z;\n    var m = z.length;\n    var n = z[0].length; // we already made sure z isn't ragged in interp2d\n    var twoWide = m === 2 || n === 2;\n    var xi;\n    var yi;\n    var startIndices;\n    var ystartIndices;\n    var label;\n    var corners;\n    var mi;\n    var pi;\n    var i;\n\n    for(yi = 0; yi < m - 1; yi++) {\n        ystartIndices = [];\n        if(yi === 0) ystartIndices = ystartIndices.concat(constants.BOTTOMSTART);\n        if(yi === m - 2) ystartIndices = ystartIndices.concat(constants.TOPSTART);\n\n        for(xi = 0; xi < n - 1; xi++) {\n            startIndices = ystartIndices.slice();\n            if(xi === 0) startIndices = startIndices.concat(constants.LEFTSTART);\n            if(xi === n - 2) startIndices = startIndices.concat(constants.RIGHTSTART);\n\n            label = xi + ',' + yi;\n            corners = [[z[yi][xi], z[yi][xi + 1]],\n                       [z[yi + 1][xi], z[yi + 1][xi + 1]]];\n            for(i = 0; i < pathinfo.length; i++) {\n                pi = pathinfo[i];\n                mi = getMarchingIndex(pi.level, corners);\n                if(!mi) continue;\n\n                pi.crossings[label] = mi;\n                if(startIndices.indexOf(mi) !== -1) {\n                    pi.starts.push([xi, yi]);\n                    if(twoWide && startIndices.indexOf(mi,\n                            startIndices.indexOf(mi) + 1) !== -1) {\n                        // the same square has starts from opposite sides\n                        // it's not possible to have starts on opposite edges\n                        // of a corner, only a start and an end...\n                        // but if the array is only two points wide (either way)\n                        // you can have starts on opposite sides.\n                        pi.starts.push([xi, yi]);\n                    }\n                }\n            }\n        }\n    }\n};\n\n// modified marching squares algorithm,\n// so we disambiguate the saddle points from the start\n// and we ignore the cases with no crossings\n// the index I'm using is based on:\n// http://en.wikipedia.org/wiki/Marching_squares\n// except that the saddles bifurcate and I represent them\n// as the decimal combination of the two appropriate\n// non-saddle indices\nfunction getMarchingIndex(val, corners) {\n    var mi = (corners[0][0] > val ? 0 : 1) +\n             (corners[0][1] > val ? 0 : 2) +\n             (corners[1][1] > val ? 0 : 4) +\n             (corners[1][0] > val ? 0 : 8);\n    if(mi === 5 || mi === 10) {\n        var avg = (corners[0][0] + corners[0][1] +\n                   corners[1][0] + corners[1][1]) / 4;\n        // two peaks with a big valley\n        if(val > avg) return (mi === 5) ? 713 : 1114;\n        // two valleys with a big ridge\n        return (mi === 5) ? 104 : 208;\n    }\n    return (mi === 15) ? 0 : mi;\n}\n\n},{\"./constants\":946}],960:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../../components/drawing');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar setConvert = _dereq_('../../plots/cartesian/set_convert');\n\nvar heatmapPlot = _dereq_('../heatmap/plot');\nvar makeCrossings = _dereq_('./make_crossings');\nvar findAllPaths = _dereq_('./find_all_paths');\nvar emptyPathinfo = _dereq_('./empty_pathinfo');\nvar convertToConstraints = _dereq_('./convert_to_constraints');\nvar closeBoundaries = _dereq_('./close_boundaries');\nvar constants = _dereq_('./constants');\nvar costConstants = constants.LABELOPTIMIZER;\n\nexports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    Lib.makeTraceGroups(contourLayer, cdcontours, 'contour').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n        var x = cd0.x;\n        var y = cd0.y;\n        var contours = trace.contours;\n        var pathinfo = emptyPathinfo(contours, plotinfo, cd0);\n\n        // use a heatmap to fill - draw it behind the lines\n        var heatmapColoringLayer = Lib.ensureSingle(plotGroup, 'g', 'heatmapcoloring');\n        var cdheatmaps = [];\n        if(contours.coloring === 'heatmap') {\n            cdheatmaps = [cd];\n        }\n        heatmapPlot(gd, plotinfo, cdheatmaps, heatmapColoringLayer);\n\n        makeCrossings(pathinfo);\n        findAllPaths(pathinfo);\n\n        var leftedge = xa.c2p(x[0], true);\n        var rightedge = xa.c2p(x[x.length - 1], true);\n        var bottomedge = ya.c2p(y[0], true);\n        var topedge = ya.c2p(y[y.length - 1], true);\n        var perimeter = [\n            [leftedge, topedge],\n            [rightedge, topedge],\n            [rightedge, bottomedge],\n            [leftedge, bottomedge]\n        ];\n\n        var fillPathinfo = pathinfo;\n        if(contours.type === 'constraint') {\n            fillPathinfo = convertToConstraints(pathinfo, contours._operation);\n            closeBoundaries(fillPathinfo, contours._operation, perimeter, trace);\n        }\n\n        // draw everything\n        makeBackground(plotGroup, perimeter, contours);\n        makeFills(plotGroup, fillPathinfo, perimeter, contours);\n        makeLinesAndLabels(plotGroup, pathinfo, gd, cd0, contours);\n        clipGaps(plotGroup, plotinfo, gd, cd0, perimeter);\n    });\n};\n\nfunction makeBackground(plotgroup, perimeter, contours) {\n    var bggroup = Lib.ensureSingle(plotgroup, 'g', 'contourbg');\n\n    var bgfill = bggroup.selectAll('path')\n        .data(contours.coloring === 'fill' ? [0] : []);\n    bgfill.enter().append('path');\n    bgfill.exit().remove();\n    bgfill\n        .attr('d', 'M' + perimeter.join('L') + 'Z')\n        .style('stroke', 'none');\n}\n\nfunction makeFills(plotgroup, pathinfo, perimeter, contours) {\n    var fillgroup = Lib.ensureSingle(plotgroup, 'g', 'contourfill');\n\n    var fillitems = fillgroup.selectAll('path')\n        .data(contours.coloring === 'fill' || (contours.type === 'constraint' && contours._operation !== '=') ? pathinfo : []);\n    fillitems.enter().append('path');\n    fillitems.exit().remove();\n    fillitems.each(function(pi) {\n        // join all paths for this level together into a single path\n        // first follow clockwise around the perimeter to close any open paths\n        // if the whole perimeter is above this level, start with a path\n        // enclosing the whole thing. With all that, the parity should mean\n        // that we always fill everything above the contour, nothing below\n        var fullpath = joinAllPaths(pi, perimeter);\n\n        if(!fullpath) d3.select(this).remove();\n        else d3.select(this).attr('d', fullpath).style('stroke', 'none');\n    });\n}\n\nfunction initFullPath(pi, perimeter) {\n    var prefixBoundary = pi.prefixBoundary;\n    if(prefixBoundary === undefined) {\n        var edgeVal2 = Math.min(pi.z[0][0], pi.z[0][1]);\n        prefixBoundary = (!pi.edgepaths.length && edgeVal2 > pi.level);\n    }\n\n    if(prefixBoundary) {\n        // TODO: why does ^^ not work for constraints?\n        // pi.prefixBoundary gets set by closeBoundaries\n        return 'M' + perimeter.join('L') + 'Z';\n    }\n    return '';\n}\n\nfunction joinAllPaths(pi, perimeter) {\n    var fullpath = initFullPath(pi, perimeter);\n    var i = 0;\n    var startsleft = pi.edgepaths.map(function(v, i) { return i; });\n    var newloop = true;\n    var endpt;\n    var newendpt;\n    var cnt;\n    var nexti;\n    var possiblei;\n    var addpath;\n\n    function istop(pt) { return Math.abs(pt[1] - perimeter[0][1]) < 0.01; }\n    function isbottom(pt) { return Math.abs(pt[1] - perimeter[2][1]) < 0.01; }\n    function isleft(pt) { return Math.abs(pt[0] - perimeter[0][0]) < 0.01; }\n    function isright(pt) { return Math.abs(pt[0] - perimeter[2][0]) < 0.01; }\n\n    while(startsleft.length) {\n        addpath = Drawing.smoothopen(pi.edgepaths[i], pi.smoothing);\n        fullpath += newloop ? addpath : addpath.replace(/^M/, 'L');\n        startsleft.splice(startsleft.indexOf(i), 1);\n        endpt = pi.edgepaths[i][pi.edgepaths[i].length - 1];\n        nexti = -1;\n\n        // now loop through sides, moving our endpoint until we find a new start\n        for(cnt = 0; cnt < 4; cnt++) { // just to prevent infinite loops\n            if(!endpt) {\n                Lib.log('Missing end?', i, pi);\n                break;\n            }\n\n            if(istop(endpt) && !isright(endpt)) newendpt = perimeter[1]; // right top\n            else if(isleft(endpt)) newendpt = perimeter[0]; // left top\n            else if(isbottom(endpt)) newendpt = perimeter[3]; // right bottom\n            else if(isright(endpt)) newendpt = perimeter[2]; // left bottom\n\n            for(possiblei = 0; possiblei < pi.edgepaths.length; possiblei++) {\n                var ptNew = pi.edgepaths[possiblei][0];\n                // is ptNew on the (horz. or vert.) segment from endpt to newendpt?\n                if(Math.abs(endpt[0] - newendpt[0]) < 0.01) {\n                    if(Math.abs(endpt[0] - ptNew[0]) < 0.01 &&\n                            (ptNew[1] - endpt[1]) * (newendpt[1] - ptNew[1]) >= 0) {\n                        newendpt = ptNew;\n                        nexti = possiblei;\n                    }\n                } else if(Math.abs(endpt[1] - newendpt[1]) < 0.01) {\n                    if(Math.abs(endpt[1] - ptNew[1]) < 0.01 &&\n                            (ptNew[0] - endpt[0]) * (newendpt[0] - ptNew[0]) >= 0) {\n                        newendpt = ptNew;\n                        nexti = possiblei;\n                    }\n                } else {\n                    Lib.log('endpt to newendpt is not vert. or horz.',\n                        endpt, newendpt, ptNew);\n                }\n            }\n\n            endpt = newendpt;\n\n            if(nexti >= 0) break;\n            fullpath += 'L' + newendpt;\n        }\n\n        if(nexti === pi.edgepaths.length) {\n            Lib.log('unclosed perimeter path');\n            break;\n        }\n\n        i = nexti;\n\n        // if we closed back on a loop we already included,\n        // close it and start a new loop\n        newloop = (startsleft.indexOf(i) === -1);\n        if(newloop) {\n            i = startsleft[0];\n            fullpath += 'Z';\n        }\n    }\n\n    // finally add the interior paths\n    for(i = 0; i < pi.paths.length; i++) {\n        fullpath += Drawing.smoothclosed(pi.paths[i], pi.smoothing);\n    }\n\n    return fullpath;\n}\n\nfunction makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours) {\n    var lineContainer = Lib.ensureSingle(plotgroup, 'g', 'contourlines');\n    var showLines = contours.showlines !== false;\n    var showLabels = contours.showlabels;\n    var clipLinesForLabels = showLines && showLabels;\n\n    // Even if we're not going to show lines, we need to create them\n    // if we're showing labels, because the fill paths include the perimeter\n    // so can't be used to position the labels correctly.\n    // In this case we'll remove the lines after making the labels.\n    var linegroup = exports.createLines(lineContainer, showLines || showLabels, pathinfo);\n\n    var lineClip = exports.createLineClip(lineContainer, clipLinesForLabels, gd, cd0.trace.uid);\n\n    var labelGroup = plotgroup.selectAll('g.contourlabels')\n        .data(showLabels ? [0] : []);\n\n    labelGroup.exit().remove();\n\n    labelGroup.enter().append('g')\n        .classed('contourlabels', true);\n\n    if(showLabels) {\n        var labelClipPathData = [];\n        var labelData = [];\n\n        // invalidate the getTextLocation cache in case paths changed\n        Lib.clearLocationCache();\n\n        var contourFormat = exports.labelFormatter(contours, cd0.t.cb, gd._fullLayout);\n\n        var dummyText = Drawing.tester.append('text')\n            .attr('data-notex', 1)\n            .call(Drawing.font, contours.labelfont);\n\n        var xa = pathinfo[0].xaxis;\n        var ya = pathinfo[0].yaxis;\n        var xLen = xa._length;\n        var yLen = ya._length;\n        var xRng = xa.range;\n        var yRng = ya.range;\n        var xMin = Lib.aggNums(Math.min, null, cd0.x);\n        var xMax = Lib.aggNums(Math.max, null, cd0.x);\n        var yMin = Lib.aggNums(Math.min, null, cd0.y);\n        var yMax = Lib.aggNums(Math.max, null, cd0.y);\n        var x0 = Math.max(xa.c2p(xMin, true), 0);\n        var x1 = Math.min(xa.c2p(xMax, true), xLen);\n        var y0 = Math.max(ya.c2p(yMax, true), 0);\n        var y1 = Math.min(ya.c2p(yMin, true), yLen);\n\n        // visible bounds of the contour trace (and the midpoints, to\n        // help with cost calculations)\n        var bounds = {};\n\n        if(xRng[0] < xRng[1]) {\n            bounds.left = x0;\n            bounds.right = x1;\n        } else {\n            bounds.left = x1;\n            bounds.right = x0;\n        }\n\n        if(yRng[0] < yRng[1]) {\n            bounds.top = y0;\n            bounds.bottom = y1;\n        } else {\n            bounds.top = y1;\n            bounds.bottom = y0;\n        }\n\n        bounds.middle = (bounds.top + bounds.bottom) / 2;\n        bounds.center = (bounds.left + bounds.right) / 2;\n\n        labelClipPathData.push([\n            [bounds.left, bounds.top],\n            [bounds.right, bounds.top],\n            [bounds.right, bounds.bottom],\n            [bounds.left, bounds.bottom]\n        ]);\n\n        var plotDiagonal = Math.sqrt(xLen * xLen + yLen * yLen);\n\n        // the path length to use to scale the number of labels to draw:\n        var normLength = constants.LABELDISTANCE * plotDiagonal /\n            Math.max(1, pathinfo.length / constants.LABELINCREASE);\n\n        linegroup.each(function(d) {\n            var textOpts = exports.calcTextOpts(d.level, contourFormat, dummyText, gd);\n\n            d3.select(this).selectAll('path').each(function() {\n                var path = this;\n                var pathBounds = Lib.getVisibleSegment(path, bounds, textOpts.height / 2);\n                if(!pathBounds) return;\n\n                if(pathBounds.len < (textOpts.width + textOpts.height) * constants.LABELMIN) return;\n\n                var maxLabels = Math.min(Math.ceil(pathBounds.len / normLength),\n                    constants.LABELMAX);\n\n                for(var i = 0; i < maxLabels; i++) {\n                    var loc = exports.findBestTextLocation(path, pathBounds, textOpts,\n                        labelData, bounds);\n\n                    if(!loc) break;\n\n                    exports.addLabelData(loc, textOpts, labelData, labelClipPathData);\n                }\n            });\n        });\n\n        dummyText.remove();\n\n        exports.drawLabels(labelGroup, labelData, gd, lineClip,\n            clipLinesForLabels ? labelClipPathData : null);\n    }\n\n    if(showLabels && !showLines) linegroup.remove();\n}\n\nexports.createLines = function(lineContainer, makeLines, pathinfo) {\n    var smoothing = pathinfo[0].smoothing;\n\n    var linegroup = lineContainer.selectAll('g.contourlevel')\n        .data(makeLines ? pathinfo : []);\n\n    linegroup.exit().remove();\n    linegroup.enter().append('g')\n        .classed('contourlevel', true);\n\n    if(makeLines) {\n        // pedgepaths / ppaths are used by contourcarpet, for the paths transformed from a/b to x/y\n        // edgepaths / paths are used by contour since it's in x/y from the start\n        var opencontourlines = linegroup.selectAll('path.openline')\n            .data(function(d) { return d.pedgepaths || d.edgepaths; });\n\n        opencontourlines.exit().remove();\n        opencontourlines.enter().append('path')\n            .classed('openline', true);\n\n        opencontourlines\n            .attr('d', function(d) {\n                return Drawing.smoothopen(d, smoothing);\n            })\n            .style('stroke-miterlimit', 1)\n            .style('vector-effect', 'non-scaling-stroke');\n\n        var closedcontourlines = linegroup.selectAll('path.closedline')\n            .data(function(d) { return d.ppaths || d.paths; });\n\n        closedcontourlines.exit().remove();\n        closedcontourlines.enter().append('path')\n            .classed('closedline', true);\n\n        closedcontourlines\n            .attr('d', function(d) {\n                return Drawing.smoothclosed(d, smoothing);\n            })\n            .style('stroke-miterlimit', 1)\n            .style('vector-effect', 'non-scaling-stroke');\n    }\n\n    return linegroup;\n};\n\nexports.createLineClip = function(lineContainer, clipLinesForLabels, gd, uid) {\n    var clips = gd._fullLayout._clips;\n    var clipId = clipLinesForLabels ? ('clipline' + uid) : null;\n\n    var lineClip = clips.selectAll('#' + clipId)\n        .data(clipLinesForLabels ? [0] : []);\n    lineClip.exit().remove();\n\n    lineClip.enter().append('clipPath')\n        .classed('contourlineclip', true)\n        .attr('id', clipId);\n\n    Drawing.setClipUrl(lineContainer, clipId, gd);\n\n    return lineClip;\n};\n\nexports.labelFormatter = function(contours, colorbar, fullLayout) {\n    if(contours.labelformat) {\n        return fullLayout._d3locale.numberFormat(contours.labelformat);\n    } else {\n        var formatAxis;\n        if(colorbar) {\n            formatAxis = colorbar.axis;\n        } else {\n            formatAxis = {\n                type: 'linear',\n                _id: 'ycontour',\n                showexponent: 'all',\n                exponentformat: 'B'\n            };\n\n            if(contours.type === 'constraint') {\n                var value = contours.value;\n                if(Array.isArray(value)) {\n                    formatAxis.range = [value[0], value[value.length - 1]];\n                } else formatAxis.range = [value, value];\n            } else {\n                formatAxis.range = [contours.start, contours.end];\n                formatAxis.nticks = (contours.end - contours.start) / contours.size;\n            }\n\n            if(formatAxis.range[0] === formatAxis.range[1]) {\n                formatAxis.range[1] += formatAxis.range[0] || 1;\n            }\n            if(!formatAxis.nticks) formatAxis.nticks = 1000;\n\n            setConvert(formatAxis, fullLayout);\n            Axes.prepTicks(formatAxis);\n            formatAxis._tmin = null;\n            formatAxis._tmax = null;\n        }\n        return function(v) {\n            return Axes.tickText(formatAxis, v).text;\n        };\n    }\n};\n\nexports.calcTextOpts = function(level, contourFormat, dummyText, gd) {\n    var text = contourFormat(level);\n    dummyText.text(text)\n        .call(svgTextUtils.convertToTspans, gd);\n    var bBox = Drawing.bBox(dummyText.node(), true);\n\n    return {\n        text: text,\n        width: bBox.width,\n        height: bBox.height,\n        level: level,\n        dy: (bBox.top + bBox.bottom) / 2\n    };\n};\n\nexports.findBestTextLocation = function(path, pathBounds, textOpts, labelData, plotBounds) {\n    var textWidth = textOpts.width;\n\n    var p0, dp, pMax, pMin, loc;\n    if(pathBounds.isClosed) {\n        dp = pathBounds.len / costConstants.INITIALSEARCHPOINTS;\n        p0 = pathBounds.min + dp / 2;\n        pMax = pathBounds.max;\n    } else {\n        dp = (pathBounds.len - textWidth) / (costConstants.INITIALSEARCHPOINTS + 1);\n        p0 = pathBounds.min + dp + textWidth / 2;\n        pMax = pathBounds.max - (dp + textWidth) / 2;\n    }\n\n    var cost = Infinity;\n    for(var j = 0; j < costConstants.ITERATIONS; j++) {\n        for(var p = p0; p < pMax; p += dp) {\n            var newLocation = Lib.getTextLocation(path, pathBounds.total, p, textWidth);\n            var newCost = locationCost(newLocation, textOpts, labelData, plotBounds);\n            if(newCost < cost) {\n                cost = newCost;\n                loc = newLocation;\n                pMin = p;\n            }\n        }\n        if(cost > costConstants.MAXCOST * 2) break;\n\n        // subsequent iterations just look half steps away from the\n        // best we found in the previous iteration\n        if(j) dp /= 2;\n        p0 = pMin - dp / 2;\n        pMax = p0 + dp * 1.5;\n    }\n    if(cost <= costConstants.MAXCOST) return loc;\n};\n\n/*\n * locationCost: a cost function for label locations\n * composed of three kinds of penalty:\n * - for open paths, being close to the end of the path\n * - the angle away from horizontal\n * - being too close to already placed neighbors\n */\nfunction locationCost(loc, textOpts, labelData, bounds) {\n    var halfWidth = textOpts.width / 2;\n    var halfHeight = textOpts.height / 2;\n    var x = loc.x;\n    var y = loc.y;\n    var theta = loc.theta;\n    var dx = Math.cos(theta) * halfWidth;\n    var dy = Math.sin(theta) * halfWidth;\n\n    // cost for being near an edge\n    var normX = ((x > bounds.center) ? (bounds.right - x) : (x - bounds.left)) /\n        (dx + Math.abs(Math.sin(theta) * halfHeight));\n    var normY = ((y > bounds.middle) ? (bounds.bottom - y) : (y - bounds.top)) /\n        (Math.abs(dy) + Math.cos(theta) * halfHeight);\n    if(normX < 1 || normY < 1) return Infinity;\n    var cost = costConstants.EDGECOST * (1 / (normX - 1) + 1 / (normY - 1));\n\n    // cost for not being horizontal\n    cost += costConstants.ANGLECOST * theta * theta;\n\n    // cost for being close to other labels\n    var x1 = x - dx;\n    var y1 = y - dy;\n    var x2 = x + dx;\n    var y2 = y + dy;\n    for(var i = 0; i < labelData.length; i++) {\n        var labeli = labelData[i];\n        var dxd = Math.cos(labeli.theta) * labeli.width / 2;\n        var dyd = Math.sin(labeli.theta) * labeli.width / 2;\n        var dist = Lib.segmentDistance(\n            x1, y1,\n            x2, y2,\n            labeli.x - dxd, labeli.y - dyd,\n            labeli.x + dxd, labeli.y + dyd\n        ) * 2 / (textOpts.height + labeli.height);\n\n        var sameLevel = labeli.level === textOpts.level;\n        var distOffset = sameLevel ? costConstants.SAMELEVELDISTANCE : 1;\n\n        if(dist <= distOffset) return Infinity;\n\n        var distFactor = costConstants.NEIGHBORCOST *\n            (sameLevel ? costConstants.SAMELEVELFACTOR : 1);\n\n        cost += distFactor / (dist - distOffset);\n    }\n\n    return cost;\n}\n\nexports.addLabelData = function(loc, textOpts, labelData, labelClipPathData) {\n    var halfWidth = textOpts.width / 2;\n    var halfHeight = textOpts.height / 2;\n\n    var x = loc.x;\n    var y = loc.y;\n    var theta = loc.theta;\n\n    var sin = Math.sin(theta);\n    var cos = Math.cos(theta);\n    var dxw = halfWidth * cos;\n    var dxh = halfHeight * sin;\n    var dyw = halfWidth * sin;\n    var dyh = -halfHeight * cos;\n    var bBoxPts = [\n        [x - dxw - dxh, y - dyw - dyh],\n        [x + dxw - dxh, y + dyw - dyh],\n        [x + dxw + dxh, y + dyw + dyh],\n        [x - dxw + dxh, y - dyw + dyh],\n    ];\n\n    labelData.push({\n        text: textOpts.text,\n        x: x,\n        y: y,\n        dy: textOpts.dy,\n        theta: theta,\n        level: textOpts.level,\n        width: textOpts.width,\n        height: textOpts.height\n    });\n\n    labelClipPathData.push(bBoxPts);\n};\n\nexports.drawLabels = function(labelGroup, labelData, gd, lineClip, labelClipPathData) {\n    var labels = labelGroup.selectAll('text')\n        .data(labelData, function(d) {\n            return d.text + ',' + d.x + ',' + d.y + ',' + d.theta;\n        });\n\n    labels.exit().remove();\n\n    labels.enter().append('text')\n        .attr({\n            'data-notex': 1,\n            'text-anchor': 'middle'\n        })\n        .each(function(d) {\n            var x = d.x + Math.sin(d.theta) * d.dy;\n            var y = d.y - Math.cos(d.theta) * d.dy;\n            d3.select(this)\n                .text(d.text)\n                .attr({\n                    x: x,\n                    y: y,\n                    transform: 'rotate(' + (180 * d.theta / Math.PI) + ' ' + x + ' ' + y + ')'\n                })\n                .call(svgTextUtils.convertToTspans, gd);\n        });\n\n    if(labelClipPathData) {\n        var clipPath = '';\n        for(var i = 0; i < labelClipPathData.length; i++) {\n            clipPath += 'M' + labelClipPathData[i].join('L') + 'Z';\n        }\n\n        var lineClipPath = Lib.ensureSingle(lineClip, 'path', '');\n        lineClipPath.attr('d', clipPath);\n    }\n};\n\nfunction clipGaps(plotGroup, plotinfo, gd, cd0, perimeter) {\n    var clips = gd._fullLayout._clips;\n    var clipId = 'clip' + cd0.trace.uid;\n\n    var clipPath = clips.selectAll('#' + clipId)\n        .data(cd0.trace.connectgaps ? [] : [0]);\n    clipPath.enter().append('clipPath')\n        .classed('contourclip', true)\n        .attr('id', clipId);\n    clipPath.exit().remove();\n\n    if(cd0.trace.connectgaps === false) {\n        var clipPathInfo = {\n            // fraction of the way from missing to present point\n            // to draw the boundary.\n            // if you make this 1 (or 1-epsilon) then a point in\n            // a sea of missing data will disappear entirely.\n            level: 0.9,\n            crossings: {},\n            starts: [],\n            edgepaths: [],\n            paths: [],\n            xaxis: plotinfo.xaxis,\n            yaxis: plotinfo.yaxis,\n            x: cd0.x,\n            y: cd0.y,\n            // 0 = no data, 1 = data\n            z: makeClipMask(cd0),\n            smoothing: 0\n        };\n\n        makeCrossings([clipPathInfo]);\n        findAllPaths([clipPathInfo]);\n        var fullpath = joinAllPaths(clipPathInfo, perimeter);\n\n        var path = Lib.ensureSingle(clipPath, 'path', '');\n        path.attr('d', fullpath);\n    } else clipId = null;\n\n    Drawing.setClipUrl(plotGroup, clipId, gd);\n}\n\nfunction makeClipMask(cd0) {\n    var empties = cd0.trace._emptypoints;\n    var z = [];\n    var m = cd0.z.length;\n    var n = cd0.z[0].length;\n    var i;\n    var row = [];\n    var emptyPoint;\n\n    for(i = 0; i < n; i++) row.push(1);\n    for(i = 0; i < m; i++) z.push(row.slice());\n    for(i = 0; i < empties.length; i++) {\n        emptyPoint = empties[i];\n        z[emptyPoint[0]][emptyPoint[1]] = 0;\n    }\n    // save this mask to determine whether to show this data in hover\n    cd0.zmask = z;\n    return z;\n}\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plots/cartesian/axes\":767,\"../../plots/cartesian/set_convert\":785,\"../heatmap/plot\":1012,\"./close_boundaries\":944,\"./constants\":946,\"./convert_to_constraints\":950,\"./empty_pathinfo\":952,\"./find_all_paths\":954,\"./make_crossings\":959,\"d3\":163}],961:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function setContours(trace, vals) {\n    var contours = trace.contours;\n\n    // check if we need to auto-choose contour levels\n    if(trace.autocontour) {\n        // N.B. do not try to use coloraxis cmin/cmax,\n        // these values here are meant to remain \"per-trace\" for now\n        var zmin = trace.zmin;\n        var zmax = trace.zmax;\n        if(trace.zauto || zmin === undefined) {\n            zmin = Lib.aggNums(Math.min, null, vals);\n        }\n        if(trace.zauto || zmax === undefined) {\n            zmax = Lib.aggNums(Math.max, null, vals);\n        }\n\n        var dummyAx = autoContours(zmin, zmax, trace.ncontours);\n        contours.size = dummyAx.dtick;\n        contours.start = Axes.tickFirst(dummyAx);\n        dummyAx.range.reverse();\n        contours.end = Axes.tickFirst(dummyAx);\n\n        if(contours.start === zmin) contours.start += contours.size;\n        if(contours.end === zmax) contours.end -= contours.size;\n\n        // if you set a small ncontours, *and* the ends are exactly on zmin/zmax\n        // there's an edge case where start > end now. Make sure there's at least\n        // one meaningful contour, put it midway between the crossed values\n        if(contours.start > contours.end) {\n            contours.start = contours.end = (contours.start + contours.end) / 2;\n        }\n\n        // copy auto-contour info back to the source data.\n        // previously we copied the whole contours object back, but that had\n        // other info (coloring, showlines) that should be left to supplyDefaults\n        if(!trace._input.contours) trace._input.contours = {};\n        Lib.extendFlat(trace._input.contours, {\n            start: contours.start,\n            end: contours.end,\n            size: contours.size\n        });\n        trace._input.autocontour = true;\n    } else if(contours.type !== 'constraint') {\n        // sanity checks on manually-supplied start/end/size\n        var start = contours.start;\n        var end = contours.end;\n        var inputContours = trace._input.contours;\n\n        if(start > end) {\n            contours.start = inputContours.start = end;\n            end = contours.end = inputContours.end = start;\n            start = contours.start;\n        }\n\n        if(!(contours.size > 0)) {\n            var sizeOut;\n            if(start === end) sizeOut = 1;\n            else sizeOut = autoContours(start, end, trace.ncontours).dtick;\n\n            inputContours.size = contours.size = sizeOut;\n        }\n    }\n};\n\n\n/*\n * autoContours: make a dummy axis object with dtick we can use\n * as contours.size, and if needed we can use Axes.tickFirst\n * with this axis object to calculate the start and end too\n *\n * start: the value to start the contours at\n * end: the value to end at (must be > start)\n * ncontours: max number of contours to make, like roughDTick\n *\n * returns: an axis object\n */\nfunction autoContours(start, end, ncontours) {\n    var dummyAx = {\n        type: 'linear',\n        range: [start, end]\n    };\n\n    Axes.autoTicks(\n        dummyAx,\n        (end - start) / (ncontours || 15)\n    );\n\n    return dummyAx;\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767}],962:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Drawing = _dereq_('../../components/drawing');\nvar heatmapStyle = _dereq_('../heatmap/style');\n\nvar makeColorMap = _dereq_('./make_color_map');\n\n\nmodule.exports = function style(gd) {\n    var contours = d3.select(gd).selectAll('g.contour');\n\n    contours.style('opacity', function(d) {\n        return d[0].trace.opacity;\n    });\n\n    contours.each(function(d) {\n        var c = d3.select(this);\n        var trace = d[0].trace;\n        var contours = trace.contours;\n        var line = trace.line;\n        var cs = contours.size || 1;\n        var start = contours.start;\n\n        // for contourcarpet only - is this a constraint-type contour trace?\n        var isConstraintType = contours.type === 'constraint';\n        var colorLines = !isConstraintType && contours.coloring === 'lines';\n        var colorFills = !isConstraintType && contours.coloring === 'fill';\n\n        var colorMap = (colorLines || colorFills) ? makeColorMap(trace) : null;\n\n        c.selectAll('g.contourlevel').each(function(d) {\n            d3.select(this).selectAll('path')\n                .call(Drawing.lineGroupStyle,\n                    line.width,\n                    colorLines ? colorMap(d.level) : line.color,\n                    line.dash);\n        });\n\n        var labelFont = contours.labelfont;\n        c.selectAll('g.contourlabels text').each(function(d) {\n            Drawing.font(d3.select(this), {\n                family: labelFont.family,\n                size: labelFont.size,\n                color: labelFont.color || (colorLines ? colorMap(d.level) : line.color)\n            });\n        });\n\n        if(isConstraintType) {\n            c.selectAll('g.contourfill path')\n                .style('fill', trace.fillcolor);\n        } else if(colorFills) {\n            var firstFill;\n\n            c.selectAll('g.contourfill path')\n                .style('fill', function(d) {\n                    if(firstFill === undefined) firstFill = d.level;\n                    return colorMap(d.level + 0.5 * cs);\n                });\n\n            if(firstFill === undefined) firstFill = start;\n\n            c.selectAll('g.contourbg path')\n                .style('fill', colorMap(firstFill - 0.5 * cs));\n        }\n    });\n\n    heatmapStyle(gd);\n};\n\n},{\"../../components/drawing\":614,\"../heatmap/style\":1013,\"./make_color_map\":958,\"d3\":163}],963:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar handleLabelDefaults = _dereq_('./label_defaults');\n\n\nmodule.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {\n    var coloring = coerce('contours.coloring');\n\n    var showLines;\n    var lineColor = '';\n    if(coloring === 'fill') showLines = coerce('contours.showlines');\n\n    if(showLines !== false) {\n        if(coloring !== 'lines') lineColor = coerce('line.color', '#000');\n        coerce('line.width', 0.5);\n        coerce('line.dash');\n    }\n\n    if(coloring !== 'none') {\n        // plots/plots always coerces showlegend to true, but in this case\n        // we default to false and (by default) show a colorbar instead\n        if(traceIn.showlegend !== true) traceOut.showlegend = false;\n        traceOut._dfltShowLegend = false;\n\n        colorscaleDefaults(\n            traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}\n        );\n    }\n\n    coerce('line.smoothing');\n\n    handleLabelDefaults(coerce, layout, lineColor, opts);\n};\n\n},{\"../../components/colorscale/defaults\":603,\"./label_defaults\":957}],964:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar heatmapAttrs = _dereq_('../heatmap/attributes');\nvar contourAttrs = _dereq_('../contour/attributes');\nvar contourContourAttrs = contourAttrs.contours;\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar scatterLineAttrs = scatterAttrs.line;\n\nmodule.exports = extendFlat({\n    carpet: {\n        valType: 'string',\n        \n        editType: 'calc',\n        \n    },\n    z: heatmapAttrs.z,\n    a: heatmapAttrs.x,\n    a0: heatmapAttrs.x0,\n    da: heatmapAttrs.dx,\n    b: heatmapAttrs.y,\n    b0: heatmapAttrs.y0,\n    db: heatmapAttrs.dy,\n    text: heatmapAttrs.text,\n    hovertext: heatmapAttrs.hovertext,\n    transpose: heatmapAttrs.transpose,\n    atype: heatmapAttrs.xtype,\n    btype: heatmapAttrs.ytype,\n\n    fillcolor: contourAttrs.fillcolor,\n\n    autocontour: contourAttrs.autocontour,\n    ncontours: contourAttrs.ncontours,\n\n    contours: {\n        type: contourContourAttrs.type,\n        start: contourContourAttrs.start,\n        end: contourContourAttrs.end,\n        size: contourContourAttrs.size,\n        coloring: {\n            // from contourAttrs.contours.coloring but no 'heatmap' option\n            valType: 'enumerated',\n            values: ['fill', 'lines', 'none'],\n            dflt: 'fill',\n            \n            editType: 'calc',\n            \n        },\n        showlines: contourContourAttrs.showlines,\n        showlabels: contourContourAttrs.showlabels,\n        labelfont: contourContourAttrs.labelfont,\n        labelformat: contourContourAttrs.labelformat,\n        operation: contourContourAttrs.operation,\n        value: contourContourAttrs.value,\n        editType: 'calc',\n        impliedEdits: {'autocontour': false}\n    },\n\n    line: {\n        color: extendFlat({}, scatterLineAttrs.color, {\n            \n        }),\n        width: scatterLineAttrs.width,\n        dash: scatterLineAttrs.dash,\n        smoothing: extendFlat({}, scatterLineAttrs.smoothing, {\n            \n        }),\n        editType: 'plot'\n    },\n    transforms: undefined\n},\n\n    colorScaleAttrs('', {\n        cLetter: 'z',\n        autoColorDflt: false\n    })\n);\n\n},{\"../../components/colorscale/attributes\":600,\"../../lib/extend\":710,\"../contour/attributes\":942,\"../heatmap/attributes\":1001,\"../scatter/attributes\":1112}],965:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\nvar Lib = _dereq_('../../lib');\n\nvar convertColumnData = _dereq_('../heatmap/convert_column_xyz');\nvar clean2dArray = _dereq_('../heatmap/clean_2d_array');\nvar interp2d = _dereq_('../heatmap/interp2d');\nvar findEmpties = _dereq_('../heatmap/find_empties');\nvar makeBoundArray = _dereq_('../heatmap/make_bound_array');\nvar supplyDefaults = _dereq_('./defaults');\nvar lookupCarpet = _dereq_('../carpet/lookup_carpetid');\nvar setContours = _dereq_('../contour/set_contours');\n\n// most is the same as heatmap calc, then adjust it\n// though a few things inside heatmap calc still look for\n// contour maps, because the makeBoundArray calls are too entangled\nmodule.exports = function calc(gd, trace) {\n    var carpet = trace._carpetTrace = lookupCarpet(gd, trace);\n    if(!carpet || !carpet.visible || carpet.visible === 'legendonly') return;\n\n    if(!trace.a || !trace.b) {\n        // Look up the original incoming carpet data:\n        var carpetdata = gd.data[carpet.index];\n\n        // Look up the incoming trace data, *except* perform a shallow\n        // copy so that we're not actually modifying it when we use it\n        // to supply defaults:\n        var tracedata = gd.data[trace.index];\n        // var tracedata = extendFlat({}, gd.data[trace.index]);\n\n        // If the data is not specified\n        if(!tracedata.a) tracedata.a = carpetdata.a;\n        if(!tracedata.b) tracedata.b = carpetdata.b;\n\n        supplyDefaults(tracedata, trace, trace._defaultColor, gd._fullLayout);\n    }\n\n    var cd = heatmappishCalc(gd, trace);\n    setContours(trace, trace._z);\n\n    return cd;\n};\n\nfunction heatmappishCalc(gd, trace) {\n    // prepare the raw data\n    // run makeCalcdata on x and y even for heatmaps, in case of category mappings\n    var carpet = trace._carpetTrace;\n    var aax = carpet.aaxis;\n    var bax = carpet.baxis;\n    var a,\n        a0,\n        da,\n        b,\n        b0,\n        db,\n        z;\n\n    // cancel minimum tick spacings (only applies to bars and boxes)\n    aax._minDtick = 0;\n    bax._minDtick = 0;\n\n    if(Lib.isArray1D(trace.z)) convertColumnData(trace, aax, bax, 'a', 'b', ['z']);\n    a = trace._a = trace._a || trace.a;\n    b = trace._b = trace._b || trace.b;\n\n    a = a ? aax.makeCalcdata(trace, '_a') : [];\n    b = b ? bax.makeCalcdata(trace, '_b') : [];\n    a0 = trace.a0 || 0;\n    da = trace.da || 1;\n    b0 = trace.b0 || 0;\n    db = trace.db || 1;\n\n    z = trace._z = clean2dArray(trace._z || trace.z, trace.transpose);\n\n    trace._emptypoints = findEmpties(z);\n    interp2d(z, trace._emptypoints);\n\n    // create arrays of brick boundaries, to be used by autorange and heatmap.plot\n    var xlen = Lib.maxRowLength(z);\n    var xIn = trace.xtype === 'scaled' ? '' : a;\n    var xArray = makeBoundArray(trace, xIn, a0, da, xlen, aax);\n    var yIn = trace.ytype === 'scaled' ? '' : b;\n    var yArray = makeBoundArray(trace, yIn, b0, db, z.length, bax);\n\n    var cd0 = {\n        a: xArray,\n        b: yArray,\n        z: z,\n    };\n\n    if(trace.contours.type === 'levels' && trace.contours.coloring !== 'none') {\n        // auto-z and autocolorscale if applicable\n        colorscaleCalc(gd, trace, {\n            vals: z,\n            containerStr: '',\n            cLetter: 'z'\n        });\n    }\n\n    return [cd0];\n}\n\n},{\"../../components/colorscale/calc\":601,\"../../lib\":719,\"../carpet/lookup_carpetid\":915,\"../contour/set_contours\":961,\"../heatmap/clean_2d_array\":1003,\"../heatmap/convert_column_xyz\":1005,\"../heatmap/find_empties\":1007,\"../heatmap/interp2d\":1010,\"../heatmap/make_bound_array\":1011,\"./defaults\":966}],966:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleXYZDefaults = _dereq_('../heatmap/xyz_defaults');\nvar attributes = _dereq_('./attributes');\nvar handleConstraintDefaults = _dereq_('../contour/constraint_defaults');\nvar handleContoursDefaults = _dereq_('../contour/contours_defaults');\nvar handleStyleDefaults = _dereq_('../contour/style_defaults');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    function coerce2(attr) {\n        return Lib.coerce2(traceIn, traceOut, attributes, attr);\n    }\n\n    coerce('carpet');\n\n    // If either a or b is not present, then it's not a valid trace *unless* the carpet\n    // axis has the a or b values we're looking for. So if these are not found, just defer\n    // that decision until the calc step.\n    //\n    // NB: the calc step will modify the original data input by assigning whichever of\n    // a or b are missing. This is necessary because panning goes right from supplyDefaults\n    // to plot (skipping calc). That means on subsequent updates, this *will* need to be\n    // able to find a and b.\n    //\n    // The long-term proper fix is that this should perhaps use underscored attributes to\n    // at least modify the user input to a slightly lesser extent. Fully removing the\n    // input mutation is challenging. The underscore approach is not currently taken since\n    // it requires modification to all of the functions below that expect the coerced\n    // attribute name to match the property name -- except '_a' !== 'a' so that is not\n    // straightforward.\n    if(traceIn.a && traceIn.b) {\n        var len = handleXYZDefaults(traceIn, traceOut, coerce, layout, 'a', 'b');\n\n        if(!len) {\n            traceOut.visible = false;\n            return;\n        }\n\n        coerce('text');\n        var isConstraint = (coerce('contours.type') === 'constraint');\n\n        if(isConstraint) {\n            handleConstraintDefaults(traceIn, traceOut, coerce, layout, defaultColor, {hasHover: false});\n        } else {\n            handleContoursDefaults(traceIn, traceOut, coerce, coerce2);\n            handleStyleDefaults(traceIn, traceOut, coerce, layout, {hasHover: false});\n        }\n    } else {\n        traceOut._defaultColor = defaultColor;\n        traceOut._length = null;\n    }\n};\n\n},{\"../../lib\":719,\"../contour/constraint_defaults\":947,\"../contour/contours_defaults\":949,\"../contour/style_defaults\":963,\"../heatmap/xyz_defaults\":1015,\"./attributes\":964}],967:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../contour/colorbar'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    style: _dereq_('../contour/style'),\n\n    moduleType: 'trace',\n    name: 'contourcarpet',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', 'carpet', 'contour', 'symbols', 'showLegend', 'hasLines', 'carpetDependent'],\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../contour/colorbar\":945,\"../contour/style\":962,\"./attributes\":964,\"./calc\":965,\"./defaults\":966,\"./plot\":970}],968:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Drawing = _dereq_('../../components/drawing');\nvar axisAlignedLine = _dereq_('../carpet/axis_aligned_line');\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function joinAllPaths(trace, pi, perimeter, ab2p, carpet, carpetcd, xa, ya) {\n    var i;\n    var fullpath = '';\n\n    var startsleft = pi.edgepaths.map(function(v, i) { return i; });\n    var newloop = true;\n    var endpt, newendpt, cnt, nexti, possiblei, addpath;\n\n    var atol = Math.abs(perimeter[0][0] - perimeter[2][0]) * 1e-4;\n    var btol = Math.abs(perimeter[0][1] - perimeter[2][1]) * 1e-4;\n\n    function istop(pt) { return Math.abs(pt[1] - perimeter[0][1]) < btol; }\n    function isbottom(pt) { return Math.abs(pt[1] - perimeter[2][1]) < btol; }\n    function isleft(pt) { return Math.abs(pt[0] - perimeter[0][0]) < atol; }\n    function isright(pt) { return Math.abs(pt[0] - perimeter[2][0]) < atol; }\n\n    function pathto(pt0, pt1) {\n        var i, j, segments, axis;\n        var path = '';\n\n        if((istop(pt0) && !isright(pt0)) || (isbottom(pt0) && !isleft(pt0))) {\n            axis = carpet.aaxis;\n            segments = axisAlignedLine(carpet, carpetcd, [pt0[0], pt1[0]], 0.5 * (pt0[1] + pt1[1]));\n        } else {\n            axis = carpet.baxis;\n            segments = axisAlignedLine(carpet, carpetcd, 0.5 * (pt0[0] + pt1[0]), [pt0[1], pt1[1]]);\n        }\n\n        for(i = 1; i < segments.length; i++) {\n            path += axis.smoothing ? 'C' : 'L';\n            for(j = 0; j < segments[i].length; j++) {\n                var pt = segments[i][j];\n                path += [xa.c2p(pt[0]), ya.c2p(pt[1])] + ' ';\n            }\n        }\n\n        return path;\n    }\n\n    i = 0;\n    endpt = null;\n    while(startsleft.length) {\n        var startpt = pi.edgepaths[i][0];\n\n        if(endpt) {\n            fullpath += pathto(endpt, startpt);\n        }\n\n        addpath = Drawing.smoothopen(pi.edgepaths[i].map(ab2p), pi.smoothing);\n        fullpath += newloop ? addpath : addpath.replace(/^M/, 'L');\n        startsleft.splice(startsleft.indexOf(i), 1);\n        endpt = pi.edgepaths[i][pi.edgepaths[i].length - 1];\n        nexti = -1;\n\n        // now loop through sides, moving our endpoint until we find a new start\n        for(cnt = 0; cnt < 4; cnt++) { // just to prevent infinite loops\n            if(!endpt) {\n                Lib.log('Missing end?', i, pi);\n                break;\n            }\n\n            if(istop(endpt) && !isright(endpt)) {\n                newendpt = perimeter[1]; // left top ---> right top\n            } else if(isleft(endpt)) {\n                newendpt = perimeter[0]; // left bottom ---> left top\n            } else if(isbottom(endpt)) {\n                newendpt = perimeter[3]; // right bottom\n            } else if(isright(endpt)) {\n                newendpt = perimeter[2]; // left bottom\n            }\n\n            for(possiblei = 0; possiblei < pi.edgepaths.length; possiblei++) {\n                var ptNew = pi.edgepaths[possiblei][0];\n                // is ptNew on the (horz. or vert.) segment from endpt to newendpt?\n                if(Math.abs(endpt[0] - newendpt[0]) < atol) {\n                    if(Math.abs(endpt[0] - ptNew[0]) < atol && (ptNew[1] - endpt[1]) * (newendpt[1] - ptNew[1]) >= 0) {\n                        newendpt = ptNew;\n                        nexti = possiblei;\n                    }\n                } else if(Math.abs(endpt[1] - newendpt[1]) < btol) {\n                    if(Math.abs(endpt[1] - ptNew[1]) < btol && (ptNew[0] - endpt[0]) * (newendpt[0] - ptNew[0]) >= 0) {\n                        newendpt = ptNew;\n                        nexti = possiblei;\n                    }\n                } else {\n                    Lib.log('endpt to newendpt is not vert. or horz.', endpt, newendpt, ptNew);\n                }\n            }\n\n            if(nexti >= 0) break;\n            fullpath += pathto(endpt, newendpt);\n            endpt = newendpt;\n        }\n\n        if(nexti === pi.edgepaths.length) {\n            Lib.log('unclosed perimeter path');\n            break;\n        }\n\n        i = nexti;\n\n        // if we closed back on a loop we already included,\n        // close it and start a new loop\n        newloop = (startsleft.indexOf(i) === -1);\n        if(newloop) {\n            i = startsleft[0];\n            fullpath += pathto(endpt, newendpt) + 'Z';\n            endpt = null;\n        }\n    }\n\n    // finally add the interior paths\n    for(i = 0; i < pi.paths.length; i++) {\n        fullpath += Drawing.smoothclosed(pi.paths[i].map(ab2p), pi.smoothing);\n    }\n\n    return fullpath;\n};\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../carpet/axis_aligned_line\":899}],969:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function mapPathinfo(pathinfo, map) {\n    var i, j, k, pi, pedgepaths, ppaths, pedgepath, ppath, path;\n\n    for(i = 0; i < pathinfo.length; i++) {\n        pi = pathinfo[i];\n        pedgepaths = pi.pedgepaths = [];\n        ppaths = pi.ppaths = [];\n        for(j = 0; j < pi.edgepaths.length; j++) {\n            path = pi.edgepaths[j];\n            pedgepath = [];\n            for(k = 0; k < path.length; k++) {\n                pedgepath[k] = map(path[k]);\n            }\n            pedgepaths.push(pedgepath);\n        }\n        for(j = 0; j < pi.paths.length; j++) {\n            path = pi.paths[j];\n            ppath = [];\n            for(k = 0; k < path.length; k++) {\n                ppath[k] = map(path[k]);\n            }\n            ppaths.push(ppath);\n        }\n    }\n};\n\n},{}],970:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar map1dArray = _dereq_('../carpet/map_1d_array');\nvar makepath = _dereq_('../carpet/makepath');\nvar Drawing = _dereq_('../../components/drawing');\nvar Lib = _dereq_('../../lib');\n\nvar makeCrossings = _dereq_('../contour/make_crossings');\nvar findAllPaths = _dereq_('../contour/find_all_paths');\nvar contourPlot = _dereq_('../contour/plot');\nvar constants = _dereq_('../contour/constants');\nvar convertToConstraints = _dereq_('../contour/convert_to_constraints');\nvar joinAllPaths = _dereq_('./join_all_paths');\nvar emptyPathinfo = _dereq_('../contour/empty_pathinfo');\nvar mapPathinfo = _dereq_('./map_pathinfo');\nvar lookupCarpet = _dereq_('../carpet/lookup_carpetid');\nvar closeBoundaries = _dereq_('../contour/close_boundaries');\n\nmodule.exports = function plot(gd, plotinfo, cdcontours, contourcarpetLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    Lib.makeTraceGroups(contourcarpetLayer, cdcontours, 'contour').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n\n        var carpet = trace._carpetTrace = lookupCarpet(gd, trace);\n        var carpetcd = gd.calcdata[carpet.index][0];\n\n        if(!carpet.visible || carpet.visible === 'legendonly') return;\n\n        var a = cd0.a;\n        var b = cd0.b;\n        var contours = trace.contours;\n        var pathinfo = emptyPathinfo(contours, plotinfo, cd0);\n        var isConstraint = contours.type === 'constraint';\n        var operation = contours._operation;\n        var coloring = isConstraint ? (operation === '=' ? 'lines' : 'fill') : contours.coloring;\n\n        // Map [a, b] (data) --> [i, j] (pixels)\n        function ab2p(ab) {\n            var pt = carpet.ab2xy(ab[0], ab[1], true);\n            return [xa.c2p(pt[0]), ya.c2p(pt[1])];\n        }\n\n        // Define the perimeter in a/b coordinates:\n        var perimeter = [\n            [a[0], b[b.length - 1]],\n            [a[a.length - 1], b[b.length - 1]],\n            [a[a.length - 1], b[0]],\n            [a[0], b[0]]\n        ];\n\n        // Extract the contour levels:\n        makeCrossings(pathinfo);\n        var atol = (a[a.length - 1] - a[0]) * 1e-8;\n        var btol = (b[b.length - 1] - b[0]) * 1e-8;\n        findAllPaths(pathinfo, atol, btol);\n\n        // Constraints might need to be draw inverted, which is not something contours\n        // handle by default since they're assumed fully opaque so that they can be\n        // drawn overlapping. This function flips the paths as necessary so that they're\n        // drawn correctly.\n        //\n        // TODO: Perhaps this should be generalized and *all* paths should be drawn as\n        // closed regions so that translucent contour levels would be valid.\n        // See: https://github.com/plotly/plotly.js/issues/1356\n        var fillPathinfo = pathinfo;\n        if(contours.type === 'constraint') {\n            fillPathinfo = convertToConstraints(pathinfo, operation);\n            closeBoundaries(fillPathinfo, operation, perimeter, trace);\n        }\n\n        // Map the paths in a/b coordinates to pixel coordinates:\n        mapPathinfo(pathinfo, ab2p);\n\n        // draw everything\n\n        // Compute the boundary path\n        var seg, xp, yp, i;\n        var segs = [];\n        for(i = carpetcd.clipsegments.length - 1; i >= 0; i--) {\n            seg = carpetcd.clipsegments[i];\n            xp = map1dArray([], seg.x, xa.c2p);\n            yp = map1dArray([], seg.y, ya.c2p);\n            xp.reverse();\n            yp.reverse();\n            segs.push(makepath(xp, yp, seg.bicubic));\n        }\n\n        var boundaryPath = 'M' + segs.join('L') + 'Z';\n\n        // Draw the baseline background fill that fills in the space behind any other\n        // contour levels:\n        makeBackground(plotGroup, carpetcd.clipsegments, xa, ya, isConstraint, coloring);\n\n        // Draw the specific contour fills. As a simplification, they're assumed to be\n        // fully opaque so that it's easy to draw them simply overlapping. The alternative\n        // would be to flip adjacent paths and draw closed paths for each level instead.\n        makeFills(trace, plotGroup, xa, ya, fillPathinfo, perimeter, ab2p, carpet, carpetcd, coloring, boundaryPath);\n\n        // Draw contour lines:\n        makeLinesAndLabels(plotGroup, pathinfo, gd, cd0, contours, plotinfo, carpet);\n\n        // Clip the boundary of the plot\n        Drawing.setClipUrl(plotGroup, carpet._clipPathId, gd);\n    });\n};\n\nfunction makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, plotinfo, carpet) {\n    var lineContainer = Lib.ensureSingle(plotgroup, 'g', 'contourlines');\n    var showLines = contours.showlines !== false;\n    var showLabels = contours.showlabels;\n    var clipLinesForLabels = showLines && showLabels;\n\n    // Even if we're not going to show lines, we need to create them\n    // if we're showing labels, because the fill paths include the perimeter\n    // so can't be used to position the labels correctly.\n    // In this case we'll remove the lines after making the labels.\n    var linegroup = contourPlot.createLines(lineContainer, showLines || showLabels, pathinfo);\n\n    var lineClip = contourPlot.createLineClip(lineContainer, clipLinesForLabels, gd, cd0.trace.uid);\n\n    var labelGroup = plotgroup.selectAll('g.contourlabels')\n        .data(showLabels ? [0] : []);\n\n    labelGroup.exit().remove();\n\n    labelGroup.enter().append('g')\n        .classed('contourlabels', true);\n\n    if(showLabels) {\n        var xa = plotinfo.xaxis;\n        var ya = plotinfo.yaxis;\n        var xLen = xa._length;\n        var yLen = ya._length;\n        // for simplicity use the xy box for label clipping outline.\n        var labelClipPathData = [[\n            [0, 0],\n            [xLen, 0],\n            [xLen, yLen],\n            [0, yLen]\n        ]];\n\n\n        var labelData = [];\n\n        // invalidate the getTextLocation cache in case paths changed\n        Lib.clearLocationCache();\n\n        var contourFormat = contourPlot.labelFormatter(contours, cd0.t.cb, gd._fullLayout);\n\n        var dummyText = Drawing.tester.append('text')\n            .attr('data-notex', 1)\n            .call(Drawing.font, contours.labelfont);\n\n        // use `bounds` only to keep labels away from the x/y boundaries\n        // `constrainToCarpet` below ensures labels don't go off the\n        // carpet edges\n        var bounds = {\n            left: 0,\n            right: xLen,\n            center: xLen / 2,\n            top: 0,\n            bottom: yLen,\n            middle: yLen / 2\n        };\n\n        var plotDiagonal = Math.sqrt(xLen * xLen + yLen * yLen);\n\n        // the path length to use to scale the number of labels to draw:\n        var normLength = constants.LABELDISTANCE * plotDiagonal /\n            Math.max(1, pathinfo.length / constants.LABELINCREASE);\n\n        linegroup.each(function(d) {\n            var textOpts = contourPlot.calcTextOpts(d.level, contourFormat, dummyText, gd);\n\n            d3.select(this).selectAll('path').each(function(pathData) {\n                var path = this;\n                var pathBounds = Lib.getVisibleSegment(path, bounds, textOpts.height / 2);\n                if(!pathBounds) return;\n\n                constrainToCarpet(path, pathData, d, pathBounds, carpet, textOpts.height);\n\n                if(pathBounds.len < (textOpts.width + textOpts.height) * constants.LABELMIN) return;\n\n                var maxLabels = Math.min(Math.ceil(pathBounds.len / normLength),\n                    constants.LABELMAX);\n\n                for(var i = 0; i < maxLabels; i++) {\n                    var loc = contourPlot.findBestTextLocation(path, pathBounds, textOpts,\n                        labelData, bounds);\n\n                    if(!loc) break;\n\n                    contourPlot.addLabelData(loc, textOpts, labelData, labelClipPathData);\n                }\n            });\n        });\n\n        dummyText.remove();\n\n        contourPlot.drawLabels(labelGroup, labelData, gd, lineClip,\n            clipLinesForLabels ? labelClipPathData : null);\n    }\n\n    if(showLabels && !showLines) linegroup.remove();\n}\n\n// figure out if this path goes off the edge of the carpet\n// and shorten the part we call visible to keep labels away from the edge\nfunction constrainToCarpet(path, pathData, levelData, pathBounds, carpet, textHeight) {\n    var pathABData;\n    for(var i = 0; i < levelData.pedgepaths.length; i++) {\n        if(pathData === levelData.pedgepaths[i]) {\n            pathABData = levelData.edgepaths[i];\n        }\n    }\n    if(!pathABData) return;\n\n    var aMin = carpet.a[0];\n    var aMax = carpet.a[carpet.a.length - 1];\n    var bMin = carpet.b[0];\n    var bMax = carpet.b[carpet.b.length - 1];\n\n    function getOffset(abPt, pathVector) {\n        var offset = 0;\n        var edgeVector;\n        var dAB = 0.1;\n        if(Math.abs(abPt[0] - aMin) < dAB || Math.abs(abPt[0] - aMax) < dAB) {\n            edgeVector = normalizeVector(carpet.dxydb_rough(abPt[0], abPt[1], dAB));\n            offset = Math.max(offset, textHeight * vectorTan(pathVector, edgeVector) / 2);\n        }\n\n        if(Math.abs(abPt[1] - bMin) < dAB || Math.abs(abPt[1] - bMax) < dAB) {\n            edgeVector = normalizeVector(carpet.dxyda_rough(abPt[0], abPt[1], dAB));\n            offset = Math.max(offset, textHeight * vectorTan(pathVector, edgeVector) / 2);\n        }\n        return offset;\n    }\n\n    var startVector = getUnitVector(path, 0, 1);\n    var endVector = getUnitVector(path, pathBounds.total, pathBounds.total - 1);\n    var minStart = getOffset(pathABData[0], startVector);\n    var maxEnd = pathBounds.total - getOffset(pathABData[pathABData.length - 1], endVector);\n\n    if(pathBounds.min < minStart) pathBounds.min = minStart;\n    if(pathBounds.max > maxEnd) pathBounds.max = maxEnd;\n\n    pathBounds.len = pathBounds.max - pathBounds.min;\n}\n\nfunction getUnitVector(path, p0, p1) {\n    var pt0 = path.getPointAtLength(p0);\n    var pt1 = path.getPointAtLength(p1);\n    var dx = pt1.x - pt0.x;\n    var dy = pt1.y - pt0.y;\n    var len = Math.sqrt(dx * dx + dy * dy);\n    return [dx / len, dy / len];\n}\n\nfunction normalizeVector(v) {\n    var len = Math.sqrt(v[0] * v[0] + v[1] * v[1]);\n    return [v[0] / len, v[1] / len];\n}\n\nfunction vectorTan(v0, v1) {\n    var cos = Math.abs(v0[0] * v1[0] + v0[1] * v1[1]);\n    var sin = Math.sqrt(1 - cos * cos);\n    return sin / cos;\n}\n\nfunction makeBackground(plotgroup, clipsegments, xaxis, yaxis, isConstraint, coloring) {\n    var seg, xp, yp, i;\n    var bggroup = Lib.ensureSingle(plotgroup, 'g', 'contourbg');\n\n    var bgfill = bggroup.selectAll('path')\n        .data((coloring === 'fill' && !isConstraint) ? [0] : []);\n    bgfill.enter().append('path');\n    bgfill.exit().remove();\n\n    var segs = [];\n    for(i = 0; i < clipsegments.length; i++) {\n        seg = clipsegments[i];\n        xp = map1dArray([], seg.x, xaxis.c2p);\n        yp = map1dArray([], seg.y, yaxis.c2p);\n        segs.push(makepath(xp, yp, seg.bicubic));\n    }\n\n    bgfill\n        .attr('d', 'M' + segs.join('L') + 'Z')\n        .style('stroke', 'none');\n}\n\nfunction makeFills(trace, plotgroup, xa, ya, pathinfo, perimeter, ab2p, carpet, carpetcd, coloring, boundaryPath) {\n    var fillgroup = Lib.ensureSingle(plotgroup, 'g', 'contourfill');\n\n    var fillitems = fillgroup.selectAll('path')\n        .data(coloring === 'fill' ? pathinfo : []);\n    fillitems.enter().append('path');\n    fillitems.exit().remove();\n    fillitems.each(function(pi) {\n        // join all paths for this level together into a single path\n        // first follow clockwise around the perimeter to close any open paths\n        // if the whole perimeter is above this level, start with a path\n        // enclosing the whole thing. With all that, the parity should mean\n        // that we always fill everything above the contour, nothing below\n        var fullpath = joinAllPaths(trace, pi, perimeter, ab2p, carpet, carpetcd, xa, ya);\n\n        if(pi.prefixBoundary) {\n            fullpath = boundaryPath + fullpath;\n        }\n\n        if(!fullpath) {\n            d3.select(this).remove();\n        } else {\n            d3.select(this)\n                .attr('d', fullpath)\n                .style('stroke', 'none');\n        }\n    });\n}\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../carpet/lookup_carpetid\":915,\"../carpet/makepath\":916,\"../carpet/map_1d_array\":917,\"../contour/close_boundaries\":944,\"../contour/constants\":946,\"../contour/convert_to_constraints\":950,\"../contour/empty_pathinfo\":952,\"../contour/find_all_paths\":954,\"../contour/make_crossings\":959,\"../contour/plot\":960,\"./join_all_paths\":968,\"./map_pathinfo\":969,\"d3\":163}],971:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar scatterMapboxAttrs = _dereq_('../scattermapbox/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\n/*\n * - https://docs.mapbox.com/help/tutorials/make-a-heatmap-with-mapbox-gl-js/\n * - https://docs.mapbox.com/mapbox-gl-js/example/heatmap-layer/\n * - https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers-heatmap\n * - https://blog.mapbox.com/introducing-heatmaps-in-mapbox-gl-js-71355ada9e6c\n *\n * Gotchas:\n * - https://github.com/mapbox/mapbox-gl-js/issues/6463\n * - https://github.com/mapbox/mapbox-gl-js/issues/6112\n */\n\n/*\n *\n * In mathematical terms, Mapbox GL heatmaps are a bivariate (2D) kernel density\n * estimation with a Gaussian kernel. It means that each data point has an area\n * of “influence” around it (called a kernel) where the numerical value of\n * influence (which we call density) decreases as you go further from the point.\n * If we sum density values of all points in every pixel of the screen, we get a\n * combined density value which we then map to a heatmap color.\n *\n */\n\nmodule.exports = extendFlat({\n    lon: scatterMapboxAttrs.lon,\n    lat: scatterMapboxAttrs.lat,\n\n    z: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    radius: {\n        valType: 'number',\n        \n        editType: 'plot',\n        arrayOk: true,\n        min: 1,\n        dflt: 30,\n        \n    },\n\n    below: {\n        valType: 'string',\n        \n        editType: 'plot',\n        \n    },\n\n    text: scatterMapboxAttrs.text,\n    hovertext: scatterMapboxAttrs.hovertext,\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['lon', 'lat', 'z', 'text', 'name']\n    }),\n    hovertemplate: hovertemplateAttrs()\n},\n    colorScaleAttrs('', {\n        cLetter: 'z',\n        editTypeOverride: 'calc'\n    })\n);\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../scattermapbox/attributes\":1171}],972:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\nvar _ = _dereq_('../../lib')._;\n\nmodule.exports = function calc(gd, trace) {\n    var len = trace._length;\n    var calcTrace = new Array(len);\n    var z = trace.z;\n    var hasZ = isArrayOrTypedArray(z) && z.length;\n\n    for(var i = 0; i < len; i++) {\n        var cdi = calcTrace[i] = {};\n\n        var lon = trace.lon[i];\n        var lat = trace.lat[i];\n\n        cdi.lonlat = isNumeric(lon) && isNumeric(lat) ?\n            [+lon, +lat] :\n            [BADNUM, BADNUM];\n\n        if(hasZ) {\n            var zi = z[i];\n            cdi.z = isNumeric(zi) ? zi : BADNUM;\n        }\n    }\n\n    colorscaleCalc(gd, trace, {\n        vals: hasZ ? z : [0, 1],\n        containerStr: '',\n        cLetter: 'z'\n    });\n\n    if(len) {\n        calcTrace[0].t = {\n            labels: {\n                lat: _(gd, 'lat:') + ' ',\n                lon: _(gd, 'lon:') + ' '\n            }\n        };\n    }\n\n    return calcTrace;\n};\n\n},{\"../../components/colorscale/calc\":601,\"../../constants/numerical\":695,\"../../lib\":719,\"fast-isnumeric\":225}],973:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\nvar Colorscale = _dereq_('../../components/colorscale');\n\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\nvar makeBlank = _dereq_('../../lib/geojson_utils').makeBlank;\n\nmodule.exports = function convert(calcTrace) {\n    var trace = calcTrace[0].trace;\n    var isVisible = (trace.visible === true && trace._length !== 0);\n\n    var heatmap = {\n        layout: {visibility: 'none'},\n        paint: {}\n    };\n\n    var opts = trace._opts = {\n        heatmap: heatmap,\n        geojson: makeBlank()\n    };\n\n    // early return if not visible or placeholder\n    if(!isVisible) return opts;\n\n    var features = [];\n    var i;\n\n    var z = trace.z;\n    var radius = trace.radius;\n    var hasZ = Lib.isArrayOrTypedArray(z) && z.length;\n    var hasArrayRadius = Lib.isArrayOrTypedArray(radius);\n\n    for(i = 0; i < calcTrace.length; i++) {\n        var cdi = calcTrace[i];\n        var lonlat = cdi.lonlat;\n\n        if(lonlat[0] !== BADNUM) {\n            var props = {};\n\n            if(hasZ) {\n                var zi = cdi.z;\n                props.z = zi !== BADNUM ? zi : 0;\n            }\n            if(hasArrayRadius) {\n                props.r = (isNumeric(radius[i]) && radius[i] > 0) ? +radius[i] : 0;\n            }\n\n            features.push({\n                type: 'Feature',\n                geometry: {type: 'Point', coordinates: lonlat},\n                properties: props\n            });\n        }\n    }\n\n    var cOpts = Colorscale.extractOpts(trace);\n    var scl = cOpts.reversescale ?\n        Colorscale.flipScale(cOpts.colorscale) :\n        cOpts.colorscale;\n\n    // Add alpha channel to first colorscale step.\n    // If not, we would essentially color the entire map.\n    // See https://docs.mapbox.com/mapbox-gl-js/example/heatmap-layer/\n    var scl01 = scl[0][1];\n    var color0 = Color.opacity(scl01) < 1 ? scl01 : Color.addOpacity(scl01, 0);\n\n    var heatmapColor = [\n        'interpolate', ['linear'],\n        ['heatmap-density'],\n        0, color0\n    ];\n    for(i = 1; i < scl.length; i++) {\n        heatmapColor.push(scl[i][0], scl[i][1]);\n    }\n\n    // Those \"weights\" have to be in [0, 1], we can do this either:\n    // - as here using a mapbox-gl expression\n    // - or, scale the 'z' property in the feature loop\n    var zExp = [\n        'interpolate', ['linear'],\n        ['get', 'z'],\n        cOpts.min, 0,\n        cOpts.max, 1\n    ];\n\n    Lib.extendFlat(opts.heatmap.paint, {\n        'heatmap-weight': hasZ ? zExp : 1 / (cOpts.max - cOpts.min),\n\n        'heatmap-color': heatmapColor,\n\n        'heatmap-radius': hasArrayRadius ?\n            {type: 'identity', property: 'r'} :\n            trace.radius,\n\n        'heatmap-opacity': trace.opacity\n    });\n\n    opts.geojson = {type: 'FeatureCollection', features: features};\n    opts.heatmap.layout.visibility = 'visible';\n\n    return opts;\n};\n\n},{\"../../components/color\":593,\"../../components/colorscale\":605,\"../../constants/numerical\":695,\"../../lib\":719,\"../../lib/geojson_utils\":714,\"fast-isnumeric\":225}],974:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var lon = coerce('lon') || [];\n    var lat = coerce('lat') || [];\n\n    var len = Math.min(lon.length, lat.length);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    traceOut._length = len;\n\n    coerce('z');\n    coerce('radius');\n    coerce('below');\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"./attributes\":971}],975:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function eventData(out, pt) {\n    out.lon = pt.lon;\n    out.lat = pt.lat;\n    out.z = pt.z;\n    return out;\n};\n\n},{}],976:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar scatterMapboxHoverPoints = _dereq_('../scattermapbox/hover');\n\nmodule.exports = function hoverPoints(pointData, xval, yval) {\n    var pts = scatterMapboxHoverPoints(pointData, xval, yval);\n    if(!pts) return;\n\n    var newPointData = pts[0];\n    var cd = newPointData.cd;\n    var trace = cd[0].trace;\n    var di = cd[newPointData.index];\n\n    // let Fx.hover pick the color\n    delete newPointData.color;\n\n    if('z' in di) {\n        var ax = newPointData.subplot.mockAxis;\n        newPointData.z = di.z;\n        newPointData.zLabel = Axes.tickText(ax, ax.c2l(di.z), 'hover').text;\n    }\n\n    newPointData.extraText = getExtraText(trace, di, cd[0].t.labels);\n\n    return [newPointData];\n};\n\nfunction getExtraText(trace, di, labels) {\n    if(trace.hovertemplate) return;\n\n    var hoverinfo = di.hi || trace.hoverinfo;\n    var parts = hoverinfo.split('+');\n    var isAll = parts.indexOf('all') !== -1;\n    var hasLon = parts.indexOf('lon') !== -1;\n    var hasLat = parts.indexOf('lat') !== -1;\n    var lonlat = di.lonlat;\n    var text = [];\n\n    function format(v) {\n        return v + '\\u00B0';\n    }\n\n    if(isAll || (hasLon && hasLat)) {\n        text.push('(' + format(lonlat[0]) + ', ' + format(lonlat[1]) + ')');\n    } else if(hasLon) {\n        text.push(labels.lon + format(lonlat[0]));\n    } else if(hasLat) {\n        text.push(labels.lat + format(lonlat[1]));\n    }\n\n    if(isAll || parts.indexOf('text') !== -1) {\n        Lib.fillText(di, trace, text);\n    }\n\n    return text.join('<br>');\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../scattermapbox/hover\":1175}],977:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../heatmap/colorbar'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    hoverPoints: _dereq_('./hover'),\n    eventData: _dereq_('./event_data'),\n\n    getBelow: function(trace, subplot) {\n        var mapLayers = subplot.getMapLayers();\n\n        // find first layer with `type: 'symbol'`,\n        // that is not a plotly layer\n        for(var i = 0; i < mapLayers.length; i++) {\n            var layer = mapLayers[i];\n            var layerId = layer.id;\n            if(layer.type === 'symbol' &&\n                typeof layerId === 'string' && layerId.indexOf('plotly-') === -1\n            ) {\n                return layerId;\n            }\n        }\n    },\n\n    moduleType: 'trace',\n    name: 'densitymapbox',\n    basePlotModule: _dereq_('../../plots/mapbox'),\n    categories: ['mapbox', 'gl'],\n    meta: {\n        hr_name: 'density_mapbox',\n        \n    }\n};\n\n},{\"../../plots/mapbox\":822,\"../heatmap/colorbar\":1004,\"./attributes\":971,\"./calc\":972,\"./defaults\":974,\"./event_data\":975,\"./hover\":976,\"./plot\":978}],978:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar convert = _dereq_('./convert');\nvar LAYER_PREFIX = _dereq_('../../plots/mapbox/constants').traceLayerPrefix;\n\nfunction DensityMapbox(subplot, uid) {\n    this.subplot = subplot;\n    this.uid = uid;\n\n    this.sourceId = 'source-' + uid;\n\n    this.layerList = [\n        ['heatmap', LAYER_PREFIX + uid + '-heatmap']\n    ];\n\n    // previous 'below' value,\n    // need this to update it properly\n    this.below = null;\n}\n\nvar proto = DensityMapbox.prototype;\n\nproto.update = function(calcTrace) {\n    var subplot = this.subplot;\n    var layerList = this.layerList;\n    var optsAll = convert(calcTrace);\n    var below = subplot.belowLookup['trace-' + this.uid];\n\n    subplot.map\n        .getSource(this.sourceId)\n        .setData(optsAll.geojson);\n\n    if(below !== this.below) {\n        this._removeLayers();\n        this._addLayers(optsAll, below);\n        this.below = below;\n    }\n\n    for(var i = 0; i < layerList.length; i++) {\n        var item = layerList[i];\n        var k = item[0];\n        var id = item[1];\n        var opts = optsAll[k];\n\n        subplot.setOptions(id, 'setLayoutProperty', opts.layout);\n\n        if(opts.layout.visibility === 'visible') {\n            subplot.setOptions(id, 'setPaintProperty', opts.paint);\n        }\n    }\n};\n\nproto._addLayers = function(optsAll, below) {\n    var subplot = this.subplot;\n    var layerList = this.layerList;\n    var sourceId = this.sourceId;\n\n    for(var i = 0; i < layerList.length; i++) {\n        var item = layerList[i];\n        var k = item[0];\n        var opts = optsAll[k];\n\n        subplot.addLayer({\n            type: k,\n            id: item[1],\n            source: sourceId,\n            layout: opts.layout,\n            paint: opts.paint\n        }, below);\n    }\n};\n\nproto._removeLayers = function() {\n    var map = this.subplot.map;\n    var layerList = this.layerList;\n\n    for(var i = layerList.length - 1; i >= 0; i--) {\n        map.removeLayer(layerList[i][1]);\n    }\n};\n\nproto.dispose = function() {\n    var map = this.subplot.map;\n    this._removeLayers();\n    map.removeSource(this.sourceId);\n};\n\nmodule.exports = function createDensityMapbox(subplot, calcTrace) {\n    var trace = calcTrace[0].trace;\n    var densityMapbox = new DensityMapbox(subplot, trace.uid);\n    var sourceId = densityMapbox.sourceId;\n    var optsAll = convert(calcTrace);\n    var below = densityMapbox.below = subplot.belowLookup['trace-' + trace.uid];\n\n    subplot.map.addSource(sourceId, {\n        type: 'geojson',\n        data: optsAll.geojson\n    });\n\n    densityMapbox._addLayers(optsAll, below);\n\n    return densityMapbox;\n};\n\n},{\"../../plots/mapbox/constants\":820,\"./convert\":973}],979:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n// arrayOk attributes, merge them into calcdata array\nmodule.exports = function arraysToCalcdata(cd, trace) {\n    for(var i = 0; i < cd.length; i++) cd[i].i = i;\n\n    Lib.mergeArray(trace.text, cd, 'tx');\n    Lib.mergeArray(trace.hovertext, cd, 'htx');\n\n    var marker = trace.marker;\n    if(marker) {\n        Lib.mergeArray(marker.opacity, cd, 'mo');\n        Lib.mergeArray(marker.color, cd, 'mc');\n\n        var markerLine = marker.line;\n        if(markerLine) {\n            Lib.mergeArray(markerLine.color, cd, 'mlc');\n            Lib.mergeArrayCastPositive(markerLine.width, cd, 'mlw');\n        }\n    }\n};\n\n},{\"../../lib\":719}],980:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar barAttrs = _dereq_('../bar/attributes');\nvar lineAttrs = _dereq_('../scatter/attributes').line;\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar constants = _dereq_('./constants');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar Color = _dereq_('../../components/color');\n\nmodule.exports = {\n    x: barAttrs.x,\n    x0: barAttrs.x0,\n    dx: barAttrs.dx,\n    y: barAttrs.y,\n    y0: barAttrs.y0,\n    dy: barAttrs.dy,\n\n    hovertext: barAttrs.hovertext,\n    hovertemplate: hovertemplateAttrs({}, {\n        keys: constants.eventDataKeys\n    }),\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['name', 'x', 'y', 'text', 'percent initial', 'percent previous', 'percent total']\n    }),\n\n    textinfo: {\n        valType: 'flaglist',\n        flags: ['label', 'text', 'percent initial', 'percent previous', 'percent total', 'value'],\n        extras: ['none'],\n        \n        editType: 'plot',\n        arrayOk: false,\n        \n    },\n\n    text: barAttrs.text,\n    textposition: extendFlat({}, barAttrs.textposition, {dflt: 'auto'}),\n    insidetextanchor: extendFlat({}, barAttrs.insidetextanchor, {dflt: 'middle'}),\n    textangle: extendFlat({}, barAttrs.textangle, {dflt: 0}),\n    textfont: barAttrs.textfont,\n    insidetextfont: barAttrs.insidetextfont,\n    outsidetextfont: barAttrs.outsidetextfont,\n    constraintext: barAttrs.constraintext,\n    cliponaxis: barAttrs.cliponaxis,\n\n    orientation: extendFlat({}, barAttrs.orientation, {\n        \n    }),\n\n    offset: extendFlat({}, barAttrs.offset, {arrayOk: false}),\n    width: extendFlat({}, barAttrs.width, {arrayOk: false}),\n\n    marker: barAttrs.marker,\n\n    connector: {\n        fillcolor: {\n            valType: 'color',\n            \n            editType: 'style',\n            \n        },\n        line: {\n            color: extendFlat({}, lineAttrs.color, {dflt: Color.defaultLine}),\n            width: extendFlat({}, lineAttrs.width, {\n                dflt: 0,\n                editType: 'plot',\n            }),\n            dash: lineAttrs.dash,\n            editType: 'style'\n        },\n        visible: {\n            valType: 'boolean',\n            dflt: true,\n            \n            editType: 'plot',\n            \n        },\n        editType: 'plot'\n    },\n\n    offsetgroup: barAttrs.offsetgroup,\n    alignmentgroup: barAttrs.alignmentgroup\n};\n\n},{\"../../components/color\":593,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../bar/attributes\":857,\"../scatter/attributes\":1112,\"./constants\":982}],981:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar arraysToCalcdata = _dereq_('./arrays_to_calcdata');\nvar calcSelection = _dereq_('../scatter/calc_selection');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function calc(gd, trace) {\n    var xa = Axes.getFromId(gd, trace.xaxis || 'x');\n    var ya = Axes.getFromId(gd, trace.yaxis || 'y');\n    var size, pos, i, cdi;\n\n    if(trace.orientation === 'h') {\n        size = xa.makeCalcdata(trace, 'x');\n        pos = ya.makeCalcdata(trace, 'y');\n    } else {\n        size = ya.makeCalcdata(trace, 'y');\n        pos = xa.makeCalcdata(trace, 'x');\n    }\n\n    // create the \"calculated data\" to plot\n    var serieslen = Math.min(pos.length, size.length);\n    var cd = new Array(serieslen);\n\n    // Unlike other bar-like traces funnels do not support base attribute.\n    // bases for funnels are computed internally in a way that\n    // the mid-point of each bar are located on the axis line.\n    trace._base = [];\n\n    // set position and size\n    for(i = 0; i < serieslen; i++) {\n        // treat negative values as bad numbers\n        if(size[i] < 0) size[i] = BADNUM;\n\n        var connectToNext = false;\n        if(size[i] !== BADNUM) {\n            if(i + 1 < serieslen && size[i + 1] !== BADNUM) {\n                connectToNext = true;\n            }\n        }\n\n        cdi = cd[i] = {\n            p: pos[i],\n            s: size[i],\n            cNext: connectToNext\n        };\n\n        trace._base[i] = -0.5 * cdi.s;\n\n        if(trace.ids) {\n            cdi.id = String(trace.ids[i]);\n        }\n\n        // calculate total values\n        if(i === 0) cd[0].vTotal = 0;\n        cd[0].vTotal += fixNum(cdi.s);\n\n        // ratio from initial value\n        cdi.begR = fixNum(cdi.s) / fixNum(cd[0].s);\n    }\n\n    var prevGoodNum;\n    for(i = 0; i < serieslen; i++) {\n        cdi = cd[i];\n        if(cdi.s === BADNUM) continue;\n\n        // ratio of total value\n        cdi.sumR = cdi.s / cd[0].vTotal;\n\n        // ratio of previous (good) value\n        cdi.difR = (prevGoodNum !== undefined) ? cdi.s / prevGoodNum : 1;\n\n        prevGoodNum = cdi.s;\n    }\n\n    arraysToCalcdata(cd, trace);\n    calcSelection(cd, trace);\n\n    return cd;\n};\n\nfunction fixNum(a) {\n    return (a === BADNUM) ? 0 : a;\n}\n\n},{\"../../constants/numerical\":695,\"../../plots/cartesian/axes\":767,\"../scatter/calc_selection\":1114,\"./arrays_to_calcdata\":979}],982:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    eventDataKeys: [\n        'percentInitial',\n        'percentPrevious',\n        'percentTotal'\n    ]\n};\n\n},{}],983:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar setGroupPositions = _dereq_('../bar/cross_trace_calc').setGroupPositions;\n\nmodule.exports = function crossTraceCalc(gd, plotinfo) {\n    var fullLayout = gd._fullLayout;\n    var fullData = gd._fullData;\n    var calcdata = gd.calcdata;\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n    var funnels = [];\n    var funnelsVert = [];\n    var funnelsHorz = [];\n    var cd, i;\n\n    for(i = 0; i < fullData.length; i++) {\n        var fullTrace = fullData[i];\n        var isHorizontal = (fullTrace.orientation === 'h');\n\n        if(\n            fullTrace.visible === true &&\n            fullTrace.xaxis === xa._id &&\n            fullTrace.yaxis === ya._id &&\n            fullTrace.type === 'funnel'\n        ) {\n            cd = calcdata[i];\n\n            if(isHorizontal) {\n                funnelsHorz.push(cd);\n            } else {\n                funnelsVert.push(cd);\n            }\n\n            funnels.push(cd);\n        }\n    }\n\n    var opts = {\n        mode: fullLayout.funnelmode,\n        norm: fullLayout.funnelnorm,\n        gap: fullLayout.funnelgap,\n        groupgap: fullLayout.funnelgroupgap\n    };\n\n    setGroupPositions(gd, xa, ya, funnelsVert, opts);\n    setGroupPositions(gd, ya, xa, funnelsHorz, opts);\n\n    for(i = 0; i < funnels.length; i++) {\n        cd = funnels[i];\n\n        for(var j = 0; j < cd.length; j++) {\n            if(j + 1 < cd.length) {\n                cd[j].nextP0 = cd[j + 1].p0;\n                cd[j].nextS0 = cd[j + 1].s0;\n\n                cd[j].nextP1 = cd[j + 1].p1;\n                cd[j].nextS1 = cd[j + 1].s1;\n            }\n        }\n    }\n};\n\n},{\"../bar/cross_trace_calc\":860}],984:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleGroupingDefaults = _dereq_('../bar/defaults').handleGroupingDefaults;\nvar handleText = _dereq_('../bar/defaults').handleText;\nvar handleXYDefaults = _dereq_('../scatter/xy_defaults');\nvar attributes = _dereq_('./attributes');\nvar Color = _dereq_('../../components/color');\n\nfunction supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleXYDefaults(traceIn, traceOut, layout, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('orientation', (traceOut.y && !traceOut.x) ? 'v' : 'h');\n    coerce('offset');\n    coerce('width');\n\n    var text = coerce('text');\n\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    var textposition = coerce('textposition');\n    handleText(traceIn, traceOut, layout, coerce, textposition, {\n        moduleHasSelected: false,\n        moduleHasUnselected: false,\n        moduleHasConstrain: true,\n        moduleHasCliponaxis: true,\n        moduleHasTextangle: true,\n        moduleHasInsideanchor: true\n    });\n\n    if(traceOut.textposition !== 'none') {\n        coerce('textinfo', Array.isArray(text) ? 'text+value' : 'value');\n    }\n\n    var markerColor = coerce('marker.color', defaultColor);\n    coerce('marker.line.color', Color.defaultLine);\n    coerce('marker.line.width');\n\n    var connectorVisible = coerce('connector.visible');\n    if(connectorVisible) {\n        coerce('connector.fillcolor', defaultFillColor(markerColor));\n\n        var connectorLineWidth = coerce('connector.line.width');\n        if(connectorLineWidth) {\n            coerce('connector.line.color');\n            coerce('connector.line.dash');\n        }\n    }\n}\n\nfunction defaultFillColor(markerColor) {\n    var cBase = Lib.isArrayOrTypedArray(markerColor) ? '#000' : markerColor;\n\n    return Color.addOpacity(cBase, 0.5 * Color.opacity(cBase));\n}\n\nfunction crossTraceDefaults(fullData, fullLayout) {\n    var traceIn, traceOut;\n\n    function coerce(attr) {\n        return Lib.coerce(traceOut._input, traceOut, attributes, attr);\n    }\n\n    if(fullLayout.funnelmode === 'group') {\n        for(var i = 0; i < fullData.length; i++) {\n            traceOut = fullData[i];\n            traceIn = traceOut._input;\n\n            handleGroupingDefaults(traceIn, traceOut, fullLayout, coerce);\n        }\n    }\n}\n\nmodule.exports = {\n    supplyDefaults: supplyDefaults,\n    crossTraceDefaults: crossTraceDefaults\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../bar/defaults\":861,\"../scatter/xy_defaults\":1137,\"./attributes\":980}],985:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function eventData(out, pt /* , trace, cd, pointNumber */) {\n    // standard cartesian event data\n    out.x = 'xVal' in pt ? pt.xVal : pt.x;\n    out.y = 'yVal' in pt ? pt.yVal : pt.y;\n\n    // for funnel\n    if('percentInitial' in pt) out.percentInitial = pt.percentInitial;\n    if('percentPrevious' in pt) out.percentPrevious = pt.percentPrevious;\n    if('percentTotal' in pt) out.percentTotal = pt.percentTotal;\n\n    if(pt.xa) out.xaxis = pt.xa;\n    if(pt.ya) out.yaxis = pt.ya;\n\n    return out;\n};\n\n},{}],986:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar opacity = _dereq_('../../components/color').opacity;\nvar hoverOnBars = _dereq_('../bar/hover').hoverOnBars;\nvar formatPercent = _dereq_('../../lib').formatPercent;\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode) {\n    var point = hoverOnBars(pointData, xval, yval, hovermode);\n    if(!point) return;\n\n    var cd = point.cd;\n    var trace = cd[0].trace;\n    var isHorizontal = (trace.orientation === 'h');\n\n    // the closest data point\n    var index = point.index;\n    var di = cd[index];\n\n    var sizeLetter = isHorizontal ? 'x' : 'y';\n    point[sizeLetter + 'LabelVal'] = di.s;\n\n    point.percentInitial = di.begR;\n    point.percentInitialLabel = formatPercent(di.begR, 1);\n\n    point.percentPrevious = di.difR;\n    point.percentPreviousLabel = formatPercent(di.difR, 1);\n\n    point.percentTotal = di.sumR;\n    point.percentTotalLabel = formatPercent(di.sumR, 1);\n\n    var hoverinfo = di.hi || trace.hoverinfo;\n    var text = [];\n    if(hoverinfo && hoverinfo !== 'none' && hoverinfo !== 'skip') {\n        var isAll = (hoverinfo === 'all');\n        var parts = hoverinfo.split('+');\n\n        var hasFlag = function(flag) { return isAll || parts.indexOf(flag) !== -1; };\n\n        if(hasFlag('percent initial')) {\n            text.push(point.percentInitialLabel + ' of initial');\n        }\n        if(hasFlag('percent previous')) {\n            text.push(point.percentPreviousLabel + ' of previous');\n        }\n        if(hasFlag('percent total')) {\n            text.push(point.percentTotalLabel + ' of total');\n        }\n    }\n    point.extraText = text.join('<br>');\n\n    point.color = getTraceColor(trace, di);\n\n    return [point];\n};\n\nfunction getTraceColor(trace, di) {\n    var cont = trace.marker;\n    var mc = di.mc || cont.color;\n    var mlc = di.mlc || cont.line.color;\n    var mlw = di.mlw || cont.line.width;\n    if(opacity(mc)) return mc;\n    else if(opacity(mlc) && mlw) return mlc;\n}\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../bar/hover\":863}],987:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyDefaults: _dereq_('./defaults').supplyDefaults,\n    crossTraceDefaults: _dereq_('./defaults').crossTraceDefaults,\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n    calc: _dereq_('./calc'),\n    crossTraceCalc: _dereq_('./cross_trace_calc'),\n    plot: _dereq_('./plot'),\n    style: _dereq_('./style').style,\n    hoverPoints: _dereq_('./hover'),\n    eventData: _dereq_('./event_data'),\n\n    selectPoints: _dereq_('../bar/select'),\n\n    moduleType: 'trace',\n    name: 'funnel',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['bar-like', 'cartesian', 'svg', 'oriented', 'showLegend', 'zoomScale'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../bar/select\":868,\"./attributes\":980,\"./calc\":981,\"./cross_trace_calc\":983,\"./defaults\":984,\"./event_data\":985,\"./hover\":986,\"./layout_attributes\":988,\"./layout_defaults\":989,\"./plot\":990,\"./style\":991}],988:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    funnelmode: {\n        valType: 'enumerated',\n        values: ['stack', 'group', 'overlay'],\n        dflt: 'stack',\n        \n        editType: 'calc',\n        \n    },\n    funnelgap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        \n        editType: 'calc',\n        \n    },\n    funnelgroupgap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    }\n};\n\n},{}],989:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nmodule.exports = function(layoutIn, layoutOut, fullData) {\n    var hasTraceType = false;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n\n        if(trace.visible && trace.type === 'funnel') {\n            hasTraceType = true;\n            break;\n        }\n    }\n\n    if(hasTraceType) {\n        coerce('funnelmode');\n        coerce('funnelgap', 0.2);\n        coerce('funnelgroupgap');\n    }\n};\n\n},{\"../../lib\":719,\"./layout_attributes\":988}],990:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../../components/drawing');\nvar barPlot = _dereq_('../bar/plot').plot;\n\nmodule.exports = function plot(gd, plotinfo, cdModule, traceLayer) {\n    var fullLayout = gd._fullLayout;\n\n    plotConnectorRegions(gd, plotinfo, cdModule, traceLayer);\n    plotConnectorLines(gd, plotinfo, cdModule, traceLayer);\n\n    barPlot(gd, plotinfo, cdModule, traceLayer, {\n        mode: fullLayout.funnelmode,\n        norm: fullLayout.funnelmode,\n        gap: fullLayout.funnelgap,\n        groupgap: fullLayout.funnelgroupgap\n    });\n};\n\nfunction plotConnectorRegions(gd, plotinfo, cdModule, traceLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    Lib.makeTraceGroups(traceLayer, cdModule, 'trace bars').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var trace = cd[0].trace;\n\n        var group = Lib.ensureSingle(plotGroup, 'g', 'regions');\n\n        if(!trace.connector || !trace.connector.visible) {\n            group.remove();\n            return;\n        }\n\n        var isHorizontal = (trace.orientation === 'h');\n\n        var connectors = group.selectAll('g.region').data(Lib.identity);\n\n        connectors.enter().append('g')\n            .classed('region', true);\n\n        connectors.exit().remove();\n\n        var len = connectors.size();\n\n        connectors.each(function(di, i) {\n            // don't draw lines between nulls\n            if(i !== len - 1 && !di.cNext) return;\n\n            var xy = getXY(di, xa, ya, isHorizontal);\n            var x = xy[0];\n            var y = xy[1];\n\n            var shape = '';\n\n            if(x[3] !== undefined && y[3] !== undefined) {\n                if(isHorizontal) {\n                    shape += 'M' + x[0] + ',' + y[1] + 'L' + x[2] + ',' + y[2] + 'H' + x[3] + 'L' + x[1] + ',' + y[1] + 'Z';\n                } else {\n                    shape += 'M' + x[1] + ',' + y[1] + 'L' + x[2] + ',' + y[3] + 'V' + y[2] + 'L' + x[1] + ',' + y[0] + 'Z';\n                }\n            }\n\n            Lib.ensureSingle(d3.select(this), 'path')\n                .attr('d', shape)\n                .call(Drawing.setClipUrl, plotinfo.layerClipId, gd);\n        });\n    });\n}\n\nfunction plotConnectorLines(gd, plotinfo, cdModule, traceLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    Lib.makeTraceGroups(traceLayer, cdModule, 'trace bars').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var trace = cd[0].trace;\n\n        var group = Lib.ensureSingle(plotGroup, 'g', 'lines');\n\n        if(!trace.connector || !trace.connector.visible || !trace.connector.line.width) {\n            group.remove();\n            return;\n        }\n\n        var isHorizontal = (trace.orientation === 'h');\n\n        var connectors = group.selectAll('g.line').data(Lib.identity);\n\n        connectors.enter().append('g')\n            .classed('line', true);\n\n        connectors.exit().remove();\n\n        var len = connectors.size();\n\n        connectors.each(function(di, i) {\n            // don't draw lines between nulls\n            if(i !== len - 1 && !di.cNext) return;\n\n            var xy = getXY(di, xa, ya, isHorizontal);\n            var x = xy[0];\n            var y = xy[1];\n\n            var shape = '';\n\n            if(x[3] !== undefined && y[3] !== undefined) {\n                if(isHorizontal) {\n                    shape += 'M' + x[0] + ',' + y[1] + 'L' + x[2] + ',' + y[2];\n                    shape += 'M' + x[1] + ',' + y[1] + 'L' + x[3] + ',' + y[2];\n                } else {\n                    shape += 'M' + x[1] + ',' + y[1] + 'L' + x[2] + ',' + y[3];\n                    shape += 'M' + x[1] + ',' + y[0] + 'L' + x[2] + ',' + y[2];\n                }\n            }\n\n            if(shape === '') shape = 'M0,0Z';\n\n            Lib.ensureSingle(d3.select(this), 'path')\n                .attr('d', shape)\n                .call(Drawing.setClipUrl, plotinfo.layerClipId, gd);\n        });\n    });\n}\n\nfunction getXY(di, xa, ya, isHorizontal) {\n    var s = [];\n    var p = [];\n\n    var sAxis = isHorizontal ? xa : ya;\n    var pAxis = isHorizontal ? ya : xa;\n\n    s[0] = sAxis.c2p(di.s0, true);\n    p[0] = pAxis.c2p(di.p0, true);\n\n    s[1] = sAxis.c2p(di.s1, true);\n    p[1] = pAxis.c2p(di.p1, true);\n\n    s[2] = sAxis.c2p(di.nextS0, true);\n    p[2] = pAxis.c2p(di.nextP0, true);\n\n    s[3] = sAxis.c2p(di.nextS1, true);\n    p[3] = pAxis.c2p(di.nextP1, true);\n\n    return isHorizontal ? [s, p] : [p, s];\n}\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../bar/plot\":867,\"d3\":163}],991:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Drawing = _dereq_('../../components/drawing');\nvar Color = _dereq_('../../components/color');\nvar DESELECTDIM = _dereq_('../../constants/interactions').DESELECTDIM;\n\nvar styleTextPoints = _dereq_('../bar/style').styleTextPoints;\n\nfunction style(gd, cd, sel) {\n    var s = sel ? sel : d3.select(gd).selectAll('g.funnellayer').selectAll('g.trace');\n\n    s.style('opacity', function(d) { return d[0].trace.opacity; });\n\n    s.each(function(d) {\n        var gTrace = d3.select(this);\n        var trace = d[0].trace;\n\n        gTrace.selectAll('.point > path').each(function(di) {\n            if(!di.isBlank) {\n                var cont = trace.marker;\n\n                d3.select(this)\n                    .call(Color.fill, di.mc || cont.color)\n                    .call(Color.stroke, di.mlc || cont.line.color)\n                    .call(Drawing.dashLine, cont.line.dash, di.mlw || cont.line.width)\n                    .style('opacity', trace.selectedpoints && !di.selected ? DESELECTDIM : 1);\n            }\n        });\n\n        styleTextPoints(gTrace, trace, gd);\n\n        gTrace.selectAll('.regions').each(function() {\n            d3.select(this).selectAll('path').style('stroke-width', 0).call(Color.fill, trace.connector.fillcolor);\n        });\n\n        gTrace.selectAll('.lines').each(function() {\n            var cont = trace.connector.line;\n\n            Drawing.lineGroupStyle(\n                d3.select(this).selectAll('path'),\n                cont.width,\n                cont.color,\n                cont.dash\n            );\n        });\n    });\n}\n\nmodule.exports = {\n    style: style\n};\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../constants/interactions\":694,\"../bar/style\":870,\"d3\":163}],992:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar pieAttrs = _dereq_('../pie/attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = {\n    labels: pieAttrs.labels,\n    // equivalent of x0 and dx, if label is missing\n    label0: pieAttrs.label0,\n    dlabel: pieAttrs.dlabel,\n    values: pieAttrs.values,\n\n    marker: {\n        colors: pieAttrs.marker.colors,\n        line: {\n            color: extendFlat({}, pieAttrs.marker.line.color, {\n                dflt: null,\n                \n            }),\n            width: extendFlat({}, pieAttrs.marker.line.width, {dflt: 1}),\n            editType: 'calc'\n        },\n        editType: 'calc'\n    },\n\n    text: pieAttrs.text,\n    hovertext: pieAttrs.hovertext,\n\n    scalegroup: extendFlat({}, pieAttrs.scalegroup, {\n        \n    }),\n\n    textinfo: extendFlat({}, pieAttrs.textinfo, {\n        flags: ['label', 'text', 'value', 'percent']\n    }),\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['label', 'text', 'value', 'percent', 'name']\n    }),\n\n    hovertemplate: hovertemplateAttrs({}, {\n        keys: ['label', 'color', 'value', 'percent', 'text']\n    }),\n\n    textposition: extendFlat({}, pieAttrs.textposition, {\n        values: ['inside', 'none'],\n        dflt: 'inside'\n    }),\n\n    textfont: pieAttrs.textfont,\n    insidetextfont: pieAttrs.insidetextfont,\n\n    title: {\n        text: pieAttrs.title.text,\n        font: pieAttrs.title.font,\n        position: extendFlat({}, pieAttrs.title.position, {\n            values: ['top left', 'top center', 'top right'],\n            dflt: 'top center'\n        }),\n        editType: 'plot'\n    },\n\n    domain: domainAttrs({name: 'funnelarea', trace: true, editType: 'calc'}),\n\n    aspectratio: {\n        valType: 'number',\n        \n        min: 0,\n        dflt: 1,\n        editType: 'plot',\n        \n    },\n\n    baseratio: {\n        valType: 'number',\n        \n        min: 0,\n        max: 1,\n        dflt: 0.333,\n        editType: 'plot',\n        \n    }\n};\n\n},{\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../../plots/domain\":792,\"../pie/attributes\":1086}],993:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\n\nexports.name = 'funnelarea';\n\nexports.plot = function(gd) {\n    var Funnelarea = Registry.getModule('funnelarea');\n    var cdFunnelarea = getModuleCalcData(gd.calcdata, Funnelarea)[0];\n    Funnelarea.plot(gd, cdFunnelarea);\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var hadFunnelarea = (oldFullLayout._has && oldFullLayout._has('funnelarea'));\n    var hasFunnelarea = (newFullLayout._has && newFullLayout._has('funnelarea'));\n\n    if(hadFunnelarea && !hasFunnelarea) {\n        oldFullLayout._funnelarealayer.selectAll('g.trace').remove();\n    }\n};\n\n},{\"../../plots/get_data\":802,\"../../registry\":847}],994:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar pieCalc = _dereq_('../pie/calc');\n\nfunction calc(gd, trace) {\n    return pieCalc.calc(gd, trace);\n}\n\nfunction crossTraceCalc(gd) {\n    pieCalc.crossTraceCalc(gd, { type: 'funnelarea' });\n}\n\nmodule.exports = {\n    calc: calc,\n    crossTraceCalc: crossTraceCalc\n};\n\n},{\"../pie/calc\":1088}],995:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attributes = _dereq_('./attributes');\nvar handleDomainDefaults = _dereq_('../../plots/domain').defaults;\nvar handleText = _dereq_('../bar/defaults').handleText;\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len;\n    var vals = coerce('values');\n    var hasVals = Lib.isArrayOrTypedArray(vals);\n    var labels = coerce('labels');\n    if(Array.isArray(labels)) {\n        len = labels.length;\n        if(hasVals) len = Math.min(len, vals.length);\n    } else if(hasVals) {\n        len = vals.length;\n\n        coerce('label0');\n        coerce('dlabel');\n    }\n\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n    traceOut._length = len;\n\n    var lineWidth = coerce('marker.line.width');\n    if(lineWidth) coerce('marker.line.color', layout.paper_bgcolor);\n\n    coerce('marker.colors');\n\n    coerce('scalegroup');\n\n    var textData = coerce('text');\n    var textInfo = coerce('textinfo', Array.isArray(textData) ? 'text+percent' : 'percent');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    if(textInfo && textInfo !== 'none') {\n        var textposition = coerce('textposition');\n        handleText(traceIn, traceOut, layout, coerce, textposition, {\n            moduleHasSelected: false,\n            moduleHasUnselected: false,\n            moduleHasConstrain: false,\n            moduleHasCliponaxis: false,\n            moduleHasTextangle: false,\n            moduleHasInsideanchor: false\n        });\n    }\n\n    handleDomainDefaults(traceOut, layout, coerce);\n\n    var title = coerce('title.text');\n    if(title) {\n        coerce('title.position');\n        Lib.coerceFont(coerce, 'title.font', layout.font);\n    }\n\n    coerce('aspectratio');\n    coerce('baseratio');\n};\n\n},{\"../../lib\":719,\"../../plots/domain\":792,\"../bar/defaults\":861,\"./attributes\":992}],996:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'funnelarea',\n    basePlotModule: _dereq_('./base_plot'),\n    categories: ['pie-like', 'funnelarea', 'showLegend'],\n\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n\n    calc: _dereq_('./calc').calc,\n    crossTraceCalc: _dereq_('./calc').crossTraceCalc,\n\n    plot: _dereq_('./plot'),\n    style: _dereq_('./style'),\n    styleOne: _dereq_('../pie/style_one'),\n\n    meta: {\n        \n    }\n};\n\n},{\"../pie/style_one\":1097,\"./attributes\":992,\"./base_plot\":993,\"./calc\":994,\"./defaults\":995,\"./layout_attributes\":997,\"./layout_defaults\":998,\"./plot\":999,\"./style\":1000}],997:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hiddenlabels = _dereq_('../pie/layout_attributes').hiddenlabels;\n\nmodule.exports = {\n    hiddenlabels: hiddenlabels,\n\n    funnelareacolorway: {\n        valType: 'colorlist',\n        \n        editType: 'calc',\n        \n    },\n    extendfunnelareacolors: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        \n    }\n};\n\n},{\"../pie/layout_attributes\":1093}],998:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n\n    coerce('hiddenlabels');\n    coerce('funnelareacolorway', layoutOut.colorway);\n    coerce('extendfunnelareacolors');\n};\n\n},{\"../../lib\":719,\"./layout_attributes\":997}],999:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Drawing = _dereq_('../../components/drawing');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\n\nvar barPlot = _dereq_('../bar/plot');\nvar getTransformToMoveInsideBar = barPlot.getTransformToMoveInsideBar;\n\nvar pieHelpers = _dereq_('../pie/helpers');\nvar piePlot = _dereq_('../pie/plot');\n\nvar attachFxHandlers = piePlot.attachFxHandlers;\nvar determineInsideTextFont = piePlot.determineInsideTextFont;\n\nvar layoutAreas = piePlot.layoutAreas;\nvar prerenderTitles = piePlot.prerenderTitles;\nvar positionTitleOutside = piePlot.positionTitleOutside;\n\nmodule.exports = function plot(gd, cdModule) {\n    var fullLayout = gd._fullLayout;\n\n    prerenderTitles(cdModule, gd);\n    layoutAreas(cdModule, fullLayout._size);\n\n    Lib.makeTraceGroups(fullLayout._funnelarealayer, cdModule, 'trace').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n\n        setCoords(cd);\n\n        plotGroup.each(function() {\n            var slices = d3.select(this).selectAll('g.slice').data(cd);\n\n            slices.enter().append('g')\n                .classed('slice', true);\n            slices.exit().remove();\n\n            slices.each(function(pt) {\n                if(pt.hidden) {\n                    d3.select(this).selectAll('path,g').remove();\n                    return;\n                }\n\n                // to have consistent event data compared to other traces\n                pt.pointNumber = pt.i;\n                pt.curveNumber = trace.index;\n\n                var cx = cd0.cx;\n                var cy = cd0.cy;\n                var sliceTop = d3.select(this);\n                var slicePath = sliceTop.selectAll('path.surface').data([pt]);\n\n                slicePath.enter().append('path')\n                    .classed('surface', true)\n                    .style({'pointer-events': 'all'});\n\n                sliceTop.call(attachFxHandlers, gd, cd);\n\n                var shape =\n                    'M' + (cx + pt.TR[0]) + ',' + (cy + pt.TR[1]) +\n                    line(pt.TR, pt.BR) +\n                    line(pt.BR, pt.BL) +\n                    line(pt.BL, pt.TL) +\n                    'Z';\n\n                slicePath.attr('d', shape);\n\n                // add text\n                var textPosition = pieHelpers.castOption(trace.textposition, pt.pts);\n                var sliceTextGroup = sliceTop.selectAll('g.slicetext')\n                    .data(pt.text && (textPosition !== 'none') ? [0] : []);\n\n                sliceTextGroup.enter().append('g')\n                    .classed('slicetext', true);\n                sliceTextGroup.exit().remove();\n\n                sliceTextGroup.each(function() {\n                    var sliceText = Lib.ensureSingle(d3.select(this), 'text', '', function(s) {\n                        // prohibit tex interpretation until we can handle\n                        // tex and regular text together\n                        s.attr('data-notex', 1);\n                    });\n\n                    sliceText.text(pt.text)\n                        .attr({\n                            'class': 'slicetext',\n                            transform: '',\n                            'text-anchor': 'middle'\n                        })\n                        .call(Drawing.font, determineInsideTextFont(trace, pt, gd._fullLayout.font))\n                        .call(svgTextUtils.convertToTspans, gd);\n\n                    // position the text relative to the slice\n                    var textBB = Drawing.bBox(sliceText.node());\n                    var transform;\n\n                    var x0, x1;\n                    var y0 = Math.min(pt.BL[1], pt.BR[1]);\n                    var y1 = Math.max(pt.TL[1], pt.TR[1]);\n\n                    x0 = Math.max(pt.TL[0], pt.BL[0]);\n                    x1 = Math.min(pt.TR[0], pt.BR[0]);\n\n                    transform = getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, {\n                        isHorizontal: true,\n                        constrained: true,\n                        angle: 0,\n                        anchor: 'middle'\n                    });\n\n                    sliceText.attr('transform',\n                        'translate(' + cx + ',' + cy + ')' + transform\n                    );\n                });\n            });\n\n            // add the title\n            var titleTextGroup = d3.select(this).selectAll('g.titletext')\n                .data(trace.title.text ? [0] : []);\n\n            titleTextGroup.enter().append('g')\n                .classed('titletext', true);\n            titleTextGroup.exit().remove();\n\n            titleTextGroup.each(function() {\n                var titleText = Lib.ensureSingle(d3.select(this), 'text', '', function(s) {\n                    // prohibit tex interpretation as above\n                    s.attr('data-notex', 1);\n                });\n\n                var txt = trace.title.text;\n                if(trace._meta) {\n                    txt = Lib.templateString(txt, trace._meta);\n                }\n\n                titleText.text(txt)\n                    .attr({\n                        'class': 'titletext',\n                        transform: '',\n                        'text-anchor': 'middle',\n                    })\n                .call(Drawing.font, trace.title.font)\n                .call(svgTextUtils.convertToTspans, gd);\n\n                var transform = positionTitleOutside(cd0, fullLayout._size);\n\n                titleText.attr('transform',\n                    'translate(' + transform.x + ',' + transform.y + ')' +\n                    (transform.scale < 1 ? ('scale(' + transform.scale + ')') : '') +\n                    'translate(' + transform.tx + ',' + transform.ty + ')');\n            });\n        });\n    });\n};\n\nfunction line(a, b) {\n    var dx = b[0] - a[0];\n    var dy = b[1] - a[1];\n\n    return 'l' + dx + ',' + dy;\n}\n\nfunction getBetween(a, b) {\n    return [\n        0.5 * (a[0] + b[0]),\n        0.5 * (a[1] + b[1])\n    ];\n}\n\nfunction setCoords(cd) {\n    if(!cd.length) return;\n\n    var cd0 = cd[0];\n    var trace = cd0.trace;\n\n    var aspectratio = trace.aspectratio;\n\n    var h = trace.baseratio;\n    if(h > 0.999) h = 0.999; // TODO: may handle this case separately\n    var h2 = Math.pow(h, 2);\n\n    var v1 = cd0.vTotal;\n    var v0 = v1 * h2 / (1 - h2);\n\n    var totalValues = v1;\n    var sumSteps = v0 / v1;\n\n    function calcPos() {\n        var q = Math.sqrt(sumSteps);\n        return {\n            x: q,\n            y: -q\n        };\n    }\n\n    function getPoint() {\n        var pos = calcPos();\n        return [pos.x, pos.y];\n    }\n\n    var p;\n    var allPoints = [];\n    allPoints.push(getPoint());\n\n    var i, cdi;\n    for(i = cd.length - 1; i > -1; i--) {\n        cdi = cd[i];\n        if(cdi.hidden) continue;\n\n        var step = cdi.v / totalValues;\n        sumSteps += step;\n\n        allPoints.push(getPoint());\n    }\n\n    var minY = Infinity;\n    var maxY = -Infinity;\n    for(i = 0; i < allPoints.length; i++) {\n        p = allPoints[i];\n        minY = Math.min(minY, p[1]);\n        maxY = Math.max(maxY, p[1]);\n    }\n\n    // center the shape\n    for(i = 0; i < allPoints.length; i++) {\n        allPoints[i][1] -= (maxY + minY) / 2;\n    }\n\n    var lastX = allPoints[allPoints.length - 1][0];\n\n    // get pie r\n    var r = cd0.r;\n\n    var rY = (maxY - minY) / 2;\n    var scaleX = r / lastX;\n    var scaleY = r / rY * aspectratio;\n\n    // set funnelarea r\n    cd0.r = scaleY * rY;\n\n    // scale the shape\n    for(i = 0; i < allPoints.length; i++) {\n        allPoints[i][0] *= scaleX;\n        allPoints[i][1] *= scaleY;\n    }\n\n    // record first position\n    p = allPoints[0];\n    var prevLeft = [-p[0], p[1]];\n    var prevRight = [p[0], p[1]];\n\n    var n = 0; // note we skip the very first point.\n    for(i = cd.length - 1; i > -1; i--) {\n        cdi = cd[i];\n        if(cdi.hidden) continue;\n\n        n += 1;\n        var x = allPoints[n][0];\n        var y = allPoints[n][1];\n\n        cdi.TL = [-x, y];\n        cdi.TR = [x, y];\n\n        cdi.BL = prevLeft;\n        cdi.BR = prevRight;\n\n        cdi.pxmid = getBetween(cdi.TR, cdi.BR);\n\n        prevLeft = cdi.TL;\n        prevRight = cdi.TR;\n    }\n}\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../bar/plot\":867,\"../pie/helpers\":1091,\"../pie/plot\":1095,\"d3\":163}],1000:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar styleOne = _dereq_('../pie/style_one');\n\nmodule.exports = function style(gd) {\n    gd._fullLayout._funnelarealayer.selectAll('.trace').each(function(cd) {\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n        var traceSelection = d3.select(this);\n\n        traceSelection.style({opacity: trace.opacity});\n\n        traceSelection.selectAll('path.surface').each(function(pt) {\n            d3.select(this).call(styleOne, pt, trace);\n        });\n    });\n};\n\n},{\"../pie/style_one\":1097,\"d3\":163}],1001:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar FORMAT_LINK = _dereq_('../../constants/docs').FORMAT_LINK;\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = extendFlat({\n    z: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    x: extendFlat({}, scatterAttrs.x, {impliedEdits: {xtype: 'array'}}),\n    x0: extendFlat({}, scatterAttrs.x0, {impliedEdits: {xtype: 'scaled'}}),\n    dx: extendFlat({}, scatterAttrs.dx, {impliedEdits: {xtype: 'scaled'}}),\n    y: extendFlat({}, scatterAttrs.y, {impliedEdits: {ytype: 'array'}}),\n    y0: extendFlat({}, scatterAttrs.y0, {impliedEdits: {ytype: 'scaled'}}),\n    dy: extendFlat({}, scatterAttrs.dy, {impliedEdits: {ytype: 'scaled'}}),\n\n    text: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    hovertext: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    transpose: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    xtype: {\n        valType: 'enumerated',\n        values: ['array', 'scaled'],\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    ytype: {\n        valType: 'enumerated',\n        values: ['array', 'scaled'],\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    zsmooth: {\n        valType: 'enumerated',\n        values: ['fast', 'best', false],\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    connectgaps: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    xgap: {\n        valType: 'number',\n        dflt: 0,\n        min: 0,\n        \n        editType: 'plot',\n        \n    },\n    ygap: {\n        valType: 'number',\n        dflt: 0,\n        min: 0,\n        \n        editType: 'plot',\n        \n    },\n    zhoverformat: {\n        valType: 'string',\n        dflt: '',\n        \n        editType: 'none',\n        \n    },\n    hovertemplate: hovertemplateAttrs()\n}, {\n    transforms: undefined\n},\n    colorScaleAttrs('', {cLetter: 'z', autoColorDflt: false})\n);\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../constants/docs\":690,\"../../lib/extend\":710,\"../scatter/attributes\":1112}],1002:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nvar histogram2dCalc = _dereq_('../histogram2d/calc');\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\nvar convertColumnData = _dereq_('./convert_column_xyz');\nvar clean2dArray = _dereq_('./clean_2d_array');\nvar interp2d = _dereq_('./interp2d');\nvar findEmpties = _dereq_('./find_empties');\nvar makeBoundArray = _dereq_('./make_bound_array');\n\nmodule.exports = function calc(gd, trace) {\n    // prepare the raw data\n    // run makeCalcdata on x and y even for heatmaps, in case of category mappings\n    var xa = Axes.getFromId(gd, trace.xaxis || 'x');\n    var ya = Axes.getFromId(gd, trace.yaxis || 'y');\n    var isContour = Registry.traceIs(trace, 'contour');\n    var isHist = Registry.traceIs(trace, 'histogram');\n    var isGL2D = Registry.traceIs(trace, 'gl2d');\n    var zsmooth = isContour ? 'best' : trace.zsmooth;\n    var x;\n    var x0;\n    var dx;\n    var y;\n    var y0;\n    var dy;\n    var z;\n    var i;\n    var binned;\n\n    // cancel minimum tick spacings (only applies to bars and boxes)\n    xa._minDtick = 0;\n    ya._minDtick = 0;\n\n    if(isHist) {\n        binned = histogram2dCalc(gd, trace);\n        x = binned.x;\n        x0 = binned.x0;\n        dx = binned.dx;\n        y = binned.y;\n        y0 = binned.y0;\n        dy = binned.dy;\n        z = binned.z;\n    } else {\n        var zIn = trace.z;\n        if(Lib.isArray1D(zIn)) {\n            convertColumnData(trace, xa, ya, 'x', 'y', ['z']);\n            x = trace._x;\n            y = trace._y;\n            zIn = trace._z;\n        } else {\n            x = trace._x = trace.x ? xa.makeCalcdata(trace, 'x') : [];\n            y = trace._y = trace.y ? ya.makeCalcdata(trace, 'y') : [];\n        }\n\n        x0 = trace.x0;\n        dx = trace.dx;\n        y0 = trace.y0;\n        dy = trace.dy;\n\n        z = clean2dArray(zIn, trace, xa, ya);\n\n        if(isContour || trace.connectgaps) {\n            trace._emptypoints = findEmpties(z);\n            interp2d(z, trace._emptypoints);\n        }\n    }\n\n    function noZsmooth(msg) {\n        zsmooth = trace._input.zsmooth = trace.zsmooth = false;\n        Lib.warn('cannot use zsmooth: \"fast\": ' + msg);\n    }\n\n    // check whether we really can smooth (ie all boxes are about the same size)\n    if(zsmooth === 'fast') {\n        if(xa.type === 'log' || ya.type === 'log') {\n            noZsmooth('log axis found');\n        } else if(!isHist) {\n            if(x.length) {\n                var avgdx = (x[x.length - 1] - x[0]) / (x.length - 1);\n                var maxErrX = Math.abs(avgdx / 100);\n                for(i = 0; i < x.length - 1; i++) {\n                    if(Math.abs(x[i + 1] - x[i] - avgdx) > maxErrX) {\n                        noZsmooth('x scale is not linear');\n                        break;\n                    }\n                }\n            }\n            if(y.length && zsmooth === 'fast') {\n                var avgdy = (y[y.length - 1] - y[0]) / (y.length - 1);\n                var maxErrY = Math.abs(avgdy / 100);\n                for(i = 0; i < y.length - 1; i++) {\n                    if(Math.abs(y[i + 1] - y[i] - avgdy) > maxErrY) {\n                        noZsmooth('y scale is not linear');\n                        break;\n                    }\n                }\n            }\n        }\n    }\n\n    // create arrays of brick boundaries, to be used by autorange and heatmap.plot\n    var xlen = Lib.maxRowLength(z);\n    var xIn = trace.xtype === 'scaled' ? '' : x;\n    var xArray = makeBoundArray(trace, xIn, x0, dx, xlen, xa);\n    var yIn = trace.ytype === 'scaled' ? '' : y;\n    var yArray = makeBoundArray(trace, yIn, y0, dy, z.length, ya);\n\n    // handled in gl2d convert step\n    if(!isGL2D) {\n        trace._extremes[xa._id] = Axes.findExtremes(xa, xArray);\n        trace._extremes[ya._id] = Axes.findExtremes(ya, yArray);\n    }\n\n    var cd0 = {\n        x: xArray,\n        y: yArray,\n        z: z,\n        text: trace._text || trace.text,\n        hovertext: trace._hovertext || trace.hovertext\n    };\n\n    if(xIn && xIn.length === xArray.length - 1) cd0.xCenter = xIn;\n    if(yIn && yIn.length === yArray.length - 1) cd0.yCenter = yIn;\n\n    if(isHist) {\n        cd0.xRanges = binned.xRanges;\n        cd0.yRanges = binned.yRanges;\n        cd0.pts = binned.pts;\n    }\n\n    if(!isContour) {\n        colorscaleCalc(gd, trace, {vals: z, cLetter: 'z'});\n    }\n\n    if(isContour && trace.contours && trace.contours.coloring === 'heatmap') {\n        var dummyTrace = {\n            type: trace.type === 'contour' ? 'heatmap' : 'histogram2d',\n            xcalendar: trace.xcalendar,\n            ycalendar: trace.ycalendar\n        };\n        cd0.xfill = makeBoundArray(dummyTrace, xIn, x0, dx, xlen, xa);\n        cd0.yfill = makeBoundArray(dummyTrace, yIn, y0, dy, z.length, ya);\n    }\n\n    return [cd0];\n};\n\n},{\"../../components/colorscale/calc\":601,\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"../histogram2d/calc\":1033,\"./clean_2d_array\":1003,\"./convert_column_xyz\":1005,\"./find_empties\":1007,\"./interp2d\":1010,\"./make_bound_array\":1011}],1003:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar Lib = _dereq_('../../lib');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function clean2dArray(zOld, trace, xa, ya) {\n    var rowlen, collen, getCollen, old2new, i, j;\n\n    function cleanZvalue(v) {\n        if(!isNumeric(v)) return undefined;\n        return +v;\n    }\n\n    if(trace && trace.transpose) {\n        rowlen = 0;\n        for(i = 0; i < zOld.length; i++) rowlen = Math.max(rowlen, zOld[i].length);\n        if(rowlen === 0) return false;\n        getCollen = function(zOld) { return zOld.length; };\n        old2new = function(zOld, i, j) { return (zOld[j] || [])[i]; };\n    } else {\n        rowlen = zOld.length;\n        getCollen = function(zOld, i) { return zOld[i].length; };\n        old2new = function(zOld, i, j) { return (zOld[i] || [])[j]; };\n    }\n\n    var padOld2new = function(zOld, i, j) {\n        if(i === BADNUM || j === BADNUM) return BADNUM;\n        return old2new(zOld, i, j);\n    };\n\n    function axisMapping(ax) {\n        if(trace && trace.type !== 'carpet' && trace.type !== 'contourcarpet' &&\n            ax && ax.type === 'category' && trace['_' + ax._id.charAt(0)].length) {\n            var axLetter = ax._id.charAt(0);\n            var axMapping = {};\n            var traceCategories = trace['_' + axLetter + 'CategoryMap'] || trace[axLetter];\n            for(i = 0; i < traceCategories.length; i++) {\n                axMapping[traceCategories[i]] = i;\n            }\n            return function(i) {\n                var ind = axMapping[ax._categories[i]];\n                return ind + 1 ? ind : BADNUM;\n            };\n        } else {\n            return Lib.identity;\n        }\n    }\n\n    var xMap = axisMapping(xa);\n    var yMap = axisMapping(ya);\n\n    if(ya && ya.type === 'category') rowlen = ya._categories.length;\n    var zNew = new Array(rowlen);\n\n    for(i = 0; i < rowlen; i++) {\n        if(xa && xa.type === 'category') {\n            collen = xa._categories.length;\n        } else {\n            collen = getCollen(zOld, i);\n        }\n        zNew[i] = new Array(collen);\n        for(j = 0; j < collen; j++) zNew[i][j] = cleanZvalue(padOld2new(zOld, yMap(i), xMap(j)));\n    }\n\n    return zNew;\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"fast-isnumeric\":225}],1004:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    min: 'zmin',\n    max: 'zmax'\n};\n\n},{}],1005:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name, arrayVarNames) {\n    var colLen = trace._length;\n    var col1 = ax1.makeCalcdata(trace, var1Name);\n    var col2 = ax2.makeCalcdata(trace, var2Name);\n    var textCol = trace.text;\n    var hasColumnText = (textCol !== undefined && Lib.isArray1D(textCol));\n    var hoverTextCol = trace.hovertext;\n    var hasColumnHoverText = (hoverTextCol !== undefined && Lib.isArray1D(hoverTextCol));\n    var i, j;\n\n    var col1dv = Lib.distinctVals(col1);\n    var col1vals = col1dv.vals;\n    var col2dv = Lib.distinctVals(col2);\n    var col2vals = col2dv.vals;\n    var newArrays = [];\n    var text;\n    var hovertext;\n\n    for(i = 0; i < arrayVarNames.length; i++) {\n        newArrays[i] = Lib.init2dArray(col2vals.length, col1vals.length);\n    }\n\n    if(hasColumnText) {\n        text = Lib.init2dArray(col2vals.length, col1vals.length);\n    }\n    if(hasColumnHoverText) {\n        hovertext = Lib.init2dArray(col2vals.length, col1vals.length);\n    }\n\n    for(i = 0; i < colLen; i++) {\n        if(col1[i] !== BADNUM && col2[i] !== BADNUM) {\n            var i1 = Lib.findBin(col1[i] + col1dv.minDiff / 2, col1vals);\n            var i2 = Lib.findBin(col2[i] + col2dv.minDiff / 2, col2vals);\n\n            for(j = 0; j < arrayVarNames.length; j++) {\n                var arrayVarName = arrayVarNames[j];\n                var arrayVar = trace[arrayVarName];\n                var newArray = newArrays[j];\n                newArray[i2][i1] = arrayVar[i];\n            }\n\n            if(hasColumnText) text[i2][i1] = textCol[i];\n            if(hasColumnHoverText) hovertext[i2][i1] = hoverTextCol[i];\n        }\n    }\n\n    trace['_' + var1Name] = col1vals;\n    trace['_' + var2Name] = col2vals;\n    for(j = 0; j < arrayVarNames.length; j++) {\n        trace['_' + arrayVarNames[j]] = newArrays[j];\n    }\n    if(hasColumnText) trace._text = text;\n    if(hasColumnHoverText) trace._hovertext = hovertext;\n\n    if(ax1 && ax1.type === 'category') {\n        trace['_' + var1Name + 'CategoryMap'] = col1vals.map(function(v) { return ax1._categories[v];});\n    }\n\n    if(ax2 && ax2.type === 'category') {\n        trace['_' + var2Name + 'CategoryMap'] = col2vals.map(function(v) { return ax2._categories[v];});\n    }\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719}],1006:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleXYZDefaults = _dereq_('./xyz_defaults');\nvar handleStyleDefaults = _dereq_('./style_defaults');\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var validData = handleXYZDefaults(traceIn, traceOut, coerce, layout);\n    if(!validData) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    handleStyleDefaults(traceIn, traceOut, coerce, layout);\n\n    coerce('connectgaps', Lib.isArray1D(traceOut.z) && (traceOut.zsmooth !== false));\n\n    colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"./attributes\":1001,\"./style_defaults\":1014,\"./xyz_defaults\":1015}],1007:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar maxRowLength = _dereq_('../../lib').maxRowLength;\n\n/* Return a list of empty points in 2D array z\n * each empty point z[i][j] gives an array [i, j, neighborCount]\n * neighborCount is the count of 4 nearest neighbors that DO exist\n * this is to give us an order of points to evaluate for interpolation.\n * if no neighbors exist, we iteratively look for neighbors that HAVE\n * neighbors, and add a fractional neighborCount\n */\nmodule.exports = function findEmpties(z) {\n    var empties = [];\n    var neighborHash = {};\n    var noNeighborList = [];\n    var nextRow = z[0];\n    var row = [];\n    var blank = [0, 0, 0];\n    var rowLength = maxRowLength(z);\n    var prevRow;\n    var i;\n    var j;\n    var thisPt;\n    var p;\n    var neighborCount;\n    var newNeighborHash;\n    var foundNewNeighbors;\n\n    for(i = 0; i < z.length; i++) {\n        prevRow = row;\n        row = nextRow;\n        nextRow = z[i + 1] || [];\n        for(j = 0; j < rowLength; j++) {\n            if(row[j] === undefined) {\n                neighborCount = (row[j - 1] !== undefined ? 1 : 0) +\n                    (row[j + 1] !== undefined ? 1 : 0) +\n                    (prevRow[j] !== undefined ? 1 : 0) +\n                    (nextRow[j] !== undefined ? 1 : 0);\n\n                if(neighborCount) {\n                    // for this purpose, don't count off-the-edge points\n                    // as undefined neighbors\n                    if(i === 0) neighborCount++;\n                    if(j === 0) neighborCount++;\n                    if(i === z.length - 1) neighborCount++;\n                    if(j === row.length - 1) neighborCount++;\n\n                    // if all neighbors that could exist do, we don't\n                    // need this for finding farther neighbors\n                    if(neighborCount < 4) {\n                        neighborHash[[i, j]] = [i, j, neighborCount];\n                    }\n\n                    empties.push([i, j, neighborCount]);\n                } else noNeighborList.push([i, j]);\n            }\n        }\n    }\n\n    while(noNeighborList.length) {\n        newNeighborHash = {};\n        foundNewNeighbors = false;\n\n        // look for cells that now have neighbors but didn't before\n        for(p = noNeighborList.length - 1; p >= 0; p--) {\n            thisPt = noNeighborList[p];\n            i = thisPt[0];\n            j = thisPt[1];\n\n            neighborCount = ((neighborHash[[i - 1, j]] || blank)[2] +\n                (neighborHash[[i + 1, j]] || blank)[2] +\n                (neighborHash[[i, j - 1]] || blank)[2] +\n                (neighborHash[[i, j + 1]] || blank)[2]) / 20;\n\n            if(neighborCount) {\n                newNeighborHash[thisPt] = [i, j, neighborCount];\n                noNeighborList.splice(p, 1);\n                foundNewNeighbors = true;\n            }\n        }\n\n        if(!foundNewNeighbors) {\n            throw 'findEmpties iterated with no new neighbors';\n        }\n\n        // put these new cells into the main neighbor list\n        for(thisPt in newNeighborHash) {\n            neighborHash[thisPt] = newNeighborHash[thisPt];\n            empties.push(newNeighborHash[thisPt]);\n        }\n    }\n\n    // sort the full list in descending order of neighbor count\n    return empties.sort(function(a, b) { return b[2] - a[2]; });\n};\n\n},{\"../../lib\":719}],1008:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Fx = _dereq_('../../components/fx');\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar extractOpts = _dereq_('../../components/colorscale').extractOpts;\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer, contour) {\n    var cd0 = pointData.cd[0];\n    var trace = cd0.trace;\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var x = cd0.x;\n    var y = cd0.y;\n    var z = cd0.z;\n    var xc = cd0.xCenter;\n    var yc = cd0.yCenter;\n    var zmask = cd0.zmask;\n    var zhoverformat = trace.zhoverformat;\n    var x2 = x;\n    var y2 = y;\n\n    var xl, yl, nx, ny;\n\n    if(pointData.index !== false) {\n        try {\n            nx = Math.round(pointData.index[1]);\n            ny = Math.round(pointData.index[0]);\n        } catch(e) {\n            Lib.error('Error hovering on heatmap, ' +\n                'pointNumber must be [row,col], found:', pointData.index);\n            return;\n        }\n        if(nx < 0 || nx >= z[0].length || ny < 0 || ny > z.length) {\n            return;\n        }\n    } else if(Fx.inbox(xval - x[0], xval - x[x.length - 1], 0) > 0 ||\n            Fx.inbox(yval - y[0], yval - y[y.length - 1], 0) > 0) {\n        return;\n    } else {\n        if(contour) {\n            var i2;\n            x2 = [2 * x[0] - x[1]];\n\n            for(i2 = 1; i2 < x.length; i2++) {\n                x2.push((x[i2] + x[i2 - 1]) / 2);\n            }\n            x2.push([2 * x[x.length - 1] - x[x.length - 2]]);\n\n            y2 = [2 * y[0] - y[1]];\n            for(i2 = 1; i2 < y.length; i2++) {\n                y2.push((y[i2] + y[i2 - 1]) / 2);\n            }\n            y2.push([2 * y[y.length - 1] - y[y.length - 2]]);\n        }\n        nx = Math.max(0, Math.min(x2.length - 2, Lib.findBin(xval, x2)));\n        ny = Math.max(0, Math.min(y2.length - 2, Lib.findBin(yval, y2)));\n    }\n\n    var x0 = xa.c2p(x[nx]);\n    var x1 = xa.c2p(x[nx + 1]);\n    var y0 = ya.c2p(y[ny]);\n    var y1 = ya.c2p(y[ny + 1]);\n\n    if(contour) {\n        x1 = x0;\n        xl = x[nx];\n        y1 = y0;\n        yl = y[ny];\n    } else {\n        xl = xc ? xc[nx] : ((x[nx] + x[nx + 1]) / 2);\n        yl = yc ? yc[ny] : ((y[ny] + y[ny + 1]) / 2);\n\n        if(xa && xa.type === 'category') xl = x[nx];\n        if(ya && ya.type === 'category') yl = y[ny];\n\n        if(trace.zsmooth) {\n            x0 = x1 = xa.c2p(xl);\n            y0 = y1 = ya.c2p(yl);\n        }\n    }\n\n    var zVal = z[ny][nx];\n    if(zmask && !zmask[ny][nx]) zVal = undefined;\n\n    var text;\n    if(Array.isArray(cd0.hovertext) && Array.isArray(cd0.hovertext[ny])) {\n        text = cd0.hovertext[ny][nx];\n    } else if(Array.isArray(cd0.text) && Array.isArray(cd0.text[ny])) {\n        text = cd0.text[ny][nx];\n    }\n\n    // dummy axis for formatting the z value\n    var cOpts = extractOpts(trace);\n    var dummyAx = {\n        type: 'linear',\n        range: [cOpts.min, cOpts.max],\n        hoverformat: zhoverformat,\n        _separators: xa._separators,\n        _numFormat: xa._numFormat\n    };\n    var zLabel = Axes.tickText(dummyAx, zVal, 'hover').text;\n\n    return [Lib.extendFlat(pointData, {\n        index: [ny, nx],\n        // never let a 2D override 1D type as closest point\n        distance: pointData.maxHoverDistance,\n        spikeDistance: pointData.maxSpikeDistance,\n        x0: x0,\n        x1: x1,\n        y0: y0,\n        y1: y1,\n        xLabelVal: xl,\n        yLabelVal: yl,\n        zLabelVal: zVal,\n        zLabel: zLabel,\n        text: text\n    })];\n};\n\n},{\"../../components/colorscale\":605,\"../../components/fx\":632,\"../../lib\":719,\"../../plots/cartesian/axes\":767}],1009:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    colorbar: _dereq_('./colorbar'),\n    style: _dereq_('./style'),\n    hoverPoints: _dereq_('./hover'),\n\n    moduleType: 'trace',\n    name: 'heatmap',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', '2dMap'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"./attributes\":1001,\"./calc\":1002,\"./colorbar\":1004,\"./defaults\":1006,\"./hover\":1008,\"./plot\":1012,\"./style\":1013}],1010:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar INTERPTHRESHOLD = 1e-2;\nvar NEIGHBORSHIFTS = [[-1, 0], [1, 0], [0, -1], [0, 1]];\n\nfunction correctionOvershoot(maxFractionalChange) {\n    // start with less overshoot, until we know it's converging,\n    // then ramp up the overshoot for faster convergence\n    return 0.5 - 0.25 * Math.min(1, maxFractionalChange * 0.5);\n}\n\n/*\n * interp2d: Fill in missing data from a 2D array using an iterative\n *   poisson equation solver with zero-derivative BC at edges.\n *   Amazingly, this just amounts to repeatedly averaging all the existing\n *   nearest neighbors, at least if we don't take x/y scaling into account,\n *   which is the right approach here where x and y may not even have the\n *   same units.\n *\n * @param {array of arrays} z\n *      The 2D array to fill in. Will be mutated here. Assumed to already be\n *      cleaned, so all entries are numbers except gaps, which are `undefined`.\n * @param {array of arrays} emptyPoints\n *      Each entry [i, j, neighborCount] for empty points z[i][j] and the number\n *      of neighbors that are *not* missing. Assumed to be sorted from most to\n *      least neighbors, as produced by heatmap/find_empties.\n */\nmodule.exports = function interp2d(z, emptyPoints) {\n    var maxFractionalChange = 1;\n    var i;\n\n    // one pass to fill in a starting value for all the empties\n    iterateInterp2d(z, emptyPoints);\n\n    // we're don't need to iterate lone empties - remove them\n    for(i = 0; i < emptyPoints.length; i++) {\n        if(emptyPoints[i][2] < 4) break;\n    }\n    // but don't remove these points from the original array,\n    // we'll use them for masking, so make a copy.\n    emptyPoints = emptyPoints.slice(i);\n\n    for(i = 0; i < 100 && maxFractionalChange > INTERPTHRESHOLD; i++) {\n        maxFractionalChange = iterateInterp2d(z, emptyPoints,\n            correctionOvershoot(maxFractionalChange));\n    }\n    if(maxFractionalChange > INTERPTHRESHOLD) {\n        Lib.log('interp2d didn\\'t converge quickly', maxFractionalChange);\n    }\n\n    return z;\n};\n\nfunction iterateInterp2d(z, emptyPoints, overshoot) {\n    var maxFractionalChange = 0;\n    var thisPt;\n    var i;\n    var j;\n    var p;\n    var q;\n    var neighborShift;\n    var neighborRow;\n    var neighborVal;\n    var neighborCount;\n    var neighborSum;\n    var initialVal;\n    var minNeighbor;\n    var maxNeighbor;\n\n    for(p = 0; p < emptyPoints.length; p++) {\n        thisPt = emptyPoints[p];\n        i = thisPt[0];\n        j = thisPt[1];\n        initialVal = z[i][j];\n        neighborSum = 0;\n        neighborCount = 0;\n\n        for(q = 0; q < 4; q++) {\n            neighborShift = NEIGHBORSHIFTS[q];\n            neighborRow = z[i + neighborShift[0]];\n            if(!neighborRow) continue;\n            neighborVal = neighborRow[j + neighborShift[1]];\n            if(neighborVal !== undefined) {\n                if(neighborSum === 0) {\n                    minNeighbor = maxNeighbor = neighborVal;\n                } else {\n                    minNeighbor = Math.min(minNeighbor, neighborVal);\n                    maxNeighbor = Math.max(maxNeighbor, neighborVal);\n                }\n                neighborCount++;\n                neighborSum += neighborVal;\n            }\n        }\n\n        if(neighborCount === 0) {\n            throw 'iterateInterp2d order is wrong: no defined neighbors';\n        }\n\n        // this is the laplace equation interpolation:\n        // each point is just the average of its neighbors\n        // note that this ignores differential x/y scaling\n        // which I think is the right approach, since we\n        // don't know what that scaling means\n        z[i][j] = neighborSum / neighborCount;\n\n        if(initialVal === undefined) {\n            if(neighborCount < 4) maxFractionalChange = 1;\n        } else {\n            // we can make large empty regions converge faster\n            // if we overshoot the change vs the previous value\n            z[i][j] = (1 + overshoot) * z[i][j] - overshoot * initialVal;\n\n            if(maxNeighbor > minNeighbor) {\n                maxFractionalChange = Math.max(maxFractionalChange,\n                    Math.abs(z[i][j] - initialVal) / (maxNeighbor - minNeighbor));\n            }\n        }\n    }\n\n    return maxFractionalChange;\n}\n\n},{\"../../lib\":719}],1011:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\n\nmodule.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) {\n    var arrayOut = [];\n    var isContour = Registry.traceIs(trace, 'contour');\n    var isHist = Registry.traceIs(trace, 'histogram');\n    var isGL2D = Registry.traceIs(trace, 'gl2d');\n    var v0;\n    var dv;\n    var i;\n\n    var isArrayOfTwoItemsOrMore = isArrayOrTypedArray(arrayIn) && arrayIn.length > 1;\n\n    if(isArrayOfTwoItemsOrMore && !isHist && (ax.type !== 'category')) {\n        var len = arrayIn.length;\n\n        // given vals are brick centers\n        // hopefully length === numbricks, but use this method even if too few are supplied\n        // and extend it linearly based on the last two points\n        if(len <= numbricks) {\n            // contour plots only want the centers\n            if(isContour || isGL2D) arrayOut = arrayIn.slice(0, numbricks);\n            else if(numbricks === 1) {\n                arrayOut = [arrayIn[0] - 0.5, arrayIn[0] + 0.5];\n            } else {\n                arrayOut = [1.5 * arrayIn[0] - 0.5 * arrayIn[1]];\n\n                for(i = 1; i < len; i++) {\n                    arrayOut.push((arrayIn[i - 1] + arrayIn[i]) * 0.5);\n                }\n\n                arrayOut.push(1.5 * arrayIn[len - 1] - 0.5 * arrayIn[len - 2]);\n            }\n\n            if(len < numbricks) {\n                var lastPt = arrayOut[arrayOut.length - 1];\n                var delta = lastPt - arrayOut[arrayOut.length - 2];\n\n                for(i = len; i < numbricks; i++) {\n                    lastPt += delta;\n                    arrayOut.push(lastPt);\n                }\n            }\n        } else {\n            // hopefully length === numbricks+1, but do something regardless:\n            // given vals are brick boundaries\n            return isContour ?\n                arrayIn.slice(0, numbricks) :  // we must be strict for contours\n                arrayIn.slice(0, numbricks + 1);\n        }\n    } else {\n        var calendar = trace[ax._id.charAt(0) + 'calendar'];\n\n        if(isHist) {\n            v0 = ax.r2c(v0In, 0, calendar);\n        } else {\n            if(isArrayOrTypedArray(arrayIn) && arrayIn.length === 1) {\n                v0 = arrayIn[0];\n            } else if(v0In === undefined) {\n                v0 = 0;\n            } else {\n                var fn = ax.type === 'log' ? ax.d2c : ax.r2c;\n                v0 = fn(v0In, 0, calendar);\n            }\n        }\n\n        dv = dvIn || 1;\n\n        for(i = (isContour || isGL2D) ? 0 : -0.5; i < numbricks; i++) {\n            arrayOut.push(v0 + dv * i);\n        }\n    }\n\n    return arrayOut;\n};\n\n},{\"../../lib\":719,\"../../registry\":847}],1012:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar tinycolor = _dereq_('tinycolor2');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar makeColorScaleFuncFromTrace = _dereq_('../../components/colorscale').makeColorScaleFuncFromTrace;\nvar xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');\n\nmodule.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    Lib.makeTraceGroups(heatmapLayer, cdheatmaps, 'hm').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n\n        var z = cd0.z;\n        var x = cd0.x;\n        var y = cd0.y;\n        var xc = cd0.xCenter;\n        var yc = cd0.yCenter;\n        var isContour = Registry.traceIs(trace, 'contour');\n        var zsmooth = isContour ? 'best' : trace.zsmooth;\n\n        // get z dims\n        var m = z.length;\n        var n = Lib.maxRowLength(z);\n        var xrev = false;\n        var yrev = false;\n\n        var left, right, temp, top, bottom, i;\n\n        // TODO: if there are multiple overlapping categorical heatmaps,\n        // or if we allow category sorting, then the categories may not be\n        // sequential... may need to reorder and/or expand z\n\n        // Get edges of png in pixels (xa.c2p() maps axes coordinates to pixel coordinates)\n        // figure out if either axis is reversed (y is usually reversed, in pixel coords)\n        // also clip the image to maximum 50% outside the visible plot area\n        // bigger image lets you pan more naturally, but slows performance.\n        // TODO: use low-resolution images outside the visible plot for panning\n        // these while loops find the first and last brick bounds that are defined\n        // (in case of log of a negative)\n        i = 0;\n        while(left === undefined && i < x.length - 1) {\n            left = xa.c2p(x[i]);\n            i++;\n        }\n        i = x.length - 1;\n        while(right === undefined && i > 0) {\n            right = xa.c2p(x[i]);\n            i--;\n        }\n\n        if(right < left) {\n            temp = right;\n            right = left;\n            left = temp;\n            xrev = true;\n        }\n\n        i = 0;\n        while(top === undefined && i < y.length - 1) {\n            top = ya.c2p(y[i]);\n            i++;\n        }\n        i = y.length - 1;\n        while(bottom === undefined && i > 0) {\n            bottom = ya.c2p(y[i]);\n            i--;\n        }\n\n        if(bottom < top) {\n            temp = top;\n            top = bottom;\n            bottom = temp;\n            yrev = true;\n        }\n\n        // for contours with heatmap fill, we generate the boundaries based on\n        // brick centers but then use the brick edges for drawing the bricks\n        if(isContour) {\n            xc = x;\n            yc = y;\n            x = cd0.xfill;\n            y = cd0.yfill;\n        }\n\n        // make an image that goes at most half a screen off either side, to keep\n        // time reasonable when you zoom in. if zsmooth is true/fast, don't worry\n        // about this, because zooming doesn't increase number of pixels\n        // if zsmooth is best, don't include anything off screen because it takes too long\n        if(zsmooth !== 'fast') {\n            var extra = zsmooth === 'best' ? 0 : 0.5;\n            left = Math.max(-extra * xa._length, left);\n            right = Math.min((1 + extra) * xa._length, right);\n            top = Math.max(-extra * ya._length, top);\n            bottom = Math.min((1 + extra) * ya._length, bottom);\n        }\n\n        var imageWidth = Math.round(right - left);\n        var imageHeight = Math.round(bottom - top);\n\n        // setup image nodes\n\n        // if image is entirely off-screen, don't even draw it\n        var isOffScreen = (imageWidth <= 0 || imageHeight <= 0);\n\n        if(isOffScreen) {\n            var noImage = plotGroup.selectAll('image').data([]);\n            noImage.exit().remove();\n            return;\n        }\n\n        // generate image data\n\n        var canvasW, canvasH;\n        if(zsmooth === 'fast') {\n            canvasW = n;\n            canvasH = m;\n        } else {\n            canvasW = imageWidth;\n            canvasH = imageHeight;\n        }\n\n        var canvas = document.createElement('canvas');\n        canvas.width = canvasW;\n        canvas.height = canvasH;\n        var context = canvas.getContext('2d');\n\n        var sclFunc = makeColorScaleFuncFromTrace(trace, {noNumericCheck: true, returnArray: true});\n\n        // map brick boundaries to image pixels\n        var xpx,\n            ypx;\n        if(zsmooth === 'fast') {\n            xpx = xrev ?\n                function(index) { return n - 1 - index; } :\n                Lib.identity;\n            ypx = yrev ?\n                function(index) { return m - 1 - index; } :\n                Lib.identity;\n        } else {\n            xpx = function(index) {\n                return Lib.constrain(Math.round(xa.c2p(x[index]) - left),\n                    0, imageWidth);\n            };\n            ypx = function(index) {\n                return Lib.constrain(Math.round(ya.c2p(y[index]) - top),\n                    0, imageHeight);\n            };\n        }\n\n        // build the pixel map brick-by-brick\n        // cruise through z-matrix row-by-row\n        // build a brick at each z-matrix value\n        var yi = ypx(0);\n        var yb = [yi, yi];\n        var xbi = xrev ? 0 : 1;\n        var ybi = yrev ? 0 : 1;\n        // for collecting an average luminosity of the heatmap\n        var pixcount = 0;\n        var rcount = 0;\n        var gcount = 0;\n        var bcount = 0;\n\n        var xb, j, xi, v, row, c;\n\n        function setColor(v, pixsize) {\n            if(v !== undefined) {\n                var c = sclFunc(v);\n                c[0] = Math.round(c[0]);\n                c[1] = Math.round(c[1]);\n                c[2] = Math.round(c[2]);\n\n                pixcount += pixsize;\n                rcount += c[0] * pixsize;\n                gcount += c[1] * pixsize;\n                bcount += c[2] * pixsize;\n                return c;\n            }\n            return [0, 0, 0, 0];\n        }\n\n        function interpColor(r0, r1, xinterp, yinterp) {\n            var z00 = r0[xinterp.bin0];\n            if(z00 === undefined) return setColor(undefined, 1);\n\n            var z01 = r0[xinterp.bin1];\n            var z10 = r1[xinterp.bin0];\n            var z11 = r1[xinterp.bin1];\n            var dx = (z01 - z00) || 0;\n            var dy = (z10 - z00) || 0;\n            var dxy;\n\n            // the bilinear interpolation term needs different calculations\n            // for all the different permutations of missing data\n            // among the neighbors of the main point, to ensure\n            // continuity across brick boundaries.\n            if(z01 === undefined) {\n                if(z11 === undefined) dxy = 0;\n                else if(z10 === undefined) dxy = 2 * (z11 - z00);\n                else dxy = (2 * z11 - z10 - z00) * 2 / 3;\n            } else if(z11 === undefined) {\n                if(z10 === undefined) dxy = 0;\n                else dxy = (2 * z00 - z01 - z10) * 2 / 3;\n            } else if(z10 === undefined) dxy = (2 * z11 - z01 - z00) * 2 / 3;\n            else dxy = (z11 + z00 - z01 - z10);\n\n            return setColor(z00 + xinterp.frac * dx + yinterp.frac * (dy + xinterp.frac * dxy));\n        }\n\n        if(zsmooth) { // best or fast, works fastest with imageData\n            var pxIndex = 0;\n            var pixels;\n\n            try {\n                pixels = new Uint8Array(imageWidth * imageHeight * 4);\n            } catch(e) {\n                pixels = new Array(imageWidth * imageHeight * 4);\n            }\n\n            if(zsmooth === 'best') {\n                var xForPx = xc || x;\n                var yForPx = yc || y;\n                var xPixArray = new Array(xForPx.length);\n                var yPixArray = new Array(yForPx.length);\n                var xinterpArray = new Array(imageWidth);\n                var findInterpX = xc ? findInterpFromCenters : findInterp;\n                var findInterpY = yc ? findInterpFromCenters : findInterp;\n                var yinterp, r0, r1;\n\n                // first make arrays of x and y pixel locations of brick boundaries\n                for(i = 0; i < xForPx.length; i++) xPixArray[i] = Math.round(xa.c2p(xForPx[i]) - left);\n                for(i = 0; i < yForPx.length; i++) yPixArray[i] = Math.round(ya.c2p(yForPx[i]) - top);\n\n                // then make arrays of interpolations\n                // (bin0=closest, bin1=next, frac=fractional dist.)\n                for(i = 0; i < imageWidth; i++) xinterpArray[i] = findInterpX(i, xPixArray);\n\n                // now do the interpolations and fill the png\n                for(j = 0; j < imageHeight; j++) {\n                    yinterp = findInterpY(j, yPixArray);\n                    r0 = z[yinterp.bin0];\n                    r1 = z[yinterp.bin1];\n                    for(i = 0; i < imageWidth; i++, pxIndex += 4) {\n                        c = interpColor(r0, r1, xinterpArray[i], yinterp);\n                        putColor(pixels, pxIndex, c);\n                    }\n                }\n            } else { // zsmooth = fast\n                for(j = 0; j < m; j++) {\n                    row = z[j];\n                    yb = ypx(j);\n                    for(i = 0; i < imageWidth; i++) {\n                        c = setColor(row[i], 1);\n                        pxIndex = (yb * imageWidth + xpx(i)) * 4;\n                        putColor(pixels, pxIndex, c);\n                    }\n                }\n            }\n\n            var imageData = context.createImageData(imageWidth, imageHeight);\n            try {\n                imageData.data.set(pixels);\n            } catch(e) {\n                var pxArray = imageData.data;\n                var dlen = pxArray.length;\n                for(j = 0; j < dlen; j ++) {\n                    pxArray[j] = pixels[j];\n                }\n            }\n\n            context.putImageData(imageData, 0, 0);\n        } else { // zsmooth = false -> filling potentially large bricks works fastest with fillRect\n            // gaps do not need to be exact integers, but if they *are* we will get\n            // cleaner edges by rounding at least one edge\n            var xGap = trace.xgap;\n            var yGap = trace.ygap;\n            var xGapLeft = Math.floor(xGap / 2);\n            var yGapTop = Math.floor(yGap / 2);\n\n            for(j = 0; j < m; j++) {\n                row = z[j];\n                yb.reverse();\n                yb[ybi] = ypx(j + 1);\n                if(yb[0] === yb[1] || yb[0] === undefined || yb[1] === undefined) {\n                    continue;\n                }\n                xi = xpx(0);\n                xb = [xi, xi];\n                for(i = 0; i < n; i++) {\n                    // build one color brick!\n                    xb.reverse();\n                    xb[xbi] = xpx(i + 1);\n                    if(xb[0] === xb[1] || xb[0] === undefined || xb[1] === undefined) {\n                        continue;\n                    }\n                    v = row[i];\n                    c = setColor(v, (xb[1] - xb[0]) * (yb[1] - yb[0]));\n                    context.fillStyle = 'rgba(' + c.join(',') + ')';\n\n                    context.fillRect(xb[0] + xGapLeft, yb[0] + yGapTop,\n                        xb[1] - xb[0] - xGap, yb[1] - yb[0] - yGap);\n                }\n            }\n        }\n\n        rcount = Math.round(rcount / pixcount);\n        gcount = Math.round(gcount / pixcount);\n        bcount = Math.round(bcount / pixcount);\n        var avgColor = tinycolor('rgb(' + rcount + ',' + gcount + ',' + bcount + ')');\n\n        gd._hmpixcount = (gd._hmpixcount||0) + pixcount;\n        gd._hmlumcount = (gd._hmlumcount||0) + pixcount * avgColor.getLuminance();\n\n        var image3 = plotGroup.selectAll('image')\n            .data(cd);\n\n        image3.enter().append('svg:image').attr({\n            xmlns: xmlnsNamespaces.svg,\n            preserveAspectRatio: 'none'\n        });\n\n        image3.attr({\n            height: imageHeight,\n            width: imageWidth,\n            x: left,\n            y: top,\n            'xlink:href': canvas.toDataURL('image/png')\n        });\n    });\n};\n\n// get interpolated bin value. Returns {bin0:closest bin, frac:fractional dist to next, bin1:next bin}\nfunction findInterp(pixel, pixArray) {\n    var maxBin = pixArray.length - 2;\n    var bin = Lib.constrain(Lib.findBin(pixel, pixArray), 0, maxBin);\n    var pix0 = pixArray[bin];\n    var pix1 = pixArray[bin + 1];\n    var interp = Lib.constrain(bin + (pixel - pix0) / (pix1 - pix0) - 0.5, 0, maxBin);\n    var bin0 = Math.round(interp);\n    var frac = Math.abs(interp - bin0);\n\n    if(!interp || interp === maxBin || !frac) {\n        return {\n            bin0: bin0,\n            bin1: bin0,\n            frac: 0\n        };\n    }\n    return {\n        bin0: bin0,\n        frac: frac,\n        bin1: Math.round(bin0 + frac / (interp - bin0))\n    };\n}\n\nfunction findInterpFromCenters(pixel, centerPixArray) {\n    var maxBin = centerPixArray.length - 1;\n    var bin = Lib.constrain(Lib.findBin(pixel, centerPixArray), 0, maxBin);\n    var pix0 = centerPixArray[bin];\n    var pix1 = centerPixArray[bin + 1];\n    var frac = ((pixel - pix0) / (pix1 - pix0)) || 0;\n    if(frac <= 0) {\n        return {\n            bin0: bin,\n            bin1: bin,\n            frac: 0\n        };\n    }\n    if(frac < 0.5) {\n        return {\n            bin0: bin,\n            bin1: bin + 1,\n            frac: frac\n        };\n    }\n    return {\n        bin0: bin + 1,\n        bin1: bin,\n        frac: 1 - frac\n    };\n}\n\nfunction putColor(pixels, pxIndex, c) {\n    pixels[pxIndex] = c[0];\n    pixels[pxIndex + 1] = c[1];\n    pixels[pxIndex + 2] = c[2];\n    pixels[pxIndex + 3] = Math.round(c[3] * 255);\n}\n\n},{\"../../components/colorscale\":605,\"../../constants/xmlns_namespaces\":696,\"../../lib\":719,\"../../registry\":847,\"d3\":163,\"tinycolor2\":537}],1013:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nmodule.exports = function style(gd) {\n    d3.select(gd).selectAll('.hm image')\n        .style('opacity', function(d) {\n            return d.trace.opacity;\n        });\n};\n\n},{\"d3\":163}],1014:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = function handleStyleDefaults(traceIn, traceOut, coerce) {\n    var zsmooth = coerce('zsmooth');\n    if(zsmooth === false) {\n        // ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.\n        coerce('xgap');\n        coerce('ygap');\n    }\n\n    coerce('zhoverformat');\n};\n\n},{}],1015:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar Lib = _dereq_('../../lib');\n\nvar Registry = _dereq_('../../registry');\n\nmodule.exports = function handleXYZDefaults(traceIn, traceOut, coerce, layout, xName, yName) {\n    var z = coerce('z');\n    xName = xName || 'x';\n    yName = yName || 'y';\n    var x, y;\n\n    if(z === undefined || !z.length) return 0;\n\n    if(Lib.isArray1D(traceIn.z)) {\n        x = coerce(xName);\n        y = coerce(yName);\n\n        var xlen = Lib.minRowLength(x);\n        var ylen = Lib.minRowLength(y);\n\n        // column z must be accompanied by xName and yName arrays\n        if(xlen === 0 || ylen === 0) return 0;\n\n        traceOut._length = Math.min(xlen, ylen, z.length);\n    } else {\n        x = coordDefaults(xName, coerce);\n        y = coordDefaults(yName, coerce);\n\n        // TODO put z validation elsewhere\n        if(!isValidZ(z)) return 0;\n\n        coerce('transpose');\n\n        traceOut._length = null;\n    }\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, [xName, yName], layout);\n\n    return true;\n};\n\nfunction coordDefaults(coordStr, coerce) {\n    var coord = coerce(coordStr);\n    var coordType = coord ? coerce(coordStr + 'type', 'array') : 'scaled';\n\n    if(coordType === 'scaled') {\n        coerce(coordStr + '0');\n        coerce('d' + coordStr);\n    }\n\n    return coord;\n}\n\nfunction isValidZ(z) {\n    var allRowsAreArrays = true;\n    var oneRowIsFilled = false;\n    var hasOneNumber = false;\n    var zi;\n\n    /*\n     * Without this step:\n     *\n     * hasOneNumber = false breaks contour but not heatmap\n     * allRowsAreArrays = false breaks contour but not heatmap\n     * oneRowIsFilled = false breaks both\n     */\n\n    for(var i = 0; i < z.length; i++) {\n        zi = z[i];\n        if(!Lib.isArrayOrTypedArray(zi)) {\n            allRowsAreArrays = false;\n            break;\n        }\n        if(zi.length > 0) oneRowIsFilled = true;\n        for(var j = 0; j < zi.length; j++) {\n            if(isNumeric(zi[j])) {\n                hasOneNumber = true;\n                break;\n            }\n        }\n    }\n\n    return (allRowsAreArrays && oneRowIsFilled && hasOneNumber);\n}\n\n},{\"../../lib\":719,\"../../registry\":847,\"fast-isnumeric\":225}],1016:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar heatmapAttrs = _dereq_('../heatmap/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar commonList = [\n    'z',\n    'x', 'x0', 'dx',\n    'y', 'y0', 'dy',\n    'text', 'transpose',\n    'xtype', 'ytype'\n];\n\nvar attrs = {};\n\nfor(var i = 0; i < commonList.length; i++) {\n    var k = commonList[i];\n    attrs[k] = heatmapAttrs[k];\n}\n\nextendFlat(\n    attrs,\n    colorScaleAttrs('', {cLetter: 'z', autoColorDflt: false})\n);\n\nmodule.exports = overrideAll(attrs, 'calc', 'nested');\n\n},{\"../../components/colorscale/attributes\":600,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../heatmap/attributes\":1001}],1017:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar createHeatmap2D = _dereq_('gl-heatmap2d');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar str2RGBArray = _dereq_('../../lib/str2rgbarray');\n\n\nfunction Heatmap(scene, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.type = 'heatmapgl';\n\n    this.name = '';\n    this.hoverinfo = 'all';\n\n    this.xData = [];\n    this.yData = [];\n    this.zData = [];\n    this.textLabels = [];\n\n    this.idToIndex = [];\n    this.bounds = [0, 0, 0, 0];\n\n    this.options = {\n        z: [],\n        x: [],\n        y: [],\n        shape: [0, 0],\n        colorLevels: [0],\n        colorValues: [0, 0, 0, 1]\n    };\n\n    this.heatmap = createHeatmap2D(scene.glplot, this.options);\n    this.heatmap._trace = this;\n}\n\nvar proto = Heatmap.prototype;\n\nproto.handlePick = function(pickResult) {\n    var options = this.options;\n    var shape = options.shape;\n    var index = pickResult.pointId;\n    var xIndex = index % shape[0];\n    var yIndex = Math.floor(index / shape[0]);\n    var zIndex = index;\n\n    return {\n        trace: this,\n        dataCoord: pickResult.dataCoord,\n        traceCoord: [\n            options.x[xIndex],\n            options.y[yIndex],\n            options.z[zIndex]\n        ],\n        textLabel: this.textLabels[index],\n        name: this.name,\n        pointIndex: [yIndex, xIndex],\n        hoverinfo: this.hoverinfo\n    };\n};\n\nproto.update = function(fullTrace, calcTrace) {\n    var calcPt = calcTrace[0];\n\n    this.index = fullTrace.index;\n    this.name = fullTrace.name;\n    this.hoverinfo = fullTrace.hoverinfo;\n\n    // convert z from 2D -> 1D\n    var z = calcPt.z;\n    this.options.z = [].concat.apply([], z);\n\n    var rowLen = z[0].length;\n    var colLen = z.length;\n    this.options.shape = [rowLen, colLen];\n\n    this.options.x = calcPt.x;\n    this.options.y = calcPt.y;\n\n    var colorOptions = convertColorscale(fullTrace);\n    this.options.colorLevels = colorOptions.colorLevels;\n    this.options.colorValues = colorOptions.colorValues;\n\n    // convert text from 2D -> 1D\n    this.textLabels = [].concat.apply([], fullTrace.text);\n\n    this.heatmap.update(this.options);\n\n    var xa = this.scene.xaxis;\n    var ya = this.scene.yaxis;\n    fullTrace._extremes[xa._id] = Axes.findExtremes(xa, calcPt.x);\n    fullTrace._extremes[ya._id] = Axes.findExtremes(ya, calcPt.y);\n};\n\nproto.dispose = function() {\n    this.heatmap.dispose();\n};\n\nfunction convertColorscale(fullTrace) {\n    var scl = fullTrace.colorscale;\n    var zmin = fullTrace.zmin;\n    var zmax = fullTrace.zmax;\n\n    var N = scl.length;\n    var domain = new Array(N);\n    var range = new Array(4 * N);\n\n    for(var i = 0; i < N; i++) {\n        var si = scl[i];\n        var color = str2RGBArray(si[1]);\n\n        domain[i] = zmin + si[0] * (zmax - zmin);\n\n        for(var j = 0; j < 4; j++) {\n            range[(4 * i) + j] = color[j];\n        }\n    }\n\n    return {\n        colorLevels: domain,\n        colorValues: range\n    };\n}\n\nfunction createHeatmap(scene, fullTrace, calcTrace) {\n    var plot = new Heatmap(scene, fullTrace.uid);\n    plot.update(fullTrace, calcTrace);\n    return plot;\n}\n\nmodule.exports = createHeatmap;\n\n},{\"../../lib/str2rgbarray\":742,\"../../plots/cartesian/axes\":767,\"gl-heatmap2d\":251}],1018:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('../heatmap/defaults'),\n    colorbar: _dereq_('../heatmap/colorbar'),\n\n    calc: _dereq_('../heatmap/calc'),\n    plot: _dereq_('./convert'),\n\n    moduleType: 'trace',\n    name: 'heatmapgl',\n    basePlotModule: _dereq_('../../plots/gl2d'),\n    categories: ['gl', 'gl2d', '2dMap'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/gl2d\":805,\"../heatmap/calc\":1002,\"../heatmap/colorbar\":1004,\"../heatmap/defaults\":1006,\"./attributes\":1016,\"./convert\":1017}],1019:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar barAttrs = _dereq_('../bar/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar makeBinAttrs = _dereq_('./bin_attributes');\nvar constants = _dereq_('./constants');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = {\n    x: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n    y: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    text: extendFlat({}, barAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, barAttrs.hovertext, {\n        \n    }),\n    orientation: barAttrs.orientation,\n\n    histfunc: {\n        valType: 'enumerated',\n        values: ['count', 'sum', 'avg', 'min', 'max'],\n        \n        dflt: 'count',\n        editType: 'calc',\n        \n    },\n    histnorm: {\n        valType: 'enumerated',\n        values: ['', 'percent', 'probability', 'density', 'probability density'],\n        dflt: '',\n        \n        editType: 'calc',\n        \n    },\n\n    cumulative: {\n        enabled: {\n            valType: 'boolean',\n            dflt: false,\n            \n            editType: 'calc',\n            \n        },\n\n        direction: {\n            valType: 'enumerated',\n            values: ['increasing', 'decreasing'],\n            dflt: 'increasing',\n            \n            editType: 'calc',\n            \n        },\n\n        currentbin: {\n            valType: 'enumerated',\n            values: ['include', 'exclude', 'half'],\n            dflt: 'include',\n            \n            editType: 'calc',\n            \n        },\n        editType: 'calc'\n    },\n    nbinsx: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    xbins: makeBinAttrs('x', true),\n\n    nbinsy: {\n        valType: 'integer',\n        min: 0,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    ybins: makeBinAttrs('y', true),\n    autobinx: {\n        valType: 'boolean',\n        dflt: null,\n        \n        editType: 'calc',\n        \n    },\n    autobiny: {\n        valType: 'boolean',\n        dflt: null,\n        \n        editType: 'calc',\n        \n    },\n\n    bingroup: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'calc',\n        \n    },\n\n    hovertemplate: hovertemplateAttrs({}, {\n        keys: constants.eventDataKeys\n    }),\n\n    marker: barAttrs.marker,\n\n    offsetgroup: barAttrs.offsetgroup,\n    alignmentgroup: barAttrs.alignmentgroup,\n\n    selected: barAttrs.selected,\n    unselected: barAttrs.unselected,\n\n    _deprecated: {\n        bardir: barAttrs._deprecated.bardir\n    }\n};\n\n},{\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../bar/attributes\":857,\"./bin_attributes\":1021,\"./constants\":1025}],1020:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nmodule.exports = function doAvg(size, counts) {\n    var nMax = size.length;\n    var total = 0;\n    for(var i = 0; i < nMax; i++) {\n        if(counts[i]) {\n            size[i] /= counts[i];\n            total += size[i];\n        } else size[i] = null;\n    }\n    return total;\n};\n\n},{}],1021:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function makeBinAttrs(axLetter, match) {\n    return {\n        start: {\n            valType: 'any', // for date axes\n            \n            editType: 'calc',\n            \n        },\n        end: {\n            valType: 'any', // for date axes\n            \n            editType: 'calc',\n            \n        },\n        size: {\n            valType: 'any', // for date axes\n            \n            editType: 'calc',\n            \n        },\n        editType: 'calc'\n    };\n};\n\n},{}],1022:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\n\nmodule.exports = {\n    count: function(n, i, size) {\n        size[n]++;\n        return 1;\n    },\n\n    sum: function(n, i, size, counterData) {\n        var v = counterData[i];\n        if(isNumeric(v)) {\n            v = Number(v);\n            size[n] += v;\n            return v;\n        }\n        return 0;\n    },\n\n    avg: function(n, i, size, counterData, counts) {\n        var v = counterData[i];\n        if(isNumeric(v)) {\n            v = Number(v);\n            size[n] += v;\n            counts[n]++;\n        }\n        return 0;\n    },\n\n    min: function(n, i, size, counterData) {\n        var v = counterData[i];\n        if(isNumeric(v)) {\n            v = Number(v);\n            if(!isNumeric(size[n])) {\n                size[n] = v;\n                return v;\n            } else if(size[n] > v) {\n                var delta = v - size[n];\n                size[n] = v;\n                return delta;\n            }\n        }\n        return 0;\n    },\n\n    max: function(n, i, size, counterData) {\n        var v = counterData[i];\n        if(isNumeric(v)) {\n            v = Number(v);\n            if(!isNumeric(size[n])) {\n                size[n] = v;\n                return v;\n            } else if(size[n] < v) {\n                var delta = v - size[n];\n                size[n] = v;\n                return delta;\n            }\n        }\n        return 0;\n    }\n};\n\n},{\"fast-isnumeric\":225}],1023:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar numConstants = _dereq_('../../constants/numerical');\nvar oneYear = numConstants.ONEAVGYEAR;\nvar oneMonth = numConstants.ONEAVGMONTH;\nvar oneDay = numConstants.ONEDAY;\nvar oneHour = numConstants.ONEHOUR;\nvar oneMin = numConstants.ONEMIN;\nvar oneSec = numConstants.ONESEC;\nvar tickIncrement = _dereq_('../../plots/cartesian/axes').tickIncrement;\n\n\n/*\n * make a function that will find rounded bin edges\n * @param {number} leftGap: how far from the left edge of any bin is the closest data value?\n * @param {number} rightGap: how far from the right edge of any bin is the closest data value?\n * @param {Array[number]} binEdges: the actual edge values used in binning\n * @param {object} pa: the position axis\n * @param {string} calendar: the data calendar\n *\n * @return {function(v, isRightEdge)}:\n *   find the start (isRightEdge is falsy) or end (truthy) label value for a bin edge `v`\n */\nmodule.exports = function getBinSpanLabelRound(leftGap, rightGap, binEdges, pa, calendar) {\n    // the rounding digit is the largest digit that changes in *all* of 4 regions:\n    // - inside the rightGap before binEdges[0] (shifted 10% to the left)\n    // - inside the leftGap after binEdges[0] (expanded by 10% of rightGap on each end)\n    // - same for binEdges[1]\n    var dv0 = -1.1 * rightGap;\n    var dv1 = -0.1 * rightGap;\n    var dv2 = leftGap - dv1;\n    var edge0 = binEdges[0];\n    var edge1 = binEdges[1];\n    var leftDigit = Math.min(\n        biggestDigitChanged(edge0 + dv1, edge0 + dv2, pa, calendar),\n        biggestDigitChanged(edge1 + dv1, edge1 + dv2, pa, calendar)\n    );\n    var rightDigit = Math.min(\n        biggestDigitChanged(edge0 + dv0, edge0 + dv1, pa, calendar),\n        biggestDigitChanged(edge1 + dv0, edge1 + dv1, pa, calendar)\n    );\n\n    // normally we try to make the label for the right edge different from\n    // the left edge label, so it's unambiguous which bin gets data on the edge.\n    // but if this results in more than 3 extra digits (or for dates, more than\n    // 2 fields ie hr&min or min&sec, which is 3600x), it'll be more clutter than\n    // useful so keep the label cleaner instead\n    var digit, disambiguateEdges;\n    if(leftDigit > rightDigit && rightDigit < Math.abs(edge1 - edge0) / 4000) {\n        digit = leftDigit;\n        disambiguateEdges = false;\n    } else {\n        digit = Math.min(leftDigit, rightDigit);\n        disambiguateEdges = true;\n    }\n\n    if(pa.type === 'date' && digit > oneDay) {\n        var dashExclude = (digit === oneYear) ? 1 : 6;\n        var increment = (digit === oneYear) ? 'M12' : 'M1';\n\n        return function(v, isRightEdge) {\n            var dateStr = pa.c2d(v, oneYear, calendar);\n            var dashPos = dateStr.indexOf('-', dashExclude);\n            if(dashPos > 0) dateStr = dateStr.substr(0, dashPos);\n            var roundedV = pa.d2c(dateStr, 0, calendar);\n\n            if(roundedV < v) {\n                var nextV = tickIncrement(roundedV, increment, false, calendar);\n                if((roundedV + nextV) / 2 < v + leftGap) roundedV = nextV;\n            }\n\n            if(isRightEdge && disambiguateEdges) {\n                return tickIncrement(roundedV, increment, true, calendar);\n            }\n\n            return roundedV;\n        };\n    }\n\n    return function(v, isRightEdge) {\n        var roundedV = digit * Math.round(v / digit);\n        // if we rounded down and we could round up and still be < leftGap\n        // (or what leftGap values round to), do that\n        if(roundedV + (digit / 10) < v && roundedV + (digit * 0.9) < v + leftGap) {\n            roundedV += digit;\n        }\n        // finally for the right edge back off one digit - but only if we can do that\n        // and not clip off any data that's potentially in the bin\n        if(isRightEdge && disambiguateEdges) {\n            roundedV -= digit;\n        }\n        return roundedV;\n    };\n};\n\n/*\n * Find the largest digit that changes within a (calcdata) region [v1, v2]\n * if dates, \"digit\" means date/time part when it's bigger than a second\n * returns the unit value to round to this digit, eg 0.01 to round to hundredths, or\n * 100 to round to hundreds. returns oneMonth or oneYear for month or year rounding,\n * so that Math.min will work, rather than 'M1' and 'M12'\n */\nfunction biggestDigitChanged(v1, v2, pa, calendar) {\n    // are we crossing zero? can't say anything.\n    // in principle this doesn't apply to dates but turns out this doesn't matter.\n    if(v1 * v2 <= 0) return Infinity;\n\n    var dv = Math.abs(v2 - v1);\n    var isDate = pa.type === 'date';\n    var digit = biggestGuaranteedDigitChanged(dv, isDate);\n    // see if a larger digit also changed\n    for(var i = 0; i < 10; i++) {\n        // numbers: next digit needs to be >10x but <100x then gets rounded down.\n        // dates: next digit can be as much as 60x (then rounded down)\n        var nextDigit = biggestGuaranteedDigitChanged(digit * 80, isDate);\n        // if we get to years, the chain stops\n        if(digit === nextDigit) break;\n        if(didDigitChange(nextDigit, v1, v2, isDate, pa, calendar)) digit = nextDigit;\n        else break;\n    }\n    return digit;\n}\n\n/*\n * Find the largest digit that *definitely* changes in a region [v, v + dv] for any v\n * for nonuniform date regions (months/years) pick the largest\n */\nfunction biggestGuaranteedDigitChanged(dv, isDate) {\n    if(isDate && dv > oneSec) {\n        // this is supposed to be the biggest *guaranteed* change\n        // so compare to the longest month and year across any calendar,\n        // and we'll iterate back up later\n        // note: does not support rounding larger than one year. We could add\n        // that if anyone wants it, but seems unusual and not strictly necessary.\n        if(dv > oneDay) {\n            if(dv > oneYear * 1.1) return oneYear;\n            if(dv > oneMonth * 1.1) return oneMonth;\n            return oneDay;\n        }\n\n        if(dv > oneHour) return oneHour;\n        if(dv > oneMin) return oneMin;\n        return oneSec;\n    }\n    return Math.pow(10, Math.floor(Math.log(dv) / Math.LN10));\n}\n\nfunction didDigitChange(digit, v1, v2, isDate, pa, calendar) {\n    if(isDate && digit > oneDay) {\n        var dateParts1 = dateParts(v1, pa, calendar);\n        var dateParts2 = dateParts(v2, pa, calendar);\n        var parti = (digit === oneYear) ? 0 : 1;\n        return dateParts1[parti] !== dateParts2[parti];\n    }\n    return Math.floor(v2 / digit) - Math.floor(v1 / digit) > 0.1;\n}\n\nfunction dateParts(v, pa, calendar) {\n    var parts = pa.c2d(v, oneYear, calendar).split('-');\n    if(parts[0] === '') {\n        parts.unshift();\n        parts[0] = '-' + parts[0];\n    }\n    return parts;\n}\n\n},{\"../../constants/numerical\":695,\"../../plots/cartesian/axes\":767}],1024:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nvar arraysToCalcdata = _dereq_('../bar/arrays_to_calcdata');\nvar binFunctions = _dereq_('./bin_functions');\nvar normFunctions = _dereq_('./norm_functions');\nvar doAvg = _dereq_('./average');\nvar getBinSpanLabelRound = _dereq_('./bin_label_vals');\n\nfunction calc(gd, trace) {\n    var pos = [];\n    var size = [];\n    var pa = Axes.getFromId(gd, trace.orientation === 'h' ? trace.yaxis : trace.xaxis);\n    var mainData = trace.orientation === 'h' ? 'y' : 'x';\n    var counterData = {x: 'y', y: 'x'}[mainData];\n    var calendar = trace[mainData + 'calendar'];\n    var cumulativeSpec = trace.cumulative;\n    var i;\n\n    var binsAndPos = calcAllAutoBins(gd, trace, pa, mainData);\n    var binSpec = binsAndPos[0];\n    var pos0 = binsAndPos[1];\n\n    var nonuniformBins = typeof binSpec.size === 'string';\n    var binEdges = [];\n    var bins = nonuniformBins ? binEdges : binSpec;\n    // make the empty bin array\n    var inc = [];\n    var counts = [];\n    var inputPoints = [];\n    var total = 0;\n    var norm = trace.histnorm;\n    var func = trace.histfunc;\n    var densityNorm = norm.indexOf('density') !== -1;\n    var i2, binEnd, n;\n\n    if(cumulativeSpec.enabled && densityNorm) {\n        // we treat \"cumulative\" like it means \"integral\" if you use a density norm,\n        // which in the end means it's the same as without \"density\"\n        norm = norm.replace(/ ?density$/, '');\n        densityNorm = false;\n    }\n\n    var extremeFunc = func === 'max' || func === 'min';\n    var sizeInit = extremeFunc ? null : 0;\n    var binFunc = binFunctions.count;\n    var normFunc = normFunctions[norm];\n    var isAvg = false;\n    var pr2c = function(v) { return pa.r2c(v, 0, calendar); };\n    var rawCounterData;\n\n    if(Lib.isArrayOrTypedArray(trace[counterData]) && func !== 'count') {\n        rawCounterData = trace[counterData];\n        isAvg = func === 'avg';\n        binFunc = binFunctions[func];\n    }\n\n    // create the bins (and any extra arrays needed)\n    // assume more than 1e6 bins is an error, so we don't crash the browser\n    i = pr2c(binSpec.start);\n\n    // decrease end a little in case of rounding errors\n    binEnd = pr2c(binSpec.end) + (i - Axes.tickIncrement(i, binSpec.size, false, calendar)) / 1e6;\n\n    while(i < binEnd && pos.length < 1e6) {\n        i2 = Axes.tickIncrement(i, binSpec.size, false, calendar);\n        pos.push((i + i2) / 2);\n        size.push(sizeInit);\n        inputPoints.push([]);\n        // nonuniform bins (like months) we need to search,\n        // rather than straight calculate the bin we're in\n        binEdges.push(i);\n        // nonuniform bins also need nonuniform normalization factors\n        if(densityNorm) inc.push(1 / (i2 - i));\n        if(isAvg) counts.push(0);\n        // break to avoid infinite loops\n        if(i2 <= i) break;\n        i = i2;\n    }\n    binEdges.push(i);\n\n    // for date axes we need bin bounds to be calcdata. For nonuniform bins\n    // we already have this, but uniform with start/end/size they're still strings.\n    if(!nonuniformBins && pa.type === 'date') {\n        bins = {\n            start: pr2c(bins.start),\n            end: pr2c(bins.end),\n            size: bins.size\n        };\n    }\n\n    // bin the data\n    // and make histogram-specific pt-number-to-cd-index map object\n    var nMax = size.length;\n    var uniqueValsPerBin = true;\n    var leftGap = Infinity;\n    var rightGap = Infinity;\n    var ptNumber2cdIndex = {};\n    for(i = 0; i < pos0.length; i++) {\n        var posi = pos0[i];\n        n = Lib.findBin(posi, bins);\n        if(n >= 0 && n < nMax) {\n            total += binFunc(n, i, size, rawCounterData, counts);\n            if(uniqueValsPerBin && inputPoints[n].length && posi !== pos0[inputPoints[n][0]]) {\n                uniqueValsPerBin = false;\n            }\n            inputPoints[n].push(i);\n            ptNumber2cdIndex[i] = n;\n\n            leftGap = Math.min(leftGap, posi - binEdges[n]);\n            rightGap = Math.min(rightGap, binEdges[n + 1] - posi);\n        }\n    }\n\n    var roundFn;\n    if(!uniqueValsPerBin) {\n        roundFn = getBinSpanLabelRound(leftGap, rightGap, binEdges, pa, calendar);\n    }\n\n    // average and/or normalize the data, if needed\n    if(isAvg) total = doAvg(size, counts);\n    if(normFunc) normFunc(size, total, inc);\n\n    // after all normalization etc, now we can accumulate if desired\n    if(cumulativeSpec.enabled) cdf(size, cumulativeSpec.direction, cumulativeSpec.currentbin);\n\n    var seriesLen = Math.min(pos.length, size.length);\n    var cd = [];\n    var firstNonzero = 0;\n    var lastNonzero = seriesLen - 1;\n\n    // look for empty bins at the ends to remove, so autoscale omits them\n    for(i = 0; i < seriesLen; i++) {\n        if(size[i]) {\n            firstNonzero = i;\n            break;\n        }\n    }\n    for(i = seriesLen - 1; i >= firstNonzero; i--) {\n        if(size[i]) {\n            lastNonzero = i;\n            break;\n        }\n    }\n\n    // create the \"calculated data\" to plot\n    for(i = firstNonzero; i <= lastNonzero; i++) {\n        if((isNumeric(pos[i]) && isNumeric(size[i]))) {\n            var cdi = {\n                p: pos[i],\n                s: size[i],\n                b: 0\n            };\n\n            // setup hover and event data fields,\n            // N.B. pts and \"hover\" positions ph0/ph1 don't seem to make much sense\n            // for cumulative distributions\n            if(!cumulativeSpec.enabled) {\n                cdi.pts = inputPoints[i];\n                if(uniqueValsPerBin) {\n                    cdi.ph0 = cdi.ph1 = (inputPoints[i].length) ? pos0[inputPoints[i][0]] : pos[i];\n                } else {\n                    cdi.ph0 = roundFn(binEdges[i]);\n                    cdi.ph1 = roundFn(binEdges[i + 1], true);\n                }\n            }\n            cd.push(cdi);\n        }\n    }\n\n    if(cd.length === 1) {\n        // when we collapse to a single bin, calcdata no longer describes bin size\n        // so we need to explicitly specify it\n        cd[0].width1 = Axes.tickIncrement(cd[0].p, binSpec.size, false, calendar) - cd[0].p;\n    }\n\n    arraysToCalcdata(cd, trace);\n\n    if(Lib.isArrayOrTypedArray(trace.selectedpoints)) {\n        Lib.tagSelected(cd, trace, ptNumber2cdIndex);\n    }\n\n    return cd;\n}\n\n/*\n * calcAllAutoBins: we want all histograms inside the same bingroup\n * (see logic in Histogram.crossTraceDefaults) to share bin specs\n *\n * If the user has explicitly specified differing\n * bin specs, there's nothing we can do, but if possible we will try to use the\n * smallest bins of any of the auto values for all histograms inside the same\n * bingroup.\n */\nfunction calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {\n    var binAttr = mainData + 'bins';\n    var fullLayout = gd._fullLayout;\n    var groupName = trace['_' + mainData + 'bingroup'];\n    var binOpts = fullLayout._histogramBinOpts[groupName];\n    var isOverlay = fullLayout.barmode === 'overlay';\n    var i, traces, tracei, calendar, pos0, autoVals, cumulativeSpec;\n\n    var r2c = function(v) { return pa.r2c(v, 0, calendar); };\n    var c2r = function(v) { return pa.c2r(v, 0, calendar); };\n\n    var cleanBound = pa.type === 'date' ?\n        function(v) { return (v || v === 0) ? Lib.cleanDate(v, null, calendar) : null; } :\n        function(v) { return isNumeric(v) ? Number(v) : null; };\n\n    function setBound(attr, bins, newBins) {\n        if(bins[attr + 'Found']) {\n            bins[attr] = cleanBound(bins[attr]);\n            if(bins[attr] === null) bins[attr] = newBins[attr];\n        } else {\n            autoVals[attr] = bins[attr] = newBins[attr];\n            Lib.nestedProperty(traces[0], binAttr + '.' + attr).set(newBins[attr]);\n        }\n    }\n\n    // all but the first trace in this group has already been marked finished\n    // clear this flag, so next time we run calc we will run autobin again\n    if(trace['_' + mainData + 'autoBinFinished']) {\n        delete trace['_' + mainData + 'autoBinFinished'];\n    } else {\n        traces = binOpts.traces;\n        var allPos = [];\n\n        // Note: we're including `legendonly` traces here for autobin purposes,\n        // so that showing & hiding from the legend won't affect bins.\n        // But this complicates things a bit since those traces don't `calc`,\n        // hence `isFirstVisible`.\n        var isFirstVisible = true;\n        var has2dMap = false;\n        var hasHist2dContour = false;\n        for(i = 0; i < traces.length; i++) {\n            tracei = traces[i];\n\n            if(tracei.visible) {\n                var mainDatai = binOpts.dirs[i];\n                pos0 = tracei['_' + mainDatai + 'pos0'] = pa.makeCalcdata(tracei, mainDatai);\n\n                allPos = Lib.concat(allPos, pos0);\n                delete tracei['_' + mainData + 'autoBinFinished'];\n\n                if(trace.visible === true) {\n                    if(isFirstVisible) {\n                        isFirstVisible = false;\n                    } else {\n                        delete tracei._autoBin;\n                        tracei['_' + mainData + 'autoBinFinished'] = 1;\n                    }\n                    if(Registry.traceIs(tracei, '2dMap')) {\n                        has2dMap = true;\n                    }\n                    if(tracei.type === 'histogram2dcontour') {\n                        hasHist2dContour = true;\n                    }\n                }\n            }\n        }\n\n        calendar = traces[0][mainData + 'calendar'];\n        var newBinSpec = Axes.autoBin(allPos, pa, binOpts.nbins, has2dMap, calendar, binOpts.sizeFound && binOpts.size);\n\n        var autoBin = traces[0]._autoBin = {};\n        autoVals = autoBin[binOpts.dirs[0]] = {};\n\n        if(hasHist2dContour) {\n            // the \"true\" 2nd argument reverses the tick direction (which we can't\n            // just do with a minus sign because of month bins)\n            if(!binOpts.size) {\n                newBinSpec.start = c2r(Axes.tickIncrement(\n                    r2c(newBinSpec.start), newBinSpec.size, true, calendar));\n            }\n            if(binOpts.end === undefined) {\n                newBinSpec.end = c2r(Axes.tickIncrement(\n                    r2c(newBinSpec.end), newBinSpec.size, false, calendar));\n            }\n        }\n\n        // Edge case: single-valued histogram overlaying others\n        // Use them all together to calculate the bin size for the single-valued one\n        if(isOverlay && !Registry.traceIs(trace, '2dMap') && newBinSpec._dataSpan === 0 &&\n            pa.type !== 'category' && pa.type !== 'multicategory') {\n            // Several single-valued histograms! Stop infinite recursion,\n            // just return an extra flag that tells handleSingleValueOverlays\n            // to sort out this trace too\n            if(_overlayEdgeCase) return [newBinSpec, pos0, true];\n\n            newBinSpec = handleSingleValueOverlays(gd, trace, pa, mainData, binAttr);\n        }\n\n        // adjust for CDF edge cases\n        cumulativeSpec = tracei.cumulative || {};\n        if(cumulativeSpec.enabled && (cumulativeSpec.currentbin !== 'include')) {\n            if(cumulativeSpec.direction === 'decreasing') {\n                newBinSpec.start = c2r(Axes.tickIncrement(\n                    r2c(newBinSpec.start), newBinSpec.size, true, calendar));\n            } else {\n                newBinSpec.end = c2r(Axes.tickIncrement(\n                    r2c(newBinSpec.end), newBinSpec.size, false, calendar));\n            }\n        }\n\n        binOpts.size = newBinSpec.size;\n        if(!binOpts.sizeFound) {\n            autoVals.size = newBinSpec.size;\n            Lib.nestedProperty(traces[0], binAttr + '.size').set(newBinSpec.size);\n        }\n\n        setBound('start', binOpts, newBinSpec);\n        setBound('end', binOpts, newBinSpec);\n    }\n\n    pos0 = trace['_' + mainData + 'pos0'];\n    delete trace['_' + mainData + 'pos0'];\n\n    // Each trace can specify its own start/end, or if omitted\n    // we ensure they're beyond the bounds of this trace's data,\n    // and we need to make sure start is aligned with the main start\n    var traceInputBins = trace._input[binAttr] || {};\n    var traceBinOptsCalc = Lib.extendFlat({}, binOpts);\n    var mainStart = binOpts.start;\n    var startIn = pa.r2l(traceInputBins.start);\n    var hasStart = startIn !== undefined;\n    if((binOpts.startFound || hasStart) && startIn !== pa.r2l(mainStart)) {\n        // We have an explicit start to reconcile across traces\n        // if this trace has an explicit start, shift it down to a bin edge\n        // if another trace had an explicit start, shift it down to a\n        // bin edge past our data\n        var traceStart = hasStart ?\n            startIn :\n            Lib.aggNums(Math.min, null, pos0);\n\n        var dummyAx = {\n            type: (pa.type === 'category' || pa.type === 'multicategory') ? 'linear' : pa.type,\n            r2l: pa.r2l,\n            dtick: binOpts.size,\n            tick0: mainStart,\n            calendar: calendar,\n            range: ([traceStart, Axes.tickIncrement(traceStart, binOpts.size, false, calendar)]).map(pa.l2r)\n        };\n        var newStart = Axes.tickFirst(dummyAx);\n        if(newStart > pa.r2l(traceStart)) {\n            newStart = Axes.tickIncrement(newStart, binOpts.size, true, calendar);\n        }\n        traceBinOptsCalc.start = pa.l2r(newStart);\n        if(!hasStart) Lib.nestedProperty(trace, binAttr + '.start').set(traceBinOptsCalc.start);\n    }\n\n    var mainEnd = binOpts.end;\n    var endIn = pa.r2l(traceInputBins.end);\n    var hasEnd = endIn !== undefined;\n    if((binOpts.endFound || hasEnd) && endIn !== pa.r2l(mainEnd)) {\n        // Reconciling an explicit end is easier, as it doesn't need to\n        // match bin edges\n        var traceEnd = hasEnd ?\n            endIn :\n            Lib.aggNums(Math.max, null, pos0);\n\n        traceBinOptsCalc.end = pa.l2r(traceEnd);\n        if(!hasEnd) Lib.nestedProperty(trace, binAttr + '.start').set(traceBinOptsCalc.end);\n    }\n\n    // Backward compatibility for one-time autobinning.\n    // autobin: true is handled in cleanData, but autobin: false\n    // needs to be here where we have determined the values.\n    var autoBinAttr = 'autobin' + mainData;\n    if(trace._input[autoBinAttr] === false) {\n        trace._input[binAttr] = Lib.extendFlat({}, trace[binAttr] || {});\n        delete trace._input[autoBinAttr];\n        delete trace[autoBinAttr];\n    }\n\n    return [traceBinOptsCalc, pos0];\n}\n\n/*\n * Adjust single-value histograms in overlay mode to make as good a\n * guess as we can at autobin values the user would like.\n *\n * Returns the binSpec for the trace that sparked all this\n */\nfunction handleSingleValueOverlays(gd, trace, pa, mainData, binAttr) {\n    var fullLayout = gd._fullLayout;\n    var overlaidTraceGroup = getConnectedHistograms(gd, trace);\n    var pastThisTrace = false;\n    var minSize = Infinity;\n    var singleValuedTraces = [trace];\n    var i, tracei, binOpts;\n\n    // first collect all the:\n    // - min bin size from all multi-valued traces\n    // - single-valued traces\n    for(i = 0; i < overlaidTraceGroup.length; i++) {\n        tracei = overlaidTraceGroup[i];\n\n        if(tracei === trace) {\n            pastThisTrace = true;\n        } else if(!pastThisTrace) {\n            // This trace has already had its autobins calculated, so either:\n            // - it is part of a bingroup\n            // - it is NOT a single-valued trace\n            binOpts = fullLayout._histogramBinOpts[tracei['_' + mainData + 'bingroup']];\n            minSize = Math.min(minSize, binOpts.size || tracei[binAttr].size);\n        } else {\n            var resulti = calcAllAutoBins(gd, tracei, pa, mainData, true);\n            var binSpeci = resulti[0];\n            var isSingleValued = resulti[2];\n\n            // so we can use this result when we get to tracei in the normal\n            // course of events, mark it as done and put _pos0 back\n            tracei['_' + mainData + 'autoBinFinished'] = 1;\n            tracei['_' + mainData + 'pos0'] = resulti[1];\n\n            if(isSingleValued) {\n                singleValuedTraces.push(tracei);\n            } else {\n                minSize = Math.min(minSize, binSpeci.size);\n            }\n        }\n    }\n\n    // find the real data values for each single-valued trace\n    // hunt through pos0 for the first valid value\n    var dataVals = new Array(singleValuedTraces.length);\n    for(i = 0; i < singleValuedTraces.length; i++) {\n        var pos0 = singleValuedTraces[i]['_' + mainData + 'pos0'];\n        for(var j = 0; j < pos0.length; j++) {\n            if(pos0[j] !== undefined) {\n                dataVals[i] = pos0[j];\n                break;\n            }\n        }\n    }\n\n    // are ALL traces are single-valued? use the min difference between\n    // all of their values (which defaults to 1 if there's still only one)\n    if(!isFinite(minSize)) {\n        minSize = Lib.distinctVals(dataVals).minDiff;\n    }\n\n    // now apply the min size we found to all single-valued traces\n    for(i = 0; i < singleValuedTraces.length; i++) {\n        tracei = singleValuedTraces[i];\n        var calendar = tracei[mainData + 'calendar'];\n\n        var newBins = {\n            start: pa.c2r(dataVals[i] - minSize / 2, 0, calendar),\n            end: pa.c2r(dataVals[i] + minSize / 2, 0, calendar),\n            size: minSize\n        };\n\n        tracei._input[binAttr] = tracei[binAttr] = newBins;\n\n        binOpts = fullLayout._histogramBinOpts[tracei['_' + mainData + 'bingroup']];\n        if(binOpts) Lib.extendFlat(binOpts, newBins);\n    }\n\n    return trace[binAttr];\n}\n\n/*\n * Return an array of histograms that share axes and orientation.\n *\n * Only considers histograms. In principle we could include bars in a\n * similar way to how we do manually binned histograms, though this\n * would have tons of edge cases and value judgments to make.\n */\nfunction getConnectedHistograms(gd, trace) {\n    var xid = trace.xaxis;\n    var yid = trace.yaxis;\n    var orientation = trace.orientation;\n\n    var out = [];\n    var fullData = gd._fullData;\n    for(var i = 0; i < fullData.length; i++) {\n        var tracei = fullData[i];\n        if(tracei.type === 'histogram' &&\n            tracei.visible === true &&\n            tracei.orientation === orientation &&\n            tracei.xaxis === xid && tracei.yaxis === yid\n        ) {\n            out.push(tracei);\n        }\n    }\n\n    return out;\n}\n\nfunction cdf(size, direction, currentBin) {\n    var i, vi, prevSum;\n\n    function firstHalfPoint(i) {\n        prevSum = size[i];\n        size[i] /= 2;\n    }\n\n    function nextHalfPoint(i) {\n        vi = size[i];\n        size[i] = prevSum + vi / 2;\n        prevSum += vi;\n    }\n\n    if(currentBin === 'half') {\n        if(direction === 'increasing') {\n            firstHalfPoint(0);\n            for(i = 1; i < size.length; i++) {\n                nextHalfPoint(i);\n            }\n        } else {\n            firstHalfPoint(size.length - 1);\n            for(i = size.length - 2; i >= 0; i--) {\n                nextHalfPoint(i);\n            }\n        }\n    } else if(direction === 'increasing') {\n        for(i = 1; i < size.length; i++) {\n            size[i] += size[i - 1];\n        }\n\n        // 'exclude' is identical to 'include' just shifted one bin over\n        if(currentBin === 'exclude') {\n            size.unshift(0);\n            size.pop();\n        }\n    } else {\n        for(i = size.length - 2; i >= 0; i--) {\n            size[i] += size[i + 1];\n        }\n\n        if(currentBin === 'exclude') {\n            size.push(0);\n            size.shift();\n        }\n    }\n}\n\nmodule.exports = {\n    calc: calc,\n    calcAllAutoBins: calcAllAutoBins\n};\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../../registry\":847,\"../bar/arrays_to_calcdata\":856,\"./average\":1020,\"./bin_functions\":1022,\"./bin_label_vals\":1023,\"./norm_functions\":1031,\"fast-isnumeric\":225}],1025:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = {\n    eventDataKeys: ['binNumber']\n};\n\n},{}],1026:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar axisIds = _dereq_('../../plots/cartesian/axis_ids');\n\nvar traceIs = _dereq_('../../registry').traceIs;\nvar handleGroupingDefaults = _dereq_('../bar/defaults').handleGroupingDefaults;\n\nvar nestedProperty = Lib.nestedProperty;\nvar getAxisGroup = axisIds.getAxisGroup;\n\nvar BINATTRS = [\n    {aStr: {x: 'xbins.start', y: 'ybins.start'}, name: 'start'},\n    {aStr: {x: 'xbins.end', y: 'ybins.end'}, name: 'end'},\n    {aStr: {x: 'xbins.size', y: 'ybins.size'}, name: 'size'},\n    {aStr: {x: 'nbinsx', y: 'nbinsy'}, name: 'nbins'}\n];\n\nvar BINDIRECTIONS = ['x', 'y'];\n\n// handle bin attrs and relink auto-determined values so fullData is complete\nmodule.exports = function crossTraceDefaults(fullData, fullLayout) {\n    var allBinOpts = fullLayout._histogramBinOpts = {};\n    var histTraces = [];\n    var mustMatchTracesLookup = {};\n    var otherTracesList = [];\n\n    var traceOut, traces, groupName, binDir;\n    var i, j, k;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceOut._input, traceOut, traceOut._module.attributes, attr, dflt);\n    }\n\n    function orientation2binDir(traceOut) {\n        return traceOut.orientation === 'v' ? 'x' : 'y';\n    }\n\n    function getAxisType(traceOut, binDir) {\n        var ax = axisIds.getFromTrace({_fullLayout: fullLayout}, traceOut, binDir);\n        return ax.type;\n    }\n\n    function fillBinOpts(traceOut, groupName, binDir) {\n        // N.B. group traces that don't have a bingroup with themselves\n        var fallbackGroupName = traceOut.uid + '__' + binDir;\n        if(!groupName) groupName = fallbackGroupName;\n\n        var axType = getAxisType(traceOut, binDir);\n        var calendar = traceOut[binDir + 'calendar'];\n        var binOpts = allBinOpts[groupName];\n        var needsNewItem = true;\n\n        if(binOpts) {\n            if(axType === binOpts.axType && calendar === binOpts.calendar) {\n                needsNewItem = false;\n                binOpts.traces.push(traceOut);\n                binOpts.dirs.push(binDir);\n            } else {\n                groupName = fallbackGroupName;\n\n                if(axType !== binOpts.axType) {\n                    Lib.warn([\n                        'Attempted to group the bins of trace', traceOut.index,\n                        'set on a', 'type:' + axType, 'axis',\n                        'with bins on', 'type:' + binOpts.axType, 'axis.'\n                    ].join(' '));\n                }\n                if(calendar !== binOpts.calendar) {\n                    // prohibit bingroup for traces using different calendar,\n                    // there's probably a way to make this work, but skip for now\n                    Lib.warn([\n                        'Attempted to group the bins of trace', traceOut.index,\n                        'set with a', calendar, 'calendar',\n                        'with bins',\n                        (binOpts.calendar ? 'on a ' + binOpts.calendar + ' calendar' : 'w/o a set calendar')\n                    ].join(' '));\n                }\n            }\n        }\n\n        if(needsNewItem) {\n            allBinOpts[groupName] = {\n                traces: [traceOut],\n                dirs: [binDir],\n                axType: axType,\n                calendar: traceOut[binDir + 'calendar'] || ''\n            };\n        }\n        traceOut['_' + binDir + 'bingroup'] = groupName;\n    }\n\n    for(i = 0; i < fullData.length; i++) {\n        traceOut = fullData[i];\n\n        if(traceIs(traceOut, 'histogram')) {\n            histTraces.push(traceOut);\n\n            // TODO: this shouldn't be relinked as it's only used within calc\n            // https://github.com/plotly/plotly.js/issues/749\n            delete traceOut._xautoBinFinished;\n            delete traceOut._yautoBinFinished;\n\n            // N.B. need to coerce *alignmentgroup* before *bingroup*, as traces\n            // in same alignmentgroup \"have to match\"\n            if(!traceIs(traceOut, '2dMap')) {\n                handleGroupingDefaults(traceOut._input, traceOut, fullLayout, coerce);\n            }\n        }\n    }\n\n    var alignmentOpts = fullLayout._alignmentOpts || {};\n\n    // Look for traces that \"have to match\", that is:\n    // - 1d histogram traces on the same subplot with same orientation under barmode:stack,\n    // - 1d histogram traces on the same subplot with same orientation under barmode:group\n    // - 1d histogram traces on the same position axis with the same orientation\n    //   and the same *alignmentgroup* (coerced under barmode:group)\n    // - Once `stackgroup` gets implemented (see https://github.com/plotly/plotly.js/issues/3614),\n    //   traces within the same stackgroup will also \"have to match\"\n    for(i = 0; i < histTraces.length; i++) {\n        traceOut = histTraces[i];\n        groupName = '';\n\n        if(!traceIs(traceOut, '2dMap')) {\n            binDir = orientation2binDir(traceOut);\n\n            if(fullLayout.barmode === 'group' && traceOut.alignmentgroup) {\n                var pa = traceOut[binDir + 'axis'];\n                var aGroupId = getAxisGroup(fullLayout, pa) + traceOut.orientation;\n                if((alignmentOpts[aGroupId] || {})[traceOut.alignmentgroup]) {\n                    groupName = aGroupId;\n                }\n            }\n\n            if(!groupName && fullLayout.barmode !== 'overlay') {\n                groupName = (\n                    getAxisGroup(fullLayout, traceOut.xaxis) +\n                    getAxisGroup(fullLayout, traceOut.yaxis) +\n                    orientation2binDir(traceOut)\n                );\n            }\n        }\n\n        if(groupName) {\n            if(!mustMatchTracesLookup[groupName]) {\n                mustMatchTracesLookup[groupName] = [];\n            }\n            mustMatchTracesLookup[groupName].push(traceOut);\n        } else {\n            otherTracesList.push(traceOut);\n        }\n    }\n\n    // Setup binOpts for traces that have to match,\n    // if the traces have a valid bingroup, use that\n    // if not use axis+binDir groupName\n    for(groupName in mustMatchTracesLookup) {\n        traces = mustMatchTracesLookup[groupName];\n\n        // no need to 'force' anything when a single\n        // trace is detected as \"must match\"\n        if(traces.length === 1) {\n            otherTracesList.push(traces[0]);\n            continue;\n        }\n\n        var binGroupFound = false;\n        for(i = 0; i < traces.length; i++) {\n            traceOut = traces[i];\n            binGroupFound = coerce('bingroup');\n            break;\n        }\n\n        groupName = binGroupFound || groupName;\n\n        for(i = 0; i < traces.length; i++) {\n            traceOut = traces[i];\n            var bingroupIn = traceOut._input.bingroup;\n            if(bingroupIn && bingroupIn !== groupName) {\n                Lib.warn([\n                    'Trace', traceOut.index, 'must match',\n                    'within bingroup', groupName + '.',\n                    'Ignoring its bingroup:', bingroupIn, 'setting.'\n                ].join(' '));\n            }\n            traceOut.bingroup = groupName;\n\n            // N.B. no need to worry about 2dMap case\n            // (where both bin direction are set in each trace)\n            // as 2dMap trace never \"have to match\"\n            fillBinOpts(traceOut, groupName, orientation2binDir(traceOut));\n        }\n    }\n\n    // setup binOpts for traces that can but don't have to match,\n    // notice that these traces can be matched with traces that have to match\n    for(i = 0; i < otherTracesList.length; i++) {\n        traceOut = otherTracesList[i];\n\n        var binGroup = coerce('bingroup');\n\n        if(traceIs(traceOut, '2dMap')) {\n            for(k = 0; k < 2; k++) {\n                binDir = BINDIRECTIONS[k];\n                var binGroupInDir = coerce(binDir + 'bingroup',\n                    binGroup ? binGroup + '__' + binDir : null\n                );\n                fillBinOpts(traceOut, binGroupInDir, binDir);\n            }\n        } else {\n            fillBinOpts(traceOut, binGroup, orientation2binDir(traceOut));\n        }\n    }\n\n    // coerce bin attrs!\n    for(groupName in allBinOpts) {\n        var binOpts = allBinOpts[groupName];\n        traces = binOpts.traces;\n\n        for(j = 0; j < BINATTRS.length; j++) {\n            var attrSpec = BINATTRS[j];\n            var attr = attrSpec.name;\n            var aStr;\n            var autoVals;\n\n            // nbins(x|y) is moot if we have a size. This depends on\n            // nbins coming after size in binAttrs.\n            if(attr === 'nbins' && binOpts.sizeFound) continue;\n\n            for(i = 0; i < traces.length; i++) {\n                traceOut = traces[i];\n                binDir = binOpts.dirs[i];\n                aStr = attrSpec.aStr[binDir];\n\n                if(nestedProperty(traceOut._input, aStr).get() !== undefined) {\n                    binOpts[attr] = coerce(aStr);\n                    binOpts[attr + 'Found'] = true;\n                    break;\n                }\n\n                autoVals = (traceOut._autoBin || {})[binDir] || {};\n                if(autoVals[attr]) {\n                    // if this is the *first* autoval\n                    nestedProperty(traceOut, aStr).set(autoVals[attr]);\n                }\n            }\n\n            // start and end we need to coerce anyway, after having collected the\n            // first of each into binOpts, in case a trace wants to restrict its\n            // data to a certain range\n            if(attr === 'start' || attr === 'end') {\n                for(; i < traces.length; i++) {\n                    traceOut = traces[i];\n                    if(traceOut['_' + binDir + 'bingroup']) {\n                        autoVals = (traceOut._autoBin || {})[binDir] || {};\n                        coerce(aStr, autoVals[attr]);\n                    }\n                }\n            }\n\n            if(attr === 'nbins' && !binOpts.sizeFound && !binOpts.nbinsFound) {\n                traceOut = traces[0];\n                binOpts[attr] = coerce(aStr);\n            }\n        }\n    }\n};\n\n},{\"../../lib\":719,\"../../plots/cartesian/axis_ids\":770,\"../../registry\":847,\"../bar/defaults\":861}],1027:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\n\nvar handleStyleDefaults = _dereq_('../bar/style_defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var x = coerce('x');\n    var y = coerce('y');\n\n    var cumulative = coerce('cumulative.enabled');\n    if(cumulative) {\n        coerce('cumulative.direction');\n        coerce('cumulative.currentbin');\n    }\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    var orientation = coerce('orientation', (y && !x) ? 'h' : 'v');\n    var sampleLetter = orientation === 'v' ? 'x' : 'y';\n    var aggLetter = orientation === 'v' ? 'y' : 'x';\n\n    var len = (x && y) ?\n        Math.min(Lib.minRowLength(x) && Lib.minRowLength(y)) :\n        Lib.minRowLength(traceOut[sampleLetter] || []);\n\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    traceOut._length = len;\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);\n\n    var hasAggregationData = traceOut[aggLetter];\n    if(hasAggregationData) coerce('histfunc');\n    coerce('histnorm');\n\n    // Note: bin defaults are now handled in Histogram.crossTraceDefaults\n    // autobin(x|y) are only included here to appease Plotly.validate\n    coerce('autobin' + sampleLetter);\n\n    handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n\n    var lineColor = (traceOut.marker.line || {}).color;\n\n    // override defaultColor for error bars with defaultLine\n    var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || Color.defaultLine, {axis: 'y'});\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || Color.defaultLine, {axis: 'x', inherit: 'y'});\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../../registry\":847,\"../bar/style_defaults\":871,\"./attributes\":1019}],1028:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function eventData(out, pt, trace, cd, pointNumber) {\n    // standard cartesian event data\n    out.x = 'xVal' in pt ? pt.xVal : pt.x;\n    out.y = 'yVal' in pt ? pt.yVal : pt.y;\n\n    // for 2d histograms\n    if('zLabelVal' in pt) out.z = pt.zLabelVal;\n\n    if(pt.xa) out.xaxis = pt.xa;\n    if(pt.ya) out.yaxis = pt.ya;\n\n    // specific to histogram - CDFs do not have pts (yet?)\n    if(!(trace.cumulative || {}).enabled) {\n        var pts = Array.isArray(pointNumber) ?\n            cd[0].pts[pointNumber[0]][pointNumber[1]] :\n            cd[pointNumber].pts;\n\n        out.pointNumbers = pts;\n        out.binNumber = out.pointNumber;\n        delete out.pointNumber;\n        delete out.pointIndex;\n\n        var pointIndices;\n        if(trace._indexToPoints) {\n            pointIndices = [];\n            for(var i = 0; i < pts.length; i++) {\n                pointIndices = pointIndices.concat(trace._indexToPoints[pts[i]]);\n            }\n        } else {\n            pointIndices = pts;\n        }\n\n        out.pointIndices = pointIndices;\n    }\n\n    return out;\n};\n\n},{}],1029:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar barHover = _dereq_('../bar/hover').hoverPoints;\nvar hoverLabelText = _dereq_('../../plots/cartesian/axes').hoverLabelText;\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode) {\n    var pts = barHover(pointData, xval, yval, hovermode);\n\n    if(!pts) return;\n\n    pointData = pts[0];\n    var di = pointData.cd[pointData.index];\n    var trace = pointData.cd[0].trace;\n\n    if(!trace.cumulative.enabled) {\n        var posLetter = trace.orientation === 'h' ? 'y' : 'x';\n\n        pointData[posLetter + 'Label'] = hoverLabelText(pointData[posLetter + 'a'], di.ph0, di.ph1);\n    }\n\n    if(trace.hovermplate) pointData.hovertemplate = trace.hovertemplate;\n\n    return pts;\n};\n\n},{\"../../plots/cartesian/axes\":767,\"../bar/hover\":863}],1030:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * Histogram has its own attribute, defaults and calc steps,\n * but uses bar's plot to display\n * and bar's crossTraceCalc (formerly known as setPositions) for stacking and grouping\n */\n\n/**\n * histogram errorBarsOK is debatable, but it's put in for backward compat.\n * there are use cases for it - sqrt for a simple histogram works right now,\n * constant and % work but they're not so meaningful. I guess it could be cool\n * to allow quadrature combination of errors in summed histograms...\n */\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('../bar/layout_attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    crossTraceDefaults: _dereq_('./cross_trace_defaults'),\n    supplyLayoutDefaults: _dereq_('../bar/layout_defaults'),\n    calc: _dereq_('./calc').calc,\n    crossTraceCalc: _dereq_('../bar/cross_trace_calc').crossTraceCalc,\n    plot: _dereq_('../bar/plot').plot,\n    layerName: 'barlayer',\n    style: _dereq_('../bar/style').style,\n    styleOnSelect: _dereq_('../bar/style').styleOnSelect,\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n    hoverPoints: _dereq_('./hover'),\n    selectPoints: _dereq_('../bar/select'),\n    eventData: _dereq_('./event_data'),\n\n    moduleType: 'trace',\n    name: 'histogram',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['bar-like', 'cartesian', 'svg', 'bar', 'histogram', 'oriented', 'errorBarsOK', 'showLegend'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../bar/cross_trace_calc\":860,\"../bar/layout_attributes\":865,\"../bar/layout_defaults\":866,\"../bar/plot\":867,\"../bar/select\":868,\"../bar/style\":870,\"../scatter/marker_colorbar\":1129,\"./attributes\":1019,\"./calc\":1024,\"./cross_trace_defaults\":1026,\"./defaults\":1027,\"./event_data\":1028,\"./hover\":1029}],1031:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nmodule.exports = {\n    percent: function(size, total) {\n        var nMax = size.length;\n        var norm = 100 / total;\n        for(var n = 0; n < nMax; n++) size[n] *= norm;\n    },\n    probability: function(size, total) {\n        var nMax = size.length;\n        for(var n = 0; n < nMax; n++) size[n] /= total;\n    },\n    density: function(size, total, inc, yinc) {\n        var nMax = size.length;\n        yinc = yinc || 1;\n        for(var n = 0; n < nMax; n++) size[n] *= inc[n] * yinc;\n    },\n    'probability density': function(size, total, inc, yinc) {\n        var nMax = size.length;\n        if(yinc) total /= yinc;\n        for(var n = 0; n < nMax; n++) size[n] *= inc[n] / total;\n    }\n};\n\n},{}],1032:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar histogramAttrs = _dereq_('../histogram/attributes');\nvar makeBinAttrs = _dereq_('../histogram/bin_attributes');\nvar heatmapAttrs = _dereq_('../heatmap/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = extendFlat(\n    {\n        x: histogramAttrs.x,\n        y: histogramAttrs.y,\n\n        z: {\n            valType: 'data_array',\n            editType: 'calc',\n            \n        },\n        marker: {\n            color: {\n                valType: 'data_array',\n                editType: 'calc',\n                \n            },\n            editType: 'calc'\n        },\n\n        histnorm: histogramAttrs.histnorm,\n        histfunc: histogramAttrs.histfunc,\n        nbinsx: histogramAttrs.nbinsx,\n        xbins: makeBinAttrs('x'),\n        nbinsy: histogramAttrs.nbinsy,\n        ybins: makeBinAttrs('y'),\n        autobinx: histogramAttrs.autobinx,\n        autobiny: histogramAttrs.autobiny,\n\n        bingroup: extendFlat({}, histogramAttrs.bingroup, {\n            \n        }),\n        xbingroup: extendFlat({}, histogramAttrs.bingroup, {\n            \n        }),\n        ybingroup: extendFlat({}, histogramAttrs.bingroup, {\n            \n        }),\n\n        xgap: heatmapAttrs.xgap,\n        ygap: heatmapAttrs.ygap,\n        zsmooth: heatmapAttrs.zsmooth,\n        zhoverformat: heatmapAttrs.zhoverformat,\n        hovertemplate: hovertemplateAttrs({}, {keys: 'z'})\n    },\n    colorScaleAttrs('', {cLetter: 'z', autoColorDflt: false})\n);\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../heatmap/attributes\":1001,\"../histogram/attributes\":1019,\"../histogram/bin_attributes\":1021}],1033:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nvar binFunctions = _dereq_('../histogram/bin_functions');\nvar normFunctions = _dereq_('../histogram/norm_functions');\nvar doAvg = _dereq_('../histogram/average');\nvar getBinSpanLabelRound = _dereq_('../histogram/bin_label_vals');\nvar calcAllAutoBins = _dereq_('../histogram/calc').calcAllAutoBins;\n\nmodule.exports = function calc(gd, trace) {\n    var xa = Axes.getFromId(gd, trace.xaxis);\n    var ya = Axes.getFromId(gd, trace.yaxis);\n\n    var xcalendar = trace.xcalendar;\n    var ycalendar = trace.ycalendar;\n    var xr2c = function(v) { return xa.r2c(v, 0, xcalendar); };\n    var yr2c = function(v) { return ya.r2c(v, 0, ycalendar); };\n    var xc2r = function(v) { return xa.c2r(v, 0, xcalendar); };\n    var yc2r = function(v) { return ya.c2r(v, 0, ycalendar); };\n\n    var i, j, n, m;\n\n    // calculate the bins\n    var xBinsAndPos = calcAllAutoBins(gd, trace, xa, 'x');\n    var xBinSpec = xBinsAndPos[0];\n    var xPos0 = xBinsAndPos[1];\n    var yBinsAndPos = calcAllAutoBins(gd, trace, ya, 'y');\n    var yBinSpec = yBinsAndPos[0];\n    var yPos0 = yBinsAndPos[1];\n\n    var serieslen = trace._length;\n    if(xPos0.length > serieslen) xPos0.splice(serieslen, xPos0.length - serieslen);\n    if(yPos0.length > serieslen) yPos0.splice(serieslen, yPos0.length - serieslen);\n\n    // make the empty bin array & scale the map\n    var z = [];\n    var onecol = [];\n    var zerocol = [];\n    var nonuniformBinsX = typeof xBinSpec.size === 'string';\n    var nonuniformBinsY = typeof yBinSpec.size === 'string';\n    var xEdges = [];\n    var yEdges = [];\n    var xbins = nonuniformBinsX ? xEdges : xBinSpec;\n    var ybins = nonuniformBinsY ? yEdges : yBinSpec;\n    var total = 0;\n    var counts = [];\n    var inputPoints = [];\n    var norm = trace.histnorm;\n    var func = trace.histfunc;\n    var densitynorm = norm.indexOf('density') !== -1;\n    var extremefunc = func === 'max' || func === 'min';\n    var sizeinit = extremefunc ? null : 0;\n    var binfunc = binFunctions.count;\n    var normfunc = normFunctions[norm];\n    var doavg = false;\n    var xinc = [];\n    var yinc = [];\n\n    // set a binning function other than count?\n    // for binning functions: check first for 'z',\n    // then 'mc' in case we had a colored scatter plot\n    // and want to transfer these colors to the 2D histo\n    // TODO: axe this, make it the responsibility of the app changing type? or an impliedEdit?\n    var rawCounterData = ('z' in trace) ?\n        trace.z :\n        (('marker' in trace && Array.isArray(trace.marker.color)) ?\n            trace.marker.color : '');\n    if(rawCounterData && func !== 'count') {\n        doavg = func === 'avg';\n        binfunc = binFunctions[func];\n    }\n\n    // decrease end a little in case of rounding errors\n    var xBinSize = xBinSpec.size;\n    var xBinStart = xr2c(xBinSpec.start);\n    var xBinEnd = xr2c(xBinSpec.end) +\n        (xBinStart - Axes.tickIncrement(xBinStart, xBinSize, false, xcalendar)) / 1e6;\n\n    for(i = xBinStart; i < xBinEnd; i = Axes.tickIncrement(i, xBinSize, false, xcalendar)) {\n        onecol.push(sizeinit);\n        xEdges.push(i);\n        if(doavg) zerocol.push(0);\n    }\n    xEdges.push(i);\n\n    var nx = onecol.length;\n    var dx = (i - xBinStart) / nx;\n    var x0 = xc2r(xBinStart + dx / 2);\n\n    var yBinSize = yBinSpec.size;\n    var yBinStart = yr2c(yBinSpec.start);\n    var yBinEnd = yr2c(yBinSpec.end) +\n        (yBinStart - Axes.tickIncrement(yBinStart, yBinSize, false, ycalendar)) / 1e6;\n\n    for(i = yBinStart; i < yBinEnd; i = Axes.tickIncrement(i, yBinSize, false, ycalendar)) {\n        z.push(onecol.slice());\n        yEdges.push(i);\n        var ipCol = new Array(nx);\n        for(j = 0; j < nx; j++) ipCol[j] = [];\n        inputPoints.push(ipCol);\n        if(doavg) counts.push(zerocol.slice());\n    }\n    yEdges.push(i);\n\n    var ny = z.length;\n    var dy = (i - yBinStart) / ny;\n    var y0 = yc2r(yBinStart + dy / 2);\n\n    if(densitynorm) {\n        xinc = makeIncrements(onecol.length, xbins, dx, nonuniformBinsX);\n        yinc = makeIncrements(z.length, ybins, dy, nonuniformBinsY);\n    }\n\n    // for date axes we need bin bounds to be calcdata. For nonuniform bins\n    // we already have this, but uniform with start/end/size they're still strings.\n    if(!nonuniformBinsX && xa.type === 'date') xbins = binsToCalc(xr2c, xbins);\n    if(!nonuniformBinsY && ya.type === 'date') ybins = binsToCalc(yr2c, ybins);\n\n    // put data into bins\n    var uniqueValsPerX = true;\n    var uniqueValsPerY = true;\n    var xVals = new Array(nx);\n    var yVals = new Array(ny);\n    var xGapLow = Infinity;\n    var xGapHigh = Infinity;\n    var yGapLow = Infinity;\n    var yGapHigh = Infinity;\n    for(i = 0; i < serieslen; i++) {\n        var xi = xPos0[i];\n        var yi = yPos0[i];\n        n = Lib.findBin(xi, xbins);\n        m = Lib.findBin(yi, ybins);\n        if(n >= 0 && n < nx && m >= 0 && m < ny) {\n            total += binfunc(n, i, z[m], rawCounterData, counts[m]);\n            inputPoints[m][n].push(i);\n\n            if(uniqueValsPerX) {\n                if(xVals[n] === undefined) xVals[n] = xi;\n                else if(xVals[n] !== xi) uniqueValsPerX = false;\n            }\n            if(uniqueValsPerY) {\n                if(yVals[m] === undefined) yVals[m] = yi;\n                else if(yVals[m] !== yi) uniqueValsPerY = false;\n            }\n\n            xGapLow = Math.min(xGapLow, xi - xEdges[n]);\n            xGapHigh = Math.min(xGapHigh, xEdges[n + 1] - xi);\n            yGapLow = Math.min(yGapLow, yi - yEdges[m]);\n            yGapHigh = Math.min(yGapHigh, yEdges[m + 1] - yi);\n        }\n    }\n    // normalize, if needed\n    if(doavg) {\n        for(m = 0; m < ny; m++) total += doAvg(z[m], counts[m]);\n    }\n    if(normfunc) {\n        for(m = 0; m < ny; m++) normfunc(z[m], total, xinc, yinc[m]);\n    }\n\n    return {\n        x: xPos0,\n        xRanges: getRanges(xEdges, uniqueValsPerX && xVals, xGapLow, xGapHigh, xa, xcalendar),\n        x0: x0,\n        dx: dx,\n        y: yPos0,\n        yRanges: getRanges(yEdges, uniqueValsPerY && yVals, yGapLow, yGapHigh, ya, ycalendar),\n        y0: y0,\n        dy: dy,\n        z: z,\n        pts: inputPoints\n    };\n};\n\nfunction makeIncrements(len, bins, dv, nonuniform) {\n    var out = new Array(len);\n    var i;\n    if(nonuniform) {\n        for(i = 0; i < len; i++) out[i] = 1 / (bins[i + 1] - bins[i]);\n    } else {\n        var inc = 1 / dv;\n        for(i = 0; i < len; i++) out[i] = inc;\n    }\n    return out;\n}\n\nfunction binsToCalc(r2c, bins) {\n    return {\n        start: r2c(bins.start),\n        end: r2c(bins.end),\n        size: bins.size\n    };\n}\n\nfunction getRanges(edges, uniqueVals, gapLow, gapHigh, ax, calendar) {\n    var i;\n    var len = edges.length - 1;\n    var out = new Array(len);\n    var roundFn = getBinSpanLabelRound(gapLow, gapHigh, edges, ax, calendar);\n\n    for(i = 0; i < len; i++) {\n        var v = (uniqueVals || [])[i];\n        out[i] = v === undefined ?\n            [roundFn(edges[i]), roundFn(edges[i + 1], true)] :\n            [v, v];\n    }\n    return out;\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../histogram/average\":1020,\"../histogram/bin_functions\":1022,\"../histogram/bin_label_vals\":1023,\"../histogram/calc\":1024,\"../histogram/norm_functions\":1031}],1034:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleSampleDefaults = _dereq_('./sample_defaults');\nvar handleStyleDefaults = _dereq_('../heatmap/style_defaults');\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    handleSampleDefaults(traceIn, traceOut, coerce, layout);\n    if(traceOut.visible === false) return;\n\n    handleStyleDefaults(traceIn, traceOut, coerce, layout);\n    colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});\n    coerce('hovertemplate');\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"../heatmap/style_defaults\":1014,\"./attributes\":1032,\"./sample_defaults\":1037}],1035:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar heatmapHover = _dereq_('../heatmap/hover');\nvar hoverLabelText = _dereq_('../../plots/cartesian/axes').hoverLabelText;\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer, contour) {\n    var pts = heatmapHover(pointData, xval, yval, hovermode, hoverLayer, contour);\n\n    if(!pts) return;\n\n    pointData = pts[0];\n    var indices = pointData.index;\n    var ny = indices[0];\n    var nx = indices[1];\n    var cd0 = pointData.cd[0];\n    var xRange = cd0.xRanges[nx];\n    var yRange = cd0.yRanges[ny];\n\n    pointData.xLabel = hoverLabelText(pointData.xa, xRange[0], xRange[1]);\n    pointData.yLabel = hoverLabelText(pointData.ya, yRange[0], yRange[1]);\n\n    return pts;\n};\n\n},{\"../../plots/cartesian/axes\":767,\"../heatmap/hover\":1008}],1036:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    crossTraceDefaults: _dereq_('../histogram/cross_trace_defaults'),\n    calc: _dereq_('../heatmap/calc'),\n    plot: _dereq_('../heatmap/plot'),\n    layerName: 'heatmaplayer',\n    colorbar: _dereq_('../heatmap/colorbar'),\n    style: _dereq_('../heatmap/style'),\n    hoverPoints: _dereq_('./hover'),\n    eventData: _dereq_('../histogram/event_data'),\n\n    moduleType: 'trace',\n    name: 'histogram2d',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', '2dMap', 'histogram'],\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../heatmap/calc\":1002,\"../heatmap/colorbar\":1004,\"../heatmap/plot\":1012,\"../heatmap/style\":1013,\"../histogram/cross_trace_defaults\":1026,\"../histogram/event_data\":1028,\"./attributes\":1032,\"./defaults\":1034,\"./hover\":1035}],1037:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function handleSampleDefaults(traceIn, traceOut, coerce, layout) {\n    var x = coerce('x');\n    var y = coerce('y');\n    var xlen = Lib.minRowLength(x);\n    var ylen = Lib.minRowLength(y);\n\n    // we could try to accept x0 and dx, etc...\n    // but that's a pretty weird use case.\n    // for now require both x and y explicitly specified.\n    if(!xlen || !ylen) {\n        traceOut.visible = false;\n        return;\n    }\n\n    traceOut._length = Math.min(xlen, ylen);\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);\n\n    // if marker.color is an array, we can use it in aggregation instead of z\n    var hasAggregationData = coerce('z') || coerce('marker.color');\n\n    if(hasAggregationData) coerce('histfunc');\n    coerce('histnorm');\n\n    // Note: bin defaults are now handled in Histogram2D.crossTraceDefaults\n    // autobin(x|y) are only included here to appease Plotly.validate\n    coerce('autobinx');\n    coerce('autobiny');\n};\n\n},{\"../../lib\":719,\"../../registry\":847}],1038:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar histogram2dAttrs = _dereq_('../histogram2d/attributes');\nvar contourAttrs = _dereq_('../contour/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = extendFlat({\n    x: histogram2dAttrs.x,\n    y: histogram2dAttrs.y,\n    z: histogram2dAttrs.z,\n    marker: histogram2dAttrs.marker,\n\n    histnorm: histogram2dAttrs.histnorm,\n    histfunc: histogram2dAttrs.histfunc,\n    nbinsx: histogram2dAttrs.nbinsx,\n    xbins: histogram2dAttrs.xbins,\n    nbinsy: histogram2dAttrs.nbinsy,\n    ybins: histogram2dAttrs.ybins,\n    autobinx: histogram2dAttrs.autobinx,\n    autobiny: histogram2dAttrs.autobiny,\n\n    bingroup: histogram2dAttrs.bingroup,\n    xbingroup: histogram2dAttrs.xbingroup,\n    ybingroup: histogram2dAttrs.ybingroup,\n\n    autocontour: contourAttrs.autocontour,\n    ncontours: contourAttrs.ncontours,\n    contours: contourAttrs.contours,\n    line: contourAttrs.line,\n    zhoverformat: histogram2dAttrs.zhoverformat,\n    hovertemplate: histogram2dAttrs.hovertemplate\n},\n    colorScaleAttrs('', {\n        cLetter: 'z',\n        editTypeOverride: 'calc'\n    })\n);\n\n},{\"../../components/colorscale/attributes\":600,\"../../lib/extend\":710,\"../contour/attributes\":942,\"../histogram2d/attributes\":1032}],1039:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleSampleDefaults = _dereq_('../histogram2d/sample_defaults');\nvar handleContoursDefaults = _dereq_('../contour/contours_defaults');\nvar handleStyleDefaults = _dereq_('../contour/style_defaults');\nvar attributes = _dereq_('./attributes');\n\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    function coerce2(attr) {\n        return Lib.coerce2(traceIn, traceOut, attributes, attr);\n    }\n\n    handleSampleDefaults(traceIn, traceOut, coerce, layout);\n    if(traceOut.visible === false) return;\n\n    handleContoursDefaults(traceIn, traceOut, coerce, coerce2);\n    handleStyleDefaults(traceIn, traceOut, coerce, layout);\n    coerce('hovertemplate');\n};\n\n},{\"../../lib\":719,\"../contour/contours_defaults\":949,\"../contour/style_defaults\":963,\"../histogram2d/sample_defaults\":1037,\"./attributes\":1038}],1040:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    crossTraceDefaults: _dereq_('../histogram/cross_trace_defaults'),\n    calc: _dereq_('../contour/calc'),\n    plot: _dereq_('../contour/plot').plot,\n    layerName: 'contourlayer',\n    style: _dereq_('../contour/style'),\n    colorbar: _dereq_('../contour/colorbar'),\n    hoverPoints: _dereq_('../contour/hover'),\n\n    moduleType: 'trace',\n    name: 'histogram2dcontour',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', '2dMap', 'contour', 'histogram', 'showLegend'],\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../contour/calc\":943,\"../contour/colorbar\":945,\"../contour/hover\":955,\"../contour/plot\":960,\"../contour/style\":962,\"../histogram/cross_trace_defaults\":1026,\"./attributes\":1038,\"./defaults\":1039}],1041:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar extendDeep = _dereq_('../../lib/extend').extendDeep;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\nvar axesAttrs = _dereq_('../../plots/cartesian/layout_attributes');\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\nvar delta = _dereq_('../../constants/delta.js');\nvar FORMAT_LINK = _dereq_('../../constants/docs').FORMAT_LINK;\n\nvar textFontAttrs = fontAttrs({\n    editType: 'plot',\n    colorEditType: 'plot'\n});\n\nvar gaugeBarAttrs = {\n    color: {\n        valType: 'color',\n        editType: 'plot',\n        \n        \n    },\n    line: {\n        color: {\n            valType: 'color',\n            \n            dflt: colorAttrs.defaultLine,\n            editType: 'plot',\n            \n        },\n        width: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 0,\n            editType: 'plot',\n            \n        },\n        editType: 'calc'\n    },\n    thickness: {\n        valType: 'number',\n        \n        min: 0,\n        max: 1,\n        dflt: 1,\n        editType: 'plot',\n        \n    },\n    editType: 'calc'\n};\n\nvar rangeAttr = {\n    valType: 'info_array',\n    \n    items: [\n            {valType: 'number', editType: 'plot'},\n            {valType: 'number', editType: 'plot'}\n    ],\n    editType: 'plot',\n    \n};\n\nvar stepsAttrs = templatedArray('steps', extendDeep({}, gaugeBarAttrs, {\n    range: rangeAttr\n}));\n\nmodule.exports = {\n    mode: {\n        valType: 'flaglist',\n        editType: 'calc',\n        \n        flags: ['number', 'delta', 'gauge'],\n        dflt: 'number',\n        \n    },\n    value: {\n        valType: 'number',\n        editType: 'calc',\n        \n        anim: true,\n        \n    },\n    align: {\n        valType: 'enumerated',\n        values: ['left', 'center', 'right'],\n        \n        editType: 'plot',\n        \n    },\n    // position\n    domain: domainAttrs({name: 'indicator', trace: true, editType: 'calc'}),\n\n    title: {\n        text: {\n            valType: 'string',\n            \n            editType: 'plot',\n            \n        },\n        align: {\n            valType: 'enumerated',\n            values: ['left', 'center', 'right'],\n            \n            editType: 'plot',\n            \n        },\n        font: extendFlat({}, textFontAttrs, {\n            \n        }),\n        editType: 'plot'\n    },\n    number: {\n        valueformat: {\n            valType: 'string',\n            dflt: '',\n            \n            editType: 'plot',\n            \n        },\n        font: extendFlat({}, textFontAttrs, {\n            \n        }),\n        prefix: {\n            valType: 'string',\n            dflt: '',\n            \n            editType: 'plot',\n            \n        },\n        suffix: {\n            valType: 'string',\n            dflt: '',\n            \n            editType: 'plot',\n            \n        },\n        editType: 'plot'\n    },\n    delta: {\n        reference: {\n            valType: 'number',\n            \n            editType: 'calc',\n            \n        },\n        position: {\n            valType: 'enumerated',\n            values: ['top', 'bottom', 'left', 'right'],\n            \n            dflt: 'bottom',\n            editType: 'plot',\n            \n        },\n        relative: {\n            valType: 'boolean',\n            editType: 'plot',\n            \n            dflt: false,\n            \n        },\n        valueformat: {\n            valType: 'string',\n            \n            editType: 'plot',\n            \n        },\n        increasing: {\n            symbol: {\n                valType: 'string',\n                \n                dflt: delta.INCREASING.SYMBOL,\n                editType: 'plot',\n                \n            },\n            color: {\n                valType: 'color',\n                \n                dflt: delta.INCREASING.COLOR,\n                editType: 'plot',\n                \n            },\n            // TODO: add attribute to show sign\n            editType: 'plot'\n        },\n        decreasing: {\n            symbol: {\n                valType: 'string',\n                \n                dflt: delta.DECREASING.SYMBOL,\n                editType: 'plot',\n                \n            },\n            color: {\n                valType: 'color',\n                \n                dflt: delta.DECREASING.COLOR,\n                editType: 'plot',\n                \n            },\n            // TODO: add attribute to hide sign\n            editType: 'plot'\n        },\n        font: extendFlat({}, textFontAttrs, {\n            \n        }),\n        editType: 'calc'\n    },\n    gauge: {\n        shape: {\n            valType: 'enumerated',\n            editType: 'plot',\n            \n            dflt: 'angular',\n            values: ['angular', 'bullet'],\n            \n        },\n        bar: extendDeep({}, gaugeBarAttrs, {\n            color: {dflt: 'green'},\n            \n        }),\n        // Background of the gauge\n        bgcolor: {\n            valType: 'color',\n            \n            editType: 'plot',\n            \n        },\n        bordercolor: {\n            valType: 'color',\n            dflt: colorAttrs.defaultLine,\n            \n            editType: 'plot',\n            \n        },\n        borderwidth: {\n            valType: 'number',\n            min: 0,\n            dflt: 1,\n            \n            editType: 'plot',\n            \n        },\n        axis: overrideAll({\n            range: rangeAttr,\n            visible: extendFlat({}, axesAttrs.visible, {\n                dflt: true\n            }),\n            // tick and title properties named and function exactly as in axes\n            tickmode: axesAttrs.tickmode,\n            nticks: axesAttrs.nticks,\n            tick0: axesAttrs.tick0,\n            dtick: axesAttrs.dtick,\n            tickvals: axesAttrs.tickvals,\n            ticktext: axesAttrs.ticktext,\n            ticks: extendFlat({}, axesAttrs.ticks, {dflt: 'outside'}),\n            ticklen: axesAttrs.ticklen,\n            tickwidth: axesAttrs.tickwidth,\n            tickcolor: axesAttrs.tickcolor,\n            showticklabels: axesAttrs.showticklabels,\n            tickfont: fontAttrs({\n                \n            }),\n            tickangle: axesAttrs.tickangle,\n            tickformat: axesAttrs.tickformat,\n            tickformatstops: axesAttrs.tickformatstops,\n            tickprefix: axesAttrs.tickprefix,\n            showtickprefix: axesAttrs.showtickprefix,\n            ticksuffix: axesAttrs.ticksuffix,\n            showticksuffix: axesAttrs.showticksuffix,\n            separatethousands: axesAttrs.separatethousands,\n            exponentformat: axesAttrs.exponentformat,\n            showexponent: axesAttrs.showexponent,\n            editType: 'plot'\n        }, 'plot'),\n        // Steps (or ranges) and thresholds\n        steps: stepsAttrs,\n        threshold: {\n            line: {\n                color: extendFlat({}, gaugeBarAttrs.line.color, {\n                    \n                }),\n                width: extendFlat({}, gaugeBarAttrs.line.width, {\n                    dflt: 1,\n                    \n                }),\n                editType: 'plot'\n            },\n            thickness: extendFlat({}, gaugeBarAttrs.thickness, {\n                dflt: 0.85,\n                \n            }),\n            value: {\n                valType: 'number',\n                editType: 'calc',\n                dflt: false,\n                \n                \n            },\n            editType: 'plot'\n        },\n        \n        editType: 'plot'\n        // TODO: in future version, add marker: (bar|needle)\n    }\n};\n\n},{\"../../components/color/attributes\":592,\"../../constants/delta.js\":689,\"../../constants/docs\":690,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plot_api/plot_template\":757,\"../../plots/cartesian/layout_attributes\":779,\"../../plots/domain\":792,\"../../plots/font_attributes\":793}],1042:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\n\nvar name = exports.name = 'indicator';\n\nexports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {\n    var _module = Registry.getModule(name);\n    var cdmodule = getModuleCalcData(gd.calcdata, _module)[0];\n    _module.plot(gd, cdmodule, transitionOpts, makeOnCompleteCallback);\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var had = (oldFullLayout._has && oldFullLayout._has(name));\n    var has = (newFullLayout._has && newFullLayout._has(name));\n\n    if(had && !has) {\n        oldFullLayout._indicatorlayer.selectAll('g.trace').remove();\n    }\n};\n\n},{\"../../plots/get_data\":802,\"../../registry\":847}],1043:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// var Lib = require('../../lib');\n\nfunction calc(gd, trace) {\n    var cd = [];\n\n    var lastReading = trace.value;\n    if(!(typeof trace._lastValue === 'number')) trace._lastValue = trace.value;\n    var secondLastReading = trace._lastValue;\n    var deltaRef = secondLastReading;\n    if(trace._hasDelta && typeof trace.delta.reference === 'number') {\n        deltaRef = trace.delta.reference;\n    }\n    cd[0] = {\n        y: lastReading,\n        lastY: secondLastReading,\n\n        delta: lastReading - deltaRef,\n        relativeDelta: (lastReading - deltaRef) / deltaRef,\n    };\n    return cd;\n}\n\nmodule.exports = {\n    calc: calc\n};\n\n},{}],1044:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    // Defaults for delta\n    defaultNumberFontSize: 80,\n    bulletNumberDomainSize: 0.25,\n    bulletPadding: 0.025,\n    innerRadius: 0.75,\n    valueThickness: 0.5, // thickness of value bars relative to full thickness,\n    titlePadding: 5,\n    horizontalPadding: 10\n};\n\n},{}],1045:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attributes = _dereq_('./attributes');\nvar handleDomainDefaults = _dereq_('../../plots/domain').defaults;\nvar Template = _dereq_('../../plot_api/plot_template');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\nvar cn = _dereq_('./constants.js');\n\nvar handleTickValueDefaults = _dereq_('../../plots/cartesian/tick_value_defaults');\nvar handleTickMarkDefaults = _dereq_('../../plots/cartesian/tick_mark_defaults');\nvar handleTickLabelDefaults = _dereq_('../../plots/cartesian/tick_label_defaults');\n\nfunction supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    handleDomainDefaults(traceOut, layout, coerce);\n\n    // Mode\n    coerce('mode');\n    traceOut._hasNumber = traceOut.mode.indexOf('number') !== -1;\n    traceOut._hasDelta = traceOut.mode.indexOf('delta') !== -1;\n    traceOut._hasGauge = traceOut.mode.indexOf('gauge') !== -1;\n\n    var value = coerce('value');\n    traceOut._range = [0, (typeof value === 'number' ? 1.5 * value : 1)];\n\n    // Number attributes\n    var auto = new Array(2);\n    var bignumberFontSize;\n    if(traceOut._hasNumber) {\n        coerce('number.valueformat');\n        coerce('number.font.color', layout.font.color);\n        coerce('number.font.family', layout.font.family);\n        coerce('number.font.size');\n        if(traceOut.number.font.size === undefined) {\n            traceOut.number.font.size = cn.defaultNumberFontSize;\n            auto[0] = true;\n        }\n        coerce('number.prefix');\n        coerce('number.suffix');\n        bignumberFontSize = traceOut.number.font.size;\n    }\n\n    // delta attributes\n    var deltaFontSize;\n    if(traceOut._hasDelta) {\n        coerce('delta.font.color', layout.font.color);\n        coerce('delta.font.family', layout.font.family);\n        coerce('delta.font.size');\n        if(traceOut.delta.font.size === undefined) {\n            traceOut.delta.font.size = (traceOut._hasNumber ? 0.5 : 1) * (bignumberFontSize || cn.defaultNumberFontSize);\n            auto[1] = true;\n        }\n        coerce('delta.reference', traceOut.value);\n        coerce('delta.relative');\n        coerce('delta.valueformat', traceOut.delta.relative ? '2%' : '');\n        coerce('delta.increasing.symbol');\n        coerce('delta.increasing.color');\n        coerce('delta.decreasing.symbol');\n        coerce('delta.decreasing.color');\n        coerce('delta.position');\n        deltaFontSize = traceOut.delta.font.size;\n    }\n    traceOut._scaleNumbers = (!traceOut._hasNumber || auto[0]) && (!traceOut._hasDelta || auto[1]) || false;\n\n    // Title attributes\n    coerce('title.font.color', layout.font.color);\n    coerce('title.font.family', layout.font.family);\n    coerce('title.font.size', 0.25 * (bignumberFontSize || deltaFontSize || cn.defaultNumberFontSize));\n    coerce('title.text');\n\n    // Gauge attributes\n    var gaugeIn, gaugeOut, axisIn, axisOut;\n    function coerceGauge(attr, dflt) {\n        return Lib.coerce(gaugeIn, gaugeOut, attributes.gauge, attr, dflt);\n    }\n    function coerceGaugeAxis(attr, dflt) {\n        return Lib.coerce(axisIn, axisOut, attributes.gauge.axis, attr, dflt);\n    }\n\n    if(traceOut._hasGauge) {\n        gaugeIn = traceIn.gauge;\n        if(!gaugeIn) gaugeIn = {};\n        gaugeOut = Template.newContainer(traceOut, 'gauge');\n        coerceGauge('shape');\n        var isBullet = traceOut._isBullet = traceOut.gauge.shape === 'bullet';\n        if(!isBullet) {\n            coerce('title.align', 'center');\n        }\n        var isAngular = traceOut._isAngular = traceOut.gauge.shape === 'angular';\n        if(!isAngular) {\n            coerce('align', 'center');\n        }\n\n        // gauge background\n        coerceGauge('bgcolor', layout.paper_bgcolor);\n        coerceGauge('borderwidth');\n        coerceGauge('bordercolor');\n\n        // gauge bar indicator\n        coerceGauge('bar.color');\n        coerceGauge('bar.line.color');\n        coerceGauge('bar.line.width');\n        var defaultBarThickness = cn.valueThickness * (traceOut.gauge.shape === 'bullet' ? 0.5 : 1);\n        coerceGauge('bar.thickness', defaultBarThickness);\n\n        // Gauge steps\n        handleArrayContainerDefaults(gaugeIn, gaugeOut, {\n            name: 'steps',\n            handleItemDefaults: stepDefaults\n        });\n\n        // Gauge threshold\n        coerceGauge('threshold.value');\n        coerceGauge('threshold.thickness');\n        coerceGauge('threshold.line.width');\n        coerceGauge('threshold.line.color');\n\n        // Gauge axis\n        axisIn = {};\n        if(gaugeIn) axisIn = gaugeIn.axis || {};\n        axisOut = Template.newContainer(gaugeOut, 'axis');\n        coerceGaugeAxis('visible');\n        traceOut._range = coerceGaugeAxis('range', traceOut._range);\n\n        var opts = {outerTicks: true};\n        handleTickValueDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear');\n        handleTickLabelDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear', opts);\n        handleTickMarkDefaults(axisIn, axisOut, coerceGaugeAxis, opts);\n    } else {\n        coerce('title.align', 'center');\n        coerce('align', 'center');\n        traceOut._isAngular = traceOut._isBullet = false;\n    }\n\n    // disable 1D transforms\n    traceOut._length = null;\n}\n\nfunction stepDefaults(stepIn, stepOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(stepIn, stepOut, attributes.gauge.steps, attr, dflt);\n    }\n\n    coerce('color');\n    coerce('line.color');\n    coerce('line.width');\n    coerce('range');\n    coerce('thickness');\n}\n\nmodule.exports = {\n    supplyDefaults: supplyDefaults\n};\n\n},{\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../plots/array_container_defaults\":763,\"../../plots/cartesian/tick_label_defaults\":786,\"../../plots/cartesian/tick_mark_defaults\":787,\"../../plots/cartesian/tick_value_defaults\":788,\"../../plots/domain\":792,\"./attributes\":1041,\"./constants.js\":1044}],1046:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'indicator',\n    basePlotModule: _dereq_('./base_plot'),\n    categories: ['svg', 'noOpacity', 'noHover'],\n    animatable: true,\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults').supplyDefaults,\n\n    calc: _dereq_('./calc').calc,\n\n    plot: _dereq_('./plot'),\n\n    meta: {\n        \n    }\n};\n\n},{\"./attributes\":1041,\"./base_plot\":1042,\"./calc\":1043,\"./defaults\":1045,\"./plot\":1047}],1047:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../../lib');\nvar rad2deg = Lib.rad2deg;\nvar MID_SHIFT = _dereq_('../../constants/alignment').MID_SHIFT;\nvar Drawing = _dereq_('../../components/drawing');\nvar cn = _dereq_('./constants');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar handleAxisDefaults = _dereq_('../../plots/cartesian/axis_defaults');\nvar handleAxisPositionDefaults = _dereq_('../../plots/cartesian/position_defaults');\nvar axisLayoutAttrs = _dereq_('../../plots/cartesian/layout_attributes');\n\nvar Color = _dereq_('../../components/color');\nvar anchor = {\n    'left': 'start',\n    'center': 'middle',\n    'right': 'end'\n};\nvar position = {\n    'left': 0,\n    'center': 0.5,\n    'right': 1\n};\n\nvar SI_PREFIX = /[yzafpnµmkMGTPEZY]/;\n\nfunction hasTransition(transitionOpts) {\n    // If transition config is provided, then it is only a partial replot and traces not\n    // updated are removed.\n    return transitionOpts && transitionOpts.duration > 0;\n}\n\nmodule.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallback) {\n    var fullLayout = gd._fullLayout;\n    var onComplete;\n\n    if(hasTransition(transitionOpts)) {\n        if(makeOnCompleteCallback) {\n            // If it was passed a callback to register completion, make a callback. If\n            // this is created, then it must be executed on completion, otherwise the\n            // pos-transition redraw will not execute:\n            onComplete = makeOnCompleteCallback();\n        }\n    }\n\n    Lib.makeTraceGroups(fullLayout._indicatorlayer, cdModule, 'trace').each(function(cd) {\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n\n        var plotGroup = d3.select(this);\n\n        // Elements in trace\n        var hasGauge = trace._hasGauge;\n        var isAngular = trace._isAngular;\n        var isBullet = trace._isBullet;\n\n        // Domain size\n        var domain = trace.domain;\n        var size = {\n            w: fullLayout._size.w * (domain.x[1] - domain.x[0]),\n            h: fullLayout._size.h * (domain.y[1] - domain.y[0]),\n            l: fullLayout._size.l + fullLayout._size.w * domain.x[0],\n            r: fullLayout._size.r + fullLayout._size.w * (1 - domain.x[1]),\n            t: fullLayout._size.t + fullLayout._size.h * (1 - domain.y[1]),\n            b: fullLayout._size.b + fullLayout._size.h * (domain.y[0])\n        };\n        var centerX = size.l + size.w / 2;\n        var centerY = size.t + size.h / 2;\n\n        // Angular gauge size\n        var radius = Math.min(size.w / 2, size.h); // fill domain\n        var innerRadius = cn.innerRadius * radius;\n\n        // Position numbers based on mode and set the scaling logic\n        var numbersX, numbersY, numbersScaler;\n        var numbersAlign = trace.align || 'center';\n\n        numbersY = centerY;\n        if(!hasGauge) {\n            numbersX = size.l + position[numbersAlign] * size.w;\n            numbersScaler = function(el) {\n                return fitTextInsideBox(el, size.w, size.h);\n            };\n        } else {\n            if(isAngular) {\n                numbersX = centerX;\n                numbersY = centerY + radius / 2;\n                numbersScaler = function(el) {\n                    return fitTextInsideCircle(el, 0.9 * innerRadius);\n                };\n            }\n            if(isBullet) {\n                var padding = cn.bulletPadding;\n                var p = (1 - cn.bulletNumberDomainSize) + padding;\n                numbersX = size.l + (p + (1 - p) * position[numbersAlign]) * size.w;\n                numbersScaler = function(el) {\n                    return fitTextInsideBox(el, (cn.bulletNumberDomainSize - padding) * size.w, size.h);\n                };\n            }\n        }\n\n        // Draw numbers\n        drawNumbers(gd, plotGroup, cd, {\n            numbersX: numbersX,\n            numbersY: numbersY,\n            numbersScaler: numbersScaler,\n            transitionOpts: transitionOpts,\n            onComplete: onComplete\n        });\n\n        // Reexpress our gauge background attributes for drawing\n        var gaugeBg, gaugeOutline;\n        if(hasGauge) {\n            gaugeBg = {\n                range: trace.gauge.axis.range,\n                color: trace.gauge.bgcolor,\n                line: {\n                    color: trace.gauge.bordercolor,\n                    width: 0\n                },\n                thickness: 1\n            };\n\n            gaugeOutline = {\n                range: trace.gauge.axis.range,\n                color: 'rgba(0, 0, 0, 0)',\n                line: {\n                    color: trace.gauge.bordercolor,\n                    width: trace.gauge.borderwidth\n                },\n                thickness: 1\n            };\n        }\n\n        // Prepare angular gauge layers\n        var angularGauge = plotGroup.selectAll('g.angular').data(isAngular ? cd : []);\n        angularGauge.exit().remove();\n        var angularaxisLayer = plotGroup.selectAll('g.angularaxis').data(isAngular ? cd : []);\n        angularaxisLayer.exit().remove();\n\n        if(isAngular) {\n            drawAngularGauge(gd, plotGroup, cd, {\n                radius: radius,\n                innerRadius: innerRadius,\n\n                gauge: angularGauge,\n                layer: angularaxisLayer,\n                size: size,\n                gaugeBg: gaugeBg,\n                gaugeOutline: gaugeOutline,\n                transitionOpts: transitionOpts,\n                onComplete: onComplete\n            });\n        }\n\n        // Prepare bullet layers\n        var bulletGauge = plotGroup.selectAll('g.bullet').data(isBullet ? cd : []);\n        bulletGauge.exit().remove();\n        var bulletaxisLayer = plotGroup.selectAll('g.bulletaxis').data(isBullet ? cd : []);\n        bulletaxisLayer.exit().remove();\n\n        if(isBullet) {\n            drawBulletGauge(gd, plotGroup, cd, {\n                gauge: bulletGauge,\n                layer: bulletaxisLayer,\n                size: size,\n                gaugeBg: gaugeBg,\n                gaugeOutline: gaugeOutline,\n                transitionOpts: transitionOpts,\n                onComplete: onComplete\n            });\n        }\n\n        // title\n        var title = plotGroup.selectAll('text.title').data(cd);\n        title.exit().remove();\n        title.enter().append('text').classed('title', true);\n        title\n            .attr('text-anchor', function() {\n                return isBullet ? anchor.right : anchor[trace.title.align];\n            })\n            .text(trace.title.text)\n            .call(Drawing.font, trace.title.font)\n            .call(svgTextUtils.convertToTspans, gd);\n\n        // Position title\n        title.attr('transform', function() {\n            var titleX = size.l + size.w * position[trace.title.align];\n            var titleY;\n            var titlePadding = cn.titlePadding;\n            var titlebBox = Drawing.bBox(title.node());\n            if(hasGauge) {\n                if(isAngular) {\n                    // position above axis ticks/labels\n                    if(trace.gauge.axis.visible) {\n                        var bBox = Drawing.bBox(angularaxisLayer.node());\n                        titleY = (bBox.top - titlePadding) - titlebBox.bottom;\n                    } else {\n                        titleY = size.t + size.h / 2 - radius / 2 - titlebBox.bottom - titlePadding;\n                    }\n                }\n                if(isBullet) {\n                    // position outside domain\n                    titleY = numbersY - (titlebBox.top + titlebBox.bottom) / 2;\n                    titleX = size.l - cn.bulletPadding * size.w; // Outside domain, on the left\n                }\n            } else {\n                // position above numbers\n                titleY = (trace._numbersTop - titlePadding) - titlebBox.bottom;\n            }\n            return strTranslate(titleX, titleY);\n        });\n    });\n};\n\nfunction drawBulletGauge(gd, plotGroup, cd, opts) {\n    var trace = cd[0].trace;\n\n    var bullet = opts.gauge;\n    var axisLayer = opts.layer;\n    var gaugeBg = opts.gaugeBg;\n    var gaugeOutline = opts.gaugeOutline;\n    var size = opts.size;\n    var domain = trace.domain;\n\n    var transitionOpts = opts.transitionOpts;\n    var onComplete = opts.onComplete;\n\n    // preparing axis\n    var ax, vals, transFn, tickSign, shift;\n\n    // Enter bullet, axis\n    bullet.enter().append('g').classed('bullet', true);\n    bullet.attr('transform', 'translate(' + size.l + ', ' + size.t + ')');\n\n    axisLayer.enter().append('g')\n        .classed('bulletaxis', true)\n        .classed('crisp', true);\n    axisLayer.selectAll('g.' + 'xbulletaxis' + 'tick,path,text').remove();\n\n    // Draw bullet\n    var bulletHeight = size.h; // use all vertical domain\n    var innerBulletHeight = trace.gauge.bar.thickness * bulletHeight;\n    var bulletLeft = domain.x[0];\n    var bulletRight = domain.x[0] + (domain.x[1] - domain.x[0]) * ((trace._hasNumber || trace._hasDelta) ? (1 - cn.bulletNumberDomainSize) : 1);\n\n    ax = mockAxis(gd, trace.gauge.axis);\n    ax._id = 'xbulletaxis';\n    ax.domain = [bulletLeft, bulletRight];\n    ax.setScale();\n\n    vals = Axes.calcTicks(ax);\n    transFn = Axes.makeTransFn(ax);\n    tickSign = Axes.getTickSigns(ax)[2];\n\n    shift = size.t + size.h;\n    if(ax.visible) {\n        Axes.drawTicks(gd, ax, {\n            vals: ax.ticks === 'inside' ? Axes.clipEnds(ax, vals) : vals,\n            layer: axisLayer,\n            path: Axes.makeTickPath(ax, shift, tickSign),\n            transFn: transFn\n        });\n\n        Axes.drawLabels(gd, ax, {\n            vals: vals,\n            layer: axisLayer,\n            transFn: transFn,\n            labelFns: Axes.makeLabelFns(ax, shift)\n        });\n    }\n\n    function drawRect(s) {\n        s\n            .attr('width', function(d) { return Math.max(0, ax.c2p(d.range[1]) - ax.c2p(d.range[0]));})\n            .attr('x', function(d) { return ax.c2p(d.range[0]);})\n            .attr('y', function(d) { return 0.5 * (1 - d.thickness) * bulletHeight;})\n            .attr('height', function(d) { return d.thickness * bulletHeight; });\n    }\n\n    // Draw bullet background, steps\n    var boxes = [gaugeBg].concat(trace.gauge.steps);\n    var bgBullet = bullet.selectAll('g.bg-bullet').data(boxes);\n    bgBullet.enter().append('g').classed('bg-bullet', true).append('rect');\n    bgBullet.select('rect')\n        .call(drawRect)\n        .call(styleShape);\n    bgBullet.exit().remove();\n\n    // Draw value bar with transitions\n    var fgBullet = bullet.selectAll('g.value-bullet').data([trace.gauge.bar]);\n    fgBullet.enter().append('g').classed('value-bullet', true).append('rect');\n    fgBullet.select('rect')\n        .attr('height', innerBulletHeight)\n        .attr('y', (bulletHeight - innerBulletHeight) / 2)\n        .call(styleShape);\n    if(hasTransition(transitionOpts)) {\n        fgBullet.select('rect')\n            .transition()\n            .duration(transitionOpts.duration)\n            .ease(transitionOpts.easing)\n            .each('end', function() { onComplete && onComplete(); })\n            .each('interrupt', function() { onComplete && onComplete(); })\n            .attr('width', Math.max(0, ax.c2p(Math.min(trace.gauge.axis.range[1], cd[0].y))));\n    } else {\n        fgBullet.select('rect')\n            .attr('width', typeof cd[0].y === 'number' ?\n                Math.max(0, ax.c2p(Math.min(trace.gauge.axis.range[1], cd[0].y))) :\n                0);\n    }\n    fgBullet.exit().remove();\n\n    var data = cd.filter(function() {return trace.gauge.threshold.value;});\n    var threshold = bullet.selectAll('g.threshold-bullet').data(data);\n    threshold.enter().append('g').classed('threshold-bullet', true).append('line');\n    threshold.select('line')\n        .attr('x1', ax.c2p(trace.gauge.threshold.value))\n        .attr('x2', ax.c2p(trace.gauge.threshold.value))\n        .attr('y1', (1 - trace.gauge.threshold.thickness) / 2 * bulletHeight)\n        .attr('y2', (1 - (1 - trace.gauge.threshold.thickness) / 2) * bulletHeight)\n        .call(Color.stroke, trace.gauge.threshold.line.color)\n        .style('stroke-width', trace.gauge.threshold.line.width);\n    threshold.exit().remove();\n\n    var bulletOutline = bullet.selectAll('g.gauge-outline').data([gaugeOutline]);\n    bulletOutline.enter().append('g').classed('gauge-outline', true).append('rect');\n    bulletOutline.select('rect')\n        .call(drawRect)\n        .call(styleShape);\n    bulletOutline.exit().remove();\n}\n\nfunction drawAngularGauge(gd, plotGroup, cd, opts) {\n    var trace = cd[0].trace;\n\n    var size = opts.size;\n    var radius = opts.radius;\n    var innerRadius = opts.innerRadius;\n    var gaugeBg = opts.gaugeBg;\n    var gaugeOutline = opts.gaugeOutline;\n    var gaugePosition = [size.l + size.w / 2, size.t + size.h / 2 + radius / 2];\n    var gauge = opts.gauge;\n    var axisLayer = opts.layer;\n\n    var transitionOpts = opts.transitionOpts;\n    var onComplete = opts.onComplete;\n\n    // circular gauge\n    var theta = Math.PI / 2;\n    function valueToAngle(v) {\n        var min = trace.gauge.axis.range[0];\n        var max = trace.gauge.axis.range[1];\n        var angle = (v - min) / (max - min) * Math.PI - theta;\n        if(angle < -theta) return -theta;\n        if(angle > theta) return theta;\n        return angle;\n    }\n\n    function arcPathGenerator(size) {\n        return d3.svg.arc()\n                  .innerRadius((innerRadius + radius) / 2 - size / 2 * (radius - innerRadius))\n                  .outerRadius((innerRadius + radius) / 2 + size / 2 * (radius - innerRadius))\n                  .startAngle(-theta);\n    }\n\n    function drawArc(p) {\n        p\n            .attr('d', function(d) {\n                return arcPathGenerator(d.thickness)\n                  .startAngle(valueToAngle(d.range[0]))\n                  .endAngle(valueToAngle(d.range[1]))();\n            });\n    }\n\n    // preparing axis\n    var ax, vals, transFn, tickSign;\n\n    // Enter gauge and axis\n    gauge.enter().append('g').classed('angular', true);\n    gauge.attr('transform', strTranslate(gaugePosition[0], gaugePosition[1]));\n\n    axisLayer.enter().append('g')\n        .classed('angularaxis', true)\n        .classed('crisp', true);\n    axisLayer.selectAll('g.' + 'xangularaxis' + 'tick,path,text').remove();\n\n    ax = mockAxis(gd, trace.gauge.axis);\n    ax.type = 'linear';\n    ax.range = trace.gauge.axis.range;\n    ax._id = 'xangularaxis'; // or 'y', but I don't think this makes a difference here\n    ax.setScale();\n\n    // 't'ick to 'g'eometric radians is used all over the place here\n    var t2g = function(d) {\n        return (ax.range[0] - d.x) / (ax.range[1] - ax.range[0]) * Math.PI + Math.PI;\n    };\n\n    var labelFns = {};\n    var out = Axes.makeLabelFns(ax, 0);\n    var labelStandoff = out.labelStandoff;\n    labelFns.xFn = function(d) {\n        var rad = t2g(d);\n        return Math.cos(rad) * labelStandoff;\n    };\n    labelFns.yFn = function(d) {\n        var rad = t2g(d);\n        var ff = Math.sin(rad) > 0 ? 0.2 : 1;\n        return -Math.sin(rad) * (labelStandoff + d.fontSize * ff) +\n                Math.abs(Math.cos(rad)) * (d.fontSize * MID_SHIFT);\n    };\n    labelFns.anchorFn = function(d) {\n        var rad = t2g(d);\n        var cos = Math.cos(rad);\n        return Math.abs(cos) < 0.1 ?\n                'middle' :\n                (cos > 0 ? 'start' : 'end');\n    };\n    labelFns.heightFn = function(d, a, h) {\n        var rad = t2g(d);\n        return -0.5 * (1 + Math.sin(rad)) * h;\n    };\n    var _transFn = function(rad) {\n        return strTranslate(\n            gaugePosition[0] + radius * Math.cos(rad),\n            gaugePosition[1] - radius * Math.sin(rad)\n        );\n    };\n    transFn = function(d) {\n        return _transFn(t2g(d));\n    };\n    var transFn2 = function(d) {\n        var rad = t2g(d);\n        return _transFn(rad) + 'rotate(' + -rad2deg(rad) + ')';\n    };\n    vals = Axes.calcTicks(ax);\n    tickSign = Axes.getTickSigns(ax)[2];\n    if(ax.visible) {\n        tickSign = ax.ticks === 'inside' ? -1 : 1;\n        var pad = (ax.linewidth || 1) / 2;\n        Axes.drawTicks(gd, ax, {\n            vals: vals,\n            layer: axisLayer,\n            path: 'M' + (tickSign * pad) + ',0h' + (tickSign * ax.ticklen),\n            transFn: transFn2\n        });\n        Axes.drawLabels(gd, ax, {\n            vals: vals,\n            layer: axisLayer,\n            transFn: transFn,\n            labelFns: labelFns\n        });\n    }\n\n    // Draw background + steps\n    var arcs = [gaugeBg].concat(trace.gauge.steps);\n    var bgArc = gauge.selectAll('g.bg-arc').data(arcs);\n    bgArc.enter().append('g').classed('bg-arc', true).append('path');\n    bgArc.select('path').call(drawArc).call(styleShape);\n    bgArc.exit().remove();\n\n    // Draw foreground with transition\n    var valueArcPathGenerator = arcPathGenerator(trace.gauge.bar.thickness);\n    var valueArc = gauge.selectAll('g.value-arc').data([trace.gauge.bar]);\n    valueArc.enter().append('g').classed('value-arc', true).append('path');\n    var valueArcPath = valueArc.select('path');\n    if(hasTransition(transitionOpts)) {\n        valueArcPath\n            .transition()\n            .duration(transitionOpts.duration)\n            .ease(transitionOpts.easing)\n            .each('end', function() { onComplete && onComplete(); })\n            .each('interrupt', function() { onComplete && onComplete(); })\n            .attrTween('d', arcTween(valueArcPathGenerator, valueToAngle(cd[0].lastY), valueToAngle(cd[0].y)));\n        trace._lastValue = cd[0].y;\n    } else {\n        valueArcPath.attr('d', typeof cd[0].y === 'number' ?\n            valueArcPathGenerator.endAngle(valueToAngle(cd[0].y)) :\n            'M0,0Z');\n    }\n    valueArcPath.call(styleShape);\n    valueArc.exit().remove();\n\n    // Draw threshold\n    arcs = [];\n    var v = trace.gauge.threshold.value;\n    if(v) {\n        arcs.push({\n            range: [v, v],\n            color: trace.gauge.threshold.color,\n            line: {\n                color: trace.gauge.threshold.line.color,\n                width: trace.gauge.threshold.line.width\n            },\n            thickness: trace.gauge.threshold.thickness\n        });\n    }\n    var thresholdArc = gauge.selectAll('g.threshold-arc').data(arcs);\n    thresholdArc.enter().append('g').classed('threshold-arc', true).append('path');\n    thresholdArc.select('path').call(drawArc).call(styleShape);\n    thresholdArc.exit().remove();\n\n    // Draw border last\n    var gaugeBorder = gauge.selectAll('g.gauge-outline').data([gaugeOutline]);\n    gaugeBorder.enter().append('g').classed('gauge-outline', true).append('path');\n    gaugeBorder.select('path').call(drawArc).call(styleShape);\n    gaugeBorder.exit().remove();\n}\n\nfunction drawNumbers(gd, plotGroup, cd, opts) {\n    var trace = cd[0].trace;\n\n    var numbersX = opts.numbersX;\n    var numbersY = opts.numbersY;\n    var numbersAlign = trace.align || 'center';\n    var numbersAnchor = anchor[numbersAlign];\n\n    var transitionOpts = opts.transitionOpts;\n    var onComplete = opts.onComplete;\n\n    var numbers = Lib.ensureSingle(plotGroup, 'g', 'numbers');\n    var bignumberbBox, deltabBox;\n    var numbersbBox;\n\n    var data = [];\n    if(trace._hasNumber) data.push('number');\n    if(trace._hasDelta) {\n        data.push('delta');\n        if(trace.delta.position === 'left') data.reverse();\n    }\n    var sel = numbers.selectAll('text').data(data);\n    sel.enter().append('text');\n    sel\n        .attr('text-anchor', function() {return numbersAnchor;})\n        .attr('class', function(d) { return d;})\n        .attr('x', null)\n        .attr('y', null)\n        .attr('dx', null)\n        .attr('dy', null);\n    sel.exit().remove();\n\n    // Function to override the number formatting used during transitions\n    function transitionFormat(valueformat, fmt, from, to) {\n        // For now, do not display SI prefix if start and end value do not have any\n        if(valueformat.match('s') && // If using SI prefix\n            (from >= 0 !== to >= 0) && // If sign change\n            (!fmt(from).slice(-1).match(SI_PREFIX) && !fmt(to).slice(-1).match(SI_PREFIX)) // Has no SI prefix\n        ) {\n            var transitionValueFormat = valueformat.slice().replace('s', 'f').replace(/\\d+/, function(m) { return parseInt(m) - 1;});\n            var transitionAx = mockAxis(gd, {tickformat: transitionValueFormat});\n            return function(v) {\n                // Switch to fixed precision if number is smaller than one\n                if(Math.abs(v) < 1) return Axes.tickText(transitionAx, v).text;\n                return fmt(v);\n            };\n        } else {\n            return fmt;\n        }\n    }\n\n    function drawBignumber() {\n        var bignumberAx = mockAxis(gd, {tickformat: trace.number.valueformat}, trace._range);\n        bignumberAx.setScale();\n        Axes.calcTicks(bignumberAx);\n\n        var fmt = function(v) { return Axes.tickText(bignumberAx, v).text;};\n        var bignumberSuffix = trace.number.suffix;\n        var bignumberPrefix = trace.number.prefix;\n\n        var number = numbers.select('text.number');\n\n        function writeNumber() {\n            var txt = typeof cd[0].y === 'number' ?\n                bignumberPrefix + fmt(cd[0].y) + bignumberSuffix :\n                '-';\n            number.text(txt)\n                .call(Drawing.font, trace.number.font)\n                .call(svgTextUtils.convertToTspans, gd);\n        }\n\n        if(hasTransition(transitionOpts)) {\n            number\n                .transition()\n                .duration(transitionOpts.duration)\n                .ease(transitionOpts.easing)\n                .each('end', function() { writeNumber(); onComplete && onComplete(); })\n                .each('interrupt', function() { writeNumber(); onComplete && onComplete(); })\n                .attrTween('text', function() {\n                    var that = d3.select(this);\n                    var interpolator = d3.interpolateNumber(cd[0].lastY, cd[0].y);\n                    trace._lastValue = cd[0].y;\n\n                    var transitionFmt = transitionFormat(trace.number.valueformat, fmt, cd[0].lastY, cd[0].y);\n                    return function(t) {\n                        that.text(bignumberPrefix + transitionFmt(interpolator(t)) + bignumberSuffix);\n                    };\n                });\n        } else {\n            writeNumber();\n        }\n\n        bignumberbBox = measureText(bignumberPrefix + fmt(cd[0].y) + bignumberSuffix, trace.number.font, numbersAnchor, gd);\n        return number;\n    }\n\n    function drawDelta() {\n        var deltaAx = mockAxis(gd, {tickformat: trace.delta.valueformat}, trace._range);\n        deltaAx.setScale();\n        Axes.calcTicks(deltaAx);\n\n        var deltaFmt = function(v) { return Axes.tickText(deltaAx, v).text;};\n        var deltaValue = function(d) {\n            var value = trace.delta.relative ? d.relativeDelta : d.delta;\n            return value;\n        };\n        var deltaFormatText = function(value, numberFmt) {\n            if(value === 0 || typeof value !== 'number' || isNaN(value)) return '-';\n            return (value > 0 ? trace.delta.increasing.symbol : trace.delta.decreasing.symbol) + numberFmt(value);\n        };\n        var deltaFill = function(d) {\n            return d.delta >= 0 ? trace.delta.increasing.color : trace.delta.decreasing.color;\n        };\n        if(trace._deltaLastValue === undefined) {\n            trace._deltaLastValue = deltaValue(cd[0]);\n        }\n        var delta = numbers.select('text.delta');\n        delta\n            .call(Drawing.font, trace.delta.font)\n            .call(Color.fill, deltaFill({delta: trace._deltaLastValue}));\n\n        function writeDelta() {\n            delta.text(deltaFormatText(deltaValue(cd[0]), deltaFmt))\n                .call(Color.fill, deltaFill(cd[0]))\n                .call(svgTextUtils.convertToTspans, gd);\n        }\n\n        if(hasTransition(transitionOpts)) {\n            delta\n                .transition()\n                .duration(transitionOpts.duration)\n                .ease(transitionOpts.easing)\n                .tween('text', function() {\n                    var that = d3.select(this);\n                    var to = deltaValue(cd[0]);\n                    var from = trace._deltaLastValue;\n                    var transitionFmt = transitionFormat(trace.delta.valueformat, deltaFmt, from, to);\n                    var interpolator = d3.interpolateNumber(from, to);\n                    trace._deltaLastValue = to;\n                    return function(t) {\n                        that.text(deltaFormatText(interpolator(t), transitionFmt));\n                        that.call(Color.fill, deltaFill({delta: interpolator(t)}));\n                    };\n                })\n                .each('end', function() { writeDelta(); onComplete && onComplete(); })\n                .each('interrupt', function() { writeDelta(); onComplete && onComplete(); });\n        } else {\n            writeDelta();\n        }\n\n        deltabBox = measureText(deltaFormatText(deltaValue(cd[0]), deltaFmt), trace.delta.font, numbersAnchor, gd);\n        return delta;\n    }\n\n    var key = trace.mode + trace.align;\n    var delta;\n    if(trace._hasDelta) {\n        delta = drawDelta();\n        key += trace.delta.position + trace.delta.font.size + trace.delta.font.family + trace.delta.valueformat;\n        key += trace.delta.increasing.symbol + trace.delta.decreasing.symbol;\n        numbersbBox = deltabBox;\n    }\n    if(trace._hasNumber) {\n        drawBignumber();\n        key += trace.number.font.size + trace.number.font.family + trace.number.valueformat + trace.number.suffix + trace.number.prefix;\n        numbersbBox = bignumberbBox;\n    }\n\n    // Position delta relative to bignumber\n    if(trace._hasDelta && trace._hasNumber) {\n        var bignumberCenter = [\n            (bignumberbBox.left + bignumberbBox.right) / 2,\n            (bignumberbBox.top + bignumberbBox.bottom) / 2\n        ];\n        var deltaCenter = [\n            (deltabBox.left + deltabBox.right) / 2,\n            (deltabBox.top + deltabBox.bottom) / 2\n        ];\n\n        var dx, dy;\n        var padding = 0.75 * trace.delta.font.size;\n        if(trace.delta.position === 'left') {\n            dx = cache(trace, 'deltaPos', 0, -1 * (bignumberbBox.width * (position[trace.align]) + deltabBox.width * (1 - position[trace.align]) + padding), key, Math.min);\n            dy = bignumberCenter[1] - deltaCenter[1];\n\n            numbersbBox = {\n                width: bignumberbBox.width + deltabBox.width + padding,\n                height: Math.max(bignumberbBox.height, deltabBox.height),\n                left: deltabBox.left + dx,\n                right: bignumberbBox.right,\n                top: Math.min(bignumberbBox.top, deltabBox.top + dy),\n                bottom: Math.max(bignumberbBox.bottom, deltabBox.bottom + dy)\n            };\n        }\n        if(trace.delta.position === 'right') {\n            dx = cache(trace, 'deltaPos', 0, bignumberbBox.width * (1 - position[trace.align]) + deltabBox.width * position[trace.align] + padding, key, Math.max);\n            dy = bignumberCenter[1] - deltaCenter[1];\n\n            numbersbBox = {\n                width: bignumberbBox.width + deltabBox.width + padding,\n                height: Math.max(bignumberbBox.height, deltabBox.height),\n                left: bignumberbBox.left,\n                right: deltabBox.right + dx,\n                top: Math.min(bignumberbBox.top, deltabBox.top + dy),\n                bottom: Math.max(bignumberbBox.bottom, deltabBox.bottom + dy)\n            };\n        }\n        if(trace.delta.position === 'bottom') {\n            dx = null;\n            dy = deltabBox.height;\n\n            numbersbBox = {\n                width: Math.max(bignumberbBox.width, deltabBox.width),\n                height: bignumberbBox.height + deltabBox.height,\n                left: Math.min(bignumberbBox.left, deltabBox.left),\n                right: Math.max(bignumberbBox.right, deltabBox.right),\n                top: bignumberbBox.bottom - bignumberbBox.height,\n                bottom: bignumberbBox.bottom + deltabBox.height\n            };\n        }\n        if(trace.delta.position === 'top') {\n            dx = null;\n            dy = bignumberbBox.top;\n\n            numbersbBox = {\n                width: Math.max(bignumberbBox.width, deltabBox.width),\n                height: bignumberbBox.height + deltabBox.height,\n                left: Math.min(bignumberbBox.left, deltabBox.left),\n                right: Math.max(bignumberbBox.right, deltabBox.right),\n                top: bignumberbBox.bottom - bignumberbBox.height - deltabBox.height,\n                bottom: bignumberbBox.bottom\n            };\n        }\n\n        delta.attr({dx: dx, dy: dy});\n    }\n\n    // Resize numbers to fit within space and position\n    if(trace._hasNumber || trace._hasDelta) {\n        numbers.attr('transform', function() {\n            var m = opts.numbersScaler(numbersbBox);\n            key += m[2];\n            var scaleRatio = cache(trace, 'numbersScale', 1, m[0], key, Math.min);\n            var translateY;\n            if(!trace._scaleNumbers) scaleRatio = 1;\n            if(trace._isAngular) {\n                // align vertically to bottom\n                translateY = numbersY - scaleRatio * numbersbBox.bottom;\n            } else {\n                // align vertically to center\n                translateY = numbersY - scaleRatio * (numbersbBox.top + numbersbBox.bottom) / 2;\n            }\n\n            // Stash the top position of numbersbBox for title positioning\n            trace._numbersTop = scaleRatio * (numbersbBox.top) + translateY;\n\n            var ref = numbersbBox[numbersAlign];\n            if(numbersAlign === 'center') ref = (numbersbBox.left + numbersbBox.right) / 2;\n            var translateX = numbersX - scaleRatio * ref;\n\n            // Stash translateX\n            translateX = cache(trace, 'numbersTranslate', 0, translateX, key, Math.max);\n            return strTranslate(translateX, translateY) + ' scale(' + scaleRatio + ')';\n        });\n    }\n}\n\n// Apply fill, stroke, stroke-width to SVG shape\nfunction styleShape(p) {\n    p\n        .each(function(d) { Color.stroke(d3.select(this), d.line.color);})\n        .each(function(d) { Color.fill(d3.select(this), d.color);})\n        .style('stroke-width', function(d) { return d.line.width;});\n}\n\n// Returns a tween for a transition’s \"d\" attribute, transitioning any selected\n// arcs from their current angle to the specified new angle.\nfunction arcTween(arc, endAngle, newAngle) {\n    return function() {\n        var interpolate = d3.interpolate(endAngle, newAngle);\n        return function(t) {\n            return arc.endAngle(interpolate(t))();\n        };\n    };\n}\n\n// mocks our axis\nfunction mockAxis(gd, opts, zrange) {\n    var fullLayout = gd._fullLayout;\n\n    var axisIn = Lib.extendFlat({\n        type: 'linear',\n        ticks: 'outside',\n        range: zrange,\n        showline: true\n    }, opts);\n\n    var axisOut = {\n        type: 'linear',\n        _id: 'x' + opts._id\n    };\n\n    var axisOptions = {\n        letter: 'x',\n        font: fullLayout.font,\n        noHover: true,\n        noTickson: true\n    };\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(axisIn, axisOut, axisLayoutAttrs, attr, dflt);\n    }\n\n    handleAxisDefaults(axisIn, axisOut, coerce, axisOptions, fullLayout);\n    handleAxisPositionDefaults(axisIn, axisOut, coerce, axisOptions);\n\n    return axisOut;\n}\n\nfunction strTranslate(x, y) {\n    return 'translate(' + x + ',' + y + ')';\n}\n\nfunction fitTextInsideBox(textBB, width, height) {\n    // compute scaling ratio to have text fit within specified width and height\n    var ratio = Math.min(width / textBB.width, height / textBB.height);\n    return [ratio, textBB, width + 'x' + height];\n}\n\nfunction fitTextInsideCircle(textBB, radius) {\n    // compute scaling ratio to have text fit within specified radius\n    var elRadius = Math.sqrt((textBB.width / 2) * (textBB.width / 2) + textBB.height * textBB.height);\n    var ratio = radius / elRadius;\n    return [ratio, textBB, radius];\n}\n\nfunction measureText(txt, font, textAnchor, gd) {\n    var element = document.createElementNS('http://www.w3.org/2000/svg', 'text');\n    var sel = d3.select(element);\n    sel.text(txt)\n      .attr('x', 0)\n      .attr('y', 0)\n      .attr('text-anchor', textAnchor)\n      .attr('data-unformatted', txt)\n      .call(svgTextUtils.convertToTspans, gd)\n      .call(Drawing.font, font);\n    return Drawing.bBox(sel.node());\n}\n\nfunction cache(trace, name, initialValue, value, key, fn) {\n    var objName = '_cache' + name;\n    if(!(trace[objName] && trace[objName].key === key)) {\n        trace[objName] = {key: key, value: initialValue};\n    }\n    var v = Lib.aggNums(fn, null, [trace[objName].value, value], 2);\n    trace[objName].value = v;\n\n    return v;\n}\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../constants/alignment\":688,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plots/cartesian/axes\":767,\"../../plots/cartesian/axis_defaults\":769,\"../../plots/cartesian/layout_attributes\":779,\"../../plots/cartesian/position_defaults\":782,\"./constants\":1044,\"d3\":163}],1048:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar meshAttrs = _dereq_('../mesh3d/attributes');\nvar baseAttrs = _dereq_('../../plots/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nfunction makeSliceAttr(axLetter) {\n    return {\n        show: {\n            valType: 'boolean',\n            \n            dflt: false,\n            \n        },\n        locations: {\n            valType: 'data_array',\n            dflt: [],\n            \n            \n        },\n        fill: {\n            valType: 'number',\n            \n            min: 0,\n            max: 1,\n            dflt: 1,\n            \n        }\n    };\n}\n\nfunction makeCapAttr(axLetter) {\n    return {\n        show: {\n            valType: 'boolean',\n            \n            dflt: true,\n            \n        },\n        fill: {\n            valType: 'number',\n            \n            min: 0,\n            max: 1,\n            dflt: 1,\n            \n        }\n    };\n}\n\nvar attrs = module.exports = overrideAll(extendFlat({\n    x: {\n        valType: 'data_array',\n        \n        \n    },\n    y: {\n        valType: 'data_array',\n        \n        \n    },\n    z: {\n        valType: 'data_array',\n        \n        \n    },\n    value: {\n        valType: 'data_array',\n        \n        \n    },\n    isomin: {\n        valType: 'number',\n        \n        \n    },\n    isomax: {\n        valType: 'number',\n        \n        \n    },\n\n    surface: {\n        show: {\n            valType: 'boolean',\n            \n            dflt: true,\n            \n        },\n        count: {\n            valType: 'integer',\n            \n            dflt: 2,\n            min: 1,\n            \n        },\n        fill: {\n            valType: 'number',\n            \n            min: 0,\n            max: 1,\n            dflt: 1,\n            \n        },\n        pattern: {\n            valType: 'flaglist',\n            flags: ['A', 'B', 'C', 'D', 'E'],\n            extras: ['all', 'odd', 'even'],\n            dflt: 'all',\n            \n            \n        }\n    },\n\n    spaceframe: {\n        show: {\n            valType: 'boolean',\n            \n            dflt: false,\n            \n        },\n        fill: {\n            valType: 'number',\n            \n            min: 0,\n            max: 1,\n            dflt: 0.15,\n            \n        }\n    },\n\n    slices: {\n        x: makeSliceAttr('x'),\n        y: makeSliceAttr('y'),\n        z: makeSliceAttr('z')\n    },\n\n    caps: {\n        x: makeCapAttr('x'),\n        y: makeCapAttr('y'),\n        z: makeCapAttr('z')\n    },\n\n    text: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        \n    },\n    hovertemplate: hovertemplateAttrs()\n},\n\ncolorScaleAttrs('', {\n    colorAttr: '`value`',\n    showScaleDflt: true,\n    editTypeOverride: 'calc'\n}), {\n    opacity: meshAttrs.opacity,\n    lightposition: meshAttrs.lightposition,\n    lighting: meshAttrs.lighting,\n    flatshading: meshAttrs.flatshading,\n    contour: meshAttrs.contour,\n\n    hoverinfo: extendFlat({}, baseAttrs.hoverinfo)\n}), 'calc', 'nested');\n\n// required defaults to speed up surface normal calculations\nattrs.flatshading.dflt = true; attrs.lighting.facenormalsepsilon.dflt = 0;\n\nattrs.x.editType = attrs.y.editType = attrs.z.editType = attrs.value.editType = 'calc+clearAxisTypes';\nattrs.transforms = undefined;\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/attributes\":764,\"../mesh3d/attributes\":1053}],1049:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\n\nmodule.exports = function calc(gd, trace) {\n    trace._len = Math.min(trace.x.length, trace.y.length, trace.z.length, trace.value.length);\n\n    var min = Infinity;\n    var max = -Infinity;\n    var len = trace.value.length;\n    for(var i = 0; i < len; i++) {\n        var v = trace.value[i];\n        min = Math.min(min, v);\n        max = Math.max(max, v);\n    }\n\n    trace._minValues = min;\n    trace._maxValues = max;\n\n    trace._vMin = (trace.isomin === undefined || trace.isomin === null) ? min : trace.isomin;\n    trace._vMax = (trace.isomax === undefined || trace.isomin === null) ? max : trace.isomax;\n\n    colorscaleCalc(gd, trace, {\n        vals: [trace._vMin, trace._vMax],\n        containerStr: '',\n        cLetter: 'c'\n    });\n};\n\n},{\"../../components/colorscale/calc\":601}],1050:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar createMesh = _dereq_('gl-mesh3d');\n\nvar Lib = _dereq_('../../lib');\n\nvar parseColorScale = _dereq_('../../lib/gl_format_color').parseColorScale;\nvar str2RgbaArray = _dereq_('../../lib/str2rgbarray');\nvar extractOpts = _dereq_('../../components/colorscale').extractOpts;\nvar zip3 = _dereq_('../../plots/gl3d/zip3');\n\nfunction distinctVals(col) {\n    return Lib.distinctVals(col).vals;\n}\n\nvar findNearestOnAxis = function(w, arr) {\n    for(var q = arr.length - 1; q > 0; q--) {\n        var min = Math.min(arr[q], arr[q - 1]);\n        var max = Math.max(arr[q], arr[q - 1]);\n        if(max > min && min < w && w <= max) {\n            return {\n                id: q,\n                distRatio: (max - w) / (max - min)\n            };\n        }\n    }\n    return {\n        id: 0,\n        distRatio: 0\n    };\n};\n\nfunction IsosurfaceTrace(scene, mesh, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.mesh = mesh;\n    this.name = '';\n    this.data = null;\n    this.showContour = false;\n}\n\nvar proto = IsosurfaceTrace.prototype;\n\nproto.handlePick = function(selection) {\n    if(selection.object === this.mesh) {\n        var rawId = selection.data.index;\n\n        var x = this.data._x[rawId];\n        var y = this.data._y[rawId];\n        var z = this.data._z[rawId];\n\n        var height = this.data._Ys.length;\n        var depth = this.data._Zs.length;\n\n        var i = findNearestOnAxis(x, this.data._Xs).id;\n        var j = findNearestOnAxis(y, this.data._Ys).id;\n        var k = findNearestOnAxis(z, this.data._Zs).id;\n\n        var selectIndex = selection.index = k + depth * j + depth * height * i;\n\n        selection.traceCoordinate = [\n            this.data._x[selectIndex],\n            this.data._y[selectIndex],\n            this.data._z[selectIndex],\n            this.data.value[selectIndex]\n        ];\n\n        var text = this.data.hovertext || this.data.text;\n        if(Array.isArray(text) && text[selectIndex] !== undefined) {\n            selection.textLabel = text[selectIndex];\n        } else if(text) {\n            selection.textLabel = text;\n        }\n\n        return true;\n    }\n};\n\nproto.update = function(data) {\n    var scene = this.scene;\n    var layout = scene.fullSceneLayout;\n\n    this.data = generateIsoMeshes(data);\n\n    // Unpack position data\n    function toDataCoords(axis, coord, scale, calendar) {\n        return coord.map(function(x) {\n            return axis.d2l(x, 0, calendar) * scale;\n        });\n    }\n\n    var positions = zip3(\n        toDataCoords(layout.xaxis, data._x, scene.dataScale[0], data.xcalendar),\n        toDataCoords(layout.yaxis, data._y, scene.dataScale[1], data.ycalendar),\n        toDataCoords(layout.zaxis, data._z, scene.dataScale[2], data.zcalendar));\n\n    var cells = zip3(data._i, data._j, data._k);\n\n    var config = {\n        positions: positions,\n        cells: cells,\n        lightPosition: [data.lightposition.x, data.lightposition.y, data.lightposition.z],\n        ambient: data.lighting.ambient,\n        diffuse: data.lighting.diffuse,\n        specular: data.lighting.specular,\n        roughness: data.lighting.roughness,\n        fresnel: data.lighting.fresnel,\n        vertexNormalsEpsilon: data.lighting.vertexnormalsepsilon,\n        faceNormalsEpsilon: data.lighting.facenormalsepsilon,\n        opacity: data.opacity,\n        contourEnable: data.contour.show,\n        contourColor: str2RgbaArray(data.contour.color).slice(0, 3),\n        contourWidth: data.contour.width,\n        useFacetNormals: data.flatshading\n    };\n\n    var cOpts = extractOpts(data);\n    config.vertexIntensity = data._intensity;\n    config.vertexIntensityBounds = [cOpts.min, cOpts.max];\n    config.colormap = parseColorScale(data);\n\n    // Update mesh\n    this.mesh.update(config);\n};\n\nproto.dispose = function() {\n    this.scene.glplot.remove(this.mesh);\n    this.mesh.dispose();\n};\n\nfunction generateIsoMeshes(data) {\n    data._i = [];\n    data._j = [];\n    data._k = [];\n\n    var showSurface = data.surface.show;\n    var showSpaceframe = data.spaceframe.show;\n\n    var surfaceFill = data.surface.fill;\n    var spaceframeFill = data.spaceframe.fill;\n\n    var drawingSurface = false;\n    var drawingSpaceframe = false;\n\n    var numFaces = 0;\n    var numVertices;\n    var beginVertextLength;\n\n    var Xs = distinctVals(data.x.slice(0, data._len));\n    var Ys = distinctVals(data.y.slice(0, data._len));\n    var Zs = distinctVals(data.z.slice(0, data._len));\n\n    var width = Xs.length;\n    var height = Ys.length;\n    var depth = Zs.length;\n\n    function getIndex(i, j, k) {\n        return k + depth * j + depth * height * i;\n    }\n\n    var minValues = data._minValues;\n    var maxValues = data._maxValues;\n\n    var vMin = data._vMin;\n    var vMax = data._vMax;\n\n    var allXs;\n    var allYs;\n    var allZs;\n    var allVs;\n\n    function findVertexId(x, y, z) {\n        // could be used to find the vertex id of previously generated vertex within the group\n\n        var len = allVs.length;\n        for(var f = beginVertextLength; f < len; f++) {\n            if(\n                x === allXs[f] &&\n                y === allYs[f] &&\n                z === allZs[f]\n            ) {\n                return f;\n            }\n        }\n        return -1;\n    }\n\n    function beginGroup() {\n        beginVertextLength = numVertices;\n    }\n\n    function emptyVertices() {\n        allXs = [];\n        allYs = [];\n        allZs = [];\n        allVs = [];\n        numVertices = 0;\n\n        beginGroup();\n    }\n\n    function addVertex(x, y, z, v) {\n        allXs.push(x);\n        allYs.push(y);\n        allZs.push(z);\n        allVs.push(v);\n        numVertices++;\n\n        return numVertices - 1;\n    }\n\n    function addFace(a, b, c) {\n        data._i.push(a);\n        data._j.push(b);\n        data._k.push(c);\n        numFaces++;\n\n        return numFaces - 1;\n    }\n\n    function getCenter(A, B, C) {\n        var M = [];\n        for(var i = 0; i < A.length; i++) {\n            M[i] = (A[i] + B[i] + C[i]) / 3.0;\n        }\n        return M;\n    }\n\n    function getBetween(A, B, r) {\n        var M = [];\n        for(var i = 0; i < A.length; i++) {\n            M[i] = A[i] * (1 - r) + r * B[i];\n        }\n        return M;\n    }\n\n    var activeFill;\n    function setFill(fill) {\n        activeFill = fill;\n    }\n\n    function createOpenTri(xyzv, abc) {\n        var A = xyzv[0];\n        var B = xyzv[1];\n        var C = xyzv[2];\n        var G = getCenter(A, B, C);\n\n        var r = Math.sqrt(1 - activeFill);\n        var p1 = getBetween(G, A, r);\n        var p2 = getBetween(G, B, r);\n        var p3 = getBetween(G, C, r);\n\n        var a = abc[0];\n        var b = abc[1];\n        var c = abc[2];\n\n        return {\n            xyzv: [\n                [A, B, p2], [p2, p1, A],\n                [B, C, p3], [p3, p2, B],\n                [C, A, p1], [p1, p3, C]\n            ],\n            abc: [\n                [a, b, -1], [-1, -1, a],\n                [b, c, -1], [-1, -1, b],\n                [c, a, -1], [-1, -1, c]\n            ]\n        };\n    }\n\n    function styleIncludes(style, char) {\n        if(style === 'all' || style === null) return true;\n        return (style.indexOf(char) > -1);\n    }\n\n    function mapValue(style, value) {\n        if(style === null) return value;\n        return style;\n    }\n\n    function drawTri(style, xyzv, abc) {\n        beginGroup();\n\n        var allXYZVs = [xyzv];\n        var allABCs = [abc];\n        if(activeFill >= 1) {\n            allXYZVs = [xyzv];\n            allABCs = [abc];\n        } else if(activeFill > 0) {\n            var openTri = createOpenTri(xyzv, abc);\n            allXYZVs = openTri.xyzv;\n            allABCs = openTri.abc;\n        }\n\n        for(var f = 0; f < allXYZVs.length; f++) {\n            xyzv = allXYZVs[f];\n            abc = allABCs[f];\n\n            var pnts = [];\n            for(var i = 0; i < 3; i++) {\n                var x = xyzv[i][0];\n                var y = xyzv[i][1];\n                var z = xyzv[i][2];\n                var v = xyzv[i][3];\n\n                var id = (abc[i] > -1) ? abc[i] : findVertexId(x, y, z);\n                if(id > -1) {\n                    pnts[i] = id;\n                } else {\n                    pnts[i] = addVertex(x, y, z, mapValue(style, v));\n                }\n            }\n\n            addFace(pnts[0], pnts[1], pnts[2]);\n        }\n    }\n\n    function drawQuad(style, xyzv, abcd) {\n        var makeTri = function(i, j, k) {\n            drawTri(style, [xyzv[i], xyzv[j], xyzv[k]], [abcd[i], abcd[j], abcd[k]]);\n        };\n\n        makeTri(0, 1, 2);\n        makeTri(2, 3, 0);\n    }\n\n    function drawTetra(style, xyzv, abcd) {\n        var makeTri = function(i, j, k) {\n            drawTri(style, [xyzv[i], xyzv[j], xyzv[k]], [abcd[i], abcd[j], abcd[k]]);\n        };\n\n        makeTri(0, 1, 2);\n        makeTri(3, 0, 1);\n        makeTri(2, 3, 0);\n        makeTri(1, 2, 3);\n    }\n\n    function calcIntersection(pointOut, pointIn, min, max) {\n        var value = pointOut[3];\n\n        if(value < min) value = min;\n        if(value > max) value = max;\n\n        var ratio = (pointOut[3] - value) / (pointOut[3] - pointIn[3] + 0.000000001); // we had to add this error to force solve the tiny caps\n\n        var result = [];\n        for(var s = 0; s < 4; s++) {\n            result[s] = (1 - ratio) * pointOut[s] + ratio * pointIn[s];\n        }\n        return result;\n    }\n\n    function inRange(value, min, max) {\n        return (\n            value >= min &&\n            value <= max\n        );\n    }\n\n    function almostInFinalRange(value) {\n        var vErr = 0.001 * (vMax - vMin);\n        return (\n            value >= vMin - vErr &&\n            value <= vMax + vErr\n        );\n    }\n\n    function getXYZV(indecies) {\n        var xyzv = [];\n        for(var q = 0; q < 4; q++) {\n            var index = indecies[q];\n            xyzv.push(\n                [\n                    data.x[index],\n                    data.y[index],\n                    data.z[index],\n                    data.value[index]\n                ]\n            );\n        }\n\n        return xyzv;\n    }\n\n    var MAX_PASS = 3;\n\n    function tryCreateTri(style, xyzv, abc, min, max, nPass) {\n        if(!nPass) nPass = 1;\n\n        abc = [-1, -1, -1]; // Note: for the moment we override indices\n        // to run faster! But it is possible to comment this line\n        // to reduce the number of vertices.\n\n        var result = false;\n\n        var ok = [\n            inRange(xyzv[0][3], min, max),\n            inRange(xyzv[1][3], min, max),\n            inRange(xyzv[2][3], min, max)\n        ];\n\n        if(!ok[0] && !ok[1] && !ok[2]) {\n            return false;\n        }\n\n        var tryDrawTri = function(style, xyzv, abc) {\n            if( // we check here if the points are in `real` iso-min/max range\n                almostInFinalRange(xyzv[0][3]) &&\n                almostInFinalRange(xyzv[1][3]) &&\n                almostInFinalRange(xyzv[2][3])\n            ) {\n                drawTri(style, xyzv, abc);\n                return true;\n            } else if(nPass < MAX_PASS) {\n                return tryCreateTri(style, xyzv, abc, vMin, vMax, ++nPass); // i.e. second pass using actual vMin vMax bounds\n            }\n            return false;\n        };\n\n        if(ok[0] && ok[1] && ok[2]) {\n            return tryDrawTri(style, xyzv, abc) || result;\n        }\n\n        var interpolated = false;\n\n        [\n            [0, 1, 2],\n            [2, 0, 1],\n            [1, 2, 0]\n        ].forEach(function(e) {\n            if(ok[e[0]] && ok[e[1]] && !ok[e[2]]) {\n                var A = xyzv[e[0]];\n                var B = xyzv[e[1]];\n                var C = xyzv[e[2]];\n\n                var p1 = calcIntersection(C, A, min, max);\n                var p2 = calcIntersection(C, B, min, max);\n\n                result = tryDrawTri(style, [p2, p1, A], [-1, -1, abc[e[0]]]) || result;\n                result = tryDrawTri(style, [A, B, p2], [abc[e[0]], abc[e[1]], -1]) || result;\n\n                interpolated = true;\n            }\n        });\n        if(interpolated) return result;\n\n        [\n            [0, 1, 2],\n            [1, 2, 0],\n            [2, 0, 1]\n        ].forEach(function(e) {\n            if(ok[e[0]] && !ok[e[1]] && !ok[e[2]]) {\n                var A = xyzv[e[0]];\n                var B = xyzv[e[1]];\n                var C = xyzv[e[2]];\n\n                var p1 = calcIntersection(B, A, min, max);\n                var p2 = calcIntersection(C, A, min, max);\n\n                result = tryDrawTri(style, [p2, p1, A], [-1, -1, abc[e[0]]]) || result;\n\n                interpolated = true;\n            }\n        });\n        return result;\n    }\n\n    function tryCreateTetra(style, abcd, min, max) {\n        var result = false;\n\n        var xyzv = getXYZV(abcd);\n\n        var ok = [\n            inRange(xyzv[0][3], min, max),\n            inRange(xyzv[1][3], min, max),\n            inRange(xyzv[2][3], min, max),\n            inRange(xyzv[3][3], min, max)\n        ];\n\n        if(!ok[0] && !ok[1] && !ok[2] && !ok[3]) {\n            return result;\n        }\n\n        if(ok[0] && ok[1] && ok[2] && ok[3]) {\n            if(drawingSpaceframe) {\n                result = drawTetra(style, xyzv, abcd) || result;\n            }\n            return result;\n        }\n\n        var interpolated = false;\n\n        [\n            [0, 1, 2, 3],\n            [3, 0, 1, 2],\n            [2, 3, 0, 1],\n            [1, 2, 3, 0]\n        ].forEach(function(e) {\n            if(ok[e[0]] && ok[e[1]] && ok[e[2]] && !ok[e[3]]) {\n                var A = xyzv[e[0]];\n                var B = xyzv[e[1]];\n                var C = xyzv[e[2]];\n                var D = xyzv[e[3]];\n\n                if(drawingSpaceframe) {\n                    result = drawTri(style, [A, B, C], [abcd[e[0]], abcd[e[1]], abcd[e[2]]]) || result;\n                } else {\n                    var p1 = calcIntersection(D, A, min, max);\n                    var p2 = calcIntersection(D, B, min, max);\n                    var p3 = calcIntersection(D, C, min, max);\n\n                    result = drawTri(null, [p1, p2, p3], [-1, -1, -1]) || result;\n                }\n\n                interpolated = true;\n            }\n        });\n        if(interpolated) return result;\n\n        [\n            [0, 1, 2, 3],\n            [1, 2, 3, 0],\n            [2, 3, 0, 1],\n            [3, 0, 1, 2],\n            [0, 2, 3, 1],\n            [1, 3, 2, 0]\n        ].forEach(function(e) {\n            if(ok[e[0]] && ok[e[1]] && !ok[e[2]] && !ok[e[3]]) {\n                var A = xyzv[e[0]];\n                var B = xyzv[e[1]];\n                var C = xyzv[e[2]];\n                var D = xyzv[e[3]];\n\n                var p1 = calcIntersection(C, A, min, max);\n                var p2 = calcIntersection(C, B, min, max);\n                var p3 = calcIntersection(D, B, min, max);\n                var p4 = calcIntersection(D, A, min, max);\n\n                if(drawingSpaceframe) {\n                    result = drawTri(style, [A, p4, p1], [abcd[e[0]], -1, -1]) || result;\n                    result = drawTri(style, [B, p2, p3], [abcd[e[1]], -1, -1]) || result;\n                } else {\n                    result = drawQuad(null, [p1, p2, p3, p4], [-1, -1, -1, -1]) || result;\n                }\n\n                interpolated = true;\n            }\n        });\n        if(interpolated) return result;\n\n        [\n            [0, 1, 2, 3],\n            [1, 2, 3, 0],\n            [2, 3, 0, 1],\n            [3, 0, 1, 2]\n        ].forEach(function(e) {\n            if(ok[e[0]] && !ok[e[1]] && !ok[e[2]] && !ok[e[3]]) {\n                var A = xyzv[e[0]];\n                var B = xyzv[e[1]];\n                var C = xyzv[e[2]];\n                var D = xyzv[e[3]];\n\n                var p1 = calcIntersection(B, A, min, max);\n                var p2 = calcIntersection(C, A, min, max);\n                var p3 = calcIntersection(D, A, min, max);\n\n                if(drawingSpaceframe) {\n                    result = drawTri(style, [A, p1, p2], [abcd[e[0]], -1, -1]) || result;\n                    result = drawTri(style, [A, p2, p3], [abcd[e[0]], -1, -1]) || result;\n                    result = drawTri(style, [A, p3, p1], [abcd[e[0]], -1, -1]) || result;\n                } else {\n                    result = drawTri(null, [p1, p2, p3], [-1, -1, -1]) || result;\n                }\n\n                interpolated = true;\n            }\n        });\n        return result;\n    }\n\n    function addCube(style, p000, p001, p010, p011, p100, p101, p110, p111, min, max) {\n        var result = false;\n\n        if(drawingSurface) {\n            if(styleIncludes(style, 'A')) {\n                result = tryCreateTetra(null, [p000, p001, p010, p100], min, max) || result;\n            }\n            if(styleIncludes(style, 'B')) {\n                result = tryCreateTetra(null, [p001, p010, p011, p111], min, max) || result;\n            }\n            if(styleIncludes(style, 'C')) {\n                result = tryCreateTetra(null, [p001, p100, p101, p111], min, max) || result;\n            }\n            if(styleIncludes(style, 'D')) {\n                result = tryCreateTetra(null, [p010, p100, p110, p111], min, max) || result;\n            }\n            if(styleIncludes(style, 'E')) {\n                result = tryCreateTetra(null, [p001, p010, p100, p111], min, max) || result;\n            }\n        }\n\n        if(drawingSpaceframe) {\n            result = tryCreateTetra(style, [p001, p010, p100, p111], min, max) || result;\n        }\n\n        return result;\n    }\n\n    function addRect(style, a, b, c, d, min, max, previousResult) {\n        return [\n            (previousResult[0] === true) ? true :\n            tryCreateTri(style, getXYZV([a, b, c]), [a, b, c], min, max),\n            (previousResult[1] === true) ? true :\n            tryCreateTri(style, getXYZV([c, d, a]), [c, d, a], min, max)\n        ];\n    }\n\n    function begin2dCell(style, p00, p01, p10, p11, min, max, isEven, previousResult) {\n        // used to create caps and/or slices on exact axis points\n        if(isEven) {\n            return addRect(style, p00, p01, p11, p10, min, max, previousResult);\n        } else {\n            return addRect(style, p01, p11, p10, p00, min, max, previousResult);\n        }\n    }\n\n    function beginSection(style, i, j, k, min, max, distRatios) {\n        // used to create slices between axis points\n\n        var result = false;\n        var A, B, C, D;\n\n        var makeSection = function() {\n            result = tryCreateTri(style, [A, B, C], [-1, -1, -1], min, max) || result;\n            result = tryCreateTri(style, [C, D, A], [-1, -1, -1], min, max) || result;\n        };\n\n        var rX = distRatios[0];\n        var rY = distRatios[1];\n        var rZ = distRatios[2];\n\n        if(rX) {\n            A = getBetween(getXYZV([getIndex(i, j - 0, k - 0)])[0], getXYZV([getIndex(i - 1, j - 0, k - 0)])[0], rX);\n            B = getBetween(getXYZV([getIndex(i, j - 0, k - 1)])[0], getXYZV([getIndex(i - 1, j - 0, k - 1)])[0], rX);\n            C = getBetween(getXYZV([getIndex(i, j - 1, k - 1)])[0], getXYZV([getIndex(i - 1, j - 1, k - 1)])[0], rX);\n            D = getBetween(getXYZV([getIndex(i, j - 1, k - 0)])[0], getXYZV([getIndex(i - 1, j - 1, k - 0)])[0], rX);\n            makeSection();\n        }\n\n        if(rY) {\n            A = getBetween(getXYZV([getIndex(i - 0, j, k - 0)])[0], getXYZV([getIndex(i - 0, j - 1, k - 0)])[0], rY);\n            B = getBetween(getXYZV([getIndex(i - 0, j, k - 1)])[0], getXYZV([getIndex(i - 0, j - 1, k - 1)])[0], rY);\n            C = getBetween(getXYZV([getIndex(i - 1, j, k - 1)])[0], getXYZV([getIndex(i - 1, j - 1, k - 1)])[0], rY);\n            D = getBetween(getXYZV([getIndex(i - 1, j, k - 0)])[0], getXYZV([getIndex(i - 1, j - 1, k - 0)])[0], rY);\n            makeSection();\n        }\n\n        if(rZ) {\n            A = getBetween(getXYZV([getIndex(i - 0, j - 0, k)])[0], getXYZV([getIndex(i - 0, j - 0, k - 1)])[0], rZ);\n            B = getBetween(getXYZV([getIndex(i - 0, j - 1, k)])[0], getXYZV([getIndex(i - 0, j - 1, k - 1)])[0], rZ);\n            C = getBetween(getXYZV([getIndex(i - 1, j - 1, k)])[0], getXYZV([getIndex(i - 1, j - 1, k - 1)])[0], rZ);\n            D = getBetween(getXYZV([getIndex(i - 1, j - 0, k)])[0], getXYZV([getIndex(i - 1, j - 0, k - 1)])[0], rZ);\n            makeSection();\n        }\n\n        return result;\n    }\n\n    function begin3dCell(style, p000, p001, p010, p011, p100, p101, p110, p111, min, max, isEven) {\n        // used to create spaceframe and/or iso-surfaces\n\n        var cellStyle = style;\n        if(isEven) {\n            if(drawingSurface && style === 'even') cellStyle = null;\n            return addCube(cellStyle, p000, p001, p010, p011, p100, p101, p110, p111, min, max);\n        } else {\n            if(drawingSurface && style === 'odd') cellStyle = null;\n            return addCube(cellStyle, p111, p110, p101, p100, p011, p010, p001, p000, min, max);\n        }\n    }\n\n    function draw2dX(style, items, min, max, previousResult) {\n        var result = [];\n        var n = 0;\n        for(var q = 0; q < items.length; q++) {\n            var i = items[q];\n            for(var k = 1; k < depth; k++) {\n                for(var j = 1; j < height; j++) {\n                    result.push(\n                        begin2dCell(style,\n                            getIndex(i, j - 1, k - 1),\n                            getIndex(i, j - 1, k),\n                            getIndex(i, j, k - 1),\n                            getIndex(i, j, k),\n                            min,\n                            max,\n                            (i + j + k) % 2,\n                            (previousResult && previousResult[n]) ? previousResult[n] : []\n                        )\n                    );\n                    n++;\n                }\n            }\n        }\n        return result;\n    }\n\n    function draw2dY(style, items, min, max, previousResult) {\n        var result = [];\n        var n = 0;\n        for(var q = 0; q < items.length; q++) {\n            var j = items[q];\n            for(var i = 1; i < width; i++) {\n                for(var k = 1; k < depth; k++) {\n                    result.push(\n                        begin2dCell(style,\n                            getIndex(i - 1, j, k - 1),\n                            getIndex(i, j, k - 1),\n                            getIndex(i - 1, j, k),\n                            getIndex(i, j, k),\n                            min,\n                            max,\n                            (i + j + k) % 2,\n                            (previousResult && previousResult[n]) ? previousResult[n] : []\n                        )\n                    );\n                    n++;\n                }\n            }\n        }\n        return result;\n    }\n\n    function draw2dZ(style, items, min, max, previousResult) {\n        var result = [];\n        var n = 0;\n        for(var q = 0; q < items.length; q++) {\n            var k = items[q];\n            for(var j = 1; j < height; j++) {\n                for(var i = 1; i < width; i++) {\n                    result.push(\n                        begin2dCell(style,\n                            getIndex(i - 1, j - 1, k),\n                            getIndex(i - 1, j, k),\n                            getIndex(i, j - 1, k),\n                            getIndex(i, j, k),\n                            min,\n                            max,\n                            (i + j + k) % 2,\n                            (previousResult && previousResult[n]) ? previousResult[n] : []\n                        )\n                    );\n                    n++;\n                }\n            }\n        }\n        return result;\n    }\n\n    function draw3d(style, min, max) {\n        for(var k = 1; k < depth; k++) {\n            for(var j = 1; j < height; j++) {\n                for(var i = 1; i < width; i++) {\n                    begin3dCell(style,\n                        getIndex(i - 1, j - 1, k - 1),\n                        getIndex(i - 1, j - 1, k),\n                        getIndex(i - 1, j, k - 1),\n                        getIndex(i - 1, j, k),\n                        getIndex(i, j - 1, k - 1),\n                        getIndex(i, j - 1, k),\n                        getIndex(i, j, k - 1),\n                        getIndex(i, j, k),\n                        min,\n                        max,\n                        (i + j + k) % 2\n                    );\n                }\n            }\n        }\n    }\n\n    function drawSpaceframe(style, min, max) {\n        drawingSpaceframe = true;\n        draw3d(style, min, max);\n        drawingSpaceframe = false;\n    }\n\n    function drawSurface(style, min, max) {\n        drawingSurface = true;\n        draw3d(style, min, max);\n        drawingSurface = false;\n    }\n\n    function drawSectionX(style, items, min, max, distRatios, previousResult) {\n        var result = [];\n        var n = 0;\n        for(var q = 0; q < items.length; q++) {\n            var i = items[q];\n            for(var k = 1; k < depth; k++) {\n                for(var j = 1; j < height; j++) {\n                    result.push(\n                        beginSection(style, i, j, k, min, max, distRatios[q],\n                            (previousResult && previousResult[n]) ? previousResult[n] : []\n                        )\n                    );\n                    n++;\n                }\n            }\n        }\n        return result;\n    }\n\n    function drawSectionY(style, items, min, max, distRatios, previousResult) {\n        var result = [];\n        var n = 0;\n        for(var q = 0; q < items.length; q++) {\n            var j = items[q];\n            for(var i = 1; i < width; i++) {\n                for(var k = 1; k < depth; k++) {\n                    result.push(\n                        beginSection(style, i, j, k, min, max, distRatios[q],\n                            (previousResult && previousResult[n]) ? previousResult[n] : []\n                        )\n                    );\n                    n++;\n                }\n            }\n        }\n        return result;\n    }\n\n    function drawSectionZ(style, items, min, max, distRatios, previousResult) {\n        var result = [];\n        var n = 0;\n        for(var q = 0; q < items.length; q++) {\n            var k = items[q];\n            for(var j = 1; j < height; j++) {\n                for(var i = 1; i < width; i++) {\n                    result.push(\n                        beginSection(style, i, j, k, min, max, distRatios[q],\n                            (previousResult && previousResult[n]) ? previousResult[n] : []\n                        )\n                    );\n                    n++;\n                }\n            }\n        }\n        return result;\n    }\n\n    function createRange(a, b) {\n        var range = [];\n        for(var q = a; q < b; q++) {\n            range.push(q);\n        }\n        return range;\n    }\n\n    function insertGridPoints() {\n        for(var i = 0; i < width; i++) {\n            for(var j = 0; j < height; j++) {\n                for(var k = 0; k < depth; k++) {\n                    var index = getIndex(i, j, k);\n                    addVertex(\n                        data.x[index],\n                        data.y[index],\n                        data.z[index],\n                        data.value[index]\n                    );\n                }\n            }\n        }\n    }\n\n    function drawAll() {\n        emptyVertices();\n\n        // insert grid points\n        insertGridPoints();\n\n        var activeStyle = null;\n\n        // draw spaceframes\n        if(showSpaceframe && spaceframeFill) {\n            setFill(spaceframeFill);\n\n            drawSpaceframe(activeStyle, vMin, vMax);\n        }\n\n        // draw iso-surfaces\n        if(showSurface && surfaceFill) {\n            setFill(surfaceFill);\n\n            var surfacePattern = data.surface.pattern;\n            var surfaceCount = data.surface.count;\n            for(var q = 0; q < surfaceCount; q++) {\n                var ratio = (surfaceCount === 1) ? 0.5 : q / (surfaceCount - 1);\n                var level = (1 - ratio) * vMin + ratio * vMax;\n\n                var d1 = Math.abs(level - minValues);\n                var d2 = Math.abs(level - maxValues);\n                var ranges = (d1 > d2) ?\n                    [minValues, level] :\n                    [level, maxValues];\n\n                drawSurface(surfacePattern, ranges[0], ranges[1]);\n            }\n        }\n\n        var setupMinMax = [\n            [ Math.min(vMin, maxValues), Math.max(vMin, maxValues) ],\n            [ Math.min(minValues, vMax), Math.max(minValues, vMax) ]\n        ];\n\n        ['x', 'y', 'z'].forEach(function(e) {\n            var preRes = [];\n            for(var s = 0; s < setupMinMax.length; s++) {\n                var count = 0;\n\n                var activeMin = setupMinMax[s][0];\n                var activeMax = setupMinMax[s][1];\n\n                // draw slices\n                var slice = data.slices[e];\n                if(slice.show && slice.fill) {\n                    setFill(slice.fill);\n\n                    var exactIndices = [];\n                    var ceilIndices = [];\n                    var distRatios = [];\n                    if(slice.locations.length) {\n                        for(var q = 0; q < slice.locations.length; q++) {\n                            var near = findNearestOnAxis(\n                                slice.locations[q],\n                                (e === 'x') ? Xs :\n                                (e === 'y') ? Ys : Zs\n                            );\n\n                            if(near.distRatio === 0) {\n                                exactIndices.push(near.id);\n                            } else if(near.id > 0) {\n                                ceilIndices.push(near.id);\n                                if(e === 'x') {\n                                    distRatios.push([near.distRatio, 0, 0]);\n                                } else if(e === 'y') {\n                                    distRatios.push([0, near.distRatio, 0]);\n                                } else {\n                                    distRatios.push([0, 0, near.distRatio]);\n                                }\n                            }\n                        }\n                    } else {\n                        if(e === 'x') {\n                            exactIndices = createRange(1, width - 1);\n                        } else if(e === 'y') {\n                            exactIndices = createRange(1, height - 1);\n                        } else {\n                            exactIndices = createRange(1, depth - 1);\n                        }\n                    }\n\n                    if(ceilIndices.length > 0) {\n                        if(e === 'x') {\n                            preRes[count] = drawSectionX(activeStyle, ceilIndices, activeMin, activeMax, distRatios, preRes[count]);\n                        } else if(e === 'y') {\n                            preRes[count] = drawSectionY(activeStyle, ceilIndices, activeMin, activeMax, distRatios, preRes[count]);\n                        } else {\n                            preRes[count] = drawSectionZ(activeStyle, ceilIndices, activeMin, activeMax, distRatios, preRes[count]);\n                        }\n                        count++;\n                    }\n\n                    if(exactIndices.length > 0) {\n                        if(e === 'x') {\n                            preRes[count] = draw2dX(activeStyle, exactIndices, activeMin, activeMax, preRes[count]);\n                        } else if(e === 'y') {\n                            preRes[count] = draw2dY(activeStyle, exactIndices, activeMin, activeMax, preRes[count]);\n                        } else {\n                            preRes[count] = draw2dZ(activeStyle, exactIndices, activeMin, activeMax, preRes[count]);\n                        }\n                        count++;\n                    }\n                }\n\n                // draw caps\n                var cap = data.caps[e];\n                if(cap.show && cap.fill) {\n                    setFill(cap.fill);\n                    if(e === 'x') {\n                        preRes[count] = draw2dX(activeStyle, [0, width - 1], activeMin, activeMax, preRes[count]);\n                    } else if(e === 'y') {\n                        preRes[count] = draw2dY(activeStyle, [0, height - 1], activeMin, activeMax, preRes[count]);\n                    } else {\n                        preRes[count] = draw2dZ(activeStyle, [0, depth - 1], activeMin, activeMax, preRes[count]);\n                    }\n                    count++;\n                }\n            }\n        });\n\n        // remove vertices arrays (i.e. grid points) in case no face was created.\n        if(numFaces === 0) {\n            emptyVertices();\n        }\n\n        data._x = allXs;\n        data._y = allYs;\n        data._z = allZs;\n        data._intensity = allVs;\n\n        data._Xs = Xs;\n        data._Ys = Ys;\n        data._Zs = Zs;\n    }\n\n    drawAll();\n\n    return data;\n}\n\nfunction createIsosurfaceTrace(scene, data) {\n    var gl = scene.glplot.gl;\n    var mesh = createMesh({gl: gl});\n    var result = new IsosurfaceTrace(scene, mesh, data.uid);\n\n    mesh._trace = result;\n    result.update(data);\n    scene.glplot.add(mesh);\n    return result;\n}\n\nmodule.exports = {\n    findNearestOnAxis: findNearestOnAxis,\n    generateIsoMeshes: generateIsoMeshes,\n    createIsosurfaceTrace: createIsosurfaceTrace,\n};\n\n},{\"../../components/colorscale\":605,\"../../lib\":719,\"../../lib/gl_format_color\":716,\"../../lib/str2rgbarray\":742,\"../../plots/gl3d/zip3\":818,\"gl-mesh3d\":280}],1051:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\nvar attributes = _dereq_('./attributes');\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\n\nfunction supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n}\n\nfunction supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce) {\n    var isomin = coerce('isomin');\n    var isomax = coerce('isomax');\n\n    if(isomax !== undefined && isomax !== null &&\n        isomin !== undefined && isomin !== null &&\n         isomin > isomax) {\n        // applying default values in this case:\n        traceOut.isomin = null;\n        traceOut.isomax = null;\n    }\n\n    var x = coerce('x');\n    var y = coerce('y');\n    var z = coerce('z');\n    var value = coerce('value');\n\n    if(\n        !x || !x.length ||\n        !y || !y.length ||\n        !z || !z.length ||\n        !value || !value.length\n    ) {\n        traceOut.visible = false;\n        return;\n    }\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);\n\n    ['x', 'y', 'z'].forEach(function(dim) {\n        var capDim = 'caps.' + dim;\n        var showCap = coerce(capDim + '.show');\n        if(showCap) {\n            coerce(capDim + '.fill');\n        }\n\n        var sliceDim = 'slices.' + dim;\n        var showSlice = coerce(sliceDim + '.show');\n        if(showSlice) {\n            coerce(sliceDim + '.fill');\n            coerce(sliceDim + '.locations');\n        }\n    });\n\n    var showSpaceframe = coerce('spaceframe.show');\n    if(showSpaceframe) {\n        coerce('spaceframe.fill');\n    }\n\n    var showSurface = coerce('surface.show');\n    if(showSurface) {\n        coerce('surface.count');\n        coerce('surface.fill');\n        coerce('surface.pattern');\n    }\n\n    var showContour = coerce('contour.show');\n    if(showContour) {\n        coerce('contour.color');\n        coerce('contour.width');\n    }\n\n    // Coerce remaining properties\n    [\n        'text',\n        'hovertext',\n        'hovertemplate',\n        'lighting.ambient',\n        'lighting.diffuse',\n        'lighting.specular',\n        'lighting.roughness',\n        'lighting.fresnel',\n        'lighting.vertexnormalsepsilon',\n        'lighting.facenormalsepsilon',\n        'lightposition.x',\n        'lightposition.y',\n        'lightposition.z',\n        'flatshading',\n        'opacity'\n    ].forEach(function(x) { coerce(x); });\n\n    colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});\n\n    // disable 1D transforms (for now)\n    traceOut._length = null;\n}\n\nmodule.exports = {\n    supplyDefaults: supplyDefaults,\n    supplyIsoDefaults: supplyIsoDefaults\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"../../registry\":847,\"./attributes\":1048}],1052:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults').supplyDefaults,\n    calc: _dereq_('./calc'),\n    colorbar: {\n        min: 'cmin',\n        max: 'cmax'\n    },\n    plot: _dereq_('./convert').createIsosurfaceTrace,\n\n    moduleType: 'trace',\n    name: 'isosurface',\n    basePlotModule: _dereq_('../../plots/gl3d'),\n    categories: ['gl3d'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/gl3d\":807,\"./attributes\":1048,\"./calc\":1049,\"./convert\":1050,\"./defaults\":1051}],1053:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar surfaceAtts = _dereq_('../surface/attributes');\nvar baseAttrs = _dereq_('../../plots/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = extendFlat({\n    x: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n    y: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n    z: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    i: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    j: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n\n    },\n    k: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n\n    },\n\n    text: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n    hovertemplate: hovertemplateAttrs({editType: 'calc'}),\n\n    delaunayaxis: {\n        valType: 'enumerated',\n        \n        values: [ 'x', 'y', 'z' ],\n        dflt: 'z',\n        editType: 'calc',\n        \n    },\n\n    alphahull: {\n        valType: 'number',\n        \n        dflt: -1,\n        editType: 'calc',\n        \n    },\n\n    intensity: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    // Color field\n    color: {\n        valType: 'color',\n        \n        editType: 'calc',\n        \n    },\n    vertexcolor: {\n        valType: 'data_array',\n        \n        editType: 'calc',\n        \n    },\n    facecolor: {\n        valType: 'data_array',\n        \n        editType: 'calc',\n        \n    },\n    transforms: undefined\n},\n\ncolorScaleAttrs('', {\n    colorAttr: '`intensity`',\n    showScaleDflt: true,\n    editTypeOverride: 'calc'\n}), {\n    opacity: surfaceAtts.opacity,\n\n    // Flat shaded mode\n    flatshading: {\n        valType: 'boolean',\n        \n        dflt: false,\n        editType: 'calc',\n        \n    },\n\n    contour: {\n        show: extendFlat({}, surfaceAtts.contours.x.show, {\n            \n        }),\n        color: surfaceAtts.contours.x.color,\n        width: surfaceAtts.contours.x.width,\n        editType: 'calc'\n    },\n\n    lightposition: {\n        x: extendFlat({}, surfaceAtts.lightposition.x, {dflt: 1e5}),\n        y: extendFlat({}, surfaceAtts.lightposition.y, {dflt: 1e5}),\n        z: extendFlat({}, surfaceAtts.lightposition.z, {dflt: 0}),\n        editType: 'calc'\n    },\n    lighting: extendFlat({\n        vertexnormalsepsilon: {\n            valType: 'number',\n            \n            min: 0.00,\n            max: 1,\n            dflt: 1e-12, // otherwise finely tessellated things eg. the brain will have no specular light reflection\n            editType: 'calc',\n            \n        },\n        facenormalsepsilon: {\n            valType: 'number',\n            \n            min: 0.00,\n            max: 1,\n            dflt: 1e-6, // even the brain model doesn't appear to need finer than this\n            editType: 'calc',\n            \n        },\n        editType: 'calc'\n    }, surfaceAtts.lighting),\n\n    hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {editType: 'calc'})\n});\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../surface/attributes\":1224}],1054:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\n\nmodule.exports = function calc(gd, trace) {\n    if(trace.intensity) {\n        colorscaleCalc(gd, trace, {\n            vals: trace.intensity,\n            containerStr: '',\n            cLetter: 'c'\n        });\n    }\n};\n\n},{\"../../components/colorscale/calc\":601}],1055:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar createMesh = _dereq_('gl-mesh3d');\nvar triangulate = _dereq_('delaunay-triangulate');\nvar alphaShape = _dereq_('alpha-shape');\nvar convexHull = _dereq_('convex-hull');\n\nvar parseColorScale = _dereq_('../../lib/gl_format_color').parseColorScale;\nvar str2RgbaArray = _dereq_('../../lib/str2rgbarray');\nvar extractOpts = _dereq_('../../components/colorscale').extractOpts;\nvar zip3 = _dereq_('../../plots/gl3d/zip3');\n\nfunction Mesh3DTrace(scene, mesh, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.mesh = mesh;\n    this.name = '';\n    this.color = '#fff';\n    this.data = null;\n    this.showContour = false;\n}\n\nvar proto = Mesh3DTrace.prototype;\n\nproto.handlePick = function(selection) {\n    if(selection.object === this.mesh) {\n        var selectIndex = selection.index = selection.data.index;\n\n        selection.traceCoordinate = [\n            this.data.x[selectIndex],\n            this.data.y[selectIndex],\n            this.data.z[selectIndex]\n        ];\n\n        var text = this.data.hovertext || this.data.text;\n        if(Array.isArray(text) && text[selectIndex] !== undefined) {\n            selection.textLabel = text[selectIndex];\n        } else if(text) {\n            selection.textLabel = text;\n        }\n\n        return true;\n    }\n};\n\nfunction parseColorArray(colors) {\n    var b = [];\n    var len = colors.length;\n    for(var i = 0; i < len; i++) {\n        b[i] = str2RgbaArray(colors[i]);\n    }\n    return b;\n}\n\n// Unpack position data\nfunction toDataCoords(axis, coord, scale, calendar) {\n    var b = [];\n    var len = coord.length;\n    for(var i = 0; i < len; i++) {\n        b[i] = axis.d2l(coord[i], 0, calendar) * scale;\n    }\n    return b;\n}\n\n// Round indices if passed as floats\nfunction toRoundIndex(a) {\n    var b = [];\n    var len = a.length;\n    for(var i = 0; i < len; i++) {\n        b[i] = Math.round(a[i]);\n    }\n    return b;\n}\n\nfunction delaunayCells(delaunayaxis, positions) {\n    var d = ['x', 'y', 'z'].indexOf(delaunayaxis);\n    var b = [];\n    var len = positions.length;\n    for(var i = 0; i < len; i++) {\n        b[i] = [positions[i][(d + 1) % 3], positions[i][(d + 2) % 3]];\n    }\n    return triangulate(b);\n}\n\n// Validate indices\nfunction hasValidIndices(list, numVertices) {\n    var len = list.length;\n    for(var i = 0; i < len; i++) {\n        if(list[i] <= -0.5 || list[i] >= numVertices - 0.5) { // Note: the indices would be rounded -0.49 is valid.\n            return false;\n        }\n    }\n    return true;\n}\n\nproto.update = function(data) {\n    var scene = this.scene;\n    var layout = scene.fullSceneLayout;\n\n    this.data = data;\n\n    var numVertices = data.x.length;\n\n    var positions = zip3(\n        toDataCoords(layout.xaxis, data.x, scene.dataScale[0], data.xcalendar),\n        toDataCoords(layout.yaxis, data.y, scene.dataScale[1], data.ycalendar),\n        toDataCoords(layout.zaxis, data.z, scene.dataScale[2], data.zcalendar)\n    );\n\n    var cells;\n    if(data.i && data.j && data.k) {\n        if(\n            data.i.length !== data.j.length ||\n            data.j.length !== data.k.length ||\n            !hasValidIndices(data.i, numVertices) ||\n            !hasValidIndices(data.j, numVertices) ||\n            !hasValidIndices(data.k, numVertices)\n        ) {\n            return;\n        }\n        cells = zip3(\n            toRoundIndex(data.i),\n            toRoundIndex(data.j),\n            toRoundIndex(data.k)\n        );\n    } else if(data.alphahull === 0) {\n        cells = convexHull(positions);\n    } else if(data.alphahull > 0) {\n        cells = alphaShape(data.alphahull, positions);\n    } else {\n        cells = delaunayCells(data.delaunayaxis, positions);\n    }\n\n    var config = {\n        positions: positions,\n        cells: cells,\n        lightPosition: [data.lightposition.x, data.lightposition.y, data.lightposition.z],\n        ambient: data.lighting.ambient,\n        diffuse: data.lighting.diffuse,\n        specular: data.lighting.specular,\n        roughness: data.lighting.roughness,\n        fresnel: data.lighting.fresnel,\n        vertexNormalsEpsilon: data.lighting.vertexnormalsepsilon,\n        faceNormalsEpsilon: data.lighting.facenormalsepsilon,\n        opacity: data.opacity,\n        contourEnable: data.contour.show,\n        contourColor: str2RgbaArray(data.contour.color).slice(0, 3),\n        contourWidth: data.contour.width,\n        useFacetNormals: data.flatshading\n    };\n\n    if(data.intensity) {\n        var cOpts = extractOpts(data);\n        this.color = '#fff';\n        config.vertexIntensity = data.intensity;\n        config.vertexIntensityBounds = [cOpts.min, cOpts.max];\n        config.colormap = parseColorScale(data);\n    } else if(data.vertexcolor) {\n        this.color = data.vertexcolor[0];\n        config.vertexColors = parseColorArray(data.vertexcolor);\n    } else if(data.facecolor) {\n        this.color = data.facecolor[0];\n        config.cellColors = parseColorArray(data.facecolor);\n    } else {\n        this.color = data.color;\n        config.meshColor = str2RgbaArray(data.color);\n    }\n\n    // Update mesh\n    this.mesh.update(config);\n};\n\nproto.dispose = function() {\n    this.scene.glplot.remove(this.mesh);\n    this.mesh.dispose();\n};\n\nfunction createMesh3DTrace(scene, data) {\n    var gl = scene.glplot.gl;\n    var mesh = createMesh({gl: gl});\n    var result = new Mesh3DTrace(scene, mesh, data.uid);\n    mesh._trace = result;\n    result.update(data);\n    scene.glplot.add(mesh);\n    return result;\n}\n\nmodule.exports = createMesh3DTrace;\n\n},{\"../../components/colorscale\":605,\"../../lib/gl_format_color\":716,\"../../lib/str2rgbarray\":742,\"../../plots/gl3d/zip3\":818,\"alpha-shape\":64,\"convex-hull\":130,\"delaunay-triangulate\":165,\"gl-mesh3d\":280}],1056:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    // read in face/vertex properties\n    function readComponents(array) {\n        var ret = array.map(function(attr) {\n            var result = coerce(attr);\n\n            if(result && Lib.isArrayOrTypedArray(result)) return result;\n            return null;\n        });\n\n        return ret.every(function(x) {\n            return x && x.length === ret[0].length;\n        }) && ret;\n    }\n\n    var coords = readComponents(['x', 'y', 'z']);\n    if(!coords) {\n        traceOut.visible = false;\n        return;\n    }\n\n    readComponents(['i', 'j', 'k']);\n    // three indices should be all provided or not\n    if(\n        (traceOut.i && (!traceOut.j || !traceOut.k)) ||\n        (traceOut.j && (!traceOut.k || !traceOut.i)) ||\n        (traceOut.k && (!traceOut.i || !traceOut.j))\n    ) {\n        traceOut.visible = false;\n        return;\n    }\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);\n\n    // Coerce remaining properties\n    [\n        'lighting.ambient',\n        'lighting.diffuse',\n        'lighting.specular',\n        'lighting.roughness',\n        'lighting.fresnel',\n        'lighting.vertexnormalsepsilon',\n        'lighting.facenormalsepsilon',\n        'lightposition.x',\n        'lightposition.y',\n        'lightposition.z',\n        'contour.show',\n        'contour.color',\n        'contour.width',\n        'colorscale',\n        'reversescale',\n        'flatshading',\n        'alphahull',\n        'delaunayaxis',\n        'opacity'\n    ].forEach(function(x) { coerce(x); });\n\n    if('intensity' in traceIn) {\n        coerce('intensity');\n        colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});\n    } else {\n        traceOut.showscale = false;\n\n        if('facecolor' in traceIn) coerce('facecolor');\n        else if('vertexcolor' in traceIn) coerce('vertexcolor');\n        else coerce('color', defaultColor);\n    }\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    // disable 1D transforms\n    // x/y/z should match lengths, and i/j/k should match as well, but\n    // the two sets have different lengths so transforms wouldn't work.\n    traceOut._length = null;\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"../../registry\":847,\"./attributes\":1053}],1057:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc'),\n    colorbar: {\n        min: 'cmin',\n        max: 'cmax'\n    },\n    plot: _dereq_('./convert'),\n\n    moduleType: 'trace',\n    name: 'mesh3d',\n    basePlotModule: _dereq_('../../plots/gl3d'),\n    categories: ['gl3d'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/gl3d\":807,\"./attributes\":1053,\"./calc\":1054,\"./convert\":1055,\"./defaults\":1056}],1058:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar extendFlat = _dereq_('../../lib').extendFlat;\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar dash = _dereq_('../../components/drawing/attributes').dash;\nvar fxAttrs = _dereq_('../../components/fx/attributes');\nvar delta = _dereq_('../../constants/delta.js');\n\nvar INCREASING_COLOR = delta.INCREASING.COLOR;\nvar DECREASING_COLOR = delta.DECREASING.COLOR;\n\nvar lineAttrs = scatterAttrs.line;\n\nfunction directionAttrs(lineColorDefault) {\n    return {\n        line: {\n            color: extendFlat({}, lineAttrs.color, {dflt: lineColorDefault}),\n            width: lineAttrs.width,\n            dash: dash,\n            editType: 'style'\n        },\n        editType: 'style'\n    };\n}\n\nmodule.exports = {\n\n    x: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    open: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    high: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    low: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    close: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    line: {\n        width: extendFlat({}, lineAttrs.width, {\n            \n        }),\n        dash: extendFlat({}, dash, {\n            \n        }),\n        editType: 'style'\n    },\n\n    increasing: directionAttrs(INCREASING_COLOR),\n\n    decreasing: directionAttrs(DECREASING_COLOR),\n\n    text: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n\n    tickwidth: {\n        valType: 'number',\n        min: 0,\n        max: 0.5,\n        dflt: 0.3,\n        \n        editType: 'calc',\n        \n    },\n\n    hoverlabel: extendFlat({}, fxAttrs.hoverlabel, {\n        split: {\n            valType: 'boolean',\n            \n            dflt: false,\n            editType: 'style',\n            \n        }\n    }),\n};\n\n},{\"../../components/drawing/attributes\":613,\"../../components/fx/attributes\":623,\"../../constants/delta.js\":689,\"../../lib\":719,\"../scatter/attributes\":1112}],1059:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar _ = Lib._;\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nfunction calc(gd, trace) {\n    var xa = Axes.getFromId(gd, trace.xaxis);\n    var ya = Axes.getFromId(gd, trace.yaxis);\n\n    var tickLen = convertTickWidth(gd, xa, trace);\n    var minDiff = trace._minDiff;\n    trace._minDiff = null;\n    var x = trace._xcalc;\n    trace._xcalc = null;\n\n    var cd = calcCommon(gd, trace, x, ya, ptFunc);\n\n    trace._extremes[xa._id] = Axes.findExtremes(xa, x, {vpad: minDiff / 2});\n    if(cd.length) {\n        Lib.extendFlat(cd[0].t, {\n            wHover: minDiff / 2,\n            tickLen: tickLen\n        });\n        return cd;\n    } else {\n        return [{t: {empty: true}}];\n    }\n}\n\nfunction ptFunc(o, h, l, c) {\n    return {\n        o: o,\n        h: h,\n        l: l,\n        c: c\n    };\n}\n\n\n// shared between OHLC and candlestick\n// ptFunc makes a calcdata point specific to each trace type, from oi, hi, li, ci\nfunction calcCommon(gd, trace, x, ya, ptFunc) {\n    var o = ya.makeCalcdata(trace, 'open');\n    var h = ya.makeCalcdata(trace, 'high');\n    var l = ya.makeCalcdata(trace, 'low');\n    var c = ya.makeCalcdata(trace, 'close');\n\n    var hasTextArray = Array.isArray(trace.text);\n    var hasHovertextArray = Array.isArray(trace.hovertext);\n\n    // we're optimists - before we have any changing data, assume increasing\n    var increasing = true;\n    var cPrev = null;\n\n    var cd = [];\n    for(var i = 0; i < x.length; i++) {\n        var xi = x[i];\n        var oi = o[i];\n        var hi = h[i];\n        var li = l[i];\n        var ci = c[i];\n\n        if(xi !== BADNUM && oi !== BADNUM && hi !== BADNUM && li !== BADNUM && ci !== BADNUM) {\n            if(ci === oi) {\n                // if open == close, look for a change from the previous close\n                if(cPrev !== null && ci !== cPrev) increasing = ci > cPrev;\n                // else (c === cPrev or cPrev is null) no change\n            } else increasing = ci > oi;\n\n            cPrev = ci;\n\n            var pt = ptFunc(oi, hi, li, ci);\n\n            pt.pos = xi;\n            pt.yc = (oi + ci) / 2;\n            pt.i = i;\n            pt.dir = increasing ? 'increasing' : 'decreasing';\n\n            // For categoryorder, store low and high\n            pt.x = pt.pos;\n            pt.y = [li, hi];\n\n            if(hasTextArray) pt.tx = trace.text[i];\n            if(hasHovertextArray) pt.htx = trace.hovertext[i];\n\n            cd.push(pt);\n        } else {\n            cd.push({pos: xi, empty: true});\n        }\n    }\n\n    trace._extremes[ya._id] = Axes.findExtremes(ya, Lib.concat(l, h), {padded: true});\n\n    if(cd.length) {\n        cd[0].t = {\n            labels: {\n                open: _(gd, 'open:') + ' ',\n                high: _(gd, 'high:') + ' ',\n                low: _(gd, 'low:') + ' ',\n                close: _(gd, 'close:') + ' '\n            }\n        };\n    }\n\n    return cd;\n}\n\n/*\n * find min x-coordinates difference of all traces\n * attached to this x-axis and stash the result in _minDiff\n * in all traces; when a trace uses this in its\n * calc step it deletes _minDiff, so that next calc this is\n * done again in case the data changed.\n * also since we need it here, stash _xcalc on the trace\n */\nfunction convertTickWidth(gd, xa, trace) {\n    var minDiff = trace._minDiff;\n\n    if(!minDiff) {\n        var fullData = gd._fullData;\n        var ohlcTracesOnThisXaxis = [];\n\n        minDiff = Infinity;\n\n        var i;\n\n        for(i = 0; i < fullData.length; i++) {\n            var tracei = fullData[i];\n\n            if(tracei.type === 'ohlc' &&\n                tracei.visible === true &&\n                tracei.xaxis === xa._id\n            ) {\n                ohlcTracesOnThisXaxis.push(tracei);\n\n                var xcalc = xa.makeCalcdata(tracei, 'x');\n                tracei._xcalc = xcalc;\n\n                var _minDiff = Lib.distinctVals(xcalc).minDiff;\n                if(_minDiff && isFinite(_minDiff)) {\n                    minDiff = Math.min(minDiff, _minDiff);\n                }\n            }\n        }\n\n        // if minDiff is still Infinity here, set it to 1\n        if(minDiff === Infinity) minDiff = 1;\n\n        for(i = 0; i < ohlcTracesOnThisXaxis.length; i++) {\n            ohlcTracesOnThisXaxis[i]._minDiff = minDiff;\n        }\n    }\n\n    return minDiff * trace.tickwidth;\n}\n\nmodule.exports = {\n    calc: calc,\n    calcCommon: calcCommon\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../plots/cartesian/axes\":767}],1060:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar handleOHLC = _dereq_('./ohlc_defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleOHLC(traceIn, traceOut, coerce, layout);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('line.width');\n    coerce('line.dash');\n\n    handleDirection(traceIn, traceOut, coerce, 'increasing');\n    handleDirection(traceIn, traceOut, coerce, 'decreasing');\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('tickwidth');\n\n    layout._requestRangeslider[traceOut.xaxis] = true;\n};\n\nfunction handleDirection(traceIn, traceOut, coerce, direction) {\n    coerce(direction + '.line.color');\n    coerce(direction + '.line.width', traceOut.line.width);\n    coerce(direction + '.line.dash', traceOut.line.dash);\n}\n\n},{\"../../lib\":719,\"./attributes\":1058,\"./ohlc_defaults\":1063}],1061:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Lib = _dereq_('../../lib');\nvar Fx = _dereq_('../../components/fx');\nvar Color = _dereq_('../../components/color');\nvar fillText = _dereq_('../../lib').fillText;\nvar delta = _dereq_('../../constants/delta.js');\n\nvar DIRSYMBOL = {\n    increasing: delta.INCREASING.SYMBOL,\n    decreasing: delta.DECREASING.SYMBOL\n};\n\nfunction hoverPoints(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n\n    if(trace.hoverlabel.split) {\n        return hoverSplit(pointData, xval, yval, hovermode);\n    }\n\n    return hoverOnPoints(pointData, xval, yval, hovermode);\n}\n\nfunction getClosestPoint(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var xa = pointData.xa;\n    var trace = cd[0].trace;\n    var t = cd[0].t;\n\n    var type = trace.type;\n    var minAttr = type === 'ohlc' ? 'l' : 'min';\n    var maxAttr = type === 'ohlc' ? 'h' : 'max';\n\n    var hoverPseudoDistance, spikePseudoDistance;\n\n    // potentially shift xval for grouped candlesticks\n    var centerShift = t.bPos || 0;\n    var shiftPos = function(di) { return di.pos + centerShift - xval; };\n\n    // ohlc and candlestick call displayHalfWidth different things...\n    var displayHalfWidth = t.bdPos || t.tickLen;\n    var hoverHalfWidth = t.wHover;\n\n    // if two figures are overlaying, let the narrowest one win\n    var pseudoDistance = Math.min(1, displayHalfWidth / Math.abs(xa.r2c(xa.range[1]) - xa.r2c(xa.range[0])));\n    hoverPseudoDistance = pointData.maxHoverDistance - pseudoDistance;\n    spikePseudoDistance = pointData.maxSpikeDistance - pseudoDistance;\n\n    function dx(di) {\n        var pos = shiftPos(di);\n        return Fx.inbox(pos - hoverHalfWidth, pos + hoverHalfWidth, hoverPseudoDistance);\n    }\n\n    function dy(di) {\n        var min = di[minAttr];\n        var max = di[maxAttr];\n        return min === max || Fx.inbox(min - yval, max - yval, hoverPseudoDistance);\n    }\n\n    function dxy(di) { return (dx(di) + dy(di)) / 2; }\n\n    var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);\n    Fx.getClosest(cd, distfn, pointData);\n\n    if(pointData.index === false) return null;\n\n    var di = cd[pointData.index];\n\n    if(di.empty) return null;\n\n    var dir = di.dir;\n    var container = trace[dir];\n    var lc = container.line.color;\n\n    if(Color.opacity(lc) && container.line.width) pointData.color = lc;\n    else pointData.color = container.fillcolor;\n\n    pointData.x0 = xa.c2p(di.pos + centerShift - displayHalfWidth, true);\n    pointData.x1 = xa.c2p(di.pos + centerShift + displayHalfWidth, true);\n\n    pointData.xLabelVal = di.pos;\n\n    pointData.spikeDistance = dxy(di) * spikePseudoDistance / hoverPseudoDistance;\n    pointData.xSpike = xa.c2p(di.pos, true);\n\n    return pointData;\n}\n\nfunction hoverSplit(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var ya = pointData.ya;\n    var trace = cd[0].trace;\n    var t = cd[0].t;\n    var closeBoxData = [];\n\n    var closestPoint = getClosestPoint(pointData, xval, yval, hovermode);\n    // skip the rest (for this trace) if we didn't find a close point\n    if(!closestPoint) return [];\n\n    var cdIndex = closestPoint.index;\n    var di = cd[cdIndex];\n    var hoverinfo = di.hi || trace.hoverinfo;\n    var hoverParts = hoverinfo.split('+');\n    var isAll = hoverinfo === 'all';\n    var hasY = isAll || hoverParts.indexOf('y') !== -1;\n\n    // similar to hoverOnPoints, we return nothing\n    // if all or y is not present.\n    if(!hasY) return [];\n\n    var attrs = ['high', 'open', 'close', 'low'];\n\n    // several attributes can have the same y-coordinate. We will\n    // bunch them together in a single text block. For this, we keep\n    // a dictionary mapping y-coord -> point data.\n    var usedVals = {};\n\n    for(var i = 0; i < attrs.length; i++) {\n        var attr = attrs[i];\n\n        var val = trace[attr][closestPoint.index];\n        var valPx = ya.c2p(val, true);\n        var pointData2;\n        if(val in usedVals) {\n            pointData2 = usedVals[val];\n            pointData2.yLabel += '<br>' + t.labels[attr] + Axes.hoverLabelText(ya, val);\n        } else {\n            // copy out to a new object for each new y-value to label\n            pointData2 = Lib.extendFlat({}, closestPoint);\n\n            pointData2.y0 = pointData2.y1 = valPx;\n            pointData2.yLabelVal = val;\n            pointData2.yLabel = t.labels[attr] + Axes.hoverLabelText(ya, val);\n\n            pointData2.name = '';\n\n            closeBoxData.push(pointData2);\n            usedVals[val] = pointData2;\n        }\n    }\n\n    return closeBoxData;\n}\n\nfunction hoverOnPoints(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var ya = pointData.ya;\n    var trace = cd[0].trace;\n    var t = cd[0].t;\n\n    var closestPoint = getClosestPoint(pointData, xval, yval, hovermode);\n    // skip the rest (for this trace) if we didn't find a close point\n    if(!closestPoint) return [];\n\n    // we don't make a calcdata point if we're missing any piece (x/o/h/l/c)\n    // so we need to fix the index here to point to the data arrays\n    var cdIndex = closestPoint.index;\n    var di = cd[cdIndex];\n    var i = closestPoint.index = di.i;\n    var dir = di.dir;\n\n    function getLabelLine(attr) {\n        return t.labels[attr] + Axes.hoverLabelText(ya, trace[attr][i]);\n    }\n\n    var hoverinfo = di.hi || trace.hoverinfo;\n    var hoverParts = hoverinfo.split('+');\n    var isAll = hoverinfo === 'all';\n    var hasY = isAll || hoverParts.indexOf('y') !== -1;\n    var hasText = isAll || hoverParts.indexOf('text') !== -1;\n\n    var textParts = hasY ? [\n        getLabelLine('open'),\n        getLabelLine('high'),\n        getLabelLine('low'),\n        getLabelLine('close') + '  ' + DIRSYMBOL[dir]\n    ] : [];\n    if(hasText) fillText(di, trace, textParts);\n\n    // don't make .yLabelVal or .text, since we're managing hoverinfo\n    // put it all in .extraText\n    closestPoint.extraText = textParts.join('<br>');\n\n    // this puts the label *and the spike* at the midpoint of the box, ie\n    // halfway between open and close, not between high and low.\n    closestPoint.y0 = closestPoint.y1 = ya.c2p(di.yc, true);\n\n    return [closestPoint];\n}\n\nmodule.exports = {\n    hoverPoints: hoverPoints,\n    hoverSplit: hoverSplit,\n    hoverOnPoints: hoverOnPoints\n};\n\n},{\"../../components/color\":593,\"../../components/fx\":632,\"../../constants/delta.js\":689,\"../../lib\":719,\"../../plots/cartesian/axes\":767}],1062:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'ohlc',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', 'showLegend'],\n    meta: {\n        \n    },\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc').calc,\n    plot: _dereq_('./plot'),\n    style: _dereq_('./style'),\n    hoverPoints: _dereq_('./hover').hoverPoints,\n    selectPoints: _dereq_('./select')\n};\n\n},{\"../../plots/cartesian\":778,\"./attributes\":1058,\"./calc\":1059,\"./defaults\":1060,\"./hover\":1061,\"./plot\":1064,\"./select\":1065,\"./style\":1066}],1063:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function handleOHLC(traceIn, traceOut, coerce, layout) {\n    var x = coerce('x');\n    var open = coerce('open');\n    var high = coerce('high');\n    var low = coerce('low');\n    var close = coerce('close');\n\n    coerce('hoverlabel.split');\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x'], layout);\n\n    if(!(open && high && low && close)) return;\n\n    var len = Math.min(open.length, high.length, low.length, close.length);\n    if(x) len = Math.min(len, Lib.minRowLength(x));\n    traceOut._length = len;\n\n    return len;\n};\n\n},{\"../../lib\":719,\"../../registry\":847}],1064:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function plot(gd, plotinfo, cdOHLC, ohlcLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    Lib.makeTraceGroups(ohlcLayer, cdOHLC, 'trace ohlc').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var cd0 = cd[0];\n        var t = cd0.t;\n        var trace = cd0.trace;\n\n        if(trace.visible !== true || t.empty) {\n            plotGroup.remove();\n            return;\n        }\n\n        var tickLen = t.tickLen;\n\n        var paths = plotGroup.selectAll('path').data(Lib.identity);\n\n        paths.enter().append('path');\n\n        paths.exit().remove();\n\n        paths.attr('d', function(d) {\n            if(d.empty) return 'M0,0Z';\n\n            var x = xa.c2p(d.pos, true);\n            var xo = xa.c2p(d.pos - tickLen, true);\n            var xc = xa.c2p(d.pos + tickLen, true);\n\n            var yo = ya.c2p(d.o, true);\n            var yh = ya.c2p(d.h, true);\n            var yl = ya.c2p(d.l, true);\n            var yc = ya.c2p(d.c, true);\n\n            return 'M' + xo + ',' + yo + 'H' + x +\n                'M' + x + ',' + yh + 'V' + yl +\n                'M' + xc + ',' + yc + 'H' + x;\n        });\n    });\n};\n\n},{\"../../lib\":719,\"d3\":163}],1065:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function selectPoints(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var xa = searchInfo.xaxis;\n    var ya = searchInfo.yaxis;\n    var selection = [];\n    var i;\n    // for (potentially grouped) candlesticks\n    var posOffset = cd[0].t.bPos || 0;\n\n    if(selectionTester === false) {\n        // clear selection\n        for(i = 0; i < cd.length; i++) {\n            cd[i].selected = 0;\n        }\n    } else {\n        for(i = 0; i < cd.length; i++) {\n            var di = cd[i];\n\n            if(selectionTester.contains([xa.c2p(di.pos + posOffset), ya.c2p(di.yc)], null, di.i, searchInfo)) {\n                selection.push({\n                    pointNumber: di.i,\n                    x: xa.c2d(di.pos),\n                    y: ya.c2d(di.yc)\n                });\n                di.selected = 1;\n            } else {\n                di.selected = 0;\n            }\n        }\n    }\n\n    return selection;\n};\n\n},{}],1066:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Drawing = _dereq_('../../components/drawing');\nvar Color = _dereq_('../../components/color');\n\nmodule.exports = function style(gd, cd, sel) {\n    var s = sel ? sel : d3.select(gd).selectAll('g.ohlclayer').selectAll('g.trace');\n\n    s.style('opacity', function(d) {\n        return d[0].trace.opacity;\n    });\n\n    s.each(function(d) {\n        var trace = d[0].trace;\n\n        d3.select(this).selectAll('path').each(function(di) {\n            if(di.empty) return;\n\n            var dirLine = trace[di.dir].line;\n            d3.select(this)\n                .style('fill', 'none')\n                .call(Color.stroke, dirLine.color)\n                .call(Drawing.dashLine, dirLine.dash, dirLine.width)\n                // TODO: custom selection style for OHLC\n                .style('opacity', trace.selectedpoints && !di.selected ? 0.3 : 1);\n        });\n    });\n};\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"d3\":163}],1067:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\n\nvar line = extendFlat(\n    {editType: 'calc'},\n    colorScaleAttrs('line', {editTypeOverride: 'calc'}),\n    {\n        shape: {\n            valType: 'enumerated',\n            values: ['linear', 'hspline'],\n            dflt: 'linear',\n            \n            editType: 'plot',\n            \n        },\n\n        hovertemplate: hovertemplateAttrs({\n            editType: 'plot',\n            arrayOk: false\n        }, {\n            keys: ['count', 'probability'],\n            \n        })\n    }\n);\n\nmodule.exports = {\n    domain: domainAttrs({name: 'parcats', trace: true, editType: 'calc'}),\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['count', 'probability'],\n        editType: 'plot',\n        arrayOk: false\n    }),\n    hoveron: {\n        valType: 'enumerated',\n        values: ['category', 'color', 'dimension'],\n        dflt: 'category',\n        \n        editType: 'plot',\n        \n    },\n    hovertemplate: hovertemplateAttrs({\n        editType: 'plot',\n        arrayOk: false\n    }, {\n        keys: [\n            'count', 'probability', 'category',\n            'categorycount', 'colorcount', 'bandcolorcount'\n        ],\n        \n    }),\n\n    arrangement: {\n        valType: 'enumerated',\n        values: ['perpendicular', 'freeform', 'fixed'],\n        dflt: 'perpendicular',\n        \n        editType: 'plot',\n        \n    },\n    bundlecolors: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'plot',\n        \n    },\n    sortpaths: {\n        valType: 'enumerated',\n        values: ['forward', 'backward'],\n        dflt: 'forward',\n        \n        editType: 'plot',\n        \n    },\n    labelfont: fontAttrs({\n        editType: 'calc',\n        \n    }),\n\n    tickfont: fontAttrs({\n        editType: 'calc',\n        \n    }),\n\n    dimensions: {\n        _isLinkedToArray: 'dimension',\n        label: {\n            valType: 'string',\n            \n            editType: 'calc',\n            \n        },\n        categoryorder: {\n            valType: 'enumerated',\n            values: [\n                'trace', 'category ascending', 'category descending', 'array'\n            ],\n            dflt: 'trace',\n            \n            editType: 'calc',\n            \n        },\n        categoryarray: {\n            valType: 'data_array',\n            \n            editType: 'calc',\n            \n        },\n        ticktext: {\n            valType: 'data_array',\n            \n            editType: 'calc',\n            \n        },\n        values: {\n            valType: 'data_array',\n            \n            dflt: [],\n            editType: 'calc',\n            \n        },\n        displayindex: {\n            valType: 'integer',\n            \n            editType: 'calc',\n            \n        },\n        editType: 'calc',\n        \n        visible: {\n            valType: 'boolean',\n            dflt: true,\n            \n            editType: 'calc',\n            \n        }\n    },\n\n    line: line,\n    counts: {\n        valType: 'number',\n        min: 0,\n        dflt: 1,\n        arrayOk: true,\n        \n        editType: 'calc',\n        \n    },\n\n    // Hide unsupported top-level properties from plot-schema\n    customdata: undefined,\n    hoverlabel: undefined,\n    ids: undefined,\n    legendgroup: undefined,\n    opacity: undefined,\n    selectedpoints: undefined,\n    showlegend: undefined\n};\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../../plots/domain\":792,\"../../plots/font_attributes\":793}],1068:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\nvar parcatsPlot = _dereq_('./plot');\n\nvar PARCATS = 'parcats';\nexports.name = PARCATS;\n\nexports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {\n    var cdModuleAndOthers = getModuleCalcData(gd.calcdata, PARCATS);\n\n    if(cdModuleAndOthers.length) {\n        var calcData = cdModuleAndOthers[0];\n        parcatsPlot(gd, calcData, transitionOpts, makeOnCompleteCallback);\n    }\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var hadTable = (oldFullLayout._has && oldFullLayout._has('parcats'));\n    var hasTable = (newFullLayout._has && newFullLayout._has('parcats'));\n\n    if(hadTable && !hasTable) {\n        oldFullLayout._paperdiv.selectAll('.parcats').remove();\n    }\n};\n\n},{\"../../plots/get_data\":802,\"./plot\":1073}],1069:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n// Requirements\n// ============\nvar wrap = _dereq_('../../lib/gup').wrap;\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\nvar filterUnique = _dereq_('../../lib/filter_unique.js');\nvar Drawing = _dereq_('../../components/drawing');\nvar Lib = _dereq_('../../lib');\n\n/**\n * Create a wrapped ParcatsModel object from trace\n *\n * Note: trace defaults have already been applied\n * @param {Object} gd\n * @param {Object} trace\n * @return {Array.<ParcatsModel>}\n */\nmodule.exports = function calc(gd, trace) {\n    var visibleDims = Lib.filterVisible(trace.dimensions);\n\n    if(visibleDims.length === 0) return [];\n\n    var uniqueInfoDims = visibleDims.map(function(dim) {\n        var categoryValues;\n        if(dim.categoryorder === 'trace') {\n            // Use order of first occurrence in trace\n            categoryValues = null;\n        } else if(dim.categoryorder === 'array') {\n            // Use categories specified in `categoryarray` first,\n            // then add extra to the end in trace order\n            categoryValues = dim.categoryarray;\n        } else {\n            // Get all categories up front so we can order them\n            // Should we check for numbers as sort numerically?\n            categoryValues = filterUnique(dim.values).sort();\n            if(dim.categoryorder === 'category descending') {\n                categoryValues = categoryValues.reverse();\n            }\n        }\n        return getUniqueInfo(dim.values, categoryValues);\n    });\n\n    var counts,\n        count,\n        totalCount;\n    if(Lib.isArrayOrTypedArray(trace.counts)) {\n        counts = trace.counts;\n    } else {\n        counts = [trace.counts];\n    }\n\n    validateDimensionDisplayInds(visibleDims);\n\n    visibleDims.forEach(function(dim, dimInd) {\n        validateCategoryProperties(dim, uniqueInfoDims[dimInd]);\n    });\n\n    // Handle path colors\n    // ------------------\n    var line = trace.line;\n    var markerColorscale;\n\n    // Process colorscale\n    if(line) {\n        if(hasColorscale(trace, 'line')) {\n            colorscaleCalc(gd, trace, {\n                vals: trace.line.color,\n                containerStr: 'line',\n                cLetter: 'c'\n            });\n        }\n        markerColorscale = Drawing.tryColorscale(line);\n    } else {\n        markerColorscale = Lib.identity;\n    }\n\n    // Build color generation function\n    function getMarkerColorInfo(index) {\n        var value;\n        if(Lib.isArrayOrTypedArray(line.color)) {\n            value = line.color[index % line.color.length];\n        } else {\n            value = line.color;\n        }\n\n        return {color: markerColorscale(value), rawColor: value};\n    }\n\n    // Number of values and counts\n    // ---------------------------\n    var numValues = visibleDims[0].values.length;\n\n    // Build path info\n    // ---------------\n    // Mapping from category inds to PathModel objects\n    var pathModels = {};\n\n    // Category inds array for each dimension\n    var categoryIndsDims = uniqueInfoDims.map(function(di) {return di.inds;});\n\n    // Initialize total count\n    totalCount = 0;\n    var valueInd;\n    var d;\n\n    for(valueInd = 0; valueInd < numValues; valueInd++) {\n        // Category inds for this input value across dimensions\n        var categoryIndsPath = [];\n        for(d = 0; d < categoryIndsDims.length; d++) {\n            categoryIndsPath.push(categoryIndsDims[d][valueInd]);\n        }\n\n        // Count\n        count = counts[valueInd % counts.length];\n\n        // Update total count\n        totalCount += count;\n\n        // Path color\n        var pathColorInfo = getMarkerColorInfo(valueInd);\n\n        // path key\n        var pathKey = categoryIndsPath + '-' + pathColorInfo.rawColor;\n\n        // Create / Update PathModel\n        if(pathModels[pathKey] === undefined) {\n            pathModels[pathKey] = createPathModel(categoryIndsPath,\n                pathColorInfo.color,\n                pathColorInfo.rawColor);\n        }\n        updatePathModel(pathModels[pathKey], valueInd, count);\n    }\n\n    var dimensionModels = visibleDims.map(function(di, i) {\n        return createDimensionModel(i, di._index, di._displayindex, di.label, totalCount);\n    });\n\n\n    for(valueInd = 0; valueInd < numValues; valueInd++) {\n        count = counts[valueInd % counts.length];\n\n        for(d = 0; d < dimensionModels.length; d++) {\n            var containerInd = dimensionModels[d].containerInd;\n            var catInd = uniqueInfoDims[d].inds[valueInd];\n            var cats = dimensionModels[d].categories;\n\n            if(cats[catInd] === undefined) {\n                var catValue = trace.dimensions[containerInd]._categoryarray[catInd];\n                var catLabel = trace.dimensions[containerInd]._ticktext[catInd];\n                cats[catInd] = createCategoryModel(d, catInd, catValue, catLabel);\n            }\n\n            updateCategoryModel(cats[catInd], valueInd, count);\n        }\n    }\n\n    // Compute unique\n    return wrap(createParcatsModel(dimensionModels, pathModels, totalCount));\n};\n\n// Models\n// ======\n\n// Parcats Model\n// -------------\n/**\n * @typedef {Object} ParcatsModel\n *  Object containing calculated information about a parcats trace\n *\n * @property {Array.<DimensionModel>} dimensions\n *  Array of dimension models\n * @property {Object.<string,PathModel>} paths\n *  Dictionary from category inds string (e.g. \"1,2,1,1\") to path model\n * @property {Number} maxCats\n *  The maximum number of categories of any dimension in the diagram\n * @property {Number} count\n *  Total number of input values\n * @property {Object} trace\n */\n\n/**\n * Create and new ParcatsModel object\n * @param {Array.<DimensionModel>} dimensions\n * @param {Object.<string,PathModel>} paths\n * @param {Number} count\n * @return {ParcatsModel}\n */\nfunction createParcatsModel(dimensions, paths, count) {\n    var maxCats = dimensions\n        .map(function(d) {return d.categories.length;})\n        .reduce(function(v1, v2) {return Math.max(v1, v2);});\n    return {dimensions: dimensions, paths: paths, trace: undefined, maxCats: maxCats, count: count};\n}\n\n// Dimension Model\n// ---------------\n/**\n * @typedef {Object} DimensionModel\n *  Object containing calculated information about a single dimension\n *\n * @property {Number} dimensionInd\n *  The index of this dimension among the *visible* dimensions\n * @property {Number} containerInd\n *  The index of this dimension in the original dimensions container,\n *  irrespective of dimension visibility\n * @property {Number} displayInd\n *  The display index of this dimension (where 0 is the left most dimension)\n * @property {String} dimensionLabel\n *  The label of this dimension\n * @property {Number} count\n *  Total number of input values\n * @property {Array.<CategoryModel>} categories\n * @property {Number|null} dragX\n *  The x position of dimension that is currently being dragged. null if not being dragged\n */\n\n/**\n * Create and new DimensionModel object with an empty categories array\n * @param {Number} dimensionInd\n * @param {Number} containerInd\n * @param {Number} displayInd\n * @param {String} dimensionLabel\n * @param {Number} count\n *  Total number of input values\n * @return {DimensionModel}\n */\nfunction createDimensionModel(dimensionInd, containerInd, displayInd, dimensionLabel, count) {\n    return {\n        dimensionInd: dimensionInd,\n        containerInd: containerInd,\n        displayInd: displayInd,\n        dimensionLabel: dimensionLabel,\n        count: count,\n        categories: [],\n        dragX: null\n    };\n}\n\n// Category Model\n// --------------\n/**\n * @typedef {Object} CategoryModel\n *  Object containing calculated information about a single category.\n *\n * @property {Number} dimensionInd\n *  The index of this categories dimension\n * @property {Number} categoryInd\n *  The index of this category\n * @property {Number} displayInd\n *  The display index of this category (where 0 is the topmost category)\n * @property {String} categoryLabel\n *  The name of this category\n * @property categoryValue: Raw value of the category\n * @property {Array} valueInds\n *  Array of indices (into the original value array) of all samples in this category\n * @property {Number} count\n *  The number of elements from the original array in this path\n * @property {Number|null} dragY\n *  The y position of category that is currently being dragged. null if not being dragged\n */\n\n/**\n * Create and return a new CategoryModel object\n * @param {Number} dimensionInd\n * @param {Number} categoryInd\n *  The display index of this category (where 0 is the topmost category)\n * @param {String} categoryValue\n * @param {String} categoryLabel\n * @return {CategoryModel}\n */\nfunction createCategoryModel(dimensionInd, categoryInd, categoryValue, categoryLabel) {\n    return {\n        dimensionInd: dimensionInd,\n        categoryInd: categoryInd,\n        categoryValue: categoryValue,\n        displayInd: categoryInd,\n        categoryLabel: categoryLabel,\n        valueInds: [],\n        count: 0,\n        dragY: null\n    };\n}\n\n/**\n * Update a CategoryModel object with a new value index\n * Note: The calling parameter is modified in place.\n *\n * @param {CategoryModel} categoryModel\n * @param {Number} valueInd\n * @param {Number} count\n */\nfunction updateCategoryModel(categoryModel, valueInd, count) {\n    categoryModel.valueInds.push(valueInd);\n    categoryModel.count += count;\n}\n\n\n// Path Model\n// ----------\n/**\n * @typedef {Object} PathModel\n *  Object containing calculated information about the samples in a path.\n *\n * @property {Array} categoryInds\n *  Array of category indices for each dimension (length `numDimensions`)\n * @param {String} pathColor\n *  Color of this path. (Note: Any colorscaling has already taken place)\n * @property {Array} valueInds\n *  Array of indices (into the original value array) of all samples in this path\n * @property {Number} count\n *  The number of elements from the original array in this path\n * @property {String} color\n *  The path's color (ass CSS color string)\n * @property rawColor\n *  The raw color value specified by the user. May be a CSS color string or a Number\n */\n\n/**\n * Create and return a new PathModel object\n * @param {Array} categoryInds\n * @param color\n * @param rawColor\n * @return {PathModel}\n */\nfunction createPathModel(categoryInds, color, rawColor) {\n    return {\n        categoryInds: categoryInds,\n        color: color,\n        rawColor: rawColor,\n        valueInds: [],\n        count: 0\n    };\n}\n\n/**\n * Update a PathModel object with a new value index\n * Note: The calling parameter is modified in place.\n *\n * @param {PathModel} pathModel\n * @param {Number} valueInd\n * @param {Number} count\n */\nfunction updatePathModel(pathModel, valueInd, count) {\n    pathModel.valueInds.push(valueInd);\n    pathModel.count += count;\n}\n\n// Unique calculations\n// ===================\n/**\n * @typedef {Object} UniqueInfo\n *  Object containing information about the unique values of an input array\n *\n * @property {Array} uniqueValues\n *  The unique values in the input array\n * @property {Array} uniqueCounts\n *  The number of times each entry in uniqueValues occurs in input array.\n *  This has the same length as `uniqueValues`\n * @property {Array} inds\n *  Indices into uniqueValues that would reproduce original input array\n */\n\n/**\n * Compute unique value information for an array\n *\n * IMPORTANT: Note that values are considered unique\n * if their string representations are unique.\n *\n * @param {Array} values\n * @param {Array|undefined} uniqueValues\n *  Array of expected unique values. The uniqueValues property of the resulting UniqueInfo object will begin with\n *  these entries. Entries are included even if there are zero occurrences in the values array. Entries found in\n *  the values array that are not present in uniqueValues will be included at the end of the array in the\n *  UniqueInfo object.\n * @return {UniqueInfo}\n */\nfunction getUniqueInfo(values, uniqueValues) {\n    // Initialize uniqueValues if not specified\n    if(uniqueValues === undefined || uniqueValues === null) {\n        uniqueValues = [];\n    } else {\n        // Shallow copy so append below doesn't alter input array\n        uniqueValues = uniqueValues.map(function(e) {return e;});\n    }\n\n    // Initialize Variables\n    var uniqueValueCounts = {};\n    var uniqueValueInds = {};\n    var inds = [];\n\n    // Initialize uniqueValueCounts and\n    uniqueValues.forEach(function(uniqueVal, valInd) {\n        uniqueValueCounts[uniqueVal] = 0;\n        uniqueValueInds[uniqueVal] = valInd;\n    });\n\n    // Compute the necessary unique info in a single pass\n    for(var i = 0; i < values.length; i++) {\n        var item = values[i];\n        var itemInd;\n\n        if(uniqueValueCounts[item] === undefined) {\n            // This item has a previously unseen value\n            uniqueValueCounts[item] = 1;\n            itemInd = uniqueValues.push(item) - 1;\n            uniqueValueInds[item] = itemInd;\n        } else {\n            // Increment count for this item\n            uniqueValueCounts[item]++;\n            itemInd = uniqueValueInds[item];\n        }\n        inds.push(itemInd);\n    }\n\n    // Build UniqueInfo\n    var uniqueCounts = uniqueValues.map(function(v) { return uniqueValueCounts[v]; });\n\n    return {\n        uniqueValues: uniqueValues,\n        uniqueCounts: uniqueCounts,\n        inds: inds\n    };\n}\n\n\n/**\n * Validate the requested display order for the dimensions.\n * If the display order is a permutation of 0 through dimensions.length - 1, link to _displayindex\n * Otherwise, replace the display order with the dimension order\n * @param {Object} trace\n */\nfunction validateDimensionDisplayInds(visibleDims) {\n    var displayInds = visibleDims.map(function(d) { return d.displayindex; });\n    var i;\n\n    if(isRangePermutation(displayInds)) {\n        for(i = 0; i < visibleDims.length; i++) {\n            visibleDims[i]._displayindex = visibleDims[i].displayindex;\n        }\n    } else {\n        for(i = 0; i < visibleDims.length; i++) {\n            visibleDims[i]._displayindex = i;\n        }\n    }\n}\n\n\n/**\n * Update category properties based on the unique values found for this dimension\n * @param {Object} dim\n * @param {UniqueInfo} uniqueInfoDim\n */\nfunction validateCategoryProperties(dim, uniqueInfoDim) {\n    // Update categoryarray\n    dim._categoryarray = uniqueInfoDim.uniqueValues;\n\n    // Handle ticktext\n    if(dim.ticktext === null || dim.ticktext === undefined) {\n        dim._ticktext = [];\n    } else {\n        // Shallow copy to avoid modifying input array\n        dim._ticktext = dim.ticktext.slice();\n    }\n\n    // Extend ticktext with elements from uniqueInfoDim.uniqueValues\n    for(var i = dim._ticktext.length; i < uniqueInfoDim.uniqueValues.length; i++) {\n        dim._ticktext.push(uniqueInfoDim.uniqueValues[i]);\n    }\n}\n\n/**\n * Determine whether an array contains a permutation of the integers from 0 to the array's length - 1\n * @param {Array} inds\n * @return {boolean}\n */\nfunction isRangePermutation(inds) {\n    var indsSpecified = new Array(inds.length);\n\n    for(var i = 0; i < inds.length; i++) {\n        // Check for out of bounds\n        if(inds[i] < 0 || inds[i] >= inds.length) {\n            return false;\n        }\n\n        // Check for collisions with already specified index\n        if(indsSpecified[inds[i]] !== undefined) {\n            return false;\n        }\n\n        indsSpecified[inds[i]] = true;\n    }\n\n    // Nothing out of bounds and no collisions. We have a permutation\n    return true;\n}\n\n},{\"../../components/colorscale/calc\":601,\"../../components/colorscale/helpers\":604,\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/filter_unique.js\":711,\"../../lib/gup\":717}],1070:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar handleDomainDefaults = _dereq_('../../plots/domain').defaults;\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nvar attributes = _dereq_('./attributes');\nvar mergeLength = _dereq_('../parcoords/merge_length');\n\nfunction handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {\n    coerce('line.shape');\n    coerce('line.hovertemplate');\n\n    var lineColor = coerce('line.color', layout.colorway[0]);\n    if(hasColorscale(traceIn, 'line') && Lib.isArrayOrTypedArray(lineColor)) {\n        if(lineColor.length) {\n            coerce('line.colorscale');\n            colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});\n            return lineColor.length;\n        } else {\n            traceOut.line.color = defaultColor;\n        }\n    }\n    return Infinity;\n}\n\nfunction dimensionDefaults(dimensionIn, dimensionOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(dimensionIn, dimensionOut, attributes.dimensions, attr, dflt);\n    }\n\n    var values = coerce('values');\n    var visible = coerce('visible');\n    if(!(values && values.length)) {\n        visible = dimensionOut.visible = false;\n    }\n\n    if(visible) {\n        // Dimension level\n        coerce('label');\n        coerce('displayindex', dimensionOut._index);\n\n        // Category level\n        var arrayIn = dimensionIn.categoryarray;\n        var isValidArray = (Array.isArray(arrayIn) && arrayIn.length > 0);\n\n        var orderDefault;\n        if(isValidArray) orderDefault = 'array';\n        var order = coerce('categoryorder', orderDefault);\n\n        // coerce 'categoryarray' only in array order case\n        if(order === 'array') {\n            coerce('categoryarray');\n            coerce('ticktext');\n        } else {\n            delete dimensionIn.categoryarray;\n            delete dimensionIn.ticktext;\n        }\n\n        // cannot set 'categoryorder' to 'array' with an invalid 'categoryarray'\n        if(!isValidArray && order === 'array') {\n            dimensionOut.categoryorder = 'trace';\n        }\n    }\n}\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var dimensions = handleArrayContainerDefaults(traceIn, traceOut, {\n        name: 'dimensions',\n        handleItemDefaults: dimensionDefaults\n    });\n\n    var len = handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n\n    handleDomainDefaults(traceOut, layout, coerce);\n\n    if(!Array.isArray(dimensions) || !dimensions.length) {\n        traceOut.visible = false;\n    }\n\n    mergeLength(traceOut, dimensions, 'values', len);\n\n    coerce('hoveron');\n    coerce('hovertemplate');\n    coerce('arrangement');\n    coerce('bundlecolors');\n    coerce('sortpaths');\n    coerce('counts');\n\n    var labelfontDflt = {\n        family: layout.font.family,\n        size: Math.round(layout.font.size),\n        color: layout.font.color\n    };\n\n    Lib.coerceFont(coerce, 'labelfont', labelfontDflt);\n\n    var categoryfontDefault = {\n        family: layout.font.family,\n        size: Math.round(layout.font.size / 1.2),\n        color: layout.font.color\n    };\n\n    Lib.coerceFont(coerce, 'tickfont', categoryfontDefault);\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../components/colorscale/helpers\":604,\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"../../plots/domain\":792,\"../parcoords/merge_length\":1083,\"./attributes\":1067}],1071:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    colorbar: {\n        container: 'line',\n        min: 'cmin',\n        max: 'cmax'\n    },\n\n    moduleType: 'trace',\n    name: 'parcats',\n    basePlotModule: _dereq_('./base_plot'),\n    categories: ['noOpacity'],\n    meta: {\n        \n    }\n};\n\n},{\"./attributes\":1067,\"./base_plot\":1068,\"./calc\":1069,\"./defaults\":1070,\"./plot\":1073}],1072:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Plotly = _dereq_('../../plot_api/plot_api');\nvar Fx = _dereq_('../../components/fx');\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../../components/drawing');\nvar tinycolor = _dereq_('tinycolor2');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\n\nfunction performPlot(parcatsModels, graphDiv, layout, svg) {\n    var viewModels = parcatsModels.map(createParcatsViewModel.bind(0, graphDiv, layout));\n\n    // Get (potentially empty) parcatslayer selection with bound data to single element array\n    var layerSelection = svg.selectAll('g.parcatslayer').data([null]);\n\n    // Initialize single parcatslayer group if it doesn't exist\n    layerSelection.enter()\n        .append('g')\n        .attr('class', 'parcatslayer')\n        .style('pointer-events', 'all');\n\n    // Bind data to children of layerSelection and get reference to traceSelection\n    var traceSelection = layerSelection\n        .selectAll('g.trace.parcats')\n        .data(viewModels, key);\n\n    // Initialize group for each trace/dimensions\n    var traceEnter = traceSelection.enter()\n        .append('g')\n        .attr('class', 'trace parcats');\n\n    // Update properties for each trace\n    traceSelection\n        .attr('transform', function(d) {\n            return 'translate(' + d.x + ', ' + d.y + ')';\n        });\n\n    // Initialize paths group\n    traceEnter\n        .append('g')\n        .attr('class', 'paths');\n\n    // Update paths transform\n    var pathsSelection = traceSelection\n        .select('g.paths');\n\n    // Get paths selection\n    var pathSelection = pathsSelection\n        .selectAll('path.path')\n        .data(function(d) {\n            return d.paths;\n        }, key);\n\n    // Update existing path colors\n    pathSelection\n        .attr('fill', function(d) {\n            return d.model.color;\n        });\n\n    // Create paths\n    var pathSelectionEnter = pathSelection\n        .enter()\n        .append('path')\n        .attr('class', 'path')\n        .attr('stroke-opacity', 0)\n        .attr('fill', function(d) {\n            return d.model.color;\n        })\n        .attr('fill-opacity', 0);\n\n    stylePathsNoHover(pathSelectionEnter);\n\n    // Set path geometry\n    pathSelection\n        .attr('d', function(d) {\n            return d.svgD;\n        });\n\n    // sort paths\n    if(!pathSelectionEnter.empty()) {\n        // Only sort paths if there has been a change.\n        // Otherwise paths are already sorted or a hover operation may be in progress\n        pathSelection.sort(compareRawColor);\n    }\n\n    // Remove any old paths\n    pathSelection.exit().remove();\n\n    // Path hover\n    pathSelection\n        .on('mouseover', mouseoverPath)\n        .on('mouseout', mouseoutPath)\n        .on('click', clickPath);\n\n    // Initialize dimensions group\n    traceEnter.append('g').attr('class', 'dimensions');\n\n    // Update dimensions transform\n    var dimensionsSelection = traceSelection\n        .select('g.dimensions');\n\n    // Get dimension selection\n    var dimensionSelection = dimensionsSelection\n        .selectAll('g.dimension')\n        .data(function(d) {\n            return d.dimensions;\n        }, key);\n\n    // Create dimension groups\n    dimensionSelection.enter()\n        .append('g')\n        .attr('class', 'dimension');\n\n    // Update dimension group transforms\n    dimensionSelection.attr('transform', function(d) {\n        return 'translate(' + d.x + ', 0)';\n    });\n\n    // Remove any old dimensions\n    dimensionSelection.exit().remove();\n\n    // Get category selection\n    var categorySelection = dimensionSelection\n        .selectAll('g.category')\n        .data(function(d) {\n            return d.categories;\n        }, key);\n\n    // Initialize category groups\n    var categoryGroupEnterSelection = categorySelection\n        .enter()\n        .append('g')\n        .attr('class', 'category');\n\n    // Update category transforms\n    categorySelection\n        .attr('transform', function(d) {\n            return 'translate(0, ' + d.y + ')';\n        });\n\n\n    // Initialize rectangle\n    categoryGroupEnterSelection\n        .append('rect')\n        .attr('class', 'catrect')\n        .attr('pointer-events', 'none');\n\n\n    // Update rectangle\n    categorySelection.select('rect.catrect')\n        .attr('fill', 'none')\n        .attr('width', function(d) {\n            return d.width;\n        })\n        .attr('height', function(d) {\n            return d.height;\n        });\n\n    styleCategoriesNoHover(categoryGroupEnterSelection);\n\n    // Initialize color band rects\n    var bandSelection = categorySelection\n        .selectAll('rect.bandrect')\n        .data(\n            /** @param {CategoryViewModel} catViewModel*/\n            function(catViewModel) {\n                return catViewModel.bands;\n            }, key);\n\n    // Raise all update bands to the top so that fading enter/exit bands will be behind\n    bandSelection.each(function() {Lib.raiseToTop(this);});\n\n    // Update band color\n    bandSelection\n        .attr('fill', function(d) {\n            return d.color;\n        });\n\n    var bandsSelectionEnter = bandSelection.enter()\n        .append('rect')\n        .attr('class', 'bandrect')\n        .attr('stroke-opacity', 0)\n        .attr('fill', function(d) {\n            return d.color;\n        })\n        .attr('fill-opacity', 0);\n\n    bandSelection\n        .attr('fill', function(d) {\n            return d.color;\n        })\n        .attr('width', function(d) {\n            return d.width;\n        })\n        .attr('height', function(d) {\n            return d.height;\n        })\n        .attr('y', function(d) {\n            return d.y;\n        })\n        .attr('cursor',\n            /** @param {CategoryBandViewModel} bandModel*/\n            function(bandModel) {\n                if(bandModel.parcatsViewModel.arrangement === 'fixed') {\n                    return 'default';\n                } else if(bandModel.parcatsViewModel.arrangement === 'perpendicular') {\n                    return 'ns-resize';\n                } else {\n                    return 'move';\n                }\n            });\n\n    styleBandsNoHover(bandsSelectionEnter);\n\n    bandSelection.exit().remove();\n\n    // Initialize category label\n    categoryGroupEnterSelection\n        .append('text')\n        .attr('class', 'catlabel')\n        .attr('pointer-events', 'none');\n\n    var paperColor = graphDiv._fullLayout.paper_bgcolor;\n\n    // Update category label\n    categorySelection.select('text.catlabel')\n        .attr('text-anchor',\n            function(d) {\n                if(catInRightDim(d)) {\n                    // Place label to the right of category\n                    return 'start';\n                } else {\n                    // Place label to the left of category\n                    return 'end';\n                }\n            })\n        .attr('alignment-baseline', 'middle')\n\n        .style('text-shadow',\n            paperColor + ' -1px  1px 2px, ' +\n            paperColor + ' 1px  1px 2px, ' +\n            paperColor + '  1px -1px 2px, ' +\n            paperColor + ' -1px -1px 2px')\n        .style('fill', 'rgb(0, 0, 0)')\n        .attr('x',\n            function(d) {\n                if(catInRightDim(d)) {\n                    // Place label to the right of category\n                    return d.width + 5;\n                } else {\n                    // Place label to the left of category\n                    return -5;\n                }\n            })\n        .attr('y', function(d) {\n            return d.height / 2;\n        })\n        .text(function(d) {\n            return d.model.categoryLabel;\n        })\n        .each(\n            /** @param {CategoryViewModel} catModel*/\n            function(catModel) {\n                Drawing.font(d3.select(this), catModel.parcatsViewModel.categorylabelfont);\n                svgTextUtils.convertToTspans(d3.select(this), graphDiv);\n            });\n\n    // Initialize dimension label\n    categoryGroupEnterSelection\n        .append('text')\n        .attr('class', 'dimlabel');\n\n    // Update dimension label\n    categorySelection.select('text.dimlabel')\n        .attr('text-anchor', 'middle')\n        .attr('alignment-baseline', 'baseline')\n        .attr('cursor',\n             /** @param {CategoryViewModel} catModel*/\n            function(catModel) {\n                if(catModel.parcatsViewModel.arrangement === 'fixed') {\n                    return 'default';\n                } else {\n                    return 'ew-resize';\n                }\n            })\n        .attr('x', function(d) {\n            return d.width / 2;\n        })\n        .attr('y', -5)\n        .text(function(d, i) {\n            if(i === 0) {\n                // Add dimension label above topmost category\n                return d.parcatsViewModel.model.dimensions[d.model.dimensionInd].dimensionLabel;\n            } else {\n                return null;\n            }\n        })\n        .each(\n            /** @param {CategoryViewModel} catModel*/\n            function(catModel) {\n                Drawing.font(d3.select(this), catModel.parcatsViewModel.labelfont);\n            });\n\n    // Category hover\n    // categorySelection.select('rect.catrect')\n    categorySelection.selectAll('rect.bandrect')\n        .on('mouseover', mouseoverCategoryBand)\n        .on('mouseout', mouseoutCategory);\n\n    // Remove unused categories\n    categorySelection.exit().remove();\n\n    // Setup drag\n    dimensionSelection.call(d3.behavior.drag()\n        .origin(function(d) {\n            return {x: d.x, y: 0};\n        })\n        .on('dragstart', dragDimensionStart)\n        .on('drag', dragDimension)\n        .on('dragend', dragDimensionEnd));\n\n\n    // Save off selections to view models\n    traceSelection.each(function(d) {\n        d.traceSelection = d3.select(this);\n        d.pathSelection = d3.select(this).selectAll('g.paths').selectAll('path.path');\n        d.dimensionSelection = d3.select(this).selectAll('g.dimensions').selectAll('g.dimension');\n    });\n\n    // Remove any orphan traces\n    traceSelection.exit().remove();\n}\n\n/**\n * Create / update parcat traces\n *\n * @param {Object} graphDiv\n * @param {Object} svg\n * @param {Array.<ParcatsModel>} parcatsModels\n * @param {Layout} layout\n */\nmodule.exports = function(graphDiv, svg, parcatsModels, layout) {\n    performPlot(parcatsModels, graphDiv, layout, svg);\n};\n\n/**\n * Function the returns the key property of an object for use with as D3 join function\n * @param d\n */\nfunction key(d) {\n    return d.key;\n}\n\n /** True if a category view model is in the right-most display dimension\n  * @param {CategoryViewModel} d */\nfunction catInRightDim(d) {\n    var numDims = d.parcatsViewModel.dimensions.length;\n    var leftDimInd = d.parcatsViewModel.dimensions[numDims - 1].model.dimensionInd;\n    return d.model.dimensionInd === leftDimInd;\n}\n\n/**\n * @param {PathViewModel} a\n * @param {PathViewModel} b\n */\nfunction compareRawColor(a, b) {\n    if(a.model.rawColor > b.model.rawColor) {\n        return 1;\n    } else if(a.model.rawColor < b.model.rawColor) {\n        return -1;\n    } else {\n        return 0;\n    }\n}\n\n/**\n * Handle path mouseover\n * @param {PathViewModel} d\n */\nfunction mouseoverPath(d) {\n    if(!d.parcatsViewModel.dragDimension) {\n        // We're not currently dragging\n\n        if(d.parcatsViewModel.hoverinfoItems.indexOf('skip') === -1) {\n            // hoverinfo is not skip, so we at least style the paths and emit interaction events\n\n            // Raise path to top\n            Lib.raiseToTop(this);\n\n            stylePathsHover(d3.select(this));\n\n            // Emit hover event\n            var points = buildPointsArrayForPath(d);\n            d.parcatsViewModel.graphDiv.emit('plotly_hover', {points: points, event: d3.event});\n\n            // Handle hover label\n            if(d.parcatsViewModel.hoverinfoItems.indexOf('none') === -1) {\n                // hoverinfo is a combination of 'count' and 'probability'\n\n                // Mouse\n                var hoverX = d3.mouse(this)[0];\n\n                // Label\n                var gd = d.parcatsViewModel.graphDiv;\n                var trace = d.parcatsViewModel.trace;\n                var fullLayout = gd._fullLayout;\n                var rootBBox = fullLayout._paperdiv.node().getBoundingClientRect();\n                var graphDivBBox = d.parcatsViewModel.graphDiv.getBoundingClientRect();\n\n                // Find path center in path coordinates\n                var pathCenterX,\n                    pathCenterY,\n                    dimInd;\n\n                for(dimInd = 0; dimInd < (d.leftXs.length - 1); dimInd++) {\n                    if(d.leftXs[dimInd] + d.dimWidths[dimInd] - 2 <= hoverX && hoverX <= d.leftXs[dimInd + 1] + 2) {\n                        var leftDim = d.parcatsViewModel.dimensions[dimInd];\n                        var rightDim = d.parcatsViewModel.dimensions[dimInd + 1];\n                        pathCenterX = (leftDim.x + leftDim.width + rightDim.x) / 2;\n                        pathCenterY = (d.topYs[dimInd] + d.topYs[dimInd + 1] + d.height) / 2;\n                        break;\n                    }\n                }\n\n                // Find path center in root coordinates\n                var hoverCenterX = d.parcatsViewModel.x + pathCenterX;\n                var hoverCenterY = d.parcatsViewModel.y + pathCenterY;\n\n                var textColor = tinycolor.mostReadable(d.model.color, ['black', 'white']);\n\n                var count = d.model.count;\n                var prob = count / d.parcatsViewModel.model.count;\n                var labels = {\n                    countLabel: count,\n                    probabilityLabel: prob.toFixed(3)\n                };\n\n                // Build hover text\n                var hovertextParts = [];\n                if(d.parcatsViewModel.hoverinfoItems.indexOf('count') !== -1) {\n                    hovertextParts.push(['Count:', labels.countLabel].join(' '));\n                }\n                if(d.parcatsViewModel.hoverinfoItems.indexOf('probability') !== -1) {\n                    hovertextParts.push(['P:', labels.probabilityLabel].join(' '));\n                }\n\n                var hovertext = hovertextParts.join('<br>');\n                var mouseX = d3.mouse(gd)[0];\n\n                Fx.loneHover({\n                    trace: trace,\n                    x: hoverCenterX - rootBBox.left + graphDivBBox.left,\n                    y: hoverCenterY - rootBBox.top + graphDivBBox.top,\n                    text: hovertext,\n                    color: d.model.color,\n                    borderColor: 'black',\n                    fontFamily: 'Monaco, \"Courier New\", monospace',\n                    fontSize: 10,\n                    fontColor: textColor,\n                    idealAlign: mouseX < hoverCenterX ? 'right' : 'left',\n                    hovertemplate: (trace.line || {}).hovertemplate,\n                    hovertemplateLabels: labels,\n                    eventData: [{\n                        data: trace._input,\n                        fullData: trace,\n                        count: count,\n                        probability: prob\n                    }]\n                }, {\n                    container: fullLayout._hoverlayer.node(),\n                    outerContainer: fullLayout._paper.node(),\n                    gd: gd\n                });\n            }\n        }\n    }\n}\n\n/**\n * Handle path mouseout\n * @param {PathViewModel} d\n */\nfunction mouseoutPath(d) {\n    if(!d.parcatsViewModel.dragDimension) {\n        // We're not currently dragging\n        stylePathsNoHover(d3.select(this));\n\n        // Remove and hover label\n        Fx.loneUnhover(d.parcatsViewModel.graphDiv._fullLayout._hoverlayer.node());\n\n        // Restore path order\n        d.parcatsViewModel.pathSelection.sort(compareRawColor);\n\n        // Emit unhover event\n        if(d.parcatsViewModel.hoverinfoItems.indexOf('skip') === -1) {\n            var points = buildPointsArrayForPath(d);\n            d.parcatsViewModel.graphDiv.emit('plotly_unhover', {points: points, event: d3.event});\n        }\n    }\n}\n\n/**\n * Build array of point objects for a path\n *\n * For use in click/hover events\n * @param {PathViewModel} d\n */\nfunction buildPointsArrayForPath(d) {\n    var points = [];\n    var curveNumber = getTraceIndex(d.parcatsViewModel);\n\n    for(var i = 0; i < d.model.valueInds.length; i++) {\n        var pointNumber = d.model.valueInds[i];\n        points.push({\n            curveNumber: curveNumber,\n            pointNumber: pointNumber\n        });\n    }\n    return points;\n}\n\n/**\n * Handle path click\n * @param {PathViewModel} d\n */\nfunction clickPath(d) {\n    if(d.parcatsViewModel.hoverinfoItems.indexOf('skip') === -1) {\n        // hoverinfo it's skip, so interaction events aren't disabled\n        var points = buildPointsArrayForPath(d);\n        d.parcatsViewModel.graphDiv.emit('plotly_click', {points: points, event: d3.event});\n    }\n}\n\nfunction stylePathsNoHover(pathSelection) {\n    pathSelection\n        .attr('fill', function(d) {\n            return d.model.color;\n        })\n        .attr('fill-opacity', 0.6)\n        .attr('stroke', 'lightgray')\n        .attr('stroke-width', 0.2)\n        .attr('stroke-opacity', 1.0);\n}\n\nfunction stylePathsHover(pathSelection) {\n    pathSelection\n        .attr('fill-opacity', 0.8)\n        .attr('stroke', function(d) {\n            return tinycolor.mostReadable(d.model.color, ['black', 'white']);\n        })\n        .attr('stroke-width', 0.3);\n}\n\nfunction styleCategoryHover(categorySelection) {\n    categorySelection\n        .select('rect.catrect')\n        .attr('stroke', 'black')\n        .attr('stroke-width', 2.5);\n}\n\nfunction styleCategoriesNoHover(categorySelection) {\n    categorySelection\n        .select('rect.catrect')\n        .attr('stroke', 'black')\n        .attr('stroke-width', 1)\n        .attr('stroke-opacity', 1);\n}\n\nfunction styleBandsHover(bandsSelection) {\n    bandsSelection\n        .attr('stroke', 'black')\n        .attr('stroke-width', 1.5);\n}\n\nfunction styleBandsNoHover(bandsSelection) {\n    bandsSelection\n        .attr('stroke', 'black')\n        .attr('stroke-width', 0.2)\n        .attr('stroke-opacity', 1.0)\n        .attr('fill-opacity', 1.0);\n}\n\n/**\n * Return selection of all paths that pass through the specified category\n * @param {CategoryBandViewModel} catBandViewModel\n */\nfunction selectPathsThroughCategoryBandColor(catBandViewModel) {\n    var allPaths = catBandViewModel.parcatsViewModel.pathSelection;\n    var dimInd = catBandViewModel.categoryViewModel.model.dimensionInd;\n    var catInd = catBandViewModel.categoryViewModel.model.categoryInd;\n\n    return allPaths\n        .filter(\n            /** @param {PathViewModel} pathViewModel */\n            function(pathViewModel) {\n                return pathViewModel.model.categoryInds[dimInd] === catInd &&\n                    pathViewModel.model.color === catBandViewModel.color;\n            });\n}\n\n\n/**\n * Perform hover styling for all paths that pass though the specified band element's category\n *\n * @param {HTMLElement} bandElement\n *  HTML element for band\n *\n */\nfunction styleForCategoryHovermode(bandElement) {\n    // Get all bands in the current category\n    var bandSel = d3.select(bandElement.parentNode).selectAll('rect.bandrect');\n\n    // Raise and style paths\n    bandSel.each(function(bvm) {\n        var paths = selectPathsThroughCategoryBandColor(bvm);\n        stylePathsHover(paths);\n        paths.each(function() {\n            // Raise path to top\n            Lib.raiseToTop(this);\n        });\n    });\n\n    // Style category\n    styleCategoryHover(d3.select(bandElement.parentNode));\n}\n\n/**\n * Perform hover styling for all paths that pass though the category of the specified band element and share the\n * same color\n *\n * @param {HTMLElement} bandElement\n *  HTML element for band\n *\n */\nfunction styleForColorHovermode(bandElement) {\n    var bandViewModel = d3.select(bandElement).datum();\n    var catPaths = selectPathsThroughCategoryBandColor(bandViewModel);\n    stylePathsHover(catPaths);\n    catPaths.each(function() {\n        // Raise path to top\n        Lib.raiseToTop(this);\n    });\n\n    // Style category for drag\n    d3.select(bandElement.parentNode)\n        .selectAll('rect.bandrect')\n        .filter(function(b) {return b.color === bandViewModel.color;})\n        .each(function() {\n            Lib.raiseToTop(this);\n            styleBandsHover(d3.select(this));\n        });\n}\n\n\n/**\n * @param {HTMLElement} bandElement\n *  HTML element for band\n * @param eventName\n *  Event name (plotly_hover or plotly_click)\n * @param event\n *  Mouse Event\n */\nfunction emitPointsEventCategoryHovermode(bandElement, eventName, event) {\n    // Get all bands in the current category\n    var bandViewModel = d3.select(bandElement).datum();\n    var gd = bandViewModel.parcatsViewModel.graphDiv;\n    var bandSel = d3.select(bandElement.parentNode).selectAll('rect.bandrect');\n\n    var points = [];\n    bandSel.each(function(bvm) {\n        var paths = selectPathsThroughCategoryBandColor(bvm);\n        paths.each(function(pathViewModel) {\n            // Extend points array\n            Array.prototype.push.apply(points, buildPointsArrayForPath(pathViewModel));\n        });\n    });\n\n    gd.emit(eventName, {points: points, event: event});\n}\n\n/**\n * @param {HTMLElement} bandElement\n *  HTML element for band\n * @param eventName\n *  Event name (plotly_hover or plotly_click)\n * @param event\n *  Mouse Event\n */\nfunction emitPointsEventColorHovermode(bandElement, eventName, event) {\n    var bandViewModel = d3.select(bandElement).datum();\n    var gd = bandViewModel.parcatsViewModel.graphDiv;\n    var paths = selectPathsThroughCategoryBandColor(bandViewModel);\n\n    var points = [];\n    paths.each(function(pathViewModel) {\n        // Extend points array\n        Array.prototype.push.apply(points, buildPointsArrayForPath(pathViewModel));\n    });\n\n    gd.emit(eventName, {points: points, event: event});\n}\n\n/**\n * Create hover label for a band element's category (for use when hoveron === 'category')\n *\n * @param {ClientRect} rootBBox\n *  Client bounding box for root of figure\n * @param {HTMLElement} bandElement\n *  HTML element for band\n *\n */\nfunction createHoverLabelForCategoryHovermode(rootBBox, bandElement) {\n    // Selections\n    var rectSelection = d3.select(bandElement.parentNode).select('rect.catrect');\n    var rectBoundingBox = rectSelection.node().getBoundingClientRect();\n\n    // Models\n    /** @type {CategoryViewModel} */\n    var catViewModel = rectSelection.datum();\n    var parcatsViewModel = catViewModel.parcatsViewModel;\n    var dimensionModel = parcatsViewModel.model.dimensions[catViewModel.model.dimensionInd];\n    var trace = parcatsViewModel.trace;\n\n    // Positions\n    var hoverCenterY = rectBoundingBox.top + rectBoundingBox.height / 2;\n    var hoverCenterX,\n        hoverLabelIdealAlign;\n\n    if(parcatsViewModel.dimensions.length > 1 &&\n        dimensionModel.displayInd === parcatsViewModel.dimensions.length - 1) {\n        // right most dimension\n        hoverCenterX = rectBoundingBox.left;\n        hoverLabelIdealAlign = 'left';\n    } else {\n        hoverCenterX = rectBoundingBox.left + rectBoundingBox.width;\n        hoverLabelIdealAlign = 'right';\n    }\n\n    var count = catViewModel.model.count;\n    var catLabel = catViewModel.model.categoryLabel;\n    var prob = count / catViewModel.parcatsViewModel.model.count;\n    var labels = {\n        countLabel: count,\n        categoryLabel: catLabel,\n        probabilityLabel: prob.toFixed(3)\n    };\n\n    // Hover label text\n    var hoverinfoParts = [];\n    if(catViewModel.parcatsViewModel.hoverinfoItems.indexOf('count') !== -1) {\n        hoverinfoParts.push(['Count:', labels.countLabel].join(' '));\n    }\n    if(catViewModel.parcatsViewModel.hoverinfoItems.indexOf('probability') !== -1) {\n        hoverinfoParts.push(['P(' + labels.categoryLabel + '):', labels.probabilityLabel].join(' '));\n    }\n\n    var hovertext = hoverinfoParts.join('<br>');\n    return {\n        trace: trace,\n        x: hoverCenterX - rootBBox.left,\n        y: hoverCenterY - rootBBox.top,\n        text: hovertext,\n        color: 'lightgray',\n        borderColor: 'black',\n        fontFamily: 'Monaco, \"Courier New\", monospace',\n        fontSize: 12,\n        fontColor: 'black',\n        idealAlign: hoverLabelIdealAlign,\n        hovertemplate: trace.hovertemplate,\n        hovertemplateLabels: labels,\n        eventData: [{\n            data: trace._input,\n            fullData: trace,\n            count: count,\n            category: catLabel,\n            probability: prob\n        }]\n    };\n}\n\n/**\n * Create hover label for a band element's category (for use when hoveron === 'category')\n *\n * @param {ClientRect} rootBBox\n *  Client bounding box for root of figure\n * @param {HTMLElement} bandElement\n *  HTML element for band\n *\n */\nfunction createHoverLabelForDimensionHovermode(rootBBox, bandElement) {\n    var allHoverlabels = [];\n\n    d3.select(bandElement.parentNode.parentNode)\n        .selectAll('g.category')\n        .select('rect.catrect')\n        .each(function() {\n            var bandNode = this;\n            allHoverlabels.push(createHoverLabelForCategoryHovermode(rootBBox, bandNode));\n        });\n\n    return allHoverlabels;\n}\n\n/**\n * Create hover labels for a band element's category (for use when hoveron === 'dimension')\n *\n * @param {ClientRect} rootBBox\n *  Client bounding box for root of figure\n * @param {HTMLElement} bandElement\n *  HTML element for band\n *\n */\nfunction createHoverLabelForColorHovermode(rootBBox, bandElement) {\n    var bandBoundingBox = bandElement.getBoundingClientRect();\n\n    // Models\n    /** @type {CategoryBandViewModel} */\n    var bandViewModel = d3.select(bandElement).datum();\n    var catViewModel = bandViewModel.categoryViewModel;\n    var parcatsViewModel = catViewModel.parcatsViewModel;\n    var dimensionModel = parcatsViewModel.model.dimensions[catViewModel.model.dimensionInd];\n    var trace = parcatsViewModel.trace;\n\n    // positions\n    var hoverCenterY = bandBoundingBox.y + bandBoundingBox.height / 2;\n\n    var hoverCenterX,\n        hoverLabelIdealAlign;\n    if(parcatsViewModel.dimensions.length > 1 &&\n        dimensionModel.displayInd === parcatsViewModel.dimensions.length - 1) {\n        // right most dimension\n        hoverCenterX = bandBoundingBox.left;\n        hoverLabelIdealAlign = 'left';\n    } else {\n        hoverCenterX = bandBoundingBox.left + bandBoundingBox.width;\n        hoverLabelIdealAlign = 'right';\n    }\n\n    // Labels\n    var catLabel = catViewModel.model.categoryLabel;\n\n    // Counts\n    var totalCount = bandViewModel.parcatsViewModel.model.count;\n\n    var bandColorCount = 0;\n    bandViewModel.categoryViewModel.bands.forEach(function(b) {\n        if(b.color === bandViewModel.color) {\n            bandColorCount += b.count;\n        }\n    });\n\n    var catCount = catViewModel.model.count;\n\n    var colorCount = 0;\n    parcatsViewModel.pathSelection.each(\n        /** @param {PathViewModel} pathViewModel */\n        function(pathViewModel) {\n            if(pathViewModel.model.color === bandViewModel.color) {\n                colorCount += pathViewModel.model.count;\n            }\n        });\n\n    var pColorAndCat = bandColorCount / totalCount;\n    var pCatGivenColor = bandColorCount / colorCount;\n    var pColorGivenCat = bandColorCount / catCount;\n\n    var labels = {\n        countLabel: totalCount,\n        categoryLabel: catLabel,\n        probabilityLabel: pColorAndCat.toFixed(3)\n    };\n\n    // Hover label text\n    var hoverinfoParts = [];\n    if(catViewModel.parcatsViewModel.hoverinfoItems.indexOf('count') !== -1) {\n        hoverinfoParts.push(['Count:', labels.countLabel].join(' '));\n    }\n    if(catViewModel.parcatsViewModel.hoverinfoItems.indexOf('probability') !== -1) {\n        hoverinfoParts.push('P(color ∩ ' + catLabel + '): ' + labels.probabilityLabel);\n        hoverinfoParts.push('P(' + catLabel + ' | color): ' + pCatGivenColor.toFixed(3));\n        hoverinfoParts.push('P(color | ' + catLabel + '): ' + pColorGivenCat.toFixed(3));\n    }\n\n    var hovertext = hoverinfoParts.join('<br>');\n\n    // Compute text color\n    var textColor = tinycolor.mostReadable(bandViewModel.color, ['black', 'white']);\n\n    return {\n        trace: trace,\n        x: hoverCenterX - rootBBox.left,\n        y: hoverCenterY - rootBBox.top,\n        // name: 'NAME',\n        text: hovertext,\n        color: bandViewModel.color,\n        borderColor: 'black',\n        fontFamily: 'Monaco, \"Courier New\", monospace',\n        fontColor: textColor,\n        fontSize: 10,\n        idealAlign: hoverLabelIdealAlign,\n        hovertemplate: trace.hovertemplate,\n        hovertemplateLabels: labels,\n        eventData: [{\n            data: trace._input,\n            fullData: trace,\n            category: catLabel,\n            count: totalCount,\n            probability: pColorAndCat,\n            categorycount: catCount,\n            colorcount: colorCount,\n            bandcolorcount: bandColorCount\n        }]\n    };\n}\n\n/**\n * Handle dimension mouseover\n * @param {CategoryBandViewModel} bandViewModel\n */\nfunction mouseoverCategoryBand(bandViewModel) {\n    if(!bandViewModel.parcatsViewModel.dragDimension) {\n        // We're not currently dragging\n\n        if(bandViewModel.parcatsViewModel.hoverinfoItems.indexOf('skip') === -1) {\n            // hoverinfo is not skip, so we at least style the bands and emit interaction events\n\n            // Mouse\n            var mouseY = d3.mouse(this)[1];\n            if(mouseY < -1) {\n                // Hover is above above the category rectangle (probably the dimension title text)\n                return;\n            }\n\n            var gd = bandViewModel.parcatsViewModel.graphDiv;\n            var fullLayout = gd._fullLayout;\n            var rootBBox = fullLayout._paperdiv.node().getBoundingClientRect();\n            var hoveron = bandViewModel.parcatsViewModel.hoveron;\n\n            /** @type {HTMLElement} */\n            var bandElement = this;\n\n            // Handle style and events\n            if(hoveron === 'color') {\n                styleForColorHovermode(bandElement);\n                emitPointsEventColorHovermode(bandElement, 'plotly_hover', d3.event);\n            } else {\n                styleForCategoryHovermode(bandElement);\n                emitPointsEventCategoryHovermode(bandElement, 'plotly_hover', d3.event);\n            }\n\n            // Handle hover label\n            if(bandViewModel.parcatsViewModel.hoverinfoItems.indexOf('none') === -1) {\n                var hoverItems;\n                if(hoveron === 'category') {\n                    hoverItems = createHoverLabelForCategoryHovermode(rootBBox, bandElement);\n                } else if(hoveron === 'color') {\n                    hoverItems = createHoverLabelForColorHovermode(rootBBox, bandElement);\n                } else if(hoveron === 'dimension') {\n                    hoverItems = createHoverLabelForDimensionHovermode(rootBBox, bandElement);\n                }\n\n                if(hoverItems) {\n                    Fx.loneHover(hoverItems, {\n                        container: fullLayout._hoverlayer.node(),\n                        outerContainer: fullLayout._paper.node(),\n                        gd: gd\n                    });\n                }\n            }\n        }\n    }\n}\n\n\n/**\n * Handle dimension mouseover\n * @param {CategoryBandViewModel} bandViewModel\n */\nfunction mouseoutCategory(bandViewModel) {\n    var parcatsViewModel = bandViewModel.parcatsViewModel;\n\n    if(!parcatsViewModel.dragDimension) {\n        // We're not dragging anything\n\n        // Reset unhovered styles\n        stylePathsNoHover(parcatsViewModel.pathSelection);\n        styleCategoriesNoHover(parcatsViewModel.dimensionSelection.selectAll('g.category'));\n        styleBandsNoHover(parcatsViewModel.dimensionSelection.selectAll('g.category').selectAll('rect.bandrect'));\n\n        // Remove hover label\n        Fx.loneUnhover(parcatsViewModel.graphDiv._fullLayout._hoverlayer.node());\n\n        // Restore path order\n        parcatsViewModel.pathSelection.sort(compareRawColor);\n\n        // Emit unhover event\n        if(parcatsViewModel.hoverinfoItems.indexOf('skip') === -1) {\n            var hoveron = bandViewModel.parcatsViewModel.hoveron;\n            var bandElement = this;\n\n            // Handle style and events\n            if(hoveron === 'color') {\n                emitPointsEventColorHovermode(bandElement, 'plotly_unhover', d3.event);\n            } else {\n                emitPointsEventCategoryHovermode(bandElement, 'plotly_unhover', d3.event);\n            }\n        }\n    }\n}\n\n\n/**\n * Handle dimension drag start\n * @param {DimensionViewModel} d\n */\nfunction dragDimensionStart(d) {\n    // Check if dragging is supported\n    if(d.parcatsViewModel.arrangement === 'fixed') {\n        return;\n    }\n\n    // Save off initial drag indexes for dimension\n    d.dragDimensionDisplayInd = d.model.displayInd;\n    d.initialDragDimensionDisplayInds = d.parcatsViewModel.model.dimensions.map(function(d) {return d.displayInd;});\n    d.dragHasMoved = false;\n\n    // Check for category hit\n    d.dragCategoryDisplayInd = null;\n    d3.select(this)\n        .selectAll('g.category')\n        .select('rect.catrect')\n        .each(\n            /** @param {CategoryViewModel} catViewModel */\n            function(catViewModel) {\n                var catMouseX = d3.mouse(this)[0];\n                var catMouseY = d3.mouse(this)[1];\n\n\n                if(-2 <= catMouseX && catMouseX <= catViewModel.width + 2 &&\n                    -2 <= catMouseY && catMouseY <= catViewModel.height + 2) {\n                    // Save off initial drag indexes for categories\n                    d.dragCategoryDisplayInd = catViewModel.model.displayInd;\n                    d.initialDragCategoryDisplayInds = d.model.categories.map(function(c) {\n                        return c.displayInd;\n                    });\n\n                    // Initialize categories dragY to be the current y position\n                    catViewModel.model.dragY = catViewModel.y;\n\n                    // Raise category\n                    Lib.raiseToTop(this.parentNode);\n\n                    // Get band element\n                    d3.select(this.parentNode)\n                        .selectAll('rect.bandrect')\n                        /** @param {CategoryBandViewModel} bandViewModel */\n                        .each(function(bandViewModel) {\n                            if(bandViewModel.y < catMouseY && catMouseY <= bandViewModel.y + bandViewModel.height) {\n                                d.potentialClickBand = this;\n                            }\n                        });\n                }\n            });\n\n    // Update toplevel drag dimension\n    d.parcatsViewModel.dragDimension = d;\n\n    // Remove hover label if any\n    Fx.loneUnhover(d.parcatsViewModel.graphDiv._fullLayout._hoverlayer.node());\n}\n\n/**\n * Handle dimension drag\n * @param {DimensionViewModel} d\n */\nfunction dragDimension(d) {\n    // Check if dragging is supported\n    if(d.parcatsViewModel.arrangement === 'fixed') {\n        return;\n    }\n\n    d.dragHasMoved = true;\n\n    if(d.dragDimensionDisplayInd === null) {\n        return;\n    }\n\n    var dragDimInd = d.dragDimensionDisplayInd;\n    var prevDimInd = dragDimInd - 1;\n    var nextDimInd = dragDimInd + 1;\n\n    var dragDimension = d.parcatsViewModel\n        .dimensions[dragDimInd];\n\n    // Update category\n    if(d.dragCategoryDisplayInd !== null) {\n        var dragCategory = dragDimension.categories[d.dragCategoryDisplayInd];\n\n        // Update dragY by dy\n        dragCategory.model.dragY += d3.event.dy;\n        var categoryY = dragCategory.model.dragY;\n\n        // Check for category drag swaps\n        var catDisplayInd = dragCategory.model.displayInd;\n        var dimCategoryViews = dragDimension.categories;\n\n        var catAbove = dimCategoryViews[catDisplayInd - 1];\n        var catBelow = dimCategoryViews[catDisplayInd + 1];\n\n        // Check for overlap above\n        if(catAbove !== undefined) {\n            if(categoryY < (catAbove.y + catAbove.height / 2.0)) {\n                // Swap display inds\n                dragCategory.model.displayInd = catAbove.model.displayInd;\n                catAbove.model.displayInd = catDisplayInd;\n            }\n        }\n\n        if(catBelow !== undefined) {\n            if((categoryY + dragCategory.height) > (catBelow.y + catBelow.height / 2.0)) {\n                // Swap display inds\n                dragCategory.model.displayInd = catBelow.model.displayInd;\n                catBelow.model.displayInd = catDisplayInd;\n            }\n        }\n\n        // Update category drag display index\n        d.dragCategoryDisplayInd = dragCategory.model.displayInd;\n    }\n\n    // Update dimension position\n    if(d.dragCategoryDisplayInd === null || d.parcatsViewModel.arrangement === 'freeform') {\n        dragDimension.model.dragX = d3.event.x;\n\n        // Check for dimension swaps\n        var prevDimension = d.parcatsViewModel.dimensions[prevDimInd];\n        var nextDimension = d.parcatsViewModel.dimensions[nextDimInd];\n\n        if(prevDimension !== undefined) {\n            if(dragDimension.model.dragX < (prevDimension.x + prevDimension.width)) {\n                // Swap display inds\n                dragDimension.model.displayInd = prevDimension.model.displayInd;\n                prevDimension.model.displayInd = dragDimInd;\n            }\n        }\n\n        if(nextDimension !== undefined) {\n            if((dragDimension.model.dragX + dragDimension.width) > nextDimension.x) {\n                // Swap display inds\n                dragDimension.model.displayInd = nextDimension.model.displayInd;\n                nextDimension.model.displayInd = d.dragDimensionDisplayInd;\n            }\n        }\n\n        // Update drag display index\n        d.dragDimensionDisplayInd = dragDimension.model.displayInd;\n    }\n\n    // Update view models\n    updateDimensionViewModels(d.parcatsViewModel);\n    updatePathViewModels(d.parcatsViewModel);\n\n    // Update svg geometry\n    updateSvgCategories(d.parcatsViewModel);\n    updateSvgPaths(d.parcatsViewModel);\n}\n\n\n/**\n * Handle dimension drag end\n * @param {DimensionViewModel} d\n */\nfunction dragDimensionEnd(d) {\n    // Check if dragging is supported\n    if(d.parcatsViewModel.arrangement === 'fixed') {\n        return;\n    }\n\n    if(d.dragDimensionDisplayInd === null) {\n        return;\n    }\n\n    d3.select(this).selectAll('text').attr('font-weight', 'normal');\n\n    // Compute restyle command\n    // -----------------------\n    var restyleData = {};\n    var traceInd = getTraceIndex(d.parcatsViewModel);\n\n    // ### Handle dimension reordering ###\n    var finalDragDimensionDisplayInds = d.parcatsViewModel.model.dimensions.map(function(d) {return d.displayInd;});\n    var anyDimsReordered = d.initialDragDimensionDisplayInds.some(function(initDimDisplay, dimInd) {\n        return initDimDisplay !== finalDragDimensionDisplayInds[dimInd];\n    });\n\n    if(anyDimsReordered) {\n        finalDragDimensionDisplayInds.forEach(function(finalDimDisplay, dimInd) {\n            var containerInd = d.parcatsViewModel.model.dimensions[dimInd].containerInd;\n            restyleData['dimensions[' + containerInd + '].displayindex'] = finalDimDisplay;\n        });\n    }\n\n    // ### Handle category reordering ###\n    var anyCatsReordered = false;\n    if(d.dragCategoryDisplayInd !== null) {\n        var finalDragCategoryDisplayInds = d.model.categories.map(function(c) {\n            return c.displayInd;\n        });\n\n        anyCatsReordered = d.initialDragCategoryDisplayInds.some(function(initCatDisplay, catInd) {\n            return initCatDisplay !== finalDragCategoryDisplayInds[catInd];\n        });\n\n        if(anyCatsReordered) {\n            // Sort a shallow copy of the category models by display index\n            var sortedCategoryModels = d.model.categories.slice().sort(\n                function(a, b) { return a.displayInd - b.displayInd; });\n\n            // Get new categoryarray and ticktext values\n            var newCategoryArray = sortedCategoryModels.map(function(v) { return v.categoryValue; });\n            var newCategoryLabels = sortedCategoryModels.map(function(v) { return v.categoryLabel; });\n\n            restyleData['dimensions[' + d.model.containerInd + '].categoryarray'] = [newCategoryArray];\n            restyleData['dimensions[' + d.model.containerInd + '].ticktext'] = [newCategoryLabels];\n            restyleData['dimensions[' + d.model.containerInd + '].categoryorder'] = 'array';\n        }\n    }\n\n    // Handle potential click event\n    // ----------------------------\n    if(d.parcatsViewModel.hoverinfoItems.indexOf('skip') === -1) {\n        if(!d.dragHasMoved && d.potentialClickBand) {\n            if(d.parcatsViewModel.hoveron === 'color') {\n                emitPointsEventColorHovermode(d.potentialClickBand, 'plotly_click', d3.event.sourceEvent);\n            } else {\n                emitPointsEventCategoryHovermode(d.potentialClickBand, 'plotly_click', d3.event.sourceEvent);\n            }\n        }\n    }\n\n    // Nullify drag states\n    // -------------------\n    d.model.dragX = null;\n    if(d.dragCategoryDisplayInd !== null) {\n        var dragCategory = d.parcatsViewModel\n            .dimensions[d.dragDimensionDisplayInd]\n            .categories[d.dragCategoryDisplayInd];\n\n        dragCategory.model.dragY = null;\n        d.dragCategoryDisplayInd = null;\n    }\n\n    d.dragDimensionDisplayInd = null;\n    d.parcatsViewModel.dragDimension = null;\n    d.dragHasMoved = null;\n    d.potentialClickBand = null;\n\n    // Update view models\n    // ------------------\n    updateDimensionViewModels(d.parcatsViewModel);\n    updatePathViewModels(d.parcatsViewModel);\n\n    // Perform transition\n    // ------------------\n    var transition = d3.transition()\n        .duration(300)\n        .ease('cubic-in-out');\n\n    transition\n        .each(function() {\n            updateSvgCategories(d.parcatsViewModel, true);\n            updateSvgPaths(d.parcatsViewModel, true);\n        })\n        .each('end', function() {\n            if(anyDimsReordered || anyCatsReordered) {\n                // Perform restyle if the order of categories or dimensions changed\n                Plotly.restyle(d.parcatsViewModel.graphDiv, restyleData, [traceInd]);\n            }\n        });\n}\n\n/**\n *\n * @param {ParcatsViewModel} parcatsViewModel\n */\nfunction getTraceIndex(parcatsViewModel) {\n    var traceInd;\n    var allTraces = parcatsViewModel.graphDiv._fullData;\n    for(var i = 0; i < allTraces.length; i++) {\n        if(parcatsViewModel.key === allTraces[i].uid) {\n            traceInd = i;\n            break;\n        }\n    }\n    return traceInd;\n}\n\n/** Update the svg paths for view model\n * @param {ParcatsViewModel} parcatsViewModel\n * @param {boolean} hasTransition Whether to update element with transition\n */\nfunction updateSvgPaths(parcatsViewModel, hasTransition) {\n    if(hasTransition === undefined) {\n        hasTransition = false;\n    }\n\n    function transition(selection) {\n        return hasTransition ? selection.transition() : selection;\n    }\n\n    // Update binding\n    parcatsViewModel.pathSelection.data(function(d) {\n        return d.paths;\n    }, key);\n\n    // Update paths\n    transition(parcatsViewModel.pathSelection).attr('d', function(d) {\n        return d.svgD;\n    });\n}\n\n/** Update the svg paths for view model\n * @param {ParcatsViewModel} parcatsViewModel\n * @param {boolean} hasTransition Whether to update element with transition\n */\nfunction updateSvgCategories(parcatsViewModel, hasTransition) {\n    if(hasTransition === undefined) {\n        hasTransition = false;\n    }\n\n    function transition(selection) {\n        return hasTransition ? selection.transition() : selection;\n    }\n\n    // Update binding\n    parcatsViewModel.dimensionSelection\n        .data(function(d) {\n            return d.dimensions;\n        }, key);\n\n    var categorySelection = parcatsViewModel.dimensionSelection\n        .selectAll('g.category')\n        .data(function(d) {return d.categories;}, key);\n\n    // Update dimension position\n    transition(parcatsViewModel.dimensionSelection)\n        .attr('transform', function(d) {\n            return 'translate(' + d.x + ', 0)';\n        });\n\n    // Update category position\n    transition(categorySelection)\n        .attr('transform', function(d) {\n            return 'translate(0, ' + d.y + ')';\n        });\n\n    var dimLabelSelection = categorySelection.select('.dimlabel');\n\n    // ### Update dimension label\n    // Only the top-most display category should have the dimension label\n    dimLabelSelection\n        .text(function(d, i) {\n            if(i === 0) {\n                // Add dimension label above topmost category\n                return d.parcatsViewModel.model.dimensions[d.model.dimensionInd].dimensionLabel;\n            } else {\n                return null;\n            }\n        });\n\n    // Update category label\n    // Categories in the right-most display dimension have their labels on\n    // the right, all others on the left\n    var catLabelSelection = categorySelection.select('.catlabel');\n    catLabelSelection\n        .attr('text-anchor',\n            function(d) {\n                if(catInRightDim(d)) {\n                    // Place label to the right of category\n                    return 'start';\n                } else {\n                    // Place label to the left of category\n                    return 'end';\n                }\n            })\n        .attr('x',\n            function(d) {\n                if(catInRightDim(d)) {\n                    // Place label to the right of category\n                    return d.width + 5;\n                } else {\n                    // Place label to the left of category\n                    return -5;\n                }\n            })\n        .each(function(d) {\n            // Update attriubutes of <tspan> elements\n            var newX;\n            var newAnchor;\n            if(catInRightDim(d)) {\n                // Place label to the right of category\n                newX = d.width + 5;\n                newAnchor = 'start';\n            } else {\n                // Place label to the left of category\n                newX = -5;\n                newAnchor = 'end';\n            }\n            d3.select(this)\n                .selectAll('tspan')\n                .attr('x', newX)\n                .attr('text-anchor', newAnchor);\n        });\n\n    // Update bands\n    // Initialize color band rects\n    var bandSelection = categorySelection\n        .selectAll('rect.bandrect')\n        .data(\n            /** @param {CategoryViewModel} catViewModel*/\n            function(catViewModel) {\n                return catViewModel.bands;\n            }, key);\n\n    var bandsSelectionEnter = bandSelection.enter()\n        .append('rect')\n        .attr('class', 'bandrect')\n        .attr('cursor', 'move')\n        .attr('stroke-opacity', 0)\n        .attr('fill', function(d) {\n            return d.color;\n        })\n        .attr('fill-opacity', 0);\n\n    bandSelection\n        .attr('fill', function(d) {\n            return d.color;\n        })\n        .attr('width', function(d) {\n            return d.width;\n        })\n        .attr('height', function(d) {\n            return d.height;\n        })\n        .attr('y', function(d) {\n            return d.y;\n        });\n\n    styleBandsNoHover(bandsSelectionEnter);\n\n    // Raise bands to the top\n    bandSelection.each(function() {Lib.raiseToTop(this);});\n\n    // Remove unused bands\n    bandSelection.exit().remove();\n}\n\n/**\n * Create a ParcatsViewModel traces\n * @param {Object} graphDiv\n *  Top-level graph div element\n * @param {Layout} layout\n *  SVG layout object\n * @param {Array.<ParcatsModel>} wrappedParcatsModel\n *  Wrapped ParcatsModel for this trace\n * @return {ParcatsViewModel}\n */\nfunction createParcatsViewModel(graphDiv, layout, wrappedParcatsModel) {\n    // Unwrap model\n    var parcatsModel = wrappedParcatsModel[0];\n\n    // Compute margin\n    var margin = layout.margin || {l: 80, r: 80, t: 100, b: 80};\n\n    // Compute pixel position/extents\n    var trace = parcatsModel.trace;\n    var domain = trace.domain;\n    var figureWidth = layout.width;\n    var figureHeight = layout.height;\n    var traceWidth = Math.floor(figureWidth * (domain.x[1] - domain.x[0]));\n    var traceHeight = Math.floor(figureHeight * (domain.y[1] - domain.y[0]));\n    var traceX = domain.x[0] * figureWidth + margin.l;\n    var traceY = layout.height - domain.y[1] * layout.height + margin.t;\n\n    // Handle path shape\n    // -----------------\n    var pathShape = trace.line.shape;\n\n    // Handle hover info\n    // -----------------\n    var hoverinfoItems;\n    if(trace.hoverinfo === 'all') {\n        hoverinfoItems = ['count', 'probability'];\n    } else {\n        hoverinfoItems = (trace.hoverinfo || '').split('+');\n    }\n\n    // Construct parcatsViewModel\n    // --------------------------\n    var parcatsViewModel = {\n        trace: trace,\n        key: trace.uid,\n        model: parcatsModel,\n        x: traceX,\n        y: traceY,\n        width: traceWidth,\n        height: traceHeight,\n        hoveron: trace.hoveron,\n        hoverinfoItems: hoverinfoItems,\n        arrangement: trace.arrangement,\n        bundlecolors: trace.bundlecolors,\n        sortpaths: trace.sortpaths,\n        labelfont: trace.labelfont,\n        categorylabelfont: trace.tickfont,\n        pathShape: pathShape,\n        dragDimension: null,\n        margin: margin,\n        paths: [],\n        dimensions: [],\n        graphDiv: graphDiv,\n        traceSelection: null,\n        pathSelection: null,\n        dimensionSelection: null\n    };\n\n    // Update dimension view models if we have at least 1 dimension\n    if(parcatsModel.dimensions) {\n        updateDimensionViewModels(parcatsViewModel);\n\n        // Update path view models if we have at least 2 dimensions\n        updatePathViewModels(parcatsViewModel);\n    }\n    // Inside a categories view model\n    return parcatsViewModel;\n}\n\n/**\n * Build the SVG string to represents a parallel categories path\n * @param {Array.<Number>} leftXPositions\n *  Array of the x positions of the left edge of each dimension (in display order)\n * @param {Array.<Number>} pathYs\n *  Array of the y positions of the top of the path at each dimension (in display order)\n * @param {Array.<Number>} dimWidths\n *  Array of the widths of each dimension in display order\n * @param {Number} pathHeight\n *  The height of the path in pixels\n * @param {Number} curvature\n *  The curvature factor for the path. 0 results in a straight line and values greater than zero result in curved paths\n * @return {string}\n */\nfunction buildSvgPath(leftXPositions, pathYs, dimWidths, pathHeight, curvature) {\n    // Compute the x midpoint of each path segment\n    var xRefPoints1 = [];\n    var xRefPoints2 = [];\n    var refInterpolator;\n    var d;\n\n    for(d = 0; d < dimWidths.length - 1; d++) {\n        refInterpolator = d3.interpolateNumber(dimWidths[d] + leftXPositions[d], leftXPositions[d + 1]);\n        xRefPoints1.push(refInterpolator(curvature));\n        xRefPoints2.push(refInterpolator(1 - curvature));\n    }\n\n    // Move to top of path on left edge of left-most category\n    var svgD = 'M ' + leftXPositions[0] + ',' + pathYs[0];\n\n    // Horizontal line to right edge\n    svgD += 'l' + dimWidths[0] + ',0 ';\n\n    // Horizontal line to right edge\n    for(d = 1; d < dimWidths.length; d++) {\n        // Curve to left edge of category\n        svgD += 'C' + xRefPoints1[d - 1] + ',' + pathYs[d - 1] +\n              ' ' + xRefPoints2[d - 1] + ',' + pathYs[d] +\n              ' ' + leftXPositions[d] + ',' + pathYs[d];\n\n        // svgD += 'L' + leftXPositions[d] + ',' + pathYs[d];\n\n        // Horizontal line to right edge\n        svgD += 'l' + dimWidths[d] + ',0 ';\n    }\n\n    // Line down\n    svgD += 'l' + '0,' + pathHeight + ' ';\n\n    // Line to left edge of right-most category\n    svgD += 'l -' + dimWidths[dimWidths.length - 1] + ',0 ';\n\n    for(d = dimWidths.length - 2; d >= 0; d--) {\n        // Curve to right edge of category\n        svgD += 'C' + xRefPoints2[d] + ',' + (pathYs[d + 1] + pathHeight) +\n             ' ' + xRefPoints1[d] + ',' + (pathYs[d] + pathHeight) +\n             ' ' + (leftXPositions[d] + dimWidths[d]) + ',' + (pathYs[d] + pathHeight);\n\n        // svgD += 'L' + (leftXPositions[d] + dimWidths[d]) + ',' + (pathYs[d] + pathHeight);\n\n        // Horizontal line to right edge\n        svgD += 'l-' + dimWidths[d] + ',0 ';\n    }\n\n    // Close path\n    svgD += 'Z';\n    return svgD;\n}\n\n/**\n * Update the path view models based on the dimension view models in a ParcatsViewModel\n *\n * @param {ParcatsViewModel} parcatsViewModel\n *  View model for trace\n */\nfunction updatePathViewModels(parcatsViewModel) {\n    // Initialize an array of the y position of the top of the next path to be added to each category.\n    //\n    // nextYPositions[d][c] is the y position of the next path through category with index c of dimension with index d\n    var dimensionViewModels = parcatsViewModel.dimensions;\n    var parcatsModel = parcatsViewModel.model;\n    var nextYPositions = dimensionViewModels.map(\n        function(d) {\n            return d.categories.map(\n                function(c) {\n                    return c.y;\n                });\n        });\n\n    // Array from category index to category display index for each true dimension index\n    var catToDisplayIndPerDim = parcatsViewModel.model.dimensions.map(\n        function(d) {\n            return d.categories.map(function(c) {return c.displayInd;});\n        });\n\n    // Array from true dimension index to dimension display index\n    var dimToDisplayInd = parcatsViewModel.model.dimensions.map(function(d) {return d.displayInd;});\n    var displayToDimInd = parcatsViewModel.dimensions.map(function(d) {return d.model.dimensionInd;});\n\n    // Array of the x position of the left edge of the rectangles for each dimension\n    var leftXPositions = dimensionViewModels.map(\n        function(d) {\n            return d.x;\n        });\n\n    // Compute dimension widths\n    var dimWidths = dimensionViewModels.map(function(d) {return d.width;});\n\n    // Build sorted Array of PathModel objects\n    var pathModels = [];\n    for(var p in parcatsModel.paths) {\n        if(parcatsModel.paths.hasOwnProperty(p)) {\n            pathModels.push(parcatsModel.paths[p]);\n        }\n    }\n\n    // Compute category display inds to use for sorting paths\n    function pathDisplayCategoryInds(pathModel) {\n        var dimensionInds = pathModel.categoryInds.map(function(catInd, dimInd) {return catToDisplayIndPerDim[dimInd][catInd];});\n        var displayInds = displayToDimInd.map(function(dimInd) {\n            return dimensionInds[dimInd];\n        });\n        return displayInds;\n    }\n\n    // Sort in ascending order by display index array\n    pathModels.sort(function(v1, v2) {\n        // Build display inds for each path\n        var sortArray1 = pathDisplayCategoryInds(v1);\n        var sortArray2 = pathDisplayCategoryInds(v2);\n\n        // Handle path sort order\n        if(parcatsViewModel.sortpaths === 'backward') {\n            sortArray1.reverse();\n            sortArray2.reverse();\n        }\n\n        // Append the first value index of the path to break ties\n        sortArray1.push(v1.valueInds[0]);\n        sortArray2.push(v2.valueInds[0]);\n\n        // Handle color bundling\n        if(parcatsViewModel.bundlecolors) {\n            // Prepend sort array with the raw color value\n            sortArray1.unshift(v1.rawColor);\n            sortArray2.unshift(v2.rawColor);\n        }\n\n        // colors equal, sort by display categories\n        if(sortArray1 < sortArray2) {\n            return -1;\n        }\n        if(sortArray1 > sortArray2) {\n            return 1;\n        }\n\n        return 0;\n    });\n\n    // Create path models\n    var pathViewModels = new Array(pathModels.length);\n    var totalCount = dimensionViewModels[0].model.count;\n    var totalHeight = dimensionViewModels[0].categories\n        .map(function(c) { return c.height; })\n        .reduce(function(v1, v2) { return v1 + v2; });\n\n\n    for(var pathNumber = 0; pathNumber < pathModels.length; pathNumber++) {\n        var pathModel = pathModels[pathNumber];\n\n        var pathHeight;\n        if(totalCount > 0) {\n            pathHeight = totalHeight * (pathModel.count / totalCount);\n        } else {\n            pathHeight = 0;\n        }\n\n        // Build path y coords\n        var pathYs = new Array(nextYPositions.length);\n        for(var d = 0; d < pathModel.categoryInds.length; d++) {\n            var catInd = pathModel.categoryInds[d];\n            var catDisplayInd = catToDisplayIndPerDim[d][catInd];\n            var dimDisplayInd = dimToDisplayInd[d];\n\n            // Update next y position\n            pathYs[dimDisplayInd] = nextYPositions[dimDisplayInd][catDisplayInd];\n            nextYPositions[dimDisplayInd][catDisplayInd] += pathHeight;\n\n            // Update category color information\n            var catViewModle = parcatsViewModel.dimensions[dimDisplayInd].categories[catDisplayInd];\n            var numBands = catViewModle.bands.length;\n            var lastCatBand = catViewModle.bands[numBands - 1];\n\n            if(lastCatBand === undefined || pathModel.rawColor !== lastCatBand.rawColor) {\n                // Create a new band\n                var bandY = lastCatBand === undefined ? 0 : lastCatBand.y + lastCatBand.height;\n                catViewModle.bands.push({\n                    key: bandY,\n                    color: pathModel.color,\n                    rawColor: pathModel.rawColor,\n                    height: pathHeight,\n                    width: catViewModle.width,\n                    count: pathModel.count,\n                    y: bandY,\n                    categoryViewModel: catViewModle,\n                    parcatsViewModel: parcatsViewModel\n                });\n            } else {\n                // Extend current band\n                var currentBand = catViewModle.bands[numBands - 1];\n                currentBand.height += pathHeight;\n                currentBand.count += pathModel.count;\n            }\n        }\n\n        // build svg path\n        var svgD;\n        if(parcatsViewModel.pathShape === 'hspline') {\n            svgD = buildSvgPath(leftXPositions, pathYs, dimWidths, pathHeight, 0.5);\n        } else {\n            svgD = buildSvgPath(leftXPositions, pathYs, dimWidths, pathHeight, 0);\n        }\n\n        pathViewModels[pathNumber] = {\n            key: pathModel.valueInds[0],\n            model: pathModel,\n            height: pathHeight,\n            leftXs: leftXPositions,\n            topYs: pathYs,\n            dimWidths: dimWidths,\n            svgD: svgD,\n            parcatsViewModel: parcatsViewModel\n        };\n    }\n\n    parcatsViewModel.paths = pathViewModels;\n\n // * @property key\n // *  Unique key for this model\n // * @property {PathModel} model\n // *  Source path model\n // * @property {Number} height\n // *  Height of this path (pixels)\n // * @property {String} svgD\n // *  SVG path \"d\" attribute string\n}\n\n/**\n * Update the dimension view models based on the dimension models in a ParcatsViewModel\n *\n * @param {ParcatsViewModel} parcatsViewModel\n *  View model for trace\n */\nfunction updateDimensionViewModels(parcatsViewModel) {\n    // Compute dimension ordering\n    var dimensionsIndInfo = parcatsViewModel.model.dimensions.map(function(d) {\n        return {displayInd: d.displayInd, dimensionInd: d.dimensionInd};\n    });\n\n    dimensionsIndInfo.sort(function(a, b) {\n        return a.displayInd - b.displayInd;\n    });\n\n    var dimensions = [];\n    for(var displayInd in dimensionsIndInfo) {\n        var dimensionInd = dimensionsIndInfo[displayInd].dimensionInd;\n        var dimModel = parcatsViewModel.model.dimensions[dimensionInd];\n        dimensions.push(createDimensionViewModel(parcatsViewModel, dimModel));\n    }\n\n    parcatsViewModel.dimensions = dimensions;\n}\n\n/**\n * Create a parcats DimensionViewModel\n *\n * @param {ParcatsViewModel} parcatsViewModel\n *  View model for trace\n * @param {DimensionModel} dimensionModel\n * @return {DimensionViewModel}\n */\nfunction createDimensionViewModel(parcatsViewModel, dimensionModel) {\n    // Compute dimension x position\n    var categoryLabelPad = 40;\n    var dimWidth = 16;\n    var numDimensions = parcatsViewModel.model.dimensions.length;\n    var displayInd = dimensionModel.displayInd;\n\n    // Compute x coordinate values\n    var dimDx;\n    var dimX0;\n    var dimX;\n\n    if(numDimensions > 1) {\n        dimDx = (parcatsViewModel.width - 2 * categoryLabelPad - dimWidth) / (numDimensions - 1);\n    } else {\n        dimDx = 0;\n    }\n    dimX0 = categoryLabelPad;\n    dimX = dimX0 + dimDx * displayInd;\n\n    // Compute categories\n    var categories = [];\n    var maxCats = parcatsViewModel.model.maxCats;\n    var numCats = dimensionModel.categories.length;\n    var catSpacing = 8;\n    var totalCount = dimensionModel.count;\n    var totalHeight = parcatsViewModel.height - catSpacing * (maxCats - 1);\n    var nextCatHeight;\n    var nextCatModel;\n    var nextCat;\n    var catInd;\n    var catDisplayInd;\n\n    // Compute starting Y offset\n    var nextCatY = (maxCats - numCats) * catSpacing / 2.0;\n\n    // Compute category ordering\n    var categoryIndInfo = dimensionModel.categories.map(function(c) {\n        return {displayInd: c.displayInd, categoryInd: c.categoryInd};\n    });\n\n    categoryIndInfo.sort(function(a, b) {\n        return a.displayInd - b.displayInd;\n    });\n\n    for(catDisplayInd = 0; catDisplayInd < numCats; catDisplayInd++) {\n        catInd = categoryIndInfo[catDisplayInd].categoryInd;\n        nextCatModel = dimensionModel.categories[catInd];\n\n        if(totalCount > 0) {\n            nextCatHeight = (nextCatModel.count / totalCount) * totalHeight;\n        } else {\n            nextCatHeight = 0;\n        }\n\n        nextCat = {\n            key: nextCatModel.valueInds[0],\n            model: nextCatModel,\n            width: dimWidth,\n            height: nextCatHeight,\n            y: nextCatModel.dragY !== null ? nextCatModel.dragY : nextCatY,\n            bands: [],\n            parcatsViewModel: parcatsViewModel\n        };\n\n        nextCatY = nextCatY + nextCatHeight + catSpacing;\n        categories.push(nextCat);\n    }\n\n    return {\n        key: dimensionModel.dimensionInd,\n        x: dimensionModel.dragX !== null ? dimensionModel.dragX : dimX,\n        y: 0,\n        width: dimWidth,\n        model: dimensionModel,\n        categories: categories,\n        parcatsViewModel: parcatsViewModel,\n        dragCategoryDisplayInd: null,\n        dragDimensionDisplayInd: null,\n        initialDragDimensionDisplayInds: null,\n        initialDragCategoryDisplayInds: null,\n        dragHasMoved: null,\n        potentialClickBand: null\n    };\n}\n\n// JSDoc typedefs\n// ==============\n/**\n * @typedef {Object} Layout\n *  Object containing svg layout information\n *\n * @property {Number} width (pixels)\n *  Usable width for Figure (after margins are removed)\n * @property {Number} height (pixels)\n *  Usable height for Figure (after margins are removed)\n * @property {Margin} margin\n *  Margin around the Figure (pixels)\n */\n\n/**\n * @typedef {Object} Margin\n *  Object containing padding information in pixels\n *\n * @property {Number} t\n *  Top margin\n * @property {Number} r\n *  Right margin\n * @property {Number} b\n *  Bottom margin\n * @property {Number} l\n *  Left margin\n */\n\n/**\n * @typedef {Object} Font\n *  Object containing font information\n *\n * @property {Number} size: Font size\n * @property {String} color: Font color\n * @property {String} family: Font family\n */\n\n/**\n * @typedef {Object} ParcatsViewModel\n *  Object containing calculated parcats view information\n *\n *  These are quantities that require Layout information to calculate\n * @property key\n *  Unique key for this model\n * @property {ParcatsModel} model\n *  Source parcats model\n * @property {Array.<DimensionViewModel>} dimensions\n *  Array of dimension view models\n * @property {Number} width\n *  Width for this trace (pixels)\n * @property {Number} height\n *  Height for this trace (pixels)\n * @property {Number} x\n *  X position of this trace with respect to the Figure (pixels)\n * @property {Number} y\n *  Y position of this trace with respect to the Figure (pixels)\n * @property {String} hoveron\n *  Hover interaction mode. One of: 'category', 'color', or 'dimension'\n * @property {Array.<String>} hoverinfoItems\n *  Info to display on hover. Array with a combination of 'counts' and/or 'probabilities', or 'none', or 'skip'\n * @property {String} arrangement\n *  Category arrangement. One of: 'perpendicular', 'freeform', or 'fixed'\n * @property {Boolean} bundlecolors\n *  Whether paths should be sorted so that like colors are bundled together as they pass through categories\n * @property {String} sortpaths\n *  If 'forward' then sort paths based on dimensions from left to right. If 'backward' sort based on dimensions\n *  from right to left\n * @property {Font} labelfont\n *  Font for the dimension labels\n * @property {Font} categorylabelfont\n *  Font for the category labels\n * @property {String} pathShape\n *  The shape of the paths. Either 'linear' or 'hspline'.\n * @property {DimensionViewModel|null} dragDimension\n *  Dimension currently being dragged. Null if no drag in progress\n * @property {Margin} margin\n *  Margin around the Figure\n * @property {Object} graphDiv\n *  Top-level graph div element\n * @property {Object} traceSelection\n *  D3 selection of this view models trace group element\n * @property {Object} pathSelection\n *  D3 selection of this view models path elements\n * @property {Object} dimensionSelection\n *  D3 selection of this view models dimension group element\n */\n\n/**\n * @typedef {Object} DimensionViewModel\n *  Object containing calculated parcats dimension view information\n *\n *  These are quantities that require Layout information to calculate\n * @property key\n *  Unique key for this model\n * @property {DimensionModel} model\n *  Source dimension model\n * @property {Number} x\n *  X position of the center of this dimension with respect to the Figure (pixels)\n * @property {Number} y\n *  Y position of the top of this dimension with respect to the Figure (pixels)\n * @property {Number} width\n *  Width of categories in this dimension (pixels)\n * @property {ParcatsViewModel} parcatsViewModel\n *  The parent trace's view model\n * @property {Array.<CategoryViewModel>} categories\n *  Dimensions category view models\n * @property {Number|null} dragCategoryDisplayInd\n *  Display index of category currently being dragged. null if no category is being dragged\n * @property {Number|null} dragDimensionDisplayInd\n *  Display index of the dimension being dragged. null if no dimension is being dragged\n * @property {Array.<Number>|null} initialDragDimensionDisplayInds\n *  Dimensions display indexes at the beginning of the current drag. null if no dimension is being dragged\n * @property {Array.<Number>|null} initialDragCategoryDisplayInds\n *  Category display indexes for the at the beginning of the current drag. null if no category is being dragged\n * @property {HTMLElement} potentialClickBand\n *  Band under mouse when current drag began. If no drag movement takes place then a click will be emitted for this\n *  band. Null if not drag in progress.\n * @property {Boolean} dragHasMoved\n *  True if there is an active drag and the drag has moved. If drag doesn't move before being ended then\n *  this may be interpreted as a click. Null if no drag in progress\n */\n\n/**\n * @typedef {Object} CategoryViewModel\n *  Object containing calculated parcats category view information\n *\n *  These are quantities that require Layout information to calculate\n * @property key\n *  Unique key for this model\n * @property {CategoryModel} model\n *  Source category model\n * @property {Number} width\n *  Width for this category (pixels)\n * @property {Number} height\n *  Height for this category (pixels)\n * @property {Number} y\n *  Y position of this cateogry with respect to the Figure (pixels)\n * @property {Array.<CategoryBandViewModel>} bands\n *  Array of color bands inside the category\n * @property {ParcatsViewModel} parcatsViewModel\n *  The parent trace's view model\n */\n\n/**\n * @typedef {Object} CategoryBandViewModel\n *  Object containing calculated category band information. A category band is a region inside a category covering\n *  paths of a single color\n *\n * @property key\n *  Unique key for this model\n * @property color\n *  Band color\n * @property rawColor\n *  Raw color value for band\n * @property {Number} width\n *  Band width\n * @property {Number} height\n *  Band height\n * @property {Number} y\n *  Y position of top of the band with respect to the category\n * @property {Number} count\n *  The number of samples represented by the band\n * @property {CategoryViewModel} categoryViewModel\n *  The parent categorie's view model\n * @property {ParcatsViewModel} parcatsViewModel\n *  The parent trace's view model\n */\n\n/**\n * @typedef {Object} PathViewModel\n *  Object containing calculated parcats path view information\n *\n *  These are quantities that require Layout information to calculate\n * @property key\n *  Unique key for this model\n * @property {PathModel} model\n *  Source path model\n * @property {Number} height\n *  Height of this path (pixels)\n * @property {Array.<Number>} leftXs\n *  The x position of the left edge of each display dimension\n * @property {Array.<Number>} topYs\n *  The y position of the top of the path for each display dimension\n * @property {Array.<Number>} dimWidths\n *  The width of each display dimension\n * @property {String} svgD\n *  SVG path \"d\" attribute string\n * @property {ParcatsViewModel} parcatsViewModel\n *  The parent trace's view model\n */\n\n},{\"../../components/drawing\":614,\"../../components/fx\":632,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"../../plot_api/plot_api\":754,\"d3\":163,\"tinycolor2\":537}],1073:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nvar parcats = _dereq_('./parcats');\n\n/**\n * Create / update parcat traces\n *\n * @param {Object} graphDiv\n * @param {Array.<ParcatsModel>} parcatsModels\n */\nmodule.exports = function plot(graphDiv, parcatsModels, transitionOpts, makeOnCompleteCallback) {\n    var fullLayout = graphDiv._fullLayout;\n    var svg = fullLayout._paper;\n    var size = fullLayout._size;\n\n    parcats(\n        graphDiv,\n        svg,\n        parcatsModels,\n        {\n            width: size.w,\n            height: size.h,\n            margin: {\n                t: size.t,\n                r: size.r,\n                b: size.b,\n                l: size.l\n            }\n        },\n        transitionOpts,\n        makeOnCompleteCallback\n    );\n};\n\n},{\"./parcats\":1072}],1074:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar axesAttrs = _dereq_('../../plots/cartesian/layout_attributes');\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\nmodule.exports = {\n    domain: domainAttrs({name: 'parcoords', trace: true, editType: 'plot'}),\n\n    labelangle: {\n        valType: 'angle',\n        dflt: 0,\n        \n        editType: 'plot',\n        \n    },\n\n    labelside: {\n        valType: 'enumerated',\n        \n        values: ['top', 'bottom'],\n        dflt: 'top',\n        editType: 'plot',\n        \n    },\n\n    labelfont: fontAttrs({\n        editType: 'plot',\n        \n    }),\n    tickfont: fontAttrs({\n        editType: 'plot',\n        \n    }),\n    rangefont: fontAttrs({\n        editType: 'plot',\n        \n    }),\n\n    dimensions: templatedArray('dimension', {\n        label: {\n            valType: 'string',\n            \n            editType: 'plot',\n            \n        },\n        // TODO: better way to determine ordinal vs continuous axes,\n        // so users can use tickvals/ticktext with a continuous axis.\n        tickvals: extendFlat({}, axesAttrs.tickvals, {\n            editType: 'plot',\n            \n        }),\n        ticktext: extendFlat({}, axesAttrs.ticktext, {\n            editType: 'plot',\n            \n        }),\n        tickformat: extendFlat({}, axesAttrs.tickformat, {\n            editType: 'plot'\n        }),\n        visible: {\n            valType: 'boolean',\n            dflt: true,\n            \n            editType: 'plot',\n            \n        },\n        range: {\n            valType: 'info_array',\n            \n            items: [\n                {valType: 'number', editType: 'plot'},\n                {valType: 'number', editType: 'plot'}\n            ],\n            editType: 'plot',\n            \n        },\n        constraintrange: {\n            valType: 'info_array',\n            \n            freeLength: true,\n            dimensions: '1-2',\n            items: [\n                {valType: 'number', editType: 'plot'},\n                {valType: 'number', editType: 'plot'}\n            ],\n            editType: 'plot',\n            \n        },\n        multiselect: {\n            valType: 'boolean',\n            dflt: true,\n            \n            editType: 'plot',\n            \n        },\n        values: {\n            valType: 'data_array',\n            \n            editType: 'calc',\n            \n        },\n        editType: 'calc',\n        \n    }),\n\n    line: extendFlat({editType: 'calc'},\n        colorScaleAttrs('line', {\n            // the default autocolorscale isn't quite usable for parcoords due to context ambiguity around 0 (grey, off-white)\n            // autocolorscale therefore defaults to false too, to avoid being overridden by the blue-white-red autocolor palette\n            colorscaleDflt: 'Viridis',\n            autoColorDflt: false,\n            editTypeOverride: 'calc'\n        })\n    )\n};\n\n},{\"../../components/colorscale/attributes\":600,\"../../lib/extend\":710,\"../../plot_api/plot_template\":757,\"../../plots/cartesian/layout_attributes\":779,\"../../plots/domain\":792,\"../../plots/font_attributes\":793}],1075:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar c = _dereq_('./constants');\nvar d3 = _dereq_('d3');\nvar keyFun = _dereq_('../../lib/gup').keyFun;\nvar repeat = _dereq_('../../lib/gup').repeat;\nvar sortAsc = _dereq_('../../lib').sorterAsc;\n\nvar snapRatio = c.bar.snapRatio;\nfunction snapOvershoot(v, vAdjacent) { return v * (1 - snapRatio) + vAdjacent * snapRatio; }\n\nvar snapClose = c.bar.snapClose;\nfunction closeToCovering(v, vAdjacent) { return v * (1 - snapClose) + vAdjacent * snapClose; }\n\n// snap for the low end of a range on an ordinal scale\n// on an ordinal scale, always show some overshoot from the exact value,\n// so it's clear we're covering it\n// find the interval we're in, and snap to 1/4 the distance to the next\n// these two could be unified at a slight loss of readability / perf\nfunction ordinalScaleSnap(isHigh, a, v, existingRanges) {\n    if(overlappingExisting(v, existingRanges)) return v;\n\n    var dir = isHigh ? -1 : 1;\n\n    var first = 0;\n    var last = a.length - 1;\n    if(dir < 0) {\n        var tmp = first;\n        first = last;\n        last = tmp;\n    }\n\n    var aHere = a[first];\n    var aPrev = aHere;\n    for(var i = first; dir * i < dir * last; i += dir) {\n        var nextI = i + dir;\n        var aNext = a[nextI];\n\n        // very close to the previous - snap down to it\n        if(dir * v < dir * closeToCovering(aHere, aNext)) return snapOvershoot(aHere, aPrev);\n        if(dir * v < dir * aNext || nextI === last) return snapOvershoot(aNext, aHere);\n\n        aPrev = aHere;\n        aHere = aNext;\n    }\n}\n\nfunction overlappingExisting(v, existingRanges) {\n    for(var i = 0; i < existingRanges.length; i++) {\n        if(v >= existingRanges[i][0] && v <= existingRanges[i][1]) return true;\n    }\n    return false;\n}\n\nfunction barHorizontalSetup(selection) {\n    selection\n        .attr('x', -c.bar.captureWidth / 2)\n        .attr('width', c.bar.captureWidth);\n}\n\nfunction backgroundBarHorizontalSetup(selection) {\n    selection\n        .attr('visibility', 'visible')\n        .style('visibility', 'visible')\n        .attr('fill', 'yellow')\n        .attr('opacity', 0);\n}\n\nfunction setHighlight(d) {\n    if(!d.brush.filterSpecified) {\n        return '0,' + d.height;\n    }\n    var pixelRanges = unitToPx(d.brush.filter.getConsolidated(), d.height);\n    var dashArray = [0]; // we start with a 0 length selection as filter ranges are inclusive, not exclusive\n    var p, sectionHeight, iNext;\n    var currentGap = pixelRanges.length ? pixelRanges[0][0] : null;\n    for(var i = 0; i < pixelRanges.length; i++) {\n        p = pixelRanges[i];\n        sectionHeight = p[1] - p[0];\n        dashArray.push(currentGap);\n        dashArray.push(sectionHeight);\n        iNext = i + 1;\n        if(iNext < pixelRanges.length) {\n            currentGap = pixelRanges[iNext][0] - p[1];\n        }\n    }\n    dashArray.push(d.height);\n    // d.height is added at the end to ensure that (1) we have an even number of dasharray points, MDN page says\n    // \"If an odd number of values is provided, then the list of values is repeated to yield an even number of values.\"\n    // and (2) it's _at least_ as long as the full height (even if range is minuscule and at the bottom) though this\n    // may not be necessary, maybe duplicating the last point would do too. But no harm in a longer dasharray than line.\n    return dashArray;\n}\n\nfunction unitToPx(unitRanges, height) {\n    return unitRanges.map(function(pr) {\n        return pr.map(function(v) { return v * height; }).sort(sortAsc);\n    });\n}\n\n// is the cursor over the north, middle, or south of a bar?\n// the end handles extend over the last 10% of the bar\nfunction getRegion(fPix, y) {\n    var pad = c.bar.handleHeight;\n    if(y > fPix[1] + pad || y < fPix[0] - pad) return;\n    if(y >= 0.9 * fPix[1] + 0.1 * fPix[0]) return 'n';\n    if(y <= 0.9 * fPix[0] + 0.1 * fPix[1]) return 's';\n    return 'ns';\n}\n\nfunction clearCursor() {\n    d3.select(document.body)\n        .style('cursor', null);\n}\n\nfunction styleHighlight(selection) {\n    // stroke-dasharray is used to minimize the number of created DOM nodes, because the requirement calls for up to\n    // 1000 individual selections on an axis, and there can be 60 axes per parcoords, and multiple parcoords per\n    // dashboard. The technique is similar to https://codepen.io/monfera/pen/rLYqWR and using a `polyline` with\n    // multiple sections, or a `path` element via its `d` attribute would also be DOM-sparing alternatives.\n    selection.attr('stroke-dasharray', setHighlight);\n}\n\nfunction renderHighlight(root, tweenCallback) {\n    var bar = d3.select(root).selectAll('.highlight, .highlight-shadow');\n    var barToStyle = tweenCallback ? bar.transition().duration(c.bar.snapDuration).each('end', tweenCallback) : bar;\n    styleHighlight(barToStyle);\n}\n\nfunction getInterval(d, y) {\n    var b = d.brush;\n    var active = b.filterSpecified;\n    var closestInterval = NaN;\n    var out = {};\n    var i;\n\n    if(active) {\n        var height = d.height;\n        var intervals = b.filter.getConsolidated();\n        var pixIntervals = unitToPx(intervals, height);\n        var hoveredInterval = NaN;\n        var previousInterval = NaN;\n        var nextInterval = NaN;\n        for(i = 0; i <= pixIntervals.length; i++) {\n            var p = pixIntervals[i];\n            if(p && p[0] <= y && y <= p[1]) {\n                // over a bar\n                hoveredInterval = i;\n                break;\n            } else {\n                // between bars, or before/after the first/last bar\n                previousInterval = i ? i - 1 : NaN;\n                if(p && p[0] > y) {\n                    nextInterval = i;\n                    break; // no point continuing as intervals are non-overlapping and sorted; could use log search\n                }\n            }\n        }\n\n        closestInterval = hoveredInterval;\n        if(isNaN(closestInterval)) {\n            if(isNaN(previousInterval) || isNaN(nextInterval)) {\n                closestInterval = isNaN(previousInterval) ? nextInterval : previousInterval;\n            } else {\n                closestInterval = (y - pixIntervals[previousInterval][1] < pixIntervals[nextInterval][0] - y) ?\n                    previousInterval : nextInterval;\n            }\n        }\n\n        if(!isNaN(closestInterval)) {\n            var fPix = pixIntervals[closestInterval];\n            var region = getRegion(fPix, y);\n\n            if(region) {\n                out.interval = intervals[closestInterval];\n                out.intervalPix = fPix;\n                out.region = region;\n            }\n        }\n    }\n\n    if(d.ordinal && !out.region) {\n        var a = d.unitTickvals;\n        var unitLocation = d.unitToPaddedPx.invert(y);\n        for(i = 0; i < a.length; i++) {\n            var rangei = [\n                a[Math.max(i - 1, 0)] * 0.25 + a[i] * 0.75,\n                a[Math.min(i + 1, a.length - 1)] * 0.25 + a[i] * 0.75\n            ];\n            if(unitLocation >= rangei[0] && unitLocation <= rangei[1]) {\n                out.clickableOrdinalRange = rangei;\n                break;\n            }\n        }\n    }\n\n    return out;\n}\n\nfunction attachDragBehavior(selection) {\n    // There's some fiddling with pointer cursor styling so that the cursor preserves its shape while dragging a brush\n    // even if the cursor strays from the interacting bar, which is bound to happen as bars are thin and the user\n    // will inevitably leave the hotspot strip. In this regard, it does something similar to what the D3 brush would do.\n    selection\n        .on('mousemove', function(d) {\n            d3.event.preventDefault();\n            if(!d.parent.inBrushDrag) {\n                var y = d.height - d3.mouse(this)[1] - 2 * c.verticalPadding;\n                var interval = getInterval(d, y);\n\n                var cursor = 'crosshair';\n                if(interval.clickableOrdinalRange) cursor = 'pointer';\n                else if(interval.region) cursor = interval.region + '-resize';\n                d3.select(document.body)\n                    .style('cursor', cursor);\n            }\n        })\n        .on('mouseleave', function(d) {\n            if(!d.parent.inBrushDrag) clearCursor();\n        })\n        .call(d3.behavior.drag()\n            .on('dragstart', function(d) {\n                d3.event.sourceEvent.stopPropagation();\n                var y = d.height - d3.mouse(this)[1] - 2 * c.verticalPadding;\n                var unitLocation = d.unitToPaddedPx.invert(y);\n                var b = d.brush;\n                var interval = getInterval(d, y);\n                var unitRange = interval.interval;\n                var s = b.svgBrush;\n                s.wasDragged = false; // we start assuming there won't be a drag - useful for reset\n                s.grabbingBar = interval.region === 'ns';\n                if(s.grabbingBar) {\n                    var pixelRange = unitRange.map(d.unitToPaddedPx);\n                    s.grabPoint = y - pixelRange[0] - c.verticalPadding;\n                    s.barLength = pixelRange[1] - pixelRange[0];\n                }\n                s.clickableOrdinalRange = interval.clickableOrdinalRange;\n                s.stayingIntervals = (d.multiselect && b.filterSpecified) ? b.filter.getConsolidated() : [];\n                if(unitRange) {\n                    s.stayingIntervals = s.stayingIntervals.filter(function(int2) {\n                        return int2[0] !== unitRange[0] && int2[1] !== unitRange[1];\n                    });\n                }\n                s.startExtent = interval.region ? unitRange[interval.region === 's' ? 1 : 0] : unitLocation;\n                d.parent.inBrushDrag = true;\n                s.brushStartCallback();\n            })\n            .on('drag', function(d) {\n                d3.event.sourceEvent.stopPropagation();\n                var y = d.height - d3.mouse(this)[1] - 2 * c.verticalPadding;\n                var s = d.brush.svgBrush;\n                s.wasDragged = true;\n\n                if(s.grabbingBar) { // moving the bar\n                    s.newExtent = [y - s.grabPoint, y + s.barLength - s.grabPoint].map(d.unitToPaddedPx.invert);\n                } else { // south/north drag or new bar creation\n                    s.newExtent = [s.startExtent, d.unitToPaddedPx.invert(y)].sort(sortAsc);\n                }\n\n                // take care of the parcoords axis height constraint: bar can't breach it\n                var bottomViolation = Math.max(0, -s.newExtent[0]);\n                var topViolation = Math.max(0, s.newExtent[1] - 1);\n                s.newExtent[0] += bottomViolation;\n                s.newExtent[1] -= topViolation;\n                if(s.grabbingBar) {\n                    // in case of bar dragging (non-resizing interaction, unlike north/south resize or new bar creation)\n                    // the constraint adjustment must apply to the other end of the bar as well, otherwise it'd\n                    // shorten or lengthen\n                    s.newExtent[1] += bottomViolation;\n                    s.newExtent[0] -= topViolation;\n                }\n\n                d.brush.filterSpecified = true;\n                s.extent = s.stayingIntervals.concat([s.newExtent]);\n                s.brushCallback(d);\n                renderHighlight(this.parentNode);\n            })\n            .on('dragend', function(d) {\n                var e = d3.event;\n                e.sourceEvent.stopPropagation();\n                var brush = d.brush;\n                var filter = brush.filter;\n                var s = brush.svgBrush;\n                var grabbingBar = s.grabbingBar;\n                s.grabbingBar = false;\n                s.grabLocation = undefined;\n                d.parent.inBrushDrag = false;\n                clearCursor(); // instead of clearing, a nicer thing would be to set it according to current location\n                if(!s.wasDragged) { // a click+release on the same spot (ie. w/o dragging) means a bar or full reset\n                    s.wasDragged = undefined; // logic-wise unneeded, just shows `wasDragged` has no longer a meaning\n                    if(s.clickableOrdinalRange) {\n                        if(brush.filterSpecified && d.multiselect) {\n                            s.extent.push(s.clickableOrdinalRange);\n                        } else {\n                            s.extent = [s.clickableOrdinalRange];\n                            brush.filterSpecified = true;\n                        }\n                    } else if(grabbingBar) {\n                        s.extent = s.stayingIntervals;\n                        if(s.extent.length === 0) {\n                            brushClear(brush);\n                        }\n                    } else {\n                        brushClear(brush);\n                    }\n                    s.brushCallback(d);\n                    renderHighlight(this.parentNode);\n                    s.brushEndCallback(brush.filterSpecified ? filter.getConsolidated() : []);\n                    return; // no need to fuse intervals or snap to ordinals, so we can bail early\n                }\n\n                var mergeIntervals = function() {\n                    // Key piece of logic: once the button is released, possibly overlapping intervals will be fused:\n                    // Here it's done immediately on click release while on ordinal snap transition it's done at the end\n                    filter.set(filter.getConsolidated());\n                };\n\n                if(d.ordinal) {\n                    var a = d.unitTickvals;\n                    if(a[a.length - 1] < a[0]) a.reverse();\n                    s.newExtent = [\n                        ordinalScaleSnap(0, a, s.newExtent[0], s.stayingIntervals),\n                        ordinalScaleSnap(1, a, s.newExtent[1], s.stayingIntervals)\n                    ];\n                    var hasNewExtent = s.newExtent[1] > s.newExtent[0];\n                    s.extent = s.stayingIntervals.concat(hasNewExtent ? [s.newExtent] : []);\n                    if(!s.extent.length) {\n                        brushClear(brush);\n                    }\n                    s.brushCallback(d);\n                    if(hasNewExtent) {\n                        // merging intervals post the snap tween\n                        renderHighlight(this.parentNode, mergeIntervals);\n                    } else {\n                        // if no new interval, don't animate, just redraw the highlight immediately\n                        mergeIntervals();\n                        renderHighlight(this.parentNode);\n                    }\n                } else {\n                    mergeIntervals(); // merging intervals immediately\n                }\n                s.brushEndCallback(brush.filterSpecified ? filter.getConsolidated() : []);\n            })\n        );\n}\n\nfunction startAsc(a, b) { return a[0] - b[0]; }\n\nfunction renderAxisBrush(axisBrush) {\n    var background = axisBrush.selectAll('.background').data(repeat);\n\n    background.enter()\n        .append('rect')\n        .classed('background', true)\n        .call(barHorizontalSetup)\n        .call(backgroundBarHorizontalSetup)\n        .style('pointer-events', 'auto') // parent pointer events are disabled; we must have it to register events\n        .attr('transform', 'translate(0 ' + c.verticalPadding + ')');\n\n    background\n        .call(attachDragBehavior)\n        .attr('height', function(d) {\n            return d.height - c.verticalPadding;\n        });\n\n    var highlightShadow = axisBrush.selectAll('.highlight-shadow').data(repeat); // we have a set here, can't call it `extent`\n\n    highlightShadow.enter()\n        .append('line')\n        .classed('highlight-shadow', true)\n        .attr('x', -c.bar.width / 2)\n        .attr('stroke-width', c.bar.width + c.bar.strokeWidth)\n        .attr('stroke', c.bar.strokeColor)\n        .attr('opacity', c.bar.strokeOpacity)\n        .attr('stroke-linecap', 'butt');\n\n    highlightShadow\n        .attr('y1', function(d) { return d.height; })\n        .call(styleHighlight);\n\n    var highlight = axisBrush.selectAll('.highlight').data(repeat); // we have a set here, can't call it `extent`\n\n    highlight.enter()\n        .append('line')\n        .classed('highlight', true)\n        .attr('x', -c.bar.width / 2)\n        .attr('stroke-width', c.bar.width - c.bar.strokeWidth)\n        .attr('stroke', c.bar.fillColor)\n        .attr('opacity', c.bar.fillOpacity)\n        .attr('stroke-linecap', 'butt');\n\n    highlight\n        .attr('y1', function(d) { return d.height; })\n        .call(styleHighlight);\n}\n\nfunction ensureAxisBrush(axisOverlays) {\n    var axisBrush = axisOverlays.selectAll('.' + c.cn.axisBrush)\n        .data(repeat, keyFun);\n\n    axisBrush.enter()\n        .append('g')\n        .classed(c.cn.axisBrush, true);\n\n    renderAxisBrush(axisBrush);\n}\n\nfunction getBrushExtent(brush) {\n    return brush.svgBrush.extent.map(function(e) {return e.slice();});\n}\n\nfunction brushClear(brush) {\n    brush.filterSpecified = false;\n    brush.svgBrush.extent = [[-Infinity, Infinity]];\n}\n\nfunction axisBrushMoved(callback) {\n    return function axisBrushMoved(dimension) {\n        var brush = dimension.brush;\n        var extent = getBrushExtent(brush);\n        var newExtent = extent.slice();\n        brush.filter.set(newExtent);\n        callback();\n    };\n}\n\nfunction dedupeRealRanges(intervals) {\n    // Fuses elements of intervals if they overlap, yielding discontiguous intervals, results.length <= intervals.length\n    // Currently uses closed intervals, ie. dedupeRealRanges([[400, 800], [300, 400]]) -> [300, 800]\n    var queue = intervals.slice();\n    var result = [];\n    var currentInterval;\n    var current = queue.shift();\n    while(current) { // [].shift === undefined, so we don't descend into an empty array\n        currentInterval = current.slice();\n        while((current = queue.shift()) && current[0] <= /* right-open interval would need `<` */ currentInterval[1]) {\n            currentInterval[1] = Math.max(currentInterval[1], current[1]);\n        }\n        result.push(currentInterval);\n    }\n    return result;\n}\n\nfunction makeFilter() {\n    var filter = [];\n    var consolidated;\n    var bounds;\n    return {\n        set: function(a) {\n            filter = a\n                .map(function(d) { return d.slice().sort(sortAsc); })\n                .sort(startAsc);\n\n            // handle unselected case\n            if(filter.length === 1 &&\n                filter[0][0] === -Infinity &&\n                filter[0][1] === Infinity) {\n                filter = [[0, -1]];\n            }\n\n            consolidated = dedupeRealRanges(filter);\n            bounds = filter.reduce(function(p, n) {\n                return [Math.min(p[0], n[0]), Math.max(p[1], n[1])];\n            }, [Infinity, -Infinity]);\n        },\n        get: function() { return filter.slice(); },\n        getConsolidated: function() { return consolidated; },\n        getBounds: function() { return bounds; }\n    };\n}\n\nfunction makeBrush(state, rangeSpecified, initialRange, brushStartCallback, brushCallback, brushEndCallback) {\n    var filter = makeFilter();\n    filter.set(initialRange);\n    return {\n        filter: filter,\n        filterSpecified: rangeSpecified, // there's a difference between not filtering and filtering a non-proper subset\n        svgBrush: {\n            extent: [], // this is where the svgBrush writes contents into\n            brushStartCallback: brushStartCallback,\n            brushCallback: axisBrushMoved(brushCallback),\n            brushEndCallback: brushEndCallback\n        }\n    };\n}\n\n// for use by supplyDefaults, but it needed tons of pieces from here so\n// seemed to make more sense just to put the whole routine here\nfunction cleanRanges(ranges, dimension) {\n    if(Array.isArray(ranges[0])) {\n        ranges = ranges.map(function(ri) { return ri.sort(sortAsc); });\n\n        if(!dimension.multiselect) ranges = [ranges[0]];\n        else ranges = dedupeRealRanges(ranges.sort(startAsc));\n    } else ranges = [ranges.sort(sortAsc)];\n\n    // ordinal snapping\n    if(dimension.tickvals) {\n        var sortedTickVals = dimension.tickvals.slice().sort(sortAsc);\n        ranges = ranges.map(function(ri) {\n            var rSnapped = [\n                ordinalScaleSnap(0, sortedTickVals, ri[0], []),\n                ordinalScaleSnap(1, sortedTickVals, ri[1], [])\n            ];\n            if(rSnapped[1] > rSnapped[0]) return rSnapped;\n        })\n        .filter(function(ri) { return ri; });\n\n        if(!ranges.length) return;\n    }\n    return ranges.length > 1 ? ranges : ranges[0];\n}\n\nmodule.exports = {\n    makeBrush: makeBrush,\n    ensureAxisBrush: ensureAxisBrush,\n    cleanRanges: cleanRanges\n};\n\n},{\"../../lib\":719,\"../../lib/gup\":717,\"./constants\":1078,\"d3\":163}],1076:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\nvar parcoordsPlot = _dereq_('./plot');\nvar xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');\n\nexports.name = 'parcoords';\n\nexports.plot = function(gd) {\n    var calcData = getModuleCalcData(gd.calcdata, 'parcoords')[0];\n    if(calcData.length) parcoordsPlot(gd, calcData);\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var hadParcoords = (oldFullLayout._has && oldFullLayout._has('parcoords'));\n    var hasParcoords = (newFullLayout._has && newFullLayout._has('parcoords'));\n\n    if(hadParcoords && !hasParcoords) {\n        oldFullLayout._paperdiv.selectAll('.parcoords').remove();\n        oldFullLayout._glimages.selectAll('*').remove();\n    }\n};\n\nexports.toSVG = function(gd) {\n    var imageRoot = gd._fullLayout._glimages;\n    var root = d3.select(gd).selectAll('.svg-container');\n    var canvases = root.filter(function(d, i) {return i === root.size() - 1;})\n        .selectAll('.gl-canvas-context, .gl-canvas-focus');\n\n    function canvasToImage() {\n        var canvas = this;\n        var imageData = canvas.toDataURL('image/png');\n        var image = imageRoot.append('svg:image');\n\n        image.attr({\n            xmlns: xmlnsNamespaces.svg,\n            'xlink:href': imageData,\n            preserveAspectRatio: 'none',\n            x: 0,\n            y: 0,\n            width: canvas.width,\n            height: canvas.height\n        });\n    }\n\n    canvases.each(canvasToImage);\n\n    // Chrome / Safari bug workaround - browser apparently loses connection to the defined pattern\n    // Without the workaround, these browsers 'lose' the filter brush styling (color etc.) after a snapshot\n    // on a subsequent interaction.\n    // Firefox works fine without this workaround\n    window.setTimeout(function() {\n        d3.selectAll('#filterBarPattern')\n            .attr('id', 'filterBarPattern');\n    }, 60);\n};\n\n},{\"../../constants/xmlns_namespaces\":696,\"../../plots/get_data\":802,\"./plot\":1085,\"d3\":163}],1077:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\nvar Colorscale = _dereq_('../../components/colorscale');\nvar wrap = _dereq_('../../lib/gup').wrap;\n\nmodule.exports = function calc(gd, trace) {\n    var lineColor;\n    var cscale;\n\n    if(Colorscale.hasColorscale(trace, 'line') && isArrayOrTypedArray(trace.line.color)) {\n        lineColor = trace.line.color;\n        cscale = Colorscale.extractOpts(trace.line).colorscale;\n\n        Colorscale.calc(gd, trace, {\n            vals: lineColor,\n            containerStr: 'line',\n            cLetter: 'c'\n        });\n    } else {\n        lineColor = constHalf(trace._length);\n        cscale = [[0, trace.line.color], [1, trace.line.color]];\n    }\n\n    return wrap({lineColor: lineColor, cscale: cscale});\n};\n\nfunction constHalf(len) {\n    var out = new Array(len);\n    for(var i = 0; i < len; i++) {\n        out[i] = 0.5;\n    }\n    return out;\n}\n\n},{\"../../components/colorscale\":605,\"../../lib\":719,\"../../lib/gup\":717}],1078:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n\nmodule.exports = {\n    maxDimensionCount: 60, // this cannot be increased without WebGL code refactoring\n    overdrag: 45,\n    verticalPadding: 2, // otherwise, horizontal lines on top or bottom are of lower width\n    tickDistance: 50,\n    canvasPixelRatio: 1,\n    blockLineCount: 5000,\n    layers: ['contextLineLayer', 'focusLineLayer', 'pickLineLayer'],\n    axisTitleOffset: 28,\n    axisExtentOffset: 10,\n    deselectedLineColor: '#777',\n    bar: {\n        width: 4, // Visible width of the filter bar\n        captureWidth: 10, // Mouse-sensitive width for interaction (Fitts law)\n        fillColor: 'magenta', // Color of the filter bar fill\n        fillOpacity: 1, // Filter bar fill opacity\n        snapDuration: 150, // tween duration in ms for brush snap for ordinal axes\n        snapRatio: 0.25, // ratio of bar extension relative to the distance between two adjacent ordinal values\n        snapClose: 0.01, // fraction of inter-value distance to snap to the closer one, even if you're not over it\n        strokeColor: 'white', // Color of the filter bar side lines\n        strokeOpacity: 1, // Filter bar side stroke opacity\n        strokeWidth: 1, // Filter bar side stroke width in pixels\n        handleHeight: 8, // Height of the filter bar vertical resize areas on top and bottom\n        handleOpacity: 1, // Opacity of the filter bar vertical resize areas on top and bottom\n        handleOverlap: 0 // A larger than 0 value causes overlaps with the filter bar, represented as pixels\n    },\n    cn: {\n        axisExtentText: 'axis-extent-text',\n        parcoordsLineLayers: 'parcoords-line-layers',\n        parcoordsLineLayer: 'parcoords-lines',\n        parcoords: 'parcoords',\n        parcoordsControlView: 'parcoords-control-view',\n        yAxis: 'y-axis',\n        axisOverlays: 'axis-overlays',\n        axis: 'axis',\n        axisHeading: 'axis-heading',\n        axisTitle: 'axis-title',\n        axisExtent: 'axis-extent',\n        axisExtentTop: 'axis-extent-top',\n        axisExtentTopText: 'axis-extent-top-text',\n        axisExtentBottom: 'axis-extent-bottom',\n        axisExtentBottomText: 'axis-extent-bottom-text',\n        axisBrush: 'axis-brush'\n    },\n    id: {\n        filterBarPattern: 'filter-bar-pattern'\n\n    }\n};\n\n},{}],1079:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar handleDomainDefaults = _dereq_('../../plots/domain').defaults;\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nvar attributes = _dereq_('./attributes');\nvar axisBrush = _dereq_('./axisbrush');\nvar maxDimensionCount = _dereq_('./constants').maxDimensionCount;\nvar mergeLength = _dereq_('./merge_length');\n\nfunction handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {\n    var lineColor = coerce('line.color', defaultColor);\n\n    if(hasColorscale(traceIn, 'line') && Lib.isArrayOrTypedArray(lineColor)) {\n        if(lineColor.length) {\n            coerce('line.colorscale');\n            colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});\n            // TODO: I think it would be better to keep showing lines beyond the last line color\n            // but I'm not sure what color to give these lines - probably black or white\n            // depending on the background color?\n            return lineColor.length;\n        } else {\n            traceOut.line.color = defaultColor;\n        }\n    }\n    return Infinity;\n}\n\nfunction dimensionDefaults(dimensionIn, dimensionOut, parentOut, opts) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(dimensionIn, dimensionOut, attributes.dimensions, attr, dflt);\n    }\n\n    var values = coerce('values');\n    var visible = coerce('visible');\n    if(!(values && values.length)) {\n        visible = dimensionOut.visible = false;\n    }\n\n    if(visible) {\n        coerce('label');\n        coerce('tickvals');\n        coerce('ticktext');\n        coerce('tickformat');\n        var range = coerce('range');\n\n        dimensionOut._ax = {\n            _id: 'y',\n            type: 'linear',\n            showexponent: 'all',\n            exponentformat: 'B',\n            range: range\n        };\n\n        Axes.setConvert(dimensionOut._ax, opts.layout);\n\n        coerce('multiselect');\n        var constraintRange = coerce('constraintrange');\n        if(constraintRange) {\n            dimensionOut.constraintrange = axisBrush.cleanRanges(constraintRange, dimensionOut);\n        }\n    }\n}\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var dimensionsIn = traceIn.dimensions;\n    if(Array.isArray(dimensionsIn) && dimensionsIn.length > maxDimensionCount) {\n        Lib.log('parcoords traces support up to ' + maxDimensionCount + ' dimensions at the moment');\n        dimensionsIn.splice(maxDimensionCount);\n    }\n\n    var dimensions = handleArrayContainerDefaults(traceIn, traceOut, {\n        name: 'dimensions',\n        layout: layout,\n        handleItemDefaults: dimensionDefaults\n    });\n\n    var len = handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n\n    handleDomainDefaults(traceOut, layout, coerce);\n\n    if(!Array.isArray(dimensions) || !dimensions.length) {\n        traceOut.visible = false;\n    }\n\n    mergeLength(traceOut, dimensions, 'values', len);\n\n    // make default font size 10px (default is 12),\n    // scale linearly with global font size\n    var fontDflt = {\n        family: layout.font.family,\n        size: Math.round(layout.font.size / 1.2),\n        color: layout.font.color\n    };\n\n    Lib.coerceFont(coerce, 'labelfont', fontDflt);\n    Lib.coerceFont(coerce, 'tickfont', fontDflt);\n    Lib.coerceFont(coerce, 'rangefont', fontDflt);\n\n    coerce('labelangle');\n    coerce('labelside');\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../components/colorscale/helpers\":604,\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"../../plots/cartesian/axes\":767,\"../../plots/domain\":792,\"./attributes\":1074,\"./axisbrush\":1075,\"./constants\":1078,\"./merge_length\":1083}],1080:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isTypedArray = _dereq_('../../lib').isTypedArray;\n\nexports.convertTypedArray = function(a) {\n    return isTypedArray(a) ? Array.prototype.slice.call(a) : a;\n};\n\nexports.isOrdinal = function(dimension) {\n    return !!dimension.tickvals;\n};\n\nexports.isVisible = function(dimension) {\n    return dimension.visible || !('visible' in dimension);\n};\n\n},{\"../../lib\":719}],1081:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    colorbar: {\n        container: 'line',\n        min: 'cmin',\n        max: 'cmax'\n    },\n\n    moduleType: 'trace',\n    name: 'parcoords',\n    basePlotModule: _dereq_('./base_plot'),\n    categories: ['gl', 'regl', 'noOpacity', 'noHover'],\n    meta: {\n        \n    }\n};\n\n},{\"./attributes\":1074,\"./base_plot\":1076,\"./calc\":1077,\"./defaults\":1079,\"./plot\":1085}],1082:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar glslify = _dereq_('glslify');\nvar vertexShaderSource = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nvarying vec4 fragColor;\\n\\nattribute vec4 p01_04, p05_08, p09_12, p13_16,\\n               p17_20, p21_24, p25_28, p29_32,\\n               p33_36, p37_40, p41_44, p45_48,\\n               p49_52, p53_56, p57_60, colors;\\n\\nuniform mat4 dim0A, dim1A, dim0B, dim1B, dim0C, dim1C, dim0D, dim1D,\\n             loA, hiA, loB, hiB, loC, hiC, loD, hiD;\\n\\nuniform vec2 resolution, viewBoxPos, viewBoxSize;\\nuniform sampler2D mask, palette;\\nuniform float maskHeight;\\nuniform float drwLayer; // 0: context, 1: focus, 2: pick\\nuniform vec4 contextColor;\\n\\nbool isPick    = (drwLayer > 1.5);\\nbool isContext = (drwLayer < 0.5);\\n\\nconst vec4 ZEROS = vec4(0.0, 0.0, 0.0, 0.0);\\nconst vec4 UNITS = vec4(1.0, 1.0, 1.0, 1.0);\\n\\nfloat val(mat4 p, mat4 v) {\\n    return dot(matrixCompMult(p, v) * UNITS, UNITS);\\n}\\n\\nfloat axisY(float ratio, mat4 A, mat4 B, mat4 C, mat4 D) {\\n    float y1 = val(A, dim0A) + val(B, dim0B) + val(C, dim0C) + val(D, dim0D);\\n    float y2 = val(A, dim1A) + val(B, dim1B) + val(C, dim1C) + val(D, dim1D);\\n    return y1 * (1.0 - ratio) + y2 * ratio;\\n}\\n\\nint iMod(int a, int b) {\\n    return a - b * (a / b);\\n}\\n\\nbool fOutside(float p, float lo, float hi) {\\n    return (lo < hi) && (lo > p || p > hi);\\n}\\n\\nbool vOutside(vec4 p, vec4 lo, vec4 hi) {\\n    return (\\n        fOutside(p[0], lo[0], hi[0]) ||\\n        fOutside(p[1], lo[1], hi[1]) ||\\n        fOutside(p[2], lo[2], hi[2]) ||\\n        fOutside(p[3], lo[3], hi[3])\\n    );\\n}\\n\\nbool mOutside(mat4 p, mat4 lo, mat4 hi) {\\n    return (\\n        vOutside(p[0], lo[0], hi[0]) ||\\n        vOutside(p[1], lo[1], hi[1]) ||\\n        vOutside(p[2], lo[2], hi[2]) ||\\n        vOutside(p[3], lo[3], hi[3])\\n    );\\n}\\n\\nbool outsideBoundingBox(mat4 A, mat4 B, mat4 C, mat4 D) {\\n    return mOutside(A, loA, hiA) ||\\n           mOutside(B, loB, hiB) ||\\n           mOutside(C, loC, hiC) ||\\n           mOutside(D, loD, hiD);\\n}\\n\\nbool outsideRasterMask(mat4 A, mat4 B, mat4 C, mat4 D) {\\n    mat4 pnts[4];\\n    pnts[0] = A;\\n    pnts[1] = B;\\n    pnts[2] = C;\\n    pnts[3] = D;\\n\\n    for(int i = 0; i < 4; ++i) {\\n        for(int j = 0; j < 4; ++j) {\\n            for(int k = 0; k < 4; ++k) {\\n                if(0 == iMod(\\n                    int(255.0 * texture2D(mask,\\n                        vec2(\\n                            (float(i * 2 + j / 2) + 0.5) / 8.0,\\n                            (pnts[i][j][k] * (maskHeight - 1.0) + 1.0) / maskHeight\\n                        ))[3]\\n                    ) / int(pow(2.0, float(iMod(j * 4 + k, 8)))),\\n                    2\\n                )) return true;\\n            }\\n        }\\n    }\\n    return false;\\n}\\n\\nvec4 position(bool isContext, float v, mat4 A, mat4 B, mat4 C, mat4 D) {\\n    float x = 0.5 * sign(v) + 0.5;\\n    float y = axisY(x, A, B, C, D);\\n    float z = 1.0 - abs(v);\\n\\n    z += isContext ? 0.0 : 2.0 * float(\\n        outsideBoundingBox(A, B, C, D) ||\\n        outsideRasterMask(A, B, C, D)\\n    );\\n\\n    return vec4(\\n        2.0 * (vec2(x, y) * viewBoxSize + viewBoxPos) / resolution - 1.0,\\n        z,\\n        1.0\\n    );\\n}\\n\\nvoid main() {\\n    mat4 A = mat4(p01_04, p05_08, p09_12, p13_16);\\n    mat4 B = mat4(p17_20, p21_24, p25_28, p29_32);\\n    mat4 C = mat4(p33_36, p37_40, p41_44, p45_48);\\n    mat4 D = mat4(p49_52, p53_56, p57_60, ZEROS);\\n\\n    float v = colors[3];\\n\\n    gl_Position = position(isContext, v, A, B, C, D);\\n\\n    fragColor =\\n        isContext ? vec4(contextColor) :\\n        isPick ? vec4(colors.rgb, 1.0) : texture2D(palette, vec2(abs(v), 0.5));\\n}\\n\"]);\nvar fragmentShaderSource = glslify([\"precision highp float;\\n#define GLSLIFY 1\\n\\nvarying vec4 fragColor;\\n\\nvoid main() {\\n    gl_FragColor = fragColor;\\n}\\n\"]);\nvar maxDim = _dereq_('./constants').maxDimensionCount;\n\nvar Lib = _dereq_('../../lib');\n\n// don't change; otherwise near/far plane lines are lost\nvar depthLimitEpsilon = 1e-6;\n\n// precision of multiselect is the full range divided into this many parts\nvar maskHeight = 2048;\n\nvar dummyPixel = new Uint8Array(4);\nvar dataPixel = new Uint8Array(4);\n\nvar paletteTextureConfig = {\n    shape: [256, 1],\n    format: 'rgba',\n    type: 'uint8',\n    mag: 'nearest',\n    min: 'nearest'\n};\n\nfunction ensureDraw(regl) {\n    regl.read({\n        x: 0,\n        y: 0,\n        width: 1,\n        height: 1,\n        data: dummyPixel\n    });\n}\n\nfunction clear(regl, x, y, width, height) {\n    var gl = regl._gl;\n    gl.enable(gl.SCISSOR_TEST);\n    gl.scissor(x, y, width, height);\n    regl.clear({color: [0, 0, 0, 0], depth: 1}); // clearing is done in scissored panel only\n}\n\nfunction renderBlock(regl, glAes, renderState, blockLineCount, sampleCount, item) {\n    var rafKey = item.key;\n\n    function render(blockNumber) {\n        var count = Math.min(blockLineCount, sampleCount - blockNumber * blockLineCount);\n\n        if(blockNumber === 0) {\n            // stop drawing possibly stale glyphs before clearing\n            window.cancelAnimationFrame(renderState.currentRafs[rafKey]);\n            delete renderState.currentRafs[rafKey];\n            clear(regl, item.scissorX, item.scissorY, item.scissorWidth, item.viewBoxSize[1]);\n        }\n\n        if(renderState.clearOnly) {\n            return;\n        }\n\n        item.count = 2 * count;\n        item.offset = 2 * blockNumber * blockLineCount;\n        glAes(item);\n\n        if(blockNumber * blockLineCount + count < sampleCount) {\n            renderState.currentRafs[rafKey] = window.requestAnimationFrame(function() {\n                render(blockNumber + 1);\n            });\n        }\n\n        renderState.drawCompleted = false;\n    }\n\n    if(!renderState.drawCompleted) {\n        ensureDraw(regl);\n        renderState.drawCompleted = true;\n    }\n\n    // start with rendering item 0; recursion handles the rest\n    render(0);\n}\n\nfunction adjustDepth(d) {\n    // WebGL matrix operations use floats with limited precision, potentially causing a number near a border of [0, 1]\n    // to end up slightly outside the border. With an epsilon, we reduce the chance that a line gets clipped by the\n    // near or the far plane.\n    return Math.max(depthLimitEpsilon, Math.min(1 - depthLimitEpsilon, d));\n}\n\nfunction palette(unitToColor, opacity) {\n    var result = new Array(256);\n    for(var i = 0; i < 256; i++) {\n        result[i] = unitToColor(i / 255).concat(opacity);\n    }\n    return result;\n}\n\n// Maps the sample index [0...sampleCount - 1] to a range of [0, 1] as the shader expects colors in the [0, 1] range.\n// but first it shifts the sample index by 0, 8 or 16 bits depending on rgbIndex [0..2]\n// with the end result that each line will be of a unique color, making it possible for the pick handler\n// to uniquely identify which line is hovered over (bijective mapping).\n// The inverse, i.e. readPixel is invoked from 'parcoords.js'\nfunction calcPickColor(i, rgbIndex) {\n    return (i >>> 8 * rgbIndex) % 256 / 255;\n}\n\nfunction makePoints(sampleCount, dims, color) {\n    var points = new Array(sampleCount * (maxDim + 4));\n    var n = 0;\n    for(var i = 0; i < sampleCount; i++) {\n        for(var k = 0; k < maxDim; k++) {\n            points[n++] = (k < dims.length) ? dims[k].paddedUnitValues[i] : 0.5;\n        }\n        points[n++] = calcPickColor(i, 2);\n        points[n++] = calcPickColor(i, 1);\n        points[n++] = calcPickColor(i, 0);\n        points[n++] = adjustDepth(color[i]);\n    }\n    return points;\n}\n\nfunction makeVecAttr(vecIndex, sampleCount, points) {\n    var pointPairs = new Array(sampleCount * 8);\n    var n = 0;\n    for(var i = 0; i < sampleCount; i++) {\n        for(var j = 0; j < 2; j++) {\n            for(var k = 0; k < 4; k++) {\n                var q = vecIndex * 4 + k;\n                var v = points[i * 64 + q];\n                if(q === 63 && j === 0) {\n                    v *= -1;\n                }\n                pointPairs[n++] = v;\n            }\n        }\n    }\n    return pointPairs;\n}\n\nfunction pad2(num) {\n    var s = '0' + num;\n    return s.substr(s.length - 2);\n}\n\nfunction getAttrName(i) {\n    return (i < maxDim) ? 'p' + pad2(i + 1) + '_' + pad2(i + 4) : 'colors';\n}\n\nfunction setAttributes(attributes, sampleCount, points) {\n    for(var i = 0; i <= maxDim; i += 4) {\n        attributes[getAttrName(i)](makeVecAttr(i / 4, sampleCount, points));\n    }\n}\n\nfunction emptyAttributes(regl) {\n    var attributes = {};\n    for(var i = 0; i <= maxDim; i += 4) {\n        attributes[getAttrName(i)] = regl.buffer({usage: 'dynamic', type: 'float', data: new Uint8Array(0)});\n    }\n    return attributes;\n}\n\nfunction makeItem(model, leftmost, rightmost, itemNumber, i0, i1, x, y, panelSizeX, panelSizeY, crossfilterDimensionIndex, drwLayer, constraints) {\n    var dims = [[], []];\n    for(var k = 0; k < 64; k++) {\n        dims[0][k] = (k === i0) ? 1 : 0;\n        dims[1][k] = (k === i1) ? 1 : 0;\n    }\n\n    var overdrag = model.lines.canvasOverdrag;\n    var domain = model.domain;\n    var canvasWidth = model.canvasWidth;\n    var canvasHeight = model.canvasHeight;\n\n    var deselectedLinesColor = model.deselectedLines.color;\n\n    var itemModel = Lib.extendFlat({\n        key: crossfilterDimensionIndex,\n        resolution: [canvasWidth, canvasHeight],\n        viewBoxPos: [x + overdrag, y],\n        viewBoxSize: [panelSizeX, panelSizeY],\n        i0: i0,\n        i1: i1,\n\n        dim0A: dims[0].slice(0, 16),\n        dim0B: dims[0].slice(16, 32),\n        dim0C: dims[0].slice(32, 48),\n        dim0D: dims[0].slice(48, 64),\n        dim1A: dims[1].slice(0, 16),\n        dim1B: dims[1].slice(16, 32),\n        dim1C: dims[1].slice(32, 48),\n        dim1D: dims[1].slice(48, 64),\n\n        drwLayer: drwLayer,\n        contextColor: [\n            deselectedLinesColor[0] / 255,\n            deselectedLinesColor[1] / 255,\n            deselectedLinesColor[2] / 255,\n            deselectedLinesColor[3] < 1 ?\n                deselectedLinesColor[3] :\n                Math.max(1 / 255, Math.pow(1 / model.lines.color.length, 1 / 3))\n        ],\n\n        scissorX: (itemNumber === leftmost ? 0 : x + overdrag) + (model.pad.l - overdrag) + model.layoutWidth * domain.x[0],\n        scissorWidth: (itemNumber === rightmost ? canvasWidth - x + overdrag : panelSizeX + 0.5) + (itemNumber === leftmost ? x + overdrag : 0),\n        scissorY: y + model.pad.b + model.layoutHeight * domain.y[0],\n        scissorHeight: panelSizeY,\n\n        viewportX: model.pad.l - overdrag + model.layoutWidth * domain.x[0],\n        viewportY: model.pad.b + model.layoutHeight * domain.y[0],\n        viewportWidth: canvasWidth,\n        viewportHeight: canvasHeight\n    }, constraints);\n\n    return itemModel;\n}\n\nfunction expandedPixelRange(bounds) {\n    var dh = maskHeight - 1;\n    return [\n        Math.max(0, Math.floor(bounds[0] * dh), 0),\n        Math.min(dh, Math.ceil(bounds[1] * dh), dh)\n    ];\n}\n\nmodule.exports = function(canvasGL, d) {\n    // context & pick describe which canvas we're talking about - won't change with new data\n    var isContext = d.context;\n    var isPick = d.pick;\n\n    var regl = d.regl;\n\n    var renderState = {\n        currentRafs: {},\n        drawCompleted: true,\n        clearOnly: false\n    };\n\n    // state to be set by update and used later\n    var model;\n    var vm;\n    var initialDims;\n    var sampleCount;\n    var attributes = emptyAttributes(regl);\n    var maskTexture;\n    var paletteTexture = regl.texture(paletteTextureConfig);\n\n    var prevAxisOrder = [];\n\n    update(d);\n\n    var glAes = regl({\n\n        profile: false,\n\n        blend: {\n            enable: isContext,\n            func: {\n                srcRGB: 'src alpha',\n                dstRGB: 'one minus src alpha',\n                srcAlpha: 1,\n                dstAlpha: 1 // 'one minus src alpha'\n            },\n            equation: {\n                rgb: 'add',\n                alpha: 'add'\n            },\n            color: [0, 0, 0, 0]\n        },\n\n        depth: {\n            enable: !isContext,\n            mask: true,\n            func: 'less',\n            range: [0, 1]\n        },\n\n        // for polygons\n        cull: {\n            enable: true,\n            face: 'back'\n        },\n\n        scissor: {\n            enable: true,\n            box: {\n                x: regl.prop('scissorX'),\n                y: regl.prop('scissorY'),\n                width: regl.prop('scissorWidth'),\n                height: regl.prop('scissorHeight')\n            }\n        },\n\n        viewport: {\n            x: regl.prop('viewportX'),\n            y: regl.prop('viewportY'),\n            width: regl.prop('viewportWidth'),\n            height: regl.prop('viewportHeight')\n        },\n\n        dither: false,\n\n        vert: vertexShaderSource,\n\n        frag: fragmentShaderSource,\n\n        primitive: 'lines',\n        lineWidth: 1,\n        attributes: attributes,\n        uniforms: {\n            resolution: regl.prop('resolution'),\n            viewBoxPos: regl.prop('viewBoxPos'),\n            viewBoxSize: regl.prop('viewBoxSize'),\n            dim0A: regl.prop('dim0A'),\n            dim1A: regl.prop('dim1A'),\n            dim0B: regl.prop('dim0B'),\n            dim1B: regl.prop('dim1B'),\n            dim0C: regl.prop('dim0C'),\n            dim1C: regl.prop('dim1C'),\n            dim0D: regl.prop('dim0D'),\n            dim1D: regl.prop('dim1D'),\n            loA: regl.prop('loA'),\n            hiA: regl.prop('hiA'),\n            loB: regl.prop('loB'),\n            hiB: regl.prop('hiB'),\n            loC: regl.prop('loC'),\n            hiC: regl.prop('hiC'),\n            loD: regl.prop('loD'),\n            hiD: regl.prop('hiD'),\n            palette: paletteTexture,\n            contextColor: regl.prop('contextColor'),\n            mask: regl.prop('maskTexture'),\n            drwLayer: regl.prop('drwLayer'),\n            maskHeight: regl.prop('maskHeight')\n        },\n        offset: regl.prop('offset'),\n        count: regl.prop('count')\n    });\n\n    function update(dNew) {\n        model = dNew.model;\n        vm = dNew.viewModel;\n        initialDims = vm.dimensions.slice();\n        sampleCount = initialDims[0] ? initialDims[0].values.length : 0;\n\n        var lines = model.lines;\n        var color = isPick ? lines.color.map(function(_, i) {return i / lines.color.length;}) : lines.color;\n\n        var points = makePoints(sampleCount, initialDims, color);\n        setAttributes(attributes, sampleCount, points);\n\n        if(!isContext && !isPick) {\n            paletteTexture = regl.texture(Lib.extendFlat({\n                data: palette(model.unitToColor, 255)\n            }, paletteTextureConfig));\n        }\n    }\n\n    function makeConstraints(isContext) {\n        var i, j, k;\n\n        var limits = [[], []];\n        for(k = 0; k < 64; k++) {\n            var p = (!isContext && k < initialDims.length) ?\n                initialDims[k].brush.filter.getBounds() : [-Infinity, Infinity];\n\n            limits[0][k] = p[0];\n            limits[1][k] = p[1];\n        }\n\n        var len = maskHeight * 8;\n        var mask = new Array(len);\n        for(i = 0; i < len; i++) {\n            mask[i] = 255;\n        }\n        if(!isContext) {\n            for(i = 0; i < initialDims.length; i++) {\n                var u = i % 8;\n                var v = (i - u) / 8;\n                var bitMask = Math.pow(2, u);\n                var dim = initialDims[i];\n                var ranges = dim.brush.filter.get();\n                if(ranges.length < 2) continue; // bail if the bounding box based filter is sufficient\n\n                var prevEnd = expandedPixelRange(ranges[0])[1];\n                for(j = 1; j < ranges.length; j++) {\n                    var nextRange = expandedPixelRange(ranges[j]);\n                    for(k = prevEnd + 1; k < nextRange[0]; k++) {\n                        mask[k * 8 + v] &= ~bitMask;\n                    }\n                    prevEnd = Math.max(prevEnd, nextRange[1]);\n                }\n            }\n        }\n\n        var textureData = {\n            // 8 units x 8 bits = 64 bits, just sufficient for the almost 64 dimensions we support\n            shape: [8, maskHeight],\n            format: 'alpha',\n            type: 'uint8',\n            mag: 'nearest',\n            min: 'nearest',\n            data: mask\n        };\n        if(maskTexture) maskTexture(textureData);\n        else maskTexture = regl.texture(textureData);\n\n        return {\n            maskTexture: maskTexture,\n            maskHeight: maskHeight,\n            loA: limits[0].slice(0, 16),\n            loB: limits[0].slice(16, 32),\n            loC: limits[0].slice(32, 48),\n            loD: limits[0].slice(48, 64),\n            hiA: limits[1].slice(0, 16),\n            hiB: limits[1].slice(16, 32),\n            hiC: limits[1].slice(32, 48),\n            hiD: limits[1].slice(48, 64),\n        };\n    }\n\n    function renderGLParcoords(panels, setChanged, clearOnly) {\n        var panelCount = panels.length;\n        var i;\n\n        var leftmost;\n        var rightmost;\n        var lowestX = Infinity;\n        var highestX = -Infinity;\n\n        for(i = 0; i < panelCount; i++) {\n            if(panels[i].dim0.canvasX < lowestX) {\n                lowestX = panels[i].dim0.canvasX;\n                leftmost = i;\n            }\n            if(panels[i].dim1.canvasX > highestX) {\n                highestX = panels[i].dim1.canvasX;\n                rightmost = i;\n            }\n        }\n\n        if(panelCount === 0) {\n            // clear canvas here, as the panel iteration below will not enter the loop body\n            clear(regl, 0, 0, model.canvasWidth, model.canvasHeight);\n        }\n        var constraints = makeConstraints(isContext);\n\n        for(i = 0; i < panelCount; i++) {\n            var p = panels[i];\n            var i0 = p.dim0.crossfilterDimensionIndex;\n            var i1 = p.dim1.crossfilterDimensionIndex;\n            var x = p.canvasX;\n            var y = p.canvasY;\n            var nextX = x + p.panelSizeX;\n            if(setChanged ||\n                !prevAxisOrder[i0] ||\n                prevAxisOrder[i0][0] !== x ||\n                prevAxisOrder[i0][1] !== nextX\n            ) {\n                prevAxisOrder[i0] = [x, nextX];\n\n                var item = makeItem(\n                    model,\n                    leftmost, rightmost, i, i0, i1, x, y,\n                    p.panelSizeX, p.panelSizeY,\n                    p.dim0.crossfilterDimensionIndex,\n                    isContext ? 0 : isPick ? 2 : 1,\n                    constraints\n                );\n\n                renderState.clearOnly = clearOnly;\n\n                var blockLineCount = setChanged ? model.lines.blockLineCount : sampleCount;\n                renderBlock(\n                    regl, glAes, renderState, blockLineCount, sampleCount, item\n                );\n            }\n        }\n    }\n\n    function readPixel(canvasX, canvasY) {\n        regl.read({\n            x: canvasX,\n            y: canvasY,\n            width: 1,\n            height: 1,\n            data: dataPixel\n        });\n        return dataPixel;\n    }\n\n    function readPixels(canvasX, canvasY, width, height) {\n        var pixelArray = new Uint8Array(4 * width * height);\n        regl.read({\n            x: canvasX,\n            y: canvasY,\n            width: width,\n            height: height,\n            data: pixelArray\n        });\n        return pixelArray;\n    }\n\n    function destroy() {\n        canvasGL.style['pointer-events'] = 'none';\n        paletteTexture.destroy();\n        if(maskTexture) maskTexture.destroy();\n        for(var k in attributes) attributes[k].destroy();\n    }\n\n    return {\n        render: renderGLParcoords,\n        readPixel: readPixel,\n        readPixels: readPixels,\n        destroy: destroy,\n        update: update\n    };\n};\n\n},{\"../../lib\":719,\"./constants\":1078,\"glslify\":409}],1083:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\n/**\n * mergeLength: set trace length as the minimum of all dimension data lengths\n *     and propagates this length into each dimension\n *\n * @param {object} traceOut: the fullData trace\n * @param {Array(object)} dimensions: array of dimension objects\n * @param {string} dataAttr: the attribute of each dimension containing the data\n * @param {integer} len: an already-existing length from other attributes\n */\nmodule.exports = function(traceOut, dimensions, dataAttr, len) {\n    if(!len) len = Infinity;\n    var i, dimi;\n    for(i = 0; i < dimensions.length; i++) {\n        dimi = dimensions[i];\n        if(dimi.visible) len = Math.min(len, dimi[dataAttr].length);\n    }\n    if(len === Infinity) len = 0;\n\n    traceOut._length = len;\n    for(i = 0; i < dimensions.length; i++) {\n        dimi = dimensions[i];\n        if(dimi.visible) dimi._length = len;\n    }\n\n    return len;\n};\n\n},{}],1084:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar rgba = _dereq_('color-rgba');\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar Drawing = _dereq_('../../components/drawing');\nvar Colorscale = _dereq_('../../components/colorscale');\n\nvar gup = _dereq_('../../lib/gup');\nvar keyFun = gup.keyFun;\nvar repeat = gup.repeat;\nvar unwrap = gup.unwrap;\n\nvar helpers = _dereq_('./helpers');\nvar c = _dereq_('./constants');\nvar brush = _dereq_('./axisbrush');\nvar lineLayerMaker = _dereq_('./lines');\n\nfunction findExtreme(fn, values, len) {\n    return Lib.aggNums(fn, null, values, len);\n}\n\nfunction findExtremes(values, len) {\n    return [\n        findExtreme(Math.min, values, len),\n        findExtreme(Math.max, values, len)\n    ];\n}\n\nfunction dimensionExtent(dimension) {\n    var range = dimension.range;\n    if(!range) range = findExtremes(dimension.values, dimension._length);\n\n    var lo = range[0];\n    var hi = range[1];\n\n    if(isNaN(lo) || !isFinite(lo)) {\n        lo = 0;\n    }\n\n    if(isNaN(hi) || !isFinite(hi)) {\n        hi = 0;\n    }\n\n    // avoid a degenerate (zero-width) domain\n    if(lo === hi) {\n        if(lo === 0) {\n            // no use to multiplying zero, so add/subtract in this case\n            lo -= 1;\n            hi += 1;\n        } else {\n            // this keeps the range in the order of magnitude of the data\n            lo *= 0.9;\n            hi *= 1.1;\n        }\n    }\n\n    return [lo, hi];\n}\n\nfunction toText(formatter, texts) {\n    if(texts) {\n        return function(v, i) {\n            var text = texts[i];\n            if(text === null || text === undefined) return formatter(v);\n            return text;\n        };\n    }\n    return formatter;\n}\n\nfunction domainScale(height, padding, dimension, tickvals, ticktext) {\n    var extent = dimensionExtent(dimension);\n    if(tickvals) {\n        return d3.scale.ordinal()\n            .domain(tickvals.map(toText(d3.format(dimension.tickformat), ticktext)))\n            .range(tickvals\n                .map(function(d) {\n                    var unitVal = (d - extent[0]) / (extent[1] - extent[0]);\n                    return (height - padding + unitVal * (2 * padding - height));\n                })\n            );\n    }\n    return d3.scale.linear()\n        .domain(extent)\n        .range([height - padding, padding]);\n}\n\nfunction unitToPaddedPx(height, padding) {\n    return d3.scale.linear().range([padding, height - padding]);\n}\n\nfunction domainToPaddedUnitScale(dimension, padFraction) {\n    return d3.scale.linear()\n        .domain(dimensionExtent(dimension))\n        .range([padFraction, 1 - padFraction]);\n}\n\nfunction ordinalScale(dimension) {\n    if(!dimension.tickvals) return;\n\n    var extent = dimensionExtent(dimension);\n    return d3.scale.ordinal()\n        .domain(dimension.tickvals)\n        .range(dimension.tickvals.map(function(d) {\n            return (d - extent[0]) / (extent[1] - extent[0]);\n        }));\n}\n\nfunction unitToColorScale(cscale) {\n    var colorStops = cscale.map(function(d) { return d[0]; });\n    var colorTuples = cscale.map(function(d) {\n        var RGBA = rgba(d[1]);\n        return d3.rgb('rgb(' + RGBA[0] + ',' + RGBA[1] + ',' + RGBA[2] + ')');\n    });\n    var prop = function(n) { return function(o) { return o[n]; }; };\n\n    // We can't use d3 color interpolation as we may have non-uniform color palette raster\n    // (various color stop distances).\n    var polylinearUnitScales = 'rgb'.split('').map(function(key) {\n        return d3.scale.linear()\n            .clamp(true)\n            .domain(colorStops)\n            .range(colorTuples.map(prop(key)));\n    });\n\n    return function(d) {\n        return polylinearUnitScales.map(function(s) {\n            return s(d);\n        });\n    };\n}\n\nfunction someFiltersActive(view) {\n    return view.dimensions.some(function(p) {\n        return p.brush.filterSpecified;\n    });\n}\n\nfunction model(layout, d, i) {\n    var cd0 = unwrap(d);\n    var trace = cd0.trace;\n    var lineColor = helpers.convertTypedArray(cd0.lineColor);\n    var line = trace.line;\n    var deselectedLines = {color: rgba(c.deselectedLineColor)};\n    var cOpts = Colorscale.extractOpts(line);\n    var cscale = cOpts.reversescale ? Colorscale.flipScale(cd0.cscale) : cd0.cscale;\n    var domain = trace.domain;\n    var dimensions = trace.dimensions;\n    var width = layout.width;\n    var labelAngle = trace.labelangle;\n    var labelSide = trace.labelside;\n    var labelFont = trace.labelfont;\n    var tickFont = trace.tickfont;\n    var rangeFont = trace.rangefont;\n\n    var lines = Lib.extendDeepNoArrays({}, line, {\n        color: lineColor.map(d3.scale.linear().domain(\n            dimensionExtent({\n                values: lineColor,\n                range: [cOpts.min, cOpts.max],\n                _length: trace._length\n            })\n        )),\n        blockLineCount: c.blockLineCount,\n        canvasOverdrag: c.overdrag * c.canvasPixelRatio\n    });\n\n    var groupWidth = Math.floor(width * (domain.x[1] - domain.x[0]));\n    var groupHeight = Math.floor(layout.height * (domain.y[1] - domain.y[0]));\n\n    var pad = layout.margin || {l: 80, r: 80, t: 100, b: 80};\n    var rowContentWidth = groupWidth;\n    var rowHeight = groupHeight;\n\n    return {\n        key: i,\n        colCount: dimensions.filter(helpers.isVisible).length,\n        dimensions: dimensions,\n        tickDistance: c.tickDistance,\n        unitToColor: unitToColorScale(cscale),\n        lines: lines,\n        deselectedLines: deselectedLines,\n        labelAngle: labelAngle,\n        labelSide: labelSide,\n        labelFont: labelFont,\n        tickFont: tickFont,\n        rangeFont: rangeFont,\n        layoutWidth: width,\n        layoutHeight: layout.height,\n        domain: domain,\n        translateX: domain.x[0] * width,\n        translateY: layout.height - domain.y[1] * layout.height,\n        pad: pad,\n        canvasWidth: rowContentWidth * c.canvasPixelRatio + 2 * lines.canvasOverdrag,\n        canvasHeight: rowHeight * c.canvasPixelRatio,\n        width: rowContentWidth,\n        height: rowHeight,\n        canvasPixelRatio: c.canvasPixelRatio\n    };\n}\n\nfunction viewModel(state, callbacks, model) {\n    var width = model.width;\n    var height = model.height;\n    var dimensions = model.dimensions;\n    var canvasPixelRatio = model.canvasPixelRatio;\n\n    var xScale = function(d) {return width * d / Math.max(1, model.colCount - 1);};\n\n    var unitPad = c.verticalPadding / height;\n    var _unitToPaddedPx = unitToPaddedPx(height, c.verticalPadding);\n\n    var vm = {\n        key: model.key,\n        xScale: xScale,\n        model: model,\n        inBrushDrag: false // consider factoring it out and putting it in a centralized global-ish gesture state object\n    };\n\n    var uniqueKeys = {};\n\n    vm.dimensions = dimensions.filter(helpers.isVisible).map(function(dimension, i) {\n        var domainToPaddedUnit = domainToPaddedUnitScale(dimension, unitPad);\n        var foundKey = uniqueKeys[dimension.label];\n        uniqueKeys[dimension.label] = (foundKey || 0) + 1;\n        var key = dimension.label + (foundKey ? '__' + foundKey : '');\n        var specifiedConstraint = dimension.constraintrange;\n        var filterRangeSpecified = specifiedConstraint && specifiedConstraint.length;\n        if(filterRangeSpecified && !Array.isArray(specifiedConstraint[0])) {\n            specifiedConstraint = [specifiedConstraint];\n        }\n        var filterRange = filterRangeSpecified ?\n            specifiedConstraint.map(function(d) { return d.map(domainToPaddedUnit); }) :\n            [[-Infinity, Infinity]];\n        var brushMove = function() {\n            var p = vm;\n            p.focusLayer && p.focusLayer.render(p.panels, true);\n            var filtersActive = someFiltersActive(p);\n            if(!state.contextShown() && filtersActive) {\n                p.contextLayer && p.contextLayer.render(p.panels, true);\n                state.contextShown(true);\n            } else if(state.contextShown() && !filtersActive) {\n                p.contextLayer && p.contextLayer.render(p.panels, true, true);\n                state.contextShown(false);\n            }\n        };\n\n        var truncatedValues = dimension.values;\n        if(truncatedValues.length > dimension._length) {\n            truncatedValues = truncatedValues.slice(0, dimension._length);\n        }\n\n        var tickvals = dimension.tickvals;\n        var ticktext;\n        function makeTickItem(v, i) { return {val: v, text: ticktext[i]}; }\n        function sortTickItem(a, b) { return a.val - b.val; }\n        if(Array.isArray(tickvals) && tickvals.length) {\n            ticktext = dimension.ticktext;\n\n            // ensure ticktext and tickvals have same length\n            if(!Array.isArray(ticktext) || !ticktext.length) {\n                ticktext = tickvals.map(d3.format(dimension.tickformat));\n            } else if(ticktext.length > tickvals.length) {\n                ticktext = ticktext.slice(0, tickvals.length);\n            } else if(tickvals.length > ticktext.length) {\n                tickvals = tickvals.slice(0, ticktext.length);\n            }\n\n            // check if we need to sort tickvals/ticktext\n            for(var j = 1; j < tickvals.length; j++) {\n                if(tickvals[j] < tickvals[j - 1]) {\n                    var tickItems = tickvals.map(makeTickItem).sort(sortTickItem);\n                    for(var k = 0; k < tickvals.length; k++) {\n                        tickvals[k] = tickItems[k].val;\n                        ticktext[k] = tickItems[k].text;\n                    }\n                    break;\n                }\n            }\n        } else tickvals = undefined;\n\n        truncatedValues = helpers.convertTypedArray(truncatedValues);\n        truncatedValues = helpers.convertTypedArray(truncatedValues);\n\n        return {\n            key: key,\n            label: dimension.label,\n            tickFormat: dimension.tickformat,\n            tickvals: tickvals,\n            ticktext: ticktext,\n            ordinal: helpers.isOrdinal(dimension),\n            multiselect: dimension.multiselect,\n            xIndex: i,\n            crossfilterDimensionIndex: i,\n            visibleIndex: dimension._index,\n            height: height,\n            values: truncatedValues,\n            paddedUnitValues: truncatedValues.map(domainToPaddedUnit),\n            unitTickvals: tickvals && tickvals.map(domainToPaddedUnit),\n            xScale: xScale,\n            x: xScale(i),\n            canvasX: xScale(i) * canvasPixelRatio,\n            unitToPaddedPx: _unitToPaddedPx,\n            domainScale: domainScale(height, c.verticalPadding, dimension, tickvals, ticktext),\n            ordinalScale: ordinalScale(dimension),\n            parent: vm,\n            model: model,\n            brush: brush.makeBrush(\n                state,\n                filterRangeSpecified,\n                filterRange,\n                function() {\n                    state.linePickActive(false);\n                },\n                brushMove,\n                function(f) {\n                    vm.focusLayer.render(vm.panels, true);\n                    vm.pickLayer && vm.pickLayer.render(vm.panels, true);\n                    state.linePickActive(true);\n                    if(callbacks && callbacks.filterChanged) {\n                        var invScale = domainToPaddedUnit.invert;\n\n                        // update gd.data as if a Plotly.restyle were fired\n                        var newRanges = f.map(function(r) {\n                            return r.map(invScale).sort(Lib.sorterAsc);\n                        }).sort(function(a, b) { return a[0] - b[0]; });\n                        callbacks.filterChanged(vm.key, dimension._index, newRanges);\n                    }\n                }\n            )\n        };\n    });\n\n    return vm;\n}\n\nfunction styleExtentTexts(selection) {\n    selection\n        .classed(c.cn.axisExtentText, true)\n        .attr('text-anchor', 'middle')\n        .style('cursor', 'default')\n        .style('user-select', 'none');\n}\n\nfunction parcoordsInteractionState() {\n    var linePickActive = true;\n    var contextShown = false;\n    return {\n        linePickActive: function(val) {return arguments.length ? linePickActive = !!val : linePickActive;},\n        contextShown: function(val) {return arguments.length ? contextShown = !!val : contextShown;}\n    };\n}\n\nfunction calcTilt(angle, position) {\n    var dir = (position === 'top') ? 1 : -1;\n    var radians = angle * Math.PI / 180;\n    var dx = Math.sin(radians);\n    var dy = Math.cos(radians);\n    return {\n        dir: dir,\n        dx: dx,\n        dy: dy,\n        degrees: angle\n    };\n}\n\nfunction updatePanelLayout(yAxis, vm) {\n    var panels = vm.panels || (vm.panels = []);\n    var data = yAxis.data();\n    for(var i = 0; i < data.length - 1; i++) {\n        var p = panels[i] || (panels[i] = {});\n        var dim0 = data[i];\n        var dim1 = data[i + 1];\n        p.dim0 = dim0;\n        p.dim1 = dim1;\n        p.canvasX = dim0.canvasX;\n        p.panelSizeX = dim1.canvasX - dim0.canvasX;\n        p.panelSizeY = vm.model.canvasHeight;\n        p.y = 0;\n        p.canvasY = 0;\n    }\n}\n\nfunction calcAllTicks(cd) {\n    for(var i = 0; i < cd.length; i++) {\n        for(var j = 0; j < cd[i].length; j++) {\n            var trace = cd[i][j].trace;\n            var dimensions = trace.dimensions;\n\n            for(var k = 0; k < dimensions.length; k++) {\n                var values = dimensions[k].values;\n                var dim = dimensions[k]._ax;\n\n                if(dim) {\n                    if(!dim.range) dim.range = findExtremes(values, trace._length);\n                    if(!dim.dtick) dim.dtick = 0.01 * (Math.abs(dim.range[1] - dim.range[0]) || 1);\n\n                    dim.tickformat = dimensions[k].tickformat;\n                    Axes.calcTicks(dim);\n                    dim.cleanRange();\n                }\n            }\n        }\n    }\n}\n\nfunction linearFormat(dim, v) {\n    return Axes.tickText(dim._ax, v, false).text;\n}\n\nfunction extremeText(d, isTop) {\n    if(d.ordinal) return '';\n    var domain = d.domainScale.domain();\n    var v = (domain[isTop ? domain.length - 1 : 0]);\n\n    return linearFormat(d.model.dimensions[d.visibleIndex], v);\n}\n\n\nmodule.exports = function parcoords(gd, cdModule, layout, callbacks) {\n    var fullLayout = gd._fullLayout;\n    var svg = fullLayout._toppaper;\n    var glContainer = fullLayout._glcontainer;\n\n    calcAllTicks(cdModule);\n\n    var state = parcoordsInteractionState();\n\n    var vm = cdModule\n        .filter(function(d) { return unwrap(d).trace.visible; })\n        .map(model.bind(0, layout))\n        .map(viewModel.bind(0, state, callbacks));\n\n    glContainer.each(function(d, i) {\n        return Lib.extendFlat(d, vm[i]);\n    });\n\n    var glLayers = glContainer.selectAll('.gl-canvas')\n        .each(function(d) {\n            // FIXME: figure out how to handle multiple instances\n            d.viewModel = vm[0];\n            d.model = d.viewModel ? d.viewModel.model : null;\n        });\n\n    var lastHovered = null;\n\n    var pickLayer = glLayers.filter(function(d) {return d.pick;});\n\n    // emit hover / unhover event\n    pickLayer\n        .style('pointer-events', 'auto')\n        .on('mousemove', function(d) {\n            if(state.linePickActive() && d.lineLayer && callbacks && callbacks.hover) {\n                var event = d3.event;\n                var cw = this.width;\n                var ch = this.height;\n                var pointer = d3.mouse(this);\n                var x = pointer[0];\n                var y = pointer[1];\n\n                if(x < 0 || y < 0 || x >= cw || y >= ch) {\n                    return;\n                }\n                var pixel = d.lineLayer.readPixel(x, ch - 1 - y);\n                var found = pixel[3] !== 0;\n                // inverse of the calcPickColor in `lines.js`; detailed comment there\n                var curveNumber = found ? pixel[2] + 256 * (pixel[1] + 256 * pixel[0]) : null;\n                var eventData = {\n                    x: x,\n                    y: y,\n                    clientX: event.clientX,\n                    clientY: event.clientY,\n                    dataIndex: d.model.key,\n                    curveNumber: curveNumber\n                };\n                if(curveNumber !== lastHovered) { // don't unnecessarily repeat the same hit (or miss)\n                    if(found) {\n                        callbacks.hover(eventData);\n                    } else if(callbacks.unhover) {\n                        callbacks.unhover(eventData);\n                    }\n                    lastHovered = curveNumber;\n                }\n            }\n        });\n\n    glLayers\n        .style('opacity', function(d) {return d.pick ? 0 : 1;});\n\n    svg.style('background', 'rgba(255, 255, 255, 0)');\n    var controlOverlay = svg.selectAll('.' + c.cn.parcoords)\n        .data(vm, keyFun);\n\n    controlOverlay.exit().remove();\n\n    controlOverlay.enter()\n        .append('g')\n        .classed(c.cn.parcoords, true)\n        .style('shape-rendering', 'crispEdges')\n        .style('pointer-events', 'none');\n\n    controlOverlay.attr('transform', function(d) {\n        return 'translate(' + d.model.translateX + ',' + d.model.translateY + ')';\n    });\n\n    var parcoordsControlView = controlOverlay.selectAll('.' + c.cn.parcoordsControlView)\n        .data(repeat, keyFun);\n\n    parcoordsControlView.enter()\n        .append('g')\n        .classed(c.cn.parcoordsControlView, true);\n\n    parcoordsControlView.attr('transform', function(d) {\n        return 'translate(' + d.model.pad.l + ',' + d.model.pad.t + ')';\n    });\n\n    var yAxis = parcoordsControlView.selectAll('.' + c.cn.yAxis)\n        .data(function(p) { return p.dimensions; }, keyFun);\n\n    yAxis.enter()\n        .append('g')\n        .classed(c.cn.yAxis, true);\n\n    parcoordsControlView.each(function(p) {\n        updatePanelLayout(yAxis, p);\n    });\n\n    glLayers\n        .each(function(d) {\n            if(d.viewModel) {\n                if(!d.lineLayer || callbacks) { // recreate in case of having callbacks e.g. restyle. Should we test for callback to be a restyle?\n                    d.lineLayer = lineLayerMaker(this, d);\n                } else d.lineLayer.update(d);\n\n                if(d.key || d.key === 0) d.viewModel[d.key] = d.lineLayer;\n\n                var setChanged = (!d.context || // don't update background\n                                  callbacks);   // unless there is a callback on the context layer. Should we test the callback?\n\n                d.lineLayer.render(d.viewModel.panels, setChanged);\n            }\n        });\n\n    yAxis.attr('transform', function(d) {\n        return 'translate(' + d.xScale(d.xIndex) + ', 0)';\n    });\n\n    // drag column for reordering columns\n    yAxis.call(d3.behavior.drag()\n        .origin(function(d) { return d; })\n        .on('drag', function(d) {\n            var p = d.parent;\n            state.linePickActive(false);\n            d.x = Math.max(-c.overdrag, Math.min(d.model.width + c.overdrag, d3.event.x));\n            d.canvasX = d.x * d.model.canvasPixelRatio;\n            yAxis\n                .sort(function(a, b) { return a.x - b.x; })\n                .each(function(e, i) {\n                    e.xIndex = i;\n                    e.x = d === e ? e.x : e.xScale(e.xIndex);\n                    e.canvasX = e.x * e.model.canvasPixelRatio;\n                });\n\n            updatePanelLayout(yAxis, p);\n\n            yAxis.filter(function(e) { return Math.abs(d.xIndex - e.xIndex) !== 0; })\n                .attr('transform', function(d) { return 'translate(' + d.xScale(d.xIndex) + ', 0)'; });\n            d3.select(this).attr('transform', 'translate(' + d.x + ', 0)');\n            yAxis.each(function(e, i0, i1) { if(i1 === d.parent.key) p.dimensions[i0] = e; });\n            p.contextLayer && p.contextLayer.render(p.panels, false, !someFiltersActive(p));\n            p.focusLayer.render && p.focusLayer.render(p.panels);\n        })\n        .on('dragend', function(d) {\n            var p = d.parent;\n            d.x = d.xScale(d.xIndex);\n            d.canvasX = d.x * d.model.canvasPixelRatio;\n            updatePanelLayout(yAxis, p);\n            d3.select(this)\n                .attr('transform', function(d) { return 'translate(' + d.x + ', 0)'; });\n            p.contextLayer && p.contextLayer.render(p.panels, false, !someFiltersActive(p));\n            p.focusLayer && p.focusLayer.render(p.panels);\n            p.pickLayer && p.pickLayer.render(p.panels, true);\n            state.linePickActive(true);\n\n            if(callbacks && callbacks.axesMoved) {\n                callbacks.axesMoved(p.key, p.dimensions.map(function(e) {return e.crossfilterDimensionIndex;}));\n            }\n        })\n    );\n\n    yAxis.exit()\n        .remove();\n\n    var axisOverlays = yAxis.selectAll('.' + c.cn.axisOverlays)\n        .data(repeat, keyFun);\n\n    axisOverlays.enter()\n        .append('g')\n        .classed(c.cn.axisOverlays, true);\n\n    axisOverlays.selectAll('.' + c.cn.axis).remove();\n\n    var axis = axisOverlays.selectAll('.' + c.cn.axis)\n        .data(repeat, keyFun);\n\n    axis.enter()\n        .append('g')\n        .classed(c.cn.axis, true);\n\n    axis\n        .each(function(d) {\n            var wantedTickCount = d.model.height / d.model.tickDistance;\n            var scale = d.domainScale;\n            var sdom = scale.domain();\n            d3.select(this)\n                .call(d3.svg.axis()\n                    .orient('left')\n                    .tickSize(4)\n                    .outerTickSize(2)\n                    .ticks(wantedTickCount, d.tickFormat) // works for continuous scales only...\n                    .tickValues(d.ordinal ? // and this works for ordinal scales\n                        sdom :\n                        null)\n                    .tickFormat(function(v) {\n                        return helpers.isOrdinal(d) ? v : linearFormat(d.model.dimensions[d.visibleIndex], v);\n                    })\n                    .scale(scale));\n            Drawing.font(axis.selectAll('text'), d.model.tickFont);\n        });\n\n    axis.selectAll('.domain, .tick>line')\n        .attr('fill', 'none')\n        .attr('stroke', 'black')\n        .attr('stroke-opacity', 0.25)\n        .attr('stroke-width', '1px');\n\n    axis.selectAll('text')\n        .style('text-shadow', '1px 1px 1px #fff, -1px -1px 1px #fff, 1px -1px 1px #fff, -1px 1px 1px #fff')\n        .style('cursor', 'default')\n        .style('user-select', 'none');\n\n    var axisHeading = axisOverlays.selectAll('.' + c.cn.axisHeading)\n        .data(repeat, keyFun);\n\n    axisHeading.enter()\n        .append('g')\n        .classed(c.cn.axisHeading, true);\n\n    var axisTitle = axisHeading.selectAll('.' + c.cn.axisTitle)\n        .data(repeat, keyFun);\n\n    axisTitle.enter()\n        .append('text')\n        .classed(c.cn.axisTitle, true)\n        .attr('text-anchor', 'middle')\n        .style('cursor', 'ew-resize')\n        .style('user-select', 'none')\n        .style('pointer-events', 'auto');\n\n    axisTitle\n        .text(function(d) { return d.label; })\n        .each(function(d) {\n            var e = d3.select(this);\n            Drawing.font(e, d.model.labelFont);\n            svgTextUtils.convertToTspans(e, gd);\n        })\n        .attr('transform', function(d) {\n            var tilt = calcTilt(d.model.labelAngle, d.model.labelSide);\n            var r = c.axisTitleOffset;\n            return (\n                (tilt.dir > 0 ? '' : 'translate(0,' + (2 * r + d.model.height) + ')') +\n                'rotate(' + tilt.degrees + ')' +\n                'translate(' + (-r * tilt.dx) + ',' + (-r * tilt.dy) + ')'\n            );\n        })\n        .attr('text-anchor', function(d) {\n            var tilt = calcTilt(d.model.labelAngle, d.model.labelSide);\n            var adx = Math.abs(tilt.dx);\n            var ady = Math.abs(tilt.dy);\n\n            if(2 * adx > ady) {\n                return (tilt.dir * tilt.dx < 0) ? 'start' : 'end';\n            } else {\n                return 'middle';\n            }\n        });\n\n    var axisExtent = axisOverlays.selectAll('.' + c.cn.axisExtent)\n        .data(repeat, keyFun);\n\n    axisExtent.enter()\n        .append('g')\n        .classed(c.cn.axisExtent, true);\n\n    var axisExtentTop = axisExtent.selectAll('.' + c.cn.axisExtentTop)\n        .data(repeat, keyFun);\n\n    axisExtentTop.enter()\n        .append('g')\n        .classed(c.cn.axisExtentTop, true);\n\n    axisExtentTop\n        .attr('transform', 'translate(' + 0 + ',' + -c.axisExtentOffset + ')');\n\n    var axisExtentTopText = axisExtentTop.selectAll('.' + c.cn.axisExtentTopText)\n        .data(repeat, keyFun);\n\n    axisExtentTopText.enter()\n        .append('text')\n        .classed(c.cn.axisExtentTopText, true)\n        .call(styleExtentTexts);\n\n    axisExtentTopText\n        .text(function(d) { return extremeText(d, true); })\n        .each(function(d) { Drawing.font(d3.select(this), d.model.rangeFont); });\n\n    var axisExtentBottom = axisExtent.selectAll('.' + c.cn.axisExtentBottom)\n        .data(repeat, keyFun);\n\n    axisExtentBottom.enter()\n        .append('g')\n        .classed(c.cn.axisExtentBottom, true);\n\n    axisExtentBottom\n        .attr('transform', function(d) {\n            return 'translate(' + 0 + ',' + (d.model.height + c.axisExtentOffset) + ')';\n        });\n\n    var axisExtentBottomText = axisExtentBottom.selectAll('.' + c.cn.axisExtentBottomText)\n        .data(repeat, keyFun);\n\n    axisExtentBottomText.enter()\n        .append('text')\n        .classed(c.cn.axisExtentBottomText, true)\n        .attr('dy', '0.75em')\n        .call(styleExtentTexts);\n\n    axisExtentBottomText\n        .text(function(d) { return extremeText(d, false); })\n        .each(function(d) { Drawing.font(d3.select(this), d.model.rangeFont); });\n\n    brush.ensureAxisBrush(axisOverlays);\n};\n\n},{\"../../components/colorscale\":605,\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/gup\":717,\"../../lib/svg_text_utils\":743,\"../../plots/cartesian/axes\":767,\"./axisbrush\":1075,\"./constants\":1078,\"./helpers\":1080,\"./lines\":1082,\"color-rgba\":122,\"d3\":163}],1085:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar parcoords = _dereq_('./parcoords');\nvar prepareRegl = _dereq_('../../lib/prepare_regl');\nvar isVisible = _dereq_('./helpers').isVisible;\n\nfunction newIndex(visibleIndices, orig, dim) {\n    var origIndex = orig.indexOf(dim);\n    var currentIndex = visibleIndices.indexOf(origIndex);\n    if(currentIndex === -1) {\n        // invisible dimensions initially go to the end\n        currentIndex += orig.length;\n    }\n    return currentIndex;\n}\n\nfunction sorter(visibleIndices, orig) {\n    return function sorter(d1, d2) {\n        return (\n            newIndex(visibleIndices, orig, d1) -\n            newIndex(visibleIndices, orig, d2)\n        );\n    };\n}\n\nmodule.exports = function plot(gd, cdModule) {\n    var fullLayout = gd._fullLayout;\n\n    var success = prepareRegl(gd);\n    if(!success) return;\n\n    var currentDims = {};\n    var initialDims = {};\n    var fullIndices = {};\n    var inputIndices = {};\n\n    var size = fullLayout._size;\n\n    cdModule.forEach(function(d, i) {\n        var trace = d[0].trace;\n        fullIndices[i] = trace.index;\n        var iIn = inputIndices[i] = trace._fullInput.index;\n        currentDims[i] = gd.data[iIn].dimensions;\n        initialDims[i] = gd.data[iIn].dimensions.slice();\n    });\n\n    var filterChanged = function(i, initialDimIndex, newRanges) {\n        // Have updated `constraintrange` data on `gd.data` and raise `Plotly.restyle` event\n        // without having to incur heavy UI blocking due to an actual `Plotly.restyle` call\n\n        var dim = initialDims[i][initialDimIndex];\n        var newConstraints = newRanges.map(function(r) { return r.slice(); });\n\n        // Store constraint range in preGUI\n        // This one doesn't work if it's stored in pieces in _storeDirectGUIEdit\n        // because it's an array of variable dimensionality. So store the whole\n        // thing at once manually.\n        var aStr = 'dimensions[' + initialDimIndex + '].constraintrange';\n        var preGUI = fullLayout._tracePreGUI[gd._fullData[fullIndices[i]]._fullInput.uid];\n        if(preGUI[aStr] === undefined) {\n            var initialVal = dim.constraintrange;\n            preGUI[aStr] = initialVal || null;\n        }\n\n        var fullDimension = gd._fullData[fullIndices[i]].dimensions[initialDimIndex];\n\n        if(!newConstraints.length) {\n            delete dim.constraintrange;\n            delete fullDimension.constraintrange;\n            newConstraints = null;\n        } else {\n            if(newConstraints.length === 1) newConstraints = newConstraints[0];\n            dim.constraintrange = newConstraints;\n            fullDimension.constraintrange = newConstraints.slice();\n            // wrap in another array for restyle event data\n            newConstraints = [newConstraints];\n        }\n\n        var restyleData = {};\n        restyleData[aStr] = newConstraints;\n        gd.emit('plotly_restyle', [restyleData, [inputIndices[i]]]);\n    };\n\n    var hover = function(eventData) {\n        gd.emit('plotly_hover', eventData);\n    };\n\n    var unhover = function(eventData) {\n        gd.emit('plotly_unhover', eventData);\n    };\n\n    var axesMoved = function(i, visibleIndices) {\n        // Have updated order data on `gd.data` and raise `Plotly.restyle` event\n        // without having to incur heavy UI blocking due to an actual `Plotly.restyle` call\n\n        // drag&drop sorting of the visible dimensions\n        var orig = sorter(visibleIndices, initialDims[i].filter(isVisible));\n        currentDims[i].sort(orig);\n\n        // invisible dimensions are not interpreted in the context of drag&drop sorting as an invisible dimension\n        // cannot be dragged; they're interspersed into their original positions by this subsequent merging step\n        initialDims[i].filter(function(d) {return !isVisible(d);})\n             .sort(function(d) {\n                 // subsequent splicing to be done left to right, otherwise indices may be incorrect\n                 return initialDims[i].indexOf(d);\n             })\n            .forEach(function(d) {\n                currentDims[i].splice(currentDims[i].indexOf(d), 1); // remove from the end\n                currentDims[i].splice(initialDims[i].indexOf(d), 0, d); // insert at original index\n            });\n\n        // TODO: we can't really store this part of the interaction state\n        // directly as below, since it incudes data arrays. If we want to\n        // persist column order we may have to do something special for this\n        // case to just store the order itself.\n        // Registry.call('_storeDirectGUIEdit',\n        //     gd.data[inputIndices[i]],\n        //     fullLayout._tracePreGUI[gd._fullData[fullIndices[i]]._fullInput.uid],\n        //     {dimensions: currentDims[i]}\n        // );\n\n        gd.emit('plotly_restyle', [{dimensions: [currentDims[i]]}, [inputIndices[i]]]);\n    };\n\n    parcoords(\n        gd,\n        cdModule,\n        { // layout\n            width: size.w,\n            height: size.h,\n            margin: {\n                t: size.t,\n                r: size.r,\n                b: size.b,\n                l: size.l\n            }\n        },\n        { // callbacks\n            filterChanged: filterChanged,\n            hover: hover,\n            unhover: unhover,\n            axesMoved: axesMoved\n        }\n    );\n};\n\n},{\"../../lib/prepare_regl\":732,\"./helpers\":1080,\"./parcoords\":1084}],1086:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar textFontAttrs = fontAttrs({\n    editType: 'plot',\n    arrayOk: true,\n    colorEditType: 'plot',\n    \n});\n\nmodule.exports = {\n    labels: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    // equivalent of x0 and dx, if label is missing\n    label0: {\n        valType: 'number',\n        \n        dflt: 0,\n        editType: 'calc',\n        \n    },\n    dlabel: {\n        valType: 'number',\n        \n        dflt: 1,\n        editType: 'calc',\n        \n    },\n\n    values: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    marker: {\n        colors: {\n            valType: 'data_array',  // TODO 'color_array' ?\n            editType: 'calc',\n            \n        },\n\n        line: {\n            color: {\n                valType: 'color',\n                \n                dflt: colorAttrs.defaultLine,\n                arrayOk: true,\n                editType: 'style',\n                \n            },\n            width: {\n                valType: 'number',\n                \n                min: 0,\n                dflt: 0,\n                arrayOk: true,\n                editType: 'style',\n                \n            },\n            editType: 'calc'\n        },\n        editType: 'calc'\n    },\n\n    text: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'style',\n        \n    },\n\n// 'see eg:'\n// 'https://www.e-education.psu.edu/natureofgeoinfo/sites/www.e-education.psu.edu.natureofgeoinfo/files/image/hisp_pies.gif',\n// '(this example involves a map too - may someday be a whole trace type',\n// 'of its own. but the point is the size of the whole pie is important.)'\n    scalegroup: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'calc',\n        \n    },\n\n    // labels (legend is handled by plots.attributes.showlegend and layout.hiddenlabels)\n    textinfo: {\n        valType: 'flaglist',\n        \n        flags: ['label', 'text', 'value', 'percent'],\n        extras: ['none'],\n        editType: 'calc',\n        \n    },\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['label', 'text', 'value', 'percent', 'name']\n    }),\n    hovertemplate: hovertemplateAttrs({}, {\n        keys: ['label', 'color', 'value', 'percent', 'text']\n    }),\n    textposition: {\n        valType: 'enumerated',\n        \n        values: ['inside', 'outside', 'auto', 'none'],\n        dflt: 'auto',\n        arrayOk: true,\n        editType: 'plot',\n        \n    },\n    textfont: extendFlat({}, textFontAttrs, {\n        \n    }),\n    insidetextfont: extendFlat({}, textFontAttrs, {\n        \n    }),\n    outsidetextfont: extendFlat({}, textFontAttrs, {\n        \n    }),\n\n    title: {\n        text: {\n            valType: 'string',\n            dflt: '',\n            \n            editType: 'plot',\n            \n        },\n        font: extendFlat({}, textFontAttrs, {\n            \n        }),\n        position: {\n            valType: 'enumerated',\n            values: [\n                'top left', 'top center', 'top right',\n                'middle center',\n                'bottom left', 'bottom center', 'bottom right'\n            ],\n            \n            editType: 'plot',\n            \n        },\n\n        editType: 'plot'\n    },\n\n    // position and shape\n    domain: domainAttrs({name: 'pie', trace: true, editType: 'calc'}),\n\n    hole: {\n        valType: 'number',\n        \n        min: 0,\n        max: 1,\n        dflt: 0,\n        editType: 'calc',\n        \n    },\n\n    // ordering and direction\n    sort: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'calc',\n        \n    },\n    direction: {\n        /**\n         * there are two common conventions, both of which place the first\n         * (largest, if sorted) slice with its left edge at 12 o'clock but\n         * succeeding slices follow either cw or ccw from there.\n         *\n         * see http://visage.co/data-visualization-101-pie-charts/\n         */\n        valType: 'enumerated',\n        values: ['clockwise', 'counterclockwise'],\n        \n        dflt: 'counterclockwise',\n        editType: 'calc',\n        \n    },\n    rotation: {\n        valType: 'number',\n        \n        min: -360,\n        max: 360,\n        dflt: 0,\n        editType: 'calc',\n        \n    },\n\n    pull: {\n        valType: 'number',\n        \n        min: 0,\n        max: 1,\n        dflt: 0,\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n\n    _deprecated: {\n        title: {\n            valType: 'string',\n            dflt: '',\n            \n            editType: 'calc',\n            \n        },\n        titlefont: extendFlat({}, textFontAttrs, {\n            \n        }),\n        titleposition: {\n            valType: 'enumerated',\n            values: [\n                'top left', 'top center', 'top right',\n                'middle center',\n                'bottom left', 'bottom center', 'bottom right'\n            ],\n            \n            editType: 'calc',\n            \n        }\n    }\n};\n\n},{\"../../components/color/attributes\":592,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../../plots/domain\":792,\"../../plots/font_attributes\":793}],1087:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\n\nexports.name = 'pie';\n\nexports.plot = function(gd) {\n    var Pie = Registry.getModule('pie');\n    var cdPie = getModuleCalcData(gd.calcdata, Pie)[0];\n    Pie.plot(gd, cdPie);\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var hadPie = (oldFullLayout._has && oldFullLayout._has('pie'));\n    var hasPie = (newFullLayout._has && newFullLayout._has('pie'));\n\n    if(hadPie && !hasPie) {\n        oldFullLayout._pielayer.selectAll('g.trace').remove();\n    }\n};\n\n},{\"../../plots/get_data\":802,\"../../registry\":847}],1088:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\nvar tinycolor = _dereq_('tinycolor2');\n\nvar Color = _dereq_('../../components/color');\nvar helpers = _dereq_('./helpers');\nvar isValidTextValue = _dereq_('../../lib').isValidTextValue;\n\nvar extendedColorWayList = {};\n\nfunction calc(gd, trace) {\n    var cd = [];\n\n    var fullLayout = gd._fullLayout;\n    var hiddenLabels = fullLayout.hiddenlabels || [];\n\n    var labels = trace.labels;\n    var colors = trace.marker.colors || [];\n    var vals = trace.values;\n    var hasVals = isArrayOrTypedArray(vals) && vals.length;\n\n    var i, pt;\n\n    if(trace.dlabel) {\n        labels = new Array(vals.length);\n        for(i = 0; i < vals.length; i++) {\n            labels[i] = String(trace.label0 + i * trace.dlabel);\n        }\n    }\n\n    var allThisTraceLabels = {};\n    var pullColor = makePullColorFn(fullLayout['_' + trace.type + 'colormap']);\n    var seriesLen = (hasVals ? vals : labels).length;\n    var vTotal = 0;\n    var isAggregated = false;\n\n    for(i = 0; i < seriesLen; i++) {\n        var v, label, hidden;\n        if(hasVals) {\n            v = vals[i];\n            if(!isNumeric(v)) continue;\n            v = +v;\n            if(v < 0) continue;\n        } else v = 1;\n\n        label = labels[i];\n        if(label === undefined || label === '') label = i;\n        label = String(label);\n\n        var thisLabelIndex = allThisTraceLabels[label];\n        if(thisLabelIndex === undefined) {\n            allThisTraceLabels[label] = cd.length;\n\n            hidden = hiddenLabels.indexOf(label) !== -1;\n\n            if(!hidden) vTotal += v;\n\n            cd.push({\n                v: v,\n                label: label,\n                color: pullColor(colors[i], label),\n                i: i,\n                pts: [i],\n                hidden: hidden\n            });\n        } else {\n            isAggregated = true;\n\n            pt = cd[thisLabelIndex];\n            pt.v += v;\n            pt.pts.push(i);\n            if(!pt.hidden) vTotal += v;\n\n            if(pt.color === false && colors[i]) {\n                pt.color = pullColor(colors[i], label);\n            }\n        }\n    }\n\n    var shouldSort = (trace.type === 'funnelarea') ? isAggregated : trace.sort;\n    if(shouldSort) cd.sort(function(a, b) { return b.v - a.v; });\n\n    // include the sum of all values in the first point\n    if(cd[0]) cd[0].vTotal = vTotal;\n\n    // now insert text\n    var textinfo = trace.textinfo;\n    if(textinfo && textinfo !== 'none') {\n        var parts = textinfo.split('+');\n        var hasFlag = function(flag) { return parts.indexOf(flag) !== -1; };\n        var hasLabel = hasFlag('label');\n        var hasText = hasFlag('text');\n        var hasValue = hasFlag('value');\n        var hasPercent = hasFlag('percent');\n\n        var separators = fullLayout.separators;\n        var text;\n\n        for(i = 0; i < cd.length; i++) {\n            pt = cd[i];\n            text = hasLabel ? [pt.label] : [];\n            if(hasText) {\n                var tx = helpers.getFirstFilled(trace.text, pt.pts);\n                if(isValidTextValue(tx)) text.push(tx);\n            }\n            if(hasValue) text.push(helpers.formatPieValue(pt.v, separators));\n            if(hasPercent) text.push(helpers.formatPiePercent(pt.v / vTotal, separators));\n            pt.text = text.join('<br>');\n        }\n    }\n\n    return cd;\n}\n\nfunction makePullColorFn(colorMap) {\n    return function pullColor(color, id) {\n        if(!color) return false;\n\n        color = tinycolor(color);\n        if(!color.isValid()) return false;\n\n        color = Color.addOpacity(color, color.getAlpha());\n        if(!colorMap[id]) colorMap[id] = color;\n\n        return color;\n    };\n}\n\n/*\n * `calc` filled in (and collated) explicit colors.\n * Now we need to propagate these explicit colors to other traces,\n * and fill in default colors.\n * This is done after sorting, so we pick defaults\n * in the order slices will be displayed\n */\nfunction crossTraceCalc(gd, plotinfo) { // TODO: should we name the second argument opts?\n    var desiredType = (plotinfo || {}).type;\n    if(!desiredType) desiredType = 'pie';\n\n    var fullLayout = gd._fullLayout;\n    var calcdata = gd.calcdata;\n    var colorWay = fullLayout[desiredType + 'colorway'];\n    var colorMap = fullLayout['_' + desiredType + 'colormap'];\n\n    if(fullLayout['extend' + desiredType + 'colors']) {\n        colorWay = generateExtendedColors(colorWay, extendedColorWayList);\n    }\n    var dfltColorCount = 0;\n\n    for(var i = 0; i < calcdata.length; i++) {\n        var cd = calcdata[i];\n        var traceType = cd[0].trace.type;\n        if(traceType !== desiredType) continue;\n\n        for(var j = 0; j < cd.length; j++) {\n            var pt = cd[j];\n            if(pt.color === false) {\n                // have we seen this label and assigned a color to it in a previous trace?\n                if(colorMap[pt.label]) {\n                    pt.color = colorMap[pt.label];\n                } else {\n                    colorMap[pt.label] = pt.color = colorWay[dfltColorCount % colorWay.length];\n                    dfltColorCount++;\n                }\n            }\n        }\n    }\n}\n\n/**\n * pick a default color from the main default set, augmented by\n * itself lighter then darker before repeating\n */\nfunction generateExtendedColors(colorList, extendedColorWays) {\n    var i;\n    var colorString = JSON.stringify(colorList);\n    var colors = extendedColorWays[colorString];\n    if(!colors) {\n        colors = colorList.slice();\n\n        for(i = 0; i < colorList.length; i++) {\n            colors.push(tinycolor(colorList[i]).lighten(20).toHexString());\n        }\n\n        for(i = 0; i < colorList.length; i++) {\n            colors.push(tinycolor(colorList[i]).darken(20).toHexString());\n        }\n        extendedColorWays[colorString] = colors;\n    }\n\n    return colors;\n}\n\nmodule.exports = {\n    calc: calc,\n    crossTraceCalc: crossTraceCalc,\n\n    makePullColorFn: makePullColorFn,\n    generateExtendedColors: generateExtendedColors\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"./helpers\":1091,\"fast-isnumeric\":225,\"tinycolor2\":537}],1089:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attributes = _dereq_('./attributes');\nvar handleDomainDefaults = _dereq_('../../plots/domain').defaults;\nvar handleText = _dereq_('../bar/defaults').handleText;\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len;\n    var vals = coerce('values');\n    var hasVals = Lib.isArrayOrTypedArray(vals);\n    var labels = coerce('labels');\n    if(Array.isArray(labels)) {\n        len = labels.length;\n        if(hasVals) len = Math.min(len, vals.length);\n    } else if(hasVals) {\n        len = vals.length;\n\n        coerce('label0');\n        coerce('dlabel');\n    }\n\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n    traceOut._length = len;\n\n    var lineWidth = coerce('marker.line.width');\n    if(lineWidth) coerce('marker.line.color');\n\n    coerce('marker.colors');\n\n    coerce('scalegroup');\n    // TODO: hole needs to be coerced to the same value within a scaleegroup\n\n    var textData = coerce('text');\n    var textInfo = coerce('textinfo', Array.isArray(textData) ? 'text+percent' : 'percent');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    if(textInfo && textInfo !== 'none') {\n        var textposition = coerce('textposition');\n        handleText(traceIn, traceOut, layout, coerce, textposition, {\n            moduleHasSelected: false,\n            moduleHasUnselected: false,\n            moduleHasConstrain: false,\n            moduleHasCliponaxis: false,\n            moduleHasTextangle: false,\n            moduleHasInsideanchor: false\n        });\n    }\n\n    handleDomainDefaults(traceOut, layout, coerce);\n\n    var hole = coerce('hole');\n    var title = coerce('title.text');\n    if(title) {\n        var titlePosition = coerce('title.position', hole ? 'middle center' : 'top center');\n        if(!hole && titlePosition === 'middle center') traceOut.title.position = 'top center';\n        Lib.coerceFont(coerce, 'title.font', layout.font);\n    }\n\n    coerce('sort');\n    coerce('direction');\n    coerce('rotation');\n    coerce('pull');\n};\n\n},{\"../../lib\":719,\"../../plots/domain\":792,\"../bar/defaults\":861,\"./attributes\":1086}],1090:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar appendArrayMultiPointValues = _dereq_('../../components/fx/helpers').appendArrayMultiPointValues;\n\n// Note: like other eventData routines, this creates the data for hover/unhover/click events\n// but it has a different API and goes through a totally different pathway.\n// So to ensure it doesn't get misused, it's not attached to the Pie module.\nmodule.exports = function eventData(pt, trace) {\n    var out = {\n        curveNumber: trace.index,\n        pointNumbers: pt.pts,\n        data: trace._input,\n        fullData: trace,\n        label: pt.label,\n        color: pt.color,\n        value: pt.v,\n        percent: pt.percent,\n        text: pt.text,\n\n        // pt.v (and pt.i below) for backward compatibility\n        v: pt.v\n    };\n\n    // Only include pointNumber if it's unambiguous\n    if(pt.pts.length === 1) out.pointNumber = out.i = pt.pts[0];\n\n    // Add extra data arrays to the output\n    // notice that this is the multi-point version ('s' on the end!)\n    // so added data will be arrays matching the pointNumbers array.\n    appendArrayMultiPointValues(out, trace, pt.pts);\n\n    // don't include obsolete fields in new funnelarea traces\n    if(trace.type === 'funnelarea') {\n        delete out.v;\n        delete out.i;\n    }\n\n    return out;\n};\n\n},{\"../../components/fx/helpers\":628}],1091:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nexports.formatPiePercent = function formatPiePercent(v, separators) {\n    var vRounded = (v * 100).toPrecision(3);\n    if(vRounded.lastIndexOf('.') !== -1) {\n        vRounded = vRounded.replace(/[.]?0+$/, '');\n    }\n    return Lib.numSeparate(vRounded, separators) + '%';\n};\n\nexports.formatPieValue = function formatPieValue(v, separators) {\n    var vRounded = v.toPrecision(10);\n    if(vRounded.lastIndexOf('.') !== -1) {\n        vRounded = vRounded.replace(/[.]?0+$/, '');\n    }\n    return Lib.numSeparate(vRounded, separators);\n};\n\nexports.getFirstFilled = function getFirstFilled(array, indices) {\n    if(!Array.isArray(array)) return;\n    for(var i = 0; i < indices.length; i++) {\n        var v = array[indices[i]];\n        if(v || v === 0) return v;\n    }\n};\n\nexports.castOption = function castOption(item, indices) {\n    if(Array.isArray(item)) return exports.getFirstFilled(item, indices);\n    else if(item) return item;\n};\n\n},{\"../../lib\":719}],1092:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n\n    calc: _dereq_('./calc').calc,\n    crossTraceCalc: _dereq_('./calc').crossTraceCalc,\n\n    plot: _dereq_('./plot').plot,\n    style: _dereq_('./style'),\n    styleOne: _dereq_('./style_one'),\n\n    moduleType: 'trace',\n    name: 'pie',\n    basePlotModule: _dereq_('./base_plot'),\n    categories: ['pie-like', 'pie', 'showLegend'],\n    meta: {\n        \n    }\n};\n\n},{\"./attributes\":1086,\"./base_plot\":1087,\"./calc\":1088,\"./defaults\":1089,\"./layout_attributes\":1093,\"./layout_defaults\":1094,\"./plot\":1095,\"./style\":1096,\"./style_one\":1097}],1093:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    hiddenlabels: {\n        valType: 'data_array',\n        \n        editType: 'calc',\n        \n    },\n    piecolorway: {\n        valType: 'colorlist',\n        \n        editType: 'calc',\n        \n    },\n    extendpiecolors: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        \n    }\n};\n\n},{}],1094:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n\n    coerce('hiddenlabels');\n    coerce('piecolorway', layoutOut.colorway);\n    coerce('extendpiecolors');\n};\n\n},{\"../../lib\":719,\"./layout_attributes\":1093}],1095:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Fx = _dereq_('../../components/fx');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar Lib = _dereq_('../../lib');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\n\nvar helpers = _dereq_('./helpers');\nvar eventData = _dereq_('./event_data');\n\nfunction plot(gd, cdModule) {\n    var fullLayout = gd._fullLayout;\n\n    prerenderTitles(cdModule, gd);\n    layoutAreas(cdModule, fullLayout._size);\n\n    var plotGroups = Lib.makeTraceGroups(fullLayout._pielayer, cdModule, 'trace').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n\n        setCoords(cd);\n\n        // TODO: miter might look better but can sometimes cause problems\n        // maybe miter with a small-ish stroke-miterlimit?\n        plotGroup.attr('stroke-linejoin', 'round');\n\n        plotGroup.each(function() {\n            var slices = d3.select(this).selectAll('g.slice').data(cd);\n\n            slices.enter().append('g')\n                .classed('slice', true);\n            slices.exit().remove();\n\n            var quadrants = [\n                [[], []], // y<0: x<0, x>=0\n                [[], []] // y>=0: x<0, x>=0\n            ];\n            var hasOutsideText = false;\n\n            slices.each(function(pt) {\n                if(pt.hidden) {\n                    d3.select(this).selectAll('path,g').remove();\n                    return;\n                }\n\n                // to have consistent event data compared to other traces\n                pt.pointNumber = pt.i;\n                pt.curveNumber = trace.index;\n\n                quadrants[pt.pxmid[1] < 0 ? 0 : 1][pt.pxmid[0] < 0 ? 0 : 1].push(pt);\n\n                var cx = cd0.cx;\n                var cy = cd0.cy;\n                var sliceTop = d3.select(this);\n                var slicePath = sliceTop.selectAll('path.surface').data([pt]);\n\n                slicePath.enter().append('path')\n                    .classed('surface', true)\n                    .style({'pointer-events': 'all'});\n\n                sliceTop.call(attachFxHandlers, gd, cd);\n\n                if(trace.pull) {\n                    var pull = +helpers.castOption(trace.pull, pt.pts) || 0;\n                    if(pull > 0) {\n                        cx += pull * pt.pxmid[0];\n                        cy += pull * pt.pxmid[1];\n                    }\n                }\n\n                pt.cxFinal = cx;\n                pt.cyFinal = cy;\n\n                function arc(start, finish, cw, scale) {\n                    var dx = scale * (finish[0] - start[0]);\n                    var dy = scale * (finish[1] - start[1]);\n\n                    return 'a' +\n                        (scale * cd0.r) + ',' + (scale * cd0.r) + ' 0 ' +\n                        pt.largeArc + (cw ? ' 1 ' : ' 0 ') + dx + ',' + dy;\n                }\n\n                var hole = trace.hole;\n                if(pt.v === cd0.vTotal) { // 100% fails bcs arc start and end are identical\n                    var outerCircle = 'M' + (cx + pt.px0[0]) + ',' + (cy + pt.px0[1]) +\n                        arc(pt.px0, pt.pxmid, true, 1) +\n                        arc(pt.pxmid, pt.px0, true, 1) + 'Z';\n                    if(hole) {\n                        slicePath.attr('d',\n                            'M' + (cx + hole * pt.px0[0]) + ',' + (cy + hole * pt.px0[1]) +\n                            arc(pt.px0, pt.pxmid, false, hole) +\n                            arc(pt.pxmid, pt.px0, false, hole) +\n                            'Z' + outerCircle);\n                    } else slicePath.attr('d', outerCircle);\n                } else {\n                    var outerArc = arc(pt.px0, pt.px1, true, 1);\n\n                    if(hole) {\n                        var rim = 1 - hole;\n                        slicePath.attr('d',\n                            'M' + (cx + hole * pt.px1[0]) + ',' + (cy + hole * pt.px1[1]) +\n                            arc(pt.px1, pt.px0, false, hole) +\n                            'l' + (rim * pt.px0[0]) + ',' + (rim * pt.px0[1]) +\n                            outerArc +\n                            'Z');\n                    } else {\n                        slicePath.attr('d',\n                            'M' + cx + ',' + cy +\n                            'l' + pt.px0[0] + ',' + pt.px0[1] +\n                            outerArc +\n                            'Z');\n                    }\n                }\n\n                // add text\n                var textPosition = helpers.castOption(trace.textposition, pt.pts);\n                var sliceTextGroup = sliceTop.selectAll('g.slicetext')\n                    .data(pt.text && (textPosition !== 'none') ? [0] : []);\n\n                sliceTextGroup.enter().append('g')\n                    .classed('slicetext', true);\n                sliceTextGroup.exit().remove();\n\n                sliceTextGroup.each(function() {\n                    var sliceText = Lib.ensureSingle(d3.select(this), 'text', '', function(s) {\n                        // prohibit tex interpretation until we can handle\n                        // tex and regular text together\n                        s.attr('data-notex', 1);\n                    });\n\n                    sliceText.text(pt.text)\n                        .attr({\n                            'class': 'slicetext',\n                            transform: '',\n                            'text-anchor': 'middle'\n                        })\n                        .call(Drawing.font, textPosition === 'outside' ?\n                          determineOutsideTextFont(trace, pt, gd._fullLayout.font) :\n                          determineInsideTextFont(trace, pt, gd._fullLayout.font))\n                        .call(svgTextUtils.convertToTspans, gd);\n\n                    // position the text relative to the slice\n                    var textBB = Drawing.bBox(sliceText.node());\n                    var transform;\n\n                    if(textPosition === 'outside') {\n                        transform = transformOutsideText(textBB, pt);\n                    } else {\n                        transform = transformInsideText(textBB, pt, cd0);\n                        if(textPosition === 'auto' && transform.scale < 1) {\n                            sliceText.call(Drawing.font, trace.outsidetextfont);\n                            if(trace.outsidetextfont.family !== trace.insidetextfont.family ||\n                                    trace.outsidetextfont.size !== trace.insidetextfont.size) {\n                                textBB = Drawing.bBox(sliceText.node());\n                            }\n                            transform = transformOutsideText(textBB, pt);\n                        }\n                    }\n\n                    var translateX = cx + pt.pxmid[0] * transform.rCenter + (transform.x || 0);\n                    var translateY = cy + pt.pxmid[1] * transform.rCenter + (transform.y || 0);\n\n                    // save some stuff to use later ensure no labels overlap\n                    if(transform.outside) {\n                        pt.yLabelMin = translateY - textBB.height / 2;\n                        pt.yLabelMid = translateY;\n                        pt.yLabelMax = translateY + textBB.height / 2;\n                        pt.labelExtraX = 0;\n                        pt.labelExtraY = 0;\n                        hasOutsideText = true;\n                    }\n\n                    sliceText.attr('transform',\n                        'translate(' + translateX + ',' + translateY + ')' +\n                        (transform.scale < 1 ? ('scale(' + transform.scale + ')') : '') +\n                        (transform.rotate ? ('rotate(' + transform.rotate + ')') : '') +\n                        'translate(' +\n                            (-(textBB.left + textBB.right) / 2) + ',' +\n                            (-(textBB.top + textBB.bottom) / 2) +\n                        ')');\n                });\n            });\n\n            // add the title\n            var titleTextGroup = d3.select(this).selectAll('g.titletext')\n                .data(trace.title.text ? [0] : []);\n\n            titleTextGroup.enter().append('g')\n                .classed('titletext', true);\n            titleTextGroup.exit().remove();\n\n            titleTextGroup.each(function() {\n                var titleText = Lib.ensureSingle(d3.select(this), 'text', '', function(s) {\n                    // prohibit tex interpretation as above\n                    s.attr('data-notex', 1);\n                });\n\n                var txt = trace.title.text;\n                if(trace._meta) {\n                    txt = Lib.templateString(txt, trace._meta);\n                }\n\n                titleText.text(txt)\n                    .attr({\n                        'class': 'titletext',\n                        transform: '',\n                        'text-anchor': 'middle',\n                    })\n                .call(Drawing.font, trace.title.font)\n                .call(svgTextUtils.convertToTspans, gd);\n\n                var transform;\n\n                if(trace.title.position === 'middle center') {\n                    transform = positionTitleInside(cd0);\n                } else {\n                    transform = positionTitleOutside(cd0, fullLayout._size);\n                }\n\n                titleText.attr('transform',\n                    'translate(' + transform.x + ',' + transform.y + ')' +\n                    (transform.scale < 1 ? ('scale(' + transform.scale + ')') : '') +\n                    'translate(' + transform.tx + ',' + transform.ty + ')');\n            });\n\n            // now make sure no labels overlap (at least within one pie)\n            if(hasOutsideText) scootLabels(quadrants, trace);\n\n            plotTextLines(slices, trace);\n        });\n    });\n\n    // This is for a bug in Chrome (as of 2015-07-22, and does not affect FF)\n    // if insidetextfont and outsidetextfont are different sizes, sometimes the size\n    // of an \"em\" gets taken from the wrong element at first so lines are\n    // spaced wrong. You just have to tell it to try again later and it gets fixed.\n    // I have no idea why we haven't seen this in other contexts. Also, sometimes\n    // it gets the initial draw correct but on redraw it gets confused.\n    setTimeout(function() {\n        plotGroups.selectAll('tspan').each(function() {\n            var s = d3.select(this);\n            if(s.attr('dy')) s.attr('dy', s.attr('dy'));\n        });\n    }, 0);\n}\n\n// TODO add support for transition\nfunction plotTextLines(slices, trace) {\n    slices.each(function(pt) {\n        var sliceTop = d3.select(this);\n\n        if(!pt.labelExtraX && !pt.labelExtraY) {\n            sliceTop.select('path.textline').remove();\n            return;\n        }\n\n        // first move the text to its new location\n        var sliceText = sliceTop.select('g.slicetext text');\n\n        sliceText.attr('transform', 'translate(' + pt.labelExtraX + ',' + pt.labelExtraY + ')' +\n            sliceText.attr('transform'));\n\n        // then add a line to the new location\n        var lineStartX = pt.cxFinal + pt.pxmid[0];\n        var lineStartY = pt.cyFinal + pt.pxmid[1];\n        var textLinePath = 'M' + lineStartX + ',' + lineStartY;\n        var finalX = (pt.yLabelMax - pt.yLabelMin) * (pt.pxmid[0] < 0 ? -1 : 1) / 4;\n\n        if(pt.labelExtraX) {\n            var yFromX = pt.labelExtraX * pt.pxmid[1] / pt.pxmid[0];\n            var yNet = pt.yLabelMid + pt.labelExtraY - (pt.cyFinal + pt.pxmid[1]);\n\n            if(Math.abs(yFromX) > Math.abs(yNet)) {\n                textLinePath +=\n                    'l' + (yNet * pt.pxmid[0] / pt.pxmid[1]) + ',' + yNet +\n                    'H' + (lineStartX + pt.labelExtraX + finalX);\n            } else {\n                textLinePath += 'l' + pt.labelExtraX + ',' + yFromX +\n                    'v' + (yNet - yFromX) +\n                    'h' + finalX;\n            }\n        } else {\n            textLinePath +=\n                'V' + (pt.yLabelMid + pt.labelExtraY) +\n                'h' + finalX;\n        }\n\n        Lib.ensureSingle(sliceTop, 'path', 'textline')\n            .call(Color.stroke, trace.outsidetextfont.color)\n            .attr({\n                'stroke-width': Math.min(2, trace.outsidetextfont.size / 8),\n                d: textLinePath,\n                fill: 'none'\n            });\n    });\n}\n\nfunction attachFxHandlers(sliceTop, gd, cd) {\n    var cd0 = cd[0];\n    var trace = cd0.trace;\n    var cx = cd0.cx;\n    var cy = cd0.cy;\n\n    // hover state vars\n    // have we drawn a hover label, so it should be cleared later\n    if(!('_hasHoverLabel' in trace)) trace._hasHoverLabel = false;\n    // have we emitted a hover event, so later an unhover event should be emitted\n    // note that click events do not depend on this - you can still get them\n    // with hovermode: false or if you were earlier dragging, then clicked\n    // in the same slice that you moused up in\n    if(!('_hasHoverEvent' in trace)) trace._hasHoverEvent = false;\n\n    sliceTop.on('mouseover', function(pt) {\n        // in case fullLayout or fullData has changed without a replot\n        var fullLayout2 = gd._fullLayout;\n        var trace2 = gd._fullData[trace.index];\n\n        if(gd._dragging || fullLayout2.hovermode === false) return;\n\n        var hoverinfo = trace2.hoverinfo;\n        if(Array.isArray(hoverinfo)) {\n            // super hacky: we need to pull out the *first* hoverinfo from\n            // pt.pts, then put it back into an array in a dummy trace\n            // and call castHoverinfo on that.\n            // TODO: do we want to have Fx.castHoverinfo somehow handle this?\n            // it already takes an array for index, for 2D, so this seems tricky.\n            hoverinfo = Fx.castHoverinfo({\n                hoverinfo: [helpers.castOption(hoverinfo, pt.pts)],\n                _module: trace._module\n            }, fullLayout2, 0);\n        }\n\n        if(hoverinfo === 'all') hoverinfo = 'label+text+value+percent+name';\n\n        // in case we dragged over the pie from another subplot,\n        // or if hover is turned off\n        if(trace2.hovertemplate || (hoverinfo !== 'none' && hoverinfo !== 'skip' && hoverinfo)) {\n            var rInscribed = pt.rInscribed || 0;\n            var hoverCenterX = cx + pt.pxmid[0] * (1 - rInscribed);\n            var hoverCenterY = cy + pt.pxmid[1] * (1 - rInscribed);\n            var separators = fullLayout2.separators;\n            var text = [];\n\n            if(hoverinfo && hoverinfo.indexOf('label') !== -1) text.push(pt.label);\n            pt.text = helpers.castOption(trace2.hovertext || trace2.text, pt.pts);\n            if(hoverinfo && hoverinfo.indexOf('text') !== -1) {\n                var tx = pt.text;\n                if(Lib.isValidTextValue(tx)) text.push(tx);\n            }\n            pt.value = pt.v;\n            pt.valueLabel = helpers.formatPieValue(pt.v, separators);\n            if(hoverinfo && hoverinfo.indexOf('value') !== -1) text.push(pt.valueLabel);\n            pt.percent = pt.v / cd0.vTotal;\n            pt.percentLabel = helpers.formatPiePercent(pt.percent, separators);\n            if(hoverinfo && hoverinfo.indexOf('percent') !== -1) text.push(pt.percentLabel);\n\n            var hoverLabel = trace2.hoverlabel;\n            var hoverFont = hoverLabel.font;\n\n            Fx.loneHover({\n                trace: trace,\n                x0: hoverCenterX - rInscribed * cd0.r,\n                x1: hoverCenterX + rInscribed * cd0.r,\n                y: hoverCenterY,\n                text: text.join('<br>'),\n                name: (trace2.hovertemplate || hoverinfo.indexOf('name') !== -1) ? trace2.name : undefined,\n                idealAlign: pt.pxmid[0] < 0 ? 'left' : 'right',\n                color: helpers.castOption(hoverLabel.bgcolor, pt.pts) || pt.color,\n                borderColor: helpers.castOption(hoverLabel.bordercolor, pt.pts),\n                fontFamily: helpers.castOption(hoverFont.family, pt.pts),\n                fontSize: helpers.castOption(hoverFont.size, pt.pts),\n                fontColor: helpers.castOption(hoverFont.color, pt.pts),\n                nameLength: helpers.castOption(hoverLabel.namelength, pt.pts),\n                textAlign: helpers.castOption(hoverLabel.align, pt.pts),\n                hovertemplate: helpers.castOption(trace2.hovertemplate, pt.pts),\n                hovertemplateLabels: pt,\n                eventData: [eventData(pt, trace2)]\n            }, {\n                container: fullLayout2._hoverlayer.node(),\n                outerContainer: fullLayout2._paper.node(),\n                gd: gd\n            });\n\n            trace._hasHoverLabel = true;\n        }\n\n        trace._hasHoverEvent = true;\n        gd.emit('plotly_hover', {\n            points: [eventData(pt, trace2)],\n            event: d3.event\n        });\n    });\n\n    sliceTop.on('mouseout', function(evt) {\n        var fullLayout2 = gd._fullLayout;\n        var trace2 = gd._fullData[trace.index];\n        var pt = d3.select(this).datum();\n\n        if(trace._hasHoverEvent) {\n            evt.originalEvent = d3.event;\n            gd.emit('plotly_unhover', {\n                points: [eventData(pt, trace2)],\n                event: d3.event\n            });\n            trace._hasHoverEvent = false;\n        }\n\n        if(trace._hasHoverLabel) {\n            Fx.loneUnhover(fullLayout2._hoverlayer.node());\n            trace._hasHoverLabel = false;\n        }\n    });\n\n    sliceTop.on('click', function(pt) {\n        // TODO: this does not support right-click. If we want to support it, we\n        // would likely need to change pie to use dragElement instead of straight\n        // mapbox event binding. Or perhaps better, make a simple wrapper with the\n        // right mousedown, mousemove, and mouseup handlers just for a left/right click\n        // mapbox would use this too.\n        var fullLayout2 = gd._fullLayout;\n        var trace2 = gd._fullData[trace.index];\n\n        if(gd._dragging || fullLayout2.hovermode === false) return;\n\n        gd._hoverdata = [eventData(pt, trace2)];\n        Fx.click(gd, d3.event);\n    });\n}\n\nfunction determineOutsideTextFont(trace, pt, layoutFont) {\n    var color =\n        helpers.castOption(trace.outsidetextfont.color, pt.pts) ||\n        helpers.castOption(trace.textfont.color, pt.pts) ||\n        layoutFont.color;\n\n    var family =\n        helpers.castOption(trace.outsidetextfont.family, pt.pts) ||\n        helpers.castOption(trace.textfont.family, pt.pts) ||\n        layoutFont.family;\n\n    var size =\n        helpers.castOption(trace.outsidetextfont.size, pt.pts) ||\n        helpers.castOption(trace.textfont.size, pt.pts) ||\n        layoutFont.size;\n\n    return {\n        color: color,\n        family: family,\n        size: size\n    };\n}\n\nfunction determineInsideTextFont(trace, pt, layoutFont) {\n    var customColor = helpers.castOption(trace.insidetextfont.color, pt.pts);\n    if(!customColor && trace._input.textfont) {\n        // Why not simply using trace.textfont? Because if not set, it\n        // defaults to layout.font which has a default color. But if\n        // textfont.color and insidetextfont.color don't supply a value,\n        // a contrasting color shall be used.\n        customColor = helpers.castOption(trace._input.textfont.color, pt.pts);\n    }\n\n    var family =\n        helpers.castOption(trace.insidetextfont.family, pt.pts) ||\n        helpers.castOption(trace.textfont.family, pt.pts) ||\n        layoutFont.family;\n\n    var size =\n        helpers.castOption(trace.insidetextfont.size, pt.pts) ||\n        helpers.castOption(trace.textfont.size, pt.pts) ||\n        layoutFont.size;\n\n    return {\n        color: customColor || Color.contrast(pt.color),\n        family: family,\n        size: size\n    };\n}\n\nfunction prerenderTitles(cdModule, gd) {\n    var cd0, trace;\n\n    // Determine the width and height of the title for each pie.\n    for(var i = 0; i < cdModule.length; i++) {\n        cd0 = cdModule[i][0];\n        trace = cd0.trace;\n\n        if(trace.title.text) {\n            var txt = trace.title.text;\n            if(trace._meta) {\n                txt = Lib.templateString(txt, trace._meta);\n            }\n\n            var dummyTitle = Drawing.tester.append('text')\n              .attr('data-notex', 1)\n              .text(txt)\n              .call(Drawing.font, trace.title.font)\n              .call(svgTextUtils.convertToTspans, gd);\n            var bBox = Drawing.bBox(dummyTitle.node(), true);\n            cd0.titleBox = {\n                width: bBox.width,\n                height: bBox.height,\n            };\n            dummyTitle.remove();\n        }\n    }\n}\n\nfunction transformInsideText(textBB, pt, cd0) {\n    var textDiameter = Math.sqrt(textBB.width * textBB.width + textBB.height * textBB.height);\n    var textAspect = textBB.width / textBB.height;\n    var halfAngle = pt.halfangle;\n    var ring = pt.ring;\n    var rInscribed = pt.rInscribed;\n    var r = cd0.r || pt.rpx1;\n\n    // max size text can be inserted inside without rotating it\n    // this inscribes the text rectangle in a circle, which is then inscribed\n    // in the slice, so it will be an underestimate, which some day we may want\n    // to improve so this case can get more use\n    var transform = {\n        scale: rInscribed * r * 2 / textDiameter,\n\n        // and the center position and rotation in this case\n        rCenter: 1 - rInscribed,\n        rotate: 0\n    };\n\n    if(transform.scale >= 1) return transform;\n\n    // max size if text is rotated radially\n    var Qr = textAspect + 1 / (2 * Math.tan(halfAngle));\n    var maxHalfHeightRotRadial = r * Math.min(\n        1 / (Math.sqrt(Qr * Qr + 0.5) + Qr),\n        ring / (Math.sqrt(textAspect * textAspect + ring / 2) + textAspect)\n    );\n    var radialTransform = {\n        scale: maxHalfHeightRotRadial * 2 / textBB.height,\n        rCenter: Math.cos(maxHalfHeightRotRadial / r) -\n            maxHalfHeightRotRadial * textAspect / r,\n        rotate: (180 / Math.PI * pt.midangle + 720) % 180 - 90\n    };\n\n    // max size if text is rotated tangentially\n    var aspectInv = 1 / textAspect;\n    var Qt = aspectInv + 1 / (2 * Math.tan(halfAngle));\n    var maxHalfWidthTangential = r * Math.min(\n        1 / (Math.sqrt(Qt * Qt + 0.5) + Qt),\n        ring / (Math.sqrt(aspectInv * aspectInv + ring / 2) + aspectInv)\n    );\n    var tangentialTransform = {\n        scale: maxHalfWidthTangential * 2 / textBB.width,\n        rCenter: Math.cos(maxHalfWidthTangential / r) -\n            maxHalfWidthTangential / textAspect / r,\n        rotate: (180 / Math.PI * pt.midangle + 810) % 180 - 90\n    };\n    // if we need a rotated transform, pick the biggest one\n    // even if both are bigger than 1\n    var rotatedTransform = tangentialTransform.scale > radialTransform.scale ?\n            tangentialTransform : radialTransform;\n\n    if(transform.scale < 1 && rotatedTransform.scale > transform.scale) return rotatedTransform;\n    return transform;\n}\n\nfunction getInscribedRadiusFraction(pt, cd0) {\n    if(pt.v === cd0.vTotal && !cd0.trace.hole) return 1;// special case of 100% with no hole\n\n    return Math.min(1 / (1 + 1 / Math.sin(pt.halfangle)), pt.ring / 2);\n}\n\nfunction transformOutsideText(textBB, pt) {\n    var x = pt.pxmid[0];\n    var y = pt.pxmid[1];\n    var dx = textBB.width / 2;\n    var dy = textBB.height / 2;\n\n    if(x < 0) dx *= -1;\n    if(y < 0) dy *= -1;\n\n    return {\n        scale: 1,\n        rCenter: 1,\n        rotate: 0,\n        x: dx + Math.abs(dy) * (dx > 0 ? 1 : -1) / 2,\n        y: dy / (1 + x * x / (y * y)),\n        outside: true\n    };\n}\n\nfunction positionTitleInside(cd0) {\n    var textDiameter =\n        Math.sqrt(cd0.titleBox.width * cd0.titleBox.width + cd0.titleBox.height * cd0.titleBox.height);\n    return {\n        x: cd0.cx,\n        y: cd0.cy,\n        scale: cd0.trace.hole * cd0.r * 2 / textDiameter,\n        tx: 0,\n        ty: - cd0.titleBox.height / 2 + cd0.trace.title.font.size\n    };\n}\n\nfunction positionTitleOutside(cd0, plotSize) {\n    var scaleX = 1;\n    var scaleY = 1;\n    var maxPull;\n\n    var trace = cd0.trace;\n    // position of the baseline point of the text box in the plot, before scaling.\n    // we anchored the text in the middle, so the baseline is on the bottom middle\n    // of the first line of text.\n    var topMiddle = {\n        x: cd0.cx,\n        y: cd0.cy\n    };\n    // relative translation of the text box after scaling\n    var translate = {\n        tx: 0,\n        ty: 0\n    };\n\n    // we reason below as if the baseline is the top middle point of the text box.\n    // so we must add the font size to approximate the y-coord. of the top.\n    // note that this correction must happen after scaling.\n    translate.ty += trace.title.font.size;\n    maxPull = getMaxPull(trace);\n\n    if(trace.title.position.indexOf('top') !== -1) {\n        topMiddle.y -= (1 + maxPull) * cd0.r;\n        translate.ty -= cd0.titleBox.height;\n    } else if(trace.title.position.indexOf('bottom') !== -1) {\n        topMiddle.y += (1 + maxPull) * cd0.r;\n    }\n\n    var rx = applyAspectRatio(cd0.r, cd0.trace.aspectratio);\n\n    var maxWidth = plotSize.w * (trace.domain.x[1] - trace.domain.x[0]) / 2;\n    if(trace.title.position.indexOf('left') !== -1) {\n        // we start the text at the left edge of the pie\n        maxWidth = maxWidth + rx;\n        topMiddle.x -= (1 + maxPull) * rx;\n        translate.tx += cd0.titleBox.width / 2;\n    } else if(trace.title.position.indexOf('center') !== -1) {\n        maxWidth *= 2;\n    } else if(trace.title.position.indexOf('right') !== -1) {\n        maxWidth = maxWidth + rx;\n        topMiddle.x += (1 + maxPull) * rx;\n        translate.tx -= cd0.titleBox.width / 2;\n    }\n    scaleX = maxWidth / cd0.titleBox.width;\n    scaleY = getTitleSpace(cd0, plotSize) / cd0.titleBox.height;\n    return {\n        x: topMiddle.x,\n        y: topMiddle.y,\n        scale: Math.min(scaleX, scaleY),\n        tx: translate.tx,\n        ty: translate.ty\n    };\n}\n\nfunction applyAspectRatio(x, aspectratio) {\n    return x / ((aspectratio === undefined) ? 1 : aspectratio);\n}\n\nfunction getTitleSpace(cd0, plotSize) {\n    var trace = cd0.trace;\n    var pieBoxHeight = plotSize.h * (trace.domain.y[1] - trace.domain.y[0]);\n    // use at most half of the plot for the title\n    return Math.min(cd0.titleBox.height, pieBoxHeight / 2);\n}\n\nfunction getMaxPull(trace) {\n    var maxPull = trace.pull;\n    if(!maxPull) return 0;\n\n    var j;\n    if(Array.isArray(maxPull)) {\n        maxPull = 0;\n        for(j = 0; j < trace.pull.length; j++) {\n            if(trace.pull[j] > maxPull) maxPull = trace.pull[j];\n        }\n    }\n    return maxPull;\n}\n\nfunction scootLabels(quadrants, trace) {\n    var xHalf, yHalf, equatorFirst, farthestX, farthestY,\n        xDiffSign, yDiffSign, thisQuad, oppositeQuad,\n        wholeSide, i, thisQuadOutside, firstOppositeOutsidePt;\n\n    function topFirst(a, b) { return a.pxmid[1] - b.pxmid[1]; }\n    function bottomFirst(a, b) { return b.pxmid[1] - a.pxmid[1]; }\n\n    function scootOneLabel(thisPt, prevPt) {\n        if(!prevPt) prevPt = {};\n\n        var prevOuterY = prevPt.labelExtraY + (yHalf ? prevPt.yLabelMax : prevPt.yLabelMin);\n        var thisInnerY = yHalf ? thisPt.yLabelMin : thisPt.yLabelMax;\n        var thisOuterY = yHalf ? thisPt.yLabelMax : thisPt.yLabelMin;\n        var thisSliceOuterY = thisPt.cyFinal + farthestY(thisPt.px0[1], thisPt.px1[1]);\n        var newExtraY = prevOuterY - thisInnerY;\n\n        var xBuffer, i, otherPt, otherOuterY, otherOuterX, newExtraX;\n\n        // make sure this label doesn't overlap other labels\n        // this *only* has us move these labels vertically\n        if(newExtraY * yDiffSign > 0) thisPt.labelExtraY = newExtraY;\n\n        // make sure this label doesn't overlap any slices\n        if(!Array.isArray(trace.pull)) return; // this can only happen with array pulls\n\n        for(i = 0; i < wholeSide.length; i++) {\n            otherPt = wholeSide[i];\n\n            // overlap can only happen if the other point is pulled more than this one\n            if(otherPt === thisPt || (\n                (helpers.castOption(trace.pull, thisPt.pts) || 0) >=\n                (helpers.castOption(trace.pull, otherPt.pts) || 0))\n            ) {\n                continue;\n            }\n\n            if((thisPt.pxmid[1] - otherPt.pxmid[1]) * yDiffSign > 0) {\n                // closer to the equator - by construction all of these happen first\n                // move the text vertically to get away from these slices\n                otherOuterY = otherPt.cyFinal + farthestY(otherPt.px0[1], otherPt.px1[1]);\n                newExtraY = otherOuterY - thisInnerY - thisPt.labelExtraY;\n\n                if(newExtraY * yDiffSign > 0) thisPt.labelExtraY += newExtraY;\n            } else if((thisOuterY + thisPt.labelExtraY - thisSliceOuterY) * yDiffSign > 0) {\n                // farther from the equator - happens after we've done all the\n                // vertical moving we're going to do\n                // move horizontally to get away from these more polar slices\n\n                // if we're moving horz. based on a slice that's several slices away from this one\n                // then we need some extra space for the lines to labels between them\n                xBuffer = 3 * xDiffSign * Math.abs(i - wholeSide.indexOf(thisPt));\n\n                otherOuterX = otherPt.cxFinal + farthestX(otherPt.px0[0], otherPt.px1[0]);\n                newExtraX = otherOuterX + xBuffer - (thisPt.cxFinal + thisPt.pxmid[0]) - thisPt.labelExtraX;\n\n                if(newExtraX * xDiffSign > 0) thisPt.labelExtraX += newExtraX;\n            }\n        }\n    }\n\n    for(yHalf = 0; yHalf < 2; yHalf++) {\n        equatorFirst = yHalf ? topFirst : bottomFirst;\n        farthestY = yHalf ? Math.max : Math.min;\n        yDiffSign = yHalf ? 1 : -1;\n\n        for(xHalf = 0; xHalf < 2; xHalf++) {\n            farthestX = xHalf ? Math.max : Math.min;\n            xDiffSign = xHalf ? 1 : -1;\n\n            // first sort the array\n            // note this is a copy of cd, so cd itself doesn't get sorted\n            // but we can still modify points in place.\n            thisQuad = quadrants[yHalf][xHalf];\n            thisQuad.sort(equatorFirst);\n\n            oppositeQuad = quadrants[1 - yHalf][xHalf];\n            wholeSide = oppositeQuad.concat(thisQuad);\n\n            thisQuadOutside = [];\n            for(i = 0; i < thisQuad.length; i++) {\n                if(thisQuad[i].yLabelMid !== undefined) thisQuadOutside.push(thisQuad[i]);\n            }\n\n            firstOppositeOutsidePt = false;\n            for(i = 0; yHalf && i < oppositeQuad.length; i++) {\n                if(oppositeQuad[i].yLabelMid !== undefined) {\n                    firstOppositeOutsidePt = oppositeQuad[i];\n                    break;\n                }\n            }\n\n            // each needs to avoid the previous\n            for(i = 0; i < thisQuadOutside.length; i++) {\n                var prevPt = i && thisQuadOutside[i - 1];\n                // bottom half needs to avoid the first label of the top half\n                // top half we still need to call scootOneLabel on the first slice\n                // so we can avoid other slices, but we don't pass a prevPt\n                if(firstOppositeOutsidePt && !i) prevPt = firstOppositeOutsidePt;\n                scootOneLabel(thisQuadOutside[i], prevPt);\n            }\n        }\n    }\n}\n\nfunction layoutAreas(cdModule, plotSize) {\n    var scaleGroups = [];\n\n    // figure out the center and maximum radius\n    for(var i = 0; i < cdModule.length; i++) {\n        var cd0 = cdModule[i][0];\n        var trace = cd0.trace;\n\n        var domain = trace.domain;\n        var width = plotSize.w * (domain.x[1] - domain.x[0]);\n        var height = plotSize.h * (domain.y[1] - domain.y[0]);\n        // leave some space for the title, if it will be displayed outside\n        if(trace.title.text && trace.title.position !== 'middle center') {\n            height -= getTitleSpace(cd0, plotSize);\n        }\n\n        var rx = width / 2;\n        var ry = height / 2;\n        if(trace.type === 'funnelarea' && !trace.scalegroup) {\n            ry /= trace.aspectratio;\n        }\n\n        cd0.r = Math.min(rx, ry) / (1 + getMaxPull(trace));\n\n        cd0.cx = plotSize.l + plotSize.w * (trace.domain.x[1] + trace.domain.x[0]) / 2;\n        cd0.cy = plotSize.t + plotSize.h * (1 - trace.domain.y[0]) - height / 2;\n        if(trace.title.text && trace.title.position.indexOf('bottom') !== -1) {\n            cd0.cy -= getTitleSpace(cd0, plotSize);\n        }\n\n        if(trace.scalegroup && scaleGroups.indexOf(trace.scalegroup) === -1) {\n            scaleGroups.push(trace.scalegroup);\n        }\n    }\n\n    groupScale(cdModule, scaleGroups);\n}\n\nfunction groupScale(cdModule, scaleGroups) {\n    var cd0, i, trace;\n\n    // scale those that are grouped\n    for(var k = 0; k < scaleGroups.length; k++) {\n        var min = Infinity;\n        var g = scaleGroups[k];\n\n        for(i = 0; i < cdModule.length; i++) {\n            cd0 = cdModule[i][0];\n            trace = cd0.trace;\n\n            if(trace.scalegroup === g) {\n                var area;\n                if(trace.type === 'pie') {\n                    area = cd0.r * cd0.r;\n                } else if(trace.type === 'funnelarea') {\n                    var rx, ry;\n\n                    if(trace.aspectratio > 1) {\n                        rx = cd0.r;\n                        ry = rx / trace.aspectratio;\n                    } else {\n                        ry = cd0.r;\n                        rx = ry * trace.aspectratio;\n                    }\n\n                    rx *= (1 + trace.baseratio) / 2;\n\n                    area = rx * ry;\n                }\n\n                min = Math.min(min, area / cd0.vTotal);\n            }\n        }\n\n        for(i = 0; i < cdModule.length; i++) {\n            cd0 = cdModule[i][0];\n            trace = cd0.trace;\n            if(trace.scalegroup === g) {\n                var v = min * cd0.vTotal;\n                if(trace.type === 'funnelarea') {\n                    v /= (1 + trace.baseratio) / 2;\n                    v /= trace.aspectratio;\n                }\n\n                cd0.r = Math.sqrt(v);\n            }\n        }\n    }\n}\n\nfunction setCoords(cd) {\n    var cd0 = cd[0];\n    var trace = cd0.trace;\n    var currentAngle = trace.rotation * Math.PI / 180;\n    var angleFactor = 2 * Math.PI / cd0.vTotal;\n    var firstPt = 'px0';\n    var lastPt = 'px1';\n\n    var i, cdi, currentCoords;\n\n    if(trace.direction === 'counterclockwise') {\n        for(i = 0; i < cd.length; i++) {\n            if(!cd[i].hidden) break; // find the first non-hidden slice\n        }\n        if(i === cd.length) return; // all slices hidden\n\n        currentAngle += angleFactor * cd[i].v;\n        angleFactor *= -1;\n        firstPt = 'px1';\n        lastPt = 'px0';\n    }\n\n    function getCoords(angle) {\n        return [cd0.r * Math.sin(angle), -cd0.r * Math.cos(angle)];\n    }\n\n    currentCoords = getCoords(currentAngle);\n\n    for(i = 0; i < cd.length; i++) {\n        cdi = cd[i];\n        if(cdi.hidden) continue;\n\n        cdi[firstPt] = currentCoords;\n\n        currentAngle += angleFactor * cdi.v / 2;\n        cdi.pxmid = getCoords(currentAngle);\n        cdi.midangle = currentAngle;\n\n        currentAngle += angleFactor * cdi.v / 2;\n        currentCoords = getCoords(currentAngle);\n\n        cdi[lastPt] = currentCoords;\n\n        cdi.largeArc = (cdi.v > cd0.vTotal / 2) ? 1 : 0;\n\n        cdi.halfangle = Math.PI * Math.min(cdi.v / cd0.vTotal, 0.5);\n        cdi.ring = 1 - trace.hole;\n        cdi.rInscribed = getInscribedRadiusFraction(cdi, cd0);\n    }\n}\n\nmodule.exports = {\n    plot: plot,\n    transformInsideText: transformInsideText,\n    determineInsideTextFont: determineInsideTextFont,\n    positionTitleOutside: positionTitleOutside,\n    prerenderTitles: prerenderTitles,\n    layoutAreas: layoutAreas,\n    attachFxHandlers: attachFxHandlers,\n};\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../components/fx\":632,\"../../lib\":719,\"../../lib/svg_text_utils\":743,\"./event_data\":1090,\"./helpers\":1091,\"d3\":163}],1096:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar styleOne = _dereq_('./style_one');\n\nmodule.exports = function style(gd) {\n    gd._fullLayout._pielayer.selectAll('.trace').each(function(cd) {\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n        var traceSelection = d3.select(this);\n\n        traceSelection.style({opacity: trace.opacity});\n\n        traceSelection.selectAll('path.surface').each(function(pt) {\n            d3.select(this).call(styleOne, pt, trace);\n        });\n    });\n};\n\n},{\"./style_one\":1097,\"d3\":163}],1097:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Color = _dereq_('../../components/color');\nvar castOption = _dereq_('./helpers').castOption;\n\nmodule.exports = function styleOne(s, pt, trace) {\n    var line = trace.marker.line;\n    var lineColor = castOption(line.color, pt.pts) || Color.defaultLine;\n    var lineWidth = castOption(line.width, pt.pts) || 0;\n\n    s.style('stroke-width', lineWidth)\n        .call(Color.fill, pt.color)\n        .call(Color.stroke, lineColor);\n};\n\n},{\"../../components/color\":593,\"./helpers\":1091}],1098:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterglAttrs = _dereq_('../scatter/attributes');\n\nmodule.exports = {\n    x: scatterglAttrs.x,\n    y: scatterglAttrs.y,\n    xy: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    indices: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    xbounds: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    ybounds: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    text: scatterglAttrs.text,\n    marker: {\n        color: {\n            valType: 'color',\n            arrayOk: false,\n            \n            editType: 'calc',\n            \n        },\n        opacity: {\n            valType: 'number',\n            min: 0,\n            max: 1,\n            dflt: 1,\n            arrayOk: false,\n            \n            editType: 'calc',\n            \n        },\n        blend: {\n            valType: 'boolean',\n            dflt: null,\n            \n            editType: 'calc',\n            \n        },\n        sizemin: {\n            valType: 'number',\n            min: 0.1,\n            max: 2,\n            dflt: 0.5,\n            \n            editType: 'calc',\n            \n        },\n        sizemax: {\n            valType: 'number',\n            min: 0.1,\n            dflt: 20,\n            \n            editType: 'calc',\n            \n        },\n        border: {\n            color: {\n                valType: 'color',\n                arrayOk: false,\n                \n                editType: 'calc',\n                \n            },\n            arearatio: {\n                valType: 'number',\n                min: 0,\n                max: 1,\n                dflt: 0,\n                \n                editType: 'calc',\n                \n            },\n            editType: 'calc'\n        },\n        editType: 'calc'\n    },\n    transforms: undefined\n};\n\n},{\"../scatter/attributes\":1112}],1099:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar createPointCloudRenderer = _dereq_('gl-pointcloud2d');\n\nvar str2RGBArray = _dereq_('../../lib/str2rgbarray');\nvar findExtremes = _dereq_('../../plots/cartesian/autorange').findExtremes;\nvar getTraceColor = _dereq_('../scatter/get_trace_color');\n\nfunction Pointcloud(scene, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.type = 'pointcloud';\n\n    this.pickXData = [];\n    this.pickYData = [];\n    this.xData = [];\n    this.yData = [];\n    this.textLabels = [];\n    this.color = 'rgb(0, 0, 0)';\n    this.name = '';\n    this.hoverinfo = 'all';\n\n    this.idToIndex = new Int32Array(0);\n    this.bounds = [0, 0, 0, 0];\n\n    this.pointcloudOptions = {\n        positions: new Float32Array(0),\n        idToIndex: this.idToIndex,\n        sizemin: 0.5,\n        sizemax: 12,\n        color: [0, 0, 0, 1],\n        areaRatio: 1,\n        borderColor: [0, 0, 0, 1]\n    };\n    this.pointcloud = createPointCloudRenderer(scene.glplot, this.pointcloudOptions);\n    this.pointcloud._trace = this; // scene2d requires this prop\n}\n\nvar proto = Pointcloud.prototype;\n\nproto.handlePick = function(pickResult) {\n    var index = this.idToIndex[pickResult.pointId];\n\n    // prefer the readout from XY, if present\n    return {\n        trace: this,\n        dataCoord: pickResult.dataCoord,\n        traceCoord: this.pickXYData ?\n            [this.pickXYData[index * 2], this.pickXYData[index * 2 + 1]] :\n            [this.pickXData[index], this.pickYData[index]],\n        textLabel: Array.isArray(this.textLabels) ?\n            this.textLabels[index] :\n            this.textLabels,\n        color: this.color,\n        name: this.name,\n        pointIndex: index,\n        hoverinfo: this.hoverinfo\n    };\n};\n\nproto.update = function(options) {\n    this.index = options.index;\n    this.textLabels = options.text;\n    this.name = options.name;\n    this.hoverinfo = options.hoverinfo;\n    this.bounds = [Infinity, Infinity, -Infinity, -Infinity];\n\n    this.updateFast(options);\n\n    this.color = getTraceColor(options, {});\n};\n\nproto.updateFast = function(options) {\n    var x = this.xData = this.pickXData = options.x;\n    var y = this.yData = this.pickYData = options.y;\n    var xy = this.pickXYData = options.xy;\n\n    var userBounds = options.xbounds && options.ybounds;\n    var index = options.indices;\n\n    var len;\n    var idToIndex;\n    var positions;\n    var bounds = this.bounds;\n\n    var xx, yy, i;\n\n    if(xy) {\n        positions = xy;\n\n        // dividing xy.length by 2 and truncating to integer if xy.length was not even\n        len = xy.length >>> 1;\n\n        if(userBounds) {\n            bounds[0] = options.xbounds[0];\n            bounds[2] = options.xbounds[1];\n            bounds[1] = options.ybounds[0];\n            bounds[3] = options.ybounds[1];\n        } else {\n            for(i = 0; i < len; i++) {\n                xx = positions[i * 2];\n                yy = positions[i * 2 + 1];\n\n                if(xx < bounds[0]) bounds[0] = xx;\n                if(xx > bounds[2]) bounds[2] = xx;\n                if(yy < bounds[1]) bounds[1] = yy;\n                if(yy > bounds[3]) bounds[3] = yy;\n            }\n        }\n\n        if(index) {\n            idToIndex = index;\n        } else {\n            idToIndex = new Int32Array(len);\n\n            for(i = 0; i < len; i++) {\n                idToIndex[i] = i;\n            }\n        }\n    } else {\n        len = x.length;\n\n        positions = new Float32Array(2 * len);\n        idToIndex = new Int32Array(len);\n\n        for(i = 0; i < len; i++) {\n            xx = x[i];\n            yy = y[i];\n\n            idToIndex[i] = i;\n\n            positions[i * 2] = xx;\n            positions[i * 2 + 1] = yy;\n\n            if(xx < bounds[0]) bounds[0] = xx;\n            if(xx > bounds[2]) bounds[2] = xx;\n            if(yy < bounds[1]) bounds[1] = yy;\n            if(yy > bounds[3]) bounds[3] = yy;\n        }\n    }\n\n    this.idToIndex = idToIndex;\n    this.pointcloudOptions.idToIndex = idToIndex;\n\n    this.pointcloudOptions.positions = positions;\n\n    var markerColor = str2RGBArray(options.marker.color);\n    var borderColor = str2RGBArray(options.marker.border.color);\n    var opacity = options.opacity * options.marker.opacity;\n\n    markerColor[3] *= opacity;\n    this.pointcloudOptions.color = markerColor;\n\n    // detect blending from the number of points, if undefined\n    // because large data with blending hits performance\n    var blend = options.marker.blend;\n    if(blend === null) {\n        var maxPoints = 100;\n        blend = x.length < maxPoints || y.length < maxPoints;\n    }\n    this.pointcloudOptions.blend = blend;\n\n    borderColor[3] *= opacity;\n    this.pointcloudOptions.borderColor = borderColor;\n\n    var markerSizeMin = options.marker.sizemin;\n    var markerSizeMax = Math.max(options.marker.sizemax, options.marker.sizemin);\n    this.pointcloudOptions.sizeMin = markerSizeMin;\n    this.pointcloudOptions.sizeMax = markerSizeMax;\n    this.pointcloudOptions.areaRatio = options.marker.border.arearatio;\n\n    this.pointcloud.update(this.pointcloudOptions);\n\n    // add item for autorange routine\n    var xa = this.scene.xaxis;\n    var ya = this.scene.yaxis;\n    var pad = markerSizeMax / 2 || 0.5;\n    options._extremes[xa._id] = findExtremes(xa, [bounds[0], bounds[2]], {ppad: pad});\n    options._extremes[ya._id] = findExtremes(ya, [bounds[1], bounds[3]], {ppad: pad});\n};\n\nproto.dispose = function() {\n    this.pointcloud.dispose();\n};\n\nfunction createPointcloud(scene, data) {\n    var plot = new Pointcloud(scene, data.uid);\n    plot.update(data);\n    return plot;\n}\n\nmodule.exports = createPointcloud;\n\n},{\"../../lib/str2rgbarray\":742,\"../../plots/cartesian/autorange\":766,\"../scatter/get_trace_color\":1121,\"gl-pointcloud2d\":292}],1100:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    coerce('x');\n    coerce('y');\n\n    coerce('xbounds');\n    coerce('ybounds');\n\n    if(traceIn.xy && traceIn.xy instanceof Float32Array) {\n        traceOut.xy = traceIn.xy;\n    }\n\n    if(traceIn.indices && traceIn.indices instanceof Int32Array) {\n        traceOut.indices = traceIn.indices;\n    }\n\n    coerce('text');\n    coerce('marker.color', defaultColor);\n    coerce('marker.opacity');\n    coerce('marker.blend');\n    coerce('marker.sizemin');\n    coerce('marker.sizemax');\n    coerce('marker.border.color', defaultColor);\n    coerce('marker.border.arearatio');\n\n    // disable 1D transforms - that would defeat the purpose of this trace type, performance!\n    traceOut._length = null;\n};\n\n},{\"../../lib\":719,\"./attributes\":1098}],1101:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n\n    // reuse the Scatter3D 'dummy' calc step so that legends know what to do\n    calc: _dereq_('../scatter3d/calc'),\n    plot: _dereq_('./convert'),\n\n    moduleType: 'trace',\n    name: 'pointcloud',\n    basePlotModule: _dereq_('../../plots/gl2d'),\n    categories: ['gl', 'gl2d', 'showLegend'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/gl2d\":805,\"../scatter3d/calc\":1139,\"./attributes\":1098,\"./convert\":1099,\"./defaults\":1100}],1102:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar colorAttrs = _dereq_('../../components/color/attributes');\nvar fxAttrs = _dereq_('../../components/fx/attributes');\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar colorAttributes = _dereq_('../../components/colorscale/attributes');\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar FORMAT_LINK = _dereq_('../../constants/docs').FORMAT_LINK;\n\nvar attrs = module.exports = overrideAll({\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: [],\n        arrayOk: false,\n        \n    }),\n    hoverlabel: fxAttrs.hoverlabel,\n    domain: domainAttrs({name: 'sankey', trace: true}),\n\n    orientation: {\n        valType: 'enumerated',\n        values: ['v', 'h'],\n        dflt: 'h',\n        \n        \n    },\n\n    valueformat: {\n        valType: 'string',\n        dflt: '.3s',\n        \n        \n    },\n\n    valuesuffix: {\n        valType: 'string',\n        dflt: '',\n        \n        \n    },\n\n    arrangement: {\n        valType: 'enumerated',\n        values: ['snap', 'perpendicular', 'freeform', 'fixed'],\n        dflt: 'snap',\n        \n        \n    },\n\n    textfont: fontAttrs({\n        \n    }),\n\n    node: {\n        label: {\n            valType: 'data_array',\n            dflt: [],\n            \n            \n        },\n        groups: {\n            valType: 'info_array',\n            impliedEdits: {'x': [], 'y': []},\n            dimensions: 2,\n            freeLength: true,\n            dflt: [],\n            items: {valType: 'number', editType: 'calc'},\n            \n            \n        },\n        x: {\n            valType: 'data_array',\n            dflt: [],\n            \n            \n        },\n        y: {\n            valType: 'data_array',\n            dflt: [],\n            \n            \n        },\n        color: {\n            valType: 'color',\n            \n            arrayOk: true,\n            \n        },\n        line: {\n            color: {\n                valType: 'color',\n                \n                dflt: colorAttrs.defaultLine,\n                arrayOk: true,\n                \n            },\n            width: {\n                valType: 'number',\n                \n                min: 0,\n                dflt: 0.5,\n                arrayOk: true,\n                \n            }\n        },\n        pad: {\n            valType: 'number',\n            arrayOk: false,\n            min: 0,\n            dflt: 20,\n            \n            \n        },\n        thickness: {\n            valType: 'number',\n            arrayOk: false,\n            min: 1,\n            dflt: 20,\n            \n            \n        },\n        hoverinfo: {\n            valType: 'enumerated',\n            values: ['all', 'none', 'skip'],\n            dflt: 'all',\n            \n            \n        },\n        hoverlabel: fxAttrs.hoverlabel, // needs editType override,\n        hovertemplate: hovertemplateAttrs({}, {\n            \n            keys: ['value', 'label']\n        }),\n        \n    },\n\n    link: {\n        label: {\n            valType: 'data_array',\n            dflt: [],\n            \n            \n        },\n        color: {\n            valType: 'color',\n            \n            arrayOk: true,\n            \n        },\n        line: {\n            color: {\n                valType: 'color',\n                \n                dflt: colorAttrs.defaultLine,\n                arrayOk: true,\n                \n            },\n            width: {\n                valType: 'number',\n                \n                min: 0,\n                dflt: 0,\n                arrayOk: true,\n                \n            }\n        },\n        source: {\n            valType: 'data_array',\n            \n            dflt: [],\n            \n        },\n        target: {\n            valType: 'data_array',\n            \n            dflt: [],\n            \n        },\n        value: {\n            valType: 'data_array',\n            dflt: [],\n            \n            \n        },\n        hoverinfo: {\n            valType: 'enumerated',\n            values: ['all', 'none', 'skip'],\n            dflt: 'all',\n            \n            \n        },\n        hoverlabel: fxAttrs.hoverlabel, // needs editType override,\n        hovertemplate: hovertemplateAttrs({}, {\n            \n            keys: ['value', 'label']\n        }),\n        colorscales: templatedArray('concentrationscales', {\n            editType: 'calc',\n            label: {\n                valType: 'string',\n                \n                editType: 'calc',\n                \n                dflt: ''\n            },\n            cmax: {\n                valType: 'number',\n                \n                editType: 'calc',\n                dflt: 1,\n                \n            },\n            cmin: {\n                valType: 'number',\n                \n                editType: 'calc',\n                dflt: 0,\n                \n            },\n            colorscale: extendFlat(colorAttributes().colorscale, {dflt: [[0, 'white'], [1, 'black']]})\n        }),\n        \n        \n    }\n}, 'calc', 'nested');\nattrs.transforms = undefined;\n\n},{\"../../components/color/attributes\":592,\"../../components/colorscale/attributes\":600,\"../../components/fx/attributes\":623,\"../../components/fx/hovertemplate_attributes\":631,\"../../constants/docs\":690,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plot_api/plot_template\":757,\"../../plots/attributes\":764,\"../../plots/domain\":792,\"../../plots/font_attributes\":793}],1103:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\nvar plot = _dereq_('./plot');\nvar fxAttrs = _dereq_('../../components/fx/layout_attributes');\n\nvar setCursor = _dereq_('../../lib/setcursor');\nvar dragElement = _dereq_('../../components/dragelement');\nvar prepSelect = _dereq_('../../plots/cartesian/select').prepSelect;\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\n\nvar SANKEY = 'sankey';\n\nexports.name = SANKEY;\n\nexports.baseLayoutAttrOverrides = overrideAll({\n    hoverlabel: fxAttrs.hoverlabel\n}, 'plot', 'nested');\n\nexports.plot = function(gd) {\n    var calcData = getModuleCalcData(gd.calcdata, SANKEY)[0];\n    plot(gd, calcData);\n    exports.updateFx(gd);\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var hadPlot = (oldFullLayout._has && oldFullLayout._has(SANKEY));\n    var hasPlot = (newFullLayout._has && newFullLayout._has(SANKEY));\n\n    if(hadPlot && !hasPlot) {\n        oldFullLayout._paperdiv.selectAll('.sankey').remove();\n        oldFullLayout._paperdiv.selectAll('.bgsankey').remove();\n    }\n};\n\nexports.updateFx = function(gd) {\n    for(var i = 0; i < gd._fullData.length; i++) {\n        subplotUpdateFx(gd, i);\n    }\n};\n\nfunction subplotUpdateFx(gd, index) {\n    var trace = gd._fullData[index];\n    var fullLayout = gd._fullLayout;\n\n    var dragMode = fullLayout.dragmode;\n    var cursor = fullLayout.dragmode === 'pan' ? 'move' : 'crosshair';\n    var bgRect = trace._bgRect;\n\n    if(dragMode === 'pan' || dragMode === 'zoom') return;\n\n    setCursor(bgRect, cursor);\n\n    var xaxis = {\n        _id: 'x',\n        c2p: Lib.identity,\n        _offset: trace._sankey.translateX,\n        _length: trace._sankey.width\n    };\n    var yaxis = {\n        _id: 'y',\n        c2p: Lib.identity,\n        _offset: trace._sankey.translateY,\n        _length: trace._sankey.height\n    };\n\n    // Note: dragOptions is needed to be declared for all dragmodes because\n    // it's the object that holds persistent selection state.\n    var dragOptions = {\n        gd: gd,\n        element: bgRect.node(),\n        plotinfo: {\n            id: index,\n            xaxis: xaxis,\n            yaxis: yaxis,\n            fillRangeItems: Lib.noop\n        },\n        subplot: index,\n        // create mock x/y axes for hover routine\n        xaxes: [xaxis],\n        yaxes: [yaxis],\n        doneFnCompleted: function(selection) {\n            var traceNow = gd._fullData[index];\n            var newGroups;\n            var oldGroups = traceNow.node.groups.slice();\n            var newGroup = [];\n\n            function findNode(pt) {\n                var nodes = traceNow._sankey.graph.nodes;\n                for(var i = 0; i < nodes.length; i++) {\n                    if(nodes[i].pointNumber === pt) return nodes[i];\n                }\n            }\n\n            for(var j = 0; j < selection.length; j++) {\n                var node = findNode(selection[j].pointNumber);\n                if(!node) continue;\n\n                // If the node represents a group\n                if(node.group) {\n                    // Add all its children to the current selection\n                    for(var k = 0; k < node.childrenNodes.length; k++) {\n                        newGroup.push(node.childrenNodes[k].pointNumber);\n                    }\n                    // Flag group for removal from existing list of groups\n                    oldGroups[node.pointNumber - traceNow.node._count] = false;\n                } else {\n                    newGroup.push(node.pointNumber);\n                }\n            }\n\n            newGroups = oldGroups\n                .filter(Boolean)\n                .concat([newGroup]);\n\n            Registry.call('_guiRestyle', gd, {\n                'node.groups': [ newGroups ]\n            }, index);\n        }\n    };\n\n    dragOptions.prepFn = function(e, startX, startY) {\n        prepSelect(e, startX, startY, dragOptions, dragMode);\n    };\n\n    dragElement.init(dragOptions);\n}\n\n},{\"../../components/dragelement\":611,\"../../components/fx/layout_attributes\":633,\"../../lib\":719,\"../../lib/setcursor\":739,\"../../plot_api/edit_types\":750,\"../../plots/cartesian/select\":784,\"../../plots/get_data\":802,\"../../registry\":847,\"./plot\":1108}],1104:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar tarjan = _dereq_('strongly-connected-components');\nvar Lib = _dereq_('../../lib');\nvar wrap = _dereq_('../../lib/gup').wrap;\n\nvar isArrayOrTypedArray = Lib.isArrayOrTypedArray;\nvar isIndex = Lib.isIndex;\nvar Colorscale = _dereq_('../../components/colorscale');\n\nfunction convertToD3Sankey(trace) {\n    var nodeSpec = trace.node;\n    var linkSpec = trace.link;\n\n    var links = [];\n    var hasLinkColorArray = isArrayOrTypedArray(linkSpec.color);\n    var linkedNodes = {};\n\n    var components = {};\n    var componentCount = linkSpec.colorscales.length;\n    var i;\n    for(i = 0; i < componentCount; i++) {\n        var cscale = linkSpec.colorscales[i];\n        var specs = Colorscale.extractScale(cscale, {cLetter: 'c'});\n        var scale = Colorscale.makeColorScaleFunc(specs);\n        components[cscale.label] = scale;\n    }\n\n    var maxNodeId = 0;\n    for(i = 0; i < linkSpec.value.length; i++) {\n        if(linkSpec.source[i] > maxNodeId) maxNodeId = linkSpec.source[i];\n        if(linkSpec.target[i] > maxNodeId) maxNodeId = linkSpec.target[i];\n    }\n    var nodeCount = maxNodeId + 1;\n    trace.node._count = nodeCount;\n\n    // Group nodes\n    var j;\n    var groups = trace.node.groups;\n    var groupLookup = {};\n    for(i = 0; i < groups.length; i++) {\n        var group = groups[i];\n        // Build a lookup table to quickly find in which group a node is\n        for(j = 0; j < group.length; j++) {\n            var nodeIndex = group[j];\n            var groupIndex = nodeCount + i;\n            if(groupLookup.hasOwnProperty(nodeIndex)) {\n                Lib.warn('Node ' + nodeIndex + ' is already part of a group.');\n            } else {\n                groupLookup[nodeIndex] = groupIndex;\n            }\n        }\n    }\n\n    // Process links\n    var groupedLinks = {\n        source: [],\n        target: []\n    };\n    for(i = 0; i < linkSpec.value.length; i++) {\n        var val = linkSpec.value[i];\n        // remove negative values, but keep zeros with special treatment\n        var source = linkSpec.source[i];\n        var target = linkSpec.target[i];\n        if(!(val > 0 && isIndex(source, nodeCount) && isIndex(target, nodeCount))) {\n            continue;\n        }\n\n        // Remove links that are within the same group\n        if(groupLookup.hasOwnProperty(source) && groupLookup.hasOwnProperty(target) && groupLookup[source] === groupLookup[target]) {\n            continue;\n        }\n\n        // if link targets a node in the group, relink target to that group\n        if(groupLookup.hasOwnProperty(target)) {\n            target = groupLookup[target];\n        }\n\n        // if link originates from a node in a group, relink source to that group\n        if(groupLookup.hasOwnProperty(source)) {\n            source = groupLookup[source];\n        }\n\n        source = +source;\n        target = +target;\n        linkedNodes[source] = linkedNodes[target] = true;\n\n        var label = '';\n        if(linkSpec.label && linkSpec.label[i]) label = linkSpec.label[i];\n\n        var concentrationscale = null;\n        if(label && components.hasOwnProperty(label)) concentrationscale = components[label];\n\n        links.push({\n            pointNumber: i,\n            label: label,\n            color: hasLinkColorArray ? linkSpec.color[i] : linkSpec.color,\n            concentrationscale: concentrationscale,\n            source: source,\n            target: target,\n            value: +val\n        });\n\n        groupedLinks.source.push(source);\n        groupedLinks.target.push(target);\n    }\n\n    // Process nodes\n    var totalCount = nodeCount + groups.length;\n    var hasNodeColorArray = isArrayOrTypedArray(nodeSpec.color);\n    var nodes = [];\n    for(i = 0; i < totalCount; i++) {\n        if(!linkedNodes[i]) continue;\n        var l = nodeSpec.label[i];\n\n        nodes.push({\n            group: (i > nodeCount - 1),\n            childrenNodes: [],\n            pointNumber: i,\n            label: l,\n            color: hasNodeColorArray ? nodeSpec.color[i] : nodeSpec.color\n        });\n    }\n\n    // Check if we have circularity on the resulting graph\n    var circular = false;\n    if(circularityPresent(totalCount, groupedLinks.source, groupedLinks.target)) {\n        circular = true;\n    }\n\n    return {\n        circular: circular,\n        links: links,\n        nodes: nodes,\n\n        // Data structure for groups\n        groups: groups,\n        groupLookup: groupLookup\n    };\n}\n\nfunction circularityPresent(nodeLen, sources, targets) {\n    var nodes = Lib.init2dArray(nodeLen, 0);\n\n    for(var i = 0; i < Math.min(sources.length, targets.length); i++) {\n        if(Lib.isIndex(sources[i], nodeLen) && Lib.isIndex(targets[i], nodeLen)) {\n            if(sources[i] === targets[i]) {\n                return true; // self-link which is also a scc of one\n            }\n            nodes[sources[i]].push(targets[i]);\n        }\n    }\n\n    var scc = tarjan(nodes);\n\n    // Tarján's strongly connected components algorithm coded by Mikola Lysenko\n    // returns at least one non-singular component if there's circularity in the graph\n    return scc.components.some(function(c) {\n        return c.length > 1;\n    });\n}\n\nmodule.exports = function calc(gd, trace) {\n    var result = convertToD3Sankey(trace);\n\n    return wrap({\n        circular: result.circular,\n        _nodes: result.nodes,\n        _links: result.links,\n\n        // Data structure for grouping\n        _groups: result.groups,\n        _groupLookup: result.groupLookup,\n    });\n};\n\n},{\"../../components/colorscale\":605,\"../../lib\":719,\"../../lib/gup\":717,\"strongly-connected-components\":530}],1105:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    nodeTextOffsetHorizontal: 4,\n    nodeTextOffsetVertical: 3,\n    nodePadAcross: 10,\n    sankeyIterations: 50,\n    forceIterations: 5,\n    forceTicksPerFrame: 10,\n    duration: 500,\n    ease: 'linear',\n    cn: {\n        sankey: 'sankey',\n        sankeyLinks: 'sankey-links',\n        sankeyLink: 'sankey-link',\n        sankeyNodeSet: 'sankey-node-set',\n        sankeyNode: 'sankey-node',\n        nodeRect: 'node-rect',\n        nodeCapture: 'node-capture',\n        nodeCentered: 'node-entered',\n        nodeLabelGuide: 'node-label-guide',\n        nodeLabel: 'node-label',\n        nodeLabelTextPath: 'node-label-text-path'\n    }\n};\n\n},{}],1106:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attributes = _dereq_('./attributes');\nvar Color = _dereq_('../../components/color');\nvar tinycolor = _dereq_('tinycolor2');\nvar handleDomainDefaults = _dereq_('../../plots/domain').defaults;\nvar handleHoverLabelDefaults = _dereq_('../../components/fx/hoverlabel_defaults');\nvar Template = _dereq_('../../plot_api/plot_template');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var hoverlabelDefault = Lib.extendDeep(layout.hoverlabel, traceIn.hoverlabel);\n\n    // node attributes\n    var nodeIn = traceIn.node;\n    var nodeOut = Template.newContainer(traceOut, 'node');\n\n    function coerceNode(attr, dflt) {\n        return Lib.coerce(nodeIn, nodeOut, attributes.node, attr, dflt);\n    }\n    coerceNode('label');\n    coerceNode('groups');\n    coerceNode('x');\n    coerceNode('y');\n    coerceNode('pad');\n    coerceNode('thickness');\n    coerceNode('line.color');\n    coerceNode('line.width');\n    coerceNode('hoverinfo', traceIn.hoverinfo);\n    handleHoverLabelDefaults(nodeIn, nodeOut, coerceNode, hoverlabelDefault);\n    coerceNode('hovertemplate');\n\n    var colors = layout.colorway;\n\n    var defaultNodePalette = function(i) {return colors[i % colors.length];};\n\n    coerceNode('color', nodeOut.label.map(function(d, i) {\n        return Color.addOpacity(defaultNodePalette(i), 0.8);\n    }));\n\n    // link attributes\n    var linkIn = traceIn.link || {};\n    var linkOut = Template.newContainer(traceOut, 'link');\n\n    function coerceLink(attr, dflt) {\n        return Lib.coerce(linkIn, linkOut, attributes.link, attr, dflt);\n    }\n    coerceLink('label');\n    coerceLink('source');\n    coerceLink('target');\n    coerceLink('value');\n    coerceLink('line.color');\n    coerceLink('line.width');\n    coerceLink('hoverinfo', traceIn.hoverinfo);\n    handleHoverLabelDefaults(linkIn, linkOut, coerceLink, hoverlabelDefault);\n    coerceLink('hovertemplate');\n\n    var defaultLinkColor = tinycolor(layout.paper_bgcolor).getLuminance() < 0.333 ?\n                'rgba(255, 255, 255, 0.6)' :\n                'rgba(0, 0, 0, 0.2)';\n\n    coerceLink('color', Lib.repeat(defaultLinkColor, linkOut.value.length));\n\n    handleArrayContainerDefaults(linkIn, linkOut, {\n        name: 'colorscales',\n        handleItemDefaults: concentrationscalesDefaults\n    });\n\n    handleDomainDefaults(traceOut, layout, coerce);\n\n    coerce('orientation');\n    coerce('valueformat');\n    coerce('valuesuffix');\n\n    var dfltArrangement;\n    if(nodeOut.x.length && nodeOut.y.length) {\n        dfltArrangement = 'freeform';\n    }\n    coerce('arrangement', dfltArrangement);\n\n    Lib.coerceFont(coerce, 'textfont', Lib.extendFlat({}, layout.font));\n\n    // disable 1D transforms - arrays here are 1D but their lengths/meanings\n    // don't match, between nodes and links\n    traceOut._length = null;\n};\n\nfunction concentrationscalesDefaults(In, Out) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(In, Out, attributes.link.colorscales, attr, dflt);\n    }\n\n    coerce('label');\n    coerce('cmin');\n    coerce('cmax');\n    coerce('colorscale');\n}\n\n},{\"../../components/color\":593,\"../../components/fx/hoverlabel_defaults\":630,\"../../lib\":719,\"../../plot_api/plot_template\":757,\"../../plots/array_container_defaults\":763,\"../../plots/domain\":792,\"./attributes\":1102,\"tinycolor2\":537}],1107:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n\n    moduleType: 'trace',\n    name: 'sankey',\n    basePlotModule: _dereq_('./base_plot'),\n    selectPoints: _dereq_('./select.js'),\n    categories: ['noOpacity'],\n    meta: {\n        \n    }\n};\n\n},{\"./attributes\":1102,\"./base_plot\":1103,\"./calc\":1104,\"./defaults\":1106,\"./plot\":1108,\"./select.js\":1110}],1108:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar render = _dereq_('./render');\nvar Fx = _dereq_('../../components/fx');\nvar Color = _dereq_('../../components/color');\nvar Lib = _dereq_('../../lib');\nvar cn = _dereq_('./constants').cn;\n\nvar _ = Lib._;\n\nfunction renderableValuePresent(d) {return d !== '';}\n\nfunction ownTrace(selection, d) {\n    return selection.filter(function(s) {return s.key === d.traceId;});\n}\n\nfunction makeTranslucent(element, alpha) {\n    d3.select(element)\n        .select('path')\n        .style('fill-opacity', alpha);\n    d3.select(element)\n        .select('rect')\n        .style('fill-opacity', alpha);\n}\n\nfunction makeTextContrasty(element) {\n    d3.select(element)\n        .select('text.name')\n        .style('fill', 'black');\n}\n\nfunction relatedLinks(d) {\n    return function(l) {\n        return d.node.sourceLinks.indexOf(l.link) !== -1 || d.node.targetLinks.indexOf(l.link) !== -1;\n    };\n}\n\nfunction relatedNodes(l) {\n    return function(d) {\n        return d.node.sourceLinks.indexOf(l.link) !== -1 || d.node.targetLinks.indexOf(l.link) !== -1;\n    };\n}\n\nfunction nodeHoveredStyle(sankeyNode, d, sankey) {\n    if(d && sankey) {\n        ownTrace(sankey, d)\n            .selectAll('.' + cn.sankeyLink)\n            .filter(relatedLinks(d))\n            .call(linkHoveredStyle.bind(0, d, sankey, false));\n    }\n}\n\nfunction nodeNonHoveredStyle(sankeyNode, d, sankey) {\n    if(d && sankey) {\n        ownTrace(sankey, d)\n            .selectAll('.' + cn.sankeyLink)\n            .filter(relatedLinks(d))\n            .call(linkNonHoveredStyle.bind(0, d, sankey, false));\n    }\n}\n\nfunction linkHoveredStyle(d, sankey, visitNodes, sankeyLink) {\n    var label = sankeyLink.datum().link.label;\n\n    sankeyLink.style('fill-opacity', function(l) {\n        if(!l.link.concentrationscale) {\n            return 0.4;\n        }\n    });\n\n    if(label) {\n        ownTrace(sankey, d)\n            .selectAll('.' + cn.sankeyLink)\n            .filter(function(l) {return l.link.label === label;})\n            .style('fill-opacity', function(l) {\n                if(!l.link.concentrationscale) {\n                    return 0.4;\n                }\n            });\n    }\n\n    if(visitNodes) {\n        ownTrace(sankey, d)\n            .selectAll('.' + cn.sankeyNode)\n            .filter(relatedNodes(d))\n            .call(nodeHoveredStyle);\n    }\n}\n\nfunction linkNonHoveredStyle(d, sankey, visitNodes, sankeyLink) {\n    var label = sankeyLink.datum().link.label;\n\n    sankeyLink.style('fill-opacity', function(d) {return d.tinyColorAlpha;});\n    if(label) {\n        ownTrace(sankey, d)\n            .selectAll('.' + cn.sankeyLink)\n            .filter(function(l) {return l.link.label === label;})\n            .style('fill-opacity', function(d) {return d.tinyColorAlpha;});\n    }\n\n    if(visitNodes) {\n        ownTrace(sankey, d)\n            .selectAll(cn.sankeyNode)\n            .filter(relatedNodes(d))\n            .call(nodeNonHoveredStyle);\n    }\n}\n\n// does not support array values for now\nfunction castHoverOption(trace, attr) {\n    var labelOpts = trace.hoverlabel || {};\n    var val = Lib.nestedProperty(labelOpts, attr).get();\n    return Array.isArray(val) ? false : val;\n}\n\nmodule.exports = function plot(gd, calcData) {\n    var fullLayout = gd._fullLayout;\n    var svg = fullLayout._paper;\n    var size = fullLayout._size;\n\n    // stash initial view\n    for(var i = 0; i < gd._fullData.length; i++) {\n        if(gd._fullData[i].type !== cn.sankey) continue;\n        if(!gd._fullData[i]._viewInitial) {\n            var node = gd._fullData[i].node;\n            gd._fullData[i]._viewInitial = {\n                node: {\n                    groups: node.groups.slice(),\n                    x: node.x.slice(),\n                    y: node.y.slice()\n                }\n            };\n        }\n    }\n\n    var linkSelect = function(element, d) {\n        var evt = d.link;\n        evt.originalEvent = d3.event;\n        gd._hoverdata = [evt];\n        Fx.click(gd, { target: true });\n    };\n\n    var linkHover = function(element, d, sankey) {\n        if(gd._fullLayout.hovermode === false) return;\n        d3.select(element).call(linkHoveredStyle.bind(0, d, sankey, true));\n        if(d.link.trace.link.hoverinfo !== 'skip') {\n            d.link.fullData = d.link.trace;\n            gd.emit('plotly_hover', {\n                event: d3.event,\n                points: [d.link]\n            });\n        }\n    };\n\n    var sourceLabel = _(gd, 'source:') + ' ';\n    var targetLabel = _(gd, 'target:') + ' ';\n    var concentrationLabel = _(gd, 'concentration:') + ' ';\n    var incomingLabel = _(gd, 'incoming flow count:') + ' ';\n    var outgoingLabel = _(gd, 'outgoing flow count:') + ' ';\n\n    var linkHoverFollow = function(element, d) {\n        if(gd._fullLayout.hovermode === false) return;\n        var obj = d.link.trace.link;\n        if(obj.hoverinfo === 'none' || obj.hoverinfo === 'skip') return;\n\n        var hoverItems = [];\n\n        function hoverCenterPosition(link) {\n            var hoverCenterX, hoverCenterY;\n            if(link.circular) {\n                hoverCenterX = (link.circularPathData.leftInnerExtent + link.circularPathData.rightInnerExtent) / 2 + d.parent.translateX;\n                hoverCenterY = link.circularPathData.verticalFullExtent + d.parent.translateY;\n            } else {\n                hoverCenterX = (link.source.x1 + link.target.x0) / 2 + d.parent.translateX;\n                hoverCenterY = (link.y0 + link.y1) / 2 + d.parent.translateY;\n            }\n            return [hoverCenterX, hoverCenterY];\n        }\n\n        // For each related links, create a hoverItem\n        var anchorIndex = 0;\n        for(var i = 0; i < d.flow.links.length; i++) {\n            var link = d.flow.links[i];\n            if(gd._fullLayout.hovermode === 'closest' && d.link.pointNumber !== link.pointNumber) continue;\n            if(d.link.pointNumber === link.pointNumber) anchorIndex = i;\n            link.fullData = link.trace;\n            obj = d.link.trace.link;\n            var hoverCenter = hoverCenterPosition(link);\n            var hovertemplateLabels = {valueLabel: d3.format(d.valueFormat)(link.value) + d.valueSuffix};\n\n            hoverItems.push({\n                x: hoverCenter[0],\n                y: hoverCenter[1],\n                name: hovertemplateLabels.valueLabel,\n                text: [\n                    link.label || '',\n                    sourceLabel + link.source.label,\n                    targetLabel + link.target.label,\n                    link.concentrationscale ? concentrationLabel + d3.format('%0.2f')(link.flow.labelConcentration) : ''\n                ].filter(renderableValuePresent).join('<br>'),\n                color: castHoverOption(obj, 'bgcolor') || Color.addOpacity(link.color, 1),\n                borderColor: castHoverOption(obj, 'bordercolor'),\n                fontFamily: castHoverOption(obj, 'font.family'),\n                fontSize: castHoverOption(obj, 'font.size'),\n                fontColor: castHoverOption(obj, 'font.color'),\n                nameLength: castHoverOption(obj, 'namelength'),\n                textAlign: castHoverOption(obj, 'align'),\n                idealAlign: d3.event.x < hoverCenter[0] ? 'right' : 'left',\n\n                hovertemplate: obj.hovertemplate,\n                hovertemplateLabels: hovertemplateLabels,\n                eventData: [link]\n            });\n        }\n\n        var tooltips = Fx.loneHover(hoverItems, {\n            container: fullLayout._hoverlayer.node(),\n            outerContainer: fullLayout._paper.node(),\n            gd: gd,\n            anchorIndex: anchorIndex\n        });\n\n        tooltips.each(function() {\n            var tooltip = this;\n            if(!d.link.concentrationscale) {\n                makeTranslucent(tooltip, 0.65);\n            }\n            makeTextContrasty(tooltip);\n        });\n    };\n\n    var linkUnhover = function(element, d, sankey) {\n        if(gd._fullLayout.hovermode === false) return;\n        d3.select(element).call(linkNonHoveredStyle.bind(0, d, sankey, true));\n        if(d.link.trace.link.hoverinfo !== 'skip') {\n            d.link.fullData = d.link.trace;\n            gd.emit('plotly_unhover', {\n                event: d3.event,\n                points: [d.link]\n            });\n        }\n\n        Fx.loneUnhover(fullLayout._hoverlayer.node());\n    };\n\n    var nodeSelect = function(element, d, sankey) {\n        var evt = d.node;\n        evt.originalEvent = d3.event;\n        gd._hoverdata = [evt];\n        d3.select(element).call(nodeNonHoveredStyle, d, sankey);\n        Fx.click(gd, { target: true });\n    };\n\n    var nodeHover = function(element, d, sankey) {\n        if(gd._fullLayout.hovermode === false) return;\n        d3.select(element).call(nodeHoveredStyle, d, sankey);\n        if(d.node.trace.node.hoverinfo !== 'skip') {\n            d.node.fullData = d.node.trace;\n            gd.emit('plotly_hover', {\n                event: d3.event,\n                points: [d.node]\n            });\n        }\n    };\n\n    var nodeHoverFollow = function(element, d) {\n        if(gd._fullLayout.hovermode === false) return;\n\n        var obj = d.node.trace.node;\n        if(obj.hoverinfo === 'none' || obj.hoverinfo === 'skip') return;\n        var nodeRect = d3.select(element).select('.' + cn.nodeRect);\n        var rootBBox = gd._fullLayout._paperdiv.node().getBoundingClientRect();\n        var boundingBox = nodeRect.node().getBoundingClientRect();\n        var hoverCenterX0 = boundingBox.left - 2 - rootBBox.left;\n        var hoverCenterX1 = boundingBox.right + 2 - rootBBox.left;\n        var hoverCenterY = boundingBox.top + boundingBox.height / 4 - rootBBox.top;\n\n        var hovertemplateLabels = {valueLabel: d3.format(d.valueFormat)(d.node.value) + d.valueSuffix};\n        d.node.fullData = d.node.trace;\n\n        var tooltip = Fx.loneHover({\n            x0: hoverCenterX0,\n            x1: hoverCenterX1,\n            y: hoverCenterY,\n            name: d3.format(d.valueFormat)(d.node.value) + d.valueSuffix,\n            text: [\n                d.node.label,\n                incomingLabel + d.node.targetLinks.length,\n                outgoingLabel + d.node.sourceLinks.length\n            ].filter(renderableValuePresent).join('<br>'),\n            color: castHoverOption(obj, 'bgcolor') || d.tinyColorHue,\n            borderColor: castHoverOption(obj, 'bordercolor'),\n            fontFamily: castHoverOption(obj, 'font.family'),\n            fontSize: castHoverOption(obj, 'font.size'),\n            fontColor: castHoverOption(obj, 'font.color'),\n            nameLength: castHoverOption(obj, 'namelength'),\n            textAlign: castHoverOption(obj, 'align'),\n            idealAlign: 'left',\n\n            hovertemplate: obj.hovertemplate,\n            hovertemplateLabels: hovertemplateLabels,\n            eventData: [d.node]\n        }, {\n            container: fullLayout._hoverlayer.node(),\n            outerContainer: fullLayout._paper.node(),\n            gd: gd\n        });\n\n        makeTranslucent(tooltip, 0.85);\n        makeTextContrasty(tooltip);\n    };\n\n    var nodeUnhover = function(element, d, sankey) {\n        if(gd._fullLayout.hovermode === false) return;\n        d3.select(element).call(nodeNonHoveredStyle, d, sankey);\n        if(d.node.trace.node.hoverinfo !== 'skip') {\n            d.node.fullData = d.node.trace;\n            gd.emit('plotly_unhover', {\n                event: d3.event,\n                points: [d.node]\n            });\n        }\n\n        Fx.loneUnhover(fullLayout._hoverlayer.node());\n    };\n\n    render(\n        gd,\n        svg,\n        calcData,\n        {\n            width: size.w,\n            height: size.h,\n            margin: {\n                t: size.t,\n                r: size.r,\n                b: size.b,\n                l: size.l\n            }\n        },\n        {\n            linkEvents: {\n                hover: linkHover,\n                follow: linkHoverFollow,\n                unhover: linkUnhover,\n                select: linkSelect\n            },\n            nodeEvents: {\n                hover: nodeHover,\n                follow: nodeHoverFollow,\n                unhover: nodeUnhover,\n                select: nodeSelect\n            }\n        }\n    );\n};\n\n},{\"../../components/color\":593,\"../../components/fx\":632,\"../../lib\":719,\"./constants\":1105,\"./render\":1109,\"d3\":163}],1109:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar c = _dereq_('./constants');\nvar d3 = _dereq_('d3');\nvar tinycolor = _dereq_('tinycolor2');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar d3Sankey = _dereq_('@plotly/d3-sankey');\nvar d3SankeyCircular = _dereq_('@plotly/d3-sankey-circular');\nvar d3Force = _dereq_('d3-force');\nvar Lib = _dereq_('../../lib');\nvar gup = _dereq_('../../lib/gup');\nvar keyFun = gup.keyFun;\nvar repeat = gup.repeat;\nvar unwrap = gup.unwrap;\nvar interpolateNumber = _dereq_('d3-interpolate').interpolateNumber;\n\nvar Registry = _dereq_('../../registry');\n\n// view models\n\nfunction sankeyModel(layout, d, traceIndex) {\n    var calcData = unwrap(d);\n    var trace = calcData.trace;\n    var domain = trace.domain;\n    var horizontal = trace.orientation === 'h';\n    var nodePad = trace.node.pad;\n    var nodeThickness = trace.node.thickness;\n\n    var width = layout.width * (domain.x[1] - domain.x[0]);\n    var height = layout.height * (domain.y[1] - domain.y[0]);\n\n    var nodes = calcData._nodes;\n    var links = calcData._links;\n    var circular = calcData.circular;\n\n    // Select Sankey generator\n    var sankey;\n    if(circular) {\n        sankey = d3SankeyCircular\n            .sankeyCircular()\n            .circularLinkGap(0);\n    } else {\n        sankey = d3Sankey.sankey();\n    }\n\n    sankey\n      .iterations(c.sankeyIterations)\n      .size(horizontal ? [width, height] : [height, width])\n      .nodeWidth(nodeThickness)\n      .nodePadding(nodePad)\n      .nodeId(function(d) {\n          return d.pointNumber;\n      })\n      .nodes(nodes)\n      .links(links);\n\n    var graph = sankey();\n\n    if(sankey.nodePadding() < nodePad) {\n        Lib.warn('node.pad was reduced to ', sankey.nodePadding(), ' to fit within the figure.');\n    }\n\n    // Counters for nested loops\n    var i, j, k;\n\n    // Create transient nodes for animations\n    for(var nodePointNumber in calcData._groupLookup) {\n        var groupIndex = parseInt(calcData._groupLookup[nodePointNumber]);\n\n        // Find node representing groupIndex\n        var groupingNode;\n\n        for(i = 0; i < graph.nodes.length; i++) {\n            if(graph.nodes[i].pointNumber === groupIndex) {\n                groupingNode = graph.nodes[i];\n                break;\n            }\n        }\n        // If groupinNode is undefined, no links are targeting this group\n        if(!groupingNode) continue;\n\n        var child = {\n            pointNumber: parseInt(nodePointNumber),\n            x0: groupingNode.x0,\n            x1: groupingNode.x1,\n            y0: groupingNode.y0,\n            y1: groupingNode.y1,\n            partOfGroup: true,\n            sourceLinks: [],\n            targetLinks: []\n        };\n\n        graph.nodes.unshift(child);\n        groupingNode.childrenNodes.unshift(child);\n    }\n\n    function computeLinkConcentrations() {\n        for(i = 0; i < graph.nodes.length; i++) {\n            var node = graph.nodes[i];\n            // Links connecting the same two nodes are part of a flow\n            var flows = {};\n            var flowKey;\n            var link;\n            for(j = 0; j < node.targetLinks.length; j++) {\n                link = node.targetLinks[j];\n                flowKey = link.source.pointNumber + ':' + link.target.pointNumber;\n                if(!flows.hasOwnProperty(flowKey)) flows[flowKey] = [];\n                flows[flowKey].push(link);\n            }\n\n            // Compute statistics for each flow\n            var keys = Object.keys(flows);\n            for(j = 0; j < keys.length; j++) {\n                flowKey = keys[j];\n                var flowLinks = flows[flowKey];\n\n                // Find the total size of the flow and total size per label\n                var total = 0;\n                var totalPerLabel = {};\n                for(k = 0; k < flowLinks.length; k++) {\n                    link = flowLinks[k];\n                    if(!totalPerLabel[link.label]) totalPerLabel[link.label] = 0;\n                    totalPerLabel[link.label] += link.value;\n                    total += link.value;\n                }\n\n                // Find the ratio of the link's value and the size of the flow\n                for(k = 0; k < flowLinks.length; k++) {\n                    link = flowLinks[k];\n                    link.flow = {\n                        value: total,\n                        labelConcentration: totalPerLabel[link.label] / total,\n                        concentration: link.value / total,\n                        links: flowLinks\n                    };\n                    if(link.concentrationscale) {\n                        link.color = tinycolor(link.concentrationscale(link.flow.labelConcentration));\n                    }\n                }\n            }\n\n            // Gather statistics of all links at current node\n            var totalOutflow = 0;\n            for(j = 0; j < node.sourceLinks.length; j++) {\n                totalOutflow += node.sourceLinks[j].value;\n            }\n            for(j = 0; j < node.sourceLinks.length; j++) {\n                link = node.sourceLinks[j];\n                link.concentrationOut = link.value / totalOutflow;\n            }\n\n            var totalInflow = 0;\n            for(j = 0; j < node.targetLinks.length; j++) {\n                totalInflow += node.targetLinks[j].value;\n            }\n\n            for(j = 0; j < node.targetLinks.length; j++) {\n                link = node.targetLinks[j];\n                link.concenrationIn = link.value / totalInflow;\n            }\n        }\n    }\n    computeLinkConcentrations();\n\n    // Push any overlapping nodes down.\n    function resolveCollisionsTopToBottom(columns) {\n        columns.forEach(function(nodes) {\n            var node;\n            var dy;\n            var y = 0;\n            var n = nodes.length;\n            var i;\n            nodes.sort(function(a, b) {\n                return a.y0 - b.y0;\n            });\n            for(i = 0; i < n; ++i) {\n                node = nodes[i];\n                if(node.y0 >= y) {\n                    // No overlap\n                } else {\n                    dy = (y - node.y0);\n                    if(dy > 1e-6) node.y0 += dy, node.y1 += dy;\n                }\n                y = node.y1 + nodePad;\n            }\n        });\n    }\n\n    // Group nodes into columns based on their x position\n    function snapToColumns(nodes) {\n        // Sort nodes by x position\n        var orderedNodes = nodes.map(function(n, i) {\n            return {\n                x0: n.x0,\n                index: i\n            };\n        })\n        .sort(function(a, b) {\n            return a.x0 - b.x0;\n        });\n\n        var columns = [];\n        var colNumber = -1;\n        var colX; // Position of column\n        var lastX = -Infinity; // Position of last node\n        var dx;\n        for(i = 0; i < orderedNodes.length; i++) {\n            var node = nodes[orderedNodes[i].index];\n            // If the node does not overlap with the last one\n            if(node.x0 > lastX + nodeThickness) {\n                // Start a new column\n                colNumber += 1;\n                colX = node.x0;\n            }\n            lastX = node.x0;\n\n            // Add node to its associated column\n            if(!columns[colNumber]) columns[colNumber] = [];\n            columns[colNumber].push(node);\n\n            // Change node's x position to align it with its column\n            dx = colX - node.x0;\n            node.x0 += dx, node.x1 += dx;\n        }\n        return columns;\n    }\n\n    // Force node position\n    if(trace.node.x.length && trace.node.y.length) {\n        for(i = 0; i < Math.min(trace.node.x.length, trace.node.y.length, graph.nodes.length); i++) {\n            if(trace.node.x[i] && trace.node.y[i]) {\n                var pos = [trace.node.x[i] * width, trace.node.y[i] * height];\n                graph.nodes[i].x0 = pos[0] - nodeThickness / 2;\n                graph.nodes[i].x1 = pos[0] + nodeThickness / 2;\n\n                var nodeHeight = graph.nodes[i].y1 - graph.nodes[i].y0;\n                graph.nodes[i].y0 = pos[1] - nodeHeight / 2;\n                graph.nodes[i].y1 = pos[1] + nodeHeight / 2;\n            }\n        }\n        if(trace.arrangement === 'snap') {\n            nodes = graph.nodes;\n            var columns = snapToColumns(nodes);\n            resolveCollisionsTopToBottom(columns);\n        }\n        // Update links\n        sankey.update(graph);\n    }\n\n\n    return {\n        circular: circular,\n        key: traceIndex,\n        trace: trace,\n        guid: Lib.randstr(),\n        horizontal: horizontal,\n        width: width,\n        height: height,\n        nodePad: trace.node.pad,\n        nodeLineColor: trace.node.line.color,\n        nodeLineWidth: trace.node.line.width,\n        linkLineColor: trace.link.line.color,\n        linkLineWidth: trace.link.line.width,\n        valueFormat: trace.valueformat,\n        valueSuffix: trace.valuesuffix,\n        textFont: trace.textfont,\n        translateX: domain.x[0] * layout.width + layout.margin.l,\n        translateY: layout.height - domain.y[1] * layout.height + layout.margin.t,\n        dragParallel: horizontal ? height : width,\n        dragPerpendicular: horizontal ? width : height,\n        arrangement: trace.arrangement,\n        sankey: sankey,\n        graph: graph,\n        forceLayouts: {},\n        interactionState: {\n            dragInProgress: false,\n            hovered: false\n        }\n    };\n}\n\nfunction linkModel(d, l, i) {\n    var tc = tinycolor(l.color);\n    var basicKey = l.source.label + '|' + l.target.label;\n    var key = basicKey + '__' + i;\n\n    // for event data\n    l.trace = d.trace;\n    l.curveNumber = d.trace.index;\n\n    return {\n        circular: d.circular,\n        key: key,\n        traceId: d.key,\n        pointNumber: l.pointNumber,\n        link: l,\n        tinyColorHue: Color.tinyRGB(tc),\n        tinyColorAlpha: tc.getAlpha(),\n        linkPath: linkPath,\n        linkLineColor: d.linkLineColor,\n        linkLineWidth: d.linkLineWidth,\n        valueFormat: d.valueFormat,\n        valueSuffix: d.valueSuffix,\n        sankey: d.sankey,\n        parent: d,\n        interactionState: d.interactionState,\n        flow: l.flow\n    };\n}\n\nfunction createCircularClosedPathString(link) {\n    // Using coordinates computed by d3-sankey-circular\n    var pathString = '';\n    var offset = link.width / 2;\n    var coords = link.circularPathData;\n    if(link.circularLinkType === 'top') {\n        // Top path\n        pathString =\n          // start at the left of the target node\n          'M ' +\n          coords.targetX + ' ' + (coords.targetY + offset) + ' ' +\n          'L' +\n          coords.rightInnerExtent + ' ' + (coords.targetY + offset) +\n          'A' +\n          (coords.rightLargeArcRadius + offset) + ' ' + (coords.rightSmallArcRadius + offset) + ' 0 0 1 ' +\n          (coords.rightFullExtent - offset) + ' ' + (coords.targetY - coords.rightSmallArcRadius) +\n          'L' +\n          (coords.rightFullExtent - offset) + ' ' + coords.verticalRightInnerExtent +\n          'A' +\n          (coords.rightLargeArcRadius + offset) + ' ' + (coords.rightLargeArcRadius + offset) + ' 0 0 1 ' +\n          coords.rightInnerExtent + ' ' + (coords.verticalFullExtent - offset) +\n          'L' +\n          coords.leftInnerExtent + ' ' + (coords.verticalFullExtent - offset) +\n          'A' +\n          (coords.leftLargeArcRadius + offset) + ' ' + (coords.leftLargeArcRadius + offset) + ' 0 0 1 ' +\n          (coords.leftFullExtent + offset) + ' ' + coords.verticalLeftInnerExtent +\n          'L' +\n          (coords.leftFullExtent + offset) + ' ' + (coords.sourceY - coords.leftSmallArcRadius) +\n          'A' +\n          (coords.leftLargeArcRadius + offset) + ' ' + (coords.leftSmallArcRadius + offset) + ' 0 0 1 ' +\n          coords.leftInnerExtent + ' ' + (coords.sourceY + offset) +\n          'L' +\n          coords.sourceX + ' ' + (coords.sourceY + offset) +\n\n          // Walking back\n          'L' +\n          coords.sourceX + ' ' + (coords.sourceY - offset) +\n          'L' +\n          coords.leftInnerExtent + ' ' + (coords.sourceY - offset) +\n          'A' +\n          (coords.leftLargeArcRadius - offset) + ' ' + (coords.leftSmallArcRadius - offset) + ' 0 0 0 ' +\n          (coords.leftFullExtent - offset) + ' ' + (coords.sourceY - coords.leftSmallArcRadius) +\n          'L' +\n          (coords.leftFullExtent - offset) + ' ' + coords.verticalLeftInnerExtent +\n          'A' +\n          (coords.leftLargeArcRadius - offset) + ' ' + (coords.leftLargeArcRadius - offset) + ' 0 0 0 ' +\n          coords.leftInnerExtent + ' ' + (coords.verticalFullExtent + offset) +\n          'L' +\n          coords.rightInnerExtent + ' ' + (coords.verticalFullExtent + offset) +\n          'A' +\n          (coords.rightLargeArcRadius - offset) + ' ' + (coords.rightLargeArcRadius - offset) + ' 0 0 0 ' +\n          (coords.rightFullExtent + offset) + ' ' + coords.verticalRightInnerExtent +\n          'L' +\n          (coords.rightFullExtent + offset) + ' ' + (coords.targetY - coords.rightSmallArcRadius) +\n          'A' +\n          (coords.rightLargeArcRadius - offset) + ' ' + (coords.rightSmallArcRadius - offset) + ' 0 0 0 ' +\n          coords.rightInnerExtent + ' ' + (coords.targetY - offset) +\n          'L' +\n          coords.targetX + ' ' + (coords.targetY - offset) +\n          'Z';\n    } else {\n        // Bottom path\n        pathString =\n          // start at the left of the target node\n          'M ' +\n          coords.targetX + ' ' + (coords.targetY - offset) + ' ' +\n          'L' +\n          coords.rightInnerExtent + ' ' + (coords.targetY - offset) +\n          'A' +\n          (coords.rightLargeArcRadius + offset) + ' ' + (coords.rightSmallArcRadius + offset) + ' 0 0 0 ' +\n          (coords.rightFullExtent - offset) + ' ' + (coords.targetY + coords.rightSmallArcRadius) +\n          'L' +\n          (coords.rightFullExtent - offset) + ' ' + coords.verticalRightInnerExtent +\n          'A' +\n          (coords.rightLargeArcRadius + offset) + ' ' + (coords.rightLargeArcRadius + offset) + ' 0 0 0 ' +\n          coords.rightInnerExtent + ' ' + (coords.verticalFullExtent + offset) +\n          'L' +\n          coords.leftInnerExtent + ' ' + (coords.verticalFullExtent + offset) +\n          'A' +\n          (coords.leftLargeArcRadius + offset) + ' ' + (coords.leftLargeArcRadius + offset) + ' 0 0 0 ' +\n          (coords.leftFullExtent + offset) + ' ' + coords.verticalLeftInnerExtent +\n          'L' +\n          (coords.leftFullExtent + offset) + ' ' + (coords.sourceY + coords.leftSmallArcRadius) +\n          'A' +\n          (coords.leftLargeArcRadius + offset) + ' ' + (coords.leftSmallArcRadius + offset) + ' 0 0 0 ' +\n          coords.leftInnerExtent + ' ' + (coords.sourceY - offset) +\n          'L' +\n          coords.sourceX + ' ' + (coords.sourceY - offset) +\n\n          // Walking back\n          'L' +\n          coords.sourceX + ' ' + (coords.sourceY + offset) +\n          'L' +\n          coords.leftInnerExtent + ' ' + (coords.sourceY + offset) +\n          'A' +\n          (coords.leftLargeArcRadius - offset) + ' ' + (coords.leftSmallArcRadius - offset) + ' 0 0 1 ' +\n          (coords.leftFullExtent - offset) + ' ' + (coords.sourceY + coords.leftSmallArcRadius) +\n          'L' +\n          (coords.leftFullExtent - offset) + ' ' + coords.verticalLeftInnerExtent +\n          'A' +\n          (coords.leftLargeArcRadius - offset) + ' ' + (coords.leftLargeArcRadius - offset) + ' 0 0 1 ' +\n          coords.leftInnerExtent + ' ' + (coords.verticalFullExtent - offset) +\n          'L' +\n          coords.rightInnerExtent + ' ' + (coords.verticalFullExtent - offset) +\n          'A' +\n          (coords.rightLargeArcRadius - offset) + ' ' + (coords.rightLargeArcRadius - offset) + ' 0 0 1 ' +\n          (coords.rightFullExtent + offset) + ' ' + coords.verticalRightInnerExtent +\n          'L' +\n          (coords.rightFullExtent + offset) + ' ' + (coords.targetY + coords.rightSmallArcRadius) +\n          'A' +\n          (coords.rightLargeArcRadius - offset) + ' ' + (coords.rightSmallArcRadius - offset) + ' 0 0 1 ' +\n          coords.rightInnerExtent + ' ' + (coords.targetY + offset) +\n          'L' +\n          coords.targetX + ' ' + (coords.targetY + offset) +\n          'Z';\n    }\n    return pathString;\n}\n\nfunction linkPath() {\n    var curvature = 0.5;\n    function path(d) {\n        if(d.link.circular) {\n            return createCircularClosedPathString(d.link);\n        } else {\n            var x0 = d.link.source.x1;\n            var x1 = d.link.target.x0;\n            var xi = interpolateNumber(x0, x1);\n            var x2 = xi(curvature);\n            var x3 = xi(1 - curvature);\n            var y0a = d.link.y0 - d.link.width / 2;\n            var y0b = d.link.y0 + d.link.width / 2;\n            var y1a = d.link.y1 - d.link.width / 2;\n            var y1b = d.link.y1 + d.link.width / 2;\n            return 'M' + x0 + ',' + y0a +\n                 'C' + x2 + ',' + y0a +\n                 ' ' + x3 + ',' + y1a +\n                 ' ' + x1 + ',' + y1a +\n                 'L' + x1 + ',' + y1b +\n                 'C' + x3 + ',' + y1b +\n                 ' ' + x2 + ',' + y0b +\n                 ' ' + x0 + ',' + y0b +\n                 'Z';\n        }\n    }\n    return path;\n}\n\nfunction nodeModel(d, n) {\n    var tc = tinycolor(n.color);\n    var zoneThicknessPad = c.nodePadAcross;\n    var zoneLengthPad = d.nodePad / 2;\n    n.dx = n.x1 - n.x0;\n    n.dy = n.y1 - n.y0;\n    var visibleThickness = n.dx;\n    var visibleLength = Math.max(0.5, n.dy);\n\n    var key = 'node_' + n.pointNumber;\n    // If it's a group, it's mutable and should be unique\n    if(n.group) {\n        key = Lib.randstr();\n    }\n\n    // for event data\n    n.trace = d.trace;\n    n.curveNumber = d.trace.index;\n\n    return {\n        index: n.pointNumber,\n        key: key,\n        partOfGroup: n.partOfGroup || false,\n        group: n.group,\n        traceId: d.key,\n        trace: d.trace,\n        node: n,\n        nodePad: d.nodePad,\n        nodeLineColor: d.nodeLineColor,\n        nodeLineWidth: d.nodeLineWidth,\n        textFont: d.textFont,\n        size: d.horizontal ? d.height : d.width,\n        visibleWidth: Math.ceil(visibleThickness),\n        visibleHeight: visibleLength,\n        zoneX: -zoneThicknessPad,\n        zoneY: -zoneLengthPad,\n        zoneWidth: visibleThickness + 2 * zoneThicknessPad,\n        zoneHeight: visibleLength + 2 * zoneLengthPad,\n        labelY: d.horizontal ? n.dy / 2 + 1 : n.dx / 2 + 1,\n        left: n.originalLayer === 1,\n        sizeAcross: d.width,\n        forceLayouts: d.forceLayouts,\n        horizontal: d.horizontal,\n        darkBackground: tc.getBrightness() <= 128,\n        tinyColorHue: Color.tinyRGB(tc),\n        tinyColorAlpha: tc.getAlpha(),\n        valueFormat: d.valueFormat,\n        valueSuffix: d.valueSuffix,\n        sankey: d.sankey,\n        graph: d.graph,\n        arrangement: d.arrangement,\n        uniqueNodeLabelPathId: [d.guid, d.key, key].join('_'),\n        interactionState: d.interactionState,\n        figure: d\n    };\n}\n\n// rendering snippets\n\nfunction updateNodePositions(sankeyNode) {\n    sankeyNode\n        .attr('transform', function(d) {\n            return 'translate(' + d.node.x0.toFixed(3) + ', ' + (d.node.y0).toFixed(3) + ')';\n        });\n}\n\nfunction updateNodeShapes(sankeyNode) {\n    sankeyNode.call(updateNodePositions);\n}\n\nfunction updateShapes(sankeyNode, sankeyLink) {\n    sankeyNode.call(updateNodeShapes);\n    sankeyLink.attr('d', linkPath());\n}\n\nfunction sizeNode(rect) {\n    rect\n      .attr('width', function(d) {return d.node.x1 - d.node.x0;})\n      .attr('height', function(d) {return d.visibleHeight;});\n}\n\nfunction salientEnough(d) {return (d.link.width > 1 || d.linkLineWidth > 0);}\n\nfunction sankeyTransform(d) {\n    var offset = 'translate(' + d.translateX + ',' + d.translateY + ')';\n    return offset + (d.horizontal ? 'matrix(1 0 0 1 0 0)' : 'matrix(0 1 1 0 0 0)');\n}\n\nfunction nodeCentering(d) {\n    return 'translate(' + (d.horizontal ? 0 : d.labelY) + ' ' + (d.horizontal ? d.labelY : 0) + ')';\n}\n\nfunction textGuidePath(d) {\n    return d3.svg.line()([\n        [d.horizontal ? (d.left ? -d.sizeAcross : d.visibleWidth + c.nodeTextOffsetHorizontal) : c.nodeTextOffsetHorizontal, 0],\n        [d.horizontal ? (d.left ? - c.nodeTextOffsetHorizontal : d.sizeAcross) : d.visibleHeight - c.nodeTextOffsetHorizontal, 0]\n    ]);\n}\n\nfunction sankeyInverseTransform(d) {return d.horizontal ? 'matrix(1 0 0 1 0 0)' : 'matrix(0 1 1 0 0 0)';}\nfunction textFlip(d) {return d.horizontal ? 'scale(1 1)' : 'scale(-1 1)';}\nfunction nodeTextColor(d) {return d.darkBackground && !d.horizontal ? 'rgb(255,255,255)' : 'rgb(0,0,0)';}\nfunction nodeTextOffset(d) {return d.horizontal && d.left ? '100%' : '0%';}\n\n// event handling\n\nfunction attachPointerEvents(selection, sankey, eventSet) {\n    selection\n        .on('.basic', null) // remove any preexisting handlers\n        .on('mouseover.basic', function(d) {\n            if(!d.interactionState.dragInProgress && !d.partOfGroup) {\n                eventSet.hover(this, d, sankey);\n                d.interactionState.hovered = [this, d];\n            }\n        })\n        .on('mousemove.basic', function(d) {\n            if(!d.interactionState.dragInProgress && !d.partOfGroup) {\n                eventSet.follow(this, d);\n                d.interactionState.hovered = [this, d];\n            }\n        })\n        .on('mouseout.basic', function(d) {\n            if(!d.interactionState.dragInProgress && !d.partOfGroup) {\n                eventSet.unhover(this, d, sankey);\n                d.interactionState.hovered = false;\n            }\n        })\n        .on('click.basic', function(d) {\n            if(d.interactionState.hovered) {\n                eventSet.unhover(this, d, sankey);\n                d.interactionState.hovered = false;\n            }\n            if(!d.interactionState.dragInProgress && !d.partOfGroup) {\n                eventSet.select(this, d, sankey);\n            }\n        });\n}\n\nfunction attachDragHandler(sankeyNode, sankeyLink, callbacks, gd) {\n    var dragBehavior = d3.behavior.drag()\n        .origin(function(d) {\n            return {\n                x: d.node.x0 + d.visibleWidth / 2,\n                y: d.node.y0 + d.visibleHeight / 2\n            };\n        })\n\n        .on('dragstart', function(d) {\n            if(d.arrangement === 'fixed') return;\n            Lib.ensureSingle(gd._fullLayout._infolayer, 'g', 'dragcover', function(s) {\n                gd._fullLayout._dragCover = s;\n            });\n            Lib.raiseToTop(this);\n            d.interactionState.dragInProgress = d.node;\n\n            saveCurrentDragPosition(d.node);\n            if(d.interactionState.hovered) {\n                callbacks.nodeEvents.unhover.apply(0, d.interactionState.hovered);\n                d.interactionState.hovered = false;\n            }\n            if(d.arrangement === 'snap') {\n                var forceKey = d.traceId + '|' + d.key;\n                if(d.forceLayouts[forceKey]) {\n                    d.forceLayouts[forceKey].alpha(1);\n                } else { // make a forceLayout if needed\n                    attachForce(sankeyNode, forceKey, d, gd);\n                }\n                startForce(sankeyNode, sankeyLink, d, forceKey, gd);\n            }\n        })\n\n        .on('drag', function(d) {\n            if(d.arrangement === 'fixed') return;\n            var x = d3.event.x;\n            var y = d3.event.y;\n            if(d.arrangement === 'snap') {\n                d.node.x0 = x - d.visibleWidth / 2;\n                d.node.x1 = x + d.visibleWidth / 2;\n                d.node.y0 = y - d.visibleHeight / 2;\n                d.node.y1 = y + d.visibleHeight / 2;\n            } else {\n                if(d.arrangement === 'freeform') {\n                    d.node.x0 = x - d.visibleWidth / 2;\n                    d.node.x1 = x + d.visibleWidth / 2;\n                }\n                y = Math.max(0, Math.min(d.size - d.visibleHeight / 2, y));\n                d.node.y0 = y - d.visibleHeight / 2;\n                d.node.y1 = y + d.visibleHeight / 2;\n            }\n\n            saveCurrentDragPosition(d.node);\n            if(d.arrangement !== 'snap') {\n                d.sankey.update(d.graph);\n                updateShapes(sankeyNode.filter(sameLayer(d)), sankeyLink);\n            }\n        })\n\n        .on('dragend', function(d) {\n            if(d.arrangement === 'fixed') return;\n            d.interactionState.dragInProgress = false;\n            for(var i = 0; i < d.node.childrenNodes.length; i++) {\n                d.node.childrenNodes[i].x = d.node.x;\n                d.node.childrenNodes[i].y = d.node.y;\n            }\n            if(d.arrangement !== 'snap') persistFinalNodePositions(d, gd);\n        });\n\n    sankeyNode\n        .on('.drag', null) // remove possible previous handlers\n        .call(dragBehavior);\n}\n\nfunction attachForce(sankeyNode, forceKey, d, gd) {\n    // Attach force to nodes in the same column (same x coordinate)\n    switchToForceFormat(d.graph.nodes);\n    var nodes = d.graph.nodes\n        .filter(function(n) {return n.originalX === d.node.originalX;})\n        // Filter out children\n        .filter(function(n) {return !n.partOfGroup;});\n    d.forceLayouts[forceKey] = d3Force.forceSimulation(nodes)\n        .alphaDecay(0)\n        .force('collide', d3Force.forceCollide()\n            .radius(function(n) {return n.dy / 2 + d.nodePad / 2;})\n            .strength(1)\n            .iterations(c.forceIterations))\n        .force('constrain', snappingForce(sankeyNode, forceKey, nodes, d, gd))\n        .stop();\n}\n\nfunction startForce(sankeyNode, sankeyLink, d, forceKey, gd) {\n    window.requestAnimationFrame(function faster() {\n        var i;\n        for(i = 0; i < c.forceTicksPerFrame; i++) {\n            d.forceLayouts[forceKey].tick();\n        }\n\n        var nodes = d.graph.nodes;\n        switchToSankeyFormat(nodes);\n\n        d.sankey.update(d.graph);\n        updateShapes(sankeyNode.filter(sameLayer(d)), sankeyLink);\n\n        if(d.forceLayouts[forceKey].alpha() > 0) {\n            window.requestAnimationFrame(faster);\n        } else {\n            // Make sure the final x position is equal to its original value\n            // because the force simulation will have numerical error\n            var x = d.node.originalX;\n            d.node.x0 = x - d.visibleWidth / 2;\n            d.node.x1 = x + d.visibleWidth / 2;\n\n            persistFinalNodePositions(d, gd);\n        }\n    });\n}\n\nfunction snappingForce(sankeyNode, forceKey, nodes, d) {\n    return function _snappingForce() {\n        var maxVelocity = 0;\n        for(var i = 0; i < nodes.length; i++) {\n            var n = nodes[i];\n            if(n === d.interactionState.dragInProgress) { // constrain node position to the dragging pointer\n                n.x = n.lastDraggedX;\n                n.y = n.lastDraggedY;\n            } else {\n                n.vx = (n.originalX - n.x) / c.forceTicksPerFrame; // snap to layer\n                n.y = Math.min(d.size - n.dy / 2, Math.max(n.dy / 2, n.y)); // constrain to extent\n            }\n            maxVelocity = Math.max(maxVelocity, Math.abs(n.vx), Math.abs(n.vy));\n        }\n        if(!d.interactionState.dragInProgress && maxVelocity < 0.1 && d.forceLayouts[forceKey].alpha() > 0) {\n            d.forceLayouts[forceKey].alpha(0); // This will stop the animation loop\n        }\n    };\n}\n\n// basic data utilities\n\nfunction persistFinalNodePositions(d, gd) {\n    var x = [];\n    var y = [];\n    for(var i = 0; i < d.graph.nodes.length; i++) {\n        var nodeX = (d.graph.nodes[i].x0 + d.graph.nodes[i].x1) / 2;\n        var nodeY = (d.graph.nodes[i].y0 + d.graph.nodes[i].y1) / 2;\n        x.push(nodeX / d.figure.width);\n        y.push(nodeY / d.figure.height);\n    }\n    Registry.call('_guiRestyle', gd, {\n        'node.x': [x],\n        'node.y': [y]\n    }, d.trace.index)\n    .then(function() {\n        if(gd._fullLayout._dragCover) gd._fullLayout._dragCover.remove();\n    });\n}\n\nfunction persistOriginalPlace(nodes) {\n    var distinctLayerPositions = [];\n    var i;\n    for(i = 0; i < nodes.length; i++) {\n        nodes[i].originalX = (nodes[i].x0 + nodes[i].x1) / 2;\n        nodes[i].originalY = (nodes[i].y0 + nodes[i].y1) / 2;\n        if(distinctLayerPositions.indexOf(nodes[i].originalX) === -1) {\n            distinctLayerPositions.push(nodes[i].originalX);\n        }\n    }\n    distinctLayerPositions.sort(function(a, b) {return a - b;});\n    for(i = 0; i < nodes.length; i++) {\n        nodes[i].originalLayerIndex = distinctLayerPositions.indexOf(nodes[i].originalX);\n        nodes[i].originalLayer = nodes[i].originalLayerIndex / (distinctLayerPositions.length - 1);\n    }\n}\n\nfunction saveCurrentDragPosition(d) {\n    d.lastDraggedX = d.x0 + d.dx / 2;\n    d.lastDraggedY = d.y0 + d.dy / 2;\n}\n\nfunction sameLayer(d) {\n    return function(n) {return n.node.originalX === d.node.originalX;};\n}\n\nfunction switchToForceFormat(nodes) {\n    // force uses x, y as centers\n    for(var i = 0; i < nodes.length; i++) {\n        nodes[i].y = (nodes[i].y0 + nodes[i].y1) / 2;\n        nodes[i].x = (nodes[i].x0 + nodes[i].x1) / 2;\n    }\n}\n\nfunction switchToSankeyFormat(nodes) {\n    // sankey uses x0, x1, y0, y1\n    for(var i = 0; i < nodes.length; i++) {\n        nodes[i].y0 = nodes[i].y - nodes[i].dy / 2;\n        nodes[i].y1 = nodes[i].y0 + nodes[i].dy;\n\n        nodes[i].x0 = nodes[i].x - nodes[i].dx / 2;\n        nodes[i].x1 = nodes[i].x0 + nodes[i].dx;\n    }\n}\n\n// scene graph\nmodule.exports = function(gd, svg, calcData, layout, callbacks) {\n    // To prevent animation on first render\n    var firstRender = false;\n    Lib.ensureSingle(gd._fullLayout._infolayer, 'g', 'first-render', function() {\n        firstRender = true;\n    });\n\n    // To prevent animation on dragging\n    var dragcover = gd._fullLayout._dragCover;\n\n    var styledData = calcData\n            .filter(function(d) {return unwrap(d).trace.visible;})\n            .map(sankeyModel.bind(null, layout));\n\n    var sankey = svg.selectAll('.' + c.cn.sankey)\n        .data(styledData, keyFun);\n\n    sankey.exit()\n        .remove();\n\n    sankey.enter()\n        .append('g')\n        .classed(c.cn.sankey, true)\n        .style('box-sizing', 'content-box')\n        .style('position', 'absolute')\n        .style('left', 0)\n        .style('shape-rendering', 'geometricPrecision')\n        .style('pointer-events', 'auto')\n        .attr('transform', sankeyTransform);\n\n    sankey.each(function(d, i) {\n        gd._fullData[i]._sankey = d;\n        // Create dragbox if missing\n        var dragboxClassName = 'bgsankey-' + d.trace.uid + '-' + i;\n        Lib.ensureSingle(gd._fullLayout._draggers, 'rect', dragboxClassName);\n\n        gd._fullData[i]._bgRect = d3.select('.' + dragboxClassName);\n\n        // Style dragbox\n        gd._fullData[i]._bgRect\n          .style('pointer-events', 'all')\n          .attr('width', d.width)\n          .attr('height', d.height)\n          .attr('x', d.translateX)\n          .attr('y', d.translateY)\n          .classed('bgsankey', true)\n          .style({fill: 'transparent', 'stroke-width': 0});\n    });\n\n    sankey.transition()\n        .ease(c.ease).duration(c.duration)\n        .attr('transform', sankeyTransform);\n\n    var sankeyLinks = sankey.selectAll('.' + c.cn.sankeyLinks)\n        .data(repeat, keyFun);\n\n    sankeyLinks.enter()\n        .append('g')\n        .classed(c.cn.sankeyLinks, true)\n        .style('fill', 'none');\n\n    var sankeyLink = sankeyLinks.selectAll('.' + c.cn.sankeyLink)\n          .data(function(d) {\n              var links = d.graph.links;\n              return links\n                .filter(function(l) {return l.value;})\n                .map(linkModel.bind(null, d));\n          }, keyFun);\n\n    sankeyLink\n          .enter().append('path')\n          .classed(c.cn.sankeyLink, true)\n          .call(attachPointerEvents, sankey, callbacks.linkEvents);\n\n    sankeyLink\n        .style('stroke', function(d) {\n            return salientEnough(d) ? Color.tinyRGB(tinycolor(d.linkLineColor)) : d.tinyColorHue;\n        })\n        .style('stroke-opacity', function(d) {\n            return salientEnough(d) ? Color.opacity(d.linkLineColor) : d.tinyColorAlpha;\n        })\n        .style('fill', function(d) {\n            return d.tinyColorHue;\n        })\n        .style('fill-opacity', function(d) {\n            return d.tinyColorAlpha;\n        })\n        .style('stroke-width', function(d) {\n            return salientEnough(d) ? d.linkLineWidth : 1;\n        })\n        .attr('d', linkPath());\n\n    sankeyLink\n        .style('opacity', function() { return (gd._context.staticPlot || firstRender || dragcover) ? 1 : 0;})\n        .transition()\n        .ease(c.ease).duration(c.duration)\n        .style('opacity', 1);\n\n    sankeyLink.exit()\n        .transition()\n        .ease(c.ease).duration(c.duration)\n        .style('opacity', 0)\n        .remove();\n\n    var sankeyNodeSet = sankey.selectAll('.' + c.cn.sankeyNodeSet)\n        .data(repeat, keyFun);\n\n    sankeyNodeSet.enter()\n        .append('g')\n        .classed(c.cn.sankeyNodeSet, true);\n\n    sankeyNodeSet\n        .style('cursor', function(d) {\n            switch(d.arrangement) {\n                case 'fixed': return 'default';\n                case 'perpendicular': return 'ns-resize';\n                default: return 'move';\n            }\n        });\n\n    var sankeyNode = sankeyNodeSet.selectAll('.' + c.cn.sankeyNode)\n        .data(function(d) {\n            var nodes = d.graph.nodes;\n            persistOriginalPlace(nodes);\n            return nodes\n              .map(nodeModel.bind(null, d));\n        }, keyFun);\n\n    sankeyNode.enter()\n        .append('g')\n        .classed(c.cn.sankeyNode, true)\n        .call(updateNodePositions)\n        .style('opacity', function(n) { return ((gd._context.staticPlot || firstRender) && !n.partOfGroup) ? 1 : 0;});\n\n    sankeyNode\n        .call(attachPointerEvents, sankey, callbacks.nodeEvents)\n        .call(attachDragHandler, sankeyLink, callbacks, gd); // has to be here as it binds sankeyLink\n\n    sankeyNode\n        .transition()\n        .ease(c.ease).duration(c.duration)\n        .call(updateNodePositions)\n        .style('opacity', function(n) { return n.partOfGroup ? 0 : 1;});\n\n    sankeyNode.exit()\n        .transition()\n        .ease(c.ease).duration(c.duration)\n        .style('opacity', 0)\n        .remove();\n\n    var nodeRect = sankeyNode.selectAll('.' + c.cn.nodeRect)\n        .data(repeat);\n\n    nodeRect.enter()\n        .append('rect')\n        .classed(c.cn.nodeRect, true)\n        .call(sizeNode);\n\n    nodeRect\n        .style('stroke-width', function(d) {return d.nodeLineWidth;})\n        .style('stroke', function(d) {return Color.tinyRGB(tinycolor(d.nodeLineColor));})\n        .style('stroke-opacity', function(d) {return Color.opacity(d.nodeLineColor);})\n        .style('fill', function(d) {return d.tinyColorHue;})\n        .style('fill-opacity', function(d) {return d.tinyColorAlpha;});\n\n    nodeRect.transition()\n        .ease(c.ease).duration(c.duration)\n        .call(sizeNode);\n\n    var nodeCapture = sankeyNode.selectAll('.' + c.cn.nodeCapture)\n        .data(repeat);\n\n    nodeCapture.enter()\n        .append('rect')\n        .classed(c.cn.nodeCapture, true)\n        .style('fill-opacity', 0);\n\n    nodeCapture\n        .attr('x', function(d) {return d.zoneX;})\n        .attr('y', function(d) {return d.zoneY;})\n        .attr('width', function(d) {return d.zoneWidth;})\n        .attr('height', function(d) {return d.zoneHeight;});\n\n    var nodeCentered = sankeyNode.selectAll('.' + c.cn.nodeCentered)\n        .data(repeat);\n\n    nodeCentered.enter()\n        .append('g')\n        .classed(c.cn.nodeCentered, true)\n        .attr('transform', nodeCentering);\n\n    nodeCentered\n        .transition()\n        .ease(c.ease).duration(c.duration)\n        .attr('transform', nodeCentering);\n\n    var nodeLabelGuide = nodeCentered.selectAll('.' + c.cn.nodeLabelGuide)\n        .data(repeat);\n\n    nodeLabelGuide.enter()\n        .append('path')\n        .classed(c.cn.nodeLabelGuide, true)\n        .attr('id', function(d) {return d.uniqueNodeLabelPathId;})\n        .attr('d', textGuidePath)\n        .attr('transform', sankeyInverseTransform);\n\n    nodeLabelGuide\n        .transition()\n        .ease(c.ease).duration(c.duration)\n        .attr('d', textGuidePath)\n        .attr('transform', sankeyInverseTransform);\n\n    var nodeLabel = nodeCentered.selectAll('.' + c.cn.nodeLabel)\n        .data(repeat);\n\n    nodeLabel.enter()\n        .append('text')\n        .classed(c.cn.nodeLabel, true)\n        .attr('transform', textFlip)\n        .style('user-select', 'none')\n        .style('cursor', 'default')\n        .style('fill', 'black');\n\n    nodeLabel\n        .style('text-shadow', function(d) {\n            return d.horizontal ? '-1px 1px 1px #fff, 1px 1px 1px #fff, 1px -1px 1px #fff, -1px -1px 1px #fff' : 'none';\n        })\n        .each(function(d) {Drawing.font(nodeLabel, d.textFont);});\n\n    nodeLabel\n        .transition()\n        .ease(c.ease).duration(c.duration)\n        .attr('transform', textFlip);\n\n    var nodeLabelTextPath = nodeLabel.selectAll('.' + c.cn.nodeLabelTextPath)\n        .data(repeat);\n\n    nodeLabelTextPath.enter()\n        .append('textPath')\n        .classed(c.cn.nodeLabelTextPath, true)\n        .attr('alignment-baseline', 'middle')\n        .attr('xlink:href', function(d) {return '#' + d.uniqueNodeLabelPathId;})\n        .attr('startOffset', nodeTextOffset)\n        .style('fill', nodeTextColor);\n\n    nodeLabelTextPath\n        .text(function(d) {return d.horizontal || d.node.dy > 5 ? d.node.label : '';})\n        .attr('text-anchor', function(d) {return d.horizontal && d.left ? 'end' : 'start';});\n\n    nodeLabelTextPath\n        .transition()\n        .ease(c.ease).duration(c.duration)\n        .attr('startOffset', nodeTextOffset)\n        .style('fill', nodeTextColor);\n};\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/gup\":717,\"../../registry\":847,\"./constants\":1105,\"@plotly/d3-sankey\":54,\"@plotly/d3-sankey-circular\":53,\"d3\":163,\"d3-force\":156,\"d3-interpolate\":158,\"tinycolor2\":537}],1110:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function selectPoints(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var selection = [];\n    var fullData = cd[0].trace;\n\n    var nodes = fullData._sankey.graph.nodes;\n\n    for(var i = 0; i < nodes.length; i++) {\n        var node = nodes[i];\n        if(node.partOfGroup) continue; // Those are invisible\n\n        // Position of node's centroid\n        var pos = [(node.x0 + node.x1) / 2, (node.y0 + node.y1) / 2];\n\n        // Swap x and y if trace is vertical\n        if(fullData.orientation === 'v') pos.reverse();\n\n        if(selectionTester && selectionTester.contains(pos, false, i, searchInfo)) {\n            selection.push({\n                pointNumber: node.pointNumber\n                // TODO: add eventData\n            });\n        }\n    }\n    return selection;\n};\n\n},{}],1111:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n\n// arrayOk attributes, merge them into calcdata array\nmodule.exports = function arraysToCalcdata(cd, trace) {\n    // so each point knows which index it originally came from\n    for(var i = 0; i < cd.length; i++) cd[i].i = i;\n\n    Lib.mergeArray(trace.text, cd, 'tx');\n    Lib.mergeArray(trace.hovertext, cd, 'htx');\n    Lib.mergeArray(trace.customdata, cd, 'data');\n    Lib.mergeArray(trace.textposition, cd, 'tp');\n    if(trace.textfont) {\n        Lib.mergeArrayCastPositive(trace.textfont.size, cd, 'ts');\n        Lib.mergeArray(trace.textfont.color, cd, 'tc');\n        Lib.mergeArray(trace.textfont.family, cd, 'tf');\n    }\n\n    var marker = trace.marker;\n    if(marker) {\n        Lib.mergeArrayCastPositive(marker.size, cd, 'ms');\n        Lib.mergeArrayCastPositive(marker.opacity, cd, 'mo');\n        Lib.mergeArray(marker.symbol, cd, 'mx');\n        Lib.mergeArray(marker.color, cd, 'mc');\n\n        var markerLine = marker.line;\n        if(marker.line) {\n            Lib.mergeArray(markerLine.color, cd, 'mlc');\n            Lib.mergeArrayCastPositive(markerLine.width, cd, 'mlw');\n        }\n\n        var markerGradient = marker.gradient;\n        if(markerGradient && markerGradient.type !== 'none') {\n            Lib.mergeArray(markerGradient.type, cd, 'mgt');\n            Lib.mergeArray(markerGradient.color, cd, 'mgc');\n        }\n    }\n};\n\n},{\"../../lib\":719}],1112:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar dash = _dereq_('../../components/drawing/attributes').dash;\n\nvar Drawing = _dereq_('../../components/drawing');\nvar constants = _dereq_('./constants');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = {\n    x: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        anim: true,\n        \n    },\n    x0: {\n        valType: 'any',\n        dflt: 0,\n        \n        editType: 'calc+clearAxisTypes',\n        anim: true,\n        \n    },\n    dx: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'calc',\n        anim: true,\n        \n    },\n    y: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        anim: true,\n        \n    },\n    y0: {\n        valType: 'any',\n        dflt: 0,\n        \n        editType: 'calc+clearAxisTypes',\n        anim: true,\n        \n    },\n    dy: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'calc',\n        anim: true,\n        \n    },\n\n    stackgroup: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'calc',\n        \n    },\n    orientation: {\n        valType: 'enumerated',\n        \n        values: ['v', 'h'],\n        editType: 'calc',\n        \n    },\n    groupnorm: {\n        valType: 'enumerated',\n        values: ['', 'fraction', 'percent'],\n        dflt: '',\n        \n        editType: 'calc',\n        \n    },\n    stackgaps: {\n        valType: 'enumerated',\n        values: ['infer zero', 'interpolate'],\n        dflt: 'infer zero',\n        \n        editType: 'calc',\n        \n    },\n\n    text: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'calc',\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        editType: 'style',\n        \n    },\n    mode: {\n        valType: 'flaglist',\n        flags: ['lines', 'markers', 'text'],\n        extras: ['none'],\n        \n        editType: 'calc',\n        \n    },\n    hoveron: {\n        valType: 'flaglist',\n        flags: ['points', 'fills'],\n        \n        editType: 'style',\n        \n    },\n    hovertemplate: hovertemplateAttrs({}, {\n        keys: constants.eventDataKeys\n    }),\n    line: {\n        color: {\n            valType: 'color',\n            \n            editType: 'style',\n            anim: true,\n            \n        },\n        width: {\n            valType: 'number',\n            min: 0,\n            dflt: 2,\n            \n            editType: 'style',\n            anim: true,\n            \n        },\n        shape: {\n            valType: 'enumerated',\n            values: ['linear', 'spline', 'hv', 'vh', 'hvh', 'vhv'],\n            dflt: 'linear',\n            \n            editType: 'plot',\n            \n        },\n        smoothing: {\n            valType: 'number',\n            min: 0,\n            max: 1.3,\n            dflt: 1,\n            \n            editType: 'plot',\n            \n        },\n        dash: extendFlat({}, dash, {editType: 'style'}),\n        simplify: {\n            valType: 'boolean',\n            dflt: true,\n            \n            editType: 'plot',\n            \n        },\n        editType: 'plot'\n    },\n\n    connectgaps: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    cliponaxis: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'plot',\n        \n    },\n\n    fill: {\n        valType: 'enumerated',\n        values: ['none', 'tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'],\n        \n        editType: 'calc',\n        \n    },\n    fillcolor: {\n        valType: 'color',\n        \n        editType: 'style',\n        anim: true,\n        \n    },\n    marker: extendFlat({\n        symbol: {\n            valType: 'enumerated',\n            values: Drawing.symbolList,\n            dflt: 'circle',\n            arrayOk: true,\n            \n            editType: 'style',\n            \n        },\n        opacity: {\n            valType: 'number',\n            min: 0,\n            max: 1,\n            arrayOk: true,\n            \n            editType: 'style',\n            anim: true,\n            \n        },\n        size: {\n            valType: 'number',\n            min: 0,\n            dflt: 6,\n            arrayOk: true,\n            \n            editType: 'calc',\n            anim: true,\n            \n        },\n        maxdisplayed: {\n            valType: 'number',\n            min: 0,\n            dflt: 0,\n            \n            editType: 'plot',\n            \n        },\n        sizeref: {\n            valType: 'number',\n            dflt: 1,\n            \n            editType: 'calc',\n            \n        },\n        sizemin: {\n            valType: 'number',\n            min: 0,\n            dflt: 0,\n            \n            editType: 'calc',\n            \n        },\n        sizemode: {\n            valType: 'enumerated',\n            values: ['diameter', 'area'],\n            dflt: 'diameter',\n            \n            editType: 'calc',\n            \n        },\n\n        line: extendFlat({\n            width: {\n                valType: 'number',\n                min: 0,\n                arrayOk: true,\n                \n                editType: 'style',\n                anim: true,\n                \n            },\n            editType: 'calc'\n        },\n            colorScaleAttrs('marker.line', {anim: true})\n        ),\n        gradient: {\n            type: {\n                valType: 'enumerated',\n                values: ['radial', 'horizontal', 'vertical', 'none'],\n                arrayOk: true,\n                dflt: 'none',\n                \n                editType: 'calc',\n                \n            },\n            color: {\n                valType: 'color',\n                arrayOk: true,\n                \n                editType: 'calc',\n                \n            },\n            editType: 'calc'\n        },\n        editType: 'calc'\n    },\n        colorScaleAttrs('marker', {anim: true})\n    ),\n    selected: {\n        marker: {\n            opacity: {\n                valType: 'number',\n                min: 0,\n                max: 1,\n                \n                editType: 'style',\n                \n            },\n            color: {\n                valType: 'color',\n                \n                editType: 'style',\n                \n            },\n            size: {\n                valType: 'number',\n                min: 0,\n                \n                editType: 'style',\n                \n            },\n            editType: 'style'\n        },\n        textfont: {\n            color: {\n                valType: 'color',\n                \n                editType: 'style',\n                \n            },\n            editType: 'style'\n        },\n        editType: 'style'\n    },\n    unselected: {\n        marker: {\n            opacity: {\n                valType: 'number',\n                min: 0,\n                max: 1,\n                \n                editType: 'style',\n                \n            },\n            color: {\n                valType: 'color',\n                \n                editType: 'style',\n                \n            },\n            size: {\n                valType: 'number',\n                min: 0,\n                \n                editType: 'style',\n                \n            },\n            editType: 'style'\n        },\n        textfont: {\n            color: {\n                valType: 'color',\n                \n                editType: 'style',\n                \n            },\n            editType: 'style'\n        },\n        editType: 'style'\n    },\n\n    textposition: {\n        valType: 'enumerated',\n        values: [\n            'top left', 'top center', 'top right',\n            'middle left', 'middle center', 'middle right',\n            'bottom left', 'bottom center', 'bottom right'\n        ],\n        dflt: 'middle center',\n        arrayOk: true,\n        \n        editType: 'calc',\n        \n    },\n    textfont: fontAttrs({\n        editType: 'calc',\n        colorEditType: 'style',\n        arrayOk: true,\n        \n    }),\n\n    r: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    t: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    }\n};\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/drawing\":614,\"../../components/drawing/attributes\":613,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/font_attributes\":793,\"./constants\":1116}],1113:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar Lib = _dereq_('../../lib');\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nvar subTypes = _dereq_('./subtypes');\nvar calcColorscale = _dereq_('./colorscale_calc');\nvar arraysToCalcdata = _dereq_('./arrays_to_calcdata');\nvar calcSelection = _dereq_('./calc_selection');\n\nfunction calc(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var xa = Axes.getFromId(gd, trace.xaxis || 'x');\n    var ya = Axes.getFromId(gd, trace.yaxis || 'y');\n    var x = xa.makeCalcdata(trace, 'x');\n    var y = ya.makeCalcdata(trace, 'y');\n    var serieslen = trace._length;\n    var cd = new Array(serieslen);\n    var ids = trace.ids;\n    var stackGroupOpts = getStackOpts(trace, fullLayout, xa, ya);\n    var interpolateGaps = false;\n    var isV, i, j, k, interpolate, vali;\n\n    setFirstScatter(fullLayout, trace);\n\n    var xAttr = 'x';\n    var yAttr = 'y';\n    var posAttr;\n    if(stackGroupOpts) {\n        Lib.pushUnique(stackGroupOpts.traceIndices, trace._expandedIndex);\n        isV = stackGroupOpts.orientation === 'v';\n\n        // size, like we use for bar\n        if(isV) {\n            yAttr = 's';\n            posAttr = 'x';\n        } else {\n            xAttr = 's';\n            posAttr = 'y';\n        }\n        interpolate = stackGroupOpts.stackgaps === 'interpolate';\n    } else {\n        var ppad = calcMarkerSize(trace, serieslen);\n        calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);\n    }\n\n    for(i = 0; i < serieslen; i++) {\n        var cdi = cd[i] = {};\n        var xValid = isNumeric(x[i]);\n        var yValid = isNumeric(y[i]);\n        if(xValid && yValid) {\n            cdi[xAttr] = x[i];\n            cdi[yAttr] = y[i];\n        } else if(stackGroupOpts && (isV ? xValid : yValid)) {\n            // if we're stacking we need to hold on to all valid positions\n            // even with invalid sizes\n\n            cdi[posAttr] = isV ? x[i] : y[i];\n            cdi.gap = true;\n            if(interpolate) {\n                cdi.s = BADNUM;\n                interpolateGaps = true;\n            } else {\n                cdi.s = 0;\n            }\n        } else {\n            cdi[xAttr] = cdi[yAttr] = BADNUM;\n        }\n\n        if(ids) {\n            cdi.id = String(ids[i]);\n        }\n    }\n\n    arraysToCalcdata(cd, trace);\n    calcColorscale(gd, trace);\n    calcSelection(cd, trace);\n\n    if(stackGroupOpts) {\n        // remove bad positions and sort\n        // note that original indices get added to cd in arraysToCalcdata\n        i = 0;\n        while(i < cd.length) {\n            if(cd[i][posAttr] === BADNUM) {\n                cd.splice(i, 1);\n            } else i++;\n        }\n\n        Lib.sort(cd, function(a, b) {\n            return (a[posAttr] - b[posAttr]) || (a.i - b.i);\n        });\n\n        if(interpolateGaps) {\n            // first fill the beginning with constant from the first point\n            i = 0;\n            while(i < cd.length - 1 && cd[i].gap) {\n                i++;\n            }\n            vali = cd[i].s;\n            if(!vali) vali = cd[i].s = 0; // in case of no data AT ALL in this trace - use 0\n            for(j = 0; j < i; j++) {\n                cd[j].s = vali;\n            }\n            // then fill the end with constant from the last point\n            k = cd.length - 1;\n            while(k > i && cd[k].gap) {\n                k--;\n            }\n            vali = cd[k].s;\n            for(j = cd.length - 1; j > k; j--) {\n                cd[j].s = vali;\n            }\n            // now interpolate internal gaps linearly\n            while(i < k) {\n                i++;\n                if(cd[i].gap) {\n                    j = i + 1;\n                    while(cd[j].gap) {\n                        j++;\n                    }\n                    var pos0 = cd[i - 1][posAttr];\n                    var size0 = cd[i - 1].s;\n                    var m = (cd[j].s - size0) / (cd[j][posAttr] - pos0);\n                    while(i < j) {\n                        cd[i].s = size0 + (cd[i][posAttr] - pos0) * m;\n                        i++;\n                    }\n                }\n            }\n        }\n    }\n\n    return cd;\n}\n\nfunction calcAxisExpansion(gd, trace, xa, ya, x, y, ppad) {\n    var serieslen = trace._length;\n    var fullLayout = gd._fullLayout;\n    var xId = xa._id;\n    var yId = ya._id;\n    var firstScatter = fullLayout._firstScatter[firstScatterGroup(trace)] === trace.uid;\n    var stackOrientation = (getStackOpts(trace, fullLayout, xa, ya) || {}).orientation;\n    var fill = trace.fill;\n\n    // cancel minimum tick spacings (only applies to bars and boxes)\n    xa._minDtick = 0;\n    ya._minDtick = 0;\n\n    // check whether bounds should be tight, padded, extended to zero...\n    // most cases both should be padded on both ends, so start with that.\n    var xOptions = {padded: true};\n    var yOptions = {padded: true};\n\n    if(ppad) {\n        xOptions.ppad = yOptions.ppad = ppad;\n    }\n\n    // TODO: text size\n\n    var openEnded = serieslen < 2 || (x[0] !== x[serieslen - 1]) || (y[0] !== y[serieslen - 1]);\n\n    if(openEnded && (\n        (fill === 'tozerox') ||\n        ((fill === 'tonextx') && (firstScatter || stackOrientation === 'h'))\n    )) {\n        // include zero (tight) and extremes (padded) if fill to zero\n        // (unless the shape is closed, then it's just filling the shape regardless)\n\n        xOptions.tozero = true;\n    } else if(!(trace.error_y || {}).visible && (\n        // if no error bars, markers or text, or fill to y=0 remove x padding\n\n            (fill === 'tonexty' || fill === 'tozeroy') ||\n            (!subTypes.hasMarkers(trace) && !subTypes.hasText(trace))\n        )) {\n        xOptions.padded = false;\n        xOptions.ppad = 0;\n    }\n\n    if(openEnded && (\n        (fill === 'tozeroy') ||\n        ((fill === 'tonexty') && (firstScatter || stackOrientation === 'v'))\n    )) {\n        // now check for y - rather different logic, though still mostly padded both ends\n        // include zero (tight) and extremes (padded) if fill to zero\n        // (unless the shape is closed, then it's just filling the shape regardless)\n\n        yOptions.tozero = true;\n    } else if(fill === 'tonextx' || fill === 'tozerox') {\n        // tight y: any x fill\n\n        yOptions.padded = false;\n    }\n\n    // N.B. asymmetric splom traces call this with blank {} xa or ya\n    if(xId) trace._extremes[xId] = Axes.findExtremes(xa, x, xOptions);\n    if(yId) trace._extremes[yId] = Axes.findExtremes(ya, y, yOptions);\n}\n\nfunction calcMarkerSize(trace, serieslen) {\n    if(!subTypes.hasMarkers(trace)) return;\n\n    // Treat size like x or y arrays --- Run d2c\n    // this needs to go before ppad computation\n    var marker = trace.marker;\n    var sizeref = 1.6 * (trace.marker.sizeref || 1);\n    var markerTrans;\n\n    if(trace.marker.sizemode === 'area') {\n        markerTrans = function(v) {\n            return Math.max(Math.sqrt((v || 0) / sizeref), 3);\n        };\n    } else {\n        markerTrans = function(v) {\n            return Math.max((v || 0) / sizeref, 3);\n        };\n    }\n\n    if(Lib.isArrayOrTypedArray(marker.size)) {\n        // I tried auto-type but category and dates dont make much sense.\n        var ax = {type: 'linear'};\n        Axes.setConvert(ax);\n\n        var s = ax.makeCalcdata(trace.marker, 'size');\n\n        var sizeOut = new Array(serieslen);\n        for(var i = 0; i < serieslen; i++) {\n            sizeOut[i] = markerTrans(s[i]);\n        }\n        return sizeOut;\n    } else {\n        return markerTrans(marker.size);\n    }\n}\n\n/**\n * mark the first scatter trace for each subplot\n * note that scatter and scattergl each get their own first trace\n * note also that I'm doing this during calc rather than supplyDefaults\n * so I don't need to worry about transforms, but if we ever do\n * per-trace calc this will get confused.\n */\nfunction setFirstScatter(fullLayout, trace) {\n    var group = firstScatterGroup(trace);\n    var firstScatter = fullLayout._firstScatter;\n    if(!firstScatter[group]) firstScatter[group] = trace.uid;\n}\n\nfunction firstScatterGroup(trace) {\n    var stackGroup = trace.stackgroup;\n    return trace.xaxis + trace.yaxis + trace.type +\n        (stackGroup ? '-' + stackGroup : '');\n}\n\nfunction getStackOpts(trace, fullLayout, xa, ya) {\n    var stackGroup = trace.stackgroup;\n    if(!stackGroup) return;\n    var stackOpts = fullLayout._scatterStackOpts[xa._id + ya._id][stackGroup];\n    var stackAx = stackOpts.orientation === 'v' ? ya : xa;\n    // Allow stacking only on numeric axes\n    // calc is a little late to be figuring this out, but during supplyDefaults\n    // we don't know the axis type yet\n    if(stackAx.type === 'linear' || stackAx.type === 'log') return stackOpts;\n}\n\nmodule.exports = {\n    calc: calc,\n    calcMarkerSize: calcMarkerSize,\n    calcAxisExpansion: calcAxisExpansion,\n    setFirstScatter: setFirstScatter,\n    getStackOpts: getStackOpts\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"./arrays_to_calcdata\":1111,\"./calc_selection\":1114,\"./colorscale_calc\":1115,\"./subtypes\":1135,\"fast-isnumeric\":225}],1114:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function calcSelection(cd, trace) {\n    if(Lib.isArrayOrTypedArray(trace.selectedpoints)) {\n        Lib.tagSelected(cd, trace);\n    }\n};\n\n},{\"../../lib\":719}],1115:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar calcColorscale = _dereq_('../../components/colorscale/calc');\n\nvar subTypes = _dereq_('./subtypes');\n\nmodule.exports = function calcMarkerColorscale(gd, trace) {\n    if(subTypes.hasLines(trace) && hasColorscale(trace, 'line')) {\n        calcColorscale(gd, trace, {\n            vals: trace.line.color,\n            containerStr: 'line',\n            cLetter: 'c'\n        });\n    }\n\n    if(subTypes.hasMarkers(trace)) {\n        if(hasColorscale(trace, 'marker')) {\n            calcColorscale(gd, trace, {\n                vals: trace.marker.color,\n                containerStr: 'marker',\n                cLetter: 'c'\n            });\n        }\n        if(hasColorscale(trace, 'marker.line')) {\n            calcColorscale(gd, trace, {\n                vals: trace.marker.line.color,\n                containerStr: 'marker.line',\n                cLetter: 'c'\n            });\n        }\n    }\n};\n\n},{\"../../components/colorscale/calc\":601,\"../../components/colorscale/helpers\":604,\"./subtypes\":1135}],1116:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = {\n    PTS_LINESONLY: 20,\n\n    // fixed parameters of clustering and clipping algorithms\n\n    // fraction of clustering tolerance \"so close we don't even consider it a new point\"\n    minTolerance: 0.2,\n    // how fast does clustering tolerance increase as you get away from the visible region\n    toleranceGrowth: 10,\n\n    // number of viewport sizes away from the visible region\n    // at which we clip all lines to the perimeter\n    maxScreensAway: 20,\n\n    eventDataKeys: []\n};\n\n},{}],1117:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar calc = _dereq_('./calc');\n\n/*\n * Scatter stacking & normalization calculations\n * runs per subplot, and can handle multiple stacking groups\n */\n\nmodule.exports = function crossTraceCalc(gd, plotinfo) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n    var subplot = xa._id + ya._id;\n\n    var subplotStackOpts = gd._fullLayout._scatterStackOpts[subplot];\n    if(!subplotStackOpts) return;\n\n    var calcTraces = gd.calcdata;\n\n    var i, j, k, i2, cd, cd0, posj, sumj, norm;\n    var groupOpts, interpolate, groupnorm, posAttr, valAttr;\n    var hasAnyBlanks;\n\n    for(var stackGroup in subplotStackOpts) {\n        groupOpts = subplotStackOpts[stackGroup];\n        var indices = groupOpts.traceIndices;\n\n        // can get here with no indices if the stack axis is non-numeric\n        if(!indices.length) continue;\n\n        interpolate = groupOpts.stackgaps === 'interpolate';\n        groupnorm = groupOpts.groupnorm;\n        if(groupOpts.orientation === 'v') {\n            posAttr = 'x';\n            valAttr = 'y';\n        } else {\n            posAttr = 'y';\n            valAttr = 'x';\n        }\n        hasAnyBlanks = new Array(indices.length);\n        for(i = 0; i < hasAnyBlanks.length; i++) {\n            hasAnyBlanks[i] = false;\n        }\n\n        // Collect the complete set of all positions across ALL traces.\n        // Start with the first trace, then interleave items from later traces\n        // as needed.\n        // Fill in mising items as we go.\n        cd0 = calcTraces[indices[0]];\n        var allPositions = new Array(cd0.length);\n        for(i = 0; i < cd0.length; i++) {\n            allPositions[i] = cd0[i][posAttr];\n        }\n\n        for(i = 1; i < indices.length; i++) {\n            cd = calcTraces[indices[i]];\n\n            for(j = k = 0; j < cd.length; j++) {\n                posj = cd[j][posAttr];\n                for(; posj > allPositions[k] && k < allPositions.length; k++) {\n                    // the current trace is missing a position from some previous trace(s)\n                    insertBlank(cd, j, allPositions[k], i, hasAnyBlanks, interpolate, posAttr);\n                    j++;\n                }\n                if(posj !== allPositions[k]) {\n                    // previous trace(s) are missing a position from the current trace\n                    for(i2 = 0; i2 < i; i2++) {\n                        insertBlank(calcTraces[indices[i2]], k, posj, i2, hasAnyBlanks, interpolate, posAttr);\n                    }\n                    allPositions.splice(k, 0, posj);\n                }\n                k++;\n            }\n            for(; k < allPositions.length; k++) {\n                insertBlank(cd, j, allPositions[k], i, hasAnyBlanks, interpolate, posAttr);\n                j++;\n            }\n        }\n\n        var serieslen = allPositions.length;\n\n        // stack (and normalize)!\n        for(j = 0; j < cd0.length; j++) {\n            sumj = cd0[j][valAttr] = cd0[j].s;\n            for(i = 1; i < indices.length; i++) {\n                cd = calcTraces[indices[i]];\n                cd[0].trace._rawLength = cd[0].trace._length;\n                cd[0].trace._length = serieslen;\n                sumj += cd[j].s;\n                cd[j][valAttr] = sumj;\n            }\n\n            if(groupnorm) {\n                norm = ((groupnorm === 'fraction') ? sumj : (sumj / 100)) || 1;\n                for(i = 0; i < indices.length; i++) {\n                    var cdj = calcTraces[indices[i]][j];\n                    cdj[valAttr] /= norm;\n                    cdj.sNorm = cdj.s / norm;\n                }\n            }\n        }\n\n        // autorange\n        for(i = 0; i < indices.length; i++) {\n            cd = calcTraces[indices[i]];\n            var trace = cd[0].trace;\n            var ppad = calc.calcMarkerSize(trace, trace._rawLength);\n            var arrayPad = Array.isArray(ppad);\n            if((ppad && hasAnyBlanks[i]) || arrayPad) {\n                var ppadRaw = ppad;\n                ppad = new Array(serieslen);\n                for(j = 0; j < serieslen; j++) {\n                    ppad[j] = cd[j].gap ? 0 : (arrayPad ? ppadRaw[cd[j].i] : ppadRaw);\n                }\n            }\n            var x = new Array(serieslen);\n            var y = new Array(serieslen);\n            for(j = 0; j < serieslen; j++) {\n                x[j] = cd[j].x;\n                y[j] = cd[j].y;\n            }\n            calc.calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);\n\n            // while we're here (in a loop over all traces in the stack)\n            // record the orientation, so hover can find it easily\n            cd[0].t.orientation = groupOpts.orientation;\n        }\n    }\n};\n\nfunction insertBlank(calcTrace, index, position, traceIndex, hasAnyBlanks, interpolate, posAttr) {\n    hasAnyBlanks[traceIndex] = true;\n    var newEntry = {\n        i: null,\n        gap: true,\n        s: 0\n    };\n    newEntry[posAttr] = position;\n    calcTrace.splice(index, 0, newEntry);\n    // Even if we're not interpolating, if one trace has multiple\n    // values at the same position and this trace only has one value there,\n    // we just duplicate that one value rather than insert a zero.\n    // We also make it look like a real point - because it's ambiguous which\n    // one really is the real one!\n    if(index && position === calcTrace[index - 1][posAttr]) {\n        var prevEntry = calcTrace[index - 1];\n        newEntry.s = prevEntry.s;\n        // TODO is it going to cause any problems to have multiple\n        // calcdata points with the same index?\n        newEntry.i = prevEntry.i;\n        newEntry.gap = prevEntry.gap;\n    } else if(interpolate) {\n        newEntry.s = getInterp(calcTrace, index, position, posAttr);\n    }\n    if(!index) {\n        // t and trace need to stay on the first cd entry\n        calcTrace[0].t = calcTrace[1].t;\n        calcTrace[0].trace = calcTrace[1].trace;\n        delete calcTrace[1].t;\n        delete calcTrace[1].trace;\n    }\n}\n\nfunction getInterp(calcTrace, index, position, posAttr) {\n    var pt0 = calcTrace[index - 1];\n    var pt1 = calcTrace[index + 1];\n    if(!pt1) return pt0.s;\n    if(!pt0) return pt1.s;\n    return pt0.s + (pt1.s - pt0.s) * (position - pt0[posAttr]) / (pt1[posAttr] - pt0[posAttr]);\n}\n\n},{\"./calc\":1113}],1118:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\n// remove opacity for any trace that has a fill or is filled to\nmodule.exports = function crossTraceDefaults(fullData) {\n    for(var i = 0; i < fullData.length; i++) {\n        var tracei = fullData[i];\n        if(tracei.type !== 'scatter') continue;\n\n        var filli = tracei.fill;\n        if(filli === 'none' || filli === 'toself') continue;\n\n        tracei.opacity = undefined;\n\n        if(filli === 'tonexty' || filli === 'tonextx') {\n            for(var j = i - 1; j >= 0; j--) {\n                var tracej = fullData[j];\n\n                if((tracej.type === 'scatter') &&\n                        (tracej.xaxis === tracei.xaxis) &&\n                        (tracej.yaxis === tracei.yaxis)) {\n                    tracej.opacity = undefined;\n                    break;\n                }\n            }\n        }\n    }\n};\n\n},{}],1119:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\n\nvar attributes = _dereq_('./attributes');\nvar constants = _dereq_('./constants');\nvar subTypes = _dereq_('./subtypes');\nvar handleXYDefaults = _dereq_('./xy_defaults');\nvar handleStackDefaults = _dereq_('./stack_defaults');\nvar handleMarkerDefaults = _dereq_('./marker_defaults');\nvar handleLineDefaults = _dereq_('./line_defaults');\nvar handleLineShapeDefaults = _dereq_('./line_shape_defaults');\nvar handleTextDefaults = _dereq_('./text_defaults');\nvar handleFillColorDefaults = _dereq_('./fillcolor_defaults');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleXYDefaults(traceIn, traceOut, layout, coerce);\n    if(!len) traceOut.visible = false;\n\n    if(!traceOut.visible) return;\n\n    var stackGroupOpts = handleStackDefaults(traceIn, traceOut, layout, coerce);\n\n    var defaultMode = !stackGroupOpts && (len < constants.PTS_LINESONLY) ?\n        'lines+markers' : 'lines';\n    coerce('text');\n    coerce('hovertext');\n    coerce('mode', defaultMode);\n\n    if(subTypes.hasLines(traceOut)) {\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n        handleLineShapeDefaults(traceIn, traceOut, coerce);\n        coerce('connectgaps');\n        coerce('line.simplify');\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {gradient: true});\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce);\n    }\n\n    var dfltHoverOn = [];\n\n    if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {\n        coerce('cliponaxis');\n        coerce('marker.maxdisplayed');\n        dfltHoverOn.push('points');\n    }\n\n    // It's possible for this default to be changed by a later trace.\n    // We handle that case in some hacky code inside handleStackDefaults.\n    coerce('fill', stackGroupOpts ? stackGroupOpts.fillDflt : 'none');\n    if(traceOut.fill !== 'none') {\n        handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);\n        if(!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce);\n    }\n\n    var lineColor = (traceOut.line || {}).color;\n    var markerColor = (traceOut.marker || {}).color;\n\n    if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {\n        dfltHoverOn.push('fills');\n    }\n    coerce('hoveron', dfltHoverOn.join('+') || 'points');\n    if(traceOut.hoveron !== 'fills') coerce('hovertemplate');\n    var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'y'});\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'x', inherit: 'y'});\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\n},{\"../../lib\":719,\"../../registry\":847,\"./attributes\":1112,\"./constants\":1116,\"./fillcolor_defaults\":1120,\"./line_defaults\":1124,\"./line_shape_defaults\":1126,\"./marker_defaults\":1130,\"./stack_defaults\":1133,\"./subtypes\":1135,\"./text_defaults\":1136,\"./xy_defaults\":1137}],1120:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Color = _dereq_('../../components/color');\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\n\nmodule.exports = function fillColorDefaults(traceIn, traceOut, defaultColor, coerce) {\n    var inheritColorFromMarker = false;\n\n    if(traceOut.marker) {\n        // don't try to inherit a color array\n        var markerColor = traceOut.marker.color;\n        var markerLineColor = (traceOut.marker.line || {}).color;\n\n        if(markerColor && !isArrayOrTypedArray(markerColor)) {\n            inheritColorFromMarker = markerColor;\n        } else if(markerLineColor && !isArrayOrTypedArray(markerLineColor)) {\n            inheritColorFromMarker = markerLineColor;\n        }\n    }\n\n    coerce('fillcolor', Color.addOpacity(\n        (traceOut.line || {}).color ||\n        inheritColorFromMarker ||\n        defaultColor, 0.5\n    ));\n};\n\n},{\"../../components/color\":593,\"../../lib\":719}],1121:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Color = _dereq_('../../components/color');\nvar subtypes = _dereq_('./subtypes');\n\n\nmodule.exports = function getTraceColor(trace, di) {\n    var lc, tc;\n\n    // TODO: text modes\n\n    if(trace.mode === 'lines') {\n        lc = trace.line.color;\n        return (lc && Color.opacity(lc)) ?\n            lc : trace.fillcolor;\n    } else if(trace.mode === 'none') {\n        return trace.fill ? trace.fillcolor : '';\n    } else {\n        var mc = di.mcc || (trace.marker || {}).color;\n        var mlc = di.mlcc || ((trace.marker || {}).line || {}).color;\n\n        tc = (mc && Color.opacity(mc)) ? mc :\n            (mlc && Color.opacity(mlc) &&\n                (di.mlw || ((trace.marker || {}).line || {}).width)) ? mlc : '';\n\n        if(tc) {\n            // make sure the points aren't TOO transparent\n            if(Color.opacity(tc) < 0.3) {\n                return Color.addOpacity(tc, 0.3);\n            } else return tc;\n        } else {\n            lc = (trace.line || {}).color;\n            return (lc && Color.opacity(lc) &&\n                subtypes.hasLines(trace) && trace.line.width) ?\n                    lc : trace.fillcolor;\n        }\n    }\n};\n\n},{\"../../components/color\":593,\"./subtypes\":1135}],1122:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Fx = _dereq_('../../components/fx');\nvar Registry = _dereq_('../../registry');\nvar getTraceColor = _dereq_('./get_trace_color');\nvar Color = _dereq_('../../components/color');\nvar fillText = Lib.fillText;\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var xpx = xa.c2p(xval);\n    var ypx = ya.c2p(yval);\n    var pt = [xpx, ypx];\n    var hoveron = trace.hoveron || '';\n    var minRad = (trace.mode.indexOf('markers') !== -1) ? 3 : 0.5;\n\n    // look for points to hover on first, then take fills only if we\n    // didn't find a point\n    if(hoveron.indexOf('points') !== -1) {\n        var dx = function(di) {\n            // dx and dy are used in compare modes - here we want to always\n            // prioritize the closest data point, at least as long as markers are\n            // the same size or nonexistent, but still try to prioritize small markers too.\n            var rad = Math.max(3, di.mrc || 0);\n            var kink = 1 - 1 / rad;\n            var dxRaw = Math.abs(xa.c2p(di.x) - xpx);\n            var d = (dxRaw < rad) ? (kink * dxRaw / rad) : (dxRaw - rad + kink);\n            return d;\n        };\n        var dy = function(di) {\n            var rad = Math.max(3, di.mrc || 0);\n            var kink = 1 - 1 / rad;\n            var dyRaw = Math.abs(ya.c2p(di.y) - ypx);\n            return (dyRaw < rad) ? (kink * dyRaw / rad) : (dyRaw - rad + kink);\n        };\n        var dxy = function(di) {\n            // scatter points: d.mrc is the calculated marker radius\n            // adjust the distance so if you're inside the marker it\n            // always will show up regardless of point size, but\n            // prioritize smaller points\n            var rad = Math.max(minRad, di.mrc || 0);\n            var dx = xa.c2p(di.x) - xpx;\n            var dy = ya.c2p(di.y) - ypx;\n            return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - minRad / rad);\n        };\n        var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);\n\n        Fx.getClosest(cd, distfn, pointData);\n\n        // skip the rest (for this trace) if we didn't find a close point\n        if(pointData.index !== false) {\n            // the closest data point\n            var di = cd[pointData.index];\n            var xc = xa.c2p(di.x, true);\n            var yc = ya.c2p(di.y, true);\n            var rad = di.mrc || 1;\n\n            // now we're done using the whole `calcdata` array, replace the\n            // index with the original index (in case of inserted point from\n            // stacked area)\n            pointData.index = di.i;\n\n            var orientation = cd[0].t.orientation;\n            // TODO: for scatter and bar, option to show (sub)totals and\n            // raw data? Currently stacked and/or normalized bars just show\n            // the normalized individual sizes, so that's what I'm doing here\n            // for now.\n            var sizeVal = orientation && (di.sNorm || di.s);\n            var xLabelVal = (orientation === 'h') ? sizeVal : di.x;\n            var yLabelVal = (orientation === 'v') ? sizeVal : di.y;\n\n            Lib.extendFlat(pointData, {\n                color: getTraceColor(trace, di),\n\n                x0: xc - rad,\n                x1: xc + rad,\n                xLabelVal: xLabelVal,\n\n                y0: yc - rad,\n                y1: yc + rad,\n                yLabelVal: yLabelVal,\n\n                spikeDistance: dxy(di),\n                hovertemplate: trace.hovertemplate\n            });\n\n            fillText(di, trace, pointData);\n            Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData);\n\n            return [pointData];\n        }\n    }\n\n    // even if hoveron is 'fills', only use it if we have polygons too\n    if(hoveron.indexOf('fills') !== -1 && trace._polygons) {\n        var polygons = trace._polygons;\n        var polygonsIn = [];\n        var inside = false;\n        var xmin = Infinity;\n        var xmax = -Infinity;\n        var ymin = Infinity;\n        var ymax = -Infinity;\n\n        var i, j, polygon, pts, xCross, x0, x1, y0, y1;\n\n        for(i = 0; i < polygons.length; i++) {\n            polygon = polygons[i];\n            // TODO: this is not going to work right for curved edges, it will\n            // act as though they're straight. That's probably going to need\n            // the elements themselves to capture the events. Worth it?\n            if(polygon.contains(pt)) {\n                inside = !inside;\n                // TODO: need better than just the overall bounding box\n                polygonsIn.push(polygon);\n                ymin = Math.min(ymin, polygon.ymin);\n                ymax = Math.max(ymax, polygon.ymax);\n            }\n        }\n\n        if(inside) {\n            // constrain ymin/max to the visible plot, so the label goes\n            // at the middle of the piece you can see\n            ymin = Math.max(ymin, 0);\n            ymax = Math.min(ymax, ya._length);\n\n            // find the overall left-most and right-most points of the\n            // polygon(s) we're inside at their combined vertical midpoint.\n            // This is where we will draw the hover label.\n            // Note that this might not be the vertical midpoint of the\n            // whole trace, if it's disjoint.\n            var yAvg = (ymin + ymax) / 2;\n            for(i = 0; i < polygonsIn.length; i++) {\n                pts = polygonsIn[i].pts;\n                for(j = 1; j < pts.length; j++) {\n                    y0 = pts[j - 1][1];\n                    y1 = pts[j][1];\n                    if((y0 > yAvg) !== (y1 >= yAvg)) {\n                        x0 = pts[j - 1][0];\n                        x1 = pts[j][0];\n                        if(y1 - y0) {\n                            xCross = x0 + (x1 - x0) * (yAvg - y0) / (y1 - y0);\n                            xmin = Math.min(xmin, xCross);\n                            xmax = Math.max(xmax, xCross);\n                        }\n                    }\n                }\n            }\n\n            // constrain xmin/max to the visible plot now too\n            xmin = Math.max(xmin, 0);\n            xmax = Math.min(xmax, xa._length);\n\n            // get only fill or line color for the hover color\n            var color = Color.defaultLine;\n            if(Color.opacity(trace.fillcolor)) color = trace.fillcolor;\n            else if(Color.opacity((trace.line || {}).color)) {\n                color = trace.line.color;\n            }\n\n            Lib.extendFlat(pointData, {\n                // never let a 2D override 1D type as closest point\n                // also: no spikeDistance, it's not allowed for fills\n                distance: pointData.maxHoverDistance,\n                x0: xmin,\n                x1: xmax,\n                y0: yAvg,\n                y1: yAvg,\n                color: color,\n                hovertemplate: false\n            });\n\n            delete pointData.index;\n\n            if(trace.text && !Array.isArray(trace.text)) {\n                pointData.text = String(trace.text);\n            } else pointData.text = trace.name;\n\n            return [pointData];\n        }\n    }\n};\n\n},{\"../../components/color\":593,\"../../components/fx\":632,\"../../lib\":719,\"../../registry\":847,\"./get_trace_color\":1121}],1123:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar subtypes = _dereq_('./subtypes');\n\nmodule.exports = {\n    hasLines: subtypes.hasLines,\n    hasMarkers: subtypes.hasMarkers,\n    hasText: subtypes.hasText,\n    isBubble: subtypes.isBubble,\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    crossTraceDefaults: _dereq_('./cross_trace_defaults'),\n    calc: _dereq_('./calc').calc,\n    crossTraceCalc: _dereq_('./cross_trace_calc'),\n    arraysToCalcdata: _dereq_('./arrays_to_calcdata'),\n    plot: _dereq_('./plot'),\n    colorbar: _dereq_('./marker_colorbar'),\n    style: _dereq_('./style').style,\n    styleOnSelect: _dereq_('./style').styleOnSelect,\n    hoverPoints: _dereq_('./hover'),\n    selectPoints: _dereq_('./select'),\n    animatable: true,\n\n    moduleType: 'trace',\n    name: 'scatter',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: [\n        'cartesian', 'svg', 'symbols', 'errorBarsOK', 'showLegend', 'scatter-like',\n        'zoomScale'\n    ],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"./arrays_to_calcdata\":1111,\"./attributes\":1112,\"./calc\":1113,\"./cross_trace_calc\":1117,\"./cross_trace_defaults\":1118,\"./defaults\":1119,\"./hover\":1122,\"./marker_colorbar\":1129,\"./plot\":1131,\"./select\":1132,\"./style\":1134,\"./subtypes\":1135}],1124:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\n\nmodule.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) {\n    var markerColor = (traceIn.marker || {}).color;\n\n    coerce('line.color', defaultColor);\n\n    if(hasColorscale(traceIn, 'line')) {\n        colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});\n    } else {\n        var lineColorDflt = (isArrayOrTypedArray(markerColor) ? false : markerColor) || defaultColor;\n        coerce('line.color', lineColorDflt);\n    }\n\n    coerce('line.width');\n    if(!(opts || {}).noDash) coerce('line.dash');\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../components/colorscale/helpers\":604,\"../../lib\":719}],1125:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar numConstants = _dereq_('../../constants/numerical');\nvar BADNUM = numConstants.BADNUM;\nvar LOG_CLIP = numConstants.LOG_CLIP;\nvar LOG_CLIP_PLUS = LOG_CLIP + 0.5;\nvar LOG_CLIP_MINUS = LOG_CLIP - 0.5;\nvar Lib = _dereq_('../../lib');\nvar segmentsIntersect = Lib.segmentsIntersect;\nvar constrain = Lib.constrain;\nvar constants = _dereq_('./constants');\n\n\nmodule.exports = function linePoints(d, opts) {\n    var xa = opts.xaxis;\n    var ya = opts.yaxis;\n    var xLog = xa.type === 'log';\n    var yLog = ya.type === 'log';\n    var xLen = xa._length;\n    var yLen = ya._length;\n    var connectGaps = opts.connectGaps;\n    var baseTolerance = opts.baseTolerance;\n    var shape = opts.shape;\n    var linear = shape === 'linear';\n    var fill = opts.fill && opts.fill !== 'none';\n    var segments = [];\n    var minTolerance = constants.minTolerance;\n    var len = d.length;\n    var pts = new Array(len);\n    var pti = 0;\n\n    var i;\n\n    // pt variables are pixel coordinates [x,y] of one point\n    // these four are the outputs of clustering on a line\n    var clusterStartPt, clusterEndPt, clusterHighPt, clusterLowPt;\n\n    // \"this\" is the next point we're considering adding to the cluster\n    var thisPt;\n\n    // did we encounter the high point first, then a low point, or vice versa?\n    var clusterHighFirst;\n\n    // the first two points in the cluster determine its unit vector\n    // so the second is always in the \"High\" direction\n    var clusterUnitVector;\n\n    // the pixel delta from clusterStartPt\n    var thisVector;\n\n    // val variables are (signed) pixel distances along the cluster vector\n    var clusterRefDist, clusterHighVal, clusterLowVal, thisVal;\n\n    // deviation variables are (signed) pixel distances normal to the cluster vector\n    var clusterMinDeviation, clusterMaxDeviation, thisDeviation;\n\n    // turn one calcdata point into pixel coordinates\n    function getPt(index) {\n        var di = d[index];\n        if(!di) return false;\n        var x = xa.c2p(di.x);\n        var y = ya.c2p(di.y);\n\n        // if non-positive log values, set them VERY far off-screen\n        // so the line looks essentially straight from the previous point.\n        if(x === BADNUM) {\n            if(xLog) x = xa.c2p(di.x, true);\n            if(x === BADNUM) return false;\n            // If BOTH were bad log values, make the line follow a constant\n            // exponent rather than a constant slope\n            if(yLog && y === BADNUM) {\n                x *= Math.abs(xa._m * yLen * (xa._m > 0 ? LOG_CLIP_PLUS : LOG_CLIP_MINUS) /\n                    (ya._m * xLen * (ya._m > 0 ? LOG_CLIP_PLUS : LOG_CLIP_MINUS)));\n            }\n            x *= 1000;\n        }\n        if(y === BADNUM) {\n            if(yLog) y = ya.c2p(di.y, true);\n            if(y === BADNUM) return false;\n            y *= 1000;\n        }\n        return [x, y];\n    }\n\n    function crossesViewport(xFrac0, yFrac0, xFrac1, yFrac1) {\n        var dx = xFrac1 - xFrac0;\n        var dy = yFrac1 - yFrac0;\n        var dx0 = 0.5 - xFrac0;\n        var dy0 = 0.5 - yFrac0;\n        var norm2 = dx * dx + dy * dy;\n        var dot = dx * dx0 + dy * dy0;\n        if(dot > 0 && dot < norm2) {\n            var cross = dx0 * dy - dy0 * dx;\n            if(cross * cross < norm2) return true;\n        }\n    }\n\n    var latestXFrac, latestYFrac;\n    // if we're off-screen, increase tolerance over baseTolerance\n    function getTolerance(pt, nextPt) {\n        var xFrac = pt[0] / xLen;\n        var yFrac = pt[1] / yLen;\n        var offScreenFraction = Math.max(0, -xFrac, xFrac - 1, -yFrac, yFrac - 1);\n        if(offScreenFraction && (latestXFrac !== undefined) &&\n            crossesViewport(xFrac, yFrac, latestXFrac, latestYFrac)\n        ) {\n            offScreenFraction = 0;\n        }\n        if(offScreenFraction && nextPt &&\n            crossesViewport(xFrac, yFrac, nextPt[0] / xLen, nextPt[1] / yLen)\n        ) {\n            offScreenFraction = 0;\n        }\n\n        return (1 + constants.toleranceGrowth * offScreenFraction) * baseTolerance;\n    }\n\n    function ptDist(pt1, pt2) {\n        var dx = pt1[0] - pt2[0];\n        var dy = pt1[1] - pt2[1];\n        return Math.sqrt(dx * dx + dy * dy);\n    }\n\n    // last bit of filtering: clip paths that are VERY far off-screen\n    // so we don't get near the browser's hard limit (+/- 2^29 px in Chrome and FF)\n\n    var maxScreensAway = constants.maxScreensAway;\n\n    // find the intersections between the segment from pt1 to pt2\n    // and the large rectangle maxScreensAway around the viewport\n    // if one of pt1 and pt2 is inside and the other outside, there\n    // will be only one intersection.\n    // if both are outside there will be 0 or 2 intersections\n    // (or 1 if it's right at a corner - we'll treat that like 0)\n    // returns an array of intersection pts\n    var xEdge0 = -xLen * maxScreensAway;\n    var xEdge1 = xLen * (1 + maxScreensAway);\n    var yEdge0 = -yLen * maxScreensAway;\n    var yEdge1 = yLen * (1 + maxScreensAway);\n    var edges = [\n        [xEdge0, yEdge0, xEdge1, yEdge0],\n        [xEdge1, yEdge0, xEdge1, yEdge1],\n        [xEdge1, yEdge1, xEdge0, yEdge1],\n        [xEdge0, yEdge1, xEdge0, yEdge0]\n    ];\n    var xEdge, yEdge, lastXEdge, lastYEdge, lastFarPt, edgePt;\n\n    // for linear line shape, edge intersections should be linearly interpolated\n    // spline uses this too, which isn't precisely correct but is actually pretty\n    // good, because Catmull-Rom weights far-away points less in creating the curvature\n    function getLinearEdgeIntersections(pt1, pt2) {\n        var out = [];\n        var ptCount = 0;\n        for(var i = 0; i < 4; i++) {\n            var edge = edges[i];\n            var ptInt = segmentsIntersect(\n                pt1[0], pt1[1], pt2[0], pt2[1],\n                edge[0], edge[1], edge[2], edge[3]\n            );\n            if(ptInt && (!ptCount ||\n                Math.abs(ptInt.x - out[0][0]) > 1 ||\n                Math.abs(ptInt.y - out[0][1]) > 1\n            )) {\n                ptInt = [ptInt.x, ptInt.y];\n                // if we have 2 intersections, make sure the closest one to pt1 comes first\n                if(ptCount && ptDist(ptInt, pt1) < ptDist(out[0], pt1)) out.unshift(ptInt);\n                else out.push(ptInt);\n                ptCount++;\n            }\n        }\n        return out;\n    }\n\n    function onlyConstrainedPoint(pt) {\n        if(pt[0] < xEdge0 || pt[0] > xEdge1 || pt[1] < yEdge0 || pt[1] > yEdge1) {\n            return [constrain(pt[0], xEdge0, xEdge1), constrain(pt[1], yEdge0, yEdge1)];\n        }\n    }\n\n    function sameEdge(pt1, pt2) {\n        if(pt1[0] === pt2[0] && (pt1[0] === xEdge0 || pt1[0] === xEdge1)) return true;\n        if(pt1[1] === pt2[1] && (pt1[1] === yEdge0 || pt1[1] === yEdge1)) return true;\n    }\n\n    // for line shapes hv and vh, movement in the two dimensions is decoupled,\n    // so all we need to do is constrain each dimension independently\n    function getHVEdgeIntersections(pt1, pt2) {\n        var out = [];\n        var ptInt1 = onlyConstrainedPoint(pt1);\n        var ptInt2 = onlyConstrainedPoint(pt2);\n        if(ptInt1 && ptInt2 && sameEdge(ptInt1, ptInt2)) return out;\n\n        if(ptInt1) out.push(ptInt1);\n        if(ptInt2) out.push(ptInt2);\n        return out;\n    }\n\n    // hvh and vhv we sometimes have to move one of the intersection points\n    // out BEYOND the clipping rect, by a maximum of a factor of 2, so that\n    // the midpoint line is drawn in the right place\n    function getABAEdgeIntersections(dim, limit0, limit1) {\n        return function(pt1, pt2) {\n            var ptInt1 = onlyConstrainedPoint(pt1);\n            var ptInt2 = onlyConstrainedPoint(pt2);\n\n            var out = [];\n            if(ptInt1 && ptInt2 && sameEdge(ptInt1, ptInt2)) return out;\n\n            if(ptInt1) out.push(ptInt1);\n            if(ptInt2) out.push(ptInt2);\n\n            var midShift = 2 * Lib.constrain((pt1[dim] + pt2[dim]) / 2, limit0, limit1) -\n                ((ptInt1 || pt1)[dim] + (ptInt2 || pt2)[dim]);\n            if(midShift) {\n                var ptToAlter;\n                if(ptInt1 && ptInt2) {\n                    ptToAlter = (midShift > 0 === ptInt1[dim] > ptInt2[dim]) ? ptInt1 : ptInt2;\n                } else ptToAlter = ptInt1 || ptInt2;\n\n                ptToAlter[dim] += midShift;\n            }\n\n            return out;\n        };\n    }\n\n    var getEdgeIntersections;\n    if(shape === 'linear' || shape === 'spline') {\n        getEdgeIntersections = getLinearEdgeIntersections;\n    } else if(shape === 'hv' || shape === 'vh') {\n        getEdgeIntersections = getHVEdgeIntersections;\n    } else if(shape === 'hvh') getEdgeIntersections = getABAEdgeIntersections(0, xEdge0, xEdge1);\n    else if(shape === 'vhv') getEdgeIntersections = getABAEdgeIntersections(1, yEdge0, yEdge1);\n\n    // a segment pt1->pt2 entirely outside the nearby region:\n    // find the corner it gets closest to touching\n    function getClosestCorner(pt1, pt2) {\n        var dx = pt2[0] - pt1[0];\n        var m = (pt2[1] - pt1[1]) / dx;\n        var b = (pt1[1] * pt2[0] - pt2[1] * pt1[0]) / dx;\n\n        if(b > 0) return [m > 0 ? xEdge0 : xEdge1, yEdge1];\n        else return [m > 0 ? xEdge1 : xEdge0, yEdge0];\n    }\n\n    function updateEdge(pt) {\n        var x = pt[0];\n        var y = pt[1];\n        var xSame = x === pts[pti - 1][0];\n        var ySame = y === pts[pti - 1][1];\n        // duplicate point?\n        if(xSame && ySame) return;\n        if(pti > 1) {\n            // backtracking along an edge?\n            var xSame2 = x === pts[pti - 2][0];\n            var ySame2 = y === pts[pti - 2][1];\n            if(xSame && (x === xEdge0 || x === xEdge1) && xSame2) {\n                if(ySame2) pti--; // backtracking exactly - drop prev pt and don't add\n                else pts[pti - 1] = pt; // not exact: replace the prev pt\n            } else if(ySame && (y === yEdge0 || y === yEdge1) && ySame2) {\n                if(xSame2) pti--;\n                else pts[pti - 1] = pt;\n            } else pts[pti++] = pt;\n        } else pts[pti++] = pt;\n    }\n\n    function updateEdgesForReentry(pt) {\n        // if we're outside the nearby region and going back in,\n        // we may need to loop around a corner point\n        if(pts[pti - 1][0] !== pt[0] && pts[pti - 1][1] !== pt[1]) {\n            updateEdge([lastXEdge, lastYEdge]);\n        }\n        updateEdge(pt);\n        lastFarPt = null;\n        lastXEdge = lastYEdge = 0;\n    }\n\n    function addPt(pt) {\n        latestXFrac = pt[0] / xLen;\n        latestYFrac = pt[1] / yLen;\n        // Are we more than maxScreensAway off-screen any direction?\n        // if so, clip to this box, but in such a way that on-screen\n        // drawing is unchanged\n        xEdge = (pt[0] < xEdge0) ? xEdge0 : (pt[0] > xEdge1) ? xEdge1 : 0;\n        yEdge = (pt[1] < yEdge0) ? yEdge0 : (pt[1] > yEdge1) ? yEdge1 : 0;\n        if(xEdge || yEdge) {\n            if(!pti) {\n                // to get fills right - if first point is far, push it toward the\n                // screen in whichever direction(s) are far\n\n                pts[pti++] = [xEdge || pt[0], yEdge || pt[1]];\n            } else if(lastFarPt) {\n                // both this point and the last are outside the nearby region\n                // check if we're crossing the nearby region\n                var intersections = getEdgeIntersections(lastFarPt, pt);\n                if(intersections.length > 1) {\n                    updateEdgesForReentry(intersections[0]);\n                    pts[pti++] = intersections[1];\n                }\n            } else {\n                // we're leaving the nearby region - add the point where we left it\n\n                edgePt = getEdgeIntersections(pts[pti - 1], pt)[0];\n                pts[pti++] = edgePt;\n            }\n\n            var lastPt = pts[pti - 1];\n            if(xEdge && yEdge && (lastPt[0] !== xEdge || lastPt[1] !== yEdge)) {\n                // we've gone out beyond a new corner: add the corner too\n                // so that the next point will take the right winding\n                if(lastFarPt) {\n                    if(lastXEdge !== xEdge && lastYEdge !== yEdge) {\n                        if(lastXEdge && lastYEdge) {\n                            // we've gone around to an opposite corner - we\n                            // need to add the correct extra corner\n                            // in order to get the right winding\n                            updateEdge(getClosestCorner(lastFarPt, pt));\n                        } else {\n                            // we're coming from a far edge - the extra corner\n                            // we need is determined uniquely by the sectors\n                            updateEdge([lastXEdge || xEdge, lastYEdge || yEdge]);\n                        }\n                    } else if(lastXEdge && lastYEdge) {\n                        updateEdge([lastXEdge, lastYEdge]);\n                    }\n                }\n                updateEdge([xEdge, yEdge]);\n            } else if((lastXEdge - xEdge) && (lastYEdge - yEdge)) {\n                // we're coming from an edge or far corner to an edge - again the\n                // extra corner we need is uniquely determined by the sectors\n                updateEdge([xEdge || lastXEdge, yEdge || lastYEdge]);\n            }\n            lastFarPt = pt;\n            lastXEdge = xEdge;\n            lastYEdge = yEdge;\n        } else {\n            if(lastFarPt) {\n                // this point is in range but the previous wasn't: add its entry pt first\n                updateEdgesForReentry(getEdgeIntersections(lastFarPt, pt)[0]);\n            }\n\n            pts[pti++] = pt;\n        }\n    }\n\n    // loop over ALL points in this trace\n    for(i = 0; i < len; i++) {\n        clusterStartPt = getPt(i);\n        if(!clusterStartPt) continue;\n\n        pti = 0;\n        lastFarPt = null;\n        addPt(clusterStartPt);\n\n        // loop over one segment of the trace\n        for(i++; i < len; i++) {\n            clusterHighPt = getPt(i);\n            if(!clusterHighPt) {\n                if(connectGaps) continue;\n                else break;\n            }\n\n            // can't decimate if nonlinear line shape\n            // TODO: we *could* decimate [hv]{2,3} shapes if we restricted clusters to horz or vert again\n            // but spline would be verrry awkward to decimate\n            if(!linear || !opts.simplify) {\n                addPt(clusterHighPt);\n                continue;\n            }\n\n            var nextPt = getPt(i + 1);\n\n            clusterRefDist = ptDist(clusterHighPt, clusterStartPt);\n\n            // #3147 - always include the very first and last points for fills\n            if(!(fill && (pti === 0 || pti === len - 1)) &&\n                clusterRefDist < getTolerance(clusterHighPt, nextPt) * minTolerance) continue;\n\n            clusterUnitVector = [\n                (clusterHighPt[0] - clusterStartPt[0]) / clusterRefDist,\n                (clusterHighPt[1] - clusterStartPt[1]) / clusterRefDist\n            ];\n\n            clusterLowPt = clusterStartPt;\n            clusterHighVal = clusterRefDist;\n            clusterLowVal = clusterMinDeviation = clusterMaxDeviation = 0;\n            clusterHighFirst = false;\n            clusterEndPt = clusterHighPt;\n\n            // loop over one cluster of points that collapse onto one line\n            for(i++; i < d.length; i++) {\n                thisPt = nextPt;\n                nextPt = getPt(i + 1);\n                if(!thisPt) {\n                    if(connectGaps) continue;\n                    else break;\n                }\n                thisVector = [\n                    thisPt[0] - clusterStartPt[0],\n                    thisPt[1] - clusterStartPt[1]\n                ];\n                // cross product (or dot with normal to the cluster vector)\n                thisDeviation = thisVector[0] * clusterUnitVector[1] - thisVector[1] * clusterUnitVector[0];\n                clusterMinDeviation = Math.min(clusterMinDeviation, thisDeviation);\n                clusterMaxDeviation = Math.max(clusterMaxDeviation, thisDeviation);\n\n                if(clusterMaxDeviation - clusterMinDeviation > getTolerance(thisPt, nextPt)) break;\n\n                clusterEndPt = thisPt;\n                thisVal = thisVector[0] * clusterUnitVector[0] + thisVector[1] * clusterUnitVector[1];\n\n                if(thisVal > clusterHighVal) {\n                    clusterHighVal = thisVal;\n                    clusterHighPt = thisPt;\n                    clusterHighFirst = false;\n                } else if(thisVal < clusterLowVal) {\n                    clusterLowVal = thisVal;\n                    clusterLowPt = thisPt;\n                    clusterHighFirst = true;\n                }\n            }\n\n            // insert this cluster into pts\n            // we've already inserted the start pt, now check if we have high and low pts\n            if(clusterHighFirst) {\n                addPt(clusterHighPt);\n                if(clusterEndPt !== clusterLowPt) addPt(clusterLowPt);\n            } else {\n                if(clusterLowPt !== clusterStartPt) addPt(clusterLowPt);\n                if(clusterEndPt !== clusterHighPt) addPt(clusterHighPt);\n            }\n            // and finally insert the end pt\n            addPt(clusterEndPt);\n\n            // have we reached the end of this segment?\n            if(i >= d.length || !thisPt) break;\n\n            // otherwise we have an out-of-cluster point to insert as next clusterStartPt\n            addPt(thisPt);\n            clusterStartPt = thisPt;\n        }\n\n        // to get fills right - repeat what we did at the start\n        if(lastFarPt) updateEdge([lastXEdge || lastFarPt[0], lastYEdge || lastFarPt[1]]);\n\n        segments.push(pts.slice(0, pti));\n    }\n\n    return segments;\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"./constants\":1116}],1126:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\n// common to 'scatter' and 'scatterternary'\nmodule.exports = function handleLineShapeDefaults(traceIn, traceOut, coerce) {\n    var shape = coerce('line.shape');\n    if(shape === 'spline') coerce('line.smoothing');\n};\n\n},{}],1127:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar LINKEDFILLS = {tonextx: 1, tonexty: 1, tonext: 1};\n\nmodule.exports = function linkTraces(gd, plotinfo, cdscatter) {\n    var trace, i, group, prevtrace, groupIndex;\n\n    // first sort traces to keep stacks & filled-together groups together\n    var groupIndices = {};\n    var needsSort = false;\n    var prevGroupIndex = -1;\n    var nextGroupIndex = 0;\n    var prevUnstackedGroupIndex = -1;\n    for(i = 0; i < cdscatter.length; i++) {\n        trace = cdscatter[i][0].trace;\n        group = trace.stackgroup || '';\n        if(group) {\n            if(group in groupIndices) {\n                groupIndex = groupIndices[group];\n            } else {\n                groupIndex = groupIndices[group] = nextGroupIndex;\n                nextGroupIndex++;\n            }\n        } else if(trace.fill in LINKEDFILLS && prevUnstackedGroupIndex >= 0) {\n            groupIndex = prevUnstackedGroupIndex;\n        } else {\n            groupIndex = prevUnstackedGroupIndex = nextGroupIndex;\n            nextGroupIndex++;\n        }\n\n        if(groupIndex < prevGroupIndex) needsSort = true;\n        trace._groupIndex = prevGroupIndex = groupIndex;\n    }\n\n    var cdscatterSorted = cdscatter.slice();\n    if(needsSort) {\n        cdscatterSorted.sort(function(a, b) {\n            var traceA = a[0].trace;\n            var traceB = b[0].trace;\n            return (traceA._groupIndex - traceB._groupIndex) ||\n                (traceA.index - traceB.index);\n        });\n    }\n\n    // now link traces to each other\n    var prevtraces = {};\n    for(i = 0; i < cdscatterSorted.length; i++) {\n        trace = cdscatterSorted[i][0].trace;\n        group = trace.stackgroup || '';\n\n        // Note: The check which ensures all cdscatter here are for the same axis and\n        // are either cartesian or scatterternary has been removed. This code assumes\n        // the passed scattertraces have been filtered to the proper plot types and\n        // the proper subplots.\n        if(trace.visible === true) {\n            trace._nexttrace = null;\n\n            if(trace.fill in LINKEDFILLS) {\n                prevtrace = prevtraces[group];\n                trace._prevtrace = prevtrace || null;\n\n                if(prevtrace) {\n                    prevtrace._nexttrace = trace;\n                }\n            }\n\n            trace._ownfill = (trace.fill && (\n                trace.fill.substr(0, 6) === 'tozero' ||\n                trace.fill === 'toself' ||\n                (trace.fill.substr(0, 2) === 'to' && !trace._prevtrace)\n            ));\n\n            prevtraces[group] = trace;\n        } else {\n            trace._prevtrace = trace._nexttrace = trace._ownfill = null;\n        }\n    }\n\n    return cdscatterSorted;\n};\n\n},{}],1128:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\n\n// used in the drawing step for 'scatter' and 'scattegeo' and\n// in the convert step for 'scatter3d'\nmodule.exports = function makeBubbleSizeFn(trace) {\n    var marker = trace.marker;\n    var sizeRef = marker.sizeref || 1;\n    var sizeMin = marker.sizemin || 0;\n\n    // for bubble charts, allow scaling the provided value linearly\n    // and by area or diameter.\n    // Note this only applies to the array-value sizes\n\n    var baseFn = (marker.sizemode === 'area') ?\n        function(v) { return Math.sqrt(v / sizeRef); } :\n        function(v) { return v / sizeRef; };\n\n    // TODO add support for position/negative bubbles?\n    // TODO add 'sizeoffset' attribute?\n    return function(v) {\n        var baseSize = baseFn(v / 2);\n\n        // don't show non-numeric and negative sizes\n        return (isNumeric(baseSize) && (baseSize > 0)) ?\n            Math.max(baseSize, sizeMin) :\n            0;\n    };\n};\n\n},{\"fast-isnumeric\":225}],1129:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nmodule.exports = {\n    container: 'marker',\n    min: 'cmin',\n    max: 'cmax'\n};\n\n},{}],1130:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Color = _dereq_('../../components/color');\nvar hasColorscale = _dereq_('../../components/colorscale/helpers').hasColorscale;\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\n\nvar subTypes = _dereq_('./subtypes');\n\n/*\n * opts: object of flags to control features not all marker users support\n *   noLine: caller does not support marker lines\n *   gradient: caller supports gradients\n *   noSelect: caller does not support selected/unselected attribute containers\n */\nmodule.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) {\n    var isBubble = subTypes.isBubble(traceIn);\n    var lineColor = (traceIn.line || {}).color;\n    var defaultMLC;\n\n    opts = opts || {};\n\n    // marker.color inherit from line.color (even if line.color is an array)\n    if(lineColor) defaultColor = lineColor;\n\n    coerce('marker.symbol');\n    coerce('marker.opacity', isBubble ? 0.7 : 1);\n    coerce('marker.size');\n\n    coerce('marker.color', defaultColor);\n    if(hasColorscale(traceIn, 'marker')) {\n        colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});\n    }\n\n    if(!opts.noSelect) {\n        coerce('selected.marker.color');\n        coerce('unselected.marker.color');\n        coerce('selected.marker.size');\n        coerce('unselected.marker.size');\n    }\n\n    if(!opts.noLine) {\n        // if there's a line with a different color than the marker, use\n        // that line color as the default marker line color\n        // (except when it's an array)\n        // mostly this is for transparent markers to behave nicely\n        if(lineColor && !Array.isArray(lineColor) && (traceOut.marker.color !== lineColor)) {\n            defaultMLC = lineColor;\n        } else if(isBubble) defaultMLC = Color.background;\n        else defaultMLC = Color.defaultLine;\n\n        coerce('marker.line.color', defaultMLC);\n        if(hasColorscale(traceIn, 'marker.line')) {\n            colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'});\n        }\n\n        coerce('marker.line.width', isBubble ? 1 : 0);\n    }\n\n    if(isBubble) {\n        coerce('marker.sizeref');\n        coerce('marker.sizemin');\n        coerce('marker.sizemode');\n    }\n\n    if(opts.gradient) {\n        var gradientType = coerce('marker.gradient.type');\n        if(gradientType !== 'none') {\n            coerce('marker.gradient.color');\n        }\n    }\n};\n\n},{\"../../components/color\":593,\"../../components/colorscale/defaults\":603,\"../../components/colorscale/helpers\":604,\"./subtypes\":1135}],1131:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar ensureSingle = Lib.ensureSingle;\nvar identity = Lib.identity;\nvar Drawing = _dereq_('../../components/drawing');\n\nvar subTypes = _dereq_('./subtypes');\nvar linePoints = _dereq_('./line_points');\nvar linkTraces = _dereq_('./link_traces');\nvar polygonTester = _dereq_('../../lib/polygon').tester;\n\nmodule.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transitionOpts, makeOnCompleteCallback) {\n    var join, onComplete;\n\n    // If transition config is provided, then it is only a partial replot and traces not\n    // updated are removed.\n    var isFullReplot = !transitionOpts;\n    var hasTransition = !!transitionOpts && transitionOpts.duration > 0;\n\n    // Link traces so the z-order of fill layers is correct\n    var cdscatterSorted = linkTraces(gd, plotinfo, cdscatter);\n\n    join = scatterLayer.selectAll('g.trace')\n        .data(cdscatterSorted, function(d) { return d[0].trace.uid; });\n\n    // Append new traces:\n    join.enter().append('g')\n        .attr('class', function(d) {\n            return 'trace scatter trace' + d[0].trace.uid;\n        })\n        .style('stroke-miterlimit', 2);\n    join.order();\n\n    createFills(gd, join, plotinfo);\n\n    if(hasTransition) {\n        if(makeOnCompleteCallback) {\n            // If it was passed a callback to register completion, make a callback. If\n            // this is created, then it must be executed on completion, otherwise the\n            // pos-transition redraw will not execute:\n            onComplete = makeOnCompleteCallback();\n        }\n\n        var transition = d3.transition()\n            .duration(transitionOpts.duration)\n            .ease(transitionOpts.easing)\n            .each('end', function() {\n                onComplete && onComplete();\n            })\n            .each('interrupt', function() {\n                onComplete && onComplete();\n            });\n\n        transition.each(function() {\n            // Must run the selection again since otherwise enters/updates get grouped together\n            // and these get executed out of order. Except we need them in order!\n            scatterLayer.selectAll('g.trace').each(function(d, i) {\n                plotOne(gd, i, plotinfo, d, cdscatterSorted, this, transitionOpts);\n            });\n        });\n    } else {\n        join.each(function(d, i) {\n            plotOne(gd, i, plotinfo, d, cdscatterSorted, this, transitionOpts);\n        });\n    }\n\n    if(isFullReplot) {\n        join.exit().remove();\n    }\n\n    // remove paths that didn't get used\n    scatterLayer.selectAll('path:not([d])').remove();\n};\n\nfunction createFills(gd, traceJoin, plotinfo) {\n    traceJoin.each(function(d) {\n        var fills = ensureSingle(d3.select(this), 'g', 'fills');\n        Drawing.setClipUrl(fills, plotinfo.layerClipId, gd);\n\n        var trace = d[0].trace;\n\n        var fillData = [];\n        if(trace._ownfill) fillData.push('_ownFill');\n        if(trace._nexttrace) fillData.push('_nextFill');\n\n        var fillJoin = fills.selectAll('g').data(fillData, identity);\n\n        fillJoin.enter().append('g');\n\n        fillJoin.exit()\n            .each(function(d) { trace[d] = null; })\n            .remove();\n\n        fillJoin.order().each(function(d) {\n            // make a path element inside the fill group, just so\n            // we can give it its own data later on and the group can\n            // keep its simple '_*Fill' data\n            trace[d] = ensureSingle(d3.select(this), 'path', 'js-fill');\n        });\n    });\n}\n\nfunction plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transitionOpts) {\n    var i;\n\n    // Since this has been reorganized and we're executing this on individual traces,\n    // we need to pass it the full list of cdscatter as well as this trace's index (idx)\n    // since it does an internal n^2 loop over comparisons with other traces:\n    selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll);\n\n    var hasTransition = !!transitionOpts && transitionOpts.duration > 0;\n\n    function transition(selection) {\n        return hasTransition ? selection.transition() : selection;\n    }\n\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    var trace = cdscatter[0].trace;\n    var line = trace.line;\n    var tr = d3.select(element);\n\n    var errorBarGroup = ensureSingle(tr, 'g', 'errorbars');\n    var lines = ensureSingle(tr, 'g', 'lines');\n    var points = ensureSingle(tr, 'g', 'points');\n    var text = ensureSingle(tr, 'g', 'text');\n\n    // error bars are at the bottom\n    Registry.getComponentMethod('errorbars', 'plot')(gd, errorBarGroup, plotinfo, transitionOpts);\n\n    if(trace.visible !== true) return;\n\n    transition(tr).style('opacity', trace.opacity);\n\n    // BUILD LINES AND FILLS\n    var ownFillEl3, tonext;\n    var ownFillDir = trace.fill.charAt(trace.fill.length - 1);\n    if(ownFillDir !== 'x' && ownFillDir !== 'y') ownFillDir = '';\n\n    // store node for tweaking by selectPoints\n    cdscatter[0][plotinfo.isRangePlot ? 'nodeRangePlot3' : 'node3'] = tr;\n\n    var prevRevpath = '';\n    var prevPolygons = [];\n    var prevtrace = trace._prevtrace;\n\n    if(prevtrace) {\n        prevRevpath = prevtrace._prevRevpath || '';\n        tonext = prevtrace._nextFill;\n        prevPolygons = prevtrace._polygons;\n    }\n\n    var thispath;\n    var thisrevpath;\n    // fullpath is all paths for this curve, joined together straight\n    // across gaps, for filling\n    var fullpath = '';\n    // revpath is fullpath reversed, for fill-to-next\n    var revpath = '';\n    // functions for converting a point array to a path\n    var pathfn, revpathbase, revpathfn;\n    // variables used before and after the data join\n    var pt0, lastSegment, pt1, thisPolygons;\n\n    // initialize line join data / method\n    var segments = [];\n    var makeUpdate = Lib.noop;\n\n    ownFillEl3 = trace._ownFill;\n\n    if(subTypes.hasLines(trace) || trace.fill !== 'none') {\n        if(tonext) {\n            // This tells .style which trace to use for fill information:\n            tonext.datum(cdscatter);\n        }\n\n        if(['hv', 'vh', 'hvh', 'vhv'].indexOf(line.shape) !== -1) {\n            pathfn = Drawing.steps(line.shape);\n            revpathbase = Drawing.steps(\n                line.shape.split('').reverse().join('')\n            );\n        } else if(line.shape === 'spline') {\n            pathfn = revpathbase = function(pts) {\n                var pLast = pts[pts.length - 1];\n                if(pts.length > 1 && pts[0][0] === pLast[0] && pts[0][1] === pLast[1]) {\n                    // identical start and end points: treat it as a\n                    // closed curve so we don't get a kink\n                    return Drawing.smoothclosed(pts.slice(1), line.smoothing);\n                } else {\n                    return Drawing.smoothopen(pts, line.smoothing);\n                }\n            };\n        } else {\n            pathfn = revpathbase = function(pts) {\n                return 'M' + pts.join('L');\n            };\n        }\n\n        revpathfn = function(pts) {\n            // note: this is destructive (reverses pts in place) so can't use pts after this\n            return revpathbase(pts.reverse());\n        };\n\n        segments = linePoints(cdscatter, {\n            xaxis: xa,\n            yaxis: ya,\n            connectGaps: trace.connectgaps,\n            baseTolerance: Math.max(line.width || 1, 3) / 4,\n            shape: line.shape,\n            simplify: line.simplify,\n            fill: trace.fill\n        });\n\n        // since we already have the pixel segments here, use them to make\n        // polygons for hover on fill\n        // TODO: can we skip this if hoveron!=fills? That would mean we\n        // need to redraw when you change hoveron...\n        thisPolygons = trace._polygons = new Array(segments.length);\n        for(i = 0; i < segments.length; i++) {\n            trace._polygons[i] = polygonTester(segments[i]);\n        }\n\n        if(segments.length) {\n            pt0 = segments[0][0];\n            lastSegment = segments[segments.length - 1];\n            pt1 = lastSegment[lastSegment.length - 1];\n        }\n\n        makeUpdate = function(isEnter) {\n            return function(pts) {\n                thispath = pathfn(pts);\n                thisrevpath = revpathfn(pts);\n                if(!fullpath) {\n                    fullpath = thispath;\n                    revpath = thisrevpath;\n                } else if(ownFillDir) {\n                    fullpath += 'L' + thispath.substr(1);\n                    revpath = thisrevpath + ('L' + revpath.substr(1));\n                } else {\n                    fullpath += 'Z' + thispath;\n                    revpath = thisrevpath + 'Z' + revpath;\n                }\n\n                if(subTypes.hasLines(trace) && pts.length > 1) {\n                    var el = d3.select(this);\n\n                    // This makes the coloring work correctly:\n                    el.datum(cdscatter);\n\n                    if(isEnter) {\n                        transition(el.style('opacity', 0)\n                            .attr('d', thispath)\n                            .call(Drawing.lineGroupStyle))\n                                .style('opacity', 1);\n                    } else {\n                        var sel = transition(el);\n                        sel.attr('d', thispath);\n                        Drawing.singleLineStyle(cdscatter, sel);\n                    }\n                }\n            };\n        };\n    }\n\n    var lineJoin = lines.selectAll('.js-line').data(segments);\n\n    transition(lineJoin.exit())\n        .style('opacity', 0)\n        .remove();\n\n    lineJoin.each(makeUpdate(false));\n\n    lineJoin.enter().append('path')\n        .classed('js-line', true)\n        .style('vector-effect', 'non-scaling-stroke')\n        .call(Drawing.lineGroupStyle)\n        .each(makeUpdate(true));\n\n    Drawing.setClipUrl(lineJoin, plotinfo.layerClipId, gd);\n\n    function clearFill(selection) {\n        transition(selection).attr('d', 'M0,0Z');\n    }\n\n    if(segments.length) {\n        if(ownFillEl3) {\n            ownFillEl3.datum(cdscatter);\n            if(pt0 && pt1) {\n                if(ownFillDir) {\n                    if(ownFillDir === 'y') {\n                        pt0[1] = pt1[1] = ya.c2p(0, true);\n                    } else if(ownFillDir === 'x') {\n                        pt0[0] = pt1[0] = xa.c2p(0, true);\n                    }\n\n                    // fill to zero: full trace path, plus extension of\n                    // the endpoints to the appropriate axis\n                    // For the sake of animations, wrap the points around so that\n                    // the points on the axes are the first two points. Otherwise\n                    // animations get a little crazy if the number of points changes.\n                    transition(ownFillEl3).attr('d', 'M' + pt1 + 'L' + pt0 + 'L' + fullpath.substr(1))\n                        .call(Drawing.singleFillStyle);\n                } else {\n                    // fill to self: just join the path to itself\n                    transition(ownFillEl3).attr('d', fullpath + 'Z')\n                        .call(Drawing.singleFillStyle);\n                }\n            }\n        } else if(tonext) {\n            if(trace.fill.substr(0, 6) === 'tonext' && fullpath && prevRevpath) {\n                // fill to next: full trace path, plus the previous path reversed\n                if(trace.fill === 'tonext') {\n                    // tonext: for use by concentric shapes, like manually constructed\n                    // contours, we just add the two paths closed on themselves.\n                    // This makes strange results if one path is *not* entirely\n                    // inside the other, but then that is a strange usage.\n                    transition(tonext).attr('d', fullpath + 'Z' + prevRevpath + 'Z')\n                        .call(Drawing.singleFillStyle);\n                } else {\n                    // tonextx/y: for now just connect endpoints with lines. This is\n                    // the correct behavior if the endpoints are at the same value of\n                    // y/x, but if they *aren't*, we should ideally do more complicated\n                    // things depending on whether the new endpoint projects onto the\n                    // existing curve or off the end of it\n                    transition(tonext).attr('d', fullpath + 'L' + prevRevpath.substr(1) + 'Z')\n                        .call(Drawing.singleFillStyle);\n                }\n                trace._polygons = trace._polygons.concat(prevPolygons);\n            } else {\n                clearFill(tonext);\n                trace._polygons = null;\n            }\n        }\n        trace._prevRevpath = revpath;\n        trace._prevPolygons = thisPolygons;\n    } else {\n        if(ownFillEl3) clearFill(ownFillEl3);\n        else if(tonext) clearFill(tonext);\n        trace._polygons = trace._prevRevpath = trace._prevPolygons = null;\n    }\n\n\n    function visFilter(d) {\n        return d.filter(function(v) { return !v.gap && v.vis; });\n    }\n\n    function visFilterWithGaps(d) {\n        return d.filter(function(v) { return v.vis; });\n    }\n\n    function gapFilter(d) {\n        return d.filter(function(v) { return !v.gap; });\n    }\n\n    function keyFunc(d) {\n        return d.id;\n    }\n\n    // Returns a function if the trace is keyed, otherwise returns undefined\n    function getKeyFunc(trace) {\n        if(trace.ids) {\n            return keyFunc;\n        }\n    }\n\n    function hideFilter() {\n        return false;\n    }\n\n    function makePoints(points, text, cdscatter) {\n        var join, selection, hasNode;\n\n        var trace = cdscatter[0].trace;\n        var showMarkers = subTypes.hasMarkers(trace);\n        var showText = subTypes.hasText(trace);\n\n        var keyFunc = getKeyFunc(trace);\n        var markerFilter = hideFilter;\n        var textFilter = hideFilter;\n\n        if(showMarkers || showText) {\n            var showFilter = identity;\n            // if we're stacking, \"infer zero\" gap mode gets markers in the\n            // gap points - because we've inferred a zero there - but other\n            // modes (currently \"interpolate\", later \"interrupt\" hopefully)\n            // we don't draw generated markers\n            var stackGroup = trace.stackgroup;\n            var isInferZero = stackGroup && (\n                gd._fullLayout._scatterStackOpts[xa._id + ya._id][stackGroup].stackgaps === 'infer zero');\n            if(trace.marker.maxdisplayed || trace._needsCull) {\n                showFilter = isInferZero ? visFilterWithGaps : visFilter;\n            } else if(stackGroup && !isInferZero) {\n                showFilter = gapFilter;\n            }\n\n            if(showMarkers) markerFilter = showFilter;\n            if(showText) textFilter = showFilter;\n        }\n\n        // marker points\n\n        selection = points.selectAll('path.point');\n\n        join = selection.data(markerFilter, keyFunc);\n\n        var enter = join.enter().append('path')\n            .classed('point', true);\n\n        if(hasTransition) {\n            enter\n                .call(Drawing.pointStyle, trace, gd)\n                .call(Drawing.translatePoints, xa, ya)\n                .style('opacity', 0)\n                .transition()\n                .style('opacity', 1);\n        }\n\n        join.order();\n\n        var styleFns;\n        if(showMarkers) {\n            styleFns = Drawing.makePointStyleFns(trace);\n        }\n\n        join.each(function(d) {\n            var el = d3.select(this);\n            var sel = transition(el);\n            hasNode = Drawing.translatePoint(d, sel, xa, ya);\n\n            if(hasNode) {\n                Drawing.singlePointStyle(d, sel, trace, styleFns, gd);\n\n                if(plotinfo.layerClipId) {\n                    Drawing.hideOutsideRangePoint(d, sel, xa, ya, trace.xcalendar, trace.ycalendar);\n                }\n\n                if(trace.customdata) {\n                    el.classed('plotly-customdata', d.data !== null && d.data !== undefined);\n                }\n            } else {\n                sel.remove();\n            }\n        });\n\n        if(hasTransition) {\n            join.exit().transition()\n                .style('opacity', 0)\n                .remove();\n        } else {\n            join.exit().remove();\n        }\n\n        // text points\n        selection = text.selectAll('g');\n        join = selection.data(textFilter, keyFunc);\n\n        // each text needs to go in its own 'g' in case\n        // it gets converted to mathjax\n        join.enter().append('g').classed('textpoint', true).append('text');\n\n        join.order();\n\n        join.each(function(d) {\n            var g = d3.select(this);\n            var sel = transition(g.select('text'));\n            hasNode = Drawing.translatePoint(d, sel, xa, ya);\n\n            if(hasNode) {\n                if(plotinfo.layerClipId) {\n                    Drawing.hideOutsideRangePoint(d, g, xa, ya, trace.xcalendar, trace.ycalendar);\n                }\n            } else {\n                g.remove();\n            }\n        });\n\n        join.selectAll('text')\n            .call(Drawing.textPointStyle, trace, gd)\n            .each(function(d) {\n                // This just *has* to be totally custom becuase of SVG text positioning :(\n                // It's obviously copied from translatePoint; we just can't use that\n                var x = xa.c2p(d.x);\n                var y = ya.c2p(d.y);\n\n                d3.select(this).selectAll('tspan.line').each(function() {\n                    transition(d3.select(this)).attr({x: x, y: y});\n                });\n            });\n\n        join.exit().remove();\n    }\n\n    points.datum(cdscatter);\n    text.datum(cdscatter);\n    makePoints(points, text, cdscatter);\n\n    // lastly, clip points groups of `cliponaxis !== false` traces\n    // on `plotinfo._hasClipOnAxisFalse === true` subplots\n    var hasClipOnAxisFalse = trace.cliponaxis === false;\n    var clipUrl = hasClipOnAxisFalse ? null : plotinfo.layerClipId;\n    Drawing.setClipUrl(points, clipUrl, gd);\n    Drawing.setClipUrl(text, clipUrl, gd);\n}\n\nfunction selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n    var xr = d3.extent(Lib.simpleMap(xa.range, xa.r2c));\n    var yr = d3.extent(Lib.simpleMap(ya.range, ya.r2c));\n\n    var trace = cdscatter[0].trace;\n    if(!subTypes.hasMarkers(trace)) return;\n    // if marker.maxdisplayed is used, select a maximum of\n    // mnum markers to show, from the set that are in the viewport\n    var mnum = trace.marker.maxdisplayed;\n\n    // TODO: remove some as we get away from the viewport?\n    if(mnum === 0) return;\n\n    var cd = cdscatter.filter(function(v) {\n        return v.x >= xr[0] && v.x <= xr[1] && v.y >= yr[0] && v.y <= yr[1];\n    });\n    var inc = Math.ceil(cd.length / mnum);\n    var tnum = 0;\n    cdscatterAll.forEach(function(cdj, j) {\n        var tracei = cdj[0].trace;\n        if(subTypes.hasMarkers(tracei) &&\n                tracei.marker.maxdisplayed > 0 && j < idx) {\n            tnum++;\n        }\n    });\n\n    // if multiple traces use maxdisplayed, stagger which markers we\n    // display this formula offsets successive traces by 1/3 of the\n    // increment, adding an extra small amount after each triplet so\n    // it's not quite periodic\n    var i0 = Math.round(tnum * inc / 3 + Math.floor(tnum / 3) * inc / 7.1);\n\n    // for error bars: save in cd which markers to show\n    // so we don't have to repeat this\n    cdscatter.forEach(function(v) { delete v.vis; });\n    cd.forEach(function(v, i) {\n        if(Math.round((i + i0) % inc) === 0) v.vis = true;\n    });\n}\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/polygon\":731,\"../../registry\":847,\"./line_points\":1125,\"./link_traces\":1127,\"./subtypes\":1135,\"d3\":163}],1132:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar subtypes = _dereq_('./subtypes');\n\nmodule.exports = function selectPoints(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var xa = searchInfo.xaxis;\n    var ya = searchInfo.yaxis;\n    var selection = [];\n    var trace = cd[0].trace;\n    var i;\n    var di;\n    var x;\n    var y;\n\n    var hasOnlyLines = (!subtypes.hasMarkers(trace) && !subtypes.hasText(trace));\n    if(hasOnlyLines) return [];\n\n    if(selectionTester === false) { // clear selection\n        for(i = 0; i < cd.length; i++) {\n            cd[i].selected = 0;\n        }\n    } else {\n        for(i = 0; i < cd.length; i++) {\n            di = cd[i];\n            x = xa.c2p(di.x);\n            y = ya.c2p(di.y);\n\n            if((di.i !== null) && selectionTester.contains([x, y], false, i, searchInfo)) {\n                selection.push({\n                    pointNumber: di.i,\n                    x: xa.c2d(di.x),\n                    y: ya.c2d(di.y)\n                });\n                di.selected = 1;\n            } else {\n                di.selected = 0;\n            }\n        }\n    }\n\n    return selection;\n};\n\n},{\"./subtypes\":1135}],1133:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar perStackAttrs = ['orientation', 'groupnorm', 'stackgaps'];\n\nmodule.exports = function handleStackDefaults(traceIn, traceOut, layout, coerce) {\n    var stackOpts = layout._scatterStackOpts;\n\n    var stackGroup = coerce('stackgroup');\n    if(stackGroup) {\n        // use independent stacking options per subplot\n        var subplot = traceOut.xaxis + traceOut.yaxis;\n        var subplotStackOpts = stackOpts[subplot];\n        if(!subplotStackOpts) subplotStackOpts = stackOpts[subplot] = {};\n\n        var groupOpts = subplotStackOpts[stackGroup];\n        var firstTrace = false;\n        if(groupOpts) {\n            groupOpts.traces.push(traceOut);\n        } else {\n            groupOpts = subplotStackOpts[stackGroup] = {\n                // keep track of trace indices for use during stacking calculations\n                // this will be filled in during `calc` and used during `crossTraceCalc`\n                // so it's OK if we don't recreate it during a non-calc edit\n                traceIndices: [],\n                // Hold on to the whole set of prior traces\n                // First one is most important, so we can clear defaults\n                // there if we find explicit values only in later traces.\n                // We're only going to *use* the values stored in groupOpts,\n                // but for the editor and validate we want things self-consistent\n                // The full set of traces is used only to fix `fill` default if\n                // we find `orientation: 'h'` beyond the first trace\n                traces: [traceOut]\n            };\n            firstTrace = true;\n        }\n        // TODO: how is this going to work with groupby transforms?\n        // in principle it should be OK I guess, as long as explicit group styles\n        // don't override explicit base-trace styles?\n\n        var dflts = {\n            orientation: (traceOut.x && !traceOut.y) ? 'h' : 'v'\n        };\n\n        for(var i = 0; i < perStackAttrs.length; i++) {\n            var attr = perStackAttrs[i];\n            var attrFound = attr + 'Found';\n            if(!groupOpts[attrFound]) {\n                var traceHasAttr = traceIn[attr] !== undefined;\n                var isOrientation = attr === 'orientation';\n                if(traceHasAttr || firstTrace) {\n                    groupOpts[attr] = coerce(attr, dflts[attr]);\n\n                    if(isOrientation) {\n                        groupOpts.fillDflt = groupOpts[attr] === 'h' ?\n                            'tonextx' : 'tonexty';\n                    }\n\n                    if(traceHasAttr) {\n                        // Note: this will show a value here even if it's invalid\n                        // in which case it will revert to default.\n                        groupOpts[attrFound] = true;\n\n                        // Note: only one trace in the stack will get a _fullData\n                        // entry for a given stack-wide attribute. If no traces\n                        // (or the first trace) specify that attribute, the\n                        // first trace will get it. If the first trace does NOT\n                        // specify it but some later trace does, then it gets\n                        // removed from the first trace and only included in the\n                        // one that specified it. This is mostly important for\n                        // editors (that want to see the full values to know\n                        // what settings are available) and Plotly.react diffing.\n                        // Editors may want to use fullLayout._scatterStackOpts\n                        // directly and make these settings available from all\n                        // traces in the stack... then set the new value into\n                        // the first trace, and clear all later traces.\n                        if(!firstTrace) {\n                            delete groupOpts.traces[0][attr];\n\n                            // orientation can affect default fill of previous traces\n                            if(isOrientation) {\n                                for(var j = 0; j < groupOpts.traces.length - 1; j++) {\n                                    var trace2 = groupOpts.traces[j];\n                                    if(trace2._input.fill !== trace2.fill) {\n                                        trace2.fill = groupOpts.fillDflt;\n                                    }\n                                }\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        return groupOpts;\n    }\n};\n\n},{}],1134:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Drawing = _dereq_('../../components/drawing');\nvar Registry = _dereq_('../../registry');\n\nfunction style(gd) {\n    var s = d3.select(gd).selectAll('g.trace.scatter');\n\n    s.style('opacity', function(d) {\n        return d[0].trace.opacity;\n    });\n\n    s.selectAll('g.points').each(function(d) {\n        var sel = d3.select(this);\n        var trace = d.trace || d[0].trace;\n        stylePoints(sel, trace, gd);\n    });\n\n    s.selectAll('g.text').each(function(d) {\n        var sel = d3.select(this);\n        var trace = d.trace || d[0].trace;\n        styleText(sel, trace, gd);\n    });\n\n    s.selectAll('g.trace path.js-line')\n        .call(Drawing.lineGroupStyle);\n\n    s.selectAll('g.trace path.js-fill')\n        .call(Drawing.fillGroupStyle);\n\n    Registry.getComponentMethod('errorbars', 'style')(s);\n}\n\nfunction stylePoints(sel, trace, gd) {\n    Drawing.pointStyle(sel.selectAll('path.point'), trace, gd);\n}\n\nfunction styleText(sel, trace, gd) {\n    Drawing.textPointStyle(sel.selectAll('text'), trace, gd);\n}\n\nfunction styleOnSelect(gd, cd, sel) {\n    var trace = cd[0].trace;\n\n    if(trace.selectedpoints) {\n        Drawing.selectedPointStyle(sel.selectAll('path.point'), trace);\n        Drawing.selectedTextStyle(sel.selectAll('text'), trace);\n    } else {\n        stylePoints(sel, trace, gd);\n        styleText(sel, trace, gd);\n    }\n}\n\nmodule.exports = {\n    style: style,\n    stylePoints: stylePoints,\n    styleText: styleText,\n    styleOnSelect: styleOnSelect\n};\n\n},{\"../../components/drawing\":614,\"../../registry\":847,\"d3\":163}],1135:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = {\n    hasLines: function(trace) {\n        return trace.visible && trace.mode &&\n            trace.mode.indexOf('lines') !== -1;\n    },\n\n    hasMarkers: function(trace) {\n        return trace.visible && (\n            (trace.mode && trace.mode.indexOf('markers') !== -1) ||\n            // until splom implements 'mode'\n            trace.type === 'splom'\n        );\n    },\n\n    hasText: function(trace) {\n        return trace.visible && trace.mode &&\n            trace.mode.indexOf('text') !== -1;\n    },\n\n    isBubble: function(trace) {\n        return Lib.isPlainObject(trace.marker) &&\n            Lib.isArrayOrTypedArray(trace.marker.size);\n    }\n};\n\n},{\"../../lib\":719}],1136:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n/*\n * opts: object of flags to control features not all text users support\n *   noSelect: caller does not support selected/unselected attribute containers\n */\nmodule.exports = function(traceIn, traceOut, layout, coerce, opts) {\n    opts = opts || {};\n\n    coerce('textposition');\n    Lib.coerceFont(coerce, 'textfont', layout.font);\n\n    if(!opts.noSelect) {\n        coerce('selected.textfont.color');\n        coerce('unselected.textfont.color');\n    }\n};\n\n},{\"../../lib\":719}],1137:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\n\nmodule.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {\n    var x = coerce('x');\n    var y = coerce('y');\n    var len;\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);\n\n    if(x) {\n        var xlen = Lib.minRowLength(x);\n        if(y) {\n            len = Math.min(xlen, Lib.minRowLength(y));\n        } else {\n            len = xlen;\n            coerce('y0');\n            coerce('dy');\n        }\n    } else {\n        if(!y) return 0;\n\n        len = Lib.minRowLength(y);\n        coerce('x0');\n        coerce('dx');\n    }\n\n    traceOut._length = len;\n\n    return len;\n};\n\n},{\"../../lib\":719,\"../../registry\":847}],1138:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar colorAttributes = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar baseAttrs = _dereq_('../../plots/attributes');\nvar DASHES = _dereq_('../../constants/gl3d_dashes');\n\nvar MARKER_SYMBOLS = _dereq_('../../constants/gl3d_markers');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar scatterLineAttrs = scatterAttrs.line;\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar scatterMarkerLineAttrs = scatterMarkerAttrs.line;\n\nvar lineAttrs = extendFlat({\n    width: scatterLineAttrs.width,\n    dash: {\n        valType: 'enumerated',\n        values: Object.keys(DASHES),\n        dflt: 'solid',\n        \n        \n    }\n}, colorAttributes('line'));\n\nfunction makeProjectionAttr(axLetter) {\n    return {\n        show: {\n            valType: 'boolean',\n            \n            dflt: false,\n            \n        },\n        opacity: {\n            valType: 'number',\n            \n            min: 0,\n            max: 1,\n            dflt: 1,\n            \n        },\n        scale: {\n            valType: 'number',\n            \n            min: 0,\n            max: 10,\n            dflt: 2 / 3,\n            \n        }\n    };\n}\n\nvar attrs = module.exports = overrideAll({\n    x: scatterAttrs.x,\n    y: scatterAttrs.y,\n    z: {\n        valType: 'data_array',\n        \n    },\n\n    text: extendFlat({}, scatterAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, scatterAttrs.hovertext, {\n        \n    }),\n    hovertemplate: hovertemplateAttrs(),\n\n    mode: extendFlat({}, scatterAttrs.mode,  // shouldn't this be on-par with 2D?\n        {dflt: 'lines+markers'}),\n    surfaceaxis: {\n        valType: 'enumerated',\n        \n        values: [-1, 0, 1, 2],\n        dflt: -1,\n        \n    },\n    surfacecolor: {\n        valType: 'color',\n        \n        \n    },\n    projection: {\n        x: makeProjectionAttr('x'),\n        y: makeProjectionAttr('y'),\n        z: makeProjectionAttr('z')\n    },\n\n    connectgaps: scatterAttrs.connectgaps,\n    line: lineAttrs,\n\n    marker: extendFlat({  // Parity with scatter.js?\n        symbol: {\n            valType: 'enumerated',\n            values: Object.keys(MARKER_SYMBOLS),\n            \n            dflt: 'circle',\n            arrayOk: true,\n            \n        },\n        size: extendFlat({}, scatterMarkerAttrs.size, {dflt: 8}),\n        sizeref: scatterMarkerAttrs.sizeref,\n        sizemin: scatterMarkerAttrs.sizemin,\n        sizemode: scatterMarkerAttrs.sizemode,\n        opacity: extendFlat({}, scatterMarkerAttrs.opacity, {\n            arrayOk: false,\n            \n        }),\n        colorbar: scatterMarkerAttrs.colorbar,\n\n        line: extendFlat({\n            width: extendFlat({}, scatterMarkerLineAttrs.width, {arrayOk: false})\n        },\n            colorAttributes('marker.line')\n        )\n    },\n        colorAttributes('marker')\n    ),\n\n    textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center'}),\n    textfont: {\n        color: scatterAttrs.textfont.color,\n        size: scatterAttrs.textfont.size,\n        family: extendFlat({}, scatterAttrs.textfont.family, {arrayOk: false})\n    },\n\n    hoverinfo: extendFlat({}, baseAttrs.hoverinfo)\n}, 'calc', 'nested');\n\nattrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes';\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../constants/gl3d_dashes\":692,\"../../constants/gl3d_markers\":693,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/attributes\":764,\"../scatter/attributes\":1112}],1139:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar arraysToCalcdata = _dereq_('../scatter/arrays_to_calcdata');\nvar calcColorscale = _dereq_('../scatter/colorscale_calc');\n\n/**\n * This is a kludge to put the array attributes into\n * calcdata the way Scatter.plot does, so that legends and\n * popovers know what to do with them.\n */\nmodule.exports = function calc(gd, trace) {\n    var cd = [{x: false, y: false, trace: trace, t: {}}];\n\n    arraysToCalcdata(cd, trace);\n    calcColorscale(gd, trace);\n\n    return cd;\n};\n\n},{\"../scatter/arrays_to_calcdata\":1111,\"../scatter/colorscale_calc\":1115}],1140:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\n\nfunction calculateAxisErrors(data, params, scaleFactor, axis) {\n    if(!params || !params.visible) return null;\n\n    var computeError = Registry.getComponentMethod('errorbars', 'makeComputeError')(params);\n    var result = new Array(data.length);\n\n    for(var i = 0; i < data.length; i++) {\n        var errors = computeError(+data[i], i);\n\n        if(axis.type === 'log') {\n            var point = axis.c2l(data[i]);\n            var min = data[i] - errors[0];\n            var max = data[i] + errors[1];\n\n            result[i] = [\n                (axis.c2l(min, true) - point) * scaleFactor,\n                (axis.c2l(max, true) - point) * scaleFactor\n            ];\n\n            // Keep track of the lower error bound which isn't negative!\n            if(min > 0) {\n                var lower = axis.c2l(min);\n                if(!axis._lowerLogErrorBound) axis._lowerLogErrorBound = lower;\n                axis._lowerErrorBound = Math.min(axis._lowerLogErrorBound, lower);\n            }\n        } else {\n            result[i] = [\n                -errors[0] * scaleFactor,\n                errors[1] * scaleFactor\n            ];\n        }\n    }\n\n    return result;\n}\n\nfunction dataLength(array) {\n    for(var i = 0; i < array.length; i++) {\n        if(array[i]) return array[i].length;\n    }\n    return 0;\n}\n\nfunction calculateErrors(data, scaleFactor, sceneLayout) {\n    var errors = [\n        calculateAxisErrors(data.x, data.error_x, scaleFactor[0], sceneLayout.xaxis),\n        calculateAxisErrors(data.y, data.error_y, scaleFactor[1], sceneLayout.yaxis),\n        calculateAxisErrors(data.z, data.error_z, scaleFactor[2], sceneLayout.zaxis)\n    ];\n\n    var n = dataLength(errors);\n    if(n === 0) return null;\n\n    var errorBounds = new Array(n);\n\n    for(var i = 0; i < n; i++) {\n        var bound = [[0, 0, 0], [0, 0, 0]];\n\n        for(var j = 0; j < 3; j++) {\n            if(errors[j]) {\n                for(var k = 0; k < 2; k++) {\n                    bound[k][j] = errors[j][i][k];\n                }\n            }\n        }\n\n        errorBounds[i] = bound;\n    }\n\n    return errorBounds;\n}\n\nmodule.exports = calculateErrors;\n\n},{\"../../registry\":847}],1141:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar createLinePlot = _dereq_('gl-line3d');\nvar createScatterPlot = _dereq_('gl-scatter3d');\nvar createErrorBars = _dereq_('gl-error3d');\nvar createMesh = _dereq_('gl-mesh3d');\nvar triangulate = _dereq_('delaunay-triangulate');\n\nvar Lib = _dereq_('../../lib');\nvar str2RgbaArray = _dereq_('../../lib/str2rgbarray');\nvar formatColor = _dereq_('../../lib/gl_format_color').formatColor;\nvar makeBubbleSizeFn = _dereq_('../scatter/make_bubble_size_func');\nvar DASH_PATTERNS = _dereq_('../../constants/gl3d_dashes');\nvar MARKER_SYMBOLS = _dereq_('../../constants/gl3d_markers');\n\nvar calculateError = _dereq_('./calc_errors');\n\nfunction LineWithMarkers(scene, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.linePlot = null;\n    this.scatterPlot = null;\n    this.errorBars = null;\n    this.textMarkers = null;\n    this.delaunayMesh = null;\n    this.color = null;\n    this.mode = '';\n    this.dataPoints = [];\n    this.axesBounds = [\n        [-Infinity, -Infinity, -Infinity],\n        [Infinity, Infinity, Infinity]\n    ];\n    this.textLabels = null;\n    this.data = null;\n}\n\nvar proto = LineWithMarkers.prototype;\n\nproto.handlePick = function(selection) {\n    if(selection.object &&\n        (selection.object === this.linePlot ||\n         selection.object === this.delaunayMesh ||\n         selection.object === this.textMarkers ||\n         selection.object === this.scatterPlot)\n    ) {\n        var ind = selection.index = selection.data.index;\n\n        if(selection.object.highlight) {\n            selection.object.highlight(null);\n        }\n        if(this.scatterPlot) {\n            selection.object = this.scatterPlot;\n            this.scatterPlot.highlight(selection.data);\n        }\n\n        selection.textLabel = '';\n        if(this.textLabels) {\n            if(Array.isArray(this.textLabels)) {\n                if(this.textLabels[ind] || this.textLabels[ind] === 0) {\n                    selection.textLabel = this.textLabels[ind];\n                }\n            } else {\n                selection.textLabel = this.textLabels;\n            }\n        }\n\n        selection.traceCoordinate = [\n            this.data.x[ind],\n            this.data.y[ind],\n            this.data.z[ind]\n        ];\n\n        return true;\n    }\n};\n\nfunction constructDelaunay(points, color, axis) {\n    var u = (axis + 1) % 3;\n    var v = (axis + 2) % 3;\n    var filteredPoints = [];\n    var filteredIds = [];\n    var i;\n\n    for(i = 0; i < points.length; ++i) {\n        var p = points[i];\n        if(isNaN(p[u]) || !isFinite(p[u]) ||\n           isNaN(p[v]) || !isFinite(p[v])) {\n            continue;\n        }\n        filteredPoints.push([p[u], p[v]]);\n        filteredIds.push(i);\n    }\n    var cells = triangulate(filteredPoints);\n    for(i = 0; i < cells.length; ++i) {\n        var c = cells[i];\n        for(var j = 0; j < c.length; ++j) {\n            c[j] = filteredIds[c[j]];\n        }\n    }\n    return {\n        positions: points,\n        cells: cells,\n        meshColor: color\n    };\n}\n\nfunction calculateErrorParams(errors) {\n    var capSize = [0.0, 0.0, 0.0];\n    var color = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];\n    var lineWidth = [1.0, 1.0, 1.0];\n\n    for(var i = 0; i < 3; i++) {\n        var e = errors[i];\n\n        if(e && e.copy_zstyle !== false && errors[2].visible !== false) e = errors[2];\n        if(!e || !e.visible) continue;\n\n        capSize[i] = e.width / 2;  // ballpark rescaling\n        color[i] = str2RgbaArray(e.color);\n        lineWidth[i] = e.thickness;\n    }\n\n    return {capSize: capSize, color: color, lineWidth: lineWidth};\n}\n\nfunction parseAlignmentX(a) {\n    if(a === null || a === undefined) return 0;\n\n    return (a.indexOf('left') > -1) ? -1 :\n           (a.indexOf('right') > -1) ? 1 : 0;\n}\n\nfunction parseAlignmentY(a) {\n    if(a === null || a === undefined) return 0;\n\n    return (a.indexOf('top') > -1) ? -1 :\n           (a.indexOf('bottom') > -1) ? 1 : 0;\n}\n\nfunction calculateTextOffset(tp) {\n    // Read out text properties\n\n    var defaultAlignmentX = 0;\n    var defaultAlignmentY = 0;\n\n    var textOffset = [\n        defaultAlignmentX,\n        defaultAlignmentY\n    ];\n\n    if(Array.isArray(tp)) {\n        for(var i = 0; i < tp.length; i++) {\n            textOffset[i] = [\n                defaultAlignmentX,\n                defaultAlignmentY\n            ];\n            if(tp[i]) {\n                textOffset[i][0] = parseAlignmentX(tp[i]);\n                textOffset[i][1] = parseAlignmentY(tp[i]);\n            }\n        }\n    } else {\n        textOffset[0] = parseAlignmentX(tp);\n        textOffset[1] = parseAlignmentY(tp);\n    }\n\n    return textOffset;\n}\n\n\nfunction calculateSize(sizeIn, sizeFn) {\n    // rough parity with Plotly 2D markers\n    return sizeFn(sizeIn * 4);\n}\n\nfunction calculateSymbol(symbolIn) {\n    return MARKER_SYMBOLS[symbolIn];\n}\n\nfunction formatParam(paramIn, len, calculate, dflt, extraFn) {\n    var paramOut = null;\n\n    if(Lib.isArrayOrTypedArray(paramIn)) {\n        paramOut = [];\n\n        for(var i = 0; i < len; i++) {\n            if(paramIn[i] === undefined) paramOut[i] = dflt;\n            else paramOut[i] = calculate(paramIn[i], extraFn);\n        }\n    } else paramOut = calculate(paramIn, Lib.identity);\n\n    return paramOut;\n}\n\n\nfunction convertPlotlyOptions(scene, data) {\n    var points = [];\n    var sceneLayout = scene.fullSceneLayout;\n    var scaleFactor = scene.dataScale;\n    var xaxis = sceneLayout.xaxis;\n    var yaxis = sceneLayout.yaxis;\n    var zaxis = sceneLayout.zaxis;\n    var marker = data.marker;\n    var line = data.line;\n    var x = data.x || [];\n    var y = data.y || [];\n    var z = data.z || [];\n    var len = x.length;\n    var xcalendar = data.xcalendar;\n    var ycalendar = data.ycalendar;\n    var zcalendar = data.zcalendar;\n    var xc, yc, zc;\n    var params, i;\n    var text;\n\n    // Convert points\n    for(i = 0; i < len; i++) {\n        // sanitize numbers and apply transforms based on axes.type\n        xc = xaxis.d2l(x[i], 0, xcalendar) * scaleFactor[0];\n        yc = yaxis.d2l(y[i], 0, ycalendar) * scaleFactor[1];\n        zc = zaxis.d2l(z[i], 0, zcalendar) * scaleFactor[2];\n\n        points[i] = [xc, yc, zc];\n    }\n\n    // convert text\n    if(Array.isArray(data.text)) text = data.text;\n    else if(data.text !== undefined) {\n        text = new Array(len);\n        for(i = 0; i < len; i++) text[i] = data.text;\n    }\n\n    // Build object parameters\n    params = {\n        position: points,\n        mode: data.mode,\n        text: text\n    };\n\n    if('line' in data) {\n        params.lineColor = formatColor(line, 1, len);\n        params.lineWidth = line.width;\n        params.lineDashes = line.dash;\n    }\n\n    if('marker' in data) {\n        var sizeFn = makeBubbleSizeFn(data);\n\n        params.scatterColor = formatColor(marker, 1, len);\n        params.scatterSize = formatParam(marker.size, len, calculateSize, 20, sizeFn);\n        params.scatterMarker = formatParam(marker.symbol, len, calculateSymbol, '●');\n        params.scatterLineWidth = marker.line.width;  // arrayOk === false\n        params.scatterLineColor = formatColor(marker.line, 1, len);\n        params.scatterAngle = 0;\n    }\n\n    if('textposition' in data) {\n        params.textOffset = calculateTextOffset(data.textposition);\n        params.textColor = formatColor(data.textfont, 1, len);\n        params.textSize = formatParam(data.textfont.size, len, Lib.identity, 12);\n        params.textFont = data.textfont.family;  // arrayOk === false\n        params.textAngle = 0;\n    }\n\n    var dims = ['x', 'y', 'z'];\n    params.project = [false, false, false];\n    params.projectScale = [1, 1, 1];\n    params.projectOpacity = [1, 1, 1];\n    for(i = 0; i < 3; ++i) {\n        var projection = data.projection[dims[i]];\n        if((params.project[i] = projection.show)) {\n            params.projectOpacity[i] = projection.opacity;\n            params.projectScale[i] = projection.scale;\n        }\n    }\n\n    params.errorBounds = calculateError(data, scaleFactor, sceneLayout);\n\n    var errorParams = calculateErrorParams([data.error_x, data.error_y, data.error_z]);\n    params.errorColor = errorParams.color;\n    params.errorLineWidth = errorParams.lineWidth;\n    params.errorCapSize = errorParams.capSize;\n\n    params.delaunayAxis = data.surfaceaxis;\n    params.delaunayColor = str2RgbaArray(data.surfacecolor);\n\n    return params;\n}\n\nfunction arrayToColor(color) {\n    if(Array.isArray(color)) {\n        var c = color[0];\n\n        if(Array.isArray(c)) color = c;\n\n        return 'rgb(' + color.slice(0, 3).map(function(x) {\n            return Math.round(x * 255);\n        }) + ')';\n    }\n\n    return null;\n}\n\nproto.update = function(data) {\n    var gl = this.scene.glplot.gl;\n    var lineOptions;\n    var scatterOptions;\n    var errorOptions;\n    var textOptions;\n    var dashPattern = DASH_PATTERNS.solid;\n\n    // Save data\n    this.data = data;\n\n    // Run data conversion\n    var options = convertPlotlyOptions(this.scene, data);\n\n    if('mode' in options) {\n        this.mode = options.mode;\n    }\n    if('lineDashes' in options) {\n        if(options.lineDashes in DASH_PATTERNS) {\n            dashPattern = DASH_PATTERNS[options.lineDashes];\n        }\n    }\n\n    this.color = arrayToColor(options.scatterColor) ||\n                 arrayToColor(options.lineColor);\n\n    // Save data points\n    this.dataPoints = options.position;\n\n    lineOptions = {\n        gl: this.scene.glplot.gl,\n        position: options.position,\n        color: options.lineColor,\n        lineWidth: options.lineWidth || 1,\n        dashes: dashPattern[0],\n        dashScale: dashPattern[1],\n        opacity: data.opacity,\n        connectGaps: data.connectgaps\n    };\n\n    if(this.mode.indexOf('lines') !== -1) {\n        if(this.linePlot) this.linePlot.update(lineOptions);\n        else {\n            this.linePlot = createLinePlot(lineOptions);\n            this.linePlot._trace = this;\n            this.scene.glplot.add(this.linePlot);\n        }\n    } else if(this.linePlot) {\n        this.scene.glplot.remove(this.linePlot);\n        this.linePlot.dispose();\n        this.linePlot = null;\n    }\n\n    // N.B. marker.opacity must be a scalar for performance\n    var scatterOpacity = data.opacity;\n    if(data.marker && data.marker.opacity) scatterOpacity *= data.marker.opacity;\n\n    scatterOptions = {\n        gl: this.scene.glplot.gl,\n        position: options.position,\n        color: options.scatterColor,\n        size: options.scatterSize,\n        glyph: options.scatterMarker,\n        opacity: scatterOpacity,\n        orthographic: true,\n        lineWidth: options.scatterLineWidth,\n        lineColor: options.scatterLineColor,\n        project: options.project,\n        projectScale: options.projectScale,\n        projectOpacity: options.projectOpacity\n    };\n\n    if(this.mode.indexOf('markers') !== -1) {\n        if(this.scatterPlot) this.scatterPlot.update(scatterOptions);\n        else {\n            this.scatterPlot = createScatterPlot(scatterOptions);\n            this.scatterPlot._trace = this;\n            this.scatterPlot.highlightScale = 1;\n            this.scene.glplot.add(this.scatterPlot);\n        }\n    } else if(this.scatterPlot) {\n        this.scene.glplot.remove(this.scatterPlot);\n        this.scatterPlot.dispose();\n        this.scatterPlot = null;\n    }\n\n    textOptions = {\n        gl: this.scene.glplot.gl,\n        position: options.position,\n        glyph: options.text,\n        color: options.textColor,\n        size: options.textSize,\n        angle: options.textAngle,\n        alignment: options.textOffset,\n        font: options.textFont,\n        orthographic: true,\n        lineWidth: 0,\n        project: false,\n        opacity: data.opacity\n    };\n\n    this.textLabels = data.hovertext || data.text;\n\n    if(this.mode.indexOf('text') !== -1) {\n        if(this.textMarkers) this.textMarkers.update(textOptions);\n        else {\n            this.textMarkers = createScatterPlot(textOptions);\n            this.textMarkers._trace = this;\n            this.textMarkers.highlightScale = 1;\n            this.scene.glplot.add(this.textMarkers);\n        }\n    } else if(this.textMarkers) {\n        this.scene.glplot.remove(this.textMarkers);\n        this.textMarkers.dispose();\n        this.textMarkers = null;\n    }\n\n    errorOptions = {\n        gl: this.scene.glplot.gl,\n        position: options.position,\n        color: options.errorColor,\n        error: options.errorBounds,\n        lineWidth: options.errorLineWidth,\n        capSize: options.errorCapSize,\n        opacity: data.opacity\n    };\n    if(this.errorBars) {\n        if(options.errorBounds) {\n            this.errorBars.update(errorOptions);\n        } else {\n            this.scene.glplot.remove(this.errorBars);\n            this.errorBars.dispose();\n            this.errorBars = null;\n        }\n    } else if(options.errorBounds) {\n        this.errorBars = createErrorBars(errorOptions);\n        this.errorBars._trace = this;\n        this.scene.glplot.add(this.errorBars);\n    }\n\n    if(options.delaunayAxis >= 0) {\n        var delaunayOptions = constructDelaunay(\n            options.position,\n            options.delaunayColor,\n            options.delaunayAxis\n        );\n        delaunayOptions.opacity = data.opacity;\n\n        if(this.delaunayMesh) {\n            this.delaunayMesh.update(delaunayOptions);\n        } else {\n            delaunayOptions.gl = gl;\n            this.delaunayMesh = createMesh(delaunayOptions);\n            this.delaunayMesh._trace = this;\n            this.scene.glplot.add(this.delaunayMesh);\n        }\n    } else if(this.delaunayMesh) {\n        this.scene.glplot.remove(this.delaunayMesh);\n        this.delaunayMesh.dispose();\n        this.delaunayMesh = null;\n    }\n};\n\nproto.dispose = function() {\n    if(this.linePlot) {\n        this.scene.glplot.remove(this.linePlot);\n        this.linePlot.dispose();\n    }\n    if(this.scatterPlot) {\n        this.scene.glplot.remove(this.scatterPlot);\n        this.scatterPlot.dispose();\n    }\n    if(this.errorBars) {\n        this.scene.glplot.remove(this.errorBars);\n        this.errorBars.dispose();\n    }\n    if(this.textMarkers) {\n        this.scene.glplot.remove(this.textMarkers);\n        this.textMarkers.dispose();\n    }\n    if(this.delaunayMesh) {\n        this.scene.glplot.remove(this.delaunayMesh);\n        this.delaunayMesh.dispose();\n    }\n};\n\nfunction createLineWithMarkers(scene, data) {\n    var plot = new LineWithMarkers(scene, data.uid);\n    plot.update(data);\n    return plot;\n}\n\nmodule.exports = createLineWithMarkers;\n\n},{\"../../constants/gl3d_dashes\":692,\"../../constants/gl3d_markers\":693,\"../../lib\":719,\"../../lib/gl_format_color\":716,\"../../lib/str2rgbarray\":742,\"../scatter/make_bubble_size_func\":1128,\"./calc_errors\":1140,\"delaunay-triangulate\":165,\"gl-error3d\":247,\"gl-line3d\":255,\"gl-mesh3d\":280,\"gl-scatter3d\":297}],1142:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\n\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar handleLineDefaults = _dereq_('../scatter/line_defaults');\nvar handleTextDefaults = _dereq_('../scatter/text_defaults');\n\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleXYZDefaults(traceIn, traceOut, coerce, layout);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n    coerce('mode');\n\n    if(subTypes.hasLines(traceOut)) {\n        coerce('connectgaps');\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noSelect: true});\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce, {noSelect: true});\n    }\n\n    var lineColor = (traceOut.line || {}).color;\n    var markerColor = (traceOut.marker || {}).color;\n    if(coerce('surfaceaxis') >= 0) coerce('surfacecolor', lineColor || markerColor);\n\n    var dims = ['x', 'y', 'z'];\n    for(var i = 0; i < 3; ++i) {\n        var projection = 'projection.' + dims[i];\n        if(coerce(projection + '.show')) {\n            coerce(projection + '.opacity');\n            coerce(projection + '.scale');\n        }\n    }\n\n    var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'z'});\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'y', inherit: 'z'});\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'x', inherit: 'z'});\n};\n\nfunction handleXYZDefaults(traceIn, traceOut, coerce, layout) {\n    var len = 0;\n    var x = coerce('x');\n    var y = coerce('y');\n    var z = coerce('z');\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);\n\n    if(x && y && z) {\n        // TODO: what happens if one is missing?\n        len = Math.min(x.length, y.length, z.length);\n        traceOut._length = traceOut._xlength = traceOut._ylength = traceOut._zlength = len;\n    }\n\n    return len;\n}\n\n},{\"../../lib\":719,\"../../registry\":847,\"../scatter/line_defaults\":1124,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"../scatter/text_defaults\":1136,\"./attributes\":1138}],1143:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    plot: _dereq_('./convert'),\n    attributes: _dereq_('./attributes'),\n    markerSymbols: _dereq_('../../constants/gl3d_markers'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: [\n        {\n            container: 'marker',\n            min: 'cmin',\n            max: 'cmax'\n        }, {\n            container: 'line',\n            min: 'cmin',\n            max: 'cmax'\n        }\n    ],\n    calc: _dereq_('./calc'),\n\n    moduleType: 'trace',\n    name: 'scatter3d',\n    basePlotModule: _dereq_('../../plots/gl3d'),\n    categories: ['gl3d', 'symbols', 'showLegend'],\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../constants/gl3d_markers\":693,\"../../plots/gl3d\":807,\"./attributes\":1138,\"./calc\":1139,\"./convert\":1141,\"./defaults\":1142}],1144:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar scatterLineAttrs = scatterAttrs.line;\nvar scatterMarkerLineAttrs = scatterMarkerAttrs.line;\n\nmodule.exports = {\n    carpet: {\n        valType: 'string',\n        \n        editType: 'calc',\n        \n    },\n    a: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    b: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    mode: extendFlat({}, scatterAttrs.mode, {dflt: 'markers'}),\n    text: extendFlat({}, scatterAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, scatterAttrs.hovertext, {\n        \n    }),\n    line: {\n        color: scatterLineAttrs.color,\n        width: scatterLineAttrs.width,\n        dash: scatterLineAttrs.dash,\n        shape: extendFlat({}, scatterLineAttrs.shape,\n            {values: ['linear', 'spline']}),\n        smoothing: scatterLineAttrs.smoothing,\n        editType: 'calc'\n    },\n    connectgaps: scatterAttrs.connectgaps,\n    fill: extendFlat({}, scatterAttrs.fill, {\n        values: ['none', 'toself', 'tonext'],\n        dflt: 'none',\n        \n    }),\n    fillcolor: scatterAttrs.fillcolor,\n    marker: extendFlat({\n        symbol: scatterMarkerAttrs.symbol,\n        opacity: scatterMarkerAttrs.opacity,\n        maxdisplayed: scatterMarkerAttrs.maxdisplayed,\n        size: scatterMarkerAttrs.size,\n        sizeref: scatterMarkerAttrs.sizeref,\n        sizemin: scatterMarkerAttrs.sizemin,\n        sizemode: scatterMarkerAttrs.sizemode,\n        line: extendFlat({\n            width: scatterMarkerLineAttrs.width,\n            editType: 'calc'\n        },\n            colorScaleAttrs('marker.line')\n        ),\n        gradient: scatterMarkerAttrs.gradient,\n        editType: 'calc'\n    },\n        colorScaleAttrs('marker')\n    ),\n\n    textfont: scatterAttrs.textfont,\n    textposition: scatterAttrs.textposition,\n\n    selected: scatterAttrs.selected,\n    unselected: scatterAttrs.unselected,\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['a', 'b', 'text', 'name']\n    }),\n    hoveron: scatterAttrs.hoveron,\n    hovertemplate: hovertemplateAttrs()\n};\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../scatter/attributes\":1112}],1145:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar calcColorscale = _dereq_('../scatter/colorscale_calc');\nvar arraysToCalcdata = _dereq_('../scatter/arrays_to_calcdata');\nvar calcSelection = _dereq_('../scatter/calc_selection');\nvar calcMarkerSize = _dereq_('../scatter/calc').calcMarkerSize;\nvar lookupCarpet = _dereq_('../carpet/lookup_carpetid');\n\nmodule.exports = function calc(gd, trace) {\n    var carpet = trace._carpetTrace = lookupCarpet(gd, trace);\n    if(!carpet || !carpet.visible || carpet.visible === 'legendonly') return;\n    var i;\n\n    // Transfer this over from carpet before plotting since this is a necessary\n    // condition in order for cartesian to actually plot this trace:\n    trace.xaxis = carpet.xaxis;\n    trace.yaxis = carpet.yaxis;\n\n    // make the calcdata array\n    var serieslen = trace._length;\n    var cd = new Array(serieslen);\n    var a, b;\n    var needsCull = false;\n    for(i = 0; i < serieslen; i++) {\n        a = trace.a[i];\n        b = trace.b[i];\n        if(isNumeric(a) && isNumeric(b)) {\n            var xy = carpet.ab2xy(+a, +b, true);\n            var visible = carpet.isVisible(+a, +b);\n            if(!visible) needsCull = true;\n            cd[i] = {x: xy[0], y: xy[1], a: a, b: b, vis: visible};\n        } else cd[i] = {x: false, y: false};\n    }\n\n    trace._needsCull = needsCull;\n\n    cd[0].carpet = carpet;\n    cd[0].trace = trace;\n\n    calcMarkerSize(trace, serieslen);\n    calcColorscale(gd, trace);\n    arraysToCalcdata(cd, trace);\n    calcSelection(cd, trace);\n\n    return cd;\n};\n\n},{\"../carpet/lookup_carpetid\":915,\"../scatter/arrays_to_calcdata\":1111,\"../scatter/calc\":1113,\"../scatter/calc_selection\":1114,\"../scatter/colorscale_calc\":1115,\"fast-isnumeric\":225}],1146:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar constants = _dereq_('../scatter/constants');\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar handleLineDefaults = _dereq_('../scatter/line_defaults');\nvar handleLineShapeDefaults = _dereq_('../scatter/line_shape_defaults');\nvar handleTextDefaults = _dereq_('../scatter/text_defaults');\nvar handleFillColorDefaults = _dereq_('../scatter/fillcolor_defaults');\n\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    coerce('carpet');\n\n    // XXX: Don't hard code this\n    traceOut.xaxis = 'x';\n    traceOut.yaxis = 'y';\n\n    var a = coerce('a');\n    var b = coerce('b');\n    var len = Math.min(a.length, b.length);\n\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    traceOut._length = len;\n\n    coerce('text');\n    coerce('hovertext');\n\n    var defaultMode = len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines';\n    coerce('mode', defaultMode);\n\n    if(subTypes.hasLines(traceOut)) {\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n        handleLineShapeDefaults(traceIn, traceOut, coerce);\n        coerce('connectgaps');\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {gradient: true});\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce);\n    }\n\n    var dfltHoverOn = [];\n\n    if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {\n        coerce('marker.maxdisplayed');\n        dfltHoverOn.push('points');\n    }\n\n    coerce('fill');\n    if(traceOut.fill !== 'none') {\n        handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);\n        if(!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce);\n    }\n\n    if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {\n        dfltHoverOn.push('fills');\n    }\n\n    var hoverOn = coerce('hoveron', dfltHoverOn.join('+') || 'points');\n    if(hoverOn !== 'fills') coerce('hovertemplate');\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\n},{\"../../lib\":719,\"../scatter/constants\":1116,\"../scatter/fillcolor_defaults\":1120,\"../scatter/line_defaults\":1124,\"../scatter/line_shape_defaults\":1126,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"../scatter/text_defaults\":1136,\"./attributes\":1144}],1147:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function eventData(out, pt, trace, cd, pointNumber) {\n    var cdi = cd[pointNumber];\n\n    out.a = cdi.a;\n    out.b = cdi.b;\n    out.y = cdi.y;\n\n    return out;\n};\n\n},{}],1148:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterHover = _dereq_('../scatter/hover');\nvar fillText = _dereq_('../../lib').fillText;\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode) {\n    var scatterPointData = scatterHover(pointData, xval, yval, hovermode);\n    if(!scatterPointData || scatterPointData[0].index === false) return;\n\n    var newPointData = scatterPointData[0];\n\n    // if hovering on a fill, we don't show any point data so the label is\n    // unchanged from what scatter gives us - except that it needs to\n    // be constrained to the trianglular plot area, not just the rectangular\n    // area defined by the synthetic x and y axes\n    // TODO: in some cases the vertical middle of the shape is not within\n    // the triangular viewport at all, so the label can become disconnected\n    // from the shape entirely. But calculating what portion of the shape\n    // is actually visible, as constrained by the diagonal axis lines, is not\n    // so easy and anyway we lost the information we would have needed to do\n    // this inside scatterHover.\n    if(newPointData.index === undefined) {\n        var yFracUp = 1 - (newPointData.y0 / pointData.ya._length);\n        var xLen = pointData.xa._length;\n        var xMin = xLen * yFracUp / 2;\n        var xMax = xLen - xMin;\n        newPointData.x0 = Math.max(Math.min(newPointData.x0, xMax), xMin);\n        newPointData.x1 = Math.max(Math.min(newPointData.x1, xMax), xMin);\n        return scatterPointData;\n    }\n\n    var cdi = newPointData.cd[newPointData.index];\n\n    newPointData.a = cdi.a;\n    newPointData.b = cdi.b;\n\n    newPointData.xLabelVal = undefined;\n    newPointData.yLabelVal = undefined;\n    // TODO: nice formatting, and label by axis title, for a, b, and c?\n\n    var trace = newPointData.trace;\n    var carpet = trace._carpet;\n\n    var ij = carpet.ab2ij([cdi.a, cdi.b]);\n    var i0 = Math.floor(ij[0]);\n    var ti = ij[0] - i0;\n    var j0 = Math.floor(ij[1]);\n    var tj = ij[1] - j0;\n    var xy = carpet.evalxy([], i0, j0, ti, tj);\n    newPointData.yLabel = xy[1].toFixed(3);\n\n    delete newPointData.text;\n    var text = [];\n\n    function textPart(ax, val) {\n        var prefix;\n\n        if(ax.labelprefix && ax.labelprefix.length > 0) {\n            prefix = ax.labelprefix.replace(/ = $/, '');\n        } else {\n            prefix = ax._hovertitle;\n        }\n\n        text.push(prefix + ': ' + val.toFixed(3) + ax.labelsuffix);\n    }\n\n\n    if(!trace.hovertemplate) {\n        var hoverinfo = cdi.hi || trace.hoverinfo;\n        var parts = hoverinfo.split('+');\n\n        if(parts.indexOf('all') !== -1) parts = ['a', 'b', 'text'];\n        if(parts.indexOf('a') !== -1) textPart(carpet.aaxis, cdi.a);\n        if(parts.indexOf('b') !== -1) textPart(carpet.baxis, cdi.b);\n\n        text.push('y: ' + newPointData.yLabel);\n\n        if(parts.indexOf('text') !== -1) {\n            fillText(cdi, trace, text);\n        }\n\n        newPointData.extraText = text.join('<br>');\n    }\n\n    return scatterPointData;\n};\n\n},{\"../../lib\":719,\"../scatter/hover\":1122}],1149:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    style: _dereq_('../scatter/style').style,\n    styleOnSelect: _dereq_('../scatter/style').styleOnSelect,\n    hoverPoints: _dereq_('./hover'),\n    selectPoints: _dereq_('../scatter/select'),\n    eventData: _dereq_('./event_data'),\n\n    moduleType: 'trace',\n    name: 'scattercarpet',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['svg', 'carpet', 'symbols', 'showLegend', 'carpetDependent', 'zoomScale'],\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../scatter/marker_colorbar\":1129,\"../scatter/select\":1132,\"../scatter/style\":1134,\"./attributes\":1144,\"./calc\":1145,\"./defaults\":1146,\"./event_data\":1147,\"./hover\":1148,\"./plot\":1150}],1150:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar scatterPlot = _dereq_('../scatter/plot');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Drawing = _dereq_('../../components/drawing');\n\nmodule.exports = function plot(gd, plotinfoproxy, data, layer) {\n    var i, trace, node;\n\n    var carpet = data[0][0].carpet;\n    // mimic cartesian plotinfo\n    var plotinfo = {\n        xaxis: Axes.getFromId(gd, carpet.xaxis || 'x'),\n        yaxis: Axes.getFromId(gd, carpet.yaxis || 'y'),\n        plot: plotinfoproxy.plot,\n    };\n\n    scatterPlot(gd, plotinfo, data, layer);\n\n    for(i = 0; i < data.length; i++) {\n        trace = data[i][0].trace;\n\n        // Note: .select is adequate but seems to mutate the node data,\n        // which is at least a bit suprising and causes problems elsewhere\n        node = layer.selectAll('g.trace' + trace.uid + ' .js-line');\n\n        // Note: it would be more efficient if this didn't need to be applied\n        // separately to all scattercarpet traces, but that would require\n        // lots of reorganization of scatter traces that is otherwise not\n        // necessary. That makes this a potential optimization.\n        Drawing.setClipUrl(node, data[i][0].carpet._clipPathId, gd);\n    }\n};\n\n},{\"../../components/drawing\":614,\"../../plots/cartesian/axes\":767,\"../scatter/plot\":1131}],1151:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar colorAttributes = _dereq_('../../components/colorscale/attributes');\nvar dash = _dereq_('../../components/drawing/attributes').dash;\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar scatterLineAttrs = scatterAttrs.line;\nvar scatterMarkerLineAttrs = scatterMarkerAttrs.line;\n\nmodule.exports = overrideAll({\n    lon: {\n        valType: 'data_array',\n        \n    },\n    lat: {\n        valType: 'data_array',\n        \n    },\n\n    locations: {\n        valType: 'data_array',\n        \n    },\n    locationmode: {\n        valType: 'enumerated',\n        values: ['ISO-3', 'USA-states', 'country names'],\n        \n        dflt: 'ISO-3',\n        \n    },\n\n    mode: extendFlat({}, scatterAttrs.mode, {dflt: 'markers'}),\n\n    text: extendFlat({}, scatterAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, scatterAttrs.hovertext, {\n        \n    }),\n\n    textfont: scatterAttrs.textfont,\n    textposition: scatterAttrs.textposition,\n\n    line: {\n        color: scatterLineAttrs.color,\n        width: scatterLineAttrs.width,\n        dash: dash\n    },\n    connectgaps: scatterAttrs.connectgaps,\n\n    marker: extendFlat({\n        symbol: scatterMarkerAttrs.symbol,\n        opacity: scatterMarkerAttrs.opacity,\n        size: scatterMarkerAttrs.size,\n        sizeref: scatterMarkerAttrs.sizeref,\n        sizemin: scatterMarkerAttrs.sizemin,\n        sizemode: scatterMarkerAttrs.sizemode,\n        colorbar: scatterMarkerAttrs.colorbar,\n        line: extendFlat({\n            width: scatterMarkerLineAttrs.width\n        },\n            colorAttributes('marker.line')\n        ),\n        gradient: scatterMarkerAttrs.gradient\n    },\n        colorAttributes('marker')\n    ),\n\n    fill: {\n        valType: 'enumerated',\n        values: ['none', 'toself'],\n        dflt: 'none',\n        \n        \n    },\n    fillcolor: scatterAttrs.fillcolor,\n\n    selected: scatterAttrs.selected,\n    unselected: scatterAttrs.unselected,\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['lon', 'lat', 'location', 'text', 'name']\n    }),\n    hovertemplate: hovertemplateAttrs(),\n}, 'calc', 'nested');\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/drawing/attributes\":613,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/attributes\":764,\"../scatter/attributes\":1112}],1152:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nvar calcMarkerColorscale = _dereq_('../scatter/colorscale_calc');\nvar arraysToCalcdata = _dereq_('../scatter/arrays_to_calcdata');\nvar calcSelection = _dereq_('../scatter/calc_selection');\n\nvar _ = _dereq_('../../lib')._;\n\nmodule.exports = function calc(gd, trace) {\n    var hasLocationData = Array.isArray(trace.locations);\n    var len = hasLocationData ? trace.locations.length : trace._length;\n    var calcTrace = new Array(len);\n\n    for(var i = 0; i < len; i++) {\n        var calcPt = calcTrace[i] = {};\n\n        if(hasLocationData) {\n            var loc = trace.locations[i];\n            calcPt.loc = typeof loc === 'string' ? loc : null;\n        } else {\n            var lon = trace.lon[i];\n            var lat = trace.lat[i];\n\n            if(isNumeric(lon) && isNumeric(lat)) calcPt.lonlat = [+lon, +lat];\n            else calcPt.lonlat = [BADNUM, BADNUM];\n        }\n    }\n\n    arraysToCalcdata(calcTrace, trace);\n    calcMarkerColorscale(gd, trace);\n    calcSelection(calcTrace, trace);\n\n    if(len) {\n        calcTrace[0].t = {\n            labels: {\n                lat: _(gd, 'lat:') + ' ',\n                lon: _(gd, 'lon:') + ' '\n            }\n        };\n    }\n\n    return calcTrace;\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../scatter/arrays_to_calcdata\":1111,\"../scatter/calc_selection\":1114,\"../scatter/colorscale_calc\":1115,\"fast-isnumeric\":225}],1153:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar handleLineDefaults = _dereq_('../scatter/line_defaults');\nvar handleTextDefaults = _dereq_('../scatter/text_defaults');\nvar handleFillColorDefaults = _dereq_('../scatter/fillcolor_defaults');\n\nvar attributes = _dereq_('./attributes');\n\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleLonLatLocDefaults(traceIn, traceOut, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n    coerce('mode');\n\n    if(subTypes.hasLines(traceOut)) {\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n        coerce('connectgaps');\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {gradient: true});\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce);\n    }\n\n    coerce('fill');\n    if(traceOut.fill !== 'none') {\n        handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);\n    }\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\nfunction handleLonLatLocDefaults(traceIn, traceOut, coerce) {\n    var len = 0;\n    var locations = coerce('locations');\n\n    var lon, lat;\n\n    if(locations) {\n        coerce('locationmode');\n        len = locations.length;\n        return len;\n    }\n\n    lon = coerce('lon') || [];\n    lat = coerce('lat') || [];\n    len = Math.min(lon.length, lat.length);\n    traceOut._length = len;\n\n    return len;\n}\n\n},{\"../../lib\":719,\"../scatter/fillcolor_defaults\":1120,\"../scatter/line_defaults\":1124,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"../scatter/text_defaults\":1136,\"./attributes\":1151}],1154:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nmodule.exports = function eventData(out, pt) {\n    out.lon = pt.lon;\n    out.lat = pt.lat;\n    out.location = pt.loc ? pt.loc : null;\n\n    return out;\n};\n\n},{}],1155:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Fx = _dereq_('../../components/fx');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nvar getTraceColor = _dereq_('../scatter/get_trace_color');\nvar fillText = _dereq_('../../lib').fillText;\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function hoverPoints(pointData, xval, yval) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var geo = pointData.subplot;\n\n    var isLonLatOverEdges = geo.projection.isLonLatOverEdges;\n    var project = geo.project;\n\n    function distFn(d) {\n        var lonlat = d.lonlat;\n\n        if(lonlat[0] === BADNUM) return Infinity;\n        if(isLonLatOverEdges(lonlat)) return Infinity;\n\n        var pt = project(lonlat);\n        var px = project([xval, yval]);\n        var dx = Math.abs(pt[0] - px[0]);\n        var dy = Math.abs(pt[1] - px[1]);\n        var rad = Math.max(3, d.mrc || 0);\n\n        // N.B. d.mrc is the calculated marker radius\n        // which is only set for trace with 'markers' mode.\n\n        return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - 3 / rad);\n    }\n\n    Fx.getClosest(cd, distFn, pointData);\n\n    // skip the rest (for this trace) if we didn't find a close point\n    if(pointData.index === false) return;\n\n    var di = cd[pointData.index];\n    var lonlat = di.lonlat;\n    var pos = [xa.c2p(lonlat), ya.c2p(lonlat)];\n    var rad = di.mrc || 1;\n\n    pointData.x0 = pos[0] - rad;\n    pointData.x1 = pos[0] + rad;\n    pointData.y0 = pos[1] - rad;\n    pointData.y1 = pos[1] + rad;\n\n    pointData.loc = di.loc;\n    pointData.lon = lonlat[0];\n    pointData.lat = lonlat[1];\n\n    var ax = geo.mockAxis;\n    pointData.lonLabel = Axes.tickText(ax, ax.c2l(pointData.lon), 'hover').text;\n    pointData.latLabel = Axes.tickText(ax, ax.c2l(pointData.lat), 'hover').text;\n\n    pointData.color = getTraceColor(trace, di);\n    pointData.extraText = getExtraText(trace, di, pointData, cd[0].t.labels);\n    pointData.hovertemplate = trace.hovertemplate;\n\n    return [pointData];\n};\n\nfunction getExtraText(trace, pt, pointData, labels) {\n    if(trace.hovertemplate) return;\n\n    var hoverinfo = pt.hi || trace.hoverinfo;\n\n    var parts = hoverinfo === 'all' ?\n        attributes.hoverinfo.flags :\n        hoverinfo.split('+');\n\n    var hasLocation = parts.indexOf('location') !== -1 && Array.isArray(trace.locations);\n    var hasLon = (parts.indexOf('lon') !== -1);\n    var hasLat = (parts.indexOf('lat') !== -1);\n    var hasText = (parts.indexOf('text') !== -1);\n    var text = [];\n\n    function format(val) { return val + '\\u00B0'; }\n\n    if(hasLocation) {\n        text.push(pt.loc);\n    } else if(hasLon && hasLat) {\n        text.push('(' + format(pointData.lonLabel) + ', ' + format(pointData.latLabel) + ')');\n    } else if(hasLon) {\n        text.push(labels.lon + format(pointData.lonLabel));\n    } else if(hasLat) {\n        text.push(labels.lat + format(pointData.latLabel));\n    }\n\n    if(hasText) {\n        fillText(pt, trace, text);\n    }\n\n    return text.join('<br>');\n}\n\n},{\"../../components/fx\":632,\"../../constants/numerical\":695,\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../scatter/get_trace_color\":1121,\"./attributes\":1151}],1156:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    style: _dereq_('./style'),\n    styleOnSelect: _dereq_('../scatter/style').styleOnSelect,\n    hoverPoints: _dereq_('./hover'),\n    eventData: _dereq_('./event_data'),\n    selectPoints: _dereq_('./select'),\n\n    moduleType: 'trace',\n    name: 'scattergeo',\n    basePlotModule: _dereq_('../../plots/geo'),\n    categories: ['geo', 'symbols', 'showLegend', 'scatter-like'],\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/geo\":797,\"../scatter/marker_colorbar\":1129,\"../scatter/style\":1134,\"./attributes\":1151,\"./calc\":1152,\"./defaults\":1153,\"./event_data\":1154,\"./hover\":1155,\"./plot\":1157,\"./select\":1158,\"./style\":1159}],1157:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Lib = _dereq_('../../lib');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\nvar getTopojsonFeatures = _dereq_('../../lib/topojson_utils').getTopojsonFeatures;\nvar locationToFeature = _dereq_('../../lib/geo_location_utils').locationToFeature;\nvar geoJsonUtils = _dereq_('../../lib/geojson_utils');\nvar subTypes = _dereq_('../scatter/subtypes');\nvar style = _dereq_('./style');\n\nmodule.exports = function plot(gd, geo, calcData) {\n    for(var i = 0; i < calcData.length; i++) {\n        calcGeoJSON(calcData[i], geo.topojson);\n    }\n\n    function removeBADNUM(d, node) {\n        if(d.lonlat[0] === BADNUM) {\n            d3.select(node).remove();\n        }\n    }\n\n    var scatterLayer = geo.layers.frontplot.select('.scatterlayer');\n    var gTraces = Lib.makeTraceGroups(scatterLayer, calcData, 'trace scattergeo');\n\n    // TODO find a way to order the inner nodes on update\n    gTraces.selectAll('*').remove();\n\n    gTraces.each(function(calcTrace) {\n        var s = d3.select(this);\n        var trace = calcTrace[0].trace;\n\n        if(subTypes.hasLines(trace) || trace.fill !== 'none') {\n            var lineCoords = geoJsonUtils.calcTraceToLineCoords(calcTrace);\n\n            var lineData = (trace.fill !== 'none') ?\n                geoJsonUtils.makePolygon(lineCoords) :\n                geoJsonUtils.makeLine(lineCoords);\n\n            s.selectAll('path.js-line')\n                .data([{geojson: lineData, trace: trace}])\n              .enter().append('path')\n                .classed('js-line', true)\n                .style('stroke-miterlimit', 2);\n        }\n\n        if(subTypes.hasMarkers(trace)) {\n            s.selectAll('path.point')\n                .data(Lib.identity)\n             .enter().append('path')\n                .classed('point', true)\n                .each(function(calcPt) { removeBADNUM(calcPt, this); });\n        }\n\n        if(subTypes.hasText(trace)) {\n            s.selectAll('g')\n                .data(Lib.identity)\n              .enter().append('g')\n                .append('text')\n                .each(function(calcPt) { removeBADNUM(calcPt, this); });\n        }\n\n        // call style here within topojson request callback\n        style(gd, calcTrace);\n    });\n};\n\nfunction calcGeoJSON(calcTrace, topojson) {\n    var trace = calcTrace[0].trace;\n\n    if(!Array.isArray(trace.locations)) return;\n\n    var features = getTopojsonFeatures(trace, topojson);\n    var locationmode = trace.locationmode;\n\n    for(var i = 0; i < calcTrace.length; i++) {\n        var calcPt = calcTrace[i];\n        var feature = locationToFeature(locationmode, calcPt.loc, features);\n\n        calcPt.lonlat = feature ? feature.properties.ct : [BADNUM, BADNUM];\n    }\n}\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../lib/geo_location_utils\":713,\"../../lib/geojson_utils\":714,\"../../lib/topojson_utils\":746,\"../scatter/subtypes\":1135,\"./style\":1159,\"d3\":163}],1158:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar subtypes = _dereq_('../scatter/subtypes');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function selectPoints(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var xa = searchInfo.xaxis;\n    var ya = searchInfo.yaxis;\n    var selection = [];\n    var trace = cd[0].trace;\n\n    var di, lonlat, x, y, i;\n\n    var hasOnlyLines = (!subtypes.hasMarkers(trace) && !subtypes.hasText(trace));\n    if(hasOnlyLines) return [];\n\n    if(selectionTester === false) {\n        for(i = 0; i < cd.length; i++) {\n            cd[i].selected = 0;\n        }\n    } else {\n        for(i = 0; i < cd.length; i++) {\n            di = cd[i];\n            lonlat = di.lonlat;\n\n            // some projection types can't handle BADNUMs\n            if(lonlat[0] === BADNUM) continue;\n\n            x = xa.c2p(lonlat);\n            y = ya.c2p(lonlat);\n\n            if(selectionTester.contains([x, y], null, i, searchInfo)) {\n                selection.push({\n                    pointNumber: i,\n                    lon: lonlat[0],\n                    lat: lonlat[1]\n                });\n                di.selected = 1;\n            } else {\n                di.selected = 0;\n            }\n        }\n    }\n\n    return selection;\n};\n\n},{\"../../constants/numerical\":695,\"../scatter/subtypes\":1135}],1159:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Drawing = _dereq_('../../components/drawing');\nvar Color = _dereq_('../../components/color');\n\nvar scatterStyle = _dereq_('../scatter/style');\nvar stylePoints = scatterStyle.stylePoints;\nvar styleText = scatterStyle.styleText;\n\nmodule.exports = function style(gd, calcTrace) {\n    if(calcTrace) styleTrace(gd, calcTrace);\n};\n\nfunction styleTrace(gd, calcTrace) {\n    var trace = calcTrace[0].trace;\n    var s = calcTrace[0].node3;\n\n    s.style('opacity', calcTrace[0].trace.opacity);\n\n    stylePoints(s, trace, gd);\n    styleText(s, trace, gd);\n\n    // this part is incompatible with Drawing.lineGroupStyle\n    s.selectAll('path.js-line')\n        .style('fill', 'none')\n        .each(function(d) {\n            var path = d3.select(this);\n            var trace = d.trace;\n            var line = trace.line || {};\n\n            path.call(Color.stroke, line.color)\n                .call(Drawing.dashLine, line.dash || '', line.width || 0);\n\n            if(trace.fill !== 'none') {\n                path.call(Color.fill, trace.fillcolor);\n            }\n        });\n}\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../scatter/style\":1134,\"d3\":163}],1160:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar DASHES = _dereq_('./constants').DASHES;\n\nvar scatterLineAttrs = scatterAttrs.line;\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar scatterMarkerLineAttrs = scatterMarkerAttrs.line;\n\nvar attrs = module.exports = overrideAll({\n    x: scatterAttrs.x,\n    x0: scatterAttrs.x0,\n    dx: scatterAttrs.dx,\n    y: scatterAttrs.y,\n    y0: scatterAttrs.y0,\n    dy: scatterAttrs.dy,\n\n    text: scatterAttrs.text,\n    hovertext: scatterAttrs.hovertext,\n\n    textposition: scatterAttrs.textposition,\n    textfont: scatterAttrs.textfont,\n\n    mode: {\n        valType: 'flaglist',\n        flags: ['lines', 'markers', 'text'],\n        extras: ['none'],\n        \n        \n    },\n    line: {\n        color: scatterLineAttrs.color,\n        width: scatterLineAttrs.width,\n        shape: {\n            valType: 'enumerated',\n            values: ['linear', 'hv', 'vh', 'hvh', 'vhv'],\n            dflt: 'linear',\n            \n            editType: 'plot',\n            \n        },\n        dash: {\n            valType: 'enumerated',\n            values: Object.keys(DASHES),\n            dflt: 'solid',\n            \n            \n        }\n    },\n    marker: extendFlat({}, colorScaleAttrs('marker'), {\n        symbol: scatterMarkerAttrs.symbol,\n        size: scatterMarkerAttrs.size,\n        sizeref: scatterMarkerAttrs.sizeref,\n        sizemin: scatterMarkerAttrs.sizemin,\n        sizemode: scatterMarkerAttrs.sizemode,\n        opacity: scatterMarkerAttrs.opacity,\n        colorbar: scatterMarkerAttrs.colorbar,\n        line: extendFlat({}, colorScaleAttrs('marker.line'), {\n            width: scatterMarkerLineAttrs.width\n        })\n    }),\n    connectgaps: scatterAttrs.connectgaps,\n    fill: extendFlat({}, scatterAttrs.fill, {dflt: 'none'}),\n    fillcolor: scatterAttrs.fillcolor,\n\n    // no hoveron\n\n    selected: {\n        marker: scatterAttrs.selected.marker,\n        textfont: scatterAttrs.selected.textfont\n    },\n    unselected: {\n        marker: scatterAttrs.unselected.marker,\n        textfont: scatterAttrs.unselected.textfont\n    },\n\n    opacity: plotAttrs.opacity\n\n}, 'calc', 'nested');\n\nattrs.x.editType = attrs.y.editType = attrs.x0.editType = attrs.y0.editType = 'calc+clearAxisTypes';\nattrs.hovertemplate = scatterAttrs.hovertemplate;\n\n},{\"../../components/colorscale/attributes\":600,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/attributes\":764,\"../scatter/attributes\":1112,\"./constants\":1162}],1161:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar cluster = _dereq_('point-cluster');\n\nvar Lib = _dereq_('../../lib');\nvar AxisIDs = _dereq_('../../plots/cartesian/axis_ids');\nvar findExtremes = _dereq_('../../plots/cartesian/autorange').findExtremes;\n\nvar scatterCalc = _dereq_('../scatter/calc');\nvar calcMarkerSize = scatterCalc.calcMarkerSize;\nvar calcAxisExpansion = scatterCalc.calcAxisExpansion;\nvar setFirstScatter = scatterCalc.setFirstScatter;\nvar calcColorscale = _dereq_('../scatter/colorscale_calc');\nvar convert = _dereq_('./convert');\nvar sceneUpdate = _dereq_('./scene_update');\n\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\nvar TOO_MANY_POINTS = _dereq_('./constants').TOO_MANY_POINTS;\n\nmodule.exports = function calc(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var xa = AxisIDs.getFromId(gd, trace.xaxis);\n    var ya = AxisIDs.getFromId(gd, trace.yaxis);\n    var subplot = fullLayout._plots[trace.xaxis + trace.yaxis];\n    var len = trace._length;\n    var hasTooManyPoints = len >= TOO_MANY_POINTS;\n    var len2 = len * 2;\n    var stash = {};\n    var i, xx, yy;\n\n    var x = xa.makeCalcdata(trace, 'x');\n    var y = ya.makeCalcdata(trace, 'y');\n\n    // we need hi-precision for scatter2d,\n    // regl-scatter2d uses NaNs for bad/missing values\n    var positions = new Array(len2);\n    for(i = 0; i < len; i++) {\n        xx = x[i];\n        yy = y[i];\n        positions[i * 2] = xx === BADNUM ? NaN : xx;\n        positions[i * 2 + 1] = yy === BADNUM ? NaN : yy;\n    }\n\n    if(xa.type === 'log') {\n        for(i = 0; i < len2; i += 2) {\n            positions[i] = xa.c2l(positions[i]);\n        }\n    }\n    if(ya.type === 'log') {\n        for(i = 1; i < len2; i += 2) {\n            positions[i] = ya.c2l(positions[i]);\n        }\n    }\n\n    // we don't build a tree for log axes since it takes long to convert log2px\n    // and it is also\n    if(hasTooManyPoints && (xa.type !== 'log' && ya.type !== 'log')) {\n        // FIXME: delegate this to webworker\n        stash.tree = cluster(positions);\n    } else {\n        var ids = stash.ids = new Array(len);\n        for(i = 0; i < len; i++) {\n            ids[i] = i;\n        }\n    }\n\n    // create scene options and scene\n    calcColorscale(gd, trace);\n    var opts = sceneOptions(gd, subplot, trace, positions, x, y);\n    var scene = sceneUpdate(gd, subplot);\n\n    // Reuse SVG scatter axis expansion routine.\n    // For graphs with very large number of points and array marker.size,\n    // use average marker size instead to speed things up.\n    setFirstScatter(fullLayout, trace);\n    var ppad;\n    if(!hasTooManyPoints) {\n        ppad = calcMarkerSize(trace, len);\n    } else if(opts.marker) {\n        ppad = 2 * (opts.marker.sizeAvg || Math.max(opts.marker.size, 3));\n    }\n    calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);\n    if(opts.errorX) expandForErrorBars(trace, xa, opts.errorX);\n    if(opts.errorY) expandForErrorBars(trace, ya, opts.errorY);\n\n    // set flags to create scene renderers\n    if(opts.fill && !scene.fill2d) scene.fill2d = true;\n    if(opts.marker && !scene.scatter2d) scene.scatter2d = true;\n    if(opts.line && !scene.line2d) scene.line2d = true;\n    if((opts.errorX || opts.errorY) && !scene.error2d) scene.error2d = true;\n    if(opts.text && !scene.glText) scene.glText = true;\n\n    // FIXME: organize it in a more appropriate manner, probably in sceneOptions\n    // put point-cluster instance for optimized regl calc\n    if(opts.marker) {\n        opts.marker.snap = stash.tree || TOO_MANY_POINTS;\n    }\n\n    scene.lineOptions.push(opts.line);\n    scene.errorXOptions.push(opts.errorX);\n    scene.errorYOptions.push(opts.errorY);\n    scene.fillOptions.push(opts.fill);\n    scene.markerOptions.push(opts.marker);\n    scene.markerSelectedOptions.push(opts.markerSel);\n    scene.markerUnselectedOptions.push(opts.markerUnsel);\n    scene.textOptions.push(opts.text);\n    scene.textSelectedOptions.push(opts.textSel);\n    scene.textUnselectedOptions.push(opts.textUnsel);\n    scene.selectBatch.push([]);\n    scene.unselectBatch.push([]);\n\n    stash._scene = scene;\n    stash.index = scene.count;\n    stash.x = x;\n    stash.y = y;\n    stash.positions = positions;\n    scene.count++;\n\n    return [{x: false, y: false, t: stash, trace: trace}];\n};\n\nfunction expandForErrorBars(trace, ax, opts) {\n    var extremes = trace._extremes[ax._id];\n    var errExt = findExtremes(ax, opts._bnds, {padded: true});\n    extremes.min = extremes.min.concat(errExt.min);\n    extremes.max = extremes.max.concat(errExt.max);\n}\n\nfunction sceneOptions(gd, subplot, trace, positions, x, y) {\n    var opts = convert.style(gd, trace);\n\n    if(opts.marker) {\n        opts.marker.positions = positions;\n    }\n\n    if(opts.line && positions.length > 1) {\n        Lib.extendFlat(\n            opts.line,\n            convert.linePositions(gd, trace, positions)\n        );\n    }\n\n    if(opts.errorX || opts.errorY) {\n        var errors = convert.errorBarPositions(gd, trace, positions, x, y);\n\n        if(opts.errorX) {\n            Lib.extendFlat(opts.errorX, errors.x);\n        }\n        if(opts.errorY) {\n            Lib.extendFlat(opts.errorY, errors.y);\n        }\n    }\n\n    if(opts.text) {\n        Lib.extendFlat(\n            opts.text,\n            {positions: positions},\n            convert.textPosition(gd, trace, opts.text, opts.marker)\n        );\n        Lib.extendFlat(\n            opts.textSel,\n            {positions: positions},\n            convert.textPosition(gd, trace, opts.text, opts.markerSel)\n        );\n        Lib.extendFlat(\n            opts.textUnsel,\n            {positions: positions},\n            convert.textPosition(gd, trace, opts.text, opts.markerUnsel)\n        );\n    }\n\n    return opts;\n}\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../plots/cartesian/autorange\":766,\"../../plots/cartesian/axis_ids\":770,\"../scatter/calc\":1113,\"../scatter/colorscale_calc\":1115,\"./constants\":1162,\"./convert\":1163,\"./scene_update\":1169,\"point-cluster\":469}],1162:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar SYMBOL_SIZE = 20;\n\nmodule.exports = {\n    TOO_MANY_POINTS: 1e5,\n\n    SYMBOL_SDF_SIZE: 200,\n    SYMBOL_SIZE: SYMBOL_SIZE,\n    SYMBOL_STROKE: SYMBOL_SIZE / 20,\n\n    DOT_RE: /-dot/,\n    OPEN_RE: /-open/,\n\n    DASHES: {\n        solid: [1],\n        dot: [1, 1],\n        dash: [4, 1],\n        longdash: [8, 1],\n        dashdot: [4, 1, 1, 1],\n        longdashdot: [8, 1, 1, 1]\n    }\n};\n\n},{}],1163:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar svgSdf = _dereq_('svg-path-sdf');\nvar rgba = _dereq_('color-normalize');\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../../components/drawing');\nvar AxisIDs = _dereq_('../../plots/cartesian/axis_ids');\n\nvar formatColor = _dereq_('../../lib/gl_format_color').formatColor;\nvar subTypes = _dereq_('../scatter/subtypes');\nvar makeBubbleSizeFn = _dereq_('../scatter/make_bubble_size_func');\n\nvar constants = _dereq_('./constants');\nvar DESELECTDIM = _dereq_('../../constants/interactions').DESELECTDIM;\n\nvar TEXTOFFSETSIGN = {\n    start: 1, left: 1, end: -1, right: -1, middle: 0, center: 0, bottom: 1, top: -1\n};\n\nfunction convertStyle(gd, trace) {\n    var i;\n\n    var opts = {\n        marker: undefined,\n        markerSel: undefined,\n        markerUnsel: undefined,\n        line: undefined,\n        fill: undefined,\n        errorX: undefined,\n        errorY: undefined,\n        text: undefined,\n        textSel: undefined,\n        textUnsel: undefined\n    };\n\n    if(trace.visible !== true) return opts;\n\n    if(subTypes.hasText(trace)) {\n        opts.text = convertTextStyle(trace);\n        opts.textSel = convertTextSelection(trace, trace.selected);\n        opts.textUnsel = convertTextSelection(trace, trace.unselected);\n    }\n\n    if(subTypes.hasMarkers(trace)) {\n        opts.marker = convertMarkerStyle(trace);\n        opts.markerSel = convertMarkerSelection(trace, trace.selected);\n        opts.markerUnsel = convertMarkerSelection(trace, trace.unselected);\n\n        if(!trace.unselected && Array.isArray(trace.marker.opacity)) {\n            var mo = trace.marker.opacity;\n            opts.markerUnsel.opacity = new Array(mo.length);\n            for(i = 0; i < mo.length; i++) {\n                opts.markerUnsel.opacity[i] = DESELECTDIM * mo[i];\n            }\n        }\n    }\n\n    if(subTypes.hasLines(trace)) {\n        opts.line = {\n            overlay: true,\n            thickness: trace.line.width,\n            color: trace.line.color,\n            opacity: trace.opacity\n        };\n\n        var dashes = (constants.DASHES[trace.line.dash] || [1]).slice();\n        for(i = 0; i < dashes.length; ++i) {\n            dashes[i] *= trace.line.width;\n        }\n        opts.line.dashes = dashes;\n    }\n\n    if(trace.error_x && trace.error_x.visible) {\n        opts.errorX = convertErrorBarStyle(trace, trace.error_x);\n    }\n\n    if(trace.error_y && trace.error_y.visible) {\n        opts.errorY = convertErrorBarStyle(trace, trace.error_y);\n    }\n\n    if(!!trace.fill && trace.fill !== 'none') {\n        opts.fill = {\n            closed: true,\n            fill: trace.fillcolor,\n            thickness: 0\n        };\n    }\n\n    return opts;\n}\n\nfunction convertTextStyle(trace) {\n    var count = trace._length;\n    var textfontIn = trace.textfont;\n    var textpositionIn = trace.textposition;\n    var textPos = Array.isArray(textpositionIn) ? textpositionIn : [textpositionIn];\n    var tfc = textfontIn.color;\n    var tfs = textfontIn.size;\n    var tff = textfontIn.family;\n    var optsOut = {};\n    var i;\n\n    optsOut.text = trace.text;\n    optsOut.opacity = trace.opacity;\n    optsOut.font = {};\n    optsOut.align = [];\n    optsOut.baseline = [];\n\n    for(i = 0; i < textPos.length; i++) {\n        var tp = textPos[i].split(/\\s+/);\n\n        switch(tp[1]) {\n            case 'left':\n                optsOut.align.push('right');\n                break;\n            case 'right':\n                optsOut.align.push('left');\n                break;\n            default:\n                optsOut.align.push(tp[1]);\n        }\n        switch(tp[0]) {\n            case 'top':\n                optsOut.baseline.push('bottom');\n                break;\n            case 'bottom':\n                optsOut.baseline.push('top');\n                break;\n            default:\n                optsOut.baseline.push(tp[0]);\n        }\n    }\n\n    if(Array.isArray(tfc)) {\n        optsOut.color = new Array(count);\n        for(i = 0; i < count; i++) {\n            optsOut.color[i] = tfc[i];\n        }\n    } else {\n        optsOut.color = tfc;\n    }\n\n    if(Array.isArray(tfs) || Array.isArray(tff)) {\n        // if any textfont param is array - make render a batch\n        optsOut.font = new Array(count);\n        for(i = 0; i < count; i++) {\n            var fonti = optsOut.font[i] = {};\n\n            fonti.size = Array.isArray(tfs) ?\n                (isNumeric(tfs[i]) ? tfs[i] : 0) :\n                tfs;\n\n            fonti.family = Array.isArray(tff) ? tff[i] : tff;\n        }\n    } else {\n        // if both are single values, make render fast single-value\n        optsOut.font = {size: tfs, family: tff};\n    }\n\n    return optsOut;\n}\n\n\nfunction convertMarkerStyle(trace) {\n    var count = trace._length;\n    var optsIn = trace.marker;\n    var optsOut = {};\n    var i;\n\n    var multiSymbol = Array.isArray(optsIn.symbol);\n    var multiColor = Lib.isArrayOrTypedArray(optsIn.color);\n    var multiLineColor = Lib.isArrayOrTypedArray(optsIn.line.color);\n    var multiOpacity = Lib.isArrayOrTypedArray(optsIn.opacity);\n    var multiSize = Lib.isArrayOrTypedArray(optsIn.size);\n    var multiLineWidth = Lib.isArrayOrTypedArray(optsIn.line.width);\n\n    var isOpen;\n    if(!multiSymbol) isOpen = constants.OPEN_RE.test(optsIn.symbol);\n\n    // prepare colors\n    if(multiSymbol || multiColor || multiLineColor || multiOpacity) {\n        optsOut.colors = new Array(count);\n        optsOut.borderColors = new Array(count);\n\n        var colors = formatColor(optsIn, optsIn.opacity, count);\n        var borderColors = formatColor(optsIn.line, optsIn.opacity, count);\n\n        if(!Array.isArray(borderColors[0])) {\n            var borderColor = borderColors;\n            borderColors = Array(count);\n            for(i = 0; i < count; i++) {\n                borderColors[i] = borderColor;\n            }\n        }\n        if(!Array.isArray(colors[0])) {\n            var color = colors;\n            colors = Array(count);\n            for(i = 0; i < count; i++) {\n                colors[i] = color;\n            }\n        }\n\n        optsOut.colors = colors;\n        optsOut.borderColors = borderColors;\n\n        for(i = 0; i < count; i++) {\n            if(multiSymbol) {\n                var symbol = optsIn.symbol[i];\n                isOpen = constants.OPEN_RE.test(symbol);\n            }\n            if(isOpen) {\n                borderColors[i] = colors[i].slice();\n                colors[i] = colors[i].slice();\n                colors[i][3] = 0;\n            }\n        }\n\n        optsOut.opacity = trace.opacity;\n    } else {\n        if(isOpen) {\n            optsOut.color = rgba(optsIn.color, 'uint8');\n            optsOut.color[3] = 0;\n            optsOut.borderColor = rgba(optsIn.color, 'uint8');\n        } else {\n            optsOut.color = rgba(optsIn.color, 'uint8');\n            optsOut.borderColor = rgba(optsIn.line.color, 'uint8');\n        }\n\n        optsOut.opacity = trace.opacity * optsIn.opacity;\n    }\n\n    // prepare symbols\n    if(multiSymbol) {\n        optsOut.markers = new Array(count);\n        for(i = 0; i < count; i++) {\n            optsOut.markers[i] = getSymbolSdf(optsIn.symbol[i]);\n        }\n    } else {\n        optsOut.marker = getSymbolSdf(optsIn.symbol);\n    }\n\n    // prepare sizes\n    var markerSizeFunc = makeBubbleSizeFn(trace);\n    var s;\n\n    if(multiSize || multiLineWidth) {\n        var sizes = optsOut.sizes = new Array(count);\n        var borderSizes = optsOut.borderSizes = new Array(count);\n        var sizeTotal = 0;\n        var sizeAvg;\n\n        if(multiSize) {\n            for(i = 0; i < count; i++) {\n                sizes[i] = markerSizeFunc(optsIn.size[i]);\n                sizeTotal += sizes[i];\n            }\n            sizeAvg = sizeTotal / count;\n        } else {\n            s = markerSizeFunc(optsIn.size);\n            for(i = 0; i < count; i++) {\n                sizes[i] = s;\n            }\n        }\n\n        // See  https://github.com/plotly/plotly.js/pull/1781#discussion_r121820798\n        if(multiLineWidth) {\n            for(i = 0; i < count; i++) {\n                borderSizes[i] = optsIn.line.width[i] / 2;\n            }\n        } else {\n            s = optsIn.line.width / 2;\n            for(i = 0; i < count; i++) {\n                borderSizes[i] = s;\n            }\n        }\n\n        optsOut.sizeAvg = sizeAvg;\n    } else {\n        optsOut.size = markerSizeFunc(optsIn && optsIn.size || 10);\n        optsOut.borderSizes = markerSizeFunc(optsIn.line.width);\n    }\n\n    return optsOut;\n}\n\nfunction convertMarkerSelection(trace, target) {\n    var optsIn = trace.marker;\n    var optsOut = {};\n\n    if(!target) return optsOut;\n\n    if(target.marker && target.marker.symbol) {\n        optsOut = convertMarkerStyle(Lib.extendFlat({}, optsIn, target.marker));\n    } else if(target.marker) {\n        if(target.marker.size) optsOut.size = target.marker.size / 2;\n        if(target.marker.color) optsOut.colors = target.marker.color;\n        if(target.marker.opacity !== undefined) optsOut.opacity = target.marker.opacity;\n    }\n\n    return optsOut;\n}\n\nfunction convertTextSelection(trace, target) {\n    var optsOut = {};\n\n    if(!target) return optsOut;\n\n    if(target.textfont) {\n        var optsIn = {\n            opacity: 1,\n            text: trace.text,\n            textposition: trace.textposition,\n            textfont: Lib.extendFlat({}, trace.textfont)\n        };\n        if(target.textfont) {\n            Lib.extendFlat(optsIn.textfont, target.textfont);\n        }\n        optsOut = convertTextStyle(optsIn);\n    }\n\n    return optsOut;\n}\n\nfunction convertErrorBarStyle(trace, target) {\n    var optsOut = {\n        capSize: target.width * 2,\n        lineWidth: target.thickness,\n        color: target.color\n    };\n\n    if(target.copy_ystyle) {\n        optsOut = trace.error_y;\n    }\n\n    return optsOut;\n}\n\nvar SYMBOL_SDF_SIZE = constants.SYMBOL_SDF_SIZE;\nvar SYMBOL_SIZE = constants.SYMBOL_SIZE;\nvar SYMBOL_STROKE = constants.SYMBOL_STROKE;\nvar SYMBOL_SDF = {};\nvar SYMBOL_SVG_CIRCLE = Drawing.symbolFuncs[0](SYMBOL_SIZE * 0.05);\n\nfunction getSymbolSdf(symbol) {\n    if(symbol === 'circle') return null;\n\n    var symbolPath, symbolSdf;\n    var symbolNumber = Drawing.symbolNumber(symbol);\n    var symbolFunc = Drawing.symbolFuncs[symbolNumber % 100];\n    var symbolNoDot = !!Drawing.symbolNoDot[symbolNumber % 100];\n    var symbolNoFill = !!Drawing.symbolNoFill[symbolNumber % 100];\n\n    var isDot = constants.DOT_RE.test(symbol);\n\n    // get symbol sdf from cache or generate it\n    if(SYMBOL_SDF[symbol]) return SYMBOL_SDF[symbol];\n\n    if(isDot && !symbolNoDot) {\n        symbolPath = symbolFunc(SYMBOL_SIZE * 1.1) + SYMBOL_SVG_CIRCLE;\n    } else {\n        symbolPath = symbolFunc(SYMBOL_SIZE);\n    }\n\n    symbolSdf = svgSdf(symbolPath, {\n        w: SYMBOL_SDF_SIZE,\n        h: SYMBOL_SDF_SIZE,\n        viewBox: [-SYMBOL_SIZE, -SYMBOL_SIZE, SYMBOL_SIZE, SYMBOL_SIZE],\n        stroke: symbolNoFill ? SYMBOL_STROKE : -SYMBOL_STROKE\n    });\n    SYMBOL_SDF[symbol] = symbolSdf;\n\n    return symbolSdf || null;\n}\n\nfunction convertLinePositions(gd, trace, positions) {\n    var len = positions.length;\n    var count = len / 2;\n    var linePositions;\n    var i;\n\n    if(subTypes.hasLines(trace) && count) {\n        if(trace.line.shape === 'hv') {\n            linePositions = [];\n            for(i = 0; i < count - 1; i++) {\n                if(isNaN(positions[i * 2]) || isNaN(positions[i * 2 + 1])) {\n                    linePositions.push(NaN, NaN, NaN, NaN);\n                } else {\n                    linePositions.push(positions[i * 2], positions[i * 2 + 1]);\n                    if(!isNaN(positions[i * 2 + 2]) && !isNaN(positions[i * 2 + 3])) {\n                        linePositions.push(positions[i * 2 + 2], positions[i * 2 + 1]);\n                    } else {\n                        linePositions.push(NaN, NaN);\n                    }\n                }\n            }\n            linePositions.push(positions[len - 2], positions[len - 1]);\n        } else if(trace.line.shape === 'hvh') {\n            linePositions = [];\n            for(i = 0; i < count - 1; i++) {\n                if(isNaN(positions[i * 2]) || isNaN(positions[i * 2 + 1]) || isNaN(positions[i * 2 + 2]) || isNaN(positions[i * 2 + 3])) {\n                    if(!isNaN(positions[i * 2]) && !isNaN(positions[i * 2 + 1])) {\n                        linePositions.push(positions[i * 2], positions[i * 2 + 1]);\n                    } else {\n                        linePositions.push(NaN, NaN);\n                    }\n                    linePositions.push(NaN, NaN);\n                } else {\n                    var midPtX = (positions[i * 2] + positions[i * 2 + 2]) / 2;\n                    linePositions.push(\n                        positions[i * 2],\n                        positions[i * 2 + 1],\n                        midPtX,\n                        positions[i * 2 + 1],\n                        midPtX,\n                        positions[i * 2 + 3]\n                    );\n                }\n            }\n            linePositions.push(positions[len - 2], positions[len - 1]);\n        } else if(trace.line.shape === 'vhv') {\n            linePositions = [];\n            for(i = 0; i < count - 1; i++) {\n                if(isNaN(positions[i * 2]) || isNaN(positions[i * 2 + 1]) || isNaN(positions[i * 2 + 2]) || isNaN(positions[i * 2 + 3])) {\n                    if(!isNaN(positions[i * 2]) && !isNaN(positions[i * 2 + 1])) {\n                        linePositions.push(positions[i * 2], positions[i * 2 + 1]);\n                    } else {\n                        linePositions.push(NaN, NaN);\n                    }\n                    linePositions.push(NaN, NaN);\n                } else {\n                    var midPtY = (positions[i * 2 + 1] + positions[i * 2 + 3]) / 2;\n                    linePositions.push(\n                        positions[i * 2],\n                        positions[i * 2 + 1],\n                        positions[i * 2],\n                        midPtY,\n                        positions[i * 2 + 2],\n                        midPtY\n                    );\n                }\n            }\n            linePositions.push(positions[len - 2], positions[len - 1]);\n        } else if(trace.line.shape === 'vh') {\n            linePositions = [];\n            for(i = 0; i < count - 1; i++) {\n                if(isNaN(positions[i * 2]) || isNaN(positions[i * 2 + 1])) {\n                    linePositions.push(NaN, NaN, NaN, NaN);\n                } else {\n                    linePositions.push(positions[i * 2], positions[i * 2 + 1]);\n                    if(!isNaN(positions[i * 2 + 2]) && !isNaN(positions[i * 2 + 3])) {\n                        linePositions.push(positions[i * 2], positions[i * 2 + 3]);\n                    } else {\n                        linePositions.push(NaN, NaN);\n                    }\n                }\n            }\n            linePositions.push(positions[len - 2], positions[len - 1]);\n        } else {\n            linePositions = positions;\n        }\n    }\n\n    // If we have data with gaps, we ought to use rect joins\n    // FIXME: get rid of this\n    var hasNaN = false;\n    for(i = 0; i < linePositions.length; i++) {\n        if(isNaN(linePositions[i])) {\n            hasNaN = true;\n            break;\n        }\n    }\n\n    var join = (hasNaN || linePositions.length > constants.TOO_MANY_POINTS) ? 'rect' :\n        subTypes.hasMarkers(trace) ? 'rect' : 'round';\n\n    // fill gaps\n    if(hasNaN && trace.connectgaps) {\n        var lastX = linePositions[0];\n        var lastY = linePositions[1];\n\n        for(i = 0; i < linePositions.length; i += 2) {\n            if(isNaN(linePositions[i]) || isNaN(linePositions[i + 1])) {\n                linePositions[i] = lastX;\n                linePositions[i + 1] = lastY;\n            } else {\n                lastX = linePositions[i];\n                lastY = linePositions[i + 1];\n            }\n        }\n    }\n\n    return {\n        join: join,\n        positions: linePositions\n    };\n}\n\nfunction convertErrorBarPositions(gd, trace, positions, x, y) {\n    var makeComputeError = Registry.getComponentMethod('errorbars', 'makeComputeError');\n    var xa = AxisIDs.getFromId(gd, trace.xaxis);\n    var ya = AxisIDs.getFromId(gd, trace.yaxis);\n    var count = positions.length / 2;\n    var out = {};\n\n    function convertOneAxis(coords, ax) {\n        var axLetter = ax._id.charAt(0);\n        var opts = trace['error_' + axLetter];\n\n        if(opts && opts.visible && (ax.type === 'linear' || ax.type === 'log')) {\n            var computeError = makeComputeError(opts);\n            var pOffset = {x: 0, y: 1}[axLetter];\n            var eOffset = {x: [0, 1, 2, 3], y: [2, 3, 0, 1]}[axLetter];\n            var errors = new Float64Array(4 * count);\n            var minShoe = Infinity;\n            var maxHat = -Infinity;\n\n            for(var i = 0, j = 0; i < count; i++, j += 4) {\n                var dc = coords[i];\n\n                if(isNumeric(dc)) {\n                    var dl = positions[i * 2 + pOffset];\n                    var vals = computeError(dc, i);\n                    var lv = vals[0];\n                    var hv = vals[1];\n\n                    if(isNumeric(lv) && isNumeric(hv)) {\n                        var shoe = dc - lv;\n                        var hat = dc + hv;\n\n                        errors[j + eOffset[0]] = dl - ax.c2l(shoe);\n                        errors[j + eOffset[1]] = ax.c2l(hat) - dl;\n                        errors[j + eOffset[2]] = 0;\n                        errors[j + eOffset[3]] = 0;\n\n                        minShoe = Math.min(minShoe, dc - lv);\n                        maxHat = Math.max(maxHat, dc + hv);\n                    }\n                }\n            }\n\n            out[axLetter] = {\n                positions: positions,\n                errors: errors,\n                _bnds: [minShoe, maxHat]\n            };\n        }\n    }\n\n    convertOneAxis(x, xa);\n    convertOneAxis(y, ya);\n    return out;\n}\n\nfunction convertTextPosition(gd, trace, textOpts, markerOpts) {\n    var count = trace._length;\n    var out = {};\n    var i;\n\n    // corresponds to textPointPosition from component.drawing\n    if(subTypes.hasMarkers(trace)) {\n        var fontOpts = textOpts.font;\n        var align = textOpts.align;\n        var baseline = textOpts.baseline;\n        out.offset = new Array(count);\n\n        for(i = 0; i < count; i++) {\n            var ms = markerOpts.sizes ? markerOpts.sizes[i] : markerOpts.size;\n            var fs = Array.isArray(fontOpts) ? fontOpts[i].size : fontOpts.size;\n\n            var a = Array.isArray(align) ?\n                (align.length > 1 ? align[i] : align[0]) :\n                align;\n            var b = Array.isArray(baseline) ?\n                (baseline.length > 1 ? baseline[i] : baseline[0]) :\n                baseline;\n\n            var hSign = TEXTOFFSETSIGN[a];\n            var vSign = TEXTOFFSETSIGN[b];\n            var xPad = ms ? ms / 0.8 + 1 : 0;\n            var yPad = -vSign * xPad - vSign * 0.5;\n            out.offset[i] = [hSign * xPad / fs, yPad / fs];\n        }\n    }\n\n    return out;\n}\n\nmodule.exports = {\n    style: convertStyle,\n\n    markerStyle: convertMarkerStyle,\n    markerSelection: convertMarkerSelection,\n\n    linePositions: convertLinePositions,\n    errorBarPositions: convertErrorBarPositions,\n    textPosition: convertTextPosition\n};\n\n},{\"../../components/drawing\":614,\"../../constants/interactions\":694,\"../../lib\":719,\"../../lib/gl_format_color\":716,\"../../plots/cartesian/axis_ids\":770,\"../../registry\":847,\"../scatter/make_bubble_size_func\":1128,\"../scatter/subtypes\":1135,\"./constants\":1162,\"color-normalize\":120,\"fast-isnumeric\":225,\"svg-path-sdf\":535}],1164:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Registry = _dereq_('../../registry');\n\nvar attributes = _dereq_('./attributes');\nvar constants = _dereq_('../scatter/constants');\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleXYDefaults = _dereq_('../scatter/xy_defaults');\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar handleLineDefaults = _dereq_('../scatter/line_defaults');\nvar handleFillColorDefaults = _dereq_('../scatter/fillcolor_defaults');\nvar handleTextDefaults = _dereq_('../scatter/text_defaults');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var isOpen = traceIn.marker ? /-open/.test(traceIn.marker.symbol) : false;\n    var isBubble = subTypes.isBubble(traceIn);\n\n    var len = handleXYDefaults(traceIn, traceOut, layout, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n    var defaultMode = len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines';\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n    coerce('mode', defaultMode);\n\n    if(subTypes.hasLines(traceOut)) {\n        coerce('connectgaps');\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n        coerce('line.shape');\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n        coerce('marker.line.width', isOpen || isBubble ? 1 : 0);\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce);\n    }\n\n    var lineColor = (traceOut.line || {}).color;\n    var markerColor = (traceOut.marker || {}).color;\n\n    coerce('fill');\n    if(traceOut.fill !== 'none') {\n        handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);\n    }\n\n    var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'y'});\n    errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'x', inherit: 'y'});\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\n},{\"../../lib\":719,\"../../registry\":847,\"../scatter/constants\":1116,\"../scatter/fillcolor_defaults\":1120,\"../scatter/line_defaults\":1124,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"../scatter/text_defaults\":1136,\"../scatter/xy_defaults\":1137,\"./attributes\":1160}],1165:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\n\nvar DESELECTDIM = _dereq_('../../constants/interactions').DESELECTDIM;\n\nfunction styleTextSelection(cd) {\n    var cd0 = cd[0];\n    var trace = cd0.trace;\n    var stash = cd0.t;\n    var scene = stash._scene;\n    var index = stash.index;\n    var els = scene.selectBatch[index];\n    var unels = scene.unselectBatch[index];\n    var baseOpts = scene.textOptions[index];\n    var selOpts = scene.textSelectedOptions[index] || {};\n    var unselOpts = scene.textUnselectedOptions[index] || {};\n    var opts = Lib.extendFlat({}, baseOpts);\n    var i, j;\n\n    if(els.length || unels.length) {\n        var stc = selOpts.color;\n        var utc = unselOpts.color;\n        var base = baseOpts.color;\n        var hasArrayBase = Array.isArray(base);\n        opts.color = new Array(trace._length);\n\n        for(i = 0; i < els.length; i++) {\n            j = els[i];\n            opts.color[j] = stc || (hasArrayBase ? base[j] : base);\n        }\n        for(i = 0; i < unels.length; i++) {\n            j = unels[i];\n            var basej = hasArrayBase ? base[j] : base;\n            opts.color[j] = utc ? utc :\n                stc ? basej : Color.addOpacity(basej, DESELECTDIM);\n        }\n    }\n\n    scene.glText[index].update(opts);\n}\n\nmodule.exports = {\n    styleTextSelection: styleTextSelection\n};\n\n},{\"../../components/color\":593,\"../../constants/interactions\":694,\"../../lib\":719}],1166:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\nvar getTraceColor = _dereq_('../scatter/get_trace_color');\n\nfunction hoverPoints(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var stash = cd[0].t;\n    var trace = cd[0].trace;\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var x = stash.x;\n    var y = stash.y;\n    var xpx = xa.c2p(xval);\n    var ypx = ya.c2p(yval);\n    var maxDistance = pointData.distance;\n    var ids;\n\n    // FIXME: make sure this is a proper way to calc search radius\n    if(stash.tree) {\n        var xl = xa.p2c(xpx - maxDistance);\n        var xr = xa.p2c(xpx + maxDistance);\n        var yl = ya.p2c(ypx - maxDistance);\n        var yr = ya.p2c(ypx + maxDistance);\n\n        if(hovermode === 'x') {\n            ids = stash.tree.range(\n                Math.min(xl, xr), Math.min(ya._rl[0], ya._rl[1]),\n                Math.max(xl, xr), Math.max(ya._rl[0], ya._rl[1])\n            );\n        } else {\n            ids = stash.tree.range(\n                Math.min(xl, xr), Math.min(yl, yr),\n                Math.max(xl, xr), Math.max(yl, yr)\n            );\n        }\n    } else if(stash.ids) {\n        ids = stash.ids;\n    } else return [pointData];\n\n    // pick the id closest to the point\n    // note that point possibly may not be found\n    var id, ptx, pty, i, dx, dy, dist, dxy;\n\n    var minDist = maxDistance;\n    if(hovermode === 'x') {\n        for(i = 0; i < ids.length; i++) {\n            ptx = x[ids[i]];\n            dx = Math.abs(xa.c2p(ptx) - xpx);\n            if(dx < minDist) {\n                minDist = dx;\n                dy = ya.c2p(y[ids[i]]) - ypx;\n                dxy = Math.sqrt(dx * dx + dy * dy);\n                id = ids[i];\n            }\n        }\n    } else {\n        for(i = ids.length - 1; i > -1; i--) {\n            ptx = x[ids[i]];\n            pty = y[ids[i]];\n            dx = xa.c2p(ptx) - xpx;\n            dy = ya.c2p(pty) - ypx;\n\n            dist = Math.sqrt(dx * dx + dy * dy);\n            if(dist < minDist) {\n                minDist = dxy = dist;\n                id = ids[i];\n            }\n        }\n    }\n\n    pointData.index = id;\n    pointData.distance = minDist;\n    pointData.dxy = dxy;\n\n    if(id === undefined) return [pointData];\n\n    calcHover(pointData, x, y, trace);\n\n    return [pointData];\n}\n\nfunction calcHover(pointData, x, y, trace) {\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var minDist = pointData.distance;\n    var dxy = pointData.dxy;\n    var id = pointData.index;\n\n    // the closest data point\n    var di = {\n        pointNumber: id,\n        x: x[id],\n        y: y[id]\n    };\n\n    // that is single-item arrays_to_calcdata excerpt, since we are doing it for a single point and we don't have to do it beforehead for 1e6 points\n    di.tx = Array.isArray(trace.text) ? trace.text[id] : trace.text;\n    di.htx = Array.isArray(trace.hovertext) ? trace.hovertext[id] : trace.hovertext;\n    di.data = Array.isArray(trace.customdata) ? trace.customdata[id] : trace.customdata;\n    di.tp = Array.isArray(trace.textposition) ? trace.textposition[id] : trace.textposition;\n\n    var font = trace.textfont;\n    if(font) {\n        di.ts = Array.isArray(font.size) ? font.size[id] : font.size;\n        di.tc = Array.isArray(font.color) ? font.color[id] : font.color;\n        di.tf = Array.isArray(font.family) ? font.family[id] : font.family;\n    }\n\n    var marker = trace.marker;\n    if(marker) {\n        di.ms = Lib.isArrayOrTypedArray(marker.size) ? marker.size[id] : marker.size;\n        di.mo = Lib.isArrayOrTypedArray(marker.opacity) ? marker.opacity[id] : marker.opacity;\n        di.mx = Array.isArray(marker.symbol) ? marker.symbol[id] : marker.symbol;\n        di.mc = Lib.isArrayOrTypedArray(marker.color) ? marker.color[id] : marker.color;\n    }\n\n    var line = marker && marker.line;\n    if(line) {\n        di.mlc = Array.isArray(line.color) ? line.color[id] : line.color;\n        di.mlw = Lib.isArrayOrTypedArray(line.width) ? line.width[id] : line.width;\n    }\n\n    var grad = marker && marker.gradient;\n    if(grad && grad.type !== 'none') {\n        di.mgt = Array.isArray(grad.type) ? grad.type[id] : grad.type;\n        di.mgc = Array.isArray(grad.color) ? grad.color[id] : grad.color;\n    }\n\n    var xp = xa.c2p(di.x, true);\n    var yp = ya.c2p(di.y, true);\n    var rad = di.mrc || 1;\n\n    var hoverlabel = trace.hoverlabel;\n\n    if(hoverlabel) {\n        di.hbg = Array.isArray(hoverlabel.bgcolor) ? hoverlabel.bgcolor[id] : hoverlabel.bgcolor;\n        di.hbc = Array.isArray(hoverlabel.bordercolor) ? hoverlabel.bordercolor[id] : hoverlabel.bordercolor;\n        di.hts = Array.isArray(hoverlabel.font.size) ? hoverlabel.font.size[id] : hoverlabel.font.size;\n        di.htc = Array.isArray(hoverlabel.font.color) ? hoverlabel.font.color[id] : hoverlabel.font.color;\n        di.htf = Array.isArray(hoverlabel.font.family) ? hoverlabel.font.family[id] : hoverlabel.font.family;\n        di.hnl = Array.isArray(hoverlabel.namelength) ? hoverlabel.namelength[id] : hoverlabel.namelength;\n    }\n    var hoverinfo = trace.hoverinfo;\n    if(hoverinfo) {\n        di.hi = Array.isArray(hoverinfo) ? hoverinfo[id] : hoverinfo;\n    }\n\n    var hovertemplate = trace.hovertemplate;\n    if(hovertemplate) {\n        di.ht = Array.isArray(hovertemplate) ? hovertemplate[id] : hovertemplate;\n    }\n\n    var fakeCd = {};\n    fakeCd[pointData.index] = di;\n\n    Lib.extendFlat(pointData, {\n        color: getTraceColor(trace, di),\n\n        x0: xp - rad,\n        x1: xp + rad,\n        xLabelVal: di.x,\n\n        y0: yp - rad,\n        y1: yp + rad,\n        yLabelVal: di.y,\n\n        cd: fakeCd,\n        distance: minDist,\n        spikeDistance: dxy,\n\n        hovertemplate: di.ht\n    });\n\n    if(di.htx) pointData.text = di.htx;\n    else if(di.tx) pointData.text = di.tx;\n    else if(trace.text) pointData.text = trace.text;\n\n    Lib.fillText(di, trace, pointData);\n    Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData);\n\n    return pointData;\n}\n\nmodule.exports = {\n    hoverPoints: hoverPoints,\n    calcHover: calcHover\n};\n\n},{\"../../lib\":719,\"../../registry\":847,\"../scatter/get_trace_color\":1121}],1167:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hover = _dereq_('./hover');\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'scattergl',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['gl', 'regl', 'cartesian', 'symbols', 'errorBarsOK', 'showLegend', 'scatter-like'],\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    crossTraceDefaults: _dereq_('../scatter/cross_trace_defaults'),\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    hoverPoints: hover.hoverPoints,\n    selectPoints: _dereq_('./select'),\n\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../scatter/cross_trace_defaults\":1118,\"../scatter/marker_colorbar\":1129,\"./attributes\":1160,\"./calc\":1161,\"./defaults\":1164,\"./hover\":1166,\"./plot\":1168,\"./select\":1170}],1168:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar createScatter = _dereq_('regl-scatter2d');\nvar createLine = _dereq_('regl-line2d');\nvar createError = _dereq_('regl-error2d');\nvar Text = _dereq_('gl-text');\n\nvar Lib = _dereq_('../../lib');\nvar prepareRegl = _dereq_('../../lib/prepare_regl');\n\nvar subTypes = _dereq_('../scatter/subtypes');\nvar linkTraces = _dereq_('../scatter/link_traces');\n\nvar styleTextSelection = _dereq_('./edit_style').styleTextSelection;\n\nfunction getViewport(fullLayout, xaxis, yaxis) {\n    var gs = fullLayout._size;\n    var width = fullLayout.width;\n    var height = fullLayout.height;\n    return [\n        gs.l + xaxis.domain[0] * gs.w,\n        gs.b + yaxis.domain[0] * gs.h,\n        (width - gs.r) - (1 - xaxis.domain[1]) * gs.w,\n        (height - gs.t) - (1 - yaxis.domain[1]) * gs.h\n    ];\n}\n\nmodule.exports = function plot(gd, subplot, cdata) {\n    if(!cdata.length) return;\n\n    var fullLayout = gd._fullLayout;\n    var scene = subplot._scene;\n    var xaxis = subplot.xaxis;\n    var yaxis = subplot.yaxis;\n    var i, j;\n\n    // we may have more subplots than initialized data due to Axes.getSubplots method\n    if(!scene) return;\n\n    var success = prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);\n    if(!success) {\n        scene.init();\n        return;\n    }\n\n    var count = scene.count;\n    var regl = fullLayout._glcanvas.data()[0].regl;\n\n    // that is needed for fills\n    linkTraces(gd, subplot, cdata);\n\n    if(scene.dirty) {\n        // make sure scenes are created\n        if(scene.error2d === true) {\n            scene.error2d = createError(regl);\n        }\n        if(scene.line2d === true) {\n            scene.line2d = createLine(regl);\n        }\n        if(scene.scatter2d === true) {\n            scene.scatter2d = createScatter(regl);\n        }\n        if(scene.fill2d === true) {\n            scene.fill2d = createLine(regl);\n        }\n        if(scene.glText === true) {\n            scene.glText = new Array(count);\n            for(i = 0; i < count; i++) {\n                scene.glText[i] = new Text(regl);\n            }\n        }\n\n        // update main marker options\n        if(scene.glText) {\n            if(count > scene.glText.length) {\n                // add gl text marker\n                var textsToAdd = count - scene.glText.length;\n                for(i = 0; i < textsToAdd; i++) {\n                    scene.glText.push(new Text(regl));\n                }\n            } else if(count < scene.glText.length) {\n                // remove gl text marker\n                var textsToRemove = scene.glText.length - count;\n                var removedTexts = scene.glText.splice(count, textsToRemove);\n                removedTexts.forEach(function(text) { text.destroy(); });\n            }\n\n            for(i = 0; i < count; i++) {\n                scene.glText[i].update(scene.textOptions[i]);\n            }\n        }\n        if(scene.line2d) {\n            scene.line2d.update(scene.lineOptions);\n            scene.lineOptions = scene.lineOptions.map(function(lineOptions) {\n                if(lineOptions && lineOptions.positions) {\n                    var srcPos = lineOptions.positions;\n\n                    var firstptdef = 0;\n                    while(firstptdef < srcPos.length && (isNaN(srcPos[firstptdef]) || isNaN(srcPos[firstptdef + 1]))) {\n                        firstptdef += 2;\n                    }\n                    var lastptdef = srcPos.length - 2;\n                    while(lastptdef > firstptdef && (isNaN(srcPos[lastptdef]) || isNaN(srcPos[lastptdef + 1]))) {\n                        lastptdef -= 2;\n                    }\n                    lineOptions.positions = srcPos.slice(firstptdef, lastptdef + 2);\n                }\n                return lineOptions;\n            });\n            scene.line2d.update(scene.lineOptions);\n        }\n        if(scene.error2d) {\n            var errorBatch = (scene.errorXOptions || []).concat(scene.errorYOptions || []);\n            scene.error2d.update(errorBatch);\n        }\n        if(scene.scatter2d) {\n            scene.scatter2d.update(scene.markerOptions);\n        }\n\n        // fill requires linked traces, so we generate it's positions here\n        scene.fillOrder = Lib.repeat(null, count);\n        if(scene.fill2d) {\n            scene.fillOptions = scene.fillOptions.map(function(fillOptions, i) {\n                var cdscatter = cdata[i];\n                if(!fillOptions || !cdscatter || !cdscatter[0] || !cdscatter[0].trace) return;\n                var cd = cdscatter[0];\n                var trace = cd.trace;\n                var stash = cd.t;\n                var lineOptions = scene.lineOptions[i];\n                var last, j;\n\n                var fillData = [];\n                if(trace._ownfill) fillData.push(i);\n                if(trace._nexttrace) fillData.push(i + 1);\n                if(fillData.length) scene.fillOrder[i] = fillData;\n\n                var pos = [];\n                var srcPos = (lineOptions && lineOptions.positions) || stash.positions;\n                var firstptdef, lastptdef;\n\n                if(trace.fill === 'tozeroy') {\n                    firstptdef = 0;\n                    while(firstptdef < srcPos.length && isNaN(srcPos[firstptdef + 1])) {\n                        firstptdef += 2;\n                    }\n                    lastptdef = srcPos.length - 2;\n                    while(lastptdef > firstptdef && isNaN(srcPos[lastptdef + 1])) {\n                        lastptdef -= 2;\n                    }\n                    if(srcPos[firstptdef + 1] !== 0) {\n                        pos = [srcPos[firstptdef], 0];\n                    }\n                    pos = pos.concat(srcPos.slice(firstptdef, lastptdef + 2));\n                    if(srcPos[lastptdef + 1] !== 0) {\n                        pos = pos.concat([srcPos[lastptdef], 0]);\n                    }\n                } else if(trace.fill === 'tozerox') {\n                    firstptdef = 0;\n                    while(firstptdef < srcPos.length && isNaN(srcPos[firstptdef])) {\n                        firstptdef += 2;\n                    }\n                    lastptdef = srcPos.length - 2;\n                    while(lastptdef > firstptdef && isNaN(srcPos[lastptdef])) {\n                        lastptdef -= 2;\n                    }\n                    if(srcPos[firstptdef] !== 0) {\n                        pos = [0, srcPos[firstptdef + 1]];\n                    }\n                    pos = pos.concat(srcPos.slice(firstptdef, lastptdef + 2));\n                    if(srcPos[lastptdef] !== 0) {\n                        pos = pos.concat([ 0, srcPos[lastptdef + 1]]);\n                    }\n                } else if(trace.fill === 'toself' || trace.fill === 'tonext') {\n                    pos = [];\n                    last = 0;\n                    for(j = 0; j < srcPos.length; j += 2) {\n                        if(isNaN(srcPos[j]) || isNaN(srcPos[j + 1])) {\n                            pos = pos.concat(srcPos.slice(last, j));\n                            pos.push(srcPos[last], srcPos[last + 1]);\n                            last = j + 2;\n                        }\n                    }\n                    pos = pos.concat(srcPos.slice(last));\n                    if(last) {\n                        pos.push(srcPos[last], srcPos[last + 1]);\n                    }\n                } else {\n                    var nextTrace = trace._nexttrace;\n\n                    if(nextTrace) {\n                        var nextOptions = scene.lineOptions[i + 1];\n\n                        if(nextOptions) {\n                            var nextPos = nextOptions.positions;\n                            if(trace.fill === 'tonexty') {\n                                pos = srcPos.slice();\n\n                                for(i = Math.floor(nextPos.length / 2); i--;) {\n                                    var xx = nextPos[i * 2];\n                                    var yy = nextPos[i * 2 + 1];\n                                    if(isNaN(xx) || isNaN(yy)) continue;\n                                    pos.push(xx, yy);\n                                }\n                                fillOptions.fill = nextTrace.fillcolor;\n                            }\n                        }\n                    }\n                }\n\n                // detect prev trace positions to exclude from current fill\n                if(trace._prevtrace && trace._prevtrace.fill === 'tonext') {\n                    var prevLinePos = scene.lineOptions[i - 1].positions;\n\n                    // FIXME: likely this logic should be tested better\n                    var offset = pos.length / 2;\n                    last = offset;\n                    var hole = [last];\n                    for(j = 0; j < prevLinePos.length; j += 2) {\n                        if(isNaN(prevLinePos[j]) || isNaN(prevLinePos[j + 1])) {\n                            hole.push(j / 2 + offset + 1);\n                            last = j + 2;\n                        }\n                    }\n\n                    pos = pos.concat(prevLinePos);\n                    fillOptions.hole = hole;\n                }\n                fillOptions.fillmode = trace.fill;\n                fillOptions.opacity = trace.opacity;\n                fillOptions.positions = pos;\n\n                return fillOptions;\n            });\n\n            scene.fill2d.update(scene.fillOptions);\n        }\n    }\n\n    // form batch arrays, and check for selected points\n    var dragmode = fullLayout.dragmode;\n    var selectMode = dragmode === 'lasso' || dragmode === 'select';\n    var clickSelectEnabled = fullLayout.clickmode.indexOf('select') > -1;\n\n    for(i = 0; i < count; i++) {\n        var cd0 = cdata[i][0];\n        var trace = cd0.trace;\n        var stash = cd0.t;\n        var index = stash.index;\n        var len = trace._length;\n        var x = stash.x;\n        var y = stash.y;\n\n        if(trace.selectedpoints || selectMode || clickSelectEnabled) {\n            if(!selectMode) selectMode = true;\n\n            // regenerate scene batch, if traces number changed during selection\n            if(trace.selectedpoints) {\n                var selPts = scene.selectBatch[index] = Lib.selIndices2selPoints(trace);\n\n                var selDict = {};\n                for(j = 0; j < selPts.length; j++) {\n                    selDict[selPts[j]] = 1;\n                }\n                var unselPts = [];\n                for(j = 0; j < len; j++) {\n                    if(!selDict[j]) unselPts.push(j);\n                }\n                scene.unselectBatch[index] = unselPts;\n            }\n\n            // precalculate px coords since we are not going to pan during select\n            // TODO, could do better here e.g.\n            // - spin that in a webworker\n            // - compute selection from polygons in data coordinates\n            //   (maybe just for linear axes)\n            var xpx = stash.xpx = new Array(len);\n            var ypx = stash.ypx = new Array(len);\n            for(j = 0; j < len; j++) {\n                xpx[j] = xaxis.c2p(x[j]);\n                ypx[j] = yaxis.c2p(y[j]);\n            }\n        } else {\n            stash.xpx = stash.ypx = null;\n        }\n    }\n\n    if(selectMode) {\n        // create scatter instance by cloning scatter2d\n        if(!scene.select2d) {\n            scene.select2d = createScatter(fullLayout._glcanvas.data()[1].regl);\n        }\n\n        // use unselected styles on 'context' canvas\n        if(scene.scatter2d) {\n            var unselOpts = new Array(count);\n            for(i = 0; i < count; i++) {\n                unselOpts[i] = scene.selectBatch[i].length || scene.unselectBatch[i].length ?\n                    scene.markerUnselectedOptions[i] :\n                    {};\n            }\n            scene.scatter2d.update(unselOpts);\n        }\n\n        // use selected style on 'focus' canvas\n        if(scene.select2d) {\n            scene.select2d.update(scene.markerOptions);\n            scene.select2d.update(scene.markerSelectedOptions);\n        }\n\n        if(scene.glText) {\n            cdata.forEach(function(cdscatter) {\n                var trace = ((cdscatter || [])[0] || {}).trace || {};\n                if(subTypes.hasText(trace)) {\n                    styleTextSelection(cdscatter);\n                }\n            });\n        }\n    } else {\n        // reset 'context' scatter2d opts to base opts,\n        // thus unsetting markerUnselectedOptions from selection\n        if(scene.scatter2d) {\n            scene.scatter2d.update(scene.markerOptions);\n        }\n    }\n\n    // provide viewport and range\n    var vpRange0 = {\n        viewport: getViewport(fullLayout, xaxis, yaxis),\n        // TODO do we need those fallbacks?\n        range: [\n            (xaxis._rl || xaxis.range)[0],\n            (yaxis._rl || yaxis.range)[0],\n            (xaxis._rl || xaxis.range)[1],\n            (yaxis._rl || yaxis.range)[1]\n        ]\n    };\n    var vpRange = Lib.repeat(vpRange0, scene.count);\n\n    // upload viewport/range data to GPU\n    if(scene.fill2d) {\n        scene.fill2d.update(vpRange);\n    }\n    if(scene.line2d) {\n        scene.line2d.update(vpRange);\n    }\n    if(scene.error2d) {\n        scene.error2d.update(vpRange.concat(vpRange));\n    }\n    if(scene.scatter2d) {\n        scene.scatter2d.update(vpRange);\n    }\n    if(scene.select2d) {\n        scene.select2d.update(vpRange);\n    }\n    if(scene.glText) {\n        scene.glText.forEach(function(text) { text.update(vpRange0); });\n    }\n};\n\n},{\"../../lib\":719,\"../../lib/prepare_regl\":732,\"../scatter/link_traces\":1127,\"../scatter/subtypes\":1135,\"./edit_style\":1165,\"gl-text\":317,\"regl-error2d\":490,\"regl-line2d\":491,\"regl-scatter2d\":497}],1169:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n// make sure scene exists on subplot, return it\nmodule.exports = function sceneUpdate(gd, subplot) {\n    var scene = subplot._scene;\n\n    var resetOpts = {\n        // number of traces in subplot, since scene:subplot -> 1:1\n        count: 0,\n        // whether scene requires init hook in plot call (dirty plot call)\n        dirty: true,\n        // last used options\n        lineOptions: [],\n        fillOptions: [],\n        markerOptions: [],\n        markerSelectedOptions: [],\n        markerUnselectedOptions: [],\n        errorXOptions: [],\n        errorYOptions: [],\n        textOptions: [],\n        textSelectedOptions: [],\n        textUnselectedOptions: [],\n        // selection batches\n        selectBatch: [],\n        unselectBatch: []\n    };\n\n    // regl- component stubs, initialized in dirty plot call\n    var initOpts = {\n        fill2d: false,\n        scatter2d: false,\n        error2d: false,\n        line2d: false,\n        glText: false,\n        select2d: false\n    };\n\n    if(!subplot._scene) {\n        scene = subplot._scene = {};\n\n        scene.init = function init() {\n            Lib.extendFlat(scene, initOpts, resetOpts);\n        };\n\n        scene.init();\n\n        // apply new option to all regl components (used on drag)\n        scene.update = function update(opt) {\n            var opts = Lib.repeat(opt, scene.count);\n\n            if(scene.fill2d) scene.fill2d.update(opts);\n            if(scene.scatter2d) scene.scatter2d.update(opts);\n            if(scene.line2d) scene.line2d.update(opts);\n            if(scene.error2d) scene.error2d.update(opts.concat(opts));\n            if(scene.select2d) scene.select2d.update(opts);\n            if(scene.glText) {\n                for(var i = 0; i < scene.count; i++) {\n                    scene.glText[i].update(opt);\n                }\n            }\n        };\n\n        // draw traces in proper order\n        scene.draw = function draw() {\n            var count = scene.count;\n            var fill2d = scene.fill2d;\n            var error2d = scene.error2d;\n            var line2d = scene.line2d;\n            var scatter2d = scene.scatter2d;\n            var glText = scene.glText;\n            var select2d = scene.select2d;\n            var selectBatch = scene.selectBatch;\n            var unselectBatch = scene.unselectBatch;\n\n            for(var i = 0; i < count; i++) {\n                if(fill2d && scene.fillOrder[i]) {\n                    fill2d.draw(scene.fillOrder[i]);\n                }\n                if(line2d && scene.lineOptions[i]) {\n                    line2d.draw(i);\n                }\n                if(error2d) {\n                    if(scene.errorXOptions[i]) error2d.draw(i);\n                    if(scene.errorYOptions[i]) error2d.draw(i + count);\n                }\n                if(scatter2d && scene.markerOptions[i]) {\n                    if(unselectBatch[i].length) {\n                        var arg = Lib.repeat([], scene.count);\n                        arg[i] = unselectBatch[i];\n                        scatter2d.draw(arg);\n                    } else if(!selectBatch[i].length) {\n                        scatter2d.draw(i);\n                    }\n                }\n                if(glText[i] && scene.textOptions[i]) {\n                    glText[i].render();\n                }\n            }\n\n            if(select2d) {\n                select2d.draw(selectBatch);\n            }\n\n            scene.dirty = false;\n        };\n\n        // remove scene resources\n        scene.destroy = function destroy() {\n            if(scene.fill2d && scene.fill2d.destroy) scene.fill2d.destroy();\n            if(scene.scatter2d && scene.scatter2d.destroy) scene.scatter2d.destroy();\n            if(scene.error2d && scene.error2d.destroy) scene.error2d.destroy();\n            if(scene.line2d && scene.line2d.destroy) scene.line2d.destroy();\n            if(scene.select2d && scene.select2d.destroy) scene.select2d.destroy();\n            if(scene.glText) {\n                scene.glText.forEach(function(text) {\n                    if(text.destroy) text.destroy();\n                });\n            }\n\n            scene.lineOptions = null;\n            scene.fillOptions = null;\n            scene.markerOptions = null;\n            scene.markerSelectedOptions = null;\n            scene.markerUnselectedOptions = null;\n            scene.errorXOptions = null;\n            scene.errorYOptions = null;\n            scene.textOptions = null;\n            scene.textSelectedOptions = null;\n            scene.textUnselectedOptions = null;\n\n            scene.selectBatch = null;\n            scene.unselectBatch = null;\n\n            // we can't just delete _scene, because `destroy` is called in the\n            // middle of supplyDefaults, before relinkPrivateKeys which will put it back.\n            subplot._scene = null;\n        };\n    }\n\n    // in case if we have scene from the last calc - reset data\n    if(!scene.dirty) {\n        Lib.extendFlat(scene, resetOpts);\n    }\n\n    return scene;\n};\n\n},{\"../../lib\":719}],1170:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar subTypes = _dereq_('../scatter/subtypes');\nvar styleTextSelection = _dereq_('./edit_style').styleTextSelection;\n\nmodule.exports = function select(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var selection = [];\n    var trace = cd[0].trace;\n    var stash = cd[0].t;\n    var len = trace._length;\n    var x = stash.x;\n    var y = stash.y;\n    var scene = stash._scene;\n    var index = stash.index;\n\n    if(!scene) return selection;\n\n    var hasText = subTypes.hasText(trace);\n    var hasMarkers = subTypes.hasMarkers(trace);\n    var hasOnlyLines = !hasMarkers && !hasText;\n\n    if(trace.visible !== true || hasOnlyLines) return selection;\n\n    var els = [];\n    var unels = [];\n\n    // degenerate polygon does not enable selection\n    // filter out points by visible scatter ones\n    if(selectionTester !== false && !selectionTester.degenerate) {\n        for(var i = 0; i < len; i++) {\n            if(selectionTester.contains([stash.xpx[i], stash.ypx[i]], false, i, searchInfo)) {\n                els.push(i);\n                selection.push({\n                    pointNumber: i,\n                    x: x[i],\n                    y: y[i]\n                });\n            } else {\n                unels.push(i);\n            }\n        }\n    }\n\n    if(hasMarkers) {\n        var scatter2d = scene.scatter2d;\n\n        if(!els.length && !unels.length) {\n            // reset to base styles when clearing\n            var baseOpts = new Array(scene.count);\n            baseOpts[index] = scene.markerOptions[index];\n            scatter2d.update.apply(scatter2d, baseOpts);\n        } else if(!scene.selectBatch[index].length && !scene.unselectBatch[index].length) {\n            // set unselected styles on 'context' canvas (if not done already)\n            var unselOpts = new Array(scene.count);\n            unselOpts[index] = scene.markerUnselectedOptions[index];\n            scatter2d.update.apply(scatter2d, unselOpts);\n        }\n    }\n\n    scene.selectBatch[index] = els;\n    scene.unselectBatch[index] = unels;\n\n    if(hasText) {\n        styleTextSelection(cd);\n    }\n\n    return selection;\n};\n\n},{\"../scatter/subtypes\":1135,\"./edit_style\":1165}],1171:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar scatterGeoAttrs = _dereq_('../scattergeo/attributes');\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar mapboxAttrs = _dereq_('../../plots/mapbox/layout_attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar lineAttrs = scatterGeoAttrs.line;\nvar markerAttrs = scatterGeoAttrs.marker;\n\nmodule.exports = overrideAll({\n    lon: scatterGeoAttrs.lon,\n    lat: scatterGeoAttrs.lat,\n\n    // locations\n    // locationmode\n\n    mode: extendFlat({}, scatterAttrs.mode, {\n        dflt: 'markers',\n        \n    }),\n\n    text: extendFlat({}, scatterAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, scatterAttrs.hovertext, {\n        \n    }),\n\n    line: {\n        color: lineAttrs.color,\n        width: lineAttrs.width\n\n        // TODO\n        // dash: dash\n    },\n\n    connectgaps: scatterAttrs.connectgaps,\n\n    marker: extendFlat({\n        symbol: {\n            valType: 'string',\n            dflt: 'circle',\n            \n            arrayOk: true,\n            \n        },\n        opacity: markerAttrs.opacity,\n        size: markerAttrs.size,\n        sizeref: markerAttrs.sizeref,\n        sizemin: markerAttrs.sizemin,\n        sizemode: markerAttrs.sizemode\n    },\n        colorScaleAttrs('marker')\n        // line\n    ),\n\n    fill: scatterGeoAttrs.fill,\n    fillcolor: scatterAttrs.fillcolor,\n\n    textfont: mapboxAttrs.layers.symbol.textfont,\n    textposition: mapboxAttrs.layers.symbol.textposition,\n\n    below: {\n        valType: 'string',\n        \n        \n    },\n\n    selected: {\n        marker: scatterAttrs.selected.marker\n    },\n    unselected: {\n        marker: scatterAttrs.unselected.marker\n    },\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['lon', 'lat', 'text', 'name']\n    }),\n    hovertemplate: hovertemplateAttrs(),\n}, 'calc', 'nested');\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/attributes\":764,\"../../plots/mapbox/layout_attributes\":824,\"../scatter/attributes\":1112,\"../scattergeo/attributes\":1151}],1172:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\nvar geoJsonUtils = _dereq_('../../lib/geojson_utils');\n\nvar Colorscale = _dereq_('../../components/colorscale');\nvar Drawing = _dereq_('../../components/drawing');\nvar makeBubbleSizeFn = _dereq_('../scatter/make_bubble_size_func');\nvar subTypes = _dereq_('../scatter/subtypes');\nvar convertTextOpts = _dereq_('../../plots/mapbox/convert_text_opts');\n\nmodule.exports = function convert(calcTrace) {\n    var trace = calcTrace[0].trace;\n\n    var isVisible = (trace.visible === true && trace._length !== 0);\n    var hasFill = (trace.fill !== 'none');\n    var hasLines = subTypes.hasLines(trace);\n    var hasMarkers = subTypes.hasMarkers(trace);\n    var hasText = subTypes.hasText(trace);\n    var hasCircles = (hasMarkers && trace.marker.symbol === 'circle');\n    var hasSymbols = (hasMarkers && trace.marker.symbol !== 'circle');\n\n    var fill = initContainer();\n    var line = initContainer();\n    var circle = initContainer();\n    var symbol = initContainer();\n\n    var opts = {\n        fill: fill,\n        line: line,\n        circle: circle,\n        symbol: symbol\n    };\n\n    // early return if not visible or placeholder\n    if(!isVisible) return opts;\n\n    // fill layer and line layer use the same coords\n    var lineCoords;\n    if(hasFill || hasLines) {\n        lineCoords = geoJsonUtils.calcTraceToLineCoords(calcTrace);\n    }\n\n    if(hasFill) {\n        fill.geojson = geoJsonUtils.makePolygon(lineCoords);\n        fill.layout.visibility = 'visible';\n\n        Lib.extendFlat(fill.paint, {\n            'fill-color': trace.fillcolor\n        });\n    }\n\n    if(hasLines) {\n        line.geojson = geoJsonUtils.makeLine(lineCoords);\n        line.layout.visibility = 'visible';\n\n        Lib.extendFlat(line.paint, {\n            'line-width': trace.line.width,\n            'line-color': trace.line.color,\n            'line-opacity': trace.opacity\n        });\n\n        // TODO convert line.dash into line-dasharray\n    }\n\n    if(hasCircles) {\n        var circleOpts = makeCircleOpts(calcTrace);\n        circle.geojson = circleOpts.geojson;\n        circle.layout.visibility = 'visible';\n\n        Lib.extendFlat(circle.paint, {\n            'circle-color': circleOpts.mcc,\n            'circle-radius': circleOpts.mrc,\n            'circle-opacity': circleOpts.mo\n        });\n    }\n\n    if(hasSymbols || hasText) {\n        symbol.geojson = makeSymbolGeoJSON(calcTrace);\n\n        Lib.extendFlat(symbol.layout, {\n            visibility: 'visible',\n            'icon-image': '{symbol}-15',\n            'text-field': '{text}'\n        });\n\n        if(hasSymbols) {\n            Lib.extendFlat(symbol.layout, {\n                'icon-size': trace.marker.size / 10\n            });\n\n            Lib.extendFlat(symbol.paint, {\n                'icon-opacity': trace.opacity * trace.marker.opacity,\n\n                // TODO does not work ??\n                'icon-color': trace.marker.color\n            });\n        }\n\n        if(hasText) {\n            var iconSize = (trace.marker || {}).size;\n            var textOpts = convertTextOpts(trace.textposition, iconSize);\n\n            // all data-driven below !!\n\n            Lib.extendFlat(symbol.layout, {\n                'text-size': trace.textfont.size,\n                'text-anchor': textOpts.anchor,\n                'text-offset': textOpts.offset\n\n                // TODO font family\n                // 'text-font': symbol.textfont.family.split(', '),\n            });\n\n            Lib.extendFlat(symbol.paint, {\n                'text-color': trace.textfont.color,\n                'text-opacity': trace.opacity\n            });\n        }\n    }\n\n    return opts;\n};\n\nfunction initContainer() {\n    return {\n        geojson: geoJsonUtils.makeBlank(),\n        layout: { visibility: 'none' },\n        paint: {}\n    };\n}\n\nfunction makeCircleOpts(calcTrace) {\n    var trace = calcTrace[0].trace;\n    var marker = trace.marker;\n    var selectedpoints = trace.selectedpoints;\n    var arrayColor = Lib.isArrayOrTypedArray(marker.color);\n    var arraySize = Lib.isArrayOrTypedArray(marker.size);\n    var arrayOpacity = Lib.isArrayOrTypedArray(marker.opacity);\n    var i;\n\n    function addTraceOpacity(o) { return trace.opacity * o; }\n\n    function size2radius(s) { return s / 2; }\n\n    var colorFn;\n    if(arrayColor) {\n        if(Colorscale.hasColorscale(trace, 'marker')) {\n            colorFn = Colorscale.makeColorScaleFuncFromTrace(marker);\n        } else {\n            colorFn = Lib.identity;\n        }\n    }\n\n    var sizeFn;\n    if(arraySize) {\n        sizeFn = makeBubbleSizeFn(trace);\n    }\n\n    var opacityFn;\n    if(arrayOpacity) {\n        opacityFn = function(mo) {\n            var mo2 = isNumeric(mo) ? +Lib.constrain(mo, 0, 1) : 0;\n            return addTraceOpacity(mo2);\n        };\n    }\n\n    var features = [];\n    for(i = 0; i < calcTrace.length; i++) {\n        var calcPt = calcTrace[i];\n        var lonlat = calcPt.lonlat;\n\n        if(isBADNUM(lonlat)) continue;\n\n        var props = {};\n        if(colorFn) props.mcc = calcPt.mcc = colorFn(calcPt.mc);\n        if(sizeFn) props.mrc = calcPt.mrc = sizeFn(calcPt.ms);\n        if(opacityFn) props.mo = opacityFn(calcPt.mo);\n        if(selectedpoints) props.selected = calcPt.selected || 0;\n\n        features.push({\n            type: 'Feature',\n            geometry: {type: 'Point', coordinates: lonlat},\n            properties: props\n        });\n    }\n\n    var fns;\n    if(selectedpoints) {\n        fns = Drawing.makeSelectedPointStyleFns(trace);\n\n        for(i = 0; i < features.length; i++) {\n            var d = features[i].properties;\n\n            if(fns.selectedOpacityFn) {\n                d.mo = addTraceOpacity(fns.selectedOpacityFn(d));\n            }\n            if(fns.selectedColorFn) {\n                d.mcc = fns.selectedColorFn(d);\n            }\n            if(fns.selectedSizeFn) {\n                d.mrc = fns.selectedSizeFn(d);\n            }\n        }\n    }\n\n    return {\n        geojson: {type: 'FeatureCollection', features: features},\n        mcc: arrayColor || (fns && fns.selectedColorFn) ?\n            {type: 'identity', property: 'mcc'} :\n            marker.color,\n        mrc: arraySize || (fns && fns.selectedSizeFn) ?\n            {type: 'identity', property: 'mrc'} :\n            size2radius(marker.size),\n        mo: arrayOpacity || (fns && fns.selectedOpacityFn) ?\n            {type: 'identity', property: 'mo'} :\n            addTraceOpacity(marker.opacity)\n    };\n}\n\nfunction makeSymbolGeoJSON(calcTrace) {\n    var trace = calcTrace[0].trace;\n\n    var marker = trace.marker || {};\n    var symbol = marker.symbol;\n    var text = trace.text;\n\n    var fillSymbol = (symbol !== 'circle') ?\n        getFillFunc(symbol) :\n        blankFillFunc;\n\n    var fillText = subTypes.hasText(trace) ?\n        getFillFunc(text) :\n        blankFillFunc;\n\n    var features = [];\n\n    for(var i = 0; i < calcTrace.length; i++) {\n        var calcPt = calcTrace[i];\n\n        if(isBADNUM(calcPt.lonlat)) continue;\n\n        features.push({\n            type: 'Feature',\n            geometry: {\n                type: 'Point',\n                coordinates: calcPt.lonlat\n            },\n            properties: {\n                symbol: fillSymbol(calcPt.mx),\n                text: fillText(calcPt.tx)\n            }\n        });\n    }\n\n    return {\n        type: 'FeatureCollection',\n        features: features\n    };\n}\n\nfunction getFillFunc(attr) {\n    if(Lib.isArrayOrTypedArray(attr)) {\n        return function(v) { return v; };\n    } else if(attr) {\n        return function() { return attr; };\n    } else {\n        return blankFillFunc;\n    }\n}\n\nfunction blankFillFunc() { return ''; }\n\n// only need to check lon (OR lat)\nfunction isBADNUM(lonlat) {\n    return lonlat[0] === BADNUM;\n}\n\n},{\"../../components/colorscale\":605,\"../../components/drawing\":614,\"../../constants/numerical\":695,\"../../lib\":719,\"../../lib/geojson_utils\":714,\"../../plots/mapbox/convert_text_opts\":821,\"../scatter/make_bubble_size_func\":1128,\"../scatter/subtypes\":1135,\"fast-isnumeric\":225}],1173:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar handleLineDefaults = _dereq_('../scatter/line_defaults');\nvar handleTextDefaults = _dereq_('../scatter/text_defaults');\nvar handleFillColorDefaults = _dereq_('../scatter/fillcolor_defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleLonLatDefaults(traceIn, traceOut, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n    coerce('mode');\n    coerce('below');\n\n    if(subTypes.hasLines(traceOut)) {\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noDash: true});\n        coerce('connectgaps');\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {noLine: true});\n\n        // array marker.size and marker.color are only supported with circles\n        var marker = traceOut.marker;\n        if(marker.symbol !== 'circle') {\n            if(Lib.isArrayOrTypedArray(marker.size)) marker.size = marker.size[0];\n            if(Lib.isArrayOrTypedArray(marker.color)) marker.color = marker.color[0];\n        }\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce, {noSelect: true});\n    }\n\n    coerce('fill');\n    if(traceOut.fill !== 'none') {\n        handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);\n    }\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\nfunction handleLonLatDefaults(traceIn, traceOut, coerce) {\n    var lon = coerce('lon') || [];\n    var lat = coerce('lat') || [];\n    var len = Math.min(lon.length, lat.length);\n    traceOut._length = len;\n\n    return len;\n}\n\n},{\"../../lib\":719,\"../scatter/fillcolor_defaults\":1120,\"../scatter/line_defaults\":1124,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"../scatter/text_defaults\":1136,\"./attributes\":1171}],1174:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\n\nmodule.exports = function eventData(out, pt) {\n    out.lon = pt.lon;\n    out.lat = pt.lat;\n\n    return out;\n};\n\n},{}],1175:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Fx = _dereq_('../../components/fx');\nvar Lib = _dereq_('../../lib');\nvar getTraceColor = _dereq_('../scatter/get_trace_color');\nvar fillText = Lib.fillText;\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function hoverPoints(pointData, xval, yval) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var subplot = pointData.subplot;\n\n    // compute winding number about [-180, 180] globe\n    var winding = (xval >= 0) ?\n        Math.floor((xval + 180) / 360) :\n        Math.ceil((xval - 180) / 360);\n\n    // shift longitude to [-180, 180] to determine closest point\n    var lonShift = winding * 360;\n    var xval2 = xval - lonShift;\n\n    function distFn(d) {\n        var lonlat = d.lonlat;\n        if(lonlat[0] === BADNUM) return Infinity;\n\n        var lon = Lib.modHalf(lonlat[0], 360);\n        var lat = lonlat[1];\n        var pt = subplot.project([lon, lat]);\n        var dx = pt.x - xa.c2p([xval2, lat]);\n        var dy = pt.y - ya.c2p([lon, yval]);\n        var rad = Math.max(3, d.mrc || 0);\n\n        return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - 3 / rad);\n    }\n\n    Fx.getClosest(cd, distFn, pointData);\n\n    // skip the rest (for this trace) if we didn't find a close point\n    if(pointData.index === false) return;\n\n    var di = cd[pointData.index];\n    var lonlat = di.lonlat;\n    var lonlatShifted = [Lib.modHalf(lonlat[0], 360) + lonShift, lonlat[1]];\n\n    // shift labels back to original winded globe\n    var xc = xa.c2p(lonlatShifted);\n    var yc = ya.c2p(lonlatShifted);\n    var rad = di.mrc || 1;\n\n    pointData.x0 = xc - rad;\n    pointData.x1 = xc + rad;\n    pointData.y0 = yc - rad;\n    pointData.y1 = yc + rad;\n\n    pointData.color = getTraceColor(trace, di);\n    pointData.extraText = getExtraText(trace, di, cd[0].t.labels);\n    pointData.hovertemplate = trace.hovertemplate;\n\n    return [pointData];\n};\n\nfunction getExtraText(trace, di, labels) {\n    if(trace.hovertemplate) {\n        return;\n    }\n\n    var hoverinfo = di.hi || trace.hoverinfo;\n    var parts = hoverinfo.split('+');\n    var isAll = parts.indexOf('all') !== -1;\n    var hasLon = parts.indexOf('lon') !== -1;\n    var hasLat = parts.indexOf('lat') !== -1;\n    var lonlat = di.lonlat;\n    var text = [];\n\n    // TODO should we use a mock axis to format hover?\n    // If so, we'll need to make precision be zoom-level dependent\n    function format(v) {\n        return v + '\\u00B0';\n    }\n\n    if(isAll || (hasLon && hasLat)) {\n        text.push('(' + format(lonlat[0]) + ', ' + format(lonlat[1]) + ')');\n    } else if(hasLon) {\n        text.push(labels.lon + format(lonlat[0]));\n    } else if(hasLat) {\n        text.push(labels.lat + format(lonlat[1]));\n    }\n\n    if(isAll || parts.indexOf('text') !== -1) {\n        fillText(di, trace, text);\n    }\n\n    return text.join('<br>');\n}\n\n},{\"../../components/fx\":632,\"../../constants/numerical\":695,\"../../lib\":719,\"../scatter/get_trace_color\":1121}],1176:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n    calc: _dereq_('../scattergeo/calc'),\n    plot: _dereq_('./plot'),\n    hoverPoints: _dereq_('./hover'),\n    eventData: _dereq_('./event_data'),\n    selectPoints: _dereq_('./select'),\n\n    styleOnSelect: function(_, cd) {\n        if(cd) {\n            var trace = cd[0].trace;\n            trace._glTrace.update(cd);\n        }\n    },\n\n    moduleType: 'trace',\n    name: 'scattermapbox',\n    basePlotModule: _dereq_('../../plots/mapbox'),\n    categories: ['mapbox', 'gl', 'symbols', 'showLegend', 'scatterlike'],\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/mapbox\":822,\"../scatter/marker_colorbar\":1129,\"../scattergeo/calc\":1152,\"./attributes\":1171,\"./defaults\":1173,\"./event_data\":1174,\"./hover\":1175,\"./plot\":1177,\"./select\":1178}],1177:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar convert = _dereq_('./convert');\nvar LAYER_PREFIX = _dereq_('../../plots/mapbox/constants').traceLayerPrefix;\nvar ORDER = ['fill', 'line', 'circle', 'symbol'];\n\nfunction ScatterMapbox(subplot, uid) {\n    this.subplot = subplot;\n    this.uid = uid;\n\n    this.sourceIds = {\n        fill: 'source-' + uid + '-fill',\n        line: 'source-' + uid + '-line',\n        circle: 'source-' + uid + '-circle',\n        symbol: 'source-' + uid + '-symbol'\n    };\n\n    this.layerIds = {\n        fill: LAYER_PREFIX + uid + '-fill',\n        line: LAYER_PREFIX + uid + '-line',\n        circle: LAYER_PREFIX + uid + '-circle',\n        symbol: LAYER_PREFIX + uid + '-symbol'\n    };\n\n    // We could merge the 'fill' source with the 'line' source and\n    // the 'circle' source with the 'symbol' source if ever having\n    // for up-to 4 sources per 'scattermapbox' traces becomes a problem.\n\n    // previous 'below' value,\n    // need this to update it properly\n    this.below = null;\n}\n\nvar proto = ScatterMapbox.prototype;\n\nproto.addSource = function(k, opts) {\n    this.subplot.map.addSource(this.sourceIds[k], {\n        type: 'geojson',\n        data: opts.geojson\n    });\n};\n\nproto.setSourceData = function(k, opts) {\n    this.subplot.map\n        .getSource(this.sourceIds[k])\n        .setData(opts.geojson);\n};\n\nproto.addLayer = function(k, opts, below) {\n    this.subplot.addLayer({\n        type: k,\n        id: this.layerIds[k],\n        source: this.sourceIds[k],\n        layout: opts.layout,\n        paint: opts.paint\n    }, below);\n};\n\nproto.update = function update(calcTrace) {\n    var subplot = this.subplot;\n    var map = subplot.map;\n    var optsAll = convert(calcTrace);\n    var below = subplot.belowLookup['trace-' + this.uid];\n    var i, k, opts;\n\n    if(below !== this.below) {\n        for(i = ORDER.length - 1; i >= 0; i--) {\n            k = ORDER[i];\n            map.removeLayer(this.layerIds[k]);\n        }\n        for(i = 0; i < ORDER.length; i++) {\n            k = ORDER[i];\n            opts = optsAll[k];\n            this.addLayer(k, opts, below);\n        }\n        this.below = below;\n    }\n\n    for(i = 0; i < ORDER.length; i++) {\n        k = ORDER[i];\n        opts = optsAll[k];\n\n        subplot.setOptions(this.layerIds[k], 'setLayoutProperty', opts.layout);\n\n        if(opts.layout.visibility === 'visible') {\n            this.setSourceData(k, opts);\n            subplot.setOptions(this.layerIds[k], 'setPaintProperty', opts.paint);\n        }\n    }\n\n    // link ref for quick update during selections\n    calcTrace[0].trace._glTrace = this;\n};\n\nproto.dispose = function dispose() {\n    var map = this.subplot.map;\n\n    for(var i = ORDER.length - 1; i >= 0; i--) {\n        var k = ORDER[i];\n        map.removeLayer(this.layerIds[k]);\n        map.removeSource(this.sourceIds[k]);\n    }\n};\n\nmodule.exports = function createScatterMapbox(subplot, calcTrace) {\n    var trace = calcTrace[0].trace;\n    var scatterMapbox = new ScatterMapbox(subplot, trace.uid);\n    var optsAll = convert(calcTrace);\n    var below = scatterMapbox.below = subplot.belowLookup['trace-' + trace.uid];\n\n    for(var i = 0; i < ORDER.length; i++) {\n        var k = ORDER[i];\n        var opts = optsAll[k];\n        scatterMapbox.addSource(k, opts);\n        scatterMapbox.addLayer(k, opts, below);\n    }\n\n    // link ref for quick update during selections\n    calcTrace[0].trace._glTrace = scatterMapbox;\n\n    return scatterMapbox;\n};\n\n},{\"../../plots/mapbox/constants\":820,\"./convert\":1172}],1178:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar subtypes = _dereq_('../scatter/subtypes');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function selectPoints(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var xa = searchInfo.xaxis;\n    var ya = searchInfo.yaxis;\n    var selection = [];\n    var trace = cd[0].trace;\n    var i;\n\n    if(!subtypes.hasMarkers(trace)) return [];\n\n    if(selectionTester === false) {\n        for(i = 0; i < cd.length; i++) {\n            cd[i].selected = 0;\n        }\n    } else {\n        for(i = 0; i < cd.length; i++) {\n            var di = cd[i];\n            var lonlat = di.lonlat;\n\n            if(lonlat[0] !== BADNUM) {\n                var lonlat2 = [Lib.modHalf(lonlat[0], 360), lonlat[1]];\n                var xy = [xa.c2p(lonlat2), ya.c2p(lonlat2)];\n\n                if(selectionTester.contains(xy, null, i, searchInfo)) {\n                    selection.push({\n                        pointNumber: i,\n                        lon: lonlat[0],\n                        lat: lonlat[1]\n                    });\n                    di.selected = 1;\n                } else {\n                    di.selected = 0;\n                }\n            }\n        }\n    }\n\n    return selection;\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../scatter/subtypes\":1135}],1179:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar lineAttrs = scatterAttrs.line;\n\nmodule.exports = {\n    mode: scatterAttrs.mode,\n\n    r: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    theta: {\n        valType: 'data_array',\n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    r0: {\n        valType: 'any',\n        dflt: 0,\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    dr: {\n        valType: 'number',\n        dflt: 1,\n        \n        editType: 'calc',\n        \n    },\n\n    theta0: {\n        valType: 'any',\n        dflt: 0,\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    dtheta: {\n        valType: 'number',\n        \n        editType: 'calc',\n        \n    },\n\n    thetaunit: {\n        valType: 'enumerated',\n        values: ['radians', 'degrees', 'gradians'],\n        dflt: 'degrees',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    text: scatterAttrs.text,\n    hovertext: scatterAttrs.hovertext,\n\n    line: {\n        color: lineAttrs.color,\n        width: lineAttrs.width,\n        dash: lineAttrs.dash,\n        shape: extendFlat({}, lineAttrs.shape, {\n            values: ['linear', 'spline']\n        }),\n        smoothing: lineAttrs.smoothing,\n        editType: 'calc'\n    },\n    connectgaps: scatterAttrs.connectgaps,\n\n    marker: scatterAttrs.marker,\n    cliponaxis: extendFlat({}, scatterAttrs.cliponaxis, {dflt: false}),\n\n    textposition: scatterAttrs.textposition,\n    textfont: scatterAttrs.textfont,\n\n    fill: extendFlat({}, scatterAttrs.fill, {\n        values: ['none', 'toself', 'tonext'],\n        dflt: 'none',\n        \n    }),\n    fillcolor: scatterAttrs.fillcolor,\n\n    // TODO error bars\n    // https://stackoverflow.com/a/26597487/4068492\n    // error_x (error_r, error_theta)\n    // error_y\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['r', 'theta', 'text', 'name']\n    }),\n    hoveron: scatterAttrs.hoveron,\n    hovertemplate: hovertemplateAttrs(),\n\n    selected: scatterAttrs.selected,\n    unselected: scatterAttrs.unselected\n};\n\n},{\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../scatter/attributes\":1112}],1180:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\nvar calcColorscale = _dereq_('../scatter/colorscale_calc');\nvar arraysToCalcdata = _dereq_('../scatter/arrays_to_calcdata');\nvar calcSelection = _dereq_('../scatter/calc_selection');\nvar calcMarkerSize = _dereq_('../scatter/calc').calcMarkerSize;\n\nmodule.exports = function calc(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var subplotId = trace.subplot;\n    var radialAxis = fullLayout[subplotId].radialaxis;\n    var angularAxis = fullLayout[subplotId].angularaxis;\n    var rArray = radialAxis.makeCalcdata(trace, 'r');\n    var thetaArray = angularAxis.makeCalcdata(trace, 'theta');\n    var len = trace._length;\n    var cd = new Array(len);\n\n    for(var i = 0; i < len; i++) {\n        var r = rArray[i];\n        var theta = thetaArray[i];\n        var cdi = cd[i] = {};\n\n        if(isNumeric(r) && isNumeric(theta)) {\n            cdi.r = r;\n            cdi.theta = theta;\n        } else {\n            cdi.r = BADNUM;\n        }\n    }\n\n    var ppad = calcMarkerSize(trace, len);\n    trace._extremes.x = Axes.findExtremes(radialAxis, rArray, {ppad: ppad});\n\n    calcColorscale(gd, trace);\n    arraysToCalcdata(cd, trace);\n    calcSelection(cd, trace);\n\n    return cd;\n};\n\n},{\"../../constants/numerical\":695,\"../../plots/cartesian/axes\":767,\"../scatter/arrays_to_calcdata\":1111,\"../scatter/calc\":1113,\"../scatter/calc_selection\":1114,\"../scatter/colorscale_calc\":1115,\"fast-isnumeric\":225}],1181:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar handleLineDefaults = _dereq_('../scatter/line_defaults');\nvar handleLineShapeDefaults = _dereq_('../scatter/line_shape_defaults');\nvar handleTextDefaults = _dereq_('../scatter/text_defaults');\nvar handleFillColorDefaults = _dereq_('../scatter/fillcolor_defaults');\nvar PTS_LINESONLY = _dereq_('../scatter/constants').PTS_LINESONLY;\n\nvar attributes = _dereq_('./attributes');\n\nfunction supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleRThetaDefaults(traceIn, traceOut, layout, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('thetaunit');\n    coerce('mode', len < PTS_LINESONLY ? 'lines+markers' : 'lines');\n    coerce('text');\n    coerce('hovertext');\n    if(traceOut.hoveron !== 'fills') coerce('hovertemplate');\n\n    if(subTypes.hasLines(traceOut)) {\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n        handleLineShapeDefaults(traceIn, traceOut, coerce);\n        coerce('connectgaps');\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {gradient: true});\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce);\n    }\n\n    var dfltHoverOn = [];\n\n    if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {\n        coerce('cliponaxis');\n        coerce('marker.maxdisplayed');\n        dfltHoverOn.push('points');\n    }\n\n    coerce('fill');\n\n    if(traceOut.fill !== 'none') {\n        handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);\n        if(!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce);\n    }\n\n    if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {\n        dfltHoverOn.push('fills');\n    }\n    coerce('hoveron', dfltHoverOn.join('+') || 'points');\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n}\n\nfunction handleRThetaDefaults(traceIn, traceOut, layout, coerce) {\n    var r = coerce('r');\n    var theta = coerce('theta');\n    var len;\n\n    if(r) {\n        if(theta) {\n            len = Math.min(r.length, theta.length);\n        } else {\n            len = r.length;\n            coerce('theta0');\n            coerce('dtheta');\n        }\n    } else {\n        if(!theta) return 0;\n        len = traceOut.theta.length;\n        coerce('r0');\n        coerce('dr');\n    }\n\n    traceOut._length = len;\n    return len;\n}\n\nmodule.exports = {\n    handleRThetaDefaults: handleRThetaDefaults,\n    supplyDefaults: supplyDefaults\n};\n\n},{\"../../lib\":719,\"../scatter/constants\":1116,\"../scatter/fillcolor_defaults\":1120,\"../scatter/line_defaults\":1124,\"../scatter/line_shape_defaults\":1126,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"../scatter/text_defaults\":1136,\"./attributes\":1179}],1182:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterHover = _dereq_('../scatter/hover');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar Lib = _dereq_('../../lib');\n\nfunction hoverPoints(pointData, xval, yval, hovermode) {\n    var scatterPointData = scatterHover(pointData, xval, yval, hovermode);\n    if(!scatterPointData || scatterPointData[0].index === false) return;\n\n    var newPointData = scatterPointData[0];\n\n    // hovering on fill case\n    if(newPointData.index === undefined) {\n        return scatterPointData;\n    }\n\n    var subplot = pointData.subplot;\n    var cdi = newPointData.cd[newPointData.index];\n    var trace = newPointData.trace;\n\n    if(!subplot.isPtInside(cdi)) return;\n\n    newPointData.xLabelVal = undefined;\n    newPointData.yLabelVal = undefined;\n    makeHoverPointText(cdi, trace, subplot, newPointData);\n    newPointData.hovertemplate = trace.hovertemplate;\n    return scatterPointData;\n}\n\nfunction makeHoverPointText(cdi, trace, subplot, pointData) {\n    var radialAxis = subplot.radialAxis;\n    var angularAxis = subplot.angularAxis;\n    radialAxis._hovertitle = 'r';\n    angularAxis._hovertitle = 'θ';\n\n    var rVal = radialAxis.c2l(cdi.r);\n    pointData.rLabel = Axes.tickText(radialAxis, rVal, 'hover').text;\n\n    // N.B here the ° sign is part of the formatted value for thetaunit:'degrees'\n    var thetaVal = angularAxis.thetaunit === 'degrees' ? Lib.rad2deg(cdi.theta) : cdi.theta;\n    pointData.thetaLabel = Axes.tickText(angularAxis, thetaVal, 'hover').text;\n\n    var hoverinfo = cdi.hi || trace.hoverinfo;\n    var text = [];\n    function textPart(ax, val) {\n        text.push(ax._hovertitle + ': ' + val);\n    }\n\n    if(!trace.hovertemplate) {\n        var parts = hoverinfo.split('+');\n\n        if(parts.indexOf('all') !== -1) parts = ['r', 'theta', 'text'];\n        if(parts.indexOf('r') !== -1) textPart(radialAxis, pointData.rLabel);\n        if(parts.indexOf('theta') !== -1) textPart(angularAxis, pointData.thetaLabel);\n\n        if(parts.indexOf('text') !== -1 && pointData.text) {\n            text.push(pointData.text);\n            delete pointData.text;\n        }\n\n        pointData.extraText = text.join('<br>');\n    }\n}\n\nmodule.exports = {\n    hoverPoints: hoverPoints,\n    makeHoverPointText: makeHoverPointText\n};\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../scatter/hover\":1122}],1183:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'scatterpolar',\n    basePlotModule: _dereq_('../../plots/polar'),\n    categories: ['polar', 'symbols', 'showLegend', 'scatter-like'],\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults').supplyDefaults,\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    style: _dereq_('../scatter/style').style,\n    styleOnSelect: _dereq_('../scatter/style').styleOnSelect,\n    hoverPoints: _dereq_('./hover').hoverPoints,\n    selectPoints: _dereq_('../scatter/select'),\n\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/polar\":831,\"../scatter/marker_colorbar\":1129,\"../scatter/select\":1132,\"../scatter/style\":1134,\"./attributes\":1179,\"./calc\":1180,\"./defaults\":1181,\"./hover\":1182,\"./plot\":1184}],1184:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterPlot = _dereq_('../scatter/plot');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function plot(gd, subplot, moduleCalcData) {\n    var mlayer = subplot.layers.frontplot.select('g.scatterlayer');\n\n    var plotinfo = {\n        xaxis: subplot.xaxis,\n        yaxis: subplot.yaxis,\n        plot: subplot.framework,\n        layerClipId: subplot._hasClipOnAxisFalse ? subplot.clipIds.forTraces : null\n    };\n\n    var radialAxis = subplot.radialAxis;\n    var angularAxis = subplot.angularAxis;\n\n    // convert:\n    // 'c' (r,theta) -> 'geometric' (r,theta) -> (x,y)\n    for(var i = 0; i < moduleCalcData.length; i++) {\n        var cdi = moduleCalcData[i];\n\n        for(var j = 0; j < cdi.length; j++) {\n            var cd = cdi[j];\n            var r = cd.r;\n\n            if(r === BADNUM) {\n                cd.x = cd.y = BADNUM;\n            } else {\n                var rg = radialAxis.c2g(r);\n                var thetag = angularAxis.c2g(cd.theta);\n                cd.x = rg * Math.cos(thetag);\n                cd.y = rg * Math.sin(thetag);\n            }\n        }\n    }\n\n    scatterPlot(gd, plotinfo, moduleCalcData, mlayer);\n};\n\n},{\"../../constants/numerical\":695,\"../scatter/plot\":1131}],1185:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterPolarAttrs = _dereq_('../scatterpolar/attributes');\nvar scatterGlAttrs = _dereq_('../scattergl/attributes');\n\nmodule.exports = {\n    mode: scatterPolarAttrs.mode,\n    r: scatterPolarAttrs.r,\n    theta: scatterPolarAttrs.theta,\n    r0: scatterPolarAttrs.r0,\n    dr: scatterPolarAttrs.dr,\n    theta0: scatterPolarAttrs.theta0,\n    dtheta: scatterPolarAttrs.dtheta,\n    thetaunit: scatterPolarAttrs.thetaunit,\n\n    text: scatterPolarAttrs.text,\n    hovertext: scatterPolarAttrs.hovertext,\n    hovertemplate: scatterPolarAttrs.hovertemplate,\n\n    line: scatterGlAttrs.line,\n    connectgaps: scatterGlAttrs.connectgaps,\n\n    marker: scatterGlAttrs.marker,\n    // no cliponaxis\n\n    fill: scatterGlAttrs.fill,\n    fillcolor: scatterGlAttrs.fillcolor,\n\n    textposition: scatterGlAttrs.textposition,\n    textfont: scatterGlAttrs.textfont,\n\n    hoverinfo: scatterPolarAttrs.hoverinfo,\n    // no hoveron\n\n    selected: scatterPolarAttrs.selected,\n    unselected: scatterPolarAttrs.unselected\n};\n\n},{\"../scattergl/attributes\":1160,\"../scatterpolar/attributes\":1179}],1186:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar calcColorscale = _dereq_('../scatter/colorscale_calc');\nvar calcMarkerSize = _dereq_('../scatter/calc').calcMarkerSize;\nvar convert = _dereq_('../scattergl/convert');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar TOO_MANY_POINTS = _dereq_('../scattergl/constants').TOO_MANY_POINTS;\n\nmodule.exports = function calc(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var subplotId = trace.subplot;\n    var radialAxis = fullLayout[subplotId].radialaxis;\n    var angularAxis = fullLayout[subplotId].angularaxis;\n    var rArray = radialAxis.makeCalcdata(trace, 'r');\n    var thetaArray = angularAxis.makeCalcdata(trace, 'theta');\n    var len = trace._length;\n    var stash = {};\n\n    if(len < rArray.length) rArray = rArray.slice(0, len);\n    if(len < thetaArray.length) thetaArray = thetaArray.slice(0, len);\n\n    stash.r = rArray;\n    stash.theta = thetaArray;\n\n    calcColorscale(gd, trace);\n\n    // only compute 'style' options in calc, as position options\n    // depend on the radial range and must be set in plot\n    var opts = stash.opts = convert.style(gd, trace);\n\n    // For graphs with very large number of points and array marker.size,\n    // use average marker size instead to speed things up.\n    var ppad;\n    if(len < TOO_MANY_POINTS) {\n        ppad = calcMarkerSize(trace, len);\n    } else if(opts.marker) {\n        ppad = 2 * (opts.marker.sizeAvg || Math.max(opts.marker.size, 3));\n    }\n    trace._extremes.x = Axes.findExtremes(radialAxis, rArray, {ppad: ppad});\n\n    return [{x: false, y: false, t: stash, trace: trace}];\n};\n\n},{\"../../plots/cartesian/axes\":767,\"../scatter/calc\":1113,\"../scatter/colorscale_calc\":1115,\"../scattergl/constants\":1162,\"../scattergl/convert\":1163}],1187:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleRThetaDefaults = _dereq_('../scatterpolar/defaults').handleRThetaDefaults;\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar handleLineDefaults = _dereq_('../scatter/line_defaults');\nvar handleTextDefaults = _dereq_('../scatter/text_defaults');\nvar handleFillColorDefaults = _dereq_('../scatter/fillcolor_defaults');\nvar PTS_LINESONLY = _dereq_('../scatter/constants').PTS_LINESONLY;\n\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleRThetaDefaults(traceIn, traceOut, layout, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('thetaunit');\n    coerce('mode', len < PTS_LINESONLY ? 'lines+markers' : 'lines');\n    coerce('text');\n    coerce('hovertext');\n    if(traceOut.hoveron !== 'fills') coerce('hovertemplate');\n\n    if(subTypes.hasLines(traceOut)) {\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n        coerce('connectgaps');\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce);\n    }\n\n    coerce('fill');\n    if(traceOut.fill !== 'none') {\n        handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);\n    }\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\n},{\"../../lib\":719,\"../scatter/constants\":1116,\"../scatter/fillcolor_defaults\":1120,\"../scatter/line_defaults\":1124,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"../scatter/text_defaults\":1136,\"../scatterpolar/defaults\":1181,\"./attributes\":1185}],1188:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hover = _dereq_('../scattergl/hover');\nvar makeHoverPointText = _dereq_('../scatterpolar/hover').makeHoverPointText;\n\nfunction hoverPoints(pointData, xval, yval, hovermode) {\n    var cd = pointData.cd;\n    var stash = cd[0].t;\n    var rArray = stash.r;\n    var thetaArray = stash.theta;\n\n    var scatterPointData = hover.hoverPoints(pointData, xval, yval, hovermode);\n    if(!scatterPointData || scatterPointData[0].index === false) return;\n\n    var newPointData = scatterPointData[0];\n\n    if(newPointData.index === undefined) {\n        return scatterPointData;\n    }\n\n    var subplot = pointData.subplot;\n    var cdi = newPointData.cd[newPointData.index];\n    var trace = newPointData.trace;\n\n    // augment pointData with r/theta param\n    cdi.r = rArray[newPointData.index];\n    cdi.theta = thetaArray[newPointData.index];\n\n    if(!subplot.isPtInside(cdi)) return;\n\n    newPointData.xLabelVal = undefined;\n    newPointData.yLabelVal = undefined;\n    makeHoverPointText(cdi, trace, subplot, newPointData);\n\n    return scatterPointData;\n}\n\nmodule.exports = {\n    hoverPoints: hoverPoints\n};\n\n},{\"../scattergl/hover\":1166,\"../scatterpolar/hover\":1182}],1189:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'scatterpolargl',\n    basePlotModule: _dereq_('../../plots/polar'),\n    categories: ['gl', 'regl', 'polar', 'symbols', 'showLegend', 'scatter-like'],\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    hoverPoints: _dereq_('./hover').hoverPoints,\n    selectPoints: _dereq_('../scattergl/select'),\n\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/polar\":831,\"../scatter/marker_colorbar\":1129,\"../scattergl/select\":1170,\"./attributes\":1185,\"./calc\":1186,\"./defaults\":1187,\"./hover\":1188,\"./plot\":1190}],1190:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar cluster = _dereq_('point-cluster');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar scatterglPlot = _dereq_('../scattergl/plot');\nvar sceneUpdate = _dereq_('../scattergl/scene_update');\nvar convert = _dereq_('../scattergl/convert');\n\nvar Lib = _dereq_('../../lib');\n\nvar TOO_MANY_POINTS = _dereq_('../scattergl/constants').TOO_MANY_POINTS;\n\nmodule.exports = function plot(gd, subplot, cdata) {\n    if(!cdata.length) return;\n\n    var radialAxis = subplot.radialAxis;\n    var angularAxis = subplot.angularAxis;\n    var scene = sceneUpdate(gd, subplot);\n\n    cdata.forEach(function(cdscatter) {\n        if(!cdscatter || !cdscatter[0] || !cdscatter[0].trace) return;\n        var cd = cdscatter[0];\n        var trace = cd.trace;\n        var stash = cd.t;\n        var len = trace._length;\n        var rArray = stash.r;\n        var thetaArray = stash.theta;\n        var opts = stash.opts;\n        var i;\n\n        var subRArray = rArray.slice();\n        var subThetaArray = thetaArray.slice();\n\n        // filter out by range\n        for(i = 0; i < rArray.length; i++) {\n            if(!subplot.isPtInside({r: rArray[i], theta: thetaArray[i]})) {\n                subRArray[i] = NaN;\n                subThetaArray[i] = NaN;\n            }\n        }\n\n        var positions = new Array(len * 2);\n        var x = Array(len);\n        var y = Array(len);\n\n        for(i = 0; i < len; i++) {\n            var r = subRArray[i];\n            var xx, yy;\n\n            if(isNumeric(r)) {\n                var rg = radialAxis.c2g(r);\n                var thetag = angularAxis.c2g(subThetaArray[i], trace.thetaunit);\n                xx = rg * Math.cos(thetag);\n                yy = rg * Math.sin(thetag);\n            } else {\n                xx = yy = NaN;\n            }\n            x[i] = positions[i * 2] = xx;\n            y[i] = positions[i * 2 + 1] = yy;\n        }\n\n        stash.tree = cluster(positions);\n\n        // FIXME: see scattergl.js#109\n        if(opts.marker && len >= TOO_MANY_POINTS) {\n            opts.marker.cluster = stash.tree;\n        }\n\n        if(opts.marker) {\n            opts.markerSel.positions = opts.markerUnsel.positions = opts.marker.positions = positions;\n        }\n\n        if(opts.line && positions.length > 1) {\n            Lib.extendFlat(\n                opts.line,\n                convert.linePositions(gd, trace, positions)\n            );\n        }\n\n        if(opts.text) {\n            Lib.extendFlat(\n                opts.text,\n                {positions: positions},\n                convert.textPosition(gd, trace, opts.text, opts.marker)\n            );\n            Lib.extendFlat(\n                opts.textSel,\n                {positions: positions},\n                convert.textPosition(gd, trace, opts.text, opts.markerSel)\n            );\n            Lib.extendFlat(\n                opts.textUnsel,\n                {positions: positions},\n                convert.textPosition(gd, trace, opts.text, opts.markerUnsel)\n            );\n        }\n\n        if(opts.fill && !scene.fill2d) scene.fill2d = true;\n        if(opts.marker && !scene.scatter2d) scene.scatter2d = true;\n        if(opts.line && !scene.line2d) scene.line2d = true;\n        if(opts.text && !scene.glText) scene.glText = true;\n\n        scene.lineOptions.push(opts.line);\n        scene.fillOptions.push(opts.fill);\n        scene.markerOptions.push(opts.marker);\n        scene.markerSelectedOptions.push(opts.markerSel);\n        scene.markerUnselectedOptions.push(opts.markerUnsel);\n        scene.textOptions.push(opts.text);\n        scene.textSelectedOptions.push(opts.textSel);\n        scene.textUnselectedOptions.push(opts.textUnsel);\n        scene.selectBatch.push([]);\n        scene.unselectBatch.push([]);\n\n        stash.x = x;\n        stash.y = y;\n        stash.rawx = x;\n        stash.rawy = y;\n        stash.r = rArray;\n        stash.theta = thetaArray;\n        stash.positions = positions;\n        stash._scene = scene;\n        stash.index = scene.count;\n        scene.count++;\n    });\n\n    return scatterglPlot(gd, subplot, cdata);\n};\n\n},{\"../../lib\":719,\"../scattergl/constants\":1162,\"../scattergl/convert\":1163,\"../scattergl/plot\":1168,\"../scattergl/scene_update\":1169,\"fast-isnumeric\":225,\"point-cluster\":469}],1191:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar dash = _dereq_('../../components/drawing/attributes').dash;\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar scatterLineAttrs = scatterAttrs.line;\nvar scatterMarkerLineAttrs = scatterMarkerAttrs.line;\n\nmodule.exports = {\n    a: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    b: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    c: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    sum: {\n        valType: 'number',\n        \n        dflt: 0,\n        min: 0,\n        editType: 'calc',\n        \n    },\n    mode: extendFlat({}, scatterAttrs.mode, {dflt: 'markers'}),\n    text: extendFlat({}, scatterAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, scatterAttrs.hovertext, {\n        \n    }),\n    line: {\n        color: scatterLineAttrs.color,\n        width: scatterLineAttrs.width,\n        dash: dash,\n        shape: extendFlat({}, scatterLineAttrs.shape,\n            {values: ['linear', 'spline']}),\n        smoothing: scatterLineAttrs.smoothing,\n        editType: 'calc'\n    },\n    connectgaps: scatterAttrs.connectgaps,\n    cliponaxis: scatterAttrs.cliponaxis,\n    fill: extendFlat({}, scatterAttrs.fill, {\n        values: ['none', 'toself', 'tonext'],\n        dflt: 'none',\n        \n    }),\n    fillcolor: scatterAttrs.fillcolor,\n    marker: extendFlat({\n        symbol: scatterMarkerAttrs.symbol,\n        opacity: scatterMarkerAttrs.opacity,\n        maxdisplayed: scatterMarkerAttrs.maxdisplayed,\n        size: scatterMarkerAttrs.size,\n        sizeref: scatterMarkerAttrs.sizeref,\n        sizemin: scatterMarkerAttrs.sizemin,\n        sizemode: scatterMarkerAttrs.sizemode,\n        line: extendFlat({\n            width: scatterMarkerLineAttrs.width,\n            editType: 'calc'\n        },\n            colorScaleAttrs('marker.line')\n        ),\n        gradient: scatterMarkerAttrs.gradient,\n        editType: 'calc'\n    },\n        colorScaleAttrs('marker')\n    ),\n\n    textfont: scatterAttrs.textfont,\n    textposition: scatterAttrs.textposition,\n\n    selected: scatterAttrs.selected,\n    unselected: scatterAttrs.unselected,\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['a', 'b', 'c', 'text', 'name']\n    }),\n    hoveron: scatterAttrs.hoveron,\n    hovertemplate: hovertemplateAttrs(),\n};\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/drawing/attributes\":613,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../scatter/attributes\":1112}],1192:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar calcColorscale = _dereq_('../scatter/colorscale_calc');\nvar arraysToCalcdata = _dereq_('../scatter/arrays_to_calcdata');\nvar calcSelection = _dereq_('../scatter/calc_selection');\nvar calcMarkerSize = _dereq_('../scatter/calc').calcMarkerSize;\n\nvar dataArrays = ['a', 'b', 'c'];\nvar arraysToFill = {a: ['b', 'c'], b: ['a', 'c'], c: ['a', 'b']};\n\nmodule.exports = function calc(gd, trace) {\n    var ternary = gd._fullLayout[trace.subplot];\n    var displaySum = ternary.sum;\n    var normSum = trace.sum || displaySum;\n    var arrays = {a: trace.a, b: trace.b, c: trace.c};\n\n    var i, j, dataArray, newArray, fillArray1, fillArray2;\n\n    // fill in one missing component\n    for(i = 0; i < dataArrays.length; i++) {\n        dataArray = dataArrays[i];\n        if(arrays[dataArray]) continue;\n\n        fillArray1 = arrays[arraysToFill[dataArray][0]];\n        fillArray2 = arrays[arraysToFill[dataArray][1]];\n        newArray = new Array(fillArray1.length);\n        for(j = 0; j < fillArray1.length; j++) {\n            newArray[j] = normSum - fillArray1[j] - fillArray2[j];\n        }\n        arrays[dataArray] = newArray;\n    }\n\n    // make the calcdata array\n    var serieslen = trace._length;\n    var cd = new Array(serieslen);\n    var a, b, c, norm, x, y;\n    for(i = 0; i < serieslen; i++) {\n        a = arrays.a[i];\n        b = arrays.b[i];\n        c = arrays.c[i];\n        if(isNumeric(a) && isNumeric(b) && isNumeric(c)) {\n            a = +a;\n            b = +b;\n            c = +c;\n            norm = displaySum / (a + b + c);\n            if(norm !== 1) {\n                a *= norm;\n                b *= norm;\n                c *= norm;\n            }\n            // map a, b, c onto x and y where the full scale of y\n            // is [0, sum], and x is [-sum, sum]\n            // TODO: this makes `a` always the top, `b` the bottom left,\n            // and `c` the bottom right. Do we want options to rearrange\n            // these?\n            y = a;\n            x = c - b;\n            cd[i] = {x: x, y: y, a: a, b: b, c: c};\n        } else cd[i] = {x: false, y: false};\n    }\n\n    calcMarkerSize(trace, serieslen);\n    calcColorscale(gd, trace);\n    arraysToCalcdata(cd, trace);\n    calcSelection(cd, trace);\n\n    return cd;\n};\n\n},{\"../scatter/arrays_to_calcdata\":1111,\"../scatter/calc\":1113,\"../scatter/calc_selection\":1114,\"../scatter/colorscale_calc\":1115,\"fast-isnumeric\":225}],1193:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar constants = _dereq_('../scatter/constants');\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar handleLineDefaults = _dereq_('../scatter/line_defaults');\nvar handleLineShapeDefaults = _dereq_('../scatter/line_shape_defaults');\nvar handleTextDefaults = _dereq_('../scatter/text_defaults');\nvar handleFillColorDefaults = _dereq_('../scatter/fillcolor_defaults');\n\nvar attributes = _dereq_('./attributes');\n\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var a = coerce('a');\n    var b = coerce('b');\n    var c = coerce('c');\n    var len;\n\n    // allow any one array to be missing, len is the minimum length of those\n    // present. Note that after coerce data_array's are either Arrays (which\n    // are truthy even if empty) or undefined. As in scatter, an empty array\n    // is different from undefined, because it can signify that this data is\n    // not known yet but expected in the future\n    if(a) {\n        len = a.length;\n        if(b) {\n            len = Math.min(len, b.length);\n            if(c) len = Math.min(len, c.length);\n        } else if(c) len = Math.min(len, c.length);\n        else len = 0;\n    } else if(b && c) {\n        len = Math.min(b.length, c.length);\n    }\n\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    traceOut._length = len;\n\n    coerce('sum');\n\n    coerce('text');\n    coerce('hovertext');\n    if(traceOut.hoveron !== 'fills') coerce('hovertemplate');\n\n    var defaultMode = len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines';\n    coerce('mode', defaultMode);\n\n    if(subTypes.hasLines(traceOut)) {\n        handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n        handleLineShapeDefaults(traceIn, traceOut, coerce);\n        coerce('connectgaps');\n    }\n\n    if(subTypes.hasMarkers(traceOut)) {\n        handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {gradient: true});\n    }\n\n    if(subTypes.hasText(traceOut)) {\n        handleTextDefaults(traceIn, traceOut, layout, coerce);\n    }\n\n    var dfltHoverOn = [];\n\n    if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {\n        coerce('cliponaxis');\n        coerce('marker.maxdisplayed');\n        dfltHoverOn.push('points');\n    }\n\n    coerce('fill');\n    if(traceOut.fill !== 'none') {\n        handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);\n        if(!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce);\n    }\n\n    if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {\n        dfltHoverOn.push('fills');\n    }\n    coerce('hoveron', dfltHoverOn.join('+') || 'points');\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\n},{\"../../lib\":719,\"../scatter/constants\":1116,\"../scatter/fillcolor_defaults\":1120,\"../scatter/line_defaults\":1124,\"../scatter/line_shape_defaults\":1126,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"../scatter/text_defaults\":1136,\"./attributes\":1191}],1194:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function eventData(out, pt, trace, cd, pointNumber) {\n    if(pt.xa) out.xaxis = pt.xa;\n    if(pt.ya) out.yaxis = pt.ya;\n\n    if(cd[pointNumber]) {\n        var cdi = cd[pointNumber];\n\n        // N.B. These are the normalized coordinates.\n        out.a = cdi.a;\n        out.b = cdi.b;\n        out.c = cdi.c;\n    } else {\n        // for fill-hover only\n        out.a = pt.a;\n        out.b = pt.b;\n        out.c = pt.c;\n    }\n\n    return out;\n};\n\n},{}],1195:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar scatterHover = _dereq_('../scatter/hover');\nvar Axes = _dereq_('../../plots/cartesian/axes');\n\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode) {\n    var scatterPointData = scatterHover(pointData, xval, yval, hovermode);\n    if(!scatterPointData || scatterPointData[0].index === false) return;\n\n    var newPointData = scatterPointData[0];\n\n    // if hovering on a fill, we don't show any point data so the label is\n    // unchanged from what scatter gives us - except that it needs to\n    // be constrained to the trianglular plot area, not just the rectangular\n    // area defined by the synthetic x and y axes\n    // TODO: in some cases the vertical middle of the shape is not within\n    // the triangular viewport at all, so the label can become disconnected\n    // from the shape entirely. But calculating what portion of the shape\n    // is actually visible, as constrained by the diagonal axis lines, is not\n    // so easy and anyway we lost the information we would have needed to do\n    // this inside scatterHover.\n    if(newPointData.index === undefined) {\n        var yFracUp = 1 - (newPointData.y0 / pointData.ya._length);\n        var xLen = pointData.xa._length;\n        var xMin = xLen * yFracUp / 2;\n        var xMax = xLen - xMin;\n        newPointData.x0 = Math.max(Math.min(newPointData.x0, xMax), xMin);\n        newPointData.x1 = Math.max(Math.min(newPointData.x1, xMax), xMin);\n        return scatterPointData;\n    }\n\n    var cdi = newPointData.cd[newPointData.index];\n\n    newPointData.a = cdi.a;\n    newPointData.b = cdi.b;\n    newPointData.c = cdi.c;\n\n    newPointData.xLabelVal = undefined;\n    newPointData.yLabelVal = undefined;\n\n    var ternary = newPointData.subplot;\n    newPointData.aLabel = Axes.tickText(ternary.aaxis, cdi.a, 'hover').text;\n    newPointData.bLabel = Axes.tickText(ternary.baxis, cdi.b, 'hover').text;\n    newPointData.cLabel = Axes.tickText(ternary.caxis, cdi.c, 'hover').text;\n\n    var trace = newPointData.trace;\n    var hoverinfo = cdi.hi || trace.hoverinfo;\n    var text = [];\n    function textPart(ax, val) {\n        text.push(ax._hovertitle + ': ' + val);\n    }\n    if(!trace.hovertemplate) {\n        var parts = hoverinfo.split('+');\n        if(parts.indexOf('all') !== -1) parts = ['a', 'b', 'c'];\n        if(parts.indexOf('a') !== -1) textPart(ternary.aaxis, newPointData.aLabel);\n        if(parts.indexOf('b') !== -1) textPart(ternary.baxis, newPointData.bLabel);\n        if(parts.indexOf('c') !== -1) textPart(ternary.caxis, newPointData.cLabel);\n    }\n    newPointData.extraText = text.join('<br>');\n    newPointData.hovertemplate = trace.hovertemplate;\n    return scatterPointData;\n};\n\n},{\"../../plots/cartesian/axes\":767,\"../scatter/hover\":1122}],1196:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    style: _dereq_('../scatter/style').style,\n    styleOnSelect: _dereq_('../scatter/style').styleOnSelect,\n    hoverPoints: _dereq_('./hover'),\n    selectPoints: _dereq_('../scatter/select'),\n    eventData: _dereq_('./event_data'),\n\n    moduleType: 'trace',\n    name: 'scatterternary',\n    basePlotModule: _dereq_('../../plots/ternary'),\n    categories: ['ternary', 'symbols', 'showLegend', 'scatter-like'],\n    meta: {\n        \n        \n    }\n};\n\n},{\"../../plots/ternary\":843,\"../scatter/marker_colorbar\":1129,\"../scatter/select\":1132,\"../scatter/style\":1134,\"./attributes\":1191,\"./calc\":1192,\"./defaults\":1193,\"./event_data\":1194,\"./hover\":1195,\"./plot\":1197}],1197:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar scatterPlot = _dereq_('../scatter/plot');\n\nmodule.exports = function plot(gd, ternary, moduleCalcData) {\n    var plotContainer = ternary.plotContainer;\n\n    // remove all nodes inside the scatter layer\n    plotContainer.select('.scatterlayer').selectAll('*').remove();\n\n    // mimic cartesian plotinfo\n    var plotinfo = {\n        xaxis: ternary.xaxis,\n        yaxis: ternary.yaxis,\n        plot: plotContainer,\n        layerClipId: ternary._hasClipOnAxisFalse ? ternary.clipIdRelative : null\n    };\n\n    var scatterLayer = ternary.layers.frontplot.select('g.scatterlayer');\n\n    scatterPlot(gd, plotinfo, moduleCalcData, scatterLayer);\n};\n\n},{\"../scatter/plot\":1131}],1198:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar scatterAttrs = _dereq_('../scatter/attributes');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar scatterGlAttrs = _dereq_('../scattergl/attributes');\nvar cartesianIdRegex = _dereq_('../../plots/cartesian/constants').idRegex;\nvar templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar scatterMarkerAttrs = scatterAttrs.marker;\nvar scatterMarkerLineAttrs = scatterMarkerAttrs.line;\n\nvar markerLineAttrs = extendFlat(colorScaleAttrs('marker.line', {editTypeOverride: 'calc'}), {\n    width: extendFlat({}, scatterMarkerLineAttrs.width, {editType: 'calc'}),\n    editType: 'calc'\n});\n\nvar markerAttrs = extendFlat(colorScaleAttrs('marker'), {\n    symbol: scatterMarkerAttrs.symbol,\n    size: extendFlat({}, scatterMarkerAttrs.size, {editType: 'markerSize'}),\n    sizeref: scatterMarkerAttrs.sizeref,\n    sizemin: scatterMarkerAttrs.sizemin,\n    sizemode: scatterMarkerAttrs.sizemode,\n    opacity: scatterMarkerAttrs.opacity,\n    colorbar: scatterMarkerAttrs.colorbar,\n    line: markerLineAttrs,\n    editType: 'calc'\n});\n\nmarkerAttrs.color.editType = markerAttrs.cmin.editType = markerAttrs.cmax.editType = 'style';\n\nfunction makeAxesValObject(axLetter) {\n    return {\n        valType: 'info_array',\n        freeLength: true,\n        \n        editType: 'calc',\n        items: {\n            valType: 'subplotid',\n            regex: cartesianIdRegex[axLetter],\n            editType: 'plot'\n        },\n        \n    };\n}\n\nmodule.exports = {\n    dimensions: templatedArray('dimension', {\n        visible: {\n            valType: 'boolean',\n            \n            dflt: true,\n            editType: 'calc',\n            \n        },\n        label: {\n            valType: 'string',\n            \n            editType: 'calc',\n            \n        },\n        values: {\n            valType: 'data_array',\n            \n            editType: 'calc+clearAxisTypes',\n            \n        },\n\n        axis: {\n            type: {\n                valType: 'enumerated',\n                values: ['linear', 'log', 'date', 'category'],\n                \n                editType: 'calc+clearAxisTypes',\n                \n            },\n\n            // TODO make 'true' the default in v2?\n            matches: {\n                valType: 'boolean',\n                dflt: false,\n                \n                editType: 'calc',\n                \n            },\n\n            editType: 'calc+clearAxisTypes'\n        },\n\n        // TODO should add an attribute to pin down x only vars and y only vars\n        // like https://seaborn.pydata.org/generated/seaborn.pairplot.html\n        // x_vars and y_vars\n\n        // maybe more axis defaulting option e.g. `showgrid: false`\n\n        editType: 'calc+clearAxisTypes'\n    }),\n\n    // mode: {}, (only 'markers' for now)\n\n    text: extendFlat({}, scatterGlAttrs.text, {\n        \n    }),\n    hovertext: extendFlat({}, scatterGlAttrs.hovertext, {\n        \n    }),\n\n    hovertemplate: hovertemplateAttrs(),\n\n    marker: markerAttrs,\n\n    xaxes: makeAxesValObject('x'),\n    yaxes: makeAxesValObject('y'),\n\n    diagonal: {\n        visible: {\n            valType: 'boolean',\n            \n            dflt: true,\n            editType: 'calc',\n            \n        },\n\n        // type: 'scattergl' | 'histogram' | 'box' | 'violin'\n        // ...\n        // more options\n\n        editType: 'calc'\n    },\n\n    showupperhalf: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'calc',\n        \n    },\n    showlowerhalf: {\n        valType: 'boolean',\n        \n        dflt: true,\n        editType: 'calc',\n        \n    },\n\n    selected: {\n        marker: scatterGlAttrs.selected.marker,\n        editType: 'calc'\n    },\n    unselected: {\n        marker: scatterGlAttrs.unselected.marker,\n        editType: 'calc'\n    },\n\n    opacity: scatterGlAttrs.opacity\n};\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plot_api/plot_template\":757,\"../../plots/cartesian/constants\":773,\"../scatter/attributes\":1112,\"../scattergl/attributes\":1160}],1199:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar createLine = _dereq_('regl-line2d');\n\nvar Registry = _dereq_('../../registry');\nvar prepareRegl = _dereq_('../../lib/prepare_regl');\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\nvar Cartesian = _dereq_('../../plots/cartesian');\nvar getFromId = _dereq_('../../plots/cartesian/axis_ids').getFromId;\nvar shouldShowZeroLine = _dereq_('../../plots/cartesian/axes').shouldShowZeroLine;\n\nvar SPLOM = 'splom';\n\nfunction plot(gd) {\n    var fullLayout = gd._fullLayout;\n    var _module = Registry.getModule(SPLOM);\n    var splomCalcData = getModuleCalcData(gd.calcdata, _module)[0];\n\n    var success = prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);\n    if(!success) return;\n\n    if(fullLayout._hasOnlyLargeSploms) {\n        updateGrid(gd);\n    }\n\n    _module.plot(gd, {}, splomCalcData);\n}\n\nfunction drag(gd) {\n    var cd = gd.calcdata;\n    var fullLayout = gd._fullLayout;\n\n    if(fullLayout._hasOnlyLargeSploms) {\n        updateGrid(gd);\n    }\n\n    for(var i = 0; i < cd.length; i++) {\n        var cd0 = cd[i][0];\n        var trace = cd0.trace;\n        var scene = fullLayout._splomScenes[trace.uid];\n\n        if(trace.type === 'splom' && scene && scene.matrix) {\n            dragOne(gd, trace, scene);\n        }\n    }\n}\n\nfunction dragOne(gd, trace, scene) {\n    var visibleLength = scene.matrixOptions.data.length;\n    var visibleDims = trace._visibleDims;\n    var ranges = scene.viewOpts.ranges = new Array(visibleLength);\n\n    for(var k = 0; k < visibleDims.length; k++) {\n        var i = visibleDims[k];\n        var rng = ranges[k] = new Array(4);\n\n        var xa = getFromId(gd, trace._diag[i][0]);\n        if(xa) {\n            rng[0] = xa.r2l(xa.range[0]);\n            rng[2] = xa.r2l(xa.range[1]);\n        }\n\n        var ya = getFromId(gd, trace._diag[i][1]);\n        if(ya) {\n            rng[1] = ya.r2l(ya.range[0]);\n            rng[3] = ya.r2l(ya.range[1]);\n        }\n    }\n\n    if(scene.selectBatch.length || scene.unselectBatch.length) {\n        scene.matrix.update({ranges: ranges}, {ranges: ranges});\n    } else {\n        scene.matrix.update({ranges: ranges});\n    }\n}\n\nfunction updateGrid(gd) {\n    var fullLayout = gd._fullLayout;\n    var regl = fullLayout._glcanvas.data()[0].regl;\n    var splomGrid = fullLayout._splomGrid;\n\n    if(!splomGrid) {\n        splomGrid = fullLayout._splomGrid = createLine(regl);\n    }\n    splomGrid.update(makeGridData(gd));\n}\n\nfunction makeGridData(gd) {\n    var fullLayout = gd._fullLayout;\n    var gs = fullLayout._size;\n    var fullView = [0, 0, fullLayout.width, fullLayout.height];\n    var lookup = {};\n    var k;\n\n    function push(prefix, ax, x0, x1, y0, y1) {\n        var lcolor = ax[prefix + 'color'];\n        var lwidth = ax[prefix + 'width'];\n        var key = String(lcolor + lwidth);\n\n        if(key in lookup) {\n            lookup[key].data.push(NaN, NaN, x0, x1, y0, y1);\n        } else {\n            lookup[key] = {\n                data: [x0, x1, y0, y1],\n                join: 'rect',\n                thickness: lwidth,\n                color: lcolor,\n                viewport: fullView,\n                range: fullView,\n                overlay: false\n            };\n        }\n    }\n\n    for(k in fullLayout._splomSubplots) {\n        var sp = fullLayout._plots[k];\n        var xa = sp.xaxis;\n        var ya = sp.yaxis;\n        var xVals = xa._vals;\n        var yVals = ya._vals;\n        // ya.l2p assumes top-to-bottom coordinate system (a la SVG),\n        // we need to compute bottom-to-top offsets and slopes:\n        var yOffset = gs.b + ya.domain[0] * gs.h;\n        var ym = -ya._m;\n        var yb = -ym * ya.r2l(ya.range[0], ya.calendar);\n        var x, y;\n\n        if(xa.showgrid) {\n            for(k = 0; k < xVals.length; k++) {\n                x = xa._offset + xa.l2p(xVals[k].x);\n                push('grid', xa, x, yOffset, x, yOffset + ya._length);\n            }\n        }\n        if(ya.showgrid) {\n            for(k = 0; k < yVals.length; k++) {\n                y = yOffset + yb + ym * yVals[k].x;\n                push('grid', ya, xa._offset, y, xa._offset + xa._length, y);\n            }\n        }\n        if(shouldShowZeroLine(gd, xa, ya)) {\n            x = xa._offset + xa.l2p(0);\n            push('zeroline', xa, x, yOffset, x, yOffset + ya._length);\n        }\n        if(shouldShowZeroLine(gd, ya, xa)) {\n            y = yOffset + yb + 0;\n            push('zeroline', ya, xa._offset, y, xa._offset + xa._length, y);\n        }\n    }\n\n    var gridBatches = [];\n    for(k in lookup) {\n        gridBatches.push(lookup[k]);\n    }\n\n    return gridBatches;\n}\n\nfunction clean(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var lookup = {};\n    var i;\n\n    if(oldFullLayout._splomScenes) {\n        for(i = 0; i < newFullData.length; i++) {\n            var newTrace = newFullData[i];\n            if(newTrace.type === 'splom') {\n                lookup[newTrace.uid] = 1;\n            }\n        }\n        for(i = 0; i < oldFullData.length; i++) {\n            var oldTrace = oldFullData[i];\n            if(!lookup[oldTrace.uid]) {\n                var scene = oldFullLayout._splomScenes[oldTrace.uid];\n                if(scene && scene.destroy) scene.destroy();\n                // must first set scene to null in order to get garbage collected\n                oldFullLayout._splomScenes[oldTrace.uid] = null;\n                delete oldFullLayout._splomScenes[oldTrace.uid];\n            }\n        }\n    }\n\n    if(Object.keys(oldFullLayout._splomScenes || {}).length === 0) {\n        delete oldFullLayout._splomScenes;\n    }\n\n    if(oldFullLayout._splomGrid &&\n        (!newFullLayout._hasOnlyLargeSploms && oldFullLayout._hasOnlyLargeSploms)) {\n        // must first set scene to null in order to get garbage collected\n        oldFullLayout._splomGrid.destroy();\n        oldFullLayout._splomGrid = null;\n        delete oldFullLayout._splomGrid;\n    }\n\n    Cartesian.clean(newFullData, newFullLayout, oldFullData, oldFullLayout);\n}\n\nmodule.exports = {\n    name: SPLOM,\n    attr: Cartesian.attr,\n    attrRegex: Cartesian.attrRegex,\n    layoutAttributes: Cartesian.layoutAttributes,\n    supplyLayoutDefaults: Cartesian.supplyLayoutDefaults,\n    drawFramework: Cartesian.drawFramework,\n    plot: plot,\n    drag: drag,\n    updateGrid: updateGrid,\n    clean: clean,\n    updateFx: Cartesian.updateFx,\n    toSVG: Cartesian.toSVG\n};\n\n},{\"../../lib/prepare_regl\":732,\"../../plots/cartesian\":778,\"../../plots/cartesian/axes\":767,\"../../plots/cartesian/axis_ids\":770,\"../../plots/get_data\":802,\"../../registry\":847,\"regl-line2d\":491}],1200:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar AxisIDs = _dereq_('../../plots/cartesian/axis_ids');\n\nvar calcMarkerSize = _dereq_('../scatter/calc').calcMarkerSize;\nvar calcAxisExpansion = _dereq_('../scatter/calc').calcAxisExpansion;\nvar calcColorscale = _dereq_('../scatter/colorscale_calc');\nvar convertMarkerSelection = _dereq_('../scattergl/convert').markerSelection;\nvar convertMarkerStyle = _dereq_('../scattergl/convert').markerStyle;\nvar sceneUpdate = _dereq_('./scene_update');\n\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\nvar TOO_MANY_POINTS = _dereq_('../scattergl/constants').TOO_MANY_POINTS;\n\nmodule.exports = function calc(gd, trace) {\n    var dimensions = trace.dimensions;\n    var commonLength = trace._length;\n    var opts = {};\n    // 'c' for calculated, 'l' for linear,\n    // only differ here for log axes, pass ldata to createMatrix as 'data'\n    var cdata = opts.cdata = [];\n    var ldata = opts.data = [];\n    // keep track of visible dimensions\n    var visibleDims = trace._visibleDims = [];\n    var i, k, dim, xa, ya;\n\n    function makeCalcdata(ax, dim) {\n        // call makeCalcdata with fake input\n        var ccol = ax.makeCalcdata({\n            v: dim.values,\n            vcalendar: trace.calendar\n        }, 'v');\n\n        for(var j = 0; j < ccol.length; j++) {\n            ccol[j] = ccol[j] === BADNUM ? NaN : ccol[j];\n        }\n        cdata.push(ccol);\n        ldata.push(ax.type === 'log' ? Lib.simpleMap(ccol, ax.c2l) : ccol);\n    }\n\n    for(i = 0; i < dimensions.length; i++) {\n        dim = dimensions[i];\n\n        if(dim.visible) {\n            xa = AxisIDs.getFromId(gd, trace._diag[i][0]);\n            ya = AxisIDs.getFromId(gd, trace._diag[i][1]);\n\n            // if corresponding x & y axes don't have matching types, skip dim\n            if(xa && ya && xa.type !== ya.type) {\n                Lib.log('Skipping splom dimension ' + i + ' with conflicting axis types');\n                continue;\n            }\n\n            if(xa) {\n                makeCalcdata(xa, dim);\n                if(ya && ya.type === 'category') {\n                    ya._categories = xa._categories.slice();\n                }\n            } else {\n                // should not make it here, if both xa and ya undefined\n                makeCalcdata(ya, dim);\n            }\n\n            visibleDims.push(i);\n        }\n    }\n\n    calcColorscale(gd, trace);\n    Lib.extendFlat(opts, convertMarkerStyle(trace));\n\n    var visibleLength = cdata.length;\n    var hasTooManyPoints = (visibleLength * commonLength) > TOO_MANY_POINTS;\n\n    // Reuse SVG scatter axis expansion routine.\n    // For graphs with very large number of points and array marker.size,\n    // use average marker size instead to speed things up.\n    var ppad;\n    if(hasTooManyPoints) {\n        ppad = 2 * (opts.sizeAvg || Math.max(opts.size, 3));\n    } else {\n        ppad = calcMarkerSize(trace, commonLength);\n    }\n\n    for(k = 0; k < visibleDims.length; k++) {\n        i = visibleDims[k];\n        dim = dimensions[i];\n        xa = AxisIDs.getFromId(gd, trace._diag[i][0]) || {};\n        ya = AxisIDs.getFromId(gd, trace._diag[i][1]) || {};\n        calcAxisExpansion(gd, trace, xa, ya, cdata[k], cdata[k], ppad);\n    }\n\n    var scene = sceneUpdate(gd, trace);\n    if(!scene.matrix) scene.matrix = true;\n    scene.matrixOptions = opts;\n\n    scene.selectedOptions = convertMarkerSelection(trace, trace.selected);\n    scene.unselectedOptions = convertMarkerSelection(trace, trace.unselected);\n\n    return [{x: false, y: false, t: {}, trace: trace}];\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../plots/cartesian/axis_ids\":770,\"../scatter/calc\":1113,\"../scatter/colorscale_calc\":1115,\"../scattergl/constants\":1162,\"../scattergl/convert\":1163,\"./scene_update\":1207}],1201:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');\n\nvar attributes = _dereq_('./attributes');\nvar subTypes = _dereq_('../scatter/subtypes');\nvar handleMarkerDefaults = _dereq_('../scatter/marker_defaults');\nvar mergeLength = _dereq_('../parcoords/merge_length');\nvar OPEN_RE = /-open/;\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var dimensions = handleArrayContainerDefaults(traceIn, traceOut, {\n        name: 'dimensions',\n        handleItemDefaults: dimensionDefaults\n    });\n\n    var showDiag = coerce('diagonal.visible');\n    var showUpper = coerce('showupperhalf');\n    var showLower = coerce('showlowerhalf');\n\n    var dimLength = mergeLength(traceOut, dimensions, 'values');\n\n    if(!dimLength || (!showDiag && !showUpper && !showLower)) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n\n    var isOpen = OPEN_RE.test(traceOut.marker.symbol);\n    var isBubble = subTypes.isBubble(traceOut);\n    coerce('marker.line.width', isOpen || isBubble ? 1 : 0);\n\n    handleAxisDefaults(traceIn, traceOut, layout, coerce);\n\n    Lib.coerceSelectionMarkerOpacity(traceOut, coerce);\n};\n\nfunction dimensionDefaults(dimIn, dimOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(dimIn, dimOut, attributes.dimensions, attr, dflt);\n    }\n\n    coerce('label');\n    var values = coerce('values');\n\n    if(!(values && values.length)) dimOut.visible = false;\n    else coerce('visible');\n\n    coerce('axis.type');\n    coerce('axis.matches');\n}\n\nfunction handleAxisDefaults(traceIn, traceOut, layout, coerce) {\n    var dimensions = traceOut.dimensions;\n    var dimLength = dimensions.length;\n    var showUpper = traceOut.showupperhalf;\n    var showLower = traceOut.showlowerhalf;\n    var showDiag = traceOut.diagonal.visible;\n    var i, j;\n\n    var xAxesDflt = new Array(dimLength);\n    var yAxesDflt = new Array(dimLength);\n\n    for(i = 0; i < dimLength; i++) {\n        var suffix = i ? i + 1 : '';\n        xAxesDflt[i] = 'x' + suffix;\n        yAxesDflt[i] = 'y' + suffix;\n    }\n\n    var xaxes = coerce('xaxes', xAxesDflt);\n    var yaxes = coerce('yaxes', yAxesDflt);\n\n    // build list of [x,y] axis corresponding to each dimensions[i],\n    // very useful for passing options to regl-splom\n    var diag = traceOut._diag = new Array(dimLength);\n\n    // lookup for 'drawn' x|y axes, to avoid costly indexOf downstream\n    traceOut._xaxes = {};\n    traceOut._yaxes = {};\n\n    // list of 'drawn' x|y axes, use to generate list of subplots\n    var xList = [];\n    var yList = [];\n\n    function fillAxisStashes(axId, counterAxId, dim, list) {\n        if(!axId) return;\n\n        var axLetter = axId.charAt(0);\n        var stash = layout._splomAxes[axLetter];\n\n        traceOut['_' + axLetter + 'axes'][axId] = 1;\n        list.push(axId);\n\n        if(!(axId in stash)) {\n            var s = stash[axId] = {};\n            if(dim) {\n                s.label = dim.label || '';\n                if(dim.visible && dim.axis) {\n                    if(dim.axis.type) s.type = dim.axis.type;\n                    if(dim.axis.matches) s.matches = counterAxId;\n                }\n            }\n        }\n    }\n\n    // cases where showDiag and showLower or showUpper are false\n    // no special treatment as the 'drawn' x-axes and y-axes no longer match\n    // the dimensions items and xaxes|yaxes 1-to-1\n    var mustShiftX = !showDiag && !showLower;\n    var mustShiftY = !showDiag && !showUpper;\n\n    traceOut._axesDim = {};\n    for(i = 0; i < dimLength; i++) {\n        var dim = dimensions[i];\n        var i0 = i === 0;\n        var iN = i === dimLength - 1;\n\n        var xaId = (i0 && mustShiftX) || (iN && mustShiftY) ?\n            undefined :\n            xaxes[i];\n\n        var yaId = (i0 && mustShiftY) || (iN && mustShiftX) ?\n            undefined :\n            yaxes[i];\n\n        fillAxisStashes(xaId, yaId, dim, xList);\n        fillAxisStashes(yaId, xaId, dim, yList);\n        diag[i] = [xaId, yaId];\n        traceOut._axesDim[xaId] = i;\n        traceOut._axesDim[yaId] = i;\n    }\n\n    // fill in splom subplot keys\n    for(i = 0; i < xList.length; i++) {\n        for(j = 0; j < yList.length; j++) {\n            var id = xList[i] + yList[j];\n\n            if(i > j && showUpper) {\n                layout._splomSubplots[id] = 1;\n            } else if(i < j && showLower) {\n                layout._splomSubplots[id] = 1;\n            } else if(i === j && (showDiag || !showLower || !showUpper)) {\n                // need to include diagonal subplots when\n                // hiding one half and the diagonal\n                layout._splomSubplots[id] = 1;\n            }\n        }\n    }\n\n    // when lower half is omitted, or when just the diagonal is gone,\n    // override grid default to make sure axes remain on\n    // the left/bottom of the plot area\n    if(!showLower || (!showDiag && showUpper && showLower)) {\n        layout._splomGridDflt.xside = 'bottom';\n        layout._splomGridDflt.yside = 'left';\n    }\n}\n\n},{\"../../lib\":719,\"../../plots/array_container_defaults\":763,\"../parcoords/merge_length\":1083,\"../scatter/marker_defaults\":1130,\"../scatter/subtypes\":1135,\"./attributes\":1198}],1202:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar calcColorscale = _dereq_('../scatter/colorscale_calc');\nvar convertMarkerStyle = _dereq_('../scattergl/convert').markerStyle;\n\nmodule.exports = function editStyle(gd, cd0) {\n    var trace = cd0.trace;\n    var scene = gd._fullLayout._splomScenes[trace.uid];\n\n    if(scene) {\n        calcColorscale(gd, trace);\n\n        Lib.extendFlat(scene.matrixOptions, convertMarkerStyle(trace));\n        // TODO [un]selected styles?\n\n        var opts = Lib.extendFlat({}, scene.matrixOptions, scene.viewOpts);\n\n        // TODO this is too long for arrayOk attributes!\n        scene.matrix.update(opts, null);\n    }\n};\n\n},{\"../../lib\":719,\"../scatter/colorscale_calc\":1115,\"../scattergl/convert\":1163}],1203:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nexports.getDimIndex = function getDimIndex(trace, ax) {\n    var axId = ax._id;\n    var axLetter = axId.charAt(0);\n    var ind = {x: 0, y: 1}[axLetter];\n    var visibleDims = trace._visibleDims;\n\n    for(var k = 0; k < visibleDims.length; k++) {\n        var i = visibleDims[k];\n        if(trace._diag[i][ind] === axId) return k;\n    }\n    return false;\n};\n\n},{}],1204:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar helpers = _dereq_('./helpers');\nvar calcHover = _dereq_('../scattergl/hover').calcHover;\n\nfunction hoverPoints(pointData, xval, yval) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n    var scene = pointData.scene;\n    var cdata = scene.matrixOptions.cdata;\n    var xa = pointData.xa;\n    var ya = pointData.ya;\n    var xpx = xa.c2p(xval);\n    var ypx = ya.c2p(yval);\n    var maxDistance = pointData.distance;\n\n    var xi = helpers.getDimIndex(trace, xa);\n    var yi = helpers.getDimIndex(trace, ya);\n    if(xi === false || yi === false) return [pointData];\n\n    var x = cdata[xi];\n    var y = cdata[yi];\n\n    var id, dxy;\n    var minDist = maxDistance;\n\n    for(var i = 0; i < x.length; i++) {\n        var ptx = x[i];\n        var pty = y[i];\n        var dx = xa.c2p(ptx) - xpx;\n        var dy = ya.c2p(pty) - ypx;\n        var dist = Math.sqrt(dx * dx + dy * dy);\n\n        if(dist < minDist) {\n            minDist = dxy = dist;\n            id = i;\n        }\n    }\n\n    pointData.index = id;\n    pointData.distance = minDist;\n    pointData.dxy = dxy;\n\n    if(id === undefined) return [pointData];\n\n    calcHover(pointData, x, y, trace);\n\n    return [pointData];\n}\n\nmodule.exports = {\n    hoverPoints: hoverPoints\n};\n\n},{\"../scattergl/hover\":1166,\"./helpers\":1203}],1205:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Grid = _dereq_('../../components/grid');\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'splom',\n\n    basePlotModule: _dereq_('./base_plot'),\n    categories: ['gl', 'regl', 'cartesian', 'symbols', 'showLegend', 'scatter-like'],\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: _dereq_('../scatter/marker_colorbar'),\n\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n    hoverPoints: _dereq_('./hover').hoverPoints,\n    selectPoints: _dereq_('./select'),\n    editStyle: _dereq_('./edit_style'),\n\n    meta: {\n        \n    }\n};\n\n// splom traces use the 'grid' component to generate their axes,\n// register it here\nRegistry.register(Grid);\n\n},{\"../../components/grid\":636,\"../../registry\":847,\"../scatter/marker_colorbar\":1129,\"./attributes\":1198,\"./base_plot\":1199,\"./calc\":1200,\"./defaults\":1201,\"./edit_style\":1202,\"./hover\":1204,\"./plot\":1206,\"./select\":1208}],1206:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar createMatrix = _dereq_('regl-splom');\n\nvar Lib = _dereq_('../../lib');\nvar AxisIDs = _dereq_('../../plots/cartesian/axis_ids');\n\nmodule.exports = function plot(gd, _, splomCalcData) {\n    if(!splomCalcData.length) return;\n\n    for(var i = 0; i < splomCalcData.length; i++) {\n        plotOne(gd, splomCalcData[i][0]);\n    }\n};\n\nfunction plotOne(gd, cd0) {\n    var fullLayout = gd._fullLayout;\n    var gs = fullLayout._size;\n    var trace = cd0.trace;\n    var stash = cd0.t;\n    var scene = fullLayout._splomScenes[trace.uid];\n    var matrixOpts = scene.matrixOptions;\n    var cdata = matrixOpts.cdata;\n    var regl = fullLayout._glcanvas.data()[0].regl;\n    var dragmode = fullLayout.dragmode;\n    var xa, ya;\n    var i, j, k;\n\n    if(cdata.length === 0) return;\n\n    // augment options with proper upper/lower halves\n    // regl-splom's default grid starts from bottom-left\n    matrixOpts.lower = trace.showupperhalf;\n    matrixOpts.upper = trace.showlowerhalf;\n    matrixOpts.diagonal = trace.diagonal.visible;\n\n    var visibleDims = trace._visibleDims;\n    var visibleLength = cdata.length;\n    var viewOpts = scene.viewOpts = {};\n    viewOpts.ranges = new Array(visibleLength);\n    viewOpts.domains = new Array(visibleLength);\n\n    for(k = 0; k < visibleDims.length; k++) {\n        i = visibleDims[k];\n\n        var rng = viewOpts.ranges[k] = new Array(4);\n        var dmn = viewOpts.domains[k] = new Array(4);\n\n        xa = AxisIDs.getFromId(gd, trace._diag[i][0]);\n        if(xa) {\n            rng[0] = xa._rl[0];\n            rng[2] = xa._rl[1];\n            dmn[0] = xa.domain[0];\n            dmn[2] = xa.domain[1];\n        }\n\n        ya = AxisIDs.getFromId(gd, trace._diag[i][1]);\n        if(ya) {\n            rng[1] = ya._rl[0];\n            rng[3] = ya._rl[1];\n            dmn[1] = ya.domain[0];\n            dmn[3] = ya.domain[1];\n        }\n    }\n\n    viewOpts.viewport = [gs.l, gs.b, gs.w + gs.l, gs.h + gs.b];\n\n    if(scene.matrix === true) {\n        scene.matrix = createMatrix(regl);\n    }\n\n    var clickSelectEnabled = fullLayout.clickmode.indexOf('select') > -1;\n    var selectMode = dragmode === 'lasso' || dragmode === 'select' ||\n      !!trace.selectedpoints || clickSelectEnabled;\n    var needsBaseUpdate = true;\n\n    if(selectMode) {\n        var commonLength = trace._length;\n\n        // regenerate scene batch, if traces number changed during selection\n        if(trace.selectedpoints) {\n            scene.selectBatch = trace.selectedpoints;\n\n            var selPts = trace.selectedpoints;\n            var selDict = {};\n            for(i = 0; i < selPts.length; i++) {\n                selDict[selPts[i]] = true;\n            }\n            var unselPts = [];\n            for(i = 0; i < commonLength; i++) {\n                if(!selDict[i]) unselPts.push(i);\n            }\n            scene.unselectBatch = unselPts;\n        }\n\n        // precalculate px coords since we are not going to pan during select\n        var xpx = stash.xpx = new Array(visibleLength);\n        var ypx = stash.ypx = new Array(visibleLength);\n\n        for(k = 0; k < visibleDims.length; k++) {\n            i = visibleDims[k];\n\n            xa = AxisIDs.getFromId(gd, trace._diag[i][0]);\n            if(xa) {\n                xpx[k] = new Array(commonLength);\n                for(j = 0; j < commonLength; j++) {\n                    xpx[k][j] = xa.c2p(cdata[k][j]);\n                }\n            }\n\n            ya = AxisIDs.getFromId(gd, trace._diag[i][1]);\n            if(ya) {\n                ypx[k] = new Array(commonLength);\n                for(j = 0; j < commonLength; j++) {\n                    ypx[k][j] = ya.c2p(cdata[k][j]);\n                }\n            }\n        }\n\n        if(scene.selectBatch.length || scene.unselectBatch.length) {\n            var unselOpts = Lib.extendFlat({}, matrixOpts, scene.unselectedOptions, viewOpts);\n            var selOpts = Lib.extendFlat({}, matrixOpts, scene.selectedOptions, viewOpts);\n            scene.matrix.update(unselOpts, selOpts);\n            needsBaseUpdate = false;\n        }\n    } else {\n        stash.xpx = stash.ypx = null;\n    }\n\n    if(needsBaseUpdate) {\n        var opts = Lib.extendFlat({}, matrixOpts, viewOpts);\n        scene.matrix.update(opts, null);\n    }\n}\n\n},{\"../../lib\":719,\"../../plots/cartesian/axis_ids\":770,\"regl-splom\":501}],1207:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nmodule.exports = function sceneUpdate(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var uid = trace.uid;\n\n    // must place ref to 'scene' in fullLayout, so that:\n    // - it can be relinked properly on updates\n    // - it can be destroyed properly when needed\n    var splomScenes = fullLayout._splomScenes;\n    if(!splomScenes) splomScenes = fullLayout._splomScenes = {};\n\n    var reset = {dirty: true};\n\n    var first = {\n        matrix: false,\n        selectBatch: [],\n        unselectBatch: []\n    };\n\n    var scene = splomScenes[trace.uid];\n\n    if(!scene) {\n        scene = splomScenes[uid] = Lib.extendFlat({}, reset, first);\n\n        scene.draw = function draw() {\n            if(scene.matrix && scene.matrix.draw) {\n                if(scene.selectBatch.length || scene.unselectBatch.length) {\n                    scene.matrix.draw(scene.unselectBatch, scene.selectBatch);\n                } else {\n                    scene.matrix.draw();\n                }\n            }\n\n            scene.dirty = false;\n        };\n\n        // remove scene resources\n        scene.destroy = function destroy() {\n            if(scene.matrix && scene.matrix.destroy) {\n                scene.matrix.destroy();\n            }\n            scene.matrixOptions = null;\n            scene.selectBatch = null;\n            scene.unselectBatch = null;\n            scene = null;\n        };\n    }\n\n    // In case if we have scene from the last calc - reset data\n    if(!scene.dirty) {\n        Lib.extendFlat(scene, reset);\n    }\n\n    return scene;\n};\n\n},{\"../../lib\":719}],1208:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar subTypes = _dereq_('../scatter/subtypes');\nvar helpers = _dereq_('./helpers');\n\nmodule.exports = function select(searchInfo, selectionTester) {\n    var cd = searchInfo.cd;\n    var trace = cd[0].trace;\n    var stash = cd[0].t;\n    var scene = searchInfo.scene;\n    var cdata = scene.matrixOptions.cdata;\n    var xa = searchInfo.xaxis;\n    var ya = searchInfo.yaxis;\n    var selection = [];\n\n    if(!scene) return selection;\n\n    var hasOnlyLines = (!subTypes.hasMarkers(trace) && !subTypes.hasText(trace));\n    if(trace.visible !== true || hasOnlyLines) return selection;\n\n    var xi = helpers.getDimIndex(trace, xa);\n    var yi = helpers.getDimIndex(trace, ya);\n    if(xi === false || yi === false) return selection;\n\n    var xpx = stash.xpx[xi];\n    var ypx = stash.ypx[yi];\n    var x = cdata[xi];\n    var y = cdata[yi];\n    var els = [];\n    var unels = [];\n\n    // degenerate polygon does not enable selection\n    // filter out points by visible scatter ones\n    if(selectionTester !== false && !selectionTester.degenerate) {\n        for(var i = 0; i < x.length; i++) {\n            if(selectionTester.contains([xpx[i], ypx[i]], null, i, searchInfo)) {\n                els.push(i);\n                selection.push({\n                    pointNumber: i,\n                    x: x[i],\n                    y: y[i]\n                });\n            } else {\n                unels.push(i);\n            }\n        }\n    }\n\n    var matrixOpts = scene.matrixOptions;\n\n    if(!els.length && !unels.length) {\n        scene.matrix.update(matrixOpts, null);\n    } else if(!scene.selectBatch.length && !scene.unselectBatch.length) {\n        scene.matrix.update(\n            scene.unselectedOptions,\n            Lib.extendFlat({}, matrixOpts, scene.selectedOptions, scene.viewOpts)\n        );\n    }\n\n    scene.selectBatch = els;\n    scene.unselectBatch = unels;\n\n    return selection;\n};\n\n},{\"../../lib\":719,\"../scatter/subtypes\":1135,\"./helpers\":1203}],1209:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar mesh3dAttrs = _dereq_('../mesh3d/attributes');\nvar baseAttrs = _dereq_('../../plots/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nvar attrs = {\n    x: {\n        valType: 'data_array',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    y: {\n        valType: 'data_array',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n    z: {\n        valType: 'data_array',\n        \n        editType: 'calc+clearAxisTypes',\n        \n    },\n\n    u: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    v: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    w: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    starts: {\n        x: {\n            valType: 'data_array',\n            editType: 'calc',\n            \n        },\n        y: {\n            valType: 'data_array',\n            editType: 'calc',\n            \n        },\n        z: {\n            valType: 'data_array',\n            editType: 'calc',\n            \n        },\n        editType: 'calc'\n    },\n\n    maxdisplayed: {\n        valType: 'integer',\n        min: 0,\n        dflt: 1000,\n        \n        editType: 'calc',\n        \n    },\n\n    // TODO\n    //\n    // Should add 'absolute' (like cone traces have), but currently gl-streamtube3d's\n    // `absoluteTubeSize` doesn't behave well enough for our needs.\n    //\n    // 'fixed' would be a nice addition to plot stream 'lines', see\n    // https://github.com/plotly/plotly.js/commit/812be20750e21e0a1831975001c248d365850f73#r29129877\n    //\n    // sizemode: {\n    //     valType: 'enumerated',\n    //     values: ['scaled', 'absolute', 'fixed'],\n    //     dflt: 'scaled',\n    //     \n    //     editType: 'calc',\n    //     \n    // },\n\n    sizeref: {\n        valType: 'number',\n        \n        editType: 'calc',\n        min: 0,\n        dflt: 1,\n        \n    },\n\n    text: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'calc',\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'calc',\n        \n    },\n    hovertemplate: hovertemplateAttrs({editType: 'calc'}, {\n        keys: [\n            'tubex', 'tubey', 'tubez',\n            'tubeu', 'tubev', 'tubew',\n            'norm', 'divergence'\n        ]\n    })\n};\n\nextendFlat(attrs, colorScaleAttrs('', {\n    colorAttr: 'u/v/w norm',\n    showScaleDflt: true,\n    editTypeOverride: 'calc'\n}));\n\nvar fromMesh3d = ['opacity', 'lightposition', 'lighting'];\nfromMesh3d.forEach(function(k) {\n    attrs[k] = mesh3dAttrs[k];\n});\n\nattrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {\n    editType: 'calc',\n    flags: ['x', 'y', 'z', 'u', 'v', 'w', 'norm', 'divergence', 'text', 'name'],\n    dflt: 'x+y+z+norm+text+name'\n});\n\nattrs.transforms = undefined;\n\nmodule.exports = attrs;\n\n},{\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../mesh3d/attributes\":1053}],1210:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\n\nmodule.exports = function calc(gd, trace) {\n    var i;\n\n    var u = trace.u;\n    var v = trace.v;\n    var w = trace.w;\n    var x = trace.x;\n    var y = trace.y;\n    var z = trace.z;\n    var len = Math.min(x.length, y.length, z.length, u.length, v.length, w.length);\n\n    var slen = 0;\n    var startx, starty, startz;\n    if(trace.starts) {\n        startx = trace.starts.x || [];\n        starty = trace.starts.y || [];\n        startz = trace.starts.z || [];\n        slen = Math.min(startx.length, starty.length, startz.length);\n    }\n\n    var normMax = 0;\n    var normMin = Infinity;\n\n    for(i = 0; i < len; i++) {\n        var uu = u[i];\n        var vv = v[i];\n        var ww = w[i];\n        var norm = Math.sqrt(uu * uu + vv * vv + ww * ww);\n\n        normMax = Math.max(normMax, norm);\n        normMin = Math.min(normMin, norm);\n    }\n\n    colorscaleCalc(gd, trace, {\n        vals: [normMin, normMax],\n        containerStr: '',\n        cLetter: 'c'\n    });\n\n    var xMax = -Infinity;\n    var xMin = Infinity;\n    var yMax = -Infinity;\n    var yMin = Infinity;\n    var zMax = -Infinity;\n    var zMin = Infinity;\n\n    for(i = 0; i < len; i++) {\n        var xx = x[i];\n        xMax = Math.max(xMax, xx);\n        xMin = Math.min(xMin, xx);\n\n        var yy = y[i];\n        yMax = Math.max(yMax, yy);\n        yMin = Math.min(yMin, yy);\n\n        var zz = z[i];\n        zMax = Math.max(zMax, zz);\n        zMin = Math.min(zMin, zz);\n    }\n    for(i = 0; i < slen; i++) {\n        var sx = startx[i];\n        xMax = Math.max(xMax, sx);\n        xMin = Math.min(xMin, sx);\n\n        var sy = starty[i];\n        yMax = Math.max(yMax, sy);\n        yMin = Math.min(yMin, sy);\n\n        var sz = startz[i];\n        zMax = Math.max(zMax, sz);\n        zMin = Math.min(zMin, sz);\n    }\n\n    trace._len = len;\n    trace._slen = slen;\n    trace._normMax = normMax;\n    trace._xbnds = [xMin, xMax];\n    trace._ybnds = [yMin, yMax];\n    trace._zbnds = [zMin, zMax];\n};\n\n},{\"../../components/colorscale/calc\":601}],1211:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar tube2mesh = _dereq_('gl-streamtube3d');\nvar createTubeMesh = tube2mesh.createTubeMesh;\n\nvar Lib = _dereq_('../../lib');\nvar parseColorScale = _dereq_('../../lib/gl_format_color').parseColorScale;\nvar extractOpts = _dereq_('../../components/colorscale').extractOpts;\nvar zip3 = _dereq_('../../plots/gl3d/zip3');\n\nvar axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2};\n\nfunction Streamtube(scene, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.mesh = null;\n    this.data = null;\n}\n\nvar proto = Streamtube.prototype;\n\nproto.handlePick = function(selection) {\n    var sceneLayout = this.scene.fullSceneLayout;\n    var dataScale = this.scene.dataScale;\n\n    function fromDataScale(v, axisName) {\n        var ax = sceneLayout[axisName];\n        var scale = dataScale[axisName2scaleIndex[axisName]];\n        return ax.l2c(v) / scale;\n    }\n\n    if(selection.object === this.mesh) {\n        var pos = selection.data.position;\n        var uvx = selection.data.velocity;\n\n        selection.traceCoordinate = [\n            fromDataScale(pos[0], 'xaxis'),\n            fromDataScale(pos[1], 'yaxis'),\n            fromDataScale(pos[2], 'zaxis'),\n\n            fromDataScale(uvx[0], 'xaxis'),\n            fromDataScale(uvx[1], 'yaxis'),\n            fromDataScale(uvx[2], 'zaxis'),\n\n            // u/v/w norm\n            selection.data.intensity * this.data._normMax,\n            // divergence\n            selection.data.divergence\n        ];\n\n        selection.textLabel = this.data.hovertext || this.data.text;\n\n        return true;\n    }\n};\n\nfunction distinctVals(col) {\n    return Lib.distinctVals(col).vals;\n}\n\nfunction getDfltStartingPositions(vec) {\n    var len = vec.length;\n    var s;\n\n    if(len > 2) {\n        s = vec.slice(1, len - 1);\n    } else if(len === 2) {\n        s = [(vec[0] + vec[1]) / 2];\n    } else {\n        s = vec;\n    }\n    return s;\n}\n\nfunction getBoundPads(vec) {\n    var len = vec.length;\n    if(len === 1) {\n        return [0.5, 0.5];\n    } else {\n        return [vec[1] - vec[0], vec[len - 1] - vec[len - 2]];\n    }\n}\n\nfunction convert(scene, trace) {\n    var sceneLayout = scene.fullSceneLayout;\n    var dataScale = scene.dataScale;\n    var len = trace._len;\n    var tubeOpts = {};\n\n    function toDataCoords(arr, axisName) {\n        var ax = sceneLayout[axisName];\n        var scale = dataScale[axisName2scaleIndex[axisName]];\n        return Lib.simpleMap(arr, function(v) { return ax.d2l(v) * scale; });\n    }\n\n    tubeOpts.vectors = zip3(\n        toDataCoords(trace.u, 'xaxis'),\n        toDataCoords(trace.v, 'yaxis'),\n        toDataCoords(trace.w, 'zaxis'),\n        len\n    );\n\n    var valsx = distinctVals(trace.x.slice(0, len));\n    var valsy = distinctVals(trace.y.slice(0, len));\n    var valsz = distinctVals(trace.z.slice(0, len));\n\n    // Over-specified mesh case, this would error in tube2mesh\n    if(valsx.length * valsy.length * valsz.length > len) {\n        return {positions: [], cells: []};\n    }\n\n    var meshx = toDataCoords(valsx, 'xaxis');\n    var meshy = toDataCoords(valsy, 'yaxis');\n    var meshz = toDataCoords(valsz, 'zaxis');\n\n    tubeOpts.meshgrid = [meshx, meshy, meshz];\n\n    if(trace.starts) {\n        var slen = trace._slen;\n        tubeOpts.startingPositions = zip3(\n            toDataCoords(trace.starts.x.slice(0, slen), 'xaxis'),\n            toDataCoords(trace.starts.y.slice(0, slen), 'yaxis'),\n            toDataCoords(trace.starts.z.slice(0, slen), 'zaxis')\n        );\n    } else {\n        // Default starting positions:\n        //\n        // if len>2, cut xz plane at min-y,\n        // takes all x/y/z pts on that plane except those on the edges\n        // to generate \"well-defined\" tubes,\n        //\n        // if len=2, take position halfway between two the pts,\n        //\n        // if len=1, take that pt\n        var sy0 = meshy[0];\n        var sx = getDfltStartingPositions(meshx);\n        var sz = getDfltStartingPositions(meshz);\n        var startingPositions = new Array(sx.length * sz.length);\n        var m = 0;\n\n        for(var i = 0; i < sx.length; i++) {\n            for(var k = 0; k < sz.length; k++) {\n                startingPositions[m++] = [sx[i], sy0, sz[k]];\n            }\n        }\n        tubeOpts.startingPositions = startingPositions;\n    }\n\n    tubeOpts.colormap = parseColorScale(trace);\n    tubeOpts.tubeSize = trace.sizeref;\n    tubeOpts.maxLength = trace.maxdisplayed;\n\n    // add some padding around the bounds\n    // to e.g. allow tubes starting from a slice of the x/y/z mesh\n    // to go beyond bounds a little bit w/o getting clipped\n    var xbnds = toDataCoords(trace._xbnds, 'xaxis');\n    var ybnds = toDataCoords(trace._ybnds, 'yaxis');\n    var zbnds = toDataCoords(trace._zbnds, 'zaxis');\n    var xpads = getBoundPads(meshx);\n    var ypads = getBoundPads(meshy);\n    var zpads = getBoundPads(meshz);\n\n    var bounds = [\n        [xbnds[0] - xpads[0], ybnds[0] - ypads[0], zbnds[0] - zpads[0]],\n        [xbnds[1] + xpads[1], ybnds[1] + ypads[1], zbnds[1] + zpads[1]]\n    ];\n\n    var meshData = tube2mesh(tubeOpts, bounds);\n\n    // N.B. cmin/cmax correspond to the min/max vector norm\n    // in the u/v/w arrays, which in general is NOT equal to max\n    // intensity that colors the tubes.\n    var cOpts = extractOpts(trace);\n    meshData.vertexIntensityBounds = [cOpts.min / trace._normMax, cOpts.max / trace._normMax];\n\n    // pass gl-mesh3d lighting attributes\n    var lp = trace.lightposition;\n    meshData.lightPosition = [lp.x, lp.y, lp.z];\n    meshData.ambient = trace.lighting.ambient;\n    meshData.diffuse = trace.lighting.diffuse;\n    meshData.specular = trace.lighting.specular;\n    meshData.roughness = trace.lighting.roughness;\n    meshData.fresnel = trace.lighting.fresnel;\n    meshData.opacity = trace.opacity;\n\n    // stash autorange pad value\n    trace._pad = meshData.tubeScale * trace.sizeref * 2;\n\n    return meshData;\n}\n\nproto.update = function(data) {\n    this.data = data;\n\n    var meshData = convert(this.scene, data);\n    this.mesh.update(meshData);\n};\n\nproto.dispose = function() {\n    this.scene.glplot.remove(this.mesh);\n    this.mesh.dispose();\n};\n\nfunction createStreamtubeTrace(scene, data) {\n    var gl = scene.glplot.gl;\n\n    var meshData = convert(scene, data);\n    var mesh = createTubeMesh(gl, meshData);\n\n    var streamtube = new Streamtube(scene, data.uid);\n    streamtube.mesh = mesh;\n    streamtube.data = data;\n    mesh._trace = streamtube;\n\n    scene.glplot.add(mesh);\n\n    return streamtube;\n}\n\nmodule.exports = createStreamtubeTrace;\n\n},{\"../../components/colorscale\":605,\"../../lib\":719,\"../../lib/gl_format_color\":716,\"../../plots/gl3d/zip3\":818,\"gl-streamtube3d\":313}],1212:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var u = coerce('u');\n    var v = coerce('v');\n    var w = coerce('w');\n\n    var x = coerce('x');\n    var y = coerce('y');\n    var z = coerce('z');\n\n    if(\n        !u || !u.length || !v || !v.length || !w || !w.length ||\n        !x || !x.length || !y || !y.length || !z || !z.length\n    ) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('starts.x');\n    coerce('starts.y');\n    coerce('starts.z');\n\n    coerce('maxdisplayed');\n    coerce('sizeref');\n\n    coerce('lighting.ambient');\n    coerce('lighting.diffuse');\n    coerce('lighting.specular');\n    coerce('lighting.roughness');\n    coerce('lighting.fresnel');\n    coerce('lightposition.x');\n    coerce('lightposition.y');\n    coerce('lightposition.z');\n\n    colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    // disable 1D transforms (for now)\n    // x/y/z and u/v/w have matching lengths,\n    // but they don't have to match with starts.(x|y|z)\n    traceOut._length = null;\n};\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"./attributes\":1209}],1213:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'streamtube',\n    basePlotModule: _dereq_('../../plots/gl3d'),\n    categories: ['gl3d'],\n\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: {\n        min: 'cmin',\n        max: 'cmax'\n    },\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./convert'),\n    eventData: function(out, pt) {\n        out.tubex = out.x;\n        out.tubey = out.y;\n        out.tubez = out.z;\n\n        out.tubeu = pt.traceCoordinate[3];\n        out.tubev = pt.traceCoordinate[4];\n        out.tubew = pt.traceCoordinate[5];\n\n        out.norm = pt.traceCoordinate[6];\n        out.divergence = pt.traceCoordinate[7];\n\n        // Does not correspond to input x/y/z, so delete them\n        delete out.x;\n        delete out.y;\n        delete out.z;\n\n        return out;\n    },\n\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/gl3d\":807,\"./attributes\":1209,\"./calc\":1210,\"./convert\":1211,\"./defaults\":1212}],1214:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\nvar pieAtts = _dereq_('../pie/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = {\n    labels: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    parents: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n\n    values: {\n        valType: 'data_array',\n        editType: 'calc',\n        \n    },\n    branchvalues: {\n        valType: 'enumerated',\n        values: ['remainder', 'total'],\n        dflt: 'remainder',\n        editType: 'calc',\n        \n        \n    },\n\n    level: {\n        valType: 'any',\n        editType: 'plot',\n        anim: true,\n        \n        \n    },\n    maxdepth: {\n        valType: 'integer',\n        editType: 'plot',\n        \n        dflt: -1,\n        \n    },\n\n    marker: {\n        colors: {\n            valType: 'data_array',\n            editType: 'calc',\n            \n        },\n\n        // colorinheritance: {\n        //     valType: 'enumerated',\n        //     values: ['per-branch', 'per-label', false]\n        // },\n\n        line: {\n            color: extendFlat({}, pieAtts.marker.line.color, {\n                dflt: null,\n                \n            }),\n            width: extendFlat({}, pieAtts.marker.line.width, {dflt: 1}),\n            editType: 'calc'\n        },\n        editType: 'calc'\n    },\n\n    leaf: {\n        opacity: {\n            valType: 'number',\n            editType: 'style',\n            \n            min: 0,\n            max: 1,\n            dflt: 0.7,\n            \n        },\n        editType: 'plot'\n    },\n\n    text: pieAtts.text,\n    textinfo: extendFlat({}, pieAtts.textinfo, {\n        editType: 'plot',\n        flags: ['label', 'text', 'value']\n    }),\n    textfont: pieAtts.textfont,\n\n    hovertext: pieAtts.hovertext,\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['label', 'text', 'value', 'name']\n    }),\n    hovertemplate: hovertemplateAttrs(),\n\n    insidetextfont: pieAtts.insidetextfont,\n    outsidetextfont: pieAtts.outsidetextfont,\n\n    domain: domainAttrs({name: 'sunburst', trace: true, editType: 'calc'})\n};\n\n},{\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../../plots/domain\":792,\"../pie/attributes\":1086}],1215:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\n\nvar name = exports.name = 'sunburst';\n\nexports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {\n    var _module = Registry.getModule(name);\n    var cdmodule = getModuleCalcData(gd.calcdata, _module)[0];\n    _module.plot(gd, cdmodule, transitionOpts, makeOnCompleteCallback);\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var had = (oldFullLayout._has && oldFullLayout._has(name));\n    var has = (newFullLayout._has && newFullLayout._has(name));\n\n    if(had && !has) {\n        oldFullLayout._sunburstlayer.selectAll('g.trace').remove();\n    }\n};\n\n},{\"../../plots/get_data\":802,\"../../registry\":847}],1216:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3Hierarchy = _dereq_('d3-hierarchy');\nvar isNumeric = _dereq_('fast-isnumeric');\n\nvar Lib = _dereq_('../../lib');\nvar makePullColorFn = _dereq_('../pie/calc').makePullColorFn;\nvar generateExtendedColors = _dereq_('../pie/calc').generateExtendedColors;\n\nvar isArrayOrTypedArray = Lib.isArrayOrTypedArray;\n\nvar sunburstExtendedColorWays = {};\n\nexports.calc = function(gd, trace) {\n    var fullLayout = gd._fullLayout;\n    var ids = trace.ids;\n    var hasIds = isArrayOrTypedArray(ids);\n    var labels = trace.labels;\n    var parents = trace.parents;\n    var vals = trace.values;\n    var hasVals = isArrayOrTypedArray(vals);\n    var cd = [];\n\n    var parent2children = {};\n    var refs = {};\n    var addToLookup = function(parent, v) {\n        if(parent2children[parent]) parent2children[parent].push(v);\n        else parent2children[parent] = [v];\n        refs[v] = 1;\n    };\n\n    // treat number `0` as valid\n    var isValidKey = function(k) {\n        return k || typeof k === 'number';\n    };\n\n    var isValidVal = function(i) {\n        return !hasVals || (isNumeric(vals[i]) && vals[i] >= 0);\n    };\n\n    var len;\n    var isValid;\n    var getId;\n\n    if(hasIds) {\n        len = Math.min(ids.length, parents.length);\n        isValid = function(i) { return isValidKey(ids[i]) && isValidVal(i); };\n        getId = function(i) { return String(ids[i]); };\n    } else {\n        len = Math.min(labels.length, parents.length);\n        isValid = function(i) { return isValidKey(labels[i]) && isValidVal(i); };\n        // TODO We could allow some label / parent duplication\n        //\n        // From AJ:\n        //  It would work OK for one level\n        //  (multiple rows with the same name and different parents -\n        //  or even the same parent) but if that name is then used as a parent\n        //  which one is it?\n        getId = function(i) { return String(labels[i]); };\n    }\n\n    if(hasVals) len = Math.min(len, vals.length);\n\n    for(var i = 0; i < len; i++) {\n        if(isValid(i)) {\n            var id = getId(i);\n            var pid = isValidKey(parents[i]) ? String(parents[i]) : '';\n\n            var cdi = {\n                i: i,\n                id: id,\n                pid: pid,\n                label: isValidKey(labels[i]) ? String(labels[i]) : ''\n            };\n\n            if(hasVals) cdi.v = +vals[i];\n            cd.push(cdi);\n            addToLookup(pid, id);\n        }\n    }\n\n    if(!parent2children['']) {\n        var impliedRoots = [];\n        var k;\n        for(k in parent2children) {\n            if(!refs[k]) {\n                impliedRoots.push(k);\n            }\n        }\n\n        // if an `id` has no ref in the `parents` array,\n        // take it as being the root node\n\n        if(impliedRoots.length === 1) {\n            k = impliedRoots[0];\n            cd.unshift({\n                id: k,\n                pid: '',\n                label: k\n            });\n        } else {\n            return Lib.warn('Multiple implied roots, cannot build sunburst hierarchy.');\n        }\n    } else if(parent2children[''].length > 1) {\n        var dummyId = Lib.randstr();\n\n        // if multiple rows linked to the root node,\n        // add dummy \"root of roots\" node to make d3 build the hierarchy successfully\n\n        for(var j = 0; j < cd.length; j++) {\n            if(cd[j].pid === '') {\n                cd[j].pid = dummyId;\n            }\n        }\n\n        cd.unshift({\n            hasMultipleRoots: true,\n            id: dummyId,\n            pid: ''\n        });\n    }\n\n    // TODO might be better to replace stratify() with our own algorithm\n    var root;\n    try {\n        root = d3Hierarchy.stratify()\n            .id(function(d) { return d.id; })\n            .parentId(function(d) { return d.pid; })(cd);\n    } catch(e) {\n        return Lib.warn('Failed to build sunburst hierarchy. Error: ' + e.message);\n    }\n\n    var hierarchy = d3Hierarchy.hierarchy(root);\n    var failed = false;\n\n    if(hasVals) {\n        switch(trace.branchvalues) {\n            case 'remainder':\n                hierarchy.sum(function(d) { return d.data.v; });\n                break;\n            case 'total':\n                hierarchy.each(function(d) {\n                    var v = d.data.data.v;\n\n                    if(d.children) {\n                        var partialSum = d.children.reduce(function(a, c) {\n                            return a + c.data.data.v;\n                        }, 0);\n                        if(v < partialSum) {\n                            failed = true;\n                            return Lib.warn([\n                                'Total value for node', d.data.data.id,\n                                'is smaller than the sum of its children.'\n                            ].join(' '));\n                        }\n                    }\n\n                    d.value = v;\n                });\n                break;\n        }\n    } else {\n        hierarchy.count();\n    }\n\n    if(failed) return;\n\n    // TODO add way to sort by height also?\n    hierarchy.sort(function(a, b) { return b.value - a.value; });\n\n    var colors = trace.marker.colors || [];\n    var pullColor = makePullColorFn(fullLayout._sunburstcolormap);\n\n    // TODO keep track of 'root-children' (i.e. branch) for hover info etc.\n\n    hierarchy.each(function(d) {\n        var cdi = d.data.data;\n        var id = cdi.id;\n        // N.B. this mutates items in `cd`\n        cdi.color = pullColor(colors[cdi.i], id);\n    });\n\n    cd[0].hierarchy = hierarchy;\n\n    return cd;\n};\n\n/*\n * `calc` filled in (and collated) explicit colors.\n * Now we need to propagate these explicit colors to other traces,\n * and fill in default colors.\n * This is done after sorting, so we pick defaults\n * in the order slices will be displayed\n */\nexports.crossTraceCalc = function(gd) {\n    var fullLayout = gd._fullLayout;\n    var calcdata = gd.calcdata;\n    var colorWay = fullLayout.sunburstcolorway;\n    var colorMap = fullLayout._sunburstcolormap;\n\n    if(fullLayout.extendsunburstcolors) {\n        colorWay = generateExtendedColors(colorWay, sunburstExtendedColorWays);\n    }\n    var dfltColorCount = 0;\n\n    function pickColor(d) {\n        var cdi = d.data.data;\n        var id = cdi.id;\n\n        if(cdi.color === false) {\n            if(colorMap[id]) {\n                // have we seen this label and assigned a color to it in a previous trace?\n                cdi.color = colorMap[id];\n            } else if(d.parent) {\n                if(d.parent.parent) {\n                    // from third-level on, inherit from parent\n                    cdi.color = d.parent.data.data.color;\n                } else {\n                    // pick new color for second level\n                    colorMap[id] = cdi.color = colorWay[dfltColorCount % colorWay.length];\n                    dfltColorCount++;\n                }\n            } else {\n                // root gets no coloring by default\n                cdi.color = 'rgba(0,0,0,0)';\n            }\n        }\n    }\n\n    for(var i = 0; i < calcdata.length; i++) {\n        var cd = calcdata[i];\n        var cd0 = cd[0];\n        if(cd0.trace.type === 'sunburst' && cd0.hierarchy) {\n            cd0.hierarchy.each(pickColor);\n        }\n    }\n};\n\n},{\"../../lib\":719,\"../pie/calc\":1088,\"d3-hierarchy\":157,\"fast-isnumeric\":225}],1217:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    CLICK_TRANSITION_TIME: 750,\n    CLICK_TRANSITION_EASING: 'linear'\n};\n\n},{}],1218:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attributes = _dereq_('./attributes');\nvar handleDomainDefaults = _dereq_('../../plots/domain').defaults;\nvar handleText = _dereq_('../bar/defaults').handleText;\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var labels = coerce('labels');\n    var parents = coerce('parents');\n\n    if(!labels || !labels.length || !parents || !parents.length) {\n        traceOut.visible = false;\n        return;\n    }\n\n    var vals = coerce('values');\n    if(vals && vals.length) coerce('branchvalues');\n\n    coerce('level');\n    coerce('maxdepth');\n\n    var lineWidth = coerce('marker.line.width');\n    if(lineWidth) coerce('marker.line.color', layout.paper_bgcolor);\n\n    coerce('marker.colors');\n\n    coerce('leaf.opacity');\n\n    var text = coerce('text');\n    coerce('textinfo', Array.isArray(text) ? 'text+label' : 'label');\n\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    var textposition = 'auto';\n    handleText(traceIn, traceOut, layout, coerce, textposition, {\n        moduleHasSelected: false,\n        moduleHasUnselected: false,\n        moduleHasConstrain: false,\n        moduleHasCliponaxis: false,\n        moduleHasTextangle: false,\n        moduleHasInsideanchor: false\n    });\n\n    handleDomainDefaults(traceOut, layout, coerce);\n\n    // do not support transforms for now\n    traceOut._length = null;\n};\n\n},{\"../../lib\":719,\"../../plots/domain\":792,\"../bar/defaults\":861,\"./attributes\":1214}],1219:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    moduleType: 'trace',\n    name: 'sunburst',\n    basePlotModule: _dereq_('./base_plot'),\n    categories: [],\n    animatable: true,\n\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n\n    calc: _dereq_('./calc').calc,\n    crossTraceCalc: _dereq_('./calc').crossTraceCalc,\n\n    plot: _dereq_('./plot'),\n    style: _dereq_('./style').style,\n\n    meta: {\n        \n    }\n};\n\n},{\"./attributes\":1214,\"./base_plot\":1215,\"./calc\":1216,\"./defaults\":1218,\"./layout_attributes\":1220,\"./layout_defaults\":1221,\"./plot\":1222,\"./style\":1223}],1220:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    sunburstcolorway: {\n        valType: 'colorlist',\n        \n        editType: 'calc',\n        \n    },\n    extendsunburstcolors: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        \n    }\n};\n\n},{}],1221:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n    coerce('sunburstcolorway', layoutOut.colorway);\n    coerce('extendsunburstcolors');\n};\n\n},{\"../../lib\":719,\"./layout_attributes\":1220}],1222:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar d3Hierarchy = _dereq_('d3-hierarchy');\n\nvar Registry = _dereq_('../../registry');\nvar Fx = _dereq_('../../components/fx');\nvar Color = _dereq_('../../components/color');\nvar Drawing = _dereq_('../../components/drawing');\nvar Lib = _dereq_('../../lib');\nvar Events = _dereq_('../../lib/events');\nvar svgTextUtils = _dereq_('../../lib/svg_text_utils');\nvar setCursor = _dereq_('../../lib/setcursor');\nvar appendArrayPointValue = _dereq_('../../components/fx/helpers').appendArrayPointValue;\n\nvar transformInsideText = _dereq_('../pie/plot').transformInsideText;\nvar formatPieValue = _dereq_('../pie/helpers').formatPieValue;\nvar styleOne = _dereq_('./style').styleOne;\n\nvar constants = _dereq_('./constants');\n\nmodule.exports = function(gd, cdmodule, transitionOpts, makeOnCompleteCallback) {\n    var fullLayout = gd._fullLayout;\n    var layer = fullLayout._sunburstlayer;\n    var join, onComplete;\n\n    // If transition config is provided, then it is only a partial replot and traces not\n    // updated are removed.\n    var isFullReplot = !transitionOpts;\n    var hasTransition = transitionOpts && transitionOpts.duration > 0;\n\n    join = layer.selectAll('g.trace.sunburst')\n        .data(cdmodule, function(cd) { return cd[0].trace.uid; });\n\n    // using same 'stroke-linejoin' as pie traces\n    join.enter().append('g')\n        .classed('trace', true)\n        .classed('sunburst', true)\n        .attr('stroke-linejoin', 'round');\n\n    join.order();\n\n    if(hasTransition) {\n        if(makeOnCompleteCallback) {\n            // If it was passed a callback to register completion, make a callback. If\n            // this is created, then it must be executed on completion, otherwise the\n            // pos-transition redraw will not execute:\n            onComplete = makeOnCompleteCallback();\n        }\n\n        var transition = d3.transition()\n            .duration(transitionOpts.duration)\n            .ease(transitionOpts.easing)\n            .each('end', function() { onComplete && onComplete(); })\n            .each('interrupt', function() { onComplete && onComplete(); });\n\n        transition.each(function() {\n            // Must run the selection again since otherwise enters/updates get grouped together\n            // and these get executed out of order. Except we need them in order!\n            layer.selectAll('g.trace').each(function(cd) {\n                plotOne(gd, cd, this, transitionOpts);\n            });\n        });\n    } else {\n        join.each(function(cd) {\n            plotOne(gd, cd, this, transitionOpts);\n        });\n    }\n\n    if(isFullReplot) {\n        join.exit().remove();\n    }\n};\n\nfunction plotOne(gd, cd, element, transitionOpts) {\n    var fullLayout = gd._fullLayout;\n    // We could optimize hasTransition per trace,\n    // as sunburst has no cross-trace logic!\n    var hasTransition = transitionOpts && transitionOpts.duration > 0;\n\n    var gTrace = d3.select(element);\n    var slices = gTrace.selectAll('g.slice');\n\n    var cd0 = cd[0];\n    var trace = cd0.trace;\n    var hierarchy = cd0.hierarchy;\n    var entry = findEntryWithLevel(hierarchy, trace.level);\n    var maxDepth = trace.maxdepth >= 0 ? trace.maxdepth : Infinity;\n\n    var gs = fullLayout._size;\n    var domain = trace.domain;\n    var vpw = gs.w * (domain.x[1] - domain.x[0]);\n    var vph = gs.h * (domain.y[1] - domain.y[0]);\n    var rMax = 0.5 * Math.min(vpw, vph);\n    var cx = cd0.cx = gs.l + gs.w * (domain.x[1] + domain.x[0]) / 2;\n    var cy = cd0.cy = gs.t + gs.h * (1 - domain.y[0]) - vph / 2;\n\n    if(!entry) {\n        return slices.remove();\n    }\n\n    // previous root 'pt' (can be empty)\n    var prevEntry = null;\n    // stash of 'previous' position data used by tweening functions\n    var prevLookup = {};\n\n    if(hasTransition) {\n        // Important: do this before binding new sliceData!\n        slices.each(function(pt) {\n            prevLookup[getPtId(pt)] = {\n                rpx0: pt.rpx0,\n                rpx1: pt.rpx1,\n                x0: pt.x0,\n                x1: pt.x1,\n                transform: pt.transform\n            };\n\n            if(!prevEntry && isEntry(pt)) {\n                prevEntry = pt;\n            }\n        });\n    }\n\n    // N.B. slice data isn't the calcdata,\n    // grab corresponding calcdata item in sliceData[i].data.data\n    var sliceData = partition(entry).descendants();\n    var maxHeight = entry.height + 1;\n    var yOffset = 0;\n    var cutoff = maxDepth;\n\n    // N.B. handle multiple-root special case\n    if(cd0.hasMultipleRoots && isHierachyRoot(entry)) {\n        sliceData = sliceData.slice(1);\n        maxHeight -= 1;\n        yOffset = 1;\n        cutoff += 1;\n    }\n\n    // filter out slices that won't show up on graph\n    sliceData = sliceData.filter(function(pt) { return pt.y1 <= cutoff; });\n\n    // partition span ('y') to sector radial px value\n    var maxY = Math.min(maxHeight, maxDepth);\n    var y2rpx = function(y) { return (y - yOffset) / maxY * rMax; };\n    // (radial px value, partition angle ('x'))  to px [x,y]\n    var rx2px = function(r, x) { return [r * Math.cos(x), -r * Math.sin(x)]; };\n    // slice path generation fn\n    var pathSlice = function(d) { return Lib.pathAnnulus(d.rpx0, d.rpx1, d.x0, d.x1, cx, cy); };\n    // slice text translate x/y\n    var transTextX = function(d) { return cx + d.pxmid[0] * d.transform.rCenter + (d.transform.x || 0); };\n    var transTextY = function(d) { return cy + d.pxmid[1] * d.transform.rCenter + (d.transform.y || 0); };\n\n    slices = slices.data(sliceData, function(pt) { return getPtId(pt); });\n\n    slices.enter().append('g')\n        .classed('slice', true);\n\n    if(hasTransition) {\n        slices.exit().transition()\n            .each(function() {\n                var sliceTop = d3.select(this);\n\n                var slicePath = sliceTop.select('path.surface');\n                slicePath.transition().attrTween('d', function(pt2) {\n                    var interp = makeExitSliceInterpolator(pt2);\n                    return function(t) { return pathSlice(interp(t)); };\n                });\n\n                var sliceTextGroup = sliceTop.select('g.slicetext');\n                sliceTextGroup.attr('opacity', 0);\n            })\n            .remove();\n    } else {\n        slices.exit().remove();\n    }\n\n    slices.order();\n\n    // next x1 (i.e. sector end angle) of previous entry\n    var nextX1ofPrevEntry = null;\n    if(hasTransition && prevEntry) {\n        var prevEntryId = getPtId(prevEntry);\n        slices.each(function(pt) {\n            if(nextX1ofPrevEntry === null && (getPtId(pt) === prevEntryId)) {\n                nextX1ofPrevEntry = pt.x1;\n            }\n        });\n    }\n\n    var updateSlices = slices;\n    if(hasTransition) {\n        updateSlices = updateSlices.transition().each('end', function() {\n            // N.B. gd._transitioning is (still) *true* by the time\n            // transition updates get hare\n            var sliceTop = d3.select(this);\n            setSliceCursor(sliceTop, gd, {isTransitioning: false});\n        });\n    }\n\n    updateSlices.each(function(pt) {\n        var sliceTop = d3.select(this);\n\n        var slicePath = Lib.ensureSingle(sliceTop, 'path', 'surface', function(s) {\n            s.style('pointer-events', 'all');\n        });\n\n        pt.rpx0 = y2rpx(pt.y0);\n        pt.rpx1 = y2rpx(pt.y1);\n        pt.xmid = (pt.x0 + pt.x1) / 2;\n        pt.pxmid = rx2px(pt.rpx1, pt.xmid);\n        pt.midangle = -(pt.xmid - Math.PI / 2);\n        pt.halfangle = 0.5 * Math.min(Lib.angleDelta(pt.x0, pt.x1) || Math.PI, Math.PI);\n        pt.ring = 1 - (pt.rpx0 / pt.rpx1);\n        pt.rInscribed = getInscribedRadiusFraction(pt, trace);\n\n        if(hasTransition) {\n            slicePath.transition().attrTween('d', function(pt2) {\n                var interp = makeUpdateSliceIntepolator(pt2);\n                return function(t) { return pathSlice(interp(t)); };\n            });\n        } else {\n            slicePath.attr('d', pathSlice);\n        }\n\n        sliceTop\n            .call(attachFxHandlers, gd, cd)\n            .call(setSliceCursor, gd, {isTransitioning: gd._transitioning});\n\n        slicePath.call(styleOne, pt, trace);\n\n        var sliceTextGroup = Lib.ensureSingle(sliceTop, 'g', 'slicetext');\n        var sliceText = Lib.ensureSingle(sliceTextGroup, 'text', '', function(s) {\n            // prohibit tex interpretation until we can handle\n            // tex and regular text together\n            s.attr('data-notex', 1);\n        });\n\n        sliceText.text(formatSliceLabel(pt, trace, fullLayout))\n            .classed('slicetext', true)\n            .attr('text-anchor', 'middle')\n            .call(Drawing.font, isHierachyRoot(pt) ?\n              determineOutsideTextFont(trace, pt, fullLayout.font) :\n              determineInsideTextFont(trace, pt, fullLayout.font))\n            .call(svgTextUtils.convertToTspans, gd);\n\n        // position the text relative to the slice\n        var textBB = Drawing.bBox(sliceText.node());\n        pt.transform = transformInsideText(textBB, pt, cd0);\n        pt.translateX = transTextX(pt);\n        pt.translateY = transTextY(pt);\n\n        var strTransform = function(d, textBB) {\n            return 'translate(' + d.translateX + ',' + d.translateY + ')' +\n                (d.transform.scale < 1 ? ('scale(' + d.transform.scale + ')') : '') +\n                (d.transform.rotate ? ('rotate(' + d.transform.rotate + ')') : '') +\n                'translate(' +\n                    (-(textBB.left + textBB.right) / 2) + ',' +\n                    (-(textBB.top + textBB.bottom) / 2) +\n                ')';\n        };\n\n        if(hasTransition) {\n            sliceText.transition().attrTween('transform', function(pt2) {\n                var interp = makeUpdateTextInterpolar(pt2);\n                return function(t) { return strTransform(interp(t), textBB); };\n            });\n        } else {\n            sliceText.attr('transform', strTransform(pt, textBB));\n        }\n    });\n\n    function makeExitSliceInterpolator(pt) {\n        var id = getPtId(pt);\n        var prev = prevLookup[id];\n        var entryPrev = prevLookup[getPtId(entry)];\n        var next;\n\n        if(entryPrev) {\n            var a = pt.x1 > entryPrev.x1 ? 2 * Math.PI : 0;\n            // if pt to remove:\n            // - if 'below' where the root-node used to be: shrink it radially inward\n            // - otherwise, collapse it clockwise or counterclockwise which ever is shortest to theta=0\n            next = pt.rpx1 < entryPrev.rpx1 ? {rpx0: 0, rpx1: 0} : {x0: a, x1: a};\n        } else {\n            // this happens when maxdepth is set, when leaves must\n            // be removed and the rootPt is new (i.e. does not have a 'prev' object)\n            var parent;\n            var parentId = getPtId(pt.parent);\n            slices.each(function(pt2) {\n                if(getPtId(pt2) === parentId) {\n                    return parent = pt2;\n                }\n            });\n            var parentChildren = parent.children;\n            var ci;\n            parentChildren.forEach(function(pt2, i) {\n                if(getPtId(pt2) === id) {\n                    return ci = i;\n                }\n            });\n            var n = parentChildren.length;\n            var interp = d3.interpolate(parent.x0, parent.x1);\n            next = {\n                rpx0: rMax, rpx1: rMax,\n                x0: interp(ci / n), x1: interp((ci + 1) / n)\n            };\n        }\n\n        return d3.interpolate(prev, next);\n    }\n\n    function makeUpdateSliceIntepolator(pt) {\n        var prev0 = prevLookup[getPtId(pt)];\n        var prev;\n        var next = {x0: pt.x0, x1: pt.x1, rpx0: pt.rpx0, rpx1: pt.rpx1};\n\n        if(prev0) {\n            // if pt already on graph, this is easy\n            prev = prev0;\n        } else {\n            // for new pts:\n            if(prevEntry) {\n                // if trace was visible before\n                if(pt.parent) {\n                    if(nextX1ofPrevEntry) {\n                        // if new branch, twist it in clockwise or\n                        // counterclockwise which ever is shorter to\n                        // its final angle\n                        var a = pt.x1 > nextX1ofPrevEntry ? 2 * Math.PI : 0;\n                        prev = {x0: a, x1: a};\n                    } else {\n                        // if new leaf (when maxdepth is set),\n                        // grow it radially and angularly from\n                        // its parent node\n                        prev = {rpx0: rMax, rpx1: rMax};\n                        Lib.extendFlat(prev, interpX0X1FromParent(pt));\n                    }\n                } else {\n                    // if new root-node, grow it radially\n                    prev = {rpx0: 0, rpx1: 0};\n                }\n            } else {\n                // start sector of new traces from theta=0\n                prev = {x0: 0, x1: 0};\n            }\n        }\n\n        return d3.interpolate(prev, next);\n    }\n\n    function makeUpdateTextInterpolar(pt) {\n        var prev0 = prevLookup[getPtId(pt)];\n        var prev;\n        var transform = pt.transform;\n\n        if(prev0) {\n            prev = prev0;\n        } else {\n            prev = {\n                rpx1: pt.rpx1,\n                transform: {\n                    scale: 0,\n                    rotate: transform.rotate,\n                    rCenter: transform.rCenter,\n                    x: transform.x,\n                    y: transform.y\n                }\n            };\n\n            // for new pts:\n            if(prevEntry) {\n                // if trace was visible before\n                if(pt.parent) {\n                    if(nextX1ofPrevEntry) {\n                        // if new branch, twist it in clockwise or\n                        // counterclockwise which ever is shorter to\n                        // its final angle\n                        var a = pt.x1 > nextX1ofPrevEntry ? 2 * Math.PI : 0;\n                        prev.x0 = prev.x1 = a;\n                    } else {\n                        // if leaf\n                        Lib.extendFlat(prev, interpX0X1FromParent(pt));\n                    }\n                } else {\n                    // if new root-node\n                    prev.x0 = prev.x1 = 0;\n                }\n            } else {\n                // on new traces\n                prev.x0 = prev.x1 = 0;\n            }\n        }\n\n        var rpx1Fn = d3.interpolate(prev.rpx1, pt.rpx1);\n        var x0Fn = d3.interpolate(prev.x0, pt.x0);\n        var x1Fn = d3.interpolate(prev.x1, pt.x1);\n        var scaleFn = d3.interpolate(prev.transform.scale, transform.scale);\n        var rotateFn = d3.interpolate(prev.transform.rotate, transform.rotate);\n\n        // smooth out start/end from entry, to try to keep text inside sector\n        // while keeping transition smooth\n        var pow = transform.rCenter === 0 ? 3 :\n            prev.transform.rCenter === 0 ? 1 / 3 :\n            1;\n        var _rCenterFn = d3.interpolate(prev.transform.rCenter, transform.rCenter);\n        var rCenterFn = function(t) { return _rCenterFn(Math.pow(t, pow)); };\n\n        return function(t) {\n            var rpx1 = rpx1Fn(t);\n            var x0 = x0Fn(t);\n            var x1 = x1Fn(t);\n            var rCenter = rCenterFn(t);\n\n            var d = {\n                pxmid: rx2px(rpx1, (x0 + x1) / 2),\n                transform: {\n                    rCenter: rCenter,\n                    x: transform.x,\n                    y: transform.y\n                }\n            };\n\n            var out = {\n                rpx1: rpx1Fn(t),\n                translateX: transTextX(d),\n                translateY: transTextY(d),\n                transform: {\n                    scale: scaleFn(t),\n                    rotate: rotateFn(t),\n                    rCenter: rCenter\n                }\n            };\n\n            return out;\n        };\n    }\n\n    function interpX0X1FromParent(pt) {\n        var parent = pt.parent;\n        var parentPrev = prevLookup[getPtId(parent)];\n        var out = {};\n\n        if(parentPrev) {\n            // if parent is visible\n            var parentChildren = parent.children;\n            var ci = parentChildren.indexOf(pt);\n            var n = parentChildren.length;\n            var interp = d3.interpolate(parentPrev.x0, parentPrev.x1);\n            out.x0 = interp(ci / n);\n            out.x1 = interp(ci / n);\n        } else {\n            // w/o visible parent\n            // TODO !!! HOW ???\n            out.x0 = out.x1 = 0;\n        }\n\n        return out;\n    }\n}\n\n// x[0-1] keys are angles [radians]\n// y[0-1] keys are hierarchy heights [integers]\nfunction partition(entry) {\n    return d3Hierarchy.partition()\n        .size([2 * Math.PI, entry.height + 1])(entry);\n}\n\nfunction findEntryWithLevel(hierarchy, level) {\n    var out;\n    if(level) {\n        hierarchy.eachAfter(function(pt) {\n            if(getPtId(pt) === level) {\n                return out = pt.copy();\n            }\n        });\n    }\n    return out || hierarchy;\n}\n\nfunction findEntryWithChild(hierarchy, childId) {\n    var out;\n    hierarchy.eachAfter(function(pt) {\n        var children = pt.children || [];\n        for(var i = 0; i < children.length; i++) {\n            var child = children[i];\n            if(getPtId(child) === childId) {\n                return out = pt.copy();\n            }\n        }\n    });\n    return out || hierarchy;\n}\n\nfunction isHierachyRoot(pt) {\n    var cdi = pt.data.data;\n    return cdi.pid === '';\n}\n\nfunction isEntry(pt) {\n    return !pt.parent;\n}\n\nfunction isLeaf(pt) {\n    return !pt.children;\n}\n\nfunction getPtId(pt) {\n    var cdi = pt.data.data;\n    return cdi.id;\n}\n\nfunction setSliceCursor(sliceTop, gd, opts) {\n    var pt = sliceTop.datum();\n    var isTransitioning = (opts || {}).isTransitioning;\n    setCursor(sliceTop, (isTransitioning || isLeaf(pt) || isHierachyRoot(pt)) ? null : 'pointer');\n}\n\nfunction attachFxHandlers(sliceTop, gd, cd) {\n    var cd0 = cd[0];\n    var trace = cd0.trace;\n\n    // hover state vars\n    // have we drawn a hover label, so it should be cleared later\n    if(!('_hasHoverLabel' in trace)) trace._hasHoverLabel = false;\n    // have we emitted a hover event, so later an unhover event should be emitted\n    // note that click events do not depend on this - you can still get them\n    // with hovermode: false or if you were earlier dragging, then clicked\n    // in the same slice that you moused up in\n    if(!('_hasHoverEvent' in trace)) trace._hasHoverEvent = false;\n\n    sliceTop.on('mouseover', function(pt) {\n        var fullLayoutNow = gd._fullLayout;\n\n        if(gd._dragging || fullLayoutNow.hovermode === false) return;\n\n        var traceNow = gd._fullData[trace.index];\n        var cdi = pt.data.data;\n        var ptNumber = cdi.i;\n\n        var _cast = function(astr) {\n            return Lib.castOption(traceNow, ptNumber, astr);\n        };\n\n        var hovertemplate = _cast('hovertemplate');\n        var hoverinfo = Fx.castHoverinfo(traceNow, fullLayoutNow, ptNumber);\n        var separators = fullLayoutNow.separators;\n\n        if(hovertemplate || (hoverinfo && hoverinfo !== 'none' && hoverinfo !== 'skip')) {\n            var rInscribed = pt.rInscribed;\n            var hoverCenterX = cd0.cx + pt.pxmid[0] * (1 - rInscribed);\n            var hoverCenterY = cd0.cy + pt.pxmid[1] * (1 - rInscribed);\n            var hoverPt = {};\n            var parts = [];\n            var thisText = [];\n            var hasFlag = function(flag) { return parts.indexOf(flag) !== -1; };\n\n            if(hoverinfo) {\n                parts = hoverinfo === 'all' ?\n                    traceNow._module.attributes.hoverinfo.flags :\n                    hoverinfo.split('+');\n            }\n\n            hoverPt.label = cdi.label;\n            if(hasFlag('label') && hoverPt.label) thisText.push(hoverPt.label);\n\n            if(cdi.hasOwnProperty('v')) {\n                hoverPt.value = cdi.v;\n                hoverPt.valueLabel = formatPieValue(hoverPt.value, separators);\n                if(hasFlag('value')) thisText.push(hoverPt.valueLabel);\n            }\n\n            hoverPt.text = _cast('hovertext') || _cast('text');\n            if(hasFlag('text')) {\n                var tx = hoverPt.text;\n                if(Lib.isValidTextValue(tx)) thisText.push(tx);\n            }\n\n            Fx.loneHover({\n                trace: traceNow,\n                x0: hoverCenterX - rInscribed * pt.rpx1,\n                x1: hoverCenterX + rInscribed * pt.rpx1,\n                y: hoverCenterY,\n                idealAlign: pt.pxmid[0] < 0 ? 'left' : 'right',\n                text: thisText.join('<br>'),\n                name: (hovertemplate || hasFlag('name')) ? traceNow.name : undefined,\n                color: _cast('hoverlabel.bgcolor') || cdi.color,\n                borderColor: _cast('hoverlabel.bordercolor'),\n                fontFamily: _cast('hoverlabel.font.family'),\n                fontSize: _cast('hoverlabel.font.size'),\n                fontColor: _cast('hoverlabel.font.color'),\n                nameLength: _cast('hoverlabel.namelength'),\n                textAlign: _cast('hoverlabel.align'),\n                hovertemplate: hovertemplate,\n                hovertemplateLabels: hoverPt,\n                eventData: [makeEventData(pt, traceNow)]\n            }, {\n                container: fullLayoutNow._hoverlayer.node(),\n                outerContainer: fullLayoutNow._paper.node(),\n                gd: gd\n            });\n\n            trace._hasHoverLabel = true;\n        }\n\n        trace._hasHoverEvent = true;\n        gd.emit('plotly_hover', {\n            points: [makeEventData(pt, traceNow)],\n            event: d3.event\n        });\n    });\n\n    sliceTop.on('mouseout', function(evt) {\n        var fullLayoutNow = gd._fullLayout;\n        var traceNow = gd._fullData[trace.index];\n        var pt = d3.select(this).datum();\n\n        if(trace._hasHoverEvent) {\n            evt.originalEvent = d3.event;\n            gd.emit('plotly_unhover', {\n                points: [makeEventData(pt, traceNow)],\n                event: d3.event\n            });\n            trace._hasHoverEvent = false;\n        }\n\n        if(trace._hasHoverLabel) {\n            Fx.loneUnhover(fullLayoutNow._hoverlayer.node());\n            trace._hasHoverLabel = false;\n        }\n    });\n\n    sliceTop.on('click', function(pt) {\n        // TODO: this does not support right-click. If we want to support it, we\n        // would likely need to change pie to use dragElement instead of straight\n        // mapbox event binding. Or perhaps better, make a simple wrapper with the\n        // right mousedown, mousemove, and mouseup handlers just for a left/right click\n        // mapbox would use this too.\n        var fullLayoutNow = gd._fullLayout;\n        var traceNow = gd._fullData[trace.index];\n\n        var clickVal = Events.triggerHandler(gd, 'plotly_sunburstclick', {\n            points: [makeEventData(pt, traceNow)],\n            event: d3.event\n        });\n\n        // 'regular' click event when sunburstclick is disabled or when\n        // clikcin on leaves or the hierarchy root\n        if(clickVal === false || isLeaf(pt) || isHierachyRoot(pt)) {\n            if(fullLayoutNow.hovermode) {\n                gd._hoverdata = [makeEventData(pt, traceNow)];\n                Fx.click(gd, d3.event);\n            }\n            return;\n        }\n\n        // skip if triggered from dragging a nearby cartesian subplot\n        if(gd._dragging) return;\n\n        // skip during transitions, to avoid potential bugs\n        // we could remove this check later\n        if(gd._transitioning) return;\n\n        // store 'old' level in guiEdit stash, so that subsequent Plotly.react\n        // calls with the same uirevision can start from the same entry\n        Registry.call('_storeDirectGUIEdit', traceNow, fullLayoutNow._tracePreGUI[traceNow.uid], {level: traceNow.level});\n\n        var hierarchy = cd0.hierarchy;\n        var id = getPtId(pt);\n        var nextEntry = isEntry(pt) ?\n            findEntryWithChild(hierarchy, id) :\n            findEntryWithLevel(hierarchy, id);\n\n        var frame = {\n            data: [{level: getPtId(nextEntry)}],\n            traces: [trace.index]\n        };\n\n        var animOpts = {\n            frame: {\n                redraw: false,\n                duration: constants.CLICK_TRANSITION_TIME\n            },\n            transition: {\n                duration: constants.CLICK_TRANSITION_TIME,\n                easing: constants.CLICK_TRANSITION_EASING\n            },\n            mode: 'immediate',\n            fromcurrent: true\n        };\n\n        Fx.loneUnhover(fullLayoutNow._hoverlayer.node());\n        Registry.call('animate', gd, frame, animOpts);\n    });\n}\n\nfunction makeEventData(pt, trace) {\n    var cdi = pt.data.data;\n\n    var out = {\n        curveNumber: trace.index,\n        pointNumber: cdi.i,\n        data: trace._input,\n        fullData: trace,\n\n        // TODO more things like 'children', 'siblings', 'hierarchy?\n    };\n\n    appendArrayPointValue(out, trace, cdi.i);\n\n    return out;\n}\n\nfunction formatSliceLabel(pt, trace, fullLayout) {\n    var textinfo = trace.textinfo;\n\n    if(!textinfo || textinfo === 'none') {\n        return '';\n    }\n\n    var cdi = pt.data.data;\n    var separators = fullLayout.separators;\n    var parts = textinfo.split('+');\n    var hasFlag = function(flag) { return parts.indexOf(flag) !== -1; };\n    var thisText = [];\n\n    if(hasFlag('label') && cdi.label) thisText.push(cdi.label);\n\n    if(cdi.hasOwnProperty('v') && hasFlag('value')) {\n        thisText.push(formatPieValue(cdi.v, separators));\n    }\n\n    if(hasFlag('text')) {\n        var tx = Lib.castOption(trace, cdi.i, 'text');\n        if(Lib.isValidTextValue(tx)) thisText.push(tx);\n    }\n\n    return thisText.join('<br>');\n}\n\nfunction determineOutsideTextFont(trace, pt, layoutFont) {\n    var cdi = pt.data.data;\n    var ptNumber = cdi.i;\n\n    var color = Lib.castOption(trace, ptNumber, 'outsidetextfont.color') ||\n        Lib.castOption(trace, ptNumber, 'textfont.color') ||\n        layoutFont.color;\n\n    var family = Lib.castOption(trace, ptNumber, 'outsidetextfont.family') ||\n        Lib.castOption(trace, ptNumber, 'textfont.family') ||\n        layoutFont.family;\n\n    var size = Lib.castOption(trace, ptNumber, 'outsidetextfont.size') ||\n        Lib.castOption(trace, ptNumber, 'textfont.size') ||\n        layoutFont.size;\n\n    return {\n        color: color,\n        family: family,\n        size: size\n    };\n}\n\nfunction determineInsideTextFont(trace, pt, layoutFont) {\n    var cdi = pt.data.data;\n    var ptNumber = cdi.i;\n\n    var customColor = Lib.castOption(trace, ptNumber, 'insidetextfont.color');\n    if(!customColor && trace._input.textfont) {\n        // Why not simply using trace.textfont? Because if not set, it\n        // defaults to layout.font which has a default color. But if\n        // textfont.color and insidetextfont.color don't supply a value,\n        // a contrasting color shall be used.\n        customColor = Lib.castOption(trace._input, ptNumber, 'textfont.color');\n    }\n\n    var family = Lib.castOption(trace, ptNumber, 'insidetextfont.family') ||\n        Lib.castOption(trace, ptNumber, 'textfont.family') ||\n        layoutFont.family;\n\n    var size = Lib.castOption(trace, ptNumber, 'insidetextfont.size') ||\n        Lib.castOption(trace, ptNumber, 'textfont.size') ||\n        layoutFont.size;\n\n    return {\n        color: customColor || Color.contrast(cdi.color),\n        family: family,\n        size: size\n    };\n}\n\nfunction getInscribedRadiusFraction(pt) {\n    if(pt.rpx0 === 0 && Lib.isFullCircle([pt.x0, pt.x1])) {\n        // special case of 100% with no hole\n        return 1;\n    } else {\n        return Math.max(0, Math.min(\n            1 / (1 + 1 / Math.sin(pt.halfangle)),\n            pt.ring / 2\n        ));\n    }\n}\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../components/fx\":632,\"../../components/fx/helpers\":628,\"../../lib\":719,\"../../lib/events\":709,\"../../lib/setcursor\":739,\"../../lib/svg_text_utils\":743,\"../../registry\":847,\"../pie/helpers\":1091,\"../pie/plot\":1095,\"./constants\":1217,\"./style\":1223,\"d3\":163,\"d3-hierarchy\":157}],1223:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Color = _dereq_('../../components/color');\nvar Lib = _dereq_('../../lib');\n\nfunction style(gd) {\n    gd._fullLayout._sunburstlayer.selectAll('.trace').each(function(cd) {\n        var gTrace = d3.select(this);\n        var cd0 = cd[0];\n        var trace = cd0.trace;\n\n        gTrace.style('opacity', trace.opacity);\n\n        gTrace.selectAll('path.surface').each(function(pt) {\n            d3.select(this).call(styleOne, pt, trace);\n        });\n    });\n}\n\nfunction styleOne(s, pt, trace) {\n    var cdi = pt.data.data;\n    var isLeaf = !pt.children;\n    var ptNumber = cdi.i;\n    var lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;\n    var lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;\n\n    s.style('stroke-width', lineWidth)\n        .call(Color.fill, cdi.color)\n        .call(Color.stroke, lineColor)\n        .style('opacity', isLeaf ? trace.leaf.opacity : null);\n}\n\nmodule.exports = {\n    style: style,\n    styleOne: styleOne\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"d3\":163}],1224:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Color = _dereq_('../../components/color');\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar baseAttrs = _dereq_('../../plots/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nfunction makeContourProjAttr(axLetter) {\n    return {\n        valType: 'boolean',\n        \n        dflt: false,\n        \n    };\n}\n\nfunction makeContourAttr(axLetter) {\n    return {\n        show: {\n            valType: 'boolean',\n            \n            dflt: false,\n            \n        },\n        start: {\n            valType: 'number',\n            dflt: null,\n            \n            editType: 'plot',\n         // impliedEdits: {'^autocontour': false},\n            \n        },\n        end: {\n            valType: 'number',\n            dflt: null,\n            \n            editType: 'plot',\n         // impliedEdits: {'^autocontour': false},\n            \n        },\n        size: {\n            valType: 'number',\n            dflt: null,\n            min: 0,\n            \n            editType: 'plot',\n         // impliedEdits: {'^autocontour': false},\n            \n        },\n        project: {\n            x: makeContourProjAttr('x'),\n            y: makeContourProjAttr('y'),\n            z: makeContourProjAttr('z')\n        },\n        color: {\n            valType: 'color',\n            \n            dflt: Color.defaultLine,\n            \n        },\n        usecolormap: {\n            valType: 'boolean',\n            \n            dflt: false,\n            \n        },\n        width: {\n            valType: 'number',\n            \n            min: 1,\n            max: 16,\n            dflt: 2,\n            \n        },\n        highlight: {\n            valType: 'boolean',\n            \n            dflt: true,\n            \n        },\n        highlightcolor: {\n            valType: 'color',\n            \n            dflt: Color.defaultLine,\n            \n        },\n        highlightwidth: {\n            valType: 'number',\n            \n            min: 1,\n            max: 16,\n            dflt: 2,\n            \n        }\n    };\n}\n\nvar attrs = module.exports = overrideAll(extendFlat({\n    z: {\n        valType: 'data_array',\n        \n    },\n    x: {\n        valType: 'data_array',\n        \n    },\n    y: {\n        valType: 'data_array',\n        \n    },\n\n    text: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        \n    },\n    hovertext: {\n        valType: 'string',\n        \n        dflt: '',\n        arrayOk: true,\n        \n    },\n    hovertemplate: hovertemplateAttrs(),\n\n    connectgaps: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n\n    surfacecolor: {\n        valType: 'data_array',\n        \n    },\n},\n\ncolorScaleAttrs('', {\n    colorAttr: 'z or surfacecolor',\n    showScaleDflt: true,\n    autoColorDflt: false,\n    editTypeOverride: 'calc'\n}), {\n    contours: {\n        x: makeContourAttr('x'),\n        y: makeContourAttr('y'),\n        z: makeContourAttr('z')\n    },\n    hidesurface: {\n        valType: 'boolean',\n        \n        dflt: false,\n        \n    },\n\n    lightposition: {\n        x: {\n            valType: 'number',\n            \n            min: -1e5,\n            max: 1e5,\n            dflt: 10,\n            \n        },\n        y: {\n            valType: 'number',\n            \n            min: -1e5,\n            max: 1e5,\n            dflt: 1e4,\n            \n        },\n        z: {\n            valType: 'number',\n            \n            min: -1e5,\n            max: 1e5,\n            dflt: 0,\n            \n        }\n    },\n\n    lighting: {\n        ambient: {\n            valType: 'number',\n            \n            min: 0.00,\n            max: 1.0,\n            dflt: 0.8,\n            \n        },\n        diffuse: {\n            valType: 'number',\n            \n            min: 0.00,\n            max: 1.00,\n            dflt: 0.8,\n            \n        },\n        specular: {\n            valType: 'number',\n            \n            min: 0.00,\n            max: 2.00,\n            dflt: 0.05,\n            \n        },\n        roughness: {\n            valType: 'number',\n            \n            min: 0.00,\n            max: 1.00,\n            dflt: 0.5,\n            \n        },\n        fresnel: {\n            valType: 'number',\n            \n            min: 0.00,\n            max: 5.00,\n            dflt: 0.2,\n            \n        }\n    },\n\n    opacity: {\n        valType: 'number',\n        \n        min: 0,\n        max: 1,\n        dflt: 1,\n        \n    },\n\n    _deprecated: {\n        zauto: extendFlat({}, colorScaleAttrs.zauto, {\n            \n        }),\n        zmin: extendFlat({}, colorScaleAttrs.zmin, {\n            \n        }),\n        zmax: extendFlat({}, colorScaleAttrs.zmax, {\n            \n        })\n    },\n\n    hoverinfo: extendFlat({}, baseAttrs.hoverinfo)\n}), 'calc', 'nested');\n\nattrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes';\nattrs.transforms = undefined;\n\n},{\"../../components/color\":593,\"../../components/colorscale/attributes\":600,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/attributes\":764}],1225:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar colorscaleCalc = _dereq_('../../components/colorscale/calc');\n\n\n// Compute auto-z and autocolorscale if applicable\nmodule.exports = function calc(gd, trace) {\n    if(trace.surfacecolor) {\n        colorscaleCalc(gd, trace, {\n            vals: trace.surfacecolor,\n            containerStr: '',\n            cLetter: 'c'\n        });\n    } else {\n        colorscaleCalc(gd, trace, {\n            vals: trace.z,\n            containerStr: '',\n            cLetter: 'c'\n        });\n    }\n};\n\n},{\"../../components/colorscale/calc\":601}],1226:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n\n'use strict';\n\nvar createSurface = _dereq_('gl-surface3d');\n\nvar ndarray = _dereq_('ndarray');\nvar homography = _dereq_('ndarray-homography');\nvar fill = _dereq_('ndarray-fill');\n\nvar isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;\nvar parseColorScale = _dereq_('../../lib/gl_format_color').parseColorScale;\nvar str2RgbaArray = _dereq_('../../lib/str2rgbarray');\nvar extractOpts = _dereq_('../../components/colorscale').extractOpts;\n\nvar interp2d = _dereq_('../heatmap/interp2d');\nvar findEmpties = _dereq_('../heatmap/find_empties');\n\nfunction SurfaceTrace(scene, surface, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.surface = surface;\n    this.data = null;\n    this.showContour = [false, false, false];\n    this.contourStart = [null, null, null];\n    this.contourEnd = [null, null, null];\n    this.contourSize = [0, 0, 0];\n    this.minValues = [Infinity, Infinity, Infinity];\n    this.maxValues = [-Infinity, -Infinity, -Infinity];\n    this.dataScaleX = 1.0;\n    this.dataScaleY = 1.0;\n    this.refineData = true;\n    this.objectOffset = [0, 0, 0];\n}\n\nvar proto = SurfaceTrace.prototype;\n\nproto.getXat = function(a, b, calendar, axis) {\n    var v = (\n       (!isArrayOrTypedArray(this.data.x)) ?\n            a :\n       (isArrayOrTypedArray(this.data.x[0])) ?\n            this.data.x[b][a] :\n            this.data.x[a]\n    );\n\n    return (calendar === undefined) ? v : axis.d2l(v, 0, calendar);\n};\n\nproto.getYat = function(a, b, calendar, axis) {\n    var v = (\n       (!isArrayOrTypedArray(this.data.y)) ?\n            b :\n       (isArrayOrTypedArray(this.data.y[0])) ?\n            this.data.y[b][a] :\n            this.data.y[b]\n    );\n\n    return (calendar === undefined) ? v : axis.d2l(v, 0, calendar);\n};\n\nproto.getZat = function(a, b, calendar, axis) {\n    var v = this.data.z[b][a];\n\n    if(v === null && this.data.connectgaps && this.data._interpolatedZ) {\n        v = this.data._interpolatedZ[b][a];\n    }\n\n    return (calendar === undefined) ? v : axis.d2l(v, 0, calendar);\n};\n\nproto.handlePick = function(selection) {\n    if(selection.object === this.surface) {\n        var xRatio = (selection.data.index[0] - 1) / this.dataScaleX - 1;\n        var yRatio = (selection.data.index[1] - 1) / this.dataScaleY - 1;\n\n        var j = Math.max(Math.min(Math.round(xRatio), this.data.z[0].length - 1), 0);\n        var k = Math.max(Math.min(Math.round(yRatio), this.data._ylength - 1), 0);\n\n        selection.index = [j, k];\n\n        selection.traceCoordinate = [\n            this.getXat(j, k),\n            this.getYat(j, k),\n            this.getZat(j, k)\n        ];\n\n        selection.dataCoordinate = [\n            this.getXat(j, k, this.data.xcalendar, this.scene.fullSceneLayout.xaxis),\n            this.getYat(j, k, this.data.ycalendar, this.scene.fullSceneLayout.yaxis),\n            this.getZat(j, k, this.data.zcalendar, this.scene.fullSceneLayout.zaxis)\n        ];\n\n        for(var i = 0; i < 3; i++) {\n            var v = selection.dataCoordinate[i];\n            if(v !== null && v !== undefined) {\n                selection.dataCoordinate[i] *= this.scene.dataScale[i];\n            }\n        }\n\n        var text = this.data.hovertext || this.data.text;\n        if(Array.isArray(text) && text[k] && text[k][j] !== undefined) {\n            selection.textLabel = text[k][j];\n        } else if(text) {\n            selection.textLabel = text;\n        } else {\n            selection.textLabel = '';\n        }\n\n        selection.data.dataCoordinate = selection.dataCoordinate.slice();\n\n        this.surface.highlight(selection.data);\n\n        // Snap spikes to data coordinate\n        this.scene.glplot.spikes.position = selection.dataCoordinate;\n\n        return true;\n    }\n};\n\nfunction isColormapCircular(colormap) {\n    var first = colormap[0].rgb;\n    var last = colormap[colormap.length - 1].rgb;\n\n    return (\n        first[0] === last[0] &&\n        first[1] === last[1] &&\n        first[2] === last[2] &&\n        first[3] === last[3]\n    );\n}\n\nvar shortPrimes = [\n    2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,\n    101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,\n    211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293,\n    307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,\n    401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499,\n    503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599,\n    601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691,\n    701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797,\n    809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,\n    907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997,\n    1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097,\n    1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193,\n    1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297,\n    1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399,\n    1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499,\n    1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597,\n    1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699,\n    1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789,\n    1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889,\n    1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999,\n    2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099,\n    2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179,\n    2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297,\n    2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399,\n    2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477,\n    2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593,\n    2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699,\n    2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797,\n    2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897,\n    2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999\n];\n\nfunction getPow(a, b) {\n    if(a < b) return 0;\n    var n = 0;\n    while(Math.floor(a % b) === 0) {\n        a /= b;\n        n++;\n    }\n    return n;\n}\n\nfunction getFactors(a) {\n    var powers = [];\n    for(var i = 0; i < shortPrimes.length; i++) {\n        var b = shortPrimes[i];\n        powers.push(\n            getPow(a, b)\n        );\n    }\n    return powers;\n}\n\nfunction smallestDivisor(a) {\n    var A = getFactors(a);\n    var result = a;\n    for(var i = 0; i < shortPrimes.length; i++) {\n        if(A[i] > 0) {\n            result = shortPrimes[i];\n            break;\n        }\n    }\n    return result;\n}\n\nfunction leastCommonMultiple(a, b) {\n    if(a < 1 || b < 1) return undefined;\n    var A = getFactors(a);\n    var B = getFactors(b);\n    var n = 1;\n    for(var i = 0; i < shortPrimes.length; i++) {\n        n *= Math.pow(\n            shortPrimes[i], Math.max(A[i], B[i])\n        );\n    }\n    return n;\n}\n\nfunction arrayLCM(A) {\n    if(A.length === 0) return undefined;\n    var n = 1;\n    for(var i = 0; i < A.length; i++) {\n        n = leastCommonMultiple(n, A[i]);\n    }\n    return n;\n}\n\nproto.calcXnums = function(xlen) {\n    var i;\n    var nums = [];\n    for(i = 1; i < xlen; i++) {\n        var a = this.getXat(i - 1, 0);\n        var b = this.getXat(i, 0);\n\n        if(b !== a &&\n            a !== undefined && a !== null &&\n            b !== undefined && b !== null) {\n            nums[i - 1] = Math.abs(b - a);\n        } else {\n            nums[i - 1] = 0;\n        }\n    }\n\n    var totalDist = 0;\n    for(i = 1; i < xlen; i++) {\n        totalDist += nums[i - 1];\n    }\n\n    for(i = 1; i < xlen; i++) {\n        if(nums[i - 1] === 0) {\n            nums[i - 1] = 1;\n        } else {\n            nums[i - 1] = Math.round(totalDist / nums[i - 1]);\n        }\n    }\n\n    return nums;\n};\n\nproto.calcYnums = function(ylen) {\n    var i;\n    var nums = [];\n    for(i = 1; i < ylen; i++) {\n        var a = this.getYat(0, i - 1);\n        var b = this.getYat(0, i);\n\n        if(b !== a &&\n            a !== undefined && a !== null &&\n            b !== undefined && b !== null) {\n            nums[i - 1] = Math.abs(b - a);\n        } else {\n            nums[i - 1] = 0;\n        }\n    }\n\n    var totalDist = 0;\n    for(i = 1; i < ylen; i++) {\n        totalDist += nums[i - 1];\n    }\n\n    for(i = 1; i < ylen; i++) {\n        if(nums[i - 1] === 0) {\n            nums[i - 1] = 1;\n        } else {\n            nums[i - 1] = Math.round(totalDist / nums[i - 1]);\n        }\n    }\n\n    return nums;\n};\n\nvar highlyComposites = [1, 2, 4, 6, 12, 24, 36, 48, 60, 120, 180, 240, 360, 720, 840, 1260];\n\nvar MIN_RESOLUTION = highlyComposites[9];\nvar MAX_RESOLUTION = highlyComposites[13];\n\nproto.estimateScale = function(resSrc, axis) {\n    var nums = (axis === 0) ?\n        this.calcXnums(resSrc) :\n        this.calcYnums(resSrc);\n\n    var resDst = 1 + arrayLCM(nums);\n\n    while(resDst < MIN_RESOLUTION) {\n        resDst *= 2;\n    }\n\n    while(resDst > MAX_RESOLUTION) {\n        resDst--;\n        resDst /= smallestDivisor(resDst);\n        resDst++;\n\n        if(resDst < MIN_RESOLUTION) {\n         // resDst = MIN_RESOLUTION; // option 1: use min resolution\n            resDst = MAX_RESOLUTION; // option 2: use max resolution\n        }\n    }\n\n    var scale = Math.round(resDst / resSrc);\n    return (scale > 1) ? scale : 1;\n};\n\nproto.refineCoords = function(coords) {\n    var scaleW = this.dataScaleX;\n    var scaleH = this.dataScaleY;\n\n    var width = coords[0].shape[0];\n    var height = coords[0].shape[1];\n\n    var newWidth = Math.floor(coords[0].shape[0] * scaleW + 1) | 0;\n    var newHeight = Math.floor(coords[0].shape[1] * scaleH + 1) | 0;\n\n    // Pad coords by +1\n    var padWidth = 1 + width + 1;\n    var padHeight = 1 + height + 1;\n    var padImg = ndarray(new Float32Array(padWidth * padHeight), [padWidth, padHeight]);\n\n    for(var i = 0; i < coords.length; ++i) {\n        this.surface.padField(padImg, coords[i]);\n\n        var scaledImg = ndarray(new Float32Array(newWidth * newHeight), [newWidth, newHeight]);\n        homography(scaledImg, padImg,\n            [\n                scaleW, 0, 0,\n                0, scaleH, 0,\n                0, 0, 1\n            ]\n        );\n        coords[i] = scaledImg;\n    }\n};\n\nfunction insertIfNewLevel(arr, newValue) {\n    var found = false;\n    for(var k = 0; k < arr.length; k++) {\n        if(newValue === arr[k]) {\n            found = true;\n            break;\n        }\n    }\n    if(found === false) arr.push(newValue);\n}\n\nproto.setContourLevels = function() {\n    var newLevels = [[], [], []];\n    var useNewLevels = [false, false, false];\n    var needsUpdate = false;\n\n    var i, j, value;\n\n    for(i = 0; i < 3; ++i) {\n        if(this.showContour[i]) {\n            needsUpdate = true;\n\n            if(\n                this.contourSize[i] > 0 &&\n                this.contourStart[i] !== null &&\n                this.contourEnd[i] !== null &&\n                this.contourEnd[i] > this.contourStart[i]\n            ) {\n                useNewLevels[i] = true;\n\n                for(j = this.contourStart[i]; j < this.contourEnd[i]; j += this.contourSize[i]) {\n                    value = j * this.scene.dataScale[i];\n\n                    insertIfNewLevel(newLevels[i], value);\n                }\n            }\n        }\n    }\n\n    if(needsUpdate) {\n        var allLevels = [[], [], []];\n        for(i = 0; i < 3; ++i) {\n            if(this.showContour[i]) {\n                allLevels[i] = useNewLevels[i] ? newLevels[i] : this.scene.contourLevels[i];\n            }\n        }\n        this.surface.update({ levels: allLevels });\n    }\n};\n\nproto.update = function(data) {\n    var scene = this.scene;\n    var sceneLayout = scene.fullSceneLayout;\n    var surface = this.surface;\n    var alpha = data.opacity;\n    var colormap = parseColorScale(data, alpha);\n    var scaleFactor = scene.dataScale;\n    var xlen = data.z[0].length;\n    var ylen = data._ylength;\n    var contourLevels = scene.contourLevels;\n\n    // Save data\n    this.data = data;\n\n    /*\n     * Fill and transpose zdata.\n     * Consistent with 'heatmap' and 'contour', plotly 'surface'\n     * 'z' are such that sub-arrays correspond to y-coords\n     * and that the sub-array entries correspond to a x-coords,\n     * which is the transpose of 'gl-surface-plot'.\n     */\n\n    var i, j, k, v;\n    var rawCoords = [];\n    for(i = 0; i < 3; i++) {\n        rawCoords[i] = [];\n        for(j = 0; j < xlen; j++) {\n            rawCoords[i][j] = [];\n            /*\n            for(k = 0; k < ylen; k++) {\n                rawCoords[i][j][k] = undefined;\n            }\n            */\n        }\n    }\n\n    // coords x, y & z\n    for(j = 0; j < xlen; j++) {\n        for(k = 0; k < ylen; k++) {\n            rawCoords[0][j][k] = this.getXat(j, k, data.xcalendar, sceneLayout.xaxis);\n            rawCoords[1][j][k] = this.getYat(j, k, data.ycalendar, sceneLayout.yaxis);\n            rawCoords[2][j][k] = this.getZat(j, k, data.zcalendar, sceneLayout.zaxis);\n        }\n    }\n\n    if(data.connectgaps) {\n        data._emptypoints = findEmpties(rawCoords[2]);\n        interp2d(rawCoords[2], data._emptypoints);\n\n        data._interpolatedZ = [];\n        for(j = 0; j < xlen; j++) {\n            data._interpolatedZ[j] = [];\n            for(k = 0; k < ylen; k++) {\n                data._interpolatedZ[j][k] = rawCoords[2][j][k];\n            }\n        }\n    }\n\n    // Note: log axes are not defined in surfaces yet.\n    // but they could be defined here...\n\n    for(i = 0; i < 3; i++) {\n        for(j = 0; j < xlen; j++) {\n            for(k = 0; k < ylen; k++) {\n                v = rawCoords[i][j][k];\n                if(v === null || v === undefined) {\n                    rawCoords[i][j][k] = NaN;\n                } else {\n                    v = rawCoords[i][j][k] *= scaleFactor[i];\n                }\n            }\n        }\n    }\n\n    for(i = 0; i < 3; i++) {\n        for(j = 0; j < xlen; j++) {\n            for(k = 0; k < ylen; k++) {\n                v = rawCoords[i][j][k];\n                if(v !== null && v !== undefined) {\n                    if(this.minValues[i] > v) {\n                        this.minValues[i] = v;\n                    }\n                    if(this.maxValues[i] < v) {\n                        this.maxValues[i] = v;\n                    }\n                }\n            }\n        }\n    }\n\n    for(i = 0; i < 3; i++) {\n        this.objectOffset[i] = 0.5 * (this.minValues[i] + this.maxValues[i]);\n    }\n\n    for(i = 0; i < 3; i++) {\n        for(j = 0; j < xlen; j++) {\n            for(k = 0; k < ylen; k++) {\n                v = rawCoords[i][j][k];\n                if(v !== null && v !== undefined) {\n                    rawCoords[i][j][k] -= this.objectOffset[i];\n                }\n            }\n        }\n    }\n\n    // convert processed raw data to Float32 matrices\n    var coords = [\n        ndarray(new Float32Array(xlen * ylen), [xlen, ylen]),\n        ndarray(new Float32Array(xlen * ylen), [xlen, ylen]),\n        ndarray(new Float32Array(xlen * ylen), [xlen, ylen])\n    ];\n    fill(coords[0], function(row, col) { return rawCoords[0][row][col]; });\n    fill(coords[1], function(row, col) { return rawCoords[1][row][col]; });\n    fill(coords[2], function(row, col) { return rawCoords[2][row][col]; });\n    rawCoords = []; // free memory\n\n    var params = {\n        colormap: colormap,\n        levels: [[], [], []],\n        showContour: [true, true, true],\n        showSurface: !data.hidesurface,\n        contourProject: [\n            [false, false, false],\n            [false, false, false],\n            [false, false, false]\n        ],\n        contourWidth: [1, 1, 1],\n        contourColor: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],\n        contourTint: [1, 1, 1],\n        dynamicColor: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],\n        dynamicWidth: [1, 1, 1],\n        dynamicTint: [1, 1, 1],\n        opacity: data.opacity\n    };\n\n    var cOpts = extractOpts(data);\n    params.intensityBounds = [cOpts.min, cOpts.max];\n\n    // Refine surface color if necessary\n    if(data.surfacecolor) {\n        var intensity = ndarray(new Float32Array(xlen * ylen), [xlen, ylen]);\n\n        fill(intensity, function(row, col) {\n            return data.surfacecolor[col][row];\n        });\n\n        coords.push(intensity);\n    } else {\n        // when 'z' is used as 'intensity',\n        // we must scale its value\n        params.intensityBounds[0] *= scaleFactor[2];\n        params.intensityBounds[1] *= scaleFactor[2];\n    }\n\n    if(MAX_RESOLUTION < coords[0].shape[0] ||\n        MAX_RESOLUTION < coords[0].shape[1]) {\n        this.refineData = false;\n    }\n\n    if(this.refineData === true) {\n        this.dataScaleX = this.estimateScale(coords[0].shape[0], 0);\n        this.dataScaleY = this.estimateScale(coords[0].shape[1], 1);\n        if(this.dataScaleX !== 1 || this.dataScaleY !== 1) {\n            this.refineCoords(coords);\n        }\n    }\n\n    if(data.surfacecolor) {\n        params.intensity = coords.pop();\n    }\n\n    var highlightEnable = [true, true, true];\n    var axis = ['x', 'y', 'z'];\n\n    for(i = 0; i < 3; ++i) {\n        var contourParams = data.contours[axis[i]];\n        highlightEnable[i] = contourParams.highlight;\n\n        params.showContour[i] = contourParams.show || contourParams.highlight;\n        if(!params.showContour[i]) continue;\n\n        params.contourProject[i] = [\n            contourParams.project.x,\n            contourParams.project.y,\n            contourParams.project.z\n        ];\n\n        if(contourParams.show) {\n            this.showContour[i] = true;\n            params.levels[i] = contourLevels[i];\n            surface.highlightColor[i] = params.contourColor[i] = str2RgbaArray(contourParams.color);\n\n            if(contourParams.usecolormap) {\n                surface.highlightTint[i] = params.contourTint[i] = 0;\n            } else {\n                surface.highlightTint[i] = params.contourTint[i] = 1;\n            }\n            params.contourWidth[i] = contourParams.width;\n\n            this.contourStart[i] = contourParams.start;\n            this.contourEnd[i] = contourParams.end;\n            this.contourSize[i] = contourParams.size;\n        } else {\n            this.showContour[i] = false;\n\n            this.contourStart[i] = null;\n            this.contourEnd[i] = null;\n            this.contourSize[i] = 0;\n        }\n\n        if(contourParams.highlight) {\n            params.dynamicColor[i] = str2RgbaArray(contourParams.highlightcolor);\n            params.dynamicWidth[i] = contourParams.highlightwidth;\n        }\n    }\n\n    // see https://github.com/plotly/plotly.js/issues/940\n    if(isColormapCircular(colormap)) {\n        params.vertexColor = true;\n    }\n\n    params.objectOffset = this.objectOffset;\n\n    params.coords = coords;\n    surface.update(params);\n\n    surface.visible = data.visible;\n    surface.enableDynamic = highlightEnable;\n    surface.enableHighlight = highlightEnable;\n\n    surface.snapToData = true;\n\n    if('lighting' in data) {\n        surface.ambientLight = data.lighting.ambient;\n        surface.diffuseLight = data.lighting.diffuse;\n        surface.specularLight = data.lighting.specular;\n        surface.roughness = data.lighting.roughness;\n        surface.fresnel = data.lighting.fresnel;\n    }\n\n    if('lightposition' in data) {\n        surface.lightPosition = [data.lightposition.x, data.lightposition.y, data.lightposition.z];\n    }\n\n    if(alpha && alpha < 1) {\n        surface.supportsTransparency = true;\n    }\n};\n\nproto.dispose = function() {\n    this.scene.glplot.remove(this.surface);\n    this.surface.dispose();\n};\n\nfunction createSurfaceTrace(scene, data) {\n    var gl = scene.glplot.gl;\n    var surface = createSurface({ gl: gl });\n    var result = new SurfaceTrace(scene, surface, data.uid);\n    surface._trace = result;\n    result.update(data);\n    scene.glplot.add(surface);\n    return result;\n}\n\nmodule.exports = createSurfaceTrace;\n\n},{\"../../components/colorscale\":605,\"../../lib\":719,\"../../lib/gl_format_color\":716,\"../../lib/str2rgbarray\":742,\"../heatmap/find_empties\":1007,\"../heatmap/interp2d\":1010,\"gl-surface3d\":316,\"ndarray\":450,\"ndarray-fill\":440,\"ndarray-homography\":442}],1227:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Registry = _dereq_('../../registry');\nvar Lib = _dereq_('../../lib');\n\nvar colorscaleDefaults = _dereq_('../../components/colorscale/defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    var i, j;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var x = coerce('x');\n    var y = coerce('y');\n\n    var z = coerce('z');\n    if(!z || !z.length ||\n       (x ? (x.length < 1) : false) ||\n       (y ? (y.length < 1) : false)\n    ) {\n        traceOut.visible = false;\n        return;\n    }\n\n    traceOut._xlength = (Array.isArray(x) && Lib.isArrayOrTypedArray(x[0])) ? z.length : z[0].length;\n    traceOut._ylength = z.length;\n\n    var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');\n    handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);\n\n    coerce('text');\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    // Coerce remaining properties\n    [\n        'lighting.ambient',\n        'lighting.diffuse',\n        'lighting.specular',\n        'lighting.roughness',\n        'lighting.fresnel',\n        'lightposition.x',\n        'lightposition.y',\n        'lightposition.z',\n        'hidesurface',\n        'connectgaps',\n        'opacity'\n    ].forEach(function(x) { coerce(x); });\n\n    var surfaceColor = coerce('surfacecolor');\n\n    var dims = ['x', 'y', 'z'];\n    for(i = 0; i < 3; ++i) {\n        var contourDim = 'contours.' + dims[i];\n        var show = coerce(contourDim + '.show');\n        var highlight = coerce(contourDim + '.highlight');\n\n        if(show || highlight) {\n            for(j = 0; j < 3; ++j) {\n                coerce(contourDim + '.project.' + dims[j]);\n            }\n        }\n\n        if(show) {\n            coerce(contourDim + '.color');\n            coerce(contourDim + '.width');\n            coerce(contourDim + '.usecolormap');\n        }\n\n        if(highlight) {\n            coerce(contourDim + '.highlightcolor');\n            coerce(contourDim + '.highlightwidth');\n        }\n\n        coerce(contourDim + '.start');\n        coerce(contourDim + '.end');\n        coerce(contourDim + '.size');\n    }\n\n    // backward compatibility block\n    if(!surfaceColor) {\n        mapLegacy(traceIn, 'zmin', 'cmin');\n        mapLegacy(traceIn, 'zmax', 'cmax');\n        mapLegacy(traceIn, 'zauto', 'cauto');\n    }\n\n    // TODO if contours.?.usecolormap are false and hidesurface is true\n    // the colorbar shouldn't be shown by default\n\n    colorscaleDefaults(\n        traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'}\n    );\n\n    // disable 1D transforms - currently surface does NOT support column data like heatmap does\n    // you can use mesh3d for this use case, but not surface\n    traceOut._length = null;\n};\n\nfunction mapLegacy(traceIn, oldAttr, newAttr) {\n    if(oldAttr in traceIn && !(newAttr in traceIn)) {\n        traceIn[newAttr] = traceIn[oldAttr];\n    }\n}\n\n},{\"../../components/colorscale/defaults\":603,\"../../lib\":719,\"../../registry\":847,\"./attributes\":1224}],1228:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    colorbar: {\n        min: 'cmin',\n        max: 'cmax'\n    },\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./convert'),\n\n    moduleType: 'trace',\n    name: 'surface',\n    basePlotModule: _dereq_('../../plots/gl3d'),\n    categories: ['gl3d', '2dMap', 'noOpacity'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/gl3d\":807,\"./attributes\":1224,\"./calc\":1225,\"./convert\":1226,\"./defaults\":1227}],1229:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar annAttrs = _dereq_('../../components/annotations/attributes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\nvar fontAttrs = _dereq_('../../plots/font_attributes');\nvar domainAttrs = _dereq_('../../plots/domain').attributes;\n\nvar FORMAT_LINK = _dereq_('../../constants/docs').FORMAT_LINK;\n\nvar attrs = module.exports = overrideAll({\n    domain: domainAttrs({name: 'table', trace: true}),\n\n    columnwidth: {\n        valType: 'number',\n        arrayOk: true,\n        dflt: null,\n        \n        \n    },\n\n    columnorder: {\n        valType: 'data_array',\n        \n        \n    },\n\n    header: {\n\n        values: {\n            valType: 'data_array',\n            \n            dflt: [],\n            \n        },\n\n        format: {\n            valType: 'data_array',\n            \n            dflt: [],\n            \n        },\n\n        prefix: {\n            valType: 'string',\n            arrayOk: true,\n            dflt: null,\n            \n            \n        },\n\n        suffix: {\n            valType: 'string',\n            arrayOk: true,\n            dflt: null,\n            \n            \n        },\n\n        height: {\n            valType: 'number',\n            dflt: 28,\n            \n            \n        },\n\n        align: extendFlat({}, annAttrs.align, {arrayOk: true}),\n\n        line: {\n            width: {\n                valType: 'number',\n                arrayOk: true,\n                dflt: 1,\n                \n            },\n            color: {\n                valType: 'color',\n                arrayOk: true,\n                dflt: 'grey',\n                \n            }\n        },\n\n        fill: {\n            color: {\n                valType: 'color',\n                arrayOk: true,\n                dflt: 'white',\n                \n                \n            }\n        },\n\n        font: extendFlat({}, fontAttrs({arrayOk: true}))\n    },\n\n    cells: {\n\n        values: {\n            valType: 'data_array',\n            \n            dflt: [],\n            \n        },\n\n        format: {\n            valType: 'data_array',\n            \n            dflt: [],\n            \n        },\n\n        prefix: {\n            valType: 'string',\n            arrayOk: true,\n            dflt: null,\n            \n            \n        },\n\n        suffix: {\n            valType: 'string',\n            arrayOk: true,\n            dflt: null,\n            \n            \n        },\n\n        height: {\n            valType: 'number',\n            dflt: 20,\n            \n            \n        },\n\n        align: extendFlat({}, annAttrs.align, {arrayOk: true}),\n\n        line: {\n            width: {\n                valType: 'number',\n                arrayOk: true,\n                dflt: 1,\n                \n            },\n            color: {\n                valType: 'color',\n                arrayOk: true,\n                dflt: 'grey',\n                \n            }\n        },\n\n        fill: {\n            color: {\n                valType: 'color',\n                arrayOk: true,\n                \n                dflt: 'white',\n                \n            }\n        },\n\n        font: extendFlat({}, fontAttrs({arrayOk: true}))\n    }\n}, 'calc', 'from-root');\nattrs.transforms = undefined;\n\n},{\"../../components/annotations/attributes\":576,\"../../constants/docs\":690,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/domain\":792,\"../../plots/font_attributes\":793}],1230:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;\nvar tablePlot = _dereq_('./plot');\n\nvar TABLE = 'table';\n\nexports.name = TABLE;\n\nexports.plot = function(gd) {\n    var calcData = getModuleCalcData(gd.calcdata, TABLE)[0];\n    if(calcData.length) tablePlot(gd, calcData);\n};\n\nexports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {\n    var hadTable = (oldFullLayout._has && oldFullLayout._has(TABLE));\n    var hasTable = (newFullLayout._has && newFullLayout._has(TABLE));\n\n    if(hadTable && !hasTable) {\n        oldFullLayout._paperdiv.selectAll('.table').remove();\n    }\n};\n\n},{\"../../plots/get_data\":802,\"./plot\":1237}],1231:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar wrap = _dereq_('../../lib/gup').wrap;\n\nmodule.exports = function calc() {\n    // we don't actually need to include the trace here, since that will be added\n    // by Plots.doCalcdata, and that's all we actually need later.\n    return wrap({});\n};\n\n},{\"../../lib/gup\":717}],1232:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    cellPad: 8,\n    columnExtentOffset: 10,\n    columnTitleOffset: 28,\n    emptyHeaderHeight: 16,\n    latexCheck: /^\\$.*\\$$/,\n    goldenRatio: 1.618,\n    lineBreaker: '<br>',\n    maxDimensionCount: 60,\n    overdrag: 45,\n    releaseTransitionDuration: 120,\n    releaseTransitionEase: 'cubic-out',\n    scrollbarCaptureWidth: 18,\n    scrollbarHideDelay: 1000,\n    scrollbarHideDuration: 1000,\n    scrollbarOffset: 5,\n    scrollbarWidth: 8,\n    transitionDuration: 100,\n    transitionEase: 'cubic-out',\n    uplift: 5,\n    wrapSpacer: ' ',\n    wrapSplitCharacter: ' ',\n    cn: {\n        // general class names\n        table: 'table',\n        tableControlView: 'table-control-view',\n        scrollBackground: 'scroll-background',\n        yColumn: 'y-column',\n        columnBlock: 'column-block',\n        scrollAreaClip: 'scroll-area-clip',\n        scrollAreaClipRect: 'scroll-area-clip-rect',\n        columnBoundary: 'column-boundary',\n        columnBoundaryClippath: 'column-boundary-clippath',\n        columnBoundaryRect: 'column-boundary-rect',\n        columnCells: 'column-cells',\n        columnCell: 'column-cell',\n        cellRect: 'cell-rect',\n        cellText: 'cell-text',\n        cellTextHolder: 'cell-text-holder',\n\n        // scroll related class names\n        scrollbarKit: 'scrollbar-kit',\n        scrollbar: 'scrollbar',\n        scrollbarSlider: 'scrollbar-slider',\n        scrollbarGlyph: 'scrollbar-glyph',\n        scrollbarCaptureZone: 'scrollbar-capture-zone'\n    }\n};\n\n},{}],1233:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar c = _dereq_('./constants');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar isNumeric = _dereq_('fast-isnumeric');\n\n// pure functions, don't alter but passes on `gd` and parts of `trace` without deep copying\nmodule.exports = function calc(gd, trace) {\n    var cellsValues = squareStringMatrix(trace.cells.values);\n    var slicer = function(a) {\n        return a.slice(trace.header.values.length, a.length);\n    };\n    var headerValuesIn = squareStringMatrix(trace.header.values);\n    if(headerValuesIn.length && !headerValuesIn[0].length) {\n        headerValuesIn[0] = [''];\n        headerValuesIn = squareStringMatrix(headerValuesIn);\n    }\n    var headerValues = headerValuesIn\n        .concat(slicer(cellsValues).map(function() {\n            return emptyStrings((headerValuesIn[0] || ['']).length);\n        }));\n\n    var domain = trace.domain;\n    var groupWidth = Math.floor(gd._fullLayout._size.w * (domain.x[1] - domain.x[0]));\n    var groupHeight = Math.floor(gd._fullLayout._size.h * (domain.y[1] - domain.y[0]));\n    var headerRowHeights = trace.header.values.length ?\n        headerValues[0].map(function() { return trace.header.height; }) :\n        [c.emptyHeaderHeight];\n    var rowHeights = cellsValues.length ? cellsValues[0].map(function() { return trace.cells.height; }) : [];\n    var headerHeight = headerRowHeights.reduce(sum, 0);\n    var scrollHeight = groupHeight - headerHeight;\n    var minimumFillHeight = scrollHeight + c.uplift;\n    var anchorToRowBlock = makeAnchorToRowBlock(rowHeights, minimumFillHeight);\n    var anchorToHeaderRowBlock = makeAnchorToRowBlock(headerRowHeights, headerHeight);\n    var headerRowBlocks = makeRowBlock(anchorToHeaderRowBlock, []);\n    var rowBlocks = makeRowBlock(anchorToRowBlock, headerRowBlocks);\n    var uniqueKeys = {};\n    var columnOrder = trace._fullInput.columnorder.concat(slicer(cellsValues.map(function(d, i) {return i;})));\n    var columnWidths = headerValues.map(function(d, i) {\n        var value = Array.isArray(trace.columnwidth) ?\n            trace.columnwidth[Math.min(i, trace.columnwidth.length - 1)] :\n            trace.columnwidth;\n        return isNumeric(value) ? Number(value) : 1;\n    });\n    var totalColumnWidths = columnWidths.reduce(sum, 0);\n\n    // fit columns in the available vertical space as there's no vertical scrolling now\n    columnWidths = columnWidths.map(function(d) { return d / totalColumnWidths * groupWidth; });\n\n    var maxLineWidth = Math.max(arrayMax(trace.header.line.width), arrayMax(trace.cells.line.width));\n\n    var calcdata = {\n        // include staticPlot in the key so if it changes we delete and redraw\n        key: trace.uid + gd._context.staticPlot,\n        translateX: domain.x[0] * gd._fullLayout._size.w,\n        translateY: gd._fullLayout._size.h * (1 - domain.y[1]),\n        size: gd._fullLayout._size,\n        width: groupWidth,\n        maxLineWidth: maxLineWidth,\n        height: groupHeight,\n        columnOrder: columnOrder, // will be mutated on column move, todo use in callback\n        groupHeight: groupHeight,\n        rowBlocks: rowBlocks,\n        headerRowBlocks: headerRowBlocks,\n        scrollY: 0, // will be mutated on scroll\n        cells: extendFlat({}, trace.cells, {values: cellsValues}),\n        headerCells: extendFlat({}, trace.header, {values: headerValues}),\n        gdColumns: headerValues.map(function(d) {return d[0];}),\n        gdColumnsOriginalOrder: headerValues.map(function(d) {return d[0];}),\n        prevPages: [0, 0],\n        scrollbarState: {scrollbarScrollInProgress: false},\n        columns: headerValues.map(function(label, i) {\n            var foundKey = uniqueKeys[label];\n            uniqueKeys[label] = (foundKey || 0) + 1;\n            var key = label + '__' + uniqueKeys[label];\n            return {\n                key: key,\n                label: label,\n                specIndex: i,\n                xIndex: columnOrder[i],\n                xScale: xScale,\n                x: undefined, // initialized below\n                calcdata: undefined, // initialized below\n                columnWidth: columnWidths[i]\n            };\n        })\n    };\n\n    calcdata.columns.forEach(function(col) {\n        col.calcdata = calcdata;\n        col.x = xScale(col);\n    });\n\n    return calcdata;\n};\n\nfunction arrayMax(maybeArray) {\n    if(Array.isArray(maybeArray)) {\n        var max = 0;\n        for(var i = 0; i < maybeArray.length; i++) {\n            max = Math.max(max, arrayMax(maybeArray[i]));\n        }\n        return max;\n    }\n    return maybeArray;\n}\n\nfunction sum(a, b) { return a + b; }\n\n// fill matrix in place to equal lengths\n// and ensure it's uniformly 2D\nfunction squareStringMatrix(matrixIn) {\n    var matrix = matrixIn.slice();\n    var minLen = Infinity;\n    var maxLen = 0;\n    var i;\n    for(i = 0; i < matrix.length; i++) {\n        if(!Array.isArray(matrix[i])) matrix[i] = [matrix[i]];\n        minLen = Math.min(minLen, matrix[i].length);\n        maxLen = Math.max(maxLen, matrix[i].length);\n    }\n\n    if(minLen !== maxLen) {\n        for(i = 0; i < matrix.length; i++) {\n            var padLen = maxLen - matrix[i].length;\n            if(padLen) matrix[i] = matrix[i].concat(emptyStrings(padLen));\n        }\n    }\n    return matrix;\n}\n\nfunction emptyStrings(len) {\n    var padArray = new Array(len);\n    for(var j = 0; j < len; j++) padArray[j] = '';\n    return padArray;\n}\n\nfunction xScale(d) {\n    return d.calcdata.columns.reduce(function(prev, next) {\n        return next.xIndex < d.xIndex ? prev + next.columnWidth : prev;\n    }, 0);\n}\n\nfunction makeRowBlock(anchorToRowBlock, auxiliary) {\n    var blockAnchorKeys = Object.keys(anchorToRowBlock);\n    return blockAnchorKeys.map(function(k) {return extendFlat({}, anchorToRowBlock[k], {auxiliaryBlocks: auxiliary});});\n}\n\nfunction makeAnchorToRowBlock(rowHeights, minimumFillHeight) {\n    var anchorToRowBlock = {};\n    var currentRowHeight;\n    var currentAnchor = 0;\n    var currentBlockHeight = 0;\n    var currentBlock = makeIdentity();\n    var currentFirstRowIndex = 0;\n    var blockCounter = 0;\n    for(var i = 0; i < rowHeights.length; i++) {\n        currentRowHeight = rowHeights[i];\n        currentBlock.rows.push({\n            rowIndex: i,\n            rowHeight: currentRowHeight\n        });\n        currentBlockHeight += currentRowHeight;\n        if(currentBlockHeight >= minimumFillHeight || i === rowHeights.length - 1) {\n            anchorToRowBlock[currentAnchor] = currentBlock;\n            currentBlock.key = blockCounter++;\n            currentBlock.firstRowIndex = currentFirstRowIndex;\n            currentBlock.lastRowIndex = i;\n            currentBlock = makeIdentity();\n            currentAnchor += currentBlockHeight;\n            currentFirstRowIndex = i + 1;\n            currentBlockHeight = 0;\n        }\n    }\n\n    return anchorToRowBlock;\n}\n\nfunction makeIdentity() {\n    return {\n        firstRowIndex: null,\n        lastRowIndex: null,\n        rows: []\n    };\n}\n\n},{\"../../lib/extend\":710,\"./constants\":1232,\"fast-isnumeric\":225}],1234:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\n// pure functions, don't alter but passes on `gd` and parts of `trace` without deep copying\n\nexports.splitToPanels = function(d) {\n    var prevPages = [0, 0];\n    var headerPanel = extendFlat({}, d, {\n        key: 'header',\n        type: 'header',\n        page: 0,\n        prevPages: prevPages,\n        currentRepaint: [null, null],\n        dragHandle: true,\n        values: d.calcdata.headerCells.values[d.specIndex],\n        rowBlocks: d.calcdata.headerRowBlocks,\n        calcdata: extendFlat({}, d.calcdata, {cells: d.calcdata.headerCells})\n    });\n    var revolverPanel1 = extendFlat({}, d, {\n        key: 'cells1',\n        type: 'cells',\n        page: 0,\n        prevPages: prevPages,\n        currentRepaint: [null, null],\n        dragHandle: false,\n        values: d.calcdata.cells.values[d.specIndex],\n        rowBlocks: d.calcdata.rowBlocks\n    });\n    var revolverPanel2 = extendFlat({}, d, {\n        key: 'cells2',\n        type: 'cells',\n        page: 1,\n        prevPages: prevPages,\n        currentRepaint: [null, null],\n        dragHandle: false,\n        values: d.calcdata.cells.values[d.specIndex],\n        rowBlocks: d.calcdata.rowBlocks\n    });\n    // order due to SVG using painter's algo:\n    return [revolverPanel1, revolverPanel2, headerPanel];\n};\n\nexports.splitToCells = function(d) {\n    var fromTo = rowFromTo(d);\n    return (d.values || []).slice(fromTo[0], fromTo[1]).map(function(v, i) {\n        // By keeping identical key, a DOM node removal, creation and addition is spared, important when visible\n        // grid has a lot of elements (quadratic with xcol/ycol count).\n        // But it has to be busted when `svgUtil.convertToTspans` is used as it reshapes cell subtrees asynchronously,\n        // and by that time the user may have scrolled away, resulting in stale overwrites. The real solution will be\n        // to turn `svgUtil.convertToTspans` into a cancelable request, in which case no key busting is needed.\n        var buster = (typeof v === 'string') && v.match(/[<$&> ]/) ? '_keybuster_' + Math.random() : '';\n        return {\n            // keyWithinBlock: /*fromTo[0] + */i, // optimized future version - no busting\n            // keyWithinBlock: fromTo[0] + i, // initial always-unoptimized version - janky scrolling with 5+ columns\n            keyWithinBlock: i + buster, // current compromise: regular content is very fast; async content is possible\n            key: fromTo[0] + i,\n            column: d,\n            calcdata: d.calcdata,\n            page: d.page,\n            rowBlocks: d.rowBlocks,\n            value: v\n        };\n    });\n};\n\nfunction rowFromTo(d) {\n    var rowBlock = d.rowBlocks[d.page];\n    // fixme rowBlock truthiness check is due to ugly hack of placing 2nd panel as d.page = -1\n    var rowFrom = rowBlock ? rowBlock.rows[0].rowIndex : 0;\n    var rowTo = rowBlock ? rowFrom + rowBlock.rows.length : 0;\n    return [rowFrom, rowTo];\n}\n\n},{\"../../lib/extend\":710}],1235:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attributes = _dereq_('./attributes');\nvar handleDomainDefaults = _dereq_('../../plots/domain').defaults;\n\nfunction defaultColumnOrder(traceOut, coerce) {\n    var specifiedColumnOrder = traceOut.columnorder || [];\n    var commonLength = traceOut.header.values.length;\n    var truncated = specifiedColumnOrder.slice(0, commonLength);\n    var sorted = truncated.slice().sort(function(a, b) {return a - b;});\n    var oneStepped = truncated.map(function(d) {return sorted.indexOf(d);});\n    for(var i = oneStepped.length; i < commonLength; i++) {\n        oneStepped.push(i);\n    }\n    coerce('columnorder', oneStepped);\n}\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    handleDomainDefaults(traceOut, layout, coerce);\n\n    coerce('columnwidth');\n\n    coerce('header.values');\n    coerce('header.format');\n    coerce('header.align');\n\n    coerce('header.prefix');\n    coerce('header.suffix');\n    coerce('header.height');\n    coerce('header.line.width');\n    coerce('header.line.color');\n    coerce('header.fill.color');\n    Lib.coerceFont(coerce, 'header.font', Lib.extendFlat({}, layout.font));\n\n    defaultColumnOrder(traceOut, coerce);\n\n    coerce('cells.values');\n    coerce('cells.format');\n    coerce('cells.align');\n    coerce('cells.prefix');\n    coerce('cells.suffix');\n    coerce('cells.height');\n    coerce('cells.line.width');\n    coerce('cells.line.color');\n    coerce('cells.fill.color');\n    Lib.coerceFont(coerce, 'cells.font', Lib.extendFlat({}, layout.font));\n\n    // disable 1D transforms\n    traceOut._length = null;\n};\n\n},{\"../../lib\":719,\"../../plots/domain\":792,\"./attributes\":1229}],1236:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('./calc'),\n    plot: _dereq_('./plot'),\n\n    moduleType: 'trace',\n    name: 'table',\n    basePlotModule: _dereq_('./base_plot'),\n    categories: ['noOpacity'],\n    meta: {\n        \n    }\n};\n\n},{\"./attributes\":1229,\"./base_plot\":1230,\"./calc\":1231,\"./defaults\":1235,\"./plot\":1237}],1237:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar c = _dereq_('./constants');\nvar d3 = _dereq_('d3');\nvar gup = _dereq_('../../lib/gup');\nvar Drawing = _dereq_('../../components/drawing');\nvar svgUtil = _dereq_('../../lib/svg_text_utils');\nvar raiseToTop = _dereq_('../../lib').raiseToTop;\nvar cancelEeaseColumn = _dereq_('../../lib').cancelTransition;\nvar prepareData = _dereq_('./data_preparation_helper');\nvar splitData = _dereq_('./data_split_helpers');\nvar Color = _dereq_('../../components/color');\n\nmodule.exports = function plot(gd, wrappedTraceHolders) {\n    var dynamic = !gd._context.staticPlot;\n\n    var table = gd._fullLayout._paper.selectAll('.' + c.cn.table)\n        .data(wrappedTraceHolders.map(function(wrappedTraceHolder) {\n            var traceHolder = gup.unwrap(wrappedTraceHolder);\n            var trace = traceHolder.trace;\n            return prepareData(gd, trace);\n        }), gup.keyFun);\n\n    table.exit().remove();\n\n    table.enter()\n        .append('g')\n        .classed(c.cn.table, true)\n        .attr('overflow', 'visible')\n        .style('box-sizing', 'content-box')\n        .style('position', 'absolute')\n        .style('left', 0)\n        .style('overflow', 'visible')\n        .style('shape-rendering', 'crispEdges')\n        .style('pointer-events', 'all');\n\n    table\n        .attr('width', function(d) {return d.width + d.size.l + d.size.r;})\n        .attr('height', function(d) {return d.height + d.size.t + d.size.b;})\n        .attr('transform', function(d) {\n            return 'translate(' + d.translateX + ',' + d.translateY + ')';\n        });\n\n    var tableControlView = table.selectAll('.' + c.cn.tableControlView)\n        .data(gup.repeat, gup.keyFun);\n\n    var cvEnter = tableControlView.enter()\n        .append('g')\n        .classed(c.cn.tableControlView, true)\n        .style('box-sizing', 'content-box');\n    if(dynamic) {\n        cvEnter\n            .on('mousemove', function(d) {\n                tableControlView\n                    .filter(function(dd) {return d === dd;})\n                    .call(renderScrollbarKit, gd);\n            })\n            .on('mousewheel', function(d) {\n                if(d.scrollbarState.wheeling) return;\n                d.scrollbarState.wheeling = true;\n                var newY = d.scrollY + d3.event.deltaY;\n                var noChange = makeDragRow(gd, tableControlView, null, newY)(d);\n                if(!noChange) {\n                    d3.event.stopPropagation();\n                    d3.event.preventDefault();\n                }\n                d.scrollbarState.wheeling = false;\n            })\n            .call(renderScrollbarKit, gd, true);\n    }\n\n    tableControlView\n        .attr('transform', function(d) {return 'translate(' + d.size.l + ' ' + d.size.t + ')';});\n\n    // scrollBackground merely ensures that mouse events are captured even on crazy fast scrollwheeling\n    // otherwise rendering glitches may occur\n    var scrollBackground = tableControlView.selectAll('.' + c.cn.scrollBackground)\n        .data(gup.repeat, gup.keyFun);\n\n    scrollBackground.enter()\n        .append('rect')\n        .classed(c.cn.scrollBackground, true)\n        .attr('fill', 'none');\n\n    scrollBackground\n        .attr('width', function(d) {return d.width;})\n        .attr('height', function(d) {return d.height;});\n\n    tableControlView.each(function(d) {\n        Drawing.setClipUrl(d3.select(this), scrollAreaBottomClipKey(gd, d), gd);\n    });\n\n    var yColumn = tableControlView.selectAll('.' + c.cn.yColumn)\n        .data(function(vm) {return vm.columns;}, gup.keyFun);\n\n    yColumn.enter()\n        .append('g')\n        .classed(c.cn.yColumn, true);\n\n    yColumn.exit().remove();\n\n    yColumn.attr('transform', function(d) {return 'translate(' + d.x + ' 0)';});\n\n    if(dynamic) {\n        yColumn.call(d3.behavior.drag()\n            .origin(function(d) {\n                var movedColumn = d3.select(this);\n                easeColumn(movedColumn, d, -c.uplift);\n                raiseToTop(this);\n                d.calcdata.columnDragInProgress = true;\n                renderScrollbarKit(tableControlView.filter(function(dd) {return d.calcdata.key === dd.key;}), gd);\n                return d;\n            })\n            .on('drag', function(d) {\n                var movedColumn = d3.select(this);\n                var getter = function(dd) {return (d === dd ? d3.event.x : dd.x) + dd.columnWidth / 2;};\n                d.x = Math.max(-c.overdrag, Math.min(d.calcdata.width + c.overdrag - d.columnWidth, d3.event.x));\n\n                var sortableColumns = flatData(yColumn).filter(function(dd) {return dd.calcdata.key === d.calcdata.key;});\n                var newOrder = sortableColumns.sort(function(a, b) {return getter(a) - getter(b);});\n                newOrder.forEach(function(dd, i) {\n                    dd.xIndex = i;\n                    dd.x = d === dd ? dd.x : dd.xScale(dd);\n                });\n\n                yColumn.filter(function(dd) {return d !== dd;})\n                    .transition()\n                    .ease(c.transitionEase)\n                    .duration(c.transitionDuration)\n                    .attr('transform', function(d) {return 'translate(' + d.x + ' 0)';});\n                movedColumn\n                    .call(cancelEeaseColumn)\n                    .attr('transform', 'translate(' + d.x + ' -' + c.uplift + ' )');\n            })\n            .on('dragend', function(d) {\n                var movedColumn = d3.select(this);\n                var p = d.calcdata;\n                d.x = d.xScale(d);\n                d.calcdata.columnDragInProgress = false;\n                easeColumn(movedColumn, d, 0);\n                columnMoved(gd, p, p.columns.map(function(dd) {return dd.xIndex;}));\n            })\n        );\n    }\n\n    yColumn.each(function(d) {\n        Drawing.setClipUrl(d3.select(this), columnBoundaryClipKey(gd, d), gd);\n    });\n\n    var columnBlock = yColumn.selectAll('.' + c.cn.columnBlock)\n        .data(splitData.splitToPanels, gup.keyFun);\n\n    columnBlock.enter()\n        .append('g')\n        .classed(c.cn.columnBlock, true)\n        .attr('id', function(d) {return d.key;});\n\n    columnBlock\n        .style('cursor', function(d) {\n            return d.dragHandle ? 'ew-resize' : d.calcdata.scrollbarState.barWiggleRoom ? 'ns-resize' : 'default';\n        });\n\n    var headerColumnBlock = columnBlock.filter(headerBlock);\n    var cellsColumnBlock = columnBlock.filter(cellsBlock);\n\n    if(dynamic) {\n        cellsColumnBlock.call(d3.behavior.drag()\n            .origin(function(d) {\n                d3.event.stopPropagation();\n                return d;\n            })\n            .on('drag', makeDragRow(gd, tableControlView, -1))\n            .on('dragend', function() {\n                // fixme emit plotly notification\n            })\n        );\n    }\n\n    // initial rendering: header is rendered first, as it may may have async LaTeX (show header first)\n    // but blocks are _entered_ the way they are due to painter's algo (header on top)\n    renderColumnCellTree(gd, tableControlView, headerColumnBlock, columnBlock);\n    renderColumnCellTree(gd, tableControlView, cellsColumnBlock, columnBlock);\n\n    var scrollAreaClip = tableControlView.selectAll('.' + c.cn.scrollAreaClip)\n        .data(gup.repeat, gup.keyFun);\n\n    scrollAreaClip.enter()\n        .append('clipPath')\n        .classed(c.cn.scrollAreaClip, true)\n        .attr('id', function(d) {return scrollAreaBottomClipKey(gd, d);});\n\n    var scrollAreaClipRect = scrollAreaClip.selectAll('.' + c.cn.scrollAreaClipRect)\n        .data(gup.repeat, gup.keyFun);\n\n    scrollAreaClipRect.enter()\n        .append('rect')\n        .classed(c.cn.scrollAreaClipRect, true)\n        .attr('x', -c.overdrag)\n        .attr('y', -c.uplift)\n        .attr('fill', 'none');\n\n    scrollAreaClipRect\n        .attr('width', function(d) {return d.width + 2 * c.overdrag;})\n        .attr('height', function(d) {return d.height + c.uplift;});\n\n    var columnBoundary = yColumn.selectAll('.' + c.cn.columnBoundary)\n        .data(gup.repeat, gup.keyFun);\n\n    columnBoundary.enter()\n        .append('g')\n        .classed(c.cn.columnBoundary, true);\n\n    var columnBoundaryClippath = yColumn.selectAll('.' + c.cn.columnBoundaryClippath)\n        .data(gup.repeat, gup.keyFun);\n\n    // SVG spec doesn't mandate wrapping into a <defs> and doesn't seem to cause a speed difference\n    columnBoundaryClippath.enter()\n        .append('clipPath')\n        .classed(c.cn.columnBoundaryClippath, true);\n\n    columnBoundaryClippath\n        .attr('id', function(d) {return columnBoundaryClipKey(gd, d);});\n\n    var columnBoundaryRect = columnBoundaryClippath.selectAll('.' + c.cn.columnBoundaryRect)\n        .data(gup.repeat, gup.keyFun);\n\n    columnBoundaryRect.enter()\n        .append('rect')\n        .classed(c.cn.columnBoundaryRect, true)\n        .attr('fill', 'none');\n\n    columnBoundaryRect\n        .attr('width', function(d) { return d.columnWidth + 2 * roundHalfWidth(d); })\n        .attr('height', function(d) {return d.calcdata.height + 2 * roundHalfWidth(d) + c.uplift;})\n        .attr('x', function(d) { return -roundHalfWidth(d); })\n        .attr('y', function(d) { return -roundHalfWidth(d); });\n\n    updateBlockYPosition(null, cellsColumnBlock, tableControlView);\n};\n\nfunction roundHalfWidth(d) {\n    return Math.ceil(d.calcdata.maxLineWidth / 2);\n}\n\nfunction scrollAreaBottomClipKey(gd, d) {\n    return 'clip' + gd._fullLayout._uid + '_scrollAreaBottomClip_' + d.key;\n}\n\nfunction columnBoundaryClipKey(gd, d) {\n    return 'clip' + gd._fullLayout._uid + '_columnBoundaryClippath_' + d.calcdata.key + '_' + d.specIndex;\n}\n\nfunction flatData(selection) {\n    return [].concat.apply([], selection.map(function(g) {return g;}))\n        .map(function(g) {return g.__data__;});\n}\n\nfunction renderScrollbarKit(tableControlView, gd, bypassVisibleBar) {\n    function calcTotalHeight(d) {\n        var blocks = d.rowBlocks;\n        return firstRowAnchor(blocks, blocks.length - 1) + (blocks.length ? rowsHeight(blocks[blocks.length - 1], Infinity) : 1);\n    }\n\n    var scrollbarKit = tableControlView.selectAll('.' + c.cn.scrollbarKit)\n        .data(gup.repeat, gup.keyFun);\n\n    scrollbarKit.enter()\n        .append('g')\n        .classed(c.cn.scrollbarKit, true)\n        .style('shape-rendering', 'geometricPrecision');\n\n    scrollbarKit\n        .each(function(d) {\n            var s = d.scrollbarState;\n            s.totalHeight = calcTotalHeight(d);\n            s.scrollableAreaHeight = d.groupHeight - headerHeight(d);\n            s.currentlyVisibleHeight = Math.min(s.totalHeight, s.scrollableAreaHeight);\n            s.ratio = s.currentlyVisibleHeight / s.totalHeight;\n            s.barLength = Math.max(s.ratio * s.currentlyVisibleHeight, c.goldenRatio * c.scrollbarWidth);\n            s.barWiggleRoom = s.currentlyVisibleHeight - s.barLength;\n            s.wiggleRoom = Math.max(0, s.totalHeight - s.scrollableAreaHeight);\n            s.topY = s.barWiggleRoom === 0 ? 0 : (d.scrollY / s.wiggleRoom) * s.barWiggleRoom;\n            s.bottomY = s.topY + s.barLength;\n            s.dragMultiplier = s.wiggleRoom / s.barWiggleRoom;\n        })\n        .attr('transform', function(d) {\n            var xPosition = d.width + c.scrollbarWidth / 2 + c.scrollbarOffset;\n            return 'translate(' + xPosition + ' ' + headerHeight(d) + ')';\n        });\n\n    var scrollbar = scrollbarKit.selectAll('.' + c.cn.scrollbar)\n        .data(gup.repeat, gup.keyFun);\n\n    scrollbar.enter()\n        .append('g')\n        .classed(c.cn.scrollbar, true);\n\n    var scrollbarSlider = scrollbar.selectAll('.' + c.cn.scrollbarSlider)\n        .data(gup.repeat, gup.keyFun);\n\n    scrollbarSlider.enter()\n        .append('g')\n        .classed(c.cn.scrollbarSlider, true);\n\n    scrollbarSlider\n        .attr('transform', function(d) {\n            return 'translate(0 ' + (d.scrollbarState.topY || 0) + ')';\n        });\n\n    var scrollbarGlyph = scrollbarSlider.selectAll('.' + c.cn.scrollbarGlyph)\n        .data(gup.repeat, gup.keyFun);\n\n    scrollbarGlyph.enter()\n        .append('line')\n        .classed(c.cn.scrollbarGlyph, true)\n        .attr('stroke', 'black')\n        .attr('stroke-width', c.scrollbarWidth)\n        .attr('stroke-linecap', 'round')\n        .attr('y1', c.scrollbarWidth / 2);\n\n    scrollbarGlyph\n        .attr('y2', function(d) {\n            return d.scrollbarState.barLength - c.scrollbarWidth / 2;\n        })\n        .attr('stroke-opacity', function(d) {\n            return d.columnDragInProgress || !d.scrollbarState.barWiggleRoom || bypassVisibleBar ? 0 : 0.4;\n        });\n\n    // cancel transition: possible pending (also, delayed) transition\n    scrollbarGlyph\n        .transition().delay(0).duration(0);\n\n    scrollbarGlyph\n        .transition().delay(c.scrollbarHideDelay).duration(c.scrollbarHideDuration)\n        .attr('stroke-opacity', 0);\n\n    var scrollbarCaptureZone = scrollbar.selectAll('.' + c.cn.scrollbarCaptureZone)\n        .data(gup.repeat, gup.keyFun);\n\n    scrollbarCaptureZone.enter()\n        .append('line')\n        .classed(c.cn.scrollbarCaptureZone, true)\n        .attr('stroke', 'white')\n        .attr('stroke-opacity', 0.01) // some browser might get rid of a 0 opacity element\n        .attr('stroke-width', c.scrollbarCaptureWidth)\n        .attr('stroke-linecap', 'butt')\n        .attr('y1', 0)\n        .on('mousedown', function(d) {\n            var y = d3.event.y;\n            var bbox = this.getBoundingClientRect();\n            var s = d.scrollbarState;\n            var pixelVal = y - bbox.top;\n            var inverseScale = d3.scale.linear().domain([0, s.scrollableAreaHeight]).range([0, s.totalHeight]).clamp(true);\n            if(!(s.topY <= pixelVal && pixelVal <= s.bottomY)) {\n                makeDragRow(gd, tableControlView, null, inverseScale(pixelVal - s.barLength / 2))(d);\n            }\n        })\n        .call(d3.behavior.drag()\n            .origin(function(d) {\n                d3.event.stopPropagation();\n                d.scrollbarState.scrollbarScrollInProgress = true;\n                return d;\n            })\n            .on('drag', makeDragRow(gd, tableControlView))\n            .on('dragend', function() {\n                // fixme emit Plotly event\n            })\n        );\n\n    scrollbarCaptureZone\n        .attr('y2', function(d) {\n            return d.scrollbarState.scrollableAreaHeight;\n        });\n\n    // Remove scroll glyph and capture zone on static plots\n    // as they don't render properly when converted to PDF\n    // in the Chrome PDF viewer\n    // https://github.com/plotly/streambed/issues/11618\n    if(gd._context.staticPlot) {\n        scrollbarGlyph.remove();\n        scrollbarCaptureZone.remove();\n    }\n}\n\nfunction renderColumnCellTree(gd, tableControlView, columnBlock, allColumnBlock) {\n    // fixme this perf hotspot\n    // this is performance critical code as scrolling calls it on every revolver switch\n    // it appears sufficiently fast but there are plenty of low-hanging fruits for performance optimization\n\n    var columnCells = renderColumnCells(columnBlock);\n\n    var columnCell = renderColumnCell(columnCells);\n\n    supplyStylingValues(columnCell);\n\n    var cellRect = renderCellRect(columnCell);\n\n    sizeAndStyleRect(cellRect);\n\n    var cellTextHolder = renderCellTextHolder(columnCell);\n\n    var cellText = renderCellText(cellTextHolder);\n\n    setFont(cellText);\n    populateCellText(cellText, tableControlView, allColumnBlock, gd);\n\n    // doing this at the end when text, and text stlying are set\n    setCellHeightAndPositionY(columnCell);\n}\n\nfunction renderColumnCells(columnBlock) {\n    var columnCells = columnBlock.selectAll('.' + c.cn.columnCells)\n        .data(gup.repeat, gup.keyFun);\n\n    columnCells.enter()\n        .append('g')\n        .classed(c.cn.columnCells, true);\n\n    columnCells.exit()\n        .remove();\n\n    return columnCells;\n}\n\nfunction renderColumnCell(columnCells) {\n    var columnCell = columnCells.selectAll('.' + c.cn.columnCell)\n        .data(splitData.splitToCells, function(d) {return d.keyWithinBlock;});\n\n    columnCell.enter()\n        .append('g')\n        .classed(c.cn.columnCell, true);\n\n    columnCell.exit()\n        .remove();\n\n    return columnCell;\n}\n\nfunction renderCellRect(columnCell) {\n    var cellRect = columnCell.selectAll('.' + c.cn.cellRect)\n        .data(gup.repeat, function(d) {return d.keyWithinBlock;});\n\n    cellRect.enter()\n        .append('rect')\n        .classed(c.cn.cellRect, true);\n\n    return cellRect;\n}\n\nfunction renderCellText(cellTextHolder) {\n    var cellText = cellTextHolder.selectAll('.' + c.cn.cellText)\n        .data(gup.repeat, function(d) {return d.keyWithinBlock;});\n\n    cellText.enter()\n        .append('text')\n        .classed(c.cn.cellText, true)\n        .style('cursor', function() {return 'auto';})\n        .on('mousedown', function() {d3.event.stopPropagation();});\n\n    return cellText;\n}\n\nfunction renderCellTextHolder(columnCell) {\n    var cellTextHolder = columnCell.selectAll('.' + c.cn.cellTextHolder)\n        .data(gup.repeat, function(d) {return d.keyWithinBlock;});\n\n    cellTextHolder.enter()\n        .append('g')\n        .classed(c.cn.cellTextHolder, true)\n        .style('shape-rendering', 'geometricPrecision');\n\n    return cellTextHolder;\n}\n\nfunction supplyStylingValues(columnCell) {\n    columnCell\n        .each(function(d, i) {\n            var spec = d.calcdata.cells.font;\n            var col = d.column.specIndex;\n            var font = {\n                size: gridPick(spec.size, col, i),\n                color: gridPick(spec.color, col, i),\n                family: gridPick(spec.family, col, i)\n            };\n            d.rowNumber = d.key;\n            d.align = gridPick(d.calcdata.cells.align, col, i);\n            d.cellBorderWidth = gridPick(d.calcdata.cells.line.width, col, i);\n            d.font = font;\n        });\n}\n\nfunction setFont(cellText) {\n    cellText\n        .each(function(d) {\n            Drawing.font(d3.select(this), d.font);\n        });\n}\n\nfunction sizeAndStyleRect(cellRect) {\n    cellRect\n        .attr('width', function(d) {return d.column.columnWidth;})\n        .attr('stroke-width', function(d) {return d.cellBorderWidth;})\n        .each(function(d) {\n            var atomicSelection = d3.select(this);\n            Color.stroke(atomicSelection, gridPick(d.calcdata.cells.line.color, d.column.specIndex, d.rowNumber));\n            Color.fill(atomicSelection, gridPick(d.calcdata.cells.fill.color, d.column.specIndex, d.rowNumber));\n        });\n}\n\nfunction populateCellText(cellText, tableControlView, allColumnBlock, gd) {\n    cellText\n        .text(function(d) {\n            var col = d.column.specIndex;\n            var row = d.rowNumber;\n\n            var userSuppliedContent = d.value;\n            var stringSupplied = (typeof userSuppliedContent === 'string');\n            var hasBreaks = stringSupplied && userSuppliedContent.match(/<br>/i);\n            var userBrokenText = !stringSupplied || hasBreaks;\n            d.mayHaveMarkup = stringSupplied && userSuppliedContent.match(/[<&>]/);\n\n            var latex = isLatex(userSuppliedContent);\n            d.latex = latex;\n\n            var prefix = latex ? '' : gridPick(d.calcdata.cells.prefix, col, row) || '';\n            var suffix = latex ? '' : gridPick(d.calcdata.cells.suffix, col, row) || '';\n            var format = latex ? null : gridPick(d.calcdata.cells.format, col, row) || null;\n\n            var prefixSuffixedText = prefix + (format ? d3.format(format)(d.value) : d.value) + suffix;\n\n            var hasWrapSplitCharacter;\n            d.wrappingNeeded = !d.wrapped && !userBrokenText && !latex && (hasWrapSplitCharacter = hasWrapCharacter(prefixSuffixedText));\n            d.cellHeightMayIncrease = hasBreaks || latex || d.mayHaveMarkup || (hasWrapSplitCharacter === void(0) ? hasWrapCharacter(prefixSuffixedText) : hasWrapSplitCharacter);\n            d.needsConvertToTspans = d.mayHaveMarkup || d.wrappingNeeded || d.latex;\n\n            var textToRender;\n            if(d.wrappingNeeded) {\n                var hrefPreservedText = c.wrapSplitCharacter === ' ' ? prefixSuffixedText.replace(/<a href=/ig, '<a_href=') : prefixSuffixedText;\n                var fragments = hrefPreservedText.split(c.wrapSplitCharacter);\n                var hrefRestoredFragments = c.wrapSplitCharacter === ' ' ? fragments.map(function(frag) {return frag.replace(/<a_href=/ig, '<a href=');}) : fragments;\n                d.fragments = hrefRestoredFragments.map(function(f) {return {text: f, width: null};});\n                d.fragments.push({fragment: c.wrapSpacer, width: null});\n                textToRender = hrefRestoredFragments.join(c.lineBreaker) + c.lineBreaker + c.wrapSpacer;\n            } else {\n                delete d.fragments;\n                textToRender = prefixSuffixedText;\n            }\n\n            return textToRender;\n        })\n        .attr('dy', function(d) {\n            return d.needsConvertToTspans ? 0 : '0.75em';\n        })\n        .each(function(d) {\n            var element = this;\n            var selection = d3.select(element);\n\n            // finalize what's in the DOM\n\n            var renderCallback = d.wrappingNeeded ? wrapTextMaker : updateYPositionMaker;\n            if(d.needsConvertToTspans) {\n                svgUtil.convertToTspans(selection, gd, renderCallback(allColumnBlock, element, tableControlView, gd, d));\n            } else {\n                d3.select(element.parentNode)\n                    // basic cell adjustment - compliance with `cellPad`\n                    .attr('transform', function(d) {return 'translate(' + xPosition(d) + ' ' + c.cellPad + ')';})\n                    .attr('text-anchor', function(d) {\n                        return ({\n                            left: 'start',\n                            center: 'middle',\n                            right: 'end'\n                        })[d.align];\n                    });\n            }\n        });\n}\n\nfunction isLatex(content) {\n    return typeof content === 'string' && content.match(c.latexCheck);\n}\n\nfunction hasWrapCharacter(text) {return text.indexOf(c.wrapSplitCharacter) !== -1;}\n\nfunction columnMoved(gd, calcdata, indices) {\n    var o = calcdata.gdColumnsOriginalOrder;\n    calcdata.gdColumns.sort(function(a, b) {\n        return indices[o.indexOf(a)] - indices[o.indexOf(b)];\n    });\n\n    calcdata.columnorder = indices;\n\n    // TODO: there's no data here, but also this reordering is not reflected\n    // in gd.data or even gd._fullData.\n    // For now I will not attempt to persist this in _preGUI\n    gd.emit('plotly_restyle');\n}\n\nfunction gridPick(spec, col, row) {\n    if(Array.isArray(spec)) {\n        var column = spec[Math.min(col, spec.length - 1)];\n        if(Array.isArray(column)) {\n            return column[Math.min(row, column.length - 1)];\n        } else {\n            return column;\n        }\n    } else {\n        return spec;\n    }\n}\n\nfunction easeColumn(selection, d, y) {\n    selection\n        .transition()\n        .ease(c.releaseTransitionEase)\n        .duration(c.releaseTransitionDuration)\n        .attr('transform', 'translate(' + d.x + ' ' + y + ')');\n}\n\nfunction cellsBlock(d) {return d.type === 'cells';}\nfunction headerBlock(d) {return d.type === 'header';}\n\n/**\n * Revolver panel and cell contents layouting\n */\n\nfunction headerHeight(d) {\n    var headerBlocks = d.rowBlocks.length ? d.rowBlocks[0].auxiliaryBlocks : [];\n    return headerBlocks.reduce(function(p, n) {return p + rowsHeight(n, Infinity);}, 0);\n}\n\nfunction findPagesAndCacheHeights(blocks, scrollY, scrollHeight) {\n    var pages = [];\n    var pTop = 0;\n\n    for(var blockIndex = 0; blockIndex < blocks.length; blockIndex++) {\n        var block = blocks[blockIndex];\n        var blockRows = block.rows;\n        var rowsHeight = 0;\n        for(var i = 0; i < blockRows.length; i++) {\n            rowsHeight += blockRows[i].rowHeight;\n        }\n\n        // caching allRowsHeight on the block - it's safe as this function is always called from within the code part\n        // that handles increases to row heights\n        block.allRowsHeight = rowsHeight;\n\n        var pBottom = pTop + rowsHeight;\n        var windowTop = scrollY;\n        var windowBottom = windowTop + scrollHeight;\n        if(windowTop < pBottom && windowBottom > pTop) {\n            pages.push(blockIndex);\n        }\n        pTop += rowsHeight;\n\n        // consider this nice final optimization; put it in `for` condition - caveat, currently the\n        // block.allRowsHeight relies on being invalidated, so enabling this opt may not be safe\n        // if(pages.length > 1) break;\n    }\n\n    return pages;\n}\n\nfunction updateBlockYPosition(gd, cellsColumnBlock, tableControlView) {\n    var d = flatData(cellsColumnBlock)[0];\n    if(d === undefined) return;\n    var blocks = d.rowBlocks;\n    var calcdata = d.calcdata;\n\n    var bottom = firstRowAnchor(blocks, blocks.length);\n    var scrollHeight = d.calcdata.groupHeight - headerHeight(d);\n    var scrollY = calcdata.scrollY = Math.max(0, Math.min(bottom - scrollHeight, calcdata.scrollY));\n\n    var pages = findPagesAndCacheHeights(blocks, scrollY, scrollHeight);\n    if(pages.length === 1) {\n        if(pages[0] === blocks.length - 1) {\n            pages.unshift(pages[0] - 1);\n        } else {\n            pages.push(pages[0] + 1);\n        }\n    }\n\n    // make phased out page jump by 2 while leaving stationary page intact\n    if(pages[0] % 2) {\n        pages.reverse();\n    }\n\n    cellsColumnBlock\n        .each(function(d, i) {\n            // these values will also be needed when a block is translated again due to growing cell height\n            d.page = pages[i];\n            d.scrollY = scrollY;\n        });\n\n    cellsColumnBlock\n        .attr('transform', function(d) {\n            var yTranslate = firstRowAnchor(d.rowBlocks, d.page) - d.scrollY;\n            return 'translate(0 ' + yTranslate + ')';\n        });\n\n    // conditionally rerendering panel 0 and 1\n    if(gd) {\n        conditionalPanelRerender(gd, tableControlView, cellsColumnBlock, pages, d.prevPages, d, 0);\n        conditionalPanelRerender(gd, tableControlView, cellsColumnBlock, pages, d.prevPages, d, 1);\n        renderScrollbarKit(tableControlView, gd);\n    }\n}\n\nfunction makeDragRow(gd, allTableControlView, optionalMultiplier, optionalPosition) {\n    return function dragRow(eventD) {\n        // may come from whichever DOM event target: drag, wheel, bar... eventD corresponds to event target\n        var d = eventD.calcdata ? eventD.calcdata : eventD;\n        var tableControlView = allTableControlView.filter(function(dd) {return d.key === dd.key;});\n        var multiplier = optionalMultiplier || d.scrollbarState.dragMultiplier;\n\n        var initialScrollY = d.scrollY;\n\n        d.scrollY = optionalPosition === void(0) ? d.scrollY + multiplier * d3.event.dy : optionalPosition;\n        var cellsColumnBlock = tableControlView.selectAll('.' + c.cn.yColumn).selectAll('.' + c.cn.columnBlock).filter(cellsBlock);\n        updateBlockYPosition(gd, cellsColumnBlock, tableControlView);\n\n        // return false if we've \"used\" the scroll, ie it did something,\n        // so the event shouldn't bubble (if appropriate)\n        return d.scrollY === initialScrollY;\n    };\n}\n\nfunction conditionalPanelRerender(gd, tableControlView, cellsColumnBlock, pages, prevPages, d, revolverIndex) {\n    var shouldComponentUpdate = pages[revolverIndex] !== prevPages[revolverIndex];\n    if(shouldComponentUpdate) {\n        clearTimeout(d.currentRepaint[revolverIndex]);\n        d.currentRepaint[revolverIndex] = setTimeout(function() {\n            // setTimeout might lag rendering but yields a smoother scroll, because fast scrolling makes\n            // some repaints invisible ie. wasteful (DOM work blocks the main thread)\n            var toRerender = cellsColumnBlock.filter(function(d, i) {return i === revolverIndex && pages[i] !== prevPages[i];});\n            renderColumnCellTree(gd, tableControlView, toRerender, cellsColumnBlock);\n            prevPages[revolverIndex] = pages[revolverIndex];\n        });\n    }\n}\n\nfunction wrapTextMaker(columnBlock, element, tableControlView, gd) {\n    return function wrapText() {\n        var cellTextHolder = d3.select(element.parentNode);\n        cellTextHolder\n            .each(function(d) {\n                var fragments = d.fragments;\n                cellTextHolder.selectAll('tspan.line').each(function(dd, i) {\n                    fragments[i].width = this.getComputedTextLength();\n                });\n                // last element is only for measuring the separator character, so it's ignored:\n                var separatorLength = fragments[fragments.length - 1].width;\n                var rest = fragments.slice(0, -1);\n                var currentRow = [];\n                var currentAddition, currentAdditionLength;\n                var currentRowLength = 0;\n                var rowLengthLimit = d.column.columnWidth - 2 * c.cellPad;\n                d.value = '';\n                while(rest.length) {\n                    currentAddition = rest.shift();\n                    currentAdditionLength = currentAddition.width + separatorLength;\n                    if(currentRowLength + currentAdditionLength > rowLengthLimit) {\n                        d.value += currentRow.join(c.wrapSpacer) + c.lineBreaker;\n                        currentRow = [];\n                        currentRowLength = 0;\n                    }\n                    currentRow.push(currentAddition.text);\n                    currentRowLength += currentAdditionLength;\n                }\n                if(currentRowLength) {\n                    d.value += currentRow.join(c.wrapSpacer);\n                }\n                d.wrapped = true;\n            });\n\n        // the pre-wrapped text was rendered only for the text measurements\n        cellTextHolder.selectAll('tspan.line').remove();\n\n        // resupply text, now wrapped\n        populateCellText(cellTextHolder.select('.' + c.cn.cellText), tableControlView, columnBlock, gd);\n        d3.select(element.parentNode.parentNode).call(setCellHeightAndPositionY);\n    };\n}\n\nfunction updateYPositionMaker(columnBlock, element, tableControlView, gd, d) {\n    return function updateYPosition() {\n        if(d.settledY) return;\n        var cellTextHolder = d3.select(element.parentNode);\n        var l = getBlock(d);\n        var rowIndex = d.key - l.firstRowIndex;\n\n        var declaredRowHeight = l.rows[rowIndex].rowHeight;\n\n        var requiredHeight = d.cellHeightMayIncrease ? element.parentNode.getBoundingClientRect().height + 2 * c.cellPad : declaredRowHeight;\n\n        var finalHeight = Math.max(requiredHeight, declaredRowHeight);\n        var increase = finalHeight - l.rows[rowIndex].rowHeight;\n\n        if(increase) {\n            // current row height increased\n            l.rows[rowIndex].rowHeight = finalHeight;\n\n            columnBlock\n                .selectAll('.' + c.cn.columnCell)\n                .call(setCellHeightAndPositionY);\n\n            updateBlockYPosition(null, columnBlock.filter(cellsBlock), 0);\n\n            // if d.column.type === 'header', then the scrollbar has to be pushed downward to the scrollable area\n            // if d.column.type === 'cells', it can still be relevant if total scrolling content height is less than the\n            //                               scrollable window, as increases to row heights may need scrollbar updates\n            renderScrollbarKit(tableControlView, gd, true);\n        }\n\n        cellTextHolder\n            .attr('transform', function() {\n                // this code block is only invoked for items where d.cellHeightMayIncrease is truthy\n                var element = this;\n                var columnCellElement = element.parentNode;\n                var box = columnCellElement.getBoundingClientRect();\n                var rectBox = d3.select(element.parentNode).select('.' + c.cn.cellRect).node().getBoundingClientRect();\n                var currentTransform = element.transform.baseVal.consolidate();\n                var yPosition = rectBox.top - box.top + (currentTransform ? currentTransform.matrix.f : c.cellPad);\n                return 'translate(' + xPosition(d, d3.select(element.parentNode).select('.' + c.cn.cellTextHolder).node().getBoundingClientRect().width) + ' ' + yPosition + ')';\n            });\n\n        d.settledY = true;\n    };\n}\n\nfunction xPosition(d, optionalWidth) {\n    switch(d.align) {\n        case 'left': return c.cellPad;\n        case 'right': return d.column.columnWidth - (optionalWidth || 0) - c.cellPad;\n        case 'center': return (d.column.columnWidth - (optionalWidth || 0)) / 2;\n        default: return c.cellPad;\n    }\n}\n\nfunction setCellHeightAndPositionY(columnCell) {\n    columnCell\n        .attr('transform', function(d) {\n            var headerHeight = d.rowBlocks[0].auxiliaryBlocks.reduce(function(p, n) {return p + rowsHeight(n, Infinity);}, 0);\n            var l = getBlock(d);\n            var rowAnchor = rowsHeight(l, d.key);\n            var yOffset = rowAnchor + headerHeight;\n            return 'translate(0 ' + yOffset + ')';\n        })\n        .selectAll('.' + c.cn.cellRect)\n        .attr('height', function(d) {return getRow(getBlock(d), d.key).rowHeight;});\n}\n\nfunction firstRowAnchor(blocks, page) {\n    var total = 0;\n    for(var i = page - 1; i >= 0; i--) {\n        total += allRowsHeight(blocks[i]);\n    }\n    return total;\n}\n\nfunction rowsHeight(rowBlock, key) {\n    var total = 0;\n    for(var i = 0; i < rowBlock.rows.length && rowBlock.rows[i].rowIndex < key; i++) {\n        total += rowBlock.rows[i].rowHeight;\n    }\n    return total;\n}\n\nfunction allRowsHeight(rowBlock) {\n    var cached = rowBlock.allRowsHeight;\n\n    if(cached !== void(0)) {\n        return cached;\n    }\n\n    var total = 0;\n    for(var i = 0; i < rowBlock.rows.length; i++) {\n        total += rowBlock.rows[i].rowHeight;\n    }\n    rowBlock.allRowsHeight = total;\n\n    return total;\n}\n\nfunction getBlock(d) {return d.rowBlocks[d.page];}\nfunction getRow(l, i) {return l.rows[i - l.firstRowIndex];}\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../lib\":719,\"../../lib/gup\":717,\"../../lib/svg_text_utils\":743,\"./constants\":1232,\"./data_preparation_helper\":1233,\"./data_split_helpers\":1234,\"d3\":163}],1238:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar boxAttrs = _dereq_('../box/attributes');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\n\nmodule.exports = {\n    y: boxAttrs.y,\n    x: boxAttrs.x,\n    x0: boxAttrs.x0,\n    y0: boxAttrs.y0,\n    name: extendFlat({}, boxAttrs.name, {\n        \n    }),\n    orientation: extendFlat({}, boxAttrs.orientation, {\n        \n    }),\n\n    bandwidth: {\n        valType: 'number',\n        min: 0,\n        \n        editType: 'calc',\n        \n    },\n\n    scalegroup: {\n        valType: 'string',\n        \n        dflt: '',\n        editType: 'calc',\n        \n    },\n    scalemode: {\n        valType: 'enumerated',\n        values: ['width', 'count'],\n        dflt: 'width',\n        \n        editType: 'calc',\n        \n    },\n\n    spanmode: {\n        valType: 'enumerated',\n        values: ['soft', 'hard', 'manual'],\n        dflt: 'soft',\n        \n        editType: 'calc',\n        \n    },\n    span: {\n        valType: 'info_array',\n        items: [\n            {valType: 'any', editType: 'calc'},\n            {valType: 'any', editType: 'calc'}\n        ],\n        \n        editType: 'calc',\n        \n    },\n\n    line: {\n        color: {\n            valType: 'color',\n            \n            editType: 'style',\n            \n        },\n        width: {\n            valType: 'number',\n            \n            min: 0,\n            dflt: 2,\n            editType: 'style',\n            \n        },\n        editType: 'plot'\n    },\n    fillcolor: boxAttrs.fillcolor,\n\n    points: extendFlat({}, boxAttrs.boxpoints, {\n        \n    }),\n    jitter: extendFlat({}, boxAttrs.jitter, {\n        \n    }),\n    pointpos: extendFlat({}, boxAttrs.pointpos, {\n        \n    }),\n\n    width: extendFlat({}, boxAttrs.width, {\n        \n    }),\n\n    marker: boxAttrs.marker,\n    text: boxAttrs.text,\n    hovertext: boxAttrs.hovertext,\n    hovertemplate: boxAttrs.hovertemplate,\n\n    box: {\n        visible: {\n            valType: 'boolean',\n            dflt: false,\n            \n            editType: 'plot',\n            \n        },\n        width: {\n            valType: 'number',\n            min: 0,\n            max: 1,\n            dflt: 0.25,\n            \n            editType: 'plot',\n            \n        },\n        fillcolor: {\n            valType: 'color',\n            \n            editType: 'style',\n            \n        },\n        line: {\n            color: {\n                valType: 'color',\n                \n                editType: 'style',\n                \n            },\n            width: {\n                valType: 'number',\n                min: 0,\n                \n                editType: 'style',\n                \n            },\n            editType: 'style'\n        },\n        editType: 'plot'\n    },\n\n    meanline: {\n        visible: {\n            valType: 'boolean',\n            dflt: false,\n            \n            editType: 'plot',\n            \n        },\n        color: {\n            valType: 'color',\n            \n            editType: 'style',\n            \n        },\n        width: {\n            valType: 'number',\n            min: 0,\n            \n            editType: 'style',\n            \n        },\n        editType: 'plot'\n    },\n\n    side: {\n        valType: 'enumerated',\n        values: ['both', 'positive', 'negative'],\n        dflt: 'both',\n        \n        editType: 'calc',\n        \n    },\n\n    offsetgroup: boxAttrs.offsetgroup,\n    alignmentgroup: boxAttrs.alignmentgroup,\n\n    selected: boxAttrs.selected,\n    unselected: boxAttrs.unselected,\n\n    hoveron: {\n        valType: 'flaglist',\n        flags: ['violins', 'points', 'kde'],\n        dflt: 'violins+points+kde',\n        extras: ['all'],\n        \n        editType: 'style',\n        \n    }\n};\n\n},{\"../../lib/extend\":710,\"../box/attributes\":880}],1239:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar boxCalc = _dereq_('../box/calc');\nvar helpers = _dereq_('./helpers');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nmodule.exports = function calc(gd, trace) {\n    var cd = boxCalc(gd, trace);\n\n    if(cd[0].t.empty) return cd;\n\n    var fullLayout = gd._fullLayout;\n    var valAxis = Axes.getFromId(\n        gd,\n        trace[trace.orientation === 'h' ? 'xaxis' : 'yaxis']\n    );\n\n    var spanMin = Infinity;\n    var spanMax = -Infinity;\n    var maxKDE = 0;\n    var maxCount = 0;\n\n    for(var i = 0; i < cd.length; i++) {\n        var cdi = cd[i];\n        var vals = cdi.pts.map(helpers.extractVal);\n\n        var bandwidth = cdi.bandwidth = calcBandwidth(trace, cdi, vals);\n        var span = cdi.span = calcSpan(trace, cdi, valAxis, bandwidth);\n\n        if(cdi.min === cdi.max && bandwidth === 0) {\n            // if span is zero and bandwidth is zero, we want a violin with zero width\n            span = cdi.span = [cdi.min, cdi.max];\n            cdi.density = [{v: 1, t: span[0]}];\n            cdi.bandwidth = bandwidth;\n            maxKDE = Math.max(maxKDE, 1);\n        } else {\n            // step that well covers the bandwidth and is multiple of span distance\n            var dist = span[1] - span[0];\n            var n = Math.ceil(dist / (bandwidth / 3));\n            var step = dist / n;\n\n            if(!isFinite(step) || !isFinite(n)) {\n                Lib.error('Something went wrong with computing the violin span');\n                cd[0].t.empty = true;\n                return cd;\n            }\n\n            var kde = helpers.makeKDE(cdi, trace, vals);\n            cdi.density = new Array(n);\n\n            for(var k = 0, t = span[0]; t < (span[1] + step / 2); k++, t += step) {\n                var v = kde(t);\n                cdi.density[k] = {v: v, t: t};\n                maxKDE = Math.max(maxKDE, v);\n            }\n        }\n\n        maxCount = Math.max(maxCount, vals.length);\n        spanMin = Math.min(spanMin, span[0]);\n        spanMax = Math.max(spanMax, span[1]);\n    }\n\n    var extremes = Axes.findExtremes(valAxis, [spanMin, spanMax], {padded: true});\n    trace._extremes[valAxis._id] = extremes;\n\n    if(trace.width) {\n        cd[0].t.maxKDE = maxKDE;\n    } else {\n        var violinScaleGroupStats = fullLayout._violinScaleGroupStats;\n        var scaleGroup = trace.scalegroup;\n        var groupStats = violinScaleGroupStats[scaleGroup];\n\n        if(groupStats) {\n            groupStats.maxKDE = Math.max(groupStats.maxKDE, maxKDE);\n            groupStats.maxCount = Math.max(groupStats.maxCount, maxCount);\n        } else {\n            violinScaleGroupStats[scaleGroup] = {\n                maxKDE: maxKDE,\n                maxCount: maxCount\n            };\n        }\n    }\n\n    cd[0].t.labels.kde = Lib._(gd, 'kde:');\n\n    return cd;\n};\n\n// Default to Silveman's rule of thumb\n// - https://stats.stackexchange.com/a/6671\n// - https://en.wikipedia.org/wiki/Kernel_density_estimation#A_rule-of-thumb_bandwidth_estimator\n// - https://github.com/statsmodels/statsmodels/blob/master/statsmodels/nonparametric/bandwidths.py\nfunction silvermanRule(len, ssd, iqr) {\n    var a = Math.min(ssd, iqr / 1.349);\n    return 1.059 * a * Math.pow(len, -0.2);\n}\n\nfunction calcBandwidth(trace, cdi, vals) {\n    var span = cdi.max - cdi.min;\n\n    // If span is zero\n    if(!span) {\n        if(trace.bandwidth) {\n            return trace.bandwidth;\n        } else {\n            // if span is zero and no bandwidth is specified\n            // it returns zero bandwidth which is a special case\n            return 0;\n        }\n    }\n\n    // Limit how small the bandwidth can be.\n    //\n    // Silverman's rule of thumb can be \"very\" small\n    // when IQR does a poor job at describing the spread\n    // of the distribution.\n    // We also want to limit custom bandwidths\n    // to not blow up kde computations.\n\n    if(trace.bandwidth) {\n        return Math.max(trace.bandwidth, span / 1e4);\n    } else {\n        var len = vals.length;\n        var ssd = Lib.stdev(vals, len - 1, cdi.mean);\n        return Math.max(\n            silvermanRule(len, ssd, cdi.q3 - cdi.q1),\n            span / 100\n        );\n    }\n}\n\nfunction calcSpan(trace, cdi, valAxis, bandwidth) {\n    var spanmode = trace.spanmode;\n    var spanIn = trace.span || [];\n    var spanTight = [cdi.min, cdi.max];\n    var spanLoose = [cdi.min - 2 * bandwidth, cdi.max + 2 * bandwidth];\n    var spanOut;\n\n    function calcSpanItem(index) {\n        var s = spanIn[index];\n        var sc = valAxis.type === 'multicategory' ?\n            valAxis.r2c(s) :\n            valAxis.d2c(s, 0, trace[cdi.valLetter + 'calendar']);\n        return sc === BADNUM ? spanLoose[index] : sc;\n    }\n\n    if(spanmode === 'soft') {\n        spanOut = spanLoose;\n    } else if(spanmode === 'hard') {\n        spanOut = spanTight;\n    } else {\n        spanOut = [calcSpanItem(0), calcSpanItem(1)];\n    }\n\n    // to reuse the equal-range-item block\n    var dummyAx = {\n        type: 'linear',\n        range: spanOut\n    };\n    Axes.setConvert(dummyAx);\n    dummyAx.cleanRange();\n\n    return spanOut;\n}\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../box/calc\":881,\"./helpers\":1242}],1240:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar setPositionOffset = _dereq_('../box/cross_trace_calc').setPositionOffset;\nvar orientations = ['v', 'h'];\n\nmodule.exports = function crossTraceCalc(gd, plotinfo) {\n    var calcdata = gd.calcdata;\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    for(var i = 0; i < orientations.length; i++) {\n        var orientation = orientations[i];\n        var posAxis = orientation === 'h' ? ya : xa;\n        var violinList = [];\n\n        for(var j = 0; j < calcdata.length; j++) {\n            var cd = calcdata[j];\n            var t = cd[0].t;\n            var trace = cd[0].trace;\n\n            if(trace.visible === true && trace.type === 'violin' &&\n                    !t.empty &&\n                    trace.orientation === orientation &&\n                    trace.xaxis === xa._id &&\n                    trace.yaxis === ya._id\n              ) {\n                violinList.push(j);\n            }\n        }\n\n        setPositionOffset('violin', gd, violinList, posAxis);\n    }\n};\n\n},{\"../box/cross_trace_calc\":882}],1241:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Color = _dereq_('../../components/color');\n\nvar boxDefaults = _dereq_('../box/defaults');\nvar attributes = _dereq_('./attributes');\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n    function coerce2(attr, dflt) {\n        return Lib.coerce2(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    boxDefaults.handleSampleDefaults(traceIn, traceOut, coerce, layout);\n    if(traceOut.visible === false) return;\n\n    coerce('bandwidth');\n    coerce('side');\n\n    var width = coerce('width');\n    if(!width) {\n        coerce('scalegroup', traceOut.name);\n        coerce('scalemode');\n    }\n\n    var span = coerce('span');\n    var spanmodeDflt;\n    if(Array.isArray(span)) spanmodeDflt = 'manual';\n    coerce('spanmode', spanmodeDflt);\n\n    var lineColor = coerce('line.color', (traceIn.marker || {}).color || defaultColor);\n    var lineWidth = coerce('line.width');\n    var fillColor = coerce('fillcolor', Color.addOpacity(traceOut.line.color, 0.5));\n\n    boxDefaults.handlePointsDefaults(traceIn, traceOut, coerce, {prefix: ''});\n\n    var boxWidth = coerce2('box.width');\n    var boxFillColor = coerce2('box.fillcolor', fillColor);\n    var boxLineColor = coerce2('box.line.color', lineColor);\n    var boxLineWidth = coerce2('box.line.width', lineWidth);\n    var boxVisible = coerce('box.visible', Boolean(boxWidth || boxFillColor || boxLineColor || boxLineWidth));\n    if(!boxVisible) traceOut.box = {visible: false};\n\n    var meanLineColor = coerce2('meanline.color', lineColor);\n    var meanLineWidth = coerce2('meanline.width', lineWidth);\n    var meanLineVisible = coerce('meanline.visible', Boolean(meanLineColor || meanLineWidth));\n    if(!meanLineVisible) traceOut.meanline = {visible: false};\n};\n\n},{\"../../components/color\":593,\"../../lib\":719,\"../box/defaults\":883,\"./attributes\":1238}],1242:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\n// Maybe add kernels more down the road,\n// but note that the default `spanmode: 'soft'` bounds might have\n// to become kernel-dependent\nvar kernels = {\n    gaussian: function(v) {\n        return (1 / Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * v * v);\n    }\n};\n\nexports.makeKDE = function(calcItem, trace, vals) {\n    var len = vals.length;\n    var kernel = kernels.gaussian;\n    var bandwidth = calcItem.bandwidth;\n    var factor = 1 / (len * bandwidth);\n\n    // don't use Lib.aggNums to skip isNumeric checks\n    return function(x) {\n        var sum = 0;\n        for(var i = 0; i < len; i++) {\n            sum += kernel((x - vals[i]) / bandwidth);\n        }\n        return factor * sum;\n    };\n};\n\nexports.getPositionOnKdePath = function(calcItem, trace, valuePx) {\n    var posLetter, valLetter;\n\n    if(trace.orientation === 'h') {\n        posLetter = 'y';\n        valLetter = 'x';\n    } else {\n        posLetter = 'x';\n        valLetter = 'y';\n    }\n\n    var pointOnPath = Lib.findPointOnPath(\n        calcItem.path,\n        valuePx,\n        valLetter,\n        {pathLength: calcItem.pathLength}\n    );\n\n    var posCenterPx = calcItem.posCenterPx;\n    var posOnPath0 = pointOnPath[posLetter];\n    var posOnPath1 = trace.side === 'both' ?\n        2 * posCenterPx - posOnPath0 :\n        posCenterPx;\n\n    return [posOnPath0, posOnPath1];\n};\n\nexports.getKdeValue = function(calcItem, trace, valueDist) {\n    var vals = calcItem.pts.map(exports.extractVal);\n    var kde = exports.makeKDE(calcItem, trace, vals);\n    return kde(valueDist) / calcItem.posDensityScale;\n};\n\nexports.extractVal = function(o) { return o.v; };\n\n},{\"../../lib\":719}],1243:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar boxHoverPoints = _dereq_('../box/hover');\nvar helpers = _dereq_('./helpers');\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer) {\n    var cd = pointData.cd;\n    var trace = cd[0].trace;\n    var hoveron = trace.hoveron;\n    var hasHoveronViolins = hoveron.indexOf('violins') !== -1;\n    var hasHoveronKDE = hoveron.indexOf('kde') !== -1;\n    var closeData = [];\n    var closePtData;\n    var violinLineAttrs;\n\n    if(hasHoveronViolins || hasHoveronKDE) {\n        var closeBoxData = boxHoverPoints.hoverOnBoxes(pointData, xval, yval, hovermode);\n\n        if(hasHoveronKDE && closeBoxData.length > 0) {\n            var xa = pointData.xa;\n            var ya = pointData.ya;\n            var pLetter, vLetter, pAxis, vAxis, vVal;\n\n            if(trace.orientation === 'h') {\n                vVal = xval;\n                pLetter = 'y';\n                pAxis = ya;\n                vLetter = 'x';\n                vAxis = xa;\n            } else {\n                vVal = yval;\n                pLetter = 'x';\n                pAxis = xa;\n                vLetter = 'y';\n                vAxis = ya;\n            }\n\n            var di = cd[pointData.index];\n\n            if(vVal >= di.span[0] && vVal <= di.span[1]) {\n                var kdePointData = Lib.extendFlat({}, pointData);\n                var vValPx = vAxis.c2p(vVal, true);\n                var kdeVal = helpers.getKdeValue(di, trace, vVal);\n                var pOnPath = helpers.getPositionOnKdePath(di, trace, vValPx);\n                var paOffset = pAxis._offset;\n                var paLength = pAxis._length;\n\n                kdePointData[pLetter + '0'] = pOnPath[0];\n                kdePointData[pLetter + '1'] = pOnPath[1];\n                kdePointData[vLetter + '0'] = kdePointData[vLetter + '1'] = vValPx;\n                kdePointData[vLetter + 'Label'] = vLetter + ': ' + Axes.hoverLabelText(vAxis, vVal) + ', ' + cd[0].t.labels.kde + ' ' + kdeVal.toFixed(3);\n\n                // move the spike to the KDE point\n                kdePointData.spikeDistance = closeBoxData[0].spikeDistance;\n                var spikePosAttr = pLetter + 'Spike';\n                kdePointData[spikePosAttr] = closeBoxData[0][spikePosAttr];\n                closeBoxData[0].spikeDistance = undefined;\n                closeBoxData[0][spikePosAttr] = undefined;\n\n                // no hovertemplate support yet\n                kdePointData.hovertemplate = false;\n\n                closeData.push(kdePointData);\n\n                violinLineAttrs = {stroke: pointData.color};\n                violinLineAttrs[pLetter + '1'] = Lib.constrain(paOffset + pOnPath[0], paOffset, paOffset + paLength);\n                violinLineAttrs[pLetter + '2'] = Lib.constrain(paOffset + pOnPath[1], paOffset, paOffset + paLength);\n                violinLineAttrs[vLetter + '1'] = violinLineAttrs[vLetter + '2'] = vAxis._offset + vValPx;\n            }\n        }\n\n        if(hasHoveronViolins) {\n            closeData = closeData.concat(closeBoxData);\n        }\n    }\n\n    if(hoveron.indexOf('points') !== -1) {\n        closePtData = boxHoverPoints.hoverOnPoints(pointData, xval, yval);\n    }\n\n    // update violin line (if any)\n    var violinLine = hoverLayer.selectAll('.violinline-' + trace.uid)\n        .data(violinLineAttrs ? [0] : []);\n    violinLine.enter().append('line')\n        .classed('violinline-' + trace.uid, true)\n        .attr('stroke-width', 1.5);\n    violinLine.exit().remove();\n    violinLine.attr(violinLineAttrs);\n\n    // same combine logic as box hoverPoints\n    if(hovermode === 'closest') {\n        if(closePtData) return [closePtData];\n        return closeData;\n    }\n    if(closePtData) {\n        closeData.push(closePtData);\n        return closeData;\n    }\n    return closeData;\n};\n\n},{\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../box/hover\":885,\"./helpers\":1242}],1244:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    crossTraceDefaults: _dereq_('../box/defaults').crossTraceDefaults,\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n    calc: _dereq_('./calc'),\n    crossTraceCalc: _dereq_('./cross_trace_calc'),\n    plot: _dereq_('./plot'),\n    style: _dereq_('./style'),\n    styleOnSelect: _dereq_('../scatter/style').styleOnSelect,\n    hoverPoints: _dereq_('./hover'),\n    selectPoints: _dereq_('../box/select'),\n\n    moduleType: 'trace',\n    name: 'violin',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['cartesian', 'svg', 'symbols', 'oriented', 'box-violin', 'showLegend', 'violinLayout', 'zoomScale'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../box/defaults\":883,\"../box/select\":890,\"../scatter/style\":1134,\"./attributes\":1238,\"./calc\":1239,\"./cross_trace_calc\":1240,\"./defaults\":1241,\"./hover\":1243,\"./layout_attributes\":1245,\"./layout_defaults\":1246,\"./plot\":1247,\"./style\":1248}],1245:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar boxLayoutAttrs = _dereq_('../box/layout_attributes');\nvar extendFlat = _dereq_('../../lib').extendFlat;\n\nmodule.exports = {\n    violinmode: extendFlat({}, boxLayoutAttrs.boxmode, {\n        \n    }),\n    violingap: extendFlat({}, boxLayoutAttrs.boxgap, {\n        \n    }),\n    violingroupgap: extendFlat({}, boxLayoutAttrs.boxgroupgap, {\n        \n    })\n};\n\n},{\"../../lib\":719,\"../box/layout_attributes\":887}],1246:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar layoutAttributes = _dereq_('./layout_attributes');\nvar boxLayoutDefaults = _dereq_('../box/layout_defaults');\n\nmodule.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n    boxLayoutDefaults._supply(layoutIn, layoutOut, fullData, coerce, 'violin');\n};\n\n},{\"../../lib\":719,\"../box/layout_defaults\":888,\"./layout_attributes\":1245}],1247:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../../components/drawing');\n\nvar boxPlot = _dereq_('../box/plot');\nvar linePoints = _dereq_('../scatter/line_points');\nvar helpers = _dereq_('./helpers');\n\nmodule.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {\n    var fullLayout = gd._fullLayout;\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    function makePath(pts) {\n        var segments = linePoints(pts, {\n            xaxis: xa,\n            yaxis: ya,\n            connectGaps: true,\n            baseTolerance: 0.75,\n            shape: 'spline',\n            simplify: true\n        });\n        return Drawing.smoothopen(segments[0], 1);\n    }\n\n    Lib.makeTraceGroups(violinLayer, cdViolins, 'trace violins').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var cd0 = cd[0];\n        var t = cd0.t;\n        var trace = cd0.trace;\n\n        if(trace.visible !== true || t.empty) {\n            plotGroup.remove();\n            return;\n        }\n\n        var bPos = t.bPos;\n        var bdPos = t.bdPos;\n        var valAxis = plotinfo[t.valLetter + 'axis'];\n        var posAxis = plotinfo[t.posLetter + 'axis'];\n        var hasBothSides = trace.side === 'both';\n        var hasPositiveSide = hasBothSides || trace.side === 'positive';\n        var hasNegativeSide = hasBothSides || trace.side === 'negative';\n\n        var violins = plotGroup.selectAll('path.violin').data(Lib.identity);\n\n        violins.enter().append('path')\n            .style('vector-effect', 'non-scaling-stroke')\n            .attr('class', 'violin');\n\n        violins.exit().remove();\n\n        violins.each(function(d) {\n            var pathSel = d3.select(this);\n            var density = d.density;\n            var len = density.length;\n            var posCenter = d.pos + bPos;\n            var posCenterPx = posAxis.c2p(posCenter);\n\n            var scale;\n            if(trace.width) {\n                scale = t.maxKDE / bdPos;\n            } else {\n                var groupStats = fullLayout._violinScaleGroupStats[trace.scalegroup];\n                scale = trace.scalemode === 'count' ?\n                    (groupStats.maxKDE / bdPos) * (groupStats.maxCount / d.pts.length) :\n                    groupStats.maxKDE / bdPos;\n            }\n\n            var pathPos, pathNeg, path;\n            var i, k, pts, pt;\n\n            if(hasPositiveSide) {\n                pts = new Array(len);\n                for(i = 0; i < len; i++) {\n                    pt = pts[i] = {};\n                    pt[t.posLetter] = posCenter + (density[i].v / scale);\n                    pt[t.valLetter] = density[i].t;\n                }\n                pathPos = makePath(pts);\n            }\n\n            if(hasNegativeSide) {\n                pts = new Array(len);\n                for(k = 0, i = len - 1; k < len; k++, i--) {\n                    pt = pts[k] = {};\n                    pt[t.posLetter] = posCenter - (density[i].v / scale);\n                    pt[t.valLetter] = density[i].t;\n                }\n                pathNeg = makePath(pts);\n            }\n\n            if(hasBothSides) {\n                path = pathPos + 'L' + pathNeg.substr(1) + 'Z';\n            } else {\n                var startPt = [posCenterPx, valAxis.c2p(density[0].t)];\n                var endPt = [posCenterPx, valAxis.c2p(density[len - 1].t)];\n\n                if(trace.orientation === 'h') {\n                    startPt.reverse();\n                    endPt.reverse();\n                }\n\n                if(hasPositiveSide) {\n                    path = 'M' + startPt + 'L' + pathPos.substr(1) + 'L' + endPt;\n                } else {\n                    path = 'M' + endPt + 'L' + pathNeg.substr(1) + 'L' + startPt;\n                }\n            }\n            pathSel.attr('d', path);\n\n            // save a few things used in getPositionOnKdePath, getKdeValue\n            // on hover and for meanline draw block below\n            d.posCenterPx = posCenterPx;\n            d.posDensityScale = scale * bdPos;\n            d.path = pathSel.node();\n            d.pathLength = d.path.getTotalLength() / (hasBothSides ? 2 : 1);\n        });\n\n        var boxAttrs = trace.box;\n        var boxWidth = boxAttrs.width;\n        var boxLineWidth = (boxAttrs.line || {}).width;\n        var bdPosScaled;\n        var bPosPxOffset;\n\n        if(hasBothSides) {\n            bdPosScaled = bdPos * boxWidth;\n            bPosPxOffset = 0;\n        } else if(hasPositiveSide) {\n            bdPosScaled = [0, bdPos * boxWidth / 2];\n            bPosPxOffset = -boxLineWidth;\n        } else {\n            bdPosScaled = [bdPos * boxWidth / 2, 0];\n            bPosPxOffset = boxLineWidth;\n        }\n\n        // inner box\n        boxPlot.plotBoxAndWhiskers(plotGroup, {pos: posAxis, val: valAxis}, trace, {\n            bPos: bPos,\n            bdPos: bdPosScaled,\n            bPosPxOffset: bPosPxOffset\n        });\n\n        // meanline insider box\n        boxPlot.plotBoxMean(plotGroup, {pos: posAxis, val: valAxis}, trace, {\n            bPos: bPos,\n            bdPos: bdPosScaled,\n            bPosPxOffset: bPosPxOffset\n        });\n\n        var fn;\n        if(!trace.box.visible && trace.meanline.visible) {\n            fn = Lib.identity;\n        }\n\n        // N.B. use different class name than boxPlot.plotBoxMean,\n        // to avoid selectAll conflict\n        var meanPaths = plotGroup.selectAll('path.meanline').data(fn || []);\n        meanPaths.enter().append('path')\n            .attr('class', 'meanline')\n            .style('fill', 'none')\n            .style('vector-effect', 'non-scaling-stroke');\n        meanPaths.exit().remove();\n        meanPaths.each(function(d) {\n            var v = valAxis.c2p(d.mean, true);\n            var p = helpers.getPositionOnKdePath(d, trace, v);\n\n            d3.select(this).attr('d',\n                trace.orientation === 'h' ?\n                    'M' + v + ',' + p[0] + 'V' + p[1] :\n                    'M' + p[0] + ',' + v + 'H' + p[1]\n            );\n        });\n\n        boxPlot.plotPoints(plotGroup, {x: xa, y: ya}, trace, t);\n    });\n};\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../box/plot\":889,\"../scatter/line_points\":1125,\"./helpers\":1242,\"d3\":163}],1248:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Color = _dereq_('../../components/color');\nvar stylePoints = _dereq_('../scatter/style').stylePoints;\n\nmodule.exports = function style(gd) {\n    var s = d3.select(gd).selectAll('g.trace.violins');\n\n    s.style('opacity', function(d) { return d[0].trace.opacity; });\n\n    s.each(function(d) {\n        var trace = d[0].trace;\n        var sel = d3.select(this);\n        var box = trace.box || {};\n        var boxLine = box.line || {};\n        var meanline = trace.meanline || {};\n        var meanLineWidth = meanline.width;\n\n        sel.selectAll('path.violin')\n            .style('stroke-width', trace.line.width + 'px')\n            .call(Color.stroke, trace.line.color)\n            .call(Color.fill, trace.fillcolor);\n\n        sel.selectAll('path.box')\n            .style('stroke-width', boxLine.width + 'px')\n            .call(Color.stroke, boxLine.color)\n            .call(Color.fill, box.fillcolor);\n\n        var meanLineStyle = {\n            'stroke-width': meanLineWidth + 'px',\n            'stroke-dasharray': (2 * meanLineWidth) + 'px,' + meanLineWidth + 'px'\n        };\n\n        sel.selectAll('path.mean')\n            .style(meanLineStyle)\n            .call(Color.stroke, meanline.color);\n\n        sel.selectAll('path.meanline')\n            .style(meanLineStyle)\n            .call(Color.stroke, meanline.color);\n\n        stylePoints(sel, trace, gd);\n    });\n};\n\n},{\"../../components/color\":593,\"../scatter/style\":1134,\"d3\":163}],1249:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar colorScaleAttrs = _dereq_('../../components/colorscale/attributes');\nvar isosurfaceAttrs = _dereq_('../isosurface/attributes');\nvar baseAttrs = _dereq_('../../plots/attributes');\n\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;\n\nvar attrs = module.exports = overrideAll(extendFlat({\n    x: isosurfaceAttrs.x,\n    y: isosurfaceAttrs.y,\n    z: isosurfaceAttrs.z,\n    value: isosurfaceAttrs.value,\n    isomin: isosurfaceAttrs.isomin,\n    isomax: isosurfaceAttrs.isomax,\n    surface: isosurfaceAttrs.surface,\n    spaceframe: {\n        show: {\n            valType: 'boolean',\n            \n            dflt: false,\n            \n        },\n        fill: {\n            valType: 'number',\n            \n            min: 0,\n            max: 1,\n            dflt: 1,\n            \n        }\n    },\n\n    slices: isosurfaceAttrs.slices,\n    caps: isosurfaceAttrs.caps,\n    text: isosurfaceAttrs.text,\n    hovertext: isosurfaceAttrs.hovertext,\n    hovertemplate: isosurfaceAttrs.hovertemplate\n},\n\ncolorScaleAttrs('', {\n    colorAttr: '`value`',\n    showScaleDflt: true,\n    editTypeOverride: 'calc'\n}), {\n\n    colorbar: isosurfaceAttrs.colorbar,\n    opacity: isosurfaceAttrs.opacity,\n    opacityscale: {\n        valType: 'any',\n        \n        editType: 'calc',\n        \n    },\n\n    lightposition: isosurfaceAttrs.lightposition,\n    lighting: isosurfaceAttrs.lighting,\n    flatshading: isosurfaceAttrs.flatshading,\n    contour: isosurfaceAttrs.contour,\n\n    hoverinfo: extendFlat({}, baseAttrs.hoverinfo)\n}), 'calc', 'nested');\n\nattrs.x.editType = attrs.y.editType = attrs.z.editType = attrs.value.editType = 'calc+clearAxisTypes';\nattrs.transforms = undefined;\n\n},{\"../../components/colorscale/attributes\":600,\"../../lib/extend\":710,\"../../plot_api/edit_types\":750,\"../../plots/attributes\":764,\"../isosurface/attributes\":1048}],1250:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar createMesh = _dereq_('gl-mesh3d');\n\nvar parseColorScale = _dereq_('../../lib/gl_format_color').parseColorScale;\nvar str2RgbaArray = _dereq_('../../lib/str2rgbarray');\nvar extractOpts = _dereq_('../../components/colorscale').extractOpts;\nvar zip3 = _dereq_('../../plots/gl3d/zip3');\n\nvar findNearestOnAxis = _dereq_('../isosurface/convert').findNearestOnAxis;\nvar generateIsoMeshes = _dereq_('../isosurface/convert').generateIsoMeshes;\n\nfunction VolumeTrace(scene, mesh, uid) {\n    this.scene = scene;\n    this.uid = uid;\n    this.mesh = mesh;\n    this.name = '';\n    this.data = null;\n    this.showContour = false;\n}\n\nvar proto = VolumeTrace.prototype;\n\nproto.handlePick = function(selection) {\n    if(selection.object === this.mesh) {\n        var rawId = selection.data.index;\n\n        var x = this.data._x[rawId];\n        var y = this.data._y[rawId];\n        var z = this.data._z[rawId];\n\n        var height = this.data._Ys.length;\n        var depth = this.data._Zs.length;\n\n        var i = findNearestOnAxis(x, this.data._Xs).id;\n        var j = findNearestOnAxis(y, this.data._Ys).id;\n        var k = findNearestOnAxis(z, this.data._Zs).id;\n\n        var selectIndex = selection.index = k + depth * j + depth * height * i;\n\n        selection.traceCoordinate = [\n            this.data._x[selectIndex],\n            this.data._y[selectIndex],\n            this.data._z[selectIndex],\n            this.data.value[selectIndex]\n        ];\n\n        var text = this.data.hovertext || this.data.text;\n        if(Array.isArray(text) && text[selectIndex] !== undefined) {\n            selection.textLabel = text[selectIndex];\n        } else if(text) {\n            selection.textLabel = text;\n        }\n\n        return true;\n    }\n};\n\nproto.update = function(data) {\n    var scene = this.scene;\n    var layout = scene.fullSceneLayout;\n\n    this.data = generateIsoMeshes(data);\n\n    // Unpack position data\n    function toDataCoords(axis, coord, scale, calendar) {\n        return coord.map(function(x) {\n            return axis.d2l(x, 0, calendar) * scale;\n        });\n    }\n\n    var positions = zip3(\n        toDataCoords(layout.xaxis, data._x, scene.dataScale[0], data.xcalendar),\n        toDataCoords(layout.yaxis, data._y, scene.dataScale[1], data.ycalendar),\n        toDataCoords(layout.zaxis, data._z, scene.dataScale[2], data.zcalendar));\n\n    var cells = zip3(data._i, data._j, data._k);\n\n    var config = {\n        positions: positions,\n        cells: cells,\n        lightPosition: [data.lightposition.x, data.lightposition.y, data.lightposition.z],\n        ambient: data.lighting.ambient,\n        diffuse: data.lighting.diffuse,\n        specular: data.lighting.specular,\n        roughness: data.lighting.roughness,\n        fresnel: data.lighting.fresnel,\n        vertexNormalsEpsilon: data.lighting.vertexnormalsepsilon,\n        faceNormalsEpsilon: data.lighting.facenormalsepsilon,\n        opacity: data.opacity,\n        opacityscale: data.opacityscale,\n        contourEnable: data.contour.show,\n        contourColor: str2RgbaArray(data.contour.color).slice(0, 3),\n        contourWidth: data.contour.width,\n        useFacetNormals: data.flatshading\n    };\n\n    var cOpts = extractOpts(data);\n    config.vertexIntensity = data._intensity;\n    config.vertexIntensityBounds = [cOpts.min, cOpts.max];\n    config.colormap = parseColorScale(data);\n\n    // Update mesh\n    this.mesh.update(config);\n};\n\nproto.dispose = function() {\n    this.scene.glplot.remove(this.mesh);\n    this.mesh.dispose();\n};\n\nfunction createVolumeTrace(scene, data) {\n    var gl = scene.glplot.gl;\n    var mesh = createMesh({gl: gl});\n    var result = new VolumeTrace(scene, mesh, data.uid);\n\n    mesh._trace = result;\n    result.update(data);\n    scene.glplot.add(mesh);\n    return result;\n}\n\nmodule.exports = createVolumeTrace;\n\n},{\"../../components/colorscale\":605,\"../../lib/gl_format_color\":716,\"../../lib/str2rgbarray\":742,\"../../plots/gl3d/zip3\":818,\"../isosurface/convert\":1050,\"gl-mesh3d\":280}],1251:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar attributes = _dereq_('./attributes');\nvar supplyIsoDefaults = _dereq_('../isosurface/defaults').supplyIsoDefaults;\n\nvar MIN = 0.1; // Note: often we don't want the data cube to be disappeared\n\nfunction createWave(n, minOpacity) {\n    var arr = [];\n    var steps = 32; // Max: 256\n    for(var i = 0; i < steps; i++) {\n        var u = i / (steps - 1);\n        var v = minOpacity + (1 - minOpacity) * (1 - Math.pow(Math.sin(n * u * Math.PI), 2));\n        arr.push([\n            u,\n            Math.max(1, Math.min(0, v))\n        ]);\n    }\n    return arr;\n}\n\nmodule.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce);\n\n    var opacityscale = coerce('opacityscale');\n    if(opacityscale === 'max') {\n        traceOut.opacityscale = [[0, MIN], [1, 1]];\n    } else if(opacityscale === 'min') {\n        traceOut.opacityscale = [[0, 1], [1, MIN]];\n    } else if(opacityscale === 'extremes') {\n        traceOut.opacityscale = createWave(1, MIN);\n    } else if(!isValidScaleArray(opacityscale)) {\n        traceOut.opacityscale = undefined;\n    }\n};\n\nfunction isValidScaleArray(scl) {\n    var highestVal = 0;\n\n    if(!Array.isArray(scl) || scl.length < 2) return false;\n\n    if(!scl[0] || !scl[scl.length - 1]) return false;\n\n    if(+scl[0][0] !== 0 || +scl[scl.length - 1][0] !== 1) return false;\n\n    for(var i = 0; i < scl.length; i++) {\n        var si = scl[i];\n\n        if(si.length !== 2 || +si[0] < highestVal) {\n            return false;\n        }\n\n        highestVal = +si[0];\n    }\n\n    return true;\n}\n\n},{\"../../lib\":719,\"../isosurface/defaults\":1051,\"./attributes\":1249}],1252:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    supplyDefaults: _dereq_('./defaults'),\n    calc: _dereq_('../isosurface/calc'),\n    colorbar: {\n        min: 'cmin',\n        max: 'cmax'\n    },\n    plot: _dereq_('./convert'),\n\n    moduleType: 'trace',\n    name: 'volume',\n    basePlotModule: _dereq_('../../plots/gl3d'),\n    categories: ['gl3d'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/gl3d\":807,\"../isosurface/calc\":1049,\"./attributes\":1249,\"./convert\":1250,\"./defaults\":1251}],1253:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar barAttrs = _dereq_('../bar/attributes');\nvar lineAttrs = _dereq_('../scatter/attributes').line;\nvar plotAttrs = _dereq_('../../plots/attributes');\nvar hovertemplateAttrs = _dereq_('../../components/fx/hovertemplate_attributes');\nvar constants = _dereq_('./constants');\nvar extendFlat = _dereq_('../../lib/extend').extendFlat;\nvar Color = _dereq_('../../components/color');\n\nfunction directionAttrs(dirTxt) {\n    return {\n        marker: {\n            color: extendFlat({}, barAttrs.marker.color, {\n                arrayOk: false,\n                editType: 'style',\n                \n            }),\n            line: {\n                color: extendFlat({}, barAttrs.marker.line.color, {\n                    arrayOk: false,\n                    editType: 'style',\n                    \n                }),\n                width: extendFlat({}, barAttrs.marker.line.width, {\n                    arrayOk: false,\n                    editType: 'style',\n                    \n                }),\n                editType: 'style',\n            },\n            editType: 'style'\n        },\n        editType: 'style'\n    };\n}\n\nmodule.exports = {\n    measure: {\n        valType: 'data_array',\n        dflt: [],\n        \n        editType: 'calc',\n        \n    },\n\n    base: {\n        valType: 'number',\n        dflt: null,\n        arrayOk: false,\n        \n        editType: 'calc',\n        \n    },\n\n    x: barAttrs.x,\n    x0: barAttrs.x0,\n    dx: barAttrs.dx,\n    y: barAttrs.y,\n    y0: barAttrs.y0,\n    dy: barAttrs.dy,\n\n    hovertext: barAttrs.hovertext,\n    hovertemplate: hovertemplateAttrs({}, {\n        keys: constants.eventDataKeys\n    }),\n\n    hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {\n        flags: ['name', 'x', 'y', 'text', 'initial', 'delta', 'final']\n    }),\n\n    textinfo: {\n        valType: 'flaglist',\n        flags: ['label', 'text', 'initial', 'delta', 'final'],\n        extras: ['none'],\n        \n        editType: 'plot',\n        arrayOk: false,\n        \n    },\n\n    text: barAttrs.text,\n    textposition: barAttrs.textposition,\n    insidetextanchor: barAttrs.insidetextanchor,\n    textangle: barAttrs.textangle,\n    textfont: barAttrs.textfont,\n    insidetextfont: barAttrs.insidetextfont,\n    outsidetextfont: barAttrs.outsidetextfont,\n    constraintext: barAttrs.constraintext,\n\n    cliponaxis: barAttrs.cliponaxis,\n    orientation: barAttrs.orientation,\n\n    offset: barAttrs.offset,\n    width: barAttrs.width,\n\n    increasing: directionAttrs('increasing'),\n    decreasing: directionAttrs('decreasing'),\n    totals: directionAttrs('intermediate sums and total'),\n\n    connector: {\n        line: {\n            color: extendFlat({}, lineAttrs.color, {dflt: Color.defaultLine}),\n            width: extendFlat({}, lineAttrs.width, {\n                editType: 'plot', // i.e. to adjust bars is mode: 'between'. See https://github.com/plotly/plotly.js/issues/3787\n            }),\n            dash: lineAttrs.dash,\n            editType: 'plot'\n        },\n        mode: {\n            valType: 'enumerated',\n            values: ['spanning', 'between'],\n            dflt: 'between',\n            \n            editType: 'plot',\n            \n        },\n        visible: {\n            valType: 'boolean',\n            dflt: true,\n            \n            editType: 'plot',\n            \n        },\n        editType: 'plot'\n    },\n\n    offsetgroup: barAttrs.offsetgroup,\n    alignmentgroup: barAttrs.alignmentgroup\n};\n\n},{\"../../components/color\":593,\"../../components/fx/hovertemplate_attributes\":631,\"../../lib/extend\":710,\"../../plots/attributes\":764,\"../bar/attributes\":857,\"../scatter/attributes\":1112,\"./constants\":1255}],1254:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../../plots/cartesian/axes');\nvar mergeArray = _dereq_('../../lib').mergeArray;\nvar calcSelection = _dereq_('../scatter/calc_selection');\nvar BADNUM = _dereq_('../../constants/numerical').BADNUM;\n\nfunction isAbsolute(a) {\n    return (a === 'a' || a === 'absolute');\n}\n\nfunction isTotal(a) {\n    return (a === 't' || a === 'total');\n}\n\nmodule.exports = function calc(gd, trace) {\n    var xa = Axes.getFromId(gd, trace.xaxis || 'x');\n    var ya = Axes.getFromId(gd, trace.yaxis || 'y');\n    var size, pos;\n\n    if(trace.orientation === 'h') {\n        size = xa.makeCalcdata(trace, 'x');\n        pos = ya.makeCalcdata(trace, 'y');\n    } else {\n        size = ya.makeCalcdata(trace, 'y');\n        pos = xa.makeCalcdata(trace, 'x');\n    }\n\n    // create the \"calculated data\" to plot\n    var serieslen = Math.min(pos.length, size.length);\n    var cd = new Array(serieslen);\n\n    // set position and size (as well as for waterfall total size)\n    var previousSum = 0;\n    var newSize;\n    // trace-wide flags\n    var hasTotals = false;\n\n    for(var i = 0; i < serieslen; i++) {\n        var amount = size[i] || 0;\n\n        var connectToNext = false;\n        if(size[i] !== BADNUM || isTotal(trace.measure[i]) || isAbsolute(trace.measure[i])) {\n            if(i + 1 < serieslen && (size[i + 1] !== BADNUM || isTotal(trace.measure[i + 1]) || isAbsolute(trace.measure[i + 1]))) {\n                connectToNext = true;\n            }\n        }\n\n        var cdi = cd[i] = {\n            i: i,\n            p: pos[i],\n            s: amount,\n            rawS: amount,\n            cNext: connectToNext\n        };\n\n        if(isAbsolute(trace.measure[i])) {\n            previousSum = cdi.s;\n\n            cdi.isSum = true;\n            cdi.dir = 'totals';\n            cdi.s = previousSum;\n        } else if(isTotal(trace.measure[i])) {\n            cdi.isSum = true;\n            cdi.dir = 'totals';\n            cdi.s = previousSum;\n        } else {\n            // default: relative\n            cdi.isSum = false;\n            cdi.dir = cdi.rawS < 0 ? 'decreasing' : 'increasing';\n            newSize = cdi.s;\n            cdi.s = previousSum + newSize;\n            previousSum += newSize;\n        }\n\n        if(cdi.dir === 'totals') {\n            hasTotals = true;\n        }\n\n        if(trace.ids) {\n            cdi.id = String(trace.ids[i]);\n        }\n\n        cdi.v = (trace.base || 0) + previousSum;\n    }\n\n    if(cd.length) cd[0].hasTotals = hasTotals;\n\n    mergeArray(trace.text, cd, 'tx');\n    mergeArray(trace.hovertext, cd, 'htx');\n    calcSelection(cd, trace);\n\n    return cd;\n};\n\n},{\"../../constants/numerical\":695,\"../../lib\":719,\"../../plots/cartesian/axes\":767,\"../scatter/calc_selection\":1114}],1255:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    eventDataKeys: [\n        'initial',\n        'delta',\n        'final'\n    ]\n};\n\n},{}],1256:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar setGroupPositions = _dereq_('../bar/cross_trace_calc').setGroupPositions;\n\nmodule.exports = function crossTraceCalc(gd, plotinfo) {\n    var fullLayout = gd._fullLayout;\n    var fullData = gd._fullData;\n    var calcdata = gd.calcdata;\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n    var waterfalls = [];\n    var waterfallsVert = [];\n    var waterfallsHorz = [];\n    var cd, i;\n\n    for(i = 0; i < fullData.length; i++) {\n        var fullTrace = fullData[i];\n\n        if(\n            fullTrace.visible === true &&\n            fullTrace.xaxis === xa._id &&\n            fullTrace.yaxis === ya._id &&\n            fullTrace.type === 'waterfall'\n        ) {\n            cd = calcdata[i];\n\n            if(fullTrace.orientation === 'h') {\n                waterfallsHorz.push(cd);\n            } else {\n                waterfallsVert.push(cd);\n            }\n\n            waterfalls.push(cd);\n        }\n    }\n\n    var opts = {\n        mode: fullLayout.waterfallmode,\n        norm: fullLayout.waterfallnorm,\n        gap: fullLayout.waterfallgap,\n        groupgap: fullLayout.waterfallgroupgap\n    };\n\n    setGroupPositions(gd, xa, ya, waterfallsVert, opts);\n    setGroupPositions(gd, ya, xa, waterfallsHorz, opts);\n\n    for(i = 0; i < waterfalls.length; i++) {\n        cd = waterfalls[i];\n\n        for(var j = 0; j < cd.length; j++) {\n            var di = cd[j];\n\n            if(di.isSum === false) {\n                di.s0 += (j === 0) ? 0 : cd[j - 1].s;\n            }\n\n            if(j + 1 < cd.length) {\n                cd[j].nextP0 = cd[j + 1].p0;\n                cd[j].nextS0 = cd[j + 1].s0;\n            }\n        }\n    }\n};\n\n},{\"../bar/cross_trace_calc\":860}],1257:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\n\nvar handleGroupingDefaults = _dereq_('../bar/defaults').handleGroupingDefaults;\nvar handleText = _dereq_('../bar/defaults').handleText;\nvar handleXYDefaults = _dereq_('../scatter/xy_defaults');\nvar attributes = _dereq_('./attributes');\nvar Color = _dereq_('../../components/color');\nvar delta = _dereq_('../../constants/delta.js');\n\nvar INCREASING_COLOR = delta.INCREASING.COLOR;\nvar DECREASING_COLOR = delta.DECREASING.COLOR;\nvar TOTALS_COLOR = '#4499FF';\n\nfunction handleDirection(coerce, direction, defaultColor) {\n    coerce(direction + '.marker.color', defaultColor);\n    coerce(direction + '.marker.line.color', Color.defaultLine);\n    coerce(direction + '.marker.line.width');\n}\n\nfunction supplyDefaults(traceIn, traceOut, defaultColor, layout) {\n    function coerce(attr, dflt) {\n        return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);\n    }\n\n    var len = handleXYDefaults(traceIn, traceOut, layout, coerce);\n    if(!len) {\n        traceOut.visible = false;\n        return;\n    }\n\n    coerce('measure');\n\n    coerce('orientation', (traceOut.x && !traceOut.y) ? 'h' : 'v');\n    coerce('base');\n    coerce('offset');\n    coerce('width');\n\n    coerce('text');\n\n    coerce('hovertext');\n    coerce('hovertemplate');\n\n    var textposition = coerce('textposition');\n    handleText(traceIn, traceOut, layout, coerce, textposition, {\n        moduleHasSelected: false,\n        moduleHasUnselected: false,\n        moduleHasConstrain: true,\n        moduleHasCliponaxis: true,\n        moduleHasTextangle: true,\n        moduleHasInsideanchor: true\n    });\n\n\n    if(traceOut.textposition !== 'none') {\n        coerce('textinfo');\n    }\n\n    handleDirection(coerce, 'increasing', INCREASING_COLOR);\n    handleDirection(coerce, 'decreasing', DECREASING_COLOR);\n    handleDirection(coerce, 'totals', TOTALS_COLOR);\n\n    var connectorVisible = coerce('connector.visible');\n    if(connectorVisible) {\n        coerce('connector.mode');\n        var connectorLineWidth = coerce('connector.line.width');\n        if(connectorLineWidth) {\n            coerce('connector.line.color');\n            coerce('connector.line.dash');\n        }\n    }\n}\n\nfunction crossTraceDefaults(fullData, fullLayout) {\n    var traceIn, traceOut;\n\n    function coerce(attr) {\n        return Lib.coerce(traceOut._input, traceOut, attributes, attr);\n    }\n\n    if(fullLayout.waterfallmode === 'group') {\n        for(var i = 0; i < fullData.length; i++) {\n            traceOut = fullData[i];\n            traceIn = traceOut._input;\n\n            handleGroupingDefaults(traceIn, traceOut, fullLayout, coerce);\n        }\n    }\n}\n\nmodule.exports = {\n    supplyDefaults: supplyDefaults,\n    crossTraceDefaults: crossTraceDefaults\n};\n\n},{\"../../components/color\":593,\"../../constants/delta.js\":689,\"../../lib\":719,\"../bar/defaults\":861,\"../scatter/xy_defaults\":1137,\"./attributes\":1253}],1258:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = function eventData(out, pt /* , trace, cd, pointNumber */) {\n    // standard cartesian event data\n    out.x = 'xVal' in pt ? pt.xVal : pt.x;\n    out.y = 'yVal' in pt ? pt.yVal : pt.y;\n\n    // for funnel\n    if('initial' in pt) out.initial = pt.initial;\n    if('delta' in pt) out.delta = pt.delta;\n    if('final' in pt) out.final = pt.final;\n\n    if(pt.xa) out.xaxis = pt.xa;\n    if(pt.ya) out.yaxis = pt.ya;\n\n    return out;\n};\n\n},{}],1259:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar hoverLabelText = _dereq_('../../plots/cartesian/axes').hoverLabelText;\nvar opacity = _dereq_('../../components/color').opacity;\nvar hoverOnBars = _dereq_('../bar/hover').hoverOnBars;\nvar delta = _dereq_('../../constants/delta.js');\n\nvar DIRSYMBOL = {\n    increasing: delta.INCREASING.SYMBOL,\n    decreasing: delta.DECREASING.SYMBOL\n};\n\nmodule.exports = function hoverPoints(pointData, xval, yval, hovermode) {\n    var point = hoverOnBars(pointData, xval, yval, hovermode);\n    if(!point) return;\n\n    var cd = point.cd;\n    var trace = cd[0].trace;\n    var isHorizontal = (trace.orientation === 'h');\n\n    var vAxis = isHorizontal ? pointData.xa : pointData.ya;\n\n    function formatNumber(a) {\n        return hoverLabelText(vAxis, a);\n    }\n\n    // the closest data point\n    var index = point.index;\n    var di = cd[index];\n\n    var size = (di.isSum) ? di.b + di.s : di.rawS;\n\n    if(!di.isSum) {\n        point.initial = di.b + di.s - size;\n        point.delta = size;\n        point.final = point.initial + point.delta;\n\n        var v = formatNumber(Math.abs(point.delta));\n        point.deltaLabel = size < 0 ? '(' + v + ')' : v;\n        point.finalLabel = formatNumber(point.final);\n        point.initialLabel = formatNumber(point.initial);\n    }\n\n    var hoverinfo = di.hi || trace.hoverinfo;\n    var text = [];\n    if(hoverinfo && hoverinfo !== 'none' && hoverinfo !== 'skip') {\n        var isAll = (hoverinfo === 'all');\n        var parts = hoverinfo.split('+');\n\n        var hasFlag = function(flag) { return isAll || parts.indexOf(flag) !== -1; };\n\n        if(!di.isSum) {\n            if(hasFlag('final') &&\n                (isHorizontal ? !hasFlag('x') : !hasFlag('y')) // don't display redundant info.\n            ) {\n                text.push(point.finalLabel);\n            }\n            if(hasFlag('delta')) {\n                if(size < 0) {\n                    text.push(point.deltaLabel + ' ' + DIRSYMBOL.decreasing);\n                } else {\n                    text.push(point.deltaLabel + ' ' + DIRSYMBOL.increasing);\n                }\n            }\n            if(hasFlag('initial')) {\n                text.push('Initial: ' + point.initialLabel);\n            }\n        }\n    }\n\n    if(text.length) point.extraText = text.join('<br>');\n\n    point.color = getTraceColor(trace, di);\n\n    return [point];\n};\n\nfunction getTraceColor(trace, di) {\n    var cont = trace[di.dir].marker;\n    var mc = cont.color;\n    var mlc = cont.line.color;\n    var mlw = cont.line.width;\n    if(opacity(mc)) return mc;\n    else if(opacity(mlc) && mlw) return mlc;\n}\n\n},{\"../../components/color\":593,\"../../constants/delta.js\":689,\"../../plots/cartesian/axes\":767,\"../bar/hover\":863}],1260:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    attributes: _dereq_('./attributes'),\n    layoutAttributes: _dereq_('./layout_attributes'),\n    supplyDefaults: _dereq_('./defaults').supplyDefaults,\n    crossTraceDefaults: _dereq_('./defaults').crossTraceDefaults,\n    supplyLayoutDefaults: _dereq_('./layout_defaults'),\n    calc: _dereq_('./calc'),\n    crossTraceCalc: _dereq_('./cross_trace_calc'),\n    plot: _dereq_('./plot'),\n    style: _dereq_('./style').style,\n    hoverPoints: _dereq_('./hover'),\n    eventData: _dereq_('./event_data'),\n\n    selectPoints: _dereq_('../bar/select'),\n\n    moduleType: 'trace',\n    name: 'waterfall',\n    basePlotModule: _dereq_('../../plots/cartesian'),\n    categories: ['bar-like', 'cartesian', 'svg', 'oriented', 'showLegend', 'zoomScale'],\n    meta: {\n        \n    }\n};\n\n},{\"../../plots/cartesian\":778,\"../bar/select\":868,\"./attributes\":1253,\"./calc\":1254,\"./cross_trace_calc\":1256,\"./defaults\":1257,\"./event_data\":1258,\"./hover\":1259,\"./layout_attributes\":1261,\"./layout_defaults\":1262,\"./plot\":1263,\"./style\":1264}],1261:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nmodule.exports = {\n    waterfallmode: {\n        valType: 'enumerated',\n        values: ['group', 'overlay'],\n        dflt: 'group',\n        \n        editType: 'calc',\n        \n    },\n    waterfallgap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        \n        editType: 'calc',\n        \n    },\n    waterfallgroupgap: {\n        valType: 'number',\n        min: 0,\n        max: 1,\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    }\n};\n\n},{}],1262:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../../lib');\nvar layoutAttributes = _dereq_('./layout_attributes');\n\nmodule.exports = function(layoutIn, layoutOut, fullData) {\n    var hasTraceType = false;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);\n    }\n\n    for(var i = 0; i < fullData.length; i++) {\n        var trace = fullData[i];\n\n        if(trace.visible && trace.type === 'waterfall') {\n            hasTraceType = true;\n            break;\n        }\n    }\n\n    if(hasTraceType) {\n        coerce('waterfallmode');\n        coerce('waterfallgap', 0.2);\n        coerce('waterfallgroupgap');\n    }\n};\n\n},{\"../../lib\":719,\"./layout_attributes\":1261}],1263:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\nvar Lib = _dereq_('../../lib');\nvar Drawing = _dereq_('../../components/drawing');\nvar barPlot = _dereq_('../bar/plot').plot;\n\nmodule.exports = function plot(gd, plotinfo, cdModule, traceLayer) {\n    var fullLayout = gd._fullLayout;\n\n    barPlot(gd, plotinfo, cdModule, traceLayer, {\n        mode: fullLayout.waterfallmode,\n        norm: fullLayout.waterfallmode,\n        gap: fullLayout.waterfallgap,\n        groupgap: fullLayout.waterfallgroupgap\n    });\n\n    plotConnectors(gd, plotinfo, cdModule, traceLayer);\n};\n\nfunction plotConnectors(gd, plotinfo, cdModule, traceLayer) {\n    var xa = plotinfo.xaxis;\n    var ya = plotinfo.yaxis;\n\n    Lib.makeTraceGroups(traceLayer, cdModule, 'trace bars').each(function(cd) {\n        var plotGroup = d3.select(this);\n        var trace = cd[0].trace;\n\n        var group = Lib.ensureSingle(plotGroup, 'g', 'lines');\n\n        if(!trace.connector || !trace.connector.visible) {\n            group.remove();\n            return;\n        }\n\n        var isHorizontal = (trace.orientation === 'h');\n        var mode = trace.connector.mode;\n\n        var connectors = group.selectAll('g.line').data(Lib.identity);\n\n        connectors.enter().append('g')\n            .classed('line', true);\n\n        connectors.exit().remove();\n\n        var len = connectors.size();\n\n        connectors.each(function(di, i) {\n            // don't draw lines between nulls\n            if(i !== len - 1 && !di.cNext) return;\n\n            var xy = getXY(di, xa, ya, isHorizontal);\n            var x = xy[0];\n            var y = xy[1];\n\n            var shape = '';\n\n            if(mode === 'spanning') {\n                if(!di.isSum && i > 0) {\n                    if(isHorizontal) {\n                        shape += 'M' + x[0] + ',' + y[1] + 'V' + y[0];\n                    } else {\n                        shape += 'M' + x[1] + ',' + y[0] + 'H' + x[0];\n                    }\n                }\n            }\n\n            if(mode !== 'between') {\n                if(di.isSum || i < len - 1) {\n                    if(isHorizontal) {\n                        shape += 'M' + x[1] + ',' + y[0] + 'V' + y[1];\n                    } else {\n                        shape += 'M' + x[0] + ',' + y[1] + 'H' + x[1];\n                    }\n                }\n            }\n\n            if(x[2] !== undefined && y[2] !== undefined) {\n                if(isHorizontal) {\n                    shape += 'M' + x[1] + ',' + y[1] + 'V' + y[2];\n                } else {\n                    shape += 'M' + x[1] + ',' + y[1] + 'H' + x[2];\n                }\n            }\n\n            if(shape === '') shape = 'M0,0Z';\n\n            Lib.ensureSingle(d3.select(this), 'path')\n                .attr('d', shape)\n                .call(Drawing.setClipUrl, plotinfo.layerClipId, gd);\n        });\n    });\n}\n\nfunction getXY(di, xa, ya, isHorizontal) {\n    var s = [];\n    var p = [];\n\n    var sAxis = isHorizontal ? xa : ya;\n    var pAxis = isHorizontal ? ya : xa;\n\n    s[0] = sAxis.c2p(di.s0, true);\n    p[0] = pAxis.c2p(di.p0, true);\n\n    s[1] = sAxis.c2p(di.s1, true);\n    p[1] = pAxis.c2p(di.p1, true);\n\n    s[2] = sAxis.c2p(di.nextS0, true);\n    p[2] = pAxis.c2p(di.nextP0, true);\n\n    return isHorizontal ? [s, p] : [p, s];\n}\n\n},{\"../../components/drawing\":614,\"../../lib\":719,\"../bar/plot\":867,\"d3\":163}],1264:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar d3 = _dereq_('d3');\n\nvar Drawing = _dereq_('../../components/drawing');\nvar Color = _dereq_('../../components/color');\nvar DESELECTDIM = _dereq_('../../constants/interactions').DESELECTDIM;\n\nvar styleTextPoints = _dereq_('../bar/style').styleTextPoints;\n\nfunction style(gd, cd, sel) {\n    var s = sel ? sel : d3.select(gd).selectAll('g.waterfalllayer').selectAll('g.trace');\n\n    s.style('opacity', function(d) { return d[0].trace.opacity; });\n\n    s.each(function(d) {\n        var gTrace = d3.select(this);\n        var trace = d[0].trace;\n\n        gTrace.selectAll('.point > path').each(function(di) {\n            if(!di.isBlank) {\n                var cont = trace[di.dir].marker;\n\n                d3.select(this)\n                    .call(Color.fill, cont.color)\n                    .call(Color.stroke, cont.line.color)\n                    .call(Drawing.dashLine, cont.line.dash, cont.line.width)\n                    .style('opacity', trace.selectedpoints && !di.selected ? DESELECTDIM : 1);\n            }\n        });\n\n        styleTextPoints(gTrace, trace, gd);\n\n        gTrace.selectAll('.lines').each(function() {\n            var cont = trace.connector.line;\n\n            Drawing.lineGroupStyle(\n                d3.select(this).selectAll('path'),\n                cont.width,\n                cont.color,\n                cont.dash\n            );\n        });\n    });\n}\n\nmodule.exports = {\n    style: style\n};\n\n},{\"../../components/color\":593,\"../../components/drawing\":614,\"../../constants/interactions\":694,\"../bar/style\":870,\"d3\":163}],1265:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Axes = _dereq_('../plots/cartesian/axes');\nvar Lib = _dereq_('../lib');\nvar PlotSchema = _dereq_('../plot_api/plot_schema');\nvar pointsAccessorFunction = _dereq_('./helpers').pointsAccessorFunction;\nvar BADNUM = _dereq_('../constants/numerical').BADNUM;\n\nexports.moduleType = 'transform';\n\nexports.name = 'aggregate';\n\nvar attrs = exports.attributes = {\n    enabled: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        \n    },\n    groups: {\n        // TODO: groupby should support string or array grouping this way too\n        // currently groupby only allows a grouping array\n        valType: 'string',\n        strict: true,\n        noBlank: true,\n        arrayOk: true,\n        dflt: 'x',\n        \n        editType: 'calc',\n        \n    },\n    aggregations: {\n        _isLinkedToArray: 'aggregation',\n        target: {\n            valType: 'string',\n            \n            editType: 'calc',\n            \n        },\n        func: {\n            valType: 'enumerated',\n            values: ['count', 'sum', 'avg', 'median', 'mode', 'rms', 'stddev', 'min', 'max', 'first', 'last', 'change', 'range'],\n            dflt: 'first',\n            \n            editType: 'calc',\n            \n        },\n        funcmode: {\n            valType: 'enumerated',\n            values: ['sample', 'population'],\n            dflt: 'sample',\n            \n            editType: 'calc',\n            \n        },\n        enabled: {\n            valType: 'boolean',\n            dflt: true,\n            \n            editType: 'calc',\n            \n        },\n        editType: 'calc'\n    },\n    editType: 'calc'\n};\n\nvar aggAttrs = attrs.aggregations;\n\n/**\n * Supply transform attributes defaults\n *\n * @param {object} transformIn\n *  object linked to trace.transforms[i] with 'func' set to exports.name\n * @param {object} traceOut\n *  the _fullData trace this transform applies to\n * @param {object} layout\n *  the plot's (not-so-full) layout\n * @param {object} traceIn\n *  the input data trace this transform applies to\n *\n * @return {object} transformOut\n *  copy of transformIn that contains attribute defaults\n */\nexports.supplyDefaults = function(transformIn, traceOut) {\n    var transformOut = {};\n    var i;\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(transformIn, transformOut, attrs, attr, dflt);\n    }\n\n    var enabled = coerce('enabled');\n\n    if(!enabled) return transformOut;\n\n    /*\n     * Normally _arrayAttrs is calculated during doCalc, but that comes later.\n     * Anyway this can change due to *count* aggregations (see below) so it's not\n     * necessarily the same set.\n     *\n     * For performance we turn it into an object of truthy values\n     * we'll use 1 for arrays we haven't aggregated yet, 0 for finished arrays,\n     * as distinct from undefined which means this array isn't present in the input\n     * missing arrays can still be aggregate outputs for *count* aggregations.\n     */\n    var arrayAttrArray = PlotSchema.findArrayAttributes(traceOut);\n    var arrayAttrs = {};\n    for(i = 0; i < arrayAttrArray.length; i++) arrayAttrs[arrayAttrArray[i]] = 1;\n\n    var groups = coerce('groups');\n\n    if(!Array.isArray(groups)) {\n        if(!arrayAttrs[groups]) {\n            transformOut.enabled = false;\n            return transformOut;\n        }\n        arrayAttrs[groups] = 0;\n    }\n\n    var aggregationsIn = transformIn.aggregations || [];\n    var aggregationsOut = transformOut.aggregations = new Array(aggregationsIn.length);\n    var aggregationOut;\n\n    function coercei(attr, dflt) {\n        return Lib.coerce(aggregationsIn[i], aggregationOut, aggAttrs, attr, dflt);\n    }\n\n    for(i = 0; i < aggregationsIn.length; i++) {\n        aggregationOut = {_index: i};\n        var target = coercei('target');\n        var func = coercei('func');\n        var enabledi = coercei('enabled');\n\n        // add this aggregation to the output only if it's the first instance\n        // of a valid target attribute - or an unused target attribute with \"count\"\n        if(enabledi && target && (arrayAttrs[target] || (func === 'count' && arrayAttrs[target] === undefined))) {\n            if(func === 'stddev') coercei('funcmode');\n\n            arrayAttrs[target] = 0;\n            aggregationsOut[i] = aggregationOut;\n        } else aggregationsOut[i] = {enabled: false, _index: i};\n    }\n\n    // any array attributes we haven't yet covered, fill them with the default aggregation\n    for(i = 0; i < arrayAttrArray.length; i++) {\n        if(arrayAttrs[arrayAttrArray[i]]) {\n            aggregationsOut.push({\n                target: arrayAttrArray[i],\n                func: aggAttrs.func.dflt,\n                enabled: true,\n                _index: -1\n            });\n        }\n    }\n\n    return transformOut;\n};\n\n\nexports.calcTransform = function(gd, trace, opts) {\n    if(!opts.enabled) return;\n\n    var groups = opts.groups;\n\n    var groupArray = Lib.getTargetArray(trace, {target: groups});\n    if(!groupArray) return;\n\n    var i, vi, groupIndex, newGrouping;\n\n    var groupIndices = {};\n    var indexToPoints = {};\n    var groupings = [];\n\n    var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);\n\n    var len = groupArray.length;\n    if(trace._length) len = Math.min(len, trace._length);\n\n    for(i = 0; i < len; i++) {\n        vi = groupArray[i];\n        groupIndex = groupIndices[vi];\n        if(groupIndex === undefined) {\n            groupIndices[vi] = groupings.length;\n            newGrouping = [i];\n            groupings.push(newGrouping);\n            indexToPoints[groupIndices[vi]] = originalPointsAccessor(i);\n        } else {\n            groupings[groupIndex].push(i);\n            indexToPoints[groupIndices[vi]] = (indexToPoints[groupIndices[vi]] || []).concat(originalPointsAccessor(i));\n        }\n    }\n\n    opts._indexToPoints = indexToPoints;\n\n    var aggregations = opts.aggregations;\n\n    for(i = 0; i < aggregations.length; i++) {\n        aggregateOneArray(gd, trace, groupings, aggregations[i]);\n    }\n\n    if(typeof groups === 'string') {\n        aggregateOneArray(gd, trace, groupings, {\n            target: groups,\n            func: 'first',\n            enabled: true\n        });\n    }\n\n    trace._length = groupings.length;\n};\n\nfunction aggregateOneArray(gd, trace, groupings, aggregation) {\n    if(!aggregation.enabled) return;\n\n    var attr = aggregation.target;\n    var targetNP = Lib.nestedProperty(trace, attr);\n    var arrayIn = targetNP.get();\n    var conversions = Axes.getDataConversions(gd, trace, attr, arrayIn);\n    var func = getAggregateFunction(aggregation, conversions);\n\n    var arrayOut = new Array(groupings.length);\n    for(var i = 0; i < groupings.length; i++) {\n        arrayOut[i] = func(arrayIn, groupings[i]);\n    }\n    targetNP.set(arrayOut);\n\n    if(aggregation.func === 'count') {\n        // count does not depend on an input array, so it's likely not part of _arrayAttrs yet\n        // but after this transform it most definitely *is* an array attribute.\n        Lib.pushUnique(trace._arrayAttrs, attr);\n    }\n}\n\nfunction getAggregateFunction(opts, conversions) {\n    var func = opts.func;\n    var d2c = conversions.d2c;\n    var c2d = conversions.c2d;\n\n    switch(func) {\n        // count, first, and last don't depend on anything about the data\n        // point back to pure functions for performance\n        case 'count':\n            return count;\n        case 'first':\n            return first;\n        case 'last':\n            return last;\n\n        case 'sum':\n            // This will produce output in all cases even though it's nonsensical\n            // for date or category data.\n            return function(array, indices) {\n                var total = 0;\n                for(var i = 0; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) total += vi;\n                }\n                return c2d(total);\n            };\n\n        case 'avg':\n            // Generally meaningless for category data but it still does something.\n            return function(array, indices) {\n                var total = 0;\n                var cnt = 0;\n                for(var i = 0; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) {\n                        total += vi;\n                        cnt++;\n                    }\n                }\n                return cnt ? c2d(total / cnt) : BADNUM;\n            };\n\n        case 'min':\n            return function(array, indices) {\n                var out = Infinity;\n                for(var i = 0; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) out = Math.min(out, vi);\n                }\n                return (out === Infinity) ? BADNUM : c2d(out);\n            };\n\n        case 'max':\n            return function(array, indices) {\n                var out = -Infinity;\n                for(var i = 0; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) out = Math.max(out, vi);\n                }\n                return (out === -Infinity) ? BADNUM : c2d(out);\n            };\n\n        case 'range':\n            return function(array, indices) {\n                var min = Infinity;\n                var max = -Infinity;\n                for(var i = 0; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) {\n                        min = Math.min(min, vi);\n                        max = Math.max(max, vi);\n                    }\n                }\n                return (max === -Infinity || min === Infinity) ? BADNUM : c2d(max - min);\n            };\n\n        case 'change':\n            return function(array, indices) {\n                var first = d2c(array[indices[0]]);\n                var last = d2c(array[indices[indices.length - 1]]);\n                return (first === BADNUM || last === BADNUM) ? BADNUM : c2d(last - first);\n            };\n\n        case 'median':\n            return function(array, indices) {\n                var sortCalc = [];\n                for(var i = 0; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) sortCalc.push(vi);\n                }\n                if(!sortCalc.length) return BADNUM;\n                sortCalc.sort();\n                var mid = (sortCalc.length - 1) / 2;\n                return c2d((sortCalc[Math.floor(mid)] + sortCalc[Math.ceil(mid)]) / 2);\n            };\n\n        case 'mode':\n            return function(array, indices) {\n                var counts = {};\n                var maxCnt = 0;\n                var out = BADNUM;\n                for(var i = 0; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) {\n                        var counti = counts[vi] = (counts[vi] || 0) + 1;\n                        if(counti > maxCnt) {\n                            maxCnt = counti;\n                            out = vi;\n                        }\n                    }\n                }\n                return maxCnt ? c2d(out) : BADNUM;\n            };\n\n        case 'rms':\n            return function(array, indices) {\n                var total = 0;\n                var cnt = 0;\n                for(var i = 0; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) {\n                        total += vi * vi;\n                        cnt++;\n                    }\n                }\n                return cnt ? c2d(Math.sqrt(total / cnt)) : BADNUM;\n            };\n\n        case 'stddev':\n            return function(array, indices) {\n                // balance numerical stability with performance:\n                // so that we call d2c once per element but don't need to\n                // store them, reference all to the first element\n                var total = 0;\n                var total2 = 0;\n                var cnt = 1;\n                var v0 = BADNUM;\n                var i;\n                for(i = 0; i < indices.length && v0 === BADNUM; i++) {\n                    v0 = d2c(array[indices[i]]);\n                }\n                if(v0 === BADNUM) return BADNUM;\n\n                for(; i < indices.length; i++) {\n                    var vi = d2c(array[indices[i]]);\n                    if(vi !== BADNUM) {\n                        var dv = vi - v0;\n                        total += dv;\n                        total2 += dv * dv;\n                        cnt++;\n                    }\n                }\n\n                // This is population std dev, if we want sample std dev\n                // we would need (...) / (cnt - 1)\n                // Also note there's no c2d here - that means for dates the result\n                // is a number of milliseconds, and for categories it's a number\n                // of category differences, which is not generically meaningful but\n                // as in other cases we don't forbid it.\n                var norm = (opts.funcmode === 'sample') ? (cnt - 1) : cnt;\n                // this is debatable: should a count of 1 return sample stddev of\n                // 0 or undefined?\n                if(!norm) return 0;\n                return Math.sqrt((total2 - (total * total / cnt)) / norm);\n            };\n    }\n}\n\nfunction count(array, indices) {\n    return indices.length;\n}\n\nfunction first(array, indices) {\n    return array[indices[0]];\n}\n\nfunction last(array, indices) {\n    return array[indices[indices.length - 1]];\n}\n\n},{\"../constants/numerical\":695,\"../lib\":719,\"../plot_api/plot_schema\":756,\"../plots/cartesian/axes\":767,\"./helpers\":1268}],1266:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar Registry = _dereq_('../registry');\nvar Axes = _dereq_('../plots/cartesian/axes');\nvar pointsAccessorFunction = _dereq_('./helpers').pointsAccessorFunction;\n\nvar filterOps = _dereq_('../constants/filter_ops');\nvar COMPARISON_OPS = filterOps.COMPARISON_OPS;\nvar INTERVAL_OPS = filterOps.INTERVAL_OPS;\nvar SET_OPS = filterOps.SET_OPS;\n\nexports.moduleType = 'transform';\n\nexports.name = 'filter';\n\nexports.attributes = {\n    enabled: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        \n    },\n    target: {\n        valType: 'string',\n        strict: true,\n        noBlank: true,\n        arrayOk: true,\n        dflt: 'x',\n        \n        editType: 'calc',\n        \n    },\n    operation: {\n        valType: 'enumerated',\n        values: []\n            .concat(COMPARISON_OPS)\n            .concat(INTERVAL_OPS)\n            .concat(SET_OPS),\n        dflt: '=',\n        \n        editType: 'calc',\n        \n    },\n    value: {\n        valType: 'any',\n        dflt: 0,\n        \n        editType: 'calc',\n        \n    },\n    preservegaps: {\n        valType: 'boolean',\n        dflt: false,\n        \n        editType: 'calc',\n        \n    },\n    editType: 'calc'\n};\n\nexports.supplyDefaults = function(transformIn) {\n    var transformOut = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(transformIn, transformOut, exports.attributes, attr, dflt);\n    }\n\n    var enabled = coerce('enabled');\n\n    if(enabled) {\n        var target = coerce('target');\n\n        if(Lib.isArrayOrTypedArray(target) && target.length === 0) {\n            transformOut.enabled = false;\n            return transformOut;\n        }\n\n        coerce('preservegaps');\n        coerce('operation');\n        coerce('value');\n\n        var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');\n        handleCalendarDefaults(transformIn, transformOut, 'valuecalendar', null);\n        handleCalendarDefaults(transformIn, transformOut, 'targetcalendar', null);\n    }\n\n    return transformOut;\n};\n\nexports.calcTransform = function(gd, trace, opts) {\n    if(!opts.enabled) return;\n\n    var targetArray = Lib.getTargetArray(trace, opts);\n    if(!targetArray) return;\n\n    var target = opts.target;\n\n    var len = targetArray.length;\n    if(trace._length) len = Math.min(len, trace._length);\n\n    var targetCalendar = opts.targetcalendar;\n    var arrayAttrs = trace._arrayAttrs;\n    var preservegaps = opts.preservegaps;\n\n    // even if you provide targetcalendar, if target is a string and there\n    // is a calendar attribute matching target it will get used instead.\n    if(typeof target === 'string') {\n        var attrTargetCalendar = Lib.nestedProperty(trace, target + 'calendar').get();\n        if(attrTargetCalendar) targetCalendar = attrTargetCalendar;\n    }\n\n    var d2c = Axes.getDataToCoordFunc(gd, trace, target, targetArray);\n    var filterFunc = getFilterFunc(opts, d2c, targetCalendar);\n    var originalArrays = {};\n    var indexToPoints = {};\n    var index = 0;\n\n    function forAllAttrs(fn, index) {\n        for(var j = 0; j < arrayAttrs.length; j++) {\n            var np = Lib.nestedProperty(trace, arrayAttrs[j]);\n            fn(np, index);\n        }\n    }\n\n    var initFn;\n    var fillFn;\n    if(preservegaps) {\n        initFn = function(np) {\n            originalArrays[np.astr] = Lib.extendDeep([], np.get());\n            np.set(new Array(len));\n        };\n        fillFn = function(np, index) {\n            var val = originalArrays[np.astr][index];\n            np.get()[index] = val;\n        };\n    } else {\n        initFn = function(np) {\n            originalArrays[np.astr] = Lib.extendDeep([], np.get());\n            np.set([]);\n        };\n        fillFn = function(np, index) {\n            var val = originalArrays[np.astr][index];\n            np.get().push(val);\n        };\n    }\n\n    // copy all original array attribute values, and clear arrays in trace\n    forAllAttrs(initFn);\n\n    var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);\n\n    // loop through filter array, fill trace arrays if passed\n    for(var i = 0; i < len; i++) {\n        var passed = filterFunc(targetArray[i]);\n        if(passed) {\n            forAllAttrs(fillFn, i);\n            indexToPoints[index++] = originalPointsAccessor(i);\n        } else if(preservegaps) index++;\n    }\n\n    opts._indexToPoints = indexToPoints;\n    trace._length = index;\n};\n\nfunction getFilterFunc(opts, d2c, targetCalendar) {\n    var operation = opts.operation;\n    var value = opts.value;\n    var hasArrayValue = Array.isArray(value);\n\n    function isOperationIn(array) {\n        return array.indexOf(operation) !== -1;\n    }\n\n    var d2cValue = function(v) { return d2c(v, 0, opts.valuecalendar); };\n    var d2cTarget = function(v) { return d2c(v, 0, targetCalendar); };\n\n    var coercedValue;\n\n    if(isOperationIn(COMPARISON_OPS)) {\n        coercedValue = hasArrayValue ? d2cValue(value[0]) : d2cValue(value);\n    } else if(isOperationIn(INTERVAL_OPS)) {\n        coercedValue = hasArrayValue ?\n            [d2cValue(value[0]), d2cValue(value[1])] :\n            [d2cValue(value), d2cValue(value)];\n    } else if(isOperationIn(SET_OPS)) {\n        coercedValue = hasArrayValue ? value.map(d2cValue) : [d2cValue(value)];\n    }\n\n    switch(operation) {\n        case '=':\n            return function(v) { return d2cTarget(v) === coercedValue; };\n\n        case '!=':\n            return function(v) { return d2cTarget(v) !== coercedValue; };\n\n        case '<':\n            return function(v) { return d2cTarget(v) < coercedValue; };\n\n        case '<=':\n            return function(v) { return d2cTarget(v) <= coercedValue; };\n\n        case '>':\n            return function(v) { return d2cTarget(v) > coercedValue; };\n\n        case '>=':\n            return function(v) { return d2cTarget(v) >= coercedValue; };\n\n        case '[]':\n            return function(v) {\n                var cv = d2cTarget(v);\n                return cv >= coercedValue[0] && cv <= coercedValue[1];\n            };\n\n        case '()':\n            return function(v) {\n                var cv = d2cTarget(v);\n                return cv > coercedValue[0] && cv < coercedValue[1];\n            };\n\n        case '[)':\n            return function(v) {\n                var cv = d2cTarget(v);\n                return cv >= coercedValue[0] && cv < coercedValue[1];\n            };\n\n        case '(]':\n            return function(v) {\n                var cv = d2cTarget(v);\n                return cv > coercedValue[0] && cv <= coercedValue[1];\n            };\n\n        case '][':\n            return function(v) {\n                var cv = d2cTarget(v);\n                return cv <= coercedValue[0] || cv >= coercedValue[1];\n            };\n\n        case ')(':\n            return function(v) {\n                var cv = d2cTarget(v);\n                return cv < coercedValue[0] || cv > coercedValue[1];\n            };\n\n        case '](':\n            return function(v) {\n                var cv = d2cTarget(v);\n                return cv <= coercedValue[0] || cv > coercedValue[1];\n            };\n\n        case ')[':\n            return function(v) {\n                var cv = d2cTarget(v);\n                return cv < coercedValue[0] || cv >= coercedValue[1];\n            };\n\n        case '{}':\n            return function(v) {\n                return coercedValue.indexOf(d2cTarget(v)) !== -1;\n            };\n\n        case '}{':\n            return function(v) {\n                return coercedValue.indexOf(d2cTarget(v)) === -1;\n            };\n    }\n}\n\n},{\"../constants/filter_ops\":691,\"../lib\":719,\"../plots/cartesian/axes\":767,\"../registry\":847,\"./helpers\":1268}],1267:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar PlotSchema = _dereq_('../plot_api/plot_schema');\nvar Plots = _dereq_('../plots/plots');\nvar pointsAccessorFunction = _dereq_('./helpers').pointsAccessorFunction;\n\nexports.moduleType = 'transform';\n\nexports.name = 'groupby';\n\nexports.attributes = {\n    enabled: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        \n    },\n    groups: {\n        valType: 'data_array',\n        dflt: [],\n        \n        editType: 'calc',\n        \n    },\n    nameformat: {\n        valType: 'string',\n        \n        editType: 'calc',\n        \n    },\n    styles: {\n        _isLinkedToArray: 'style',\n        target: {\n            valType: 'string',\n            \n            editType: 'calc',\n            \n        },\n        value: {\n            valType: 'any',\n            \n            dflt: {},\n            editType: 'calc',\n            \n            _compareAsJSON: true\n        },\n        editType: 'calc'\n    },\n    editType: 'calc'\n};\n\n/**\n * Supply transform attributes defaults\n *\n * @param {object} transformIn\n *  object linked to trace.transforms[i] with 'type' set to exports.name\n * @param {object} traceOut\n *  the _fullData trace this transform applies to\n * @param {object} layout\n *  the plot's (not-so-full) layout\n * @param {object} traceIn\n *  the input data trace this transform applies to\n *\n * @return {object} transformOut\n *  copy of transformIn that contains attribute defaults\n */\nexports.supplyDefaults = function(transformIn, traceOut, layout) {\n    var i;\n    var transformOut = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(transformIn, transformOut, exports.attributes, attr, dflt);\n    }\n\n    var enabled = coerce('enabled');\n\n    if(!enabled) return transformOut;\n\n    coerce('groups');\n    coerce('nameformat', layout._dataLength > 1 ? '%{group} (%{trace})' : '%{group}');\n\n    var styleIn = transformIn.styles;\n    var styleOut = transformOut.styles = [];\n\n    if(styleIn) {\n        for(i = 0; i < styleIn.length; i++) {\n            var thisStyle = styleOut[i] = {};\n            Lib.coerce(styleIn[i], styleOut[i], exports.attributes.styles, 'target');\n            var value = Lib.coerce(styleIn[i], styleOut[i], exports.attributes.styles, 'value');\n\n            // so that you can edit value in place and have Plotly.react notice it, or\n            // rebuild it every time and have Plotly.react NOT think it changed:\n            // use _compareAsJSON to say we should diff the _JSON_value\n            if(Lib.isPlainObject(value)) thisStyle.value = Lib.extendDeep({}, value);\n            else if(value) delete thisStyle.value;\n        }\n    }\n\n    return transformOut;\n};\n\n\n/**\n * Apply transform !!!\n *\n * @param {array} data\n *  array of transformed traces (is [fullTrace] upon first transform)\n *\n * @param {object} state\n *  state object which includes:\n *      - transform {object} full transform attributes\n *      - fullTrace {object} full trace object which is being transformed\n *      - fullData {array} full pre-transform(s) data array\n *      - layout {object} the plot's (not-so-full) layout\n *\n * @return {object} newData\n *  array of transformed traces\n */\nexports.transform = function(data, state) {\n    var newTraces, i, j;\n    var newData = [];\n\n    for(i = 0; i < data.length; i++) {\n        newTraces = transformOne(data[i], state);\n\n        for(j = 0; j < newTraces.length; j++) {\n            newData.push(newTraces[j]);\n        }\n    }\n\n    return newData;\n};\n\nfunction transformOne(trace, state) {\n    var i, j, k, attr, srcArray, groupName, newTrace, transforms, arrayLookup;\n    var groupNameObj;\n\n    var opts = state.transform;\n    var transformIndex = state.transformIndex;\n    var groups = trace.transforms[transformIndex].groups;\n    var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);\n\n    if(!(Array.isArray(groups)) || groups.length === 0) {\n        return [trace];\n    }\n\n    var groupNames = Lib.filterUnique(groups);\n    var newData = new Array(groupNames.length);\n    var len = groups.length;\n\n    var arrayAttrs = PlotSchema.findArrayAttributes(trace);\n\n    var styles = opts.styles || [];\n    var styleLookup = {};\n    for(i = 0; i < styles.length; i++) {\n        styleLookup[styles[i].target] = styles[i].value;\n    }\n\n    if(opts.styles) {\n        groupNameObj = Lib.keyedContainer(opts, 'styles', 'target', 'value.name');\n    }\n\n    // An index to map group name --> expanded trace index\n    var indexLookup = {};\n    var indexCnts = {};\n\n    for(i = 0; i < groupNames.length; i++) {\n        groupName = groupNames[i];\n        indexLookup[groupName] = i;\n        indexCnts[groupName] = 0;\n\n        // Start with a deep extend that just copies array references.\n        newTrace = newData[i] = Lib.extendDeepNoArrays({}, trace);\n        newTrace._group = groupName;\n        newTrace.transforms[transformIndex]._indexToPoints = {};\n\n        var suppliedName = null;\n        if(groupNameObj) {\n            suppliedName = groupNameObj.get(groupName);\n        }\n\n        if(suppliedName || suppliedName === '') {\n            newTrace.name = suppliedName;\n        } else {\n            newTrace.name = Lib.templateString(opts.nameformat, {\n                trace: trace.name,\n                group: groupName\n            });\n        }\n\n        // In order for groups to apply correctly to other transform data (e.g.\n        // a filter transform), we have to break the connection and clone the\n        // transforms so that each group writes grouped values into a different\n        // destination. This function does not break the array reference\n        // connection between the split transforms it creates. That's handled in\n        // initialize, which creates a new empty array for each arrayAttr.\n        transforms = newTrace.transforms;\n        newTrace.transforms = [];\n        for(j = 0; j < transforms.length; j++) {\n            newTrace.transforms[j] = Lib.extendDeepNoArrays({}, transforms[j]);\n        }\n\n        // Initialize empty arrays for the arrayAttrs, to be split in the next step\n        for(j = 0; j < arrayAttrs.length; j++) {\n            Lib.nestedProperty(newTrace, arrayAttrs[j]).set([]);\n        }\n    }\n\n    // For each array attribute including those nested inside this and other\n    // transforms (small note that we technically only need to do this for\n    // transforms that have not yet been applied):\n    for(k = 0; k < arrayAttrs.length; k++) {\n        attr = arrayAttrs[k];\n\n        // Cache all the arrays to which we'll push:\n        for(j = 0, arrayLookup = []; j < groupNames.length; j++) {\n            arrayLookup[j] = Lib.nestedProperty(newData[j], attr).get();\n        }\n\n        // Get the input data:\n        srcArray = Lib.nestedProperty(trace, attr).get();\n\n        // Send each data point to the appropriate expanded trace:\n        for(j = 0; j < len; j++) {\n            // Map group data --> trace index --> array and push data onto it\n            arrayLookup[indexLookup[groups[j]]].push(srcArray[j]);\n        }\n    }\n\n    for(j = 0; j < len; j++) {\n        newTrace = newData[indexLookup[groups[j]]];\n\n        var indexToPoints = newTrace.transforms[transformIndex]._indexToPoints;\n        indexToPoints[indexCnts[groups[j]]] = originalPointsAccessor(j);\n        indexCnts[groups[j]]++;\n    }\n\n    for(i = 0; i < groupNames.length; i++) {\n        groupName = groupNames[i];\n        newTrace = newData[i];\n\n        Plots.clearExpandedTraceDefaultColors(newTrace);\n\n        // there's no need to coerce styleLookup[groupName] here\n        // as another round of supplyDefaults is done on the transformed traces\n        newTrace = Lib.extendDeepNoArrays(newTrace, styleLookup[groupName] || {});\n    }\n\n    return newData;\n}\n\n},{\"../lib\":719,\"../plot_api/plot_schema\":756,\"../plots/plots\":828,\"./helpers\":1268}],1268:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nexports.pointsAccessorFunction = function(transforms, opts) {\n    var tr;\n    var prevIndexToPoints;\n    for(var i = 0; i < transforms.length; i++) {\n        tr = transforms[i];\n        if(tr === opts) break;\n        if(!tr._indexToPoints || tr.enabled === false) continue;\n        prevIndexToPoints = tr._indexToPoints;\n    }\n    var originalPointsAccessor = prevIndexToPoints ?\n        function(i) {return prevIndexToPoints[i];} :\n        function(i) {return [i];};\n    return originalPointsAccessor;\n};\n\n},{}],1269:[function(_dereq_,module,exports){\n/**\n* Copyright 2012-2019, Plotly, Inc.\n* All rights reserved.\n*\n* This source code is licensed under the MIT license found in the\n* LICENSE file in the root directory of this source tree.\n*/\n\n'use strict';\n\nvar Lib = _dereq_('../lib');\nvar Axes = _dereq_('../plots/cartesian/axes');\nvar pointsAccessorFunction = _dereq_('./helpers').pointsAccessorFunction;\n\nexports.moduleType = 'transform';\n\nexports.name = 'sort';\n\nexports.attributes = {\n    enabled: {\n        valType: 'boolean',\n        dflt: true,\n        \n        editType: 'calc',\n        \n    },\n    target: {\n        valType: 'string',\n        strict: true,\n        noBlank: true,\n        arrayOk: true,\n        dflt: 'x',\n        \n        editType: 'calc',\n        \n    },\n    order: {\n        valType: 'enumerated',\n        values: ['ascending', 'descending'],\n        dflt: 'ascending',\n        \n        editType: 'calc',\n        \n    },\n    editType: 'calc'\n};\n\nexports.supplyDefaults = function(transformIn) {\n    var transformOut = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(transformIn, transformOut, exports.attributes, attr, dflt);\n    }\n\n    var enabled = coerce('enabled');\n\n    if(enabled) {\n        coerce('target');\n        coerce('order');\n    }\n\n    return transformOut;\n};\n\nexports.calcTransform = function(gd, trace, opts) {\n    if(!opts.enabled) return;\n\n    var targetArray = Lib.getTargetArray(trace, opts);\n    if(!targetArray) return;\n\n    var target = opts.target;\n\n    var len = targetArray.length;\n    if(trace._length) len = Math.min(len, trace._length);\n\n    var arrayAttrs = trace._arrayAttrs;\n    var d2c = Axes.getDataToCoordFunc(gd, trace, target, targetArray);\n    var indices = getIndices(opts, targetArray, d2c, len);\n    var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);\n    var indexToPoints = {};\n    var i, j;\n\n    for(i = 0; i < arrayAttrs.length; i++) {\n        var np = Lib.nestedProperty(trace, arrayAttrs[i]);\n        var arrayOld = np.get();\n        var arrayNew = new Array(len);\n\n        for(j = 0; j < len; j++) {\n            arrayNew[j] = arrayOld[indices[j]];\n        }\n\n        np.set(arrayNew);\n    }\n\n    for(j = 0; j < len; j++) {\n        indexToPoints[j] = originalPointsAccessor(indices[j]);\n    }\n\n    opts._indexToPoints = indexToPoints;\n    trace._length = len;\n};\n\nfunction getIndices(opts, targetArray, d2c, len) {\n    var sortedArray = new Array(len);\n    var indices = new Array(len);\n    var i;\n\n    for(i = 0; i < len; i++) {\n        sortedArray[i] = {v: targetArray[i], i: i};\n    }\n\n    sortedArray.sort(getSortFunc(opts, d2c));\n\n    for(i = 0; i < len; i++) {\n        indices[i] = sortedArray[i].i;\n    }\n\n    return indices;\n}\n\nfunction getSortFunc(opts, d2c) {\n    switch(opts.order) {\n        case 'ascending':\n            return function(a, b) { return d2c(a.v) - d2c(b.v); };\n        case 'descending':\n            return function(a, b) { return d2c(b.v) - d2c(a.v); };\n    }\n}\n\n},{\"../lib\":719,\"../plots/cartesian/axes\":767,\"./helpers\":1268}]},{},[25])(25)\n});\n"
  },
  {
    "path": "cyacas/packaging/deb/rules",
    "content": "#!/usr/bin/make -f\n# Sample debian/rules that uses debhelper.\n# GNU copyright 1997 to 1999 by Joey Hess.\n\n# Uncomment this to turn on verbose mode.\n#export DH_VERBOSE=1\n\nifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))\n    BUILDTYPE = Debug\nelse\n    BUILDTYPE = RelWithDebInfo\nendif\n\nifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))\n    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))\n    MAKEFLAGS += -j$(NUMJOBS)\nendif\n\nbuild: build-arch build-indep\nbuild-arch: build-stamp\nbuild-indep: build-stamp\n\nbuild-stamp:\n\tdh_testdir\n\n\t# Add here commands to compile the package.\n\tmkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=$(BUILDTYPE) -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_CYACAS_KERNEL=ON -DENABLE_DOCS=ON .. && make $(MAKEFLAGS)\n\t# --- end custom part for compiling\n\n\ttouch build-stamp\n\nclean:\n\tdh_testdir\n\tdh_testroot\n\trm -f build-stamp\n\n\t# Add here commands to clean up after the build process.\n\trm -rf build\n\t# --- end custom part for cleaning up\n\n\tdh_clean\n\ninstall: build\n\tdh_testdir\n\tdh_testroot\n\tdh_prep\n\tdh_installdirs\n\n\t# Add here commands to install the package\n\tcd build && make install DESTDIR=../debian/yacas && cd ..\n\tmkdir -p debian/yacas-common/usr/share/yacas\n\tmv debian/yacas/usr/share/yacas/scripts debian/yacas-common/usr/share/yacas\n\tmv debian/yacas/usr/share/yacas/tests debian/yacas-common/usr/share/yacas\n\tmkdir -p debian/yacas-console/usr/bin\n\tmv debian/yacas/usr/bin/yacas debian/yacas-console/usr/bin\n\tmkdir -p debian/yacas-gui/usr/bin\n\tmv debian/yacas/usr/bin/yacas-gui debian/yacas-gui/usr/bin\n\tmkdir -p debian/yacas-gui/usr/share/yacas\n\tmv debian/yacas/usr/share/yacas/resources debian/yacas-gui/usr/share/yacas\n\tmv debian/yacas/usr/share/applications debian/yacas-gui/usr/share\n\tmv debian/yacas/usr/share/pixmaps debian/yacas-gui/usr/share\n\tmv debian/yacas/usr/share/icons debian/yacas-gui/usr/share\n\tmkdir -p debian/yacas-kernel/usr/bin\n\tmv debian/yacas/usr/bin/yacas-kernel debian/yacas-kernel/usr/bin\n\tmkdir -p debian/yacas-dev/usr\n\tmv debian/yacas/usr/lib debian/yacas-dev/usr\n\tmv debian/yacas/usr/include debian/yacas-dev/usr\n\tmkdir -p debian/yacas-doc/usr/share/yacas/documentation\n\tmv debian/yacas/usr/share/doc/yacas/singlehtml debian/yacas-doc/usr/share/yacas/documentation\n\n\t# replace fonts in yacas-doc with symbolic links to system-wide ones\n\tfor f in Lato-BoldItalic.ttf Lato-Bold.ttf Lato-Italic.ttf Lato-Regular.ttf; do ln -s -f /usr/share/fonts/truetype/lato/$$f debian/yacas-doc/usr/share/yacas/documentation/singlehtml/_static/fonts/$$f; done\n\tfor f in RobotoSlab-Bold.ttf RobotoSlab-Regular.ttf; do ln -s -f /usr/share/fonts/truetype/roboto/slab/$$f debian/yacas-doc/usr/share/yacas/documentation/singlehtml/_static/fonts/$$f; done\n\tln -s -f /usr/share/fonts/truetype/font-awesome/fontawesome-webfont.ttf debian/yacas-doc/usr/share/yacas/documentation/singlehtml/_static/fonts/fontawesome-webfont.ttf\n\n\t# replace javascript libs in yacas-doc with symbolic links to system-wide ones\n\tln -s -f /usr/share/javascript/jquery/jquery.js debian/yacas-doc/usr/share/yacas/documentation/singlehtml/_static/jquery.js\n\tln -s -f /usr/share/javascript/jquery/underscore.js debian/yacas-doc/usr/share/yacas/documentation/singlehtml/_static/underscore.js\n\n\t# replace MathJax in yacas-gui with symbolic link to system-wide one\n\trm -rf debian/yacas-gui/usr/share/yacas/resources/mathjax\n\tln -s /usr/share/javascript/mathjax debian/yacas-gui/usr/share/yacas/resources/mathjax\n\n\t# replace CodeMirror in yacas-gui with symbolic link to system-wide one\n\trm -rf debian/yacas-gui/usr/share/yacas/resources/codemirror\n\tln -s /usr/share/javascript/codemirror debian/yacas-gui/usr/share/yacas/resources/codemirror\n\n\t# replace jquery and jquery-ui in yacas-gui with symbolic links to system-wide ones\n\tln -s -f /usr/share/javascript/jquery/jquery.min.js debian/yacas-gui/usr/share/yacas/resources/jquery/jquery.min.js\n\tln -s -f /usr/share/javascript/jquery-ui/jquery-ui.min.js debian/yacas-gui/usr/share/yacas/resources/jquery/jquery-ui.min.js\n\tln -s -f /usr/share/javascript/jquery-ui/themes/base/jquery-ui.min.css debian/yacas-gui/usr/share/yacas/resources/jquery/jquery-ui.min.css\n\n\t# --- end custom part for installing\n\n# Build architecture-independent files here.\nbinary-indep: build install\n\t# We have nothing to do by default.\n\n# Build architecture-dependent files here.\nbinary-arch: build install\n\tdh_testdir\n\tdh_testroot\n#\tdh_installdebconf\n\tdh_installdocs\n\tdh_installexamples\n\tdh_installmenu\n#\tdh_installlogrotate\n#\tdh_installemacsen\n#\tdh_installpam\n#\tdh_installmime\n#\tdh_installinit\n\tdh_installcron\n\tdh_installman\n\tdh_installinfo\n#\tdh_undocumented\n\tdh_installchangelogs\n\tdh_link\n\tdh_strip\n\tdh_compress\n\tdh_fixperms\n#\tdh_makeshlibs\n\tdh_installdeb\n#\tdh_perl\n\tdh_shlibdeps\n\tdh_gencontrol\n\tdh_md5sums\n\tdh_builddeb\n\nbinary: binary-indep binary-arch\n.PHONY: build clean binary-indep binary-arch binary install\n"
  },
  {
    "path": "cyacas/packaging/deb/source/format",
    "content": "3.0 (quilt)\n"
  },
  {
    "path": "cyacas/packaging/deb/source/include-binaries",
    "content": "debian/yacas/usr/share/doc/yacas/singlehtml/objects.inv\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/yacaslogo_w250px.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/up.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/file.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/plus.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/minus.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/comment-close.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/up-pressed.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/favicon.ico\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/comment.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/down.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/comment-bright.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/ajax-loader.gif\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/down-pressed.png\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/Lato-Italic.woff2\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/fontawesome-webfont.ttf\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/RobotoSlab-Bold.woff2\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/Lato-Regular.woff2\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/fontawesome-webfont.woff\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/Lato-Bold.ttf\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/Lato-Italic.ttf\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/RobotoSlab-Regular.ttf\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/Lato-Regular.ttf\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/Lato-Bold.woff2\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/Lato-BoldItalic.woff2\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/RobotoSlab-Bold.ttf\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/RobotoSlab-Regular.woff2\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/fontawesome-webfont.woff2\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/Lato-BoldItalic.ttf\ndebian/yacas/usr/share/doc/yacas/singlehtml/_static/fonts/fontawesome-webfont.eot\ndebian/yacas/usr/share/man/man1/yacas.1.gz\n\n"
  },
  {
    "path": "cyacas/packaging/deb/yacas.1",
    "content": ".\\\" Man page generated from reStructuredText.\n.\n.TH YACAS 1 \"\" \"\" \"\"\n.SH NAME\nyacas \\- Yet Another Computer Algebra System\n.\n.nr rst2man-indent-level 0\n.\n.de1 rstReportMargin\n\\\\$1 \\\\n[an-margin]\nlevel \\\\n[rst2man-indent-level]\nlevel margin: \\\\n[rst2man-indent\\\\n[rst2man-indent-level]]\n-\n\\\\n[rst2man-indent0]\n\\\\n[rst2man-indent1]\n\\\\n[rst2man-indent2]\n..\n.de1 INDENT\n.\\\" .rstReportMargin pre:\n. RS \\\\$1\n. nr rst2man-indent\\\\n[rst2man-indent-level] \\\\n[an-margin]\n. nr rst2man-indent-level +1\n.\\\" .rstReportMargin post:\n..\n.de UNINDENT\n. RE\n.\\\" indent \\\\n[an-margin]\n.\\\" old: \\\\n[rst2man-indent\\\\n[rst2man-indent-level]]\n.nr rst2man-indent-level -1\n.\\\" new: \\\\n[rst2man-indent\\\\n[rst2man-indent-level]]\n.in \\\\n[rst2man-indent\\\\n[rst2man-indent-level]]u\n..\n.SH SYNOPSIS\n.sp\nyacas [\\fIOPTION\\fP] [\\fIFILE\\fP]\n.sp\nyacas \\fB\\-i\\fP \\fICOMMAND\\fP\n.SH DESCRIPTION\n.sp\nYacas is an easy to use, general purpose Computer Algebra System, a program for\nsymbolic manipulation of mathematical expressions. It uses its own programming\nlanguage designed for symbolic as well as arbitrary\\-precision numerical\ncomputations. The system has a library of scripts that implement many of the\nsymbolic algebra operations; new algorithms can be easily added to the library.\nYacas comes with extensive documentation covering the scripting language, the\nfunctionality that is already implemented in the system, and the algorithms we\nused.\n.SH OPTIONS\n.INDENT 0.0\n.TP\n.B \\fB\\-d\\fP\nprint default scripts path and exit\n.TP\n.B \\fB\\-v\\fP\nprint yacas version and exit\n.TP\n.B \\fB\\-p\\fP\nplain (dumb\\-terminal) mode\n.TP\n.B \\fB\\-c\\fP\ndo not print prompt\n.TP\n.B \\fB\\-i\\fP \\fICOMMAND\\fP\nexecute COMMAND and exit\n.UNINDENT\n.SH OTHER DOCUMENTATION\n.sp\nFull documentation at: \\fI\\%https://yacas.readthedocs.io/\\fP\n.\\\" Generated by docutils manpage writer.\n.\n"
  },
  {
    "path": "cyacas/packaging/ebuild/yacas.ebuild",
    "content": "# Copyright 1999-2017 Gentoo Foundation\n# Distributed under the terms of the GNU General Public License v2\n# $Id$\n\nEAPI=6\n\nCMAKE_IN_SOURCE_BUILD=0\n\ninherit java-pkg-opt-2 cmake-utils\n\nDESCRIPTION=\"General purpose computer algebra system\"\nHOMEPAGE=\"http://www.yacas.org/\"\nSRC_URI=\"https://codeload.github.com/grzegorzmazur/${PN}/tar.gz/v${PV} -> ${P}.tar.gz\"\n\nSLOT=\"0/1\"\nLICENSE=\"LGPL-2.1+\"\nKEYWORDS=\"~amd64 ~x86\"\nIUSE=\"doc gui java +jupyter static-libs\"\n\nDEPEND=\"\n\tdoc? ( dev-python/sphinx )\n\tgui? (\t>=dev-qt/qtcore-5.6[icu]\n\t\t\t>=dev-qt/qtgui-5.6\n\t\t\t>=dev-qt/qtwidgets-5.6\n\t\t\t>=dev-qt/qtnetwork-5.6\n\t\t\t>=dev-qt/qtwebkit-5.6\n\t\t\t>=dev-qt/qtmultimedia-5.6\n\t\t\t>=dev-qt/qtsql-5.6\n\t\t\t>=dev-qt/qtprintsupport-5.6\n\t\t\t>=dev-qt/qtopengl-5.6\n\t\t\t>=dev-qt/qtprintsupport-5.6 )\n\tjupyter? (\tdev-python/jupyter\n\t\t\t\tdev-libs/boost\n\t\t\t\tdev-libs/jsoncpp\n\t\t\t\tdev-libs/openssl:0\n\t\t\t\tnet-libs/zeromq\n\t\t\t\t>=net-libs/zmqpp-4.1.2 )\n\tjava? ( >=virtual/jdk-1.6 )\"\nRDEPEND=\"java? ( >=virtual/jre-1.6 )\"\n\nsrc_configure() {\n\tlocal mycmakeargs=(\n\t\t-DENABLE_DOCS=$(usex doc)\n\t\t-DENABLE_CYACAS_GUI=$(usex gui)\n\t\t-DENABLE_CYACAS_KERNEL=$(usex jupyter)\n\t\t-DENABLE_JYACAS=$(usex java)\n\t)\n\tcmake-utils_src_configure\n}\n"
  },
  {
    "path": "cyacas/packaging/flatpak/org.yacas.yacas-gui.appdata.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<component type=\"desktop\">\n    <id>org.yacas.yacas-gui</id>\n    <metadata_license>CC0-1.0</metadata_license>\n    <project_license>LGPL-2.1-or-later</project_license>\n    <name>yancas</name>\n    <summary>Yet Another Computer Algebra System</summary>\n    <description>\n\t<p>\n\t    Yacas is an easy to use, general purpose Computer Algebra System, a\n            program for symbolic manipulation of mathematical expressions. It\n            uses its own programming language designed for symbolic as well as\n            arbitrary-precision numerical computations. The system has a library\n            of scripts that implement many of the symbolic algebra operations;\n            new algorithms can be easily added to the library.\n\t</p>\n    </description>\n    <screenshots>\n        <screenshot type=\"default\">\n          <image>http://www.yacas.org/images/screenshot-yagy-on_mac.png</image>\n        </screenshot>\n        <screenshot>\n          <image>http://www.yacas.org/images/screenshot-yagy-autocompletion.png</image>\n        </screenshot>\n    </screenshots>\n    <categories>\n        <category>Science</category>\n        <category>Education</category>\n    </categories>\n    <url type=\"bugtracker\">https://github.com/grzegorzmazur/yacas/issues</url>\n    <url type=\"homepage\">http://www.yacas.org/</url>\n    <url type=\"help\">https://groups.google.com/g/yacas/</url>\n    <developer_name>yancas</developer_name>\n    <kudos>\n        <kudo>HiDpiIcon</kudo>\n        <kudo>HighContrast</kudo>\n        <kudo>UserDocs</kudo>\n    </kudos>\n    <launchable type=\"desktop-id\">yacas-gui.desktop</launchable>\n    <provides>\n        <binary>yancas-gui</binary>\n    </provides>\n    <translation type=\"gettext\">yancas</translation>\n    <content_rating type=\"oars-1.1\">\n        <content_attribute id=\"social-info\">mild</content_attribute>\n    </content_rating>\n    <releases>\n\t<release version=\"1.9.1\" date=\"2020-07-04\"></release>\n    </releases>\n</component>\n"
  },
  {
    "path": "cyacas/packaging/flatpak/org.yacas.yacas-gui.json",
    "content": "{\n    \"app-id\": \"org.yacas.yacas-gui\",\n    \"branch\": \"1.9\",\n    \"runtime\": \"org.freedesktop.Platform\",\n    \"runtime-version\": \"1.6\",\n    \"sdk\": \"org.freedesktop.Sdk\",\n    \"command\": \"yacas-gui\",\n    \"finish-args\": [\n        \"--socket=x11\",\n        \"--share=network\",\n        \"--filesystem=home\"\n    ],\n    \"rename-desktop-file\": \"yacas-gui.desktop\",\n    \"rename-icon\": \"yacas-gui\",\n    \"copy-icon\": true,\n    \"modules\": [\n        {\n            \"name\": \"qt5-qtbase\",\n            \"cleanup\": [ \"/bin\" ],\n            \"config-opts\": [ \"--confirm-license\", \"--opensource\",\n                             \"--release\", \"--shared\",\n                             \"-platform\", \"linux-g++\",\n                             \"-accessibility\",\n                             \"-dbus-linked\",\n                             \"-fontconfig\",\n                             \"-iconv\",\n                             \"-icu\",\n                             \"-no-alsa\",\n                             \"-no-pch\",\n                             \"-no-rpath\",\n                             \"-no-separate-debug-info\",\n                             \"-no-directfb\",\n                             \"-no-linuxfb\",\n                             \"-no-kms\",\n                             \"-no-cups\",\n                             \"-no-gtkstyle\",\n                             \"-nomake\", \"examples\",\n                             \"-nomake\", \"tests\",\n                             \"-optimized-qmake\",\n                             \"-system-proxies\",\n                             \"-qt-harfbuzz\",\n                             \"-qt-zlib\",\n                             \"-qt-libjpeg\",\n                             \"-qt-libpng\",\n                             \"-qt-pcre\",\n                             \"-reduce-relocations\",\n                             \"-prefix\", \"/app\"\n                           ],\n            \"sources\": [\n                {\n                    \"type\": \"git\",\n                    \"url\": \"git://code.qt.io/qt/qtbase.git\",\n                    \"branch\": \"v5.10.1\"\n                }\n            ]\n        },\n        {\n            \"name\": \"qt5-qtsvg\",\n            \"cleanup\": [ \"/bin\", \"/mkspecs\" ],\n            \"sources\": [\n                {\n                    \"type\": \"git\",\n                    \"url\": \"git://code.qt.io/qt/qtsvg.git\",\n                    \"branch\": \"v5.10.1\"\n                },\n                {\n                    \"type\": \"script\",\n                    \"commands\": [ \"qmake\" ],\n                    \"dest-filename\": \"configure\"\n                }\n            ]\n        },\n        {\n            \"name\": \"qt5-qtwebengine\",\n            \"cleanup\": [ \"/bin\", \"/mkspecs\" ],\n            \"sources\": [\n                {\n                    \"type\": \"git\",\n                    \"url\": \"git://code.qt.io/qt/qtwebengine.git\",\n                    \"branch\": \"v5.10.1\"\n                },\n                {\n                    \"type\": \"script\",\n                    \"commands\": [ \"qmake\" ],\n                    \"dest-filename\": \"configure\"\n                }\n            ]\n        },\n        {\n            \"name\": \"yacas-gui\",\n            \"sources\": [\n                {\n                    \"type\": \"archive\",\n                    \"url\": \"https://github.com/grzegorzmazur/yacas/archive/v1.9.2.tar.gz\",\n                    \"sha256\": \"6b94394f705bed70a9d104967073efd6c23e9eb1a832805c4d805ef875555ae5\"\n                }\n            ],\n            \"buildsystem\": \"cmake\",\n            \"build-options\": {\n                \"build-args\": [\n                    \"--share=network\"\n                ]\n            },\n            \"config-opts\": [\n                \"-DCMAKE_BUILD_TYPE=Release\",\n                \"-DCMAKE_INSTALL_PREFIX=/app\",\n                \"-DENABLE_CYACAS_GUI=On\",\n                \"-DENABLE_CYACAS_KERNEL=Off\",\n                \"-DENABLE_JYACAS=Off\"\n            ],\n            \"cleanup\": [\n                \"/include\",\n                \"/lib\"\n            ]\n        }\n    ]\n}\n"
  },
  {
    "path": "cyacas/packaging/flatpak/org.yacas.yacas.json",
    "content": "{\n    \"app-id\": \"org.yacas.yacas\",\n    \"branch\": \"1.9\",\n    \"runtime\": \"org.freedesktop.Platform\",\n    \"runtime-version\": \"1.6\",\n    \"sdk\": \"org.freedesktop.Sdk\",\n    \"command\": \"yacas\",\n    \"finish-args\": [\n        \"--socket=x11\",\n        \"--share=network\",\n        \"--filesystem=home\"\n    ],\n    \"modules\": [\n        {\n            \"name\": \"yacas\",\n            \"sources\": [\n                {\n                    \"type\": \"archive\",\n                    \"url\": \"https://github.com/grzegorzmazur/yacas/archive/v1.9.2.tar.gz\",\n                    \"sha256\": \"6b94394f705bed70a9d104967073efd6c23e9eb1a832805c4d805ef875555ae5\"\n                }\n            ],\n            \"buildsystem\": \"cmake\",\n            \"config-opts\": [\n                \"-DCMAKE_BUILD_TYPE=Release\",\n                \"-DCMAKE_INSTALL_PREFIX=/app\",\n                \"-DENABLE_CYACAS_GUI=Off\",\n                \"-DENABLE_CYACAS_KERNEL=Off\",\n                \"-DENABLE_JYACAS=Off\"\n            ],\n            \"cleanup\": [\n                \"/include\",\n                \"/lib\"\n            ]\n        }\n    ]\n}\n"
  },
  {
    "path": "cyacas/packaging/nsis/COPYING",
    "content": "                  GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 2.1, February 1999\n\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n[This is the first released version of the Lesser GPL.  It also counts\n as the successor of the GNU Library Public License, version 2, hence\n the version number 2.1.]\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicenses are intended to guarantee your freedom to share and change\nfree software--to make sure the software is free for all its users.\n\n  This license, the Lesser General Public License, applies to some\nspecially designated software packages--typically libraries--of the\nFree Software Foundation and other authors who decide to use it.  You\ncan use it too, but we suggest you first think carefully about whether\nthis license or the ordinary General Public License is the better\nstrategy to use in any particular case, based on the explanations below.\n\n  When we speak of free software, we are referring to freedom of use,\nnot price.  Our General Public Licenses are designed to make sure that\nyou have the freedom to distribute copies of free software (and charge\nfor this service if you wish); that you receive source code or can get\nit if you want it; that you can change the software and use pieces of\nit in new free programs; and that you are informed that you can do\nthese things.\n\n  To protect your rights, we need to make restrictions that forbid\ndistributors to deny you these rights or to ask you to surrender these\nrights.  These restrictions translate to certain responsibilities for\nyou if you distribute copies of the library or if you modify it.\n\n  For example, if you distribute copies of the library, whether gratis\nor for a fee, you must give the recipients all the rights that we gave\nyou.  You must make sure that they, too, receive or can get the source\ncode.  If you link other code with the library, you must provide\ncomplete object files to the recipients, so that they can relink them\nwith the library after making changes to the library and recompiling\nit.  And you must show them these terms so they know their rights.\n\n  We protect your rights with a two-step method: (1) we copyright the\nlibrary, and (2) we offer you this license, which gives you legal\npermission to copy, distribute and/or modify the library.\n\n  To protect each distributor, we want to make it very clear that\nthere is no warranty for the free library.  Also, if the library is\nmodified by someone else and passed on, the recipients should know\nthat what they have is not the original version, so that the original\nauthor's reputation will not be affected by problems that might be\nintroduced by others.\n\f\n  Finally, software patents pose a constant threat to the existence of\nany free program.  We wish to make sure that a company cannot\neffectively restrict the users of a free program by obtaining a\nrestrictive license from a patent holder.  Therefore, we insist that\nany patent license obtained for a version of the library must be\nconsistent with the full freedom of use specified in this license.\n\n  Most GNU software, including some libraries, is covered by the\nordinary GNU General Public License.  This license, the GNU Lesser\nGeneral Public License, applies to certain designated libraries, and\nis quite different from the ordinary General Public License.  We use\nthis license for certain libraries in order to permit linking those\nlibraries into non-free programs.\n\n  When a program is linked with a library, whether statically or using\na shared library, the combination of the two is legally speaking a\ncombined work, a derivative of the original library.  The ordinary\nGeneral Public License therefore permits such linking only if the\nentire combination fits its criteria of freedom.  The Lesser General\nPublic License permits more lax criteria for linking other code with\nthe library.\n\n  We call this license the \"Lesser\" General Public License because it\ndoes Less to protect the user's freedom than the ordinary General\nPublic License.  It also provides other free software developers Less\nof an advantage over competing non-free programs.  These disadvantages\nare the reason we use the ordinary General Public License for many\nlibraries.  However, the Lesser license provides advantages in certain\nspecial circumstances.\n\n  For example, on rare occasions, there may be a special need to\nencourage the widest possible use of a certain library, so that it becomes\na de-facto standard.  To achieve this, non-free programs must be\nallowed to use the library.  A more frequent case is that a free\nlibrary does the same job as widely used non-free libraries.  In this\ncase, there is little to gain by limiting the free library to free\nsoftware only, so we use the Lesser General Public License.\n\n  In other cases, permission to use a particular library in non-free\nprograms enables a greater number of people to use a large body of\nfree software.  For example, permission to use the GNU C Library in\nnon-free programs enables many more people to use the whole GNU\noperating system, as well as its variant, the GNU/Linux operating\nsystem.\n\n  Although the Lesser General Public License is Less protective of the\nusers' freedom, it does ensure that the user of a program that is\nlinked with the Library has the freedom and the wherewithal to run\nthat program using a modified version of the Library.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.  Pay close attention to the difference between a\n\"work based on the library\" and a \"work that uses the library\".  The\nformer contains code derived from the library, whereas the latter must\nbe combined with the library in order to run.\n\f\n                  GNU LESSER GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License Agreement applies to any software library or other\nprogram which contains a notice placed by the copyright holder or\nother authorized party saying it may be distributed under the terms of\nthis Lesser General Public License (also called \"this License\").\nEach licensee is addressed as \"you\".\n\n  A \"library\" means a collection of software functions and/or data\nprepared so as to be conveniently linked with application programs\n(which use some of those functions and data) to form executables.\n\n  The \"Library\", below, refers to any such software library or work\nwhich has been distributed under these terms.  A \"work based on the\nLibrary\" means either the Library or any derivative work under\ncopyright law: that is to say, a work containing the Library or a\nportion of it, either verbatim or with modifications and/or translated\nstraightforwardly into another language.  (Hereinafter, translation is\nincluded without limitation in the term \"modification\".)\n\n  \"Source code\" for a work means the preferred form of the work for\nmaking modifications to it.  For a library, complete source code means\nall the source code for all modules it contains, plus any associated\ninterface definition files, plus the scripts used to control compilation\nand installation of the library.\n\n  Activities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning a program using the Library is not restricted, and output from\nsuch a program is covered only if its contents constitute a work based\non the Library (independent of the use of the Library in a tool for\nwriting it).  Whether that is true depends on what the Library does\nand what the program that uses the Library does.\n\n  1. You may copy and distribute verbatim copies of the Library's\ncomplete source code as you receive it, in any medium, provided that\nyou conspicuously and appropriately publish on each copy an\nappropriate copyright notice and disclaimer of warranty; keep intact\nall the notices that refer to this License and to the absence of any\nwarranty; and distribute a copy of this License along with the\nLibrary.\n\n  You may charge a fee for the physical act of transferring a copy,\nand you may at your option offer warranty protection in exchange for a\nfee.\n\f\n  2. You may modify your copy or copies of the Library or any portion\nof it, thus forming a work based on the Library, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) The modified work must itself be a software library.\n\n    b) You must cause the files modified to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    c) You must cause the whole of the work to be licensed at no\n    charge to all third parties under the terms of this License.\n\n    d) If a facility in the modified Library refers to a function or a\n    table of data to be supplied by an application program that uses\n    the facility, other than as an argument passed when the facility\n    is invoked, then you must make a good faith effort to ensure that,\n    in the event an application does not supply such function or\n    table, the facility still operates, and performs whatever part of\n    its purpose remains meaningful.\n\n    (For example, a function in a library to compute square roots has\n    a purpose that is entirely well-defined independent of the\n    application.  Therefore, Subsection 2d requires that any\n    application-supplied function or table used by this function must\n    be optional: if the application does not supply it, the square\n    root function must still compute square roots.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Library,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Library, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote\nit.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Library.\n\nIn addition, mere aggregation of another work not based on the Library\nwith the Library (or with a work based on the Library) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may opt to apply the terms of the ordinary GNU General Public\nLicense instead of this License to a given copy of the Library.  To do\nthis, you must alter all the notices that refer to this License, so\nthat they refer to the ordinary GNU General Public License, version 2,\ninstead of to this License.  (If a newer version than version 2 of the\nordinary GNU General Public License has appeared, then you can specify\nthat version instead if you wish.)  Do not make any other change in\nthese notices.\n\f\n  Once this change is made in a given copy, it is irreversible for\nthat copy, so the ordinary GNU General Public License applies to all\nsubsequent copies and derivative works made from that copy.\n\n  This option is useful when you wish to copy part of the code of\nthe Library into a program that is not a library.\n\n  4. You may copy and distribute the Library (or a portion or\nderivative of it, under Section 2) in object code or executable form\nunder the terms of Sections 1 and 2 above provided that you accompany\nit with the complete corresponding machine-readable source code, which\nmust be distributed under the terms of Sections 1 and 2 above on a\nmedium customarily used for software interchange.\n\n  If distribution of object code is made by offering access to copy\nfrom a designated place, then offering equivalent access to copy the\nsource code from the same place satisfies the requirement to\ndistribute the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  5. A program that contains no derivative of any portion of the\nLibrary, but is designed to work with the Library by being compiled or\nlinked with it, is called a \"work that uses the Library\".  Such a\nwork, in isolation, is not a derivative work of the Library, and\ntherefore falls outside the scope of this License.\n\n  However, linking a \"work that uses the Library\" with the Library\ncreates an executable that is a derivative of the Library (because it\ncontains portions of the Library), rather than a \"work that uses the\nlibrary\".  The executable is therefore covered by this License.\nSection 6 states terms for distribution of such executables.\n\n  When a \"work that uses the Library\" uses material from a header file\nthat is part of the Library, the object code for the work may be a\nderivative work of the Library even though the source code is not.\nWhether this is true is especially significant if the work can be\nlinked without the Library, or if the work is itself a library.  The\nthreshold for this to be true is not precisely defined by law.\n\n  If such an object file uses only numerical parameters, data\nstructure layouts and accessors, and small macros and small inline\nfunctions (ten lines or less in length), then the use of the object\nfile is unrestricted, regardless of whether it is legally a derivative\nwork.  (Executables containing this object code plus portions of the\nLibrary will still fall under Section 6.)\n\n  Otherwise, if the work is a derivative of the Library, you may\ndistribute the object code for the work under the terms of Section 6.\nAny executables containing that work also fall under Section 6,\nwhether or not they are linked directly with the Library itself.\n\f\n  6. As an exception to the Sections above, you may also combine or\nlink a \"work that uses the Library\" with the Library to produce a\nwork containing portions of the Library, and distribute that work\nunder terms of your choice, provided that the terms permit\nmodification of the work for the customer's own use and reverse\nengineering for debugging such modifications.\n\n  You must give prominent notice with each copy of the work that the\nLibrary is used in it and that the Library and its use are covered by\nthis License.  You must supply a copy of this License.  If the work\nduring execution displays copyright notices, you must include the\ncopyright notice for the Library among them, as well as a reference\ndirecting the user to the copy of this License.  Also, you must do one\nof these things:\n\n    a) Accompany the work with the complete corresponding\n    machine-readable source code for the Library including whatever\n    changes were used in the work (which must be distributed under\n    Sections 1 and 2 above); and, if the work is an executable linked\n    with the Library, with the complete machine-readable \"work that\n    uses the Library\", as object code and/or source code, so that the\n    user can modify the Library and then relink to produce a modified\n    executable containing the modified Library.  (It is understood\n    that the user who changes the contents of definitions files in the\n    Library will not necessarily be able to recompile the application\n    to use the modified definitions.)\n\n    b) Use a suitable shared library mechanism for linking with the\n    Library.  A suitable mechanism is one that (1) uses at run time a\n    copy of the library already present on the user's computer system,\n    rather than copying library functions into the executable, and (2)\n    will operate properly with a modified version of the library, if\n    the user installs one, as long as the modified version is\n    interface-compatible with the version that the work was made with.\n\n    c) Accompany the work with a written offer, valid for at\n    least three years, to give the same user the materials\n    specified in Subsection 6a, above, for a charge no more\n    than the cost of performing this distribution.\n\n    d) If distribution of the work is made by offering access to copy\n    from a designated place, offer equivalent access to copy the above\n    specified materials from the same place.\n\n    e) Verify that the user has already received a copy of these\n    materials or that you have already sent this user a copy.\n\n  For an executable, the required form of the \"work that uses the\nLibrary\" must include any data and utility programs needed for\nreproducing the executable from it.  However, as a special exception,\nthe materials to be distributed need not include anything that is\nnormally distributed (in either source or binary form) with the major\ncomponents (compiler, kernel, and so on) of the operating system on\nwhich the executable runs, unless that component itself accompanies\nthe executable.\n\n  It may happen that this requirement contradicts the license\nrestrictions of other proprietary libraries that do not normally\naccompany the operating system.  Such a contradiction means you cannot\nuse both them and the Library together in an executable that you\ndistribute.\n\f\n  7. You may place library facilities that are a work based on the\nLibrary side-by-side in a single library together with other library\nfacilities not covered by this License, and distribute such a combined\nlibrary, provided that the separate distribution of the work based on\nthe Library and of the other library facilities is otherwise\npermitted, and provided that you do these two things:\n\n    a) Accompany the combined library with a copy of the same work\n    based on the Library, uncombined with any other library\n    facilities.  This must be distributed under the terms of the\n    Sections above.\n\n    b) Give prominent notice with the combined library of the fact\n    that part of it is a work based on the Library, and explaining\n    where to find the accompanying uncombined form of the same work.\n\n  8. You may not copy, modify, sublicense, link with, or distribute\nthe Library except as expressly provided under this License.  Any\nattempt otherwise to copy, modify, sublicense, link with, or\ndistribute the Library is void, and will automatically terminate your\nrights under this License.  However, parties who have received copies,\nor rights, from you under this License will not have their licenses\nterminated so long as such parties remain in full compliance.\n\n  9. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Library or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Library (or any work based on the\nLibrary), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Library or works based on it.\n\n  10. Each time you redistribute the Library (or any work based on the\nLibrary), the recipient automatically receives a license from the\noriginal licensor to copy, distribute, link with or modify the Library\nsubject to these terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties with\nthis License.\n\f\n  11. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Library at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Library by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Library.\n\nIf any portion of this section is held invalid or unenforceable under any\nparticular circumstance, the balance of the section is intended to apply,\nand the section as a whole is intended to apply in other circumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  12. If the distribution and/or use of the Library is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Library under this License may add\nan explicit geographical distribution limitation excluding those countries,\nso that distribution is permitted only in or among countries not thus\nexcluded.  In such case, this License incorporates the limitation as if\nwritten in the body of this License.\n\n  13. The Free Software Foundation may publish revised and/or new\nversions of the Lesser General Public License from time to time.\nSuch new versions will be similar in spirit to the present version,\nbut may differ in detail to address new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Library\nspecifies a version number of this License which applies to it and\n\"any later version\", you have the option of following the terms and\nconditions either of that version or of any later version published by\nthe Free Software Foundation.  If the Library does not specify a\nlicense version number, you may choose any version ever published by\nthe Free Software Foundation.\n\f\n  14. If you wish to incorporate parts of the Library into other free\nprograms whose distribution conditions are incompatible with these,\nwrite to the author to ask for permission.  For software which is\ncopyrighted by the Free Software Foundation, write to the Free\nSoftware Foundation; we sometimes make exceptions for this.  Our\ndecision will be guided by the two goals of preserving the free status\nof all derivatives of our free software and of promoting the sharing\nand reuse of software generally.\n\n                            NO WARRANTY\n\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\nDAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\f\n           How to Apply These Terms to Your New Libraries\n\n  If you develop a new library, and you want it to be of the greatest\npossible use to the public, we recommend making it free software that\neveryone can redistribute and change.  You can do so by permitting\nredistribution under these terms (or, alternatively, under the terms of the\nordinary General Public License).\n\n  To apply these terms, attach the following notices to the library.  It is\nsafest to attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least the\n\"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the library's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This library is free software; you can redistribute it and/or\n    modify it under the terms of the GNU Lesser General Public\n    License as published by the Free Software Foundation; either\n    version 2.1 of the License, or (at your option) any later version.\n\n    This library is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n    Lesser General Public License for more details.\n\n    You should have received a copy of the GNU Lesser General Public\n    License along with this library; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n\nAlso add information on how to contact you by electronic and paper mail.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\n\n  <signature of Ty Coon>, 1 April 1990\n  Ty Coon, President of Vice\n\nThat's all there is to it!\n"
  },
  {
    "path": "cyacas/packaging/nsis/yacas-win64.nsi",
    "content": "!include \"MUI2.nsh\"\n\n!define APPNAME \"Yacas\"\n!define DESCRIPTION \"Yet Another Computer Algebra System\"\n!define VERSIONMAJOR 1\n!define VERSIONMINOR 7\n!define VERSIONPATCH 0\n!define HELPURL \"http://www.yacas.org\"\n!define UPDATEURL \"http://www.yacas.org/downloads\"\n!define ABOUTURL \"http://www.yacas.org\"\n!define INSTALLSIZE 17500\n\nName ${APPNAME}\nOutfile \"yacas-${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONPATCH}-win64.exe\"\n\nInstallDir \"$PROGRAMFILES64\\yacas\\\"\n\n!include \"WordFunc.nsh\"\n!insertmacro VersionCompare\n\nVar UNINSTALL_OLD_VERSION\n\nFunction .onInit\n    SetRegView 64\n\n    ClearErrors\n    ReadRegStr $0 HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"DisplayVersion\"\n    IfErrors init.uninst\n    ${VersionCompare} $0 ${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONPATCH} $1\n    IntCmp $1 2 init.uninst\n\n    MessageBox MB_YESNO|MB_ICONQUESTION \"${APPNAME} version $0 seems to be already installed on your system.$\\nWould you like to remove it and proceed with the installation of version ${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONPATCH}?\" IDYES init.uninst\n    Quit\n\ninit.uninst:\n    ClearErrors\n    ReadRegStr $0 HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"UninstallString\"\n    IfErrors init.done\n    StrCpy $UNINSTALL_OLD_VERSION '$0 /S'\n\ninit.done:\n\nFunctionEnd\n\nFunction un.onInit\n    SetRegView 64\nFunctionEnd\n\n!define MUI_ICON \"yacas.ico\"\n!define MUI_UNICON \"yacas.ico\"\n\n!insertmacro MUI_PAGE_WELCOME\n!insertmacro MUI_PAGE_LICENSE \"COPYING\"\n!insertmacro MUI_PAGE_DIRECTORY\n!insertmacro MUI_PAGE_COMPONENTS\n!insertmacro MUI_PAGE_INSTFILES\n!insertmacro MUI_PAGE_FINISH\n\n!insertmacro MUI_UNPAGE_WELCOME\n!insertmacro MUI_UNPAGE_CONFIRM\n!insertmacro MUI_UNPAGE_INSTFILES\n!insertmacro MUI_UNPAGE_FINISH\n\n!insertmacro MUI_LANGUAGE \"English\"\n\nSection \"Yacas\"\n    SectionIn RO\n\n    StrCmp $UNINSTALL_OLD_VERSION \"\" yacas.files\n    ExecWait '$UNINSTALL_OLD_VERSION'\n\nyacas.files:\n\n    SetOutPath $INSTDIR\n    File /r bin\n\n    SetOutPath $INSTDIR\\share\\yacas\n    File yacas.ico\n    File /r share\\yacas\\scripts\n    File /r share\\yacas\\tests\n\n    WriteUninstaller $INSTDIR\\Uninstall.exe\n\n    WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"DisplayName\" \"${APPNAME} - ${DESCRIPTION}\"\n    WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"UninstallString\" \"$\\\"$INSTDIR\\Uninstall.exe$\\\"\"\n    WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"QuietUninstallString\" \"$\\\"$INSTDIR\\Uninstall.exe$\\\" /S\"\n    WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"InstallLocation\" \"$INSTDIR\"\n    WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"DisplayIcon\" \"$INSTDIR\\share\\yacas\\yacas.ico\"\n    WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"Publisher\" \"Yacas Team\"\n    WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"HelpLink\" \"${HELPURL}\"\n    #WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"URLUpdateInfo\" \"${UPDATEURL}\"\n    #WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"URLInfoAbout\" \"${ABOUTURL}\"\n    WriteRegStr HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"DisplayVersion\" \"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONPATCH}\"\n    WriteRegDWORD HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"VersionMajor\" ${VERSIONMAJOR}\n    WriteRegDWORD HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"VersionMinor\" ${VERSIONMINOR}\n    WriteRegDWORD HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"NoModify\" 1\n    WriteRegDWORD HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"NoRepair\" 1\n    WriteRegDWORD HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\" \"EstimatedSize\" ${INSTALLSIZE}\nSectionEnd\n\nSection \"Documentation\"\n    SetOutPath $INSTDIR\\share\\yacas\n    File /r share\\yacas\\documentation\nSectionEnd\n\nSection \"Development\"\n    SetOutPath $INSTDIR\n    File /r lib\n    File /r include\nSectionEnd\n\nSection \"Uninstall\"\n    Delete $INSTDIR\\Uninstall.exe\n    RMDir /r /REBOOTOK $INSTDIR\n    DeleteRegKey HKLM \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\"\nSectionEnd\n"
  },
  {
    "path": "cyacas/packaging/pkg/distribution.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<installer-gui-script minSpecVersion=\"1\">\n    <title>Yacas</title>\n    <readme file=\"readme.html\" mime-type=\"text/html\"/>\n    <license file=\"license.txt\" mime-type=\"text/plain\"/>\n    <options require-scripts=\"false\"/>\n    <choices-outline>\n        <line choice=\"yacas-cli\"/>\n        <line choice=\"yacas-gui\"/>\n    </choices-outline>\n\n    <choice id=\"yacas-cli\" title=\"yacas (text console)\">\n        <pkg-ref id=\"yacas-cli\"/>\n    </choice>\n\n    <choice id=\"yacas-gui\" title=\"yacas-gui.app (GUI)\">\n        <pkg-ref id=\"yacas-gui\"/>\n    </choice>\n\n    <pkg-ref id=\"yacas-cli\" version=\"1.9.2\" onConclusion=\"none\">yacas-cli.pkg</pkg-ref>\n    <pkg-ref id=\"yacas-gui\" version=\"1.9.2\" onConclusion=\"none\">yacas-gui.pkg</pkg-ref>\n\n</installer-gui-script>\n"
  },
  {
    "path": "cyacas/packaging/pkg/license.txt",
    "content": "                  GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 2.1, February 1999\n\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n[This is the first released version of the Lesser GPL.  It also counts\n as the successor of the GNU Library Public License, version 2, hence\n the version number 2.1.]\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicenses are intended to guarantee your freedom to share and change\nfree software--to make sure the software is free for all its users.\n\n  This license, the Lesser General Public License, applies to some\nspecially designated software packages--typically libraries--of the\nFree Software Foundation and other authors who decide to use it.  You\ncan use it too, but we suggest you first think carefully about whether\nthis license or the ordinary General Public License is the better\nstrategy to use in any particular case, based on the explanations below.\n\n  When we speak of free software, we are referring to freedom of use,\nnot price.  Our General Public Licenses are designed to make sure that\nyou have the freedom to distribute copies of free software (and charge\nfor this service if you wish); that you receive source code or can get\nit if you want it; that you can change the software and use pieces of\nit in new free programs; and that you are informed that you can do\nthese things.\n\n  To protect your rights, we need to make restrictions that forbid\ndistributors to deny you these rights or to ask you to surrender these\nrights.  These restrictions translate to certain responsibilities for\nyou if you distribute copies of the library or if you modify it.\n\n  For example, if you distribute copies of the library, whether gratis\nor for a fee, you must give the recipients all the rights that we gave\nyou.  You must make sure that they, too, receive or can get the source\ncode.  If you link other code with the library, you must provide\ncomplete object files to the recipients, so that they can relink them\nwith the library after making changes to the library and recompiling\nit.  And you must show them these terms so they know their rights.\n\n  We protect your rights with a two-step method: (1) we copyright the\nlibrary, and (2) we offer you this license, which gives you legal\npermission to copy, distribute and/or modify the library.\n\n  To protect each distributor, we want to make it very clear that\nthere is no warranty for the free library.  Also, if the library is\nmodified by someone else and passed on, the recipients should know\nthat what they have is not the original version, so that the original\nauthor's reputation will not be affected by problems that might be\nintroduced by others.\n\f\n  Finally, software patents pose a constant threat to the existence of\nany free program.  We wish to make sure that a company cannot\neffectively restrict the users of a free program by obtaining a\nrestrictive license from a patent holder.  Therefore, we insist that\nany patent license obtained for a version of the library must be\nconsistent with the full freedom of use specified in this license.\n\n  Most GNU software, including some libraries, is covered by the\nordinary GNU General Public License.  This license, the GNU Lesser\nGeneral Public License, applies to certain designated libraries, and\nis quite different from the ordinary General Public License.  We use\nthis license for certain libraries in order to permit linking those\nlibraries into non-free programs.\n\n  When a program is linked with a library, whether statically or using\na shared library, the combination of the two is legally speaking a\ncombined work, a derivative of the original library.  The ordinary\nGeneral Public License therefore permits such linking only if the\nentire combination fits its criteria of freedom.  The Lesser General\nPublic License permits more lax criteria for linking other code with\nthe library.\n\n  We call this license the \"Lesser\" General Public License because it\ndoes Less to protect the user's freedom than the ordinary General\nPublic License.  It also provides other free software developers Less\nof an advantage over competing non-free programs.  These disadvantages\nare the reason we use the ordinary General Public License for many\nlibraries.  However, the Lesser license provides advantages in certain\nspecial circumstances.\n\n  For example, on rare occasions, there may be a special need to\nencourage the widest possible use of a certain library, so that it becomes\na de-facto standard.  To achieve this, non-free programs must be\nallowed to use the library.  A more frequent case is that a free\nlibrary does the same job as widely used non-free libraries.  In this\ncase, there is little to gain by limiting the free library to free\nsoftware only, so we use the Lesser General Public License.\n\n  In other cases, permission to use a particular library in non-free\nprograms enables a greater number of people to use a large body of\nfree software.  For example, permission to use the GNU C Library in\nnon-free programs enables many more people to use the whole GNU\noperating system, as well as its variant, the GNU/Linux operating\nsystem.\n\n  Although the Lesser General Public License is Less protective of the\nusers' freedom, it does ensure that the user of a program that is\nlinked with the Library has the freedom and the wherewithal to run\nthat program using a modified version of the Library.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.  Pay close attention to the difference between a\n\"work based on the library\" and a \"work that uses the library\".  The\nformer contains code derived from the library, whereas the latter must\nbe combined with the library in order to run.\n\f\n                  GNU LESSER GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License Agreement applies to any software library or other\nprogram which contains a notice placed by the copyright holder or\nother authorized party saying it may be distributed under the terms of\nthis Lesser General Public License (also called \"this License\").\nEach licensee is addressed as \"you\".\n\n  A \"library\" means a collection of software functions and/or data\nprepared so as to be conveniently linked with application programs\n(which use some of those functions and data) to form executables.\n\n  The \"Library\", below, refers to any such software library or work\nwhich has been distributed under these terms.  A \"work based on the\nLibrary\" means either the Library or any derivative work under\ncopyright law: that is to say, a work containing the Library or a\nportion of it, either verbatim or with modifications and/or translated\nstraightforwardly into another language.  (Hereinafter, translation is\nincluded without limitation in the term \"modification\".)\n\n  \"Source code\" for a work means the preferred form of the work for\nmaking modifications to it.  For a library, complete source code means\nall the source code for all modules it contains, plus any associated\ninterface definition files, plus the scripts used to control compilation\nand installation of the library.\n\n  Activities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning a program using the Library is not restricted, and output from\nsuch a program is covered only if its contents constitute a work based\non the Library (independent of the use of the Library in a tool for\nwriting it).  Whether that is true depends on what the Library does\nand what the program that uses the Library does.\n\n  1. You may copy and distribute verbatim copies of the Library's\ncomplete source code as you receive it, in any medium, provided that\nyou conspicuously and appropriately publish on each copy an\nappropriate copyright notice and disclaimer of warranty; keep intact\nall the notices that refer to this License and to the absence of any\nwarranty; and distribute a copy of this License along with the\nLibrary.\n\n  You may charge a fee for the physical act of transferring a copy,\nand you may at your option offer warranty protection in exchange for a\nfee.\n\f\n  2. You may modify your copy or copies of the Library or any portion\nof it, thus forming a work based on the Library, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) The modified work must itself be a software library.\n\n    b) You must cause the files modified to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    c) You must cause the whole of the work to be licensed at no\n    charge to all third parties under the terms of this License.\n\n    d) If a facility in the modified Library refers to a function or a\n    table of data to be supplied by an application program that uses\n    the facility, other than as an argument passed when the facility\n    is invoked, then you must make a good faith effort to ensure that,\n    in the event an application does not supply such function or\n    table, the facility still operates, and performs whatever part of\n    its purpose remains meaningful.\n\n    (For example, a function in a library to compute square roots has\n    a purpose that is entirely well-defined independent of the\n    application.  Therefore, Subsection 2d requires that any\n    application-supplied function or table used by this function must\n    be optional: if the application does not supply it, the square\n    root function must still compute square roots.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Library,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Library, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote\nit.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Library.\n\nIn addition, mere aggregation of another work not based on the Library\nwith the Library (or with a work based on the Library) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may opt to apply the terms of the ordinary GNU General Public\nLicense instead of this License to a given copy of the Library.  To do\nthis, you must alter all the notices that refer to this License, so\nthat they refer to the ordinary GNU General Public License, version 2,\ninstead of to this License.  (If a newer version than version 2 of the\nordinary GNU General Public License has appeared, then you can specify\nthat version instead if you wish.)  Do not make any other change in\nthese notices.\n\f\n  Once this change is made in a given copy, it is irreversible for\nthat copy, so the ordinary GNU General Public License applies to all\nsubsequent copies and derivative works made from that copy.\n\n  This option is useful when you wish to copy part of the code of\nthe Library into a program that is not a library.\n\n  4. You may copy and distribute the Library (or a portion or\nderivative of it, under Section 2) in object code or executable form\nunder the terms of Sections 1 and 2 above provided that you accompany\nit with the complete corresponding machine-readable source code, which\nmust be distributed under the terms of Sections 1 and 2 above on a\nmedium customarily used for software interchange.\n\n  If distribution of object code is made by offering access to copy\nfrom a designated place, then offering equivalent access to copy the\nsource code from the same place satisfies the requirement to\ndistribute the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  5. A program that contains no derivative of any portion of the\nLibrary, but is designed to work with the Library by being compiled or\nlinked with it, is called a \"work that uses the Library\".  Such a\nwork, in isolation, is not a derivative work of the Library, and\ntherefore falls outside the scope of this License.\n\n  However, linking a \"work that uses the Library\" with the Library\ncreates an executable that is a derivative of the Library (because it\ncontains portions of the Library), rather than a \"work that uses the\nlibrary\".  The executable is therefore covered by this License.\nSection 6 states terms for distribution of such executables.\n\n  When a \"work that uses the Library\" uses material from a header file\nthat is part of the Library, the object code for the work may be a\nderivative work of the Library even though the source code is not.\nWhether this is true is especially significant if the work can be\nlinked without the Library, or if the work is itself a library.  The\nthreshold for this to be true is not precisely defined by law.\n\n  If such an object file uses only numerical parameters, data\nstructure layouts and accessors, and small macros and small inline\nfunctions (ten lines or less in length), then the use of the object\nfile is unrestricted, regardless of whether it is legally a derivative\nwork.  (Executables containing this object code plus portions of the\nLibrary will still fall under Section 6.)\n\n  Otherwise, if the work is a derivative of the Library, you may\ndistribute the object code for the work under the terms of Section 6.\nAny executables containing that work also fall under Section 6,\nwhether or not they are linked directly with the Library itself.\n\f\n  6. As an exception to the Sections above, you may also combine or\nlink a \"work that uses the Library\" with the Library to produce a\nwork containing portions of the Library, and distribute that work\nunder terms of your choice, provided that the terms permit\nmodification of the work for the customer's own use and reverse\nengineering for debugging such modifications.\n\n  You must give prominent notice with each copy of the work that the\nLibrary is used in it and that the Library and its use are covered by\nthis License.  You must supply a copy of this License.  If the work\nduring execution displays copyright notices, you must include the\ncopyright notice for the Library among them, as well as a reference\ndirecting the user to the copy of this License.  Also, you must do one\nof these things:\n\n    a) Accompany the work with the complete corresponding\n    machine-readable source code for the Library including whatever\n    changes were used in the work (which must be distributed under\n    Sections 1 and 2 above); and, if the work is an executable linked\n    with the Library, with the complete machine-readable \"work that\n    uses the Library\", as object code and/or source code, so that the\n    user can modify the Library and then relink to produce a modified\n    executable containing the modified Library.  (It is understood\n    that the user who changes the contents of definitions files in the\n    Library will not necessarily be able to recompile the application\n    to use the modified definitions.)\n\n    b) Use a suitable shared library mechanism for linking with the\n    Library.  A suitable mechanism is one that (1) uses at run time a\n    copy of the library already present on the user's computer system,\n    rather than copying library functions into the executable, and (2)\n    will operate properly with a modified version of the library, if\n    the user installs one, as long as the modified version is\n    interface-compatible with the version that the work was made with.\n\n    c) Accompany the work with a written offer, valid for at\n    least three years, to give the same user the materials\n    specified in Subsection 6a, above, for a charge no more\n    than the cost of performing this distribution.\n\n    d) If distribution of the work is made by offering access to copy\n    from a designated place, offer equivalent access to copy the above\n    specified materials from the same place.\n\n    e) Verify that the user has already received a copy of these\n    materials or that you have already sent this user a copy.\n\n  For an executable, the required form of the \"work that uses the\nLibrary\" must include any data and utility programs needed for\nreproducing the executable from it.  However, as a special exception,\nthe materials to be distributed need not include anything that is\nnormally distributed (in either source or binary form) with the major\ncomponents (compiler, kernel, and so on) of the operating system on\nwhich the executable runs, unless that component itself accompanies\nthe executable.\n\n  It may happen that this requirement contradicts the license\nrestrictions of other proprietary libraries that do not normally\naccompany the operating system.  Such a contradiction means you cannot\nuse both them and the Library together in an executable that you\ndistribute.\n\f\n  7. You may place library facilities that are a work based on the\nLibrary side-by-side in a single library together with other library\nfacilities not covered by this License, and distribute such a combined\nlibrary, provided that the separate distribution of the work based on\nthe Library and of the other library facilities is otherwise\npermitted, and provided that you do these two things:\n\n    a) Accompany the combined library with a copy of the same work\n    based on the Library, uncombined with any other library\n    facilities.  This must be distributed under the terms of the\n    Sections above.\n\n    b) Give prominent notice with the combined library of the fact\n    that part of it is a work based on the Library, and explaining\n    where to find the accompanying uncombined form of the same work.\n\n  8. You may not copy, modify, sublicense, link with, or distribute\nthe Library except as expressly provided under this License.  Any\nattempt otherwise to copy, modify, sublicense, link with, or\ndistribute the Library is void, and will automatically terminate your\nrights under this License.  However, parties who have received copies,\nor rights, from you under this License will not have their licenses\nterminated so long as such parties remain in full compliance.\n\n  9. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Library or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Library (or any work based on the\nLibrary), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Library or works based on it.\n\n  10. Each time you redistribute the Library (or any work based on the\nLibrary), the recipient automatically receives a license from the\noriginal licensor to copy, distribute, link with or modify the Library\nsubject to these terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties with\nthis License.\n\f\n  11. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Library at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Library by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Library.\n\nIf any portion of this section is held invalid or unenforceable under any\nparticular circumstance, the balance of the section is intended to apply,\nand the section as a whole is intended to apply in other circumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  12. If the distribution and/or use of the Library is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Library under this License may add\nan explicit geographical distribution limitation excluding those countries,\nso that distribution is permitted only in or among countries not thus\nexcluded.  In such case, this License incorporates the limitation as if\nwritten in the body of this License.\n\n  13. The Free Software Foundation may publish revised and/or new\nversions of the Lesser General Public License from time to time.\nSuch new versions will be similar in spirit to the present version,\nbut may differ in detail to address new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Library\nspecifies a version number of this License which applies to it and\n\"any later version\", you have the option of following the terms and\nconditions either of that version or of any later version published by\nthe Free Software Foundation.  If the Library does not specify a\nlicense version number, you may choose any version ever published by\nthe Free Software Foundation.\n\f\n  14. If you wish to incorporate parts of the Library into other free\nprograms whose distribution conditions are incompatible with these,\nwrite to the author to ask for permission.  For software which is\ncopyrighted by the Free Software Foundation, write to the Free\nSoftware Foundation; we sometimes make exceptions for this.  Our\ndecision will be guided by the two goals of preserving the free status\nof all derivatives of our free software and of promoting the sharing\nand reuse of software generally.\n\n                            NO WARRANTY\n\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\nDAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\f\n           How to Apply These Terms to Your New Libraries\n\n  If you develop a new library, and you want it to be of the greatest\npossible use to the public, we recommend making it free software that\neveryone can redistribute and change.  You can do so by permitting\nredistribution under these terms (or, alternatively, under the terms of the\nordinary General Public License).\n\n  To apply these terms, attach the following notices to the library.  It is\nsafest to attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least the\n\"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the library's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This library is free software; you can redistribute it and/or\n    modify it under the terms of the GNU Lesser General Public\n    License as published by the Free Software Foundation; either\n    version 2.1 of the License, or (at your option) any later version.\n\n    This library is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n    Lesser General Public License for more details.\n\n    You should have received a copy of the GNU Lesser General Public\n    License along with this library; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n\nAlso add information on how to contact you by electronic and paper mail.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\n\n  <signature of Ty Coon>, 1 April 1990\n  Ty Coon, President of Vice\n\nThat's all there is to it!\n"
  },
  {
    "path": "cyacas/packaging/pkg/readme.html",
    "content": "<html>\n    <body>\n        <p>\n            Yacas (Yet Another Computer Algebra System) is a small and highly flexible general-purpose\n            Computer Algebra System (CAS). The syntax uses an infix-operator grammar parser. The\n            distribution contains a small library of mathematical functions, but its real strength\n            is in the language in which you can easily write your own symbolic manipulation algorithms.\n            The core engine supports arbitrary precision arithmetic and is able to execute symbolic\n            manipulations on various mathematical objects by following user-defined rules. For detailed\n            information on yacas features and usage, see <a href=\"http://www.yacas.org\" class=\"uri\">\n                http://www.yacas.org</a>.\n        </p>\n    </body>\n</html>\n"
  },
  {
    "path": "cyacas/packaging/rpm/yacas.spec",
    "content": "# -*- rpm-spec -*-\n#\n# This file and all modifications and additions to the pristine\n# package are under the same license as the package itself.\n#\n# norootforbuild\n#\n\nName:           yacas\nVersion:        1.9.2\nRelease:        1%{?dist}\nSummary:        Easy to use, general purpose computer algebra system\n%if 0%{?suse_version}\nGroup:          Productivity/Scientific/Math\n%else\nGroup:          Applications/Engineering\n%endif\n%if 0%{?suse_version}\nLicense:        LGPL-2.0+\n%else\nLicense:        LGPLv2+\n%endif\nURL:            http://www.yacas.org\nSource:         v%{version}.tar.gz\n%if 0%{?suse_version}\nBuildRequires:  cmake gcc-c++ python-sphinx python-sphinx_rtd_theme libqt5-qtsvg-devel libQt5WebKitWidgets-devel libQt5PrintSupport-devel\n%else\nBuildRequires:  cmake gcc-c++ python3-sphinx python3-sphinx_rtd_theme qt5-qtwebengine-devel qt5-qtsvg-devel\n%endif\n%description\nYacas is an easy to use, general purpose Computer Algebra System, a\nprogram for symbolic manipulation of mathematical expressions. It uses\nits own programming language designed for symbolic as well as\narbitrary-precision numerical computations. The system has a library\nof scripts that implement many of the symbolic algebra operations; new\nalgorithms can be easily added to the library. Yacas comes with\nextensive documentation covering the scripting language, the\nfunctionality that is already implemented in the system and the\nalgorithms used.\n%prep\n%setup -q\n%build\ncmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_DOCS=ON -DENABLE_CYACAS_KERNEL=OFF -DCMAKE_INSTALL_PREFIX=%{_prefix} .\n%{__make} %{?_smp_mflags}\n%check\n%{__make} test\n%install\n%{__make} DESTDIR=%{buildroot} install\n%clean\nrm -rf %{buildroot}\n\n%package console\nSummary:        Yacas text console\n%if 0%{?suse_version}\nGroup:          Productivity/Scientific/Math\n%else\nGroup:          Applications/Engineering\n%endif\nRequires: yacas-common = %{version}, yacas-doc = %{version}\n%description console\nYacas is an easy to use, general purpose Computer Algebra System, a\nprogram for symbolic manipulation of mathematical expressions. It\nuses its own programming language designed for symbolic as well as\narbitrary-precision numerical computations. The system has a library\nof scripts that implement many of the symbolic algebra operations;\nnew algorithms can be easily added to the library. Yacas comes with\nextensive documentation covering the scripting language, the\nfunctionality that is already implemented in the system and the\nalgorithms used.\n%files console\n%defattr(-,root,root,-)\n%{_bindir}/yacas\n\n%package common\nSummary:        Yacas common files\n%if 0%{?suse_version}\nGroup:          Productivity/Scientific/Math\n%else\nGroup:          Applications/Engineering\n%endif\n%description common\nCommon files for yacas and yacas GUI. Yacas is an easy to use, general\npurpose Computer Algebra System, a program for symbolic manipulation\nof mathematical expressions. It uses its own programming language\ndesigned for symbolic as well as arbitrary-precision numerical\ncomputations. The system has a library of scripts that implement\nmany of the symbolic algebra operations; new algorithms can be easily\nadded to the library. Yacas comes with extensive documentation\ncovering the scripting language, the functionality that is already\nimplemented in the system and the algorithms used.\n%files common\n%dir %{_datarootdir}/yacas\n%dir %{_datarootdir}/yacas/scripts\n%{_datarootdir}/yacas/scripts/*\n%dir %{_datarootdir}/yacas/tests\n%{_datarootdir}/yacas/tests/*\n\n%package gui\nSummary:        Yacas GUI\n%if 0%{?suse_version}\nGroup:          Productivity/Scientific/Math\n%else\nGroup:          Applications/Engineering\n%endif\nRequires: yacas-common = %{version}, yacas-doc = %{version}\n%description gui\nGraphical User Interface for yacas. Yacas is an easy to use, general\npurpose Computer Algebra System, a program for symbolic manipulation\nof mathematical expressions. It uses its own programming language\ndesigned for symbolic as well as arbitrary-precision numerical\ncomputations. The system has a library of scripts that implement many\nof the symbolic algebra operations; new algorithms can be easily\nadded to the library. Yacas comes with extensive documentation\ncovering the scripting language, the functionality that is already\nimplemented in the system and the algorithms used.\n%files gui\n%defattr(-,root,root,-)\n%{_bindir}/yacas-gui\n%dir %{_datarootdir}/yacas/resources\n%{_datarootdir}/yacas/resources/*\n%dir %{_datarootdir}/icons\n%{_datarootdir}/icons/*\n%dir %{_datarootdir}/pixmaps\n%{_datarootdir}/pixmaps/*\n%{_datarootdir}/applications/yacas-gui.desktop\n\n%package doc\nSummary:        Yacas documentation\n%if 0%{?suse_version}\nGroup:          Documentation/HTML\n%else\nGroup:          Documentation\n%endif\n%description doc\nYacas documentation. Yacas is an easy to use, general purpose Computer\nAlgebra System, a program for symbolic manipulation of mathematical\nexpressions. It uses its own programming language designed for\nsymbolic as well as arbitrary-precision numerical computations. The\nsystem has a library of scripts that implement many of the symbolic\nalgebra operations; new algorithms can be easily added to the\nlibrary. Yacas comes with extensive documentation covering the\nscripting language, the functionality that is already implemented in\nthe system and the algorithms used.\n%files doc\n%defattr(-,root,root,-)\n%{_mandir}/man1/yacas.1.gz\n%dir %{_docdir}/yacas\n%dir %{_docdir}/yacas/singlehtml\n%docdir %{_docdir}/yacas\n%{_docdir}/yacas/singlehtml/*\n\n%package devel\nSummary:        Yacas development files\n%if 0%{?suse_version}\nGroup:          Development/Libraries/C and C++\n%else\nGroup:          Development/Libraries\n%endif\nRequires: yacas-common = %{version}\n%description devel\nHeader files and libraries necessary for yacas development.  Yacas is\nan easy to use, general purpose Computer Algebra System, a program for\nsymbolic manipulation of mathematical expressions. It uses its own\nprogramming language designed for symbolic as well as\narbitrary-precision numerical computations. The system has a library\nof scripts that implement many of the symbolic algebra operations; new\nalgorithms can be easily added to the library. Yacas comes with\nextensive documentation covering the scripting language, the\nfunctionality that is already implemented in the system and the\nalgorithms used.\n%files devel\n%defattr(-,root,root,-)\n%{_libdir}/libyacas*.a\n%dir %{_includedir}/yacas\n%{_includedir}/yacas/*\n\n%changelog\n* Tue Aug  4 2020 Grzegorz Mazur <teoretyk@gmail.com> 1.9.2-1\n- New upstream release\n* Wed Jul  1 2020 Grzegorz Mazur <teoretyk@gmail.com> 1.9.1-1\n- New upstream release\n* Thu Feb 15 2018 Grzegorz Mazur <teoretyk@gmail.com> 1.8.0-1\n- Changes are none, there is only the now (Ayal Pinkus)\n"
  },
  {
    "path": "cyacas/packaging/snap/snap/gui/yacas.gui.desktop",
    "content": "[Desktop Entry]\nName=yacas-gui\nComment=Yacas GUI\nExec=yacas.gui\nIcon=/snap/yacas/current/meta/gui/yacas-gui.png\nTerminal=false\nType=Application\nCategories=Education;Science;Math;\n"
  },
  {
    "path": "cyacas/packaging/snap/snapcraft.yaml",
    "content": "name: yacas\nversion: 1.9.2-snap1\ngrade: stable\nbase: core18\nsummary: Yet Another Computer Algebra System\ndescription: |\n  Yacas is an easy to use, general purpose Computer Algebra System, a\n  program for symbolic manipulation of mathematical expressions. It\n  uses its own programming language designed for symbolic as well as\n  arbitrary-precision numerical computations. The system has a library\n  of scripts that implement many of the symbolic algebra operations;\n  new algorithms can be easily added to the library.\n\nconfinement: strict\n\napps:\n  yacas:\n    command: yacas\n    plugs: [home]\n  gui:\n    command: desktop-launch yacas-gui\n    plugs: [home, x11, wayland, desktop, desktop-legacy, opengl, browser-support]\n    environment:\n      DISABLE_WAYLAND: 1\n      QTWEBENGINEPROCESS_PATH: $RUNTIME/usr/lib/$ARCH/qt5/libexec/QtWebEngineProcess\n      QT_QPA_PLATFORMTHEME: gtk3\n\nplugs:\n  gtk-3-themes:\n    interface: content\n    target: $SNAP/data-dir/themes\n    default-provider: gtk-common-themes\n  icon-themes:\n    interface: content\n    target: $SNAP/data-dir/icons\n    default-provider: gtk-common-themes\n  sound-themes:\n    interface: content\n    target: $SNAP/data-dir/sounds\n    default-provider: gtk-common-themes\n\nbuild-packages:\n  - g++\n  - build-essential\n  - python3-sphinx\n  - python3-sphinx-rtd-theme\n  - qtbase5-dev\n  - libqt5webkit5-dev\n  - libssl-dev\n  - libboost-date-time-dev\n  - libboost-program-options-dev\n  - libjsoncpp-dev\n  - dpkg-dev\n  - git-lfs\n\nparts:\n  # Remote part for support of various desktop technologies\n  # Refer: https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml\n  desktop-qt5:\n    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git\n    source-depth: 1\n    source-subdir: qt\n\n    plugin: make\n    make-parameters: [\"FLAVOR=qt5\"]\n    stage-packages:\n    - libxkbcommon0\n    - ttf-ubuntu-font-family\n    - dmz-cursor-theme\n    - light-themes\n    - adwaita-icon-theme\n    - gnome-themes-standard\n    - shared-mime-info\n    - libqt5gui5\n    - libgdk-pixbuf2.0-0\n    - libqt5svg5 # for loading icon themes which are svg\n    - locales-all\n    - xdg-user-dirs\n    - qt5-gtk-platformtheme\n  yacas:\n    source: https://github.com/grzegorzmazur/yacas/archive/v1.9.2.tar.gz\n    plugin: cmake\n    configflags:\n      - -DCMAKE_BUILD_TYPE=Release\n      - -DENABLE_DOCS=On\n    after: [desktop-qt5]\n    build-packages:\n      - libqt5svg5-dev\n      - qtwebengine5-dev\n      - libjsoncpp-dev\n      - python3-sphinxcontrib.bibtex\n    stage-packages:\n      - qtwayland5\n      - libqt5webengine5\n      - libqt5webenginewidgets5\n      - libqt5printsupport5\n      - libqt5quickwidgets5\n      - libjsoncpp1\n\nlayout:\n    /usr/share/qt5:\n        bind: $SNAP/usr/share/qt5"
  },
  {
    "path": "cyacas/xeus-yacas/CMakeLists.txt",
    "content": "find_package(xeus REQUIRED)\nfind_package(xeus-zmq REQUIRED)\nfind_package(Threads)\n\nfind_package (Boost REQUIRED filesystem)\n\nadd_executable(xeus-yacas src/main.cpp src/interpreter.cpp)\ntarget_include_directories(xeus-yacas PRIVATE include)\ntarget_link_libraries(xeus-yacas PRIVATE xeus-zmq-static Threads::Threads Boost::filesystem libyacas)\n\ninstall (TARGETS xeus-yacas RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT app)\n"
  },
  {
    "path": "cyacas/xeus-yacas/include/xeus-yacas/xeus-yacas.hpp",
    "content": "#ifndef XEUS_YACAS_HPP\n#define XEUS_YACAS_HPP\n\n#include <memory>\n#include <sstream>\n#include <string>\n\n#include <xeus/xinterpreter.hpp>\n\n#include \"yacas/yacas.h\"\n\nclass YacasInterpreter : public xeus::xinterpreter {\npublic:\n    YacasInterpreter(const std::string& scripts_path);\n    virtual ~YacasInterpreter() = default;\n\nprivate:\n    void configure_impl() override;\n\n    nl::json execute_request_impl(int execution_counter,\n                                  const std::string& code,\n                                  bool silent,\n                                  bool store_history,\n                                  nl::json user_expressions,\n                                  bool allow_stdin) override;\n\n    nl::json complete_request_impl(const std::string& code,\n                                   int cursor_pos) override;\n\n    nl::json inspect_request_impl(const std::string& code,\n                                  int cursor_pos,\n                                  int detail_level) override;\n\n    nl::json is_complete_request_impl(const std::string& code) override;\n\n    nl::json kernel_info_request_impl() override;\n\n    void shutdown_request_impl() override;\n\n    std::string m_scripts_path;\n    std::unique_ptr<std::ostringstream> m_side_effects;\n    std::unique_ptr<CYacas> m_yacas;\n};\n\n#endif"
  },
  {
    "path": "cyacas/xeus-yacas/src/interpreter.cpp",
    "content": "#include \"xeus-yacas/xeus-yacas.hpp\"\n\n#include <regex>\n#include <set>\n\n#include <xeus/xhelper.hpp>\n#include <xtl/xbase64.hpp>\n\nYacasInterpreter::YacasInterpreter(const std::string& scripts_path) :\n    m_scripts_path(scripts_path)\n{\n}\n\nvoid YacasInterpreter::configure_impl()\n{\n    m_side_effects = std::make_unique<std::ostringstream>();\n    m_yacas = std::make_unique<CYacas>(*m_side_effects.get());\n\n    m_yacas->Evaluate(std::string(\"DefaultDirectory(\\\"\") + m_scripts_path +\n                      std::string(\"\\\");\"));\n    m_yacas->Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n    m_yacas->Evaluate(\"Plot2D'outputs();\");\n    m_yacas->Evaluate(\"UnProtect(Plot2D'outputs);\");\n    m_yacas->Evaluate(\"Plot2D'outputs() := {{\\\"default\\\", \\\"png\\\"}, {\\\"png\\\", \"\n                      \"\\\"Plot2D'png\\\"}}\");\n    m_yacas->Evaluate(\"Protect(Plot2D'outputs);\");\n    m_yacas->Evaluate(\"Plot3DS'outputs();\");\n    m_yacas->Evaluate(\"UnProtect(Plot3DS'outputs);\");\n    m_yacas->Evaluate(\"Plot3DS'outputs() := {{\\\"default\\\", \\\"png\\\"}, {\\\"png\\\", \"\n                      \"\\\"Plot3DS'png\\\"}}\");\n    m_yacas->Evaluate(\"Protect(Plot3DS'outputs);\");\n}\n\nnl::json YacasInterpreter::execute_request_impl(int execution_counter,\n                                                const std::string& code,\n                                                bool silent,\n                                                bool store_history,\n                                                nl::json user_expressions,\n                                                bool allow_stdin)\n{\n    m_side_effects->str(\"\");\n    m_side_effects->clear();\n\n    const std::string code_block{'[' + code + (code.back() != ';' ? \";\" : \"\") +\n                                 ']'};\n    m_yacas->Evaluate(code_block);\n\n    if (m_yacas->IsError()) {\n        publish_execution_error(\"Error\", m_yacas->Error(), {});\n        // publish_execution_error() does not print the error message to stderr,\n        // so we do it ourselves\n        publish_stream(\"stderr\", m_yacas->Error());\n        const nl::json error{{\"status\", \"error\"},\n                             {\"ename\", \"Error\"},\n                             {\"evalue\", m_yacas->Error()},\n                             {\"traceback\", nl::json::array()}};\n        return error;\n    } else {\n        std::string text_result = m_yacas->Result();\n        if (!text_result.empty() && text_result.back() == ';')\n            text_result.pop_back();\n\n        nl::json pub_data{{\"text/plain\", text_result}};\n\n        const std::string side_effects{m_side_effects->str()};\n\n        m_side_effects->clear();\n        m_side_effects->str(\"\");\n\n        if (!side_effects.empty())\n            publish_stream(\"stdout\", side_effects);\n\n        std::regex rx(\"File\\\\(\\\"([^\\\"]+)\\\", *\\\"([^\\\"]+)\\\"\\\\)\",\n                      std::regex_constants::ECMAScript);\n        std::smatch m;\n        if (std::regex_match(text_result, m, rx)) {\n            std::ifstream f(m[1], std::ios_base::in | std::ios_base::binary);\n            const std::string img{\n                std::istreambuf_iterator<char>(f),\n                std::istreambuf_iterator<char>()};\n            pub_data[m[2]] = xtl::base64encode(img);\n        } else {\n            m_yacas->Evaluate(std::string(\"TeXForm(Hold(\") + text_result +\n                              \"));\");\n            std::string tex_result = m_yacas->Result();\n            tex_result = tex_result.substr(1, tex_result.size() - 3);\n            pub_data[\"text/latex\"] = tex_result;\n        }\n\n        publish_execution_result(\n            execution_counter, std::move(pub_data), nl::json::object());\n\n        const nl::json result{{\"status\", \"ok\"},\n                              {\"execution_count\", execution_counter},\n                              {\"payload\", nl::json::array()},\n                              {\"user_expressions\", nl::json::object()}};\n        return result;\n    }\n}\n\nnl::json YacasInterpreter::complete_request_impl(const std::string& code,\n                                                 int cursor)\n{\n    int start = cursor;\n    while (start > 0 && std::isalpha(code[start - 1]))\n        start -= 1;\n    const std::string prefix = code.substr(start, cursor - start);\n\n    std::set<std::string> matches;\n\n    for (auto op : m_yacas->getDefEnv().getEnv().PreFix())\n        if (op.first->compare(0, prefix.length(), prefix) == 0)\n            matches.insert(*op.first);\n\n    for (auto op : m_yacas->getDefEnv().getEnv().InFix())\n        if (op.first->compare(0, prefix.length(), prefix) == 0)\n            matches.insert(*op.first);\n\n    for (auto op : m_yacas->getDefEnv().getEnv().PostFix())\n        if (op.first->compare(0, prefix.length(), prefix) == 0)\n            matches.insert(*op.first);\n\n    for (auto op : m_yacas->getDefEnv().getEnv().Bodied())\n        if (op.first->compare(0, prefix.length(), prefix) == 0)\n            matches.insert(*op.first);\n\n    for (auto op : m_yacas->getDefEnv().getEnv().CoreCommands())\n        if (op.first->compare(0, prefix.length(), prefix) == 0)\n            matches.insert(*op.first);\n\n    for (auto op : m_yacas->getDefEnv().getEnv().UserFunctions())\n        if (op.first->compare(0, prefix.length(), prefix) == 0)\n            matches.insert(*op.first);\n\n    return xeus::create_complete_reply(matches, start, cursor);\n}\n\nnl::json YacasInterpreter::inspect_request_impl(const std::string& code,\n                                                int cursor_pos,\n                                                int detail_level)\n{\n    return xeus::create_inspect_reply();\n}\n\nnl::json YacasInterpreter::is_complete_request_impl(const std::string& code)\n{\n    return xeus::create_is_complete_reply(\"unknown\");\n}\n\nnl::json YacasInterpreter::kernel_info_request_impl()\n{\n    const nl::json language_info{{\"file_extension\", \".ys\"},\n                                 {\"mimetype\", \"text/x-yacas\"},\n                                 {\"name\", \"yacas\"},\n                                 {\"version\", \"24.07\"},\n                                 {\"codemirror_mode\", {{\"name\", \"yacas\"}}}};\n\n    const nl::json help_links{\n        {{\"text\", \"Yacas Homepage\"}, {\"url\", \"http://www.yacas.org\"}},\n        {{\"text\", \"Yacas Documentation\"},\n         {\"url\", \"http://yacas.readthedocs.org\"}}};\n\n    const nl::json result{{\"implementation\", \"yacas_kernel\"},\n                          {\"implementation_version\", \"24.07\"},\n                          {\"language_info\", language_info},\n                          {\"banner\", \"yacas_kernel\"}, // YACAS_VERSION},\n                          {\"help_links\", help_links}};\n\n    return result;\n}\n\nvoid YacasInterpreter::shutdown_request_impl()\n{\n    m_yacas.reset();\n    m_side_effects.reset();\n}"
  },
  {
    "path": "cyacas/xeus-yacas/src/main.cpp",
    "content": "#include <cstdlib>\n#include <filesystem>\n#include <fstream>\n#include <iostream>\n#include <memory>\n\n#include <boost/dll/runtime_symbol_info.hpp>\n\n#include <xeus/xkernel.hpp>\n#include <xeus/xkernel_configuration.hpp>\n\n#include <xeus-zmq/xserver_shell_main.hpp>\n#include <xeus-zmq/xserver_zmq.hpp>\n#include <xeus-zmq/xzmq_context.hpp>\n\n#include \"xeus-yacas/xeus-yacas.hpp\"\n\nnamespace fs = std::filesystem;\n\nvoid print_help(const std::string& program_name)\n{\n    std::cout << \"Usage: \" << program_name << \" [connection_file]\\n\";\n}\n\nint install(const std::string& prefix)\n{\n    fs::create_directories(prefix + \"/jupyter/kernels/yacas\");\n    std::ofstream kernel_json_file{prefix + \"/jupyter/kernels/yacas/kernel.json\"};\n\n    if (kernel_json_file.is_open()) {\n        const nl::json kernel_json{{\"display_name\", \"yacas\"},\n                                   {\"argv\",\n                                    {boost::dll::program_location().c_str(),\n                                     \"-f\",\n                                     \"{connection_file}\"}},\n                                   {\"language\", \"yacas\"}};\n\n        kernel_json_file << kernel_json.dump(4) << std::endl;\n        return 0;\n    } else {\n        std::cerr << \"Error: could not write kernel.json\\n\";\n        return 1;\n    }\n}\n\nvoid run_kernel(const std::string& file_name)\n{\n    const xeus::xconfiguration config{xeus::load_configuration(file_name)};\n\n    const std::string scripts_path =\n        (boost::dll::program_location().parent_path().parent_path() /\n         \"share/yacas/scripts/\")\n            .string();\n\n    std::unique_ptr<xeus::xcontext> context{xeus::make_zmq_context()};\n\n    std::unique_ptr<YacasInterpreter> interpreter{\n        std::make_unique<YacasInterpreter>(scripts_path)};\n\n    xeus::xkernel kernel{config,\n                         xeus::get_user_name(),\n                         std::move(context),\n                         std::move(interpreter),\n                         xeus::make_xserver_shell_main};\n\n    kernel.start();\n}\n\nint main(int argc, char* argv[])\n{\n    if (argc > 1 &&\n        (std::string(argv[1]) == \"-h\" || std::string(argv[1]) == \"--help\")) {\n        print_help(argv[0]);\n        return 0;\n    }\n\n    if (argc > 1 && std::string(argv[1]) == \"install\") {\n        std::string prefix{\"/usr/share\"};\n\n        if (argc > 2) {\n            if (std::string(argv[2]) == \"--prefix\") {\n                if (argc > 3) {\n                    prefix = argv[3];\n                } else {\n                    std::cerr << \"Error: --prefix requires an argument\\n\";\n                    return 1;\n                }\n            } else if (std::string(argv[2]) == \"--user\") {\n                prefix = std::string(std::getenv(\"HOME\")) + \"/.local/share\";\n            } else {\n                std::cerr << \"Error: unknown argument \" << argv[2] << \"\\n\";\n                return 1;\n            }\n        }\n\n        return install(prefix);\n    }\n\n    const std::string file_name{(argc == 1) ? \"connection.json\" : argv[2]};\n\n    run_kernel(file_name);\n}\n"
  },
  {
    "path": "cyacas/yacas/CMakeLists.txt",
    "content": "include_directories(\n  \"include\"\n  )\n\n\nset (YACAS_COMMON_SOURCES src/yacasmain.cpp src/commandline.cpp src/stdcommandline.cpp)\nset (YACAS_COMMON_HEADERS include/commandline.h include/stdcommandline.h)\n\nset (YACAS_UNIX_SOURCES src/unixcommandline.cpp)\nset (YACAS_WIN32_SOURCES src/win32commandline.cpp res/yacas.rc)\n\nset (YACAS_UNIX_HEADERS include/unixcommandline.h)\nset (YACAS_WIN32_HEADERS include/win32commandline.h)\n\nif (UNIX)\n  set (YACAS_SOURCES ${YACAS_COMMON_SOURCES} ${YACAS_UNIX_SOURCES})\n  set (YACAS_HEADERS ${YACAS_COMMON_HEADERS} ${YACAS_UNIX_HEADERS})\nelse ()\n  set (YACAS_SOURCES ${YACAS_COMMON_SOURCES} ${YACAS_WIN32_SOURCES})\n  set (YACAS_HEADERS ${YACAS_COMMON_HEADERS} ${YACAS_WIN32_HEADERS})\nendif ()\n\nif (${CMAKE_SYSTEM_NAME} STREQUAL \"Emscripten\")\n    list (APPEND YACAS_SOURCES src/js_interface.cpp)\nendif ()\n\nadd_executable (yacas ${YACAS_SOURCES} ${YACAS_HEADERS})\nset_target_properties (yacas PROPERTIES  INTERPROCEDURAL_OPTIMIZATION ${IPO_SUPPORTED})\n\nif (APPLE)\n    set_target_properties(yacas PROPERTIES INSTALL_RPATH \"@loader_path/../lib\")\nendif()\n\ntarget_link_libraries (yacas libyacas)\n\nif (WIN32)\n  target_link_libraries (yacas wsock32 ws2_32 shlwapi)\nendif()\n\ninstall (TARGETS yacas RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT app)\n"
  },
  {
    "path": "cyacas/yacas/include/commandline.h",
    "content": "\n/** \\file commandline.h\n *  Implementation of a platform-independent command line with history.\n *\n *  The class CCommandLine has two roles:\n *  1) It has an outside interface, ReadLine(), that yields to the\n *     system until the user is finished entering an expression at\n *     the command line. The result can be found in iLine.\n *  2) It defines a mini-API needed to implement the command line.\n *     For each platform Yacas is meant to run on there should be a\n *     CCommandLine-derived class if this functionality is to be used.\n *\n */\n\n#ifndef YACAS_COMMANDLINE_H\n#define YACAS_COMMANDLINE_H\n\n#include <string>\n#include <vector>\n\n#include \"yacas/lispstring.h\"\n#include \"yacas/utf8.h\"\n\nenum ESpecialChars\n{\n    eDelete     = utf8::internal::CODE_POINT_MAX + 1,\n    eCtrlD,\n    eBackSpace,\n    eLeft,\n    eRight,\n    eUp,\n    eDown,\n    eHome,\n    eEnd,\n    eEnter,\n    eTab,\n    eEscape,\n    eKill\n};\n\n/**\n *  Implementation of a platform-independent command line with history.\n *\n *  The class CCommandLine has two roles:\n *  1) It has an outside interface, ReadLine(), that yields to the\n *     system until the user is finished entering an expression at\n *     the command line. The result can be found in iLine.\n *  2) It defines a mini-API needed to implement the command line.\n *     For each platform Yacas is meant to run on there should be a\n *     CCommandLine-derived class if this functionality is to be used.\n *\n *  The derived class is responsible for filling the history list,\n *  and for externalizing the history list to disk when the system\n *  shuts down.\n */\n\n/// \\class CConsoleHistory, implement history list the user can browse through.\nclass CConsoleHistory\n{\npublic:\n  CConsoleHistory();\n\n  void ResetHistoryPosition();\n  void AddLine(const std::string& s);\n  void Append(const std::string& s);\n  bool ArrowUp(std::string& s, unsigned c);\n  bool ArrowDown(std::string& s, unsigned c);\n  bool Complete(std::string& s, unsigned& c);\n  std::size_t NrLines();\n  const std::string& GetLine(std::size_t);\n\nprotected:\n  std::vector<std::string> iHistory;\n  std::size_t history;\n};\n\nclass CCommandLine {\npublic:\n  CCommandLine():\n      full_line_dirty(false),\n      history_unchanged(false)\n  {\n  }\n\n  virtual ~CCommandLine() = default;\n\n  /// Call this function if the user needs to enter an expression.\n  virtual void ReadLine(const std::string& prompt);\npublic: //platform stuff\n  /** return a key press, which is either an ascii value, or one\n   * of the values specified in ESpecialChars\n   */\n  virtual char32_t GetKey() = 0;\n  /// Go to the next line on the console (carriage return/line feed).\n  virtual void NewLine()   = 0;\n  /** Show the current line (in iSubLine), with the required prompt,\n   *  and the cursor position at cursor (starting from the prompt).\n   */\n  virtual void ShowLine(const std::string& prompt, unsigned cursor) = 0;\n  /// Pause for a short while. Used when matching brackets.\n  virtual void Pause() = 0;\n\n  /// Maximum number of history lines to be saved\n  virtual void MaxHistoryLinesSaved(std::size_t aNrLines);\n\nprotected:\n  virtual void ReadLineSub(const std::string& prompt);\nprivate:\n  void GetHistory(std::size_t aLine);\n  void ShowOpen(const std::string& prompt,\n                 char aOpen, char aClose,\n                 unsigned aCurPos);\nprotected:\n  bool full_line_dirty;\n  bool history_unchanged;\n\npublic:\n  std::string iLine;\n  std::string iSubLine;\n\n  CConsoleHistory iHistoryList;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/yacas/include/core_yacasmain.h",
    "content": "CORE_KERNEL_FUNCTION(\"Exit\",LispExit,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsExitRequested\",LispExitRequested,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"HistorySize\",LispHistorySize,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"IsPromptShown\",LispIsPromptShown,0,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"ReadCmdLineString\",LispReadCmdLineString,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"GetTime\",LispTime,1,YacasEvaluator::Macro | YacasEvaluator::Fixed)\nCORE_KERNEL_FUNCTION(\"FileSize\",LispFileSize,1,YacasEvaluator::Function | YacasEvaluator::Fixed)\n"
  },
  {
    "path": "cyacas/yacas/include/stdcommandline.h",
    "content": "#ifndef YACAS_STDCOMMANDLINE_H\n#define YACAS_STDCOMMANDLINE_H\n\n#include \"commandline.h\"\n/** Simple no-frills implementation of CCommandLine, using stdlibc-functions\n *  only, and no ansi characters. No history is supported either.\n */\nclass CStdCommandLine final: public CCommandLine\n{\npublic:\n    void ReadLine(const std::string& prompt) override;\npublic:\n    char32_t GetKey() override;\n    void NewLine() override;\n    void ShowLine(const std::string& prompt, unsigned cursor) override;\n    void Pause() override;\n};\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/yacas/include/unixcommandline.h",
    "content": "#ifndef YACAS_UNIXCOMMANDLINE_H\n#define YACAS_UNIXCOMMANDLINE_H\n\n#include \"commandline.h\"\n\n#include <termios.h>\n\n\n/** Unix command line class, using assorted termios functionality\n *  and sending ansi character sequences to the console.\n */\nclass CUnixCommandLine final: public CCommandLine\n{\npublic:\n    CUnixCommandLine();\n    ~CUnixCommandLine();\n\n    char32_t GetKey() override;\n    void NewLine() override;\n    void ShowLine(const std::string& prompt, unsigned cursor) override;\n    void Pause() override;\n    void MaxHistoryLinesSaved(std::size_t) override;\n\nprivate:\n    unsigned char term_chars[NCCS];\n    struct termios orig_termio, rl_termio;\n    int _cursor_line, _last_line;\n\n    std::size_t _max_lines;\n};\n\n\n#endif\n\n"
  },
  {
    "path": "cyacas/yacas/include/win32commandline.h",
    "content": "#ifndef YACAS_WIN32COMMANDLINE_H\n#define YACAS_WIN32COMMANDLINE_H\n\n#include <windows.h>\n\n#include \"commandline.h\"\n\nclass CWin32CommandLine final: public CCommandLine\n{\npublic:\n    CWin32CommandLine();\n    ~CWin32CommandLine();\n\n    char32_t GetKey() override;\n    void NewLine() override;\n    void ShowLine(const std::string& prompt, unsigned cursor) override;\n    void Pause() override;\n    void MaxHistoryLinesSaved(std::size_t) override;\n\nprivate:\n    void color_print(const std::string& str, WORD text_attrib);\n\n    HANDLE out_console;\n\n    SHORT _cursor_line, _last_line;\n\n    std::size_t _max_lines;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/yacas/res/yacas.rc",
    "content": "#include \"winver.h\"\n#include \"yacas/yacas_version.h\"\n\nVS_VERSION_INFO VERSIONINFO\nFILEVERSION     YACAS_VERSION_MAJOR, YACAS_VERSION_MINOR, YACAS_VERSION_MICRO, 0\nPRODUCTVERSION  YACAS_VERSION_MAJOR, YACAS_VERSION_MINOR, YACAS_VERSION_MICRO, 0\nFILEFLAGSMASK  \tVS_FFI_FILEFLAGSMASK\nFILEFLAGS      \tVS_FF_PRERELEASE\nFILEOS          VOS__WINDOWS32\nFILETYPE        VFT_APP\n\nBEGIN\n    BLOCK \"StringFileInfo\"\n    BEGIN\n        BLOCK \"040904E4\"\n        BEGIN\n            VALUE \"FileVersion\",      YACAS_VERSION\n            VALUE \"LegalCopyright\",   \"LGPL version 2.1 or any later version\"\n            VALUE \"ProductName\",      \"yacas\"\n            VALUE \"ProductVersion\",   YACAS_VERSION\n        END\n    END\n    BLOCK \"VarFileInfo\"\n    BEGIN\n        VALUE \"Translation\", 0x409, 1252\n    END\nEND\n\n100             ICON \"yacas.ico\"\n"
  },
  {
    "path": "cyacas/yacas/src/commandline.cpp",
    "content": "#include \"commandline.h\"\n\n#include <algorithm>\n#include <cstdint>\n\nnamespace {\n    struct IsPrefix {\n\n        explicit IsPrefix(const std::string& p) : _p(p), _l(p.length()) {}\n\n        bool operator()(const std::string& s) const\n        {\n            return _p.compare(0, _l, s, 0, _l) == 0;\n        }\n\n    private:\n        std::string _p;\n        std::size_t _l;\n    };\n}\n\nvoid CCommandLine::GetHistory(std::size_t aLine)\n{\n    iSubLine = iHistoryList.GetLine(aLine);\n}\n\nvoid CCommandLine::MaxHistoryLinesSaved(std::size_t aNrLines) {}\n\nvoid CCommandLine::ReadLine(const std::string& prompt)\n{\n    iLine.clear();\n\n    bool next_line;\n\n    do {\n        next_line = false;\n        iSubLine.clear();\n\n        ReadLineSub(prompt);\n\n        iLine.append(iSubLine);\n        const std::size_t n = iLine.size();\n        if (n && iLine[n - 1] == '\\\\') {\n            iLine.resize(n - 1);\n            next_line = true;\n        }\n    } while (next_line);\n}\n\nvoid CCommandLine::ReadLineSub(const std::string& prompt)\n{\n    unsigned cursor = 0;\n\n    iHistoryList.ResetHistoryPosition();\n    history_unchanged = false;\n\n    full_line_dirty = true;\n    ShowLine(prompt, cursor);\n\n    for (;;) {\n\n#ifdef YACAS_UINT32_T_IN_GLOBAL_NAMESPACE\n        uint32_t c = GetKey();\n#else\n        std::uint32_t c = GetKey();\n#endif\n        const std::size_t len =\n            utf8::distance(iSubLine.begin(), iSubLine.end());\n\n        if (c == eCtrlD && len == 0) {\n            iSubLine = \"Exit()\";\n            NewLine();\n            return;\n        }\n\n        switch (c) {\n        case eCtrlD:\n        case eDelete:\n            if (cursor < len) {\n                std::string::iterator i = iSubLine.begin();\n                utf8::advance(i, cursor, iSubLine.end());\n                std::string::iterator j = i;\n                utf8::next(j, iSubLine.end());\n                iSubLine.erase(i, j);\n                full_line_dirty = true;\n                history_unchanged = false;\n            }\n            break;\n        case eBackSpace:\n            if (cursor > 0) {\n                cursor -= 1;\n                std::string::iterator i = iSubLine.begin();\n                utf8::advance(i, cursor, iSubLine.end());\n                std::string::iterator j = i;\n                utf8::next(j, iSubLine.end());\n                iSubLine.erase(i, j);\n                full_line_dirty = true;\n                history_unchanged = false;\n            }\n            break;\n        case eLeft:\n            if (cursor > 0)\n                cursor--;\n            break;\n        case eRight:\n            if (cursor < len)\n                cursor++;\n            break;\n\n        case eUp:\n            history_unchanged = true;\n            full_line_dirty = true;\n            iHistoryList.ArrowUp(iSubLine, cursor);\n            break;\n        case eDown:\n            history_unchanged = true;\n            full_line_dirty = true;\n            iHistoryList.ArrowDown(iSubLine, cursor);\n            break;\n\n        case eTab:\n            iHistoryList.Complete(iSubLine, cursor);\n            full_line_dirty = true;\n            history_unchanged = true;\n            break;\n        case eEscape:\n            iSubLine = \"\";\n            cursor = 0;\n            full_line_dirty = true;\n            history_unchanged = false;\n            iHistoryList.ResetHistoryPosition();\n            break;\n        case eHome:\n            cursor = 0;\n            break;\n        case eEnd:\n            cursor = len;\n            break;\n        case eEnter:\n            if (!iSubLine.empty()) {\n                NewLine();\n                iHistoryList.AddLine(iSubLine);\n                return;\n            }\n            full_line_dirty = true;\n            break;\n        case eKill:\n            if (cursor < len) {\n                std::string::iterator i = iSubLine.begin();\n                utf8::advance(i, cursor, iSubLine.end());\n                iSubLine.erase(i, iSubLine.end());\n                full_line_dirty = true;\n                history_unchanged = false;\n            }\n            break;\n        default: {\n            std::string octets;\n            utf8::append(c, std::back_inserter(octets));\n            std::string::iterator i = iSubLine.begin();\n            utf8::advance(i, cursor, iSubLine.end());\n            iSubLine.insert(i, octets.begin(), octets.end());\n            full_line_dirty = true;\n            history_unchanged = false;\n            cursor++;\n        } break;\n        }\n        switch (c) {\n        case ')':\n            ShowOpen(prompt, '(', ')', cursor);\n            break;\n        case '}':\n            ShowOpen(prompt, '{', '}', cursor);\n            break;\n        case ']':\n            ShowOpen(prompt, '[', ']', cursor);\n            break;\n        case '\\\"':\n            ShowOpen(prompt, '\\\"', '\\\"', cursor);\n            break;\n        }\n        ShowLine(prompt, cursor);\n    }\n}\n\nvoid CCommandLine::ShowOpen(const std::string& prompt,\n                            char aOpen,\n                            char aClose,\n                            unsigned cursor)\n{\n    if (cursor < 2)\n        return;\n\n    cursor -= 2;\n\n    int count = 1;\n\n    std::string::iterator p = iSubLine.begin();\n    utf8::advance(p, cursor, iSubLine.end());\n\n    for (;;) {\n        if (*p == aOpen)\n            count--;\n        else if (*p == aClose)\n            count++;\n\n        if (count == 0)\n            break;\n\n        if (p == iSubLine.begin())\n            break;\n\n        utf8::prior(p, iSubLine.begin());\n        cursor -= 1;\n    }\n\n    if (count == 0) {\n        ShowLine(prompt, cursor);\n        Pause();\n    }\n}\n\nCConsoleHistory::CConsoleHistory() : history(0) {}\n\nvoid CConsoleHistory::Append(const std::string& s)\n{\n    iHistory.push_back(s);\n    history = iHistory.size();\n}\n\nvoid CConsoleHistory::AddLine(const std::string& s)\n{\n    bool history_changed = false;\n\n    if (history >= iHistory.size()) {\n        history_changed = true;\n        history++;\n    } else if (iHistory[history] != s) {\n        history_changed = true;\n    }\n\n    if (history_changed) {\n        iHistory.push_back(s);\n        return;\n    }\n\n    const std::string orig = iHistory[history];\n    iHistory.erase(iHistory.begin() + history);\n    iHistory.push_back(orig);\n}\n\nbool CConsoleHistory::ArrowUp(std::string& s, unsigned c)\n{\n    if (history == 0)\n        return false;\n\n    std::string::iterator i = s.begin();\n    utf8::advance(i, c, s.end());\n\n    const std::string prefix(s.begin(), i);\n\n    auto p = iHistory.rbegin();\n    std::advance(p, iHistory.size() - history);\n\n    const std::vector<std::string>::reverse_iterator q =\n        std::find_if(p, iHistory.rend(), IsPrefix(prefix));\n\n    if (q == iHistory.rend())\n        return false;\n\n    s = *q;\n    history -= std::distance(p, q) + 1;\n    return true;\n}\n\nbool CConsoleHistory::ArrowDown(std::string& s, unsigned c)\n{\n    if (history > iHistory.size())\n        return false;\n\n    std::string::iterator i = s.begin();\n    utf8::advance(i, c, s.end());\n\n    const std::string prefix(s.begin(), i);\n\n    auto p = iHistory.begin();\n    std::advance(p, history + 1);\n\n    const std::vector<std::string>::iterator q =\n        std::find_if(p, iHistory.end(), IsPrefix(prefix));\n\n    if (q != iHistory.end()) {\n        s = *q;\n        history += std::distance(p, q) + 1;\n        return true;\n    } else {\n        history = iHistory.size();\n        s = prefix;\n        return false;\n    }\n}\n\nstd::size_t CConsoleHistory::NrLines()\n{\n    return iHistory.size();\n}\n\nconst std::string& CConsoleHistory::GetLine(std::size_t n)\n{\n    return iHistory[n];\n}\nvoid CConsoleHistory::ResetHistoryPosition()\n{\n    history = iHistory.size();\n}\n\nbool CConsoleHistory::Complete(std::string& s, unsigned& c)\n{\n    if (history == 0)\n        return false;\n\n    const std::size_t old_history = history;\n\n    history = iHistory.size() - 1;\n\n    std::string::iterator i = s.begin();\n    utf8::advance(i, c, s.end());\n    const std::string prefix(s.begin(), i);\n\n    auto p = iHistory.rbegin();\n    std::advance(p, iHistory.size() - history);\n\n    const std::vector<std::string>::reverse_iterator q =\n        std::find_if(p, iHistory.rend(), IsPrefix(prefix));\n\n    if (q == iHistory.rend()) {\n        history = old_history;\n        return false;\n    }\n\n    s = *q;\n    c = utf8::distance(s.begin(), s.end());\n    history -= std::distance(p, q) + 1;\n    return true;\n}\n"
  },
  {
    "path": "cyacas/yacas/src/js_interface.cpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas.  If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n/*\n * File:   js_interface.cpp\n * Author: mazur\n *\n * Created on January 19, 2016, 10:34 AM\n */\n\n#include <emscripten.h>\n\n#include <set>\n#include <string>\n\n#include \"yacas/yacas.h\"\n\nnamespace {\n    static CYacas* _yacas;\n    static std::string _yacas_result;\n    static std::string _yacas_side_effects;\n    static bool _yacas_is_error;\n}\n\nextern \"C\" bool EMSCRIPTEN_KEEPALIVE yacas_is_error()\n{\n    return _yacas_is_error;\n}\n\nextern \"C\" char* EMSCRIPTEN_KEEPALIVE yacas_result()\n{\n    std::size_t rn = _yacas_result.length();\n    char* r = new char[rn + 1];\n    for (std::size_t i = 0; i < rn; ++i)\n        r[i] = _yacas_result[i];\n\n    r[rn] = 0;\n\n    return r;\n}\n\nextern \"C\" char* EMSCRIPTEN_KEEPALIVE yacas_side_effects()\n{\n    std::size_t rn = _yacas_side_effects.length();\n    char* r = new char[rn + 1];\n    for (std::size_t i = 0; i < rn; ++i)\n        r[i] = _yacas_side_effects[i];\n\n    r[rn] = 0;\n\n    return r;\n}\n\nextern \"C\" void EMSCRIPTEN_KEEPALIVE yacas_evaluate(const char* const p)\n{\n    static std::stringstream os;\n    os.clear();\n    os.str(\"\");\n\n    if (!_yacas) {\n        _yacas = new CYacas(os);\n        _yacas->Evaluate(\"DefaultDirectory(\\\"/share/yacas/scripts/\\\");\");\n        _yacas->Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n    }\n\n    _yacas->Evaluate(p);\n\n    _yacas_is_error = _yacas->IsError();\n\n    if (!_yacas_is_error)\n        _yacas_result = _yacas->Result();\n    else\n        _yacas_result = _yacas->Error();\n\n    _yacas_side_effects = os.str();\n}\n\nextern \"C\" char* EMSCRIPTEN_KEEPALIVE yacas_complete(const char* const p)\n{\n    const std::size_t pn = std::strlen(p);\n\n    std::set<std::string> ss;\n\n    for (auto op : _yacas->getDefEnv().getEnv().PreFix())\n        if (op.first->substr(0, pn) == p)\n            ss.insert(*op.first);\n\n    for (auto op : _yacas->getDefEnv().getEnv().InFix())\n        if (op.first->substr(0, pn) == p)\n            ss.insert(*op.first);\n\n    for (auto op : _yacas->getDefEnv().getEnv().PostFix())\n        if (op.first->substr(0, pn) == p)\n            ss.insert(*op.first);\n\n    for (auto op : _yacas->getDefEnv().getEnv().Bodied())\n        if (op.first->substr(0, pn) == p)\n            ss.insert(*op.first);\n\n    for (auto op : _yacas->getDefEnv().getEnv().CoreCommands())\n        if (op.first->substr(0, pn) == p)\n            ss.insert(*op.first);\n\n    for (auto& op : _yacas->getDefEnv().getEnv().UserFunctions())\n        if (op.first->substr(0, pn) == p)\n            ss.insert(*op.first);\n\n    std::string s;\n    for (const std::string& t : ss) {\n        s.append(t);\n        s.append(\";\");\n    }\n    s.pop_back();\n\n    const std::size_t sn = s.length();\n    char* r = new char[sn + 1];\n    for (std::size_t i = 0; i < sn; ++i)\n        r[i] = s[i];\n\n    r[sn] = 0;\n\n    return r;\n}\n"
  },
  {
    "path": "cyacas/yacas/src/stdcommandline.cpp",
    "content": "#include \"stdcommandline.h\"\n\n#include <iostream>\n\nvoid CStdCommandLine::NewLine() {}\n\nvoid CStdCommandLine::Pause() {}\n\nvoid CStdCommandLine::ShowLine(const std::string& prompt, unsigned cursor) {}\n\nchar32_t CStdCommandLine::GetKey()\n{\n    return '\\n';\n}\n\nvoid CStdCommandLine::ReadLine(const std::string& prompt)\n{\n    std::cout << prompt << std::flush;\n\n    iLine.clear();\n\n    do {\n\n        std::getline(std::cin, iLine);\n        if (!std::cin.good())\n            iLine = \"quit\";\n\n        // FIXME: utf-8 compliant checking for continuation\n    } while (iLine.empty() || iLine.back() == '\\\\');\n}\n"
  },
  {
    "path": "cyacas/yacas/src/unixcommandline.cpp",
    "content": "#include \"unixcommandline.h\"\n\n#include <sys/ioctl.h>\n\n#include <fstream>\n#include <iostream>\n#include <stdexcept>\n\nvoid CUnixCommandLine::NewLine()\n{\n    _cursor_line = 0;\n    _last_line = 0;\n\n    std::cout << std::endl;\n}\n\nvoid CUnixCommandLine::Pause()\n{\n    clock_t i = clock() + CLOCKS_PER_SEC / 4;\n    while (clock() < i)\n        ;\n}\n\nvoid CUnixCommandLine::ShowLine(const std::string& prompt, unsigned cursor)\n{\n    struct winsize w;\n    ioctl(0, TIOCGWINSZ, &w);\n\n    const std::size_t prompt_len = prompt.length();\n\n    const int l = (cursor + prompt_len) / w.ws_col;\n    const int c = (cursor + prompt_len) % w.ws_col;\n\n    if (_cursor_line)\n        std::cout << \"\\x1b[\" << _cursor_line << \"F\";\n\n    if (full_line_dirty) {\n        if (_last_line)\n            std::cout << \"\\x1b[\" << _last_line << \"B\";\n\n        for (int i = 0; i < _last_line; ++i)\n            std::cout << \"\\r\\x1b[K\\x1b[F\";\n\n        std::cout << \"\\r\\x1b[K\\x1b[K\" << prompt << iSubLine;\n\n        if (prompt_len + iSubLine.size() != 0 && (prompt_len + iSubLine.size()) % w.ws_col == 0)\n            std::cout << \"\\n\";\n\n        _last_line = (prompt_len + iSubLine.size()) / w.ws_col;\n        if (_last_line)\n            std::cout << \"\\x1b[\" << _last_line << \"F\";\n    }\n\n    if (l)\n        std::cout << \"\\r\\x1b[\" << l << \"B\";\n\n    std::cout << \"\\r\\x1b[\" << c + 1 << \"G\";\n\n    std::cout << std::flush;\n\n    _cursor_line = l;\n\n    full_line_dirty = false;\n}\n\nCUnixCommandLine::CUnixCommandLine() :\n    _cursor_line(0),\n    _last_line(0),\n    _max_lines(1024)\n{\n    struct winsize w;\n    int rc = ioctl(0, TIOCGWINSZ, &w);\n\n    if (rc < 0 || w.ws_col == 0)\n        throw std::runtime_error(\"dumb terminal\");\n\n    /* set termio so we can do our own input processing */\n    tcgetattr(0, &orig_termio);\n    rl_termio = orig_termio;\n    rl_termio.c_iflag &= ~(BRKINT | PARMRK | INPCK /*|IUCLC*/ | IXON | IXOFF);\n    rl_termio.c_iflag |= (IGNBRK | IGNPAR);\n    /* rl_termio.c_oflag &= ~(ONOCR); Costas Sphocleous Irvine,CA */\n    rl_termio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | NOFLSH);\n    rl_termio.c_lflag |= (ISIG);\n    rl_termio.c_cc[VMIN] = 1;\n    rl_termio.c_cc[VTIME] = 0;\n    term_chars[VERASE] = orig_termio.c_cc[VERASE];\n    term_chars[VEOF] = orig_termio.c_cc[VEOF];\n    term_chars[VKILL] = orig_termio.c_cc[VKILL];\n    term_chars[VWERASE] = orig_termio.c_cc[VWERASE];\n    term_chars[VREPRINT] = orig_termio.c_cc[VREPRINT];\n    term_chars[VSUSP] = orig_termio.c_cc[VSUSP];\n    /* disable suspending process on ^Z */\n    rl_termio.c_cc[VSUSP] = 0;\n    tcsetattr(0, TCSADRAIN, &rl_termio);\n\n    const char* home_dir = getenv(\"HOME\");\n\n    if (!home_dir)\n        return;\n\n    const std::string fname = std::string(home_dir) + \"/.yacas_history\";\n\n    std::ifstream is(fname.c_str());\n\n    std::string line;\n    while (std::getline(is, line))\n        iHistoryList.Append(line);\n}\n\nCUnixCommandLine::~CUnixCommandLine()\n{\n    tcsetattr(0, TCSADRAIN, &orig_termio);\n\n    const char* home_dir = getenv(\"HOME\");\n\n    if (!home_dir)\n        return;\n\n    const std::string fname = std::string(home_dir) + \"/.yacas_history\";\n\n    std::ofstream os(fname.c_str());\n\n    if (os) {\n        std::size_t from = 0;\n\n        if (_max_lines > 0 && iHistoryList.NrLines() > _max_lines)\n            from = iHistoryList.NrLines() - _max_lines;\n\n        for (std::size_t i = from; i < iHistoryList.NrLines(); ++i)\n            os << iHistoryList.GetLine(i) << \"\\n\";\n    }\n}\n\nvoid CUnixCommandLine::MaxHistoryLinesSaved(std::size_t n)\n{\n    _max_lines = n;\n}\n\nchar32_t CUnixCommandLine::GetKey()\n{\n    int c = getc(stdin);\n\n    if (feof(stdin))\n        exit(0);\n\n    char32_t ch = 0;\n\n    if (c == term_chars[VERASE]) /* Backspace */\n        ch = eBackSpace;\n    else if (c == term_chars[VEOF]) /* end of file/delete */\n        ch = eCtrlD;\n    else {\n        switch (c) {\n        case 9: //  9   tab\n            ch = eTab;\n            break;\n        case 10: /* Enter */\n            ch = eEnter;\n            break;\n        case 001: /* ^A  (unix home) */\n            ch = eHome;\n            break;\n        case 005: /* ^E  (unix end) */\n            ch = eEnd;\n            break;\n        case 127:\n            ch = eDelete;\n            break;\n        case 8: /* ^H  (unix backspace) */\n            ch = eBackSpace;\n            break;\n        case 11: /* ^K (unix kill to the end of line */\n            ch = eKill;\n            break;\n        case 033: {\n            c = getc(stdin); /* check for CSI */\n\n            switch (c) {\n            case 27:\n                ch = eEscape;\n                break;\n            case '[':\n            case 79: {\n                c = getc(stdin); /* get command character */\n                switch (c) {\n                case 'D': /* left arrow key */\n                    ch = eLeft;\n                    break;\n                case 'C': /* right arrow key */\n                    ch = eRight;\n                    break;\n                case 'A': /* up arrow key */\n                    ch = eUp;\n                    break;\n                case 'B': /* down arrow key */\n                    ch = eDown;\n                    break;\n                case 'H': /* home */\n                    ch = eHome;\n                    break;\n                case 'F': /* end */\n                    ch = eEnd;\n                    break;\n                }\n                break;\n            }\n            }\n            break;\n        }\n        default: {\n            char p[4] = {static_cast<char>(c), 0, 0, 0};\n            char* q = p + 1;\n            while (!utf8::is_valid(p, q))\n                *q++ = getc(stdin);\n\n            utf8::utf8to32(p, q, &ch);\n\n            break;\n        }\n        }\n    }\n    return ch;\n}\n"
  },
  {
    "path": "cyacas/yacas/src/win32commandline.cpp",
    "content": "#include \"win32commandline.h\"\n\n#include <fstream>\n#include <string>\n\n#include <conio.h>\n\n#include <shlobj.h>\n#include <shlwapi.h>\n#include <windows.h>\n\n/*\n  This displays a message box.\n*/\nstatic void win_assert(BOOL condition)\n{\n    if (condition)\n        return;\n\n    LPVOID lpMsgBuf;\n    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |\n                      FORMAT_MESSAGE_IGNORE_INSERTS,\n                  nullptr,\n                  GetLastError(),\n                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language\n                  (LPTSTR)&lpMsgBuf,\n                  0,\n                  nullptr);\n\n    MessageBox(nullptr, (LPCTSTR)lpMsgBuf, \"Error\", MB_OK | MB_ICONINFORMATION);\n\n    LocalFree(lpMsgBuf);\n\n    exit(1);\n}\n\nvoid CWin32CommandLine::color_print(const std::string& str, WORD text_attrib)\n{\n    BOOL status;\n    CONSOLE_SCREEN_BUFFER_INFO old_info;\n\n    status = GetConsoleScreenBufferInfo(out_console, &old_info);\n    win_assert(status);\n\n    WORD old_attrib = old_info.wAttributes;\n\n    status = SetConsoleTextAttribute(out_console, text_attrib);\n    win_assert(status);\n\n    DWORD written;\n    status =\n        WriteConsole(out_console, str.c_str(), str.length(), &written, nullptr);\n    win_assert(status);\n    // restore the attributes\n    status = SetConsoleTextAttribute(out_console, old_attrib);\n    win_assert(status);\n}\n\nvoid CWin32CommandLine::NewLine()\n{\n    _cursor_line = 0;\n    _last_line = 0;\n\n    color_print(\"\\n\", 0);\n}\n\nvoid CWin32CommandLine::Pause()\n{\n    Sleep(250);\n}\n\nvoid CWin32CommandLine::ShowLine(const std::string& prompt, unsigned cursor)\n{\n    CONSOLE_SCREEN_BUFFER_INFO csbi;\n    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);\n\n    const SHORT no_cols = csbi.dwSize.X;\n    const SHORT no_rows = csbi.dwSize.Y;\n\n    const std::size_t prompt_len = prompt.length();\n\n    const unsigned l = (cursor + prompt_len) / no_cols;\n    const unsigned c = (cursor + prompt_len) % no_cols;\n\n    COORD coords;\n\n    coords.X = 0;\n    coords.Y = csbi.dwCursorPosition.Y - _cursor_line;\n\n    SetConsoleCursorPosition(out_console, coords);\n\n    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);\n\n    if (full_line_dirty) {\n        for (int i = 0; i <= _last_line; ++i) {\n            coords.X = 0;\n            coords.Y = csbi.dwCursorPosition.Y + i;\n            DWORD no_written;\n            FillConsoleOutputCharacter(\n                out_console, ' ', no_cols, coords, &no_written);\n        }\n\n        const std::string line = prompt + iSubLine.c_str();\n        color_print(line.c_str(),\n                    FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);\n\n        _last_line = line.length() / no_cols;\n\n        if (csbi.dwCursorPosition.Y + _last_line >= no_rows)\n            csbi.dwCursorPosition.Y -=\n                csbi.dwCursorPosition.Y + _last_line + 1 - no_rows;\n    }\n\n    coords.X = c;\n    coords.Y = csbi.dwCursorPosition.Y + l;\n    SetConsoleCursorPosition(out_console, coords);\n\n    _cursor_line = l;\n\n    full_line_dirty = false;\n}\n\nCWin32CommandLine::CWin32CommandLine() :\n    out_console(GetStdHandle(STD_OUTPUT_HANDLE)),\n    _cursor_line(0),\n    _last_line(0),\n    _max_lines(1024)\n{\n    win_assert(INVALID_HANDLE_VALUE != out_console);\n\n    char appdata_dir_buf[MAX_PATH];\n    SHGetFolderPathA(\n        nullptr, CSIDL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, appdata_dir_buf);\n\n    const std::string yacas_data_dir = std::string(appdata_dir_buf) + \"\\\\yacas\";\n\n    std::ifstream is((yacas_data_dir + \"\\\\history.log\").c_str());\n\n    while (is) {\n        std::string line;\n        std::getline(is, line);\n        iHistoryList.Append(line.c_str());\n    }\n}\n\nCWin32CommandLine::~CWin32CommandLine()\n{\n    char appdata_dir_buf[MAX_PATH];\n    SHGetFolderPathA(\n        nullptr, CSIDL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, appdata_dir_buf);\n\n    const std::string yacas_data_dir = std::string(appdata_dir_buf) + \"\\\\yacas\";\n\n    if (!PathFileExistsA(yacas_data_dir.c_str()))\n        CreateDirectoryA(yacas_data_dir.c_str(), nullptr);\n\n    std::ofstream os((yacas_data_dir + \"\\\\history.log\").c_str());\n\n    if (os) {\n        std::size_t from = 0;\n\n        if (_max_lines > 0 && iHistoryList.NrLines() > _max_lines)\n            from = iHistoryList.NrLines() - _max_lines;\n\n        for (std::size_t i = from; i < iHistoryList.NrLines(); ++i)\n            os << iHistoryList.GetLine(i).c_str() << \"\\n\";\n    }\n}\n\nvoid CWin32CommandLine::MaxHistoryLinesSaved(std::size_t n)\n{\n    _max_lines = n;\n}\n\nchar32_t CWin32CommandLine::GetKey()\n{\n    // FIXME: support surrogates?\n    char32_t c = _getwch();\n\n    switch (c) {\n    case 8:\n        c = eBackSpace; // Backspace\n        break;\n    case 9: //  Tab\n        c = eTab;\n        break;\n    case 13: // Enter\n        c = eEnter;\n        break;\n    case 0xE0:\n        c = _getwch(); // Get extended scan code\n        switch (c) {\n        case 75: // left arrow key\n            c = eLeft;\n            break;\n        case 77: // right arrow key\n            c = eRight;\n            break;\n        case 72: // up arrow key\n            c = eUp;\n            break;\n        case 80: // down arrow key\n            c = eDown;\n            break;\n        case 71: // home\n            c = eHome;\n            break;\n        case 79: // end\n            c = eEnd;\n            break;\n        case 83: // delete\n            c = eDelete;\n            break;\n        }\n        break;\n    }\n\n    return c;\n}\n"
  },
  {
    "path": "cyacas/yacas/src/yacasmain.cpp",
    "content": "\n/*\n * Example terminal client for the yacas Computer Algebra library.\n * It is heavily tailored to Unix (Linux), but you should be able\n * to easily make a version that links with libyacas.a and provides\n * an interface for a different platform.\n */\n\n// Usage :\n//   1) yacas\n//      just runs yacas in interactive command line mode.\n//   2) yacas <file>\n//      executes file <file> and exits\n//   3) yacas <options>\n//      where options is of the form -<opt>. <opt> can be any\n//      of the combinations of:\n//      - d return the directory of the default scripts.\n//      - v print the version number\n//      - f : treats stdin as one file, and executes the first\n//            read statement only.\n//      - p : plain mode. No fancy readline functionality.\n//      - c : inhibits printing the prompt to the console\n//      - b : inhibits printing the banner\n//   4)\n//  -i <command> : execute <command>\n//\n// Example: 'yacas -pc' will use minimal command line interaction,\n//          showing no prompts, and with no readline functionality.\n//\n\n#include <csignal>\n#include <cstdlib>\n#include <cstring>\n#include <ctime>\n#include <fstream>\n#include <iostream>\n#include <sstream>\n#include <string>\n#include <vector>\n\n#define PATH_SEPARATOR '/'\n#define PATH_SEPARATOR_2 \"/\"\n\n#include \"yacas/yacas.h\"\n\n#ifndef _WIN32\n#    include <libgen.h>\n#    include <sys/stat.h>\n#    include <sys/types.h>\n#    include <unistd.h>\n\n#    include \"unixcommandline.h\"\n#    define FANCY_COMMAND_LINE CUnixCommandLine\n#else\n#    define _WINSOCKAPI_ // Prevent inclusion of winsock.h in windows.h\n#    define _WIN32_WINDOWS                                                     \\\n        0x0410 // Make sure that Waitable Timer functions are declared in\n               // winbase.h\n#    include \"win32commandline.h\"\n#    define FANCY_COMMAND_LINE CWin32CommandLine\n#    include <shlobj.h>\n#    include <shlwapi.h>\n#    include <windows.h>\n#endif\n\n#if defined(__FreeBSD__) || defined(__DragonFly__)\n#    include <stddef.h>\n#    include <sys/sysctl.h>\n#    include <sys/syslimits.h>\n#    include <sys/types.h>\n#    include <unistd.h>\n#endif\n\n#include \"stdcommandline.h\"\n#include \"yacas/arggetter.h\"\n#include \"yacas/numbers.h\"\n#include \"yacas/standard.h\"\n\n#include \"yacas/errors.h\"\n#include \"yacas/string_utils.h\"\n\n#ifndef YACAS_VERSION\n#    include \"yacas/yacas_version.h\"\n#endif\n\n#if defined(__APPLE__)\n#    include <mach-o/dyld.h>\n#endif\n\n#include \"yacas/GPL_stuff.h\"\n\nCYacas* engine = nullptr;\nCCommandLine* commandline = nullptr;\n\nbool use_stdin = false;\nbool use_plain = false;\nbool show_prompt = true;\nbool show_banner = true;\nbool use_texmacs_out = false;\n\nbool patchload = false;\nbool exit_after_files = false;\n\nstd::string root_dir;\nstd::string doc_dir;\nstd::string init_script = \"yacasinit.ys\";\n\nconst char* read_eval_print = \"REP()\";\n\nstatic bool readmode = false;\n\nconst char* execute_commnd = nullptr;\n\nstatic bool busy = true;\nstatic bool restart = false;\n\nvoid ReportNrCurrent() {}\n\n#define RESULT aEnvironment.iStack[aStackTop]\n#define ARGUMENT(i) aEnvironment.iStack[aStackTop + i]\n\nvoid LispExit(LispEnvironment& aEnvironment, int aStackTop)\n{\n    busy = false;\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispExitRequested(LispEnvironment& aEnvironment, int aStackTop)\n{\n    if (!busy)\n        InternalTrue(aEnvironment, RESULT);\n    else\n        InternalFalse(aEnvironment, RESULT);\n}\n\n#ifdef _WIN32\nstd::string get_default_browser()\n{\n    HKEY key;\n    RegOpenKeyEx(HKEY_CLASSES_ROOT,\n                 \"http\\\\shell\\\\open\\\\command\",\n                 0,\n                 KEY_QUERY_VALUE,\n                 &key);\n    TCHAR buf[256];\n    DWORD size = 256;\n    RegQueryValueEx(key, nullptr, nullptr, nullptr, (LPBYTE)buf, &size);\n    RegCloseKey(key);\n\n    return buf;\n}\n#endif\n\nstd::string ReadInputString(const std::string& prompt)\n{\n    if (!commandline)\n        return \"False\";\n\n    readmode = true;\n    commandline->ReadLine(prompt);\n    readmode = false;\n    std::string inpline = commandline->iLine;\n\n    trim(inpline);\n\n    if (inpline.empty())\n        return \"True\";\n\n    if (inpline == \"restart\") {\n        restart = true;\n        busy = false;\n    } else if (inpline == \"quit\") {\n        busy = false;\n    } else if (inpline.front() == '?') {\n        const std::string key(inpline.begin() + 1, inpline.end());\n\n        const std::string prefix = \"file://\" + doc_dir + \"/index.html\";\n        std::string url = prefix + \"#\" + key;\n        if (key == \"licence\" || key == \"license\" || key == \"warranty\")\n            url = prefix + \"#document-license\";\n        else if (key == \"?\")\n            url = prefix + \"#document-reference_manual/index\";\n\n#ifndef _WIN32\n\n#    if defined(__APPLE__)\n        const std::string cmd = \"osascript -e 'open location \\\"\" + url + \"\\\"'\";\n#    else\n        const std::string viewer = \"xdg-open\";\n        const std::string cmd = viewer + \" \" + url;\n#    endif\n        if (system(cmd.c_str()) == 0)\n            inpline = \"True\";\n        else\n            inpline = \"False\";\n#else\n        const std::string viewer = get_default_browser();\n\n        std::string cmd = viewer;\n        cmd.replace(cmd.find(\"%1\"), 2, url);\n\n        STARTUPINFO si;\n        PROCESS_INFORMATION pi;\n\n        ZeroMemory(&si, sizeof si);\n        ZeroMemory(&pi, sizeof pi);\n\n        si.cb = sizeof si;\n\n        if (CreateProcess(nullptr,\n                          (LPSTR)cmd.c_str(),\n                          nullptr,\n                          nullptr,\n                          0,\n                          0,\n                          nullptr,\n                          nullptr,\n                          &si,\n                          &pi))\n            inpline = \"True\";\n        else\n            inpline = \"False\";\n#endif\n    }\n\n    return inpline;\n}\n\nstatic void LispReadCmdLineString(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArgIsString(1, aEnvironment, aStackTop);\n    LispPtr promptObject = (ARGUMENT(1));\n    const std::string prompt = InternalUnstringify(*promptObject->String());\n    const std::string output = ReadInputString(prompt);\n    RESULT = LispAtom::New(aEnvironment, stringify(output));\n}\n\nstatic void LispHistorySize(LispEnvironment& aEnvironment, int aStackTop)\n{\n    int depth = GetShortIntegerArgument(aEnvironment, aStackTop, 1);\n\n    if (commandline)\n        commandline->MaxHistoryLinesSaved(depth);\n\n    InternalTrue(aEnvironment, RESULT);\n}\n\nvoid LispTime(LispEnvironment& aEnvironment, int aStackTop)\n{\n    const std::clock_t starttime = std::clock();\n    LispPtr res;\n    aEnvironment.iEvaluator->Eval(aEnvironment, res, ARGUMENT(1));\n    const std::clock_t endtime = std::clock();\n\n    std::ostringstream os;\n    os << static_cast<double>(endtime - starttime) / CLOCKS_PER_SEC;\n\n    RESULT = LispAtom::New(aEnvironment, os.str());\n}\n\nvoid LispFileSize(LispEnvironment& aEnvironment, int aStackTop)\n{\n    CheckArgIsString(1, aEnvironment, aStackTop);\n    LispPtr fnameObject = (ARGUMENT(1));\n    const std::string fname = InternalUnstringify(*fnameObject->String());\n\n    std::ifstream in(fname.c_str(), std::ifstream::in | std::ifstream::binary);\n    in.seekg(0, std::ifstream::end);\n    std::ostringstream os;\n    os << in.tellg();\n    RESULT = LispAtom::New(aEnvironment, os.str());\n}\n\nvoid LispIsPromptShown(LispEnvironment& aEnvironment, int aStackTop)\n{ // this function must access show_prompt which is a\n  // *global* in yacasmain.cpp, so it's not possible to put\n  // this function in mathcommands.cpp\n    InternalBoolean(aEnvironment, RESULT, show_prompt);\n}\n\nvoid my_exit()\n{\n    if (engine) {\n        if (show_prompt)\n            std::cout << \"Quitting...\\n\";\n\n        // Delete the command line first, so that if in debug mode and\n        // some assert fires while deleting the Yacas environment object,\n        // at least we have a saved history\n        if (commandline) {\n            delete commandline;\n            commandline = nullptr;\n        }\n\n        if (engine) {\n            delete engine;\n            engine = nullptr;\n        }\n\n        ReportNrCurrent();\n    }\n}\n\n#define TEXMACS_DATA_BEGIN ((char)2)\n#define TEXMACS_DATA_END ((char)5)\n#define TEXMACS_DATA_ESCAPE ((char)27)\n\nvoid ShowResult(const std::string& prompt)\n{\n    if (use_texmacs_out)\n        std::cout << TEXMACS_DATA_BEGIN << \"latex:\";\n\n    if (engine->IsError())\n        std::cout << engine->Error() << \"\\n\";\n    else if (engine->getDefEnv().getEnv().PrettyPrinter() == nullptr)\n        std::cout << prompt << engine->Result() << \"\\n\";\n\n    if (use_texmacs_out)\n        std::cout << TEXMACS_DATA_END;\n\n    std::cout << std::flush;\n}\n\nvoid DeclarePath(const char* ptr2)\n{\n    std::ostringstream os;\n\n    if (ptr2[strlen(ptr2) - 1] != PATH_SEPARATOR)\n        os << \"DefaultDirectory(\\\"\" << ptr2 << PATH_SEPARATOR_2 << \"\\\");\";\n    else\n        os << \"DefaultDirectory(\\\"\" << ptr2 << \"\\\");\";\n\n    engine->Evaluate(os.str());\n\n    if (engine->IsError())\n        std::cout << \"Failed to set default directory: \" << engine->Error()\n                  << \"\\n\";\n}\n\nvoid LoadYacas(std::ostream& os)\n{\n    if (engine)\n        return;\n\n    busy = true;\n\n    engine = new CYacas(os);\n\n#define CORE_KERNEL_FUNCTION(iname, fname, nrargs, flags)                      \\\n    engine->getDefEnv().getEnv().SetCommand(fname, iname, nrargs, flags);\n\n#include \"core_yacasmain.h\"\n\n#undef CORE_KERNEL_FUNCTION\n\n    {\n        /* Split up root_dir in pieces separated by colons, and run\n           DefaultDirectory on each of them. */\n        const char *ptr1, *ptr2;\n        ptr1 = ptr2 = root_dir.c_str();\n        while (*ptr1 != '\\0') {\n#ifndef _WIN32\n            while (*ptr1 != '\\0' && *ptr1 != ':')\n                ptr1++;\n            if (*ptr1 == ':') {\n#else\n            while (*ptr1 != '\\0' && *ptr1 != ';')\n                ptr1++;\n            if (*ptr1 == ';') {\n#endif\n                const std::string path(ptr2, ptr1);\n                DeclarePath(path.c_str());\n                ptr1++;\n                ptr2 = ptr1;\n            }\n        }\n        DeclarePath(ptr2);\n\n        std::ostringstream os;\n        os << \"Load(\\\"\" << init_script << \"\\\");\";\n        engine->Evaluate(os.str());\n        if (engine->IsError()) {\n            ShowResult(\"\");\n            read_eval_print = nullptr;\n        }\n    }\n\n    if (engine->IsError())\n        ShowResult(\"\");\n\n    if (use_texmacs_out)\n        std::cout << TEXMACS_DATA_BEGIN << \"verbatim:\";\n\n#ifdef _WIN32\n    char appdata_dir_buf[MAX_PATH];\n    SHGetFolderPathA(\n        nullptr, CSIDL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, appdata_dir_buf);\n\n    const std::string yacas_data_dir = std::string(appdata_dir_buf) + \"\\\\yacas\";\n    std::string yacasrc_path = yacas_data_dir + \"\\\\yacasrc\";\n\n    std::ifstream test(yacasrc_path.c_str());\n    if (test) {\n        for (char& c : yacasrc_path)\n            if (c == '\\\\')\n                c = '/';\n\n        std::ostringstream os;\n        os << \"Load(\\\"\" << yacasrc_path << \"\\\");\";\n        engine->Evaluate(os.str());\n    }\n#else\n    if (const char* home = getenv(\"HOME\")) {\n        std::ostringstream os;\n        os << home << \"/.yacasrc\";\n\n        std::ifstream test(os.str().c_str(), std::ios::binary);\n        if (test) {\n            std::ostringstream os;\n            os << \"Load(\\\"\" << home << \"/.yacasrc\"\n               << \"\\\");\";\n            engine->Evaluate(os.str());\n        }\n    }\n#endif\n\n    if (use_texmacs_out)\n        std::cout << TEXMACS_DATA_END;\n\n    std::cout << std::flush;\n}\n\n#ifdef SIGHANDLER_NO_ARGS\nvoid InterruptHandler(void)\n#else\nvoid InterruptHandler(int errupt)\n#endif\n{\n    std::cout << \"^C pressed\\n\";\n    engine->getDefEnv().getEnv().stop_evaluation = true;\n\n    if (readmode)\n        std::exit(EXIT_SUCCESS);\n}\n\nvoid runconsole(const std::string& inprompt, const std::string& outprompt)\n{\n    if (show_banner) {\n        if (use_texmacs_out) {\n            std::cout << TEXMACS_DATA_BEGIN << \"verbatim:\"\n                      << \"This is Yacas version `\" << YACAS_VERSION\n                      << \"' under TeXmacs\\n\"\n                      << GPL_blurb_nohelp << TEXMACS_DATA_END;\n        } else {\n            std::cout << \"This is Yacas version '\" << YACAS_VERSION << \"'.\\n\";\n            std::cout << GPL_blurb;\n            std::cout << \"To exit Yacas, enter  Exit(); or quit or Ctrl-c.\\n\"\n                      << \"Type 'restart' to restart Yacas.\\n\"\n                      << \"To see example commands, keep typing Example();\\n\";\n        }\n\n        std::cout << std::flush;\n    }\n\n    if (read_eval_print) {\n        while (busy) {\n            engine->Evaluate(read_eval_print);\n\n            if (engine->IsError())\n                std::cout << engine->Error() << \"\\n\";\n        }\n    } else {\n        while (busy) {\n            ReadInputString(inprompt);\n\n            const std::string inpline = commandline->iLine;\n            if (use_texmacs_out)\n                std::cout << TEXMACS_DATA_BEGIN << \"verbatim:\";\n\n            if (busy) {\n                if (!inpline.empty()) {\n                    if (use_texmacs_out)\n                        std::cout << TEXMACS_DATA_BEGIN << \"latex:\";\n\n                    engine->Evaluate(inpline);\n\n                    if (use_texmacs_out)\n                        std::cout << TEXMACS_DATA_END;\n\n                    ShowResult(outprompt);\n                }\n            }\n\n            if (use_texmacs_out)\n                std::cout << TEXMACS_DATA_END;\n\n            std::cout << std::flush;\n        }\n    }\n}\n\nint parse_options(int argc, char** argv)\n{\n    int fileind = 1;\n    if (argc > 1) {\n\n        for (; fileind < argc && argv[fileind][0] == '-'; ++fileind) {\n            if (!std::strcmp(argv[fileind], \"--texmacs\")) {\n                use_texmacs_out = true;\n                use_plain = true;\n                read_eval_print = nullptr;\n            } else if (!std::strcmp(argv[fileind], \"--patchload\")) {\n                patchload = true;\n            } else if (!std::strcmp(argv[fileind], \"--init\")) {\n                fileind++;\n                if (fileind < argc)\n                    init_script = argv[fileind];\n            } else if (!std::strcmp(argv[fileind], \"--read-eval-print\")) {\n                fileind++;\n\n                if (fileind < argc) {\n                    if (argv[fileind][0])\n                        read_eval_print = argv[fileind];\n                    else\n                        read_eval_print = nullptr;\n                }\n            } else if (!std::strcmp(argv[fileind], \"--rootdir\")) {\n                fileind++;\n                if (fileind < argc)\n                    root_dir = argv[fileind];\n            } else if (!std::strcmp(argv[fileind], \"--execute\")) {\n                fileind++;\n                if (fileind < argc)\n                    execute_commnd = argv[fileind];\n            } else if (!std::strcmp(argv[fileind], \"-i\")) {\n                fileind++;\n                if (fileind < argc) {\n                    const char* immediate = argv[fileind];\n                    if (immediate) {\n                        LoadYacas(std::cout);\n\n                        if (use_texmacs_out)\n                            engine->getDefEnv().getEnv().SetPrettyPrinter(\n                                engine->getDefEnv().getEnv().HashTable().LookUp(\n                                    \"\\\"TexForm\\\"\"));\n\n                        engine->Evaluate(immediate);\n\n                        if (engine->IsError())\n                            std::cout << \"Error in immediate command \"\n                                      << immediate << \":\\n\"\n                                      << engine->Error() << \"\\n\";\n\n                        exit_after_files = true;\n                    }\n                }\n            } else {\n                if (std::strchr(argv[fileind], 'f')) {\n                    use_stdin = true;\n                }\n                if (std::strchr(argv[fileind], 'p')) {\n                    use_plain = true;\n                }\n                if (std::strchr(argv[fileind], 'c')) {\n                    show_prompt = false;\n                }\n                if (std::strchr(argv[fileind], 'b')) {\n                    show_banner = false;\n                }\n                if (std::strchr(argv[fileind], 'd')) {\n                    std::cout << root_dir << \"\\n\";\n                    std::exit(EXIT_SUCCESS);\n                }\n                if (std::strchr(argv[fileind], 'v')) {\n                    std::cout << YACAS_VERSION << \"\\n\";\n                    std::exit(EXIT_SUCCESS);\n                }\n            }\n        }\n    }\n\n    return fileind;\n}\n\nint main(int argc, char** argv)\n{\n#if defined(__APPLE__)\n    char buf[PATH_MAX];\n    uint32_t size = sizeof(buf);\n    _NSGetExecutablePath(buf, &size);\n\n    char path[PATH_MAX];\n    realpath(buf, path);\n    root_dir = dirname(dirname(path));\n#elif defined(__FreeBSD__) || defined(__DragonFly__)\n    int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};\n    char buf[PATH_MAX] = {};\n    size_t cb = sizeof(buf);\n    if (sysctl(mib, 4, buf, &cb, NULL, 0) != 0) {\n        std::cerr << \"yacas: failed to locate the executable, bailing out\\n\";\n        exit(EXIT_FAILURE);\n    }\n    root_dir = dirname(dirname(buf));\n#elif defined(__linux__)\n    {\n        struct stat sb;\n        if (stat(\"/proc/self/exe\", &sb) == -1) {\n            std::cerr << \"yacas: failed to stat /proc/self/exe, bailing out\\n\";\n            exit(EXIT_FAILURE);\n        }\n\n        std::vector<char> buf(sb.st_size + 1);\n\n        const ssize_t r =\n            readlink(\"/proc/self/exe\", buf.data(), sb.st_size + 1);\n\n        if (r == -1) {\n            std::cerr << \"yacas: failed to read /proc/self/exe, bailing out\\n\";\n            std::exit(EXIT_FAILURE);\n        }\n\n        if (r > sb.st_size) {\n            std::cerr\n                << \"yacas: /proc/self/exe changed between stat and readlink\\n\";\n            std::exit(EXIT_FAILURE);\n        }\n\n        buf[r] = '\\0';\n\n        root_dir = dirname(dirname(buf.data()));\n    }\n#elif defined(_WIN32)\n    char buf[MAX_PATH];\n    if (!GetModuleFileName(nullptr, buf, MAX_PATH)) {\n        std::cerr << \"yacas: failed to locate the executable, bailing out\\n\";\n        exit(EXIT_FAILURE);\n    }\n\n    PathRemoveFileSpec(buf);\n    PathRemoveFileSpec(buf);\n\n    root_dir = buf;\n\n    for (char& c : root_dir)\n        if (c == '\\\\')\n            c = '/';\n#elif defined(EMSCRIPTEN)\n    root_dir = \"\";\n    use_plain = true;\n#else\n#    error                                                                     \\\n        \"This platform is not yet supported. Please contact developers at yacas@googlegroups.com\"\n#endif\n\n    doc_dir = root_dir + \"/share/yacas/documentation/singlehtml\";\n    root_dir += \"/share/yacas/scripts\";\n\n    int fileind = parse_options(argc, argv);\n\n    if (fileind < 0)\n        return 0;\n\n    std::atexit(my_exit);\n\n    signal(SIGINT, InterruptHandler);\n\n    if (!use_plain) {\n        try {\n            commandline = new FANCY_COMMAND_LINE;\n        } catch (const std::runtime_error&) {\n            use_plain = true;\n        }\n    }\n\n    if (use_plain)\n        commandline = new CStdCommandLine;\n\n    std::string inprompt;\n    std::string outprompt;\n\n    if (show_prompt && !use_texmacs_out) {\n        inprompt = \"In> \";\n        outprompt = \"Out> \";\n    }\n\n    LoadYacas(std::cout);\n\n    if (use_texmacs_out)\n        engine->getDefEnv().getEnv().SetPrettyPrinter(\n            engine->getDefEnv().getEnv().HashTable().LookUp(\"\\\"TexForm\\\"\"));\n\n    for (; fileind < argc; fileind++) {\n        std::ostringstream os;\n        if (patchload)\n            os << \"PatchLoad(\\\"\" << argv[fileind] << \"\\\");\";\n        else\n            os << \"Load(\\\"\" << argv[fileind] << \"\\\");\";\n\n        engine->Evaluate(os.str());\n\n        if (engine->IsError())\n            std::cout << \"Error in file \" << argv[fileind] << \"\\n\"\n                      << engine->Error() << \"\\n\";\n\n        exit_after_files = true;\n    }\n\n    if (exit_after_files)\n        std::exit(EXIT_SUCCESS);\n\n    if (show_prompt && (!use_texmacs_out))\n        ShowResult(\"\");\n\n    if (execute_commnd) {\n\n        engine->Evaluate(execute_commnd);\n\n        if (engine->IsError())\n            std::cout << \"Error in file \" << argv[fileind] << \"\\n\"\n                      << engine->Error() << \"\\n\";\n\n        if (show_prompt && (!use_texmacs_out))\n            ShowResult(\"\");\n    }\n\n    if (use_stdin) {\n        std::string buffer;\n\n        do {\n            std::string line;\n            std::getline(std::cin, line);\n            buffer.append(line);\n        } while (std::cin.good());\n\n        engine->Evaluate(buffer);\n        ShowResult(outprompt);\n\n        std::exit(EXIT_SUCCESS);\n    }\n\n    do {\n        restart = false;\n\n        runconsole(inprompt, outprompt);\n\n        if (restart) {\n            delete engine;\n            engine = nullptr;\n            LoadYacas(std::cout);\n        }\n\n    } while (restart);\n\n    std::exit(EXIT_SUCCESS);\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/CMakeLists.txt",
    "content": "set (CMAKE_INCLUDE_CURRENT_DIR ON)\nset (CMAKE_AUTOMOC ON)\n\n\nif (APPLE)\n    set(OS_BUNDLE MACOSX_BUNDLE)\nelseif(WIN32)\n    set(OS_BUNDLE WIN32)\nendif()\n\nfind_package (Qt5Core REQUIRED)\nfind_package (Qt5Widgets REQUIRED)\nfind_package (Qt5WebEngine REQUIRED)\nfind_package (Qt5WebEngineWidgets REQUIRED)\nfind_package (Qt5Svg REQUIRED)\nfind_package (Qt5PrintSupport REQUIRED)\n\nif (Qt5_POSITION_INDEPENDENT_CODE)\n  set(CMAKE_POSITION_INDEPENDENT_CODE ON)\nendif()\n\ninclude_directories (include)\n\nqt5_wrap_ui (ui_mainwindow.h ui/mainwindow.ui)\nqt5_wrap_ui (ui_preferences_dialog.h ui/preferences_dialog.ui)\n\nqt5_add_resources (qrc_img.cpp img.qrc OPTIONS --compress 9)\n\nset (QRESOURCES qrc_img.cpp)\n\nset (SOURCES\n    src/main.cpp\n    src/mainwindow.cpp\n    src/cellproxy.cpp\n    src/yacasrequest.cpp\n    src/yacasengine.cpp\n    src/yacasserver.cpp\n    src/preferences_dialog.cpp\n    src/preferences.cpp\n)\n\nset (HEADERS\n    include/cellproxy.h\n    include/preferences_dialog.h\n    include/yacasengine.h\n    include/yacasserver.h\n    include/mainwindow.h\n    include/preferences.h\n    include/yacasrequest.h\n    ui_mainwindow.h\n    ui_preferences_dialog.h\n)\n\nif (WIN32)\n    set (SOURCES ${SOURCES} winres/yacas_gui.rc)\nendif ()\n\nif (APPLE)\n    set(ICON_NAME yacas)\n\n    set(OSX_ICON_FILES ${ICON_NAME}.icns)\n    set_source_files_properties(${OSX_ICON_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)\n    set(SOURCES ${SOURCES} ${OSX_ICON_FILES})\n\n    set(MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})\nendif ()\n\nadd_executable (yacas-gui ${OS_BUNDLE} ${SOURCES} ${HEADERS} ${QRESOURCES})\nset_target_properties (yacas-gui PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${IPO_SUPPORTED})\n\ntarget_link_libraries(yacas-gui Qt5::Core Qt5::Widgets Qt5::WebEngine Qt5::WebEngineWidgets Qt5::Svg Qt5::PrintSupport libyacas)\n\nif (APPLE)\n    add_dependencies (yacas-gui yacas-gui_codemirror yacas-gui_vis yacas-gui_mathjax)\n    # add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E remove_directory $<TARGET_FILE_DIR:yacas-gui>/../Frameworks/yacas.framework)\n    # add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory $<TARGET_FILE_DIR:libyacas_framework>/../../.. $<TARGET_FILE_DIR:yacas-gui>/../Frameworks)\n    # add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E remove_directory $<TARGET_FILE_DIR:yacas-gui>/../Frameworks/yacas_mp.framework)\n    # add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory $<TARGET_FILE_DIR:libyacas_mp_framework>/../../.. $<TARGET_FILE_DIR:yacas-gui>/../Frameworks)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/scripts $<TARGET_FILE_DIR:yacas-gui>/../Resources/scripts)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${_qt5Core_install_prefix}/bin/macdeployqt $<TARGET_FILE_DIR:yacas-gui>/../.. -always-overwrite -codesign=-)\n\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/resources/webchannel $<TARGET_FILE_DIR:yacas-gui>/../Resources/webchannel)\n\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/resources/jquery $<TARGET_FILE_DIR:yacas-gui>/../Resources/jquery)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/resources/mathbar $<TARGET_FILE_DIR:yacas-gui>/../Resources/mathbar)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/resources/yacas_gui $<TARGET_FILE_DIR:yacas-gui>/../Resources/yacas_gui)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/yacas_gui.html $<TARGET_FILE_DIR:yacas-gui>/../Resources)\n\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_codemirror/lib $<TARGET_FILE_DIR:yacas-gui>/../Resources/codemirror/lib)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_codemirror/mode/yacas $<TARGET_FILE_DIR:yacas-gui>/../Resources/codemirror/mode/yacas)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_codemirror/addon/edit $<TARGET_FILE_DIR:yacas-gui>/../Resources/codemirror/addon/edit)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_codemirror/addon/hint $<TARGET_FILE_DIR:yacas-gui>/../Resources/codemirror/addon/hint)\n\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/third_party/plotly-1.49.0.min.js $<TARGET_FILE_DIR:yacas-gui>/../Resources)\n\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_vis/dist/vis.min.css $<TARGET_FILE_DIR:yacas-gui>/../Resources/vis/vis.min.css)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_vis/dist/vis.min.js $<TARGET_FILE_DIR:yacas-gui>/../Resources/vis/vis.min.js)\n\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_mathjax/fonts/HTML-CSS/STIX-Web/otf $<TARGET_FILE_DIR:yacas-gui>/../Resources/mathjax/fonts/HTML-CSS/STIX-Web/otf)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_mathjax/fonts/HTML-CSS/STIX-Web/woff $<TARGET_FILE_DIR:yacas-gui>/../Resources/mathjax/fonts/HTML-CSS/STIX-Web/woff)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_mathjax/fonts/HTML-CSS/TeX/otf $<TARGET_FILE_DIR:yacas-gui>/../Resources/mathjax/fonts/HTML-CSS/TeX/otf)\n    add_custom_command (TARGET yacas-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/resources/external_packages/src/yacas-gui_mathjax/unpacked $<TARGET_FILE_DIR:yacas-gui>/../Resources/mathjax/unpacked)\nendif ()\n\nif (WIN32)\n    target_link_libraries (yacas-gui shlwapi)\nendif ()\n\nadd_subdirectory (resources)\n\nif (APPLE)\n    install (TARGETS yacas-gui BUNDLE DESTINATION ${CMAKE_INSTALL_BUNDLE_PREFIX})\nelse ()\n    install (TARGETS yacas-gui DESTINATION ${CMAKE_INSTALL_BINDIR})\nendif ()\n\nif (${CMAKE_SYSTEM_NAME} STREQUAL \"Linux\")\n    install (PROGRAMS yacas-gui.desktop PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)\nendif ()\n\nif (WIN32)\n    include(DeployQt)\n    windeployqt(yacas-gui)\nendif ()\n"
  },
  {
    "path": "cyacas/yacas-gui/img.qrc",
    "content": "<RCC>\n    <qresource prefix=\"/\">\n        <file>resources/img/icon.png</file>\n        <file>resources/img/splash.png</file>\n        <file>resources/img/evaluate.svg</file>\n        <file>resources/img/interupt.svg</file>\n        <file>resources/img/save_document.svg</file>\n        <file>resources/img/new_document.svg</file>\n        <file>resources/img/open_document_dark.svg</file>\n        <file>resources/img/close_document.svg</file>\n        <file>resources/img/exit.svg</file>\n        <file>resources/img/save_as.svg</file>\n        <file>resources/img/print.svg</file>\n        <file>resources/img/help_2.svg</file>\n        <file>resources/img/help.svg</file>\n        <file>resources/img/info.svg</file>\n        <file>resources/img/export.svg</file>\n        <file>resources/img/import.svg</file>\n        <file>resources/img/paste.svg</file>\n        <file>resources/img/copy.svg</file>\n        <file>resources/img/delete_current.svg</file>\n        <file>resources/img/add_below.svg</file>\n        <file>resources/img/add_above.svg</file>\n        <file>resources/img/reevaluate_2.svg</file>\n        <file>resources/img/restart_yacas.svg</file>\n        <file>resources/img/use_script.svg</file>\n        <file>resources/img/cell_next.svg</file>\n        <file>resources/img/cell_previous.svg</file>\n        <file>resources/img/preferences.svg</file>\n        <file>resources/img/cut.svg</file>\n    </qresource>\n</RCC>\n"
  },
  {
    "path": "cyacas/yacas-gui/include/cellproxy.h",
    "content": "#ifndef CELLPROXY_H\n#define\tCELLPROXY_H\n\n#include <QtCore/QObject>\n#include <QtWebEngineWidgets/QWebEnginePage>\n\n#include \"yacasrequest.h\"\n#include \"yacasserver.h\"\n\nclass CellProxy: public QObject {\n    Q_OBJECT\npublic:\n    CellProxy(QWebEnginePage* page, int idx, QString expr, YacasServer& yacas_server, CYacas& yacas2tex, QObject* = 0);\n    ~CellProxy();\n    \npublic slots:\n    void on_request_state_changed(YacasRequest::State);\n    \nprivate:\n    QWebEnginePage* _page;\n    const int _idx;\n    QString _expr;\n    YacasServer& _yacas_server;\n    CYacas& _yacas2tex;\n\n    YacasRequest* _request;\n};\n\n#endif\t/* CELLPROXY_H */\n\n"
  },
  {
    "path": "cyacas/yacas-gui/include/mainwindow.h",
    "content": "#ifndef MAINWINDOW_H\n#define MAINWINDOW_H\n\n#include <QtCore/QMap>\n#include <QtCore/QVariant>\n\n#include <QtGui/QCloseEvent>\n#include <QtGui/QClipboard>\n\n#include <QtWidgets/QMainWindow>\n\n#include <QtPrintSupport/QPrinter>\n\n#include \"yacasserver.h\"\n#include \"yacas/yacas.h\"\n\n#include \"preferences.h\"\n\nnamespace Ui {\n    class MainWindow;\n}\n\nclass MainWindow : public QMainWindow {\n    Q_OBJECT\npublic:\n    explicit MainWindow(Preferences& prefs, QWidget* parent = 0);\n    ~MainWindow();\n\n    Q_INVOKABLE QStringList complete(QString);\n\n    Q_INVOKABLE int getIsWebGLEnabled();\n    Q_PROPERTY(int isWebGLEnabled READ getIsWebGLEnabled)\n    \npublic slots:\n    void eval(int idx, QString expr);\n    void help(QString, int);\n    void copyToClipboard( QString newText );\n    \n    void on_initComplete();\n    void on_contentsChanged();\n\nprotected:\n    void closeEvent(QCloseEvent*);\n    \n    void loadYacasPage();\n\nprivate slots:\n    void print(QPrinter*);\n\n    void on_action_New_triggered();\n    void on_action_Open_triggered();\n    void on_action_Save_triggered();\n    void on_action_Save_As_triggered();\n    void on_action_Print_triggered();\n    void on_action_Close_triggered();\n    void on_action_Quit_triggered();\n\n    void on_actionCu_t_triggered();\n    void on_action_Copy_triggered();\n    void on_action_Paste_triggered();\n    void on_actionPreferences_triggered();\n    \n    void on_action_Next_triggered();\n    void on_action_Previous_triggered();\n    void on_actionInsert_Before_triggered();\n    void on_actionInsert_After_triggered();\n    void on_actionDelete_Current_triggered();\n    \n    void on_action_Use_triggered();\n    void on_action_Import_triggered();\n    void on_action_Export_triggered();\n\n    void on_actionEvaluate_Current_triggered();\n    void on_actionEvaluate_All_triggered();\n    void on_action_Stop_triggered();\n    void on_action_Restart_triggered();\n\n    void on_actionYacas_Manual_triggered();\n    void on_actionCurrent_Symbol_Help_triggered();\n    void on_action_About_triggered();\n\n    void handle_engine_busy(bool);\n    void handle_prefs_changed();\n        \nprivate:\n    void _save();\n    void _update_title();\n\n    Preferences& _prefs;\n    \n    Ui::MainWindow* _ui;\n\n    class NullBuffer: public std::streambuf {\n    public:\n        int overflow(int c) { return c; }\n    };\n\n    NullBuffer _null_buffer;\n    std::ostream _null_stream;\n\n    QString _scripts_path;\n    \n    YacasServer* _yacas_server;\n    CYacas* _yacas2tex;\n\n    QScopedPointer<QPrinter> _printer;\n\n    bool _has_file;\n    bool _modified;\n    QString _fname;\n    \n    QString _to_complete;\n    \n    static QList<MainWindow*> _windows;\n    static unsigned _cntr;\n};\n\n#endif // MAINWINDOW_H\n"
  },
  {
    "path": "cyacas/yacas-gui/include/preferences.h",
    "content": "#ifndef PREFERENCES_H\n#define\tPREFERENCES_H\n\n#include <QtCore/QSettings>\n#include <QtWidgets/QApplication>\n\nclass Preferences: public QObject {\n    \n    Q_OBJECT\n            \npublic:\n    explicit Preferences(const QApplication&);\n    \n    bool get_enable_toolbar() const;\n    void set_enable_toolbar(bool);\n\n    bool get_enable_WebGL() const;\n    void set_enable_WebGL(bool);\n    \n    unsigned get_math_font_scale() const;\n    void set_math_font_scale(unsigned);\n    \n    QString get_math_font() const;\n    void set_math_font(const QString&);\n    \n    bool get_scripts_path_default() const;\n    void set_scripts_path_default(bool);\n    \n    QString get_default_scripts_path() const;\n    \n    QString get_custom_scripts_path() const;\n    void set_custom_scripts_path(const QString&);\n\n    QString get_scripts_path() const;\n\n    QString get_resources_path() const;\n    \n    QString get_cwd() const;\n    void set_cwd(const QString&);\n    \nsignals:\n    void changed();\n    \nprivate:\n    QSettings _settings;\n    QString _default_scripts_path;\n    QString _default_resources_path;\n};\n\n#endif\t/* PREFERENCES_H */\n\n"
  },
  {
    "path": "cyacas/yacas-gui/include/preferences_dialog.h",
    "content": "#ifndef PREFERENCES_DIALOG_H\n#define\tPREFERENCES_DIALOG_H\n\n#include <QtWidgets/QDialog>\n\n#include \"ui_preferences_dialog.h\"\n\n#include \"preferences.h\"\n\nclass PreferencesDialog: public QDialog, public Ui::PreferencesDialog {\n    \n    Q_OBJECT\n    \npublic:\n    explicit PreferencesDialog(Preferences& prefs, QWidget* parent = nullptr);\n\nprivate slots:\n    void on_choosePathButton_clicked();\n    void on_customPathButton_toggled(bool);\n    \n    void accept();\n    void reject();\n    \nprivate:\n    Preferences& _prefs;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/yacas-gui/include/yacasengine.h",
    "content": "#ifndef YACASENGINE_H\n#define YACASENGINE_H\n\n#include <QtCore/QObject>\n\n#include <QtCore/QMutex>\n#include <QtCore/QQueue>\n#include <QtCore/QWaitCondition>\n#include <QtCore/QStringList>\n\n#include <sstream>\n\n#include \"yacasrequest.h\"\n\n#include \"yacas/yacas.h\"\n\nstruct YacasRequestQueue {\n    QMutex mtx;\n    QWaitCondition cnd;\n    QQueue<YacasRequest*> waiting;\n    bool shutdown;\n};\n\nclass YacasEngine: public QObject\n{\n    Q_OBJECT\npublic:\n    explicit YacasEngine(const QString& scripts_path, YacasRequestQueue& requests, QObject* = 0);\n    ~YacasEngine();\n\n    void cancel();\n    \n    QStringList symbols() const;\n    \npublic slots:\n    void on_start_processing();\n\nsignals:\n    void busy(bool);\n    \nprivate:\n    void _update_symbols();\n    \n    YacasRequestQueue& _requests;\n    CYacas* _yacas;\n    std::ostringstream _side_effects;\n    unsigned _idx;\n    \n    QStringList _symbols;\n    mutable QMutex _symbols_mtx;\n};\n\n#endif // YACASENGINE_H\n"
  },
  {
    "path": "cyacas/yacas-gui/include/yacasrequest.h",
    "content": "#ifndef YACASREQUEST_H\n#define YACASREQUEST_H\n\n#include <QObject>\n\nclass YacasRequest : public QObject\n{\n    Q_OBJECT\npublic:\n    explicit YacasRequest(QString expr, QObject *parent = 0);\n\n    enum State {\n        WAITING,\n        BUSY,\n        READY\n    };\n\n    enum ResultType {\n        EXPRESSION,\n        PLOT2D,\n        PLOT3D,\n        GRAPH,\n        ERROR\n    };\n\n    State state() const;\n\n    QString take();\n    void answer(unsigned idx, ResultType type, QString result, QString side_effects);\n\n    ResultType result_type() const;\n    QString result() const;\n    QString side_effects() const;\n\nsignals:\n\n    void state_changed(YacasRequest::State);\n\npublic slots:\n\nprivate:\n    QString _expr;\n    State _state;\n    unsigned _idx;\n    ResultType _result_type;\n    QString _result;\n    QString _side_effects;\n};\n\nQ_DECLARE_METATYPE(YacasRequest::State)\n\n#endif // YACASREQUEST_H\n"
  },
  {
    "path": "cyacas/yacas-gui/include/yacasserver.h",
    "content": "#ifndef YACASSERVER_H\n#define YACASSERVER_H\n\n#include <QObject>\n#include <QThread>\n\n#include \"yacasengine.h\"\n\nclass YacasServer: public QObject\n{\n    Q_OBJECT\npublic:\n    explicit YacasServer(const QString& scripts_path, QObject* parent = 0);\n    ~YacasServer();\n\n    void submit(YacasRequest*);\n    void cancel();\n\n    QStringList symbols() const;\n    \nsignals:\n    void start_processing();\n    void interrupt();\n    void busy(bool);\n\npublic slots:\n    void on_engine_busy(bool);\n    \nprivate:\n    YacasRequestQueue _requests;\n    YacasEngine* _engine;\n    QThread _engine_thread;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/CMakeLists.txt",
    "content": "include (ExternalProject)\n\nExternalProject_Add (yacas-gui_vis\n    PREFIX external_packages\n    URL file://${CMAKE_SOURCE_DIR}/third_party/vis-4.21.0.zip\n    URL_HASH MD5=413939fa8b8c150e373ec5818b6db126\n    CONFIGURE_COMMAND \"\"\n    BUILD_COMMAND \"\"\n    INSTALL_COMMAND \"\")\n\nif (NOT APPLE)\n    install (FILES ${CMAKE_SOURCE_DIR}/third_party/plotly-1.49.0.min.js DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources)\n    install (DIRECTORY jquery DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources)\n    install (DIRECTORY webchannel DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources)\n    install (DIRECTORY mathbar DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources)\n    install (DIRECTORY yacas_gui DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources)\n    install (FILES yacas_gui.html DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources)\n    install (DIRECTORY pixmaps DESTINATION ${CMAKE_INSTALL_DATAROOTDIR})\n    install (DIRECTORY icons DESTINATION ${CMAKE_INSTALL_DATAROOTDIR})\n\n    install (FILES ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_vis/dist/vis.min.css ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_vis/dist/vis.min.js DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/vis)\n\n    if (ENABLE_CYACAS_GUI_PRIVATE_CODEMIRROR)\n        ExternalProject_Add (yacas-gui_codemirror\n            PREFIX external_packages\n            URL file://${CMAKE_SOURCE_DIR}/third_party/CodeMirror-minified-5.47.0.zip\n            URL_HASH MD5=2e15622d1f5d8f82884484b95cf631f5\n            CONFIGURE_COMMAND \"\"\n            BUILD_COMMAND \"\"\n            INSTALL_COMMAND \"\")\n\n        install (DIRECTORY ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_codemirror/lib DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/codemirror)\n        install (DIRECTORY ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_codemirror/mode/yacas DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/codemirror/mode)\n        install (DIRECTORY ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_codemirror/addon/edit DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/codemirror/addon)\n        install (DIRECTORY ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_codemirror/addon/hint DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/codemirror/addon)\n    else ()\n        find_file (CODEMIRROR_PATH codemirror.js PATHS /usr/share/javascript/codemirror ENV CODEMIRROR_PATH)\n        if (CODEMIRROR_PATH STREQUAL CODEMIRROR_PATH-NOTFOUND)\n            message (SEND_ERROR \"CodeMirror not found\")\n        else ()\n            get_filename_component (CODEMIRROR_DIR ${CODEMIRROR_PATH} DIRECTORY)\n            install (CODE \"execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CODEMIRROR_DIR} \\\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/codemirror\\\")\")\n        endif ()\n    endif ()\n    if (ENABLE_CYACAS_GUI_PRIVATE_MATHJAX)\n        ExternalProject_Add (yacas-gui_mathjax\n            PREFIX external_packages\n            URL file://${CMAKE_SOURCE_DIR}/third_party/MathJax-2.7.3.zip\n            URL_HASH MD5=3d1a968f6af90097ef4453fe2b90b373\n            CONFIGURE_COMMAND \"\"\n            BUILD_COMMAND \"\"\n            INSTALL_COMMAND \"\")\n\n        install (DIRECTORY ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_mathjax/fonts/HTML-CSS/STIX-Web/otf DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/mathjax/fonts/HTML-CSS/STIX-Web)\n        install (DIRECTORY ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_mathjax/fonts/HTML-CSS/STIX-Web/woff DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/mathjax/fonts/HTML-CSS/STIX-Web)\n        install (DIRECTORY ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_mathjax/fonts/HTML-CSS/TeX/otf DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/mathjax/fonts/HTML-CSS/TeX)\n        install (DIRECTORY ${CMAKE_BINARY_DIR}/cyacas/yacas-gui/resources/external_packages/src/yacas-gui_mathjax/unpacked DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/mathjax)\n    else ()\n        find_file (MATHJAX_PATH MathJax.js PATHS /usr/share/javascript/mathjax ENV MATHJAX_PATH)\n        if (MATHJAX_PATH STREQUAL MATHJAX_PATH-NOTFOUND)\n            message (SEND_ERROR \"MathJax not found\")\n        else ()\n            get_filename_component (MATHJAX_DIR ${MATHJAX_PATH} DIRECTORY)\n            install (CODE \"execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${MATHJAX_DIR} \\\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/yacas/resources/mathjax\\\")\")\n        endif ()\n    endif ()\nelse ()\n    ExternalProject_Add (yacas-gui_codemirror\n        PREFIX external_packages\n        URL file://${CMAKE_SOURCE_DIR}/third_party/CodeMirror-minified-5.47.0.zip\n        URL_HASH MD5=2e15622d1f5d8f82884484b95cf631f5\n        CONFIGURE_COMMAND \"\"\n        BUILD_COMMAND \"\"\n        INSTALL_COMMAND \"\")\n\n    ExternalProject_Add (yacas-gui_mathjax\n        PREFIX external_packages\n        URL file://${CMAKE_SOURCE_DIR}/third_party/MathJax-2.7.3.zip\n        CONFIGURE_COMMAND \"\"\n        BUILD_COMMAND \"\"\n        INSTALL_COMMAND \"\")\nendif ()\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/jquery/jquery.jeditable.autogrow.js",
    "content": "/*\n * Autosize textarea for Jeditable dedicated for YAGY\n *\n *\n */\n \n$.editable.addInputType( 'autogrow', {\n    element : function( settings, original ) {\n        var textarea = $('<textarea />');\n        if ( settings.rows ) {\n            textarea.attr('rows', settings.rows);\n        } else {\n            textarea.height(settings.height);\n        }\n        if ( settings.cols ) {\n            textarea.attr('cols', settings.cols);\n        } else {\n            textarea.width(settings.width);\n        }\n        $( this ).append( textarea );\n        return( textarea );\n    },\n    plugin : function( settings, original ) {\n                        \n        this[0].editor = CodeMirror.fromTextArea($( 'textarea', this )[0], {lineNumbers: false, mode: {name: \"javascript\", globalVars: true},matchBrackets: true });\n\n                        \n        $( 'textarea', this ).autosize();\n        $( 'textarea', this ).keydown( function (e) {\n                                var number = this.name;\n                                if( e.which == 13 && e.shiftKey ){\n                                      $(this).closest( \"form\" )[0].editor.save();\n                                      $(this).closest( \"form\" ).submit();\n                                }\n                                //if( e.which == 13 ) e.preventDefault();\n                                if( e.which == 38 && e.shiftKey ){\n                                    if( !goUp( number ))\n                                      return;\n                                }\n                                if( e.which == 40 && e.shiftKey ){\n                                    if( !goDown( number ))\n                                        return;\n                                }\n                                      \n                            });\n        $( 'textarea', this ).keyup( function (e) {\n                                \n                                if ( $(this).parents(\"tbody\").hasClass(\"New\"))\n                                    return;\n                                    \n                                original = $(this).parents(\"span\")[0].calculatedExpression;\n                                if ( original != this.value ){\n                                      $(this).parents(\"tbody\").addClass(\"Modified\");\n                                }else{\n                                      $(this).parents(\"tbody\").removeClass(\"Modified\");\n                                }\n                            });\n                                      \n\n                                      \n                                \n    }\n});\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/jquery/jquery.jeditable.js",
    "content": "/*\n * Jeditable - jQuery in place edit plugin\n *\n * Copyright (c) 2006-2009 Mika Tuupola, Dylan Verheul\n *\n * Licensed under the MIT license:\n *   http://www.opensource.org/licenses/mit-license.php\n *\n * Project home:\n *   http://www.appelsiini.net/projects/jeditable\n *\n * Based on editable by Dylan Verheul <dylan_at_dyve.net>:\n *    http://www.dyve.net/jquery/?editable\n *\n */\n\n/*\n * (!) Changed for Yagy. Search for YAGY CHANGE text.\n */\n\n/**\n  * Version 1.7.1\n  *\n  * ** means there is basic unit tests for this parameter. \n  *\n  * @name  Jeditable\n  * @type  jQuery\n  * @param String  target             (POST) URL or function to send edited content to **\n  * @param Hash    options            additional options \n  * @param String  options[method]    method to use to send edited content (POST or PUT) **\n  * @param Function options[callback] Function to run after submitting edited content **\n  * @param String  options[name]      POST parameter name of edited content\n  * @param String  options[id]        POST parameter name of edited div id\n  * @param Hash    options[submitdata] Extra parameters to send when submitting edited content.\n  * @param String  options[type]      text, textarea or select (or any 3rd party input type) **\n  * @param Integer options[rows]      number of rows if using textarea ** \n  * @param Integer options[cols]      number of columns if using textarea **\n  * @param Mixed   options[height]    'auto', 'none' or height in pixels **\n  * @param Mixed   options[width]     'auto', 'none' or width in pixels **\n  * @param String  options[loadurl]   URL to fetch input content before editing **\n  * @param String  options[loadtype]  Request type for load url. Should be GET or POST.\n  * @param String  options[loadtext]  Text to display while loading external content.\n  * @param Mixed   options[loaddata]  Extra parameters to pass when fetching content before editing.\n  * @param Mixed   options[data]      Or content given as paramameter. String or function.**\n  * @param String  options[indicator] indicator html to show when saving\n  * @param String  options[tooltip]   optional tooltip text via title attribute **\n  * @param String  options[event]     jQuery event such as 'click' of 'dblclick' **\n  * @param String  options[submit]    submit button value, empty means no button **\n  * @param String  options[cancel]    cancel button value, empty means no button **\n  * @param String  options[cssclass]  CSS class to apply to input form. 'inherit' to copy from parent. **\n  * @param String  options[style]     Style to apply to input form 'inherit' to copy from parent. **\n  * @param String  options[select]    true or false, when true text is highlighted ??\n  * @param String  options[placeholder] Placeholder text or html to insert when element is empty. **\n  * @param String  options[onblur]    'cancel', 'submit', 'ignore' or function ??\n  *             \n  * @param Function options[onsubmit] function(settings, original) { ... } called before submit\n  * @param Function options[onreset]  function(settings, original) { ... } called before reset\n  * @param Function options[onerror]  function(settings, original, xhr) { ... } called on error\n  *             \n  * @param Hash    options[ajaxoptions]  jQuery Ajax options. See docs.jquery.com.\n  *             \n  */\n\n(function($) {\n\n    $.fn.editable = function(target, options) {\n            \n        if ('disable' == target) {\n            $(this).data('disabled.editable', true);\n            return;\n        }\n        if ('enable' == target) {\n            $(this).data('disabled.editable', false);\n            return;\n        }\n        if ('destroy' == target) {\n            $(this)\n                .unbind($(this).data('event.editable'))\n                .removeData('disabled.editable')\n                .removeData('event.editable');\n            return;\n        }\n        \n        var settings = $.extend({}, $.fn.editable.defaults, {target:target}, options);\n        \n        /* setup some functions */\n        var plugin   = $.editable.types[settings.type].plugin || function() { };\n        var submit   = $.editable.types[settings.type].submit || function() { };\n        var buttons  = $.editable.types[settings.type].buttons \n                    || $.editable.types['defaults'].buttons;\n        var content  = $.editable.types[settings.type].content \n                    || $.editable.types['defaults'].content;\n        var element  = $.editable.types[settings.type].element \n                    || $.editable.types['defaults'].element;\n        var reset    = $.editable.types[settings.type].reset \n                    || $.editable.types['defaults'].reset;\n        var callback = settings.callback || function() { };\n        var onedit   = settings.onedit   || function() { }; \n        var onsubmit = settings.onsubmit || function() { };\n        var onreset  = settings.onreset  || function() { };\n        var onerror  = settings.onerror  || reset;\n          \n        /* show tooltip */\n        if (settings.tooltip) {\n            $(this).attr('title', settings.tooltip);\n        }\n        \n        settings.autowidth  = 'auto' == settings.width;\n        settings.autoheight = 'auto' == settings.height;\n        \n        return this.each(function() {\n                        \n            /* save this to self because this changes when scope changes */\n            var self = this;  \n                   \n            /* inlined block elements lose their width and height after first edit */\n            /* save them for later use as workaround */\n\n            var savedwidth  = $(self).width();\n            var savedheight = $(self).height();\n            \n            /* save so it can be later used by $.editable('destroy') */\n            $(this).data('event.editable', settings.event);\n            \n            /* if element is empty add something clickable (if requested) */\n            if (!$.trim($(this).html())) {\n                $(this).html(settings.placeholder);\n            }\n            \n            $(this).bind(settings.event, function(e) {\n                \n                /* abort if disabled for this element */\n                if (true === $(this).data('disabled.editable')) {\n                    return;\n                }\n                \n                /* prevent throwing an exeption if edit field is clicked again */\n                if (self.editing) {\n                    return;\n                }\n                \n                /* abort if onedit hook returns false */\n                if (false === onedit.apply(this, [settings, self])) {\n                   return;\n                }\n                \n                /* prevent default action and bubbling */\n                e.preventDefault();\n                e.stopPropagation();\n                \n                /* remove tooltip */\n                if (settings.tooltip) {\n                    $(self).removeAttr('title');\n                }\n                \n                /* figure out how wide and tall we are, saved width and height */\n                /* are workaround for http://dev.jquery.com/ticket/2190 */\n                if (0 == $(self).width()) {\n                    //$(self).css('visibility', 'hidden');\n                    settings.width  = \"100%\";\n                    settings.height = savedheight;\n                } else {\n                    if (settings.width != 'none') {\n                        settings.width = \n                            settings.autowidth ? $(self).width()  : settings.width;\n                    }\n                    if (settings.height != 'none') {\n                        settings.height = \n                            settings.autoheight ? $(self).height() : settings.height;\n                    }\n                }\n                //$(this).css('visibility', '');\n                \n                /* remove placeholder text, replace is here because of IE */\n                if ($(this).html().toLowerCase().replace(/(;|\")/g, '') == \n                    settings.placeholder.toLowerCase().replace(/(;|\")/g, '')) {\n                        $(this).html('');\n                }\n                                \n                self.editing    = true;\n                //YAGY CHANGE: chaned from $(self).html() to $(self).text() to not have html entites encoded\n                self.revert     = $(self).text();\n                $(self).html('');\n\n                /* create the form object */\n                var form = $('<form />');\n                \n                /* apply css or style or both */\n                if (settings.cssclass) {\n                    if ('inherit' == settings.cssclass) {\n                        form.attr('class', $(self).attr('class'));\n                    } else {\n                        form.attr('class', settings.cssclass);\n                    }\n                }\n\n                if (settings.style) {\n                    if ('inherit' == settings.style) {\n                        form.attr('style', $(self).attr('style'));\n                        /* IE needs the second line or display wont be inherited */\n                        form.css('display', $(self).css('display'));                \n                    } else {\n                        form.attr('style', settings.style);\n                    }\n                }\n\n                /* add main input element to form and store it in input */\n                var input = element.apply(form, [settings, self]);\n\n                /* set input content via POST, GET, given data or existing value */\n                var input_content;\n                \n                if (settings.loadurl) {\n                    var t = setTimeout(function() {\n                        input.disabled = true;\n                        content.apply(form, [settings.loadtext, settings, self]);\n                    }, 100);\n\n                    var loaddata = {};\n                    loaddata[settings.id] = self.id;\n                    if ($.isFunction(settings.loaddata)) {\n                        $.extend(loaddata, settings.loaddata.apply(self, [self.revert, settings]));\n                    } else {\n                        $.extend(loaddata, settings.loaddata);\n                    }\n                    $.ajax({\n                       type : settings.loadtype,\n                       url  : settings.loadurl,\n                       data : loaddata,\n                       async : false,\n                       success: function(result) {\n                          window.clearTimeout(t);\n                          input_content = result;\n                          input.disabled = false;\n                       }\n                    });\n                } else if (settings.data) {\n                    input_content = settings.data;\n                    if ($.isFunction(settings.data)) {\n                        input_content = settings.data.apply(self, [self.revert, settings]);\n                    }\n                } else {\n                    input_content = self.revert; \n                }\n                content.apply(form, [input_content, settings, self]);\n\n                input.attr('name', settings.name);\n        \n                /* add buttons to the form */\n                buttons.apply(form, [settings, self]);\n         \n                /* add created form to self */\n                $(self).append(form);\n         \n                /* attach 3rd party plugin if requested */\n                plugin.apply(form, [settings, self]);\n\n                /* focus to first visible form element */\n                $(':input:visible:enabled:first', form).focus();\n\n                /* highlight input contents when requested */\n                if (settings.select) {\n                    input.select();\n                }\n        \n                /* discard changes if pressing esc */\n                input.keydown(function(e) {\n                    if (e.keyCode == 27) {\n                        e.preventDefault();\n                        //self.reset();\n                        reset.apply(form, [settings, self]);\n                    }\n /*                   if( e.which == 13 && e.shiftKey ){\n                        form.submit();\n                    }\n                    if( e.which == 13 ){\n                        e.preventDefault();\n                    }\n*/\n                });\n                                                                 \n\n\n                /* discard, submit or nothing with changes when clicking outside */\n                /* do nothing is usable when navigating with tab */\n                var t;\n                if ('cancel' == settings.onblur) {\n                    input.blur(function(e) {\n                        /* prevent canceling if submit was clicked */\n                        t = setTimeout(function() {\n                            reset.apply(form, [settings, self]);\n                        }, 500);\n                    });\n                } else if ('submit' == settings.onblur) {\n                    input.blur(function(e) {\n                        /* prevent double submit if submit was clicked */\n                        t = setTimeout(function() {\n                            form.submit();\n                        }, 200);\n                    });\n                } else if ($.isFunction(settings.onblur)) {\n                    input.blur(function(e) {\n                        settings.onblur.apply(self, [input.val(), settings]);\n                    });\n                } else {\n                    input.blur(function(e) {\n                      /* TODO: maybe something here */\n                    });\n                }\n\n                form.submit(function(e) {\n\n                    if (t) { \n                        clearTimeout(t);\n                    }\n\n                    /* do no submit */\n                    e.preventDefault(); \n            \n                    /* call before submit hook. */\n                    /* if it returns false abort submitting */                    \n                    if (false !== onsubmit.apply(form, [settings, self])) { \n                        /* custom inputs call before submit hook. */\n                        /* if it returns false abort submitting */\n                        if (false !== submit.apply(form, [settings, self])) { \n\n                          /* check if given target is function */\n                          if ($.isFunction(settings.target)) {\n                              var str = settings.target.apply(self, [input.val(), settings]);\n                              $(self).html(str);\n                              self.editing = false;\n                              callback.apply(self, [self.innerHTML, settings]);\n                              /* TODO: this is not dry */                              \n                              if (!$.trim($(self).html())) {\n                                  $(self).html(settings.placeholder);\n                              }\n                          } else {\n                              /* add edited content and id of edited element to POST */\n                              var submitdata = {};\n                              submitdata[settings.name] = input.val();\n                              submitdata[settings.id] = self.id;\n                              /* add extra data to be POST:ed */\n                              if ($.isFunction(settings.submitdata)) {\n                                  $.extend(submitdata, settings.submitdata.apply(self, [self.revert, settings]));\n                              } else {\n                                  $.extend(submitdata, settings.submitdata);\n                              }\n\n                              /* quick and dirty PUT support */\n                              if ('PUT' == settings.method) {\n                                  submitdata['_method'] = 'put';\n                              }\n\n                              /* show the saving indicator */\n                              $(self).html(settings.indicator);\n                              \n                              /* defaults for ajaxoptions */\n                              var ajaxoptions = {\n                                  type    : 'POST',\n                                  data    : submitdata,\n                                  dataType: 'html',\n                                  url     : settings.target,\n                                  success : function(result, status) {\n                                      if (ajaxoptions.dataType == 'html') {\n                                        $(self).html(result);\n                                      }\n                                      self.editing = false;\n                                      callback.apply(self, [result, settings]);\n                                      if (!$.trim($(self).html())) {\n                                          $(self).html(settings.placeholder);\n                                      }\n                                  },\n                                  error   : function(xhr, status, error) {\n                                      onerror.apply(form, [settings, self, xhr]);\n                                  }\n                              };\n                              \n                              /* override with what is given in settings.ajaxoptions */\n                              $.extend(ajaxoptions, settings.ajaxoptions);   \n                              $.ajax(ajaxoptions);          \n                              \n                            }\n                        }\n                    }\n                    \n                    /* show tooltip again */\n                    $(self).attr('title', settings.tooltip);\n                    \n                    return false;\n                });\n            });\n            \n            /* privileged methods */\n            this.reset = function(form) {\n                /* prevent calling reset twice when blurring */\n                if (this.editing) {\n                    /* before reset hook, if it returns false abort reseting */\n                    if (false !== onreset.apply(form, [settings, self])) { \n                        $(self).html(self.revert);\n                        self.editing   = false;\n                        if (!$.trim($(self).html())) {\n                            $(self).html(settings.placeholder);\n                        }\n                        /* show tooltip again */\n                        if (settings.tooltip) {\n                            $(self).attr('title', settings.tooltip);                \n                        }\n                    }                    \n                }\n            };            \n        });\n\n    };\n\n\n    $.editable = {\n        types: {\n            defaults: {\n                element : function(settings, original) {\n                    var input = $('<input type=\"hidden\"></input>');                \n                    $(this).append(input);\n                    return(input);\n                },\n                content : function(string, settings, original) {\n                    $(':input:first', this).val(string);\n                },\n                reset : function(settings, original) {\n                  original.reset(this);\n                },\n                buttons : function(settings, original) {\n                    var form = this;\n                    if (settings.submit) {\n                        /* if given html string use that */\n                        if (settings.submit.match(/>$/)) {\n                            var submit = $(settings.submit).click(function() {\n                                if (submit.attr(\"type\") != \"submit\") {\n                                    form.submit();\n                                }\n                            });\n                        /* otherwise use button with given string as text */\n                        } else {\n                            var submit = $('<button type=\"submit\" />');\n                            submit.html(settings.submit);                            \n                        }\n                        $(this).append(submit);\n                    }\n                    if (settings.cancel) {\n                        /* if given html string use that */\n                        if (settings.cancel.match(/>$/)) {\n                            var cancel = $(settings.cancel);\n                        /* otherwise use button with given string as text */\n                        } else {\n                            var cancel = $('<button type=\"cancel\" />');\n                            cancel.html(settings.cancel);\n                        }\n                        $(this).append(cancel);\n\n                        $(cancel).click(function(event) {\n                            //original.reset();\n                            if ($.isFunction($.editable.types[settings.type].reset)) {\n                                var reset = $.editable.types[settings.type].reset;                                                                \n                            } else {\n                                var reset = $.editable.types['defaults'].reset;                                \n                            }\n                            reset.apply(form, [settings, original]);\n                            return false;\n                        });\n                    }\n                }\n            },\n            text: {\n                element : function(settings, original) {\n                    var input = $('<input />');\n                    if (settings.width  != 'none') { input.width(settings.width);  }\n                    if (settings.height != 'none') { input.height(settings.height); }\n                    /* https://bugzilla.mozilla.org/show_bug.cgi?id=236791 */\n                    //input[0].setAttribute('autocomplete','off');\n                    input.attr('autocomplete','off');\n                    $(this).append(input);\n                    return(input);\n                }\n            },\n            textarea: {\n                element : function(settings, original) {\n                    var textarea = $('<textarea />');\n                    if (settings.rows) {\n                        textarea.attr('rows', settings.rows);\n                    } else if (settings.height != \"none\") {\n                        textarea.height(settings.height);\n                    }\n                    if (settings.cols) {\n                        textarea.attr('cols', settings.cols);\n                    } else if (settings.width != \"none\") {\n                        textarea.width(settings.width);\n                    }\n                    $(this).append(textarea);\n                    return(textarea);\n                }\n            },\n            select: {\n               element : function(settings, original) {\n                    var select = $('<select />');\n                    $(this).append(select);\n                    return(select);\n                },\n                content : function(data, settings, original) {\n                    /* If it is string assume it is json. */\n                    if (String == data.constructor) {      \n                        eval ('var json = ' + data);\n                    } else {\n                    /* Otherwise assume it is a hash already. */\n                        var json = data;\n                    }\n                    for (var key in json) {\n                        if (!json.hasOwnProperty(key)) {\n                            continue;\n                        }\n                        if ('selected' == key) {\n                            continue;\n                        } \n                        var option = $('<option />').val(key).append(json[key]);\n                        $('select', this).append(option);    \n                    }                    \n                    /* Loop option again to set selected. IE needed this... */ \n                    $('select', this).children().each(function() {\n                        if ($(this).val() == json['selected'] || \n                            $(this).text() == $.trim(original.revert)) {\n                                $(this).attr('selected', 'selected');\n                        }\n                    });\n                }\n            }\n        },\n\n        /* Add new input type */\n        addInputType: function(name, input) {\n            $.editable.types[name] = input;\n        }\n    };\n\n    // publicly accessible defaults\n    $.fn.editable.defaults = {\n        name       : 'value',\n        id         : 'id',\n        type       : 'text',\n        width      : 'auto',\n        height     : 'auto',\n        event      : 'click.editable',\n        onblur     : 'cancel',\n        loadtype   : 'GET',\n        loadtext   : 'Loading...',\n        placeholder: 'Click to edit',\n        loaddata   : {},\n        submitdata : {},\n        ajaxoptions: {}\n    };\n\n})(jQuery);\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/mathbar/functions.json",
    "content": "{\n    \"categories\": {\n        \"number\": [\n            \"Sqrt\",\n            \"Exp\",\n            \"Ln\"\n        ],\n        \"function_1\": [\n            \"Simplify\",\n            \"Integrate\",\n            \"Derivative\",\n            \"Plot2D\",\n            \"Limit\"\n        ],\n        \"function_2\": [\n            \"Simplify\",\n            \"Integrate\",\n            \"Derivative\",\n            \"Plot3D\"\n        ],\n        \"constant\": [\n            \"N\"\n        ]\n    },\n    \"functions\": {\n        \"N\": {\n            \"parameters\": [\n                {\n                    \"parameterName\": \"with_precision\",\n                    \"parameterType\": \"condition\",\n                    \"text\": \"\",\n                    \"defaultValue\": \"false\",\n                    \"parameters\": [\n                        {\n                            \"parameterName\": \"precision\",\n                            \"parameterType\": \"edit\",\n                            \"defaultValue\": \"10\",\n                            \"widestValue\": \"0000\",\n                            \"text\": \"with precision\"\n                        }\n                    ]\n                }\n            ],\n            \"parser\": \"NumericalValueParser\"\n        },\n        \"Sqrt\": {\n            \"parameters\": [],\n            \"parser\": \"SquareRootParser\"\n        },\n        \"Exp\": {\n            \"parameters\": [],\n            \"parser\": \"ExponentialParser\"\n        },\n        \"Ln\": {\n            \"parameters\": [],\n            \"parser\": \"NaturalLogarithmParser\"\n        },\n        \"Simplify\": {\n            \"parameters\": [],\n            \"parser\": \"SimplifyParser\"\n        },\n        \"Integrate\": {\n            \"parameters\": [\n                {\n                    \"parameterName\": \"variable\",\n                    \"parameterType\": \"select\",\n                    \"defaultValue\": [\n                        \"x\"\n                    ],\n                    \"text\": \"over\"\n                },\n                {\n                    \"parameterName\": \"definite\",\n                    \"parameterType\": \"condition\",\n                    \"text\": \"\",\n                    \"defaultValue\": \"false\",\n                    \"parameters\": [\n                        {\n                            \"parameterName\": \"from\",\n                            \"parameterType\": \"edit\",\n                            \"defaultValue\": \"0\",\n                            \"widestValue\": \"-Infinity\"\n                        },\n                        {\n                            \"parameterName\": \"to\",\n                            \"parameterType\": \"edit\",\n                            \"defaultValue\": \"5\",\n                            \"widestValue\": \"-Infinity\"\n                        }\n                    ]\n                }\n            ],\n            \"parser\": \"IntegrateParser\"\n        },\n        \"Derivative\": {\n            \"parameters\": [\n                {\n                    \"parameterName\": \"variable\",\n                    \"parameterType\": \"select\",\n                    \"defaultValue\": [\n                        \"x\"\n                    ],\n                    \"text\": \"with respect to\"\n                }\n            ],\n            \"parser\": \"DerivativeParser\"\n        },\n        \"Plot2D\": {\n            \"parameters\": [\n                {\n                    \"parameterName\": \"from\",\n                    \"parameterType\": \"edit\",\n                    \"defaultValue\": \"-5\",\n                    \"widestValue\": \"00000\"\n                },\n                {\n                    \"parameterName\": \"to\",\n                    \"parameterType\": \"edit\",\n                    \"defaultValue\": \"5\",\n                    \"widestValue\": \"00000\"\n                }\n            ],\n            \"text\": \"Plot\",\n            \"parser\": \"Plot2dParser\"\n        },\n        \"Limit\": {\n            \"parameters\": [\n                {\n                    \"parameterName\": \"variable\",\n                    \"parameterType\": \"select\",\n                    \"defaultValue\": \"x\",\n                    \"text\": \"as\"\n                },\n                {\n                    \"parameterName\": \"value\",\n                    \"parameterType\": \"edit\",\n                    \"defaultValue\": \"0\",\n                    \"text\": \"approaches\",\n                    \"widestValue\": \"-Infinity\"\n                },\n                {\n                    \"parameterName\": \"direction\",\n                    \"parameterType\": \"condition\",\n                    \"text\": \"\",\n                    \"defaultValue\": \"false\",\n                    \"parameters\": [\n                        {\n                            \"parameterName\": \"from\",\n                            \"parameterType\": \"select\",\n                            \"defaultValue\": [\n                                \"Left\",\n                                \"Right\"\n                            ]\n                        }\n                    ]\n                }\n            ],\n            \"parser\": \"LimitParser\"\n        },\n        \"Plot3D\": {\n            \"parameters\": [\n                {\n                    \"parameterName\": \"var\",\n                    \"parameterType\": \"label\",\n                    \"defaultValue\": \"%VARIABLE%0%\",\n                    \"text\": \"\"\n                },\n                {\n                    \"parameterName\": \"variable_0_from\",\n                    \"parameterType\": \"edit\",\n                    \"defaultValue\": \"-5\",\n                    \"widestValue\": \"00000\",\n                    \"text\": \"from\"\n                },\n                {\n                    \"parameterName\": \"variable_0_to\",\n                    \"parameterType\": \"edit\",\n                    \"defaultValue\": \"5\",\n                    \"widestValue\": \"00000\",\n                    \"text\": \"to\"\n                },\n                {\n                    \"parameterName\": \"var\",\n                    \"parameterType\": \"label\",\n                    \"defaultValue\": \"%VARIABLE%1%\",\n                    \"text\": \"\"\n                },\n                {\n                    \"parameterName\": \"variable_1_from\",\n                    \"parameterType\": \"edit\",\n                    \"defaultValue\": \"-5\",\n                    \"widestValue\": \"00000\",\n                    \"text\": \"from\"\n                },\n                {\n                    \"parameterName\": \"variable_1_to\",\n                    \"parameterType\": \"edit\",\n                    \"defaultValue\": \"5\",\n                    \"widestValue\": \"00000\",\n                    \"text\": \"to\"\n                }\n            ],\n            \"text\": \"Plot\",\n            \"parser\": \"Plot3dParser\"\n        }\n    }\n}"
  },
  {
    "path": "cyacas/yacas-gui/resources/mathbar/functions_parser.js",
    "content": "\"use strict\";\n\nfunction SquareRootParser(outputValue, parameters) {\n    return \"Sqrt(\" + outputValue + \")\";\n}\n\n\n\nfunction NaturalLogarithmParser(outputValue, parameters) {\n    return \"Ln(\" + outputValue + \")\";\n}\n\nfunction NumericalValueParser(outputValue, parameters) {\n    const withPrecision = parameters[\"with_precision\"];\n\n    if (withPrecision) {\n        const precision = parameters[\"precision\"];\n        return \"N(\" + outputValue + \",\" + precision + \")\";\n    } else {\n        return \"N(\" + outputValue + \")\";\n    }\n}\n\nfunction ExponentialParser(outputValue, parameters) {\n    return \"Exp(\" + outputValue + \")\";\n}\n\n\nfunction SimplifyParser(outputValue, parameters) {\n    return \"Simplify(\" + outputValue + \")\";\n}\n\nfunction IntegrateParser(outputValue, parameters) {\n    const variable = parameters[\"variable\"];\n\n    const definite = parameters[\"definite\"];\n\n    if (definite) {\n        const to = parameters[\"to\"];\n        const from = parameters[\"from\"];\n        return \"Integrate(\" + variable + \",\" + from + \",\" + to + \")\" + outputValue;\n    } else {\n        return \"Integrate(\" + variable + \")\" + outputValue;\n    }\n}\n\nfunction DerivativeParser(outputValue, parameters) {\n    const variable = parameters[\"variable\"];\n    return \"D(\" + variable + \")\" + outputValue;\n}\n\nfunction Plot2dParser(outputValue, parameters) {\n    const from = parameters[\"from\"];\n    const to = parameters[\"to\"];\n\n    return \"Plot2D(\" + outputValue + \",\" + from + \":\" + to + \")\";\n}\n\nfunction Plot3dParser(outputValue, parameters) {\n    const from0 = parameters[\"variable_0_from\"];\n    const to0 = parameters[\"variable_0_to\"];\n    const from1 = parameters[\"variable_1_from\"];\n    const to1 = parameters[\"variable_1_to\"];\n\n    return \"Plot3DS(\" + outputValue + \",\" + from0 + \":\" + to0 + \",\" + from1 + \":\" + to1 + \")\";\n}\n\nfunction LimitParser(outputValue, parameters) {\n    const variable = parameters[\"variable\"];\n    const value = parameters[\"value\"];\n    const direction = parameters[\"direction\"];\n\n\n    if (direction) {\n        const from = parameters[\"from\"];\n        return \"Limit(\" + variable + \",\" + value + \",\" + from + \")\" + outputValue;\n\n    } else {\n        return \"Limit(\" + variable + \",\" + value + \")\" + outputValue;\n\n    }\n}\n\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/mathbar/mathBar.js",
    "content": "\"use strict\";\n\nMathBar.selectMoreText = \"more\";\nMathBar.functions;\nMathBar.categories;\n\n//VIF - Very Importatnt Function\nfunction MathBar(outputID, options, callback) {\n    let self = this;\n\n    let $button = $(\"<button>\", { name: outputID, class: \"MathBarButton\" });\n    $button.click(function () { self.toggle(); });\n    $(\"#\" + outputID).append($(\"<div>\", { class: \"inside\" }).append($button));\n    self.button = $button;\n\n    if (options[\"layout\"] === undefined)\n        self.layout = \"singleline\";\n    else\n        self.layout = options[\"layout\"];\n\n    self.categories = MathBar.categories[options[\"type\"]];\n\n    if (options[\"VIF\"] === undefined || options[\"VIF\"] === \"max\")\n        self.numberOfVIF = self.categories.length;\n    else\n        self.numberOfVIF = options[\"VIF\"];\n\n    self.outputID = outputID;\n    self.defaultParameters = options[\"defaultParameters\"];\n    self.callback = callback;\n\n    self.drawn = false;\n    self.currentOption = \"\";\n    self.currentOptionVIF = true;\n    self.visible = false;\n    self.outputValue = $(\"#\" + outputID)[0].yacasExpression;\n\n    $button.on(\"keydown\", function (event) {\n        if (event.which === 13) {\n            event.preventDefault();\n            if (event.shiftKey)\n                this.mathBar.run();\n        }\n    });\n}\n\nMathBar.prototype.drawMathBar = function () {\n    let $functionsDiv = this.createFunctionsDiv();\n    let $submitButton = this.createSubmitButton();\n    let $mathBarTable = this.createMathBarTable();\n\n    $mathBarTable.find(\".functions\").append($functionsDiv);\n    $mathBarTable.find(\".submitButton\").append($submitButton);\n\n    let $mathBarElement = $(\"<div>\", { class: \"MathBar\" }).hide();\n\n    $(\"#\" + this.outputID).after($mathBarElement.append($mathBarTable));\n\n    this.mathBarElement = $mathBarElement;\n    $mathBarElement[0].mathBar = this;\n    this.show();\n\n    //In case number of all functions is 1 more than VIF do not display combobox with only one function\n    //but treat all of them as VIFs\n    if (this.layout !== \"multiline\")\n        if (this.numberOfVIF === this.categories.length)\n            $functionsDiv.parent().width($functionsDiv.width() + 1);\n        else\n            $functionsDiv.parent().width($functionsDiv.width());\n\n    this.optionClicked(this.categories[0], true);\n\n    let $functionsSelect = $functionsDiv.find(\"select\");\n    if ($functionsSelect) {\n        $functionsSelect.selectmenu();\n        $functionsSelect.on(\"selectmenuselect\", function () {\n            $mathBarElement = $(this).parents(\".MathBar:first\");\n            $mathBarElement[0].mathBar.optionClicked($(\"option:selected\", this).attr(\"name\"), false);\n        });\n    }\n};\n\nMathBar.prototype.createSubmitButton = function () {\n    let $submitButton = $(\"<button>\", { class: \"submitButton\" });\n    $submitButton.click(function () {\n        let $mathBarElement = $(this).parents(\".MathBar:first\");\n        $mathBarElement[0].mathBar.run();\n    });\n    return $submitButton;\n};\n\nMathBar.prototype.createFunctionsDiv = function () {\n    if (this.numberOfVIF > this.categories.length)\n        this.numberOfVIF = this.categories.length;\n\n    if (this.categories.length - this.numberOfVIF === 1)\n        this.numberOfVIF++;\n\n    let $functionsDiv = $(\"<div>\", { class: \"radio_group_horizontal styled_radio\" });\n    let i;\n    for (i = 0; i < this.numberOfVIF; i++) {\n\n        let func = MathBar.functions[this.categories[i]];\n        let text = func[\"text\"];\n\n        let $input = $(\"<input>\", { type: \"radio\", name: this.outputID, value: this.categories[i] });\n\n        if (i === 0)\n            $input.prop(\"checked\", true);\n\n        $input.click(function () {\n            let $mathBarElement = $(this).parents(\".MathBar:first\");\n            $mathBarElement[0].mathBar.optionClicked(this.value, true);\n        });\n\n        let $span = $(\"<span>\").append(text);\n        let $label = $(\"<label>\");\n        $label.append($input).append($span);\n\n        $functionsDiv.append($label);\n        $label.dblclick(function (e) { e.stopPropagation(); this.run(); });\n    }\n\n    if (i !== this.categories.length) {\n\n        let $functionsSelect = $(\"<select>\");\n        let $option = $(\"<option>\").append(MathBar.selectMoreText);\n        $option.attr(\"disabled\", true);\n        $option.attr(\"selected\", true);\n        $functionsSelect.append($option);\n\n        for (let j = this.numberOfVIF; j < this.categories.length; j++) {\n            let func = MathBar.functions[this.categories[j]];\n            let text = func[\"text\"];\n            $functionsSelect.append($(\"<option>\", { name: this.categories[j] }).append(text));\n        }\n\n        let $label = $(\"<label>\");\n        $label.dblclick(function (e) {\n            if ($label.find(\"option:selected\").val() === MathBar.selectMoreText)\n                return true;\n\n            e.stopPropagation();\n            this.run();\n            return false;\n        });\n        $functionsDiv.append($label.append($functionsSelect));\n    }\n\n    return $functionsDiv;\n};\n\nMathBar.prototype.createMathBarTable = function () {\n\n    if (this.layout === \"singleline\") {\n\n        let $mathRow = $(\"<tr>\");\n\n        $mathRow.append($(\"<td>\", { class: \"functions\" }));\n        $mathRow.append($(\"<td>\", { class: \"separator\" }));\n        $mathRow.append($(\"<td>\", { class: \"parameters\" }).append($(\"<div>\", { class: \"parameters\" })));\n        $mathRow.append($(\"<td>\", { class: \"submitButton\" }));\n\n        return $(\"<table>\").append($mathRow);\n    }\n\n    if (this.layout === \"multiline\") {\n        let $functionsRow = $(\"<tr>\");\n\n        $functionsRow.append($(\"<td>\", { class: \"functions\" }));\n        $functionsRow.append($(\"<td>\", { class: \"submitButton\" }));\n\n        let $parametersRow = $(\"<tr>\");\n        $parametersRow.append($(\"<td>\", { class: \"parameters\", colspan: \"2\" }).append($(\"<div>\", { class: \"parameters\" })));\n\n        return $(\"<table>\").append($functionsRow).append($parametersRow);\n    }\n};\n\n\nMathBar.keydownEventHandler = function (event) {\n    let $mathBarElement = $(this).parents(\".MathBar:first\");\n    if (event.which === 13 && event.shiftKey) {\n        event.preventDefault();\n        $mathBarElement[0].mathBar.run();\n        return false;\n    }\n    return true;\n};\n\n\nMathBar.parseFunctions = function () {\n    let keys = Object.keys(MathBar.categories);\n    for (let j = 0; j < keys.length; j++) {\n        let funcList = MathBar.categories[keys[j]];\n        for (let i = 0; i < funcList.length; i++) {\n            let ff = MathBar.functions[funcList[i]];\n            if (ff === undefined)\n                console.error(\"Function \" + funcList[i] + \" is not defined!\");\n        }\n    }\n    keys = Object.keys(MathBar.functions);\n    for (let j = 0; j < keys.length; j++) {\n        let func = MathBar.functions[keys[j]];\n        if (func[\"text\"] === undefined)\n            func[\"text\"] = keys[j];\n        let parameters = func[\"parameters\"];\n        if (parameters === undefined)\n            func[\"parameters\"] = [];\n\n        for (let i = 0; i < parameters.length; i++)\n            MathBar.parseParameter(parameters[i]);\n\n        if (func[\"parser\"] === undefined)\n            console.error(\"Parser for function: \" + keys[j] + \" is undefined\");\n        else\n            if (window[func[\"parser\"]] === undefined)\n                console.error(\"Parser: \" + func[\"parser\"] + \" is undefined\");\n    }\n};\n\nMathBar.parseParameter = function (parameter) {\n    if (parameter[\"parameterName\"] === undefined) {\n        console.error(\"Name of parameter is undefined: \" + parameter);\n        parameter[\"parameterName\"] = \"undefined\";\n    }\n\n    if (parameter[\"text\"] === undefined)\n        parameter[\"text\"] = parameter[\"parameterName\"];\n\n    if (parameter[\"parameterType\"] === undefined) {\n        parameter[\"parameterType\"] = \"edit\";\n        console.warning(\"Lack of type of parameter: \" + parameter[\"parameterName\"]);\n    }\n\n    if (parameter[\"defaultValue\"] === undefined)\n        switch (parameter[\"parameterType\"]) {\n            case \"label\":\n                parameter[\"defaultValue\"] = \"\";\n                break;\n            case \"edit\":\n                parameter[\"defaultValue\"] = \"\";\n                break;\n            case \"checkbox\":\n                parameter[\"defaultValue\"] = false;\n                break;\n            case \"condition\":\n                parameter[\"defaultValue\"] = false;\n                break;\n            case \"select\":\n                parameter[\"defaultValue\"] = [];\n                break;\n            default:\n                console.error(\"This paramter type is not implemented: \" + parameter[\"parameterType\"] + \"!\");\n        }\n\n    if (parameter[\"parameterType\"] === \"edit\")\n        if (parameter[\"widestValue\"] !== undefined)\n            parameter[\"inputWidth\"] = MathBar.calculateInputWidth(parameter[\"widestValue\"]);\n        else\n            parameter[\"inputWidth\"] = MathBar.calculateInputWidth(parameter[\"defaultValue\"]) * 3;\n\n    let parameters = parameter[\"parameters\"];\n    if (parameters !== undefined)\n        for (let i = 0; i < parameters.length; i++)\n            MathBar.parseParameter(parameters[i]);\n};\n\nMathBar.prototype.optionClicked = function (functionName, VIF) {\n\n    if (this.currentOptionVIF && functionName === MathBar.selectMoreText)\n        return;\n    this.currentOptionVIF = VIF;\n    this.currentOption = functionName;\n\n\n    let $parametersElement = $(this.mathBarElement).find(\".parameters\");\n    $parametersElement.html(\"\");\n\n    if (functionName === MathBar.selectMoreText)\n        return;\n\n    if (!VIF) {\n        $(this.mathBarElement).find(\"input:checked\").prop(\"checked\", false);\n        $(this.mathBarElement).find(\"select\").parent().addClass(\"checked\");\n    } else {\n        $(this.mathBarElement).find(\"select\").parent().removeClass(\"checked\");\n    }\n\n    let func = MathBar.functions[functionName];\n    let parameters = func[\"parameters\"];\n\n    for (let i = 0; i < parameters.length; i++)\n        $parametersElement.append(this.getPropertyLabel(parameters[i]));\n\n    $parametersElement.find(\"select\").selectmenu();\n};\n\nMathBar.prototype.changeConstToVariables = function (text) {\n\n    let variables = this.defaultParameters[\"variable\"];\n\n    if (variables === undefined)\n        return text;\n\n    if ($.isArray(text)) {\n        for (let k = 0; k < text.length; k++)\n            text[k] = this.changeConstToVariables(text[k]);\n        return text;\n    }\n\n    if (variables.length === 1)\n        text = text.replace(\"%VARIABLE%\", variables);\n\n    if (variables.length > 1)\n        for (let j = 0; j < variables.length; j++) {\n            let textToSearch = \"%VARIABLE%\" + j + \"%\";\n            text = text.replace(textToSearch, variables[j]);\n        }\n\n    return text;\n};\n\nMathBar.prototype.getPropertyLabel = function (parameter) {\n    let $label = $(\"<label>\");\n    let type = parameter[\"parameterType\"];\n\n    let value;\n    if (this.defaultParameters !== undefined)\n        value = this.defaultParameters[parameter[\"parameterName\"]];\n\n    if (value === undefined)\n        value = parameter[\"defaultValue\"];\n\n    let text = parameter[\"text\"];\n\n    if (this.defaultParameters !== undefined) {\n        value = this.changeConstToVariables(value);\n        text = this.changeConstToVariables(text);\n    }\n\n    if (type === \"select\" && value.length === 1) {\n        type = \"label\";\n        value = value[0];\n    }\n\n    if (type === \"label\") {\n        let $span = $(\"<span>\", { class: \"parameter\", name: parameter[\"parameterName\"] });\n        $span.append(value);\n\n        if (text === \"\")\n            $span.css(\"margin-left\", \"0px\");\n        else\n            $label.append(text);\n\n        $label.append($span);\n    }\n\n    if (type === \"edit\") {\n        let $input = $(\"<input>\", { type: \"text\", name: parameter[\"parameterName\"] });\n        $input.keydown(MathBar.keydownEventHandler);\n        $input.css(\"width\", parameter[\"inputWidth\"]);\n        $input.val(value);\n\n        if (text !== \"\")\n            $label.append(text);\n\n        $label.append($input);\n    }\n\n    if (type === \"checkbox\") {\n        let $input = $(\"<input>\", { type: \"checkbox\", name: parameter[\"parameterName\"] });\n        $input.prop(\"checked\", value);\n        $label.append($input).append(text);\n    }\n\n    if (type === \"condition\") {\n        let $input = $(\"<input>\", { type: \"checkbox\", name: parameter[\"parameterName\"] });\n\n        let checked = value === \"true\";\n\n        $input.change(function () {\n            let $mathBarElement = $(this).parents(\".MathBar:first\");\n            MathBar.toggleParameters($mathBarElement, parameter[\"parameterName\"], !$(this).is(\":checked\"));\n        });\n\n        $input.prop(\"checked\", checked);\n        $label.append($input).append(text);\n\n        let conditionalParameters = parameter[\"parameters\"];\n        let $outerlabel = $(\"<span>\").append($label);\n\n        for (let i = 0; i < conditionalParameters.length; i++) {\n            let $condparLabel = this.getPropertyLabel(conditionalParameters[i]);\n            $condparLabel.addClass(\"check_\" + parameter[\"parameterName\"]);\n\n            if (!checked) {\n                $condparLabel.addClass(\"labelDisabled\");\n                $condparLabel.find(\"input\").prop(\"disabled\", true);\n                $condparLabel.find(\"select\").prop(\"disabled\", true);\n            }\n\n            $outerlabel.append($condparLabel);\n        }\n\n        $label = $outerlabel;\n    }\n\n    if (type === \"select\") {\n\n        let $select = $(\"<select>\", { name: parameter[\"parameterName\"] });\n\n        for (let i = 0; i < value.length; i++)\n            $select.append($(\"<option>\").append(value[i]));\n\n        $label.append(text).append($select);\n    }\n\n    return $label;\n};\n\nMathBar.toggleParameters = function ($mathBarElement, parameterName, disabled) {\n    let $label = $mathBarElement.find(\".check_\" + parameterName).toggleClass(\"labelDisabled\", disabled);\n    $label.find(\"input\").prop(\"disabled\", disabled);\n    if (disabled)\n        $label.find(\"select\").selectmenu(\"disable\");\n    else\n        $label.find(\"select\").selectmenu(\"enable\");\n};\n\nMathBar.prototype.getPropertyValue = function (parameter, outValues) {\n    let type = parameter[\"parameterType\"];\n    let parameterName = parameter[\"parameterName\"];\n\n    let $element = this.mathBarElement.find(\"[name='\" + parameterName + \"']:first\");\n\n    switch (type) {\n        case \"label\":\n            outValues[parameterName] = $element.text();\n            break;\n        case \"edit\":\n            outValues[parameterName] = $element.val();\n            break;\n        case \"checkbox\":\n            outValues[parameterName] = $element.prop(\"checked\");\n            break;\n        case \"condition\":\n            outValues[parameterName] = $element.prop(\"checked\");\n\n            let conditionalParameters = parameter[\"parameters\"];\n            for (let i = 0; i < conditionalParameters.length; i++)\n                this.getPropertyValue(conditionalParameters[i], outValues);\n            break;\n        case \"select\":\n            if ($element.val() !== \"\")\n                outValues[parameterName] = $element.val();\n            else\n                outValues[parameterName] = $element.text();\n            break;\n        default:\n            console.error(\"This paramter type is not implemented: \" + type + \"!\");\n    }\n};\n\nMathBar.prototype.run = function () {\n\n    let func = MathBar.functions[this.currentOption];\n\n    let parameters = func[\"parameters\"];\n    let outValues = [];\n\n    for (let i = 0; i < parameters.length; i++)\n        this.getPropertyValue(parameters[i], outValues);\n\n    let parser = func[\"parser\"];\n    let result = window[parser](this.outputValue, outValues);\n\n    this.callback(result, this.outputID);\n    this.hide();\n};\n\nMathBar.prototype.remove = function () {\n    this.button.mathBar = null;\n    this.mathBarElement.slideUp(300, function () { this.remove(); });\n    $(this.button).removeClass(\"up\");\n};\n\nMathBar.prototype.show = function () {\n    this.visible = true;\n    this.mathBarElement.slideDown(300);\n    $(this.button).addClass(\"up\");\n};\n\nMathBar.prototype.hide = function () {\n    this.visible = false;\n    this.mathBarElement.slideUp(300);\n    $(this.button).removeClass(\"up\");\n};\n\nMathBar.prototype.toggle = function () {\n\n    if (this.visible)\n        this.hide();\n    else\n        if (!this.drawn) this.drawMathBar();\n    this.show();\n};\n\n\nMathBar.initializeFunctions = function (jsonfile) {\n    let xhttp = new XMLHttpRequest();\n    xhttp.onreadystatechange = function () {\n        if (xhttp.readyState === 4)\n            if (xhttp.status === 200 || xhttp.status === 0) {\n                const data = jQuery.parseJSON(xhttp.responseText);\n                MathBar.functions = data[\"functions\"];\n                MathBar.categories = data[\"categories\"];\n                MathBar.parseFunctions();\n            } else {\n                console.error(\"Couldn't load json file\");\n            }\n    };\n\n    xhttp.open(\"GET\", jsonfile, true);\n    xhttp.send();\n};\n\nMathBar.supportsExpressionType = function (expressionType, numberOfVariables) {\n    if (numberOfVariables > 0)\n        expressionType += \"_\" + numberOfVariables;\n\n    if (MathBar.categories[expressionType] !== undefined)\n        return true;\n\n    return false;\n};\n\nMathBar.calculateInputWidth = function (value) {\n    let $testDiv = $(\"#MathBarStringWidthTest\");\n    $testDiv.show();\n    $testDiv.text(value);\n    let width = $testDiv.width() + 1;\n    $testDiv.hide();\n    return width;\n};\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/mathbar/mathbar.css",
    "content": "\n.outside {\n    position: relative;\n}\n\n.inside {\n    position: absolute;\n    right: 2px;\n    bottom: 2px;\n}\n\n.radio_group_horizontal label {\n    display: inline-block;\n    text-align: center;\n    padding: 0 2px 0 0;\n}\n\n.MathBar {\n    background-color: #f5faff;\n    border: 1px solid #c2e0ff;\n    -webkit-box-sizing: border-box;\n    box-sizing: border-box;\n    width: 100%;\n    padding: 0;\n}\n\n.MathBar table {\n    table-layout: fixed;\n    width: 100%;\n    border-spacing: 0;\n    padding: 2px;\n}\n\n.MathBar td {\n    font-family: sans-serif;\n    padding: 0;\n}\n\n.MathBar td.functions {\n    vertical-align: top;\n    width: 100%;\n}\n\n.MathBar .separator {\n    width: 1px;\n    background-color: #c2e0ff;\n}\n\n.MathBar td.parameters {\n    word-wrap: break-word;\n    vertical-align: middle;\n    padding-left: 3px;\n    color: #555;\n}\n\n.Expression button.MathBarButton {\n    background: url(./images/double_arrows_down_disabled.png) center center no-repeat;\n    background-size: 8px 8px;\n    width: 12px;\n    height: 12px;\n    border: none;\n    cursor: pointer;\n}\n\n.Expression:hover button.MathBarButton {\n    background: url(./images/double_arrows_down.png) center center no-repeat;\n    background-size: 8px 8px;\n}\n\n.Expression button.MathBarButton.up {\n    background: url(./images/double_arrows_up_disabled.png) center center no-repeat;\n    background-size: 8px 8px;\n}\n\n.Expression:hover button.MathBarButton.up {\n    background: url(./images/double_arrows_up.png) center center no-repeat;\n    background-size: 8px 8px;\n}\n\n.MathBar button.submitButton {\n    background: url(./images/mathBar_submit_triangle_gradient_light.png) center center no-repeat;\n    width: 16px;\n    height: 16px;\n    border: none;\n    cursor: pointer;\n}\n\n.MathBar button.submitButton:hover {\n    background: url(./images/mathBar_submit_triangle_gradient.png) center center no-repeat;\n}\n\n.MathBar td.submitButton {\n    width: 16px;\n    padding: 0 3px;\n    margin: 0;\n    white-space: nowrap;\n}\n\n.MathBar input {\n    border: 1px solid #c2e0ff;\n    padding-left: 5px;\n    padding-right: 2px;\n    margin-left: 5px;\n    margin-right: 0;\n    text-align: right;\n    color: #246bb2;\n}\n\n.MathBar span.parameter {\n    border: 1px solid #c2e0ff;\n    padding: 1px 5px;\n    margin: 2px 0 2px 5px;\n    display: inline-block;\n    height: 15px;\n    color: #246bb2;\n}\n\n.MathBar input[type=\"text\"]:disabled {\n    -webkit-text-fill-color: #246bb2;\n}\n\n.MathBar .parameters label {\n    margin-left: 2px;\n    margin-right: 2px;\n    margin-top: 4px;\n    display: inline-block;\n    white-space: nowrap;\n    padding-right: 2px;\n}\n\n.MathBar label.labelDisabled {\n    opacity: 0.35;\n}\n\n.MathBar .parameters input[type=checkbox] {\n    margin: 0;\n}\n\n.styled_radio input[type=radio] {\n    display: none;\n}\n\n.parameters label > span[role=combobox] {\n    background: url(./images/mathBar_combobox_triangle.png) right 5px center no-repeat, linear-gradient(white, white);\n    border: 1px solid #c2e0ff;\n    padding: 1px;\n    padding-left: 5px;\n    margin-left: 5px;\n}\n\n.styled_radio label > span {\n    cursor: pointer;\n    display: block;\n    line-height: 20px;\n    padding: 2px 6px;\n    -webkit-user-select: none;\n    background: linear-gradient(white, #f3f9ff);\n    border: 1px solid #246bb2;\n    color: #246bb2;\n    margin: 0;\n}\n\n.styled_radio label > span[role=combobox] {\n    background: url(./images/mathBar_combobox_triangle.png) right 5px center no-repeat, linear-gradient(white, #f3f9ff);\n}\n\n.styled_radio label > span:hover {\n    background: linear-gradient(white, #d6ebff);\n}\n\n.styled_radio label.checked > span {\n    background: linear-gradient(#47a3ff, #246bb2);\n    text-decoration: none;\n    color: white;\n}\n\n.styled_radio label.checked > span:hover {\n    color: #e7eef8;\n    background: linear-gradient(#47a3ff, #246bb2);\n}\n\n.styled_radio input[type=radio]:checked + span {\n    background: linear-gradient(#47a3ff, #246bb2);\n    text-decoration: none;\n    color: white;\n}\n\n.styled_radio input[type=radio]:checked:hover + span {\n    color: #e7eef8;\n}\n\n.styled_radio label.checked > span[role=combobox] {\n    background: url(./images/mathBar_combobox_triangle_white.png) right 5px center no-repeat, linear-gradient(#47a3ff, #246bb2);\n}\n\n.styled_radio label > span[role=combobox]:hover {\n    background: url(./images/mathBar_combobox_triangle.png) right 5px center no-repeat, linear-gradient(white, #d6ebff);\n}\n\n.parameters label > span[role=combobox]:not(.ui-state-disabled):hover {\n    background: url(./images/mathBar_combobox_triangle.png) right 5px center no-repeat, linear-gradient(white, #d6ebff);\n    color: #246bb2;\n}\n\n.MathBar .parameters .ui-state-focus {\n    color: #246bb2;\n}\n\n.MathBar .parameters .ui-state-default {\n    color: #246bb2;\n    opacity: 1;\n}\n\n.MathBar select {\n    margin: 0;\n}\n\n.radio_group_horizontal {\n    padding: 0;\n    margin: 0;\n    display: inline-block;\n}\n\n#MathBarStringWidthTest {\n    position: absolute;\n    visibility: hidden;\n    height: auto;\n    width: auto;\n    white-space: nowrap;\n    padding-left: 5px;\n    padding-right: 5px;\n    font-family: sans-serif;\n    font-size: small;\n    border-spacing: 2px;\n    display: none;\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/webchannel/qwebchannel.js",
    "content": "/****************************************************************************\n**\n** Copyright (C) 2016 The Qt Company Ltd.\n** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>\n** Contact: https://www.qt.io/licensing/\n**\n** This file is part of the QtWebChannel module of the Qt Toolkit.\n**\n** $QT_BEGIN_LICENSE:LGPL$\n** Commercial License Usage\n** Licensees holding valid commercial Qt licenses may use this file in\n** accordance with the commercial license agreement provided with the\n** Software or, alternatively, in accordance with the terms contained in\n** a written agreement between you and The Qt Company. For licensing terms\n** and conditions see https://www.qt.io/terms-conditions. For further\n** information use the contact form at https://www.qt.io/contact-us.\n**\n** GNU Lesser General Public License Usage\n** Alternatively, this file may be used under the terms of the GNU Lesser\n** General Public License version 3 as published by the Free Software\n** Foundation and appearing in the file LICENSE.LGPL3 included in the\n** packaging of this file. Please review the following information to\n** ensure the GNU Lesser General Public License version 3 requirements\n** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.\n**\n** GNU General Public License Usage\n** Alternatively, this file may be used under the terms of the GNU\n** General Public License version 2.0 or (at your option) the GNU General\n** Public license version 3 or any later version approved by the KDE Free\n** Qt Foundation. The licenses are as published by the Free Software\n** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3\n** included in the packaging of this file. Please review the following\n** information to ensure the GNU General Public License requirements will\n** be met: https://www.gnu.org/licenses/gpl-2.0.html and\n** https://www.gnu.org/licenses/gpl-3.0.html.\n**\n** $QT_END_LICENSE$\n**\n****************************************************************************/\n\n\"use strict\";\n\nvar QWebChannelMessageTypes = {\n    signal: 1,\n    propertyUpdate: 2,\n    init: 3,\n    idle: 4,\n    debug: 5,\n    invokeMethod: 6,\n    connectToSignal: 7,\n    disconnectFromSignal: 8,\n    setProperty: 9,\n    response: 10,\n};\n\nvar QWebChannel = function(transport, initCallback)\n{\n    if (typeof transport !== \"object\" || typeof transport.send !== \"function\") {\n        console.error(\"The QWebChannel expects a transport object with a send function and onmessage callback property.\" +\n                      \" Given is: transport: \" + typeof(transport) + \", transport.send: \" + typeof(transport.send));\n        return;\n    }\n\n    var channel = this;\n    this.transport = transport;\n\n    this.send = function(data)\n    {\n        if (typeof(data) !== \"string\") {\n            data = JSON.stringify(data);\n        }\n        channel.transport.send(data);\n    }\n\n    this.transport.onmessage = function(message)\n    {\n        var data = message.data;\n        if (typeof data === \"string\") {\n            data = JSON.parse(data);\n        }\n        switch (data.type) {\n            case QWebChannelMessageTypes.signal:\n                channel.handleSignal(data);\n                break;\n            case QWebChannelMessageTypes.response:\n                channel.handleResponse(data);\n                break;\n            case QWebChannelMessageTypes.propertyUpdate:\n                channel.handlePropertyUpdate(data);\n                break;\n            default:\n                console.error(\"invalid message received:\", message.data);\n                break;\n        }\n    }\n\n    this.execCallbacks = {};\n    this.execId = 0;\n    this.exec = function(data, callback)\n    {\n        if (!callback) {\n            // if no callback is given, send directly\n            channel.send(data);\n            return;\n        }\n        if (channel.execId === Number.MAX_VALUE) {\n            // wrap\n            channel.execId = Number.MIN_VALUE;\n        }\n        if (data.hasOwnProperty(\"id\")) {\n            console.error(\"Cannot exec message with property id: \" + JSON.stringify(data));\n            return;\n        }\n        data.id = channel.execId++;\n        channel.execCallbacks[data.id] = callback;\n        channel.send(data);\n    };\n\n    this.objects = {};\n\n    this.handleSignal = function(message)\n    {\n        var object = channel.objects[message.object];\n        if (object) {\n            object.signalEmitted(message.signal, message.args);\n        } else {\n            console.warn(\"Unhandled signal: \" + message.object + \"::\" + message.signal);\n        }\n    }\n\n    this.handleResponse = function(message)\n    {\n        if (!message.hasOwnProperty(\"id\")) {\n            console.error(\"Invalid response message received: \", JSON.stringify(message));\n            return;\n        }\n        channel.execCallbacks[message.id](message.data);\n        delete channel.execCallbacks[message.id];\n    }\n\n    this.handlePropertyUpdate = function(message)\n    {\n        for (var i in message.data) {\n            var data = message.data[i];\n            var object = channel.objects[data.object];\n            if (object) {\n                object.propertyUpdate(data.signals, data.properties);\n            } else {\n                console.warn(\"Unhandled property update: \" + data.object + \"::\" + data.signal);\n            }\n        }\n        channel.exec({type: QWebChannelMessageTypes.idle});\n    }\n\n    this.debug = function(message)\n    {\n        channel.send({type: QWebChannelMessageTypes.debug, data: message});\n    };\n\n    channel.exec({type: QWebChannelMessageTypes.init}, function(data) {\n        for (var objectName in data) {\n            var object = new QObject(objectName, data[objectName], channel);\n        }\n        // now unwrap properties, which might reference other registered objects\n        for (var objectName in channel.objects) {\n            channel.objects[objectName].unwrapProperties();\n        }\n        if (initCallback) {\n            initCallback(channel);\n        }\n        channel.exec({type: QWebChannelMessageTypes.idle});\n    });\n};\n\nfunction QObject(name, data, webChannel)\n{\n    this.__id__ = name;\n    webChannel.objects[name] = this;\n\n    // List of callbacks that get invoked upon signal emission\n    this.__objectSignals__ = {};\n\n    // Cache of all properties, updated when a notify signal is emitted\n    this.__propertyCache__ = {};\n\n    var object = this;\n\n    // ----------------------------------------------------------------------\n\n    this.unwrapQObject = function(response)\n    {\n        if (response instanceof Array) {\n            // support list of objects\n            var ret = new Array(response.length);\n            for (var i = 0; i < response.length; ++i) {\n                ret[i] = object.unwrapQObject(response[i]);\n            }\n            return ret;\n        }\n        if (!response\n            || !response[\"__QObject*__\"]\n            || response.id === undefined) {\n            return response;\n        }\n\n        var objectId = response.id;\n        if (webChannel.objects[objectId])\n            return webChannel.objects[objectId];\n\n        if (!response.data) {\n            console.error(\"Cannot unwrap unknown QObject \" + objectId + \" without data.\");\n            return;\n        }\n\n        var qObject = new QObject( objectId, response.data, webChannel );\n        qObject.destroyed.connect(function() {\n            if (webChannel.objects[objectId] === qObject) {\n                delete webChannel.objects[objectId];\n                // reset the now deleted QObject to an empty {} object\n                // just assigning {} though would not have the desired effect, but the\n                // below also ensures all external references will see the empty map\n                // NOTE: this detour is necessary to workaround QTBUG-40021\n                var propertyNames = [];\n                for (var propertyName in qObject) {\n                    propertyNames.push(propertyName);\n                }\n                for (var idx in propertyNames) {\n                    delete qObject[propertyNames[idx]];\n                }\n            }\n        });\n        // here we are already initialized, and thus must directly unwrap the properties\n        qObject.unwrapProperties();\n        return qObject;\n    }\n\n    this.unwrapProperties = function()\n    {\n        for (var propertyIdx in object.__propertyCache__) {\n            object.__propertyCache__[propertyIdx] = object.unwrapQObject(object.__propertyCache__[propertyIdx]);\n        }\n    }\n\n    function addSignal(signalData, isPropertyNotifySignal)\n    {\n        var signalName = signalData[0];\n        var signalIndex = signalData[1];\n        object[signalName] = {\n            connect: function(callback) {\n                if (typeof(callback) !== \"function\") {\n                    console.error(\"Bad callback given to connect to signal \" + signalName);\n                    return;\n                }\n\n                object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];\n                object.__objectSignals__[signalIndex].push(callback);\n\n                if (!isPropertyNotifySignal && signalName !== \"destroyed\") {\n                    // only required for \"pure\" signals, handled separately for properties in propertyUpdate\n                    // also note that we always get notified about the destroyed signal\n                    webChannel.exec({\n                        type: QWebChannelMessageTypes.connectToSignal,\n                        object: object.__id__,\n                        signal: signalIndex\n                    });\n                }\n            },\n            disconnect: function(callback) {\n                if (typeof(callback) !== \"function\") {\n                    console.error(\"Bad callback given to disconnect from signal \" + signalName);\n                    return;\n                }\n                object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];\n                var idx = object.__objectSignals__[signalIndex].indexOf(callback);\n                if (idx === -1) {\n                    console.error(\"Cannot find connection of signal \" + signalName + \" to \" + callback.name);\n                    return;\n                }\n                object.__objectSignals__[signalIndex].splice(idx, 1);\n                if (!isPropertyNotifySignal && object.__objectSignals__[signalIndex].length === 0) {\n                    // only required for \"pure\" signals, handled separately for properties in propertyUpdate\n                    webChannel.exec({\n                        type: QWebChannelMessageTypes.disconnectFromSignal,\n                        object: object.__id__,\n                        signal: signalIndex\n                    });\n                }\n            }\n        };\n    }\n\n    /**\n     * Invokes all callbacks for the given signalname. Also works for property notify callbacks.\n     */\n    function invokeSignalCallbacks(signalName, signalArgs)\n    {\n        var connections = object.__objectSignals__[signalName];\n        if (connections) {\n            connections.forEach(function(callback) {\n                callback.apply(callback, signalArgs);\n            });\n        }\n    }\n\n    this.propertyUpdate = function(signals, propertyMap)\n    {\n        // update property cache\n        for (var propertyIndex in propertyMap) {\n            var propertyValue = propertyMap[propertyIndex];\n            object.__propertyCache__[propertyIndex] = propertyValue;\n        }\n\n        for (var signalName in signals) {\n            // Invoke all callbacks, as signalEmitted() does not. This ensures the\n            // property cache is updated before the callbacks are invoked.\n            invokeSignalCallbacks(signalName, signals[signalName]);\n        }\n    }\n\n    this.signalEmitted = function(signalName, signalArgs)\n    {\n        invokeSignalCallbacks(signalName, this.unwrapQObject(signalArgs));\n    }\n\n    function addMethod(methodData)\n    {\n        var methodName = methodData[0];\n        var methodIdx = methodData[1];\n        object[methodName] = function() {\n            var args = [];\n            var callback;\n            for (var i = 0; i < arguments.length; ++i) {\n                var argument = arguments[i];\n                if (typeof argument === \"function\")\n                    callback = argument;\n                else if (argument instanceof QObject && webChannel.objects[argument.__id__] !== undefined)\n                    args.push({\n                        \"id\": argument.__id__\n                    });\n                else\n                    args.push(argument);\n            }\n\n            webChannel.exec({\n                \"type\": QWebChannelMessageTypes.invokeMethod,\n                \"object\": object.__id__,\n                \"method\": methodIdx,\n                \"args\": args\n            }, function(response) {\n                if (response !== undefined) {\n                    var result = object.unwrapQObject(response);\n                    if (callback) {\n                        (callback)(result);\n                    }\n                }\n            });\n        };\n    }\n\n    function bindGetterSetter(propertyInfo)\n    {\n        var propertyIndex = propertyInfo[0];\n        var propertyName = propertyInfo[1];\n        var notifySignalData = propertyInfo[2];\n        // initialize property cache with current value\n        // NOTE: if this is an object, it is not directly unwrapped as it might\n        // reference other QObject that we do not know yet\n        object.__propertyCache__[propertyIndex] = propertyInfo[3];\n\n        if (notifySignalData) {\n            if (notifySignalData[0] === 1) {\n                // signal name is optimized away, reconstruct the actual name\n                notifySignalData[0] = propertyName + \"Changed\";\n            }\n            addSignal(notifySignalData, true);\n        }\n\n        Object.defineProperty(object, propertyName, {\n            configurable: true,\n            get: function () {\n                var propertyValue = object.__propertyCache__[propertyIndex];\n                if (propertyValue === undefined) {\n                    // This shouldn't happen\n                    console.warn(\"Undefined value in property cache for property \\\"\" + propertyName + \"\\\" in object \" + object.__id__);\n                }\n\n                return propertyValue;\n            },\n            set: function(value) {\n                if (value === undefined) {\n                    console.warn(\"Property setter for \" + propertyName + \" called with undefined value!\");\n                    return;\n                }\n                object.__propertyCache__[propertyIndex] = value;\n                var valueToSend = value;\n                if (valueToSend instanceof QObject && webChannel.objects[valueToSend.__id__] !== undefined)\n                    valueToSend = { \"id\": valueToSend.__id__ };\n                webChannel.exec({\n                    \"type\": QWebChannelMessageTypes.setProperty,\n                    \"object\": object.__id__,\n                    \"property\": propertyIndex,\n                    \"value\": valueToSend\n                });\n            }\n        });\n\n    }\n\n    // ----------------------------------------------------------------------\n\n    data.methods.forEach(addMethod);\n\n    data.properties.forEach(bindGetterSetter);\n\n    data.signals.forEach(function(signal) { addSignal(signal, false); });\n\n    for (var name in data.enums) {\n        object[name] = data.enums[name];\n    }\n}\n\n//required for use with nodejs\nif (typeof module === 'object') {\n    module.exports = {\n        QWebChannel: QWebChannel\n    };\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/yacas-online.html",
    "content": "<!DOCTYPE html >\n\n<html>\n    <head>\n        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n        \n        <title>Yacas Online</title>\n\n        <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css\">\n        <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/w2ui/1.4.3/w2ui.css\" />\n        <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/fontawesome.css\" />\n        <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.css\" />\n        <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/hint/show-hint.css\" />\n        <link rel=\"stylesheet\" href=\"yacas_gui/yacas_gui.css?v=14\" />\n        <link rel=\"stylesheet\" href=\"mathbar/mathbar.css\" />\n        <link rel=\"stylesheet\" href=\"jquery/jquery-ui.min.css\" />\n        <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.css\" />\n\n        <script type=\"text/x-mathjax-config\">\n            MathJax.Hub.Config({\n                        tex2jax: {\n                            inlineMath: [[\"$\",\"$\"],[\"\\\\(\",\"\\\\)\"]],\n                            displayMath: [[\"$$\",\"$$\"], [\"\\[\",\"\\]\"]]\n                        },\n                        CommonHTML: {\n                            linebreaks: { automatic: true },\n                            scale: 80\n                        },\n                        showMathMenu: false,\n                        displayAlign: \"left\"\n            });\n        </script>\n        \n        <script type=\"text/javascript\" src=\"yacas_gui/yacas_gui.js?v=14\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.min.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery-ui.min.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.jeditable.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.jeditable.autogrow.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.autosize.min.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.ui-contextmenu.min.js\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_CHTML\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.49.5/plotly.min.js\"></script>\n        <script type=\"text/javascript\" src=\"mathbar/mathBar.js?v=4\"></script>  \n        <script type=\"text/javascript\" src=\"mathbar/functions_parser.js?v=4\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.js\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/yacas/yacas.js\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/edit/matchbrackets.js\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/edit/closebrackets.js\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/hint/show-hint.js\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/hint/anyword-hint.js\"></script>\n        <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/w2ui/1.4.3/w2ui.js\"></script>\n        \n        <script type='text/javascript'>\n          String.prototype.beginsWith = function (string) {\n              return(this.indexOf(string) === 0);\n          };\n\n          var yacas;\n          \n          var Module = {\n              noInitialRun: true,\n              onRuntimeInitialized: function() {\n                  var yacas_evaluate = Module.cwrap('yacas_evaluate', null, ['string']);\n                  var yacas_is_error = Module.cwrap('yacas_is_error', 'number', []);\n                  var yacas_result = Module.cwrap('yacas_result', 'string', []);\n                  var yacas_side_effects = Module.cwrap('yacas_side_effects', 'string', []);\n                  var yacas_complete = Module.cwrap('yacas_complete', 'string', ['string']);\n\n                  yacas_evaluate(\"Plot2D'outputs();\");\n                  yacas_evaluate(\"UnProtect(Plot2D'outputs);\");\n                  yacas_evaluate(\"Plot2D'yagy(values_IsList, _options'hash) <-- Yagy'Plot2D'Data(values, options'hash);\");\n                  yacas_evaluate(\"Plot2D'outputs() := { {\\\"default\\\", \\\"yagy\\\"}, {\\\"data\\\", \\\"Plot2D'data\\\"}, {\\\"gnuplot\\\", \\\"Plot2D'gnuplot\\\"}, {\\\"java\\\", \\\"Plot2D'java\\\"}, {\\\"yagy\\\", \\\"Plot2D'yagy\\\"}, };\");\n                  yacas_evaluate(\"Protect(Plot2D'outputs);\");\n\n                  yacas_evaluate(\"Plot3DS'outputs();\");\n                  yacas_evaluate(\"UnProtect(Plot3DS'outputs);\");\n                  yacas_evaluate(\"Plot3DS'yagy(values_IsList, _options'hash) <-- Yagy'Plot3DS'Data(values, options'hash);\");\n                  yacas_evaluate(\"Plot3DS'outputs() := { {\\\"default\\\", \\\"yagy\\\"}, {\\\"data\\\", \\\"Plot3DS'data\\\"}, {\\\"gnuplot\\\", \\\"Plot3DS'gnuplot\\\"}, {\\\"yagy\\\", \\\"Plot3DS'yagy\\\"},};\");\n                  yacas_evaluate(\"Protect(Plot3DS'outputs);\");\n                  \n                  yacas = {\n                      isWebGLEnabled: function () {\n                          return true;\n                      },\n                      eval: function (idx, expr) {\n\n                          var evaluationResult = {\n                              idx: idx,\n                              input: expr,\n                          };\n\n                          yacas_evaluate(expr);\n\n                          var side_effects = yacas_side_effects();\n                          \n                          if (side_effects !== '')\n                              evaluationResult['side_effects'] = side_effects;\n                          \n                          var result = yacas_result().trim();\n\n                          var is_error = yacas_is_error();\n\n                          if (!is_error)\n                              result = result.substr(0, result.length - 1);\n                          \n                          if (is_error) {\n                              evaluationResult['type'] = 'Error';\n                              evaluationResult['error_message'] = result;\n                          } else if (result.beginsWith('Graph(')) {\n                              result = result.substr(6, result.length - 7);\n                              var parts = result.substr(1, result.length - 2).split('},{');\n                              var vertices = parts[0].split(',');\n                              var edges = [];\n                              var t = parts[1].split(',');\n                              for (var i = 0; i < t.length; ++i) {\n                                  var bi = true;\n                                  var ft = t[i].split('<->');\n                                  if (ft.length == 1) {\n                                      ft = t[i].split('->');\n                                      bi = false;\n                                  }\n                                  edges.push({from: vertices.indexOf(ft[0]) + 1, to: vertices.indexOf(ft[1]) + 1, bi: bi});\n                              }\n                              \n                              evaluationResult['type'] = 'Graph';\n                              evaluationResult['graph_vertices'] = vertices;\n                              evaluationResult['graph_edges'] = edges;\n                              \n                          } else if (result.beginsWith(\"Yagy'Plot2D'Data(\")) {\n                              result = result.substr(17, result.length - 18);\n                              var parts = result.split(\"}},{{\");\n                              var optionsString = parts.pop();\n                              options = optionsString.substr(0, optionsString.length - 2).split('},{');\n\n                              var labels = [];\n                              \n                              for (var i = 0; i < options.length; ++i) {\n                                  var match = /(\"[^\",]+?\"),(.+)/.exec(options[i]);\n                                  if (match[1] === '\"yname\"') {\n                                      var s = match[2];\n                                      s = s.substr(2, s.length - 4);\n                                      labels = s.split(/\",(?=(?:[^\\\\\"\"]*\\\\\"\"[^\\\\\"\"]*\\\\\"\")*(?![^\\\\\"\"]*\\\\\"\"))\"/);\n                                  }\n                              }\n\n                              var data = [];\n                              \n                              for (var i = 0; i < parts.length; ++i) {\n                                  var part = parts[i].replace('{{{', '').replace('}}}', '');\n                                  var points = part.split('},{');\n                                  var partialData = [];\n                                  for (var j = 0; j < points.length; ++j) {\n                                      var point = points[j].replace('{', '').replace('}', '').split(',');\n                                      for (var k = 0; k < point.length; ++k)\n                                          point[k] = parseFloat(point[k]);\n                                      partialData.push(point);\n                                  }\n                                  data.push({label: labels[i], data: partialData});\n                              }\n\n                              evaluationResult['type'] = 'Plot2D';\n                              evaluationResult['plot2d_data'] = data;\n\n                          } else if (result.beginsWith(\"Yagy'Plot3DS'Data(\")) {\n                              result = result.substr(18, result.length - 19);\n                              var parts = result.split(\"}},{{\");\n                              var optionsString = parts.pop();\n                              options = optionsString.substr(0, optionsString.length - 2).split('},{');\n\n                              var labels = [];\n                              \n                              for (var i = 0; i < options.length; ++i) {\n                                  var match = /(\"[^\",]+?\"),(.+)/.exec(options[i]);\n                                  if (match[1] === '\"zname\"') {\n                                      var s = match[2];\n                                      s = s.substr(2, s.length - 4);\n                                      labels = s.split(/\",(?=(?:[^\\\\\"\"]*\\\\\"\"[^\\\\\"\"]*\\\\\"\")*(?![^\\\\\"\"]*\\\\\"\"))\"/);\n                                  }\n                              }\n\n                              var data = [];\n                              \n                              for (var i = 0; i < parts.length; ++i) {\n                                  var part = parts[i].replace('{{{', '').replace('}}}', '');\n                                  var points = part.split('},{');\n                                  var partialData = [];\n                                  for (var j = 0; j < points.length; ++j) {\n                                      var point = points[j].replace('{', '').replace('}', '').split(',');\n                                      for (var k = 0; k < point.length; ++k)\n                                          point[k] = parseFloat(point[k]);\n                                      partialData.push(point);\n                                  }\n                                  data.push({label: labels[i], data: partialData});\n                              }\n\n                              evaluationResult['type'] = 'Plot3D';\n                              evaluationResult['plot3d_data'] = data;\n                          } else {\n                              yacas_evaluate('TeXForm(Hold(' + result + '));');\n                              var texFormResult = yacas_result();\n                              texCode = texFormResult.trim().substr(2, texFormResult.length - 5);\n\n                              yacas_evaluate('IsNumber(Hold(' + result + '));');\n                              var isNumber =  yacas_result() === 'True;';\n                              yacas_evaluate('IsConstant(Hold(' + result + '));');\n                              var isConstant = yacas_result() === 'True;';\n                              yacas_evaluate('IsVector(Hold(' + result + '));');\n                              var isVector = yacas_result() === 'True;';\n                              yacas_evaluate('IsMatrix(Hold(' + result + '));');\n                              var isMatrix = yacas_result() === 'True;';\n                              yacas_evaluate('IsSquareMatrix(Hold(' + result + '));');\n                              var isSquareMatrix = yacas_result() === 'True;';\n\n                              var expressionType = 'function';\n                              \n                              if (isNumber)\n                                  expressionType = 'number';\n                              else if (isConstant && !(isVector || isMatrix))\n                                  expressionType = 'constant';\n                              else if (isVector)\n                                  expressionType = 'vector';\n                              else if (isSquareMatrix)\n                                  expressionType = 'square_matrix';\n                              else if (isMatrix)\n                                  expressionType = 'matrix';\n\n                              yacas_evaluate('VarList(Hold(' + result + '));');\n                              var variables = yacas_result();\n                              variables = variables.trim().substr(1, variables.length - 3);\n                              if (variables === '')\n                                  variables = []\n                              else\n                                  variables = variables.split(',');\n                              \n                              evaluationResult['type'] = 'Expression';\n                              evaluationResult['expression'] = result;\n                              evaluationResult['tex_code'] = texCode;\n                              evaluationResult['expression_type'] = expressionType;\n                              evaluationResult['variables'] = variables;\n                          }\n                          \n                          printResults(evaluationResult);\n                      },\n                      complete: function (ps) {\n                          return yacas_complete(ps).split(';');\n                      }\n                  };\n                  load();\n              },\n              preRun: [],\n              postRun: [],\n              print: (function() {\n                  return function(text) {\n                      if (arguments.length > 1)\n                          text = Array.prototype.slice.call(arguments).join(' ');\n                      console.log(text);\n                  };\n              })()\n          };\n        </script>\n\n        \n        <script async type=\"text/javascript\" src=\"yacas.js\"></script>\n    </head>\n\n    <body>\n        <div id=\"toolbar\"></div>\n        <script type=\"text/javascript\">\n          $(document).ready(function() {\n          });\n          function download(filename, text) {\n              var element = document.createElement('a');\n              element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));\n              element.setAttribute('download', filename);\n              \n              element.style.display = 'none';\n              document.body.appendChild(element);\n              \n              element.click();\n              \n              document.body.removeChild(element);\n          }\n          $(function () {\n              $('#toolbar').w2toolbar({\n                  name: 'toolbar',\n                  tooltip: 'bottom',\n                  items: [\n                      // { type: 'button', id: 'new', icon: 'fa fa-file', hint: 'New' },\n                      // { type: 'button', id: 'open', icon: 'fa fa-folder-open', hint: 'Open' },\n                      // { type: 'button', id: 'save', icon: 'fa fa-save', hint: 'Save' },\n                      // { type: 'break' },\n                      { type: 'button', id: 'down', icon: 'fa fa-arrow-down', hint: 'Go down' },\n                      { type: 'button', id: 'up', icon: 'fa fa-arrow-up', hint: 'Go up' },\n                      { type: 'break' },\n                      { type: 'button', id: 'insert_below', icon: 'fa fa-caret-square-o-down', hint: 'Insert cell below' },\n                      { type: 'button', id: 'insert_above', icon: 'fa fa-caret-square-o-up', hint: 'Insert cell above' },\n                      { type: 'button', id: 'delete', icon: 'fa fa-remove', hint: 'Remove current cell' },\n                      { type: 'break' },\n                      { type: 'button', id: 'evaluate', icon: 'fa fa-play', hint: 'Evaluate current cell' },\n                      { type: 'button', id: 'evaluate_all', icon: 'fa fa-repeat', hint: 'Evaluate all' },\n\t\t      // { type: 'button', id: 'stop', icon: 'fa fa-stop', hint: 'Stop evaluation' },\n\t\t      // { type: 'break' },\n\t\t      // { type: 'button', id: 'settings', icon: 'fa fa-cog', hint: 'Settings' },\n                      { type: 'break' },\n                      // { type: 'button', id: 'info', icon: 'fa fa-info-circle', hint: 'Current symbol info' },\n                      { type: 'button', id: 'help', icon: 'fa fa-life-ring', hint: 'Help' }\n                  ],\n                  onClick: function (event) {\n                      switch(event.target) {\n                      case 'new':\n                          var win = window.open(window.location.href, '_blank');\n                          win.focus();\n                          break;\n                      case 'save':\n                          currentInputCell.focus();\n                          download('yacas.ygy', JSON.stringify(getAllInputs()));\n                          break;\n                      case 'up':\n                          if (currentInputCell.number === undefined)\n                              goUp(0);\n                          else\n                              goUp(currentInputCell.number);\n                          break;\n                      case 'down':\n                          goDown(currentInputCell.number);\n                          break;\n                      case 'insert_above':\n                          currentInputCell.focus();\n                          insertBeforeCurrent();\n                          break;\n                      case 'insert_below':\n                          currentInputCell.focus();\n                          insertAfterCurrent();\n                          break;\n                      case 'delete':\n                          currentInputCell.focus();\n                          deleteCurrent();\n                          break;\n                      case 'evaluate':\n                          currentInputCell.focus();\n                          evaluateCurrent();\n                          break;\n                      case 'evaluate_all':\n                          evaluateAll();\n                          break;\n                      case 'help':\n                          var win = window.open('https://yacas.readthedocs.io/en/latest/reference_manual/index.html');\n                          win.focus();\n                          break;\n                      default:\n                          console.log('not implemented target: '+ event.target);\n                          break;\n                      };\n                      event.preventDefault();\n                  }\n              });\n          });\n        </script>\n        <div>\n            <p><br /></p>\n            <p>This is online demo of <a href=\"http://www.yacas.org\" target=\"blank_\">yacas</a>, a simple yet capable Computer Algebra System</p>\n            <p>\n            <p>Please note that this is only a demo, it's slower than than the desktop version and doesn't allow saving or loading</p>\n            <p>All calculations are performed locally in your browser; yacas is a C++ application transpiled into JavaScript/WebAssembly by the magic of <a href=\"https://emscripten.org/\">Emscripten</a></p>\n            <p>Press Shift+Enter or click <i class=\"fa fa-play\"></i> above to perform calculations</p>\n            <p>Type Example() and press Shift+Enter to see an example; repeat to see another one</p>\n            <p>Click <i class=\"fa fa-life-ring\"></i> above for help</p>\n        </div>\n        <div id=\"YacasAREA\">\n\n            <table id=\"Elements\">\n                <tbody id=\"expression_0\" class=\"New\">\n                <tr id='tr_input'>\n                    <td>in&nbsp&nbsp:</td>\n                    <td><textarea class='jtransform' id='inputExpression' onKeyDown='return submitenter(this,event)' autofocus></textarea></td>\n                </tr>\n                </tbody>\n             </table>\n        </div>\n        <div id=\"MathBarStringWidthTest\"></div>\n        <script>\n            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n            })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n            ga('create', 'UA-68673768-2', 'auto');\n            ga('send', 'pageview');\n        </script>\n    </body>\n</html>\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/yacas_gui/attic/intput.editable.js",
    "content": "var bluredEditable = null;\n\n\nfunction editableLoad(){\n    $( window ).on( 'blur', function(){ if ( bluredEditable !== null ) $( bluredEditable ).click(); } );\n    $( document ).on( 'click', function(){ bluredEditable = null; });\n}\n\nfunction editableReset( element ){\n    original = $(element).parents(\"span\")[0].calculatedExpression;\n    revert = $(element).parents(\"span\")[0].revert;\n    if ( original === revert ){\n        $(element).parents(\"tbody\").removeClass(\"Modified\");\n    }\n}\n\nfunction editableBlur( element ){\n    bluredEditable = element;\n    $(element).parents(\"tbody\").addClass(\"NotToCalculate\");\n    $(element).children().submit();\n}\n\nvar EmptyEditableText = \"Click to edit...\";\n\nfunction changeToEditable( elementID, number ){\n    $( elementID ).editable(\n                            function(value, settings) { return value; },\n                            {\n                            width   : '100%',\n                            type    : \"autogrow\",\n                            tooltip : EmptyEditableText,\n                            style   : \"width:100%\",\n                            onreset: function(value,settings){\n                            editableReset( this );\n                            },\n                            onblur  : function( value, setting){\n                            editableBlur ( this );\n                            },\n                            name    : number,\n                            callback: function( value, settings ){\n                            processChange( value, settings.name, this  );\n                            }\n                            });\n}\n\n\nfunction addEditable( lineid, number, value, rootElementID ){\n    \n    var row = $( \"<tr class='In'></tr>\" );\n    row.append( \"<td>in&nbsp&nbsp\"+ number + \":</td>\" );\n    row.append( \"<td><span class='editable'>\"+ value +\"</span></td>\" );\n    $( rootElementID ).append( row );\n    \n    var editable = row.find(\".editable\");\n    editable[0].calculatedExpression = value;\n    \n    changeToEditable( editable, lineid );\n    return editable;\n}\n\nfunction evaluateCurrent_deprecatedEditable(){\n    var active = document.activeElement;\n    if ( active.id === \"inputExpression\" && active.value != \"\"){\n        calculate( active.value );\n    }else{\n        $(document.activeElement).parent().trigger(\"submit\");\n    }\n}\n\nfunction evaluateAll_deprecatedEditable(){\n    $(\".editable\").each( function() {\n                        value = $(this).text();\n                        \n                        if ( value === \"\" ){\n                        $(this).find(\"form:first\").trigger(\"submit\");\n                        }else{\n                        \n                        if ( value === EmptyEditableText ) value = \"\";\n                        \n                        number = $(this).parents(\"tbody\")[0].id.split(\"_\")[1];\n                        processChange( value, number, this );\n                        }\n                        });\n    inputVal = $( \"#inputExpression\" ).val();\n    if ( inputVal !== \"\" ) calculate( inputVal );\n    $(\"#inputExpression\").focus();\n}\n\nfunction getAllInputs_depreciateEditable(){\n    var inputs = [];\n    $(\".editable\").each( function() {\n                        value = $(this).text();\n                        \n                        if ( value === \"\" ){\n                        inputs.push( $(this).find(\"textarea:first\").val() );\n                        }else{\n                        \n                        if ( value === EmptyEditableText ) value = \"\";\n                        inputs.push( value );\n                        }\n                        });\n    inputVal = $( \"#inputExpression\" ).val();\n    if ( inputVal !== \"\" ) inputs.push( inputVal );\n    \n    return inputs;\n}"
  },
  {
    "path": "cyacas/yacas-gui/resources/yacas_gui/yacas_gui.css",
    "content": "body {\n    margin: 0;\n    overflow-y: scroll;\n}\n\n#Elements {\n    border-collapse: collapse;\n    width: 100%;\n    table-layout: fixed;\n}\n\ntd {\n    font-family: monospace;\n    font-size: small;\n    padding: 5px;\n}\n\n.New > tr > td:first-child {\n    background-color: lightgray !important;\n    color: black !important;\n}\n\n.Error > tr > td:first-child {\n    background-color: red !important;\n    color: white !important;\n}\n\n.Modified > tr > td:first-child {\n    background-color: gold !important;\n    color: black !important;\n}\n\n.Expression > tr.Out > td {\n    font-size: 16px;\n}\n\n#Elements > tbody > tr > td:first-child {\n    font-size: x-small;\n    width: 45px;\n    background-color: #66cd00;\n    color: white;\n}\n\n.CodeMirror {\n    box-sizing: border-box;\n    height: auto;\n    width: 100%;\n}\n\n.CodeMirror-focused {\n    border: 1px solid #ddd;\n}\n\n#expression_0 .CodeMirror {\n    border: 1px solid #ddd;\n}\n\ntextarea {\n    width: 100%;\n    font-family: courier, monospace;\n    font-size: small;\n    resize: none;\n    padding: 4px;\n    height: 14px;\n}\n\n.containment {\n    width: 100%;\n}\n\n.editable {\n    color: slategray;\n}\n\n.Error {\n    color: red;\n}\n\n.Plot2D {\n    height: 300px;\n}\n\n.Plot3D {\n    height: 300px;\n}\n\n.Plot3DActive {\n    -webkit-box-sizing: border-box;\n    box-sizing: border-box;\n    border: 2px solid #41403b;\n}\n\n.w2ui-toolbar table.w2ui-button .w2ui-tb-image > span {\n    color: #f1f1f1;\n}\n\n#toolbar {\n    padding: 10px 16px;\n    background: #555;\n    color: #808080;\n    border: 1px solid #000;\n    border-radius: 10px;\n    position: fixed;\n    top: 0;\n    width: 100%;\n    overflow-y: visible;\n    z-index: 99;\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/yacas_gui/yacas_gui.js",
    "content": "/* global CodeMirror, MathBar, MathJax, Plotly, vis, yacas */\n\n\"use strict\";\n\nvar currentExpression = 1;\nvar numberOfLines = 1;\nvar currentInputCell = null;\n\n//Function stops scrolling event, and just scrool the window\n//Otherwise Code-Mirror editor kept scrolling one line up even if there was no line to scroll\nfunction scrollListener(e) {\n\n    const dx = e.wheelDeltaX;\n    const dy = -1 * e.wheelDeltaY;\n\n    window.scrollBy(dx, dy);\n    e.preventDefault();\n}\n\nfunction findPreviousExpression(number) {\n    var previous = $(\"#expression_\" + number).prev(\"tbody\");\n    if (previous.length === 0)\n        return null; //First row\n    return previous[0].id.split(\"_\")[1];\n\n}\n\nfunction findNextExpression(number) {\n    var next = $(\"#expression_\" + number).next(\"tbody\");\n    if (next.length === 0)\n        return null; //First row\n    return next[0].id.split(\"_\")[1];\n\n}\n\nfunction goto(number) {\n    if (number === \"0\")\n        $(\"#inputExpression\")[0].editor.focus();\n    else\n        $(\"#expression_\" + number).find(\"textarea\")[0].editor.focus();\n}\n\nfunction goUp(number) {\n    var prev = findPreviousExpression(number);\n    if (prev === null)\n        return false;\n    goto(prev);\n    return true;\n}\n\nfunction goDown(number) {\n    var next = findNextExpression(number);\n    if (next === null)\n        return false;\n    goto(next);\n    return true;\n}\n\nfunction submitenter(input, event) {\n    if (event.which === 13 && event.shiftKey) {\n        $(\"#inputExpression\")[0].editor.save();\n        const value = $(\"#inputExpression\")[0].editor.getValue();\n        calculate(value);\n        return false;\n    }\n    if (event.which === 38 && event.ctrlKey) {\n        goUp(0);\n        return false;\n    }\n\n    return true;\n}\n\nfunction hint(cm) {\n    return new Promise(function (accept) {\n        var cursor = cm.getCursor();\n        var line = cm.getLine(cursor.line);\n\n        var start = cursor.ch;\n        var end = cursor.ch;\n\n        while (start && /\\w/.test(line.charAt(start - 1)))\n            --start;\n\n        while (end < line.length && /\\w/.test(line.charAt(end)))\n            ++end;\n\n        var word = line.slice(start, end);\n\n        yacas.complete(word, function (hints) {\n            return accept({\n                list: hints,\n                from: CodeMirror.Pos(cursor.line, start),\n                to: CodeMirror.Pos(cursor.line, end)\n            });\n        });\n    });\n}\n\nfunction load() {\n\n    MathBar.initializeFunctions(\"mathbar/functions.json\");\n\n    //To keep CodeMirror editor from bad scrolling\n    document.body.addEventListener(\"mousewheel\", function (e) {\n        scrollListener(e);\n    });\n\n    $(\"#inputExpression\").autosize();\n\n    $(window).on(\"resize\", function () {\n\n        var w = $(\"body\").width() - $(\"#Elements>tbody>tr>td:first-child\").innerWidth() - 10; //10 is for padding in the td.Out element\n        $(\".resizable\").each(function () {\n            var maxwidth = $(this).resizable(\"option\", \"maxWidth\");\n            if ($(this).width() > w || $(this).width() === maxwidth)\n                $(this).width(w);\n        });\n        $(\".resizable\").resizable(\"option\", \"maxWidth\", w);\n        // $( \".CodeMirror\").width( w - 2 );\n\n        return true;\n    });\n\n    CodeMirror.defaults[\"lineNumbers\"] = false;\n    CodeMirror.defaults[\"mode\"] = { name: \"yacas\" };\n    CodeMirror.defaults[\"matchBrackets\"] = true;\n    CodeMirror.defaults[\"autoCloseBrackets\"] = '()[]{}\"\"';\n    CodeMirror.defaults[\"readOnly\"] = false;\n    CodeMirror.defaults[\"lineWrapping\"] = true;\n    CodeMirror.defaults[\"hintOptions\"] = { hint: hint };\n\n    if (/Mac/.test(navigator.platform))\n        CodeMirror.defaults[\"extraKeys\"] = { \"Cmd-Space\": \"autocomplete\" };\n    else\n        CodeMirror.defaults[\"extraKeys\"] = { \"Ctrl-Space\": \"autocomplete\" };\n\n\n    var editor = CodeMirror.fromTextArea(document.getElementById(\"inputExpression\"));\n    $(\"#inputExpression\")[0].editor = editor;\n    $(editor.getInputField()).keydown(function (event) {\n        return submitenter(this, event);\n    });\n    editor.on(\"change\", function () {\n        if (yacas.hasOwnProperty(\"on_contentsChanged\"))\n            yacas.on_contentsChanged();\n    });\n    editor.on(\"focus\", function (editor) {\n        currentInputCell = editor;\n    });\n\n    currentInputCell = editor;    \n\n    $(document).contextmenu({\n        delegate: \".Expression>.Out\",\n        menu: [\n            { title: \"Copy TeX\", cmd: \"copyTeX\" },\n            { title: \"Copy Yacas Expression\", cmd: \"copyYacasExpression\" }\n        ],\n        select: function (event, ui) {\n            const parents = ui.target.parents(\".Expression\");\n\n            if (ui.cmd === \"copyTeX\")\n                yacas.copyToClipboard($(parents[0]).children(\"script\")[0].textContent);\n            else if (ui.cmd === \"copyYacasExpression\")\n                yacas.copyToClipboard($(parents)[0].yacasExpression);\n        },\n        preventContextMenuForPopup: true\n    });\n}\n\n\nfunction changeMathJaxScale(newScale) {\n    MathJax.Hub.Config({\n        CommonHTML: {\n            scale: newScale\n        }\n    });\n    MathJax.Hub.Queue([\"Rerender\", MathJax.Hub]);\n\n}\n\nfunction changeMathJaxFont(newFont) {\n    MathJax.Hub.Config({\n        CommonHTML: {\n            preferredFont: newFont\n        }\n    });\n    MathJax.Hub.Queue([\"Rerender\", MathJax.Hub]);\n\n}\n\nfunction updateInputNumber(updatedNumber) {\n    $(\"#inputCounter\").html(\"in \" + updatedNumber + \":\");\n}\n\nfunction clearInput() {\n    $(\"#inputExpression\").val(\"\");\n    $(\"#inputExpression\")[0].editor.setValue(\"\");\n}\n\nfunction addInputEditor(lineid, number, value, rootElementID) {\n\n    var $row = $(\"<tr>\", { class: \"In\" });\n\n    var $tdnumber = $(\"<td>\").append(\"in  \" + number + \":\");\n\n    var $textarea = $(\"<textarea>\", { class: \"InputTextarea\" }).append(value);\n    var $tdinput = $(\"<td>\").append($textarea);\n\n    $row.append($tdnumber).append($tdinput);\n\n    $(rootElementID).append($row);\n\n    var editor = CodeMirror.fromTextArea($textarea[0]);\n\n    editor.number = lineid;\n\n    $textarea[0].editor = editor;\n    editor.calculatedExpression = value;\n\n    editor.on(\"keydown\", function (editor, event) {\n\n        if (event.which === 13 && event.shiftKey) {\n            editor.save();\n            event.preventDefault();\n            processChange(editor.getValue(), editor.number, null);\n        }\n\n        if (event.which === 38 && event.ctrlKey)\n            goUp(editor.number);\n\n        if (event.which === 40 && event.ctrlKey)\n            goDown(editor.number);\n\n    });\n\n    editor.on(\"keyup\", function (editor) {\n\n        var $tbody = $(editor.getTextArea()).parents(\"tbody\");\n        if ($tbody.hasClass(\"New\"))\n            return;\n\n        var original = editor.calculatedExpression;\n        var currentValue = editor.getValue();\n\n        if (original !== currentValue) {\n            $tbody.addClass(\"Modified\");\n            yacas.on_contentsChanged();\n        } else {\n            $tbody.removeClass(\"Modified\");\n        }\n    });\n\n    editor.on(\"focus\", function (editor) {\n        currentInputCell = editor;\n    });\n\n    return editor;\n}\n\nfunction addOutput(lineid, number, rootElementID) {\n    var outputID = \"output_\" + lineid;\n\n    var $row = $(\"<tr>\", { class: \"Out\" });\n\n    $row.append(\"<td>out \" + number + \":</td>\");\n    $row.append(\"<td><div id='\" + outputID + \"' ></div></td>\");\n\n    $(rootElementID).append($row);\n    $(\"#\" + outputID).append(\"<img src='yacas_gui/progressbar.indicator.gif' width='20' ></img>\");\n}\n\nfunction addSideEffects(number, sideEffects, rootElementID) {\n    var row = $(\"<tr></tr>\").insertBefore(rootElementID);\n    row.append(\"<td></td>\");\n    row.append(\"<td><span>\" + sideEffects + \"</span></td>\");\n}\n\nfunction debounce(func, wait, immediate) {\n    var timeout;\n    return function () {\n        let context = this, args = arguments;\n        let later = function () {\n            timeout = null;\n            if (!immediate)\n                func.apply(context, args);\n        };\n        let callNow = immediate && !timeout;\n        clearTimeout(timeout);\n        timeout = setTimeout(later, wait);\n        if (callNow)\n            func.apply(context, args);\n    };\n}\n\nfunction printResults(result) {\n    var number = result[\"idx\"];\n    var outputID = \"output_\" + number;\n\n    var ExpressionElement = $(\"#expression_\" + number);\n\n    if (result.hasOwnProperty(\"side_effects\")) {\n        var outRow = ExpressionElement.children(\".Out\");\n        addSideEffects(number, result[\"side_effects\"].replace(/\\n/g, \"<br />\"), outRow);\n    }\n\n    var output = $(\"#\" + outputID);\n\n    output.addClass(result[\"type\"]);\n\n    ExpressionElement.removeClass(\"Modified New Error Expression\");\n    ExpressionElement.addClass(result[\"type\"]);\n\n    output.text(\"\");\n\n    if (result[\"type\"] === \"Expression\") {\n\n        output.addClass(\"outside\");\n        output.append(\"$$\" + result[\"tex_code\"] + \"$$\");\n\n        renderOutput(outputID);\n        output[0].yacasExpression = result[\"expression\"];\n        output[0].lastWidth = $(output).width();\n\n        if (MathBar.supportsExpressionType(result[\"expression_type\"], result[\"variables\"].length)) {\n\n            let options = {};\n            options[\"layout\"] = \"singleline\";\n            options[\"VIF\"] = \"max\";\n            options[\"type\"] = result[\"expression_type\"];\n\n            if (result[\"variables\"].length > 0) {\n                options[\"type\"] = options[\"type\"] + \"_\" + result[\"variables\"].length;\n                options[\"defaultParameters\"] = {};\n                options[\"defaultParameters\"][\"variable\"] = result[\"variables\"];\n            }\n\n            var bar = new MathBar(outputID, options, function (result, outputID) {\n                parseMathBarResult(result, outputID);\n            });\n\n        }\n\n        $(output).resize(debounce(function () {\n            var w = $(this)[0].lastWidth;\n            if ($(this).width() !== w) {\n                MathJax.Hub.Rerender(this);\n                $(this)[0].lastWidth = $(this).width();\n            }\n        }, 250));\n\n    } else if (result[\"type\"] === \"Error\") {\n\n        output.append(result[\"error_message\"]);\n\n    } else if (result[\"type\"] === \"Plot2D\") {\n        let data = [];\n\n        for (let i = 0; i < result[\"plot2d_data\"].length; ++i) {\n            let x = [];\n            let y = [];\n            const d = result[\"plot2d_data\"][i][\"data\"];\n            for (let j = 0; j < d.length; ++j) {\n                x.push(d[j][0]);\n                y.push(d[j][1]);\n            }\n            data.push({\n                type: \"scatter\",\n                name: result[\"plot2d_data\"][i][\"label\"],\n                x: x,\n                y: y,\n            });\n        }\n\n        const layout = {\n            autosize: true,\n            margin: {\n                l: 0,\n                r: 0,\n                b: 0,\n                t: 16\n            },\n            xaxis: {\n                automargin: true,\n            },\n            yaxis: {\n                automargin: true,\n            }\n        };\n\n        const options = {\n            responsive: true\n        };\n\n        Plotly.newPlot(output[0], data, layout, options);\n\n        output.resizable({\n            handles: \"s,e\",\n            minWidth: 200,\n            minHeight: 200,\n            resize: function (e, info) {\n                window.console.log(\"resize\", info);\n                Plotly.relayout(output[0], { height: info[\"size\"][\"height\"] });\n                return true;\n            }\n        });\n\n        output.addClass(\"resizable\");\n\n    } else if (result[\"type\"] === \"Plot3D\") {\n        let data = [];\n\n        for (let i = 0; i < result[\"plot3d_data\"].length; ++i) {\n            let x = [];\n            let y = [];\n            let z = [];\n            const d = result[\"plot3d_data\"][i][\"data\"];\n            for (let j = 0; j < d.length; ++j) {\n                x.push(d[j][0]);\n                y.push(d[j][1]);\n                z.push(d[j][2]);\n            }\n            data.push({\n                type: \"mesh3d\",\n                opacity: 0.8,\n                x: x,\n                y: y,\n                z: z\n            });\n        }\n\n        const layout = {\n            autosize: true,\n            margin: {\n                l: 0,\n                r: 0,\n                b: 8,\n                t: 16\n            }\n        };\n\n        const options = {\n            responsive: true\n        };\n\n        Plotly.newPlot(output[0], data, layout, options);\n\n        output.resizable({\n            handles: \"s\",\n            minWidth: 200,\n            minHeight: 200,\n            resize: function (e, info) {\n                Plotly.relayout(output[0], { height: info[\"size\"][\"height\"] });\n                return true;\n            }\n        });\n\n        output.addClass(\"resizable\");\n\n    } else if (result[\"type\"] === \"Graph\") {\n        const vertices = result[\"graph_vertices\"];\n        const noVertices = vertices.length;\n\n        let visVertices = [];\n\n        for (let i = 0; i < noVertices; ++i)\n            visVertices.push({ id: i + 1, label: vertices[i] });\n\n        const edges = result[\"graph_edges\"];\n        const noEdges = edges.length;\n\n        let visEdges = [];\n\n        for (let i = 0; i < noEdges; ++i) {\n            var arrows = \"to\";\n            if (edges[i].bi)\n                arrows += \",from\";\n            visEdges.push({ from: edges[i].from, to: edges[i].to, arrows: arrows });\n        }\n\n        let data = {\n            nodes: visVertices,\n            edges: visEdges\n        };\n        let options = {};\n\n        let network = new vis.Network(output[0], data, options);\n\n        const width = output.width();\n\n        output.resizable({ maxWidth: width, minWidth: 200, minHeight: 200 });\n        output.addClass(\"resizable\");\n    }\n}\n\nfunction renderOutput(outputID) {\n    MathJax.Hub.Queue([\"Typeset\", MathJax.Hub, outputID]);\n}\n\nfunction removeOldResults(number) {\n    $(\"#expression_\" + number).remove();\n}\n\nfunction addExpressionCells(lineId, expressionId, value, rootElementId, expressionClass) {\n    $(\"<tbody>\", { id: \"expression_\" + lineId, class: expressionClass }).insertBefore(rootElementId);\n    addInputEditor(lineId, expressionId, value, \"#expression_\" + lineId);\n    addOutput(lineId, expressionId, \"#expression_\" + lineId);\n}\n\nfunction calculateAt(value, rootElementId) {\n    addExpressionCells(numberOfLines, currentExpression, value, \"#\" + rootElementId, \"New\");\n\n    yacas.eval(numberOfLines, value);\n\n    currentExpression++;\n    numberOfLines++;\n}\n\nfunction calculate(value) {\n    calculateAt(value, \"expression_0\");\n    clearInput();\n}\n\nfunction parseMathBarResult(value, outputID) {\n    const number = outputID.split(\"_\")[1];\n    const nextNumber = findNextExpression(number);\n    calculateAt(value, \"expression_\" + nextNumber);\n    goto(nextNumber);\n}\n\nfunction processChange(value, number) {\n    var decodedValue = $(\"<div/>\").html(value).text();\n\n    if ($(\"#expression_\" + number).hasClass(\"NotToCalculate\")) {\n        $(\"#expression_\" + number).removeClass(\"NotToCalculate\");\n        return;\n    }\n\n    const expressionClass = $(\"#expression_\" + number).attr(\"class\");\n\n    addExpressionCells(numberOfLines, currentExpression, decodedValue, \"#expression_\" + number, expressionClass);\n\n    yacas.eval(numberOfLines, decodedValue);\n\n    goDown(number);\n\n    currentExpression++;\n    numberOfLines++;\n\n    removeOldResults(number);\n}\n\nfunction evaluateCurrent() {\n    var $tbody = $(document.activeElement).parents(\"tbody\");\n    var $input = $tbody.find(\".InputTextarea\");\n\n    if ($input.length) {\n        var editor = $input[0].editor;\n        processChange(editor.getValue(), editor.number, null);\n        return;\n    }\n\n    $input = $tbody.find(\"#inputExpression\");\n\n\n    if ($input.length) {\n        var inputVal = $input[0].editor.getValue();\n        if (inputVal !== \"\")\n            calculate(inputVal);\n    }\n}\n\n\nfunction evaluateAll() {\n    $(\".InputTextarea\").each(function () {\n        var editor = this.editor;\n        processChange(editor.getValue(), editor.number, null);\n    });\n\n    var $input = $(\"#inputExpression\");\n    if ($input.length) {\n        var inputVal = $input[0].editor.getValue();\n        if (inputVal !== \"\")\n            calculate(inputVal);\n    }\n\n    $input.focus();\n}\n\n\n\nfunction getAllInputs() {\n    let inputs = [];\n    $(\".InputTextarea\").each(function () {\n        inputs.push(this.editor.getValue());\n\n    });\n    let inputVal = $(\"#inputExpression\")[0].editor.getValue();\n    if (inputVal !== \"\")\n        inputs.push(inputVal);\n    return inputs;\n}\n\nfunction previousCell() {\n    const focused = $(\":focus\").parents(\"tbody\");\n\n    if (focused.length === 0)\n        return;\n\n    const number = $(focused)[0].id.split(\"_\")[1];\n    goUp(number);\n}\n\nfunction nextCell() {\n    const focused = $(\":focus\").parents(\"tbody\");\n\n    if (focused.length === 0)\n        return;\n\n    const number = $(focused)[0].id.split(\"_\")[1];\n    goDown(number);\n}\n\n\nfunction insertElement(whetherAfterOrBefore) {\n    const focused = $(\":focus\").parents(\"tbody\");\n\n    if (focused.length === 0)\n        return;\n\n    let element = $(\"<tbody id='expression_\" + numberOfLines + \"' class='New'></tbody\");\n    let value = \"\";\n    let clickNew = true;\n\n    //Special case when inserting after last input (expression_0)\n    if (whetherAfterOrBefore === \"after\" && $(focused)[0].id === \"expression_0\") {\n        whetherAfterOrBefore = \"before\";\n        value = $(\"#inputExpression\").val();\n        clearInput();\n        clickNew = false;\n    }\n\n    if (whetherAfterOrBefore === \"before\")\n        element.insertBefore(focused);\n    else\n        element.insertAfter(focused);\n\n    let editor = addInputEditor(numberOfLines, \"\", value, \"#expression_\" + numberOfLines);\n\n    if (clickNew)\n        editor.focus();\n\n    numberOfLines++;\n}\n\nfunction insertAfterCurrent() {\n    insertElement(\"after\");\n}\n\nfunction insertBeforeCurrent() {\n    insertElement(\"before\");\n}\n\nfunction deleteCurrent() {\n    let focused = $(\":focus\").parents(\"tbody\");\n\n    if (focused.length === 0)\n        return;\n\n    //Cannot delete last input (expression_0)\n    if ($(focused)[0].id === \"expression_0\")\n        return;\n\n    const number = $(focused)[0].id.split(\"_\")[1];\n    goDown(number);\n    $(focused).remove();\n}\n\nfunction contextHelp() {\n    let e = document.activeElement;\n    yacas.help(e.value, e.selectionStart);\n}\n\nfunction exportScript() {\n    var elems = document.getElementsByClassName(\"InputTextarea\");\n    var r = [];\n    for (var i = 0; i < elems.length; ++i) {\n        var s = elems[i].value;\n        if (!s.endsWith(\";\"))\n            s += \";\";\n        r.push(s);\n    }\n    return r;\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/resources/yacas_gui.html",
    "content": "<!DOCTYPE html >\n\n<html>\n    <head>\n        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n\n        <title>Yacas GUI</title>\n\n        <link rel=\"stylesheet\" href=\"codemirror/lib/codemirror.css\" />\n        <link rel=\"stylesheet\" href=\"codemirror/addon/hint/show-hint.css\" />\n        <link rel=\"stylesheet\" href=\"yacas_gui/yacas_gui.css\" />\n        <link rel=\"stylesheet\" href=\"mathbar/mathbar.css\" />\n        <link rel=\"stylesheet\" href=\"jquery/jquery-ui.min.css\" />\n        <link rel=\"stylesheet\" href=\"vis/vis.min.css\" />\n\n        <script type=\"text/x-mathjax-config\">\n            MathJax.Hub.Config({\n                        tex2jax: {\n                            inlineMath: [[\"$\",\"$\"],[\"\\\\(\",\"\\\\)\"]],\n                            displayMath: [[\"$$\",\"$$\"], [\"\\[\",\"\\]\"]]\n                        },\n                        CommonHTML: {\n                            linebreaks: { automatic: true },\n                            scale: 80\n                        },\n                        showMathMenu: false,\n                        displayAlign: \"left\"\n            });\n        </script>\n\n        <script type=\"text/javascript\" src=\"yacas_gui/yacas_gui.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.min.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery-ui.min.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.jeditable.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.jeditable.autogrow.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.autosize.min.js\"></script>\n        <script type=\"text/javascript\" src=\"jquery/jquery.ui-contextmenu.min.js\"></script>\n        <script type=\"text/javascript\" src=\"mathjax/unpacked/MathJax.js?config=TeX-AMS_CHTML\"></script>\n        <script type=\"text/javascript\" src=\"plotly-1.49.0.min.js\"></script>\n        <script type=\"text/javascript\" src=\"mathbar/mathBar.js\"></script>\n        <script type=\"text/javascript\" src=\"mathbar/functions_parser.js\"></script>\n        <script type=\"text/javascript\" src=\"codemirror/lib/codemirror.js\"></script>\n        <script type=\"text/javascript\" src=\"codemirror/mode/yacas/yacas.js\"></script>\n        <script type=\"text/javascript\" src=\"codemirror/addon/edit/matchbrackets.js\"></script>\n        <script type=\"text/javascript\" src=\"codemirror/addon/edit/closebrackets.js\"></script>\n        <script type=\"text/javascript\" src=\"codemirror/addon/hint/show-hint.js\"></script>\n        <script type=\"text/javascript\" src=\"vis/vis.min.js\"></script>\n        <script type=\"text/javascript\" src=\"webchannel/qwebchannel.js\"></script>\n        <script>\n            var channel;\n            var yacas;\n\n            $( document ).ready(function () {\n                channel = new QWebChannel(qt.webChannelTransport, function(channel) {\n                    yacas = channel.objects.yacas;\n                    load();\n                    yacas.on_initComplete();\n                });\n            });\n        </script>\n    </head>\n\n    <body>\n        <div id=\"YacasAREA\">\n\n            <table id=\"Elements\">\n                <tbody id=\"expression_0\" class=\"New\">\n                <tr id='tr_input'>\n                    <td>in&nbsp&nbsp:</td>\n                    <td><textarea class='jtransform' id='inputExpression' onKeyDown='return submitenter(this,event)' autofocus></textarea></td>\n                </tr>\n                </tbody>\n             </table>\n        </div>\n        <div id=\"MathBarStringWidthTest\"></div>\n    </body>\n</html>\n"
  },
  {
    "path": "cyacas/yacas-gui/src/cellproxy.cpp",
    "content": "#include \"cellproxy.h\"\n\n#include <QtCore/QJsonDocument>\n#include <QtCore/QVariant>\n\nCellProxy::CellProxy(QWebEnginePage* page,\n                     int idx,\n                     QString expr,\n                     YacasServer& yacas_server,\n                     CYacas& yacas2tex,\n                     QObject* parent) :\n    QObject(parent),\n    _page(page),\n    _idx(idx),\n    _expr(expr),\n    _yacas_server(yacas_server),\n    _yacas2tex(yacas2tex),\n    _request(new YacasRequest(\n        expr.trimmed().isEmpty()\n            ? \"True;\"\n            : (expr.endsWith(\";\") ? \"[\" + expr + \"];\" : \"[\" + expr + \";];\")))\n{\n    connect(_request,\n            SIGNAL(state_changed(YacasRequest::State)),\n            this,\n            SLOT(on_request_state_changed(YacasRequest::State)));\n    _yacas_server.submit(_request);\n}\n\nCellProxy::~CellProxy()\n{\n    delete _request;\n}\n\nvoid CellProxy::on_request_state_changed(YacasRequest::State state)\n{\n    if (state == YacasRequest::READY) {\n        QVariantMap evaluation_result;\n        evaluation_result[\"idx\"] = _idx;\n        evaluation_result[\"input\"] = _expr;\n\n        if (!_request->side_effects().isEmpty())\n            evaluation_result[\"side_effects\"] = _request->side_effects();\n\n        switch (_request->result_type()) {\n        case YacasRequest::EXPRESSION: {\n            const QString result = _request->result().trimmed();\n            const QString texform_expr =\n                QString(\"TeXForm(Hold(\") + result + \"));\";\n            _yacas2tex.Evaluate(texform_expr.toStdString());\n            const QString texform_result =\n                QString::fromStdString(_yacas2tex.Result());\n            const QString tex_code =\n                texform_result.trimmed().mid(2, texform_result.length() - 5);\n            evaluation_result[\"type\"] = \"Expression\";\n            evaluation_result[\"expression\"] = result;\n            evaluation_result[\"tex_code\"] = tex_code;\n\n            bool is_number = false;\n            bool is_constant = false;\n            bool is_vector = false;\n            bool is_matrix = false;\n            bool is_square_matrix = false;\n\n            _yacas2tex.Evaluate(\n                (QString(\"IsNumber(Hold(\") + result + \"));\").toStdString());\n            if (_yacas2tex.Result() == \"True;\")\n                is_number = true;\n            _yacas2tex.Evaluate(\n                (QString(\"IsConstant(Hold(\") + result + \"));\").toStdString());\n            if (_yacas2tex.Result() == \"True;\")\n                is_constant = true;\n            _yacas2tex.Evaluate(\n                (QString(\"IsVector(Hold(\") + result + \"));\").toStdString());\n            if (_yacas2tex.Result() == \"True;\")\n                is_vector = true;\n            _yacas2tex.Evaluate(\n                (QString(\"IsMatrix(Hold(\") + result + \"));\").toStdString());\n            if (_yacas2tex.Result() == \"True;\")\n                is_matrix = true;\n            _yacas2tex.Evaluate(\n                (QString(\"IsSquareMatrix(Hold(\") + result + \"));\")\n                    .toStdString());\n            if (_yacas2tex.Result() == \"True;\")\n                is_square_matrix = true;\n\n            evaluation_result[\"expression_type\"] = \"function\";\n\n            if (is_number)\n                evaluation_result[\"expression_type\"] = \"number\";\n            else if (is_constant && !(is_vector || is_matrix))\n                evaluation_result[\"expression_type\"] = \"constant\";\n            else if (is_vector)\n                evaluation_result[\"expression_type\"] = \"vector\";\n            else if (is_square_matrix)\n                evaluation_result[\"expression_type\"] = \"square_matrix\";\n            else if (is_matrix)\n                evaluation_result[\"expression_type\"] = \"matrix\";\n\n            evaluation_result[\"variables\"] = QStringList();\n\n            _yacas2tex.Evaluate(\n                (QString(\"VarList(Hold(\") + result + \"));\").toStdString());\n            QString vars = QString::fromStdString(_yacas2tex.Result());\n            vars = vars.remove(\"{\");\n            vars.truncate(vars.length() - 2);\n            if (vars.length() != 0)\n                evaluation_result[\"variables\"] = vars.split(\",\");\n\n            break;\n        }\n        case YacasRequest::PLOT2D: {\n\n            QList<QVariant> data;\n\n            const QString result = _request->result().trimmed();\n            QStringList parts = result.split(\"}},{{\");\n\n            QString options_string = parts.takeLast().trimmed();\n            options_string.truncate(options_string.length() - 2);\n\n            QRegExp dict_entry_rx(\"(\\\"[^\\\"]+\\\"),(.+)\");\n            QRegExp number_list_rx(\"\\\\{([^,\\\\}]+)(?:,([^,\\\\}]+))*\\\\}\");\n            QRegExp split_string_list_rx(\"\\\",(?=(?:[^\\\\\\\"\\\"]*\\\\\\\"\\\"[^\\\\\\\"\\\"]*\"\n                                         \"\\\\\\\"\\\")*(?![^\\\\\\\"\\\"]*\\\\\\\"\\\"))\\\"\");\n\n            QStringList labels;\n\n            foreach (QString os, options_string.split(\"},{\")) {\n\n                dict_entry_rx.exactMatch(os);\n\n                if (dict_entry_rx.cap(1) == \"\\\"xrange\\\"\") {\n                    number_list_rx.exactMatch(dict_entry_rx.cap(2));\n                }\n\n                if (dict_entry_rx.cap(1) == \"\\\"yname\\\"\") {\n                    QString s = dict_entry_rx.cap(2);\n                    s.remove(0, 2);\n                    s.chop(2);\n                    labels = s.split(split_string_list_rx);\n                }\n            }\n\n            parts = parts.replaceInStrings(\"{{{\", \"\");\n            parts = parts.replaceInStrings(\"}}}\", \"\");\n\n            for (int i = 0; i < parts.size(); ++i) {\n\n                QList<QVariant> partial_data;\n\n                foreach (const QString& ss, parts[i].split(\"},{\")) {\n                    QList<QVariant> p;\n                    foreach (QString s, ss.split(\",\")) {\n                        p.append(\n                            s.replace(\"{\", \"\").replace(\"}\", \"\").toDouble());\n                    }\n                    partial_data.append(QVariant(p));\n                }\n\n                QVariantMap data_entry;\n                data_entry[\"label\"] = labels[i];\n                data_entry[\"data\"] = partial_data;\n                data.append(data_entry);\n            }\n\n            evaluation_result[\"type\"] = \"Plot2D\";\n            evaluation_result[\"plot2d_data\"] = data;\n\n            break;\n        }\n        case YacasRequest::PLOT3D: {\n            QList<QVariant> data;\n\n            const QString result = _request->result().trimmed();\n\n            QStringList parts = result.split(\"}},{{\");\n\n            QString options_string = parts.takeLast().trimmed();\n            options_string.truncate(options_string.length() - 2);\n\n            QRegExp dict_entry_rx(\"(\\\"[^\\\"]+\\\"),(.+)\");\n            QRegExp number_list_rx(\"\\\\{([^,\\\\}]+)(?:,([^,\\\\}]+))*\\\\}\");\n            QRegExp split_string_list_rx(\"\\\",(?=(?:[^\\\\\\\"\\\"]*\\\\\\\"\\\"[^\\\\\\\"\\\"]*\"\n                                         \"\\\\\\\"\\\")*(?![^\\\\\\\"\\\"]*\\\\\\\"\\\"))\\\"\");\n\n            QStringList labels;\n\n            foreach (QString os, options_string.split(\"},{\")) {\n                dict_entry_rx.exactMatch(os);\n\n                if (dict_entry_rx.cap(1) == \"\\\"zname\\\"\") {\n                    QString s = dict_entry_rx.cap(2);\n                    s.remove(0, 2);\n                    s.chop(2);\n                    labels = s.split(split_string_list_rx);\n                }\n            }\n\n            parts = parts.replaceInStrings(\"{{{\", \"\");\n            parts = parts.replaceInStrings(\"}}}\", \"\");\n\n            for (int i = 0; i < parts.size(); ++i) {\n\n                QList<QVariant> partial_data;\n\n                foreach (const QString& ss, parts[i].split(\"},{\")) {\n                    QList<QVariant> p;\n                    foreach (QString s, ss.split(\",\")) {\n                        p.append(\n                            s.replace(\"{\", \"\").replace(\"}\", \"\").toDouble());\n                    }\n                    partial_data.append(QVariant(p));\n                }\n\n                QVariantMap data_entry;\n                data_entry[\"label\"] = labels[i];\n                data_entry[\"data\"] = partial_data;\n                data.append(data_entry);\n            }\n\n            evaluation_result[\"type\"] = \"Plot3D\";\n            evaluation_result[\"plot3d_data\"] = data;\n\n            break;\n        }\n\n        case YacasRequest::GRAPH: {\n            evaluation_result[\"type\"] = \"Graph\";\n            const QString result = _request->result().trimmed();\n            QStringList parts = result.split(\"},{\");\n            const QStringList vertices = parts[0].replace(\"{\", \"\").split(\",\");\n            QVariantList edges;\n            foreach (QString es, parts[1].replace(\"}\", \"\").split(\",\")) {\n                bool bi = true;\n                QStringList ft = es.split(\"<->\");\n                if (ft.length() == 1) {\n                    ft = es.split(\"->\");\n                    bi = false;\n                }\n                QVariantMap edge;\n                edge[\"from\"] = vertices.indexOf(ft[0]) + 1;\n                edge[\"to\"] = vertices.indexOf(ft[1]) + 1;\n                edge[\"bi\"] = bi;\n\n                edges.append(edge);\n            }\n\n            evaluation_result[\"graph_vertices\"] = vertices;\n            evaluation_result[\"graph_edges\"] = edges;\n\n            break;\n        }\n\n        case YacasRequest::ERROR: {\n            evaluation_result[\"type\"] = \"Error\";\n            evaluation_result[\"error_message\"] = _request->result().trimmed();\n\n            break;\n        }\n        }\n\n        _page->runJavaScript(\n            QString(\"printResults(\") +\n            (QJsonDocument::fromVariant(evaluation_result)).toJson() + \");\");\n\n        deleteLater();\n    }\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/src/main.cpp",
    "content": "#include \"mainwindow.h\"\n\n#include <QtCore/QTimer>\n#include <QtGui/QBitmap>\n#include <QtGui/QPixmap>\n#include <QtWidgets/QApplication>\n#include <QtWidgets/QMessageBox>\n#include <QtWidgets/QSplashScreen>\n\n#include \"yacasrequest.h\"\n\n#include \"preferences.h\"\n\nvoid addSplashScreen(MainWindow* widget);\n\nint main(int argc, char* argv[])\n{\n    QApplication app(argc, argv);\n\n    try {\n        app.setApplicationName(\"yacas-gui\");\n        app.setApplicationDisplayName(\"Yacas GUI\");\n        app.setOrganizationName(\"yacas.org\");\n        app.setOrganizationDomain(\"yacas.org\");\n\n#ifndef _WIN32\n        app.setAttribute(Qt::AA_DontShowIconsInMenus);\n#endif\n\n        qRegisterMetaType<YacasRequest::State>(\"YacasRequest::State\");\n\n        Preferences prefs(app);\n\n        MainWindow widget(prefs);\n\n#ifndef __APPLE__\n        addSplashScreen(&widget);\n#endif\n\n        widget.show();\n\n        return app.exec();\n    } catch (const std::exception& e) {\n        QMessageBox::critical(nullptr, \"Yacas GUI Error\", e.what());\n        return 1;\n    } catch (...) {\n        QMessageBox::critical(nullptr, \"Yacas GUI Error\", \"Unknown error\");\n        return 1;\n    }\n\n    return 0;\n}\n\nvoid addSplashScreen(MainWindow* widget)\n{\n    QPixmap si(\":/resources/img/splash.png\");\n    QSplashScreen ss(si, Qt::WindowStaysOnTopHint);\n    ss.setMask(si.mask());\n    ss.showFullScreen();\n    QTimer::singleShot(3000, &ss, SLOT(close()));\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/src/mainwindow.cpp",
    "content": "#include \"mainwindow.h\"\n#include \"cellproxy.h\"\n#include \"preferences_dialog.h\"\n#include \"ui_mainwindow.h\"\n\n#include <QtCore/QDebug>\n#include <QtCore/QFile>\n#include <QtCore/QFileInfo>\n#include <QtCore/QJsonArray>\n#include <QtCore/QJsonDocument>\n#include <QtCore/QJsonObject>\n#include <QtCore/QList>\n#include <QtCore/QUrl>\n#include <QtCore/QVariant>\n\n#include <QtGui/QDesktopServices>\n\n#include <QtWebEngineWidgets/QtWebEngineWidgets>\n\n#include <QtPrintSupport/QPrintDialog>\n#include <QtWidgets/QFileDialog>\n#include <QtWidgets/QMessageBox>\n\n#include \"yacas/yacas_version.h\"\n\nMainWindow::MainWindow(Preferences& prefs, QWidget* parent) :\n    QMainWindow(parent),\n    _prefs(prefs),\n    _ui(new Ui::MainWindow),\n    _null_stream(&_null_buffer),\n    _scripts_path(prefs.get_scripts_path()),\n    _yacas_server(nullptr),\n    _yacas2tex(new CYacas(_null_stream)),\n    _has_file(false),\n    _modified(false),\n    _fname(QString(\"Untitled Notebook \") + QString::number(_cntr++))\n{\n    _yacas_server = new YacasServer(_scripts_path);\n\n    connect(_yacas_server,\n            &YacasServer::busy,\n            this,\n            &MainWindow::handle_engine_busy);\n\n    _yacas2tex->Evaluate(((std::string(\"DefaultDirectory(\\\"\") +\n                           _scripts_path.toStdString() + \"\\\");\")));\n    _yacas2tex->Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n\n    _ui->setupUi(this);\n\n    const qreal scale =\n        QGuiApplication::primaryScreen()->logicalDotsPerInch() / 96.0;\n\n    resize(size() * scale);\n\n    const qreal icon_size = 16 * scale;\n    _ui->toolBar->setIconSize(QSize(icon_size, icon_size));\n\n    _ui->webEngineView->setZoomFactor(scale);\n\n    _update_title();\n\n    loadYacasPage();\n    _ui->webEngineView->setAttribute(Qt::WA_AcceptTouchEvents, false);\n\n    _ui->webEngineView->addAction(_ui->actionInsert_Before);\n    _ui->webEngineView->addAction(_ui->actionInsert_After);\n    _ui->webEngineView->addAction(_ui->actionDelete_Current);\n    _ui->webEngineView->addAction(_ui->actionCurrent_Symbol_Help);\n\n    _windows.append(this);\n\n    connect(&_prefs,\n            &Preferences::changed,\n            this,\n            &MainWindow::handle_prefs_changed);\n\n#ifdef __APPLE__\n    // workaround for a qt bug causing toolbar to be displayed with black\n    // background when QWebEngineView is used\n    setUnifiedTitleAndToolBarOnMac(false);\n#endif\n}\n\nMainWindow::~MainWindow()\n{\n    _windows.removeOne(this);\n\n    delete _yacas_server;\n    delete _yacas2tex;\n    delete _ui;\n}\n\nvoid MainWindow::closeEvent(QCloseEvent* event)\n{\n    if (!_modified) {\n        event->accept();\n    } else {\n        const QMessageBox::StandardButton reply = QMessageBox::question(\n            this,\n            \"Save notebook?\",\n            \"Save changes before closing?\\n\\nYour changes will be lost if you \"\n            \"don't save them.\",\n            QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Close);\n\n        if (reply == QMessageBox::Save)\n            on_action_Save_triggered();\n\n        if (reply == QMessageBox::Cancel)\n            event->ignore();\n        else\n            event->accept();\n    }\n}\n\nvoid MainWindow::loadYacasPage()\n{\n    QDir resources_dir(_prefs.get_resources_path());\n    const QUrl url =\n        QUrl::fromLocalFile(resources_dir.absoluteFilePath(\"yacas_gui.html\"));\n\n    QWebChannel* c = new QWebChannel();\n    c->registerObject(\"yacas\", this);\n    _ui->webEngineView->page()->setWebChannel(c);\n\n    _ui->webEngineView->load(url);\n}\n\nvoid MainWindow::print(QPrinter* printer)\n{\n#if QT_VERSION_MAJOR >= 5 && QT_VERSION_MINOR >= 8\n    _ui->webEngineView->page()->print(printer, [](bool) {});\n#endif\n}\n\nvoid MainWindow::on_action_New_triggered()\n{\n    MainWindow* w = new MainWindow(_prefs);\n    w->show();\n}\n\nvoid MainWindow::on_action_Open_triggered()\n{\n    QString fname = QFileDialog::getOpenFileName(\n        this, \"Open\", _prefs.get_cwd(), \"Yagy files (*.ygy);;All files (*)\");\n\n    if (fname.length() == 0)\n        return;\n\n    QFile f(fname);\n\n    if (!f.open(QIODevice::ReadOnly)) {\n        qWarning(\"Couldn't open file for loading.\");\n        return;\n    }\n\n    QByteArray data = f.readAll();\n\n    loadYacasPage();\n\n    foreach (const QJsonValue& v, QJsonDocument::fromJson(data).array())\n        _ui->webEngineView->page()->runJavaScript(\n            QString(\"calculate(\\\"\") +\n            v.toObject()[\"input\"].toString().replace(\"\\\"\", \"\\\\\\\"\") +\n            QString(\"\\\");\"));\n\n    _fname = fname;\n    _modified = false;\n    _has_file = true;\n    _update_title();\n\n    _prefs.set_cwd(QFileInfo(f).canonicalPath());\n}\n\nvoid MainWindow::on_action_Save_triggered()\n{\n    if (!_has_file)\n        on_action_Save_As_triggered();\n    else\n        _save();\n}\n\nvoid MainWindow::on_action_Save_As_triggered()\n{\n    QString fname = QFileDialog::getSaveFileName(\n        this, \"Save\", _fname, \"Yacas GUI files (*.ygy);;All files (*)\");\n\n    if (fname.length() == 0)\n        return;\n\n    if (QFileInfo(fname).suffix() == \"\")\n        fname += \".ygy\";\n\n    _fname = fname;\n\n    _save();\n}\n\nvoid MainWindow::on_action_Print_triggered()\n{\n    if (!_printer)\n        _printer.reset(new QPrinter);\n\n    QScopedPointer<QPrintDialog> d(new QPrintDialog(_printer.data(), this));\n    d->setAttribute(Qt::WA_DeleteOnClose);\n    connect(d.data(), SIGNAL(accepted(QPrinter*)), SLOT(print(QPrinter*)));\n    d->show();\n    d.take();\n}\n\nvoid MainWindow::on_action_Close_triggered()\n{\n    close();\n}\n\nvoid MainWindow::on_action_Quit_triggered()\n{\n    foreach (MainWindow* w, _windows)\n        w->close();\n}\n\nvoid MainWindow::on_actionCu_t_triggered()\n{\n    _ui->webEngineView->triggerPageAction(QWebEnginePage::Cut);\n}\n\nvoid MainWindow::on_action_Copy_triggered()\n{\n    _ui->webEngineView->triggerPageAction(QWebEnginePage::Copy);\n}\n\nvoid MainWindow::on_action_Paste_triggered()\n{\n    _ui->webEngineView->triggerPageAction(QWebEnginePage::Paste);\n}\n\nvoid MainWindow::on_actionPreferences_triggered()\n{\n    PreferencesDialog(_prefs, this).exec();\n}\n\nvoid MainWindow::on_actionInsert_Before_triggered()\n{\n    _ui->webEngineView->page()->runJavaScript(\"insertBeforeCurrent();\");\n}\n\nvoid MainWindow::on_action_Previous_triggered()\n{\n    _ui->webEngineView->page()->runJavaScript(\"previousCell();\");\n}\n\nvoid MainWindow::on_action_Next_triggered()\n{\n    _ui->webEngineView->page()->runJavaScript(\"nextCell();\");\n}\n\nvoid MainWindow::on_actionInsert_After_triggered()\n{\n    _ui->webEngineView->page()->runJavaScript(\"insertAfterCurrent();\");\n}\n\nvoid MainWindow::on_actionDelete_Current_triggered()\n{\n    _ui->webEngineView->page()->runJavaScript(\"deleteCurrent();\");\n}\n\nvoid MainWindow::on_action_Use_triggered()\n{\n    QString fname = QFileDialog::getOpenFileName(\n        this, \"Open\", \"\", \"Yacas scripts (*.ys);;All files (*)\");\n\n    if (fname.length() == 0)\n        return;\n\n    QFile f(fname);\n\n    if (!f.open(QIODevice::ReadOnly)) {\n        qWarning(\"Couldn't open file for loading.\");\n        return;\n    }\n\n    _ui->webEngineView->page()->runJavaScript(QString(\"calculate('Use(\\\"\") +\n                                              fname + \"\\\")');\");\n}\n\nvoid MainWindow::on_action_Import_triggered()\n{\n    QString fname = QFileDialog::getOpenFileName(\n        this, \"Open\", \"\", \"Yacas scripts (*.ys);;All files (*)\");\n\n    if (fname.length() == 0)\n        return;\n\n    QFile f(fname);\n\n    if (!f.open(QIODevice::ReadOnly)) {\n        qWarning(\"Couldn't open file for loading.\");\n        return;\n    }\n\n    QString data = f.readAll();\n\n    QList<QString> l;\n\n    QString s;\n    bool in_string = false;\n    int level = 0;\n    for (QString::const_iterator i = data.begin(); i != data.end(); ++i) {\n\n        if (in_string) {\n            s.push_back(*i);\n            if (*i == '\"')\n                in_string = false;\n            continue;\n        }\n\n        if (*i == '\"') {\n            s.push_back(*i);\n            in_string = true;\n            continue;\n        }\n\n        if (*i == '[') {\n            s.push_back(*i);\n            level += 1;\n            continue;\n        }\n\n        if (*i == ']') {\n            s.push_back(*i);\n            level -= 1;\n            continue;\n        }\n\n        if (*i == '\\n' && s.isEmpty())\n            continue;\n\n        if (*i == ';' && level == 0) {\n            l.push_back(s);\n            s.clear();\n            continue;\n        }\n\n        if (*i == '\\n') {\n            s.push_back(\"\\\\n\");\n            continue;\n        }\n\n        s.push_back(*i);\n    }\n\n    foreach (const QString& s, l)\n        _ui->webEngineView->page()->runJavaScript(QString(\"calculate('\") + s +\n                                                  \"');\");\n}\n\nvoid MainWindow::on_action_Export_triggered()\n{\n    QString fname = QFileDialog::getSaveFileName(\n        this, \"Open\", \"\", \"Yacas scripts (*.ys);;All files (*)\");\n\n    if (fname.length() == 0)\n        return;\n\n    _ui->webEngineView->page()->runJavaScript(\n        \"exportScript();\", [fname](const QVariant& v) {\n            QFile f(fname);\n\n            if (!f.open(QIODevice::WriteOnly)) {\n                qWarning(\"Couldn't open file for saving.\");\n                return;\n            }\n\n            for (const QString& s : v.toStringList()) {\n                f.write(s.toLatin1());\n                f.write(\"\\n\");\n            }\n        });\n}\n\nvoid MainWindow::on_actionEvaluate_Current_triggered()\n{\n    _ui->webEngineView->page()->runJavaScript(QString(\"evaluateCurrent()\"));\n}\n\nvoid MainWindow::on_actionEvaluate_All_triggered()\n{\n    _ui->webEngineView->page()->runJavaScript(QString(\"evaluateAll()\"));\n}\n\nvoid MainWindow::on_action_Stop_triggered()\n{\n    _yacas_server->cancel();\n}\n\nvoid MainWindow::on_action_Restart_triggered()\n{\n    const QMessageBox::StandardButton reply = QMessageBox::question(\n        this, \"Restart\", \"Restart Yacas?\", QMessageBox::Yes | QMessageBox::No);\n\n    if (reply == QMessageBox::Yes) {\n        delete _yacas_server;\n        _yacas_server = new YacasServer(_scripts_path);\n    }\n}\n\nvoid MainWindow::on_actionYacas_Manual_triggered()\n{\n    QDesktopServices::openUrl(QUrl(\n        \"http://yacas.readthedocs.org/en/latest/reference_manual/index.html\"));\n}\n\nvoid MainWindow::on_actionCurrent_Symbol_Help_triggered()\n{\n    _ui->webEngineView->page()->runJavaScript(\"contextHelp()\");\n}\n\nvoid MainWindow::on_action_About_triggered()\n{\n    QString about = \"Yacas GUI version %1\\n\"\n                    \"\\n\"\n                    \"Powered by Yacas version %1\";\n\n    QMessageBox::about(this, \"About Yacas GUI\", about.arg(YACAS_VERSION));\n}\n\nvoid MainWindow::handle_engine_busy(bool busy)\n{\n    _ui->action_Stop->setEnabled(busy);\n}\n\nvoid MainWindow::handle_prefs_changed()\n{\n    _ui->toolBar->setVisible(_prefs.get_enable_toolbar());\n    _ui->webEngineView->page()->runJavaScript(\n        QString(\"changeMathJaxScale(%1)\").arg(_prefs.get_math_font_scale()));\n    QString font = _prefs.get_math_font();\n    if (font == \"Default\")\n        font = \"TeX\";\n    _ui->webEngineView->page()->runJavaScript(\n        QString(\"changeMathJaxFont(\\\"%1\\\")\").arg(font));\n\n    if (_scripts_path != _prefs.get_scripts_path()) {\n        _scripts_path = _prefs.get_scripts_path();\n        delete _yacas_server;\n        _yacas_server = new YacasServer(_scripts_path);\n        delete _yacas2tex;\n        _yacas2tex = new CYacas(_null_stream);\n        _yacas2tex->Evaluate(((std::string(\"DefaultDirectory(\\\"\") +\n                               _scripts_path.toStdString() + \"\\\");\"))\n                                 .c_str());\n        _yacas2tex->Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n    }\n}\n\nvoid MainWindow::eval(int idx, QString expr)\n{\n    new CellProxy(\n        _ui->webEngineView->page(), idx, expr, *_yacas_server, *_yacas2tex);\n\n    if (!_modified) {\n        _modified = true;\n        _update_title();\n    }\n}\n\nQStringList MainWindow::complete(QString p)\n{\n    QStringList hints;\n\n    for (const QString& s : _yacas_server->symbols())\n        if (s.startsWith(p))\n            hints.push_back(s);\n\n    hints.sort();\n\n    return hints;\n}\n\nvoid MainWindow::help(QString s, int cp)\n{\n    if (s.length() == 0)\n        return;\n\n    if (cp >= s.length())\n        cp = s.length() - 1;\n\n    int b = QRegExp(\"[^a-zA-Z']\").lastIndexIn(s, cp);\n    if (b == cp && cp > 0)\n        b = QRegExp(\"[^a-zA-Z']\").lastIndexIn(s, cp - 1);\n\n    if (b == -1)\n        b = 0;\n\n    QRegExp word_rx(\"[a-zA-Z']+\");\n\n    if (word_rx.indexIn(s, b) == -1)\n        return;\n\n    const QString key = word_rx.cap(0);\n\n    QDir doc_dir(QApplication::applicationDirPath());\n#ifdef __APPLE__\n    doc_dir.cd(\"../SharedFrameworks/yacas.framework/Versions/Current/Resources/\"\n               \"documentation/singlehtml\");\n#else\n    doc_dir.cd(\"../share/yacas/documentation/singlehtml\");\n#endif\n\n    const QString ref = QString(\"file://\") + doc_dir.canonicalPath() +\n                        QString(\"/index.html#\") + key;\n\n    QDesktopServices::openUrl(QUrl(ref));\n}\n\nvoid MainWindow::on_contentsChanged()\n{\n    if (!_modified) {\n        _modified = true;\n        _update_title();\n    }\n}\n\nvoid MainWindow::on_initComplete()\n{\n    handle_prefs_changed();\n    _modified = false;\n    _update_title();\n}\n\nint MainWindow::getIsWebGLEnabled()\n{\n    return _prefs.get_enable_WebGL();\n}\n\nvoid MainWindow::_save()\n{\n    QFile f(_fname);\n\n    if (!f.open(QIODevice::WriteOnly)) {\n        qWarning(\"Couldn't open file for saving.\");\n        return;\n    }\n\n    _ui->webEngineView->page()->runJavaScript(\n        \"getAllInputs()\", [&f](const QVariant& v) {\n            QJsonArray j;\n            foreach (const QVariant e, v.toList()) {\n                QJsonObject o;\n                o[\"input\"] = e.toString();\n                j.push_back(o);\n            }\n\n            QJsonDocument d(j);\n\n            f.write(d.toJson());\n        });\n\n    _modified = false;\n    _has_file = true;\n    _update_title();\n}\n\nvoid MainWindow::_update_title()\n{\n    QString title = QFileInfo(_fname).baseName();\n\n    if (_modified)\n        title = \"*\" + title;\n\n    setWindowTitle(title);\n\n    _ui->action_Save->setEnabled(_modified);\n}\n\nvoid MainWindow::copyToClipboard(QString newText)\n{\n    QClipboard* clipboard = QApplication::clipboard();\n    clipboard->setText(newText);\n}\n\nQList<MainWindow*> MainWindow::_windows;\nunsigned MainWindow::_cntr = 1;\n"
  },
  {
    "path": "cyacas/yacas-gui/src/preferences.cpp",
    "content": "#include \"preferences.h\"\n\n#include <QtCore/QDir>\n\nPreferences::Preferences(const QApplication& app)\n{\n    QDir dir(app.applicationDirPath());\n#ifdef __APPLE__\n    dir.cd(\"../Resources/scripts\");\n#else\n    dir.cd(\"../share/yacas/scripts\");\n#endif\n    _default_scripts_path = dir.canonicalPath() + \"/\";\n\n    dir.setPath(app.applicationDirPath());\n#ifdef __APPLE__\n    dir.cd(\"../Resources\");\n#else\n    dir.cd(\"../share/yacas/resources\");\n#endif\n    _default_resources_path = dir.canonicalPath();\n}\n\nbool Preferences::get_enable_toolbar() const\n{\n    return _settings.value(\"View/enable_toolbar\", true).toBool();\n}\n\nvoid Preferences::set_enable_toolbar(bool state)\n{\n    if (_settings.value(\"View/enable_toolbar\", true).toBool() != state) {\n        _settings.setValue(\"View/enable_toolbar\", state);\n        emit changed();\n    }\n}\n\nunsigned Preferences::get_math_font_scale() const\n{\n    return _settings.value(\"View/math_font_scale\", 80u).toUInt();\n}\n\nvoid Preferences::set_math_font_scale(unsigned scale)\n{\n    if (_settings.value(\"View/math_font_scale\", 80u).toUInt() != scale) {\n        _settings.setValue(\"View/math_font_scale\", scale);\n        emit changed();\n    }\n}\n\nQString Preferences::get_math_font() const\n{\n    return _settings.value(\"View/math_font\", \"Default\").toString();\n}\n\nvoid Preferences::set_math_font(const QString& font)\n{\n    if (_settings.value(\"View/math_font\", \"Default\").toString() != font) {\n        _settings.setValue(\"View/math_font\", font);\n        emit changed();\n    }\n}\n\nbool Preferences::get_scripts_path_default() const\n{\n    return _settings.value(\"Engine/scripts_path_default\", true).toBool();\n}\n\nvoid Preferences::set_scripts_path_default(bool state)\n{\n    if (_settings.value(\"Engine/scripts_path_default\", true).toBool() !=\n        state) {\n        _settings.setValue(\"Engine/scripts_path_default\", state);\n        emit changed();\n    }\n}\n\nQString Preferences::get_default_scripts_path() const\n{\n    return _default_scripts_path;\n}\n\nQString Preferences::get_custom_scripts_path() const\n{\n    return _settings.value(\"Engine/custom_scripts_path\", \"\").toString();\n}\n\nvoid Preferences::set_custom_scripts_path(const QString& path)\n{\n    if (_settings.value(\"Engine/custom_scripts_path\", \"\").toString() != path) {\n        _settings.setValue(\"Engine/custom_scripts_path\", path);\n        emit changed();\n    }\n}\n\nQString Preferences::get_scripts_path() const\n{\n    if (get_scripts_path_default())\n        return get_default_scripts_path();\n\n    return get_custom_scripts_path();\n}\n\nQString Preferences::get_resources_path() const\n{\n    return _default_resources_path;\n}\n\nQString Preferences::get_cwd() const\n{\n    return _settings.value(\"working_directory\", QDir::homePath()).toString();\n}\n\nvoid Preferences::set_cwd(const QString& cwd)\n{\n    if (get_cwd() != cwd) {\n        _settings.setValue(\"working_directory\", cwd);\n        emit changed();\n    }\n}\n\nbool Preferences::get_enable_WebGL() const\n{\n    return _settings.value(\"View/enable_WebGL\", true).toBool();\n}\n\nvoid Preferences::set_enable_WebGL(bool state)\n{\n\n    if (_settings.value(\"View/enable_WebGL\", true).toBool() != state) {\n        _settings.setValue(\"View/enable_WebGL\", state);\n        emit changed();\n    }\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/src/preferences_dialog.cpp",
    "content": "#include \"preferences_dialog.h\"\n\n#include <QtWidgets/QFileDialog>\n#include <QtWidgets/QMessageBox>\n\nPreferencesDialog::PreferencesDialog(Preferences& prefs, QWidget* parent) :\n    QDialog(parent),\n    _prefs(prefs)\n{\n    setupUi(this);\n\n    enableToolbarCheckBox->setChecked(_prefs.get_enable_toolbar());\n    enableWebGLCheckBox->setChecked(_prefs.get_enable_WebGL());\n    mathFontScaleSpinBox->setValue(_prefs.get_math_font_scale());\n    mathFontComboBox->setCurrentIndex(\n        mathFontComboBox->findText(_prefs.get_math_font()));\n    pathEdit->setText(_prefs.get_custom_scripts_path());\n    defaultPathButton->setChecked(_prefs.get_scripts_path_default());\n    customPathButton->setChecked(!_prefs.get_scripts_path_default());\n}\n\nvoid PreferencesDialog::on_choosePathButton_clicked()\n{\n    const QString path =\n        QFileDialog::getExistingDirectory(this, \"Scripts Directory\", \"\");\n\n    if (!path.isNull())\n        pathEdit->setText(path + \"/\");\n}\n\nvoid PreferencesDialog::on_customPathButton_toggled(bool enabled)\n{\n    pathEdit->setEnabled(enabled);\n    choosePathButton->setEnabled(enabled);\n}\n\nvoid PreferencesDialog::accept()\n{\n    if (!defaultPathButton->isChecked()) {\n        if (!pathEdit->text().isEmpty() && !pathEdit->text().endsWith('/'))\n            pathEdit->setText(pathEdit->text() + \"/\");\n\n        if (!QFile(pathEdit->text() + \"yacasinit.ys\").exists()) {\n            QMessageBox::warning(\n                this, \"YAGY Warning\", \"Invalid custom scripts path.\");\n            return;\n        }\n    }\n\n    const QString old_path = _prefs.get_scripts_path();\n    const QString new_path = defaultPathButton->isChecked()\n                                 ? _prefs.get_default_scripts_path()\n                                 : pathEdit->text();\n    if (new_path != old_path)\n        if (QMessageBox::question(\n                this,\n                \"YAGY Preferences\",\n                \"The scripts path has changed. Engine restart required. Do you \"\n                \"want to proceed?\") == QMessageBox::No)\n            return;\n\n    _prefs.set_enable_toolbar(enableToolbarCheckBox->checkState());\n    _prefs.set_math_font_scale(mathFontScaleSpinBox->value());\n    _prefs.set_math_font(mathFontComboBox->currentText());\n    _prefs.set_custom_scripts_path(pathEdit->text());\n    _prefs.set_scripts_path_default(defaultPathButton->isChecked());\n    _prefs.set_enable_WebGL(enableWebGLCheckBox->checkState());\n\n    QDialog::accept();\n}\n\nvoid PreferencesDialog::reject()\n{\n    QDialog::reject();\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/src/yacasengine.cpp",
    "content": "#include \"yacasengine.h\"\n\n#include <string>\n\n#include <QtCore/QFile>\n#include <QtCore/QMutexLocker>\n#include <QtCore/QSet>\n\nYacasEngine::YacasEngine(const QString& scripts_path,\n                         YacasRequestQueue& requests,\n                         QObject* parent) :\n    QObject(parent),\n    _requests(requests),\n    _yacas(new CYacas(_side_effects)),\n    _idx(1)\n{\n    if (!QFile(scripts_path + \"yacasinit.ys\").exists())\n        throw std::runtime_error(QString(\"Invalid yacas scripts path: %1\")\n                                     .arg(scripts_path)\n                                     .toStdString());\n\n    _yacas->Evaluate(std::string(\"DefaultDirectory(\\\"\") +\n                     scripts_path.toStdString() + std::string(\"\\\");\"));\n    _yacas->Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n\n    _yacas->Evaluate(\"Plot2D'outputs();\");\n    _yacas->Evaluate(\"UnProtect(Plot2D'outputs);\");\n    _yacas->Evaluate(\"Plot2D'yagy(values_IsList, _options'hash) <-- \"\n                     \"Yagy'Plot2D'Data(values, options'hash);\");\n    _yacas->Evaluate(\n        \"Plot2D'outputs() := { {\\\"default\\\", \\\"yagy\\\"}, {\\\"data\\\", \"\n        \"\\\"Plot2D'data\\\"}, {\\\"gnuplot\\\", \\\"Plot2D'gnuplot\\\"}, {\\\"java\\\", \"\n        \"\\\"Plot2D'java\\\"}, {\\\"yagy\\\", \\\"Plot2D'yagy\\\"}, };\");\n    _yacas->Evaluate(\"Protect(Plot2D'outputs);\");\n    _yacas->Evaluate(\"Plot3DS'outputs();\");\n    _yacas->Evaluate(\"UnProtect(Plot3DS'outputs);\");\n    _yacas->Evaluate(\"Plot3DS'yagy(values_IsList, _options'hash) <-- \"\n                     \"Yagy'Plot3DS'Data(values, options'hash);\");\n    _yacas->Evaluate(\"Plot3DS'outputs() := { {\\\"default\\\", \\\"yagy\\\"}, \"\n                     \"{\\\"data\\\", \\\"Plot3DS'data\\\"}, {\\\"gnuplot\\\", \"\n                     \"\\\"Plot3DS'gnuplot\\\"}, {\\\"yagy\\\", \\\"Plot3DS'yagy\\\"},};\");\n    _yacas->Evaluate(\"Protect(Plot3DS'outputs);\");\n\n    _update_symbols();\n}\n\nYacasEngine::~YacasEngine()\n{\n    delete _yacas;\n}\n\nvoid YacasEngine::cancel()\n{\n    _yacas->getDefEnv().getEnv().stop_evaluation = true;\n}\n\nQStringList YacasEngine::symbols() const\n{\n    QMutexLocker lock(&_symbols_mtx);\n    return _symbols;\n}\n\nvoid YacasEngine::on_start_processing()\n{\n    for (;;) {\n\n        QMutexLocker lock(&_requests.mtx);\n\n        if (_requests.shutdown)\n            return;\n\n        busy(false);\n\n        _requests.cnd.wait(&_requests.mtx);\n\n        if (_requests.shutdown)\n            return;\n\n        _yacas->getDefEnv().getEnv().stop_evaluation = false;\n\n        busy(true);\n\n        while (!_requests.waiting.empty()) {\n            YacasRequest* request = _requests.waiting.dequeue();\n\n            // Beware of low flying butterflies\n            _requests.mtx.unlock();\n\n            const QString expr = request->take();\n\n            _side_effects.clear();\n            _side_effects.str(\"\");\n            _yacas->Evaluate((expr + \";\").toStdString());\n\n            _update_symbols();\n\n            if (!_yacas->IsError()) {\n                QString result = QString::fromStdString(_yacas->Result());\n                result = result.left(result.length() - 1).trimmed();\n\n                YacasRequest::ResultType result_type = YacasRequest::EXPRESSION;\n                if (result.startsWith(\"Yagy'Plot2D'Data\")) {\n                    result_type = YacasRequest::PLOT2D;\n                    result = result.remove(\"Yagy'Plot2D'Data(\");\n                    result.truncate(result.length() - 1);\n                } else if (result.startsWith(\"Yagy'Plot3DS'Data\")) {\n                    result_type = YacasRequest::PLOT3D;\n                    result = result.remove(\"Yagy'Plot3DS'Data(\");\n                    result.truncate(result.length() - 1);\n                } else if (result.startsWith(\"Graph(\")) {\n                    result_type = YacasRequest::GRAPH;\n                    result = result.remove(\"Graph(\");\n                    result.truncate(result.length() - 1);\n                }\n                request->answer(_idx++,\n                                result_type,\n                                result,\n                                QString::fromStdString(_side_effects.str()));\n            } else {\n                QString msg = QString::fromStdString(_yacas->Error());\n                request->answer(_idx++,\n                                YacasRequest::ERROR,\n                                msg.trimmed(),\n                                QString::fromStdString(_side_effects.str()));\n            }\n\n            _requests.mtx.lock();\n        }\n    }\n}\n\nvoid YacasEngine::_update_symbols()\n{\n    QMutexLocker lock(&_symbols_mtx);\n\n    _symbols.clear();\n\n    for (auto op : _yacas->getDefEnv().getEnv().PreFix())\n        _symbols.push_back(QString::fromStdString(*op.first));\n\n    for (auto op : _yacas->getDefEnv().getEnv().InFix())\n        _symbols.push_back(QString::fromStdString(*op.first));\n\n    for (auto op : _yacas->getDefEnv().getEnv().PostFix())\n        _symbols.push_back(QString::fromStdString(*op.first));\n\n    for (auto op : _yacas->getDefEnv().getEnv().Bodied())\n        _symbols.push_back(QString::fromStdString(*op.first));\n\n    for (auto op : _yacas->getDefEnv().getEnv().CoreCommands())\n        _symbols.push_back(QString::fromStdString(*op.first));\n\n    for (auto& op : _yacas->getDefEnv().getEnv().UserFunctions())\n        _symbols.push_back(QString::fromStdString(*op.first));\n\n    _symbols.removeDuplicates();\n    _symbols.sort();\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/src/yacasrequest.cpp",
    "content": "#include \"yacasrequest.h\"\n\nYacasRequest::YacasRequest(QString expr, QObject* parent) :\n    QObject(parent),\n    _expr(expr),\n    _state(WAITING)\n{\n}\n\nYacasRequest::State YacasRequest::state() const\n{\n    return _state;\n}\n\nQString YacasRequest::take()\n{\n    _state = BUSY;\n    emit state_changed(_state);\n    return _expr;\n}\n\nvoid YacasRequest::answer(unsigned idx,\n                          ResultType type,\n                          QString result,\n                          QString side_effects)\n{\n    _idx = idx;\n    _result_type = type;\n    _result = result;\n    _side_effects = side_effects;\n\n    _state = READY;\n\n    emit state_changed(_state);\n}\n\nYacasRequest::ResultType YacasRequest::result_type() const\n{\n    return _result_type;\n}\n\nQString YacasRequest::result() const\n{\n    return _result;\n}\n\nQString YacasRequest::side_effects() const\n{\n    return _side_effects;\n}\n"
  },
  {
    "path": "cyacas/yacas-gui/src/yacasserver.cpp",
    "content": "#include \"yacasserver.h\"\n\n#include <QDebug>\n#include <QMutexLocker>\n\nYacasServer::YacasServer(const QString& scripts_path, QObject* parent) :\n    QObject(parent)\n{\n    _requests.shutdown = false;\n\n    _engine = new YacasEngine(scripts_path, _requests);\n    _engine->moveToThread(&_engine_thread);\n    _engine_thread.start();\n    connect(&_engine_thread, SIGNAL(finished()), _engine, SLOT(deleteLater()));\n    connect(\n        this, SIGNAL(start_processing()), _engine, SLOT(on_start_processing()));\n    connect(_engine, SIGNAL(busy(bool)), this, SLOT(on_engine_busy(bool)));\n\n    emit start_processing();\n}\n\nYacasServer::~YacasServer()\n{\n    _requests.shutdown = true;\n    _requests.cnd.wakeAll();\n\n    _engine_thread.quit();\n    _engine_thread.wait();\n}\n\nvoid YacasServer::submit(YacasRequest* request)\n{\n    QMutexLocker lock(&_requests.mtx);\n    _requests.waiting.enqueue(request);\n    _requests.cnd.wakeAll();\n}\n\nvoid YacasServer::cancel()\n{\n    _engine->cancel();\n}\n\nQStringList YacasServer::symbols() const\n{\n    return _engine->symbols();\n}\n\nvoid YacasServer::on_engine_busy(bool b)\n{\n    busy(b);\n}"
  },
  {
    "path": "cyacas/yacas-gui/ui/mainwindow.ui",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ui version=\"4.0\">\n <class>MainWindow</class>\n <widget class=\"QMainWindow\" name=\"MainWindow\">\n  <property name=\"geometry\">\n   <rect>\n    <x>0</x>\n    <y>0</y>\n    <width>740</width>\n    <height>682</height>\n   </rect>\n  </property>\n  <property name=\"windowTitle\">\n   <string>Yagy</string>\n  </property>\n  <property name=\"windowIcon\">\n   <iconset resource=\"img.qrc\">\n    <normaloff>:/resources/img/icon.png</normaloff>:/resources/img/icon.png</iconset>\n  </property>\n  <property name=\"toolButtonStyle\">\n   <enum>Qt::ToolButtonFollowStyle</enum>\n  </property>\n  <property name=\"documentMode\">\n   <bool>false</bool>\n  </property>\n  <property name=\"dockNestingEnabled\">\n   <bool>false</bool>\n  </property>\n  <property name=\"unifiedTitleAndToolBarOnMac\">\n   <bool>true</bool>\n  </property>\n  <widget class=\"QWidget\" name=\"centralWidget\">\n   <layout class=\"QVBoxLayout\" name=\"verticalLayout\">\n    <property name=\"spacing\">\n     <number>0</number>\n    </property>\n    <property name=\"leftMargin\">\n     <number>0</number>\n    </property>\n    <property name=\"topMargin\">\n     <number>0</number>\n    </property>\n    <property name=\"rightMargin\">\n     <number>0</number>\n    </property>\n    <property name=\"bottomMargin\">\n     <number>0</number>\n    </property>\n    <item>\n     <widget class=\"QWebEngineView\" name=\"webEngineView\">\n      <property name=\"minimumSize\">\n       <size>\n        <width>250</width>\n        <height>100</height>\n       </size>\n      </property>\n      <property name=\"url\">\n       <url>\n        <string>qrc:/view.html</string>\n       </url>\n      </property>\n     </widget>\n    </item>\n   </layout>\n  </widget>\n  <widget class=\"QStatusBar\" name=\"statusBar\"/>\n  <widget class=\"QToolBar\" name=\"toolBar\">\n   <property name=\"windowTitle\">\n    <string>toolBar</string>\n   </property>\n   <property name=\"movable\">\n    <bool>false</bool>\n   </property>\n   <property name=\"toolButtonStyle\">\n    <enum>Qt::ToolButtonIconOnly</enum>\n   </property>\n   <property name=\"floatable\">\n    <bool>false</bool>\n   </property>\n   <attribute name=\"toolBarArea\">\n    <enum>TopToolBarArea</enum>\n   </attribute>\n   <attribute name=\"toolBarBreak\">\n    <bool>false</bool>\n   </attribute>\n   <addaction name=\"action_New\"/>\n   <addaction name=\"action_Open\"/>\n   <addaction name=\"action_Save\"/>\n   <addaction name=\"separator\"/>\n   <addaction name=\"action_Previous\"/>\n   <addaction name=\"action_Next\"/>\n   <addaction name=\"separator\"/>\n   <addaction name=\"actionInsert_Before\"/>\n   <addaction name=\"actionInsert_After\"/>\n   <addaction name=\"actionDelete_Current\"/>\n   <addaction name=\"separator\"/>\n   <addaction name=\"actionEvaluate_Current\"/>\n   <addaction name=\"actionEvaluate_All\"/>\n   <addaction name=\"action_Stop\"/>\n   <addaction name=\"separator\"/>\n   <addaction name=\"actionPreferences\"/>\n   <addaction name=\"actionCurrent_Symbol_Help\"/>\n   <addaction name=\"actionYacas_Manual\"/>\n  </widget>\n  <widget class=\"QMenuBar\" name=\"menuBar\">\n   <property name=\"geometry\">\n    <rect>\n     <x>0</x>\n     <y>0</y>\n     <width>740</width>\n     <height>22</height>\n    </rect>\n   </property>\n   <widget class=\"QMenu\" name=\"menu_File\">\n    <property name=\"title\">\n     <string>&amp;File</string>\n    </property>\n    <addaction name=\"action_New\"/>\n    <addaction name=\"action_Open\"/>\n    <addaction name=\"action_Save\"/>\n    <addaction name=\"action_Save_As\"/>\n    <addaction name=\"action_Print\"/>\n    <addaction name=\"action_Close\"/>\n    <addaction name=\"action_Quit\"/>\n   </widget>\n   <widget class=\"QMenu\" name=\"menu_Help\">\n    <property name=\"title\">\n     <string>&amp;Help</string>\n    </property>\n    <addaction name=\"actionYacas_Manual\"/>\n    <addaction name=\"actionCurrent_Symbol_Help\"/>\n    <addaction name=\"action_About\"/>\n   </widget>\n   <widget class=\"QMenu\" name=\"menu_Edit\">\n    <property name=\"title\">\n     <string>&amp;Edit</string>\n    </property>\n    <addaction name=\"actionCu_t\"/>\n    <addaction name=\"action_Copy\"/>\n    <addaction name=\"action_Paste\"/>\n    <addaction name=\"separator\"/>\n    <addaction name=\"actionPreferences\"/>\n   </widget>\n   <widget class=\"QMenu\" name=\"menuScript\">\n    <property name=\"title\">\n     <string>&amp;Script</string>\n    </property>\n    <addaction name=\"action_Use\"/>\n    <addaction name=\"separator\"/>\n    <addaction name=\"action_Import\"/>\n    <addaction name=\"action_Export\"/>\n   </widget>\n   <widget class=\"QMenu\" name=\"menu_Evaluate\">\n    <property name=\"title\">\n     <string>E&amp;valuate</string>\n    </property>\n    <addaction name=\"actionEvaluate_Current\"/>\n    <addaction name=\"actionEvaluate_All\"/>\n    <addaction name=\"separator\"/>\n    <addaction name=\"action_Stop\"/>\n    <addaction name=\"separator\"/>\n    <addaction name=\"action_Restart\"/>\n   </widget>\n   <widget class=\"QMenu\" name=\"menu_Cell\">\n    <property name=\"title\">\n     <string>&amp;Cell</string>\n    </property>\n    <addaction name=\"action_Previous\"/>\n    <addaction name=\"action_Next\"/>\n    <addaction name=\"separator\"/>\n    <addaction name=\"actionInsert_Before\"/>\n    <addaction name=\"actionInsert_After\"/>\n    <addaction name=\"actionDelete_Current\"/>\n   </widget>\n   <addaction name=\"menu_File\"/>\n   <addaction name=\"menu_Edit\"/>\n   <addaction name=\"menu_Cell\"/>\n   <addaction name=\"menu_Evaluate\"/>\n   <addaction name=\"menuScript\"/>\n   <addaction name=\"menu_Help\"/>\n  </widget>\n  <action name=\"action_New\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/new_document.svg</normaloff>:/resources/img/new_document.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;New</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+N</string>\n   </property>\n  </action>\n  <action name=\"action_Open\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/open_document_dark.svg</normaloff>:/resources/img/open_document_dark.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Open...</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+O</string>\n   </property>\n  </action>\n  <action name=\"action_Save\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/save_document.svg</normaloff>:/resources/img/save_document.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Save</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+S</string>\n   </property>\n  </action>\n  <action name=\"action_Save_As\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/save_as.svg</normaloff>:/resources/img/save_as.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Save &amp;As...</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+Shift+S</string>\n   </property>\n  </action>\n  <action name=\"action_About\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/info.svg</normaloff>:/resources/img/info.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;About</string>\n   </property>\n  </action>\n  <action name=\"action_Quit\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/exit.svg</normaloff>:/resources/img/exit.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Quit</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+Q</string>\n   </property>\n  </action>\n  <action name=\"action_Print\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/print.svg</normaloff>:/resources/img/print.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Print...</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+P</string>\n   </property>\n  </action>\n  <action name=\"actionYacas_Manual\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/help_2.svg</normaloff>:/resources/img/help_2.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Yacas &amp;Manual</string>\n   </property>\n  </action>\n  <action name=\"action_Copy\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/copy.svg</normaloff>:/resources/img/copy.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Copy</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+C</string>\n   </property>\n  </action>\n  <action name=\"action_Paste\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/paste.svg</normaloff>:/resources/img/paste.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Paste</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+V</string>\n   </property>\n  </action>\n  <action name=\"action_Use\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/use_script.svg</normaloff>:/resources/img/use_script.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Use</string>\n   </property>\n  </action>\n  <action name=\"action_Import\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/import.svg</normaloff>:/resources/img/import.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Import</string>\n   </property>\n  </action>\n  <action name=\"action_Restart\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/restart_yacas.svg</normaloff>:/resources/img/restart_yacas.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Restart Yacas</string>\n   </property>\n  </action>\n  <action name=\"action_Stop\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/interupt.svg</normaloff>:/resources/img/interupt.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Stop</string>\n   </property>\n   <property name=\"toolTip\">\n    <string>Stop evaluation</string>\n   </property>\n  </action>\n  <action name=\"actionEvaluate_Current\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/evaluate.svg</normaloff>:/resources/img/evaluate.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Current</string>\n   </property>\n   <property name=\"toolTip\">\n    <string>Evaluate current cell</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Shift+Return</string>\n   </property>\n  </action>\n  <action name=\"actionEvaluate_All\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/reevaluate_2.svg</normaloff>:/resources/img/reevaluate_2.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;All</string>\n   </property>\n   <property name=\"toolTip\">\n    <string>Reevaluate all</string>\n   </property>\n  </action>\n  <action name=\"action_Export\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/export.svg</normaloff>:/resources/img/export.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Export</string>\n   </property>\n  </action>\n  <action name=\"action_Close\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/close_document.svg</normaloff>:/resources/img/close_document.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Close Window</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+W</string>\n   </property>\n  </action>\n  <action name=\"actionInsert_Before\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/add_above.svg</normaloff>:/resources/img/add_above.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Insert &amp;Before</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+Shift+Up</string>\n   </property>\n  </action>\n  <action name=\"actionInsert_After\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/add_below.svg</normaloff>:/resources/img/add_below.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Insert &amp;After</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+Shift+Down</string>\n   </property>\n  </action>\n  <action name=\"actionDelete_Current\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/delete_current.svg</normaloff>:/resources/img/delete_current.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Delete Current</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+D</string>\n   </property>\n  </action>\n  <action name=\"actionCurrent_Symbol_Help\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/help.svg</normaloff>:/resources/img/help.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Current &amp;Symbol Help</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+H</string>\n   </property>\n  </action>\n  <action name=\"action_Next\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/cell_next.svg</normaloff>:/resources/img/cell_next.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Next</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+Shift+Down</string>\n   </property>\n  </action>\n  <action name=\"action_Previous\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/cell_previous.svg</normaloff>:/resources/img/cell_previous.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>&amp;Previous</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+Shift+Up</string>\n   </property>\n  </action>\n  <action name=\"actionPreferences\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/preferences.svg</normaloff>:/resources/img/preferences.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Preferences...</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+,</string>\n   </property>\n  </action>\n  <action name=\"actionCu_t\">\n   <property name=\"icon\">\n    <iconset resource=\"img.qrc\">\n     <normaloff>:/resources/img/cut.svg</normaloff>:/resources/img/cut.svg</iconset>\n   </property>\n   <property name=\"text\">\n    <string>Cu&amp;t</string>\n   </property>\n   <property name=\"shortcut\">\n    <string>Ctrl+X</string>\n   </property>\n  </action>\n </widget>\n <layoutdefault spacing=\"6\" margin=\"11\"/>\n <customwidgets>\n  <customwidget>\n   <class>QWebEngineView</class>\n   <extends>QWidget</extends>\n   <header>QtWebEngineWidgets/QWebEngineView</header>\n  </customwidget>\n </customwidgets>\n <resources>\n  <include location=\"img.qrc\"/>\n  <include location=\"img.qrc\"/>\n </resources>\n <connections/>\n</ui>\n"
  },
  {
    "path": "cyacas/yacas-gui/ui/preferences_dialog.ui",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ui version=\"4.0\">\n <class>PreferencesDialog</class>\n <widget class=\"QDialog\" name=\"PreferencesDialog\">\n  <property name=\"geometry\">\n   <rect>\n    <x>0</x>\n    <y>0</y>\n    <width>386</width>\n    <height>288</height>\n   </rect>\n  </property>\n  <property name=\"windowTitle\">\n   <string>Preferences</string>\n  </property>\n  <layout class=\"QVBoxLayout\" name=\"verticalLayout\">\n   <item>\n    <widget class=\"QTabWidget\" name=\"tabWidget\">\n     <property name=\"currentIndex\">\n      <number>0</number>\n     </property>\n     <widget class=\"QWidget\" name=\"viewTab\">\n      <attribute name=\"title\">\n       <string>View</string>\n      </attribute>\n      <layout class=\"QGridLayout\" name=\"gridLayout_2\">\n       <property name=\"topMargin\">\n        <number>12</number>\n       </property>\n       <property name=\"bottomMargin\">\n        <number>15</number>\n       </property>\n       <property name=\"spacing\">\n        <number>6</number>\n       </property>\n       <item row=\"0\" column=\"0\" colspan=\"3\">\n        <widget class=\"QCheckBox\" name=\"enableToolbarCheckBox\">\n         <property name=\"text\">\n          <string>Enable toolbar</string>\n         </property>\n         <property name=\"checked\">\n          <bool>true</bool>\n         </property>\n        </widget>\n       </item>\n       <item row=\"7\" column=\"0\">\n        <spacer name=\"verticalSpacer_2\">\n         <property name=\"orientation\">\n          <enum>Qt::Vertical</enum>\n         </property>\n         <property name=\"sizeHint\" stdset=\"0\">\n          <size>\n           <width>20</width>\n           <height>40</height>\n          </size>\n         </property>\n        </spacer>\n       </item>\n       <item row=\"5\" column=\"2\">\n        <widget class=\"QSpinBox\" name=\"mathFontScaleSpinBox\">\n         <property name=\"suffix\">\n          <string>%</string>\n         </property>\n         <property name=\"minimum\">\n          <number>50</number>\n         </property>\n         <property name=\"maximum\">\n          <number>400</number>\n         </property>\n         <property name=\"value\">\n          <number>100</number>\n         </property>\n        </widget>\n       </item>\n       <item row=\"5\" column=\"0\">\n        <widget class=\"QLabel\" name=\"label\">\n         <property name=\"text\">\n          <string>Math font scale:</string>\n         </property>\n        </widget>\n       </item>\n       <item row=\"3\" column=\"0\">\n        <widget class=\"QCheckBox\" name=\"enableWebGLCheckBox\">\n         <property name=\"enabled\">\n          <bool>true</bool>\n         </property>\n         <property name=\"text\">\n          <string>Enable WebGL</string>\n         </property>\n         <property name=\"checked\">\n          <bool>true</bool>\n         </property>\n        </widget>\n       </item>\n       <item row=\"6\" column=\"0\">\n        <widget class=\"QLabel\" name=\"label_2\">\n         <property name=\"text\">\n          <string>Math font:</string>\n         </property>\n        </widget>\n       </item>\n       <item row=\"6\" column=\"2\">\n        <widget class=\"QComboBox\" name=\"mathFontComboBox\">\n         <item>\n          <property name=\"text\">\n           <string>Default</string>\n          </property>\n         </item>\n         <item>\n          <property name=\"text\">\n           <string>TeX</string>\n          </property>\n         </item>\n         <item>\n          <property name=\"text\">\n           <string>STIX</string>\n          </property>\n         </item>\n        </widget>\n       </item>\n      </layout>\n     </widget>\n     <widget class=\"QWidget\" name=\"engineTab\">\n      <attribute name=\"title\">\n       <string>Engine</string>\n      </attribute>\n      <layout class=\"QVBoxLayout\" name=\"verticalLayout_2\">\n       <item>\n        <widget class=\"QLabel\" name=\"label_4\">\n         <property name=\"text\">\n          <string>Scripts location:</string>\n         </property>\n        </widget>\n       </item>\n       <item>\n        <widget class=\"QWidget\" name=\"widget_2\" native=\"true\">\n         <layout class=\"QGridLayout\" name=\"gridLayout\">\n          <item row=\"0\" column=\"0\" colspan=\"2\">\n           <widget class=\"QRadioButton\" name=\"defaultPathButton\">\n            <property name=\"text\">\n             <string>Default</string>\n            </property>\n            <property name=\"checked\">\n             <bool>true</bool>\n            </property>\n           </widget>\n          </item>\n          <item row=\"1\" column=\"0\">\n           <widget class=\"QRadioButton\" name=\"customPathButton\">\n            <property name=\"text\">\n             <string/>\n            </property>\n           </widget>\n          </item>\n          <item row=\"1\" column=\"1\">\n           <widget class=\"QLineEdit\" name=\"pathEdit\">\n            <property name=\"enabled\">\n             <bool>false</bool>\n            </property>\n            <property name=\"clearButtonEnabled\">\n             <bool>false</bool>\n            </property>\n           </widget>\n          </item>\n          <item row=\"1\" column=\"2\">\n           <widget class=\"QToolButton\" name=\"choosePathButton\">\n            <property name=\"enabled\">\n             <bool>false</bool>\n            </property>\n            <property name=\"text\">\n             <string>...</string>\n            </property>\n            <property name=\"autoRaise\">\n             <bool>false</bool>\n            </property>\n            <property name=\"arrowType\">\n             <enum>Qt::NoArrow</enum>\n            </property>\n           </widget>\n          </item>\n         </layout>\n        </widget>\n       </item>\n       <item>\n        <spacer name=\"verticalSpacer\">\n         <property name=\"orientation\">\n          <enum>Qt::Vertical</enum>\n         </property>\n         <property name=\"sizeHint\" stdset=\"0\">\n          <size>\n           <width>20</width>\n           <height>40</height>\n          </size>\n         </property>\n        </spacer>\n       </item>\n      </layout>\n     </widget>\n    </widget>\n   </item>\n   <item>\n    <widget class=\"QWidget\" name=\"widget\" native=\"true\">\n     <layout class=\"QHBoxLayout\" name=\"horizontalLayout\">\n      <item>\n       <spacer name=\"horizontalSpacer\">\n        <property name=\"orientation\">\n         <enum>Qt::Horizontal</enum>\n        </property>\n        <property name=\"sizeHint\" stdset=\"0\">\n         <size>\n          <width>156</width>\n          <height>20</height>\n         </size>\n        </property>\n       </spacer>\n      </item>\n      <item>\n       <widget class=\"QDialogButtonBox\" name=\"buttonBox\">\n        <property name=\"orientation\">\n         <enum>Qt::Horizontal</enum>\n        </property>\n        <property name=\"standardButtons\">\n         <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>\n        </property>\n       </widget>\n      </item>\n     </layout>\n    </widget>\n   </item>\n  </layout>\n </widget>\n <tabstops>\n  <tabstop>tabWidget</tabstop>\n  <tabstop>enableToolbarCheckBox</tabstop>\n  <tabstop>buttonBox</tabstop>\n  <tabstop>defaultPathButton</tabstop>\n  <tabstop>customPathButton</tabstop>\n  <tabstop>pathEdit</tabstop>\n  <tabstop>choosePathButton</tabstop>\n </tabstops>\n <resources/>\n <connections>\n  <connection>\n   <sender>buttonBox</sender>\n   <signal>accepted()</signal>\n   <receiver>PreferencesDialog</receiver>\n   <slot>accept()</slot>\n   <hints>\n    <hint type=\"sourcelabel\">\n     <x>248</x>\n     <y>254</y>\n    </hint>\n    <hint type=\"destinationlabel\">\n     <x>157</x>\n     <y>274</y>\n    </hint>\n   </hints>\n  </connection>\n  <connection>\n   <sender>buttonBox</sender>\n   <signal>rejected()</signal>\n   <receiver>PreferencesDialog</receiver>\n   <slot>reject()</slot>\n   <hints>\n    <hint type=\"sourcelabel\">\n     <x>316</x>\n     <y>260</y>\n    </hint>\n    <hint type=\"destinationlabel\">\n     <x>286</x>\n     <y>274</y>\n    </hint>\n   </hints>\n  </connection>\n </connections>\n</ui>\n"
  },
  {
    "path": "cyacas/yacas-gui/winres/yacas_gui.rc",
    "content": "#include \"winver.h\"\n#include \"yacas/yacas_version.h\"\n\nVS_VERSION_INFO VERSIONINFO\nFILEVERSION     YACAS_VERSION_MAJOR, YACAS_VERSION_MINOR, YACAS_VERSION_MICRO, 0\nPRODUCTVERSION  YACAS_VERSION_MAJOR, YACAS_VERSION_MINOR, YACAS_VERSION_MICRO, 0\nFILEFLAGSMASK  \tVS_FFI_FILEFLAGSMASK\nFILEFLAGS      \tVS_FF_PRERELEASE\nFILEOS          VOS__WINDOWS32\nFILETYPE        VFT_APP\n\nBEGIN\n    BLOCK \"StringFileInfo\"\n    BEGIN\n        BLOCK \"040904E4\"\n        BEGIN\n            VALUE \"FileVersion\",      YACAS_VERSION\n            VALUE \"LegalCopyright\",   \"GPL2\"\n            VALUE \"ProductName\",      \"yacas_gui\"\n            VALUE \"ProductVersion\",   YACAS_VERSION\n        END\n    END\n    BLOCK \"VarFileInfo\"\n    BEGIN\n        VALUE \"Translation\", 0x409, 1252\n    END\nEND\n\n100             ICON \"yacas_gui.ico\"\n"
  },
  {
    "path": "cyacas/yacas-gui/yacas-gui.desktop",
    "content": "[Desktop Entry]\nName=yacas-gui\nComment=Yacas GUI\nExec=yacas-gui\nIcon=yacas-gui\nTerminal=false\nType=Application\nCategories=Science;Math\n"
  },
  {
    "path": "cyacas/yacas-kernel/CMakeLists.txt",
    "content": "#\n#\n# This file is part of yacas.\n# Yacas is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesset General Public License as\n# published by the Free Software Foundation, either version 2.1\n# of the License, or (at your option) any later version.\n#\n# Yacas is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n#\n#\n\nif (UNIX)\n    find_path (ZEROMQ_INCLUDE_DIRS zmq.hpp)\n    find_library (ZEROMQ_LIBRARY NAMES zmq)\nelse ()\n    find_package(ZeroMQ REQUIRED)\n    find_package(cppzmq CONFIG REQUIRED)\nendif ()\n\n# https://github.com/open-source-parsers/jsoncpp/wiki/Building#another-approach-for-cmake\nfind_package(jsoncpp CONFIG REQUIRED)\nget_target_property(JSON_INC_PATH jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)\nfind_package (OpenSSL)\nfind_package (Boost REQUIRED date_time filesystem)\n\nadd_executable (yacas-kernel src/main.cpp src/yacas_kernel.cpp src/yacas_engine.cpp src/hmac_sha256.cpp src/base64.cpp)\n\nset_target_properties (yacas-kernel PROPERTIES  INTERPROCEDURAL_OPTIMIZATION ${IPO_SUPPORTED})\n\ntarget_include_directories (yacas-kernel PRIVATE include)\ntarget_include_directories (yacas-kernel PRIVATE ${ZeroMQ_INCLUDE_DIRS})\ntarget_include_directories (yacas-kernel PRIVATE ${JSON_INC_PATH})\n\nif (UNIX)\n    target_link_libraries (yacas-kernel PRIVATE libyacas ${ZEROMQ_LIBRARY} jsoncpp_lib OpenSSL::SSL OpenSSL::Crypto Boost::boost  Boost::date_time Boost::filesystem pthread ${CMAKE_DL_LIBS})\nelse ()\n    target_link_libraries (yacas-kernel PRIVATE libyacas libzmq cppzmq cppzmq-static jsoncpp_lib jsoncpp_object OpenSSL::SSL OpenSSL::Crypto Boost::boost  Boost::date_time Boost::filesystem bcrypt)\nendif ()\n\n\ninstall (TARGETS yacas-kernel DESTINATION ${CMAKE_INSTALL_BINDIR})\n"
  },
  {
    "path": "cyacas/yacas-kernel/include/base64.hpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#ifndef BASE64_HPP\n#define BASE64_HPP\n\n#include <string>\n#include <vector>\n\nstd::string base64_encode(std::vector<unsigned char>);\n\n#endif\n"
  },
  {
    "path": "cyacas/yacas-kernel/include/hmac_sha256.hpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n/*\n * File:   hmac_sha256.hpp\n * Author: mazur\n *\n * Created on November 4, 2015, 11:55 AM\n */\n\n#ifndef HMAC_SHA256_HPP\n#define HMAC_SHA256_HPP\n\n#include <openssl/hmac.h>\n#include <string>\n\nclass HMAC_SHA256 {\npublic:\n    explicit HMAC_SHA256(const std::string& key);\n    HMAC_SHA256(const std::string& key, const std::string& msg);\n    HMAC_SHA256(const HMAC_SHA256&);\n    ~HMAC_SHA256();\n\n    void update(const std::string&);\n\n    std::string hexdigest();\n\nprivate:\n    HMAC_CTX* _ctx;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/yacas-kernel/include/yacas_engine.hpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n/*\n * File:   yacas_engine.hpp\n * Author: mazur\n *\n * Created on November 7, 2015, 12:52 PM\n */\n\n#ifndef YACAS_ENGINE_HPP\n#define YACAS_ENGINE_HPP\n\n#include \"yacas/yacas.h\"\n\n#include <zmq.hpp>\n\n#include <atomic>\n#include <condition_variable>\n#include <deque>\n#include <mutex>\n#include <sstream>\n#include <string>\n#include <thread>\n\nclass YacasEngine {\npublic:\n    YacasEngine(const std::string& scripts_path,\n                zmq::context_t& ctx,\n                const std::string& endpoint = \"inproc://engine\");\n\n    ~YacasEngine();\n\n    void submit(unsigned long id, const std::string& expr);\n\nprivate:\n    void _worker();\n\n    std::ostringstream _side_effects;\n    CYacas _yacas;\n\n    struct TaskInfo {\n        unsigned long id;\n        std::string expr;\n    };\n\n    std::deque<TaskInfo> _tasks;\n\n    std::mutex _mtx;\n    std::condition_variable _cv;\n\n    std::thread* _worker_thread;\n\n    zmq::socket_t _socket;\n\n    std::atomic<bool> _shutdown;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/yacas-kernel/include/yacas_kernel.hpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n/*\n * File:   yacas_kernel.hpp\n * Author: mazur\n *\n * Created on November 6, 2015, 3:10 PM\n */\n\n#ifndef YACAS_KERNEL_HPP\n#define YACAS_KERNEL_HPP\n\n#include \"hmac_sha256.hpp\"\n#include \"yacas_engine.hpp\"\n\n#include <boost/uuid/random_generator.hpp>\n#include <json/json.h>\n#include <zmq.hpp>\n#include <zmq_addon.hpp>\n#include <map>\n#include <sstream>\n\nclass YacasKernel : NonCopyable {\npublic:\n    YacasKernel(const std::string& scripts_path, const Json::Value&);\n\n    void run();\n\nprivate:\n    class Session : NonCopyable {\n    public:\n        explicit Session(const std::string& key);\n\n        const HMAC_SHA256& auth() const { return _auth; };\n        const boost::uuids::uuid& uuid() const { return _uuid; };\n\n        boost::uuids::uuid generate_msg_uuid() const { return _uuid_gen(); }\n\n    private:\n        HMAC_SHA256 _auth;\n\n        mutable boost::uuids::random_generator _uuid_gen;\n        boost::uuids::uuid _uuid;\n    };\n\n    class Request : NonCopyable {\n    public:\n        Request(const Session& session, const zmq::multipart_t& msg);\n\n        const Json::Value& header() const { return _header; }\n        const Json::Value& content() const { return _content; }\n\n        void reply(zmq::socket_t&,\n                   const std::string& type,\n                   const Json::Value& content) const;\n\n    private:\n        const Session& _session;\n        Json::Value _header;\n        Json::Value _content;\n        Json::Value _metadata;\n        std::string _identities_buf;\n    };\n\n    void _handle_shell(const std::shared_ptr<Request>& request);\n    void _handle_engine(const zmq::multipart_t& msg);\n\n    Session _session;\n\n    zmq::context_t _ctx;\n\n    zmq::socket_t _hb_socket;\n    zmq::socket_t _iopub_socket;\n    zmq::socket_t _control_socket;\n    zmq::socket_t _stdin_socket;\n    zmq::socket_t _shell_socket;\n\n    zmq::socket_t _engine_socket;\n\n    unsigned long _execution_count;\n\n    YacasEngine _engine;\n\n    bool _tex_output;\n    std::stringstream _side_effects;\n    CYacas _yacas;\n\n    std::map<unsigned long, std::shared_ptr<Request>> _execute_requests;\n\n    bool _shutdown;\n};\n\n#endif\n"
  },
  {
    "path": "cyacas/yacas-kernel/src/base64.cpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n#include \"base64.hpp\"\n\n#include <boost/archive/iterators/base64_from_binary.hpp>\n#include <boost/archive/iterators/insert_linebreaks.hpp>\n#include <boost/archive/iterators/transform_width.hpp>\n\nstd::string base64_encode(std::vector<unsigned char> data)\n{\n    using namespace boost::archive::iterators;\n\n    typedef insert_linebreaks< // insert line breaks every 72 characters\n        base64_from_binary<    // convert binary values ot base64 characters\n            transform_width< // retrieve 6 bit integers from a sequence of 8 bit\n                             // bytes\n                const char*,\n                6,\n                8>>,\n        72>\n        base64_text; // compose all the above operations in to a new iterator\n\n    int p = 0;\n    while (data.size() % 3) {\n        data.push_back(0);\n        p += 1;\n    }\n\n    std::string result(base64_text(&data.front()), base64_text(&data.front() + data.size() - p));\n\n    for (int i = 0; i < p; ++i)\n        result.push_back('=');\n\n    return result;\n}"
  },
  {
    "path": "cyacas/yacas-kernel/src/hmac_sha256.cpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n/*\n * File:   HMAC_SHA256.cpp\n * Author: mazur\n *\n * Created on November 4, 2015, 11:55 AM\n */\n\n#include \"hmac_sha256.hpp\"\n\n#include <openssl/opensslv.h>\n\nnamespace {\n    static const char hex_digit[] = {'0',\n                                     '1',\n                                     '2',\n                                     '3',\n                                     '4',\n                                     '5',\n                                     '6',\n                                     '7',\n                                     '8',\n                                     '9',\n                                     'a',\n                                     'b',\n                                     'c',\n                                     'd',\n                                     'e',\n                                     'f'};\n}\n\nHMAC_SHA256::HMAC_SHA256(const std::string& key):\n#if OPENSSL_VERSION_NUMBER < 0x10100000L\n    _ctx(new HMAC_CTX)\n#else\n    _ctx(HMAC_CTX_new())\n#endif\n{\n    HMAC_Init_ex(_ctx, key.c_str(), key.size(), EVP_sha256(), nullptr);\n}\n\nHMAC_SHA256::HMAC_SHA256(const std::string& key, const std::string& msg) :\n    HMAC_SHA256(key)\n{\n    update(msg);\n}\n\nHMAC_SHA256::HMAC_SHA256(const HMAC_SHA256& other):\n#if OPENSSL_VERSION_NUMBER < 0x10100000L\n    _ctx(new HMAC_CTX)\n#else\n    _ctx(HMAC_CTX_new())\n#endif\n{\n    HMAC_CTX_copy(_ctx, const_cast<HMAC_CTX*>(other._ctx));\n}\n\nHMAC_SHA256::~HMAC_SHA256()\n{\n#if OPENSSL_VERSION_NUMBER < 0x10100000L\n    HMAC_CTX_cleanup(_ctx);\n    delete _ctx;\n#else\n    HMAC_CTX_free(_ctx);\n#endif\n}\n\nvoid HMAC_SHA256::update(const std::string& msg)\n{\n    HMAC_Update(_ctx, (const unsigned char*)(msg.c_str()), msg.size());\n}\n\nstd::string HMAC_SHA256::hexdigest()\n{\n    const unsigned n = 32;\n\n    unsigned char result[n];\n    unsigned result_len = n;\n    HMAC_Final(_ctx, result, &result_len);\n\n    std::string s(2 * n, 0);\n    for (unsigned i = 0; i < n; ++i) {\n        s[2 * i] = hex_digit[result[i] / 16];\n        s[2 * i + 1] = hex_digit[result[i] % 16];\n    }\n\n    return s;\n}\n"
  },
  {
    "path": "cyacas/yacas-kernel/src/main.cpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n/*\n * File:   main.cpp\n * Author: mazur\n *\n * Created on November 8, 2015, 10:34 AM\n */\n\n#include \"yacas_kernel.hpp\"\n\n#include <json/json.h>\n\n#include <boost/dll/runtime_symbol_info.hpp>\n\n#include <iostream>\n\nint main(int argc, char** argv)\n{\n    using boost::filesystem::path;\n\n    if (argc < 2 || argc > 3) {\n        std::cerr << \"yacas_kernel: wrong number of arguments\\n\";\n        return 1;\n    }\n\n    Json::Value config;\n\n    {\n        std::ifstream config_file(argv[1]);\n        config_file >> config;\n    }\n\n    std::string scripts_path =\n        (boost::dll::program_location().parent_path().parent_path() /\n         \"share/yacas/scripts\").string();\n\n    if (argc == 3) {\n        scripts_path = argv[2];\n        if (scripts_path.front() == '\"')\n            scripts_path.erase(0, 1);\n        if (scripts_path.back() == '\"')\n            scripts_path.pop_back();\n    }\n\n    if (scripts_path.back() != '/')\n        scripts_path.push_back('/');\n\n    YacasKernel kernel(scripts_path, config);\n\n    kernel.run();\n}\n"
  },
  {
    "path": "cyacas/yacas-kernel/src/yacas_engine.cpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n/*\n * File:   yacas_engine.cpp\n * Author: mazur\n *\n * Created on November 7, 2015, 12:52 PM\n */\n\n#include \"yacas_engine.hpp\"\n\n#include <json/writer.h>\n#include <zmq_addon.hpp>\n\nYacasEngine::YacasEngine(const std::string& scripts_path,\n                         zmq::context_t& ctx,\n                         const std::string& endpoint) :\n    _yacas(_side_effects),\n    _socket(ctx, zmq::socket_type::pair),\n    _shutdown(false)\n{\n    _yacas.Evaluate(std::string(\"DefaultDirectory(\\\"\") + scripts_path +\n                    std::string(\"\\\");\"));\n    _yacas.Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n    _yacas.Evaluate(\"Plot2D'outputs();\");\n    _yacas.Evaluate(\"UnProtect(Plot2D'outputs);\");\n    _yacas.Evaluate(\"Plot2D'outputs() := {{\\\"default\\\", \\\"png\\\"}, {\\\"png\\\", \\\"Plot2D'png\\\"}}\");\n    _yacas.Evaluate(\"Protect(Plot2D'outputs);\");\n    _yacas.Evaluate(\"Plot3DS'outputs();\");\n    _yacas.Evaluate(\"UnProtect(Plot3DS'outputs);\");\n    _yacas.Evaluate(\"Plot3DS'outputs() := {{\\\"default\\\", \\\"png\\\"}, {\\\"png\\\", \\\"Plot3DS'png\\\"}}\");\n    _yacas.Evaluate(\"Protect(Plot3DS'outputs);\");\n\n    _socket.connect(endpoint);\n\n    _worker_thread = new std::thread(std::bind(&YacasEngine::_worker, this));\n}\n\nYacasEngine::~YacasEngine()\n{\n    _shutdown = true;\n    _yacas.getDefEnv().getEnv().stop_evaluation = true;\n    _cv.notify_all();\n    _worker_thread->join();\n\n    delete _worker_thread;\n}\n\nvoid YacasEngine::submit(unsigned long id, const std::string& expr)\n{\n    const TaskInfo ti = {id, expr};\n\n    std::lock_guard<std::mutex> lock(_mtx);\n    _tasks.push_back(ti);\n    _cv.notify_all();\n}\n\nvoid YacasEngine::_worker()\n{\n    for (;;) {\n        TaskInfo ti;\n\n        {\n            std::unique_lock<std::mutex> lock(_mtx);\n\n            while (_tasks.empty() && !_shutdown)\n                _cv.wait(lock);\n\n            if (_shutdown)\n                return;\n\n            ti = _tasks.front();\n            _tasks.pop_front();\n        }\n\n        Json::Value calculate_content;\n        calculate_content[\"id\"] = Json::Value::UInt64(ti.id);\n        calculate_content[\"expr\"] = ti.expr;\n        zmq::multipart_t status_msg;\n        status_msg.addstr(\"calculate\");\n        status_msg.addstr(Json::writeString(Json::StreamWriterBuilder(),\n                                        calculate_content));\n        status_msg.send(_socket);\n\n        _side_effects.clear();\n        _side_effects.str(\"\");\n\n        _yacas.Evaluate((ti.expr + \";\"));\n\n        Json::Value result_content;\n        result_content[\"id\"] = Json::Value::UInt64(ti.id);\n\n        if (_yacas.IsError())\n            result_content[\"error\"] = _yacas.Error();\n        else\n            result_content[\"result\"] = _yacas.Result();\n\n        result_content[\"side_effects\"] = _side_effects.str();\n\n        zmq::multipart_t result_msg;\n        result_msg.addstr(\"result\");\n        result_msg.addstr(Json::writeString(Json::StreamWriterBuilder(),\n                                        result_content));\n        result_msg.send(_socket);\n    }\n}\n"
  },
  {
    "path": "cyacas/yacas-kernel/src/yacas_kernel.cpp",
    "content": "/*\n * This file is part of yacas.\n * Yacas is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Lesset General Public License as\n * published by the Free Software Foundation, either version 2.1\n * of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with yacas. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n/*\n * File:   yacas_kernel.cpp\n * Author: mazur\n *\n * Created on November 6, 2015, 3:10 PM\n */\n\n#include \"yacas_kernel.hpp\"\n#include \"base64.hpp\"\n\n#include \"yacas/yacas_version.h\"\n\n#include <boost/date_time/posix_time/posix_time.hpp>\n#include <boost/uuid/uuid_io.hpp>\n\n#include <regex>\n#include <set>\n#include <string>\n\nnamespace {\n    std::string now()\n    {\n        using namespace boost::posix_time;\n\n        return to_iso_extended_string(microsec_clock::local_time());\n    }\n}\n\nYacasKernel::YacasKernel(const std::string& scripts_path,\n                         const Json::Value& config) :\n    _session(config[\"key\"].asString()),\n    _hb_socket(_ctx, zmq::socket_type::rep),\n    _iopub_socket(_ctx, zmq::socket_type::pub),\n    _control_socket(_ctx, zmq::socket_type::router),\n    _stdin_socket(_ctx, zmq::socket_type::router),\n    _shell_socket(_ctx, zmq::socket_type::router),\n    _engine_socket(_ctx, zmq::socket_type::pair),\n    _execution_count(1),\n    _engine(scripts_path, _ctx, \"inproc://engine\"),\n    _tex_output(true),\n    _yacas(_side_effects),\n    _shutdown(false)\n{\n    const std::string transport = config[\"transport\"].asString();\n    const std::string ip = config[\"ip\"].asString();\n\n    _hb_socket.bind(transport + \"://\" + ip + \":\" +\n                    config[\"hb_port\"].asString());\n    _iopub_socket.bind(transport + \"://\" + ip + \":\" +\n                       config[\"iopub_port\"].asString());\n    _control_socket.bind(transport + \"://\" + ip + \":\" +\n                         config[\"control_port\"].asString());\n    _stdin_socket.bind(transport + \"://\" + ip + \":\" +\n                       config[\"stdin_port\"].asString());\n    _shell_socket.bind(transport + \"://\" + ip + \":\" +\n                       config[\"shell_port\"].asString());\n    _engine_socket.bind(\"inproc://engine\");\n\n    _yacas.Evaluate(std::string(\"DefaultDirectory(\\\"\") + scripts_path +\n                    std::string(\"\\\");\"));\n    _yacas.Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n}\n\nvoid YacasKernel::run()\n{\n    std::vector<zmq::pollitem_t> items{\n        {_hb_socket, 0, ZMQ_POLLIN, 0},\n        {_control_socket, 0, ZMQ_POLLIN, 0},\n        {_stdin_socket, 0, ZMQ_POLLIN, 0},\n        {_shell_socket, 0, ZMQ_POLLIN, 0},\n        {_iopub_socket, 0, ZMQ_POLLIN, 0},\n        {_engine_socket, 0, ZMQ_POLLIN, 0}\n    };\n\n    for (;;) {\n        zmq::poll(items);\n\n        if (items[0].revents & ZMQ_POLLIN) { // heartbeat\n            zmq::message_t msg;\n            while (!_hb_socket.recv(msg))\n                ;\n            _hb_socket.send(msg, zmq::send_flags::none);\n        }\n\n        if (items[3].revents & ZMQ_POLLIN) { // shell\n            zmq::multipart_t msg;\n            msg.recv(_shell_socket);\n            _handle_shell(std::make_shared<Request>(_session, msg));\n        }\n\n        if (items[1].revents & ZMQ_POLLIN) { // control\n            zmq::multipart_t msg;\n            msg.recv(_control_socket);\n            Request request(_session, msg);\n\n            if (request.header()[\"msg_type\"].asString() == \"shutdown_request\")\n                _shutdown = true;\n        }\n\n        if (_shutdown)\n            return;\n\n        if (items[2].revents & ZMQ_POLLIN) { // stdin\n            zmq::message_t msg;\n            while (!_stdin_socket.recv(msg))\n                ;\n        }\n\n        if (items[5].revents & ZMQ_POLLIN) { // engine\n            zmq::multipart_t msg;\n            msg.recv(_engine_socket);\n            _handle_engine(msg);\n        }\n    }\n}\n\nYacasKernel::Session::Session(const std::string& key) :\n    _auth(key),\n    _uuid(_uuid_gen())\n{\n}\n\nYacasKernel::Request::Request(const Session& session,\n                              const zmq::multipart_t& msg) :\n    _session(session)\n{\n    const std::string header_buf{msg.peekstr(3)};\n    const std::string parent_header_buf{msg.peekstr(4)};\n    const std::string metadata_buf{msg.peekstr(5)};\n    const std::string content_buf{msg.peekstr(6)};\n\n    HMAC_SHA256 auth(_session.auth());\n\n    auth.update(header_buf);\n    auth.update(parent_header_buf);\n    auth.update(metadata_buf);\n    auth.update(content_buf);\n\n    std::string signature_buf{msg.peekstr(2)};\n\n    if (auth.hexdigest() != signature_buf)\n        throw std::runtime_error(\"invalid signature\");\n\n    _identities_buf = msg.peekstr(0);\n\n    std::istringstream{header_buf} >> _header;\n    std::istringstream{content_buf} >> _content;\n    std::istringstream{metadata_buf} >> _metadata;\n}\n\nvoid YacasKernel::Request::reply(zmq::socket_t& socket,\n                                 const std::string& msg_type,\n                                 const Json::Value& content) const\n{\n    Json::Value header;\n    header[\"username\"] = \"kernel\";\n    header[\"version\"] = \"5.0\";\n    header[\"session\"] = boost::uuids::to_string(_session.uuid());\n    header[\"date\"] = now();\n    header[\"msg_id\"] = boost::uuids::to_string(_session.generate_msg_uuid());\n    header[\"msg_type\"] = msg_type;\n\n    Json::StreamWriterBuilder builder;\n\n    const std::string content_buf = Json::writeString(builder, content);\n    // FIXME:\n    const std::string metadata_buf = \"{}\";\n    const std::string header_buf = Json::writeString(builder, header);\n    const std::string parent_header_buf = Json::writeString(builder, _header);\n\n    HMAC_SHA256 auth(_session.auth());\n\n    auth.update(header_buf);\n    auth.update(parent_header_buf);\n    auth.update(metadata_buf);\n    auth.update(content_buf);\n\n    zmq::multipart_t msg;\n\n    msg.addstr(_identities_buf);\n    msg.addstr(\"<IDS|MSG>\");\n    msg.addstr(auth.hexdigest());\n    msg.addstr(header_buf);\n    msg.addstr(parent_header_buf);\n    msg.addstr(metadata_buf);\n    msg.addstr(content_buf);\n\n    msg.send(socket);\n}\n\nvoid YacasKernel::_handle_shell(const std::shared_ptr<Request>& request)\n{\n    const std::string msg_type = request->header()[\"msg_type\"].asString();\n\n    if (msg_type == \"kernel_info_request\") {\n        Json::Value codemirror_mode;\n        codemirror_mode[\"name\"] = \"yacas\";\n\n        Json::Value language_info;\n        language_info[\"name\"] = \"yacas\";\n        language_info[\"version\"] = YACAS_VERSION;\n        language_info[\"mimetype\"] = \"text/x-yacas\";\n        language_info[\"file_extension\"] = \".ys\";\n        language_info[\"codemirror_mode\"] = codemirror_mode;\n\n        Json::Value homepage;\n        homepage[\"text\"] = \"Yacas Homepage\";\n        homepage[\"url\"] = \"http://www.yacas.org\";\n\n        Json::Value docs;\n        docs[\"text\"] = \"Yacas Documentation\";\n        docs[\"url\"] = \"http://yacas.readthedocs.org\";\n\n        Json::Value help_links;\n        help_links.append(homepage);\n        help_links.append(docs);\n\n        Json::Value reply_content;\n        reply_content[\"status\"] = \"ok\";\n        reply_content[\"protocol_version\"] = \"5.2\";\n        reply_content[\"implementation\"] = \"yacas_kernel\";\n        reply_content[\"implementation_version\"] = \"0.2\";\n        reply_content[\"language_info\"] = language_info;\n        reply_content[\"banner\"] = \"yacas_kernel \" YACAS_VERSION;\n        reply_content[\"help_links\"] = help_links;\n\n        request->reply(_shell_socket, \"kernel_info_reply\", reply_content);\n\n        Json::Value status_content;\n        status_content[\"execution_state\"] = \"idle\";\n        request->reply(_iopub_socket, \"status\", status_content);\n    } else if (msg_type == \"execute_request\") {\n\n        _execute_requests.insert(\n            std::make_pair(_execution_count, std::move(request)));\n        _engine.submit(_execution_count, request->content()[\"code\"].asString());\n\n        _execution_count += 1;\n    } else if (msg_type == \"complete_request\") {\n        std::string code = request->content()[\"code\"].asString();\n        int cursor = request->content()[\"cursor_pos\"].asInt();\n        int start = cursor;\n        while (start > 0 && std::isalpha(code[start - 1]))\n            start -= 1;\n        const std::string prefix = code.substr(start, cursor - start);\n\n        std::set<std::string> matches;\n\n        for (auto op : _yacas.getDefEnv().getEnv().PreFix())\n            if (op.first->compare(0, prefix.length(), prefix) == 0)\n                matches.insert(*op.first);\n\n        for (auto op : _yacas.getDefEnv().getEnv().InFix())\n            if (op.first->compare(0, prefix.length(), prefix) == 0)\n                matches.insert(*op.first);\n\n        for (auto op : _yacas.getDefEnv().getEnv().PostFix())\n            if (op.first->compare(0, prefix.length(), prefix) == 0)\n                matches.insert(*op.first);\n\n        for (auto op : _yacas.getDefEnv().getEnv().Bodied())\n            if (op.first->compare(0, prefix.length(), prefix) == 0)\n                matches.insert(*op.first);\n\n        for (auto op : _yacas.getDefEnv().getEnv().CoreCommands())\n            if (op.first->compare(0, prefix.length(), prefix) == 0)\n                matches.insert(*op.first);\n\n        for (auto op : _yacas.getDefEnv().getEnv().UserFunctions())\n            if (op.first->compare(0, prefix.length(), prefix) == 0)\n                matches.insert(*op.first);\n\n        Json::Value reply_content_matches;\n        for (const std::string& match : matches)\n            reply_content_matches.append(match);\n\n        Json::Value reply_content;\n        reply_content[\"status\"] = \"ok\";\n        reply_content[\"cursor_start\"] = start;\n        reply_content[\"cursor_end\"] = cursor;\n        reply_content[\"matches\"] = reply_content_matches;\n\n        request->reply(_shell_socket, \"complete_reply\", reply_content);\n\n    } else if (msg_type == \"shutdown_request\") {\n\n        _shutdown = true;\n\n        Json::Value reply_content;\n        reply_content[\"status\"] = \"ok\";\n\n        request->reply(_shell_socket, \"shutdown_reply\", reply_content);\n    }\n}\n\nvoid YacasKernel::_handle_engine(const zmq::multipart_t& msg)\n{\n    const std::string msg_type{msg.peekstr(0)};\n    const std::string content_buf{msg.peekstr(1)};\n\n    Json::Value content;\n    std::istringstream{content_buf} >> content;\n\n    std::shared_ptr<YacasKernel::Request> request =\n        _execute_requests[content[\"id\"].asUInt64()];\n\n    bool condemned = false;\n\n    if (msg_type == \"calculate\") {\n        Json::Value status_content;\n        status_content[\"execution_state\"] = \"busy\";\n\n        request->reply(_iopub_socket, \"status\", status_content);\n\n        Json::Value execute_input_content;\n        execute_input_content[\"execution_count\"] = content[\"id\"];\n        execute_input_content[\"code\"] = content[\"expr\"];\n\n        request->reply(_iopub_socket, \"execute_input\", execute_input_content);\n    } else if (msg_type == \"result\") {\n\n        if (content.isMember(\"side_effects\")) {\n            Json::Value stream_content;\n            stream_content[\"name\"] = \"stdout\";\n            stream_content[\"text\"] = content[\"side_effects\"];\n\n            request->reply(_iopub_socket, \"stream\", stream_content);\n        }\n\n        if (content.isMember(\"error\")) {\n            Json::Value reply_content;\n            reply_content[\"status\"] = \"error\";\n            reply_content[\"execution_count\"] = content[\"id\"];\n            reply_content[\"ename\"] = \"\";\n            reply_content[\"evalue\"] = \"\";\n            reply_content[\"traceback\"].append(content[\"error\"]);\n\n            request->reply(_shell_socket, \"execute_reply\", reply_content);\n\n            Json::Value error_content;\n            error_content[\"execution_count\"] = content[\"id\"];\n            error_content[\"ename\"] = \"\";\n            error_content[\"evalue\"] = \"\";\n            error_content[\"traceback\"].append(content[\"error\"]);\n\n            request->reply(_iopub_socket, \"error\", error_content);\n        } else {\n            std::string text_result = content[\"result\"].asString();\n            if (text_result.back() == ';')\n                text_result.pop_back();\n\n            Json::Value content_data;\n            content_data[\"text/plain\"] = text_result;\n\n            std::regex rx(\"File\\\\(\\\"([^\\\"]+)\\\", *\\\"([^\\\"]+)\\\"\\\\)\",\n                          std::regex_constants::ECMAScript);\n            std::smatch m;\n            if (std::regex_match(text_result, m, rx)) {\n                std::ifstream f(m[1],\n                                std::ios_base::in | std::ios_base::binary);\n                const std::vector<unsigned char> img(\n                    (std::istreambuf_iterator<char>(f)),\n                    std::istreambuf_iterator<char>());\n                content_data[m[2]] = base64_encode(img);\n            } else {\n                if (_tex_output) {\n                    _side_effects.clear();\n                    _side_effects.str(\"\");\n\n                    _yacas.Evaluate(std::string(\"TeXForm(Hold(\") + text_result +\n                                    \"));\");\n\n                    std::string tex_result = _yacas.Result();\n                    tex_result = tex_result.substr(1, tex_result.size() - 3);\n\n                    content_data[\"text/latex\"] = tex_result;\n                }\n            }\n\n            Json::Value reply_content;\n            reply_content[\"status\"] = \"ok\";\n            reply_content[\"execution_count\"] = content[\"id\"];\n            reply_content[\"data\"] = content_data;\n\n            request->reply(_shell_socket, \"execute_result\", reply_content);\n\n            Json::Value result_content;\n            result_content[\"execution_count\"] = content[\"id\"];\n            result_content[\"data\"] = content_data;\n            result_content[\"metadata\"] = \"{}\";\n\n            request->reply(_iopub_socket, \"execute_result\", result_content);\n\n            condemned = true;\n        }\n\n        Json::Value status_content;\n        status_content[\"execution_state\"] = \"idle\";\n\n        request->reply(_iopub_socket, \"status\", status_content);\n\n        if (condemned)\n            _execute_requests.erase(content[\"id\"].asUInt64());\n    }\n}\n"
  },
  {
    "path": "docs/CMakeLists.txt",
    "content": "find_package(Sphinx REQUIRED)\n\nif(NOT DEFINED SPHINX_THEME)\n    set(SPHINX_THEME default)\nendif()\n\nif(NOT DEFINED SPHINX_THEME_DIR)\n    set(SPHINX_THEME_DIR)\nendif()\n\n# configured documentation tools and intermediate build results\nset(BINARY_BUILD_DIR \"${CMAKE_CURRENT_BINARY_DIR}/_build\")\n\n# Sphinx cache with pickled ReST documents\nset(SPHINX_CACHE_DIR \"${CMAKE_CURRENT_BINARY_DIR}/_doctrees\")\n\n# HTML output directory\nset(SPHINX_HTML_DIR \"${CMAKE_CURRENT_BINARY_DIR}/html\")\nset(SPHINX_SINGLEHTML_DIR \"${CMAKE_CURRENT_BINARY_DIR}/singlehtml\")\n\nfile (\n    COPY\n      util\n      favicon.ico\n      yacaslogo.png\n      yacaslogo_w250px.png\n      conf.py\n    DESTINATION\n      \"${BINARY_BUILD_DIR}\")\n\nadd_custom_target(yacas_docs ALL\n    ${SPHINX_EXECUTABLE}\n        -q -b singlehtml\n        -c \"${BINARY_BUILD_DIR}\"\n        -d \"${SPHINX_CACHE_DIR}\"\n        \"${CMAKE_CURRENT_SOURCE_DIR}\"\n        \"${SPHINX_SINGLEHTML_DIR}\"\n    COMMENT \"Building HTML documentation with Sphinx\")\n\ninstall (DIRECTORY \"${SPHINX_SINGLEHTML_DIR}\"\n         DESTINATION ${CMAKE_INSTALL_DOCDIR}\n         COMPONENT doc\n         PATTERN \".buildinfo\" EXCLUDE)\n"
  },
  {
    "path": "docs/Makefile",
    "content": "# Makefile for Sphinx documentation\n#\n\n# You can set these variables from the command line.\nSPHINXOPTS    =\nSPHINXBUILD   = sphinx-build\nPAPER         =\nBUILDDIR      = _build\n\n# User-friendly check for sphinx-build\nifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)\n$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)\nendif\n\n# Internal variables.\nPAPEROPT_a4     = -D latex_paper_size=a4\nPAPEROPT_letter = -D latex_paper_size=letter\nALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .\n# the i18n builder cannot share the environment and doctrees with the others\nI18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .\n\n.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext\n\nhelp:\n\t@echo \"Please use \\`make <target>' where <target> is one of\"\n\t@echo \"  html       to make standalone HTML files\"\n\t@echo \"  dirhtml    to make HTML files named index.html in directories\"\n\t@echo \"  singlehtml to make a single large HTML file\"\n\t@echo \"  pickle     to make pickle files\"\n\t@echo \"  json       to make JSON files\"\n\t@echo \"  htmlhelp   to make HTML files and a HTML help project\"\n\t@echo \"  qthelp     to make HTML files and a qthelp project\"\n\t@echo \"  devhelp    to make HTML files and a Devhelp project\"\n\t@echo \"  epub       to make an epub\"\n\t@echo \"  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter\"\n\t@echo \"  latexpdf   to make LaTeX files and run them through pdflatex\"\n\t@echo \"  latexpdfja to make LaTeX files and run them through platex/dvipdfmx\"\n\t@echo \"  text       to make text files\"\n\t@echo \"  man        to make manual pages\"\n\t@echo \"  texinfo    to make Texinfo files\"\n\t@echo \"  info       to make Texinfo files and run them through makeinfo\"\n\t@echo \"  gettext    to make PO message catalogs\"\n\t@echo \"  changes    to make an overview of all changed/added/deprecated items\"\n\t@echo \"  xml        to make Docutils-native XML files\"\n\t@echo \"  pseudoxml  to make pseudoxml-XML files for display purposes\"\n\t@echo \"  linkcheck  to check all external links for integrity\"\n\t@echo \"  doctest    to run all doctests embedded in the documentation (if enabled)\"\n\nclean:\n\trm -rf $(BUILDDIR)/*\n\nhtml:\n\t$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html\n\t@echo\n\t@echo \"Build finished. The HTML pages are in $(BUILDDIR)/html.\"\n\ndirhtml:\n\t$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml\n\t@echo\n\t@echo \"Build finished. The HTML pages are in $(BUILDDIR)/dirhtml.\"\n\nsinglehtml:\n\t$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml\n\t@echo\n\t@echo \"Build finished. The HTML page is in $(BUILDDIR)/singlehtml.\"\n\npickle:\n\t$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle\n\t@echo\n\t@echo \"Build finished; now you can process the pickle files.\"\n\njson:\n\t$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json\n\t@echo\n\t@echo \"Build finished; now you can process the JSON files.\"\n\nhtmlhelp:\n\t$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp\n\t@echo\n\t@echo \"Build finished; now you can run HTML Help Workshop with the\" \\\n\t      \".hhp project file in $(BUILDDIR)/htmlhelp.\"\n\nqthelp:\n\t$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp\n\t@echo\n\t@echo \"Build finished; now you can run \"qcollectiongenerator\" with the\" \\\n\t      \".qhcp project file in $(BUILDDIR)/qthelp, like this:\"\n\t@echo \"# qcollectiongenerator $(BUILDDIR)/qthelp/yacas.qhcp\"\n\t@echo \"To view the help file:\"\n\t@echo \"# assistant -collectionFile $(BUILDDIR)/qthelp/yacas.qhc\"\n\ndevhelp:\n\t$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp\n\t@echo\n\t@echo \"Build finished.\"\n\t@echo \"To view the help file:\"\n\t@echo \"# mkdir -p $$HOME/.local/share/devhelp/yacas\"\n\t@echo \"# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/yacas\"\n\t@echo \"# devhelp\"\n\nepub:\n\t$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub\n\t@echo\n\t@echo \"Build finished. The epub file is in $(BUILDDIR)/epub.\"\n\nlatex:\n\t$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex\n\t@echo\n\t@echo \"Build finished; the LaTeX files are in $(BUILDDIR)/latex.\"\n\t@echo \"Run \\`make' in that directory to run these through (pdf)latex\" \\\n\t      \"(use \\`make latexpdf' here to do that automatically).\"\n\nlatexpdf:\n\t$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex\n\t@echo \"Running LaTeX files through pdflatex...\"\n\t$(MAKE) -C $(BUILDDIR)/latex all-pdf\n\t@echo \"pdflatex finished; the PDF files are in $(BUILDDIR)/latex.\"\n\nlatexpdfja:\n\t$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex\n\t@echo \"Running LaTeX files through platex and dvipdfmx...\"\n\t$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja\n\t@echo \"pdflatex finished; the PDF files are in $(BUILDDIR)/latex.\"\n\ntext:\n\t$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text\n\t@echo\n\t@echo \"Build finished. The text files are in $(BUILDDIR)/text.\"\n\nman:\n\t$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man\n\t@echo\n\t@echo \"Build finished. The manual pages are in $(BUILDDIR)/man.\"\n\ntexinfo:\n\t$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo\n\t@echo\n\t@echo \"Build finished. The Texinfo files are in $(BUILDDIR)/texinfo.\"\n\t@echo \"Run \\`make' in that directory to run these through makeinfo\" \\\n\t      \"(use \\`make info' here to do that automatically).\"\n\ninfo:\n\t$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo\n\t@echo \"Running Texinfo files through makeinfo...\"\n\tmake -C $(BUILDDIR)/texinfo info\n\t@echo \"makeinfo finished; the Info files are in $(BUILDDIR)/texinfo.\"\n\ngettext:\n\t$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale\n\t@echo\n\t@echo \"Build finished. The message catalogs are in $(BUILDDIR)/locale.\"\n\nchanges:\n\t$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes\n\t@echo\n\t@echo \"The overview file is in $(BUILDDIR)/changes.\"\n\nlinkcheck:\n\t$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck\n\t@echo\n\t@echo \"Link check complete; look for any errors in the above output \" \\\n\t      \"or in $(BUILDDIR)/linkcheck/output.txt.\"\n\ndoctest:\n\t$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest\n\t@echo \"Testing of doctests in the sources finished, look at the \" \\\n\t      \"results in $(BUILDDIR)/doctest/output.txt.\"\n\nxml:\n\t$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml\n\t@echo\n\t@echo \"Build finished. The XML files are in $(BUILDDIR)/xml.\"\n\npseudoxml:\n\t$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml\n\t@echo\n\t@echo \"Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml.\"\n"
  },
  {
    "path": "docs/book_of_algorithms/basic.rst",
    "content": "==========================\nAdaptive function plotting\n==========================\n\nHere we consider plotting of functions :math:`y=f(x)`.\n\nThere are two tasks related to preparation of plots of functions:\nfirst, to produce the numbers required for a plot, and second, to draw\na plot with axes, symbols, a legend, perhaps additional illustrations\nand so on.  Here we only concern ourselves with the first task, that\nof preparation of the numerical data for a plot.  There are many\nplotting programs that can read a file with numbers and plot it in any\ndesired manner.\n\nGenerating data for plots of functions generally does not require\nhigh-precision calculations.  However, we need an algorithm that can\nbe adjusted to produce data to different levels of precision.  In some\nparticularly ill-behaved cases, a precise plot will not be possible\nand we would not want to waste time producing data that is too\naccurate for what it is worth.\n\nA simple approach to plotting would be to divide the interval into\nmany equal subintervals and to evaluate the function on the resulting\ngrid.  Precision of the plot can be adjusted by choosing a larger or a\nsmaller number of points.\n\nHowever, this approach is not optimal. Sometimes a function changes\nrapidly near one point but slowly everywhere else.  For example,\n:math:`f(x)=\\frac{1}{x}` changes very quickly at small :math:`x`.\nSuppose we need to plot this function between :math:`0` and\n:math:`100`.  It would be wasteful to use the same subdivision\ninterval everywhere: a finer grid is only required over a small\nportion of the plotting range near :math:`x=0`.\n\nThe adaptive plotting routine :func:`Plot2D'adaptive` uses a simple\nalgorithm to select the optimal grid to approximate a function of one\nargument :math:`f(x)`.  The algorithm repeatedly subdivides the grid\nintervals near points where the existing grid does not represent the\nfunction well enough.  A similar algorithm for adaptive grid\nrefinement could be used for numerical integration. The idea is that\nplotting and numerical integration require the same kind of detailed\nknowledge about the behavior of the function.\n\nThe algorithm first splits the interval into a specified initial\nnumber of equal subintervals, and then repeatedly splits each\nsubinterval in half until the function is well enough approximated by\nthe resulting grid. The integer parameter {depth} gives the maximum\nnumber of binary splittings for a given initial interval; thus, at\nmost :math:`2^{depth}` additional grid points will be generated. The\nfunction :func:`Plot2D'adaptive` should return a list of pairs of points\n``{{{x1,y1}, {x2,y2}, ...}}`` to be used directly for plotting.\n\nThe adaptive plotting algorithm works like this:\n\n1. Given an interval (:math:`a`, :math:`c`), we split it in half,\n   :math:`b:=(a+c)/2` and first compute :math:`f(x)` at five grid\n   points :math:`a`, :math:`a_1:=(a+b)/2`, :math:`b`,\n   :math:`b_1:=(b+c)/2`, :math:`c`.\n2. If currently :math:`depth <= 0`, return this list of five points and\n   values because we cannot refine the grid any more.\n3. Otherwise, check that the function does not oscillate too rapidly\n   on the interval :math:`[a, c]`.  The formal criterion is that the\n   five values are all finite and do not make a \"zigzag\" pattern such\n   as :math:`(1,3,2,3,1)`.  More formally, we use the following\n   procedure: For each three consecutive values, write \"1\" if the\n   middle value is larger than the other two, or if it is smaller than\n   the other two, or if one of them is not a number (e.g. ``Infinity``\n   or ``Undefined}``.  If we have at most two ones now, then we\n   consider the change of values to be \"slow enough\". Otherwise it is\n   not \"slow enough\".  In this case we need to refine the grid; go to\n   step 5.  Otherwise, go to step 4.\n4. Check that the function values are smooth enough through the\n   interval. Smoothness is controlled by a parameter\n   :math:`\\epsilon`. The meaning of the parameter :math:`\\epsilon` is\n   the (relative) error of the numerical approximation of the integral\n   of :math:`f(x)` by the grid. A good heuristic value of\n   :math:`\\epsilon` is 1/(the number of pixels on the screen) because\n   it means that no pixels will be missing in the area under the\n   graph. For this to work we need to make sure that we are actually\n   computing the area *under* the graph; so we define\n   :math:`g(x):=f(x)-f[0]` where :math:`f[0]` is the minimum of the\n   values of :math:`f(x)` on the five grid points :math:`a`,\n   :math:`a_1`, :math:`b`, :math:`b_1`, and :math:`c`; the function\n   :math:`g(x)` is nonnegative and has the minimum value 0.  Then we\n   compute two different Newton-Cotes quadratures for\n   :math:`\\int_b^{b_1}g(x)\\,\\mathrm{d}x` using these five\n   points. (Asymmetric quadratures are chosen to avoid running into an\n   accidental symmetry of the function; the first quadrature uses\n   points :math:`a`, :math:`a_1`, :math:`b`, :math:`b_1` and the\n   second quadrature uses :math:`b`, :math:`b_1`, :math:`c`.) If the\n   absolute value of the difference between these quadratures is less\n   than :math:`epsilon` times the value of the second quadrature, then we\n   are done and we return the list of these five points and values.\n5. Otherwise, we need to refine the grid. We compute\n   :func:`Plot2D'adaptive` recursively for the two halves of the\n   interval, that is, for :math:`[a, b]` and :math:`[b, c]`.  We also\n   decrease :math:`depth` by 1 and multiply :math:`\\epsilon` by 2 because we\n   need to maintain a constant *absolute* precision and this means\n   that the relative error for the two subintervals can be twice as\n   large.  The resulting two lists for the two subintervals are\n   concatenated (excluding the double value at point :math:`b`) and\n   returned.\n\nThis algorithm works well if the initial number of points and the\n:math:`depth` parameter are large enough.  These parameters can be\nadjusted to balance the available computing time and the desired level\nof detail in the resulting plot.\n\nSingularities in the function are handled by the step 3.  Namely, the\nchange in the sequence :math:`a`, :math:`a_1`, :math:`b`, :math:`b_1`,\n:math:`c` is always considered to be \"too rapid\" if one of these\nvalues is a non-number (e.g. ``Infinity`` or ``Undefined``). Thus,\nthe interval immediately adjacent to a singularity will be plotted at\nthe highest allowed refinement level. When preparing the plotting\ndata, the singular points are simply not printed to the data file, so\nthat a plotting programs does not encounter any problems.\n\nNewton-Cotes quadratures\n------------------------\n\nThe meaning of Newton-Cotes quadrature coefficients is that an\nintegral of a function :math:`f(x)` is approximated by a sum\n\n.. math:: \\int_{a_0}^{a_n}f(x)\\,\\mathrm{d}x\\approx h\\sum_{k=0}^nc_kf(a_k)\n\nwhere :math:`a_k` are the grid points, :math:`h:=a_1-a_0` is the grid\nstep, and :math:`c_k` are the quadrature coefficients.  It may seem\nsurprising, but these coefficients :math:`c_k` are independent of the\nfunction :math:`f(x)` and can be precomputed in advance for a given\ngrid :math:`a_k`.  [The quadrature coefficients do depend on the\nrelative separations of the grid.  Here we assume a uniform grid with\na constant step :math:`h=a_k-a_{k-1}`.  Quadrature coefficients can\nalso be found for non-uniform grids.]\n\nThe coefficients :math:`c_k` for grids with a constant step :math:`h`\ncan be found, for example, by solving the following system of\nequations,\n\n.. math::\n   \\sum_{k=0}^nc_kk^p=\\frac{n^{p+1}}{p+1}\n\nfor :math:`p=0,1,\\ldots,n`. This system of equations means that the\nquadrature correctly gives the integrals of :math:`p+1` functions\n:math:`f(x)=x^p`, :math:`p=0,1,\\ldots,n` over the interval\n:math:`(0,n)`.  The solution of this system always exists and gives\nquadrature coefficients as rational numbers. For example, the\nwell-known Simpson quadrature :math:`c_0=1/3,c_1=4/3,c_2=1/3` is\nobtained with :math:`n=2`.  An example of using this quadrature is the\napproximation\n\n.. math::\n   \\int_0^2f(x)\\,\\mathrm{d}x\\approx(f(0)+f(2))/3+4/3*f(1)\n\n\nNewton-Cotes quadratures for partial intervals\n----------------------------------------------\n\nIn the same way it is possible to find quadratures for the integral\nover a subinterval rather than over the whole interval of\n:math:`x`. In the current implementation of the adaptive plotting\nalgorithm, two quadratures are used: the 3-point quadrature\n(:math:`n=2`) and the 4-point quadrature (:math:`n=3`) for the\nintegral over the first subinterval,\n:math:`\\int_{a_0}^{a_1}(x,a[0],a[1])f(x)\\,\\mathrm{d}x`. Their\ncoefficients are\n:math:`\\left(\\frac{5}{12},\\frac{2}{3},-\\frac{1}{12}\\right)` and\n:math:`\\left(\\frac{3}{8},\\frac{19}{24},-\\frac{5}{24},\\frac{1}{24}\\right)`.\nAn example of using the first of these subinterval quadratures would\nbe the approximation\n\n.. math::\n   \\int_0^2f(x)\\,\\mathrm{d}x\\approx \\frac{5}{12}f(0)+\\frac{2}{3}f(1)-\\frac{1}{12}f(2).\n\nThese quadratures are intentionally chosen to be asymmetric to avoid\nan accidental cancellation when the function :math:`f(x)` itself is\nsymmetric.  (Otherwise the error estimate could accidentally become\nexactly zero.)\n\n================\nSurface plotting\n================\n\nHere we consider plotting of functions :math:`z=f(x,y)`.\n\nThe task of surface plotting is to obtain a picture of a\ntwo-dimensional surface as if it were a solid object in three\ndimensions.  A graphical representation of a surface is a complicated\ntask.  Sometimes it is required to use particular coordinates or\nprojections, to colorize the surface, to remove hidden lines and so\non.  We shall only be concerned with the task of obtaining the data\nfor a plot from a given function of two variables :math:`f(x,y)`.\nSpecialized programs can take a text file with the data and let the\nuser interactively produce a variety of surface plots.\n\nThe currently implemented algorithm in the function :func:`Plot3DS` is\nvery similar to the adaptive plotting algorithm for two-dimensional\nplots.  A given rectangular plotting region :math:`a_1\\leq x\\leq a_2`,\n:math:`b_1\\leq y\\leq b_2` is subdivided to produce an equally spaced\nrectangular grid of points.  This is the initial grid which will be\nadaptively refined where necessary.  The refinement algorithm will\ndivide a given rectangle in four quarters if the available function\nvalues indicate that the function does not change smoothly enough on\nthat rectangle.\n\nThe criterion of a \"smooth enough\" change is very similar to the\nprocedure outlined in the previous section.  The change is \"smooth\nenough\" if all points are finite, nonsingular values, and if the\nintegral of the function over the rectangle is sufficiently well\napproximated by a certain low-order \"cubature\" formula.\n\nThe two-dimensional integral of the function is estimated using the\nfollowing 5-point Newton-Cotes cubature:\n\n+------+----+------+\n| 1/12 |  0 | 1/12 |\n+------+----+------+\n|   0  | 2/3|  0   |\n+------+----+------+\n| 1/12 |  0 | 1/12 |\n+------+----+------+\n\nAn example of using this cubature would be the approximation\n\n.. math::\n   \\int_0^1\\mathrm{d}x\\int_0^1\\mathrm{d}y f(x,y)\\approx \\frac{f(0,0)+f(0,1)+f(1,0)+f(1,1)}{12}+\\frac{2}{3}f\\left(\\frac{1}{2},\\frac{1}{2}\\right)\n\nSimilarly, an 8-point cubature with zero sum is used to estimate the\nerror:\n\n+------+------+------+\n| -1/3 |  2/3 |  1/6 |\n+------+------+------+\t\n| -1/6 | -2/3 | -1/2 |\n+------+------+------+\n| 1/2  |   0  |  1/3 |\n+------+------+------+\n\nThis set of coefficients was intentionally chosen to be asymmetric to\navoid possible exact cancellations when the function itself is\nsymmetric.\n\nOne minor problem with adaptive surface plotting is that the resulting\nset of points may not correspond to a rectangular grid in the\nparameter space :math:`(x,y)`.  This is because some rectangles from\nthe initial grid will need to be bisected more times than others.  So,\nunless adaptive refinement is disabled, the function :func:`Plot3DS`\nproduces a somewhat disordered set of points.  However, most surface\nplotting programs require that the set of data points be a rectangular\ngrid in the parameter space.  So a smoothing and interpolation\nprocedure is necessary to convert a non-gridded set of data points\n(\"scattered\" data) to a gridded set.\n\n================\nParametric plots\n================\n\nCurrently, parametric plots are not directly implemented in Yacas.\nHowever, it is possible to use Yacas to obtain numerical data for such\nplots.  One can then use external programs to produce actual graphics.\n\nA two-dimensional parametric plot is a line in a two-dimensional\nspace, defined by two equations such as :math:`x=f(t),y=g(t)`.  Two\nfunctions :math:`f, g` and a range of the independent variable\n:math:`t`, for example, :math:`t_1\\leq t\\leq t_2`, need to be\nspecified.\n\nParametric plots can be used to represent plots of functions in\nnon-Euclidean coordinates.  For example, to plot the function\n:math:`\\rho=\\cos(4\\phi)^2` in polar coordinates :math:`(\\rho,\\phi)`,\none can rewrite the Euclidean coordinates through the polar\ncoordinates, :math:`x=\\rho\\cos(\\phi),y = \\rho\\sin(\\phi)`, and\nuse the equivalent parametric plot with :math:`\\phi` as the parameter:\n:math:`x=\\cos(4\\phi)^2\\cos(\\phi), y = \\cos(4\\phi)^2\\sin(\\phi)`.\n\nSometimes higher-dimensional parametric plots are required.  A line\nplot in three dimensions is defined by three functions of one\nvariable, for example, :math:`x=f(t),y=g(t),z=h(t)`, and a range of\nthe parameter :math:`t`.  A surface plot in three dimensions is\ndefined by three functions of two variables each, for example,\n:math:`x=f(u,v),y=g(u,v),z=h(u,v)`, and a rectangular domain in the\n:math:`(u,v)` space.\n\nThe data for parametric plots can be generated separately using the\nsame adaptive plotting algorithms as for ordinary function plots, as\nif all functions such as :math:`f(t)` or :math:`g(u,v)` were unrelated\nfunctions.  The result would be several separate data sets for the\n:math:`x,y,\\ldots` coordinates.  These data sets could then be\ncombined using an interactive plotting program.\n\n============================================\nThe cost of arbitrary-precision computations\n============================================\n\nA computer algebra system absolutely needs to be able to perform\ncomputations with very large *integer* numbers. Without this\ncapability, many symbolic computations (such as exact GCD of\npolynomials or exact solution of polynomial equations) would be\nimpossible.\n\nA different question is whether a CAS really needs to be able to\nevaluate, say, 10,000 digits of the value of a Bessel function of some\n10,000-digit complex argument.  It seems likely that no applied\nproblem of natural sciences would need floating-point computations of\nspecial functions with such a high precision. However,\narbitrary-precision computations are certainly useful in some\nmathematical applications; e.g. some mathematical identities can be\nfirst guessed by a floating-point computation with many digits and\nthen proved.\n\nVery high precision computations of special functions *might* be\nuseful in the future.  But it is already quite clear that computations\nwith moderately high precision (say, 50 or 100 decimal digits) are\nuseful for applied problems.  For example, to obtain the leading\nasymptotic of an analytic function, we could expand it in series and\ntake the first term.  But we need to check that the coefficient at\nwhat we think is the leading term of the series does not vanish.  This\ncoefficient could be a certain \"exact\" number such as\n:math:`(\\cos(355)+1)^2`.  This number is \"exact\" in the sense that it\nis made of integers and elementary functions.  But we cannot say *a\npriori* that this number is nonzero.  The problem of \"zero\ndetermination\" (finding out whether a certain \"exact\" number is zero)\nis known to be algorithmically unsolvable if we allow transcendental\nfunctions.  The only practical general approach seems to be to compute\nthe number in question with many digits.  Usually a few digits are\nenough, but occasionally several hundred digits are needed.\n\nImplementing an efficient algorithm that computes 100 digits of\n:math:`\\sin(\\frac{3}{7})` already involves many of the issues that would also\nbe relevant for a 10,000 digit computation.  Modern algorithms allow\nevaluations of all elementary functions in time that is asymptotically\nlogarithmic in the number of digits :math:`P` and linear in the cost\nof long multiplication (usually denoted :math:`M(P)`).  Almost all\nspecial functions can be evaluated in time that is asymptotically\nlinear in :math:`P` and in :math:`M(P)`.  (However, this asymptotic\ncost sometimes applies only to very high precision, e.g.,\n:math:`P>1000`, and different algorithms need to be implemented for\ncalculations in lower precision.)\n\nIn yacas we strive to implement all numerical functions to arbitrary\nprecision.  All integer or rational functions return exact results,\nand all floating-point functions return their value with :math:`P`\ncorrect decimal digits (assuming sufficient precision of the\narguments).  The current value of :math:`P` is accessed as\n:func:`Builtin'Precision'Get` and may be changed by\n:func:`Builtin'Precision'Set`.\n\nImplementing an arbitrary-precision floating-point computation of a\nfunction :math:`f(x)`, such as :math:`f(x)=\\exp(x)`, typically needs\nthe following:\n\n* An algorithm that will compute :math:`f(x)` for a given value\n  :math:`x` to a user-specified precision of :math:`P` (decimal)\n  digits. Often, several algorithms must be implemented for different\n  subdomains of the (:math:`x`,:math:`P`) space.\n* An estimate of the computational cost of the algorithm(s), as a\n  function of :math:`x` and :math:`P`. This is needed to select the\n  best algorithm for given :math:`x, P`.\n* An estimate of the round-off error.  This is needed to select the\n  \"working precision\" which will typically be somewhat higher than the\n  precision of the final result.\n\nIn calculations with machine precision where the number of digits is\nfixed, the problem of round-off errors is quite prominent.  Every\narithmetic operation causes a small loss of precision; as a result, a\nfew last digits of the final value are usually incorrect.  But if we\nhave an arbitrary precision capability, we can always increase\nprecision by a few more digits during intermediate computations and\nthus eliminate all round-off error in the final result.  We should, of\ncourse, take care not to increase the working precision unnecessarily,\nbecause any increase of precision means slower calculations.  Taking\ntwice as many digits as needed and hoping that the result is precise\nis not a good solution.\n\nSelecting algorithms for computations is the most non-trivial part of\nthe implementation.  We want to achieve arbitrarily high precision, so\nwe need to find either a series, or a continued fraction, or a\nsequence given by explicit formula, that converges to the function in\na controlled way.  It is not enough to use a table of precomputed\nvalues or a fixed approximation formula that has a limited precision.\n\nIn the last 30 years, the interest in arbitrary-precision computations\ngrew and many efficient algorithms for elementary and special\nfunctions were published.  Most algorithms are iterative.  Almost\nalways it is very important to know in advance how many iterations are\nneeded for given :math:`x`, :math:`P`.  This knowledge allows to\nestimate the computational cost, in terms of the required precision\n:math:`P` and of the cost of long multiplication :math:`M(P)`, and\nchoose the best algorithm.\n\nTypically all operations will fall into one of the following\ncategories (sorted by the increasing cost):\n\n* addition, subtraction: linear in :math:`P`;\n* multiplication, division, integer power, integer root: linear in\n  :math:`M(P)`;\n* elementary functions: :math:`\\exp(x)`, :math:`\\ln(x)`, :math:`\\sin(x)`,\n  :math:`\\arctan(x)` etc.: :math:`M(P)\\ln(P)` or slower by some powers of\n  :math:`\\ln(P)`;\n* transcendental functions: :math:`erf(x)`, :math:`\\gamma(x)` etc.:\n  typically :math:`PM(P)` or slower.\n\nThe cost of long multiplication :math:`M(P)` is between :math:`O(P^2)`\nfor low precision and :math:`O(P\\ln(P))` for very high precision.  In\nsome cases, a different algorithm should be chosen if the precision is\nhigh enough to allow :math:`M(P)` faster than :math:`O(P^2)`.\n\nSome algorithms also need storage space (e.g. an efficient algorithm\nfor summation of the Taylor series uses :math:`O(\\ln(P))` temporary\n:math:`P`-digit numbers).\n\nBelow we shall normally denote by :math:`P` the required number of\ndecimal digits.  The formulae frequently contain conspicuous factors\nof :math:`\\ln(10)`, so it will be clear how to obtain analogous\nexpressions for another base.  (Most implementations use a binary base\nrather than a decimal base since it is more convenient for many\ncalculations.)\n\n==================================\nEstimating convergence of a series\n==================================\n\nAnalyzing convergence of a power series is usually not difficult.\nHere is a worked-out example of how we could estimate the required\nnumber of terms in the power series\n\n.. math::\n  \\exp(x)=1+x+\\frac{x^2}{2!} +\\ldots +\\frac{x^n}{n!} +O(x^{n+1})\n\nif we need :math:`P` decimal digits of precision in the\nresult.  To be specific, assume that :math:`|x|<1`. (A similar\ncalculation can be done for any other bound on :math:`x`.)\n\nSuppose we truncate the series after :math:`n`-th term and the series\nconverges \"well enough\" after that term. Then the error will be\napproximately equal to the first term we dropped. (This is what we\nreally mean by \"converges well enough\" and this will generally be the\ncase in all applications, because we would not want to use a series\nthat does not converge well enough.)\n\nThe term we dropped is :math:`\\frac{x^{n+1}}{(n+1)!}`.  To estimate :math:`n!`\nfor large :math:`n`, one can use the inequality\n\n.. math::\n  e^{e-1}*(n/e)^n < n! < (n/e)^{n+1}\n\n(valid for all :math:`n\\geq 47`) which provides tight\nbounds for the growth of the factorial, or a weaker inequality which\nis somewhat easier to use,\n\n\n.. math::\n  (n/e)^n < n! < ((n+1)/e)^{n+1}\n\n(valid for all :math:`n\\geq 6`). The latter inequality is sufficient for most\npurposes.\n\nIf we use the upper bound on :math:`n!` from this estimate, we find\nthat the term we dropped is bounded by\n\n.. math::\n  x^{n+1}/(n+1)! < (e/(n+2))^{n+2}.\n\nWe need this number to be smaller than\n:math:`10^{-P}`. This leads to an inequality\n\n.. math::\n   (e/(n+2))^(n+2) < 10^{-P},\n\nwhich we now need to solve for :math:`n`. The left hand\nside decreases with growing :math:`n`. So it is clear that the\ninequality will hold for large enough :math:`n`, say for :math:`n\\geq n_0`\nwhere :math:`n_0` is an unknown (integer) value. We can take a\nlogarithm of both sides, replace :math:`n` with :math:`n_0` and obtain\nthe following equation for :math:`n_0`:\n\n.. math::\n  (n_0+2)\\ln((n_0+2)/e) = P*\\ln(10).\n\nThis equation cannot be solved exactly in terms of\nelementary functions; this is a typical situation in such\nestimates. However, we do not really need a very precise solution for\n:math:`n_0`; all we need is an estimate of its integer part.  This is\nalso a typical situation.  It is acceptable if our approximate value\nof :math:`n_0` comes out a couple of units higher than necessary,\nbecause a couple of extra terms of the Taylor series will not\nsignificantly slow down the algorithm (but it is important that we do\nnot underestimate :math:`n_0`).  Finally, we are mostly interested in\nhaving a good enough answer for large values of :math:`P`.\n\nWe can try to guess the result.  The largest term on the LHS grows as\n:math:`n_0\\ln(n_0)` and it should be approximately equal to\n:math:`P\\ln(10)`; but :math:`\\ln(n_0)` grows very slowly, so this gives\nus a hint that :math:`n_0` is proportional to :math:`P\\ln(10)`.  As a\nfirst try, we set :math:`n_0=P\\ln(10)-2` and compare the RHS with the\nLHS; we find that we have overshot by a factor\n:math:`\\ln(P)-1+\\ln(\\ln(10))`, which is not a large factor. We can now\ncompensate and divide :math:`n_0` by this factor, so our second try is\n\n.. math::\n  n0 = (P\\ln(10))/(\\ln(P)-1+\\ln(\\ln(10)))-2.\n\n(This approximation\nprocedure is equivalent to solving the equation\n\n.. math::\n  x = (P*\\ln(10))/(\\ln(x)-1)\n\nby direct iteration, starting from\n:math:`x=P\\ln(10)`.)  If we substitute our second try for :math:`n_0`\ninto the equation, we shall find that we undershot a little bit\n(i.e. the LHS is a little smaller than the RHS), but our :math:`n_0` is\nnow smaller than it should be by a quantity that is smaller than 1 for\nlarge enough :math:`P`.  So we should stop at this point and simply\nadd 1 to this approximate answer. We should also replace\n:math:`\\ln(\\ln(10))-1` by 0 for simplicity (this is safe because it will\nslightly increase :math:`n_0`.)\n\nOur final result is that it is enough to take\n\n.. math::\n  n=(P*\\ln(10))/\\ln(P)-1\n\nterms in the Taylor series to compute :math:`\\exp(x)` for\n:math:`|x|<1` to :math:`P` decimal digits. (Of course, if :math:`x`\nis much smaller than 1, many fewer terms will suffice.)\n\n==============================\nEstimating the round-off error\n==============================\n\nUnavoidable round-off errors\n----------------------------\n\nAs the required precision :math:`P` grows, an arbitrary-precision\nalgorithm will need more iterations or more terms of the series. So\nthe round-off error introduced by every floating-point operation will\nincrease. When doing arbitrary-precision computations, we can always\nperform all calculations with a few more digits and compensate for\nround-off error.  It is however imperative to know in advance how many\nmore digits we need to take for our \"working precision\". We should\nalso take that increase into account when estimating the total cost of\nthe method.  (In most cases this increase is small.)\n\nHere is a simple estimate of the normal round-off error in a\ncomputation of :math:`n` terms of a power series.  Suppose that the\nsum of the series is of order :math:`1`, that the terms monotonically\ndecrease in magnitude, and that adding one term requires two\nmultiplications and one addition. If all calculations are performed\nwith absolute precision :math:`\\epsilon=10^{-P}`, then the total\naccumulated round-off error is :math:`3n\\epsilon`. If the relative\nerror is :math:`3n\\epsilon`, it means that our answer is something\nlike :math:`a*(1+3n\\epsilon)` where :math:`a` is the correct\nanswer. We can see that out of the total :math:`P` digits of this\nanswer, only the first :math:`k` decimal digits are correct, where\n:math:`k= -\\ln(3n\\epsilon)/\\ln(10)`. In other words, we have lost\n\n.. math::\n  P-k=\\ln(3n)/\\ln(10)\n\ndigits because of accumulated round-off\nerror. So we found that we need :math:`\\ln(3*n)/\\ln(10)` extra decimal\ndigits to compensate for this round-off error.\n\nThis estimate assumes several things about the series (basically, that\nthe series is \"well-behaved\").  These assumptions must be verified in\neach particular case.  For example, if the series begins with some\nlarge terms but converges to a very small value, this estimate is\nwrong (see the next subsection).\n\nIn the previous exercise we found the number of terms :math:`n` for\n:math:`\\exp(x)`. So now we know how many extra digits of working\nprecision we need for this particular case.\n\nBelow we shall have to perform similar estimates of the required\nnumber of terms and of the accumulated round-off error in our analysis\nof the algorithms.\n\nCatastrophic round-off error\n----------------------------\n\nSometimes the round-off error of a particular method of computation\nbecomes so large that the method becomes highly inefficient.\n\nConsider the computation of :math:`\\sin(x)` by the truncated Taylor\nseries\n\n.. math::\n  \\sin(x)\\approx \\sum_{k=0}^{N-1}(-1)^kx^{2k+1}/(2k+1)!),\n\nwhen :math:`x` is large.  We know that this series converges for all\n:math:`x`, no matter how large.  Assume that :math:`x=10^M` with\n:math:`M\\geq 1`, and that we need :math:`P` decimal digits of precision\nin the result.\n\nFirst, we determine the necessary number of terms :math:`N`.  The\nmagnitude of the sum is never larger than :math:`1`.  Therefore we\nneed the :math:`N`-th term of the series to be smaller than\n:math:`10^{-P}`.  The inequality is :math:`(2N+1)! >\n10^{P+M(2N+1)}`.  We obtain that :math:`2N+2>e10^M` is a\nnecessary condition, and if :math:`P` is large, we find approximately\n\n.. math::\n  2N+2 \\approx ((P-M)\\ln(10)) / (\\ln(P-M)-1-M\\ln(10)).\n\nHowever, taking enough terms does not yet guarantee a good result.\nThe terms of the series grow at first and then start to decrease.  The\nsum of these terms is, however, small.  Therefore there is some\ncancellation and we need to increase the working precision to avoid\nthe round-off.  Let us estimate the required working precision.\n\nWe need to find the magnitude of the largest term of the series.  The\nratio of the next term to the previous term is :math:`x/(2k(2k+1))`\nand therefore the maximum will be when this ratio becomes equal to\n:math:`1`, i.e. for :math:`2k\\approx\\sqrt{x}`. Therefore the largest term\nis of order :math:`x^{\\sqrt{x}}/\\sqrt{x}!` and so we need about\n:math:`M/2\\sqrt{x}` decimal digits before the decimal point to\nrepresent this term.  But we also need to keep at least :math:`P`\ndigits after the decimal point, or else the round-off error will erase\nthe significant digits of the result.  In addition, we will have\nunavoidable round-off error due to :math:`O(P)` arithmetic operations.\nSo we should increase precision again by :math:`P+\\ln(P)/\\ln(10)` digits\nplus a few guard digits.\n\nAs an example, to compute :math:`\\sin(10)` to :math:`P=50` decimal\ndigits with this method, we need a working precision of about\n:math:`60` digits, while to compute :math:`\\sin(10000)` we need to work\nwith about :math:`260` digits.  This shows how inefficient the Taylor\nseries for :math:`\\sin(x)` becomes for large arguments :math:`x`.  A\nsimple transformation :math:`x=2\\pi n+x'` would have reduced :math:`x`\nto at most 7, and the unnecessary computations with :math:`260` digits\nwould be avoided.  The main cause of this inefficiency is that we have\nto add and subtract extremely large numbers to get a relatively small\nresult of order :math:`1`.\n\nWe find that the method of Taylor series for :math:`\\sin(x)` at large\n:math:`x` is highly inefficient because of round-off error and should\nbe complemented by other methods.  This situation seems to be typical\nfor Taylor series.\n\n\n====================================\nBasic arbitrary-precision arithmetic\n====================================\n\nYacas uses an internal math library (the ``yacasnumbers`` library) which\ncomes with the source code. This reduces the dependencies of the yacas\nsystem and improves portability.  The internal math library is simple\nand does not necessarily use the most optimal algorithms.\n\nIf :math:`P` is the number of digits of precision, then multiplication\nand division take :math:`M(P)=O(P^2)` operations in the internal\nmath. (Of course, multiplication and division by a short integer takes\ntime linear in :math:`P`.)  Much faster algorithms (Karatsuba,\nToom-Cook, FFT multiplication, Newton-Raphson division etc.) are\nimplemented in {gmp}, {CLN} and some other libraries.  The asymptotic\ncost of multiplication for very large precision is\n:math:`M(P)\\approx O(P^{1.6})` for the Karatsuba method and\n:math:`M(P)=O(P\\ln(P)\\ln(\\ln(P)))` for the FFT method.  In the\nestimates of computation cost in this book we shall assume that\n:math:`M(P)` is at least linear in :math:`P` and maybe a bit slower.\n\nThe costs of multiplication may be different in various\narbitrary-precision arithmetic libraries and on different computer\nplatforms.  As a rough guide, one can assume that the straightforward\n:math:`O(P^2)` multiplication is good until 100-200 decimal digits,\nthe asymptotically fastest method of FFT multiplication is good at the\nprecision of about 5,000 or more decimal digits, and the Karatsuba\nmultiplication is best in the middle range.\n\nWarning: calculations with internal yacas math using precision\nexceeding 10,000 digits are currently impractically slow.\n\nIn some algorithms it is necessary to compute the integer parts of\nexpressions such as :math:`a\\ln(b)/\\ln(10)` or :math:`a\\ln(10)/\\ln(2)`,\nwhere :math:`a`, :math:`b` are short integers of order\n:math:`O(P)`. Such expressions are frequently needed to estimate the\nnumber of terms in the Taylor series or similar parameters of the\nalgorithms. In these cases, it is important that the result is not\nunderestimated. However, it would be wasteful to compute\n:math:`1000\\ln(10)/\\ln(2)` in great precision only to discard most of\nthat information by taking the integer part of that number.  It is\nmore efficient to approximate such constants from above by short\nrational numbers, for example, :math:`\\ln(10)/\\ln(2) < 28738/8651` and\n:math:`\\ln(2) < 7050/10171`. The error of such an approximation will be\nsmall enough for practical purposes. The function :func:`BracketRational`\ncan be used to find optimal rational approximations.\n\nThe function :func:`IntLog` (see below) efficiently computes the integer\npart of a logarithm (for an integer base, not a natural logarithm). If\nmore precision is desired in calculating :math:`\\ln(a)/\\ln(b)` for\ninteger :math:`a`, :math:`b`, one can compute :math:`IntLog(a^k,b)`\nfor some integer :math:`k` and then divide by :math:`k`.\n\nHow many digits of :math:`\\sin(\\exp(\\exp(1000)))` do we need?\n-------------------------------------------------------------\n\nArbitrary-precision math is not omnipotent against overflow.  Consider\nthe problem of representing very large numbers such as\n:math:`x=\\exp(\\exp(1000))`.  Suppose we need a floating-point\nrepresentation of the number :math:`x` with :math:`P` decimal digits\nof precision.  In other words, we need to express :math:`x\\approx M10^E`,\nwhere the mantissa :math:`1<M<10` is a floating-point number and\nthe exponent :math:`E` is an integer, chosen so that the relative\nprecision is :math:`10^{-P}`.  How much effort is needed to find\n:math:`M` and :math:`E`?\n\nThe exponent :math:`E` is easy to obtain:\n\n.. math::\n  E = \\lfloor\\ln(x)/\\ln(10)\\rfloor = \\lfloor\\exp(1000)/\\ln(10)\\rfloor\\approx 8.55 * 10^{433}.\n\nTo compute the integer\npart :math:`\\lfloor y\\rfloor` of a number :math:`y` exactly, we need to\napproximate :math:`y` with at least :math:`\\ln(y)/\\ln(10)`\nfloating-point digits.  In our example, we find that we need 434\ndecimal digits to represent :math:`E`.\n\nOnce we found :math:`E`, we can write :math:`x=10^{E+m}` where\n:math:`m=\\exp(1000)/\\ln(10)-E` is a floating-point number,\n:math:`0<m<1`.  Then :math:`M=10^m`.  To find :math:`M` with :math:`P`\n(decimal) digits, we need :math:`m` with also at least :math:`P`\ndigits.  Therefore, we actually need to evaluate\n:math:`\\exp(1000)/\\ln(10)` with :math:`434+P` decimal digits before we\ncan find :math:`P` digits of the mantissa of :math:`x`.  We ran into a\nperhaps surprising situation: one needs a high-precision calculation\neven to find the first digit of :math:`x`, because it is necessary to\nfind the exponent :math:`E` exactly as an integer, and :math:`E` is a\nrather large integer.  A normal double-precision numerical calculation\nwould give an overflow error at this point.\n\nSuppose we have found the number :math:`x=\\exp(\\exp(1000))` with some\nprecision.  What about finding :math:`\\sin(x)`?  Now, this is extremely\ndifficult, because to find even the first digit of :math:`\\sin(x)` we\nhave to evaluate :math:`x` with *absolute* error of at most\n:math:`0.5`.  We know, however, that the number :math:`x` has\napproximately :math:`10^434` digits *before* the decimal point.\nTherefore, we would need to calculate :math:`x` with at least that\nmany digits.  Computations with :math:`10^434` digits is clearly far\nbeyond the capability of modern computers.  It seems unlikely that\neven the sign of :math:`\\sin(\\exp(\\exp(1000)))` will be obtained in the\nnear future [#]_. \n\n.. [#] It seems even less likely that the sign of :math:`\\sin(\\exp(\\exp(1000)))` would be of any use to anybody even if it could be computed.\n\nSuppose that :math:`N` is the largest integer that our\narbitrary-precision facility can reasonably handle.  (For yacas\ninternal math library, :math:`N` is about :math:`10^10000`.)  Then it\nfollows that numbers :math:`x` of order :math:`10^N` can be calculated\nwith at most one (1) digit of floating-point precision, while larger\nnumbers cannot be calculated with any precision at all.\n\nIt seems that very large numbers can be obtained in practice only\nthrough exponentiation or powers.  It is unlikely that such numbers\nwill arise from sums or products of reasonably-sized numbers in some\nformula [#]_.\n\n.. [#] A factorial function can produce rapidly growing results, but exact factorials :math:`n!` for large :math:`n` are well represented by the Stirling formula which involves powers and exponentials.  For example, suppose a program operates with numbers :math:`x` of size :math:`N` or smaller; a number such as :math:`10^N` can be obtained only by multiplying :math:`O(N)` numbers :math:`x` together.  But since :math:`N` is the largest representable number, it is certainly not feasible to perform :math:`O(N)` sequential operations on a computer.  However, it is feasible to obtain :math:`N`-th power of a small number, since it requires only :math:`O(Ln(N))` operations.\n\nIf numbers larger than :math:`10^N` are created only by exponentiation\noperations, then special exponential notation could be used to\nrepresent them.  For example, a very large number :math:`z` could be\nstored and manipulated as an unevaluated exponential\n:math:`z=\\exp(M10^E)` where :math:`M\\geq 1` is a floating-point number\nwith :math:`P` digits of mantissa and :math:`E` is an integer,\n:math:`\\ln(N)<E<N`.  Let us call such objects \"exponentially large\nnumbers\" or \"exp-numbers\" for short.\n\nIn practice, we should decide on a threshold value :math:`N` and\npromote a number to an exp-number when its logarithm exceeds\n:math:`N`.\n\nNote that an exp-number :math:`z` might be positive or negative, e.g.\n:math:`z= -\\exp(M10^E)`.\n\nArithmetic operations can be applied to the exp-numbers.  However,\nexp-large arithmetic is of limited use because of an almost certainly\ncritical loss of precision.  The power and logarithm operations can be\nmeaningfully performed on exp-numbers :math:`z`.  For example, if\n:math:`z=\\exp(M10^E)` and :math:`p` is a normal floating-point number,\nthen :math:`z^p=\\exp(pM10^E)` and :math:`\\ln(z)=M10^E`.  We can also\nmultiply or divide two exp-numbers.  But it makes no sense to multiply\nan exp-number :math:`z` by a normal number because we cannot represent\nthe difference between :math:`z` and say :math:`2.52*z`.  Similarly,\nadding :math:`z` to anything else would result in a total underflow,\nsince we do not actually know a single digit of the decimal\nrepresentation of :math:`z`.  So if :math:`z_1` and :math:`z_2` are\nexp-numbers, then :math:`z_1+z_2` is simply equal to either :math:`z1`\nor :math:`z2` depending on which of them is larger.\n\nWe find that an exp-number :math:`z` acts as an effective \"infinity\"\ncompared with normal numbers.  But exp-numbers cannot be used as a\ndevice for computing limits: the unavoidable underflow will almost\ncertainly produce wrong results.  For example, trying to verify\n\n.. math::\n  \\lim_{x\\to 0} \\frac{\\exp(x)-1}{x} = 1\n\nby substituting :math:`x=1/z` with\nsome exp-number :math:`z` gives 0 instead of 1.\n\nTaking a logarithm of an exp-number brings it back to the realm of\nnormal, representable numbers.  However, taking an exponential of an\nexp-number results in a number which is not representable even as an\nexp-number.  This is because an exp-number :math:`z` needs to have its\nexponent :math:`E` represented exactly as an integer, but\n:math:`\\exp(z)` has an exponent of order :math:`O(z)` which is not a\nrepresentable number.  The monstrous number :math:`\\exp(z)` could be\nonly written as :math:`\\exp(\\exp(M10^E))`, i.e. as a \"doubly\nexponentially large\" number, or \"2-exp-number\" for short.  Thus we\nobtain a hierarchy of iterated exp-numbers.  Each layer is\n\"unrepresentably larger\" than the previous one.\n\nThe same considerations apply to very small numbers of the order\n:math:`10^{-N}` or smaller.  Such numbers can be manipulated as\n\"exponentially small numbers\", i.e. expressions of the form\n:math:`Exp(-M*10^E)` with floating-point mantissa :math:`M\\geq 1` and\ninteger :math:`E` satisfying :math:`\\ln(N)<E<N`.  Exponentially small\nnumbers act as an effective zero compared with normal numbers.\n\nTaking a logarithm of an exp-small number makes it again a normal\nrepresentable number.  However, taking an exponential of an exp-small\nnumber produces 1 because of underflow.  To obtain a \"doubly\nexponentially small\" number, we need to take a reciprocal of a doubly\nexponentially large number, or take the exponent of an exponentially\nlarge negative power.  In other words, :math:`\\exp(-M10^E)` is\nexp-small, while :math:`\\exp(-\\exp(M10^E))` is 2-exp-small.\n\nThe practical significance of exp-numbers is rather limited.  We\ncannot obtain even a single significant digit of an exp-number.  A\n\"computation\" with exp-numbers is essentially a floating-point\ncomputation with logarithms of these exp-numbers.  A practical problem\nthat needs numbers of this magnitude can probably be restated in terms\nof more manageable logarithms of such numbers.  In practice,\nexp-numbers could be useful not as a means to get a numerical answer,\nbut as a warning sign of critical overflow or underflow [#]_.\n\n.. [#] Yacas currently does not implement exp-numbers or any other guards against overflow and underflow. If a decimal exponential becomes too large, an incorrect answer may result.\n"
  },
  {
    "path": "docs/book_of_algorithms/index.rst",
    "content": "****************************\nThe Yacas Book of Algorithms\n****************************\n\nThis book is a detailed description of the algorithms used in the\nYacas system for exact symbolic and arbitrary-precision numerical\ncomputations. Very few of these algorithms are new, and most are\nwell-known.  The goal of this book is to become a compendium of all\nrelevant issues of design and implementation of these algorithms.\n\n.. toctree::\n   :maxdepth: 1\n\n   basic.rst\n   multivar.rst\n   integration.rst\n   transforms.rst\n   sturm-sequences.rst\n   numtheory.rst\n   references.rst\n"
  },
  {
    "path": "docs/book_of_algorithms/integration.rst",
    "content": "===========\nIntegration\n===========\n\nIntegration can be performed by the function :func:`Integrate`, which has\ntwo calling conventions::\n\n    Integrate(variable) expression\n    Integrate(variable, from, to) expression\n\n:func:`Integrate` can have its own set of rules for specific integrals, which\nmight return a correct answer immediately. Alternatively, it calls the function\n:func:`AntiDeriv`, to see if the anti-derivative can be determined for the\nintegral requested. If this is the case, the anti-derivative is used to compose\nthe output.\n\nIf the integration algorithm cannot perform the integral, the\nexpression is returned unsimplified.\n\nThe integration algorithm\n-------------------------\n\nGeneral structure\n^^^^^^^^^^^^^^^^^\n\nThe integration starts at the function :func:`Integrate`, but the task is\ndelegated to other functions, one after the other. Each function can deem the\nintegral unsolvable, and thus return the integral unevaluated. These different\nfunctions offer hooks for adding new types of integrals to be handled.\n\nExpression clean-up\n^^^^^^^^^^^^^^^^^^^\n\nIntegration starts by first cleaning up the expression, by calling\n:func:`TrigSimpCombine` to simplify expressions containing multiplications of\ntrigonometric functions into additions of trigonometric functions (for which the\nintegration rules are trivial), and then passing the result to :func:`Simplify`.\n\nGeneralized integration rules\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nFor the function :func:`AntiDeriv`, which is responsible for finding the\nanti-derivative of a function, the code splits up expressions\naccording to the additive properties of integration, eg. integration\nof :math:`a+b` is the same as integrating :math:`a` and :math:`b` separately\nand adding the integrals.\n\n* Polynomials which can be expressed as univariate polynomials in the\n  variable to be integrated over are handled by one integration rule.\n* Expressions of the form :math:`pf(x)`, where :math:`p` represents a\n  univariate polynomial, and :math:`f(x)` an integrable function, are\n  handled by a special integration rule. This transformation rule has\n  to be designed carefully not to invoke infinite recursion.\n* Rational functions, :math:`f(x)/g(x)` with both :math:`f(x)` and :math:`g(x)`\n  being univariate polynomials, is handled separately also, using partial\n  fraction expansion to reduce rational function to a sum of simpler\n  expressions.\n\nIntegration tables\n^^^^^^^^^^^^^^^^^^\n\nFor elementary functions, yacas uses integration tables. For instance,\nthe fact that the anti-derivative of :math:`\\cos(x)` is :math:`\\sin(x)` is\ndeclared in an integration table.\n\nFor the purpose of setting up the integration table, a few declaration\nfunctions have been defined, which use some generalized pattern\nmatchers to be more flexible in recognizing expressions that are\nintegrable.\n\nIntegrating simple functions of a variable\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nFor functions like :math:`\\sin(x)` the anti-derivative can be declared with\nthe function :func:`IntFunc`.\n\nThe calling sequence for :func:`IntFunc` is::\n\n    IntFunc(variable,pattern,antiderivative)\n\nFor instance, for the function :func:`Cos` there is a declaration::\n\n    IntFunc(x,Cos(_x),Sin(x));\n\nThe fact that the second argument is a pattern means that each\noccurrence of the variable to be matched should be referred to as\n``_x``, as in the example above.\n\n:func:`IntFunc` generalizes the integration implicitly, in that it will set up\nthe system to actually recognize expressions of the form :math:`\\cos(ax+b)`,\nand return :math:`\\sin(ax+b)/a` automatically. This means that the\nvariables ``a`` and ``b`` are reserved, and can not be used in the\npattern. Also, the variable used (in this case, ``_x`` is actually\nmatched to the expression passed in to the function, and the variable\n``var`` is the real variable being integrated over. To clarify: suppose\nthe user wants to integrate :math:`\\cos(cy+d)` over :math:`y`, then the\nfollowing variables are set:\n\n* ``a`` = :math:`c`\n* ``b`` = :math:`d`\n* ``x`` = :math:`ay+b`\n* ``var`` = :math:`x`\n\nWhen functions are multiplied by constants, that situation is handled\nby the integration rule that can deal with univariate polynomials\nmultiplied by functions, as a constant is a polynomial of degree zero.\n\n\nIntegrating functions containing expressions of the form :math:`ax^2+b`\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThere are numerous expressions containing sub-expressions of the form\n:math:`ax^2+b` which can easily be integrated.\n\nThe general form for declaring anti-derivatives for such expressions\nis::\n\n  IntPureSquare(variable, pattern, sign2, sign0, antiderivative)\n\nHere :func:`IntPureSquare` uses :func:`MatchPureSquared` to match the expression.\n\nThe expression is searched for the pattern, where the variable can\nmatch to a sub-expression of the form :math:`ax^2+b`, and for which both\n:math:`a` and :math:`b` are numbers and :math:`a*sign2>0` and :math:`b*sign0>0`.\n\nAs an example::\n\n    IntPureSquare(x,num_IsFreeOf(var)/(_x),1,1,\n                    (num/(a*Sqrt(b/a)))*ArcTan(var/Sqrt(b/a)));\n\ndeclares that the anti-derivative of :math:`\\frac{c}{a*x^2+b}` is\n\n.. math::\n\n   \\frac{c}{a\\sqrt{\\frac{b}{a}}}\\arctan{\\frac{x}{\\sqrt{\\frac{b}{a}}}},\n\nif both :math:`a` and :math:`b` are positive numbers.\n"
  },
  {
    "path": "docs/book_of_algorithms/multivar.rst",
    "content": "======================\nSparse representations\n======================\n\nThe sparse tree data structure\n------------------------------\n\nYacas has a sparse tree object for use as a storage for storing\n(key,value) pairs for which the following properties hold:\n\n* ``(key, value1) + (key, value2) = (key, value1+value2)``\n* ``(key1, value1) * (key2, value2) = (key1+key2, value1*value2)``\n\nThe last is optional. For multivariate polynomials (described\nelsewhere) both hold, but for matrices, only the addition property\nholds.  The function {MultiplyAddSparseTrees} (described below) should\nnot be used in these cases.\n\nInternal structure\n------------------\n\nA key is defined to be a list of integer numbers :math:`(n_1,\\ldots, n_m)`.\nThus for a two-dimensional key, one item in the sparse tree\ndatabase could be reflected as the (key,value) pair { {{1,2},3} },\nwhich states that element {(1,2)} has value {3}. (Note: this is not\nthe way it is stored in the database!).\n\nThe storage is recursive. The sparse tree begins with a list of\nobjects { {n1,tree1} } for values of {n1} for the first item in the\nkey. The {tree1} part then contains a sub-tree for all the items in\nthe database for which the value of the first item in the key is {n1}.\n\nThe above single element could be created with::\n\n  In> r:=CreateSparseTree({1,2},3)\n  Out> {{1,{{2,3}}}};\n\n{CreateSparseTree} makes a database with exactly one item.  Items can\nnow be obtained from the sparse tree with {SparseTreeGet}.::\n\n  In> SparseTreeGet({1,2},r)\n  Out> 3;\n  In> SparseTreeGet({1,3},r)\n  Out> 0;\n\nAnd values can also be set or changed::\n\n  In> SparseTreeSet({1,2},r,Current+5)\n  Out> 8;\n  In> r\n  Out> {{1,{{2,8}}}};\n  In> SparseTreeSet({1,3},r,Current+5)\n  Out> 5;\n  In> r\n  Out> {{1,{{3,5},{2,8}}}};\n\nThe variable {Current} represents the current value, and can be used\nto determine the new value. {SparseTreeSet} destructively modifies the\noriginal, and returns the new value. If the key pair was not found, it\nis added to the tree.\n\nThe sparse tree can be traversed, one element at a time, with\n{SparseTreeScan}::\n\n  In> SparseTreeScan(Hold({{k,v},Echo({k,v})}),2,r)\n  {1,3} 5 \n  {1,2} 8 \n\nAn example of the use of this function could be multiplying a sparse\nmatrix with a sparse vector, where the entire matrix can be scanned\nwith {SparseTreeScan}, and each non-zero matrix element :math:`A_{ij}`\ncan then be multiplied with a vector element :math:`v_j`, and the result\nadded to a sparse vector :math:`w_i`, using the {SparseTreeGet} and\n{SparseTreeSet} functions.  Multiplying two sparse matrices would\nrequire two nested calls to {SparseTreeScan} to multiply every item\nfrom one matrix with an element from the other, and add it to the\nappropriate element in the resulting sparse matrix.\n\nWhen the matrix elements :math:`A_{ij}` are defined by a function :math:`f(i,j`)\n(which can be considered a dense representation), and it\nneeds to be multiplied with a sparse vector :math:`v_j`, it is better to\niterate over the sparse vector :math:`v_j`.  Representation defines the\nmost efficient algorithm to use in this case.\n\nThe API to sparse trees is:\n\n* {CreateSparseTree(coefs,fact)} - Create a sparse tree with one\n  monomial, where 'coefs' is the key, and 'fact' the value. 'coefs'\n  should be a list of integers.\n* {SparseTreeMap(op,depth,tree)} - Walk over the sparse tree, one\n  element at a time, and apply the function \"op\" on the arguments\n  (key,value). The 'value' in the tree is replaced by the value\n  returned by the {op} function. 'depth' signifies the dimension of\n  the tree (number of indices in the key).\n* {SparseTreeScan(op,depth,tree)} - Same as SparseTreeMap, but without\n  changing elements.\n* {AddSparseTrees(depth,x,y)},\n  {MultiplyAddSparseTrees(depth,x,y,coefs,fact)} - Add sparse tree 'y'\n  to sparse tree 'x', destructively.  in the {MultiplyAdd} case, the\n  monomials are treated as if they were multiplied by a monomial with\n  coefficients with the (key,value) pair (coefs,fact). 'depth'\n  signifies the dimension of the tree (number of indices in the key).\n* {SparseTreeGet(key,tree)} - return value stored for key in the tree.\n* {SparseTreeSet(key,tree,newvalue)} - change the value stored for the\n  key to newvalue. If the key was not found then {newvalue} is stored\n  as a new item. The variable {Current} is set to the old value (or\n  zero if the key didn't exist in the tree) before evaluating\n  {newvalue}.\n\n\nImplementation of multivariate polynomials\n------------------------------------------\n\nThis section describes the implementation of multivariate\npolynomials in yacas. Concepts and ideas are taken from the books\n:cite:`davenport1988:computer_algebra` and\n:cite:`gathen1999:modern_computer_algebra`.\n\n\nDefinitions\n^^^^^^^^^^^\n\nThe following definitions define multivariate polynomials, and the\nfunctions defined on them that are of interest for using such\nmultivariates.\n\nA *term* is an object which can be written as \n\n.. math:: cx_1^{n_1}x_2^{n_2}\\ldots x_m^{n_m}\n\nfor :math:`m` variables (:math:`x_1`, ..., :math:`x_m`). The numbers\n:math:`n_m` are integers. :math:`c` is called a *coefficient*, and \n:math:`x_1^{n_1}x_2^{n_2}\\ldots x_m^{n_m}` a *monomial*.\n\nA *multivariate polynomial* is taken to be a sum over terms.\n\nWe write :math:`c_ax^a` for a term, where :math:`a` is a list of\npowers for the monomial, and :math:`c_a` the *coefficient* of the \nterm.\n\nIt is useful to define an ordering of monomials, to be able to determine the\ncanonical form of a multivariate. For the currently implemented code the\n*lexicographic order* has been chosen:\n\n* First, the ordering of variables is chosen, (:math:`x_1`, ..., :math:`x_m`)\n* For the exponents of a monomial, :math:`a = (a_1,\\ldots, a_m)`\n  the lexicographic order first looks at the first exponent, :math:`a_1`,\n  to determine which of the two monomials comes first in the\n  multivariate.  If the two exponents are the same, the next exponent\n  is considered.\n\nThis method is called *lexicographic* because it is similar to\nthe way words are ordered in a usual dictionary.\n\nFor all algorithms (including division) there is some freedom in the\nordering of monomials. One interesting advantage of the lexicographic\norder is that it can be implemented with a recursive data structure,\nwhere the first variable, :math:`x_1` can be treated as the main\nvariable, thus presenting it as a univariate polynomial in :math:`x_1`\nwith all its terms grouped together.\n\nOther orderings can be used, by re-implementing a part of the code\ndealing with multivariate polynomials, and then selecting the new code\nto be used as a driver, as will be described later on.\n\nGiven the above ordering, the following definitions can be stated:\n\nFor a non-zero *multivariate polynomial*\n\n.. math:: f = \\sum_{a=a_{max}}^{a_{min}}c_ax^a\n\nwith a monomial order:\n\n#. :math:`c_ax^a` is a *term* of the multivariate.\n#. the *multidegree* of :math:`f` is :math:`\\operatorname{mdeg}(f) := a_{max}`.\n#. the *leading coefficient* of :math:`f` is :math:`\\operatorname{lc}(f):=c_{\\operatorname{mdeg}(f)}`, for the first term with non-zero coefficient.\n#. the *leading monomial* of :math:`f` is :math:`\\operatorname{lm}(f):=x^{\\operatorname{mdeg}(f)}`.\n#. the *leading term* of :math:`f` is :math:`\\operatorname{lt}(f):=\\operatorname{lc}(f)\\operatorname{lm}(f)`.\n\nThe above define access to the leading monomial, which is used for\ndivisions, gcd calculations and the like. Thus an implementation needs\nbe able to determine :math:`(\\operatorname{mdeg}(f),\\operatorname{lc}(f)`.\nNote the similarity with the (key,value) pairs described in the sparse tree\nsection. :math:`\\operatorname{mdeg}(f)` can be thought of as a key, and \n:math:`\\operatorname{lc}(f)` as a value.\n\nThe *multicontent*, :math:`\\operatorname{multicont}(f)`, is defined to be a\nterm that divides all the terms in :math:`f`, and is the term described by\n:math:`(\\min(a), \\gcd(c))`, with :math:`\\gcd(c)` the GCD of all the\ncoefficients, and :math:\\min(a)` the lowest exponents for each variable,\noccurring in :math:`f` for which :math:`c` is non-zero.\n\nThe *multiprimitive part* is then defined as \n:math:`\\operatorname{pp}(f):=\\frac{f}{\\operatorname{multicont}(f)}`.\n\nFor a multivariate polynomial, the obvious addition and (distributive)\nmultiplication rules hold\n\n* :math:`(a+b) + c = a+(b+c)`\n* :math:`a(b+c) = ab+ac`\n\nThese are supported in the Yacas system through a multiply-add\noperation: :math:`\\operatorname{muadd}(f,t,g) := f+tg`.  This allows for both\nadding two polynomials (:math:`t=1`), or multiplication of two polynomials by\nscanning one polynomial, and multiplying each term of the scanned\npolynomial with the other polynomial, and adding the result to the\npolynomial that will be returned. Thus there should be an efficient\n:math:`\\operatorname{muadd}` operation in the system.\n\n\nRepresentation\n^^^^^^^^^^^^^^\n\nFor the representation of polynomials, on computers it is natural to\ndo this in an array: :math:`(a_1, a_2,\\ldots, a_n)` for a univariate\npolynomial, and the equivalent for multivariates. This is called a\n*dense* representation, because all the coefficients are stored,\neven if they are zero.  Computers are efficient at dealing with\narrays. However, in the case of multivariate polynomials, arrays can\nbecome rather large, requiring a lot of storage and processing power\neven to add two such polynomials. For instance, :math:`x^{200}y^{100}z^{300}+1`\ncould take 6000000 places in an array for the coefficients. Of\ncourse variables could be substituted for the single factors,\n:math:`p:=x^{200}` *etc.*, but it requires an additional *ad hoc* step.\n\nAn alternative is to store only the terms for which the coefficients\nare non-zero. This adds a little overhead to polynomials that could\nefficiently be stored in a dense representation, but it is still\nlittle memory, whereas large sparse polynomials are stored in\nacceptable memory too. It is of importance to still be able to add,\nmultiply divide and get the leading term of a multivariate polynomial,\nwhen the polynomial is stored in a sparse representation.\n\nFor the representation, the data structure containing the\n{(exponents,coefficient)} pair can be viewed as a database holding\n{(key,value)} pairs, where the list of exponents is the key, and the\ncoefficient of the term is the value stored for that key. Thus, for a\nvariable set {{x,y}} the list ``{{1,2},3}`` represents :math:`3xy^2`.\n\nYacas stores multivariates internally as ``MultiNomial(vars, terms)``,\nwhere ``vars`` is the ordered list of variables, and terms some object\nstoring all the ``(key, value)`` pairs representing the terms.  Note we\nkeep the storage vague: the ``terms`` placeholder is implemented by\nother code, as a database of terms. The specific representation can be\nconfigured at startup (this is described in more detail below).\n\nFor the current version, yacas uses the sparse tree representation,\nwhich is a recursive sparse representation.  For example, for a\nvariable set ``{x,y,z}``, the ``terms`` object contains a list of objects\nof form ``{deg,terms}``, one for each degree ``deg`` for the variable ``x``\noccurring in the polynomial. The ``terms`` part of this object is then a\nsub-sparse tree for the variables ``{y,z}``.\n\nAn explicit example::\n\n  In> MM(3*x^2+y)\n  Out> MultiNomial({x,y},{{2,{{0,3}}},{0,{{1,1}, {0,0}}}});\n\nThe first item in the main list is ``{2,{{0,3}}}``, which states that\nthere is a term of the form :math:`x^2y^03`. The second item states that\nthere are two terms, :math:`x^0y^11` and :math:`x^0y^00 = 0`.\n\nThis representation is sparse::\n\n  In> r:=MM(x^1000+x)\n  Out> MultiNomial({x},{{1000,1},{1,1}});\n\nand allows for easy multiplication::\n\n  In> r*r\n  Out> MultiNomial({x},{{2000,1},{1001,2},{2,1},{0,0}});\n  In> NormalForm(%)\n  Out> x^2000+2*x^1001+x^2;\n\nInternal code organization\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe implementation of multivariates can be divided in three levels.\n\nAt the top level are the routines callable by the user or the rest of\nthe system: :func:`MultiDegree`, :func:`MultiDivide`, :func:`MultiGcd`,\n:func:`Groebner`, *etc.*  In general, this is the level implementing the\noperations actually desired.\n\nThe middle level does the book-keeping of the ``MultiNomial(vars,terms)``\nexpressions, using the functionality offered by the lowest level.\n\nFor the current system, the middle level is in ``multivar.rep/sparsenomial.ys``,\nand it uses the sparse tree representation implemented in ``sparsetree.ys``.\n\nThe middle level is called the *driver*, and can be changed, or\nre-implemented if necessary. For instance, in case calculations need\nto be done for which dense representations are actually acceptable,\none could write C++ implementing above-mentioned database structure,\nand then write a middle-level driver using the code.  The driver can\nthen be selected at startup. In the file ``yacasinit.ys`` the default\ndriver is chosen, but this can be overridden in the ``.yacasrc`` file or\nsome file that is loaded, or at the command line, as long as it is\ndone before the multivariates module is loaded (which loads the\nselected driver). Driver selection is as simple as setting a global\nvariable to contain a file name of the file implementing the driver::\n\n    Set(MultiNomialDriver,\n      \"multivar.rep/sparsenomial.ys\");\n\nwhere \"multivar.rep/sparsenomial.ys\" is the file implementing the\ndriver (this is also the default driver, so the above command would\nnot change any thing).\n\nThe choice was made for static configuration of the driver before the\nsystem starts up because it is expected that there will in general be\none best way of doing it, given a certain system with a certain set of\nlibraries installed on the operating system, and for a specific\nversion of Yacas. The best version can then be selected at start up,\nas a configuration step. The advantage of static selection is that no\noverhead is imposed: there is no performance penalty for the\nabstraction layers between the three levels.\n\nDriver interface\n^^^^^^^^^^^^^^^^\n\nThe driver should implement the following interface:\n\n* ``CreateTerm(vars,{exp,coef})`` - create a multivariate polynomial\n  with one term, in the variables defined in ``var``, with the\n  (key,value) pair (coefs,fact)\n* ``MultiNomialAdd(multi1, multi2)`` - add two multivars, and\n  (possibly) destructively modify ``multi1`` to contain the result::\n      \n    [ multi1 := multi1 + multi2; multi1; ];\n    \n* ``MultiNomialMultiplyAdd(multi1, multi2,exp,coef)`` - add two\n  multivars, and (possibly) destructively modify ``multi1`` to contain the\n  result. ``multi2`` is considered multiplied by a term represented by the\n  (key,value) pair (exp,coef)::\n  \n    [ multi1 := multi1 + term * multi2; multi1; ];\n    \n* ``MultiNomialNegate(multi)`` - negate a multivar, returning -multi,\n  and destructively changing the original::\n  \n    [ multi := - multi; multi1; ];\n  \n* ``MultiNomialMultiply(multi1,multi2)`` - Multiply two multivars, and\n  (possibly) destructively modify ``multi1`` to contain the result,\n  returning the result::\n  \n    [ multi1 := multi1 * multi2; multi1; ];\n    \n* ``NormalForm(multi)`` - convert MultiNomial to normal form (as would\n  be typed in be the user).  This is part of the driver because the\n  driver might be able to do this more efficiently than code above it\n  which can use :func:`ScanMultiNomial`.\n* ``MultiLeadingTerm(multi)`` - return the (key,value) pair\n  (mdeg(f),lc(f)) representing the leading term. This is all the\n  information needed about the leading term, and thus the leading\n  coefficient and multidegree can be extracted from it.\n* ``MultiDropLeadingZeroes(multi)`` - remove leading terms with zero\n  factors.\n* ``MultiTermLess(x,y)`` - for two (key,value) pairs, return :data:`True` if\n  :math:`x<y`, where the operation :math:`<` is the one used for the\n  representation, and :data:`False` otherwise.\n* ``ScanMultiNomial(op,multi)`` - traverse all the terms of the\n  multivariate, applying the function ``op`` to each (key,value) pair\n  (exp,coef). The monomials are traversed in the ordering defined by\n  MultiTermLess. ``op`` should be a function accepting two arguments.\n* ``MultiZero(multi)`` - return :data:`True` if the multivariate is zero (all\n  coefficients are zero), :data:`False` otherwise.\n"
  },
  {
    "path": "docs/book_of_algorithms/numtheory.rst",
    "content": "========================\nNumber theory algorithms\n========================\n\nThis chapter describes the algorithms used for computing various\nnumber-theoretic functions.  We call \"number-theoretic\" any function\nthat takes integer arguments, produces integer values, and is of\ninterest to number theory.\n\nEuclidean GCD algorithms\n------------------------\n\nThe main algorithm for the calculation of the GCD of two integers is\nthe binary Euclidean algorithm.  It is based on the following\nidentities: :math:`\\gcd(a,b) = \\gcd(b,a)`, :math:`\\gcd(a,b) = \\gcd(a-b,b)`,\nand for odd :math:`b`, :math:`\\gcd(2a,b) = \\gcd(a,b)`. Thus we can produce\na sequence of pairs with the same GCD as the original two numbers, and each\npair will be at most half the size of the previous pair. The number of\nsteps is logarithmic in the number of digits in :math:`a`, :math:`b`. The only\noperations needed for this algorithm are binary shifts and\nsubtractions (no modular division is necessary).  The low-level\nfunction for this is :func:`MathGcd`.\n\nTo speed up the calculation when one of the numbers is much larger\nthan another, one could use the property :math:`\\gcd(a,b)=\\gcd(a,a \\bmod b)`.\nThis will introduce an additional modular division into the algorithm;\nthis is a slow operation when the numbers are large.\n\nPrime numbers: the Miller-Rabin test and its improvements\n---------------------------------------------------------\n\nSmall prime numbers are simply stored in a precomputed table as an array of\nbits; the bits corresponding to prime numbers are set to 1.  This makes\nprimality testing on small numbers very quick.  This is implemented by the\nfunction :func:`FastIsPrime`.\n\nPrimality of larger numbers is tested by the function :func:`IsPrime` that\nuses the Miller-Rabin algorithm. [#miller-rabin]_ This algorithm is\ndeterministic (guaranteed correct within a certain running time) for\nsmall numbers :math:`n<3.4\\cdot10^{13}` and probabilistic (correct with high\nprobability, but not guaranteed) for larger numbers.  In other words,\nthe Miller-Rabin test could sometimes flag a large number :math:`n` as prime\nwhen in fact :math:`n` is composite; but the probability for this to happen\ncan be made extremely small. The basic reference is\n:cite:`rabin1980:probabilistic_algorithm_testing`.  We also implemented some\nof the improvements suggested in :cite:`davenport1992:primality_test_revisited`.\n\n.. [#miller-rabin] Initial implementation and documentation was supplied by Christian Obrecht.\n\nThe idea of the Miller-Rabin algorithm is to improve on the Fermat\nprimality test. If :math:`n` is prime, then for any :math:`x` we have\n:math:`\\gcd(n,x)=1`. Then by `Fermat's little theorem`_,\n:math:`x^{n-1}:=1 \\bmod n`. (This is really a simple statement; if :math:`n` is\nprime, then :math:`n-1` nonzero remainders modulo :math:`n`: :math:`1, 2, \n\\ldots, n-1` form a cyclic multiplicative group.) Therefore we pick some \n\"base\" integer :math:`x` and compute :math:`x^{n-1} \\bmod n`; this is a quick\ncomputation even if :math:`n` is large. If this value is not equal to 1 for \nsome base :math:`x`, then :math:`n` is definitely not prime.  However, we\ncannot test *every* base :math:`x<n`; instead we test only some :math:`x`, so\nit may happen that we miss the right values of :math:`x` that would expose the\nnon-primality of :math:`n`.  So Fermat's test sometimes fails, i.e. says\nthat :math:`n` is a prime when :math:`n` is in fact not a prime.  Also there\nare infinitely many integers called `Carmichael numbers`_ which are not\nprime but pass the Fermat test for every base.\n\n.. _Fermat's little theorem: https://en.wikipedia.org/wiki/Fermat%27s_little_theorem\n.. _Carmichael numbers: https://en.wikipedia.org/wiki/Carmichael_number\n\nThe Miller-Rabin algorithm improves on this by using the property that\nfor prime :math:`n` there are no nontrivial square roots of unity in the\nring of integers modulo :math:`n` (this is Lagrange's theorem). In other\nwords, if :math:`x^2:=1 \\bmod n` for some :math:`x`, then :math:`x` must\nbe equal to 1 or -1 modulo :math:`n`. (Since :math:`n-1` is equal to -1\nmodulo :math:`n`, we have :math:`n-1` as a trivial square root of unity\nmodulo :math:`n`.  Note that even if :math:`n` is prime there may be\nnontrivial divisors of 1, for example, :math:`2\\dot49:=1 \\bmod 97`.)\n\nWe can check that :math:`n` is odd before applying any primality test. (A\ntest :math:`n^2:=1 \\bmod 24` guarantees that :math:`n` is not divisible by\n2 or 3.  For large :math:`n` it is faster to first compute :math:`n \\bmod 24`\nrather than :math:`n^2`, or test :math:`n` directly.)  Then we note that in\nFermat's test the number :math:`n-1` is certainly a composite number because\n:math:`n-1` is even. So if we first find the largest power of 2 in :math:`n-1`\nand decompose :math:`n-1=2^rq` with :math:`q` odd, then\n:math:`x^{n-1}:=a^{2^r}\\bmod n` where :math:`a:=x^q \\bmod n`. (Here\n:math:`r\\ge 1` since :math:`n` is odd.) In other words,\nthe number :math:`x^{n-1}\\bmod n` is obtained by repeated squaring of the\nnumber :math:`a`.  We get a sequence of :math:`r` repeated squares:\n:math:`a, a^2,\\ldots,a^{2^r}`.  The last element of this sequence must be 1 if\n:math:`n` passes the Fermat test.  (If it does not pass, :math:`n` is\ndefinitely a composite number.)  If :math:`n` passes the Fermat test, the\nlast-but-one element :math:`a^{2^{r-1}}` of the sequence of squares is a\nsquare root of unity modulo :math:`n`.  We can check whether this square\nroot is non-trivial (i.e. not equal to 1 or -1 modulo :math:`n`). If it is\nnon-trivial, then :math:`n` definitely cannot be a prime. If it is trivial\nand equal to 1, we can check the preceding element, and so on. If an\nelement is equal to -1, we cannot say anything, i.e. the test passes\n(:math:`n` is \"probably a prime\").\n \nThis procedure can be summarized like this:\n\n1. Find the largest power of 2 in :math:`n-1` and an odd number :math:`q`\n   such that :math:`n-1=2^rq`.\n2. Select the \"base number\" :math:`x<n`. Compute the sequence\n   :math:`a:=x^q \\bmod n`, :math:`a^2, a^4,\\ldots, a^{2^r}` by repeated\n   squaring modulo :math:`n`. This sequence contains at least two elements\n   since :math:`r\\ge 1`.\n3. If :math:`a=1` or :math:`a=n-1`, the test passes on the base number\n   :math:`x`. Otherwise, the test passes if at least one of the elements of\n   the sequence is equal to :math:`n-1` and fails if none of them are equal\n   to :math:`n-1`. This simplified procedure works because the first element\n   that is equal to 1 *must* be preceded by a -1, or else we would find a\n   nontrivial root of unity.\n\nHere is a more formal definition. An odd integer :math:`n` is called\n*strongly-probably-prime* for base :math:`b` if :math:`b^q:=1 \\bmod n` or\n:math:`b^{q2^i}:=n-1 \\bmod n` for some :math:`i` such that :math:`0\\le i < r`,\nwhere :math:`q` and :math:`r` are such that :math:`q` is odd and\n:math:`n-1 = q2^r`.\n\nA practical application of this procedure needs to select particular\nbase numbers.  It is advantageous (according to\n:cite:`pomerance1980:pseudoprimes` to choose *prime* numbers :math:`b`\nas bases, because for a composite base :math:`b=pq`, if :math:`n` is\na strong pseudoprime for both :math:`p` and :math:`q`, then it is very\nprobable that :math:`n` is a strong pseudoprime also for :math:`b`,\nso composite bases rarely give new information.\n\nAn additional check suggested by :cite:`davenport1992:primality_test_revisited`\nis activated if :math:`r>2` (i.e. if :math:`n:=1\\bmod 8` which is true for\nonly 1/4 of all odd numbers).  If :math:`i\\ge 1` is found such that\n:math:`b^{q2^i}:=n-1\\bmod n`, then :math:`b^{q2^{i-1}}` is a square root\nof -1 modulo :math:`n`. If :math:`n` is prime, there may be only two different\nsquare roots of -1.  Therefore we should store the set of found values\nof roots of -1; if there are more than two such roots, then we will find\nsome roots :math:`s_1`, :math:`s_2` of -1 such that\n:math:`s_1+s_2\\ne 0 \\bmod n`. But :math:`s_1^2-s_2^2:=0 \\bmod n`.\nTherefore :math:`n` is definitely composite, e.g. :math:`\\gcd(s_1+s_2,n)>1`.\nThis check costs very little computational effort but guards against some\nstrong pseudoprimes.\n\nYet another small improvement comes from :cite:`damgard1993:average_case_error`.\nThey found that the strong primality test sometimes (rarely) passes on\ncomposite numbers :math:`n` for more than 1/8 of all bases :math:`x<n`\nif :math:n` is such that either :math:`3n+1` or :math:`8n+1` is a perfect\nsquare, or if :math:`n` is a Carmichael number. Checking Carmichael numbers\nis slow, but it is easy to show that if :math:`n` is a large enough prime\nnumber, then neither :math:`3n+1`, nor :math:`8n+1`, nor any :math:`sn+1`\nwith small integer :math:`s` can be a perfect square.  [If :math:`sn+1=r^2`,\nthen :math:`sn=(r-1)(r+1)`.]  Testing for a perfect square is quick and does\nnot slow down the algorithm. This is however not implemented in yacas because\nit seems that perfect squares are too rare for this improvement to be\nsignificant.\n\nIf an integer is not \"strongly-probably-prime\" for a given base :math:`b`,\nthen it is a composite number.  However, the converse statement is\nfalse, i.e. \"strongly-probably-prime\" numbers can actually be\ncomposite.  Composite strongly-probably-prime numbers for base :math:`b` are\ncalled *strong pseudoprimes* for base :math:`b`. There is a theorem\nthat if :math:`n` is composite, then among all numbers :math:`b` such that\n:math:`1 < b < n`, at most one fourth are such that :math:`n` is a strong\npseudoprime for base :math:`b`.  Therefore if :math:`n` is \nstrongly-probably-prime for many bases, then the probability for :math:`n`\nto be composite is very small.\n\nFor numbers less than :math:`B=34155071728321`, exhaustive [#exhaustive]_\ncomputations have shown that there are no strong\npseudoprimes simultaneously for bases 2, 3, 5, 7, 11, 13 and 17. This\ngives a simple and reliable primality test for integers below :math:`B`.\nIf :math:`n\\ge B`, the Rabin-Miller method consists of checking if\n:math:`n` is strongly-probably-prime for :math:`k` base numbers :math:`b`.\nThe base numbers are chosen to be consecutive \"weak pseudoprimes\" that are\neasy to generate (see below the function :func:`NextPseudoPrime`).\n\n.. [#exhaustive] And surely exhausting.\n\nIn the implemented routine :func:`RabinMiller`, the number of bases :math:`k`\nis chosen to make the probability of erroneously passing the test\n:math:`p < 10^{-25}`. (Note that this is *not* the same as the probability\nto give an incorrect answer, because all numbers that do not pass the\ntest are definitely composite.) The probability for the test to pass\nmistakenly on a given number is found as follows.  Suppose the number\nof bases :math:`k` is fixed. Then the probability for a given composite\nnumber to pass the test is less than :math:`p_f=4^{-k}`. The probability\nfor a given number :math:`n` to be prime is roughly\n:math:`p_p=\\frac{1}{\\ln{n}}` and to be composite\n:math:`p_c=1-\\frac{1}{\\ln{n}}`. Prime numbers never fail the test.\nTherefore, the probability for the test to pass is :math:`p_fp_c+p_p`\nand the probability to pass erroneously is\n\n.. math:: p = \\frac{p_fp_c}{p_fp_c+p_p} < 4^{-k}\\ln(n).\n\nTo make :math:`p<\\epsilon`, it is enough to select\n:math:`k=\\frac{1}{\\ln{4}(\\ln{n}-\\ln{\\epsilon})}`.\n\nBefore calling :func:`MillerRabin`, the function :func:`IsPrime` performs two\nquick checks: first, for :math:`n\\ge4` it checks that :math:`n` is not divisible by\n2 or 3 (all primes larger than 4 must satisfy this); second, for\n:math:`n>257`, it checks that :math:`n` does not contain small prime factors\n:math:`p\\le257`.  This is checked by evaluating the GCD of :math:`n` with the\nprecomputed product of all primes up to 257.  The computation of the\nGCD is quick and saves time in case a small prime factor is present.\n\nThere is also a function :func:`NextPrime` that returns the smallest\nprime number larger than :math:`n`.  This function uses a sequence\n:math:`5,7,11,13,\\ldots` generated by the function :func:`NextPseudoPrime`.\nThis sequence contains numbers not divisible by 2 or 3 (but perhaps\ndivisible by 5,7,...). The function :func:`NextPseudoPrime` is very fast\nbecause it does not perform a full primality test.\n\nThe function :func:`NextPrime` however does check each of these pseudoprimes\nusing :func:`IsPrime` and finds the first prime number.\n\n\nFactorization of integers\n-------------------------\n\nWhen we find from the primality test that an integer :math:`n` is composite,\nwe usually do not obtain any factors of :math:`n`.  Factorization is\nimplemented by functions :func:`Factor` and :func:`Factors`.  Both functions\nuse the same algorithms to find all prime factors of a given integer :math:`n`.\n(Before doing this, the primality checking algorithm is used to detect\nwhether :math:`n` is a prime number.)  Factorization consists of repeatedly\nfinding a factor, i.e. an integer :math:`f` such that :math:`n\\bmod f=0`, and\ndividing :math:`n` by :math:`f`.  (Of course, each fastor :math:`f` needs to be\nfactorized too.)\n\nsmall prime factors\n^^^^^^^^^^^^^^^^^^^\n\nFirst we determine whether the number :math:`n` contains \"small\" prime\nfactors :math:`p\\le257`. A quick test is to find the GCD of :math:`n` and the\nproduct of all primes up to 257: if the GCD is greater than 1, then\n:math:`n` has at least one small prime factor. (The product of primes is\nprecomputed.) If this is the case, the trial division algorithm is\nused: :math:`n` is divided by all prime numbers :math:`p\\le257` until a factor is\nfound. :func:`NextPseudoPrime` is used to generate the sequence of candidate\ndivisors :math:`p`.\n\nchecking for prime powers\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nAfter separating small prime factors, we test whether the number :math:`n`\nis an integer power of a prime number, i.e. whether :math:`n=p^s` for some\nprime number :math:`p` and an integer :math:`s\\ge1`. This is tested by the\nfollowing algorithm. We already know that :math:`n` is not prime and that\n:math:`n` does not contain any small prime factors up to 257. Therefore if\n:math:`n=p^s`, then :math:`p>257` and :math:`2\\le s<s_0=\\frac{\\ln{n}}{\\ln{257}}`.\nIn other words, we only need to look for powers not greater than :math:`s_0.`\nThis number can be approximated by the \"integer logarithm\" of :math:`n` in\nbase 257 (routine ``IntLog(n, 257)``).\n\nNow we need to check whether :math:`n` is of the form :math:`p^s` for\n:math:`s=2,3,\\ldots,s_0`. Note that if for example :math:`n=p^{24}` for some\n:math:`p`, then the square root of :math:`n` will already be an integer,\n:math:`n^\\frac{1}{2}=p^{12}`. Therefore it is enough to test whether\n:math:`n^\\frac{1}{s}` is an integer for all *prime* values of :math:`s` up to\n:math:`s_0`, and then we will definitely discover whether :math:`n` is a power\nof some other integer. The testing is performed using the integer :math:`n`-th\nroot function :func:`IntNthRoot` which quickly computes the integer part of\n:math:`n`-th root of an integer number. If we discover that :math:`n` has an\ninteger root :math:`p` of order :math:`s`, we have to check that :math:`p`\nitself is a prime power (we use the same algorithm recursively). The number\n:math:`n` is a prime power if and only if :math:`p` is itself a prime power.\nIf we find no integer roots of orders :math:`s\\le s_0`, then :math:`n` is not\na prime power.\n\nPollard's rho algorithm\n^^^^^^^^^^^^^^^^^^^^^^^\n\nIf the number :math:`n` is not a prime power, the `Pollard's rho algorithm`_\nis applied :cite:`pollard1975:theory_algebraic_numbers`. The Pollard rho\nalgorithm takes an irreducible polynomial, e.g. :math:`p(x)=x^2+1` and builds\na sequence of integers :math:`x_{k+1}:=p(x_k)\\bmod n`, starting from\n:math:`x_0=2`. For each :math:`k`, the value :math:`x_{2k}-x_k` is attempted\nas possibly containing a common factor with :math:`n`. The GCD of\n:math:`x_{2k}-x_k` with :math:`n` is computed, and if\n:math:`\\gcd(x_{2k}-x_k,n)>1`, then that GCD value divides :math:`n`.\n\n.. _Pollard's rho algorithm: https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm\n\nThe idea behind the rho algorithm is to generate an effectively\nrandom sequence of trial numbers :math:`t_k` that may have a common factor\nwith :math:`n`. The efficiency of this algorithm is determined by the size\nof the smallest factor :math:`p` of :math:`n`. Suppose :math:`p` is the\nsmallest prime factor of :math:`n` and suppose we generate a random sequence\nof integers :math:`t_k` such that :math:`1\\leq t_k<n`. It is clear that, on\nthe average, a fraction :math:`\\frac{1}{p}` of these integers will be divisible\nby :math:`p`. Therefore (if :math:`t_k` are truly random) we should need on\nthe average :math:`p` tries until we find :math:`t_k` which is accidentally\ndivisible by :math:`p`. In practice, of course, we do not use a truly random\nsequence and the number of tries before we find a factor :math:`p` may be\nsignificantly different from :math:`p`. The quadratic polynomial seems to\nhelp reduce the number of tries in most cases.\n\nBut the Pollard \"rho\" algorithm may actually enter an infinite loop\nwhen the sequence :math:`x_k` repeats itself without giving any factors of\n:math:`n`. For example, the unmodified rho algorithm starting from\n:math:`x_0=2` loops on the number 703. The loop is detected by comparing\n:math:`x_{2k}` and :math:`x_k`. When these two quantities become equal to each\nother for the first time, the loop may not yet have occurred so the\nvalue of GCD is set to 1 and the sequence is continued. But when the\nequality of :math:`x_{2k}` and :math:`x_k` occurs many times, it indicates that\nthe algorithm has entered a loop. A solution is to randomly choose a\ndifferent starting number :math:`x_0` when a loop occurs and try factoring\nagain, and keep trying new random starting numbers between 1 and :math:`n`\nuntil a non-looping sequence is found. The current implementation\nstops after 100 restart attempts and prints an error message, \"failed\nto factorize number\".\n\nA better (and faster) integer factoring algorithm needs to be\nimplemented in yacas.\n\noverview of algorithms\n^^^^^^^^^^^^^^^^^^^^^^\n\nModern factoring algorithms are all probabilistic (i.e. they do not\nguarantee a particular finishing time) and fall into three categories:\n\n1. Methods that work well (i.e. quickly) if there is a relatively\n   small factor :math:`p` of :math:`n` (even if :math:`n` itself is large).\n   Pollard's rho algorithm belongs to this category. The fastest in this\n   category is `Lenstra's elliptic curves method`_ (ECM).\n2. Methods that work equally quickly regardless of the size of\n   factors (but slower with larger :math:`n`). These are the continued\n   fractions method and the various sieve methods. The current best\n   is the `General Number Field Sieve`_ (GNFS) but it is quite a\n   complicated algorithm requiring operations with high-order algebraic\n   numbers. The next best one is the `Multiple Polynomial Quadratic\n   Sieve`_ (MPQS).\n3. Methods that are suitable only for numbers of special\n   interesting form, e.g. Fermat numbers :math:`2^{2^k}-1` or generally\n   numbers of the form :math:`r^s+a` where :math:`s` is large but :math:`r`\n   and :math:`a` are very small integers. The best method seems to be the\n   `Special Number Field Sieve`_ which is a faster variant of the GNFS adapted\n   to the problem.\n\n.. _Lenstra's elliptic curves method: https://en.wikipedia.org/wiki/Lenstra_elliptic_curve_factorization\n.. _General Number Field Sieve: https://en.wikipedia.org/wiki/General_number_field_sieve\n.. _Multiple Polynomial Quadratic Sieve: http://www.mersennewiki.org/index.php/Multiple_polynomial_quadratic_sieve\n.. _Special Number Field Sieve: https://en.wikipedia.org/wiki/Special_number_field_sieve\n\nThere is ample literature describing these algorithms.\n\nThe Jacobi symbol\n-----------------\n\nA number :math:`m` is a *quadratic residue modulo* :math:`n` if there exists a\nnumber :math:`k` such that :math:`k^2:=m\\bmod n`.\n\nThe `Legendre symbol`_ :math:`(\\frac{m}{n})` is defined as :math:`+1` if \n:math:`m` is a quadratic residue modulo :math:`n` and :math:`-1` if it is a\nnon-residue. The Legendre symbol is equal to :math:`0` if :math:`\\frac{m}{n}`\nis an integer.\n\n.. _Legendre symbol: https://en.wikipedia.org/wiki/Legendre_symbol\n\nThe `Jacobi symbol` :math:`(\\frac{m}{n})` is defined as the product of the\nLegendre symbols of the prime factors :math:`f_i` of \n:math:`n=f_1^{p_1}\\ldots f_s^{p_s}`\n\n.. math:: \\left(\\frac{m}{n}\\right) := \\left(\\frac{m}{f_1}\\right)^{p_1}\\ldots \\left(\\frac{m}{f}\\right)^{p_s}\n\n(Here we used the same notation :math:`(\\frac{a}{b})` for the Legendre and the\nJacobi symbols; this is confusing but seems to be the current practice.)  The\nJacobi symbol is equal to :math:`0` if :math:`m`, :math:`n` are not mutually\nprime (have a common factor). The Jacobi symbol and the Legendre symbol have\nvalues :math:`+1`, :math:`-1` or :math:`0`.\n\n.. _Jacobi symbol: https://en.wikipedia.org/wiki/Jacobi_symbol\n\nThe Jacobi symbol can be efficiently computed without knowing the full\nfactorization of the number :math:`n`.  The currently used method is based\non the following identities for the Jacobi symbol:\n\n1. :math:`(\\frac{a}{1}) = 1`,\n2. :math:`(\\frac{2}{b}) = (-1)^{\\frac{b^2-1}{8}}`,\n3. :math:`(\\frac{ab}{c}) = (\\frac{a}{c})(\\frac{b}{c})`,\n4. If :math:`a:=b\\bmod c`, then :math:`(\\frac{a}{c})=(\\frac{b}{c})`,\n5. If :math:`a`, :math:`b` are both odd, then\n   :math:`(\\frac{a}{b})=(\\frac{b}{a}) (-1)^\\frac{(a-1)(b-1)}{4}`.\n\nUsing these identities, we can recursively reduce the computation of\nthe Jacobi symbol :math:`(\\frac{a}{b})` to the computation of the Jacobi\nsymbol for numbers that are on the average half as large.  This is similar\nto the fast binary Euclidean algorithm for the computation of the GCD.  The\nnumber of levels of recursion is logarithmic in the arguments :math:`a`,\n:math:`b`.\n\nMore formally, Jacobi symbol :math:`(\\frac{a}{b})` is computed by the following\nalgorithm.  (The number :math:`b` must be an odd positive integer, otherwise\nthe result is undefined.)\n\n1. If :math:`b=1`, return :math:`1` and stop. If :math:`a=0`, return :math:`0`\n   and stop. Otherwise, replace :math:`(\\frac{a}{b})` by\n   :math:`(\\frac{a\\bmod b}{b})` (identity 4).\n2. Find the largest power of :math:`2` that divides :math:`a`. Say, \n   :math:`a=2^{sc}` where :math:`c` is odd.  Replace :math:`(\\frac{a}{b})` by\n   :math:`(\\frac{c}{b})(-1)^\\frac{s(b^2-1)}{8}`\n   (identities 2 and 3).\n3. Now that :math:`c<b`, replace :math:`(\\frac{c}{b})` by \n   :math:`(\\frac{b}{c})(-1)^\\frac{(b-1)(c-1)}{4}` (identity 5).\n4. Continue to step 1.\n\nNote that the arguments :math:`a`, :math:`b` may be very large integers and we\nshould avoid performing multiplications of these numbers.  We can\ncompute :math:`(-1)^\\frac{(b-1)(c-1)}{4}` without multiplications. This\nexpression is equal to :math:`1` if either :math:`b` or :math:`c` is equal to 1\nmod 4; it is equal to :math:`-1` only if both :math:`b` and :math:`c` are equal\nto 3 mod 4. Also, :math:`(-1)^\\frac{b^2-1}{8}` is equal to :math:`1` if either\n:math:`b=1` or :math:`b=7` mod 8, and it is equal to :math:`-1` if :math:`b=3`\nor :math:`b=5` mod 8.  Of course, if :math:`s` is even, none of this needs\nto be computed.\n\n\nInteger partitions\n------------------\n\npartitions of an integer\n^^^^^^^^^^^^^^^^^^^^^^^^\n\nA partition of an integer :math:`n` is a way of writing :math:`n` as the sum of\npositive integers, where the order of these integers is unimportant.\nFor example, there are 3 ways to write the number 3 in this way:\n:math:`3=1+1+1`, :math:`3=1+2`, :math:`3=3`.  The function :func:`PartitionsP`\ncounts the number of such partitions.\n\npartitions of an integer by Rademacher-Hardy-Ramanujan series\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nLarge :math:`n`\n\nThe first algorithm used to compute this function uses the\nRademacher-Hardy-Ramanujan (RHR) theorem and is efficient for large\n:math:`n`.  (See for example [Ahlgren <i>et al.</i> 2001].)  The number of\npartitions :math:`P(n)` is equal to an infinite sum:\n\n.. math:: P(n) = \\frac{1}{\\pi\\sqrt{2}}\\sum_{k=1}^{\\infty}\\sqrt{k}A(k,n)S(k,n),\n\nwhere the functions :math:`A` and :math:`S` are defined as follows:\n\n.. math:: S(k,n) := \\frac{d}{dn} \\frac{\\sinh(\\frac{\\pi}{k}\\sqrt{\\frac{2}{3}(n-\\frac{1}{24})})}{\\sqrt{n-\\frac{1}{24}}}\n\n.. math:: A(k,n) := \\sum_{l=1}^{k} \\delta_{\\gcd(l,k),1}\\exp(-2\\pi i \\frac{ln}{k}+\\pi i B(k,l)),\n\nwhere :math:`\\delta_{x,y}` is the Kronecker delta function (so that the\nsummation goes only over integers :math:`l` which are mutually prime with\n:math:`k`) and :math:`B` is defined by \n\n.. math:: B(k,l) := \\sum_{j=1}^{k-1}\\frac{j}{k}\\left(\\frac{lj}{k}-\\left\\lfloor\\frac{lj}{k}\\right\\rfloor-\\frac{1}{2}\\right).\n\nThe first term of the series gives, at large :math:`n`, the Hardy-Ramanujan\nasymptotic estimate,\n\n.. math:: P(n) \\sim P_0(n) := \\frac{1}{4n\\sqrt{3}}\\exp\\left(\\pi\\sqrt{\\frac{2n}{3}}\\right).\n\nThe absolute value of each term decays quickly, so after :math:`O(\\sqrt{n})`\nterms the series gives an answer that is very close to the integer result.\n\nThere exist estimates of the error of this series, but they are\ncomplicated.  The series is sufficiently well-behaved and it is easier\nto determine the truncation point heuristically.  Each term of the\nseries is either 0 (when all terms in :math:`A(k,n)` happen to cancel) or\nhas a magnitude which is not very much larger than the magnitude of\nthe previous nonzero term.  (But the series is not actually\nmonotonic.)  In the current implementation, the series is truncated\nwhen :math:`|A(k,n)S(n)\\sqrt{k}|` becomes smaller than :math:`0.1` for the\nfirst time; in any case, the maximum number of calculated terms is\n:math:`5+\\frac{\\sqrt{n}}{2}`.  One can show that asymptotically for large\n:math:`n`, the required number of terms is less than\n:math:`\\frac{\\mu}{\\ln{\\mu}}`, where :math:`\\mu:=\\pi\\sqrt{\\frac{2n}{3}}`.\n\n[Ahlgren <i>et al.</i> 2001] mention that there exist explicit\nconstants :math:`B_1` and :math:`B_2` such that\n\n.. math:: |P(n)-\\sum_{k=1}^{B_1\\sqrt{n}}A(k,n))| < B_2n^{-\\frac{1}{4}}.\n\nThe floating-point precision necessary to obtain the integer result\nmust be at least the number of digits in the first term :math:`P_0(n)`, i.e.\n\n.. math:: Prec > \\frac{\\pi\\sqrt{\\frac{2n}{3}}-\\ln(4n\\sqrt{3})}{\\ln(10)}.\n\nHowever, :program:`yacas` currently uses the fixed-point precision model.\nTherefore, the current implementation divides the series by :math:`P_0(n)`\nand computes all terms to :math:`Prec` digits.\n\nThe RHR algorithm requires :math:`O\\left(\\left(\\frac{n}{\\ln(n)}\\right)^\\frac{3}{2}\\right)`\noperations, of which :math:`O(\\frac{n}{\\ln(n)})` are long multiplications at\nprecision :math:`Prec\\sim O(\\sqrt{n})` digits.  The computational cost is\ntherefore :math:`O(\\frac{n}{\\ln(n)}M(\\sqrt{n}))`.\n\npartitions of an integer by recurrence relation\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nSmall :math:`n`\n\nThe second, simpler algorithm involves a recurrence relation\n\n.. math:: P_n = \\sum_{k=1}^n (-1)^{k+1}(P_{n-\\frac{k(3k-1)}{2}}+P_{n-\\frac{k(3k+1)}{2}}).\n\nThe sum can be written out as\n\n.. math:: P_{n-1}+P_{n-2}-P_{n-5}-P_{n-7}+\\ldots,\n\nwhere :math:`1, 2, 5, 7, \\ldots` is the `generalized pentagonal sequence`_\ngenerated by the pairs :math:`\\frac{k(3k-1)}{2}`, :math:`\\frac{k(3k+1)}{2}`\nfor :math:`k=1,2,\\ldots`. The recurrence starts from :math:`P_0=1`,\n:math:`P_1=1`.  (This is implemented as :func:`PartitionsP'recur`.)\n\n.. _generalized pentagonal sequence: https://oeis.org/A001318\n\nThe sum is actually not over all :math:`k` up to :math:`n` but is truncated when\nthe pentagonal sequence grows above :math:`n`.  Therefore, it contains only\n:math:`O(\\sqrt{n})` terms.  However, computing :math:`P_n` using the recurrence\nrelation requires computing and storing :math:`P_k` for all\n:math:`1\\le k\\le n`. No long multiplications are necessary, but the number\nof long additions of numbers with :math:`Prec\\sim O(\\sqrt{n})` digits is\n:math:`O(n^\\frac{3}{2})`. Therefore the computational cost is :math:`O(n^2)`.\nThis is asymptotically slower than the RHR algorithm even if a slow\n:math:`O(n^2)` multiplication is used. With internal yacas math, the recurrence\nrelation is faster for :math:`n<300` or so, and for larger :math:`n` the RHR\nalgorithm is faster.\n\n\nMiscellaneous functions\n-----------------------\n\ndivisors\n^^^^^^^^\n\nThe function :func:`Divisors` currently returns the number of divisors of\ninteger, while :func:`DivisorsSum` returns the sum of these divisors.  (The\ncurrent algorithms need to factor the number.) The following theorem\nis used:\n\nLet :math:`p_1^{k_1}\\ldots p_r^{k_r}` be the prime factorization of :math:`n`,\nwhere :math:`r` is the number of prime factors and :math:`k_i` is the\nmultiplicity of the :math:`i`-th factor. Then \n\n.. math::\n\n   \\mathrm{Divisors}(n) =(k_1+1)\\ldots(k_r+1)\n\n.. math::\n   \\mathrm{DivisorsSum}(n) = \\frac{p_1^{k_1+1} -1}{p_1-1}\\ldots\\frac{p_r^{k_r+1} -1}{p_r-1}\n\nproper divisors\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nThe functions :func:`ProperDivisors` and :func:`ProperDivisorsSum` are\nfunctions that do the same as the above functions, except they do not consider\nthe number :math:`n` as a divisor for itself.  These functions are defined\nby:\n\n.. math::\n\n   \\mathrm{ProperDivisors}(n) := \\mathrm{Divisors}(n) - 1;\n\n.. math::\n   \\mathrm{ProperDivisorsSum}(n) := \\mathrm{DivisorsSum}(n) - n;\n\nAnother number-theoretic function is :func:`Moebius`, defined as follows:\n:math:`\\mathrm{Moebius}(n)=(-1)^r` if no factors of :math:`n` are repeated,\n:math:`\\mathrm{Moebius}(n)=0` if some factors are repeated, and\n:math:`\\mathrm{Moebius}(n)=1` if :math:`n = 1`. This again requires to factor\nthe number :math:`n` completely and investigate the properties of its prime\nfactors. From the definition, it can be seen that if :math:`n` is prime,\nthen :math:`\\mathrm{Moebius}(n) = -1`. The predicate :func:`IsSquareFree` then\nreducess to :math:`\\mathrm{Moebius}(n)\\ne0`, which means that no factors of\n:math:`n` are repeated.\n\n\nGaussian integers\n-----------------\n\nA *Gaussian integer* is a complex number of the form :math:`z =\na+b*\\imath`, where :math:`a` and :math:`b` are ordinary (rational) integers.\n[#rational_integers]_ The ring of Gaussian integers is usually denoted by\n:math:`\\mathbb{Z}[\\imath]` in the mathematical literature. It is an example\nof a ring of algebraic integers.\n\n.. [#rational_integers] To distinguish ordinary integers from Gaussian\n   integers, the ordinary integers (with no imaginary part) are called\n   *rational integers*.\n\nThe function :func:`GaussianNorm` computes the norm :math:`N(z)=a^2+b^2` of\n:math:`z`. The norm plays a fundamental role in the arithmetic of Gaussian\nintegers, since it has the multiplicative property\n\n.. math:: N(zw) = N(z)N(w).\n\nA unit of a ring is an element that divides any other element of the\nring.  There are four units in the Gaussian integers: :math:`1`, :math:`-1`,\n:math:`\\imath`, :math:`-\\imath`. They are exactly the Gaussian integers whose\nnorm is :math:`1`. The predicate :func:`IsGaussianUnit` tests for a Gaussian\nunit.\n\nTwo Gaussian integers :math:`z` and :math:`w` are *associated* is\n:math:`\\frac{z}{w}` is a unit. For example, :math:`2+\\imath` and\n:math:`-1+2\\imath` are associated.\n\nA Gaussian integer is called *prime* if it is only divisible by the\nunits and by its associates. It can be shown that the primes in the\nring of Gaussian integers are:\n\n1. :math:`1+\\imath` and its associates.\n2. The rational (ordinary) primes of the form :math:`4n+3`.\n3. The factors :math:`a+b\\imath` of rational primes :math:`p` of the form\n   :math:`p=4n+1`, whose norm is :math:`p=a^2+b^2`.\n\nFor example, :math:`7` is prime as a Gaussian integer, while :math:`5` is not,\nsince :math:`5 = (2+\\imath)(2-\\imath)`.  Here :math:`2+\\imath` is a Gaussian\nprime.\n\nFactors\n^^^^^^^\n\nThe ring of Gaussian integers is an example of an Euclidean ring,\ni.e. a ring where there is a division algorithm.  This makes it\npossible to compute the greatest common divisor using Euclid's\nalgorithm. This is what the function :func:GaussianGcd` computes.\n\nAs a consequence, one can prove a version of the fundamental theorem\nof arithmetic for this ring: The expression of a Gaussian integer as a\nproduct of primes is unique, apart from the order of primes, the\npresence of units, and the ambiguities between associated primes.\n\nThe function :func:`GaussianFactors` finds this expression of a Gaussian\ninteger :math:`z` as the product of Gaussian primes, and returns the result\nas a list of pairs :math:`(p,e)`, where :math:`p` is a Gaussian prime and\n:math:`e` is the corresponding exponent.  To do that, an auxiliary function\ncalled :func:`GaussianFactorPrime` is used. This function finds a factor of a\nrational prime of the form :math:`4n+1`. We compute :math:`a := (2n)!\\bmod p`.\nBy Wilson's theorem :math:`a^2` is congruent to :math:`-1` (mod :math:`p`),\nand it follows that :math:`p` divides :math:`(a+\\imath)(a-\\imath)=a^2+1` in\nthe Gaussian integers. The desired factor is then the :func:`GaussianGcd` of\n:math:`a+\\imath` and :math:`p`. If the result is :math:`a+b\\imath`, then\n:math:`p=a^2+b^2`.\n\nIf :math:`z` is a rational (i.e. real) integer, we factor :math:`z` in the\nGaussian integers by first factoring it in the rational integers, and\nafter that by factoring each of the integer prime factors in the\nGaussian integers.\n \nIf :math:`z` is not a rational integer, we find its possible Gaussian prime\nfactors by first factoring its norm :math:`N(z)` and then computing the\nexponent of each of the factors of :math:`N(z)` in the decomposition of\n:math:`z`.\n\nA simple factorization algorithm for univariate polynomials\n-----------------------------------------------------------\n\nThis section discusses factoring polynomials using arithmetic modulo\nprime numbers. Information was used from\n:cite:`knuth1997:acp_seminumerical_algorithms` and\n:cite:`davenport1988:computer_algebra`.\n\nA simple factorization algorithm is developed for univariate\npolynomials. This algorithm is implemented as the function\n:func:`BinaryFactors`. The algorithm was named the binary factoring\nalgorithm since it determines factors to a polynomial modulo :math:`2^n` for\nsuccessive values of :math:`n`, effectively adding one binary digit to the\nsolution in each iteration. No reference to this algorithm has been\nfound so far in literature.\n\nBerlekamp showed that polynomials can be efficiently factored when\narithmetic is done modulo a prime. The `Berlekamp algorithm`_ is only\nefficient for small primes, but after that `Hensel lifting`_ can be used\nto determine the factors modulo larger numbers.\n\n.. _Berlekamp algorithm: https://en.wikipedia.org/wiki/Berlekamp%27s_algorithm\n.. _Hensel lifting: https://en.wikipedia.org/wiki/Hensel%27s_lemma\n\nThe algorithm presented here is similar in approach to applying the\nBerlekamp algorithm to factor modulo a small prime, and then factoring\nmodulo powers of this prime (using the solutions found modulo the\nsmall prime by the Berlekamp algorithm) by applying Hensel lifting.\nHowever it is simpler in set up. It factors modulo 2, by trying all\npossible factors modulo 2 (two possibilities, if the polynomial is\nmonic). This performs the same action usually left to the Berlekamp\nstep. After that, given a solution modulo :math:`2^n`, it will test for a\nsolution :math:`f_i` modulo :math:`2^n` if :math:`f_i` or :math:`f_i + 2^n`\nare a solution modulo :math:`2^{n+1}`.\n\nThis scheme raises the precision of the solution with one digit in\nbinary representation. This is similar to the linear Hensel lifting\nalgorithm, which factors modulo :math:`p^n` for some prime :math:`p`, where\n:math:`n` increases by one after each iteration. There is also a quadratic\nversion of Hensel lifting which factors modulo :math:`p^{2^n}`, in effect\ndoubling the number of digits (in :math:`p`-adic expansion) of the solution\nafter each iteration. However, according to Davenport, the quadratic\nalgorithm is not necessarily faster.\n\nThe algorithm here thus should be equivalent in complexity to Hensel\nlifting linear version. This has not been verified yet.\n\n\nModular arithmetic\n------------------\n\nThis section copies some definitions and rules from <I>The Art of\nComputer Programming, Volume 1, Fundamental Algorithms </I> regarding\narithmetic modulo an integer.\n\nArithmetic modulo an integer :math:`p` requires performing the arithmetic\noperation and afterwards determining that integer modulo :math:`p`. A number\n:math:`x` can be written as\n\n.. math:: x=qp+r\n\nwhere :math:`q` is called the quotient, and :math:`r` remainder.  There is some\nliberty in the range one chooses :math:`r` to be in. If :math:`r` is an integer\nin the range :math:`0,1,\\ldots,p-1` then it is the *modulo*,\n:math:`r = x \\bmod p`.\n\nWhen :math:`x\\bmod p = y\\bmod p`, the notation :math:`x=y\\pmod p` is used. All\narithmetic calculations are done modulo an integer :math:`p` in that case.\n\nFor calculations modulo some :math:`p` the following rules hold:\n\n* If :math:`a=b\\pmod p` and :math:`x=y\\pmod p`, then :math:`ax=by\\pmod p`,\n  :math:`a+x=b+y\\pmod p`, and :math:`a-x=b-y\\pmod p`.  This means that for\n  instance also :math:`x^n\\bmod p = (x\\bmod p)^n\\bmod p`.\n* Two numbers :math:`x` and :math:`y` are *relatively prime* if they don't\n  share a common factor, that is, if their greatest common denominator\n  is one, :math:`\\gcd(x,y)=1`.\n* If :math:`ax=by\\pmod p` and if :math:`a=b\\pmod p`, and if :math:`a` and \n  :math:`p` are relatively prime, then :math:`x=y\\pmod p`.  This is useful\n  for dividing out common factors.\n* :math:`a=b\\pmod p` if and only if :math:`an=bn\\pmod np` when :math:`n\\ne0`.\n  Also, if :math:`r` and :math:`s` are relatively prime, then\n  :math:`a=b\\pmod rs` only if :math:`a=b\\pmod r` and :math:`a=b\\pmod s`.\n  These rules are useful when the modulus is changed.\n\nFor polynomials :math:`v_1(x)` and :math:`v_2(x)` it further holds that\n\n.. math:: (v_1(x)+v_2(x))^p = v_1(x)^p + v_2(x)^p\\pmod p\n\nThis follows by writing out the expression, noting that the binomial\ncoefficients that result are multiples of :math:`p`, and thus their value\nmodulo :math:`p` is zero (:math:`p` divides these coefficients), so only the\ntwo terms on the right hand side remain.\n\nSome corollaries\n^^^^^^^^^^^^^^^^\n\nOne corollary of the rules for calculations modulo an integer is\n`Fermat's little theorem`_: if :math:`p` is a prime number then\n:math:`a^p=a\\pmod p` for all integers :math:`a` (for a proof, see Knuth).\n\n.. _Fermat's little theorem: https://en.wikipedia.org/wiki/Fermat%27s_little_theorem\n\nAn interesting corollary to this is that, for some prime integer :math:`p`:\n\n.. math:: v(x)^p = v(x^p)\\pmod p.\n\nThis follows from writing it out and using Fermat's little theorem to replace\n:math:`a^p` with :math:`a` where appropriate (the coefficients to the\npolynomial when written out, on the left hand side).\n\nFactoring using modular arithmetic\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe task is to factor a polynomial \n\n.. math:: p(x) = a_nx^n + \\ldots + a_0\n\ninto a form \n\n.. math p(x) = Cg(x)f_1(x)^p_1f_2(x)^p_2\\ldots f_m(x)^p_m\n\nWhere :math:`f_i(x)` are irreducible polynomials of the form:\n\n.. math:: f_i(x) = x+c_i\n\nThe part that could not be factorized is returned as :math:`g(x)`,\nwith a possible constant factor :math:`C`.\n\nThe factors :math:`f_i(x)` and :math:`g(x)` are determined uniquely by\nrequiring them to be monic. The constant :math:`C` accounts for a common factor.\n\nThe :math:`c_i` constants in the resulting solutions :math:`f_i(x)` can be \nrational numbers (or even complex numbers, if Gaussian integers\nare used).\n\nPreparing the polynomial for factorization\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe final factoring algorithm needs the input polynomial to be monic\nwith integer coefficients (a polynomial is monic if its leading\ncoefficient is one). Given a non-monic polynomial with rational\ncoefficients, the following steps are performed:\n\nConvert polynomial with rational coefficients to polynomial with integer coefficients\n\nFirst the least common multiple :math:`lcm` of the denominators of the\ncoefficients :math:`p(x)` has to be found, and the polynomial is multiplied\nby this number.  Afterwards, the :math:`C` constant in the result should\nhave a factor :math:`\\frac{1}{lcm}`.\n\nThe polynomial now only has integer coefficients.\n\n\nConvert polynomial to a monic polynomial\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe next step is to convert the polynomial to one where the leading\ncoefficient is one. In order to do so, following \"Davenport\", the\nfollowing steps have to be taken:\n\n1. Multiply the polynomial by :math:`a_n^{n-1}`\n2. Perform the substitution :math:`x=\\frac{y}{a_n}`\n\nThe polynomial is now a monic polynomial in :math:`y`.\n\nAfter factoring, the irreducible factors of :math:`p(x)`  can be obtained by\nmultiplying :math:`C` with :math:`\\frac{1}{a_n^{n-1}}`, and replacing\n:math:`y` with :math:`a_nx`. The irreducible solutions :math:`a_nx+c_i`\ncan be replaced by :math:`x+\\frac{c_i}{a_i}` after multiplying :math:`C`\nby :math:`a_n`, converting the factors to monic factors.\n\nAfter the steps described here the polynomial is now monic with\ninteger coefficients, and the factorization of this polynomial can be\nused to determine the factors of the original polynomial :math:`p(x)`.\n\n\nDefinition of division of polynomials\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nTo factor a polynomial a division operation for polynomials modulo\nsome integer is needed. This algorithm needs to return a quotient\n:math:`q(x)` and remainder :math:`r(x)` such that:\n\n.. math:: p(x) = q(r)d(x) + r(x)\\pmod p\n\nfor some polymomial :math:`d(x)` to be divided by, modulo some integer\n:math:`p`. :math:`d(x)` is said to divide :math:`p(x)` (modulo :math:`p`)\nif :math:`r(x)` is zero.  It is then a factor modulo :math:`p`.\n\nFor binary factoring algorithm it is important that if some monic\n:math:`d(x)` divides :math:`p(x)`, then it also divides :math:`p(x)` modulo\nsome integer :math:`p`.\n\nDefine :math:`\\mathrm{deg}(f(x))` to be the `degree`_ of :math:`f(x)` and\n:math:`\\mathrm{lc}(f(x))` to be the leading coefficient of :math:`f(x)`.\nThen, if :math:`\\mathrm{deg}(p(x))\\ge \\mathrm{deg}(d(x))`, one\ncan compute an integer :math:`s` such that\n\n.. _degree: https://en.wikipedia.org/wiki/Degree_of_a_polynomial\n\n.. math:: \\mathrm{lc}(d(x))s = lc(p(x)\\pmod p\n\nIf :math:`p` is prime, then \n\n.. math:: s = \\mathrm{lc}(p(x))\\mathrm{lc}(d(x))^{p-2}\\bmod p\n\nBecause :math:`a^{p-1} = 1\\pmod p` for any :math:`a`. If :math:`p` is not\nprime but :math:`d(x)` is monic (and thus :math:`\\mathrm{lc}(d(x)) = 1`,\n\n.. math:: s = \\mathrm{lc}(p(x))\n\nThis identity can also be used when dividing in general (not modulo\nsome integer), since the divisor is monic.\n\nThe quotient can then be updated by adding a term:\n\n.. math:: term = sx^{\\mathrm{deg}(p(x))-\\mathrm{deg}(d(x))}\n\nand updating the polynomial to be divided, :math:`p(x)`, by subtracting\n:math:`d(x)term`. The resulting polynomial to be divided now has a degree\none smaller than the previous.\n\nWhen the degree of :math:`p(x)` is less than the degree of :math:`d(x)` it is\nreturned as the remainder.\n\nA full division algorithm for arbitrary integer :math:`p>1` with\n:math:`\\mathrm{lc}(d(x)) = 1` would thus look like::\n\n\tdivide(p(x),d(x),p)\n\t   q(x) = 0\n\t   r(x) = p(x)\n\t   while (deg(r(x)) >= deg(d(x)))\n\t      s = lc(r(x))\n\t      term = s*x^(deg(r(x))-deg(d(x)))\n\t      q(x) = q(x) + term\n\t      r(x) = r(x) - term*d(x) mod p\n\t   return (q(x),r(x))\n\nThe reason we can get away with factoring modulo :math:`2^n` as opposed to\nfactoring modulo some prime :math:`p` in later sections is that the divisor\n:math:`d(x)` is monic. Its leading coefficient is one and thus :math:`q(x)` and\n:math:`r(x)` can be uniquely determined. If :math:`p` is not prime and\n:math:`\\mathrm{lc}(d(x))` is not equal to one, there might be multiple\ncombinations for which :math:`p(x) = q(x)d(x)+r(x)`, and we are interested\nin the combinations where :math:`r(x)` is zero. This can be costly to determine\nunless :math:`(q(x),r(x))` is unique.  This is the case here because we are\nfactoring a monic polynomial, and are thus only interested in cases where\n:math:`\\mathrm{lc}(d(x)) = 1`.\n\n\nDetermining possible factors modulo 2\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nWe start with a polynomial :math:`p(x)` which is monic and has integer\ncoefficients.\n\nIt will be factored into a form:\n\n.. math:: p(x) = g(x)f_1(x)^{p_1}f_2(x)^{p_2}\\ldots f_m(x)^{p_m}\n\nwhere all factors :math:`f_i(x)` are monic also.\n\nThe algorithm starts by setting up a test polynomial, :math:`p_{test}(x)`\nwhich divides :math:`p(x)`, but has the property that\n\n.. math:: p_{test}(x) = g(x)f_1(x)f_2(x)\\ldots f_m(x)\n\nSuch a polynomial is said to be *square-free*.  It has the same\nfactors as the original polynomial, but the original might have\nmultiple of each factor, where :math:`p_{test}(x)` does not.\n\nThe square-free part of a polynomial can be obtained as follows:\n\n.. math:: p_{test}(x) = \\frac{p(x)}{\\gcd(p(x),\\frac{d}{dx}p(x))}\n\nIt can be seen by simply writing this out that :math:`p(x)` and\n:math:`\\frac{d}{dx}p(x)` will have factors :math:`f_i(x)^{p_i-1}` in common.\nthese can thus be divided out.\n\nIt is not a requirement of the algorithm that the algorithm being\nworked with is square-free, but it speeds up computations to work with\nthe square-free part of the polynomial if the only thing sought after\nis the set of factors. The multiplicity of the factors can be\ndetermined using the original :math:`p(x)`.\n\nBinary factoring then proceeds by trying to find potential solutions\nmodulo :math:`p=2` first. There can only be two such solutions: :math:`x+0`\nand :math:`x+1`.\n\nA list of possible solutions :math:`L` is set up with potential solutions.\n\n\nDetermining factors modulo :math:`2^n` given a factorization modulo 2\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nAt this point there is a list :math:`L` with solutions modulo :math:`2^n` for\nsome :math:`n`. The solutions will be of the form: :math:`x+a`. The first step\nis to determine if any of the elements in :math:`L` divides :math:`p(x)` (not\nmodulo any integer).  Since :math:`x+a` divides :math:`p_{test}(x)` modulo\n:math:`2^n`, both :math:`x+a` and :math:`x+a-2^n` have to be checked.\n\nIf an element in :math:`L` divides :math:`p_{test}(x)`, :math:`p_{test}(x)`\nis divided by it, and a loop is entered to test how often it divides\n:math:`p(x)` to determine the multiplicity :math:`p_i` of the factor.\nThe found factor :math:`f_i(x) = x+c_i` is added as a combination\n:math:`(x+c_i, p_i)`. :math:`p(x)` is divided by :math:`f_i(x)^p_i`.\n\nAt this point there is a list :math:`L` of factors that divide\n:math:`p_{test}(x)` modulo :math:`2^n`. This implies that for each of the\nelements :math:`u` in :math:`L`, either :math:`u` or :math:`u+2^n` should\ndivide :math:`p_{test}(x)` modulo :math:`2^{n+1}`. The following step is thus\nto set up a new list with new elements that divide :math:`p_{test}(x)`\nmodulo :math:`2^{n+1}`.\n\nThe loop is re-entered, this time doing the calculation modulo\n:math:`2^{n+1}` instead of modulo :math:`2^n`.\n\nThe loop is terminated if the number of factors found equals\n:math:`\\mathrm{deg}(p_{test}(x))`, or if :math:`2^n` is larger than the\nsmallest non-zero coefficient of :math:`p_test(x)` as this smallest non-zero\ncoefficient is the product of all the smallest non-zero coefficients of the\nfactors, or if the list of potential factors is zero.\n\nThe polynomial :math:`p(x)` can not be factored any further, and is added as\na factor :math:`(p(x), 1)`.\n\nThe function :func:`BinaryFactors`, yields the following interaction in yacas::\n\n  In> BinaryFactors((x+1)^4*(x-3)^2)\n  Out> {{x-3,2},{x+1,4}}\n  In> BinaryFactors((x-1/5)*(2*x+1/3))\n  Out> {{2,1},{x-1/5,1},{x+1/6,1}}\n  In> BinaryFactors((x-1123125)*(2*x+123233))\n  Out> {{2,1},{x-1123125,1},{x+123233/2,1}}\n\nThe binary factoring algorithm starts with a factorization modulo 2,\nand then each time tries to guess the next bit of the solution,\nmaintaining a list of potential solutions.  This list can grow\nexponentially in certain instances.  For instance, factoring\n:math:`(x-a)(x-2a)(x-3a)\\ldots(x-na)` implies a that the roots have common\nfactors. There are inputs where the number of potential solutions\n(almost) doubles with each iteration.  For these inputs the algorithm\nbecomes exponential. The worst-case performance is therefore\nexponential. The list of potential solutions while iterating will\ncontain a lot of false roots in that case.\n\nEfficiently deciding if a polynomial divides another\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nGiven the polynomial :math:`p(x)`, and a potential divisor\n\n.. math:: f_i(x) = x-p\n\nmodulo some :math:`q=2^n` an expression for the remainder after division\nis\n\n.. math:: \\mathrm{rem}(p)=\\sum_{i=0}^n a_ip^i\n\nFor the initial solutions modulo 2, where the possible solutions are\n:math:`x` and :math:`x-1`. For :math:`p=0`, :math:`\\mathrm{rem}(0) = a_0`.\nFor :math:`p=1`, :math:`\\mathrm{rem}(1) = \\sum_{i=0}^na_i`.\n\nGiven a solution :math:`x-p` modulo :math:`q=2^n`, we consider the possible\nsolutions :math:`x-p\\bmod 2^{n+1}` and :math:`x-(p+2^n)\\bmod 2^{n+1}`.\n\n:math:`x-p` is a possible solution if :math:`\\mathrm{rem}(p)\\bmod 2^{n+1} = 0`.\n\n:math:`x-(p+q)` is a possible solution if \n:math:`\\mathrm{rem}(p+q)\\bmod 2^{n+1} = 0`. Expanding\n:math:`\\mathrm{rem}(p+q)\\bmod 2q` yields:\n\n.. math:: \\mathrm{rem}(p+q) = \\mathrm{rem}(p) + \\mathrm{extra}(p,q)\\pmod{2q}\n\nWhen expanding this expression, some terms grouped under\n:math:`\\mathrm{extra}(p,q)` have factors like :math:`2q` or :math:`q^2`.\nSince :math:`q=2^n`, these terms vanish if the calculation is done modulo\n:math:`2^{n+1}`.\n\nThe expression for :math:`\\mathrm{extra}(p,q)` then becomes\n\n.. math:: \\mathrm{extra}(p,q) = q\\sum_{i=1}^{\\frac{n}{2}} (2i-1)a(2i)p^{2i-2}\n\nAn efficient approach to determining if :math:`x-p` or :math:`x-(p+q)` divides\n:math:`p(x)` modulo :math:`2^{n+1}` is then to first calculate\n:math:`\\mathrm{rem}(p)\\bmod 2q`. If this is zero, :math:`x-p` divides\n:math:`p(x)`. In addition, if\n:math:`\\mathrm{rem}(p)+\\mathrm{extra}(p,q)\\bmod 2q` is zero, :math:`x-(p+q)`\nis a potential candidate.\n\nOther efficiencies are derived from the fact that the operations are\ndone in binary. Eg. if :math:`q=2^n`, then :math:`q_{next}=2^{n+1} = 2q = q<<1`\nis used in the next iteration. Also, calculations modulo :math:`2^n` are\nequivalent to performing a bitwise and with :math:`2^n-1`. These operations\ncan in general be performed efficiently on todays hardware which is\nbased on binary representations.\n\n\nExtending the algorithm\n^^^^^^^^^^^^^^^^^^^^^^^\n\nOnly univariate polynomials with rational coefficients have been\nconsidered so far. This could be extended to allow for roots that are\ncomplex numbers :math:`a+b\\imath` where both :math:`a` and :math:`b` are\nrational numbers.\n\nFor this to work the division algorithm would have to be extended to\nhandle complex numbers with integer :math:`a` and :math:`b` modulo some\ninteger, and the initial setup of the potential solutions would have to be\nextended to try :math:`x+1+\\imath` and :math:`x+\\imath` also. The step\nwhere new potential solutions modulo :math:`2^{n+1}` are determined should\nthen also test for :math:`x+2^n\\imath` and :math:`x+2^n+2^n\\imath`.\n\nThe same extension could be made for multivariate polynomials,\nalthough setting up the initial irreducible polynomials that divide\n:math:`p_{test}(x)` modulo 2 might become expensive if done on a polynomial\nwith many variables (:math:`2^{2^m-1}` trials for :math:`m` variables).\n\nLastly, polynomials with real-valued coefficients *could* be\nfactored, if the coefficients were first converted to rational\nnumbers. However, for real-valued coefficients there exist other\nmethods (Sturm sequences).\n\nNewton iteration\n^^^^^^^^^^^^^^^^\n\nWhat the :func:`BinaryFactor` algorithm effectively does is finding a set of\npotential solutions modulo :math:`2^{n+1}` when given a set of potential\nsolutions modulo :math:`2^n`.  There is a better algorithm that does\nsomething similar: Hensel lifting. Hensel lifting is a generalized\nform of Newton iteration, where given a factorization modulo :math:`p`, each\niteration returns a factorization modulo :math:`p^2`.\n\nNewton iteration is based on the following idea: when one takes a\nTaylor series expansion of a function:\n\n.. math:: f(x_0+dx) := f(x_0) + (\\frac{d}{dx}f(x_0))dx +\\ldots\n\nNewton iteration then proceeds by taking only the first two terms in\nthis series, the constant plus the constant times :math:`dx`. Given some\ngood initial value :math:`x_0`, the function will is assumed to be close to\na root, and the function is assumed to be almost linear, hence this\napproximation.  Under these assumptions, if we want :math:`f(x_0+dx)` to be\nzero,\n\n.. math:: f(x_0+dx) = f(x_0) + (\\frac{d}{dx}f(x_0))dx = 0\n\nThis yields:\n\n.. math:: dx := -\\frac{f(x_0)}{\\frac{d}{dx}f(x_0)} = 0\n\nAnd thus a next, better, approximation for the root is\n\n.. math:: x_1=x_0-\\frac{f(x_0)}{\\frac{d}{dx}f(x_0)},\n\nor more general:\n\n.. math:: x_{n+1}=x_n-\\frac{f(x_n)}{\\frac{d}{dx}f(x_n)}.\n\nIf the root has multiplicity one, a Newton iteration can converge\n*quadratically*, meaning the number of decimals precision for\neach iteration doubles.\n\nAs an example, we can try to find a root of :math:`\\sin x` near\n:math:`3`, which should converge to :math:`\\pi`.\n\nSetting precision to 30 digits,::\n\n  In> Builtin'Precision'Set(30)\n  Out> True;\n\nWe first set up a function :math:`dx(x)`::\n\n  In> dx(x):=Eval(-Sin(x)/(D(x)Sin(x)))\n  Out> True;\n\nAnd we start with a good initial approximation to :math:`\\pi`, namely\n:math:`3`. Note we should set ``x`` *after* we set ``dx(x)``, as the right\nhand side of the function definition is evaluated. We could also have\nused a different parameter name for the definition of the function\n:math:`dx(x)`::\n\n  In> x:=3\n  Out> 3;\n\nWe can now start the iteration::\n\n  In> x:=N(x+dx(x))\n  Out> 3.142546543074277805295635410534;\n  In> x:=N(x+dx(x))\n  Out> 3.14159265330047681544988577172;\n  In> x:=N(x+dx(x))\n  Out> 3.141592653589793238462643383287;\n  In> x:=N(x+dx(x))\n  Out> 3.14159265358979323846264338328;\n  In> x:=N(x+dx(x))\n  Out> 3.14159265358979323846264338328;\n\nAs shown, in this example the iteration converges quite quickly.\n\nFinding roots of multiple equations in multiple variables using Newton iteration\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nOne generalization, mentioned in W.H. Press et al., <i>NUMERICAL\nRECIPES in C, The Art of Scientific computing</i> is finding roots for\nmultiple functions in multiple variables.\n\nGiven :math:`N` functions in :math:`N` variables, we want to solve\n\n.. math:: f_i(x_1,\\ldots,x_N) = 0\n\nfor :math:`i = 1,\\ldots N`. If de denote by :math:`X` the vector \n\n.. math:: X := (x_1,x_2,\\ldots,x_N)\n\nand by :math:`dX` the delta vector, then one can write\n\n.. math:: f_i(X+dX) = f_i(X)+\\sum_{j=1}^N\\frac{d}{dx_j}f_i(X)dx_j\n\nSetting :math:`f_i(X+dX)` to zero, one obtains\n\n\\sum_{j=1}^Na_{ij}dx_j = b_i\n\nwhere\n\n.. math:: a_{ij} := \\frac{d}{dx_j}f_i(X)\n\nand\n\n.. math:: b_i := -f_i(X)\n\nSo the generalization is to first initialize :math:`X` to a good initial\nvalue, calculate the matrix elements :math:`a_{ij}` and the vector :math:`b_i`,\nand then to proceed to calculate :math:`dX` by solving the matrix equation,\nand calculating\n\n.. math:: X_{i+1} = X_i + dX_i\n\nIn the case of one function with one variable, the summation reduces\nto one term, so this linear set of equations was a lot simpler in that\ncase. In this case we will have to solve this set of linear equations\nin each iteration.\n\nAs an example, suppose we want to find the zeroes for the following\ntwo functions:\n\n.. math:: f_1(a,x) := \\sin(ax)\n\nand\n\n.. math:: f_2(a,x) := a-2\n\nIt is clear that the solution to this is :math:`a=2` and\n:math:`x:=N\\frac{\\pi}{2}` for any integer value :math:`N`.\n\nWe will do calculations with precision 30::\n\n  In> Builtin'Precision'Set(30)\n  Out> True;\n\nAnd set up a vector of functions :math:`(f_1(X),f_2(X))`\nwhere :math:`X:=(a,x)`::\n\n  In> f(a,x):={Sin(a*x),a-2}\n  Out> True;\n\nNow we set up a function ``matrix(a,x)`` which returns the\nmatrix :math:`a_{ij}`::\n\n  In> matrix(a,x):=Eval({D(a)f(a,x),D(x)f(a,x)})\n  Out> True;\n\nWe now set up some initial values::\n\n  In> {a,x}:={1.5,1.5}\n  Out> {1.5,1.5};\n\n\nThe iteration converges a lot slower for this example, so we\nwill loop 100 times::\n\n  In> For(ii:=1,ii<100,ii++)[{a,x}:={a,x}+\\\n        N(SolveMatrix(matrix(a,x),-f(a,x)));]\n  Out> True;\n  In> {a,x}\n  Out> {2.,0.059667311457823162437151576236};\n\n\nThe value for :math:`a` has already been found. Iterating a\nfew more times::\n\n  In> For(ii:=1,ii<100,ii++)[{a,x}:={a,x}+\\\n        N(SolveMatrix(matrix(a,x),-f(a,x)));]\n  Out> True;\n  In> {a,x}\n  Out> {2.,-0.042792753588155918852832259721};\n  In> For(ii:=1,ii<100,ii++)[{a,x}:={a,x}+\\\n\t   N(SolveMatrix(matrix(a,x),-f(a,x)));]\n  Out> True;\n  In> {a,x}\n  Out> {2.,0.035119151349413516969586788023};\n\nthe value for :math:`x` converges a lot slower this time, and to the\nuninteresting value of zero (a rather trivial zero of this set of\nfunctions).  In fact for all integer values :math:`N` the value\n:math:`\\frac{N\\pi}{2}` is a solution.  Trying various initial values will\nfind them.\n\n\nNewton iteration on polynomials\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nvon zur Gathen *et al.*, :cite:`gathen1999:modern_computer_algebra` discusses\ntaking the inverse of a polynomial using Newton iteration.  The task is,\ngiven a polynomial :math:`f(x)`, to find a polynomial :math:`g(x)` such that\n:math:`f(x) = \\frac{1}{g(x)}`, modulo some power in :math:`x`.  This implies\nthat we want to find a polynomial :math:`g` for which:\n\n.. math:: h(g) = \\frac{1}{g}-f = 0\n\nApplying a Newton iteration step :math:`g_{i+1} = g_i -\n\\frac{h(g_i)}{\\frac{d}{dg}h(g_i)}` to this expression yields:\n\n.. math:: g_{i+1} = 2g_i - f(g_i)^2\n\nvon zur Gathen then proves by induction that for :math:`f(x)` monic, and\nthus :math:`f(0)=1`, given initial value :math:`g_0(x) = 1`, that\n\n.. math:: fg_i=1\\pmod{x^{2^i}}\n\nExample:\n\nsuppose we want to find the polynomial :math:`g(x)` up to the 7-th degree\nfor which :math:`f(x)g(x) = 1\\pmod{x^8}`, for the function\n\n.. math:: f(x):=1+x+\\frac{1}{2}x^2+\\frac{1}{6}x^3+\\frac{1}{24}x^4\n\nFirst we define the function f::\n\n  In> f:=1+x+x^2/2+x^3/6+x^4/24\n  Out> x+x^2/2+x^3/6+x^4/24+1\n\nAnd initialize :math:`g` and :math:`i`::\n\n  In> g:=1\n  Out> 1\n  In> i:=0\n  Out> 0\n\nNow we iterate, increasing :math:`i`, and replacing :math:`g` with the\nnew value for :math:`g`::\n\n  In> [i++;g:=BigOh(2*g-f*g^2,x,2^i);]\n  Out> 1-x;\n  In> [i++;g:=BigOh(2*g-f*g^2,x,2^i);]\n  Out> x^2/2-x^3/6-x+1;\n  In> [i++;g:=BigOh(2*g-f*g^2,x,2^i);]\n  Out> x^7/72-x^6/72+x^4/24-x^3/6+x^2/2-x+1;\n\nThe resulting expression must thus be:\n\n.. math:: g(x):=\\frac{1}{72}x^7-\\frac{1}{72}x^6+\\frac{1}{24}x^4-\\frac{1}{6}x^3+\\frac{1}{2}x^2-x+1\n\nWe can easily verify this::\n\n  In> Expand(f*g)\n  Out> x^11/1728+x^10/576+x^9/216+(5*x^8)/576+1\n\nThis expression is 1 modulo :math:`x^8`, as can easily be shown::\n\n  In> BigOh(%,x,8)\n  Out> 1;\n"
  },
  {
    "path": "docs/book_of_algorithms/references.bib",
    "content": "@article{damgard1993:average_case_error,\n    author = {Ivan Damgård and Peter Landrock and Carl Pomerance},\n    title = {Average Case Error Estimates for the Strong Probable Prime Test},\n    journal = {Mathematics of Computation},\n    year = {1993},\n    volume = {61},\n    number = {203},\n    pages = {177-194},\n    doi = {10.2307/2152945},\n    issn = {00255718, 10886842},\n    url = {http://www.jstor.org/stable/2152945},\n    abstract = {Consider a procedure that chooses k-bit odd numbers independently and from the uniform distribution, subjects each number to t independent iterations of the strong probable prime test (Miller-Rabin test) with randomly chosen bases, and outputs the first number found that passes all t tests. Let p<sub>k, t</sub> denote the probability that this procedure returns a composite number. We obtain numerical upper bounds for p<sub>k, t</sub> for various choices of k, t and obtain clean explicit functions that bound p<sub>k, t</sub> for certain infinite classes of k, t. For example, we show p<sub>100, 10</sub> ≤ 2<sup>-44</sup>, p<sub>300, 5</sub> ≤ 2<sup>-60</sup>, p<sub>600, 1</sub> ≤ 2<sup>-75</sup>, and <tex-math>$p_{k, 1} \\leq k^2 4^{2 - \\sqrt k}$</tex-math> for all <tex-math>$k \\qeq 2$</tex-math>. In addition, we characterize the worst-case numbers with unusually many \"false witnesses\" and give an upper bound on their distribution that is probably close to best possible.},\n    publisher = {American Mathematical Society}\n}\n\n@book{davenport1988:computer_algebra,\n    author = {Davenport, J. H. and Siret, Y. and Tournier, E.},\n    title = {Computer Algebra, Systems and Algorithms for Algebraic\n             Computation},\n    year = {1988},\n    isbn = {0-122-04230-1},\n    publisher = {Academic Press},\n    address = {New York, NY, USA}\n}\n\n@InProceedings{davenport1992:primality_test_revisited,\n    author = {J. H. Davenport},\n    title = {Primality Testing Revisited},\n    booktitle = {Proceedings of International Symposium on Symbolic and Algebraic Computation (ISSAC'92)},\n    year = {1992},\n    publisher = {ACM Press},\n    editor = {P. S. Wang},\n    pages = {123--129}\n}\n\n\n@book{gathen1999:modern_computer_algebra,\n    author = {von zur Gathen, Joachim and Gerhard, Jürgen},\n    title = {Modern Computer Algebra},\n    year = {1999},\n    isbn = {0-521-64176-4},\n    publisher = {Cambridge University Press},\n    address = {New York, NY, USA},\n}\n\n@book{gathen2003:modern_computer_algebra,\n    author = {{\\noop{Gathen}{von zur Gathen}}, Joachim and Gerhard, Jürgen},\n    title = {Modern Computer Algebra},\n    year = {2003},\n    isbn = {0-521-82646-2},\n    edition = {2},\n    publisher = {Cambridge University Press},\n    address = {New York, NY, USA},\n} \n\n@book{hardy1945:introduction_theory_numbers,\n    author = {G. H. Hardy and E. M. Wright},\n    title = {An Introduction to the Theory of Numbers},\n    year = {1945},\n    publisher = {Oxford University Press}\n}\n\n@book{knuth1997:acp_seminumerical_algorithms,\n    author = {Knuth, Donald E.},\n    title = {The Art of Computer Programming, Volume 2 (3rd Ed.): Seminumerical Algorithms},\n    year = {1997},\n    isbn = {0-201-89684-2},\n    publisher = {Addison-Wesley Longman Publishing Co., Inc.},\n    address = {Boston, MA, USA},\n} \n\n@book{pollard1975:theory_algebraic_numbers,\n    author = {H. Pollard and H. G. Diamond},\n    title = {The Theory of Algebraic Numbers},\n    year = {1975},\n    publisher = {Wiley},\n    address = {New York}\n}\n\n@article {pomerance1980:pseudoprimes,\n    author = {Pomerance, Carl and Selfridge, J. L. and Wagstaff, Jr., Samuel S.},\n    title = {The Pseudoprimes to {$25\\cdot 10^{9}$}},\n    journal = {Mathematics of Computation},\n    year = {1980},\n    volume = {35},\n    number = {151},\n    pages = {1003--1026},\n    issn = {0025-5718},\n    doi = {10.2307/2006210}\n}\n\n@article{rabin1980:probabilistic_algorithm_testing,\n    author = \"Michael O Rabin\",\n    title = \"Probabilistic algorithm for testing primality\",\n    journal = \"Journal of Number Theory\",\n    volume = \"12\",\n    number = \"1\",\n    pages = \"128 -- 138\",\n    year = \"1980\",\n    issn = \"0022-314X\",\n    doi = \"http://dx.doi.org/10.1016/0022-314X(80)90084-0\",\n    url = \"http://www.sciencedirect.com/science/article/pii/0022314X80900840\",\n    abstract = \"We present a practical probabilistic algorithm for testing large numbers of arbitrary form for primality. The algorithm has the feature that when it determines a number composite then the result is always true, but when it asserts that a number is prime there is a provably small probability of error. The algorithm was used to generate large numbers asserted to be primes of arbitrary and special forms, including very large numbers asserted to be twin primes. Theoretical foundations as well as details of implementation and experimental results are given.\"\n}\n"
  },
  {
    "path": "docs/book_of_algorithms/references.rst",
    "content": "References\n----------\n\n.. bibliography:: references.bib\n\n.. .. [Davenport1988] James H Davenport, Y Siret, E Tournier, *Computer algebra*, Academic Press, 1988\n.. .. [Gathen1999] Joachim von zur Gathen, Jürgen Gerhard, *Modern computer algebra*, Cambridge University Press, 1999.\n"
  },
  {
    "path": "docs/book_of_algorithms/sturm-sequences.rst",
    "content": "=================================\nFinding real roots of polynomials\n=================================\n\nreal roots\n----------\n\nThis section deals with finding roots of polynomials in the field of\nreal numbers.\n\nWithout loss of generality, the coefficients :math:`a_i` of a polynomial\n\n.. math:: p = a_nx^n+\\ldots+a_0\n\ncan be considered to be rational numbers, as real-valued numbers are\ntruncated in practice, when doing calculations on a computer.\n\nAssuming that the leading coefficient :math:`a_n=1`, the polynomial\n:math:`p` can also be written as\n\n.. math:: p = p_1^{n_1}\\ldots p_m^{n_m}\n\nwhere :math:`p_i` are the :math:`m` distinct irreducible monic factors\nof the form :math:`p_i=x-x_i`, and :math:`n_i` are multiplicities of\nthe factors. Here the roots are :math:`x_i` and some of them may be\ncomplex. However, complex roots of a polynomial with real coefficients\nalways come in conjugate pairs, so the corresponding irreducible\nfactors should be taken as :math:`p_i=x^2+c_ix+d_i`. In this case,\nthere will be less than :math:`m` irreducible factors, and all\ncoefficients will be real.\n\nsquare free decomposition\n-------------------------\n\nTo find roots, it is useful to first remove the multiplicities,\ni.e. to convert the polynomial to one with multiplicity 1 for all\nirreducible factors, i.e. find the polynomial :math:`p_1\\ldots\np_m`. This is called the *square-free part* of the original polynomial\n:math:`p`.\n\nThe square-free part of the polynomial :math:`p` can be easily found\nusing the polynomial GCD algorithm. The derivative of a polynomial\n:math:`p` can be written as:\n\n.. math:: p' = \\sum_{i=1}^m p_1^{n_1}\\ldots n_ip_i^{n_i-1}\\frac{dp_i}{dx}\\ldots p_m^{n_m}\n\nThe GCD of :math:`p` and :math:`p'` equals\n\n.. math:: \\gcd(p,p') = p_1^{n_1-1}\\ldots p_m^{n_m-1}\n\nSo if we divide :math:`p` by :math:`\\gcd(p,p')`, we get the square-free\npart of the polynomial:\n\n.. math:: \\mathrm{SquareFree}(p) := \\frac{p}{\\gcd(p,p')} = p_1\\ldots p_m.\n\nIn what follows we shall assume that all polynomials are square-free\nwith rational coefficients.  Given any polynomial, we can apply the\nfunctions :func:`SquareFree` and :func:`Rationalize` and reduce it to this form.\nThe function :func:`Rationalize` converts all numbers in an expression to\nrational numbers. The function :func:`SquareFree` returns the square-free\npart of a polynomial. For example::\n\n  In> Expand((x+1.5)^5)\n  Out> x^5+7.5*x^4+22.5*x^3+33.75*x^2+25.3125*x +7.59375;\n  In> SquareFree(Rationalize(%))\n  Out> x/5+3/10;\n  In> Simplify(%*5)\n  Out> (2*x+3)/2;\n  In> Expand(%)\n  Out> x+3/2;\n\nSturm sequences\n---------------\n\nFor a polynomial :math:`p(x)` of degree :math:`n`, the Sturm sequence\n:math:`p_0, p_1,\\dots,p_n` is defined by the following equations\n(following :cite:`davenport1988:computer_algebra`):\n\n.. math::\n   :nowrap:\n\n   \\begin{eqnarray}\n   p_0 & = & p(x) \\\\\n   p_1 & = & p'(x) \\\\\n   p_i & = & -(p_{i-2} \\bmod p_{i-1}).\n   \\end{eqnarray}\n\nThe polynomial :math:`p` can be assumed to have no multiple factors, and\nthus :math:`p` and :math:`p'` are relatively prime. The sequence of\npolynomials in the Sturm sequence are (up to a minus sign) the\nconsecutive polynomials generated by Euclid's algorithm for the\ncalculation of a greatest common divisor for :math:`p` and :math:`p'`, so the\nlast polynomial :math:`p_n` will be a constant.\n\nIn yacas, the function :func:`SturmSequence` returns the Sturm sequence\nof :math:`p`, assuming :math:`p` is a univariate polynomial in :math:`x`,\n:math:`p = p(x)`.\n\nvariations in Sturm sequences\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nGiven a Sturm sequence :math:`S` of a polynomial :math:`p`,\nthe *variation* in the Sturm sequence :math:`V(S,y)` is the number of\nsign changes in the sequence :math:`p_0,p_1,\\ldots,p_n`,\nevaluated at point :math:`y`, and disregarding zeroes in the sequence.\n\nSturm's theorem states that if :math:`a` and :math:`b` are two real numbers\nwhich are not roots of :math:`p`, and :math:`a < b`, then the number of roots\nbetween :math:`a` and :math:`b` is :math:`V(S,a) - V(S,b)`. A proof can be\nfound in Knuth, <I>The Art of Computer Programming, Volume 2, Seminumerical\nAlgorithms</I>.\n\nFor :math:`a` and :math:`b`, the values :math:`-\\infty` and :math:`\\infty` can\nalso be used. In these cases, :math:`V(S,\\infty)` is the number of sign\nchanges between the leading coefficients of the elements of the Sturm\nsequence, and :math:`V(S,-\\infty)` the same, but with a minus sign for\nthe leading coefficients for which the degree is odd.\n\nNumber of real roots\n^^^^^^^^^^^^^^^^^^^^\n\nThus, the number of real roots of a polynomial is :math:`V(S,-\\infty) -\nV(S,\\infty)`. The function :func:`NumRealRoots` returns the number of\nreal roots of :math:`p`.\n\nThe function :func:`SturmVariations` returns the number of sign changes\nbetween the elements in the Sturm sequence :math:`S`, at point :math:`x = y`::\n\n  In> p:=x^2-1\n  Out> x^2-1;\n  In> S:=SturmSequence(p)\n  Out> {x^2-1,2*x,1};\n  In> SturmVariations(S,-Infinity)-SturmVariations(S,Infinity)\n  Out> 2;\n  In> NumRealRoots(p)\n  Out> 2;\n  In> p:=x^2+1\n  Out> x^2+1;\n  In> S:=SturmSequence(p)\n  Out> {x^2+1,2*x,-1};\n  In> SturmVariations(S,-Infinity)-SturmVariations(S,Infinity)\n  Out> 0;\n  In> NumRealRoots(p)\n  Out> 0;\n\n\nFinding bounds on real roots\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nArmed with the variations in the Sturm sequence given in the previous\nsection, we can now find the number of real roots in a range\n:math:`(a,b)`, for :math:`a < b`. We can thus bound all the roots by\nsubdividing ranges until there is only one root in each range.  To be\nable to start this process, we first need some upper bounds of the\nroots, or an interval that contains all roots. Davenport gives limits\non the roots of a polynomial given the coefficients of the polynomial,\nas\n\n.. math:: |a| \\le \\max\\left(\\left|\\frac{a_{n-1}}{a_n}\\right|,\\left|\\frac{a_{n-2}}{a_{n}}\\right|^{\\frac{1}{2}},\\ldots,\\left|\\frac{a_{0}}{a_{n}}\\right|^{\\frac{1}{n}}\\right)\n\nfor all real roots :math:`a` of :math:`p`. This gives the upper bound on the\nabsolute value of the roots of the polynomial in question.  If :math:`p(0)\\ne0`\nthe minimum bound can be obtained also by considering the\nupper bound of :math:`p(\\frac{1}{x})x^n`, and taking :math:`\\frac{1}{bound}`.\n\nWe thus know that given\n\n.. math:: a_{max} = \\mathrm{MaximumBound}(p)\n\nand\n\n.. math:: a_{min} = \\mathrm{MinimumBound}(p)\n\nfor all roots :math:`a` of polynomial, either\n\n.. math:: -a_{max}\\le a\\le -a_{min}\n\nor\n\n.. math:: a_{min}\\le a\\le a_{max}\n\nNow we can start the search for the bounds on all roots. The search\nstarts with initial upper and lower bounds on ranges, subdividing\nranges until a range contains only one root, and adding that range to\nthe resulting list of bounds. If, when dividing a range, the middle of\nthe range lands on a root, care must be taken, because the bounds\nshould not be on a root themselves. This can be solved by observing\nthat if :math:`c` is a root, :math:`p` contains a factor :math:`x-c`, and thus\ntaking :math:`p(x+c)` results in a polynomial with all the roots shifted\nby a constant :math:`-c`, and the root :math:`c` moved to zero, e.g. :math:`p(x+c)`\ncontains a factor :math:`x`. Thus a new ranges to the left and right of\n:math:`c` can be determined by first calculating the minimum bound :math:`M`\nof :math:`\\frac{p(x+c)}{x}`. When the original range was :math:`(a,b)`, and\n:math:`c = \\frac{a+b}{2}` is a root, the new ranges should become\n:math:`(a,c-M)` and :math:`(c+M,b)`.\n\nIn yacas, :func:`MimimumBound` returns the lower bound described above,\nand :func:`MaximumBound` returns the upper bound on the roots in :math:`p`.\nThese bounds are returned as rational numbers.  :func:`BoundRealRoots`\nreturns a list with sublists with the bounds on the roots of a\npolynomial::\n\n  In> p:=(x+20)*(x+10)\n  Out> (x+20)*(x+10);\n  In> MinimumBound(p)\n  Out> 10/3;\n  In> MaximumBound(p)\n  Out> 60;\n  In> BoundRealRoots(p)\n  Out> {{-95/3,-35/2},{-35/2,-10/3}};\n  In> N(%)\n  Out> {{-31.6666666666,-17.5}, {-17.5,-3.3333333333}};\n\nIt should be noted that since all calculations are done with rational\nnumbers, the algorithm for bounding the roots is very robust. This is\nimportant, as the roots can be very unstable for small variations in\nthe coefficients of the polynomial in question (see Davenport).\n\nFinding real roots given the bounds on the roots\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nGiven the bounds on the real roots as determined in the previous\nsection, two methods for finding roots are available: the secant\nmethod or the Newton method, where the function is locally\napproximated by a line, and extrapolated to find a new estimate for a\nroot. This method converges quickly when \"sufficiently\" near a root,\nbut can easily fail otherwise.  The secant method can easily send the\nsearch to infinity.\n\nThe bisection method is more robust, but slower. It works by taking\nthe middle of the range, and checking signs of the polynomial to\nselect the half-range where the root is.  As there is only one root in\nthe range :math:`(a,b)`, in general it will be true that :math:`p(a)p(b) < 0`,\nwhich is assumed by this method.\n\nYacas finds the roots by first trying the secant method, starting in\nthe middle of the range, :math:`c = \\frac{a+b}{2}`. If this fails the\nbisection method is tried.\n\nThe function call to find the real roots of a polynomial :math:`p` in\nvariable :math:`x` is :func:`FindRealRoots`, for example::\n\n  In> p:=Expand((x+3.1)*(x-6.23))\n  Out> x^2-3.13*x-19.313;\n  In> FindRealRoots(p)\n  Out> {-3.1,6.23};\n  In> p:=Expand((x+3.1)^3*(x-6.23))\n  Out> x^4+3.07*x^3-29.109*x^2-149.8199\\\n  In> *x-185.59793;\n  In> p:=SquareFree(Rationalize( \\\n  In> Expand((x+3.1)^3*(x-6.23))))\n  Out> (-160000*x^2+500800*x+3090080)/2611467;\n  In> FindRealRoots(p)\n  Out> {-3.1,6.23};\n"
  },
  {
    "path": "docs/book_of_algorithms/transforms.rst",
    "content": "==========\nTransforms\n==========\n\nCurrently the only tranform defined is :func:`LaplaceTransform`, which has\nthe calling convention::\n\n  LaplaceTransform(var1,var2,func)\n\nIt has been setup much like the integration algorithm. If the\ntransformation algorithm cannot perform the transform, the expression\n(in theory) is returned unsimplified. Some cases may still erroneously\nreturn ``Undefined`` or ``Infinity``.\n\nThe :func:`LaplaceTransform` algorithm\n--------------------------------------\n\nThis section describes the steps taken in doing a Laplace \ntransform.\n\nGeneral structure\n^^^^^^^^^^^^^^^^^\n\n:func:`LaplaceTransform` is immediately handed off to :func:`LapTran`.  This is\ndone because if the last :func:`LapTran` rule is met, the Laplace transform\ncouldn't be found and it can then return :func:`LaplaceTransform`\nunevaluated.\n\nOperational properties\n^^^^^^^^^^^^^^^^^^^^^^\n\nThe first rules that are matched against utilize the various\noperational properties of :func:`LaplaceTransform`, such as:\n\n* Linearity Properties\n* Shift properties, i.e. multiplying the function by an exponential\n* :math:`\\mathcal{L}\\lbrace yx^n\\rbrace = (-1)^n \\frac{d^n}{dx^n} \\mathcal{L}\\lbrace y\\rbrace`\n* :math:`\\mathcal{L}\\lbrace \\frac{y}{x}\\rbrace = \\int_s^\\infty\\mathcal{L}\\lbrace y\\rbrace(\\sigma)d\\sigma`\n\nThe last operational property dealing with integration is not yet\nfully bug-tested, it sometimes returns ``Undefined`` or ``Infinity`` if\nthe integral returns such.\n\nTransform tables\n^^^^^^^^^^^^^^^^\n\nFor elementary functions, yacas uses transform tables. For instance,\nthe fact that the Laplace transform of :math:`cos(t)` is\n:math:`\\frac{s}{s^2+1}` is declared in a transform table.\n\nFor the purpose of setting up the transform table, a few declaration\nfunctions have been defined, which use some generalized pattern\nmatchers to be more flexible in recognizing expressions that are\ntransformable.\n\nTransforming simple functions\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nFor functions like :math:`\\sin(t)` the transform can be declared with the\nfunction :func:`LapTranDef`.\n\nThe calling sequence for :func:`LapTranDef` is::\n\n  LapTranDef(in, out)\n\nCurrently ``in`` must be a variable of ``_t`` and ``out`` must be a function\nof ``s``.  For instance, for the function :math:`\\cos(t)` there is a\ndeclaration::\n\n  LapTranDef(Cos(_t), s/(s^2+1));\n\nThe fact that the first argument is a pattern means that each\noccurrence of the variable to be matched should be referred to as\n``_t``, as in the example above.\n\n:func:`LapTranDef` generalizes the transform implicitly, in that it will set\nup the system to actually recognize expressions of the form :math:`\\cos(at)`\nand :math:`\\cos(\\frac{t}{a})` , and return the appropriate answer.  The way\nthis is done is by three separate rules for case of ``t`` itself, ``a*t`` and\n``t/a``. This is similar to the :func:`MatchLinear` function that\n:func:`Integrate` uses, except :func:`LaplaceTransforms` must have ``b=0``.\n\nFurther Directions\n^^^^^^^^^^^^^^^^^^\n\nCurrenlty :math:`\\sin(t)\\cos(t)` cannot be transformed, because it requires\na convolution integral. This will be implemented soon. The inverse\nLaplace transform will be implement soon also.\n"
  },
  {
    "path": "docs/conf.py",
    "content": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n#\n# yacas documentation build configuration file, created by\n# sphinx-quickstart on Mon Sep  8 11:39:49 2014.\n#\n# This file is execfile()d with the current directory set to its\n# containing dir.\n#\n# Note that not all possible configuration values are present in this\n# autogenerated file.\n#\n# All configuration values have a default; values that are commented out\n# serve to show the default.\n\nimport sys\nimport os\n\n# If extensions (or modules to document with autodoc) are in another directory,\n# add these directories to sys.path here. If the directory is relative to the\n# documentation root, use os.path.abspath to make it absolute, like shown here.\n#sys.path.insert(0, os.path.abspath('.'))\n\nsys.path.insert(0, os.path.abspath('./util'))\n\n# -- General configuration ------------------------------------------------\n\n# If your documentation needs a minimal Sphinx version, state it here.\n#needs_sphinx = '1.0'\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom\n# ones.\nextensions = [\n    'sphinx.ext.mathjax',\n    'sphinx.ext.todo',\n    'sphinxcontrib.bibtex',\n    'yacasdomain'\n]\n\nbibtex_bibfiles = \"book_of_algorithms/references.bib\"\n\ntodo_include_todos = True\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = ['_templates']\n\n# The suffix of source filenames.\nsource_suffix = '.rst'\n\n# The encoding of source files.\n#source_encoding = 'utf-8-sig'\n\n# The master toctree document.\nmaster_doc = 'index'\n\n# General information about the project.\nproject = 'Yacas'\ncopyright = '2002-2016, Ayal Pinkus, Serge Winnitzky, Grzegorz Mazur'\n\n# The version info for the project you're documenting, acts as replacement for\n# |version| and |release|, also used in various other places throughout the\n# built documents.\n#\n# The short X.Y version.\nversion = '1.9'\n# The full version, including alpha/beta/rc tags.\nrelease = '1.9.2'\n\n# The language for content autogenerated by Sphinx. Refer to documentation\n# for a list of supported languages.\n#language = None\n\n# There are two options for replacing |today|: either, you set today to some\n# non-false value, then it is used:\n#today = ''\n# Else, today_fmt is used as the format for a strftime call.\n#today_fmt = '%B %d, %Y'\n\n# List of patterns, relative to source directory, that match files and\n# directories to ignore when looking for source files.\nexclude_patterns = ['_build']\n\nprimary_domain = 'ys'\nhighlight_language = 'none'\n\n# The reST default role (used for this markup: `text`) to use for all\n# documents.\n#default_role = None\n\n# If true, '()' will be appended to :func: etc. cross-reference text.\n#add_function_parentheses = True\n\n# If true, the current module name will be prepended to all description\n# unit titles (such as .. function::).\n#add_module_names = True\n\n# If true, sectionauthor and moduleauthor directives will be shown in the\n# output. They are ignored by default.\n#show_authors = False\n\n# The name of the Pygments (syntax highlighting) style to use.\npygments_style = 'sphinx'\n\n# A list of ignored prefixes for module index sorting.\n#modindex_common_prefix = []\n\n# If true, keep warnings as \"system message\" paragraphs in the built documents.\n#keep_warnings = False\n\n\n# -- Options for HTML output ----------------------------------------------\n\non_rtd = os.environ.get('READTHEDOCS', None) == 'True'\n\nif not on_rtd:  # only import and set the theme if we're building docs locally\n    import sphinx_rtd_theme\n    html_theme = 'sphinx_rtd_theme'\n    html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]\n\n# The theme to use for HTML and HTML Help pages.  See the documentation for\n# a list of builtin themes.\n#html_theme = 'default'\n\n# Theme options are theme-specific and customize the look and feel of a theme\n# further.  For a list of options available for each theme, see the\n# documentation.\n#html_theme_options = {}\n\n# Add any paths that contain custom themes here, relative to this directory.\n#html_theme_path = ['_themes']\n\n# The name for this set of Sphinx documents.  If None, it defaults to\n# \"<project> v<release> documentation\".\nhtml_title = \"Yacas\"\n\n# A shorter title for the navigation bar.  Default is the same as html_title.\n#html_short_title = None\n\n# The name of an image file (relative to this directory) to place at the top\n# of the sidebar.\nhtml_logo = \"yacaslogo_w250px.png\"\n\n# The name of an image file (within the static path) to use as favicon of the\n# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32\n# pixels large.\nhtml_favicon = \"favicon.ico\"\n\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the builtin static files,\n# so a file named \"default.css\" will overwrite the builtin \"default.css\".\nhtml_static_path = ['_static']\n\n# Add any extra paths that contain custom files (such as robots.txt or\n# .htaccess) here, relative to this directory. These files are copied\n# directly to the root of the documentation.\n#html_extra_path = []\n\n# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,\n# using the given strftime format.\n#html_last_updated_fmt = '%b %d, %Y'\n\n# If true, SmartyPants will be used to convert quotes and dashes to\n# typographically correct entities.\n#html_use_smartypants = True\n\n# Custom sidebar templates, maps document names to template names.\n#html_sidebars = {}\n\n# Additional templates that should be rendered to pages, maps page names to\n# template names.\n#html_additional_pages = {}\n\n# If false, no module index is generated.\n#html_domain_indices = True\n\n# If false, no index is generated.\nhtml_use_index = True\n\n# If true, the index is split into individual pages for each letter.\nhtml_split_index = False\n\n# If true, links to the reST sources are added to the pages.\n#html_show_sourcelink = True\n\n# If true, \"Created using Sphinx\" is shown in the HTML footer. Default is True.\n#html_show_sphinx = True\n\n# If true, \"(C) Copyright ...\" is shown in the HTML footer. Default is True.\n#html_show_copyright = True\n\n# If true, an OpenSearch description file will be output, and all pages will\n# contain a <link> tag referring to it.  The value of this option must be the\n# base URL from which the finished HTML is served.\n#html_use_opensearch = ''\n\n# This is the file name suffix for HTML files (e.g. \".xhtml\").\n#html_file_suffix = None\n\n# Output file base name for HTML help builder.\nhtmlhelp_basename = 'yacasdoc'\n\n\n# -- Options for LaTeX output ---------------------------------------------\n\nlatex_elements = {\n# The paper size ('letterpaper' or 'a4paper').\n#'papersize': 'letterpaper',\n\n# The font size ('10pt', '11pt' or '12pt').\n#'pointsize': '10pt',\n\n# Additional stuff for the LaTeX preamble.\n#'preamble': '',\n}\n\n# Grouping the document tree into LaTeX files. List of tuples\n# (source start file, target name, title,\n#  author, documentclass [howto, manual, or own class]).\nlatex_documents = [\n  ('index', 'yacas.tex', 'Yacas',\n   'Ayal Pinkus, Serge Winitzki and Grzegorz Mazur', 'manual'),\n]\n\n# The name of an image file (relative to this directory) to place at the top of\n# the title page.\n#latex_logo = None\n\n# For \"manual\" documents, if this is true, then toplevel headings are parts,\n# not chapters.\n#latex_use_parts = False\n\n# If true, show page references after internal links.\n#latex_show_pagerefs = False\n\n# If true, show URL addresses after external links.\n#latex_show_urls = False\n\n# Documents to append as an appendix to all manuals.\n#latex_appendices = []\n\n# If false, no module index is generated.\n#latex_domain_indices = True\n\n\n# -- Options for manual page output ---------------------------------------\n\n# One entry per manual page. List of tuples\n# (source start file, name, description, authors, manual section).\nman_pages = [\n    ('index', 'yacas', 'Yacas',\n     ['Ayal Pinkus, Serge Winitzki and Grzegorz Mazur'], 1)\n]\n\n# If true, show URL addresses after external links.\n#man_show_urls = False\n\n\n# -- Options for Texinfo output -------------------------------------------\n\n# Grouping the document tree into Texinfo files. List of tuples\n# (source start file, target name, title, author,\n#  dir menu entry, description, category)\ntexinfo_documents = [\n  ('index', 'yacas', 'Yacas',\n   'Ayal Pinkus, Serge Winitzki and Grzegorz Mazur',\n   'yacas', 'Computer calculations made easy',\n   'Miscellaneous'),\n]\n\n# Documents to append as an appendix to all manuals.\n#texinfo_appendices = []\n\n# If false, no module index is generated.\n#texinfo_domain_indices = True\n\n# How to display URL addresses: 'footnote', 'no', or 'inline'.\n#texinfo_show_urls = 'footnote'\n\n# If true, do not generate a @detailmenu in the \"Top\" node's menu.\n#texinfo_no_detailmenu = False\n\n\n# -- Options for Epub output ----------------------------------------------\n\n# Bibliographic Dublin Core info.\nepub_title = 'Yacas'\nepub_author = 'Ayal Pinkus, Serge Winitzki and Grzegorz Mazur'\nepub_publisher = 'Yacas Team'\nepub_copyright = '2002-2016, Ayal Pinkus, Serge Winitzki, Grzegorz Mazur'\n\n# The basename for the epub file. It defaults to the project name.\n#epub_basename = 'Yacas'\n\n# The HTML theme for the epub output. Since the default themes are not optimized\n# for small screen space, using the same theme for HTML and epub output is\n# usually not wise. This defaults to 'epub', a theme designed to save visual\n# space.\n#epub_theme = 'epub'\n\n# The language of the text. It defaults to the language option\n# or en if the language is not set.\n#epub_language = ''\n\n# The scheme of the identifier. Typical schemes are ISBN or URL.\n#epub_scheme = ''\n\n# The unique identifier of the text. This can be a ISBN number\n# or the project homepage.\n#epub_identifier = ''\n\n# A unique identification for the text.\n#epub_uid = ''\n\n# A tuple containing the cover image and cover page html template filenames.\n#epub_cover = ()\n\n# A sequence of (type, uri, title) tuples for the guide element of content.opf.\n#epub_guide = ()\n\n# HTML files that should be inserted before the pages created by sphinx.\n# The format is a list of tuples containing the path and title.\n#epub_pre_files = []\n\n# HTML files shat should be inserted after the pages created by sphinx.\n# The format is a list of tuples containing the path and title.\n#epub_post_files = []\n\n# A list of files that should not be packed into the epub file.\nepub_exclude_files = ['search.html']\n\n# The depth of the table of contents in toc.ncx.\n#epub_tocdepth = 3\n\n# Allow duplicate toc entries.\n#epub_tocdup = True\n\n# Choose between 'default' and 'includehidden'.\n#epub_tocscope = 'default'\n\n# Fix unsupported image types using the PIL.\n#epub_fix_images = False\n\n# Scale large images.\n#epub_max_image_width = 0\n\n# How to display URL addresses: 'footnote', 'no', or 'inline'.\n#epub_show_urls = 'inline'\n\n# If false, no index is generated.\n#epub_use_index = True\n"
  },
  {
    "path": "docs/credits.rst",
    "content": "*******\nCredits\n*******\n\nLast-known email addresses mangled in an obvious way.\n\nOriginal/primary authors\n========================\nAyal Pinkus                  *apinkus \"AT\" xs4all \"DOT\" nl*\n    This project was started by Ayal Pinkus who remains the main author and the primary maintainer.\n\nSerge Winitzki               *serge \"AT\" cosmos \"DOT\" phy \"DOT\" tufts \"DOT\" edu*\n    Added factorials over rationals, TeXForm, did a major overhaul of the introduction manual (actually, he wrote\n    large part of the manual as it is), and initiated numerous improvements and test code for Yacas, and\n    implemented yacas_client. Actually, Serge has been one of the larger contributors, and the main force behind\n    the improved documentation.\n\nJitse Niesen                 *jn221 \"AT\" damtp \"DOT\" cam \"DOT\" ac \"DOT\" uk*\n    Reported some bugs, helped improve various parts of Yacas, and greatly improved the manual for Yacas.\n\nMaintainer\n==========\n\nGrzegorz Mazur             *teoretyk \"AT\" gmail \"DOT\" com*\n\nContributors\n============\n\nJim Apple                    *japple \"AT\" freeshell \"DOT\" org*\n    Reported bugs and supplied improved code for gcc 3.3.4\n\nMark Arrasmith               *arrasmith \"AT\" math \"DOT\" twsu \"DOT\" edu*\n    Helped greatly in setting up the fltk-based graphicaluser interface, and fixed some bugs relating to limits\n    regarding infinity.\n\nFred Bacon                   *bacon \"AT\" aerodyne \"DOT\" com*\n    Fixed some compiler errors on the newer gcc compiles. Reported some important bugs.\n\nJay Belanger                 *belanger \"AT\" truman \"DOT\" edu*\n    Reported some bugs and improved some of the GnuPlot code. He also wrote the yacas.el file, which allows you\n    to run yacas from within emacs.\n\nRoberto Colistete Junior\n    Is maintaining a version of `Yacas for SymbianOS <http://www.robertocolistete.net/Yacas/>`_.\n\nSebastian Ferraro            *sferraro \"AT\" criba \"DOT\" edu \"DOT\" ar*\n    Reported bugs and supplied improved code (determinants).\n\nJohn Fremlin\n    Added some code for fast calculation of roots of a cubic polynomial.\n\nPeter Gilbert                *peterdgilbert \"AT\" gmail \"DOT\" com*\n    Made many improvements to the C++ code to make it conform more to standard C++ coding conventions (class\n    interfaces looking more like stl), improved the regression test suite.\n\nJames Gilbertson             *azurite \"AT\" telusplanet \"DOT\" net*\n    Win32 port, improved error reporting. Added initial version of Karatsuba multiplication, and added some matrix\n    functions to the math library.\n\nGabor Grothendieck\n    Gabor is the maintainer of `Ryacas <https://code.google.com/p/ryacas/>`_, and gave valuable feedback on the\n    new web site.\n\nRene Grothmann              *2004 \"AT\" rene-grothmann \"DOT\" de*\n    Married Euler to Yacas.\n\nFranz Hack                   *franz.hack \"AT\" web \"DOT\" de*\n    Supplied a Delphi interface to the Yacas DLL.\n\nIngrid Halters\n    Helped improve the ease of use of the Yacas web site.\n\nMark Hatsell                 *mark \"AT\" autograph-maths \"DOT\" com*\n    Made the server code work on Windows.\n\nJoris van der Hoeven        *TeXmacs \"AT\" math \"DOT\" u-psud \"DOT\" fr*\n    Helped with texmacs support.\n\nWolfgang Hšnig               *pocket_software \"AT\" web \"DOT\" de*\n    Created a port of Yacas that runs on PocketPC, to be found `here <http://www.pocket-software.de.vu>`_.\n\nDaniel Richard G.            *straker \"AT\" MIT \"DOT\" EDU*\n    Added autoconf/automake scripts, made Sun/Sgi compilation possible, created a rpm spec file, many many many\n    changes to clean up the source distribution.\n\nIgor Khavkine\n    Added 'Diverge' and 'Curl', and implemented threading for the derivative operator (the gradient). Fixed GMP\n    code.\n\nJohn Lapeyre\n    Made some modifications to the make file, and improved some math code.\n\nJonathan Leto                *jonathan \"AT\" leto \"DOT\" net*\n    Helped improve the integration algorithm, and helped extend the tests used for Yacas (finding numerous bugs).\n\nVladimir Livshits            *livshits \"AT\" cs \"DOT\" stanford \"DOT\" edu*\n    Set up the initial sourceforge CVS repository, and updated the Windows version source code. He also greatly\n    improved the logic theorem prover code.\n\nEugenia Loli\n    Helped build the BeOS version of Yacas.\n\nAdolf Mathias                *adolf_mathias \"AT\" web \"DOT\" de*\n\nGrzegorz Mazur               *teoretyk \"AT\" gmail \"DOT\" com*\n\nPablo De Nápoli              *pdenapo \"AT\" yahoo \"DOT\" com*\n    Fixed the configure script so Yacas compiles under cygwin.\n\nGopal Narayanan              *gopal \"AT\" debian \"DOT\" org*\n    Debian package maintainer. Made a man page for Yacas.\n\nMarta Noga                   *marta.noga \"AT\" gmail \"DOT\" com*\n\nChristian Obrecht            *christian \"DOT\" obrecht \"AT\" wanadoo \"DOT\" fr*\n    Made a much better Limit, and made Yacas behave better at infinity.\n\nAlberto González Palomo\n    Implemented a console-mode version of Yacas for AgendaVR. Changed the directory structure for the script\n    files, and implemented initial support for OpenMath.\n\nDoreen Pinkus                *d \"DOT\" pinkus \"AT\" hccnet \"DOT\" nl*\n    Designed the second version of the Web site for Yacas.\n\nMike Pinna                   *mike \"AT\" autograph-maths \"DOT\" com*\n    Applied some bug fixes.\n\nSavario Prinz                *yacas \"AT\" mac \"DOT\" com*\n    Built a fantastic Mac version of Yacas.\n\nDirk Reusch\n    Added some linear algebra functions, and fixed some predicate functions.\n\nDaniel Rigby\n    Brought a client-server structure to the EPOC32 version of Yacas.\n\nJuan Pablo Romero            *jpablo_romero \"AT\" hotmail \"DOT\" com*\n    Reported many bugs, made many suggestions for improvements, and supplied improved code (yacas scripts and\n    makefile code).\n\nRobert V Schipper            *rvs \"AT\" achilles \"DOT\" nfia \"DOT\" org*\n    Ironed out a few bugs in Yacas.\n\nSchneelocke\n    Reported an important bug in numeric calculations.\n\nHenSiong Tan                 *tan \"AT\" stat \"DOT\" psu \"DOT\" edu*\n\nYannick Versley              *yannick \"AT\" versley \"DOT\" de*\n    Sent some patches regarding bugs relating integration and differentiation.\n\nAdrian V.                    *qwert2003 \"AT\" users \"DOT\" sourceforge \"DOT\" net*\n\nLadislav Zejda\n    Supplied patches to make Yacas work on Dec Alpha's.\n\nAndrei Zorine\n    Started the body of statistics code.\n"
  },
  {
    "path": "docs/getting_started/index.rst",
    "content": "***************\nGetting started\n***************\n\n============\nInstallation\n============\n\nYacas is available for a variety of platforms. See\n`<http://www.yacas.org/getting_started/downloads/>`_ for binary packages\nand installation instructions.\n\n=========================\nInstallation from sources\n=========================\n\nGetting sources\n---------------\n\nVersion 1.9.2 can be downloaded from\n`<https://github.com/grzegorzmazur/yacas/archive/v1.9.2.zip>`_ or\n`<https://github.com/grzegorzmazur/yacas/archive/v1.9.2.tar.gz>`_,\nwhile the current development version is accessible from\n`<https://github.com/grzegorzmazur/yacas/archive/develop.zip>`_.\n\nCompilation\n-----------\n\nCommon build options\n^^^^^^^^^^^^^^^^^^^^\n`ENABLE_CYACAS_CONSOLE`\n   Build text console for the native yacas engine. Enabled by default.\n\n`ENABLE_CYACAS_GUI`\n   Build graphical interface for the native yacas engine. Requires Qt 5.5.\n   Enabled by default.\n\n`ENABLE_CYACAS_GUI_PRIVATE_CODEMIRROR`\n   Use bundled copy of CodeMirror. Enabled by default.\n\n`ENABLE_CYACAS_GUI_PRIVATE_MATHJAX`\n   Use bundled copy of MathJax. Enabled by default.\n\n`ENABLE_CYACAS_KERNEL`\n   Build native yacas kernel for Jupyter Notebook. Requires Boost, ZeroMQ and\n   zmqpp. Disabled by default.\n\n`ENABLE_JYACAS`\n   Build the Java yacas engine and text console for it. Disabled by default.\n\n`ENABLE_DOCS`\n   Generate HTML documentation. Disabled by default.\n\nMacOS X\n~~~~~~~\n\n* Open ``Terminal`` window\n* Change directory to the yacas source directory\n* Execute\n\n  .. code-block:: bash\n\n     mkdir build\n     cd build\n     cmake -G Xcode [-Dcommon_option=value ...] ..\n\n* Open generated project in ``Xcode`` and build the Release variant\n\nMicrosoft Windows\n~~~~~~~~~~~~~~~~~\n\n* Open ``Command Prompt`` window\n* Change directory to the yacas source directory\n* Execute\n\n  .. code-block:: bat\n\n     mkdir build\n     cd build\n     cmake -G \"Visual Studio 14 2015 Win64\" [-Dcommon_option=value ...] ..\n\n* Open generated project in ``Visual Studio`` and build the Release variant\n\nLinux\n~~~~~\n\n* Open ``Terminal`` window\n* Change directory to the yacas source directory\n* Execute\n\n  .. code-block:: bash\n\n     mkdir build\n     cd build\n     cmake -DCMAKE_BUILD_TYPE=Release [-Dcommon_option=value ...] ..\n     make\n\n* To install newly built binaries execute ``make install``\n\nJava\n~~~~\n* Open ``Terminal`` or ``Command Prompt`` window\n* Change directory to the yacas source directory\n* Execute ``ant jar``\n\n\nyacas-online\n~~~~~~~~~~~~\n\n* build yacas using emscripten\n\n  .. code-block:: bash\n\n     mkdir build_js\n     cd build_js\n     cmake -DCMAKE_TOOLCHAIN_FILE=<EMSCRIPTEN_ROOT>/cmake/Modules/Platform/Emscripten.cmake \\\n     -DENABLE_CYACAS_GUI=No -DENABLE_CYACAS_KERNEL=No -DENABLE_JYACAS=No \\\n     -DENABLE_DOCS=No -DCMAKE_BUILD_TYPE=Release ..\n     make\n     cd ..\n\n  where ``<EMSCRIPTEN_ROOT>`` stands for the Emscripten root directory\n\n* copy\n\n  * ``build_js/cyacas/yacas/yacas.js``\n  * ``build_js/cyacas/yacas/yacas.js.mem``\n  * ``cyacas/yacas-gui/resources/yacas-online.html``\n  * ``cyacas/yacas-gui/resources/jquery/``\n  * ``cyacas/yacas-gui/resources/mathbar/``\n  * ``cyacas/yacas-gui/resources/plot3d/``\n  * ``cyacas/yacas-gui/resources/yacas_gui/``\n\n  to the installation directory\n"
  },
  {
    "path": "docs/glossary.rst",
    "content": "========\nGlossary\n========\n.. glossary::\n  arity \n       Arity is the number of arguments of a function.  For example,\n       the function :func:`Cos` has one argument and so we say that\n       :func:`Cos` *has arity 1*.  Arity of a function can be 0, 1, 2, ...\n\n       Yacas allows to define functions with the same name but\n       different arities, and different rules corresponding to these\n       arities will be used.  Also, it is possible to define a\n       function with optional arguments, for example, :func:`Plot2D` is one\n       such function.  Such functions can have any arity larger or\n       equal to a certain minimum arity (the number of non-optional\n       arguments).\n\n       .. seealso:: :func:`Function`, :func:`OpPrecedence`,\n                    :func:`Rule`\n\n  array\n    An array is a container object that can hold a fixed number of\n    other Yacas objects in it.  Individual elements of an array can\n    be accessed using the {[]} operation.  Most list operations also\n    work on arrays.\n\n    Arrays are faster than lists but the array size cannot be\n    changed.\n\n    .. seealso:: :func:`Array'Create`\n\n  atom\n    Atoms are basic Yacas objects that are used to represent symbols,\n    numbers, and function names.  An atom has a string representation\n    which is shown when it is displayed.  For example, {3.14159},\n    {x}, {A123}, {+}, {\"good morning\"} are atoms.\n\n    Atoms can be of type string, number, or symbol. For example, {y1}\n    is a symbolic atom, {954} is a number atom, and {\"\"} is an\n    (empty) string atom.  Symbolic atoms are normally used in yacas\n    to denote mathematical unknowns and function names. Number and\n    string atoms are used to denote values.\n\n    A symbolic atom can be bound to a value (in which case it becomes\n    a variable), or to a rule or several rules (in which case it\n    becomes a function).  An atom can also have a property object.\n\n    .. seealso:: :func:`Atom`, :func:`String`\n\n  bodied function\n\n   *Bodied functions* have all arguments except the first one inside\n   parentheses and the first argument outside the argument list, for\n   example::\n\n     Integrate(x) Sin(x);\n\n  CAS\n    Abbreviation for \"computer algebra system\". Yacas is a CAS.\n\n\n  constant\n  cached constant\n    Constants such as :data:`Pi` or :data:`GoldenRatio` are symbolic atoms\n    that are specially interpreted by yacas.  For example, there\n    are simplification rules that transform expressions such as\n    ``Sin(Pi)`` into ``0``.  When requesting a numerical evaluation of a\n    constant, the numerical value is given to the current value as\n    set with :func:`N`.\n\n    Some constants take a long time to compute and therefore they are\n    cached at the highest precision computed so far.  These are the\n    `cached constants`.\n\n    .. seealso:: :func:`N`, :func:`CachedConstant`, :data:`Pi`,\n                 :data:`GoldenRatio`, :data:`CatalanConstant`,\n                 :data:`gamma`\n\n  equation \n    To denote symbolic equations, the operator {==} is used.  This\n    operator does not assign or compare its sides.  For example, the\n    expression {Sin(x)==1} is kept unevaluated and can be passed as\n    argument to functions.  For example, In> Solve(Sin(x)==1, x) Out>\n    {x==Pi/2};\n\n    The symbolic equation operator {==} is also useful to represent\n    solutions of equations or to specify substitutions, give options,\n    and so on.\n\n    .. seealso:: :func:`Solve`, :func:`Where`, :func:`Plot2D`\n\n  function\n    A function is a symbolic atom that is bound to a rule or several\n    rules.  A function can have none, one, or more arguments.\n    Functions can also have a variable number of arguments.\n    Arguments of functions are arbitrary Yacas objects.\n\n    Functions can be evaluated, that is, the rules bound to them may\n    be executed.  For example, ``Cos(Pi+0)`` is an expression that\n    contains two functions and four atoms.  The atom ``Pi`` is a\n    symbolic atom which is normally not bound to anything.  The atom\n    ``0`` is a numeric atom.\n\n    The atoms ``Cos`` and ``+`` are symbolic atoms which are bound to\n    appropriate simplification rules.  So these two atoms are\n    functions.  Note that these functions have different syntax.\n    ``Cos`` is a normal function which takes its arguments in\n    parentheses.  The atom ``+`` is a function with special syntax\n    because ``+`` is placed between its arguments and no parentheses\n    are used.\n\n    The rules to which ``+`` is bound are such that the expression\n    ``Pi+0`` is evaluated to the symbolic atom ``Pi``.  The rules for\n    ``Cos`` are such that the expression ``Cos(Pi)`` is evaluated to\n    the numeric atom ``-1``.  The example yacas session is::\n\n      In> Cos(Pi+0)\n      Out> -1\n\n    Some functions are built-in and implemented in C++, while others\n    are library functions.\n\n    The built-in functions are usually less flexible than the library\n    functions because they cannot be left unevaluated.  Given\n    incorrect arguments, a built-in function will generate an error.\n    However, a user-defined function may simply return unevaluated in\n    such cases.\n\n\n    .. seealso:: :func:`Function`, :func:`Rule`, :func:`<--`\n\n  list\n    A list is a basic yacas container object. A list is written as\n    e.g. ``{{a, b, c}}`` or ``{{}}`` (empty list).  Individual elements of a\n    list can be accessed using the ``[]`` operation.  Lists can be\n    concatenated, and individual elements can be removed or inserted.\n\n    Lists are ubiquitous in yacas.  Most data structures in the\n    standard library is based on lists.\n\n    Lists are also used internally to represent yacas expressions.\n    For example, the expression ``Cos(x+1)`` is represented internally\n    as a nested list::\n\n        In> FullForm( Cos(x+1) )\n        (Cos (+ x 1 ))\n        Out> Cos(x+1);\n\n\n    .. seealso:: :func:`List`, :func:`Listify`, :func:`UnList`,\n                 :func:`Length`, :func:`FullForm`\n\n  matrix\n    A matrix is represented as a list of lists.  Matrices are\n    represented in the *row-major* order: a matrix is a list of rows,\n    and each row is a list of its elements.\n\n    Some basic linear algebra operations on matrices are supported.\n\n    .. seealso:: :func:`Determinant`, :func:`Identity`,\n                 :func:`IsDiagonal`, :func:`EigenValues`\n\n  operator\n    Operators are functions that have special syntax declared for\n    them.  An operator can be *bodied*, infix, prefix or postfix.\n    Because of this, operators must have precedence.\n\n    Apart from the syntax, operators are exactly the same as any\n    other functions, they can have rules bound to them in the same\n    way.\n\n    .. seealso:: :func:`Bodied`, :func:`Infix`, :func:`Prefix`,\n                 :func:`Postfix`\n\n  precedence\n    Precedence is a property of the syntax of an operator that\n    specifies how it is parsed.  Only operators, i.e. functions with\n    special syntax, can have precedence.  Precedence values are\n    nonnegative integers: 0, 1, ...  Lower numbers bind more tightly.\n\n    For example, the operator ``+`` binds less tightly (i.e. has a\n    *higher* precedence value) than the operator ``*`` and so\n    the expression ``a+b*c`` is parsed as ``a+(b*c)``, as one would\n    expect.\n\n    Infix operators can have different left-side and right-side\n    precedence -- this allows us to parse\n    expressions such as :math:`a-b+c` correctly, as :math:`(a-b)+c`, and not as\n    :math:`a-(b+c)`.\n\n    .. seealso:: :func:`Bodied`, :func:`OpPrecedence`,\n                 :func:`OpLeftPrecedence`, :func:`OpRightPrecedence`\n\n  property\n    Properties are special additional objects (tags) that can be tied\n    to expressions.  For example, the expression {1+x} may be tagged\n    by an expression {y} by the command ::\n\n      In> a:= ExtraInfo'Set(1+x,y);\n      Out> 1+x;\n    \n    Now ``a`` refers to an expression ``1+x`` which is different from all\n    other copies of ``1+x`` because it is tagged by ``y``.\n\n    .. seealso:: :func:`ExtraInfo'Get`, :func:`ExtraInfo'Set`\n\n  rule\n    Rules are the principal mechanism of expression evaluation in\n    yacas.  A rule specifies that a certain symbolic expression is\n    to be replaced by another expression.  If no rule that matches a\n    given symbolic expression can be found, the expression is left\n    unevaluated.  This is usually the desired behavior for a CAS.  For\n    example, a user can type ::\n\n      In> func1(x+0)\n      Out> func1(x);\n\n    and use an undefined function {func1}.  Since no rules are defined\n    for the function {func1}, it is not evaluated, but its argument\n    has been simplified.\n\n    Only expressions containing functions can be evaluated by rules.\n    (Atoms are evaluated only if they are bound to a value.)\n\n    Several rules can be defined for a given function.  Rules can be\n    erased or added at run time.\n\n    .. seealso:: :func:`Rule`, :func:`<--`, :func:`Retract`\n\n  string\n    A string is an atom with character string value, for example,\n    ``\"abcd\"``.  Individual characters of the string can be accessed\n    using the ``[]`` operation.  Some string manipulation functions are\n    supported.\n\n    .. seealso:: :func:`String`, :func:`StringMid'Get`,\n                 :func:`StringMid'Set`\n\n  syntax\n    Yacas uses an infix syntax similar to C or Fortran.  However,\n    the syntax is entirely user-defined and very flexible.  Infix,\n    prefix, postfix operators can be defined, as well as \"bodied\"\n    functions.  This allows to write mathematical expressions more\n    comfortably, for example ::\n\n      In> D(x) Sin(x)+1\n      Out> Cos(x);\n\n    Functions with special syntax can have different precedence.\n\n    .. seealso:: :func:`Bodied`, :func:`Infix`, :func:`Prefix`,\n                 :func:`Postfix`, :func:`OpPrecedence`\n\n  threaded function\n    Threaded function applied to a list ::\n    \n        In> Cos({Pi/2, Pi/4})\n        Out> {0,Sqrt(1/2)} \n\n  variable\n    Variables are symbolic atoms bound to a \"value\".  Value is any\n    Yacas object, such as an atom or a list.  For example, after\n    executing ::\n\n      In> a := 1\n      Out> 1;\n\n    the symbolic atom {a} becomes a variable bound to a value, the\n    numeric atom {1}.\n\n    .. seealso:: :func:`Eval`, :func:`:=`, :func:`Clear`\n\n  warranty\n    Yacas is Free Software (*logiciel libre*) and comes with **NO\n    WARRANTY**.  See :ref:`lgpl-2.1` for more information.\n"
  },
  {
    "path": "docs/index.rst",
    "content": ".. _documentation:\n\nDocumentation\n=============\n\n.. toctree::\n    :maxdepth: 1\n\n    getting_started/index\n    tutorial/index\n    reference_manual/index\n    programming_in_yacas/index\n    book_of_algorithms/index\n    credits\n    license\n    glossary\n\nIndices and tables\n==================\n\n* :ref:`genindex`\n* :ref:`search`\n\n"
  },
  {
    "path": "docs/license.rst",
    "content": "*******\nLicense\n*******\n\nYacas is Free Software -- Free as in Freedom -- so you can redistribute yacas or\nmodify it under certain conditions. Yacas comes with ABSOLUTELY NO WARRANTY.\nSee the :ref:`GNU Lesser General Public License (LGPL) version 2.1 <lgpl-2.1>`\nor (at your discretion) `any later version <http://www.gnu.org/licenses/lgpl.html>`_\nfor the full conditions. Yacas documentation is distributed under the terms of \n:ref:`gfdl-1.1`.\n\n.. _lgpl-2.1:\n\n=================================\nGNU Lesser General Public License\n=================================\n\n.. code-block:: none\n    \n                    GNU LESSER GENERAL PUBLIC LICENSE\n                         Version 2.1, February 1999\n\n   Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n   Everyone is permitted to copy and distribute verbatim copies\n   of this license document, but changing it is not allowed.\n\n  [This is the first released version of the Lesser GPL.  It also counts\n   as the successor of the GNU Library Public License, version 2, hence\n   the version number 2.1.]\n\n                              Preamble\n\n    The licenses for most software are designed to take away your\n  freedom to share and change it.  By contrast, the GNU General Public\n  Licenses are intended to guarantee your freedom to share and change\n  free software--to make sure the software is free for all its users.\n\n    This license, the Lesser General Public License, applies to some\n  specially designated software packages--typically libraries--of the\n  Free Software Foundation and other authors who decide to use it.  You\n  can use it too, but we suggest you first think carefully about whether\n  this license or the ordinary General Public License is the better\n  strategy to use in any particular case, based on the explanations below.\n\n    When we speak of free software, we are referring to freedom of use,\n  not price.  Our General Public Licenses are designed to make sure that\n  you have the freedom to distribute copies of free software (and charge\n  for this service if you wish); that you receive source code or can get\n  it if you want it; that you can change the software and use pieces of\n  it in new free programs; and that you are informed that you can do\n  these things.\n\n    To protect your rights, we need to make restrictions that forbid\n  distributors to deny you these rights or to ask you to surrender these\n  rights.  These restrictions translate to certain responsibilities for\n  you if you distribute copies of the library or if you modify it.\n\n    For example, if you distribute copies of the library, whether gratis\n  or for a fee, you must give the recipients all the rights that we gave\n  you.  You must make sure that they, too, receive or can get the source\n  code.  If you link other code with the library, you must provide\n  complete object files to the recipients, so that they can relink them\n  with the library after making changes to the library and recompiling\n  it.  And you must show them these terms so they know their rights.\n\n    We protect your rights with a two-step method: (1) we copyright the\n  library, and (2) we offer you this license, which gives you legal\n  permission to copy, distribute and/or modify the library.\n\n    To protect each distributor, we want to make it very clear that\n  there is no warranty for the free library.  Also, if the library is\n  modified by someone else and passed on, the recipients should know\n  that what they have is not the original version, so that the original\n  author's reputation will not be affected by problems that might be\n  introduced by others.\n\n    Finally, software patents pose a constant threat to the existence of\n  any free program.  We wish to make sure that a company cannot\n  effectively restrict the users of a free program by obtaining a\n  restrictive license from a patent holder.  Therefore, we insist that\n  any patent license obtained for a version of the library must be\n  consistent with the full freedom of use specified in this license.\n\n    Most GNU software, including some libraries, is covered by the\n  ordinary GNU General Public License.  This license, the GNU Lesser\n  General Public License, applies to certain designated libraries, and\n  is quite different from the ordinary General Public License.  We use\n  this license for certain libraries in order to permit linking those\n  libraries into non-free programs.\n\n    When a program is linked with a library, whether statically or using\n  a shared library, the combination of the two is legally speaking a\n  combined work, a derivative of the original library.  The ordinary\n  General Public License therefore permits such linking only if the\n  entire combination fits its criteria of freedom.  The Lesser General\n  Public License permits more lax criteria for linking other code with\n  the library.\n\n    We call this license the \"Lesser\" General Public License because it\n  does Less to protect the user's freedom than the ordinary General\n  Public License.  It also provides other free software developers Less\n  of an advantage over competing non-free programs.  These disadvantages\n  are the reason we use the ordinary General Public License for many\n  libraries.  However, the Lesser license provides advantages in certain\n  special circumstances.\n\n    For example, on rare occasions, there may be a special need to\n  encourage the widest possible use of a certain library, so that it becomes\n  a de-facto standard.  To achieve this, non-free programs must be\n  allowed to use the library.  A more frequent case is that a free\n  library does the same job as widely used non-free libraries.  In this\n  case, there is little to gain by limiting the free library to free\n  software only, so we use the Lesser General Public License.\n\n    In other cases, permission to use a particular library in non-free\n  programs enables a greater number of people to use a large body of\n  free software.  For example, permission to use the GNU C Library in\n  non-free programs enables many more people to use the whole GNU\n  operating system, as well as its variant, the GNU/Linux operating\n  system.\n\n    Although the Lesser General Public License is Less protective of the\n  users' freedom, it does ensure that the user of a program that is\n  linked with the Library has the freedom and the wherewithal to run\n  that program using a modified version of the Library.\n\n    The precise terms and conditions for copying, distribution and\n  modification follow.  Pay close attention to the difference between a\n  \"work based on the library\" and a \"work that uses the library\".  The\n  former contains code derived from the library, whereas the latter must\n  be combined with the library in order to run.\n\n                    GNU LESSER GENERAL PUBLIC LICENSE\n     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n    0. This License Agreement applies to any software library or other\n  program which contains a notice placed by the copyright holder or\n  other authorized party saying it may be distributed under the terms of\n  this Lesser General Public License (also called \"this License\").\n  Each licensee is addressed as \"you\".\n\n    A \"library\" means a collection of software functions and/or data\n  prepared so as to be conveniently linked with application programs\n  (which use some of those functions and data) to form executables.\n\n    The \"Library\", below, refers to any such software library or work\n  which has been distributed under these terms.  A \"work based on the\n  Library\" means either the Library or any derivative work under\n  copyright law: that is to say, a work containing the Library or a\n  portion of it, either verbatim or with modifications and/or translated\n  straightforwardly into another language.  (Hereinafter, translation is\n  included without limitation in the term \"modification\".)\n\n    \"Source code\" for a work means the preferred form of the work for\n  making modifications to it.  For a library, complete source code means\n  all the source code for all modules it contains, plus any associated\n  interface definition files, plus the scripts used to control compilation\n  and installation of the library.\n\n    Activities other than copying, distribution and modification are not\n  covered by this License; they are outside its scope.  The act of\n  running a program using the Library is not restricted, and output from\n  such a program is covered only if its contents constitute a work based\n  on the Library (independent of the use of the Library in a tool for\n  writing it).  Whether that is true depends on what the Library does\n  and what the program that uses the Library does.\n\n    1. You may copy and distribute verbatim copies of the Library's\n  complete source code as you receive it, in any medium, provided that\n  you conspicuously and appropriately publish on each copy an\n  appropriate copyright notice and disclaimer of warranty; keep intact\n  all the notices that refer to this License and to the absence of any\n  warranty; and distribute a copy of this License along with the\n  Library.\n\n    You may charge a fee for the physical act of transferring a copy,\n  and you may at your option offer warranty protection in exchange for a\n  fee.\n\n    2. You may modify your copy or copies of the Library or any portion\n  of it, thus forming a work based on the Library, and copy and\n  distribute such modifications or work under the terms of Section 1\n  above, provided that you also meet all of these conditions:\n\n      a) The modified work must itself be a software library.\n\n      b) You must cause the files modified to carry prominent notices\n      stating that you changed the files and the date of any change.\n\n      c) You must cause the whole of the work to be licensed at no\n      charge to all third parties under the terms of this License.\n\n      d) If a facility in the modified Library refers to a function or a\n      table of data to be supplied by an application program that uses\n      the facility, other than as an argument passed when the facility\n      is invoked, then you must make a good faith effort to ensure that,\n      in the event an application does not supply such function or\n      table, the facility still operates, and performs whatever part of\n      its purpose remains meaningful.\n\n      (For example, a function in a library to compute square roots has\n      a purpose that is entirely well-defined independent of the\n      application.  Therefore, Subsection 2d requires that any\n      application-supplied function or table used by this function must\n      be optional: if the application does not supply it, the square\n      root function must still compute square roots.)\n\n  These requirements apply to the modified work as a whole.  If\n  identifiable sections of that work are not derived from the Library,\n  and can be reasonably considered independent and separate works in\n  themselves, then this License, and its terms, do not apply to those\n  sections when you distribute them as separate works.  But when you\n  distribute the same sections as part of a whole which is a work based\n  on the Library, the distribution of the whole must be on the terms of\n  this License, whose permissions for other licensees extend to the\n  entire whole, and thus to each and every part regardless of who wrote\n  it.\n\n  Thus, it is not the intent of this section to claim rights or contest\n  your rights to work written entirely by you; rather, the intent is to\n  exercise the right to control the distribution of derivative or\n  collective works based on the Library.\n\n  In addition, mere aggregation of another work not based on the Library\n  with the Library (or with a work based on the Library) on a volume of\n  a storage or distribution medium does not bring the other work under\n  the scope of this License.\n\n    3. You may opt to apply the terms of the ordinary GNU General Public\n  License instead of this License to a given copy of the Library.  To do\n  this, you must alter all the notices that refer to this License, so\n  that they refer to the ordinary GNU General Public License, version 2,\n  instead of to this License.  (If a newer version than version 2 of the\n  ordinary GNU General Public License has appeared, then you can specify\n  that version instead if you wish.)  Do not make any other change in\n  these notices.\n\n    Once this change is made in a given copy, it is irreversible for\n  that copy, so the ordinary GNU General Public License applies to all\n  subsequent copies and derivative works made from that copy.\n\n    This option is useful when you wish to copy part of the code of\n  the Library into a program that is not a library.\n\n    4. You may copy and distribute the Library (or a portion or\n  derivative of it, under Section 2) in object code or executable form\n  under the terms of Sections 1 and 2 above provided that you accompany\n  it with the complete corresponding machine-readable source code, which\n  must be distributed under the terms of Sections 1 and 2 above on a\n  medium customarily used for software interchange.\n\n    If distribution of object code is made by offering access to copy\n  from a designated place, then offering equivalent access to copy the\n  source code from the same place satisfies the requirement to\n  distribute the source code, even though third parties are not\n  compelled to copy the source along with the object code.\n\n    5. A program that contains no derivative of any portion of the\n  Library, but is designed to work with the Library by being compiled or\n  linked with it, is called a \"work that uses the Library\".  Such a\n  work, in isolation, is not a derivative work of the Library, and\n  therefore falls outside the scope of this License.\n\n    However, linking a \"work that uses the Library\" with the Library\n  creates an executable that is a derivative of the Library (because it\n  contains portions of the Library), rather than a \"work that uses the\n  library\".  The executable is therefore covered by this License.\n  Section 6 states terms for distribution of such executables.\n\n    When a \"work that uses the Library\" uses material from a header file\n  that is part of the Library, the object code for the work may be a\n  derivative work of the Library even though the source code is not.\n  Whether this is true is especially significant if the work can be\n  linked without the Library, or if the work is itself a library.  The\n  threshold for this to be true is not precisely defined by law.\n\n    If such an object file uses only numerical parameters, data\n  structure layouts and accessors, and small macros and small inline\n  functions (ten lines or less in length), then the use of the object\n  file is unrestricted, regardless of whether it is legally a derivative\n  work.  (Executables containing this object code plus portions of the\n  Library will still fall under Section 6.)\n\n    Otherwise, if the work is a derivative of the Library, you may\n  distribute the object code for the work under the terms of Section 6.\n  Any executables containing that work also fall under Section 6,\n  whether or not they are linked directly with the Library itself.\n\n    6. As an exception to the Sections above, you may also combine or\n  link a \"work that uses the Library\" with the Library to produce a\n  work containing portions of the Library, and distribute that work\n  under terms of your choice, provided that the terms permit\n  modification of the work for the customer's own use and reverse\n  engineering for debugging such modifications.\n\n    You must give prominent notice with each copy of the work that the\n  Library is used in it and that the Library and its use are covered by\n  this License.  You must supply a copy of this License.  If the work\n  during execution displays copyright notices, you must include the\n  copyright notice for the Library among them, as well as a reference\n  directing the user to the copy of this License.  Also, you must do one\n  of these things:\n\n      a) Accompany the work with the complete corresponding\n      machine-readable source code for the Library including whatever\n      changes were used in the work (which must be distributed under\n      Sections 1 and 2 above); and, if the work is an executable linked\n      with the Library, with the complete machine-readable \"work that\n      uses the Library\", as object code and/or source code, so that the\n      user can modify the Library and then relink to produce a modified\n      executable containing the modified Library.  (It is understood\n      that the user who changes the contents of definitions files in the\n      Library will not necessarily be able to recompile the application\n      to use the modified definitions.)\n\n      b) Use a suitable shared library mechanism for linking with the\n      Library.  A suitable mechanism is one that (1) uses at run time a\n      copy of the library already present on the user's computer system,\n      rather than copying library functions into the executable, and (2)\n      will operate properly with a modified version of the library, if\n      the user installs one, as long as the modified version is\n      interface-compatible with the version that the work was made with.\n\n      c) Accompany the work with a written offer, valid for at\n      least three years, to give the same user the materials\n      specified in Subsection 6a, above, for a charge no more\n      than the cost of performing this distribution.\n\n      d) If distribution of the work is made by offering access to copy\n      from a designated place, offer equivalent access to copy the above\n      specified materials from the same place.\n\n      e) Verify that the user has already received a copy of these\n      materials or that you have already sent this user a copy.\n\n    For an executable, the required form of the \"work that uses the\n  Library\" must include any data and utility programs needed for\n  reproducing the executable from it.  However, as a special exception,\n  the materials to be distributed need not include anything that is\n  normally distributed (in either source or binary form) with the major\n  components (compiler, kernel, and so on) of the operating system on\n  which the executable runs, unless that component itself accompanies\n  the executable.\n\n    It may happen that this requirement contradicts the license\n  restrictions of other proprietary libraries that do not normally\n  accompany the operating system.  Such a contradiction means you cannot\n  use both them and the Library together in an executable that you\n  distribute.\n\n    7. You may place library facilities that are a work based on the\n  Library side-by-side in a single library together with other library\n  facilities not covered by this License, and distribute such a combined\n  library, provided that the separate distribution of the work based on\n  the Library and of the other library facilities is otherwise\n  permitted, and provided that you do these two things:\n\n      a) Accompany the combined library with a copy of the same work\n      based on the Library, uncombined with any other library\n      facilities.  This must be distributed under the terms of the\n      Sections above.\n\n      b) Give prominent notice with the combined library of the fact\n      that part of it is a work based on the Library, and explaining\n      where to find the accompanying uncombined form of the same work.\n\n    8. You may not copy, modify, sublicense, link with, or distribute\n  the Library except as expressly provided under this License.  Any\n  attempt otherwise to copy, modify, sublicense, link with, or\n  distribute the Library is void, and will automatically terminate your\n  rights under this License.  However, parties who have received copies,\n  or rights, from you under this License will not have their licenses\n  terminated so long as such parties remain in full compliance.\n\n    9. You are not required to accept this License, since you have not\n  signed it.  However, nothing else grants you permission to modify or\n  distribute the Library or its derivative works.  These actions are\n  prohibited by law if you do not accept this License.  Therefore, by\n  modifying or distributing the Library (or any work based on the\n  Library), you indicate your acceptance of this License to do so, and\n  all its terms and conditions for copying, distributing or modifying\n  the Library or works based on it.\n\n    10. Each time you redistribute the Library (or any work based on the\n  Library), the recipient automatically receives a license from the\n  original licensor to copy, distribute, link with or modify the Library\n  subject to these terms and conditions.  You may not impose any further\n  restrictions on the recipients' exercise of the rights granted herein.\n  You are not responsible for enforcing compliance by third parties with\n  this License.\n\n    11. If, as a consequence of a court judgment or allegation of patent\n  infringement or for any other reason (not limited to patent issues),\n  conditions are imposed on you (whether by court order, agreement or\n  otherwise) that contradict the conditions of this License, they do not\n  excuse you from the conditions of this License.  If you cannot\n  distribute so as to satisfy simultaneously your obligations under this\n  License and any other pertinent obligations, then as a consequence you\n  may not distribute the Library at all.  For example, if a patent\n  license would not permit royalty-free redistribution of the Library by\n  all those who receive copies directly or indirectly through you, then\n  the only way you could satisfy both it and this License would be to\n  refrain entirely from distribution of the Library.\n\n  If any portion of this section is held invalid or unenforceable under any\n  particular circumstance, the balance of the section is intended to apply,\n  and the section as a whole is intended to apply in other circumstances.\n\n  It is not the purpose of this section to induce you to infringe any\n  patents or other property right claims or to contest validity of any\n  such claims; this section has the sole purpose of protecting the\n  integrity of the free software distribution system which is\n  implemented by public license practices.  Many people have made\n  generous contributions to the wide range of software distributed\n  through that system in reliance on consistent application of that\n  system; it is up to the author/donor to decide if he or she is willing\n  to distribute software through any other system and a licensee cannot\n  impose that choice.\n\n  This section is intended to make thoroughly clear what is believed to\n  be a consequence of the rest of this License.\n\n    12. If the distribution and/or use of the Library is restricted in\n  certain countries either by patents or by copyrighted interfaces, the\n  original copyright holder who places the Library under this License may add\n  an explicit geographical distribution limitation excluding those countries,\n  so that distribution is permitted only in or among countries not thus\n  excluded.  In such case, this License incorporates the limitation as if\n  written in the body of this License.\n\n    13. The Free Software Foundation may publish revised and/or new\n  versions of the Lesser General Public License from time to time.\n  Such new versions will be similar in spirit to the present version,\n  but may differ in detail to address new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the Library\n  specifies a version number of this License which applies to it and\n  \"any later version\", you have the option of following the terms and\n  conditions either of that version or of any later version published by\n  the Free Software Foundation.  If the Library does not specify a\n  license version number, you may choose any version ever published by\n  the Free Software Foundation.\n\n    14. If you wish to incorporate parts of the Library into other free\n  programs whose distribution conditions are incompatible with these,\n  write to the author to ask for permission.  For software which is\n  copyrighted by the Free Software Foundation, write to the Free\n  Software Foundation; we sometimes make exceptions for this.  Our\n  decision will be guided by the two goals of preserving the free status\n  of all derivatives of our free software and of promoting the sharing\n  and reuse of software generally.\n\n                              NO WARRANTY\n\n    15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\n  WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\n  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\n  OTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\n  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\n  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n  PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\n  LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\n  THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n    16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\n  WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\n  AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\n  FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\n  CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\n  LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\n  RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\n  FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\n  SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\n  DAMAGES.\n\n                       END OF TERMS AND CONDITIONS\n\n             How to Apply These Terms to Your New Libraries\n\n    If you develop a new library, and you want it to be of the greatest\n  possible use to the public, we recommend making it free software that\n  everyone can redistribute and change.  You can do so by permitting\n  redistribution under these terms (or, alternatively, under the terms of the\n  ordinary General Public License).\n\n    To apply these terms, attach the following notices to the library.  It is\n  safest to attach them to the start of each source file to most effectively\n  convey the exclusion of warranty; and each file should have at least the\n  \"copyright\" line and a pointer to where the full notice is found.\n\n      <one line to give the library's name and a brief idea of what it does.>\n      Copyright (C) <year>  <name of author>\n\n      This library is free software; you can redistribute it and/or\n      modify it under the terms of the GNU Lesser General Public\n      License as published by the Free Software Foundation; either\n      version 2.1 of the License, or (at your option) any later version.\n\n      This library is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n      Lesser General Public License for more details.\n\n      You should have received a copy of the GNU Lesser General Public\n      License along with this library; if not, write to the Free Software\n      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n\n  Also add information on how to contact you by electronic and paper mail.\n\n  You should also get your employer (if you work as a programmer) or your\n  school, if any, to sign a \"copyright disclaimer\" for the library, if\n  necessary.  Here is a sample; alter the names:\n\n    Yoyodyne, Inc., hereby disclaims all copyright interest in the\n    library `Frob' (a library for tweaking knobs) written by James Random Hacker.\n\n    <signature of Ty Coon>, 1 April 1990\n    Ty Coon, President of Vice\n\n  That's all there is to it!'\n\n.. _gfdl-1.1:\n    \n==============================\nGNU Free Documentation License\n==============================\n\n.. code-block:: none\n\n                    GNU Free Documentation License\n                       Version 1.1, March 2000\n\n     Copyright (C) 2000  Free Software Foundation, Inc.\n         51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\n     Everyone is permitted to copy and distribute verbatim copies\n     of this license document, but changing it is not allowed.\n\n\n    0. PREAMBLE\n\n    The purpose of this License is to make a manual, textbook, or other\n    written document \"free\" in the sense of freedom: to assure everyone\n    the effective freedom to copy and redistribute it, with or without\n    modifying it, either commercially or noncommercially.  Secondarily,\n    this License preserves for the author and publisher a way to get\n    credit for their work, while not being considered responsible for\n    modifications made by others.\n\n    This License is a kind of \"copyleft\", which means that derivative\n    works of the document must themselves be free in the same sense.  It\n    complements the GNU General Public License, which is a copyleft\n    license designed for free software.\n\n    We have designed this License in order to use it for manuals for free\n    software, because free software needs free documentation: a free\n    program should come with manuals providing the same freedoms that the\n    software does.  But this License is not limited to software manuals;\n    it can be used for any textual work, regardless of subject matter or\n    whether it is published as a printed book.  We recommend this License\n    principally for works whose purpose is instruction or reference.\n\n\n    1. APPLICABILITY AND DEFINITIONS\n\n    This License applies to any manual or other work that contains a\n    notice placed by the copyright holder saying it can be distributed\n    under the terms of this License.  The \"Document\", below, refers to any\n    such manual or work.  Any member of the public is a licensee, and is\n    addressed as \"you\".\n\n    A \"Modified Version\" of the Document means any work containing the\n    Document or a portion of it, either copied verbatim, or with\n    modifications and/or translated into another language.\n\n    A \"Secondary Section\" is a named appendix or a front-matter section of\n    the Document that deals exclusively with the relationship of the\n    publishers or authors of the Document to the Document's overall subject\n    (or to related matters) and contains nothing that could fall directly\n    within that overall subject.  (For example, if the Document is in part a\n    textbook of mathematics, a Secondary Section may not explain any\n    mathematics.)  The relationship could be a matter of historical\n    connection with the subject or with related matters, or of legal,\n    commercial, philosophical, ethical or political position regarding\n    them.\n\n    The \"Invariant Sections\" are certain Secondary Sections whose titles\n    are designated, as being those of Invariant Sections, in the notice\n    that says that the Document is released under this License.\n\n    The \"Cover Texts\" are certain short passages of text that are listed,\n    as Front-Cover Texts or Back-Cover Texts, in the notice that says that\n    the Document is released under this License.\n\n    A \"Transparent\" copy of the Document means a machine-readable copy,\n    represented in a format whose specification is available to the\n    general public, whose contents can be viewed and edited directly and\n    straightforwardly with generic text editors or (for images composed of\n    pixels) generic paint programs or (for drawings) some widely available\n    drawing editor, and that is suitable for input to text formatters or\n    for automatic translation to a variety of formats suitable for input\n    to text formatters.  A copy made in an otherwise Transparent file\n    format whose markup has been designed to thwart or discourage\n    subsequent modification by readers is not Transparent.  A copy that is\n    not \"Transparent\" is called \"Opaque\".\n\n    Examples of suitable formats for Transparent copies include plain\n    ASCII without markup, Texinfo input format, LaTeX input format, SGML\n    or XML using a publicly available DTD, and standard-conforming simple\n    HTML designed for human modification.  Opaque formats include\n    PostScript, PDF, proprietary formats that can be read and edited only\n    by proprietary word processors, SGML or XML for which the DTD and/or\n    processing tools are not generally available, and the\n    machine-generated HTML produced by some word processors for output\n    purposes only.\n\n    The \"Title Page\" means, for a printed book, the title page itself,\n    plus such following pages as are needed to hold, legibly, the material\n    this License requires to appear in the title page.  For works in\n    formats which do not have any title page as such, \"Title Page\" means\n    the text near the most prominent appearance of the work's title,\n    preceding the beginning of the body of the text.\n\n\n    2. VERBATIM COPYING\n\n    You may copy and distribute the Document in any medium, either\n    commercially or noncommercially, provided that this License, the\n    copyright notices, and the license notice saying this License applies\n    to the Document are reproduced in all copies, and that you add no other\n    conditions whatsoever to those of this License.  You may not use\n    technical measures to obstruct or control the reading or further\n    copying of the copies you make or distribute.  However, you may accept\n    compensation in exchange for copies.  If you distribute a large enough\n    number of copies you must also follow the conditions in section 3.\n\n    You may also lend copies, under the same conditions stated above, and\n    you may publicly display copies.\n\n\n    3. COPYING IN QUANTITY\n\n    If you publish printed copies of the Document numbering more than 100,\n    and the Document's license notice requires Cover Texts, you must enclose\n    the copies in covers that carry, clearly and legibly, all these Cover\n    Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on\n    the back cover.  Both covers must also clearly and legibly identify\n    you as the publisher of these copies.  The front cover must present\n    the full title with all words of the title equally prominent and\n    visible.  You may add other material on the covers in addition.\n    Copying with changes limited to the covers, as long as they preserve\n    the title of the Document and satisfy these conditions, can be treated\n    as verbatim copying in other respects.\n\n    If the required texts for either cover are too voluminous to fit\n    legibly, you should put the first ones listed (as many as fit\n    reasonably) on the actual cover, and continue the rest onto adjacent\n    pages.\n\n    If you publish or distribute Opaque copies of the Document numbering\n    more than 100, you must either include a machine-readable Transparent\n    copy along with each Opaque copy, or state in or with each Opaque copy\n    a publicly-accessible computer-network location containing a complete\n    Transparent copy of the Document, free of added material, which the\n    general network-using public has access to download anonymously at no\n    charge using public-standard network protocols.  If you use the latter\n    option, you must take reasonably prudent steps, when you begin\n    distribution of Opaque copies in quantity, to ensure that this\n    Transparent copy will remain thus accessible at the stated location\n    until at least one year after the last time you distribute an Opaque\n    copy (directly or through your agents or retailers) of that edition to\n    the public.\n\n    It is requested, but not required, that you contact the authors of the\n    Document well before redistributing any large number of copies, to give\n    them a chance to provide you with an updated version of the Document.\n\n\n    4. MODIFICATIONS\n\n    You may copy and distribute a Modified Version of the Document under\n    the conditions of sections 2 and 3 above, provided that you release\n    the Modified Version under precisely this License, with the Modified\n    Version filling the role of the Document, thus licensing distribution\n    and modification of the Modified Version to whoever possesses a copy\n    of it.  In addition, you must do these things in the Modified Version:\n\n    A. Use in the Title Page (and on the covers, if any) a title distinct\n       from that of the Document, and from those of previous versions\n       (which should, if there were any, be listed in the History section\n       of the Document).  You may use the same title as a previous version\n       if the original publisher of that version gives permission.\n    B. List on the Title Page, as authors, one or more persons or entities\n       responsible for authorship of the modifications in the Modified\n       Version, together with at least five of the principal authors of the\n       Document (all of its principal authors, if it has less than five).\n    C. State on the Title page the name of the publisher of the\n       Modified Version, as the publisher.\n    D. Preserve all the copyright notices of the Document.\n    E. Add an appropriate copyright notice for your modifications\n       adjacent to the other copyright notices.\n    F. Include, immediately after the copyright notices, a license notice\n       giving the public permission to use the Modified Version under the\n       terms of this License, in the form shown in the Addendum below.\n    G. Preserve in that license notice the full lists of Invariant Sections\n       and required Cover Texts given in the Document's license notice.\n    H. Include an unaltered copy of this License.\n    I. Preserve the section entitled \"History\", and its title, and add to\n       it an item stating at least the title, year, new authors, and\n       publisher of the Modified Version as given on the Title Page.  If\n       there is no section entitled \"History\" in the Document, create one\n       stating the title, year, authors, and publisher of the Document as\n       given on its Title Page, then add an item describing the Modified\n       Version as stated in the previous sentence.\n    J. Preserve the network location, if any, given in the Document for\n       public access to a Transparent copy of the Document, and likewise\n       the network locations given in the Document for previous versions\n       it was based on.  These may be placed in the \"History\" section.\n       You may omit a network location for a work that was published at\n       least four years before the Document itself, or if the original\n       publisher of the version it refers to gives permission.\n    K. In any section entitled \"Acknowledgements\" or \"Dedications\",\n       preserve the section's title, and preserve in the section all the\n       substance and tone of each of the contributor acknowledgements\n       and/or dedications given therein.\n    L. Preserve all the Invariant Sections of the Document,\n       unaltered in their text and in their titles.  Section numbers\n       or the equivalent are not considered part of the section titles.\n    M. Delete any section entitled \"Endorsements\".  Such a section\n       may not be included in the Modified Version.\n    N. Do not retitle any existing section as \"Endorsements\"\n       or to conflict in title with any Invariant Section.\n\n    If the Modified Version includes new front-matter sections or\n    appendices that qualify as Secondary Sections and contain no material\n    copied from the Document, you may at your option designate some or all\n    of these sections as invariant.  To do this, add their titles to the\n    list of Invariant Sections in the Modified Version's license notice.\n    These titles must be distinct from any other section titles.\n\n    You may add a section entitled \"Endorsements\", provided it contains\n    nothing but endorsements of your Modified Version by various\n    parties--for example, statements of peer review or that the text has\n    been approved by an organization as the authoritative definition of a\n    standard.\n\n    You may add a passage of up to five words as a Front-Cover Text, and a\n    passage of up to 25 words as a Back-Cover Text, to the end of the list\n    of Cover Texts in the Modified Version.  Only one passage of\n    Front-Cover Text and one of Back-Cover Text may be added by (or\n    through arrangements made by) any one entity.  If the Document already\n    includes a cover text for the same cover, previously added by you or\n    by arrangement made by the same entity you are acting on behalf of,\n    you may not add another; but you may replace the old one, on explicit\n    permission from the previous publisher that added the old one.\n\n    The author(s) and publisher(s) of the Document do not by this License\n    give permission to use their names for publicity for or to assert or\n    imply endorsement of any Modified Version.\n\n\n    5. COMBINING DOCUMENTS\n\n    You may combine the Document with other documents released under this\n    License, under the terms defined in section 4 above for modified\n    versions, provided that you include in the combination all of the\n    Invariant Sections of all of the original documents, unmodified, and\n    list them all as Invariant Sections of your combined work in its\n    license notice.\n\n    The combined work need only contain one copy of this License, and\n    multiple identical Invariant Sections may be replaced with a single\n    copy.  If there are multiple Invariant Sections with the same name but\n    different contents, make the title of each such section unique by\n    adding at the end of it, in parentheses, the name of the original\n    author or publisher of that section if known, or else a unique number.\n    Make the same adjustment to the section titles in the list of\n    Invariant Sections in the license notice of the combined work.\n\n    In the combination, you must combine any sections entitled \"History\"\n    in the various original documents, forming one section entitled\n    \"History\"; likewise combine any sections entitled \"Acknowledgements\",\n    and any sections entitled \"Dedications\".  You must delete all sections\n    entitled \"Endorsements.\"\n\n\n    6. COLLECTIONS OF DOCUMENTS\n\n    You may make a collection consisting of the Document and other documents\n    released under this License, and replace the individual copies of this\n    License in the various documents with a single copy that is included in\n    the collection, provided that you follow the rules of this License for\n    verbatim copying of each of the documents in all other respects.\n\n    You may extract a single document from such a collection, and distribute\n    it individually under this License, provided you insert a copy of this\n    License into the extracted document, and follow this License in all\n    other respects regarding verbatim copying of that document.\n\n\n    7. AGGREGATION WITH INDEPENDENT WORKS\n\n    A compilation of the Document or its derivatives with other separate\n    and independent documents or works, in or on a volume of a storage or\n    distribution medium, does not as a whole count as a Modified Version\n    of the Document, provided no compilation copyright is claimed for the\n    compilation.  Such a compilation is called an \"aggregate\", and this\n    License does not apply to the other self-contained works thus compiled\n    with the Document, on account of their being thus compiled, if they\n    are not themselves derivative works of the Document.\n\n    If the Cover Text requirement of section 3 is applicable to these\n    copies of the Document, then if the Document is less than one quarter\n    of the entire aggregate, the Document's Cover Texts may be placed on\n    covers that surround only the Document within the aggregate.\n    Otherwise they must appear on covers around the whole aggregate.\n\n\n    8. TRANSLATION\n\n    Translation is considered a kind of modification, so you may\n    distribute translations of the Document under the terms of section 4.\n    Replacing Invariant Sections with translations requires special\n    permission from their copyright holders, but you may include\n    translations of some or all Invariant Sections in addition to the\n    original versions of these Invariant Sections.  You may include a\n    translation of this License provided that you also include the\n    original English version of this License.  In case of a disagreement\n    between the translation and the original English version of this\n    License, the original English version will prevail.\n\n\n    9. TERMINATION\n\n    You may not copy, modify, sublicense, or distribute the Document except\n    as expressly provided for under this License.  Any other attempt to\n    copy, modify, sublicense or distribute the Document is void, and will\n    automatically terminate your rights under this License.  However,\n    parties who have received copies, or rights, from you under this\n    License will not have their licenses terminated so long as such\n    parties remain in full compliance.\n\n\n    10. FUTURE REVISIONS OF THIS LICENSE\n\n    The Free Software Foundation may publish new, revised versions\n    of the GNU Free Documentation License from time to time.  Such new\n    versions will be similar in spirit to the present version, but may\n    differ in detail to address new problems or concerns.  See\n    http://www.gnu.org/copyleft/.\n\n    Each version of the License is given a distinguishing version number.\n    If the Document specifies that a particular numbered version of this\n    License \"or any later version\" applies to it, you have the option of\n    following the terms and conditions either of that specified version or\n    of any later version that has been published (not as a draft) by the\n    Free Software Foundation.  If the Document does not specify a version\n    number of this License, you may choose any version ever published (not\n    as a draft) by the Free Software Foundation.\n\n\n    ADDENDUM: How to use this License for your documents\n\n    To use this License in a document you have written, include a copy of\n    the License in the document and put the following copyright and\n    license notices just after the title page:\n\n          Copyright (c)  YEAR  YOUR NAME.\n          Permission is granted to copy, distribute and/or modify this document\n          under the terms of the GNU Free Documentation License, Version 1.1\n          or any later version published by the Free Software Foundation;\n          with the Invariant Sections being LIST THEIR TITLES, with the\n          Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.\n          A copy of the license is included in the section entitled \"GNU\n          Free Documentation License\".\n\n    If you have no Invariant Sections, write \"with no Invariant Sections\"\n    instead of saying which ones are invariant.  If you have no\n    Front-Cover Texts, write \"no Front-Cover Texts\" instead of\n    \"Front-Cover Texts being LIST\"; likewise for Back-Cover Texts.\n\n    If your document contains nontrivial examples of program code, we\n    recommend releasing these examples in parallel under your choice of\n    free software license, such as the GNU General Public License,\n    to permit their use in free software.\n"
  },
  {
    "path": "docs/make.bat",
    "content": "@ECHO OFF\r\n\r\nREM Command file for Sphinx documentation\r\n\r\nif \"%SPHINXBUILD%\" == \"\" (\r\n\tset SPHINXBUILD=sphinx-build\r\n)\r\nset BUILDDIR=_build\r\nset ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .\r\nset I18NSPHINXOPTS=%SPHINXOPTS% .\r\nif NOT \"%PAPER%\" == \"\" (\r\n\tset ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%\r\n\tset I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%\r\n)\r\n\r\nif \"%1\" == \"\" goto help\r\n\r\nif \"%1\" == \"help\" (\r\n\t:help\r\n\techo.Please use `make ^<target^>` where ^<target^> is one of\r\n\techo.  html       to make standalone HTML files\r\n\techo.  dirhtml    to make HTML files named index.html in directories\r\n\techo.  singlehtml to make a single large HTML file\r\n\techo.  pickle     to make pickle files\r\n\techo.  json       to make JSON files\r\n\techo.  htmlhelp   to make HTML files and a HTML help project\r\n\techo.  qthelp     to make HTML files and a qthelp project\r\n\techo.  devhelp    to make HTML files and a Devhelp project\r\n\techo.  epub       to make an epub\r\n\techo.  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter\r\n\techo.  text       to make text files\r\n\techo.  man        to make manual pages\r\n\techo.  texinfo    to make Texinfo files\r\n\techo.  gettext    to make PO message catalogs\r\n\techo.  changes    to make an overview over all changed/added/deprecated items\r\n\techo.  xml        to make Docutils-native XML files\r\n\techo.  pseudoxml  to make pseudoxml-XML files for display purposes\r\n\techo.  linkcheck  to check all external links for integrity\r\n\techo.  doctest    to run all doctests embedded in the documentation if enabled\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"clean\" (\r\n\tfor /d %%i in (%BUILDDIR%\\*) do rmdir /q /s %%i\r\n\tdel /q /s %BUILDDIR%\\*\r\n\tgoto end\r\n)\r\n\r\n\r\n%SPHINXBUILD% 2> nul\r\nif errorlevel 9009 (\r\n\techo.\r\n\techo.The 'sphinx-build' command was not found. Make sure you have Sphinx\r\n\techo.installed, then set the SPHINXBUILD environment variable to point\r\n\techo.to the full path of the 'sphinx-build' executable. Alternatively you\r\n\techo.may add the Sphinx directory to PATH.\r\n\techo.\r\n\techo.If you don't have Sphinx installed, grab it from\r\n\techo.http://sphinx-doc.org/\r\n\texit /b 1\r\n)\r\n\r\nif \"%1\" == \"html\" (\r\n\t%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The HTML pages are in %BUILDDIR%/html.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"dirhtml\" (\r\n\t%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"singlehtml\" (\r\n\t%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"pickle\" (\r\n\t%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished; now you can process the pickle files.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"json\" (\r\n\t%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished; now you can process the JSON files.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"htmlhelp\" (\r\n\t%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished; now you can run HTML Help Workshop with the ^\r\n.hhp project file in %BUILDDIR%/htmlhelp.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"qthelp\" (\r\n\t%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished; now you can run \"qcollectiongenerator\" with the ^\r\n.qhcp project file in %BUILDDIR%/qthelp, like this:\r\n\techo.^> qcollectiongenerator %BUILDDIR%\\qthelp\\yacas.qhcp\r\n\techo.To view the help file:\r\n\techo.^> assistant -collectionFile %BUILDDIR%\\qthelp\\yacas.ghc\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"devhelp\" (\r\n\t%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"epub\" (\r\n\t%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The epub file is in %BUILDDIR%/epub.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"latex\" (\r\n\t%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished; the LaTeX files are in %BUILDDIR%/latex.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"latexpdf\" (\r\n\t%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex\r\n\tcd %BUILDDIR%/latex\r\n\tmake all-pdf\r\n\tcd %BUILDDIR%/..\r\n\techo.\r\n\techo.Build finished; the PDF files are in %BUILDDIR%/latex.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"latexpdfja\" (\r\n\t%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex\r\n\tcd %BUILDDIR%/latex\r\n\tmake all-pdf-ja\r\n\tcd %BUILDDIR%/..\r\n\techo.\r\n\techo.Build finished; the PDF files are in %BUILDDIR%/latex.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"text\" (\r\n\t%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The text files are in %BUILDDIR%/text.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"man\" (\r\n\t%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The manual pages are in %BUILDDIR%/man.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"texinfo\" (\r\n\t%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"gettext\" (\r\n\t%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The message catalogs are in %BUILDDIR%/locale.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"changes\" (\r\n\t%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.The overview file is in %BUILDDIR%/changes.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"linkcheck\" (\r\n\t%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Link check complete; look for any errors in the above output ^\r\nor in %BUILDDIR%/linkcheck/output.txt.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"doctest\" (\r\n\t%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Testing of doctests in the sources finished, look at the ^\r\nresults in %BUILDDIR%/doctest/output.txt.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"xml\" (\r\n\t%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The XML files are in %BUILDDIR%/xml.\r\n\tgoto end\r\n)\r\n\r\nif \"%1\" == \"pseudoxml\" (\r\n\t%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml\r\n\tif errorlevel 1 exit /b 1\r\n\techo.\r\n\techo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.\r\n\tgoto end\r\n)\r\n\r\n:end\r\n"
  },
  {
    "path": "docs/programming_in_yacas/index.rst",
    "content": "********************\nProgramming in Yacas\n********************\n\n\nThis part of the manual is a somewhat in-depth explanation of the\nYacas programming language and environment. It assumes that you have\nworked through the introductory tutorial. You should consult the\nfunction reference about how to use the various Yacas functions\nmentioned here.\n\nThis document should get you started programming in Yacas. There are\nsome basic explanations and hands-on tutorials.\n\n======================\nThe Yacas architecture\n======================\n\nYacas is designed as a small core engine that interprets a library of\nscripts. The core engine provides the syntax parser and a number of\nhard-wired functions, such as {Set()} or {MathExp()} which cannot be\nredefined by the user. The script library resides in the scripts\ndirectory \"{scripts/}\" and contains higher-level definitions of\nfunctions and constants. The library scripts are on equal footing with\nany code the user executes interactively or any files the user loads.\n\nGenerally, all core functions have plain names and almost all are not\n\"bodied\" or infix operators. The file {corefunctions.h} in the source\ntree lists declarations of all kernel functions callable from Yacas;\nconsult it for reference.  For many of the core functions, the script\nlibrary already provides convenient aliases. For instance, the\naddition operator \"{+}\" is defined in the script {scripts/standard}\nwhile the actual addition of numbers is performed through the built-in\nfunction {MathAdd}.\n\nStartup, scripts and {.def} files\n---------------------------------\n\nWhen Yacas is first started or restarted, it executes the script\n{yacasinit.ys} in the scripts directory. This script may load some\nother scripts. In order to start up quickly, Yacas does not execute\nall other library scripts at first run or at restart. It only executes\nthe file {yacasinit.ys} and all {.def} files in the scripts. The\n{.def} files tell the system where it can find definitions for various\nlibrary functions. Library is divided into \"packages\" stored in\n\"repository\" directories. For example, the function {ArcTan} is\ndefined in the {stdfuncs} package; the library file is\n{stdfuncs.rep/}{code.ys} and the {.def} file is\n{stdfuncs.rep}{/code.ys.def}. The function {ArcTan} mentioned in the\n{.def} file, therefore Yacas will know to load the package {stdfuncs}\nwhen the user invokes {ArcTan}. This way Yacas knows where to look for\nany given function without actually loading the file where the\nfunction is defined.\n\nThere is one exception to the strategy of delayed loading of the\nlibrary scripts. Namely, the syntax definitions of infix, prefix,\npostfix and bodied functions, such as {Infix(\"*\",4)} cannot be delayed\n(it is currently in the file {stdopers.ys}). If it were delayed, the\nYacas parser would encounter {1+2} (typed by the user) and generate a\nsyntax error before it has a chance to load the definition of the\noperator \"{+}\".\n\nObject types\n------------\n\nYacas supports two basic kinds of objects: atoms and compounds. Atoms\nare (integer or real, arbitrary-precision) numbers such as {2.71828},\nsymbolic variables such as {A3} and character strings. Compounds\ninclude functions and expressions, e.g. {Cos(a-b)} and lists,\ne.g. {{1+a,2+b,3+c}}.\n\nThe type of an object is returned by the built-in function {Type}, for\nexample: ::\n\n  In> Type(a);\n  Out> \"\";\n  In> Type(F(x));\n  Out> \"F\";\n  In> Type(x+y);\n  Out> \"+\";\n  In> Type({1,2,3});\n  Out> \"List\";\n\nInternally, atoms are stored as strings and compounds as lists. (The\nYacas lexical analyzer is case-sensitive, so {List} and {list} are\ndifferent atoms.) The functions {String()} and {Atom()} convert\nbetween atoms and strings. A Yacas list {{1,2,3}} is internally a list\n{(List 1 2 3)} which is the same as a function call {List(1,2,3)} and\nfor this reason the \"type\" of a list is the string {\"List\"}. During\nevaluation, atoms can be interpreted as numbers, or as variables that\nmay be bound to some value, while compounds are interpreted as\nfunction calls.\n\nNote that atoms that result from an {Atom()} call may be\ninvalid and never evaluate to anything. For example,\n{Atom(3X)} is an atom with string representation \"3X\" but\nwith no other properties.\n\nCurrently, no other lowest-level objects are provided by the core\nengine besides numbers, atoms, strings, and lists. There is, however,\na possibility to link some externally compiled code that will provide\nadditional types of objects.  Those will be available in Yacas as\n\"generic objects.\"  For example, fixed-size arrays are implemented in\nthis way.\n\n=======================\nYacas evaluation scheme\n=======================\n\nEvaluation of an object is performed either explicitly by the built-in\ncommand {Eval()} or implicitly when assigning variables or calling\nfunctions with the object as argument (except when a function does not\nevaluate that argument). Evaluation of an object can be explicitly\ninhibited using {Hold()}.  To make a function not evaluate one of its\narguments, a {HoldArg(funcname, argname)} must be declared for that\nfunction.\n\nInternally, all expressions are either atoms or lists (perhaps\nnested). Use {FullForm()} to see the internal form of an expression. A\nYacas list expression written as {{a, b}} is represented internally as\n{(List a b)}, equivalently to a function call {List(a,b)}.\n\nEvaluation of an atom goes as follows: if the atom is bound locally as\na variable, the object it is bound to is returned, otherwise, if it is\nbound as a global variable then that is returned. Otherwise, the atom\nis returned unevaluated.  Note that if an atom is bound to an\nexpression, that expression is considered as final and is not\nevaluated again.\n\nInternal lists of atoms are generally interpreted in the following\nway: the first atom of the list is some command, and the atoms\nfollowing in the list are considered the arguments. The engine first\ntries to find out if it is a built-in command (core function). In that\ncase, the function is executed.  Otherwise, it could be a user-defined\nfunction (with a \"rule database\"), and in that case the rules from the\ndatabase are applied to it. If none of the rules are applicable, or if\nno rules are defined for it, the object is returned unevaluated.\n\nApplication of a rule to an expression transforms it into a different\nexpression to which other rules may be applicable. Transformation by\nmatching rules continues until no more rules are applicable, or until\na \"terminating\" rule is encountered. A \"terminating\" rule is one that\nreturns {Hold()} or {UnList()} of some expression. Calling these\nfunctions gives an unevaluated expression because it terminates the\nprocess of evaluation itself.\n\nThe main properties of this scheme are the following. When objects are\nassigned to variables, they generally are evaluated (except if you are\nusing the {Hold()} function) because assignment {var := value} is\nreally a function call to {Set(var, value)} and this function\nevaluates its second argument (but not its first argument). When\nreferencing that variable again, the object which is its value will\nnot be re-evaluated. Also, the default behavior of the engine is to\nreturn the original expression if it could not be evaluated. This is a\ndesired behavior if evaluation is used for simplifying expressions.\n\nOne major design flaw in Yacas (one that other functional languages\nlike LISP also have) is that when some expression is re-evaluated in\nanother environment, the local variables contained in the expression\nto be evaluated might have a different meaning. In this case it might\nbe useful to use the functions {LocalSymbols} and\n{TemplateFunction}. Calling ::\n\n  LocalSymbols(a,b)\n  a*b;\n\nresults in \"{a}\" and \"{b}\" in the multiplication being substituted\nwith unique symbols that can not clash with other variables that may\nbe used elsewhere. Use {TemplateFunction} instead of {Function} to\ndefine a function whose parameters should be treated as unique\nsymbols.\n\nConsider the following example: ::\n\n  In> f1(x):=Apply(\"+\",{x,x});\n  Out> True\n\nThe function {f1} simply adds its argument to itself. Now calling this\nfunction with some argument: ::\n\n  In> f1(Sin(a))\n  Out> 2*Sin(a)\n\nyields the expected result. However, if we pass as an argument an\nexpression containing the variable {x}, things go wrong: ::\n\n  In> f1(Sin(x))\n  Out> 2*Sin(Sin(x))\n\nThis happens because within the function, {x} is bound to {Sin(x)},\nand since it is passed as an argument to {Apply} it will be\nre-evaluated, resulting in {Sin(Sin(x))}. {TemplateFunction} solves\nthis by making sure the arguments can not collide like this (by using\n{LocalSymbols}: ::\n\n  In> TemplateFunction(\"f2\",{x}) Apply(\"+\",{x,x});\n  Out> True\n  In> f2(Sin(a))\n  Out> 2*Sin(a)\n  In> f2(Sin(x))\n  Out> 2*Sin(x)\n\nIn general one has to be careful when functions like {Apply}, {Map} or\n{Eval} (or derivatives) are used.\n\n\n=====\nRules\n=====\n\n*Rules* are special properties of functions that are applied when\nthe function object is being evaluated. A function object could have\njust one rule bound to it; this is similar to a \"subroutine\" having a\n\"function body\" in usual procedural languages. However, Yacas function\nobjects can also have several rules bound to them. This is analogous\nof having several alternative \"function bodies\" that are executed\nunder different circumstances. This design is more suitable for\nsymbolic manipulations.\n\nA function is identified by its name as returned by {Type} and the\nnumber of arguments, or \"arity\". The same name can be used with\ndifferent arities to define different functions: {f(x)} is said to\n\"have arity 1\" and {f(x,y)} has arity 2. Each of these functions may\npossess its own set of specific rules, which we shall call a \"rule\ndatabase\" of a function.\n\nEach function should be first declared with the built-in command\n{RuleBase} as follows: ::\n\n  RuleBase(\"FunctionName\",{argument list});\n\nSo, a new (and empty) rule database for {f(x,y)} could be created by\ntyping {RuleBase(\"f\",{x,y})}. The names for the arguments \"x\" and \"y\"\nhere are arbitrary, but they will be globally stored and must be later\nused in descriptions of particular rules for the function {f}. After\nthe new rulebase declaration, the evaluation engine of Yacas will\nbegin to really recognize {f} as a function, even though no function\nbody or equivalently no rules have been defined for it yet.\n\nThe shorthand operator {:=} for creating user functions that we\nillustrated in the tutorial is actually defined in the scripts and it\nmakes the requisite call to the {RuleBase()} function.  After a\n{RuleBase()} call you can specify parsing properties for the function;\nfor example, you could make it an infix or bodied operator.\n\nNow we can add some rules to the rule database for a function. A rule\nsimply states that if a specific function object with a specific arity\nis encountered in an expression and if a certain predicate is true,\nthen Yacas should replace this function with some other expression. To\ntell Yacas about a new rule you can use the built-in {Rule}\ncommand. This command is what does the real work for the somewhat more\naesthetically pleasing {... # ... <-- ...} construct we have seen in\nthe tutorial. You do not have to call {RuleBase()} explicitly if you\nuse that construct.\n\nHere is the general syntax for a {Rule()} call: ::\n\n  Rule(\"foo\", arity, precedence, pred) body;\n\nThis specifies that for function {foo} with given {arity} ({foo(a,b)}\nhas arity 2), there is a rule that if {pred} is true, then {body}\nshould be evaluated, and the original expression replaced by the\nresult.  Predicate and body can use the symbolic names of arguments\nthat were declared in the {RuleBase} call.\n\nAll rules for a given function can be erased with a call to\n{Retract(funcname, arity)}. This is useful, for instance, when too\nmany rules have been entered in the interactive mode. This call\nundefines the function and also invalidates the {RuleBase}\ndeclaration.\n\nYou can specify that function arguments are not evaluated before they\nare bound to the parameter: {HoldArg(\"foo\",a)} would then declare that\nthe a arguments in both {foo(a)} and {foo(a,b)} should not be\nevaluated before bound to {a}. Here the argument name {a} should be\nthe same as that used in the {RuleBase()} call when declaring these\nfunctions.  Inhibiting evaluation of certain arguments is useful for\nprocedures performing actions based partly on a variable in the\nexpression, such as integration, differentiation, looping, etc., and\nwill be typically used for functions that are algorithmic and\nprocedural by nature.\n\nRule-based programming normally makes heavy use of recursion and it is\nimportant to control the order in which replacement rules are to be\napplied. For this purpose, each rule is given a *precedence*.\nPrecedences go from low to high, so all rules with precedence 0 will\nbe tried before any rule with precedence 1.\n\nYou can assign several rules to one and the same function, as long as\nsome of the predicates differ. If none of the predicates are true, the\nfunction is returned with its arguments evaluated.\n\nThis scheme is slightly slower for ordinary functions that just have\none rule (with the predicate :data:`True`), but it is a desired behavior for\nsymbolic manipulation. You can gradually build up your own functions,\nincrementally testing their properties.\n\nExamples of using rules\n-----------------------\n\nAs a simple illustration, here are the actual {RuleBase()}\nand {Rule()} calls needed to define the factorial function: ::\n\n  In> RuleBase(\"f\",{n});\n  Out> True;\n  In> Rule(\"f\", 1, 10, n=0) 1;\n  Out> True;\n  In> Rule(\"f\", 1, 20, IsInteger(n) And n>0) n*f(n-1);\n  Out> True;\n\nThis definition is entirely equivalent to the one in the\ntutorial. {f(4)} should now return 24, while {f(a)} should return just\n{f(a)} if {a} is not bound to any value.\n\nThe {Rule} commands in this example specified two rules for function\n{f} with arity 1: one rule with precedence 10 and predicate {n=0}, and\nanother with precedence 20 and the predicate that returns :data:`True` only\nif {n} is a positive integer. Rules with lowest precedence get\nevaluated first, so the rule with precedence 10 will be tried before\nthe rule with precedence 20. Note that the predicates and the body use\nthe name \"n\" declared by the {RuleBase()} call.\n\nAfter declaring {RuleBase()} for a function, you could tell the parser\nto treat this function as a postfix operator: ::\n\n  In> Postfix(\"f\");\n  Out> True;\n  In> 4 f;\n  Out> 24;\n\nThere is already a function {Function} defined in the standard scripts\nthat allows you to construct simple functions. An example would be ::\n\n  Function (\"FirstOf\", {list})  list[1] ;\n\nwhich simply returns the first element of a list. This could also have\nbeen written as ::\n\n  Function(\"FirstOf\", {list})\n  [\n      list[1] ;\n  ];\n\nAs mentioned before, the brackets {[ ]} are also used to combine\nmultiple operations to be performed one after the other. The result of\nthe last performed action is returned.\n\nFinally, the function {FirstOf} could also have been defined by typing ::\n\n  FirstOf(list):=list[1] ;\n\n=======================================\nStructured programming and control flow\n=======================================\n\nSome functions useful for control flow are already defined in Yacas's\nstandard library. Let's look at a possible definition of a looping\nfunction {ForEach}. We shall here consider a somewhat simple-minded\ndefinition, while the actual {ForEach} as defined in the standard\nscript \"controlflow\" is a little more sophisticated. ::\n\n  Function(\"ForEach\",{foreachitem,\n    foreachlist,foreachbody})\n  [\n     Local(foreachi,foreachlen);\n     foreachlen:=Length(foreachlist);\n     foreachi:=0;\n     While (foreachi < foreachlen)\n     [\n       foreachi++;\n       MacroLocal(foreachitem);\n       MacroSet(foreachitem,\n         foreachlist[foreachi]);\n       Eval(foreachbody);\n     ];\n  ];\n    \n  Bodied(\"ForEach\");\n  UnFence(\"ForEach\",3);\n  HoldArg(\"ForEach\",foreachitem);\n  HoldArg(\"ForEach\",foreachbody);\n\nFunctions like this should probably be defined in a separate file. You\ncan load such a file with the command {Load(\"file\")}. This is an\nexample of a macro-like function.  Let's first look at the last few\nlines. There is a {Bodied(...)} call, which states that the syntax for\nthe function {ForEach()} is {ForEach(item,{list}) body;} -- that is,\nthe last argument to the command {ForEach} should be outside its\nbrackets. {UnFence(...)} states that this function can use the local\nvariables of the calling function. This is necessary, since the body\nto be evaluated for each item will probably use some local variables\nfrom that surrounding.\n\nFinally, {HoldArg(\"function\",argument)} specifies that the argument\n\"{argument}\" should not be evaluated before being bound to that\nvariable. This holds for {foreachitem} and {foreachbody}, since\n{foreachitem} specifies a variable to be set to that value, and\n{foreachbody} is the expression that should be evaluated *after*\nthat variable is set.\n\nInside the body of the function definition there are calls to\n{Local(...)}.  {Local()} declares some local variable that will only\nbe visible within a block {[ ... ]}. The command {MacroLocal()} works\nalmost the same. The difference is that it evaluates its arguments\nbefore performing the action on it. This is needed in this case,\nbecause the variable {foreachitem} is bound to a variable to be used\nas the loop iterator, and it is *the variable it is bound to*\nthat we want to make local, not {foreachitem} itself. {MacroSet()}\nworks similarly: it does the same as {Set()} except that it also first\nevaluates the first argument, thus setting the variable requested by\nthe user of this function. The {Macro}... functions in the built-in\nfunctions generally perform the same action as their non-macro\nversions, apart from evaluating an argument it would otherwise not\nevaluate.\n\nTo see the function in action, you could type: ::\n\n  ForEach(i,{1,2,3}) [Write(i); NewLine();];\n\nThis should print 1, 2 and 3, each on a new line.\n\nNote: the variable names \"foreach...\" have been chosen so they won't\nget confused with normal variables you use. This is a major design\nflaw in this language. Suppose there was a local variable\n{foreachitem}, defined in the calling function, and used in\n{foreachbody}. These two would collide, and the interpreter would use\nonly the last defined version. In general, when writing a function\nthat calls {Eval()}, it is a good idea to use variable names that can\nnot collide with user's variables. This is generally the single\nlargest cause of bugs when writing programs in Yacas. This issue\nshould be addressed in the future.\n\n==========================\nAdditional syntactic sugar\n==========================\n\nThe parser is extended slightly to allow for fancier constructs.\n\n* Lists, e.g. {{a,b}}. This then is parsed into the internal notation\n  {(List a b)} , but will be printed again as {{a,b};}\n* Statement blocks such as {[} statement1 {;} statement2{;];}. This is\n  parsed into a Lisp object {(Prog} {(}statement1 {)} {(}statement2\n  {))}, and printed out again in the proper form.\n* Object argument accessors in the form of {expr[ index ]}. These are\n  mapped internally to {Nth(expr,index)}. The value of {index}=0\n  returns the operator of the object, {index}=1 the first argument,\n  etc. So, if {expr} is {foo(bar)}, then {expr[0]} returns {foo}, and\n  {expr[1]} returns {bar}. Since lists of the form {{...}} are\n  essentially the same as {List(...)}, the same accessors can be used\n  on lists.\n* Function blocks such as ::\n\n    While (i < 10)\n      [\n        Write(i);\n        i:=i+1;\n      ];\n\nThe expression directly following the {While(...)} block is added as a\nlast argument to the {While(...)} call. So {While(a)b;} is parsed to\nthe internal form {(While a b).}\n\nThis scheme allows coding the algorithms in an almost C-like syntax.\n\nStrings are generally represented with quotes around them, e.g.  \"this\nis a string\". Backslash {\\} in a string will unconditionally add the\nnext character to the string, so a quote can be added with {\\\"} (a\nbackslash-quote sequence).\n\n======================================\nUsing \"Macro rules\" (e.g. {NFunction})\n======================================\n\nThe Yacas language allows to have rules whose definitions are\ngenerated at runtime. In other words, it is possible to write rules\n(or \"functions\") that, as a side-effect, will define other rules, and\nthose other rules will depend on some parts of the expression the\noriginal function was applied to.\n\nThis is accomplished using functions {MacroRuleBase}, {MacroRule},\n{MacroRulePattern}. These functions evaluate their arguments\n(including the rule name, predicate and body) and define the rule that\nresults from this evaluation.\n\nNormal, \"non-Macro\" calls such as {Rule()} will not evaluate their\narguments and this is a desired feature. For example, suppose we\ndefined a new predicate like this, ::\n\n  RuleBase(\"IsIntegerOrString, {x});\n  Rule(\"IsIntegerOrString\", 1, 1, True)\n      IsInteger(x) And IsString(x);\n\nIf the {Rule()} call were to evaluate its arguments, then the \"body\"\nargument, {IsInteger(x) And IsString(x)}, would be evaluated to\n:data:`False` since {x} is an atom, so we would have defined the predicate\nto be always :data:`False`, which is not at all what we meant to do. For\nthis reason, the {Rule} calls do not evaluate their arguments.\n\nConsider however the following situation. Suppose we have a function\n{f(arglist)} where {arglist} is its list of arguments, and suppose we\nwant to define a function {Nf(arglist)} with the same arguments which\nwill evaluate {f(arglist)} and return only when all arguments from\n{arglist} are numbers, and return unevaluated {Nf(arglist)}\notherwise. This can of course be done by a usual rule such as ::\n\n  Rule(\"Nf\", 3, 0, IsNumericList({x,y,z}))\n    <-- \"f\" @ {x,y,z};\n\nHere {IsNumericList} is a predicate that checks whether all elements\nof a given list are numbers. (We deliberately used a {Rule} call\ninstead of an easier-to-read {<--} operator to make it easier to\ncompare with what follows.)\n\nHowever, this will have to be done for every function {f}\nseparately. We would like to define a procedure that will define {Nf},\ngiven *any* function {f}. We would like to use it like this: ::\n\n  NFunction(\"Nf\", \"f\", {x,y,z});\n\nAfter this function call we expect to be able to use the function\n{Nf}.\n\nHere is how we could naively try to implement {NFunction} (and fail):\n::\n\n  NFunction(new'name, old'name, arg'list) := [\n    MacroRuleBase(new'name, arg'list);\n    MacroRule(new'name, Length(arg'list), 0,\n      IsNumericList(arg'list)\n      )\n    new'name @ arg'list;\n  ];\n\nNow, this just does not do anything remotely right. {MacroRule}\nevaluates its arguments. Since {arg'list} is an atom and not a list of\nnumbers at the time we are defining this, {IsNumericList(arg'list)}\nwill evaluate to :data:`False` and the new rule will be defined with a\npredicate that is always :data:`False`, i.e. it will be never applied.\n\nThe right way to figure this out is to realize that the {MacroRule}\ncall evaluates all its arguments and passes the results to a {Rule}\ncall. So we need to see exactly what {Rule()} call we need to produce\nand then we need to prepare the arguments of {MacroRule} so that they\nevaluate to the right values.  The {Rule()} call we need is something\nlike this: ::\n\n  Rule(\"actual new name\", <actual # of args>, 0,\n    IsNumericList({actual arg list})\n  )  \"actual new name\" @ {actual arg list};\n\nNote that we need to produce expressions such as {\"new name\" @\narg'list} and not *results* of evaluation of these\nexpressions. We can produce these expressions by using {UnList()},\ne.g. ::\n\n  UnList({Atom(\"@\"), \"Sin\", {x}})\n\nproduces ::\n\n  \"Sin\" @ {x};\n\nbut not {Sin(x)}, and ::\n\n  UnList({IsNumericList, {1,2,x}})\n\nproduces the expression ::\n\n  IsNumericList({1,2,x});\n\nwhich is not further evaluated.\n\nHere is a second version of {NFunction()} that works: ::\n\n  NFunction(new'name, old'name, arg'list) := [\n    MacroRuleBase(new'name, arg'list);\n    MacroRule(new'name, Length(arg'list), 0,\n      UnList({IsNumericList, arg'list})\n    )\n      UnList({Atom(\"@\"), old'name, arg'list});\n  ];\n\nNote that we used {Atom(\"@\")} rather than just the bare atom {@}\nbecause {@} is a prefix operator and prefix operator names as bare\natoms do not parse (they would be confused with applications of a\nprefix operator to what follows).\n\nFinally, there is a more concise (but less general) way of defining\n{NFunction()} for functions with known number of arguments, using the\nbackquoting mechanism. The backquote operation will first substitute\nvariables in an expression, without evaluating anything else, and then\nwill evaluate the resulting expression a second time. The code for\nfunctions of just one variable may look like this: ::\n\n  N1Function(new'name, old'name) :=\n      `( @new'name(x_IsNumber) <-- @old'name(x) );\n\nThis executes a little slower than the above version, because the\nbackquote needs to traverse the expression twice, but makes for much\nmore readable code.\n\n===============\nMacro expansion\n===============\n\nYacas supports macro expansion (back-quoting). An expression can be\nback-quoted by putting a ``\\``` in front of it. Within the back-quoted\nexpression, all atoms that have a ``@`` in front of them get replaced\nwith the value of that atom (treated as a variable), and then the\nresulting expression is evaluated: ::\n\n  In> x:=y\n  Out> y\n  In> `(@x:=2)\n  Out> 2\n  In> x\n  Out> y\n  In> y\n  Out> 2\n\nThis is useful in cases where within an expression one sub-expression\nis not evaluated. For instance, transformation rules can be built\ndynamically, before being declared. This is a particularly powerful\nfeature that allows a programmer to write programs that write\nprograms.  The idea is borrowed from Lisp.\n\nAs the above example shows, there are similarities with the\n``Macro...`` functions, that serve the same purpose for specific\nexpressions.  For example, for the above code, one could also have\ncalled ``MacroSet``::\n\n  In> MacroSet(x,3)\n  Out> True;\n  In> x\n  Out> y;\n  In> y\n  Out> 3;\n\nThe difference is that ``MacroSet``, and in general the ``Macro...``\nfunctions, are faster than their back-quoted counterparts.  This is\nbecause with back-quoting, first a new expression is built before it\nis evaluated. The advantages of back-quoting are readability and\nflexibility (the number of ``Macro...`` functions is limited, whereas\nback-quoting can be used anywhere).\n\nWhen an ``@`` operator is placed in front of a function call, the\nfunction call is replaced::\n\n  In> plus:=Add\n  Out> Add;\n  In> `(@plus(1,2,3))\n  Out> 6;\n\nApplication of pure functions is also possible by using macro\nexpansion::\n\n  In> pure:={{a,b},a+b}; \n  Out> {{a,b},a+b};\n  In> ` @pure(2,3); \n  Out> 5;\n\nPure (nameless) functions are useful for declaring a temporary\nfunction, that has functionality depending on the current environment\nit is in, or as a way to call driver functions. In the case of drivers\n(interfaces to specific functionality), a variable can be bound to a\nfunction to be evaluated to perform a specific task. That way several\ndrivers can be around, with one bound to the variables holding the\nfunctions that will be called.\n\n==========================\nScope of variable bindings\n==========================\n\nWhen setting variables or retrieving variable values, variables are\nautomatically bound global by default. You can explicitly specify\nvariables to be local to a block such as a function body; this will\nmake them invisible outside the block. Blocks have the form {[}\nstatement1{;} statement2{;} {]} and local variables are declared by\nthe {Local()} function.\n\nWhen entering a block, a new stack frame is pushed for the local\nvariables; it means that the code inside a block doesn't see the local\nvariables of the *caller* either!  You can tell the interpreter\nthat a function should see local variables of the calling environment;\nto do this, declare UnFence(funcname, arity) on that function.\n\n=========================\nEvaluation of expressions\n=========================\n\nWhen programming in some language, it helps to have a mental model of\nwhat goes on behind the scenes when evaluating expressions, or in this\ncase simplifying expressions.\n\nThis section aims to explain how evaluation (and simplification) of\nexpressions works internally, in yacas.\n\n=================\nThe LISP heritage\n=================\n\nRepresentation of expressions\n-----------------------------\n\nMuch of the inner workings is based on how LISP-like languages are\nbuilt up. When an expression is entered, or composed in some fashion,\nit is converted into a prefix form much like you get in LISP: ::\n\n  a+b    ->    (+ a b)\n  Sin(a) ->    (Sin a)\n\nHere the sub-expression is changed into a list of so-called \"atoms\",\nwhere the first atom is a function name of the function to be invoked,\nand the atoms following are the arguments to be passed in as\nparameters to that function.\n\nYacas has the function :func:`FullForm` to show the internal representation::\n\n  In> FullForm(a+b)\n  (+ a b )\n  Out> a+b;\n  In> FullForm(Sin(a))\n  (Sin a )\n  Out> Sin(a);\n  In> FullForm(a+b+c)\n  (+ (+ a b )c )\n  Out> a+b+c;\n\nThe internal representation is very close to what :func:`FullForm` shows\non screen. ``{a+b+c}`` would be ``{(+ (+ a b )c )}`` internally, or::\n\n    ()\n    |\n    |\n    +  -> () -> c\n           |\n           |\n           + -> a -> b\n\n\n==========\nEvaluation\n==========\n\nAn expression like described above is done in the following manner:\nfirst the arguments are evaluated (if they need to be evaluated,\nyacas can be told to not evaluate certain parameters to functions),\nand only then are these arguments passed in to the function for\nevaluation. They are passed in by binding local variables to the\nvalues, so these arguments are available as local values.\n\nFor instance, suppose we are evaluating ``2*3+4``. This first gets\nchanged to the internal representation ``(+ (* 2 3 )4 )``. Then,\nduring evaluation, the top expression refers to function \"{+}\".  Its\narguments are ``(* 2 3)`` and {4}. First ``(* 2 3)`` gets evaluated.\nThis is a function call to the function ``*`` with arguments {2} and\n{3}, which evaluate to themselves. Then the function \"{*}\" is invoked\nwith these arguments. The yacas standard script library has code\nthat accepts numeric input and performs the multiplication\nnumerically, resulting in {6}.\n\nThe second argument to the top-level \"{+}\" is {4}, which evaluates\nto itself. \n\nNow, both arguments to the \"{+}\" function have been evaluated, and\nthe results are {6} and {4}. Now the \"{+}\" function is invoked.\nThis function also has code in the script library to actually\nperform the addition when the arguments are numeric, so the result\nis 10: ::\n\n  In> FullForm(Hold(2*3+4))\n  (+ (* 2 3 )4 )\n  Out> 2*3+4;\n  In> 2*3+4\n  Out> 10;\n\nNote that in yacas, the script language does not define a ``+``\nfunction in the core. This and other functions are all implemented in\nthe script library.  The feature *when the arguments to* ``+`` *are\nnumeric, perform the numeric addition* is considered to be a *policy*\nwhich should be configurable.  It should not be a part of the core\nlanguage.\n\nIt is surprisingly difficult to keep in mind that evaluation is bottom\nup, and that arguments are evaluated before the function call is\nevaluated. In some sense, you might feel that the evaluation of the\narguments is part of evaluation of the function. It is not. Arguments\nare evaluated before the function gets called.\n\nSuppose we define the function :func:`f`, which adds two numbers, and\ntraces itself, as::\n\n  In> f(a,b):= \\\n  In> [\\\n  In> Local(result);\\\n  In> Echo(\"Enter f with arguments \",a,b);\\\n  In> result:=a+b;\\\n  In> Echo(\"Leave f with result \",result);\\\n  In> result;\\\n  In> ];\n  Out> True;\n\nThen the following interaction shows this principle: ::\n\n  In> f(f(2,3),4)\n  Enter f with arguments 2 3 \n  Leave f with result 5 \n  Enter f with arguments 5 4 \n  Leave f with result 9 \n  Out> 9;\n\nThe first Enter/Leave combination is for ``f(2,3)``, and only then is\nthe outer call to :func:`f` entered.\n\nThis has important consequences for the way yacas simplifies\nexpressions: the expression trees are traversed bottom up, as the\nlowest parts of the expression trees are simplified first, before\nbeing passed along up to the calling function.\n\n=================================================\nYacas-specific extensions for CAS implementations\n=================================================\n\nYacas has a few language features specifically designed for use when\nimplementing a CAS.\n\nThe transformation rules\n------------------------\n\nWorking with transformation rules is explained in the introduction and\ntutorial book. This section mainly deals with how yacas works with\ntransformation rules under the hood.\n\nA transformation rule consists of two parts: a condition that an\nexpression should match, and a result to be substituted for the\nexpression if the condition holds. The most common way to specify a\ncondition is a pattern to be matched to an expression.\n\nA pattern is again simply an expression, stored in internal format: ::\n\n  In> FullForm(a_IsInteger+b_IsInteger*(_x))\n  (+ (_ a IsInteger )(* (_ b IsInteger )(_ x )))\n  Out> a _IsInteger+b _IsInteger*_x;\n\nYacas maintains structures of transformation rules, and tries to\nmatch them to the expression being evaluated. It first tries to match\nthe structure of the pattern to the expression. In the above case, it\ntries to match to {a+b*x}. If this matches, local variables {a}, {b}\nand {x} are declared and assigned the sub-trees of the expression\nbeing matched. Then the predicates are tried on each of them: in this\ncase, {IsInteger(a)} and {IsInteger(b)} should both return :data:`True`.\n\nNot shown in the above case, are post-predicates. They get evaluated\nafterwards. This post-predicate must also evaluate to :data:`True`.  If the\nstructure of the expression matches the structure of the pattern, and\nall predicates evaluate to :data:`True`, the pattern matches and the\ntransformation rule is applied, meaning the right hand side is\nevaluated, with the local variables mentioned in the pattern\nassigned. This evaluation means all transformation rules are\nre-applied to the right-hand side of the expression.\n\nNote that the arguments to a function are evaluated first, and only\nthen is the function itself called. So the arguments are evaluated,\nand then the transformation rules applied on it. The main function\ndefines its parameters also, so these get assigned to local variables\nalso, before trying the patterns with their associated local\nvariables.\n\nHere is an example making the fact that the names in a pattern are\nlocal variables more explicit: ::\n\n    In> f1(_x,_a) <-- x+a\n    Out> True;\n    In> f2(_x,_a) <-- [Local(a); x+a;];\n    Out> True;\n    In> f1(1,2)\n    Out> 3;\n    In> f2(1,2)\n    Out> a+1;\n\nUsing different rules in different cases\n----------------------------------------\n\nIn a lot of cases, the algorithm to be invoked depends on the type of\nthe arguments. Or the result depends on the form of the input\nexpression. This results in the typical \"case\" or \"switch\" statement,\nwhere the code to evaluate to determine the result depends on the form\nof the input expression, or the type of the arguments, or some other\nconditions.\n\nYacas allows to define several transformation rules for one and the\nsame function, if the rules are to be applied under different\nconditions.\n\nSuppose the function {f} is defined, a factorial function: ::\n\n  10 # f(0) <-- 1;\n  20 # f(n_IsPositiveInteger) <-- n*f(n-1);\n\nThen interaction can look like: ::\n\n  In> f(3)\n  Out> 6;\n  In> f(a)\n  Out> f(a);\n\nIf the left hand side is matched by the expression being considered,\nthen the right hand side is evaluated. A subtle but important thing to\nnote is that this means that the whole body of transformation rules is\nthus re-applied to the right-hand side of the {<--} operator.\n\nEvaluation goes bottom-up, evaluating (simplifying) the lowest parts\nof a tree first, but for a tree that matches a transformation rule,\nthe substitution essentially means return the result of evaluating the\nright-hand side. Transformation rules are re-applied, on the right\nhand side of the transformation rule, and the original expression can\nbe thought of as been substituted by the result of evaluating this\nright-hand side, which is supposed to be a \"simpler\" expression, or a\nresult closer to what the user wants.\n\nInternally, the function {f} is built up to resemble the following\npseudo-code: ::\n\n  f(n)\n  {\n     if (n = 1)\n       return 1;\n     else if (IsPositiveInteger(n))\n       return n*f(n-1);\n     else return f(n) unevaluated;\n  }\n\nThe transformation rules are thus combined into one big statement that\ngets executed, with each transformation rule being a if-clause in the\nstatement to be evaluated.  Transformation rules can be spread over\ndifferent files, and combined in functional groups. This adds to the\nreadability.  The alternative is to write the full body of each\nfunction as one big routine, which becomes harder to maintain as the\nfunction becomes larger and larger, and hard or impossible to extend.\n\nOne nice feature is that functionality is easy to extend without\nmodifying the original source code: ::\n\n  In> Ln(x*y)\n  Out> Ln(x*y);\n  In> Ln(_x*_y) <-- Ln(x) + Ln(y)\n  Out> True;\n  In> Ln(x*y)\n  Out> Ln(x)+Ln(y);\n\nThis is generally not advisable, due to the fact that it alters the\nbehavior of the entire system. But it can be useful in some\ninstances. For instance, when introducing a new function {f(x)}, one\ncan decide to define a derivative explicitly, and a way to simplify it\nnumerically: ::\n\n  In> f(_x)_InNumericMode() <-- Exp(x)\n  Out> True;\n  In> (Deriv(_x)f(_y)) <-- f(y)*(Deriv(x)y);\n  Out> True;\n  In> f(2)\n  Out> f(2);\n  In> N(f(2))\n  Out> 7.3890560989;\n  In> Exp(2)\n  Out> Exp(2);\n  In> N(Exp(2))\n  Out> 7.3890560989;\n  In> D(x)f(a*x)\n  Out> f(a*x)*a;\n\n\n=======================================\nThe \"Evaluation is Simplification\" hack\n=======================================\n\nOne of the ideas behind the yacas scripting language is that\nevaluation is used for simplifying expressions.  One consequence of\nthis is that objects can be returned unevaluated when they can not be\nsimplified further. This happens to variables that are not assigned,\nfunctions that are not defined, or function invocations where the\narguments passed in as parameters are not actually handled by any code\nin the scripts.  An integral that can not be performed by yacas\nshould be returned unevaluated::\n\n  In> 2+3\n  Out> 5;\n  In> a+b\n  Out> a+b;\n  In> Sin(a)\n  Out> Sin(a);\n  In> Sin(0)\n  Out> 0;\n  In> Integrate(x)Ln(x)\n  Out> x*Ln(x)-x;\n  In> Integrate(x)Ln(Sin(x))\n  Out> Integrate(x)Ln(Sin(x));\n  In> a!\n  Out> a!;\n  In> 3!\n  Out> 6;\n\nOther languages usually do not allow evaluation of unbound variables,\nor undefined functions. In yacas, these are interpreted as some yet\nundefined global variables or functions, and returned unevaluated.\n\n======================\nDestructive operations\n======================\n\nYacas tries to keep as few copies of objects in memory as\npossible. Thus when assigning the value of one variable to another, a\nreference is copied, and both variables refer to the same memory,\nphysically. This is relevant for programming; for example, one should\nuse :func:`FlatCopy` to actually make a new copy of an object.  Another\nfeature relevant to reference semantics is \"destructive operations\";\nthese are functions that modify their arguments rather than work on a\ncopy. Destructive operations on lists are generally recognized because\ntheir name starts with \"Destructive\", e.g. {DestructiveDelete}. One\nother destructive operation is assignment of a list element through\n{list[index] := ...}.\n\nSome examples to illustrate destructive operations on lists: ::\n\n  In> x1:={a,b,c}\n  Out> {a,b,c};\n\nA list {x1} is created. ::\n\n  In> FullForm(x1)\n  (List a b c )\n  Out> {a,b,c};\n  In> x2:=z:x1\n  Out> {z,a,b,c};\n\nA new list {x2} is {z} appended to {x1}. The {:} operation creates a\ncopy of {x1} before appending, so {x1} is unchanged by this. ::\n\n  In> FullForm(x2)\n  (List z a b c )\n  Out> {z,a,b,c};\n  In> x2[1]:=y\n  Out> True;\n\nWe have modified the first element of {x2}, but {x1} is still the\nsame. ::\n\n  In> x2\n  Out> {y,a,b,c};\n  In> x1\n  Out> {a,b,c};\n  In> x2[2]:=A\n  Out> True;\n\nWe have modified the second element of {x2}, but {x1} is still the\nsame. ::\n\n  In> x2\n  Out> {y,A,b,c};\n  In> x1\n  Out> {a,b,c};\n  In> x2:=x1\n  Out> {A,b,c};\n\nNow {x2} and {x1} refer to the same list. ::\n\n  In> x2[1]:=A\n  Out> True;\n\nWe have modified the first element of {x2}, and {x1} is also modified. ::\n\n  In> x2\n  Out> {A,b,c};\n  In> x1\n  Out> {A,b,c};\n\nA programmer should always be cautious when dealing with destructive\noperations. Sometimes it is not desirable to change the original\nexpression.  The language deals with it this way because of\nperformance considerations.  Operations can be made non-destructive by\nusing {FlatCopy}: ::\n\n  In> x1:={a,b,c}\n  Out> {a,b,c};\n  In> DestructiveReverse(x1)\n  Out> {c,b,a};\n  In> x1\n  Out> {a};\n  In> x1:={a,b,c}\n  Out> {a,b,c};\n  In> DestructiveReverse(FlatCopy(x1))\n  Out> {c,b,a};\n  In> x1\n  Out> {a,b,c};\n\n{FlatCopy} copies the elements of an expression only at the top level\nof nesting.  This means that if a list contains sub-lists, they are\nnot copied, but references to them are copied instead: ::\n\n  In> dict1:={}\n  Out> {};\n  In> dict1[\"name\"]:=\"John\";\n  Out> True;\n  In> dict2:=FlatCopy(dict1)\n  Out> {{\"name\",\"John\"}};\n  In> dict2[\"name\"]:=\"Mark\";\n  Out> True;\n  In> dict1\n  Out> {{\"name\",\"Mark\"}};\n\nA workaround for this is to use {Subst} to copy the entire tree: ::\n\n  In> dict1:={}\n  Out> {};\n  In> dict1[\"name\"]:=\"John\";\n  Out> True;\n  In> dict2:=Subst(a,a)(dict1)\n  Out> {{\"name\",\"John\"}};\n  In> dict2[\"name\"]:=\"Mark\";\n  Out> True;\n  In> dict1\n  Out> {{\"name\",\"John\"}};\n  In> dict2\n  Out> {{\"name\",\"Mark\"}};\n\n\n============  \nCoding style\n============\n\n\nIntroduction\n------------\n\nThis chapter intends to describe the coding style and conventions\napplied in Yacas in order to make sure the engine always returns the\ncorrect result. This is an attempt at fending off such errors by\ncombining rule-based programming with a clear coding style which\nshould make help avoid these mistakes.\n\nInteractions of rules and types\n-------------------------------\n\nOne unfortunate disadvantage of rule-based programming is that rules\ncan sometimes cooperate in unwanted ways.\n\nOne example of how rules can produce unwanted results is the rule\n``a*0 <-- 0``.  This would always seem to be true. However, when a is\na vector, e.g.  {a:={b,c,d}}, then ``a*0`` should actually return\n{{0,0,0}}, that is, a zero vector. The rule ``a*0 <-- 0`` actually\nchanges the type of the expression from a vector to an integer! This\ncan have severe consequences when other functions using this\nexpressions as an argument expect a vector, or even worse, have a\ndefinition of how to work on vectors, and a different one for working\non numbers.\n\nWhen writing rules for an operator, it is assumed that the operator\nworking on arguments, e.g. :func:`Cos` or ``*``, will always have the same\nproperties regardless of the arguments. The Taylor series expansion of\n:math:`\\cos(a)` is the same regardless of whether :math:`a` is a real number,\ncomplex number or even a matrix.  Certain trigonometric identities\nshould hold for the :func:`Cos` function, regardless of the type of its\nargument.\n\nIf a function is defined which does not adhere to these rules when\napplied to another type, a different function name should be used, to\navoid confusion.\n\nBy default, if a variable has not been bound yet, it is assumed to be\na number. If it is in fact a more complex object, e.g. a vector, then\nyou can declare it to be an \"incomplete type\" vector, using\n{Object(\"IsVector\",x)} instead of {x}. This expression will evaluate\nto {x} if and only if {x} is a vector at that moment of\nevaluation. Otherwise it returns unevaluated, and thus stays an\nincomplete type.\n\nSo this means the type of a variable is numeric unless otherwise\nstated by the user, using the \"{Object}\" command. No rules should ever\nwork on incomplete types. It is just meant for delayed simplification.\n\nThe topic of implicit type of an object is important, since many rules\nneed to assume something about their argument types.\n\nOrdering of rules\n-----------------\n\nThe implementor of a rule set can specify the order in which rules\nshould be tried. This can be used to let the engine try more specific\nrules (those involving more elements in the pattern) before trying\nless specific rules.  Ordering of rules can be also explicitly given\nby precedence numbers. The Yacas engine will split the expression into\nsubexpressions, and will try to apply all matching rules to a given\nsubexpression in order of precedence.\n\nA rule with precedence 100 is defined by the syntax such as ::\n\n  100 # f(_x + _y) <-- f(x) + f(y);\n\nThe problem mentioned above with a rule for vectors and scalars could\nbe solved by making two rules:\n\n1. :math:`a*b` (if :math:`b` is a vector and :math:`a` is a number) ``<--``\n   return vector of each component multiplied by :math:`a`.\n2. :math:`a*0` ``<--`` :math:`0`\n\n\nSo vector multiplication would be tried first.\n\nThe ordering of the precedence of the rules in the standard math\nscripts is currently:\n\n* 50-60: Args are numbers: directly calculate. These are put in the\n  beginning, so they are tried first. This is useful for quickly\n  obtaining numeric results if all the arguments are numeric already,\n  and symbolic transformations are not necessary.\n* 100-199: tautologies. Transformations that do not change the type of\n  the argument, and are always true.\n* 200-399: type-specific transformations. Transformations for specific\n  types of objects.\n* 400-599: transformations on scalars (variables are assumed to be\n  scalars). Meaning transformations that can potentially change the\n  type of an argument.\n\n=============================\nWriting new library functions\n=============================\n\nWhen you implement new library functions, you need to make your new\ncode compatible and consistent with the rest of the library. Here are\nsome relevant considerations.\n\nTo evaluate or not to evaluate\n------------------------------\n\nCurrently, a general policy in the library is that functions do\nnothing unless their arguments actually allow something to be\nevaluated. For instance, if the function expects a variable name but\ninstead gets a list, or expects a list but instead gets a string, in\nmost cases it seems to be a good idea to do nothing and return\nunevaluated. The unevaluated expression will propagate and will be\neasy to spot. Most functions can accomplish this by using\ntype-checking predicates such as {IsInteger} in rules.\n\nWhen dealing with numbers, Yacas tries to maintain exact answers as\nmuch as possible and evaluate to floating-point only when explicitly\ntold so (using {N()}). The general evaluation strategy for numerical\nfunctions such as {Sin} or {Gamma} is the following:\n\n* If {InNumericMode()} returns :data:`True` and the arguments are numbers\n  (perhaps complex numbers), the function should evaluate its result\n  in floating-point to current precision.\n* Otherwise, if the arguments are such that the result can be\n  calculated exactly, it should be evaluated and\n  returned. E.g. {Sin(Pi/2)} returns {1}.\n* Otherwise the function should return unevaluated (but usually with\n  its arguments evaluated).\n\nHere are some examples of this behavior: ::\n\n  In> Sin(3)\n  Out> Sin(3);\n  In> Gamma(8)\n  Out> 5040;\n  In> Gamma(-11/2)\n  Out> (64*Sqrt(Pi))/10395;\n  In> Gamma(8/7)\n  Out> Gamma(8/7);\n  In> N(Gamma(8/7))\n  Out> 0.9354375629;\n  In> N(Gamma(8/7+x))\n  Out> Gamma(x+1.1428571428);\n  In> Gamma(12/6+x)\n  Out> Gamma(x+2);\n\nTo implement this behavior, {Gamma} and other mathematical functions\nusually have two variants: the \"symbolic\" one and the \"numerical\"\none. For instance, there are {Sin} and {MathSin}, {Ln} and\n{Internal'LnNum}, {Gamma} and {Internal'GammaNum}. (Here {MathSin}\nhappens to be a core function but it is not essential.) The\n\"numerical\" functions always evaluate to floating-point results. The\n\"symbolic\" function serves as a front-end; it evaluates when the\nresult can be expressed exactly, or calls the \"numerical\" function if\n{InNumericMode()} returns :data:`True`, and otherwise returns unevaluated.\n\nThe \"symbolic\" function usually has multiple rules while the\n\"numerical\" function is usually just one large block of\nnumber-crunching code.\n\n\nUsing :func:`N` and :func:`InNumericMode` in scripts\n----------------------------------------------------\n\nAs a rule, :func:`N` should be avoided in code that implements basic\nnumerical algorithms. This is because :func:`N` itself is implemented in\nthe library and it may need to use some of these algorithms.\nArbitrary-precision math can be handled by core functions such as\n:func:`MathDivide`, :func:`MathSin` and so on, without using :func:`N`.\nFor example, if your code needs to evaluate :math:`\\sqrt{\\pi}` to many\ndigits as an intermediate result, it is better to write\n``MathSqrt(Internal'Pi())`` than ``N(Sqrt(Pi))`` because it makes for faster,\nmore reliable code.\n\nUsing :func:`Builtin'Precision'Set`\n-----------------------------------\n\nThe usual assumption is that numerical functions will evaluate\nfloating-point results to the currently set precision. For\nintermediate calculations, a higher working precision is sometimes\nneeded. In this case, your function should set the precision back to\nthe original value at the end of the calculation and round off the\nresult.\n\nUsing verbose mode\n------------------\n\nFor routines using complicated algorithms, or when evaluation takes a\nlong time, it is usually helpful to print some diagnostic information,\nso that the user can at least watch some progress. The current\nconvention is that if :func:`InVerboseMode` returns :data:`True`, functions may\nprint diagnostic information. (But do not print too much!). Verbose\nmode is turned on by using the function :func:`V`. The\nexpression is evaluated in verbose mode.\n\nProcedural programming or rule-based programming?\n-------------------------------------------------\n\nTwo considerations are relevant to this decision. First, whether to\nuse multiple rules with predicates or one rule with multiple {If()}s.\nConsider the following sample code for the \"double factorial\" function\n:math:n!! := n(n-2)\\ldots 1` written using predicates and rules::\n\n   1# 0 !! <-- 1;\n   1# 1 !! <-- 1;\n   2# (n_IsEven) !! <-- 2^(n/2)*n!;\n   3# (n_IsOdd) !! <-- n*(n-2)!!;\n\nand an equivalent code with one rule: ::\n\n    n!! := If(n=0 Or n=1, 1,\n      If(IsEven(n), 2^(n/2)*n!,\n      If(IsOdd(n), n*(n-2)!!, Hold(n!!)))\n    );\n\n(Note: This is not the way :math:`n!!` is implemented in the library.) The\nfirst version is a lot more clear. Yacas is very quick in rule\nmatching and evaluation of predicates, so the first version is\n(marginally) faster. So it seems better to write a few rules with\npredicates than one rule with multiple :func:If` statements.\n\nThe second question is whether to use recursion or loops. Recursion\nmakes code more elegant but it is slower and limited in depth.\nCurrently the default recursion depth of :math:1000` is enough for most\ncasual calculations and yet catches infinite recursion errors\nrelatively quickly. Because of clearer code, it seems better to use\nrecursion in situations where the number of list elements will never\nbecome large. In numerical applications, such as evaluation of Taylor\nseries, recursion usually does not pay off.\n\nReporting errors\n----------------\n\nErrors occurring because of invalid argument types should be reported\nonly if absolutely necessary. (In the future there may be a static\ntype checker implemented that will make explicit checking\nunnecessary.)\n\nErrors of invalid values, e.g. a negative argument of real logarithm\nfunction, or a malformed list, mean that a human has probably made a\nmistake, so the errors need to be reported. \"Internal errors\", i.e.\nprogram bugs, certainly need to be reported.\n\nThere are currently two facilities for reporting errors: a \"hard\" one\nand a \"soft\" one.\n\nThe \"hard\" error reporting facility is the function {Check}. For\nexample, if {x}={-1}, then ::\n\n  Check(x>0,\"bad x\");\n\nwill immediately halt the execution of a Yacas script and print the\nerror messsage. This is implemented as a C++ exception. A drawback of\nthis mechanism is that the Yacas stack unwinding is not performed by\nthe Yacas interpreter, so global variables such as {InNumericMode()},\n{Verbose}, {Builtin'Precision'Set()} may keep the intermediate values\nthey had been assigned just before the error occurred. Also, sometimes\nit is better for the program to be able to catch the error and\ncontinue.\n\n.. todo:: the above will hopefully be solved soon, as we can now trap\n          exceptions in the scripts.\n\nThe \"soft\" error reporting is provided by the functions {Assert} and\n{IsError}, e.g. ::\n\n    Assert(\"domain\", x) x>0;\n    If(IsError(\"domain\"), ...);\n\nThe error will be reported but execution will continue normally until\nsome other function \"handles\" the error (prints the error message or\ndoes something else appropriate for that error). Here the string\n{\"domain\"} is the \"error type\" and {x} will be the information object\nfor this error. The error object can be any expression, but it is\nprobably a good idea to choose a short and descriptive string for the\nerror type.\n\nThe function {GetErrorTableau()} returns an associative list that\naccumulates all reported error objects. When errors are \"handled\",\ntheir objects should be removed from the list. The utility function\n{DumpErrors()} is a simple error handler that prints all errors and\nclears the list.  Other handlers are {GetError} and\n{ClearError}. These functions may be used to handle errors when it is\nsafe to do so.\n\nThe \"soft\" error reporting facility is safer and more flexible than\nthe \"hard\" facility. However, the disadvantage is that errors are not\nreported right away and pointless calculations may continue for a\nwhile until an error is handled.\n\n=================================================\nAdvanced example 1: parsing expressions ({CForm})\n=================================================\n\nIn this chapter we show how Yacas represents expressions and how one\ncan build functions that work on various types of expressions. Our\nspecific example will be {CForm()}, a standard library function that\nconverts Yacas expressions into C or C++ code. Although the input\nformat of Yacas expressions is already very close to C and perhaps\ncould be converted to C by means of an external text filter, it is\ninstructive to understand how to use Yacas to parse its own\nexpressions and produce the corresponding C code. Here we shall only\ndesign the core mechanism of {CForm()} and build a limited version\nthat handles only expressions using the four arithmetic actions.\n\nRecursive parsing of expression trees\n-------------------------------------\n\nAs we have seen in the tutorial, Yacas represents all expressions as\ntrees, or equivalently, as lists of lists. For example, the expression\n\"{a+b+c+d+e}\" is for Yacas a tree of depth 4 that could be visualized\nas ::\n\n    \"+\"\n   a  \"+\"\n     b  \"+\"\n       c  \"+\"\n         d   e\n\nor as a nested list: ``(\"+\" a (\"+\" b (\"+\" c (\"+\" d e))))``. \n\nComplicated expressions are thus built from simple ones in a general\nand flexible way. If we want a function that acts on sums of any\nnumber of terms, we only need to define this function on a single atom\nand on a sum of two terms, and the Yacas engine will recursively\nperform the action on the entire tree.\n\nSo our first try is to define rules for transforming an atom and for\ntransforming sums and products. The result of {CForm()} will always be\na string. We can use recursion like this: ::\n\n  In> 100 # CForm(a_IsAtom) <-- String(a);\n  Out> True;\n  In> 100 # CForm(_a + _b) <-- CForm(a) : \\\n    \" + \" : CForm(b);\n  Out> True;\n  In> 100 # CForm(_a * _b) <-- CForm(a) : \\\n    \" * \" : CForm(b);\n  Out> True;\n\nWe used the string concatenation operator \"{:}\" and we added spaces\naround the binary operators for clarity. All rules have the same\nprecedence 100 because there are no conflicts in rule ordering so far:\nthese rules apply in mutually exclusive cases. Let's try converting\nsome simple expressions now: ::\n\n  In> CForm(a+b*c);\n  Out> \"a + b * c\";\n  In> CForm(a+b*c*d+e+1+f);\n  Out> \"a + b * c * d + e + 1 + f\";\n\nWith only three rules, we were able to process even some complicated\nexpressions. How did it work? We could illustrate the steps Yacas went\nthrough when simplifying {CForm(a+b*c)} roughly like this: ::\n\n  CForm(a+b*c)\n      ... apply 2nd rule\n  CForm(a) : \" + \" : CForm(b*c)\n      ... apply 1st rule and 3rd rule\n  \"a\" : \" + \" : CForm(b) : \" * \" : CForm(c)\n      ... apply 1st rule\n  \"a\" : \" + \" : \"b\" : \" * \" : \"c\"\n      ... concatenate strings\n  \"a + b * c\"\n\nHandling precedence of infix operations\n---------------------------------------\n\nIt seems that recursion will do all the work for us. The power of\nrecursion is indeed great and extensive use of recursion is built into\nthe design of Yacas. We might now add rules for more operators, for\nexample, the unary addition, subtraction and division: ::\n\n  100 # CForm(+ _a) <-- \"+ \" : CForm(a);\n  100 # CForm(- _a) <-- \"- \" : CForm(a);\n  100 # CForm(_a - _b) <-- CForm(a) : \" - \"\n    : CForm(b);\n  100 # CForm(_a / _b) <-- CForm(a) : \" / \"\n    : CForm(b);\n\nHowever, soon we find that we forgot about operator precedence. Our\nsimple-minded {CForm()} gives wrong C code for expressions like this: ::\n\n  In> CForm( (a+b) * c );\n  Out> \"a + b * c\";\n\nWe need to get something like ``(a+b)*c`` in this case. How would we add\na rule to insert parentheses around subexpressions? A simple way out\nwould be to put parentheses around every subexpression, replacing our\nrules by something like this: ::\n\n  100 # CForm(_a + _b) <-- \"(\" : CForm(a)\n    : \" + \" : CForm(b) : \")\";\n  100 # CForm(- _a) <-- \"(- \" : CForm(a)\n    : \")\";\n\nand so on. This will always produce correct C code, e.g. in our case\n\"((a+b)*c)\", but generally the output will be full of unnecessary\nparentheses. It is instructive to find a better solution.\n\nWe could improve the situation by inserting parentheses only if the\nhigher-order expression requires them; for this to work, we need to\nmake a call such as {CForm(a+b)} aware that the enveloping expression\nhas a multiplication by {c} around the addition {a+b}. This can be\nimplemented by passing an extra argument to {CForm()} that will\nindicate the precedence of the enveloping operation. A compound\nexpression that uses an infix operator must be bracketed if the\nprecedence of that infix operator is higher than the precedence of the\nenveloping infix operation.\n\nWe shall define an auxiliary function also named \"CForm\" but with a\nsecond argument, the precedence of the enveloping infix operation. If\nthere is no enveloping operation, we shall set the precedence to a\nlarge number, e.g. 60000, to indicate that no parentheses should be\ninserted around the whole expression. The new \"CForm(expr,\nprecedence)\" will handle two cases: either parentheses are necessary,\nor unnecessary. For clarity we shall implement these cases in two\nseparate rules. The initial call to \"CForm(expr)\" will be delegated to\n\"CForm(expr, precedence)\".\n\nThe precedence values of infix operators such as \"{+}\" and \"{*}\" are\ndefined in the Yacas library but may change in a future\nversion. Therefore, we shall not hard-code these precedence values but\ninstead use the function {OpPrecedence()} to determine them. The new\nrules for the \"{+}\" operation could look like this: ::\n\n  PlusPrec := OpPrecedence(\"+\");\n  100 # CForm(_expr) <-- CForm(expr, 60000);\n  100 # CForm(_a + _b, _prec)_(PlusPrec>prec)\n    <-- \"(\" : CForm(a, PlusPrec) : \" + \"\n    : CForm(b, PlusPrec) : \")\";\n  120 # CForm(_a + _b, _prec) <--\n      CForm(a, PlusPrec) : \" + \"\n      : CForm(b, PlusPrec);\n\nand so on. We omitted the predicate for the last rule because it has a\nlater precedence than the preceding rule.\n\nThe way we wrote these rules is unnecessarily repetitive but\nstraightforward and it illustrates the central ideas of expression\nprocessing in Yacas. The standard library implements {CForm()}\nessentially in this way. In addition the library implementation\nsupports standard mathematical functions, arrays and so on, and is\nsomewhat better organized to allow easier extensions and avoid\nrepetition of code.\n\n==========================\nYacas programming pitfalls\n==========================\n\nNo programming language is without programming pitfalls, and yacas\nhas its fair share of pitfalls.\n\nAll rules are global\n--------------------\n\nAll rules are global, and a consequence is that rules can clash or\nsilently shadow each other, if the user defines two rules with the\nsame patterns and predicates but different bodies.\n\nFor example::\n\n  In> f(0) <-- 1\n  Out> True;\n  In> f(x_IsConstant) <-- Sin(x)/x\n  Out> True;\n\nThis can happen in practice, if care is not taken. Here two\ntransformation rules are defined which both have the same precedence\n(since their precedence was not explicitly set). In that case yacas\ngets to decide which one to try first.  Such problems can also occur\nwhere one transformation rule (possibly defined in some other file)\nhas a wrong precedence, and thus masks another transformation rule. It\nis necessary to think of a scheme for assigning precedences first. In\nmany cases, the order in which transformation rules are applied is\nimportant.\n\nIn the above example, because yacas gets to decide which rule to try\nfirst, it is possible that ``f(0)`` invokes the second rule, which would\nthen mask the first so the first rule is never called.  Indeed ::\n\n  In> f(0)\n  Out> Undefined;\n\nThe order the rules are applied in is undefined if the precedences are\nthe same. The precedences should only be the same if order does not\nmatter. This is the case if, for instance, the two rules apply to\ndifferent argument patters that could not possibly mask each other.\n\nThe solution could have been either::\n\n  In> 10 # f(0) <-- 1\n  Out> True;\n  In> 20 # f(x_IsConstant) <-- Sin(x)/x\n  Out> True;\n  In> f(0)\n  Out> 1;\n\nor ::\n\n  In> f(0) <-- 1\n  Out> True;\n  In> f(x_IsConstant)_(x != 0) <-- Sin(x)/x\n  Out> True;\n  In> f(0)\n  Out> 1;\n\nSo either the rules should have distinct precedences, or they should\nhave mutually exclusive predicates, so that they do not collide.\n\nObjects that look like functions\n--------------------------------\n\nAn expression that *looks like a function*, for example ``AbcDef(x,y)``,\nis in fact either a call to a *core function* or to a *user function*,\nand there is a huge difference between the behaviors. Core functions\nimmediately evaluate to something, while user functions are really\njust symbols to which evaluation rules may or may not be applied.\n\nFor example::\n\n  In> a+b\n  Out> a+b;\n  In> 2+3\n  Out> 5;\n  In> MathAdd(a,b)\n  In function \"MathAdd\" : \n  bad argument number 1 (counting from 1)\n  The offending argument a evaluated to a\n  CommandLine(1) : Invalid argument\n  \n  In> MathAdd(2,3)\n  Out> 5;\n\nThe ``+`` operator will return the object unsimplified if the arguments\nare not numeric. The ``+`` operator is defined in the standard scripts.\n:func:`MathAdd`, however, is a function defined in the *core* to performs\nthe numeric addition. It can only do this if the arguments are numeric\nand it fails on symbolic arguments.  (The ``+`` operator calls :func:`MathAdd`\nafter it has verified that the arguments passed to it are numeric.)\n\nA core function such as :func:`MathAdd` can never return unevaluated, but an\noperator such as ``+`` is a *user function* which might or might not\nbe evaluated to something.\n\nA user function does not have to be defined before it is used. A\nconsequence of this is that a typo in a function name or a variable\nname will always go unnoticed.  For example::\n\n  In> f(x_IsInteger,y_IsInteger) <-- Mathadd(x,y)\n  Out> True;\n  In> f(1,2)\n  Out> Mathadd(1,2);\n\nHere we made a typo: we should have written :func:`MathAdd`, but wrote\n:func:`Mathadd` instead. Yacas` happily assumed that we mean a new and (so\nfar) undefined *user function* :func:`Mathadd` and returned the expression\nunevaluated.\n\nIn the above example it was easy to spot the error. But this feature\nbecomes more dangerous when it this mistake is made in a part of some\nprocedure. A call that should have been made to an internal function,\nif a typo was made, passes silently without error and returns\nunevaluated.  The real problem occurs if we meant to call a function\nthat has side-effects and we not use its return value. In this case we\nshall not immediately find that the function was not evaluated, but\ninstead we shall encounter a mysterious bug later.\n\nGuessing when arguments are evaluated and when not\n--------------------------------------------------\n\nIf your new function does not work as expected, there is a good chance\nthat it happened because you did not expect some expression which is\nan argument to be passed to a function to be evaluated when it is in\nfact evaluated, or vice versa.\n\nFor example: ::\n\n  In> p:=Sin(x)\n  Out> Sin(x);\n  In> D(x)p\n  Out> Cos(x);\n  In> y:=x\n  Out> x;\n  In> D(y)p\n  Out> 0;\n\nHere the first argument to the differentiation function is not\nevaluated, so {y} is not evaluated to {x}, and {D(y)p} is indeed 0.\n\nThe confusing effect of {HoldArg}\n---------------------------------\n\nThe problem of distinguishing evaluated and unevaluated objects\nbecomes worse when we need to create a function that does not evaluate\nits arguments.\n\nSince in yacas evaluation starts from the bottom of the expression\ntree, all *user functions* will appear to evaluate their arguments by\ndefault. But sometimes it is convenient to prohibit evaluation of a\nparticular argument (using :func:`HoldArg` or :func:`HoldArgNr`).\n\nFor example, suppose we need a function ``A(x,y)`` that, as a\nside-effect, assigns the variable ``x`` to the sum of ``x`` and ``y``. This\nfunction will be called when ``x`` already has some value, so clearly\nthe argument ``x`` in ``A(x,y)`` should be unevaluated. It is possible to\nmake this argument unevaluated by putting :func:`Hold()` on it and always\ncalling ``A(Hold(x), y)``, but this is not very convenient and easy to\nforget. It would be better to define :func`A` so that it always keeps its\nfirst argument unevaluated.\n\nIf we define a rule base for :func:`A` and declare :func:`HoldArg`, ::\n\n  Function() A(x,y);\n  HoldArg(\"A\", x);\n\nthen we shall encounter a difficulty when working with the argument\n``x`` inside of a rule body for :func:`A`. For instance, the simple-minded\nimplementation ::\n\n  A(_x, _y) <-- (x := x+y);\n\ndoes not work::\n\n  In> [ a:=1; b:=2; A(a,b);]\n  Out> a+2;\n\nIn other words, the ``x`` inside the body of ``A(x,y)`` did not evaluate\nto ``1`` when we called the function ``:=``. Instead, it was left\nunevaluated as the atom ``x`` on the left hand side of ``:=``, since ``:=``\ndoes not evaluate its left argument. It however evaluates its right\nargument, so the ``y`` argument was evaluated to ``2`` and the ``x+y``\nbecame ``a+2``.\n\nThe evaluation of ``x`` in the body of ``A(x,y)`` was prevented by the\n:func:`HoldArg` declaration. So in the body, ``x`` will just be the atom ``x``,\nunless it is evaluated again. If you pass ``x`` to other functions, they\nwill just get the atom ``x``. Thus in our example, we passed ``x`` to the\nfunction ``:=``, thinking that it will get ``a``, but it got an\nunevaluated atom ``x`` on the left side and proceeded with that.\n\nWe need an explicit evaluation of ``x`` in this case. It can be\nperformed using :func:`Eval`, or with backquoting, or by using a core\nfunction that evaluates its argument. Here is some code that\nillustrates these three possibilities::\n\n    A(_x, _y) <-- [ Local(z); z:=Eval(x); z:=z+y; ]\n\n(using explicit evaluation) or ::\n\n    A(_x, _y) <-- `(@x := @x + y);\n\n(using backquoting) or ::\n\n    A(_x, _y) <-- MacroSet(x, x+y);\n\n(using a core function :func:`MacroSet` that evaluates its first argument).\n\nHowever, beware of a clash of names when using explicit evaluations\n(as explained above). In other words, the function :func:`A` as defined\nabove will not work correctly if we give it a variable also named\n``x``. The :func:`LocalSymbols` call should be used to get around this\nproblem.\n\nAnother caveat is that when we call another function that does not\nevaluate its argument, we need to substitute an explicitly evaluated\n``x`` into it. A frequent case is the following: suppose we have a\nfunction ``B(x,y)`` that does not evaluate ``x}``, and we need to write an\ninterface function ``B(x)`` which will just call ``B(x,0)``. We should use\nan explicit evaluation of ``x`` to accomplish this, for example ::\n\n    B(_x) <-- `B(@x,0);\n\nor ::\n\n    B(_x) <-- B @ {x, 0};\n\nOtherwise ``B(x,y)`` will not get the correct value of its first\nparameter ``x``.\n\nSpecial behavior of :func:`Hold`, :func:`UnList` and :func:`Eval`\n-----------------------------------------------------------------\n\nWhen an expression is evaluated, all matching rules are applied to it\nrepeatedly until no more rules match. Thus an expression is\n\"completely\" evaluated. There are, however, two cases when recursive\napplication of rules is stopped at a certain point, leaving an\nexpression not \"completely\" evaluated:\n\n* The expression which is the result of a call to a yacas core\n  function is not evaluated further, even if some rules apply to it.\n* The expression is a variable that has a value assigned to it; for\n  example, the variable {x} might have the expression {y+1} as the\n  value. That value is not evaluated again, so even if {y} has been\n  assigned another value, say, {y=2} a yacas expression such as\n  {2*x+1} will evaluate to {2*(y+1)+1} and not to {7}. Thus, a\n  variable can have some unevaluated expression as its value and the\n  expression will not be re-evaluated when the variable is used.\n\nThe first possibility is mostly without consequence because almost all\ncore functions return a simple atom that does not require further\nevaluation.  However, there are two core functions that can return a\ncomplicated expression: {Hold} and {UnList}. Thus, these functions can\nproduce arbitrarily complicated Yacas expressions that will be left\nunevaluated.  For example, the result of ::\n\n    UnList({Sin, 0})\n\nis the same as the result of ::\n\n    Hold(Sin(0))\n\nand is the unevaluated expression {Sin(0)} rather than {0}.\n\nTypically you want to use {UnList} because you need to construct a\nfunction call out of some objects that you have. But you need to call\n{Eval(UnList(...))} to actually evaluate this function call. For\nexample: ::\n\n  In> UnList({Sin, 0})\n  Out> Sin(0);\n  In> Eval(UnList({Sin, 0}))\n  Out> 0;\n\nIn effect, evaluation can be stopped with {Hold} or {UnList} and can\nbe explicitly restarted by using {Eval}. If several levels of\nun-evaluation are used, such as {Hold(Hold(...))}, then the same\nnumber of {Eval} calls will be needed to fully evaluate an\nexpression. ::\n\n  In> a:=Hold(Sin(0))\n  Out> Sin(0);\n  In> b:=Hold(a)\n  Out> a;\n  In> c:=Hold(b)\n  Out> b;\n  In> Eval(c)\n  Out> a;\n  In> Eval(Eval(c))\n  Out> Sin(0);\n  In> Eval(Eval(Eval(c)))\n  Out> 0;\n\nA function {FullEval} can be defined for \"complete\" evaluation of\nexpressions, as follows: ::\n\n  LocalSymbols(x,y)\n  [\n    FullEval(_x) <-- FullEval(x,Eval(x));\n    10 # FullEval(_x,_x) <-- x;\n    20 # FullEval(_x,_y) <-- FullEval(y,Eval(y));\n  ];\n\nThen the example above will be concluded with: ::\n\n  In> FullEval(c);\n  Out> 0;\n\n\nCorrectness of parameters to functions is not checked\n-----------------------------------------------------\n\nBecause yacas does not enforce type checking of arguments, it is\npossible to call functions with invalid arguments. The default way\nfunctions in yacas should deal with situations where an action can\nnot be performed, is to return the expression unevaluated. A function\nshould know when it is failing to perform a task. The typical symptoms\nare errors that seem obscure, but just mean the function called should\nhave checked that it can perform the action on the object.\n\nFor example: ::\n\n  In> 10 # f(0) <-- 1;\n  Out> True;\n  In> 20 # f(_n) <-- n*f(n-1);\n  Out> True;\n  In> f(3)\n  Out> 6;\n  In> f(1.3)\n  CommandLine(1): Max evaluation stack depth reached.\n\nHere, the function {f} is defined to be a factorial function, but the\nfunction fails to check that its argument is a positive integer, and\nthus exhausts the stack when called with a non-integer argument.  A\nbetter way would be to write ::\n\n  In> 20 # f(n_IsPositiveInteger) <-- n*f(n-1);\n\nThen the function would have returned unevaluated when passed a\nnon-integer or a symbolic expression.\n\nEvaluating variables in the wrong scope\n---------------------------------------\n\nThere is a subtle problem that occurs when {Eval} is used in a\nfunction, combined with local variables. The following example perhaps\nillustrates it: ::\n\n  In> f1(x):=[Local(a);a:=2;Eval(x);];\n  Out> True;\n  In> f1(3)\n  Out> 3;\n  In> f1(a)\n  Out> 2;\n\nHere the last call should have returned {a}, but it returned {2},\nbecause {x} was assigned the value {a}, and {a} was assigned locally\nthe value of {2}, and {x} gets re-evaluated. This problem occurs when\nthe expression being evaluated contains variables which are also local\nvariables in the function body. The solution is to use the\n{LocalSymbols} function for all local variables defined in the body.\n\nThe following illustrates this: ::\n\n  In> f2(x):=LocalSymbols(a)[Local(a);a:=2;Eval(x);];\n  Out> True;\n  In> f1(3)\n  Out> 3;\n  In> f2(a)\n  Out> a;\n\nHere {f2} returns the correct result. {x} was assigned the value {a},\nbut the {a} within the function body is made distinctly different from\nthe one referred to by {x} (which, in a sense, refers to a global\n{a}), by using {LocalSymbols}.\n\nThis problem generally occurs when defining functions that re-evaluate\none of its arguments, typically functions that perform a loop of some\nsort, evaluating a body at each iteration.\n\n==================\nDebugging in Yacas\n==================\n\nIntroduction\n------------\n\nWhen writing a code segment, it is generally a good idea to separate\nthe problem into many small functions. Not only can you then reuse\nthese functions on other problems, but it makes debugging easier too.\n\nFor debugging a faulty function, in addition to the usual\ntrial-and-error method and the \"print everything\" method, Yacas offers\nsome trace facilities. You can try to trace applications of rules\nduring evaluation of the function ({TraceRule()}, {TraceExp()}) or see\nthe stack after an error has occurred ({TraceStack()}).\n\nThere is also an interactive debugger, which shall be introduced\nin this chapter.\n\nFinally, you may want to run a debugging version of Yacas. This\nversion of the executable maintains more information about \nthe operations it performs, and can report on this. \n\nThis chapter will start with the interactive debugger, as it\nis the easiest and most useful feature to use, and then proceed\nto explain the trace and profiling facilities. Finally, the\ninternal workings of the debugger will be explained. It is highly\ncustomizable (in fact, most of the debugging code is written in\nYacas itself), so for bugs that are really difficult to track\none can write custom code to track it.\n\n\n\nThe trace facilities\n--------------------\n\nThe trace facilities are:\n\n* {TraceExp} : traces the full expression, showing all calls to user-\n  or system-defined functions, their arguments, and the return\n  values. For complex functions this can become a long list of\n  function calls.\n* {TraceRule} : traces one single user-defined function (rule). It\n  shows each invocation, the arguments passed in, and the returned\n  values. This is useful for tracking the behavior of that function in\n  the environment it is intended to be used in.\n* {TraceStack} : shows a few last function calls before an error has\n  occurred.\n* {Profile} : report on statistics (number of times functions were\n  called, etc.). Useful for performance analysis.\n\nThe online manual pages (e.g. {?TraceStack}) have more information\nabout the use of these functions.\n\nAn example invocation of {TraceRule} is ::\n\n  In> TraceRule(x+y)2+3*5+4;\n\nWhich should then show something to the effect of ::\n\n    TrEnter(2+3*5+4);\n      TrEnter(2+3*5);\n         TrArg(2,2);\n            TrArg(3*5,15);\n         TrLeave(2+3*5,17);\n          TrArg(2+3*5,17);\n          TrArg(4,4);\n      TrLeave(2+3*5+4,21);\n  Out> 21;\n\nCustom evaluation facilities\n----------------------------\n\nYacas supports a special form of evaluation where hooks are placed\nwhen evaluation enters or leaves an expression.\n\nThis section will explain the way custom evaluation is supported in\nyacas, and will proceed to demonstrate how it can be used by showing\ncode to trace, interactively step through, profile, and write custom\ndebugging code.\n\nDebugging, tracing and profiling has been implemented in the\ndebug.rep/ module, but a simplification of that code will be presented\nhere to show the basic concepts.\n\nThe basic infrastructure for custom evaluation\n----------------------------------------------\n\nThe name of the function is {CustomEval}, and the calling sequence is: ::\n\n  CustomEval(enter,leave,error,expression);\n\nHere, {expression} is the expression to be evaluated, {enter} some\nexpression that should be evaluated when entering an expression, and\n{leave} an expression to be evaluated when leaving evaluation of that\nexpression.\n\nThe {error} expression is evaluated when an error occurred. If an\nerror occurs, this is caught high up, the {error} expression is\ncalled, and the debugger goes back to evaluating {enter} again so the\nsituation can be examined. When the debugger needs to stop, the\n{error} expression is the place to call {CustomEval'Stop()} (see\nexplanation below).\n\nThe {CustomEval} function can be used to write custom debugging\ntools. Examples are:\n\n* a trace facility following entering and leaving functions\n* interactive debugger for stepping through evaluation of an\n  expression.\n* profiler functionality, by having the callback functions do the \n  bookkeeping on counts of function calls for instance.\n\nIn addition, custom code can be written to for instance halt\nevaluation and enter interactive mode as soon as some very specific\nsituation occurs, like \"stop when function foo is called while the\nfunction bar is also on the call stack and the value of the local\nvariable x is less than zero\".\n\nAs a first example, suppose we define the functions TraceEnter(),\nTraceLeave() and {TraceExp()} as follows: ::\n\n  TraceStart() := [indent := 0;];\n  TraceEnter() :=\n  [\n     indent++;\n     Space(2*indent);\n     Echo(\"Enter \",CustomEval'Expression());\n  ];\n  TraceLeave() :=\n  [\n     Space(2*indent);\n     Echo(\"Leave \",CustomEval'Result());\n     indent--;\n  ];\n  Macro(TraceExp,{expression})\n  [\n     TraceStart();\n     CustomEval(TraceEnter(),\n                TraceLeave(),\n                CustomEval'Stop(),@expression);\n  ];\n\nallows us to have tracing in a very basic way. We can now call: ::\n\n  In> TraceExp(2+3)\n    Enter 2+3 \n      Enter 2 \n      Leave 2 \n      Enter 3 \n      Leave 3 \n      Enter IsNumber(x) \n        Enter x \n        Leave 2 \n      Leave True \n      Enter IsNumber(y) \n        Enter y \n        Leave 3 \n      Leave True \n      Enter True \n      Leave True \n      Enter MathAdd(x,y) \n        Enter x \n        Leave 2 \n        Enter y \n        Leave 3 \n      Leave 5 \n    Leave 5 \n  Out> 5;\n\nThis example shows the use of {CustomEval'Expression} and\n{CustomEval'Result}. These functions give some extra access to\ninteresting information while evaluating the expression.  The\nfunctions defined to allow access to information while evaluating are:\n\n* {CustomEval'Expression()} - return expression currently on the top\n  call stack for evaluation.\n* {CustomEval'Result()} - when the {leave} argument is called this\n  function returns what the evaluation of the top expression will\n  return.\n* {CustomEval'Locals()} - returns a list with the current local\n  variables.\n* {CustomEval'Stop()} - stop debugging execution\n\nA simple interactive debugger\n\n\nThe following code allows for simple interactive debugging: ::\n\n  DebugStart():=\n  [\n     debugging:=True;\n     breakpoints:={};\n  ];\n  DebugRun():= [debugging:=False;];\n  DebugStep():=[debugging:=False;nextdebugging:=True;];\n  DebugAddBreakpoint(fname_IsString) <-- \n     [ breakpoints := fname:breakpoints;];\n  BreakpointsClear() <-- [ breakpoints := {};];\n  Macro(DebugEnter,{})\n  [\n     Echo(\">>> \",CustomEval'Expression());\n     If(debugging = False And\n        IsFunction(CustomEval'Expression()) And \n        Contains(breakpoints,\n        Type(CustomEval'Expression())),   \n          debugging:=True);\n     nextdebugging:=False;\n     While(debugging)\n     [\n        debugRes:=\n          Eval(FromString(\n            ReadCmdLineString(\"Debug> \"):\";\")\n            Read());\n        If(debugging,Echo(\"DebugOut> \",debugRes));\n     ];\n     debugging:=nextdebugging;\n  ];\n  Macro(DebugLeave,{})\n  [\n     Echo(CustomEval'Result(),\n          \" <-- \",CustomEval'Expression());\n  ];\n  Macro(Debug,{expression})\n  [\n     DebugStart();\n     CustomEval(DebugEnter(),\n                DebugLeave(),\n                debugging:=True,@expression);\n  ];\n\nThis code allows for the following interaction: ::\n\n  In> Debug(2+3)\n  >>> 2+3 \n  Debug> \n\nThe console now shows the current expression being evaluated, and a\ndebug prompt for interactive debugging. We can enter {DebugStep()},\nwhich steps to the next expression to be evaluated: ::\n\n  Debug> DebugStep();\n  >>> 2 \n  Debug> \n\nThis shows that in order to evaluate {2+3} the interpreter first needs\nto evaluate {2}. If we step further a few more times, we arrive at: ::\n\n  >>> IsNumber(x) \n  Debug> \n\nNow we might be curious as to what the value for {x} is. We can\ndynamically obtain the value for {x} by just typing it on the command\nline. ::\n\n  >>> IsNumber(x) \n  Debug> x\n  DebugOut> 2 \n\n{x} is set to {2}, so we expect {IsNumber} to return :data:`True`. Stepping\nagain: ::\n\n  Debug> DebugStep();\n  >>> x \n  Debug> DebugStep();\n  2  <-- x \n  True  <-- IsNumber(x) \n  >>> IsNumber(y) \n\nSo we see this is true. We can have a look at which local variables\nare currently available by calling {CustomEval'Locals()}: ::\n\n  Debug> CustomEval'Locals()\n  DebugOut> {arg1,arg2,x,y,aLeftAssign,aRightAssign} \n\nAnd when bored, we can proceed with {DebugRun()} which will continue\nthe debugger until finished in this case (a more sophisticated\ndebugger can add breakpoints, so running would halt again at for\ninstance a breakpoint). ::\n\n  Debug> DebugRun()\n  >>> y \n  3  <-- y \n  True  <-- IsNumber(y) \n  >>> True \n  True  <-- True \n  >>> MathAdd(x,y) \n  >>> x \n  2  <-- x \n  >>> y \n  3  <-- y \n  5  <-- MathAdd(x,y) \n  5  <-- 2+3 \n  Out> 5;\n\n\nThe above bit of code also supports primitive breakpointing, in that\none can instruct the evaluator to stop when a function will be\nentered.  The debugger then stops just before the arguments to the\nfunction are evaluated. In the following example, we make the debugger\nstop when a call is made to the {MathAdd} function: ::\n\n  In> Debug(2+3)\n  >>> 2+3 \n  Debug> DebugAddBreakpoint(\"MathAdd\")\n  DebugOut> {\"MathAdd\"} \n  Debug> DebugRun()\n  >>> 2 \n  2  <-- 2 \n  >>> 3 \n  3  <-- 3 \n  >>> IsNumber(x) \n  >>> x \n  2  <-- x \n  True  <-- IsNumber(x) \n  >>> IsNumber(y) \n  >>> y \n  3  <-- y \n  True  <-- IsNumber(y) \n  >>> True \n  True  <-- True \n  >>> MathAdd(x,y) \n  Debug> \n\nThe arguments to {MathAdd} can now be examined, or execution continued.\n\nOne great advantage of defining much of the debugger in script code\ncan be seen in the {DebugEnter} function, where the breakpoints are\nchecked, and execution halts when a breakpoint is reached. In this\ncase the condition for stopping evaluation is rather simple: when\nentering a specific function, stop. However, nothing stops a\nprogrammer from writing a custom debugger that could stop on any\ncondition, halting at e very special case.\n\n\n\nProfiling\n---------\n\nA simple profiler that counts the number of times each function is\ncalled can be written such: ::\n\n  ProfileStart():=\n  [\n     profilefn:={};\n  ];\n  10 # ProfileEnter()\n       _(IsFunction(CustomEval'Expression())) <-- \n  [\n     Local(fname);\n     fname:=Type(CustomEval'Expression());\n     If(profilefn[fname]=Empty,profilefn[fname]:=0);\n     profilefn[fname] := profilefn[fname]+1;\n  ];\n  Macro(Profile,{expression})\n  [\n     ProfileStart();\n     CustomEval(ProfileEnter(),True,\n                CustomEval'Stop(),@expression);\n     ForEach(item,profilefn)\n       Echo(\"Function \",item[1],\" called \",\n            item[2],\" times\");\n  ];\n\nwhich allows for the interaction: ::\n\n  In> Profile(2+3)\n  Function MathAdd called 1  times\n  Function IsNumber called 2  times\n  Function + called 1  times\n  Out> True;\n\n\n==========================================================\nAdvanced example 2: implementing a non-commutative algebra\n==========================================================\n\nWe need to understand how to simplify expressions in Yacas, and the\nbest way is to try writing our own algebraic expression handler. In\nthis chapter we shall consider a simple implementation of a particular\nnon-commutative algebra called the Heisenberg algebra. This algebra\nwas introduced by Dirac to develop quantum field theory. We won't\nexplain any physics here, but instead we shall to delve somewhat\ndeeper into the workings of Yacas.\n\nThe problem\n-----------\n\nSuppose we want to define special symbols :math:`A(k)` and :math:`B(k)`\nthat we can multiply with each other or by a number, or add to each other,\nbut not commute with each other, i.e. :math:`A(k)B(k)\\ne B(k)A(k)`. Here\n:math:`k` is merely a label to denote that :math:`A(1)` and :math:`A(2)`\nare two different objects. (In physics, these are called *creation* and\n*annihilation* operators for *bosonic quantum fields*.) Yacas already\nassumes that the usual multiplication operator ``*`` is commutative.\nRather than trying to redefine ``*``, we shall introduce a special\nmultiplication sign ``**`` that we shall use with the objects\n:math:`A(k)` and :math:`B(k)`; between usual numbers this would be the same\nas normal multiplication. The symbols :math:`A(k)`, :math:`B(k)` will never\nbe evaluated to numbers, so an expression such as\n``2 ** A(k1) ** B(k2) ** A(k3)`` is just going to remain like that.\n(In physics, commuting numbers are called *classical quantities* or\n*c-numbers* while non-commuting objects made up of :math:`A(k)` and\n:math:`B(k)` are called *quantum quantities* or *q-numbers*.)\nThere are certain commutation relations for these\nsymbols: the :math:`A`'s commute between themselves, :math:`A(k)A(l) =\nA(l)A(k)`, and also the :math:`B`'s, :math:`B(k)B(l) = B(l)B(k)`.\nHowever, the :math:`A`'s don't commute with the :math:`B`'s:\n:math:`A(k)B(l) - B(l)*A(k) = \\delta(k-l)`. Here the :math:`\\delta` is a\n*classical* function (called the *Dirac* :math:`\\delta` *function*)\nbut we aren't going to do anything about it, just leave it symbolic.\n\nWe would like to be able to manipulate such expressions, expanding\nbrackets, collecting similar terms and so on, while taking care to\nalways keep the non-commuting terms in the correct order. For example,\nwe want Yacas to automatically simplify ``2**B(k1)**3**A(k2)`` to\n``6**B(k1)**A(k2)``. Our goal is not to implement a general package to\ntackle complicated non-commutative operations; we merely want to teach\nYacas about these two kinds of *quantum objects* called ``A(k)`` and\n``B(k)``, and we shall define one function that a physicist would need\nto apply to these objects. This function applied to any given\nexpression containing :math:`A`'s and :math:`B`'s will compute something\ncalled a *vacuum expectation value*, or *VEV* for short, of that\nexpression. This function has \"classical\", i.e. commuting, values and\nis defined as follows: VEV of a commuting number is just that number,\ne.g. :math:`\\mathrm{VEV}(4) = 4`,\n:math:`\\mathrm{VEV}(\\delta(k-l)) = \\delta(k-l)`; and\n:math:`\\mathrm{VEV}(X*A(k)) = 0`, :math:`\\mathrm{VEV}(B(k)*X) = 0` where\n:math:`X` is any expression, commutative or not. It is straightforward to\ncompute VEV of something that contains :math:`A`'s and :math:`B`'s: one\njust uses the commutation relations to move all :math:`B`'s to the left of\nall :math:`A`'s, and then applies the definition of VEV, simply throwing\nout any remaining q-numbers.\n\nFirst steps\n-----------\n\nThe first thing that comes to mind when we start implementing this in\nyacas is to write a rule such as ::\n\n  10 # A(_k)**B(_l) <-- B(l)**A(k) + delta(k-l);\n\nHowever, this is not going to work right away. In fact this will\nimmediately give a syntax error because Yacas doesn't know yet about\nthe new multiplication ``**``. Let's fix that: we shall define a new\ninfix operator with the same precedence as multiplication::\n\n  RuleBase(\"**\", {x,y});\n  Infix(\"**\", OpPrecedence(\"*\"));\n\nNow we can use this new multiplication operator in expressions, and it\ndoesn't evaluate to anything -- exactly what we need. But we find that\nthings don't quite work: ::\n\n  In> A(_k)**B(_l) <-- B(l)**A(k)+delta(k-l);\n  Out> True;\n  In> A(x)**B(y)\n  Out> B(l)**A(k)+delta(k-l);\n\nYacas doesn't grok that ``delta(k)``, ``A(k)`` and ``B(k)`` are\nfunctions. This can be fixed by declaring ::\n\n  RuleBase(\"A\", {k});\n  RuleBase(\"B\", {k});\n  RuleBase(\"delta\", {k});\n\nNow things work as intended: ::\n\n  In> A(y)**B(z)*2\n  Out> 2*(B(z)**A(y)+delta(y-z));\n\nStructure of expressions\n------------------------\n\nAre we done yet? Let's try to calculate more things with our :math:`A`'s and\n:math:`B`'s: ::\n\n  In> A(k)*2**B(l)\n  Out> 2*A(k)**B(l);\n  In> A(x)**A(y)**B(z)\n  Out> A(x)**A(y)**B(z);\n  In> (A(x)+B(x))**2**B(y)*3\n  Out> 3*(A(x)+B(x))**2**B(y);\n\nAfter we gave it slightly more complicated input, yacas didn't fully\nevaluate expressions containing the new ``**`` operation: it didn't move\nconstants ``2`` and ``3`` together, didn't expand brackets, and, somewhat\nmysteriously, it didn't apply the rule in the first line above --\nalthough it seems like it should have. Before we hurry to fix these\nthings, let's think some more about how yacas represents our new\nexpressions. Let's start with the first line above::\n\n  In> FullForm( A(k)*2**B(l) )\n  (** (* 2 (A k ))(B l ))\n  Out> 2*A(k)**B(l);\n\nWhat looks like ``2*A(k)**B(l)`` on the screen is really ``(2*A(k)) **\nB(l)`` inside yacas. In other words, the commutation rule didn't apply\nbecause there is no subexpression of the form ``A(...)**B(...)`` in this\nexpression. It seems that we would need many rules to exhaust all ways\nin which the adjacent factors ``A(k)`` and ``B(l)`` might be divided\nbetween subexpressions. We run into this difficulty because yacas\nrepresents all expressions as trees of functions and leaves the\nsemantics to us. To yacas, the ``*`` operator is fundamentally no\ndifferent from any other function, so ``(a*b)*c`` and ``a*(b*c)`` are two\nbasically different expressions. It would take a considerable amount\nof work to teach yacas to recognize all such cases as identical. This\nis a design choice and it was made by the author of yacas to achieve\ngreater flexibility and extensibility.\n\nA solution for this problem is not to write rules for all possible\ncases (there are infinitely many cases) but to systematically reduce\nexpressions to a *canonical form*. \"Experience has shown that\" (a\nphrase used when we can't come up with specific arguments) symbolic\nmanipulation of unevaluated trees is not efficient unless these trees\nare forced to a pattern that reflects their semantics.\n\nWe should choose a canonical form for all such expressions in a way\nthat makes our calculations -- namely, the function :func:`VEV` --\neasier. In our case, our expressions contain two kinds of ingredients:\nnormal, commutative numbers and maybe a number of noncommuting symbols\n``A(k)`` and ``B(k)`` multiplied together with the ``**`` operator. It\nwill not be possible to divide anything by :math:`A(k)` or :math:`B(k)`\n-- such division is undefined.\n\nA possible canonical form for expressions with :math:`A`'s and :math:`B`'s\nis the following. All commutative numbers are moved to the left of the\nexpression and grouped together as one factor; all non-commutative\nproducts are simplified to a single chain, all brackets expanded. A\ncanonical expression should not contain any extra brackets in its\nnon-commutative part. For example, ``(A(x)+B(x)*x)**B(y)*y**A(z)`` should\nbe regrouped as a sum of two terms, ``(y)**(A(x)**(B(y))**A(z))`` and\n``(x*y)**(B(x)**(B(y))**A(z))``. Here we wrote out all parentheses to show\nexplicitly which operations are grouped.  (We have chosen the grouping\nof non-commutative factors to go from left to right, however this does\nnot seem to be an important choice.) On the screen this will look\nsimply ``{y ** A(x) ** B(y)}`` and ``{x*y** B(x) ** B(y) ** A(z)}`` because we\nhave defined the precedence of the ``**`` operator to be the same as\nthat of the normal multiplication, so yacas won't insert any more\nparentheses.\n\nThis canonical form will allow yacas to apply all the usual rules on\nthe commutative factor while cleanly separating all non-commutative\nparts for special treatment. Note that a commutative factor such as\n``2*x`` will be multiplied by a single non-commutative piece with\n``**``.\n\nThe basic idea behind the canonical form is this: we should define\nour evaluation rules in such a way that any expression containing\n``A(k)`` and ``B(k)`` will be always automatically reduced to the\ncanonical form after one full evaluation. All functions on our new\nobjects will assume that the object is already in the canonical form\nand should return objects in the same canonical form.\n\nImplementing the canonical form\n-------------------------------\n\nNow that we have a design, let's look at some implementation\nissues. We would like to write evaluation rules involving the new\noperator ``**`` as well as the ordinary multiplications and additions\ninvolving usual numbers, so that all classical numbers and all\nquantum objects are grouped together separately. This should be\naccomplished with rules that expand brackets, exchange the bracketing\norder of expressions and move commuting factors to the left. For now,\nwe shall not concern ourselves with divisions and subtractions.\n\nFirst, we need to distinguish classical terms from the quantum\nones. For this, we shall define a predicate :func:`IsQuantum` recursively,\nas follows: ::\n\n  /* Predicate IsQuantum(): will return\n     True if the expression contains A(k)\n     or B(k) and False otherwise */\n  10 # IsQuantum(A(_x)) <-- True;\n  10 # IsQuantum(B(_x)) <-- True;\n      /* Result of a binary operation may\n        be Quantum */\n  20 # IsQuantum(_x + _y) <-- IsQuantum(x) Or IsQuantum(y);\n  20 # IsQuantum(+ _y) <-- IsQuantum(y);\n  20 # IsQuantum(_x * _y) <-- IsQuantum(x) Or IsQuantum(y);\n  20 # IsQuantum(_x ** _y) <-- IsQuantum(x) Or IsQuantum(y);\n      /* If none of the rules apply, the\n        object is not Quantum */\n  30 # IsQuantum(_x) <-- False;\n\nNow we shall construct rules that implement reduction to the canonical\nform. The rules will be given precedences, so that the reduction\nproceeds by clearly defined steps. All rules at a given precedence\nbenefit from all simplifications at earlier precedences. ::\n\n  /* First, replace * by ** if one of the\n     factors is Quantum to guard against\n     user error */\n  10 # (_x * _y)_(IsQuantum(x) Or IsQuantum(y)) <-- x ** y;\n      /* Replace ** by * if neither of the\n        factors is Quantum */\n  10 # (_x ** _y)_(Not(IsQuantum(x) Or IsQuantum(y))) <-- x * y;\n      /* Now we are guaranteed that ** is\n        used between Quantum values */\n      /* Expand all brackets involving\n        Quantum values */\n  15 # (_x + _y) ** _z <-- x ** z + y ** z;\n  15 # _z ** (_x + _y) <-- z ** x + z ** y;\n      /* Now we are guaranteed that there are\n        no brackets next to \"**\" */\n      /* Regroup the ** multiplications\n        toward the right */\n  20 # (_x ** _y) ** _z <-- x ** (y ** z);\n      /* Move classical factors to the left:\n        first, inside brackets */\n  30 # (x_IsQuantum ** _y)_(Not(IsQuantum(y))) <-- y ** x;\n      /* Then, move across brackets:\n        y and z are already ordered\n        by the previous rule */\n      /* First, if we have Q ** (C ** Q) */\n  35 # (x_IsQuantum ** (_y ** _z))_(Not(IsQuantum(y))) <-- y ** (x ** z);\n      /* Second, if we have C ** (C ** Q) */\n  35 # (_x ** (_y ** _z))_(Not(IsQuantum(x) Or IsQuantum(y))) <-- (x*y) ** z;\n\nAfter we execute this in yacas, all expressions involving additions\nand multiplications are automatically reduced to the canonical\nform. Extending these rules to subtractions and divisions is\nstraightforward.\n\nImplementing commutation relations\n----------------------------------\n\nBut we still haven't implemented the commutation relations. It is\nperhaps not necessary to have commutation rules automatically applied\nat each evaluation. We shall define the function :func:`OrderBA` that will\nbring all :math:`B`'s to the left of all :math:`A`'s by using the commutation\nrelation. (In physics, this is called *normal ordering*.) Again, our\ndefinition will be recursive. We shall assign it a later precedence\nthan our quantum evaluation rules, so that our objects will always be\nin canonical form. We need a few more rules to implement the\ncommutation relation and to propagate the ordering operation down the\nexpression tree::\n\n  /* Commutation relation */\n  40 # OrderBA(A(_k) ** B(_l)) <-- B(l)**A(k) + delta(k-l);\n  40 # OrderBA(A(_k) ** (B(_l) ** _x)) <-- OrderBA(OrderBA(A(k)**B(l)) ** x);\n      /* Ordering simple terms */\n  40 # OrderBA(_x)_(Not(IsQuantum(x))) <-- x;\n  40 # OrderBA(A(_k)) <-- A(k);\n  40 # OrderBA(B(_k)) <-- B(k);\n      /* Sums of terms */\n  40 # OrderBA(_x + _y) <-- OrderBA(x) + OrderBA(y);\n      /* Product of a classical and\n        a quantum value */\n  40 # OrderBA(_x ** _y)_(Not(IsQuantum(x))) <-- x ** OrderBA(y);\n      /* B() ** X : B is already at left,\n        no need to order it */\n  50 # OrderBA(B(_k) ** _x)<-- B(k) ** OrderBA(x);\n      /* A() ** X : need to order X first */\n  50 # OrderBA(A(_k) ** _x) <-- OrderBA(A(k) ** OrderBA(x));\n\nThese rules seem to be enough for our purposes. Note that the\ncommutation relation is implemented by the first two rules; the first\none is used by the second one which applies when interchanging factors\nA and B separated by brackets. This inconvenience of having to define\nseveral rules for what seems to be \"one thing to do\" is a consequence\nof tree-like structure of expressions in yacas. It is perhaps the\nprice we have to pay for conceptual simplicity of the design.\n\nAvoiding infinite recursion\n---------------------------\n\nHowever, we quickly discover that our definitions don't\nwork. Actually, we have run into a difficulty typical of rule-based\nprogramming::\n\n  In> OrderBA(A(k)**A(l))\n  Error on line 1 in file [CommandLine]\n  Line error occurred on:\n  >>>\n  Max evaluation stack depth reached.\n  Please use MaxEvalDepth to increase the\n    stack size as needed.\n\nThis error message means that we have created an infinite\nrecursion. It is easy to see that the last rule is at fault: it never\nstops applying itself when it operates on a term containing only :math:`A`'s\nand no :math:`B`'s. When encountering a term such as ``A(k) ** X``, the routine\ncannot determine whether ``X`` has already been normal-ordered or not,\nand it unnecessarily keeps trying to normal-order it again and\nagain. We can circumvent this difficulty by using an auxiliary\nordering function that we shall call :func:`OrderBAlate`. This function\nwill operate only on terms of the form ``A(k)**X`` and only after ``X`` has\nbeen ordered.  It will not perform any extra simplifications but\ninstead delegate all work to :func:OrderBA`::\n\n  50 # OrderBA(A(_k) ** _x) <-- OrderBAlate(A(k) ** OrderBA(x));\n  55 # OrderBAlate(_x + _y) <-- OrderBAlate(x) + OrderBAlate(y);\n  55 # OrderBAlate(A(_k) ** B(_l)) <--  OrderBA(A(k)**B(l));\n  55 # OrderBAlate(A(_k) ** (B(_l) ** _x)) <-- OrderBA(A(k)**(B(l)**x));\n  60 # OrderBAlate(A(_k) ** _x) <-- A(k)**x;\n  65 # OrderBAlate(_x) <-- OrderBA(x);\n\nNow :func:`OrderBA` works as desired.\n\n\nImplementing :func:`VEV`\n------------------------\n\nNow it is easy to define the function :func:`VEV`. This function should\nfirst execute the normal-ordering operation, so that all :math:`B`'s move to\nthe left of :math:`A`'s. After an expression is normal-ordered, all of its\nquantum terms will either end with an :math:`A(k)` or begin with a :math:`B(k)`,\nor both, and :func:`VEV` of those terms will return :math:`0`. The value of\n:func:`VEV` of a non-quantum term is just that term. The implementation\ncould look like this::\n\n  100 # VEV(_x) <-- VEVOrd(OrderBA(x));\n      /* Everything is expanded now,\n        deal term by term */\n  100 # VEVOrd(_x + _y) <-- VEVOrd(x) + VEVOrd(y);\n      /* Now cancel all quantum terms */\n  110 # VEVOrd(x_IsQuantum) <-- 0;\n      /* Classical terms are left */\n  120 # VEVOrd(_x) <-- x;\n\nTo avoid infinite recursion in calling :func:`OrderBA`, we had to\nintroduce an auxiliary function :func:`VEVOrd` that assumes its argument\nto be ordered.\n\nFinally, we try some example calculations to test our rules::\n\n  In> OrderBA(A(x)*B(y))\n  Out> B(y)**A(x)+delta(x-y);\n  In> OrderBA(A(x)*B(y)*B(z))\n  Out> B(y)**B(z)**A(x)+delta(x-z)**B(y)+delta(x-y)**B(z);\n  In> VEV(A(k)*B(l))\n  Out> delta(k-l);\n  In> VEV(A(k)*B(l)*A(x)*B(y))\n  Out> delta(k-l)*delta(x-y);\n  In> VEV(A(k)*A(l)*B(x)*B(y))\n  Out> delta(l-y)*delta(k-x)+delta(l-x)*delta(k-y);\n\nThings now work as expected. Yacas's :func:`Simplify` facilities can be\nused on the result of :func:`VEV` if it needs simplification.\n\n"
  },
  {
    "path": "docs/reference_manual/arithmetic.rst",
    "content": "==========================================\nArithmetic and other operations on numbers\n==========================================\n\n.. function:: infix +(x,y)\n\n  addition\n\n  Addition can work on integers, rational numbers,\n  complex numbers, vectors, matrices and lists.\n\n  .. hint::\n    Addition is implemented in the standard math library (as\n    opposed to being built-in). This means that it can be extended by the user.\n\n\n  :Example:\n\n  ::\n\n    In> 2+3\n    Out> 5\n\n.. function:: prefix -(x)\n\n  negation\n\n  Negation can work on integers, rational numbers,\n  complex numbers, vectors, matrices and lists.\n\n  .. hint::\n    Negation is implemented in the standard math library (as\n    opposed to being built-in). This means that it can be extended by the user.\n\n\n  :Example:\n\n  ::\n\n    In> - 3\n    Out> -3\n\n.. function:: infix -(x,y)\n\n  subtraction\n\n  Subtraction can work on integers, rational numbers,\n  complex numbers, vectors, matrices and lists.\n\n  .. hint::\n    Subtraction is implemented in the standard math library (as\n    opposed to being built-in). This means that it can be extended by the user.\n\n\n  :Example:\n\n  ::\n\n    In> 2-3\n    Out> -1\n\n.. function:: infix *(x,y)\n\n  multiplication\n\n  Multiplication can work on integers, rational numbers,\n  complex numbers, vectors, matrices and lists.\n\n  .. note::\n    In the case of matrices, multiplication is defined in\n    terms of standard matrix product.\n\n  .. hint::\n    Multiplication is implemented in the standard math library (as\n    opposed to being built-in). This means that it can be extended by the user.\n\n\n  :Example:\n\n  ::\n\n    In> 2*3\n    Out> 6\n\n.. function:: infix /(x,y)\n\n  division\n\n  Division can work on integers, rational numbers,\n  complex numbers, vectors, matrices and lists.\n\n  .. note::\n    For matrices division is element-wise.\n\n  .. hint::\n    Division is implemented in the standard math library (as\n    opposed to being built-in). This means that it can be extended by the user.\n\n\n  :Example:\n\n  ::\n\n    In> 6/2\n    Out> 3\n\n.. function:: infix ^(x,y)\n\n  exponentiation\n\n  Exponentiation can work on integers, rational numbers,\n  complex numbers, vectors, matrices and lists.\n\n  .. note::\n    In the case of matrices, exponentiation is defined in\n    terms of standard matrix product.\n\n  .. hint::\n    Exponentiation is implemented in the standard math library (as\n    opposed to being built-in). This means that it can be extended by the user.\n\n\n  :Example:\n\n  ::\n\n    In> 2^3\n    Out> 8\n\n.. function:: Div(x,y)\n\n   determine divisor\n\n  :func:`Div` performs integer division.\n  If ``Div(x,y)`` returns ``a`` and ``Mod(x,y)`` equals ``b``, then these\n  numbers satisfy :math:`x =ay + b` and :math:`0 \\leq b < y`.\n\n  :Example:\n\n  ::\n\n    In> Div(5,3)\n    Out> 1\n\n  .. seealso:: :func:`Mod`, :func:`Gcd`, :func:`Lcm`\n\n.. function:: Mod(x,y)\n\n   determine remainder\n\n  :func:`Mod` returns the division remainder.\n  If ``Div(x,y)`` returns ``a`` and ``Mod(x,y)`` equals ``b``, then these\n  numbers satisfy :math:`x =ay + b` and :math:`0 \\leq b < y`.\n\n  :Example:\n\n  ::\n\n    In> Div(5,3)\n    Out> 1\n    In> Mod(5,3)\n    Out> 2\n\n\n  .. seealso:: :func:`Div`, :func:`Gcd`, :func:`Lcm`\n\n.. function:: Gcd(n,m)\n              Gcd(list)\n\n  greatest common divisor\n\n  This function returns the `greatest common divisor\n  <https://en.wikipedia.org/wiki/Greatest_common_divisor>`_ of ``n`` and ``m``\n  or of all elements of ``list``.\n\n  .. seealso:: :func:`Lcm`\n\n.. function:: Lcm(n,m)\n              Lcm(list)\n\n  least common multiple\n\n  This command returns the `least common multiple\n  <https://en.wikipedia.org/wiki/Least_common_multiple>`_ of ``n`` and ``m`` or\n  of all elements of ``list``.\n\n  :Example:\n\n  ::\n\n    In> Lcm(60,24)\n    Out> 120\n    In> Lcm({3,5,7,9})\n    Out> 315\n\n\n  .. seealso:: :func:`Gcd`\n\n.. function:: infix <<(n, m)\n              infix >>(n, m)\n\n  binary shift operators\n\n  These operators shift integers to the left or to the right.  They\n  are similar to the C shift operators. These are sign-extended\n  shifts, so they act as multiplication or division by powers of 2.\n\n  :Example:\n\n  ::\n\n    In> 1 << 10\n    Out> 1024\n    In> -1024 >> 10\n    Out> -1\n\n.. function:: FromBase(base,\"string\")\n\n   conversion of a number from non-decimal base to decimal base\n\n   :param base: integer, base to convert to/from\n   :param number: integer, number to write out in a different base\n   :param \"string\": string representing a number in a different base\n\n   In Yacas, all numbers are written in decimal notation (base 10).\n   The two functions {FromBase}, {ToBase} convert numbers between base\n   10 and a different base.  Numbers in non-decimal notation are\n   represented by strings.    {FromBase} converts an integer, written\n   as a string in base  {base}, to base 10. {ToBase} converts\n   {number},  written in base 10, to base {base}.\n\n.. function:: N(expression)\n\n   try determine numerical approximation of expression\n\n   :param expression: expression to evaluate\n   :param precision: integer, precision to use\n\n   The function :func:`N` instructs yacas to try to coerce an expression\n   in to a numerical approximation to the  expression ``expr``, using\n   ``prec`` digits precision if the second calling  sequence is used,\n   and the default precision otherwise. This overrides the normal\n   behaviour, in which expressions are kept in symbolic form (eg.\n   ``Sqrt(2)`` instead of ``1.41421``). Application of the :func:`N` operator\n   will make yacas  calculate floating point representations of\n   functions whenever  possible. In addition, the variable :data:`Pi` is\n   bound to  the value of :math:`\\pi` calculated at the current precision.\n\n   .. note::\n     :func:`N` is a macro. Its argument ``expr`` will only be evaluated after\n     switching to numeric mode.\n\n   :Example:\n\n   ::\n\n      In> 1/2\n      Out> 1/2;\n      In> N(1/2)\n      Out> 0.5;\n      In> Sin(1)\n      Out> Sin(1);\n      In> N(Sin(1),10)\n      Out> 0.8414709848;\n      In> Pi\n      Out> Pi;\n      In> N(Pi,20)\n      Out> 3.14159265358979323846;\n\n\n   .. seealso:: :func:`Pi`\n\n.. function:: Rationalize(expr)\n\n   convert floating point numbers to fractions\n\n   :param expr: an expression containing real numbers\n\n   This command converts every real number in the expression \"expr\"\n   into a rational number. This is useful when a calculation needs to\n   be  done on floating point numbers and the algorithm is unstable.\n   Converting the floating point numbers to rational numbers will\n   force  calculations to be done with infinite precision (by using\n   rational  numbers as representations).    It does this by finding\n   the smallest integer :math:`n` such that multiplying  the number with\n   :math:`10^n` is an integer. Then it divides by :math:`10^n` again,  depending\n   on the internal gcd calculation to reduce the resulting  division\n   of integers.\n\n   :Example:\n\n   ::\n\n      In> {1.2,3.123,4.5}\n      Out> {1.2,3.123,4.5};\n      In> Rationalize(%)\n      Out> {6/5,3123/1000,9/2};\n\n\n   .. seealso:: :func:`IsRational`\n\n.. function:: ContFrac(x[,depth=6])\n\n   continued fraction expansion\n\n   :param x: number or polynomial to expand in continued fractions\n   :param depth: positive integer, maximum required depth\n\n   This command returns the `continued fraction\n   <https://en.wikipedia.org/wiki/Continued_fraction>`_ expansion of ``x``,\n   which should be either a floating point number or a polynomial. The remainder\n   is denoted by ``rest``.  This is especially useful for polynomials, since\n   series expansions that converge slowly will typically converge a lot faster\n   if calculated using a continued fraction expansion.\n\n   :Example:\n\n   ::\n\n      In> PrettyForm(ContFrac(N(Pi)))\n                    1\n      --------------------------- + 3\n                 1\n      ----------------------- + 7\n              1\n      ------------------ + 15\n           1\n      -------------- + 1\n         1\n      -------- + 292\n      rest + 1\n      Out> True;\n      In> PrettyForm(ContFrac(x^2+x+1, 3))\n      x\n      ---------------- + 1\n      x\n      1 - ------------\n      x\n      -------- + 1\n      rest + 1\n      Out> True;\n\n\n   .. seealso:: :func:`PAdicExpand`, :func:`N`\n\n.. function:: Decimal(frac)\n\n   decimal representation of a rational\n\n   :param frac: a rational number\n\n   This function returns the infinite decimal representation of a\n   rational number {frac}.  It returns a list, with the first element\n   being the number before the decimal point and the last element the\n   sequence of digits that will repeat forever. All the intermediate\n   list  elements are the initial digits before the period sets in.\n\n   :Example:\n\n   ::\n\n      In> Decimal(1/22)\n      Out> {0,0,{4,5}};\n      In> N(1/22,30)\n      Out> 0.045454545454545454545454545454;\n\n\n   .. seealso:: :func:`N`\n\n.. function:: Floor(x)\n\n   round a number downwards\n\n   :param x: a number\n\n   This function returns :math:`\\left \\lfloor{x}\\right \\rfloor`, the largest\n   integer smaller than or equal to ``x``.\n\n   :Example:\n\n   ::\n\n      In> Floor(1.1)\n      Out> 1;\n      In> Floor(-1.1)\n      Out> -2;\n\n\n   .. seealso:: :func:`Ceil`, :func:`Round`\n\n.. function:: Ceil(x)\n\n   round a number upwards\n\n   :param x: a number\n\n   This function returns :math:`\\left \\lceil{x}\\right \\rceil`, the smallest\n   integer larger than or equal to ``x``.\n\n   :Example:\n\n   ::\n\n      In> Ceil(1.1)\n      Out> 2;\n      In> Ceil(-1.1)\n      Out> -1;\n\n\n   .. seealso:: :func:`Floor`, :func:`Round`\n\n.. function:: Round(x)\n\n   round a number to the nearest integer\n\n   :param x: a number\n\n   This function returns the integer closest to :math:`x`. Half-integers\n   (i.e. numbers of the form :math:`n + 0.5`, with :math:`n` an integer) are\n   rounded upwards.\n\n   :Example:\n\n   ::\n\n      In> Round(1.49)\n      Out> 1;\n      In> Round(1.51)\n      Out> 2;\n      In> Round(-1.49)\n      Out> -1;\n      In> Round(-1.51)\n      Out> -2;\n\n\n   .. seealso:: :func:`Floor`, :func:`Ceil`\n\n.. function:: Min(x,y)\n              Min(list)\n\n   minimum of a number of values\n\n   This function returns the minimum value of its argument(s). If the\n   first calling sequence is used, the smaller of ``x`` and ``y`` is\n   returned. If one uses the second form, the smallest of the entries\n   in ``list`` is returned. In both cases, this function can only be\n   used  with numerical values and not with symbolic arguments.\n\n   :Example:\n\n   ::\n\n      In> Min(2,3)\n      Out> 2\n      In> Min({5,8,4})\n      Out> 4\n      In> Min(Pi, Exp(1))\n      Out> Exp(1)\n\n\n   .. seealso:: :func:`Max`, :func:`Sum`\n\n.. function:: Max(x,y)\n              Max(list)\n\n   maximum of a number of values\n\n   This function returns the maximum value of its argument(s). If the\n   first calling sequence is used, the larger of ``x`` and ``y`` is\n   returned. If one uses the second form, the largest of the entries\n   in  ``list`` is returned. In both cases, this function can only be\n   used  with numerical values and not with symbolic arguments.\n\n   :Example:\n\n   ::\n\n      In> Max(2,3);\n      Out> 3;\n      In> Max({5,8,4});\n      Out> 8;\n\n\n   .. seealso:: :func:`Min`, :func:`Sum`\n\n.. function:: Numer(expr)\n\n   numerator of an expression\n\n   This function determines the numerator of the rational expression\n   ``expr`` and returns it. As a special case, if its argument is\n   numeric  but not rational, it returns this number. If ``expr`` is\n   neither  rational nor numeric, the function returns unevaluated.\n\n   :Example:\n\n   ::\n\n      In> Numer(2/7)\n      Out> 2;\n      In> Numer(a / x^2)\n      Out> a;\n      In> Numer(5)\n      Out> 5;\n\n\n   .. seealso:: :func:`Denom`, :func:`IsRational`, :func:`IsNumber`\n\n.. function:: Denom(expr)\n\n   denominator of an expression\n\n   This function determines the denominator of the rational expression\n   ``expr`` and returns it. As a special case, if its argument is\n   numeric but not rational, it returns ``1``. If ``expr`` is  neither\n   rational nor numeric, the function returns unevaluated.\n\n   :Example:\n\n   ::\n\n      In> Denom(2/7)\n      Out> 7;\n      In> Denom(a / x^2)\n      Out> x^2;\n      In> Denom(5)\n      Out> 1;\n\n\n   .. seealso:: :func:`Numer`, :func:`IsRational`, :func:`IsNumber`\n\n.. function:: Pslq(xlist[,precision=6])\n\n   search for integer relations between reals\n\n   :param xlist: list of numbers\n   :param precision: required number of digits precision of calculation\n\n   This function is an integer relation detection algorithm. This\n   means  that, given the numbers :math:`x_i` in the list ``xlist``, it tries\n   to find integer coefficients\n   :math:`a_i` such that  :math:`a_1*x_1+\\ldots+a_n*x_n = 0`. The list of\n   integer coefficients is returned.\n   The numbers in \"xlist\" must evaluate to floating point numbers when\n   the :func:`N` operator is applied to them.\n\n.. function:: infix <(e1, e2)\n\n   test for \"less than\"\n\n   :param e1: expression to be compared\n   :param e2: expression to be compared\n\n   The two expression are evaluated. If both results are numeric, they\n   are compared. If the first expression is smaller than the second\n   one,  the result is :data:`True` and it is :data:`False` otherwise. If either\n   of the expression is not numeric, after  evaluation, the expression\n   is returned with evaluated arguments.    The word \"numeric\" in the\n   previous paragraph has the following  meaning. An expression is\n   numeric if it is either a number (i.e. {IsNumber} returns :data:`True`),\n   or the  quotient of two numbers, or an infinity (i.e. {IsInfinity}\n   returns :data:`True`). Yacas will try to   coerce the arguments passed to\n   this comparison operator to a real value before making the\n   comparison.\n\n   :Example:\n\n   ::\n\n      In> 2 < 5;\n      Out> True;\n      In> Cos(1) < 5;\n      Out> True;\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsInfinity`, :func:`N`\n\n.. function:: infix >(e1, e2)\n\n   test for \"greater than\"\n\n   :param e1: expression to be compared\n   :param e2: expression to be compared\n\n   The two expression are evaluated. If both results are numeric, they\n   are compared. If the first expression is larger than the second\n   one,  the result is :data:`True` and it is :data:`False` otherwise. If either\n   of the expression is not numeric, after  evaluation, the expression\n   is returned with evaluated arguments.    The word \"numeric\" in the\n   previous paragraph has the following  meaning. An expression is\n   numeric if it is either a number (i.e. {IsNumber} returns :data:`True`),\n   or the  quotient of two numbers, or an infinity (i.e. {IsInfinity}\n   returns :data:`True`). Yacas will try to   coerce the arguments passed to\n   this comparison operator to a real value before making the\n   comparison.\n\n   :Example:\n\n   ::\n\n      In> 2 > 5;\n      Out> False;\n      In> Cos(1) > 5;\n      Out> False\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsInfinity`, :func:`N`\n\n.. function:: infix <=(e1, e2)\n\n   test for \"less or equal\"\n\n   :param e1: expression to be compared\n   :param e2: expression to be compared\n\n   The two expression are evaluated. If both results are numeric, they\n   are compared. If the first expression is smaller than or equals the\n   second one, the result is :data:`True` and it is :data:`False` otherwise. If\n   either of the expression is not  numeric, after evaluation, the\n   expression is returned with evaluated  arguments.    The word\n   \"numeric\" in the previous paragraph has the following  meaning. An\n   expression is numeric if it is either a number (i.e. {IsNumber}\n   returns :data:`True`), or the  quotient of two numbers, or an infinity\n   (i.e. {IsInfinity} returns :data:`True`). Yacas will try to   coerce the\n   arguments passed to this comparison operator to a real value before\n   making the comparison.\n\n   :Example:\n\n   ::\n\n      In> 2 <= 5;\n      Out> True;\n      In> Cos(1) <= 5;\n      Out> True\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsInfinity`, :func:`N`\n\n.. function:: infix >=(e1, e2)\n\n   test for \"greater or equal\"\n\n   :param e1: expression to be compared\n   :param e2: expression to be compared\n\n   The two expression are evaluated. If both results are numeric, they\n   are compared. If the first expression is larger than or equals the\n   second one, the result is :data:`True` and it is :data:`False` otherwise. If\n   either of the expression is not  numeric, after evaluation, the\n   expression is returned with evaluated  arguments.    The word\n   \"numeric\" in the previous paragraph has the following  meaning. An\n   expression is numeric if it is either a number (i.e. {IsNumber}\n   returns :data:`True`), or the  quotient of two numbers, or an infinity\n   (i.e. {IsInfinity} returns :data:`True`). Yacas will try to   coerce the\n   arguments passed to this comparison operator to a real value before\n   making the comparison.\n\n   :Example:\n\n   ::\n\n      In> 2 >= 5;\n      Out> False;\n      In> Cos(1) >= 5;\n      Out> False\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsInfinity`, :func:`N`\n\n.. function:: IsZero(n)\n\n   test whether argument is zero\n\n   :param n: number to test\n\n   ``IsZero(n)`` evaluates to :data:`True` if  ``n`` is zero. In case ``n`` is\n   not a number, the function returns  :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsZero(3.25)\n      Out> False;\n      In> IsZero(0)\n      Out> True;\n      In> IsZero(x)\n      Out> False;\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsNotZero`\n\n.. function:: IsRational(expr)\n\n   test whether argument is a rational\n\n   :param expr: expression to test\n\n   This commands tests whether the expression \"expr\" is a rational\n   number, i.e. an integer or a fraction of integers.\n\n   :Example:\n\n   ::\n\n      In> IsRational(5)\n      Out> False;\n      In> IsRational(2/7)\n      Out> True;\n      In> IsRational(0.5)\n      Out> False;\n      In> IsRational(a/b)\n      Out> False;\n      In> IsRational(x + 1/x)\n      Out> False;\n\n\n   .. seealso:: :func:`Numer`, :func:`Denom`\n\n"
  },
  {
    "path": "docs/reference_manual/calc.rst",
    "content": "========\nCalculus\n========\n\nIn this chapter, some facilities for doing calculus are\ndescribed. These include functions implementing differentiation,\nintegration, calculating limits etc.\n\n.. function:: bodied D(expression, variable[,n=1])\n\n   derivative\n\n   :param variable: variable\n   :param expression: expression to take derivatives of\n   :param n: order\n\n   :returns: ``n``-th derivative of ``expression`` with respect to ``variable``\n\n.. function:: bodied D(expression, variable)\n\n   derivative\n\n   :param variable: variable\n   :param list: a list of variables\n   :param expression: expression to take derivatives of\n   :param n: order of derivative\n\n   :returns: derivative of ``expression`` with respect to ``variable``\n\n   This function calculates the derivative of the expression {expr}\n   with  respect to the variable {var} and returns it. If the third\n   calling  format is used, the {n}-th derivative is determined. Yacas\n   knows  how to differentiate standard functions such as {Ln}  and\n   {Sin}.    The {D} operator is threaded in both {var} and  {expr}.\n   This means that if either of them is a list, the function is\n   applied to each entry in the list. The results are collected in\n   another list which is returned. If both {var} and {expr} are a\n   list, their lengths should be equal. In this case, the first entry\n   in  the list {expr} is differentiated with respect to the first\n   entry in  the list {var}, the second entry in {expr} is\n   differentiated with  respect to the second entry in {var}, and so\n   on.    The {D} operator returns the original function if :math:`n=0`, a\n   common  mathematical idiom that simplifies many formulae.\n\n   :Example:\n\n   ::\n\n      In> D(x)Sin(x*y)\n      Out> y*Cos(x*y);\n      In> D({x,y,z})Sin(x*y)\n      Out> {y*Cos(x*y),x*Cos(x*y),0};\n      In> D(x,2)Sin(x*y)\n      Out> -Sin(x*y)*y^2;\n      In> D(x){Sin(x),Cos(x)}\n      Out> {Cos(x),-Sin(x)};\n\n\n   .. seealso:: :func:`Integrate`, :func:`Taylor`, :func:`Diverge`, :func:`Curl`\n\n.. function:: Curl(vector, basis)\n\n   curl of a vector field\n\n   :param vector: vector field to take the curl of\n   :param basis: list of variables forming the basis\n\n   This function takes the curl of the vector field ``vector`` with respect to\n   the variables ``basis``. The curl is defined in the usual way, ``Curl(f,x) =\n   {D(x[2]) f[3] - D(x[3]) f[2], D(x[3]) f[1] - D(x[1])f[3], D(x[1]) f[2] -\n   D(x[2]) f[1]}``.  Both ``vector`` and ``basis`` should be lists of length 3.\n\n.. function:: Diverge(vector, basis)\n\n   divergence of a vector field\n\n   :param vector: vector field to calculate the divergence of\n   :param basis: list of variables forming the basis\n\n   This function calculates the divergence of the vector field ``vector``  with\n   respect to the variables ``basis``. The divergence is defined as\n   ``Diverge(f,x) = D(x[1]) f[1] + ... + D(x[n]) f[n]``,  where ``n`` is the\n   length of the lists ``vector`` and ``basis``. These lists should have equal\n   length.\n\n.. function:: HessianMatrix(function,var)\n\n   create the Hessian matrix\n\n   :param function: a function in :math:`n` variables\n   :param var: an :math:`n`-dimensional vector of variables\n\n   The function :func:`HessianMatrix` calculates the Hessian matrix of a vector.\n   If :math:`f(x)` is a function of an :math:`n`-dimensional vector :math:`x`,\n   then the :math:`(i,j)`-th element of the Hessian matrix of the function\n   :math:`f(x)` is defined as :math:` Deriv(x[i]) Deriv(x[j]) f(x)`. If the\n   second order mixed partials are continuous, then the Hessian matrix is\n   symmetric (a standard theorem of calculus). The Hessian matrix is used in the\n   second derivative test to discern if a critical point is a local maximum, a\n   local minimum or a saddle point.\n\n   :Example:\n\n   ::\n\n      In> HessianMatrix(3*x^2-2*x*y+y^2-8*y, {x,y} )\n      Out> {{6,-2},{-2,2}};\n      In> PrettyForm(%)\n      /                \\\n      | ( 6 )  ( -2 )  |\n      |                |\n      | ( -2 ) ( 2 )   |\n      \\                /\n\n\n.. function:: JacobianMatrix(functions,variables)\n\n   calculate the Jacobian matrix of :math:`n` functions in :math:`n` variables\n\n   :param functions: an :math:`n`-dimensional vector of functions\n   :param variables: an :math:`n`-dimensional vector of variables\n\n   The function {JacobianMatrix} calculates the Jacobian matrix  of n\n   functions in n variables.    The :math:`(i,j)`-th element of the\n   Jacobian matrix is defined as the derivative  of :math:`i`-th function\n   with respect to the :math:`j`-th variable.\n\n   :Example:\n\n   ::\n\n      In> JacobianMatrix( {Sin(x),Cos(y)}, {x,y} );\n      Out> {{Cos(x),0},{0,-Sin(y)}};\n      In> PrettyForm(%)\n      /                                 \\\n      | ( Cos( x ) ) ( 0 )              |\n      |                                 |\n      | ( 0 )        ( -( Sin( y ) ) )  |\n      \\                                 /\n\n\n.. function:: bodied Integrate(expr, var)\n              bodied Integrate(expr, var, x1, x2)\n\n   integral\n\n   :param expr: expression to integrate\n   :param var: atom, variable to integrate over\n   :param x1: first point of definite integration\n   :param x2: second point of definite integration\n\n   This function integrates the expression `expr` with respect to the\n   variable `var`. In the case of definite integral, the integration\n   is carried out from :math:`var=x1` to :math:`var=x2`\". Some simple integration\n   rules have currently been implemented.  Polynomials, some quotients\n   of polynomials, trigonometric functions and their inverses,\n   hyperbolic functions and their inverses, {Exp}, and {Ln}, and\n   products of these functions with polynomials can be integrated.\n\n   :Example:\n\n   ::\n\n      In> Integrate(x,a,b) Cos(x)\n      Out> Sin(b)-Sin(a);\n      In> Integrate(x) Cos(x)\n      Out> Sin(x);\n\n\n   .. seealso:: :func:`D`, :func:`UniqueConstant`\n\n.. function:: bodied Limit(expr, var, val)\n\n   limit of an expression\n\n   :param var: variable\n   :param val: number or ``Infinity``\n   :param dir: direction (``Left`` or ``Right``)\n   :param expr: an expression\n\n   This command tries to determine the value that the expression\n   \"expr\"  converges to when the variable \"var\" approaches \"val\". One\n   may use  {Infinity} or {-Infinity} for  \"val\". The result of\n   {Limit} may be one of the  symbols {Undefined} (meaning that the\n   limit does not  exist), {Infinity}, or {-Infinity}.    The second\n   calling sequence is used for unidirectional limits. If one  gives\n   \"dir\" the value {Left}, the limit is taken as  \"var\" approaches\n   \"val\" from the positive infinity; and {Right} will take the limit\n   from the negative infinity.\n\n   :Example:\n\n   ::\n\n      In> Limit(x,0) Sin(x)/x\n      Out> 1;\n      In> Limit(x,0) (Sin(x)-Tan(x))/(x^3)\n      Out> -1/2;\n      In> Limit(x,0) 1/x\n      Out> Undefined;\n      In> Limit(x,0,Left) 1/x\n      Out> -Infinity;\n      In> Limit(x,0,Right) 1/x\n      Out> Infinity;\n\n.. function:: Add(val1, val2, ...)\n              Add(list)\n\n   find sum of a list of values\n\n   :param val1 val2: expressions\n   :param list: list of expressions to add\n\n   This function adds all its arguments and returns their sum. It\n   accepts any  number of arguments. The arguments can be also passed\n   as a list.\n\n   :Example:\n\n   ::\n\n      In> Add(1,4,9);\n      Out> 14;\n      In> Add(1 .. 10);\n      Out> 55;\n\n.. function:: Multiply(val1, val2, ...)\n              Multiply(list)\n\n   product of a list of values\n\n   :param val1 val2: expressions\n   :param list: list of expressions to add\n\n   Multiply all arguments and returns their product. It\n   accepts any  number of arguments. The arguments can be also passed\n   as a list.\n\n   :Example:\n\n   ::\n\n      In> Multiply(2,3,4);\n      Out> 24\n      In> Multiply(1 .. 10)\n      Out> 3628800\n\n.. function:: Sum(var, from, to, body)\n\n   find sum of a sequence\n\n   :param var: variable to iterate over\n   :param from: integer value to iterate from\n   :param to: integer value to iterate up to\n   :param body: expression to evaluate for each iteration\n\n   The command finds the sum of the sequence generated by an iterative\n   formula.   The expression \"body\" is  evaluated while the variable\n   \"var\" ranges over all integers from  \"from\" up to \"to\", and the sum\n   of all the results is  returned. Obviously, \"to\" should be greater\n   than or equal to  \"from\".    Warning: {Sum} does not evaluate its\n   arguments {var} and {body} until the actual loop is run.\n\n   :Example:\n\n   ::\n\n      In> Sum(i, 1, 3, i^2);\n      Out> 14;\n\n\n   .. seealso:: :func:`Factorize`\n\n.. function:: Factorize(list)\n\n   product of a list of values\n\n   :param list: list of values to multiply\n   :param var: variable to iterate over\n   :param from: integer value to iterate from\n   :param to: integer value to iterate up to\n   :param body: expression to evaluate for each iteration\n\n   The first form of the {Factorize} command simply  multiplies all\n   the entries in \"list\" and returns their product.    If the second\n   calling sequence is used, the expression \"body\" is  evaluated while\n   the variable \"var\" ranges over all integers from  \"from\" up to\n   \"to\", and the product of all the results is  returned. Obviously,\n   \"to\" should be greater than or equal to  \"from\".\n\n   :Example:\n\n   ::\n\n      In> Factorize({1,2,3,4});\n      Out> 24;\n      In> Factorize(i, 1, 4, i);\n      Out> 24;\n\n\n   .. seealso:: :func:`Sum`, :func:`Apply`\n\n.. function:: Taylor(var, at, order) expr\n\n   univariate Taylor series expansion\n\n   :param var: variable\n   :param at: point to get Taylor series around\n   :param order: order of approximation\n   :param expr: expression to get Taylor series for\n\n   This function returns the Taylor series expansion of the expression\n   \"expr\" with respect to the variable \"var\" around \"at\" up to order\n   \"order\". This is a polynomial which agrees with \"expr\" at the\n   point \"var = at\", and furthermore the first \"order\" derivatives of\n   the polynomial at this point agree with \"expr\". Taylor expansions\n   around removable singularities are correctly handled by taking the\n   limit as \"var\" approaches \"at\".\n\n   :Example:\n\n   ::\n\n      In> PrettyForm(Taylor(x,0,9) Sin(x))\n      3    5      7       9\n      x    x      x       x\n      x - -- + --- - ---- + ------\n      6    120   5040   362880\n      Out> True;\n\n\n   .. seealso:: :func:`D`, :func:`InverseTaylor`, :func:`ReversePoly`, :func:`BigOh`\n\n.. function:: InverseTaylor(var, at, order) expr\n\n   Taylor expansion of inverse\n\n   :param var: variable\n   :param at: point to get inverse Taylor series around\n   :param order: order of approximation\n   :param expr: expression to get inverse Taylor series for\n\n   This function builds the Taylor series expansion of the inverse of\n   the  expression \"expr\" with respect to the variable \"var\" around\n   \"at\"  up to order \"order\". It uses the function {ReversePoly} to\n   perform the task.\n\n   :Example:\n\n   ::\n\n      In> PrettyPrinter'Set(\"PrettyForm\")\n      True\n      In> exp1 := Taylor(x,0,7) Sin(x)\n      3    5      7\n      x    x      x\n      x - -- + --- - ----\n      6    120   5040\n      In> exp2 := InverseTaylor(x,0,7) ArcSin(x)\n      5      7     3\n      x      x     x\n      --- - ---- - -- + x\n      120   5040   6\n      In> Simplify(exp1-exp2)\n      0\n\n\n   .. seealso:: :func:`ReversePoly`, :func:`Taylor`, :func:`BigOh`\n\n.. function:: ReversePoly(f, g, var, newvar, degree)\n\n   solve :math:`h(f(x)) = g(x) + O(x^n)` for :math:`h`\n\n   :param f: function of ``var``\n   :param g: function of ``var``\n   :param var: a variable\n   :param newvar: a new variable to express the result in\n   :param degree: the degree of the required solution\n\n   This function returns a polynomial in \"newvar\", say \"h(newvar)\",\n   with the property that \"h(f(var))\" equals \"g(var)\" up to order\n   \"degree\". The degree of the result will be at most \"degree-1\". The\n   only requirement is that the first derivative of \"f\" should not be\n   zero.    This function is used to determine the Taylor series\n   expansion of the  inverse of a function \"f\": if we take\n   \"g(var)=var\", then  \"h(f(var))=var\" (up to order \"degree\"), so \"h\"\n   will be the  inverse of \"f\".\n\n   :Example:\n\n   ::\n\n      In> f(x):=Eval(Expand((1+x)^4))\n      Out> True;\n      In> g(x) := x^2\n      Out> True;\n      In> h(y):=Eval(ReversePoly(f(x),g(x),x,y,8))\n      Out> True;\n      In> BigOh(h(f(x)),x,8)\n      Out> x^2;\n      In> h(x)\n      Out> (-2695*(x-1)^7)/131072+(791*(x-1)^6)/32768 +(-119*(x-1)^5)/4096+(37*(x-1)^4)/1024+(-3*(x-1)^3)/64+(x-1)^2/16;\n\n\n   .. seealso:: :func:`InverseTaylor`, :func:`Taylor`, :func:`BigOh`\n\n.. function:: BigOh(poly, var, degree)\n\n   drop all terms of a certain order in a polynomial\n\n   :param poly: a univariate polynomial\n   :param var: a free variable\n   :param degree: positive integer\n\n   This function drops all terms of order \"degree\" or higher in\n   \"poly\", which is a polynomial in the variable \"var\".\n\n   :Example:\n\n   ::\n\n      In> BigOh(1+x+x^2+x^3,x,2)\n      Out> x+1;\n\n\n   .. seealso:: :func:`Taylor`, :func:`InverseTaylor`\n\n.. function:: LagrangeInterpolant(xlist, ylist, var)\n\n   polynomial interpolation\n\n   :param xlist: list of argument values\n   :param ylist: list of function values\n   :param var: free variable for resulting polynomial\n\n   This function returns a polynomial in the variable \"var\" which\n   interpolates the points \"(xlist, ylist)\". Specifically, the value\n   of  the resulting polynomial at \"xlist[1]\" is \"ylist[1]\", the value\n   at  \"xlist[2]\" is \"ylist[2]\", etc. The degree of the polynomial is\n   not  greater than the length of \"xlist\".    The lists \"xlist\" and\n   \"ylist\" should be of equal  length. Furthermore, the entries of\n   \"xlist\" should be all distinct  to ensure that there is one and\n   only one solution.    This routine uses the Lagrange interpolant\n   formula to build up the  polynomial.\n\n   :Example:\n\n   ::\n\n      In> f := LagrangeInterpolant({0,1,2}, \\\n      {0,1,1}, x);\n      Out> (x*(x-1))/2-x*(x-2);\n      In> Eval(Subst(x,0) f);\n      Out> 0;\n      In> Eval(Subst(x,1) f);\n      Out> 1;\n      In> Eval(Subst(x,2) f);\n      Out> 1;\n      In> PrettyPrinter'Set(\"PrettyForm\");\n      True\n      In> LagrangeInterpolant({x1,x2,x3}, {y1,y2,y3}, x)\n      y1 * ( x - x2 ) * ( x - x3 )\n      ----------------------------\n      ( x1 - x2 ) * ( x1 - x3 )\n      y2 * ( x - x1 ) * ( x - x3 )\n      + ----------------------------\n      ( x2 - x1 ) * ( x2 - x3 )\n      y3 * ( x - x1 ) * ( x - x2 )\n      + ----------------------------\n      ( x3 - x1 ) * ( x3 - x2 )\n\n\n   .. seealso:: :func:`Subst`\n\n.. function:: postfix !(n)\n\n   factorial\n\n   :param m: integer\n   :param n: integer, half-integer, or list\n   :param a}, {b: numbers\n\n   The factorial function {n!} calculates the factorial of integer or\n   half-integer numbers. For  nonnegative integers, :math:`n! :=\n   n*(n-1)*(n-2)*...*1`. The factorial of  half-integers is defined\n   via Euler's Gamma function, :math:`z! := Gamma(z+1)`. If :math:`n=0` the\n   function returns :math:`1`.    The \"double factorial\" function {n!!}\n   calculates :math:`n*(n-2)*(n-4)*...`. This product terminates either with\n   :math:`1` or with :math:`2` depending on whether :math:`n` is odd or even. If :math:`n=0`\n   the function returns :math:`1`.    The \"partial factorial\" function {a\n   *** b} calculates the product :math:`a*(a+1)*...` which is terminated at\n   the least integer not greater than :math:`b`. The arguments :math:`a` and :math:`b`\n   do not have to be integers; for integer arguments, {a *** b} = :math:`b!\n   / (a-1)!`. This function is sometimes a lot faster than evaluating\n   the two factorials, especially if :math:`a` and :math:`b` are close together.\n   If :math:`a>b` the function returns :math:`1`.    The {Subfactorial} function\n   can be interpreted as the  number of permutations of {m} objects in\n   which no object   appears in its natural place, also called\n   \"derangements.\"     The factorial functions are threaded, meaning\n   that if the argument {n} is a  list, the function will be applied\n   to each element of the list.    Note: For reasons of Yacas syntax,\n   the factorial sign {!} cannot precede other  non-letter symbols\n   such as {+} or {*}. Therefore, you should enter a space  after {!}\n   in expressions such as {x! +1}.    The factorial functions\n   terminate and print an error message if the arguments are too large\n   (currently the limit is :math:`n < 65535`) because exact factorials of\n   such large numbers are computationally expensive and most probably\n   not useful. One can call {Internal'LnGammaNum()} to evaluate\n   logarithms of such factorials to desired precision.\n\n   :Example:\n\n   ::\n\n      In> 5!\n      Out> 120;\n      In> 1 * 2 * 3 * 4 * 5\n      Out> 120;\n      In> (1/2)!\n      Out> Sqrt(Pi)/2;\n      In> 7!!;\n      Out> 105;\n      In> 1/3 *** 10;\n      Out> 17041024000/59049;\n      In> Subfactorial(10)\n      Out> 1334961;\n\n\n   .. seealso:: :func:`Bin`, :func:`Factorize`, :func:`Gamma`, :func:`!!`, :func:`***`, :func:`Subfactorial`\n\n.. function:: postfix !!(n)\n\n   double factorial\n\n.. function:: infix ***(x,y)\n\n   whatever\n\n.. function:: Bin(n, m)\n\n   binomial coefficients\n\n   :param n}, {m: integers\n\n   This function calculates the binomial coefficient \"n\" above  \"m\",\n   which equals :math:`n! / (m! * (n-m)!)`    This is equal to the number\n   of ways  to choose \"m\" objects out of a total of \"n\" objects if\n   order is  not taken into account. The binomial coefficient is\n   defined to be zero  if \"m\" is negative or greater than \"n\";\n   {Bin(0,0)}=1.\n\n   :Example:\n\n   ::\n\n      In> Bin(10, 4)\n      Out> 210;\n      In> 10! / (4! * 6!)\n      Out> 210;\n\n\n   .. seealso:: :func:`!`, :func:`Eulerian`\n\n.. function:: Eulerian(n,m)\n\n   Eulerian numbers\n\n   The `Eulerian numbers <https://en.wikipedia.org/wiki/Eulerian_number>`_ can\n   be viewed as a generalization of the binomial coefficients,  and are given\n   explicitly by :math:`Sum(j,0,k+1,(-1)^j*Bin(n+1,j)*(k-j+1)^n)`.\n\n   :Example:\n\n   ::\n\n      In> Eulerian(6,2)\n      Out> 302;\n      In> Eulerian(10,9)\n      Out> 1;\n\n   .. seealso:: :func:`Bin`\n\n.. function:: KroneckerDelta(i,j)\n              KroneckerDelta({i,j,...})\n\n   Kronecker delta\n\n   Calculates the `Kronecker delta`_, which gives :math:`1`\n   if all arguments are equal and :math:`0` otherwise.\n\n.. _Kronecker delta: https://en.wikipedia.org/wiki/Kronecker_delta\n\n\n.. function:: LeviCivita(list)\n\n   totally anti-symmetric Levi-Civita symbol\n\n   :param list: a list of integers :math:`1,\\ldots,n` in some order\n\n   :func:`LeviCivita` implements the `Levi-Civita symbol\n   <https://en.wikipedia.org/wiki/Levi-Civita_symbol>`_. ``list``  should be a\n   list of integers, and this function returns 1 if the integers are in\n   successive order,  eg. ``LeviCivita({1,2,3,...})``  would return 1. Swapping\n   two elements of this  list would return -1. So, ``LeviCivita({2,1,3})`` would\n   evaluate  to -1.\n\n   :Example:\n\n   ::\n\n      In> LeviCivita({1,2,3})\n      Out> 1;\n      In> LeviCivita({2,1,3})\n      Out> -1;\n      In> LeviCivita({2,2,3})\n      Out> 0;\n\n\n   .. seealso:: :func:`Permutations`\n\n.. function:: Permutations(list)\n\n   get all permutations of a list\n\n   :param list: a list of elements\n\n   Permutations returns a list with all the permutations of  the\n   original list.\n\n   :Example:\n\n   ::\n\n      In> Permutations({a,b,c})\n      Out> {{a,b,c},{a,c,b},{c,a,b},{b,a,c},\n      {b,c,a},{c,b,a}};\n\n\n   .. seealso:: :func:`LeviCivita`\n\n\n.. function:: Fibonacci(n)\n\n   Fibonacci sequence\n\n   The function returns :math:`n`-th `Fibonacci number`_\n\n   :Example:\n\n   ::\n\n      In> Fibonacci(4)\n      Out> 3\n      In> Fibonacci(8)\n      Out> 21\n      In> Table(Fibonacci(i), i, 1, 10, 1)\n      Out> {1,1,2,3,5,8,13,21,34,55}\n\n.. _Fibonacci number: https://en.wikipedia.org/wiki/Fibonacci_number\n"
  },
  {
    "path": "docs/reference_manual/consts.rst",
    "content": "=========\nConstants\n=========\n\nYacas-specific constants\n------------------------\n\n.. data:: %\n\n   previous result\n\n   :data:`%` evaluates to the previous result on the command\n   line. :data:`%` is a global variable that is bound to the previous\n   result from the command line.  Using :data:`%` will evaluate the\n   previous result. (This uses the functionality offered by the\n   {SetGlobalLazyVariable} command).\n\n   Typical examples are ``Simplify(%)`` and ``PrettyForm(%)`` to\n   simplify and show the result in a nice form respectively.\n\n   :Example:\n\n   ::\n\n      In> Taylor(x,0,5)Sin(x)\n      Out> x-x^3/6+x^5/120;\n      In> PrettyForm(%)\n    \n           3    5\n          x    x\n      x - -- + ---\n          6    120\n    \n   .. seealso:: :func:`SetGlobalLazyVariable`\n\n.. data:: EndOfFile\n\n   end-of-file marker\n\n   End of file marker when reading from file. If a file contains the\n   expression {EndOfFile;} the operation will stop reading the file at\n   that point.\n\nMathematical constants\n----------------------\n\n.. data:: True\n          False\n\n   boolean constants representing true and false\n\n   :data:`True` and :data:`False` are typically a result of boolean\n   expressions such as ``2 < 3`` or ``True And False``.\n\n.. seealso:: :func:`And`, :func:`Or`, :func:`Not`\n\n.. data:: Infinity\n\n   constant representing mathematical infinity\n\n   :data:`Infinity` represents infinitely large values. It can be the\n   result of certain calculations.\n\n   Note that for most analytic functions yacas understands\n   :data:`Infinity` as a positive number.  Thus ``Infinity*2`` will\n   return ``Infinity``, and ``a < Infinity`` will evaluate to\n   :data:`True`.\n\n   :Example:\n\n   ::\n\n      In> 2*Infinity\n      Out> Infinity;\n      In> 2<Infinity\n      Out> True;\n\n.. data:: Pi\n\n   mathematical constant, :math:`\\pi`\n\n   The :term:`constant` represents the `number π <https://en.wikipedia.org/wiki/Pi>`_.\n   It is available symbolically as ``Pi`` or numerically through ``N(Pi)``.\n\n   This is a :term:`cached constant` which is recalculated only when\n   precision is increased.\n\n   :Example:\n\n   ::\n\n      In> Sin(3*Pi/2)\n      Out> -1;\n      In> Pi+1\n      Out> Pi+1;\n      In> N(Pi)\n      Out> 3.14159265358979323846;\n\n.. seealso:: :func:`Sin`, :func:`Cos`, :func:`N`, :func:`CachedConstant`\n\n.. data:: Undefined\n\n   constant signifying an undefined result\n\n   :data:`Undefined` is a token that can be returned by a function\n   when it considers its input to be invalid or when no meaningful\n   answer can be given. The result is then undefined.\n\n   Most functions also return :data:`Undefined` when evaluated on it.\n\n   :Example:\n\n   ::\n\n      In> 2*Infinity\n      Out> Infinity;\n      In> 0*Infinity\n      Out> Undefined;\n      In> Sin(Infinity);\n      Out> Undefined;\n      In> Undefined+2*Exp(Undefined);\n      Out> Undefined;\n\n.. seealso:: :data:`Infinity`\n\n.. data:: GoldenRatio\n\n   the golden ratio\n\n   The :term:`constant` represents the `golden ratio <https://en.wikipedia.org/wiki/Golden_ratio>`_\n\n   .. math::\n      \\phi := \\frac{1+\\sqrt{5}}{2} = 1.6180339887\\ldots\n\n   It is available symbolically as ``GoldenRatio`` or\n   numerically through ``N(GoldenRatio)``.\n\n   This is a :term:`cached constant` which is recalculated only when precision\n   is increased.\n\n   :Example:\n\n   ::\n\n      In> x:=GoldenRatio - 1\n      Out> GoldenRatio-1;\n      In> N(x)\n      Out> 0.6180339887;\n      In> N(1/GoldenRatio)\n      Out> 0.6180339887;\n      In> V(N(GoldenRatio,20));\n      \n      CachedConstant: Info: constant GoldenRatio is\n      being recalculated at precision 20 \n      Out> 1.6180339887498948482;\n\n\n.. seealso:: :func:`N`, :func:`CachedConstant`\n\n\n.. data:: Catalan\n\n   Catalan's constant\n\n   The :term:`constant` represents the `Catalan's constant <https://en.wikipedia.org/wiki/Catalan%27s_constant>`_\n\n   .. math::\n      G := \\beta(2) = \\sum_{n=0}^\\infty\\frac{-1^n}{(2n+1)^2}=0.9159655941\\ldots\n\n   It is available symbolically as ``Catalan`` or numerically\n   through ``N(Catalan)``.\n\n   This is a :term:`cached constant` which is recalculated only\n   when precision is increased.\n\n   :Example:\n\n   ::\n\n      In> N(Catalan)\n      Out> 0.9159655941;\n      In> DirichletBeta(2)\n      Out> Catalan;\n      In> V(N(Catalan,20))\n\n      CachedConstant: Info: constant Catalan is\n      being recalculated at precision 20\n      Out> 0.91596559417721901505;\n\n.. seealso:: :func:`N`, :func:`CachedConstant`\n\n.. data:: gamma\n\n   Euler–Mascheroni constant :math:`\\gamma`\n\n   The :term:`constant` represents the `Euler–Mascheroni constant <https://en.wikipedia.org/wiki/Euler–Mascheroni_constant>`_\n\n   .. math::\n      \\gamma := \\lim_{n\\to\\infty}\\left(-\\ln(n)+\\sum_{k=1}^n\\frac{1}{k}\\right)=0.5772156649\\ldots\n\n   It is available symbolically as ``gamma`` or numerically\n   through ``N(gamma)``.\n\n   This is a :term:`cached constant` which is recalculated only\n   when precision is increased.\n\n   .. note::\n      Euler's :math:`\\Gamma(x)` function is the capitalized :func:`Gamma` in yacas.\n\n   :Example:\n\n   ::\n\n      In> gamma+Pi\n      Out> gamma+Pi;\n      In> N(gamma+Pi)\n      Out> 3.7188083184;\n      In> V(N(gamma,20))\n    \n      CachedConstant: Info: constant gamma is being\n        recalculated at precision 20 \n      GammaConstNum: Info: used 56 iterations at\n        working precision 24 \n      Out> 0.57721566490153286061;\n\n.. seealso:: :func:`Gamma`, :func:`N`, :func:`CachedConstant`\n"
  },
  {
    "path": "docs/reference_manual/controlflow.rst",
    "content": "======================\nControl flow functions\n======================\n\nEvaluation control\n------------------\n\n.. function:: MaxEvalDepth(n)\n\n   set the maximum evaluation depth\n\n   Use this command to set the maximum evaluation depth to ``n``. The default\n   value is 1000.\n\n   The point of having a maximum evaluation depth is to catch any infinite\n   recursion. For example, after the definition ``f(x) := f(x)``, evaluating the\n   expression ``f(x)`` would call ``f(x)``, which would call ``f(x)``, etc. The\n   interpreter will halt if the maximum evaluation depth is reached. Also\n   indirect recursion, e.g. the pair of definitions ``f(x) := g(x)`` and ``g(x)\n   := f(x)``, will be caught.\n\n   An example of an infinite recursion, caught because the maximum\n   evaluation depth is reached::\n\n      In> f(x) := f(x)\n      Out> True;\n      In> f(x)\n\n      Error on line 1 in file [CommandLine]\n      Max evaluation stack depth reached.\n      Please use MaxEvalDepth to increase the stack\n      size as needed.\n\n   However, a long calculation may cause the maximum evaluation depth to\n   be reached without the presence of infinite recursion. The function\n   :func:`MaxEvalDepth` is meant for these cases::\n\n      In> 10 # g(0) <-- 1;\n      Out> True;\n      In> 20 # g(n_IsPositiveInteger) <-- \\\n      2 * g(n-1);\n      Out> True;\n      In> g(1001);\n      Error on line 1 in file [CommandLine]\n      Max evaluation stack depth reached.\n      Please use MaxEvalDepth to increase the stack\n      size as needed.\n      In> MaxEvalDepth(10000);\n      Out> True;\n      In> g(1001);\n      Out> 21430172143725346418968500981200036211228096234\n      1106721488750077674070210224987224498639675763139171\n      6255189345835106293650374290571384628087196915514939\n      7149607869135549648461970842149210124742283755908364\n      3060929499671638825347975351183310878921541258291423\n      92955373084335320859663305248773674411336138752;\n\n.. function:: Hold(expr)\n\n   keep expression unevaluated\n\n   The expression ``expr`` is returned unevaluated. This is useful to\n   prevent the evaluation of a certain expression in a context in\n   which evaluation normally takes place.\n\n   :Example:\n\n   ::\n\n      In> Echo({ Hold(1+1), \"=\", 1+1 });\n      1+1 = 2\n      Out> True;\n\n   .. seealso:: :func:`Eval`, :func:`HoldArg`, :func:`UnList`\n\n\n.. function:: Eval(expr)\n\n   force evaluation of expression\n\n   This function explicitly requests an evaluation of the expression\n   ``expr``, and returns the result of this evaluation.\n\n   :Example:\n\n   ::\n\n      In> a := x;\n      Out> x;\n      In> x := 5;\n      Out> 5;\n      In> a;\n      Out> x;\n      In> Eval(a);\n      Out> 5;\n\n   The variable ``a`` is bound to ``x``, and ``x`` is bound\n   to 5. Hence evaluating ``a`` will give ``x``. Only when an extra\n   evaluation of ``a`` is requested, the value 5 is returned.  Note\n   that the behavior would be different if we had exchanged the\n   assignments. If the assignment ``a := x`` were given while ``x``\n   had the value 5, the variable ``a`` would also get the value 5\n   because the assignment operator :func:`:=` evaluates the right-hand\n   side.\n\n   .. seealso:: :func:`Hold`, :func:`HoldArg`, :func:`:=`\n\n\nConditional execution\n---------------------\n\n.. function:: If(pred,then,[else])\n\n   branch point\n\n   This command implements a branch point. The predicate ``pred`` is evaluated,\n   which should result in either :const:`True` or :const:`False`. In the first\n   case, the expression ``then`` is evaluated and returned. If the predicate\n   yields :const:`False`, the expression ``else`` (if present) is evaluated and\n   returned. If there is no ``else`` branch, the :func:`If` expression returns\n   :const:`False`.\n\n   The sign function is defined to be 1 if its argument is positive and\n   -1 if its argument is negative. A possible implementation is::\n\n      In> mysign(x) := If (IsPositiveReal(x), 1, -1);\n      Out> True;\n      In> mysign(Pi);\n      Out> 1;\n      In> mysign(-2.5);\n      Out> -1;\n\n   Note that this will give incorrect results, if ``x`` cannot be\n   numerically approximated::\n\n      In> mysign(a);\n      Out> -1;\n\n   Hence a better implementation would be::\n\n      In> mysign(_x)_IsNumber(N(x)) <-- If(IsPositiveReal(x), 1, -1);\n      Out> True;\n\nLoops\n-----\n\n.. function:: bodied While(expr, pred)\n\n   loop while a condition is met\n\n   Keep on evaluating ``expr`` while ``pred`` evaluates to :const:`True`. More\n   precisely, :func:`While` evaluates the predicate ``pred``, which should\n   evaluate to either :const:`True` or :const:`False`. If the result is\n   :const:`True`, the expression ``expr`` is evaluated and then the predicate\n   ``pred`` is evaluated again. If it is still :const:`True`, the expressions\n   ``expr`` and ``pred`` are again evaluated and so on until ``pred`` evaluates\n   to :const:`False`. At that point, the loop terminates and :func:`While`\n   returns :const:`True`.\n\n   In particular, if ``pred`` immediately evaluates to :const:`False`, the body\n   is never executed. :func:`While` is the fundamental looping construct on\n   which all other loop commands are based. It is equivalent to the ``while``\n   command in the programming language C.\n\n   :Example:\n\n   ::\n\n      In> x := 0;\n      Out> 0;\n      In> While (x! < 10^6) [ Echo({x, x!}); x++; ];\n      0  1\n      1  1\n      2  2\n      3  6\n      4  24\n      5  120\n      6  720\n      7  5040\n      8  40320\n      9  362880\n      Out> True;\n\n\n   .. seealso:: :func:`Until`, :func:`For`\n\n.. function:: bodied Until(expr, pred)\n\n   loop until a condition is met\n\n   Keep on evaluating ``expr`` until ``pred`` becomes :const:`True`. More\n   precisely, :func:`Until` first evaluates the expression ``body``. Then the\n   predicate ``pred`` is evaluated, which should yield either :const:`True` or\n   :const:`False`. In the latter case, the expressions ``expr`` and ``pred`` are\n   again evaluated and this continues as long as \"pred\" is :const:`False`. As\n   soon as ``pred`` yields :const:`True`, the loop terminates and :func:`Until`\n   returns :const:`True`.\n\n   The main difference with :func:`While` is that :func:`Until` always evaluates\n   ``expr`` at least once, but :func:`While` may not evaluate it at all.\n   Besides, the meaning of the predicate is reversed: :func:`While` stops if\n   ``pred`` is :const:`False` while :func:`Until` stops if ``pred`` is\n   :const:`True`. The command ``Until(pred) expr;`` is equivalent to ``pred;\n   While(Not pred) body;``. In fact, the implementation of :func:`Until` is\n   based on the internal command :func:`While`. The :func:`Until` command can be\n   compared to the ``do ... while`` construct in the programming language C.\n\n   :Example:\n\n   ::\n\n      In> x := 0;\n      Out> 0;\n      In> Until (x! > 10^6) [ Echo({x, x!}); x++; ];\n      0  1\n      1  1\n      2  2\n      3  6\n      4  24\n      5  120\n      6  720\n      7  5040\n      8  40320\n      9  362880\n      Out> True;\n\n\n   .. seealso:: :func:`While`, :func:`For`\n\n.. function:: bodied For(expr, init, pred, incr)\n\n   C-style ``for`` loop\n\n   This commands implements a C style ``for`` loop. First of all, the\n   expression ``init`` is evaluated. Then the predicate ``pred`` is\n   evaluated, which should return :const:`True` or :const:`False`. Next, the\n   loop is executed as long as the predicate yields :const:`True`. One\n   traversal of the loop consists of the subsequent evaluations of\n   ``expr``, ``incr``, and ``pred``. Finally, :const:`True` is returned.\n\n   This command is most often used in a form such as ``For(i=1, i<=10,\n   i++) expr``, which evaluates ``expr`` with ``i`` subsequently set\n   to 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.\n\n   The expression ``For(init, pred, incr) expr`` is equivalent to\n   ``init; While(pred) [expr; incr;]``.\n\n   :Example:\n\n   ::\n\n      In> For (i:=1, i<=10, i++) Echo({i, i!});\n      1  1\n      2  2\n      3  6\n      4  24\n      5  120\n      6  720\n      7  5040\n      8  40320\n      9  362880\n      10  3628800\n      Out> True;\n\n\n   .. seealso:: :func:`While`, :func:`Until`, :func:`ForEach`\n\n\n.. function:: bodied ForEach(expr, var, list)\n\n   loop over all entries in list\n\n   The expression ``expr`` is evaluated multiple times. The first\n   time, ``var`` has the value of the first element of \"list\", then it\n   gets the value of the second element and so on. :func:`ForEach`\n   returns :const:`True`.\n\n   :Example:\n\n   ::\n\n      In> ForEach(i,{2,3,5,7,11}) Echo({i, i!});\n      2  2\n      3  6\n      5  120\n      7  5040\n      11  39916800\n      Out> True;\n\n\n   .. seealso:: :func:`For`\n\n\n.. function:: bodied Function(func(args))\n              bodied Function(body, funcname, {args})\n\n   declare or define a function\n\n   This command can be used to define a new function with named\n   arguments.\n\n   The number of arguments of the new function and their names are\n   determined by the list ``args``. If the ellipsis ``...`` follows\n   the last atom in ``args``, a function with a variable number of\n   arguments is declared (using :func:`RuleBaseListed`). Note that the\n   ellipsis cannot be the only element of ``args`` and *must* be\n   preceded by an atom.\n\n   A function with variable number of arguments can take more\n   arguments than elements in ``args``; in this case, it obtains its\n   last argument as a list containing all extra arguments.\n\n   The short form of the :func:`Function` call merely declares a\n   :func:`RuleBase` for the new function but does not define any\n   function body. This is a convenient shorthand for :func:`RuleBase`\n   and :func:`RuleBaseListed`, when definitions of the function are to\n   be supplied by rules. If the new function has been already declared\n   with the same number of arguments (with or without variable arguments),\n   :func:`Function` returns false and does nothing.\n\n   The second, longer form of the :func:`Function` call declares a function\n   and also defines a function body. It is equivalent to a single rule\n   such as ``funcname(_arg1, _arg2) <-- body``. The rule will be declared at\n   precedence 1025. Any previous rules associated with ``funcname`` (with\n   the same arity) will be discarded. More complicated functions (with\n   more than one body) can be defined by adding more rules.\n\n   :Example:\n\n   This will declare a new function with two or more arguments, but\n   define no rules for it. This is equivalent to ``RuleBase (\"f1\", {x,\n   y, ...})``::\n\n      In> Function() f1(x,y,...);\n      Out> True;\n      In> Function() f1(x,y);\n      Out> False;\n\n   This defines a function ``FirstOf`` which returns the first element\n   of a list. Equivalent definitions would be ``FirstOf(_list) <--\n   list[1]`` or ``FirstOf(list) := list[1]``::\n\n      In> Function(\"FirstOf\", {list})  list[1];\n      Out> True;\n      In> FirstOf({a,b,c});\n      Out> a;\n\n   The following function will print all arguments to a string::\n\n      In> Function(\"PrintAll\",{x, ...}) If(IsList(x), PrintList(x), ToString()Write(x));\n      Out> True;\n      In> PrintAll(1):\n      Out> \" 1\";\n      In> PrintAll(1,2,3);\n      Out> \" 1 2 3\";\n\n   .. seealso:: :func:`TemplateFunction`, :func:`Rule`,\n                :func:`RuleBase`, :func:`RuleBaseListed`, :func:`:=`,\n                :func:`Retract`\n\n\n.. function:: bodied Macro(func(args))\n              bodied Macro(body, funcname, {args})\n\n   declare or define a macro\n\n   This does the same as :func:`Function`, but for macros. One can\n   define a macro easily with this function, instead of having to use\n   :func:`DefMacroRuleBase`.\n\n   :Example:\n\n   The following example defines a looping function ::\n\n      In> Macro(\"myfor\",{init,pred,inc,body}) [@init;While(@pred)[@body;@inc;];True;];\n      Out> True;\n      In> a:=10\n      Out> 10;\n\n   Here this new macro ``myfor`` is used to loop, using a variable ``a``\n   from the calling environment ::\n\n      In> myfor(i:=1,i<10,i++,Echo(a*i))\n      10\n      20\n      30\n      40\n      50\n      60\n      70\n      80\n      90\n      Out> True;\n      In> i\n      Out> 10;\n\n\n   .. seealso:: :func:`Function`, :func:`DefMacroRuleBase`\n\n\n\n.. function:: Apply(fn, arglist)\n\n   apply a function to arguments\n\n   This function applies the function ``fn`` to the arguments in ``arglist`` and\n   returns the result. The first parameter ``fn`` can either be a string\n   containing the name of a function  or a pure function. Pure functions,\n   modeled after lambda-expressions, have the form ``{varlist,body}``, where\n   ``varlist`` is the list of formal parameters. Upon application, the formal\n   parameters are assigned the values in ``arglist`` (the second parameter of\n   :func:`Apply`) and the ``body`` is evaluated.\n\n   Another way to define a pure function is with the Lambda construct. Here,\n   instead of passing in ``{varlist,body}``, one can pass in\n   ``Lambda(varlist,body)``. Lambda has the advantage that its arguments are not\n   evaluated (using lists can have undesirable effects because lists are\n   evaluated). Lambda can be used everywhere a pure function is expected, in\n   principle, because the function :func:`Apply` is the only function dealing\n   with pure functions. So all places where a pure function can be passed in\n   will also accept Lambda.\n\n   An shorthand for :func:`Apply` is provided by the :func:`@` operator.\n\n   :Example:\n\n   ::\n\n      In> Apply(\"+\", {5,9});\n      Out> 14;\n      In> Apply({{x,y}, x-y^2}, {Cos(a), Sin(a)});\n      Out> Cos(a)-Sin(a)^2;\n      In>  Apply(Lambda({x,y}, x-y^2), {Cos(a), Sin(a)});\n      Out> Cos(a)-Sin(a)^2\n      In>  Lambda({x,y}, x-y^2) @ {Cos(a), Sin(a)}\n      Out> Cos(a)-Sin(a)^2\n\n\n   .. seealso:: :func:`Map`, :func:`MapSingle`, :func:`@`\n\n\n.. function:: MapArgs(expr, fn)\n\n   apply a function to all top-level arguments\n\n   Every top-level argument in ``expr`` is substituted by the result\n   of applying ``fn`` to this argument. Here ``fn`` can be either the\n   name of a function or a pure function (see :func:`Apply` for more\n   information on pure functions).\n\n   :Example:\n\n   ::\n\n      In> MapArgs(f(x,y,z),\"Sin\");\n      Out> f(Sin(x),Sin(y),Sin(z));\n      In> MapArgs({3,4,5,6}, {{x},x^2});\n      Out> {9,16,25,36};\n\n\n   .. seealso:: :func:`MapSingle`, :func:`Map`, :func:`Apply`\n\n.. function:: bodied Subst(expr, from, to)\n\n   perform a substitution\n\n   This function substitutes every occurrence of ``from`` in ``expr``\n   by ``to``. This is a syntactical substitution: only places where\n   ``from`` occurs as a subexpression are affected.\n\n   :Example:\n\n   ::\n\n      In> Subst(x, Sin(y)) x^2+x+1;\n      Out> Sin(y)^2+Sin(y)+1;\n      In> Subst(a+b, x) a+b+c;\n      Out> x+c;\n      In> Subst(b+c, x) a+b+c;\n      Out> a+b+c;\n\n   The explanation for the last result is that the expression\n   ``a+b+c`` is internally stored as ``(a+b)+c``. Hence ``a+b`` is a\n   subexpression, but ``b+c`` is not.\n\n   .. seealso:: :func:`WithValue`, :func:`/:`\n\n.. function:: WithValue(var, val, expr)\n              WithValue(varlist, vallist, expr)\n\n   temporary assignment during an evaluation\n\n   First, the expression ``val`` is assigned to the variable ``var``. Then, the\n   expression ``expr`` is evaluated and returned. Finally, the assignment is\n   reversed so that the variable ``var`` has the same value as it had before\n   :func:`WithValue` was evaluated.\n\n   The second calling sequence assigns the first element in the list of values\n   to the first element in the list of variables, the second value to the second\n   variable, etc.\n\n   :Example:\n\n   ::\n\n      In> WithValue(x, 3, x^2+y^2+1);\n      Out> y^2+10;\n      In> WithValue({x,y}, {3,2}, x^2+y^2+1);\n      Out> 14;\n\n   .. seealso:: :func:`Subst`, :func:`/:`\n\n.. function:: infix /:(expression,patterns)\n\n   local simplification rules\n\n   Sometimes you have an expression, and you want to use specific simplification\n   rules on it that are not done by default. This can be done with the ``/:``\n   and the ``/::`` operators. Suppose we have the expression containing things\n   such as ``Ln(a*b)``, and we want to change these into ``Ln(a)+Ln(b)``, the\n   easiest way to do this is using the ``/:`` operator, as follows::\n\n     In> Sin(x)*Ln(a*b)\n     Out> Sin(x)*Ln(a*b);\n     In> % /: { Ln(_x*_y) <- Ln(x)+Ln(y) }\n     Out> Sin(x)*(Ln(a)+Ln(b));\n\n   A whole list of simplification rules can be built up in the list,\n   and they will be applied to the expression on the left hand side of\n   ``/:``.\n\n   The forms the patterns can have are one of::\n\n           pattern <- replacement\n           {pattern,replacement}\n           {pattern,postpredicate,replacement}\n\n   Note that for these local rules, ``<-`` should be used instead of\n   ``<--`` which would be used in a global rule.\n\n   The ``/:`` operator traverses an expression much as :func:`Subst` does, that\n   is, top down, trying to apply the rules from the beginning of the list of\n   rules to the end of the list of rules. If the rules cannot be applied to an\n   expression, it will try subexpressions of that expression and so on.\n\n   It might be necessary sometimes to use the ``/::`` operator, which repeatedly\n   applies the ``/:`` operator until the result doesn't change any more. Caution\n   is required, since rules can contradict each other, which could result in an\n   infinite loop. To detect this situation, just use ``/:`` repeatedly on the\n   expression. The repetitive nature should become apparent.\n\n   :Example:\n\n   ::\n\n      In> Sin(u)*Ln(a*b) /: {Ln(_x*_y) <- Ln(x)+Ln(y)}\n      Out> Sin(u)*(Ln(a)+Ln(b));\n      In> Sin(u)*Ln(a*b) /:: { a <- 2, b <- 3 }\n      Out> Sin(u)*Ln(6);\n\n\n   .. seealso:: :func:`Subst`\n\n\n\n"
  },
  {
    "path": "docs/reference_manual/debugging.rst",
    "content": "=========\nDebugging\n=========\n\n.. function:: TraceStack(expression)\n\n   show calling stack after an error occurs\n\n   :func:`TraceStack` shows the calling stack after an error occurred. It shows\n   the last few items on the stack, not to flood the screen. These are usually\n   the only items of interest on the stack. This is probably by far the most\n   useful debugging function in yacas. It shows the last few things it did just\n   after an error was generated somewhere.\n\n   For each stack frame, it shows if the function evaluated was a built-in\n   function or a user-defined function, and for the user-defined function, the\n   number of the rule it is trying whether it was evaluating the pattern matcher\n   of the rule, or the body code of the rule.\n\n   This functionality is not offered by default because it slows down the\n   evaluation code.\n\n   Here is an example of a function calling itself recursively, causing yacas to\n   flood its stack::\n\n      In> f(x):=f(Sin(x))\n      Out> True;\n      In> TraceStack(f(2))\n      Debug> 982 :  f (Rule # 0 in body)\n      Debug> 983 :  f (Rule # 0 in body)\n      Debug> 984 :  f (Rule # 0 in body)\n      Debug> 985 :  f (Rule # 0 in body)\n      Debug> 986 :  f (Rule # 0 in body)\n      Debug> 987 :  f (Rule # 0 in body)\n      Debug> 988 :  f (Rule # 0 in body)\n      Debug> 989 :  f (Rule # 0 in body)\n      Debug> 990 :  f (Rule # 0 in body)\n      Debug> 991 :  f (Rule # 0 in body)\n      Debug> 992 :  f (Rule # 0 in body)\n      Debug> 993 :  f (Rule # 0 in body)\n      Debug> 994 :  f (Rule # 0 in body)\n      Debug> 995 :  f (User function)\n      Debug> 996 :  Sin (Rule # 0 in pattern)\n      Debug> 997 :  IsList (Internal function)\n      Error on line 1 in file [CommandLine]\n      Max evaluation stack depth reached.\n      Please use MaxEvalDepth to increase the stack\n      size as needed.\n\n\n   .. seealso:: :func:`TraceExp`, :func:`TraceRule`\n\n\n.. function:: TraceExp(expr)\n\n   evaluate with tracing enabled\n\n   The expression \"expr\" is evaluated with the tracing facility turned\n   on. This means that every subexpression, which is evaluated, is\n   shown before and after evaluation. Before evaluation, it is shown\n   in the form {TrEnter(x)}, where {x} denotes the subexpression being\n   evaluated. After the evaluation the line {TrLeave(x,y)} is printed,\n   where {y} is the result of the evaluation. The indentation shows\n   the nesting level.\n\n   Note that this command usually generates huge amounts of output. A\n   more specific form of tracing (eg. {TraceRule}) is probably more\n   useful  for all but very simple expressions.\n\n   :Example:\n\n   ::\n\n      In> TraceExp(2+3);\n      TrEnter(2+3);\n      TrEnter(2);\n      TrLeave(2, 2);\n      TrEnter(3);\n      TrLeave(3, 3);\n      TrEnter(IsNumber(x));\n      TrEnter(x);\n      TrLeave(x, 2);\n      TrLeave(IsNumber(x),True);\n      TrEnter(IsNumber(y));\n      TrEnter(y);\n      TrLeave(y, 3);\n      TrLeave(IsNumber(y),True);\n      TrEnter(True);\n      TrLeave(True, True);\n      TrEnter(MathAdd(x,y));\n      TrEnter(x);\n      TrLeave(x, 2);\n      TrEnter(y);\n      TrLeave(y, 3);\n      TrLeave(MathAdd(x,y),5);\n      TrLeave(2+3, 5);\n      Out> 5;\n\n\n   .. seealso:: :func:`TraceStack`, :func:`TraceRule`\n\n\n.. function:: bodied TraceRule(expr, template)\n\n   turn on tracing for a particular function\n\n   :param template: template showing the operator to trace\n   :param expr: expression to evaluate with tracing on\n\n   The tracing facility is turned on for subexpressions of the form\n   \"template\", and the expression \"expr\" is evaluated. The template\n   \"template\" is an example of the function to trace on. Specifically,\n   all subexpressions with the same top-level operator and arity as\n   \"template\" are shown. The subexpressions are displayed before\n   (indicated with {TrEnter}) and after ({TrLeave}) evaluation. In\n   between, the arguments are shown before and after evaluation\n   ({TrArg}). Only functions defined in scripts can be traced.\n\n   This is useful for tracing a function that is called from within\n   another function. This way you can see how your function behaves in\n   the environment it is used in.\n\n   :Example:\n\n   ::\n\n      In> TraceRule(x+y) 2+3*5+4;\n      TrEnter(2+3*5+4);\n      TrEnter(2+3*5);\n      TrArg(2, 2);\n      TrArg(3*5, 15);\n      TrLeave(2+3*5, 17);\n      TrArg(2+3*5, 17);\n      TrArg(4, 4);\n      TrLeave(2+3*5+4, 21);\n      Out> 21;\n\n\n   .. seealso:: :func:`TraceStack`, :func:`TraceExp`\n\n"
  },
  {
    "path": "docs/reference_manual/elementary.rst",
    "content": "====================\nElementary functions\n====================\n\n.. function:: Sin(x)\n\n   trigonometric sine function\n\n   :Example:\n\n   ::\n\n      In> Sin(1)\n      Out> Sin(1);\n      In> N(Sin(1),20)\n      Out> 0.84147098480789650665;\n      In> Sin(Pi/4)\n      Out> Sqrt(2)/2;\n\n\n   .. seealso:: :func:`Cos`, :func:`Tan`, :func:`ArcSin`, :func:`ArcCos`, :func:`ArcTan`, :const:`Pi`\n\n.. function:: Cos(x)\n\n   trigonometric cosine function\n\n   :Example:\n\n   ::\n\n      In> Cos(1)\n      Out> Cos(1);\n      In> N(Cos(1),20)\n      Out> 0.5403023058681397174;\n      In> Cos(Pi/4)\n      Out> Sqrt(1/2);\n\n\n   .. seealso:: :func:`Sin`, :func:`Tan`, :func:`ArcSin`, :func:`ArcCos`, :func:`ArcTan`, :const:`Pi`\n\n.. function:: Tan(x)\n\n   trigonometric tangent function\n\n   :Example:\n\n   ::\n\n      In> Tan(1)\n      Out> Tan(1);\n      In> N(Tan(1),20)\n      Out> 1.5574077246549022305;\n      In> Tan(Pi/4)\n      Out> 1;\n\n\n   .. seealso:: :func:`Sin`, :func:`Cos`, :func:`ArcSin`, :func:`ArcCos`, :func:`ArcTan`, :const:`Pi`\n\n.. function:: ArcSin(x)\n\n   inverse trigonometric function arc-sine\n\n   :Example:\n\n   ::\n\n      In> ArcSin(1)\n      Out> Pi/2;\n      In> ArcSin(1/3)\n      Out> ArcSin(1/3);\n      In> Sin(ArcSin(1/3))\n      Out> 1/3;\n      In> x:=N(ArcSin(0.75))\n      Out> 0.848062;\n      In> N(Sin(x))\n      Out> 0.7499999477;\n\n\n   .. seealso:: :func:`Sin`, :func:`Cos`, :func:`Tan`, :const:`Pi`, :func:`Ln`, :func:`ArcCos`, :func:`ArcTan`\n\n.. function:: ArcCos(x)\n\n   inverse trigonometric function arc-cosine\n\n   :Example:\n\n   ::\n\n      In> ArcCos(0)\n      Out> Pi/2\n      In> ArcCos(1/3)\n      Out> ArcCos(1/3)\n      In> Cos(ArcCos(1/3))\n      Out> 1/3\n      In> x:=N(ArcCos(0.75))\n      Out> 0.7227342478\n      In> N(Cos(x))\n      Out> 0.75\n\n\n   .. seealso:: :func:`Sin`, :func:`Cos`, :func:`Tan`, :const:`Pi`, :func:`Ln`, :func:`ArcSin`, :func:`ArcTan`\n\n.. function:: ArcTan(x)\n\n   inverse trigonometric function arc-tangent\n\n   :Example:\n\n   ::\n\n      In> ArcTan(1)\n      Out> Pi/4\n      In> ArcTan(1/3)\n      Out> ArcTan(1/3)\n      In> Tan(ArcTan(1/3))\n      Out> 1/3\n      In> x:=N(ArcTan(0.75))\n      Out> 0.643501108793285592213351264945231378078460693359375\n      In> N(Tan(x))\n      Out> 0.75\n\n\n   .. seealso:: :func:`Sin`, :func:`Cos`, :func:`Tan`, :const:`Pi`, :func:`Ln`, :func:`ArcSin`, :func:`ArcCos`\n\n.. function:: Exp(x)\n\n   exponential function\n\n   :Example:\n\n   ::\n\n      In> Exp(0)\n      Out> 1;\n      In> Exp(I*Pi)\n      Out> -1;\n      In> N(Exp(1))\n      Out> 2.7182818284;\n\n\n   .. seealso:: :func:`Ln`, :func:`Sin`, :func:`Cos`, :func:`Tan`\n\n.. function:: Ln(x)\n\n   natural logarithm\n\n   :Example:\n\n   ::\n\n      In> Ln(1)\n      Out> 0;\n      In> Ln(Exp(x))\n      Out> x;\n      In> D(x) Ln(x)\n      Out> 1/x;\n\n\n   .. seealso:: :func:`Exp`, :func:`Arg`\n\n.. function:: Sqrt(x)\n\n   square root\n\n   :Example:\n\n   ::\n\n      In> Sqrt(16)\n      Out> 4;\n      In> Sqrt(15)\n      Out> Sqrt(15);\n      In> N(Sqrt(15))\n      Out> 3.8729833462;\n      In> Sqrt(4/9)\n      Out> 2/3;\n      In> Sqrt(-1)\n      Out> Complex(0,1);\n\n\n   .. seealso:: :func:`Exp`, :func:`^`\n\n.. function:: Abs(x)\n\n   absolute value or modulus of complex number\n\n   :Example:\n\n   ::\n\n      In> Abs(2);\n      Out> 2;\n      In> Abs(-1/2);\n      Out> 1/2;\n      In> Abs(3+4*I);\n      Out> 5;\n\n\n   .. seealso:: :func:`Sign`, :func:`Arg`\n\n.. function:: Sign(x)\n\n   sign of a number\n\n   :Example:\n\n   ::\n\n      In> Sign(2)\n      Out> 1;\n      In> Sign(-3)\n      Out> -1;\n      In> Sign(0)\n      Out> 1;\n      In> Sign(-3) * Abs(-3)\n      Out> -3;\n\n\n   .. seealso:: :func:`Arg`, :func:`Abs`\n"
  },
  {
    "path": "docs/reference_manual/functional.rst",
    "content": "====================\nFunctional operators\n====================\n\nThese operators can help the user to program in the style of\nfunctional programming languages such as Miranda or Haskell.\n\n.. function:: infix :(item, list)\n              infix :(list, item)\n              infix :(list, list)\n              infix :(string, string)\n\n   prepend or append item to list, or concatenate lists or strings\n\n   :Example:\n\n   ::\n\n      In> a:b:c:{}\n      Out> {a,b,c};\n      In> \"This\":\"Is\":\"A\":\"String\"\n      Out> \"ThisIsAString\";\n\n\n   .. seealso:: :func:`Concat`, :func:`ConcatStrings`\n\n.. function:: infix @(fn, arglist)\n\n   apply a function\n\n   This function is a shorthand for :func:`Apply`. It applies the  function\n   ``fn`` to the argument(s) in ``arglist`` and returns the  result. ``fn`` can\n   either be a string containing  the name of a function or a pure function.\n\n   :Example:\n\n   ::\n\n      In> \"Sin\" @ a\n      Out> Sin(a);\n      In> {{a},Sin(a)} @ a\n      Out> Sin(a);\n      In> \"f\" @ {a,b}\n      Out> f(a,b);\n\n\n   .. seealso:: :func:`Apply`\n\n.. function:: infix /@(fn, list)\n\n   apply a function to all entries in a list\n\n   This function is a shorthand for :func:`MapSingle`. It successively applies\n   the function ``fn`` to all the entries in ``list`` and returns a list\n   containing the results. The parameter ``fn`` can either be a string\n   containing the name of a function or a pure  function.\n\n   :Example:\n\n   ::\n\n      In> \"Sin\" /@ {a,b}\n      Out> {Sin(a),Sin(b)};\n      In> {{a},Sin(a)*a} /@ {a,b}\n      Out> {Sin(a)*a,Sin(b)*b};\n\n\n   .. seealso:: :func:`MapSingle`, :func:`Map`, :func:`MapArgs`\n\n.. function:: infix .. (n, m)\n\n   construct a list of consecutive integers\n\n   This command returns the list ``{n, n+1, n+2, ..., m}``. If ``m`` is smaller\n   than ``n``, the empty list is returned.\n\n   .. note:: The ``..`` operator should be surrounded by spaces to keep the\n             parser happy. So one should write ``1 .. 4`` instead of ``1..4``.\n\n.. function:: NFunction(newname, funcname, arglist)\n\n   make wrapper for numeric functions\n\n   This function will define a function named :func:`newname`  with the same\n   arguments as an existing function named :func:`funcname`. The new function\n   will evaluate and return the expression ``funcname(arglist)`` only when  all\n   items in the argument list ``arglist`` are numbers, and return unevaluated\n   otherwise. This can be useful e.g. when plotting functions defined through\n   other yacas routines that cannot return unevaluated. If the numerical\n   calculation does not return a number (for example,  it might return the atom\n   :const:`Infinity` for some arguments),  then the new function will return\n   :const:`Undefined`.\n\n   :Example:\n\n   ::\n\n      In> f(x) := N(Sin(x));\n      Out> True;\n      In> NFunction(\"f1\", \"f\", {x});\n      Out> True;\n      In> f1(a);\n      Out> f1(a);\n      In> f1(0);\n      Out> 0;\n\n   Suppose we need to define a complicated function :func:`t` which cannot be\n   evaluated unless the argument is a number::\n\n      In> t(x) := If(x<=0.5, 2*x, 2*(1-x));\n      Out> True;\n      In> t(0.2);\n      Out> 0.4;\n      In> t(x);\n      In function \"If\" :\n      bad argument number 1 (counting from 1)\n      CommandLine(1) : Invalid argument\n\n   Then, we can use :func:`NFunction` to define a wrapper :func:`t1` around\n   :func:`t` which will not try to evaluate :func:`t` unless the argument is a\n   number::\n\n      In> NFunction(\"t1\", \"t\", {x})\n      Out> True;\n      In> t1(x);\n      Out> t1(x);\n      In> t1(0.2);\n      Out> 0.4;\n\n   Now we can plot the function.\n\n      In> Plot2D(t1(x), -0.1: 1.1)\n      Out> True;\n\n   .. seealso:: :func:`MacroRule`\n\n"
  },
  {
    "path": "docs/reference_manual/graphs.rst",
    "content": "======\nGraphs\n======\n\n.. function:: Graph(edges)\n              Graph(vertices, edges)\n\n  construct a graph\n\n  .. seealso:: :func:`->`, :func:`<->`\n\n\n.. function:: infix -> (vertex1, vertex2)\n              infix <-> (vertex1, vertex2)\n\n  construct an edge\n\n.. function:: Vertices(g)\n\n  return list of graph vertices\n\n  .. seealso:: :func:`Edges`, :func:`Graph`\n\n.. function:: Edges(g)\n\n  return list of graph edges\n\n  .. seealso:: :func:`Vertices`, :func:`Graph`\n\n.. function:: AdjacencyList(g)\n\n  adjacency list\n\n  :param g: graph\n\n  Return `adjacency list <https://en.wikipedia.org/wiki/Adjacency_list>`_ \n  of graph ``g``.\n\n  .. seealso:: :func:`AdjacencyMatrix`, :func:`Graph`\n\n.. function:: AdjacencyMatrix(g)\n\n  adjacency matrix\n\n  :param g: graph\n\n  Return `adjacency matrix <https://en.wikipedia.org/wiki/Adjacency_matrix>`_ \n  of graph ``g``.\n\n  .. seealso:: :func:`AdjacencyList`, :func:`Graph`\n\n.. function:: BFS(g, f)\n              BFS(g, v, f)\n\n  traverse graph in breadth-first order\n\n  .. param g: graph\n  .. param v: starting vertex\n  .. param f: functor\n\n  Traverse graph ``g`` in `breadth-first \n  <https://en.wikipedia.org/wiki/Breadth-first_search>`_ order, starting from\n  ``v`` if provided, or from the first vertex. ``f`` is called for every\n  visited vertex.\n\n  .. seealso:: :func:`DFS`, :func:`Graph`\n\n.. function:: DFS(g, f)\n              DFS(g, v, f)\n\n  traverse graph in depth-first order\n\n  .. param g: graph\n  .. param v: starting vertex\n  .. param f: functor\n\n  Traverse graph ``g`` in `depth-first \n  <https://en.wikipedia.org/wiki/Depth-first_search>`_ order, starting from\n  ``v`` if provided, or from the first vertex. ``f`` is called for every\n  visited vertex.\n\n  .. seealso:: :func:`BFS`, :func:`Graph`\n"
  },
  {
    "path": "docs/reference_manual/index.rst",
    "content": "****************\nReference Manual\n****************\n\nYacas (Yet Another Computer Algebra System) is a small and highly\nflexible general-purpose computer algebra system and programming\nlanguage. The language has a familiar, C-like infix-operator\nsyntax. The distribution contains a small library of mathematical\nfunctions, but its real strength is in the language in which you can\neasily write your own symbolic manipulation algorithms. The core\nengine supports arbitrary precision arithmetic, and is able to execute\nsymbolic manipulations on various mathematical objects by following\nuser-defined rules.\n\nThis document describes the functions that are useful in the context\nof using yacas as an end user. It is recommended to first read the\nonline interactive tutorial to get acquainted with the basic language\nconstructs first. This document expands on the tutorial by explaining\nthe usage of the functions that are useful when doing calculations.\n\n.. toctree::\n   :maxdepth: 1\n\n   arithmetic\n   elementary\n   calc\n   simplify\n   solvers\n   ode\n   logic\n   linear-algebra\n   univariate-polynomials\n   lists\n   graphs\n   functional\n   controlflow\n   predicates\n   consts\n   vars\n   io\n   plot\n   strings\n   random\n   probability-and-statistics\n   special\n   number-theory\n   numerical-methods\n   physics\n   programming\n   debugging\n   misc\n"
  },
  {
    "path": "docs/reference_manual/io.rst",
    "content": "============\nInput/output\n============\n\nThis chapter contains commands to use for input and output. All output commands\nwrite to the same destination stream, called the \"current output\". This is\ninitially the screen, but may be redirected by some commands. Similarly, most\ninput commands read from the \"current input\" stream, which can also be\nredirected. The exception to this rule are the commands for reading script\nfiles, which simply read a specified file.\n\n.. function:: FullForm(expr)\n\n   print an expression in LISP-format\n\n   :param expr: expression to be printed in LISP-format\n\n   Evaluates \"expr\", and prints it in LISP-format on the current\n   output. It is followed by a newline. The evaluated expression is\n   also  returned.    This can be useful if you want to study the\n   internal representation of  a certain expression.\n\n   :Example:\n\n   ::\n\n      In> FullForm(a+b+c);\n      (+ (+ a b )c )\n      Out> a+b+c;\n      In> FullForm(2*I*b^2);\n      (* (Complex 0 2 )(^ b 2 ))\n      Out> Complex(0,2)*b^2;\n\n   The first example shows how the expression :math:`a+b+c` is\n   internally represented. In the second example, :math:`2i` is\n   first evaluated to ``Complex(0,2)`` before the expression\n   is printed.\n\n\n   .. seealso:: :func:`LispRead`, :func:`Listify`, :func:`Unlist`\n\n.. function:: Echo(item)\n              Echo(items)\n\n   high-level printing routine\n\n   :param item: the item to be printed\n   :param items: a list of items to be printed\n\n   If passed a single item, {Echo} will evaluate it and print it to\n   the  current output, followed by a newline. If {item} is a string,\n   it is  printed without quotation marks.    If there is one\n   argument, and it is a list, {Echo} will print all the  entries in\n   the list subsequently to the current output, followed by a\n   newline. Any strings in the list are printed without quotation\n   marks. All other entries are followed by a space.    {Echo} can be\n   called with a variable number of arguments, they will all  be\n   printed, followed by a newline.    {Echo} always returns :data:`True`.\n\n   :Example:\n\n   ::\n\n      In> Echo(5+3);\n      8\n      Out> True;\n      In> Echo({\"The square of two is \", 2*2});\n      The square of two is 4\n      Out> True;\n      In> Echo(\"The square of two is \", 2*2);\n      The square of two is 4\n      Out> True;\n      Note that one must use the second calling format if one wishes to\n      print a list:\n      In> Echo({a,b,c});\n      a b c\n      Out> True;\n      In> Echo({{a,b,c}});\n      {a,b,c}\n      Out> True;\n\n\n   .. seealso:: :func:`PrettyForm`, :func:`Write`, :func:`WriteString`, :func:`RuleBaseListed`\n\n.. function:: PrettyForm(expr)\n\n   print an expression nicely with ASCII art\n\n   :param expr: an expression\n\n   :func:`PrettyForm` renders an expression in a nicer way, using ascii art.\n   This is generally useful when the result of a calculation is more complex\n   than a simple number.\n\n   :Example:\n\n   ::\n\n      In> Taylor(x,0,9)Sin(x)\n      Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880;\n      In> PrettyForm(%)\n           3    5      7       9\n          x    x      x       x\n      x - -- + --- - ---- + ------\n          6    120   5040   362880\n      Out> True;\n\n\n   .. seealso:: :func:`EvalFormula`, :func:`PrettyPrinter'Set`\n\n.. function:: EvalFormula(expr)\n\n   print an evaluation nicely with ASCII art\n\n   :param expr: an expression\n\n   Show an evaluation in a nice way, using :func:`PrettyPrinter'Set`  to show\n   'input = output'.\n\n   :Example:\n\n   ::\n\n      In> EvalFormula(Taylor(x,0,7)Sin(x))\n                                            3    5\n                                           x    x\n      Taylor( x , 0 , 5 , Sin( x ) ) = x - -- + ---\n                                           6    120\n\n\n   .. seealso:: :func:`PrettyForm`\n\n.. function:: TeXForm(expr)\n\n   export expressions to LaTeX\n\n   :param expr: an expression to be exported\n\n   :func:`TeXForm` returns a string containing LaTeX representation of the yacas\n   expression ``expr``. Currently the exporter handles most expression types but\n   not all.\n\n.. function:: CForm(expr)\n\n   export expression to C code\n\n   :param expr: expression to be exported\n\n   :func:`CForm` returns a string containing C code that attempts to\n   implement the yacas expression ``expr``. Currently the exporter\n   handles most expression types but not all.\n\n.. function:: IsCFormable(expr)\n              IsCFormable(expr, funclist)\n\n   check possibility to export expression to C code\n\n   :param expr: expression to be exported (this argument is not evaluated)\n   :param funclist: list of \"allowed\" function atoms\n\n   :func:`IsCFormable` returns :data:`True` if the yacas expression ``expr`` can\n   be exported  into C code. This is a check whether the C exporter :func:`CForm`\n   can be safely  used on the expression.    A yacas expression is considered\n   exportable if it contains only functions that can be translated into C\n   (e.g. :func:`UnList` cannot be exported). All variables and constants are\n   considered exportable. The verbose option prints names of functions that\n   are not exportable. The second calling format of :func:`IsCFormable` can be used to\n   allow certain function names that will be available in the C code.\n\n   :Example:\n\n   ::\n\n      In> IsCFormable(Sin(a1)+2*Cos(b1))\n      Out> True;\n      In> V(IsCFormable(1+func123(b1)))\n      IsCFormable: Info: unexportable function(s):\n      func123\n      Out> False;\n\n   This returned :data:`False` because the function :func:`func123` is not\n   available in C. We can explicitly allow this function and then the expression\n   will be considered exportable::\n\n      In> IsCFormable(1+func123(b1), {func123})\n      Out> True;\n\n\n   .. seealso:: :func:`CForm`, :func:`V`\n\n.. function:: Write(expr, ...)\n\n   low-level printing routine\n\n   :param expr: expression to be printed\n\n   The expression ``expr`` is evaluated and written to the current output. Note\n   that :func:`Write` accepts an arbitrary number of arguments, all of which are\n   written to the current output (see second example). :func:`Write` always\n   returns :data:`True`.\n\n   :Example:\n\n   ::\n\n      In> Write(1);\n      1Out> True;\n      In> Write(1,2);\n      1 2Out> True;\n\n   Write does not write a newline, so the ``Out>`` prompt immediately follows\n   the output of :func:`Write`.\n\n\n   .. seealso:: :func:`Echo`, :func:`WriteString`\n\n.. function:: WriteString(string)\n\n   low-level printing routine for strings\n\n   :param string: the string to be printed\n\n   The expression ``string`` is evaluated and written to the current\n   output without quotation marks. The argument should be a  string.\n   :func:`WriteString` always returns :data:`True`.\n\n   :Example:\n\n   ::\n\n      In> Write(\"Hello, world!\");\n      \"Hello, world!\"Out> True;\n      In> WriteString(\"Hello, world!\");\n      Hello, world!Out> True;\n\n   This example clearly shows the difference between :func:`Write` and\n   :func:`WriteString`. Note that :func:`Write` and :func:`WriteString` do not\n   write a newline, so the ``Out>`` prompt immediately follows the output.\n\n\n   .. seealso:: :func:`Echo`, :func:`Write`\n\n.. function:: Space()\n              Space(n)\n\n   print one or more spaces\n\n   :param n: the number of spaces to print\n\n   :func:`Space` prints one space on the  current output. The second form prints\n   ``n`` spaces on the current  output. The result is always :data:`True`.\n\n   :Example:\n\n   ::\n\n      In> Space(5);\n           Out> True;\n\n\n   .. seealso:: :func:`Echo`, :func:`Write`, :func:`NewLine`\n\n.. function:: NewLine()\n              NewLine(n)\n\n   print one or more newline characters\n\n   :param n: the number of newline characters to print\n\n   :func:`NewLine` prints a newline character on the current output. The second\n   form prints ``n`` newlines on the current output. The result is always\n   :data:`True`.\n\n   :Example:\n\n   ::\n\n      In> NewLine();\n\n      Out> True;\n\n\n   .. seealso:: :func:`Echo`, :func:`Write`, :func:`Space`\n\n.. function:: bodied FromFile(body, name)\n\n   connect current input to a file\n\n   :param name: name of the file to read\n   :param body: expression to be evaluated\n\n   The current input is connected to the file ``name``. Then the expression\n   ``body`` is evaluated. If some functions in ``body`` try to read  from\n   current input, they will read from the file ``name``. Finally, the  file is\n   closed and the result of evaluating ``body`` is returned.\n\n   :Example:\n\n   Suppose that the file ``foo`` contains ``2 + 5;``::\n\n      In> FromFile(\"foo\") res := Read();\n      Out> 2+5;\n      In> FromFile(\"foo\") res := ReadToken();\n      Out> 2;\n\n\n   .. seealso:: :func:`ToFile`, :func:`FromString`, :func:`Read`, :func:`ReadToken`\n\n.. function:: bodied FromString(body, str)\n\n   connect current input to a string\n\n   :param str: a string containing the text to parse\n   :param body: expression to be evaluated\n\n   The commands in ``body`` are executed, but every read is done from the string\n   ``str``. The result of evaluating ``body`` is returned.\n\n   :Example:\n\n   ::\n\n      In> FromString(\"2+5; this is never read\") res := Read();\n      Out> 2+5;\n      In> FromString(\"2+5; this is never read\") res := Eval(Read());\n      Out> 7;\n\n\n   .. seealso:: :func:`ToString`, :func:`FromFile`, :func:`Read`, :func:`ReadToken`\n\n.. function:: bodied ToFile(body, name)\n\n   connect current output to a file\n\n   :param name: name of the file to write the result to\n   :param body: expression to be evaluated\n\n   The current output is connected to the file ``name``. Then the expression\n   ``body`` is evaluated. Everything that the commands in ``body`` prints ends\n   up in the file ``name``. Finally, the  file is closed and the result of\n   evaluating ``body`` is returned. If the file is opened again, the old\n   contents will be overwritten.  This is a limitation of :func:`ToFile`: one\n   cannot append to a file that has already been created.\n\n   :Example:\n\n   Here is how one can create a file with C code to evaluate an expression::\n\n      In> ToFile(\"expr1.c\") WriteString(CForm(Sqrt(x-y)*Sin(x)));\n      Out> True;\n\n   The file ``expr1.c`` was created in the current working directory and it\n   contains the line ``sqrt(x-y)*sin(x)``.\n\n   As another example, take a look at the following command::\n\n      In> [ Echo(\"Result:\");  PrettyForm(Taylor(x,0,9) Sin(x)); ];\n      Result:\n           3    5      7       9\n          x    x      x       x\n      x - -- + --- - ---- + ------\n          6    120   5040   362880\n      Out> True;\n\n   Now suppose one wants to send the output of this command to a\n   file. This can be achieved as follows::\n\n      In> ToFile(\"out\") [ Echo(\"Result:\"); PrettyForm(Taylor(x,0,9) Sin(x)); ];\n      Out> True;\n\n   After this command the file ``out`` contains::\n\n      Result:\n           3    5      7       9\n          x    x      x       x\n      x - -- + --- - ---- + ------\n          6    120   5040   362880\n\n\n   .. seealso:: :func:`FromFile`, :func:`ToString`, :func:`Echo`, :func:`Write`, :func:`WriteString`, :func:`PrettyForm`, :func:`Taylor`\n\n.. function:: bodied ToString(body)\n\n   connect current output to a string\n\n   :param body: expression to be evaluated\n\n   The commands in ``body`` are executed. Everything that is printed, by\n   :func:`Echo` for instance, is collected in a string and this string is\n   returned.\n\n   :Example:\n\n   ::\n\n      In> str := ToString() [ WriteString(\"The square of 8 is \"); Write(8^2); ];\n      Out> \"The square of 8 is  64\";\n\n\n   .. seealso:: :func:`FromFile`, :func:`ToString`, :func:`Echo`, :func:`Write`, :func:`WriteString`\n\n.. function:: Read()\n\n   read an expression from current input\n\n\n   Read an expression from the current input, and return it\n   unevaluated. When  the end of an input file is encountered, the\n   token atom {EndOfFile} is returned.\n\n   :Example:\n\n   ::\n\n      In> FromString(\"2+5;\") Read();\n      Out> 2+5;\n      In> FromString(\"\") Read();\n      Out> EndOfFile;\n\n\n   .. seealso:: :func:`FromFile`, :func:`FromString`, :func:`LispRead`, :func:`ReadToken`, :func:`Write`\n\n.. function:: bodied ToStdout(body)\n\n   select initial output stream for output\n\n   :param body: expression to be evaluated\n\n   When using :func:`ToString` or :func:`ToFile`, it might happen that something\n   needs to be  written to the (initial) standard output (typically the screen).\n   :func:`ToStdout` can be used to select this stream.\n\n.. function:: ReadCmdLineString(prompt)\n\n   read an expression from command line and return in string\n\n   :param prompt: string representing the prompt shown on screen\n\n   This function allows for interactive input similar to the command\n   line.  When using this function, the history from the command line\n   is also available.    The result is returned in a string, so it\n   still needs to be parsed.    This function will typically be used\n   in situations where one wants a custom   read-eval-print loop.\n\n   :Example:\n\n   The following defines a function that when invoked keeps asking\n   for an expression (the *read* step), and then takes\n   the derivative of it (the *eval* step) and then\n   uses :func:`PrettyForm` to display the result (the *print* step)::\n\n      In> ReEvPr() := \\\n      In>   While(True) [ \\\n      In>     PrettyForm(Deriv(x) \\\n      In>      FromString(ReadCmdLineString(\"Deriv> \"):\";\")Read()); \\\n      In> ];\n      Out> True;\n\n   Then one can invoke the command, from which the following interaction\n   might follow::\n\n      In> ReEvPr()\n      Deriv> Sin(a^2*x/b)\n         /  2     \\\n         | a  * x |    2\n      Cos| ------ | * a  * b\n         \\   b    /\n      ----------------------\n                2\n               b\n      Deriv> Sin(x)\n      Cos( x )\n      Deriv>\n\n\n   .. seealso:: :func:`Read`, :func:`LispRead`, :func:`LispReadListed`\n\n.. function:: LispRead()\n\n   read expressions in LISP syntax\n\n   :func:`LispRead` reads an expression in the LISP syntax from the current\n   input, and returns  it unevaluated. When the end of an input file is\n   encountered, the  special token atom :data:`EndOfFile` is returned. The yacas\n   expression ``a+b`` is written in the LISP syntax as ``(+ a b)``. The\n   advantage of this syntax is that it is less ambiguous than the infix operator\n   grammar that yacas uses by default.\n\n   :Example:\n\n   ::\n\n      In> FromString(\"(+ a b)\") LispRead();\n      Out> a+b;\n      In> FromString(\"(List (Sin x) (- (Cos x)))\") \\\n      LispRead();\n      Out> {Sin(x),-Cos(x)};\n      In> FromString(\"(+ a b)\")LispRead()\n      Out> a+b;\n\n   .. seealso:: :func:`FromFile`, :func:`FromString`, :func:`Read`, :func:`ReadToken`, :func:`FullForm`, :func:`LispReadListed`\n\n.. function:: LispReadListed()\n\n   read expressions in LISP syntax\n\n   :func:`LispReadListed` reads a LISP expression and returns it in a list,\n   instead of the form usual to yacas (expressions). The result can be thought\n   of as applying :func:`Listify` to :func:`LispRead`.  The function\n   :func:`LispReadListed` is more useful for reading arbitrary LISP expressions,\n   because the first object in a list can be itself a list (this is never the\n   case for yacas expressions where the first object in a list is always a\n   function atom).\n\n   :Example:\n\n   ::\n\n      In> FromString(\"(+ a b)\")LispReadListed()\n      Out> {+,a,b};\n\n   .. seealso:: :func:`FromFile`, :func:`FromString`, :func:`Read`, :func:`ReadToken`, :func:`FullForm`, :func:`LispRead`\n\n.. function:: ReadToken()\n\n   read a token from current input\n\n\n   Read a token from the current input, and return it unevaluated.\n   The returned object is a Yacas atom (not a string).  When  the end\n   of an input file is encountered, the token atom {EndOfFile} is\n   returned.    A token is for computer languages what a word is for\n   human languages:  it is the smallest unit in which a command can be\n   divided, so that the  semantics (that is the meaning) of the\n   command is in some sense a  combination of the semantics of the\n   tokens. Hence {a := foo} consists of three tokens, namely {a},\n   {:=}, and {foo}.    The parsing of the string depends on the syntax\n   of the language.  The part of the kernel that does the parsing is\n   the \"tokenizer\".  Yacas can parse its own syntax (the default\n   tokenizer) or it can be instructed to parse XML or C++ syntax using\n   the directives {DefaultTokenizer} or {XmlTokenizer}.  Setting a\n   tokenizer is a global action that affects all {ReadToken} calls.\n\n   :Example:\n\n   ::\n\n      In> FromString(\"a := Sin(x)\") While((tok := ReadToken()) != EndOfFile) Echo(tok);\n      a\n      :=\n      Sin\n      (\n      x\n      )\n      Out> True;\n\n   We can read some junk too::\n\n      In> FromString(\"-$3\")ReadToken();\n      Out> -$;\n\n   The result is an atom with the string representation ``-$``. Yacas assumes\n   that ``-$`` is an operator symbol yet to be defined. The ``3`` will be in the\n   next token. (The results will be different if a non-default tokenizer is\n   selected.)\n\n   .. seealso:: :func:`FromFile`, :func:`FromString`, :func:`Read`, :func:`LispRead`, :func:`DefaultTokenizer`\n\n.. function:: Load(name)\n\n   evaluate all expressions in a file\n\n   :param name: name of the file to load\n\n   The file ``name`` is opened. All expressions in the file are read and\n   evaluated. :func:`Load` always returns :data:`True`.\n\n   .. seealso:: :func:`Use`, :func:`DefLoad`, :func:`DefaultDirectory`, :func:`FindFile`\n\n.. function:: Use(name)\n\n   load a file, but not twice\n\n   :param name: name of the file to load\n\n   If the file ``name`` has been loaded before, either by an earlier call to\n   :func:`Use` or via the :func:`DefLoad` mechanism, nothing happens. Otherwise\n   all expressions in the file are  read and evaluated. :func:`Use` always\n   returns :data:`True`. The purpose of this function is to make sure that the\n   file will at least have been loaded, but is not loaded twice.\n\n   .. seealso:: :func:`Load`, :func:`DefLoad`, :func:`DefaultDirectory`\n\n.. function:: DefLoad(name)\n\n   load a ``.def`` file\n\n   :param name: name of the file (without the ``.def`` suffix)\n\n   The suffix ``.def`` is appended to ``name`` and the  file with this name is\n   loaded. It should contain a list of functions,  terminated by a closing brace\n   ``\\}`` (the end-of-list delimiter). This  tells the system to load the file\n   ``name`` as soon as the user calls  one of the functions named in the file (if\n   not done so already). This allows for faster startup times, since not all of\n   the rules databases  need to be loaded, just the descriptions on which files\n   to load for  which functions.\n\n   .. seealso:: :func:`Load`, :func:`Use`, :func:`DefaultDirectory`\n\n.. function:: FindFile(name)\n\n   find a file in the current path\n\n   :param name: string, name of the file or directory to find\n\n   The result of this command is the full path to the file that would\n   be  opened when the command {Load(name)} would be  invoked. This\n   means that the input directories are subsequently  searched for a\n   file called \"name\". If such a file is not found, {FindFile} returns\n   an empty string.    {FindFile(\"\")} returns the name of the default\n   directory (the first one on the search path).\n\n   .. seealso:: :func:`Load`, :func:`DefaultDirectory`\n\n.. function:: PatchLoad(name)\n\n   execute commands between ``<?`` and ``?>`` in file\n\n   :param name: string, name of the file to \"patch\"\n\n   :func:`PatchLoad` loads in a file and outputs the contents to the current\n   output. The file can contain blocks delimited by ``<?`` and ``?>``. The piece\n   of text between such delimiters is treated as a separate file with yacas\n   instructions,  which is then loaded and executed. All output of write\n   statements  in that block will be written to the same current output. This is\n   similar to the way PHP works. You can have a static text file  with dynamic\n   content generated by yacas.\n\n   .. seealso:: :func:`PatchString`, :func:`Load`\n\n.. function:: Nl()\n\n   the newline character\n\n   This function returns a string with one element in it, namely a\n   newline character. This may be useful for building strings to send\n   to some output in the end.\n\n   :Example:\n\n   ::\n\n      In> WriteString(\"First line\" : Nl() : \"Second line\" : Nl());\n      First line\n      Second line\n      Out> True;\n\n\n   .. seealso:: :func:`NewLine`\n\n.. function:: V(expression)\n\n   set verbose output mode\n\n   :param expression: expression to be evaluated in verbose mode\n\n   :func:`V` will evaluate the expression in verbose mode. Various parts of\n   yacas can show extra information about the work done while doing a\n   calculation when using :func:`V`. In verbose mode, :func:`InVerboseMode` will\n   return :data:`True`, otherwise  it will return :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> OldSolve({x+2==0},{x})\n      Out> {{-2}};\n      In> V(OldSolve({x+2==0},{x}))\n      Entering OldSolve\n      From  x+2==0  it follows that  x  = -2\n      x+2==0  simplifies to  True\n      Leaving OldSolve\n      Out> {{-2}};\n      In> InVerboseMode()\n      Out> False\n      In> V(InVerboseMode())\n      Out> True\n\n\n   .. seealso:: :func:`Echo`, :func:`N`, :func:`OldSolve`, :func:`InVerboseMode`\n\n.. function:: InVerboseMode()\n\n   check for verbose output mode\n\n   In verbose mode, :func:`InVerboseMode` will return :data:`True`, otherwise it\n   will return :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> InVerboseMode()\n      Out> False\n      In> V(InVerboseMode())\n      Out> True\n\n\n   .. seealso:: :func:`Echo`, :func:`N`, :func:`OldSolve`, :func:`V`\n\n\n.. function:: XmlExplodeTag(xmltext)\n\n   convert XML strings to tag objects\n\n   :param xmltext: string containing some XML tokens\n\n   {XmlExplodeTag} parses the first XML token in {xmltext}  and\n   returns a Yacas expression.    The following subset of XML syntax\n   is supported currently:\n\n   *   {<TAG [options]>} -- an opening tag\n   *   {</TAG [options]>} -- a closing tag\n   *   {<TAG [options] />} -- an open/close tag\n   *   plain (non-tag) text\n\n   The tag options take the form {paramname=\"value\"}.\n\n   If given an XML tag, {XmlExplodeTag} returns a structure of the\n   form {XmlTag(name,params,type)}.  In the returned object, {name} is\n   the (capitalized) tag name, {params} is an assoc list with the\n   options (key fields capitalized), and type can be either \"Open\",\n   \"Close\" or \"OpenClose\".\n\n   If given a plain text string, the same string is returned.\n\n   :Example:\n\n   ::\n\n      In> XmlExplodeTag(\"some plain text\")\n      Out> \"some plain text\";\n      In> XmlExplodeTag(\"<a name=\\\"blah blah\\\"\n      align=\\\"left\\\">\")\n      Out> XmlTag(\"A\",{{\"ALIGN\",\"left\"},\n      {\"NAME\",\"blah blah\"}},\"Open\");\n      In> XmlExplodeTag(\"</p>\")\n      Out> XmlTag(\"P\",{},\"Close\");\n      In> XmlExplodeTag(\"<br/>\")\n      Out> XmlTag(\"BR\",{},\"OpenClose\");\n\n.. seealso:: :func:`XmlTokenizer`\n\n.. function:: XmlTokenizer()\n\n   select the default syntax tokenizer for parsing the input\n\n   A \"tokenizer\" is an internal routine in the kernel that parses the\n   input into Yacas expressions.  This affects all input typed in by a\n   user at the prompt and also the input redirected from files or\n   strings using {FromFile} and {FromString} and read using {Read} or\n   {ReadToken}.    The Yacas environment currently supports some\n   experimental tokenizers for   various syntaxes. {DefaultTokenizer}\n   switches to the tokenizer used for  default Yacas syntax.\n   {XmlTokenizer} switches to an XML syntax.  Note that setting the\n   tokenizer is a global side effect.  One typically needs  to switch\n   back to the default tokenizer when finished reading the special\n   syntax.    Care needs to be taken when kernel errors are raised\n   during a non-default tokenizer operation (as with any global change\n   in the environment).  Errors need to be  caught with the\n   {TrapError} function. The error handler code should re-instate  the\n   default tokenizer,  or else the user will be unable to continue the\n   session  (everything a user types will be parsed using a\n   non-default tokenizer).    When reading XML syntax, the supported\n   formats are the same as those of {XmlExplodeTag}.  The parser does\n   not validate anything in the XML input.  After an XML token has\n   been read in, it can be converted into an  Yacas expression with\n   {XmlExplodeTag}.  Note that when reading XML, any plain text\n   between tags is returned as one token.  Any malformed XML will be\n   treated as plain text.\n\n   :Example:\n\n   ::\n\n      In> [XmlTokenizer(); q:=ReadToken(); \\\n      DefaultTokenizer();q;]\n      <a>\n      Out> <a>;\n\n   Note that:\n\n   * after switching to {XmlTokenizer} the {In>} prompt disappeared;\n     the user typed {<a>} and the {Out>} prompt with the resulting\n     expression appeared.\n   * The resulting expression is an atom with the string\n     representation {<a>}; it is *not* a string.\n\n.. seealso:: :func:`OMRead`, :func:`TrapError`, :func:`XmlExplodeTag`,\n             :func:`ReadToken`, :func:`FromFile`, :func:`FromString`\n\n.. function:: DefaultTokenizer()\n\n   select the default syntax tokenizer for parsing the input\n\n   A \"tokenizer\" is an internal routine in the kernel that parses the\n   input into Yacas expressions.  This affects all input typed in by a\n   user at the prompt and also the input redirected from files or\n   strings using {FromFile} and {FromString} and read using {Read} or\n   {ReadToken}.    The Yacas environment currently supports some\n   experimental tokenizers for   various syntaxes. {DefaultTokenizer}\n   switches to the tokenizer used for  default Yacas syntax.\n   {XmlTokenizer} switches to an XML syntax.  Note that setting the\n   tokenizer is a global side effect.  One typically needs  to switch\n   back to the default tokenizer when finished reading the special\n   syntax.    Care needs to be taken when kernel errors are raised\n   during a non-default tokenizer operation (as with any global change\n   in the environment).  Errors need to be  caught with the\n   {TrapError} function. The error handler code should re-instate  the\n   default tokenizer,  or else the user will be unable to continue the\n   session  (everything a user types will be parsed using a\n   non-default tokenizer).    When reading XML syntax, the supported\n   formats are the same as those of {XmlExplodeTag}.  The parser does\n   not validate anything in the XML input.  After an XML token has\n   been read in, it can be converted into an  Yacas expression with\n   {XmlExplodeTag}.  Note that when reading XML, any plain text\n   between tags is returned as one token.  Any malformed XML will be\n   treated as plain text.\n\n.. seealso:: :func:`OMRead`, :func:`TrapError`, :func:`XmlExplodeTag`,\n             :func:`ReadToken`, :func:`FromFile`, :func:`FromString`\n\n.. function:: OMForm(expression)\n\n   convert Yacas expression to OpenMath\n\n   :param expression: expression to convert\n\n   {OMForm} prints an OpenMath representation of the input parameter\n   {expression} to standard output. If a Yacas symbol does not have a\n   mapping defined by {OMDef}, it is translated to and from OpenMath\n   as the OpenMath symbol in the CD \"yacas\" with the same name as it\n   has in Yacas.\n\n   :Example:\n\n   ::\n\n      In> str:=ToString()OMForm(2+Sin(a*3))\n      Out> \"<OMOBJ>\n        <OMA>\n          <OMS cd=\"arith1\" name=\"plus\"/>\n          <OMI>2</OMI>\n          <OMA>\n            <OMS cd=\"transc1\" name=\"sin\"/>\n            <OMA>\n              <OMS cd=\"arith1\" name=\"times\"/>\n              <OMV name=\"a\"/>\n              <OMI>3</OMI>\n            </OMA>\n          </OMA>\n        </OMA>\n      </OMOBJ>\n      \";\n      In> FromString(str)OMRead()\n      Out> 2+Sin(a*3);\n\n      In> OMForm(NotDefinedInOpenMath(2+3))\n      <OMOBJ>\n        <OMA>\n          <OMS cd=\"yacas\" name=\"NotDefinedInOpenMath\"/>\n          <OMA>\n            <OMS cd=\"arith1\" name=\"plus\"/>\n            <OMI>2</OMI>\n            <OMI>3</OMI>\n          </OMA>\n        </OMA>\n      </OMOBJ>\n      Out> True\n\n.. seealso:: :func:`XmlTokenizer`, :func:`XmlExplodeTag`, :func:`OMDef`\n\n.. function:: OMRead()\n\n   read OpenMath expression and convert to Yacas\n\n   :param expression: expression to convert\n\n   {OMRead} reads an OpenMath expression from standard input and\n   returns a normal Yacas expression that matches the input OpenMath\n   expression. If a Yacas symbol does not have a mapping defined by\n   {OMDef}, it is translated to and from OpenMath as the OpenMath\n   symbol in the CD \"yacas\" with the same name as it has in Yacas.\n\n   :Example:\n\n   ::\n\n      In> str:=ToString()OMForm(2+Sin(a*3))\n      Out> \"<OMOBJ>\n        <OMA>\n          <OMS cd=\"arith1\" name=\"plus\"/>\n          <OMI>2</OMI>\n          <OMA>\n            <OMS cd=\"transc1\" name=\"sin\"/>\n            <OMA>\n              <OMS cd=\"arith1\" name=\"times\"/>\n              <OMV name=\"a\"/>\n              <OMI>3</OMI>\n            </OMA>\n          </OMA>\n        </OMA>\n      </OMOBJ>\n      \";\n      In> FromString(str)OMRead()\n      Out> 2+Sin(a*3);\n\n.. seealso:: :func:`XmlTokenizer`, :func:`XmlExplodeTag`, :func:`OMDef`\n\n.. function:: OMDef(yacasForm, cd, name)\n\n   define translations from Yacas to OpenMath and vice-versa.\n\n   :param yacasForm: string with the name of a Yacas symbol, or a Yacas expression\n   :param cd: OpenMath Content Dictionary for the symbol\n   :param name: OpenMath name for the symbol\n   :param yacasToOM: rule for translating an application of that symbol in Yacas into an OpenMath expression\n   :param omToYacas: rule for translating an OpenMath expression into an application of this symbol in Yacas\n\n   {OMDef} defines the translation rules for symbols between the Yacas\n   representation and {OpenMath}.  The first parameter, {yacasForm},\n   can be a string or an expression. The  difference is that when\n   giving an expression only the {omToYacas} translation  is defined,\n   and it uses the exact expression given. This is used for {OpenMath}\n   symbols that must be translated into a whole subexpression in\n   Yacas, such  as {set1:emptyset} which gets translated to an empty\n   list as follows:      In> OMDef( {}, \"set1\",\"emptyset\" )      Out>\n   True      In> FromString(\"<OMOBJ><OMS cd=\\\"set1\\\"\n   name=\\\"emptyset\\\"/></OMOBJ> \")OMRead()      Out> {}      In>\n   IsList(%)      Out> True  Otherwise, a symbol that is not inside an\n   application (OMA) gets translated to  the Yacas atom with the given\n   name:      In> OMDef( \"EmptySet\", \"set1\",\"emptyset\" )      Warning:\n   the mapping for set1:emptyset was already defined as {} , but is\n   redefined now as EmptySet      Out> True      In>\n   FromString(\"<OMOBJ><OMS cd=\\\"set1\\\" name=\\\"emptyset\\\"/></OMOBJ>\n   \")OMRead()      Out> EmptySet    The definitions for the symbols in\n   the Yacas  library are in the ``*.rep`` script subdirectories. In\n   those modules for which  the mappings are defined, there is a file\n   called {om.ys} that contains the  {OMDef} calls. Those files are\n   loaded in {openmath.rep/om.ys}, so any new  file must be added to\n   the list there, at the end of the file.    A rule is represented as\n   a list of expressions. Since both OM and  Yacas expressions are\n   actually lists, the syntax is the same in both  directions. There\n   are two template forms that are expanded before the  translation:\n\n   * {$}: this symbol stands for the translation of the symbol applied\n     in the original expression.\n\n   * {_path}: a path into the original expression (list) to extract an\n     element, written as an underscore applied to an integer or a list\n     of integers.  Those integers are indexes into expressions, and\n     integers in a list are applied recursively starting at the\n     original expression.  For example, {_2} means the second\n     parameter of the expression, while {_{3,2,1}} means the first\n     parameter of the second parameter of the third parameter of the\n     original expression.\n\n   They can appear anywhere in the rule as expressions or subexpressions.\n\n   Finally, several alternative rules can be specified by joining them\n   with the {|} symbol, and each of them can be annotated with a\n   post-predicate applied with the underscore {_} symbol, in the style\n   of Yacas' simplification rules. Only the first alternative rule\n   that matches is applied, so the more specific rules must be written\n   first.\n\n   There are special symbols recognized by {OMForm} to output\n   {OpenMath} constructs that have no specific parallel in Yacas, such\n   as an OpenMath symbol having a {CD} and {name}: Yacas symbols have\n   only a name.  Those special symbols are:\n\n   *   {OMS(cd, name)}: {<OMS cd=\"cd\" name=\"name\">}\n   *   {OMA(f x y ...)}: {<OMA>f x y ...</OMA>}\n   *   {OMBIND(binderSymbol, bvars, expression)}: {<OMBIND>binderSymbol bvars expression</OMBIND>}, where {bvars} must be produced by using {OMBVAR(...)}.\n   *   {OMBVAR(x y ...)}: {<OMBVAR>x y ...</OMBVAR>}\n   *   {OME(...)}: {<OME>...</OME>}\n\n   When translating from OpenMath to Yacas, we just store unknown\n   symbols as {OMS(\"cd\", \"name\")}. This way we don't have to bother\n   defining bogus symbols for concepts that Yacas does not handle, and\n   we can evaluate expressions that contain them.\n\n   :Example:\n\n   ::\n\n      In> OMDef( \"Sqrt\" ,  \"arith1\", \"root\", { :math:`, _1, 2 }, :math:`(_1)_(_2=2) | (_1^(1/_2)) );\n      Out> True\n      In> OMForm(Sqrt(3))\n      <OMOBJ>\n        <OMA>\n          <OMS cd=\"arith1\" name=\"root\"/>\n          <OMI>3</OMI>\n          <OMI>2</OMI>\n        </OMA>\n      </OMOBJ>\n      Out> True\n      In> FromString(\"<OMOBJ><OMA><OMS cd=\\\"arith1\\\" name=\\\"root\\\"/><OMI>16</OMI><OMI>2</OMI></OMA></OMOBJ> \")OMRead()\n      Out> Sqrt(16)\n      In> FromString(\"<OMOBJ><OMA><OMS cd=\\\"arith1\\\" name=\\\"root\\\"/><OMI>16</OMI><OMI>3</OMI></OMA></OMOBJ> \")OMRead()\n      Out> 16^(1/3)\n\n      In> OMDef(\"Limit\", \"limit1\", \"limit\", \\\n            {  :math:`, _2, OMS(\"limit1\", \"under\"), OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _4) }_(_3=Left)  \\\n            |{ :math:`, _2, OMS(\"limit1\", \"above\"), OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _4) }_(_3=Right) \\\n            |{ :math:`, _2, OMS(\"limit1\", \"both_sides\"), OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _3) },      \\\n            { :math:`, _{3,2,1}, _1, Left,  _{3,3}}_(_2=OMS(\"limit1\", \"below\")) \\\n            |{$, _{3,2,1}, _1, Right, _{3,3}}_(_2=OMS(\"limit1\", \"above\")) \\\n            |{$, _{3,2,1}, _1, _{3,3}}                                    \\\n           );\n      In> OMForm(Limit(x,0) Sin(x)/x)\n      <OMOBJ>\n        <OMA>\n          <OMS cd=\"limit1\" name=\"limit\"/>\n          <OMI>0</OMI>\n          <OMS cd=\"limit1\" name=\"both_sides\"/>\n          <OMBIND>\n            <OMS cd=\"fns1\" name=\"lambda\"/>\n            <OMBVAR>\n              <OMV name=\"x\"/>\n            </OMBVAR>\n            <OMA>\n              <OMS cd=\"arith1\" name=\"divide\"/>\n              <OMA>\n                <OMS cd=\"transc1\" name=\"sin\"/>\n                <OMV name=\"x\"/>\n              </OMA>\n              <OMV name=\"x\"/>\n            </OMA>\n          </OMBIND>\n        </OMA>\n      </OMOBJ>\n      Out> True\n      In> OMForm(Limit(x,0,Right) 1/x)\n      <OMOBJ>\n        <OMA>\n          <OMS cd=\"limit1\" name=\"limit\"/>\n          <OMI>0</OMI>\n          <OMS cd=\"limit1\" name=\"above\"/>\n          <OMBIND>\n            <OMS cd=\"fns1\" name=\"lambda\"/>\n            <OMBVAR>\n              <OMV name=\"x\"/>\n            </OMBVAR>\n            <OMA>\n              <OMS cd=\"arith1\" name=\"divide\"/>\n              <OMI>1</OMI>\n              <OMV name=\"x\"/>\n            </OMA>\n          </OMBIND>\n        </OMA>\n      </OMOBJ>\n      Out> True\n      In> FromString(ToString()OMForm(Limit(x,0,Right) 1/x))OMRead()\n      Out> Limit(x,0,Right)1/x\n      In> %\n      Out> Infinity\n\n   .. seealso:: :func:`OMRead`, :func:`OMForm`\n\n"
  },
  {
    "path": "docs/reference_manual/linear-algebra.rst",
    "content": "==============\nLinear Algebra\n==============\n\nThis chapter describes the commands for doing linear algebra. They can\nbe used to manipulate vectors, represented as lists, and matrices,\nrepresented as lists of lists.\n\n.. function:: Dot(t1,t2)\n              infix . (t1,t2)\n\n   dot product of tensors\n\n   :param t1,t2: tensors (currently only vectors and matrices are supported)\n\n   :func:`Dot` returns the dot product (aka inner product) of two tensors ``t1``\n   and ``t2``. The last  index of ``t1`` and the first index of ``t2`` are\n   contracted. Currently :func:`Dot` works  only for vectors and matrices. Inner\n   product of two vectors, a matrix  with a vector (and vice versa) or two\n   matrices yields respectively a scalar, a vector or a matrix.\n\n   :Example:\n\n   ::\n\n      In> Dot({1,2},{3,4})\n      Out> 11;\n      In> Dot({{1,2},{3,4}},{5,6})\n      Out> {17,39};\n      In> Dot({5,6},{{1,2},{3,4}})\n      Out> {23,34};\n      In> Dot({{1,2},{3,4}},{{5,6},{7,8}})\n      Out> {{19,22},{43,50}};\n\n   Or, using the ``.`` operator::\n\n      In> {1,2} . {3,4}\n      Out> 11;\n      In> {{1,2},{3,4}} . {5,6}\n      Out> {17,39};\n      In> {5,6} . {{1,2},{3,4}}\n      Out> {23,34};\n      In> {{1,2},{3,4}} . {{5,6},{7,8}}\n      Out> {{19,22},{43,50}};\n\n\n   .. seealso:: :func:`Outer`, :func:`Cross`, :func:`IsScalar`, :func:`IsVector`, :func:`IsMatrix`\n\n.. function:: CrossProduct(u,v)\n              infix X(u,v)\n\n   cross outer product of vectors\n\n   :param u, v: three-dimensional vectors\n\n   The `cross product`_ of the vectors ``u``  and ``v`` is returned. Both ``u``\n   and ``v`` have to be three-dimensional.\n\n   :Example:\n\n   ::\n\n      In> {a,b,c} X {d,e,f};\n      Out> {b*f-c*e,c*d-a*f,a*e-b*d};\n\n\n   .. seealso:: :func:`Dot`\n\n   .. _cross product: https://en.wikipedia.org/wiki/Cross_product\n\n.. function:: Outer(t1,t2)\n              infix o(t1,t2)\n\n   outer tensor product\n\n   :param t1,t2: tensors (currently only vectors are supported)\n\n   :func:`Outer` returns the outer product of two tensors ``t1`` and ``t2``.\n   Currently :func:`Outer` work works only for vectors, i.e. tensors of rank 1.\n   The outer product of two vectors yields a matrix.\n\n   :Example:\n\n   ::\n\n      In> Outer({1,2},{3,4,5})\n      Out> {{3,4,5},{6,8,10}};\n      In> Outer({a,b},{c,d})\n      Out> {{a*c,a*d},{b*c,b*d}};\n\n   Or, using the ``o`` operator::\n\n      In> {1,2} o {3,4,5}\n      Out> {{3,4,5},{6,8,10}};\n      In> {a,b} o {c,d}\n      Out> {{a*c,a*d},{b*c,b*d}};\n\n\n   .. seealso:: :func:`Dot`, :func:`Cross`\n\n.. function:: ZeroVector(n)\n\n   create a vector with all zeroes\n\n   :param n: length of the vector to return\n\n   This command returns a vector of length ``n``, filled with zeroes.\n\n   :Example:\n\n   ::\n\n      In> ZeroVector(4)\n      Out> {0,0,0,0};\n\n\n   .. seealso:: :func:`BaseVector`, :func:`ZeroMatrix`, :func:`IsZeroVector`\n\n.. function:: BaseVector(k, n)\n\n   base vector\n\n   :param k: index of the base vector to construct\n   :param n: dimension of the vector\n\n   This command returns the \"k\"-th base vector of dimension \"n\". This\n   is a vector of length \"n\" with all zeroes except for the \"k\"-th\n   entry, which contains a 1.\n\n   :Example:\n\n   ::\n\n      In> BaseVector(2,4)\n      Out> {0,1,0,0};\n\n\n   .. seealso:: :func:`ZeroVector`, :func:`Identity`\n\n.. function:: Identity(n)\n\n   make identity matrix\n\n   :param n: size of the matrix\n\n   This commands returns the identity matrix of size \"n\" by \"n\". This\n   matrix has ones on the diagonal while the other entries are zero.\n\n   :Example:\n\n   ::\n\n      In> Identity(3)\n      Out> {{1,0,0},{0,1,0},{0,0,1}};\n\n\n   .. seealso:: :func:`BaseVector`, :func:`ZeroMatrix`, :func:`DiagonalMatrix`\n\n.. function:: ZeroMatrix(n)\n\n   make a zero matrix\n\n   :param n: number of rows\n   :param m: number of columns\n\n   This command returns a matrix with `n` rows and `m` columns,\n   completely filled with zeroes. If only given one parameter,  it\n   returns the square `n` by `n` zero matrix.\n\n   :Example:\n\n   ::\n\n      In> ZeroMatrix(3,4)\n      Out> {{0,0,0,0},{0,0,0,0},{0,0,0,0}};\n      In> ZeroMatrix(3)\n      Out> {{0,0,0},{0,0,0},{0,0,0}};\n\n\n   .. seealso:: :func:`ZeroVector`, :func:`Identity`\n\n.. function:: Diagonal(A)\n\n   extract the diagonal from a matrix\n\n   :param A: matrix\n\n   This command returns a vector of the diagonal components  of the\n   matrix {A}.\n\n   :Example:\n\n   ::\n\n      In> Diagonal(5*Identity(4))\n      Out> {5,5,5,5};\n      In> Diagonal(HilbertMatrix(3))\n      Out> {1,1/3,1/5};\n\n\n   .. seealso:: :func:`DiagonalMatrix`, :func:`IsDiagonal`\n\n.. function:: DiagonalMatrix(d)\n\n   construct a diagonal matrix\n\n   :param d: list of values to put on the diagonal\n\n   This command constructs a diagonal matrix, that is a square matrix\n   whose off-diagonal entries are all zero. The elements of the vector\n   \"d\" are put on the diagonal.\n\n   :Example:\n\n   ::\n\n      In> DiagonalMatrix(1 .. 4)\n      Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};\n\n\n   .. seealso:: :func:`Identity`, :func:`ZeroMatrix`\n\n.. function:: OrthogonalBasis(W)\n\n   create an orthogonal basis\n\n   :param W: A linearly independent set of row vectors (aka a matrix)\n\n   Given a linearly independent set {W} (constructed of rows vectors),\n   this command returns an orthogonal basis {V} for {W}, which means\n   that span(V) = span(W) and {InProduct(V[i],V[j]) = 0} when {i !=\n   j}.  This function uses the Gram-Schmidt orthogonalization process.\n\n   :Example:\n\n   ::\n\n      In> OrthogonalBasis({{1,1,0},{2,0,1},{2,2,1}})\n      Out> {{1,1,0},{1,-1,1},{-1/3,1/3,2/3}};\n\n\n   .. seealso:: :func:`OrthonormalBasis`, :func:`InProduct`\n\n.. function:: OrthonormalBasis(W)\n\n   create an orthonormal basis\n\n   :param W: A linearly independent set of row vectors (aka a matrix)\n\n   Given a linearly independent set {W} (constructed of rows vectors),\n   this command returns an orthonormal basis {V} for {W}. This is done\n   by first using {OrthogonalBasis(W)}, then dividing each vector by\n   its  magnitude, so as the give them unit length.\n\n   :Example:\n\n   ::\n\n      In> OrthonormalBasis({{1,1,0},{2,0,1},{2,2,1}})\n      Out> {{Sqrt(1/2),Sqrt(1/2),0},{Sqrt(1/3),-Sqrt(1/3),Sqrt(1/3)},\n      {-Sqrt(1/6),Sqrt(1/6),Sqrt(2/3)}};\n\n\n   .. seealso:: :func:`OrthogonalBasis`, :func:`InProduct`, :func:`Normalize`\n\n.. function:: Normalize(v)\n\n   normalize a vector\n\n   :param v: a vector\n\n   Return the normalized (unit) vector parallel to {v}: a vector\n   having the same  direction but with length 1.\n\n   :Example:\n\n   ::\n\n      In> v:=Normalize({3,4})\n      Out> {3/5,4/5};\n      In> v . v\n      Out> 1;\n\n\n   .. seealso:: :func:`InProduct`, :func:`CrossProduct`\n\n.. function:: Transpose(M)\n\n   get transpose of a matrix\n\n   :param M: a matrix\n\n   {Transpose} returns the transpose of a matrix :math:`M`. Because matrices\n   are  just lists of lists, this is a useful operation too for lists.\n\n   :Example:\n\n   ::\n\n      In> Transpose({{a,b}})\n      Out> {{a},{b}};\n\n\n.. function:: Determinant(M)\n\n   determinant of a matrix\n\n   :param M: a matrix\n\n   Returns the determinant of a matrix M.\n\n   :Example:\n\n   ::\n\n      In> A:=DiagonalMatrix(1 .. 4)\n      Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};\n      In> Determinant(A)\n      Out> 24;\n\n\n.. function:: Trace(M)\n\n   trace of a matrix\n\n   :param M: a matrix\n\n   {Trace} returns the trace of a matrix :math:`M` (defined as the sum of\n   the  elements on the diagonal of the matrix).\n\n   :Example:\n\n   ::\n\n      In> A:=DiagonalMatrix(1 .. 4)\n      Out> {{1,0,0,0},{0,2,0,0},{0,0,3,0},{0,0,0,4}};\n      In> Trace(A)\n      Out> 10;\n\n\n.. function:: Inverse(M)\n\n   get inverse of a matrix\n\n   :param M: a matrix\n\n   Inverse returns the inverse of matrix :math:`M`. The determinant of :math:`M`\n   should  be non-zero. Because this function uses {Determinant} for\n   calculating  the inverse of a matrix, you can supply matrices with\n   non-numeric (symbolic)  matrix elements.\n\n   :Example:\n\n   ::\n\n      In> A:=DiagonalMatrix({a,b,c})\n      Out> {{a,0,0},{0,b,0},{0,0,c}};\n      In> B:=Inverse(A)\n      Out> {{(b*c)/(a*b*c),0,0},{0,(a*c)/(a*b*c),0},\n      {0,0,(a*b)/(a*b*c)}};\n      In> Simplify(B)\n      Out> {{1/a,0,0},{0,1/b,0},{0,0,1/c}};\n\n\n   .. seealso:: :func:`Determinant`\n\n.. function:: Minor(M,i,j)\n\n   get principal minor of a matrix\n\n   :param M: a matrix\n   :param i}, {j: positive integers\n\n   Minor returns the minor of a matrix around  the element :math:`i, j`.\n   The minor is the determinant of the matrix obtained from :math:`M` by\n   deleting the :math:`i`-th row and the :math:`j`-th column.\n\n   :Example:\n\n   ::\n\n      In> A := {{1,2,3}, {4,5,6}, {7,8,9}};\n      Out> {{1,2,3},{4,5,6},{7,8,9}};\n      In> PrettyForm(A);\n      /                    \\\n      | ( 1 ) ( 2 ) ( 3 )  |\n      |                    |\n      | ( 4 ) ( 5 ) ( 6 )  |\n      |                    |\n      | ( 7 ) ( 8 ) ( 9 )  |\n      \\                    /\n      Out> True;\n      In> Minor(A,1,2);\n      Out> -6;\n      In> Determinant({{2,3}, {8,9}});\n      Out> -6;\n\n\n   .. seealso:: :func:`CoFactor`, :func:`Determinant`, :func:`Inverse`\n\n.. function:: CoFactor(M,i,j)\n\n   cofactor of a matrix\n\n   :param M: a matrix\n   :param i}, {j: positive integers\n\n   {CoFactor} returns the cofactor of a matrix around  the element\n   :math:`i,j`. The cofactor is the minor times  :math:`(-1)^(i+j)`.\n\n   :Example:\n\n   ::\n\n      In> A := {{1,2,3}, {4,5,6}, {7,8,9}};\n      Out> {{1,2,3},{4,5,6},{7,8,9}};\n      In> PrettyForm(A);\n      /                    \\\n      | ( 1 ) ( 2 ) ( 3 )  |\n      |                    |\n      | ( 4 ) ( 5 ) ( 6 )  |\n      |                    |\n      | ( 7 ) ( 8 ) ( 9 )  |\n      \\                    /\n      Out> True;\n      In> CoFactor(A,1,2);\n      Out> 6;\n      In> Minor(A,1,2);\n      Out> -6;\n      In> Minor(A,1,2) * (-1)^(1+2);\n      Out> 6;\n\n\n   .. seealso:: :func:`Minor`, :func:`Determinant`, :func:`Inverse`\n\n.. function:: MatrixPower(mat,n)\n\n   get nth power of a square matrix\n\n   :param mat: a square matrix\n   :param n: an integer\n\n   {MatrixPower(mat,n)} returns the {n}th power of a square matrix\n   {mat}. For  positive {n} it evaluates dot products of {mat} with\n   itself. For negative  {n} the nth power of the inverse of {mat} is\n   returned. For {n}=0 the identity  matrix is returned.\n\n.. function:: SolveMatrix(M,v)\n\n   solve a linear system\n\n   :param M: a matrix\n   :param v: a vector\n\n   {SolveMatrix} returns the vector :math:`x` that satisfies  the equation\n   :math:`M*x = v`. The determinant of :math:`M` should be non-zero.\n\n   :Example:\n\n   ::\n\n      In> A := {{1,2}, {3,4}};\n      Out> {{1,2},{3,4}};\n      In> v := {5,6};\n      Out> {5,6};\n      In> x := SolveMatrix(A, v);\n      Out> {-4,9/2};\n      In> A * x;\n      Out> {5,6};\n\n\n   .. seealso:: :func:`Inverse`, :func:`Solve`, :func:`PSolve`, :func:`Determinant`\n\n.. function:: Sparsity(matrix)\n\n   get the sparsity of a matrix\n\n   :param matrix: a matrix\n\n   The function {Sparsity} returns a number between {0} and {1} which\n   represents the percentage of zero entries in the matrix. Although\n   there is no definite critical value, a sparsity of {0.75}  or more\n   is almost universally considered a \"sparse\" matrix. These type of\n   matrices can be handled in a different manner than \"full\" matrices\n   which speedup many calculations by orders of magnitude.\n\n   :Example:\n\n   ::\n\n      In> Sparsity(Identity(2))\n      Out> 0.5;\n      In> Sparsity(Identity(10))\n      Out> 0.9;\n      In> Sparsity(HankelMatrix(10))\n      Out> 0.45;\n      In> Sparsity(HankelMatrix(100))\n      Out> 0.495;\n      In> Sparsity(HilbertMatrix(10))\n      Out> 0;\n      In> Sparsity(ZeroMatrix(10,10))\n      Out> 1;\n\nPredicates\n----------\n.. function:: IsScalar(expr)\n\n   test for a scalar\n\n   :param expr: a mathematical object\n\n   {IsScalar} returns :data:`True` if {expr} is a scalar, :data:`False` otherwise.\n   Something is considered to be a scalar if it's not a list.\n\n   :Example:\n\n   ::\n\n      In> IsScalar(7)\n      Out> True;\n      In> IsScalar(Sin(x)+x)\n      Out> True;\n      In> IsScalar({x,y})\n      Out> False;\n\n\n   .. seealso:: :func:`IsList`, :func:`IsVector`, :func:`IsMatrix`\n\n.. function:: IsVector([pred,]expr)\n\n   test for a vector\n\n   :param expr: expression to test\n   :param pred: predicate test (e.g. IsNumber, IsInteger, ...)\n\n   {IsVector(expr)} returns :data:`True` if {expr} is a vector, :data:`False`\n   otherwise.  Something is considered to be a vector if it's a list\n   of scalars.  {IsVector(pred,expr)} returns :data:`True` if {expr} is a\n   vector and if the  predicate test {pred} returns :data:`True` when\n   applied to every element of  the vector {expr}, :data:`False` otherwise.\n\n   :Example:\n\n   ::\n\n      In> IsVector({a,b,c})\n      Out> True;\n      In> IsVector({a,{b},c})\n      Out> False;\n      In> IsVector(IsInteger,{1,2,3})\n      Out> True;\n      In> IsVector(IsInteger,{1,2.5,3})\n      Out> False;\n\n\n   .. seealso:: :func:`IsList`, :func:`IsScalar`, :func:`IsMatrix`\n\n.. function:: IsMatrix([pred,]expr)\n\n   test for a matrix\n\n   :param expr: expression to test\n   :param pred: predicate test (e.g. IsNumber, IsInteger, ...)\n\n   {IsMatrix(expr)} returns :data:`True` if {expr} is a matrix, :data:`False`\n   otherwise.  Something is considered to be a matrix if it's a list\n   of vectors of equal  length.  {IsMatrix(pred,expr)} returns :data:`True`\n   if {expr} is a matrix and if the  predicate test {pred} returns\n   :data:`True` when applied to every element of  the matrix {expr}, :data:`False`\n   otherwise.\n\n   :Example:\n\n   ::\n\n      In> IsMatrix(1)\n      Out> False;\n      In> IsMatrix({1,2})\n      Out> False;\n      In> IsMatrix({{1,2},{3,4}})\n      Out> True;\n      In> IsMatrix(IsRational,{{1,2},{3,4}})\n      Out> False;\n      In> IsMatrix(IsRational,{{1/2,2/3},{3/4,4/5}})\n      Out> True;\n\n\n   .. seealso:: :func:`IsList`, :func:`IsVector`\n\n.. function:: IsSquareMatrix([pred,]expr)\n\n   test for a square matrix\n\n   :param expr: expression to test\n   :param pred: predicate test (e.g. IsNumber, IsInteger, ...)\n\n   {IsSquareMatrix(expr)} returns :data:`True` if {expr} is a square matrix,\n   :data:`False` otherwise. Something is considered to be a square matrix if\n   it's a matrix having the same number of rows and columns.\n   {IsMatrix(pred,expr)} returns :data:`True` if {expr} is a square matrix\n   and  if the predicate test {pred} returns :data:`True` when applied to\n   every  element of the matrix {expr}, :data:`False` otherwise.\n\n   :Example:\n\n   ::\n\n      In> IsSquareMatrix({{1,2},{3,4}});\n      Out> True;\n      In> IsSquareMatrix({{1,2,3},{4,5,6}});\n      Out> False;\n      In> IsSquareMatrix(IsBoolean,{{1,2},{3,4}});\n      Out> False;\n      In> IsSquareMatrix(IsBoolean,{{True,False},{False,True}});\n      Out> True;\n\n\n   .. seealso:: :func:`IsMatrix`\n\n.. function:: IsHermitian(A)\n\n   test for a Hermitian matrix\n\n   :param A: a square matrix\n\n   IsHermitian(A) returns :data:`True` if {A} is Hermitian and :data:`False`\n   otherwise. :math:`A` is a Hermitian matrix iff Conjugate( Transpose :math:`A`\n   )=:math:`A`.  If :math:`A` is a real matrix, it must be symmetric to be\n   Hermitian.\n\n   :Example:\n\n   ::\n\n      In> IsHermitian({{0,I},{-I,0}})\n      Out> True;\n      In> IsHermitian({{0,I},{2,0}})\n      Out> False;\n\n\n   .. seealso:: :func:`IsUnitary`\n\n.. function:: IsOrthogonal(A)\n\n   test for an orthogonal matrix\n\n   :param A: square matrix\n\n   {IsOrthogonal(A)} returns :data:`True` if {A} is orthogonal and :data:`False`\n   otherwise. :math:`A` is orthogonal iff :math:`A`*Transpose(:math:`A`) = Identity, or\n   equivalently Inverse(:math:`A`) = Transpose(:math:`A`).\n\n   :Example:\n\n   ::\n\n      In> A := {{1,2,2},{2,1,-2},{-2,2,-1}};\n      Out> {{1,2,2},{2,1,-2},{-2,2,-1}};\n      In> PrettyForm(A/3)\n      /                      \\\n      | / 1 \\  / 2 \\ / 2 \\   |\n      | | - |  | - | | - |   |\n      | \\ 3 /  \\ 3 / \\ 3 /   |\n      |                      |\n      | / 2 \\  / 1 \\ / -2 \\  |\n      | | - |  | - | | -- |  |\n      | \\ 3 /  \\ 3 / \\ 3  /  |\n      |                      |\n      | / -2 \\ / 2 \\ / -1 \\  |\n      | | -- | | - | | -- |  |\n      | \\ 3  / \\ 3 / \\ 3  /  |\n      \\                      /\n      Out> True;\n      In> IsOrthogonal(A/3)\n      Out> True;\n\n\n.. function:: IsDiagonal(A)\n\n   test for a diagonal matrix\n\n   :param A: a matrix\n\n   {IsDiagonal(A)} returns :data:`True` if {A} is a diagonal square matrix\n   and :data:`False` otherwise.\n\n   :Example:\n\n   ::\n\n      In> IsDiagonal(Identity(5))\n      Out> True;\n      In> IsDiagonal(HilbertMatrix(5))\n      Out> False;\n\n\n.. function:: IsLowerTriangular(A)\n\n   test for a lower triangular matrix\n\n   :param A: a matrix\n\n   A lower/upper triangular matrix is a square matrix which has all\n   zero entries above/below the diagonal.    {IsLowerTriangular(A)}\n   returns :data:`True` if {A} is a lower triangular matrix and :data:`False`\n   otherwise.  {IsUpperTriangular(A)} returns :data:`True` if {A} is an\n   upper triangular matrix and :data:`False` otherwise.\n\n   :Example:\n\n   ::\n\n      In> IsUpperTriangular(Identity(5))\n      Out> True;\n      In> IsLowerTriangular(Identity(5))\n      Out> True;\n      In> IsLowerTriangular({{1,2},{0,1}})\n      Out> False;\n      In> IsUpperTriangular({{1,2},{0,1}})\n      Out> True;\n      A non-square matrix cannot be triangular:\n      In> IsUpperTriangular({{1,2,3},{0,1,2}})\n      Out> False;\n\n\n   .. seealso:: :func:`IsDiagonal`\n\n.. function:: IsSymmetric(A)\n\n   test for a symmetric matrix\n\n   :param A: a matrix\n\n   {IsSymmetric(A)} returns :data:`True` if {A} is symmetric and :data:`False`\n   otherwise.  :math:`A` is symmetric iff Transpose (:math:`A`) =:math:`A`.\n\n   :Example:\n\n   ::\n\n      In> A := {{1,0,0,0,1},{0,2,0,0,0},{0,0,3,0,0},\n      {0,0,0,4,0},{1,0,0,0,5}};\n      In> PrettyForm(A)\n      /                                \\\n      | ( 1 ) ( 0 ) ( 0 ) ( 0 ) ( 1 )  |\n      |                                |\n      | ( 0 ) ( 2 ) ( 0 ) ( 0 ) ( 0 )  |\n      |                                |\n      | ( 0 ) ( 0 ) ( 3 ) ( 0 ) ( 0 )  |\n      |                                |\n      | ( 0 ) ( 0 ) ( 0 ) ( 4 ) ( 0 )  |\n      |                                |\n      | ( 1 ) ( 0 ) ( 0 ) ( 0 ) ( 5 )  |\n      \\                                /\n      Out> True;\n      In> IsSymmetric(A)\n      Out> True;\n\n\n   .. seealso:: :func:`IsHermitian`, :func:`IsSkewSymmetric`\n\n.. function:: IsSkewSymmetric(A)\n\n   test for a skew-symmetric matrix\n\n   :param A: a square matrix\n\n   {IsSkewSymmetric(A)} returns :data:`True` if {A} is skew symmetric and\n   :data:`False` otherwise.  :math:`A` is skew symmetric iff :math:`Transpose(A)` =:math:`-A`.\n\n   :Example:\n\n   ::\n\n      In> A := {{0,-1},{1,0}}\n      Out> {{0,-1},{1,0}};\n      In> PrettyForm(%)\n      /               \\\n      | ( 0 ) ( -1 )  |\n      |               |\n      | ( 1 ) ( 0 )   |\n      \\               /\n      Out> True;\n      In> IsSkewSymmetric(A);\n      Out> True;\n\n\n   .. seealso:: :func:`IsSymmetric`, :func:`IsHermitian`\n\n.. function:: IsUnitary(A)\n\n   test for a unitary matrix\n\n   :param A: a square matrix\n\n   This function tries to find out if A is unitary.    A matrix :math:`A` is\n   orthogonal iff :math:`A^(-1)` = Transpose( Conjugate(:math:`A`) ). This is\n   equivalent to the fact that the columns of :math:`A` build an orthonormal\n   system  (with respect to the scalar product defined by\n   {InProduct}).\n\n   :Example:\n\n   ::\n\n      In> IsUnitary({{0,I},{-I,0}})\n      Out> True;\n      In> IsUnitary({{0,I},{2,0}})\n      Out> False;\n\n\n   .. seealso:: :func:`IsHermitian`, :func:`IsSymmetric`\n\n.. function:: IsIdempotent(A)\n\n   test for an idempotent matrix\n\n   :param A: a square matrix\n\n   {IsIdempotent(A)} returns :data:`True` if {A} is idempotent and :data:`False`\n   otherwise.  :math:`A` is idempotent iff :math:`A^2=A`. Note that this also\n   implies that :math:`A` raised  to any power is also equal to :math:`A`.\n\n   :Example:\n\n   ::\n\n      In> IsIdempotent(ZeroMatrix(10,10));\n      Out> True;\n      In> IsIdempotent(Identity(20))\n      Out> True;\n      Special matrices\n\n\nEigenproblem\n------------\n\n.. function:: CharacteristicEquation(matrix,var)\n\n   get characteristic polynomial of a matrix\n\n   :param matrix: a matrix\n   :param var: a free variable\n\n   CharacteristicEquation  returns the characteristic equation of\n   \"matrix\", using  \"var\". The zeros of this equation are the\n   eigenvalues  of the matrix, Det(matrix-I*var);\n\n   :Example:\n\n   ::\n\n      In> A:=DiagonalMatrix({a,b,c})\n      Out> {{a,0,0},{0,b,0},{0,0,c}};\n      In> B:=CharacteristicEquation(A,x)\n      Out> (a-x)*(b-x)*(c-x);\n      In> Expand(B,x)\n      Out> (b+a+c)*x^2-x^3-((b+a)*c+a*b)*x+a*b*c;\n\n\n   .. seealso:: :func:`EigenValues`, :func:`EigenVectors`\n\n.. function:: EigenValues(matrix)\n\n   get eigenvalues of a matrix\n\n   :param matrix: a square matrix\n\n   EigenValues returns the eigenvalues of a matrix.  The eigenvalues x\n   of a matrix M are the numbers such that  :math:`M*v=x*v` for some vector.\n   It first determines the characteristic equation, and then\n   factorizes this  equation, returning the roots of the\n   characteristic equation  Det(matrix-x*identity).\n\n   :Example:\n\n   ::\n\n      In> M:={{1,2},{2,1}}\n      Out> {{1,2},{2,1}};\n      In> EigenValues(M)\n      Out> {3,-1};\n\n\n   .. seealso:: :func:`EigenVectors`, :func:`CharacteristicEquation`\n\n.. function:: EigenVectors(A,eigenvalues)\n\n   get eigenvectors of a matrix\n\n   :param matrix: a square matrix\n   :param eigenvalues: list of eigenvalues as returned by {EigenValues}\n\n   {EigenVectors} returns a list of the eigenvectors of a matrix.  It\n   uses the eigenvalues and the matrix to set up n equations with  n\n   unknowns for each eigenvalue, and then calls {Solve} to determine\n   the values of each vector.\n\n   :Example:\n\n   ::\n\n      In> M:={{1,2},{2,1}}\n      Out> {{1,2},{2,1}};\n      In> e:=EigenValues(M)\n      Out> {3,-1};\n      In> EigenVectors(M,e)\n      Out> {{-ki2/ -1,ki2},{-ki2,ki2}};\n\n\n   .. seealso:: :func:`EigenValues`, :func:`CharacteristicEquation`\n\n\nMatrix decompositions\n---------------------\n\n.. function:: Cholesky(A)\n\n   find the Cholesky decomposition\n\n   :param A: a square positive definite matrix\n\n   {Cholesky} returns a upper triangular matrix {R} such that\n   {Transpose(R)*R = A}.  The matrix {A} must be positive definite,\n   {Cholesky} will notify the user if the matrix  is not. Some\n   families of positive definite matrices are all symmetric matrices,\n   diagonal  matrices with positive elements and Hilbert matrices.\n\n   :Example:\n\n   ::\n\n      In> A:={{4,-2,4,2},{-2,10,-2,-7},{4,-2,8,4},{2,-7,4,7}}\n      Out> {{4,-2,4,2},{-2,10,-2,-7},{4,-2,8,4},{2,-7,4,7}};\n      In> R:=Cholesky(A);\n      Out> {{2,-1,2,1},{0,3,0,-2},{0,0,2,1},{0,0,0,1}};\n      In> Transpose(R)*R = A\n      Out> True;\n      In> Cholesky(4*Identity(5))\n      Out> {{2,0,0,0,0},{0,2,0,0,0},{0,0,2,0,0},{0,0,0,2,0},{0,0,0,0,2}};\n      In> Cholesky(HilbertMatrix(3))\n      Out> {{1,1/2,1/3},{0,Sqrt(1/12),Sqrt(1/12)},{0,0,Sqrt(1/180)}};\n      In> Cholesky(ToeplitzMatrix({1,2,3}))\n      In function \"Check\" :\n      CommandLine(1) : \"Cholesky: Matrix is not positive definite\"\n\n\n   .. seealso:: :func:`IsSymmetric`, :func:`IsDiagonal`, :func:`Diagonal`\n\n.. function:: LU(A)\n\n   find the LU decomposition\n\n   :param A: square matrix\n\n   :func:`LU` performs `LU decomposition`_ of a matrix.\n\n   :Example:\n\n   ::\n\n      In> A := {{1,2}, {3,4}}\n      Out> {{1,2},{3,4}}\n      In> {l,u} := LU(A)\n      Out> {{{1,0},{3,1}},{{1,2},{0,-2}}}\n      In> IsLowerTriangular(l)\n      Out> True\n      In> IsUpperTriangular(u)\n      Out> True\n      In> l * u\n      Out> {{1,2},{3,4}}\n\n   .. seealso:: :func:`LDU`, :func:`IsLowerTriangular`, :func:`IsUpperTriangular`\n\n   .. _LU decomposition: https://en.wikipedia.org/wiki/LU_decomposition\n\n.. function:: LDU(A)\n\n   find the LDU decomposition\n\n   :param A: square matrix\n\n   :func:`LDU` performs `LDU decomposition`_ of a matrix.\n\n   :Example:\n\n   ::\n\n      In> A := {{1,2}, {3,4}}\n      Out> {{1,2},{3,4}}\n      In> {l,d,u} := LDU(A)\n      Out> {{{1,0},{3,1}},{{1,0},{0,-2}},{{1,2},{0,1}}}\n      In> IsLowerTriangular(l)\n      Out> True\n      In> IsDiagonal(d)\n      Out> True\n      In> IsUpperTriangular(u)\n      Out> True\n      In> l * d * u\n      Out> {{1,2},{3,4}}\n\n   .. seealso:: :func:`LU`, :func:`IsDiagonal`, :func:`IsLowerTriangular`, :func:`IsUpperTriangular`\n\n   .. _LDU decomposition: https://en.wikipedia.org/wiki/LU_decomposition#Definitions\n\n\nSpecial matrices\n----------------\n\n.. function:: VandermondeMatrix(vector)\n\n   create the Vandermonde matrix\n\n   :param vector: an :math:`n`-dimensional vector\n\n   The function {VandermondeMatrix} calculates the Vandermonde matrix\n   of a vector.    The :math:`(i,j)`-th element of the Vandermonde matrix\n   is defined as :math:`i^(j-1)`.\n\n   :Example:\n\n   ::\n\n      In> VandermondeMatrix({1,2,3,4})\n      Out> {{1,1,1,1},{1,2,3,4},{1,4,9,16},{1,8,27,64}};\n      In>PrettyForm(%)\n      /                            \\\n      | ( 1 ) ( 1 ) ( 1 )  ( 1 )   |\n      |                            |\n      | ( 1 ) ( 2 ) ( 3 )  ( 4 )   |\n      |                            |\n      | ( 1 ) ( 4 ) ( 9 )  ( 16 )  |\n      |                            |\n      | ( 1 ) ( 8 ) ( 27 ) ( 64 )  |\n      \\                            /\n\n\n\n.. function:: HilbertMatrix(n)\n\n   create a Hilbert matrix\n\n   :param n,m: positive integers\n\n   The function {HilbertMatrix} returns the {n} by {m} Hilbert matrix\n   if given two arguments, and the square {n} by {n} Hilbert matrix\n   if given only one. The Hilbert matrix is defined as {A(i,j) =\n   1/(i+j-1)}.  The Hilbert matrix is extremely sensitive to\n   manipulate and invert numerically.\n\n   :Example:\n\n   ::\n\n      In> PrettyForm(HilbertMatrix(4))\n      /                          \\\n      | ( 1 ) / 1 \\ / 1 \\ / 1 \\  |\n      |       | - | | - | | - |  |\n      |       \\ 2 / \\ 3 / \\ 4 /  |\n      |                          |\n      | / 1 \\ / 1 \\ / 1 \\ / 1 \\  |\n      | | - | | - | | - | | - |  |\n      | \\ 2 / \\ 3 / \\ 4 / \\ 5 /  |\n      |                          |\n      | / 1 \\ / 1 \\ / 1 \\ / 1 \\  |\n      | | - | | - | | - | | - |  |\n      | \\ 3 / \\ 4 / \\ 5 / \\ 6 /  |\n      |                          |\n      | / 1 \\ / 1 \\ / 1 \\ / 1 \\  |\n      | | - | | - | | - | | - |  |\n      | \\ 4 / \\ 5 / \\ 6 / \\ 7 /  |\n      \\                          /\n\n\n   .. seealso:: :func:`HilbertInverseMatrix`\n\n.. function:: HilbertInverseMatrix(n)\n\n   create a Hilbert inverse matrix\n\n   :param n: positive integer\n\n   The function {HilbertInverseMatrix} returns the {n} by {n} inverse\n   of the  corresponding Hilbert matrix. All Hilbert inverse matrices\n   have integer  entries that grow in magnitude rapidly.\n\n   :Example:\n\n   ::\n\n      In> PrettyForm(HilbertInverseMatrix(4))\n      /                                         \\\n      | ( 16 )   ( -120 )  ( 240 )   ( -140 )   |\n      |                                         |\n      | ( -120 ) ( 1200 )  ( -2700 ) ( 1680 )   |\n      |                                         |\n      | ( 240 )  ( -2700 ) ( 6480 )  ( -4200 )  |\n      |                                         |\n      | ( -140 ) ( 1680 )  ( -4200 ) ( 2800 )   |\n      \\                                         /\n\n\n   .. seealso:: :func:`HilbertMatrix`\n\n.. function:: ToeplitzMatrix(N)\n\n   create a Toeplitz matrix\n\n   :param N: an :math:`n`-dimensional row vector\n\n   The function {ToeplitzMatrix} calculates the Toeplitz matrix given\n   an :math:`n`-dimensional row vector. This matrix has the same entries in\n   all diagonal columns, from upper left to lower right.\n\n   :Example:\n\n   ::\n\n      In> PrettyForm(ToeplitzMatrix({1,2,3,4,5}))\n      /                                \\\n      | ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 )  |\n      |                                |\n      | ( 2 ) ( 1 ) ( 2 ) ( 3 ) ( 4 )  |\n      |                                |\n      | ( 3 ) ( 2 ) ( 1 ) ( 2 ) ( 3 )  |\n      |                                |\n      | ( 4 ) ( 3 ) ( 2 ) ( 1 ) ( 2 )  |\n      |                                |\n      | ( 5 ) ( 4 ) ( 3 ) ( 2 ) ( 1 )  |\n      \\                                /\n\n\n.. function:: SylvesterMatrix(poly1,poly2,variable)\n\n   calculate the Sylvester matrix of two polynomials\n\n   :param poly1: polynomial\n   :param poly2: polynomial\n   :param variable: variable to express the matrix for\n\n   The function {SylvesterMatrix} calculates the Sylvester matrix  for a pair of\n   polynomials. The Sylvester matrix is closely related to the resultant, which\n   is defined as the determinant of the Sylvester matrix. Two polynomials  share\n   common roots only if the resultant is zero.\n\n   :Example:\n\n   ::\n\n      In> ex1:= x^2+2*x-a\n      Out> x^2+2*x-a;\n      In> ex2:= x^2+a*x-4\n      Out> x^2+a*x-4;\n      In> A:=SylvesterMatrix(ex1,ex2,x)\n      Out> {{1,2,-a,0},{0,1,2,-a},\n      {1,a,-4,0},{0,1,a,-4}};\n      In> B:=Determinant(A)\n      Out> 16-a^2*a- -8*a-4*a+a^2- -2*a^2-16-4*a;\n      In> Simplify(B)\n      Out> 3*a^2-a^3;\n      The above example shows that the two polynomials have common\n      zeros if :math:` a = 3 :math:`.\n\n\n   .. seealso:: :func:`Determinant`, :func:`Simplify`, :func:`Solve`, :func:`PSolve`\n\n"
  },
  {
    "path": "docs/reference_manual/lists.rst",
    "content": "===============\nList operations\n===============\n\nMost objects that can be of variable size are represented as lists\n(linked lists internally). Yacas does implement arrays, which are\nfaster when the number of elements in a collection of objects doesn't\nchange. Operations on lists have better support in the current system.\n\n.. function:: Head(list)\n\n   returns the first element of a list\n\n   This function returns the first element of a list. If it is applied\n   to a general expression, it returns the first operand. An error is\n   returned if ``list`` is an atom.\n\n   :Example:\n\n   ::\n\n      In> Head({a,b,c})\n      Out> a;\n      In> Head(f(a,b,c));\n      Out> a;\n\n   .. seealso:: :func:`Tail`, :func:`Length`\n\n.. function:: Tail(list)\n\n   returns a list without its first element\n\n   :Example:\n\n   ::\n\n      In> Tail({a,b,c})\n      Out> {b,c};\n\n   .. seealso:: :func:`Head`, :func:`Length`\n\n.. function:: Length(list)\n              Length(string)\n\n   The length of a list or string\n\n   :Example:\n\n   ::\n\n      In> Length({a,b,c})\n      Out> 3;\n      In> Length(\"abcdef\");\n      Out> 6;\n\n   .. seealso:: :func:`Head`, :func:`Tail`, :func:`Nth`, :func:`Count`\n\n.. function:: Map(fn, list)\n\n   apply an *n*-ary function to all entries in a list\n\n   This function applies ``fn`` to every list of arguments to be found\n   in ``list``. So the first entry of ``list`` should be a list\n   containing the first, second, third, ... argument to ``fn``, and\n   the same goes for the other entries of ``list``. The function can\n   either be given as a string or as a pure function (see :func:`Apply` for\n   more information on pure functions).\n\n   :Example:\n\n   ::\n\n      In> Map(\"+\",{{a,b},{c,d}});\n      Out> {a+c,b+d};\n\n   .. seealso:: :func:`MapSingle`, :func:`MapArgs`, :func:`Apply`\n\n.. function:: MapSingle(fn, list)\n\n   apply a unary function to all entries in a list\n\n   The function ``fn`` is successively applied to all entries in\n   ``list``, and a list containing the respective results is\n   returned. The function can be given either as a string or as a pure\n   function (see :func:`Apply` for more information on pure functions).\n\n   The ``/@`` operator provides a shorthand for :func:`MapSingle`.\n\n   :Example:\n\n   ::\n\n      In> MapSingle(\"Sin\",{a,b,c});\n      Out> {Sin(a),Sin(b),Sin(c)};\n      In> MapSingle({{x},x^2}, {a,2,c});\n      Out> {a^2,4,c^2};\n\n   .. seealso:: :func:`Map`, :func:`MapArgs`, :func:`/@`, :func:`Apply`\n\n\n.. function:: MakeVector(var,n)\n\n   vector of uniquely numbered variable names\n\n   A list of length ``n`` is generated. The first entry contains the\n   identifier ``var`` with the number 1 appended to it, the second entry\n   contains ``var`` with the suffix 2, and so on until the last entry\n   which contains ``var`` with the number ``n`` appended to it.\n\n   :Example:\n\n   ::\n\n      In> MakeVector(a,3)\n      Out> {a1,a2,a3};\n\n   .. seealso:: :func:`RandomIntegerVector`, :func:`ZeroVector`\n\n\n.. function:: Select(pred, list)\n\n   select entries satisfying some predicate\n\n   :func:`Select` returns a sublist of ``list`` which contains all the\n   entries for which the predicate ``pred`` returns ``True`` when\n   applied to this entry.\n\n   :Example:\n\n   ::\n\n      In> Select(\"IsInteger\",{a,b,2,c,3,d,4,e,f})\n      Out> {2,3,4};\n\n   .. seealso:: :func:`Length`, :func:`Find`, :func:`Count`\n\n\n.. function:: Nth(list, n)\n\n   return the ``n``-th element of a list\n\n   The entry with index ``n`` from ``list`` is returned. The first\n   entry has index 1. It is possible to pick several entries of the\n   list by taking ``n`` to be a list of indices.\n\n   More generally, ``Nth`` returns the ``n``-th operand of the\n   expression passed as first argument.\n\n   An alternative but equivalent form of ``Nth(list, n)`` is\n   ``list[n]``.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,13,19};\n      Out> {a,b,c,13,19};\n      In> Nth(lst, 3);\n      Out> c;\n      In> lst[3];\n      Out> c;\n      In> Nth(lst, {3,4,1});\n      Out> {c,13,a};\n      In> Nth(b*(a+c), 2);\n      Out> a+c;\n\n   .. seealso:: :func:`Select`, :func:`Nth`\n\n\n.. function:: Reverse(list)\n\n   return the reversed list (without touching the original)\n\n   :param list: list to reverse\n\n   This function returns a list reversed, without changing the\n   original list. It is similar to :func:`DestructiveReverse`, but safer and\n   slower.\n\n   :Example:\n\n   ::\n\n      In> lst:={a,b,c,13,19}\n      Out> {a,b,c,13,19};\n      In> revlst:=Reverse(lst)\n      Out> {19,13,c,b,a};\n      In> lst\n      Out> {a,b,c,13,19};\n\n   .. seealso:: :func:`FlatCopy`, :func:`DestructiveReverse`\n\n\n.. function:: List(expr1, expr2, ...)\n\n   construct a list\n\n   A list is constructed whose first entry is ``expr1``, the second\n   entry is ``expr2``, and so on. This command is equivalent to the\n   expression ``{expr1, expr2, ...}``.\n\n   :Example:\n\n   ::\n\n      In> List();\n      Out> {};\n      In> List(a,b);\n      Out> {a,b};\n      In> List(a,{1,2},d);\n      Out> {a,{1,2},d};\n\n   .. seealso:: :func:`UnList`, :func:`Listify`\n\n\n.. function:: UnList(list)\n\n   convert a list to a function application\n\n   This command converts a list to a function application. The first\n   entry of ``list`` is treated as a function atom, and the following\n   entries are the arguments to this function. So the function\n   referred to in the first element of ``list`` is applied to the other\n   elements.\n\n   Note that ``list`` is evaluated before the function application is\n   formed, but the resulting expression is left unevaluated. The\n   functions :func:`UnList()` and :func:`Hold()` both stop the process of\n   evaluation.\n\n   :Example:\n\n   ::\n\n      In> UnList({Cos, x});\n      Out> Cos(x);\n      In> UnList({f});\n      Out> f();\n      In> UnList({Taylor,x,0,5,Cos(x)});\n      Out> Taylor(x,0,5)Cos(x);\n      In> Eval(%);\n      Out> 1-x^2/2+x^4/24;\n\n   .. seealso:: :func:`List`, :func:`Listify`, :func:`Hold`\n\n\n.. function:: Listify(expr)\n\n   convert a function application to a list\n\n   The parameter ``expr`` is expected to be a compound object, i.e. not\n   an atom. It is evaluated and then converted to a list. The first\n   entry in the list is the top-level operator in the evaluated\n   expression and the other entries are the arguments to this\n   operator. Finally, the list is returned.\n\n   :Example:\n\n   ::\n\n      In> Listify(Cos(x));\n      Out> {Cos,x};\n      In> Listify(3*a);\n      Out> {*,3,a};\n\n   .. seealso:: :func:`List`, :func:`UnList`, :func:`IsAtom`\n\n\n.. function:: Concat(list1, list2, ...)\n\n   concatenate lists\n\n   The lists ``list1``, ``list2``, ... are evaluated and concatenated. The\n   resulting big list is returned.\n\n   :Example:\n\n   ::\n\n      In> Concat({a,b}, {c,d});\n      Out> {a,b,c,d};\n      In> Concat({5}, {a,b,c}, {{f(x)}});\n      Out> {5,a,b,c,{f(x)}};\n\n   .. seealso:: :func:`ConcatStrings`, :func:`:`, :func:`Insert`\n\n\n.. function:: Delete(list, n)\n\n   delete an element from a list\n\n   This command deletes the ``n``-th element from ``list``. The first\n   parameter should be a list, while ``n`` should be a positive integer\n   less than or equal to the length of ``list``. The entry with index\n   ``n`` is removed (the first entry has index 1), and the resulting\n   list is returned.\n\n   :Example:\n\n   ::\n\n      In> Delete({a,b,c,d,e,f}, 4);\n      Out> {a,b,c,e,f};\n\n   .. seealso:: :func:`DestructiveDelete`, :func:`Insert`, :func:`Replace`\n\n\n.. function:: Insert(list, n, expr)\n\n   insert an element into a list\n\n   The expression ``expr`` is inserted just before the ``n``-th entry in\n   ``list``. The first parameter ``list`` should be a list, while ``n``\n   should be a positive integer less than or equal to the length of\n   ``list`` plus one. The expression ``expr`` is placed between the\n   entries in ``list`` with indices ``n-1`` and ``n``. There are two border\n   line cases: if ``n`` is 1, the expression ``expr`` is placed in front\n   of the list (just as by the :func:`:` operator); if ``n`` equals the length\n   of ``list`` plus one, the expression ``expr`` is placed at the end of\n   the list (just as by :func:`Append`). In any case, the resulting list is\n   returned.\n\n   :Example:\n\n   ::\n\n      In> Insert({a,b,c,d}, 4, x);\n      Out> {a,b,c,x,d};\n      In> Insert({a,b,c,d}, 5, x);\n      Out> {a,b,c,d,x};\n      In> Insert({a,b,c,d}, 1, x);\n      Out> {x,a,b,c,d};\n\n   .. seealso:: :func:`DestructiveInsert`, :func:`:`, :func:`Append`, :func:`Delete`\n\n\n.. function:: Replace(list, n, expr)\n\n   replace an entry in a list\n\n   The ``n``-th entry of ``list`` is replaced by the expression\n   ``expr``. This is equivalent to calling :func:`Delete` and :func:`Insert` in\n   sequence. To be precise, the expression ``Replace(list, n, expr)``\n   has the same result as the expression ``Insert(Delete(list, n), n,\n   expr)``.\n\n   :Example:\n\n   ::\n\n      In> Replace({a,b,c,d,e,f}, 4, x);\n      Out> {a,b,c,x,e,f};\n\n   .. seealso:: :func:`Delete`, :func:`Insert`, :func:`DestructiveReplace`\n\n\n.. function:: FlatCopy(list)\n\n   copy the top level of a list\n\n   A copy of ``list`` is made and returned. The list is not recursed\n   into, only the first level is copied. This is useful in combination\n   with the destructive commands that actually modify lists in place\n   (for efficiency).\n\n   The following shows a possible way to define a command that\n   reverses a list nondestructively.\n\n   :Example:\n\n   ::\n\n      In> reverse(l_IsList) <-- DestructiveReverse(FlatCopy(l));\n      Out> True;\n      In> lst := {a,b,c,d,e};\n      Out> {a,b,c,d,e};\n      In> reverse(lst);\n      Out> {e,d,c,b,a};\n      In> lst;\n      Out> {a,b,c,d,e};\n\n\n.. function:: Contains(list, expr)\n\n   test whether a list contains a certain element\n\n   This command tests whether ``list`` contains the expression ``expr`` as an\n   entry. It returns :const:`True` if it does and :const:`False` otherwise. Only\n   the top level of ``list`` is examined. The parameter ``list`` may also be a\n   general expression, in that case the top-level operands are tested for the\n   occurrence of ``expr``.\n\n   :Example:\n\n   ::\n\n      In> Contains({a,b,c,d}, b);\n      Out> True;\n      In> Contains({a,b,c,d}, x);\n      Out> False;\n      In> Contains({a,{1,2,3},z}, 1);\n      Out> False;\n      In> Contains(a*b, b);\n      Out> True;\n\n   .. seealso:: :func:`Find`, :func:`Count`\n\n\n.. function:: Find(list, expr)\n\n   get the index at which a certain element occurs\n\n   This commands returns the index at which the expression ``expr``\n   occurs in ``list``. If ``expr`` occurs more than once, the lowest\n   index is returned. If ``expr`` does not occur at all, -1 is\n   returned.\n\n   :Example:\n\n   ::\n\n      In> Find({a,b,c,d,e,f}, d);\n      Out> 4;\n      In> Find({1,2,3,2,1}, 2);\n      Out> 2;\n      In> Find({1,2,3,2,1}, 4);\n      Out> -1;\n\n   .. seealso:: :func:`Contains`\n\n\n.. function:: Append(list, expr)\n\n   append an entry at the end of a list\n\n   The expression ``expr`` is appended at the end of ``list`` and the\n   resulting list is returned.\n\n   Note that due to the underlying data structure, the time it takes\n   to append an entry at the end of a list grows linearly with the\n   length of the list, while the time for prepending an entry at the\n   beginning is constant.\n\n   :Example:\n\n   ::\n\n      In> Append({a,b,c,d}, 1);\n      Out> {a,b,c,d,1};\n\n   .. seealso:: :func:`Concat`, :func:`:`, :func:`DestructiveAppend`\n\n.. function:: RemoveDuplicates(list)\n\n   remove any duplicates from a list\n\n   This command removes all duplicate elements from a given list and\n   returns the resulting list.  To be precise, the second occurrence\n   of any entry is deleted, as are the third, the fourth, etc.\n\n   :Example:\n\n   ::\n\n      In> RemoveDuplicates({1,2,3,2,1});\n      Out> {1,2,3};\n      In> RemoveDuplicates({a,1,b,1,c,1});\n      Out> {a,1,b,c};\n\n\n.. function:: Swap(list, i1, i2)\n\n   swap two elements in a list\n\n   This command swaps the pair of entries with entries ``i1`` and\n   ``i2`` in ``list``. So the element at index ``i1`` ends up at index\n   ``i2`` and the entry at ``i2`` is put at index ``i1``. Both indices\n   should be valid to address elements in the list. Then the updated\n   list is returned.  :func:`Swap` works also on generic arrays.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,d,e,f};\n      Out> {a,b,c,d,e,f};\n      In> Swap(lst, 2, 4);\n      Out> {a,d,c,b,e,f};\n\n   .. seealso:: :func:`Replace`, :func:`DestructiveReplace`, :func:`Array'Create`\n\n\n.. function:: Count(list, expr)\n\n   count the number of occurrences of an expression\n\n   This command counts the number of times that the expression\n   ``expr`` occurs in ``list`` and returns this number.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,b,a};\n      Out> {a,b,c,b,a};\n      In> Count(lst, a);\n      Out> 2;\n      In> Count(lst, c);\n      Out> 1;\n      In> Count(lst, x);\n      Out> 0;\n\n   .. seealso:: :func:`Length`, :func:`Select`, :func:`Contains`\n\n.. function:: FillList(expr, n)\n\n   fill a list with a certain expression\n\n   This command creates a list of length ``n`` in which all slots\n   contain the expression ``expr`` and returns this list.\n\n   :Example:\n\n   ::\n\n      In> FillList(x, 5);\n      Out> {x,x,x,x,x};\n\n   .. seealso:: :func:`MakeVector`, :func:`ZeroVector`, :func:`RandomIntegerVector`\n\n\n.. function:: Drop(list, n)\n              Drop(list, -n)\n              Drop(list, {m, n})\n\n   drop a range of elements from a list\n\n   This command removes a sublist of ``list`` and returns a list\n   containing the remaining entries. The first calling sequence drops\n   the first ``n`` entries in ``list``. The second form drops the last\n   ``n`` entries. The last invocation drops the elements with indices\n   ``m`` through ``n``.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,d,e,f,g};\n      Out> {a,b,c,d,e,f,g};\n      In> Drop(lst, 2);\n      Out> {c,d,e,f,g};\n      In> Drop(lst, -3);\n      Out> {a,b,c,d};\n      In> Drop(lst, {2,4});\n      Out> {a,e,f,g};\n\n   .. seealso:: :func:`Take`, :func:`Select`\n\n\n.. function:: Take(list, n)\n              Take(list, -n)\n              Take(list, {m,n})\n\n   take a sublist from a list, dropping the rest\n\n   This command takes a sublist of ``list``, drops the rest, and\n   returns the selected sublist. The first calling sequence selects\n   the first ``n`` entries in ``list``. The second form takes the last\n   ``n`` entries. The last invocation selects the sublist beginning\n   with entry number ``m`` and ending with the ``n``-th entry.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,d,e,f,g};\n      Out> {a,b,c,d,e,f,g};\n      In> Take(lst, 2);\n      Out> {a,b};\n      In> Take(lst, -3);\n      Out> {e,f,g};\n      In> Take(lst, {2,4});\n      Out> {b,c,d};\n\n   .. seealso:: :func:`Drop`, :func:`Select`\n\n\n.. function:: Partition(list, n)\n\n   partition a list in sublists of equal length\n\n   This command partitions ``list`` into non-overlapping sublists of\n   length ``n`` and returns a list of these sublists. The first ``n``\n   entries in ``list`` form the first partition, the entries from\n   position ``n+1`` up to ``2n`` form the second partition, and so\n   on. If ``n`` does not divide the length of ``list``, the remaining\n   entries will be thrown away. If ``n`` equals zero, an empty list is\n   returned.\n\n   :Example:\n\n   ::\n\n      In> Partition({a,b,c,d,e,f,}, 2);\n      Out> {{a,b},{c,d},{e,f}};\n      In> Partition(1 .. 11, 3);\n      Out> {{1,2,3},{4,5,6},{7,8,9}};\n\n   .. seealso:: :func:`Take`, :func:`Permutations`\n\n\n.. function:: Flatten(expression,operator)\n\n   flatten expression w.r.t. some operator\n\n   :func:`Flatten` flattens an expression with respect to a specific operator,\n   converting the result into a list.  This is useful for unnesting an\n   expression. :func:`Flatten` is typically used in simple simplification\n   schemes.\n\n   :Example:\n\n   ::\n\n      In> Flatten(a+b*c+d, \"+\");\n      Out> {a,b*c,d};\n      In> Flatten({a,{b,c},d}, \"List\");\n      Out> {a,b,c,d};\n\n   .. seealso:: :func:`UnFlatten`\n\n.. function:: UnFlatten(list,operator,identity)\n\n   inverse operation of :func:`Flatten`\n\n   :func:`UnFlatten` is the inverse operation of :func:`Flatten`. Given a list,\n   it can be turned into an expression representing for instance the addition of\n   these elements by calling :func:`UnFlatten` with ``+`` as argument to\n   operator, and 0 as argument to identity (0 is the identity for addition,\n   since a+0=a). For multiplication the identity element would be 1.\n\n   :Example:\n\n   ::\n\n      In> UnFlatten({a,b,c},\"+\",0)\n      Out> a+b+c;\n      In> UnFlatten({a,b,c},\"*\",1)\n      Out> a*b*c;\n\n   .. seealso:: :func:`Flatten`\n\n\n.. function:: Type(expr)\n\n   return the type of an expression\n\n   The type of the expression ``expr`` is represented as a string and\n   returned. So, if ``expr`` is a list, the string ``\"List\"`` is\n   returned. In general, the top-level operator of ``expr`` is\n   returned. If the argument ``expr`` is an atom, the result is the\n   empty string ``\"\"``.\n\n   :Example:\n\n   ::\n\n      In> Type({a,b,c});\n      Out> \"List\";\n      In> Type(a*(b+c));\n      Out> \"*\";\n      In> Type(123);\n      Out> \"\";\n\n   .. seealso:: :func:`IsAtom`, :func:`NrArgs`\n\n\n.. function:: NrArgs(expr)\n\n   return number of top-level arguments\n\n   This function evaluates to the number of top-level arguments of the\n   expression ``expr``. The argument ``expr`` may not be an atom,\n   since that would lead to an error.\n\n   :Example:\n\n   ::\n\n      In> NrArgs(f(a,b,c))\n      Out> 3;\n      In> NrArgs(Sin(x));\n      Out> 1;\n      In> NrArgs(a*(b+c));\n      Out> 2;\n\n   .. seealso:: :func:`Type`, :func:`Length`\n\n\n.. function:: VarList(expr)\n              VarListArith(expr)\n              VarListSome(expr, list)\n\n   list of variables appearing in an expression\n\n   The command :func:`VarList` returns a list of all variables that\n   appear in the expression ``expr``. The expression is traversed\n   recursively.\n\n   The command :func:`VarListSome` looks only at arguments of functions in the\n   ``list``. All other functions are considered opaque (as if they do not\n   contain any variables) and their arguments are not checked.  For example,\n   ``VarListSome(a + Sin(b-c))`` will return ``{a, b, c}``, but\n   ``VarListSome(a*Sin(b-c), {*})`` will not look at arguments of :func:`Sin`\n   and will return ``{a,Sin(b-c)}``. Here ``Sin(b-c)`` is considered a\n   variable because the function :func:`Sin` does not belong to ``list``.\n\n   The command \"func:`VarListArith` returns a list of all variables that appear\n   arithmetically in the expression ``expr``. This is implemented through\n   :func:`VarListSome` by restricting to the arithmetic functions ``+``, ``-``,\n   ``*``, ``/``.  Arguments of other functions are not checked.\n\n   Note that since the operators ``+`` and ``-`` are prefix as well as infix\n   operators, it is currently required to use ``Atom(\"+\")`` to obtain the\n   unevaluated atom ``+``.\n\n   :Example:\n\n   ::\n\n      In> VarList(Sin(x))\n      Out> {x};\n      In> VarList(x+a*y)\n      Out> {x,a,y};\n      In> VarListSome(x+a*y, {Atom(\"+\")})\n      Out> {x,a*y};\n      In> VarListArith(x+y*Cos(Ln(x)/x))\n      Out> {x,y,Cos(Ln(x)/x)}\n      In> VarListArith(x+a*y^2-1)\n      Out> {x,a,y^2};\n\n   .. seealso:: :func:`IsFreeOf`, :func:`IsVariable`, :func:`FuncList`, :func:`HasExpr`, :func:`HasFunc`\n\n\n.. function:: FuncList(expr)\n\n   list of functions used in an expression\n\n   The command :func:`FuncList` returns a list of all function atoms that appear\n   in the expression ``expr``. The expression is recursively traversed.\n\n   :Example:\n\n   ::\n\n      In> FuncList(x+y*Cos(Ln(x)/x))\n      Out> {+,*,Cos,/,Ln};\n\n   .. seealso:: :func:`VarList`, :func:`HasExpr`, :func:`HasFunc`\n\n\n.. function:: FuncListArith(expr)\n\n   list of functions used in an expression\n\n   :func:`FuncListArith` is defined through :func:`FuncListSome` to look only\n   at arithmetic operations ``+``, ``-``, ``*``, ``/``.\n\n   :Example:\n\n   ::\n\n      In> FuncListArith(x+y*Cos(Ln(x)/x))\n      Out> {+,*,Cos};\n\n   .. seealso:: :func:`VarList`, :func:`HasExpr`, :func:`HasFunc`\n\n\n.. function:: FuncListSome(expr, list)\n\n   list of functions used in an expression\n\n   The command :func:`FuncListSome` does the same as :func:`FuncList`, except it\n   only looks at arguments of a given ``list`` of functions. All other functions\n   become opaque (as if they do not contain any other functions).  For example,\n   ``FuncList(a + Sin(b-c))`` will see that the expression has a ``{-}``\n   operation and return {{+,Sin,-}}, but ``FuncListSome(a + Sin(b-c), {+})``\n   will not look at arguments of :func:`Sin` and will return ``{+,Sin}``.\n\n   Note that since the operators ``+`` and ``-`` are prefix as\n   well as infix operators, it is currently required to use\n   ``Atom(\"+\")`` to obtain the unevaluated atom ``+``.\n\n   :Example:\n\n   ::\n\n      In> FuncListSome({a+b*2,c/d},{List})\n      Out> {List,+,/};\n\n   .. seealso:: :func:`VarList`, :func:`HasExpr`, :func:`HasFunc`\n\n\n.. function:: PrintList(list [, padding])\n\n   print list with padding\n\n   Prints ``list`` and inserts the ``padding`` string between each\n   pair of items of the list. Items of the list which are strings are\n   printed without quotes, unlike :func:`Write`. Items of the list which\n   are themselves lists are printed inside braces ``{}``. If padding\n   is not specified, standard one is used \", \" (comma, space).\n\n   :Example:\n\n   ::\n\n      In> PrintList({a,b,{c, d}}, `` .. ``)\n      Out> `` a ..  b .. { c ..  d}``;\n\n   .. seealso:: :func:`Write`, :func:`WriteString`\n\n\n.. function:: Table(body, var, from, to, step)\n\n   evaluate while some variable ranges over interval\n\n   This command generates a list of values from ``body``, by assigning\n   variable ``var`` values from ``from`` up to ``to``, incrementing\n   ``step`` each time. So, the variable ``var`` first gets the value\n   ``from``, and the expression ``body`` is evaluated. Then the value\n   ``from``+``step`` is assigned to ``var`` and the expression\n   ``body`` is again evaluated. This continues, incrementing ``var``\n   with ``step`` on every iteration, until ``var`` exceeds ``to``. At\n   that moment, all the results are assembled in a list and this list\n   is returned.\n\n   :Example:\n\n   ::\n\n      In> Table(i!, i, 1, 9, 1);\n      Out> {1,2,6,24,120,720,5040,40320,362880};\n      In> Table(i, i, 3, 16, 4);\n      Out> {3,7,11,15};\n      In> Table(i^2, i, 10, 1, -1);\n      Out> {100,81,64,49,36,25,16,9,4,1};\n\n   .. seealso:: :func:`For`, :func:`MapSingle`, `..`:, :func:`TableForm`\n\n\n.. function:: TableForm(list)\n\n   print each entry in a list on a line\n\n   This functions writes out the list ``list`` in a better readable\n   form, by printing every element in the list on a separate line.\n\n   :Example:\n\n   ::\n\n      In> TableForm(Table(i!, i, 1, 10, 1));\n\n      1\n      2\n      6\n      24\n      120\n      720\n      5040\n      40320\n      362880\n      3628800\n      Out> True;\n\n   .. seealso:: :func:`PrettyForm`, :func:`Echo`, :func:`Table`\n\nDestructive operations\n----------------------\n\nDestructive commands run faster than their nondestructive counterparts because\nthe latter copy the list before they alter it.\n\n\n.. function:: DestructiveAppend(list, expr)\n\n   destructively append an entry to a list\n\n   This is the destructive counterpart of :func:`Append`. This command yields\n   the same result as the corresponding call to :func:`Append`, but the original\n   list is modified. So if a variable is bound to ``list``, it will now be bound\n   to the list with the expression ``expr`` inserted.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,d};\n      Out> {a,b,c,d};\n      In> Append(lst, 1);\n      Out> {a,b,c,d,1};\n      In> lst\n      Out> {a,b,c,d};\n      In> DestructiveAppend(lst, 1);\n      Out> {a,b,c,d,1};\n      In> lst;\n      Out> {a,b,c,d,1};\n\n   .. seealso:: :func:`Concat`, :func:`:`, :func:`Append`\n\n\n.. function:: DestructiveDelete(list, n)\n\n   delete an element destructively from a list\n\n   This is the destructive counterpart of :func`Delete`. This command yields the\n   same result as the corresponding call to :func:`Delete`, but the original\n   list is modified. So if a variable is bound to ``list``, it will now be bound\n   to the list with the ``n``-th entry removed.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,d,e,f};\n      Out> {a,b,c,d,e,f};\n      In> Delete(lst, 4);\n      Out> {a,b,c,e,f};\n      In> lst;\n      Out> {a,b,c,d,e,f};\n      In> DestructiveDelete(lst, 4);\n      Out> {a,b,c,e,f};\n      In> lst;\n      Out> {a,b,c,e,f};\n\n   .. seealso:: :func:`Delete`, :func:`DestructiveInsert`, :func:`DestructiveReplace`\n\n\n.. function:: DestructiveInsert(list, n, expr)\n\n   insert an element destructively into a list\n\n   This is the destructive counterpart of :func:`Insert`. This command\n   yields the same result as the corresponding call to :func:`Insert`, but\n   the original list is modified. So if a variable is bound to\n   ``list``, it will now be bound to the list with the expression\n   ``expr`` inserted.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,d};\n      Out> {a,b,c,d};\n      In> Insert(lst, 2, x);\n      Out> {a,x,b,c,d};\n      In> lst;\n      Out> {a,b,c,d};\n      In> DestructiveInsert(lst, 2, x);\n      Out> {a,x,b,c,d};\n      In> lst;\n      Out> {a,x,b,c,d};\n\n   .. seealso:: :func:`Insert`, :func:`DestructiveDelete`, :func:`DestructiveReplace`\n\n\n.. function:: DestructiveReplace(list, n, expr)\n\n   replace an entry destructively in a list\n\n   :param list: list of which an entry should be replaced\n   :param n: index of entry to replace\n   :param expr: expression to replace the ``n``-th entry with\n\n   This is the destructive counterpart of :func:`Replace`. This command\n   yields the same result as the corresponding call to :func:`Replace`, but\n   the original list is modified. So if a variable is bound to\n   ``list``, it will now be bound to the list with the expression\n   ``expr`` inserted.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,d,e,f};\n      Out> {a,b,c,d,e,f};\n      In> Replace(lst, 4, x);\n      Out> {a,b,c,x,e,f};\n      In> lst;\n      Out> {a,b,c,d,e,f};\n      In> DestructiveReplace(lst, 4, x);\n      Out> {a,b,c,x,e,f};\n      In> lst;\n      Out> {a,b,c,x,e,f};\n\n   .. seealso:: :func:`Replace`, :func:`DestructiveDelete`, :func:`DestructiveInsert`\n\n\n\n.. function:: DestructiveReverse(list)\n\n   reverse a list destructively\n\n   This command reverses ``list`` in place, so that the original is\n   destroyed. This means that any variable bound to ``list`` will now\n   have an undefined content, and should not be used any more.  The\n   reversed list is returned.\n\n   :Example:\n\n   ::\n\n      In> lst := {a,b,c,13,19};\n      Out> {a,b,c,13,19};\n      In> revlst := DestructiveReverse(lst);\n      Out> {19,13,c,b,a};\n      In> lst;\n      Out> {a};\n\n   .. seealso:: :func:`FlatCopy`, :func:`Reverse`\n\nSet operations\n--------------\n\n.. function:: Intersection(l1, l2)\n\n   return the intersection of two lists\n\n   The intersection of the lists ``l1`` and ``l2`` is determined and\n   returned. The intersection contains all elements that occur in both\n   lists. The entries in the result are listed in the same order as in\n   ``l1``. If an expression occurs multiple times in both ``l1`` and\n   ``l2``, then it will occur the same number of times in the result.\n\n   :Example:\n\n   ::\n\n      In> Intersection({a,b,c}, {b,c,d});\n      Out> {b,c};\n      In> Intersection({a,e,i,o,u}, {f,o,u,r,t,e,e,n});\n      Out> {e,o,u};\n      In> Intersection({1,2,2,3,3,3}, {1,1,2,2,3,3});\n      Out> {1,2,2,3,3};\n\n   .. seealso:: :func:`Union`, :func:`Difference`\n\n.. function:: Union(l1, l2)\n\n   return the union of two lists\n\n   The union of the lists ``l1`` and ``l2`` is determined and\n   returned. The union contains all elements that occur in one or both\n   of the lists. In the resulting list, any element will occur only\n   once.\n\n   :Example:\n\n   ::\n\n      In> Union({a,b,c}, {b,c,d});\n      Out> {a,b,c,d};\n      In> Union({a,e,i,o,u}, {f,o,u,r,t,e,e,n});\n      Out> {a,e,i,o,u,f,r,t,n};\n      In> Union({1,2,2,3,3,3}, {2,2,3,3,4,4});\n      Out> {1,2,3,4};\n\n   .. seealso:: :func:`Intersection`, :func:`Difference`\n\n\n.. function:: Difference(l1, l2)\n\n   return the difference of two lists\n\n   The difference of the lists ``l1`` and ``l2`` is determined and\n   returned. The difference contains all elements that occur in ``l1``\n   but not in ``l2``. The order of elements in ``l1`` is preserved. If\n   a certain expression occurs ``n1`` times in the first list and\n   ``n2`` times in the second list, it will occur ``n1-n2`` times in\n   the result if ``n1`` is greater than ``n2`` and not at all\n   otherwise.\n\n   :Example:\n\n   ::\n\n      In> Difference({a,b,c}, {b,c,d});\n      Out> {a};\n      In> Difference({a,e,i,o,u}, {f,o,u,r,t,e,e,n});\n      Out> {a,i};\n      In> Difference({1,2,2,3,3,3}, {2,2,3,4,4});\n      Out> {1,3,3};\n\n   .. seealso:: :func:`Intersection`, :func:`Union`\n\nAssociative map\n---------------\n\n.. function:: Assoc(key, alist)\n\n   return element stored in association list\n\n   The association list ``alist`` is searched for an entry stored with\n   index ``key``. If such an entry is found, it is returned. Otherwise\n   the atom :const:`Empty` is returned.\n\n   Association lists are represented as a list of two-entry lists. The\n   first element in the two-entry list is the key, the second element\n   is the value stored under this key.\n\n   The call ``Assoc(key, alist)`` can (probably more intuitively) be\n   accessed as ``alist[key]``.\n\n   :Example:\n\n   ::\n\n      In> writer := {};\n      Out> {};\n      In> writer[``Iliad``] := ``Homer``;\n      Out> True;\n      In> writer[``Henry IV``] := ``Shakespeare``;\n      Out> True;\n      In> writer[``Ulysses``] := ``James Joyce``;\n      Out> True;\n      In> Assoc(``Henry IV``, writer);\n      Out> {``Henry IV``,``Shakespeare``};\n      In> Assoc(``War and Peace``, writer);\n      Out> Empty;\n\n   .. seealso:: :func:`AssocIndices`, :func:`[]`, :func:`:=`, :func:`AssocDelete`\n\n\n.. function:: AssocIndices(alist)\n\n   return the keys in an association list\n\n   All the keys in the association list ``alist`` are assembled in a\n   list and this list is returned.\n\n   :Example:\n\n   ::\n\n      In> writer := {};\n      Out> {};\n      In> writer[``Iliad``] := ``Homer``;\n      Out> True;\n      In> writer[``Henry IV``] := ``Shakespeare``;\n      Out> True;\n      In> writer[``Ulysses``] := ``James Joyce``;\n      Out> True;\n      In> AssocIndices(writer);\n      Out> {``Iliad``,``Henry IV``,``Ulysses``};\n\n   .. seealso:: :func:`Assoc`, :func:`AssocDelete`\n\n\n.. function:: AssocDelete(alist, key)\n              AssocDelete(alist, {key, value})\n\n   delete an entry in an association list\n\n   The key {``key``} in the association list ``alist`` is deleted. (The\n   list itself is modified.) If the key was found and successfully\n   deleted, returns :const:`True`, otherwise if the given key was not found,\n   the function returns :const:`False`.\n\n   The second, longer form of the function deletes the entry that has both the\n   specified key and the specified value. It can be used for two purposes:\n\n   * to make sure that we are deleting the right value;\n   * if several values are stored on the same key, to delete the specified entry\n     (see the last example).\n\n   At most one entry is deleted.\n\n   :Example:\n\n   ::\n\n      In> writer := {};\n      Out> {};\n      In> writer[``Iliad``] := ``Homer``;\n      Out> True;\n      In> writer[``Henry IV``] := ``Shakespeare``;\n      Out> True;\n      In> writer[``Ulysses``] := ``James Joyce``;\n      Out> True;\n      In> AssocDelete(writer, ``Henry IV``)\n      Out> True;\n      In> AssocDelete(writer, ``Henry XII``)\n      Out> False;\n      In> writer\n      Out> {{``Ulysses``,``James Joyce``},\n      {``Iliad``,``Homer``}};\n      In> DestructiveAppend(writer,\n      {``Ulysses``, ``Dublin``});\n      Out> {{``Iliad``,``Homer``},{``Ulysses``,``James Joyce``},\n      {``Ulysses``,``Dublin``}};\n      In> writer[``Ulysses``];\n      Out> ``James Joyce``;\n      In> AssocDelete(writer,{``Ulysses``,``James Joyce``});\n      Out> True;\n      In> writer\n      Out> {{``Iliad``,``Homer``},{``Ulysses``,``Dublin``}};\n\n   .. seealso:: :func:`Assoc`, :func:`AssocIndices`\n\nSorting\n-------\n\n.. function:: BubbleSort(list, compare)\n\n   sort a list\n\n   This command returns ``list`` after it is sorted using ``compare`` to compare\n   elements. The function ``compare`` should accept two arguments, which will be\n   elements of ``list``, and compare them. It should return :const:`True` if in the\n   sorted list the second argument should come after the first one, and\n   :const:`False` otherwise.\n\n   The function :func:`BubbleSort` uses the so-called `bubble sort\n   <http://en.wikipedia.org/wiki/Bubble_sort>`_ algorithm to do the sorting by\n   swapping elements that are out of order. This algorithm is easy to implement,\n   though it is not particularly fast. The sorting time is proportional to\n   :math:`n^2` where :math:`n` is the length of the list.\n\n   :Example:\n\n   ::\n\n      In> BubbleSort({4,7,23,53,-2,1}, \"<\");\n      Out> {-2,1,4,7,23,53};\n\n   .. seealso:: :func:`HeapSort`\n\n\n.. function:: HeapSort(list, compare)\n\n   sort a list\n\n   This command returns ``list`` after it is sorted using ``compare`` to compare\n   elements. The function ``compare`` should accept two arguments, which will be\n   elements of ``list``, and compare them. It should return :const:`True` if in the\n   sorted list the second argument should come after the first one, and\n   :const:`False` otherwise.\n\n   The function :func:`HeapSort` uses the :func:`heapsort algorithm\n   <http://en.wikipedia.org/wiki/Heapsort>` and is much faster for large lists.\n   The sorting time is proportional to :math:`n\\ln(n)` where :math:`n` is the\n   length of the list.\n\n   :Example:\n\n   ::\n\n      In> HeapSort({4,7,23,53,-2,1}, ``>``);\n      Out> {53,23,7,4,1,-2};\n\n   .. seealso:: :func:`BubbleSort`\n\nStack and queue operations\n--------------------------\n\n.. function:: Push(stack, expr)\n\n   add an element on top of a stack\n\n   This is part of a simple implementation of a stack, internally\n   represented as a list. This command pushes the expression ``expr``\n   on top of the stack, and returns the stack afterwards.\n\n   :Example:\n\n   ::\n\n      In> stack := {};\n      Out> {};\n      In> Push(stack, x);\n      Out> {x};\n      In> Push(stack, x2);\n      Out> {x2,x};\n      In> PopFront(stack);\n      Out> x2;\n\n   .. seealso:: :func:`Pop`, :func:`PopFront`, :func:`PopBack`\n\n\n.. function:: Pop(stack, n)\n\n   remove an element from a stack\n\n   This is part of a simple implementation of a stack, internally\n   represented as a list. This command removes the element with index\n   ``n`` from the stack and returns this element. The top of the stack\n   is represented by the index 1. Invalid indices, for example indices\n   greater than the number of element on the stack, lead to an error.\n\n   :Example:\n\n   ::\n\n      In> stack := {};\n      Out> {};\n      In> Push(stack, x);\n      Out> {x};\n      In> Push(stack, x2);\n      Out> {x2,x};\n      In> Push(stack, x3);\n      Out> {x3,x2,x};\n      In> Pop(stack, 2);\n      Out> x2;\n      In> stack;\n      Out> {x3,x};\n\n   .. seealso:: :func:`Push`, :func:`PopFront`, :func:`PopBack`\n\n\n.. function:: PopFront(stack)\n\n   remove an element from the top of a stack\n\n   This is part of a simple implementation of a stack, internally\n   represented as a list. This command removes the element on the top\n   of the stack and returns it. This is the last element that is\n   pushed onto the stack.\n\n   :Example:\n\n   ::\n\n      In> stack := {};\n      Out> {};\n      In> Push(stack, x);\n      Out> {x};\n      In> Push(stack, x2);\n      Out> {x2,x};\n      In> Push(stack, x3);\n      Out> {x3,x2,x};\n      In> PopFront(stack);\n      Out> x3;\n      In> stack;\n      Out> {x2,x};\n\n   .. seealso:: :func:`Push`, :func:`Pop`, :func:`PopBack`\n\n\n.. function:: PopBack(stack)\n\n   remove an element from the bottom of a stack\n\n   This is part of a simple implementation of a stack, internally\n   represented as a list. This command removes the element at the\n   bottom of the stack and returns this element. Of course, the stack\n   should not be empty.\n\n   :Example:\n\n   ::\n\n      In> stack := {};\n      Out> {};\n      In> Push(stack, x);\n      Out> {x};\n      In> Push(stack, x2);\n      Out> {x2,x};\n      In> Push(stack, x3);\n      Out> {x3,x2,x};\n      In> PopBack(stack);\n      Out> x;\n      In> stack;\n      Out> {x3,x2};\n\n   .. seealso:: :func:`Push`, :func:`Pop`, :func:`PopFront`\n\nGlobal stack\n^^^^^^^^^^^^\n\nThe functions below operate on a global stack, currently implemented as a list\nthat is not accessible externally (it is protected through\n:func:`LocalSymbols`).\n\n.. function:: GlobalPop()\n              GlobalPop(var)\n\n   restore variables using a global stack\n\n   :func:`GlobalPop` removes the last pushed value from the stack. If a variable\n   name is given, the variable is assigned, otherwise the popped value is\n   returned. If the global stack is empty, an error message is printed.\n\n   .. seealso:: :func:`GlobalPush`, :func:`Pop`, :func:`PopFront`\n\n.. function:: GlobalPush(expr)\n\n   save variables using a global stack\n\n   :Example:\n\n   ::\n\n      In> GlobalPush(3)\n      Out> 3;\n      In> GlobalPush(Sin(x))\n      Out> Sin(x);\n      In> GlobalPop(x)\n      Out> Sin(x);\n      In> GlobalPop(x)\n      Out> 3;\n      In> x\n      Out> 3;\n\n   .. seealso:: :func:`GlobalPop`, :func:`Push`, :func:`PopFront`\n"
  },
  {
    "path": "docs/reference_manual/logic.rst",
    "content": "==================================\nPropositional logic theorem prover\n==================================\n\n.. function:: CanProve(proposition)\n\n   try to prove statement\n\n   :param proposition: an expression with logical operations\n\n   Yacas has a small built-in propositional logic theorem prover. It can be\n   invoked with a call to :func:`CanProve`. An example of a proposition is: \"if\n   a implies b and b implies c then a implies c\". Yacas supports the following\n   logical operations:\n\n    ``Not``\n       negation, read as \"not\"\n\n    ``And``\n        conjunction, read as \"and\"\n\n    ``Or``\n        disjunction, read as \"or\"\n    ``=>``\n        implication, read as \"implies\"\n\n   The abovementioned proposition would be represented by the following\n   expression::\n\n        ( (a=>b) And (b=>c) ) => (a=>c)\n\n   Yacas can prove that is correct by applying :func:`CanProve` to it::\n\n        In> CanProve(( (a=>b) And (b=>c) ) => (a=>c))\n        Out> True;\n\n   It does this in the following way: in order to prove a proposition :math:`p`,\n   it suffices to prove that :math:`\\neg p` is false. It continues to simplify\n   :math:`\\neg p` using the rules:\n\n    * :math:`\\neg\\neg x \\to x` (eliminate double negation),\n    * :math:`x\\Rightarrow y \\to \\neg x \\vee y` (eliminate implication),\n    * :math:`\\neg (x \\wedge y) \\to \\neg x \\vee \\neg y` (`De Morgan's law`_),\n    * :math:`\\neg (x \\vee y) \\to \\neg x \\wedge \\neg y` (`De Morgan's law`_),\n    * :math:`(x \\wedge y) \\vee z \\to (x \\vee z) \\wedge (y \\vee z)` (distribution),\n    * :math:`x \\vee (y \\wedge z) \\to (x \\vee y) \\wedge (x \\vee z)` (distribution),\n\n   and the obvious other rules, such as, :math:`1 \\vee x \\to 1` etc. The above\n   rules will translate a proposition into a form::\n\n        (p1 Or p2 Or ...) And (q1 Or q2 Or ...) And ...\n\n   If any of the clauses is false, the entire expression will be false. In the\n   next step, clauses are scanned for situations of the form: :math:`(p \\vee Y)\n   \\wedge (\\neg p \\vee Z) \\to (Y \\vee Z)`. If this combination :math:`(Y\\vee Z)`\n   is empty, it is false, and thus the entire proposition is false. As a last\n   step, the algorithm negates the result again. This has the added advantage of\n   simplifying the expression further.\n\n   :Example:\n\n   ::\n\n      In> CanProve(a Or Not a)\n      Out> True;\n      In> CanProve(True Or a)\n      Out> True;\n      In> CanProve(False Or a)\n      Out> a;\n      In> CanProve(a And Not a)\n      Out> False;\n      In> CanProve(a Or b Or (a And b))\n      Out> a Or b;\n\n\n   .. seealso:: :func:`True`, :func:`False`, :func:`And`, :func:`Or`, :func:`Not`\n\n.. _De Morgan's law: https://en.wikipedia.org/wiki/De_Morgan%27s_laws\n"
  },
  {
    "path": "docs/reference_manual/misc.rst",
    "content": "=============\nMiscellaneous\n=============\n\n.. function:: Time(expr)\n\n   measure the time taken by a function\n\n   :param expr: any expression\n\n   The function :func:`Time` evaluates the expression ``expr`` and prints the\n   time in seconds needed for the evaluation. The time is printed to the current\n   output stream. The built-in function :func:`GetTime` is used for timing.\n\n   The result is the \"user time\" as reported by the OS, not the real (\"wall\n   clock\") time. Therefore, any CPU-intensive processes running alongside yacas\n   will not significantly affect the result of :func:`Time`.\n\n   :Example:\n\n   ::\n\n      In> Time(N(MathLog(1000),40))\n      0.34 seconds taken\n      Out> 6.9077552789821370520539743640530926228033;\n\n\n   .. seealso:: :func:`GetTime`\n\n\n.. function:: SystemCall(str)\n\n   pass a command to the shell\n\n   The command contained in the string ``str`` is executed by the underlying\n   operating system. The return value of :func:`SystemCall` is :const:`True` or\n   :const:`False` according to the exit code of the command.\n\n   The :func:`SystemCall` function is not allowed in the body of the\n   :func:`Secure` command.\n\n   In a UNIX environment, the command ``SystemCall(\"ls\")`` would print\n   the contents of the current directory::\n\n      In> SystemCall(\"ls\")\n      AUTHORS\n      COPYING\n      ChangeLog\n      ... (truncated to save space)\n      Out> True;\n\n   The standard UNIX command ``test`` returns success or failure\n   depending on conditions.  For example, the following command will\n   check if a directory exists::\n\n      In> SystemCall(\"test -d scripts/\")\n      Out> True;\n\n   Check that a file exists::\n\n      In> SystemCall(\"test -f COPYING\")\n      Out> True;\n      In> SystemCall(\"test -f nosuchfile.txt\")\n      Out> False;\n\n   .. seealso:: :func:`Secure`\n"
  },
  {
    "path": "docs/reference_manual/number-theory.rst",
    "content": "=============\nNumber theory\n=============\n\nThis chapter describes functions that are of interest in number\ntheory.  These functions typically operate on integers.  Some of these\nfunctions work quite slowly.\n\n\n.. function:: IsPrime(n)\n\n   test for a prime number\n\n   :param n: integer to test\n\n\n\n.. function:: IsComposite(n)\n\n   test for a composite number\n\n   :param n: positive integer\n\n\n\n.. function:: IsCoprime(m,n)\n\n   test if integers are coprime\n\n   :param m: positive integer\n   :param n: positive integer\n   :param list: list of positive integers\n\n\n\n.. function:: IsSquareFree(n)\n\n   test for a square-free number\n\n   :param n: positive integer\n\n\n\n.. function:: IsPrimePower(n)\n\n   test for a power of a prime number\n\n   :param n: integer to test\n\n\n\n.. function:: NextPrime(i)\n\n   generate a prime following a number\n\n   :param i: integer value\n\n\n\n.. function:: IsTwinPrime(n)\n\n   test for a twin prime\n\n   :param n: positive integer\n\n\n\n.. function:: IsIrregularPrime(n)\n\n   test for an irregular prime\n\n   :param n: positive integer\n\n\n\n.. function:: IsCarmichaelNumber(n)\n\n   test for a Carmichael number\n\n   :param n: positive integer\n\n\n\n.. function:: Factors(x)\n\n   factorization\n\n   :param x: integer or univariate polynomial\n\n\n\n.. function:: IsAmicablePair(m,n)\n\n   test for a pair of amicable numbers\n\n   :param m: positive integer\n   :param n: positive integer\n\n\n\n.. function:: Factor(x)\n\n   factorization, in pretty form\n\n   :param x: integer or univariate polynomial\n\n\n\n.. function:: Divisors(n)\n\n   number of divisors\n\n   :param n: positive integer\n\n\n\n.. function:: DivisorsSum(n)\n\n   the sum of  divisors\n\n   :param n: positive integer\n\n\n\n.. function:: ProperDivisors(n)\n\n   the number of proper divisors\n\n   :param n: positive integer\n\n\n\n.. function:: ProperDivisorsSum(n)\n\n   the sum of proper divisors\n\n   :param n: positive integer\n\n\n\n.. function:: Moebius(n)\n\n   the Moebius function\n\n   :param n: positive integer\n\n\n\n.. function:: CatalanNumber(n)\n\n   return the ``n``-th Catalan Number\n\n   :param n: positive integer\n\n\n\n.. function:: FermatNumber(n)\n\n   return the ``n``-th Fermat Number\n\n   :param n: positive integer\n\n\n\n.. function:: HarmonicNumber(n)\n\n   return the ``n``-th Harmonic Number\n\n   :param n: positive integer\n   :param r: positive integer\n\n\n\n.. function:: StirlingNumber1(n,m)\n\n   return the ``n,m``-th Stirling Number of the first kind\n\n   :param n: positive integers\n   :param m: positive integers\n\n\n\n.. function:: StirlingNumber1(n,m)\n\n   return the ``n,m``-th Stirling Number of the second kind\n\n   :param n: positive integer\n   :param m: positive integer\n\n\n\n.. function:: DivisorsList(n)\n\n   the list of divisors\n\n   :param n: positive integer\n\n\n\n.. function:: SquareFreeDivisorsList(n)\n\n   the list of square-free divisors\n\n   :param n: positive integer\n\n\n\n.. function:: MoebiusDivisorsList(n)\n\n   the list of divisors and Moebius values\n\n   :param n: positive integer\n\n\n\n.. function:: SumForDivisors(var,n,expr)\n\n   loop over divisors\n\n   :param var: atom, variable name\n   :param n: positive integer\n   :param expr: expression depending on ``var``\n\n\n\n.. function:: RamanujanSum(k,n)\n\n   compute the Ramanujan's sum\n\n   :param k: positive integer\n   :param n: positive integer\n\n   This function computes the Ramanujan's sum, i.e. the sum of the\n   ``n``-th powers of the ``k``-th primitive roots of the unit:\n\n   .. math:: \\sum_{l=1}^k\\frac{\\exp(2ln\\pi\\imath)}{k}\n \n   where :math:`l` runs thought the integers between 1 and ``k-1``\n   that are coprime to :math:`l`. The computation is done by using the\n   formula in T. M. Apostol, <i>Introduction to Analytic Theory</i>\n   (Springer-Verlag), Theorem 8.6.\n\n   .. todo:: check the definition\n\n\n.. function:: PAdicExpand(n, p)\n\n   p-adic expansion\n\n   :param n: number or polynomial to expand\n   :param p: base to expand in\n\n\n\n.. function:: IsQuadraticResidue(m,n)\n\n   functions related to finite groups\n\n   :param m: integer\n   :param n: odd positive integer\n\n\n\n.. function:: GaussianFactors(z)\n\n   factorization in Gaussian integers\n\n   :param z: Gaussian integer\n\n\n\n.. function:: GaussianNorm(z)\n\n   norm of a Gaussian integer\n\n   :param z: Gaussian integer\n\n\n\n.. function:: IsGaussianUnit(z)\n\n   test for a Gaussian unit\n\n   :param z: a Gaussian integer\n\n\n\n.. function:: IsGaussianPrime(z)\n\n   test for a Gaussian prime\n\n   :param z: a complex or real number\n\n\n\n.. function:: GaussianGcd(z,w)\n\n   greatest common divisor in Gaussian integers\n\n   :param z: Gaussian integer\n   :param w: Gaussian integer\n\n\n"
  },
  {
    "path": "docs/reference_manual/numerical-methods.rst",
    "content": "=================\nNumerical methods\n=================\n\n.. function:: bodied NIntegrate(expr, x, x0, x1)\n\n  numerical integration\n\n  :param x: integration variable\n  :param x0: lower integration limit\n  :param x1: upper integration limit\n  :param expr: integrand\n\n  Numerically integrate ``expr`` over ``x`` from ``x0`` to ``x1``.\n\n  .. seealso:: :func:`Integrate`\n"
  },
  {
    "path": "docs/reference_manual/ode.rst",
    "content": "======================\nDifferential Equations\n======================\n\nIn this chapter, some facilities for solving differential equations\nare described. Currently only simple equations without auxiliary\nconditions are supported.\n\n\n.. function:: OdeSolve(expr1==expr2)\n\n   general ODE solver\n\n   :param expr1,expr2: expressions containing a function to solve for\n\n   This function currently can solve second order homogeneous linear equations\n   with real constant  coefficient. The solution is returned with unique\n   constants  generated by {UniqueConstant}. The roots of the auxiliary\n   equation are used as the arguments of exponentials. If the roots are complex\n   conjugate  pairs, then the solution returned is in the form of exponentials,\n   sines  and cosines. First and second derivatives are entered as ``y'``,\n   ``y''``. Higher order derivatives  may be entered as ``y(n)``, where ``n``\n   is any positive integer.\n\n   :Example:\n\n   ::\n\n      In> OdeSolve( y'' + y == 0 )\n      Out> C42*Sin(x)+C43*Cos(x);\n      In> OdeSolve( 2*y'' + 3*y' + 5*y == 0 )\n      Out> Exp(((-3)*x)/4)*(C78*Sin(Sqrt(31/16)*x)+C79*Cos(Sqrt(31/16)*x));\n      In> OdeSolve( y'' - 4*y == 0 )\n      Out> C132*Exp((-2)*x)+C136*Exp(2*x);\n      In> OdeSolve( y'' +2*y' + y == 0 )\n      Out> (C183+C184*x)*Exp(-x);\n\n\n   .. seealso:: :func:`Solve`, :func:`RootsWithMultiples`\n\n\n.. function:: OdeTest(eqn,testsol)\n\n   test the solution of an ODE\n\n   :param eqn: equation to test\n   :param testsol: test solution\n\n   This function automates the verification of the solution of an ODE.\n   It can also be used to quickly see how a particular equation\n   operates  on a function.\n\n   :Example:\n\n   ::\n\n      In> OdeTest(y''+y,Sin(x)+Cos(x))\n      Out> 0;\n      In> OdeTest(y''+2*y,Sin(x)+Cos(x))\n      Out> Sin(x)+Cos(x);\n\n\n   .. seealso:: :func:`OdeSolve`\n\n\n.. function:: OdeOrder(eqn)\n\n   return order of an ODE\n\n   :param eqn: equation\n\n   This function returns the order of the differential equation, which\n   is  order of the highest derivative. If no derivatives appear, zero\n   is returned.\n\n   :Example:\n\n   ::\n\n      In> OdeOrder(y'' + 2*y' == 0)\n      Out> 2;\n      In> OdeOrder(Sin(x)*y(5) + 2*y' == 0)\n      Out> 5;\n      In> OdeOrder(2*y + Sin(y) == 0)\n      Out> 0;\n\n\n   .. seealso:: :func:`OdeSolve`\n\n.. function:: WronskianMatrix(func,var)\n\n   create the Wronskian matrix\n\n   :param func: an :math:`n`-dimensional vector of functions\n   :param var: a variable to differentiate with respect to\n\n   The function :func:`WronskianMatrix` calculates the `Wronskian matrix`_  of :math:`n`\n   functions. The Wronskian matrix is created by putting each function as the\n   first element of each column, and filling in the rest of each  column by the\n   :math:`(i-1)`-th derivative, where :math:`i` is the current row.    The\n   Wronskian matrix is used to verify that the :math:`n` functions are linearly\n   independent, usually solutions to a differential equation.  If the\n   determinant of the Wronskian matrix is zero, then the functions  are\n   dependent, otherwise they are independent.\n\n   :Example:\n\n   ::\n\n      In> WronskianMatrix({Sin(x),Cos(x),x^4},x);\n      Out> {{Sin(x),Cos(x),x^4},{Cos(x),-Sin(x),4*x^3},\n      {-Sin(x),-Cos(x),12*x^2}};\n      In> PrettyForm(%)\n      /                                                 \\\n      | ( Sin( x ) )      ( Cos( x ) )      /  4 \\      |\n      |                                     \\ x  /      |\n      |                                                 |\n      | ( Cos( x ) )      ( -( Sin( x ) ) ) /      3 \\  |\n      |                                     \\ 4 * x  /  |\n      |                                                 |\n      | ( -( Sin( x ) ) ) ( -( Cos( x ) ) ) /       2 \\ |\n      |                                     \\ 12 * x  / |\n      \\                                                 /\n\n   The last element is a linear combination of the first two, so the determinant is zero::\n\n      In> A:=Determinant( WronskianMatrix( {x^4,x^3,2*x^4+3*x^3},x ) )\n      Out> x^4*3*x^2*(24*x^2+18*x)-x^4*(8*x^3+9*x^2)*6*x\n      +(2*x^4+3*x^3)*4*x^3*6*x-4*x^6*(24*x^2+18*x)+x^3\n      *(8*x^3+9*x^2)*12*x^2-(2*x^4+3*x^3)*3*x^2*12*x^2;\n      In> Simplify(A)\n      Out> 0;\n\n.. _Wronskian matrix: https://en.wikipedia.org/wiki/Wronskian\n"
  },
  {
    "path": "docs/reference_manual/physics.rst",
    "content": "=======\nPhysics\n=======\n\nAssorted physics-related functions\n\nQuantum Physics\n^^^^^^^^^^^^^^^\n\n.. function:: ClebschGordan({j1,m1}, {j2,m2}, {J,M})\n\n   Clebsch-Gordan coefficient\n\n   Calculates the `Clebsch-Gordan coefficient`_ :math:`\\langle j_1m_1j_2m_2\\vert JM\\rangle`\n\n.. _Clebsch-Gordan coefficient: https://en.wikipedia.org/wiki/Clebsch%E2%80%93Gordan_coefficients\n"
  },
  {
    "path": "docs/reference_manual/plot.rst",
    "content": "========\nPlotting\n========\n\n\n.. function:: Plot2D(expr,[x0:x1],[option=value, [...]])\n              Plot2D({expr1, expr2, ..., exprn},[x0:x1],[option=value,[...]])\n\n   adaptive two-dimensional plotting\n\n   :param f(x): unevaluated expression containing one variables (function to be plotted)\n   :param list: list of functions to plot\n   :param a}, {b: numbers, plotting range in the :math:`x` coordinate\n   :param option: atom, option name\n   :param value: atom, number or string (value of option)\n\n   The routine :func:`Plot2D` performs adaptive plotting of one or several\n   functions  of one variable in the specified range.  The result is presented\n   as a line given by the equation :math:`y=f(x)`.  Several functions can be\n   plotted at once.  Various plotting options can be specified.  Output can be\n   directed to a plotting program (the default is to use  {data}) to a list of\n   values.    The function parameter {f(x)} must evaluate to a yacas expression\n   containing  at most one variable. (The variable does not have to be called\n   {x}.) Also, {N(f(x))} must evaluate to a real (not complex) numerical value\n   when given a numerical value of the argument {x}.  If the function {f(x)}\n   does not satisfy these requirements, an error is raised.    Several functions\n   may be specified as a list and they do not have to depend on the same\n   variable, for example, {{f(x), g(y)}}.  The functions will be plotted on the\n   same graph using the same coordinate ranges.    If you have defined a\n   function which accepts a number but does not  accept an undefined variable,\n   {Plot2D} will fail to plot it.  Use {NFunction} to overcome this difficulty.\n   Data files are created in a temporary directory {/tmp/plot.tmp/} unless\n   otherwise requested.  File names  and other information is printed if\n   {InVerboseMode()} returns :data:`True` on using {V()}.    The current\n   algorithm uses Newton-Cotes quadratures and some heuristics for error\n   estimation (see <*yacasdoc://Algo/3/1/*>).  The initial grid of {points+1}\n   points is refined between any grid points :math:`x0`, :math:`x1` if the\n   integral :math:`Integrate(x,a,b)f(x)` is not approximated to the given\n   precision by  the existing grid.    Default plotting range is {-5:5}. Range\n   can also be specified as {x= -5:5} (note the mandatory space separating \"{=}\"\n   and \"{-}\");  currently the variable name {x} is ignored in this case.\n   Options are of the form {option=value}. Currently supported option names\n   are: \"points\", \"precision\", \"depth\", \"output\", \"filename\", \"yrange\". Option\n   values  are either numbers or special unevaluated atoms such as {data}.  If\n   you need to use the names of these atoms  in your script, strings can be\n   used. Several option/value pairs may be specified (the function {Plot2D} has\n   a variable number of arguments).\n\n   * {yrange}: the range of ordinates to use for plotting, e.g.\n     {yrange=0:20}. If no range is specified, the default is usually\n     to leave the choice to the plotting backend.\n   * {points}: initial number of points (default 23) -- at least that\n     many points will be plotted. The initial grid of this many points\n     will be adaptively refined.\n   * {precision}: graphing precision (default :math:`10^(-6)`). This is\n     interpreted as the relative precision of computing the integral\n     of :math:`f(x)-Min(f(x))` using the grid points. For a smooth,\n     non-oscillating function this value should be roughly 1/(number\n     of screen pixels in the plot).\n   * {depth}: max. refinement depth, logarithmic (default 5) -- means\n     there will be at most :math:`2^depth` extra points per initial grid\n     point.\n   * {output}: name of the plotting backend. Supported names: {data}\n     (default).  The {data} backend will return the data as a list of\n     pairs such as {{{x1,y1}, {x2,y2}, ...}}.\n   * {filename}: specify name of the created data file. For example:\n     {filename=\"data1.txt\"}.  The default is the name {\"output.data\"}.\n     Note that if several functions are plotted, the data files will\n     have a number appended to the given name, for example\n     {data.txt1}, {data.txt2}.\n\n   Other options may be supported in the future.\n\n   The current implementation can deal with a singularity within the\n   plotting range only if the function {f(x)} returns {Infinity},\n   {-Infinity} or {Undefined} at the singularity.  If the function\n   {f(x)} generates a numerical error and fails at a singularity,\n   {Plot2D} will fail if one of the grid points falls on thez\n   singularity.  (All grid points are generated by bisection so in\n   principle the endpoints and the {points} parameter could be chosen\n   to avoid numerical singularities.)\n\n.. seealso:: :func:`V`, :func:`NFunction`, :func:`Plot3DS`\n\n.. function:: Plot3DS(expr,[option=value, [...]])\n              Plot3DS({expr1, expr2, ..., exprn},[option=value,[...]])\n\n   three-dimensional (surface) plotting\n\n   The routine :func:`Plot3DS` performs adaptive plotting of a function of two\n   variables in the specified ranges.  The result is presented as a surface\n   given by the equation :math:`z=f(x,y)`.  Several functions can be plotted at\n   once, by giving a list of functions.  Various plotting options can be\n   specified.  Output can be directed to a plotting program (the default is to\n   use  {data}), to a list of values.    The function parameter {f(x,y)} must\n   evaluate to a Yacas expression containing  at most two variables. (The\n   variables do not have to be called {x} and {y}.)  Also, {N(f(x,y))} must\n   evaluate to a real (not complex) numerical value when given numerical values\n   of the arguments {x}, {y}.  If the function {f(x,y)} does not satisfy these\n   requirements, an error is raised.    Several functions may be specified as a\n   list but they have to depend on the same symbolic variables, for example,\n   {{f(x,y), g(y,x)}}, but not {{f(x,y), g(a,b)}}.  The functions will be\n   plotted on the same graph using the same coordinate ranges.    If you have\n   defined a function which accepts a number but does not  accept an undefined\n   variable, {Plot3DS} will fail to plot it.  Use {NFunction} to overcome this\n   difficulty.    Data files are created in a temporary directory\n   {/tmp/plot.tmp/} unless otherwise requested.  File names  and other\n   information is printed if {InVerboseMode()} returns :data:`True` on using\n   {V()}.    The current algorithm uses Newton-Cotes cubatures and some\n   heuristics for error estimation (see <*yacasdoc://Algo/3/1/*>).  The initial\n   rectangular grid of {xpoints+1}*{ypoints+1} points is refined within any\n   rectangle where the integral  of :math:`f(x,y)` is not approximated to the\n   given precision by  the existing grid.    Default plotting range is {-5:5} in\n   both coordinates.  A range can also be specified with a variable name, e.g.\n   {x= -5:5} (note the mandatory space separating \"{=}\" and \"{-}\").  The\n   variable name {x} should be the same as that used in the function {f(x,y)}.\n   If ranges are not given with variable names, the first variable encountered\n   in the function {f(x,y)} is associated with the first of the two ranges.\n   Options are of the form {option=value}. Currently supported option names are\n   \"points\", \"xpoints\", \"ypoints\", \"precision\", \"depth\", \"output\", \"filename\",\n   \"xrange\", \"yrange\", \"zrange\". Option values  are either numbers or special\n   unevaluated atoms such as {data}.  If you need to use the names of these\n   atoms  in your script, strings can be used (e.g. {output=\"data\"}). Several\n   option/value pairs may be specified (the function {Plot3DS} has a variable\n   number of arguments).\n\n   * {xrange}, {yrange}: optionally override coordinate ranges. Note\n     that {xrange} is always the first variable and {yrange} the\n     second variable, regardless of the actual variable names.\n   * {zrange}: the range of the :math:`z` axis to use for plotting, e.g.\n     {zrange=0:20}. If no range is specified, the default is usually\n     to leave the choice to the plotting backend. Automatic choice\n     based on actual values may give visually inadequate plots if the\n     function has a singularity.\n   * {points}, {xpoints}, {ypoints}: initial number of points (default\n     10 each) -- at least that many points will be plotted in each\n     coordinate.  The initial grid of this many points will be\n     adaptively refined.  If {points} is specified, it serves as a\n     default for both {xpoints} and {ypoints}; this value may be\n     overridden by {xpoints} and {ypoints} values.\n   * {precision}: graphing precision (default :math:`0.01`). This is\n     interpreted as the relative precision of computing the integral\n     of :math:`f(x,y)-Min(f(x,y))` using the grid points. For a smooth,\n     non-oscillating function this value should be roughly 1/(number\n     of screen pixels in the plot).\n   * {depth}: max. refinement depth, logarithmic (default 3) -- means\n     there will be at most :math:`2^depth` extra points per initial grid\n     point (in each coordinate).\n   * {output}: name of the plotting backend. Supported names: {data}\n     (default). The {data} backend will return the data as a list of\n     triples such as {{{x1, y1, z1}, {x2, y2, z2}, ...}}.\n\n   Other options may be supported in the future.\n\n   The current implementation can deal with a singularity within the\n   plotting range only if the function {f(x,y)} returns {Infinity},\n   {-Infinity} or {Undefined} at the singularity.  If the function\n   {f(x,y)} generates a numerical error and fails at a singularity,\n   {Plot3DS} will fail only if one of the grid points falls on the\n   singularity.  (All grid points are generated by bisection so in\n   principle the endpoints and the {xpoints}, {ypoints} parameters\n   could be chosen to avoid numerical singularities.)\n\n   The {filename} option is optional if using graphical backends, but\n   can be used to specify the location of the created data file.\n\n   :Example:\n\n   ::\n\n      In> Plot3DS(a*b^2)\n      Out> True;\n      In> V(Plot3DS(Sin(x)*Cos(y),x=0:20, y=0:20,depth=3))\n      CachedConstant: Info: constant Pi is being\n      recalculated at precision 10\n      CachedConstant: Info: constant Pi is being\n      recalculated at precision 11\n      Plot3DS: using 1699  points for function Sin(x)*Cos(y)\n      Plot3DS: max. used 8 subdivisions for Sin(x)*Cos(y)\n      Plot3DS'datafile: created file '/tmp/plot.tmp/data1'\n      Out> True;\n\n.. seealso:: :func:`V`, :func:`NFunction`, :func:`Plot2D`\n"
  },
  {
    "path": "docs/reference_manual/predicates.rst",
    "content": "==========\nPredicates\n==========\n\nA predicate is a function that returns a boolean value, i.e. :data:`True` or\n:data:`False`. Predicates are often used in patterns, For instance, a rule\nthat only holds for a positive integer would use a pattern such as\n{n_IsPositiveInteger}.\n\n.. function:: e1 != e2\n\n   test for \"not equal\"\n\n   :param e1}, {e2: expressions to be compared\n\n   Both expressions are evaluated and compared. If they turn out to be\n   equal, the result is :data:`False`. Otherwise, the result  is :data:`True`.\n   The expression {e1 != e2} is equivalent to {Not(e1 = e2)}.\n\n   :Example:\n\n   ::\n\n      In> 1 != 2;\n      Out> True;\n      In> 1 != 1;\n      Out> False;\n\n\n   .. seealso:: :func:`=`\n\n.. function:: e1 = e2\n\n   test for equality of expressions\n\n   :param e1, e2: expressions to be compared\n\n   Both expressions are evaluated and compared. If they turn out to be\n   equal, the  result is :data:`True`. Otherwise, the result is :data:`False`. The\n   function {Equals} does  the same.    Note that the test is on\n   syntactic equality, not mathematical equality. Hence  even if the\n   result is :data:`False`, the expressions can still be\n   *mathematically* equal; see the examples below. Put otherwise,\n   this  function tests whether the two expressions would be displayed\n   in the same way  if they were printed.\n\n   :Example:\n\n   ::\n\n      In> e1 := (x+1) * (x-1);\n      Out> (x+1)*(x-1);\n      In> e2 := x^2 - 1;\n      Out> x^2-1;\n      In> e1 = e2;\n      Out> False;\n      In> Expand(e1) = e2;\n      Out> True;\n\n\n   .. seealso:: :func:`!=`, :func:`Equals`\n\n.. function:: Not(expr)\n              prefix Not(expr)\n\n   logical negation\n\n   :param expr: a boolean expression\n\n   Not returns the logical negation of the argument expr. If ``expr`` is\n   :data:`False` it returns :data:`True`, and if ``expr`` is :data:`True`, {Not expr}\n   returns :data:`False`.  If the argument is neither :data:`True` nor :data:`False`, it\n   returns the entire  expression with evaluated arguments.\n\n   :Example:\n\n   ::\n\n      In> Not True\n      Out> False;\n      In> Not False\n      Out> True;\n      In> Not(a)\n      Out> Not a;\n\n\n   .. seealso:: :func:`And`, :func:`Or`\n\n.. function:: a1 And a2\n\n   logical conjunction\n\n   :param a}1, ..., {a}: boolean values (may evaluate to :data:`True` or :data:`False`)\n\n   This function returns :data:`True` if all arguments are true. The  {And}\n   operation is \"lazy\", i.e. it returns :data:`False` as soon as a :data:`False`\n   argument  is found (from left to right). If an argument other than\n   :data:`True` or  :data:`False` is encountered a new {And} expression is\n   returned with all  arguments that didn't evaluate to :data:`True` or\n   :data:`False` yet.\n\n   :Example:\n\n   ::\n\n      In> True And False\n      Out> False;\n      In> And(True,True)\n      Out> True;\n      In> False And a\n      Out> False;\n      In> True And a\n      Out> And(a);\n      In> And(True,a,True,b)\n      Out> b And a;\n\n\n   .. seealso:: :func:`Or`, :func:`Not`\n\n.. function:: a1 Or a2\n\n   logical disjunction\n\n   :param a}1, ..., {a}: boolean expressions (may evaluate to :data:`True` or :data:`False`)\n\n   This function returns :data:`True` if an argument is encountered  that is\n   true (scanning from left to right). The  {Or} operation is \"lazy\",\n   i.e. it returns :data:`True` as soon as a :data:`True` argument  is found (from\n   left to right). If an argument other than :data:`True` or  :data:`False` is\n   encountered, an unevaluated {Or} expression is returned with all\n   arguments that didn't evaluate to :data:`True` or :data:`False` yet.\n\n   :Example:\n\n   ::\n\n      In> True Or False\n      Out> True;\n      In> False Or a\n      Out> Or(a);\n      In> Or(False,a,b,True)\n      Out> True;\n\n\n   .. seealso:: :func:`And`, :func:`Not`\n\n.. function:: IsFreeOf(var, expr)\n\n   test whether expression depends on variable\n\n   :param expr: expression to test\n   :param var: variable to look for in \"expr\"\n\n   This function checks whether the expression \"expr\" (after being\n   evaluated) depends on the variable \"var\". It returns :data:`False` if\n   this is the case and :data:`True`  otherwise.    The second form test\n   whether the expression depends on *any* of  the variables\n   named in the list. The result is :data:`True` if none of the variables\n   appear in the expression and :data:`False` otherwise.\n\n   :Example:\n\n   ::\n\n      In> IsFreeOf(x, Sin(x));\n      Out> False;\n      In> IsFreeOf(y, Sin(x));\n      Out> True;\n      In> IsFreeOf(x, D(x) a*x+b);\n      Out> True;\n      In> IsFreeOf({x,y}, Sin(x));\n      Out> False;\n      The third command returns :data:`True` because the\n      expression {D(x) a*x+b} evaluates to {a}, which does not depend on {x}.\n\n\n   .. seealso:: :func:`Contains`\n\n.. function:: IsZeroVector(list)\n\n   test whether list contains only zeroes\n\n   :param list: list to compare against the zero vector\n\n   The only argument given to {IsZeroVector} should be  a list. The\n   result is :data:`True` if the list contains  only zeroes and :data:`False`\n   otherwise.\n\n   :Example:\n\n   ::\n\n      In> IsZeroVector({0, x, 0});\n      Out> False;\n      In> IsZeroVector({x-x, 1 - D(x) x});\n      Out> True;\n\n\n   .. seealso:: :func:`IsList`, :func:`ZeroVector`\n\n.. function:: IsNonObject(expr)\n\n   test whether argument is not an {Object()}\n\n   :param expr: the expression to examine\n\n   This function returns :data:`True` if \"expr\" is not of  the form\n   {Object(...)} and :data:`False`  otherwise.\n\n.. function:: IsEven(n)\n\n   test for an even integer\n\n   :param n: integer to test\n\n   This function tests whether the integer \"n\" is even. An integer is\n   even if it is divisible by two. Hence the even numbers are 0, 2, 4,\n   6,  8, 10, etc., and -2, -4, -6, -8, -10, etc.\n\n   :Example:\n\n   ::\n\n      In> IsEven(4);\n      Out> True;\n      In> IsEven(-1);\n      Out> False;\n\n\n   .. seealso:: :func:`IsOdd`, :func:`IsInteger`\n\n.. function:: IsOdd(n)\n\n   test for an odd integer\n\n   :param n: integer to test\n\n   This function tests whether the integer \"n\" is odd. An integer is\n   odd if it is not divisible by two. Hence the odd numbers are 1, 3,\n   5,  7, 9, etc., and -1, -3, -5, -7, -9, etc.\n\n   :Example:\n\n   ::\n\n      In> IsOdd(4);\n      Out> False;\n      In> IsOdd(-1);\n      Out> True;\n\n\n   .. seealso:: :func:`IsEven`, :func:`IsInteger`\n\n.. function:: IsEvenFunction(expression,variable)\n\n   Return true if function is an even function, False otherwise\n\n   :param expression: mathematical expression\n   :param variable: variable\n\n   These functions return :data:`True` if yacas can determine that the\n   function is even or odd respectively. Even functions are  defined\n   to be functions that have the property:    :math:`f(x) = f(-x)`\n   And odd functions have the property: :math:`f(x) = -f(-x)`.\n   :math:`\\sin(x)` is an example of an odd function, and :math:`cos(x)`\n   is an example of an even function.\n\n\n   .. note::\n\n      One can decompose a function into an  even and an odd part\n      :math:`f(x) = f_{even}(x) + f_{odd}(x)` where\n      :math:`f_{even}(x) = \\frac{f(x)+f(-x)}{2}` and\n      :math:`f_{odd}(x) = \\frac{f(x)-f(-x)}{2}`\n\n.. function:: IsFunction(expr)\n\n   test for a composite object\n\n   This function tests whether ``expr`` is a composite object, i.e. not\n   an  atom. This includes not only obvious functions such as ``f(x)``,\n   but also expressions such as ``x+5`` and lists.\n\n   :Example:\n\n   ::\n\n      In> IsFunction(x+5);\n      Out> True;\n      In> IsFunction(x);\n      Out> False;\n\n\n   .. seealso:: :func:`IsAtom`, :func:`IsList`, :func:`Type`\n\n.. function:: IsAtom(expr)\n\n   test for an atom\n\n   This function tests whether ``expr`` is an atom. Numbers, strings,\n   and  variables are all atoms.\n\n   :Example:\n\n   ::\n\n      In> IsAtom(x+5);\n      Out> False;\n      In> IsAtom(5);\n      Out> True;\n\n\n   .. seealso:: :func:`IsFunction`, :func:`IsNumber`, :func:`IsString`\n\n.. function:: IsString(expr)\n\n   test for an string\n\n   :param expr: expression to test\n\n   This function tests whether \"expr\" is a string. A string is a text\n   within quotes, e.g. {\"duh\"}.\n\n   :Example:\n\n   ::\n\n      In> IsString(\"duh\");\n      Out> True;\n      In> IsString(duh);\n      Out> False;\n\n\n   .. seealso:: :func:`IsAtom`, :func:`IsNumber`\n\n.. function:: IsNumber(expr)\n\n   test for a number\n\n   :param expr: expression to test\n\n   This function tests whether \"expr\" is a number. There are two kinds\n   of numbers, integers (e.g. 6) and reals (e.g. -2.75 or 6.0). Note\n   that a  complex number is represented by the {Complex}  function,\n   so {IsNumber} will return :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsNumber(6);\n      Out> True;\n      In> IsNumber(3.25);\n      Out> True;\n      In> IsNumber(I);\n      Out> False;\n      In> IsNumber(\"duh\");\n      Out> False;\n\n\n   .. seealso:: :func:`IsAtom`, :func:`IsString`, :func:`IsInteger`, :func:`IsPositiveNumber`, :func:`IsNegativeNumber`, :func:`Complex`\n\n.. function:: IsList(expr)\n\n   test for a list\n\n   :param expr: expression to test\n\n   This function tests whether \"expr\" is a list. A list is a sequence\n   between curly braces, e.g. {{2, 3, 5}}.\n\n   :Example:\n\n   ::\n\n      In> IsList({2,3,5});\n      Out> True;\n      In> IsList(2+3+5);\n      Out> False;\n\n\n   .. seealso:: :func:`IsFunction`\n\n.. function:: IsNumericList({list})\n\n   test for a list of numbers\n\n   :param {list}: a list\n\n   Returns :data:`True` when called on a list of numbers or expressions that\n   evaluate to numbers using {N()}. Returns :data:`False` otherwise.\n\n   .. seealso:: :func:`N`, :func:`IsNumber`\n\n.. function:: IsBound(var)\n\n   test for a bound variable\n\n   :param var: variable to test\n\n   This function tests whether the variable \"var\" is bound, i.e.\n   whether  it has been assigned a value. The argument \"var\" is not\n   evaluated.\n\n   :Example:\n\n   ::\n\n      In> IsBound(x);\n      Out> False;\n      In> x := 5;\n      Out> 5;\n      In> IsBound(x);\n      Out> True;\n\n\n   .. seealso:: :func:`IsAtom`\n\n.. function:: IsBoolean(expression)\n\n   test for a Boolean value\n\n   :param expression: an expression\n\n   IsBoolean returns True if the argument is of a boolean type.  This\n   means it has to be either True, False, or an expression involving\n   functions that return a boolean result, e.g.  {=}, {>}, {<}, {>=},\n   {<=}, {!=}, {And}, {Not}, {Or}.\n\n   :Example:\n\n   ::\n\n      In> IsBoolean(a)\n      Out> False;\n      In> IsBoolean(True)\n      Out> True;\n      In> IsBoolean(a And b)\n      Out> True;\n\n\n   .. seealso:: :func:`True`, :func:`False`\n\n.. function:: IsNegativeNumber(n)\n\n   test for a negative number\n\n   :param n: number to test\n\n   {IsNegativeNumber(n)} evaluates to :data:`True` if :math:`n` is (strictly)\n   negative, i.e.  if :math:`n<0`. If {n} is not a number, the functions\n   return :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsNegativeNumber(6);\n      Out> False;\n      In> IsNegativeNumber(-2.5);\n      Out> True;\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsPositiveNumber`, :func:`IsNotZero`, :func:`IsNegativeInteger`, :func:`IsNegativeReal`\n\n.. function:: IsNegativeInteger(n)\n\n   test for a negative integer\n\n   :param n: integer to test\n\n   This function tests whether the integer {n} is (strictly)\n   negative. The negative integers are -1, -2, -3, -4, -5, etc. If\n   {n} is not a integer, the function returns :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsNegativeInteger(31);\n      Out> False;\n      In> IsNegativeInteger(-2);\n      Out> True;\n\n\n   .. seealso:: :func:`IsPositiveInteger`, :func:`IsNonZeroInteger`, :func:`IsNegativeNumber`\n\n.. function:: IsPositiveNumber(n)\n\n   test for a positive number\n\n   :param n: number to test\n\n   {IsPositiveNumber(n)} evaluates to :data:`True` if :math:`n` is (strictly)\n   positive, i.e.  if :math:`n>0`. If {n} is not a number the function\n   returns :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsPositiveNumber(6);\n      Out> True;\n      In> IsPositiveNumber(-2.5);\n      Out> False;\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsNegativeNumber`, :func:`IsNotZero`, :func:`IsPositiveInteger`, :func:`IsPositiveReal`\n\n.. function:: IsPositiveInteger(n)\n\n   test for a positive integer\n\n   :param n: integer to test\n\n   This function tests whether the integer {n} is (strictly) positive.\n   The  positive integers are 1, 2, 3, 4, 5, etc. If {n} is not a\n   integer, the  function returns :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsPositiveInteger(31);\n      Out> True;\n      In> IsPositiveInteger(-2);\n      Out> False;\n\n\n   .. seealso:: :func:`IsNegativeInteger`, :func:`IsNonZeroInteger`, :func:`IsPositiveNumber`\n\n.. function:: IsNotZero(n)\n\n   test for a nonzero number\n\n   :param n: number to test\n\n   {IsNotZero(n)} evaluates to :data:`True` if {n} is not zero. In case {n}\n   is not a  number, the function returns :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsNotZero(3.25);\n      Out> True;\n      In> IsNotZero(0);\n      Out> False;\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsPositiveNumber`, :func:`IsNegativeNumber`, :func:`IsNonZeroInteger`\n\n.. function:: IsNonZeroInteger(n)\n\n   test for a nonzero integer\n\n   :param n: integer to test\n\n   This function tests whether the integer {n} is not zero. If {n} is\n   not an integer, the result is :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsNonZeroInteger(0)\n      Out> False;\n      In> IsNonZeroInteger(-2)\n      Out> True;\n\n\n   .. seealso:: :func:`IsPositiveInteger`, :func:`IsNegativeInteger`, :func:`IsNotZero`\n\n.. function:: IsInfinity(expr)\n\n   test for an infinity\n\n   :param expr: expression to test\n\n   This function tests whether {expr} is an infinity. This is only the\n   case if {expr} is either {Infinity} or {-Infinity}.\n\n   :Example:\n\n   ::\n\n      In> IsInfinity(10^1000);\n      Out> False;\n      In> IsInfinity(-Infinity);\n      Out> True;\n\n\n   .. seealso:: :func:`Integer`\n\n.. function:: IsPositiveReal(expr)\n\n   test for a numerically positive value\n\n   :param expr: expression to test\n\n   This function tries to approximate \"expr\" numerically. It returns\n   :data:`True` if this approximation is positive. In case no  approximation\n   can be found, the function returns :data:`False`. Note that round-off\n   errors may cause incorrect  results.\n\n   :Example:\n\n   ::\n\n      In> IsPositiveReal(Sin(1)-3/4);\n      Out> True;\n      In> IsPositiveReal(Sin(1)-6/7);\n      Out> False;\n      In> IsPositiveReal(Exp(x));\n      Out> False;\n      The last result is because {Exp(x)} cannot be\n      numerically approximated if {x} is not known. Hence\n      Yacas can not determine the sign of this expression.\n\n\n   .. seealso:: :func:`IsNegativeReal`, :func:`IsPositiveNumber`, :func:`N`\n\n.. function:: IsNegativeReal(expr)\n\n   test for a numerically negative value\n\n   :param expr: expression to test\n\n   This function tries to approximate {expr} numerically. It returns\n   :data:`True` if this approximation is negative. In case no  approximation\n   can be found, the function returns :data:`False`. Note that round-off\n   errors may cause incorrect  results.\n\n   :Example:\n\n   ::\n\n      In> IsNegativeReal(Sin(1)-3/4);\n      Out> False;\n      In> IsNegativeReal(Sin(1)-6/7);\n      Out> True;\n      In> IsNegativeReal(Exp(x));\n      Out> False;\n      The last result is because {Exp(x)} cannot be\n      numerically approximated if {x} is not known. Hence\n      Yacas can not determine the sign of this expression.\n\n\n   .. seealso:: :func:`IsPositiveReal`, :func:`IsNegativeNumber`, :func:`N`\n\n.. function:: IsConstant(expr)\n\n   test for a constant\n\n   :param expr: some expression\n\n   {IsConstant} returns :data:`True` if the  expression is some constant or\n   a function with constant arguments. It  does this by checking that\n   no variables are referenced in the  expression. {Pi} is considered\n   a constant.\n\n   :Example:\n\n   ::\n\n      In> IsConstant(Cos(x))\n      Out> False;\n      In> IsConstant(Cos(2))\n      Out> True;\n      In> IsConstant(Cos(2+x))\n      Out> False;\n\n\n   .. seealso:: :func:`IsNumber`, :func:`IsInteger`, :func:`VarList`\n\n.. function:: IsGaussianInteger(z)\n\n    test for a Gaussian integer\n\n   :param z: a complex or real number\n\n   This function returns :data:`True` if the argument is a Gaussian integer\n   and :data:`False` otherwise.  A Gaussian integer is a generalization  of\n   integers into the complex plane. A complex number :math:`a+b*I` is a\n   Gaussian  integer if and only if :math:`a` and :math:`b` are integers.\n\n   :Example:\n\n   ::\n\n      In> IsGaussianInteger(5)\n      Out> True;\n      In> IsGaussianInteger(5+6*I)\n      Out> True;\n      In> IsGaussianInteger(1+2.5*I)\n      Out> False;\n\n\n   .. seealso:: :func:`IsGaussianUnit`, :func:`IsGaussianPrime`\n\n.. function:: MatchLinear(x,expr)\n\n   match an expression to a polynomial of degree one in a variable\n\n   :param x: variable to express the univariate polynomial in\n   :param expr: expression to match\n\n   {MatchLinear} tries to match an expression to a linear (degree less\n   than  two) polynomial. The function returns :data:`True` if it could\n   match, and  it stores the resulting coefficients in the variables\n   \"{a}\" and \"{b}\"  as a side effect. The function calling this\n   predicate should declare  local variables \"{a}\" and \"{b}\" for this\n   purpose.  {MatchLinear} tries to match to constant coefficients\n   which don't  depend on the variable passed in, trying to find a\n   form \"{a*x+b}\"  with \"{a}\" and \"{b}\" not depending on {x} if {x} is\n   given as the variable.\n\n   :Example:\n\n   ::\n\n      In> MatchLinear(x,(R+1)*x+(T-1))\n      Out> True;\n      In> {a,b};\n      Out> {R+1,T-1};\n      In> MatchLinear(x,Sin(x)*x+(T-1))\n      Out> False;\n\n\n   .. seealso:: :func:`Integrate`\n\n.. function:: HasExpr(expr, x)\n\n   check for expression containing a subexpression\n\n   :param expr: an expression\n   :param x: a subexpression to be found\n   :param list: list of function atoms to be considered \"transparent\"\n\n   The command {HasExpr} returns :data:`True` if the expression {expr}\n   contains a literal subexpression {x}. The expression is recursively\n   traversed.    The command {HasExprSome} does the same, except it\n   only looks at arguments of a given {list} of functions. All other\n   functions become \"opaque\" (as if they do not contain anything).\n   {HasExprArith} is defined through {HasExprSome} to look only at\n   arithmetic operations {+}, {-}, {*}, {/}.    Note that since the\n   operators \"{+}\" and \"{-}\" are prefix as well as infix operators, it\n   is currently required to use {Atom(\"+\")} to obtain the unevaluated\n   atom \"{+}\".\n\n   :Example:\n\n   ::\n\n      In> HasExpr(x+y*Cos(Ln(z)/z), z)\n      Out> True;\n      In> HasExpr(x+y*Cos(Ln(z)/z), Ln(z))\n      Out> True;\n      In> HasExpr(x+y*Cos(Ln(z)/z), z/Ln(z))\n      Out> False;\n      In> HasExprArith(x+y*Cos(Ln(x)/x), z)\n      Out> False;\n      In> HasExprSome({a+b*2,c/d},c/d,{List})\n      Out> True;\n      In> HasExprSome({a+b*2,c/d},c,{List})\n      Out> False;\n\n\n   .. seealso:: :func:`FuncList`, :func:`VarList`, :func:`HasFunc`\n\n.. function:: HasFunc(expr, func)\n\n   check for expression containing a function\n\n   :param expr: an expression\n   :param func: a function atom to be found\n   :param list: list of function atoms to be considered \"transparent\"\n\n   The command {HasFunc} returns :data:`True` if the expression {expr}\n   contains a function {func}. The expression is recursively\n   traversed.    The command {HasFuncSome} does the same, except it\n   only looks at arguments of a given {list} of functions. Arguments\n   of all other functions become \"opaque\" (as if they do not contain\n   anything).    {HasFuncArith} is defined through {HasFuncSome} to\n   look only at arithmetic operations {+}, {-}, {*}, {/}.    Note that\n   since the operators \"{+}\" and \"{-}\" are prefix as well as infix\n   operators, it is currently required to use {Atom(\"+\")} to obtain\n   the unevaluated atom \"{+}\".\n\n   :Example:\n\n   ::\n\n      In> HasFunc(x+y*Cos(Ln(z)/z), Ln)\n      Out> True;\n      In> HasFunc(x+y*Cos(Ln(z)/z), Sin)\n      Out> False;\n      In> HasFuncArith(x+y*Cos(Ln(x)/x), Cos)\n      Out> True;\n      In> HasFuncArith(x+y*Cos(Ln(x)/x), Ln)\n      Out> False;\n      In> HasFuncSome({a+b*2,c/d},/,{List})\n      Out> True;\n      In> HasFuncSome({a+b*2,c/d},*,{List})\n      Out> False;\n\n\n   .. seealso:: :func:`FuncList`, :func:`VarList`, :func:`HasExpr`\n\n"
  },
  {
    "path": "docs/reference_manual/probability-and-statistics.rst",
    "content": "==========================\nProbability and Statistics\n==========================\n\nProbability\n-----------\n\nDistributions\n^^^^^^^^^^^^^\n\nEach distribution is represented as an entity. For each distribution known to\nthe system the consistency of parameters is checked. If the parameters for a\ndistribution are invalid, the functions return :const:`Undefined`. For example,\n``NormalDistribution(a,-1)`` evaluates to :const:`Undefined`, because of\nnegative variance.\n\n.. function:: BernoulliDistribution(p)\n\n   Bernoulli distribution\n\n   :param p: number, probability of an event in a single trial\n\n   A random variable has a `Bernoulli distribution`_ with probability ``p`` if\n   it can be interpreted as an indicator of an event, where ``p`` is the\n   probability to observe the event in a single trial. Numerical value of ``p``\n   must satisfy ``0 < p < 1``.\n\n   .. seealso:: :func:`BinomialDistribution`\n\n.. _`Bernoulli distribution`: https://en.wikipedia.org/wiki/Bernoulli_distribution\n\n.. function:: BinomialDistribution(p,n)\n\n   binomial distribution\n\n   :param p: number, probability to observe an event in single trial\n   :param n: number of trials\n\n   Suppose we repeat a trial ``n`` times, the probability to observe an event in\n   a single trial is ``p`` and outcomes in all trials are mutually independent.\n   Then the number of trials when the event occurred is distributed according to\n   the `binomial distribution`_. The probability of that is\n   ``BinomialDistribution(p,n)``. Numerical value of ``p`` must satisfy ``0 < p\n   < 1``. Numerical value of ``n`` must be a positive integer.\n\n   .. seealso:: :func:`BernoulliDistribution`\n\n.. _`binomial distribution`: https://en.wikipedia.org/wiki/Binomial_distribution\n\n.. function:: ChiSquareDistribution(m)\n\n.. function:: DiscreteUniformDistribution(a, b)\n\n.. function:: ExponentialDistribution(l)\n\n.. function:: GeometricDistribution(p)\n\n.. function:: NormalDistribution(m, s2)\n\n.. function:: PoissonDistribution(l)\n\n\n.. function:: tDistribution(m)\n\n   Student's :math:`t` distribution\n\n   :param m: number of degrees of freedom\n\nFunctions\n^^^^^^^^^\n\n.. function:: CDF(dist,x)\n\n   cumulative density function\n\n   .. seealso:: :func:`PDF`\n\n\n.. function:: PDF(dist,x)\n\n   probability density function\n\n   :param dist: a distribution type\n   :param x: a value of random variable\n\n   If ``dist`` is a discrete distribution, then :func:`PDF` returns the\n   probability for a random variable with distribution ``dist`` to take\n   a  value of ``x``. If ``dist`` is a continuous distribution, then ``PDF``\n   returns the density function at point ``x``.\n\n   .. seealso:: :func:`CDF`\n\nStatistics\n----------\n\n\n.. function:: ChiSquareTest(observed,expected,params)\n\n   Pearson's ChiSquare test\n\n   :param observed: list of observed frequencies\n   :param expected: list of expected frequencies\n   :param params: number of estimated parameters\n\n   `Chi-squared test`_ is intended to find out if our sample was drawn from a\n   given distribution or not. To find this out, one has to calculate observed\n   frequencies into certain intervals and expected ones. To calculate expected\n   frequency the formula :math:`n_i=n p_i` must be used, where :math:`p_i` is\n   the probability measure of :math:`i`-th interval, and :math:`n` is the total\n   number of observations. If any of the parameters of the distribution were\n   estimated, this number is given as ``params``.  The function returns a list\n   of three local substitution rules. First of them contains the test statistic,\n   the second contains the value of the parameters, and the last one contains\n   the degrees of freedom. The test statistic is distributed as\n   :func:`ChiSquareDistribution`.\n\n.. _`Chi-squared test`: https://en.wikipedia.org/wiki/Chi-squared_test\n"
  },
  {
    "path": "docs/reference_manual/programming.rst",
    "content": "=========================================\nFunctions related to programming in Yacas\n=========================================\n\nIntroduction\n------------\n\nThis document aims to be a reference for functions that are useful\nwhen programming in yacas, but which are not necessarily useful when\nusing yacas. There is another document that describes the functions\nthat are useful from a users point of view.\n\nProgramming\n-----------\n\nThis chapter describes functions useful for writing yacas scripts.\n\n::\n\n   /* --- Start of comment\n   */ --- end of comment\n   // --- Beginning of one-line comment\n\n    /* comment */\n    // comment\n\nIntroduce a comment block in a source file, similar to C++ comments.\n``//`` makes everything until the end of the line a comment, while ``/*``\nand ``*/`` may delimit a multi-line comment.\n\n:Example:\n\n::\n\n   a+b; // get result\n   a + /* add them */ b;\n\n\n.. function:: Prog(expr1, expr2, ...)\n\n   block of statements\n\n   The :func:`Prog` and the ``[ ... ]`` construct have the same effect: they\n   evaluate all arguments in order and return the result of the last evaluated\n   expression.\n\n   ``Prog(a,b);`` is the same as typing ``[a;b;];`` and is very useful for\n   writing out function bodies. The ``[ ... ]`` construct is a syntactically\n   nicer version of the :func:`Prog` call; it is converted into ``Prog(...)``\n   during the parsing stage.\n\n\n\n.. function:: Bodied(op, precedence)\n\n   declare ``op`` as :term:`bodied function`\n\n   Declares a special syntax for the function to be parsed as a\n   :term:`bodied function`. For example::\n\n     For(pre, condition, post) statement;\n\n   Here the function :func:`For` has 4 arguments and the last argument is placed\n   outside the parentheses.\n\n   The ``precedence`` of a :term:`bodied function` refers to how tightly the\n   last argument is bound to the parentheses.  This makes a difference when the\n   last argument contains other operators. For example, when taking the\n   derivative ``D(x) Sin(x)+Cos(x)`` both :func:`Sin` and :func:`Cos` are under\n   the derivative because the bodied function :func:`D` binds less tightly than the\n   infix operator ``+``.\n\n   .. seealso:: :func:`IsBodied`, :func:`OpPrecedence`\n\n.. function:: Infix(op[, precedence])\n\n   declare ``op`` as infix operator\n\n   Declares a special syntax for the function ``op`` to be parsed as an infix\n   operator. Precedence is optional (will be set to 0 by default).\n\n   Infix functions must have two arguments and are syntactically placed between\n   their arguments.  Names of infix functions can be arbitrary, although for\n   reasons of readability they are usually made of non-alphabetic characters.\n\n   .. seealso:: :func:`IsBodied`, :func:`OpPrecedence`\n\n.. function:: Postfix(op[, precedence])\n\n   declare ``op`` as postfix operator\n\n   Declares a special syntax for the function ``op`` to be parsed as a  postfix\n   operator. Precedence is optional (will be set to 0 by default).\n\n   Postfix functions must have one argument and are syntactically placed after\n   their argument.\n\n   .. seealso:: :func:`IsBodied`, :func:`OpPrecedence`\n\n.. function:: Prefix(op[, precedence])\n\n   declare ``op`` as postfix operator\n\n   Declares a special syntax for the function ``op`` to be parsed as a prefix\n   operator. Precedence is optional (will be set to 0 by default).\n\n   Prefix functions must have one argument and are syntactically placed before\n   their argument. Function name can be any string but meaningful usage and\n   readability would require it to be either made up entirely of letters or\n   entirely of non-letter characters (such as \"+\", \":\" etc.).\n\n   :Example:\n\n   ::\n\n      In> YY x := x+1;\n      CommandLine(1) : Error parsing expression\n\n      In> Prefix(\"YY\", 2)\n      Out> True;\n      In> YY x := x+1;\n      Out> True;\n      In> YY YY 2*3\n      Out> 12;\n      In> Infix(\"##\", 5)\n      Out> True;\n      In> a ## b ## c\n      Out> a##b##c;\n\n   Note that, due to a current parser limitation, a function atom that\n   is declared prefix cannot be used by itself as an argument. ::\n\n     In> YY\n     CommandLine(1) : Error parsing expression\n\n   .. seealso:: :func:`IsBodied`, :func:`OpPrecedence`\n\n\n\n.. function:: IsBodied(op)\n\n   check for function syntax\n\n   :param op: string, the name of a function\n\n   Check whether the function with given name {\"op\"} has been declared as a\n   \"bodied\", infix, postfix, or prefix operator, and  return :data:`True` or :data:`False`.\n\n.. function:: IsInfix(op)\n\n   check for function syntax\n\n   :param op: string, the name of a function\n\n   Check whether the function with given name {\"op\"} has been declared as a\n   \"bodied\", infix, postfix, or prefix operator, and  return :data:`True` or :data:`False`.\n\n.. function:: IsPostfix(op)\n\n   check for function syntax\n\n   :param op: string, the name of a function\n\n   Check whether the function with given name {\"op\"} has been declared as a\n   \"bodied\", infix, postfix, or prefix operator, and  return :data:`True` or :data:`False`.\n\n.. function:: IsPrefix(op)\n\n   check for function syntax\n\n   :param op: string, the name of a function\n\n   Check whether the function with given name {\"op\"} has been declared as a\n   \"bodied\", infix, postfix, or prefix operator, and  return :data:`True` or :data:`False`.\n\n   :Example:\n\n   ::\n\n      In> IsInfix(\"+\");\n      Out> True;\n      In> IsBodied(\"While\");\n      Out> True;\n      In> IsBodied(\"Sin\");\n      Out> False;\n      In> IsPostfix(\"!\");\n      Out> True;\n\n   .. seealso:: :func:`Bodied`, :func:`OpPrecedence`\n\n.. function:: OpPrecedence(op)\n\n   get operator precedence\n\n   :param op: string, the name of a function\n\n   Returns the precedence of the function named \"op\" which should have\n   been declared as a bodied function or an infix, postfix, or prefix\n   operator. Generates an error message if the string str does not\n   represent a type of function that can have precedence.\n\n   For infix operators, right precedence can differ from left\n   precedence. Bodied functions and prefix operators cannot have left\n   precedence, while postfix operators cannot have right precedence;\n   for these operators, there is only one value of precedence.\n\n\n.. function:: OpLeftPrecedence(op)\n\n   get operator precedence\n\n   :param op: string, the name of a function\n\n   Returns the precedence of the function named \"op\" which should have\n   been declared as a bodied function or an infix, postfix, or prefix\n   operator. Generates an error message if the string str does not\n   represent a type of function that can have precedence.\n\n   For infix operators, right precedence can differ from left\n   precedence. Bodied functions and prefix operators cannot have left\n   precedence, while postfix operators cannot have right precedence;\n   for these operators, there is only one value of precedence.\n\n\n.. function:: OpRightPrecedence(op)\n\n   get operator precedence\n\n   :param string op: name of a function\n\n   Returns the precedence of the function named \"op\" which should have\n   been declared as a bodied function or an infix, postfix, or prefix\n   operator. Generates an error message if the string str does not\n   represent a type of function that can have precedence.\n\n   For infix operators, right precedence can differ from left\n   precedence. Bodied functions and prefix operators cannot have left\n   precedence, while postfix operators cannot have right precedence;\n   for these operators, there is only one value of precedence.\n\n   :Example:\n\n   ::\n\n      In> OpPrecedence(\"+\")\n      Out> 6;\n      In> OpLeftPrecedence(\"!\")\n      Out> 0;\n\n\n\n.. function:: RightAssociative(op)\n\n   declare associativity\n\n   :param op: string, the name of a function\n\n\n   This makes the operator right-associative. For example: ::\n\n     RightAssociative(\"*\")\n\n   would make multiplication right-associative. Take care not to abuse\n   this function, because the reverse, making an infix operator\n   left-associative, is not implemented. (All infix operators are by\n   default left-associative until they are declared to be\n   right-associative.)\n\n   .. seealso:: :func:`OpPrecedence`\n\n\n.. function:: LeftPrecedence(op, precedence)\n\n   set operator precedence\n\n   :param op: string, the name of a function\n   :param precedence: nonnegative integer\n\n   {\"op\"} should be an infix operator. This function call tells the\n   infix expression printer to bracket the left or right hand side of\n   the expression if its precedence is larger than precedence.\n\n   This functionality was required in order to display expressions\n   like {a-(b-c)} correctly. Thus, {a+b+c} is the same as {a+(b+c)},\n   but {a-(b-c)} is not the same as {a-b-c}.\n\n   Note that the left and right precedence of an infix operator does\n   not affect the way Yacas interprets expressions typed by the\n   user. You cannot make Yacas parse {a-b-c} as {a-(b-c)} unless you\n   declare the operator \"{-}\" to be right-associative.\n\n   .. seealso:: :func:`OpPrecedence`, :func:`OpLeftPrecedence`,\n                :func:`OpRightPrecedence`, :func:`RightAssociative`\n\n.. function:: RightPrecedence\n\n   set operator precedence(op, precedence)\n\n   :param op: string, the name of a function\n   :param precedence: nonnegative integer\n\n   {\"op\"} should be an infix operator. This function call tells the\n   infix expression printer to bracket the left or right hand side of\n   the expression if its precedence is larger than precedence.\n\n   This functionality was required in order to display expressions\n   like {a-(b-c)} correctly. Thus, {a+b+c} is the same as {a+(b+c)},\n   but {a-(b-c)} is not the same as {a-b-c}.\n\n   Note that the left and right precedence of an infix operator does\n   not affect the way Yacas interprets expressions typed by the\n   user. You cannot make Yacas parse {a-b-c} as {a-(b-c)} unless you\n   declare the operator \"{-}\" to be right-associative.\n\n   .. seealso:: :func:`OpPrecedence`, :func:`OpLeftPrecedence`,\n                :func:`OpRightPrecedence`, :func:`RightAssociative`\n\n.. function:: RuleBase(name, params)\n\n   define function with a fixed number of arguments\n\n   :param name: string, name of function\n   :param params: list of arguments to function\n\n   Define a new rules table entry for a function \"name\", with {params}\n   as the parameter list. Name can be either a string or simple atom.\n\n   In the context of the transformation rule declaration facilities\n   this is a useful function in that it allows the stating of argument\n   names that can he used with HoldArg.\n\n   Functions can be overloaded: the same function can be defined with\n   different number of arguments.\n\n\n   .. seealso:: :func:`MacroRuleBase`, :func:`RuleBaseListed`,\n                :func:`MacroRuleBaseListed`, :func:`HoldArg`,\n                :func:`Retract`\n\n\n\n.. function:: RuleBaseListed(name, params)\n\n   define function with variable number of arguments\n\n   :param name: string, name of function\n   :param params: list of arguments to function\n\n   The command {RuleBaseListed} defines a new function. It essentially\n   works the same way as {RuleBase}, except that it declares a new\n   function with a variable number of arguments. The list of\n   parameters {params} determines the smallest number of arguments\n   that the new function will accept. If the number of arguments\n   passed to the new function is larger than the number of parameters\n   in {params}, then the last argument actually passed to the new\n   function will be a list containing all the remaining arguments.\n\n   A function defined using {RuleBaseListed} will appear to have the\n   arity equal to the number of parameters in the {param} list, and it\n   can accept any number of arguments greater or equal than that. As a\n   consequence, it will be impossible to define a new function with\n   the same name and with a greater arity.\n\n   The function body will know that the function is passed more\n   arguments than the length of the {param} list, because the last\n   argument will then be a list. The rest then works like a\n   {RuleBase}-defined function with a fixed number of\n   arguments. Transformation rules can be defined for the new function\n   as usual.\n\n   :Example:\n\n\n\n   The definitions ::\n\n     RuleBaseListed(\"f\",{a,b,c})\n     10 # f(_a,_b,{_c,_d}) <--\n       Echo({\"four args\",a,b,c,d});\n     20 # f(_a,_b,c_IsList) <--\n       Echo({\"more than four args\",a,b,c});\n     30 # f(_a,_b,_c) <-- Echo({\"three args\",a,b,c});\n\n   give the following interaction: ::\n\n     In> f(A)\n     Out> f(A);\n     In> f(A,B)\n     Out> f(A,B);\n     In> f(A,B,C)\n     three args A B C\n     Out> True;\n     In> f(A,B,C,D)\n     four args A B C D\n     Out> True;\n     In> f(A,B,C,D,E)\n     more than four args A B {C,D,E}\n     Out> True;\n     In> f(A,B,C,D,E,E)\n     more than four args A B {C,D,E,E}\n     Out> True;\n\n   The function {f} now appears to occupy all arities greater than 3: ::\n\n     In> RuleBase(\"f\", {x,y,z,t});\n     CommandLine(1) : Rule base with this arity already defined\n\n\n   .. seealso:: :func:`RuleBase`, :func:`Retract`, :func:`Echo`\n\n\n.. function:: bodied Rule(body, operator, arity, precedence, predicate)\n\n   define a rewrite rule\n\n   :param \"operator\": string, name of function\n   :param arity:\n   :param precedence: integers\n   :param predicate: function returning boolean\n   :param body: expression, body of rule\n\n   Define a rule for the function \"operator\" with \"arity\",\n   \"precedence\", \"predicate\" and \"body\". The \"precedence\" goes from\n   low to high: rules with low precedence will be applied first.\n\n   The arity for a rules database equals the number of\n   arguments. Different rules data bases can be built for functions\n   with the same name but with a different number of arguments.\n\n   Rules with a low precedence value will be tried before rules with a\n   high value, so a rule with precedence 0 will be tried before a rule\n   with precedence 1.\n\n.. function:: HoldArg(operator, parameters)\n\n   mark argument as not evaluated\n\n   {\"operator\"} -- string, name of a function\n   {parameter} -- atom, symbolic name of parameter\n\n\n   Specify that parameter should not be evaluated before used. This\n   will be declared for all arities of \"operator\", at the moment this\n   function is called, so it is best called after all {RuleBase} calls\n   for this operator.  \"operator\" can be a string or atom specifying\n   the function name.\n\n   The {parameter} must be an atom from the list of symbolic arguments\n   used when calling {RuleBase}.\n\n   .. seealso:: :func:`RuleBase`, :func:`HoldArgNr`,\n                :func:`RuleBaseArgList`\n\n.. function:: Retract(function, arity)\n\n   erase rules for a function\n\n   {\"function\"} -- string, name of function\n   {arity} -- positive integer\n\n   Remove a rulebase for the function named {\"function\"} with the\n   specific {arity}, if it exists at all. This will make Yacas forget\n   all rules defined for a given function. Rules for functions with\n   the same name but different arities are not affected.\n\n   Assignment {:=} of a function does this to the function being\n   (re)defined.\n\n   .. seealso:: :func:`RuleBaseArgList`, :func:`RuleBase`, :func:`:=`\n\n.. function:: UnFence(operator, arity)\n\n   change local variable scope for a function\n\n   {\"operator\"} -- string, name of function\n   {arity} -- positive integers\n\n   When applied to a user function, the bodies defined for the rules\n   for \"operator\" with given arity can see the local variables from\n   the calling function. This is useful for defining macro-like\n   procedures (looping and such).\n\n   The standard library functions {For} and {ForEach} use {UnFence}.\n\n.. function:: HoldArgNr(function, arity, argNum)\n\n   specify argument as not evaluated\n\n   {\"function\"} -- string, function name\n   {arity}, {argNum} -- positive integers\n\n   Declares the argument numbered {argNum} of the function named\n   {\"function\"} with specified {arity} to be unevaluated\n   (\"held\"). Useful if you don't know symbolic names of parameters,\n   for instance, when the function was not declared using an explicit\n   {RuleBase} call. Otherwise you could use {HoldArg}.\n\n   .. seealso:: :func:`HoldArg`, :func:`RuleBase`\n\n\n.. function:: RuleBaseArgList(operator, arity)\n\n   obtain list of arguments\n\n   {\"operator\"} -- string, name of function\n   {arity} -- integer\n\n   Returns a list of atoms, symbolic parameters specified in the\n   {RuleBase} call for the function named {\"operator\"} with the\n   specific {arity}.\n\n   .. seealso:: :func:`RuleBase`, :func:`HoldArgNr`, :func:`HoldArg`\n\n\n.. function:: MacroSet\n\n   define rules in functions\n\n.. function:: MacroClear\n\n   define rules in functions\n\n.. function:: MacroLocal\n\n   define rules in functions\n\n.. function:: MacroRuleBase\n\n   define rules in functions\n\n.. function:: MacroRuleBaseListed\n\n   define rules in functions\n\n.. function:: MacroRule\n\n   define rules in functions\n\n   These functions have the same effect as their non-macro\n   counterparts, except that their arguments are evaluated before the\n   required action is performed.  This is useful in macro-like\n   procedures or in functions that need to define new rules based on\n   parameters.\n\n   Make sure that the arguments of {Macro}... commands evaluate to\n   expressions that would normally be used in the non-macro versions!\n\n   .. seealso:: :func:`Set`, :func:`Clear`, :func:`Local`,\n                :func:`RuleBase`, :func:`Rule`, :func:`Backquoting`\n\n.. function:: Backquoting\n\n   macro expansion (LISP-style backquoting)\n\n   {expression} -- expression containing \"{@var}\" combinations to substitute the value of variable \"{var}\"\n\n   Backquoting is a macro substitution mechanism. A backquoted\n   {expression} is evaluated in two stages: first, variables prefixed\n   by {@} are evaluated inside an expression, and second, the new\n   expression is evaluated.\n\n   To invoke this functionality, a backquote {`} needs to be placed in\n   front of an expression. Parentheses around the expression are\n   needed because the backquote binds tighter than other operators.\n\n   The expression should contain some variables (assigned atoms) with\n   the special prefix operator {@}. Variables prefixed by {@} will be\n   evaluated even if they are inside function arguments that are\n   normally not evaluated (e.g. functions declared with {HoldArg}). If\n   the {@var} pair is in place of a function name, e.g. \"{@f(x)}\",\n   then at the first stage of evaluation the function name itself is\n   replaced, not the return value of the function (see example); so at\n   the second stage of evaluation, a new function may be called.\n\n   One way to view backquoting is to view it as a parametric\n   expression generator. {@var} pairs get substituted with the value\n   of the variable {var} even in contexts where nothing would be\n   evaluated. This effect can be also achieved using {UnList} and\n   {Hold} but the resulting code is much more difficult to read and\n   maintain.\n\n   This operation is relatively slow since a new expression is built\n   before it is evaluated, but nonetheless backquoting is a powerful\n   mechanism that sometimes allows to greatly simplify code.\n\n   :Example:\n\n   This example defines a function that automatically evaluates to\n   a number as soon as the argument is a number (a lot of functions\n   do this only when inside a {N(...)} section). ::\n\n     In> Decl(f1,f2) := \\\n     In>   `(@f1(x_IsNumber) <-- N(@f2(x)));\n     Out> True;\n     In> Decl(nSin,Sin)\n     Out> True;\n     In> Sin(1)\n     Out> Sin(1);\n     In> nSin(1)\n     Out> 0.8414709848;\n\n   This example assigns the expression {func(value)} to variable\n   {var}. Normally the first argument of {Set} would be unevaluated. ::\n\n     In> SetF(var,func,value) := \\\n     In>     `(Set(@var,@func(@value)));\n     Out> True;\n     In> SetF(a,Sin,x)\n     Out> True;\n     In> a\n     Out> Sin(x);\n\n\n   .. seealso:: :func:`MacroSet`, :func:`MacroLocal`,\n                :func:`MacroRuleBase`, :func:`Hold`, :func:`HoldArg`,\n                :func:`DefMacroRuleBase`\n\n\n\n.. function:: DefMacroRuleBase(name,params)\n\n   define a function as a macro\n\n   {name} -- string, name of a function\n   {params} -- list of arguments\n\n   {DefMacroRuleBase} is similar to {RuleBase}, with the difference\n   that it declares a macro, instead of a function.  After this call,\n   rules can be defined for the function \"{name}\", but their\n   interpretation will be different.\n\n   With the usual functions, the evaluation model is that of the\n   *applicative-order model of substitution*, meaning that first\n   the arguments are evaluated, and then the function is applied to\n   the result of evaluating these arguments. The function is entered,\n   and the code inside the function can not access local variables\n   outside of its own local variables.\n\n   With macros, the evaluation model is that of the *normal-order\n   model of substitution*, meaning that all occurrences of\n   variables in an expression are first substituted into the body of\n   the macro, and only then is the resulting expression evaluated\n   *in its calling environment*. This is important, because then\n   in principle a macro body can access the local variables from the\n   calling environment, whereas functions can not do that.\n\n   As an example, suppose there is a function {square}, which squares\n   its argument, and a function {add}, which adds its\n   arguments. Suppose the definitions of these functions are::\n\n     add(x,y) <-- x+y;\n\n   and ::\n\n     square(x) <-- x*x;\n\n   In applicative-order mode (the usual way functions are evaluated),\n   in the following expression ::\n\n     add(square(2),square(3))\n\n   first the arguments to {add} get evaluated. So, first {square(2)}\n   is evaluated.  To evaluate this, first {2} is evaluated, but this\n   evaluates to itself. Then the {square} function is applied to it,\n   {2*2}, which returns 4. The same is done for {square(3)}, resulting\n   in {9}. Only then, after evaluating these two arguments, {add} is\n   applied to them, which is equivalent to ``add(4,9)`` resulting in\n   calling {4+9}, which in turn results in {13}.\n\n   In contrast, when {add} is a macro, the arguments to {add} are first\n   expanded. So ::\n\n     add(square(2),square(3))\n\n   first expands to ::\n\n     square(2) + square(3)\n\n   and then this expression is evaluated, as if the user had written\n   it directly.  In other words, {square(2)} is not evaluated before\n   the macro has been fully expanded.\n\n\n   Macros are useful for customizing syntax, and compilers can\n   potentially greatly optimize macros, as they can be inlined in the\n   calling environment, and optimized accordingly.\n\n   There are disadvantages, however. In interpreted mode, macros are\n   slower, as the requirement for substitution means that a new\n   expression to be evaluated has to be created on the fly. Also, when\n   one of the parameters to the macro occur more than once in the body\n   of the macro, it is evaluated multiple times.\n\n   When defining transformation rules for macros, the variables to be\n   substituted need to be preceded by the {@} operator, similar to the\n   back-quoting mechanism.  Apart from that, the two are similar, and\n   all transformation rules can also be applied to macros.\n\n   Macros can co-exist with functions with the same name but different\n   arity.  For instance, one can have a function {foo(a,b)} with two\n   arguments, and a macro {foo(a,b,c)} with three arguments.\n\n\n   :Example:\n\n      The following example defines a function {myfor}, and shows one\n      use, referencing a variable {a} from the calling environment. ::\n\n        In> DefMacroRuleBase(\"myfor\",{init,pred,inc,body})\n        Out> True;\n        In> myfor(_init,_pred,_inc,_body)<--[@init;While(@pred)[@body;@inc;];True;];\n        Out> True;\n        In> a:=10\n        Out> 10;\n        In> myfor(i:=1,i<10,i++,Echo(a*i))\n        10\n        20\n        30\n        40\n        50\n        60\n        70\n        80\n        90\n        Out> True;\n        In> i\n        Out> 10;\n\n   .. seealso:: :func:`RuleBase`, :func:`Backquoting`,\n                :func:`DefMacroRuleBaseListed`\n\n.. function:: DefMacroRuleBaseListed(name, params)\n\n   define macro with variable number of arguments\n\n   {\"name\"} -- string, name of function\n   {params} -- list of arguments to function\n\n   This does the same as {DefMacroRuleBase} (define a macro), but with a variable\n   number of arguments, similar to {RuleBaseListed}.\n\n   .. seealso:: :func:`RuleBase`, :func:`RuleBaseListed`,\n                :func:`Backquoting`, :func:`DefMacroRuleBase`\n\n\n.. function:: ExtraInfo'Set(expr,tag)\n              ExtraInfo'Get(expr)\n\n   annotate objects with additional information\n\n   {expr} -- any expression\n   {tag} -- tag information (any other expression)\n\n   Sometimes it is useful to be able to add extra tag information to\n   \"annotate\" objects or to label them as having certain\n   \"properties\". The functions {ExtraInfo'Set} and {ExtraInfo'Get}\n   enable this.\n\n   The function {ExtraInfo'Set} returns the tagged expression, leaving\n   the original expression alone. This means there is a common\n   pitfall: be sure to assign the returned value to a variable, or the\n   tagged expression is lost when the temporary object is destroyed.\n\n   The original expression is left unmodified, and the tagged\n   expression returned, in order to keep the atomic objects small. To\n   tag an object, a new type of object is created from the old object,\n   with one added property (the tag). The tag can be any expression\n   whatsoever.\n\n   The function {ExtraInfo'Get(x)} retrieves this tag expression from\n   an object {x}. If an object has no tag, it looks the same as if it\n   had a tag with value :data:`False`.\n\n   No part of the Yacas core uses tags in a way that is visible to the\n   outside world, so for specific purposes a programmer can devise a\n   format to use for tag information. Association lists (hashes) are a\n   natural fit for this, although it is not required and a tag can be\n   any object (except the atom :data:`False` because it is indistinguishable\n   from having no tag information). Using association lists is highly\n   advised since it is most likely to be the format used by other\n   parts of the library, and one needs to avoid clashes with other\n   library code.  Typically, an object will either have no tag or a\n   tag which is an associative list (perhaps empty). A script that\n   uses tagged objects will check whether an object has a tag and if\n   so, will add or modify certain entries of the association list,\n   preserving any other tag information.\n\n   Note that {FlatCopy} currently does *not* copy the tag\n   information (see examples).\n\n   :Example:\n\n   ::\n\n      In> a:=2*b\n      Out> 2*b;\n      In> a:=ExtraInfo'Set(a,{{\"type\",\"integer\"}})\n      Out> 2*b;\n      In> a\n      Out> 2*b;\n      In> ExtraInfo'Get(a)\n      Out> {{\"type\",\"integer\"}};\n      In> ExtraInfo'Get(a)[\"type\"]\n      Out> \"integer\";\n      In> c:=a\n      Out> 2*b;\n      In> ExtraInfo'Get(c)\n      Out> {{\"type\",\"integer\"}};\n      In> c\n      Out> 2*b;\n      In> d:=FlatCopy(a);\n      Out> 2*b;\n      In> ExtraInfo'Get(d)\n      Out> False;\n\n   .. seealso:: :func:`Assoc`, :func:`:=`\n\n.. function:: GarbageCollect()\n\n   do garbage collection on unused memory\n\n   {GarbageCollect} garbage-collects unused memory. The Yacas system\n   uses a reference counting system for most objects, so this call is\n   usually not necessary.\n\n   Reference counting refers to bookkeeping where in each object a\n   counter is held, keeping track of the number of parts in the system\n   using that object. When this count drops to zero, the object is\n   automatically removed. Reference counting is not the fastest way of\n   doing garbage collection, but it can be implemented in a very clean\n   way with very little code.\n\n   Among the most important objects that are not reference counted are\n   the strings. {GarbageCollect} collects these and disposes of them\n   when they are not used any more.\n\n   {GarbageCollect} is useful when doing a lot of text processing, to\n   clean up the text buffers. It is not highly needed, but it keeps\n   memory use low.\n\n\n.. function:: FindFunction(function)\n\n   find the library file where a function is defined\n\n   {function} -- string, the name of a function\n\n   This function is useful for quickly finding the file where a\n   standard library function is defined. It is likely to only be\n   useful for developers. The function {FindFunction} scans the {.def}\n   files that were loaded at start-up.  This means that functions that\n   are not listed in {.def} files will not be found with\n   {FindFunction}.\n\n   :Example:\n\n   ::\n\n      In> FindFunction(\"Sum\")\n      Out> \"sums.rep/code.ys\";\n      In> FindFunction(\"Integrate\")\n      Out> \"integrate.rep/code.ys\";\n\n   .. seealso:: :func:`Vi`\n\n.. function:: Secure(body)\n\n   guard the host OS\n\n   {body} -- expression\n\n   {Secure} evaluates {body} in a \"safe\" environment, where files\n   cannot be opened and system calls are not allowed. This can help\n   protect the system when e.g. a script is sent over the Internet to\n   be evaluated on a remote computer, which is potentially unsafe.\n\n   .. seealso:: :func:`SystemCall`\n\nArbitrary-precision numerical programming\n-----------------------------------------\n\nThis chapter contains functions that help programming numerical\ncalculations with arbitrary precision.\n\n.. function:: MultiplyNum(x,y[,...])\n\n   optimized numerical multiplication\n\n   {x}, {y}, {z} -- integer, rational or floating-point numbers to multiply\n\n\n   The function {MultiplyNum} is used to speed up multiplication of\n   floating-point numbers with rational numbers. Suppose we need to\n   compute :math:`(p/q)*x` where :math:`p`, :math:`q` are integers and :math:`x` is a\n   floating-point number. At high precision, it is faster to multiply\n   :math:`x` by an integer :math:`p` and divide by an integer :math:`q` than to compute\n   :math:`p/q` to high precision and then multiply by :math:`x`. The function\n   {MultiplyNum} performs this optimization.\n\n   The function accepts any number of arguments (not less than two) or\n   a list of numbers. The result is always a floating-point number\n   (even if {InNumericMode()} returns False).\n\n   .. seealso:: :func:`MathMultiply`\n\n.. function:: CachedConstant(cache, Cname, Cfunc)\n\n   precompute multiple-precision constants\n\n   {cache} -- atom, name of the cache\n   {Cname} -- atom, name of the constant\n   {Cfunc} -- expression that evaluates the constant\n\n   This function is used to create precomputed multiple-precision\n   values of constants. Caching these values will save time if they\n   are frequently used.\n\n   The call to {CachedConstant} defines a new function named {Cname()}\n   that returns the value of the constant at given precision. If the\n   precision is increased, the value will be recalculated as\n   necessary, otherwise calling {Cname()} will take very little time.\n\n   The parameter {Cfunc} must be an expression that can be evaluated\n   and returns the value of the desired constant at the current\n   precision. (Most arbitrary-precision mathematical functions do this\n   by default.)\n\n   The associative list {cache} contains elements of the form {{Cname,\n   prec, value}}, as illustrated in the example. If this list does not\n   exist, it will be created.\n\n   This mechanism is currently used by {N()} to precompute the values\n   of :math:`Pi` and :math:`gamma` (and the golden ratio through {GoldenRatio},\n   and {Catalan}).  The name of the cache for {N()} is\n   {CacheOfConstantsN}.  The code in the function {N()} assigns\n   unevaluated calls to {Internal'Pi()} and {Internal'gamma()} to the\n   atoms {Pi} and {gamma} and declares them to be lazy global\n   variables through {SetGlobalLazyVariable} (with equivalent\n   functions assigned to other constants that are added to the list of\n   cached constants).\n\n   The result is that the constants will be recalculated only when\n   they are used in the expression under {N()}.  In other words, the\n   code in {N()} does the equivalent of ::\n\n     SetGlobalLazyVariable(mypi,Hold(Internal'Pi()));\n     SetGlobalLazyVariable(mygamma,Hold(Internal'gamma()));\n\n   After this, evaluating an expression such as {1/2+gamma} will call\n   the function {Internal'gamma()} but not the function\n   {Internal'Pi()}.\n\n   :Example:\n\n   ::\n\n      In> CachedConstant( my'cache, Ln2, Internal'LnNum(2) )\n      Out> True;\n      In> Internal'Ln2()\n      Out> 0.6931471806;\n      In> V(N(Internal'Ln2(),20))\n      CachedConstant: Info: constant Ln2 is being recalculated at precision 20\n      Out> 0.69314718055994530942;\n      In> my'cache\n      Out> {{\"Ln2\",20,0.69314718055994530942}};\n\n   .. seealso:: :func:`N`, :func:`Builtin'Precision'Set`, :func:`Pi`,\n                :func:`GoldenRatio`, :func:`Catalan`, :func:`gamma`\n\n.. function:: NewtonNum(func, x0[, prec0[, order]])\n\n   low-level optimized Newton's iterations\n\n   {func} -- a function specifying the iteration sequence\n   {x0} -- initial value (must be close enough to the root)\n   {prec0} -- initial precision (at least 4, default 5)\n   {order} -- convergence order (typically 2 or 3, default 2)\n\n   This function is an optimized interface for computing Newton's\n   iteration sequences for numerical solution of equations in\n   arbitrary precision.\n\n   {NewtonNum} will iterate the given function starting from the\n   initial value, until the sequence converges within current\n   precision.  Initially, up to 5 iterations at the initial precision\n   {prec0} is performed (the low precision is set for speed). The\n   initial value {x0} must be close enough to the root so that the\n   initial iterations converge. If the sequence does not produce even\n   a single correct digit of the root after these initial iterations,\n   an error message is printed. The default value of the initial\n   precision is 5.\n\n   The {order} parameter should give the convergence order of the\n   scheme.  Normally, Newton iteration converges quadratically (so the\n   default value is {order}=2) but some schemes converge faster and\n   you can speed up this function by specifying the correct\n   order. (Caution: if you give {order}=3 but the sequence is actually\n   quadratic, the result will be silently incorrect. It is safe to use\n   {order}=2.)\n\n   The verbose option {V} can be used to monitor the convergence. The\n   achieved exact digits should roughly form a geometric progression.\n\n   :Example:\n\n   ::\n\n      In> Builtin'Precision'Set(20)\n      Out> True;\n      In> NewtonNum({{x}, x+Sin(x)}, 3, 5, 3)\n      Out> 3.14159265358979323846;\n\n   .. seealso:: :func:`Newton`\n\n.. function:: SumTaylorNum\n\n   optimized numerical evaluation of Taylor series\n\n   SumTaylorNum(x, NthTerm, order)\n   SumTaylorNum(x, NthTerm, TermFactor, order)\n   SumTaylorNum(x, ZerothTerm, TermFactor, order)\n\n   {NthTerm} -- a function specifying :math:`n`-th coefficient of the series\n   {ZerothTerm} -- value of the :math:`0`-th coefficient of the series\n   {x} -- number, value of the expansion variable\n   {TermFactor} -- a function specifying the ratio of :math:`n`-th term to the previous one\n   {order} -- power of :math:`x` in the last term\n\n   {SumTaylorNum} computes a Taylor series :math:`Sum(k,0,n,a[k]*x^k)`\n   numerically. This function allows very efficient computations of\n   functions given by Taylor series, although some tweaking of the\n   parameters is required for good results.\n\n   The coefficients :math:`a_k` of the Taylor series are given as functions\n   of one integer variable (:math:`k`). It is convenient to pass them to\n   {SumTaylorNum} as closures.  For example, if a function {a(k)} is\n   defined, then ::\n\n    SumTaylorNum(x, {{k}, a(k)}, n)\n\n   computes the series :math:`Sum(k, 0, n, a(k)*x^k)`.\n\n   Often a simple relation between successive coefficients :math:`a_{k-1}`,\n   :math:`a{k}` of the series is available; usually they are related by a\n   rational factor. In this case, the second form of {SumTaylorNum}\n   should be used because it will compute the series faster. The\n   function {TermFactor} applied to an integer :math:`k>=1` must return the\n   ratio :math:`a_k/a_{k-1}`. (If possible, the function {TermFactor}\n   should return a rational number and not a floating-point number.)\n   The function {NthTerm} may also be given, but the current\n   implementation only calls {NthTerm(0)} and obtains all other\n   coefficients by using {TermFactor}.  Instead of the function\n   {NthTerm}, a number giving the :math:`0`-th term can be given.\n\n   The algorithm is described elsewhere in the documentation.  The\n   number of terms {order}+1 must be specified and a sufficiently high\n   precision must be preset in advance to achieve the desired\n   accuracy.  (The function {SumTaylorNum} does not change the current\n   precision.)\n\n   :Example:\n\n   To compute 20 digits of :math:`Exp(1)` using the Taylor series, one needs\n   21 digits of working precision and 21 terms of the series. ::\n\n     In> Builtin'Precision'Set(21)\n     Out> True;\n     In> SumTaylorNum(1, {{k},1/k!}, 21)\n     Out> 2.718281828459045235351;\n     In> SumTaylorNum(1, 1, {{k},1/k}, 21)\n     Out> 2.71828182845904523535;\n     In> SumTaylorNum(1, {{k},1/k!}, {{k},1/k}, 21)\n     Out> 2.71828182845904523535;\n     In> RoundTo(N(Ln(%)),20)\n     Out> 1;\n\n   .. seealso:: :func:`Taylor`\n\n.. function:: IntPowerNum(x, n, mult, unity)\n\n   optimized computation of integer powers\n\n   {x} -- a number or an expression\n   {n} -- a non-negative integer (power to raise {x} to)\n   {mult} -- a function that performs one multiplication\n   {unity} -- value of the unity with respect to that multiplication\n\n   {IntPowerNum} computes the power :math:`x^n` using the fast binary\n   algorithm.  It can compute integer powers with :math:`n>=0` in any ring\n   where multiplication with unity is defined.  The multiplication\n   function and the unity element must be specified.  The number of\n   multiplications is no more than :math:`2*Ln(n)/Ln(2)`.\n\n   Mathematically, this function is a generalization of {MathPower} to\n   rings other than that of real numbers.\n\n   In the current implementation, the {unity} argument is only used\n   when the given power {n} is zero.\n\n   :Example:\n\n   For efficient numerical calculations, the {MathMultiply} function can be passed: ::\n\n     In> IntPowerNum(3, 3, MathMultiply,1)\n     Out> 27;\n\n   Otherwise, the usual {*} operator suffices: ::\n\n     In> IntPowerNum(3+4*I, 3, *,1)\n     Out> Complex(-117,44);\n     In> IntPowerNum(HilbertMatrix(2), 4, *, Identity(2))\n     Out> {{289/144,29/27},{29/27,745/1296}};\n\n   Compute :math:`Mod(3^100,7)`: ::\n\n     In> IntPowerNum(3,100,{{x,y},Mod(x*y,7)},1)\n     Out> 4;\n\n   .. seealso:: :func:`MultiplyNum`, :func:`MathPower`,\n                :func:`MatrixPower`\n\n.. function:: BinSplitNum(n1, n2, a, b, c, d)\n\n   computations of series by the binary splitting method\n\n.. function:: BinSplitData(n1,n2, a, b, c, d)\n\n   computations of series by the binary splitting method\n\n.. function:: BinSplitFinal({P,Q,B,T})\n\n   computations of series by the binary splitting method\n\n   {n1}, {n2} -- integers, initial and final indices for summation\n   {a}, {b}, {c}, {d} -- functions of one argument, coefficients of the series\n   {P}, {Q}, {B}, {T} -- numbers, intermediate data as returned by {BinSplitData}\n\n   The binary splitting method is an efficient way to evaluate many\n   series when fast multiplication is available and when the series\n   contains only rational numbers.  The function {BinSplitNum}\n   evaluates a series of the form :math:`S(n[1],n[2])=Sum(k,n[1],n[2],\n   a(k)/b(k)*(p(0)/q(0)) * ... * p(k)/q(k))`.  Most series for\n   elementary and special functions at rational points are of this\n   form when the functions :math:`a(k)`, :math:`b(k)`, :math:`p(k)`, :math:`q(k)` are chosen\n   appropriately.\n\n   The last four arguments of {BinSplitNum} are functions of one\n   argument that give the coefficients :math:`a(k)`, :math:`b(k)`, :math:`p(k)`, :math:`q(k)`.\n   In most cases these will be short integers that are simple to\n   determine.  The binary splitting method will work also for\n   non-integer coefficients, but the calculation will take much longer\n   in that case.\n\n   Note: the binary splitting method outperforms the straightforward\n   summation only if the multiplication of integers is faster than\n   quadratic in the number of digits.  See <*the algorithm\n   documentation|yacasdoc://Algo/3/14/*> for more information.\n\n   The two other functions are low-level functions that allow a finer\n   control over the calculation.  The use of the low-level routines\n   allows checkpointing or parallelization of a binary splitting\n   calculation.\n\n   The binary splitting method recursively reduces the calculation of\n   :math:`S(n[1],n[2])` to the same calculation for the two halves of the\n   interval :math:`[n_1, n_2]`.  The intermediate results of a binary\n   splitting calculation are returned by {BinSplitData} and consist of\n   four integers :math:`P`, :math:`Q`, :math:`B`, :math:`T`.  These four integers are\n   converted into the final answer :math:`S` by the routine {BinSplitFinal}\n   using the relation :math:`S = T / (B*Q)`.\n\n   :Example:\n\n   Compute the series for :math:`e=Exp(1)` using binary splitting.\n   (We start from :math:`n=1` to simplify the coefficient functions.)::\n\n     In> Builtin'Precision'Set(21)\n     Out> True;\n     In>  BinSplitNum(1,21, {{k},1}, {{k},1},{{k},1},{{k},k})\n     Out> 1.718281828459045235359;\n     In> N(Exp(1)-1)\n     Out> 1.71828182845904523536;\n     In>  BinSplitData(1,21, {{k},1}, {{k},1},{{k},1},{{k},k})\n     Out> {1,51090942171709440000,1, 87788637532500240022};\n     In> BinSplitFinal(%)\n     Out> 1.718281828459045235359;\n\n   .. seealso:: :func:`SumTaylorNum`\n\n.. function:: MathSetExactBits(x)\n\n   manipulate precision of floating-point numbers\n\n.. function:: MathGetExactBits(x,bits)\n\n   manipulate precision of floating-point numbers\n\n   {x} -- an expression evaluating to a floating-point number\n   {bits} -- integer, number of bits\n\n   Each floating-point number in Yacas has an internal precision\n   counter that stores the number of exact bits in the mantissa.  The\n   number of exact bits is automatically updated after each arithmetic\n   operation to reflect the gain or loss of precision due to\n   round-off.  The functions {MathGetExactBits}, {MathSetExactBits}\n   allow to query or set the precision flags of individual number\n   objects.\n\n   {MathGetExactBits(x)} returns an integer number :math:`n` such that {x}\n   represents a real number in the interval :math:`[x*(1-2^(-n)),\n   x*(1+2^(-n))]` if :math:`x!=0` and in the interval :math:`[-2^(-n), 2^(-n)]`\n   if :math:`x=0`.  The integer :math:`n` is always nonnegative unless {x} is zero\n   (a \"floating zero\").  A floating zero can have a negative value of\n   the number :math:`n` of exact bits.\n\n   These functions are only meaningful for floating-point numbers.\n   (All integers are always exact.)  For integer {x}, the function\n   {MathGetExactBits} returns the bit count of {x} and the function\n   {MathSetExactBits} returns the unmodified integer {x}.\n\n   .. todo:: FIXME - these examples currently do not work because of bugs\n\n   :Example:\n\n   The default precision of 10 decimals corresponds to 33 bits::\n\n     In> MathGetExactBits(1000.123)\n     Out> 33;\n     In> x:=MathSetExactBits(10., 20)\n     Out> 10.;\n     In> MathGetExactBits(x)\n     Out> 20;\n\n   Prepare a \"floating zero\" representing an interval [-4, 4]::\n\n     In> x:=MathSetExactBits(0., -2)\n     Out> 0.;\n     In> x=0\n     Out> True;\n\n   .. seealso:: :func:`Builtin'Precision'Set`, :func:`Builtin'Precision'Get`\n\n\n.. function:: InNumericMode()\n\n   determine if currently in numeric mode\n\n.. function:: NonN(expr)\n\n   calculate part in non-numeric mode\n\n   {expr} -- expression to evaluate\n   {prec} -- integer, precision to use\n\n   When in numeric mode, :func:`InNumericMode` will return :data:`True`, else it\n   will return :data:`False`. Yacas is in numeric mode when evaluating an\n   expression with the function :func:`N`. Thus when calling ``N(expr)``,\n   :func:`InNumericMode` will return :data:`True` while ``expr`` is being\n   evaluated.\n\n   :func:`InNumericMode` would typically be used to define a\n   transformation rule that defines how to get a numeric approximation\n   of some expression. One could define a transformation rule::\n\n     f(_x)_InNumericMode() <- [... some code to get a numeric approximation of f(x) ... ];\n\n   :func:`InNumericMode` usually returns :data:`False`, so transformation rules\n   that check for this predicate are usually left alone.\n\n   When in numeric mode, :func:`NonN` can be called to switch back to non-numeric\n   mode temporarily.\n\n   :func:`NonN` is a macro. Its argument ``expr`` will only be evaluated after\n   the numeric mode has been set appropriately.\n\n   :Example:\n\n   ::\n\n      In> InNumericMode()\n      Out> False\n      In> N(InNumericMode())\n      Out> True\n      In> N(NonN(InNumericMode()))\n      Out> False\n\n   .. seealso:: :func:`N`, :func:`Builtin'Precision'Set`,\n                :func:`Builtin'Precision'Get`, :func:`Pi`,\n                :func:`CachedConstant`\n\n.. function:: IntLog(n, base)\n\n   integer part of logarithm\n\n   {n}, {base} -- positive integers\n\n   {IntLog} calculates the integer part of the logarithm of {n} in\n   base {base}. The algorithm uses only integer math and may be faster\n   than computing :math:`Ln(n)/Ln(base)` with multiple precision\n   floating-point math and rounding off to get the integer part.\n\n   This function can also be used to quickly count the digits in a\n   given number.\n\n   :Example:\n\n   Count the number of bits::\n\n     In> IntLog(257^8, 2)\n     Out> 64;\n\n   Count the number of decimal digits::\n\n     In> IntLog(321^321, 10)\n     Out> 804;\n\n   .. seealso:: :func:`IntNthRoot`, :func:`Div`, :func:`Mod`,\n                :func:`Ln`\n\n.. function:: IntNthRoot(x, n)\n\n   integer part of :math:`n`-th root\n\n   {x}, {n} -- positive integers\n\n   {IntNthRoot} calculates the integer part of the :math:`n`-th root of\n   :math:`x`. The algorithm uses only integer math and may be faster than\n   computing :math:`x^(1/n)` with floating-point and rounding.\n\n   This function is used to test numbers for prime powers.\n\n   :Example:\n\n   ::\n\n      In> IntNthRoot(65537^111, 37)\n      Out> 281487861809153;\n\n   .. seealso:: :func:`IntLog`, :func:`MathPower`, :func:`IsPrimePower`\n\n\n\n.. function:: NthRoot(m,n)\n\n   calculate/simplify nth root of an integer\n\n   {m} -- a non-negative integer (`m>0`)\n   {n} -- a positive integer greater than 1 (`n>1`)\n\n   {NthRoot(m,n)} calculates the integer part of the :math:`n`-th root\n   :math:`m^(1/n)` and returns a list {{f,r}}. {f} and {r} are both positive\n   integers that satisfy :math:`f^nr=m`.  In other words, :math:`f` is the\n   largest integer such that :math:`m` divides :math:`f^n` and :math:`r` is the\n   remaining factor.\n\n   For large {m} and small {n} {NthRoot} may work quite slowly. Every\n   result {{f,r}} for given {m}, {n} is saved in a lookup table, thus\n   subsequent calls to {NthRoot} with the same values {m}, {n} will be\n   executed quite fast.\n\n   :Example:\n\n   ::\n\n      In> NthRoot(12,2)\n      Out> {2,3};\n      In> NthRoot(81,3)\n      Out> {3,3};\n      In> NthRoot(3255552,2)\n      Out> {144,157};\n      In> NthRoot(3255552,3)\n      Out> {12,1884};\n\n   .. seealso:: :func:`IntNthRoot`, :func:`Factors`, :func:`MathPower`\n\n\n.. function:: ContFracList(frac[,depth])\n\n   manipulate continued fractions\n\n.. function:: ContFracEval(list[,rest])\n\n   manipulate continued fractions\n\n   {frac} -- a number to be expanded\n   {depth} -- desired number of terms\n   {list} -- a list of coefficients\n   {rest} -- expression to put at the end of the continued fraction\n\n   The function {ContFracList} computes terms of the continued\n   fraction representation of a rational number {frac}.  It returns a\n   list of terms of length {depth}. If {depth} is not specified, it\n   returns all terms.\n\n   The function {ContFracEval} converts a list of coefficients into a\n   continued fraction expression. The optional parameter {rest}\n   specifies the symbol to put at the end of the expansion. If it is\n   not given, the result is the same as if {rest=0}.\n\n   :Example:\n\n   ::\n\n      In> A:=ContFracList(33/7 + 0.000001)\n      Out> {4,1,2,1,1,20409,2,1,13,2,1,4,1,1,3,3,2};\n      In> ContFracEval(Take(A, 5))\n      Out> 33/7;\n      In> ContFracEval(Take(A,3), remainder)\n      Out> 1/(1/(remainder+2)+1)+4;\n\n   .. seealso:: :func:`ContFrac`, :func:`GuessRational`\n\n.. function:: GuessRational(x[,digits])\n\n   find optimal rational approximations\n\n.. function:: NearRational(x,[digits])\n\n   find optimal rational approximations\n\n.. function:: BracketRational(x,eps)\n\n   find optimal rational approximations\n\n   {x} -- a number to be approximated (must be already evaluated to floating-point)\n   {digits} -- desired number of decimal digits (integer)\n   {eps} -- desired precision\n\n   The functions {GuessRational(x)} and {NearRational(x)} attempt to\n   find \"optimal\" rational approximations to a given value {x}. The\n   approximations are \"optimal\" in the sense of having smallest\n   numerators and denominators among all rational numbers close to\n   {x}. This is done by computing a continued fraction representation\n   of {x} and truncating it at a suitably chosen term.  Both functions\n   return a rational number which is an approximation of {x}.\n\n   Unlike the function {Rationalize()} which converts floating-point\n   numbers to rationals without loss of precision, the functions\n   {GuessRational()} and {NearRational()} are intended to find the\n   best rational that is *approximately* equal to a given value.\n\n   The function {GuessRational()} is useful if you have obtained a\n   floating-point representation of a rational number and you know\n   approximately how many digits its exact representation should\n   contain.  This function takes an optional second parameter {digits}\n   which limits the number of decimal digits in the denominator of the\n   resulting rational number. If this parameter is not given, it\n   defaults to half the current precision. This function truncates the\n   continuous fraction expansion when it encounters an unusually large\n   value (see example).  This procedure does not always give the\n   \"correct\" rational number; a rule of thumb is that the\n   floating-point number should have at least as many digits as the\n   combined number of digits in the numerator and the denominator of\n   the correct rational number.\n\n   The function {NearRational(x)} is useful if one needs to\n   approximate a given value, i.e. to find an \"optimal\" rational\n   number that lies in a certain small interval around a certain value\n   {x}. This function takes an optional second parameter {digits}\n   which has slightly different meaning: it specifies the number of\n   digits of precision of the approximation; in other words, the\n   difference between {x} and the resulting rational number should be\n   at most one digit of that precision. The parameter {digits} also\n   defaults to half of the current precision.\n\n   The function {BracketRational(x,eps)} can be used to find\n   approximations with a given relative precision from above and from\n   below.  This function returns a list of two rational numbers\n   {{r1,r2}} such that :math:`r1<x<r2` and :math:`Abs(r2-r1)<Abs(x*eps)`.  The\n   argument {x} must be already evaluated to enough precision so that\n   this approximation can be meaningfully found.  If the approximation\n   with the desired precision cannot be found, the function returns an\n   empty list.\n\n   :Example:\n\n   Start with a rational number and obtain a floating-point approximation::\n\n     In> x:=N(956/1013)\n     Out> 0.9437314906\n     In> Rationalize(x)\n     Out> 4718657453/5000000000;\n     In> V(GuessRational(x))\n     GuessRational: using 10 terms of the continued fraction\n     Out> 956/1013;\n     In> ContFracList(x)\n     Out> {0,1,16,1,3,2,1,1,1,1,508848,3,1,2,1,2,2};\n\n   The first 10 terms of this continued fraction correspond to the\n   correct continued fraction for the original rational number::\n\n     In> NearRational(x)\n     Out> 218/231;\n\n   This function found a different rational number closeby because the\n   precision was not high enough::\n\n     In> NearRational(x, 10)\n     Out> 956/1013;\n\n   Find an approximation to :math:`Ln(10)` good to 8 digits::\n\n     In> BracketRational(N(Ln(10)), 10^(-8))\n     Out> {12381/5377,41062/17833};\n\n\n   .. seealso:: :func:`ContFrac`, :func:`ContFracList`,\n                :func:`Rationalize`\n\n\n.. function:: TruncRadian(r)\n\n   remainder modulo :math:`2*Pi`\n\n   {r} -- a number\n\n   {TruncRadian} calculates :math:`Mod(r,2*Pi)`, returning a value between\n   :math:`0` and :math:`2*Pi`. This function is used in the trigonometry\n   functions, just before doing a numerical calculation using a Taylor\n   series. It greatly speeds up the calculation if the value passed is\n   a large number.\n\n   The library uses the formula :math:`TruncRadian(r) = r - Floor( r/(2*Pi)\n   )*2*Pi`, where :math:`r` and :math:`2*Pi` are calculated with twice the\n   precision used in the environment to make sure there is no rounding\n   error in the significant digits.\n\n   :Example:\n\n   ::\n\n      In> 2*Internal'Pi()\n      Out> 6.283185307;\n      In> TruncRadian(6.28)\n      Out> 6.28;\n      In> TruncRadian(6.29)\n      Out> 0.0068146929;\n\n   .. seealso:: :func:`Sin`, :func:`Cos`, :func:`Tan`\n\n\n.. function:: Builtin'Precision'Set(n)\n\n   set the precision\n\n   {n} -- integer, new value of precision\n\n   This command sets the number of decimal digits to be used in\n   calculations.  All subsequent floating point operations will allow\n   for at least {n} digits of mantissa.\n\n   This is not the number of digits after the decimal point.  For\n   example, {123.456} has 3 digits after the decimal point and 6\n   digits of mantissa.  The number {123.456} is adequately computed by\n   specifying {Builtin'Precision'Set(6)}.\n\n   The call {Builtin'Precision'Set(n)} will not guarantee that all\n   results are precise to {n} digits.\n\n   When the precision is changed, all variables containing previously\n   calculated values remain unchanged.  The {Builtin'Precision'Set}\n   function only makes all further calculations proceed with a\n   different precision.\n\n   Also, when typing floating-point numbers, the current value of\n   {Builtin'Precision'Set} is used to implicitly determine the number\n   of precise digits in the number.\n\n   :Example:\n\n   ::\n\n      In> Builtin'Precision'Set(10)\n      Out> True;\n      In> N(Sin(1))\n      Out> 0.8414709848;\n      In> Builtin'Precision'Set(20)\n      Out> True;\n      In> x:=N(Sin(1))\n      Out> 0.84147098480789650665;\n\n   The value {x} is not changed by a {Builtin'Precision'Set()} call::\n\n      In> [ Builtin'Precision'Set(10); x; ]\n      Out> 0.84147098480789650665;\n\n   The value {x} is rounded off to 10 digits after an arithmetic\n   operation::\n\n     In> x+0.\n     Out> 0.8414709848;\n\n   In the above operation, {0.} was interpreted as a number which is\n   precise to 10 digits (the user does not need to type {0.0000000000}\n   for this to happen).  So the result of {x+0.} is precise only to 10\n   digits.\n\n   .. seealso:: :func:`Builtin'Precision'Get`, :func:`N`\n\n.. function:: Builtin'Precision'Get()\n\n   get the current precision\n\n   This command returns the current precision, as set by\n   {Builtin'Precision'Set}.\n\n   :Example:\n\n   ::\n\n      In> Builtin'Precision'Get();\n      Out> 10;\n      In> Builtin'Precision'Set(20);\n      Out> True;\n      In> Builtin'Precision'Get();\n      Out> 20;\n\n   .. seealso:: :func:`Builtin'Precision'Set`, :func:`N`\n\n\n\n\nError reporting\n---------------\n\nThis chapter contains commands useful for reporting errors to the user.\n\n.. function:: Check(predicate,\"error text\")\n\n   report \"hard\" errors\n\n.. function:: TrapError(expression,errorHandler)\n\n   trap \"hard\" errors\n\n.. function:: GetCoreError()\n\n   get \"hard\" error string\n\n   {predicate} -- expression returning :data:`True` or :data:`False`\n   {\"error text\"} -- string to print on error\n   {expression} -- expression to evaluate (causing potential error)\n   {errorHandler} -- expression to be called to handle error\n\n   If {predicate} does not evaluate to :data:`True`, the current operation\n   will be stopped, the string {\"error text\"} will be printed, and\n   control will be returned immediately to the command line. This\n   facility can be used to assure that some condition is satisfied\n   during evaluation of expressions (guarding against critical\n   internal errors).\n\n   A \"soft\" error reporting facility that does not stop the execution\n   is provided by the function {Assert}.\n\n   :Example:\n\n      In> [Check(1=0,\"bad value\"); Echo(OK);]\n      In function \"Check\" :\n      CommandLine(1) : \"bad value\"\n\n   Note that {OK} is not printed.\n\n   TrapError evaluates its argument {expression}, returning the result\n   of evaluating {expression}. If an error occurs, {errorHandler} is\n   evaluated, returning its return value in stead.\n\n   GetCoreError returns a string describing the core error.  TrapError\n   and GetCoreError can be used in combination to write a custom error\n   handler.\n\n\n   .. seealso:: :func:`Assert`\n\n.. function:: Assert(pred, str, expr)\n              Assert(pred, str) pred\n              Assert(pred)\n\n   signal \"soft\" custom error\n\n\n   Precedence:\n   EVAL OpPrecedence(\"Assert\")\n\n   {pred} -- predicate to check\n   {\"str\"} -- string to classify the error\n   {expr} -- expression, error object\n\n   {Assert} is a global error reporting mechanism. It can be used to\n   check for errors and report them. An error is considered to occur\n   when the predicate {pred} evaluates to anything except :data:`True`. In\n   this case, the function returns :data:`False` and an error object is\n   created and posted to the global error tableau.  Otherwise the\n   function returns :data:`True`.\n\n   Unlike the \"hard\" error function {Check}, the function {Assert}\n   does not stop the execution of the program.\n\n   The error object consists of the string {\"str\"} and an arbitrary\n   expression {expr}. The string should be used to classify the kind\n   of error that has occurred, for example \"domain\" or \"format\". The\n   error object can be any expression that might be useful for\n   handling the error later; for example, a list of erroneous values\n   and explanations.  The association list of error objects is\n   currently obtainable through the function {GetErrorTableau()}.\n\n   If the parameter {expr} is missing, {Assert} substitutes :data:`True`. If\n   both optional parameters {\"str\"} and {expr} are missing, {Assert}\n   creates an error of class {\"generic\"}.\n\n   Errors can be handled by a custom error handler in the portion of\n   the code that is able to handle a certain class of errors. The\n   functions {IsError}, {GetError} and {ClearError} can be used.\n\n   Normally, all errors posted to the error tableau during evaluation\n   of an expression should be eventually printed to the screen. This\n   is the behavior of prettyprinters {DefaultPrint}, {Print},\n   {PrettyForm} and {TeXForm} (but not of the inline prettyprinter,\n   which is enabled by default); they call {DumpErrors} after\n   evaluating the expression.\n\n   :Example:\n\n   ::\n\n      In> Assert(\"bad value\", \"must be zero\") 1=0\n      Out> False;\n      In> Assert(\"bad value\", \"must be one\") 1=1\n      Out> True;\n      In> IsError()\n      Out> True;\n      In> IsError(\"bad value\")\n      Out> True;\n      In> IsError(\"bad file\")\n      Out> False;\n      In> GetError(\"bad value\");\n      Out> \"must be zero\";\n      In> DumpErrors()\n      Error: bad value: must be zero\n      Out> True;\n\n   No more errors left::\n\n     In> IsError()\n     Out> False;\n     In> DumpErrors()\n     Out> True;\n\n   .. seealso:: :func:`IsError`, :func:`DumpErrors`, :func:`Check`,\n                :func:`GetError`, :func:`ClearError`,\n                :func:`ClearErrors`, :func:`GetErrorTableau`\n\n.. function:: DumpErrors()\n\n   simple error handlers\n\n.. function:: ClearErrors()\n\n   simple error handlers\n\n   {DumpErrors} is a simple error handler for the global error\n   reporting mechanism. It prints all errors posted using {Assert} and\n   clears the error tableau.\n\n   {ClearErrors} is a trivial error handler that does nothing except\n   it clears the tableau.\n\n   .. seealso:: :func:`Assert`, :func:`IsError`\n\n.. function:: IsError()\n              IsError(str)\n\n   check for custom error\n\n   {\"str\"} -- string to classify the error\n\n   {IsError()} returns :data:`True` if any custom errors have been reported\n   using {Assert}.  The second form takes a parameter {\"str\"} that\n   designates the class of the error we are interested in. It returns\n   :data:`True` if any errors of the given class {\"str\"} have been reported.\n\n   .. seealso:: :func:`GetError`, :func:`ClearError`, :func:`Assert`,\n                :func:`Check`\n\n\n.. function:: GetError(str)\n\n   custom errors handlers\n\n.. function:: ClearError(str)\n\n   custom errors handlers\n\n.. function:: GetErrorTableau()\n\n   custom errors handlers\n\n   {\"str\"} -- string to classify the error\n\n   These functions can be used to create a custom error handler.\n\n   {GetError} returns the error object if a custom error of class\n   {\"str\"} has been reported using {Assert}, or :data:`False` if no errors\n   of this class have been reported.\n\n   {ClearError(\"str\")} deletes the same error object that is returned\n   by {GetError(\"str\")}. It deletes at most one error object. It\n   returns :data:`True` if an object was found and deleted, and :data:`False`\n   otherwise.\n\n   {GetErrorTableau()} returns the entire association list of\n   currently reported errors.\n\n   :Example:\n\n   ::\n\n      In> x:=1\n      Out> 1;\n      In> Assert(\"bad value\", {x,\"must be zero\"}) x=0\n      Out> False;\n      In> GetError(\"bad value\")\n      Out> {1, \"must be zero\"};\n      In> ClearError(\"bad value\");\n      Out> True;\n      In> IsError()\n      Out> False;\n\n   .. seealso:: :func:`IsError`, :func:`Assert`, :func:`Check`,\n                :func:`ClearErrors`\n\n.. function:: CurrentFile()\n\n   return current input file\n\n.. function:: CurrentLine()\n\n   return current line number on input\n\n   The functions {CurrentFile} and {CurrentLine} return a string\n   with the file name of the current file and the current line\n   of input respectively.\n\n   These functions are most useful in batch file calculations, where\n   there is a need to determine at which line an error occurred.\n   One can define a function::\n\n     tst() := Echo({CurrentFile(),CurrentLine()});\n\n   which can then be inserted into the input file at various places,\n   to see how far the interpreter reaches before an error occurs.\n\n   .. seealso:: :func:`Echo`\n\n\n\n\n\n\nBuilt-in (core) functions\n-------------------------\n\nYacas comes with a small core of built-in functions and a large\nlibrary of user-defined functions. Some of these core functions are\ndocumented in this chapter.\n\nIt is important for a developer to know which functions are built-in\nand cannot be redefined or {Retract}-ed. Also, core functions may be\nsomewhat faster to execute than functions defined in the script\nlibrary. All core functions are listed in the file {corefunctions.h}\nin the {src/} subdirectory of the Yacas source tree. The declarations\ntypically look like this::\n\n  SetCommand(LispSubtract, \"MathSubtract\");\n\nHere {LispSubtract} is the Yacas internal name for the function and\n{MathSubtract} is the name visible to the Yacas language.  Built-in\nbodied functions and infix operators are declared in the same file.\n\n\n.. function:: MathNot(expression)\n\n   built-in logical \"not\"\n\n   Returns \"False\" if \"expression\" evaluates to \"True\", and vice\n   versa.\n\n.. function:: MathAnd()\n\n   built-in logical \"and\"\n\n   Lazy logical {And}: returns :data:`True` if all args evaluate to :data:`True`,\n   and does this by looking at first, and then at the second argument,\n   until one is :data:`False`.  If one of the arguments is :data:`False`, {And}\n   immediately returns :data:`False` without evaluating the rest. This is\n   faster, but also means that none of the arguments should cause side\n   effects when they are evaluated.\n\n.. function:: MathOr()\n\n   built-in logical \"or\"\n\n   {MathOr} is the basic logical \"or\" function. Similarly to {And}, it\n   is lazy-evaluated. {And(...)} and {Or(...)} do also exist, defined\n   in the script library. You can redefine them as infix operators\n   yourself, so you have the choice of precedence. In the standard\n   scripts they are in fact declared as infix operators, so you can\n   write {expr1 And expr}.\n\n.. function:: BitAnd(n,m)\n\n   bitwise and operation\n\n.. function:: BitOr(n,m)\n\n   bitwise or operation\n\n.. function:: BitXor(n,m)\n\n   bitwise xor operation\n\n   These functions return bitwise \"and\", \"or\" and \"xor\" of two\n   numbers.\n\n.. function:: Equals(a,b)\n\n   check equality\n\n   Compares evaluated {a} and {b} recursively (stepping into\n   expressions). So \"Equals(a,b)\" returns \"True\" if the expressions\n   would be printed exactly the same, and \"False\" otherwise.\n\n.. function:: GreaterThan(a,b)\n\n   comparison predicate\n\n.. function:: LessThan(a,b)\n\n   comparison predicate\n\n\n   {a}, {b} -- numbers or strings\n\n   Comparing numbers or strings (lexicographically).\n\n   :Example:\n\n   ::\n\n      In> LessThan(1,1)\n      Out> False;\n      In> LessThan(\"a\",\"b\")\n      Out> True;\n\n\n.. function:: MathExp()\n\n\n.. function:: MathLog()\n\n\n.. function:: MathPower()\n\n\n.. function:: MathSin()\n\n\n.. function:: MathCos()\n\n\n.. function:: MathTan()\n\n\n.. function:: MathArcSin()\n\n\n.. function:: MathArcCos()\n\n\n.. function:: MathArcTan()\n\n\n.. function:: MathSinh()\n\n\n.. function:: MathCosh()\n\n\n.. function:: MathTanh()\n\n\n.. function:: MathArcSinh()\n\n\n.. function:: MathArcCosh()\n\n\n.. function:: MathArcTanh()\n\n\n.. function:: MathGcd()\n\n\n.. function:: MathAdd()\n\n\n.. function:: MathSubtract()\n\n\n.. function:: MathMultiply()\n\n\n.. function:: MathDivide()\n\n\n.. function:: MathSqrt()\n\n\n.. function:: MathFloor()\n\n\n.. function:: MathCeil()\n\n\n.. function:: MathAbs()\n\n\n.. function:: MathMod()\n\n\n.. function:: MathDiv()\n\n\n.. function:: MathGcd(n,m)\n\n   Greatest Common Divisor\n\n.. function:: MathAdd(x,y)\n   (add two numbers)\n\n.. function:: MathSubtract(x,y)\n   (subtract two numbers)\n\n.. function:: MathMultiply(x,y)\n\n   (multiply two numbers)\n\n.. function:: MathDivide(x,y)\n\n   (divide two numbers)\n\n.. function:: MathSqrt(x)\n\n   (square root, must be x>=0)\n\n.. function:: MathFloor(x)\n\n   (largest integer not larger than x)\n\n.. function:: MathCeil(x)\n\n   (smallest integer not smaller than x)\n\n.. function:: MathAbs(x)\n\n   (absolute value of x, or ``|x|`` )\n\n.. function:: MathExp(x)\n\n   (exponential, base 2.718...)\n\n.. function:: MathLog(x)\n\n   (natural logarithm, for x>0)\n\n.. function:: MathPower(x,y)\n\n   (power, x ^ y)\n\n.. function:: MathSin(x)\n\n   (sine)\n\n.. function:: MathCos(x)\n\n   (cosine)\n\n.. function:: MathTan(x)\n\n   (tangent)\n\n.. function:: MathSinh(x)\n\n   (hyperbolic sine)\n\n.. function:: MathCosh(x)\n\n   (hyperbolic cosine)\n\n.. function:: MathTanh(x)\n\n   (hyperbolic tangent)\n\n.. function:: MathArcSin(x)\n\n   (inverse sine)\n\n.. function:: MathArcCos(x)\n\n   (inverse cosine)\n\n.. function:: MathArcTan(x)\n\n   (inverse tangent)\n\n.. function:: MathArcSinh(x)\n\n   (inverse hyperbolic sine)\n\n.. function:: MathArcCosh(x)\n\n   (inverse hyperbolic cosine)\n\n.. function:: MathArcTanh(x)\n\n   (inverse hyperbolic tangent)\n\n.. function:: MathDiv(x,y)\n\n   (integer division, result is an integer)\n\n.. function:: MathMod(x,y)\n\n   (remainder of division, or x mod y)\n\n   These commands perform the calculation of elementary mathematical\n   functions.  The arguments *must* be numbers.  The reason for\n   the prefix {Math} is that the library needs to define equivalent\n   non-numerical functions for symbolic computations, such as {Exp},\n   {Sin} and so on.\n\n   Note that all functions, such as the {MathPower}, {MathSqrt},\n   {MathAdd} etc., accept integers as well as floating-point numbers.\n   The resulting values may be integers or floats.  If the\n   mathematical result is an exact integer, then the integer is\n   returned.  For example, {MathSqrt(25)} returns the integer {5}, and\n   {MathPower(2,3)} returns the integer {8}.  In such cases, the\n   integer result is returned even if the calculation requires more\n   digits than set by {Builtin'Precision'Set}.  However, when the\n   result is mathematically not an integer, the functions return a\n   floating-point result which is correct only to the current\n   precision.\n\n   :Example:\n\n   ::\n\n      In> Builtin'Precision'Set(10)\n      Out> True\n      In> Sqrt(10)\n      Out> Sqrt(10)\n      In> MathSqrt(10)\n      Out> 3.16227766\n      In> MathSqrt(490000*2^150)\n      Out> 26445252304070013196697600\n      In> MathSqrt(490000*2^150+1)\n      Out> 0.264452523e26\n      In> MathPower(2,3)\n      Out> 8\n      In> MathPower(2,-3)\n      Out> 0.125\n\n\n.. function:: FastLog(x)\n\n   (natural logarithm),\n\n.. function:: FastPower(x,y)\n\n\n.. function:: FastArcSin(x)\n\n   double-precision math functions\n\n   Versions of these functions using the C++ library. These should\n   then at least be faster than the arbitrary precision versions.\n\n.. function:: ShiftLeft(expr, bits)\n\n   built-in bitwise shift left operation\n\n.. function:: ShiftRight(expr, bits)\n\n   built-in bitwise shift right operation\n\n   ShiftLeft(expr,bits)\n   ShiftRight(expr,bits)\n\n   Shift bits to the left or to the right.\n\n.. function:: IsPromptShown()\n\n   test for the Yacas prompt option\n\n   Returns :data:`False` if Yacas has been started with the option to\n   suppress the prompt, and :data:`True` otherwise.\n\n\n.. function:: GetTime(expr)\n\n   measure the time taken by an evaluation\n\n   {expr} -- any expression\n\n\n   The function {GetTime(expr)} evaluates the expression {expr} and\n   returns the time needed for the evaluation.  The result is returned\n   as a floating-point number of seconds.  The value of the expression\n   {expr} is lost.\n\n   The result is the \"user time\" as reported by the OS, not the real\n   (\"wall clock\") time.  Therefore, any CPU-intensive processes\n   running alongside Yacas will not significantly affect the result of\n   {GetTime}.\n\n   :Example:\n\n   ::\n\n      In> GetTime(Simplify((a*b)/(b*a)))\n      Out> 0.09;\n\n   .. seealso:: :func:`Time`\n\n\n\nGeneric objects\n---------------\n\nGeneric objects are objects that are implemented in C++, but\ncan be accessed through the Yacas interpreter.\n\n.. function:: IsGeneric(object)\n\n   check for generic object\n\n   Returns :data:`True` if an object is of a generic object type.\n\n.. function:: GenericTypeName(object)\n\n   get type name\n\n   Returns a string representation of the name of a generic object.\n\n   :Example:\n\n   ::\n\n      In> GenericTypeName(Array'Create(10,1))\n      Out> \"Array\";\n\n.. function:: Array'Create(size, init)\n\n   create array\n\n   :param size: size of the array\n   :param init: initial value\n\n   Creates an array with ``size`` elements, all initialized to the\n   value ``init``.\n\n.. function:: Array'Size(array)\n\n   array size\n\n   :param array: an array\n   :returns: array size (number of elements in the array)\n\n.. function:: Array'Get(array,index)\n\n   fetch array element\n\n   :param array: an array\n   :param index: an index\n\n   :returns: the element of ``array`` at position ``index``\n\n   .. note::\n\n      Array indices are one-based, which means that the first element\n      is indexed by 1.\n\n   Arrays can also be accessed through the ``[]`` operators. So\n   ``array[index]`` would return the same as ``Array'Get(array,\n   index)``.\n\n.. function:: Array'Set(array,index,element)\n\n   set array element\n\n   Sets the element at position index in the array passed to the value\n   passed in as argument to element. Arrays are treated as base-one,\n   so {index} set to 1 would set first element.\n\n   Arrays can also be accessed through the {[]} operators. So\n   {array[index] := element} would do the same as {Array'Set(array,\n   index,element)}.\n\n.. function:: Array'CreateFromList(list)\n\n   convert list to array\n\n   Creates an array from the contents of the list passed in.\n\n.. function:: Array'ToList(array)\n\n   convert array to list\n\n   Creates a list from the contents of the array passed in.\n\n\n\nThe Yacas test suite\n--------------------\n\nThis chapter describes commands used for verifying correct performance\nof Yacas.\n\nYacas comes with a test suite which can be found in\nthe directory {tests/}. Typing\n\n    make test\n\non the command line after Yacas was built will run the test.\nThis test can be run even before {make install}, as it only\nuses files in the local directory of the Yacas source tree.\nThe default extension for test scripts is {.yts} (Yacas test script).\n\nThe verification commands described in this chapter only  display the\nexpressions that do not evaluate correctly. Errors do not terminate the\nexecution of the Yacas script that uses these testing commands, since they are\nmeant to be used in test scripts.\n\n\n.. function:: Verify(question,answer)\n\n   verifying equivalence of two expressions\n\n.. function:: TestYacas(question,answer)\n\n   verifying equivalence of two expressions\n\n.. function:: LogicVerify(question,answer)\n\n   verifying equivalence of two expressions\n\n.. function:: LogicTest(variables,expr1,expr2)\n\n   verifying equivalence of two expressions\n\n   {question} -- expression to check for\n   {answer} -- expected result after evaluation\n   {variables} -- list of variables\n   {exprN} -- Some boolean expression\n\n   The commands {Verify}, {TestYacas}, {LogicVerify} and {LogicTest}\n   can be used to verify that an expression is <I>equivalent</I> to a\n   correct answer after evaluation. All three commands return :data:`True`\n   or :data:`False`.\n\n   For some calculations, the demand that two expressions are\n   *identical* syntactically is too stringent. The yacas system\n   might change at various places in the future, but :math:` 1+x` would\n   still be equivalent, from a mathematical point of view, to :math:`x+1`.\n\n   The general problem of deciding that two expressions :math:`a` and\n   :math:`b` are equivalent, which is the same as saying that :math:`a-b=0`,\n   is generally hard to decide on. The following commands solve this\n   problem by having domain-specific comparisons.\n\n   The comparison commands do the following comparison types:\n\n   * :func:`Verify` -- verify for literal equality.\n     This is the fastest and simplest comparison, and can be\n     used, for example, to test that an expression evaluates to :math:`2`.\n   * :func:`TestYacas` -- compare two expressions after simplification as\n     multivariate polynomials. If the two arguments are equivalent\n     multivariate polynomials, this test succeeds. :func:`TestYacas` uses\n     :func:`Simplify`. Note: :func:`TestYacas` currently should not be used to\n     test equality of lists.\n   * :func:`LogicVerify` -- Perform a test by using :func:`CanProve` to verify\n     that from ``question`` the expression ``answer`` follows. This test\n     command is used for testing the logic theorem prover in yacas.\n   * :func:`LogicTest` -- Generate a truth table for the two expressions and\n     compare these two tables. They should be the same if the two\n     expressions are logically the same.\n\n   :Example:\n\n   ::\n\n    In> Verify(1+2,3)\n    Out> True;\n    In> Verify(x*(1+x),x^2+x)\n    ******************\n    x*(x+1) evaluates to x*(x+1) which differs\n      from x^2+x\n    ******************\n    Out> False;\n    In> TestYacas(x*(1+x),x^2+x)\n    Out> True;\n    In> Verify(a And c Or b And Not c,a Or b)\n    ******************\n     a And c Or b And Not c evaluates to  a And c\n      Or b And Not c which differs from  a Or b\n    ******************\n    Out> False;\n    In> LogicVerify(a And c Or b And Not c,a Or b)\n    Out> True;\n    In> LogicVerify(a And c Or b And Not c,b Or a)\n    Out> True;\n    In> LogicTest({A,B,C},Not((Not A) And (Not B)),A Or B)\n    Out> True\n    In> LogicTest({A,B,C},Not((Not A) And (Not B)),A Or C)\n    ******************\n    CommandLine: 1\n\n    :math:`TrueFalse4({A,B,C},Not(Not A And Not B))\n     evaluates to\n    {{{False,False},{True,True}},{{True,True},{True,True}}}\n     which differs from\n    {{{False,True},{False,True}},{{True,True},{True,True}}}\n    ******************\n    Out> False\n\n   .. seealso:: :func:`Simplify`, :func:`CanProve`,\n                :func:`KnownFailure`\n\n\n.. function:: KnownFailure(test)\n\n   Mark a test as a known failure\n\n   {test} -- expression that should return :data:`False` on failure\n\n   The command {KnownFailure} marks a test as known to fail by\n   displaying a message to that effect on screen.\n\n   This might be used by developers when they have no time to fix the\n   defect, but do not wish to alarm users who download Yacas and type\n   {make test}.\n\n   :Example:\n\n   ::\n\n      In> KnownFailure(Verify(1,2))\n      Known failure:\n      ******************\n      1 evaluates to  1 which differs from  2\n      ******************\n      Out> False;\n      In> KnownFailure(Verify(1,1))\n      Known failure:\n      Failure resolved!\n      Out> True;\n\n   .. seealso:: :func:`Verify`, :func:`TestYacas`, :func:`LogicVerify`\n\n.. function:: RoundTo(number,precision)\n\n   Round a real-valued result to a set number of digits\n\n   {number} -- number to round off\n   {precision} -- precision to use for round-off\n\n   The function {RoundTo} rounds a floating point number to a\n   specified precision, allowing for testing for correctness using the\n   {Verify} command.\n\n   :Example:\n\n   ::\n\n      In> N(RoundTo(Exp(1),30),30)\n      Out> 2.71828182110230114951959786552;\n      In> N(RoundTo(Exp(1),20),20)\n      Out> 2.71828182796964237096;\n\n   .. seealso:: :func:`Verify`, :func:`VerifyArithmetic`, :func:`VerifyDiv`\n\n\n\n.. function:: VerifyArithmetic(x,n,m)\n\n   Special purpose arithmetic verifiers\n\n.. function:: RandVerifyArithmetic(n)\n\n   Special purpose arithmetic verifiers\n\n.. function:: VerifyDiv(u,v)\n\n   Special purpose arithmetic verifiers\n\n\n   {x}, {n}, {m}, {u}, {v} -- integer arguments\n\n   The commands {VerifyArithmetic} and {VerifyDiv} test a mathematic\n   equality which should hold, testing that the result returned by the\n   system is mathematically correct according to a mathematically\n   provable theorem.\n\n   {VerifyArithmetic} verifies for an arbitrary set of numbers\n   :math:`x`, :math:`n` and :math:`m` that\n   :math:`(x^n-1)*(x^m-1) = x^(n+m)-(x^n)-(x^m)+1`.\n\n   The left and right side represent two ways to arrive at the\n   same result, and so an arithmetic module actually doing the\n   calculation does the calculation in two different ways.\n   The results should be exactly equal.\n\n   {RandVerifyArithmetic(n)} calls {VerifyArithmetic} with\n   random values, {n} times.\n\n   {VerifyDiv(u,v)} checks that\n   :math:`u = v*Div(u,v) + Mod(u,v)`.\n\n   :Example:\n\n   ::\n\n      In> VerifyArithmetic(100,50,60)\n      Out> True;\n      In> RandVerifyArithmetic(4)\n      Out> True;\n      In> VerifyDiv(x^2+2*x+3,x+1)\n      Out> True;\n      In> VerifyDiv(3,2)\n      Out> True;\n\n   .. seealso:: :func:`Verify`\n"
  },
  {
    "path": "docs/reference_manual/random.rst",
    "content": "==============\nRandom numbers\n==============\n\nSimple interface\n----------------\n\n.. function:: RandomSeed(seed)\n\n   seed the global pseudo-random generator\n\n   .. seealso:: :func:`Random`\n\n.. function:: Random()\n\n   generate pseudo-random number\n\n   :func:`Random` generates a uniformly-distributed pseudo-random number\n   between 0 and 1.\n\n   .. seealso:: :func:`RandomSeed`\n\nAdvanced interface\n------------------\n\n.. function:: RngCreate()\n              RngCreate(seed)\n              RngCreate([seed=seed], [engine=engine], [dist=dist])\n              RngCreate({seed, engine, dist})\n\n   create a pseudo-random generator\n\n   :func:`RngCreate` returns a list which is a well-formed RNG object.  Its\n   value should be saved in a variable and used to call :func:`Rng` and\n   :func:`RngSeed`.\n\n   Engines:\n\n    * ``default``\n    * ``advanced``\n\n   Distributions:\n\n    * ``default`` (the same as ``flat``)\n    * ``flat`` (uniform)\n    * ``gauss`` (normal)\n\n.. seealso:: :func:`Rng`, :func:`RngSeed`\n\n.. function:: RngSeed(r, seed)\n\n   (re)seed pseudo-random number generator\n\n   :func:`RngSeed` re-initializes the RNG object ``r`` with the seed value\n   ``seed``. The seed value should be a positive integer.\n\n.. seealso:: :func:`RngCreate`, :func:`Rng`, :func:`RandomSeed`\n\n.. function:: Rng(r)\n\n   generate pseudo-random number\n\n   :func:`Rng(r)` returns a floating-point random number between 0 and 1 and\n   updates the RNG object ``r``.  (Currently, the Gaussian option makes a RNG\n   return a *complex* random number instead of a real random number.)\n\n   .. seealso:: :func:`RngCreate`, :func:`RngSeed`, :func:`Random`\n\n\nAuxilliary functions\n--------------------\n\n.. function:: RandomIntegerMatrix(rows,cols,from,to)\n\n   generate a matrix of random integers\n\n   This function generates a ``rows x cols`` matrix of random integers.\n   All  entries lie between ``from`` and ``to``, including the boundaries,\n   and are uniformly distributed in this interval.\n\n   :Example:\n\n   ::\n\n      In> PrettyForm( RandomIntegerMatrix(5,5,-2^10,2^10) )\n      /                                               \\\n      | ( -506 ) ( 749 )  ( -574 ) ( -674 ) ( -106 )  |\n      |                                               |\n      | ( 301 )  ( 151 )  ( -326 ) ( -56 )  ( -277 )  |\n      |                                               |\n      | ( 777 )  ( -761 ) ( -161 ) ( -918 ) ( -417 )  |\n      |                                               |\n      | ( -518 ) ( 127 )  ( 136 )  ( 797 )  ( -406 )  |\n      |                                               |\n      | ( 679 )  ( 854 )  ( -78 )  ( 503 )  ( 772 )   |\n      \\                                               /\n\n\n   .. seealso:: :func:`RandomIntegerVector`, :func:`RandomPoly`\n\n.. function:: RandomIntegerVector(n, from, to)\n\n   generate a vector of random integers\n\n   This function generates a list with ``n`` random integers. All\n   entries lie between ``from`` and ``to``, including the boundaries, and\n   are uniformly distributed in this interval.\n\n   :Example:\n\n   ::\n\n      In> RandomIntegerVector(4,-3,3)\n      Out> {0,3,2,-2};\n\n\n   .. seealso:: :func:`Random`, :func:`RandomPoly`\n\n.. function:: RandomPoly(var,deg,coefmin,coefmax)\n\n   construct a random polynomial\n\n   :func:`RandomPoly` generates a random polynomial in the variable ``var``, of\n   degree ``deg``, with integer coefficients ranging from ``coefmin`` to\n   ``coefmax`` (inclusive). The coefficients are uniformly distributed in  this\n   interval, and are independent of each other.\n\n   :Example:\n\n   ::\n\n      In> RandomPoly(x,3,-10,10)\n      Out> 3*x^3+10*x^2-4*x-6;\n      In> RandomPoly(x,3,-10,10)\n      Out> -2*x^3-8*x^2+8;\n\n\n   .. seealso:: :func:`Random`, :func:`RandomIntegerVector`\n"
  },
  {
    "path": "docs/reference_manual/simplify.rst",
    "content": "=============================\nSimplification of expressions\n=============================\n\nSimplification of expression is a big and non-trivial\nsubject. Simplification implies that there is a preferred form. In\npractice the preferred form depends on the calculation at hand. This\nchapter describes the functions offered that allow simplification of\nexpressions.\n\n.. function:: Simplify(expr)\n\n   try to simplify an expression\n\n   This function tries to simplify the expression ``expr`` as much  as\n   possible. It does this by grouping powers within terms, and then\n   grouping similar terms.\n\n   :Example:\n\n   ::\n\n      In> a*b*a^2/b-a^3\n      Out> (b*a^3)/b-a^3;\n      In> Simplify(a*b*a^2/b-a^3)\n      Out> 0;\n\n\n   .. seealso:: :func:`FactorialSimplify`, :func:`LnCombine`, :func:`LnExpand`, :func:`RadSimp`, :func:`TrigSimpCombine`\n\n.. function:: RadSimp(expr)\n\n   simplify expression with nested radicals\n\n   This function tries to write the expression ``expr`` as a sum of roots  of\n   integers: :math:`\\sqrt{e_1} + \\sqrt{e_2} + ...`, where :math:`e_1,e_2` and so\n   on are natural numbers. The expression ``expr`` may not contain  free\n   variables.\n\n   It does this by trying all possible combinations for :math:`e_1,e_2,\\ldots`.\n   Every possibility is numerically evaluated using :func:`N` and compared with\n   the numerical evaluation of ``expr``. If the approximations are equal (up to\n   a certain margin), this possibility is returned. Otherwise, the expression is\n   returned unevaluated.\n\n   .. note::\n     Due to the use of numerical approximations, there is a small chance that\n     the expression returned by :func:`RadSimp` is close but not equal to\n     ``expr``::\n\n      In> RadSimp(Sqrt(1+10^(-6)))\n      Out> 1;\n\n   .. note::\n     If the numerical value of ``expr`` is large, the\n     number of possibilities becomes exorbitantly big so the evaluation may take\n     very long.\n\n   :Example:\n\n   ::\n\n      In> RadSimp(Sqrt(9+4*Sqrt(2)))\n      Out> Sqrt(8)+1;\n      In> RadSimp(Sqrt(5+2*Sqrt(6)) + Sqrt(5-2*Sqrt(6)))\n      Out> Sqrt(12);\n      In> RadSimp(Sqrt(14+3*Sqrt(3+2*Sqrt(5-12*Sqrt(3-2*Sqrt(2))))))\n      Out> Sqrt(2)+3;\n\n   .. seealso:: :func:`Simplify`, :func:`N`, :func:`Sqrt`\n\n.. function:: FactorialSimplify(expression)\n\n   simplify hypergeometric expressions containing factorials\n\n   :func:`FactorialSimplify` takes an expression that may contain factorials,\n   and tries to simplify it. An expression like :math:`\\frac{(n+1)!}{n!}` would\n   simplify to :math:`(n+1)`.\n\n   .. seealso:: :func:`Simplify`, :func:`!`\n\n.. function:: LnExpand(expr)\n\n   expand a logarithmic expression using standard logarithm rules\n\n   :func:`LnExpand` takes an expression of the form :math:`\\ln(expr)`, and\n   applies logarithm  rules to expand this into multiple :func:`Ln` expressions\n   where possible.  An  expression like :math:`\\ln(ab^n)` would be expanded to\n   :math:`\\ln(a)+n\\ln(b)`. If the logarithm of an integer is discovered, it is\n   factorised using :func:`Factors` and expanded as though :func:`LnExpand` had\n   been given the factorised form.  So :math:`\\ln(18)` goes to\n   :math:`\\ln(2)+2\\ln(3)`.\n\n   .. seealso:: :func:`LnCombine`, :func:`Simplify`, :func:`Ln`, :func:`Expand`\n\n.. function:: LnCombine(expr)\n\n   combine logarithmic expressions using standard logarithm rules\n\n   :func:`LnCombine` finds :func:`Ln` terms in the expression it is given, and\n   combines them  using logarithm rules.  It is intended to be the converse of\n   :func:`LnExpand`.\n\n   .. seealso:: :func:`LnExpand`, :func:`Simplify`, :func:`Ln`\n\n.. function:: TrigSimpCombine(expr)\n\n   combine products of trigonometric functions\n\n   This function applies the product rules of trigonometry, e.g.\n   :math:`\\cos{u}\\sin{v} = \\frac{1}{2}(\\sin(v-u) + \\sin(v+u))`. As a result, all\n   products of the trigonometric functions :func:`Cos` and :func:`Sin`\n   disappear. The function also tries to simplify the resulting expression as\n   much as  possible by combining all similar terms. This function is used in\n   for instance :func:`Integrate`, to bring down the expression into a simpler\n   form that hopefully can be  integrated easily.\n\n   :Example:\n\n   ::\n\n      In> PrettyPrinter'Set(\"PrettyForm\");\n      True\n      In> TrigSimpCombine(Cos(a)^2+Sin(a)^2)\n      1\n      In> TrigSimpCombine(Cos(a)^2-Sin(a)^2)\n      Cos( -2 * a )\n      Out>\n      In> TrigSimpCombine(Cos(a)^2*Sin(b))\n      Sin( b )   Sin( -2 * a + b )\n      -------- + -----------------\n         2               4\n        Sin( -2 * a - b )\n      - -----------------\n               4\n\n\n   .. seealso:: :func:`Simplify`, :func:`Integrate`, :func:`Expand`, :func:`Sin`, :func:`Cos`, :func:`Tan`\n\n"
  },
  {
    "path": "docs/reference_manual/solvers.rst",
    "content": "=======\nSolvers\n=======\n\nBy solving one tries to find a mathematical object that meets certain\ncriteria. This chapter documents the functions that are available to\nhelp find solutions to specific types of problems.\n\nSymbolic Solvers\n----------------\n\n\n.. function:: Solve(eq, var)\n\n   solve an equation\n\n   :param eq: equation to solve\n   :param var: variable to solve for\n\n   This command tries to solve an equation. If {eq} does not contain\n   the  {==} operator, it is assumed that the user wants to solve :math:`eq\n   ==  0`. The result is a list of equations of the form {var ==\n   value}, each  representing a solution of the given equation. The\n   {Where} operator  can be used to substitute this solution in\n   another expression. If the  given equation {eq} does not have any\n   solutions, or if {Solve} is  unable to find any, then an empty list\n   is returned.    The current implementation is far from perfect. In\n   particular, the  user should keep the following points in mind:\n\n\n.. function:: OldSolve(eq, var)\n\n   old version of {Solve}\n\n   :param eq: single identity equation\n   :param var: single variable\n   :param eqlist: list of identity equations\n   :param varlist: list of variables\n\n   This is an older version of {Solve}. It is retained for two\n   reasons. The first one is philosophical: it is good to have\n   multiple  algorithms available. The second reason is more\n   practical: the newer  version cannot handle systems of equations,\n   but {OldSolve} can.    This command tries to solve one or more\n   equations. Use the first form  to solve a single equation and the\n   second one for systems of  equations.    The first calling sequence\n   solves the equation \"eq\" for the variable  \"var\". Use the {==}\n   operator to form the equation.  The value of \"var\" which satisfies\n   the equation, is returned. Note  that only one solution is found\n   and returned.    To solve a system of equations, the second form\n   should be used. It  solves the system of equations contained in the\n   list \"eqlist\" for  the variables appearing in the list \"varlist\". A\n   list of results is  returned, and each result is a list containing\n   the values of the  variables in \"varlist\". Again, at most a single\n   solution is  returned.    The task of solving a single equation is\n   simply delegated to {SuchThat}. Multiple equations are solved\n   recursively:  firstly, an equation is sought in which one of the\n   variables occurs  exactly once; then this equation is solved with\n   {SuchThat}; and finally the solution is substituted in the  other\n   equations by {Eliminate} decreasing the number  of equations by\n   one. This suffices for all linear equations and a  large group of\n   simple nonlinear equations.\n\n   :Example:\n\n   ::\n\n      In> OldSolve(a+x*y==z,x)\n      Out> (z-a)/y;\n      In> OldSolve({a*x+y==0,x+z==0},{x,y})\n      Out> {{-z,z*a}};\n      This means that \"x = (z-a)/y\" is a solution of the first equation\n      and that \"x = -z\", \"y = z*a\" is a solution of the systems of\n      equations in the second command.\n      An example which {OldSolve} cannot solve:\n      In> OldSolve({x^2-x == y^2-y,x^2-x == y^3+y},{x,y});\n      Out> {};\n\n\n   .. seealso:: :func:`Solve`, :func:`SuchThat`, :func:`Eliminate`, :func:`PSolve`, :func:`==`\n\n\n.. function:: SuchThat(expr, var)\n\n   special purpose solver\n\n   :param expr: expression to make zero\n   :param var: variable (or subexpression) to solve for\n\n   This functions tries to find a value of the variable \"var\" which\n   makes the expression \"expr\" zero. It is also possible to pass a\n   subexpression as \"var\", in which case {SuchThat}  will try to solve\n   for that subexpression.    Basically, only expressions in which\n   \"var\" occurs only once are  handled; in fact, {SuchThat} may even\n   give wrong  results if the variables occurs more than once. This is\n   a consequence  of the implementation, which repeatedly applies the\n   inverse of the top  function until the variable \"var\" is reached.\n\n   :Example:\n\n   ::\n\n      In> SuchThat(a+b*x, x)\n      Out> (-a)/b;\n      In> SuchThat(Cos(a)+Cos(b)^2, Cos(b))\n      Out> Cos(a)^(1/2);\n      In> A:=Expand(a*x+b*x+c, x)\n      Out> (a+b)*x+c;\n      In> SuchThat(A, x)\n      Out> (-c)/(a+b);\n\n\n   .. seealso:: :func:`Solve`, :func:`OldSolve`, :func:`Subst`, :func:`Simplify`\n\n\n.. function:: Eliminate(var, value, expr)\n\n   substitute and simplify\n\n   :param var: variable (or subexpression) to substitute\n   :param value: new value of \"var\"\n   :param expr: expression in which the substitution should take place\n\n   This function uses {Subst} to replace all instances  of the\n   variable (or subexpression) \"var\" in the expression \"expr\"  with\n   \"value\", calls {Simplify} to simplify the  resulting expression,\n   and returns the result.\n\n   :Example:\n\n   ::\n\n      In> Subst(Cos(b), c) (Sin(a)+Cos(b)^2/c)\n      Out> Sin(a)+c^2/c;\n      In> Eliminate(Cos(b), c, Sin(a)+Cos(b)^2/c)\n      Out> Sin(a)+c;\n\n\n   .. seealso:: :func:`SuchThat`, :func:`Subst`, :func:`Simplify`\n\n\n.. function:: PSolve(poly, var)\n\n   solve a polynomial equation\n\n   :param poly: a polynomial in \"var\"\n   :param var: a variable\n\n   This commands returns a list containing the roots of \"poly\",\n   considered as a polynomial in the variable \"var\". If there is only\n   one root, it is not returned as a one-entry list but just by\n   itself. A double root occurs twice in the result, and similarly for\n   roots of higher multiplicity. All polynomials of degree up to 4 are\n   handled.\n\n   :Example:\n\n   ::\n\n      In> PSolve(b*x+a,x)\n      Out> -a/b;\n      In> PSolve(c*x^2+b*x+a,x)\n      Out> {(Sqrt(b^2-4*c*a)-b)/(2*c),(-(b+\n      Sqrt(b^2-4*c*a)))/(2*c)};\n\n\n   .. seealso:: :func:`Solve`, :func:`Factor`\n\n\n.. function:: MatrixSolve(A,b)\n\n   solve a system of equations\n\n   :param A: coefficient matrix\n   :param b: row vector\n\n   {MatrixSolve} solves the matrix equations {A*x = b} using Gaussian\n   Elimination  with Backward substitution. If your matrix is\n   triangular or diagonal, it will  be recognized as such and a faster\n   algorithm will be used.\n\n   :Example:\n\n   ::\n\n      In> A:={{2,4,-2,-2},{1,2,4,-3},{-3,-3,8,-2},{-1,1,6,-3}};\n      Out> {{2,4,-2,-2},{1,2,4,-3},{-3,-3,8,-2},{-1,1,6,-3}};\n      In> b:={-4,5,7,7};\n      Out> {-4,5,7,7};\n      In> MatrixSolve(A,b);\n      Out> {1,2,3,4};\n      Numeric solvers\n\n\nNumeric Solvers\n---------------\n\n\n.. function:: Newton(expr, var, initial, accuracy)\n\n   solve an equation numerically with Newton's method\n\n   :param expr: an expression to find a zero for\n   :param var: free variable to adjust to find a zero\n   :param initial: initial value for \"var\" to use in the search\n   :param accuracy: minimum required accuracy of the result\n   :param min: minimum value for \"var\" to use in the search\n   :param max: maximum value for \"var\" to use in the search\n\n   This function tries to numerically find a zero of the expression\n   {expr}, which should depend only on the variable {var}. It uses\n   the value {initial} as an initial guess.    The function will\n   iterate using Newton's method until it estimates  that it has come\n   within a distance {accuracy} of the correct  solution, and then it\n   will return its best guess. In particular, it  may loop forever if\n   the algorithm does not converge.    When {min} and {max} are\n   supplied, the Newton iteration takes them  into account by\n   returning {Fail} if it failed to find a root in  the given range.\n   Note this doesn't mean there isn't a root, just  that this\n   algorithm failed to find it due to the trial values  going outside\n   of the bounds.\n\n   :Example:\n\n   ::\n\n      In> Newton(Sin(x),x,3,0.0001)\n      Out> 3.1415926535;\n      In> Newton(x^2-1,x,2,0.0001,-5,5)\n      Out> 1;\n      In> Newton(x^2+1,x,2,0.0001,-5,5)\n      Out> Fail;\n\n\n   .. seealso:: :func:`Solve`, :func:`NewtonNum`\n\n\n.. function:: FindRealRoots(p)\n\n   find the real roots of a polynomial\n\n   :param p: a polynomial in {x}\n\n   Return a list with the real roots of :math:`p`. It tries to find the\n   real-valued  roots, and thus requires numeric floating point\n   calculations. The precision  of the result can be improved by\n   increasing the calculation precision.\n\n   :Example:\n\n   ::\n\n      In> p:=Expand((x+3.1)^5*(x-6.23))\n      Out> x^6+9.27*x^5-0.465*x^4-300.793*x^3-\n      1394.2188*x^2-2590.476405*x-1783.5961073;\n      In> FindRealRoots(p)\n      Out> {-3.1,6.23};\n\n\n   .. seealso:: :func:`SquareFree`, :func:`NumRealRoots`, :func:`MinimumBound`, :func:`MaximumBound`, :func:`Factor`\n\n\n.. function:: NumRealRoots(p)\n\n   return the number of real roots of a polynomial\n\n   :param p: a polynomial in ``x``\n\n   Returns the number of real roots of a polynomial :math:`p`.  The\n   polynomial must use the variable ``x`` and no other variables.\n\n   :Example:\n\n   ::\n\n      In> NumRealRoots(x^2-1)\n      Out> 2;\n      In> NumRealRoots(x^2+1)\n      Out> 0;\n\n\n   .. seealso:: :func:`FindRealRoots`, :func:`SquareFree`, :func:`MinimumBound`, :func:`MaximumBound`, :func:`Factor`\n\n\n.. function:: MinimumBound(p)\n\n   return lower bounds on the absolute values of real roots of a polynomial\n\n   :param p: a polynomial in :math:`x`\n\n   Return minimum and maximum bounds for the absolute values of the\n   real  roots of a polynomial {p}. The polynomial has to be converted\n   to one with  rational coefficients first, and be made square-free.\n   The polynomial must use the variable {x}.\n\n   :Example:\n\n   ::\n\n      In> p:=SquareFree(Rationalize((x-3.1)*(x+6.23)))\n      Out> (-40000*x^2-125200*x+772520)/870489;\n      In> MinimumBound(p)\n      Out> 5000000000/2275491039;\n      In> N(%)\n      Out> 2.1973279236;\n      In> MaximumBound(p)\n      Out> 10986639613/1250000000;\n      In> N(%)\n      Out> 8.7893116904;\n\n\n   .. seealso:: :func:`SquareFree`, :func:`NumRealRoots`, :func:`FindRealRoots`, :func:`Factor`\n\nAuxilliary Functions\n--------------------\n\n.. function:: infix Where(expr, x==v)\n\n   substitute result into expression\n\n   :param expr: expression to evaluate\n   :param x: variable to set\n   :param v: value to substitute for variable\n\n   The operator :func:`Where` fills in values for variables, in its simplest\n   form.  It accepts sets of variable/value pairs defined as ``var1==val1 And\n   var2==val2 And ...``    and fills in the corresponding values. Lists of value\n   pairs are also possible, as: ``{var1==val1 And var2==val2, var1==val3 And\n   var2==val4}``. These values might be obtained through :func:`Solve`.\n\n   :Example:\n\n   ::\n\n      In> x^2+y^2 Where x==2\n      Out> y^2+4;\n      In> x^2+y^2 Where x==2 And y==3\n      Out> 13;\n      In> x^2+y^2 Where {x==2 And y==3}\n      Out> {13};\n      In> x^2+y^2 Where {x==2 And y==3,x==4 And y==5}\n      Out> {13,41};\n\n\n   .. seealso:: :func:`Solve`, :func:`AddTo`\n\n.. function:: infix AddTo(eq1,eq2)\n\n   add an equation to a set of equations or set of set of equations\n\n   :param eq: (set of) set of equations\n\n   Given two (sets of) sets of equations, the command AddTo combines\n   multiple sets of equations into one.     A list {a,b} means that a\n   is a solution, OR b is a solution.  AddTo then acts as a AND\n   operation:           (a or b) and (c or d) =>          (a or b)\n   Addto (c or d) =>          (a and c) or (a and d) or (b and c)\n   or (b and d)    This function is useful for adding an identity to\n   an already  existing set of equations. Suppose a solve command\n   returned  {a>=0 And x==a,a<0 And x== -a} from an expression\n   x==Abs(a),  then a new identity a==2 could be added as follows:\n   In> a==2 AddTo {a>=0 And x==a,a<0 And x== -a}         Out> {a==2\n   And a>=0 And x==a,a==2 And a<0           And x== -a};    Passing\n   this set of set of identities back to solve, solve  should\n   recognize that the second one is not a possibility  any more, since\n   a==2 And a<0 can never be true at the same time.\n\n   :Example:\n\n   ::\n\n      In> {A==2,c==d} AddTo {b==3 And d==2}\n      Out> {A==2 And b==3 And d==2,c==d\n      And b==3 And d==2};\n      In> {A==2,c==d} AddTo {b==3, d==2}\n      Out> {A==2 And b==3,A==2 And d==2,c==d\n      And b==3,c==d And d==2};\n\n\n   .. seealso:: :func:`Where`, :func:`Solve`\n\n"
  },
  {
    "path": "docs/reference_manual/special.rst",
    "content": "=================\nSpecial functions\n=================\n\n.. function:: Gamma(x)\n\n   `Euler`_'s `Gamma`_ function\n\n   .. note:: Euler's constant is represented by :const:`gamma` in yacas.\n\n   :Example:\n\n   ::\n\n      In> Gamma(1.3)\n      Out> Gamma(1.3);\n      In> N(Gamma(1.3),30)\n      Out> 0.897470696306277188493754954771;\n      In> Gamma(1.5)\n      Out> Sqrt(Pi)/2;\n      In> N(Gamma(1.5),30);\n      Out> 0.88622692545275801364908374167;\n\n   .. seealso:: :func:`!`, :const:`gamma`\n\n.. function:: Zeta(x)\n\n   `Riemann`_'s `Zeta`_ function\n\n   :Example:\n\n   ::\n\n      In> Precision(30)\n      Out> True;\n      In> Zeta(1)\n      Out> Infinity;\n      In> Zeta(1.3)\n      Out> Zeta(1.3);\n      In> N(Zeta(1.3))\n      Out> 3.93194921180954422697490751058798;\n      In> Zeta(2)\n      Out> Pi^2/6;\n      In> N(Zeta(2));\n      Out> 1.64493406684822643647241516664602;\n\n\n   .. seealso:: :func:`!`\n\n.. function:: Bernoulli(n)\n              Bernoulli(n, x)\n\n   `Bernoulli numbers`_ and `Bernoulli polynomials`_\n\n.. function:: Euler(n)\n              Euler(n, x)\n\n   `Euler numbers`_ and `Euler polynomials`_\n\n   :Example:\n\n   ::\n\n      In> Euler(6)\n      Out> -61;\n      In> A:=Euler(5,x)\n      Out> (x-1/2)^5+(-10*(x-1/2)^3)/4+(25*(x-1/2))/16;\n      In> Simplify(A)\n      Out> (2*x^5-5*x^4+5*x^2-1)/2;\n\n\n   .. seealso:: :func:`Bin`\n\n.. function:: LambertW(x)\n\n   `Lambert`_'s `W-function`_\n\n   :Example:\n\n   ::\n\n      In> LambertW(0)\n      Out> 0;\n      In> N(LambertW(-0.24/Sqrt(3*Pi)))\n      Out> -0.0851224014;\n\n\n   .. seealso:: :func:`Exp`\n\n.. _Bernoulli numbers: https://en.wikipedia.org/wiki/Bernoulli_number\n.. _Bernoulli polynomials: https://en.wikipedia.org/wiki/Bernoulli_polynomials\n.. _Euler: https://en.wikipedia.org/wiki/Leonhard_Euler\n.. _Euler numbers: https://en.wikipedia.org/wiki/Euler_number\n.. _Euler polynomials: http://mathworld.wolfram.com/EulerPolynomial.html\n.. _Lambert: https://en.wikipedia.org/wiki/Johann_Heinrich_Lambert\n.. _Riemann: https://en.wikipedia.org/wiki/Bernhard_Riemann\n.. _Gamma: https://en.wikipedia.org/wiki/Gamma_function\n.. _Zeta: https://en.wikipedia.org/wiki/Riemann_zeta_function\n.. _W-function: https://en.wikipedia.org/wiki/Lambert_W_function\n"
  },
  {
    "path": "docs/reference_manual/strings.rst",
    "content": "===================\nString manipulation\n===================\n\n\n.. function:: StringMid'Set(index,substring,string)\n\n   change a substring\n\n   :param index: index of substring to get\n   :param substring: substring to store\n   :param string: string to store substring in\n\n   Set (change) a part of a string. It leaves the original alone,\n   returning a new changed copy.\n\n   :Example:\n\n   ::\n\n      In> StringMid'Set(3,\"XY\",\"abcdef\")\n      Out> \"abXYef\";\n\n   .. seealso:: :func:`StringMid'Get`, :func:`Length`\n\n\n.. function:: StringMid'Get(index,length,string)\n\n   retrieve a substring\n\n   :param index: index of substring to get\n   :param length: length of substring to get\n   :param string: string to get substring from\n\n   {StringMid'Get} returns a part of a string. Substrings can also be\n   accessed using the {[]} operator.\n\n   :Example:\n\n   ::\n\n      In> StringMid'Get(3,2,\"abcdef\")\n      Out> \"cd\";\n      In> \"abcdefg\"[2 .. 4]\n      Out> \"bcd\";\n\n   .. seealso:: :func:`StringMid'Set`, :func:`Length`\n\n\n.. function:: Atom(\"string\")\n\n   convert string to atom\n\n   :param \"string\": a string\n\n   Returns an atom with the string representation given as the\n   evaluated argument. Example: {Atom(\"foo\");} returns {foo}.\n\n   :Example:\n\n   ::\n\n      In> Atom(\"a\")\n      Out> a;\n\n   .. seealso:: :func:`String`\n\n\n.. function:: String(atom)\n\n   convert atom to string\n\n   :param atom: an atom\n\n\n   {String} is the inverse of {Atom}: turns {atom} into {\"atom\"}.\n\n   :Example:\n\n   ::\n\n      In> String(a)\n      Out> \"a\";\n\n   .. seealso:: :func:`Atom`\n\n\n.. function:: ConcatStrings(strings)\n\n   concatenate strings\n\n   :param strings: one or more strings\n\n   Concatenates strings.\n\n   :Example:\n\n   ::\n\n      In> ConcatStrings(\"a\",\"b\",\"c\")\n      Out> \"abc\";\n\n   .. seealso:: :func:`Concat`\n\n\n.. function:: PatchString(string)\n\n   execute commands between ``<?`` and ``?>`` in strings\n\n   :param string: a string to patch\n\n   This function does the same as :func:`PatchLoad`, but it works on a string\n   instead of on the contents of a text file. See :func:`PatchLoad` for more\n   details.\n\n   :Example:\n\n   ::\n\n      In> PatchString(\"Two plus three is <? Write(2+3); ?> \");\n      Out> \"Two plus three is 5 \";\n\n   .. seealso:: :func:`PatchLoad`\n\n"
  },
  {
    "path": "docs/reference_manual/univariate-polynomials.rst",
    "content": "=========================\nOperations on polynomials\n=========================\n\nThis chapter contains commands to manipulate polynomials. This\nincludes functions for constructing and evaluating orthogonal\npolynomials.\n\n.. function:: Expand(expr)\n              Expand(expr,var)\n              Expand(expr,varlist)\n\n   transform a polynomial to an expanded form\n\n   :param expr: a polynomial expression\n   :param var: a variable\n   :param varlist: a list of variables\n\n   This command brings a polynomial in expanded form, in which\n   polynomials are represented in the form   :math:`c_0 + c_1x + c_2x^2 + ...\n   + c_nx^n`. In this form, it is   easier to test whether a\n   polynomial is zero, namely by testing  whether all coefficients are\n   zero.    If the polynomial {expr} contains only one variable, the\n   first  calling sequence can be used. Otherwise, the second form\n   should be  used which explicitly mentions that {expr} should be\n   considered as a  polynomial in the variable {var}. The third\n   calling form can be used  for multivariate polynomials. Firstly,\n   the polynomial {expr} is  expanded with respect to the first\n   variable in {varlist}. Then the  coefficients are all expanded with\n   respect to the second variable, and  so on.\n\n   :Example:\n\n   ::\n\n      In> Expand((1+x)^5)\n      Out> x^5+5*x^4+10*x^3+10*x^2+5*x+1\n      In> Expand((1+x-y)^2, x);\n      Out> x^2+2*(1-y)*x+(1-y)^2\n      In> Expand((1+x-y)^2, {x,y})\n      Out> x^2+((-2)*y+2)*x+y^2-2*y+1\n\n\n   .. seealso:: :func:`ExpandBrackets`\n\n.. function:: Degree(expr,[var])\n\n   degree of a polynomial\n\n   :param expr: a polynomial\n   :param var: a variable occurring in {expr}\n\n   This command returns the\n   `degree <http://en.wikipedia.org/wiki/Degree_of_a_polynomial>`_ of the\n   polynomial ``expr`` with respect to the variable ``var``. If only one\n   variable occurs in ``expr``, the first calling sequence can be used.\n   Otherwise the user should use the second form in which the variable is\n   explicitly mentioned.\n\n   :Example:\n\n   ::\n\n      In> Degree(x^5+x-1);\n      Out> 5;\n      In> Degree(a+b*x^3, a);\n      Out> 1;\n      In> Degree(a+b*x^3, x);\n      Out> 3;\n\n\n   .. seealso:: :func:`Expand`, :func:`Coef`\n\n.. function:: Coef(expr, var, order)\n\n   coefficient of a polynomial\n\n   :param expr: a polynomial\n   :param var: a variable occurring in {expr}\n   :param order: integer or list of integers\n\n   This command returns the coefficient of {var} to the power {order}\n   in the polynomial {expr}. The parameter {order} can also be a list\n   of integers, in which case this function returns a list of\n   coefficients.\n\n   :Example:\n\n   ::\n\n      In> e := Expand((a+x)^4,x)\n      Out> x^4+4*a*x^3+(a^2+(2*a)^2+a^2)*x^2+\n      (a^2*2*a+2*a^3)*x+a^4;\n      In> Coef(e,a,2)\n      Out> 6*x^2;\n      In> Coef(e,a,0 .. 4)\n      Out> {x^4,4*x^3,6*x^2,4*x,1};\n\n\n   .. seealso:: :func:`Expand`, :func:`Degree`, :func:`LeadingCoef`\n\n.. function:: Content(expr)\n\n   content of a univariate polynomial\n\n   :param expr: univariate polynomial\n\n   This command determines the\n   `content <https://en.wikipedia.org/wiki/Primitive_part_and_content>`_\n   of a univariate polynomial.\n\n   :Example:\n\n   ::\n\n      In> poly := 2*x^2 + 4*x;\n      Out> 2*x^2+4*x;\n      In> c := Content(poly);\n      Out> 2*x;\n      In> pp := PrimitivePart(poly);\n      Out> x+2;\n      In> Expand(pp*c);\n      Out> 2*x^2+4*x;\n\n\n   .. seealso:: :func:`PrimitivePart`, :func:`Gcd`\n\n.. function:: PrimitivePart(expr)\n\n   primitive part of a univariate polynomial\n\n   :param expr: univariate polynomial\n\n   This command determines the `primitive part\n   <https://en.wikipedia.org/wiki/Primitive_part_and_content>`_ of a univariate\n   polynomial. The primitive part is what remains after the content is divided\n   out. So the  product of the content and the primitive part equals the\n   original  polynomial.\n\n   :Example:\n\n   ::\n\n      In> poly := 2*x^2 + 4*x;\n      Out> 2*x^2+4*x;\n      In> c := Content(poly);\n      Out> 2*x;\n      In> pp := PrimitivePart(poly);\n      Out> x+2;\n      In> Expand(pp*c);\n      Out> 2*x^2+4*x;\n\n\n   .. seealso:: :func:`Content`\n\n.. function:: LeadingCoef(poly)\n              LeadingCoef(poly, var)\n\n   leading coefficient of a polynomial\n\n   This function returns the `leading coefficient\n   <https://en.wikipedia.org/wiki/Coefficient>`_ of ``poly``, regarded as  a\n   polynomial in the variable ``var``. The leading coefficient is the\n   coefficient of the term of highest degree. If only one variable  appears in\n   the expression ``poly``, it is obvious that it should be  regarded as a\n   polynomial in this variable and the first calling  sequence may be used.\n\n   :Example:\n\n   ::\n\n      In> poly := 2*x^2 + 4*x;\n      Out> 2*x^2+4*x;\n      In> lc := LeadingCoef(poly);\n      Out> 2;\n      In> m := Monic(poly);\n      Out> x^2+2*x;\n      In> Expand(lc*m);\n      Out> 2*x^2+4*x;\n      In> LeadingCoef(2*a^2 + 3*a*b^2 + 5, a);\n      Out> 2;\n      In> LeadingCoef(2*a^2 + 3*a*b^2 + 5, b);\n      Out> 3*a;\n\n\n   .. seealso:: :func:`Coef`, :func:`Monic`\n\n.. function:: Monic(poly)\n              Monic(poly, var)\n\n   monic part of a polynomial\n\n   This function returns the monic part of ``poly``, regarded as a polynomial in\n   the variable ``var``. The monic part of a polynomial is the quotient of this\n   polynomial by its leading coefficient. So the leading coefficient of the\n   monic part is always one. If only one variable appears in the expression\n   ``poly``, it is obvious that it should be regarded as a polynomial in this\n   variable and the first calling sequence may be used.\n\n   :Example:\n\n   ::\n\n      In> poly := 2*x^2 + 4*x;\n      Out> 2*x^2+4*x;\n      In> lc := LeadingCoef(poly);\n      Out> 2;\n      In> m := Monic(poly);\n      Out> x^2+2*x;\n      In> Expand(lc*m);\n      Out> 2*x^2+4*x;\n      In> Monic(2*a^2 + 3*a*b^2 + 5, a);\n      Out> a^2+(a*3*b^2)/2+5/2;\n      In> Monic(2*a^2 + 3*a*b^2 + 5, b);\n      Out> b^2+(2*a^2+5)/(3*a);\n\n\n   .. seealso:: :func:`LeadingCoef`\n\n.. function:: SquareFree(p)\n\n   return the square-free part of polynomial\n\n   :param p: a polynomial in {x}\n\n   Given a polynomial :math:`p = p_1^{n_1}\\ldots p_m^{n_m}`  with irreducible\n   polynomials :math:`p_i`,  return the square-free version part (with all the\n   factors having multiplicity 1):  :math:`p_1\\ldots p_m`\n\n   :Example:\n\n   ::\n\n      In> Expand((x+1)^5)\n      Out> x^5+5*x^4+10*x^3+10*x^2+5*x+1;\n      In> SquareFree(%)\n      Out> (x+1)/5;\n      In> Monic(%)\n      Out> x+1;\n\n\n   .. seealso:: :func:`FindRealRoots`, :func:`NumRealRoots`, :func:`MinimumBound`, :func:`MaximumBound`, :func:`Factor`\n\n.. function:: SquareFreeFactorize(p,x)\n\n   return square-free decomposition of polynomial\n\n   :param p: a polynomial in {x}\n\n   Given a polynomial :math:`p` having square-free decomposition :math:`p =\n   p_1^{n_1}\\ldots p_m^{n_m}`  where :math:`p_i` are square-free and\n   :math:`n_{i+1}>n_i`,  return the list of pairs (:math:`p_i`, :math:`n_i`)\n\n   :Example:\n\n   ::\n\n      In> Expand((x+1)^5)\n      Out> x^5+5*x^4+10*x^3+10*x^2+5*x+1\n      In> SquareFreeFactorize(%,x)\n      Out> {{x+1,5}}\n\n\n   .. seealso:: :func:`Factor`\n\n.. function:: Horner(expr, var)\n\n   convert a polynomial into the Horner form\n\n   This command turns the polynomial ``expr``, considered as a univariate\n   polynomial in ``var``, into the Horner form. A polynomial in normal form  is\n   an expression such as  :math:`c_0 + c_1x + \\ldots + c_nx^n`. If one converts\n   this polynomial into Horner form, one gets the  equivalent expression\n   :math:`(\\ldots( c_nx + c_{n-1}) x + \\ldots  + c_1)x + c_0`. Both expression\n   are equal, but the latter form gives a more  efficient way to evaluate the\n   polynomial as  the powers have  disappeared.\n\n   :Example:\n\n   ::\n\n      In> expr1:=Expand((1+x)^4)\n      Out> x^4+4*x^3+6*x^2+4*x+1;\n      In> Horner(expr1,x)\n      Out> (((x+4)*x+6)*x+4)*x+1;\n\n\n   .. seealso:: :func:`Expand`, :func:`ExpandBrackets`, :func:`EvaluateHornerScheme`\n\n.. function:: ExpandBrackets(expr)\n\n   expand all brackets\n\n   This command tries to expand all the brackets by repeatedly using the\n   distributive laws :math:`a(b+c) = ab + ac` and :math:`(a+b)c = ac + bc`. It\n   goes further than :func:`Expand`, in that it expands all brackets.\n\n   :Example:\n\n   ::\n\n      In> Expand((a-x)*(b-x),x)\n      Out> x^2-(b+a)*x+a*b;\n      In> Expand((a-x)*(b-x),{x,a,b})\n      Out> x^2-(b+a)*x+b*a;\n      In> ExpandBrackets((a-x)*(b-x))\n      Out> a*b-x*b+x^2-a*x;\n\n   .. seealso:: :func:`Expand`\n\n.. function:: EvaluateHornerScheme(coeffs,x)\n\n   fast evaluation of polynomials\n\n   This function evaluates a polynomial given as a list of its coefficients,\n   using the `Horner scheme <https://en.wikipedia.org/wiki/Horner%27s_method>`_.\n   The list of coefficients starts with the :math:`0`-th power.\n\n.. function:: OrthoP(n, x)\n              OrthoP(n, a, b, x)\n\n   Legendre and Jacobi orthogonal polynomials\n\n   The first calling format with two arguments evaluates the `Legendre\n   polynomial <https://en.wikipedia.org/wiki/Legendre_polynomials>`_  of degree\n   ``n`` at the point ``x``. The second form does the same for the `Jacobi\n   polynomial <https://en.wikipedia.org/wiki/Jacobi_polynomials>`_ with\n   parameters ``a`` and ``b``, which should be both greater than :math:`-1`.\n\n   The Jacobi polynomials are orthogonal with respect to the weight  function\n   :math:`(1-x)^a(1+x)^b` on the interval :math:`[-1,1]`. They satisfy the\n   recurrence relation :math:`P(n,a,b,x) =\n   \\frac{2n+a+b-1}{2n+a+b-2}\\frac{a^2-b^2+x(2n+a+b-2)(n+a+b)}{2n(n+a+b)}P(n-1,a,b,x) -\n   \\frac{(n+a-1)(n+b-1)(2n+a+b)}{n(n+a+b)(2n+a+b-2)}P(n-2,a,b,x)` for\n   :math:`n > 1`, with  :math:`P(0,a,b,x) = 1`,  :math:`P(1,a,b,x) =\n   \\frac{a-b}{2}+x(1+\\frac{a+b}{2})`.\n\n.. function:: OrthoH(n, x)\n\n   Hermite orthogonal polynomials\n\n   This function evaluates the `Hermite polynomial\n   <https://en.wikipedia.org/wiki/Hermite_polynomials>`_ of degree ``n`` at the\n   point ``x``.\n\n   The Hermite polynomials are orthogonal with respect to the weight function\n   :math:`\\exp(\\frac{-x^2}{2})` on the entire real axis. They satisfy the\n   recurrence relation  :math:`H(n,x) = 2xH(n-1,x) - 2(n-1)H(n-2,x)` for\n   :math:`n > 1`, with  :math:`H(0,x) = 1`,  :math:`H(1,x) = 2x`.\n\n   :Example:\n\n   ::\n\n      In> OrthoH(3, x);\n      Out> x*(8*x^2-12);\n      In> OrthoH(6, 0.5);\n      Out> 31;\n\n   .. seealso:: :func:`OrthoHSum`, :func:`OrthoPoly`\n\n.. function:: OrthoG(n, a, x)\n\n   Gegenbauer orthogonal polynomials\n\n   This function evaluates the `Gegenbauer (or ultraspherical) polynomial\n   <https://en.wikipedia.org/wiki/Gegenbauer_polynomials>`_ with parameter ``a``\n   and degree ``n`` at the point ``x``. The parameter ``a`` should be greater\n   than :math:`-\\frac{1}{2}`.\n\n   The Gegenbauer polynomials are orthogonal with respect to the weight function\n   :math:`(1-x^2)^{a-\\frac{1}{2}}` on the interval :math:`[-1,1]`. Hence they are\n   connected to the Jacobi polynomials via :math:`G(n, a, x) = P(n, a-\\frac{1}{2},\n   a-\\frac{1}{2}, x)`. They satisfy the recurrence relation :math:`G(n,a,x) =\n   2(1+\\frac{a-1}{n})xG(n-1,a,x)-(1+2\\frac{a-2}{n})G(n-2,a,x)`  for :math:`n>1`,\n   with :math:`G(0,a,x) = 1`, :math:`G(1,a,x) = 2x`.\n\n.. function:: OrthoL(n, a, x)\n\n   Laguerre orthogonal polynomials\n\n   This function evaluates the `Laguerre polynomial\n   <https://en.wikipedia.org/wiki/Laguerre_polynomials>`_ with parameter ``a``\n   and degree ``n`` at the point ``x``. The parameter ``a`` should be greater\n   than :math:`-1`.\n\n   The Laguerre polynomials are orthogonal with respect to the weight function\n   :math:`x^a\\exp(-x)` on the positive real axis. They satisfy the  recurrence\n   relation  :math:`L(n,a,x) = (2+\\frac{a-1-x}{n})L(n-1,a,x)\n   -(1-\\frac{a-1}{n})L(n-2,a,x)`  for :math:`n>1`, with   :math:`L(0,a,x) = 1`,\n   :math:`L(1,a,x) = a + 1 - x`.\n\n.. function:: OrthoT(n, x)\n              OrthoU(n, x)\n\n   Chebyshev polynomials\n\n   These functions evaluate the `Chebyshev polynomials\n   <https://en.wikipedia.org/wiki/Chebyshev_polynomials>`_ of the first kind\n   :math:`T(n,x)` and of the second kind :math:`U(n,x)`, of degree ``n`` at the\n   point ``x``. (The  name of this Russian mathematician is also sometimes\n   spelled Tschebyscheff.)\n\n   The Chebyshev polynomials are orthogonal with respect to the weight  function\n   :math:`(1-x^2)^{-\\frac{1}{2}}`. Hence they are a special case of the Gegenbauer\n   polynomials :math:`G(n,a,x)`, with :math:`a=0`. They satisfy the recurrence\n   relations  :math:`T(n,x) = 2xT(n-1,x) - T(n-2,x)`,  :math:`U(n,x) =\n   2xU(n-1,x) - U(n-2,x)`  for :math:`n > 1`, with  :math:`T(0,x) = 1`,\n   :math:`T(1,x) = x`, :math:`U(0,x) = 1`, :math:`U(1,x) = 2x`.\n\n   :Example:\n\n   ::\n\n      In> OrthoT(3, x);\n      Out> 2*x*(2*x^2-1)-x;\n      In> OrthoT(10, 0.9);\n      Out> -0.2007474688;\n      In> OrthoU(3, x);\n      Out> 4*x*(2*x^2-1);\n      In> OrthoU(10, 0.9);\n      Out> -2.2234571776;\n\n   .. seealso:: :func:`OrthoG`, :func:`OrthoTSum`, :func:`OrthoUSum`, :func:`OrthoPoly`\n\n.. function:: OrthoPSum(c, x)\n              OrthoPSum(c, a, b, x)\n              OrthoGSum(c, a, x)\n              OrthoHSum(c, x)\n              OrthoLSum(c, a, x)\n              OrthoTSum(c, x)\n              OrthoUSum(c, x)\n\n   sums of series of orthogonal polynomials\n\n   These functions evaluate the sum of series of orthogonal polynomials at the\n   point ``x``, with given list of coefficients ``c`` of the series and fixed\n   polynomial parameters ``a``, ``b`` (if applicable). The list of coefficients\n   starts with the lowest order, so that for example  ``OrthoLSum(c, a, x) = c[1]\n   L[0](a,x) + c[2] L[1](a,x) + ... + c[N] L[N-1](a,x)``.\n\n   See pages for specific orthogonal polynomials for more details on the\n   parameters of the polynomials.  Most of the work is performed by the internal\n   function :func:`OrthoPolySum`. The individual polynomials entering the series\n   are not computed, only the sum of the series.\n\n   :Example:\n\n   ::\n\n      In> Expand(OrthoPSum({1,0,0,1/7,1/8}, 3/2, 2/3, x));\n      Out> (7068985*x^4)/3981312+(1648577*x^3)/995328+\n      (-3502049*x^2)/4644864+(-4372969*x)/6967296\n      +28292143/27869184\n\n\n   .. seealso:: :func:`OrthoP`, :func:`OrthoG`, :func:`OrthoH`, :func:`OrthoL`, :func:`OrthoT`, :func:`OrthoU`, :func:`OrthoPolySum`\n\n.. function:: OrthoPoly(name, n, params, x)\n\n   internal function for constructing orthogonal polynomials\n\n   This function is used internally to construct orthogonal polynomials. It\n   returns the ``n``-th polynomial from the family ``name`` with parameters\n   ``params`` at the point ``x``. All known families are stored in the\n   association list returned by the function :func:`KnownOrthoPoly`. The\n   ``name`` serves as key.\n\n   At the moment the following names are known to yacas: ``\"Jacobi\"``,\n   ``\"Gegenbauer\"``, ``\"Laguerre\"``, ``\"Hermite\"``, ``\"Tscheb1\"``, and\n   ``\"Tscheb2\"``. The value associated to the key is a pure function that takes\n   two arguments: the order ``n`` and the  extra parameters ``p``, and returns a\n   list of two lists: the first list  contains the coefficients ``{A,B}`` of the\n   ``n=1`` polynomial, i.e. :math:`A+Bx`;  the second list contains the\n   coefficients ``{A,B,C}`` in the recurrence  relation, i.e. :math:`P_n =\n   (A+Bx)P_{n-1}+CP_{n-2}`.\n\n   .. note::\n     There are only 3 coefficients in the second list, because none of the\n     considered polynomials use :math:`C+Dx` instead of :math:`C` in the\n     recurrence relation. This is assumed in the implementation.\n\n   If the argument ``x`` is numerical, the function :func:`OrthoPolyNumeric` is\n   called. Otherwise, the function :func:`OrthoPolyCoeffs` computes a list of\n   coefficients, and :func:`EvaluateHornerScheme` converts this list into a\n   polynomial expression.\n\n   .. seealso:: :func:`OrthoP`, :func:`OrthoG`, :func:`OrthoH`, :func:`OrthoL`, :func:`OrthoT`, :func:`OrthoU`, :func:`OrthoPolySum`\n\n.. function:: OrthoPolySum(name, c, params, x)\n\n   internal function for computing series of orthogonal polynomials\n\n   This function is used internally to compute series of orthogonal polynomials.\n   It is similar to the function :func:`OrthoPoly` and returns the result of the\n   summation of series of polynomials from the family ``name`` with parameters\n   ``params``  at the point ``x``, where ``c`` is the list of coefficients of\n   the series. The algorithm used to compute the series without first computing\n   the individual polynomials is the Clenshaw-Smith recurrence scheme.  (See the\n   algorithms book for explanations.)\n\n   If the argument ``x`` is numerical, the function :func:`OrthoPolySumNumeric`\n   is called. Otherwise, the function :func:`OrthoPolySumCoeffs` computes the\n   list of coefficients  of the resulting polynomial, and\n   :func:`EvaluateHornerScheme` converts this list into a polynomial expression.\n\n   .. seealso:: :func:`OrthoPSum`, :func:`OrthoGSum`, :func:`OrthoHSum`, :func:`OrthoLSum`, :func:`OrthoTSum`, :func:`OrthoUSum`, :func:`OrthoPoly`\n\n"
  },
  {
    "path": "docs/reference_manual/vars.rst",
    "content": "=========\nVariables\n=========\n\n.. function:: infix :=(var,expr)\n              infix :=(var[i],expr)\n              infix :=(varlist,exprlist)\n              infix :=(fn,expr)\n\n   assign a variable or a list; define a function\n\n   var := expr\n   {var1, var2, ...} := {expr1, expr2, ...}\n   var[i] := expr\n   fn(arg1, arg2, ...) := expr\n\n   :param var: atom, variable which should be assigned\n   :param expr: expression to assign to the variable or body of function\n   :param i: index (can be integer or string)\n   :param fn: atom, name of a new function to define\n   :param arg1, arg2: atoms, names of arguments of the new function {fn}\n\n   The :func:`:=` operator can be used in a number of ways. In all\n   cases, some sort of assignment or definition takes place.  The\n   first form is the most basic one. It evaluates the expression on\n   the right-hand side and assigns it to the variable named on the\n   left-hand side. The left-hand side is not evaluated. The evaluated\n   expression is also returned.  The second form is a small extension,\n   which allows one to do multiple assignments. The first entry in the\n   list on the right-hand side is assigned to the first variable\n   mentioned in the left-hand side, the second entry on the right-hand\n   side to the second variable on the left-hand side, etc.  The list\n   on the right-hand side must have at least as many entries as the\n   list on the left-hand side. Any excess entries are silently\n   ignored. The result of the expression is the list of values that\n   have been assigned.  The third form allows one to change an entry\n   in the list. If the index \"i\" is an integer, the \"i\"-th entry in\n   the list is changed to the expression on the right-hand side. It is\n   assumed that the length of the list is at least \"i\". If the index\n   \"i\" is a string, then \"var\" is considered to be an associative list\n   (sometimes called hash table), and the key \"i\" is paired with the\n   value \"exp\". In both cases, the right-hand side is evaluated before\n   the assignment and the result of the assignment is :data:`True`.  The\n   last form defines a function. For example, the assignment {fn(x) :=\n   x^2} removes any rules previously associated with {fn(x)} and\n   defines the rule {fn(_x) <-- x^2}. Note that the left-hand side may\n   take a different form if {fn} is defined to be a prefix, infix or\n   bodied function. This case is special since the right-hand side is\n   not evaluated immediately, but only when the function {fn} is\n   used. If this takes time, it may be better to force an immediate\n   evaluation with {Eval} (see the last example).  If the expression\n   on the right hand side begins with {Eval()}, then it *will* be\n   evaluated before defining the new function. A variant of the\n   function definition can be used to make a function accepting a\n   variable number of arguments. The last argument\n\n   Simple assignment::\n\n      In> a := Sin(x) + 3;\n      Out> Sin(x)+3;\n      In> a;\n      Out> Sin(x)+3;\n\n   Multiple assignments::\n\n      In> {a,b,c} := {1,2,3};\n      Out> {1,2,3};\n      In> a;\n      Out> 1;\n      In> b+c;\n      Out> 5;\n\n   Assignment to a list::\n\n      In> xs := { 1,2,3,4,5 };\n      Out> {1,2,3,4,5};\n      In> xs[3] := 15;\n      Out> True;\n      In> xs;\n      Out> {1,2,15,4,5};\n\n   Building an associative list::\n\n      In> alist := {};\n      Out> {};\n      In> alist[\"cherry\"] := \"red\";\n      Out> True;\n      In> alist[\"banana\"] := \"yellow\";\n      Out> True;\n      In> alist[\"cherry\"];\n      Out> \"red\";\n      In> alist;\n      Out> {{\"banana\",\"yellow\"},{\"cherry\",\"red\"}};\n\n   Defining a function::\n\n      In> f(x) := x^2;\n      Out> True;\n      In> f(3);\n      Out> 9;\n      In> f(Sin(a));\n      Out> Sin(a)^2;\n\n   Defining a function with variable number of arguments::\n\n      In> f(x, ...) := If(IsList(x),Sum(x),x);\n      Out> True;\n      In> f(2);\n      Out> 2;\n      In> f(1,2,3);\n      Out> 6;\n\n   Defining a new infix operator::\n\n      In> Infix(\"*&*\",10);\n      Out> True;\n      In> x1 *&* x2 := x1/x2 + x2/x1;\n      Out> True;\n      In> Sin(a) *&* Cos(a);\n      Out> Tan(1)+Cos(1)/Sin(1);\n      In> Clear(a);\n      Out> True;\n      In> Sin(a) *&* Exp(a);\n      Out> Sin(a)/Exp(a)+Exp(a)/Sin(a);\n\n   In the following example, it may take some time to compute the Taylor\n   expansion. This has to be done every time the function {f} is called::\n\n      In> f(a) := Taylor(x,0,25) Sin(x);\n      Out> True;\n      In> f(1);\n      Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880-\n      x^11/39916800+x^13/6227020800-x^15/\n      1307674368000+x^17/355687428096000-x^19/\n      121645100408832000+x^21/51090942171709440000\n      -x^23/25852016738884976640000+x^25\n      /15511210043330985984000000;\n      In> f(2);\n      Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880-\n      x^11/39916800+x^13/6227020800-x^15\n      /1307674368000+x^17/355687428096000-x^19/\n      121645100408832000+x^21/51090942171709440000\n      -x^23/25852016738884976640000+x^25/\n      15511210043330985984000000;\n\n   The remedy is to evaluate the Taylor expansion immediately. Now the\n   expansion is computed only once::\n\n      In> f(a) := Eval(Taylor(x,0,25) Sin(x));\n      Out> True;\n      In> f(1);\n      Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880-\n      x^11/39916800+x^13/6227020800-x^15/\n      1307674368000+x^17/355687428096000-x^19/\n      121645100408832000+x^21/51090942171709440000\n      -x^23/25852016738884976640000+x^25\n      /15511210043330985984000000;\n      In> f(2);\n      Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880-\n      x^11/39916800+x^13/6227020800-x^15\n      /1307674368000+x^17/355687428096000-x^19/\n      121645100408832000+x^21/51090942171709440000\n      -x^23/25852016738884976640000+x^25/\n      15511210043330985984000000;\n      \n\n   .. seealso:: :func:`Set`, :func:`Clear`, :func:`[]`, :func:`Rule`, :func:`Infix`, :func:`Eval`, :func:`Function`\n\n.. function:: Set(var, exp)\n\n   assignment\n\n   :param var: variable which should be assigned\n   :param exp: expression to assign to the variable\n\n   The expression \"exp\" is evaluated and assigned it to the variable\n   named \"var\". The first argument is not evaluated. The value True\n   is returned.    The statement {Set(var, exp)} is equivalent to {var\n   := exp}, but the {:=} operator  has more uses, e.g. changing\n   individual entries in a list.\n\n   :Example:\n\n   ::\n\n      In> Set(a, Sin(x)+3);\n      Out> True;\n      In> a;\n      Out> Sin(x)+3;\n      \n\n   .. seealso:: :func:`Clear`, :func:`:=`\n\n.. function:: Clear(var, ...)\n\n   undo an assignment\n\n   :param var: name of the variable to be cleared\n\n   All assignments made to the variables listed as arguments are\n   undone. From now on, all these variables remain unevaluated (until\n   a  subsequent assignment is made). The result of the expression is\n   True.\n\n   :Example:\n\n   ::\n\n      In> a := 5;\n      Out> 5;\n      In> a^2;\n      Out> 25;\n      In> Clear(a);\n      Out> True;\n      In> a^2;\n      Out> a^2;\n      \n\n   .. seealso:: :func:`Set`, :func:`:=`\n\n.. function:: Local(var, ...)\n\n   declare new local variables\n\n   :param var: name of the variable to be declared as local\n\n   All variables in the argument list are declared as local\n   variables. The arguments are not evaluated. The value ``True`` is\n   returned.  By default, all variables in Yacas are global. This\n   means that the variable has the same value everywhere. But\n   sometimes it is useful to have a private copy of some variable,\n   either to prevent the outside world from changing it or to prevent\n   accidental changes to the outside world. This can be achieved by\n   declaring the variable local. Now only expressions within the\n   :func:`Prog` block (or its syntactic equivalent, the ``[]``\n   block) can access and change it. Functions called within this block\n   cannot access the local copy unless this is specifically allowed\n   with :func:`UnFence`.\n\n   :Example:\n\n   ::\n\n      In> a := 3;\n      Out> 3;\n      In> [ a := 4; a; ];\n      Out> 4;\n      In> a;\n      Out> 4;\n      In> [ Local(a); a := 5; a; ];\n      Out> 5;\n      In> a;\n      Out> 4;\n\n   In the first block, ``a`` is not declared local and hence defaults\n   to be a global variable. Indeed, changing the variable inside the\n   block also changes the value of ``a`` outside the block. However,\n   in the second block ``a`` is defined to be local and now the value\n   outside the block stays the same, even though ``a`` is assigned the\n   value 5 inside the block.\n      \n\n   .. seealso:: :func:`LocalSymbols`, :func:`Prog`, :func:`[]`, :func:`UnFence`\n\n.. function:: postfix ++(var)\n\n   increment variable\n\n   :param var: variable to increment\n\n   The variable with name ``var`` is incremented, i.e. the number 1 is\n   added to it. The expression ``x++`` is equivalent to the assignment\n   ``x := x + 1``, except that the assignment returns the new value of\n   ``x`` while ``x++`` always returns ``True``. In this respect,\n   Yacas' ``++`` differs from the corresponding operator in the\n   programming language C.\n\n   :Example:\n\n   ::\n\n      In> x := 5;\n      Out> 5;\n      In> x++;\n      Out> True;\n      In> x;\n      Out> 6;\n      \n\n   .. seealso:: :func:`--`, :func:`:=`\n\n.. function:: postfix --(var)\n\n   decrement variable\n\n   :param var: variable to decrement\n\n   The variable with name ``var`` is decremented, i.e. the number 1 is\n   subtracted from it. The expression ``x--`` is equivalent to the\n   assignment ``x := x - 1``, except that the assignment returns the\n   new value of ``x`` while ``x--`` always returns ``True``. In this\n   respect, Yacas' ``--`` differs from the corresponding operator in\n   the programming language C.\n\n   :Example:\n\n   ::\n\n      In> x := 5;\n      Out> 5;\n      In> x--;\n      Out> True;\n      In> x;\n      Out> 4;\n      \n\n   .. seealso:: :func:`++`, :func:`:=`\n\n.. function:: Object(\"pred\", expr)\n\n   create an incomplete type\n\n   :param pred: name of the predicate to apply\n   :param expr: expression on which ``pred`` should be applied\n\n   This function returns \"obj\" as soon as \"pred\" returns :data:`True` when\n   applied on \"obj\". This is used to declare  so-called incomplete\n   types.\n\n   :Example:\n\n   ::\n\n      In> a := Object(\"IsNumber\", x);\n      Out> Object(\"IsNumber\",x);\n      In> Eval(a);\n      Out> Object(\"IsNumber\",x);\n      In> x := 5;\n      Out> 5;\n      In> Eval(a);\n      Out> 5;\n      \n\n   .. seealso:: :func:`IsNonObject`\n\n.. function:: SetGlobalLazyVariable(var,value)\n\n   global variable is to be evaluated lazily\n\n   :param var: variable (held argument)\n   :param value: value to be set to (evaluated before it is assigned)\n\n   :func:`SetGlobalLazyVariable` enforces that a global variable will\n   re-evaluate when used. This functionality doesn't survive if\n   ``Clear(var)`` is called afterwards.  Places where this is used\n   include the global variables ``%`` and ``I``.  The use of lazy in\n   the name stems from the concept of lazy evaluation.  The object the\n   global variable is bound to will only be evaluated when called.\n   The {SetGlobalLazyVariable} property only holds once: after that,\n   the result of evaluation is stored in the global variable, and it\n   won't be reevaluated again::\n\n     In> SetGlobalLazyVariable(a,Hold(Taylor(x,0,30)Sin(x)))\n     Out> True\n\n   Then the first time you call ``a`` it evaluates ``Taylor(...)`` and\n   assigns the result to ``a``. The next time you call ``a`` it\n   immediately returns the result.  :func:`SetGlobalLazyVariable` is\n   called for ``%`` each time ``%`` changes.  The following example\n   demonstrates the sequence of execution::\n\n     In> SetGlobalLazyVariable(test,Hold(Write(\"hello\")))\n     Out> True\n   \n   The text \"hello\" is not written out to screen yet. However,\n   evaluating the variable ``test`` forces the expression to be\n   evaluated::\n\n     In> test = \"hello\"\n     Out> True\n\n   :Example:\n\n   ::\n\n      In> Set(a,Hold(2+3))\n      Out> True\n      In> a\n      Out> 2+3\n      In> SetGlobalLazyVariable(a,Hold(2+3))\n      Out> True\n      In> a\n      Out> 5\n      \n\n   .. seealso:: :func:`Set`, :func:`Clear`, :func:`Local`, :func:`%`, :func:`I`\n\n.. function:: UniqueConstant()\n\n   create a unique identifier\n\n\n   This function returns a unique constant atom each time you call\n   it. The atom starts with a C character, and a unique number is\n   appended to it.\n\n   :Example:\n\n   ::\n\n      In> UniqueConstant()\n      Out> C9\n      In>  UniqueConstant()\n      Out> C10\n      \n\n   .. seealso:: :func:`LocalSymbols`\n\n.. function:: bodied LocalSymbols(expr, var1, var2, ...)\n\n   create unique local symbols with given prefix\n\n   :param var1, var2, ..: atoms, symbols to be made local\n   :param expr: expression to execute\n\n   Given the symbols passed as the first arguments to\n   :func:`LocalSymbols`, a set of unique local symbols will be\n   created, typically of the form ``$<symbol><number>``, where\n   ``symbol`` was the symbol entered by the user, and ``number`` is a\n   unique number. This scheme is used to ensure that a generated\n   symbol can not accidentally be entered by a user.  This is useful\n   in cases where a guaranteed free variable is needed, for example,\n   in the macro-like functions (:func:`For`, :func:`While` etc.).\n\n   :Example:\n\n   ::\n\n      In> LocalSymbols(a,b)a+b\n      Out> :math:`a6+ :math:`b6;\n      \n\n   .. seealso:: :func:`UniqueConstant`\n\n"
  },
  {
    "path": "docs/requirements.txt",
    "content": "sphinxcontrib-bibtex\n\n"
  },
  {
    "path": "docs/tutorial/index.rst",
    "content": ".. _tutorial:\n\n********\nTutorial\n********\n\n.. _syntax:\n\n============\nYacas syntax\n============\n\nExpressions in Yacas are generally built up of words. We will not bore\nyou with the exact definitions of such words, but roughly speaking\nthey are either sequences of alphabetic letters, or a number, or a\nbracket, or space to separate words, or a word built up from symbols\nlike ``+``, ``-``, ``*``, ``<``, *etc.*. If you want, you can mix\nthese different types of characters, by surrounding them with\nquotes. Thus, ``\"This text\"`` is what is called one token, surrounded\nby quotes.\n\nThe usual notation people use when writing down a calculation is\ncalled the infix notation, and you can readily recognize it, as for\nexample ``2+3`` and ``3*4``. Prefix operators also exist. These\noperators come before an expression, like for example the unary minus\nsign (called unary because it accepts one argument), ``-(3*4)``. In\naddition to prefix operators there are also postfix operators, like\nthe exclamation mark to calculate the factorial of a number, ``10!``.\n\nYacas understands standard simple arithmetic expressions. Some\nexamples:\n\n* ``2+3`` (addition)\n* ``2*3`` (multiplication)\n* ``2-3`` (subtraction)\n* ``2^3`` (raising powers)\n* ``2+3*4``\n* ``(2+3)*4``\n* ``6/3`` (division)\n* ``1/3``\n\nDivisions are not reduced to real numbers, but kept as a rational for\nas long as possible, since the rational is an exact correct expression\n(and any real number would just be an approximation). Yacas is able to\nchange a rational in to a number with the function ``N``, for example\n``N(1/3)``.\n\nOperators have *precedence*, meaning that certain operations are done\nfirst before others are done. For example, in ``2+3*4`` the\nmultiplication is performed before the addition. The usual way to\nchange the order of a calculation is with round brackets.  The round\nbrackets in the expression ``(2+3)*4`` will force Yacas to first add 2\nand 3, and then multiply the result.\n\nSimple function calls have their arguments between round brackets,\nseparated by commas. Examples are ``Sin(Pi)`` (which indicates that\nyou are interested in the value of the trigonometric function\n:math:`\\sin` applied to the constant :math:`\\pi`), and\n``Min(5,1,3,-5,10)`` (which should return the lowest of its arguments,\n``-5`` in this case).  Functions usually have the form ``f()``,\n``f(x)`` or ``f(x,y,z,...)`` depending on how many arguments the\nfunction accepts. Functions always return a result.  For example,\n``Cos(0)`` should return ``1``. Evaluating functions can be thought of\nas simplifying an expression as much as possible. Sometimes further\nsimplification is not possible and a function returns itself\nunsimplified, like taking the square root of an integer ``Sqrt(2)``. A\nreduction to a number would be an approximation. We explain elsewhere\nhow to get Yacas to simplify an expression to a number.\n\nYacas allows for use of the infix notation, but with some\nadditions. Functions can be *bodied*, meaning that the last argument\nis written past the close bracket. An example is ``ForEach``, where we\nwrite ``ForEach(item, 1 .. 10) Echo(item);``.  ``Echo(item)`` is the\nlast argument to the function ``ForEach``.\n\nA list is enclosed with curly braces, and is written out with commas between the\nelements, like for example ``{1,2,3}``.  items in lists (and things\nthat can be made to look like lists, like arrays and strings), can\nthen be accessed by indicating the index between square brackets after\nthe object. ``{a,b,c}[2]`` should return ``b``, as ``b`` is the second\nelement in the list (Yacas starts counting from 1 when accessing\nelements). The same can be done with strings: ``\"abc\"[2]``.\n\nAnd finally, function calls can be grouped together, where they get\nexecuted one at a time, and the result of executing the last\nexpression is returned. This is done through square brackets, as ``[\nEcho(\"Hello\"); Echo(\"World\"); True; ];``, which first writes ``Hello``\nto screen, then ``World`` on the next line, and then returns ``True``.\n\nWhen you type in an expression, you have to take in to account the\nfact that Yacas is case-sensitive. This means that a function ``sin``\n(with all lowercase) is a different function from ``Sin`` (which\nstarts with a capital S), and the variable ``v`` is a different one\nfrom ``V``.\n\n=======================================\nUsing Yacas from the calculation center\n=======================================\n\nAs mentioned earlier, you can type in commands on the command line in\nthe calculation center. Typically, you would enter one statement per\nline, for example, click on ``Sin(Pi/2);``. The command line has a memory, \nand remembers results from calculations performed before.  For example, if\nyou define a function on a line (or set a variable to a value), the\ndefined function (or variable) are available to be used in following\nlines. A session can be restarted (forgetting all previous definitions\nand results) by typing ``restart``.  All memory is erased in that\ncase.\n\nStatements should end with a semicolon ``;`` although this is not\nrequired in interactive sessions (Yacas will append a semicolon at end\nof line to finish the statement).\n\nThe command line has a history list, so it should be easy to browse\nthrough the expressions you entered previously using the up and down\narrow keys.\n\nWhen a few characters have been typed, the command line will use the\ncharacters before the cursor as a filter into the history, and allow\nyou to browse through all the commands in the history that start with\nthese characters quickly, instead of browsing through the entire\nhistory. If the system recognized the first few characters, it will\nalso show the commands that start with the sequence entered. You can\nuse the arrow keys to browse through this list, and then select the\nintended function to be inserted by pressing enter.\n\nCommands spanning multiple lines can (and actually have to) be entered\nby using a trailing backslash \\ at end of each continued line. For\nexample, clicking on ``2+3+`` will result in an\nerror, but entering the same with a backslash at the end and then\nentering another expression will concatenate the two lines and\nevaluate the concatenated input.\n\nIncidentally, any text Yacas prints without a prompt is either\na message printed by a function as a side-effect, or an error\nmessage. Resulting values of expressions are always printed after an\n``Out>`` prompt.\n\n==============================\nYacas as a symbolic calculator\n==============================\n\nWe are ready to try some calculations. Yacas uses a C-like\ninfix syntax and is case-sensitive. Here are some exact manipulations\nwith fractions for a start: ``1/14+5/21*(30-(1+1/2)*5^2);``\n\nThe standard scripts already contain a simple math library for\nsymbolic simplification of basic algebraic functions. Any names such\nas ``x`` are treated as independent, symbolic variables and are not\nevaluated by default. Some examples to try:\n\n* ``0+x``\n* ``x+1*y``\n* ``Sin(ArcSin(alpha))+Tan(ArcTan(beta))``\n\nNote that the answers are not just simple numbers here, but actual\nexpressions. This is where Yacas shines. It was built specifically to\ndo calculations that have expressions as answers.\n\nIn Yacas after a calculation is done, you can refer to the previous\nresult with ``%``. For example, we could first type ``(x+1)*(x-1)``,\nand then decide we would like to see a simpler version of that\nexpression, and thus type ``Simplify(%)``,\nwhich should result in ``x^2-1``.\n\nThe special operator ``%`` automatically recalls the result from the\nprevious line.  The function ``Simplify`` attempts to reduce an\nexpression to a simpler form. Note that standard function names in\nYacas are typically capitalized. Multiple capitalization such as\n``ArcSin`` is sometimes used. The underscore character ``_`` is a\nreserved operator symbol and cannot be part of variable or function\nnames.\n\nYacas offers some more powerful symbolic manipulation\noperations. A few will be shown here to wetten the appetite.\n\nSome simple equation solving algorithms are in place:\n\n* ``Solve(x/(1+x) == a, x);``\n* ``Solve(x^2+x == 0, x);``\n* ``Solve(a+x*y==z,x);``\n\n(Note the use of the ``==`` operator, which does not evaluate to\nanything, to denote an \"equation\" object.)\n\nTaylor series are supported, for example: ``Taylor(x,0,3) Exp(x)`` is\na bodied operator that expands ``Exp(x)`` for ``x`` around ``x=0``, up\nto order 3.\n\nSymbolic manipulation is the main application of Yacas. This is\na small tour of the capabilities Yacas currently offers. Note\nthat this list of examples is far from complete. Yacas contains\na few hundred commands, of which only a few are shown here.\n\n* ``Expand((1+x)^5);`` (expand the expression into a polynomial)\n* ``Limit(x,0) Sin(x)/x;`` (calculate the limit of ``Sin(x)/x`` as\n  ``x`` approaches zero)\n* ``Newton(Sin(x),x,3,0.0001);`` (use Newton's method to find the\n  value of ``x`` near ``3`` where ``Sin(x)`` equals zero numerically\n  and stop if the result is closer than ``0.0001`` to the real result)\n* ``DiagonalMatrix({a,b,c});`` (create a matrix with the elements\n  specified in the vector on the diagonal)\n* ``Integrate(x,a,b) x*Sin(x);`` (integrate a function over variable\n  ``x``, from ``a`` to ``b``)\n* ``Factor(x^2-1);`` (factorize a polynomial)\n* ``Apart(1/(x^2-1),x);`` (create a partial fraction expansion of a\n  polynomial)\n* ``Simplify((x^2-1)/(x-1));`` (simplification of expressions)\n* ``CanProve( (a And b) Or (a And Not b) );`` (special-purpose\n  simplifier that tries to simplify boolean expressions as much as\n  possible)\n* ``TrigSimpCombine(Cos(a)*Sin(b));`` (special-purpose simplifier that\n  tries to transform trigonometric expressions into a form where there\n  are only additions of trigonometric functions involved and no\n  multiplications)\n\n===========================\nArbitrary precision numbers\n===========================\n\nYacas can deal with arbitrary precision numbers. It can work with\nlarge integers, like ``20!`` (The ! means factorial, thus\n``1*2*3*...*20``).\n\nAs we saw before, rational numbers will stay rational as long as the\nnumerator and denominator are integers, so ``55/10`` will evaluate to\n``11/2``. You can override this behavior by using the numerical\nevaluation function ``N()``. For example, ``N(55/10)`` will evaluate\nto ``5.5`` . This behavior holds for most math functions. Yacas will\ntry to maintain an exact answer (in terms of integers or fractions)\ninstead of using floating point numbers, unless ``N()`` is used. Where\nthe value for the constant pi is needed, use the built-in variable\n``Pi``. It will be replaced by the (approximate) numerical value when\n``N(Pi)`` is called.  Yacas knows some simplification rules using\n``Pi`` (especially with trigonometric functions).\n\nThe function ``N`` takes either one or two arguments. It evaluates its\nfirst argument and tries to reduce it as much as possible to a\nreal-valued approximation of the expression. If the second argument is\npresent, it states the number of digits precision required. Thus\n``N(1/234)`` returns a number with the current default precision\n(which starts at 20 digits), but you can request as many digits as you\nlike by passing a second argument, as in ``N(1/234, 10)``, ``N(1/234,\n20)``, ``N(1/234, 30)``, etcetera.\n\nNote that we need to enter ``N()`` to force the approximate\ncalculation, otherwise the fraction would have been left unevaluated.\n\nRevisiting ``Pi``, we can get as many digits of ``Pi`` as we like, by\nproviding the precision required as argument to ``N``.  So to get 50\ndigits precision, we can evaluate ``N(Pi,50)``.\n\nTaking a derivative of a function was amongst the very first of\nsymbolic calculations to be performed by a computer, as the operation\nlends itself surprisingly well to being performed\nautomatically. Naturally, it is also implemented in Yacas, through the\nfunction ``D``.  ``D`` is a *bodied* function, meaning that its\nlast argument is past the closing brackets. Where normal functions are\ncalled with syntax similar to ``f(x,y,z)``, a bodied function would be\ncalled with a syntax ``f(x,y)z``. Here are two examples of taking a\nderivative:\n\n* ``D(x) Sin(x);`` (taking a derivative)\n* ``D(x) D(x) Sin(x);`` (taking a derivative twice)\n\nThe :func:`D` function also accepts an argument specifying how many times the\nderivative has to be taken. In that case, the above expressions can also be\nwritten as:\n\n* ``D(x,1) Sin(x);`` (taking a derivative)\n* ``D(x,2) Sin(x);`` (taking a derivative twice)\n\n==================\nAnalytic functions\n==================\n\nMany of the usual analytic functions have been defined in the yacas library.\nExamples are ``Exp(1)``, ``Sin(2)``, ``ArcSin(1/2)``, ``Sqrt(2)``.  These will\nnot evaluate to a numeric result in general, unless the result is an integer,\nlike ``Sqrt(4)``. If asked to reduce the result to a numeric approximation with\nthe function :func:`N`, then *yacas will do so*, as for example in\n``N(Sqrt(2),50)``.\n\n=========\nVariables\n=========\n\nYacas supports variables. You can set the value of a variable with the\n``:=`` infix operator, as in ``a:=1;``. The variable can then be used\nin expressions, and everywhere where it is referred to, it will be\nreplaced by its value.\n\nTo clear a variable binding, execute ``Clear(a);``.  A variable will\nevaluate to itself after a call to clear it (so after the call to\nclear ``a`` above, calling <span class=\"commandlink\">a`` should now\nreturn ``a``).  This is one of the properties of the evaluation scheme\nof Yacas; when some object can not be evaluated or transformed any\nfurther, it is returned as the final result.\n\n=========\nFunctions\n=========\n\nThe ``:=`` operator can also be used to define simple functions:\n``f(x):=2*x*x``.  will define a new function, ``f``, that accepts one\nargument and returns twice the square of that argument.  This function\ncan now be called, ``f(a)``. You can change the definition of a\nfunction by defining it again.\n\nOne and the same function name such as ``f`` may define different\nfunctions if they take different numbers of arguments. One can define\na function ``f`` which takes one argument, as for example\n``f(x):=x^2;``, or two arguments, ``f(x,y):=x*y;``.  If you clicked on\nboth links, both functions should now be defined, and ``f(a)`` calls\nthe one function whereas ``f(a,b)`` calls the other.\n\nYacas is very flexible when it comes to types of mathematical\nobjects. Functions can in general accept or return any type of\nargument.\n\n==================================\nBoolean expressions and predicates\n==================================\n\nYacas predefines :data:`True` and :data:`False` as boolean values. Functions\nreturning boolean values are called *predicates*. For example, :func:`IsNumber`\nand :func:`IsInteger` are predicates defined in the yacas environment. For\nexample, try ``IsNumber(2+x)``, or ``IsInteger(15/5)``.\n\nThere are also comparison operators. Typing ``2 > 1`` would return :data:`True`.\nYou can also use the infix operators ``And`` and ``Or``, and the prefix operator\n``Not``, to make more complex boolean expressions. For example, try ``True And\nFalse``, ``True Or False``, ``True And Not(False)``.\n\n=================\nStrings and lists\n=================\n\nIn addition to numbers and variables, Yacas supports strings and\nlists. Strings are simply sequences of characters enclosed by double\nquotes, for example: ``\"this is a string with \\\"quotes\\\" in it\"``.\n\nLists are ordered groups of items, as usual. Yacas represents lists by\nputting the objects between braces and separating them with\ncommas. The list consisting of objects a, b, and c could be entered by\ntyping ``{a,b,c}``.  In Yacas, vectors are represented as lists and\nmatrices as lists of lists.\n\nItems in a list can be accessed through the ``[ ]`` operator. The\nfirst element has index one. Examples: when you enter\n``uu:={a,b,c,d,e,f};`` then ``uu[2];`` evaluates to ``b``, and\n``uu[2 .. 4];`` evaluates to ``{b,c,d}``. The \"range\" expression\n``2 .. 4`` evaluates to ``{2,3,4}``. Note that spaces around the\n``..`` operator are necessary, or else the parser will not be able to\ndistinguish it from a part of a number.\n\nLists evaluate their arguments, and return a list with results of\nevaluating each element. So, typing ``{1+2,3};`` would evaluate to ``{3,3}``.\n\nThe idea of using lists to represent expressions dates back to the\nlanguage `LISP`_ developed in the 1970's. From a small set of operations\non lists, very powerful symbolic manipulation algorithms can be\nbuilt. Lists can also be used as function arguments when a variable\nnumber of arguments are necessary.\n\n.. _LISP: https://en.wikipedia.org/wiki/Lisp_(programming_language)\n\nLet's try some list operations now. First click on ``m:={a,b,c};`` to\nset up an initial list to work on. Then click on links below:\n\n* ``Length(m)`` (return the length of a list)\n* ``Reverse(m)`` (return the string reversed)\n* ``Concat(m,m)`` (concatenate two strings)\n* ``m[1]:=d`` (setting the first element of the list to a new value, ``d``,\n  as can be verified by evaluating ``m``)\n\nMany more list operations are described in the reference manual.\n\n============================\nWriting simplification rules\n============================\n\nMathematical calculations require versatile transformations on\nsymbolic quantities. Instead of trying to define all possible\ntransformations, Yacas provides a simple and easy to use pattern\nmatching scheme for manipulating expressions according to user-defined\n*rules*. Yacas itself is designed as a small core engine\nexecuting a large library of rules to match and replace patterns.\n\nOne simple application of pattern-matching rules is to define new\nfunctions. (This is actually the only way Yacas can learn about new\nfunctions.) As an example, let's define a function ``f`` that will\nevaluate factorials of non-negative integers. We will define a\npredicate to check whether our argument is indeed a non-negative\ninteger, and we will use this predicate and the obvious recursion\n``f(n)=n*f(n-1) if n>0 and 1 if n=0`` to evaluate the factorial.\n\nWe start with the simple termination condition, which is that ``f(n)``\nshould return one if ``n`` is zero: ``10 # f(0) <-- 1;``. You can verify\nthat this already works for input value zero, with ``f(0)``.\n\nNow we come to the more complex line ``20 # f(n_IsIntegerGreaterThanZero) <--\nn*f(n-1);`` Now we realize we need a function :func:`IsGreaterThanZero`, so we\ndefine this function, with ``IsIntegerGreaterThanZero(_n) <-- (IsInteger(n) And\nn > 0);`` You can verify that it works by trying ``f(5)``, which should return\nthe same value as ``5!``.\n\nIn the above example we have first defined two *simplification rules*\nfor a new function :func:`f`. Then we realized that we need to define a\npredicate :func:`IsIntegerGreaterThanZero`. A predicate equivalent to\n:func:`IsIntegerGreaterThanZero` is actually already defined in the\nstandard library and it's called :func:`IsPositiveInteger`, so it was not\nnecessary, strictly speaking, to define our own predicate to do the\nsame thing. We did it here just for illustration purposes.\n\nThe first two lines recursively define a factorial function\n:math:`f(n)=n(n-1)\\ldots 1`. The rules are given precedence values 10 and\n20, so the first rule will be applied first.  Incidentally, the\nfactorial is also defined in the standard library as a postfix\noperator ! and it is bound to an internal routine much faster than the\nrecursion in our example. The example does show how to create your own\nroutine with a few lines of code. One of the design goals of Yacas was\nto allow precisely that, definition of a new function with very little\neffort.\n\nThe operator ``<--`` defines a rule to be applied to a specific\nfunction. (The ``<--`` operation cannot be applied to an atom.)\nThe ``_n`` in the rule for :func:`IsIntegerGreaterThanZero` specifies\nthat any object which happens to be the argument of that predicate is\nmatched and assigned to the local variable ``n``. The expression to\nthe right of ``<--`` can use ``n`` (without the underscore) as a\nvariable.\n\nNow we consider the rules for the function :func:`f`. The first rule just\nspecifies that ``f(0)`` should be replaced by 1 in any expression. The\nsecond rule is a little more involved.  ``n_IsIntegerGreaterThanZero``\nis a match for the argument of ``f``, with the proviso that the\npredicate ``IsIntegerGreaterThanZero(n)`` should return ``True``,\notherwise the pattern is not matched. The underscore operator is to be\nused only on the left hand side of the rule definition operator\n``<--``.\n\nThere is another, slightly longer but equivalent way of writing the second rule:\n``20 # f(_n)_(IsIntegerGreaterThanZero(n)) <-- n*f(n-1);`` The underscore after\nthe function object denotes a *postpredicate* that should return :data:`True` or\nelse there is no match. This predicate may be a complicated expression involving\nseveral logical operations, unlike the simple checking of just one predicate in\nthe ``n_IsIntegerGreaterThanZero`` construct. The postpredicate can also use the\nvariable ``n`` (without the underscore).\n\nPrecedence values for rules are given by a number followed by the\n``#`` infix operator (and the transformation rule after it). This\nnumber determines the ordering of precedence for the pattern matching\nrules, with 0 the lowest allowed precedence value, i.e. rules with\nprecedence 0 will be tried first. Multiple rules can have the same\nnumber: this just means that it doesn't matter what order these\npatterns are tried in. If no number is supplied, 0 is assumed. In our\nexample, the rule ``f(0) <-- 1`` must be applied earlier than the\nrecursive rule, or else the recursion will never terminate. But as\nlong as there are no other rules concerning the function ``f``, the\nassignment of numbers 10 and 20 is arbitrary, and they could have been\n500 and 501 just as well.  It is usually a good idea however to keep\nsome space between these numbers, so you have room to insert new\ntransformation rules later on.\n\nPredicates can be combined: for example, :func:`IsIntegerGreaterThanZero`\ncould also have been defined as::\n\n   10 # IsIntegerGreaterThanZero(n_IsInteger)_(n>0) <-- True;\n   20 # IsIntegerGreaterThanZero(_n) <-- False;\n\nThe first rule specifies that if ``n`` is an integer, and is greater than\nzero, the result is ``True``, and the second rule states that\notherwise (when the rule with precedence 10 did not apply) the\npredicate returns ``False``.\n\nIn the above example, the expression ``n > 0`` is added after the\npattern and allows the pattern to match only if this predicate return\n``True``. This is a useful syntax for defining rules with complicated\npredicates. There is no difference between the rules\n``F(n_IsPositiveInteger) <-- ...`` and ``F(_n)_(IsPositiveInteger(n))\n<-- ...`` except that the first syntax is a little more concise.\n\nThe rule expression has the following form::\n\n   [precedence #] pattern [_ postpredicate] <-- replacement;\n\nThe optional *precedence* must be a positive integer.\n\nSome more examples of rules (not made clickable because their\nequivalents are already in the basic yacas library)::\n\n   10 # _x + 0 <-- x;\n\n   20 # _x - _x <-- 0;\n\n   ArcSin(Sin(_x)) <-- x;\n\nThe last rule has no explicit precedence specified in it (the precedence\nzero will be assigned automatically by the system).\n\nYacas will first try to match the pattern as a template. Names\npreceded or followed by an underscore can match any one object: a\nnumber, a function, a list, etc. Yacas will assign the relevant\nvariables as local variables within the rule, and try the predicates\nas stated in the pattern. The post-predicate (defined after the\npattern) is tried after all these matched. As an example, the\nsimplification rule ``_x - _x <--0`` specifies that the two objects\nat left and at right of the minus sign should be the same for this\ntransformation rule to apply.\n\n==========================\nLocal simplification rules\n==========================\n\nSometimes you have an expression, and you want to use specific\nsimplification rules on it that should not be universally applied.\nThis can be done with the ``/:`` and the ``/::`` operators.  Suppose\nwe have the expression containing things such as ``Ln(a*b)``, and we\nwant to change these into ``Ln(a)+Ln(b)``. The easiest way to do this\nis using the ``/:`` operator as follows:\n\n* ``Sin(x)*Ln(a*b)`` (example expression without simplification)\n* ``Sin(x)*Ln(a*b) /: {Ln(_x*_y) <- Ln(x)+Ln(y) }`` (with instruction\n  to simplify the expression)\n\nA whole list of simplification rules can be built up in the list, and\nthey will be applied to the expression on the left hand side of\n``/:``.\n\nNote that for these local rules, ``<-`` should be used instead of\n``<--``.  Using latter would result in a global definition of a new\ntransformation rule on evaluation, which is not the intention.\n\nThe ``/:`` operator traverses an expression from the top down, trying\nto apply the rules from the beginning of the list of rules to the end\nof the list of rules. If no rules can be applied to the whole\nexpression, it will try the sub-expressions of the expression being\nanalyzed.\n\nIt might be sometimes necessary to use the ``/::`` operator, which\nrepeatedly applies the ``/:`` operator until the result does not\nchange any more. Caution is required, since rules can contradict each\nother, and that could result in an infinite loop. To detect this\nsituation, just use ``/:`` repeatedly on the expression. The\nrepetitive nature should become apparent.\n\n======================\nProgramming essentials\n======================\n\nAn important feature of yacas is its programming language which\nallows you to create your own programs for doing calculations.  This\nsection describes some constructs and functions for control flow.\n\nLooping can be done with the function :func:`ForEach`. There are more\noptions, but :func:`ForEach` is the simplest to use for now and will suffice\nfor this turorial.  The statement form ``ForEach(x, list) body``\nexecutes its body for each element of the list and assigns the\nvariable ``x`` to that element each time. The statement form\n``While(predicate) body`` repeats execution of the expression\nrepresented by ``body`` until evaluation of the expression represented\nby ``predicate`` returns ``False``.\n\nThis example loops over the integers from one to three, and writes out\na line for each, multiplying the integer by 3 and displaying the\nresult with the function :func:`Echo`::\n\n   ForEach(x,1 .. 5) Echo(x,\" times 3 equals \",3*x);\n\nCompound statements\n-------------------\n\nMultiple statements can be grouped together using the ``[`` and ``]``\nbrackets. The compound ``[a; Echo(\"In the middle\"); 1+2;];`` evaluates\n``a``, then the :func:`Echo` command, and finally evaluates ``1+2``, and\nreturns the result of evaluating the last statement ``1+2``.\n\nA variable can be declared local to a compound statement block by the\nfunction ``Local(var1, var2, ...)``. For example, if you execute\n``[Local(v);v:=1+2;v;];`` the result will be ``3``. The program body\ncreated a variable called ``v``, assigned the value of evaluating\n``1+2`` to it, and made sure the contents of the variable ``v`` were\nreturned.  If you now evaluate ``v`` afterwards you will notice that\nthe variable ``v`` is not bound to a value any more. The variable\n``v`` was defined locally in the program body between the two square\nbrackets ``[`` and ``]``.\n\nConditional execution is implemented by the ::\n\n   If(predicate, body1, body2)\n\nfunction call. If the expression ``predicate`` evaluates to\n``True``, the expression represented by ``body1`` is evaluated,\notherwise ``body2`` is evaluated, and the corresponding value is\nreturned. For example, the absolute value of a number can be computed\nwith: ``f(x) := If(x < 0,-x,x);`` (note that there already is a\nstandard library function that calculates the absolute value of a\nnumber).\n\nVariables can also be made to be local to a small set of functions,\nwith ``LocalSymbols(variables) body``. For example, the following code\nsnippet::\n\n   LocalSymbols(a,b) [\n       a:=0;\n       b:=0;\n       inc():=[a:=a+1;b:=b-1;show();];\n       show():=Echo(\"a = \",a,\" b = \",b);\n   ];\n\ndefines two functions, :func:`inc` and :func:`show`. Calling ``inc()``\nrepeatedly increments ``a`` and decrements ``b``, and calling\n``show()`` then shows the result (the function :func:`inc` also calls the\nfunction :func:`show`, but the purpose of this example is to show how two\nfunctions can share the same variable while the outside world cannot\nget at that variable). The variables are local to these two functions,\nas you can see by evaluating ``a`` and ``b`` outside the scope of\nthese two functions. This feature is very important when writing a\nlarger body of code, where you want to be able to guarantee that there\nare no unintended side-effects due to two bits of code defined in\ndifferent files accidentally using the same global variable.\n\nTo illustrate these features, let us create a list of all even\nintegers from 2 to 20 and compute the product of all those integers\nexcept those divisible by 3::\n\n  [\n      Local(L,i,answer);\n      L:={}; i:=2;\n      /*Make a list of all even integers from 2 to 20 */\n      While (i <= 20) [ L := Append(L, i); i := i + 2; ];\n      /* Now calculate the product of all of these numbers that are not divisible by 3 */\n      answer := 1;\n      ForEach(i,L) If (Mod(i, 3) != 0, answer := answer * i);\n      /* And return the answer */\n      answer;\n  ];\n\n(Note that it is not necessarily the most economical way to do it in\nyacas.)\n\nWe used a shorter form of ``If(predicate, body)`` with only one body\nwhich is executed when the condition holds. If the condition does not\nhold, this function call returns ``False``. We also introduced\ncomments, which can be placed between ``/*`` and ``*/``. Yacas will\nignore anything between those two. When putting a program in a file\nyou can also use ``//``. Everything after ``//`` up until the end of\nthe line will be a comment.  Also shown is the use of the ``While``\nfunction. Its form is ``While (predicate) body``.  While the\nexpression represented by ``predicate`` evaluates to ``True``, the\nexpression represented by ``body`` will keep on being evaluated.\n\nThe above example is not the shortest possible way to write out the\nalgorithm. It is written out in a procedural way, where the program\nexplains step by step what the computer should do. There is nothing\nfundamentally wrong with the approach of writing down a program in a\nprocedural way, but the symbolic nature of Yacas also allows you to\nwrite it in a more concise, elegant, compact way, by combining\nfunction calls.\n\nThere is nothing wrong with procedural style, but there is amore\n'functional' approach to the same problem would go as follows\nbelow. The advantage of the functional approach is that it is shorter\nand more concise (the difference is cosmetic mostly).\n\nBefore we show how to do the same calculation in a functional style,\nwe need to explain what a *pure function* is, as you will need it a\nlot when programming in a functional style. We will jump in with an\nexample that should be self-explanatory. Consider the expression\n``Lambda({x,y},x+y)``.  This has two arguments, the first listing ``x``\nand ``y``, and the second an expression. We can use this construct with\nthe function :func:`Apply` as follows::\n\n   Apply(Lambda({x,y},x+y),{2,3})\n\nThe result should be ``5``, the result of adding ``2`` and ``3``. The\nexpression starting with :func:`Lambda` is essentially a prescription for\na specific operation, where it is stated that it accepts 2 arguments,\nand returns the arguments added together.  In this case, since the\noperation was so simple, we could also have used the name of a\nfunction to apply the arguments to, the addition operator in this case\n``Apply(\"+\",{2,3})``. When the operations become more complex however,\nthe :func:`Lambda` construct becomes more useful.\n\nNow we are ready to do the same example using a functional\napproach. First, let us construct a list with all even numbers from 2\nto 20. For this we use the ``..`` operator to set up all numbers from\none to ten, and then multiply that with two: ``2 * (1 .. 10)``.\n\nNow we want an expression that returns all the even numbers up to 20\nwhich are not divisible by 3. For this we can use ``Select``, which\ntakes as first argument a predicate that should return ``True`` if the\nlist item is to be accepted, and ``False`` otherwise, and as second\nargument the list in question::\n\n   Select(Lambda({n},Mod(n,3)!=0),2*(1 .. 10))\n\nThe numbers 6, 12 and 18 have been correctly filtered out. Here you see one\nexample of a pure function where the operation is a little bit more complex.\n\nAll that remains is to factor the items in this list. For this we can\nuse ``UnFlatten``.  Two examples of the use of ``UnFlatten`` are\n\n* ``UnFlatten({a,b,c},\"*\",1)``\n* ``UnFlatten({a,b,c},\"+\",0)``\n\nThe 0 and 1 are a base element to start with when grouping the\narguments in to an expression (they should be the respective `identity\nelements <http://en.wikipedia.org/wiki/Identity_element>`_, hence it\nis zero for addition and 1 for multiplication).\n\nNow we have all the ingredients to finally do the same calculation we\ndid above in a procedural way, but this time we can do it in a\nfunctional style, and thus captured in one concise single line: ::\n\n  UnFlatten(Select(Lambda({n},Mod(n,3)!=0),2*(1 .. 10)),\"*\",1)\n\nAs was mentioned before, the choice between the two is mostly a matter\nof style.\n\n======\nMacros\n======\n\nOne of the powerful constructs in yacas is the construct of a\nmacro. In its essence, a macro is a prescription to create another\nprogram before executing the program. An example perhaps explains it\nbest. Evaluate the following expression ::\n\n   Macro(for,{st,pr,in,bd}) [(@st);While(@pr)[(@bd);(@in);];];\n\nThis expression defines a macro that allows for looping.  Yacas has a\n:func:`For` function already, but this is how it could be defined in one line\n(In yacas the :func:`For` function is bodied, we left that out here for clarity,\nas the example is about macros).\n\nTo see it work just type ``for(i:=0,i<3,i:=i+1,Echo(i))``. You will see\nthe count from one to three.\n\nThe construct works as follows; The expression defining the macro sets\nup a macro named :func:`for` with four arguments. On the right is the body\nof the macro. This body contains expressions of the form ``@var``.\nThese are replaced by the values passed in on calling the macro.\nAfter all the variables have been replaced, the resulting expression\nis evaluated. In effect a new program has been created. Such macro constructs\ncome from LISP, and are famous for allowing you to almost design your own\nprogramming language constructs just for your own problem at hand. When used\nright, macros can greatly simplify the task of writing a program.\n\nYou can also use the back-quote ````` to expand a macro in-place. It\ntakes on the form ```(expression)``, where the expression can again\ncontain sub-expressions of the form ``@variable``. These instances\nwill be replaced with the values of these variables.\n\n====================================\nThe practice of programming in yacas\n====================================\n\nWhen you become more proficient in working with yacas you will be\ndoing more and more sophisticated calculations. For such calculations\nit is generally necessary to write little programs. In real life you\nwill usually write these programs in a text editor, and then start\nyacas, load the text file you just wrote, and try out the\ncalculation. Generally this is an iterative process, where you go back\nto the text editor to modify something, and then go back to yacas,\ntype ``restart`` and then reload the file.\n\nOn this site you can run yacas in a little window called a yacas\ncalculation center (the same as the one below this tutorial). On page\nthere is tab that contains a Yacas calculation center. If you click on\nthat tab you will be directed to a larger calculation center than the\none below this tutorial. In this page you can easily switch between\ndoing a calculation and editing a program to load at startup. We tried\nto make the experience match the general use of Yacas on a desktop as\nmuch as possible. The Yacas journal (which you see when you go to the\nYacas web site) contains examples of calculations done before by\nothers.\n\n===========================\nDefining your own operators\n===========================\n\nLarge part of the yacas system is defined in the scripting language\nitself. This includes the definitions of the operators it accepts, and\ntheir precedences. This means that you too can define your own\noperators. This section shows you how to do that.\n\nSuppose we wanted to define a function ``F(x,y)=x/y+y/x``. We could\nuse the standard syntax ``F(a,b) := a/b + b/a;``.  ``F(1,2);``. For\nthe purpose of this demonstration, lets assume that we want to define\nan infix operator ``xx`` for this operation. We can teach yacas about\nthis infix operator with ``Infix(\"xx\", OpPrecedence(\"/\"));``. Here we\ntold Yacas that the operator ``xx`` is to have the same precedence as\nthe division operator.  We can now proceed to tell Yacas how to\nevaluate expressions involving the operator ``xx`` by defining it as\nwe would with a function, ``a xx b := a/b + b/a;``.\n\nYou can verify for yourself ``3 xx 2 + 1;`` and ``1 + 3 xx 2;`` return\nthe same value, and that they follow the precedence rules (eg. ``xx``\nbinds stronger than ``+``).\n\nWe have chosen the name ``xx`` just to show that we don't need to use\nthe special characters in the infix operator's name. However we must\ndefine this operator as infix before using it in expressions,\notherwise yacas will raise a syntax error.\n\nFinally, we might decide to be completely flexible with this important\nfunction and also define it as a mathematical operator ``##`` . First\nwe define ``##`` as a *bodied* function and then proceed as\nbefore. First we can tell yacas that ``##`` is a bodied operator with\n``Bodied(\"##\", OpPrecedence(\"/\"));``. Then we define the function\nitself: ``##(a) b := a xx b;``. And now we can use the function,\n``##(1) 3 + 2;``.\n\nWe have used the name ``##`` but we could have used any other name\nsuch as ``xx`` or ``F`` or even ``_-+@+-_``.  Apart from possibly\nconfusing yourself, it doesn't matter what you call the functions you\ndefine.\n\nThere is currently one limitation in yacas: once a function name is\ndeclared as infix (prefix, postfix) or bodied, it will always be\ninterpreted that way. If we declare a function ``f`` to be bodied, we\nmay later define different functions named ``f`` with different\nnumbers of arguments, however all of these functions must be bodied.\n\nWhen you use infix operators and either a prefix of postfix operator\nnext to it you can run in to a situation where yacas can not quite\nfigure out what you typed. This happens when the operators are right\nnext to each other and all consist of symbols (and could thus in\nprinciple form a single operator). Yacas will raise an error in that\ncase. This can be avoided by inserting spaces.\n\n================================\nSome assorted programming topics\n================================\n\nOne use of lists is the associative list, sometimes called a\ndictionary in other programming languages, which is implemented in\nYacas simply as a list of key-value pairs. Keys must be strings and\nvalues may be any objects. Associative lists can also work as\nmini-databases, where a name is associated to an object.  As an\nexample, first enter ``record:={};`` to set up\nan empty record. After that, we can fill arbitrary fields in this\nrecord: ::\n\n  record[\"name\"]:=\"Isaia\";\n  record[\"occupation\"]:=\"prophet\";\n  record[\"is alive\"]:=False;\n\nNow, evaluating ``record[\"name\"]`` should result in the answer\n``\"Isaia\"``. The record is now a list that contains three sublists, as\nyou can see by evaluating ``record``.\n\nAssignment of multiple variables is also possible using lists. For\ninstance, evaluating ``{x,y}:={2!,3!}`` will result in 2 being\nassigned to ``x`` and 6 to ``y``.\n\nWhen assigning variables, the right hand side is evaluated before it\nis assigned. Thus ``a:=2*2`` will set a to 4. This is however\n*not* the case for functions. When entering ``f(x):=x+x`` the\nright hand side, ``x+x``, is not evaluated before being assigned. This\ncan be forced by using ``Eval()``.  Defining ``f(x)`` with\n``f(x):=Eval(x+x)`` will tell the system to first evaluate ``x+x``\n(which results in ``2*x``) before assigning it to the user function\n:func:`f`. This specific example is not a very useful one but it will come\nin handy when the operation being performed on the right hand side is\nexpensive. For example, if we evaluate a Taylor series expansion\nbefore assigning it to the user-defined function, the engine doesn't\nneed to create the Taylor series expansion each time that user-defined\nfunction is called.\n\nThe imaginary unit :math:`\\imath` is denoted ``I`` and complex numbers can be\nentered as either expressions involving ``I``, as for example\n``1+I*2``, or explicitly as ``Complex(a,b)`` for :math:`a+\\imath b`. The form\n``Complex(re,im)`` is the way yacas deals with complex numbers\ninternally.\n\n==============\nLinear Algebra\n==============\n\nVectors of fixed dimension are represented as lists of their\ncomponents. The list ``{1, 2+x, 3*Sin(p)}`` would be a\nthree-dimensional vector with components ``1``, ``2+x`` and\n``3*Sin(p)``. Matrices are represented as a lists of lists.\n\nVector components can be assigned values just like list items, since\nthey are in fact list items. If we first set up a variable called\n\"vector\" to contain a three-dimensional vector with the command\n``vector:=ZeroVector(3);`` (you can verify that it is indeed a vector\nwith all components set to zero by evaluating ``vector``), you can\nchange elements of the vector just like you would the elements of a\nlist (seeing as it is represented as a list). For example, to set the\nsecond element to two, just evaluate ``vector[2] := 2;``. This results\nin a new value for ``vector``.\n\nYacas can perform multiplication of matrices, vectors and numbers as\nusual in linear algebra.  The standard Yacas script library also\nincludes taking the determinant and inverse of a matrix, finding\neigenvectors and eigenvalues (in simple cases) and solving linear sets\nof equations, such as A * x = b where A is a matrix, and x and b are\nvectors.  As a little example to wetten your appetite, we define a\nHilbert matrix: ``hilbert:=HilbertMatrix(3)``. We can then calculate\nthe determinant with ``Determinant(hilbert)``, or the inverse with\n``Inverse(hilbert)``.  There are several more matrix operations\nsupported. See the reference manual for more details.\n\nThreading of functions\n----------------------\n\nSome functions in Yacas can be *threaded*. This means that calling the\nfunction with a list as argument will result in a list with that\nfunction being called on each item in the list. E.g. ``Sin({a,b,c});``\nwill result in ``{Sin(a),Sin(b),Sin(c)}``. This functionality is\nimplemented for most normal analytic functions and arithmetic\noperators.\n\nFunctions as lists\n------------------\n\nFor some work it pays to understand how things work under the\nhood. Internally, Yacas represents all atomic expressions (numbers and\nvariables) as strings and all compound expressions as lists, like\nLisp. Try ``FullForm(a+b*c);`` and you will see the text ``(+ a (* b c\n))`` appear on the screen. This function is occasionally useful, for\nexample when trying to figure out why a specific transformation rule\ndoes not work on a specific expression.\n\nIf you try ``FullForm(1+2)`` you will see that the result is not quite\nwhat we intended. The system first adds up one and two, and then shows\nthe tree structure of the end result, which is a simple number\n``3``. To stop Yacas from evaluating something, you can use the\nfunction ``Hold``, as ``FullForm(Hold(1+2))``. The function ``Eval``\nis the opposite, it instructs Yacas to re-evaluate its argument\n(effectively evaluating it twice). This undoes the effect of ``Hold``,\nas for example ``Eval(Hold(1+2))``.\n\nAlso, any expression can be converted to a list by the function\n``Listify`` or back to an expression by the function ``UnList``:\n\n* ``Listify(a+b*(c+d));``\n* ``UnList({Atom(\"+\"),x,1});``\n\nNote that the first element of the list is the name of the function\n``+`` which is equivalently represented as ``Atom(\"+\")`` and that the\nsubexpression ``b*(c+d)`` was not converted to list form. Listify just\ntook the top node of the expression.\n"
  },
  {
    "path": "docs/util/yacasdomain.py",
    "content": "# -*- coding: utf-8 -*-\n\"\"\"\n    The Yacas domain.\n\n    :copyright: Copyright 2014 by the Sphinx team, see AUTHORS.\n    :license: BSD, see LICENSE for details.\n\"\"\"\n\nimport re\n\nfrom docutils import nodes\nfrom docutils.parsers.rst import directives\n\nfrom sphinx import addnodes\nfrom sphinx.roles import XRefRole\nfrom sphinx.locale import _\nfrom sphinx.domains import Domain, ObjType, Index\nfrom sphinx.directives import ObjectDescription\nfrom sphinx.util.nodes import make_refnode\nfrom sphinx.util.docfields import Field, GroupedField, TypedField\n\n\n# REs for Yacas signatures\nyacas_sig_re = re.compile(\n    r'''^ (prefix|infix|postfix|bodied)? \\s*   # syntax\n          ([\\@a-zA-Z0-9'!*+-/^<>:=]+)  \\s*      # thing name\n          (?: \\((.*)\\)                         # optional: arguments\n          )? $                                 # and nothing more\n          ''', re.VERBOSE)\n\n\ndef _pseudo_parse_arglist(signode, arglist):\n    \"\"\"\"Parse\" a list of arguments separated by commas.\n\n    Arguments can have \"optional\" annotations given by enclosing them in\n    brackets.  Currently, this will split at any comma, even if it's inside a\n    string literal (e.g. default argument value).\n    \"\"\"\n    paramlist = addnodes.desc_parameterlist()\n    stack = [paramlist]\n    try:\n        for argument in arglist.split(','):\n            argument = argument.strip()\n            ends_open = ends_close = 0\n            while argument.startswith('['):\n                stack.append(addnodes.desc_optional())\n                stack[-2] += stack[-1]\n                argument = argument[1:].strip()\n            while argument.startswith(']'):\n                stack.pop()\n                argument = argument[1:].strip()\n            while argument.endswith(']'):\n                ends_close += 1\n                argument = argument[:-1].strip()\n            while argument.endswith('['):\n                ends_open += 1\n                argument = argument[:-1].strip()\n            if argument:\n                stack[-1] += addnodes.desc_parameter(argument, argument)\n            while ends_open:\n                stack.append(addnodes.desc_optional())\n                stack[-2] += stack[-1]\n                ends_open -= 1\n            while ends_close:\n                stack.pop()\n                ends_close -= 1\n        if len(stack) != 1:\n            raise IndexError\n    except IndexError:\n        # if there are too few or too many elements on the stack, just give up\n        # and treat the whole argument list as one argument, discarding the\n        # already partially populated paramlist node\n        signode += addnodes.desc_parameterlist()\n        signode[-1] += addnodes.desc_parameter(arglist, arglist)\n    else:\n        signode += paramlist\n\n\nclass YacasObject(ObjectDescription):\n    \"\"\"\n    Description of a general Yacas object.\n    \"\"\"\n    option_spec = {\n        'noindex': directives.flag,\n        'module': directives.unchanged,\n        'annotation': directives.unchanged,\n    }\n\n    doc_field_types = [\n        Field('parameter', label=_('Arguments'), names=('param')),\n        Field('returnvalue', label=_('Returns'), has_arg=False,\n              names=('returns', 'return')),\n    ]\n\n    def get_signature_prefix(self, sig):\n        \"\"\"May return a prefix to put before the object name in the\n        signature.\n        \"\"\"\n        return ''\n\n    def needs_arglist(self):\n        \"\"\"May return true if an empty argument list is to be generated even if\n        the document contains none.\n        \"\"\"\n        return self.objtype == 'function'\n\n    def handle_signature(self, sig, signode):\n        \"\"\"Transform a Yacas signature into RST nodes.\n\n        Return (fully qualified name of the thing, classname if any).\n\n        If inside a class, the current class name is handled intelligently:\n        * it is stripped from the displayed name if present\n        * it is added to the full name (return value) if not present\n        \"\"\"\n        m = yacas_sig_re.match(sig)\n        if m is None:\n            raise ValueError\n        syntax, name, arglist = m.groups()\n\n        add_module = False\n\n        fullname = name\n\n        signode['fullname'] = fullname\n\n        sig_prefix = self.get_signature_prefix(sig)\n        if sig_prefix:\n            signode += addnodes.desc_annotation(sig_prefix, sig_prefix)\n\n        if add_module and self.env.config.add_module_names:\n            modname = self.options.get(\n                'module', self.env.temp_data.get('ys:module'))\n            if modname:\n                nodetext = modname + '.'\n                signode += addnodes.desc_addname(nodetext, nodetext)\n\n        anno = self.options.get('annotation')\n\n        if syntax == 'prefix':\n            signode += addnodes.desc_name(name, name)\n            signode += addnodes.desc_type(arglist, arglist)\n            return fullname, ''\n\n        if syntax == 'infix':\n            left, right = arglist.split(',')\n            left = left + ' '\n            right = ' ' + right\n            signode += addnodes.desc_type(left, left)\n            signode += addnodes.desc_name(name, name)\n            signode += addnodes.desc_type(right, right)\n            return fullname, ''\n\n        if syntax == 'postfix':\n            signode += addnodes.desc_type(arglist, arglist)\n            signode += addnodes.desc_name(name, name)\n            return fullname, ''\n\n        signode += addnodes.desc_name(name, name)\n        if not arglist:\n            if self.needs_arglist():\n                # for callables, add an empty parameter list\n                signode += addnodes.desc_parameterlist()\n            if anno:\n                signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)\n            return fullname, ''\n\n        if (syntax == 'bodied'):\n            body = arglist.split(',')[0]\n            arglist = str.join(',', arglist.split(',')[1:])\n\n        _pseudo_parse_arglist(signode, arglist)\n\n        if (syntax == 'bodied'):\n            signode += addnodes.desc_type(' ' + body, ' ' + body)\n\n        if anno:\n            signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)\n\n        return fullname, ''\n\n    def get_index_text(self, modname, name):\n        \"\"\"Return the text for the index entry of the object.\"\"\"\n        if self.objtype == 'function':\n            return _('%s()') % name[0]\n        elif self.objtype == 'data':\n            return _('%s') % name[0]\n        else:\n            return ''\n\n    def add_target_and_index(self, name_cls, sig, signode):\n        modname = self.options.get(\n            'module', self.env.temp_data.get('ys:module'))\n        fullname = (modname and modname + '.' or '') + name_cls[0]\n        # note target\n        if fullname not in self.state.document.ids:\n            signode['names'].append(fullname)\n            signode['ids'].append(fullname)\n            signode['first'] = (not self.names)\n            self.state.document.note_explicit_target(signode)\n            objects = self.env.domaindata['ys']['objects']\n            if fullname in objects:\n                self.state_machine.reporter.warning(\n                    'duplicate object description of %s, ' % fullname +\n                    'other instance in ' +\n                    self.env.doc2path(objects[fullname][0]) +\n                    ', use :noindex: for one of them',\n                    line=self.lineno)\n            objects[fullname] = (self.env.docname, self.objtype)\n\n        indextext = self.get_index_text(modname, name_cls)\n        if indextext:\n            self.indexnode['entries'].append(('single', indextext,\n                                              fullname, '', None))\n\n    def before_content(self):\n        # needed for automatic qualification of members (reset in subclasses)\n        self.clsname_set = False\n\n    def after_content(self):\n        if self.clsname_set:\n            self.env.temp_data['yacas:class'] = None\n\n\nclass YacasXRefRole(XRefRole):\n    def process_link(self, env, refnode, has_explicit_title, title, target):\n        refnode['ys:module'] = env.temp_data.get('ys:module')\n        refnode['ys:class'] = env.temp_data.get('ys:class')\n        if not has_explicit_title:\n            title = title.lstrip('.')   # only has a meaning for the target\n            target = target.lstrip('~')  # only has a meaning for the title\n            # if the first character is a tilde, don't display the module/class\n            # parts of the contents\n            if title[0:1] == '~':\n                title = title[1:]\n                dot = title.rfind('.')\n                if dot != -1:\n                    title = title[dot+1:]\n        # if the first character is a dot, search more specific namespaces first\n        # else search builtins first\n        if target[0:1] == '.':\n            target = target[1:]\n            refnode['refspecific'] = True\n        return title, target\n\n\nclass YacasDomain(Domain):\n    \"\"\"Yacas language domain.\"\"\"\n    name = 'ys'\n    label = 'Yacas'\n    object_types = {\n        'function':     ObjType(_('function'),      'func', 'obj'),\n        'data':         ObjType(_('data'),          'data', 'obj'),\n    }\n\n    directives = {\n        'function':        YacasObject,  # YacasModulelevel,\n        'data':            YacasObject,  # YacasModulelevel,\n    }\n    roles = {\n        'data':  YacasXRefRole(),\n        'func':  YacasXRefRole(fix_parens=True),\n        'const': YacasXRefRole(),\n    }\n    initial_data = {\n        'objects': {},  # fullname -> docname, objtype\n    }\n\n    def clear_doc(self, docname):\n        for fullname, (fn, _) in list(self.data['objects'].items()):\n            if fn == docname:\n                del self.data['objects'][fullname]\n\n    def find_obj(self, env, modname, classname, name, type, searchmode=0):\n        \"\"\"Find a Yacas object for \"name\", perhaps using the given module\n        and/or classname.  Returns a list of (name, object entry) tuples.\n        \"\"\"\n        # skip parens\n        if name[-2:] == '()':\n            name = name[:-2]\n\n        if not name:\n            return []\n\n        objects = self.data['objects']\n        matches = []\n\n        newname = None\n        if searchmode == 1:\n            objtypes = self.objtypes_for_role(type)\n            if objtypes is not None:\n                if modname and classname:\n                    fullname = modname + '.' + classname + '.' + name\n                    if fullname in objects and objects[fullname][1] in objtypes:\n                        newname = fullname\n                if not newname:\n                    if modname and modname + '.' + name in objects and \\\n                       objects[modname + '.' + name][1] in objtypes:\n                        newname = modname + '.' + name\n                    elif name in objects and objects[name][1] in objtypes:\n                        newname = name\n                    else:\n                        # \"fuzzy\" searching mode\n                        searchname = '.' + name\n                        matches = [(oname, objects[oname]) for oname in objects\n                                   if oname.endswith(searchname)\n                                   and objects[oname][1] in objtypes]\n        else:\n            # NOTE: searching for exact match, object type is not considered\n            if name in objects:\n                newname = name\n            elif type == 'mod':\n                # only exact matches allowed for modules\n                return []\n            elif classname and classname + '.' + name in objects:\n                newname = classname + '.' + name\n            elif modname and modname + '.' + name in objects:\n                newname = modname + '.' + name\n            elif modname and classname and \\\n                    modname + '.' + classname + '.' + name in objects:\n                newname = modname + '.' + classname + '.' + name\n            # special case: builtin exceptions have module \"exceptions\" set\n            elif type == 'exc' and '.' not in name and \\\n                    'exceptions.' + name in objects:\n                newname = 'exceptions.' + name\n            # special case: object methods\n            elif type in ('func', 'meth') and '.' not in name and \\\n                    'object.' + name in objects:\n                newname = 'object.' + name\n        if newname is not None:\n            matches.append((newname, objects[newname]))\n        return matches\n\n    def resolve_xref(self, env, fromdocname, builder,\n                     type, target, node, contnode):\n        modname = node.get('ys:module')\n        clsname = node.get('ys:class')\n        searchmode = node.hasattr('refspecific') and 1 or 0\n        matches = self.find_obj(env, modname, clsname, target,\n                                type, searchmode)\n        if not matches:\n            return None\n        elif len(matches) > 1:\n            env.warn_node(\n                'more than one target found for cross-reference '\n                '%r: %s' % (target, ', '.join(match[0] for match in matches)),\n                node)\n        name, obj = matches[0]\n\n        if obj[1] == 'module':\n            # get additional info for modules\n            docname, synopsis, platform, deprecated = self.data['modules'][name]\n            assert docname == obj[0]\n            title = name\n            if synopsis:\n                title += ': ' + synopsis\n            if deprecated:\n                title += _(' (deprecated)')\n            if platform:\n                title += ' (' + platform + ')'\n            return make_refnode(builder, fromdocname, docname,\n                                'module-' + name, contnode, title)\n        else:\n            return make_refnode(builder, fromdocname, obj[0], name,\n                                contnode, name)\n\n    def get_objects(self):\n        for refname, (docname, type) in self.data['objects'].items():\n            yield (refname, refname, type, docname, refname, 1)\n\n\ndef setup(sphinx):\n    sphinx.add_domain(YacasDomain)\n"
  },
  {
    "path": "jyacas/CMakeLists.txt",
    "content": "configure_file (\n    \"${CMAKE_CURRENT_SOURCE_DIR}/CVersion.java.in\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/CVersion.java\"\n    )\n\nset (CMAKE_JAVA_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/jyacas.dir/)\n\nset (JYACAS_SRCS\n    ${CMAKE_CURRENT_BINARY_DIR}/CVersion.java\n    net/sf/yacas/StdFileInput.java\n    net/sf/yacas/StreamGobbler.java\n    net/sf/yacas/JarInputFile.java\n    net/sf/yacas/CachedStdFileInput.java\n    net/sf/yacas/InputStatus.java\n    net/sf/yacas/LispInput.java\n    net/sf/yacas/LispDefFile.java\n    net/sf/yacas/LispDefFiles.java\n    net/sf/yacas/InputDirectories.java\n    net/sf/yacas/LispHashTable.java\n    net/sf/yacas/LispGlobalVariable.java\n    net/sf/yacas/LispArgList.java\n    net/sf/yacas/GenericClass.java\n    net/sf/yacas/LispGenericClass.java\n    net/sf/yacas/ArrayClass.java\n    net/sf/yacas/AssociationClass.java\n    net/sf/yacas/LispInFixOperator.java\n    net/sf/yacas/LispPtr.java\n    net/sf/yacas/LispObject.java\n    net/sf/yacas/LispPrinter.java\n    net/sf/yacas/LispError.java\n    net/sf/yacas/LispTokenizer.java\n    net/sf/yacas/LispParser.java\n    net/sf/yacas/LispAtom.java\n    net/sf/yacas/LispNumber.java\n    net/sf/yacas/LispSubList.java\n    net/sf/yacas/LispStandard.java\n    net/sf/yacas/LispArityUserFunction.java\n    net/sf/yacas/BranchingUserFunction.java\n    net/sf/yacas/MacroUserFunction.java\n    net/sf/yacas/ListedMacroUserFunction.java\n    net/sf/yacas/ListedBranchingUserFunction.java\n    net/sf/yacas/LispMultiUserFunction.java\n    net/sf/yacas/StringInput.java\n    net/sf/yacas/InfixParser.java\n    net/sf/yacas/ParsedObject.java\n    net/sf/yacas/LispEvaluatorBase.java\n    net/sf/yacas/BigNumber.java\n    net/sf/yacas/YacasEvaluator.java\n    net/sf/yacas/YacasEvalCaller.java\n    net/sf/yacas/UserStackInformation.java\n    net/sf/yacas/BasicEvaluator.java\n    net/sf/yacas/EvalFuncBase.java\n    net/sf/yacas/LispOperators.java\n    net/sf/yacas/LispUserFunction.java\n    net/sf/yacas/LispPtrArray.java\n    net/sf/yacas/LispLocalFrame.java\n    net/sf/yacas/LispIterator.java\n    net/sf/yacas/InfixPrinter.java\n    net/sf/yacas/LispEnvironment.java\n    net/sf/yacas/MathCommands.java\n    net/sf/yacas/YacasPatternPredicateBase.java\n    net/sf/yacas/PatternClass.java\n    net/sf/yacas/CYacas.java\n    net/sf/yacas/YacasConsole.java\n    net/sf/yacas/YacasInterpreter.java\n    net/sf/yacas/YacasParamMatcherBase.java\n    net/sf/yacas/MatchSubList.java\n    net/sf/yacas/MatchNumber.java\n    net/sf/yacas/MatchAtom.java\n    net/sf/yacas/MatchVariable.java\n    net/sf/yacas/XmlTokenizer.java\n    net/sf/yacas/SubstBehaviourBase.java\n    net/sf/yacas/SubstBehaviour.java\n    net/sf/yacas/LocalSymbolBehaviour.java\n    net/sf/yacas/BackQuoteBehaviour.java\n    net/sf/yacas/YacasException.java)\n\nadd_jar (jyacas ${JYACAS_SRCS} ENTRY_POINT net/sf/yacas/YacasConsole VERSION ${YACAS_VERSION} OUTPUT_NAME yacas)\n\nget_target_property(JYACAS_JAR_FILE jyacas JAR_FILE)\n\nadd_custom_command(\n    TARGET jyacas POST_BUILD\n    COMMAND ${Java_JAR_EXECUTABLE} -uf ${JYACAS_JAR_FILE} ${YACAS_SCRIPTS}\n    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})\n"
  },
  {
    "path": "jyacas/CVersion.java.in",
    "content": "package net.sf.yacas;\n\nclass CVersion {\n    static String VERSION = \"${YACAS_VERSION}\";\n}\n"
  },
  {
    "path": "jyacas/JavaYacas.1",
    "content": ".\\\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.\r\n.\\\"See Also:\r\n.\\\"man mdoc.samples for a complete listing of options\r\n.\\\"man mdoc for the short list of editing options\r\n.\\\"/usr/share/misc/mdoc.template\r\n.Dd 7/10/05               \\\" DATE \r\n.Dt JavaYacas 1      \\\" Program name and manual section number \r\n.Os Darwin\r\n.Sh NAME                 \\\" Section Header - required - don't modify \r\n.Nm JavaYacas,\r\n.\\\" The following lines are read in generating the apropos(man -k) database. Use only key\r\n.\\\" words here as the database is built based on the words here and in the .ND line. \r\n.Nm Other_name_for_same_program(),\r\n.Nm Yet another name for the same program.\r\n.\\\" Use .Nm macro to designate other names for the documented program.\r\n.Nd This line parsed for whatis database.\r\n.Sh SYNOPSIS             \\\" Section Header - required - don't modify\r\n.Nm\r\n.Op Fl abcd              \\\" [-abcd]\r\n.Op Fl a Ar path         \\\" [-a path] \r\n.Op Ar file              \\\" [file]\r\n.Op Ar                   \\\" [file ...]\r\n.Ar arg0                 \\\" Underlined argument - use .Ar anywhere to underline\r\narg2 ...                 \\\" Arguments\r\n.Sh DESCRIPTION          \\\" Section Header - required - don't modify\r\nUse the .Nm macro to refer to your program throughout the man page like such:\r\n.Nm\r\nUnderlining is accomplished with the .Ar macro like this:\r\n.Ar underlined text .\r\n.Pp                      \\\" Inserts a space\r\nA list of items with descriptions:\r\n.Bl -tag -width -indent  \\\" Begins a tagged list \r\n.It item a               \\\" Each item preceded by .It macro\r\nDescription of item a\r\n.It item b\r\nDescription of item b\r\n.El                      \\\" Ends the list\r\n.Pp\r\nA list of flags and their descriptions:\r\n.Bl -tag -width -indent  \\\" Differs from above in tag removed \r\n.It Fl a                 \\\"-a flag as a list item\r\nDescription of -a flag\r\n.It Fl b\r\nDescription of -b flag\r\n.El                      \\\" Ends the list\r\n.Pp\r\n.\\\" .Sh ENVIRONMENT      \\\" May not be needed\r\n.\\\" .Bl -tag -width \"ENV_VAR_1\" -indent \\\" ENV_VAR_1 is width of the string ENV_VAR_1\r\n.\\\" .It Ev ENV_VAR_1\r\n.\\\" Description of ENV_VAR_1\r\n.\\\" .It Ev ENV_VAR_2\r\n.\\\" Description of ENV_VAR_2\r\n.\\\" .El                      \r\n.Sh FILES                \\\" File used or created by the topic of the man page\r\n.Bl -tag -width \"/Users/joeuser/Library/really_long_file_name\" -compact\r\n.It Pa /usr/share/file_name\r\nFILE_1description\r\n.It Pa /Users/joeuser/Library/really_long_file_name\r\nFILE_2 description\r\n.\\\" .Sh DIAGNOSTICS       \\\" May not be needed\r\n.\\\" .Bl -diag\r\n.\\\" .It Diagnostic Tag\r\n.\\\" Diagnostic informtion here.\r\n.\\\" .It Diagnostic Tag\r\n.\\\" Diagnostic informtion here.\r\n.\\\" .El\r\n.Sh SEE ALSO \r\n.\\\" List links in ascending order by section, alphabetically within a section.\r\n.\\\" Please do not reference files that do not exist without filing a bug report\r\n.Xr a 1 , \r\n.Xr b 1 ,\r\n.Xr c 1 ,\r\n.Xr a 2 ,\r\n.Xr b 2 ,\r\n.Xr a 3 ,\r\n.Xr b 3 \r\n.\\\" .Sh BUGS              \\\" Document known, unremedied bugs \r\n.\\\" .Sh HISTORY           \\\" Document history if command behaves in a unique manner \r\n\r\n"
  },
  {
    "path": "jyacas/MANIFEST.MF",
    "content": "Main-Class: net/sf/yacas/YacasConsole\nClass-Path: yacas.jar datahub.jar\n"
  },
  {
    "path": "jyacas/net/sf/yacas/ArrayClass.java",
    "content": "package net.sf.yacas;\n\n\nfinal class ArrayClass extends GenericClass\n{\n  public ArrayClass(int aSize,LispObject aInitialItem)\n  {\n    iArray = new LispPtrArray(aSize,aInitialItem);\n  }\n  @Override\n  public String TypeName()\n  {\n    return \"\\\"Array\\\"\";\n  }\n\n  public int Size()\n  {\n    return iArray.Size();\n  }\n  public LispObject GetElement(int aItem) throws Exception\n  {\n    LispError.LISPASSERT(aItem>0 && aItem<=iArray.Size());\n    return iArray.GetElement(aItem-1).Get();\n  }\n  public void SetElement(int aItem,LispObject aObject) throws Exception\n  {\n    LispError.LISPASSERT(aItem>0 && aItem<=iArray.Size());\n    iArray.SetElement(aItem-1,aObject);\n  }\n  LispPtrArray iArray;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/AssociationClass.java",
    "content": "package net.sf.yacas;\n\nimport java.util.Comparator;\nimport java.util.Map;\nimport java.util.TreeMap;\n\nfinal class AssociationClass extends GenericClass {\n\n    private static class Cmp implements Comparator<LispPtr> {\n        public Cmp(LispEnvironment env) {\n            this._env = env;\n        }\n        \n        @Override\n        public int compare(LispPtr e1, LispPtr e2) {\n            try {\n                if (LispStandard.InternalStrictTotalOrder(_env, e1, e2))\n                    return -1;\n\n                if (LispStandard.InternalEquals(_env, e1, e2))\n                    return 0;\n                \n            } catch (Exception e) {\n                // this shouldn't happen, right?\n                System.exit(255);\n            }\n             \n            return 1;\n            \n        }\n        \n        LispEnvironment _env;\n    }\n    \n    public AssociationClass(LispEnvironment env) {\n        this._env = env;\n        this._map = new TreeMap<>(new Cmp(env));\n    }\n\n    @Override\n    public String TypeName() {\n        return \"\\\"Association\\\"\";\n    }\n\n    public int Size() {\n        return _map.size();\n    }\n\n    public LispObject GetElement(LispObject k) throws Exception {\n        LispPtr v =  _map.get(new LispPtr(k));\n        \n        if (v != null)\n            return v.Get();\n        \n        return null;\n    }\n\n    public void SetElement(LispObject k, LispObject v) throws Exception {\n        _map.put(new LispPtr(k), new LispPtr(v));\n    }\n\n    public boolean DropElement(LispObject k) throws Exception {\n        return _map.remove(new LispPtr(k)) != null;\n    }\n\n    public LispPtr Keys() throws Exception {\n        LispObject head = LispAtom.New(_env, \"List\");\n        LispPtr p = new LispPtr(head);\n        for (Map.Entry<LispPtr, LispPtr> e : _map.entrySet()) {\n            p.Get().Set(e.getKey().Get().Copy(true));\n            p = p.Get().Next();\n        }\n        return new LispPtr(LispSubList.New(head));\n    }\n    \n    public LispPtr ToList() throws Exception {\n        LispObject head = LispAtom.New(_env, \"List\");\n        LispPtr p = new LispPtr(head);\n        for (Map.Entry<LispPtr, LispPtr> e: _map.entrySet()) {\n            LispPtr q = new LispPtr(LispAtom.New(_env, \"List\"));\n            p.Get().Set(LispSubList.New(q.Get()));\n            p = p.Get().Next();\n            q.Get().Set(e.getKey().Get().Copy(true));\n            q = q.Get().Next();\n            q.Get().Set(e.getValue().Get().Copy(true));\n        }\n        return new LispPtr(LispSubList.New(head));\n    }\n    \n    LispPtr Head() throws Exception {\n        assert(!_map.isEmpty());\n        Map.Entry<LispPtr, LispPtr> e = _map.entrySet().iterator().next();\n        \n        LispObject p = LispAtom.New(_env, \"List\");\n        LispPtr q = new LispPtr(p);\n        q.Get().Set(e.getKey().Get().Copy(true));\n        q = q.Get().Next();\n        q.Get().Set(e.getValue().Get().Copy(true));\n        \n        return new LispPtr(LispSubList.New(p));\n    }\n    \n    LispEnvironment _env;\n    Map<LispPtr, LispPtr> _map;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/BackQuoteBehaviour.java",
    "content": "package net.sf.yacas;\n\n/** subst behaviour for backquote mechanism as in LISP.\n * When typing `(...) all occurrences of @a will be\n * replaced with:\n * 1) a evaluated if a is an atom\n * 2) function call with function name replaced by evaluated\n *    head of function if a is a function. For instance, if\n *    a is f(x) and f is g, then f(x) gets replaced by g(x)\n */\nclass BackQuoteBehaviour implements SubstBehaviourBase\n{\n\n    public BackQuoteBehaviour(LispEnvironment aEnvironment)\n    {\n      iEnvironment = aEnvironment;\n    }\n    @Override\n    public boolean Matches(LispPtr aResult, LispPtr aElement) throws Exception\n    {\n      if (aElement.Get().SubList() == null) return false;\n      LispObject ptr = aElement.Get().SubList().Get();\n      if (ptr == null) return false;\n      if (ptr.String() == null) return false;\n\n      if (ptr.String().equals(\"`\"))\n      {\n        aResult.Set(aElement.Get());\n        return true;\n      }\n\n      if (!ptr.String().equals(\"@\"))\n        return false;\n      ptr = ptr.Next().Get();\n      if (ptr == null)\n        return false;\n      if (ptr.String() != null)\n      {\n        LispPtr cur = new LispPtr();\n        cur.Set(ptr);\n        iEnvironment.iEvaluator.Eval(iEnvironment, aResult, cur);\n        return true;\n      }\n      else\n      {\n        ptr = ptr.SubList().Get();\n        LispPtr cur = new LispPtr();\n        cur.Set(ptr);\n        LispPtr args = new LispPtr();\n        args.Set(ptr.Next().Get());\n        LispPtr result = new LispPtr();\n        iEnvironment.iEvaluator.Eval(iEnvironment, result, cur);\n        result.Get().Next().Set(args.Get());\n        LispPtr result2 = new LispPtr();\n        result2.Set(LispSubList.New(result.Get()));\n        LispStandard.InternalSubstitute(aResult, result2,this);\n        return true;\n      }\n//      return false;\n    }\n    LispEnvironment iEnvironment;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/BasicEvaluator.java",
    "content": "package net.sf.yacas;\n\n\n/// The basic evaluator for Lisp expressions.\n\nclass BasicEvaluator extends LispEvaluatorBase\n{\n  /// Evaluate a Lisp expression\n  /// \\param aEnvironment the Lisp environment, in which the\n  /// evaluation should take place.\n  /// \\param aResult the result of the evaluation.\n  /// \\param aExpression the expression to evaluate.\n  ///\n  /// First, the evaluation depth is checked. An error is raised if\n  /// the maximum evaluation depth is exceeded.\n  ///\n  /// The next step is the actual evaluation. \\a aExpression is a\n  /// LispObject, so we can distinguish three cases.\n  ///   - If \\a aExpression is a string starting with \\c \" , it is\n  ///     simply copied in \\a aResult. If it starts with another\n  ///     character (this includes the case where it represents a\n  ///     number), the environment is checked to see whether a\n  ///     variable with this name exists. If it does, its value is\n  ///     copied in \\a aResult, otherwise \\a aExpression is copied.\n  ///   - If \\a aExpression is a list, the head of the list is\n  ///     examined. If the head is not a string. InternalApplyPure()\n  ///     is called. If the head is a string, it is checked against\n  ///     the core commands; if there is a check, the corresponding\n  ///     evaluator is called. Then it is checked agaist the list of\n  ///     user function with GetUserFunction() . Again, the\n  ///     corresponding evaluator is called if there is a check. If\n  ///     all fails, ReturnUnEvaluated() is called.\n  ///   - Otherwise (ie. if \\a aExpression is a generic object), it is\n  ///     copied in \\a aResult.\n  ///\n  /// \\note The result of this operation must be a unique (copied)\n  /// element! Eg. its Next might be set...\n  ///\n  @Override\n  public void Eval(LispEnvironment aEnvironment, LispPtr aResult, LispPtr aExpression) throws Exception\n  {\n    LispError.LISPASSERT(aExpression.Get() != null);\n    aEnvironment.iEvalDepth++;\n    if (aEnvironment.iEvalDepth>=aEnvironment.iMaxEvalDepth)\n    {\n      if (aEnvironment.iEvalDepth>aEnvironment.iMaxEvalDepth+20)\n      {\n        LispError.Check(aEnvironment.iEvalDepth<aEnvironment.iMaxEvalDepth,\n             LispError.KLispErrUserInterrupt);\n      }\n      else\n      {\n        LispError.Check(aEnvironment.iEvalDepth<aEnvironment.iMaxEvalDepth, LispError.KLispErrMaxRecurseDepthReached);\n      }\n    }\n\n    String str = aExpression.Get().String();\n\n    // Evaluate an atom: find the bound value (treat it as a variable)\n    if (str != null)\n    {\n      if (str.charAt(0) == '\\\"')\n      {\n        aResult.Set(aExpression.Get().Copy(false));\n        aEnvironment.iEvalDepth--;\n        return;\n      }\n\n      LispPtr val = new LispPtr();\n      aEnvironment.GetVariable(str,val);\n      if (val.Get() != null)\n      {\n        aResult.Set(val.Get().Copy(false));\n        aEnvironment.iEvalDepth--;\n        return;\n      }\n      aResult.Set(aExpression.Get().Copy(false));\n      aEnvironment.iEvalDepth--;\n      return;\n    }\n\n    {\n      LispPtr subList = aExpression.Get().SubList();\n\n      if (subList != null)\n      {\n        LispObject head = subList.Get();\n        if (head != null)\n        {\n          if (head.String() != null)\n          {\n            {\n              YacasEvaluator evaluator = aEnvironment.CoreCommands().get(head.String());\n              // Try to find a built-in command\n              if (evaluator != null)\n              {\n                evaluator.Evaluate(aResult, aEnvironment, subList);\n                aEnvironment.iEvalDepth--;\n                return;\n              }\n            }\n\n            {\n              LispUserFunction userFunc;\n              userFunc = GetUserFunction(aEnvironment, subList);\n              if (userFunc != null)\n              {\n                userFunc.Evaluate(aResult,aEnvironment,subList);\n                aEnvironment.iEvalDepth--;\n                return;\n              }\n            }\n          }\n          else\n          {\n            //printf(\"ApplyPure!\\n\");\n            LispPtr oper = new LispPtr();\n            LispPtr args2 = new LispPtr();\n            oper.Set(subList.Get());\n            args2.Set(subList.Get().Next().Get());\n            LispStandard.InternalApplyPure(oper,args2,aResult,aEnvironment);\n            aEnvironment.iEvalDepth--;\n            return;\n          }\n          //printf(\"**** Undef: %s\\n\",head.String().String());\n          LispStandard.ReturnUnEvaluated(aResult,subList,aEnvironment);\n          aEnvironment.iEvalDepth--;\n          return;\n        }\n      }\n      aResult.Set(aExpression.Get().Copy(false));\n    }\n    aEnvironment.iEvalDepth--;\n  }\n\n  LispUserFunction GetUserFunction(LispEnvironment aEnvironment, LispPtr subList) throws Exception\n  {\n    LispObject head = subList.Get();\n\n    LispUserFunction userFunc = aEnvironment.UserFunction(subList);\n    if (userFunc != null)\n    {\n      return userFunc;\n    }\n    else if (head.String()!=null)\n    {\n      LispMultiUserFunction multiUserFunc = aEnvironment.MultiUserFunction(head.String());\n      if (multiUserFunc.iFileToOpen!=null)\n      {\n        LispDefFile def = multiUserFunc.iFileToOpen;\n        multiUserFunc.iFileToOpen=null;\n        LispStandard.InternalUse(aEnvironment,def.iFileName);\n      }\n      userFunc = aEnvironment.UserFunction(subList);\n    }\n    return userFunc;\n  }\n\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/BigNumber.java",
    "content": "package net.sf.yacas;\n\nimport java.io.Writer;\nimport java.math.*;\n\nfinal class BigNumber\n{\n  //constructors\n  public BigNumber( String aString,int aBasePrecision,int aBase/*=10*/)\n  {\n    SetTo(aString, aBasePrecision, aBase);\n  }\n  /// copy constructor\n  public BigNumber( BigNumber aOther)\n  {\n    SetTo(aOther);\n  }\n  // no constructors from int or double to avoid automatic conversions\n  public BigNumber(int aPrecision/* = 20*/)\n  {\n    iPrecision = aPrecision;\n    iTensExp = 0;\n    integer = new BigInteger(\"0\");\n  }\n  // assign from another number\n  public void SetTo( BigNumber aOther)\n  {\n    iPrecision = aOther.GetPrecision();\n    iTensExp = aOther.iTensExp;\n    integer  = aOther.integer;\n    decimal  = aOther.decimal;\n  }\n  boolean IsFloat(String aString,int aBase)\n  {\n    if (aString.indexOf('.')>=0)\n      return true;\n    if (aBase>10)\n      return false;\n    if (aString.indexOf('e')>=0)\n      return true;\n    return aString.indexOf('E')>=0;\n  }\n  // assign from string, precision in base digits\n  public void SetTo( String aString,int aPrecision,int aBase/*=10*/)\n  {\n    integer = null;\n    decimal = null;\n    boolean isFloat = IsFloat(aString,aBase);\n\n    iPrecision = aPrecision;\n    iTensExp = 0;\n    if (isFloat)\n    {\n      int decimalPos;\n      decimalPos = aString.indexOf('e');\n      if (decimalPos < 0)\n        decimalPos = aString.indexOf('E');\n      if (decimalPos > 0) // will never be zero\n      {\n        iTensExp = Integer.parseInt(aString.substring(decimalPos+1,aString.length()));\n        aString = aString.substring(0,decimalPos);\n      }\n\n      decimal = new BigDecimal(aString); //TODO FIXME does not listen to aBase!!!\n      if (decimal.scale() > iPrecision)\n        iPrecision = decimal.scale();\n    }\n    else\n    {\n      integer = new BigInteger(aString, aBase);\n    }\n  }\n  // assign from a platform type\n  public void SetTo(long value)\n  {\n    SetTo(\"\"+value,iPrecision,10);\n  }\n  public void SetTo(int value)\n  {\n    SetTo((long)value);\n  }\n  public void SetTo(double value)\n  {\n    SetTo(\"\"+value,iPrecision,10);\n  }\n  // Convert back to other types\n  /// ToString : return string representation of number in aResult to given precision (base digits)\n  public String ToString(int aPrecision, int aBase/*=10*/)\n  {\n    if (integer != null)\n      return integer.toString(aBase);\n    else\n    {\n      String result = decimal.toString();\n\n      int extraExp = 0;\n      // Parse out the exponent\n      {\n        int pos = result.indexOf('E');\n        if (pos<0) pos = result.indexOf('e');\n        if (pos > 0)\n        {\n          extraExp = Integer.parseInt(result.substring(pos+1));\n          result = result.substring(0,pos);\n        }\n      }\n\n\n      int dotPos = result.indexOf('.');\n      if (dotPos >= 0)\n      {\n        int endpos = result.length();\n        while (endpos>dotPos && result.charAt(endpos-1) == '0') endpos--;\n        if (endpos > 1)\n        {\n          if (result.charAt(endpos-1) == '.' && result.charAt(endpos-2) >= '0' && result.charAt(endpos-2) <= '9')\n          {\n            endpos--;\n          }\n        }\n        result = result.substring(0,endpos);\n      }\n\n      if (iTensExp + extraExp != 0)\n        result = result + \"e\" + (iTensExp+extraExp);\n\n      return result;\n    }\n  }\n  /// Give approximate representation as a double number\n  public double Double()\n  {\n    if (integer != null)\n      return integer.doubleValue();\n    else\n      return decimal.doubleValue();\n  }\n  public long Long()\n  {\n    if (integer != null)\n      return integer.longValue();\n    else\n      return decimal.longValue();\n  }\n\n  //basic object manipulation\n  public boolean Equals( BigNumber aOther)\n  {\n    if (integer != null) {\n        if (aOther.integer != null)\n            return (integer.compareTo(aOther.integer) == 0);\n\n        BigDecimal x = GetDecimal(this);\n        BigDecimal y = aOther.decimal;\n\n        if (iTensExp > aOther.iTensExp)\n            x = x.movePointRight(iTensExp - aOther.iTensExp);\n        else if (iTensExp < aOther.iTensExp)\n            y = y.movePointRight(iTensExp - aOther.iTensExp);\n        \n        return x.compareTo(y) == 0;\n    }\n    \n    if (decimal != null) {\n        BigDecimal thisd = decimal;\n        BigDecimal otherd = aOther.decimal;\n        if (otherd == null)\n            otherd = GetDecimal(aOther);\n\n        if (iTensExp > aOther.iTensExp)\n            thisd = thisd.movePointRight(iTensExp - aOther.iTensExp);\n        else if (iTensExp < aOther.iTensExp)\n            otherd = otherd.movePointRight(iTensExp - aOther.iTensExp);\n        \n        return thisd.compareTo(otherd) == 0;\n    }\n    return true;\n  }\n  public boolean IsInt()\n  {\n    return (integer != null && decimal == null);\n  }\n  public boolean IsSmall()\n  {\n    if (IsInt())\n    {\n      BigInteger i = integer.abs();\n      return (i.compareTo(new BigInteger(\"65535\"))<0);\n    }\n    else\n    // a function to test smallness of a float is not present in ANumber, need to code a workaround to determine whether a number fits into double.\n    {\n      //TODO fixme\n      return true;\n/*\n      LispInt tensExp = iNumber->iTensExp;\n      if (tensExp<0)tensExp = -tensExp;\n      return\n      (\n        iNumber->iPrecision <= 53  // standard float is 53 bits\n        && tensExp<1021 // 306  // 1021 bits is about 306 decimals\n      );\n      // standard range of double precision is about 53 bits of mantissa and binary exponent of about 1021\n*/\n    }\n  }\n  public void BecomeInt()\n  {\n    if (decimal != null)\n    {\n      integer = decimal.toBigInteger();\n      decimal = null;\n    }\n  }\n  public void BecomeFloat(int aPrecision/*=0*/)\n  {\n    if (integer != null)\n    {\n      decimal = new BigDecimal(integer);\n      iTensExp = 0;\n      integer = null;\n    }\n  }\n  public boolean LessThan( BigNumber aOther)\n  {\n    boolean floatResult = (decimal != null || aOther.decimal != null);\n    if (floatResult)\n    {\n      BigDecimal dX = GetDecimal(this);\n      BigDecimal dY = GetDecimal(aOther);\n      return dX.compareTo(dY)<0;\n    }\n    else\n    {\n      return integer.compareTo(aOther.integer)<0;\n    }\n  }\n  //arithmetic\n  /// Multiply two numbers at given precision and put result in *this\n  public void Multiply( BigNumber aX,  BigNumber aY, int aPrecision)\n  {\n    boolean floatResult = (aX.decimal != null || aY.decimal != null);\n    if (floatResult)\n    {\n      BigDecimal dX = GetDecimal(aX);\n      BigDecimal dY = GetDecimal(aY);\n      integer = null;\n      decimal = dX.multiply(dY);\n      int newScale = iPrecision;\n      if (newScale < decimal.scale())\n        decimal = decimal.setScale(newScale,BigDecimal.ROUND_HALF_EVEN);\n      iTensExp = aX.iTensExp + aY.iTensExp;\n    }\n    else\n    {\n      decimal = null;\n      integer = aX.integer.multiply(aY.integer);\n    }\n  }\n  /// Add two numbers at given precision and return result in *this\n  public void Add( BigNumber aX,  BigNumber aY, int aPrecision)\n  {\n    boolean floatResult = (aX.decimal != null || aY.decimal != null);\n    if (floatResult)\n    {\n      integer = null;\n\n      BigDecimal dX = GetDecimal(aX);\n      BigDecimal dY = GetDecimal(aY);\n\n      iTensExp = aX.iTensExp;\n      if (aX.iTensExp > aY.iTensExp)\n      {\n        dY = dY.movePointLeft(aX.iTensExp-aY.iTensExp);\n        iTensExp = aX.iTensExp;\n      }\n      else if (aX.iTensExp < aY.iTensExp)\n      {\n        dX = dX.movePointLeft(aY.iTensExp-aX.iTensExp);\n        iTensExp = aY.iTensExp;\n      }\n      \n      decimal = dX.add(dY);\n    }\n    else\n    {\n      decimal = null;\n      integer = aX.integer.add(aY.integer);\n    }\n  }\n  /// Negate the given number, return result in *this\n  public void Negate( BigNumber aX)\n  {\n    if (aX.integer != null)\n    {\n      decimal = null;\n      integer = aX.integer.negate();\n    }\n    if (aX.decimal != null)\n    {\n      integer = null;\n      decimal = aX.decimal.negate();\n      iTensExp = aX.iTensExp;\n    }\n  }\n  /// Divide two numbers and return result in *this. Note: if the two arguments are integer, it should return an integer result!\n  public void Divide( BigNumber aX,  BigNumber aY, int aPrecision)\n  {\n    boolean floatResult = (aX.decimal != null || aY.decimal != null);\n    if (floatResult)\n    {\n      BigDecimal dX = GetDecimal(aX);\n      BigDecimal dY = GetDecimal(aY);\n      integer = null;\n      int newScale = aPrecision+aY.GetPrecision();\n      if (newScale > dX.scale())\n        dX = dX.setScale(newScale);\n      decimal = dX.divide(dY,BigDecimal.ROUND_HALF_EVEN);\n      iPrecision = decimal.scale();\n      iTensExp = aX.iTensExp-aY.iTensExp;\n    }\n    else\n    {\n      decimal = null;\n      integer = aX.integer.divide(aY.integer);\n    }\n  }\n\n  /// integer operation: *this = y mod z\n  public void Mod( BigNumber aY,  BigNumber aZ) throws Exception\n  {\n    LispError.Check(aY.integer != null, LispError.KLispErrNotInteger);\n    LispError.Check(aZ.integer != null, LispError.KLispErrNotInteger);\n//TODO fixme    LispError.Check(!IsZero(aZ),LispError.KLispErrInvalidArg);\n    integer = aY.integer.mod(aZ.integer);\n    decimal = null;\n  }\n\n  /// For debugging purposes, dump internal state of this object into a string\n  public void DumpDebugInfo(Writer aOutput) throws Exception\n  {\n    if (integer != null)\n    {\n      aOutput.write((\"integer: \"+integer.toString()+\"\\n\"));\n    }\n    else\n    {\n      aOutput.write((\"decimal: \"+decimal.unscaledValue()+\" scale \"+decimal.scale()+\" x 10^(\"+iTensExp+\")\\n\"));\n    }\n  }\n\n  /// assign self to Floor(aX) if possible\n  public void Floor( BigNumber aX)\n  {\n    if (aX.decimal != null)\n    {\n      BigDecimal d = aX.decimal;\n      if (aX.iTensExp != 0)\n      {\n        d = d.movePointRight(aX.iTensExp);\n      }\n      BigInteger rounded = d.toBigInteger();\n      if (aX.decimal.signum()<0)\n      {\n        BigDecimal back =  new BigDecimal(rounded);\n        BigDecimal difference = aX.decimal.subtract(back);\n        if (difference.signum() != 0)\n        {\n          rounded = rounded.add(new BigInteger(\"-1\"));\n        }\n      }\n      integer = rounded;\n    }\n    else\n    {\n      integer = aX.integer;\n    }\n    decimal = null;\n  }\n  /// set precision (in bits)\n  public void Precision(int aPrecision)\n  {\n    iPrecision = aPrecision;\n    if (decimal != null)\n    {\n      if (decimal.scale() > aPrecision)\n      {\n        decimal = decimal.setScale(aPrecision, BigDecimal.ROUND_HALF_EVEN);\n      }\n    }\n  }\n\n  /// Bitwise operations, return result in *this.\n  void ShiftLeft(  BigNumber aX, int aNrToShift) throws Exception\n  {\n    LispError.LISPASSERT(aX.integer != null);\n    decimal = null;\n    integer = aX.integer.shiftLeft(aNrToShift);\n  }\n  void ShiftRight(  BigNumber aX, int aNrToShift) throws Exception\n  {\n    LispError.LISPASSERT(aX.integer != null);\n    decimal = null;\n    integer = aX.integer.shiftRight(aNrToShift);\n  }\n\n  void Gcd( BigNumber aX,  BigNumber aY) throws Exception\n  {\n    LispError.LISPASSERT(aX.integer != null);\n    LispError.LISPASSERT(aY.integer != null);\n    integer = aX.integer.gcd(aY.integer);\n    decimal = null;\n  }\n  void BitAnd( BigNumber aX,  BigNumber aY) throws Exception\n  {\n    LispError.LISPASSERT(aX.integer != null);\n    LispError.LISPASSERT(aY.integer != null);\n    integer = aX.integer.and(aY.integer);\n    decimal = null;\n  }\n  void BitOr( BigNumber aX,  BigNumber aY) throws Exception\n  {\n    LispError.LISPASSERT(aX.integer != null);\n    LispError.LISPASSERT(aY.integer != null);\n    integer = aX.integer.or(aY.integer);\n    decimal = null;\n  }\n  void BitXor( BigNumber aX,  BigNumber aY) throws Exception\n  {\n    LispError.LISPASSERT(aX.integer != null);\n    LispError.LISPASSERT(aY.integer != null);\n    integer = aX.integer.xor(aY.integer);\n    decimal = null;\n  }\n  void BitNot( BigNumber aX) throws Exception\n  {\n    LispError.LISPASSERT(aX.integer != null);\n    integer = aX.integer.not();\n    decimal = null;\n  }\n  /// Bit count operation: return the number of significant bits if integer, return the binary exponent if float (shortcut for binary logarithm)\n  /// give bit count as a platform integer\n  private static BigDecimal zero = new BigDecimal(\"0\");\n  private static BigDecimal one = new BigDecimal(\"1\");\n  private static BigDecimal two = new BigDecimal(\"2\");\n  private static BigDecimal ten = new BigDecimal(\"10\");\n  public long BitCount()\n  {\n    //TODO fixme check that it works as needed\n    if (integer != null)\n      return integer.abs().bitLength();\n    {\n      BigDecimal d = decimal.abs();\n      if (iTensExp != 0)\n        d = d.movePointRight(iTensExp);\n      if (d.compareTo(one)>0)\n        return d.toBigInteger().bitLength();\n      BigDecimal integerPart = new BigDecimal(d.toBigInteger());\n      integerPart = integerPart.negate();\n      d = d.add(integerPart);\n      if (d.compareTo(zero) == 0)\n        return 0;\n      int bitCount = 0;\n\n      //TODO OPTIMIZE\n      d = d.multiply(two);\n      while (d.compareTo(one)<0)\n      {\n        d = d.multiply(two);\n        bitCount--;\n      }\n      return bitCount;\n    }\n  }\n\n  /// Give sign (-1, 0, 1)\n  public int Sign()\n  {\n    if (integer != null)\n      return integer.signum();\n    if (decimal != null)\n      return decimal.signum();\n\n    return 0;\n  }\n\n  public int GetPrecision()\n  {\n    return iPrecision;\n  }\n\n  int iPrecision;\n  int iTensExp;\n\n  BigDecimal GetDecimal(BigNumber aNumber)\n  {\n    if (aNumber.decimal != null)\n      return aNumber.decimal;\n    return new BigDecimal(aNumber.integer);\n  }\n\n   /// Internal library wrapper starts here.\n  BigInteger integer = null;\n  BigDecimal decimal= null;\n  /// Internal library wrapper ends here.\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/BranchingUserFunction.java",
    "content": "package net.sf.yacas;\n\n\nimport java.util.*;\n\n/// A mathematical function defined by several rules.\n/// This is the basic class which implements functions in Yacas.\n/// Evaluation is done by consulting a set of rewriting rules. The\n/// body of the first rule that matches, is evaluated and this gives\n/// the result of evaluating the function.\n\nclass BranchingUserFunction extends LispArityUserFunction\n{\n  /// Structure containing name of parameter and whether it is put on hold.\n  class BranchParameter\n  {\n    public BranchParameter(String aParameter, boolean aHold /*=false*/)\n    {\n      iParameter = aParameter;\n      iHold = aHold;\n    }\n    String  iParameter;\n    boolean iHold;\n  }\n\n  /// Abstract base class for rules.\n  abstract class BranchRuleBase\n  {\n    public abstract boolean Matches(LispEnvironment aEnvironment, LispPtr[] aArguments) throws Exception;\n    public abstract int Precedence();\n    public abstract LispPtr Body();\n  }\n\n  /// A rule with a predicate.\n  /// This rule matches if the predicate evaluates to #true.\n  class BranchRule extends BranchRuleBase\n  {\n    public BranchRule(int aPrecedence,LispPtr  aPredicate,LispPtr  aBody)\n    {\n      iPrecedence = aPrecedence;\n      iPredicate.Set(aPredicate.Get());\n      iBody.Set(aBody.Get());\n    }\n\n    /// Return true if the rule matches.\n    /// #iPredicate is evaluated in \\a Environment. If the result\n    /// IsTrue(), this function returns true.\n    @Override\n    public boolean Matches(LispEnvironment  aEnvironment, LispPtr[] aArguments) throws Exception\n    {\n      LispPtr pred = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, pred, iPredicate);\n      return LispStandard.IsTrue(aEnvironment,pred);\n    }\n\n    /// Access #iPrecedence.\n    @Override\n    public int Precedence()\n    {\n      return iPrecedence;\n    }\n\n    /// Access #iBody.\n    @Override\n    public LispPtr Body()\n    {\n      return iBody;\n    }\n    protected BranchRule()\n    {\n    }\n    protected int iPrecedence;\n    protected LispPtr iBody = new LispPtr();\n    protected LispPtr iPredicate = new LispPtr();\n  }\n\n  /// A rule that always matches.\n  class BranchRuleTruePredicate extends BranchRule\n  {\n    public BranchRuleTruePredicate(int aPrecedence,LispPtr  aBody)\n    {\n      iPrecedence = aPrecedence;\n      iBody.Set(aBody.Get());\n    }\n    /// Return #true, always.\n    @Override\n    public boolean Matches(LispEnvironment  aEnvironment, LispPtr[] aArguments) throws Exception\n    {\n      return true;\n    }\n  }\n\n  /// A rule which matches if the corresponding PatternClass matches.\n  class BranchPattern extends BranchRuleBase\n  {\n    /// Constructor.\n    /// \\param aPrecedence precedence of the rule\n    /// \\param aPredicate generic object of type \\c Pattern\n    /// \\param aBody body of the rule\n    public BranchPattern(int aPrecedence,LispPtr  aPredicate,LispPtr  aBody) throws Exception\n    {\n      iPatternClass = null;\n      iPrecedence = aPrecedence;\n      iPredicate.Set(aPredicate.Get());\n\n      GenericClass gen = aPredicate.Get().Generic();\n      LispError.Check(gen != null,LispError.KLispErrInvalidArg);\n      LispError.Check(gen.TypeName().equals(\"\\\"Pattern\\\"\"),LispError.KLispErrInvalidArg);\n\n      iPatternClass = (PatternClass)gen;\n      iBody.Set(aBody.Get());\n    }\n\n    /// Return true if the corresponding pattern matches.\n    @Override\n    public boolean Matches(LispEnvironment  aEnvironment, LispPtr[] aArguments) throws Exception\n    {\n      return iPatternClass.Matches(aEnvironment,aArguments);\n    }\n\n    /// Access #iPrecedence\n    @Override\n    public int Precedence()\n    {\n      return iPrecedence;\n    }\n\n    /// Access #iBody\n    @Override\n    public LispPtr Body()\n    {\n      return iBody;\n    }\n\n    /// The precedence of this rule.\n    protected int iPrecedence;\n\n    /// The body of this rule.\n    protected LispPtr iBody = new LispPtr();\n\n    /// Generic object of type \\c Pattern containing #iPatternClass\n    protected LispPtr iPredicate = new LispPtr();\n\n    /// The pattern that decides whether this rule matches.\n    protected PatternClass iPatternClass;\n  };\n\n  /// Constructor.\n  /// \\param aParameters linked list constaining the names of the arguments\n  ///\n  /// #iParamList and #iParameters are set from \\a aParameters.\n  BranchingUserFunction(LispPtr aParameters) throws Exception\n  {\n    iParamList.Set(aParameters.Get());\n    LispIterator iter = new LispIterator(aParameters);\n    while (iter.GetObject() != null)\n    {\n      LispError.Check(iter.GetObject().String() != null,LispError.KLispErrCreatingUserFunction);\n      BranchParameter param = new BranchParameter(iter.GetObject().String(),false);\n      iParameters.add(param);\n      iter.GoNext();\n    }\n  }\n\n  /// Evaluate the function on given arguments.\n  /// \\param aResult (on output) the result of the evaluation\n  /// \\param aEnvironment the underlying Lisp environment\n  /// \\param aArguments the arguments to the function\n  ///\n  /// First, all arguments are evaluated by the evaluator associated\n  /// to \\a aEnvironment, unless the \\c iHold flag of the\n  /// corresponding parameter is true. Then a new LispLocalFrame is\n  /// constructed, in which the actual arguments are assigned to the\n  /// names of the formal arguments, as stored in \\c iParameter. Then\n  /// all rules in #iRules are tried one by one. The body of the\n  /// first rule that matches is evaluated, and the result is put in\n  /// \\a aResult. If no rule matches, \\a aResult will recieve a new\n  /// expression with evaluated arguments.\n  @Override\n  public void Evaluate(LispPtr aResult,LispEnvironment aEnvironment, LispPtr aArguments) throws Exception\n  {\n    int arity = Arity();\n    int i;\n\n/*TODO fixme\n    if (Traced())\n    {\n        LispPtr tr;\n        tr.Set(LispSubList.New(aArguments.Get()));\n        TraceShowEnter(aEnvironment,tr);\n        tr.Set(null);\n    }\n*/\n    LispIterator iter = new LispIterator(aArguments);\n    iter.GoNext();\n\n    // unrollable arguments\n    LispPtr[] arguments;\n    if (arity==0)\n        arguments = null;\n    else\n    {\n        LispError.LISPASSERT(arity>0);\n        arguments = new LispPtr[arity];\n        for (i=0;i<arity;i++)\n          arguments[i] = new LispPtr();\n    }\n\n    // Walk over all arguments, evaluating them as necessary\n    for (i=0;i<arity;i++)\n    {\n        LispError.Check(iter.GetObject() != null, LispError.KLispErrWrongNumberOfArgs);\n        if (iParameters.get(i).iHold)\n        {\n            arguments[i].Set(iter.GetObject().Copy(false));\n        }\n        else\n        {\n            LispError.Check(iter.Ptr() != null, LispError.KLispErrWrongNumberOfArgs);\n            aEnvironment.iEvaluator.Eval(aEnvironment, arguments[i], iter.Ptr());\n        }\n        iter.GoNext();\n    }\n/*TODO fixme\n    if (Traced())\n    {\n        LispIterator iter = new LispIterator(aArguments);\n        iter.GoNext();\n        for (i=0;i<arity;i++)\n        {\n            TraceShowArg(aEnvironment,*iter.Ptr(),\n                  arguments[i]);\n\n            iter.GoNext();\n        }\n    }\n*/\n    // declare a new local stack.\n    aEnvironment.PushLocalFrame(Fenced());\n    try\n    {\n      // define the local variables.\n      for (i=0;i<arity;i++)\n      {\n          String variable = iParameters.get(i).iParameter;\n          // set the variable to the new value\n          aEnvironment.NewLocal(variable,arguments[i].Get());\n      }\n\n      // walk the rules database, returning the evaluated result if the\n      // predicate is true.\n      int nrRules = iRules.size();\n      UserStackInformation st = aEnvironment.iEvaluator.StackInformation();\n      for (i=0;i<nrRules;i++)\n      {\n          BranchRuleBase thisRule = iRules.get(i);\n          LispError.LISPASSERT(thisRule != null);\n\n          st.iRulePrecedence = thisRule.Precedence();\n          boolean matches = thisRule.Matches(aEnvironment, arguments);\n          if (matches)\n          {\n              st.iSide = 1;\n              aEnvironment.iEvaluator.Eval(aEnvironment, aResult, thisRule.Body());\n  /*TODO fixme\n              if (Traced())\n              {\n                  LispPtr tr;\n                  tr.Set(LispSubList.New(aArguments.Get()));\n                  TraceShowLeave(aEnvironment, aResult,tr);\n                  tr.Set(null);\n              }\n  */\n              return;\n          }\n\n          // If rules got inserted, walk back\n          while (thisRule != iRules.get(i) && i>0) i--;\n      }\n\n      // No predicate was true: return a new expression with the evaluated\n      // arguments.\n\n      {\n          LispPtr full = new LispPtr();\n          full.Set(aArguments.Get().Copy(false));\n          if (arity == 0)\n          {\n              full.Get().Next().Set(null);\n          }\n          else\n          {\n              full.Get().Next().Set(arguments[0].Get());\n              for (i=0;i<arity-1;i++)\n              {\n                  arguments[i].Get().Next().Set(arguments[i+1].Get());\n              }\n          }\n          aResult.Set(LispSubList.New(full.Get()));\n      }\n\n  /*TODO fixme\n      if (Traced())\n      {\n          LispPtr tr;\n          tr.Set(LispSubList.New(aArguments.Get()));\n          TraceShowLeave(aEnvironment, aResult,tr);\n          tr.Set(null);\n      }\n  */\n    }\n    catch (Exception e)\n    {\n      throw e;\n    }\n    finally\n    {\n      aEnvironment.PopLocalFrame();\n    }\n  }\n\n  /// Put an argument on hold.\n  /// \\param aVariable name of argument to put un hold\n  ///\n  /// The \\c iHold flag of the corresponding argument is set. This\n  /// implies that this argument is not evaluated by Evaluate().\n  @Override\n  public void HoldArgument(String aVariable)\n  {\n    int i;\n    int nrc=iParameters.size();\n    for (i=0;i<nrc;i++)\n    {\n        if (iParameters.get(i).iParameter == aVariable)\n            iParameters.get(i).iHold = true;\n    }\n  }\n\n  /// Return true if the arity of the function equals \\a aArity.\n  @Override\n  public boolean IsArity(int aArity)\n  {\n    return (Arity() == aArity);\n  }\n\n  /// Return the arity (number of arguments) of the function.\n  @Override\n  public int Arity()\n  {\n    return iParameters.size();\n  }\n\n  /// Add a BranchRule to the list of rules.\n  /// \\sa InsertRule()\n  @Override\n  public void DeclareRule(int aPrecedence, LispPtr aPredicate, LispPtr aBody) throws Exception\n  {\n    // New branching rule.\n    BranchRule newRule = new BranchRule(aPrecedence,aPredicate,aBody);\n\n    InsertRule(aPrecedence,newRule);\n  }\n\n  /// Add a BranchRuleTruePredicate to the list of rules.\n  /// \\sa InsertRule()\n  @Override\n  public void DeclareRule(int aPrecedence, LispPtr aBody) throws Exception\n  {\n    // New branching rule.\n    BranchRule newRule = new BranchRuleTruePredicate(aPrecedence,aBody);\n\n    InsertRule(aPrecedence,newRule);\n  }\n\n  /// Add a BranchPattern to the list of rules.\n  /// \\sa InsertRule()\n  @Override\n  public void DeclarePattern(int aPrecedence, LispPtr aPredicate, LispPtr aBody) throws Exception\n  {\n    // New branching rule.\n    BranchPattern newRule = new BranchPattern(aPrecedence,aPredicate,aBody);\n\n    InsertRule(aPrecedence,newRule);\n  }\n\n  /// Insert any BranchRuleBase object in the list of rules.\n  /// This function does the real work for DeclareRule() and\n  /// DeclarePattern(): it inserts the rule in #iRules, while\n  /// keeping it sorted. The algorithm is \\f$O(\\log n)\\f$, where\n  /// \\f$n\\f$ denotes the number of rules.\n  void InsertRule(int aPrecedence,BranchRuleBase newRule)\n  {\n    // Find place to insert\n    int low,high,mid;\n    low=0;\n    high=iRules.size();\n\n    // Constant time: find out if the precedence is before any of the\n    // currently defined rules or past them.\n    if (high>0)\n    {\n        if (iRules.get(0).Precedence() > aPrecedence)\n        {\n            mid=0;\n            // Insert it\n            iRules.add(mid,newRule);return;\n        }\n        if (iRules.get(high-1).Precedence() < aPrecedence)\n        {\n            mid=high;\n            // Insert it\n            iRules.add(mid,newRule);return;\n        }\n    }\n\n    // Otherwise, O(log n) search algorithm for place to insert\n    for(;;)\n    {\n      if (low>=high)\n      {\n        mid=low;\n        // Insert it\n        iRules.add(mid,newRule);return;\n      }\n      mid = (low+high)>>1;\n\n      if (iRules.get(mid).Precedence() > aPrecedence)\n      {\n        high = mid;\n      }\n      else if (iRules.get(mid).Precedence() < aPrecedence)\n      {\n        low = (++mid);\n      }\n      else\n      {\n        // Insert it\n        iRules.add(mid,newRule);return;\n      }\n    }\n  }\n\n  /// Return the argument list, stored in #iParamList\n  @Override\n  public LispPtr ArgList()\n  {\n    return iParamList;\n  }\n\n  /// List of arguments, with corresponding \\c iHold property.\n  protected ArrayList<BranchParameter> iParameters = new ArrayList<>();\n\n  /// List of rules, sorted on precedence.\n  protected ArrayList<BranchRuleBase> iRules = new ArrayList<>();\n\n  /// List of arguments\n  LispPtr iParamList = new LispPtr();\n}\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/CYacas.java",
    "content": "package net.sf.yacas;\n\nimport java.io.StringWriter;\nimport java.io.Writer;\n\n\npublic class CYacas\n{\n  public CYacas(Writer stdoutput)\n  {\n    try\n    {\n      env = new LispEnvironment(stdoutput);\n      tokenizer = new LispTokenizer();\n      printer = new InfixPrinter(env.iPrefixOperators, env.iInfixOperators, env.iPostfixOperators, env.iBodiedOperators);\n    }\n    catch (Exception e)\n    {\n       e.printStackTrace();\n      System.out.println(e.toString());\n    }\n  }\n  public String Evaluate(String input)\n  {\n    if (input.length() == 0)\n      return \"\";\n    String rs = \"\";\n    try\n    {\n       env.iEvalDepth=0;\n       env.iEvaluator.ResetStack();\n\n\n      iError = null;\n\n      LispPtr in_expr = new LispPtr();\n      if (env.iPrettyReader != null)\n      {\n        InputStatus someStatus = new InputStatus();\n        StringBuilder inp = new StringBuilder();\n        inp.append(input);\n        InputStatus oldstatus = env.iInputStatus;\n        env.iInputStatus.SetTo(\"String\");\n        StringInput newInput = new StringInput(new StringBuffer(input),env.iInputStatus);\n\n        LispInput previous = env.iCurrentInput;\n        env.iCurrentInput = newInput;\n        try\n        {\n         LispPtr args = new LispPtr();\n         LispStandard.InternalApplyString(env, in_expr,\n                             env.iPrettyReader,\n                             args);\n        }\n        catch (Exception e)\n        {\n          throw e;\n        }\n        finally\n        {\n          env.iCurrentInput = previous;\n          env.iInputStatus.RestoreFrom(oldstatus);\n        }\n      }\n      else\n      {\n        InputStatus someStatus = new InputStatus();\n        StringBuffer inp = new StringBuffer();\n        inp.append(input);\n        inp.append(\";\");\n        StringInput input_str = new StringInput(inp,someStatus);\n        LispParser parser = new InfixParser(tokenizer, input_str, env, env.iPrefixOperators, env.iInfixOperators, env.iPostfixOperators, env.iBodiedOperators);\n        parser.Parse( in_expr );\n      }\n\n      LispPtr result = new LispPtr();\n      env.iEvaluator.Eval(env, result, in_expr);\n\n      String percent = env.HashTable().LookUp(\"%\");\n      env.UnProtect(percent);\n      env.SetVariable(percent,result,true);\n      env.Protect(percent);\n\n      StringWriter output = new StringWriter();\n\n      if (env.iPrettyPrinter != null)\n      {\n         LispPtr nonresult = new LispPtr();\n         LispStandard.InternalApplyString(env, nonresult,\n                             env.iPrettyPrinter,\n                             result);\n        rs = output.toString();\n      }\n      else\n      {\n        printer.RememberLastChar(' ');\n        printer.Print(result, output, env);\n        rs = output.toString();\n      }\n    }\n    catch (Exception e)\n    {\n//      e.printStackTrace();\n      System.out.println(e.toString());\n      iError = e.toString();\n    }\n    return rs;\n  }\n  public LispEnvironment env = null;\n  LispTokenizer tokenizer = null;\n  LispPrinter printer = null;\n  String iError = null;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/CachedStdFileInput.java",
    "content": "package net.sf.yacas;\n\n\n/** CachedStdFileInput : input from stdin */\nclass CachedStdFileInput extends LispInput\n{\n    public CachedStdFileInput(InputStatus aStatus)\n    {\n      super(aStatus);\n      Rewind();\n    }\n    @Override\n    public char Next() throws Exception\n    {\n      int c = Peek();\n      iCurrentPos++;\n      if (c == '\\n')\n        iStatus.NextLine();\n      return (char)c;\n    }\n    @Override\n    public char Peek() throws Exception\n    {\n      if (iCurrentPos == iBuffer.length())\n      {\n        int newc;\n        newc = System.in.read();\n        iBuffer.append((char)newc);\n        while (newc != '\\n')\n        {\n          newc = System.in.read();\n          iBuffer.append((char)newc);\n        }\n      }\n      return iBuffer.charAt(iCurrentPos);\n    }\n    @Override\n    public boolean EndOfStream()\n    {\n      return false;\n    }\n    public void Rewind()\n    {\n      iBuffer = new StringBuffer();\n      iCurrentPos = 0;\n    }\n    @Override\n    public int Position()\n    {\n      return iCurrentPos;\n    }\n    @Override\n    public void SetPosition(int aPosition)\n    {\n      iCurrentPos = aPosition;\n    }\n\n    StringBuffer iBuffer;\n    int iCurrentPos;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/EvalFuncBase.java",
    "content": "package net.sf.yacas;\n\n\n\n// class EvalFuncBase defines the interface to 'something that can\n// evaluate'\nabstract class EvalFuncBase\n{\n  public abstract void Evaluate(LispPtr aResult,LispEnvironment aEnvironment, LispPtr aArguments) throws Exception;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/GenericClass.java",
    "content": "package net.sf.yacas;\n\n/// Abstract class which can be put inside a LispGenericClass.\nabstract class GenericClass {\n    public abstract String TypeName();\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/InfixParser.java",
    "content": "package net.sf.yacas;\n\n\nfinal class InfixParser extends LispParser\n{\n  public InfixParser(LispTokenizer aTokenizer, LispInput aInput,\n                LispEnvironment aEnvironment,\n                LispOperators aPrefixOperators,\n                LispOperators aInfixOperators,\n                LispOperators aPostfixOperators,\n                LispOperators aBodiedOperators)\n  {\n    super( aTokenizer,  aInput, aEnvironment);\n    iPrefixOperators = aPrefixOperators;\n    iInfixOperators = aInfixOperators;\n    iPostfixOperators = aPostfixOperators;\n    iBodiedOperators = aBodiedOperators;\n  }\n  @Override\n  public void Parse(LispPtr aResult) throws Exception\n  {\n    ParseCont(aResult);\n  }\n  public void ParseCont(LispPtr aResult) throws Exception\n  {\n    ParsedObject object = new ParsedObject(this);\n    object.Parse();\n    aResult.Set(object.iResult.Get());\n  }\n  public LispOperators iPrefixOperators;\n  public LispOperators iInfixOperators;\n  public LispOperators iPostfixOperators;\n  public LispOperators iBodiedOperators;\n}\n\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/InfixPrinter.java",
    "content": "package net.sf.yacas;\n\nimport java.io.Writer;\n\n\nfinal class InfixPrinter extends LispPrinter\n{\n\n  static int KMaxPrecedence = 60000;\n  public InfixPrinter(LispOperators aPrefixOperators,\n                 LispOperators aInfixOperators,\n                 LispOperators aPostfixOperators,\n                 LispOperators aBodiedOperators)\n  {\n    iPrefixOperators = aPrefixOperators;\n    iInfixOperators = aInfixOperators;\n    iPostfixOperators = aPostfixOperators;\n    iBodiedOperators = aBodiedOperators;\n    iPrevLastChar = 0;\n  }\n  @Override\n  public void Print(LispPtr aExpression, Writer aOutput, LispEnvironment aEnvironment) throws Exception\n  {\n    iCurrentEnvironment = aEnvironment;\n    Print(aExpression, aOutput, KMaxPrecedence);\n  }\n  @Override\n  public void RememberLastChar(char aChar)\n  {\n    iPrevLastChar = aChar;\n  }\n  void Print(LispPtr aExpression, Writer aOutput, int iPrecedence) throws Exception\n  {\n    LispError.LISPASSERT(aExpression.Get() != null);\n\n    String string = aExpression.Get().String();\n    if (string != null)\n    {\n        boolean bracket=false;\n        if (iPrecedence<KMaxPrecedence &&\n            string.charAt(0) == '-' &&\n            (Character.isDigit(string.charAt(1)) || string.charAt(1) == '.')\n           )\n        {\n            bracket=true;\n        }\n        if (bracket) WriteToken(aOutput,\"(\");\n        WriteToken(aOutput,string);\n        if (bracket) WriteToken(aOutput,\")\");\n        return;\n    }\n\n    if (aExpression.Get().Generic() != null) {\n        if (aExpression.Get().Generic() instanceof ArrayClass) {\n            WriteToken(aOutput, \"Array\");\n            WriteToken(aOutput, \"(\");\n            ArrayClass a = (ArrayClass)aExpression.Get().Generic();\n            int n = a.Size();\n            for (int i = 1; i <=n; ++i) {\n                Print(new LispPtr(a.GetElement(i)), aOutput, KMaxPrecedence);\n                if (i != n)\n                    WriteToken(aOutput, \",\");\n            }\n            WriteToken(aOutput, \")\");\n        } else if (aExpression.Get().Generic() instanceof AssociationClass) {\n            WriteToken(aOutput, \"Association\");\n            WriteToken(aOutput, \"(\");\n            Print(((AssociationClass)aExpression.Get().Generic()).ToList(), aOutput, KMaxPrecedence);\n            WriteToken(aOutput, \")\");\n        } else {\n            WriteToken(aOutput,aExpression.Get().Generic().TypeName());\n        }\n\n        return;\n    }\n\n    LispPtr subList = aExpression.Get().SubList();\n    LispError.Check(subList!=null, LispError.KLispErrUnprintableToken);\n    if (subList.Get() == null)\n    {\n        WriteToken(aOutput,\"( )\");\n    }\n    else\n    {\n        int length = LispStandard.InternalListLength(subList);\n        string = subList.Get().String();\n        LispInFixOperator prefix  = iPrefixOperators.get(string);\n        LispInFixOperator infix   = iInfixOperators.get(string);\n        LispInFixOperator postfix = iPostfixOperators.get(string);\n        LispInFixOperator bodied  = iBodiedOperators.get(string);\n        LispInFixOperator op = null;\n\n        if (length!=2)\n        {\n            prefix=null;\n            postfix=null;\n        }\n        if (length!=3)\n        {\n            infix=null;\n        }\n        if (prefix != null)   op=prefix;\n        if (postfix != null)  op=postfix;\n        if (infix != null)    op=infix;\n\n        if (op != null)\n        {\n            LispPtr left  = null;\n            LispPtr right = null;\n\n            if (prefix != null)\n            {\n                right = subList.Get().Next();\n            }\n            else if (infix != null)\n            {\n                left  = subList.Get().Next();\n                right = subList.Get().Next().Get().Next();\n            }\n            else if (postfix != null)\n            {\n                left = subList.Get().Next();\n            }\n\n            if (iPrecedence < op.iPrecedence)\n            {\n                WriteToken(aOutput,\"(\");\n            }\n            else\n            {\n            //Vladimir?    aOutput.Write(\" \");\n            }\n            if (left != null)\n                Print(left, aOutput,op.iLeftPrecedence);\n            WriteToken(aOutput,string);\n            if (right != null)\n                Print(right, aOutput,op.iRightPrecedence);\n            if (iPrecedence < op.iPrecedence)\n                WriteToken(aOutput,\")\");\n        }\n        else\n        {\n            LispIterator iter = new LispIterator(subList.Get().Next());\n            if (string == iCurrentEnvironment.iList.String())\n            {\n                WriteToken(aOutput,\"{\");\n                while (iter.GetObject() != null)\n                {\n                    Print(iter.Ptr(), aOutput, KMaxPrecedence);\n                    iter.GoNext();\n                    if (iter.GetObject() != null)\n                        WriteToken(aOutput,\",\");\n                }\n                WriteToken(aOutput,\"}\");\n            }\n            else if (string == iCurrentEnvironment.iProg.String())\n            {\n                WriteToken(aOutput,\"[\");\n                while (iter.GetObject() != null)\n                {\n                    Print(iter.Ptr(), aOutput, KMaxPrecedence);\n                    iter.GoNext();\n                    WriteToken(aOutput,\";\");\n                }\n                WriteToken(aOutput,\"]\");\n            }\n            else if (string == iCurrentEnvironment.iNth.String())\n            {\n                Print(iter.Ptr(), aOutput, 0);\n                iter.GoNext();\n                WriteToken(aOutput,\"[\");\n                Print(iter.Ptr(), aOutput, KMaxPrecedence);\n                WriteToken(aOutput,\"]\");\n            }\n            else\n            {\n                boolean bracket = false;\n                if (bodied != null)\n                {\n//printf(\"%d > %d\\n\",iPrecedence, bodied.iPrecedence);\n                  if (iPrecedence < bodied.iPrecedence)\n                    bracket = true;\n                }\n                if (bracket) WriteToken(aOutput,\"(\");\n                if (string != null)\n                {\n                  WriteToken(aOutput,string);\n                }\n                else\n                {\n                  Print(subList,aOutput,0);\n                }\n                WriteToken(aOutput,\"(\");\n\n                LispIterator counter = new LispIterator(iter.Ptr());\n                int nr=0;\n\n                while (counter.GetObject() != null)\n                {\n                    counter.GoNext();\n                    nr++;\n                }\n\n                if (bodied != null)\n                    nr--;\n                while (nr-- != 0)\n                {\n                    Print(iter.Ptr(), aOutput, KMaxPrecedence);\n\n                    iter.GoNext();\n                    if (nr != 0)\n                        WriteToken(aOutput,\",\");\n                }\n                WriteToken(aOutput,\")\");\n                if (iter.GetObject() != null)\n                    Print(iter.Ptr(), aOutput, bodied.iPrecedence);\n\n                if (bracket) WriteToken(aOutput,\")\");\n            }\n        }\n    }\n  }\n  void WriteToken(Writer aOutput,String aString) throws Exception\n  {\n    if (LispTokenizer.IsAlNum(iPrevLastChar) && (LispTokenizer.IsAlNum(aString.charAt(0)) || aString.charAt(0)=='_'))\n    {\n        aOutput.write(\" \");\n    }\n    else if (LispTokenizer.IsSymbolic(iPrevLastChar) && LispTokenizer.IsSymbolic(aString.charAt(0)))\n    {\n        aOutput.write(\" \");\n    }\n    aOutput.write(aString);\n    RememberLastChar(aString.charAt(aString.length()-1));\n  }\n  LispOperators iPrefixOperators;\n  LispOperators iInfixOperators;\n  LispOperators iPostfixOperators;\n  LispOperators iBodiedOperators;\n  char iPrevLastChar;\n  LispEnvironment iCurrentEnvironment;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/InputDirectories.java",
    "content": "package net.sf.yacas;\n\nclass InputDirectories extends java.util.ArrayList<String>\n{\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/InputStatus.java",
    "content": "package net.sf.yacas;\n\n\nclass InputStatus\n{\n  public InputStatus()\n  {\n    iFileName = \"none\";\n    iLineNumber = -1;\n  }\n\n  public InputStatus(InputStatus aPreviousStatus)\n  {\n    iFileName = aPreviousStatus.iFileName;\n    iLineNumber = aPreviousStatus.iLineNumber;\n//System.out.println(\"InputStatus construct to \"+iFileName);\n  }\n  public void SetTo(String aFileName)\n  {\n//System.out.println(\"InputStatus set to \"+aFileName);\n    iFileName = aFileName;\n    iLineNumber = 1;\n  }\n  public void RestoreFrom(InputStatus aPreviousStatus)\n  {\n    iFileName = aPreviousStatus.iFileName;\n    iLineNumber = aPreviousStatus.iLineNumber;\n\n//System.out.println(\"InputStatus restore to \"+iFileName);\n\n  }\n  public int LineNumber()\n  {\n    return iLineNumber;\n  }\n  public String FileName()\n  {\n    return iFileName;\n  }\n  public  void NextLine()\n  {\n    iLineNumber++;\n  }\n  String iFileName;\n  int  iLineNumber;\n}\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/JarInputFile.java",
    "content": "package net.sf.yacas;\n\n\nimport java.io.*;\nimport java.net.*;\n\nclass JarInputFile extends StringInput\n{\n  public JarInputFile(String aFileName, InputStatus aStatus) throws Exception\n  {\n    super(new StringBuffer(),aStatus);\n  URL url = new URL(aFileName);\n  JarURLConnection con = (JarURLConnection) url.openConnection();\n    InputStream stream = con.getInputStream();\n    int c;\n    while (true)\n    {\n      c = stream.read();\n      if (c == -1)\n        break;\n      iString.append((char)c);\n    }\n  }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispArgList.java",
    "content": "package net.sf.yacas;\n\n\nabstract class LispArgList\n{\n  public abstract int NrArguments();\n  public abstract String GetArgument(int aIndex);\n  public abstract boolean Compare(int aIndex, String aString);\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispArityUserFunction.java",
    "content": "package net.sf.yacas;\n\n\n/// User function with a specific arity.\n/// This is still an abstract class, but the arity (number of\n/// arguments) of the function is now fixed.\n\nabstract class LispArityUserFunction extends LispUserFunction\n{\n    public abstract int Arity();\n    public abstract boolean IsArity(int aArity);\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispAtom.java",
    "content": "package net.sf.yacas;\n\n\nclass LispAtom extends LispObject\n{\n    static LispObject New(LispEnvironment aEnvironment, String aString) throws Exception\n  {\n    LispObject self;\n    if (LispStandard.IsNumber(aString,true))  // check if aString is a number (int or float)\n    {\n      /// construct a number from a decimal string representation (also create a number object)\n      self = new LispNumber(aString, aEnvironment.Precision());\n    }\n    else\n    {\n      self = new LispAtom(aEnvironment.HashTable().LookUp(aString));\n    }\n    return self;\n  }\n    @Override\n    public String String()\n  {\n    return iString;\n  }\n    @Override\n    public LispObject Copy(boolean aRecursed)\n  {\n     return new LispAtom(iString);\n  }\n    LispAtom(String aString)\n  {\n    iString = aString;\n  }\n    String iString;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispDefFile.java",
    "content": "package net.sf.yacas;\n\nimport java.util.HashSet;\n\n/** LispDefFile represents one file that can be loaded just-in-time.\n */\nclass LispDefFile\n{\n    public LispDefFile(String aFile)\n    {\n      iFileName = aFile;\n      iIsLoaded = false;\n    }\n    public LispDefFile(LispDefFile aOther)\n    {\n      iFileName = aOther.iFileName;\n      iIsLoaded = aOther.iIsLoaded;\n    }\n    public void SetLoaded()\n    {\n      iIsLoaded = true;\n    }\n    public boolean IsLoaded()\n    {\n      return iIsLoaded;\n    }\n    public String FileName()\n    {\n      return iFileName;\n    }\n\n    String iFileName;\n    boolean   iIsLoaded;\n    HashSet<String> symbols = new HashSet<>();\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispDefFiles.java",
    "content": "package net.sf.yacas;\n\nimport java.util.HashMap;\n\nclass LispDefFiles {\n\n    LispDefFile File(String aFileName) {\n        LispDefFile file = map.get(aFileName);\n\n        if (file == null) {\n            file = new LispDefFile(aFileName);\n            map.put(aFileName, file);\n        }\n\n        return file;\n    }\n\n    HashMap<String, LispDefFile> map = new HashMap<>();\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispEnvironment.java",
    "content": "package net.sf.yacas;\n\nimport java.io.Writer;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Set;\nimport static net.sf.yacas.LispError.Check;\n\nfinal class LispEnvironment\n{\n  //TODO FIXME\n\n  LispEnvironment(Writer aCurrentOutput) throws Exception\n  {\n    iCurrentTokenizer = iDefaultTokenizer;\n    iInitialOutput = aCurrentOutput;\n    iCurrentOutput = aCurrentOutput;\n    iCurrentPrinter = new InfixPrinter(iPrefixOperators, iInfixOperators, iPostfixOperators, iBodiedOperators);\n\n    protected_symbols = new HashSet<>();\n\n    iTrue = LispAtom.New(this,\"True\");\n    iFalse = LispAtom.New(this,\"False\");\n\n    Protect(iTrue.String());\n    Protect(iTrue.String());\n\n    iEndOfFile    = LispAtom.New(this,\"EndOfFile\");\n    iEndStatement = LispAtom.New(this,\";\");\n    iProgOpen     = LispAtom.New(this,\"[\");\n    iProgClose    = LispAtom.New(this,\"]\");\n    iNth          = LispAtom.New(this,\"Nth\");\n    iBracketOpen  = LispAtom.New(this,\"(\");\n    iBracketClose = LispAtom.New(this,\")\");\n    iListOpen     = LispAtom.New(this,\"{\");\n    iListClose    = LispAtom.New(this,\"}\");\n    iComma        = LispAtom.New(this,\",\");\n    iList         = LispAtom.New(this,\"List\");\n    iProg         = LispAtom.New(this,\"Prog\");\n\n    Protect(iList.String());\n    Protect(iProg.String());\n\n    Protect(iHashTable.LookUp(\"Infinity\"));\n    Protect(iHashTable.LookUp(\"Undefined\"));\n\n    iStack = new ArrayList<>();\n    MathCommands mc = new MathCommands();\n    mc.AddCommands(this);\n    PushLocalFrame(true);\n  }\n\n  LispHashTable HashTable()\n  {\n    return iHashTable;\n  }\n  int Precision()\n  {\n    return iPrecision;\n  }\n  void SetPrecision(int aPrecision) throws Exception\n  {\n    iPrecision = aPrecision;    // precision in decimal digits\n  }\n  private int iPrecision = 10;\n\n  LispHashTable iHashTable = new LispHashTable();\n  LispObject iTrue;\n  LispObject iFalse;\n\n  LispObject iEndOfFile;\n  LispObject iEndStatement;\n  LispObject iProgOpen;\n  LispObject iProgClose;\n  LispObject iNth;\n  LispObject iBracketOpen;\n  LispObject iBracketClose;\n  LispObject iListOpen;\n  LispObject iListClose;\n  LispObject iComma;\n  LispObject iList;\n  LispObject iProg;\n\n  LispOperators iPrefixOperators = new LispOperators();\n  LispOperators iInfixOperators = new LispOperators();\n  LispOperators iPostfixOperators = new LispOperators();\n  LispOperators iBodiedOperators = new LispOperators();\n\n  Set<String> protected_symbols;\n\n  int iEvalDepth = 0;\n  int iMaxEvalDepth = 1000;\n\n  ArrayList<LispPtr> iStack;\n\n  public HashMap<String, YacasEvaluator> CoreCommands()\n  {\n    return iCoreCommands;\n  }\n\n  HashMap<String, YacasEvaluator> iCoreCommands = new HashMap<>();\n\n  LispEvaluatorBase iEvaluator = new BasicEvaluator();\n\n\n\n\n\n\n\n  LispPtr FindLocal(String aVariable) throws Exception\n  {\n    LispError.Check(iLocalsList != null,LispError.KLispErrInvalidStack);\n//    Check(iLocalsList.iFirst != null,KLispErrInvalidStack);\n    LispLocalVariable t = iLocalsList.iFirst;\n\n    while (t != null)\n    {\n        if (t.iVariable == aVariable)\n        {\n            return t.iValue;\n        }\n        t = t.iNext;\n    }\n    return null;\n  }\n\n  void SetVariable(String aVariable, LispPtr aValue, boolean aGlobalLazyVariable) throws Exception\n  {\n    LispPtr local = FindLocal(aVariable);\n    if (local != null)\n    {\n      local.Set(aValue.Get());\n      return;\n    }\n    // FIXME: or should local variables be protected as well?\n    Check(!IsProtected(aVariable), LispError.KLispErrSymbolProtected);\n\n    LispGlobalVariable global = new LispGlobalVariable(aValue);\n    iGlobals.put(aVariable, global);\n    if (aGlobalLazyVariable)\n    {\n      global.SetEvalBeforeReturn(true);\n    }\n  }\n\n  void GetVariable(String aVariable,LispPtr aResult) throws Exception\n  {\n    aResult.Set(null);\n    LispPtr local = FindLocal(aVariable);\n    if (local != null)\n    {\n      aResult.Set(local.Get());\n      return;\n    }\n    LispGlobalVariable l = iGlobals.get(aVariable);\n    if (l != null)\n    {\n      if (l.iEvalBeforeReturn)\n      {\n        iEvaluator.Eval(this, aResult, l.iValue);\n        l.iValue.Set(aResult.Get());\n        l.iEvalBeforeReturn = false;\n      }\n      else\n      {\n        aResult.Set(l.iValue.Get());\n      }\n    }\n  }\n\n  void UnsetVariable(String aString) throws Exception\n  {\n    LispPtr local = FindLocal(aString);\n    if (local != null)\n    {\n        local.Set(null);\n        return;\n    }\n    // FIXME: or should local variables be protected as well?\n    Check(!IsProtected(aString), LispError.KLispErrSymbolProtected);\n    iGlobals.remove(aString);\n  }\n\n  void PushLocalFrame(boolean aFenced)\n  {\n    if (aFenced)\n    {\n        LocalVariableFrame newFrame =\n            new LocalVariableFrame(iLocalsList, null);\n        iLocalsList = newFrame;\n    }\n    else\n    {\n        LocalVariableFrame newFrame =\n            new LocalVariableFrame(iLocalsList, iLocalsList.iFirst);\n        iLocalsList = newFrame;\n    }\n  }\n\n  void PopLocalFrame() throws Exception\n  {\n    LispError.LISPASSERT(iLocalsList != null);\n    LocalVariableFrame nextFrame = iLocalsList.iNext;\n    iLocalsList.Delete();\n    iLocalsList = nextFrame;\n  }\n\n  void NewLocal(String aVariable,LispObject aValue) throws Exception\n  {\n    LispError.LISPASSERT(iLocalsList != null);\n    iLocalsList.Add(new LispLocalVariable(aVariable, aValue));\n  }\n\n\n  class LispLocalVariable\n  {\n    public LispLocalVariable(String aVariable, LispObject aValue)\n    {\n      iNext = null;\n      iVariable = aVariable;\n      iValue.Set(aValue);\n\n    }\n    LispLocalVariable iNext;\n    String iVariable;\n    LispPtr iValue = new LispPtr();\n  }\n  class LocalVariableFrame\n  {\n\n      public LocalVariableFrame(LocalVariableFrame aNext, LispLocalVariable aFirst)\n      {\n        iNext = aNext;\n        iFirst = aFirst;\n        iLast = aFirst;\n      }\n      void Add(LispLocalVariable aNew)\n      {\n          aNew.iNext = iFirst;\n          iFirst = aNew;\n      }\n      void Delete()\n      {\n        LispLocalVariable t = iFirst;\n        LispLocalVariable next;\n        while (t != iLast)\n        {\n          next = t.iNext;\n          t = next;\n        }\n      }\n\n\n      LocalVariableFrame iNext;\n      LispLocalVariable iFirst;\n      LispLocalVariable iLast;\n  }\n  LocalVariableFrame iLocalsList;\n\n  HashMap<String, LispGlobalVariable> iGlobals = new HashMap<>();\n\n  boolean iSecure = false;\n\n  int iLastUniqueId = 1;\n  public int GetUniqueId()\n  {\n    return iLastUniqueId++;\n  }\n\n  Writer iCurrentOutput = null;\n  Writer iInitialOutput = null;\n\n  LispPrinter iCurrentPrinter = null;\n  LispInput   iCurrentInput   = null;\n  InputStatus iInputStatus    = new InputStatus();\n  LispTokenizer iCurrentTokenizer;\n  LispTokenizer iDefaultTokenizer = new LispTokenizer();\n  LispTokenizer iXmlTokenizer = new XmlTokenizer();\n\n  HashMap<String, LispMultiUserFunction> iUserFunctions = new HashMap<>();\n\n  String iError = null;\n\n  public void HoldArgument(String  aOperator, String aVariable) throws Exception\n  {\n    LispMultiUserFunction multiUserFunc = iUserFunctions.get(aOperator);\n    LispError.Check(multiUserFunc != null,LispError.KLispErrInvalidArg);\n    multiUserFunc.HoldArgument(aVariable);\n  }\n  public void Retract(String aOperator,int aArity) throws Exception\n  {\n    Check(!IsProtected(aOperator), LispError.KLispErrSymbolProtected);\n    LispMultiUserFunction multiUserFunc = iUserFunctions.get(aOperator);\n    if (multiUserFunc != null)\n    {\n      multiUserFunc.DeleteBase(aArity);\n    }\n  }\n\n\n\n  public LispUserFunction UserFunction(LispPtr aArguments) throws Exception\n  {\n    LispMultiUserFunction multiUserFunc =\n        iUserFunctions.get(aArguments.Get().String());\n    if (multiUserFunc != null)\n    {\n      int arity = LispStandard.InternalListLength(aArguments)-1;\n      return  multiUserFunc.UserFunc(arity);\n    }\n    return null;\n  }\n\n  public LispUserFunction UserFunction(String aName,int aArity) throws Exception\n  {\n    LispMultiUserFunction multiUserFunc = iUserFunctions.get(aName);\n    if (multiUserFunc != null)\n    {\n        return  multiUserFunc.UserFunc(aArity);\n    }\n    return null;\n  }\n\n  public void UnFenceRule(String aOperator,int aArity) throws Exception\n  {\n    Check(!IsProtected(aOperator), LispError.KLispErrSymbolProtected);\n    LispMultiUserFunction multiUserFunc = iUserFunctions.get(aOperator);\n\n    LispError.Check(multiUserFunc != null, LispError.KLispErrInvalidArg);\n    LispUserFunction userFunc = multiUserFunc.UserFunc(aArity);\n    LispError.Check(userFunc != null, LispError.KLispErrInvalidArg);\n    userFunc.UnFence();\n  }\n\n  public LispMultiUserFunction MultiUserFunction(String aOperator) throws Exception\n  {\n    // Find existing multiuser func.\n    LispMultiUserFunction multiUserFunc = iUserFunctions.get(aOperator);\n\n    // If none exists, add one to the user functions list\n    if (multiUserFunc == null)\n    {\n        multiUserFunc = new LispMultiUserFunction();\n        iUserFunctions.put(aOperator, multiUserFunc);\n    }\n    return multiUserFunc;\n  }\n\n\n  public void DeclareRuleBase(String aOperator, LispPtr aParameters, boolean aListed) throws Exception\n  {\n    Check(!IsProtected(aOperator), LispError.KLispErrSymbolProtected);\n\n    LispMultiUserFunction multiUserFunc = MultiUserFunction(aOperator);\n\n    // add an operator with this arity to the multiuserfunc.\n    BranchingUserFunction newFunc;\n    if (aListed)\n    {\n        newFunc = new ListedBranchingUserFunction(aParameters);\n    }\n    else\n    {\n        newFunc = new BranchingUserFunction(aParameters);\n    }\n    multiUserFunc.DefineRuleBase(newFunc);\n  }\n\n  public void DefineRule(String aOperator,int aArity,\n                                  int aPrecedence, LispPtr aPredicate,\n                                  LispPtr aBody) throws Exception\n  {\n    Check(!IsProtected(aOperator), LispError.KLispErrSymbolProtected);\n\n    // Find existing multiuser func.\n    LispMultiUserFunction multiUserFunc = iUserFunctions.get(aOperator);\n    LispError.Check(multiUserFunc != null, LispError.KLispErrCreatingRule);\n\n    // Get the specific user function with the right arity\n    LispUserFunction userFunc = multiUserFunc.UserFunc(aArity);\n    LispError.Check(userFunc != null, LispError.KLispErrCreatingRule);\n\n    // Declare a new evaluation rule\n\n\n    if (LispStandard.IsTrue(this, aPredicate))\n    {\n//        printf(\"FastPredicate on %s\\n\",aOperator->String());\n        userFunc.DeclareRule(aPrecedence, aBody);\n    }\n    else\n        userFunc.DeclareRule(aPrecedence, aPredicate,aBody);\n  }\n\n  void DeclareMacroRuleBase(String aOperator, LispPtr aParameters, boolean aListed) throws Exception\n  {\n    Check(!IsProtected(aOperator), LispError.KLispErrSymbolProtected);\n\n    LispMultiUserFunction multiUserFunc = MultiUserFunction(aOperator);\n    MacroUserFunction newFunc;\n    if (aListed)\n    {\n      newFunc = new ListedMacroUserFunction(aParameters);\n    }\n    else\n    {\n      newFunc = new MacroUserFunction(aParameters);\n    }\n    multiUserFunc.DefineRuleBase(newFunc);\n  }\n\n  void DefineRulePattern(String aOperator,int aArity, int aPrecedence, LispPtr aPredicate, LispPtr aBody) throws Exception\n  {\n    // Check(!IsProtected(aOperator), LispError.KLispErrSymbolProtected);\n\n    // Find existing multiuser func.\n    LispMultiUserFunction multiUserFunc = iUserFunctions.get(aOperator);\n    LispError.Check(multiUserFunc != null, LispError.KLispErrCreatingRule);\n\n    // Get the specific user function with the right arity\n    LispUserFunction userFunc = multiUserFunc.UserFunc(aArity);\n    LispError.Check(userFunc != null, LispError.KLispErrCreatingRule);\n\n    // Declare a new evaluation rule\n    userFunc.DeclarePattern(aPrecedence, aPredicate,aBody);\n  }\n\n\n  void Protect(String symbol)\n  {\n      protected_symbols.add(symbol);\n  }\n\n  void UnProtect(String symbol)\n  {\n      protected_symbols.remove(symbol);\n  }\n\n  boolean IsProtected(String symbol)\n  {\n      return protected_symbols.contains(symbol);\n  }\n\n  LispDefFiles iDefFiles = new LispDefFiles();\n  InputDirectories iInputDirectories = new InputDirectories();\n\n  String iPrettyReader = null;\n  String iPrettyPrinter = null;\n\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispError.java",
    "content": "package net.sf.yacas;\n\n\nclass LispError\n{\n  static String ErrorString(int aError) throws Exception\n  {\n    LISPASSERT(aError>=0 && aError < KLispNrErrors);\n//    switch (aError)\n    {\n      if (aError ==  KLispErrNone)\n          return \"No error\";\n      if (aError ==  KLispErrInvalidArg)\n          return \"Invalid argument\";\n      if (aError ==  KLispErrWrongNumberOfArgs)\n          return \"Wrong number of arguments\";\n      if (aError ==  KLispErrNotList)\n          return \"Argument is not a list\";\n      if (aError ==  KLispErrListNotLongEnough)\n          return \"List not long enough\";\n      if (aError ==  KLispErrInvalidStack)\n          return \"Invalid stack\";\n      if (aError ==  KQuitting)\n          return \"Quitting...\";\n      if (aError ==  KLispErrNotEnoughMemory)\n          return \"Not enough memory\";\n      if (aError ==  KInvalidToken)\n          return \"Empty token during parsing\";\n      if (aError ==  KLispErrInvalidExpression)\n          return \"Error parsing expression\";\n      if (aError ==  KLispErrUnprintableToken)\n          return \"Unprintable atom\";\n      if (aError ==  KLispErrFileNotFound)\n          return \"File not found\";\n      if (aError ==  KLispErrReadingFile)\n          return \"Error reading file\";\n      if (aError ==  KLispErrCreatingUserFunction)\n          return \"Could not create user function\";\n      if (aError ==  KLispErrCreatingRule)\n          return \"Could not create rule\";\n      if (aError ==  KLispErrArityAlreadyDefined)\n          return \"Rule base with this arity already defined\";\n      if (aError ==  KLispErrCommentToEndOfFile)\n          return \"Reaching end of file within a comment block\";\n      if (aError ==  KLispErrNotString)\n          return \"Argument is not a string\";\n      if (aError ==  KLispErrNotInteger)\n          return \"Argument is not an integer\";\n      if (aError ==  KLispErrParsingInput)\n          return \"Error while parsing input\";\n      if (aError ==  KLispErrMaxRecurseDepthReached)\n          return \"Max evaluation stack depth reached.\\nPlease use MaxEvalDepth to increase the stack size as needed.\";\n      if (aError ==  KLispErrDefFileAlreadyChosen)\n          return \"DefFile already chosen for function\";\n      if (aError ==  KLispErrDivideByZero)\n          return \"Divide by zero\";\n      if (aError ==  KLispErrNotAnInFixOperator)\n          return \"Trying to make a non-infix operator right-associative\";\n      if (aError ==  KLispErrIsNotInFix)\n          return \"Trying to get precedence of non-infix operator\";\n      if (aError ==  KLispErrSecurityBreach)\n          return \"Trying to perform an insecure action\";\n      if (aError ==  KLispErrLibraryNotFound)\n          return \"Could not find library\";\n      if (aError ==  KLispErrUserInterrupt)\n          return \"User interrupted calculation\";\n      if (aError ==  KLispErrNonBooleanPredicateInPattern)\n          return \"Predicate doesn't evaluate to a boolean in pattern\";\n      if (aError ==  KLispErrSymbolProtected)\n          return \"Trying to modify protected symbol\";\n     if (aError ==  KLispErrGenericFormat) return \"Generic format\";\n    }\n    return \"Unspecified Error\";\n  }\n  static void Check(boolean hastobetrue, int aError) throws Exception\n  {\n    if (!hastobetrue)\n    {\n      String error = ErrorString(aError);//\"Error number \"+aError+\" (//TODO FIXME still need to port over the string table)\";\n      throw new YacasException(error);\n    }\n  }\n  static void RaiseError(String str) throws Exception\n  {\n      throw new YacasException(str);\n  }\n\n  public static void CheckNrArgs(int n, LispPtr aArguments, LispEnvironment aEnvironment) throws Exception\n  {\n    int nrArguments = LispStandard.InternalListLength(aArguments);\n    if (nrArguments != n)\n    {\n      ErrorNrArgs(n-1, nrArguments-1, aArguments, aEnvironment);\n    }\n  }\n  static void ErrorNrArgs(int needed, int passed, LispPtr aArguments, LispEnvironment aEnvironment) throws Exception\n  {\n    if (aArguments.Get() == null)\n    {\n      throw new YacasException(\"Error in compiled code.\");\n    }\n    else\n    {\n//TODO FIXME      ShowStack(aEnvironment);\n      String error = ShowFunctionError(aArguments, aEnvironment) + \"expected \"+needed+\" arguments, got \"+passed;\n      throw new YacasException(error);\n\n/*TODO FIXME\n      LispChar str[20];\n      aEnvironment.iErrorOutput.Write(\"expected \");\n      InternalIntToAscii(str,needed);\n      aEnvironment.iErrorOutput.Write(str);\n      aEnvironment.iErrorOutput.Write(\" arguments, got \");\n      InternalIntToAscii(str,passed);\n      aEnvironment.iErrorOutput.Write(str);\n      aEnvironment.iErrorOutput.Write(\"\\n\");\n      LispError.Check(passed == needed,LispError.KLispErrWrongNumberOfArgs);\n*/\n    }\n  }\n\n  static String ShowFunctionError(LispPtr aArguments, LispEnvironment aEnvironment) throws Exception\n  {\n    if (aArguments.Get() == null)\n    {\n      return \"Error in compiled code. \";\n    }\n    else\n    {\n      String string = aArguments.Get().String();\n      if (string != null)\n      {\n        return \"In function \\\"\" + string + \"\\\" : \";\n      }\n    }\n    return \"[Atom]\";\n  }\n  public static void CHK_CORE(LispEnvironment aEnvironment,int aStackTop,boolean aPredicate ,int errNo) throws Exception\n  {\n    if (!aPredicate)\n    {\n        LispPtr arguments = YacasEvalCaller.ARGUMENT(aEnvironment,aStackTop,0);\n        if (arguments.Get() == null)\n        {\n          throw new YacasException(\"Error in compiled code\\n\");\n        }\n        else\n        {\n          String error = \"\";\n//TODO FIXME          ShowStack(aEnvironment);\n          error = error + ShowFunctionError(arguments, aEnvironment) + \"generic error\";\n          throw new YacasException(error);\n        }\n      }\n  }\n  public static void LISPASSERT(boolean aPredicate) throws Exception\n  {\n    if (!aPredicate)\n      throw new YacasException(\"Assertion failed\");\n  }\n  public static void CHK_ARG_CORE(LispEnvironment aEnvironment,int aStackTop,boolean aPredicate,int aArgNr) throws Exception\n  {\n    CheckArgTypeWithError(aEnvironment, aStackTop, aPredicate, aArgNr,\"\");\n  }\n  public static void CHK_ISLIST_CORE(LispEnvironment aEnvironment,int aStackTop,LispPtr evaluated,int aArgNr) throws Exception\n  {\n    CheckArgTypeWithError(aEnvironment, aStackTop, LispStandard.InternalIsList(evaluated), aArgNr,\"argument is not a list\");\n  }\n  public static void CHK_ISSTRING_CORE(LispEnvironment aEnvironment,int aStackTop,LispPtr evaluated,int aArgNr) throws Exception\n  {\n    CheckArgTypeWithError(aEnvironment, aStackTop, LispStandard.InternalIsString(evaluated.Get().String()), aArgNr,\"argument is not a string\");\n  }\n  public static void CheckArgTypeWithError(LispEnvironment aEnvironment,int aStackTop,boolean aPredicate,int aArgNr, String aErrorDescription) throws Exception\n  {\n    if (!aPredicate)\n    {\n        LispPtr arguments = YacasEvalCaller.ARGUMENT(aEnvironment,aStackTop,0);\n        if (arguments.Get() == null)\n        {\n          throw new YacasException(\"Error in compiled code\\n\");\n        }\n        else\n        {\n          String error = \"\";\n//TODO FIXME          ShowStack(aEnvironment);\n          error = error + ShowFunctionError(arguments, aEnvironment) + \"\\nbad argument number \"+aArgNr+\"(counting from 1) : \\n\"+aErrorDescription + \"\\n\";\n          LispPtr arg = YacasEvalCaller.Argument(arguments,aArgNr);\n          String strout;\n\n          error = error + \"The offending argument \";\n          strout = LispStandard.PrintExpression(arg, aEnvironment, 60);\n          error = error + strout;\n\n          LispPtr eval = new LispPtr();\n          aEnvironment.iEvaluator.Eval(aEnvironment, eval, arg);\n          error = error + \" evaluated to \";\n          strout = LispStandard.PrintExpression(eval, aEnvironment, 60);\n          error = error + strout;\n          error = error + \"\\n\";\n\n          throw new YacasException(error);\n        }\n    }\n  }\n\n\n  static int KLispErrNone                   = 0;\n  static int KLispErrInvalidArg             = 1;\n  static int KLispErrWrongNumberOfArgs      = 2;\n  static int KLispErrNotList                = 3;\n  static int KLispErrListNotLongEnough      = 4;\n  static int KLispErrInvalidStack           = 5;\n  static int KQuitting                      = 6;\n  static int KLispErrNotEnoughMemory        = 7;\n  static int KInvalidToken                  = 8;\n  static int KLispErrInvalidExpression      = 9;\n  static int KLispErrUnprintableToken       = 10;\n  static int KLispErrFileNotFound           = 11;\n  static int KLispErrReadingFile            = 12;\n  static int KLispErrCreatingUserFunction   = 13;\n  static int KLispErrCreatingRule           = 14;\n  static int KLispErrArityAlreadyDefined    = 15;\n  static int KLispErrCommentToEndOfFile     = 16;\n  static int KLispErrNotString              = 17;\n  static int KLispErrNotInteger             = 18;\n  static int KLispErrParsingInput           = 19;\n  static int KLispErrMaxRecurseDepthReached = 20;\n  static int KLispErrDefFileAlreadyChosen   = 21;\n  static int KLispErrDivideByZero           = 22;\n  static int KLispErrNotAnInFixOperator     = 23;\n  static int KLispErrIsNotInFix             = 24;\n  static int KLispErrSecurityBreach         = 25;\n  static int KLispErrLibraryNotFound        = 26;\n  static int KLispErrUserInterrupt          = 27;\n  static int KLispErrNonBooleanPredicateInPattern = 28;\n  static int KLispErrSymbolProtected        = 29;\n  static int KLispErrGenericFormat          = 30;\n  static int KLispNrErrors                  = 31;\n\n\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispEvaluatorBase.java",
    "content": "package net.sf.yacas;\n\nimport java.io.OutputStream;\n\n\n/// Abstract evaluator for Lisp expressions.\n/// Eval() is a pure virtual function, to be provided by the derived class.\n/// The other functions are stubs.\n\nabstract class LispEvaluatorBase\n{\n    public abstract void Eval(LispEnvironment aEnvironment, LispPtr aResult, LispPtr aExpression) throws Exception;\n    public void ResetStack()\n    {\n    }\n    public UserStackInformation StackInformation()\n    {\n      return iBasicInfo;\n    }\n    public void ShowStack(LispEnvironment aEnvironment, OutputStream aOutput)\n    {\n    }\n    UserStackInformation iBasicInfo = new UserStackInformation();\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispGenericClass.java",
    "content": "package net.sf.yacas;\n\n\nclass LispGenericClass extends LispObject\n{\n\n    public static LispGenericClass New(GenericClass aClass) throws Exception\n    {\n      LispError.LISPASSERT(aClass!=null);\n      return new LispGenericClass(aClass);\n    }\n    @Override\n    public GenericClass Generic()\n    {\n      return iClass;\n    }\n    @Override\n    public String String()\n    {\n      return null;\n    }\n    @Override\n    public LispObject Copy(boolean aRecursed)\n    {\n      LispObject copied = new LispGenericClass(iClass);\n      return copied;\n    }\n    LispGenericClass(GenericClass aClass)\n    {\n      iClass = aClass;\n    }\n    GenericClass iClass;\n}"
  },
  {
    "path": "jyacas/net/sf/yacas/LispGlobalVariable.java",
    "content": "package net.sf.yacas;\n\n\n/// Value of a Lisp global variable.\n/// The only special feature of this class is the attribute\n/// #iEvalBeforeReturn, which defaults to #LispFalse. If this\n/// attribute is set to #LispTrue, the value in #iValue needs to be\n/// evaluated to get the value of the Lisp variable.\n/// \\sa LispEnvironment::GetVariable()\n\nfinal class LispGlobalVariable\n{\n  public LispGlobalVariable(LispGlobalVariable aOther)\n  {\n    iValue = aOther.iValue;\n    iEvalBeforeReturn = aOther.iEvalBeforeReturn;\n  }\n  public LispGlobalVariable(LispPtr aValue)\n  {\n    iValue.Set(aValue.Get());\n    iEvalBeforeReturn = false;\n  }\n  public  void SetEvalBeforeReturn(boolean aEval)\n  {\n   iEvalBeforeReturn = aEval;\n  }\n  LispPtr iValue = new LispPtr();\n  boolean iEvalBeforeReturn;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispHashTable.java",
    "content": "package net.sf.yacas;\n\nclass LispHashTable {\n\n    String LookUp(String aString) {\n        return aString.intern();\n    }\n\n    String LookUpStringify(String aString) {\n        return (\"\\\"\" + aString + \"\\\"\").intern();\n    }\n\n    String LookUpUnStringify(String aString) {\n        return aString.substring(1, aString.length() - 1).intern();\n    }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispInFixOperator.java",
    "content": "package net.sf.yacas;\n\n\nclass LispInFixOperator\n{\n  public LispInFixOperator(int aPrecedence)\n  {\n    iPrecedence = aPrecedence;\n    iLeftPrecedence = aPrecedence;\n    iRightPrecedence = aPrecedence;\n    iRightAssociative = 0;\n  }\n  public void SetRightAssociative()\n  {\n      iRightAssociative = 1;\n  }\n  public void SetLeftPrecedence(int aPrecedence)\n  {\n      iLeftPrecedence = aPrecedence;\n  }\n  public void SetRightPrecedence(int aPrecedence)\n  {\n      iRightPrecedence = aPrecedence;\n  }\n  public int iPrecedence;\n  public int iLeftPrecedence;\n  public int iRightPrecedence;\n  public int iRightAssociative;\n}\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispInput.java",
    "content": "package net.sf.yacas;\n\n\n/** \\class LispInput : pure abstract class declaring the interface\n *  that needs to be implemented by a file (something that expressions\n *  can be read from).\n */\nabstract class LispInput\n{\n    /** Constructor with InputStatus. InputStatus retains the information\n     * needed when an error occurred, and the file has already been\n     * closed.\n     */\n    public LispInput(InputStatus aStatus)\n  {\n    iStatus = aStatus;\n  }\n\n    /// Return the next character in the file\n    public abstract char Next() throws Exception;\n\n    /** Peek at the next character in the file, without advancing the file\n     *  pointer.\n     */\n    public abstract char Peek() throws Exception;\n\n    public InputStatus Status()\n  {\n    return iStatus;\n  }\n\n    /// Check if the file position is past the end of the file.\n    public abstract boolean EndOfStream();\n\n    public abstract int Position();\n    public abstract void SetPosition(int aPosition);\n\n    InputStatus iStatus;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispIterator.java",
    "content": "package net.sf.yacas;\n\n/**\n * class LispIterator works almost like LispPtr, but doesn't enforce\n * reference counting, so it should be slightly faster. This one\n * should be used in stead of LispPtr if you are going to traverse\n * a lisp expression in a non-destructive way.\n */\nclass LispIterator\n{\n  public LispIterator(LispPtr aPtr)\n  {\n    iPtr = aPtr;\n  }\n  public LispObject GetObject()\n  {\n    return iPtr.Get();\n  }\n  public LispPtr Ptr()\n  {\n    return iPtr;\n  }\n  public void GoNext() throws Exception\n  {\n    LispError.Check(iPtr.Get() != null,LispError.KLispErrListNotLongEnough);\n    iPtr = (iPtr.Get().Next());\n  }\n  public void GoSub() throws Exception\n  {\n    LispError.Check(iPtr.Get() != null,LispError.KLispErrInvalidArg);\n    LispError.Check(iPtr.Get().SubList() != null,LispError.KLispErrNotList);\n    iPtr = iPtr.Get().SubList();\n  }\n  LispPtr iPtr;\n}"
  },
  {
    "path": "jyacas/net/sf/yacas/LispLocalFrame.java",
    "content": "package net.sf.yacas;\n\n\n// Local lisp stack, unwindable by the exception handler\nclass LispLocalFrame\n{\n  public LispLocalFrame(LispEnvironment aEnvironment, boolean aFenced)\n  {\n    iEnvironment = aEnvironment;\n    iEnvironment.PushLocalFrame(aFenced);\n  }\n  public void Delete() throws Exception\n  {\n    iEnvironment.PopLocalFrame();\n  }\n\n  LispEnvironment iEnvironment;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispMultiUserFunction.java",
    "content": "package net.sf.yacas;\n\n\nimport java.util.*;\n\n/// Set of LispArityUserFunction's.\n/// By using this class, you can associate multiple functions (with\n/// different arities) to one name. A specific LispArityUserFunction\n/// can be selected by providing its name. Additionally, the name of\n/// the file in which the function is defined, can be specified.\n\nclass LispMultiUserFunction\n{\n    /// Constructor.\n    public LispMultiUserFunction()\n    {\n      iFileToOpen = null;\n    }\n\n    /// Return user function with given arity.\n    public LispUserFunction UserFunc(int aArity) throws Exception\n    {\n      int i;\n      //Find function body with the right arity\n      int nrc=iFunctions.size();\n      for (i=0;i<nrc;i++)\n      {\n        LispError.LISPASSERT(iFunctions.get(i) != null);\n        if (((LispArityUserFunction)iFunctions.get(i)).IsArity(aArity))\n        {\n          return iFunctions.get(i);\n        }\n      }\n\n      // if function not found, just unaccept!\n      // User-defined function not found! Returning null\n      return null;\n    }\n\n    /// Specify that some argument should be held.\n    public void HoldArgument(String aVariable) throws Exception\n    {\n      int i;\n      for (i=0;i<iFunctions.size();i++)\n      {\n        LispError.LISPASSERT(iFunctions.get(i) != null);\n        iFunctions.get(i).HoldArgument(aVariable);\n      }\n    }\n\n    /// Add another LispArityUserFunction to #iFunctions.\n    public  void DefineRuleBase(LispArityUserFunction aNewFunction) throws Exception\n    {\n      int i;\n      //Find function body with the right arity\n      int nrc=iFunctions.size();\n      for (i=0;i<nrc;i++)\n      {\n          LispError.LISPASSERT(((LispArityUserFunction)iFunctions.get(i)) != null);\n          LispError.LISPASSERT(aNewFunction != null);\n          LispError.Check(!((LispArityUserFunction)iFunctions.get(i)).IsArity(aNewFunction.Arity()),LispError.KLispErrArityAlreadyDefined);\n          LispError.Check(!aNewFunction.IsArity(((LispArityUserFunction)iFunctions.get(i)).Arity()),LispError.KLispErrArityAlreadyDefined);\n      }\n      iFunctions.add(aNewFunction);\n    }\n\n    /// Delete tuser function with given arity.\n    public  void DeleteBase(int aArity) throws Exception\n    {\n      int i;\n      //Find function body with the right arity\n      int nrc=iFunctions.size();\n      for (i=0;i<nrc;i++)\n      {\n        LispError.LISPASSERT(((LispArityUserFunction)iFunctions.get(i)) != null);\n        if (((LispArityUserFunction)iFunctions.get(i)).IsArity(aArity))\n        {\n          iFunctions.remove(i);\n          return;\n        }\n      }\n    }\n\n\n    /// Set of LispArityUserFunction's provided by this LispMultiUserFunction.\n    ArrayList<LispUserFunction> iFunctions = new ArrayList<>();\n\n    /// File to read for the definition of this function.\n    LispDefFile iFileToOpen;\n}"
  },
  {
    "path": "jyacas/net/sf/yacas/LispNumber.java",
    "content": "package net.sf.yacas;\n\n\nclass LispNumber extends LispObject\n{\n    /// constructors:\n    /// construct from another LispNumber\n    public LispNumber(BigNumber aNumber,String aString)\n  {\n    iString = aString;\n    iNumber = aNumber;\n  }\n    /// construct from a BigNumber; the string representation will be absent\n    public LispNumber(BigNumber aNumber)\n  {\n    iString = null;\n    iNumber =aNumber;\n  }\n  /// construct from a decimal string representation (also create a number object) and use aBasePrecision decimal digits\n    public LispNumber(String aString, int aBasePrecision)\n  {\n    iString = aString;\n    iNumber = null;  // purge whatever it was\n    // create a new BigNumber object out of iString, set its precision in digits\n//TODO FIXME enable this in the end    Number(aBasePrecision);\n  }\n    @Override\n  public LispObject Copy(boolean aRecursed)\n  {\n    return new LispNumber(iNumber, iString);\n  }\n    /// return a string representation in decimal with maximum decimal precision allowed by the inherent accuracy of the number\n    @Override\n    public String String() throws Exception\n     {\n    if (iString == null)\n    {\n      LispError.LISPASSERT(iNumber != null);  // either the string is null or the number but not both\n      iString = iNumber.ToString(0/*TODO FIXME*/,10);\n    // export the current number to string and store it as LispNumber::iString\n    }\n    return iString;\n  }\n    /// give access to the BigNumber object; if necessary, will create a BigNumber object out of the stored string, at given precision (in decimal?)\n    @Override\n    public BigNumber Number(int aPrecision) throws Exception\n  {\n    if (iNumber == null)\n    {  // create and store a BigNumber out of string\n      LispError.LISPASSERT(iString != null);\n      String str;\n      str = iString;\n      // aBasePrecision is in digits, not in bits, ok\n      iNumber = new BigNumber(str, aPrecision, 10/*TODO FIXME BASE10*/);\n    }\n\n    // check if the BigNumber object has enough precision, if not, extend it\n    // (applies only to floats). Note that iNumber->GetPrecision() might be < 0\n\n    else if (!iNumber.IsInt() && iNumber.GetPrecision() < aPrecision)\n    {\n      if (iString != null)\n      {// have string representation, can extend precision\n        iNumber.SetTo(iString,aPrecision, 10);\n      }\n      else\n      {\n      // do not have string representation, cannot extend precision!\n      }\n    }\n\n    return iNumber;\n  }\n    /// number object; NULL if not yet converted from string\n    BigNumber iNumber;\n    /// string representation in decimal; NULL if not yet converted from BigNumber\n    String iString;\n}"
  },
  {
    "path": "jyacas/net/sf/yacas/LispObject.java",
    "content": "package net.sf.yacas;\n\n\n/** class LispObject is the base object class that can be put in\n *  linked lists. It either has a pointer to a string, obtained through\n *  String(), or it is a holder for a sublist, obtainable through SubList(),\n *  or it is a generic object, in which case Generic() returns non-NULL.\n *  Only one of these three functions should return a non-NULL value.\n *  It is a reference-counted object. LispPtr handles the reference counting.\n */\nabstract class LispObject extends LispPtr\n{\n  public  LispPtr Next()\n  {\n    return this;\n  }\n\n  /** Return string representation, or NULL if the object doesn't have one.\n    *  the string representation is only relevant if the object is a\n    *  simple atom. This method returns NULL by default.\n    */\n  public abstract String String() throws Exception;\n  /** If this object is a list, return a pointer to it.\n    *  Default behaviour is to return NULL.\n    */\n  public LispPtr SubList()\n  {\n    return null;\n  }\n  public GenericClass Generic()\n  {\n    return null;\n  }\n\n  /** If this is a number, return a BigNumber representation\n    */\n  public BigNumber Number(int aPrecision) throws Exception\n  {\n    return null;\n  }\n\n  public abstract LispObject Copy(boolean aRecursed) throws Exception;\n\n  public boolean Equal(LispObject aOther) throws Exception\n  {\n    // next line handles the fact that either one is a string\n    if (String() != aOther.String())\n      return false;\n\n    //So, no strings.\n    LispPtr iter1 = SubList();\n    LispPtr iter2 = aOther.SubList();\n    if (!(iter1 != null && iter2 != null))\n      return false;\n\n    // check all elements in sublist\n    while (iter1.Get()!= null && iter2.Get()!=null)\n    {\n      if (! iter1.Get().Equal(iter2.Get() ))\n        return false;\n\n      iter1 = iter1.Get().Next();\n      iter2 = iter2.Get().Next();\n    }\n      //One list longer than the other?\n          return iter1.Get()== null && iter2.Get()==null;\n  }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispOperators.java",
    "content": "package net.sf.yacas;\n\nimport java.util.HashMap;\n\nclass LispOperators extends HashMap<String, LispInFixOperator>\n{\n  public void SetOperator(int aPrecedence,String aString)\n  {\n    LispInFixOperator op = new LispInFixOperator(aPrecedence);\n    put(aString, op);\n  }\n  public void SetRightAssociative(String aString) throws Exception\n  {\n    LispInFixOperator op = get(aString);\n    LispError.Check(op != null, LispError.KLispErrNotAnInFixOperator);\n    op.SetRightAssociative();\n  }\n  public void SetLeftPrecedence(String aString,int aPrecedence) throws Exception\n  {\n    LispInFixOperator op = get(aString);\n    LispError.Check(op != null, LispError.KLispErrNotAnInFixOperator);\n    op.SetLeftPrecedence(aPrecedence);\n  }\n  public void SetRightPrecedence(String aString,int aPrecedence) throws Exception\n  {\n    LispInFixOperator op = get(aString);\n    LispError.Check(op != null,LispError.KLispErrNotAnInFixOperator);\n    op.SetRightPrecedence(aPrecedence);\n  }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispParser.java",
    "content": "package net.sf.yacas;\n\n\nclass LispParser\n{\n   public LispParser(LispTokenizer aTokenizer, LispInput aInput,\n              LispEnvironment aEnvironment)\n   {\n     iTokenizer = aTokenizer;\n   iInput = aInput;\n   iEnvironment = aEnvironment;\n     iListed = false;\n   }\n   public void Parse(LispPtr aResult ) throws Exception\n   {\n  aResult.Set(null);\n\n  String token;\n  // Get token.\n  token = iTokenizer.NextToken(iInput,iEnvironment.HashTable());\n  if (token.length() == 0) //TODO FIXME either token == null or token.length() == 0?\n  {\n    aResult.Set(LispAtom.New(iEnvironment,\"EndOfFile\"));\n    return;\n  }\n  ParseAtom(aResult,token);\n   }\n\n   void ParseList(LispPtr aResult) throws Exception\n   {\n    String token;\n\n    LispPtr iter = aResult;\n    if (iListed)\n    {\n        aResult.Set(LispAtom.New(iEnvironment,\"List\"));\n        iter  = (aResult.Get().Next()); //TODO FIXME\n    }\n    for (;;)\n    {\n        //Get token.\n        token = iTokenizer.NextToken(iInput,iEnvironment.HashTable());\n        // if token is empty string, error!\n        LispError.Check(token.length() > 0,LispError.KInvalidToken); //TODO FIXME\n        // if token is \")\" return result.\n        if (token == iEnvironment.HashTable().LookUp(\")\"))\n        {\n            return;\n        }\n        // else parse simple atom with Parse, and append it to the\n        // results list.\n\n        ParseAtom(iter,token);\n        iter = (iter.Get().Next()); //TODO FIXME\n    }\n   }\n\n   void ParseAtom(LispPtr aResult,String aToken) throws Exception\n   {\n    // if token is empty string, return null pointer (no expression)\n    if (aToken.length() == 0) //TODO FIXME either token == null or token.length() == 0?\n        return;\n    // else if token is \"(\" read in a whole array of objects until \")\",\n    //   and make a sublist\n    if (aToken == iEnvironment.HashTable().LookUp(\"(\"))\n    {\n        LispPtr subList = new LispPtr();\n        ParseList(subList);\n        aResult.Set(LispSubList.New(subList.Get()));\n        return;\n    }\n    // else make a simple atom, and return it.\n    aResult.Set(LispAtom.New(iEnvironment,aToken));\n   }\n   public LispTokenizer iTokenizer;\n   public LispInput iInput;\n   public LispEnvironment iEnvironment;\n   public boolean iListed;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispPrinter.java",
    "content": "package net.sf.yacas;\n\nimport java.io.Writer;\n\n\nclass LispPrinter\n{\n  public void Print(LispPtr aExpression, Writer aOutput, LispEnvironment aEnvironment) throws Exception\n  {\n    PrintExpression(aExpression, aOutput, aEnvironment,0);\n  }\n  public void RememberLastChar(char aChar)\n  {\n  }\n\n   void PrintExpression(LispPtr aExpression, Writer aOutput,\n                        LispEnvironment aEnvironment,int aDepth /* =0 */) throws Exception\n   {\n    LispPtr iter = new LispPtr();\n    iter.Set(aExpression.Get());\n    int item = 0;\n    while (iter.Get() != null)\n    {\n        // if String not null pointer: print string\n        String string = iter.Get().String();\n\n        if (string != null)\n        {\n            aOutput.write(string);\n            aOutput.write(\" \");\n        }\n        // else print \"(\", print sublist, and print \")\"\n        else if (iter.Get().SubList() != null)\n        {\n      if (item != 0)\n      {\n        Indent(aOutput,aDepth+1);\n      }\n            aOutput.write(\"(\");\n            PrintExpression((iter.Get().SubList()),aOutput, aEnvironment,aDepth+1);\n            aOutput.write(\")\");\n      item=0;\n        }\n        else\n        {\n            aOutput.write(\"[GenericObject]\");\n        }\n        iter = (iter.Get().Next());\n  item++;\n    } // print next element\n   }\n\n    void Indent(Writer aOutput, int aDepth) throws Exception {\n        aOutput.write(\"\\n\");\n        int i;\n        for (i = aDepth; i > 0; i--) {\n            aOutput.write(\"  \");\n        }\n    }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispPtr.java",
    "content": "package net.sf.yacas;\n\n\n/** class LispPtr. This class is a smart pointer type class to Lisp\n *  objects that can be inserted into linked lists. They do the actual\n *  reference counting, and consequent destruction of the object if\n *  nothing points to it. LispPtr is used in LispObject as a pointer\n *  to the next object, and in diverse parts of the built-in internal\n *  functions to hold temporary values.\n */\nclass LispPtr\n{\n    public LispPtr()\n  {\n    iNext = null;\n  }\n    public LispPtr(LispPtr aOther)\n  {\n    iNext = aOther.iNext;\n  }\n    public LispPtr(LispObject aOther)\n  {\n    iNext = aOther;\n  }\n    public void Set(LispObject aNext)\n  {\n    iNext = aNext;\n  }\n    public LispObject Get()\n  {\n    return iNext;\n  }\n    public void GoNext()\n  {\n    iNext = iNext.iNext.iNext;\n  }\n    void DoSet(LispObject aNext)\n  {\n    iNext = aNext;\n  }\n    LispObject iNext;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispPtrArray.java",
    "content": "package net.sf.yacas;\n\n\n/** \\class LispPtrArray is similar to LispPtr, but implements an array\n *  of pointers to objects.\n */\nclass LispPtrArray\n{\n  public LispPtrArray(int aSize,LispObject aInitialItem)\n  {\n    iArray = new LispPtr[aSize];\n    iSize = aSize;\n    int i;\n    for(i=0;i<aSize;i++)\n    {\n      iArray[i] = new LispPtr();\n      iArray[i].Set(aInitialItem);\n    }\n  }\n  public int Size()\n  {\n    return iSize;\n  }\n  public LispPtr GetElement(int aItem)\n  {\n    return iArray[aItem];\n  }\n  public void SetElement(int aItem,LispObject aObject)\n  {\n    iArray[aItem].Set(aObject);\n  }\n  int iSize;\n  LispPtr iArray[];\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispStandard.java",
    "content": "package net.sf.yacas;\n\nimport java.io.StringWriter;\nimport java.io.Writer;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\n\n\nclass LispStandard\n{\n  static boolean IsNumber(String ptr, boolean aAllowFloat)\n  {\n    int pos = 0;\n    if (ptr.charAt(pos) == '-' || ptr.charAt(pos) == '+')\n        pos++;\n\n    int nrDigits=0;\n    int index=0;\n    if (pos+index == ptr.length())\n      return false;\n    while(ptr.charAt(pos+index) >= '0' && ptr.charAt(pos+index) <= '9')\n    {\n        nrDigits++;\n        index++;\n        if (pos+index == ptr.length())\n          return true;\n    }\n    if (ptr.charAt(pos+index) == '.')\n    {\n        if (!aAllowFloat)\n            return false;\n        index++;\n        if (pos+index == ptr.length())\n          return true;\n        while(ptr.charAt(pos+index) >= '0' && ptr.charAt(pos+index) <= '9')\n        {\n            nrDigits++;\n            index++;\n            if (pos+index == ptr.length())\n              return true;\n        }\n    }\n    if (nrDigits == 0)\n        return false;\n    if (ptr.charAt(pos+index) == 'e' || ptr.charAt(pos+index) == 'E')\n    {\n        if (!aAllowFloat)\n            return false;\n        index++;\n        if (pos+index == ptr.length())\n          return true;\n        if (ptr.charAt(pos+index) == '-' || ptr.charAt(pos+index) == '+') index++;\n        while(ptr.charAt(pos+index) >= '0' && ptr.charAt(pos+index) <= '9')\n        {\n          index++;\n          if (pos+index == ptr.length())\n            return true;\n        }\n    }\n    return ptr.length() == (pos+index);\n  }\n\n  static int InternalListLength(LispPtr aOriginal) throws Exception\n  {\n    LispIterator iter = new LispIterator(aOriginal);\n    int length = 0;\n    while (iter.GetObject() != null)\n    {\n      iter.GoNext();\n      length++;\n    }\n    return length;\n  }\n  static void InternalReverseList(LispPtr aResult, LispPtr aOriginal)\n  {\n    LispPtr iter = new LispPtr(aOriginal);\n    LispPtr previous = new LispPtr();\n    LispPtr tail = new LispPtr();\n    tail.Set(aOriginal.Get());\n\n    while (iter.Get() != null)\n    {\n      tail.Set(iter.Get().Next().Get());\n      iter.Get().Next().Set(previous.Get());\n      previous.Set(iter.Get());\n      iter.Set(tail.Get());\n    }\n    aResult.Set(previous.Get());\n  }\n\n  public static void ReturnUnEvaluated(LispPtr aResult,LispPtr aArguments, LispEnvironment aEnvironment) throws Exception\n  {\n    LispPtr full = new LispPtr();\n    full.Set(aArguments.Get().Copy(false));\n    aResult.Set(LispSubList.New(full.Get()));\n\n    LispIterator iter = new LispIterator(aArguments);\n    iter.GoNext();\n\n    while (iter.GetObject() != null)\n    {\n      LispPtr next = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, next, iter.Ptr());\n      full.Get().Next().Set(next.Get());\n      full.Set(next.Get());\n      iter.GoNext();\n    }\n    full.Get().Next().Set(null);\n  }\n\n\n\n\n  public static void InternalApplyString(LispEnvironment aEnvironment, LispPtr aResult,\n                 String aOperator,LispPtr aArgs) throws Exception\n  {\n    LispError.Check(InternalIsString(aOperator),LispError.KLispErrNotString);\n\n    LispObject head =\n        LispAtom.New(aEnvironment,SymbolName(aEnvironment, aOperator));\n    head.Next().Set(aArgs.Get());\n    LispPtr body = new LispPtr();\n    body.Set(LispSubList.New(head));\n    aEnvironment.iEvaluator.Eval(aEnvironment, aResult, body);\n  }\n\n  public static void InternalApplyPure(LispPtr oper,LispPtr args2,LispPtr aResult, LispEnvironment aEnvironment) throws Exception\n  {\n      LispError.Check(oper.Get().SubList() != null,LispError.KLispErrInvalidArg);\n      LispError.Check(oper.Get().SubList().Get() != null,LispError.KLispErrInvalidArg);\n      LispPtr oper2 = new LispPtr();\n      oper2.Set(oper.Get().SubList().Get().Next().Get());\n      LispError.Check(oper2.Get() != null,LispError.KLispErrInvalidArg);\n\n      LispPtr body = new LispPtr();\n      body.Set(oper2.Get().Next().Get());\n      LispError.Check(body.Get() != null,LispError.KLispErrInvalidArg);\n\n      LispError.Check(oper2.Get().SubList() != null,LispError.KLispErrInvalidArg);\n      LispError.Check(oper2.Get().SubList().Get() != null,LispError.KLispErrInvalidArg);\n      oper2.Set(oper2.Get().SubList().Get().Next().Get());\n\n      aEnvironment.PushLocalFrame(false);\n      try\n      {\n        while (oper2.Get() != null)\n        {\n            LispError.Check(args2.Get() != null,LispError.KLispErrInvalidArg);\n\n            String var = oper2.Get().String();\n            LispError.Check(var != null,LispError.KLispErrInvalidArg);\n            LispPtr newly = new LispPtr();\n            newly.Set(args2.Get().Copy(false));\n            aEnvironment.NewLocal(var,newly.Get());\n            oper2.Set(oper2.Get().Next().Get());\n            args2.Set(args2.Get().Next().Get());\n        }\n        LispError.Check(args2.Get() == null,LispError.KLispErrInvalidArg);\n        aEnvironment.iEvaluator.Eval(aEnvironment, aResult, body);\n      }\n      catch (YacasException e) { throw e; }\n      finally { aEnvironment.PopLocalFrame(); }\n\n  }\n\n  public static void InternalTrue(LispEnvironment aEnvironment, LispPtr aResult) throws Exception\n  {\n    aResult.Set(aEnvironment.iTrue.Copy(false));\n  }\n\n  public static void InternalFalse(LispEnvironment aEnvironment, LispPtr aResult) throws Exception\n  {\n    aResult.Set(aEnvironment.iFalse.Copy(false));\n  }\n  public static void InternalBoolean(LispEnvironment aEnvironment, LispPtr aResult, boolean aValue) throws Exception\n  {\n    if (aValue)\n    {\n      InternalTrue(aEnvironment, aResult);\n    }\n    else\n    {\n      InternalFalse(aEnvironment, aResult);\n    }\n  }\n\n  public static void InternalNth(LispPtr aResult, LispPtr aArg, int n) throws Exception\n  {\n    LispError.Check(aArg.Get() != null,LispError.KLispErrInvalidArg);\n    LispError.Check(aArg.Get().SubList() != null,LispError.KLispErrInvalidArg);\n    LispError.Check(n>=0,LispError.KLispErrInvalidArg);\n    LispIterator iter = new LispIterator(aArg.Get().SubList());\n\n    while (n>0)\n    {\n      LispError.Check(iter.GetObject() != null,LispError.KLispErrInvalidArg);\n      iter.GoNext();\n      n--;\n    }\n    LispError.Check(iter.GetObject() != null,LispError.KLispErrInvalidArg);\n    aResult.Set(iter.GetObject().Copy(false));\n  }\n\n\n  public static void InternalTail(LispPtr aResult, LispPtr aArg) throws Exception\n  {\n    LispError.Check(aArg.Get() != null,LispError.KLispErrInvalidArg);\n    LispError.Check(aArg.Get().SubList() != null,LispError.KLispErrInvalidArg);\n\n    LispPtr iter = aArg.Get().SubList();\n\n    LispError.Check(iter.Get() != null,LispError.KLispErrInvalidArg);\n    aResult.Set(LispSubList.New(iter.Get().Next().Get()));\n  }\n\n  public static boolean IsTrue(LispEnvironment aEnvironment, LispPtr aExpression) throws Exception\n  {\n    LispError.LISPASSERT(aExpression.Get() != null);\n    return aExpression.Get().String() == aEnvironment.iTrue.String();\n  }\n  public static boolean IsFalse(LispEnvironment aEnvironment, LispPtr aExpression) throws Exception\n  {\n    LispError.LISPASSERT(aExpression.Get() != null);\n    return aExpression.Get().String() == aEnvironment.iFalse.String();\n  }\n\n  public static String SymbolName(LispEnvironment aEnvironment, String aSymbol)\n  {\n    if (aSymbol.charAt(0) == '\\\"')\n    {\n      return aEnvironment.HashTable().LookUpUnStringify(aSymbol);\n    }\n    else\n    {\n      return aEnvironment.HashTable().LookUp(aSymbol);\n    }\n  }\n\n  public static boolean InternalIsList(LispPtr aPtr) throws Exception\n  {\n    if (aPtr.Get() == null)\n        return false;\n    if (aPtr.Get().SubList() == null)\n        return false;\n    if (aPtr.Get().SubList().Get() == null)\n        return false;\n      //TODO this StrEqual is far from perfect. We could pass in a LispEnvironment object...\n          return aPtr.Get().SubList().Get().String().equals(\"List\");\n  }\n\n  public static boolean InternalIsString(String aOriginal)\n  {\n    if (aOriginal != null)\n      if (aOriginal.charAt(0) == '\\\"')\n        if (aOriginal.charAt(aOriginal.length()-1) == '\\\"')\n          return true;\n    return false;\n  }\n\n  public static void InternalNot(LispPtr aResult, LispEnvironment aEnvironment, LispPtr aExpression) throws Exception\n  {\n    if (IsTrue(aEnvironment, aExpression))\n    {\n        InternalFalse(aEnvironment,aResult);\n    }\n    else\n    {\n        LispError.Check(IsFalse(aEnvironment, aExpression),LispError.KLispErrInvalidArg);\n        InternalTrue(aEnvironment,aResult);\n    }\n  }\n\n  public static void InternalFlatCopy(LispPtr aResult, LispPtr aOriginal) throws Exception\n  {\n    LispIterator orig = new LispIterator(aOriginal);\n    LispIterator res = new LispIterator(aResult);\n\n    while (orig.GetObject() != null)\n    {\n      res.Ptr().Set(orig.GetObject().Copy(false));\n      orig.GoNext();\n      res.GoNext();\n    }\n  }\n\n    public static boolean InternalStrictTotalOrder(LispEnvironment env, LispPtr e1, LispPtr e2) throws Exception\n    {\n        if (e1.Get() == e2.Get()) {\n            return false;\n        }\n\n        if (e1.Get() == null && e2.Get() != null) {\n            return true;\n        }\n\n        if (e1.Get() != null && e2.Get() == null) {\n            return false;\n        }\n\n        BigNumber n1 = e1.Get().Number(env.Precision());\n        BigNumber n2 = e2.Get().Number(env.Precision());\n\n        if (n1 != null && n2 == null) {\n            return true;\n        }\n\n        if (n1 == null && n2 != null) {\n            return false;\n        }\n\n        if (n1 != null && n2 != null) {\n            if (n1.LessThan(n2)) {\n                return true;\n            }\n            if (!n1.Equals(n2)) {\n                return InternalStrictTotalOrder(env, e1.Get().Next(), e2.Get().Next());\n            }\n        }\n\n        String s1 = e1.Get().String();\n        String s2 = e2.Get().String();\n\n        if (s1 != null && s2 == null) {\n            return true;\n        }\n\n        if (s1 == null && s2 != null) {\n            return false;\n        }\n\n        if (s1 != null && s2 != null) {\n            int c = s1.compareTo(s2);\n\n            if (c != 0) {\n                return c < 0;\n            }\n\n            return InternalStrictTotalOrder(env, e1.Get().Next(), e2.Get().Next());\n        }\n\n        LispPtr l1 = e1.Get().SubList();\n        LispPtr l2 = e2.Get().SubList();\n\n        if (l1 != null && l2 == null) {\n            return true;\n        }\n\n        if (l1 == null && l2 != null) {\n            return false;\n        }\n\n        if (l1 != null && l2 != null) {\n            LispIterator i1 = new LispIterator(l1);\n            LispIterator i2 = new LispIterator(l2);\n\n            while (i1.GetObject() != null && i2.GetObject() != null) {\n                LispPtr p1 = i1.Ptr();\n                LispPtr p2 = i2.Ptr();\n\n                if (InternalEquals(env, p1, p2)) {\n                    i1.GoNext();\n                    i2.GoNext();\n\n                    continue;\n                }\n\n                return InternalStrictTotalOrder(env, p1, p2);\n            }\n\n            if (i1.GetObject() != null) {\n                return false;\n            }\n\n            if (i2.GetObject() != null) {\n                return true;\n            }\n\n            return false;\n        }\n\n        // FIXME: deal with generics\n        return false;\n    }\n\n  public static boolean InternalEquals(LispEnvironment aEnvironment, LispPtr aExpression1, LispPtr aExpression2) throws Exception\n  {\n    // Handle pointers to same, or null\n    if (aExpression1.Get() == aExpression2.Get())\n    {\n        return true;\n    }\n\n    BigNumber n1 = aExpression1.Get().Number(aEnvironment.Precision());\n    BigNumber n2 = aExpression2.Get().Number(aEnvironment.Precision());\n    if (!(n1 == null && n2 == null) )\n    {\n        if (n1 == n2)\n        {\n            return true;\n        }\n        if (n1 == null) return false;\n        if (n2 == null) return false;\n        return n1.Equals(n2);\n    }\n\n    //Pointers to strings should be the same\n    if (aExpression1.Get().String() != aExpression2.Get().String())\n    {\n        return false;\n    }\n\n    // Handle same sublists, or null\n    if (aExpression1.Get().SubList() == aExpression2.Get().SubList())\n    {\n        return true;\n    }\n\n    // Now check the sublists\n    if (aExpression1.Get().SubList() != null)\n    {\n        if (aExpression2.Get().SubList() == null)\n        {\n            return false;\n        }\n        LispIterator iter1 = new LispIterator(aExpression1.Get().SubList());\n        LispIterator iter2 = new LispIterator(aExpression2.Get().SubList());\n\n        while (iter1.GetObject() != null && iter2.GetObject() != null)\n        {\n            // compare two list elements\n            if (!InternalEquals(aEnvironment, iter1.Ptr(),iter2.Ptr()))\n            {\n                return false;\n            }\n\n            // Step to next\n            iter1.GoNext();\n            iter2.GoNext();\n        }\n        // Lists don't have the same length\n        // Same!\n                return iter1.GetObject() == iter2.GetObject();\n    }\n\n    // expressions sublists are not the same!\n    return false;\n  }\n\n\n\n\n\n  public static void InternalSubstitute(LispPtr aTarget, LispPtr aSource, SubstBehaviourBase aBehaviour) throws Exception\n  {\n    LispObject object = aSource.Get();\n    LispError.LISPASSERT(object != null);\n    if (!aBehaviour.Matches(aTarget,aSource))\n    {\n      LispPtr oldList = object.SubList();\n      if (oldList != null)\n      {\n        LispPtr newList = new LispPtr();\n        LispPtr next = newList;\n        while (oldList.Get() != null)\n        {\n          InternalSubstitute(next, oldList, aBehaviour);\n          oldList = oldList.Get().Next();\n          next = next.Get().Next();\n        }\n        aTarget.Set(LispSubList.New(newList.Get()));\n      }\n      else\n      {\n        aTarget.Set(object.Copy(false));\n      }\n    }\n  }\n\n  public static String InternalUnstringify(String aOriginal) throws Exception\n  {\n    LispError.Check(aOriginal != null,LispError.KLispErrInvalidArg);\n    LispError.Check(aOriginal.charAt(0) == '\\\"',LispError.KLispErrInvalidArg);\n    int nrc=aOriginal.length()-1;\n    LispError.Check(aOriginal.charAt(nrc) == '\\\"',LispError.KLispErrInvalidArg);\n    return aOriginal.substring(1,nrc);\n  }\n\n\n\n\n  public static void DoInternalLoad(LispEnvironment aEnvironment,LispInput aInput) throws Exception\n  {\n    LispInput previous = aEnvironment.iCurrentInput;\n    try\n    {\n      aEnvironment.iCurrentInput = aInput;\n      // TODO make \"EndOfFile\" a global thing\n      // read-parse-eval to the end of file\n      String eof = aEnvironment.HashTable().LookUp(\"EndOfFile\");\n      boolean endoffile = false;\n      InfixParser parser = new InfixParser(new LispTokenizer(),\n                         aEnvironment.iCurrentInput, aEnvironment,\n                         aEnvironment.iPrefixOperators, aEnvironment.iInfixOperators,\n                         aEnvironment.iPostfixOperators, aEnvironment.iBodiedOperators);\n      LispPtr readIn =new LispPtr();\n      while (!endoffile)\n      {\n        // Read expression\n        parser.Parse(readIn);\n\n        LispError.Check(readIn.Get() != null, LispError.KLispErrReadingFile);\n        // Check for end of file\n        if (readIn.Get().String() == eof)\n        {\n          endoffile = true;\n        }\n        // Else evaluate\n        else\n        {\n          LispPtr result = new LispPtr();\n          aEnvironment.iEvaluator.Eval(aEnvironment, result, readIn);\n        }\n      }\n    }\n    catch (Exception e)\n    {\n      throw e;\n    }\n    finally\n    {\n      aEnvironment.iCurrentInput = previous;\n    }\n  }\n\n\n\n  public static void InternalLoad(LispEnvironment aEnvironment,String aFileName) throws Exception\n  {\n    String oper = InternalUnstringify(aFileName);\n\n    String hashedname = aEnvironment.HashTable().LookUp(oper);\n\n    InputStatus oldstatus = new InputStatus(aEnvironment.iInputStatus);\n    aEnvironment.iInputStatus.SetTo(hashedname);\n    try\n    {\n      // Open file\n      LispInput newInput = // new StdFileInput(hashedname, aEnvironment.iInputStatus);\n          OpenInputFile(aEnvironment, aEnvironment.iInputDirectories, hashedname, aEnvironment.iInputStatus);\n\n      LispError.Check(newInput != null, LispError.KLispErrFileNotFound);\n      DoInternalLoad(aEnvironment,newInput);\n    }\n    catch (Exception e)\n    {\n      throw e;\n    }\n    finally\n    {\n      aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n    }\n  }\n\n  public static void InternalUse(LispEnvironment aEnvironment,String aFileName) throws Exception\n  {\n    LispDefFile def = aEnvironment.iDefFiles.File(aFileName);\n    if (!def.IsLoaded())\n    {\n      def.SetLoaded();\n\n      for (String s: def.symbols)\n          aEnvironment.UnProtect(s);\n\n      InternalLoad(aEnvironment,aFileName);\n\n      for (String s: def.symbols)\n          aEnvironment.Protect(s);\n    }\n  }\n\n    public static void DoPatchString(String unpatchedString,\n                                     Writer aOutput,\n                                     LispEnvironment aEnvironment) throws Exception\n    {\n        String[] tags = unpatchedString.split(\"\\\\?\\\\>\");\n        if (tags.length > 1) {\n            for (int x = 0; x < tags.length; x++) {\n                String[] tag = tags[x].split(\"\\\\<\\\\?\");\n                if (tag.length > 1) {\n                    aOutput.write(tag[0]);\n                    String scriptCode = tag[1].trim();\n                    StringBuffer scriptCodeBuffer =\n                        new StringBuffer(scriptCode);\n                    StringInput scriptStream =\n                        new StringInput(scriptCodeBuffer, aEnvironment.iInputStatus);\n                    Writer previous = aEnvironment.iCurrentOutput;\n                    try {\n                        aEnvironment.iCurrentOutput = aOutput;\n                        LispStandard.DoInternalLoad(aEnvironment, scriptStream);\n                    } catch(Exception e) {\n                        throw e;\n                    } finally {\n                        aEnvironment.iCurrentOutput = previous;\n                    }\n                }\n            }\n            aOutput.write(tags[tags.length - 1]);\n        } else {\n            aOutput.write(unpatchedString);\n        }\n    }\n\n    public static void InternalPatchLoad(LispEnvironment aEnvironment, String aFileName) throws Exception\n    {\n        String fname = InternalUnstringify(aFileName);\n\n        InputStatus oldstatus = new InputStatus(aEnvironment.iInputStatus);\n        aEnvironment.iInputStatus.SetTo(fname);\n        try {\n            String path = InternalFindFile(fname, aEnvironment.iInputDirectories);\n            LispError.Check(Files.exists(Paths.get(path)), LispError.KLispErrFileNotFound);\n\n            byte[] encoded = Files.readAllBytes(Paths.get(path));\n            String content = new String(encoded);\n\n            LispStandard.DoPatchString(content, aEnvironment.iCurrentOutput, aEnvironment);\n        }\n        catch (Exception e) {\n            throw e;\n        }\n        finally {\n            aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n        }\n    }\n\n\n  static String PrintExpression(LispPtr aExpression,\n                      LispEnvironment aEnvironment,\n                      int aMaxChars) throws Exception\n  {\n    StringWriter newOutput = new StringWriter();\n    InfixPrinter infixprinter = new InfixPrinter(aEnvironment.iPrefixOperators,\n                              aEnvironment.iInfixOperators,\n                              aEnvironment.iPostfixOperators,\n                              aEnvironment.iBodiedOperators);\n    infixprinter.Print(aExpression, newOutput, aEnvironment);\n    StringBuilder result = new StringBuilder(newOutput.toString());\n    if (aMaxChars > 0 && result.length()>aMaxChars)\n    {\n      result.delete(aMaxChars,result.length());\n      result.append(\"...\");\n    }\n    return result.toString();\n  }\n\n\n  public static LispInput OpenInputFile(String aFileName, InputStatus aInputStatus) throws Exception\n  {\n    try\n    {\n      if (zipFile != null)\n      {\n        java.util.zip.ZipEntry e = zipFile.getEntry(\"scripts/\" + aFileName);\n        if (e != null)\n        {\n          java.io.InputStream s = zipFile.getInputStream(e);\n          return new StdFileInput(s, aInputStatus);\n        }\n      }\n\n      if (aFileName.substring(0,4).equals(\"jar:\"))\n      {\n        return new JarInputFile(aFileName, aInputStatus);\n      }\n      else\n      {\n        return new StdFileInput(aFileName, aInputStatus);\n      }\n    }\n    catch (Exception e)\n    {\n    }\n    return null;\n  }\n\n  public static LispInput OpenInputFile(LispEnvironment aEnvironment,\n      InputDirectories aInputDirectories, String aFileName,\n      InputStatus aInputStatus) throws Exception\n  {\n    String othername = aFileName;\n    int i = 0;\n    LispInput f = OpenInputFile(othername, aInputStatus);\n    while (f == null && i<aInputDirectories.size())\n    {\n      othername = aInputDirectories.get(i) + aFileName;\n      f = OpenInputFile(othername, aInputStatus);\n      i++;\n    }\n    return f;\n  }\n\n\n  public static String InternalFindFile(String aFileName, InputDirectories aInputDirectories) throws Exception\n  {\n    InputStatus inputStatus = new InputStatus();\n    String othername = aFileName;\n    int i = 0;\n    LispInput f = OpenInputFile(othername, inputStatus);\n    if (f != null) return othername;\n    while (i<aInputDirectories.size())\n    {\n      othername = aInputDirectories.get(i) + aFileName;\n      f = OpenInputFile(othername, inputStatus);\n      if (f != null) return othername;\n      i++;\n    }\n    return \"\";\n  }\n\n  public static java.util.zip.ZipFile zipFile = null;\n\n\n  private static void DoLoadDefFile(LispEnvironment aEnvironment, LispInput aInput,\n                            LispDefFile def) throws Exception\n  {\n    LispInput previous = aEnvironment.iCurrentInput;\n    try\n    {\n      aEnvironment.iCurrentInput = aInput;\n      String eof = aEnvironment.HashTable().LookUp(\"EndOfFile\");\n      String end = aEnvironment.HashTable().LookUp(\"}\");\n      boolean endoffile = false;\n\n      LispTokenizer tok = new LispTokenizer();\n\n      while (!endoffile)\n      {\n        // Read expression\n        String token = tok.NextToken(aEnvironment.iCurrentInput, aEnvironment.HashTable());\n\n        // Check for end of file\n        if (token == eof || token == end)\n        {\n            endoffile = true;\n        }\n        // Else evaluate\n        else\n        {\n            String str = token;\n            LispMultiUserFunction multiUser = aEnvironment.MultiUserFunction(str);\n            if (multiUser.iFileToOpen!=null)\n            {\n              throw new YacasException(\"[\"+str+\"]\"+\"] : def file already chosen: \"+multiUser.iFileToOpen.iFileName);\n            }\n            multiUser.iFileToOpen = def;\n\n            def.symbols.add(token);\n            aEnvironment.Protect(token);\n        }\n      }\n    }\n    catch (Exception e)\n    {\n      throw e;\n    }\n    finally\n    {\n      aEnvironment.iCurrentInput = previous;\n    }\n  }\n\n\n  public static void LoadDefFile(LispEnvironment aEnvironment, String aFileName) throws Exception\n  {\n    LispError.LISPASSERT(aFileName!=null);\n\n    String flatfile = InternalUnstringify(aFileName) + \".def\";\n    LispDefFile def = aEnvironment.iDefFiles.File(aFileName);\n\n    String hashedname = aEnvironment.HashTable().LookUp(flatfile);\n\n    InputStatus oldstatus = aEnvironment.iInputStatus;\n    aEnvironment.iInputStatus.SetTo(hashedname);\n\n    {\n      LispInput newInput = // new StdFileInput(hashedname, aEnvironment.iInputStatus);\n          OpenInputFile(aEnvironment, aEnvironment.iInputDirectories, hashedname, aEnvironment.iInputStatus);\n      LispError.Check(newInput != null, LispError.KLispErrFileNotFound);\n      DoLoadDefFile(aEnvironment, newInput,def);\n    }\n    aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n  }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  //////////////////////////////////////////////////\n  ///// bits_to_digits and digits_to_bits implementation\n  //////////////////////////////////////////////////\n\n  // lookup table for transforming the number of digits\n\n  static int log2_table_size = 32;\n  // report the table size\n  int log2_table_range()\n  {\n    return log2_table_size;\n  }\n\n  // A lookup table of Ln(n)/Ln(2) for n = 1 .. 32.\n  // Generated by: PrintList(N(Ln(1 .. 32)/Ln(2)), \",\") at precision 40\n  static double log2_table[] =\n    {\n    0.,\n    1.,\n    1.5849625007211561814537389439478165087598,\n    2.,\n    2.3219280948873623478703194294893901758648,\n    2.5849625007211561814537389439478165087598,\n    2.807354922057604107441969317231830808641,\n    3.,\n    3.1699250014423123629074778878956330175196,\n    3.3219280948873623478703194294893901758648,\n    3.4594316186372972561993630467257929587032,\n    3.5849625007211561814537389439478165087598,\n    3.7004397181410921603968126542566947336284,\n    3.807354922057604107441969317231830808641,\n    3.9068905956085185293240583734372066846246,\n    4.,\n    4.0874628412503394082540660108104043540112,\n    4.1699250014423123629074778878956330175196,\n    4.2479275134435854937935194229068344226935,\n    4.3219280948873623478703194294893901758648,\n    4.3923174227787602888957082611796473174008,\n    4.4594316186372972561993630467257929587032,\n    4.5235619560570128722941482441626688444988,\n    4.5849625007211561814537389439478165087598,\n    4.6438561897747246957406388589787803517296,\n    4.7004397181410921603968126542566947336284,\n    4.7548875021634685443612168318434495262794,\n    4.807354922057604107441969317231830808641,\n    4.8579809951275721207197733246279847624768,\n    4.9068905956085185293240583734372066846246,\n    4.9541963103868752088061235991755544235489,\n    5.\n    };\n\n  // table look-up of small integer logarithms, for converting the number of digits to binary and back\n  static double log2_table_lookup(int n) throws Exception\n  {\n      if (n<=log2_table_size && n>=2)\n        return log2_table[n-1];\n      else\n      {\n        throw new YacasException(\"log2_table_lookup: error: invalid argument \"+n);\n      }\n  }\n  // convert the number of digits in given base to the number of bits, and back.\n  // need to round the number of digits.\n  // to make sure that there is no hysteresis, we round upwards on digits_to_bits but round down on bits_to_digits\n  static long digits_to_bits(long digits, int base) throws Exception\n  {\n    return (long)Math.ceil(digits*log2_table_lookup(base));\n  }\n\n  static long bits_to_digits(long bits, int base) throws Exception\n  {\n    return (long)Math.floor(bits/log2_table_lookup(base));\n  }\n\n\n\n\n}\n\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispSubList.java",
    "content": "package net.sf.yacas;\n\n\nclass LispSubList extends LispObject\n{\n  public static LispSubList New(LispObject aSubList)\n  {\n    return new LispSubList(aSubList);\n  }\n  @Override\n    public LispPtr SubList()\n  {\n    return iSubList;\n  }\n  @Override\n  public String String()\n  {\n    return null;\n  }\n  @Override\n  public LispObject Copy(boolean aRecursed) throws Exception\n  {\n    //TODO recursed copy needs to be implemented still\n    LispError.LISPASSERT(aRecursed == false);\n    LispObject copied = new LispSubList(iSubList.Get());\n    return copied;\n  }\n    LispSubList(LispObject aSubList)\n  {\n    iSubList.Set(aSubList);\n  }\n    LispPtr iSubList = new LispPtr();\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispTokenizer.java",
    "content": "package net.sf.yacas;\n\nclass LispTokenizer {\n\n    /// Return a string representing the next token\n    String NextToken(LispInput aInput, LispHashTable aHashTable) throws Exception {\n\n        char c;\n\n        for (;;) {\n            if (aInput.EndOfStream())\n                return aHashTable.LookUp(\"\");\n\n            c = aInput.Next();\n\n            if (Character.isWhitespace(c))\n                continue;\n\n            // parse comments\n            if (c == '/' && aInput.Peek() == '*') {\n                aInput.Next();\n                for (;;) {\n                    while (aInput.Next() != '*' && !aInput.EndOfStream())\n                        ;\n\n                    LispError.Check(!aInput.EndOfStream(), LispError.KLispErrCommentToEndOfFile);\n\n                    if (aInput.Peek() == '/') {\n                        aInput.Next();\n                        break;\n                    }\n                }\n\n                continue;\n            }\n\n            if (c == '/' && aInput.Peek() == '/') {\n                aInput.Next();\n                while (aInput.Next() != '\\n' && !aInput.EndOfStream())\n                    ;\n                continue;\n            }\n\n            break;\n        }\n\n        // parse brackets\n        if (c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']')\n            return aHashTable.LookUp(Character.toString(c));\n\n        // percent\n        if (c == '%')\n            return aHashTable.LookUp(Character.toString(c));\n\n        // comma and semicolon\n        if (c == ',' || c == ';')\n            return aHashTable.LookUp(Character.toString(c));\n\n        // parse . or ..\n        if (c == '.' && !Character.isDigit(aInput.Peek())) {\n            StringBuilder token = new StringBuilder();\n            token.append(c);\n            while (aInput.Peek() == '.')\n                token.append(aInput.Next());\n            return aHashTable.LookUp(token.toString());\n        }\n\n        if (c == '\\\"') {\n            StringBuilder str = new StringBuilder();\n            str.append(c);\n            while (aInput.Peek() != '\\\"') {\n                if (aInput.Peek() == '\\\\') {\n                    aInput.Next();\n                    LispError.Check(!aInput.EndOfStream(), LispError.KLispErrParsingInput);\n                    switch (aInput.Next()) {\n                        case '\\\"':\n                            str.append(\"\\\"\");\n                            break;\n                        case '\\\\':\n                            str.append(\"\\\\\");\n                            break;\n                        case 't':\n                            str.append('\\t');\n                            break;\n                        case 'n':\n                            str.append('\\n');\n                            break;\n                        default:\n                            LispError.Check(false, LispError.KLispErrParsingInput);\n                    }\n                } else {\n                    str.append(aInput.Next());\n                }\n\n                LispError.Check(!aInput.EndOfStream(), LispError.KLispErrParsingInput);\n            }\n            str.append(aInput.Next());\n            return aHashTable.LookUp(str.toString());\n        }\n\n        // parse atoms\n        if (Character.isAlphabetic(c) || c == '\\'') {\n            StringBuilder atom = new StringBuilder();\n            atom.append(c);\n            while (Character.isAlphabetic(aInput.Peek()) || aInput.Peek() == '\\'' || Character.isDigit(aInput.Peek()))\n                atom.append(aInput.Next());\n            return aHashTable.LookUp(atom.toString());\n        }\n\n        // parse operators\n        if (IsSymbolic(c)) {\n            StringBuilder op = new StringBuilder();\n            op.append(c);\n            while (IsSymbolic(aInput.Peek()))\n                op.append(aInput.Next());\n            return aHashTable.LookUp(op.toString());\n        }\n\n        // parse subscripts\n        if (c == '_') {\n            StringBuilder token = new StringBuilder();\n            token.append(c);\n            while (aInput.Peek() == '_')\n                token.append(aInput.Next());\n            return aHashTable.LookUp(token.toString());\n        }\n\n        // parse numbers\n        if (Character.isDigit(c) || c == '.') {\n            StringBuilder number = new StringBuilder();\n            number.append(c);\n\n            while (Character.isDigit(aInput.Peek()))\n                number.append(aInput.Next());\n\n            if (aInput.Peek() == '.') {\n                number.append(aInput.Next());\n                while (Character.isDigit(aInput.Peek()))\n                    number.append(aInput.Next());\n            }\n\n            if (aInput.Peek() == 'e' || aInput.Peek() == 'E') {\n                number.append(aInput.Next());\n                if (aInput.Peek() == '-' || aInput.Peek() == '+')\n                    number.append(aInput.Next());\n\n                while (Character.isDigit(aInput.Peek()))\n                    number.append(aInput.Next());\n            }\n\n            return aHashTable.LookUp(number.toString());\n        }\n\n        LispError.Check(false, LispError.KInvalidToken);\n\n        return aHashTable.LookUp(\"\");\n    }\n\n    static boolean IsAlpha(char c) {\n        return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '\\''));\n    }\n\n    static boolean IsAlNum(char c) {\n        return (IsAlpha(c) || Character.isDigit(c));\n    }\n\n    static String symbolics = \"~`!@#$^&*-=+:<>?/\\\\|\";\n\n    static boolean IsSymbolic(char c) {\n        return (symbolics.indexOf(c) >= 0);\n    }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LispUserFunction.java",
    "content": "package net.sf.yacas;\n\n\n/// Abstract class providing the basic user function API.\n/// Instances of this class are associated to the name of the function\n/// via an associated hash table. When obtained, they can be used to\n/// evaluate the function with some arguments.\n\nabstract class LispUserFunction extends EvalFuncBase\n{\n    public LispUserFunction()\n    {\n      iFenced = true;\n      iTraced = false;\n    }\n    @Override\n    public abstract void Evaluate(LispPtr aResult,LispEnvironment aEnvironment, LispPtr aArguments) throws Exception;\n    public abstract void HoldArgument(String aVariable);\n    public abstract void DeclareRule(int aPrecedence, LispPtr aPredicate, LispPtr aBody) throws Exception;\n    public abstract void DeclareRule(int aPrecedence, LispPtr aBody) throws Exception;\n    public abstract void DeclarePattern(int aPrecedence, LispPtr aPredicate, LispPtr aBody) throws Exception;\n    public abstract LispPtr ArgList();\n\n    public void UnFence()\n    {\n      iFenced = false;\n    }\n    public boolean Fenced()\n    {\n      return iFenced;\n    }\n\n    public void Trace()\n    {\n      iTraced = true;\n    }\n    public void UnTrace()\n    {\n      iTraced = false;\n    }\n    public boolean Traced()\n    {\n      return iTraced;\n    }\n\n    boolean iFenced;\n    boolean iTraced;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/ListedBranchingUserFunction.java",
    "content": "package net.sf.yacas;\n\n\nclass ListedBranchingUserFunction extends BranchingUserFunction\n{\n  public ListedBranchingUserFunction(LispPtr  aParameters) throws Exception\n  {\n    super(aParameters);\n  }\n  @Override\n  public boolean IsArity(int aArity)\n  {\n    return (Arity() <= aArity);\n  }\n  @Override\n  public void Evaluate(LispPtr aResult, LispEnvironment aEnvironment, LispPtr aArguments) throws Exception\n  {\n    LispPtr newArgs = new LispPtr();\n    LispIterator iter = new LispIterator(aArguments);\n    LispPtr ptr =  newArgs;\n    int arity = Arity();\n    int i=0;\n    while (i < arity && iter.GetObject() != null)\n    {\n        ptr.Set(iter.GetObject().Copy(false));\n        ptr = ptr.Get().Next();\n        i++;\n        iter.GoNext();\n    }\n    if (iter.GetObject().Next().Get() == null)\n    {\n        ptr.Set(iter.GetObject().Copy(false));\n        iter.GoNext();\n        LispError.LISPASSERT(iter.GetObject() == null);\n    }\n    else\n    {\n        LispPtr head = new LispPtr();\n        head.Set(aEnvironment.iList.Copy(false));\n        head.Get().Next().Set(iter.GetObject());\n        ptr.Set(LispSubList.New(head.Get()));\n    }\n    super.Evaluate(aResult, aEnvironment, newArgs);\n  }\n}\n\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/ListedMacroUserFunction.java",
    "content": "package net.sf.yacas;\n\n\nclass ListedMacroUserFunction extends MacroUserFunction\n{\n\n  public ListedMacroUserFunction(LispPtr  aParameters) throws Exception\n  {\n    super(aParameters);\n  }\n  @Override\n  public boolean IsArity(int aArity)\n  {\n    return (Arity() <= aArity);\n  }\n  @Override\n  public void Evaluate(LispPtr aResult, LispEnvironment aEnvironment, LispPtr aArguments) throws Exception\n  {\n    LispPtr newArgs = new LispPtr();\n    LispIterator iter = new LispIterator(aArguments);\n    LispPtr ptr =  newArgs;\n    int arity = Arity();\n    int i=0;\n    while (i < arity && iter.GetObject() != null)\n    {\n        ptr.Set(iter.GetObject().Copy(false));\n        ptr = (ptr.Get().Next());\n        i++;\n        iter.GoNext();\n    }\n    if (iter.GetObject().Next().Get() == null)\n    {\n        ptr.Set(iter.GetObject().Copy(false));\n        iter.GoNext();\n        LispError.LISPASSERT(iter.GetObject() == null);\n    }\n    else\n    {\n        LispPtr head = new LispPtr();\n        head.Set(aEnvironment.iList.Copy(false));\n        head.Get().Next().Set(iter.GetObject());\n        ptr.Set(LispSubList.New(head.Get()));\n    }\n    super.Evaluate(aResult, aEnvironment, newArgs);\n  }\n}\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/LocalSymbolBehaviour.java",
    "content": "package net.sf.yacas;\n\n/** subst behaviour for changing the local variables to have unique\n * names.\n */\nclass LocalSymbolBehaviour implements SubstBehaviourBase\n{\n    public LocalSymbolBehaviour(LispEnvironment aEnvironment,\n                         String[] aOriginalNames,\n                         String[] aNewNames, int aNrNames)\n    {\n      iEnvironment = aEnvironment;\n      iOriginalNames = aOriginalNames;\n      iNewNames = aNewNames;\n      iNrNames = aNrNames;\n    }\n    @Override\n    public boolean Matches(LispPtr aResult, LispPtr aElement) throws Exception\n    {\n      String name = aElement.Get().String();\n      if (name == null)\n          return false;\n\n      int i;\n      for (i=0;i<iNrNames;i++)\n      {\n        if (name == iOriginalNames[i])\n        {\n          aResult.Set(LispAtom.New(iEnvironment,iNewNames[i]));\n          return true;\n        }\n      }\n      return false;\n    }\n\n    LispEnvironment iEnvironment;\n    String[] iOriginalNames;\n    String[] iNewNames;\n    int iNrNames;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/MacroUserFunction.java",
    "content": "package net.sf.yacas;\n\n\nclass MacroUserFunction extends BranchingUserFunction\n{\n  public MacroUserFunction(LispPtr  aParameters) throws Exception\n  {\n    super(aParameters);\n    LispIterator iter = new LispIterator(aParameters);\n    int i=0;\n    while (iter.GetObject() != null)\n    {\n        LispError.Check(iter.GetObject().String() != null,LispError.KLispErrCreatingUserFunction);\n        iParameters.get(i).iHold = true;\n        iter.GoNext();\n        i++;\n    }\n    UnFence();\n  }\n  @Override\n  public void Evaluate(LispPtr  aResult,LispEnvironment  aEnvironment,\n                LispPtr  aArguments) throws Exception\n  {\n    int arity = Arity();\n    int i;\n\n    //hier\n/*TODO fixme\n    if (Traced())\n    {\n        LispPtr tr;\n        tr.Set(LispSubList.New(aArguments.Get()));\n        TraceShowEnter(aEnvironment,tr);\n        tr.Set(null);\n    }\n*/\n    LispIterator iter = new LispIterator(aArguments);\n    iter.GoNext();\n\n    // unrollable arguments\n    LispPtr[] arguments;\n    if (arity==0)\n        arguments = null;\n    else\n    {\n        LispError.LISPASSERT(arity>0);\n        arguments = new LispPtr[arity];\n    }\n\n    // Walk over all arguments, evaluating them as necessary\n    for (i=0;i<arity;i++)\n    {\n        arguments[i] = new LispPtr();\n        LispError.Check(iter.GetObject() != null, LispError.KLispErrWrongNumberOfArgs);\n        if (iParameters.get(i).iHold)\n        {\n          arguments[i].Set(iter.GetObject().Copy(false));\n        }\n        else\n        {\n            LispError.Check(iter.Ptr() != null, LispError.KLispErrWrongNumberOfArgs);\n            aEnvironment.iEvaluator.Eval(aEnvironment, arguments[i], iter.Ptr());\n        }\n        iter.GoNext();\n    }\n/*TODO fixme\n    if (Traced())\n    {\n        LispIterator iter = new LispIterator(aArguments);\n        iter.GoNext();\n        for (i=0;i<arity;i++)\n        {\n            TraceShowArg(aEnvironment,*iter.Ptr(),\n                  arguments[i]);\n\n            iter.GoNext();\n        }\n    }\n*/\n    LispPtr substedBody = new LispPtr();\n    {\n      // declare a new local stack.\n      aEnvironment.PushLocalFrame(false);\n      try\n      {\n        // define the local variables.\n        for (i=0;i<arity;i++)\n        {\n            String variable = iParameters.get(i).iParameter;\n            // set the variable to the new value\n            aEnvironment.NewLocal(variable,arguments[i].Get());\n        }\n\n        // walk the rules database, returning the evaluated result if the\n        // predicate is true.\n        int nrRules = iRules.size();\n        UserStackInformation st = aEnvironment.iEvaluator.StackInformation();\n        for (i=0;i<nrRules;i++)\n        {\n            BranchRuleBase thisRule = iRules.get(i);\n//TODO remove            CHECKPTR(thisRule);\n            LispError.LISPASSERT(thisRule != null);\n\n            st.iRulePrecedence = thisRule.Precedence();\n            boolean matches = thisRule.Matches(aEnvironment, arguments);\n            if (matches)\n            {\n                st.iSide = 1;\n\n                BackQuoteBehaviour behaviour = new BackQuoteBehaviour(aEnvironment);\n                LispStandard.InternalSubstitute(substedBody, thisRule.Body(), behaviour);\n  //              aEnvironment.iEvaluator.Eval(aEnvironment, aResult, thisRule.Body());\n                break;\n            }\n\n            // If rules got inserted, walk back\n            while (thisRule != iRules.get(i) && i>0) i--;\n        }\n      }\n      catch (Exception e)\n      {\n        throw e;\n      }\n      finally\n      {\n        aEnvironment.PopLocalFrame();\n      }\n    }\n\n\n    if (substedBody.Get() != null)\n    {\n        aEnvironment.iEvaluator.Eval(aEnvironment, aResult, substedBody);\n    }\n    else\n    // No predicate was true: return a new expression with the evaluated\n    // arguments.\n      {\n        LispPtr full = new LispPtr();\n        full.Set(aArguments.Get().Copy(false));\n        if (arity == 0)\n        {\n            full.Get().Next().Set(null);\n        }\n        else\n        {\n            full.Get().Next().Set(arguments[0].Get());\n            for (i=0;i<arity-1;i++)\n            {\n                arguments[i].Get().Next().Set(arguments[i+1].Get());\n            }\n        }\n        aResult.Set(LispSubList.New(full.Get()));\n    }\n//FINISH:\n/*TODO fixme\n    if (Traced())\n    {\n        LispPtr tr;\n        tr.Set(LispSubList.New(aArguments.Get()));\n        TraceShowLeave(aEnvironment, aResult,tr);\n        tr.Set(null);\n    }\n*/\n  }\n}\n\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/MatchAtom.java",
    "content": "package net.sf.yacas;\n\n\n/// Class for matching an expression to a given atom.\nclass MatchAtom extends YacasParamMatcherBase\n{\n  public MatchAtom(String aString)\n  {\n    iString = aString;\n  }\n  @Override\n  public boolean ArgumentMatches(LispEnvironment  aEnvironment,\n                                      LispPtr  aExpression,\n                                      LispPtr[]  arguments) throws Exception\n  {\n    // If it is a floating point, don't even bother comparing\n    if (aExpression.Get() != null)\n      if (aExpression.Get().Number(0) != null)\n        if (!aExpression.Get().Number(0).IsInt())\n          return false;\n\n    return (iString == aExpression.Get().String());\n  }\n  protected String iString;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/MatchNumber.java",
    "content": "package net.sf.yacas;\n\n\n/// Class for matching an expression to a given number.\nclass MatchNumber extends YacasParamMatcherBase\n{\n  public MatchNumber(BigNumber aNumber)\n  {\n    iNumber = aNumber;\n  }\n  @Override\n  public boolean ArgumentMatches(LispEnvironment  aEnvironment,\n                                      LispPtr  aExpression,\n                                      LispPtr[]  arguments) throws Exception\n  {\n    if (aExpression.Get().Number(aEnvironment.Precision()) != null)\n      return iNumber.Equals(aExpression.Get().Number(aEnvironment.Precision()));\n    return false;\n  }\n  protected BigNumber iNumber;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/MatchSubList.java",
    "content": "package net.sf.yacas;\n\n\n/// Class for matching against a list of YacasParamMatcherBase objects.\nclass MatchSubList extends YacasParamMatcherBase\n{\n  public MatchSubList(YacasParamMatcherBase[] aMatchers, int aNrMatchers)\n  {\n    iMatchers = aMatchers;\n    iNrMatchers = aNrMatchers;\n  }\n\n  @Override\n  public boolean ArgumentMatches(LispEnvironment  aEnvironment,\n                                      LispPtr  aExpression,\n                                      LispPtr[]  arguments) throws Exception\n  {\n    if (aExpression.Get().SubList() == null)\n        return false;\n    int i;\n\n    LispIterator iter = new LispIterator(aExpression);\n    iter.GoSub();\n\n    for (i=0;i<iNrMatchers;i++)\n    {\n        LispPtr  ptr = iter.Ptr();\n        if (ptr == null)\n            return false;\n        if (iter.GetObject() == null)\n            return false;\n        if (!iMatchers[i].ArgumentMatches(aEnvironment,ptr,arguments))\n            return false;\n        iter.GoNext();\n    }\n    return iter.GetObject() == null;\n  }\n\n  protected YacasParamMatcherBase[] iMatchers;\n  protected int iNrMatchers;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/MatchVariable.java",
    "content": "package net.sf.yacas;\n\n\n/// Class for matching against a pattern variable.\nclass MatchVariable extends YacasParamMatcherBase\n{\n  public MatchVariable(int aVarIndex)\n  {\n    iVarIndex = aVarIndex;\n  }\n\n  /// Matches an expression against the pattern variable.\n  /// \\param aEnvironment the underlying Lisp environment.\n  /// \\param aExpression the expression to test.\n  /// \\param arguments (input/output) actual values of the pattern\n  /// variables for \\a aExpression.\n  ///\n  /// If entry #iVarIndex in \\a arguments is still empty, the\n  /// pattern matches and \\a aExpression is stored in this\n  /// entry. Otherwise, the pattern only matches if the entry equals\n  /// \\a aExpression.\n  @Override\n  public boolean ArgumentMatches(LispEnvironment  aEnvironment,\n                                      LispPtr  aExpression,\n                                      LispPtr[]  arguments) throws Exception\n  {\n// this should not be necessary\n//    if (arguments[iVarIndex] == null)\n//    {\n//      arguments[iVarIndex] = new LispPtr();\n//    }\n    if (arguments[iVarIndex].Get() == null)\n    {\n        arguments[iVarIndex].Set(aExpression.Get());\n//        LogPrintf(\"Set var %d\\n\",iVarIndex);\n        return true;\n    }\n    else\n    {\n//            LogPrintf(\"Matched var %d\\n\",iVarIndex);\n\n        return LispStandard.InternalEquals(aEnvironment, aExpression, arguments[iVarIndex]);\n    }\n//    return false;\n  }\n\n  /// Index of variable in YacasPatternPredicateBase.iVariables.\n  protected int iVarIndex;\n\n  /// Not used.\n  protected String iString;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/MathCommands.java",
    "content": "package net.sf.yacas;\n\nimport java.io.*;\nimport java.util.ArrayList;\n\nclass MathCommands\n{\n  public void AddCommands(LispEnvironment aEnvironment)\n  {\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"While\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"Rule\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"MacroRule\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"RulePattern\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"MacroRulePattern\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"FromFile\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"FromString\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"ToFile\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"ToString\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"ToStdout\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"TraceRule\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"Subst\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"LocalSymbols\");\n    aEnvironment.iBodiedOperators.SetOperator(InfixPrinter.KMaxPrecedence,\"BackQuote\");\n    aEnvironment.iPrefixOperators.SetOperator(0,\"`\");\n    aEnvironment.iPrefixOperators.SetOperator(0,\"@\");\n    aEnvironment.iPrefixOperators.SetOperator(0,\"_\");\n    aEnvironment.iInfixOperators.SetOperator(0,\"_\");\n\n    aEnvironment.CoreCommands().put(\n        \"Hold\",\n        new YacasEvaluator(new LispQuote(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Eval\",\n         new YacasEvaluator(new LispEval(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Write\",\n         new YacasEvaluator(new LispWrite(),1, YacasEvaluator.Variable|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"WriteString\",\n         new YacasEvaluator(new LispWriteString(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"FullForm\",\n         new YacasEvaluator(new LispFullForm(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DefaultDirectory\",\n         new YacasEvaluator(new LispDefaultDirectory(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"FromFile\",\n         new YacasEvaluator(new LispFromFile(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"FromString\",\n         new YacasEvaluator(new LispFromString(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Read\",\n         new YacasEvaluator(new LispRead(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"ReadToken\",\n         new YacasEvaluator(new LispReadToken(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"ToFile\",\n         new YacasEvaluator(new LispToFile(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"ToString\",\n         new YacasEvaluator(new LispToString(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"ToStdout\",\n         new YacasEvaluator(new LispToStdout(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Load\",\n         new YacasEvaluator(new LispLoad(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"TmpFile\",\n         new YacasEvaluator(new LispTmpFile(), 0, YacasEvaluator.Fixed | YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Protect\",\n         new YacasEvaluator(new LispProtect(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"UnProtect\",\n         new YacasEvaluator(new LispUnProtect(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"IsProtected\",\n         new YacasEvaluator(new LispIsProtected(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Set\",\n         new YacasEvaluator(new LispSetVar(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MacroSet\",\n         new YacasEvaluator(new LispMacroSetVar(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Clear\",\n         new YacasEvaluator(new LispClearVar(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MacroClear\",\n         new YacasEvaluator(new LispClearVar(),1, YacasEvaluator.Variable|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Local\",\n         new YacasEvaluator(new LispNewLocal(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MacroLocal\",\n         new YacasEvaluator(new LispNewLocal(),1, YacasEvaluator.Variable|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Head\",\n         new YacasEvaluator(new LispHead(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathNth\",\n         new YacasEvaluator(new LispNth(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Tail\",\n         new YacasEvaluator(new LispTail(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DestructiveReverse\",\n         new YacasEvaluator(new LispDestructiveReverse(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Length\",\n         new YacasEvaluator(new LispLength(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"List\",\n         new YacasEvaluator(new LispList(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"UnList\",\n         new YacasEvaluator(new LispUnList(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Listify\",\n         new YacasEvaluator(new LispListify(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Concat\",\n         new YacasEvaluator(new LispConcatenate(),1, YacasEvaluator.Variable|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"ConcatStrings\",\n         new YacasEvaluator(new LispConcatenateStrings(),1, YacasEvaluator.Variable|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Delete\",\n         new YacasEvaluator(new LispDelete(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DestructiveDelete\",\n         new YacasEvaluator(new LispDestructiveDelete(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Insert\",\n         new YacasEvaluator(new LispInsert(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DestructiveInsert\",\n         new YacasEvaluator(new LispDestructiveInsert(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Replace\",\n         new YacasEvaluator(new LispReplace(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DestructiveReplace\",\n         new YacasEvaluator(new LispDestructiveReplace(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Atom\",\n         new YacasEvaluator(new LispAtomize(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"String\",\n         new YacasEvaluator(new LispStringify(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"CharString\",\n         new YacasEvaluator(new LispCharString(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"FlatCopy\",\n         new YacasEvaluator(new LispFlatCopy(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Prog\",\n         new YacasEvaluator(new LispProgBody(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"While\",\n         new YacasEvaluator(new LispWhile(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"If\",\n         new YacasEvaluator(new LispIf(),2, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Check\",\n         new YacasEvaluator(new LispCheck(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"TrapError\",\n         new YacasEvaluator(new LispTrapError(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"GetCoreError\",\n         new YacasEvaluator(new LispGetCoreError(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Prefix\",\n         new YacasEvaluator(new LispPreFix(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Infix\",\n         new YacasEvaluator(new LispInFix(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Postfix\",\n         new YacasEvaluator(new LispPostFix(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Bodied\",\n         new YacasEvaluator(new LispBodied(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"RuleBase\",\n         new YacasEvaluator(new LispRuleBase(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MacroRuleBase\",\n         new YacasEvaluator(new LispMacroRuleBase(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"RuleBaseListed\",\n         new YacasEvaluator(new LispRuleBaseListed(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MacroRuleBaseListed\",\n         new YacasEvaluator(new LispMacroRuleBaseListed(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DefMacroRuleBase\",\n         new YacasEvaluator(new LispDefMacroRuleBase(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"DefMacroRuleBaseListed\",\n         new YacasEvaluator(new LispDefMacroRuleBaseListed(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"HoldArg\",\n         new YacasEvaluator(new LispHoldArg(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Rule\",\n         new YacasEvaluator(new LispNewRule(),5, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MacroRule\",\n         new YacasEvaluator(new LispMacroNewRule(),5, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"UnFence\",\n         new YacasEvaluator(new LispUnFence(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Retract\",\n         new YacasEvaluator(new LispRetract(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathNot\",\n         new YacasEvaluator(new LispNot(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Not\",\n         new YacasEvaluator(new LispNot(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathAnd\",\n         new YacasEvaluator(new LispLazyAnd(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"And\",\n         new YacasEvaluator(new LispLazyAnd(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MathOr\",\n         new YacasEvaluator(new LispLazyOr(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Or\",\n         new YacasEvaluator(new LispLazyOr(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"Equals\",\n         new YacasEvaluator(new LispEquals(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"=\",\n         new YacasEvaluator(new LispEquals(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"StrictTotalOrder\",\n         new YacasEvaluator(new LispStrictTotalOrder(), 2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"LessThan\",\n         new YacasEvaluator(new LispLessThan(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"GreaterThan\",\n         new YacasEvaluator(new LispGreaterThan(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsFunction\",\n         new YacasEvaluator(new LispIsFunction(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsAtom\",\n         new YacasEvaluator(new LispIsAtom(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsNumber\",\n         new YacasEvaluator(new LispIsNumber(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsInteger\",\n         new YacasEvaluator(new LispIsInteger(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsList\",\n         new YacasEvaluator(new LispIsList(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsString\",\n         new YacasEvaluator(new LispIsString(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsBound\",\n         new YacasEvaluator(new LispIsBound(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MathMultiply\",\n         new YacasEvaluator(new LispMultiply(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathAdd\",\n         new YacasEvaluator(new LispAdd(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathSubtract\",\n         new YacasEvaluator(new LispSubtract(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathDivide\",\n         new YacasEvaluator(new LispDivide(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Builtin'Precision'Set\",\n         new YacasEvaluator(new YacasBuiltinPrecisionSet(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathGetExactBits\",\n         new YacasEvaluator(new LispGetExactBits(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathSetExactBits\",\n         new YacasEvaluator(new LispSetExactBits(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathBitCount\",\n         new YacasEvaluator(new LispBitCount(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathSign\",\n         new YacasEvaluator(new LispMathSign(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathIsSmall\",\n         new YacasEvaluator(new LispMathIsSmall(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathNegate\",\n         new YacasEvaluator(new LispMathNegate(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathFloor\",\n         new YacasEvaluator(new LispFloor(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathCeil\",\n         new YacasEvaluator(new LispCeil(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathAbs\",\n         new YacasEvaluator(new LispAbs(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathMod\",\n         new YacasEvaluator(new LispMod(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathDiv\",\n         new YacasEvaluator(new LispDiv(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"BitsToDigits\",\n         new YacasEvaluator(new LispBitsToDigits(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DigitsToBits\",\n         new YacasEvaluator(new LispDigitsToBits(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathGcd\",\n         new YacasEvaluator(new LispGcd(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"SystemCall\",\n         new YacasEvaluator(new LispSystemCall(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"SystemName\",\n         new YacasEvaluator(new LispSystemName(), 0, YacasEvaluator.Fixed | YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"FastArcSin\",\n         new YacasEvaluator(new LispFastArcSin(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"FastLog\",\n         new YacasEvaluator(new LispFastLog(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"FastPower\",\n         new YacasEvaluator(new LispFastPower(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"ShiftLeft\",\n         new YacasEvaluator(new LispShiftLeft(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"ShiftRight\",\n         new YacasEvaluator(new LispShiftRight(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"FromBase\",\n         new YacasEvaluator(new LispFromBase(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"ToBase\",\n         new YacasEvaluator(new LispToBase(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MaxEvalDepth\",\n         new YacasEvaluator(new LispMaxEvalDepth(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DefLoad\",\n         new YacasEvaluator(new LispDefLoad(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Use\",\n         new YacasEvaluator(new LispUse(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"RightAssociative\",\n         new YacasEvaluator(new LispRightAssociative(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"LeftPrecedence\",\n         new YacasEvaluator(new LispLeftPrecedence(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"RightPrecedence\",\n         new YacasEvaluator(new LispRightPrecedence(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsBodied\",\n         new YacasEvaluator(new LispIsBodied(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsInfix\",\n         new YacasEvaluator(new LispIsInFix(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsPrefix\",\n         new YacasEvaluator(new LispIsPreFix(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsPostfix\",\n         new YacasEvaluator(new LispIsPostFix(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"OpPrecedence\",\n         new YacasEvaluator(new LispGetPrecedence(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"OpLeftPrecedence\",\n         new YacasEvaluator(new LispGetLeftPrecedence(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"OpRightPrecedence\",\n         new YacasEvaluator(new LispGetRightPrecedence(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Builtin'Precision'Get\",\n         new YacasEvaluator(new YacasBuiltinPrecisionGet(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"BitAnd\",\n         new YacasEvaluator(new LispBitAnd(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"BitOr\",\n         new YacasEvaluator(new LispBitOr(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"BitXor\",\n         new YacasEvaluator(new LispBitXor(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Secure\",\n         new YacasEvaluator(new LispSecure(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"FindFile\",\n         new YacasEvaluator(new LispFindFile(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"FindFunction\",\n         new YacasEvaluator(new LispFindFunction(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsGeneric\",\n         new YacasEvaluator(new LispIsGeneric(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"GenericTypeName\",\n         new YacasEvaluator(new LispGenericTypeName(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Array'Create\",\n         new YacasEvaluator(new GenArrayCreate(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Array'Size\",\n         new YacasEvaluator(new GenArraySize(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Array'Get\",\n         new YacasEvaluator(new GenArrayGet(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Array'Set\",\n         new YacasEvaluator(new GenArraySet(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'Create\",\n         new YacasEvaluator(new GenAssociationCreate(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'Size\",\n         new YacasEvaluator(new GenAssociationSize(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'Contains\",\n         new YacasEvaluator(new GenAssociationContains(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'Get\",\n         new YacasEvaluator(new GenAssociationGet(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'Set\",\n         new YacasEvaluator(new GenAssociationSet(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'Drop\",\n         new YacasEvaluator(new GenAssociationDrop(), 2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'Keys\",\n         new YacasEvaluator(new GenAssociationKeys(), 1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'ToList\",\n         new YacasEvaluator(new GenAssociationToList(), 1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Association'Head\",\n         new YacasEvaluator(new GenAssociationHead(), 1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"CustomEval\",\n         new YacasEvaluator(new LispCustomEval(),4, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"CustomEval'Expression\",\n         new YacasEvaluator(new LispCustomEvalExpression(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"CustomEval'Result\",\n         new YacasEvaluator(new LispCustomEvalResult(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"CustomEval'Locals\",\n         new YacasEvaluator(new LispCustomEvalLocals(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"CustomEval'Stop\",\n         new YacasEvaluator(new LispCustomEvalStop(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"TraceRule\",\n         new YacasEvaluator(new LispTraceRule(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"TraceStack\",\n         new YacasEvaluator(new LispTraceStack(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"LispRead\",\n         new YacasEvaluator(new LispReadLisp(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"LispReadListed\",\n         new YacasEvaluator(new LispReadLispListed(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Type\",\n         new YacasEvaluator(new LispType(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"StringMid'Get\",\n         new YacasEvaluator(new YacasStringMidGet(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"StringMid'Set\",\n         new YacasEvaluator(new YacasStringMidSet(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Pattern'Create\",\n         new YacasEvaluator(new GenPatternCreate(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Pattern'Matches\",\n         new YacasEvaluator(new GenPatternMatches(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"RuleBaseDefined\",\n         new YacasEvaluator(new LispRuleBaseDefined(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DefLoadFunction\",\n         new YacasEvaluator(new LispDefLoadFunction(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"RuleBaseArgList\",\n         new YacasEvaluator(new LispRuleBaseArgList(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"RulePattern\",\n         new YacasEvaluator(new LispNewRulePattern(),5, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MacroRulePattern\",\n         new YacasEvaluator(new LispMacroNewRulePattern(),5, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Subst\",\n         new YacasEvaluator(new LispSubst(),3, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"LocalSymbols\",\n         new YacasEvaluator(new LispLocalSymbols(),1, YacasEvaluator.Variable|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"FastIsPrime\",\n         new YacasEvaluator(new LispFastIsPrime(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"MathFac\",\n         new YacasEvaluator(new LispFac(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"ApplyPure\",\n         new YacasEvaluator(new LispApplyPure(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"PrettyReader'Set\",\n         new YacasEvaluator(new YacasPrettyReaderSet(),1, YacasEvaluator.Variable|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"PrettyPrinter'Set\",\n         new YacasEvaluator(new YacasPrettyPrinterSet(),1, YacasEvaluator.Variable|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"PrettyPrinter'Get\",\n         new YacasEvaluator(new YacasPrettyPrinterGet(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"PrettyReader'Get\",\n         new YacasEvaluator(new YacasPrettyReaderGet(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"GarbageCollect\",\n         new YacasEvaluator(new LispGarbageCollect(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"SetGlobalLazyVariable\",\n         new YacasEvaluator(new LispSetGlobalLazyVariable(),2, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"PatchLoad\",\n         new YacasEvaluator(new LispPatchLoad(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"PatchString\",\n         new YacasEvaluator(new LispPatchString(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DefaultTokenizer\",\n         new YacasEvaluator(new LispDefaultTokenizer(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"CommonLispTokenizer\",\n         new YacasEvaluator(new LispCommonLispTokenizer(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"XmlTokenizer\",\n         new YacasEvaluator(new LispXmlTokenizer(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"XmlExplodeTag\",\n         new YacasEvaluator(new LispExplodeTag(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Builtin'Assoc\",\n         new YacasEvaluator(new YacasBuiltinAssoc(),2, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"CurrentFile\",\n         new YacasEvaluator(new LispCurrentFile(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"CurrentLine\",\n         new YacasEvaluator(new LispCurrentLine(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"`\",\n         new YacasEvaluator(new LispBackQuote(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"MathDebugInfo\",\n         new YacasEvaluator(new LispDumpBigNumberDebugInfo(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"InDebugMode\",\n         new YacasEvaluator(new LispInDebugMode(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DebugFile\",\n         new YacasEvaluator(new LispDebugFile(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"DebugLine\",\n         new YacasEvaluator(new LispDebugLine(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Interpreter\",\n         new YacasEvaluator(new interpreter(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Version\",\n         new YacasEvaluator(new LispVersion(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"Exit\",\n         new YacasEvaluator(new LispExit(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsExitRequested\",\n         new YacasEvaluator(new LispExitRequested(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"HistorySize\",\n         new YacasEvaluator(new LispHistorySize(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"StaSiz\",\n         new YacasEvaluator(new LispStackSize(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"IsPromptShown\",\n         new YacasEvaluator(new LispIsPromptShown(),0, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"ReadCmdLineString\",\n         new YacasEvaluator(new LispReadCmdLineString(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n    aEnvironment.CoreCommands().put(\n         \"GetTime\",\n         new YacasEvaluator(new LispTime(),1, YacasEvaluator.Fixed|YacasEvaluator.Macro));\n    aEnvironment.CoreCommands().put(\n         \"FileSize\",\n         new YacasEvaluator(new LispFileSize(),1, YacasEvaluator.Fixed|YacasEvaluator.Function));\n  }\n\n\n  /// Construct a BigNumber from one of the arguments.\n  /// \\param x (on output) the constructed bignumber\n  /// \\param aEnvironment the current environment\n  /// \\param aStackTop the index of the top of the stack\n  /// \\param aArgNr the index of the argument to be converted\n  public static BigNumber GetNumber(LispEnvironment aEnvironment, int aStackTop, int aArgNr) throws Exception\n  {\n    BigNumber x = YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, aArgNr).Get().Number(aEnvironment.Precision());\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,x != null,aArgNr);\n    return x;\n  }\n\n  static void MultiFix(LispEnvironment aEnvironment, int aStackTop, LispOperators aOps) throws Exception\n  {\n    // Get operator\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n    String orig = YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n    LispPtr precedence = new LispPtr();\n    aEnvironment.iEvaluator.Eval(aEnvironment, precedence, YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2));\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,precedence.Get().String() != null, 2);\n    int prec = Integer.parseInt(precedence.Get().String(),10);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,prec <= InfixPrinter.KMaxPrecedence, 2);\n    aOps.SetOperator(prec,LispStandard.SymbolName(aEnvironment,orig));\n    LispStandard.InternalTrue(aEnvironment,YacasEvalCaller.RESULT(aEnvironment, aStackTop));\n  }\n  public static void SingleFix(int aPrecedence, LispEnvironment aEnvironment, int aStackTop, LispOperators aOps) throws Exception\n  {\n    // Get operator\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n    String orig = YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n    aOps.SetOperator(aPrecedence,LispStandard.SymbolName(aEnvironment,orig));\n    LispStandard.InternalTrue(aEnvironment,YacasEvalCaller.RESULT(aEnvironment, aStackTop));\n  }\n\n  public static LispInFixOperator OperatorInfo(LispEnvironment aEnvironment,int aStackTop, LispOperators aOperators) throws Exception\n  {\n    // Get operator\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n\n    LispPtr evaluated = new LispPtr();\n    evaluated.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n    String orig = evaluated.Get().String();\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n    //\n    return aOperators.get(LispStandard.SymbolName(aEnvironment,orig));\n  }\n\n  /// Execute the Yacas commands \\c Set and \\c MacroSet.\n  /// The argument \\a aMacroMode determines whether the first argument\n  /// should be evaluated. The real work is done by\n  /// LispEnvironment::SetVariable() .\n  /// \\sa LispSetVar(), LispMacroSetVar()\n  static void InternalSetVar(LispEnvironment aEnvironment, int aStackTop, boolean aMacroMode, boolean aGlobalLazyVariable) throws Exception\n  {\n    String varstring;\n    if (aMacroMode)\n    {\n      LispPtr result = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, result, YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1));\n      varstring = result.Get().String();\n    }\n    else\n    {\n      varstring = YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n    }\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,varstring != null,1);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,!LispStandard.IsNumber(varstring,true),1);\n\n    LispPtr result = new LispPtr();\n    aEnvironment.iEvaluator.Eval(aEnvironment, result, YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2));\n    aEnvironment.SetVariable(varstring, result, aGlobalLazyVariable);\n    LispStandard.InternalTrue(aEnvironment,YacasEvalCaller.RESULT(aEnvironment, aStackTop));\n  }\n\n  public static void InternalDelete(LispEnvironment aEnvironment, int aStackTop, boolean aDestructive) throws Exception\n  {\n    LispPtr evaluated = new LispPtr();\n    evaluated.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get());\n    LispError.CHK_ISLIST_CORE(aEnvironment,aStackTop,evaluated,1);\n\n    LispPtr copied = new LispPtr();\n    if (aDestructive)\n    {\n      copied.Set(evaluated.Get().SubList().Get());\n    }\n    else\n    {\n      LispStandard.InternalFlatCopy(copied,evaluated.Get().SubList());\n    }\n\n    LispPtr index = new LispPtr();\n    index.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2).Get());\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 2);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 2);\n    int ind = Integer.parseInt(index.Get().String(),10);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ind>0,2);\n\n    LispIterator iter = new LispIterator(copied);\n    while (ind>0)\n    {\n      iter.GoNext();\n      ind--;\n    }\n    LispError.CHK_CORE(aEnvironment, aStackTop,iter.GetObject() != null, LispError.KLispErrListNotLongEnough);\n    LispPtr next = new LispPtr();\n    next.Set(iter.GetObject().Next().Get());\n    iter.Ptr().Set(next.Get());\n    YacasEvalCaller.RESULT(aEnvironment, aStackTop).Set(LispSubList.New(copied.Get()));\n  }\n\n\n  public static void InternalInsert(LispEnvironment aEnvironment, int aStackTop, boolean aDestructive) throws Exception\n  {\n    LispPtr evaluated = new LispPtr();\n    evaluated.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get());\n    LispError.CHK_ISLIST_CORE(aEnvironment,aStackTop,evaluated,1);\n\n    LispPtr copied = new LispPtr();\n    if (aDestructive)\n    {\n        copied.Set(evaluated.Get().SubList().Get());\n    }\n    else\n    {\n        LispStandard.InternalFlatCopy(copied,evaluated.Get().SubList());\n    }\n\n    LispPtr index = new LispPtr();\n    index.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2).Get());\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 2);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 2);\n    int ind = Integer.parseInt(index.Get().String(),10);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ind>0,2);\n\n    LispIterator iter = new LispIterator(copied);\n    while (ind>0)\n    {\n      iter.GoNext();\n      ind--;\n    }\n\n    LispPtr toInsert = new LispPtr();\n    toInsert.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 3).Get());\n    toInsert.Get().Next().Set(iter.GetObject());\n    iter.Ptr().Set(toInsert.Get());\n    YacasEvalCaller.RESULT(aEnvironment, aStackTop).Set(LispSubList.New(copied.Get()));\n  }\n\n\n\n\n\n\n  public static void InternalReplace(LispEnvironment aEnvironment, int aStackTop, boolean aDestructive) throws Exception\n  {\n    LispPtr evaluated = new LispPtr();\n    evaluated.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get());\n    // Ok, so lets not check if it is a list, but it needs to be at least a 'function'\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get().SubList() != null, 1);\n\n    LispPtr index = new LispPtr();\n    index.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2).Get());\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 2);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 2);\n    int ind = Integer.parseInt(index.Get().String(),10);\n\n    LispPtr copied = new LispPtr();\n    if (aDestructive)\n    {\n      copied.Set(evaluated.Get().SubList().Get());\n    }\n    else\n    {\n      LispStandard.InternalFlatCopy(copied,evaluated.Get().SubList());\n    }\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ind>0,2);\n\n    LispIterator iter = new LispIterator(copied);\n    while (ind>0)\n    {\n      iter.GoNext();\n      ind--;\n    }\n\n    LispPtr toInsert = new LispPtr();\n    toInsert.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 3).Get());\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,iter.Ptr() != null, 2);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,iter.Ptr().Get() != null, 2);\n    toInsert.Get().Next().Set(iter.Ptr().Get().Next().Get());\n    iter.Ptr().Set(toInsert.Get());\n    YacasEvalCaller.RESULT(aEnvironment, aStackTop).Set(LispSubList.New(copied.Get()));\n  }\n\n\n  /// Implements the Yacas functions \\c RuleBase and \\c MacroRuleBase .\n  /// The real work is done by LispEnvironment::DeclareRuleBase().\n  public static void InternalRuleBase(LispEnvironment aEnvironment, int aStackTop,  boolean aListed) throws Exception\n  {\n    //TESTARGS(3);\n\n    // Get operator\n    LispPtr args = new LispPtr();\n\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n    String orig = YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n    args.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n    // The arguments\n    LispError.CHK_ISLIST_CORE(aEnvironment,aStackTop,args,2);\n\n    // Finally define the rule base\n    aEnvironment.DeclareRuleBase(LispStandard.SymbolName(aEnvironment,orig),\n                                 args.Get().SubList().Get().Next(),aListed);\n\n    // Return true\n    LispStandard.InternalTrue(aEnvironment,YacasEvalCaller.RESULT(aEnvironment, aStackTop));\n  }\n\n  public static void InternalNewRule(LispEnvironment aEnvironment, int aStackTop) throws Exception\n  {\n    //TESTARGS(6);\n\n    int arity;\n    int precedence;\n\n    LispPtr ar = new LispPtr();\n    LispPtr pr = new LispPtr();\n    LispPtr predicate = new LispPtr();\n    LispPtr body = new LispPtr();\n\n    // Get operator\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n    String orig = YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n    ar.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2).Get());\n    pr.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 3).Get());\n    predicate.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 4).Get());\n    body.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 5).Get());\n\n    // The arity\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ar.Get() != null, 2);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ar.Get().String() != null, 2);\n    arity = Integer.parseInt(ar.Get().String(),10);\n\n    // The precedence\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,pr.Get() != null, 3);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,pr.Get().String() != null, 3);\n    precedence = Integer.parseInt(pr.Get().String(),10);\n\n    // Finally define the rule base\n    aEnvironment.DefineRule(LispStandard.SymbolName(aEnvironment,orig),\n                            arity,\n                            precedence,\n                            predicate,\n                            body );\n\n    // Return true\n    LispStandard.InternalTrue(aEnvironment,YacasEvalCaller.RESULT(aEnvironment, aStackTop));\n  }\n\n\n\n\n  void InternalDefMacroRuleBase(LispEnvironment aEnvironment, int aStackTop, boolean aListed) throws Exception\n  {\n    // Get operator\n    LispPtr args = new LispPtr();\n    LispPtr body = new LispPtr();\n\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n    String orig = YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n    // The arguments\n    args.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2).Get());\n    LispError.CHK_ISLIST_CORE(aEnvironment,aStackTop,args,2);\n\n    // Finally define the rule base\n    aEnvironment.DeclareMacroRuleBase(LispStandard.SymbolName(aEnvironment,orig),\n                                 args.Get().SubList().Get().Next(),aListed);\n\n    // Return true\n    LispStandard.InternalTrue(aEnvironment,YacasEvalCaller.RESULT(aEnvironment, aStackTop));\n  }\n\n\n\n\n  public void InternalNewRulePattern(LispEnvironment aEnvironment, int aStackTop, boolean aMacroMode) throws Exception\n  {\n    int arity;\n    int precedence;\n\n    LispPtr ar = new LispPtr();\n    LispPtr pr = new LispPtr();\n    LispPtr predicate = new LispPtr();\n    LispPtr body = new LispPtr();\n\n    // Get operator\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n    String orig = YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n    ar.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2).Get());\n    pr.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 3).Get());\n    predicate.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 4).Get());\n    body.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 5).Get());\n\n    // The arity\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ar.Get() != null, 2);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ar.Get().String() != null, 2);\n    arity = Integer.parseInt(ar.Get().String(),10);\n\n    // The precedence\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,pr.Get() != null, 3);\n    LispError.CHK_ARG_CORE(aEnvironment,aStackTop,pr.Get().String() != null, 3);\n    precedence = Integer.parseInt(pr.Get().String(),10);\n\n    // Finally define the rule base\n    aEnvironment.DefineRulePattern(LispStandard.SymbolName(aEnvironment,orig),\n                            arity,\n                            precedence,\n                            predicate,\n                            body );\n\n    // Return true\n    LispStandard.InternalTrue(aEnvironment,YacasEvalCaller.RESULT(aEnvironment, aStackTop));\n  }\n\n\n\n  class LispQuote extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      RESULT(aEnvironment, aStackTop).Set(ARGUMENT(aEnvironment, aStackTop, 1).Get().Copy(false));\n    }\n  }\n\n  class LispEval extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 1));\n    }\n  }\n\n  class LispWrite extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr subList = ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList();\n      if (subList != null)\n      {\n        LispIterator iter = new LispIterator(subList);\n        iter.GoNext();\n        while (iter.GetObject() != null)\n        {\n          aEnvironment.iCurrentPrinter.Print(iter.Ptr(),aEnvironment.iCurrentOutput,aEnvironment);\n          iter.GoNext();\n        }\n      }\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispWriteString extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get()!= null,1);\n      String str = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str != null,1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str.charAt(0) == '\\\"',1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str.charAt(str.length()-1) == '\\\"',1);\n\n      str = LispStandard.InternalUnstringify(str);\n\n      aEnvironment.iCurrentOutput.write(str);\n\n      // pass last printed character to the current printer\n      aEnvironment.iCurrentPrinter.RememberLastChar(str.charAt(str.length()-1));  // hacky hacky\n\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispFullForm extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      RESULT(aEnvironment, aStackTop).Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispPrinter printer = new LispPrinter();\n      printer.Print(RESULT(aEnvironment, aStackTop), aEnvironment.iCurrentOutput, aEnvironment);\n      aEnvironment.iCurrentOutput.write(\"\\n\");\n    }\n  }\n\n  class LispDefaultDirectory extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n      String orig = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n      aEnvironment.iInputDirectories.add(oper);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispFromFile extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_CORE(aEnvironment, aStackTop,aEnvironment.iSecure == false, LispError.KLispErrSecurityBreach);\n      LispPtr evaluated = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, evaluated, ARGUMENT(aEnvironment, aStackTop, 1));\n\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      String hashedname = aEnvironment.HashTable().LookUpUnStringify(orig);\n\n      InputStatus oldstatus = aEnvironment.iInputStatus;\n      LispInput previous = aEnvironment.iCurrentInput;\n      try\n      {\n        aEnvironment.iInputStatus.SetTo(hashedname);\n        LispInput input = // new StdFileInput(hashedname, aEnvironment.iInputStatus);\n          LispStandard.OpenInputFile(aEnvironment, aEnvironment.iInputDirectories, hashedname, aEnvironment.iInputStatus);\n        aEnvironment.iCurrentInput = input;\n        // Open file\n        LispError.CHK_CORE(aEnvironment, aStackTop,input != null, LispError.KLispErrFileNotFound);\n\n        // Evaluate the body\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 2));\n      }\n      catch (Exception e)\n      {\n        throw e;\n      }\n      finally\n      {\n        aEnvironment.iCurrentInput = previous;\n        aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n      }\n      //Return the result\n    }\n  }\n\n  class LispFromString extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, evaluated, ARGUMENT(aEnvironment, aStackTop, 1));\n\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n\n      InputStatus oldstatus = aEnvironment.iInputStatus;\n      aEnvironment.iInputStatus.SetTo(\"String\");\n      StringInput newInput = new StringInput(new StringBuffer(oper),aEnvironment.iInputStatus);\n\n      LispInput previous = aEnvironment.iCurrentInput;\n      aEnvironment.iCurrentInput = newInput;\n      try\n      {\n        // Evaluate the body\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 2));\n      }\n      catch (Exception e)\n      {\n        throw e;\n      }\n      finally\n      {\n        aEnvironment.iCurrentInput = previous;\n        aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n      }\n\n      //Return the result\n    }\n  }\n\n  class LispRead extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InfixParser parser = new InfixParser(aEnvironment.iCurrentTokenizer,\n                         aEnvironment.iCurrentInput,\n                         aEnvironment,\n                         aEnvironment.iPrefixOperators,\n                         aEnvironment.iInfixOperators,\n                         aEnvironment.iPostfixOperators,\n                         aEnvironment.iBodiedOperators);\n      // Read expression\n      parser.Parse(RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispReadToken extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispTokenizer tok = aEnvironment.iCurrentTokenizer;\n      String result;\n      result = tok.NextToken(aEnvironment.iCurrentInput, aEnvironment.HashTable());\n\n      if (result.length() == 0)\n      {\n          RESULT(aEnvironment, aStackTop).Set(aEnvironment.iEndOfFile.Copy(false));\n          return;\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,result));\n    }\n  }\n\n  class LispToFile extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_CORE(aEnvironment, aStackTop,aEnvironment.iSecure == false, LispError.KLispErrSecurityBreach);\n\n      LispPtr evaluated = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, evaluated, ARGUMENT(aEnvironment, aStackTop, 1));\n\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n\n      Writer newOutput = new OutputStreamWriter(new FileOutputStream(new File(oper)), \"UTF-8\");\n\n      Writer previous = aEnvironment.iCurrentOutput;\n      aEnvironment.iCurrentOutput = newOutput;\n\n      try\n      {\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 2));\n      }\n      catch (Exception e) { throw e; }\n      finally\n      {\n          newOutput.close();\n          aEnvironment.iCurrentOutput = previous;\n      }\n    }\n  }\n\n  class LispToString extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      StringWriter newOutput = new StringWriter();\n      Writer previous = aEnvironment.iCurrentOutput;\n      aEnvironment.iCurrentOutput = newOutput;\n      try\n      {\n        // Evaluate the body\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 1));\n\n        newOutput.close();\n\n        //Return the result\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.HashTable().LookUpStringify(newOutput.toString())));\n      }\n      catch (Exception e) { throw e; }\n      finally\n      {\n        aEnvironment.iCurrentOutput = previous;\n      }\n    }\n  }\n\n  class LispToStdout extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      Writer previous = aEnvironment.iCurrentOutput;\n      aEnvironment.iCurrentOutput = aEnvironment.iInitialOutput;\n      try\n      {\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 1));\n      }\n      catch (Exception e) { throw e; }\n      finally\n      {\n        aEnvironment.iCurrentOutput = previous;\n      }\n    }\n  }\n\n  class LispLoad extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_CORE(aEnvironment, aStackTop,aEnvironment.iSecure == false, LispError.KLispErrSecurityBreach);\n\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      LispStandard.InternalLoad(aEnvironment,orig);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispTmpFile extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment, int aStackTop) throws Exception\n    {\n      LispError.CHK_CORE(aEnvironment, aStackTop, aEnvironment.iSecure == false, LispError.KLispErrSecurityBreach);\n\n      File f = File.createTempFile(\"yacas\", null);\n      f.deleteOnExit();\n\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment, aEnvironment.HashTable().LookUpStringify(f.getCanonicalPath())));\n    }\n  }\n\n  class LispProtect extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment env, int top) throws Exception\n    {\n      String s = YacasEvalCaller.ARGUMENT(env, top, 1).Get().String();\n\n      LispError.CHK_ARG_CORE(env, top, s != null, 1);\n      LispError.CHK_ARG_CORE(env, top, !LispStandard.IsNumber(s,true), 1);\n\n      env.Protect(s);\n\n      LispStandard.InternalTrue(env, RESULT(env, top));\n    }\n  }\n\n  class LispUnProtect extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment env, int top) throws Exception\n    {\n      String s = YacasEvalCaller.ARGUMENT(env, top, 1).Get().String();\n\n      LispError.CHK_ARG_CORE(env, top, s != null, 1);\n      LispError.CHK_ARG_CORE(env, top, !LispStandard.IsNumber(s,true), 1);\n\n      env.UnProtect(s);\n\n      LispStandard.InternalTrue(env, RESULT(env, top));\n    }\n  }\n\n  class LispIsProtected extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment env, int top) throws Exception\n    {\n      String s = YacasEvalCaller.ARGUMENT(env, top, 1).Get().String();\n\n      LispError.CHK_ARG_CORE(env, top, s != null, 1);\n      LispError.CHK_ARG_CORE(env, top, !LispStandard.IsNumber(s,true), 1);\n\n      if (env.IsProtected(s))\n          LispStandard.InternalTrue(env, RESULT(env, top));\n      else\n          LispStandard.InternalFalse(env, RESULT(env, top));\n    }\n  }\n\n\n  class LispSetVar extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalSetVar(aEnvironment, aStackTop, false, false);\n    }\n  }\n\n  class LispMacroSetVar extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalSetVar(aEnvironment, aStackTop, true, false);\n    }\n  }\n\n  class LispSetGlobalLazyVariable extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalSetVar(aEnvironment, aStackTop, false, true);\n    }\n  }\n\n  class LispClearVar extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr subList = ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList();\n      if (subList != null)\n      {\n        LispIterator iter = new LispIterator(subList);\n        iter.GoNext();\n        int nr=1;\n        while (iter.GetObject() != null)\n        {\n          String str;\n          str = iter.GetObject().String();\n          LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str != null, nr);\n          aEnvironment.UnsetVariable(str);\n          iter.GoNext();\n          nr++;\n        }\n      }\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispNewLocal extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr subList = ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList();\n      if (subList!= null)\n      {\n        LispIterator iter = new LispIterator(subList);\n        iter.GoNext();\n\n        int nr = 1;\n        while (iter.GetObject() != null)\n        {\n          String variable = iter.GetObject().String();\n          LispError.CHK_ARG_CORE(aEnvironment,aStackTop,variable != null,nr);\n    // printf(\"Variable %s\\n\",variable.String());\n          aEnvironment.NewLocal(variable,null);\n          iter.GoNext();\n          nr++;\n        }\n      }\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispHead extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispStandard.InternalNth(RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 1),1);\n    }\n  }\n\n  class LispNth extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      String str;\n      str = ARGUMENT(aEnvironment, aStackTop, 2).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str != null,2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,LispStandard.IsNumber(str,false),2);\n      int index = Integer.parseInt(str);\n      LispStandard.InternalNth(RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 1), index);\n    }\n  }\n\n  class LispTail extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr first = new LispPtr();\n      LispStandard.InternalTail(first, ARGUMENT(aEnvironment, aStackTop, 1));\n      LispStandard.InternalTail(RESULT(aEnvironment, aStackTop), first);\n      LispPtr head = new LispPtr();\n      head.Set(aEnvironment.iList.Copy(false));\n      head.Get().Next().Set(RESULT(aEnvironment, aStackTop).Get().SubList().Get());\n      RESULT(aEnvironment, aStackTop).Get().SubList().Set(head.Get());\n    }\n  }\n\n  class LispDestructiveReverse extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr reversed = new LispPtr();\n      reversed.Set(aEnvironment.iList.Copy(false));\n      LispStandard.InternalReverseList(reversed.Get().Next(), ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList().Get().Next());\n      RESULT(aEnvironment, aStackTop).Set(LispSubList.New(reversed.Get()));\n    }\n  }\n\n  class LispLength extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr subList = ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList();\n      if (subList != null)\n      {\n        int num = LispStandard.InternalListLength(subList.Get().Next());\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+num));\n        return;\n      }\n      String string = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      if (LispStandard.InternalIsString(string))\n      {\n        int num = string.length()-2;\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+num));\n        return;\n      }\n      GenericClass gen = ARGUMENT(aEnvironment, aStackTop, 1).Get().Generic();\n      if (gen != null)\n        if (gen.TypeName().equals(\"\\\"Array\\\"\")) {\n          int size=((ArrayClass)gen).Size();\n          RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+size));\n        } else if (gen.TypeName().equals(\"\\\"Association\\\"\")) {\n          int size=((AssociationClass)gen).Size();\n          RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+size));\n        }\n    //  CHK_ISLIST_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1),1);\n    }\n  }\n\n  class LispList extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr all = new LispPtr();\n      all.Set(aEnvironment.iList.Copy(false));\n      LispIterator tail = new LispIterator(all);\n      tail.GoNext();\n      LispIterator iter = new LispIterator(ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList());\n      iter.GoNext();\n      while (iter.GetObject() != null)\n      {\n        LispPtr evaluated = new LispPtr();\n        aEnvironment.iEvaluator.Eval(aEnvironment,evaluated,iter.Ptr());\n        tail.Ptr().Set(evaluated.Get());\n        tail.GoNext();\n        iter.GoNext();\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispSubList.New(all.Get()));\n    }\n  }\n\n  class LispUnList extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList() != null, 1);\n      LispObject subList = ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList().Get();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,subList != null, 1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,subList.String() == aEnvironment.iList.String(),1);\n      LispStandard.InternalTail(RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 1));\n    }\n  }\n\n  class LispListify extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList() != null, 1);\n      LispPtr head = new LispPtr();\n      head.Set(aEnvironment.iList.Copy(false));\n      head.Get().Next().Set(ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList().Get());\n      RESULT(aEnvironment, aStackTop).Set(LispSubList.New(head.Get()));\n    }\n  }\n\n  class LispConcatenate extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr all = new LispPtr();\n      all.Set(aEnvironment.iList.Copy(false));\n      LispIterator tail = new LispIterator(all);\n      tail.GoNext();\n      int arg = 1;\n\n      LispIterator iter = new LispIterator(ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList());\n      iter.GoNext();\n      while (iter.GetObject() != null)\n      {\n        LispError.CHK_ISLIST_CORE(aEnvironment,aStackTop,iter.Ptr(),arg);\n        LispStandard.InternalFlatCopy(tail.Ptr(),iter.Ptr().Get().SubList().Get().Next());\n        while (tail.GetObject() != null)\n          tail.GoNext();\n        iter.GoNext();\n        arg++;\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispSubList.New(all.Get()));\n    }\n  }\n\n  class LispConcatenateStrings extends YacasEvalCaller\n  {\n    void ConcatenateStrings(StringBuffer aStringBuffer, LispEnvironment aEnvironment, int aStackTop) throws Exception\n    {\n      aStringBuffer.append('\\\"');\n      int arg=1;\n\n      LispIterator iter = new LispIterator(ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList());\n      iter.GoNext();\n      while (iter.GetObject() != null)\n      {\n        LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,iter.Ptr(),arg);\n        String thisString = iter.GetObject().String();\n        String toAppend = thisString.substring(1,thisString.length()-1);\n        aStringBuffer.append(toAppend);\n        iter.GoNext();\n        arg++;\n      }\n      aStringBuffer.append('\\\"');\n    }\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      StringBuffer strBuffer = new StringBuffer(\"\");\n      ConcatenateStrings(strBuffer,aEnvironment, aStackTop);\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,strBuffer.toString()));\n    }\n  }\n\n  class LispDelete extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalDelete(aEnvironment, aStackTop,false);\n    }\n  }\n\n  class LispDestructiveDelete extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalDelete(aEnvironment, aStackTop,true);\n    }\n  }\n\n  class LispInsert extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalInsert(aEnvironment, aStackTop,false);\n    }\n  }\n\n  class LispDestructiveInsert extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalInsert(aEnvironment, aStackTop,true);\n    }\n  }\n\n  class LispReplace extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalReplace(aEnvironment, aStackTop,false);\n    }\n  }\n\n  class LispDestructiveReplace extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.InternalReplace(aEnvironment, aStackTop,true);\n    }\n  }\n\n  class LispAtomize extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      // Get operator\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.HashTable().LookUpUnStringify(orig)));\n    }\n  }\n\n  class LispStringify extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      // Get operator\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.HashTable().LookUpStringify(orig)));\n    }\n  }\n\n  class LispCharString extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      String str;\n      str = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str != null,2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,LispStandard.IsNumber(str,false),2);\n      char asciiCode = (char)Integer.parseInt(str,10);\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\\\"\"+asciiCode+\"\\\"\"));\n    }\n  }\n\n  class LispFlatCopy extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr copied = new LispPtr();\n      LispStandard.InternalFlatCopy(copied,ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList());\n      RESULT(aEnvironment, aStackTop).Set(LispSubList.New(copied.Get()));\n    }\n  }\n\n  class LispProgBody extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Allow accessing previous locals.\n      aEnvironment.PushLocalFrame(false);\n      try\n      {\n        LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n\n        // Evaluate args one by one.\n\n        LispIterator iter = new LispIterator(ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList());\n        iter.GoNext();\n        while (iter.GetObject() != null)\n        {\n          aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), iter.Ptr());\n          iter.GoNext();\n        }\n      }\n      catch (Exception e) { throw e; }\n      finally\n      {\n        aEnvironment.PopLocalFrame();\n      }\n    }\n  }\n\n  class LispWhile extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr arg1 = ARGUMENT(aEnvironment, aStackTop, 1);\n      LispPtr arg2 = ARGUMENT(aEnvironment, aStackTop, 2);\n\n      LispPtr predicate = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, predicate, arg1);\n\n      while (LispStandard.IsTrue(aEnvironment,predicate))\n      {\n          LispPtr evaluated = new LispPtr();\n          aEnvironment.iEvaluator.Eval(aEnvironment, evaluated, arg2);\n          aEnvironment.iEvaluator.Eval(aEnvironment, predicate, arg1);\n\n      }\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,LispStandard.IsFalse(aEnvironment,predicate),1);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispIf extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      int nrArguments = LispStandard.InternalListLength(ARGUMENT(aEnvironment, aStackTop, 0));\n      LispError.CHK_CORE(aEnvironment,aStackTop,nrArguments == 3 || nrArguments == 4,LispError.KLispErrWrongNumberOfArgs);\n\n      LispPtr predicate = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, predicate, ARGUMENT(aEnvironment, aStackTop, 1));\n\n      if (LispStandard.IsTrue(aEnvironment,predicate))\n      {\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), Argument(ARGUMENT(aEnvironment, aStackTop, 0),2));\n      }\n      else\n      {\n          LispError.CHK_ARG_CORE(aEnvironment,aStackTop,LispStandard.IsFalse(aEnvironment,predicate),1);\n          if (nrArguments == 4)\n          {\n            aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), Argument(ARGUMENT(aEnvironment, aStackTop, 0),3));\n          }\n          else\n          {\n            LispStandard.InternalFalse(aEnvironment,RESULT(aEnvironment, aStackTop));\n          }\n      }\n    }\n  }\n\n  class LispCheck extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr pred = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, pred, ARGUMENT(aEnvironment, aStackTop, 1));\n      if (!LispStandard.IsTrue(aEnvironment,pred))\n      {\n          LispPtr evaluated = new LispPtr();\n          aEnvironment.iEvaluator.Eval(aEnvironment, evaluated, ARGUMENT(aEnvironment, aStackTop, 2));\n          LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,evaluated,2);\n          throw new Exception(evaluated.Get().String());\n      }\n      RESULT(aEnvironment, aStackTop).Set(pred.Get());\n    }\n  }\n\n  class LispTrapError extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      try\n      {\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 1));\n      }\n      catch (Exception e)\n      {\n        aEnvironment.iError = e.toString();\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 2));\n        aEnvironment.iError = null;\n      }\n    }\n  }\n\n  class LispGetCoreError extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.HashTable().LookUpStringify(aEnvironment.iError)));\n    }\n  }\n\n  class LispPreFix extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.MultiFix(aEnvironment, aStackTop, aEnvironment.iPrefixOperators);\n    }\n  }\n\n  class LispInFix extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.MultiFix(aEnvironment, aStackTop, aEnvironment.iInfixOperators);\n    }\n  }\n\n  class LispPostFix extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      int nrArguments = LispStandard.InternalListLength(ARGUMENT(aEnvironment, aStackTop, 0));\n      if (nrArguments == 2)\n      {\n        MathCommands.SingleFix(0, aEnvironment, aStackTop, aEnvironment.iPostfixOperators);\n      }\n      else\n      {\n        MathCommands.MultiFix(aEnvironment, aStackTop, aEnvironment.iPostfixOperators);\n      }\n    }\n  }\n\n  class LispBodied extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      MathCommands.MultiFix(aEnvironment, aStackTop, aEnvironment.iBodiedOperators);\n    }\n  }\n\n  class LispRuleBase extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalRuleBase(aEnvironment, aStackTop, false);\n    }\n  }\n\n  class LispMacroRuleBase extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalRuleBase(aEnvironment, aStackTop, false);\n    }\n  }\n\n  class LispRuleBaseListed extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalRuleBase(aEnvironment, aStackTop, true);\n    }\n  }\n\n  class LispMacroRuleBaseListed extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalRuleBase(aEnvironment, aStackTop, true);\n    }\n  }\n\n  class LispDefMacroRuleBase extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalDefMacroRuleBase(aEnvironment, aStackTop, false);\n    }\n  }\n\n  class LispDefMacroRuleBaseListed extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalDefMacroRuleBase(aEnvironment, aStackTop, true);\n    }\n  }\n\n  class LispHoldArg extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get operator\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n      String orig = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      // The arguments\n      String tohold = ARGUMENT(aEnvironment, aStackTop, 2).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,tohold != null, 2);\n      aEnvironment.HoldArgument(LispStandard.SymbolName(aEnvironment,orig), tohold);\n      // Return true\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispNewRule extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalNewRule(aEnvironment, aStackTop);\n    }\n  }\n\n  class LispMacroNewRule extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalNewRule(aEnvironment, aStackTop);\n    }\n  }\n\n  class LispUnFence extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get operator\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n      String orig = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      // The arity\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 2).Get() != null, 2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 2).Get().String() != null, 2);\n      int arity = Integer.parseInt(ARGUMENT(aEnvironment, aStackTop, 2).Get().String(),10);\n\n      aEnvironment.UnFenceRule(LispStandard.SymbolName(aEnvironment,orig), arity);\n\n      // Return true\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispRetract extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get operator\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.SymbolName(aEnvironment,orig);\n\n      LispPtr arity = new LispPtr();\n      arity.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,arity.Get().String() != null, 2);\n      int ar = Integer.parseInt(arity.Get().String(),10);\n      aEnvironment.Retract(oper, ar);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispNot extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      if (LispStandard.IsTrue(aEnvironment, evaluated) || LispStandard.IsFalse(aEnvironment, evaluated))\n      {\n        LispStandard.InternalNot(RESULT(aEnvironment, aStackTop), aEnvironment, evaluated);\n      }\n      else\n      {\n        LispPtr ptr = new LispPtr();\n        ptr.Set(ARGUMENT(aEnvironment, aStackTop, 0).Get().Copy(false));\n        ptr.Get().Next().Set(evaluated.Get());\n        RESULT(aEnvironment, aStackTop).Set(LispSubList.New(ptr.Get()));\n      }\n    }\n  }\n\n  class LispLazyAnd extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr nogos = new LispPtr();\n      int nrnogos=0;\n      LispPtr evaluated = new LispPtr();\n\n      LispIterator iter = new LispIterator(ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList());\n      iter.GoNext();\n      while (iter.GetObject() != null)\n      {\n          aEnvironment.iEvaluator.Eval(aEnvironment, evaluated, iter.Ptr());\n          if (LispStandard.IsFalse(aEnvironment, evaluated))\n          {\n              LispStandard.InternalFalse(aEnvironment,RESULT(aEnvironment, aStackTop));\n              return;\n          }\n          else if (!LispStandard.IsTrue(aEnvironment, evaluated))\n          {\n              LispPtr ptr = new LispPtr();\n              nrnogos++;\n              ptr.Set(evaluated.Get().Copy(false));\n              ptr.Get().Next().Set(nogos.Get());\n              nogos.Set(ptr.Get());\n          }\n\n          iter.GoNext();\n      }\n\n      if (nogos.Get() != null)\n      {\n          if (nrnogos == 1)\n          {\n              RESULT(aEnvironment, aStackTop).Set(nogos.Get());\n          }\n          else\n          {\n              LispPtr ptr = new LispPtr();\n\n              LispStandard.InternalReverseList(ptr, nogos);\n              nogos.Set(ptr.Get());\n\n              ptr.Set(ARGUMENT(aEnvironment, aStackTop, 0).Get().Copy(false));\n              ptr.Get().Next().Set(nogos.Get());\n              nogos.Set(ptr.Get());\n              RESULT(aEnvironment, aStackTop).Set(LispSubList.New(nogos.Get()));\n\n              //aEnvironment.CurrentPrinter().Print(RESULT(aEnvironment, aStackTop), *aEnvironment.CurrentOutput());\n          }\n      }\n      else\n      {\n          LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n      }\n    }\n  }\n\n  class LispLazyOr extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr nogos = new LispPtr();\n      int nrnogos=0;\n\n      LispPtr evaluated = new LispPtr();\n\n      LispIterator iter = new LispIterator(ARGUMENT(aEnvironment, aStackTop, 1).Get().SubList());\n      iter.GoNext();\n      while (iter.GetObject() != null)\n      {\n        aEnvironment.iEvaluator.Eval(aEnvironment, evaluated, iter.Ptr());\n        if (LispStandard.IsTrue(aEnvironment, evaluated))\n        {\n          LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n          return;\n        }\n        else if (!LispStandard.IsFalse(aEnvironment, evaluated))\n        {\n          LispPtr ptr = new LispPtr();\n          nrnogos++;\n\n          ptr.Set(evaluated.Get().Copy(false));\n          ptr.Get().Next().Set(nogos.Get());\n          nogos.Set(ptr.Get());\n        }\n        iter.GoNext();\n      }\n\n      if (nogos.Get() != null)\n      {\n        if (nrnogos == 1)\n        {\n          RESULT(aEnvironment, aStackTop).Set(nogos.Get());\n        }\n        else\n        {\n          LispPtr ptr = new LispPtr();\n\n          LispStandard.InternalReverseList(ptr, nogos);\n          nogos.Set(ptr.Get());\n\n          ptr.Set(ARGUMENT(aEnvironment, aStackTop, 0).Get().Copy(false));\n          ptr.Get().Next().Set(nogos.Get());\n          nogos.Set(ptr.Get());\n          RESULT(aEnvironment, aStackTop).Set(LispSubList.New(nogos.Get()));\n        }\n        //aEnvironment.CurrentPrinter().Print(RESULT(aEnvironment, aStackTop), *aEnvironment.CurrentOutput());\n      }\n      else\n      {\n        LispStandard.InternalFalse(aEnvironment,RESULT(aEnvironment, aStackTop));\n      }\n    }\n  }\n\n  class LispEquals extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated1 = new LispPtr();\n      evaluated1.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispPtr evaluated2 = new LispPtr();\n      evaluated2.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop),\n                      LispStandard.InternalEquals(aEnvironment, evaluated1, evaluated2));\n    }\n  }\n\n    class LispStrictTotalOrder extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment aEnvironment, int aStackTop) throws Exception {\n            LispPtr evaluated1 = new LispPtr();\n            evaluated1.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n            LispPtr evaluated2 = new LispPtr();\n            evaluated2.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n            LispStandard.InternalBoolean(aEnvironment, RESULT(aEnvironment, aStackTop),\n                    LispStandard.InternalStrictTotalOrder(aEnvironment, evaluated1, evaluated2));\n        }\n    }\n\n  abstract class LispLexCompare2\n  {\n    abstract boolean lexfunc(String f1, String f2, LispHashTable aHashTable,int aPrecision);\n    abstract boolean numfunc(BigNumber n1, BigNumber n2);\n\n    void Compare(LispEnvironment aEnvironment, int aStackTop) throws Exception\n    {\n      LispPtr result1 = new LispPtr();\n      LispPtr result2 = new LispPtr();\n      result1.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      result2.Set(YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 2).Get());\n      boolean cmp;\n      BigNumber n1 = result1.Get().Number(aEnvironment.Precision());\n      BigNumber n2 = result2.Get().Number(aEnvironment.Precision());\n      if (n1 != null && n2 != null)\n      {\n        cmp =numfunc(n1,n2);\n      }\n      else\n      {\n        String str1;\n        String str2;\n        str1 = result1.Get().String();\n        str2 = result2.Get().String();\n        LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str1 != null ,1);\n        LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str2 != null, 2);\n      // the precision argument is ignored in \"lex\" functions\n        cmp =lexfunc(str1,str2,\n                              aEnvironment.HashTable(),\n                              aEnvironment.Precision());\n      }\n\n      LispStandard.InternalBoolean(aEnvironment,YacasEvalCaller.RESULT(aEnvironment, aStackTop), cmp);\n    }\n  }\n\n\n  class LexLessThan extends LispLexCompare2\n  {\n    @Override\n    boolean lexfunc(String f1, String f2, LispHashTable aHashTable,int aPrecision)\n    {\n      return f1.compareTo(f2)<0;\n    }\n    @Override\n    boolean numfunc(BigNumber n1, BigNumber n2)\n    {\n      return n1.LessThan(n2) && !n1.Equals(n2);\n    }\n  }\n  class LexGreaterThan extends LispLexCompare2\n  {\n    @Override\n    boolean lexfunc(String f1, String f2, LispHashTable aHashTable,int aPrecision)\n    {\n      return f1.compareTo(f2)>0;\n    }\n    @Override\n    boolean numfunc(BigNumber n1, BigNumber n2)\n    {\n      return !(n1.LessThan(n2) || n1.Equals(n2));\n    }\n  }\n\n\n  class LispLessThan extends YacasEvalCaller\n  {\n    LexLessThan compare = new LexLessThan();\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      compare.Compare(aEnvironment,aStackTop);\n    }\n  }\n\n  class LispGreaterThan extends YacasEvalCaller\n  {\n    LexGreaterThan compare = new LexGreaterThan();\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      compare.Compare(aEnvironment,aStackTop);\n    }\n  }\n\n  class LispIsFunction extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr result = new LispPtr();\n      result.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop),\n                      result.Get().SubList()!=null);\n    }\n  }\n\n  class LispIsAtom extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr result = new LispPtr();\n      result.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      String s = result.Get().String();\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop),s!=null);\n    }\n  }\n\n  class LispIsNumber extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr result = new LispPtr();\n      result.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop), result.Get().Number(aEnvironment.Precision()) != null);\n    }\n  }\n\n  class LispIsInteger extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr result = new LispPtr();\n      result.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      BigNumber num = result.Get().Number(aEnvironment.Precision());\n      if (num == null)\n      {\n        LispStandard.InternalFalse(aEnvironment,RESULT(aEnvironment, aStackTop));\n      }\n      else\n      {\n        LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop), num.IsInt());\n      }\n    }\n  }\n\n  class LispIsList extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr result = new LispPtr();\n      result.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop),LispStandard.InternalIsList(result));\n    }\n  }\n\n  class LispIsString extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr result = new LispPtr();\n      result.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop),\n                      LispStandard.InternalIsString(result.Get().String()));\n    }\n  }\n\n  class LispIsBound extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      String str = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      if (str != null)\n      {\n        LispPtr val = new LispPtr();\n        aEnvironment.GetVariable(str,val);\n        if (val.Get() != null)\n        {\n          LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n          return;\n        }\n      }\n      LispStandard.InternalFalse(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispMultiply extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.Multiply(x,y,aEnvironment.Precision());\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n/// Corresponds to the Yacas function \\c MathAdd.\n/// If called with one argument (unary plus), this argument is\n/// converted to BigNumber. If called with two arguments (binary plus),\n/// both argument are converted to a BigNumber, and these are added\n/// together at the current precision. The sum is returned.\n/// \\sa GetNumber(), BigNumber::Add()\n  class LispAdd extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      int length = LispStandard.InternalListLength(ARGUMENT(aEnvironment, aStackTop, 0));\n      if (length == 2)\n      {\n        BigNumber x;\n        x = MathCommands.GetNumber(aEnvironment, aStackTop, 1);\n        RESULT(aEnvironment, aStackTop).Set(new LispNumber(x));\n      }\n      else\n      {\n        BigNumber x = MathCommands.GetNumber(aEnvironment, aStackTop, 1);\n        BigNumber y = MathCommands.GetNumber(aEnvironment, aStackTop, 2);\n        int bin = aEnvironment.Precision();\n        BigNumber z = new BigNumber(bin);\n        z.Add(x,y,aEnvironment.Precision());\n        RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n      }\n    }\n  }\n\n  class LispSubtract extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      int length = LispStandard.InternalListLength(ARGUMENT(aEnvironment, aStackTop, 0));\n      if (length == 2)\n      {\n        BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n        BigNumber z = new BigNumber(x);\n        z.Negate(x);\n        RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n        return;\n      }\n      else\n      {\n        BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n        BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n        BigNumber yneg = new BigNumber(y);\n        yneg.Negate(y);\n        BigNumber z = new BigNumber(aEnvironment.Precision());\n        z.Add(x,yneg,aEnvironment.Precision());\n        RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n        return;\n      }\n    }\n  }\n\n  class LispDivide extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      // if both arguments are integers, then BigNumber::Divide would perform an integer divide, but we want a float divide here.\n      if (x.IsInt() && y.IsInt())\n      {\n        // why can't we just say BigNumber temp; ?\n        BigNumber tempx = new BigNumber(aEnvironment.Precision());\n        tempx.SetTo(x);\n        tempx.BecomeFloat(aEnvironment.Precision());  // coerce x to float\n        BigNumber tempy = new BigNumber(aEnvironment.Precision());\n        tempy.SetTo(y);\n        tempy.BecomeFloat(aEnvironment.Precision());  // coerce x to float\n        z.Divide(tempx, tempy,aEnvironment.Precision());\n      }\n      else\n      {\n        z.Divide(x, y,aEnvironment.Precision());\n      }\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class YacasBuiltinPrecisionSet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr index = new LispPtr();\n      index.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 1);\n\n      int ind = Integer.parseInt(index.Get().String(),10);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ind>0,1);\n      aEnvironment.SetPrecision(ind);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispGetExactBits extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(\n        (x.IsInt())\n      ? x.BitCount()  // for integers, return the bit count\n        : LispStandard.digits_to_bits((x.GetPrecision()), 10)   // for floats, return the precision\n        );\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n\n    class LispSetExactBits extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment aEnvironment, int aStackTop) throws Exception {\n            BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n            BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n            BigNumber z = new BigNumber(aEnvironment.Precision());\n            z.SetTo(x);\n\n            // do nothing for integers\n            if (!(z.IsInt())) {\n                z.Precision((int) (LispStandard.bits_to_digits((long) (y.Double()), 10)));\n            }\n            RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n        }\n    }\n\n  class LispBitCount extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(x.BitCount());\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispMathSign extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(x.Sign());\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispMathIsSmall extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop), x.IsSmall());\n    }\n  }\n\n  class LispMathNegate extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.Negate(x);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispFloor extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.Floor(x);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispCeil extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.Negate(x);\n      z.Floor(z);\n      z.Negate(z);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispAbs extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(x);\n      if (x.Sign()<0)\n        z.Negate(x);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispMod extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.Mod(x,y);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispDiv extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      if (x.IsInt() && y.IsInt())\n      {  // both integer, perform integer division\n          BigNumber z = new BigNumber(aEnvironment.Precision());\n          z.Divide(x,y,aEnvironment.Precision());\n          RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n      }\n      else\n      {\n        throw new Exception(\"LispDiv: error: both arguments must be integer\");\n      }\n    }\n  }\n\n  class LispBitsToDigits extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      long result = 0;  // initialize just in case\n      if (x.IsInt() && x.IsSmall() && y.IsInt() && y.IsSmall())\n      {\n        // bits_to_digits uses unsigned long, see numbers.h\n        int base = (int)y.Double();\n        result = LispStandard.bits_to_digits((long)(x.Double()), base);\n      }\n      else\n      {\n        throw new YacasException(\"BitsToDigits: error: arguments (\"+x.Double()+\", \"+y.Double()+\") must be small integers\");\n      }\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(result);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispDigitsToBits extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      long result = 0;  // initialize just in case\n      if (x.IsInt() && x.IsSmall() && y.IsInt() && y.IsSmall())\n      {\n        // bits_to_digits uses unsigned long, see numbers.h\n        int base = (int)y.Double();\n        result = LispStandard.digits_to_bits((long)(x.Double()), base);\n      }\n      else\n      {\n        throw new YacasException(\"BitsToDigits: error: arguments (\"+x.Double()+\", \"+y.Double()+\") must be small integers\");\n      }\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(result);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispGcd extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.Gcd(x,y);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispSystemCall extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n      String orig = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n      String ls_str;\n      final Process ls_proc = Runtime.getRuntime().exec(oper);\n\n      StreamGobbler og = new StreamGobbler(ls_proc.getInputStream());\n      StreamGobbler eg = new StreamGobbler(ls_proc.getErrorStream());\n\n      og.start();\n      eg.start();\n\n      // Wait for the process. Therefore a separate thread is used.\n      // Thus yacas can continue even if the process is running.\n      Thread waitForProcess = new Thread() {\n          @Override\n          public void run() {\n              int returncode = -1;\n              try {\n                  while (returncode < 0 && !isInterrupted()) {\n                      returncode = ls_proc.waitFor();\n                  }\n                  if (returncode != 0) System.out.println(\"Subprocess terminated with return code \" + returncode);\n              } catch (InterruptedException ex) {\n                  interrupt();\n                  System.err.println(\"Subprocess still running. Yacas will not wait for it.\");\n              }\n          }\n      };\n      waitForProcess.start();\n      // Wait for the process to terminate. If it does not within 9500 ms\n      // yacas will continue (without destroing the subprocess).\n      waitForProcess.join(9500);\n      waitForProcess.interrupt();\n\n      // Wait (at most 250 ms) for the process output stream thread to die.\n      og.join(250);\n      ArrayList<String> output = og.shutdown();\n      for (String s: output) {\n          aEnvironment.iCurrentOutput.write(s);\n          aEnvironment.iCurrentOutput.write(\"\\n\");\n      }\n      // Wait (at most 250 ms) for the process error stream thread to die.\n      eg.join(250);\n      ArrayList<String> errors = eg.shutdown();\n      for (String s: errors) {\n          aEnvironment.iCurrentOutput.write(s);\n          aEnvironment.iCurrentOutput.write(\"\\n\");\n      }\n    }\n  }\n\n  class LispSystemName extends YacasEvalCaller\n  {\n      @Override\n      public void Eval(LispEnvironment aEnvironment, int aStackTop) throws Exception\n      {\n          String os = System.getProperty(\"os.name\");\n\n          if (os == null) {\n              RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment, aEnvironment.HashTable().LookUpStringify(\"Unknown\")));\n              return;\n          }\n\n          os = os.toLowerCase();\n\n          if (os.equals(\"mac os x\"))\n              RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment, aEnvironment.HashTable().LookUpStringify(\"MacOSX\")));\n          else if (os.contains(\"windows\"))\n              RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment, aEnvironment.HashTable().LookUpStringify(\"Windows\")));\n          else if (os.contains(\"linux\"))\n              RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment, aEnvironment.HashTable().LookUpStringify(\"Linux\")));\n          else\n              RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment, aEnvironment.HashTable().LookUpStringify(\"Unknown\")));\n      }\n  }\n\n  class LispFastArcSin extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x;\n      x = GetNumber(aEnvironment, aStackTop, 1);\n      double result = Math.asin(x.Double());\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(result);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispFastLog extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x;\n      x = GetNumber(aEnvironment, aStackTop, 1);\n      double result = Math.log(x.Double());\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(result);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispFastPower extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x, y;\n      x = GetNumber(aEnvironment, aStackTop, 1);\n      y = GetNumber(aEnvironment, aStackTop, 2);\n      double result = Math.pow(x.Double(), y.Double());\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(result);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispShiftLeft extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber n = GetNumber(aEnvironment, aStackTop, 2);\n      long nrToShift = n.Long();\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.ShiftLeft(x,(int)nrToShift);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispShiftRight extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber n = GetNumber(aEnvironment, aStackTop, 2);\n      long nrToShift = n.Long();\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.ShiftRight(x,(int)nrToShift);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispFromBase extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get the base to convert to:\n      // Evaluate first argument, and store result in oper\n      LispPtr oper = new LispPtr();\n      oper.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      // Check that result is a number, and that it is in fact an integer\n      BigNumber num = oper.Get().Number(aEnvironment.Precision());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,num != null,1);\n    // check that the base is an integer between 2 and 32\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,num.IsInt(), 1);\n\n      // Get a short platform integer from the first argument\n      int base = (int)(num.Double());\n\n      // Get the number to convert\n      LispPtr fromNum = new LispPtr();\n      fromNum.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n      String str2;\n      str2 = fromNum.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str2 != null,2);\n\n      // Added, unquote a string\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,LispStandard.InternalIsString(str2),2);\n      str2 = aEnvironment.HashTable().LookUpUnStringify(str2);\n\n      // convert using correct base\n      BigNumber z = new BigNumber(str2,aEnvironment.Precision(),base);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispToBase extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get the base to convert to:\n      // Evaluate first argument, and store result in oper\n      LispPtr oper = new LispPtr();\n      oper.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      // Check that result is a number, and that it is in fact an integer\n      BigNumber num = oper.Get().Number(aEnvironment.Precision());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,num != null,1);\n    // check that the base is an integer between 2 and 32\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,num.IsInt(), 1);\n\n      // Get a short platform integer from the first argument\n      int base = (int)(num.Long());\n\n      // Get the number to convert\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 2);\n\n      // convert using correct base\n      String str;\n      str = x.ToString(aEnvironment.Precision(),base);\n      // Get unique string from hash table, and create an atom from it.\n\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.HashTable().LookUpStringify(str)));\n    }\n  }\n\n  class LispMaxEvalDepth extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr index = new LispPtr();\n      index.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 1);\n\n      int ind = Integer.parseInt(index.Get().String(),10);\n      aEnvironment.iMaxEvalDepth = ind;\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispDefLoad extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_CORE(aEnvironment, aStackTop,aEnvironment.iSecure == false, LispError.KLispErrSecurityBreach);\n\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      LispStandard.LoadDefFile(aEnvironment, orig);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispUse extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      LispStandard.InternalUse(aEnvironment,orig);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispRightAssociative extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get operator\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n      String orig = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      aEnvironment.iInfixOperators.SetRightAssociative(LispStandard.SymbolName(aEnvironment,orig));\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispLeftPrecedence extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get operator\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n      String orig = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      LispPtr index = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, index, ARGUMENT(aEnvironment, aStackTop, 2));\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 2);\n      int ind = Integer.parseInt(index.Get().String(),10);\n\n      aEnvironment.iInfixOperators.SetLeftPrecedence(LispStandard.SymbolName(aEnvironment,orig),ind);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispRightPrecedence extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // Get operator\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get() != null, 1);\n      String orig = ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n\n      LispPtr index = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, index, ARGUMENT(aEnvironment, aStackTop, 2));\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 2);\n      int ind = Integer.parseInt(index.Get().String(),10);\n\n      aEnvironment.iInfixOperators.SetRightPrecedence(LispStandard.SymbolName(aEnvironment,orig),ind);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispIsBodied extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispInFixOperator op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iBodiedOperators);\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop), op != null);\n    }\n  }\n\n  class LispIsInFix extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispInFixOperator op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iInfixOperators);\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop), op != null);\n    }\n  }\n\n  class LispIsPreFix extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispInFixOperator op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iPrefixOperators);\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop), op != null);\n    }\n  }\n\n  class LispIsPostFix extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispInFixOperator op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iPostfixOperators);\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop), op != null);\n    }\n  }\n\n  class LispGetPrecedence extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispInFixOperator op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iInfixOperators);\n      if (op == null)\n      {  // also need to check for a postfix or prefix operator\n        op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iPrefixOperators);\n        if (op == null)\n        {\n          op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iPostfixOperators);\n          if (op == null)\n          {  // or maybe it's a bodied function\n            op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iBodiedOperators);\n            LispError.CHK_CORE(aEnvironment,aStackTop,op!=null, LispError.KLispErrIsNotInFix);\n          }\n        }\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+op.iPrecedence));\n    }\n  }\n\n  class LispGetLeftPrecedence extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispInFixOperator op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iInfixOperators);\n      if (op == null)\n      {  // infix and postfix operators have left precedence\n        op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iPostfixOperators);\n        LispError.CHK_CORE(aEnvironment,aStackTop,op!=null, LispError.KLispErrIsNotInFix);\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+op.iLeftPrecedence));\n    }\n  }\n\n  class LispGetRightPrecedence extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispInFixOperator op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iInfixOperators);\n      if (op == null)\n      {   // bodied, infix and prefix operators have right precedence\n        op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iPrefixOperators);\n        if (op == null)\n        {   // or maybe it's a bodied function\n          op = MathCommands.OperatorInfo(aEnvironment, aStackTop, aEnvironment.iBodiedOperators);\n          LispError.CHK_CORE(aEnvironment,aStackTop,op!=null, LispError.KLispErrIsNotInFix);\n        }\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+op.iRightPrecedence));\n    }\n  }\n\n  class YacasBuiltinPrecisionGet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // decimal precision\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+aEnvironment.Precision()));\n    }\n  }\n\n  class LispBitAnd extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.BitAnd(x,y);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispBitOr extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.BitOr(x,y);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispBitXor extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      BigNumber y = GetNumber(aEnvironment, aStackTop, 2);\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.BitXor(x,y);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispSecure extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      boolean prevSecure = aEnvironment.iSecure;\n      aEnvironment.iSecure = true;\n      try\n      {\n        aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), ARGUMENT(aEnvironment, aStackTop, 1));\n      }\n      catch (Exception e) { throw e; }\n      finally { aEnvironment.iSecure = prevSecure; }\n    }\n  }\n\n  class LispFindFile extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_CORE(aEnvironment, aStackTop,aEnvironment.iSecure == false, LispError.KLispErrSecurityBreach);\n\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n\n      String filename = LispStandard.InternalFindFile(oper, aEnvironment.iInputDirectories);\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.HashTable().LookUpStringify(filename)));\n    }\n  }\n\n  class LispFindFunction extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_CORE(aEnvironment, aStackTop,aEnvironment.iSecure == false, LispError.KLispErrSecurityBreach);\n\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      // Get file name\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get() != null, 1);\n      String orig = evaluated.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n\n      LispMultiUserFunction multiUserFunc =\n          aEnvironment.MultiUserFunction(aEnvironment.HashTable().LookUp(oper));\n      if (multiUserFunc != null)\n      {\n        LispDefFile def = multiUserFunc.iFileToOpen;\n        if (def != null)\n        {\n          RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,def.iFileName));\n          return;\n        }\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\\\"\\\"\"));\n    }\n  }\n\n  class LispIsGeneric extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop), evaluated.Get().Generic() != null);\n    }\n  }\n\n  class LispGenericTypeName extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,evaluated.Get().Generic() != null,1);\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,evaluated.Get().Generic().TypeName()));\n    }\n  }\n\n  class GenArrayCreate extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr sizearg = new LispPtr();\n      sizearg.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get() != null, 1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get().String() != null, 1);\n\n      int size = Integer.parseInt(sizearg.Get().String(),10);\n\n      LispPtr initarg = new LispPtr();\n      initarg.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n      ArrayClass array = new ArrayClass(size,initarg.Get());\n      RESULT(aEnvironment, aStackTop).Set(LispGenericClass.New(array));\n    }\n  }\n\n  class GenArraySize extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      GenericClass gen = evaluated.Get().Generic();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,gen != null,1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,gen.TypeName().equals(\"\\\"Array\\\"\"),1);\n      int size=((ArrayClass)gen).Size();\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+size));\n    }\n  }\n\n  class GenArrayGet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      GenericClass gen = evaluated.Get().Generic();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,gen != null,1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,gen.TypeName().equals(\"\\\"Array\\\"\"),1);\n\n      LispPtr sizearg = new LispPtr();\n      sizearg.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get() != null, 2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get().String() != null, 2);\n\n      int size = Integer.parseInt(sizearg.Get().String(),10);\n\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,size>0 && size<=((ArrayClass)gen).Size(),2);\n      LispObject object = ((ArrayClass)gen).GetElement(size);\n\n      RESULT(aEnvironment, aStackTop).Set(object.Copy(false));\n    }\n  }\n\n  class GenArraySet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      GenericClass gen = evaluated.Get().Generic();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,gen != null,1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,gen.TypeName().equals(\"\\\"Array\\\"\"),1);\n\n      LispPtr sizearg = new LispPtr();\n      sizearg.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get() != null, 2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get().String() != null, 2);\n\n      int size = Integer.parseInt(sizearg.Get().String(),10);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,size>0 && size<=((ArrayClass)gen).Size(),2);\n\n      LispPtr obj = new LispPtr();\n      obj.Set(ARGUMENT(aEnvironment, aStackTop, 3).Get());\n      ((ArrayClass)gen).SetElement(size,obj.Get());\n      LispStandard.InternalTrue( aEnvironment, RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n    class GenAssociationCreate extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment env, int stack_top) throws Exception {\n            AssociationClass a = new AssociationClass(env);\n            RESULT(env, stack_top).Set(LispGenericClass.New(a));\n        }\n    }\n\n    class GenAssociationSize extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment aEnvironment, int aStackTop) throws Exception {\n            LispPtr evaluated = new LispPtr();\n            evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n            GenericClass gen = evaluated.Get().Generic();\n            LispError.CHK_ARG_CORE(aEnvironment, aStackTop, gen != null, 1);\n            LispError.CHK_ARG_CORE(aEnvironment, aStackTop, gen.TypeName().equals(\"\\\"Association\\\"\"), 1);\n            int size = ((AssociationClass)gen).Size();\n            RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment, \"\" + size));\n        }\n    }\n\n    class GenAssociationGet extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment env, int stack_top) throws Exception {\n            LispPtr evaluated = new LispPtr();\n            evaluated.Set(ARGUMENT(env, stack_top, 1).Get());\n\n            GenericClass gen = evaluated.Get().Generic();\n            LispError.CHK_ARG_CORE(env, stack_top, gen != null, 1);\n            LispError.CHK_ARG_CORE(env, stack_top, gen.TypeName().equals(\"\\\"Association\\\"\"), 1);\n\n            LispPtr k = new LispPtr();\n            k.Set(ARGUMENT(env, stack_top, 2).Get());\n\n            LispError.CHK_ARG_CORE(env, stack_top, k.Get() != null, 2);\n\n            LispObject v = ((AssociationClass)gen).GetElement(k.Get());\n\n            if (v != null)\n                RESULT(env, stack_top).Set(v.Copy(false));\n            else\n                RESULT(env, stack_top).Set(LispAtom.New(env, \"Undefined\"));\n        }\n    }\n\n    class GenAssociationContains extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment env, int stack_top) throws Exception {\n            LispPtr evaluated = new LispPtr();\n            evaluated.Set(ARGUMENT(env, stack_top, 1).Get());\n\n            GenericClass gen = evaluated.Get().Generic();\n            LispError.CHK_ARG_CORE(env, stack_top, gen != null, 1);\n            LispError.CHK_ARG_CORE(env, stack_top, gen.TypeName().equals(\"\\\"Association\\\"\"), 1);\n\n            LispPtr k = new LispPtr();\n            k.Set(ARGUMENT(env, stack_top, 2).Get());\n\n            LispError.CHK_ARG_CORE(env, stack_top, k.Get() != null, 2);\n\n            if (((AssociationClass)gen).GetElement(k.Get()) != null)\n                LispStandard.InternalTrue(env,YacasEvalCaller.RESULT(env, stack_top));\n            else\n                LispStandard.InternalFalse(env,YacasEvalCaller.RESULT(env, stack_top));\n        }\n    }\n\n    class GenAssociationSet extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment aEnvironment, int aStackTop) throws Exception {\n            LispPtr evaluated = new LispPtr();\n            evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n            GenericClass gen = evaluated.Get().Generic();\n            LispError.CHK_ARG_CORE(aEnvironment, aStackTop, gen != null, 1);\n            LispError.CHK_ARG_CORE(aEnvironment, aStackTop, gen.TypeName().equals(\"\\\"Association\\\"\"), 1);\n\n            LispPtr k = new LispPtr();\n            k.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n            LispError.CHK_ARG_CORE(aEnvironment, aStackTop, k.Get() != null, 2);\n\n            LispPtr v = new LispPtr();\n            v.Set(ARGUMENT(aEnvironment, aStackTop, 3).Get());\n            ((AssociationClass)gen).SetElement(k.Get(), v.Get());\n            LispStandard.InternalTrue(aEnvironment, RESULT(aEnvironment, aStackTop));\n        }\n    }\n\n    class GenAssociationDrop extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment env, int stack_top) throws Exception {\n            LispPtr evaluated = new LispPtr();\n            evaluated.Set(ARGUMENT(env, stack_top, 1).Get());\n\n            GenericClass gen = evaluated.Get().Generic();\n            LispError.CHK_ARG_CORE(env, stack_top, gen != null, 1);\n            LispError.CHK_ARG_CORE(env, stack_top, gen.TypeName().equals(\"\\\"Association\\\"\"), 1);\n\n            LispPtr k = new LispPtr();\n            k.Set(ARGUMENT(env, stack_top, 2).Get());\n\n            LispError.CHK_ARG_CORE(env, stack_top, k.Get() != null, 2);\n\n            if (((AssociationClass)gen).DropElement(k.Get()))\n                LispStandard.InternalTrue(env, RESULT(env, stack_top));\n            else\n                LispStandard.InternalFalse(env, RESULT(env, stack_top));\n        }\n    }\n    \n    class GenAssociationKeys extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment env, int stack_top) throws Exception {\n            LispPtr evaluated = new LispPtr();\n            evaluated.Set(ARGUMENT(env, stack_top, 1).Get());\n\n            GenericClass gen = evaluated.Get().Generic();\n            LispError.CHK_ARG_CORE(env, stack_top, gen != null, 1);\n            LispError.CHK_ARG_CORE(env, stack_top, gen.TypeName().equals(\"\\\"Association\\\"\"), 1);\n\n            RESULT(env, stack_top).Set(((AssociationClass)gen).Keys().Get());\n        }        \n    }\n    \n    class GenAssociationToList extends YacasEvalCaller {\n\n        @Override\n        public void Eval(LispEnvironment env, int stack_top) throws Exception {\n            LispPtr evaluated = new LispPtr();\n            evaluated.Set(ARGUMENT(env, stack_top, 1).Get());\n\n            GenericClass gen = evaluated.Get().Generic();\n            LispError.CHK_ARG_CORE(env, stack_top, gen != null, 1);\n            LispError.CHK_ARG_CORE(env, stack_top, gen.TypeName().equals(\"\\\"Association\\\"\"), 1);\n\n            RESULT(env, stack_top).Set(((AssociationClass)gen).ToList().Get());\n        }        \n    }\n    \n    class GenAssociationHead extends YacasEvalCaller {\n        @Override\n        public void Eval(LispEnvironment env, int stack_top) throws Exception {\n            LispPtr evaluated = new LispPtr();\n            evaluated.Set(ARGUMENT(env, stack_top, 1).Get());\n\n            GenericClass gen = evaluated.Get().Generic();\n            LispError.CHK_ARG_CORE(env, stack_top, gen != null, 1);\n            LispError.CHK_ARG_CORE(env, stack_top, gen.TypeName().equals(\"\\\"Association\\\"\"), 1);\n\n            RESULT(env, stack_top).Set(((AssociationClass)gen).Head().Get());\n        }\n    }\n\n\n  class LispCustomEval extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : CustomEval\");////TODO fixme\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispCustomEvalExpression extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : CustomEvalExpression\");////TODO fixme\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispCustomEvalResult extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : CustomEvalResult\");////TODO fixme\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispCustomEvalLocals extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : LispCustomEvalLocals\");////TODO fixme\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispCustomEvalStop extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : LispCustomEvalStop\");////TODO fixme\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispTraceRule extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : LispTraceRule\");////TODO fixme\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispTraceStack extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : TraceStack\");////TODO fixme\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispReadLisp extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispParser parser = new LispParser(aEnvironment.iCurrentTokenizer,\n                        aEnvironment.iCurrentInput,\n                        aEnvironment);\n      // Read expression\n      parser.Parse(RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispReadLispListed extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispParser parser = new LispParser(aEnvironment.iCurrentTokenizer,\n                        aEnvironment.iCurrentInput,\n                        aEnvironment);\n      parser.iListed = true;\n      // Read expression\n      parser.Parse(RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispType extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispPtr subList = evaluated.Get().SubList();\n      if (subList == null)\n      {\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\\\"\\\"\"));\n        return;\n      }\n      LispObject head = subList.Get();\n      if (head.String() == null)\n      {\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\\\"\\\"\"));\n        return;\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.HashTable().LookUpStringify(head.String())));\n    }\n  }\n\n  class YacasStringMidGet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 3).Get());\n      LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,evaluated,3);\n      String orig = evaluated.Get().String();\n\n      LispPtr index = new LispPtr();\n      index.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 1);\n      int from = Integer.parseInt(index.Get().String(),10);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,from>0,1);\n\n      index.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 2);\n      int count = Integer.parseInt(index.Get().String(),10);\n\n\n      String str = \"\\\"\"+orig.substring(from,from+count)+\"\\\"\";\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,str));\n    }\n  }\n\n  class YacasStringMidSet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr evaluated = new LispPtr();\n      evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 3).Get());\n      LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,evaluated,3);\n      String orig = evaluated.Get().String();\n      LispPtr index = new LispPtr();\n      index.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get() != null, 1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,index.Get().String() != null, 1);\n      int from = Integer.parseInt(index.Get().String(),10);\n\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,from>0,1);\n\n      LispPtr ev2 = new LispPtr();\n      ev2.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n      LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,ev2,2);\n      String replace = ev2.Get().String();\n\n      LispError.CHK_CORE(aEnvironment, aStackTop,from+replace.length()-2<orig.length(), LispError.KLispErrInvalidArg);\n      String str;\n      str = orig.substring(0,from);\n      str = str + replace.substring(1,replace.length()-1);\n//System.out.println(\"from=\"+from+replace.length()-2);\n      str = str + orig.substring(from+replace.length()-2,orig.length());\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,str));\n    }\n  }\n\n  class GenPatternCreate extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr pattern = new LispPtr();\n      pattern.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispPtr postpredicate = new LispPtr();\n      postpredicate.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n      LispIterator iter = new LispIterator(pattern);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,iter.GetObject() != null,1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,iter.GetObject().SubList() != null,1);\n      iter.GoSub();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,iter.GetObject() != null,1);\n      iter.GoNext();\n\n      LispPtr ptr = iter.Ptr();\n\n\n      YacasPatternPredicateBase matcher =\n          new YacasPatternPredicateBase(aEnvironment, ptr,postpredicate);\n      PatternClass p = new PatternClass(matcher);\n      RESULT(aEnvironment, aStackTop).Set(LispGenericClass.New(p));\n    }\n  }\n\n  class GenPatternMatches extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr pattern = new LispPtr();\n      pattern.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      GenericClass gen = pattern.Get().Generic();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,gen != null,1);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,gen.TypeName().equals(\"\\\"Pattern\\\"\"),1);\n\n      LispPtr list = new LispPtr();\n      list.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n      PatternClass patclass = (PatternClass)gen;\n\n      LispIterator iter = new LispIterator(list);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,iter.GetObject() != null,2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,iter.GetObject().SubList() != null,2);\n      iter.GoSub();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,iter.GetObject() != null,2);\n      iter.GoNext();\n\n      LispPtr ptr = iter.Ptr();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ptr != null,2);\n      boolean matches = patclass.Matches(aEnvironment,ptr);\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop),matches);\n    }\n  }\n\n  class LispRuleBaseDefined extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr name = new LispPtr();\n      name.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      String orig = name.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n\n      LispPtr sizearg = new LispPtr();\n      sizearg.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get() != null, 2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get().String() != null, 2);\n\n      int arity = Integer.parseInt(sizearg.Get().String(),10);\n\n      LispUserFunction userFunc = aEnvironment.UserFunction(aEnvironment.HashTable().LookUp(oper),arity);\n      LispStandard.InternalBoolean(aEnvironment,RESULT(aEnvironment, aStackTop),userFunc != null);\n    }\n  }\n\n  class LispDefLoadFunction extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr name = new LispPtr();\n      name.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      String orig = name.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n\n      LispMultiUserFunction multiUserFunc =\n          aEnvironment.MultiUserFunction(aEnvironment.HashTable().LookUp(oper));\n      if (multiUserFunc != null)\n      {\n        if (multiUserFunc.iFileToOpen!=null)\n        {\n          LispDefFile def = multiUserFunc.iFileToOpen;\n          if (!def.iIsLoaded)\n          {\n            multiUserFunc.iFileToOpen=null;\n            LispStandard.InternalUse(aEnvironment,def.iFileName);\n          }\n        }\n      }\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispRuleBaseArgList extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr name = new LispPtr();\n      name.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      String orig = name.Get().String();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,orig != null, 1);\n      String oper = LispStandard.InternalUnstringify(orig);\n\n      LispPtr sizearg = new LispPtr();\n      sizearg.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get() != null, 2);\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,sizearg.Get().String() != null, 2);\n\n      int arity = Integer.parseInt(sizearg.Get().String(),10);\n\n      LispUserFunction userFunc = aEnvironment.UserFunction(aEnvironment.HashTable().LookUp(oper),arity);\n      LispError.CHK_CORE(aEnvironment, aStackTop,userFunc != null, LispError.KLispErrInvalidArg);\n\n      LispPtr list = userFunc.ArgList();\n      LispPtr head = new LispPtr();\n      head.Set(aEnvironment.iList.Copy(false));\n      head.Get().Next().Set(list.Get());\n      RESULT(aEnvironment, aStackTop).Set(LispSubList.New(head.Get()));\n    }\n  }\n\n  class LispNewRulePattern extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalNewRulePattern(aEnvironment, aStackTop, false);\n    }\n  }\n\n  class LispMacroNewRulePattern extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      InternalNewRulePattern(aEnvironment, aStackTop, true\n      );\n    }\n  }\n\n  class LispSubst extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr from = new LispPtr(),to = new LispPtr(),body = new LispPtr();\n      from.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      to  .Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n      body.Set(ARGUMENT(aEnvironment, aStackTop, 3).Get());\n      SubstBehaviour behaviour = new SubstBehaviour(aEnvironment,from, to);\n      LispStandard.InternalSubstitute(RESULT(aEnvironment, aStackTop), body, behaviour);\n    }\n  }\n\n  class LispLocalSymbols extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      int nrArguments = LispStandard.InternalListLength(ARGUMENT(aEnvironment, aStackTop, 0));\n      int nrSymbols = nrArguments-2;\n\n      String names[] = new String[nrSymbols];\n      String localnames[] = new String[nrSymbols];\n\n      int uniquenumber = aEnvironment.GetUniqueId();\n      int i;\n      for (i=0;i<nrSymbols;i++)\n      {\n        String atomname = Argument(ARGUMENT(aEnvironment, aStackTop, 0), i+1).Get().String();\n        LispError.CHK_ARG_CORE(aEnvironment,aStackTop,atomname != null, i+1);\n        names[i] = atomname;\n        int len = atomname.length();\n        String newname = \"$\"+atomname+uniquenumber;\n        String variable = aEnvironment.HashTable().LookUp(newname);\n        localnames[i] = variable;\n      }\n      LocalSymbolBehaviour behaviour = new LocalSymbolBehaviour(aEnvironment,names,localnames,nrSymbols);\n      LispPtr result = new LispPtr();\n      LispStandard.InternalSubstitute(result, Argument(ARGUMENT(aEnvironment, aStackTop, 0), nrArguments-1), behaviour);\n      aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), result);\n    }\n  }\n\n  class LispFastIsPrime extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      //TODO fixme this routine should actually be called SlowIsPrime ;-)\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      long n = x.Long();\n      long result = 1;\n\n      // We only want people to pass in small integers\n      if (n>65538)\n        result = 0;\n\n      int i=2;\n      int max = (int)(1+Math.sqrt(n));\n//System.out.println(\"n = \"+n+\" max = \"+max);\n      while (i<=max && result == 1)\n      {\n      //System.out.println(\"\"+n+\"%\"+i+\" = \"+(n%i));\n        if ((n%i) == 0)\n          result = 0;\n        i++;\n      }\n\n      BigNumber z = new BigNumber(aEnvironment.Precision());\n      z.SetTo(result);\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(z));\n    }\n  }\n\n  class LispFac extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,ARGUMENT(aEnvironment, aStackTop, 1).Get().Number(0) != null,1);\n      LispPtr arg = ARGUMENT(aEnvironment, aStackTop, 1);\n\n      //TODO fixme I am sure this can be optimized still\n      int nr = (int)arg.Get().Number(0).Long();\n      LispError.Check(nr>=0,LispError.KLispErrInvalidArg);\n      BigNumber fac = new BigNumber(\"1\",10,10);\n      int i;\n      for (i=2;i<=nr;i++)\n      {\n        BigNumber m = new BigNumber(\"\"+i,10,10);\n        m.Multiply(fac,m,0);\n        fac = m;\n      }\n      RESULT(aEnvironment, aStackTop).Set(new LispNumber(fac));\n    }\n  }\n\n  class LispApplyPure extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr oper = new LispPtr();\n      oper.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispPtr args = new LispPtr();\n      args.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,args.Get().SubList() != null,2);\n      LispError.CHK_CORE(aEnvironment, aStackTop,args.Get().SubList().Get() != null,2);\n\n      // Apply a pure string\n      if (oper.Get().String() != null)\n      {\n        LispStandard.InternalApplyString(aEnvironment, RESULT(aEnvironment, aStackTop),\n                    oper.Get().String(),\n                    args.Get().SubList().Get().Next());\n      }\n      else\n      {   // Apply a pure function {args,body}.\n        LispPtr args2 = new LispPtr();\n        args2.Set(args.Get().SubList().Get().Next().Get());\n        LispError.CHK_ARG_CORE(aEnvironment,aStackTop,oper.Get().SubList() != null,1);\n        LispError.CHK_ARG_CORE(aEnvironment,aStackTop,oper.Get().SubList().Get() != null,1);\n        LispStandard.InternalApplyPure(oper,args2,RESULT(aEnvironment, aStackTop),aEnvironment);\n      }\n    }\n  }\n\n\n  class YacasPrettyReaderSet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      int nrArguments = LispStandard.InternalListLength(ARGUMENT(aEnvironment, aStackTop, 0));\n      if (nrArguments == 1)\n      {\n        aEnvironment.iPrettyReader = null;\n      }\n      else\n      {\n        LispError.CHK_CORE(aEnvironment, aStackTop,nrArguments == 2,LispError.KLispErrWrongNumberOfArgs);\n        LispPtr oper = new LispPtr();\n        oper.Set(ARGUMENT(aEnvironment, aStackTop, 0).Get());\n        oper.GoNext();\n        LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,oper,1);\n        aEnvironment.iPrettyReader = oper.Get().String();\n      }\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class YacasPrettyReaderGet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      if (aEnvironment.iPrettyReader == null)\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\\\"\\\"\"));\n      else\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.iPrettyReader));\n    }\n  }\n\n  class YacasPrettyPrinterSet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      int nrArguments = LispStandard.InternalListLength(ARGUMENT(aEnvironment, aStackTop, 0));\n      if (nrArguments == 1)\n      {\n        aEnvironment.iPrettyPrinter = null;\n      }\n      else\n      {\n        LispError.CHK_CORE(aEnvironment, aStackTop,nrArguments == 2,LispError.KLispErrWrongNumberOfArgs);\n        LispPtr oper = new LispPtr();\n        oper.Set(ARGUMENT(aEnvironment, aStackTop, 0).Get());\n        oper.GoNext();\n        LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,oper,1);\n        aEnvironment.iPrettyPrinter = oper.Get().String();\n      }\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class YacasPrettyPrinterGet extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      if (aEnvironment.iPrettyPrinter == null)\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\\\"\\\"\"));\n      else\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.iPrettyPrinter));\n    }\n  }\n\n  class LispGarbageCollect extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // all the garbage collection is performed automatically, there's no need\n      // for manual intervention\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispPatchLoad extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n        LispError.CHK_CORE(aEnvironment, aStackTop,aEnvironment.iSecure == false, LispError.KLispErrSecurityBreach);\n\n        LispPtr evaluated = new LispPtr();\n        evaluated.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n        // Get file name\n        LispError.CHK_ARG_CORE(aEnvironment, aStackTop, evaluated.Get() != null, 1);\n        String orig = evaluated.Get().String();\n        LispError.CHK_ARG_CORE(aEnvironment, aStackTop, orig != null, 1);\n\n        LispStandard.InternalPatchLoad(aEnvironment, orig);\n\n        LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispPatchString extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n        String unpatchedString =\n            YacasEvalCaller.ARGUMENT(aEnvironment, aStackTop, 1).Get().String();\n\n        LispError.CHK_ARG_CORE(aEnvironment, aStackTop, unpatchedString != null, 2);\n\n        InputStatus oldStatus = new InputStatus(aEnvironment.iInputStatus);\n        aEnvironment.iInputStatus.SetTo(\"STRING\");\n\n        StringWriter resultStream = new StringWriter();\n\n        LispStandard.DoPatchString(unpatchedString, resultStream, aEnvironment);\n\n        aEnvironment.iInputStatus.RestoreFrom(oldStatus);\n\n        resultStream.close();\n\n        RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment, resultStream.toString()));\n    }\n  }\n\n  class LispDefaultTokenizer extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentTokenizer = aEnvironment.iDefaultTokenizer;\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispCommonLispTokenizer extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : LispCommonLispTokenizer\");//TODO FIXME\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispXmlTokenizer extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentTokenizer = aEnvironment.iXmlTokenizer;\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispExplodeTag extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr out = new LispPtr();\n      out.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n      LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,out,1);\n\n      String str = out.Get().String();\n      int strInd = 0;\n      strInd++;\n      if (str.charAt(strInd) != '<')\n      {\n        RESULT(aEnvironment, aStackTop).Set(out.Get());\n        return;\n      }\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str.charAt(strInd) == '<',1);\n      strInd++;\n      String type = \"\\\"Open\\\"\";\n\n      if (str.charAt(strInd) == '/')\n      {\n        type = \"\\\"Close\\\"\";\n        strInd++;\n      }\n      String tag = new String();\n\n      tag = tag + \"\\\"\";\n      while (LispTokenizer.IsAlpha(str.charAt(strInd)))\n      {\n        char c = str.charAt(strInd);\n        strInd++;\n        if (c >= 'a' && c <= 'z')\n            c = (char)(c + ('A'-'a'));\n        tag = tag + c;\n      }\n      tag = tag + \"\\\"\";\n\n      LispObject info = null;\n\n      while (str.charAt(strInd) == ' ') strInd++;\n      while (str.charAt(strInd) != '>' && str.charAt(strInd) != '/')\n      {\n        String name = new String();\n        name = name + \"\\\"\";\n\n        while (LispTokenizer.IsAlpha(str.charAt(strInd)))\n        {\n            char c = str.charAt(strInd);\n            strInd++;\n            if (c >= 'a' && c <= 'z')\n                c = (char)(c + ('A'-'a'));\n            name = name + c;\n        }\n        name = name + \"\\\"\";\n        LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str.charAt(strInd) == '=',1);\n        strInd++;\n        LispError.CHK_ARG_CORE(aEnvironment,aStackTop,str.charAt(strInd) == '\\\"',1);\n        String value = new String();\n\n        value = value + (str.charAt(strInd));\n        strInd++;\n        while (str.charAt(strInd) != '\\\"')\n        {\n            value = value + (str.charAt(strInd));\n            strInd++;\n        }\n        value = value + (str.charAt(strInd));\n        strInd++;\n\n//printf(\"[%s], [%s]\\n\",name.String(),value.String());\n        {\n          LispObject ls = LispAtom.New(aEnvironment,\"List\");\n          LispObject nm = LispAtom.New(aEnvironment,name);\n          LispObject vl = LispAtom.New(aEnvironment,value);\n          nm.Next().Set(vl);\n          ls.Next().Set(nm);\n          LispObject newinfo =  LispSubList.New(ls);\n          newinfo.Next().Set(info);\n          info = newinfo;\n        }\n        while (str.charAt(strInd) == ' ') strInd++;\n\n//printf(\"End is %c\\n\",str[0]);\n    }\n    if (str.charAt(strInd) == '/')\n    {\n      type = \"\\\"OpenClose\\\"\";\n      strInd++;\n      while (str.charAt(strInd) == ' ') strInd++;\n    }\n\n    {\n      LispObject ls = LispAtom.New(aEnvironment,\"List\");\n      ls.Next().Set(info);\n      info = LispSubList.New(ls);\n    }\n\n    LispObject xm = LispAtom.New(aEnvironment,\"XmlTag\");\n    LispObject tg = LispAtom.New(aEnvironment,tag);\n    LispObject tp = LispAtom.New(aEnvironment,type);\n    info.Next().Set(tp);\n    tg.Next().Set(info);\n    xm.Next().Set(tg);\n    RESULT(aEnvironment, aStackTop).Set(LispSubList.New(xm));\n\n    }\n  }\n\n  class YacasBuiltinAssoc extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      // key to find\n      LispPtr key = new LispPtr();\n      key.Set(ARGUMENT(aEnvironment, aStackTop, 1).Get());\n\n      // assoc-list to find it in\n      LispPtr list = new LispPtr();\n      list.Set(ARGUMENT(aEnvironment, aStackTop, 2).Get());\n\n      LispObject t;\n\n      //Check that it is a compound object\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,list.Get().SubList() != null, 2);\n      t = list.Get().SubList().Get();\n      LispError.CHK_ARG_CORE(aEnvironment,aStackTop,t != null, 2);\n      t = t.Next().Get();\n\n      while (t != null)\n      {\n        if (t.SubList() != null)\n        {\n          LispObject sub = t.SubList().Get();\n          if (sub != null)\n          {\n            sub = sub.Next().Get();\n            LispPtr temp = new LispPtr();\n            temp.Set(sub);\n            if(LispStandard.InternalEquals(aEnvironment,key,temp))\n            {\n              RESULT(aEnvironment, aStackTop).Set(t);\n              return;\n            }\n          }\n        }\n        t = t.Next().Get();\n      }\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"Empty\"));\n    }\n  }\n\n  class LispCurrentFile extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,aEnvironment.HashTable().LookUpStringify(aEnvironment.iInputStatus.FileName())));\n    }\n  }\n\n  class LispCurrentLine extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      RESULT(aEnvironment, aStackTop).Set(LispAtom.New(aEnvironment,\"\"+aEnvironment.iInputStatus.LineNumber()));\n    }\n  }\n\n  class LispBackQuote extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BackQuoteBehaviour behaviour = new BackQuoteBehaviour(aEnvironment);\n      LispPtr result = new LispPtr();\n      LispStandard.InternalSubstitute(result, ARGUMENT(aEnvironment, aStackTop,  1), behaviour);\n      aEnvironment.iEvaluator.Eval(aEnvironment, RESULT(aEnvironment, aStackTop), result);\n    }\n  }\n\n  class LispDumpBigNumberDebugInfo extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      BigNumber x = GetNumber(aEnvironment, aStackTop, 1);\n      x.DumpDebugInfo(aEnvironment.iCurrentOutput);\n      LispStandard.InternalTrue(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispInDebugMode extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispStandard.InternalFalse(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispDebugFile extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      throw new Exception(\"Cannot call DebugFile in non-debug version of Yacas\");\n    }\n  }\n\n  class LispDebugLine extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      throw new Exception(\"Cannot call DebugLine in non-debug version of Yacas\");\n    }\n  }\n\n  class interpreter extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      RESULT(aEnvironment,aStackTop).Set(LispAtom.New(aEnvironment,\"\\\"jyacas\\\"\"));\n    }\n  }\n\n  class LispVersion extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      RESULT(aEnvironment,aStackTop).Set(LispAtom.New(aEnvironment,\"\\\"\"+CVersion.VERSION+\"\\\"\"));\n    }\n  }\n\n\n  class LispExit extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      Runtime.getRuntime().exit(0);\n    }\n  }\n\n  class LispExitRequested extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispStandard.InternalFalse(aEnvironment,RESULT(aEnvironment, aStackTop));\n    }\n  }\n\n  class LispHistorySize extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : LispHistorySize\");//TODO FIXME\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispStackSize extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : LispStackSize\");//TODO FIXME\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispIsPromptShown extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : LispIsPromptShown\");//TODO FIXME\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispReadCmdLineString extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      aEnvironment.iCurrentOutput.write(\"Function not yet implemented : LispReadCmdLineString\");//TODO FIXME\n      throw new YacasException(\"Function not yet supported\");\n    }\n  }\n\n  class LispTime extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      long starttime = System.currentTimeMillis();\n      LispPtr res = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, res, ARGUMENT(aEnvironment,aStackTop,1));\n      long endtime = System.currentTimeMillis();\n      double timeDiff;\n      timeDiff = endtime-starttime;\n      timeDiff /= 1000.0;\n      RESULT(aEnvironment,aStackTop).Set(LispAtom.New(aEnvironment,\"\"+timeDiff));\n    }\n  }\n\n  class LispFileSize extends YacasEvalCaller\n  {\n    @Override\n    public void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception\n    {\n      LispPtr fnameObject = new LispPtr();\n      fnameObject.Set(ARGUMENT(aEnvironment,aStackTop,1).Get());\n      LispError.CHK_ISSTRING_CORE(aEnvironment,aStackTop,fnameObject,1);\n      String fname = LispStandard.InternalUnstringify(fnameObject.Get().String());\n\n\n\n      long fileSize = 0;\n      InputStatus oldstatus = new InputStatus(aEnvironment.iInputStatus);\n      aEnvironment.iInputStatus.SetTo(fname);\n      try {\n          File f = new File(fname);\n          LispError.Check(f.exists(), LispError.KLispErrFileNotFound);\n          fileSize = f.length();\n      } catch (Exception e) {\n        throw e;\n      } finally {\n        aEnvironment.iInputStatus.RestoreFrom(oldstatus);\n      }\n\n      RESULT(aEnvironment,aStackTop).Set(LispAtom.New(aEnvironment,\"\"+fileSize));\n    }\n  }\n\n\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/ParsedObject.java",
    "content": "package net.sf.yacas;\n\n\nclass ParsedObject\n{\n  public ParsedObject(InfixParser aParser)\n  {\n    iParser = aParser;\n    iError = false;\n    iEndOfFile = false;\n    iLookAhead = null;\n  }\n  public void Parse() throws Exception\n  {\n    ReadToken();\n    if (iEndOfFile)\n    {\n        iResult.Set(iParser.iEnvironment.iEndOfFile.Copy(true));\n        return;\n    }\n\n    ReadExpression(InfixPrinter.KMaxPrecedence);  // least precedence\n\n    if (iLookAhead != iParser.iEnvironment.iEndStatement.String())\n    {\n      Fail();\n    }\n    if (iError)\n    {\n      while (iLookAhead.length() > 0 && iLookAhead != iParser.iEnvironment.iEndStatement.String())\n      {\n        ReadToken();\n      }\n    }\n\n    if (iError)\n    {\n      iResult.Set(null);\n    }\n    LispError.Check(!iError,LispError.KLispErrInvalidExpression);\n  }\n  void ReadToken() throws Exception\n  {\n    // Get token.\n    iLookAhead = iParser.iTokenizer.NextToken(iParser.iInput,\n                                              iParser.iEnvironment.HashTable());\n    if (iLookAhead.length() == 0)\n        iEndOfFile=true;\n  }\n  void MatchToken(String aToken) throws Exception\n  {\n    if (aToken != iLookAhead)\n      Fail();\n    ReadToken();\n  }\n  void ReadExpression(int depth) throws Exception\n  {\n    ReadAtom();\n\n    for(;;)\n    {\n        //Handle special case: a[b]. a is matched with lowest precedence!!\n        if (iLookAhead == iParser.iEnvironment.iProgOpen.String())\n        {\n            // Match opening bracket\n            MatchToken(iLookAhead);\n            // Read \"index\" argument\n            ReadExpression(InfixPrinter.KMaxPrecedence);\n            // Match closing bracket\n            if (iLookAhead != iParser.iEnvironment.iProgClose.String())\n            {\n                LispError.RaiseError(\"Expecting a ] close bracket for program block, but got \"+iLookAhead+\" instead\");\n                return;\n            }\n            MatchToken(iLookAhead);\n            // Build into Ntn(...)\n            String theOperator = iParser.iEnvironment.iNth.String();\n            InsertAtom(theOperator);\n            Combine(2);\n        }\n        else\n        {\n            LispInFixOperator op = iParser.iInfixOperators.get(iLookAhead);\n            if (op == null)\n            {\n//printf(\"op [%s]\\n\",iLookAhead.String());\n              if (LispTokenizer.IsSymbolic(iLookAhead.charAt(0)))\n              {\n                int origlen = iLookAhead.length();\n                int len = origlen;\n//printf(\"IsSymbolic, len=%d\\n\",len);\n\n                while (len>1)\n                {\n                  len--;\n                  String lookUp =\n                    iParser.iEnvironment.HashTable().LookUp(iLookAhead.substring(0,len));\n\n//printf(\"trunc %s\\n\",lookUp.String());\n                  op = iParser.iInfixOperators.get(lookUp);\n//if (op) printf(\"FOUND\\n\");\n                  if (op != null)\n                  {\nString toLookUp = iLookAhead.substring(len,origlen);\n                    String lookUpRight =\n                      iParser.iEnvironment.HashTable().LookUp(toLookUp);\n\n//printf(\"right: %s (%d)\\n\",lookUpRight.String(),origlen-len);\n\n                    if (iParser.iPrefixOperators.get(lookUpRight) != null)\n                    {\n//printf(\"ACCEPT %s\\n\",lookUp.String());\n                      iLookAhead = lookUp;\n                      LispInput input = iParser.iInput;\n                      int newPos = input.Position()-(origlen-len);\n                      input.SetPosition(newPos);\n                      break;\n                    }\n                    else op=null;\n                  }\n                }\n                if (op == null) return;\n              }\n              else\n              {\n                return;\n              }\n\n\n\n\n//              return;\n            }\n            if (depth < op.iPrecedence)\n                return;\n            int upper=op.iPrecedence;\n            if (op.iRightAssociative == 0)\n                upper--;\n            GetOtherSide(2,upper);\n        }\n    }\n  }\n  void ReadAtom() throws Exception\n  {\n    LispInFixOperator op;\n    // Parse prefix operators\n    op = iParser.iPrefixOperators.get(iLookAhead);\n    if (op != null)\n    {\n        String theOperator = iLookAhead;\n        MatchToken(iLookAhead);\n        {\n            ReadExpression(op.iPrecedence);\n            InsertAtom(theOperator);\n            Combine(1);\n        }\n    }\n    // Else parse brackets\n    else if (iLookAhead == iParser.iEnvironment.iBracketOpen.String())\n    {\n        MatchToken(iLookAhead);\n        ReadExpression(InfixPrinter.KMaxPrecedence);  // least precedence\n        MatchToken(iParser.iEnvironment.iBracketClose.String());\n    }\n    //Parse lists\n    else if (iLookAhead == iParser.iEnvironment.iListOpen.String())\n    {\n        int nrargs=0;\n        MatchToken(iLookAhead);\n        while (iLookAhead != iParser.iEnvironment.iListClose.String())\n        {\n            ReadExpression(InfixPrinter.KMaxPrecedence);  // least precedence\n            nrargs++;\n\n            if (iLookAhead == iParser.iEnvironment.iComma.String())\n            {\n                MatchToken(iLookAhead);\n            }\n            else if (iLookAhead != iParser.iEnvironment.iListClose.String())\n            {\n                LispError.RaiseError(\"Expecting a } close bracket for a list, but got \"+iLookAhead+\" instead\");\n                return;\n            }\n        }\n        MatchToken(iLookAhead);\n        String theOperator = iParser.iEnvironment.iList.String();\n        InsertAtom(theOperator);\n        Combine(nrargs);\n\n    }\n    // Parse prog bodies\n    else if (iLookAhead == iParser.iEnvironment.iProgOpen.String())\n    {\n        int nrargs=0;\n\n        MatchToken(iLookAhead);\n        while (iLookAhead != iParser.iEnvironment.iProgClose.String())\n        {\n            ReadExpression(InfixPrinter.KMaxPrecedence);  // least precedence\n            nrargs++;\n\n            if (iLookAhead == iParser.iEnvironment.iEndStatement.String())\n            {\n                MatchToken(iLookAhead);\n            }\n            else\n            {\n                LispError.RaiseError(\"Expecting ; end of statement in program block, but got \"+iLookAhead+\" instead\");\n                return;\n            }\n        }\n        MatchToken(iLookAhead);\n        String theOperator = iParser.iEnvironment.iProg.String();\n        InsertAtom(theOperator);\n\n        Combine(nrargs);\n    }\n    // Else we have an atom.\n    else\n    {\n        String theOperator = iLookAhead;\n        MatchToken(iLookAhead);\n\n        int nrargs=-1;\n        if (iLookAhead == iParser.iEnvironment.iBracketOpen.String())\n        {\n            nrargs=0;\n            MatchToken(iLookAhead);\n            while (iLookAhead != iParser.iEnvironment.iBracketClose.String())\n            {\n                ReadExpression(InfixPrinter.KMaxPrecedence);  // least precedence\n                nrargs++;\n\n                if (iLookAhead == iParser.iEnvironment.iComma.String())\n                {\n                    MatchToken(iLookAhead);\n                }\n                else if (iLookAhead != iParser.iEnvironment.iBracketClose.String())\n                {\n                    LispError.RaiseError(\"Expecting ) closing bracket for sub-expression, but got \"+iLookAhead+\" instead\");\n                    return;\n                }\n            }\n            MatchToken(iLookAhead);\n\n            op = iParser.iBodiedOperators.get(theOperator);\n            if (op != null)\n            {\n                ReadExpression(op.iPrecedence); // InfixPrinter.KMaxPrecedence\n                nrargs++;\n            }\n        }\n        InsertAtom(theOperator);\n        if (nrargs>=0)\n            Combine(nrargs);\n\n    }\n\n    // Parse postfix operators\n\n    while ((op = iParser.iPostfixOperators.get(iLookAhead)) != null)\n    {\n        InsertAtom(iLookAhead);\n        MatchToken(iLookAhead);\n        Combine(1);\n    }\n  }\n  void GetOtherSide(int aNrArgsToCombine, int depth) throws Exception\n  {\n    String theOperator = iLookAhead;\n    MatchToken(iLookAhead);\n    ReadExpression(depth);\n    InsertAtom(theOperator);\n    Combine(aNrArgsToCombine);\n  }\n  void Combine(int aNrArgsToCombine) throws Exception\n  {\n    LispPtr subList = new LispPtr();\n    subList.Set(LispSubList.New(iResult.Get()));\n    LispIterator iter = new LispIterator(iResult);\n    int i;\n    for (i=0;i<aNrArgsToCombine;i++)\n    {\n      if (iter.GetObject() == null)\n      {\n        Fail();\n        return;\n      }\n      iter.GoNext();\n    }\n    if (iter.GetObject() == null)\n    {\n      Fail();\n      return;\n    }\n    subList.Get().Next().Set(iter.GetObject().Next().Get());\n    iter.GetObject().Next().Set(null);\n\n    LispStandard.InternalReverseList(subList.Get().SubList().Get().Next(),\n                     subList.Get().SubList().Get().Next());\n    iResult.Set(subList.Get());\n  }\n  void InsertAtom(String aString) throws Exception\n  {\n    LispPtr ptr = new LispPtr();\n    ptr.Set(LispAtom.New(iParser.iEnvironment,aString));\n    ptr.Get().Next().Set(iResult.Get());\n    iResult.Set(ptr.Get());\n  }\n  void Fail()  throws Exception // called when parsing fails, raising an exception\n  {\n    iError = true;\n    if (iLookAhead != null)\n    {\n      LispError.RaiseError(\"Error parsing expression, near token \"+iLookAhead);\n    }\n    LispError.RaiseError(\"Error parsing expression\");\n  }\n\n  InfixParser iParser;\n  boolean iError;\n  boolean iEndOfFile;\n  String iLookAhead;\n\n  public LispPtr iResult =  new LispPtr();\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/PatternClass.java",
    "content": "package net.sf.yacas;\n\n\n/// Wrapper for YacasPatternPredicateBase.\n/// This class allows a YacasPatternPredicateBase to be put in a\n/// LispGenericObject.\nclass PatternClass extends GenericClass\n{\n  public PatternClass(YacasPatternPredicateBase aPatternMatcher)\n  {\n    iPatternMatcher = aPatternMatcher;\n  }\n\n  public boolean Matches(LispEnvironment  aEnvironment, LispPtr aArguments) throws Exception\n  {\n    LispError.LISPASSERT(iPatternMatcher != null);\n    boolean result;\n    result = iPatternMatcher.Matches(aEnvironment, aArguments);\n    return result;\n  }\n  public boolean Matches(LispEnvironment  aEnvironment, LispPtr[] aArguments) throws Exception\n  {\n    LispError.LISPASSERT(iPatternMatcher != null);\n    boolean result;\n    result = iPatternMatcher.Matches(aEnvironment, aArguments);\n    return result;\n  }\n  //From GenericClass\n  @Override\n  public String TypeName()\n  {\n      return \"\\\"Pattern\\\"\";\n  }\n\n  protected YacasPatternPredicateBase iPatternMatcher;\n}\n\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/StdFileInput.java",
    "content": "package net.sf.yacas;\n\n\nimport java.io.*;\n\n\nclass StdFileInput extends StringInput\n{\n    public StdFileInput(String fname, InputStatus status) throws Exception {\n        super(new StringBuffer(), status);\n        \n        FileInputStream stream = new FileInputStream(fname);\n        InputStreamReader reader = new InputStreamReader(stream, \"UTF-8\");\n        int c;\n        while (true) {\n            c = reader.read();\n            if (c == -1) {\n                break;\n            }\n            iString.append((char) c);\n        }\n    }\n    \n  public StdFileInput(InputStream aStream, InputStatus aStatus) throws Exception\n  {\n    super(new StringBuffer(),aStatus);\n    int c;\n    while (true)\n    {\n      c = aStream.read();\n      if (c == -1)\n        break;\n      iString.append((char)c);\n    }\n  }\n\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/StreamGobbler.java",
    "content": "package net.sf.yacas;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\n\nclass StreamGobbler extends Thread {\n\n    private final InputStream is;\n    private final ArrayList<String> strings;\n\n    public StreamGobbler(InputStream is)\n    {\n        this.is = is;\n        this.strings = new ArrayList<>();\n    }\n\n    @Override\n    public void run()\n    {\n        InputStreamReader isr = new InputStreamReader(is);\n        BufferedReader br = new BufferedReader(isr);\n        String line=null;\n        try {\n            while ((line = br.readLine()) != null)\n                strings.add(line);\n        } catch (IOException e) {\n        }\n    }\n\n    public ArrayList<String> shutdown()\n    {\n        try {\n            if (isAlive())\n                interrupt();\n        } finally {\n            return strings;\n        }\n    }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/StringInput.java",
    "content": "package net.sf.yacas;\n\n\nclass StringInput extends LispInput\n{\n  public StringInput(StringBuffer aString, InputStatus aStatus)\n  {\n    super(aStatus);\n    iString = aString;\n    iCurrent = 0;\n  }\n  @Override\n  public char Next() throws Exception\n  {\n    if (iCurrent == iString.length())\n      return '\\0';\n    iCurrent++;\n    char c = iString.charAt(iCurrent-1);\n    if (c == '\\n')\n      iStatus.NextLine();\n    return c;\n  }\n  @Override\n  public char Peek() throws Exception\n  {\n    if (iCurrent == iString.length())\n      return '\\0';\n    return iString.charAt(iCurrent);\n  }\n  @Override\n  public boolean EndOfStream()\n  {\n    return (iCurrent == iString.length());\n  }\n  @Override\n  public int Position()\n  {\n    return iCurrent;\n  }\n  @Override\n  public void SetPosition(int aPosition)\n  {\n    iCurrent = aPosition;\n  }\n\n  StringBuffer iString;\n  int iCurrent;\n}\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/SubstBehaviour.java",
    "content": "package net.sf.yacas;\n\n\n/** Substing one expression for another. The simplest form\n * of substitution\n */\nclass SubstBehaviour implements SubstBehaviourBase\n{\n    public SubstBehaviour(LispEnvironment aEnvironment,LispPtr aToMatch, LispPtr aToReplaceWith)\n    {\n      iEnvironment = aEnvironment;\n      iToMatch = aToMatch;\n      iToReplaceWith = aToReplaceWith;\n    }\n    @Override\n    public boolean Matches(LispPtr aResult, LispPtr aElement) throws Exception\n    {\n      if (LispStandard.InternalEquals(iEnvironment, aElement, iToMatch))\n      {\n          aResult.Set(iToReplaceWith.Get().Copy(false));\n          return true;\n      }\n      return false;\n    }\n    LispEnvironment iEnvironment;\n    LispPtr iToMatch;\n    LispPtr iToReplaceWith;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/SubstBehaviourBase.java",
    "content": "package net.sf.yacas;\n\n\n/** Behaviour for substituting sub-expressions.\n */\ninterface SubstBehaviourBase\n{\n  public boolean Matches(LispPtr aResult, LispPtr aElement) throws Exception;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/UserStackInformation.java",
    "content": "package net.sf.yacas;\n\n\nclass UserStackInformation\n{\n  public UserStackInformation()\n  {\n    iRulePrecedence = -1;\n    iSide = 0;\n  }\n  public LispPtr iOperator;\n  public LispPtr iExpression;\n  public int iRulePrecedence;\n  public int iSide; // 0=pattern, 1=body\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/XmlTokenizer.java",
    "content": "package net.sf.yacas;\n\nclass XmlTokenizer extends LispTokenizer {\n    @Override\n    public String NextToken(LispInput aInput, LispHashTable aHashTable) throws Exception {\n\n        char c;\n\n        if (aInput.EndOfStream())\n            return aHashTable.LookUp(\"\");\n\n        StringBuilder leadingSpaces = new StringBuilder();\n        while (Character.isWhitespace(aInput.Peek()))\n            leadingSpaces.append(aInput.Next());\n\n        if (aInput.EndOfStream())\n            return aHashTable.LookUp(\"\");\n\n        StringBuilder token = new StringBuilder();\n\n        c = aInput.Next();\n        token.append(c);\n\n        if (c == '<') {\n            while (c != '>') {\n                LispError.Check(!aInput.EndOfStream(), LispError.KLispErrCommentToEndOfFile);\n                c = aInput.Next();\n                token.append(c);\n            }\n        } else {\n            while (aInput.Peek() != '<' && !aInput.EndOfStream()) {\n                c = aInput.Next();\n                token.append(c);\n            }\n            leadingSpaces.append(token);\n            token = leadingSpaces;\n        }\n        return aHashTable.LookUp(token.toString());\n    }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/YacasConsole.java",
    "content": "package net.sf.yacas;\n\n\nimport java.awt.Desktop;\nimport java.io.*;\nimport java.net.URI;\nimport java.net.URISyntaxException;\n\npublic class YacasConsole extends Thread\n{\n    static String readLine(InputStream stream) {\n        InputStreamReader reader = new InputStreamReader(stream);\n        StringBuilder line = new StringBuilder();\n        try {\n            int c = reader.read();\n            while (c != '\\n') {\n                line.append((char) c);\n                c = reader.read();\n            }\n        } catch (Exception e) {\n            System.out.println(e.toString());\n        }\n        return line.toString();\n    }\n\n  static boolean quitting = false;\n\n  public static void main(String[] argv) throws IOException\n  {\n    String defaultDirectory = null;\n    String archive = null;\n    String expression = null;\n\n    {\n      java.net.URL detectURL = java.lang.ClassLoader.getSystemResource(\"scripts/yacasinit.ys\");\n\n      if (detectURL != null)\n      {\n        String path = detectURL.getPath();\n        if (path.contains(\"!\"))\n            archive = path.substring(0, path.lastIndexOf('!'));\n      }\n    }\n\n    int i=0;\n    while (i<argv.length)\n    {\n      if (argv[i].equals(\"--rootdir\"))\n      {\n        i++;\n        defaultDirectory = argv[i];\n      }\n      else if (argv[i].equals(\"--archive\"))\n      {\n        i++;\n        archive = argv[i];\n      }\n      else if (argv[i].equals(\"-v\"))\n      {\n        System.out.println(CVersion.VERSION);\n        System.exit(0);\n      }\n      else if (argv[i].equals(\"-i\"))\n      {\n        i++;\n        expression = argv[i];\n      }\n      else\n      {\n        break;\n      }\n      i++;\n    }\n    int scriptsToRun = i;\n\n    Writer out = new OutputStreamWriter(System.out, \"UTF-8\");\n    CYacas yacas = new CYacas(out);\n    yacas.env.iCurrentInput = new CachedStdFileInput(yacas.env.iInputStatus);\n\n    try\n    {\n        if (archive != null) {\n            String zipFileName = archive;\n            java.util.zip.ZipFile z = new java.util.zip.ZipFile(new File(new java.net.URI(zipFileName)));\n            LispStandard.zipFile = z;\n        }\n    }\n    catch(Exception e)\n    {\n      System.out.println(\"Failed to find yacas.jar\"+e.toString());\n    }\n\n\n    if (defaultDirectory != null)\n    {\n      String toEvaluate = \"DefaultDirectory(\\\"\"+defaultDirectory+\"\\\");\";\n      String result = yacas.Evaluate(toEvaluate);\n      if (scriptsToRun == argv.length)\n        System.out.println(\"Out> \"+result);\n    }\n    {\n      String result = yacas.Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n      if (scriptsToRun == argv.length && expression == null)\n        System.out.println(\"Out> \"+result);\n    }\n    if (expression != null)\n    {\n        String result = yacas.Evaluate(expression);\n        return;\n    }\n    if (scriptsToRun < argv.length)\n    {\n      for (;scriptsToRun<argv.length;scriptsToRun++)\n      {\n          yacas.Evaluate(\"Load(\\\"\"+argv[scriptsToRun]+\"\\\");\");\n      }\n      return;\n    }\n\n\n    out.write(\"This is Yacas version '\" + CVersion.VERSION + \"'.\\n\");\n\n    out.write(\"Yacas is Free Software--Free as in Freedom--so you can redistribute Yacas or\\n\");\n    out.write(\"modify it under certain conditions. Yacas comes with ABSOLUTELY NO WARRANTY.\\n\");\n    out.write(\"See the GNU Lesser General Public License (LGPL) version 2.1 or (at your\\n\");\n    out.write(\"discretion) any later version for the full conditions.\\n\");\n    out.write(\"Type ?license or ?licence to see the LGPL version 2.1;\\n\");\n    out.write(\"type ?warranty for warranty info.\\n\");\n    out.write(\"See http://www.yacas.org for more information on yacas\\n\");\n    out.write(\"and documentation.\\n\");\n    out.write(\"Type ?? for help. Or type ?function for help on a function.\\n\\n\");\n\n    out.write(\"To exit Yacas, enter  Exit(); or quit or Ctrl-c.\\n\");\n    //    System.out.println(\"Type 'restart' to restart Yacas.\\n\");\n\n    out.write(\"To see example commands, keep typing Example();\\n\");\n\n    out.write(\"Yacas in Java\\n\");\n\n    while (!quitting) {\n\n        out.write(\"In> \");\n        out.flush();\n        String input = readLine(System.in);\n\n        String rs = \"True\";\n\n        if (input.trim().equals(\"quit\")) {\n            quitting = true;\n        } else if (input.trim().startsWith(\"?\")) {\n            String key = input.trim().substring(1);\n\n            String prefix = \"http://yacas.sourceforge.net/\";\n\n            try {\n                URI uri = new URI(prefix + \"ref.html?\" + key);\n\n                if (key.equals(\"license\") || key.equals(\"licence\"))\n                    uri = new URI(prefix + \"refprogchapter9.html\");\n                else if (key.equals(\"warranty\"))\n                    uri = new URI(prefix + \"refprogchapter9.html#c9s2\");\n                else if (key.equals(\"?\"))\n                    uri = new URI(prefix + \"refmanual.html\");\n\n                try {\n                    Desktop.getDesktop().browse(uri);\n                } catch (IOException e) {\n                    // FIXME: report the error\n                    rs = \"False\";\n                }\n\n            } catch (URISyntaxException e) {\n                // it's a cold night in Hell\n                rs = \"False\";\n            }\n        } else {\n            rs = yacas.Evaluate(input);\n        }\n\n        out.write(\"Out> \" + rs + \"\\n\");\n        out.flush();\n    }\n  }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/YacasEvalCaller.java",
    "content": "package net.sf.yacas;\n\n\nabstract class YacasEvalCaller\n{\n  public abstract void Eval(LispEnvironment aEnvironment,int aStackTop) throws Exception;\n\n  public static LispPtr RESULT(LispEnvironment aEnvironment,int aStackTop) throws Exception\n  {\n    return aEnvironment.iStack.get(aStackTop);\n  }\n  public static LispPtr ARGUMENT(LispEnvironment aEnvironment,int aStackTop, int i)  throws Exception\n  {\n    return aEnvironment.iStack.get(aStackTop+i);\n  }\n\n  public static LispPtr Argument(LispPtr cur, int n) throws Exception\n  {\n      LispError.LISPASSERT(n>=0);\n\n      LispPtr loop = cur;\n      while(n != 0)\n      {\n        n--;\n        loop = loop.Get().Next();\n      }\n      return loop;\n  }\n\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/YacasEvaluator.java",
    "content": "package net.sf.yacas;\n\n// new-style evaluator, passing arguments onto the stack in LispEnvironment\nclass YacasEvaluator extends EvalFuncBase {\n    // FunctionFlags can be orred when passed to the constructor of this function\n\n    static int Function = 0;    // Function: evaluate arguments\n    static int Macro = 1;       // Function: don't evaluate arguments\n    static int Fixed = 0;     // fixed number of arguments\n    static int Variable = 2;  // variable number of arguments\n\n    public YacasEvaluator(YacasEvalCaller aCaller, int aNrArgs, int aFlags) {\n        iCaller = aCaller;\n        iNrArgs = aNrArgs;\n        iFlags = aFlags;\n    }\n\n    @Override\n    public void Evaluate(LispPtr aResult, LispEnvironment aEnvironment, LispPtr aArguments) throws Exception {\n        if ((iFlags & Variable) == 0)\n            LispError.CheckNrArgs(iNrArgs + 1, aArguments, aEnvironment);\n\n        int stacktop = aEnvironment.iStack.size();\n\n        // Push a place holder for the result: push full expression so it is available for error reporting\n        aEnvironment.iStack.add(new LispPtr(aArguments.Get()));\n\n        LispIterator iter = new LispIterator(aArguments);\n        iter.GoNext();\n\n        int i;\n        int nr = iNrArgs;\n\n        if ((iFlags & Variable) != 0) {\n            nr--;\n        }\n\n        // Walk over all arguments, evaluating them as necessary\n        if ((iFlags & Macro) != 0) {\n            for (i = 0; i < nr; i++) {\n                LispError.Check(iter.GetObject() != null, LispError.KLispErrWrongNumberOfArgs);\n                aEnvironment.iStack.add(new LispPtr(iter.GetObject().Copy(false)));\n                iter.GoNext();\n            }\n            if ((iFlags & Variable) != 0) {\n                LispPtr head = new LispPtr();\n                head.Set(aEnvironment.iList.Copy(false));\n                head.Get().Next().Set(iter.GetObject());\n                aEnvironment.iStack.add(new LispPtr(LispSubList.New(head.Get())));\n            }\n        } else {\n            LispPtr arg = new LispPtr();\n            for (i = 0; i < nr; i++) {\n                LispError.Check(iter.GetObject() != null, LispError.KLispErrWrongNumberOfArgs);\n                LispError.Check(iter.Ptr() != null, LispError.KLispErrWrongNumberOfArgs);\n                aEnvironment.iEvaluator.Eval(aEnvironment, arg, iter.Ptr());\n                aEnvironment.iStack.add(new LispPtr(arg.Get()));\n                iter.GoNext();\n            }\n            if ((iFlags & Variable) != 0) {\n\n                LispPtr head = new LispPtr();\n                head.Set(aEnvironment.iList.Copy(false));\n                head.Get().Next().Set(iter.GetObject());\n                LispPtr list = new LispPtr();\n                list.Set(LispSubList.New(head.Get()));\n\n                aEnvironment.iEvaluator.Eval(aEnvironment, arg, list);\n\n                aEnvironment.iStack.add(new LispPtr(arg.Get()));\n            }\n        }\n\n        iCaller.Eval(aEnvironment, stacktop);\n        aResult.Set(aEnvironment.iStack.get(stacktop).Get());\n        aEnvironment.iStack.subList(stacktop, aEnvironment.iStack.size()).clear();\n    }\n    YacasEvalCaller iCaller;\n    int iNrArgs;\n    int iFlags;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/YacasException.java",
    "content": "package net.sf.yacas;\n\n\nclass YacasException extends Exception\n{\n  public YacasException(String message)\n  {\n    super(message);\n  }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/YacasInterpreter.java",
    "content": "package net.sf.yacas;\n\nimport java.io.*;\nimport java.net.*;\nimport java.nio.file.NoSuchFileException;\nimport java.util.zip.*;\n\n/**\n * Use this class in order to access the Yacas interpreter from an external application.\n * Usage:\n * import net.sf.yacas.YacasInterpreter;\n * YacasInterpreter interpreter = new YacasInterpreter();\n * String output1 = interpreter.Evaluate(\"a := 5\");\n * String output2 = interpreter.Evaluate(\"Solve(x*x == a, x)\");\n *\n *\n * @author av\n */\npublic class YacasInterpreter {\n\n    private CYacas yacas;\n\n    /** Creates a new instance of YacasInterpreter */\n    public YacasInterpreter()  throws IOException, ZipException, URISyntaxException {\n        this(new StringWriter());\n    }\n\n    public YacasInterpreter(Writer out) throws IOException, ZipException, URISyntaxException {\n\n        String scriptsDir = \"scripts/\";\n\n        yacas = new CYacas(out);\n\n        URL initURL = yacas.getClass().getClassLoader().getResource(scriptsDir + \"yacasinit.ys\");\n        \n        if (initURL == null)\n            throw new NoSuchFileException(\"yacasinit.ys not found in \" + scriptsDir);\n        \n        String initPath = initURL.getPath();\n\n        if (initPath.lastIndexOf('!') >= 0) {\n            String archive = initPath.substring(0, initPath.lastIndexOf('!'));\n\n            ZipFile z = new ZipFile(new File(new URI(archive)));\n\n            LispStandard.zipFile = z;\n        } else {\n            yacas.Evaluate(\"DefaultDirectory(\\\"\" + scriptsDir + \"\\\");\");\n        }\n\n        yacas.Evaluate(\"Load(\\\"yacasinit.ys\\\");\");\n    }\n\n    /** Use this method to pass an expression to the Yacas interpreter.\n     *  Returns the output of the interpreter.\n     */\n    public String Evaluate(String input) {\n        return yacas.Evaluate(input);\n    }\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/YacasParamMatcherBase.java",
    "content": "package net.sf.yacas;\n\n\n/// Abstract class for matching one argument to a pattern.\nabstract class YacasParamMatcherBase\n{\n    /// Check whether some expression matches to the pattern.\n    /// \\param aEnvironment the underlying Lisp environment.\n    /// \\param aExpression the expression to test.\n    /// \\param arguments (input/output) actual values of the pattern\n    /// variables for \\a aExpression.\n    public abstract boolean ArgumentMatches(LispEnvironment  aEnvironment,\n                                        LispPtr  aExpression,\n                                        LispPtr[]  arguments) throws Exception;\n}\n"
  },
  {
    "path": "jyacas/net/sf/yacas/YacasPatternPredicateBase.java",
    "content": "package net.sf.yacas;\n\n\n/// \\file\n/// Pattern matching code.\n///\n/// General idea: have a class that can match function parameters\n/// to a pattern, check for predicates on the arguments, and return\n/// whether there was a match.\n///\n/// First the pattern is mapped onto the arguments. Then local variables\n/// are set. Then the predicates are called. If they all return true,\n/// Then the pattern matches, and the locals can stay (the body is expected\n/// to use these variables).\n\n\nimport java.util.*;\n\n/// Class that matches function arguments to a pattern.\n/// This class (specifically, the Matches() member function) can match\n/// function parameters to a pattern, check for predicates on the\n/// arguments, and return whether there was a match.\n\nclass YacasPatternPredicateBase\n{\n  /// Constructor.\n  /// \\param aEnvironment the underlying Lisp environment\n  /// \\param aPattern Lisp expression containing the pattern\n  /// \\param aPostPredicate Lisp expression containing the\n  /// postpredicate\n  ///\n  /// The function MakePatternMatcher() is called for every argument\n  /// in \\a aPattern, and the resulting pattern matchers are\n  /// collected in #iParamMatchers. Additionally, \\a aPostPredicate\n  /// is copied, and the copy is added to #iPredicates.\n  public YacasPatternPredicateBase(LispEnvironment  aEnvironment,\n                            LispPtr  aPattern,\n                            LispPtr  aPostPredicate) throws Exception\n  {\n    LispIterator iter = new LispIterator(aPattern);\n\n    while (iter.GetObject() != null)\n    {\n        YacasParamMatcherBase matcher = MakeParamMatcher(aEnvironment,iter.GetObject());\n        LispError.LISPASSERT(matcher!=null);\n        iParamMatchers.add(matcher);\n        iter.GoNext();\n    }\n    LispPtr  post = new LispPtr();\n    post.Set(aPostPredicate.Get());\n    iPredicates.add(post);\n  }\n\n\n  /// Try to match the pattern against \\a aArguments.\n  /// First, every argument in \\a aArguments is matched against the\n  /// corresponding YacasParamMatcherBase in #iParamMatches. If any\n  /// match fails, Matches() returns false. Otherwise, a temporary\n  /// LispLocalFrame is constructed, then SetPatternVariables() and\n  /// CheckPredicates() are called, and then the LispLocalFrame is\n  /// immediately deleted. If CheckPredicates() returns false, this\n  /// function also returns false. Otherwise, SetPatternVariables()\n  /// is called again, but now in the current LispLocalFrame, and\n  /// this function returns true.\n  public boolean Matches(LispEnvironment  aEnvironment, LispPtr  aArguments) throws Exception\n  {\n    int i;\n\n    LispPtr[]  arguments = null;\n    if (iVariables.size() > 0)\n    {\n        arguments = new LispPtr[iVariables.size()];\n        for (i=0;i<iVariables.size();i++)\n        {\n          arguments[i] = new LispPtr();\n        }\n\n    }\n    LispIterator iter = new LispIterator(aArguments);\n\n    for (i=0;i<iParamMatchers.size();i++)\n    {\n        if (iter.GetObject() == null)\n            return false;\n        LispPtr  ptr = iter.Ptr();\n        if (ptr==null)\n            return false;\n        if (!iParamMatchers.get(i).ArgumentMatches(aEnvironment,ptr,arguments))\n        {\n            return false;\n        }\n        iter.GoNext();\n    }\n    if (iter.GetObject() != null)\n        return false;\n\n    {\n        // set the local variables.\n        aEnvironment.PushLocalFrame(false);\n        try\n        {\n          SetPatternVariables(aEnvironment,arguments);\n\n          // do the predicates\n          if (!CheckPredicates(aEnvironment))\n              return false;\n        }\n        catch (Exception e)\n        {\n          throw e;\n        }\n        finally\n        {\n          aEnvironment.PopLocalFrame();\n        }\n    }\n\n    // set the local variables for sure now\n    SetPatternVariables(aEnvironment,arguments);\n\n    return true;\n  }\n\n  /// Try to match the pattern against \\a aArguments.\n  /// This function does the same as Matches(LispEnvironment ,LispPtr ),\n  /// but differs in the type of the arguments.\n  boolean Matches(LispEnvironment  aEnvironment, LispPtr[]  aArguments) throws Exception\n  {\n    int i;\n\n    LispPtr[]  arguments = null;\n    if (iVariables.size() > 0)\n        arguments = new LispPtr[iVariables.size()];\n    for (i=0;i<iVariables.size();i++)\n    {\n      arguments[i] = new LispPtr();\n    }\n\n    for (i=0;i<iParamMatchers.size();i++)\n    {\n        if (!iParamMatchers.get(i).ArgumentMatches(aEnvironment,aArguments[i],arguments))\n        {\n            return false;\n        }\n    }\n\n    {\n        // set the local variables.\n        aEnvironment.PushLocalFrame(false);\n        try\n        {\n          SetPatternVariables(aEnvironment,arguments);\n\n          // do the predicates\n          if (!CheckPredicates(aEnvironment))\n              return false;\n        }\n        catch (Exception e)\n        {\n          throw e;\n        }\n        finally\n        {\n          aEnvironment.PopLocalFrame();\n        }\n    }\n\n    // set the local variables for sure now\n    SetPatternVariables(aEnvironment,arguments);\n    return true;\n  }\n\n  /// Construct a pattern matcher out of a Lisp expression.\n  /// The result of this function depends on the value of \\a aPattern:\n  /// - If \\a aPattern is a number, the corresponding MatchNumber is\n  ///   constructed and returned.\n  /// - If \\a aPattern is an atom, the corresponding MatchAtom is\n  ///   constructed and returned.\n  /// - If \\a aPattern is a list of the form <tt>( _ var )<tt>,\n  ///   where \\c var is an atom, LookUp() is called on \\c var. Then\n  ///   the correspoding MatchVariable is constructed and returned.\n  /// - If \\a aPattern is a list of the form <tt>( _ var expr )<tt>,\n  ///   where \\c var is an atom, LookUp() is called on \\c var. Then,\n  ///   \\a expr is appended to #iPredicates. Finally, the\n  ///   correspoding MatchVariable is constructed and returned.\n  /// - If \\a aPattern is a list of another form, this function\n  ///   calls itself on any of the entries in this list. The\n  ///   resulting YacasParamMatcherBase objects are collected in a\n  ///   MatchSubList, which is returned.\n  /// - Otherwise, this function returns #null.\n  protected YacasParamMatcherBase MakeParamMatcher(LispEnvironment  aEnvironment, LispObject aPattern) throws Exception\n  {\n    if (aPattern == null)\n        return null;\n    if (aPattern.Number(aEnvironment.Precision()) != null)\n    {\n        return new MatchNumber(aPattern.Number(aEnvironment.Precision()));\n    }\n    // Deal with atoms\n    if (aPattern.String() != null)\n    {\n        return new MatchAtom(aPattern.String());\n    }\n\n    // Else it must be a sublist\n    if (aPattern.SubList() != null)\n    {\n        // See if it is a variable template:\n        LispPtr  sublist = aPattern.SubList();\n        LispError.LISPASSERT(sublist != null);\n\n        int num = LispStandard.InternalListLength(sublist);\n\n        // variable matcher here...\n        if (num>1)\n        {\n            LispObject head = sublist.Get();\n            if (head.String() == aEnvironment.HashTable().LookUp(\"_\"))\n            {\n                LispObject second = head.Next().Get();\n                if (second.String() != null)\n                {\n                    int index = LookUp(second.String());\n\n                    // Make a predicate for the type, if needed\n                    if (num>2)\n                    {\n                        LispPtr third = new LispPtr();\n\n                        LispObject predicate = second.Next().Get();\n                        if (predicate.SubList() != null)\n                        {\n                            LispStandard.InternalFlatCopy(third, predicate.SubList());\n                        }\n                        else\n                        {\n                            third.Set(second.Next().Get().Copy(false));\n                        }\n\n                        String str = second.String();\n                        LispObject last = third.Get();\n                        while (last.Next().Get() != null)\n                            last = last.Next().Get();\n\n                        last.Next().Set(LispAtom.New(aEnvironment,str));\n\n                        LispPtr pred = new LispPtr();\n                        pred.Set(LispSubList.New(third.Get()));\n\n                        iPredicates.add(pred);\n                    }\n                    return new MatchVariable(index);\n                }\n            }\n        }\n\n        YacasParamMatcherBase[] matchers = new YacasParamMatcherBase[num];\n\n        int i;\n        LispIterator iter = new LispIterator(sublist);\n        for (i=0;i<num;i++)\n        {\n            matchers[i] = MakeParamMatcher(aEnvironment,iter.GetObject());\n            LispError.LISPASSERT(matchers[i] != null);\n            iter.GoNext();\n        }\n        return new MatchSubList(matchers, num);\n    }\n\n    return null;\n  }\n\n  /// Look up a variable name in #iVariables\n  /// \\returns index in #iVariables array where \\a aVariable\n  /// appears.\n  ///\n  /// If \\a aVariable is not in #iVariables, it is added.\n  protected int LookUp(String aVariable)\n  {\n    int i;\n    for (i=0;i<iVariables.size();i++)\n    {\n        if (iVariables.get(i) == aVariable)\n        {\n            return i;\n        }\n    }\n    iVariables.add(aVariable);\n    return iVariables.size()-1;\n  }\n\n  /// Set local variables corresponding to the pattern variables.\n  /// This function goes through the #iVariables array. A local\n  /// variable is made for every entry in the array, and the\n  /// corresponding argument is assigned to it.\n  protected void SetPatternVariables(LispEnvironment  aEnvironment, LispPtr[]  arguments) throws Exception\n  {\n    int i;\n    for (i=0;i<iVariables.size();i++)\n    {\n        // set the variable to the new value\n        aEnvironment.NewLocal(iVariables.get(i),arguments[i].Get());\n    }\n  }\n\n  /// Check whether all predicates are true.\n  /// This function goes through all predicates in #iPredicates, and\n  /// evaluates them. It returns #false if at least one\n  /// of these results IsFalse(). An error is raised if any result\n  /// neither IsTrue() nor IsFalse().\n  protected boolean CheckPredicates(LispEnvironment  aEnvironment) throws Exception\n  {\n    int i;\n    for (i=0;i<iPredicates.size();i++)\n    {\n      LispPtr pred = new LispPtr();\n      aEnvironment.iEvaluator.Eval(aEnvironment, pred, iPredicates.get(i));\n      if (LispStandard.IsFalse(aEnvironment, pred))\n      {\n        return false;\n      }\n\n\n      // If the result is not False, it should be True, else probably something is wrong (the expression returned unevaluated)\n      boolean isTrue = LispStandard.IsTrue(aEnvironment, pred);\n      if (!isTrue)\n      {\n        //TODO this is probably not the right way to generate an error, should we perhaps do a full throw new YacasException here?\n        String strout;\n        aEnvironment.iCurrentOutput.write(\"The predicate\\n\\t\");\n        strout = LispStandard.PrintExpression(iPredicates.get(i), aEnvironment, 60);\n        aEnvironment.iCurrentOutput.write(strout);\n        aEnvironment.iCurrentOutput.write(\"\\nevaluated to\\n\\t\");\n        strout = LispStandard.PrintExpression(pred, aEnvironment, 60);\n        aEnvironment.iCurrentOutput.write(strout);\n        aEnvironment.iCurrentOutput.write(\"\\n\");\n\n        LispError.Check(isTrue,LispError.KLispErrNonBooleanPredicateInPattern);\n      }\n    }\n    return true;\n  }\n\n  /// List of parameter matches, one for every parameter.\n  protected ArrayList<YacasParamMatcherBase> iParamMatchers = new ArrayList<>();\n\n  /// List of variables appearing in the pattern.\n  protected ArrayList<String> iVariables = new ArrayList<>();\n\n  /// List of predicates which need to be true for a match.\n  protected ArrayList<LispPtr> iPredicates = new ArrayList<>();\n}\n\n"
  },
  {
    "path": "jyacas/net/sf/yacas/YacasTest.java",
    "content": "package net.sf.yacas;\n\nimport java.io.File;\nimport java.io.StringWriter;\nimport java.util.ArrayList;\nimport org.junit.Assert;\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.junit.runners.Parameterized;\nimport org.junit.runners.Parameterized.Parameters;\n\n@RunWith(Parameterized.class)\npublic class YacasTest {\n\n    private final String fname;\n\n    public YacasTest(String fname) {\n        this.fname = fname;\n    }\n\n    @Test\n    public void test() {\n        StringWriter output = new StringWriter();\n\n        try {\n            YacasInterpreter yacas = new YacasInterpreter(output);\n\n            yacas.Evaluate(\"Load(\\\"tests/\"+fname+\"\\\");\");\n\n            if (output.toString().contains(\"******************\")) {\n                System.err.print(output.toString());\n                Assert.fail(output.toString());\n            }\n        } catch (Exception e) {\n            System.err.print(\"Error: \" + e.getMessage());\n            Assert.fail(e.getMessage());\n        }\n    }\n\n    @Parameters\n    public static ArrayList<String[]> data() {\n\n        ArrayList<String[]> data = new ArrayList<>();\n\n        File tests_dir = new File(\"tests\");\n\n        File[] files = tests_dir.listFiles();\n\n        for (File f: files) {\n            if (f.isFile()) {\n                String fname = f.getName();\n                if (fname.endsWith(\".yts\")) {\n                    String[] a = {fname};\n                    data.add(a);\n                }\n            }\n        }\n\n        return data;\n    }\n}\n"
  },
  {
    "path": "man/CMakeLists.txt",
    "content": "if (${CMAKE_SYSTEM_NAME} STREQUAL \"Linux\")\n    find_package (UnixCommands REQUIRED)\n    find_program (RST2MAN rst2man)\n\n    if (RST2MAN)\n        add_custom_target (man ALL COMMAND ${RST2MAN} ${PROJECT_SOURCE_DIR}/man/yacas.1.rst | ${GZIP} -9 > ${PROJECT_BINARY_DIR}/yacas.1.gz)\n        install (FILES ${PROJECT_BINARY_DIR}/yacas.1.gz DESTINATION share/man/man1 COMPONENT app)\n    endif ()\nendif ()"
  },
  {
    "path": "man/yacas.1.rst",
    "content": "=====\nyacas\n=====\n-----------------------------------\nYet Another Computer Algebra System\n-----------------------------------\n\n:Manual section: 1\n\nSynopsis\n========\n\nyacas [*OPTION*] [*FILE*]\n\nyacas **-i** *COMMAND*\n\nDescription\n===========\n\nYacas is an easy to use, general purpose Computer Algebra System, a program for\nsymbolic manipulation of mathematical expressions. It uses its own programming\nlanguage designed for symbolic as well as arbitrary-precision numerical\ncomputations. The system has a library of scripts that implement many of the\nsymbolic algebra operations; new algorithms can be easily added to the library.\nYacas comes with extensive documentation covering the scripting language, the\nfunctionality that is already implemented in the system, and the algorithms we\nused.\n\nOptions\n=======\n\n**-d**\n  print default scripts path and exit\n\n**-v**\n  print yacas version and exit\n\n**-p**\n  plain (dumb-terminal) mode\n\n**-c**\n  do not print prompt\n\n**-b**\n  do not print banner\n\n**-i** *COMMAND*\n  execute COMMAND and exit\n\nOther Documentation\n===================\n\nFull documentation at: `<https://yacas.readthedocs.io/>`_\n\n"
  },
  {
    "path": "papers/llncs.cls",
    "content": "% LLNCS DOCUMENT CLASS -- version 2.13 (28-Jan-2002)\n% Springer Verlag LaTeX2e support for Lecture Notes in Computer Science\n%\n%%\n%% \\CharacterTable\n%%  {Upper-case    \\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z\n%%   Lower-case    \\a\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m\\n\\o\\p\\q\\r\\s\\t\\u\\v\\w\\x\\y\\z\n%%   Digits        \\0\\1\\2\\3\\4\\5\\6\\7\\8\\9\n%%   Exclamation   \\!     Double quote  \\\"     Hash (number) \\#\n%%   Dollar        \\$     Percent       \\%     Ampersand     \\&\n%%   Acute accent  \\'     Left paren    \\(     Right paren   \\)\n%%   Asterisk      \\*     Plus          \\+     Comma         \\,\n%%   Minus         \\-     Point         \\.     Solidus       \\/\n%%   Colon         \\:     Semicolon     \\;     Less than     \\<\n%%   Equals        \\=     Greater than  \\>     Question mark \\?\n%%   Commercial at \\@     Left bracket  \\[     Backslash     \\\\\n%%   Right bracket \\]     Circumflex    \\^     Underscore    \\_\n%%   Grave accent  \\`     Left brace    \\{     Vertical bar  \\|\n%%   Right brace   \\}     Tilde         \\~}\n%%\n\\NeedsTeXFormat{LaTeX2e}[1995/12/01]\n\\ProvidesClass{llncs}[2002/01/28 v2.13\n^^J LaTeX document class for Lecture Notes in Computer Science]\n% Options\n\\let\\if@envcntreset\\iffalse\n\\DeclareOption{envcountreset}{\\let\\if@envcntreset\\iftrue}\n\\DeclareOption{citeauthoryear}{\\let\\citeauthoryear=Y}\n\\DeclareOption{oribibl}{\\let\\oribibl=Y}\n\\let\\if@custvec\\iftrue\n\\DeclareOption{orivec}{\\let\\if@custvec\\iffalse}\n\\let\\if@envcntsame\\iffalse\n\\DeclareOption{envcountsame}{\\let\\if@envcntsame\\iftrue}\n\\let\\if@envcntsect\\iffalse\n\\DeclareOption{envcountsect}{\\let\\if@envcntsect\\iftrue}\n\\let\\if@runhead\\iffalse\n\\DeclareOption{runningheads}{\\let\\if@runhead\\iftrue}\n\n\\let\\if@openbib\\iffalse\n\\DeclareOption{openbib}{\\let\\if@openbib\\iftrue}\n\n% languages\n\\let\\switcht@@therlang\\relax\n\\def\\ds@deutsch{\\def\\switcht@@therlang{\\switcht@deutsch}}\n\\def\\ds@francais{\\def\\switcht@@therlang{\\switcht@francais}}\n\n\\DeclareOption*{\\PassOptionsToClass{\\CurrentOption}{article}}\n\n\\ProcessOptions\n\n\\LoadClass[twoside]{article}\n\\RequirePackage{multicol} % needed for the list of participants, index\n\n\\setlength{\\textwidth}{12.2cm}\n\\setlength{\\textheight}{19.3cm}\n\\renewcommand\\@pnumwidth{2em}\n\\renewcommand\\@tocrmarg{3.5em}\n%\n\\def\\@dottedtocline#1#2#3#4#5{%\n  \\ifnum #1>\\c@tocdepth \\else\n    \\vskip \\z@ \\@plus.2\\p@\n    {\\leftskip #2\\relax \\rightskip \\@tocrmarg \\advance\\rightskip by 0pt plus 2cm\n               \\parfillskip -\\rightskip \\pretolerance=10000\n     \\parindent #2\\relax\\@afterindenttrue\n     \\interlinepenalty\\@M\n     \\leavevmode\n     \\@tempdima #3\\relax\n     \\advance\\leftskip \\@tempdima \\null\\nobreak\\hskip -\\leftskip\n     {#4}\\nobreak\n     \\leaders\\hbox{$\\m@th\n        \\mkern \\@dotsep mu\\hbox{.}\\mkern \\@dotsep\n        mu$}\\hfill\n     \\nobreak\n     \\hb@xt@\\@pnumwidth{\\hfil\\normalfont \\normalcolor #5}%\n     \\par}%\n  \\fi}\n%\n\\def\\switcht@albion{%\n\\def\\abstractname{Abstract.}\n\\def\\ackname{Acknowledgement.}\n\\def\\andname{and}\n\\def\\lastandname{\\unskip, and}\n\\def\\appendixname{Appendix}\n\\def\\chaptername{Chapter}\n\\def\\claimname{Claim}\n\\def\\conjecturename{Conjecture}\n\\def\\contentsname{Table of Contents}\n\\def\\corollaryname{Corollary}\n\\def\\definitionname{Definition}\n\\def\\examplename{Example}\n\\def\\exercisename{Exercise}\n\\def\\figurename{Fig.}\n\\def\\keywordname{{\\bf Key words:}}\n\\def\\indexname{Index}\n\\def\\lemmaname{Lemma}\n\\def\\contriblistname{List of Contributors}\n\\def\\listfigurename{List of Figures}\n\\def\\listtablename{List of Tables}\n\\def\\mailname{{\\it Correspondence to\\/}:}\n\\def\\noteaddname{Note added in proof}\n\\def\\notename{Note}\n\\def\\partname{Part}\n\\def\\problemname{Problem}\n\\def\\proofname{Proof}\n\\def\\propertyname{Property}\n\\def\\propositionname{Proposition}\n\\def\\questionname{Question}\n\\def\\remarkname{Remark}\n\\def\\seename{see}\n\\def\\solutionname{Solution}\n\\def\\subclassname{{\\it Subject Classifications\\/}:}\n\\def\\tablename{Table}\n\\def\\theoremname{Theorem}}\n\\switcht@albion\n% Names of theorem like environments are already defined\n% but must be translated if another language is chosen\n%\n% French section\n\\def\\switcht@francais{%\\typeout{On parle francais.}%\n \\def\\abstractname{R\\'esum\\'e.}%\n \\def\\ackname{Remerciements.}%\n \\def\\andname{et}%\n \\def\\lastandname{ et}%\n \\def\\appendixname{Appendice}\n \\def\\chaptername{Chapitre}%\n \\def\\claimname{Pr\\'etention}%\n \\def\\conjecturename{Hypoth\\`ese}%\n \\def\\contentsname{Table des mati\\`eres}%\n \\def\\corollaryname{Corollaire}%\n \\def\\definitionname{D\\'efinition}%\n \\def\\examplename{Exemple}%\n \\def\\exercisename{Exercice}%\n \\def\\figurename{Fig.}%\n \\def\\keywordname{{\\bf Mots-cl\\'e:}}\n \\def\\indexname{Index}\n \\def\\lemmaname{Lemme}%\n \\def\\contriblistname{Liste des contributeurs}\n \\def\\listfigurename{Liste des figures}%\n \\def\\listtablename{Liste des tables}%\n \\def\\mailname{{\\it Correspondence to\\/}:}\n \\def\\noteaddname{Note ajout\\'ee \\`a l'\\'epreuve}%\n \\def\\notename{Remarque}%\n \\def\\partname{Partie}%\n \\def\\problemname{Probl\\`eme}%\n \\def\\proofname{Preuve}%\n \\def\\propertyname{Caract\\'eristique}%\n%\\def\\propositionname{Proposition}%\n \\def\\questionname{Question}%\n \\def\\remarkname{Remarque}%\n \\def\\seename{voir}\n \\def\\solutionname{Solution}%\n \\def\\subclassname{{\\it Subject Classifications\\/}:}\n \\def\\tablename{Tableau}%\n \\def\\theoremname{Th\\'eor\\`eme}%\n}\n%\n% German section\n\\def\\switcht@deutsch{%\\typeout{Man spricht deutsch.}%\n \\def\\abstractname{Zusammenfassung.}%\n \\def\\ackname{Danksagung.}%\n \\def\\andname{und}%\n \\def\\lastandname{ und}%\n \\def\\appendixname{Anhang}%\n \\def\\chaptername{Kapitel}%\n \\def\\claimname{Behauptung}%\n \\def\\conjecturename{Hypothese}%\n \\def\\contentsname{Inhaltsverzeichnis}%\n \\def\\corollaryname{Korollar}%\n%\\def\\definitionname{Definition}%\n \\def\\examplename{Beispiel}%\n \\def\\exercisename{\\\"Ubung}%\n \\def\\figurename{Abb.}%\n \\def\\keywordname{{\\bf Schl\\\"usselw\\\"orter:}}\n \\def\\indexname{Index}\n%\\def\\lemmaname{Lemma}%\n \\def\\contriblistname{Mitarbeiter}\n \\def\\listfigurename{Abbildungsverzeichnis}%\n \\def\\listtablename{Tabellenverzeichnis}%\n \\def\\mailname{{\\it Correspondence to\\/}:}\n \\def\\noteaddname{Nachtrag}%\n \\def\\notename{Anmerkung}%\n \\def\\partname{Teil}%\n%\\def\\problemname{Problem}%\n \\def\\proofname{Beweis}%\n \\def\\propertyname{Eigenschaft}%\n%\\def\\propositionname{Proposition}%\n \\def\\questionname{Frage}%\n \\def\\remarkname{Anmerkung}%\n \\def\\seename{siehe}\n \\def\\solutionname{L\\\"osung}%\n \\def\\subclassname{{\\it Subject Classifications\\/}:}\n \\def\\tablename{Tabelle}%\n%\\def\\theoremname{Theorem}%\n}\n\n% Ragged bottom for the actual page\n\\def\\thisbottomragged{\\def\\@textbottom{\\vskip\\z@ plus.0001fil\n\\global\\let\\@textbottom\\relax}}\n\n\\renewcommand\\small{%\n   \\@setfontsize\\small\\@ixpt{11}%\n   \\abovedisplayskip 8.5\\p@ \\@plus3\\p@ \\@minus4\\p@\n   \\abovedisplayshortskip \\z@ \\@plus2\\p@\n   \\belowdisplayshortskip 4\\p@ \\@plus2\\p@ \\@minus2\\p@\n   \\def\\@listi{\\leftmargin\\leftmargini\n               \\parsep 0\\p@ \\@plus1\\p@ \\@minus\\p@\n               \\topsep 8\\p@ \\@plus2\\p@ \\@minus4\\p@\n               \\itemsep0\\p@}%\n   \\belowdisplayskip \\abovedisplayskip\n}\n\n\\frenchspacing\n\\widowpenalty=10000\n\\clubpenalty=10000\n\n\\setlength\\oddsidemargin   {63\\p@}\n\\setlength\\evensidemargin  {63\\p@}\n\\setlength\\marginparwidth  {90\\p@}\n\n\\setlength\\headsep   {16\\p@}\n\n\\setlength\\footnotesep{7.7\\p@}\n\\setlength\\textfloatsep{8mm\\@plus 2\\p@ \\@minus 4\\p@}\n\\setlength\\intextsep   {8mm\\@plus 2\\p@ \\@minus 2\\p@}\n\n\\setcounter{secnumdepth}{2}\n\n\\newcounter {chapter}\n\\renewcommand\\thechapter      {\\@arabic\\c@chapter}\n\n\\newif\\if@mainmatter \\@mainmattertrue\n\\newcommand\\frontmatter{\\cleardoublepage\n            \\@mainmatterfalse\\pagenumbering{Roman}}\n\\newcommand\\mainmatter{\\cleardoublepage\n       \\@mainmattertrue\\pagenumbering{arabic}}\n\\newcommand\\backmatter{\\if@openright\\cleardoublepage\\else\\clearpage\\fi\n      \\@mainmatterfalse}\n\n\\renewcommand\\part{\\cleardoublepage\n                 \\thispagestyle{empty}%\n                 \\if@twocolumn\n                     \\onecolumn\n                     \\@tempswatrue\n                   \\else\n                     \\@tempswafalse\n                 \\fi\n                 \\null\\vfil\n                 \\secdef\\@part\\@spart}\n\n\\def\\@part[#1]#2{%\n    \\ifnum \\c@secnumdepth >-2\\relax\n      \\refstepcounter{part}%\n      \\addcontentsline{toc}{part}{\\thepart\\hspace{1em}#1}%\n    \\else\n      \\addcontentsline{toc}{part}{#1}%\n    \\fi\n    \\markboth{}{}%\n    {\\centering\n     \\interlinepenalty \\@M\n     \\normalfont\n     \\ifnum \\c@secnumdepth >-2\\relax\n       \\huge\\bfseries \\partname~\\thepart\n       \\par\n       \\vskip 20\\p@\n     \\fi\n     \\Huge \\bfseries #2\\par}%\n    \\@endpart}\n\\def\\@spart#1{%\n    {\\centering\n     \\interlinepenalty \\@M\n     \\normalfont\n     \\Huge \\bfseries #1\\par}%\n    \\@endpart}\n\\def\\@endpart{\\vfil\\newpage\n              \\if@twoside\n                \\null\n                \\thispagestyle{empty}%\n                \\newpage\n              \\fi\n              \\if@tempswa\n                \\twocolumn\n              \\fi}\n\n\\newcommand\\chapter{\\clearpage\n                    \\thispagestyle{empty}%\n                    \\global\\@topnum\\z@\n                    \\@afterindentfalse\n                    \\secdef\\@chapter\\@schapter}\n\\def\\@chapter[#1]#2{\\ifnum \\c@secnumdepth >\\m@ne\n                       \\if@mainmatter\n                         \\refstepcounter{chapter}%\n                         \\typeout{\\@chapapp\\space\\thechapter.}%\n                         \\addcontentsline{toc}{chapter}%\n                                  {\\protect\\numberline{\\thechapter}#1}%\n                       \\else\n                         \\addcontentsline{toc}{chapter}{#1}%\n                       \\fi\n                    \\else\n                      \\addcontentsline{toc}{chapter}{#1}%\n                    \\fi\n                    \\chaptermark{#1}%\n                    \\addtocontents{lof}{\\protect\\addvspace{10\\p@}}%\n                    \\addtocontents{lot}{\\protect\\addvspace{10\\p@}}%\n                    \\if@twocolumn\n                      \\@topnewpage[\\@makechapterhead{#2}]%\n                    \\else\n                      \\@makechapterhead{#2}%\n                      \\@afterheading\n                    \\fi}\n\\def\\@makechapterhead#1{%\n% \\vspace*{50\\p@}%\n  {\\centering\n    \\ifnum \\c@secnumdepth >\\m@ne\n      \\if@mainmatter\n        \\large\\bfseries \\@chapapp{} \\thechapter\n        \\par\\nobreak\n        \\vskip 20\\p@\n      \\fi\n    \\fi\n    \\interlinepenalty\\@M\n    \\Large \\bfseries #1\\par\\nobreak\n    \\vskip 40\\p@\n  }}\n\\def\\@schapter#1{\\if@twocolumn\n                   \\@topnewpage[\\@makeschapterhead{#1}]%\n                 \\else\n                   \\@makeschapterhead{#1}%\n                   \\@afterheading\n                 \\fi}\n\\def\\@makeschapterhead#1{%\n% \\vspace*{50\\p@}%\n  {\\centering\n    \\normalfont\n    \\interlinepenalty\\@M\n    \\Large \\bfseries  #1\\par\\nobreak\n    \\vskip 40\\p@\n  }}\n\n\\renewcommand\\section{\\@startsection{section}{1}{\\z@}%\n                       {-18\\p@ \\@plus -4\\p@ \\@minus -4\\p@}%\n                       {12\\p@ \\@plus 4\\p@ \\@minus 4\\p@}%\n                       {\\normalfont\\large\\bfseries\\boldmath\n                        \\rightskip=\\z@ \\@plus 8em\\pretolerance=10000 }}\n\\renewcommand\\subsection{\\@startsection{subsection}{2}{\\z@}%\n                       {-18\\p@ \\@plus -4\\p@ \\@minus -4\\p@}%\n                       {8\\p@ \\@plus 4\\p@ \\@minus 4\\p@}%\n                       {\\normalfont\\normalsize\\bfseries\\boldmath\n                        \\rightskip=\\z@ \\@plus 8em\\pretolerance=10000 }}\n\\renewcommand\\subsubsection{\\@startsection{subsubsection}{3}{\\z@}%\n                       {-18\\p@ \\@plus -4\\p@ \\@minus -4\\p@}%\n                       {-0.5em \\@plus -0.22em \\@minus -0.1em}%\n                       {\\normalfont\\normalsize\\bfseries\\boldmath}}\n\\renewcommand\\paragraph{\\@startsection{paragraph}{4}{\\z@}%\n                       {-12\\p@ \\@plus -4\\p@ \\@minus -4\\p@}%\n                       {-0.5em \\@plus -0.22em \\@minus -0.1em}%\n                       {\\normalfont\\normalsize\\itshape}}\n\\renewcommand\\subparagraph[1]{\\typeout{LLNCS warning: You should not use\n                  \\string\\subparagraph\\space with this class}\\vskip0.5cm\nYou should not use \\verb|\\subparagraph| with this class.\\vskip0.5cm}\n\n\\DeclareMathSymbol{\\Gamma}{\\mathalpha}{letters}{\"00}\n\\DeclareMathSymbol{\\Delta}{\\mathalpha}{letters}{\"01}\n\\DeclareMathSymbol{\\Theta}{\\mathalpha}{letters}{\"02}\n\\DeclareMathSymbol{\\Lambda}{\\mathalpha}{letters}{\"03}\n\\DeclareMathSymbol{\\Xi}{\\mathalpha}{letters}{\"04}\n\\DeclareMathSymbol{\\Pi}{\\mathalpha}{letters}{\"05}\n\\DeclareMathSymbol{\\Sigma}{\\mathalpha}{letters}{\"06}\n\\DeclareMathSymbol{\\Upsilon}{\\mathalpha}{letters}{\"07}\n\\DeclareMathSymbol{\\Phi}{\\mathalpha}{letters}{\"08}\n\\DeclareMathSymbol{\\Psi}{\\mathalpha}{letters}{\"09}\n\\DeclareMathSymbol{\\Omega}{\\mathalpha}{letters}{\"0A}\n\n\\let\\footnotesize\\small\n\n\\if@custvec\n\\def\\vec#1{\\mathchoice{\\mbox{\\boldmath$\\displaystyle#1$}}\n{\\mbox{\\boldmath$\\textstyle#1$}}\n{\\mbox{\\boldmath$\\scriptstyle#1$}}\n{\\mbox{\\boldmath$\\scriptscriptstyle#1$}}}\n\\fi\n\n\\def\\squareforqed{\\hbox{\\rlap{$\\sqcap$}$\\sqcup$}}\n\\def\\qed{\\ifmmode\\squareforqed\\else{\\unskip\\nobreak\\hfil\n\\penalty50\\hskip1em\\null\\nobreak\\hfil\\squareforqed\n\\parfillskip=0pt\\finalhyphendemerits=0\\endgraf}\\fi}\n\n\\def\\getsto{\\mathrel{\\mathchoice {\\vcenter{\\offinterlineskip\n\\halign{\\hfil\n$\\displaystyle##$\\hfil\\cr\\gets\\cr\\to\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\textstyle##$\\hfil\\cr\\gets\n\\cr\\to\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\scriptstyle##$\\hfil\\cr\\gets\n\\cr\\to\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\scriptscriptstyle##$\\hfil\\cr\n\\gets\\cr\\to\\cr}}}}}\n\\def\\lid{\\mathrel{\\mathchoice {\\vcenter{\\offinterlineskip\\halign{\\hfil\n$\\displaystyle##$\\hfil\\cr<\\cr\\noalign{\\vskip1.2pt}=\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\textstyle##$\\hfil\\cr<\\cr\n\\noalign{\\vskip1.2pt}=\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\scriptstyle##$\\hfil\\cr<\\cr\n\\noalign{\\vskip1pt}=\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\scriptscriptstyle##$\\hfil\\cr\n<\\cr\n\\noalign{\\vskip0.9pt}=\\cr}}}}}\n\\def\\gid{\\mathrel{\\mathchoice {\\vcenter{\\offinterlineskip\\halign{\\hfil\n$\\displaystyle##$\\hfil\\cr>\\cr\\noalign{\\vskip1.2pt}=\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\textstyle##$\\hfil\\cr>\\cr\n\\noalign{\\vskip1.2pt}=\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\scriptstyle##$\\hfil\\cr>\\cr\n\\noalign{\\vskip1pt}=\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\scriptscriptstyle##$\\hfil\\cr\n>\\cr\n\\noalign{\\vskip0.9pt}=\\cr}}}}}\n\\def\\grole{\\mathrel{\\mathchoice {\\vcenter{\\offinterlineskip\n\\halign{\\hfil\n$\\displaystyle##$\\hfil\\cr>\\cr\\noalign{\\vskip-1pt}<\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\textstyle##$\\hfil\\cr\n>\\cr\\noalign{\\vskip-1pt}<\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\scriptstyle##$\\hfil\\cr\n>\\cr\\noalign{\\vskip-0.8pt}<\\cr}}}\n{\\vcenter{\\offinterlineskip\\halign{\\hfil$\\scriptscriptstyle##$\\hfil\\cr\n>\\cr\\noalign{\\vskip-0.3pt}<\\cr}}}}}\n\\def\\bbbr{{\\rm I\\!R}} %reelle Zahlen\n\\def\\bbbm{{\\rm I\\!M}}\n\\def\\bbbn{{\\rm I\\!N}} %natuerliche Zahlen\n\\def\\bbbf{{\\rm I\\!F}}\n\\def\\bbbh{{\\rm I\\!H}}\n\\def\\bbbk{{\\rm I\\!K}}\n\\def\\bbbp{{\\rm I\\!P}}\n\\def\\bbbone{{\\mathchoice {\\rm 1\\mskip-4mu l} {\\rm 1\\mskip-4mu l}\n{\\rm 1\\mskip-4.5mu l} {\\rm 1\\mskip-5mu l}}}\n\\def\\bbbc{{\\mathchoice {\\setbox0=\\hbox{$\\displaystyle\\rm C$}\\hbox{\\hbox\nto0pt{\\kern0.4\\wd0\\vrule height0.9\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\textstyle\\rm C$}\\hbox{\\hbox\nto0pt{\\kern0.4\\wd0\\vrule height0.9\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\scriptstyle\\rm C$}\\hbox{\\hbox\nto0pt{\\kern0.4\\wd0\\vrule height0.9\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\scriptscriptstyle\\rm C$}\\hbox{\\hbox\nto0pt{\\kern0.4\\wd0\\vrule height0.9\\ht0\\hss}\\box0}}}}\n\\def\\bbbq{{\\mathchoice {\\setbox0=\\hbox{$\\displaystyle\\rm\nQ$}\\hbox{\\raise\n0.15\\ht0\\hbox to0pt{\\kern0.4\\wd0\\vrule height0.8\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\textstyle\\rm Q$}\\hbox{\\raise\n0.15\\ht0\\hbox to0pt{\\kern0.4\\wd0\\vrule height0.8\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\scriptstyle\\rm Q$}\\hbox{\\raise\n0.15\\ht0\\hbox to0pt{\\kern0.4\\wd0\\vrule height0.7\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\scriptscriptstyle\\rm Q$}\\hbox{\\raise\n0.15\\ht0\\hbox to0pt{\\kern0.4\\wd0\\vrule height0.7\\ht0\\hss}\\box0}}}}\n\\def\\bbbt{{\\mathchoice {\\setbox0=\\hbox{$\\displaystyle\\rm\nT$}\\hbox{\\hbox to0pt{\\kern0.3\\wd0\\vrule height0.9\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\textstyle\\rm T$}\\hbox{\\hbox\nto0pt{\\kern0.3\\wd0\\vrule height0.9\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\scriptstyle\\rm T$}\\hbox{\\hbox\nto0pt{\\kern0.3\\wd0\\vrule height0.9\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\scriptscriptstyle\\rm T$}\\hbox{\\hbox\nto0pt{\\kern0.3\\wd0\\vrule height0.9\\ht0\\hss}\\box0}}}}\n\\def\\bbbs{{\\mathchoice\n{\\setbox0=\\hbox{$\\displaystyle     \\rm S$}\\hbox{\\raise0.5\\ht0\\hbox\nto0pt{\\kern0.35\\wd0\\vrule height0.45\\ht0\\hss}\\hbox\nto0pt{\\kern0.55\\wd0\\vrule height0.5\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\textstyle        \\rm S$}\\hbox{\\raise0.5\\ht0\\hbox\nto0pt{\\kern0.35\\wd0\\vrule height0.45\\ht0\\hss}\\hbox\nto0pt{\\kern0.55\\wd0\\vrule height0.5\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\scriptstyle      \\rm S$}\\hbox{\\raise0.5\\ht0\\hbox\nto0pt{\\kern0.35\\wd0\\vrule height0.45\\ht0\\hss}\\raise0.05\\ht0\\hbox\nto0pt{\\kern0.5\\wd0\\vrule height0.45\\ht0\\hss}\\box0}}\n{\\setbox0=\\hbox{$\\scriptscriptstyle\\rm S$}\\hbox{\\raise0.5\\ht0\\hbox\nto0pt{\\kern0.4\\wd0\\vrule height0.45\\ht0\\hss}\\raise0.05\\ht0\\hbox\nto0pt{\\kern0.55\\wd0\\vrule height0.45\\ht0\\hss}\\box0}}}}\n\\def\\bbbz{{\\mathchoice {\\hbox{$\\mathsf\\textstyle Z\\kern-0.4em Z$}}\n{\\hbox{$\\mathsf\\textstyle Z\\kern-0.4em Z$}}\n{\\hbox{$\\mathsf\\scriptstyle Z\\kern-0.3em Z$}}\n{\\hbox{$\\mathsf\\scriptscriptstyle Z\\kern-0.2em Z$}}}}\n\n\\let\\ts\\,\n\n\\setlength\\leftmargini  {17\\p@}\n\\setlength\\leftmargin    {\\leftmargini}\n\\setlength\\leftmarginii  {\\leftmargini}\n\\setlength\\leftmarginiii {\\leftmargini}\n\\setlength\\leftmarginiv  {\\leftmargini}\n\\setlength  \\labelsep  {.5em}\n\\setlength  \\labelwidth{\\leftmargini}\n\\addtolength\\labelwidth{-\\labelsep}\n\n\\def\\@listI{\\leftmargin\\leftmargini\n            \\parsep 0\\p@ \\@plus1\\p@ \\@minus\\p@\n            \\topsep 8\\p@ \\@plus2\\p@ \\@minus4\\p@\n            \\itemsep0\\p@}\n\\let\\@listi\\@listI\n\\@listi\n\\def\\@listii {\\leftmargin\\leftmarginii\n              \\labelwidth\\leftmarginii\n              \\advance\\labelwidth-\\labelsep\n              \\topsep    0\\p@ \\@plus2\\p@ \\@minus\\p@}\n\\def\\@listiii{\\leftmargin\\leftmarginiii\n              \\labelwidth\\leftmarginiii\n              \\advance\\labelwidth-\\labelsep\n              \\topsep    0\\p@ \\@plus\\p@\\@minus\\p@\n              \\parsep    \\z@\n              \\partopsep \\p@ \\@plus\\z@ \\@minus\\p@}\n\n\\renewcommand\\labelitemi{\\normalfont\\bfseries --}\n\\renewcommand\\labelitemii{$\\m@th\\bullet$}\n\n\\setlength\\arraycolsep{1.4\\p@}\n\\setlength\\tabcolsep{1.4\\p@}\n\n\\def\\tableofcontents{\\chapter*{\\contentsname\\@mkboth{{\\contentsname}}%\n                                                    {{\\contentsname}}}\n \\def\\authcount##1{\\setcounter{auco}{##1}\\setcounter{@auth}{1}}\n \\def\\lastand{\\ifnum\\value{auco}=2\\relax\n                 \\unskip{} \\andname\\\n              \\else\n                 \\unskip \\lastandname\\\n              \\fi}%\n \\def\\and{\\stepcounter{@auth}\\relax\n          \\ifnum\\value{@auth}=\\value{auco}%\n             \\lastand\n          \\else\n             \\unskip,\n          \\fi}%\n \\@starttoc{toc}\\if@restonecol\\twocolumn\\fi}\n\n\\def\\l@part#1#2{\\addpenalty{\\@secpenalty}%\n   \\addvspace{2em plus\\p@}%  % space above part line\n   \\begingroup\n     \\parindent \\z@\n     \\rightskip \\z@ plus 5em\n     \\hrule\\vskip5pt\n     \\large               % same size as for a contribution heading\n     \\bfseries\\boldmath   % set line in boldface\n     \\leavevmode          % TeX command to enter horizontal mode.\n     #1\\par\n     \\vskip5pt\n     \\hrule\n     \\vskip1pt\n     \\nobreak             % Never break after part entry\n   \\endgroup}\n\n\\def\\@dotsep{2}\n\n\\def\\hyperhrefextend{\\ifx\\hyper@anchor\\@undefined\\else\n{chapter.\\thechapter}\\fi}\n\n\\def\\addnumcontentsmark#1#2#3{%\n\\addtocontents{#1}{\\protect\\contentsline{#2}{\\protect\\numberline\n                     {\\thechapter}#3}{\\thepage}\\hyperhrefextend}}\n\\def\\addcontentsmark#1#2#3{%\n\\addtocontents{#1}{\\protect\\contentsline{#2}{#3}{\\thepage}\\hyperhrefextend}}\n\\def\\addcontentsmarkwop#1#2#3{%\n\\addtocontents{#1}{\\protect\\contentsline{#2}{#3}{0}\\hyperhrefextend}}\n\n\\def\\@adcmk[#1]{\\ifcase #1 \\or\n\\def\\@gtempa{\\addnumcontentsmark}%\n  \\or    \\def\\@gtempa{\\addcontentsmark}%\n  \\or    \\def\\@gtempa{\\addcontentsmarkwop}%\n  \\fi\\@gtempa{toc}{chapter}}\n\\def\\addtocmark{\\@ifnextchar[{\\@adcmk}{\\@adcmk[3]}}\n\n\\def\\l@chapter#1#2{\\addpenalty{-\\@highpenalty}\n \\vskip 1.0em plus 1pt \\@tempdima 1.5em \\begingroup\n \\parindent \\z@ \\rightskip \\@tocrmarg\n \\advance\\rightskip by 0pt plus 2cm\n \\parfillskip -\\rightskip \\pretolerance=10000\n \\leavevmode \\advance\\leftskip\\@tempdima \\hskip -\\leftskip\n {\\large\\bfseries\\boldmath#1}\\ifx0#2\\hfil\\null\n \\else\n      \\nobreak\n      \\leaders\\hbox{$\\m@th \\mkern \\@dotsep mu.\\mkern\n      \\@dotsep mu$}\\hfill\n      \\nobreak\\hbox to\\@pnumwidth{\\hss #2}%\n \\fi\\par\n \\penalty\\@highpenalty \\endgroup}\n\n\\def\\l@title#1#2{\\addpenalty{-\\@highpenalty}\n \\addvspace{8pt plus 1pt}\n \\@tempdima \\z@\n \\begingroup\n \\parindent \\z@ \\rightskip \\@tocrmarg\n \\advance\\rightskip by 0pt plus 2cm\n \\parfillskip -\\rightskip \\pretolerance=10000\n \\leavevmode \\advance\\leftskip\\@tempdima \\hskip -\\leftskip\n #1\\nobreak\n \\leaders\\hbox{$\\m@th \\mkern \\@dotsep mu.\\mkern\n \\@dotsep mu$}\\hfill\n \\nobreak\\hbox to\\@pnumwidth{\\hss #2}\\par\n \\penalty\\@highpenalty \\endgroup}\n\n\\def\\l@author#1#2{\\addpenalty{\\@highpenalty}\n \\@tempdima=\\z@ %15\\p@\n \\begingroup\n \\parindent \\z@ \\rightskip \\@tocrmarg\n \\advance\\rightskip by 0pt plus 2cm\n \\pretolerance=10000\n \\leavevmode \\advance\\leftskip\\@tempdima %\\hskip -\\leftskip\n \\textit{#1}\\par\n \\penalty\\@highpenalty \\endgroup}\n\n\\setcounter{tocdepth}{0}\n\\newdimen\\tocchpnum\n\\newdimen\\tocsecnum\n\\newdimen\\tocsectotal\n\\newdimen\\tocsubsecnum\n\\newdimen\\tocsubsectotal\n\\newdimen\\tocsubsubsecnum\n\\newdimen\\tocsubsubsectotal\n\\newdimen\\tocparanum\n\\newdimen\\tocparatotal\n\\newdimen\\tocsubparanum\n\\tocchpnum=\\z@            % no chapter numbers\n\\tocsecnum=15\\p@          % section 88. plus 2.222pt\n\\tocsubsecnum=23\\p@       % subsection 88.8 plus 2.222pt\n\\tocsubsubsecnum=27\\p@    % subsubsection 88.8.8 plus 1.444pt\n\\tocparanum=35\\p@         % paragraph 88.8.8.8 plus 1.666pt\n\\tocsubparanum=43\\p@      % subparagraph 88.8.8.8.8 plus 1.888pt\n\\def\\calctocindent{%\n\\tocsectotal=\\tocchpnum\n\\advance\\tocsectotal by\\tocsecnum\n\\tocsubsectotal=\\tocsectotal\n\\advance\\tocsubsectotal by\\tocsubsecnum\n\\tocsubsubsectotal=\\tocsubsectotal\n\\advance\\tocsubsubsectotal by\\tocsubsubsecnum\n\\tocparatotal=\\tocsubsubsectotal\n\\advance\\tocparatotal by\\tocparanum}\n\\calctocindent\n\n\\def\\l@section{\\@dottedtocline{1}{\\tocchpnum}{\\tocsecnum}}\n\\def\\l@subsection{\\@dottedtocline{2}{\\tocsectotal}{\\tocsubsecnum}}\n\\def\\l@subsubsection{\\@dottedtocline{3}{\\tocsubsectotal}{\\tocsubsubsecnum}}\n\\def\\l@paragraph{\\@dottedtocline{4}{\\tocsubsubsectotal}{\\tocparanum}}\n\\def\\l@subparagraph{\\@dottedtocline{5}{\\tocparatotal}{\\tocsubparanum}}\n\n\\def\\listoffigures{\\@restonecolfalse\\if@twocolumn\\@restonecoltrue\\onecolumn\n \\fi\\section*{\\listfigurename\\@mkboth{{\\listfigurename}}{{\\listfigurename}}}\n \\@starttoc{lof}\\if@restonecol\\twocolumn\\fi}\n\\def\\l@figure{\\@dottedtocline{1}{0em}{1.5em}}\n\n\\def\\listoftables{\\@restonecolfalse\\if@twocolumn\\@restonecoltrue\\onecolumn\n \\fi\\section*{\\listtablename\\@mkboth{{\\listtablename}}{{\\listtablename}}}\n \\@starttoc{lot}\\if@restonecol\\twocolumn\\fi}\n\\let\\l@table\\l@figure\n\n\\renewcommand\\listoffigures{%\n    \\section*{\\listfigurename\n      \\@mkboth{\\listfigurename}{\\listfigurename}}%\n    \\@starttoc{lof}%\n    }\n\n\\renewcommand\\listoftables{%\n    \\section*{\\listtablename\n      \\@mkboth{\\listtablename}{\\listtablename}}%\n    \\@starttoc{lot}%\n    }\n\n\\ifx\\oribibl\\undefined\n\\ifx\\citeauthoryear\\undefined\n\\renewenvironment{thebibliography}[1]\n     {\\section*{\\refname}\n      \\def\\@biblabel##1{##1.}\n      \\small\n      \\list{\\@biblabel{\\@arabic\\c@enumiv}}%\n           {\\settowidth\\labelwidth{\\@biblabel{#1}}%\n            \\leftmargin\\labelwidth\n            \\advance\\leftmargin\\labelsep\n            \\if@openbib\n              \\advance\\leftmargin\\bibindent\n              \\itemindent -\\bibindent\n              \\listparindent \\itemindent\n              \\parsep \\z@\n            \\fi\n            \\usecounter{enumiv}%\n            \\let\\p@enumiv\\@empty\n            \\renewcommand\\theenumiv{\\@arabic\\c@enumiv}}%\n      \\if@openbib\n        \\renewcommand\\newblock{\\par}%\n      \\else\n        \\renewcommand\\newblock{\\hskip .11em \\@plus.33em \\@minus.07em}%\n      \\fi\n      \\sloppy\\clubpenalty4000\\widowpenalty4000%\n      \\sfcode`\\.=\\@m}\n     {\\def\\@noitemerr\n       {\\@latex@warning{Empty `thebibliography' environment}}%\n      \\endlist}\n\\def\\@lbibitem[#1]#2{\\item[{[#1]}\\hfill]\\if@filesw\n     {\\let\\protect\\noexpand\\immediate\n     \\write\\@auxout{\\string\\bibcite{#2}{#1}}}\\fi\\ignorespaces}\n\\newcount\\@tempcntc\n\\def\\@citex[#1]#2{\\if@filesw\\immediate\\write\\@auxout{\\string\\citation{#2}}\\fi\n  \\@tempcnta\\z@\\@tempcntb\\m@ne\\def\\@citea{}\\@cite{\\@for\\@citeb:=#2\\do\n    {\\@ifundefined\n       {b@\\@citeb}{\\@citeo\\@tempcntb\\m@ne\\@citea\\def\\@citea{,}{\\bfseries\n        ?}\\@warning\n       {Citation `\\@citeb' on page \\thepage \\space undefined}}%\n    {\\setbox\\z@\\hbox{\\global\\@tempcntc0\\csname b@\\@citeb\\endcsname\\relax}%\n     \\ifnum\\@tempcntc=\\z@ \\@citeo\\@tempcntb\\m@ne\n       \\@citea\\def\\@citea{,}\\hbox{\\csname b@\\@citeb\\endcsname}%\n     \\else\n      \\advance\\@tempcntb\\@ne\n      \\ifnum\\@tempcntb=\\@tempcntc\n      \\else\\advance\\@tempcntb\\m@ne\\@citeo\n      \\@tempcnta\\@tempcntc\\@tempcntb\\@tempcntc\\fi\\fi}}\\@citeo}{#1}}\n\\def\\@citeo{\\ifnum\\@tempcnta>\\@tempcntb\\else\n               \\@citea\\def\\@citea{,\\,\\hskip\\z@skip}%\n               \\ifnum\\@tempcnta=\\@tempcntb\\the\\@tempcnta\\else\n               {\\advance\\@tempcnta\\@ne\\ifnum\\@tempcnta=\\@tempcntb \\else\n                \\def\\@citea{--}\\fi\n      \\advance\\@tempcnta\\m@ne\\the\\@tempcnta\\@citea\\the\\@tempcntb}\\fi\\fi}\n\\else\n\\renewenvironment{thebibliography}[1]\n     {\\section*{\\refname}\n      \\small\n      \\list{}%\n           {\\settowidth\\labelwidth{}%\n            \\leftmargin\\parindent\n            \\itemindent=-\\parindent\n            \\labelsep=\\z@\n            \\if@openbib\n              \\advance\\leftmargin\\bibindent\n              \\itemindent -\\bibindent\n              \\listparindent \\itemindent\n              \\parsep \\z@\n            \\fi\n            \\usecounter{enumiv}%\n            \\let\\p@enumiv\\@empty\n            \\renewcommand\\theenumiv{}}%\n      \\if@openbib\n        \\renewcommand\\newblock{\\par}%\n      \\else\n        \\renewcommand\\newblock{\\hskip .11em \\@plus.33em \\@minus.07em}%\n      \\fi\n      \\sloppy\\clubpenalty4000\\widowpenalty4000%\n      \\sfcode`\\.=\\@m}\n     {\\def\\@noitemerr\n       {\\@latex@warning{Empty `thebibliography' environment}}%\n      \\endlist}\n      \\def\\@cite#1{#1}%\n      \\def\\@lbibitem[#1]#2{\\item[]\\if@filesw\n        {\\def\\protect##1{\\string ##1\\space}\\immediate\n      \\write\\@auxout{\\string\\bibcite{#2}{#1}}}\\fi\\ignorespaces}\n   \\fi\n\\else\n\\@cons\\@openbib@code{\\noexpand\\small}\n\\fi\n\n\\def\\idxquad{\\hskip 10\\p@}% space that divides entry from number\n\n\\def\\@idxitem{\\par\\hangindent 10\\p@}\n\n\\def\\subitem{\\par\\setbox0=\\hbox{--\\enspace}% second order\n                \\noindent\\hangindent\\wd0\\box0}% index entry\n\n\\def\\subsubitem{\\par\\setbox0=\\hbox{--\\,--\\enspace}% third\n                \\noindent\\hangindent\\wd0\\box0}% order index entry\n\n\\def\\indexspace{\\par \\vskip 10\\p@ plus5\\p@ minus3\\p@\\relax}\n\n\\renewenvironment{theindex}\n               {\\@mkboth{\\indexname}{\\indexname}%\n                \\thispagestyle{empty}\\parindent\\z@\n                \\parskip\\z@ \\@plus .3\\p@\\relax\n                \\let\\item\\par\n                \\def\\,{\\relax\\ifmmode\\mskip\\thinmuskip\n                             \\else\\hskip0.2em\\ignorespaces\\fi}%\n                \\normalfont\\small\n                \\begin{multicols}{2}[\\@makeschapterhead{\\indexname}]%\n                }\n                {\\end{multicols}}\n\n\\renewcommand\\footnoterule{%\n  \\kern-3\\p@\n  \\hrule\\@width 2truecm\n  \\kern2.6\\p@}\n  \\newdimen\\fnindent\n  \\fnindent1em\n\\long\\def\\@makefntext#1{%\n    \\parindent \\fnindent%\n    \\leftskip \\fnindent%\n    \\noindent\n    \\llap{\\hb@xt@1em{\\hss\\@makefnmark\\ }}\\ignorespaces#1}\n\n\\long\\def\\@makecaption#1#2{%\n  \\vskip\\abovecaptionskip\n  \\sbox\\@tempboxa{{\\bfseries #1.} #2}%\n  \\ifdim \\wd\\@tempboxa >\\hsize\n    {\\bfseries #1.} #2\\par\n  \\else\n    \\global \\@minipagefalse\n    \\hb@xt@\\hsize{\\hfil\\box\\@tempboxa\\hfil}%\n  \\fi\n  \\vskip\\belowcaptionskip}\n\n\\def\\fps@figure{htbp}\n\\def\\fnum@figure{\\figurename\\thinspace\\thefigure}\n\\def \\@floatboxreset {%\n        \\reset@font\n        \\small\n        \\@setnobreak\n        \\@setminipage\n}\n\\def\\fps@table{htbp}\n\\def\\fnum@table{\\tablename~\\thetable}\n\\renewenvironment{table}\n               {\\setlength\\abovecaptionskip{0\\p@}%\n                \\setlength\\belowcaptionskip{10\\p@}%\n                \\@float{table}}\n               {\\end@float}\n\\renewenvironment{table*}\n               {\\setlength\\abovecaptionskip{0\\p@}%\n                \\setlength\\belowcaptionskip{10\\p@}%\n                \\@dblfloat{table}}\n               {\\end@dblfloat}\n\n\\long\\def\\@caption#1[#2]#3{\\par\\addcontentsline{\\csname\n  ext@#1\\endcsname}{#1}{\\protect\\numberline{\\csname\n  the#1\\endcsname}{\\ignorespaces #2}}\\begingroup\n    \\@parboxrestore\n    \\@makecaption{\\csname fnum@#1\\endcsname}{\\ignorespaces #3}\\par\n  \\endgroup}\n\n% LaTeX does not provide a command to enter the authors institute\n% addresses. The \\institute command is defined here.\n\n\\newcounter{@inst}\n\\newcounter{@auth}\n\\newcounter{auco}\n\\newdimen\\instindent\n\\newbox\\authrun\n\\newtoks\\authorrunning\n\\newtoks\\tocauthor\n\\newbox\\titrun\n\\newtoks\\titlerunning\n\\newtoks\\toctitle\n\n\\def\\clearheadinfo{\\gdef\\@author{No Author Given}%\n                   \\gdef\\@title{No Title Given}%\n                   \\gdef\\@subtitle{}%\n                   \\gdef\\@institute{No Institute Given}%\n                   \\gdef\\@thanks{}%\n                   \\global\\titlerunning={}\\global\\authorrunning={}%\n                   \\global\\toctitle={}\\global\\tocauthor={}}\n\n\\def\\institute#1{\\gdef\\@institute{#1}}\n\n\\def\\institutename{\\par\n \\begingroup\n \\parskip=\\z@\n \\parindent=\\z@\n \\setcounter{@inst}{1}%\n \\def\\and{\\par\\stepcounter{@inst}%\n \\noindent$^{\\the@inst}$\\enspace\\ignorespaces}%\n \\setbox0=\\vbox{\\def\\thanks##1{}\\@institute}%\n \\ifnum\\c@@inst=1\\relax\n   \\gdef\\fnnstart{0}%\n \\else\n   \\xdef\\fnnstart{\\c@@inst}%\n   \\setcounter{@inst}{1}%\n   \\noindent$^{\\the@inst}$\\enspace\n \\fi\n \\ignorespaces\n \\@institute\\par\n \\endgroup}\n\n\\def\\@fnsymbol#1{\\ensuremath{\\ifcase#1\\or\\star\\or{\\star\\star}\\or\n   {\\star\\star\\star}\\or \\dagger\\or \\ddagger\\or\n   \\mathchar \"278\\or \\mathchar \"27B\\or \\|\\or **\\or \\dagger\\dagger\n   \\or \\ddagger\\ddagger \\else\\@ctrerr\\fi}}\n\n\\def\\inst#1{\\unskip$^{#1}$}\n\\def\\fnmsep{\\unskip$^,$}\n\\def\\email#1{{\\tt#1}}\n\\AtBeginDocument{\\@ifundefined{url}{\\def\\url#1{#1}}{}%\n\\@ifpackageloaded{babel}{%\n\\@ifundefined{extrasenglish}{}{\\addto\\extrasenglish{\\switcht@albion}}%\n\\@ifundefined{extrasfrenchb}{}{\\addto\\extrasfrenchb{\\switcht@francais}}%\n\\@ifundefined{extrasgerman}{}{\\addto\\extrasgerman{\\switcht@deutsch}}%\n}{\\switcht@@therlang}%\n}\n\\def\\homedir{\\~{ }}\n\n\\def\\subtitle#1{\\gdef\\@subtitle{#1}}\n\\clearheadinfo\n\n\\renewcommand\\maketitle{\\newpage\n  \\refstepcounter{chapter}%\n  \\stepcounter{section}%\n  \\setcounter{section}{0}%\n  \\setcounter{subsection}{0}%\n  \\setcounter{figure}{0}\n  \\setcounter{table}{0}\n  \\setcounter{equation}{0}\n  \\setcounter{footnote}{0}%\n  \\begingroup\n    \\parindent=\\z@\n    \\renewcommand\\thefootnote{\\@fnsymbol\\c@footnote}%\n    \\if@twocolumn\n      \\ifnum \\col@number=\\@ne\n        \\@maketitle\n      \\else\n        \\twocolumn[\\@maketitle]%\n      \\fi\n    \\else\n      \\newpage\n      \\global\\@topnum\\z@   % Prevents figures from going at top of page.\n      \\@maketitle\n    \\fi\n    \\thispagestyle{empty}\\@thanks\n%\n    \\def\\\\{\\unskip\\ \\ignorespaces}\\def\\inst##1{\\unskip{}}%\n    \\def\\thanks##1{\\unskip{}}\\def\\fnmsep{\\unskip}%\n    \\instindent=\\hsize\n    \\advance\\instindent by-\\headlineindent\n    \\if!\\the\\toctitle!\\addcontentsline{toc}{title}{\\@title}\\else\n       \\addcontentsline{toc}{title}{\\the\\toctitle}\\fi\n    \\if@runhead\n       \\if!\\the\\titlerunning!\\else\n         \\edef\\@title{\\the\\titlerunning}%\n       \\fi\n       \\global\\setbox\\titrun=\\hbox{\\small\\rm\\unboldmath\\ignorespaces\\@title}%\n       \\ifdim\\wd\\titrun>\\instindent\n          \\typeout{Title too long for running head. Please supply}%\n          \\typeout{a shorter form with \\string\\titlerunning\\space prior to\n                   \\string\\maketitle}%\n          \\global\\setbox\\titrun=\\hbox{\\small\\rm\n          Title Suppressed Due to Excessive Length}%\n       \\fi\n       \\xdef\\@title{\\copy\\titrun}%\n    \\fi\n%\n    \\if!\\the\\tocauthor!\\relax\n      {\\def\\and{\\noexpand\\protect\\noexpand\\and}%\n      \\protected@xdef\\toc@uthor{\\@author}}%\n    \\else\n      \\def\\\\{\\noexpand\\protect\\noexpand\\newline}%\n      \\protected@xdef\\scratch{\\the\\tocauthor}%\n      \\protected@xdef\\toc@uthor{\\scratch}%\n    \\fi\n    \\addcontentsline{toc}{author}{\\toc@uthor}%\n    \\if@runhead\n       \\if!\\the\\authorrunning!\n         \\value{@inst}=\\value{@auth}%\n         \\setcounter{@auth}{1}%\n       \\else\n         \\edef\\@author{\\the\\authorrunning}%\n       \\fi\n       \\global\\setbox\\authrun=\\hbox{\\small\\unboldmath\\@author\\unskip}%\n       \\ifdim\\wd\\authrun>\\instindent\n          \\typeout{Names of authors too long for running head. Please supply}%\n          \\typeout{a shorter form with \\string\\authorrunning\\space prior to\n                   \\string\\maketitle}%\n          \\global\\setbox\\authrun=\\hbox{\\small\\rm\n          Authors Suppressed Due to Excessive Length}%\n       \\fi\n       \\xdef\\@author{\\copy\\authrun}%\n       \\markboth{\\@author}{\\@title}%\n     \\fi\n  \\endgroup\n  \\setcounter{footnote}{\\fnnstart}%\n  \\clearheadinfo}\n%\n\\def\\@maketitle{\\newpage\n \\markboth{}{}%\n \\def\\lastand{\\ifnum\\value{@inst}=2\\relax\n                 \\unskip{} \\andname\\\n              \\else\n                 \\unskip \\lastandname\\\n              \\fi}%\n \\def\\and{\\stepcounter{@auth}\\relax\n          \\ifnum\\value{@auth}=\\value{@inst}%\n             \\lastand\n          \\else\n             \\unskip,\n          \\fi}%\n \\begin{center}%\n \\let\\newline\\\\\n {\\Large \\bfseries\\boldmath\n  \\pretolerance=10000\n  \\@title \\par}\\vskip .8cm\n\\if!\\@subtitle!\\else {\\large \\bfseries\\boldmath\n  \\vskip -.65cm\n  \\pretolerance=10000\n  \\@subtitle \\par}\\vskip .8cm\\fi\n \\setbox0=\\vbox{\\setcounter{@auth}{1}\\def\\and{\\stepcounter{@auth}}%\n \\def\\thanks##1{}\\@author}%\n \\global\\value{@inst}=\\value{@auth}%\n \\global\\value{auco}=\\value{@auth}%\n \\setcounter{@auth}{1}%\n{\\lineskip .5em\n\\noindent\\ignorespaces\n\\@author\\vskip.35cm}\n {\\small\\institutename}\n \\end{center}%\n }\n\n% definition of the \"\\spnewtheorem\" command.\n%\n% Usage:\n%\n%     \\spnewtheorem{env_nam}{caption}[within]{cap_font}{body_font}\n% or  \\spnewtheorem{env_nam}[numbered_like]{caption}{cap_font}{body_font}\n% or  \\spnewtheorem*{env_nam}{caption}{cap_font}{body_font}\n%\n% New is \"cap_font\" and \"body_font\". It stands for\n% fontdefinition of the caption and the text itself.\n%\n% \"\\spnewtheorem*\" gives a theorem without number.\n%\n% A defined spnewthoerem environment is used as described\n% by Lamport.\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\def\\@thmcountersep{}\n\\def\\@thmcounterend{.}\n\n\\def\\spnewtheorem{\\@ifstar{\\@sthm}{\\@Sthm}}\n\n% definition of \\spnewtheorem with number\n\n\\def\\@spnthm#1#2{%\n  \\@ifnextchar[{\\@spxnthm{#1}{#2}}{\\@spynthm{#1}{#2}}}\n\\def\\@Sthm#1{\\@ifnextchar[{\\@spothm{#1}}{\\@spnthm{#1}}}\n\n\\def\\@spxnthm#1#2[#3]#4#5{\\expandafter\\@ifdefinable\\csname #1\\endcsname\n   {\\@definecounter{#1}\\@addtoreset{#1}{#3}%\n   \\expandafter\\xdef\\csname the#1\\endcsname{\\expandafter\\noexpand\n     \\csname the#3\\endcsname \\noexpand\\@thmcountersep \\@thmcounter{#1}}%\n   \\expandafter\\xdef\\csname #1name\\endcsname{#2}%\n   \\global\\@namedef{#1}{\\@spthm{#1}{\\csname #1name\\endcsname}{#4}{#5}}%\n                              \\global\\@namedef{end#1}{\\@endtheorem}}}\n\n\\def\\@spynthm#1#2#3#4{\\expandafter\\@ifdefinable\\csname #1\\endcsname\n   {\\@definecounter{#1}%\n   \\expandafter\\xdef\\csname the#1\\endcsname{\\@thmcounter{#1}}%\n   \\expandafter\\xdef\\csname #1name\\endcsname{#2}%\n   \\global\\@namedef{#1}{\\@spthm{#1}{\\csname #1name\\endcsname}{#3}{#4}}%\n                               \\global\\@namedef{end#1}{\\@endtheorem}}}\n\n\\def\\@spothm#1[#2]#3#4#5{%\n  \\@ifundefined{c@#2}{\\@latexerr{No theorem environment `#2' defined}\\@eha}%\n  {\\expandafter\\@ifdefinable\\csname #1\\endcsname\n  {\\global\\@namedef{the#1}{\\@nameuse{the#2}}%\n  \\expandafter\\xdef\\csname #1name\\endcsname{#3}%\n  \\global\\@namedef{#1}{\\@spthm{#2}{\\csname #1name\\endcsname}{#4}{#5}}%\n  \\global\\@namedef{end#1}{\\@endtheorem}}}}\n\n\\def\\@spthm#1#2#3#4{\\topsep 7\\p@ \\@plus2\\p@ \\@minus4\\p@\n\\refstepcounter{#1}%\n\\@ifnextchar[{\\@spythm{#1}{#2}{#3}{#4}}{\\@spxthm{#1}{#2}{#3}{#4}}}\n\n\\def\\@spxthm#1#2#3#4{\\@spbegintheorem{#2}{\\csname the#1\\endcsname}{#3}{#4}%\n                    \\ignorespaces}\n\n\\def\\@spythm#1#2#3#4[#5]{\\@spopargbegintheorem{#2}{\\csname\n       the#1\\endcsname}{#5}{#3}{#4}\\ignorespaces}\n\n\\def\\@spbegintheorem#1#2#3#4{\\trivlist\n                 \\item[\\hskip\\labelsep{#3#1\\ #2\\@thmcounterend}]#4}\n\n\\def\\@spopargbegintheorem#1#2#3#4#5{\\trivlist\n      \\item[\\hskip\\labelsep{#4#1\\ #2}]{#4(#3)\\@thmcounterend\\ }#5}\n\n% definition of \\spnewtheorem* without number\n\n\\def\\@sthm#1#2{\\@Ynthm{#1}{#2}}\n\n\\def\\@Ynthm#1#2#3#4{\\expandafter\\@ifdefinable\\csname #1\\endcsname\n   {\\global\\@namedef{#1}{\\@Thm{\\csname #1name\\endcsname}{#3}{#4}}%\n    \\expandafter\\xdef\\csname #1name\\endcsname{#2}%\n    \\global\\@namedef{end#1}{\\@endtheorem}}}\n\n\\def\\@Thm#1#2#3{\\topsep 7\\p@ \\@plus2\\p@ \\@minus4\\p@\n\\@ifnextchar[{\\@Ythm{#1}{#2}{#3}}{\\@Xthm{#1}{#2}{#3}}}\n\n\\def\\@Xthm#1#2#3{\\@Begintheorem{#1}{#2}{#3}\\ignorespaces}\n\n\\def\\@Ythm#1#2#3[#4]{\\@Opargbegintheorem{#1}\n       {#4}{#2}{#3}\\ignorespaces}\n\n\\def\\@Begintheorem#1#2#3{#3\\trivlist\n                           \\item[\\hskip\\labelsep{#2#1\\@thmcounterend}]}\n\n\\def\\@Opargbegintheorem#1#2#3#4{#4\\trivlist\n      \\item[\\hskip\\labelsep{#3#1}]{#3(#2)\\@thmcounterend\\ }}\n\n\\if@envcntsect\n   \\def\\@thmcountersep{.}\n   \\spnewtheorem{theorem}{Theorem}[section]{\\bfseries}{\\itshape}\n\\else\n   \\spnewtheorem{theorem}{Theorem}{\\bfseries}{\\itshape}\n   \\if@envcntreset\n      \\@addtoreset{theorem}{section}\n   \\else\n      \\@addtoreset{theorem}{chapter}\n   \\fi\n\\fi\n\n%definition of divers theorem environments\n\\spnewtheorem*{claim}{Claim}{\\itshape}{\\rmfamily}\n\\spnewtheorem*{proof}{Proof}{\\itshape}{\\rmfamily}\n\\if@envcntsame % alle Umgebungen wie Theorem.\n   \\def\\spn@wtheorem#1#2#3#4{\\@spothm{#1}[theorem]{#2}{#3}{#4}}\n\\else % alle Umgebungen mit eigenem Zaehler\n   \\if@envcntsect % mit section numeriert\n      \\def\\spn@wtheorem#1#2#3#4{\\@spxnthm{#1}{#2}[section]{#3}{#4}}\n   \\else % nicht mit section numeriert\n      \\if@envcntreset\n         \\def\\spn@wtheorem#1#2#3#4{\\@spynthm{#1}{#2}{#3}{#4}\n                                   \\@addtoreset{#1}{section}}\n      \\else\n         \\def\\spn@wtheorem#1#2#3#4{\\@spynthm{#1}{#2}{#3}{#4}\n                                   \\@addtoreset{#1}{chapter}}%\n      \\fi\n   \\fi\n\\fi\n\\spn@wtheorem{case}{Case}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{conjecture}{Conjecture}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{corollary}{Corollary}{\\bfseries}{\\itshape}\n\\spn@wtheorem{definition}{Definition}{\\bfseries}{\\itshape}\n\\spn@wtheorem{example}{Example}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{exercise}{Exercise}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{lemma}{Lemma}{\\bfseries}{\\itshape}\n\\spn@wtheorem{note}{Note}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{problem}{Problem}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{property}{Property}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{proposition}{Proposition}{\\bfseries}{\\itshape}\n\\spn@wtheorem{question}{Question}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{solution}{Solution}{\\itshape}{\\rmfamily}\n\\spn@wtheorem{remark}{Remark}{\\itshape}{\\rmfamily}\n\n\\def\\@takefromreset#1#2{%\n    \\def\\@tempa{#1}%\n    \\let\\@tempd\\@elt\n    \\def\\@elt##1{%\n        \\def\\@tempb{##1}%\n        \\ifx\\@tempa\\@tempb\\else\n            \\@addtoreset{##1}{#2}%\n        \\fi}%\n    \\expandafter\\expandafter\\let\\expandafter\\@tempc\\csname cl@#2\\endcsname\n    \\expandafter\\def\\csname cl@#2\\endcsname{}%\n    \\@tempc\n    \\let\\@elt\\@tempd}\n\n\\def\\theopargself{\\def\\@spopargbegintheorem##1##2##3##4##5{\\trivlist\n      \\item[\\hskip\\labelsep{##4##1\\ ##2}]{##4##3\\@thmcounterend\\ }##5}\n                  \\def\\@Opargbegintheorem##1##2##3##4{##4\\trivlist\n      \\item[\\hskip\\labelsep{##3##1}]{##3##2\\@thmcounterend\\ }}\n      }\n\n\\renewenvironment{abstract}{%\n      \\list{}{\\advance\\topsep by0.35cm\\relax\\small\n      \\leftmargin=1cm\n      \\labelwidth=\\z@\n      \\listparindent=\\z@\n      \\itemindent\\listparindent\n      \\rightmargin\\leftmargin}\\item[\\hskip\\labelsep\n                                    \\bfseries\\abstractname]}\n    {\\endlist}\n\n\\newdimen\\headlineindent             % dimension for space between\n\\headlineindent=1.166cm              % number and text of headings.\n\n\\def\\ps@headings{\\let\\@mkboth\\@gobbletwo\n   \\let\\@oddfoot\\@empty\\let\\@evenfoot\\@empty\n   \\def\\@evenhead{\\normalfont\\small\\rlap{\\thepage}\\hspace{\\headlineindent}%\n                  \\leftmark\\hfil}\n   \\def\\@oddhead{\\normalfont\\small\\hfil\\rightmark\\hspace{\\headlineindent}%\n                 \\llap{\\thepage}}\n   \\def\\chaptermark##1{}%\n   \\def\\sectionmark##1{}%\n   \\def\\subsectionmark##1{}}\n\n\\def\\ps@titlepage{\\let\\@mkboth\\@gobbletwo\n   \\let\\@oddfoot\\@empty\\let\\@evenfoot\\@empty\n   \\def\\@evenhead{\\normalfont\\small\\rlap{\\thepage}\\hspace{\\headlineindent}%\n                  \\hfil}\n   \\def\\@oddhead{\\normalfont\\small\\hfil\\hspace{\\headlineindent}%\n                 \\llap{\\thepage}}\n   \\def\\chaptermark##1{}%\n   \\def\\sectionmark##1{}%\n   \\def\\subsectionmark##1{}}\n\n\\if@runhead\\ps@headings\\else\n\\ps@empty\\fi\n\n\\setlength\\arraycolsep{1.4\\p@}\n\\setlength\\tabcolsep{1.4\\p@}\n\n\\endinput\n%end of file llncs.cls\n"
  },
  {
    "path": "papers/paper1.tex",
    "content": "\\documentclass{llncs}\n\n\\begin{document}\n\n\\title{YACAS: A Do-it-yourself Symbolic Algebra Environment}\n\n\\author{Ayal Zwi Pinkus\\inst{1} \\and Serge Winitzki\\inst{2}}\n\\institute{3e Oosterparkstraat 109-III,\nAmsterdam, The Netherlands\n(\\email{apinkus@xs4all.nl})\n\\and\nTufts Institute of Cosmology, Department of Physics and Astronomy, Tufts University, Medford, MA 02155, USA\n(\\email{serge@cosmos.phy.tufts.edu})\n}\n\n\\maketitle\n\n\\begin{abstract}\nWe describe the design and implementation of \\textsc{Yacas}, a free computer\nalgebra system currently under development.  The system consists of a core\ninterpreter and a library of scripts that implement symbolic algebra\nfunctionality.  The interpreter provides a high-level weakly typed functional\nlanguage designed for quick prototyping of computer algebra algorithms, but the\nlanguage is suitable for all kinds of symbolic manipulation. It supports\nconditional term rewriting of symbolic expression trees, closures (pure\nfunctions) and delayed evaluation, dynamic creation of transformation rules,\narbitrary-precision numerical calculations, and flexible user-defined syntax\nusing infix notation.  The library of scripts currently provides basic\nnumerical and symbolic functionality. The main advantages of \\textsc{Yacas} are: free (GPL)\nsoftware; a\nflexible and easy-to-use programming language with a comfortable and adjustable\nsyntax; cross-platform portability and small resource requirements; and extensibility.\n\\end{abstract}\n\n%%% Start of main text\n\n\n\\section{Introduction}\n\\textsc{Yacas} is a computer algebra system (CAS) which has been in development since the beginning of 1999.\nThe goal was to make a small system that allows to easily prototype and\nresearch symbolic mathematics algorithms. A secondary future goal is to evolve\n\\textsc{Yacas} into a full-blown general purpose CAS.\n\n\n\\textsc{Yacas} is primarily intended to be a research tool for easy\nexploration and prototyping of algorithms of symbolic\ncomputation.  The main advantage of \\textsc{Yacas}, besides being free software, is its rich and flexible\nscripting language. The language is closely related to LISP \\cite{WH89} but has\na recursive descent infix grammar parser \\cite{ASU86}, includes expression\ntransformation (term rewriting), and supports defining infix operators at run time\nsimilarly to Prolog \\cite{B86}.\n\n\nThe \\textsc{Yacas} language interpreter comes with a library of scripts that implement a set of computer algebra features. The \\textsc{Yacas} script library\nis in active development and at the present stage does not offer the rich functionality of\nindustrial-strength systems such as \\textsc{Mathematica} or \\textsc{Maple}.\nExtensive\nimplementation of algorithms of symbolic computation is one of the future\ndevelopment goals.\n\n\\textsc{Yacas} handles input and output in plain ASCII,\neither interactively or in batch mode. (A graphical interface is under development.) There is also an optional plugin mechanism\nwhereby external libraries can be linked into the system to provide extra\nfunctionality.\n\n\\textsc{Yacas} currently (at version 1.0.49) consists of approximately 22000 lines of C++ code and  13000 lines of \nscript code, with 170 functions defined in the C++ kernel and 600 functions\ndefined in the script library.\n\n\n\\section{Basic design}\n\n\\textsc{Yacas} consists of a ``core engine\" (kernel), which is an interpreter\nfor the \\textsc{Yacas} scripting language, and a library of script code.\n\nThe\n\\textsc{Yacas} engine has been implemented in a subset of C++ which is\nsupported by almost all C++ compilers.\nThe design goals for \\textsc{Yacas} core engine are: portability,\nself-containment (no dependence on extra libraries or packages), ease of\nimplementing algorithms, code transparency, and flexibility. The \\textsc{Yacas}\nsystem as a whole falls into the ``prototype/hacker\" rather than into the\n``axiom/algebraic\" category, according to the terminology of Fateman\n\\cite{F90}. There are relatively few specific design decisions related to\nmathematics, but instead the emphasis is made on extensibility.\n\n\nThe kernel offers sufficiently rich but basic functionality through a limited\nnumber of core functions. This core functionality includes substitutions and\nrewriting of symbolic expression trees, an infix syntax parser, and arbitrary\nprecision numerics. The kernel does not contain any definitions of symbolic\nmathematical operations and tries to be as general and free as possible of\npredefined notions or policies in the domain of symbolic computation.\n\nThe plugin inter-operability mechanism allows to extend the \\textsc{Yacas} kernel or to use external libraries, e.g.~GUI toolkits or implementations of special-purpose algorithms. A simple C++ API is provided for writing ``stubs'' that make external functions appear in \\textsc{Yacas} as new core functions. Plugins are on the same footing as the \\textsc{Yacas} kernel and can in principle manipulate all \\textsc{Yacas} internal structures. Plugins can be compiled either statically or dynamically as shared libraries to be loaded at runtime from \\textsc{Yacas} scripts. \n\n%\nThe script library contains declarations of transformation rules and of function\nsyntax (prefix, infix etc.). The intention is that almost all symbolic manipulation algorithms and definitions\nof mathematical functions should be held in the script library and not in the kernel. \n%The only exception so far is for a very small number of mathematical or utility functions that are frequently used; they are compiled into the core for speed.\n\n\nFor example, the mathematical operator ``\\texttt{+}\" is an infix operator defined in the\nlibrary scripts. To the kernel, this operator is on the same footing as any\nother function defined by the user and can be redefined. The \\textsc{Yacas} kernel\nitself does not store any properties for this operator. Instead it relies\nentirely on the script library to provide transformation rules for manipulating\nexpressions involving the operator ``\\texttt{+}\". In this way, the kernel does not need\nto anticipate all possible meanings of the operator ``\\texttt{+}\" that users might need\nin their calculations.\n\n\\section{Advantages of \\textsc{Yacas}}\n\nThe ``policy-free\" kernel design means that \\textsc{Yacas} is highly configurable\nthrough its scripting language. It is possible to create an entirely different\nsymbolic manipulation engine based on the same kernel, with different syntax\nand different naming  conventions, by loading another script library. An example of the flexibility of the\n\\textsc{Yacas} system is a sample script \\texttt{wordproblems.ys}. It contains\na set of rule definitions that make \\textsc{Yacas} recognize simple English\nsentences, e.g.~``Tom has 3 chairs\" or ``Jane gave an apple to Jill\", as\nvalid \\textsc{Yacas} expressions. \\textsc{Yacas} can then ``evaluate\" these\nsentences to \\texttt{True} or \\texttt{False} according to the semantics of the\ndescribed situation.\n\nThis example illustrates a major advantage of \\textsc{Yacas}---the flexibility of its syntax. Although \\textsc{Yacas}\nworks internally as a LISP-style interpreter,\nthe script language has a C-like grammar. Infix operators\ndefined in the script library or by the user may contain non-alphabetic characters such as ``\\texttt{=}\"\nor ``\\verb|#|\". This means that the user works with a comfortable and adjustable infix syntax,\nrather than a LISP-style syntax. The user can introduce such syntactic\nconventions as are most convenient for a given problem.\nFor example, algebraic expressions can be entered\nin the familiar infix form such as\n%\n\\begin{quote}\\small\\begin{verbatim}\n(x+1)^2 - (y-2*z)/(y+3) + Sin(x*Pi/2)\n\\end{verbatim}\\end{quote}\n%\nThe same syntactic flexibility is available for defining transformation rules.\nSuppose the user needs to reorder expressions containing non-commutative\noperators of quantum theory. It takes about 20\nrules to define an infix operation ``\\texttt{**}\"\nto express non-commutative multiplication with the appropriate commutation\nrelations and to automatically reorder all expressions involving both non-commutative and commutative factors. Thanks to the \\textsc{Yacas} parser,\nthe rules for the new operator can be written in a simple and readable form. Once the operator\n``\\texttt{**}\" is defined, the rules that express distributivity of this operation\nwith respect to addition may look like this:\n\\begin{quote}\\small\\begin{verbatim}\n15 # (_x + _y) ** _z <-- x ** z + y ** z;\n15 # _z ** (_x + _y) <-- z ** x + z ** y;\n\\end{verbatim}\\end{quote}\nHere, ``\\verb|15 #|\" is a specification of the rule precedence, ``\\verb|_x|\" denotes a\npattern-matching variable \\texttt{x} and the expression to the right of ``\\texttt{<--}\" is to be\nsubstituted instead of a matched expression on the left hand side.\n\nRule-based and functional programming can be freely combined with procedural\nprogramming style when the latter is more appropriate for reasons of efficiency or simplicity. Standard\npatterns of procedural programming, such as subroutines that return values,\nwith code blocks and temporary local variables, the familiar \\texttt{if} /\n\\texttt{else} construct and \\texttt{For()},\n\\texttt{ForEach()} loop functions are defined in the script library for the\nconvenience of users. The \\textsc{Yacas} interpreter is sufficiently powerful\nto define these functions in the script library itself rather than in the\nkernel. This power is fully given to the user, since the library scrips are on\nthe same footing as any user-defined code. Many library functions are intended\nmainly as tools available to a \\textsc{Yacas} user to make algorithm\nimplementation more comfortable.\n\n% more advantages?\n%\n\n\\section{The \\textsc{Yacas} kernel functionality}\n\n\\textsc{Yacas} script is a functional language based on various ideas that\nseemed useful for an implementation of a CAS: list-based data structures,\nobject properties, functional programming (\\`{a} la LISP); term rewriting\n\\cite{BN98} with pattern matching somewhat along the lines of\n\\textsc{Mathematica}; user-defined infix operators \\'{a} la PROLOG; delayed\nevaluation of expressions; and arbitrary precision arithmetic. Garbage\ncollection is implemented through reference counting.\n\n\nThe kernel provides three basic data types: numbers, strings, and atoms and\ntwo container types: list and static array (for speed). Additional container or data types (``generic objects'') can be made available through C++ plugins. Atoms are implemented\nas strings that can be assigned values and evaluated. Boolean values are simply\natoms \\texttt{True} and \\texttt{False}. Hash tables, stacks, and\nclosures (pure functions) are implemented using nested lists. Kernel primitives are available for arbitrary\nprecision arithmetic, string and list manipulation, control flow, defining\ntransformation rules, and declaring function  syntax. Expression trees are\ninternally represented by nested lists. Expressions can be ``tagged\" (assigned a\n``property object\" \\`{a} la LISP).\n\nThe interpreter engine recursively evaluates expression trees according to\nthe transformation rules from the script library.\nEvaluation proceeds from the leaves of the tree upwards. The engine tries to apply all existing rules to each subexpression, rewriting leaves or branches of the expression tree, until no more rules apply.\n%\nThis type of semantic matching has been implemented in the past\n(see, e.g., \\cite{C86}). However, the \\textsc{Yacas} language\nincludes some advanced features to create a more flexible and powerful term\nrewriting system.\n\nRules have predicates that determine whether a\nrule should be applied to an expression. Predicates can be any \\textsc{Yacas}\nexpressions that evaluate to the atoms \\texttt{True} or \\texttt{False} and are typically\nfunctions of pattern variables.\n\nAll rules are assigned a precedence value (a positive integer) and\nrule matching is attempted in the order of precedence. (Thus \\textsc{Yacas} provides somewhat better control\nover the automatic recursion than e.g.~the pattern-matching system of \\textsc{Mathematica}\nwhich does not allow for rule precedence.)\n% example\nUsing rule precedence and predicates, a\nrecursive implementation of the integer factorial function may look like this:\n%\n\\begin{quote}\\small\\begin{verbatim}\n10 # Factorial(0) <-- 1;\n20 # Factorial(n_IsInteger) _ (n>0) <-- n*Factorial(n-1);\n\\end{verbatim}\\end{quote}\n%\nThe rules have precedence $10$ and $20$, therefore the first rule will be tried first and the recursion will stop when $n = 0$ is reached.\n\nNew rules can be defined dynamically as a side-effect of evaluation.\nThis means that there is no predefined ``ranking alphabet\" of ``ground terms\"\n(in the terminology of \\cite{TATA99}). It is possible to define a ``rule closure\"\nthat defines rules depending on its arguments, or to erase rules. Thus, a\n(read-only) \\textsc{Yacas} script library does not actually represent a\nfixed tree rewriting automaton; an implementation of machine learning is\npossible.\n\n%A \\texttt{HoldArg()} primitive is provided to not evaluate certain arguments of certain functions before passing them on as parameters to these functions. The \\texttt{Hold()} and \\texttt{Eval()} primitives, similarly to LISP's \\texttt{QUOTE} and \\texttt{EVAL}, can be used to stop the recursive application of rules at a certain point and obtain an unevaluated expression, or to initiate evaluation of an expression which was previously held unevaluated.\n\nThe Knuth-Bendix termination algorithm \\cite{KB70} is not used because rules in \\textsc{Yacas} are not an expression of mathematical equivalence but a programming technique. Termination is the responsibility of the user who has complete control over the order of rule application.\n\n\n\\section{Current status}\n\nCurrently, the script library implements basic algorithms of computer algebra:\nmanipulation of polynomials and elementary functions, limits, derivatives and\n(basic) symbolic integration, solution of (simple) equations, and some special-purpose\nfunctions. (The primary sources of inspiration were the books \\cite{K98}, \\cite{GG99} and\n\\cite{B86}.) The system is free (GNU GPL) software and comes with ample documentation to facilitate cooperative development. The main Internet site for \\textsc{Yacas} is \\texttt{http://www.xs4all.nl/\\homedir apinkus/}.\n\nThe main development platform is GNU/Linux, but \\textsc{Yacas} runs also\nunder various Unix flavors,  Windows environments, Psion organizers (EPOC32),\nIpaq PDAs running the Linux kernel, BeOS, and Mac OS X. Creating an\nexecutable for another platform (including embedded platforms) should not be\ndifficult.\n\nIn the future, \\textsc{Yacas} is intended to grow into a general-purpose CAS as well as a repository and a testbed of algorithms.\nIn our opinion, \\textsc{Yacas} is a promising research tool for exploring symbolic computation.\n\n%%% End of main text\n\n\\begin{thebibliography}{TATW99}\n\n\\bibitem[ASU86]{ASU86} A. Aho, R. Sethi and J. Ullman, \\emph{Compilers (Principles, Techniques and Tools)}, Addison-Wesley, 1986.\n\n\n\\bibitem[B86]{B86} I. Bratko, \\emph{Prolog (Programming for Artificial Intelligence)}, Addison-Wesley, 1986.\n\n\n\\bibitem[BN98]{BN98} F. Baader and T. Nipkow, \\emph{Term rewriting and all that}, Cambridge University Press, 1998.\n\n\n\\bibitem[C86]{C86} G. Cooperman, \\emph{A semantic matcher for computer algebra}, in Proceedings of the symposium on symbolic and algebraic computation (1986), Waterloo, Ontario, Canada (ACM Press, NY).\n\n\n\\bibitem[F90]{F90} R. Fateman, \\emph{On the design and construction of algebraic manipulation systems}, also published as: ACM Proceedings of the ISSAC-90, Tokyo, Japan.\n\n\n\\bibitem[GG99]{GG99} J. von zur Gathen and J. Gerhard, \\emph{Modern Computer Algebra}, Cambridge University Press, 1999.\n\n\n\\bibitem[K98]{K98} D. E. Knuth, \\emph{The Art of Computer Programming (Volume 2, Seminumerical Algorithms)}, Addison-Wesley, 1998.\n\n\\bibitem[KB70]{KB70} D. E. Knuth and P. B. Bendix, \\emph{Simple word problems in universal algebras}, in \\emph{Computational problems in abstract algebra}, ed.~J. Leech, p.~263, Pergamon Press, 1970.\n\n\n%\\bibitem[M98]{M98} See, for example, M. B. Monagan \\emph{et al.}: \\emph{Maple V programming guide,} Springer-Verlag, Berlin, 1998.\n\n\n\\bibitem[TATA99]{TATA99} H. Comon, M. Dauchet, R. Gilleron, F. Jacquemard, D. Lugiez, S. Tison, and M. Tommasi, \\emph{Tree Automata Techniques and Applications}, 1999, online book: {\\small \\verb|http://www.grappa.univ-lille3.fr/tata|}\n\n\n%\\bibitem[W96]{W96} S. Wolfram, \\emph{The Mathematica book}, Wolfram Media, Champain, 1996.\n\n\n\\bibitem[WH89]{WH89} P. Winston and B. Horn, \\emph{LISP}, Addison-Wesley, 1989.\n\n\n\\end{thebibliography}\n\n\\end{document}\n"
  },
  {
    "path": "papers/paper2.tex",
    "content": "\\documentclass{llncs}\n\n\\begin{document}\n\n\\title{YACAS: A Do-it-yourself Symbolic Algebra Environment}\n\n\\author{Ayal Zwi Pinkus\\inst{1} \\and Serge Winitzki\\inst{2}}\n\\institute{3e Oosterparkstraat 109-III,\nAmsterdam, The Netherlands\n(\\email{apinkus@xs4all.nl})\n\\and\nTufts Institute of Cosmology, Department of Physics and Astronomy, Tufts University, Medford, MA 02155, USA\n(\\email{serge@cosmos.phy.tufts.edu})\n}\n\n\\maketitle\n\n\\begin{abstract}\nWe describe the design and implementation of \\textsc{Yacas}, a free computer\nalgebra system currently under development.  The system consists of a core\ninterpreter and a library of scripts that implement symbolic algebra\nfunctionality.  The interpreter provides a high-level weakly typed functional\nlanguage designed for quick prototyping of computer algebra algorithms, but the \nlanguage is suitable for all kinds of symbolic manipulation. It supports\nconditional term rewriting of symbolic expression trees, closures (pure\nfunctions) and delayed evaluation, dynamic creation of transformation rules,\narbitrary-precision numerical calculations, and flexible user-defined syntax\nusing infix notation.  The library of scripts currently provides basic\nnumerical and symbolic algebra functionality, such as polynomials and\nelementary functions, limits, derivatives and (limited) integration, solution\nof (simple) equations. The main advantages of \\textsc{Yacas} are: free (GPL)\nsoftware; a\nflexible and easy-to-use programming language with a comfortable and adjustable\nsyntax; cross-platform portability and small resource requirements; and extensibility.\n\\end{abstract}\n\n%%% Start of main text\n\n\n\\section{%\nIntroduction}\n\\textsc{Yacas} is a computer algebra system (CAS) which has been in development since the beginning of 1999.\nThe goal was to make a small system that allows to easily prototype and\nresearch symbolic mathematics algorithms. A secondary future goal is to evolve\n\\textsc{Yacas} into a full-blown general purpose CAS.\n%end of paragraph\n\n\\textsc{Yacas} is primarily intended to be a research tool for easy\nexploration and prototyping of algorithms of symbolic\ncomputation.  The main advantage of \\textsc{Yacas} is its rich and flexible\nscripting language. The language is closely related to LISP \\small{\\texttt{WH89}} but has\na recursive descent infix grammar parser \\small{\\texttt{ASU86}} which supports defining \ninfix operators at run time similarly to Prolog \\small{\\texttt{B86}}, and includes \nexpression transformation (term rewriting) as a basic feature of the\nlanguage.\n%end of paragraph\n\nThe \\textsc{Yacas} language interpreter comes with a library of scripts that implement a set of computer algebra features. The \\textsc{Yacas} script library\nis in active development and at the present stage does not offer the rich functionality of\nindustrial-strength systems such as \\small{\\texttt{Mathematica}} or \\small{\\texttt{Maple}}.\nExtensive\nimplementation of algorithms of symbolic computation is one of the future\ndevelopment goals.\n%end of paragraph\n\n\\textsc{Yacas} handles input and output in plain ASCII,\neither interactively or in batch mode. (A graphical interface is under development.) There is also an optional plugin mechanism\nwhereby external libraries can be linked into the system to provide extra\nfunctionality. Basic facilities are in place to compile Yacas scripts\nto C++ so they can be compiled into plugins.\n%end of paragraph\n\n\\section{%\nBasic design}\n\\textsc{Yacas} consists of a ``core engine\" (kernel), which is an interpreter\nfor the \\textsc{Yacas} scripting language, and a library of script code.\n%end of paragraph\n\nThe\n\\textsc{Yacas} engine has been implemented in a subset of C++ which is\nsupported by almost all C++ compilers.\nThe design goals for \\textsc{Yacas} core engine are: portability,\nself-containment (no dependence on extra libraries or packages), ease of\nimplementing algorithms, code transparency, and flexibility. The \\textsc{Yacas}\nsystem as a whole falls into the ``prototype/hacker\" rather than into the\n``axiom/algebraic\" category, according to the terminology of Fateman\n\\small{\\texttt{F90}}. There are relatively few specific design decisions related to\nmathematics, but instead the emphasis is made on extensibility.\n%end of paragraph\n\nThe kernel offers sufficiently rich but basic functionality through a limited\nnumber of core functions. This core functionality includes substitutions and\nrewriting of symbolic expression trees, an infix syntax parser, and arbitrary\nprecision numerics. The kernel does not contain any definitions of symbolic\nmathematical operations and tries to be as general and free as possible of\npredefined notions or policies in the domain of symbolic computation.\n%end of paragraph\n\nThe plugin inter-operability mechanism allows extension of the \\textsc{Yacas} kernel and the use of external libraries, e.g. GUI toolkits or implementations of special-purpose algorithms. A simple C++ API is provided for writing ``stubs'' that make external functions appear in \\textsc{Yacas} as new core functions. Plugins are on the same footing as the \\textsc{Yacas} kernel and can in principle manipulate all \\textsc{Yacas} internal structures. Plugins can be compiled either statically or dynamically as shared libraries to be loaded at runtime from \\textsc{Yacas} scripts. \nIn addition, \\textsc{Yacas} scripts can be compiled to C++ code for further\ncompilation into a plugin. Systems that don't support plugins can then\nlink these modules in statically. The system can also be run without\nthe plugins, for debugging and development purposes. The scripts\nwill be interpreted in that case.\n%end of paragraph\n\nThe script library contains declarations of transformation rules and of function\nsyntax (prefix, infix etc.). The intention is that all symbolic manipulation algorithms, definitions\nof mathematical functions etc. should be held in the script library and not in the kernel. The\nonly exception so far is for a very small number of mathematical or utility\nfunctions that are frequently used; they are compiled into the core for speed.\n%end of paragraph\n\n\\subsection*{%\nPortability}\n\\textsc{Yacas} is designed to be as platform-independent as possible.\nAll platform-specific parts have been clearly separated to facilitate porting.\nEven the standard C++ library is considered to be platform-specific, as there\nexist  platforms without support for the standard C++ library (e.g. the\nEPOC32 platform).\n%end of paragraph\n\nThe primary development platform is GNU/Linux. Currently \\textsc{Yacas} runs under\nvarious Unix variants, Windows environments, Psion organizers (EPOC32),\nIpaq PDAs,\nBeOS, and Apple iMacs. Creating an executable for another platform (including embedded platforms)\nshould not be difficult.\n%end of paragraph\n\n\\subsection*{%\nA self-contained system}\n\\textsc{Yacas} should work as a standalone package, requiring minimum support from other\noperating system components. \\textsc{Yacas} takes input and output in plain ASCII,\neither interactively or in batch mode. (An optional graphical interface is under development.) The system comes with its own\n(unoptimized) arbitrary precision arithmetic module but could be compiled to\nuse another arbitrary precision arithmetic library; currently linking to \\small{\\texttt{gmp}}\nis experimentally supported. There is also an optional plugin mechanism\nwhereby external libraries can be linked into the system to provide extra\nfunctionality.\n%end of paragraph\n\nSelf-containment is a requirement if the program is to be easy to port. A\ndependency on libraries that might not be available on other platforms would\nreduce portability. On the other hand, \\textsc{Yacas} can be compiled with a complement\nof external libraries on ``production\" platforms.\n%end of paragraph\n\n\\subsection*{%\nEase of use}\n\\textsc{Yacas} is used mainly by executing programs written in the \\textsc{Yacas} script\nlanguage. A design goal is to create a high-level language that allows the user\nto conveniently express symbolic algorithms. A few lines of user code should go\na long way.\n%end of paragraph\n\nOne major advantage of \\textsc{Yacas} is the flexibility of its syntax. Although \\textsc{Yacas}\nworks internally as a LISP-style interpreter, all user interaction is through\nthe \\textsc{Yacas} script language which has a flexible infix grammar. Infix operators\nare defined by the user and may contain non-alphabetic characters such as ``\\small{\\texttt{=}}\"\nor ``\\small{\\texttt{\\#}}\". This means that the user interacts with \\textsc{Yacas} using a comfortable and adjustable infix syntax,\nrather than a LISP-style syntax. The user can introduce such syntactic\nconventions as are most convenient for a given problem.\n%end of paragraph\n\nFor example, the \\textsc{Yacas} script library defines infix operators ``\\small{\\texttt{+}}\", \"\\small{\\texttt{*}}\" and so\non with conventional precedence, so that an algebraic expression can be entered\nin the familiar infix form such as\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\n(x+1)^2 - (y-2*z)/(y+3) + Sin(x*Pi/2)\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nOnce such infix operators are defined, it is possible to describe new\ntransformation rules directly using the new syntax. This makes it easy to\ndevelop simplification or evaluation procedures adapted to a particular\nproblem.\n%end of paragraph\n\nSuppose the user needs to reorder expressions containing non-commutative creation and\nannihilation operators of quantum field theory. It takes about 20 lines of\n\\textsc{Yacas} script code to define an infix operation ``\\small{\\texttt{**}}\" to express non-commutative\nmultiplication with the appropriate commutation relations and to automatically\nnormal-order all expressions involving these symbols and other (commutative)\nfactors. Once the operator \\small{\\texttt{**}} is defined (with precedence 40),\n\\begin{quote}\\small\\begin{verbatim}\nInfix(\"**\", 40);\n\\end{verbatim}\\end{quote}\nthe rules that express distributivity of the operation \\small{\\texttt{**}} with\nrespect to addition may look like this:\n\\begin{quote}\\small\\begin{verbatim}\n15 # (_x + _y) ** _z <-- x ** z + y ** z;\n15 # _z ** (_x + _y) <-- z ** x + z ** y;\n\\end{verbatim}\\end{quote}\nHere, \\small{\\texttt{15 \\#}} is a specification of the rule precedence, \\small{\\texttt{\\_x}} denotes a\npattern-matching variable \\small{\\texttt{x}} and the expression to the right of \\small{\\texttt{<--}} is to be\nsubstituted instead of a matched expression on the left hand side. Since all\ntransformation rules are applied recursively, these two lines of code are enough for the \\textsc{Yacas}\nengine to expand all brackets in any expression containing the infix operators\n\\small{\\texttt{**}} and \\small{\\texttt{+}}.\n%end of paragraph\n\nRule-based programming is not the only method that can be used in \\textsc{Yacas} scripts;\nthere are alternatives that may be more useful in some situations. For example,\nthe familiar \\small{\\texttt{if}} / \\small{\\texttt{else}} constructs, \\small{\\texttt{For}}, \\small{\\texttt{ForEach}} loops are\ndefined in the script library for the convenience of users.\n%end of paragraph\n\nStandard patterns of procedural programming, such as subroutines that\nreturn values, with code blocks and temporary local variables, are also\navailable. (A ``subroutine\" is implemented as a new ``ground term\" with a single\nrule defined for it.) Users may freely combine rules with C-like\nprocedures or LISP-like list processing primitives such as \\small{\\texttt{Head()}},\n\\small{\\texttt{Tail()}}.\n%end of paragraph\n\n\\subsection*{%\nCode clarity vs. speed}\nSpeed is obviously an important factor. For \\textsc{Yacas}, where a choice had to be\nmade between speed and clarity of code, clarity was chosen. \\textsc{Yacas} is mainly a\nprototyping system and its future maintainability is more important.\n%end of paragraph\n\nThis means that special-purpose systems designed for specific types of\ncalculations, as well as heavily optimized industrial-strength computer algebra\nsystems, will outperform \\textsc{Yacas}. However, special-purpose or optimized external\nlibraries can be dynamically linked into \\textsc{Yacas} using the plugin mechanism.\n%end of paragraph\n\n\\subsection*{%\nFlexible, ``policy-free\" engine}\nThe core engine of the \\textsc{Yacas} system interprets the Yacas script language.\nThe reason to implement yet another LISP-based custom language interpreter\ninstead of taking an already existing one was to have full control over the\ndesign of the system and to make it self-contained.\nWhile most of the features of the \\textsc{Yacas} script language are ``syntactic sugar\" on top of a LISP \ninterpreter, some features not commonly found in LISP systems were added.\n%end of paragraph\n\nThe script library contains declarations of transformation rules and of function\nsyntax (prefix, infix etc.). The intention is that all symbolic manipulation algorithms, definitions\nof mathematical functions and so on should be held in the script library and not in the kernel. The\nonly exception so far is for a very small number of mathematical or utility\nfunctions that are frequently used; they are compiled into the core for speed.\n%end of paragraph\n\nFor example, the mathematical operator ``\\small{\\texttt{+}}\" is an infix operator defined in the\nlibrary scripts. To the kernel, this operator is on the same footing as any\nother function defined by the user and can be redefined. The \\textsc{Yacas} kernel\nitself does not store any properties for this operator. Instead it relies\nentirely on the script library to provide transformation rules for manipulating\nexpressions involving the operator ``\\small{\\texttt{+}}\". In this way, the kernel does not need\nto anticipate all possible meanings of the operator ``\\small{\\texttt{+}}\" that users might need\nin their calculations.\n%end of paragraph\n\nThis policy-free scheme means that \\textsc{Yacas} is highly configurable through its\nscripting language. It is possible to create an entirely different symbolic\nmanipulation engine based on the same C++ kernel, with different syntax and\ndifferent naming  conventions, by simply using another script library instead\nof the current library scripts. An example of the flexibility of the \\textsc{Yacas}\nsystem is a sample script \\small{\\texttt{wordproblems.ys}} that comes with the distribution. It contains a set of rule\ndefinitions that make \\textsc{Yacas} recognize simple English sentences, such as ``Tom\nhas 3 apples\" or ``Jane gave an apple to Tom\", as valid \\textsc{Yacas} expressions. \\textsc{Yacas}\ncan then ``evaluate\" these sentences to \\small{\\texttt{True}} or \\small{\\texttt{False}} according to\nthe semantics of the current situation described in them.\n%end of paragraph\n\nThe ``policy-free\" concept extends to typing: strong typing is not required by\nthe kernel, but can be easily enforced by the  scripts if needed for a\nparticular problem. The language offers features, but does not enforce their\nuse.\nHere is an example of a policy implemented in the script library:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\n61 # x_IsPositiveNumber ^ y_IsPositiveNumber \n      <-- MathPower(x,y);\n\\end{verbatim}\\end{quote}\nBy this rule, expressions of the form $x^y$ (representing powers $x ^{y}$) are\nevaluated and replaced by a number if and only if \\small{\\texttt{x}} and \\small{\\texttt{y}} are positive\nnumerical constants. (The function \\small{\\texttt{MathPower}} is  defined in the kernel.) If\nthis simplification by default is not desirable, the user could erase this rule\nfrom the library\nand have a CAS without this feature.\n%end of paragraph\n\n\\section{%\nThe \\textsc{Yacas} kernel functionality}\n\\textsc{Yacas} script is a functional language based on various ideas that seemed useful\nfor an implementation of CAS: list-based data structures, object properties,\nand functional programming (a la LISP); term rewriting [BN98] with\npattern matching somewhat along the lines of Mathematica; user-defined infix\noperators a la PROLOG; delayed evaluation of expressions; and\narbitrary-precision arithmetic.\nGarbage collection is implemented through reference counting.\n%end of paragraph\n\nThe kernel provides three basic data types: numbers,\nstrings, and atoms, and two container types: list and static array (for speed).\nAtoms are implemented as strings that can be assigned values and evaluated.\nBoolean values are simply atoms \\small{\\texttt{True}} and \\small{\\texttt{False}}. Numbers are \nrepresented by objects on which arithmetic can be performed\nimmediately. Expression trees, association (hash) tables,\nstacks, and closures (pure functions) are all implemented using nested lists. In\naddition, more data types can be provided by plugins. Kernel primitives are\navailable for arbitrary-precision arithmetic, string manipulation, array and\nlist access and manipulation, for basic control flow, for assigning variables (atoms) and for defining rules for functions (atoms with a function syntax).\n%end of paragraph\n\nThe interpreter engine recursively evaluates expression trees according to\nuser-defined transformation rules from the script library.\nEvaluation proceeds bottom-up, that is, for each function term, the arguments are evaluated first and then the function is applied to these values.\n%end of paragraph\n\nA \\small{\\texttt{HoldArg()}} primitive is provided to not evaluate certain arguments of\ncertain functions before passing them on as parameters to these functions. The\n\\small{\\texttt{Hold()}} and \\small{\\texttt{Eval()}} primitives, similarly to LISP's \\small{\\texttt{QUOTE}} and \\small{\\texttt{EVAL}}, can\nbe used to stop the recursive application of rules at a certain point and\nobtain an unevaluated expression, or to initiate evaluation of an expression\nwhich was previously held unevaluated.\n%end of paragraph\n\nWhen an expression can not be transformed any further, that is, when no more rules apply to it, the expression is returned\nunevaluated. For instance, a variable that is not assigned a value will\nreturn unevaluated. This is a desired behavior in a symbolic manipulation\nsystem. Evaluation is treated as a form of ``simplification\", in\nthat evaluating an expression returns a simplified form of the\ninput expression.\n%end of paragraph\n\nRules are matched by a pattern expression which can contain \\emph{pattern variables}, i.e. atoms marked by the ``\\small{\\texttt{\\_}}\" operator. During matching, each pattern variable atom becomes a local variable and is tentatively assigned the subexpression being matched. For example, the pattern \\small{\\texttt{\\_x + \\_y}} can match an expression \\small{\\texttt{a*x+b}} and then the pattern variable \\small{\\texttt{x}} will be assigned the value \\small{\\texttt{a*x}} (unevaluated) and the variable \\small{\\texttt{y}} will have the value \\small{\\texttt{b}}.\n%end of paragraph\n\nThis type of semantic matching has been frequently implemented before in\nvarious term rewriting systems (see, e.g., [C86]). However, the \\textsc{Yacas} language\noffers its users an ability to create a much more flexible and powerful term\nrewriting system than one based on a fixed set of rules. Here are some of the features:\n%end of paragraph\n\nFirst, transformation rules in \\textsc{Yacas} have predicates that control whether a\nrule should be applied to an expression. Predicates can be any \\textsc{Yacas}\nexpressions that evaluate to the atoms \\small{\\texttt{True}} or \\small{\\texttt{False}} and are typically\nfunctions of pattern variables. A predicate could check the types or\nvalues of certain subexpressions of the matching context (see the \\small{\\texttt{\\_x \\^ \\_y}}\nexample in the previous subsection).\n%end of paragraph\n\nSecond, rules are assigned a precedence value (a positive integer) that\ncontrols the order of rules to be attempted. Thus \\textsc{Yacas} provides somewhat better control\nover the automatic recursion than the pattern-matching system of \\small{\\texttt{Mathematica}}\nwhich does not allow for rule precedence.\nThe interpreter will first apply the rule that matches the argument pattern,\nfor which the predicate returns \\small{\\texttt{True}}, and which has the least precedence.\n%end of paragraph\n\nThird, new rules can be defined dynamically as a side-effect of evaluation.\nThis means that there is no predefined ``ranking alphabet\" of ``ground terms\" (in\nthe terminology of [TATA99]), in other words, no fixed set of functions with\npredefined arities. It is also possible to define a ``rule closure\" that defines\nrules depending on its arguments, or to erase rules. Thus, a \\textsc{Yacas} script\nlibrary (although it is read-only) does not represent a fixed tree rewriting\nautomaton. An implementation of machine learning is possible in \\textsc{Yacas} (among\nother things). For example, when the module \\small{\\texttt{wordproblems.ys}} (mentioned in the previous subsection) \"learns\" from the\nuser input that \\small{\\texttt{apple}} is a countable object, it defines a new postfix\noperator \\small{\\texttt{apples}} and a rule for its evaluation, so the expression \\small{\\texttt{3 apples}} is later parsed as a\nfunction \\small{\\texttt{apples(3)}} and evaluated according to the rule.\n%end of paragraph\n\nFourth, \\textsc{Yacas} expressions can be ``tagged\" (assigned a ``property object\" a la\nLISP) and tags can be checked by predicates in rules or used in the evaluation.\n%end of paragraph\n\nFifth, the scope of variables can be controlled. In addition to having its own\nlocal variables, a function can be allowed to access local variables of its\ncalling environment (the \\small{\\texttt{UnFence()}} primitive).\nIt is also possible to encapsulate a group of variables and functions into a\n``module\", making some of them inaccessible from the outside (the \\small{\\texttt{LocalSymbols()}} primitive).\nThe scoping of variables is a ``policy decision\", to be enforced by the script\nwhich  defines the function. This flexibility is by design and allows to easily\nmodify the behavior of the interpreter, effectively changing the language\nas needed.\n%end of paragraph\n\n\\section{%\nThe \\textsc{Yacas} scripting language}\nThe \\textsc{Yacas} interpreter is sufficiently powerful so that the functions \n\\small{\\texttt{For}}, \\small{\\texttt{ForEach}}, \\small{\\texttt{if}}, \\small{\\texttt{else}} etc., as well as the convenient shorthand\n``...\\small{\\texttt{<--}}...\" for defining new rules, can be defined in the script library\nitself rather than in the kernel. This power is fully given to the user, since\nthe library scripts are on the same footing as any user-defined code. Some\nlibrary functions are intended mainly as tools available to a \\textsc{Yacas} user to\nmake algorithm implementation more comfortable. Below are some examples of the features provided by the \\textsc{Yacas} script language.\n%end of paragraph\n\n\\textsc{Yacas} supports ``function overloading\": it allows a user to declare functions\n\\small{\\texttt{f(x)}} and \\small{\\texttt{f(x,y)}}, each having their own set of transformation rules. Of\ncourse, different rules can be defined for the same function name with the same\nnumber of arguments (arity) but with different argument patterns or different\npredicates.\n%end of paragraph\n\nSimple transformations on expressions can be performed using rules. For\ninstance, if we need to expand the natural logarithm in an expression, we could\nuse the following rules:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nlog(_x * _y) <-- log(x) + log(y);\nlog(_x ^ _n) <-- n * log(x);\n\\end{verbatim}\\end{quote}\nThese two rules define a new symbolic function \\small{\\texttt{log}} which will not be evaluated\nbut only transformed if one of these two rules are applicable. The symbol \\small{\\texttt{\\_}}, as before, indicates that the following atom is a pattern variable that matches subexpressions.\n%end of paragraph\n\nAfter entering these two rules, the following interactive session is possible:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> log(a*x^2)\n\nlog( a ) + 2 * log( x )\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nIntegration of the new function \\small{\\texttt{log}} can be defined by adding a rule for the\n\\small{\\texttt{AntiDeriv}} function atom,\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nAntiDeriv(_x,log(_x)) <-- x*log(x)-x;\n\\end{verbatim}\\end{quote}\nNow \\textsc{Yacas} can do integrations involving the newly defined \\small{\\texttt{log}} function, for example:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> Integrate(x)log(a*x^n)\n\nlog( a ) * x + n * ( x * log( x ) - x ) + C18\n\nIn> Integrate(x,B,C)log(a*x^n)\n\nlog( a ) * C + n * ( C * log( C ) - C ) -\n\n( log( a ) * B + n * ( B * log( B ) - B ) )\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nRules are applied when their associated patterns match and when their\npredicates return \\small{\\texttt{True}}. Rules also have precedence, an integer value\nto indicate which rules need to be applied first. Using these features, a\nrecursive implementation of the integer factorial function may look like this\nin \\textsc{Yacas} script,\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\n10 # Factorial(_n) _ (n=0) <-- 1;\n20 # Factorial(n_IsInteger) _ (n>0) <--\n  n*Factorial(n-1);\n\\end{verbatim}\\end{quote}\nHere the rules have precedence 10 and 20, so that the first rule will be tried first and the recursion will stop when $n = 0$ is reached.\n%end of paragraph\n\nRule-based programming can be freely combined with procedural programming when\nthe latter is a more appropriate method. For example, here is a function that\ncomputes ($x ^{n}\\bmod m$) efficiently:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\npowermod(x_IsPositiveInteger, \n   n_IsPositiveInteger,\n   m_IsPositiveInteger) <--\n[\n  Local(result);\n  result:=1;\n  x:=Mod(x,m);\n  While(n != 0)\n  [\n    if ((n&1) = 1)\n\t[\n      result := Mod(result*x,m);\n    ];\n    x := Mod(x*x,m);\n    n := n>>1;\n  ];\n  result;\n];\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nInteraction with the function \\small{\\texttt{powermod(x,n,m)}} would then look like this:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> powermod(2,10,100)\nOut> 24;\nIn> Mod(2^10,100)\nOut> 24;\nIn> powermod(23234234,2342424234,232423424)\nOut> 210599936;\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\n\\section{%\nCurrently supported CAS features}\n\\textsc{Yacas} consists of approximately 22000 lines of C++ code and  13000 lines of \nscripting code, with 170 functions defined in the C++ kernel and 600 functions\ndefined  in the scripting language. These numbers are deceptively small. The\nprogram is written in clean and simple style to keep it maintainable. Excessive\noptimization tends to bloat software and make it less readable.\n%end of paragraph\n\nA base of mathematical capabilities has already been implemented in the script\nlibrary (the primary sources of inspiration were the books [K98], [GG99] and\n[B86]). The script library is currently under active development.  The\nfollowing section demonstrates a few facilities already offered in the  current\nsystem.\n%end of paragraph\n\nBasic operations of elementary calculus have been implemented:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> Limit(n,Infinity)(1+(1/n))^n\n\nExp( 1 )\n\nIn> Limit(h,0) (Sin(x+h)-Sin(x))/h\n\nCos( x )\n\nIn> Taylor(x,0,5)ArcSin(x)\n\n     3        5\n    x    3 * x \nx + -- + ------\n    6      40  \n\nIn> InverseTaylor(x,0,5)Sin(x)\n\n     5    3    \n3 * x    x     \n------ + -- + x\n  40     6     \n\nIn> Integrate(x,a,b)Ln(x)+x\n\n                   2   /                    2 \\\n                  b    |                   a  |\nb * Ln( b ) - b + -- - | a * Ln( a ) - a + -- |\n                  2    \\                   2  /\n\nIn> Integrate(x)1/(x^2-1)\n\nLn( 2 * ( x - 1 ) )   Ln( 2 * ( x + 1 ) )      \n------------------- - ------------------- + C38\n         2                     2               \n\nIn> Integrate(x)Sin(a*x)^2*Cos(b*x)\n\nSin( b * x )   Sin( -2 * x * a + b * x )   \n------------ - ------------------------- - \n   2 * b          4 * ( -2 * a + b )       \n\nSin( -2 * x * a - b * x )      \n------------------------- + C39\n   4 * ( -2 * a - b )          \n\nIn> OdeSolve(y''==4*y)\n\nC193 * Exp( -2 * x ) + C195 * Exp( 2 * x )\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nSolving systems of equations has been implemented using a generalized Gaussian\nelimination scheme:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> Solve( {x+y+z==6, 2*x+y+2*z==10, \\ \nIn> x+3*y+z==10}, \\ \nIn>      {x,y,z} ) [1]\nOut> {4-z,2,z};\n\\end{verbatim}\\end{quote}\n(The solution of this underdetermined system is returned as a vector, so $x = 4 - z$, $y = 2$, and $z$ remains arbitrary.)\n%end of paragraph\n\nA small theorem prover [B86] using a resolution principle is offered:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> CanProve(P Or (Not P And Not Q))\n\nNot( Q ) Or P\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> CanProve(a > 3 And a < 2)\n\nFalse\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nVarious exact and arbitrary-precision numerical algorithms have been\nimplemented:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> N(1/7,40);    // evaluate to 40 digits\nOut> 0.1428571428571428571428571428571428571428;\nIn> Decimal(1/7);    // obtain decimal period\nOut> {0,{1,4,2,8,5,7}};\nIn> N(LnGamma(1.234+2.345*I)); // gamma-function\nOut> Complex(-2.13255691127918,0.70978922847121);\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nVarious domain-specific expression simplifiers are available:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> RadSimp(Sqrt(9+4*Sqrt(2)))\n\nSqrt( 8 ) + 1\n\nIn> TrigSimpCombine(Sin(x)^2+Cos(x)^2)\n\n1\n\nIn> TrigSimpCombine(Cos(x/2)^2-Sin(x/2)^2)\n\nCos( x )\n\nIn> GcdReduce((x^2+2*x+1)/(x^2-1),x)\n\nx + 1\n-----\nx - 1\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nUnivariate polynomials are supported in a dense representation, \nand multivariate polynomials in a sparse representation:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> Factor(x^6+9*x^5+21*x^4-5*x^3-54*x^2-12*x+40)\n\n         3            2            \n( x + 2 )  * ( x - 1 )  * ( x + 5 )\n\nIn> Apart(1/(x^2-x-2))\n\n      1               1      \n------------- - -------------\n3 * ( x - 2 )   3 * ( x + 1 )\n\nIn> Together(%)\n\n         9         \n-------------------\n     2             \n9 * x  - 9 * x - 18\n\nIn> Simplify(%)\n\n     1     \n----------\n 2        \nx  - x - 2\n\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nVarious ``syntactic sugar\" functions are defined to more easily enter\nexpressions:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> Ln(x*y) /: { Ln(_a*_b) <- Ln(a) + Ln(b) }\n\nLn( x ) + Ln( y )\n\nIn> Add(x^(1 .. 5))\n\n     2    3    4    5\nx + x  + x  + x  + x \n\nIn> Select(\"IsPrime\", 1 .. 15)\nOut> {2,3,5,7,11,13};\n\n\\end{verbatim}\\end{quote}\nGroebner bases [GG99] have been implemented:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> Groebner({x*(y-1),y*(x-1)})\n\n/           \\\n| x * y - x |\n|           |\n| x * y - y |\n|           |\n| y - x     |\n|           |\n|  2        |\n| y  - y    |\n\\           /\n\\end{verbatim}\\end{quote}\n(From this it  follows that $x = y$, and $x ^{2} = x$ so $x$ is $0$ or $1$.)\n%end of paragraph\n\nSymbolic inverses of matrices:\n%end of paragraph\n\n\\begin{quote}\\small\\begin{verbatim}\nIn> Inverse({{a,b},{c,d}})\n\n/                                      \\\n| /       d       \\ /    -( b )     \\  |\n| | ------------- | | ------------- |  |\n| \\ a * d - b * c / \\ a * d - b * c /  |\n|                                      |\n| /    -( c )     \\ /       a       \\  |\n| | ------------- | | ------------- |  |\n| \\ a * d - b * c / \\ a * d - b * c /  |\n\\                                      /\n\\end{verbatim}\\end{quote}\n%end of paragraph\n\nThis list of features is not exhaustive. \n%end of paragraph\n\n\\section{%\nInterface}\nCurrently, \\textsc{Yacas} is primarily a text-oriented application with interactive\ninterface through the text console. Commands are entered and evaluated line by\nline; files containing longer code may be loaded and evaluated. A ``notebook\"\ninterface under the GNU Emacs editor is available. There is also an experimental\ngraphical interface (\\small{\\texttt{proteus}}) for Unix and Windows environments.\n%end of paragraph\n\nDebugging facilities are implemented, allowing to trace execution of a\nfunction, trace application of a given rule pattern, examine the stack when\nrecursion did not terminate, or an online debugger from the\ncommand line. An experimental debug version of the \\textsc{Yacas}\nexecutable that provides more detailed information can be compiled.\n%end of paragraph\n\n\\section{%\nDocumentation}\nThe documentation for the \\textsc{Yacas} is extensive and is actively updated, following\nthe development of the system. Documentation currently consists of two tutorial\nguides (user's introduction and programmer's introduction), a collection of\nessays that describe some advanced features in more detail, and a full\nreference manual.\n%end of paragraph\n\n\\textsc{Yacas} currently comes with its own document formatting module that allows \nmaintenance of documentation in a special plain text format with a minimal \nmarkup.\nThis text format is automatically converted to HTML, $\\textrm{\\LaTeX\\/}$, PostScript and\nPDF formats. The HTML version of the documentation is hyperlinked and is used\nas online help available from the \\textsc{Yacas} prompt.\n%end of paragraph\n\n\\section{%\nFuture plans}\nThe long-term goal for \\textsc{Yacas} is to become an industrial-strength CAS and to\nremain a flexible research tool for easy prototyping of various methods of\nsymbolic calculations. \\textsc{Yacas} is meant to be a repository and a\ntestbed for such algorithm prototypes.\n%end of paragraph\n\nThe plugin facility will be extended in the future, so that a rich set of extra\nadditional libraries (especially free software libraries), system-specific as\nwell as mathematics-oriented, should be loadable from the \\textsc{Yacas} system. The\nissue of speed is also continuously being addressed. \n%end of paragraph\n\n%%% End of main text\n\n\\begin{thebibliography}{TATW99}\n\n\\bibitem[ASU86]{ASU86} A. Aho, R. Sethi and J. Ullman, \\emph{Compilers (Principles, Techniques and Tools)}, Addison-Wesley, 1986.\n\n\n\\bibitem[B86]{B86} I. Bratko, \\emph{Prolog (Programming for Artificial Intelligence)}, Addison-Wesley, 1986.\n\n\n\\bibitem[BN98]{BN98} F. Baader and T. Nipkow, \\emph{Term rewriting and all that}, Cambridge University Press, 1998.\n\n\n\\bibitem[C86]{C86} G. Cooperman, \\emph{A semantic matcher for computer algebra}, in Proceedings of the symposium on symbolic and algebraic computation (1986), Waterloo, Ontario, Canada (ACM Press, NY).\n\n\n\\bibitem[F90]{F90} R. Fateman, \\emph{On the design and construction of algebraic manipulation systems}, also published as: ACM Proceedings of the ISSAC-90, Tokyo, Japan.\n\n\n\\bibitem[GG99]{GG99} J. von zur Gathen and J. Gerhard, \\emph{Modern Computer Algebra}, Cambridge University Press, 1999.\n\n\n\\bibitem[K98]{K98} D. E. Knuth, \\emph{The Art of Computer Programming (Volume 2, Seminumerical Algorithms)}, Addison-Wesley, 1998.\n\n\\bibitem[TATA99]{TATA99} H. Comon, M. Dauchet, R. Gilleron, F. Jacquemard, D. Lugiez, S. Tison, and M. Tommasi, \\emph{Tree Automata Techniques and Applications}, 1999, online book: {\\small \\verb|http://www.grappa.univ-lille3.fr/tata|}\n\n\n\\bibitem[W96]{W96} S. Wolfram, \\emph{The Mathematica book}, Wolfram Media, Champain, 1996.\n\n\n\\bibitem[WH89]{WH89} P. Winston and B. Horn, \\emph{LISP}, Addison-Wesley, 1989.\n\n\n\\end{thebibliography}\n\n\\end{document}\n"
  },
  {
    "path": "scripts/array.rep/code.ys",
    "content": "\n\nArray'CreateFromList(list):=\n[\n  Local(result,i);\n  result:=Array'Create(Length(list),0);\n  i:=1;\n  While (list != {})\n  [\n    result[i]:=Head(list);\n    i++;\n    list:=Tail(list);\n  ];\n  result;\n];\n\nArray'ToList(array):= (array[1 .. Array'Size(array) ]);\n\n"
  },
  {
    "path": "scripts/array.rep/code.ys.def",
    "content": "\nArray'CreateFromList\nArray'ToList\n}\n"
  },
  {
    "path": "scripts/assoc.rep/code.ys",
    "content": "\n/* Assoc : given an assoc list like for example l:={{a,2},{b,3}},\n   Assoc(b,l) will return {b,3}. if the key is not in the list,\n   it will return the atom Empty.\n*/\n\nFunction(\"Assoc\",{key,list})  Builtin'Assoc(key,list);\n\n\nAssocIndices(associndiceslist_IsList) <--\n  DestructiveReverse(MapSingle(\"Head\",associndiceslist));\n\n/// Delete an element of an associative list.\nLocalSymbols(hash, key, element, hash'expr)\n[\n\n/// AssocDelete(hash,{\"key\", value})\n10 # AssocDelete(hash_IsList, element_IsList) <--\n[\n\tLocal(index);\n\tindex := Find(hash, element);\n\tIf(\n\t\tindex > 0,\n\t\tDestructiveDelete(hash, index)\n\t);\n\tindex>0;\t// return False if nothing found\n\n];\n\n\n/// AssocDelete(hash, \"key\")\n20 # AssocDelete(hash_IsList, key_IsString) <--\n[\n\tAssocDelete(hash, Builtin'Assoc(key, hash));\n];\n\n30 # AssocDelete(hash_IsList, Empty) <-- False;\n\n//HoldArg(\"AssocDelete\", hash);\n//UnFence(\"AssocDelete\", 1);\n//UnFence(\"AssocDelete\", 2);\n\n];\t// LocalSymbols(hash, ...)\n\nAssociation'CreateFromList(list) := [\n    Local(a, e);\n\n    a := Association'Create();\n\n    ForEach(e, list)\n        Association'Set(a, e[1], e[2]);\n\n    a;\n];"
  },
  {
    "path": "scripts/assoc.rep/code.ys.def",
    "content": "Assoc\nAssocIndices\nAssocDelete\nAssociation'CreateFromList\n}\n"
  },
  {
    "path": "scripts/base.rep/math.ys",
    "content": "\n/* This file contains some math functions that can be defined based on the\n  BigNumber API. This file should only use the features supported by the\n  compiler, as it gets compiled to a plugin for speed.  \n */\n\n\n// first define the binary exponentiation algorithm, MathIntPower.\n// Later, the MathPower function will be defined through IntPower and MathLn/MathExp. Note that MathExp uses IntPower.\n\n// power x^n only for non-negative integer n\nDefun(\"PositiveIntPower\", {x,n})\n[\n  Local(result,unit);\n  If(LessThan(n,0), False,\n  [\n\tSet(unit,1);\t // this is a constant, initial value of the power\n\tSet(result, unit);\n\tIf(Equals(n,0),unit,\n\t If(Equals(n,1),x,\n\t  [\n\t\tWhile(GreaterThan(n,0))\n\t\t[\n\t\t\tIf(\n\t\t\t\tEquals(BitAnd(n,1), 1),\n//\t\t\t\tIf(\n//\t\t\t\t\tEquals(result,unit), // if result is already assigned\n//\t\t\t\t\tSet(result, x), // avoid multiplication\n\t\t\t\t\tSet(result, MathMultiply(result,x))\n//\t\t\t\t)\n\t\t\t);\n\t\t\tSet(x, MathMultiply(x,x));\n\t\t\tSet(n,ShiftRight(n,1));\n\t\t];\n\t\tresult;\n\t  ]\t \n\t )\n\t);\n  ]);\n];\n\n// power x^y only for integer y (perhaps negative)\nDefun(\"MathIntPower\", {x,y})\n\tIf(Equals(x,0),0,If(Equals(x,1),1,\n\t If(IsInteger(y),If(LessThan(y,0), // negative power, need to convert x to float to save time, since x^(-n) is never going to be integer anyway\n\t  MathDivide(1, PositiveIntPower(MathAdd(x,0.),MathNegate(y))),\n\t   // now the positive integer y calculation - note that x might still be integer\n\t  PositiveIntPower(x,y)\n\t ),\t// floating-point calculation is absent, return False\n\t False)\n\t));\n\n\nDefun(\"Trigonometry\",{x,i,sum,term})\n[\n  Local(x2,orig,eps,previousPrec,newPrec);\n  Set(previousPrec,Builtin'Precision'Get());\n  Set(newPrec,MathAdd(Builtin'Precision'Get(),2));\n  Set(x2,MathMultiply(x,x));\n  Builtin'Precision'Set(newPrec);\n  Set(eps,MathIntPower(10,MathNegate(previousPrec)));\n  While(GreaterThan(MathAbs(term),eps))\n  [\n    Set(term,MathMultiply(term,x2));\n    Set(i,MathAdd(i,1.0));\n    Set(term,MathDivide(term,i));\n    Set(i,MathAdd(i,1.0));\n    Set(term,MathDivide(MathNegate(term),i));\n    Builtin'Precision'Set(previousPrec);\n    Set(sum, MathAdd(sum, term));\n    Builtin'Precision'Set(newPrec);\n  ];\n  Builtin'Precision'Set(previousPrec);\n  sum;\n];\n\nDefun(\"MathSin\",{x})Trigonometry(x,1.0,x,x);\nDefun(\"MathCos\",{x})Trigonometry(x,0.0,1.0,1.0);\nDefun(\"MathTan\",{x})MathDivide(MathSin(x),MathCos(x));\n\nDefun(\"MathArcSin\",{int1})\n[\n  Local(result,eps);\n\tSet(result,FastArcSin(int1));\n  Local(x,q,s,c);\n  Set(q,MathSubtract(MathSin(result),int1));\n  Set(eps,MathIntPower(10,MathNegate(Builtin'Precision'Get())));\n  While(GreaterThan(MathAbs(q),eps))\n  [\n\t\tSet(s,MathSubtract(int1,MathSin(result)));\n    Set(c,MathCos(result));\n    Set(q,MathDivide(s,c));\n    Set(result,MathAdd(result,q));\n  ];\n  result;\n];\n\n\n// simple Taylor expansion, use only for 0<=x<1\nDefun(\"MathExpTaylor0\",{x})\n[\n  Local(i,aResult,term,eps);\n  // Exp(x)=Sum(i=0 to Inf)  x^(i) /(i)!\n  // Which incrementally becomes the algorithm:\n  //\n  // i <- 0\n  Set(i,0);\n  // sum <- 1\n  Set(aResult,1.0);\n  // term <- 1\n  Set(term,1.0);\n  Set(eps,MathIntPower(10,MathNegate(Builtin'Precision'Get())));\n  // While (term>epsilon)\n  While(GreaterThan(MathAbs(term),eps))\n  [\n    //   i <- i+1\n    Set(i,MathAdd(i,1));\n    //   term <- term*x/(i)\n    Set(term,MathDivide(MathMultiply(term,x),i));\n    //   sum <- sum+term\n    Set(aResult,MathAdd(aResult,term));\n  ];\n  aResult;\n];\n\n/// Identity transformation, compute Exp(x) from value=Exp(x/2^n) by squaring the value n times\nDefun(\"MathExpDoubling\", {value, n})\n[\n\tLocal(shift, result);\n\tSet(shift, n);\n\tSet(result, value);\n\tWhile (GreaterThan(shift,0))\t// will lose 'shift' bits of precision here\n\t[\n\t\tSet(result, MathMultiply(result, result));\n\t\tSet(shift, MathAdd(shift,MathNegate(1)));\n\t];\n\tresult;\n];\n\n// MathMul2Exp: multiply x by 2^n quickly (for integer n)\n// this should really be implemented in the core as a call to BigNumber::ShiftRight or ShiftLeft\nDefun(\"MathMul2Exp\", {x,n})\t// avoid roundoff by not calculating 1/2^n separately\n\tIf(GreaterThan(n,0), MathMultiply(x, MathIntPower(2,n)), MathDivide(x, MathIntPower(2,MathNegate(n))));\n// this doesn't work because ShiftLeft/Right don't yet work on floats\n//\tIf(GreaterThan(n,0), ShiftLeft(x,n), ShiftRight(x,n)\n//\t);\n\n/// MathExp(x). Algorithm: for x<0, divide 1 by MathExp(-x); for x>1, compute MathExp(x/2)^2 recursively; for 0<x<1, use the Taylor series.\n// (This is not optimal; it would be much better to use SumTaylorNum and DoublingMinus1 from elemfuncs.ys. But this should be debugged for now, since MathExp is important for many algorithms.)\n/// FIXME: No precision tracking yet. (i.e. the correct number of digits is not always there in the answer)\n\nDefun(\"MathExp\", {x})\n\tIf(Equals(x,0),1,\n\t If(LessThan(x,0),MathDivide(1, MathExp(MathNegate(x))),\n\t  If(GreaterThan(x,1), MathExpDoubling(MathExpTaylor0(MathMul2Exp(x,MathNegate(MathBitCount(x)))), MathBitCount(x)), MathExpTaylor0(x)\n\t)));\n\n// power function for non-integer argument y -- use MathExp and MathLog\n/* Serge, I disabled this one for now, until we get a compiled version of MathLog that does not hang in \n   an infinite loop. The C++ version of MathLog never terminates, so I mapped MathLog to your Internal'LnNum\n   which of course does a much better job of it. Corollary is that this function can be defined when we also\n   have Internal'LnNum in this file.\nDefun(\"MathFloatPower\", {x,y})\n\tIf(IsInteger(y), False, MathExp(MathMultiply(y,MathLog(x))));\n*/\n\n// power function that works for all real x, y\n/// FIXME: No precision tracking yet.\n\n/* Serge, as MathFloatPower cannot be defined yet, I made the \"avoid MathPower(num,float) explicit :-)\n*/\nDefun(\"MathPower\", {x,y})\n// avoid MathPower(0,float)\n\tIf(Equals(x,0),0, If(Equals(x,1),1, \n\t  If(IsInteger(y), MathIntPower(x,y), False/*MathFloatPower(x,y)*/)\n\t));\n\n\n\n\nDefun(\"MathPi\",{})\n[\n  // Newton's method for finding pi:\n  // x[0] := 3.1415926\n  // x[n+1] := x[n] + Sin(x[n])\n  Local(initialPrec,curPrec,result,aPrecision);\n  Set(aPrecision,Builtin'Precision'Get());\n\tSet(initialPrec, aPrecision);\t// target precision of first iteration, will be computed below\n  Set(curPrec, 40);  // precision of the initial guess\n  Set(result, 3.141592653589793238462643383279502884197169399);    // initial guess \n\n\t// optimize precision sequence\n\tWhile (GreaterThan(initialPrec, MathMultiply(curPrec,3)))\n  [\n\t\tSet(initialPrec, MathFloor(MathDivide(MathAdd(initialPrec,2),3)));\n  ];\n\tSet(curPrec, initialPrec);\n  While (MathNot(GreaterThan(curPrec, aPrecision)))\n  [\n \t\t// start of iteration code\n    // Get Sin(result)\n    Builtin'Precision'Set(curPrec);\n    Set(result,MathAdd(result,MathSin(result)));\n    // Calculate new result: result := result + Sin(result);\n\t\t// end of iteration code\n\t\t// decide whether we are at end of loop now\n\t\tIf (Equals(curPrec, aPrecision),\t// if we are exactly at full precision, it's the last iteration\n    [\n\t\t\tSet(curPrec, MathAdd(aPrecision,1));\t// terminate loop\n    ],\n    [\n\t\t\tSet(curPrec, MathMultiply(curPrec,3));\t// precision triples at each iteration\n\t\t\t// need to guard against overshooting precision\n \t\t\tIf (GreaterThan(curPrec, aPrecision),\n      [\n\t\t\t\tSet(curPrec, aPrecision);\t// next will be the last iteration\n      ]);\n\t\t]);\n  ];\n  Builtin'Precision'Set(aPrecision);\n  result;\n];\n\n\n\n"
  },
  {
    "path": "scripts/base.rep/math.ys.def",
    "content": "MathSin\nMathCos\nMathTan\nMathArcSin\nMathExp\nMathPower\nMathPi\nMathMul2Exp\n}\n"
  },
  {
    "path": "scripts/c_form.rep/code.ys",
    "content": "/* CForm: convert Yacas objects to C/C++ code. */\n\n/* version 0.3 */\n\n/* Changelog\n\t0.1\tCForm() derived from TeXForm() v0.4. Have basic functionality. Do not allow list manipulation, unevaluated derivatives, set operations, limits, integrals, Infinity, explicit matrices. Complex numbers and expressions are handled just like real ones. Indexed symbols are assumed to be arrays and handled literally. No declarations or prototypes are supplied. Function definitions are not handled. Sum() is left as is (can be defined as a C function).\n\t0.2 Fix for extra parens in Sin() and other functions; fixes for Exp(), Abs() and inverse trig functions\n\t0.3 Fix for indexed expressions: support a[2][3][4]\n\t0.3.1 Fix for CForm(integer): add a decimal point\n\t0.4 Support While()[]. Added IsCFormable. Use Concat() instead of Union() on lists.\n\t0.4.1 Support False, True\n  0.4.2 Changed it so that integers are not coerced to floats any more automatically (one can coerce integers to floats manually nowadays by adding a decimal point to the string representation, eg. 1. instead of 1).\n*/\n\n/* To do:\n\t0. Find and fix bugs.\n\t1. Chop strings that are longer than 80 chars?\n\t2. Optimization of C code?\n*/\n\nRuleBase(\"CForm\",{expression});\nRuleBase(\"CForm\",{expression, precedence});\n\nFunction (\"CFormBracketIf\", {predicate, string})\n[\n\tCheck(IsBoolean(predicate) And IsString(string), \"CForm internal error: non-boolean and/or non-string argument of CFormBracketIf\");\n\tIf(predicate, ConcatStrings(\"( \", string, \") \"), string);\n];\n\n/* Proceed just like TeXForm()\n*/\n\n// CFormMaxPrec should perhaps only be used from within this file, it is thus not in the .def file.\nCFormMaxPrec() := 60000;\t /* This precedence will never be bracketed. It is equal to KMaxPrec */\n\n100 # CForm(_x) <-- CForm(x, CFormMaxPrec());\n\n/* Replace numbers and variables -- never bracketed except explicitly */\n110 # CForm(x_IsInteger, _p) <-- String(x);\n111 # CForm(x_IsZero, _p) <-- \"0.\";\n112 # CForm(x_IsNumber, _p) <-- String(x);\n/* Variables are left as is, except some special ones */\n190 # CForm(False, _p) <-- \"false\";\n190 # CForm(True, _p) <-- \"true\";\n200 # CForm(x_IsAtom, _p) <-- String(x);\n\n/* Strings must be quoted but not bracketed */\n100 # CForm(x_IsString, _p) <-- ConcatStrings(\"\\\"\", x, \"\\\"\");\n\n/* Replace operations */\n\n/* arithmetic */\n\n/* addition, subtraction, multiplication, all comparison and logical operations are \"regular\" */\n\n\nLocalSymbols(cformRegularOps) [\n  cformRegularOps := { {\"+\",\" + \"}, {\"-\",\" - \"}, {\"*\",\" * \"},\n                       {\"/\",\" / \"}, {\":=\",\" = \"}, {\"==\",\" == \"},\n                       {\"=\",\" == \"}, {\"!=\",\" != \"}, {\"<=\",\" <= \"},\n                       {\">=\",\" >= \"}, {\"<\",\" < \"}, {\">\",\" > \"},\n                       {\"And\",\" && \"}, {\"Or\",\" || \"}, {\">>\", \" >> \"},\n                       { \"<<\", \" << \" }, { \"&\", \" & \" }, { \"|\", \" | \" },\n                       { \"%\", \" % \" }, { \"^\", \" ^ \" },\n                     };\n\n  CFormRegularOps() := cformRegularOps;\n]; // LocalSymbols(cformRegularOps)\n\n\t/* This is the template for \"regular\" binary infix operators:\n100 # CForm(_x + _y, _p) <-- CFormBracketIf(p<OpPrecedence(\"+\"), ConcatStrings(CForm(x, OpLeftPrecedence(\"+\")), \" + \", CForm(y, OpRightPrecedence(\"+\")) ) );\n\t*/ \n\n\t/* unary addition */\n100 # CForm(+ _y, _p) <-- CFormBracketIf(p<OpPrecedence(\"+\"), ConcatStrings(\" + \", CForm(y, OpRightPrecedence(\"+\")) ) );\n\n\t/* unary subtraction */\n100 # CForm(- _y, _p) <-- CFormBracketIf(p<OpPrecedence(\"-\"), ConcatStrings(\" - \", CForm(y, OpRightPrecedence(\"-\")) ) );\n\n\t/* power's argument is never bracketed but it must be put in braces. */\n100 # CForm(_x ^ _y, _p) <-- CFormBracketIf(p<=OpPrecedence(\"^\"), ConcatStrings(\"pow(\", CForm(x, CFormMaxPrec()), \", \", CForm(y, CFormMaxPrec()), \")\" ) );\n\n100 # CForm(if(_pred)_body, _p) <-- \"if (\":CForm(pred,60000):\") \":CForm(body);\n100 # CForm(_left else _right, _p) <-- CForm(left):\" else \":CForm(right);\n\n\nLocalSymbols(cformMathFunctions) [\n  cformMathFunctions :=\n    {\n      {\"Sqrt\",\"sqrt\"},\n      {\"Cos\",\"cos\"},\n      {\"Sin\",\"sin\"},\n      {\"Tan\",\"tan\"},\n      {\"Cosh\",\"cosh\"},\n      {\"Sinh\",\"sinh\"},\n      {\"Tanh\",\"tanh\"},\n      {\"Exp\",\"exp\"},\n      {\"Ln\",\"log\"},\n      {\"ArcCos\",\"acos\"},\n      {\"ArcSin\",\"asin\"},\n      {\"ArcTan\",\"atan\"},\n      {\"ArcCosh\",\"acosh\"},\n      {\"ArcSinh\",\"asinh\"},\n      {\"ArcTanh\",\"atanh\"},\n      {\"Max\",\"max\"},\n      {\"Min\",\"min\"},\n      {\"Abs\",\"fabs\"},\n      {\"Floor\",\"floor\"},\n      {\"Ceil\",\"ceil\"},\n    {\"!\",\"factorial\"}\n    };\n\n  CFormMathFunctions() := cformMathFunctions;\n\n]; // LocalSymbols(cformMathFunctions)\n\n/* Precedence of 120 because we'd like to process some special functions like pow() first */\n\n\n120 # CForm(expr_IsFunction, _p)_(NrArgs(expr)=2 And Contains(AssocIndices(CFormRegularOps()), Type(expr)) ) <--\n      CFormBracketIf(p<OpPrecedence(Type(expr)), ConcatStrings(CForm(Listify(expr)[2], OpLeftPrecedence(Type(expr))), CFormRegularOps()[Type(expr)], CForm(Listify(expr)[3], OpRightPrecedence(Type(expr))) ) );\n\n\n/* Sin, Cos, etc. and their argument is always bracketed */\n\n120 # CForm(expr_IsFunction, _p) _\n      (NrArgs(expr)=1 And Contains(AssocIndices(CFormMathFunctions()), Type(expr)) ) <--\n      ConcatStrings(CFormMathFunctions()[Type(expr)], \"(\", CForm( Listify(expr)[2], CFormMaxPrec()),\")\" );\n\n/* functions */\n\n/* Unknown function, precedence 200. Leave as is, never bracket the function itself and bracket the argument(s) automatically since it's a list. Other functions are precedence 100 */\n\nCFormArgs(list_IsList) <--\n[\n  Local(i,nr,result);\n  result:=\"\";\n  nr:=Length(list);\n  For (i:=1,i<=nr,i++)\n  [\n    result:=result:CForm(list[i]);\n    If (i<nr, result:=result:\", \");\n  ];\n  result;\n];\n\n\n200 # CForm(_x, _p)_(IsFunction(x)) <--\n[\n  ConcatStrings(Type(x), \"(\", CFormArgs(Tail(Listify(x))),\")\" );\n];\n\n/* Complex numbers */\n100 # CForm(Complex(0, 1), _p) <-- \"I\";\n100 # CForm(Complex(_x, 0), _p) <-- CForm(x, p);\n110 # CForm(Complex(_x, 1), _p) <-- CForm(x+Hold(I), p);\n110 # CForm(Complex(0, _y), _p) <-- CForm(Hold(I)*y, p);\n120 # CForm(Complex(_x, _y), _p) <-- CForm(x+Hold(I)*y, p);\n\n/* Some special functions: Mod */\n\n100 # CForm(Mod(_x, _y), _p) <-- CFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(CForm(x, OpPrecedence(\"/\")), \" % \", CForm(y, OpPrecedence(\"/\")) ) )\n;\n\n/* Indexed expressions are never bracketed */\n// the rule with [ ] seems to have no effect?\n//100 # CForm(_x [ _i ], _p) <-- ConcatStrings(CForm(x, CFormMaxPrec()), \"[\", CForm(i, CFormMaxPrec()), \"]\");\n100 # CForm(Nth(_x, _i), _p) <-- ConcatStrings(CForm(x, CFormMaxPrec()), \"[\", CForm(i, CFormMaxPrec()), \"]\");\n\nLocalSymbols(cindent) [\n  cindent:=1;\n\n  NlIndented():=\n  [\n    Local(result);\n// carriage return, so needs to start at the beginning of the line\n    result:=\n\"\n\";\n    Local(i);\n    For(i:=1,i<cindent,i++)\n    [\n      result:=result:\"  \";\n    ];\n    result;\n  ];\n  CIndent() :=\n  [\n  (cindent++);\n  \"\";\n  ];\n  CUndent() :=\n  [\n  (cindent--);\n  \"\";\n  ];\n]; // LocalSymbols(cindent)\n\nCFormStatement(_x) <-- CForm(x) : \";\" : NlIndented();\n\n120 # CForm(_x,_p)_(Type(x) = \"Prog\") <--\n[\n  Local(result);\n  result:=CIndent():\"{\":NlIndented();\n  ForEach(item,Tail(Listify(x)))\n  [\n    result:=result:CFormStatement(item);\n  ];\n  result:=result:\"}\":CUndent():NlIndented();\n  result;\n];\n\n120 # CForm(For(_from,_to,_step)_body,_p) <--\n  \"for(\" : CForm(from,CFormMaxPrec()) : \";\"\n\t: CForm(to,CFormMaxPrec()) : \";\"\n\t: CForm(step,CFormMaxPrec()) : \")\"\n\t: CIndent() : NlIndented()\n\t: CFormStatement(body) : CUndent();\n\n120 # CForm(While(_pred)_body, _p) <--\n\t\"while(\" : CForm(pred,CFormMaxPrec()) : \")\"\n\t: CIndent() : NlIndented()\n\t: CFormStatement(body) : CUndent();\n\n\n\n//////////////////////////////////////////////////\n/// IsCFormable\n//////////////////////////////////////////////////\n\nLocalSymbols(CFormAllFunctions) [\n\n  /// predicate to test whether an expression can be successfully exported to C code\n\n  /// interface with empty extra function list\n  // need the backquote stuff b/c we have HoldArg now\n  IsCFormable(_expr) <-- `IsCFormable(@expr, {});\n\n  // need to check that expr contains only allowed functions\n  IsCFormable(_expr, funclist_IsList) <--\n  [\n    Local(bad'functions);\n    bad'functions := Difference(`FuncList(@expr), Concat(CFormAllFunctions, funclist));\n    If(Length(bad'functions)=0,\n      True,\n      [\n        If(InVerboseMode(),\n          Echo(Concat({\"IsCFormable: Info: unexportable function(s): \"}, bad'functions))\n        );\n        False;\n      ]\n    );\n  ];\n  HoldArgNr(\"IsCFormable\", 1, 1);\n  HoldArgNr(\"IsCFormable\", 2, 1);\n\n  /// This is a list of all function atoms which CForm can safely handle\n  CFormAllFunctions := MapSingle(Atom, Concat(AssocIndices(CFormMathFunctions()), AssocIndices(CFormRegularOps()),\n  // list of \"other\" (non-math) functions supported by CForm: needs to be updated when CForm is extended to handle new functions\n  {\n    \"For\",\n    \"While\",\n    \"Prog\",\n    \"Nth\",\n    \"Mod\",\n    \"Complex\",\n    \"if\",\n    \"else\",\n    \"++\",\n    \"--\",\n  }\n  ));\n\n\n]; // LocalSymbols(CFormAllFunctions)\n\n"
  },
  {
    "path": "scripts/c_form.rep/code.ys.def",
    "content": "CForm\nIsCFormable\n}\n\n"
  },
  {
    "path": "scripts/calendar.rep/code.ys",
    "content": "// http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm\nEaster(year) := [\n\n    Check(IsPositiveInteger(year), \"Easter: the argument must be a positive integer\");\n\n    Local(a,b,c,d,e,f,g,h,i,k,L,m,month,day);\n\n    a := Mod(year, 19);\n    b := Div(year, 100);\n    c := Mod(year, 100);\n    d := Div(b, 4);\n    e := Mod(b, 4);\n    f := Div(b + 8, 25);\n    g := Div(b - f + 1, 3);\n    h := Mod(19*a + b - d - g + 15, 30);\n    i := Div(c, 4);\n    k := Mod(c, 4);\n    L := Mod(32 + 2*e + 2*i - h - k, 7);\n    m := Div(a + 11*h + 22*L, 451);\n    month := Div(h + L - 7*m + 114, 31);\n    day := Mod(h + L - 7*m + 114, 31) + 1;\n\n    { month, day };\n];\n\n"
  },
  {
    "path": "scripts/calendar.rep/code.ys.def",
    "content": "Easter\n}\n"
  },
  {
    "path": "scripts/complex.rep/code.ys",
    "content": "\n/* Complex numbers */\n\n//\n// II is the imaginary number Sqrt(-1), and remains that way.\n// The difference is it isn't converted to the form Complex(x,y).\n//\n\n10 # II^n_IsNegativeInteger <-- (-II)^(-n);\n20 # (II^_n)_(IsEven(n) = True) <-- (-1)^(n>>1);\n20 # (II^_n)_(IsOdd(n)  = True) <--  II*(-1)^(n>>1);\n\nLocalSymbols(complexReduce) [\n\n  Set(complexReduce,\n    Hold(\n    {\n      Exp(x_IsComplexII) <- Exp(ReII(x))*(Cos(ImII(x))+II*Sin(ImII(x)))\n    }));\n\n  NN(_c) <--\n  [\n    Local(result);\n    c := (c /:: complexReduce);\n    result := Coef(Expand(c,II),II,{0,1});\n    result;\n  ];\n\n]; //LocalSymbols(complexReduce)\n\n\nReII(_c) <-- NN(c)[1];\nImII(_c) <-- NN(c)[2];\nIsComplexII(_c) <-- (ImII(c) != 0);\n\n\n\n0 # Complex(_r,i_IsZero) <-- r;\n2 # Complex(Complex(_r1,_i1),_i2) <-- Complex(r1,i1+i2);\n2 # Complex(_r1,Complex(_r2,_i2)) <-- Complex(r1-i2,r2);\n\n6 # Complex(Undefined,_x) <-- Undefined;\n6 # Complex(_x,Undefined) <-- Undefined;\n\n10 # _a + Complex(0, x_IsNegativeNumber) <-- a - Complex(0, Abs(x));\n10 # _a + Complex(x_IsNegativeNumber, y_IsNegativeNumber) <-- a - Complex(Abs(x), Abs(y));\n10 # _a + Complex(x_IsNegativeNumber, y_IsNegativeNumber) * _b <-- a - Complex(Abs(x), Abs(y)) * b;\n\n/*Real parts */\n110 # Re(Complex(_r,_i)) <-- r;\n120 # Re(Undefined) <-- Undefined;\n300 # Re(_x) <-- x;\n\n/* Imaginary parts */\n110 # Im(Complex(_r,_i)) <-- i;\n120 # Im(Undefined) <-- Undefined;\n300 # Im(_x) <-- 0;\n\n/* All things you can request a real and imaginary part for are complex */\n1 # IsComplex(x_IsRationalOrNumber)     <-- True;\n2 # IsComplex(Complex(_r,_i)) <-- True;\n3 # IsComplex(_x)             <-- False;\n\nIsNotComplex(x) := Not(IsComplex(x));\n/* Addition */\n\n110 # Complex(_r1,_i1) + Complex(_r2,_i2) <-- Complex(r1+r2,i1+i2);\n300 # Complex(_r,_i) + x_IsConstant <-- Complex(r+x,i);\n300 # x_IsConstant + Complex(_r,_i) <-- Complex(r+x,i);\n\n110 # - Complex(_r,_i) <-- Complex(-r,-i);\n\n300 # Complex(_r,_i) - x_IsConstant <-- Complex(r-x,i);\n300 # x_IsConstant - Complex(_r,_i) <-- Complex((-r)+x,-i);\n111 # Complex(_r1,_i1) - Complex(_r2,_i2) <-- Complex(r1-r2,i1-i2);\n\n/* Multiplication */\n110 # Complex(_r1,_i1) * Complex(_r2,_i2) <-- Complex(r1*r2-i1*i2,r1*i2+r2*i1);\n/* right now this is slower than above\n110 # Complex(_r1,_i1) * Complex(_r2,_i2) <--\n[   // the Karatsuba trick\n    Local(A,B);\n    A:=r1*r2;\n    B:=i1*i2;\n    Complex(A-B,(r1+i1)*(r2+i2)-A-B);\n];\n*/\n\n\n// Multiplication in combination with complex numbers in the light of infinity\n250 # Complex(r_IsZero,_i) * x_IsInfinity <-- Complex(0,i*x);\n250 # Complex(_r,i_IsZero) * x_IsInfinity <-- Complex(r*x,0);\n251 # Complex(_r,_i) * x_IsInfinity <-- Complex(r*x,i*x);\n\n250 # x_IsInfinity * Complex(r_IsZero,_i) <-- Complex(0,i*x);\n250 # x_IsInfinity * Complex(_r,i_IsZero) <-- Complex(r*x,0);\n251 # x_IsInfinity * Complex(_r,_i) <-- Complex(r*x,i*x);\n\n\n300 # Complex(_r,_i) * y_IsConstant <-- Complex(r*y,i*y);\n300 # y_IsConstant * Complex(_r,_i) <-- Complex(r*y,i*y);\n\n330 # Complex(_r,_i) * (y_IsConstant / _z) <-- (Complex(r*y,i*y))/z;\n330 # (y_IsConstant / _z) * Complex(_r,_i) <-- (Complex(r*y,i*y))/z;\n\n\n110 # x_IsConstant / Complex(_r,_i) <-- (x*Conjugate(Complex(r,i)))/(r^2+i^2);\n\n\n300 # Complex(_r,_i) / y_IsConstant <-- Complex(r/y,i/y);\n\n110 # (_x ^ Complex(_r,_i)) <-- Exp(Complex(r,i)*Ln(x));\n\nUnProtect(Sqrt);\n\n110 # Sqrt(Complex(_r,_i)) <-- Exp(Ln(Complex(r,i))/2);\n110 # (Complex(_r,_i) ^ x_IsRationalOrNumber)_(Not(IsInteger(x))) <-- Exp(x*Ln(Complex(r,i)));\n\nProtect(Sqrt);\n\n// This is commented out because it used MathPower so (2*I)^(-10) became a floating-point number. Now everything is handled by binary algorithm below\n//120 # Complex(r_IsZero,_i) ^ n_IsInteger <-- {1,I,-1,-I}[1+Mod(n,4)] * i^n;\n\n123 # Complex(_r, _i) ^ n_IsNegativeInteger <-- 1/Complex(r, i)^(-n);\n\n124 # Complex(_r, _i) ^ (p_IsZero) <-- 1;   // cannot have Complex(0,0) here\n\n125 # Complex(_r, _i) ^ n_IsPositiveInteger <--\n[\n    // use binary method\n    Local(result, x);\n    x:=Complex(r,i);\n    result:=1;\n    While(n > 0)\n    [\n        if ((n&1) = 1)\n        [\n          result := result*x;\n        ];\n        x := x*x;\n        n := n>>1;\n    ];\n    result;\n];\n\n\n/*[ // this method is disabled b/c it suffers from severe roundoff errors\n  Local(rr,ii,count,sign);\n  rr:=r^n;\n  ii:=0;\n  For(count:=1,count<=n,count:=count+2) [\n    sign:=If(IsZero(Mod(count-1,4)),1,-1);\n    ii:=ii+sign*Bin(n,count)*i^count*r^(n-count);\n    If(count<n,\n      rr:=rr-sign*Bin(n,count+1)*i^(count+1)*r^(n-count-1));\n  ];\n  Complex(rr,ii);\n];\n*/\n\nLocalSymbols(a,x)\n[\nFunction(\"Conjugate\",{a})\n  Substitute(a,{{x},Type(x)=\"Complex\"},{{x},Complex(x[1],-(x[2]))});\n]; // LocalSymbols(a,x)\n\nFunction(\"Magnitude\",{x}) [\n    Sqrt(Re(x)^2 + Im(x)^2);\n];\n\n10 # Arg(Complex(Cos(_x),Sin(_x))) <-- x;\n10 # Arg(x_IsZero) <-- Undefined;\n15 # Arg(x_IsPositiveReal) <-- 0;\n15 # Arg(x_IsNegativeReal) <-- Pi;\n20 # Arg(Complex(r_IsZero,i_IsConstant)) <-- Sign(i)*Pi/2;\n30 # Arg(Complex(r_IsPositiveReal,i_IsConstant)) <-- ArcTan(i/r);\n40 # Arg(Complex(r_IsNegativeReal,i_IsPositiveReal)) <-- Pi+ArcTan(i/r);\n50 # Arg(Complex(r_IsNegativeReal,i_IsNegativeReal)) <-- ArcTan(i/r)-Pi;\n\n\n"
  },
  {
    "path": "scripts/complex.rep/code.ys.def",
    "content": "Complex\nRe\nIm\nIsComplex\nConjugate\nArg\nMagnitude\n}\n"
  },
  {
    "path": "scripts/complex.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef( \"Complex\"  , \"complex1\",\"complex_cartesian\" );\nOMDef( \"Re\"       , \"complex1\",\"real\"              );\nOMDef( \"Im\"       , \"complex1\",\"imaginary\"         );\nOMDef( \"Conjugate\", \"complex1\",\"conjugate\"         );\nOMDef( \"Arg\"      , \"complex1\",\"argument\"          );\nOMDef( \"IsComplex\", \"yacas\",\"is_complex\"           );\n"
  },
  {
    "path": "scripts/constants.rep/code.ys",
    "content": "\n/* Definition of constants. */\n\n\n/* TODO:\n * There is a problem with defining I this way: if I is used, but the\n * file \"complex\" has not been loaded, the interpreter can not deal\n * with \"Complex\".\n */\n\nSetGlobalLazyVariable(I,Complex(0,1));\n\n//////////////////////////////////////////////////\n/// Cached constants support and definition of Pi\n//////////////////////////////////////////////////\n\n//TODO: here we wrap the entire file in LocalSymbols, this is inefficient in that it slows loading of this file. Needs optimization.\nLocalSymbols(CacheOfConstantsN) [\n\n/// declare a new cached constant C'atom and its associated function C'atom().\n/// C'atom() will call C'func() at current precision to evaluate C'atom if it has not yet been cached at that precision. (note: any arguments to C'func() must be included)\nRuleBase(\"CachedConstant\", {C'cache, C'atom, C'func});\nUnFence(\"CachedConstant\", 3);\t// not sure if this is useful\nHoldArg(\"CachedConstant\", C'func);\nHoldArg(\"CachedConstant\", C'cache);\t// name of the cache\n// check syntax: must be called on an atom and a function\nRule(\"CachedConstant\", 3, 10, And(IsAtom(C'atom), IsFunction(C'func)))\n[\n \tLocal(C'name,C'functionName);\n\tSet(C'name, String(C'atom));\t// this is for later conveniences\n  Set(C'functionName,ConcatStrings(\"Internal'\",C'name));\n\n\tIf(\t// create the cache it if it does not already exist\n\t\tIsAtom(Eval(C'cache)),\n\t\tMacroSet(Eval(C'cache), {})\n\t);\n//\tWrite({\"debug step 0: \", C'cache, Eval(C'cache), C'atom, C'func, C'name});\n\t// check that the constant is not already defined\n\tIf(\n\t  Equals(Builtin'Assoc(C'name, Eval(C'cache)), Empty),\t// the constant is not already defined, so need to define \"C'atom\" and the corresponding function \"C'atom\"()\n\t  [\t// e.g. C'atom evaluates to Pi, C'cache to a name e.g. CacheOfConstantsN, which is bound to a hash\n\t\tMacroClear(C'atom);\n//\t\tWrite({\"debug step 1: \", Cache'name, C'cache, Eval(C'cache)});\n\t\t// add the new constant to the cache\n//\t\tMacroSet(Cache'name, Insert(Eval(C'cache), 1, {C'name, 0, 0}));\n\t\tDestructiveInsert(Eval(C'cache), 1, {C'name, 0, 0});\n//\t\tWrite({\"debug step 2: \", Cache'name, C'cache, Eval(C'cache)});\n\t\t// define the new function \"C'atom\"()\n\t\t// note: this should not use N() because it may be called from inside N() itself\n\n\t\tMacroRuleBase(C'functionName, {});\n\t\t`( Rule(@C'functionName, 0, 1024, True)\n\t\t[\n\t\t\tLocal(new'prec, new'C, cached'C);\n\t\t\tSet(new'prec, Builtin'Precision'Get());\n\t\t\t// fetch the cache entry for this constant\n\t\t\t// note that this procedure will store the name of the cache here in this statement as Eval(C'cache)\n\t\t\tSet(cached'C, Builtin'Assoc(@C'name, @C'cache));\n\t\t\tIf(\n\t\t\t  LessThan(MathNth(cached'C, 2), new'prec),\n\t\t\t  [\t// need to recalculate at current precision\n\t\t\t\tIf(Equals(InVerboseMode(),True), Echo(\"CachedConstant: Info: constant \", @C'name, \" is being recalculated at precision \", new'prec));\n\t\t\t\tSet(new'C, Eval(@C'func));\n\t\t\t\tDestructiveReplace(cached'C, 2, new'prec);\n\t\t\t\tDestructiveReplace(cached'C, 3, new'C);\n\t\t\t\tnew'C;\n\t\t\t  ],\n\t\t\t  // return cached value of C'atom\n\t\t\t  MathNth(cached'C, 3)\n\t\t\t);\n\t\t]);\n\n\t\t// calculate C'atom at current precision for the first time\n//\t\tEval(UnList({C'atom}));\t// \"C'name\"();\n\t\t// we do not need this until the constant is used; it will just slow us down\n\t  ],\n\t  // the constant is defined\n\t  Echo(\"CachedConstant: Warning: constant \", C'atom, \" already defined\")\t\t\n\t);\n];\n\nRule(\"CachedConstant\", 3, 20, True)\n\tEcho(\"CachedConstant: Error: \", C'atom, \" must be an atom and \", C'func, \" must be a function.\");\n\n/// assign numerical values to all cached constants: using fixed cache \"CacheOfConstantsN\"\n// this is called from N()\nFunction(\"AssignCachedConstantsN\", {})\n[\n\tLocal(var,fname);\n\tForEach(var, AssocIndices(CacheOfConstantsN))\n\t[\n\t\tMacroClear(Atom(var));\n    Set(fname,ConcatStrings(\"Internal'\",var));\n    Set(var,Atom(var));\n\t\t// this way the routine Internal'Pi() will be actually called only when the variable 'Pi' is used, etcetera.\n    `SetGlobalLazyVariable((@var), UnList({Atom(fname)}));\n\t];\n];\nUnFence(\"AssignCachedConstantsN\", 0);\n\n/// clear values from all cached constants: using fixed cache \"CacheOfConstantsN\"\n// this is called from N()\nFunction(\"ClearCachedConstantsN\", {})\n[\n\tLocal(c'entry);\n\tForEach(c'entry, CacheOfConstantsN)\n\t\tMacroClear(Atom(c'entry[1]));\n];\nUnFence(\"ClearCachedConstantsN\", 0);\n\n/// declare some constants now\nCachedConstant(CacheOfConstantsN, Pi,\n[// it seems necessary to precompute Pi to a few more digits\n// so that Cos(0.5*Pi)=0 at precision 10\n// FIXME: find a better solution\n\tLocal(result,old'prec);\n  Set(old'prec,Builtin'Precision'Get());\nIf(Equals(InVerboseMode(),True), Echo(\"Recalculating Pi at precision \",old'prec+5));\n\tBuiltin'Precision'Set(Builtin'Precision'Get()+5);\n\tresult := MathPi();\nIf(Equals(InVerboseMode(),True),Echo(\"Switching back to precision \",old'prec));\n\tBuiltin'Precision'Set(old'prec);\n\tresult;\n]\n);\nCachedConstant(CacheOfConstantsN, gamma, GammaConstNum());\nCachedConstant(CacheOfConstantsN, GoldenRatio, N( (1+Sqrt(5))/2 ) );\nCachedConstant(CacheOfConstantsN, Catalan, CatalanConstNum() );\n\n]; // LocalSymbols(CacheOfConstantsN)\n"
  },
  {
    "path": "scripts/constants.rep/code.ys.def",
    "content": "I\nCachedConstant\nAssignCachedConstants\nClearCachedConstants\n}\n"
  },
  {
    "path": "scripts/constants.rep/om.ys",
    "content": "//From code.ys.def:\nOMDef( \"I\", \"nums1\", \"i\" );\nOMDef( \"CachedConstant\",        \"yacas\", \"CachedConstant\"        );\nOMDef( \"AssignCachedConstants\", \"yacas\", \"AssignCachedConstants\" );\nOMDef( \"ClearCachedConstants\",  \"yacas\", \"ClearCachedConstants\"  );\nOMDef( \"Pi\", \"nums1\", \"pi\" );\n"
  },
  {
    "path": "scripts/controlflow.rep/code.ys",
    "content": "\n/* Defining a For function */\nTemplateFunction(\"For\",{start,predicate,increment,body})\n[\n  Eval(start);\n  While (Equals(Eval(predicate),True))\n  [\n    Eval(body);\n    Eval(increment);\n  ];\n];\nUnFence(\"For\",4);\nHoldArgNr(\"For\",4,1);\nHoldArgNr(\"For\",4,2);\nHoldArgNr(\"For\",4,3);\nHoldArgNr(\"For\",4,4);\n\n\n/* \n * This was an experiment to try to get to using a new ForEach that works the\n * same on lists and arrays. For some odd reason all sorts of places in the scripts\n * break if we use this version of ForEach. We need to look into this still! I want\n * a ForEach that works on lists as well as arrays.\n\nMacro()(ForEachRest(i,L,B));\n\nLocalSymbols(foreachtail)\n[\n  10 # ForEachRest(_i,L_IsFunction,_B) <-- \n  [\n    Local(foreachtail);\n    Local(@i);\n    Set(foreachtail,@L);\n    While(Not(Equals(foreachtail,{})))\n    [\n      Set(@i,Head(foreachtail));\n      @B;\n      Set(foreachtail,Tail(foreachtail));\n    ];\n  ];\n];\n\nLocalSymbols(index,nr)\n[\n  20 # ForEachRest(_i,_A,_B)_(   And(\n            Equals(IsGeneric(A),True),\n            Equals(GenericTypeName(A),\"Array\")\n            )) <-- \n  [\n    Local(index,nr);\n    Local(@i);\n    Set(index,1);\n    Set(nr,Length(@A));\n    While(index<=nr)\n    [\n      Set(@i,(@A)[index]);\n      @B;\n      Set(index,MathAdd(index,1));\n    ];\n  ];\n];\n\nMacro()(ForEach(i,L)(B));\n\nLocalSymbols(itm,lst,bd)\n[\n  (ForEach(_i,_L)(_B)) <-- \n  [\n    Local(itm,lst,bd);\n//CurrentFile(),CurrentLine(),,Hold(@B)\n//Echo(CurrentFile(),CurrentLine());\n// Echo(\"ForEach(\",Hold(@i),\", \",Hold(@L),\", ) \");\n    itm:=Hold(@i);\n    lst:= (@L);\n    bd:=Hold(@B);\n//Echo(\"1...\",itm);\n    `ForEachRest(@itm,@lst,@bd);\n  ];\n];\n*/\n\nLocalSymbols(i,nr)\n[\n  TemplateFunction(\"ForEachInArray\",{item,list,body})\n  [\n    Local(i,nr);\n    MacroLocal(item);\n    Set(i,1);\n    Set(nr,Length(list));\n    While(i<=nr)\n    [\n      MacroSet(item,list[i]);\n      Eval(body);\n      Set(i,MathAdd(i,1));\n    ];\n  ];\n];\n\nUnFence(\"ForEachInArray\",3);\nHoldArgNr(\"ForEachInArray\",3,1);\nHoldArgNr(\"ForEachInArray\",3,3);\n\n\n/*TODO remove? Not yet. If the code above can be made to work we can do away with this version. */\nTemplateFunction(\"ForEach\",{item,list,body})\n[\n  If(And(Equals(IsGeneric(list),True),\n         Equals(GenericTypeName(list),\"Array\")\n         ),\n    `ForEachInArray(@item,list,@body),\n    [\n      Local(foreachtail);\n      MacroLocal(item);\n      Set(foreachtail,list);\n      While(Not(Equals(foreachtail,{})))\n      [\n        MacroSet(item,Head(foreachtail));\n        Eval(body);\n        Set(foreachtail,Tail(foreachtail));\n      ];\n    ]);\n];\nUnFence(\"ForEach\",3);\nHoldArgNr(\"ForEach\",3,1);\nHoldArgNr(\"ForEach\",3,3);\n/* */\n\n/* Lambda was introduced as a form of pure function that can be passed on to the function Apply as a first argument.\n * The original method, passing it in as a list, had the disadvantage that the list was evaluated, which caused the \n * arguments to be evaluated too. This resulted in unwanted behaviour sometimes (expressions being prematurely evaluated\n * in the body of the pure function). The arguments to Lambda are not evaluated.\n */\nDefMacroRuleBase(\"Lambda\",{args,body});\n\n\n10 # Apply(_applyoper,_applyargs) _ (Or(IsString(applyoper), IsList(applyoper))) <-- ApplyPure(applyoper,applyargs);\n20 # Apply(applyoper_IsAtom,_applyargs) <-- ApplyPure(String(applyoper),applyargs);\n\n30 # Apply(Lambda(_args,_body),_applyargs) <-- `ApplyPure(Hold({@args,@body}),applyargs);\nUnFence(\"Apply\",2);\n\n\nTemplateFunction(\"Until\",{predicate,body})\n[\n  Eval(body);\n  While (Equals(Eval(predicate),False))\n  [\n    Eval(body);\n  ];\n  True;\n];\nUnFence(\"Until\",2);\nHoldArgNr(\"Until\",2,1);\nHoldArgNr(\"Until\",2,2);\n\n\n\n"
  },
  {
    "path": "scripts/controlflow.rep/code.ys.def",
    "content": "For\nForEach\nApply\nLambda\nUntil\n}"
  },
  {
    "path": "scripts/cse.rep/cse.ys",
    "content": "/*\n * Copyright (C) 2016 Grzegorz Mazur.\n *\n * Yacas is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n * MA 02110-1301  USA\n */\n\nFunction(\"CSE'FindSimpleSubexpressions\", {e, ss})\n[\n    If(Not IsAtom(e), [\n        Local(p, l);\n        l := Listify(e);\n\n        If(Apply(\"And\",(MapSingle(\"IsAtom\",l))) And Not Head(l) = List, [\n            Association'Set(ss, l, If (Association'Contains(ss, l), Association'Get(ss, l), 0) + 1);\n        ], [\n            ForEach(p, Tail(l))\n                ss := CSE'FindSimpleSubexpressions(p, ss);\n        ]);\n    ]);\n    ss;\n];\n\nFunction(\"CSE'RemoveSporadicSubexpressions\", {ss})\n[\n    Local(r, h);\n    r := {};\n    ForEach(h, Association'ToList(ss))\n        If (h[2] > 1, DestructiveAppend(r, UnList(h[1])));\n    r;\n];\n\nFunction(\"CSE'TagSubexpressions\", {l})\n[\n    Local(r);\n    r := {};\n    ForEach(i, l)\n        DestructiveAppend(r, {UniqueConstant(), i});\n    r;\n];\n\n// For an expression e:\n//   - find all simple subexpressions present more then once\n//   - generate unique ids for for each of them\n//   - substitute them with the ids in e\n//   - return simplified expression and list of substitutions\nFunction(\"CSE\", {e})\n[\n    Local(re, csl, t, i);\n\n    re := e;\n    csl := {};\n    t := {};\n   \n    Until(Length(t) = 0) [\n        t := CSE'TagSubexpressions(CSE'RemoveSporadicSubexpressions(CSE'FindSimpleSubexpressions(re, Association'Create())));\n        ForEach(i, t) [\n            re := Subst(i[2], i[1]) re;\n            DestructiveAppend(csl, i);\n        ];\n    ];\n\n    { re, csl };\n];\n"
  },
  {
    "path": "scripts/cse.rep/cse.ys.def",
    "content": "CSE\n}\n"
  },
  {
    "path": "scripts/debug.rep/code.ys",
    "content": "\n\n\nLocalSymbols(TraceStart,TraceEnter,TraceLeave,DebugStart,DebugEnter, \n             DebugLeave,ProfileStart,ProfileEnter,result,\n             WriteLines,ClearScreenString,Debug'FileLoaded, Debug'FileLines, Debug'NrLines,\n             debugstepoverfile, debugstepoverline) [\n\nTraceStart() := [indent := 0;];\nTraceEnter() :=\n[\n    indent++;\n    Space(2*indent);\n    Echo(\"Enter \",CustomEval'Expression());\n];\nTraceLeave() :=\n[\n    Space(2*indent);\n    Echo(\"Leave \",CustomEval'Result());\n    indent--;\n];\nMacro(TraceExp,{expression})\n[\n    TraceStart();\n    CustomEval(TraceEnter(),TraceLeave(),CustomEval'Stop(),@expression);\n];\n\n\n\nDebugStart():=\n[\n   debugging:=True;\n   debugstopdepth := -1;\n   breakpoints:={};\n   filebreakpoints := {};\n   debugstopped:=False;\n   debugverbose:=False;\n   debugcallstack:={};\n   breakpredicate:=False;\n];\nDebugRun():= [debugging:=False;True;];\nDebugStep():=[debugging:=False;nextdebugging:=True;];\n\nDebugStepOver():=\n[\n  debugging:=False;\n  debugstepoverfile := DebugFile(CustomEval'Expression());\n  debugstepoverline := DebugLine(CustomEval'Expression());\n  debugstopdepth := Length(debugcallstack);\n];\nDebugBreakAt(file,line):=\n[\n  Check(InDebugMode(),\"DebugBreakAt only supported in the debug build of Yacas\");\n  If(filebreakpoints[file] = Empty,filebreakpoints[file]:={});\n  DestructiveAppend(filebreakpoints[file],line);\n];\nDebugRemoveBreakAt(file,line):=\n[\n  Check(InDebugMode(),\"DebugRemoveBreakAt only supported in the debug build of Yacas\");\n  If(filebreakpoints[file] = Empty,filebreakpoints[file]:={});\n  filebreakpoints[file] := Difference(filebreakpoints[file],{line});\n];\n\n\nDebugStop():=[debugging:=False;debugstopped:=True;CustomEval'Stop();];\nDebugVerbose(verbose):=[debugverbose:=verbose;];\nDebugAddBreakpoint(fname_IsString) <-- [ breakpoints := fname:breakpoints;];\nMacro(DebugBreakIf,{predicate})\n[\n  breakpredicate:= Hold(@predicate);\n];\n\nBreakpointsClear() <--\n[\n  breakpredicate:=False;\n  breakpoints := {};\n];\nMacro(DebugLocals,{})\n[\n  Echo(\"\");\n  Echo(\"*************** Current locals on the stack ****************\");\n  ForEach(item,CustomEval'Locals())\n  [\n    Echo(\"      \",item,\" : \",Eval(item));\n  ];\n  Echo(\"\");\n];\nDebugCallstack() <--\n[\n  Echo(\"\");\n  Echo(\"*************** Function call stack ****************\");\n  ForEach(item,debugcallstack)\n  [\n    if(IsFunction(item))\n      Echo(\"      Function \",Type(item),\" : \",item)\n    else\n      Echo(\"      Variable \",item);\n  ];\n  Echo(\"\");\n];\n\nMacro(DebugEnter,{})\n[\n  debugcallstack := CustomEval'Expression():debugcallstack;\n  // custom breakpoint (custom predicate thought up by the programmer)\n  If(debugging = False And\n      Eval(breakpredicate) = True,\n      [\n        breakpredicate:=False;\n        debugging:=True;\n      ]);\n\n  If(debugging = False And InDebugMode(),\n  [  \n    Local(file,line);\n    file := DebugFile(CustomEval'Expression());\n    If(filebreakpoints[file] != Empty,\n    [\n      line := DebugLine(CustomEval'Expression());\n      If(Not(file = debugstepoverfile And line = debugstepoverline) And\n         Contains(filebreakpoints[file],line),\n         [\n           debugging:=True;\n         ]\n        );\n    ]);\n  ]);\n\n\n  // the standard breakpoint\n  If(debugging = False And\n      IsFunction(CustomEval'Expression()) And\n      Contains(breakpoints,Type(CustomEval'Expression())),   debugging:=True);\n   nextdebugging:=False;\n   If (debugging,\n   [\n     If(InDebugMode(),DebugShowCode());\n     Echo(\">>> \",CustomEval'Expression());\n     While(debugging)\n     [\n        Echo(\"DebugOut> \",Eval(FromString(ReadCmdLineString(\"Debug> \"):\";\")Read()));\n    //      If(debugging,Echo(\"DebugOut> \",debugRes));\n       If(IsExitRequested(),debugging:=False);\n     ];\n    ]);\n   debugging:=nextdebugging;\n\n   If(IsExitRequested(),debugstopped:=True);\n\n];\nMacro(DebugLeave,{})\n[\n  If(debugging = False And debugstopdepth >= 0 And Length(debugcallstack) = debugstopdepth,\n  [\n    debugstepoverline := -1;\n    debugging := True;\n    debugstopdepth := -1;\n  ]);\n\n  debugcallstack := Tail(debugcallstack);\n  If(debugverbose,Echo(CustomEval'Result(),\" <-- \",CustomEval'Expression()));\n];\nMacro(Debug,{expression})\nToStdout()\n[\n   DebugStart();\n   CustomEval(DebugEnter(),DebugLeave(),If(debugstopped,Check(False,\"\"),[debugging:=True;debugcallstack := Tail(debugcallstack);]),@expression);\n];\n\n\nProfileStart():=\n[\n    profilefn:={};\n];\n10 # ProfileEnter()_(IsFunction(CustomEval'Expression())) <--\n[\n    Local(fname);\n    fname:=Type(CustomEval'Expression());\n    If(profilefn[fname]=Empty,profilefn[fname]:=0);\n    profilefn[fname] := profilefn[fname]+1;\n];\nMacro(Profile,{expression})\n[\n    ProfileStart();\n    CustomEval(ProfileEnter(),True,CustomEval'Stop(),@expression);\n    ForEach(item,profilefn)\n      Echo(\"Function \",item[1],\" called \",item[2],\" times\");\n];\n\n/// Measure the time taken by evaluation and print results.\nMacro(Time,{expression})\n[\n\tLocal(result);\n\tEcho(GetTime(Set(result, @expression)), \"seconds taken\");\n\tresult;\n];\n\n\n\n\n// ClearScreenString : the ascii escape codes to clear the screen\nClearScreenString := CharString(27):\"[2J\":CharString(27):\"[1;1H\";\n\n// WriteLines: do the actual outputting of lines of a file to screen\nWriteLines(filename,lines,from,nrlines,breakpoints,current):=\n[\n  Local(i,nr);\n  nr:=Length(lines);\n  WriteString(ClearScreenString);\n  Echo(\"File \",filename,\" at line \",current);\n  For(i:=from,i<from+nrlines And i<nr,i++)\n  [\n\n    if (current = i) \n      WriteString(\">\")\n    else\n      WriteString(\" \");\n    if (Contains(breakpoints,i)) \n      WriteString(\"*\")\n    else\n      WriteString(\" \");\n    WriteString(\"| \");\n    Echo(lines[i][1]);\n  ];\n];\nDebug'FileLoaded := \"\";\nDebug'FileLines := {};\nDebug'NrLines:=20;\n\n//\n// DebugShowCode: show the part of the file we are currently executing (based on the \n// value returned by CustomEval'Expression() ).\n//\n// Currently unimplemented, should we remove?\n//\nDebugShowCode():=\n[\n  False;\n];\n\n]; //LocalSymbols\n\n\n\n\n\n"
  },
  {
    "path": "scripts/debug.rep/code.ys.def",
    "content": "TraceExp\nDebug\nProfile\nDebugRun\nDebugStep\nDebugStepOver\nDebugBreakAt\nDebugRemoveBreakAt\nDebugStop\nDebugVerbose\nDebugAddBreakpoint\nBreakpointsClear\nDebugCallstack\nDebugBreakIf\nDebugLocals\nTime\nDebugShowCode\n}\n"
  },
  {
    "path": "scripts/deffunc.rep/code.ys",
    "content": "\n/* Defining a macro-like function that declares a function\n * with only one rule.\n */\nRuleBase(\"Function\",{oper,args,body});\nHoldArg(\"Function\",oper);\nHoldArg(\"Function\",args);\nHoldArg(\"Function\",body);\n\nRuleBase(\"Macro\",{oper,args,body});\nHoldArg(\"Macro\",oper);\nHoldArg(\"Macro\",args);\nHoldArg(\"Macro\",body);\n\n// function with variable number of arguments: Function(\"func\",{x,y, ...})body;\nRule(\"Function\",3,2047,\n\tAnd(GreaterThan(Length(args), 1), Equals( MathNth(args, Length(args)), Atom(\"...\") ))\n)\n[\n  DestructiveDelete(args,Length(args));\t// remove trailing \"...\"\n  Retract(oper,Length(args));\n  MacroRuleBaseListed(oper,args);\n  MacroRule(oper,Length(args),1025,True) body;\t// at precedence 1025, for flexibility\n];\n\n// function with a fixed number of arguments\nRule(\"Function\",3,2048,True)\n[\n  Retract(oper,Length(args));\n  MacroRuleBase(oper,args);\n  MacroRule(oper,Length(args),1025,True) body;\n];\n\n\n// macro with variable number of arguments: Macro(\"func\",{x,y, ...})body;\nRule(\"Macro\",3,2047,\n\tAnd(GreaterThan(Length(args), 1), Equals( MathNth(args, Length(args)), Atom(\"...\") ))\n)\n[\n  DestructiveDelete(args,Length(args));\t// remove trailing \"...\"\n  Retract(oper,Length(args));\n  `DefMacroRuleBaseListed(@oper,@args);\n  MacroRule(oper,Length(args),1025,True) body;\t// at precedence 1025, for flexibility\n];\n\n// macro with a fixed number of arguments\nRule(\"Macro\",3,2048,True)\n[\n  Retract(oper,Length(args));\n  `DefMacroRuleBase(@oper,@args);\n  MacroRule(oper,Length(args),1025,True) body;\n];\n\n\n/// shorthand function declarations\nRuleBase(\"Function\",{oper});\n// function with variable number of arguments: Function() f(x,y, ...)\nRule(\"Function\",1,2047,\n\tAnd(IsFunction(oper), GreaterThan(Length(oper), 1), Equals( MathNth(oper, Length(oper)), Atom(\"...\") ))\n)\n[\n\tLocal(args);\n\tSet(args,Tail(Listify(oper)));\n\tDestructiveDelete(args,Length(args));\t// remove trailing \"...\"\n\tIf(RuleBaseDefined(Type(oper),Length(args)),\n\t\tFalse,\t// do nothing\n\t\tMacroRuleBaseListed(Type(oper),args)\n\t);\n];\n// function with a fixed number of arguments\nRule(\"Function\",1,2048,\n\tAnd(IsFunction(oper))\n)\n[\n\tLocal(args);\n\tSet(args,Tail(Listify(oper)));\n\tIf(RuleBaseDefined(Type(oper),Length(args)),\n\t\tFalse,\t// do nothing\n\t\tMacroRuleBase(Type(oper),args)\n\t);\n];\n\n\nRuleBase(\"Macro\",{oper});\n// macro with variable number of arguments: Macro() f(x,y, ...)\nRule(\"Macro\",1,2047,\n\tAnd(IsFunction(oper), GreaterThan(Length(oper), 1), Equals( MathNth(oper, Length(oper)), Atom(\"...\") ))\n)\n[\n\tLocal(args,name);\n\tSet(args,Tail(Listify(oper)));\n\tDestructiveDelete(args,Length(args));\t// remove trailing \"...\"\n  Set(name,Type(oper));\n\tIf(RuleBaseDefined(Type(oper),Length(args)),\n\t\tFalse,\t// do nothing\n\t\t`DefMacroRuleBaseListed(@name,@args)\n\t);\n];\n// macro with a fixed number of arguments\nRule(\"Macro\",1,2048,\n\tAnd(IsFunction(oper))\n)\n[\n\tLocal(args,name);\n\tSet(args,Tail(Listify(oper)));\n  Set(name,Type(oper));\n\tIf(RuleBaseDefined(Type(oper),Length(args)),\n\t\tFalse,\t// do nothing\n\t\t[\n      `DefMacroRuleBase(@name,@args);\n    ]\n\t);\n];\n\n\nRuleBase(\"TemplateFunction\",{oper,args,body});\nBodied(\"TemplateFunction\",60000);\nHoldArg(\"TemplateFunction\",oper);\nHoldArg(\"TemplateFunction\",args);\nHoldArg(\"TemplateFunction\",body);\nRule(\"TemplateFunction\",3,2047,True)\n[\n  Retract(oper,Length(args)); \n  Local(arglist);\n  arglist:=FlatCopy(args);\n  \n  DestructiveAppend(arglist,{args,UnList({Hold,body})});\n  arglist:=ApplyPure(\"LocalSymbols\",arglist);\n\n  MacroRuleBase(oper,arglist[1]);\n  MacroRule(oper,Length(args),1025,True) arglist[2];\n\n];\n\nFunction(\"HoldArgNr\",{function,arity,index})\n[\n  Local(args);\n  args:=RuleBaseArgList(function,arity);\n/* Echo({\"holdnr \",args}); */\n  ApplyPure(\"HoldArg\",{function,args[index]});\n];\n\n\n\n/* := assignment. */\nRuleBase(\":=\",{aLeftAssign,aRightAssign});\nUnFence(\":=\",2);\nHoldArg(\":=\",aLeftAssign);\nHoldArg(\":=\",aRightAssign);\n\n/* := assignment. */\n// assign a variable\nRule(\":=\",2,0,IsAtom(aLeftAssign))\n[\n  MacroSet(aLeftAssign,Eval(aRightAssign));\n  Eval(aLeftAssign);\n];\n\n// assign lists\nRule(\":=\",2,0,IsList(aLeftAssign))\n[\n  Map(\":=\",{aLeftAssign,Eval(aRightAssign)});\n];\n\n// auxiliary function to help assign arrays using :=\nRuleBase(\"AssignArray\",{setlistterm,setlistindex,setlistresult});\nUnFence(\"AssignArray\",3);\nRule(\"AssignArray\",3,1,IsString(setlistindex))\n[\n  Local(item);\n  item:=Assoc(setlistindex,setlistterm);\n  If(item = Empty,\n     DestructiveInsert(setlistterm,1,{setlistindex,setlistresult}),\n     DestructiveReplace(item,2,setlistresult)\n     );\n  True;\n];\n// assign generic arrays\nRule(\"AssignArray\",3,1,\n   And(\n           Equals(IsGeneric(setlistterm),True),\n           Equals(GenericTypeName(setlistterm),\"Array\")\n          )\n    )\n[\n  Array'Set(setlistterm,setlistindex,setlistresult);\n];\n\n\nRule(\"AssignArray\",3,2,True)\n[\n  DestructiveReplace(setlistterm ,setlistindex, setlistresult);\n  True;\n];\n\n// a[x] := ... assigns to an array element\nRule(\":=\",2,10,IsFunction(aLeftAssign) And (Head(Listify(aLeftAssign)) = Nth))\n[\n Local(frst,scnd);\n\n Local(lst);\n Set(lst,(Listify(aLeftAssign)));\n Set(lst,Tail(lst));\n Set(frst, Eval(Head(lst)));\n Set(lst,Tail(lst));\n Set(scnd, Eval(Head(lst)));\n\n AssignArray(frst,scnd,Eval(aRightAssign));\n];\n\n// f(x):=... defines a new function\nRule(\":=\",2,30,IsFunction(aLeftAssign) And Not(Equals(aLeftAssign[0], Atom(\":=\"))))\n[\n  Local(oper,args,arity);\n  Set(oper,String(aLeftAssign[0]));\n  Set(args,Tail(Listify(aLeftAssign)));\n  If(\n\tAnd(GreaterThan(Length(args), 1), Equals( MathNth(args, Length(args)), Atom(\"...\") )),\n\t// function with variable number of arguments\n\t[\n\t  DestructiveDelete(args,Length(args));\t// remove trailing \"...\"\n\t  Set(arity,Length(args));\n\t  Retract(oper,arity); \n\t  MacroRuleBaseListed(oper, args);\n\t],\n\t// function with a fixed number of arguments\n\t[\n\t  Set(arity,Length(args));\n\t  Retract(oper,arity); \n\t  MacroRuleBase(oper, args);\n\t]\n  );\n  UnHoldable(aRightAssign);\n  MacroRule(oper,arity,1025,True) aRightAssign;\n];\n\n// this will \"unhold\" a variable - used to make sure that := with Eval()\n// immediately on the right hand side evaluates its argument\nRuleBase(\"UnHoldable\",{var});\nHoldArg(\"UnHoldable\",var);\nUnFence(\"UnHoldable\",1);\nRule(\"UnHoldable\",1,10,Equals(Type(Eval(var)),\"Eval\"))\n[\n  MacroSet(var,Eval(Eval(var)));\n/* Echo({\"unheld\",var,Eval(var)}); */\n];\nRule(\"UnHoldable\",1,20,True)\n[\n/* Echo({\"held\"}); */\n  True;\n];\n\n\n\n\n"
  },
  {
    "path": "scripts/deffunc.rep/code.ys.def",
    "content": "Function\nMacro\nTemplateFunction\nHoldArgNr\n:=\n}\n"
  },
  {
    "path": "scripts/deriv.rep/code.ys",
    "content": "\n\n\nRuleBase(\"D\",{aVar,aFunc});\nRuleBase(\"D\",{aVar,aCount,aFunc});\n\nRule(\"D\",2,1,IsList(aVar) And Not(IsList(aFunc)))\n\tMap(\"D\",{aVar,FillList(aFunc, Length(aVar))});\nRule(\"D\",2,1,IsList(aVar) And IsList(aFunc))\n\tMap(\"D\",{aVar,aFunc});\n\nRule(\"D\",2,3,True)\n[\n  MacroLocal(aVar);\n  Apply(\"Deriv\",{aVar,1,aFunc});\n];\n\nRule(\"D\",3,1,IsList(aVar) And Not(IsList(aFunc)))\n\tMap(\"D\",{aVar,\n                 FillList(aCount, Length(aVar)),\n                 FillList(aFunc, Length(aVar))});\nRule(\"D\",3,1,IsList(aVar) And IsList(aFunc))\n\tMap(\"D\",{aVar,\n                 FillList(aCount, Length(aVar)),\n                 aFunc});\nRule(\"D\",3,3,True)\n[\n  MacroLocal(aVar);\n  Apply(\"Deriv\",{aVar,aCount,aFunc});\n];\n\n\nHoldArg(\"D\",aVar);\nHoldArg(\"D\",aFunc);\n\n5 # (Deriv(_var,1)_func) <-- Deriv(var)func;\n5 # (Deriv(_var,0)_func) <-- func;\n10 # (Deriv(_var,n_IsPositiveInteger)_func) <-- Deriv(var)Deriv(var,n-1)func;\n10 # (Deriv(_var,n_IsNegativeInteger)_func) <-- Check(0,\"Negative derivative\");\n\n \n// Need to clean out Sec(x) and friends\n0 # (Deriv(_var) (_var)) <-- 1;\n1 # (Deriv(_var)func_IsAtom) <-- 0;\n2 # (Deriv(_var)_x + _y) <--  (Deriv(var)x) + (Deriv(var)y);\n2 # (Deriv(_var)- (_x) ) <-- -Deriv(var)x;\n2 # (Deriv(_var)_x - _y) <--  (Deriv(var)x) - (Deriv(var)y);\n2 # (Deriv(_var)_x * _y) <-- (x*Deriv(var)y) + (Deriv(var)x)*y;\n2 # (Deriv(_var)Sin(_x)) <--  (Deriv(var)x)*Cos(x);\n2 # (Deriv(_var)Sinh(_x))<--  (Deriv(var)x)*Cosh(x);\n2 # (Deriv(_var)Cosh(_x))<--  (Deriv(var)x)*Sinh(x);\n2 # (Deriv(_var)Cos(_x)) <-- -(Deriv(var)x)*Sin(x);\n2 # (Deriv(_var)Csc(_x)) <--  -(Deriv(var)x)*Csc(x)*Cot(x);\n2 # (Deriv(_var)Csch(_x)) <-- -(Deriv(var)x)*Csch(x)*Coth(x);\n2 # (Deriv(_var)Sec(_x)) <--  (Deriv(var)x)*Sec(x)*Tan(x);\n2 # (Deriv(_var)Sech(_x)) <-- -(Deriv(var)x)*Sech(x)*Tanh(x);\n2 # (Deriv(_var)Cot(_x)) <--  -(Deriv(var)x)*Csc(x)^2;\n2 # (Deriv(_var)Coth(_x)) <--  (Deriv(var)x)*Csch(x)^2;\n\n2 # (Deriv(_var)Tan(_x)) <-- ((Deriv(var) x) / (Cos(x)^2));\n2 # (Deriv(_var)Tanh(_x)) <-- (Deriv(var)x)*Sech(x)^2;\n\n2 # (Deriv(_var)Exp(_x)) <--  (Deriv(var)x)*Exp(x);\n\n// When dividing by a constant, this is faster\n2 # (Deriv(_var)(_x / _y))_(IsFreeOf(var,y)) <-- (Deriv(var) x) / y;\n3 # (Deriv(_var)(_x / _y)) <--\n    (y* (Deriv(var) x) - x* (Deriv(var) y))/ (y^2);\n\n2 # (Deriv(_var)Ln(_x)) <-- ((Deriv(var) x) / x);\n2 # (Deriv(_var)(_x ^ _n))_(IsRationalOrNumber(n) Or IsFreeOf(var, n)) <--\n    n * (Deriv(var) x) * (x ^ (n - 1));\n\n2 # (Deriv(_var)(Abs(_x)))  <-- Sign(x)*(Deriv(var)x);\n2 # (Deriv(_var)(Sign(_x))) <-- 0;\n\n2 # (Deriv(_var)(if(_cond)(_body))) <--\n\tUnList({Atom(\"if\"),cond,Deriv(var)body});\n2 # (Deriv(_var)((_left) else (_right))) <--\n        UnList({Atom(\"else\"), (Deriv(var)left), (Deriv(var)right) } );\n\n3 # (Deriv(_var)(_x ^ _n)) <-- (x^n)*Deriv(var)(n*Ln(x));\n\n2 # (Deriv(_var)ArcSin(_x)) <-- (Deriv(var) x )/Sqrt(1 -(x ^ 2));\n2 # (Deriv(_var)ArcCos(_x)) <-- -(Deriv(var)x)/Sqrt(1 -(x^2));\n2 # (Deriv(_var)ArcTan(_x)) <-- (Deriv(var) x)/(1 + x^2);\n2 # (Deriv(_var)Sqrt(_x)) <-- ((Deriv(var)x)/(2*Sqrt(x)));\n2 # (Deriv(_var)Complex(_r,_i)) <-- Complex(Deriv(var)r,Deriv(var)i);\n\n2 # (Deriv(_var)((_x)!)) <-- Gamma(1+x)*PolyGamma(0,1+x)*(Deriv(var) x);\n\nLocalSymbols(var,var2,a,b,y)[\n   2 # (Deriv(_var)Integrate(_var)(_y)) <-- y;\n   2 # (Deriv(_var)Integrate(_var2,_a,_b)(y_IsFreeOf(var))) <-- \n         (Deriv(var)b)*(y Where var2 == b) -\n         (Deriv(var)a)*(y Where var2 == a);\n   3 # (Deriv(_var)Integrate(_var2,_a,_b)(_y)) <-- \n         (Deriv(var)b)*(y Where var2 == b) -\n         (Deriv(var)a)*(y Where var2 == a) +\n \tIntegrate(var2,a,b) Deriv(var) y;\n ];\n\n\n\n2 # (Deriv(_var)func_IsList)_(Not(IsList(var))) <--\n    Map(\"Deriv\",{FillList(var,Length(func)),func});\n\n\n2 # (Deriv(_var)UniVariate(_var,_first,_coefs)) <--\n[\n  Local(result,m,i);\n  result:=FlatCopy(coefs);\n  m:=Length(result);\n  For(i:=1,i<=m,i++)\n  [\n    result[i] := result[i] * (first+i-1);\n  ];\n  UniVariate(var,first-1,result);\n];\n\n\nRuleBase(\"Diverge\", {aFunc, aBasis});\nRule(\"Diverge\", 2, 1, IsList(aBasis) And IsList(aFunc) And Length(aBasis) = Length(aFunc))\n\tAdd(Map(\"D\", {aBasis,aFunc}));\n\nRuleBase(\"Curl\", {aFunc, aBasis});\n\nRule(\"Curl\", 2, 1, Length(aBasis)=Length(aFunc))\n\t{\n\t\tApply(\"D\",{aBasis[2],aFunc[3]})-Apply(\"D\",{aBasis[3],aFunc[2]}),\n\t\tApply(\"D\",{aBasis[3],aFunc[1]})-Apply(\"D\",{aBasis[1],aFunc[3]}),\n\t\tApply(\"D\",{aBasis[1],aFunc[2]})-Apply(\"D\",{aBasis[2],aFunc[1]})\n\t};\n\n\n"
  },
  {
    "path": "scripts/deriv.rep/code.ys.def",
    "content": "D\nDeriv\nDiverge\nCurl\n}\n"
  },
  {
    "path": "scripts/example.rep/code.ys",
    "content": "\n\nexamplelist:=\nHold(\n{\n  {40!,\n\"Simple factorial of a number.\n\"\n  },\n  {D(x)Sin(x),\n\"Taking the derivative of a function (the derivative of Sin(x) with\nrespect to x in this case).\n\"\n  },\n  {Taylor(x,0,5)Sin(x),\n\"Expanding a function into a taylor series.\n\"\n  },\n  {Integrate(x,a,b)Sin(x),\n\"Integrate a function.\n\"\n  },\n  {Solve(a+x*y==z,x),\n\"Solve a function for a variable.\n\"\n  },\n  {Limit(x,0) Sin(x)/x,\n\"Take a limit.\n\"\n  },\n  {Subst(x,Cos(a)) x+x,\n\"Substitute an expression with another in the main expression.\n\"\n  },\n  {Expand((1+x)^3),\n\"Expand into a polynomial.\n\"\n  },\n  {2^40,\n\"Big numbers.\n\"\n  },\n  {1<<40,\n\"Bitwise operations\n\"\n  },\n  {1 .. 4,\n\"Generating a list of numbers.\n\"\n  },\n  {a:b:c:{},\n\"Generating a list of items.\n\"\n  },\n  {[Local(x);x:={a,b,c};Sin(x)^2;],\n\"Threading: Sin(..)^2 will be performed on all elements of the list\npassed in.\n\"\n  },\n  {[Local(list);list:={a,b,c,d,e,f}; list[2 .. 4];],\n\"Selecting a sublist from a list.\n\"\n  },\n  {Permutations({a,b,c}),\n\"Generate all permutations of a list.\n\"\n  },\n  {VarList(a+b*x),\n\"Show all variables that occur in an expression.\n\"\n  },\n  {TrigSimpCombine(Cos(a)*Cos(a)+Sin(a)*Sin(a)),\n\"Convert factors between trigonometric functions to addition of\ntrigonometric functions.\n\"\n  }\n}\n);\nexampleindex:=0;\n\nExample():=\n[\n  exampleindex++;\n  If (exampleindex>Length(examplelist),exampleindex:=1);\n\n  Local(example);\n  example:=examplelist[exampleindex];\n  WriteString(\"Current example : \");\n  Write(example[1]);WriteString(\";\");NewLine();\n  NewLine();\n  WriteString(example[2]);\n  NewLine();\n  Eval(example[1]);\n];\n\n\n"
  },
  {
    "path": "scripts/example.rep/code.ys.def",
    "content": "Example\n}\n"
  },
  {
    "path": "scripts/examples/ABIN.ys",
    "content": "/* Implementation of the ABIN formal grammar\n\t(see Yacas tutorial essays) */\n\nIsExpr(x_IsList) <-- IsBExpr(x) Or IsNExpr(x) Or IsAExpr(x);\n\nIsProvable(x_IsList) <-- IsAxiom(x) Or IsTheorem(x);\n\nIsAxiom(x_IsList) <-- If(IsNExpr(x) And IsBExpr(Tail(x)),\n [Echo({\"Axiom \", Map(\"ConcatStrings\", x)});\n  True; ], False);\n\n10 # IsBExpr({}) <-- False;\n\n10 # IsBExpr({\"B\"}) <-- True;\n\n20 # IsBExpr(x_IsList) <-- x[Length(x)]=\"I\" And\n IsBExpr(Take(x, {1, Length(x)-1}));\n\n10 # IsNExpr({}) <-- False;\n\n20 # IsNExpr(x_IsList) <-- x[1] = \"N\" And IsExpr(Tail(x));\n\nFindTwoExprs(x_IsList) <-- [\n Local(iter, result);\n For([iter:=1; result:=False;],\n  iter < Length(x) And Not result, iter:=iter+1 )\n   [\n    result := IsExpr(Take(x, iter))\n     And IsExpr(Take(x, {iter+1, Length(x)}));\n   ];\n {result, iter-1};\n];\n\n10 # IsAExpr(x_IsList)_(Length(x) <= 1) <-- False;\n\n20 # IsAExpr(x_IsList) <-- x[1] = \"A\" And FindTwoExprs(Tail(x))[1];\n\nIsTheorem(x_IsList) <-- If(IsNExpr(x) And IsAExpr(Tail(x)) And\n  IsProvable(Concat({\"N\"}, Take(Tail(Tail(x)),\n  FindTwoExprs(Tail(Tail(x)))[2]) )),\n [ Echo({\"Theorem \", Map(\"ConcatStrings\", x)[1], \" derived\"});\n  True; ], False);\n\nAtomToCharList(x_IsAtom) <-- [\n  Local(index, result);\n  For([ index:=Length(String(x)); result:={}; ],\n   index > 0, index:=index-1 )\n   Push(result,\n    StringMid'Get(index, 1, String(x)));\n  result;\n];\n\nABIN(x_IsAtom) <-- If(IsProvable(AtomToCharList(x)),\n True,\n [Echo({x, \"cannot be proved\"}); False; ]);\n\n/* Examples */\nIsProvable({\"N\", \"A\", \"B\", \"I\", \"B\", \"I\"});\nABIN(NAAABIBBB);\nABIN(NAAABNBIIABBIINB);\nABIN(NAABIBIBIII);\nABIN(NAABIIBIABINABIBI);\nABIN(NABNANBB);\nABIN(NAABIBIIBI);\nABIN(NAAABBIBNB);\nABIN(NAABIIBIABINABIBI);\n/* True but unprovable */ ABIN(NANBB);\n"
  },
  {
    "path": "scripts/examples/MinimumSpanningTree.ys",
    "content": "\n/* Minimum spanning tree algorithm: example of a greedy algorithm.\n * Given a set of nodes N, and edges E with each edge defined as\n * {cost,node1,node2} in the list of edges Edges, return a list of\n * edges such that every node is in the network and the network has\n * the lowest cost possible.\n *\n * It can be proven that a greedy algorithm works in this case: at each\n * step take the cheapest edge that adds one node to the network.\n */\n\n\nEdgeCompare(edge1,edge2):= (edge1[1] < edge2[1]);\n\nMinimumSpanningTree(NrNodes_IsPositiveInteger,Edges_IsList) <--\n[\n  Local(CurrentNetwork,Result,Failed);\n  Failed := False;\n\n  /* Sort the edges by cost (cheapest first) */\n  Edges := BubbleSort(Edges,\"EdgeCompare\"); /* TODO Use Sort if defined */\n\n  /* Consume the first edge, it adds two nodes to the network. */\n  CurrentNetwork := FlatCopy(Tail(Edges[1]));\n  Result := {Edges[1]};\n  Edges := Tail(Edges);\n\n  /* Loop, trying to add every node once to the network */\n  While((Length(CurrentNetwork) < NrNodes) And Failed = False)\n  [\n    Local(EdgeFound,NodeAdded,Traverser);\n     EdgeFound := 0;\n     Traverser:=1;\n\n     /* Loop over all edges, searching for the cheapest edge that adds a node to\n the\n      * current network.\n      */\n     While(EdgeFound = 0 And Traverser <= Length(Edges))\n     [\n       Local(CurrentEdge);\n\n       /* See if the current edge adds exactly one node to the currently\ncheapest network */\n       CurrentEdge := Edges[Traverser];\n\n       /* If not both nodes are already in the network */\n       if (Not(Contains(CurrentNetwork,CurrentEdge[2]) And\nContains(CurrentNetwork,CurrentEdge[3])))\n       [\n          /* If the first node is already in the network, this edge adds the\nsecond */\n         if (Contains(CurrentNetwork,CurrentEdge[2]))\n          [\n            EdgeFound := Traverser;\n            NodeAdded := CurrentEdge[3];\n          ];\n\n          /* If the second node is already in the network, this edge adds the\nfirst */\n         if (Contains(CurrentNetwork,CurrentEdge[3]))\n          [\n            EdgeFound := Traverser;\n            NodeAdded := CurrentEdge[2];\n          ];\n       ];\n       Traverser ++;\n     ];\n\n     /* If no edge was found, there is no tree connecting all the nodes to the\nnetwork. */\n     if (EdgeFound = 0)\n     [\n       Failed := True;\n       Result := {};\n     ]\n     else\n     [\n       /* Add the cheapest found edge */\n       DestructiveAppend(CurrentNetwork,NodeAdded);\n       DestructiveAppend(Result,Edges[EdgeFound]);\n       DestructiveDelete(Edges, EdgeFound);\n     ];\n  ];\n\n  /* Result contains the list of edges that are the minimum spanning tree of\nthis\n   * network plus edges\n   */\n  Result;\n];\n\nTreeCost(Edges_IsList) <-- Sum(MapSingle(\"Head\",Edges));\n\n\n\n/* Check minimum spanning tree algorithm */\nVerify(TreeCost(MinimumSpanningTree(5,\n               {\n                 {10,\"Ayal\",\"Diogo\"},\n                 {5,\"Diogo\",\"Gus\"},\n                 {15,\"Diogo\",\"Neil\"},\n                 {7,\"Ayal\",\"Neil\"},\n                 {17,\"Gus\",\"Edwin\"},\n                 {15,\"Diogo\",\"Edwin\"},\n                 {25,\"Neil\",\"Edwin\"},\n                 {18,\"Ayal\",\"Diogo\"}\n               }\n)),37);\n\n\n"
  },
  {
    "path": "scripts/examples/benchbuild.ys",
    "content": "\n\n/*\n*/\nEcho({\"Doing the Wester benchmark\"});\nToFile(\"westerbench.html\")Load(\"examples/benchmark.ys\");\n\nSystemCall(\"cp westerbench.html ../docs/\");\n\nEcho({\"Doing some example calculations\"});\nToFile(\"mybench2.html\")Load(\"examples/benchmark2.ys\");\n\nSystemCall(\"cp mybench2.html ../docs/\");\n\n"
  },
  {
    "path": "scripts/examples/benchmark.ys",
    "content": "\nUse(\"testers.ys\");\n\n\nDoNext(_string) <--\n[\n NextTest(\"<font color=0000ff>\" : string : \"</font>\");\n NewLine();\n];\n\nEcho({\"<HTML><BODY BGCOLOR=\\\"ffffff\\\"><PRE><font size=4>\"});\n\nEcho({\"An assorted selection of the tests found in the Wester benchmark\"});\n\nStartTests();\n\n/*\n*/\n\nDoNext(\"Compute 50!\");\nBenchShow(50!);\n\nDoNext(\"Compute the prime decomposition of 6!.\");\nBenchShow(ans:=Factors(6!));\n\n\n\nEcho({\"This list contains lists of two elements. This list should\nbe interpreted as \"});\nBenchShow(PrettyForm(FW(ans)));\n\nDoNext(\"Compute 1/2 + ... + 1/10.\");\nBenchShow(Sum(i,2,10,1/i));\n\nDoNext(\"Compute a numerical approximation of e^(Pi*sqrt(163)) to 50 digits.\");\nBenchCall(Builtin'Precision'Set(50));\nBenchShow(N(Exp(Pi*Sqrt(163))));\n\nDoNext(\"Compute an infinite decimal representation of 1/7\");\nBenchShow(Decimal(1/7));\n\nDoNext(\"Compute the first terms of the continued fraction of Pi.\");\nBenchShow(PrettyForm(ContFrac(Internal'Pi())));\n\nDoNext(\"Simplify sqrt(2*sqrt(3)+4).\");\nBenchShow(RadSimp(Sqrt(2*Sqrt(3)+4)));\n\nDoNext(\"Simplify sqrt(14+3*sqrt(3+2*sqrt(5-12*sqrt(3-2*sqrt(2))))).\");\nBenchShow(RadSimp(Sqrt(14+3*Sqrt(3+2*Sqrt(5-12*Sqrt(3-2*Sqrt(2)))))));\n\nDoNext(\"Simplify 2*infinity-3.\");\nBenchShow(2*Infinity-3);\n\nEcho({\"Infinity is also defined for comparisons like a &lt Infinity\"});\n\nDoNext(\"Compute the normal form of (x^2-4)/(x^2+4x+4).\");\nBenchShow(PrettyForm(GcdReduce((x^2-4)/(x^2+4*x+4),x)));\n\nDoNext(\"Expand (x+1)^5, then differentiate and factorize.\");\nBenchCall(ans:=Factors(D(x)Expand((x+1)^5)));\nBenchShow(PrettyForm(FW(ans)));\n\nDoNext(\"Simplify sqrt(997) - (997^3)^(1/6).\");\nBenchShow(RadSimp(Sqrt(997) - (997^3)^(1/6)));\n\nDoNext(\"Simplify sqrt(999983) - (999983^3)^(1/6).\");\nBenchShow(RadSimp(Sqrt(999983) - (999983^3)^(1/6)));\n\nDoNext(\"Recognize that (2^(1/3)+4^(1/3))^3-6*(2^(1/3)+4^(1/3)) - 6 is 0.\");\nBenchShow(RadSimp( (2^(1/3)+4^(1/3))^3-6*(2^(1/3)+4^(1/3)) - 6));\n\n\nDoNext(\"Simplify log e^z into z only for -Pi < Im(z) <= Pi.\");\nBenchShow(Simplify(Ln(Exp(z))));\n\nDoNext(\"Invert the 2x2 matrix [[a,b],[1,ab]]. \");\nBenchCall(A:={{a,b},{1,a*b}});\nBenchShow(ans:=Inverse(A));\nBenchShow(TableForm(Simplify(ans)));\n\nDoNext(\"Find the eigenvalues of the matrix [[5, -3, -7],[-2, 1, 2],[ 2, -3, -4]].\");\nBenchCall(A:={{5,-3,-7},{-2,1,2},{2,-3,-4}});\nBenchShow(EigenValues(A));\n\n\nDoNext(\"Compute the limit of (1-cos x)/x^2 when x goes to zero. \");\nBenchShow(Limit(x,0)(1-Cos(x))/(x^2));\n\nDoNext(\"Compute the derivative of |x|.\");\nBenchShow(D(x)Abs(x));\n\nDoNext(\"Compute an antiderivative of |x|.\");\nBenchShow(AntiDeriv(x,Abs(x)));\n\nDoNext(\"Compute the derivative of |x| (piecewise defined).\");\nBenchShow(D(x)(if (x<0) (-x) else x));\n\nDoNext(\"Compute the antiderivative of |x| (piecewise defined).\");\nBenchShow( AntiDeriv(x,if (x<0) (-x) else x));\n\nDoNext(\"Compute the first terms of the Taylor expansion of 1/sqrt(1-v^2/c^2) at v=0. \");\nBenchCall(ans:=Taylor(v,0,4)Sqrt(1/(1-v^2/c^2)));\nBenchCall(ans:=Simplify(ans));\nBenchShow(PrettyForm(ans));\n\nDoNext(\"Compute the inverse of the square of the above expansion. \");\nBenchCall(ans:=Taylor(v,0,4)(1/ans)^2);\nBenchShow(PrettyForm(Simplify(ans)));\n\n\n\nDoNext(\"Compute the Taylor expansion of tan(x) at x=0 by dividing the expansion of sin(x) by that of cos(x). \");\nBenchCall(ans1:=Taylor(x,0,5)(Sin(x)/Cos(x)));\nBenchCall(PrettyForm(ans1));\nBenchCall(ans2:=Taylor(x,0,5)Tan(x));\nBenchCall(PrettyForm(ans2));\nBenchShow(ans1-ans2);\n\n\nDoNext(\"Compute the Legendre polynomials directly.\");\n\nBenchCall(10 # Legendre(0,_x) <-- 1);\nBenchCall(20 # Legendre(n_IsInteger,_x) <--\n[\n Local(result);\n result:=[\n   Local(x);\n   Expand((1/(2^n*(n!))) * Deriv(x,n)Expand((x^2-1)^n,x));\n ];\n Eval(result);\n]);\n\nBenchCall(ForEach(item,Table(Legendre(i,x),i,0,4,1))PrettyForm(item));\n\n\nDoNext(\"Compute the Legendre polynomials recursively, using their recurrence of order 2. \");\n\nBenchCall(10 # LegendreRecursive(0,_x) <-- 1);\nBenchCall(20 # LegendreRecursive(1,_x) <-- x);\nBenchCall(30 # LegendreRecursive(n_IsPositiveInteger,_x) <--\n     Expand(((2*n - 1)*x*LegendreRecursive(n-1,x)-(n - 1)*LegendreRecursive(n-2,x))/n));\n\nBenchCall(ForEach(item,Table(LegendreRecursive(i,x),i,0,4,1))PrettyForm(item));\n\nDoNext(\"Evaluate the fourth Legendre polynomial at 1. \");\nBenchShow(Legendre(4,1));\n\nDoNext(\"Define the polynomial p = sum( i=1..5, ai*x^i ). \");\nBenchCall(ans:=Sum(MakeVector(a,5)*(FillList(x,5)^(1 .. 5))));\nBenchCall(PrettyForm(ans));\n\nDoNext(\"Apply Horner\\'s rule to the above polynomial.\");\nBenchCall(ans:=Sum(MakeVector(a,5)*(FillList(x,5)^(1 .. 5))));\nBenchCall(PrettyForm(Horner(ans,x)));\n\n\nDoNext(\"Compute the first terms of the continued fraction of Pi. \");\nBenchCall(pi:=N(Pi,20));\nBenchCall(a:=ContFrac(pi,6));\nBenchCall(PrettyForm(a));\n\nDoNext(\"Compute an infinite decimal representation of 1/7. \");\nBenchShow(Decimal(1/7));\nEcho({\"This result means that the decimal expansion of 1/7 is\n0.142857142857142....\"});\n\nDoNext(\"Evaluate TRUE and FALSE. \");\nBenchShow(True And False);\n\nDoNext(\"Solve the equation tan(x) = 1. \");\nBenchShow(Solve(Tan(x)==1,x));\n\nDoNext(\"Revert the Taylor expansion of sin(y) + cos(y) at y=0. \");\nBenchCall(t:=InverseTaylor(y,0,6)Sin(y)+Cos(y));\nBenchCall(PrettyForm(t));\nEcho({\"And check that it is in fact the inverse up to degree 5:\"});\nBenchCall(s:=Taylor(y,0,6)Sin(y)+Cos(y));\nBenchShow(BigOh(Subst(y,s)t,y,6));\n\nDoNext(\"Solve the linear (dependent) system x+y+z=6,2x+y+2z=10,x+3y+z=10.\");\nBenchShow(OldSolve({x+y+z==6,2*x+y+2*z==10,x+3*y+z==10},{x,y,z}));\n\n\n\nDoNext(\"Evaluate True And False\");\nBenchShow(True And False);\nBenchShow(CanProve(True And False));\n\nDoNext(\"Simplify x or (not x)\");\nBenchShow(CanProve(x Or Not x));\n\nDoNext(\"Simplify x or y or (x and y)\");\nBenchShow(CanProve(x Or y Or (x And y)));\n\nEcho({curline,\" examples done\"});\n\nEcho({\"</FONT></PRE></BODY></HTML>\"});\n"
  },
  {
    "path": "scripts/examples/benchmark2.ys",
    "content": "\n\nUse(\"testers.ys\");\n\n\nDoNext(_string) <--\n[\n NextTest(\"<font color=0000ff>\" : string : \"</font>\");\n NewLine();\n];\n\nEcho({\"<HTML><BODY BGCOLOR=\\\"ffffff\\\"><PRE><font size=4>\"});\n\nEcho({\"An assorted selection of example calculations using Yacas\"});\n\nStartTests();\n\n/*\n*/\n\nDoNext(\"Show that Integrate(-Pi,Pi) (Sin(n*x)*Cos(m*x)) is Pi*Delta(n,m)\");\n\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Sin(x)*Sin(2*x)) ));\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Sin(2*x)*Sin(2*x)) ));\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Sin(5*x)*Sin(5*x)) ));\n\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Cos(x)*Cos(2*x)) ));\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Cos(2*x)*Cos(2*x)) ));\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Cos(5*x)*Cos(5*x)) ));\n\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Sin(x)*Cos(2*x)) ));\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Sin(2*x)*Cos(2*x)) ));\nBenchShow(Simplify(Integrate(x,-Pi,Pi) (Sin(5*x)*Cos(5*x)) ));\n\n\nDoNext(\"Get the first 5 coefficients of the Fourier series of x^2\non the domain -Pi to Pi. This should be (1/Pi)*Sum(n,0,4)a_n * Cos(n*x)\");\n\nBenchShow(Fourier(_n,_f) <-- (1/(Pi))*Integrate(x,-Pi,Pi)(f*Cos(n*x)) );\nBenchShow(TableForm(Simplify(Table(Fourier(n,x^2),n,0,5,1))));\n\nDoNext(\"Check that f:=x*Exp(-x/2) is a solution to the equation H(f)=E f\nwhere E is a constant and H is D(x)D(x)f + f/x\");\n\nBenchCall(H(f):=(Deriv(x)Deriv(x)f) + f/x);\nBenchCall(f:=x*Exp(-x/2));\nBenchCall(res:=H(f));\nBenchCall(PrettyForm(Simplify(res)));\nBenchCall(PrettyForm(Simplify(res/f)));\n\n\nDoNext(\"Show that the first few terms of the Taylor series expansion\nof Sin(x) and Cos(x-Pi/2) are the same\");\nBenchCall(ans1:=Taylor(x,0,8)Sin(x));\nBenchCall(PrettyForm(ans1));\nBenchCall(ans2:=Taylor(x,0,8)Cos(x-Pi/2));\nBenchCall(PrettyForm(ans2));\nBenchShow(ans1-ans2);\n\n\nDoNext(\"Determine a polynomial that goes through the points\n(x,y) = { (-2,4), (1,1), (3,9) } and show that it is in fact x^2\");\n\nBenchCall(ans:=LagrangeInterpolant({-2,1,3},{4,1,9},x));\nBenchCall(PrettyForm(ans));\nBenchCall(PrettyForm(Simplify(ans)));\n\nEcho({curline,\" examples shown\"});\n\nEcho({\"</FONT></PRE></BODY></HTML>\"});\n"
  },
  {
    "path": "scripts/examples/findsum.ys",
    "content": "/* O(2^n) algorithm for finding all combinations of numbers in a list\n * that total a specific number.\n *\n * Calling sequence: FindSum(total_IsNumber, l_IsList)\n *\n * It returns a list of lists, each list containing a group of elements\n * that add up to the requested number.\n *\n * This algorithm can be speeded up a lot if the summation is only done\n * for numbers (by separating out the positive and negative values),\n * but this routine is shorter and also works for any object you care\n * to throw at it that has an addition operator defined for it (matrices,\n * vectors, complex numbers, polynoms, etc.).\n *\n * It is a nice example of a piece of code that does things the Prolog\n * way. The result is accumulated in one argument, which is treated as\n * a list of results.\n *\n * Example:  \n *\n * In( 1 ) = FindSum(10,{2,3,4,5,6,7})\n * Out( 1 ) = {{6,4},{7,3},{5,3,2}};\n *\n */\n\n/* Main entry point for FindSum. */\nFindSum(_total, l_IsList) <--\n\t[\n\t  Local(r);\n\t  r:={};                    /* r will contain the results. */\n\t  FindSum(total, l,{},0,r); /* find the solution */\n\t  r;                        /* return the results */\n\t];\n\n/* this is an exact match: add the current sum to the results. */\n10 # FindSum(_total, _l, _current, _total, _result) <-- DestructiveAppend(result, current);\n\n/* All terms consumed. return results found. */\n20 # FindSum(_total, {}, _current, _sum, _result)   <-- True;\n\n/* Try to find sums, starting from current term and sum. */\n30 # FindSum(_total, _l, _current, _sum, _result)   <--\n\t [\n\t   Local(term);\n           /* New term that can be used for sum.   */\n\t   term:=Head(l);\n\t   /* try to find a sum WITHOUT this term. */\n\t   FindSum(total, Tail(l),      current, sum,      result);\n\t   /* try to find a sum WITH    this term. */\n\t   FindSum(total, Tail(l), term:current, sum+term, result);\n\t ];\n\n\n"
  },
  {
    "path": "scripts/examples/goldbach.ys",
    "content": "\n/*\n * Example: brute force search to check Goldbach's conjecture.\n * Goldbachs conjecture: for each even number n larger than 2 there\n * are at least two primes p and q such that p+q=n. The function \n * GoldBach returns a list of pairs of numbers that sum up to the\n * even number supplied as input.\n *\n * Examples:\n * In> GoldBach(10)\n * Out> {{7,3},{5,5}};\n * In> MapSingle(\"Length\",GoldBach(2*(2 .. 10)))\n * Out> {1,1,1,2,1,2,2,2,2};\n * \n */\n \n \n \n/* Main routine */\nGoldBach(m_IsEven) <--\n[\n  Local(p);\n\n  /* Select all primes up to m/2 */\n  p:=Select(\"IsPrime\", 1 .. (m/2));\n\n  /* Given the primes p, select all the primes in (m-p) */\n  p:=Select(\"IsPrime\",m-p);\n\n  /* Return a list with the solutions */\n  Transpose({p,m-p});\n];\n\n/* Given a list of numbers, apply the goldbach test on each one of them. */\nGoldBach(m_IsList) <-- MapSingle(\"GoldBach\",m);\n\n"
  },
  {
    "path": "scripts/examples/pi.ys",
    "content": "/* Calculating Pi to multiple precision using advanced methods */\n\n/* Defined: PiMethod0(), PiMethod1(), PiMethod2(), PiBrentSalamin(), PiBorwein() */\n\n// Reference method: just use Newton's method all the time, no complicated logic to select precision steps. Slightly slower than method 1 but a lot simpler. This is implemented in Internal'Pi()\n\nPiMethod0() := [\n\tLocal(result, delta, k, Epsilon, prec, prec1, curprec);\n\tprec := Builtin'Precision'Get();\t// full required precision\n\tprec1 := Ceil(N(prec/3));\t// precision of the last-but-one iteration\n\n\t/* initial approximation */\n\tresult := 3.14159265358979323846;\n\tcurprec := 20;\n\tBuiltin'Precision'Set(curprec);\n\tFor(k:=0, curprec < prec1, k:=k+1) [\n\t\tcurprec := Min(prec1, curprec * 3);\n\t\tBuiltin'Precision'Set(curprec);\n\t\tEcho({\"Iteration \", k, \" setting precision to \", curprec});\n\t\tresult := Time(MathAdd(result, MathSin(result)));\n\t];\n\t// last iteration -- do by hand\n\tBuiltin'Precision'Set(prec);\t// restore full precision\n\tEcho(\"Iteration \", k, \" setting precision to \", Builtin'Precision'Get());\n\tresult := Time(MathAdd(result, MathSin(result)));\n\tEcho({\"variable precision Newton's method: \", k, \"iterations\"}); \n\tresult;\n];\n\n/* Brute-force method 1: start near 3.14159... and iterate using Nth order\nNewton method: x := x + ( sin(x) + 1/6*sin(x)^3 + 3/40*sin(x)^5 +\n5/112*sin(x)^7 + ...) i.e. the Taylor series for arcsin but cut at a finite\npoint. Convergence is of order of the next term, i.e. x^9, but need to evaluate\nSin() at each step. However, we don't need to evaluate them to full precision\neach time, because each iteration will correct any accumulated errors. In fact,\nfirst iterations can be computed with significantly lower precision than the\nfinal result. This makes method1 the fastest for Yacas internal math. */\n\nPiMethod1() := [\n\tLocal(result, delta, deltasq, k, Epsilon, prec, curprec);\n\tprec := Builtin'Precision'Get();\n\tN([\n    /* initial approximation */\n    curprec := 20;\n    Builtin'Precision'Set(curprec);\n    result := 3.14159265358979323846;\n    /* right now we do all but the last iteration using the 8th order scheme, and the last iteration is done using the 2nd order scheme. However it would be faster to use a very high-order scheme first, then a smaller-order scheme, etc., because it's faster to do multiplications at low precision.\n    */\n    For(k:=0, curprec*3 < prec, k := k+1) [\n      curprec := Min(Ceil((prec/3)), curprec * 9);\n      Builtin'Precision'Set(curprec);\n      Echo(\"Iteration \", k, \" setting precision to \", Builtin'Precision'Get());\n      delta := MathSin(result);\n      deltasq := (delta*delta);\n      result := Time(result + delta*(1 + deltasq*(1/6 + deltasq*(3/40 + deltasq*5/112))));\n    ];\n    // now do the last iteration\n    Builtin'Precision'Set(prec);\n    k := k+1;\n    Echo(\"Iteration \", k, \" setting precision to \", Builtin'Precision'Get());\n    result := Time(MathAdd(result, MathSin(result)));\n    Echo({\"8th order Newton's method: \", k, \"iterations\"}); \n  ]);\n\tresult;\n];\n\n/* Brute-force method 2: evaluate full series for arctan */\n/* x0 := 3.14159... and Pi = x0 - ( tan(x0) - tan(x0)^3/3 + tan(x0)^5/5 +...) i.e. the Taylor series for arctan - go until it converges to Pi. Convergence is linear but unlike method 1, we don't need to evaluate Sin() and Cos() at every step, and we can start at a very good initial approximation to cut computing time.\n*/\n\nPiMethod2() := [\n\tLocal(result, delta, tansq, k, Epsilon);\n\tN([\n    Epsilon := (2*10 ^ (-Builtin'Precision'Get()));\n\n    /* initial approximation */\n    result := 3.141592653589793;\n    delta := (-Tan(result));\n    tansq := (delta^2);\n    k := 0;\n    \n    While(Abs(delta) > Epsilon) [\n  //\t\tEcho(result);\n      result := (result + delta/(2*k+1));\n  //\t\tEcho(delta, k);\n      delta := (-delta * tansq);\n      k := k+1;\n    ];\n    Echo({\"Brute force method 2 (ArcTan series): \", k, \"iterations\"}); \n  ]);\n\tresult;\n];\n\n/* Method due to Brent and Salamin (1976) */\nPiBrentSalamin() := [\n\tLocal(a, b, c, s, k, p, result, Epsilon);\n\tEpsilon := N(2*10 ^ (-Builtin'Precision'Get()));\n\n\t/* initialization */\n\ta := 1; b := N(1/Sqrt(2)); s := N(1/2); k := 0;\n\t/* this is just to make sure we stop - the algorithm does not require initialization of p */\n\tp := 0; result := 1;\n\t/* repeat until precision is saturated */\n\tWhile(Abs(p-result) >= Epsilon) [\n\t\tk := k+1;\n\t\tresult := p;\n\t\t/* arithmetic and geometric mean */\n\t\t{a, b} := {N((a+b)/2), N(Sqrt(a*b))};\n\t\t/* difference between them is scaled by 2^k */\n\t\ts := N(s - 2^k*(a^2-b^2));\n\t\tp := N(2*a^2/s);\n\t];\n\tEcho({\"Brent and Salamin's algorithm: \", k, \"iterations\"}); \n\t\n\tresult;\n];\n\n/* Method due to Borwein (c. 1988) -- \"quartic\" method */\nPiBorwein() := [\n\tLocal(a, y, y4s, k, result, Epsilon);\n\tEpsilon := N(2*10 ^ (-Builtin'Precision'Get()));\n\n\t/* initialization */\n\ta:=N(6-4*Sqrt(2)); y := N(Sqrt(2)-1); k := 0;\n\tresult := 0;\n\t/* repeat until precision is saturated */\n\tWhile(Abs(a-result) >= Epsilon) [\n\t\tresult := a;\n\t\t/* precompute (1-y^4)^(1/4) */\n\t\ty4s:=N(Sqrt(Sqrt(1-y^4)));\n\t\t/* black magic */\n\t\ty := N((1-y4s)/(1+y4s));\n\t\t/* more black magic */\n\t\ta := a*(1+y)^4-2^(2*k+3)*y*(1+y+y^2);\n\t\tk := k+1;\n\t];\n\t/* {a} will converge to 1/Pi */\n\tresult := N(1/result);\n\n\tEcho({\"Borwein's quartic algorithm: \", k, \"iterations\"}); \n\tresult;\n];\n\n// iterate x := x + Cos(x) + 1/6 *Cos(x)^3 + ... to converge to x=Pi/2\nPiMethod3() :=\n[\n\tLocal(result, delta, deltasq, k, order, prec, curprec);\n\torder := 13;\t// order of approximation\n\tprec := Builtin'Precision'Get();\n  N([\n    /* initial approximation */\n    curprec := 20;\n    Builtin'Precision'Set(curprec);\n    result := 3.14159265358979323846*0.5;\n    // find optimal initial precision\n    For(k:=prec, k>=curprec, k:=Div(k,order)+2) True;\n    If(k<5, curprec:=5, curprec:=k);\n  //\tEcho(\"initial precision\", curprec);\n    // now k is the iteration counter\n    For(k:=0, curprec < prec, k := k+1) [\n    // at this iteration we know the result to curprec digits\n      curprec := Min(prec, curprec * order-2);\t// 2 guard digits\n      Builtin'Precision'Set(curprec+2);\n      Echo(\"Iteration \", k, \" setting precision to \", Builtin'Precision'Get());\n  //\t\tEcho(\"old result=\", MathCos(result));\n      Time([\n      delta := MathCos(result);\n      ]);\n      Time([\n      deltasq := MathMultiply(delta,delta);\n      ]);\n      result := Time(result + delta*(1 + deltasq*(1/6 + deltasq*(3/40 + deltasq*(5/112 + deltasq*(35/1152 + (deltasq*63)/2816))))));\n    ];\n    Echo({\"Method 3, using Pi/2 and order\", order, \":\", k, \"iterations\"});\n  ]);\n\tresult*2;\n];\n\nPiChudnovsky() :=\n[\t// use the Ramanujan series found by Chudnovsky brothers\n\tLocal(A, B, C, n, result, term);\n\tA:=13591409; B:=545140134; C:=640320; // black magic, Rama, Rama, Ramanujan\n\tprec := Builtin'Precision'Get();\n  N([\n    n:=Div(prec*479,6793)+1;\t// n> P*Ln(10)/(3*Ln(C/12))\n    Echo({\"Method: Chudnovsky, using \", n, \" terms\"});\n    Builtin'Precision'Set(prec+IntLog(n,10)+5);\n    result := (A+n*B);\n    While(n>0)\n    [\n  //\tEcho(n,result);\n      result := A+(n-1)*B-24*(6*n-1)*(2*n-1)*(6*n-5) /(C*n)^3 *result;\n      n--;\n    ];\n    result := C/12*Sqrt(C)/Abs(result);\n  ]);\n\tBuiltin'Precision'Set(prec);\n\tRoundTo(result,prec);\n];\n\nBenchmarkPi(prec) :=\n[\n\tLocal(result);\n\tGlobalPush(Builtin'Precision'Get());\n\tBuiltin'Precision'Set(prec);\n\t\n\tresult := {\n\t\tTime(MathPi()),\n\t\tTime(PiMethod0()),\n\t\tTime(PiMethod1()),\n\t\tTime(PiMethod2()),\n\t\tTime(PiMethod3()),\n//\t\tTime(PiMethod4()),\n\t\tTime(PiChudnovsky()),\n\t\tTime(PiBrentSalamin()),\n\t\tTime(PiBorwein()),\n\t};\n\tresult := N(Sin(result));\n\tBuiltin'Precision'Set(GlobalPop());\n\tresult;\n];\n"
  },
  {
    "path": "scripts/examples/queens.ys",
    "content": "\n/* Example: queens problem. */\n\n/* Queens(n) : main entry function. This function returns a list of\n * results to the n-queens problem. The results will be lists of numbers,\n * for instance {2,3,1,4} which is to be interpreted as queens standing\n * on (1,2), (2,4), (3,1) and (4,3).\n *\n * No typechecking is done on the arguments of the internal functions,\n * only on Queens(n), since that is the only function that should be\n * used by the outside world.\n */\nQueens(n_IsPositiveInteger) <--\n[\n  Local(result);\n  Set(result,{});\n  Queens(n,{},1 .. n,result);  /* build result */\n  result;         /* return result */\n];\n\n\n/* IsOnDiagonal determines if two queens are on a diagonal */\n10 # IsOnDiagonal({_x1,_y1},{_x2,_y2})_(MathSubtract(x1,x2) = MathSubtract(y1,y2)) <-- True;\n20 # IsOnDiagonal({_x1,_y1},{_x2,_y2})_(MathSubtract(x1,x2) = MathSubtract(y2,y1)) <-- True;\n30 # IsOnDiagonal(_n,_m)                               <-- False;\n\n/* QueenCollides determines if a new queen to be positioned on n collides\n * with the queens on positions held in the list\n */\n10 # QueenCollides(_n,_list) <--\n[\n  Local(result);\n  Set(result, False);\n  While(And(Not(result), Not(Equals(list, {}))))\n  [\n    Set(result, IsOnDiagonal(n,Head(list)));\n    Set(list, Tail(list));\n  ];\n  result;\n];\n\n\n/* If new queen does not collide with other queens, add to try list,\n * and solve the n-1 queens problem\n */\nTryAddQueen(_n,_element,_try,_use,_result)_\n            Not(QueenCollides(element,try)) <--\n[\n  Queens(MathSubtract(n,1),element:try,use,result);\n];\n\n\n/* Recursive solve n-queens problem.*/\n\n/* All queens checked, so add the result. */\n10 # Queens( 0,_try,_touse,_result) <-- DestructiveInsert(result,1,try);\n20 # Queens(_n,_try,_touse,_result) <--\n[\n  Local(tailuse,i);\n  Local(nextuse);\n  Set(tailuse, touse);\n  Set(i, 1);\n  While(Not(Equals(tailuse, {})))\n  [\n    Set(nextuse,FlatCopy(touse));\n    DestructiveDelete(nextuse,i);\n    TryAddQueen(n, {n,Head(tailuse)}, try, nextuse, result );\n    Set(tailuse,Tail(tailuse));\n    Set(i, MathAdd(i,1));\n  ];\n];\n\n\n\n"
  },
  {
    "path": "scripts/examples/series.ys",
    "content": "\n/* Generate a polynomial base1 + base2*x + ....*/\nArbPoly(_base,n_IsPositiveInteger) <-- Sum(MakeVector(base,n)*x^(0 .. (n-1)));\n\n/*\n   SinTaylor and ExpTaylor: direct series for the taylor series expansions\n   of Sin and Exp.\n   Examples:\n   \n   In> Simplify(SinTaylor(10) - Taylor(x,0,10)Sin(x))\n   Out> 0;\n   In> Simplify(ExpTaylor(10) - Taylor(x,0,10)Exp(x))\n   Out> 0;\n*/\n\nSinTaylor(n_IsPositiveInteger) <-- \n[\n  Local(m);\n  n:=((n-1)>>1);\n  m:=(1+2*(0 .. n));\n  Sum((-1)^(0 .. n)*x^m/(m!));\n];\n\nExpTaylor(n_IsPositiveInteger) <-- \n[\n  Sum(x^(0 .. n)/((0 .. n)!));\n];"
  },
  {
    "path": "scripts/examples/wordproblems.ys",
    "content": "/// Solve aritmetic problems written in (limited) English\n///\n/// Supported words:\n/// a an the is are and person persons object objects many has had ate gave to some made\n/// See coding.book section \"Example: Using rules with special syntax operators creatively\"\n\n\nPrefix(\"a\", 10);\nPrefix(\"an\", 10);\nInfix(\"to\", 15);\nPrefix(\"the\", 10);\nPrefix(\"many\", 35);\t// many apples and pears\nInfix(\"is\", 20);\nInfix(\"had\", 20);\nInfix(\"has\", 20);\nInfix(\"ate\", 20);\nInfix(\"gave\", 20);\nInfix(\"made\", 20);\nPrefix(\"some\", 10);\nInfix(\"and\", 30);\nInfix(\"are\", 40);\n\n/// object name in person's inventory is stored in plural unless it's uncountable\nKnowledge := {\n\t{\"objects\", {} },\n\t{\"countable objects\", {} },\n\t{\"persons\", {} }\n};\n\n/// articles a, an are the same as quantifiers and can be used only with countable objects\n10 # (an _x) _(Not IsList(x) And IsCountableObject(PluralFromSingular(x)))  <-- {PluralFromSingular(x), 1};\n10 # (a _x) _(Not IsList(x) And IsCountableObject(PluralFromSingular(x)))  <-- {PluralFromSingular(x), 1};\n// \"the\" with countable\n10 # (the _x) _(Not IsList(x) And IsCountableObject(PluralFromSingular(x)))  <-- {PluralFromSingular(x), 1};\n// \"the\" with uncountable\n20 # (the _x) _(Not IsList(x) And IsSomeObject(x))  <-- {x, 1};\n\n20 # _x is a person <-- DeclarePerson(x);\n20 # _x is an object <-- DeclareObject(x);\n\n/// multiple \"and\" clauses\n10 # x_IsList and _y <-- Concat(x, {y});\n15 # _x and _y <-- Concat({x}, {y});\n\n/// \"some\"\nsome _obj <-- {obj, True};\n\n/// declare many objects or many persons at once\n20 # x_IsList are persons <-- MapSingle(\"DeclarePerson\", x);\n20 # x_IsList are objects <-- MapSingle(\"DeclareObject\", x);\n\n10 # there are many xs_IsList <-- MapSingle(\"DeclareCountable\", xs);\n20 # there are many _xs <-- DeclareCountable(xs);\n\n/// aux function\nDeclarePerson(x) :=\n\t// check that hasn't been already declared\n\tIf (\n\t\tIsPerson(x),\n\t\tEcho({\"Note: we already know that \", x, \" is a person\"}),\n\t\t[\n\t\t\t// store knowledge: person with empty inventory list\n\t\t\tKnowledge[\"persons\"][String(x)] := {};\n\t\t\tEcho({\"OK, \", x, \"is a person.\"});\n\t\t]\n);\n\n/// predicates\nIsPerson(x) := Contains(AssocIndices(Knowledge[\"persons\"]), String(x));\n/// countable objects are always in plural (IsCountableObject(apple) <-- False if \"apples\" is defined)\nIsCountableObject(x) := Contains(Knowledge[\"countable objects\"], String(x));\n/// IsSomeObject(x) means that either x is uncountable, or the plural form of x is countable\nIsSomeObject(x) := Contains(Knowledge[\"objects\"], String(x));\n\n/// AssumeIsPerson will always return True and will declare a person if needed\nAssumeIsPerson(x) := If(IsPerson(x), True, DeclarePerson(x));\n\n/// declare uncountable object\nDeclareObject(x) :=\n\t// check that hasn't been already declared\n\tIf (\n\t\tIsSomeObject(x) Or IsCountableObject(x),\n\t\tEcho({\"Note: we already know that \", x, \" is an object\"}),\n\t\t[\n\t\t\t// store knowledge: object name\n\t\t\tPush(Knowledge[\"objects\"], String(x));\n\t\t\tEcho({\"OK, \", x, \"is an object.\"});\n\t\t]\n\t);\n\nDeclareCountable(x) := [\n\tLocal(singular);\n\tsingular := SingularFromPlural(x);\n\tDeclareObject(singular);\n\t// check that hasn't been already declared\n\tIf(\n\t\tIsCountableObject(x),\n\t\tEcho({\"Note: we already know that there are many \", x}),\n\t\t[\n\t\t\t// store knowledge: countable object\n\t\t\tPush(Knowledge[\"countable objects\"], String(x));\n\t\t\tMacroRuleBase(String(x), {n});\n\t\t\tMacroRule(String(x), 1, 1, True) {x, n};\n\t\t\t// Postfix does not evaluate its argument, so need to jump through hoops\n\t\t\tEval(UnList({Postfix, String(x)} ));\n\t\t\tEcho({\"OK, we assume that the plural of \\\"\", singular, \"\\\" is \\\"\", x, \"\\\".\"});\n\t\t]\n\t);\t\t\n];\n\n\n\n\n/// get singular forms from plural, e.g. apples->apple\nSingularFromPlural(x) := [\n\tLocal(singular);\n\tsingular := String(x);\t// cut the ending \"s\"\n\tsingular := StringMid'Get(1, Length(singular)-1, singular);\n\tAtom(singular);\n];\n\n/// get plural forms from singular, e.g. apple->apples\nPluralFromSingular(x) := [\n\tLocal(plural);\n\tplural := ConcatStrings(String(x), \"s\");\t// add the ending \"s\"\n\tAtom(plural);\n];\n\n/// find out how much they have and print an atom as a result\n/// note that \"x has {list}\" is a predicate defined below\n/// print number for countable objects and \"some\" or \"no\" for uncountable\n10 # (_x has _obj)_(Not IsList(obj)) <-- [\n\tLocal(quantity);\n\t// defined \"quantity\" just to save typing\n\tquantity := Knowledge[\"persons\"][String(x)][String(obj)];\n\tIf(\n\t\tIsPerson(x),\n\t\tIf(quantity=0 Or quantity=Empty, no, \n\t\t\tIf(IsSomeObject(obj), \"some\", quantity\n\t\t\t)\n\t\t)\n\t\t, False\n\t);\n];\n\n/// predicates to check who has what -- note difference from the above function\n10 # _x has {_obj, True} <-- IsPerson(x) And Knowledge[\"persons\"][String(x)][String(obj)] != Empty And Knowledge[\"persons\"][String(x)][String(obj)] > 0;\n20 # _x has {_obj, n_IsInteger} <-- IsPerson(x) And Knowledge[\"persons\"][String(x)][String(obj)] = n;\n\n/// limitation: cannot match abstract functions with special syntax, e.g. can't do this:\n///10 # (x_IsPerson had _obj(n_IsInteger)) <-- ...;\n/// when _obj is supposed to match *any* prefix operator.\n/// therefore we shall transform object quantifiers first.\n\n/// \"x had N As\" parsed into \"Serge had {apples, 6}\"\n10 # (x_AssumeIsPerson had {_obj, n_IsInteger}) _ (IsCountableObject(obj) Or n = 1 And IsSomeObject(obj)) <-- [\n\t// check knowledge: did they have it before? if yes, print warning\n\tIf(\n\t\tx has some obj,\t// need to check if it is consistent\n\t\tIf(\n\t\t\tx has {obj, n},\n\t\t\tEcho({\"Note: we already know that \", x, \" had \", n, \" \", obj, \" at that time.\"}),\n\t\t\t[\n\t\t\t\tEcho({\"Error: we know that \", x,\" had \", x has obj, \" \", obj, \" at that time.\"});\n\t\t\t\tFalse;\n\t\t\t]\n\t\t),\n\t\t[\n\t\t\t// store knowledge: x now has n obj's\n\t\t\tKnowledge[\"persons\"][String(x)][String(obj)] := n;\n\t\t\tSynopsis(x, obj);\n\t\t]\n\t);\n];\n\n/// \"x ate N As\" \n10 # (x_AssumeIsPerson ate {_obj, n_IsInteger}) _ (IsCountableObject(obj) Or n = 1 And IsSomeObject(obj)) <--\n\t// check knowledge: did they have it before? if yes, print warning\nIf(\n\t(x has some obj) And (IsCountableObject(obj) And (x has obj) >= n Or Not IsCountableObject(obj)),\t// need to check if it is consistent\n\t[\n\t\t// store knowledge: x now has fewer obj's\n\t\tKnowledge[\"persons\"][String(x)][String(obj)] := Knowledge[\"persons\"][String(x)][String(obj)] - n;\n\t\tSynopsis(x, obj);\n\t],\n\t[\n\t\tEcho({\"Error: \", x, \" does not have enough \", obj, \" at this time.\"});\n\t\tFalse;\n\t]\n);\n\n/// aux function to print diagnostic messages\nSynopsis(x, obj) := Echo({\"OK, \", x, \" has \", x has obj, \" \", obj, \" now.\"});\n\n/// X ate some A (uncountable only)\n20 # (x_AssumeIsPerson ate {_obj, True}) _ (Not IsList(obj) And IsSomeObject(obj)) <--\n\tIf(\n\t\tx has some obj,\n\t\tEcho({\"OK, \", x, \" still has some \", obj}),\n\t\t[\n\t\t\tEcho({\"Error: \", x, \" does not have any \", obj});\n\t\t\tFalse;\n\t\t]\n\t);\n/// X ate A\n30 # (x_AssumeIsPerson ate _obj)_ (Not IsList(obj) And IsSomeObject(obj)) <-- x ate {If(IsCountableObject(PluralFromSingular(obj)), PluralFromSingular(obj), obj), 1};\n\n/// interface for \"had\" in case we are dealing with uncountable objects\n/// {obj, True} is a result of \"some obj\"\n20 # (x_AssumeIsPerson had {_obj, True}) _ (Not IsList(obj)) <-- x had {obj, 1};\n/// just \"obj\" means \"1 obj\" or \"1 objs\" depending on whether \"obj\" is countable\n30 # (x_AssumeIsPerson had _obj) _ (Not IsList(obj)) <-- x had {If(IsCountableObject(PluralFromSingular(obj)), PluralFromSingular(obj), obj), 1};\n\n/// making new objects\n10 # (x_AssumeIsPerson made {_obj, n_IsInteger}) _ (IsCountableObject(obj) Or n = 1 And IsSomeObject(obj)) <-- [\n\tLocal(quantity);\n\tquantity := Knowledge[\"persons\"][String(x)][String(obj)];\n\tIf(IsNumber(quantity),\n\t\tquantity := quantity + n,\n\t\tquantity := n\n\t);\n\tKnowledge[\"persons\"][String(x)][String(obj)] := quantity;\n\tSynopsis(x, obj);\n];\n\n/// interface for making \"some\" new object\n20 # (x_AssumeIsPerson made {_obj, True}) _ (Not IsList(obj) And IsSomeObject(obj) And Not IsCountableObject(PluralFromSingular(obj))) <-- x made {obj, 1};\n30 # (x_AssumeIsPerson made _obj) _ (Not IsList(obj)) <-- x made {If(IsCountableObject(PluralFromSingular(obj)), PluralFromSingular(obj), obj), 1};\n\n/// giving objects to other people\n10 # _x gave _obj to _y <-- [\n\tx ate obj;\n\ty made obj;\n];\n\n/// knowledgebase is stored in a global variable Knowledge\n/// format: {{\"persons\", {{\"name\", {{\"objname\", quantity}, ...}}, ...} }, {\"objects\", {\"name\", ... } }, {\"countable objects\", {\"name\", ... } }  }\n\n/// print all knowledge\nKnowledge() := [\n\tLocal(person, object);\n\tEcho(\"OK, this is what we know:\");\n\tWriteString(\"Persons: \");\n\tWriteString(PrintList(AssocIndices(Knowledge[\"persons\"])));\n\tNewLine();\n\tWriteString(\"Object names: \");\n\tWriteString(PrintList(Knowledge[\"objects\"]));\n\tNewLine();\n\tWriteString(\"Countable objects: \");\n\tWriteString(PrintList(Knowledge[\"countable objects\"]));\n\tNewLine();\n\tForEach(person, AssocIndices(Knowledge[\"persons\"]))\n\t[\n\t\tEcho({person, \" has: \"});\n\t\tForEach(object, AssocIndices(Knowledge[\"persons\"][person]))\n\t\t\tEcho({Atom(person) has Atom(object), Atom(object)});\n\t\tEcho(\"\");\n\t];\n];\n\n/// testing\n/*\n\nJitse and Ayal are persons;\napple is an object;\nthere are many apples and pears;\nSerge had an apple;\nJitse had (10!) pears;\nAyal had (2+3) apples and Serge had 2 pears;\nSerge ate the apple;\nAyal ate a pear;\t// this should fail\nAyal gave an apple to Serge and Serge gave a pear to Ayal;\nAyal ate a pear;\nsoup is an object and Ayal had some soup;\nAyal gave soup to Serge and Serge ate the soup;\nSerge has soup\nSerge has apples\nAyal has apples\nSerge has some soup\nSerge has some apples\nAyal has some pears\nKnowledge();\nsoftware is an object\nAyal made some software\nAyal gave some software to everyone\nKnowledge();\n\n//*/\n"
  },
  {
    "path": "scripts/factors.rep/binaryfactors.ys",
    "content": "\n\nLocalSymbols(lastcoef,OrdBuild, AddFoundSolutionSingle , AddFoundSolution, Fct, MkfactD)\n[\n\nLastCoef(_vector,_p) <-- \n[\n  Local(n);\n  n:=Length(vector);\n  Add(vector*p^(0 .. (n-1)));\n];\n\n/*\nOrd(vector,q):=\n[\n  Local(n);\n  n:=Length(vector);\n  q*Coef(Simplify(LastCoef(vector,p+q)-LastCoef(vector,p)),q,1);\n];\n*/\n\nOrdBuild(vector,q):=\n[\n  Local(i,result,n);\n  Set(i,2);\n  Set(result, 0);\n  Set(n, Length(vector));\n  While (i<=n)\n  [\n    Set(result,result+(i-1)*vector[i]*p^(i-2));\n    Set(i, i+2);\n  ];\n  q*result;\n];\n\n\nFunction(AddFoundSolutionSingle,{p})\n[\n  Local(calc);\n//  If ( Not Contains(result,p),\n//  [\n    Set(calc, Eval(lastcoef));\n    If (Equals(calc, 0),\n    [\n      Local(newlist,count,root);\n      count:=0;\n      root := p;\n      Local(rem);\n\n      rem:={-root,1};\n      {testpoly,rem}:=MkfactD(testpoly,rem);\n\n      rem:={-root,1};\n      {newlist,rem}:=MkfactD(poly,rem);\n      While (rem = {})\n      [\n        count++;\n        Set(poly,newlist);\n        rem:={-root,1};\n        {newlist,rem}:=MkfactD(poly,rem);\n      ];\n\n      Local(lgcd,lc);\n      Set(lgcd,Gcd({andiv,an,root}));\n      Set(lc,Div(an,lgcd));\n      Set(result,{var+ (-(Div(root,lgcd)/lc)),count}:result);\n      Set(andiv,Div(andiv,lgcd^count));\n      Set(anmul,anmul*lc^count);\n\n//      factor:=(x-root);\n//      Set(result,{factor,count}:result);\n\n      Local(p,q);\n      Set(lastcoef, LastCoef(testpoly,p));\n      Set(ord, OrdBuild(testpoly,q));\n    ]);\n//  ]);\n];\nUnFence(AddFoundSolutionSingle,1);\n\nFunction(AddFoundSolution,{p})\n[\n  AddFoundSolutionSingle(p);\n  AddFoundSolutionSingle(-2*q+p);\n];\nUnFence(AddFoundSolution,1);\n\nFunction(Fct,{poly,var})\n[\n  Local(maxNrRoots,result,ord,p,q,accu,calc,twoq,mask);\n\n  Local(gcd);\n  [\n    Set(gcd,Gcd(poly));\n    If(poly[Length(poly)] < 0,Set(gcd, gcd * -1));\n    Set(poly,poly/gcd);\n  ];\n\n  Local(unrat);\n  Set(unrat,Lcm(MapSingle(\"Denom\",poly)));\n  Set(poly,unrat*poly);\n\n  Local(origdegree);\n  Set(origdegree,Length(poly)-1);\n\n  Local(an,andiv,anmul);\n  Set(an,poly[Length(poly)]);\n  Set(poly,poly* (an^((origdegree-1) .. -1)));\n  Set(andiv,an^(origdegree-1));\n  Set(anmul,1);\n\n  Local(leadingcoef,lowestcoef);\n  Set(leadingcoef,poly[Length(poly)]);\n  [ \n    Local(i);\n    Set(i,1);\n    Set(lowestcoef,Abs(poly[i]));\n    While (lowestcoef = 0 And i<=Length(poly))\n    [\n      Set(i,i+1);\n      Set(lowestcoef,Abs(poly[i]));\n    ];\n  ];\n  // testpoly is the square-free version of the polynomial, used for finding\n  // the factors. the original polynomials is kept around to find the\n  // multiplicity of the factor.\n  Local(testpoly);\n//  Set(testpoly,Mkc(Div(polynom,Monic(Gcd(polynom,Deriv(var)polynom))),var));\n  Local(deriv);\n  // First determine a derivative of the original polynomial\n  deriv:=Tail(poly);\n  [\n    Local(i);\n    For (i:=1,i<=Length(deriv),i++)\n    [\n      deriv[i] := deriv[i]*i;\n    ];\n//    Echo(\"POLY = \",poly);\n//    Echo(\"DERIV = \",deriv);\n  ];\n  [\n    Local(q,r,next);\n    q:=poly;\n    r:=deriv;\n    While(r != {})\n    [\n//Echo(q,r);\n      next := MkfactD(q,r)[2];\n      q:=r;\n      r:=next;\n    ];\n    // now q is the gcd of the polynomial and its first derivative.\n    \n    // Make it monic\n    q:=q/q[Length(q)];\n    testpoly:=MkfactD(poly,q)[1];\n//Echo(\"TESTPOLY = \",testpoly);\n  ];\n  \n//  Set(testpoly,poly); //@@@\n\n  Set(maxNrRoots,Length(testpoly)-1);\n  Set(result, {});\n\n  Set(lastcoef, LastCoef(testpoly,p));\n  Set(ord, OrdBuild(testpoly,q));\n\n  Set(accu,{});\n  Set(q,1);\n  Set(twoq,MathMultiply(q,2));\n  Set(mask,MathAdd(twoq,MathNegate(1)));\n  if (IsEven(testpoly[1]))\n  [\n    Set(accu,0:accu);\n    AddFoundSolutionSingle(0);\n  ];\n  Set(p,1);\n  Set(calc, Eval(lastcoef));\n  If (IsEven(calc),\n  [\n    Set(accu,1:accu);\n    AddFoundSolution(1);\n  ]);\n  Set(q,twoq);\n  Set(twoq,MathMultiply(q,2));\n  Set(mask,MathAdd(twoq,MathNegate(1)));\n  While(Length(result)<maxNrRoots And Length(accu)>0 And q<=Abs(testpoly[1]))\n  [\n    Local(newaccu);\n    Set(newaccu,{});\n    ForEach(p,accu)\n    [\n      Set(calc,Eval(lastcoef));\n      If (LessThan(calc,0), \n        Set(calc, MathAdd(calc,MathMultiply(twoq,MathDiv(MathAdd(MathNegate(calc),twoq),twoq))))\n         );\n      Set(calc, BitAnd(calc, mask));\n      If ( Equals(calc, 0),\n      [\n        Set(newaccu, p:newaccu);\n        AddFoundSolutionSingle(-2*q+p);\n      ]);\n      Set(calc, MathAdd(calc, Eval(ord)));\n      If (LessThan(calc,0), \n        Set(calc, MathAdd(calc,MathMultiply(twoq,MathDiv(MathAdd(MathNegate(calc),twoq),twoq))))\n         );\n      Set(calc, BitAnd(calc, mask));\n      If ( Equals(calc, 0),\n      [\n        Set(newaccu, MathAdd(p,q):newaccu);\n        AddFoundSolution(MathAdd(p,q));\n      ]);\n    ];\n    Set(accu, newaccu);\n    Set(q,twoq);\n    Set(twoq,MathMultiply(q,2));\n    Set(mask,MathAdd(twoq,MathNegate(1)));\n\n//Echo(\"q = \",q);\n//Echo(\"Length is\",Length(accu),\"accu = \",accu);\n//Echo(\"result = \",result);\n  ];\n\n  // If the polynom is not one, it is a polynomial which is not reducible any further\n  // with this algorithm, return as is.\n  Set(poly,poly*an^(0 .. (Length(poly)-1)));\n  Set(poly,gcd*anmul*poly);\n  //TODO had to add this if statement, what was andiv again, and why would it become zero? This happens with for example Factor(2*x^2)\n  If(Not IsZero(unrat * andiv ),Set(poly,poly/(unrat * andiv )));\n  If(poly != {1},\n  [\n    result:={(Add(poly*var^(0 .. (Length(poly)-1)))),1}:result;\n  ]);\n  result;\n];\n\n\n\nBinaryFactors(expr):=\n[\n  Local(result,uni,coefs);\n  uni:=MakeUni(expr,VarList(expr)[1]);\n  uni:=Listify(uni);\n  coefs:=uni[4];\n  coefs:=Concat(ZeroVector(uni[3]),coefs);\n  result:=Fct(coefs,uni[2]);\n//  Echo(result,list);\n//  Echo((Add(list*x^(0 .. (Length(list)-1)))));\n//  Factorize(x-result)*(Add(list*x^(0 .. (Length(list)-1))));\n  result;\n];\n\n\n\nMkfactD(numer,denom):=\n[\n  Local(q,r,i,j,ln,ld,nq);\n  DropEndZeroes(numer);\n  DropEndZeroes(denom);\n  Set(numer,Reverse(numer));\n  Set(denom,Reverse(denom));\n  Set(ln,Length(numer));\n  Set(ld,Length(denom));\n  Set(q,FillList(0,ln));\n  Set(r,FillList(0,ln));\n\n  Set(i,1);\n  If(ld>0,\n  [\n    While(Length(numer)>=Length(denom))\n    [\n      Set(nq,numer[1]/denom[1]);\n      q[ln-(Length(numer)-ld)] := nq;\n      For(j:=1,j<=Length(denom),j++)\n      [\n        numer[j] := (numer[j] - nq*denom[j]);\n      ];\n      r[i] := r[1] + numer[1];\n\n      Set(numer, Tail(numer));\n      i++;\n    ];\n  ]);\n  For(j:=0,j<Length(numer),j++)\n  [\n    r[i+j] := r[i+j] + numer[j+1];\n  ];\n  Set(q,Reverse(q));\n  Set(r,Reverse(r));\n  DropEndZeroes(q);\n  DropEndZeroes(r);\n  {q,r};\n];\n\n]; //LocalSymbols\n"
  },
  {
    "path": "scripts/factors.rep/binaryfactors.ys.def",
    "content": "BinaryFactors\n}\n"
  },
  {
    "path": "scripts/factors.rep/code.ys",
    "content": "\n/* This module implements factorizing integers and polynomials */\n\n/// Middle level function: returns a list of prime factors and their powers.\n/// E.g. FactorizeInt(50) returns {{2, 1}, {5, 2}}.\n1# FactorizeInt(0) <-- {{0, 1}};\n1# FactorizeInt(1) <-- {{1, 1}};\n\n2# FactorizeInt(n_IsNegativeInteger) <-- If(n = -1, {{-1, 1}}, Concat({{-1, 1}}, FactorizeInt(-n)));\n\n3# FactorizeInt(n_IsPositiveInteger) <--\n[\n  Local(small'powers);\n  n := Abs(n);  // just in case we are given a negative number\n  // first, find powers of 2, 3, ..., p with p=257 currently -- this speeds up PollardRho and should avoids its worst-case performance\n  // do a quick check first - this will save us time especially if we want to move 257 up a lot\n  If(\n    Gcd(ProductPrimesTo257(), n) > 1,   // if this is > 1, we need to separate some factors. Gcd() is very fast\n    small'powers := TrialFactorize(n, 257), // value is {n1, {p1,q1}, {p2,q2}, ...} and n1=1 if completely factorized into these factors, and the remainder otherwise\n    small'powers := {n} // pretend we had run TrialFactorize without success\n  );\n  n := small'powers[1]; // remainder\n  If(n=1, Tail(small'powers),\n  // if n!=1, need to factorize the remainder with Pollard Rho algorithm\n      [\n        If(InVerboseMode(), Echo({\"FactorizeInt: Info: remaining number \", n}));\n        SortFactorList(\n          PollardCombineLists(Tail(small'powers), PollardRhoFactorize(n))\n        );\n      ]\n  );\n];\n\n/// Sort the list of prime factors using HeapSort()\nLocalSymbols(a,b, list) [\n\nSortFactorList(list) := HeapSort(list, {{a,b}, a[1]<b[1]});\n\n];\n\n/// Simple trial factorization: can be very slow for integers > 1,000,000.\n/// Try all prime factors up to Sqrt(n).\n/// Resulting factors are automatically sorted.\n/// This function is not used any more.\n/*\n2# TrialFactorize(n_IsPrimePower) <-- {GetPrimePower(n)};\n3# TrialFactorize(n_IsInteger) <--\n[\n    Local(factorization);\n    factorization := TrialFactorize(n, n);  // TrialFactorize will limit to Sqrt(n) automatically\n    If(\n        Head(factorization) = 1,    // all factors were smaller than Sqrt(n)\n        Tail(factorization),\n        // the first element needs to be replaced\n        Concat(Tail(factorization), {{Head(factorization),1}})\n    );\n];\n*/\n\n/// Auxiliary function. Return the power of a given prime contained in a given integer and remaining integer.\n/// E.g. FindPrimeFactor(63, 3) returns {7, 2} and FindPrimeFactor(42,17) returns {42, 0}\n// use variable step loops, like in IntLog()\nFindPrimeFactor(n, prime) :=\n[\n    Local(power, factor, old'factor, step);\n    power := 1;\n    old'factor := 1;    // in case the power should be 0\n    factor := prime;\n    // first loop: increase step\n    While(Mod(n, factor)=0) // avoid division, just compute Mod()\n    [\n        old'factor := factor;   // save old value here, avoid sqrt\n        factor := factor^2;\n        power := power*2;\n    ];\n    power := Div(power,2);\n    factor := old'factor;\n    n := Div(n, factor);\n    // second loop: decrease step\n    step := Div(power,2);\n    While(step>0 And n > 1)\n    [\n        factor := prime^step;\n        If(\n            Mod(n, factor)=0,\n            [\n                n := Div(n, factor);\n                power := power + step;\n            ]\n        );\n        step := Div(step, 2);\n    ];\n    {n, power};\n];\n\n/* simpler method but slower on worstcase such as p^n or n! */\nFindPrimeFactorSimple(n, prime) :=\n[\n    Local(power, factor);\n    power := 0;\n    factor := prime;\n    While(Mod(n, factor)=0)\n    [\n        factor := factor*prime;\n        power++;\n    ];\n    {n/(factor/prime), power};\n];\n/**/\n\n/// Auxiliary function. Factorizes by trials. Return prime factors up to given limit and the remaining number.\n/// E.g. TrialFactorize(42, 2) returns {21, {{2, 1}}} and TrialFactorize(37, 4) returns {37}\nTrialFactorize(n, limit) :=\n[\n    Local(power, prime, result);\n    result := {n};  // first element of result will be replaced by the final value of n\n    prime := 2; // first prime\n    While(prime <= limit And n>1 And prime*prime <= n)\n    [   // find the max power of prime which divides n\n        {n, power} := FindPrimeFactor(n, prime);\n        If(\n            power>0,\n            DestructiveAppend(result, {prime,power})\n        );\n        prime := NextPseudoPrime(prime);    // faster than NextPrime and we don't need real primes here\n    ];\n    // replace the first element which was n by the new n\n    DestructiveReplace(result, 1, n);\n];\n\n/* This is Pollard's Rho method of factorizing, as described in\n * \"Modern Computer Algebra\". It is a rather fast algorithm for\n * factoring, but doesn't scale to polynomials regrettably.\n *\n * It acts 'by chance'. This is the Floyd cycle detection trick, where\n * you move x(i+1) = f(x(i)) and y(i+1) = f(f(y(i))), so the y goes twice\n * as fast as x, and for a certain i x(i) will be equal to y(i).\n *\n * \"Modern Computer Algebra\" reasons that if f(x) = (x^2+1) mod n for\n * the value n to be factored, then chances are good that gcd(x-y,n)\n * is a factor of n. The function x^2+1 is arbitrary, a higher order\n * polynomial could have been chosen also.\n *\n */\n\n/*\nWarning: The Pollard Rho algorithm cannot factor some numbers, e.g. 703, and\ncan enter an infinite loop. This currently results in an error message: \"failed to factorize\".\nHopefully the TrialFactorize() step will avoid these situations by excluding\nsmall prime factors.\nThis problem could also be circumvented by trying a different random initial value for x when a loop is encountered -- hopefully another initial value will not get into a loop. (currently this is not implemented)\n*/\n\nRandomInteger(n) := MathFloor(Random()*n);\n/// Polynomial for the Pollard Rho iteration\nPollardRhoPolynomial(_x) <-- x^2+1;\n\n2# PollardRhoFactorize(n_IsPrimePower) <-- {GetPrimePower(n)};\n3# PollardRhoFactorize(_n) <--\n[\n  Local(x,y,restarts,gcd,repeat);\n  gcd:=1;\n  restarts := 100;  // allow at most this many restartings of the algorithm\n  While(gcd = 1 And restarts>=0)    // outer loop: this will be typically executed only once but it is needed to restart the iteration if it \"stalls\"\n  [\n    restarts--;\n    /* Pick a random value between 1 and n-1 */\n    x:= RandomInteger(n-1)+1;\n\n    /* Initialize loop */\n    gcd:=1; y:=x;\n    repeat := 4;    // allow at most this many repetitions\n//      Echo({\"debug PollardRho: entering gcd loop, n=\", n});\n\n    /* loop until failure or success found */\n    While(gcd = 1 And repeat>=0)\n    [\n      x:= Mod( PollardRhoPolynomial(x), n);\n      y:= Mod( PollardRhoPolynomial(\n        Mod( PollardRhoPolynomial(y), n)    // this is faster for large numbers\n      ), n);\n      If(x-y = 0,\n         [\n            gcd := 1;\n            repeat--;   // guard against \"stalling\" in an infinite loop but allow a few repetitions\n         ],\n         gcd:=Gcd(x-y,n)\n         );\n//      Echo({\"debug PollardRho: gcd=\",gcd,\" x=\", x,\" y=\", y});\n    ];\n    If(InVerboseMode() And repeat<=0, Echo({\"PollardRhoFactorize: Warning: stalled while factorizing \", n, \"; counters \", x, y}));\n  ];\n  Check(restarts>0, \"PollardRhoFactorize: Error: failed to factorize \" : String(n));\n  If(InVerboseMode() And gcd > 1, Echo({\"PollardRhoFactorize: Info: while factorizing \", n, \" found factor \", gcd}));\n  /* Return result found */\n  PollardCombineLists(PollardRhoFactorize(gcd), PollardRhoFactorize(Div(n,gcd)));\n];\n\n/* PollardCombineLists combines two assoc lists used for factoring.\n   the first element in each item list is the factor, and the second\n   the exponent. Thus, an assoc list of {{2,3},{3,5}} means 2^3*3^5.\n*/\n\n5 # PollardMerge(_list,{1,_n}) <-- True;\n10 # PollardMerge(_list,_item)_(Assoc(item[1],list) = Empty) <--\n  DestructiveInsert(list,1,item);\n\n20 # PollardMerge(_list,_item) <--\n[\n  Local(assoc);\n  assoc := Assoc(item[1],list);\n  assoc[2]:=assoc[2]+item[2];\n];\n\nPollardCombineLists(_left,_right) <--\n[\n  ForEach(item,right)\n  [\n    PollardMerge(left,item);\n  ];\n  left;\n];\n\n\n\n\n/* New factorization : split between integers and polynomials. */\n10 # Factors(p_IsInteger) <-- FactorizeInt(p);\n20 # Factors(p_CanBeUni)_(Length(VarList(p)) = 1) <--  BinaryFactors(p);\n30 # Factors(p_IsGaussianInteger)   <-- GaussianFactors(p);\n\n\n// This is so Factor(Sin(x)) doesn't return FWatom(Sin(x))\n//Factor(_p) <-- FW(Factors(p));\n10 # Factor(p_CanBeUni) <-- FW(Factors(p));\n\n\n/* FW: pass FW the result of Factors, and it will show it in the\n * form of p0^n0*p1^n1*...\n */\n\n10 # FWatom({_a,1}) <-- a;\n20 # FWatom({_a,_n}) <-- UnList({Atom(\"^\"),a, n});\n5  # FW(_list)_(Length(list) = 0) <-- 1;\n10 # FW(_list)_(Length(list) = 1) <-- FWatom(list[1]);\n20 # FW(_list) <--\n[\n  Local(result);\n  result:=FWatom(Head(list));\n  ForEach(item,Tail(list))\n  [\n   result := UnList({ Atom(\"*\"),result,FWatom(item)});\n  ];\n  result;\n];\n\n10 # Roots(poly_CanBeUni) <--\n[\n  Local(factors,result,uni,root,i,deg);\n  factors:=Factors(poly);\n  result:={};\n  ForEach(item,factors)\n  [\n    uni:=MakeUni(item[1]);\n    deg:=Degree(uni);\n    If(deg > 0 And deg < 3,\n      [\n        root:= PSolve(uni);\n        If(Not IsList(root),root:={root});\n        For(i:=0,i<item[2],i++)\n          result:= Concat(root, result);\n      ]\n      );\n  ];\n  result;\n];\n\n10 # RootsWithMultiples(poly_CanBeUni) <--\n[\n  Local(factors,result,uni,root,i,deg);\n  factors:=Factors(poly);\n  result:={};\n  ForEach(item,factors)\n  [\n    uni:=MakeUni(item[1]);\n\n    deg:=Degree(uni);\n    If(deg > 0 And deg < 3,\n      [\n        root:= PSolve(uni);\n        If(Not IsList(root),root:={root});\n        For(i:=1,i<=Length(root),i++)\n          result:= Concat({{root[i],item[2]}}, result);\n      ]\n      );\n  ];\n  result;\n];\n\n// The bud of an Quadratic Seive algorithm\n// congruence solving code must be written first\nFunction(\"FactorQS\",{n})[\n    Local(x,k,fb,j);\n    // optimal number of primes in factor base\n    // according to Fundamental Number Theory with Applications - Mollin, p130\n    k:=Round(N(Sqrt(Exp(Sqrt(Ln(n)*Ln(Ln(n)))))));\n    fb:=ZeroVector(k);\n    For(j:=1,j<=k,j++)[\n        fb[j]:=NextPrime(j);\n    ];\n];\n\n// Preliminary implementation of simple square-free factorization\n// (Musser's algorithm)\n10 # SquareFreeFactorize(f_CanBeUni, x_IsAtom)_(VarList(f) = {x} Or VarList(f) = {}) <--\n[\n    Local(f', g, h, m, i);\n\n    f' := Deriv(x)f;\n\n    g := PolynomialGcd(f, f', x);\n    h := Div(f, g);\n\n    m := {};\n    i := 1;\n\n    While (h != 1) [\n\n        Local(gg, hh, mi);\n\n        hh := PolynomialGcd(g, h, x);\n        gg := Div(g, hh);\n\n        mi := Div(h, hh);\n        If (mi != 1, DestructiveAppend(m, {mi, i}));\n        i := i + 1;\n\n        g := gg;\n        h := hh;\n    ];\n\n    m;\n];\n"
  },
  {
    "path": "scripts/factors.rep/code.ys.def",
    "content": "FindPrimeFactor\nFindPrimeFactorSimple\nFactors\nFactor\nTrialFactorize\nFW\nRoots\nRootsWithMultiples\nFactorQS\nSquareFreeFactorize\n}\n"
  },
  {
    "path": "scripts/functional.rep/code.ys",
    "content": "\n/* Operators for functional programming.\n * Examples:\n *  a:b:c:{}       ->  {a,b,c}\n *  \"Sin\" @ a      ->   Sin(a)\n *  \"Sin\" @ {a,b}  ->   Sin(a,b)\n *  \"Sin\" /@ {a,b} ->   {Sin(a),Sin(b)}\n *  1 .. 4         ->   {1,2,3,4}\n */\n\n\n/* a : b will now return unevaluated (rather than cause error of invalid argument in Concat) if neither a nor b is a list and if one of them is not a string\n*/\nRuleBase(\":\",{head,tail});\nRule(\":\",2,20,IsList(head) And Not IsList(tail) ) Concat(head,{tail});\nRule(\":\",2,30,IsList(tail) ) Concat({head},tail);\nRule(\":\",2,10,IsString(tail) And IsString(head)) ConcatStrings(head,tail);\nUnFence(\":\",2);\n\n\nRuleBase(\"@\",{func,arg});\nRule(\"@\",2,1,IsList(arg)) Apply(func,arg);\nRule(\"@\",2,2,True       ) Apply(func,{arg});\n\nFunction(\"/@\",{func,lst}) Apply(\"MapSingle\",{func,lst});\n\n10 # (count'from_IsInteger .. count'to_IsInteger)_(count'from <= count'to) \n   <-- Table(i,i,count'from,count'to,1);\n20 # (count'from_IsInteger .. count'to_IsInteger) \n   <-- Table(i,i,count'from,count'to,-1);\n\n/* NFunction(\"new'func\", \"old'func\" {arg'list}) will define a wrapper function\naround  \"old'func\", called \"new'func\", which will return \"old'func(arg'list)\"\nonly when all arguments are numbers and will return unevaluated\n\"new'func(arg'list)\" otherwise. */\nLocalSymbols(NFunction'Numberize)\n[\nNFunction(new'name_IsString, old'name_IsString, arg'list_IsList) <-- [\n\tMacroRuleBase(new'name, arg'list);\n\tMacroRule(new'name, Length(arg'list), 0,\t// check whether all args are numeric\n\t\tUnList({IsNumericList, arg'list})\n\t)\n\n\t\t/* this is the rule defined for the new function.\n\t\t// this expression should evaluate to the body of the rule.\n\t\t// the body looks like this:\n\t\t// NFunction'Numberize(old'name(arg'list))\n\t\t*/ \n\t\t\tNFunction'Numberize(UnList({Atom(\"@\"), old'name, arg'list}));\n\t\t\t// cannot use bare '@' b/c get a syntax error\n\n];\n\n// this function is local to NFunction.\n// special handling for numerical errors: return Undefined unless given a number.\n10 # NFunction'Numberize(x_IsNumber) <-- x;\n20 # NFunction'Numberize(x_IsAtom) <-- Undefined;\n// do nothing unless given an atom\n\n];\t// LocalSymbols()\n\n"
  },
  {
    "path": "scripts/functional.rep/code.ys.def",
    "content": ":\n@\n/@\n..\nNFunction\n}\n"
  },
  {
    "path": "scripts/functional.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef( \":\"        , \"yacas\",\"prepend\"    );\nOMDef( \"@\"        , \"yacas\",\"apply\"      );\nOMDef( \"/@\"       , \"yacas\",\"list_apply\" );\nOMDef( \"..\"       , \"interval1\",\"integer_interval\" );\nOMDef( \"NFunction\", \"yacas\",\"NFunction\" );\n"
  },
  {
    "path": "scripts/graph.rep/code.ys",
    "content": "Graph(edges_IsList) <-- [\n    Local(v, e, f, t);\n\n    vertices := {};\n\n    ForEach (e, edges) [\n        If (IsList(e), e := Head(e));\n        {f, t} := Tail(Listify(e));\n\n        DestructiveAppend(vertices, f);\n        DestructiveAppend(vertices, t);\n    ];\n\n    Graph(RemoveDuplicates(vertices), edges);\n];\n\n10 # IsGraph(Graph(vertices_IsList, edges_IsList)) <-- True;\n20 # IsGraph(_x) <-- False;\n\nEdges(Graph(vertices_IsList, edges_IsList)) <-- edges;\nVertices(Graph(vertices_IsList, edges_IsList)) <-- vertices;\n\nAdjacencyList(g_IsGraph) <-- [\n    Local(l, vertices, edges, e, op, f, t);\n\n    l := Association'Create();\n\n    vertices := Vertices(g);\n    ForEach (v, vertices)\n        Association'Set(l, v, {});\n\n    edges := Edges(g);\n\n    ForEach(e, edges) [\n        If (IsList(e), e := Head(e));\n        {op, f, t} := Listify(e);\n        DestructiveAppend(Association'Get(l, f), t);\n        If (String(op) = \"<->\", DestructiveAppend(Association'Get(l, t), f));\n    ];\n\n    l;\n];\n\nAdjacencyMatrix(g_IsGraph) <-- [\n    Local(vertices, adjacent, n, I, A, v, a, i, j);\n\n    vertices := Vertices(g);\n\n    n := Length(vertices);\n\n    I := Association'Create();\n    For (i := 1, i <= n, i++)\n        Association'Set(I, vertices[i], i);\n\n    L := AdjacencyList(g);\n    A := ZeroMatrix(n, n);\n\n    ForEach (v, vertices) [\n        i := Association'Get(I, v);\n        adjacent := Association'Get(L, v);\n        ForEach (a, adjacent) [\n            j := Association'Get(I, a);\n            A[i][j] := 1;\n        ];\n    ];\n\n    A;\n];\n\nLocalSymbols(graph, start, func) [\n    RuleBase(\"DFS\", {graph, start, func});\n    RuleBase(\"DFS\", {graph, func});\n\n    DFS(g_IsGraph, _start, _func) <-- [\n        Local(vertices, A, S, v, r);\n\n        A := AdjacencyList(g);\n\n        Check(Association'Get(A, start) != Undefined, \"DFS: start vertex does not exist\");\n\n        r := {};\n\n        S := {start};\n\n        While (S != {}) [\n            v := Head(S);\n            DestructiveDelete(S, 1);\n\n            If (Association'Get(A, v) != Undefined, [\n                DestructiveAppend(r, Apply(func, {v}));\n                vertices := Association'Get(A, v);\n                Association'Drop(A, v); \n                ForEach (v, vertices)\n                    DestructiveInsert(S, 1, v);\n            ]);\n        ];\n\n        r;\n    ];\n\n    DFS(g_IsGraph, _func)_(Vertices(g) != {}) <-- [\n        Local(all, vertices, A, S, v, r);\n\n        A := AdjacencyList(g);\n\n        r := {};\n\n        all := Vertices(g);\n\n        While (Length(all) != 0) [\n            S := {Head(all)};\n\n            While (S != {}) [\n                v := Head(S);\n                DestructiveDelete(S, 1);\n\n                If (Association'Get(A, v) != Undefined, [\n                    DestructiveDelete(all, Find(all, v));\n                    DestructiveAppend(r, Apply(func, {v}));\n                    vertices := Association'Get(A, v);\n                    Association'Drop(A, v);\n                    ForEach (v, vertices)\n                        DestructiveInsert(S, 1, v);\n                ]);\n            ];\n        ];\n\n        r;\n    ];\n\n    HoldArg(\"DFS\", func);\n];\n\n100 # IsDAG(g_IsGraph)_(Edges(g) = {}) <-- True;\n\n200 # IsDAG(g_IsGraph)_(Find(String /@ (Head /@ (Listify /@ Edges(g))), \"<->\") != -1) <-- False;\n\n300 # IsDAG(g_IsGraph) <-- [\n    Local(V, E, I, R, e, v, op, t, f);\n\n    V := Vertices(g);\n    E := Edges(g);\n\n    I := Association'Create();\n    ForEach (v, V)\n        Association'Set(I, v, 0);\n\n    ForEach (e, E) [\n        If (IsList(e), e := Head(e));\n        {op, f, t} := Listify(e);\n        Association'Set(I, t, Association'Get(I, t) + 1);\n    ];\n    \n    R := {};\n    ForEach (e, E) [\n        If (IsList(e), e := Head(e));\n        {op, f, t} := Listify(e);\n\n        If (Association'Get(I, f) != 0, DestructiveAppend(R, e));\n    ];\n\n    IsDAG(Graph(R));\n];\n\nLocalSymbols(graph, start, func) [\n    RuleBase(\"BFS\", {graph, start, func});\n    RuleBase(\"BFS\", {graph, func});\n\n    BFS(g_IsGraph, _start, _func) <-- [\n        Local(vertices, A, Q, v, r);\n\n        A := AdjacencyList(g);\n\n        Check(Association'Get(A, start) != Undefined, \"BFS: start vertex does not exist\");\n\n        r := {};\n\n        Q := {start};\n\n        While (Length(Q) != 0) [\n            v := Head(Q);\n            DestructiveDelete(Q, 1);\n\n            If (Association'Get(A, v) != Undefined, [\n                DestructiveAppend(r, Apply(func, {v}));\n                vertices := Association'Get(A, v);\n                Association'Drop(A, v); \n                ForEach (v, vertices)\n                    DestructiveAppend(Q, v);\n            ]);\n        ];\n\n        r;\n    ];\n\n    BFS(g_IsGraph, _func)_(Vertices(g) != {}) <-- [\n        Local(all, vertices, A, Q, v, r);\n\n        A := AdjacencyList(g);\n\n        r := {};\n\n        all := Vertices(g);\n\n        While (Length(all) != 0) [\n            Q := {Head(all)};\n\n            While (Length(Q) != 0) [\n                v := Head(Q);\n                DestructiveDelete(Q, 1);\n\n                If (Association'Get(A, v) != Undefined, [\n                    DestructiveDelete(all, Find(all, v));\n                    DestructiveAppend(r, Apply(func, {v}));\n                    vertices := Association'Get(A, v);\n                    Association'Drop(A, v);\n                    ForEach (v, vertices)\n                        DestructiveAppend(Q, v);\n                ]);\n            ];\n        ];\n\n        r;\n    ];\n\n    HoldArg(\"BFS\", func);\n];\n\nTopologicalSort(g_IsGraph) <-- [\n    Local(V, E, A, I, S, L, e, v, av, op, t, f);\n\n    V := Vertices(g);\n    E := Edges(g);\n\n    I := Association'Create();\n    ForEach (v, V)\n        Association'Set(I, v, 0);\n\n    ForEach (e, E) [\n        If (IsList(e), e := Head(e));\n        {op, f, t} := Listify(e);\n        Association'Set(I, t, Association'Get(I, t) + 1);\n        If (String(op) = \"<->\", Association'Set(I, f, Association'Get(I, f) + 1));\n    ];\n\n    S := {};\n    ForEach (v, V)\n        If (Association'Get(I, v) = 0, DestructiveAppend(S, v));\n\n    A := AdjacencyList(g);\n\n    L := {};\n    While (Length(S) != 0) [\n        v := Head(S);\n        S := Tail(S);\n        DestructiveAppend(L, v);\n        ForEach (av, Association'Get(A, v)) [\n            Association'Set(I, av, Association'Get(I, av) - 1);\n            If (Association'Get(I, av) = 0, DestructiveAppend(S, av));\n        ];\n    ];\n\n    Check(Length(L) = Length(V), \"TopologicalSort: cycle detected\");\n\n    L;\n];\n\nTopologicalSort(A_IsSquareMatrix) <--\n[\n    Local(mark, n, L, visit);\n\n    mark := ZeroVector(Length(A));\n    L := {};\n\n    dfs(A, n, mark, L) := [\n        Check(mark[n] != 1, \"TopologicalSort: cycle detected\");\n        If (mark[n] = 0, [\n            Local(m, row);\n            DestructiveReplace(mark, n, 1);\n            row := A[n];\n            For (m := 1, m <= Length(row), m++)\n                If (row[m] != 0, dfs(A, m, mark, L));\n            DestructiveReplace(mark, n, 2);\n            DestructiveInsert(L, 1, n);\n        ]);\n    ];    \n\n    n := Find(mark, 0);\n\n    While (n > 0) [\n        dfs(A, n, mark, L);\n        n := Find(mark, 0);\n    ];\n\n    L;\n];\n"
  },
  {
    "path": "scripts/graph.rep/code.ys.def",
    "content": "Graph\nIsGraph\nVertices\nEdges\nAdjacencyMatrix\nAdjacencyList\nDFS\nBFS\nIsDAG\nTopologicalSort\n}\n"
  },
  {
    "path": "scripts/html.rep/code.ys",
    "content": "\n/* code to generate html */\n\n\n/* Global defines */\nanchor:={};\nanchor[\"0\"]:=\"a\";\nanchor[\"name\"]:=\"\";\n\nlink:={};\nlink[\"0\"]:=\"a\";\nlink[\"href\"]:=\"\";\n\nframeset:={};\nframeset[\"0\"]:=\"frameset\";\nframeset[\"border\"]:=\"0\";\n\nframe:={};\nframe[\"0\"]:=\"frame\";\n\ncaption:={};\ncaption[\"0\"]:=\"caption\";\n\ntable:={};\ntable[\"0\"]:=\"table\";\n\nform:={};\nform[\"0\"]:=\"form\";\n\ntextarea:={};\ntextarea[\"0\"]:=\"textarea\";\n\ntextfield:={};\ntextfield[\"0\"]:=\"input\";\ntextfield[\"TYPE\"]:=\"text\";\n\nbutton:={};\nbutton[\"0\"]:=\"input\";\nbutton[\"TYPE\"]:=\"submit\";\n\nbullets:={};\nbullets[\"0\"]:=\"ul\";\n\nbullet:={};\nbullet[\"0\"]:=\"li\";\n\nnewline:=\"\n\";\nGt():=\"&gt;\";\nLt():=\"&lt;\";\n\n\n\n\nHtmlNewParagraph():= (newline : \"<p>\" : newline);\n\nHtmlTitle(title):=\n[\n\"<head>\n  <title>\" : title : \"</title>\n  <link rel=\\\"stylesheet\\\" href=\\\"yacas.css\\\" TYPE=\\\"text/css\\\" MEDIA=\\\"screen\\\">\n  <script type=\\\"text/x-mathjax-config\\\">\n    MathJax.Hub.Config({\n      tex2jax: {inlineMath: [['$','$'], ['\\\\\\\\(','\\\\\\\\)']]}\n    });\n  </script>\n  <script type=\\\"text/javascript\\\"\n    src=\\\"https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\\\">\n  </script>\n</head>\";\n];\n\nHtmlAnchor(name):=\n[\n  anchor[\"name\"]:=name;\n  HtmlTag(anchor,\"\");\n];\nBodied(\"HtmlAnchor\",60000);\n\nHtmlTable(cellpadding,width,body):=\n[\n  table[\"cellpadding\"]:=String(cellpadding);\n  table[\"width\"]:=width;\n  HtmlTag(table,body);\n];\n\nBullets(list):=HtmlTag(bullets,list);\nBullet (list):=HtmlTag(bullet ,list);\n\n\nHtmlCaption(title):=\n[\n HtmlTag(caption,title);\n];\n\nHtmlForm(action,body):=\n[\n  form[\"method\"]:=\"get\";\n  form[\"action\"]:=action;\n  HtmlTag(form,body);\n];\n\n\nHtmlTextArea(name,width,height,body) :=\n[\n  textarea[\"name\"]:=name;\n  textarea[\"cols\"]:=String(width);\n  textarea[\"rows\"]:=String(height);\n  HtmlTag(textarea,body);\n];\n\nHtmlTextField(name,size,value):=\n[\n  textfield[\"name\"]:=name;\n  textfield[\"size\"]:=String(size);\n  textfield[\"value\"]:=value;\n  HtmlTag(textfield,\"\");\n];\n\nHtmlSubmitButton(name,value):=\n[\n  button[\"name\"]:=name;\n  button[\"value\"]:=value;\n  HtmlTag(button,\"\");\n];\n\n\nHtmlLink(description,file,tag,target):=\n[\n  If(tag != \"\",\n    link[\"href\"]:= file : \"#\" : tag,\n    link[\"href\"]:= file);\n    \n  If(target != \"\",link[\"target\"] :=target);\n  HtmlTag(link,description);\n];\n\nHtmlFrameSetRows(columns,body):=\n[\n  frameset[\"cols\"]:=\"\";\n  frameset[\"rows\"]:=columns;\n  HtmlTag(frameset,body);\n];\n\nHtmlFrameSetCols(columns,body):=\n[\n  frameset[\"cols\"]:=columns;\n  frameset[\"rows\"]:=\"\";\n  HtmlTag(frameset,body);\n];\n\nHtmlFrame(source,name):=\n[\n  frame[\"src\"]:=source;\n  frame[\"name\"]:=name;\n  HtmlTag(frame,\"\");\n];\n\n\n/* export a html tag type, using the specifications in the\n   tags assoc list.\n   */\nHtmlTag(tags,content):=\n[\n  Local(result,tag,analytics);\n  result:=\"<\" : tags[\"0\"];\n  ForEach(tag,AssocIndices(tags))\n  [\n    If (tag != \"0\" And tags[tag] != \"\",\n       result:= result : \" \" : tag : \"=\" : \"\\\"\" : tags[tag] : \"\\\"\"\n       ); \n  ];\n\n  analytics:=\"\";\n  If(tags[\"0\"] = \"body\",\n    analytics:=\"<script src=\\\"http://www.google-analytics.com/urchin.js\\\" type=\\\"text/javascript\\\">\n</script>\n<script type=\\\"text/javascript\\\">\n_uacct = \\\"UA-2425144-1\\\";\nurchinTracker();\n</script>\n\");\n\n  \n  result:= result : \">\" : newline :\n           content : newline :\n           analytics : \"</\" : tags[\"0\"] : \">\" : newline;\n  \n  result;\n];\n\n/* output directory management */\nhtmldir:=\"\";\nSetHtmlDirectory(dir):= [htmldir:=dir;];\nHtmlFile(file) := [htmldir : file;];\n\n\n/* loading and saving site info */\nsite:={};\nClearSite() := [site:={};];\nLoadSite():=\n[\n  FromFile(\"siteall\")\n  [\n    site:=Read();\n  ];\n];\n\nSaveSite():=\n[\n  ToFile(\"siteall\")\n  [\n    Write(site);\n    WriteString(\";\");\n  ];\n];\n\nMySQLQuery(pidstr,string):=\n[\n  Local(result);\n  ToFile(\"sqlin\":pidstr) WriteString(string);\n  SystemCall(\"mysql mysql < \":\"sqlin\":pidstr:\" > sqlout\":pidstr);\n  SystemCall(FindFile(\"tools/mysqlstubs\"):\" sqlout\":pidstr:\" sqlout_\":pidstr);\n  result:= FromFile(\"sqlout_\":pidstr)Read();\n  SystemCall(\"rm -rf sqlin\":pidstr);\n  SystemCall(\"rm -rf sqlout\":pidstr);\n  SystemCall(\"rm -rf sqlout_\":pidstr);\n  result;\n];\n\n"
  },
  {
    "path": "scripts/html.rep/code.ys.def",
    "content": "HtmlNewParagraph\nHtmlAnchor\nHtmlLink\nHtmlTable\nHtmlCaption\nHtmlTitle\nHtmlFrameSetRows\nHtmlFrameSetCols\nHtmlFrame\nHtmlTag\nHtmlForm\nBullets\nBullet\nHtmlTextArea\nHtmlTextField\nHtmlSubmitButton\nSetHtmlDirectory\nHtmlFile\nClearSite\nLoadSite\nSaveSite\nMySQLQuery\n}\n"
  },
  {
    "path": "scripts/integrate.rep/code.ys",
    "content": "\nRuleBase(\"IntegrateMultiplicative\",{var,from,a,b});\nUnFence(\"IntegrateMultiplicative\",4);\n\n10# (Integrate(_var)(expr_IsList))\n    <-- Map(\"Integrate\",{FillList(var,Length(expr)),expr});\n20 # (Integrate(_var)(_expr)) <-- IntSub(var,expr,AntiDeriv(var,IntClean(var,expr)));\n\n\n10 # IntSub(_var,_expr,Integrate(_var)(_expr2)) <--\n     `Hold(Integrate(@var)(@expr));\n20 # IntSub(_var,_expr,_result) <-- result;\t// + UniqueConstant();\n\n////////////////////////////////////////////////\n//\n// Integrate over a range\n//\n////////////////////////////////////////////////\n10# (Integrate(_var,_from,_to)(expr_IsList))\n    <-- Map(\"Integrate\",{FillList(var,Length(expr)),\n                         FillList(from,Length(expr)),\n\t\t\t FillList(to,Length(expr)),\n                         expr});\n\n20 # (Integrate(_var,_from,_to)(_expr))\n    <-- indefIntegrate(var,from,to,expr,a,b);\n\n////////////////////////////////////////////////\n//\n// separate rules can be added here for specific integrals\n// to indefIntegrate\n//\n////////////////////////////////////////////////\n\n10 # indefIntegrate(_var,_from,_to,_expr,_a,_b)_(from = -to And IsOddFunction(expr,var)) <-- 0;\n\n// We need to define this case (integrating from 0 to 0 over an even function) explicitly, otherwise\n// the integration ends up going in to infinite recursion. Extended it a little bit more, since if\n// you are integrating from A to A, then the result is obviously zero. There are perhaps situations\n// where this does not work, where we need to simplify (to-from) first. A naive implementation caused\n// a test to fail.\n10 # indefIntegrate(_var,_from,_from,_expr,_a,_b) <-- 0;\n\n12 # indefIntegrate(_var,_from,_to,_expr,_a,_b)_(from = -to And IsEvenFunction(expr,var)) <--\n     2*indefIntegrate(var,0,to,expr,a,b);\n\n100 # indefIntegrate(_var,_from,_to,_expr,_a,_b)_(Type(AntiDeriv(var,IntClean(var,expr))) != \"AntiDeriv\")\n    <--\n    IntegrateRange(var,expr,from,to,AntiDeriv(var,IntClean(var,expr)));\n101 # indefIntegrate(_var,_from,_to,_expr,_a,_b)\n    <-- `Hold(Integrate(@var,@from,@to)(@expr));\n//    <-- IntegrateRange(var,expr,from,to,AntiDeriv(var,expr));\n\n\n\n////////////////////////////////////////////////\n//\n// No anti-derivative found, return unavaluated.\n//\n////////////////////////////////////////////////\n10 # IntegrateRange(_var,_expr,_from,_to,Integrate(_var)_expr2)\n    <-- `Hold(Integrate(@var,@from,@to)@expr);\n\n////////////////////////////////////////////////\n//\n// Anti-derivative found, return result.\n//\n////////////////////////////////////////////////\n20 # IntegrateRange(_var,_expr,_from,_to,_antideriv)\n    <-- `(@antideriv Where @var == @to) - `(@antideriv Where @var == @from);\n\n////////////////////////////////////////////////\n//\n// IntClean cleans up an expression before passing\n// it on to integration. This function normalizes\n// an expression in a way desirable for integration.\n// TrigSimpCombine, for instance, expands expressions\n// containing trigonometric functions so that they are\n// additive as opposed to multiplicative.\n//\n// If the expression doesn't contain the variable,\n// just return it as-is. This fixes:\n// In> Integrate(x) z^100\n////////////////////////////////////////////////\n10 # IntClean(_var,_expr) <--\n[\n\tif( IsFreeOf(var,expr))[\n\t\texpr;\n\t] else if ( HasFunc(expr,Sin) Or HasFunc(expr,Cos) )[\n\t\tSimplify(TrigSimpCombine(expr));\n\t] else [\n\t\tSimplify(expr);\n\t];\n];\n\n////////////////////////////////////////////////\n//\n// Anti-derivative of a univariate polynomial\n//\n////////////////////////////////////////////////\n5  # AntiDeriv(_var, poly_CanBeUni(var) )\n     <-- NormalForm(AntiDeriv(var,`MakeUni(@poly,@var)));\n5 # AntiDeriv(_var,UniVariate(_var,_first,_coefs)) <--\n[\n  Local(result,i);\n  result:=FlatCopy(coefs);\n  For(i:=1,i<=Length(result),i++)\n  [\n    result[i]:= result[i]/(first+i);\n  ];\n  UniVariate(var,first+1,result);\n];\n\n\n\n////////////////////////////////////////////////\n//\n// Standard additive properties of integration.\n//\n////////////////////////////////////////////////\n10 # AntiDeriv(_var,_x + _y) <-- AntiDeriv(var,x) + AntiDeriv(var,y);\n10 # AntiDeriv(_var,_x - _y) <-- AntiDeriv(var,x) - AntiDeriv(var,y);\n10 # AntiDeriv(_var,   - _y) <--            - AntiDeriv(var,y);\n\n10 # AntiDeriv(_var,_x/c_IsFreeOf(var) )_(HasExpr(x,var)) <-- AntiDeriv(var,x)/c;\n10 # AntiDeriv(_var,c_IsFreeOf(var)/_x )_(HasExpr(x,var) And c!= 1)\n\t<-- c*AntiDeriv(var,1/x);\n\n\n////////////////////////////////////////////////\n//\n// Multiplying a polynomial with another (integrable)\n// function, Integrate by parts.\n//\n////////////////////////////////////////////////\n1570 # IntegrateMultiplicative(_var,(exy_CanBeUni(var)) * _exx,_dummy1,_dummy2)\n     <-- IntByParts(var,exy*exx,AntiDeriv(var,exx));\n1570 # IntegrateMultiplicative(_var,_exx * (exy_CanBeUni(var)),_dummy1,_dummy2)\n     <-- IntByParts(var,exy*exx,AntiDeriv(var,exx));\n10 # IntByParts(_var,_exy * _exx,Integrate(_var)(_something)) <--\n     `Hold(AntiDeriv(@var,((@exy)*(@exx))));\n20 # IntByParts(_var,_exy * _exx,_anti)_(Not IsFreeOf(anti,exx)) <--\n     `Hold(AntiDeriv(@var,((@exy)*(@exx))));\n30 # IntByParts(_var,_exy * _exx,_anti) <--\n     [\n       Local(cf);\n       cf:=anti*Deriv(var)exy;\n//  Echo({exy*anti,exy*exx,cf});\n       exy*anti - `(AntiDeriv(@var,@cf));\n     ];\n\n////////////////////////////////////////////////\n//\n// Rational functions: f(x)/g(x) where f and g are\n// polynomials.\n//\n////////////////////////////////////////////////\n1570 # IntegrateMultiplicative(_var,(exy_CanBeUni(var)) / (exx_CanBeUni(var)),_dummy1,_dummy2) <--\n     IntRat(var,exy/exx,MakeUni(exy,var),MakeUni(exx,var));\n\n10 # IntRat(_var,_exy / _exx,_exyu,_exxu)_\n     (Degree(exyu) > Degree(exxu) Or Degree(Gcd(exyu,exxu)) > 0) <--\n     [\n     Local(gcd);\n     gcd:=Gcd(exxu,exyu);\n     exyu:=Div(exyu,gcd);\n     exxu:=Div(exxu,gcd);\n     AntiDeriv(var,NormalForm(Div(exyu,exxu))) +\n       AntiDeriv(var,NormalForm(Mod(exyu,exxu))/NormalForm(exxu));\n     ];\n\n11 # IntRat(_var,_exy / _exx,_exyu,_exxu)_\n        (Degree(exxu,var) > 1 And LeadingCoef(exxu)=1 And\n\t IsNumericList(Coef(exxu,var,0 .. Degree(exxu)))) <--\n[\n  Local(ee);\n  ee:=Apart(exy/exx,var);\n  `AntiDeriv(@var,@ee);\n];\n\n15 # IntRat(_var,_exy / _exx,_exyu,_exxu)_\n        (Degree(exyu, var) = 0 And Degree(exxu, var) = 2 And\n         IsNumericList(Coef(exxu,var,0 .. Degree(exxu))) And\n         IsNumericList(Coef(exyu,var,0 .. Degree(exyu)))) <-- [\n    Local(a,b,c,d,e,delta);\n    {d} := Coef(exyu, var, 0 .. 0);\n    {c, b, a} := Coef(exxu, var, 0 .. 2);\n\n    delta := b^2-4*a*c;\n\n    2 * d / Sqrt(-delta) * ArcTan((2*a*var+b) / Sqrt(-delta));\n];\n\n15 # IntRat(_var,_exy / _exx,_exyu,_exxu)_\n        (Degree(exyu, var) = 1 And Degree(exxu, var) = 2 And\n         IsNumericList(Coef(exxu,var,0 .. Degree(exxu))) And\n         IsNumericList(Coef(exyu,var,0 .. Degree(exyu)))) <-- [\n    Local(a,b,c,d,e,r);\n    {e, d} := Coef(exyu, var, 0 .. 1);\n    {c, b, a} := Coef(exxu, var, 0 .. 2);\n\n    r := (e - b * d / (2 * a)) / exx;\n\n    d / (2 * a) * Ln(exx) + `AntiDeriv(@var, @r);\n];\n\n20 # IntRat(_var,_exy / _exx,_exyu,_exxu) <--\n     `Hold(AntiDeriv(@var,((@exy)/(@exx))));\n\n\n30 # AntiDeriv(_var,Deriv(_var)(_expr)) <-- expr;\n\n////////////////////////////////////////////////\n//\n// No simple form, try something else\n//\n////////////////////////////////////////////////\n100 # AntiDeriv(_var,_exp) <--\n[\n  IntegrateMultiplicative(var,exp,a,b);\n];\n\n\n////////////////////////////////////////////////\n//\n// Special anti-derivatives can be added here.\n//\n////////////////////////////////////////////////\n\n// integrating expressions containing if:\n10 # IntegrateMultiplicative(_var,if(_cond)(_body),_a,_b)\n     <--\n     [\n       body := AntiDeriv(var,body);\n       `Hold(if(@cond)(@body));\n     ];\n// integrating expressions containing else\n10 # IntegrateMultiplicative(_var,(_left) else (_right),_a,_b)\n     <--\n     [\n       left  := AntiDeriv(var,left);\n       right := AntiDeriv(var,right);\n       `Hold( (@left) else (@right) );\n     ];\n\n\n////////////////////////////////////////////////\n//\n// Could not find anti-derivative, return unsimplified\n//\n////////////////////////////////////////////////\n1600 # IntegrateMultiplicative(_var,_exp,_a,_b) <-- `Hold(Integrate(@var)(@exp));\n\n////////////////////////////////////////////////\n//\n// IntFunc declares the anti-derivative of a function\n// that has one argument.\n// Calling sequence: IntFunc(variable,from,to);\n// Example: IntFunc(x,Cos(_x),Sin(x));\n//\n////////////////////////////////////////////////\nLocalSymbols(intpred)\n[\n  intpred := 50;\n  IntFunc(_vr,_from,_to) <--\n  [\n    `((@intpred) # IntegrateMultiplicative(_var,@from,_dummy1,_dummy2)_MatchLinear(var,@vr) <-- (@to)/Matched'a());\n    intpred++;\n  ];\n];\n\n\nIntPureSquare(_vr,_from,_sign2,_sign0,_to) <--\n[\n  `(50 # IntegrateMultiplicative(_var,@from,_dummy1,_dummy2)_MatchPureSquared(var,@sign2,@sign0,@vr) <-- (@to));\n];\n\n\n\n\n////////////////////////////////////////////////\n//\n// Declaration of the anti-derivatives of a few analytic functions\n//\n////////////////////////////////////////////////\n\n\nIntFunc(x,Sqrt(_x),(2*Sqrt(x)^(3))/3);\nIntFunc(x,1/Sqrt(_x),2*Sqrt(x));\nIntFunc(x,1/_x^(_n),x^(1-n)/(1-n) );\nIntFunc(x,Sin(_x),-Cos(x));\nIntFunc(x,1/Sin(_x), Ln( 1/Sin(x) - Cos(x)/Sin(x) ) );\nIntFunc(x,Cos(_x),Sin(x));\nIntFunc(x,1/Cos(_x),Ln(1/Cos(x)+Tan(x)));\nIntFunc(x,Tan(_x),-Ln(Cos(x)));\nIntFunc(x,1/Tan(_x),Ln(Sin(x)) );\nIntFunc(x,Cos(_x)/Sin(_x),Ln(Sin(x)));\nIntFunc(x,Exp(_x),Exp(x));\nIntFunc(x,(C_IsFreeOf(var))^(_x),C^x/Ln(C));\n// we don't need Ln(Abs(x))\nIntFunc(x,num_IsFreeOf(var) / (_x),num*Ln(x));\nIntFunc(x,Ln(_x),x*Ln(x)-x);\n// where did these 1+1's come from?\nIntFunc(x,(_x)*Ln(_x),(1/(1+1))*x^(1+1)*Ln(x) - (1/(1+1)^2)*x^(1+1) );\nIntFunc(x,Ln(_x)*(_x),(1/(1+1))*x^(1+1)*Ln(x) - (1/(1+1)^2)*x^(1+1) );\n\nIntFunc(x,1/Sin(_x)^2,-Cos(x)/Sin(x) );\nIntFunc(x,1/Cos(_x)^2,Tan(x) );\nIntFunc(x,1/(Sin(_x)*Tan(_x)),-1/Sin(x));\nIntFunc(x,Tan(_x)/Cos(_x),1/Cos(x));\nIntFunc(x,1/Sinh(_x)^2,-1/Tanh(x));\nIntFunc(x,1/Cosh(_x)^2,Tanh(x));\nIntFunc(x,1/(Sinh(_x)*Tanh(_x)),-1/Sinh(x));\nIntFunc(x,Tanh(_x)/Cosh(_x),-1/Cosh(x));\n\nIntFunc(x,1/Sqrt(m_IsFreeOf(x)-_x^2),ArcSin(x/Sqrt(m)) );\n\nIntFunc(x,Exp(n_IsNumber*_x)*Sin(m_IsNumber*_x),Exp(n*x)*(n*Sin(m*x)- m*Cos(m*x))/(m^2+n^2) );\n\n// n>0\nIntFunc(x,Ln(_x)*(_x)^n_IsNumber,(1/(n+1))*x^(n+1)*Ln(x) - (1/(n+1)^2)*x^(n+1) );\n\n// n>0\nIntFunc(x,Ln(A_IsNumber*_x)*(_x)^n_IsNumber,(1/(n+1))*x^(n+1)*Ln(A*x) - (1/(n+1)^2)*x^(n+1) );\n\nIntFunc(x,Sin(Ln(_x)),x*Sin(Ln(x))/2 - x*Cos(Ln(x))/2 );\nIntFunc(x,Cos(Ln(_x)),x*Sin(Ln(x))/2 - x*Cos(Ln(x))/2 );\n\nIntFunc(x,1/((_x)*Ln(_x)),Ln(Ln(x)));\n\nIntFunc(x,(_x)^(-1),Ln(x));\n\nIntFunc(x,(_x)^(n_IsFreeOf(x)),x^(n+1)/(n+1));\nIntFunc(x,Sinh(_x),Cosh(x));\nIntFunc(x,Sinh(_x)^2,Sinh(2*x)/4 - x/2);\nIntFunc(x,1/Sinh(_x),Ln(Tanh(x/2)));\nIntFunc(x,Cosh(_x),Sinh(x));\nIntFunc(x,Cosh(_x)^2,Sinh(2*x)/4 + x/2);\nIntFunc(x,1/Cosh(_x),ArcTan(Sinh(x)));\nIntFunc(x,Tanh(_x),Ln(Cosh(x)));\nIntFunc(x,Tanh(_x)/Cosh(_x),-1/Cosh(x));\nIntFunc(x,1/Cosh(_x)^2,Tanh(x));\n//IntFunc(x,1/Sech(_x)*Coth(_x),-1/Sinh(x));\nIntFunc(x,1/Tanh(_x),Ln(Sinh(x)));\n\nIntFunc(x,Abs(_x),Abs(x)*x/2);\t// not 2*a\n\nIntFunc(x,ArcTan(_x),x*ArcTan(x) - Ln(x^2 + 1)/2);\n//IntFunc(x,ArcSin(_x),(x*ArcSin(x)) + Sqrt(1-x^2) );\nIntFunc(x,ArcCos(_x),x*ArcCos(x) - Sqrt(1-x^2) );\n\nIntFunc(x,ArcTanh(_x),x*ArcTanh(x) + Ln(1-x^2)/2 );\nIntFunc(x,ArcSinh(_x),x*ArcSinh(x) - Sqrt(x^2 + 1) );\nIntFunc(x,ArcCosh(_x),x*ArcCosh(x) - Sqrt(x-1)*Sqrt(x+1) );\n\nIntFunc(x, _x*Exp(_x), (x - 1)*Exp(x));\nIntFunc(x, _x^n_IsPositiveInteger*Exp(_x), x^n*Exp(x) - n * AntiDeriv(x, x^(n-1)*Exp(x)));\n\nIntFunc(x, Exp(-_x), -Exp(-x));\nIntFunc(x, _x*Exp(-_x), -(x + 1)*Exp(-x));\nIntFunc(x, _x^n_IsPositiveInteger*Exp(-_x), -x^n*Exp(-x)+n*AntiDeriv(x, x^(n-1)*Exp(-x)));\n\n// n^2 > x^2\n//IntFunc(x,num_IsFreeOf(var)/(-(_x)^2 + n_IsNumber),num*ArcTanh(x/Sqrt(n))/n);\n\n// x^2 > n^2\n//IntFunc(x,num_IsFreeOf(var)/((_x)^2 - n_IsNumber),num * -ArcCoth(x/Sqrt(n))/Sqrt(n));\n\n// n^2 > x^2\n//IntFunc(x,num_IsFreeOf(var)/Sqrt(n_IsNumber - (_x)^2),num*ArcSin(x/Sqrt(n)));\n\n// previous code is killing this....\nIntFunc(x,num_IsFreeOf(var)/(A_IsNumber + B_IsNumber*(_x))^2,-num/(A*b + B^2*x));\n\n// Code works now?\nIntFunc(x,num_IsFreeOf(var)/(n_IsNumber + m_IsNumber*Exp(p_IsNumber*(_x))),num*x/n - num*Ln(n + m*Exp(p*x))/(n*p));\nIntFunc(x,num_IsFreeOf(var)/(m_IsNumber*Exp(p_IsNumber*(_x)) + n_IsNumber),num*x/n - num*Ln(n + m*Exp(p*x))/(n*p));\n\nIntPureSquare(x,num_IsFreeOf(var)/(_x),1,1,(num/(Sqrt(Matched'b()*Matched'a())))*ArcTan(var/Sqrt(Matched'b()/Matched'a())));\n\n\n\n///// Integrating Special Functions\nIntFunc(x,Erf(_x), x*Erf(x)+ 1/(Exp(x^2)*Sqrt(Pi)) );\n\n\n\n"
  },
  {
    "path": "scripts/integrate.rep/code.ys.def",
    "content": "Integrate\nAntiDeriv\n}\n"
  },
  {
    "path": "scripts/integrate.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef( \"Integrate\", \"calculus1\",\"defint\", // Same argument reordering as Sum.\n       { $, _2 .. _3, OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _4) },\n       { $, _{2,2,1}, _{1,1}, _{1,2}, _{2,3} }\n      );\nOMDef( \"AntiDeriv\", \"yacas\",\"AntiDeriv\" );\n"
  },
  {
    "path": "scripts/io.rep/code.ys",
    "content": "/// stuff related to input-output during interactive sessions\n\n/// simple prettyprinter\nUse(\"io.rep/print.ys\");\n\n/// global error reporting and handling\nUse(\"io.rep/errors.ys\");\n\n/// ascii formula prettyprinter\nUse(\"io.rep/formula.ys\");\n"
  },
  {
    "path": "scripts/io.rep/code.ys.def",
    "content": "Print\nIsError\nAssert\nGetErrorTableau\nClearErrors\nDumpErrors\nClearError\nPrettyForm\nEvalFormula\n}\n"
  },
  {
    "path": "scripts/io.rep/defaultprint.ys",
    "content": "/// The new default pretty-printer: DefaultPrint\nFunction(\"DefaultPrint\", {x})\n[\n\tDumpErrors();\n\tWriteString(\"Out> \");\n\tWrite(x);\n\tWriteString(\";\n\");\n];\nHoldArg(\"DefaultPrint\", x);\n\n"
  },
  {
    "path": "scripts/io.rep/defaultprint.ys.def",
    "content": "DefaultPrint\n}\n"
  },
  {
    "path": "scripts/io.rep/errors.ys",
    "content": "//////////////////////////////////////////////////\n/// ErrorTableau, Assert, IsError --- global error reporting\n//////////////////////////////////////////////////\n\nLocalSymbols(ErrorTableau) [\n\n  /// global error tableau. Its entries do not have to be lists.\n  Set(ErrorTableau, {});\n\n  GetErrorTableau() := ErrorTableau;\n\n  ClearErrors() <-- Set(ErrorTableau, {});\n\n  /// aux function to check for corrupt tableau\n  CheckErrorTableau() <--\n  If(\n    Not IsList(ErrorTableau),\n    Set(ErrorTableau, {{\"general\", \"corrupted ErrorTableau\"}})\n  );\n\n]; // LocalSymbols(ErrorTableau)\n\n/// check for errors\nIsError() <--\n[\n\tCheckErrorTableau();\n\tLength(GetErrorTableau())>0;\n];\n\n/// check for errors of a given kind\nIsError(error'class_IsString) <--\n[\n\tCheckErrorTableau();\n\tGetErrorTableau()[error'class] != Empty;\n];\n\n/// post an error if assertion fails\n(Assert(_error'class, _error'object) _predicate) <--\n[\n\tCheckErrorTableau();\n\tIf(Equals(predicate, True),\t// if it does not evaluate to True, it's an error\n\t\tTrue,\n\t\t[\t// error occurred, need to post error'object\n\t\t\tDestructiveAppend(GetErrorTableau(), {error'class, error'object});\n\t\t\tFalse;\n\t\t]\n\t);\n];\n\n/// interface\n(Assert(_error'class) _predicate) <-- Assert(error'class, True) predicate;\n\n/// interface\n(Assert() _predicate) <-- Assert(\"generic\", True) predicate;\n\n/// print all errors and clear the tableau\nDumpErrors() <--\n[\n\tLocal(error'object, error'word);\n\tCheckErrorTableau();\n\tForEach(error'object, GetErrorTableau())\n\t[\t// error'object might be e.g. {\"critical\", {\"bad bad\", -1000}}\n\t\tIf(\n\t\t\tIsList(error'object),\n\t\t\t[\n\t\t\t\tIf( // special case: error class \"warning\"\n\t\t\t\t\tLength(error'object) > 0 And error'object[1] = \"warning\",\n\t\t\t\t\t[\n\t\t\t\t\t\terror'word := \"Warning\";\n\t\t\t\t\t\terror'object[1] := \"\";\t// don't print the word \"warning\" again\n\t\t\t\t\t],\n\t\t\t\t\terror'word := \"Error: \"\t// important hack: insert \": \" here but not after \"Warning\"\n\t\t\t\t);\n\n\t\t\t\tIf(\t// special case: {\"error'class\", True}\n\t\t\t\t\tLength(error'object)=2 And error'object[2]=True,\n\t\t\t\t\tEcho(error'word, error'object[1]),\n\t\t\t\t\t[\n\t\t\t\t\t\tEcho(error'word, error'object[1], \": \",\n\t\t\t\t\t\t\tPrintList(Tail(error'object)));\n\t\t\t\t\t]\n\t\t\t\t);\n\t\t\t],\n\t\t\t// error'object is not a list: just print it\n\t\t\tEcho(\"Error: \", error'object)\n\t\t);\n\t];\n\tClearErrors();\n];\n\n/// obtain error object\nGetError(error'class_IsString) <--\n[\n\tLocal(error);\n\terror := GetErrorTableau()[error'class];\n\tIf(\n\t\terror != Empty,\n\t\terror,\n\t\tFalse\n\t);\n];\n\n/// delete error\nClearError(error'class_IsString) <-- AssocDelete(GetErrorTableau(), error'class);\n\n\n//////////////////////////////////////////////////\n\n"
  },
  {
    "path": "scripts/io.rep/formula.ys",
    "content": "\n/*\nTODO:\n- Func(a=b) prematurely evaluates a=b\n- clean up the code!\n  - document the code!!!\n- prefix/postfix currently not used!!!\n- some rules for rendering the formula are slooooww....\n  \n- bin, derivative, sqrt, integral, summation, limits, \n      ___\n     / a |\n \\  /  -\n  \\/   b\n\n   /\n   |\n   |\n   |\n   /\n\n  d\n --- f( x )\n d x\n\n   2\n  d\n ----  f( x )\n    2\n d x\n \n  Infinity\n    ___\n    \\\n     \\    n\n     /   x\n    /__\n    n = 0\n                 Sin(x)\n     lim         ------\n x -> Infinity    x\n\n\n    \n*/\n\n/*\nNLog(str):=\n[\n  WriteString(str);\n  NewLine();\n];\n*/\n\nCharList(length,item):=\n[\n  Local(line,i);\n  line:=\"\";\n  For(Set(i,0),LessThan(i,length),Set(i,MathAdd(i,1)))\n    Set(line, line:item);\n  line;\n];\n\nCharField(width,height) := Array'Create(height,CharList(width,\" \"));\n\nWriteCharField(charfield):=\n[\n  Local(i,len);\n  len:=Length(charfield);\n  For(Set(i,1),i<=len,Set(i,MathAdd(i,1)))\n  [\n    WriteString(charfield[i]);\n    NewLine();\n  ];\n  True;\n];\n\nColumnFilled(charfield,column):=\n[\n  Local(i,result,len);\n  result:=False;\n  len:=Length(charfield);\n  For(Set(i, 1),(result = False) And (i<=len),Set(i,MathAdd(i,1)))\n  [\n    If(StringMid'Get(column,1,charfield[i]) != \" \",result:=True);\n  ];\n  result;\n];\nWriteCharField(charfield,width):=\n[\n  Local(pos,length,len);\n  Set(length, Length(charfield[1]));\n  Set(pos, 1);\n  While(pos<=length)\n  [\n    Local(i,thiswidth);\n    Set(thiswidth, width);\n    If(thiswidth>(length-pos)+1,\n      [\n        Set(thiswidth, MathAdd(MathSubtract(length,pos),1));\n      ],\n      [\n        While (thiswidth>1 And ColumnFilled(charfield,pos+thiswidth-1))\n        [\n          Set(thiswidth,MathSubtract(thiswidth,1));\n        ];\n        If(thiswidth = 1, Set(thiswidth, width));\n      ]\n    );\n    len:=Length(charfield);\n    For(Set(i, 1),i<=len,Set(i,MathAdd(i,1)))\n    [\n      WriteString(StringMid'Get(pos,thiswidth,charfield[i]));\n      NewLine();\n    ];\n    Set(pos, MathAdd(pos, thiswidth));\n    NewLine();\n  ];\n  True;\n];\n\n\n\nPutString(charfield,x,y,string):=\n[\n  cf[y] := StringMid'Set(x,string,cf[y]);\n  True;\n];\n\nMakeOper(x,y,width,height,oper,args,base):=\n[\n  Local(result);\n  Set(result,Array'Create(7,0));\n  Array'Set(result,1,x);\n  Array'Set(result,2,y);\n  Array'Set(result,3,width);\n  Array'Set(result,4,height);\n  Array'Set(result,5,oper);\n  Array'Set(result,6,args);\n  Array'Set(result,7,base);\n  result;\n];\n\n\nMoveOper(f,x,y):=\n[\n  f[1]:=MathAdd(f[1], x); /* move x */\n  f[2]:=MathAdd(f[2], y); /* move y */\n  f[7]:=MathAdd(f[7], y); /* move base */\n];\n\nAlignBase(i1,i2):=\n[\n  Local(base);\n  Set(base, Max(i1[7],i2[7]));\n  MoveOper(i1,0,MathSubtract(base,(i1[7])));\n  MoveOper(i2,0,MathSubtract(base,(i2[7])));\n];\n\n10 # BuildArgs({}) <-- Formula(Atom(\" \"));\n20 # BuildArgs({_head}) <-- head;\n30 # BuildArgs(_any)    <--\n     [\n        Local(item1,item2,comma,base,newitem);\n        Set(item1, any[1]);\n        Set(item2, any[2]);\n        Set(comma, Formula(Atom(\",\")));\n        Set(base, Max(item1[7],item2[7]));\n        MoveOper(item1,0,MathSubtract(base,(item1[7])));\n        MoveOper(comma,MathAdd(item1[3],1),base);\n\n        MoveOper(item2,comma[1]+comma[3]+1,MathSubtract(base,(item2[7])));\n        Set(newitem, MakeOper(0,0,MathAdd(item2[1],item2[3]),Max(item1[4],item2[4]),\"Func\",{item1,comma,item2},base));\n        BuildArgs(newitem:Tail(Tail(any)));\n      ];\n\n\n\nFormulaBracket(f):=\n[\n  Local(left,right);\n  Set(left, Formula(Atom(\"(\")));\n  Set(right, Formula(Atom(\")\")));\n  left[4]:=f[4];\n  right[4]:=f[4];\n  MoveOper(left,f[1],f[2]);\n  MoveOper(f,2,0);\n  MoveOper(right,f[1]+f[3]+1,f[2]);\n  MakeOper(0,0,right[1]+right[3],f[4],\"Func\",{left,f,right},f[7]);\n];\n\n\n/* RuleBase(\"Formula\",{f}); */\n\n1 # Formula(f_IsAtom) <--\n  MakeOper(0,0,Length(String(f)),1,\"Atom\",String(f),0);\n\n2 # Formula(_xx ^ _yy) <--\n[\n  Local(l,r);\n  Set(l, BracketOn(Formula(xx),xx,OpLeftPrecedence(\"^\")));\n  Set(r, BracketOn(Formula(yy),yy,OpRightPrecedence(\"^\")));\n  MoveOper(l,0,r[4]);\n  MoveOper(r,l[3],0);\n  MakeOper(0,0,MathAdd(l[3],r[3]),MathAdd(l[4],r[4]),\"Func\",{l,r},l[2]+l[4]-1);\n];\n\n\n\n10 # FormulaArrayItem(xx_IsList) <--\n[\n  Local(sub,height);\n  sub := {};\n  height := 0;\n  ForEach(item,xx)\n  [\n    Local(made);\n    made := FormulaBracket(Formula(item));\n    If(made[4] > height,Set(height,made[4]));\n    DestructiveAppend(sub,made);\n  ];\n  MakeOper(0,0,0,height,\"List\",sub,height>>1);\n];\n\n\n20 # FormulaArrayItem(_item) <-- Formula(item);\n\n2 # Formula(xx_IsList) <--\n[\n  Local(sub,width,height);\n  sub:={};\n  width := 0;\n  height := 1;\n\n  ForEach(item,xx)\n  [\n    Local(made);\n    made := FormulaArrayItem(item);\n\n    If(made[3] > width,Set(width,made[3]));\n    MoveOper(made,0,height);\n    Set(height,MathAdd(height,MathAdd(made[4],1)));\n    DestructiveAppend(sub,made);\n  ];\n\n  Local(thislength,maxlength);\n  maxlength:=0;\n  ForEach(item,xx)\n  [\n    thislength:=0;\n    if(IsList(item)) [thislength:=Length(item);];\n    if (maxlength<thislength) [maxlength:=thislength;];\n  ];\n\n  If(maxlength>0,\n  [\n    Local(i,j);\n    width:=0;\n    For(j:=1,j<=maxlength,j++)\n    [\n      Local(w);\n      w := 0;\n      For(i:=1,i<=Length(sub),i++)\n      [\n        if (IsList(xx[i]) And j<=Length(xx[i]))\n          If(sub[i][6][j][3] > w,w := sub[i][6][j][3]);\n      ];\n      \n      For(i:=1,i<=Length(sub),i++)\n      [\n        if (IsList(xx[i]) And j<=Length(xx[i]))\n          MoveOper(sub[i][6][j],width,0);\n      ];\n      width := width+w+1;\n    ];\n    For(i:=1,i<=Length(sub),i++)\n    [\n      sub[i][3] := width;\n    ];\n  ]\n  );\n\n  sub := MakeOper(0,0,width,height,\"List\",sub,height>>1);\n  FormulaBracket(sub);\n];\n\n2 # Formula(_xx / _yy) <--\n[\n  Local(l,r,dash,width);\n/*\n  Set(l, BracketOn(Formula(xx),xx,OpLeftPrecedence(\"/\")));\n  Set(r, BracketOn(Formula(yy),yy,OpRightPrecedence(\"/\")));\n*/  \n  Set(l, Formula(xx));\n  Set(r, Formula(yy));\n  Set(width, Max(l[3],r[3]));\n  Set(dash, Formula(Atom(CharList(width,\"-\"))));\n  MoveOper(dash,0,l[4]);\n  MoveOper(l,(MathSubtract(width,l[3])>>1),0);\n  MoveOper(r,(MathSubtract(width,r[3])>>1),MathAdd(dash[2], dash[4]));\n  MakeOper(0,0,width,MathAdd(r[2], r[4]),\"Func\",{l,r,dash},dash[2]);\n];\n\nRuleBase(\"BracketOn\",{op,f,prec});\nRule(\"BracketOn\",3,1,IsFunction(f) And NrArgs(f) = 2\n     And IsInfix(Type(f)) And OpPrecedence(Type(f)) > prec)\n[\n FormulaBracket(op);\n];\nRule(\"BracketOn\",3,2,True)\n[\n  op;\n];\n\n10 # Formula(f_IsFunction)_(NrArgs(f) = 2 And IsInfix(Type(f))) <--\n[\n  Local(l,r,oper,width,height,base);\n  Set(l, Formula(f[1]));\n  Set(r, Formula(f[2]));\n\n  Set(l, BracketOn(l,f[1],OpLeftPrecedence(Type(f))));\n  Set(r, BracketOn(r,f[2],OpRightPrecedence(Type(f))));\n\n  Set(oper, Formula(f[0]));\n  Set(base, Max(l[7],r[7]));\n  MoveOper(oper,MathAdd(l[3],1),MathSubtract(base,(oper[7])));\n  MoveOper(r,oper[1] + oper[3]+1,MathSubtract(base,(r[7])));\n  MoveOper(l,0,MathSubtract(base,(l[7])));\n  Set(height, Max(MathAdd(l[2], l[4]),MathAdd(r[2], r[4])));\n\n  MakeOper(0,0,MathAdd(r[1], r[3]),height,\"Func\",{l,r,oper},base);\n];\n\n11 # Formula(f_IsFunction) <--\n[\n  Local(head,args,all);\n  Set(head, Formula(f[0]));\n  Set(all, Tail(Listify(f)));\n\n  Set(args, FormulaBracket(BuildArgs(MapSingle(\"Formula\",Apply(\"Hold\",{all})))));\n  AlignBase(head,args);\n  MoveOper(args,head[3],0);\n\n  MakeOper(0,0,args[1]+args[3],Max(head[4],args[4]),\"Func\",{head,args},head[7]);\n];\n\n\n\nRuleBase(\"RenderFormula\",{cf,f,x,y});\n\n/*\n/   /  /\n\\   |  |\n    \\  |\n       \\\n*/\n\nRule(\"RenderFormula\",4,1,f[5] = \"Atom\" And f[6] = \"(\" And f[4] > 1)\n[\n  Local(height,i);\n  Set(x, MathAdd(x,f[1]));\n  Set(y, MathAdd(y,f[2]));\n  Set(height, MathSubtract(f[4],1));\n\n  cf[y] := StringMid'Set(x, \"/\", cf[y]);\n  cf[MathAdd(y,height)] := StringMid'Set(x, \"\\\\\", cf[MathAdd(y,height)]);\n  For (Set(i,1),LessThan(i,height),Set(i,MathAdd(i,1)))\n    cf[MathAdd(y,i)] := StringMid'Set(x, \"|\", cf[MathAdd(y,i)]);\n];\n\nRule(\"RenderFormula\",4,1,f[5] = \"Atom\" And f[6] = \")\" And f[4] > 1)\n[\n  Local(height,i);\n  Set(x, MathAdd(x,f[1]));\n  Set(y, MathAdd(y,f[2]));\n  Set(height, MathSubtract(f[4],1));\n  cf[y] := StringMid'Set(x, \"\\\\\", cf[y]);\n  cf[y+height] := StringMid'Set(x, \"/\", cf[y+height]);\n  For (Set(i,1),LessThan(i,height),Set(i,MathAdd(i,1)))\n    cf[MathAdd(y,i)] := StringMid'Set(x, \"|\", cf[MathAdd(y,i)]);\n];\n\nRule(\"RenderFormula\",4,5,f[5] = \"Atom\")\n[\n  cf[MathAdd(y, f[2]) ]:=\n    StringMid'Set(MathAdd(x,f[1]),f[6],cf[MathAdd(y, f[2]) ]);\n];\n\nRule(\"RenderFormula\",4,6,True)\n[\n  ForEach(item,f[6])\n  [\n    RenderFormula(cf,item,MathAdd(x, f[1]),MathAdd(y, f[2]));\n  ];\n];\n\nLocalSymbols(formulaMaxWidth) [\n  SetFormulaMaxWidth(width):=\n  [\n    formulaMaxWidth := width;\n  ];\n  FormulaMaxWidth() := formulaMaxWidth;\n  SetFormulaMaxWidth(60);\n]; // LocalSymbols(formulaMaxWidth)\n\nFunction(\"PrettyForm\",{ff})\n[\n  Local(cf,f);\n\n  f:=Formula(ff);\n\n  cf:=CharField(f[3],f[4]);\n  RenderFormula(cf,f,1,1);\n\n  NewLine();\n  WriteCharField(cf,FormulaMaxWidth());\n  \n  DumpErrors();\n  True;\n];\n/*\nHoldArg(\"PrettyForm\",ff);\n*/\n\nEvalFormula(f):=\n[\n  Local(result);\n  result:= UnList({Atom(\"=\"),f,Eval(f)});\n  PrettyForm(result);\n  True;\n];\nHoldArg(\"EvalFormula\",f);\n\n/*\n{x,y,width,height,oper,args,base}\n*/\n\n\n\n"
  },
  {
    "path": "scripts/io.rep/print.ys",
    "content": "\n/* A reference print implementation. Expand at own leisure.\n *\n * This file implements Print, a scripted expression printer.\n */\n\n\n/* 60000 is the maximum precedence allowed for operators */\n10 # Print(_x) <--\n[\n  Print(x,60000);\n  NewLine();\n  DumpErrors();\n];\n\n/* Print an argument within an environment of precedence n */\n10 # Print(x_IsAtom,_n) <-- Write(x);\n10 # Print(_x,_n)_(IsInfix(Type(x))And NrArgs(x) = 2) <--\n[\n  Local(bracket);\n  bracket:= (OpPrecedence(Type(x)) > n);\n  If(bracket,WriteString(\"(\"));\n  Print(x[1],OpLeftPrecedence(Type(x)));\n  Write(x[0]);\n  Print(x[2],OpRightPrecedence(Type(x)));\n  If(bracket,WriteString(\")\"));\n];\n\n10 # Print(_x,_n)_(IsPrefix(Type(x)) And NrArgs(x) = 1) <--\n[\n  Local(bracket);\n  bracket:= (OpPrecedence(Type(x)) > n);\n  Write(x[0]);\n  If(bracket,WriteString(\"(\"));\n  Print(x[1],OpRightPrecedence(Type(x)));\n  If(bracket,WriteString(\")\"));\n];\n\n10 # Print(_x,_n)_(IsPostfix(Type(x))And NrArgs(x) = 1) <--\n[\n  Local(bracket);\n  bracket:= (OpPrecedence(Type(x)) > n);\n  If(bracket,WriteString(\"(\"));\n  Print(x[1],OpLeftPrecedence(Type(x)));\n  Write(x[0]);\n  If(bracket,WriteString(\")\"));\n];\n\n20 # Print(_x,_n)_(Type(x) = \"List\") <--\n[\n  WriteString(\"{\");\n  PrintArg(x);\n  WriteString(\"}\");\n];\n\n20 # Print(_x,_n)_(Type(x) = \"Prog\") <--\n[\n  WriteString(\"[\");\n  PrintArgProg(Tail(Listify(x)));\n  WriteString(\"]\");\n];\n20 # Print(_x,_n)_(Type(x) = \"Nth\") <--\n[\n  Print(x[1],0);\n  WriteString(\"[\");\n  Print(x[2],60000);\n  WriteString(\"]\");\n];\n\n100 # Print(x_IsFunction,_n) <--\n [\n   Write(x[0]);\n   WriteString(\"(\");\n   PrintArg(Tail(Listify(x)));\n   WriteString(\")\");\n ];\n\n\n/* Print the arguments of an ordinary function */\n10 # PrintArg({}) <-- True;\n\n20 # PrintArg(_list) <--\n[\n  Print(Head(list),60000);\n  PrintArgComma(Tail(list));\n];\n10 # PrintArgComma({}) <-- True;\n20 # PrintArgComma(_list) <--\n[\n  WriteString(\",\");\n  Print(Head(list),60000);\n  PrintArgComma(Tail(list));\n];\n\n\n18 # Print(Complex(0,1),_n)   <-- [WriteString(\"I\");];\n19 # Print(Complex(0,_y),_n)  <-- [WriteString(\"I*\");Print(y,4);];\n19 # Print(Complex(_x,1),_n)  <-- [Print(x,7);WriteString(\"+I\");];\n20 # Print(Complex(_x,_y),_n) <-- [Print(x,7);WriteString(\"+I*\");Print(y,4);];\n\n\n/* Tail-recursive printing the body of a compound statement */\n10 # PrintArgProg({}) <-- True;\n20 # PrintArgProg(_list) <--\n[\n   Print(Head(list),60000);\n   WriteString(\";\");\n   PrintArgProg(Tail(list));\n];\n\n\n\n\n\n\n"
  },
  {
    "path": "scripts/limit.rep/code.ys",
    "content": "/*                            */\n/*  Limit operator rule base  */\n/*                            */\n\n/* Special case: constant */\n100 # Lim(_var, _tar, _dir, p_IsFreeOf(var)) <-- p;\n\n/* Special case: limits of polynomials as x approaches infinity */\n100 # Lim(_var, _tar, _dir, _p)_(CanBeUni(var, p) And Degree(p, var) > 0 And IsConstant(LeadingCoef(p,var)) And IsInfinity(tar))\n    <-- LeadingCoef(p,var) * Sign(tar)^Degree(p,var) * Infinity;\n\n/* Special case: rational functions */\n110 # Lim(_var, _tar, _dir, _p)_(IsRationalFunction(p, var) And IsInfinity(tar)) <--\n    Lim(var, tar, dir, Div(Numer(p), Denom(p)));\n\n/* Special case: make use of the logarithm properties */\n120 # Lim(_var, _tar, _dir, Ln(_a) + Ln(_b)) <-- Lim(var, tar, dir, Ln(a*b));\n120 # Lim(_var, _tar, _dir, Ln(_a) - Ln(_b)) <-- Lim(var, tar, dir, Ln(a/b));\n\n/*  Exponentiation rules  */\n\n/*  Special limit #1:  0 ^ 0;  #2:  1 ^ Infinity;  #3:  Infinity ^ 0  */\n200 # Lim(_var, _tar, _dir, _x ^ _y)_\n( [\n    Local(lx,ly); lx := Lim(var, tar, dir, x); ly := Lim(var, tar, dir, y);\n    ((IsZero(lx) And IsZero(ly)) Or ((lx = 1) And IsInfinity(ly)) Or (IsInfinity(lx) And IsZero(ly)));\n] )\n<-- Exp(Lim(var, tar, dir, y * Ln(x)));\n\n/*  Default rule  */\n210 # Lim(_var, _tar, _dir, _x ^ _y)\n<-- Lim(var, tar, dir, x)^Lim(var, tar, dir, y);\n\n\n/*  Division rules  */\n\n/*  Special limit #4:  0 / 0;  #5:  Infinity / Infinity  */\n300 # Lim(_var, _tar, _dir, _x / _y)_\n( [\n    Local(lx,ly,infx,infy);\n     lx := Lim(var, tar, dir, x);\n     ly := Lim(var, tar, dir, y);\n     infx := (IsInfinity(lx) Or (IsZero(Re(lx)) And IsInfinity(Im(lx))));\n     infy := (IsInfinity(ly) Or (IsZero(Re(ly)) And IsInfinity(Im(ly))));\n    ((IsZero(lx) And IsZero(ly)) Or\n     (infx And infy)\n     );\n] )\n<-- Lim(var, tar, dir, ApplyPure(\"D\", {var, x})/ApplyPure(\"D\", {var, y}));\n\n/*  Special limit #6: null denominator  */\n/*  Probably there are still some problems.  */\n\nDir(Right) <-- 1;\nDir(Left) <-- -1;\n\n// make sure standard definition of Sign() is pulled in before we\n// special-case it\nSign(1);\n\nUnProtect(Sign);\n\n/*  To get the sign of the denominator on one side:  */\nSign(_var, _tar, _dir, _exp, _n)\n<-- [\n  Local(der, coef); der := ApplyPure(\"D\", {var, exp});\n  coef := Eval(ApplyPure(\"Subst\", {var, tar, der}));\n  If ( coef = 0,\n       Sign(var, tar, dir, der, n+1),\n       (Sign(coef)*Dir(dir)) ^ n\n     );\n];\n\nProtect(Sign);\n\n/*  To avoid infinite recursion (with 1/Exp(-x) for instance)  */\n310 # Lim(_var, _tar, _dir, _x / _y)_\n(IsInfinity(tar) And IsZero(Lim(var, tar, dir, y)))\n<-- Sign(Lim(var, tar, dir, x))*Sign(Lim(var, tar, dir, ApplyPure(\"D\", {var, y})))*tar;\n\n320 # Lim(_var, _tar, _dir, _x / _y)_IsZero(Lim(var, tar, dir, y))\n<-- Sign(Lim(var, tar, dir, x))*Sign(var, tar, dir, y, 1)*Infinity;\n\n\n/*  Default rule  */\n330 # Lim(_var, _tar, _dir, _x / _y) <-- [\n    Local(u,v,r);\n\n    u := Lim(var, tar, dir, x);\n    v := Lim(var, tar, dir, y);\n\n    r := u / v;\n\n    If (u = Undefined And IsInfinity(v), [\n        Local(li, ls);\n\n        li := LimInf(var,tar,dir,x);\n        ls := LimSup(var,tar,dir,x);\n        r := (li * ls) / v;\n    ]);\n\n    r;\n];\n\n\n/*  Multiplication rules  */\n\n/*  To avoid some infinite recursions  */\n400 # Lim(_var, _tar, _dir, _x * Exp(_y))_\n(IsInfinity(Lim(var, tar, dir, x)) And (Lim(var, tar, dir, y) = -Infinity))\n<-- Lim(var, tar, dir, x/Exp(-y));\n400 # Lim(_var, _tar, _dir, Exp(_x) * _y)_\n((Lim(var, tar, dir, x) = -Infinity) And IsInfinity(Lim(var, tar, dir, y)))\n<-- Lim(var, tar, dir, y/Exp(-x));\n400 # Lim(_var, _tar, _dir, Ln(_x) * _y)_\n(IsZero(Lim(var, tar, dir, x)) And IsZero(Lim(var, tar, dir, y)))\n<-- Lim(var, tar, dir, y*Ln(x));\n\n/*  Special limit #7:  0 * Infinity  */\n410 # Lim(_var, _tar, _dir, _x * _y)_\n((IsZero(Lim(var, tar, dir, x)) And IsInfinity(Lim(var, tar, dir, y)))\n  Or (IsInfinity(Lim(var, tar, dir, x)) And IsZero(Lim(var, tar, dir, y))))\n<-- Lim(var, tar, dir, Simplify(ApplyPure(\"D\", {var, y})/ApplyPure(\"D\", {var, 1/x})));\n\n/*  Default rule  */\n420 # Lim(_var, _tar, _dir, _x * _y) <-- [\n    Local(u,v,r);\n\n    u := Lim(var, tar, dir, x);\n    v := Lim(var, tar, dir, y);\n\n    r := u * v;\n\n    If (u = 0 And v = Undefined, [\n        Local(li, ls);\n        li := LimInf(var,tar,dir,y);\n        ls := LimSup(var,tar,dir,y);\n        r := u * li * ls;\n    ], If (u = Undefined And v = 0, [\n        Local(li, ls);\n        li := LimInf(var,tar,dir,x);\n        ls := LimSup(var,tar,dir,x);\n        r := v * li * ls;\n    ]));\n\n    r;\n];\n\n\n/*  Substraction rules  */\n\n/*  Special limit #8a:  Sqrt(Infinity) - Sqrt(Infinity)  */\n500 # Lim(_var, _tar, _dir, Sqrt(_x) - Sqrt(_y))_\n( [\n    Lim(var, tar, dir, x) = Infinity And Lim(var, tar, dir, y) = Infinity;\n] )\n<-- Lim(var, tar, dir, (x - y)/(Sqrt(x)+Sqrt(y)));\n\n/*  Special limit #8b:  Infinity - Infinity  */\n505 # Lim(_var, _tar, _dir, _x - _y)_\n( [\n    Local(lx,ly); lx := Lim(var, tar, dir, x); ly := Lim(var, tar, dir, y);\n    ((lx = Infinity) And (ly = Infinity)) Or ((lx = -Infinity) And (ly = -Infinity));\n] )\n<-- Lim(var, tar, dir, x*(1-y/x));\n\n/*  Default rule  */\n510 # Lim(_var, _tar, _dir, _x - _y)\n<-- Lim(var, tar, dir, x)-Lim(var, tar, dir, y);\n\n/*  Unary minus  */\n520 # Lim(_var, _tar, _dir, - _x)\n<-- - Lim(var, tar, dir, x);\n\n\n/*  Addition rules  */\n\n/*  Special limit #9:  Infinity + (-Infinity)  */\n600 # Lim(_var, _tar, _dir, _x + _y)_\n( [\n    Local(lx,ly); lx := Lim(var, tar, dir, x); ly := Lim(var, tar, dir, y);\n    ((lx = Infinity) And (ly = -Infinity)) Or ((lx = -Infinity) And (ly = Infinity));\n] )\n<-- Lim(var, tar, dir, x*(1+y/x));\n\n605 # Lim(_var, _tar, _dir, _x + _y)_\n(\n    Lim(var, tar, dir, x) = Infinity And Lim(var, tar, dir, y) = Undefined And LimInf(var, tar, dir, y) != -Infinity\n    Or\n    Lim(var, tar, dir, x) = Undefined And LimInf(var, tar, dir, x) != -Infinity And Lim(var, tar, dir, y) = Infinity\n\n) <-- Infinity;\n\n\n/*  Default rule  */\n610 # Lim(_var, _tar, _dir, _x + _y)\n<-- Lim(var, tar, dir, x)+Lim(var, tar, dir, y);\n\n/*  Global default rule : evaluate expression  */\n\n700 # Lim(_var, _tar, _dir, exp_IsFunction)\n<-- Eval(MapArgs(exp,\"LimitArgs\"));\n\nLimitArgs(_arg) <-- Lim(var,tar,dir,arg);\nUnFence(\"LimitArgs\",1); /* Allow LimitArgs to have access to the local variables of the caller. */\n\n701 # Lim(_var, _tar, _dir, _exp)\n<-- Eval(ApplyPure(\"Subst\", {var, tar, exp}));\n\n\n/*  Limit without direction  */\n\n10 # Lim(_var, tar_IsInfinity, _exp) <-- Lim(var, tar, None, exp);\n\n20 # Lim(_var, _tar, _exp)\n<-- [\n  Local(l); l := Lim(var, tar, Left, exp);\n  If ( l = Lim(var, tar, Right, exp),\n       l,\n       Undefined\n     );\n];\n\n100 # LimInf(_var, _tar, _dir, Cos( _exp ))_IsInfinity(Lim(var,tar,dir,exp)) <-- -1;\n100 # LimInf(_var, _tar, _dir, Sin( _exp ))_IsInfinity(Lim(var,tar,dir,exp)) <-- -1;\n\n500 # LimInf(_var, _tar, _dir, _exp) <-- Lim(var,tar,dir,exp);\n\n100 # LimSup(_var, _tar, _dir, Cos( _exp ))_IsInfinity(Lim(var,tar,dir,exp)) <-- 1;\n100 # LimSup(_var, _tar, _dir, Sin( _exp ))_IsInfinity(Lim(var,tar,dir,exp)) <-- 1;\n\n500 # LimSup(_var, _tar, _dir, _exp) <-- Lim(var,tar,dir,exp);\n\n\n/* User-callable function */\n\n(Limit(_var,_lim)(_fie)) <-- [\n    Check(IsAtom(var) And Not(IsNumber(var)), \"Limit: \" : (ToString() Write(var)) : \" is not a valid variable\");\n    Lim(var,lim,fie);\n];\n\n(Limit(_var,_lim,_direction)(_fie)) <-- [\n    Check(IsAtom(var) And Not(IsNumber(var)), \"Limit: \" : (ToString() Write(var)) : \" is not a valid variable\");\n    Lim(var,lim,direction,fie);\n];\n\nUnFence(\"Limit\",3);\n"
  },
  {
    "path": "scripts/limit.rep/code.ys.def",
    "content": "Limit\n}\n"
  },
  {
    "path": "scripts/limit.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef(\"Limit\", \"limit1\",\"limit\",\n      {  _0, _2, OMS(\"limit1\", \"under\"), OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _4) }_(_3=Left)\n      |{ _0, _2, OMS(\"limit1\", \"above\"), OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _4) }_(_3=Right)\n      |{ _0, _2, OMS(\"limit1\", \"both_sides\"), OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _3) },\n      { _0, _{3,2,1}, _1, Left,  _{3,3}}_(_2=OMS(\"limit1\", \"below\"))\n      |{_0, _{3,2,1}, _1, Right, _{3,3}}_(_2=OMS(\"limit1\", \"above\"))\n      |{_0, _{3,2,1}, _1, _{3,3}}\n     );\n// Test [result Limit(x,0,Right)1/x]: FromString(ToString()OMForm(Limit(x,0,Right) 1/x))OMRead()\n\n// As explained in the manual, \"limit1:both_sides\" and \"fns1:lambda\" will\n// be handled as OMS(\"limit1\", \"both_sides\") and OMS(\"fns1\", \"lambda\"), so\n// we don't need to define bogus mappings for them:\n// OMDef(\"OMSymbolLimit1BothSides\", \"limit1\", \"both_sides\");\n// OMDef(\"OMSymbolLambda\", \"fns1\", \"lambda\");\n// The same applies to \"Left\" and \"Right\", which are undefined symbols\n// that are used only inside limit expressions, so they don't need a mapping\n// of their own.\n// We could define them as follows:\n//OMDef(\"Left\",  \"limit1\",\"below\");\n//OMDef(\"Right\", \"limit1\",\"above\");\n// and then use the following rules instead:\n//      {  _0, _2, Left,  OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _4) }_(_3=Left)\n//      |{ _0, _2, Right, OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _4) }_(_3=Right)\n//      |{ _0, _2, OMS(\"limit1\", \"both_sides\"), OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _3) },\n//      { _0, _{3,2,1}, _1, _2, _{3,3}}_(_2=Left Or _2=Right)\n//      |{_0, _{3,2,1}, _1, _{3,3}}\n// The result is exactly the same. The only difference is when producing the\n// OMForm of the symbols themselves, outside the limit expression.\n"
  },
  {
    "path": "scripts/linalg.rep/code.ys",
    "content": "50 # KroneckerDelta(i_IsInteger, j_IsInteger)_(i=j) <-- 1;\n50 # KroneckerDelta(i_IsInteger, j_IsInteger)_(i!=j) <-- 0;\n\n100 # KroneckerDelta(_i, _i) <-- 1;\n\n200 # KroneckerDelta(list_IsList) <-- If (Length(RemoveDuplicates(list))=1, 1, 0);\n\n/* Levi-civita symbol */\nFunction(\"LeviCivita\",{indices})\n[\n  Local(i,j,length,left,right,factor);\n  length:=Length(indices);\n  factor:=1;\n\n  For (j:=length,j>1,j--)\n  [\n    For(i:=1,i<j,i++)\n    [\n      left:=indices[i];\n      right:=indices[i+1];\n\n      If (Equals(left,right),\n      [ factor := 0 ; ],\n      [\n        If(Not(Apply(\"<\",{left,right})),\n        [\n/*\n          Swap(indices,i,i+1);\n*/\n          indices:=Insert(Delete(indices,i),i+1,left);\n          factor:= -factor;\n        ]);\n      ]);\n    ];\n  ];\n  factor;\n];\n\nFunction(\"Permutations\",{result,list})\n[\n  If (Length(list) = 0,\n  [\n    result;\n  ],\n  [\n    Local(head);\n    Local(newresult);\n    Local(i);\n    head:=list[1];\n    newresult:={};\n    ForEach(item,result)\n    [\n      For(i:=Length(item)+1,i>0,i--)\n      [\n        DestructiveInsert(newresult,1,Insert(item,i,head));\n      ];\n    ];\n    newresult:=DestructiveReverse(newresult);\n    Permutations(newresult,Tail(list));\n  ]);\n];\n\n\nFunction(\"Permutations\",{list})\n[\n  Permutations({{}},list);\n];\n\nFunction(\"InProduct\",{aLeft,aRight})\n[\n  Local(length);\n  length:=Length(aLeft);\n  Check(length = Length(aRight),\"InProduct: error, vectors not of the same dimension\");\n\n  Local(result);\n  result:=0;\n  Local(i);\n  For(i:=1,i<=length,i++)\n  [\n    result := result + aLeft[i] * aRight[i];\n  ];\n  result;\n];\n\n\nFunction(\"CrossProduct\",{aLeft,aRight})\n[\n  Local(length);\n  length:=Length(aLeft);\n  Check(length = 3,\"OutProduct: error, vectors not of dimension 3\");\n  Check(length = Length(aRight),\"OutProduct: error, vectors not of the same dimension\");\n\n  Local(perms);\n  perms := Permutations({1,2,3});\n\n  Local(result);\n  result:=ZeroVector(3);\n\n  Local(term);\n  ForEach(term,perms)\n  [\n    result[ term[1] ] := result[ term[1] ] +\n      LeviCivita(term) * aLeft[ term[2] ] * aRight[ term[3] ] ;\n  ];\n  result;\n];\n\n\n_x o _y <-- Outer(x,y);\n\n// outer product of vectors\nOuter(t1_IsVector, t2_IsVector) <--\n[\n   Local(i,j,n,m,result);\n   n:=Length(t1);\n   m:=Length(t2);\n   result:=ZeroMatrix(n,m);\n   For(i:=1,i<=n,i++)\n      For(j:=1,j<=m,j++)\n\t result[i][j]:=t1[i]*t2[j];\n   result;\n];\n\n\n\nFunction(\"ZeroVector\",{n})\n[\n    Local(i,result);\n    result:={};\n    For(i:=1,i<=n,i++)\n    [\n      DestructiveInsert(result,1,0);\n    ];\n    result;\n];\n\n\nFunction(\"BaseVector\",{row,n})\n[\n    Local(i,result);\n    result:=ZeroVector(n);\n    result[row] := 1;\n    result;\n];\n\nRandomIntegerVector(_count,_coefmin,_coefmax) <--\n  Table(MathFloor(coefmin+Random()*(coefmax+1-coefmin)),i,1,count,1);\n\nRandomIntegerMatrix(_rows,_cols,_coefmin,_coefmax) <--\n\tGenMatrix({{i,j}, MathFloor(coefmin+Random()*(coefmax+1-coefmin))}, rows, cols );\n\n\nIdentity(n_IsNonNegativeInteger) <--\n[\n    Local(i,result);\n    result:={};\n    For(i:=1,i<=n,i++)\n    [\n      DestructiveAppend(result,BaseVector(i,n));\n    ];\n    result;\n];\n\n//\n// Diagonal: return a vector with the diagonal elements of the matrix\n//\nFunction(\"Diagonal\",{A})\n[\n\tLocal(result,i,n);\n\tn:=Length(A);\n\tresult:=ZeroVector(n);\n\tFor(i:=1,i<=n,i++)\n\t[\n\t\tresult[i] := A[i][i];\n\t];\n\tresult;\n];\n\nFunction(\"DiagonalMatrix\",{list})\n[\n  Local(result,i,n);\n  n:=Length(list);\n  result:=Identity(n);\n  For(i:=1,i<=n,i++)\n  [\n    result[i][i] := list[i];\n  ];\n  result;\n];\n\nFunction(\"Normalize\",{vector})\n[\n  Local(norm);\n  norm:=0;\n  ForEach(item,vector)\n  [\n    norm:=norm+item*item;\n  ];\n  (1/(norm^(1/2)))*vector;\n];\n\n5  # ZeroMatrix(n_IsNonNegativeInteger) <--  ZeroMatrix(n,n);\n10 # ZeroMatrix(n_IsNonNegativeInteger,m_IsNonNegativeInteger) <--\n[\n  Local(i,result);\n  result:={};\n  For(i:=1,i<=n,i++)\n    DestructiveInsert(result,i,ZeroVector(m));\n  result;\n];\n\n\nTranspose(matrix_IsList)_(Length(Dimensions(matrix))>1) <--\n[\n  Local(i,j,result);\n  result:=ZeroMatrix(Length(matrix[1]),Length(matrix));\n  For(i:=1,i<=Length(matrix),i++)\n    For(j:=1,j<=Length(matrix[1]),j++)\n      result[j][i]:=matrix[i][j];\n  result;\n];\n\nFrobeniusNorm(matrix_IsMatrix) <--\n[\n\tLocal(i,j,result);\n\tresult:=0;\n\tFor(i:=1,i<=Length(matrix),i++)\n\t\tFor(j:=1,j<=Length(matrix[1]),j++)\n\t\t\tresult:=result+Abs(matrix[i][j])^2;\n\n\tSqrt(result);\n\n];\n\n\n10 # Determinant(_matrix)_(IsUpperTriangular(matrix) Or IsLowerTriangular(matrix)) <--\n[\n\tLocal(result);\n\tresult:=1;\n\tForEach(i, Diagonal(matrix) )\n\t\tresult:=result*i;\n\tresult;\n];\n\n//\n// The fast determinant routine that does the determinant numerically, rule 20,\n// divides things by the elements on the diagonal of the matrix. So if one of these\n// elements happens to be zero, the result is something like Infinity or Undefined.\n// Use the symbolic determinant in that case, as it is slower but much more robust.\n//\n15 # Determinant(_matrix)_(Length(Select(\"IsZero\",Diagonal(matrix))) > 0) <-- SymbolicDeterminant(matrix);\n\n// Not numeric entries, so lets treat it symbolically.\n16 # Determinant(_matrix)_(VarList(matrix) != {}) <-- SymbolicDeterminant(matrix);\n\n20 # Determinant(_matrix) <-- GaussianDeterminant(matrix);\n\nGaussianDeterminant(matrix):=\n[\n  Local(n,s,result);\n  n:=Length(matrix);\n\tresult:=1;\n\n  [\n    matrix:=FlatCopy(matrix);\n    Local(i);\n    For(i:=1,i<=n,i++)\n    [\n      matrix[i]:=FlatCopy(matrix[i]);\n    ];\n  ];\n\n  // gaussian elimination\n  For(i:=1,i<n,i++)\n  [\n    For(k:=(i+1),k<=n,k++)\n    [\n      s:=matrix[k][i];\n      For(j:=i,j<=n,j++)\n      [\n        matrix[k][j] := matrix[k][j] - (s/matrix[i][i])*matrix[i][j];\n        //Echo({\"matrix[\",k,\"][\",j,\"] =\", aug[k][j],\" - \",\n        //      matrix[k][i],\"/\",matrix[i][i],\"*\",matrix[i][j],\" k i =\", k,i  });\n      ];\n    ];\n  ];\n\n//Echo(\"mat: \",matrix);\n//Echo(\"diagmat: \",Diagonal(matrix));\n\t// now upper triangular\n  ForEach(i, Diagonal(matrix) )\n    result:=result*i;\n  result;\n];\n\n/* Recursive calculation of determinant, provided by Sebastian Ferraro\n */\n20 # RecursiveDeterminant(_matrix) <--\n[\n  /*\n  Computes a determinant recursively by summing the product of each (nonzero) element on the first row of the matrix\n  by +/- the determinant of the submatrix with the corresponding row and column deleted.\n  */\n  Local(result);\n  If(Equals(Length(matrix),1),matrix[1][1],[\n    result:=0;\n    For(i:=1,i <= Length(matrix),i++)\n      //Consider only non-zero entries\n      If(Not(Equals(matrix[1][i],0)),\n        //Transpose and Drop eliminate row 1, column i\n        result:=result+matrix[1][i]*(-1)^(i+1)* RecursiveDeterminant(Transpose(Drop(Transpose(Drop(matrix,{1,1})),{i,i}))));\n    result;\n  ]);\n];\n\n\n20 # SymbolicDeterminant(_matrix) <-- LocalSymbols(i) [\n    Local(i,perms,indices,result);\n    Check((IsMatrix(matrix)),\"Determinant: Argument must be a matrix\");\n    indices:=Table(i,i,1,Length(matrix),1);\n    perms:=Permutations(indices);\n    result:=0;\n    ForEach(item,perms)\n        result:=result+Product(i,1,Length(matrix),matrix[i][item[i] ]) * LeviCivita(item);\n    result;\n];\n\n\n\nFunction(\"Sparsity\",{matrix})\n[\n\tLocal(rows,cols,nonzero);\n\tnonzero:=0;\n\trows:=Length(matrix);\n\tcols:=Length(matrix[1]);\n\tFor(i:=1,i<=rows,i++)\n\t\tFor(j:=1,j <= cols,j++)\n\t\t\tIf(matrix[i][j] != 0, nonzero:=nonzero+1 );\n\n\tN(1 - nonzero/(rows*cols));\n];\n\nFunction(\"CoFactor\",{matrix,ii,jj})\n[\n    Local(perms,indices,result);\n    indices:=Table(i,i,1,Length(matrix),1);\n    perms:=Permutations(indices);\n    result:=0;\n    ForEach(item,perms)\n        If(item[ii] = jj, [\n            Local(i, t);\n            t := 1;\n            For (i := 1, i <= Length(matrix), i++)\n                t := t * If(ii=i,1,matrix[i][item[i]]);\n            result := result + t * LeviCivita(item);\n        ]);\n    result;\n];\n\n\n\nMinor(matrix,i,j) := CoFactor(matrix,i,j)*(-1)^(i+j);\n\n10 # Inverse(A_IsDiagonal) <--\n[\n\tLocal(i,n,Inv);\n\tn:=Length(A);\n\tInv:=Identity(n);\n\n        For(i:=1,i<=n,i++)\n        \tInv[i][i] := 1/A[i][i];\n\tInv;\n];\n\n50 # Inverse(A_IsLowerTriangular) <--\n[\n\tLocal(i,m,n,l,Inv);\n\tl:=Length(A);\n\tInv:=ZeroMatrix(l,l);\n\n\tFor(m:=1,m <= l,m++)\n\t\tFor(n:=1, n <= m,n++)\n\t\t\tInv[m][n] := (KroneckerDelta(m, n) - Sum(i, 1, m-1, A[m][i] * Inv[i][n])) / A[m][m];\n\n\tInv;\n];\n\n50 # Inverse(A_IsUpperTriangular) <--\n[\n\tLocal(i,m,n,l,Inv);\n\tl:=Length(A);\n\tInv:=ZeroMatrix(l,l);\n\n\tFor(m:=l,1 <= m,m--)\n\t\tFor(n:=m,n <= l,n++)\n\t\t\tInv[m][n] := (KroneckerDelta(m, n) - Sum(i, m + 1, l, A[m][i] * Inv[i][n])) / A[m][m];\n\n\tInv;\n];\n\n// Inverse by PLDU decomposition  (PA = LDU) => (A^-1 = U^-1 D^-1 L^-1 P)\n100 # Inverse(A_IsSquareMatrix) <--\n[\n\tLocal(P,L,D,U,InvU,InvD,InvL,Inv,n,i,j,k,l);\n\t{P,L,D,U} := PLDU(A);\n\tInvU:=Inverse(U);\n\tInvD:=Diagonal(Inverse(D));\n\tInvL:=Inverse(L);\n\n\tn := Length(A);\n\tInv:=ZeroMatrix(n,n);\n\n\tFor (i := 1, i <= n, i++)\n\t\tFor (j := 1, j <= n, j++)\n\t\t\tFor (k := i, k <= n, k++)\n\t\t\t\tFor (l := 1, l <= k, l++)\n\t\t\t\t\tIf (P[l][j] = 1,\n\t\t\t\t\t\tInv[i][j] := Inv[i][j] +  InvU[i][k] * InvD[k] * InvL[k][l]);\n\tInv;\n];\n\nTr(x_IsList) <--\n[\n   Local(i,j,n,d,r,aux,result);\n   d:=Dimensions(x);\n   r:=Length(d); // tensor rank\n   n:=Min(d);    // minimal dim\n   result:=0;\n   For(i:=1,i<=n,i++)\n   [\n      aux:=x[i];\n      For(j:=2,j<=r,j++)\n\t aux:=aux[i];\n      result:=result+aux;\n   ];\n   result;\n];\n\n\nTrace(matrix_IsList) <-- Tr(matrix);\n\n\nx X y := CrossProduct(x,y);\n\nFunction(\"VandermondeMatrix\",{vector})[\n\tLocal(len,i,j,item,matrix);\n\tlen:=Length(vector);\n\tmatrix:=ZeroMatrix(len,len);\n\n\tFor(i:=1,i<=Length(matrix),i++)[\n\t\tFor(j:=1,j<=Length(matrix[1]),j++)[\n      \t\t\tmatrix[j][i]:=vector[i]^(j-1);\n\t\t];\n\t];\n\n\tmatrix;\n];\n\n/* SylvesterMatrix */\n\nFunction(\"SylvesterMatrix\",{poly1, poly2, var})\n[\n  Local(i,m,p,q,y,z,result);\n  y:=Degree(poly1,var);\n  z:=Degree(poly2,var);\n  m:=y+z;\n  p:={};\n  q:={};\n  result:=ZeroMatrix(m,m);\n\n  For(i:=y,0 <= i,i--)\n    DestructiveAppend(p,Coef(poly1,var,i));\n  For(i:=z,0 <= i,i--)\n    DestructiveAppend(q,Coef(poly2,var,i));\n\n  For(i:=1,i<=z,i++)\n  [\n    Local(j,k);\n        k:=1;\n    For(j:=i,k<=Length(p),j++)\n        [\n          result[i][j]:=p[k];\n          k++;\n        ];\n  ];\n\n  For(i:=1,i<=y,i++)\n  [\n    Local(j,k);\n        k:=1;\n    For(j:=i,k<=Length(q),j++)\n        [\n          result[i+z][j]:=q[k];\n          k++;\n        ];\n  ];\n  result;\n];\n\n\n\nFunction(\"MatrixRow\",{matrix,row})\n[\n  Check(row > 0, \"MatrixRow: row index out of range\");\n  Check(row <= Length(matrix), \"MatrixRow: row index out of range\");\n\n  Local(result);\n  result:=matrix[row];\n\n  result;\n];\n\nFunction(\"MatrixColumn\",{matrix,col})\n[\n  Local(m);\n  m:=matrix[1];\n\n  Check(col > 0, \"MatrixColumn: column index out of range\");\n  Check(col <= Length(m), \"MatrixColumn: column index out of range\");\n\n  Local(i,result);\n  result:={};\n  For(i:=1,i<=Length(matrix),i++)\n    DestructiveAppend(result,matrix[i][col]);\n\n  result;\n];\n\nFunction(\"GenMatrix\",{func,m,n})\n[\n  Local(i,j,result);\n  result:=ZeroMatrix(m,n);\n\n  For(i:=1,i<=m,i++)\n    For(j:=1,j<=n,j++)\n          result[i][j]:=ApplyPure(func,{i,j});\n\n  result;\n];\nHoldArg(\"GenMatrix\",func);\nUnFence(\"GenMatrix\",3);\n\n// The arguments of the following functions\n// should be checked\n\n// this takes N funcs in N vars\nJacobianMatrix(f,v):=GenMatrix({{i,j},Deriv(v[j])f[i]},Length(f),Length(v));\n\n// this takes 1 func in N vars\nHessianMatrix(f,v):=GenMatrix({{i,j}, Deriv(v[i]) Deriv(v[j]) f},Length(v),Length(v));\n\n// this takes N funcs in 1 var\nWronskianMatrix(f,v):=GenMatrix({{i,j}, Deriv(v,i-1) f[j]}, Length(f), Length(f) );\n\n// notoriously hard to manipulate numerically\nHilbertMatrix(n):=GenMatrix({{i,j}, 1/(i+j-1)}, n,n );\nHilbertMatrix(m,n):=GenMatrix({{i,j}, 1/(i+j-1)}, m,n );\nHilbertInverseMatrix(n):=GenMatrix({{i,j},\n\t(-1)^(i+j)*(i+j-1)*Bin(n+i-1,n-j)*Bin(n+j-1,n-i)*Bin(i+j-2,i-1)^2},n,n);\n\nHankelMatrix(n):=GenMatrix({{i,j}, If(i+j-1>n,0,i+j-1) }, n,n );\nHankelMatrix(m,n):=GenMatrix({{i,j}, If(i+j-1>n,0,i+j-1)}, m,n );\n\nToeplitzMatrix(N):=GenMatrix({{i,j},N[Abs(i-j)+1]}, Length(N), Length(N) );\n\n// Used to test numerical eigenvalue algorithms, because it\n// has eigenvalues extremely close to each other.\n// WilkinsonMatrix(21) has 2 eigenvalues near 10.7 that agree\n// to 14 decimal places\n// Leto: I am not going to document this until we actually have\n// numerical eigenvalue algorithms\nWilkinsonMatrix(N):=GenMatrix({{i,j},\n\t\tIf( Abs(i-j)=1,1,\n\t\t[ If(i=j,Abs( (N-1)/2 - i+1 ),0 ); ] )}, N,N );\n\n10 # Norm(_v) <-- PNorm(v,2);\n\n// p-norm, reduces to euclidean norm when p = 2\nFunction(\"PNorm\",{v,p})\n[\n\tLocal(result,i);\n\tCheck(p>=1,\"PNorm: p must be >= 1\");\n\n\tresult:=0;\n\tFor(i:=1,i<=Length(v),i++)[\n\t\tresult:=result+Abs(v[i])^p;\n\t];\n\n\t// make it look nicer when p = 2\n\tIf(p=2,Sqrt(result),(result)^(1/p) );\n];\n\n// This is the standard textbook definition of the Gram-Schmidt\n// Orthogonalization process, from:\n// Friedberg,Insel,Spence \"Linear Algebra\"  (1997)\n// TODO: This function does not check if the input vectors are LI, it\n// only checks for zero vectors\nFunction(\"OrthogonalBasis\",{W})[\n\tLocal(V,j,k);\n\n\tV:=ZeroMatrix(Length(W),Length(W[1]) );\n\n\tV[1]:=W[1];\n\tFor(k:=2,k<=Length(W),k++)[\n\t\tCheck(Not IsZero(Norm(W[k])) ,\n\t\t\t\"OrthogonalBasis: Input vectors must be linearly independent\");\n\t\tV[k]:=W[k]-Sum(j,1,k-1,InProduct(W[k],V[j])*V[j]/Norm(V[j])^2);\n\t];\n\tV;\n];\n// Like orthogonalization, only normalize all vectors\nFunction(\"OrthonormalBasis\",{W})[\n\tLocal(i);\n\tW:=OrthogonalBasis(W);\n\tFor(i:=1,i<=Length(W),i++)[\n\t\tW[i]:=W[i]/Norm(W[i]);\n\t];\n\tW;\n];\n\n\n/* Code that returns the list of the dimensions of a tensor\n   Code submitted by Dirk Reusch.\n */\n\nLocalSymbols(x,i,n,m,aux,dim,result)\n[\n1 # Dimensions(x_IsList) <--\n    [\n      Local(i,n,m,aux,dim,result);\n      result:=List(Length(x));\n//Echo(\"GETTING \",x);\n//Echo(Length(Select(IsList,x)));\n//Echo(\"END\");\n      If(Length(x)>0 And Length(Select(IsList,x))=Length(x),\n      [\n        n:=Length(x);\n\tdim:=MapSingle(Dimensions,x);\n\tm:=Min(MapSingle(Length,dim));\n\n\tFor(i:=1,i<=m,i++)\n\t[\n\t    aux:=Table(dim[j][i],j,1,n,1);\n\t    If(Min(aux)=Max(aux),\n\t    result:=DestructiveAppend(result,dim[1][i]),\n\t    i:=m+1);\n        ];\n      ]);\n//Echo(x,result);\n      result;\n    ];\n\n2 # Dimensions(_x) <-- List();\n];\n\n//////\n//////\n\n//////\n// dot product for vectors and matrices (dr)\n//////\n\n_x . _y <-- Dot(x,y);\n\nLocalSymbols(Dot0,Dot1)\n[\n// vector . vector\nDot(t1_IsVector,t2_IsVector)_(Length(t1)=Length(t2)) <--\n   Dot0(t1,t2,Length(t1));\n\n// matrix . vector\nDot(t1_IsMatrix,t2_IsVector)_(Length(t1[1])=Length(t2)) <--\n[\n   Local(i,n,m,result);\n   n:=Length(t1);\n   m:=Length(t2);\n   result:=List();\n   For(i:=1,i<=n,i++)\n\tDestructiveInsert(result,1,Dot0(t1[i],t2,m));\n   DestructiveReverse(result);\n];\n\n// vector . matrix\nDot(t1_IsVector,t2_IsMatrix)_(Length(t1)=Length(t2)\n                               And Length(t2[1])>0) <--\n   Dot1(t1,t2,Length(t1),Length(t2[1]));\n\n// matrix . matrix\nDot(t1_IsMatrix,t2_IsMatrix)_(Length(t1[1])=Length(t2)\n                                  And Length(t2[1])>0) <--\n[\n   Local(i,n,k,l,result);\n   n:=Length(t1);\n   k:=Length(t2);\n   l:=Length(t2[1]);\n   result:=List();\n   For(i:=1,i<=n,i++)\n      DestructiveInsert(result,1,Dot1(t1[i],t2,k,l));\n   DestructiveReverse(result);\n];\n\n// vector . vector\nDot0(_t1,_t2,_n) <--\n[\n   Local(i,result);\n   result:=0;\n   For(i:=1,i<=n,i++)\n      result:=result+t1[i]*t2[i];\n   result;\n];\n\n// vector . matrix\n// m vector length\n// n number of matrix cols\nDot1(_t1,_t2,_m,_n) <--\n[\n   Local(i,j,result);\n   result:=ZeroVector(n);\n   For(i:=1,i<=n,i++)\n      For(j:=1,j<=m,j++)\n         result[i]:=result[i]+t1[j]*t2[j][i];\n   result;\n];\n\n]; // LocalSymbols(Dot0,Dot1)\n\n//////\n//////\n\n//////\n// power of a matrix (dr)\n//////\n\nMatrixPower(x_IsSquareMatrix, n_IsNonNegativeInteger) <--\n[\n   Local(result);\n   result:=Identity(Length(x));\n   While(n != 0)\n   [\n      If(IsOdd(n),\n         result:=Dot(result,x));\n      x:=Dot(x,x);\n      n:=n>>1;\n   ];\n   result;\n];\n\nMatrixPower(x_IsSquareMatrix, n_IsNegativeInteger) <--\n   MatrixPower(Inverse(x),-n);\n\n//////\n//////\n10 # MatrixSolve(matrix_IsDiagonal,b_IsVector) <--\n[\n\tLocal(rowsm,rowsb,x);\n        rowsm:=Length(matrix);\n\trowsb:=Length(b);\n\tCheck(rowsm=rowsb,\"MatrixSolve: Matrix and vector must have same number of rows\");\n\tx:=ZeroVector(rowsb);\n\tFor(i:=1,i <= rowsb,i++)\n\t\tx[i]:=b[i]/matrix[i][i];\n\tx;\n];\n\n// Backward Substitution\n15 # MatrixSolve(matrix_IsUpperTriangular,b_IsVector) <--\n[\n        Local(rowsm,rowsb,x,s);\n        rowsm:=Length(matrix);\n        rowsb:=Length(b);\n        Check(rowsm=rowsb,\"MatrixSolve: Matrix and vector must have same number of rows\");\n        x:=ZeroVector(rowsb);\n\n\tx[rowsb]:=b[rowsb]/matrix[rowsb][rowsb];\n\tIf(InVerboseMode(),Echo({\"set x[\",rowsb,\"] = \",b[rowsb]/matrix[rowsb][rowsb]}));\n\n\tFor(i:=(rowsb-1),1 <= i ,i--)[\n\t\ts:=b[i];\n\t\tFor(j:=i+1, j <= rowsb, j++ )[\n\t\t\ts:= s - matrix[i][j]*x[j];\n\t\t];\n\t\tx[i]:= s/matrix[i][i];\n\t\tIf(InVerboseMode(),Echo({\"set x[\",i,\"] = \",s/matrix[i][i]}));\n\t];\n        x;\n];\n\n// Forward Substitution\n15 # MatrixSolve(matrix_IsLowerTriangular,b_IsVector) <--\n[\n\tLocal(rowsm,rowsb,x,s);\n\trowsm:=Length(matrix);\n\trowsb:=Length(b);\n\tCheck(rowsm=rowsb,\"MatrixSolve: Matrix and vector must have same number of rows\");\n\tx:=ZeroVector(rowsb);\n\n\tx[1]:=b[1]/matrix[1][1];\n\tIf(InVerboseMode(),Echo({\"set x[1] = \",b[1]/matrix[1][1]}));\n\n\tFor(i:=2,i <= rowsb, i++ )[\n\t\ts:=b[i];\n\t\tFor(j:=1, j < i, j++ )[\n\t\t\ts:= s - matrix[i][j]*x[j];\n\t\t];\n\t\tx[i]:= s/matrix[i][i];\n\t\tIf(InVerboseMode(),Echo({\"set x[\",i,\"] = \",s/matrix[i][i]}));\n\t];\n\tx;\n];\n// Gaussian Elimination and Back Substitution\n// pivoting not implemented yet\n20 # MatrixSolve(matrix_IsMatrix,b_IsVector) <--\n[\n\tLocal(aug,rowsm,rowsb,x,s);\n        rowsm:=Length(matrix);\n        rowsb:=Length(b);\n        Check(rowsm=rowsb,\"MatrixSolve: Matrix and vector must have same number of rows\");\n        aug:=ZeroMatrix(rowsb,rowsb+1);\n\tx:=ZeroVector(rowsb);\n\n\t// create augmented matrix\n\tFor(i:=1,i <= rowsb,i++)\n\t\tFor(j:=1, j <= rowsb,j++)\n\t\t\taug[i][j] := matrix[i][j];\n\tFor(i:=1, i <= rowsb, i++)\n\t\taug[i][rowsb+1] := b[i];\n\n\t// gaussian elimination\n\tFor(i:=1, i < rowsb, i++ )[\n\t\t// If our pivot element is 0 we need to switch\n\t\t// this row with a row that has a nonzero element\n\t\tIf(aug[i][i] = 0, [\n\t\t\tLocal(p,tmp);\n\t\t\tp:=i+1;\n\t\t\tWhile( aug[p][p] = 0 )[ p++; ];\n\t\t\tIf(InVerboseMode(), Echo({\"switching row \",i,\"with \",p}) );\n\t\t\ttmp:=aug[i];\n\t\t\taug[i]:=aug[p];\n\t\t\taug[p]:=tmp;\n\t\t]);\n\n\n\t\tFor(k:=(i+1), k <= rowsb, k++ )[\n\t\t\ts:=aug[k][i];\n\t\t\tFor(j:=i, j <= (rowsb+1), j++ )[\n\t\t\t\taug[k][j] := aug[k][j] - (s/aug[i][i])*aug[i][j];\n\t\t\t\t//Echo({\"aug[\",k,\"][\",j,\"] =\", aug[k][j],\" - \",\n\t\t\t\t//\taug[k][i],\"/\",aug[i][i],\"*\",aug[i][j],\" k i =\", k,i  });\n\t\t\t];\n\t\t];\n\t];\n\t//PrettyForm(aug);\n\tx[rowsb]:=aug[rowsb][rowsb+1]/aug[rowsb][rowsb];\n\tIf(InVerboseMode(),Echo({\"set x[\",rowsb,\"] = \",x[rowsb] }));\n\n\tFor(i:=(rowsb-1), 1 <= i,i--)[\n\t\ts:=aug[i][rowsb+1];\n\t\tFor(j:=i+1, j <= rowsb, j++)[\n\t\t\ts := s - aug[i][j]*x[j];\n\t\t];\n\t\tx[i]:=s/aug[i][i];\n\t\tIf(InVerboseMode(),Echo({\"set x[\",i,\"] = \",x[i] }));\n\t];\n\tx;\n\n];\n\n// Cholesky Decomposition, adapted from:\n//\tFundamentals Of Matrix Computation (2nd), David S. Watkins, pp38\n// This algorithm performs O(n^3) flops where A is nxn\n// Given the positive definite matrix A, a matrix R is returned such that\n// A = Transpose(R) * R\n\n10 # Cholesky(A_IsMatrix) <--\n[\n\tLocal(matrix,n,k,j);\n\tn:=Length(A);\n\tmatrix:=ZeroMatrix(n);\n\n\t// copy entries of A into matrix\n        For(i:=1, i <= n, i++ )\n                For(j:=1, j <= n,j++)\n\t\t\tmatrix[i][j] := A[i][j];\n\n\t// in place algorithm for cholesky decomp\n\tFor(i:=1, i <= n, i++)[\n\t\tFor(k:=1, k < i ,k++)\n\t\t\tmatrix[i][i] := matrix[i][i] - matrix[k][i]^2;\n\t\tCheck( matrix[i][i] > 0, \"Cholesky: Matrix is not positive definite\");\n\t\tmatrix[i][i] := Sqrt(matrix[i][i]);\n\t\t//Echo({\"matrix[\",i,\"][\",i,\"] = \", matrix[i][i] });\n\t\tFor(j:=i+1,j<=n,j++)[\n\t\t\tFor(k:=1, k < i ,k++)\n\t\t\t\tmatrix[i][j]:= matrix[i][j] - matrix[k][i]*matrix[k][j];\n\t\t\tmatrix[i][j] := matrix[i][j]/matrix[i][i];\n\t\t\t//Echo({\"matrix[\",i,\"][\",j,\"] = \", matrix[i][j] });\n\t\t];\n\t];\n\t// cholesky factorization is upper triangular\n\tFor(i:=1, i <= n, i++)\n\t\tFor(j:= 1, j <= n, j++)\n\t\t\tIf(i>j,matrix[i][j] := 0);\n\tmatrix;\n];\n\n// In place LU decomposition\n// Pivotting is not implemented\n// Adapted from Numerical Methods with Matlab\n//\tGerald Recktenwald, Sec 8.4\n10 # LU(A_IsSquareMatrix) <--\n[\n\tLocal(n,matrix,L,U);\n\tn:=Length(A);\n\tL:=ZeroMatrix(n,n);\n\tU:=ZeroMatrix(n,n);\n\tmatrix:=ZeroMatrix(n,n);\n\n        For(i:=1, i <= n, i++)\n                For(j:=1,j <= n,j++)\n                        matrix[i][j] := A[i][j];\n\n\t// loop over pivot rows\n\tFor(i:=1, i < n, i++)[\n\t\t// loop over column below the pivot\n\t\tFor(k:=i+1, k <= n, k++)[\n\t\t\t// compute multiplier and store it in L\n\t\t\tmatrix[k][i] := matrix[k][i] / matrix[i][i];\n\t\t\t// loop over elements in row k\n\t\t\tFor(j:=i+1,j<=n,j++)[\n\t\t\t\tmatrix[k][j] := matrix[k][j] - matrix[k][i]*matrix[i][j];\n\t\t\t];\n\t\t];\n\t];\n\tFor(i:=1,i <= n, i++)[\n\t\tFor(j:=1, j <= n, j++)[\n\t\t\tIf(i<=j,U[i][j]:=matrix[i][j],L[i][j]:=matrix[i][j]);\n\t\t];\n\t\t// diagonal of L is always 1's\n\t\tL[i][i]:=1;\n\t];\n\n\t{L,U};\n];\n\n// In place LDU decomposition such as A=LDU\n// Pivotting is not implemented\n// Adapted from Numerical Methods with Matlab\n//\thttp://www4.ncsu.edu/~kksivara/ma505/handouts/lu-pivot.pdf\n10 # LDU(A_IsSquareMatrix) <--\n[\n\tLocal(n,matrix,L,D,U);\n\tn:=Length(A);\n\tL:=ZeroMatrix(n,n);\n\tD:=ZeroMatrix(n,n);\n\tU:=ZeroMatrix(n,n);\n\tmatrix:=ZeroMatrix(n,n);\n\n        For(i:=1, i <= n, i++)\n                For(j:=1, j <=n, j++)\n                        matrix[i][j] := A[i][j];\n\n\t// loop over pivot rows\n\tFor(i:=1, i < n, i++)[\n\t\t// loop over column below the pivot\n\t\tFor(k:=i+1,k <= n, k++)[\n\t\t\t// compute multiplier and store it in L\n\t\t\tmatrix[k][i] := matrix[k][i] / matrix[i][i];\n\t\t\t// loop over elements in row k\n\t\t\tFor(j:=i+1,j <= n,j++)\n\t\t\t\tmatrix[k][j] := matrix[k][j] - matrix[k][i]*matrix[i][j];\n\t\t];\n\t\t// in place normalise the i-th row of U\n\t\tFor(j:=i+1, j<= n,j++)\n\t\t\tmatrix[i][j] := matrix[i][j] / matrix[i][i];\n\t];\n\tFor(i:=1,i <= n, i++)[\n\t\tFor(j:=1, j <= n, j++)\n\t\t\tIf(i<j,\n\t\t\t\tU[i][j]:=matrix[i][j],\n\t\t\t\tIf (i=j,\n\t\t\t\t\tD[i][j]:=matrix[i][j],\n\t\t\t\t\t\tL[i][j]:=matrix[i][j]));\n\t\t// diagonal of L, U is always 1's\n\t\tL[i][i]:=1;\n\t\tU[i][i]:=1;\n\t];\n\t{L,D,U};\n];\n\n// In place pivoted LDU decomposition such as PA=LDU\n// Adapted from the algorithm in Page 160 of\n//  http://www4.ncsu.edu/~kksivara/ma505/handouts/lu-pivot.pdf\n10 # PLDU(A_IsSquareMatrix) <--\n[\n\tLocal(n,matrix,P,L,D,U);\n\tn:=Length(A);\n\tP:=Identity(n);\n\tL:=ZeroMatrix(n,n);\n\tD:=ZeroMatrix(n,n);\n\tU:=ZeroMatrix(n,n);\n\tmatrix:=ZeroMatrix(n,n);\n\n        For(i:=1, i <=n, i++)\n                For(j:=1, j <= n, j++)\n                        matrix[i][j] := A[i][j];\n\n\t// loop over pivot rows\n\tFor(i:=1, i < n, i++)[\n\t\t// look for the max number in the column below (i,i)\n\t\tj:=i;\n\t\tIf(matrix[i][i]=0,\n\t\t\tFor(k:=i+1, k <= n, k++)\n\t\t\t\tIf(Not(matrix[k][i]=0), j:=k)\n\t\t);\n\t\tIf(j>i, [\n\t\t   // swap the rows i and j\n\t\t   For(k:=1, k <= n, k++) [\n\t\t\ttmp:= matrix[i][k];\n\t\t\tmatrix[i][k]:= matrix[j][k];\n\t\t\tmatrix[j][k]:= tmp;\n\t\t\ttmp:= P[i][k];\n\t\t\tP[i][k]:= P[j][k];\n\t\t\tP[j][k]:= tmp;\n\t\t   ];\n\t\t]);\n\t\t// loop over column below the pivot\n\t\tFor(k:=i+1, k <= n, k++)[\n\t\t\t// compute multiplier and store it in L\n\t\t\tmatrix[k][i] := matrix[k][i] / matrix[i][i];\n\t\t\t// loop over elements in row k\n\t\t\tFor(j:=i+1, j <= n, j++)\n\t\t\t\tmatrix[k][j] := matrix[k][j] - matrix[k][i]*matrix[i][j];\n\t\t];\n\t\t// in place normalise the i-th row of U\n\t\tFor(j:=i+1, j <= n, j++)\n\t\t\tmatrix[i][j] := matrix[i][j] / matrix[i][i];\n\t];\n\tFor(i:=1, i <= n, i++)[\n\t\tFor(j:=1, j <= n, j++)\n\t\t\tIf(i<j,\n\t\t\t\tU[i][j]:=matrix[i][j],\n\t\t\t\tIf (i=j,\n\t\t\t\t\tD[i][j]:=matrix[i][j],\n\t\t\t\t\t\tL[i][j]:=matrix[i][j]));\n\t\t// diagonal of L, U is always 1's\n\t\tL[i][i]:=1;\n\t\tU[i][i]:=1;\n\t];\n\t//PrettyForm(P);\n\t//PrettyForm(L);\n\t//PrettyForm(D);\n\t//PrettyForm(U);\n\t{P,L,D,U};\n];\n\n//\n// DAG: (p = Pp + c) => (p = P'x + c') where P' is a lower triangular matrix\n// risks vectorR = vectorP * vectorI\n//\n10 # DAG(matrixP_IsSquareMatrix, vectorI_IsVector) <--\n[\n\tLocal(i,j,n,diagonals,\n\t\tvectorP,vectorP1,vectorC,vectorR,\n\t\tmatrixI,matrixX,matrixM,matrixL,matrixD,matrixU,matrixJ,matrixLL,matrixM1,matrixB,matrixInvM,matrixInvU,matrixInvD,matrixInvL,matrixInv);\n\tn:=Length(matrixP);\n\tmatrixI:=Identity(n);\n\tvectorC:=matrixI[1];\n\tvectorR:=ZeroVector(n);\n\tmatrixJ:=ZeroMatrix(n,n);\n        For(i:=1, i <=n, i++) matrixJ[i][n+1-i]:=1; // J is the anti-identity matrix\n\tmatrixX:=matrixJ*(matrixI-matrixP)*matrixJ; \t\t\t\t// PrettyForm(matrixX);\n\tEcho(\"...PLDU\");\n\t{matrixM,matrixL,matrixD,matrixU} := PLDU(matrixX); \t\t\t// PrettyForm(matrixM*matrixX); PrettyForm(matrixL*matrixD*matrixU);\n\tEcho(\".\");\n\tdiagonals:=True; For(i:=1, i <= n, i++) diagonals:=diagonals And (matrixD[i][i]>0);\t\n\tEcho(\"...InvD\");\n\tmatrixInvD:=Inverse(matrixJ*matrixD*matrixJ); \t\t\t\t// PrettyForm(matrixInvD);\n\tEcho(\".\");\n\tEcho(\"...InvU\");\n\tmatrixInvU:=Inverse(matrixJ*matrixL*matrixJ); \t\t\t\t// PrettyForm(matrixInvU);\n\tEcho(\".\");\n\tEcho(\"...InvM\");\n\tmatrixInvM:=Transpose(matrixJ*matrixM*matrixJ); \t\t\t// PrettyForm(matrixInvM);\n\tEcho(\".\");\n\tmatrixLL:=matrixJ*matrixU*matrixJ; \t\t\t\t\t// PrettyForm(matrixLL);\n\tEcho(\"...InvL\");\n\tmatrixInvL:=Inverse(matrixLL); \t\t\t\t\t\t// PrettyForm(matrixLL*matrixInvL);\n\tEcho(\".\");\n\tEcho(\"...L'\");\n\tmatrixP1:=matrixI - matrixLL; \t\t\t\t\t\t// PrettyForm(matrixP1);\n\tEcho(\".\");\n\tEcho(\"...DUM\");\n\tmatrixB:=matrixInvD*matrixInvU*matrixInvM; \t\t\t\t// PrettyForm(matrixB);\n\tEcho(\".\");\n\tEcho(\"...c'\");\n\tvectorC1:=matrixB*vectorC; \t\t\t\t\t\t// PrettyForm(vectorC);\n\tEcho(\".\");\n\tEcho(\"...P'\");\n\tvectorP:=matrixInvL*vectorC1; \t\t\t\t\t\t// PrettyForm(vectorP);\n\tEcho(\".\");\n\tEcho(\"...r\");\n        For(i:=1, i<= n, i++) vectorR[i]:=vectorP[i]*vectorI[i]; \t\t\t// PrettyForm(vectorR);\n\tEcho(\".\");\n\t{vectorR, vectorP, matrixP1, vectorC1, diagonals};\n];\n\nNormaliseMDP(matrixP_IsSquareMatrix, vectorI_IsVector) <--\n[\n\tLocal(i,j,n,sum,diagonals,vectorP1,vectorP2,vectorR,vectorC,vectorI2,matrixP1,matrixP2);\n\tn:=Length(matrixP);\n\tsum:=0;\n\tvectorI2:=ZeroVector(n);\n\tmatrixP2:=ZeroMatrix(n,n);\n\n\t// direct acyclic graph\n\tEcho(\"...DAG\");\n\t{vectorR, vectorP1, matrixP1, vectorC, diagonals} := DAG(matrixP, vectorI);\n\tEcho(\".\");\n\n\tEcho(\"...P''\");\n\t// normalise to MDP\n\tFor(j:=1, j <= n, j++) [\n\t  sum:=0;\n\t  For(i:=1, i <= n, i++) [\n\t\tsum:=sum + matrixP1[i][j];\n\t  ];\n\t  If(Not(sum=0), [\n\t\t  For(i:=1, i <= n, i++) [\n\t\t\tmatrixP2[i][j] := matrixP1[i][j] / sum;\n\t\t  ];\n\t  ]);\n\t];\n\tEcho(\".\");\n\n\t// update impact for equivalent risks\n\tEcho(\"...DAG\");\n\tvectorP2 := DAG(matrixP2, vectorI)[2];\n\tEcho(\".\");\n\tEcho(\"...I'\");\n\tFor(i:=1, i <= n, i++) [\n\t  vectorI2[i] := vectorI[i]* vectorP1[i]/vectorP2[i];\n\t];\n\tEcho(\".\");\n\t{vectorR, vectorP1, vectorP2, matrixP1, vectorC, matrixP2, vectorI2};\n];\n\n10 # Vectorize(A_IsMatrix) <-- \"Concat\" @ Transpose(A);\n\n10 # HalfVectorize(A_IsSymmetric) <-- LocalSymbols(i, j) [\n\tLocal(v);\n\tv := {};\n\tFor(i:=1, i <= Length(A), i++)\n\t\tFor(j:=i, j <= Length(A), j++)\n\t\t\tDestructiveAppend(v, A[j][i]);\n\tv;\n];\n"
  },
  {
    "path": "scripts/linalg.rep/code.ys.def",
    "content": "KroneckerDelta\nLeviCivita\nPermutations\nInProduct\nCrossProduct\nOuter\no\nZeroVector\nBaseVector\nIdentity\nDiagonalMatrix\nNormalize\nZeroMatrix\nTranspose\nDeterminant\nSymbolicDeterminant\nCoFactor\nMinor\nInverse\nTrace\nTr\nX\n.\nSylvesterMatrix\nVandermondeMatrix\nMatrixRow\nMatrixColumn\nGenMatrix\nRandomIntegerVector\nRandomIntegerMatrix\nJacobianMatrix\nHessianMatrix\nWronskianMatrix\nHilbertMatrix\nHilbertInverseMatrix\nHankelMatrix\nToeplitzMatrix\nFrobeniusNorm\nPNorm\nNorm\nOrthogonalBasis\nOrthonormalBasis\nDimensions\nDot\nMatrixPower\nDiagonal\nSparsity\nMatrixSolve\nCholesky\nLU\nLDU\nPLDU\nDAG\nNormaliseMDP\nVectorize\nHalfVectorize\n}\n"
  },
  {
    "path": "scripts/lists.rep/code.ys",
    "content": "\n\nFunction(\"Contains\",{list,element})\n[\n  Local(result);\n  Set(result,False);\n  While(And(Not(result), Not(Equals(list, {}))))\n  [\n    If(Equals(Head(list),element),\n      Set(result, True),\n      Set(list, Tail(list))\n      );\n  ];\n  result;\n];\n\nFunction(\"Find\",{list,element})\n[\n  Local(result,count);\n  Set(result, -1);\n  Set(count, 1);\n  While(And(result<0, Not(Equals(list, {}))))\n  [\n    If(Equals(Head(list), element),\n      Set(result, count)\n      );\n    Set(list,Tail(list));\n    Set(count,MathAdd(count,1));\n  ];\n  result;\n];\n\n// Find the first thingy that matches a predicate\nFunction(\"FindPredicate\",{list,predicate})\n[\n  Local(result,count);\n  Set(result, -1);\n  Set(count, 1);\n  While(And(result<0, Not(Equals(list, {}))))\n  [\n    If(Apply(predicate,{Head(list)}),\n      Set(result, count)\n      );\n    Set(list,Tail(list));\n    Set(count,MathAdd(count,1));\n  ];\n  result;\n];  \n\n\n\n\nFunction(\"Append\",{list,element})\n[\n  Insert(list,Length(list)+1,element);\n];\nFunction(\"DestructiveAppend\",{list,element})\n[\n  DestructiveInsert(list,Length(list)+1,element);\n];\n\nFunction(\"DestructiveAppendList\",{list,toadd})\n[\n  Local(i,nr);\n  nr:=Length(toadd);\n  For(i:=1,i<=nr,i++)\n  [\n    DestructiveAppend(list,toadd[i]);\n  ];\n  True;\n];\n\n\nFunction(\"RemoveDuplicates\",{list})\n[\n   Local(result);\n   Set(result,{});\n   ForEach(item,list)\n     If(Not(Contains(result,item)),DestructiveAppend(result,item));\n   result;\n];\n\nFunction(\"Union\",{list1,list2})\n[\n  RemoveDuplicates(Concat(list1,list2));\n];\n\nFunction(\"Intersection\",{list1,list2})\n[\n  Local(l2,index,result);\n  l2:=FlatCopy(list2);\n  result:={};\n  ForEach(item,list1)\n  [\n    Set(index, Find(l2,item));\n    If(index>0,\n      [\n        DestructiveDelete(l2,index);\n        DestructiveInsert(result,1,item);\n      ]\n      );\n  ];\n  DestructiveReverse(result);\n];\n\nFunction(\"Difference\",{list1,list2})\n[\n  Local(l2,index,result);\n  l2:=FlatCopy(list2);\n  result:=FlatCopy(list1);\n  ForEach(item,list1)\n  [\n    Set(index,Find(l2,item));\n    If(index>0,\n      [\n        DestructiveDelete(l2,index);\n        DestructiveDelete(result,Find(result,item));\n      ]\n      );\n  ];\n  result;\n];\n\nFunction(\"Push\",{stack,element})\n[\n  DestructiveInsert(stack,1,element);\n];\n\nFunction(\"Pop\",{stack,index})\n[\n  Local(result);\n  result:=stack[index];\n  DestructiveDelete(stack,index);\n  result;\n];\n\nFunction(\"PopFront\",{stack}) Pop(stack,1);\nFunction(\"PopBack\",{stack})  Pop(stack,Length(stack));\n\nFunction(\"Swap\",{list,index1,index2})\n[\n  Local(item1,item2);\n  item1:=list[index1];\n  item2:=list[index2];\n  list[index1] := item2;\n  list[index2] := item1;\n];\n\n\nFunction(\"Count\",{list,element})\n[\n   Local(result);\n   Set(result,0);\n   ForEach(item,list) If(Equals(item, element), Set(result,MathAdd(result,1)));\n   result;\n];\n\nFunction(\"BubbleSort\",{list,compare})\n[\n  Local(i,j,length,left,right);\n\n  list:=FlatCopy(list);\n  length:=Length(list);\n\n  For (j:=length,j>1,j--)\n  [\n    For(i:=1,i<j,i++)\n    [\n      left:=list[i];\n      right:=list[i+1];\n      If(Not(Apply(compare,{left,right})),\n        [\n          DestructiveInsert(DestructiveDelete(list,i),i+1,left);\n        ]\n      );\n    ];\n  ];\n  list;\n];\n\n/// fast in-place sorting of a list (or array!)\n/// SmallSort sorts up to 3 elements, HeapSort sorts 4 and more elements\nSmallSort(_list, _first, _last, _compare) _ (list={}) <-- list;\nSmallSort(_list, _first, _last, _compare) _ (last=first) <-- list;\nSmallSort(_list, _first, _last, _compare) _ (last=first+1) <--\n[\n\tLocal(temp);\n\ttemp := list[first];\n\tIf(\n\t\tApply(compare,{temp,list[last]}),\n\t\tlist,\n\t\t[\n\t\t\tlist[first] := list[last];\n\t\t\tlist[last] := temp;\n\t\t]\t//Swap(list, first, last)\n\t);\n\tlist;\n];\nSmallSort(_list, _first, _last, _compare) _ (last=first+2) <--\n[\n\tLocal(temp);\n\ttemp := list[first];\n\tIf(\n\t\tApply(compare,{list[first+1],temp}),\n\t\t[\n\t\t\tlist[first] := list[first+1];\n\t\t\tlist[first+1] := temp;\n\t\t]\t//Swap(list, first, first+1)\t// x>y, z\n\t);\n\t// x<y, z\n\ttemp := list[last];\n\tIf(\n\t\tApply(compare,{list[first],temp}),\n\t\tIf(\t// z>x<y\n\t\t\tApply(compare,{list[first+1],temp}),\n\t\t\tlist,\n\t\t\t[\n\t\t\t\tlist[last] := list[first+1];\n\t\t\t\tlist[first+1] := temp;\n\t\t\t]\t//Swap(list, first+1, last)\t// 1, 3, 2\n\t\t),\n\t\t[\t// 2, 3, 1 -> 1, 2, 3\n\t\t\tlist[last] := list[first+1];\n\t\t\tlist[first+1] := list[first];\n\t\t\tlist[first] := temp;\n\t\t]\n\t);\n\tlist;\n];\n\nHeapSort(list, compare) := HeapSort(list, Array'Create(Length(list), 0), 1, Length(list), compare);\n\n// this will sort \"list\" and mangle \"tmplist\"\n1 # HeapSort(_list, _tmplist, _first, _last, _compare) _ (last - first <= 2) <-- SmallSort(list, first, last, compare);\n2 # HeapSort(_list, _tmplist, _first, _last, _compare) <-- \n[\t// See: J. W. J. Williams, Algorithm 232 (Heapsort), Com. of ACM, vol. 7, no. 6, p. 347 (1964)\n\t// sort two halves recursively, then merge two halves\n\t// cannot merge in-place efficiently, so need a second list\n\tLocal(mid, ileft, iright, pleft);\n\tmid := first+((last-first)>>1);\n\tHeapSort(list, tmplist, first, mid, compare);\n\tHeapSort(list, tmplist, mid+1, last, compare);\n\t// copy the lower part to temporary array\n\tFor(ileft := first,  ileft <= mid, ileft++)\n\t\ttmplist[ileft] := list[ileft];\n\tFor(\n\t\t[ileft := first; pleft := first; iright := mid+1;],\n\t\tileft <= mid,\t// if the left half is finished, we don't have to do any more work\n\t\tpleft++\t// one element is stored at each iteration\n\t)\t// merge two halves\n\t\t// elements before pleft have been stored\n\t\t// the smallest element of the right half is at iright\n\t\t// the smallest element of the left half is at ileft, access through tmplist\n\tIf(\t// we copy an element from ileft either if it is smaller or if the right half is finished; it is unnecessary to copy the remainder of the right half since the right half stays in the \"list\"\n\t\tiright>last Or Apply(compare,{tmplist[ileft],list[iright]}),\n\t\t[\t// take element from ileft\n\t\t\tlist[pleft] := tmplist[ileft];\n\t\t\tileft++;\n\t\t],\n\t\t[\t// take element from iright\n\t\t\tlist[pleft] := list[iright];\n\t\t\tiright++;\n\t\t]\n\t);\n\n\tlist;\n];\n\nLocalSymbols(max,f,low,high,mid,current)\n[\nFindIsq(max,f)  :=\n[\n  Local(low,high,mid,current);\n  low:=1;\n  high:=max+1;\n  Set(mid,((high+low)>>1));\n  While(high>low And mid>1)\n  [\n    Set(mid,((high+low)>>1));\n    Set(current,Apply(f,{mid}));\n//Echo({low,high,current});\n    If(current = 0,\n       high:=low-1,\n       If(current > 0,\n          Set(high,mid),\n          Set(low,mid+1)\n          )\n       );\n  ];\n  mid;\n];\n];\nUnFence(\"FindIsq\",2);\nLocalSymbols(max,f,result)\n[\n  BSearch(max,f)  :=\n  [\n    Local(result);\n    Set(result, FindIsq(max,f));\n    If(Apply(f,{result})!=0,Set(result,-1));\n    result;\n  ];\n];\nUnFence(\"BSearch\",2);\n\n\n/* VarList: return the variables this expression depends on. */\nVarList(_expr) <-- VarList(expr,\"IsVariable\");\n\nFunction(\"VarList\",{expr,filter})\n[\n  RemoveDuplicates(VarListAll(expr,filter));\n];\n\n\n\n/*\n * RuleBase for VarListAll: recursively traverse an expression looking\n * up all variables the expression depends on.\n */\n/* Accept any variable. */\n\nVarListAll(_expr) <-- VarListAll(expr,\"IsVariable\");\n\n10 # VarListAll(_expr,_filter)_(Apply(filter,{expr}) = True) <--\n     {expr};\n\n/* Otherwise check all leafs of a function. */\n20 # VarListAll(expr_IsFunction,_filter) <--\n[\n  Local(item,result, flatlist);\n  Set(flatlist,Tail(Listify(expr)));\n  Set(result,{});\n  ForEach(item,flatlist)\n    Set(result,Concat(result,VarListAll(item,filter)));\n  result;\n];\n\n/* Else it doesn't depend on any variable. */\n30 # VarListAll(_expr,_filter) <-- {};\n\n\n\n\n/* Juan: TemplateFunction (as defined in the file \"deffunc\")\n * also makes the arguments to the function local symbols.\n * Use HoldArgNr to specify the index of a variable to hold\n * (since they are defined as local symbols).\n */\n\nTemplateFunction(\"Table\",{body,var,count'from,count'to,step})\n  LocalSymbols(result,nr,ii)\n  [\n    MacroLocal(var);\n    result:={};\n    nr := (count'to - count'from) / step;\n    ii := 0;\n    While( ii <= nr )\n      [\n       MacroSet( var, count'from + ii * step );\n       DestructiveInsert( result,1,Eval(body) );\n       Set(ii,MathAdd(ii,1));\n      ];\n    DestructiveReverse(result);\n  ];\nHoldArgNr(\"Table\",5,1); /* body */\nHoldArgNr(\"Table\",5,2); /* var */\nUnFence(\"Table\",5);\n\n\n\nTemplateFunction(\"MapSingle\",{func,list})\n[\n  Local(mapsingleresult);\n  mapsingleresult:={};\n\n  ForEach(mapsingleitem,list)\n  [\n    DestructiveInsert(mapsingleresult,1,\n      Apply(func,{mapsingleitem}));\n  ];\n  DestructiveReverse(mapsingleresult);\n];\nUnFence(\"MapSingle\",2);\nHoldArg(\"MapSingle\",func);\n\n/* Another Macro... hack for /: to work. */\nTemplateFunction(\"MacroMapSingle\",{func,list})\n[\n  Local(mapsingleresult);\n  mapsingleresult:={};\n\n  ForEach(mapsingleitem,list)\n  [\n    DestructiveInsert(mapsingleresult,1,\n      `ApplyPure(func,{Hold(Hold(@mapsingleitem))}));\n  ];\n  DestructiveReverse(mapsingleresult);\n];\nUnFence(\"MacroMapSingle\",2);\nHoldArg(\"MacroMapSingle\",func);\nHoldArg(\"MacroMapSingle\",list);\n\nLocalSymbols(func,lists,mapsingleresult,mapsingleitem)\n[\n  Function(\"Map\",{func,lists})\n  [\n    Local(mapsingleresult,mapsingleitem);\n    mapsingleresult:={};\n    lists:=Transpose(lists);\n    ForEach(mapsingleitem,lists)\n    [\n      DestructiveInsert(mapsingleresult,1,Apply(func,mapsingleitem));\n    ];\n    DestructiveReverse(mapsingleresult);\n  ];\n  UnFence(\"Map\",2);\n  HoldArg(\"Map\",func);\n];\n\nTemplateFunction(\"MapArgs\",{expr,oper})\n[\n  Set(expr,Listify(expr));\n   UnList(Concat({expr[1]},\n     Apply(\"MapSingle\",{oper,Tail(expr)})\n   ) );\n];\nUnFence(\"MapArgs\",2);\nHoldArg(\"MapArgs\",oper);\n\n/* Another Macro... hack for /: to work. */\nMacro(\"MacroMapArgs\",{expr,oper})\n[\n  Local(ex,tl,op);\n  Set(op,@oper);\n  Set(ex,Listify(@expr));\n  Set(tl,Tail(ex));\n\n   UnList(Concat({ex[1]},\n     `MacroMapSingle(@op,Hold(@tl)))\n   );\n];\nUnFence(\"MapArgs\",2);\nHoldArg(\"MapArgs\",oper);\n\n10 # DeepCopy(l_IsList) <-- [\n    Local(r);\n    r := {};\n    ForEach(e, l)\n        DestructiveAppend(r, DeepCopy(e));\n    r;\n];\n\n20 # DeepCopy(_e) <-- e;\n\n10 # FillList(_item, 0) <-- {};\n\n20 # FillList(_item, length_IsPositiveInteger) <-- [\n    Local(i, result);\n    result := {};\n    For(i:=0, i < length, i++)\n        DestructiveInsert(result, 1, DeepCopy(item));\n    result;\n];\n\n/* ***** Drop ***** */\n\n/* Needs to check the parameters */\n\n/*\n * Drop( list, n ) gives 'list' with its first n elements dropped\n * Drop( list, -n ) gives 'list' with its last n elements dropped\n * Drop( list, {m,n} ) gives 'list' with elements m through n dropped\n */\n\nRuleBase(\"Drop\", {lst, range});\n\nRule(\"Drop\", 2, 1, IsList(range))\n    Concat(Take(lst,range[1]-1), Drop(lst, range[2]));\n\nRule(\"Drop\", 2, 2, range >= 0)\n    If( range = 0 Or lst = {}, lst, Drop( Tail(lst), range-1 ));\n\nRule(\"Drop\", 2, 2, range < 0)\n    Take( lst, Length(lst) + range );\n\n\n/* ***** Take ***** */\n\n/* Needs to check the parameters */\n\n/*\n * Take( list, n ) gives the first n elements of 'list'\n * Take( list, -n ) gives the last n elements of 'list'\n * Take( list, {m,n} ) elements m through n of 'list'\n */\n\nRuleBase(\"Take\", {lst, range});\n\nRule(\"Take\", 2, 1, IsList(range))\n    Take( Drop(lst, range[1] -1), range[2] - range[1] + 1);\n\nRule(\"Take\", 2, 2, range >= 0)\n    If( Length(lst)=0 Or range=0, {},\n        Concat({Head(lst)}, Take(Tail(lst), range-1)));\n\nRule(\"Take\", 2, 2, range < 0)\n    Drop( lst, Length(lst) + range );\n\n\n/* ***** Partition ***** */\n\n/* Partition( list, n ) partitions 'list' into non-overlapping sublists of length n */\n\nPartition(lst, len):=\n\tIf( Length(lst) < len Or len = 0, {},\n        \tConcat( {Take(lst,len)}, Partition(Drop(lst,len), len) ));\n\n\n//////////////////////////////////////////////////\n/// Print a list using a padding string\n//////////////////////////////////////////////////\n\n10 # PrintList(list_IsList) <-- PrintList(list, \", \");\n10 # PrintList({}, padding_IsString) <-- \"\";\n20 # PrintList(list_IsList, padding_IsString) <-- ToString() [\n\tLocal(i);\n\tForEach(i, list) [\n\t\tIf(Not(Equals(i, Head(list))), WriteString(padding));\n\t\tIf (IsString(i), WriteString(i), If(IsList(i), WriteString(\"{\" : PrintList(i, padding) : \"}\"), Write(i)));\n\t];\n];\n\n//////////////////////////////////////////////////\n/// FuncList --- list all function atoms used in an expression\n//////////////////////////////////////////////////\n/// like VarList except collects functions\n\n10 # FuncList(expr_IsAtom) <-- {};\n20 # FuncList(expr_IsFunction) <--\nRemoveDuplicates(\n\tConcat(\n\t\t{Head(Listify(expr))},\n\t\tApply(\"Concat\",\n\t\t\tMapSingle(\"FuncList\", Tail(Listify(expr)))\n\t\t)\n\t)\n);\n\n/*\nThis is like FuncList except only looks at arguments of a given list of functions. All other functions become \"opaque\".\nFuncListArith() is defined to only look at arithmetic operations +, -, *, /.\n*/\n10 # FuncList(expr_IsAtom, look'list_IsList) <-- {};\n// a function not in the looking list - return its type\n20 # FuncList(expr_IsFunction, look'list_IsList)_(Not Contains(look'list, Atom(Type(expr)))) <-- {Atom(Type(expr))};\n// a function in the looking list - traverse its arguments\n30 # FuncList(expr_IsFunction, look'list_IsList) <--\nRemoveDuplicates(\n\tConcat(\n\t\t{Head(Listify(expr))},\n\t\t[\t// gave up trying to do it using Map and MapSingle... so writing a loop now.\n\t\t\t// obtain a list of functions, considering only functions in look'list\n\t\t\tLocal(item, result);\n\t\t\tresult := {};\n\t\t\tForEach(item, expr) result := Concat(result, FuncList(item, look'list));\n\t\t\tresult;\n\t\t]\n\t)\n);\n\nFuncListArith(expr) := FuncList(expr, {Atom(\"+\"), Atom(\"-\"), *, /});\n\nHoldArgNr(\"FuncList\", 1, 1);\nHoldArgNr(\"FuncList\", 2, 1);\nHoldArgNr(\"FuncListArith\", 1, 1);\n\n/// VarListArith --- obtain arithmetic variables\n// currently the VarList(x,y) semantic is convoluted so let's introduce a new name; but in principle this needs to be cleaned up\nVarListArith(expr) := VarListSome(expr, {Atom(\"+\"), Atom(\"-\"), *, /});\n\n/// VarListSome is just like FuncList(x,y)\n\n10 # VarListSome({}, _look'list) <-- {};\n// an atom should be a variable to qualify\n10 # VarListSome(expr_IsVariable, _look'list) <-- {expr};\n15 # VarListSome(expr_IsAtom, _look'list) <-- {};\n// a function not in the looking list - return it whole\n20 # VarListSome(expr_IsFunction, look'list_IsList)_(Not Contains(look'list, Atom(Type(expr)))) <-- {expr};\n// a function in the looking list - traverse its arguments\n30 # VarListSome(expr_IsFunction, look'list_IsList) <--\nRemoveDuplicates(\n\t\t[\t// obtain a list of functions, considering only functions in look'list\n\t\t\tLocal(item, result);\n\t\t\tresult := {};\n\t\t\tForEach(item, expr) result := Concat(result, VarListSome(item, look'list));\n\t\t\tresult;\n\t\t]\n);\n\n//////////////////////////////////////////////////\n/// Global stack operations on variables\n//////////////////////////////////////////////////\n\n\nLocalSymbols(GlobalStack, x)\n[\n  GlobalStack := {};\n\n\tGlobalPop(x_IsAtom) <--\n\t[\n\t\tCheck(Length(GlobalStack)>0, \"GlobalPop: Error: empty GlobalStack\");\n\t\tMacroSet(x, PopFront(GlobalStack));\n\t\tEval(x);\n\t];\n\n\tHoldArgNr(\"GlobalPop\", 1, 1);\n\n\tGlobalPop() <--\n\t[\n\t\tCheck(Length(GlobalStack)>0, \"GlobalPop: Error: empty GlobalStack\");\n\t\tPopFront(GlobalStack);\n\t];\n\n\tGlobalPush(_x) <--\n\t[\n\t\tPush(GlobalStack, x);\n\t\tx;\n\t];\n];\n\n\n\n// Non-destructive Reverse operation\nReverse(list):=DestructiveReverse(FlatCopy(list));\n\n"
  },
  {
    "path": "scripts/lists.rep/code.ys.def",
    "content": "Contains\nFind\nFindPredicate\nAppend\nDestructiveAppend\nDestructiveAppendList\nRemoveDuplicates\nUnion\nIntersection\nDifference\nPush\nPop\nPopFront\nPopBack\nSwap\nCount\nBubbleSort\nHeapSort\nFindIsq\nBSearch\nVarList\nVarListAll\nTable\nMacroMapSingle\nMapSingle\nMap\nMacroMapArgs\nMapArgs\nFillList\nDrop\nTake\nPartition\nPrintList\nFuncList\nFuncListSome\nFuncListArith\nVarListArith\nVarListSome\nGlobalPop\nGlobalPush\nReverse\n}\n"
  },
  {
    "path": "scripts/lists.rep/scopestack.ys",
    "content": "\n/*\n   Stack simulator. Api:\n   \n   NewStack() - creates a stack simulation\n   PushStackFrame(stack,unfenced) - push frame on stack, (un)fenced\n   PushStackFrame(stack,fenced) \n   PopStackFrame(stack)   - pop stack frame\n   StackDepth(_stack) - return stack depth\n   AddToStack(stack,element) - add element to top stack frame\n\n   IsOnStack(stack,element) - returns True if element is accessible\n       on current stack, False otherwise\n   FindOnStack(stack,element) - return assoc list for element. \n       Check first with IsOnStack that it is available!\n\n*/\n\nNewStack() := {{},{}};\n\n10 # PushStackFrame(_stack,unfenced) \n   <-- \n   [\n     DestructiveInsert(stack[1],1,{});\n     DestructiveInsert(stack[2],1,True);\n   ];\n10 # PushStackFrame(_stack,fenced) \n   <-- \n   [\n     DestructiveInsert(stack[1],1,{});\n     DestructiveInsert(stack[2],1,False);\n   ];\nPopStackFrame(stack):=\n[\n  DestructiveDelete(stack[1],1);\n  DestructiveDelete(stack[2],1);\n];\nStackDepth(_stack) <-- Length(stack[1]);\n\nAddToStack(stack,element)  :=\n[\n  DestructiveInsert(stack[1][1],1,{element,{}});\n];\n\nDropOneFrame(_stack) <-- {Tail(stack[1]),Tail(stack[2])};\n\n10 # IsOnStack({{},{}},_element) <-- False;\n11 # IsOnStack(_stack,_element)_(stack[1][1][element] != Empty) <-- True;\n20 # IsOnStack(_stack,_element)_(StackDepth(stack)>0 And stack[2][1] = True) \n   <-- IsOnStack(DropOneFrame(stack),element);\n30 # IsOnStack(_stack,_element) <-- \n[\n//Echo(\"stack depth = \",StackDepth(stack));\n//Echo(stack[2][1]);\nFalse;\n];\n10 # FindOnStack(_stack,_element)_(stack[1][1][element] != Empty) \n   <-- stack[1][1][element];\n20 # FindOnStack(_stack,_element)_(StackDepth(stack)>0 And stack[2][1] = True) \n   <-- FindOnStack(DropOneFrame(stack),element);\n30 # FindOnStack(_stack,_element) <-- Check(False,\"Illegal stack access! Use IsOnStack.\");\n\n\n\n\n"
  },
  {
    "path": "scripts/lists.rep/scopestack.ys.def",
    "content": "NewStack\nPushStackFrame\nPopStackFrame\nStackDepth\nAddToStack\nIsOnStack\nFindOnStack\n}\n\n"
  },
  {
    "path": "scripts/localrules.rep/code.ys",
    "content": "\nRuleBase(\"<-\",{left,right});\nHoldArg(\"<-\",left);\nHoldArg(\"<-\",right);\n\nLocalSymbols(LocResult) [\n\n  Set(LocResult,True);\n  10 # LocPredicate(exp_IsAtom) <--\n  [\n    Local(tr,result);\n    tr:=patterns;\n    result:=False;\n    While (tr != {})\n    [\n      If (Head(Head(tr)) = exp,\n      [\n        Set(LocResult,Eval(Head(Tail(Head(tr)))));\n        result := True;\n        tr:={};\n      ],\n      [\n        tr := Tail(tr);\n      ]);\n    ];\n    result;\n  ];\n\n  10 # LocPredicate(exp_IsFunction) <--\n  [\n    Local(tr,result,head);\n    tr:=patterns;\n    result:=False;\n    While (tr != {})\n    [\n      Set(head, Head(Head(tr)));\n      If (Not(IsAtom(head)) And exp[0]=head[1] And Pattern'Matches(head[2], exp),\n      [\n        Set(LocResult,Eval(Head(Tail(Head(tr)))));\n        Set(result, True);\n        Set(tr,{});\n      ],\n      [\n        Set(tr, Tail(tr));\n      ]);\n    ];\n    result;\n  ];\n  20 # LocPredicate(_exp) <-- False;\n\n  LocChange(_exp) <-- LocResult;\n]; // LocalSymbols(LocResult)\n\nUnFence(\"LocPredicate\",1);\nUnFence(\"LocChange\",1);\n\n10 # LocProcessSingle({_pat,_post,_exp}) <-- { {pat[0],Pattern'Create(pat,post)},exp };\n20 # LocProcessSingle({pat_IsFunction,_exp}) <-- { {pat[0],Pattern'Create(pat,True)},exp };\n30 # LocProcessSingle({pat_IsAtom,_exp}) <-- { pat,exp };\n40 # LocProcessSingle(pat_IsFunction <- _exp) <-- { {pat[0],Pattern'Create(pat,True)},exp };\n50 # LocProcessSingle(pat_IsAtom <- _exp) <-- { pat,exp };\n\nLocProcess(patterns) :=\n[\n  MapSingle(\"LocProcessSingle\",patterns);\n];\n\nCompilePatterns(patterns) := LocPatterns(LocProcess(patterns));\n\n\n5 # (_expression /: LocPatterns(_patterns)) <--\n[\n  MacroSubstitute(expression,\"LocPredicate\",\"LocChange\");\n];\n10 # (_expression /: _patterns) <--\n[\n  Set(patterns, LocProcess(patterns));\n  MacroSubstitute(expression,\"LocPredicate\",\"LocChange\");\n];\n\n5 # (_expression /:: LocPatterns(_patterns)) <--\n[\n  MacroSubstitute(expression,\"LocPredicate\",\"LocChange\");\n];\n10 # (_expression /:: _patterns) <--\n[\n  Local(old);\n  Set(patterns, LocProcess(patterns));\n  Set(old, expression);\n  Set(expression, MacroSubstitute(expression,\"LocPredicate\",\"LocChange\"));\n  While (expression != old)\n  [\n    Set(old, expression);\n    Set(expression, MacroSubstitute(expression,\"LocPredicate\",\"LocChange\"));\n  ];\n  expression;\n];\n\nLocalSymbols(a, b, var, body) [\nRuleBase(\"Where\",{left,right});\n//HoldArg(\"Where\",left);\n//HoldArg(\"Where\",right);\nUnFence(\"Where\",2);\n10 # (_body Where var_IsAtom == _value)\n     <-- `[Local(@var);@var := @value;@body;];\n20 # (_body Where (_a And _b))\n     <--\n[\n  Set(body,`(@body Where @a));\n  `(@body Where @b);\n];\n\n30 # (_body Where {}) <-- {};\n40 # (_body Where list_IsList)_IsList(list[1])\n     <--\n     [\n       Local(head,rest);\n       head:=Head(list);\n       rest:=Tail(list);\n       rest:= `(@body Where @rest);\n       `(@body Where @head) : rest;\n     ];\n\n50 # (_body Where list_IsList)\n     <--\n     [\n       Local(head,rest);\n       While (list != {})\n       [\n          head:=Head(list);\n          body := `(@body Where @head);\n          list:=Tail(list);\n        ];\n        body;\n     ];\n\n\n60 # (_body Where _var == _value) <-- Subst(var,value)body;\n];\n\n\n// (a or b) and (c or d) -> (a and c) or (a and d) or (b and c) or (b and d)\n20 # (list_IsList AddTo _rest) <--\n[\n  Local(res);\n  res:={};\n  ForEach(item,list)\n  [\n    res := Concat(res,item AddTo rest);\n  ];\n  res;\n];\n30 # (_a'item AddTo list_IsList) <--\n[\n  MapSingle({{orig},a'item And orig},list);\n];\n40 # (_a'item AddTo _b) <-- a'item And b;\n\n\n\n\n\n\n\n"
  },
  {
    "path": "scripts/localrules.rep/code.ys.def",
    "content": "/:\n/::\nCompilePatterns\nWhere\nAddTo\n}\n"
  },
  {
    "path": "scripts/logic.rep/code.ys",
    "content": "/* Tests on logic */\n\n/* Small theorem prover for propositional logic, based on the\n * resolution principle.\n * Written by Ayal Pinkus, based on the simple theorem prover from \"Prolog, Ivan Bratko, chapter 20\"\n * Version 0.1 initial implementation.\n *\n *\n * Examples:\nCanProve(( (a=>b) And (b=>c)=>(a=>c) ))  <-- True\nCanProve(a  Or   Not a)                  <-- True\nCanProve(True  Or  a)                    <-- True\nCanProve(False  Or  a)                   <-- a\nCanProve(a  And   Not a)                 <-- False\nCanProve(a  Or b Or (a And b))           <-- a Or b\n */\n\nRuleBase(\"=>\",{a,b});\n\n\n/*\n   Simplify a boolean expression. CNF is responsible\n   for converting an expression to the following form:\n        (p1  Or  p2  Or  ...)  And  (q1  Or  q2  Or  ...)  And ...\n   That is, a conjunction of disjunctions.\n*/\n\n\n// Trivial simplifications\n10  # CNF( Not  True)                  <-- False;\n11  # CNF( Not  False)                 <-- True;\n12  # CNF(True   And  (_x))            <-- CNF(x);\n13  # CNF(False  And  (_x))            <-- False;\n14  # CNF(_x   And  True)              <-- CNF(x);\n15  # CNF(_x  And  False)              <-- False;\n16  # CNF(True   Or  (_x))             <-- True;\n17  # CNF(False  Or  (_x))             <-- CNF(x);\n18  # CNF((_x)  Or  True )             <-- True;\n19  # CNF((_x)  Or  False)             <-- CNF(x);\n\n// A bit more complext\n21  # CNF(_x  Or  _x)                  <-- CNF(x);\n22  # CNF(_x  And  _x)                 <-- CNF(x);\n23  # CNF(_x  Or Not (_x))             <-- True;\n14  # CNF(Not (_x)  Or _x)             <-- True;\n25  # CNF(_x  And Not (_x))            <-- False;\n26  # CNF(Not (_x)  And _x)            <-- False;\n\n// Simplifications that deal with (in)equalities\n25  # CNF(((_x) == (_y))   Or  ((_x) !== (_y)))   <-- True;\n25  # CNF(((_x) !== (_y))  Or  ((_x) == (_y)))    <-- True;\n26  # CNF(((_x) == (_y))   And ((_x) !== (_y)))   <-- False;\n26  # CNF(((_x) !== (_y))  And ((_x) == (_y)))    <-- False;\n\n27  # CNF(((_x) >= (_y))   And ((_x) < (_y)))     <-- False;\n27  # CNF(((_x) < (_y))    And ((_x) >= (_y)))    <-- False;\n28  # CNF(((_x) >= (_y))   Or  ((_x) < (_y)))     <-- True;\n28  # CNF(((_x) < (_y))    Or  ((_x) >= (_y)))    <-- True;\n\n// some things that are more complex\n120  # CNF((_x)  Or  (_y))            <-- LogOr(x, y, CNF(x), CNF(y));\n10 # LogOr(_x,_y,_x,_y)               <-- x Or y;\n20 # LogOr(_x,_y,_u,_v)               <-- CNF(u Or v);\n\n130  # CNF( Not  (_x))                <-- LogNot(x, CNF(x));\n10 # LogNot(_x, _x)                   <-- Not (x);\n20 # LogNot(_x, _y)                   <-- CNF(Not (y));\n\n40 # CNF( Not ( Not  (_x)))           <-- CNF(x);                           // eliminate double negation\n45 # CNF((_x)=>(_y))                  <-- CNF((Not (x))  Or  (y));              // eliminate implication\n\n50 # CNF( Not ((_x)  And  (_y)))      <-- CNF((Not x) Or (Not y));          // De Morgan's law\n60 # CNF( Not ((_x)  Or  (_y)))       <-- CNF(Not (x)) And CNF(Not (y));        // De Morgan's law\n\n/*\n70 # CNF((_x) And ((_y)  Or  (_z)))   <-- CNF(x And y) Or CNF(x And z);\n70 # CNF(((_x) Or (_y)) And (_z))     <-- CNF(x And z) Or CNF(y And z);\n\n80 # CNF((_x)  Or  ((_y)  And  (_z))) <-- CNF(x Or y) And CNF(x Or z);\n80 # CNF(((_x)  And  (_y)) Or (_z))   <-- CNF(x Or z) And CNF(y Or z);\n*/\n\n70 # CNF(((_x)  And  (_y))  Or  (_z)) <-- CNF(x Or z) And CNF(y Or z);      // Distributing Or over And\n80 # CNF((_x)  Or  ((_y)  And  (_z))) <-- CNF(x Or y) And CNF(x Or z);\n\n90 # CNF((_x)  And  (_y))             <-- CNF(x) And CNF(y);                // Transform subexpression\n\n101 # CNF( (_x) < (_y) )              <-- Not CNFInEq(x >=  y);\n102 # CNF( (_x) > (_y) )              <-- CNFInEq(x >   y);\n103 # CNF( (_x) >= (_y) )             <-- CNFInEq(x >=  y);\n104 # CNF( (_x) <= (_y) )             <-- Not CNFInEq(x >  y);\n105 # CNF( (_x) == (_y) )             <-- CNFInEq(x ==  y);\n106 # CNF( (_x) !== (_y) )            <-- Not CNFInEq(x == y);\n\n111 # CNF( Not((_x) <  (_y)) )        <-- CNFInEq( x >= y );\n113 # CNF( Not((_x) <= (_y)) )        <-- CNFInEq( x > y );\n116 # CNF( Not((_x) !== (_y)) )       <-- CNFInEq( x == y );\n\n/* Accept as fully simplified, fallthrough case */\n200 # CNF(_x)                         <-- x;\n\n20 # CNFInEq((_xex) == (_yex))        <-- (CNFInEqSimplify(xex-yex) ==  0);\n20 # CNFInEq((_xex) > (_yex))         <-- (CNFInEqSimplify(xex-yex) >   0);\n20 # CNFInEq((_xex) >= (_yex))        <-- (CNFInEqSimplify(xex-yex) >=  0);\n30 # CNFInEq(_exp)                    <-- (CNFInEqSimplify(exp));\n\n10 # CNFInEqSimplify((_x) - (_x))     <-- 0;        // strictly speaking, this is not always valid, i.e. 1/0 - 1/0 != 0...\n100# CNFInEqSimplify(_x)              <-- [/*Echo({\"Hit the bottom of CNFInEqSimplify with \", x, Nl()});*/ x;];\n                                                    // former \"Simplify\";\n\n// Some shortcuts to match prev interface\nCanProveAux(_proposition)                           <-- LogicSimplify(proposition, 3);\n10 # LogicSimplify(_proposition, _level)_(level<2)  <-- CNF(proposition);\n\n20 # LogicSimplify(_proposition, _level) <--\n[\n  Local(cnf, list, clauses);\n  Check(level > 1, \"Wrong level\");\n  // First get the CNF version of the proposition\n  Set(cnf, CNF(proposition));\n\n  If(level <= 1, cnf, [\n    Set(list, Flatten(cnf, \"And\"));\n    Set(clauses, {});\n    ForEach(clause, list)\n    [\n      Local(newclause);\n      //newclause := BubbleSort(LogicRemoveTautologies(Flatten(clause, \"Or\")), LessThan);\n      Set(newclause, LogicRemoveTautologies(Flatten(clause, \"Or\")));\n      If(newclause != {True}, DestructiveAppend(clauses, newclause));\n    ];\n\n    /*\n        Note that we sort each of the clauses so that they look the same,\n        i.e. if we have (A And B) And ( B And A), only the first one will\n        persist.\n    */\n    Set(clauses, RemoveDuplicates(clauses));\n\n    If(Equals(level, 3) And (Length(clauses) != 0), [\n        Set(clauses, DoUnitSubsumptionAndResolution(clauses));\n        Set(clauses, LogicCombine(clauses));\n    ]);\n\n    Set(clauses, RemoveDuplicates(clauses));\n\n    If(Equals(Length(clauses), 0), True, [\n        /* assemble the result back into a boolean expression */\n        Local(result);\n        Set(result, True);\n        ForEach(item,clauses)\n        [\n            Set(result, result And UnFlatten(item, \"Or\", False));\n        ];\n\n        result;\n    ]);\n  ]);\n];\n\n/* CanProve tries to prove that the negation of the negation of\n   the proposition is true. Negating twice is just a trick to\n   allow all the simplification rules a la De Morgan to operate\n */\n/*CanProve(_proposition)    <-- CanProveAux( Not CanProveAux( Not proposition));*/\n\nCanProve(_proposition)      <-- CanProveAux( proposition );\n\n1 # SimpleNegate(Not (_x))  <-- x;\n2 # SimpleNegate(_x)        <-- Not(x);\n\n/* LogicRemoveTautologies scans a list representing e1 Or e2 Or ... to find\n   if there are elements p and  Not p in the list. This signifies p Or Not p,\n   which is always True. These pairs are removed. Another function that is used\n   is RemoveDuplicates, which converts p Or p into p.\n*/\n\n/* this can be optimized to walk through the lists a bit more efficiently and also take\ncare of duplicates in one pass */\nLocalCmp(_e1, _e2)                  <-- LessThan(ToString() Write(e1), ToString() Write(e2));\n\n// we may want to add other expression simplifers for new expression types\n100 # SimplifyExpression(_x)        <-- x;\n\n// Return values:\n//  {True} means True\n//  {} means False\nLogicRemoveTautologies(_e) <--\n[\n  Local(i, len, negationfound); Set(len, Length(e));\n  Set(negationfound, False);\n\n  //Echo(e);\n  e := BubbleSort(e, \"LocalCmp\");\n\n  For(Set(i, 1), (i <= len) And (Not negationfound), i++)\n  [\n    Local(x, n, j);\n    // we can register other simplification rules for expressions\n    //e[i] := MathNth(e,i) /:: {gamma(_y) <- SimplifyExpression(gamma(y))};\n    Set(x, MathNth(e,i));\n    Set(n, SimpleNegate(x));                    /* this is all we have to do because of\n                                                the kind of expressions we can have coming in */\n\n    For(Set(j, i+1), (j <= len) And (Not negationfound), j++) [\n        Local(y);\n        Set(y, MathNth(e,j));\n\n        If(Equals(y, n),\n            [\n                //Echo({\"Deleting from \", e, \" i=\", i, \", j=\", j, Nl()});\n\n                Set(negationfound, True);\n                //Echo({\"Removing clause \", i, Nl()});\n            ],\n        If(Equals(y, x),\n            [\n                //Echo({\"Deleting from \", e, \" j=\", j, Nl()});\n                DestructiveDelete(e, j);\n                Set(len,MathSubtract(len,1));\n            ])\n        );\n    ];\n    Check(len = Length(e), \"The length computation is incorrect\");\n  ];\n\n  If(negationfound, {True}, e);            /* note that a list is returned */\n];\n\n10 # Contradict((_x) - (_y) == 0, (_x) - (_z) == 0)_(y != z)     <-- True;\n12 # Contradict((_x) == (_y), (_x) == (_z))_(y != z)             <-- True;\n13 # Contradict((_x) - (_y) == 0, (_x) - (_z) >= 0)_(z > y)      <-- True;\n14 # Contradict((_x) - (_y) == 0, (_x) - (_z) >  0)_(z > y)      <-- True;\n14 # Contradict(Not (_x) - (_y) >= 0, (_x) - (_z) >  0)_(z > y)  <-- True;\n15 # Contradict(_a, _b)                                          <-- Equals(SimpleNegate(a), b);\n\n/* find the number of the list that contains n in it, a pointer to a list of lists in passed */\nLogicFindWith(_list, _i, _n) <--\n[\n  Local(result, index, j);\n  Set(result, -1); Set(index, -1);\n\n  For(j := i+1, (result<0) And (j <= Length(list)), j++)\n  [\n    Local(k, len); Set(len, Length(list[j]));\n    For(k := 1, (result<0) And (k<=len), k++)\n    [\n      Local(el); Set(el, list[j][k]);\n\n      If(Contradict(n, el),\n        [Set(result, j); Set(index, k);]);\n    ];\n  ];\n  {result, index};\n];\n\n/* LogicCombine is responsible for scanning a list of lists, which represent\n   a form (p1  Or  p2  Or  ...)  And  (q1  Or  q2  Or  ...)  And ... by scanning the lists\n   for combinations x Or Y  And   Not x Or Z <-- Y Or Z . If Y Or Z is empty then this clause\n   is false, and thus the entire proposition is false.\n*/\nLogicCombine(_list) <--\n[\n  Local(i, j);\n  For(Set(i,1), i<=Length(list), Set(i,MathAdd(i,1)))\n  [\n    //Echo({\"list[\", i, \"/\", Length(list), \"]: \", list[i], Nl()});\n\n    For(j := 1, (j<=Length(list[i])), j++)\n    [\n      Local(tocombine, n, k);\n      Set(n, list[i][j]);\n\n      {tocombine, k} := LogicFindWith(list, i, n);// search forward for n, tocombine is the list we\n                                                  // will combine the current one with\n      If(tocombine != -1,\n      [\n        Local(combination);\n        Check(k != -1, \"k is -1\");\n\n        Set(combination, LogicRemoveTautologies(Concat(list[i], list[tocombine])));\n        If(combination = {},                      // the combined clause is false, so the whole thing is false\n          [Set(list, {{}}); Set(i, Length(list)+1);], [/*Set(i, 0);*/]);\n      ]);\n    ];\n  ];\n  list;\n];\n\n10 # Subsumes((_x) - (_y) == 0, Not ((_x) - (_z)==0))_(y!=z)    <-- True;\n// suif_tmp0_127_1-72==0 And 78-suif_tmp0_127_1>=0\n20 # Subsumes((_x) - (_y) == 0, (_z) - (_x) >= 0)_(z>=y)        <-- True;\n20 # Subsumes((_x) - (_y) == 0, (_z) - (_x) >  0)_(z>y)         <-- True;\n// suif_tmp0_127_1-72==0 And suif_tmp0_127_1-63>=0\n30 # Subsumes((_x) - (_y) == 0, (_x) - (_z) >= 0)_(y>=z)        <-- True;\n30 # Subsumes((_x) - (_y) == 0, (_x) - (_z) > 0)_(y>z)          <-- True;\n\n90 # Subsumes((_x), (_x))                                       <-- True;\n\n100# Subsumes((_x), (_y))                                       <-- False;\n\n\n// perform unit subsumption and resolutiuon for a unit clause # i\n// a boolean indicated whether there was a change is returned\nDoUnitSubsumptionAndResolution(_list) <--\n[\n    Local(i, j, k, isFalse, isTrue, changed);\n    Set(isFalse, False);\n    Set(isTrue,  False);\n    Set(changed, True);\n\n    //Echo({\"In DoUnitSubsumptionAndResolution\", Nl()});\n\n    While(changed) [\n      Set(changed, False);\n\n      For(i:=1, (Not isFalse And Not isTrue) And i <= Length(list), i++)\n      [\n        If(Length(list[i]) = 1, [\n          Local(x); Set(x, list[i][1]); //n := SimpleNegate(x);\n          //Echo({\"Unit clause \", x, Nl()});\n\n          // found a unit clause, {x}, not use it to modify other clauses\n          For(j:=1, (Not isFalse And Not isTrue) And j <= Length(list), j++)\n          [\n              If(i !=j, [\n                Local(deletedClause); Set(deletedClause, False);\n                For(k:=1, (Not isFalse And Not isTrue And Not deletedClause) And k <= Length(list[j]),  k++)\n                [\n                    // In both of these, if a clause becomes empty, the whole thing is False\n\n                    //Echo({\"   \", x, \" subsumes \", list[j][k], i,j, Subsumes(x, list[j][k]), Nl()});\n\n                    // unit subsumption -- this kills clause j\n                    If(Subsumes(x, list[j][k]), [\n                        // delete this clause\n                        DestructiveDelete(list, j);\n                        j--;\n                        If(i>j, i--);   // i also needs to be decremented\n                        Set(deletedClause, True);\n                        Set(changed, True);\n                        If(Length(list) = 0, [Set(isTrue, True);]);\n                    ],\n                      // else, try unit resolution\n                    If(Contradict(x, list[j][k]), [\n                        //Echo({x, \" contradicts\", list[j][k], Nl()});\n                        DestructiveDelete(list[j], k);\n                        k--;\n                        Set(changed, True);\n                        If(Length(list[j]) = 0, [Set(isFalse, True);]);\n                    ])\n                    );\n                ];\n              ]);\n          ];\n        ]);\n      ];\n    ];\n\n    list;\n];"
  },
  {
    "path": "scripts/logic.rep/code.ys.def",
    "content": "CNF                                     // former LogicSimplify\nLogicSimplify                           // (expression, level=1..3\nCanProve                                // <==> LogicSimplify(expr, 3)\nLogicRemoveTautologies                  // not clear is this will stay, but it is eq. to LogicSimplify(expr, 2)\nSubsumes\n//~\n//|\n//&\n=>\n}"
  },
  {
    "path": "scripts/logic.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef( \"=>\" , \"logic1\",\"implies\" );\nOMDef( \"CNF\"          ,          \"yacas\",\"cnf\"                      );\nOMDef( \"LogicSimplify\",          \"yacas\",\"logic_simplify\"           );\nOMDef( \"CanProve\"     ,          \"yacas\",\"can_prove\"                );\nOMDef( \"LogicRemoveTautologies\", \"yacas\",\"logic_remove_tautologies\" );\nOMDef( \"Subsumes\"     ,          \"yacas\",\"subsumes\"                 );\n// The following appear in the def file, but commented out:\n//     \"~\",  \"yacas\", \"Not\"\n//     \"|\",  \"yacas\", \"Or\"\n//     \"&\",  \"yacas\", \"And\"\n"
  },
  {
    "path": "scripts/multivar.rep/code.ys",
    "content": "\n// The basic container for multivariates\nRuleBase(\"MultiNomial\",{vars,terms});\n\n// using the sparse tree driver for multivariate polynomials\n//Use(\"multivar.rep/sparsenomial.ys\");\n//Use(\"multivar.rep/partialdensenomial.ys\");\n\nIf(IsBound(MultiNomialDriver),\n  `Use(@MultiNomialDriver),\n  Use(\"multivar.rep/sparsenomial.ys\"));\n\n// Code that can build the internal representation of a multivariate polynomial\nUse(\"multivar.rep/makemulti.ys\");\n\n\nMM(_expr) <--  MM(expr,MultiExpressionList(expr));\nMM(_expr,_vars) <--  MakeMultiNomial(expr,vars);\n\nMultiSimp(_expr) <--\n[\n  Local(vars);\n  vars:=MultiExpressionList(expr);\n//Echo({\"step1 \",MM(expr,vars)});\n  MultiSimp2(MM(expr,vars));\n];\n\n10 # MultiSimp2(_a / _b) <--\n[\n  Local(c1,c2,gcd,cmn,vars);\n\n\n  c1 := MultiContentTerm(a);\n  c2 := MultiContentTerm(b);\n  gcd:=If(IsRational(c1[2]) And IsRational(c2[2]), Gcd(c1[2],c2[2]), 1);\n  c1[2] := c1[2]/gcd;\n  c2[2] := c2[2]/gcd;\n\n  cmn:=Min(c1[1],c2[1]);\n  c1[1] := c1[1] - cmn;\n  c2[1] := c2[1] - cmn;\n\n  vars:=MultiVars(a);\n  Check(vars = MultiVars(b),\"incompatible Multivars to simplify\");\n\n  (NormalForm(CreateTerm(vars,c1))/NormalForm(CreateTerm(vars,c2)))\n    *(NormalForm(MultiPrimitivePart(a))/NormalForm(MultiPrimitivePart(b)));\n];\n\n20 # MultiSimp2(expr_IsMulti) <--\n[\n  NormalForm(MultiContent(expr))*NormalForm(MultiPrimitivePart(expr));\n];\n30 # MultiSimp2(_expr) <-- expr;\n\nMultiContent(multi_IsMulti)\n<--\n[\n  Local(least,gcd);\n  Set(least, MultiDegree(multi));\n  Set(gcd,MultiLeadingCoef(multi));\n  ScanMultiNomial(\"MultiContentScan\",multi);\n  CreateTerm(MultiVars(multi),MultiContentTerm(multi));\n];\n\nMultiContentTerm(multi_IsMulti)\n<--\n[\n  Local(least,gcd);\n  Set(least, MultiDegree(multi));\n  Set(gcd,MultiLeadingCoef(multi));\n  ScanMultiNomial(\"MultiContentScan\",multi);\n  {least,gcd};\n];\n\nMultiContentScan(_coefs,_fact) <--\n[\n  Set(least,Min({least,coefs}));\n  Set(gcd,If(IsRational(gcd) And IsRational(fact), Gcd(gcd,fact), 1));\n];\nUnFence(\"MultiContentScan\",2);\n\nMultiPrimitivePart(MultiNomial(vars_IsList,_terms))\n<--\n[\n  Local(cont);\n  Set(cont,MultiContentTerm(MultiNomial(vars,terms)));\n  Set(cont,CreateTerm(vars,{-cont[1],1/(cont[2])}));\n  MultiNomialMultiply(MultiNomial(vars,terms), cont);\n];\n\n10 # MultiRemoveGcd(x_IsMulti/y_IsMulti) <--\n[\n  Local(gcd);\n  Set(gcd,MultiGcd(x,y));\n  Set(x,MultiDivide(x,{gcd})[1][1]);\n  Set(y,MultiDivide(y,{gcd})[1][1]);\n  x/y;\n];\n20 # MultiRemoveGcd(_x) <-- x;\n\n\n\n5 # MultiDegree(MultiNomial(_vars,_term))_(Not(IsList(term))) <-- {};\n10 # MultiDegree(MultiNomial(_vars,{})) <-- FillList(-Infinity,Length(vars));\n20 # MultiDegree(MultiNomial(_vars,_terms))\n   <-- (MultiLeadingTerm(MultiNomial(vars,terms))[1]);\n\n\n10 # MultiLeadingCoef(MultiNomial(_vars,_terms))\n   <-- (MultiLeadingTerm(MultiNomial(vars,terms))[2]);\n\n10 # MultiLeadingMono(MultiNomial(_vars,{})) <-- 0;\n20 # MultiLeadingMono(MultiNomial(_vars,_terms))\n   <-- Multiply(vars^(MultiDegree(MultiNomial(vars,terms))));\n\n20 # MultiLeadingTerm(_m) <-- MultiLeadingCoef(m) * MultiLeadingMono(m);\n\nMultiVars(MultiNomial(_vars,_terms)) <-- vars;\n\n20 # MultiLT(multi_IsMulti)\n   <-- CreateTerm(MultiVars(multi),MultiLeadingTerm(multi));\n\n\n/*************************************************************\n  MultiDivide :\n  input\n    f - a multivariate polynomial\n    g[1 .. n] - a list of polynomials to divide by\n  output\n    {q[1 .. n],r} such that f = q[1]*g[1] + ... + q[n]*g[n] + r\n\n  Basically quotient and remainder after division by a group of\n  polynomials.\n**************************************************************/\n20 # MultiDivide(_f,g_IsList) <--\n[\n  Local(i,v,q,r,nr);\n  v:=MultiExpressionList(f+Sum(g));\n  f:=MakeMultiNomial(f,v);\n  nr := Length(g);\n  For(i:=1,i<=nr,i++)\n  [\n    g[i] := MakeMultiNomial(g[i],v);\n  ];\n  {q,r}:=MultiDivide(f,g);\n  q:=MapSingle(\"NormalForm\",q);\n  r:=NormalForm(r);\n  {q,r};\n];\n\n10 # MultiDivide(f_IsMulti,g_IsList) <--\n[\n  Local(i,nr,q,r,p,v,finished);\n  Set(nr, Length(g));\n  Set(v, MultiVars(f));\n  Set(q, FillList(0,nr));\n  Set(r, 0);\n  Set(p, f);\n  Set(finished,MultiZero(p));\n  Local(plt,glt);\n  While (Not finished)\n  [\n    Set(plt, MultiLT(p));\n    For(i:=1,i<=nr,i++)\n    [\n      Set(glt, MultiLT(g[i]));\n\n      if (MultiDegree(glt) = MultiDegree(plt) Or MultiTermLess({MultiDegree(glt),1}, {MultiDegree(plt),1}))\n      if (Select({{n},n<0},MultiDegree(plt)-MultiDegree(glt)) = {})\n      [\n        Local(ff);\n      Set(ff, CreateTerm(v,{MultiDegree(plt)-MultiDegree(glt),MultiLeadingCoef(plt)/MultiLeadingCoef(glt)}));\n        q[i] := q[i] + ff;\n        Local(ltbefore,ltafter);\n        Set(ltbefore,MultiLeadingTerm(p));\n//        Echo(ltbefore,MultiLeadingTerm(p));\n        Set(p, p - ff*g[i]);\n        Set(ltafter,MultiLeadingTerm(p));\n//        Echo(ltbefore,MultiLeadingTerm(p));\n        if (ltbefore[1] = ltafter[1])\n        [\n          Set(ltafter,MultiLT(p));\n          Set(p,p-ltafter);\n        ];\n//        Echo(ltbefore,MultiLeadingTerm(p));\n        Set(i,nr+2);\n      ];\n    ];\n\n    If (i = nr+1,\n    [\n      Set(r, r + LocalSymbols(a,b)(Subst(a,b)plt));\n      Set(p,  p - LocalSymbols(a,b)(Subst(a,b)plt));\n    ]);\n//Echo(p);\n    Set(finished,MultiZero(p));\n  ];\n  {q,r};\n];\n\n\n//TODO optimize this! keeps on converting to and from internal format!\n\n10 # MultiGcd( 0,_g) <-- g;\n10 # MultiGcd(_f, 0) <-- f;\n\n20 # MultiGcd(_f,_g) <--\n[\n  Local(v);\n  v:=MultiExpressionList(f+g);  //hier\n  NormalForm(MultiGcd(MakeMultiNomial(f,v),MakeMultiNomial(g,v)));\n];\n\n\n5 # MultiGcd(f_IsMulti,g_IsMulti)_(MultiTermLess({MultiDegree(f),1},{MultiDegree(g),1})) <--\n[\n//Echo(\"lesser\");\n  MultiGcd(g,f);\n];\n\n5  # MultiGcd(MultiNomial(_vars,_terms),g_IsMulti)_(MultiDegree(MultiNomial(vars,terms)) = MultiDegree(g))\n     <-- CreateTerm(vars,{FillList(0,Length(vars)),1});\n\n5  # MultiGcd(MultiNomial(_vars,_terms),g_IsMulti)_(Select({{n},n<0},MultiDegree(MultiNomial(vars,terms))-MultiDegree(g)) != {})\n     <-- CreateTerm(vars,{FillList(0,Length(vars)),1});\n\n5  # MultiGcd(MultiNomial(_vars,_terms),g_IsMulti)_(NormalForm(g) = 0)\n     <-- CreateTerm(vars,{FillList(0,Length(vars)),1});\n10 # MultiGcd(f_IsMulti,g_IsMulti) <--\n[\n  LocalSymbols(a)\n  [\n    Set(f,Subst(a,a)f);\n    Set(g,Subst(a,a)g);\n  ];\n  Local(new);\n  While(g != 0)\n  [\n//Echo(\"before f\",f,NormalForm(f));\n//Echo(\"before g\",g,NormalForm(g));\n    Set(new, MultiDivide(f,{g}));\n//Echo(\"new g\",NormalForm(new[1][1]),NormalForm(new[2]));\nIf(new[1][1]=0,\n[\n  g:=MakeMultiNomial(1,MultiVars(f));\n//Echo(\"PRIM \",MultiPrimitivePart(g));\n  new[2]:=0;\n]);\n    Set(new, new[2]);\n    Set(f,g);\n    Set(g,new);\n\n//Echo(\"after f\",f,NormalForm(f));\n//Echo(\"after g\",g,NormalForm(g));\n  ];\n  MultiPrimitivePart(f);\n];\n\n\n\nMultiDivTerm(MultiNomial(_vars,_term1),MultiNomial(_vars,_term2)) <--\n[\n  Local(lm1,lm2);\n  Set(lm1,MultiLeadingTerm(MultiNomial(vars,term1)) );\n  Set(lm2,MultiLeadingTerm(MultiNomial(vars,term2)) );\n  CreateTerm(vars,{lm1[1]-lm2[1],lm1[2] / lm2[2]});\n];\nMultiS(_g,_h,MultiNomial(_vars,_terms)) <--\n[\n  Local(gamma);\n\n  gamma :=Max(MultiDegree(g),MultiDegree(h));\n  Local(result,topterm);\n  topterm := MM(Multiply(vars^gamma), vars);\n\n  result :=\n    MultiDivTerm(topterm,MultiLT(g))*g -\n    MultiDivTerm(topterm,MultiLT(h))*h;\n\n  result;\n];\n\n\n/*\n  Groebner : Calculate the Groebner basis of a set of polynomials.\n  Nice example of its power is\n\nIn> TableForm(Groebner({x*(y-1),y*(x-1)}))\n x*y-x\n x*y-y\n y-x\n y^2-y\nIn> Factor(y^2-y)\nOut> y*(y-1);\n\nFrom which you can see that x = y, and x^2 = x so x is 0 or 1.\n\n*/\n\nGroebner(f_IsList) <--\n[\n  Local(vars,i,j,S,nr,r);\n  nr:=Length(f);\n  vars:=VarList(f);\n  For(i:=1,i<=nr,i++)\n  [\n    f[i] := MakeMultiNomial(f[i],vars);\n  ];\n  S:={};\n  For(i:=1,i<nr,i++)\n  For(j:=i+1,j<=nr,j++)\n  [\n    r := (MultiDivide(MultiS(f[i],f[j],f[i]),f)[2]);\n    If(NormalForm(r) != 0, S:= r:S);\n    f:=Concat(f,S);\n    S:={};\n    nr:=Length(f);\n  ];\n  MapSingle(\"NormalForm\",Concat(f));\n];\n"
  },
  {
    "path": "scripts/multivar.rep/code.ys.def",
    "content": "MM\nMakeMultiNomial\nMultiSimp\nMultiDivide\nMultiGcd\nMultiNomial\nMultiContent\nMultiPrimitivePart\nMultiRemoveGcd\nMultiDegree\nMultiLeadingCoef\nMultiLeadingMono\nMultiLeadingTerm\nMultiLT\nMultiVars\nMultiS\nMultiDivTerm\nGroebner\n}\n"
  },
  {
    "path": "scripts/multivar.rep/makemulti.ys",
    "content": "\n/* code pertaining to creating the internal format for multivariate\n   polynomials (the inverse of NormalForm\n\n- MultiExpressionList(x)\n  extract all variable-like sub-expressions from the main expression,\n  including functions, which can then get treated as if they were\n  a variable.\n- IsMultiExpression(x)\n  determing whether 'x' can be a 'variable' for a multiNomial\n- IsMulti(x)\n  returns True if 'x' is a multivariate expression in internal format.\n  Useful for transformation rules.\n */\n\nMultiExpressionList(_expr) <-- VarList(expr,\"IsMultiExpression\");\n10 # IsMultiExpression(_x + _y) <-- False;\n10 # IsMultiExpression(_x - _y) <-- False;\n10 # IsMultiExpression(   - _y) <-- False;\n10 # IsMultiExpression(_x * _y) <-- False;\n10 # IsMultiExpression(_x / _y) <-- False;\n10 # IsMultiExpression(_x ^ y_IsPositiveInteger) <-- False;\n11 # IsMultiExpression(_x ^ _y)_(IsPositiveInteger(Simplify(y))) <-- False;\n//10 # IsMultiExpression(x_IsConstant) <-- False;\n10 # IsMultiExpression(x_IsMultiConstant) <-- False;\n\n//TODO: shouldn't this be more global? The problem right now is\n// that IsConstant/IsVariable take Pi to be a constant...\nIsMultiConstant(_n) <-- (VarList(n,\"IsVr\")={});\n10 # IsVr(n_IsNumber) <-- False;\n10 # IsVr(n_IsFunction) <-- False;\n10 # IsVr(n_IsString) <-- False;\n20 # IsVr(_n) <-- True;\n100 # IsMultiExpression(_x) <-- True;\n\n10 # IsMulti(MultiNomial(vars_IsList,_terms)) <-- True;\n20 # IsMulti(_anything) <-- False;\n\n\n\nLocalSymbols(a,vars,pow)  [\n  20 #  MultiSingleFactor(_vars,_a,_pow) <--\n    [\n      Local(term);\n      term:={FillList(0,Length(vars)),1};\n      term[1][Find(vars,a)] := pow;\n      CreateTerm(vars,term);\n    ];\n];\nLocalSymbols(x,y,vars)  [\n10 #  MakeMultiNomial(x_IsMultiConstant,vars_IsList) <--\n      CreateTerm(vars,{FillList(0,Length(vars)),x});\n20 #  MakeMultiNomial(_x,vars_IsList)_(Contains(vars,x)) <-- MultiSingleFactor(vars,x,1);\n30 #  MakeMultiNomial(_x + _y,vars_IsList) <--\n      MakeMultiNomial(x,vars) + MakeMultiNomial(y,vars);\n30 #  MakeMultiNomial(_x * _y,vars_IsList) <--\n      MakeMultiNomial(x,vars) * MakeMultiNomial(y,vars);\n30 #  MakeMultiNomial(- _x,vars_IsList) <-- -MakeMultiNomial(x,vars);\n30 #  MakeMultiNomial(_x - _y,vars_IsList) <--\n      MakeMultiNomial(x,vars) - MakeMultiNomial(y,vars);\n30 #  MakeMultiNomial(MultiNomial(_vars,_terms),vars_IsList)\n      <-- MultiNomial(vars,terms);\n\n// This rule would accept almost all terms, assuming them to be const.\n100 #  MakeMultiNomial(_x,vars_IsList) <--\n      [\n      CreateTerm(vars,{FillList(0,Length(vars)),x});\n      ];\n\n];\n\nLocalSymbols(x,y,z,vars,gcd,a,a)  [\n  20 #  MakeMultiNomial(_x / (_y / _z),vars_IsList)\n     <-- MakeMultiNomial((x*z) / y,vars_IsList);\n  20 #  MakeMultiNomial((_x / _y) / _z,vars_IsList)\n     <-- MakeMultiNomial((x*z) / y,vars_IsList);\n  25 #  MakeMultiNomial(_x / y_IsConstant,vars_IsList)_(Not IsConstant(x))\n     <-- MakeMultiNomial(1/y,vars)*MakeMultiNomial(x,vars);\n  30 #  MakeMultiNomial(_x / _y,vars_IsList) <--\n        [\n          Local(result);\n//Echo(\"1...\",x);\n//Echo(\"2...\",y);\n          Set(result,MultiRemoveGcd(MakeMultiNomial(x,vars)/MakeMultiNomial(y,vars)));\n//Echo(\"3...\",result);\n          result;\n        ];\n  ];\n\n\nMultiNomial(_vars,_x) + MultiNomial(_vars,_y) <--\n\t   MultiNomialAdd(MultiNomial(vars,x), MultiNomial(vars,y));\nMultiNomial(_vars,_x) * MultiNomial(_vars,_y) <--\n           MultiNomialMultiply(MultiNomial(vars,x), MultiNomial(vars,y));\nMultiNomial(_vars,_x) - MultiNomial(_vars,_y) <--\n        MultiNomialAdd(MultiNomial(vars,x), MultiNomialNegate(MultiNomial(vars,y)));\n                      - MultiNomial(_vars,_y) <--\n        MultiNomialNegate(MultiNomial(vars,y));\nMultiNomial(_vars,_x) / MultiNomial(_vars,_x) <-- MakeMultiNomial(1, vars);\n\nLocalSymbols(x,n,vars)  [\n30 #  MakeMultiNomial(_x ^ n_IsInteger,vars_IsList)_(Contains(vars,x)) <--\n      MultiSingleFactor(vars,x,n);\n40 #  MakeMultiNomial(_x ^ n_IsPositiveInteger,vars_IsList) <--\n      [\n        Local(mult,result);\n        Set(mult,MakeMultiNomial(x,vars));\n        Set(result,MakeMultiNomial(1,vars));\n\tWhile(n>0)\n        [\n          If(n&1 != 0, Set(result, MultiNomialMultiply(result,mult)));\n          Set(n,n>>1);\n          If(n!=0,Set(mult,MultiNomialMultiply(mult,mult)));\n        ];\n        result;\n      ];\n\n  15 #  MakeMultiNomial(_x ^ _n,vars_IsList)_(Not(IsInteger(n)) And IsInteger(Simplify(n))) <--\n        MakeMultiNomial( x ^  Simplify(n),vars);\n\n  50 #  MakeMultiNomial(_x ^ (_n),vars_IsList)_(Contains(vars,x)) <--\n        [\n          Set(n,Simplify(n));\n          If(IsInteger(n),\n            MultiSingleFactor(vars,x,n),\n            MultiSingleFactor(vars,x^n,1)\n  \t    );\n        ];\n];\n\n\nx_IsMulti + (y_IsMulti/z_IsMulti) <-- ((x*z+y)/z);\n(y_IsMulti/z_IsMulti) + x_IsMulti <-- ((x*z+y)/z);\n(y_IsMulti/z_IsMulti) + (x_IsMulti/w_IsMulti) <-- ((y*w+x*z)/(z*w));\n(y_IsMulti/z_IsMulti) - (x_IsMulti/w_IsMulti) <-- ((y*w-x*z)/(z*w));\n(y_IsMulti/z_IsMulti) * (x_IsMulti/w_IsMulti) <-- ((y*x)/(z*w));\n(y_IsMulti/z_IsMulti) / (x_IsMulti/w_IsMulti) <-- ((y*w)/(z*x));\nx_IsMulti - (y_IsMulti/z_IsMulti) <-- ((x*z-y)/z);\n(y_IsMulti/z_IsMulti) - x_IsMulti <-- ((y-x*z)/z);\n(a_IsMulti/(c_IsMulti/b_IsMulti))    <-- ((a*b)/c);\n((a_IsMulti/c_IsMulti)/b_IsMulti)    <-- (a/(b*c));\n((a_IsMulti/b_IsMulti) * c_IsMulti)  <-- ((a*c)/b);\n(a_IsMulti * (c_IsMulti/b_IsMulti))  <-- ((a*c)/b);\n- ((a_IsMulti)/(b_IsMulti))         <-- (-a)/b;\n\n\nMultiNomialMultiply(\n     MultiNomial(_vars,_terms1)/MultiNomial(_vars,_terms2),\n     MultiNomial(_vars,_terms3)/MultiNomial(_vars,_terms4)) <--\n[\n  MultiNomialMultiply(MultiNomial(vars,terms1),MultiNomial(vars,terms3))/\n  MultiNomialMultiply(MultiNomial(vars,terms2),MultiNomial(vars,terms4));\n];\nMultiNomialMultiply(\n     MultiNomial(_vars,_terms1)/MultiNomial(_vars,_terms2),\n     MultiNomial(_vars,_terms3)) <--\n[\n  MultiNomialMultiply(MultiNomial(vars,terms1),MultiNomial(vars,terms3))/\n  MultiNomial(vars,terms2);\n];\nMultiNomialMultiply(\n     MultiNomial(_vars,_terms3),\n     MultiNomial(_vars,_terms1)/MultiNomial(_vars,_terms2)) <--\n[\n  MultiNomialMultiply(MultiNomial(vars,terms1),MultiNomial(vars,terms3))/\n  MultiNomial(vars,terms2);\n];\n\n10 # MultiNomialMultiply(_a,_b) <--\n[\n  Echo({\"ERROR!\",a,b});\n  Echo({\"ERROR!\",Type(a),Type(b)});\n];\n\n\n\n\n\n"
  },
  {
    "path": "scripts/multivar.rep/sparsenomial.ys",
    "content": "\n/* Implementation of MultiNomials based on sparse representation\n   in the sparsetree.ys code. This is the real driver, using\n   the sparse trees just for representation.\n */\nUse(\"multivar.rep/sparsetree.ys\");\n\nLocalSymbols(NormalMultiNomial) [\n\nCreateTerm(_vars,{_coefs,_fact})\n  <-- MultiNomial(vars,CreateSparseTree(coefs,fact));\n\n/************************************************************\n\nAdding and multiplying multivariate polynomials\n\n************************************************************/\nMultiNomialAdd(MultiNomial(_vars,_x), MultiNomial(_vars,_y))\n    <-- MultiNomial(vars,AddSparseTrees(Length(vars),x,y));\nMultiNomialMultiplyAdd(MultiNomial(_vars,_x), MultiNomial(_vars,_y),_coefs,_fact)\n    <-- MultiNomial(vars,MultiplyAddSparseTrees(Length(vars),x,y,coefs,fact));\nMultiNomialNegate(MultiNomial(_vars,_terms))\n    <--\n    [\n      SparseTreeMap(Hold({{coefs,list},-list}),Length(vars),terms);\n      MultiNomial(vars,terms);\n    ];\nMultiNomialMultiply(MultiNomial(_vars,_x),_multi2)\n    <--\n    [\n      Local(result);\n      Set(result,MakeMultiNomial(0,vars));\n      SparseTreeScan(\"muadm\",Length(vars),x);\n      result;\n    ];\nmuadm(_coefs,_fact) <--\n[\n  Set(result,MultiNomialMultiplyAdd(result, multi2,coefs,fact));\n];\nUnFence(\"muadm\",2);\n\n\n/* NormalForm: done as an explicit loop in stead of using SparseTreeScan\n   for speed. This routine is a lot faster!\n */\n10 # NormalForm(x_IsMulti/y_IsMulti) <-- NormalForm(x)/NormalForm(y);\n20 # NormalForm(MultiNomial(_vars,_list) )\n    <-- NormalMultiNomial(vars,list,1);\n10 # NormalMultiNomial({},_term,_prefact) <-- prefact*term;\n20 # NormalMultiNomial(_vars,_list,_prefact)\n    <--\n    [\n      Local(first,rest,result);\n      Set(first,Head(vars));\n      Set(rest,Tail(vars));\n      Set(result,0);\n      ForEach(item,list)\n      [\n        Set(result,result+NormalMultiNomial(rest,item[2],prefact*first^(item[1])));\n      ];\n      result;\n    ];\n\n]; // LocalSymbols\n\nMultiLeadingTerm(MultiNomial(_vars,_terms))\n    <--\n    [\n      Local(coefs,fact);\n      Set(coefs,MultiDegreeScanHead(terms,Length(vars)));\n      {coefs,fact};\n    ];\n10 # MultiDegreeScanHead(_tree,0)\n   <--\n   [\n     Set(fact,tree);\n     {};\n   ];\n10 # MultiDegreeScanHead(_tree,1)\n   <--\n   [\n     Set(fact,tree[1][2]);\n     {tree[1][1]};\n   ];\n20 # MultiDegreeScanHead(_tree,_depth)\n   <--\n   [\n     (tree[1][1]):MultiDegreeScanHead(tree[1][2],depth-1);\n   ];\nUnFence(\"MultiDegreeScanHead\",2);\n\nScanMultiNomial(_op,MultiNomial(vars_IsList,_terms))\n    <-- SparseTreeScan(op,Length(vars),terms);\nUnFence(\"ScanMultiNomial\",2);\n\n\nMultiDropLeadingZeroes(MultiNomial(_vars,_terms))\n    <--\n    [\n      MultiDropScan(terms,Length(vars));\n      MultiNomial(vars,terms);\n    ];\n10 # MultiDropScan(0,0) <-- True;\n10 # MultiDropScan({_n,0},0) <-- True;\n20 # MultiDropScan(_n,0)\n   <--\n   [\n     False;\n   ];\n30 # MultiDropScan(_tree,_depth)\n   <--\n   [\n     Local(i);\n     For(i:=1,i<=Length(tree),i++)\n     [\n       if (MultiDropScan(tree[i][2],depth-1))\n       [\n         DestructiveDelete(tree,i);\n         i--;\n       ]\n       else\n       [\n         i:=Length(tree);\n       ];\n     ];\n     (tree = {});\n   ];\nUnFence(\"MultiDropScan\",2);\n\n\nMultiTermLess({_deg1,_fact1},{_deg2,_fact2}) <--\n  [\n    Local(deg);\n    Set(deg, deg1-deg2);\n    While(deg != {} And Head(deg) = 0) [ Set(deg, Tail(deg));];\n\n    ((deg = {}) And (fact1-fact2 < 0)) Or\n    ((deg != {}) And (deg[1] < 0));\n  ];\n\n20 # MultiZero(multi_IsMulti) <--\n[\n  CheckMultiZero(MultiDropLeadingZeroes(multi));\n];\n10 # CheckMultiZero(MultiNomial(_vars,{})) <-- True;\n20 # CheckMultiZero(MultiNomial(_vars,_terms)) <-- False;\n\n"
  },
  {
    "path": "scripts/multivar.rep/sparsetree.ys",
    "content": "\n/* Implementation of a sparse tree of Multidimensional matrix elements.\n*/\n\n10 # SparseTreeGet({},_tree) <-- tree;\n20 # SparseTreeGet(_key,_tree) <--\n[\n  SparseTreeGet2(Tail(key),Assoc(Head(key),tree));\n];\n10 # SparseTreeGet2(_key,Empty) <-- 0;\n20 # SparseTreeGet2(_key,_item) <-- SparseTreeGet(key,Head(Tail(item)));\n\n10 # SparseTreeSet({_i},_tree,_newvalue)\n   <--\n[\n  Local(Current,assoc,result);\n  Set(assoc,Assoc(i,tree));\n  if(assoc=Empty)\n  [\n    Set(Current,0);\n    Set(result,Eval(newvalue));\n    AddSparseTrees(1,tree,CreateSparseTree({i},result));\n  ]\n  else\n  [\n    Set(Current,assoc[2]);\n    Set(result,Eval(newvalue));\n    assoc[2] := result;\n  ];\n  result;\n];\n20 # SparseTreeSet(_key,_tree,_newvalue) <--\n[\n  SparseTreeSet2(Tail(key),Assoc(Head(key),tree));\n];\n10 # SparseTreeSet2(_key,Empty) <-- 0;\n20 # SparseTreeSet2(_key,_item)\n   <-- SparseTreeSet(key,Head(Tail(item)),newvalue);\nUnFence(\"SparseTreeSet\",3);\nUnFence(\"SparseTreeSet2\",2);\n\n\nLocalSymbols(SparseTreeMap2,SparseTreeScan2,Muaddterm,MuMuaddterm,\n              meradd,meraddmap) [\n\n10 # CreateSparseTree({},_fact) <-- fact;\n\n20 # CreateSparseTree(_coefs,_fact) \n    <-- CreateSparseTree(Head(coefs),Tail(coefs),fact);\n10 # CreateSparseTree(_first,{},_fact) <-- {{first,fact}};\n20 # CreateSparseTree(_first,_coefs,_fact)\n    <-- {{first,CreateSparseTree(Head(coefs),Tail(coefs),fact)}};\n\n10 # SparseTreeMap(_op,_depth,_list) <-- SparseTreeMap2(list,depth,{});\n10 # SparseTreeMap2(_list,1,_coefs)  \n   <-- \n   ForEach(item,list)\n   [\n     item[2] := ApplyPure(op,{Concat(coefs,{item[1]}),item[2]});\n   ];\n20 # SparseTreeMap2(_list,_depth,_coefs) \n   <--\n   ForEach(item,list)\n   [\n     SparseTreeMap2(item[2],MathAdd(depth,-1),Concat(coefs,{item[1]}));\n   ];\nUnFence(\"SparseTreeMap\", 3);\n[Local(fn);fn:=String(SparseTreeMap2);`UnFence(@fn,3);];\n\n10 # SparseTreeScan(_op,_depth,_list) <-- SparseTreeScan2(list,depth,{});\n10 # SparseTreeScan2(_list,0,_coefs)  <-- ApplyPure(op,{coefs,list});\n20 # SparseTreeScan2(_list,_depth,_coefs) \n   <--\n   ForEach(item,list)\n   [\n     SparseTreeScan2(item[2],MathAdd(depth,-1),Concat(coefs,{item[1]}));\n   ];\nUnFence(\"SparseTreeScan\", 3);\n[Local(fn);fn:=String(SparseTreeScan2);`UnFence(@fn,3);];\n\n\n\n5  # AddSparseTrees(0,_x,_y) <-- x+y;\n10 # AddSparseTrees(_depth,_x,_y) <-- \n[\n  Local(i,t1,t2,inspt);\n  Set(t1,x);\n  Set(i,1);\n  Set(t2,y);\n  Set(inspt,{});\n  While(t1 != {} And t2 != {})\n  [\n    Muaddterm(Head(t1),Head(t2));\n  ];  \n  While(t2 != {})\n  [\n    Set(x,DestructiveAppend(x,Head(t2)));\n    Set(t2,Tail(t2));\n  ];  \n  While(inspt != {})\n  [\n    Set(i,Head(inspt));\n    Set(x,DestructiveInsert(x,i[2],i[1]));\n    Set(inspt,Tail(inspt));\n  ];\n  x;\n];\n\n10 # Muaddterm({_pow,_list1},{_pow,_list2}) <--\n[\n  if(depth=1)\n    [ t1[1][2] := list1+list2; ]\n  else\n    [ t1[1][2] := AddSparseTrees(MathAdd(depth,-1),list1,list2);];\n  Set(t2,Tail(t2));\n];\n20 # Muaddterm(_h1,_h2)_(h1[1]<h2[1]) <--\n[\n  Set(inspt,{h2,i}:inspt);\n  Set(t2,Tail(t2));\n];\n30 # Muaddterm(_h1,_h2)<--\n[\n  Set(t1,Tail(t1));\n  Set(i,MathAdd(i,1));\n];\n[Local(fn);fn:=String(Muaddterm);`UnFence(@fn,2);];\n\n5  # MultiplyAddSparseTrees(0,_x,_y,{},_fact) <-- x+fact*y;\n10 # MultiplyAddSparseTrees(_depth,_x,_y,_coefs,_fact)\n    <--\n[\n  Local(i,t1,t2,inspt,term);\n  Set(t1,x);\n  Set(i,1);\n  Set(t2,y);\n  Set(inspt,{});\n  While(t1 != {} And t2 != {})\n  [\n    MuMuaddterm(Head(t1),Head(t2),coefs);\n  ];  \n\n  While(t2 != {})\n  [\n    Set(term,Head(t2));\n    Set(x,DestructiveAppend(x,meradd(Head(t2),coefs)));\n    Set(t2,Tail(t2));\n  ];  \n  While(inspt != {})\n  [\n    Set(i,Head(inspt));\n    Set(x,DestructiveInsert(x,i[2],i[1]));\n    Set(inspt,Tail(inspt));\n  ];\n  x;\n];\n\n10 # meradd({_ord,rest_IsList},_coefs) <-- \n[\n  Local(head);\n  Set(head,Head(coefs));\n  Set(coefs,Tail(coefs));\n  {ord+head,meraddmap(rest,coefs)};\n];\n20 # meradd({_ord,_rest},_coefs) <-- \n[\n   {ord+Head(coefs),rest*fact};\n];\n\n10 # meraddmap(list_IsList,_coefs) <-- \n[\n  Local(result);\n  Set(result,{});\n  ForEach(item,list)\n  [\n    DestructiveAppend(result,meradd(item,coefs));\n  ];\n  result;\n];\n[Local(fn);fn:=String(meradd);`UnFence(@fn,2);];\n[Local(fn);fn:=String(meraddmap);`UnFence(@fn,2);];\n\n10 # MuMuaddterm({_pow1,_list1},{_pow2,_list2},_coefs)_(pow1=pow2+coefs[1]) <--\n[\n  if(depth=1)\n    [ t1[1][2] := list1+fact*list2; ]\n  else\n    [ \n      t1[1] := {pow1,MultiplyAddSparseTrees(MathAdd(depth,-1),list1,list2,Tail(coefs),fact)};\n    ];\n  Set(t2,Tail(t2));\n];\n20 # MuMuaddterm(_h1,_h2,_coefs)_(h1[1]<h2[1]+coefs[1]) <--\n[\n//Echo({\"inspt \",h1,h2,coefs});\n  Set(inspt,{meradd(Head(t2),coefs),i}:inspt);\n  Set(t2,Tail(t2));\n];\n30 # MuMuaddterm(_h1,_h2,_coefs)<--\n[\n  Set(t1,Tail(t1));\n  Set(i,MathAdd(i,1));\n];\n[Local(fn);fn:=String(MuMuaddterm);`UnFence(@fn,3);];\n\n\n]; // LocalSymbols\n"
  },
  {
    "path": "scripts/multivar.rep/sparsetree.ys.def",
    "content": "CreateSparseTree\nSparseTreeMap\nSparseTreeScan\nAddSparseTrees\nMultiplyAddSparseTrees\nSparseTreeGet\n}\n"
  },
  {
    "path": "scripts/newly.rep/code.ys",
    "content": "\n\nNl():=\n\"\n\";\n\nNewLine() := WriteN(Nl(),1);\nNewLine(n):= WriteN(Nl(),n);\nSpace() := WriteN(\" \",1);\nSpace(n):= WriteN(\" \",n);\n\nWriteN(string,n) :=\n[\n  Local(i);\n  For(i:=1,i<=n,i++) WriteString(string);\n  True;\n];\n\nUniqueConstant() <--\n[\n  Local(result);\n  result := String(LocalSymbols(C)(C));\n  Atom(StringMid'Get(2,Length(result)-1,result));\n];\n\n\n1 # IsFreeOf({},_expr) <-- True;\n2 # IsFreeOf(var_IsList, _expr) <-- And(IsFreeOf(Head(var),expr), IsFreeOf(Tail(var),expr));\n\n4 # IsFreeOf(_var,{}) <-- True;\n5 # IsFreeOf(_var,expr_IsList) <-- And(IsFreeOf(var,Head(expr)), IsFreeOf(var,Tail(expr)));\n\n/* Accept any variable. */\n10 # IsFreeOf(_expr,_expr) <-- False;\n\n/* Otherwise check all leafs of a function. */\n11 # IsFreeOf(_var,expr_IsFunction) <-- IsFreeOf(var,Tail(Listify(expr)));\n\n/* Else it doesn't depend on any variable. */\n12 # IsFreeOf(_var,_expr) <-- True;\n\n\nFunction(\"IsZeroVector\",{aList}) aList = ZeroVector(Length(aList));\n\nTemplateFunction(\"WithValue\",{var,val,expr})\n[\n  If(IsList(var),\n     ApplyPure(\"MacroLocal\",var),\n     MacroLocal(var)\n    );\n  ApplyPure(\":=\",{var,val});\n  Eval(expr);\n];\n\n\n\nFunction(\"CharacteristicEquation\",{matrix,var})\n   SymbolicDeterminant(matrix-var*Identity(Length(matrix)));\nHoldArg(\"CharacteristicEquation\",var);\n\n// diagonal matrices will be caught by IsUpperTriangular\n10 # EigenValues(_matrix)_(IsMatrix(matrix) And IsUpperTriangular(matrix)) <-- Diagonal(matrix);\n10 # EigenValues(_matrix)_(IsMatrix(matrix) And IsLowerTriangular(matrix)) <-- Diagonal(matrix);\n\n20 # EigenValues(matrix_IsMatrix) <-- [\n    Check(IsSquareMatrix(matrix), \"EigenValues: Argument must be a square matrix\");\n    Roots(CharacteristicEquation(matrix,xx));\n];\n\nEigenVectors(_matrix,_eigenvalues) <--\n[\n  Local(result,n);\n/*  eigenvalues:=N(Eval(eigenvalues));  */\n  n:=Length(eigenvalues);\n  result:={};\n  ForEach(e,eigenvalues)\n  [\n    Local(possible);\n/* Echo({\"1...\",result}); */\n    possible:=OldSolve(matrix*MakeVector(k,n)==e*MakeVector(k,n),MakeVector(k,n))[1];\n/* Echo({\"2...\"}); */\n/* Echo({\"2...\"}); */\n\n    If(Not(IsZeroVector(possible)),\n      DestructiveAppend(result,possible)\n      );\n/* Echo({\"3...\"}); */\n  ];\n  result;\n];\n\n\n\nFunction(\"RationalizeNumber\",{x})\n[\n  Check(IsNumber(x),\"RationalizeNumber: Error: \" : (ToString()Write(x)) :\" is not a number\");\n  Local(n,i);\n  n:=1;\n  i:=0;\n  // We can not take for granted that the internal representation is rounded properly...\n  While(i<=Builtin'Precision'Get() And Not(FloatIsInt(x)))\n  [\n    n:=n*10; x:=x*10;\n    i:=i+1;\n//Echo(x,\"/\",n);\n  ];\n  Floor(x+0.5)/n; //FIXME forced thunking to string representation\n];\n\nFunction(\"Rationalize\",{a'number})\n  Substitute(a'number,{{x},IsNumber(x) And Not(IsInteger(x))},\"RationalizeNumber\");\n\n\n10 # Decimal( n_IsInteger ) <-- {n,{0}};\n10 # Decimal( (n_IsPositiveInteger) / (d_IsPositiveInteger) ) <--\n[\n  Local(result,rev,first,period,repeat,static);\n  result:={Div(n,d)};\n  Decimal(result,Mod(n,d),d,350);\n  rev:=DecimalFindPeriod(result);\n  first:=rev[1];\n  period:=rev[2];\n  repeat:=result[first .. (first+period-1)];\n  static:=result[1 .. (first-1)];\n  DestructiveAppend(static,repeat);\n];\n20 # Decimal(_n/_m)_((n/m)<0) <-- \"-\":Decimal(-n/m);\n\n10 # Decimal(_result , _n , _d,_count ) <--\n[\n  While(count>0)\n  [\n    DestructiveAppend(result,Div(10*n,d));\n    n:=Mod(10*n,d);\n    count--;\n  ];\n];\n\nDecimalFindPeriod(_list) <--\n[\n  Local(period,nr,reversed,first,i);\n  reversed:=Tail(DestructiveReverse(FlatCopy(Tail(list))));\n  nr:=Length(reversed)>>1;\n  period:=1;\n  first:=reversed[1];\n\n  For(i:=1,i<nr,i++)\n  [\n    If(reversed[i+1] = first And DecimalMatches(reversed,i),\n      [\n        period:=i;\n        i:=nr;\n      ]\n      );\n  ];\n\n  first:=Length(list)-period;\n  While(first>1 And list[first] = list[first+period]) first--;\n  first++;\n\n  {first,period};\n];\n\nDecimalMatches(_reversed,_period) <--\n[\n  Local(nr,matches,first);\n  nr:=0;\n  matches:=True;\n  first:=1;\n  While((nr<100) And matches)\n  [\n    matches := (matches And\n       (reversed[first .. (first+period-1)] = reversed[(first+period) .. (first+2*period-1)]));\n    first:=first+period;\n    nr:=nr+period;\n  ];\n  matches;\n];\n\n\n\n\n\n\nLagrangeInt(_var,_list) <--\n[\n  Local(nr);\n  nr:=Length(list);\n  Multiply(FillList(var,nr)-list);\n];\n\nLagrangeInterpolant(list_IsList,_values,_var) <--\n[\n  Local(i,nr,sublist);\n  nr:=Length(list);\n  result:=0;\n  For(i:=1,i<=nr,i++)\n  [\n    sublist:=FlatCopy(list);\n    DestructiveDelete(sublist,i);\n    result:=result + values[i]*LagrangeInt(var,sublist)/LagrangeInt(list[i],sublist);\n  ];\n  result;\n];\n\n\n/* Lagrangian power series reversion. Copied\n   from Knuth seminumerical algorithms */\n\nReversePoly(_f,_g,_var,_newvar,_degree) <--\n[\n  Local(orig,origg,G,V,W,U,n,initval,firstder,j,k,newsum);\n  orig:=MakeUni(f,var);\n  origg:=MakeUni(g,var);\n  initval:=Coef(orig,0);\n  firstder:=Coef(orig,1);\n  V:=Coef(orig,1 .. Degree(orig));\n  V:=Concat(V,FillList(0,degree));\n  G:=Coef(origg,1 .. Degree(origg));\n  G:=Concat(G,FillList(0,degree));\n  W:=FillList(0,Length(V)+2);\n  W[1]:=G[1]/firstder;\n  U:=FillList(0,Length(V)+2);\n  U[1]:=1/firstder;\n  n:=1;\n  While(n<degree-1)\n  [\n    n++;\n    For(k:=0,k<n-1,k++)\n    [\n      newsum:=U[k+1];\n      For(j:=2,j<=k+1,j++)\n      [\n        newsum:=newsum-U[k+2-j]*V[j];\n      ];\n      U[k+1]:=newsum/firstder;\n    ];\n    newsum:=0;\n    For(k:=2,k<=n,k++)\n    [\n      newsum:=newsum - k*U[n+1-k]*V[k];\n    ];\n    U[n]:=newsum/firstder;\n    newsum:=0;\n    For(k:=1,k<=n,k++)\n    [\n      newsum:=newsum + k*U[n+1-k]*G[k]/n;\n    ];\n    W[n]:=newsum;\n  ];\n  DestructiveInsert(W,1,Coef(origg,0));\n  Subst(newvar,newvar-initval)\n    NormalForm(UniVariate(newvar,0,W));\n];\n\n\n\n/* InverseTaylor : given a function y=f(x), determine the Taylor series\n * expansion of the inverse f^-1(y)=x this function around y0=f(x0).\n *\n */\nFunction(\"InverseTaylor\",{var,val,degree,func})\n[\n  Local(l1);\n  l1:=UniTaylor(func,var,val,degree);\n  val+ReversePoly(l1,var,var,var,degree+1);\n];\n\n\n\n/*\nTRun(_f,_g,_degree)<--\n[\n  Local(l2,l3,l4);\n  l2:=ReversePoly(f,g,t,z,degree);\n  l3:=Subst(z,f)l2;\n  l4:=BigOh(l3,t,degree);\n  Echo({g,\" == \",l4});\n  NewLine();\n];\n\nTRun(t+t^2,t,10);\nTRun(t/2-t^2,t,10);\nTRun(t/2-t^2,3+t+t^2/2,10);\nTRun(2+t/2-t^2,t,10);\n*/\n\n/*\nTRun(_f,_degree)<--\n[\n  Local(l2,l3,l4);\n  l2:=InverseTaylor(t,0,degree)f;\n  l3:=Subst(t,Taylor(t,0,degree)f)l2;\n  l4:=BigOh(l3,t,degree);\n\n  Echo({t,\" == \",Simplify(l4)});\n  NewLine();\n];\nTRun(Sin(a*t),3);\nTRun(a^t,3);\nTRun(a^t,3);\nTRun(t+t^2,10);\nTRun(t/2-t^2,10);\nTRun(t/2-t^2,10);\nTRun(2+t/2-t^2,10);\n*/\n\n/////////////////////////////////////////////////\n/// Continued fractions stuff\n/////////////////////////////////////////////////\n\n/// compute the list of continued fraction coefficients for a given number\n/// if order is not given, computes to the end\n10 # ContFracList(_n) <-- ContFracList(n, Infinity);\n/// compute list of given length\n10 # ContFracList(_n, _depth)_(depth <= 0) <-- {};\n20 # ContFracList(n_IsInteger, _depth) <-- {n};\n// prevent infinite loop when in numeric mode\n30 # ContFracList(n_IsNumber, _depth) _InNumericMode() <-- NonN(ContFracList(Rationalize(n), depth));\n\n40 # ContFracList(n_IsNumber, _depth) <-- ContFracList(Rationalize(n), depth);\n\n/* n/m = Div(n,m) + 1/( m/Mod(n,m) ) */\n35 # ContFracList((n_IsNegativeInteger) / (m_IsInteger), _depth) <-- Push( ContFracList(m/Mod(n,m), depth-1) , Div(n,m)-1);\n\n40 # ContFracList((n_IsInteger) / (m_IsInteger), _depth) <-- Push( ContFracList(m/Mod(n,m), depth-1) , Div(n,m));\n\n/// main interface\n10 # ContFrac(_n) <-- ContFrac(n, 6);\n50 # ContFrac(_n,_depth) <-- ContFracEval(ContFracList(n, depth), rest);\n\n//////////////////////////////////////////////////\n/// ContFracEval: evaluate continued fraction from the list of coefficients\n//////////////////////////////////////////////////\n/// Each coefficient is either a single expression or a list of 2 expressions, giving the term and the numerator of the current level in the fraction.\n/// ContFracEval({{a0, b0}, {a1, b1}, ...}) = a0+b0/(a1+b1/(...))\n/// ContFracEval({a0, a1, ...}) = a0+1/(a1+1/(...))\n\n10 # ContFracEval({}, _rest) <-- rest;\n// finish recursion here\n10 # ContFracEval({{_n, _m}}, _rest) <-- n+m+rest;\n15 # ContFracEval({_n}, _rest) <-- n+rest;\n/// Continued fractions with nontrivial numerators\n20 # ContFracEval(list_IsList, _rest)_(IsList(Head(list))) <-- Head(Head(list)) + Tail(Head(list)) / ContFracEval(Tail(list), rest);\n/// Continued fractions with unit numerators\n30 # ContFracEval(list_IsList, _rest) <-- Head(list) + 1 / ContFracEval(Tail(list), rest);\n\n/// evaluate continued fraction: main interface\nContFracEval(list_IsList) <-- ContFracEval(list, 0);\n\n//////////////////////////////////////////////////\n/// continued fractions for polynomials\n//////////////////////////////////////////////////\n\n40 # ContFrac(n_CanBeUni,_depth)_(Length(VarList(n)) = 1) <--\n[\n  ContFracDoPoly(n,depth,VarList(n)[1]);\n];\n\n5  # ContFracDoPoly(_exp,0,_var) <-- rest;\n5  # ContFracDoPoly(0,0,_var) <-- rest;\n10 # ContFracDoPoly(_exp,_depth,_var) <--\n[\n  Local(content,exp2,first,second);\n  first:=Coef(exp,var,0);\n  exp:=exp-first;\n  content:=Content(exp);\n  exp2:=DivPoly(1,PrimitivePart(exp),var,5+3*depth)-1;\n  second:=Coef(exp2,0);\n  exp2 := exp2 - second;\n  first+content/((1+second)+ContFracDoPoly(exp2,depth-1,var));\n];\n\n\n//////////////////////////////////////////////////\n/// NearRational, GuessRational\n//////////////////////////////////////////////////\n\n/// find rational number with smallest num./denom. near a given number x\n/// See: HAKMEM, MIT AI Memo 239, 02/29/1972, Item 101C\nNearRational(_x) <-- NearRational(x, Floor(1/2*Builtin'Precision'Get()));\nNearRational(x_IsRationalOrNumber, prec_IsInteger) <-- [\n    Local(x1, x2, i,  old'prec);\n    old'prec := Builtin'Precision'Get();\n  Builtin'Precision'Set(prec + 8);  // 8 guard digits (?)\n    x1 := ContFracList(N(Eval(x+10^(-prec))));\n    x2 := ContFracList(N(Eval(x-10^(-prec))));\n\n    If(InVerboseMode(), Echo(\"NearRational: x      = \", N(Eval(x           ))));\n    If(InVerboseMode(), Echo(\"NearRational: xplus  = \", N(Eval(x+10^(-prec)))));\n    If(InVerboseMode(), Echo(\"NearRational: xmin   = \", N(Eval(x-10^(-prec)))));\n\n    If(InVerboseMode(), Echo(\"NearRational: Length(x1) = \", Length(x1),\" \",x1));\n    If(InVerboseMode(), Echo(\"NearRational: Length(x2) = \", Length(x2),\" \",x1));\n    // find where the continued fractions for \"x1\" and \"x2\" differ\n    // prepare result in \"x1\" and length of result in \"i\"\n    For (i:=1, i<=Length(x1) And i<=Length(x2) And x1[i]=x2[i], i++ ) True;\n    If(\n        i>Length(x1),\n        // \"x1\" ended but matched, so use \"x2\" as \"x1\"\n        x1:=x2,\n        If(\n            i>Length(x2),\n        // \"x2\" ended but matched, so use \"x1\"\n            True,\n        // neither \"x1\" nor \"x2\" ended and there is a mismatch at \"i\"\n        // apply recipe: select the smalest of the differing terms\n            x1[i]:=Min(x1[i],x2[i])\n        )\n    );\n    // recipe: x1dd 1 to the lx1st term unless it's the lx1st in the originx1l sequence\n    //Ayal added this line, i could become bigger than Length(x1)!\n    If(InVerboseMode(), Echo({\"NearRational: using \", i, \"terms of the continued fraction\"}));\n    If(i>Length(x1),i:=Length(x1));\n    x1[i] := x1[i] + If(i=Length(x1), 0, 1);\n    Builtin'Precision'Set(old'prec);\n    ContFracEval(Take(x1, i));\n];\n\n/// guess the rational number behind an imprecise number\n/// prec parameter is the max number of digits you can have in the denominator\nGuessRational(_x) <-- GuessRational(x, Floor(1/2*Builtin'Precision'Get()));\nGuessRational(x_IsRationalOrNumber, prec_IsInteger) <-- [\n    Local(denom'estimate, cf, i);\n    denom'estimate := 1;\n    cf := ContFracList(x);\n    For(i:=2, i<=Length(cf) And denom'estimate < 10^prec, i++)\n        [   // estimate the denominator\n            denom'estimate := denom'estimate * If(\n                cf[i] = 1,\n                If(\n                    i+2<=Length(cf),    // have at least two more terms, do a full estimate\n                    RoundTo(N(Eval(cf[i]+1/(cf[i+1]+1/cf[i+2]))), 3),\n                    // have only one more term\n                    RoundTo(N(Eval(cf[i]+1/cf[i+1])), 3)\n                ),\n                // term is not 1, use the simple estimate\n                cf[i]\n            );\n        ];\n    If (denom'estimate < 10^prec,\n        If(InVerboseMode(), Echo({\"GuessRational: all \", i, \"terms are within limits\"})),\n        i-- // do not use the last term\n    );\n    i--;    // loop returns one more number\n    If(InVerboseMode(), Echo({\"GuessRational: using \", i, \"terms of the continued fraction\"}));\n    ContFracEval(Take(cf, i));\n];\n\n//////////////////////////////////////////////////\n/// BracketRational: find two rational approximations\n//////////////////////////////////////////////////\n\n/// Return a list of two rational numbers r1, r2 such that r1<r<r2 and |r2-r1| < eps*|r|\nBracketRational(r,eps):=\n[\n    Local(n,cflist, r1, r2);\n    cflist := ContFracList(r);\n    n:=2;\n    r1 := ContFracEval(Take(cflist,n));\n    r2 := -r1;\n    // find two successive approximations and check that they differ by less than |eps*r|\n    While (n<Length(cflist) And ( Abs(N(Eval(r2-r1))) > Abs(N(Eval(eps*r)) ) ) )\n    [\n        r2 := r1;\n        n++;\n        r1 := ContFracEval(Take(cflist,n));\n    ];\n    // now r1 and r2 are some rational numbers.\n    // decide whether the search was successful.\n    If(\n        n=Length(cflist),\n        {}, // return empty list if not enough precision\n        If(N(Eval(r-r1))>0,\n            {r1, r2},   // successive approximations are always bracketing, we only need to decide their order\n            {r2, r1}\n        )\n    );\n];\n\n/** MatchLinear(variable,expression)\n */\nLocalSymbols(a,b)[\n\n10 # MatchLinear(var_IsAtom,expr_CanBeUni(var)) <--\n[\n  Set(expr,MakeUni(expr,var));\n  MatchLinear(expr);\n];\n20 # MatchLinear(_var,_expr) <-- False;\n\n10 # MatchLinear(_expr)_(Degree(expr,var)<2) <--\n[\n  Check(IsUniVar(expr),ToString()Echo({\"Incorrect argument \",expr,\" passed to MatchLinear\"}));\n\n//TODO if I enable these checks, then integration fails (only users of this function any way). Can this be removed? Where are these variables cleared any way?\n//  Check(a = Hold(a), ToString()(Echo({\"Found bound variable a which should have been unbound, in MatchLinear: \", a, \"=\", Eval(a)})));\n//  Check(b = Hold(b), ToString()(Echo({\"Found bound variable b which should have been unbound, in MatchLinear: \", b, \"=\", Eval(b)})));\n\n  a := Coef(expr,1);\n  b := Coef(expr,0);\n  True;\n];\n20 # MatchLinear(_expr) <-- False;\nUnFence(\"MatchLinear\",1);\nUnFence(\"MatchLinear\",2);\n\n/** MatchPureSquared(variable,expression) - matches expressions\n *  of the form a*x^2+b.\n */\n10 # MatchPureSquared(var_IsAtom,_sign2,_sign0,expr_CanBeUni(var)) <--\n[\n  Set(expr,MakeUni(expr,var));\n  MatchPureSquared(expr,sign2,sign0);\n];\n20 # MatchPureSquared(_var,_sign2,_sign0,_expr) <-- False;\n\n10 # MatchPureSquared(_expr,_sign2,_sign0)_(Degree(expr,var)=2 And\n                                    Coef(expr,1) = 0 And\n                    IsNumber(Coef(expr,0)) And\n                    IsNumber(Coef(expr,2)) And\n                    Coef(expr,0)*sign0 > 0 And\n                    Coef(expr,2)*sign2 > 0\n                    ) <--\n[\n  Check(IsUniVar(expr),ToString()Echo({\"Incorrect argument \",expr,\" passed to MatchLinear\"}));\n//TODO if I enable these checks, then integration fails (only users of this function any way). Can this be removed? Where are these variables cleared any way?\n//  Check(a = Hold(a), \"Found bound variable which should have been unbound, in MatchLinear\");\n//  Check(b = Hold(b), \"Found bound variable which should have been unbound, in MatchLinear\");\n  a := Coef(expr,2);\n  b := Coef(expr,0);\n  True;\n];\n20 # MatchPureSquared(_expr,_sign2,_sign0) <-- False;\nUnFence(\"MatchPureSquared\",3);\nUnFence(\"MatchPureSquared\",4);\n\nMatched'a() := a;\nMatched'b() := b;\n\n\n\n]; // LocalSymbols a,b\n\nStringReplace(from_IsString, to_IsString, s_IsString) <-- [\n    Local(i, m, n, r, d);\n\n    m := Length(from);\n    n := Length(s);\n\n    r := \"\";\n\n    For (i := 1, i <= n - m + 1, i := i + d)\n        If (s[i .. i + m - 1] = from, [ r := r : to; d := m; ], [ r := r : s[i]; d := 1; ]);\n\n    If (m > 1, r := r : s[n - m + 2 .. n]);\n\n    r;\n];\n\n// Manuel Bronstein, Symbolic Integration I: Transcendental Functions\n// Polynomial Pseudo-Division\nPolyPseudoDivide(A_CanBeUni, B_CanBeUni, x_IsAtom) <-- [\n    Local(b, N, Q, R, delta);\n    b := LeadingCoef(B, x);\n    N := Degree(A, x) - Degree(B, x) + 1;\n    Q := 0;\n    R := A;\n    delta := Degree(R, x) - Degree(B, x);\n    While (R != 0 And delta >= 0) [\n        T := LeadingCoef(R,x)*x^delta;\n        N := N - 1;\n        Q := b * Q + T;\n        R := Expand(b * R - T * B);\n        delta := Degree(R, x) - Degree(B, x);\n    ];\n    {NormalForm(MakeUni(b^N * Q, x)), NormalForm(MakeUni(b^N * R, x))};\n];\n\n// Manuel Bronstein, Symbolic Integration I: Transcendental Functions\n// Subresultant\nSubResultant(A_CanBeUni, B_CanBeUni, x_IsAtom) <-- [\n    Local(R, i, j, k, gamma, delta, beta);\n\n    R := {A, B};\n    i := 1;\n    gamma := {-1};\n    delta := {Degree(A, x) - Degree(B, x)};\n    beta := {(-1)^(delta[1] + 1)};\n    r := {};\n\n    While (Not IsZero(R[i + 1])) [\n        DestructiveAppend(r, LeadingCoef(R[i + 1], x));\n        {Q, RR} := PolyPseudoDivide(R[i], R[i + 1], x);\n        DestructiveAppend(R, Simplify(RR / beta[i]));\n        DestructiveAppend(gamma, (-r[i])^delta[i]*gamma[i]^(1-delta[i]));\n        i := i + 1;\n        DestructiveAppend(delta, Degree(R[i], x) - Degree(R[i + 1], x));\n        DestructiveAppend(beta, -r[i-1] * gamma[i]^delta[i]);\n    ];\n\n    k := i - 1;\n    If (Degree(R[k + 1], x) > 0, [\n        { 0, Append(R[1 .. k + 1], 0) };\n    ], [\n        If (Degree(R[k], x) = 1, [\n            { R[k + 1], Append(R[1 .. k + 1], 0) };\n        ], [\n            Local(s, c);\n            s := 1;\n            c := 1;\n            For (j := 1, j < k, j++) [\n                If (IsOdd(Degree(R[j], x)) And IsOdd(Degree(R[j + 1], x)), s := -s);\n                c := c * (beta[j] / r[j]^(1 + delta[j]))^Degree(R[j + 1], x) * r[j]^(Degree(R[j], x) - Degree(R[j + 2], x));\n            ];\n            {s * c * R[k + 1]^Degree(R[k], x), Append(R[1 .. k + 1], 0)};\n        ]);\n    ]);\n];\n\n\n// Manuel Bronstein, Symbolic Integration I: Transcendental Functions\n// Hermite Reduction, Mack's linear version\nHermiteReduce(A_CanBeUni, D_CanBeUni, x_IsVariable) <-- [\n    Local(g, Dm, Ds);\n    g := 0;\n\n    Dm := PolynomialGcd(D, Deriv(x)D, x);\n    Ds := Div(D, Dm);\n    While (Degree(Dm) > 0) [\n        Local(Dm2, Dms, B, C);\n        Dm2 := PolynomialGcd(Dm, Deriv(x)Dm, x);\n        Dms := Div(Dm, Dm2);\n        {B, C} := ExtendedEuclidean(Div(-Ds*Deriv(x)Dm, Dm), Dms, A);\n        A := C - Div((Deriv(x)B)*Ds, Dms);\n        g := g + B/Dm;\n        Dm := Dm2;\n    ];\n\n    // FIXME: use Cancel() when available\n    Dm := PolynomialGcd(A, Ds, x);\n\n    {g, Div(A, Dm) / Div(Ds, Dm)};\n];\n\n// Manuel Bronstein, Symbolic Integration I: Transcendental Functions\n// Lazard-Rioboo-Trager algorithm\nIntRationalLogPart(A_CanBeUni, D_CanBeUni, x_IsVariable) <-- [\n\n    Local(i, j, r, t, R, PRS, Q, S, n, result);\n\n    {R, PRS} := SubResultant(D, A - t * (Deriv(x)D), x);\n\n    Q := SquareFreeFactorize(R, t);\n\n    n := Max(MatrixColumn(Q, 2));\n\n    S := {};\n\n    For(i:=1,i<=n,i++) [\n        If (i = Degree(D), [\n            DestructiveAppend(S, D);\n        ], [\n            Local(A, Qi, Si);\n            ForEach(pr, PRS) [\n                If (Degree(pr, x) = i, Si := pr);\n            ];\n            A := SquareFreeFactorize(LeadingCoef(Si, x), t);\n            j := Find(MatrixColumn(Q, 2), i);\n            Qi := If (j > 0, Q[j][1], 1);\n            ForEach(Aj, A) [\n                Si := Si / PolynomialGcd(Aj[1], Qi, t)^Aj[2];\n            ];\n            DestructiveAppend(S, Si);\n        ]);\n    ];\n\n    result := 0;\n\n    ForEach (Qi, Q) [\n        Local(c, cc);\n\n        i := Qi[2];\n        Qi := Qi[1];\n\n        Si := MakeUni(S[i], x);\n\n        cc := {};\n        ForEach (c, Si[3]) [\n            DestructiveAppend(cc, Rem(c, Qi));\n        ];\n\n        result := result + SumLog(t, Qi, 0, NormalForm(UniVariate(Si[1], Si[2], cc)));\n    ];\n\n    result;\n];\n\n// Manuel Bronstein, Symbolic Integration I: Transcendental Functions\n// Rational function integration\nIntegrateRationalFunction(N_CanBeUni, D_CanBeUni, x_IsVariable) <-- [\n    Local(g, h, Q, R, p);\n\n    {g, h} := HermiteReduce(N, D, x);\n\n    Q := Div(Numer(h), Denom(h));\n    R := Rem(Numer(h), Denom(h));\n\n    p := g + Integrate(x)Q;\n\n    If (R = 0, p, p + IntRationalLogPart(R, Denom(h),x));\n];\n"
  },
  {
    "path": "scripts/newly.rep/code.ys.def",
    "content": "Nl\nNewLine\nSpace\nUniqueConstant\nIsFreeOf\nIsZeroVector\nWithValue\nCharacteristicEquation\nEigenValues\nEigenVectors\nRationalize\nContFrac\nContFracList\nContFracEval\nNearRational\nGuessRational\nBracketRational\nDecimal\nLagrangeInterpolant\nReversePoly\nInverseTaylor\nSeries\nMatchLinear\nMatchPureSquared\nStringReplace\nPolyPseudoDivide\nSubResultant\nHermiteReduce\nIntRationalLogPart\nIntegrateRationalFunction\n}\n"
  },
  {
    "path": "scripts/nintegrate.rep/code.ys",
    "content": "100 # AdaptiveSimpson(_f, var_IsVariable, a_IsRationalOrNumber, b_IsRationalOrNumber, tol_IsRationalOrNumber) <-- [\n    Local(c, fa, fb, fc, h, q, q1, q2, stp);\n\n    c := (a + b) / 2;\n\n    fa := N(`WithValue(@var, a, f));\n    fc := N(`WithValue(@var, c, f));\n    fb := N(`WithValue(@var, b, f));\n\n    h := (b - a);\n    q := (b - a) / 6 * (fa + 4 * fc + fb);\n\n    stp(f, var, a, b, c, fa, fb, fc, q0, tol) := [\n        Local(d, e, fd, fe, q, q1, q2);\n\n        d := (a + c) / 2;\n        e := (c + b) / 2;\n\n        fd := N(`WithValue(@var, d, f));\n        fe := N(`WithValue(@var, e, f));\n\n        q1 := (c - a) / 6 * (fa + 4 * fd + fc);\n        q2 := (b - c) / 6 * (fc + 4 * fe + fb);\n\n        q := N(q1 + q2);\n\n        If (Abs(q - q0) > tol, [\n            q1 := stp (f, var, a, c, d, fa, fc, fd, q1, tol);\n            q2 := stp (f, var, c, b, e, fc, fb, fe, q2, tol);\n            q := N(q1 + q2);\n        ]);\n\n        q;\n    ];\n\n    stp(f, var, a, b, c, fa, fb, fc, q, tol);\n];\n\n\n100 # (NIntegrate(var_IsVariable, a_IsRationalOrNumber, b_IsRationalOrNumber)(_f)) <-- [\n    AdaptiveSimpson(f, var, a, b, 1e-8);\n];\n"
  },
  {
    "path": "scripts/nintegrate.rep/code.ys.def",
    "content": "NIntegrate\n}\n"
  },
  {
    "path": "scripts/numbers.rep/GaussianIntegers.ys",
    "content": "\nGaussianNorm(z_IsGaussianInteger) <-- Re(z)^2+Im(z)^2;\n\n5  # IsGaussianInteger(x_IsList)\t<-- False;\n\n// ?????? why is the following rule needed?\n// 5  # IsGaussianInteger(ProductPrimesTo257)\t<-- False;\n\n10 # IsGaussianInteger(x_IsComplex)  \t<-- (IsInteger(Re(x)) And IsInteger(Im(x)));\n// to catch IsGaussianInteger(x+2) from Apart\n15 # IsGaussianInteger(_x)\t<-- False;\nFunction(\"IsGaussianPrime\",{x})\n[\n        if( IsGaussianInteger(x) )[\n                if( IsZero(Re(x)) )[\n                        ( Abs(Im(x)) % 4 = 3 And IsPrime(Abs(Im(x))) );\n                ] else if ( IsZero(Im(x)) ) [\n                        ( Abs(Re(x)) % 4 = 3 And IsPrime(Abs(Re(x))) );\n                ] else [\n                        IsPrime(Re(x)^2 + Im(x)^2);\n                ];\n        ] else [\n                False;\n        ];\n\n];\n\n\n/*\n10 # IsGaussianPrime(p_IsInteger) <-- IsPrime(p) And Mod(p,3)=1;\n20 # IsGaussianPrime(p_IsGaussianInteger) <-- IsPrime(GaussianNorm(p));\n*/\n\nGaussianMod(z_IsGaussianInteger,w_IsGaussianInteger) <-- z - w * Round(z/w);\n\n10 # GaussianGcd(n_IsGaussianInteger,m_IsGaussianInteger) <--\n[\n\tIf(N(Abs(m))=0,n, GaussianGcd(m,n - m*Round(n/m) ) );\n];\n\n\nIsGaussianUnit(z_IsGaussianInteger) <-- GaussianNorm(z)=1;\n\n/* GaussianFactorPrime(p): auxiliary function for Gaussian factors.\nIf p is a rational prime of the form 4n+1, we find a factor of p in the\nGaussian Integers. We compute \n  a = (2n)!\nBy Wilson's theorem a^2 is -1 (mod p), it follows that\n\n        p| (a+I)(a-I)\n\nin the Gaussian integers. The desired factor is then the Gaussian GCD of a+i \nand p. Note: If the result is Complex(a,b), then p=a^2+b^2 */\n\nGaussianFactorPrime(p_IsInteger) <-- [\n Local(a,i);\n a := 1;\n For (i:=2,i<=(p-1)/2,i++) a := Mod(a*i,p);\n GaussianGcd(a+I,p);\n];\n\n/* AddGaussianFactor: auxiliary function for Gaussian Factors. \nL is a lists of factors of the Gaussian integer z and p is a Gaussian prime\nthat we want to add to the list. We first find the exponent e of p in the \ndecomposition of z (into Gaussian primes). If it is not zero, we add {p,e}\nto the list */\n\nAddGaussianFactor(L_IsList,z_IsGaussianInteger,p_IsGaussianInteger) <-- \n[\n Local(e);\n e :=0;\n While (IsGaussianInteger(z:= z/p)) e++;\n If (e != 0, DestructiveAppend(L,{p,e}));\n];\n\n/* GaussianFactors(n) : returns a list of factors of n, in a similar \nway to Factors(n).\nIf n is a rational integer, we factor n in the Gaussian integers, by first \nfactor it in the rational integers, and after that factoring each of \nits integer prime factors. */\n\n10 # GaussianFactors(n_IsInteger) <--\n[\n    Local(ifactors,gfactors,p,alpha);\n    ifactors := Factors(n);\n    If (Contains({{-1,1}, {1,1}}, Head(ifactors)), ifactors := Tail(ifactors) );\n    gfactors := {};\n    ForEach(p,ifactors) \n    [\n        If (p[1]=2, [ DestructiveAppend(gfactors,{1+I,p[2]}); \n                      DestructiveAppend(gfactors,{1-I,p[2]}); ]);\n        If (Mod(p[1],4)=3, DestructiveAppend(gfactors,p));\n        If (Mod(p[1],4)=1, [ alpha := GaussianFactorPrime(p[1]);\n                             DestructiveAppend(gfactors,{alpha,p[2]});\n                             DestructiveAppend(gfactors,{Conjugate(alpha),p[2]}); ]);\n    ];\n\n    gfactors;\n];\n\n/* If z is is a Gaussian integer, we find its possible Gassian prime factors, \nby factoring its norm */\n\n20 # GaussianFactors(z_IsGaussianInteger) <--\n[\n Local(n,nfactors,gfactors,p);\n  gfactors :={};\n  n := GaussianNorm(z);\n  nfactors := Factors(n);\n  If (Contains({{-1,1}, {1,1}}, Head(nfactors)), nfactors := Tail(nfactors) );\n  ForEach(p,nfactors) \n  [\n   If (p[1]=2, [ AddGaussianFactor(gfactors,z,1+I);]);\n   If (Mod(p[1],4)=3, AddGaussianFactor(gfactors,z,p[1]));\n   If (Mod(p[1],4)=1, [ Local(alpha); \n                        alpha := GaussianFactorPrime(p[1]);\n                        AddGaussianFactor(gfactors,z,alpha);\n                        AddGaussianFactor(gfactors,z,Conjugate(alpha));\n                      ]);                    \n ];\n gfactors;\n];\n\n// Algorithm adapted from: Number Theory: A Programmer's Guide\n//\t\t\tMark Herkommer\n// Program 8.7.1c, p 264\n// This function needs to be modified to return the factors in\n// data structure instead of printing them out\n\n// THIS FUNCTION IS DEPRECATED NOW!\n// Use GaussianFactors instead (Pablo)\n// I've leave this here so that you can compare the eficiency of one\n// function against the other\n\nFunction(\"FactorGaussianInteger\",{x}) [\n\tCheck( IsGaussianInteger(x), \"FactorGaussianInteger: argument must be a Gaussian integer\");\n\tLocal(re,im,norm,a,b,d,i,j);\n\n\tre:=Re(x);im:=Im(x);\n\n\tIf(re<0, re:=(-re) );\n\tIf(im<0, im:=(-im) );\n\tnorm:=re^2+im^2;\n\n\tif( IsComposite(norm) )[\n\t\tFor(i:=0, i^2 <= norm, i++ )[\t// real part\n\t\t\tFor(j:=0, i^2 + j^2 <= norm, j++)[\t// complex part\n\t\t\t\tif( Not( (i = re And j = im) Or\n\t\t\t\t\t (i = im And j = re) ) )[ // no associates\n\t\t\t\t\td:=i^2+j^2;\n\t\t\t\t\tif( d > 1 )[\n\t\t\t\t\t\ta := re * i + im * j;\n\t\t\t\t\t\tb := im * i - re * j;\n\t\t\t\t\t\tWhile( (Mod(a,d) = 0) And  (Mod(b,d) = 0) ) [\n\t\t\t\t\t\t\tFactorGaussianInteger(Complex(i,j));\n\t\t\t\t\t\t\tre:= a/d;\n\t\t\t\t\t\t\tim:= b/d;\n\t\t\t\t\t\t\ta := re * i + im * j;\n\t\t\t\t\t\t\tb := im * i - re * j;\n\t\t\t\t\t\t\tnorm := re^2 + im^2;\n\t\t\t\t\t\t];\n\t\t\t\t\t];\n\t\t\t\t];\n\t\t\t];\n\t\t];\n\t\tIf( re != 1 Or im != 0, Echo(Complex(re,im)) );\n\t] else [\n\t\tEcho(Complex(re,im));\n\t];\n];\n\n"
  },
  {
    "path": "scripts/numbers.rep/GaussianIntegers.ys.def",
    "content": "IsGaussianUnit\nIsGaussianInteger\nIsGaussianPrime\nGaussianFactorPrime\nGaussianNorm\nGaussianMod\nGaussianFactors\nAddGaussianFactor\nFactorGaussianInteger\nGaussianGcd\n}"
  },
  {
    "path": "scripts/numbers.rep/NumberTheory.ys",
    "content": "/* Implementation of some number theoretical functions for Yacas */\n/* (C) 2002 Pablo De Napoli <pdenapo@yahoo.com> under GNU GPL */\n\n/* DivisorsList(n) = the list of divisors of n */\n\nDivisorsList(n_IsPositiveInteger) <--\n[\n Local(nFactors,f,result,oldresult,x);\n nFactors:= Factors(n); \n result := {1};\n ForEach (f,nFactors)   \n    [ \n      oldresult := result;\n      For (k:=1,k<=f[2],k++)\n        ForEach (x,oldresult) \n\t  result:=Append(result,x*f[1]^k);\n    ]; \n  result;\n];\n\n/* This function performs a sum where sumvar runs through \n   the divisors of n \n   For example SumForDivisors(d,10,d^2) \n   sums d^2 with d walking through the divisors of 10 \n   LocalSymbols is needed since we use Eval() inside \n   Look at Programming in Yacas: Evaluating Variables in the Wrong\n   Scope */\n\nFunction (\"SumForDivisors\",{sumvar,n,sumbody}) LocalSymbols(s,d)\n[\n   Local(s,d);\n   s:=0;\n   ForEach (d,DivisorsList(n))\n   [\n    MacroLocal(sumvar);\n    MacroSet(sumvar,d);\t\n    s:=s+Eval(sumbody);\n   ];\n   s;\n];\nUnFence(\"SumForDivisors\",3);\nHoldArg(\"SumForDivisors\",sumvar);\nHoldArg(\"SumForDivisors\",sumbody); \n\n/* Returns a list of the square-free divisors of n */\nSquareFreeDivisorsList(n_IsPositiveInteger) <--\n[\n Local(nFactors,f,result,oldresult,x);\n nFactors:= Factors(n); \n result := {1};\n ForEach (f,nFactors)   \n    [ \n      oldresult := result;\n        ForEach (x,oldresult) \n\t  result:=Append(result,x*f[1]);\n    ]; \n  result;\n];\n\n/* Returns a list of pairs {d,m}\n   where d runs through the square free divisors of  n \n   and m=Moebius(m) \n   This is much more efficient than making a list of all \n   square-free divisors of n, and then compute Moebius on each of them.\n   It is useful for computing the Cyclotomic polinomials. \n   It can be useful in other computations based on\n   Moebius inversion formula. */\n\nMoebiusDivisorsList(n_IsPositiveInteger) <--\n[\n Local(nFactors,f,result,oldresult,x);\n nFactors:= Factors(n); \n result := {{1,1}};\n ForEach (f,nFactors)   \n    [ \n      oldresult := result;\n        ForEach (x,oldresult) \n\t  result:=Append(result,{x[1]*f[1],-x[2]});\n    ]; \n  result;\n];\n\n/* RamanujanSum(k,n) = the sum of the n-th powers of the\nk-th primitive roots of the identity */\n\n10 # RamanujanSum(k_IsPositiveInteger,0) <-- Totient(k);\n\n20 # RamanujanSum(k_IsPositiveInteger,n_IsPositiveInteger) <--\n[\n Local(s,gcd,d);\n s:= 0;\n gcd := Gcd(n,k);\n ForEach (d,DivisorsList(gcd))\n  s:=s+d*Moebius(k/d);\n s;\n];\n\n\n/** Compute the Jacobi symbol JS(m/n) - n must be odd, both positive.\nSee the Algo book for documentation.\n\n*/\n\n10 # JacobiSymbol(_a, 1) <-- 1;\n15 # JacobiSymbol(0, _b) <-- 0;\n18 # JacobiSymbol(_a, _b) _ (Gcd(a,b)>1) <-- 0;\n\n20 # JacobiSymbol(_a, b_IsOdd)_(a>=Abs(b) Or a<0) <-- JacobiSymbol(Mod(a,Abs(b)),Abs(b));\n\n30 # JacobiSymbol(a_IsEven, b_IsOdd) <--\n[\n\tLocal(c, s);\n\t// compute c,s where a=c*2^s and c is odd\n\t{c,s}:=FindPrimeFactorSimple(a, 2);\t// use the \"Simple\" function because we don't expect a worst case here\n\tIf(Mod(s,2)=1 And Abs(Mod(b,8)-4)=1, -1, 1) * JacobiSymbol(c,b);\n];\n\n40 # JacobiSymbol(a_IsOdd, b_IsOdd) <-- If(Mod(a,4)=3 And Mod(b,4)=3, -1, 1) * JacobiSymbol(b,a);\n\n\n"
  },
  {
    "path": "scripts/numbers.rep/NumberTheory.ys.def",
    "content": "DivisorsList\nSquareFreeDivisorsList\nMoebiusDivisorsList\nSumForDivisors\nRamanujanSum\nJacobiSymbol\n}\n"
  },
  {
    "path": "scripts/numbers.rep/code.ys",
    "content": "\n/// Return integer part of the logarithm of x in given base. Use only integer arithmetic.\n10 # IntLog(_x, _base) _ (base<=1) <-- Undefined;\n/// Use variable steps to speed up operation for large numbers x\n20 # IntLog(_x, _base) <--\n[\n\tLocal(result, step, old'step, factor, old'factor);\n\tresult := 0;\n\told'step := step := 1;\n\told'factor := factor := base;\n\t// first loop: increase step\n\tWhile (x >= factor)\n\t[\n\t\told'factor := factor;\n\t\tfactor := factor*factor;\n\t\told'step := step;\n\t\tstep := step*2;\n\t];\n\tIf(x >= base,\n\t  [\n\t\tstep := old'step;\n\t\tresult := step;\n\t\tx := Div(x, old'factor);\n\t  ],\n\t  step := 0\n\t);\n\t// second loop: decrease step\n\tWhile (step > 0 And x != 1)\n\t[\n\t\tstep := Div(step,2);\t// for each step size down to 1, divide by factor if x is up to it\n\t\tfactor := base^step;\n\t\tIf(\n\t\t\tx >= factor,\n\t\t\t[\n\t\t\t\tx:=Div(x, factor);\n\t\t\t\tresult := result + step;\n\t\t\t]\n\t\t);\n\t];\n\tresult;\n];\n\n/// obtain next number that has good chances of being prime (not divisible by 2,3)\n1# NextPseudoPrime(i_IsInteger)_(i<=1) <-- 2;\n2# NextPseudoPrime(2) <-- 3;\n//2# NextPseudoPrime(3) <-- 5;\n3# NextPseudoPrime(i_IsOdd) <--\n[\n\t// this sequence generates numbers not divisible by 2 or 3\n\ti := i+2;\n\tIf(Mod(i,3)=0, i:=i+2, i);\n/* commented out because it slows things down without a real advantage\n// this works only for odd i>=5\n\ti := If(\n\t\tMod(-i,3)=0,\n\t\ti + 2,\n\t\ti + 2*Mod(-i, 3)\n\t);\n\t// now check if divisible by 5\n\tIf(\n\t\tMod(i,5)=0,\n\t\tNextPseudoPrime(i),\n\t\ti\n\t);\n*/\n];\n// this works only for even i>=4\n4# NextPseudoPrime(i_IsEven) <-- NextPseudoPrime(i-1);\n\n/// obtain the real next prime number -- use primality testing\n1# NextPrime(_i) <--\n[\n\tUntil(IsPrime(i)) i := NextPseudoPrime(i);\n\ti;\n];\n\n/* Returns whether n is a small by a lookup table, very fast.\nThe largest prime number in the table is returned by FastIsPrime(0). */\n\n2 # IsSmallPrime(0) <-- False;\n3 # IsSmallPrime(n_IsInteger) <-- (FastIsPrime(n)>0);\n\n2 # IsPrime(_n)_(Not IsInteger(n) Or n<=1) <-- False;\n3 # IsPrime(n_IsInteger)_(n<=FastIsPrime(0)) <-- IsSmallPrime(n);\n\n/* Fast pseudoprime testing: if n is a prime, then 24 divides (n^2-1) */\n5 # IsPrime(n_IsPositiveInteger)_(n > 4 And Mod(n^2-1,24)!=0) <-- False;\n\n/* Determine if a number is prime, using Rabin-Miller primality\n   testing. Code submitted by Christian Obrecht\n */\n10 # IsPrime(n_IsPositiveInteger) <-- RabinMiller(n);\n\n5  # IsComposite(1)\t\t\t<-- False;\n10 # IsComposite(n_IsPositiveInteger) \t<-- (Not IsPrime(n));\n\n/* Returns whether n is a prime^m. */\n10 # IsPrimePower(n_IsPrime) <-- True;\n10 # IsPrimePower(0) <-- False;\n10 # IsPrimePower(1) <-- False;\n20 # IsPrimePower(n_IsPositiveInteger) <-- (GetPrimePower(n)[2] > 1);\n\n/// Check whether n is a power of some prime integer and return that integer and the power.\n/// This routine uses only integer arithmetic.\n/// Returns {p, s} where p is a prime and n=p^s.\n/// If no powers found, returns {n, 1}. Primality testing of n is not done.\n20 # GetPrimePower(n_IsPositiveInteger) <--\n[\n\tLocal(s, factors, new'factors);\n\t// first, separate any small prime factors\n\tfactors := TrialFactorize(n, 257);\t// \"factors\" = {n1, {p1,s1},{p2,s2},...} or just {n} if no factors found\n\tIf(\n\t\tLength(factors) > 1,\t// factorized into something\n\t\t// now we return {n, 1} either if we haven't completely factorized, or if we factorized into more than one prime factor; otherwise we return the information about prime factors\n\t\tIf(\n\t\t\tfactors[1] = 1 And Length(factors) = 2,\t// factors = {1, {p, s}}, so we have a prime power n=p^s\n\t\t\tfactors[2],\n\t\t\t{n, 1}\n\t\t),\n\t\t// not factorizable into small prime factors -- use main algorithm\n\t\t[\n\t\t\tfactors := CheckIntPower(n, 257);\t// now factors = {p, s} with n=p^s\n\t\t\tIf(\n\t\t\t\tfactors[2] > 1,\t// factorized into something\n\t\t\t\t// now need to check whether p is a prime or a prime power and recalculate \"s\"\n\t\t\t\tIf(\n\t\t\t\t\tIsPrime(factors[1]),\n\t\t\t\t\tfactors,\t// ok, prime power, return information\n\t\t\t\t\t[\t// not prime, need to check if it's a prime power\n\t\t\t\t\t\tnew'factors := GetPrimePower(factors[1]);\t// recursive call; now new'factors = {p1, s1} where n = (p1^s1)^s; we need to check that s1>1\n\t\t\t\t\t\tIf(\n\t\t\t\t\t\t\tnew'factors[2] > 1,\n\t\t\t\t\t\t\t{new'factors[1], new'factors[2]*factors[2]},\t// recalculate and return prime power information\n\t\t\t\t\t\t\t{n, 1}\t// not a prime power\n\t\t\t\t\t\t);\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\t// not factorizable -- return {n, 1}\n\t\t\t\t{n, 1}\n\t\t\t);\n\t\t]\n\t);\n];\n\n/// Check whether n is a power of some integer, assuming that it has no prime factors <= limit.\n/// This routine uses only integer arithmetic.\n/// Returns {p, s} where s is the smallest prime integer such that n=p^s. (p is not necessarily a prime!)\n/// If no powers found, returns {n, 1}. Primality testing of n is not done.\nCheckIntPower(n, limit) :=\n[\n\tLocal(s0, s, root);\n\tIf(limit<=1, limit:=2);\t// guard against too low value of limit\n\t// compute the bound on power s\n\ts0 := IntLog(n, limit);\n\t// loop: check whether n^(1/s) is integer for all prime s up to s0\n\troot := 0;\n\ts := 0;\n\tWhile(root = 0 And NextPseudoPrime(s)<=s0)\t// root=0 while no root is found\n\t[\n\t\ts := NextPseudoPrime(s);\n\t\troot := IntNthRoot(n, s);\n\t\tIf(\n\t\t\troot^s = n,\t// found root\n\t\t\tTrue,\n\t\t\troot := 0\n\t\t);\n\t];\n\t// return result\n\tIf(\n\t\troot=0,\n\t\t{n, 1},\n\t\t{root, s}\n\t);\n];\n\n/// Compute integer part of s-th root of (positive) integer n.\n// algorithm using floating-point math\n10 # IntNthRoot(_n, 2) <-- Floor(MathSqrt(n));\n20 # IntNthRoot(_n, s_IsInteger) <--\n[\n\tLocal(result, k);\n\tGlobalPush(Builtin'Precision'Get());\n\t// find integer k such that 2^k <= n^(1/s) < 2^(k+1)\n\tk := Div(IntLog(n, 2), s);\n\t// therefore we need k*Ln(2)/Ln(10) digits for the floating-point calculation\n\tBuiltin'Precision'Set(2+Div(k*3361, 11165));\t// 643/2136 < Ln(2)/Ln(10) < 3361/11165\n\tresult := Round(MathExp(MathDivide(Internal'LnNum(MathDivide(n, 2^(k*s))), s))*2^k);\n\tBuiltin'Precision'Set(GlobalPop());\n\t// result is rounded and so it may overshoot (we do not use Floor above because numerical calculations may undershoot)\n\tIf(result^s>n, result-1, result);\n];\n\n/* algorithm using only integer arithmetic.\n(this is slower than the floating-point algorithm for large numbers because all calculations are with long integers)\nIntNthRoot1(_n, s_IsInteger) <--\n[\n\tLocal(x1, x2, x'new, y1);\n\t// initial guess should always undershoot\n\t//\tx1:= 2 ^ Div(IntLog(n, 2), s); \t// this is worse than we can make it\n\tx1 := IntLog(n,2);\n\t// select initial interval using (the number of bits in n) mod s\n\t// note that if the answer is 1, the initial guess must also be 1 (not 0)\n\tx2 := Div(x1, s);\t// save these values for the next If()\n\tx1 := Mod(x1, s)/s;\t// this is kept as a fraction\n\t// now assign the initial interval, x1 <= root <= x2\n\t{x1, x2} := If(\n\t\tx1 >= 263/290,\t// > Ln(15/8)/Ln(2)\n\t\tDiv({15,16}*2^x2, 8),\n\t\tIf(\n\t\tx1 >= 373/462,\t// > Ln(7/4)/Ln(2)\n\t\tDiv({7,8}*2^x2, 4),\n\t\tIf(\n\t\tx1 >= 179/306,\t// > Ln(3/2)/Ln(2)\n\t\tDiv({6,7}*2^x2, 4),\n\t\tIf(\n\t\tx1 >= 113/351,\t// > Ln(5/4)/Ln(2)\n\t\tDiv({5,6}*2^x2, 4),\n\t\tDiv({4,5}*2^x2, 4)\t// between x1 and (5/4)*x1\n\t))));\n\t// check whether x2 is the root\n\ty1 := x2^s;\n\tIf(\n\t\ty1=n,\n\t\tx1 := x2,\n\t\t// x2 is not a root, so continue as before with x1\n\t\ty1 := x1^s\t// henceforth, y1 is always x1^s\n\t);\n\t// Newton iteration combined with bisection\n\tWhile(y1 < n)\n\t[\n//\tEcho({x1, x2});\n\t\tx'new := Div(x1*((s-1)*y1+(s+1)*n), (s+1)*y1+(s-1)*n) + 1;\t// add 1 because the floating-point value undershoots\n\t\tIf(\n\t\t\tx'new < Div(x1+x2, 2),\n\t\t\t// x'new did not reach the midpoint, need to check progress\n\t\t\tIf(\n\t\t\t\tDiv(x1+x2, 2)^s <= n,\n\t\t\t\t// Newton's iteration is not making good progress, so leave x2 in place and update x1 by bisection\n\t\t\t\tx'new := Div(x1+x2, 2),\n\t\t\t\t// Newton's iteration knows what it is doing. Update x2 by bisection\n\t\t\t\tx2 := Div(x1+x2, 2)\n\t\t\t)\n\t\t\t// else, x'new reached the midpoint, good progress, continue\n\t\t);\n\t\tx1 := x'new;\n\t\ty1 := x1^s;\n\t];\n\tIf(y1=n, x1, x1-1);\t// subtract 1 if we overshot\n];\n*/\n\nCatalanNumber(_n) <--\n[\n\tCheck( IsPositiveInteger(n), \"CatalanNumber: Error: argument must be positive\" );\n\tBin(2*n,n)/(n+1);\n];\n\n/// Product of small primes <= 257. Computed only once.\nLocalSymbols(p, q)\n[\n\t// p:= 1;\n\tProductPrimesTo257() := 2*3*[\n\t\tIf(\n\t\t\tIsInteger(p),\n\t\t\tp,\n\t\t\tp := Multiply(Select({{q}, Mod(q^2,24)=1 And IsSmallPrime(q)}, 5 .. 257))\n\t\t);\n//\t\tp;\n\t];\n];\n\n10 # \tRepunit(0)\t<-- 0;\n// Number consisting of n 1's\nRepunit(n_IsPositiveInteger) <--\n[\n\t(10^n-1)/9;\n];\n\n10 # \tHarmonicNumber(n_IsInteger)\t<-- HarmonicNumber(n,1);\nHarmonicNumber(n_IsInteger,r_IsPositiveInteger) <--\n[\n\t// small speed up\n\tif( r=1 )[\n\t\tSum(k,1,n,1/k);\n\t] else [\n\t\tSum(k,1,n,1/k^r);\n\t];\n];\nFunction(\"FermatNumber\",{n})[\n\tCheck(IsPositiveInteger(n),\n\t\t\"FermatNumber: argument must be a positive integer\");\n\t2^(2^n)+1;\n];\n\n// Algorithm adapted from:\n// Elementary Number Theory, David M. Burton\n// Theorem 6.2 p112\n5  # Divisors(0)\t<-- 0;\n5  # Divisors(1)\t<-- 1;\n// Unsure about if there should also be a function that returns\n// n's divisors, may have to change name in future\n10 # Divisors(_n)\t<--\n[\n\tCheck(IsPositiveInteger(n),\n\t\t\"Divisors: argument must be positive integer\");\n\tLocal(len,sum,factors,i);\n\tsum:=1;\n\tfactors:=Factors(n);\n\tlen:=Length(factors);\n\tFor(i:=1,i<=len,i++)[\n\t\tsum:=sum*(factors[i][2]+1);\n\t];\n\tsum;\n];\n10 # ProperDivisors(_n) <--\n[\n        Check(IsPositiveInteger(n),\n                \"ProperDivisors: argument must be positive integer\");\n\tDivisors(n)-1;\n];\n10 # ProperDivisorsSum(_n) <--\n[\n        Check(IsPositiveInteger(n),\n                \"ProperDivisorsSum: argument must be positive integer\");\n        DivisorsSum(n)-n;\n];\n\n// Algorithm adapted from:\n// Elementary Number Theory, David M. Burton\n// Theorem 6.2 p112\n5  # DivisorsSum(0)\t<-- 0;\n5  # DivisorsSum(1)\t<-- 1;\n10 # DivisorsSum(_n) \t<--\n[\n\tCheck(IsPositiveInteger(n),\n\t\t\"DivisorsSum: argument must be positive integer\");\n\tLocal(factors,i,sum,len,p,k);\n\tp:=0;k:=0;\n\tfactors:={};\n\tfactors:=Factors(n);\n\tlen:=Length(factors);\n\tsum:=1;\n\tFor(i:=1,i<=len,i++)[\n\t\tp:=factors[i][1];\n\t\tk:=factors[i][2];\n\t\tsum:=sum*(p^(k+1)-1)/(p-1);\n\t];\n\tsum;\n];\n\n// Algorithm adapted from:\n// Elementary Number Theory, David M. Burton\n// Definition 6.3 p120\n\n5  # Moebius(1)\t<-- 1;\n10 # Moebius(_n)\t<--\n[\n\tCheck(IsPositiveInteger(n),\n\t\t\"Moebius: argument must be positive integer\");\n        Local(factors,i,repeat);\n\trepeat:=0;\n        factors:=Factors(n);\n        len:=Length(factors);\n        For(i:=1,i<=len,i++)[\n\t\tIf(factors[i][2]>1,repeat:=1);\n        ];\n\tIf(repeat=0,(-1)^len,0);\n\n];\n\n// Algorithm adapted from:\n// Elementary Number Theory, David M. Burton\n// Theorem 7.3 p139\n\n10 # Totient(_n)\t<--\n[\n\tCheck(IsPositiveInteger(n),\n\t\t\"Totient: argument must be positive integer\");\n\tLocal(i,sum,factors,len);\n\tsum:=n;\n        factors:=Factors(n);\n        len:=Length(factors);\n        For(i:=1,i<=len,i++)[\n\t\tsum:=sum*(1-1/factors[i][1]);\n        ];\n\tsum;\n];\n// Algorithm adapted from:\n// Elementary Number Theory, David M. Burton\n// Definition 9.2 p191\n\n10 # LegendreSymbol(_a,_p)\t<--\n[\n        Check( IsInteger(a) And IsInteger(p) And p>2 And IsCoprime(a,p) And IsPrime(p),\n                \"LegendreSymbol: Invalid arguments\");\n\tIf(IsQuadraticResidue(a,p), 1, -1 );\n];\n\n\nIsPerfect(n_IsPositiveInteger) <-- ProperDivisorsSum(n)=n;\n\n5  # IsCoprime(list_IsList)                     <-- (Lcm(list) = Multiply(list));\n10 # IsCoprime(n_IsInteger,m_IsInteger)\t\t<-- (Gcd(n,m) = 1);\n\n// Algorithm adapted from:\n// Elementary Number Theory, David M. Burton\n// Theorem 9.1 p187\n10 # IsQuadraticResidue(_a,_p) <--\n[\n        Check( IsInteger(a) And IsInteger(p) And p>2 And IsCoprime(a,p) And IsPrime(p),\n                \"IsQuadraticResidue: Invalid arguments\");\n        If(a^((p-1)/2) % p = 1, True, False);\n];\n\n// Digital root of n (repeatedly add digits until reach a single digit).\n10 # DigitalRoot(n_IsPositiveInteger) <-- If(n%9=0,9,n%9);\n\nIsTwinPrime(n_IsPositiveInteger)\t<-- (IsPrime(n) And IsPrime(n+2));\n\nIsAmicablePair(m_IsPositiveInteger,n_IsPositiveInteger) <-- ( ProperDivisorsSum(m)=n And ProperDivisorsSum(n)=m );\n\n5  # IsIrregularPrime(p_IsComposite)\t<-- False;\n// First irregular prime is 37\n5  # IsIrregularPrime(_p)_(p<37)\t<-- False;\n\n// an odd prime p is irregular iff p divides the numerator of a Bernoulli number B(2*n) with\n// 2*n+1<p\n10 # IsIrregularPrime(p_IsPositiveInteger) <--\n[\n\tLocal(i,irregular);\n\n\ti:=1;\n\tirregular:=False;\n\n\tWhile( 2*i + 1 < p And (irregular = False) )[\n\t\tIf( Abs(Numer(Bernoulli(2*i))) % p = 0, irregular:=True );\n\t\ti++;\n\t];\n\tirregular;\n\n];\n\nIsSquareFree(n_IsInteger)\t<-- ( Moebius(n) != 0 );\n\n// Carmichael numbers are odd,squarefree and have at least 3 prime factors\n5  # IsCarmichaelNumber(n_IsEven)\t\t<-- False;\n5  # IsCarmichaelNumber(_n)_(n<561)\t\t<-- False;\n10 # IsCarmichaelNumber(n_IsPositiveInteger)\t<--\n[\n\tLocal(i,factors,length,carmichael);\n\n\tfactors:=Factors(n);\n\tcarmichael:=True;\n\tlength:=Length(factors);\n\tif( length < 3)[\n\t\t carmichael:=False;\n\t] else [\n\t\tFor(i:=1,i<=length And carmichael,i++)[\n\t\t\t//Echo( n-1,\"%\",factors[i][1]-1,\"=\", Mod(n-1,factors[i][1]-1) );\n\t\t\tIf( Mod(n-1,factors[i][1]-1) != 0, carmichael:=False );\n\t\t\tIf(factors[i][2]>1,carmichael:=False);\t// squarefree\n\t\t];\n\t];\n\tcarmichael;\n];\n\nIsCarmichaelNumber(n_IsList) <-- MapSingle(\"IsCarmichaelNumber\",n);\n\n/// the restricted partition function\n/// partitions of length k\n\n5  # PartitionsP(n_IsInteger,0)\t\t  \t<-- 0;\n5  # PartitionsP(n_IsInteger,n_IsInteger)\t<-- 1;\n5  # PartitionsP(n_IsInteger,1)\t\t\t<-- 1;\n5  # PartitionsP(n_IsInteger,2)\t\t\t<-- Floor(n/2);\n5  # PartitionsP(n_IsInteger,3)\t\t\t<-- Round(n^2/12);\n6  # PartitionsP(n_IsInteger,k_IsInteger)_(k>n) <-- 0;\n10 # PartitionsP(n_IsInteger,k_IsInteger)\t<-- PartitionsP(n-1,k-1)+PartitionsP(n-k,k);\n\n/// the number of additive partitions of an integer\n5  # PartitionsP(0)\t<-- 1;\n5  # PartitionsP(1)\t<-- 1;\n// decide which algorithm to use\n10 # PartitionsP(n_IsInteger)_(n<250) <-- PartitionsP'recur(n);\n20 # PartitionsP(n_IsInteger) <-- PartitionsP'HR(n);\n\n/// Calculation using the Hardy-Ramanujan series.\n10 # PartitionsP'HR(n_IsPositiveInteger) <--\n[\n\tLocal(P0, A, lambda, mu, mu'k, result, term, j, k, l, prec, epsilon);\n\tresult:=0;\n\tterm:=1;\t// initial value must be nonzero\n\tGlobalPush(Builtin'Precision'Get());\n\t// precision must be at least Pi/Ln(10)*Sqrt(2*n/3)-Ln(4*n*Sqrt(3))/Ln(10)\n\t// here Pi/Ln(10) < 161/118, and Ln(4*Sqrt(3))/Ln(10) <1 so it is disregarded. Add 2 guard digits and compensate for round-off errors by not subtracting Ln(n)/Ln(10) now\n\tprec := 2+Div(IntNthRoot(Div(2*n+2,3),2)*161+117,118);\n\tBuiltin'Precision'Set(prec);\t// compensate for round-off errors\n\tepsilon := MathPower(10,-prec)*n*10;\t// stop when term < epsilon\n\n\t// get the leading term approximation P0 - compute once at high precision\n\tlambda := N(Sqrt(n - 1/24));\n\tmu := N(Pi*lambda*Sqrt(2/3));\n\t// the hoops with MathDivide are needed to avoid roundoff error at large n due to fixed precision:\n\t// Exp(mu)/(n) must be computed by dividing by n, not by multiplying by 1/n\n\tP0 := N(1-1/mu)*MathDivide(MathExp(mu),(n-MathDivide(1,24))*4*MathSqrt(3));\n\t/*\n\tthe series is now equal to\n\tP0*Sum(k,1,Infinity,\n\t  (\n\t\tExp(mu*(1/k-1))*(1/k-1/mu) + Exp(-mu*(1/k+1))*(1/k+1/mu)\n\t  ) * A(k,n) * Sqrt(k)\n\t)\n\t*/\n\n\tA := 0;\t// this is also used as a flag\n\t// this is a heuristic, because the next term error is expensive\n\t// to calculate and the theoretic bounds have arbitrary constants\n\t// use at most 5+Sqrt(n)/2 terms, stop when the term is nonzero and result stops to change at precision prec\n\tFor(k:=1, k<=5+Div(IntNthRoot(n,2),2) And (A=0 Or Abs(term)>epsilon), k++)\n\t[\n\t\t// compute A(k,n)\n\t\tA:=0;\n\t\tFor(l:=1,l<=k,l++)\n\t\t[\n\t\t\tIf(\n\t\t\t\tGcd(l,k)=1,\n\t\t\t\tA := A + Cos(Pi*\n\t\t\t\t  (\t// replace Exp(I*Pi*...) by Cos(Pi*...) since the imaginary part always cancels\n\t\t\t\t\tSum(j,1,k-1, j*(Mod(l*j,k)/k-1/2)) - 2*l*n\n\t\t\t\t\t// replace (x/y - Floor(x/y)) by Mod(x,y)/y for integer x,y\n\t\t\t\t  )/k)\n\t\t\t);\n\t\t\tA:=N(A);\t// avoid accumulating symbolic Cos() expressions\n\t\t];\n\n\t\tterm := If(\n\t\t\tA=0,\t// avoid long calculations if the term is 0\n\t\t\t0,\n\t\t\tN( A*Sqrt(k)*(\n\t\t\t  [\n\t\t\t  \tmu'k := mu/k;\t// save time, compute mu/k once\n\t\t\t    Exp(mu'k-mu)*(mu'k-1) + Exp(-mu'k-mu)*(mu'k+1);\n\t\t\t  ]\n\t\t\t)/(mu-1) )\n\t\t);\n//\t\tEcho(\"k=\", k, \"term=\", term);\n\t\tresult := result + term;\n//\t\tEcho(\"result\", new'result* P0);\n\t];\n\tresult := result * P0;\n\tBuiltin'Precision'Set(GlobalPop());\n\tRound(result);\n];\n\n// old code for comparison\n\n10 # PartitionsP1(n_IsPositiveInteger) <--\n [\n\t\t Local(C,A,lambda,m,pa,k,h,term);\n\t   GlobalPush(Builtin'Precision'Get());\n\t   // this is an overshoot, but seems to work up to at least n=4096\n\t   Builtin'Precision'Set(10 + Floor(N(Sqrt(n))) );\n\t   pa:=0;\n\t\t C:=Pi*Sqrt(2/3)/k;\n\t\t lambda:=Sqrt(m - 1/24);\n\t   term:=1;\n\t   // this is a heuristic, because the next term error is expensive\n\t   // to calculate and the theoretic bounds have arbitrary constants\n\t   For(k:=1,k<=5+Floor(MathSqrt(n)*0.5) And ( term=0 Or Abs(term)>0.1) ,k++)[\n\t\t\t   A:=0;\n\t\t\t   For(h:=1,h<=k,h++)[\n\t\t\t\t\t   if( Gcd(h,k)=1 )[\n\t\t\t\t\t\t\t   A:=A+Exp(I*Pi*Sum(j,1,k-1,(j/k)*((h*j)/k - Floor((h*j)/k) -1/2))\n- 2*Pi*I*h*n/k );\n\t\t\t\t\t   ];\n\t\t\t   ];\n\t\t\t   If(A!=0, term:= N(A*Sqrt(k)*(Deriv(m) Sinh(C*lambda)/lambda) Where m==n ),term:=0 );\n//\t\t\t   Echo(\"Term \",k,\"is \",N(term/(Pi*Sqrt(2))));\n\t\t\t   pa:=pa+term;\n//\t\t\t   Echo(\"result\", N(pa/(Pi*Sqrt(2))));\n\t   ];\n\t   pa:=N(pa/(Pi*Sqrt(2)));\n\t   Builtin'Precision'Set(GlobalPop());\n\t   Round(pa);\n ];\n\n/// integer partitions by recurrence relation P(n) = Sum(k,1,n, (-1)^(k+1)*( P(n-k*(3*k-1)/2)+P(n-k*(3*k+1)/2) ) ) = P(n-1)+P(n-2)-P(n-5)-P(n-7)+...\n/// where 1, 2, 5, 7, ... is the \"generalized pentagonal sequence\"\n/// this method is faster with internal math for number<300 or so.\nPartitionsP'recur(number_IsPositiveInteger) <--\n[\n\t// need storage of n values PartitionsP(k) for k=1,...,n\n\tLocal(sign, cache, n, k, pentagonal, P);\n\tcache:=Array'Create(number+1,1);\t// cache[n] = PartitionsP(n-1)\n\tn := 1;\n\tWhile(n<number)\t// this will never execute if number=1\n\t[\n\t\tn++;\n\t\t// compute PartitionsP(n) now\n\t\tP := 0;\n\t\tk := 1;\n\t\tpentagonal := 1;\t// pentagonal is always equal to the first element in the k-th pair of the \"pentagonal sequence\" of pairs {k*(3*k-1)/2, k*(3*k+1)/2}\n\t\tsign := 1;\n\t\tWhile(pentagonal<=n)\n\t\t[\n\t\t\tP := P + (cache[n-pentagonal+1]+If(pentagonal+k<=n, cache[n-pentagonal-k+1], 0))*sign;\n\t\t\tpentagonal := pentagonal + 3*k+1;\n\t\t\tk++;\n\t\t\tsign := -sign;\n\t\t];\n\t\tcache[n+1] := P;\t// P(n) computed, store result\n\t];\n\tcache[number+1];\n];\nPartitionsP'recur(0) <-- 1;\n\nEulerian(n_IsInteger,k_IsInteger) <-- Sum(j,0,k+1,(-1)^j*Bin(n+1,j)*(k-j+1)^n);\n\n10 # StirlingNumber1(n_IsInteger,0) <-- If(n=0,1,0);\n10 # StirlingNumber1(n_IsInteger,1) <-- (-1)^(n-1)*(n-1)!;\n10 # StirlingNumber1(n_IsInteger,2) <-- (-1)^n*(n-1)! * HarmonicNumber(n-1);\n10 # StirlingNumber1(n_IsInteger,n-1) <-- -Bin(n,2);\n10 # StirlingNumber1(n_IsInteger,3) <-- (-1)^(n-1)*(n-1)! * (HarmonicNumber(n-1)^2 - HarmonicNumber(n-1,2))/2;\n20 # StirlingNumber1(n_IsInteger,m_IsInteger) <-- \n\tSum(k,0,n-m,(-1)^k*Bin(k+n-1,k+n-m)*Bin(2*n-m,n-k-m)*StirlingNumber2(k-m+n,k));\n\n\n10 # StirlingNumber2(n_IsInteger,0) <-- If(n=0,1,0);\n20 # StirlingNumber2(n_IsInteger,k_IsInteger) <-- Sum(i,0,k-1,(-1)^i*Bin(k,i)*(k-i)^n)/ k! ;\n\n10 # BellNumber(n_IsInteger)\t\t<-- Sum(k,1,n,StirlingNumber2(n,k));\n\n5  # Euler(0)\t\t<-- 1;\n10 # Euler(n_IsOdd)\t<-- 0;\n10 # Euler(n_IsEven)\t<-- - Sum(r,0,n/2-1,Bin(n,2*r)*Euler(2*r));\n10 # Euler(n_IsNonNegativeInteger,_x)\t<-- Sum(i,0,Round(n/2),Bin(n,2*i)*Euler(2*i)*(x-1/2)^(n-2*i)/2^(2*i));\n\n/** Compute an array of Euler numbers using recurrence relations.\n*/\n10 # EulerArray(n_IsInteger) <-- \n[\n\tLocal(E,i,sum,r);\n\tE:=ZeroVector(n+1);\n\tE[1]:=1;\n\tFor(i:=1,2*i<=n,i++)[\n\t\tsum:=0;\t\n\t\tFor(r:=0, r < i ,r++)[\n\t\t\tsum:=sum+Bin(2*i,2*r)*E[2*r+1];\n\t\t];\n\t\tE[2*i+1] := -sum;\n\t];\n\tE;\n];\n\n\n"
  },
  {
    "path": "scripts/numbers.rep/code.ys.def",
    "content": "BellNumber\nCatalanNumber\nDigitalRoot\nDivisors\nDivisorsSum\nEuler\nEulerArray\nEulerian\nFermatNumber\nGetPrimePower\nHarmonicNumber\nIntLog\nIntNthRoot\nIsAmicablePair\nIsCarmichaelNumber\nIsComposite\nIsCoprime\nIsIrregularPrime\nIsPerfect\nIsPrime\nIsPrimePower\nIsQuadraticResidue\nIsSmallPrime\nIsSquareFree\nIsTwinPrime\nLegendreSymbol\nMoebius\nNextPrime\nNextPseudoPrime\nPartitionsP\nProductPrimesTo257\nProperDivisors\nProperDivisorsSum\nRepunit\nStirlingNumber1\nStirlingNumber2\nTotient\n}\n"
  },
  {
    "path": "scripts/numbers.rep/nthroot.ys",
    "content": "//////\n// $Id: nthroot.ys,v 1.5 2007-05-17 11:56:45 ayalpinkus Exp $\n// calculation/simplifaction of nth roots of nonnegative integers\n// NthRoot         - interface function\n// NthRoot'Calc    - actually calculate/simplifies\n// NthRoot'List    - list table entries for a given n\n// NthRoot'Restore - get a root from lookup table\n// NthRoot'Save    - save a root in lookup table\n// NthRoot'Clear   - clear lookup table\n//////\n\n// LocalSymbols(m,n,r,\n//\t\tNthRoot'Table,\n//\t\tNthRoot'Calc,\n//\t\tNthRoot'List,\n//\t\tNthRoot'Restore,\n//\t\tNthRoot'Save,\n//\t\tNthRoot'Clear)\nLocalSymbols(m,n,r,\n             NthRoot'Table)\n[\n\n// interface function for nth root of m\n// m>=0, n>1, integers\n// m^(1/n) --> f*(r^(1/n))\nNthRoot(m_IsNonNegativeInteger,n_IsInteger)_(n>1) <--\n[\n   Local(r);\n   r:=NthRoot'Restore(m,n);\n   If(Length(r)=0,\n   [\n      r:=NthRoot'Calc(m,n);\n      NthRoot'Save(m,n,r);\n   ]);\n   r;\n];\n\n// internal functions\nFunction(\"NthRoot'Calc\",{m,n})\n[\n   Local(i,j,f,r,in);\n   Set(i,2);\n   Set(j,Ceil(FastPower(m,N(1.0/n))+1));\n   Set(f,1);\n   Set(r,m);\n   // for large j (approx >4000)\n   // using Factors instead of the\n   // following.  would this be \n   // faster in general?\n//Echo(\"i j \",i,\" \",j);\n   While(LessThan(i,j))\n   [\n      Set(in,MathPower(i,n));\n//Echo(\"r in mod \",r, \" \",in,\" \",MathMod(r,in));\n      While(Equals(MathMod(r,in),0))\n      [\n\t Set(f,MathMultiply(f,i));\n\t Set(r,MathDiv(r,in));\n      ];\n      While(Equals(MathMod(r,i),0))   //\n\t Set(r,MathDiv(r,i));         //\n      //Set(i,NextPrime(i));\n      Set(i,NextPseudoPrime(i));\n      Set(j,Ceil(FastPower(r,N(1.0/n))+1));\n   ];\n   //List(f,r);\n   List(f,MathDiv(m,MathPower(f,n))); //\n];\n\n// lookup table utilities\nFunction(\"NthRoot'List\",{n})\n[\n   If(Length(NthRoot'Table)>0,\n   [\n      Local(p,xx);\n      p:=Select({{xx},Head(xx)=n},NthRoot'Table);\n      If(Length(p)=1,Tail(p[1]),List());\n   ],\n   List());\n];\n\nFunction(\"NthRoot'Restore\",{m,n})\n[\n   Local(p);\n   p:=NthRoot'List(n);\n   If(Length(p)>0,\n   [\n      Local(r,xx);\n      r:=Select({{xx},Head(xx)=m},p);\n      If(Length(r)=1,Head(Tail(r[1])),List());\n   ],\n   List());\n];\n\nFunction(\"NthRoot'Save\",{m,n,r})\n[\n   Local(p);\n   p:=NthRoot'List(n);\n   If(Length(p)=0,\n   // create power list and save root\n   DestructiveInsert(NthRoot'Table,1,List(n,List(m,r))),\n   [\n      Local(rr,xx);\n      rr:=Select({{xx},Head(xx)=m},p);\n      If(Length(rr)=0,\n      [\n\t // save root only\n\t DestructiveAppend(p,List(m,r));\n      ],\n      // already saved\n      False);\n   ]);\n];\n\n//TODO why is NthRoot'Table both lazy global and protected with LocalSymbols?\nFunction(\"NthRoot'Clear\",{}) SetGlobalLazyVariable(NthRoot'Table,List());\n\n// create empty table\nNthRoot'Clear();\n\n]; // LocalSymbols(m,n,r,NthRoot'Table);\n\n//////\n//////\n"
  },
  {
    "path": "scripts/numbers.rep/nthroot.ys.def",
    "content": "NthRoot\nNthRoot'Calc\nNthRoot'List\nNthRoot'Save\nNthRoot'Restore\nNthRoot'Clear\n}\n"
  },
  {
    "path": "scripts/numbers.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef( \"BellNumber\",      \"yacas\",\"BellNumber\" );\nOMDef( \"CatalanNumber\",   \"yacas\",\"CatalanNumber\" );\nOMDef( \"DigitalRoot\",     \"yacas\",\"DigitalRoot\" );\nOMDef( \"Divisors\",        \"yacas\",\"Divisors\" );\nOMDef( \"DivisorsSum\",     \"yacas\",\"DivisorsSum\" );\nOMDef( \"Euler\",           \"yacas\",\"Euler\" );\nOMDef( \"EulerArray\",      \"yacas\",\"EulerArray\" );\nOMDef( \"Eulerian\",        \"yacas\",\"Eulerian\" );\nOMDef( \"FermatNumber\",    \"yacas\",\"FermatNumber\" );\nOMDef( \"GetPrimePower\",   \"yacas\",\"GetPrimePower\" );\nOMDef( \"HarmonicNumber\",  \"yacas\",\"HarmonicNumber\" );\nOMDef( \"IntLog\",          \"yacas\",\"IntLog\" );\nOMDef( \"IntNthRoot\",      \"yacas\",\"IntNthRoot\" );\nOMDef( \"IsAmicablePair\",  \"yacas\",\"IsAmicablePair\" );\nOMDef( \"IsCarmichaelNumber\", \"yacas\",\"IsCarmichaelNumber\" );\nOMDef( \"IsComposite\",     \"yacas\",\"IsComposite\" );\nOMDef( \"IsCoprime\",       \"yacas\",\"IsCoprime\" );\nOMDef( \"IsIrregularPrime\", \"yacas\",\"IsIrregularPrime\" );\nOMDef( \"IsPerfect\",       \"yacas\",\"IsPerfect\" );\nOMDef( \"IsPrime\",         \"yacas\",\"IsPrime\" );\nOMDef( \"IsPrimePower\",    \"yacas\",\"IsPrimePower\" );\nOMDef( \"IsQuadraticResidue\", \"yacas\",\"IsQuadraticResidue\" );\nOMDef( \"IsSmallPrime\",    \"yacas\",\"IsSmallPrime\" );\nOMDef( \"IsSquareFree\",    \"yacas\",\"IsSquareFree\" );\nOMDef( \"IsTwinPrime\",     \"yacas\",\"IsTwinPrime\" );\nOMDef( \"LegendreSymbol\",  \"yacas\",\"LegendreSymbol\" );\nOMDef( \"Moebius\",         \"yacas\",\"Moebius\" );\nOMDef( \"NextPrime\",       \"yacas\",\"NextPrime\" );\nOMDef( \"NextPseudoPrime\", \"yacas\",\"NextPseudoPrime\" );\nOMDef( \"PartitionsP\",     \"yacas\",\"PartitionsP\" );\nOMDef( \"ProductPrimesTo257\", \"yacas\",\"ProductPrimesTo257\" );\nOMDef( \"ProperDivisors\",  \"yacas\",\"ProperDivisors\" );\nOMDef( \"ProperDivisorsSum\", \"yacas\",\"ProperDivisorsSum\" );\nOMDef( \"Repunit\",         \"yacas\",\"Repunit\" );\nOMDef( \"StirlingNumber1\", \"yacas\",\"StirlingNumber1\" );\nOMDef( \"StirlingNumber2\", \"yacas\",\"StirlingNumber2\" );\nOMDef( \"Totient\",         \"yacas\",\"Totient\" );\n\n// From GaussianIntegers.ys.def\nOMDef( \"IsGaussianUnit\",    \"yacas\",\"IsGaussianUnit\" );\nOMDef( \"IsGaussianInteger\", \"yacas\",\"IsGaussianInteger\" );\nOMDef( \"IsGaussianPrime\",   \"yacas\",\"IsGaussianPrime\" );\nOMDef( \"GaussianFactorPrime\", \"yacas\",\"GaussianFactorPrime\" );\nOMDef( \"GaussianNorm\",      \"yacas\",\"GaussianNorm\" );\nOMDef( \"GaussianMod\",       \"yacas\",\"GaussianMod\" );\nOMDef( \"GaussianFactors\",   \"yacas\",\"GaussianFactors\" );\nOMDef( \"AddGaussianFactor\", \"yacas\",\"AddGaussianFactor\" );\nOMDef( \"FactorGaussianInteger\", \"yacas\",\"FactorGaussianInteger\" );\nOMDef( \"GaussianGcd\",       \"yacas\",\"GaussianGcd\" );\n\n// From nthroot.ys.def\nOMDef( \"NthRoot\",      \"yacas\",\"NthRoot\" );\nOMDef( \"NthRoot'Calc\", \"yacas\",\"NthRoot'Calc\" );\nOMDef( \"NthRoot'List\", \"yacas\",\"NthRoot'List\" );\nOMDef( \"NthRoot'Save\", \"yacas\",\"NthRoot'Save\" );\nOMDef( \"NthRoot'Restore\", \"yacas\",\"NthRoot'Restore\" );\nOMDef( \"NthRoot'Clear\", \"yacas\",\"NthRoot'Clear\" );\n\n// From NumberTheory.ys.def\nOMDef( \"DivisorsList\", \"yacas\",\"DivisorsList\" );\nOMDef( \"SquareFreeDivisorsList\", \"yacas\",\"SquareFreeDivisorsList\" );\nOMDef( \"MoebiusDivisorsList\",    \"yacas\",\"MoebiusDivisorsList\" );\nOMDef( \"SumForDivisors\", \"yacas\",\"SumForDivisors\" );\nOMDef( \"RamanujanSum\",   \"yacas\",\"RamanujanSum\" );\nOMDef( \"JacobiSymbol\",   \"yacas\",\"JacobiSymbol\" );\n"
  },
  {
    "path": "scripts/odesolver.rep/code.ys",
    "content": "/*\n 1) implement more sub-solvers\n 2) test code\n 3) Done: documentation for OdeSolve and OdeTest\n */\n\n10 # OdeLeftHandSideEq(_l == _r) <-- (l-r);\n20 # OdeLeftHandSideEq(_e) <-- e;\n\n10 # OdeNormChange(y(n_IsInteger)) <-- UnList({yyy,n});\n20 # OdeNormChange(y) <-- yyy(0);\n25 # OdeNormChange(y') <-- yyy(1);\n25 # OdeNormChange(y'') <-- yyy(2);\n30 # OdeNormChange(_e) <-- e;\nOdeNormPred(_e) <-- (e != OdeNormChange(e));\n\n\nOdeNormalForm(_e) <--\n[\n  e := Substitute(OdeLeftHandSideEq(e),\"OdeNormPred\",\"OdeNormChange\");\n];\n\n/*TODO better OdeNormalForm?\nOdeNormalForm(_e) <--\n[\n  OdeLeftHandSideEq(e) /:\n    {\n      y <- yyy(0),\n      y' <- yyy(1),\n      y'' <- yyy(2),\n      y(_n) <- yyy(n)\n    };\n];\n*/\n\n10 # OdeChange(yyy(n_IsInteger)) <-- Apply(yn,{n});\n30 # OdeChange(_e) <-- e;\nOdePred(_e) <-- (e != OdeChange(e));\nUnFence(\"OdeChange\",1);\nUnFence(\"OdePred\",1);\nOdeSubstitute(_e,_yn) <--\n[\n  Substitute(e,\"OdePred\",\"OdeChange\");\n];\nUnFence(\"OdeSubstitute\",2);\n\nOdeConstantList(n_IsInteger) <--\n[\n  Local(result,i);\n  result:=ZeroVector(n);\n  For (i:=1,i<=n,i++) result[i]:=UniqueConstant();\n  result;\n];\n\n\nRuleBase(\"OdeTerm\",{px,list});\n\n/*5 # OdeFlatTerm(_x)_[Echo({x});False;] <-- True; */\n\n10# OdeFlatTerm(OdeTerm(_a0,_b0)+OdeTerm(_a1,_b1)) <-- OdeTerm(a0+a1,b0+b1);\n10# OdeFlatTerm(OdeTerm(_a0,_b0)-OdeTerm(_a1,_b1)) <-- OdeTerm(a0-a1,b0-b1);\n10# OdeFlatTerm(-OdeTerm(_a1,_b1)) <-- OdeTerm(-a1,-b1);\n10# OdeFlatTerm(OdeTerm(_a0,_b0)*OdeTerm(_a1,_b1))_\n    (IsZeroVector(b0) Or IsZeroVector(b1)) <--\n[\n  OdeTerm(a0*a1,a1*b0+a0*b1);\n];\n\n10# OdeFlatTerm(OdeTerm(_a0,_b0)/OdeTerm(_a1,_b1))_\n    (IsZeroVector(b1)) <--\n    OdeTerm(a0/a1,b0/a1);\n\n10# OdeFlatTerm(OdeTerm(_a0,b0_IsZeroVector)^OdeTerm(_a1,b1_IsZeroVector)) <--\n    OdeTerm(a0^a1,b0);\n15 # OdeFlatTerm(OdeTerm(_a,_b)) <-- OdeTerm(a,b);\n\n15# OdeFlatTerm(OdeTerm(_a0,_b0)*OdeTerm(_a1,_b1)) <-- OdeTermFail();\n15# OdeFlatTerm(OdeTerm(_a0,b0)^OdeTerm(_a1,b1)) <-- OdeTermFail();\n15# OdeFlatTerm(OdeTerm(_a0,b0)/OdeTerm(_a1,b1)) <-- OdeTermFail();\n20 # OdeFlatTerm(a_IsAtom) <-- OdeTermFail();\n\n20 # OdeFlatTerm(_a+_b) <-- OdeFlatTerm(OdeFlatTerm(a) + OdeFlatTerm(b));\n20 # OdeFlatTerm(_a-_b) <-- OdeFlatTerm(OdeFlatTerm(a) - OdeFlatTerm(b));\n20 # OdeFlatTerm(_a*_b) <-- OdeFlatTerm(OdeFlatTerm(a) * OdeFlatTerm(b));\n20 # OdeFlatTerm(_a^_b) <-- OdeFlatTerm(OdeFlatTerm(a) ^ OdeFlatTerm(b));\n20 # OdeFlatTerm(_a/_b) <-- OdeFlatTerm(OdeFlatTerm(a) / OdeFlatTerm(b));\n\nOdeMakeTerm(xx_IsAtom) <-- OdeTerm(xx,FillList(0,10));\nOdeMakeTerm(yyy(_n)) <-- OdeTerm(0,BaseVector(n+1,10));\n\n\n20 # OdeMakeTerm(_xx) <-- OdeTerm(xx,FillList(0,10));\n10 # OdeMakeTermPred(_x+_y) <-- False;\n10 # OdeMakeTermPred(_x-_y) <-- False;\n10 # OdeMakeTermPred(  -_y) <-- False;\n10 # OdeMakeTermPred(_x*_y) <-- False;\n10 # OdeMakeTermPred(_x/_y) <-- False;\n10 # OdeMakeTermPred(_x^_y) <-- False;\n20 # OdeMakeTermPred(_rest) <-- True;\n\n\nOdeCoefList(_e) <--\n[\n  Substitute(e,\"OdeMakeTermPred\",\"OdeMakeTerm\");\n];\nOdeTermFail() <-- OdeTerm(Error,FillList(Error,10));\n\n// should check if it is linear...\nOdeAuxiliaryEquation(_e) <--\n[\n\t// extra conversion that should be optimized away later\n\te:=OdeNormalForm(e);\n\te:=OdeSubstitute(e,{{n},aaa^n*Exp(aaa*x)});\n\te:=Subst(Exp(aaa*x),1)e;\n\tSimplify(Subst(aaa,x)e);\n];\n\n/* Solving a Homogeneous linear differential equation \n   with real constant coefficients */\nOdeSolveLinearHomogeneousConstantCoefficients(_e) <--\n[\n  Local(roots,consts,auxeqn);\n\n  /* Try solution Exp(aaa*x), and divide by Exp(aaa*x), which\n   * should yield a polynomial in aaa.\n  e:=OdeSubstitute(e,{{n},aaa^n*Exp(aaa*x)});\n  e:=Subst(Exp(aaa*x),1)e;\n  auxeqn:=Simplify(Subst(aaa,x)e);\n  e:=auxeqn;\n  */\n  e:=OdeAuxiliaryEquation(e);\n  auxeqn:=e;\n\n  If(InVerboseMode(), Echo(\"OdeSolve: Auxiliary Eqn \",auxeqn) );\n\n  \n  /* Solve the resulting polynomial */\n  e := Apply(\"RootsWithMultiples\",{e});\n  e := RemoveDuplicates(e);\n\n  /* Generate dummy constants */\n  if( Length(e) > 0 )[\n    roots:=Transpose(e);\n    consts:= MapSingle(Hold({{nn},Add(OdeConstantList(nn)*(x^(0 .. (nn-1))))}),roots[2]);\n    roots:=roots[1];\n\n    /* Return results */\n    //Sum(consts * Exp(roots*x));\n    Add( consts * Exp(roots*x) );\n  ] else if ( Degree(auxeqn,x) = 2 ) [\n    // we can solve second order equations without RootsWithMultiples\n    Local(a,b,c,roots);\n    roots:=ZeroVector(2);\n\n    // this should probably be incorporated into RootsWithMultiples\n    {c,b,a} := Coef(auxeqn,x,0 .. 2);\n\n    \n    roots := PSolve(a*x^2+b*x+c,x);\n    If(InVerboseMode(),Echo(\"OdeSolve: Roots of quadratic:\",roots) );\n\n    // assuming real coefficients, the roots must come in a complex\n    // conjugate pair, so we don't have to check both\n    // also, we don't need to check to repeated root case, because\n    // RootsWithMultiples (hopefully) catches those, except for\n    // the case b,c=0\n\n    if( b=0 And c=0 )[\n\tAdd(OdeConstantList(2)*{1,x});\n    ] else if( IsNumber(N(roots[1])) )[\n\tIf(InVerboseMode(),Echo(\"OdeSolve: Real roots\"));\n\tAdd(OdeConstantList(2)*{Exp(roots[1]*x),Exp(roots[2]*x)});\n    ] else [\n      If(InVerboseMode(),Echo(\"OdeSolve: Complex conjugate pair roots\"));\n      Local(alpha,beta); \n      alpha:=Re(roots[1]);\n      beta:=Im(roots[1]);\n      Exp(alpha*x)*Add( OdeConstantList(2)*{Sin(beta*x),Cos(beta*x)} );\n    ];\n\n  ] else [\n    Echo(\"OdeSolve: Could not find roots of auxilliary equation\");\n  ];\n];\n\n// this croaks on Sin(x)*y'' because OdeMakeTerm does\n10 # OdeOrder(_e) <-- [\n\tLocal(h,i,coefs);\n\n\tcoefs:=ZeroVector(10); //ugly\n\te:=OdeNormalForm(e);\n\n\tIf(InVerboseMode(),Echo(\"OdeSolve: Normal form is\",e));\n\th:=OdeFlatTerm(OdeCoefList(e));\n\tIf(InVerboseMode(),Echo(\"OdeSolve: Flatterm is\",h));\n\n\t// get the list of coefficients of the derivatives\n\t// in decreasing order\n\tcoefs:=Reverse(Listify(h)[3]);\n\tWhile( Head(coefs) = 0 )[\n\t\tcoefs:=Tail(coefs);\n\t];\n\tLength(coefs)-1;\n];\n\n\n10 # OdeSolve(_expr)_(OdeOrder(expr)=0)\t    <-- Echo(\"OdeSolve: Not a differential equation\");\n\n// Solve the ever lovable seperable equation\n\n10 # OdeSolve(y'+_a==_expr)_(IsFreeOf(y,a)) <-- OdeSolve(y'==expr-a);\n10 # OdeSolve(y'-_a==_expr)_(IsFreeOf(y,a)) <-- OdeSolve(y'==expr+a);\n10 # OdeSolve(y'/_a==_expr)_(IsFreeOf(y,a)) <-- OdeSolve(y'==expr*a);\n10 # OdeSolve(_a*y'==_expr)_(IsFreeOf(y,a)) <-- OdeSolve(y'==expr/a);\n10 # OdeSolve(y'*_a==_expr)_(IsFreeOf(y,a)) <-- OdeSolve(y'==expr/a);\n10 # OdeSolve(_a/y'==_expr)_(IsFreeOf(y,a)) <-- OdeSolve(y'==a/expr);\n\n// only works for low order equations\n10 # OdeSolve(y'==_expr)_(IsFreeOf({y,y',y''},expr)) <-- \n[\n\tIf(InVerboseMode(),Echo(\"OdeSolve: Integral in disguise!\"));\n\tIf(InVerboseMode(),Echo(\"OdeSolve: Attempting to integrate \",expr));\n\t\n\t(Integrate(x) expr)+UniqueConstant();\n];\n\n50 # OdeSolve(_e) <--\n[\n  Local(h);\n  e:=OdeNormalForm(e);\n  If(InVerboseMode(),Echo(\"OdeSolve: Normal form is\",e));\n  h:=OdeFlatTerm(OdeCoefList(e));\n  If(InVerboseMode(),Echo(\"OdeSolve: Flatterm is\",h));\n  if (IsFreeOf(Error,h))\n  [\n    OdeSolveLinear(e,h);\n  ]\n  else\n    OdeUnsolved(e);\n];\n\n10 # OdeSolveLinear(_e,OdeTerm(0,_list))_(Length(VarList(list)) = 0) <--\n[\n  OdeSolveLinearHomogeneousConstantCoefficients(OdeNormalForm(e));\n];\n\n100 # OdeSolveLinear(_e,_ode) <-- OdeUnsolved(e);\n\nOdeUnsolved(_e) <-- Subst(yyy,y)e;\n\n\n\n/*\nFT3(_e) <--\n[\n  e:=OdeNormalForm(e);\nEcho({e});\n  e:=OdeCoefList(e);\nEcho({e});\n  e:=OdeFlatTerm(e);\nEcho({e});\n  e;\n];\nOdeBoundaries(_solution,bounds_IsList) <--\n[\n];\n*/\n\nOdeTest(_e,_solution) <--\n[\n  Local(s);\n  s:= `Lambda({n},if (n>0)(D(x,n)(@solution)) else (@solution));\n  e:=OdeNormalForm(e);\n  e:=Apply(\"OdeSubstitute\",{e,s});\n  e:=Simplify(e);\n  e;\n];\n\n\n\n\n"
  },
  {
    "path": "scripts/odesolver.rep/code.ys.def",
    "content": "OdeSolve\nOdeTest\nOdeOrder\n}\n"
  },
  {
    "path": "scripts/openmath.rep/code.ys",
    "content": "////////////////////////\n// Written by Alberto González Palomo and Ayal Pinkus.\n////////////////////////\n\n/* The read-eval-print loop */\n/* It can take one parameter, that is the evaluation count. If it is greater\n   than zero, only that number of iterations will be performed before\n   exiting. This is particularly useful when connecting to Yacas via pipes.\n*/\nRuleBase(\"OMREP\",{});\nRule(\"OMREP\",0,1,True)\n[\n  OMREP(0);// 0 means keep repeating, as usual.\n];\nRuleBase(\"OMREP\",{count});\nLocalSymbols(input,stringOut,result)\nRule(\"OMREP\",1,1,True)\n[\n  Local(input,stringOut,result);\n  While(Not(IsExitRequested()))\n  [\n    Set(errorObject, \"\");\n    TrapError(Set(input, FromString(ConcatStrings(ReadCmdLineString(\"\"),\" \"))OMRead()),Set(errorObject,OMGetCoreError()));\n    If(Not(errorObject = \"\"), errorObject);\n    If (Not(IsExitRequested()) And errorObject=\"\",\n    [\n      Set(stringOut,\"\");\n      Set(result,False);\n      TrapError(Set(stringOut,ToString()[Secure(Set(result,Eval(input)));]),Set(errorObject,OMGetCoreError()));\n      If(Not(errorObject = \"\"), errorObject);\n      If(Not(stringOut = \"\"), WriteString(stringOut));\n      SetGlobalLazyVariable(%,result);\n      If(PrettyPrinter'Get()=\"\",\n      [\n        Apply(\"OMForm\",{result});\n      ],\n      Apply(PrettyPrinter'Get(),{result}));\n      If(count > 0 And (count:=count-1) = 0, Exit());\n    ]);\n  ];\n];\n\n\nLocalSymbols(omindent) [\n  // Function definitions\n  OMIndent() := [omindent := omindent + 2;];\n  OMUndent() := [omindent := omindent - 2;];\n  OMClearIndent() := [omindent := 0;];\n  OMIndentSpace() := Space(omindent);\n\n  // Initialization of indentation\n  OMClearIndent();\n]; // LocalSymbols(omindent)\n\n///////////////////////////////////////////////////////////////////////\n// Output\n\n10 # OMForm(_expression)\n     <--\n     [\n     OMClearIndent();\n     OMEcho(\"<OMOBJ>\");\n     OMIndent();\n     If(IsAtom(expression),\n        If(expression = Atom(\"%\"),\n           Secure(expression := Eval(expression))\n           )\n        );\n     OMFormExpression(expression);\n     OMUndent();\n     OMEcho(\"</OMOBJ>\");\n     ];\n\n10 # OMFormExpression(i_IsString)  <-- [\n  Local (p, s);\n  s := \"\";\n  For (p := 1, p <= Length(i), p++) [\n    Local (c);\n    c := i[p];\n    c := If (c = \"&\", \"&amp;\", c);\n    c := If (c = \"<\", \"&lt;\", c);\n    c := If (c = \">\", \"&gt;\", c);\n    c := If (c = \"\\\"\", \"&quot;\", c);\n    c := If (c = \"'\", \"&apos;\", c);\n    s := s : c;\n  ];\n  OMEcho(\"<OMSTR>\":s:\"</OMSTR>\");\n];\n11 # OMFormExpression(i_IsInteger) <-- OMEcho(\"<OMI>\":String(i):\"</OMI>\");\n12 # OMFormExpression(i_IsNumber)  <-- OMEcho(\"<OMF dec=\\\"\":String(i):\"\\\"/>\");\n13 # OMFormExpression(i_IsConstant)_(OMSymbol()[ String(i) ] != Empty)\n     <-- OMEcho(\"<OMS cd=\\\"\":OMSymbol()[ String(i) ][1]\n                :\"\\\" name=\\\"\":OMSymbol()[ String(i) ][2]:\"\\\"/>\"\n                );\n14 # OMFormExpression(i_IsConstant)// Should we rather evaluate it?\n     <-- OMEcho(\"<OMV name=\\\"\":String(i):\"\\\"/>\");\n15 # OMFormExpression(i_IsVariable)_(OMSymbol()[ String(i) ] != Empty)\n     <-- OMEcho(\"<OMS cd=\\\"\":OMSymbol()[ String(i) ][1]\n                :\"\\\" name=\\\"\":OMSymbol()[ String(i) ][2]:\"\\\"/>\"\n                );\n16 # OMFormExpression(i_IsVariable)\n     <-- OMEcho(\"<OMV name=\\\"\":String(i):\"\\\"/>\");\n16 # OMFormExpression(i_IsVariable)_(i = Empty)\n     <-- False; // This is useful for void expressions.\n\n10 # OMFormExpression(function_IsFunction)_(Type(function) = \"OMError\")\n     <--\n     [\n     Local(cd, name);\n     If(IsList(function[1]),\n        [ cd := function[1][1]; name := function[1][2]; ],\n        [ cd := \"error\";        name := function[1];    ]);\n     OMEcho(\"<OME>\");\n     OMIndent();\n     OMEcho(\"<OMS cd=\\\"\":cd:\"\\\" name=\\\"\":name:\"\\\"/>\");\n     ForEach(i, Tail(function)) OMFormExpression(i);\n     OMUndent();\n     OMEcho(\"</OME>\");\n     ];\n10 # OMFormExpression(function_IsFunction)_(Type(function) = \"OME\")\n     <--\n     [\n     OMEcho(\"<OME>\");\n     OMIndent();\n     ForEach(i, function) OMFormExpression(i);\n     OMUndent();\n     OMEcho(\"</OME>\");\n     ];\n10 # OMFormExpression(function_IsFunction)_(Type(function) = \"OMS\")\n     <-- OMEcho(\"<OMS cd=\\\"\":function[1]:\"\\\" name=\\\"\":function[2]:\"\\\"/>\");\n10 # OMFormExpression(function_IsFunction)_(Type(function) = \"OMBIND\")\n     <--\n     [\n     OMEcho(\"<OMBIND>\");\n     OMIndent();\n     ForEach(i, function) OMFormExpression(i);\n     OMUndent();\n     OMEcho(\"</OMBIND>\");\n     ];\n10 # OMFormExpression(function_IsFunction)_(Type(function) = \"OMBVAR\")\n     <--\n     [\n     OMEcho(\"<OMBVAR>\");\n     OMIndent();\n     ForEach(i, function) OMFormExpression(i);\n     OMUndent();\n     OMEcho(\"</OMBVAR>\");\n     ];\n10 # OMFormExpression(function_IsFunction)_(Type(function) = \"OMA\")\n     <--\n     [\n     // This is not the same as the next rule: this is OMA(a,b,c,...),\n     // which is used for building OMA constructs in the mapping to OM.\n     OMEcho(\"<OMA>\");\n     OMIndent();\n     ForEach(i, function) OMFormExpression(i);\n     OMUndent();\n     OMEcho(\"</OMA>\");\n     ];\n11 # OMFormExpression(function_IsFunction)\n     <--\n     [\n     OMEcho(\"<OMA>\");\n     OMIndent();\n     OMFormFunction(function);\n     OMUndent();\n     OMEcho(\"</OMA>\");\n     ];\n\n11 # OMFormFunction(function_IsFunction)\n     <--\n     [\n     Local(arity);\n     arity := Length(function);\n     OMEcho(\"<OMS cd=\\\"yacas\\\" name=\\\"\":Type(function):\"\\\"/>\");\n     If(arity > 0, ForEach(arg, function) OMFormExpression(arg));\n     ];\n10 # OMFormFunction(function_IsFunction)_(OMSymbol()[ Type(function) ] != Empty)\n     <--\n     [\n     Local(symbolDef);\n     // [20051016 AGP] The \"signature\" feature is an old attempt at pattern\n     // matching, but now that we have real predicates in the mappings it's\n     // probably obsolete. I'll think about removing it.\n     symbolDef := OMSymbol()[ OMSignature(function) ];\n     If(symbolDef = Empty, symbolDef := OMSymbol()[ Type(function) ] );\n     If(symbolDef = Empty Or Length(symbolDef) < 3 Or symbolDef[3] = {},\n        [\n        OMEcho(\"<OMS cd=\\\"\":symbolDef[1]:\"\\\" name=\\\"\":symbolDef[2]:\"\\\"/>\");\n        ForEach(arg, function) OMFormExpression(arg);\n        ],\n        [\n        Local(result);\n        result := OMApplyMapping(function, symbolDef[3]);\n        //Check(IsList(result), ToString()Echo(\"Mapping result is not a list: \", result));\n        If(IsList(result),\n           [\n           result := UnList(Subst($, function[0]) result);\n           OMFormExpression(result[0]);\n           ForEach(i, result) OMFormExpression(i);\n           ],\n           If(result = Empty,\n              Echo(\"No rule matched \", function, symbolDef[3]),\n              Echo(\"Unexpected result value from OMApplyMapping(): \", result)\n             )\n          );\n        ]\n       );\n     ];\n\n\nOMWrite(_expression) <--\n[\n  Write(expression);\n];\n\nOMEcho(_expression) <--\n[\n  OMIndentSpace();\n  Write(expression);\n  NewLine();\n];\nOMEcho(expression_IsString) <--\n[\n  OMIndentSpace();\n  WriteString(expression);\n  NewLine();\n];\nOMEcho(expression_IsList) <--\n[\n  ForEach(arg, expression)\n  [\n    If (IsString(arg), WriteString(arg), Write(arg));\n  ];\n  NewLine();\n];\n\nOMEscape(_expression) <--\n[\n  \"<![CDATA[\":String(expression):\"]]>\";\n];\nOMEscapeString(_expression_IsString) <--\n[\n  \"<![CDATA[\":expression:\"]]>\";\n];\nOMWriteEscape(_expression) <--\n[\n  WriteString(OMEscape(expression));\n];\nOMWriteStringEscape(expression_IsString) <--\n[\n  WriteString(OMEscapeString(expression));\n];\nOMEchoEscape(_expression) <--\n[\n  OMWriteEscape(expression);\n  NewLine();\n];\nOMEchoEscape(expression_IsString) <--\n[\n  OMWriteStringEscape(expression);\n  NewLine();\n];\nOMEchoEscape(expression_IsList) <--\n[\n  WriteString(\"<![CDATA[\");\n  ForEach(arg, expression)\n  [\n    If (IsString(arg), WriteString(arg), Write(arg));\n  ];\n  WriteString(\"]]>\");\n  NewLine();\n];\n\n\nHoldArgNr(\"OMForm\",1,1);\n//HoldArgNr(\"OMFormExpression\",1,1);\n//HoldArgNr(\"OMFormFunction\",1,1);\n\n\nOMSignature(_function) <-- \"\";\nOMSignature(function_IsFunction) <--\n[\n  Local(makeSig);\n  makeSig := {ConcatStrings, Type(function), \"_\"};\n  Local(type);\n  type := \"\";// If \"function\" doesn't have parameters, the signature is \"f_\".\n  ForEach(arg, function)\n  [\n    If(Type(arg) = \"List\",\n       type := \"L\",\n       If(IsFunction(arg),\n          type := \"F\",\n          If(IsInteger(arg),\n             type := \"I\",\n             type := \"V\"\n             )\n          )\n       );\n    DestructiveAppend(makeSig, type);\n  ];\n  Secure(Eval(UnList(makeSig)));\n];\nHoldArgNr(\"OMSignature\", 1, 1);\n\n\n\n///////////////////////////////////////////////////////////////////////\n// Input\n\n// Troubleshooting guide:\n// \"encodingError:unexpected closing brace\": this happens in the ReadOMOBJ\n//      rules. It means that you forgot to call OMNextToken() from your rule.\n\nLocalSymbols(omtoken) [\n  OMNextToken() :=\n  [\n    omtoken := XmlExplodeTag(String(ReadToken()));\n  ];\n  OMToken() := omtoken;\n]; // LocalSymbols(omtoken)\n\nOMRead():=\n[\n  Local(result);\n  TrapError(\n  [\n    XmlTokenizer();\n    OMNextToken();\n    result := MatchOMOBJ(OMToken());\n    DefaultTokenizer();\n  ],\n  [\n    result := OMGetCoreError();\n    DefaultTokenizer();\n  ]);\n  result;\n];\n\n\nOMDump(str):=\nFromString(str:\" EndOfFile\")\n[\n  Local(result);\n  XmlTokenizer();\n  OMNextToken();\n  While(OMToken() != \"EndOfFile\")\n  [\n    Echo(\"Exploded \",OMToken());\n    OMNextToken();\n  ];\n  DefaultTokenizer();\n  True;\n];\n\n\n\n10 # MatchClose(_x)_(x = OMToken()) <-- [OMNextToken();True;];\n20 # MatchClose(_x) <-- Check(False,ToString()Echo(\"encodingError:unexpected closing brace\")); //@@@ TODO better error reporting\n\n10 # MatchOMOBJ(XmlTag(\"OMOBJ\",_attributes,\"Open\")) <--\n[\n  // Any attributes are ignored.\n  Local(result);\n  OMNextToken();\n  result := ReadOMOBJ(OMToken());\n  MatchClose(XmlTag(\"OMOBJ\",{},\"Close\"));\n  result;\n];\n10 # MatchOMOBJ(XmlTag(\"OMOBJ\",_attributes,\"OpenClose\")) <--\n[\n  OMNextToken();\n  // Any attributes are ignored.\n  // This is a void expression, of the form \"<OMOBJ/>\".\n  Empty;\n];\n20 # MatchOMOBJ(_rest) <-- Check(False,ToString()Echo(\"encodingError:not an OMOBJ :\",rest));\n\n10 # ReadOMOBJ(XmlTag(\"OMOBJ\",_attributes,\"Close\")) <--\n[\n  // This is a void expression, of the form \"<OMOBJ></OMOBJ>\".\n  Empty;\n];\n\n10 # ReadOMOBJ(XmlTag(\"OMI\",{},\"Open\")) <--\n[\n  Local(result);\n  OMNextToken();\n  result := Atom(OMToken());\n  OMNextToken();\n  MatchClose(XmlTag(\"OMI\",{},\"Close\"));\n  result;\n];\n\n10 # ReadOMOBJ(XmlTag(\"OMV\",{{\"NAME\",_name}},\"OpenClose\")) <--\n[\n  OMNextToken();\n  Atom(name);\n];\n\n10 # ReadOMOBJ(XmlTag(\"OMF\",{{\"DEC\",_dec}},\"OpenClose\")) <--\n[\n  OMNextToken();\n  If (dec = \"INF\", Infinity,\n    If (dec = \"-INF\", -Infinity,\n      If (dec = \"NaN\", Undefined,\n        Atom(dec) + 0.0\n      )\n    )\n  );\n];\n\n10 # ReadOMOBJ(XmlTag(\"OMSTR\",{},\"Open\")) <--\n[\n  Local(result,s,i);\n  OMNextToken();\n  If(IsString(OMToken()), [result := OMToken(); OMNextToken();], result := \"\");\n  MatchClose(XmlTag(\"OMSTR\",{},\"Close\"));\n  s := \"\";\n  For (i := 1, i <= Length(result), i++) [\n    Local(c);\n    c := result[i];\n    If (c != \"&\", s := s : c, [\n      Local(j,ec);\n      j := i;\n      While (j <= Length(result) And result[j] != \";\")\n        j := j + 1;\n\n      ec := result[i .. j];\n      If (ec = \"&amp;\", s := s : \"&\");\n      If (ec = \"&lt;\", s := s : \"<\");\n      If (ec = \"&gt;\", s := s : \">\");\n      If (ec = \"&quot;\", s := s : \"\\\"\");\n      If (ec = \"&apos;\", s := s : \"'\");\n\n      i := j;\n    ]);\n  ];\n  s;\n];\n10 # ReadOMOBJ(XmlTag(\"OMSTR\",{},\"OpenClose\")) <--\n[\n  OMNextToken();\n  \"\";\n];\n\n10 # ReadOMOBJ(XmlTag(\"OMA\",{},\"Open\")) <--\n[\n  Local(result, new);\n  result:={};\n  OMNextToken();\n  While (OMToken() != XmlTag(\"OMA\",{},\"Close\"))\n  [\n    new:=ReadOMOBJ(OMToken());\n    DestructiveAppend(result,new);\n  ];\n  MatchClose(XmlTag(\"OMA\",{},\"Close\"));\n  OMApplyReverseMapping(UnList(result));\n];\n\n10 # ReadOMOBJ(XmlTag(\"OMBIND\",{},\"Open\")) <--\n[\n  Local(result, new);\n  result:={};\n  OMNextToken();\n  While (OMToken() != XmlTag(\"OMBIND\",{},\"Close\"))\n  [\n    new:=ReadOMOBJ(OMToken());\n    DestructiveAppend(result,new);\n  ];\n  MatchClose(XmlTag(\"OMBIND\",{},\"Close\"));\n  result;\n];\n10 # ReadOMOBJ(XmlTag(\"OMBVAR\",{},\"Open\")) <--\n[\n  Local(result, new);\n  result:={};\n  OMNextToken();\n  While (OMToken() != XmlTag(\"OMBVAR\",{},\"Close\"))\n  [\n    new:=ReadOMOBJ(OMToken());\n    DestructiveAppend(result,new);\n  ];\n  MatchClose(XmlTag(\"OMBVAR\",{},\"Close\"));\n  result;\n];\n\n10 # OMApplyReverseMapping(yacasExp_IsFunction) <-- yacasExp;\n10 # OMApplyReverseMapping(yacasExp_IsFunction)_(OMSymbol()[ Type(yacasExp) ] != Empty)\n     <--\n     [\n     Local(symbolDef, result);\n     symbolDef := OMSymbol()[ Type(yacasExp) ];\n     If(symbolDef[4] = {},\n        result := yacasExp,\n        [\n          result := OMApplyMapping(yacasExp, symbolDef[4]);\n          result := Subst($, yacasExp[0]) result;\n          If(IsList(result), result := UnList(result));\n        ]\n       );\n     result;\n     ];\n\n10 # OMApplyMapping(_function, _mapping) <--\n[\n  Local(expandRules, result);\n  expandRules := { _(_path) <- OMPathSelect(path, function) };\n  expandRules[1][2][2] := function;// the \"function\" variable is not expanded above.\n\n  mapping := (mapping /: expandRules);// \"/:\" has lower precedence than \":=\".\n\n  Local(ruleMatched);\n  ruleMatched := False;\n  If(Type(mapping) = \"|\",\n     [\n     mapping := Flatten(mapping, \"|\");\n     ForEach(rule, mapping)\n       If(Not ruleMatched,\n          [\n          If(Type(rule) = \"_\",\n             If( Eval(rule[2]), [ result := rule[1]; ruleMatched := True; ] ),\n             [ result := rule; ruleMatched := True; ]\n            );\n          ]\n         );\n     ],\n     [\n     If(Type(mapping) = \"_\",\n        If(Eval(mapping[2]),\n           result := mapping[1],\n           result := Listify(function)\n          ),\n\tresult := mapping\n       );\n     ruleMatched := True;\n     ]\n    );\n\n  If(ruleMatched,\n     If(Type(result) = \":\",\n        If(Length(result) = 2,\n           result[1]:result[2],\n           result),// Perhaps we should give a warning here.\n        result),\n     Empty);\n];\n\n11 # OMPathSelect(path_IsNumber, _expression) <--\n[\n  If(path >= 0 And path <= Length(expression),\n     expression[path],\n     Undefined);\n];\n11 # OMPathSelect(path_IsList, _expression) <--\n[\n  ForEach(i, path)\n    If(IsFunction(expression) And i >= 0 And i <= Length(expression),\n       expression := expression[i],\n       Undefined);\n  expression;\n];\nHoldArgNr(\"OMPathSelect\", 2, 2);\n\n// Previously, any unknown symbols where reported as errors.\n// Now, we just store them as OMS(cd, name) since Yacas is perfectly happy\n// with such unknown symbols, and will handle them right: When\n// producing an OpenMath result from them, they will be output back\n// unmodified, forming a valid OpenMath expression.\n// This way we don't have to bother defining bogus symbols for concepts that\n// Yacas does not handle.\n100 # ReadOMOBJ(XmlTag(\"OMS\", _attributes, \"OpenClose\")) <--\n[\n  OMNextToken();\n  Local(omcd, omname);\n  omcd   := attributes[\"CD\"];\n  omname := attributes[\"NAME\"];\n  If(omcd = Empty Or omname = Empty,\n     OMCheck(False,OMError({\"moreerrors\", \"encodingError\"}, ToString()Echo(\"missing \\\"cd\\\" or \\\"name\\\" attribute: \",attributes))),\n     [\n     Local(cdTable, yacasform);\n     cdTable := OMSymbolReverse()[ omcd ];\n     If(cdTable != Empty, yacasform := cdTable[ omname ]);\n     // We can not optimize here by checking first whether the CD is \"yacas\"\n     // and avoiding the table lookup then, because for some symbols the\n     // OM name have to be different from the Yacas name (e.g. \"/@\").\n     If(yacasform = Empty,\n        If(cd = \"yacas\", Atom(omname), OMS(omcd, omname)),\n        If(IsString(yacasform), Atom(yacasform), yacasform));\n     ]\n    );\n];\n\n101 # ReadOMOBJ(_rest) <-- OMCheck(False,OMError({\"moreerrors\", \"encodingError\"}, ToString()Echo(\"unhandled tag: \",rest)));\n\n\n\n///////////////////////////////////////////////////////////////////////\n// Error reporting\n\nMacro(OMCheck,{predicate,error})\n[\n  If(Not(@predicate),\n  [\n    Assert(\"omErrorObject\", @error) False;\n    Check(False,\"omErrorObject\");\n  ]\n  ,\n  True);\n];\nOMGetCoreError():=\n[\n  Local(result);\n  result := GetCoreError();\n  If(result != \"\",\n     If( IsError(\"omErrorObject\"),\n        [result := GetError(\"omErrorObject\");                     ],\n        [result := OMError({\"moreerrors\", \"unexpected\"}, result); ])\n    );\n  result;\n];\n\n\n\n///////////////////////////////////////////////////////////////////////\n// Symbol mapping tables\n\nLocalSymbols(omsymbol, omsymbolreverse) [\n  // Initialization of the openmath symbol dictionaries\n  omsymbol := {};\n  omsymbolreverse := {};\n\n  // Access to the dictionaries\n  OMSymbol() := omsymbol;\n  OMSymbolReverse() := omsymbolreverse;\n\n]; // LocalSymbols(omsymbol, omsymbolreverse)\n\nOMDef(_yacasform, omcd_IsString, omname_IsString, _directMapping, _reverseMapping) <--\n[\n  Local(cdTable);\n  If(IsString(yacasform),\n     OMSymbol()[ yacasform ] := {omcd, omname, directMapping, reverseMapping}\n     );\n  cdTable := OMSymbolReverse()[ omcd ];\n  If(cdTable = Empty,\n     OMSymbolReverse()[ omcd ] := {{omname, yacasform}},\n     [\n       Local(oldYacasform);\n       oldYacasform := cdTable[ omname ];\n       If(oldYacasform = Empty,\n          cdTable[ omname ] := yacasform,\n          [\n          If(oldYacasform != yacasform,\n             [\n             cdTable[ omname ] := yacasform;\n             Echo(\"Warning: the mapping for \", omcd, \":\", omname,\n                  \" was already defined as \", oldYacasform,\n                  \", but is redefined now as \", yacasform\n                  );\n             ]\n            );\n          ]\n         );\n      ]\n     );\n  True;\n];\n\nOMDef(_yacasform, omcd_IsString, omname_IsString)\n<-- OMDef(yacasform, omcd, omname, {}, {});\n\nOMDef(yacasalias_IsString, yacasname_IsString) <--\n[\n  OMSymbol()[ yacasalias ] := OMSymbol()[ yacasname ];\n];\nHoldArgNr(\"OMDef\", 5, 4);\nHoldArgNr(\"OMDef\", 5, 5);\n\n// Many objects, such as matrices and sets, do not have a specific\n// encoding in Yacas, but are represented as lists.\nOMDef( {},     \"set1\",\"emptyset\" );\nOMDef( \"List\", \"set1\",\"set\"      );\nOMDef( \"List\", \"linalg2\",\"matrix\"    );\nOMDef( \"List\", \"linalg2\",\"matrixrow\" );\nOMDef( \"List\", \"linalg2\",\"vector\"    );\nOMDef( \"List\", \"list1\",\"list\" );\n\n// [20010916 AGP] I couldn't find these symbols in the def files:\n//     \"E\"        ,  \"nums1\", \"e\"\n//     \"Gamma\"    ,  \"nums1\", \"gamma\"\nOMDef( \"Infinity\" ,  \"nums1\", \"infinity\" );\nOMDef( \"Undefined\",  \"nums1\", \"NaN\"      );\n// [20010916 AGP] From stdopers.ys:\nOMDef( \"And\"   ,  \"logic1\", \"and\"        );\nOMDef( \"==\"    ,  \"logic1\", \"equivalent\" );\nOMDef( \"!==\"   ,  \"logic1\", \"not\",\n                { \"<OMA><OMS cd=\\\"logic1\\\" name=\\\"equivalent\\\"/>\",\n                  1,\n                  2,\n                  \"</OMA>\"\n                }\n      );\nOMDef( \"False\",  \"logic1\", \"false\" );\nOMDef( \"Or\"   ,  \"logic1\", \"or\"    );\nOMDef( \"True\" ,  \"logic1\", \"true\"  );\n//[20010916 AGP ] Xor is not available in Yacas.\n//     \"Xor\"  ,  \"logic1\", \"xor\"   );\nOMDef( \"&\" ,  \"yacas\", \"bitwise_and\" );\nOMDef( \"|\" ,  \"yacas\", \"bitwise_or\"  );\nOMDef( \"%\" ,  \"yacas\", \"bitwise_xor\" );\nOMDef( \"/\" , \"arith1\", \"divide\");// This definition is for OM arith1:divide to Yacas. In all other cases, the next one will be used.\nOMDef( \"/\" , \"nums1\", \"rational\", {$, _1, _2}_(IsRational(_1/_2)) | {OMS(\"arith1\", \"divide\"), _1, _2}, {/, _1, _2});\nOMDef( \"-\" ,  \"arith1\", \"unary_minus\");\nOMDef( \"-\" ,  \"arith1\", \"minus\"  );// We need a way of testing the arity.\nOMDef( \"+\" ,  \"arith1\", \"plus\"   );\nOMDef( \"^\" ,  \"arith1\", \"power\"  );\nOMDef( \"*\" ,  \"arith1\", \"times\"  );\n\n\nUse(\"constants.rep/om.ys\");\nUse(\"stdfuncs.rep/om.ys\");\nUse(\"stubs.rep/om.ys\");\nUse(\"logic.rep/om.ys\");\nUse(\"complex.rep/om.ys\");\nUse(\"integrate.rep/om.ys\");\nUse(\"sums.rep/om.ys\");\nUse(\"limit.rep/om.ys\");\n//Use(\"numbers.rep/om.ys\");// Sqrt is loaded before (stubs.rep) than IntNthRoot.\nUse(\"functional.rep/om.ys\");\nUse(\"solve.rep/om.ys\");"
  },
  {
    "path": "scripts/openmath.rep/code.ys.def",
    "content": "OMREP\nOMDef\nOMForm\nOMRead\nOMParse\nOMEcho\nOMEchoEscape\n}\n"
  },
  {
    "path": "scripts/orthopoly.rep/code.ys",
    "content": "/*\r\nOrthogonal polynomials\r\nversion 1.2\r\n(Serge Winitzki)\r\n\r\nPolynomials are found from direct recurrence relations. Sums of series of polynomials are found using the Clenshaw-Smith recurrence scheme.\r\n\r\nReference: Yudell L. Luke. Mathematical functions and their approximations. Academic Press, N. Y., 1975.\r\n\r\nUsage:\r\n  The polynomials are evaluated by functions named Ortho*, where * is one of P, G, H, L, T, U. The first argument of these functions is an integer.  The series of polynomials are evaluated by functions named Ortho*Sum. The first argument of these functions is a list of coefficients. The last argument is the value x at which the polynomials are to be computed; if x is numerical, a faster routine is used.\r\n\r\n  If n is an integer, n>=0, then:\r\n\tOrthoP(n, x) gives the n-th Legendre polynomial, evaluated on x\r\n\tOrthoP(n, a, b, x) gives the n-th Jacobi polynomial with parameters a, b, evaluated on x\r\n\tOrthoG(n, a, x) gives the n-th Gegenbauer polynomial\r\n\tOrthoH(n, x) gives the n-th Hermite polynomial\r\n\tOrthoL(n, a, x) gives the n-th Laguerre polynomial\r\n\tOrthoT(n, x) gives the n-th Tschebyscheff polynomial of the 1st kind\r\n\tOrthoU(n, x) gives the n-th Tschebyscheff polynomial of the 2nd kind\r\n\r\n  If c is a list of coefficients c[1], c[2], ..., c[N], then Ortho*Sum(c, ...) where * is one of P, G, H, L, T, U, computes the sum of a series c[1]*P_0+c[2]*P_1+...+c[N]*P_N, where P_k is the relevant polynomial of k-th order. (For polynomials taking parameters: the parameters must remain constant throughout the summation.) Note that the intermediate polynomials are not evaluated and the recurrence relations are different for this computation, so there may be a numerical difference between Ortho*(c, ...) and computing the sum of the series directly.\r\n\r\n  Internal functions that may be useful:\r\n\tOrthoPolyCoeffs(name_IsString, n_IsInteger, parameters_IsList) returns a list of coefficients of the polynomial. Here \"name\" must be one of the predefined names: \"Jacobi\", \"Gegenbauer\", \"Hermite\", \"Laguerre\", \"Tscheb1\",  \"Tscheb2\"; and \"parameters\" is a list of extra parameters for the given family of polynomials, e.g. {a,b} for the Jacobi, {a} for Laguerre and {} for Hermite polynomials.\r\n\tOrthoPolySumCoeffs(name_IsString, c_IsList, parameters_IsList) returns a list of coefficients of the polynomial which is a sum of series with coefficients c.\r\n\tEvaluateHornerScheme(coefficients, x) returns the Horner-evaluated polynomial on x. The \"coefficients\" is a list that starts at the lowest power. For example, EvaluateHornerScheme({a,b,c}, x) should return (a+x*(b+x*c))\r\n*/\r\n\r\n10 # EvaluateHornerScheme({}, _x) <-- 0;\r\n/* Strictly speaking, the following rule is not needed, but it doesn't hurt */\r\n10 # EvaluateHornerScheme({_coeffs}, _x) <-- coeffs;\r\n20 # EvaluateHornerScheme(coeffs_IsList, _x) <-- Head(coeffs)+x*EvaluateHornerScheme(Tail(coeffs), x);\r\n\r\n/* Plain polynomials */\r\n// some are computed by general routines, and some are replaced by more efficient routines below\r\nOrthoP(n_IsInteger, _x)_(n>=0) <-- OrthoP(n, 0, 0, x);\r\nOrthoP(n_IsInteger, a_IsRationalOrNumber, b_IsRationalOrNumber, _x)_(n>=0 And a> -1 And b> -1) <-- OrthoPoly(\"Jacobi\", n, {a, b}, x);\r\n\r\nOrthoG(n_IsInteger, a_IsRationalOrNumber, _x)_(n>=0 And a> -1/2) <-- OrthoPoly(\"Gegenbauer\", n, {a}, x);\r\n\r\nOrthoH(n_IsInteger, _x)_(n>=0) <-- OrthoPoly(\"Hermite\", n, {}, x);\r\n\r\nOrthoL(n_IsInteger, a_IsRationalOrNumber, _x)_(n>=0 And a> -1) <-- OrthoPoly(\"Laguerre\", n, {a}, x);\r\n\r\nOrthoT(n_IsInteger, _x)_(n>=0) <-- OrthoPoly(\"Tscheb1\", n, {}, x);\r\nOrthoU(n_IsInteger, _x)_(n>=0) <-- OrthoPoly(\"Tscheb2\", n, {}, x);\r\n\r\n/* Sums of series of orthogonal polynomials */\r\n\r\nOrthoPSum(c_IsList, _x) <-- OrthoP(c, 0, 0, x);\r\nOrthoPSum(c_IsList, a_IsRationalOrNumber, b_IsRationalOrNumber, _x)_(a> -1 And b> -1) <-- OrthoPolySum(\"Jacobi\", c, {a, b}, x);\r\n\r\nOrthoGSum(c_IsList, a_IsRationalOrNumber, _x)_(a> -1/2) <-- OrthoPolySum(\"Gegenbauer\", c, {a}, x);\r\n\r\nOrthoHSum(c_IsList, _x) <-- OrthoPolySum(\"Hermite\", c, {}, x);\r\n\r\nOrthoLSum(c_IsList, a_IsRationalOrNumber, _x)_(a> -1) <-- OrthoPolySum(\"Laguerre\", c, {a}, x);\r\n\r\nOrthoTSum(c_IsList, _x) <-- OrthoPolySum(\"Tscheb1\", c, {}, x);\r\nOrthoUSum(c_IsList, _x) <-- OrthoPolySum(\"Tscheb2\", c, {}, x);\r\n\r\n/*\r\nOrthogonal polynomials are evaluated using a general routine OrthoPolyCoeffs that generates their coefficients recursively.\r\n\r\nThe recurrence relations start with n=0 and n=1 (the n=0 polynomial is always identically 1) and continue for n>=2. Note that the n=1 polynomial is not always given by the n=1 recurrence formula if we assume P_{-1}=0, so the recurrence should be considered undefined at n=1.\r\n\r\n\tFor Legendre/Jacobi polynomials: (a>-1, b>-1)\r\nP(0,a,b,x):=1\r\nP(1,a,b,x):=(a-b)/2+x*(1+(a+b)/2)\r\nP(n,a,b,x):=(2*n+a+b-1)*(a^2-b^2+x*(2*n+a+b-2)*(2*n+a+b))/(2*n*(n+a+b)*(2*n+a+b-2))*P(n-1,a,b,x)-(n+a-1)*(n+b-1)*(2*n+a+b)/(n*(n+a+b)*(2*n+a+b-2))*P(n-2,a,b,x)\r\n\r\n\tFor Hermite polynomials:\r\nH(0,x):=1\r\nH(1,x):=2*x\r\nH(n,x):=2*x*H(n-1,x)-2*(n-1)*H(n-2,x)\r\n\r\n\tFor Gegenbauer polynomials: (a>-1/2)\r\nG(0,a,x):=1\r\nG(1,a,x):=2*a*x\r\nG(n,a,x):=2*(1+(a-1)/n)*x*G(n-1,a,x)-(1+2*(a-2)/n)*G(n-2,a,x)\r\n\r\n\tFor Laguerre polynomials: (a>-1)\r\nL(0,a,x):=1\r\nL(1,a,x):=a+1-x\r\nL(n,a,x):=(2+(a-1-x)/n)*L(n-1,a,x)-(1+(a-1)/n)*L(n-2,a,x)\r\n\r\n\tFor Tschebycheff polynomials of the first kind:\r\nT(0,x):=1\r\nT(1,x):=x\r\nT(n,x):=2*x*T(n-1,x)-T(n-2,x)\r\n\r\n\tFor Tschebycheff polynomials of the second kind:\r\nU(0,x):=1\r\nU(1,x):=2*x\r\nU(n,x):=2*x*U(n-1,x)-U(n-2,x)\r\n\r\nThe database \"KnownOrthoPoly\" contains closures that return coefficients for the recurrence relations of each family of polynomials. KnownOrthoPoly[\"name\"] is a closure that takes two arguments: the order (n) and the extra parameters (p), and returns a list of two lists: the first list contains the coefficients {A,B} of the n=1 polynomial, i.e. \"A+B*x\"; the second list contains the coefficients {A,B,C} in the recurrence relation, i.e. \"P_n = (A+B*x)*P_{n-1}+C*P_{n-2}\". (So far there are only 3 coefficients in the second list, i.e. no \"C+D*x\", but we don't want to be limited.)\r\n\r\n*/\r\n\r\nLocalSymbols(knownOrthoPoly) [\r\n  knownOrthoPoly := Hold({\r\n    {\"Jacobi\", {{n, p}, {{(p[1]-p[2])/2, 1+(p[1]+p[2])/2}, {(2*n+p[1]+p[2]-1)*((p[1])^2-(p[2])^2)/(2*n*(n+p[1]+p[2])*(2*n+p[1]+p[2]-2)), (2*n+p[1]+p[2]-1)*(2*n+p[1]+p[2])/(2*n*(n+p[1]+p[2])), -(n+p[1]-1)*(n+p[2]-1)*(2*n+p[1]+p[2])/(n*(n+p[1]+p[2])*(2*n+p[1]+p[2]-2))}}}},\r\n    {\"Gegenbauer\", {{n, p}, {{0, 2*p[1]}, {0, 2+2*(p[1]-1)/n, -1-2*(p[1]-1)/n}}}},\r\n    {\"Laguerre\", {{n, p}, {{p[1]+1, -1}, {2+(p[1]-1)/n, -1/n, -1-(p[1]-1)/n}}}},\r\n    {\"Hermite\", {{n, p}, {{0,2}, {0, 2, -2*(n-1)}}}},\r\n    {\"Tscheb1\", {{n, p}, {{0,1}, {0,2,-1}}}},\r\n    {\"Tscheb2\", {{n, p}, {{0,2}, {0,2,-1}}}}\r\n  });\r\n  KnownOrthoPoly() := knownOrthoPoly;\r\n\r\n]; // LocalSymbols(knownOrthoPoly)\r\n\r\n/*\r\nFor efficiency, polynomials are represented by lists of coefficients rather than by Yacas expressions. Polynomials are evaluated using the explicit Horner scheme. On numerical arguments, the polynomial coefficients are not computed, only the resulting value.\r\n*/\r\n\r\n/*\r\nSums of series of orthogonal polynomials are found using the Clenshaw-Smith recurrence scheme:\r\n\tIf $P_n$ satisfy $P_n = A_n p_{n-1} + B_n p_{n-2}$, $n>=2$, and if $A_1$ is defined so that $P_1 = A_1 P_0$, then $\\sum _{n=0}^N c_n P_n = X_0 P_0$, where $X_n$ are found from the following backward recurrence: $X_{N+1} = X_{N+2} = 0$, $X_n = c_n + A_{n+1} X_{n+1} + B_{n+2} X_{n+2}$, $n=N, N-1, ..., 0$.\r\n*/\r\n\r\n/* Numeric arguments are processed by a faster routine */\r\n\r\n10 # OrthoPoly(name_IsString, _n, p_IsList, x_IsRationalOrNumber) _ (KnownOrthoPoly()[name] != Empty) <-- OrthoPolyNumeric(name, n, p, x);\r\n20 # OrthoPoly(name_IsString, _n, p_IsList, _x) _ (KnownOrthoPoly()[name] != Empty) <-- EvaluateHornerScheme(OrthoPolyCoeffs(name, n, p), x);\r\n\r\n10 # OrthoPolySum(name_IsString, c_IsList, p_IsList, x_IsRationalOrNumber) _ (KnownOrthoPoly()[name] != Empty) <-- OrthoPolySumNumeric(name, c, p, x);\r\n20 # OrthoPolySum(name_IsString, c_IsList, p_IsList, _x) _ (KnownOrthoPoly()[name] != Empty) <-- EvaluateHornerScheme(OrthoPolySumCoeffs(name, c, p), x);\r\n\r\n/*\r\nOrthoPolyNumeric computes the value of the polynomial from recurrence relations directly. Do not use with non-numeric arguments, except for testing!\r\n*/\r\nOrthoPolyNumeric(name_IsString, n_IsInteger, p_IsList, _x) <-- [\r\n\tLocal(value1, value2, value3, ruleCoeffs, index);\r\n\tvalue1 := 1;\r\n\truleCoeffs := Apply(KnownOrthoPoly()[name], {n, p})[1];\r\n\tvalue2 := ruleCoeffs[1] + x*ruleCoeffs[2];\r\n\tindex := 1;\r\n\t/* value1, value2, value3 is the same as P_{n-2}, P_{n-1}, P_n where n = index */\r\n\tWhile(index<n) [\r\n\t\tindex := index + 1;\r\n\t\truleCoeffs := Apply(KnownOrthoPoly()[name], {index, p})[2];\r\n\t\tvalue3 := (ruleCoeffs[1] + x*ruleCoeffs[2])*value2 + ruleCoeffs[3]*value1;\r\n\t\tvalue1 := value2;\r\n\t\tvalue2 := value3;\r\n//Serge! \t\tEcho(index);\r\n\t];\r\n\tvalue2;\r\n];\r\n\r\n/* Clenshaw-Smith recurrence scheme */\r\nOrthoPolySumNumeric(name_IsString, c_IsList, p_IsList, _x) <-- [\r\n\tLocal(value1, value2, value3, ruleCoeffs, ruleCoeffs1, index);\r\n\tvalue1 := 0;\r\n\tvalue2 := 0;\r\n\tindex := Length(c) - 1;\r\n\t/* value1, value2, value3 is the same as X_{n+2}, X_{n+1}, X_n where n = index */\r\n\tWhile(index>=1) [\r\n\t\truleCoeffs := Apply(KnownOrthoPoly()[name], {index+1, p})[2];\r\n\t\truleCoeffs1 := Apply(KnownOrthoPoly()[name], {index+2, p})[2];\r\n\t\tvalue3 := (ruleCoeffs[1] + x*ruleCoeffs[2])*value2 + ruleCoeffs1[3]*value1 + c[index+1];\r\n\t\tvalue1 := value2;\r\n\t\tvalue2 := value3;\r\n\t\tindex := index - 1;\r\n\t];\r\n\t/* Last iteration by hand: works correctly also if c has only 1 element */\r\n\truleCoeffs := Apply(KnownOrthoPoly()[name], {1, p})[1];\r\n\truleCoeffs1 := Apply(KnownOrthoPoly()[name], {2, p})[2];\r\n\tvalue2 := (ruleCoeffs[1] + x*ruleCoeffs[2])*value2 + ruleCoeffs1[3]*value1 + c[1];\r\n\tvalue2;\r\n];\r\n\r\n/*\r\nOrthoPolyCoeffs(name, n, p) returns the list of coefficients for orthogonal polynomials, starting with the lowest powers.\r\n*/\r\n\r\n10 # OrthoPolyCoeffs(name_IsString, 0, p_IsList) <-- {1};\r\n10 # OrthoPolyCoeffs(name_IsString, 1, p_IsList) <-- Apply(KnownOrthoPoly()[name], {1, p})[1];\r\n\r\n/* Simple implementation, very slow, for testing only: recursive rule matches, no loops\r\n20 # OrthoPolyCoeffs(name_IsString, n_IsInteger, p_IsList)_(n>1) <-- [\r\n\tLocal(ruleCoeffs, newCoeffs);\r\n\truleCoeffs := Apply(KnownOrthoPoly()[name], {n, p})[2];\r\n\tnewCoeffs := OrthoPolyCoeffs(name, n-1, p);\r\n\tConcat(newCoeffs,{0})*ruleCoeffs[1] + Concat(OrthoPolyCoeffs(name, n-2, p),{0,0})*ruleCoeffs[3] + Concat({0}, newCoeffs)*ruleCoeffs[2];\r\n];\r\n*/\r\n\r\n/* A fast implementation that works directly with lists and saves memory. Same recurrence as in OrthoPolyNumeric() */\r\n/* note: here we pass \"name\" instead of \"KnownOrthoPoly()[name]\" for efficiency, but strictly speaking we don't need to use this global constant */\r\n\r\n20 # OrthoPolyCoeffs(name_IsString, n_IsInteger, p_IsList)_(n>1) <-- [\r\n\tLocal(ruleCoeffs, tmpCoeffs, newCoeffs, prevCoeffs, index, jndex, tmptmpCoeffs, prevCoeffsA, newCoeffsA, tmpCoeffsA);\r\n\t/* For speed, allocate all lists now. Length is n+1 */\r\n\tprevCoeffsA := ZeroVector(n+1);\r\n\tnewCoeffsA := ZeroVector(n+1);\r\n\ttmpCoeffsA := ZeroVector(n+1);\r\n\t/* pointers to arrays */\r\n\tprevCoeffs := prevCoeffsA;\r\n\tnewCoeffs := newCoeffsA;\r\n\ttmpCoeffs := tmpCoeffsA;\r\n\t/* Initialize: n=0 and n=1 */\r\n\tprevCoeffs[1] := 1;\r\n\truleCoeffs := Apply(KnownOrthoPoly()[name], {n, p})[1];\r\n\tnewCoeffs[1] := ruleCoeffs[1];\r\n\tnewCoeffs[2] := ruleCoeffs[2];\r\n\t/* Invariant: answer ready in \"newCoeffs\" at value of index */\r\n\tindex := 1;\r\n\t/* main loop */\r\n\tWhile(index < n) [\r\n\t\tindex := index + 1;\r\n\t\t/* Echo({\"index \", index}); */ /* in case this is slow */\r\n\t\truleCoeffs := Apply(KnownOrthoPoly()[name], {index, p})[2];\r\n\t\ttmpCoeffs[1] := ruleCoeffs[1]*newCoeffs[1] + ruleCoeffs[3]*prevCoeffs[1];\r\n\t\t/* The polynomial tmpCoeffs must have (index+1) coefficients now */\r\n\t\tFor(jndex:=2, jndex <= index, jndex:=jndex+1) [\r\n\t\t\ttmpCoeffs[jndex] := ruleCoeffs[1]*newCoeffs[jndex] + ruleCoeffs[3]*prevCoeffs[jndex] + ruleCoeffs[2]*newCoeffs[jndex-1];\r\n\t\t];\r\n\t\ttmpCoeffs[index+1] := ruleCoeffs[2]*newCoeffs[index];\r\n/*\r\n\t\tprevCoeffs := FlatCopy(newCoeffs);\r\n\t\tnewCoeffs := FlatCopy(tmpCoeffs);\r\n*/\r\n/* juggle pointers instead of copying lists */\r\n\t\ttmptmpCoeffs := prevCoeffs;\r\n\t\tprevCoeffs := newCoeffs;\r\n\t\tnewCoeffs := tmpCoeffs;\r\n\t\ttmpCoeffs := tmptmpCoeffs;\r\n\t];\r\n\tnewCoeffs;\r\n];\r\n\r\n/*\r\nOrthoPolySumCoeffs(name, c, p) returns the list of coefficients for the sum of a series of orthogonal polynomials. Same recurrence as in OrthoPolySumNumeric()\r\n*/\r\n\r\nOrthoPolySumCoeffs(name_IsString, c_IsList, p_IsList) <-- [\r\n\tLocal(n, ruleCoeffs, ruleCoeffs1, tmpCoeffs, newCoeffs, prevCoeffs, index, jndex, tmptmpCoeffs, prevCoeffsA, newCoeffsA, tmpCoeffsA);\r\n\t/* n is the max polynomial order we need */\r\n\tn := Length(c) - 1;\r\n\t/* For speed, allocate all lists now. Length is n+1 */\r\n\tprevCoeffsA := ZeroVector(n+1);\r\n\tnewCoeffsA := ZeroVector(n+1);\r\n\ttmpCoeffsA := ZeroVector(n+1);\r\n\t/* pointers to arrays */\r\n\tprevCoeffs := prevCoeffsA;\r\n\tnewCoeffs := newCoeffsA;\r\n\ttmpCoeffs := tmpCoeffsA;\r\n\t/* Invariant: answer ready in \"newCoeffs\" at value of index */\r\n\t/* main loop */\r\n\tFor(index:=n, index >= 1, index:=index-1) [\r\n\t\t/* Echo({\"index \", index}); */ /* in case this is slow */\r\n\t\truleCoeffs := Apply(KnownOrthoPoly()[name], {index+1, p})[2];\r\n\t\truleCoeffs1 := Apply(KnownOrthoPoly()[name], {index+2, p})[2];\r\n\t\ttmpCoeffs[1] := c[index+1] + ruleCoeffs[1]*newCoeffs[1] + ruleCoeffs1[3]*prevCoeffs[1];\r\n\t\t/* The polynomial tmpCoeffs must have (n-index+1) coefficients now */\r\n\t\tFor(jndex:=2, jndex <= n-index, jndex:=jndex+1) [\r\n\t\t\ttmpCoeffs[jndex] := ruleCoeffs[1]*newCoeffs[jndex] + ruleCoeffs1[3]*prevCoeffs[jndex] + ruleCoeffs[2]*newCoeffs[jndex-1];\r\n\t\t];\r\n\t\tIf(n-index>0, tmpCoeffs[n-index+1] := ruleCoeffs[2]*newCoeffs[n-index]);\r\n/*\r\n\t\tprevCoeffs := FlatCopy(newCoeffs);\r\n\t\tnewCoeffs := FlatCopy(tmpCoeffs);\r\n*/\r\n/* juggle pointers instead of copying lists */\r\n\t\ttmptmpCoeffs := prevCoeffs;\r\n\t\tprevCoeffs := newCoeffs;\r\n\t\tnewCoeffs := tmpCoeffs;\r\n\t\ttmpCoeffs := tmptmpCoeffs;\r\n\t];\r\n\t/* Last iteration by hand: works correctly also if c has only 1 element */\r\n\tindex:=0;\r\n\truleCoeffs := Apply(KnownOrthoPoly()[name], {index+1, p})[1];\r\n\truleCoeffs1 := Apply(KnownOrthoPoly()[name], {index+2, p})[2];\r\n\ttmpCoeffs[1] := c[index+1] + ruleCoeffs[1]*newCoeffs[1] + ruleCoeffs1[3]*prevCoeffs[1];\r\n\t/* The polynomial tmpCoeffs must have (n-index+1) coefficients now */\r\n\tFor(jndex:=2, jndex <= n-index, jndex:=jndex+1) [\r\n\t\ttmpCoeffs[jndex] := ruleCoeffs[1]*newCoeffs[jndex] + ruleCoeffs1[3]*prevCoeffs[jndex] + ruleCoeffs[2]*newCoeffs[jndex-1];\r\n\t];\r\n\ttmpCoeffs[n-index+1] := ruleCoeffs[2]*newCoeffs[n-index];\r\n\ttmpCoeffs;\r\n];\r\n\r\n//////////////////////////////////////////////////\r\n/// Very fast computation of Chebyshev polynomials\r\n//////////////////////////////////////////////////\r\n/// (This is not used now because of numerical instability, until I figure out how much to increase the working precision to get P correct digits.)\r\n/// See: W. Koepf. Efficient computation of Chebyshev polynomials in computer algebra (unpublished preprint). Contrary to Koepf's claim (unsupported by any calculation in his paper) that the method is numerically stable, I found unsatisfactory numerical behavior for very large orders.\r\n/// Koepf suggests to use M. Bronstein's algorithm for finding rational solutions of linear ODEs for all other orthogonal polynomials (may be faster than recursion if we want to find the analytic form of the polynomial, but still slower if an explicit formula is available).\r\n//////////////////////////////////////////////////\r\n/// Main formulae: T(2*n,x) = 2*T(n,x)^2-1; T(2*n+1,x) = 2*T(n+1,x)*T(n,x)-x;\r\n/// U(2*n,x) = 2*T(n,x)*U(n,x)-1; T(2*n+1,x) = 2*T(n+1,x)*U(n,x);\r\n/// We avoid recursive calls and build the sequence of bits of n to determine the minimal sequence of n[i] for which T(n[i], x) and U(n[i], x) need to be computed\r\n//////////////////////////////////////////////////\r\n/*\r\n/// This function will return the list of binary bits, e.g. BitList(10) returns {1,0,1,0}.\r\nBitList(n) := BitList(n, {});\r\n/// This will not be called on very large numbers so it's okay to use recursion\r\n1# BitList(0, _bits) <-- bits;\r\n2# BitList(_n, _bits) <-- BitList(Div(n,2), Push(bits, Mod(n,2)));\r\n\r\n// Tchebyshev polynomials of 1st kind\r\n1 # FastOrthoT(0, _x) <-- 1;\r\n1 # FastOrthoT(1, _x) <-- x;\r\n// Tchebyshev polynomials of 2nd kind\r\n1 # FastOrthoU(0, _x) <-- 1;\r\n1 # FastOrthoU(1, _x) <-- 2*x;\r\n\r\n// guard against user errors\r\n2 # FastOrthoT(_n, _x) _ (IsInteger(n) And n<0) <-- Undefined;\r\n2 # FastOrthoU(_n, _x) _ (IsInteger(n) And n<0) <-- Undefined;\r\n\r\n// make T(), U() of even order more efficient: delegate gruntwork to odd order\r\n2 # FastOrthoT(n_IsEven, _x) <-- 2*FastOrthoT(Div(n,2), x)^2-1;\r\n2 # FastOrthoU(n_IsEven, _x) <-- 2*FastOrthoT(Div(n,2), x)*FastOrthoU(Div(n,2), x)-1;\r\n\r\n// FastOrthoT() of odd order\r\n3 # FastOrthoT(n_IsOdd, _x) <--\r\n[\r\n\tLocal(T1, T2, i);\r\n\t// first bit in the list is always 1, so initialize the pair\r\n\tT1 := FastOrthoT(1, x);\r\n\tT2 := FastOrthoT(2, x);\r\n\tForEach(i, Tail(BitList(n)))\t// skip first bit\r\n\t[\r\n\t\t// if the current bit is 1, we need to double the second index, else double the first index.\r\n\t\t// Invariant: n[i+1] = 2*n[i] + BitList[i] and we need to have FastOrthoT(n[i]), FastOrthoT(1+n[i]) as T1, T2. Initially n[1]=1 and after the cycle n[i]=n.\r\n\t\t{T1, T2} := If\r\n\t\t(\r\n\t\t\ti=1,\r\n\t\t\t{2*T1*T2-x, 2*T2^2-1},\r\n\t\t\t{2*T1^2-1, 2*T1*T2-x}\r\n\t\t);\r\n\t];\r\n\tT1;\r\n];\r\n\r\n// FastOrthoU() of any order\r\n3 # FastOrthoU(_n, _x) <--\r\n[\r\n\tLocal(U1, T1, T2, i);\r\n\t// first bit in the list is always 1, so initialize the pair\r\n\tU1 := FastOrthoU(1, x);\r\n\tT1 := FastOrthoT(1, x);\r\n\tT2 := FastOrthoT(2, x);\r\n\tForEach(i, Tail(BitList(n)))\t// skip first bit\r\n\t[\r\n\t\t// if the current bit is 1, we need to double the second index, else double the first index\r\n\t\t// Invariant: n[i+1] = 2*n[i] + BitList[i] and we need to have U(n[i]), T(n[i]), T(1+n[i]) as U1, T1, T2. Initially n[1]=1 and after the cycle n[i]=n.\r\n\t\t{U1, T1, T2} := If\r\n\t\t(\r\n\t\t\ti=1,\r\n\t\t\t{2*U1*T2, 2*T1*T2-x, 2*T2^2-1},\r\n\t\t\t{2*U1*T1-1, 2*T1^2-1, 2*T1*T2-x}\r\n\t\t);\r\n\t];\r\n\tU1;\r\n];\r\n*/\r\n//////////////////////////////////////////////////\r\n/// Fast symbolic computation of some polynomials\r\n//////////////////////////////////////////////////\r\n\r\n\r\n//////////////////////////////////////////////////\r\n/// Fast symbolic computation of Legendre polynomials\r\n//////////////////////////////////////////////////\r\n\r\n8# OrthoPolyCoeffs(\"Jacobi\", n_IsInteger, {0,0}) <--\r\n[\r\n\tLocal(i, result);\r\n\tresult := ZeroVector(n+1);\r\n\tresult[n+1] := (2*n-1)!! /n!;\t// coefficient at x^n\r\n\ti := 1;\r\n\tWhile(2*i<=n)\r\n\t[\t// prepare coefficient at x^(n-2*i) now\r\n\t\tresult[n+1-2*i] := -(result[n+3-2*i]*(n-2*i+1)*(n-2*i+2)) / ((2*n-2*i+1)*2*i);\r\n\t\ti++;\r\n\t];\r\n\tresult;\r\n];\r\n\r\n//////////////////////////////////////////////////\r\n/// Fast symbolic computation of Hermite polynomials\r\n//////////////////////////////////////////////////\r\n\r\nOrthoPolyCoeffs(\"Hermite\", n_IsInteger, {}) <-- HermiteCoeffs(n);\r\n\r\n/// Return the list of coefficiets of Hermite polynomials.\r\nHermiteCoeffs(n_IsEven)_(n>0) <--\r\n[\r\n\tLocal(i, k, result);\r\n\tk := Div(n,2);\r\n\tresult := ZeroVector(n+1);\r\n\tresult[1] := (-2)^k*(n-1)!!;\t// coefficient at x^0\r\n\tFor(i:=1,i<=k,i++)\t// prepare coefficient at x^(2*i) now\r\n\t\tresult[2*i+1] := Div(-2*result[2*i-1] * (k-i+1), (2*i-1)*i);\t// this division is always integer but faster with Div()\r\n\tresult;\r\n];\r\nHermiteCoeffs(n_IsOdd)_(n>0) <--\r\n[\r\n\tLocal(i, k, result);\r\n\tk := Div(n,2);\r\n\tresult := ZeroVector(n+1);\r\n\tresult[2] := 2*(-2)^k*(n!!);\t// coefficient at x^1\r\n\tFor(i:=1,i<=k,i++)\t// prepare coefficient at x^(2*i+1) now\r\n\t\tresult[2*i+2] := Div(-2*result[2*i] * (k-i+1), i*(2*i+1));\t// this division is always integer but faster with Div()\r\n\tresult;\r\n];\r\n\r\n//////////////////////////////////////////////////\r\n/// Fast symbolic computation of Laguerre polynomials\r\n//////////////////////////////////////////////////\r\n\r\n/// Return the list of coefficients of Laguerre polynomials.\r\nOrthoPolyCoeffs(\"Laguerre\", n_IsInteger, {_k}) <--\r\n[\r\n\tLocal(i, result);\r\n\tresult := ZeroVector(n+1);\r\n\tresult[n+1] := (-1)^n/n!;\t// coefficient at x^n\r\n\tFor(i:=n,i>=1,i--)\t// prepare coefficient at x^(i-1) now\r\n\t\tresult[i] := -(result[i+1]*i*(k+i))/(n-i+1);\r\n\tresult;\r\n];\r\n\r\n\r\n//////////////////////////////////////////////////\r\n/// Fast symbolic computation of Chebyshev polynomials\r\n//////////////////////////////////////////////////\r\n\r\nOrthoPolyCoeffs(\"Tscheb1\", n_IsInteger, {}) <-- ChebTCoeffs(n);\r\nOrthoPolyCoeffs(\"Tscheb2\", n_IsInteger, {}) <-- ChebUCoeffs(n);\r\n\r\n1 # ChebTCoeffs(0) <-- {1};\r\n2 # ChebTCoeffs(n_IsInteger) <--\r\n[\r\n\tLocal(i, result);\r\n\tresult := ZeroVector(n+1);\r\n\tresult[n+1] := 2^(n-1);\t// coefficient at x^n\r\n\ti := 1;\r\n\tWhile(2*i<=n)\r\n\t[\t// prepare coefficient at x^(n-2*i) now\r\n\t\tresult[n+1-2*i] := -(result[n+3-2*i]*(n-2*i+2)*(n-2*i+1)) / ((n-i)*4*i);\r\n\t\ti++;\r\n\t];\r\n\tresult;\r\n];\r\n\r\n1 # ChebUCoeffs(0) <-- {1};\r\n2 # ChebUCoeffs(n_IsInteger) <--\r\n[\r\n\tLocal(i, result);\r\n\tresult := ZeroVector(n+1);\r\n\tresult[n+1] := 2^n;\t// coefficient at x^n\r\n\ti := 1;\r\n\tWhile(2*i<=n)\r\n\t[\t// prepare coefficient at x^(n-2*i) now\r\n\t\tresult[n+1-2*i] := -(result[n+3-2*i]*(n-2*i+2)*(n-2*i+1)) / ((n-i+1)*4*i);\r\n\t\ti++;\r\n\t];\r\n\tresult;\r\n];\r\n"
  },
  {
    "path": "scripts/orthopoly.rep/code.ys.def",
    "content": "OrthoP\nOrthoG\nOrthoH\nOrthoL\nOrthoT\nOrthoU\nOrthoPSum\nOrthoGSum\nOrthoHSum\nOrthoLSum\nOrthoTSum\nOrthoUSum\nEvaluateHornerScheme\n}\n"
  },
  {
    "path": "scripts/packages.ys",
    "content": "Defun(DefFileList,{}) {\n    \"array.rep/code.ys\",\n    \"assoc.rep/code.ys\",\n    \"base.rep/math.ys\",\n    \"c_form.rep/code.ys\",\n    \"calendar.rep/code.ys\",\n    \"complex.rep/code.ys\",\n    \"constants.rep/code.ys\",\n    \"controlflow.rep/code.ys\",\n    \"cse.rep/cse.ys\",\n    \"debug.rep/code.ys\",\n    \"deffunc.rep/code.ys\",\n    \"deriv.rep/code.ys\",\n    \"example.rep/code.ys\",\n    \"factors.rep/binaryfactors.ys\",\n    \"factors.rep/code.ys\",\n    \"functional.rep/code.ys\",\n    \"graph.rep/code.ys\",\n    \"html.rep/code.ys\",\n    \"integrate.rep/code.ys\",\n    \"io.rep/code.ys\",\n    \"io.rep/defaultprint.ys\",\n    \"limit.rep/code.ys\",\n    \"linalg.rep/code.ys\",\n    \"lists.rep/code.ys\",\n    \"lists.rep/scopestack.ys\",\n    \"localrules.rep/code.ys\",\n    \"logic.rep/code.ys\",\n    \"multivar.rep/code.ys\",\n    \"multivar.rep/sparsetree.ys\",\n    \"newly.rep/code.ys\",\n    \"nintegrate.rep/code.ys\",\n    \"numbers.rep/GaussianIntegers.ys\",\n    \"numbers.rep/NumberTheory.ys\",\n    \"numbers.rep/code.ys\",\n    \"numbers.rep/nthroot.ys\",\n    \"odesolver.rep/code.ys\",\n    \"openmath.rep/code.ys\",\n    \"orthopoly.rep/code.ys\",\n    \"padic.rep/code.ys\",\n    \"patterns.rep/code.ys\",\n    \"physics.rep/quantum/clebsch-gordan.ys\",\n    \"plots.rep/code.ys\",\n    \"plots.rep/plot2d.ys\",\n    \"plots.rep/plot3d.ys\",\n    \"predicates.rep/code.ys\",\n    \"probability.rep/code.ys\",\n    \"products.rep/code.ys\",\n    \"pslq.rep/code.ys\",\n    \"r_form.rep/code.ys\",\n    \"rabinmiller.rep/code.ys\",\n    \"radsimp.rep/code.ys\",\n    \"random.rep/code.ys\",\n    \"rational.rep/code.ys\",\n    \"simplify.rep/code.ys\",\n    \"simplify.rep/factorial.ys\",\n    \"solve.rep/code.ys\",\n    \"specfunc.rep/bernou.ys\",\n    \"specfunc.rep/bessel.ys\",\n    \"specfunc.rep/code.ys\",\n    \"specfunc.rep/gamma.ys\",\n    \"specfunc.rep/gammaconst.ys\",\n    \"specfunc.rep/zeta.ys\",\n    \"standard.ys\",\n    \"statistics.rep/distributions.ys\",\n    \"statistics.rep/hypothesystest.ys\",\n    \"statistics.rep/incompletegamma.ys\",\n    \"statistics.rep/regression.ys\",\n    \"statistics.rep/statistics.ys\",\n    \"stats.rep/code.ys\",\n    \"stdarith.ys\",\n    \"stdfuncs.rep/code.ys\",\n    \"stdfuncs.rep/elemfuncs.ys\",\n    \"stdfuncs.rep/numerical.ys\",\n    \"stdfuncs.rep/nummethods.ys\",\n    \"stubs.rep/code.ys\",\n    \"substitute.rep/code.ys\",\n    \"sums.rep/code.ys\",\n    \"sums.rep/taylor.ys\",\n    \"sums.rep/taylor3.ys\",\n    \"tensor.rep/code.ys\",\n    \"testers.rep/code.ys\",\n    \"texform.rep/code.ys\",\n    \"transforms.rep/code.ys\",\n    \"trigsimp.rep/code.ys\",\n    \"univar.rep/Cyclotomic.ys\",\n    \"univar.rep/code.ys\",\n    \"univar.rep/sparse.ys\",\n    \"univar.rep/sturm.ys\",\n};\n\n"
  },
  {
    "path": "scripts/padic.rep/code.ys",
    "content": "/*\n Mini-module padic. This module creates a p-adic expansion of\n an expression:\n\n expression = a0 + a1*p + a2 * p^2 + ... etc.\n\n PAdicExpand and PAdicExpandInternal can be called with integer\n or univariate polynomial arguments.\n*/\n\n10 # PAdicExpand(_x,_y) <--\n[\n  Local(coefs);\n  coefs:=PAdicExpandInternal(x,y);\n  Subst(p,y)Add(coefs*(p^(0 .. Length(coefs)-1)));\n];\n \n10 # PAdicExpandInternal(0,_y) <-- {};\n20 # PAdicExpandInternal(_x,_y) <--\n[\n  Mod(x,y) : PAdicExpandInternal(Div(x,y),y);\n];\n\n\n/* Extended Euclidean algorithm. Algorithm taken from\n * \"Modern Computer Algebra\". It does a Gcd calculation, but\n * returns the intermediate results also.\n *\n * Returns {r,s,t}\n * where \n * - r the remainder\n * - s and t are the Bezout coefficients of f and g:\n     s*f + t*g = r\n *\n * This is a slightly modified version from the one described in\n * \"Modern Computer Algebra\", where the remainder r is not\n * monic. If needed this can be done afterwards. As a consequence\n * this version works on integers as well as on polynomials.\n */\nExtendedEuclidean(_f,_g) <--\n[\n   Local(r1, r2, s1, s2, t1, t2, newr, news, newt, q);\n\n   r1 := f;\n   r2 := g;\n\n   s1 := 1;\n   s2 := 0;\n\n   t1 := 0;\n   t2 := 1;\n\n   newr := 1;\n\n   While (newr != 0) [\n     newr := Rem(r1, r2);\n     q := Div(r1, r2);\n     news := s1 - q * s2;\n     newt := t1 - q * t2;\n\n     r1 := r2;\n     s1 := s2;\n     t1 := t2;\n\n     r2 := newr;\n     s2 := news;\n     t2 := newt;\n   ];\n\n   {r1, s1, t1};\n];\n\nExtendedEuclideanMonic(_f,_g) <--\n[\n   Local(rho1, rho2, r1, r2, s1, s2, t1, t2, newrho, newr, news, newt, q);\n\n   rho1 := LeadingCoef(f);\n   rho2 := LeadingCoef(g);\n\n   r1 := Monic(f);\n   r2 := Monic(g);\n\n   s1 := 1 / rho1;\n   s2 := 0;\n\n   t1 := 0;\n   t2 := 1 / rho2;\n\n   newr := r2;\n\n   While (newr != 0) [\n     q := Div(r1, r2);\n     newr := Mod(r1, r2);\n     newrho := LeadingCoef(newr);\n\n     If (newr != 0, newr := Monic(newr));\n\n     news := s1 - q * s2;\n     newt := t1 - q * t2;\n\n     If(newrho != 0, [\n         news := news / newrho;\n         newt := newt / newrho;\n     ]);\n\n     rho := newrho;\n\n     r1 := r2;\n     s1 := s2;\n     t1 := t2;\n\n     r2 := newr;\n     s2 := news;\n     t2 := newt;\n   ];\n\n   {r1, s1, t1};\n];\n\n// Manuel Bronstein, Symbolic Integration I: Transcendental Functions\n// Extended Euclidean algorithm, diophantine version\nExtendedEuclidean(a_CanBeUni, b_CanBeUni, c_CanBeUni) <--\n[\n    Local(s, t, g, q, r);\n    // Note: ExtendedEuclidean as implemented in yacas returns\n    // results in different order than the version in Bronstein's book\n    {g, s, t} := ExtendedEuclidean(a, b);\n    q := Div(c, g);\n    r := Rem(c, g);\n    Check(r = 0, \"not an ideal\");\n    s := Expand(q * s);\n    t := Expand(q * t);\n    If (s != 0 And Degree(s) >= Degree(b), [\n        q := Div(s, b);\n        r := Rem(s, b);\n        s := r;\n        t := Expand(t + q * a);\n    ]);\n    {s, t};\n];\n\n\n\n\n\n\n/* Chinese Remaindering algorithm, as described in \"Modern Computer Algebra\".\n */\nChineseRemainderInteger(mlist_IsList,vlist_IsList) <--\n[\n  Local(m,i,nr,result,msub,euclid,clist);\n  clist:={};\n  m:=Multiply(mlist);\n  result:=0;\n  \n  nr:=Length(mlist);\n  For(i:=1,i<=nr,i++)\n  [\n    msub:=Div(m,mlist[i]);\n    euclid := ExtendedEuclidean(msub,mlist[i]);\n    Local(c);\n    c:=vlist[i] * euclid[2];\n    c:=Rem(c, mlist[i]);\n    DestructiveAppend(clist,c);\n    result:=result + msub * c;\n  ];\n  {result,clist};\n];\nChineseRemainderPoly(mlist_IsList,vlist_IsList) <--\n[\n  Local(m,i,nr,result,msub,euclid,clist);\n  clist:={};\n  m:=Multiply(mlist);\n  result:=0;\n\n/* Echo({mlist,m}); */\n\n  \n  nr:=Length(mlist);\n  For(i:=1,i<=nr,i++)\n  [\n    msub:=Div(m,mlist[i]);\n\n/* Echo({Factor(msub)}); */\n\n    euclid := ExtendedEuclideanMonic(msub,mlist[i]);\n    Local(c);\n\n    c:=vlist[i] * euclid[2];\n\n    c:=Mod(c, mlist[i]);\n\n    DestructiveAppend(clist,c);\n    result:=result + msub * c;\n  ];\n  {Expand(result),clist};\n];\n\n/* Partial fraction expansion of g/f with Degree(g)<Degree(f) */\nPartFracExpand(_g,_f) <--\n[\n  Local(mlist,vlist,res);\n\n/* Echo({\"factors = \",Factors(f)}); */\n\n  mlist:=Map(\"^\",Transpose(Factors(f)));\n\n/* Echo({\"mlist = \",mlist}); */\n\n  vlist:=Map(\"Rem\",{FillList(g,Length(mlist)),mlist});\n\n  \n/* Echo({\"g = \",g}); */\n/* Echo({\"vlist = \",vlist}); */\n\n  If(IsInteger(f), [\n    Local(t,r,m);\n\n    res:=ChineseRemainderInteger(mlist,vlist)[2];\n\n    r := {};\n    m := {};\n\n    ForEach(t, Transpose({res,mlist})) [\n      Local(f,p,c,n);\n\n      f := Factors(t[2])[1];\n\n      p := f[1];\n      c := Sign(t[1])*PAdicExpandInternal(Abs(t[1]), p);\n\n      r := Concat(r, Reverse(c));\n      m := Concat(m, MapSingle({{n}, p^n}, (1 .. f[2])));\n    ];\n\n    res := r;\n    mlist := m;\n  ],\n  [\n    Local(t,r,m);\n\n    res := ChineseRemainderPoly(mlist,vlist)[2];\n\n    r := {};\n    m := {};\n\n    ForEach(t, Transpose({res,mlist})) [\n      Local(f,p,c,n);\n\n      f := Factors(t[2])[1];\n\n      p := f[1];\n      c := PAdicExpandInternal(t[1], p);\n\n      r := Concat(r, Reverse(c));\n      m := Concat(m, MapSingle({{n}, p^n}, (1 .. f[2])));\n    ];\n\n    res := r;\n    mlist := m;\n  ]);\n\n/* Echo({res,mlist});  */\n  Local(result,divlist);\n\n\n  divlist:=Map(\"/\",{res,mlist});\n\n  If(Length(divlist)<2,\n    Add(divlist),\n    [\n      result:=divlist[1];\n      ForEach(item,Tail(divlist))\n      [\n        result:=UnList({Atom(\"+\"),result,item});\n      ];\n      result;\n    ]);\n];\n\n\n10 # RationalForm((g_CanBeUni(var))/(f_CanBeUni(var)),_var)\n     <-- { MakeUni(g,var),MakeUni(f,var)};\n20 # RationalForm(f_CanBeUni(var),_var)\n     <-- { MakeUni(f,var),MakeUni(1,var)};\n\nApart(_f) <-- Apart(f,x);\n\nApart(_f,_var) <--\n[\n  Local(rat);\n  rat:=RationalForm(f,var);\n  If(Degree(rat[1],var) = 0 And Degree(rat[2],var) = 0,\n     [\n       rat:={Coef(rat[1],var,0),Coef(rat[2],var,0)};\n       Local(summed,add);\n       summed := Eval(PartFracExpand(Rem(rat[1],rat[2]),rat[2]));\n       add:=(rat[1]/rat[2] - summed);\n       add + summed;\n     ]\n     ,\n     [\n       /*TODO check this one! Do we have to do the same as with the\n        * integers?\n        */\n       Expand(Div(rat[1],rat[2])) + PartFracExpand(Rem(rat[1],rat[2]),rat[2]);\n     ]\n     );\n];\n\n\n\n10 # Together((_f/_g) + (_h/_i)) <--\n     Expand(f*i+h*g)/Expand(g*i);\n10 # Together((_f/_g) - (_h/_i)) <--\n     Expand(f*i-h*g)/Expand(g*i);\n\n20 # Together(_f + (_g / _h)) <--\n     Expand(f*h+g)/h;\n20 # Together((_f/_g) + _h) <--\n     Expand(f+h*g)/g;\n\n20 # Together(_f - (_g / _h)) <--\n     Expand(f*h-g)/h;\n20 # Together((_f/_g) - _h) <--\n     Expand(f-h*g)/g;\n\n20 # Together(- (_g / _h)) <-- (-g)/h;\n\n20 # Together((_f/_g) * _h) <--\n     Expand(f*h)/g;\n20 # Together(_h * (_f/_g)) <--\n     Expand(f*h)/g;\n\n20 # Together((_f/_g) / _h) <--\n     (f)/Expand(g*h);\n20 # Together(_h / (_f/_g)) <--\n     Expand(g*h)/f;\n\n20 # Together(- _f) <-- - Together(f);\n30 # Together(_f) <--  f;\n\n/* Reduce rational function by dividing gcd away */\nGcdReduce(_f,_var)<--\n[\n  Local(rat,gcd); \n  rat:=RationalForm(f,var);\n  gcd:=Gcd(rat[1],rat[2]);\n/*  gcd:=gcd*Gcd(Content(rat[1]),Content(rat[2]));*/\n\n  Local(numer,denom,lc);\n  numer:=Div(rat[1],gcd);\n  denom:=Div(rat[2],gcd);\n  lc:=LeadingCoef(numer,var);\n  numer:=numer/lc;\n  denom:=denom/lc;\n  Expand(numer)/Expand(denom);\n];\n\n"
  },
  {
    "path": "scripts/padic.rep/code.ys.def",
    "content": "PAdicExpand\nPAdicExpandInternal\nApart\nTogether\nGcdReduce\nExtendedEuclidean\nExtendedEuclideanMonic\n}\n"
  },
  {
    "path": "scripts/patterns.rep/code.ys",
    "content": "\n\nRuleBase(\"MakeVector\",{vec,dimension});\nRule(\"MakeVector\",2,1,True)\n[\n    Local(res,i);\n    res:={};\n    i:=1;\n    Set(dimension,MathAdd(dimension,1));\n    While(LessThan(i,dimension))\n    [\n      DestructiveInsert(res,1,Atom(ConcatStrings(String(vec),String(i))));\n      Set(i,MathAdd(i,1));\n    ];\n    DestructiveReverse(res);\n];\n\n\nRuleBase(\"<--\",{patternleft,patternright});\n\nRule(\"<--\",2,1,Equals(Type(patternleft),\"#\"))\n[\n  DefinePattern(patternleft[2],patternright,patternleft[1],True);\n];\nRule(\"<--\",2,2,IsFunction(patternleft))\n[\n DefinePattern(patternleft,patternright,0,True);\n];\nHoldArg(\"<--\",patternleft);\nHoldArg(\"<--\",patternright);\n\nRuleBase(\"DefinePattern\",\n         {patternleft,patternright,patternprecedence,postpredicate});\nRule(\"DefinePattern\",4,9,Equals(Type(patternleft),\"_\"))\n[\n DefinePattern(patternleft[1],patternright,\n               patternprecedence,patternleft[2]);\n];\n\nRule(\"DefinePattern\",4,10,True)\n[\n  Local(patternflat,patternvars, patt, patternoper,arity);\n  Set(patternflat, Listify(patternleft));\n  Set(patternvars, Tail(patternflat));\n  Set(patternoper,String(Head(patternflat)));\n  Set(arity,Length(patternvars));\n  DefLoadFunction(patternoper);\n  If(Not(RuleBaseDefined(patternoper,arity)),\n     [\n      MacroRuleBase(patternoper,MakeVector(arg,arity));\n     ]\n    );\n  Set(patt,Pattern'Create(patternvars,postpredicate));\n  MacroRulePattern(patternoper,arity,patternprecedence,\n            patt)patternright;\n  True;\n];\n\n\n"
  },
  {
    "path": "scripts/patterns.rep/code.ys.def",
    "content": "<--\n#\nMakeVector\n}\n"
  },
  {
    "path": "scripts/physics.rep/quantum/clebsch-gordan.ys",
    "content": "10 # ClebschGordan({_j1, _m1}, {_j2, _m2}, {_J, _M})_(j1 = m1 And j2 = m2 And J = M) <-- 1;\n\n20 # ClebschGordan({_j1, _m1}, {_j2, _m2}, {0, 0})_(j1 = j2 And m1 = -m2) <-- (-1)^(j1-m1) / Sqrt(2*j1+1);\n\n100 # ClebschGordan({_j1, m1_IsRationalOrNumber}, {_j2, m2_IsRationalOrNumber}, {_J, M_IsRationalOrNumber})_(m1 + m2 != M) <-- 0;\n\n200 # ClebschGordan({j1_IsRationalOrNumber, m1_IsRationalOrNumber}, {j2_IsRationalOrNumber, m2_IsRationalOrNumber}, {J_IsRationalOrNumber, M_IsRationalOrNumber}) <-- [\n    Local(s,p,q,i);\n    s := j1 + j2 + J;\n    p := Sqrt((2*J+1) / (s+1)! * Multiply(MapSingle(!,{s-2*J,s-2*j2,s-2*j1,j1+m1,j1-m1,j2+m2,j2-m2,J+M,J-M})));\n    q := Sum(i, Max(-J + j1 + m2, -J + j2 - m1, 0), Min(j2 + m2, j1 - m1, s - J), (-1)^i / (i! * (j1+j2-J-i)! * (j1-m1-i)! * (j2+m2-i)! * (J-j2+m1+i)! * (J-j1-m2+i)!));\n    p*q;\n];\n"
  },
  {
    "path": "scripts/physics.rep/quantum/clebsch-gordan.ys.def",
    "content": "ClebschGordan\n}\n"
  },
  {
    "path": "scripts/plots.rep/backends-2d.ys",
    "content": "//////////////////////////////////////////////////\n/// Backends for 2D plotting\n//////////////////////////////////////////////////\n\n/// List of all defined backends and their symbolic labels.\n/// Add any new backends here\nPlot2D'outputs() := {\n    {\"default\", \"gnuplot\"},\n    {\"data\", \"Plot2D'data\"},\n    {\"gnuplot\", \"Plot2D'gnuplot\"},\n    {\"png\", \"Plot2D'png\"},\n    {\"java\", \"Plot2D'java\"},\n};\n\n/*\n    How backends work:\n    Plot2D'<backend>(values, options'hash)\n    options'hash is a hash that contains all plotting options:\n    [\"xrange\"] - a list of {x1, x2}, [\"xname\"] - name of the variable to plot, [\"yname\"] - array of string representations of the function(s), and perhaps other options relevant to the particular backend.\n    {values} is a list of lists of pairs of the form {{{x1, y1}, {x2, y2}, ...}, {{x1, z1}, {x2, z2}, ...}, ...} corresponding to the functions y(x), z(x), ... to be plotted. The abscissa points x[i] are not the same for all functions.\n    The backend should prepare the graph of the function(s). The \"datafile\" backend Plot2D'datafile(values, options'hash) may be used to output all data to file(s), in which case the file name should be given by the value options'hash[\"filename\"]. Multiple files are created with names obtained by appending numbers to the filename.\n    Note that the \"data\" backend does not do anything and simply returns the data.\n    The backend Plot2D'datafile takes care not to write \"Infinity\" or \"Undefined\" data points (it just ignores them). Custom backends should either use Plot2D'datafile or take care of this themselves.\n*/\n\n/// trivial backend: return data list (do not confuse with Plot2D'get'data() defined in the main code which is the middle-level plotting routine)\nPlot2D'data(values_IsList, _options'hash) <-- values;\n\nPlot2D'gnuplot'command(_file) <--\n    If (SystemName() = \"Windows\", \"cmd /c start /b gnuplot --persist \" : file, \"gnuplot --persist \" : file);\n\n/// backend: display graph using gnuplot\nPlot2D'gnuplot(values_IsList, _options'hash) <--\n[\n  Local(item, dirBase, filename'list, control'file);\n  filename'list := Plot2D'datafile(values, options'hash);\n  control'file := TmpFile();\n  ToFile(control'file)\n  [\n        // 'set xrange [-5:5]'\n        WriteString(\"set xrange [\");\n        Write(options'hash[\"xrange\"][1]);\n        WriteString(\" : \");\n        Write(options'hash[\"xrange\"][2]);\n        WriteString(\"]\" : Nl());\n        // 'set yrange [0:1]'\n        If(\n                options'hash[\"yrange\"] != Empty,\n                [\n                        WriteString(\"set yrange [\");\n                        Write(options'hash[\"yrange\"][1]);\n                        WriteString(\" : \");\n                        Write(options'hash[\"yrange\"][2]);\n                        WriteString(\"]\" : Nl());\n                ]\n        );\n        // 'plot \"data1\" title \"y(x)\" with lines, \"data2\" title \"z(x)\" with lines'\n        WriteString(\"plot \");\n        For(item:=1, item<=Length(values), item++)\n        [\n                WriteString(\"\\\"\" : StringReplace(\"\\\\\", \"\\\\\\\\\", filename'list[item]) : \"\\\" smooth csplines title \\\"\" : options'hash[\"yname\"][item] : \"\\\" with lines\");\n                If(item<Length(values), WriteString(\", \"));\n        ];\n        WriteString(Nl());\n  ];\n  SystemCall(Plot2D'gnuplot'command(control'file));\n];\n\n/// backend: use gnuplot to generate png\nPlot2D'png(values_IsList, _options'hash) <--\n[\n  Local(item, dirBase, filename'list, control'file, png'file);\n  filename'list := Plot2D'datafile(values, options'hash);\n  control'file := TmpFile();\n  png'file := If (options'hash[\"filename\"] != Empty, options'hash[\"filename\"], TmpFile());\n  ToFile(control'file)\n  [\n        WriteString(\"set output \\\"\" : StringReplace(\"\\\\\", \"\\\\\\\\\", png'file) : \"\\\"\" : Nl());\n        WriteString(\"set terminal png\" : Nl());\n        WriteString(\"set xrange [\");\n        Write(options'hash[\"xrange\"][1]);\n        WriteString(\" : \");\n        Write(options'hash[\"xrange\"][2]);\n        WriteString(\"]\" : Nl());\n        If(\n                options'hash[\"yrange\"] != Empty,\n                [\n                        WriteString(\"set yrange [\");\n                        Write(options'hash[\"yrange\"][1]);\n                        WriteString(\" : \");\n                        Write(options'hash[\"yrange\"][2]);\n                        WriteString(\"]\" : Nl());\n                ]\n        );\n        WriteString(\"plot \");\n        For(item:=1, item<=Length(values), item++)\n        [\n                WriteString(\"\\\"\" : StringReplace(\"\\\\\", \"\\\\\\\\\", filename'list[item]) : \"\\\" smooth csplines title \\\"\" : options'hash[\"yname\"][item] : \"\\\" with lines\");\n                If(item<Length(values), WriteString(\", \"));\n        ];\n        WriteString(Nl());\n  ];\n\n  SystemCall(Plot2D'gnuplot'command(control'file));\n  File(png'file, \"image/png\");\n];\n\n\n/// backend: write data into file.\n/// Returns the list of created filenames\n/// This backend is used by other backends to write data to files.\nPlot2D'datafile(values_IsList, _options'hash) <--\n[\n        Local(item, func, filename, filename'list);\n        filename'list := {};\n        For(func:=1, func<=Length(values), func++)\n        [\n                filename := TmpFile();\n                DestructiveAppend(filename'list, filename);\n                ToFile(filename) ForEach(item, values[func]) WriteDataItem(item, options'hash);\n                If(InVerboseMode(), Echo( \"Plot2D'datafile: created file '\" : filename :  \"'\"), True);\n        ];\n        filename'list;\n];\n\n/// The Java back-end generates a call-list that the Java graph plotter can handle\nPlot2D'java(values_IsList, _options'hash) <--\n[\n  Local(result,count);\n  count := 0;\n  result:=\"$plot2d:\";\n\n  result := result:\" pensize 2.0 \";\n  ForEach(function,values)\n  [\n    result := result:ColorForGraphNr(count);\n    count++;\n    result:=result:\" lines2d \":String(Length(function));\n\n    function:=Select(Lambda({item},item[2] != Undefined),function);\n\n    ForEach(item,function)\n    [\n      result := result:\" \":String(item[1]):\" \":String(item[2]):\" \";\n    ];\n  ];\n  WriteString(result:\"$\");\n  True;\n];\n\n10 # ColorForGraphNr(0) <-- \" pencolor 64 64 128 \";\n10 # ColorForGraphNr(1) <-- \" pencolor 128 64 64 \";\n10 # ColorForGraphNr(2) <-- \" pencolor 64 128 64 \";\n20 # ColorForGraphNr(_count) <-- ColorForGraphNr(Mod(count,3));\n\n\n\n\n\n"
  },
  {
    "path": "scripts/plots.rep/backends-3d.ys",
    "content": "//////////////////////////////////////////////////\n/// Backends for 3D plotting\n//////////////////////////////////////////////////\n\n/// List of all defined backends and their symbolic labels.\n/// Add any new backends here\nPlot3DS'outputs() := {\n    {\"default\", \"gnuplot\"},\n    {\"data\", \"Plot3DS'data\"},\n    {\"gnuplot\", \"Plot3DS'gnuplot\"},\n    {\"png\", \"Plot3DS'png\"}\n};\n\n/*\n    How backends work:\n    Plot3DS'<backend>(values, options'hash)\n    options'hash is a hash that contains all plotting options:\n    [\"xrange\"] - a list of {x1, x2}, [\"xname\"] - name of the variable to plot, same for \"yrange\";\n    [\"zname\"] - array of string representations of the function(s), and perhaps other options relevant to the particular backend.\n    {values} is a list of lists of triples of the form {{{x1, y1, z1}, {x2, y2, z2}, ...}, {{x1, y1, t1}, {x2, y2, t2}, ...}, ...} corresponding to the functions z(x,y), t(x,y), ... to be plotted. The points x[i], y[i] are not necessarily the same for all functions.\n    The backend should prepare the graph of the function(s). The \"datafile\" backend Plot3DS'datafile(values, options'hash) may be used to output all data to file(s), in which case the file name should be given by the value options'hash[\"filename\"]. Multiple files are created with names obtained by appending numbers to the filename.\n    Note that the \"data\" backend does not do anything and simply returns the data.\n    The backend Plot3DS'datafile takes care not to write \"Infinity\" or \"Undefined\" data points (it just ignores them). Custom backends should either use Plot3DS'datafile to prepare a file, or take care of this themselves.\n*/\n\n/// trivial backend: return data list (do not confuse with Plot3DS'get'data() defined in the main code which is the middle-level plotting routine)\nPlot3DS'data(values_IsList, _options'hash) <-- values;\n\nPlot3DS'gnuplot'command(_file) <--\n    If (SystemName() = \"Windows\", \"cmd /c start /b gnuplot --persist \" : file, \"gnuplot --persist \" : file);\n\n/// backend: display graph using gnuplot\nPlot3DS'gnuplot(values_IsList, _options'hash) <--\n[\n  Local(item, dirBase, filename'list, control'file);\n  filename'list := Plot3DS'datafile(values, options'hash);\n  control'file := TmpFile();\n  ToFile(control'file)\n  [\n        WriteString(\"set surface\" : Nl() : If(options'hash[\"hidden\"], \"set hidden3d\" : Nl(), \"\"));\n        // 'set xrange [-5:5]'\n        WriteString(\"set xrange [\");\n        Write(options'hash[\"xrange\"][1]);\n        WriteString(\" : \");\n        Write(options'hash[\"xrange\"][2]);\n        WriteString(\"]\" : Nl());\n        WriteString(\"set yrange [\");\n        Write(options'hash[\"yrange\"][1]);\n        WriteString(\" : \");\n        Write(options'hash[\"yrange\"][2]);\n        WriteString(\"]\" : Nl());\n        If(\n                options'hash[\"zrange\"] != Empty,\n                [\n                        WriteString(\"set zrange [\");\n                        Write(options'hash[\"zrange\"][1]);\n                        WriteString(\" : \");\n                        Write(options'hash[\"zrange\"][2]);\n                        WriteString(\"]\" : Nl());\n                ]\n        );\n        WriteString(\"set dgrid3d \");\n        Write(1+options'hash[\"xpoints\"]*2^(options'hash[\"depth\"] - options'hash[\"used depth\"]));\n        WriteString(\",\");\n        Write(1+options'hash[\"ypoints\"]*2^(options'hash[\"depth\"] - options'hash[\"used depth\"]));\n        WriteString(Nl());\n        // 'plot \"data1\" title \"y(x)\" with lines, \"data2\" title \"z(x)\" with lines'\n        WriteString(\"splot \");\n        For(item:=1, item<=Length(values), item++)\n        [\n                WriteString(\"\\\"\" : StringReplace(\"\\\\\", \"\\\\\\\\\", filename'list[item]) : \"\\\" title \\\"\" : options'hash[\"zname\"][item] : \"\\\" with lines\");\n                If(item<Length(values), WriteString(\", \"));\n        ];\n        WriteString(Nl());\n  ];\n  SystemCall(Plot3DS'gnuplot'command(control'file));\n];\n\n/// backend: use gnuplot to generate png\nPlot3DS'png(values_IsList, _options'hash) <--\n[\n  Local(item, dirBase, filename'list, control'file, png'file);\n  filename'list := Plot3DS'datafile(values, options'hash);\n  control'file := TmpFile();\n  png'file := If (options'hash[\"filename\"] != Empty, options'hash[\"filename\"], TmpFile());\n  ToFile(control'file)\n  [\n        WriteString(\"set output \\\"\" : StringReplace(\"\\\\\", \"\\\\\\\\\", png'file) : \"\\\"\" : Nl());\n        WriteString(\"set terminal png\" : Nl());\n        WriteString(\"set surface\" : Nl() : If(options'hash[\"hidden\"], \"set hidden3d\" : Nl(), \"\"));\n        WriteString(\"set xrange [\");\n        Write(options'hash[\"xrange\"][1]);\n        WriteString(\" : \");\n        Write(options'hash[\"xrange\"][2]);\n        WriteString(\"]\" : Nl());\n        WriteString(\"set yrange [\");\n        Write(options'hash[\"yrange\"][1]);\n        WriteString(\" : \");\n        Write(options'hash[\"yrange\"][2]);\n        WriteString(\"]\" : Nl());\n        If(\n                options'hash[\"zrange\"] != Empty,\n                [\n                        WriteString(\"set zrange [\");\n                        Write(options'hash[\"zrange\"][1]);\n                        WriteString(\" : \");\n                        Write(options'hash[\"zrange\"][2]);\n                        WriteString(\"]\" : Nl());\n                ]\n        );\n        WriteString(\"set dgrid3d \");\n        Write(1+options'hash[\"xpoints\"]*2^(options'hash[\"depth\"] - options'hash[\"used depth\"]));\n        WriteString(\",\");\n        Write(1+options'hash[\"ypoints\"]*2^(options'hash[\"depth\"] - options'hash[\"used depth\"]));\n        // WriteString(\",\");\n        // Write(4);       // gnuplot's \"norm\" for its primitive interpolation\n        WriteString(Nl());\n        WriteString(\"splot \");\n        For(item:=1, item<=Length(values), item++)\n        [\n                WriteString(\"\\\"\" : StringReplace(\"\\\\\", \"\\\\\\\\\", filename'list[item]) : \"\\\" title \\\"\" : options'hash[\"zname\"][item] : \"\\\" with lines\");\n                If(item<Length(values), WriteString(\", \"));\n        ];\n        WriteString(Nl());\n  ];\n  SystemCall(Plot3DS'gnuplot'command(control'file));\n  File(png'file, \"image/png\");\n];\n\n/// backend: write data into file.\n/// Returns the list of created filenames\n/// This backend is used by other backends to write data to files.\nPlot3DS'datafile(values_IsList, _options'hash) <--\n[\n        Local(item, func, filename, filename'list);\n        filename'list := {};\n        For(func:=1, func<=Length(values), func++)\n        [\n                filename := TmpFile();\n                DestructiveAppend(filename'list, filename);\n                ToFile(filename) ForEach(item, values[func]) WriteDataItem(item, options'hash);\n                If(InVerboseMode(), Echo( \"Plot3DS'datafile: created file '\" : filename :  \"'\"), True);\n        ];\n        filename'list;\n];\n"
  },
  {
    "path": "scripts/plots.rep/code.ys",
    "content": "/// Common functions used by all plotting packages\n\n/// utility function: convert options lists of the form\n/// \"{key=value, key=value}\" into a hash of the same form.\n/// The argument list is kept unevaluated using \"HoldArgNr()\".\n/// Note that symbolic values of type atom are automatically converted to strings, e.g. ListToHash(a=b) returns {{\"a\", \"b\"}}\nListToHash(list) :=\n[\n\tLocal(item, result);\n\tresult := {};\n\tForEach(item, list)\n\t\tIf(\n\t\t\tIsFunction(item) And (Type(item) = \"=\" Or Type(item) = \"==\") And IsAtom(item[1]),\n\t\t\tresult[String(item[1])] := If(\n\t\t\t\tIsAtom(item[2]) And Not IsNumber(item[2]) And Not IsString(item[2]),\n\t\t\t\tString(item[2]),\n\t\t\t\titem[2]\n\t\t\t),\n\t\t\tEcho({\"ListToHash: Error: item \", item, \" is not of the format a=b or a==b\"})\n\t\t);\n\tresult;\n];\n\nHoldArgNr(\"ListToHash\", 1, 1);\n\n\n/// utility function: check whether the derivative changes sign in given 3 numbers, return 0 or 1. Also return 1 when one of the arguments is not a number.\nsign'change(x,y,z) :=\nIf(\n\tIsNumber(x) And IsNumber(y) And IsNumber(z)\n\tAnd Not (\n\t\tx>y And y<z\n\t\t\tOr\n\t\tx<y And y>z\n\t)\n, 0, 1); \n\n\n\n/// service function. WriteDataItem({1,2,3}, {}) will output \"1 2 3\" on a separate line.\n/// Writes data points to the current output stream, omits non-numeric values.\nWriteDataItem(tuple_IsList, _options'hash) <--\n[\n  Local(item);\n  If(\t// do not write anything if one of the items is not a number\n  \tIsNumericList(tuple),\n\tForEach(item,tuple)\n\t[\n\t\tWrite(item);\n\t\tSpace();\n\t]\n  );\n  NewLine();\n];\n\n\n10 # RemoveRepeated({}) <-- {};\n10 # RemoveRepeated({_x}) <-- {x};\n20 # RemoveRepeated(list_IsList) <-- [\n\tLocal(i, done);\n\tdone := False;\n\tFor(i:=0, Not done, i++)\n\t[\n\t\tWhile(i<Length(list) And list[i]=list[i+1])\n\t\t\tDestructiveDelete(list, i);\n\t\tIf(i=Length(list), done := True);\n\t];\n\tlist;\n];\n\n\n"
  },
  {
    "path": "scripts/plots.rep/code.ys.def",
    "content": "ListToHash\nsign'change\nWriteDataItem\nRemoveRepeated\n}\n"
  },
  {
    "path": "scripts/plots.rep/plot2d.ys",
    "content": "//////////////////////////////////////////////////\n/// Plot2D --- adaptive two-dimensional plotting\n//////////////////////////////////////////////////\n\n/// definitions of backends\nUse(\"plots.rep/backends-2d.ys\");\n\n/*\n\tPlot2D is an interface for various backends (Plot2D'...). It calls\nPlot2D'get'data to obtain the list of points and values, and then it calls\nPlot2D'<backend> on that data.\n\n\tAlgorithm for Plot2D'get'data: \n\t1) Split the given interval into Div(points+3, 4) subintervals, and split each subinterval into 4 parts.\n\t2) For each of the parts: evaluate function values and call Plot2D'adaptive\n\t3) concatenate resulting lists and return\n*/\n\n\tLocalSymbols(var, func, range, option, options'list, delta, options'hash, c, fc, all'values, dummy)\n[\n\n// declaration of Plot2D with variable number of arguments\nFunction() Plot2D(func);\nFunction() Plot2D(func, range);\nFunction() Plot2D(func, range, options, ...);\n\n/// interface routines\n1 # Plot2D(_func) <-- (\"Plot2D\" @ {func, -5:5});\n2 # Plot2D(_func, _range) <-- (\"Plot2D\" @ {func, range, {}});\n3 # Plot2D(_func, _range, option_IsFunction) _ (Type(option) = \"=\" Or Type(option) = \"==\") <-- (\"Plot2D\" @ {func, range, {option}});\n\n/// Plot a single function\n5 # Plot2D(_func, _range, options'list_IsList)_(Not IsList(func)) <-- (\"Plot2D\" @ {{func}, range, options'list});\n\n/// Top-level 2D plotting routine:\n/// plot several functions sharing the same xrange and other options\n4 # Plot2D(func'list_IsList, _range, options'list_IsList) <--\n[\n\tLocal(var, func, delta, options'hash, c, fc, all'values, dummy);\n\tall'values := {};\n\toptions'hash := \"ListToHash\" @ {options'list};\n\t// this will be a string - name of independent variable\n\toptions'hash[\"xname\"] := \"\";\n\t// this will be a list of strings - printed forms of functions being plotted\n\toptions'hash[\"yname\"] := {};\n\t// parse range\n\tIf (\n\t\tType(range) = \"=\" Or Type(range) = \"==\",\t// variable also specified -- ignore for now, store in options\n\t\t[\n\t\t\t// store alternative variable name\n\t\t\toptions'hash[\"xname\"] := String(range[1]);\n\t\t\trange := range[2];\n\t\t]\n\t);\n\tIf(\n\t\tType(range) = \":\",\t// simple range\n\t\trange := N(Eval({range[1], range[2]}))\n\t);\n\t// set default option values\n\tIf(\n\t\toptions'hash[\"points\"] = Empty,\n\t\toptions'hash[\"points\"] := 23\n\t);\n\tIf(\n\t\toptions'hash[\"depth\"] = Empty,\n\t\toptions'hash[\"depth\"] := 5\n\t);\n\tIf(\n\t\toptions'hash[\"precision\"] = Empty,\n\t\toptions'hash[\"precision\"] := 0.0001\n\t);\n\tIf(\n\t\toptions'hash[\"output\"] = Empty Or IsString(options'hash[\"output\"]) And Plot2D'outputs()[options'hash[\"output\"]] = Empty,\n\t\toptions'hash[\"output\"] := Plot2D'outputs()[\"default\"]\n\t);\n\t// a \"filename\" parameter is required when using data file\n\tIf(\n\t\toptions'hash[\"output\"] = \"datafile\" And options'hash[\"filename\"] = Empty,\n\t\toptions'hash[\"filename\"] := \"output.data\"\n\t);\n\t// we will divide each subinterval in 4 parts, so divide number of points by 4 now\n\toptions'hash[\"points\"] := N(Eval(Div(options'hash[\"points\"]+3, 4)));\n\t// in case it is not a simple number but an unevaluated expression\n\toptions'hash[\"precision\"] := N(Eval(options'hash[\"precision\"]));\n\t// store range in options\n\toptions'hash[\"xrange\"] := {range[1], range[2]};\n\t// compute the separation between grid points\n\tdelta := N(Eval( (range[2] - range[1]) / (options'hash[\"points\"]) ));\n\t// check that the input parameters are valid (all numbers)\n\tCheck(IsNumber(range[1]) And IsNumber(range[2]) And IsNumber(options'hash[\"points\"]) And IsNumber(options'hash[\"precision\"]),\n\t\t\"Plot2D: Error: plotting range '\"\n\t\t:(ToString()Write(range))\n\t\t:\"' and/or the number of points '\"\n\t\t:(ToString()Write(options'hash[\"points\"]))\n\t\t:\"' and/or precision '\"\n\t\t:(ToString()Write(options'hash[\"precision\"]))\n\t\t:\"' is not numeric\"\n\t);\n\t// loop over functions in the list\n\tForEach(func, func'list)\n\t[\n\t\t// obtain name of variable\n\t\tvar := VarList(func);        // variable name in a one-element list\n    \tCheck(Length(var)<=1,\n\t\t\t\"Plot2D: Error: expression is not a function of one variable: \"\n\t\t\t:(ToString()Write(func))\n\t\t);\n\t\t// Allow plotting of constant functions\n\t\tIf(Length(var)=0, var:={dummy});\n\t\t// store variable name if not already done so\n\t\tIf(\n\t\t\toptions'hash[\"xname\"] = \"\",\n\t\t\toptions'hash[\"xname\"] := String(VarList(var)[1])\n\t\t);\n\t\t// store function name in options\n\t\tDestructiveAppend(options'hash[\"yname\"], ToString()Write(func));\n\t\t// compute the first point to see if it's okay\n\t\tc := range[1];\n\t\tfc := N(Eval(Apply({var, func}, {c})));\n\t\tCheck(IsNumber(fc) Or fc=Infinity Or fc= -Infinity Or fc=Undefined,\n\t\t\t\"Plot2D: Error: cannot evaluate function '\"\n\t\t\t:(ToString()Write(func))\n\t\t\t:\"' at point '\"\n\t\t\t:(ToString()Write(c))\n\t\t\t:\"' to a number, instead got '\"\n\t\t\t:(ToString()Write(fc))\n\t\t\t:\"'\"\n\t\t);\n\t\t// compute all other data points\n\t\tDestructiveAppend(all'values, Plot2D'get'data(func, var, c, fc, delta, options'hash));\n\t\tIf(InVerboseMode(), Echo({\"Plot2D: using \", Length(all'values[Length(all'values)]), \" points for function \", func}), True);\n\t];\n\t// call the specified output backend\n\tPlot2D'outputs()[options'hash[\"output\"]] @ {all'values, options'hash};\n];\n\n//HoldArg(\"Plot2D\", range);\n//HoldArg(\"Plot2D\", options);\nHoldArgNr(\"Plot2D\", 2, 2);\nHoldArgNr(\"Plot2D\", 3, 2);\nHoldArgNr(\"Plot2D\", 3, 3);\n\n/// this is the middle-level plotting routine; it generates the initial\n/// grid, calls the adaptive routine, and gathers data points.\n/// func must be just one function (not a list)\nPlot2D'get'data(_func, _var, _x'init, _y'init, _delta'x, _options'hash) <--\n[\n\tLocal(i, a, fa, b, fb, c, fc, result);\n\t// initialize list by first points (later will always use Tail() to exclude first points of subintervals)\n\tresult := { {c,fc} := {x'init, y'init} };\n\tFor(i:=0, i<options'hash[\"points\"], i++)\n\t[\n\t\t{a,fa} := {c, fc};\t// this is to save time but here a = x'init + i*delta'x\n\t\t// build subintervals\n\t\t{b, c} := N(Eval({x'init + (i+1/2)*delta'x, x'init + (i+1)*delta'x}));\t// this is not computed using \"a\" to reduce roundoff error\n\t\t{fb, fc} := N(Eval(MapSingle({var, func}, {b, c})));\n\t\tresult := Concat(result,\n\t\t\tTail(Plot2D'adaptive(func, var, {a,b,c}, {fa, fb, fc}, options'hash[\"depth\"],\n\t\t\t\t// since we are dividing into \"points\" subintervals, we need to relax precision\n\t\t\t\toptions'hash[\"precision\"]*options'hash[\"points\"] )));\n\t];\n\tresult;\n];\n\n//////////////////////////////////////////////////\n/// Plot2D'adaptive --- core routine to collect data\n//////////////////////////////////////////////////\n/*\n\tPlot2D'adaptive returns a list of pairs of coordinates { {x1,y1}, {x2,y2},...}\n\tAll arguments except f() and var must be numbers. var is a one-element list containing the independent variable. The \"a,b,c\" and \"fa, fb, fc\" arguments are values of the function that are already computed -- we don't want to recompute them once more.\n\tSee documentation (Algorithms.chapt.txt) for the description of the algorithm.\n*/\n\nPlot2D'adaptive(_func, _var, {_a,_b,_c}, {_fa, _fb, _fc}, _depth, _epsilon) <--\n[\n\tLocal(a1, b1, fa1, fb1);\n\n\ta1 := N(Eval((a+b)/2));\n\tb1 := N(Eval((b+c)/2));\n\t{fa1, fb1} := N(Eval(MapSingle({var, func}, {a1, b1})));\n\tIf(\n\t\tdepth<=0 Or\n\t\t(\n\t\t  // condition for the values not to oscillate too rapidly\n\t\t  sign'change(fa, fa1, fb) + sign'change(fa1, fb, fb1) + sign'change(fb, fb1, fc) <= 2\n\t\t  And\n\t\t  // condition for the values not to change too rapidly\n\t\t  N(Eval(Abs( (fa-5*fa1+9*fb-7*fb1+2*fc)/24 ) ))\t// this is the Simpson quadrature for the (fb,fb1) subinterval (using points b,b1,c), subtracted from the 4-point Newton-Cotes quadrature for the (fb,fb1) subinterval (using points a, a1, b, b1)\n\t\t  \t<= N(Eval( epsilon*(\t// the expression here will be nonnegative because we subtract the minimum value\n\t\t    //(fa+fc+2*fb+4*(fa1+fb1))/12\t// this is 1/4 of the Simpson quadrature on the whole interval\n\t\t\t(5*fb+8*fb1-fc)/12\t// this is the Simpson quadrature for the (fb,f1) subinterval\n\t\t\t- Min({fa,fa1,fb,fb1,fc}) ) ) )\n\t\t),\n\t\t// okay, do not refine any more\n\t\t{{a,fa}, {a1,fa1}, {b,fb}, {b1,fb1}, {c,fc}},\n\t\t// not okay, need to refine more\n\t\tConcat(\n\t\t\t// recursive call on two halves of the interval; relax precision by factor of 2\n\t\t\tPlot2D'adaptive(func, var, {a, a1, b}, {fa, fa1, fb}, depth-1, epsilon*2),\t// Tail() omits the pair {b, fb}\n\t\t\tTail(Plot2D'adaptive(func, var, {b, b1, c}, {fb, fb1, fc}, depth-1, epsilon*2))\n\t\t)\n\t);\n];\n\n];\t// LocalSymbols()\n"
  },
  {
    "path": "scripts/plots.rep/plot2d.ys.def",
    "content": "Plot2D\nPlot2D'outputs\n}\n"
  },
  {
    "path": "scripts/plots.rep/plot3d.ys",
    "content": "//////////////////////////////////////////////////\n/// Plot3DS --- adaptive three-dimensional surface plotting\n//////////////////////////////////////////////////\n\n/// definitions of backends\nUse(\"plots.rep/backends-3d.ys\");\n\n/*\n    Plot3DS is an interface for various backends (Plot3DS'...). It calls\nPlot3DS'get'data to obtain the list of points and values, and then it calls\nPlot3DS'<backend> on that data.\n\n    Algorithm for Plot3DS'get'data:\n    1) Split the given square into Div(Sqrt(points)+1, 2) subsquares, and split each subsquare into 4 parts.\n    2) For each of the parts: evaluate function values and call Plot3DS'adaptive\n    3) concatenate resulting lists and return\n*/\n\n    LocalSymbols(var, func, xrange, yrange, option, options'list, xdelta, ydelta, options'hash, cx, cy, fc, all'values, dummy)\n[\n\n// declaration of Plot3DS with variable number of arguments\nFunction() Plot3DS(func);\nFunction() Plot3DS(func, xrange, yrange);\nFunction() Plot3DS(func, xrange, yrange, options, ...);\n\n\n/// interface routines\n1 # Plot3DS(_func) <-- (\"Plot3DS\" @ {func, -5:5, -5:5});\n2 # Plot3DS(_func, _xrange, _yrange) <-- (\"Plot3DS\" @ {func, xrange, yrange, {}});\n3 # Plot3DS(_func, _xrange, _yrange, option_IsFunction) _ (Type(option) = \"=\" Or Type(option) = \"==\") <-- (\"Plot3DS\" @ {func, xrange, yrange, {option}});\n\n/// Plot a single function\n5 # Plot3DS(_func, _xrange, _yrange, options'list_IsList)_(Not IsList(func)) <-- (\"Plot3DS\" @ {{func}, xrange, yrange, options'list});\n\n/// Top-level 3D plotting routine:\n/// plot several functions sharing the same ranges and other options\n4 # Plot3DS(func'list_IsList, _xrange, _yrange, options'list_IsList) <--\n[\n    Local(var, func, xdelta, ydelta, options'hash, cx, cy, fc, all'values, dummy);\n    // this will be a list of all computed values\n    all'values := {};\n    options'hash := \"ListToHash\" @ {options'list};\n    // this will be a string - name of independent variable\n    options'hash[\"xname\"] := \"\";\n    options'hash[\"yname\"] := \"\";\n    // this will be a list of strings - printed forms of functions being plotted\n    options'hash[\"zname\"] := {};\n    // parse range\n    If (\n        Type(xrange) = \"=\" Or Type(xrange) = \"==\",  // variable also specified -- ignore for now, store in options\n        [\n            // store alternative variable name\n            options'hash[\"xname\"] := String(xrange[1]);\n            xrange := xrange[2];\n        ]\n    );\n    If (\n        Type(yrange) = \"=\" Or Type(yrange) = \"==\",  // variable also specified -- ignore for now, store in options\n        [\n            // store alternative variable name\n            options'hash[\"yname\"] := String(yrange[1]);\n            yrange := yrange[2];\n        ]\n    );\n    If(\n        Type(xrange) = \":\", // simple range\n        xrange := N(Eval({xrange[1], xrange[2]}))\n    );\n    If(\n        Type(yrange) = \":\", // simple range\n        yrange := N(Eval({yrange[1], yrange[2]}))\n    );\n    // set default option values\n    If(\n        options'hash[\"points\"] = Empty,\n        options'hash[\"points\"] := 10    // default # of points along each axis\n    );\n    If(\n        options'hash[\"xpoints\"] = Empty,\n        options'hash[\"xpoints\"] := options'hash[\"points\"]\n    );\n    If(\n        options'hash[\"ypoints\"] = Empty,\n        options'hash[\"ypoints\"] := options'hash[\"points\"]\n    );\n\n    If(\n        options'hash[\"depth\"] = Empty,\n        options'hash[\"depth\"] := 2\n    );\n    If(\n        options'hash[\"precision\"] = Empty,\n        options'hash[\"precision\"] := 0.0001\n    );\n    If(\n        options'hash[\"hidden\"] = Empty Or Not IsBoolean(options'hash[\"hidden\"]),\n        options'hash[\"hidden\"] := True\n    );\n    If(\n        options'hash[\"output\"] = Empty Or IsString(options'hash[\"output\"]) And Plot3DS'outputs()[options'hash[\"output\"]] = Empty,\n        options'hash[\"output\"] := Plot3DS'outputs()[\"default\"]\n    );\n    // a \"filename\" parameter is required when using data file\n    If(\n        options'hash[\"output\"] = \"datafile\" And options'hash[\"filename\"] = Empty,\n        options'hash[\"filename\"] := \"output.data\"\n    );\n    options'hash[\"used depth\"] := options'hash[\"depth\"];\n    // we will divide each subsquare in 4 parts, so divide number of points by 2 now\n    options'hash[\"xpoints\"] := N(Eval(Div(options'hash[\"xpoints\"]+1, 2)));\n    options'hash[\"ypoints\"] := N(Eval(Div(options'hash[\"ypoints\"]+1, 2)));\n    // in case it is not a simple number but an unevaluated expression\n    options'hash[\"precision\"] := N(Eval(options'hash[\"precision\"]));\n    // store range in options\n    options'hash[\"xrange\"] := {xrange[1], xrange[2]};\n    options'hash[\"yrange\"] := {yrange[1], yrange[2]};\n    // compute the separation between grid points\n    xdelta := N(Eval( (xrange[2] - xrange[1]) / (options'hash[\"xpoints\"]) ) );\n    ydelta := N(Eval( (yrange[2] - yrange[1]) / (options'hash[\"ypoints\"]) ) );\n    // check that the input parameters are valid (all numbers)\n    Check(IsNumericList({xrange[1], xrange[2], options'hash[\"xpoints\"], options'hash[\"ypoints\"], options'hash[\"precision\"]}),\n        \"Plot3DS: Error: plotting ranges '\"\n        :(ToString()Write(xrange, yrange))\n        :\"' and/or the number of points '\"\n        :(ToString()Write(options'hash[\"xpoints\"], options'hash[\"ypoints\"]))\n        :\"' and/or precision '\"\n        :(ToString()Write(options'hash[\"precision\"]))\n        :\"' is not numeric\"\n    );\n\n    var := {};\n    ForEach(func, func'list)\n    [\n        Local(v);\n        // obtain name of variables\n        v := VarList(func);\n        Check(Length(v)<=2,\n            \"Plot3DS: Error: expression is not a function of at most two variables: \"\n            :(ToString()Write(func))\n        );\n        var := Union(var, v);\n    ];\n\n    Check(Length(var)<=2,\n        \"Plot3DS: Error: list of expressions depend on more than two variables: \"\n        :(ToString()Write(func'list))\n    );\n\n    // Allow plotting of constant functions\n    If(Length(var)=0, var:={dummy, dummy});\n    If(Length(var)=1, var:={var[1], dummy});\n    // store variable name if not already done so\n    If(\n        options'hash[\"xname\"] = \"\",\n        options'hash[\"xname\"] := String(var[1])\n    );\n    If(\n        options'hash[\"yname\"] = \"\",\n        options'hash[\"yname\"] := String(var[2])\n    );\n\n    ForEach(func, func'list)\n    [\n        // store function name in options\n        DestructiveAppend(options'hash[\"zname\"], ToString()Write(func));\n        // compute the first point to see if it's okay\n        cx := xrange[1]; cy := yrange[1];\n        fc := N(Eval(Apply({var, func}, {cx, cy})));\n        Check(IsNumber(fc) Or fc=Infinity Or fc= -Infinity Or fc=Undefined,\n            \"Plot3DS: Error: cannot evaluate function '\"\n            :(ToString()Write(func))\n            :\"' at point '\"\n            :(ToString()Write(cx, cy))\n            :\"' to a number, instead got '\"\n            :(ToString()Write(fc))\n            :\"'\"\n        );\n        // compute all other data points\n        DestructiveAppend(all'values, RemoveRepeated(HeapSort( Plot3DS'get'data(func, var, {cx, cy, fc}, {xdelta, ydelta}, options'hash), Hold({{x,y},x[1]<y[1] Or x[1] = y[1] And x[2] <= y[2] } ) )) );\n        If(InVerboseMode(), Echo({\"Plot3DS: using \", Length(all'values[Length(all'values)]), \" points for function \", func}), True);\n        If(InVerboseMode(), Echo({\"Plot3DS: max. used \", 2^(options'hash[\"depth\"] - options'hash[\"used depth\"]), \"subdivisions for \", func}), True);\n    ];\n    // call the specified output backend\n    Plot3DS'outputs()[options'hash[\"output\"]] @ {all'values, options'hash};\n];\n\nHoldArgNr(\"Plot3DS\", 3, 2);\nHoldArgNr(\"Plot3DS\", 3, 3);\nHoldArgNr(\"Plot3DS\", 4, 2);\nHoldArgNr(\"Plot3DS\", 4, 3);\nHoldArgNr(\"Plot3DS\", 4, 4);\n\n/// this is the middle-level plotting routine; it generates the initial\n/// grid, calls the adaptive routine, and gathers data points.\n/// func must be just one function (not a list).\n/// init'values is a list with values {x,y,f}; deltas is a list {delta'x, delta'y}.\nPlot3DS'get'data(_func, _var, _init'values, _deltas, _options'hash) <--\n[\n    Local(i, j, xa, ya, fa, xb, yb, fb, result, row'cache);\n    // compute all grid points in the 0th row in the y direction;\n    // store this array in a temporary cache;\n    // also store this in the final list (\"result\");\n    // then, go in the y direction and compute the 1th row; call the adaptive routine and add all points it gives along the way. update the row cache along the way.\n    // in cases when depth=0, the adaptive routine gives no extra points, and we must make sure that the \"result\" array contains the grid in exact order\n    row'cache := {init'values};\n    For(i:=1, i<=options'hash[\"ypoints\"], i++)\n    [\n        ya := N(Eval(init'values[2]+i*deltas[2]));\n        DestructiveAppend(row'cache, {init'values[1], ya, N(Eval(Apply({var, func}, {init'values[1], ya})))});\n    ];\n    result := row'cache;\n    // now loop over the x direction\n    For(i:=1, i<=options'hash[\"xpoints\"], i++)\n    [\n        // start the next row\n        // the 0th point\n        xa := N(Eval(init'values[1]+i*deltas[1]));\n        ya := init'values[2];\n        fa := N(Eval(Apply({var, func}, {xa, ya})));\n        DestructiveAppend(result, {xa, ya, fa});\n        // now loop at each grid point in y direction\n        For(j:=1, j<=options'hash[\"ypoints\"], j++)\n        [   // now we need to plot the data inside the following square:\n            //  p  b\n            //  r  a\n            // xa, ya, fa are the values at the point a; the points p and r are stored as row'cache[j+1] and row'cache[j]. We just need to compute the point q and update the row'cache with the value at point a, and update xa, ya, fa also with b.\n            yb := N(Eval(init'values[2] + j*deltas[2]));\n            fb := N(Eval(Apply({var, func}, {xa, yb})));\n            result := Concat(result, Plot3DS'adaptive(func, var, {row'cache[j][1], ya, xa, yb, row'cache[j][3], row'cache[j+1][3], fa, fb}, options'hash[\"depth\"],\n                // since we are dividing into \"points\" subintervals, we need to relax precision\n                options'hash[\"precision\"] * options'hash[\"xpoints\"] * options'hash[\"ypoints\"], options'hash ));\n            // update row'cache\n            row'cache[j] := {xa, ya, fa};\n            ya := yb;\n            fa := fb;\n            DestructiveAppend(result, {xa, ya, fa});\n        ];\n        row'cache[options'hash[\"ypoints\"] + 1] := {xa, ya, fa};\n    ];\n\n    result;\n];\n\n//////////////////////////////////////////////////\n/// Plot3DS'adaptive --- core routine to collect data\n//////////////////////////////////////////////////\n/*\n    Plot3DS'adaptive returns a list of triples of coordinates { {x1,y1,z1}, {x2,y2,z2},...} inside a given square. The corners of the square are not returned (they are already computed).\n    All arguments except f() and var must be numbers. var is a two-element list containing the independent variables. The \"square\" argument contains the values of the function that have been already computed -- we don't want to recompute them once more.\n    square = {x1, y1, x2, y2, f11, f12, f21, f22}\n\n    So the routine will return the list f13, f31, f33, f32, f23 and any points returned by recursive calls on subsquares.\n    See the Algo book for the description of the algorithm.\n*/\n\n10 # Plot3DS'adaptive(_func, _var, _square, 0, _epsilon, _options'hash) <-- {};\n20 # Plot3DS'adaptive(_func, _var, {_x1, _y1, _x2, _y2, _f11, _f12, _f21, _f22}, _depth, _epsilon, _options'hash) <--\n[\n    Local(x3, y3, f13, f31, f33, f32, f23, result);\n\n    // if we are here, it means we used one more recursion level\n    options'hash[\"used depth\"] := depth-1;\n    // bisection\n    x3 := N(Eval((x1+x2)/2));\n    y3 := N(Eval((y1+y2)/2));\n    // compute new values\n    // use the confusing Map semantics: the list of all x's separately from the list of all y's\n    f13 := N(Eval(Apply({var, func}, {x1, y3})));\n    f31 := N(Eval(Apply({var, func}, {x3, y1})));\n    f33 := N(Eval(Apply({var, func}, {x3, y3})));\n    f32 := N(Eval(Apply({var, func}, {x3, y2})));\n    f23 := N(Eval(Apply({var, func}, {x2, y3})));\n    result := {{x1,y3,f13}, {x3, y1, f31}, {x3, y3, f33}, {x3, y2, f32}, {x2, y3, f23}};\n/*\ny2  12  32  22\n\n    13  33  23\n\ny1  11  31  21\n\n    x1      x2\n*/\n    Local(refine);\n\n    refine := False;\n\n    If (IsInfinity(f11) Or IsInfinity(f12) Or IsInfinity(f13) Or\n        IsInfinity(f21) Or IsInfinity(f22) Or IsInfinity(f23) Or\n        IsInfinity(f31) Or IsInfinity(f32) Or IsInfinity(f33), refine := True);\n\n    // condition for the values not to oscillate too rapidly\n    If (Not refine,\n        refine :=\n            sign'change(f11,f13,f12) + sign'change(f13,f12,f32) + sign'change(f12,f32,f22) > 2 Or\n            sign'change(f22,f23,f21) + sign'change(f23,f21,f31) + sign'change(f21,f31,f11) > 2);\n\n    // condition for the values not to change too rapidly\n    If (Not refine,\n        refine :=\n            N(Eval(Abs((f11-f23)/2-(f12-f21)/3+(f22-f13)/6+2*(f32-f33)/3)))\n            >\n            N(Eval(epsilon*(\n                (f11 + f12 + f21 + f22)/12 + 2*f33/3 -\n                Min({f11, f12, f21, f22, f13, f31, f33, f32, f23}))))\n    );\n\n    If(Not refine,\n        // okay, do not refine any more\n        result,\n        // not okay, need to refine more\n        Concat(\n            // first, give the extra points,\n            result,\n            // then perform recursive calls on four quarters of the original square;\n            // relax precision by factor of 4\n            Plot3DS'adaptive(func, var, {x1, y1, x3, y3, f11, f13, f31, f33}, depth-1, epsilon*4, options'hash),\n            Plot3DS'adaptive(func, var, {x1, y3, x3, y2, f13, f12, f33, f32}, depth-1, epsilon*4, options'hash),\n            Plot3DS'adaptive(func, var, {x3, y1, x2, y3, f31, f33, f21, f23}, depth-1, epsilon*4, options'hash),\n            Plot3DS'adaptive(func, var, {x3, y3, x2, y2, f33, f32, f23, f22}, depth-1, epsilon*4, options'hash)\n        )\n    );\n];\n\n];  // LocalSymbols()\n\n"
  },
  {
    "path": "scripts/plots.rep/plot3d.ys.def",
    "content": "Plot3DS\nPlot3DS'outputs\n}\n"
  },
  {
    "path": "scripts/predicates.rep/code.ys",
    "content": "\n\n\nLocalSymbols(p,x)\n[\n// test for a scalar\nFunction(\"IsScalar\",{x}) Not(IsList(x));\n\n\n\n// test for a vector\nFunction(\"IsVector\",{x})\n   If(IsList(x),\n   Length(Select(IsList,x))=0,\n   False);\n\n// test for a vector w/ element test p\nFunction(\"IsVector\",{p,x})\n[\n   If(IsList(x),\n   [\n      Local(i,n,result);\n      n:=Length(x);\n      i:=1;\n      result:=True;\n      While(i<=n And result)\n      [\n\t result:=Apply(p,{x[i]});\n\t i++;\n      ];\n      result;\n   ],\n   False);\n];\n\n// test for a matrix (dr)\nFunction(\"IsMatrix\",{x})\nIf(IsList(x) And Length(x)>0,\n[\n   Local(n);\n   n:=Length(x);\n   If(Length(Select(IsVector,x))=n,\n   MapSingle(Length,x)=Length(x[1])+ZeroVector(n),\n   False);\n],\nFalse);\n\n// test for a matrix w/ element test p (dr)\nFunction(\"IsMatrix\",{p,x})\nIf(IsMatrix(x),\n[\n   Local(i,j,m,n,result);\n   m:=Length(x);\n   n:=Length(x[1]);\n   i:=1;\n   result:=True;\n   While(i<=m And result)\n   [\n      j:=1;\n      While(j<=n And result)\n      [\n         result:=Apply(p,{x[i][j]});\n         j++;\n      ];\n      i++;\n   ];\n   result;\n],\nFalse);\n\n/* remove? (dr)\nIsSquareMatrix(_x) <--\n[\n   Local(d);\n   d:=Dimensions(x);\n   Length(d)=2 And d[1]=d[2];\n];\n*/\n\n// test for a square matrix (dr)\nFunction(\"IsSquareMatrix\",{x}) IsMatrix(x) And Length(x)=Length(x[1]);\n// test for a square matrix w/ element test p (dr)\nFunction(\"IsSquareMatrix\",{p,x}) IsMatrix(p,x) And Length(x)=Length(x[1]);\n\n]; // LocalSymbols(p,x)\n\n/* changed definition of IsRational, Nobbi 030529\nFunction(\"IsRational\",{aLeft}) Type(aLeft) = \"/\";\n\nFunction(\"IsRationalNumeric\",{aLeft})\n    Type(aLeft) = \"/\" And\n    IsNumber(aLeft[1]) And\n    IsNumber(aLeft[2]);\n\nIsRationalOrNumber(_x) <-- (IsNumber(x) Or IsRationalNumeric(x));\n\n10 # IsRationalOrInteger(x_IsInteger) <-- True;\n10 # IsRationalOrInteger(x_IsInteger / y_IsInteger) <-- True;\n20 # IsRationalOrInteger(_x) <-- False;\n\n*/\n\n10 # IsRational(x_IsInteger) <-- True;\n10 # IsRational(x_IsInteger / y_IsInteger) <-- True;\n10 # IsRational(-(x_IsInteger / y_IsInteger)) <-- True;\n60000 # IsRational(_x) <-- False;\n\n10 # IsRationalOrNumber(x_IsNumber) <-- True;\n10 # IsRationalOrNumber(x_IsNumber / y_IsNumber) <-- True;\n10 # IsRationalOrNumber(-(x_IsNumber / y_IsNumber)) <-- True;\n60000 # IsRationalOrNumber(_x) <-- False;\n\n\nIsNegativeNumber(x):= IsNumber(x) And x < 0;\nIsNonNegativeNumber(x):= IsNumber(x) And x >= 0;\nIsPositiveNumber(x):= IsNumber(x) And x > 0;\n\nIsNegativeInteger(x):= IsInteger(x) And x < 0;\nIsNonNegativeInteger(x):= IsInteger(x) And x >= 0;\nIsPositiveInteger(x):= IsInteger(x) And x > 0;\n\n\n/*\n10 # IsZero(x_IsNumber) <-- (MathDivide( Round( MathMultiply(x, 10^Builtin'Precision'Get()) ), 10^Builtin'Precision'Get() ) = 0);\n10 # IsNotZero(x_IsNumber)       <-- ( RoundTo(x,Builtin'Precision'Get()) != 0);\n*/\n// these should be calls to MathSign() and the math library should do this. Or it should be just MathEquals(x,0).\n// for now, avoid underflow and avoid IsZero(10^(-Builtin'Precision'Get())) returning True.\n10 # IsZero(x_IsNumber) <-- ( MathSign(x) = 0 Or MathAbs(x)  < MathPower(10, -Builtin'Precision'Get()));\n60000 # IsZero(_x) <-- False;\n\n10 # IsNotZero(x_IsNumber) <-- ( MathAbs(x)  >= MathPower(10, -Builtin'Precision'Get()));\n10 # IsNotZero(x_IsInfinity) <-- True;\n60000 # IsNotZero(_x) <-- False;\n\nIsNonZeroInteger(x) := (IsInteger(x) And x != 0);\n\n// why do we need this? Why doesn't x=1 not work?\n10 # IsOne(x_IsNumber) <-- IsZero(MathSubtract(x,1));\n60000 # IsOne(_x) <-- False;\n\nIsEven(n) := IsInteger(n) And ( BitAnd(n,1)  = 0 );\nIsOdd(n)  := IsInteger(n) And ( BitAnd(n,1)  != 0 );\n\nIsEvenFunction(f,x):= (f - Eval(Subst(x,-x)f) = 0);\nIsOddFunction(f,x):= (f - Eval(-Subst(x,-x)f) = 0);\n\n\n10 # IsInfinity(Infinity) <-- True;\n10 # IsInfinity(-(_x)) <-- IsInfinity(x);\n\n// This is just one example, we probably need to extend this further to include all\n// cases for f*Infinity where f can be guaranteed to not be zero\n11 # IsInfinity(Sign(_x)*y_IsInfinity) <-- True;\n\n60000 # IsInfinity(_x) <-- False;\n\n10 # IsConstant(expr_IsAtom) <-- Not IsVariable(expr);\n\n20 # IsConstant(expr_IsFunction) <-- [\n    Local(args, a, is'const);\n\n    args := Tail(Listify(expr));\n\n    is'const := True;\n\n    While (args != {} And is'const) [\n        a := Head(args);\n        args := Tail(args);\n\n        is'const := is'const And IsConstant(a);\n    ];\n\n    is'const;\n];\n\n\nFunction (\"IsBoolean\", {x})\n\t(x=True) Or (x=False) Or IsFunction(x) And Contains({\"=\", \">\", \"<\", \">=\", \"<=\", \"!=\", \"And\", \"Not\", \"Or\"}, Type(x));\n\n0 # IsBoolType(True) <-- True;\n0 # IsBoolType(False) <-- True;\n1 # IsBoolType(_anythingelse) <-- False;\n\n/* See if a number, when evaluated, would be a positive/negative real value */\nIsPositiveReal(_r) <--\n[\n  r:=N(Eval(r));\n  (IsNumber(r) And r >= 0);\n];\nIsNegativeReal(_r) <--\n[\n  r:=N(Eval(r));\n  (IsNumber(r) And r <= 0);\n];\n\n\n/* Predicates on matrices */\nIsDiagonal(A_IsMatrix) <--\n[\n\tLocal(i,j,m,n,result);\n\tm:=Length(A);\n\tn:=Length(A[1]);\n\ti:=1;\n\tresult:=(m=n);\n\tWhile(i<=m And result)\n\t[\n\t\tj:=1;\n\t\tWhile(j<=n And result)\n\t\t[\n \t\t\tresult:= (i=j Or A[i][j] = 0);\n \t\t\tj++;\n\t\t];\n\t\ti++;\n\t];\n\tresult;\n];\nIsUpperTriangular(A_IsMatrix) <--\n[\n        Local(i,j,m,n,result);\n        m:=Length(A);\n        n:=Length(A[1]);\n        i:=2;\n        result:=(m=n);\n        While(i<=m And result)\n        [\n                j:=1;\n                While(j<=n And result)\n                [\n                        result:= (i<=j Or A[i][j] = 0);\n                        j++;\n                ];\n                i++;\n        ];\n        result;\n];\nIsLowerTriangular(A_IsMatrix) <-- (IsUpperTriangular(Transpose(A)));\nIsSkewSymmetric(A_IsMatrix) <-- (Transpose(A)=(-1*A));\nIsHermitian(A_IsMatrix) <-- (Conjugate(Transpose(A))=A);\nIsSymmetric(A_IsMatrix) <-- (Transpose(A)=A);\nIsOrthogonal(A_IsMatrix) <-- (Transpose(A)*A=Identity(Length(A)));\nIsIdempotent(A_IsMatrix) <-- (A^2 = A);\nIsUnitary(A_IsMatrix) <-- (Transpose(Conjugate(A))*A = Identity(Length(A)));\n\nIsVariable(_expr) <-- (IsAtom(expr) And Not(expr=Infinity) And Not(expr= -Infinity) And Not(expr=Undefined) And Not(IsNumber(N(Eval(expr)))));\n\n// check that all items in the list are numbers\nIsNumericList(_arg'list) <-- IsList(arg'list) And\n\t(\"And\" @ (MapSingle(Hold({{x},IsNumber(N(Eval(x)))}), arg'list)));\n\n//////////////////////////////////////////////////\n/// Predicates HasExpr*, HasFunc*, ListHasFunc\n//////////////////////////////////////////////////\n\n/// HasExpr --- test for an expression containing a subexpression\n/// for checking dependence on variables, this may be faster than using VarList or IsFreeOf and this also can be used on non-variables, e.g. strings or numbers or other atoms or even on non-atoms\n// an expression contains itself -- check early\n10 # HasExpr(_expr, _atom) _ Equals(expr, atom) <-- True;\n// an atom contains itself\n15 # HasExpr(expr_IsAtom, _atom) <-- Equals(expr, atom);\n// a list contains an atom if one element contains it\n// we test for lists now because lists are also functions\n// first take care of the empty list:\n19 # HasExpr({}, _atom) <-- False;\n20 # HasExpr(expr_IsList, _atom) <-- HasExpr(Head(expr), atom) Or HasExpr(Tail(expr), atom);\n// a function contains an atom if one of its arguments contains it\n30 # HasExpr(expr_IsFunction, _atom) <-- HasExpr(Tail(Listify(expr)), atom);\n\n/// Same except only look at function arguments for functions in a given list\nHasExprSome(_expr, _atom, _look'list) _ Equals(expr, atom) <-- True;\n// an atom contains itself\n15 # HasExprSome(expr_IsAtom, _atom, _look'list) <-- Equals(expr, atom);\n// a list contains an atom if one element contains it\n// we test for lists now because lists are also functions\n// first take care of the empty list:\n19 # HasExprSome({}, _atom, _look'list) <-- False;\n20 # HasExprSome(expr_IsList, _atom, _look'list) <-- HasExprSome(Head(expr), atom, look'list) Or HasExprSome(Tail(expr), atom, look'list);\n// a function contains an atom if one of its arguments contains it\n// first deal with functions that do not belong to the list: return False since we have already checked it at #15\n25 # HasExprSome(expr_IsFunction, _atom, _look'list)_(Not Contains(look'list, Atom(Type(expr)))) <-- False;\n// a function contains an atom if one of its arguments contains it\n30 # HasExprSome(expr_IsFunction, _atom, _look'list) <-- HasExprSome(Tail(Listify(expr)), atom, look'list);\n\n/// HasFunc --- test for an expression containing a function\n/// function name given as string.\n10 # HasFunc(_expr, string_IsString) <-- HasFunc(expr, Atom(string));\n/// function given as atom.\n// atom contains no functions\n10 # HasFunc(expr_IsAtom, atom_IsAtom) <-- False;\n// a list contains the function List so we test it together with functions\n// a function contains itself, or maybe an argument contains it\n20 # HasFunc(expr_IsFunction, atom_IsAtom) <-- Equals(Head(Listify(expr)), atom) Or ListHasFunc(Tail(Listify(expr)), atom);\n\n/// function name given as string.\n10 # HasFuncSome(_expr, string_IsString, _look'list) <-- HasFuncSome(expr, Atom(string), look'list);\n/// function given as atom.\n// atom contains no functions\n10 # HasFuncSome(expr_IsAtom, atom_IsAtom, _look'list) <-- False;\n// a list contains the function List so we test it together with functions\n// a function contains itself, or maybe an argument contains it\n\n// first deal with functions that do not belong to the list: return top level function\n15 # HasFuncSome(expr_IsFunction, atom_IsAtom, _look'list)_(Not Contains(look'list, Atom(Type(expr)))) <-- Equals(Head(Listify(expr)), atom);\n// function belongs to the list - check its arguments\n20 # HasFuncSome(expr_IsFunction, atom_IsAtom, _look'list) <-- Equals(Head(Listify(expr)), atom) Or ListHasFuncSome(Tail(Listify(expr)), atom, look'list);\n\n/// ListHasFunc --- test for one of the elements of a list to contain a function\n/// this is mainly useful to test whether a list has nested lists, i.e. ListHasFunc({1,2,3}, List)=False and ListHasFunc({1,2,{3}}, List)=True.\n// need to exclude the List atom itself, so don't use Listify\n19 # ListHasFunc({}, _atom) <-- False;\n20 # ListHasFunc(expr_IsList, atom_IsAtom) <-- HasFunc(Head(expr), atom) Or ListHasFunc(Tail(expr), atom);\n\n19 # ListHasFuncSome({}, _atom, _look'list) <-- False;\n20 # ListHasFuncSome(expr_IsList, atom_IsAtom, _look'list) <-- HasFuncSome(Head(expr), atom, look'list) Or ListHasFuncSome(Tail(expr), atom, look'list);\n\n/// Analyse arithmetic expressions\n\nHasExprArith(expr, atom) := HasExprSome(expr, atom, {Atom(\"+\"), Atom(\"-\"), *, /});\nHasFuncArith(expr, atom) := HasFuncSome(expr, atom, {Atom(\"+\"), Atom(\"-\"), *, /});\n\n\n/// TODO FIXME document this: FloatIsInt returns True if the argument is integer after removing potential trailing\n/// zeroes after the decimal point\n// but in fact this should be a call to BigNumber::IsIntValue()\nFloatIsInt(_x) <--\n   [\n     x:=N(Eval(x));\n     Local(prec,result,n);\n     Set(prec,Builtin'Precision'Get());\n     If(IsZero(x),Set(n,2),\n     If(x>0,\n       Set(n,2+MathFloor(N(FastLog(x)/FastLog(10)))),\n       Set(n,2+MathFloor(N(FastLog(-x)/FastLog(10))))\n       ));\n     Builtin'Precision'Set(n+prec);\n     Set(result,IsZero(RoundTo(x-Floor(x),prec)) Or IsZero(RoundTo(x-Ceil(x),prec)));\n     Builtin'Precision'Set(prec);\n     result;\n   ];\n//\n"
  },
  {
    "path": "scripts/predicates.rep/code.ys.def",
    "content": "IsScalar\nIsMatrix\nIsVector\nIsSquareMatrix\nIsRational\nIsRationalOrNumber\nIsPositiveNumber\nIsNegativeNumber\nIsNonNegativeNumber\nIsZero\nIsNotZero\nIsNonZeroInteger\nIsPositiveInteger\nIsNegativeInteger\nIsNonNegativeInteger\nIsEven\nIsOdd\nIsEvenFunction\nIsOddFunction\nIsInfinity\nIsConstant\nIsBoolean\nIsBoolType\nIsPositiveReal\nIsNegativeReal\nIsHermitian\nIsSymmetric\nIsSkewSymmetric\nIsIdempotent\nIsOrthogonal\nIsUnitary\nIsVariable\nIsDiagonal\nIsUpperTriangular\nIsLowerTriangular\nIsNumericList\nHasExpr\nHasFunc\nHasExprSome\nHasFuncSome\nListHasFunc\nHasExprArith\nHasFuncArith\nFloatIsInt\n}\n"
  },
  {
    "path": "scripts/probability.rep/code.ys",
    "content": "/* Evaluates distribution dst at point x\n   known distributions are:\n   1. Discrete distributions\n   -- BernoulliDistribution(p)\n   -- BinomialDistribution(p,n)\n   -- DiscreteUniformDistribution(a,b)\n   -- PoissonDistribution(l)\n   2. Continuous distributions\n   -- ExponentialDistribution(l)\n   -- NormalDistrobution(a,s)\n   -- ContinuousUniformDistribution(a,b)\n   -- tDistribution(m)\n   -- GammaDistribution(m)\n   -- ChiSquareDistribution(m)\n\n  DiscreteDistribution(domain,probabilities) represent arbitrary\n  distribution with finite number of possible values; domain list\n  contains possible values such that\n  Pr(X=domain[i])=probabilities[i].\n  TODO: Should domain contain numbers only?\n*/\n\n\n10 # PDF(BernoulliDistribution(_p),0) <-- p;\n10 # PDF(BernoulliDistribution(_p),1) <-- 1-p;\n10 # PDF(BernoulliDistribution(_p),x_IsNumber)_(x != 0 And x != 1) <-- 0;\n10 # PDF(BernoulliDistribution(_p),_x) <-- Hold(If(x=0,p,If(x=1,1-p,0)));\n\n10 # PDF(BinomialDistribution(_p,_n),_k) <-- Bin(n,k)*p^k*(1-p)^(n-k);\n\n10 # PDF(DiscreteUniformDistribution(_a,_b), x_IsNumber) <-- If(x<a Or x>b, 0 ,1/(b-a+1));\n11 # PDF(DiscreteUniformDistribution(_a,_b), _x) <-- Hold(If(x<a Or x>b, 0 ,1/(b-a+1)));\n\n10 # PDF( PoissonDistribution(_l), n_IsNumber) <-- If(n<0,0,Exp(-l)*l^n/n!);\n11 # PDF(PoissonDistribution(_l),_n) <-- Exp(-l)*l^n/n!;\n\n10 # PDF(GeometricDistribution(_p),_n) <--If(n<0,0,p*(1-p)^n);\n\n10 # PDF(ExponentialDistribution(_l), _x) <-- If(x<0,0,l*Exp(-l*x));\n\n10 # PDF(NormalDistribution(_a,_s),_x) <-- Exp(-(x-a)^2/(2*s))/Sqrt(2*Pi*s);\n\n10 # PDF(ContinuousUniformDistribution(_a,_b),x)_(a<b) <-- If(x<a Or x>b,0,1/(b-a));\n\n10 # PDF( DiscreteDistribution( dom_IsList, prob_IsList), _x)_( Length(dom)=Length(prob) And Simplify(Add(prob))=1) <--\n    [\n      Local(i);\n      i:=Find(dom,x);\n      If(i = -1,0,prob[i]);\n    ];\n10 # PDF( ChiSquareDistribution( _m),x_IsRationalOrNumber)_(x<=0) <-- 0;\n20 # PDF( ChiSquareDistribution( _m),_x) <-- x^(m/2-1)*Exp(-x/2)/2^(m/2)/Gamma(m/2);\n\n10 # PDF(tDistribution(_m),x) <-- Gamma((m+1)/2)*(1+x^2/m)^(-(m+1)/2)/Gamma(m/2)/Sqrt(Pi*m);\n\n/* Evaluates Cumulative probability function CDF(x)=Pr(X<x) */\n\n10 # CDF(BernoulliDistribution(_p), x_IsNumber) <-- If(x<=0,0,If(x>0 And x<=1, p,1));\n11 # CDF(BernoulliDistribution(_p), _x) <-- Hold(If(x<=0,0,If(x>0 And x<=1, p,1)));\n\n10 # CDF(BinomialDistribution(_p,_n),m_IsNumber)_(m<=0) <-- 0;\n10 # CDF(BinomialDistribution(_p,n_IsInteger),m_IsNumber)_(m>n) <-- 1;\n10 # CDF(BinomialDistribution(_p,_n),_m) <-- [\n    Local(i);\n    Sum @ { i, 0, m-1, PDF(BinomialDistribution(p,n),i)};\n];\n\n10 # CDF(DiscreteUniformDistribution( a_IsNumber, b_IsNumber), x_IsNumber)_(x<=a) <-- 0;\n10 # CDF(DiscreteUniformDistribution( a_IsNumber, b_IsNumber), x_IsNumber)_(x>b) <-- 1;\n10 # CDF(DiscreteUniformDistribution( a_IsNumber, b_IsNumber), x_IsNumber)_(a<x And x<=b) <-- (x-a)/(b-a+1);\n11 # CDF(DiscreteUniformDistribution( _a, _b), _x) <--Hold(If(x<=a,0,If(x<=b,(x-a)/(b-a),1)));\n\n10 # CDF(PoissonDistribution(_l), x_IsNumber)_(x<=0) <-- 0;\n10 # CDF(PoissonDistribution(_l), _x) <-- [\n    Local(i);\n    Sum @ {i,0,x-1,PDF(PoissonDistribution(l),i)};\n];\n\n10 # CDF( ChiSquareDistribution(_m), _x) <-- IncompleteGamma(x/2,m/2)/Gamma(x/2);\n10 # CDF( DiscreteDistribution( dom_IsList, prob_IsList), _x)   <--\n      [\n         Local(i,cdf,y);\n\n         i := 1;\n         cdf:=0;\n         y:=dom[i];\n         While(y<x) [cdf:=cdf+prob[i];i++;];\n         cdf;\n      ];\n\n10 # Expectation(BernoulliDistribution(_p)) <-- 1-p;\n\n10 # Expectation(BinomialDistribution(_p,_n)) <-- n*p;\n\n10 # Expectation( DiscreteDistribution( dom_IsList, prob_IsList))_( Length(dom)=Length(prob) And Simplify(Sum(prob))=1) <-- [\n    Local(i);\n    Sum @ {i,1,Length(dom),dom[i]*prob[i]};\n];\n\n"
  },
  {
    "path": "scripts/probability.rep/code.ys.def",
    "content": "PDF\nCDF\nExpectation\n}\n"
  },
  {
    "path": "scripts/products.rep/code.ys",
    "content": "Function() Multiply(val, ...);\n\n10 # Multiply({}) <-- 1;\n20 # Multiply(values_IsList) <--\n[\n   Local(i, prod);\n   prod:=1;\n   ForEach(i, values) [ prod := prod * i; ];\n   prod;\n];\n\n30 # Multiply(_value) <-- value;\n\nRuleBase(\"Product\",{pvar'arg,pfrom'arg,pto'arg,pbody'arg});\n\n5  # Product(_pvar,pfrom_IsNumber,pto_IsNumber,_pbody)_(pfrom>pto) <-- 1;\n\n10 # Product(_pvar,pfrom_IsNumber,pto_IsNumber,_pbody)_(pto<pfrom) <--\n     ApplyPure(\"Product\",{pvar,pto,pfrom,pbody});\n\n20 # Product(_pvar,pfrom_IsNumber,pto_IsNumber,_pbody) <--\nLocalSymbols(pi,pp)[\n    Local(pi,pp);\n    pp:=1;\n    For(pi:=pfrom,pi<=pto,pi++) [\n        MacroLocal(pvar);\n        MacroSet(pvar,pi);\n        pp:=pp*Eval(pbody);\n    ];\n    pp;\n];\n\n\nLocalSymbols(c,d,expr,from,to,factor,product,predicate,k,n,r,var,x) [\n\n    Function() ProductFunc(k,from,to,factor, product, predicate );\n    Function() ProductFunc(k,from,to,factor, product);\n    HoldArg(ProductFunc,predicate);\n    HoldArg(ProductFunc,product);\n    HoldArg(ProductFunc,factor);\n\n    ProductFunc(_productvar,productfrom_IsInteger,_productto,_productbody,_product) <--\n    [\n        // Take the given answer and create 2 rules, one for an exact match\n        // for productfrom, and one which will catch sums starting at a different\n        // index and subtract off the difference\n\n        `(40 # Product(@productvar,@productfrom,@productto,@productbody )   <-- Eval(@product) );\n        `(41 # Product(@productvar,p_IsInteger,@productto,@productbody)_(p > @productfrom) <-- [\n            Local(denom);\n            (denom := Eval(UnList({Product,productvar'arg,@productfrom,p-1,productbody'arg})));\n            Simplify(Eval(@product) / denom);\n        ]);\n    ];\n\n    ProductFunc(_productvar,productfrom_IsInteger,_productto,_productbody,_product,_condition) <--\n    [\n\n        `(40 # Product(@productvar,@productfrom,@productto,@productbody)_(@condition)    <-- Eval(@product) );\n        `(41 # Product(@productvar,p_IsInteger,@productto,@productbody )_(@condition And p > @productfrom)\n            <-- [\n                Local(denom);\n                `(denom := Eval(UnList({Product,productvar'arg,@productfrom,p-1,productbody'arg})));\n                Simplify(Eval(@product) / denom);\n            ]);\n    ];\n\n    // Some type of canonical form is needed so that these match when\n    // given in a different order\n    ProductFunc(_k,1,_n,_c*_d,\n        Eval(UnList({Product,productvar'arg,1,n,c})) *\n        Eval(UnList({Product,productvar'arg,1,n,d}))\n    );\n    ProductFunc(_k,1,_n,_c*_expr,Eval(c^n*UnList({Product,productvar'arg,1,n,expr})), IsFreeOf(k,c) );\n    ProductFunc(_k,1,_n,_expr/_c,Eval(UnList({Product,productvar'arg,1,n,expr})/c^n), IsFreeOf(k,c) );\n\n    ProductFunc(_k,1,Infinity,0,0);\n    ProductFunc(_k,1,Infinity,1,1);\n    ProductFunc(_k,1,Infinity,1/_k,0);\n    ProductFunc(_k,1,Infinity,_k,Infinity);\n\n    ProductFunc(_k,1,_n,_c,(c)^n,IsFreeOf(k,c));\n    ProductFunc(_k,1,_n,_k, n!);\n];\n"
  },
  {
    "path": "scripts/products.rep/code.ys.def",
    "content": "Multiply\nProduct\n}\n\n"
  },
  {
    "path": "scripts/pslq.rep/code.ys",
    "content": "\n\n/*********************************************************************************************#\n#                       The PSLQ Integer Relation Algorithm                                   #\n#                                                                                             #\n# Aut.: Helaman R.P. Ferguson and David Bailey \"A Polynomial Time, Numerically Stable         #\n#       Integer Relation Algorithm\" (RNR Technical Report RNR-92-032)    helaman@super.org    #\n# Ref.: David Bailey and Simon Plouffe \"Recognizing Numerical Constants\" dbailey@nas.nasa.gov #\n# Cod.: Raymond Manzoni  raymman@club-internet.fr                                             #\n#*********************************************************************************************#\n# Creation:97/11                    #\n# New termination criteria:97/12/15 #\n# this code is free...              #\n\nPorted to Yacas 2000 Ayal Pinkus.\n\nGiven a list of constants x find coefficients sol[i] such that\n      sum(sol[i]*x[i], i=1..n) = 0    (where n=Length(x))              \n                                                                  \n    x is the list of real expressions           \n          N(x[i]) must evaluate to floating point numbers!\n    precision is the number of digits needed for completion;         \n          must be greater or equal to log10(max(sol[i]))*n               \n    returns the list of solutions with initial precision\n          and the confidence (the lower the better)\n\n    Example:\n\n    In> Pslq({2*Pi-4*Exp(1),Pi,Exp(1)},20)\n    Out> {1,-2,4};\n\n*/\n\nPslq(x, precision) :=\n[\n  Local (ndigits, gam, A, B, H, n, i, j, k, s, y, tmp, t, m, maxi, gami,\n\t t0, t1, t2, t3, t4, mini, Confidence, norme,result);\n  n:=Length(x);\n  ndigits:=Builtin'Precision'Get();\n  Builtin'Precision'Set(precision+10); // 10 is chosen arbitrarily, but should always be enough. Perhaps we can optimize by lowering this number\n  Confidence:=10^(-MathFloor(N(Eval(precision/3))));\n//Echo(\"Confidence is \",Confidence);\n\n  gam:=N(Sqrt(4/3));\n  For (i:=1, i<=n,i++) x[i]:=N(Eval(x[i]));\n\n//Echo(\"1...\");\n\n  A:=Identity(n); /*A and B are of Integer type*/\n  B:=Identity(n); /*but this doesn't speed up*/\n  s:=ZeroVector(n);\n  y:=ZeroVector(n);\n\n//Echo(\"2...\");\n\n  For(k:=1,k<=n,k++)\n  [\n    tmp:=0;\n    For (j:=k,j<=n,j++) tmp:=tmp + N(x[j]^2);\n//tmp:=MathDivide(tmp,1.0);\n//Echo(\"tmp is \",tmp);\n//MathDebugInfo(tmp);\n/*If(Not IsPositiveNumber(tmp),\n  Echo(\"******** not a positive number: \",tmp)\n);\nIf(Not IsNumber(tmp),\n  Echo(\"******** not a number: \",tmp)\n);\nIf(LessThan(tmp,0),\n[\n  Echo(\"******** not positive: \",tmp);\n]\n);*/\n\n    s[k]:=MathSqrt(tmp);\n\n\n/*If(Not IsNumber(tmp),\n[\nEcho(\"************** tmp = \",tmp);\n]);\nIf(Not IsNumber(s[k]),\n[\nEcho(\"************** s[k] = \",s[k]);\n]);*/\n\n  ];\n\n//Echo(\"3...\");\n\n  tmp:=N(Eval(s[1]));\n/*If(Not IsNumber(tmp),\n[\nEcho(\"************** tmp = \",tmp);\n]);*/\n\n  For (k:= 1,k<= n,k++)\n  [\n    y[k]:=N(Eval(x[k]/tmp));\n    s[k]:=N(Eval(s[k]/tmp));\n\n//Echo(\"1...\",\" \",y[k],\" \",s[k]);\n/*If(Not IsNumber(y[k]),\n[\nEcho(\"************** y[k] = \",y[k]);\n]);\nIf(Not IsNumber(s[k]),\n[\nEcho(\"************** s[k] = \",s[k]);\n]);*/\n\n  ];\n  H:=ZeroMatrix(n, n-1);\n\n//Echo(\"4...\",n);\n  For (i:=1,i<= n,i++)\n  [\n\n    if (i <= n-1)  [ H[i][i]:=N(s[i + 1]/s[i]); ];\n\n//Echo(\"4.1...\");\n    For (j:= 1,j<=i-1,j++)\n    [\n//Echo(\"4.2...\");\n      H[i][j]:= N(-(y[i]*y[j])/(s[j]*s[j + 1]));\n//Echo(\"4.3...\");\n\n/*If(Not IsNumber(H[i][j]),\n[\nEcho(\"************** H[i][j] = \",H[i][j]);\n]\n);*/\n\n    ];\n  ];\n\n//Echo(\"5...\");\n\n  For (i:=2,i<=n,i++)\n  [\n    For (j:=i-1,j>= 1,j--)\n    [\n//Echo(\"5.1...\");\n      t:=Round(H[i][j]/H[j][j]);\n//Echo(\"5.2...\");\n      y[j]:=y[j] + t*y[i];\n//Echo(\"2...\",\" \",y[j]);\n      For (k:=1,k<=j,k++) [ H[i][k]:=H[i][k]-t*H[j][k]; ];\n      For (k:=1,k<=n,k++)\n      [\n        A[i][k]:=A[i][k]-t*A[j][k];\n        B[k][j]:=B[k][j] + t*B[k][i];\n      ];\n    ];\n  ];\n  Local(found);\n  found:=False;\n\n//Echo(\"Enter loop\");\n\n  While (Not(found))\n  [\n    m:=1;\n//Echo(\"maxi 1...\",maxi);\n    maxi:=N(gam*Abs(H[1][1]));\n//Echo(\"maxi 2...\",maxi);\n    gami:=gam;\n//Echo(\"3...\");\n    For (i:= 2,i<= n-1,i++)\n    [\n      gami:=gami*gam;\n      tmp:=N(gami*Abs(H[i][i]));\n      if (maxi < tmp)\n      [\n        maxi:=tmp;\n//Echo(\"maxi 3...\",maxi);\n        m:=i;\n      ];\n    ];\n//Echo(\"4...\",maxi);\n    tmp:=y[m + 1];\n    y[m + 1]:=y[m];\n    y[m]:=tmp;\n//Echo(\"3...\",\" \",y[m]);\n//Echo(\"5...\");\n    For (i:= 1,i<=n,i++)\n    [\n      tmp:=A[m + 1][ i];\n      A[m + 1][ i]:=A[m][ i];\n      A[m][ i]:=tmp;\n      tmp:=B[i][ m + 1];\n      B[i][ m + 1]:=B[i][ m];\n      B[i][ m]:=tmp;\n    ];\n    For (i:=1,i<=n-1,i++)\n    [\n      tmp:=H[m + 1][ i];\n\n      H[m + 1][ i]:=H[m][ i];\n      H[m][ i]:=tmp;\n    ];\n//Echo(\"7...\");\n    if (m < n-1)\n    [\n      t0:=N(Eval(Sqrt(H[m][ m]^2 + H[m][ m + 1]^2)));\n\n      t1:=H[m][ m]/t0;\n      t2:=H[m][ m + 1]/t0;\n\n//      If(IsZero(t0),t0:=N(Confidence));\n//Echo(\"\");\n//Echo(\"H[m][ m] = \",N(H[m][ m]));\n//Echo(\"H[m][ m+1] = \",N(H[m][ m+1]));\n\n//If(IsZero(t0),[t1:=Infinity;t2:=Infinity;]);\n//Echo(\"t0=\",N(t0));\n//Echo(\"t1=\",N(t1));\n//Echo(\"t2=\",N(t2));\n\n      For (i:=m,i<=n,i++)\n      [\n        t3:=H[i][ m];\n        t4:=H[i][ m + 1];\n//Echo(\"    t1 = \",t1);\n//Echo(\"    t2 = \",t2);\n//Echo(\"    t3 = \",t3);\n//Echo(\"    t4 = \",t4);\n        H[i][ m]:=t1*t3 + t2*t4;\n//Echo(\"7.1... \",H[i][ m]);\n        H[i][ m + 1]:= -t2*t3 + t1*t4;\n//Echo(\"7.2... \",H[i][ m+1]);\n      ];\n    ];\n//Echo(\"8...\");\n    For (i:= 1,i<= n,i++)\n    [\n      For (j := Min(i-1, m + 1),j>= 1,j--)\n      [\n        t:=Round(H[i][ j]/H[j][ j]);\n//Echo(\"MATRIX\",H[i][ j],\" \",H[j][ j]);\n//Echo(\"5... before\",\" \",y[j],\" \",t,\" \",y[i]);\n        y[j]:=y[j] + t*y[i];\n//Echo(\"5... after\",\" \",y[j]);\n        For (k:=1,k<=j,k++) H[i][ k]:=H[i][ k]-t*H[j][ k];\n        For (k:= 1,k<=n,k++)\n        [\n          A[i][ k]:=A[i][ k]-t*A[j][ k];\n          B[k][ j]:=B[k][ j] + t*B[k][ i];\n        ];\n      ];\n    ];\n//Echo(\"9...\",N(H[1],10));\n\n    /* Builtin'Precision'Set(10);*/ /*low precision*/\n//    maxi := N(H[1] .  H[1],10);\n    maxi := N(H[1] .  H[1]);\n//Echo(\"H[1] = \",H[1]);\n//Echo(\"N(H[1]) = \",N(H[1]));\n//Echo(\"N(H[1] . H[1]) = \",N(H[1] . H[1]));\n//Echo(\"maxi 4...\",maxi);\n\n//Echo(\"9... maxi = \",maxi);\n\n    For (j:=2,j<=n,j++)\n    [\n//Echo(\"9.1...\");\n      tmp:=N(H[j] . H[j],10);\n//Echo(\"9.2...\");\n      if (maxi < tmp) [ maxi:=tmp; ];\n//Echo(\"maxi 5...\",maxi);\n//Echo(\"9.3...\");\n    ];\n//Echo(\"10...\");\n    norme:=N(Eval(1/Sqrt(maxi)));\n    m:=1;\n    mini:=N(Eval(Abs(y[1])));\n//Echo(\"y[1] = \",y[1],\" mini = \",mini);\n    maxi:=mini;\n\n//Echo(\"maxi 6...\",maxi);\n//Echo(\"11...\");\n    For (j:=2,j<=n,j++)\n    [\n      tmp:=N(Eval(Abs(y[j])));\n      if (tmp < mini)\n      [\n        mini:=tmp;\n        m:=j;\n      ];\n      if (tmp > maxi) [ maxi:=tmp; ];\n//Echo(\"maxi 7...\",maxi);\n    ];\n    /* following line may be commented */\n//Echo({\"Norm bound:\",norme,\" Min=\",mini,\" Conf=\",mini/maxi,\" required \",Confidence}); \n    if ((mini/maxi) < Confidence) /*prefered to : if mini < 10^(- precision) then*/\n    [\n    /* following line may be commented */\n/*      Echo({\"Found with Confidence \",mini/maxi}); */\n      Builtin'Precision'Set(ndigits);\n      result:=Transpose(B)[m];\n      found:=True;\n    ]\n    else\n    [\n      maxi:=Abs(A[1][ 1]);\n      For (i:=1,i<=n,i++)\n      [\n//Echo(\"i = \",i,\" n = \",n);\n        For (j:=1,j<=n,j++)\n        [\n//Echo(\"j = \",j,\" n = \",n);\n          tmp:=Abs(A[i][ j]);\n          if (maxi < tmp) [ maxi:=tmp;];\n        ];\n      ];\n//Echo(\"maxi = \",maxi);\n      if (maxi > 10^(precision))\n      [\n        Builtin'Precision'Set(ndigits);\n        result:=Fail;\n        found:=True;\n      ];\n      Builtin'Precision'Set(precision+2);\n//Echo(\"CLOSE\");\n    ];\n  ];\n  result;\n];\n\n/* end of file */\n\n\n\n\n"
  },
  {
    "path": "scripts/pslq.rep/code.ys.def",
    "content": "Pslq\n}\n\n"
  },
  {
    "path": "scripts/r_form.rep/code.ys",
    "content": "/*\n * Copyright (C) 2016 Grzegorz Mazur.\n *\n * Yacas is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * Yacas is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n * MA 02110-1301  USA\n */\n\n/* RForm: convert yacas objects to R code. */\n/* Derived from CForm */\n\nRuleBase(\"RForm\",{expression});\nRuleBase(\"RForm\",{expression, precedence});\n\n// auxilliary functions\nFunction (\"RFormBracketIf\", {predicate, string})\n[\n\tCheck(IsBoolean(predicate) And IsString(string), \"RForm internal error: non-boolean and/or non-string argument of RFormBracketIf\");\n\tIf(predicate, ConcatStrings(\"( \", string, \") \"), string);\n];\n\nRFormArgs(list_IsList) <--\n[\n  Local(i,nr,result);\n  result:=\"\";\n  nr:=Length(list);\n  For (i:=1,i<=nr,i++)\n  [\n    result:=result:RForm(list[i]);\n    If (i<nr, result:=result:\", \");\n  ];\n  result;\n];\n\nLocalSymbols(rindent) [\n  rindent:=1;\n\n  NlIndented():=\n  [\n    Local(result);\n    result:=\n\"\n\";\n    Local(i);\n    For(i:=1,i<rindent,i++)\n    [\n      result:=result:\"  \";\n    ];\n    result;\n  ];\n  RIndent() :=\n  [\n  (rindent++);\n  \"\";\n  ];\n  RUndent() :=\n  [\n  (rindent--);\n  \"\";\n  ];\n];\n\nRFormStatement(_x) <-- RForm(x) : \";\" : NlIndented();\n\n// RFormMaxPrec should perhaps only be used from within this file, it is thus not in the .def file.\nRFormMaxPrec() := 60000;\t /* This precedence will never be bracketed. It is equal to KMaxPrec */\n\n100 # RForm(_x) <-- RForm(x, RFormMaxPrec());\n\n// Strings must be quoted but not bracketed\n100 # RForm(x_IsString, _p) <-- ConcatStrings(\"\\\"\", x, \"\\\"\");\n\n// Numbers\n110 # RForm(x_IsNumber, _p) <-- String(x);\n\n// Complex numbers\n110 # RForm(Complex(_x, _y), _p) <-- ConcatStrings(\"complex(\", RFormArgs({1, x, y}), \")\");\n\n// Lists\n110 # RForm(l_IsList, _p)_ListHasFunc(l, List) <-- ConcatStrings(\"rbind(\", RFormArgs(l), \")\");\n111 # RForm(l_IsList, _p) <-- ConcatStrings(\"c(\", RFormArgs(l), \")\");\n\n// Constants\n115 # RForm(False, _p) <-- \"FALSE\";\n115 # RForm(True, _p) <-- \"TRUE\";\n115 # RForm(Pi, _p) <-- \"pi\";\n115 # RForm(Infinity, _p) <-- \"Inf\";\n// this one is a bit shady, but hopefully presence of a NaN in numerical results will draw\n// enough attention to what is actually wrong with the calculations\n115 # RForm(Undefined, _p) <-- \"NaN\";\n\n// Variables\n120 # RForm(x_IsAtom, _p) <-- String(x);\n\n\n/* Replace operations */\n\n// unary operators\n100 # RForm(+ _y, _p) <-- RFormBracketIf(p<OpPrecedence(\"+\"), ConcatStrings(\" + \", RForm(y, OpRightPrecedence(\"+\")) ) );\n100 # RForm(- _y, _p) <-- RFormBracketIf(p<OpPrecedence(\"-\"), ConcatStrings(\" - \", RForm(y, OpRightPrecedence(\"-\")) ) );\n\n\n// regular arithmetic operations\n\nLocalSymbols(rformRegularOps) [\n  rformRegularOps := { {\"+\",\" + \"}, {\"-\",\" - \"}, {\"*\",\" * \"},\n                       {\"/\",\" / \"}, {\":=\",\" <- \"}, {\"==\",\" == \"},\n                       {\"=\",\" == \"}, {\"!=\",\" != \"}, {\"<=\",\" <= \"},\n                       {\">=\",\" >= \"}, {\"<\",\" < \"}, {\">\",\" > \"},\n                       {\"And\",\" & \"}, {\"Or\",\" | \"},\n                       { \"%\", \" %% \" }, { \"^\", \" ^ \" }, { \"..\", \":\" }\n                     };\n\n  RFormRegularOps() := rformRegularOps;\n];\n\n120 # RForm(expr_IsFunction, _p)_(NrArgs(expr)=2 And Contains(AssocIndices(RFormRegularOps()), Type(expr)) ) <--\n      RFormBracketIf(p<OpPrecedence(Type(expr)), ConcatStrings(RForm(Listify(expr)[2], OpLeftPrecedence(Type(expr))), RFormRegularOps()[Type(expr)], RForm(Listify(expr)[3], OpRightPrecedence(Type(expr))) ) );\n\n\n// bitwise operations\n\nLocalSymbols(rformBitwiserOps) [\n  rformBitwiseOps := {\n      {\">>\", \"bitwShiftR\"},\n      {\"<<\", \"bitwShiftL\" },\n      {\"&\", \"bitAnd\" },\n      {\"|\", \"bitOr\" }\n  };\n\n  RFormBitwiseOps() := rformBitwiseOps;\n];\n\n120 # RForm(expr_IsFunction, _p)_(NrArgs(expr)=2 And Contains(AssocIndices(RFormBitwiseOps()), Type(expr)) ) <--\n      ConcatStrings(RFormBitwiseOps()[Type(expr)], \"(\", RForm( Listify(expr)[2], RFormMaxPrec()), \", \", RForm( Listify(expr)[3], RFormMaxPrec()), \")\" );\n\n// standard math functions\nLocalSymbols(rformMathFunctions) [\n  rformMathFunctions :=\n    {\n      {\"Sqrt\",\"sqrt\"},\n      {\"Cos\",\"cos\"},\n      {\"Sin\",\"sin\"},\n      {\"Tan\",\"tan\"},\n      {\"Cosh\",\"cosh\"},\n      {\"Sinh\",\"sinh\"},\n      {\"Tanh\",\"tanh\"},\n      {\"Exp\",\"exp\"},\n      {\"Ln\",\"log\"},\n      {\"ArcCos\",\"acos\"},\n      {\"ArcSin\",\"asin\"},\n      {\"ArcTan\",\"atan\"},\n      {\"ArcCosh\",\"acosh\"},\n      {\"ArcSinh\",\"asinh\"},\n      {\"ArcTanh\",\"atanh\"},\n      {\"Max\",\"max\"},\n      {\"Min\",\"min\"},\n      {\"Abs\",\"abs\"},\n      {\"Floor\",\"floor\"},\n      {\"Ceil\",\"ceiling\"},\n      {\"!\",\"factorial\"}\n    };\n\n  RFormMathFunctions() := rformMathFunctions;\n\n];\n\n120 # RForm(expr_IsFunction, _p) _\n      (NrArgs(expr)=1 And Contains(AssocIndices(RFormMathFunctions()), Type(expr)) ) <--\n      ConcatStrings(RFormMathFunctions()[Type(expr)], \"(\", RForm( Listify(expr)[2], RFormMaxPrec()),\")\" );\n\n// Special cases\n120 # RForm(Mod(_x, _y), _p) <-- RFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(RForm(x, OpPrecedence(\"/\")), \" %% \", RForm(y, OpPrecedence(\"/\")) ) );\n120 # RForm(Nth(_x, _i), _p) <-- ConcatStrings(RForm(x, RFormMaxPrec()), \"[\", RForm(i, RFormMaxPrec()), \"]\");\n120 # RForm(expr_IsFunction, _p)_(Type(expr) = \"Echo\") <-- ConcatStrings(\"print(\", RFormArgs(Tail(Listify(expr))), \")\");\n\n120 # RForm(if(_pred)_body, _p) <-- \"if (\":RForm(pred,60000):\") \":RForm(body);\n120 # RForm(_left else _right, _p) <-- RForm(left):\" else \":RForm(right);\n\n120 # RForm(_x,_p)_(Type(x) = \"Prog\") <--\n[\n  Local(result);\n  result:=RIndent():\"{\":NlIndented();\n  ForEach(item,Tail(Listify(x)))\n  [\n    result:=result:RFormStatement(item);\n  ];\n  result:=result:\"}\":RUndent():NlIndented();\n  result;\n];\n\n120 # RForm(If(_pred,_then), _p) <--\n\t\"if(\" : RForm(pred,RFormMaxPrec()) : \")\"\n\t: RIndent() : NlIndented()\n\t: RFormStatement(then)\n        : RUndent();\n\n120 # RForm(If(_pred,_then,_else), _p) <--\n\t\"if(\" : RForm(pred,RFormMaxPrec()) : \") {\"\n\t: RIndent() : NlIndented()\n\t: RFormStatement(then)\n        : RUndent() : \" } else { \"\n\t: RIndent() : NlIndented()\n\t: RFormStatement(else)\n        : RUndent() : \" }\";\n\n120 # RForm(For(_from,_to,_step)_body,_p) <--\n  \"for(\" : RForm(from,RFormMaxPrec()) : \";\"\n\t: RForm(to,RFormMaxPrec()) : \";\"\n\t: RForm(step,RFormMaxPrec()) : \")\"\n\t: RIndent() : NlIndented()\n\t: RFormStatement(body) : RUndent();\n\n120 # RForm(ForEach(_element,_list)_body,_p) <--\n  \"for(\" : RForm(element,RFormMaxPrec()) : \" in \"\n\t: RForm(list,RFormMaxPrec()) : \")\"\n\t: RIndent() : NlIndented()\n\t: RFormStatement(body) : RUndent();\n\n120 # RForm(While(_pred)_body, _p) <--\n\t\"while(\" : RForm(pred,RFormMaxPrec()) : \")\"\n\t: RIndent() : NlIndented()\n\t: RFormStatement(body) : RUndent();\n\n120 # RForm(Until(_pred)_body, _p) <--\n\t\"repeat {\"\n\t: RIndent() : NlIndented()\n\t: RFormStatement(body)\n        : \"if(\" : RForm(pred, RFormMaxPrec()) : \") break; \"\n        : RUndent() : \"}\";\n\n// Other functions\n200 # RForm(_x, _p)_(IsFunction(x)) <--\n[\n  ConcatStrings(Type(x), \"(\", RFormArgs(Tail(Listify(x))),\")\" );\n];\n\n//////////////////////////////////////////////////\n/// IsRFormable\n//////////////////////////////////////////////////\n\nLocalSymbols(RFormAllFunctions) [\n\n  /// predicate to test whether an expression can be successfully exported to C code\n\n  /// interface with empty extra function list\n  // need the backquote stuff b/c we have HoldArg now\n  IsRFormable(_expr) <-- `IsRFormable(@expr, {});\n\n  // need to check that expr contains only allowed functions\n  IsRFormable(_expr, funclist_IsList) <--\n  [\n    Local(bad'functions);\n    bad'functions := Difference(`FuncList(@expr), Concat(RFormAllFunctions, funclist));\n    If(Length(bad'functions)=0,\n      True,\n      [\n        If(InVerboseMode(),\n          Echo(Concat({\"IsRFormable: Info: unexportable function(s): \"}, bad'functions))\n        );\n        False;\n      ]\n    );\n  ];\n  HoldArgNr(\"IsRFormable\", 1, 1);\n  HoldArgNr(\"IsRFormable\", 2, 1);\n\n  /// This is a list of all function atoms which RForm can safely handle\n  RFormAllFunctions :=\n    MapSingle(Atom,\n        Concat(AssocIndices(RFormMathFunctions()),\n        AssocIndices(RFormRegularOps()),\n        AssocIndices(RFormBitwiseOps()),\n        // list of other functions supported by RForm: needs to be updated when RForm is extended to handle new functions\n        {\n          \"Complex\",\n          \"List\",\n          \"Mod\",\n          \"Nth\",\n          \"Echo\",\n          \"Prog\",\n          \"if\",\n          \"else\",\n          \"If\",\n          \"For\",\n          \"ForEach\",\n          \"While\",\n          \"Until\",\n        })\n    );\n];\n"
  },
  {
    "path": "scripts/r_form.rep/code.ys.def",
    "content": "RForm\nIsRFormable\n}\n\n"
  },
  {
    "path": "scripts/rabinmiller.rep/code.ys",
    "content": "/*\n * File `rabinmiller.ys' is an implementation of the\n *           Rabin-Miller primality test.\n */\n\n\n/*\n * FastModularPower(a, b, n) computes a^b (mod n) efficiently.\n * This function is called by IsStronglyProbablyPrime. \n */\n\nFastModularPower(a_IsPositiveInteger, b_IsPositiveInteger, n_IsPositiveInteger) <-- \n[\n  Local(p, j, r);\n  p := a;\n  j := b;\n  r := 1;\n\n  While (j > 0)\n    [\n      If (IsOdd(j), r := MathMod(r*p, n));\n      p := MathMod(p*p, n);\n      j := ShiftRight(j, 1);\n    ];\n  r;\n];\n\n\n/*\n * An integer n is `strongly-probably-prime' for base b if\n *\n *                   b^q = 1 (mod n) or\n * b^(q*2^i) = -1 (mod n) for some i such that 0 <= i < r\n *\n *    where q and r are such that n-1 = q*2^r and q is odd.\n *\n * If an integer is not strongly-probably-prime for a given\n * base b, then it is composed. The reciprocal is false.\n * Composed strongly-probably-prime numbers for base b\n * are called `strong pseudoprimes' for base b.\n */\n// this will return a pair {root, True/False}\nIsStronglyProbablyPrime(b_IsPositiveInteger, n_IsPositiveInteger) <-- \n[\n  Local(m, q, r, a, flag, i, root);\n  m := n-1;\n  q := m;\n  r := 0;\n  root := 0;\t// will be the default return value of the \"root\"\n  While (IsEven(q))\n  [\n    q := ShiftRight(q, 1);\n    r++;\n  ];\n  \n  a := FastModularPower(b, q, n);\n  flag := (a = 1 Or a = m);\n  i := 1;\n\n  While (Not(flag) And (i < r))\n  [\n\troot := a;\t// this is the value of the root if flag becomes true now\n    a := MathMod(a*a, n);\n    flag := (a = m);\n    i++;\n  ];\n\n  {root, flag};\t// return a root of -1 (or 0 if not found)\n];\n\n\n/*\n * For numbers less than 3.4e14, exhaustive computations have\n * shown that there is no strong pseudoprime simultaneously for\n * bases 2, 3, 5, 7, 11, 13 and 17.\n * Function RabinMillerSmall is based on the results of these\n * computations. \n */\n \n10 # RabinMillerSmall(1) <-- False;\n\n10 # RabinMillerSmall(2) <-- True;\n\n20 # RabinMillerSmall(n_IsEven) <-- False;\n\n20 # RabinMillerSmall(3) <-- True;\n\n30 # RabinMillerSmall(n_IsPositiveInteger) <--\n[\n  Local(continue, prime, i, primetable, pseudotable, root);\n  continue := True;\n  prime := True;\n  i := 1;\n  primetable := {2, 3, 5, 7, 11, 13, 17};\n  pseudotable := {2047, 1373653, 25326001, 3215031751, 2152302898747,\n                  3474749660383, 34155071728321};\n  // if n is strongly probably prime for all bases up to and including primetable[i], then n is actually prime unless it is >= pseudotable[i].\n  While (continue And prime And (i < 8))\n  [\t// we do not really need to collect the information about roots of -1 here, so we do not do anything with root\n    {root, prime} := IsStronglyProbablyPrime(primetable[i], n);\n    If(InVerboseMode() And prime, Echo(\"RabinMiller: Info: \", n, \"is spp base\", primetable[i]));\n    continue := (n >= pseudotable[i]);\n    i++;\n  ];\n  // the function returns \"Overflow\" when we failed to check (i.e. the number n was too large)\n  If (continue And (i = 8), Overflow, prime);\n];\n\n\n/*\n * RabinMillerProbabilistic(n, p) tells whether n is prime.\n * If n is actually prime, the result will always be `True'.\n * If n is composed the probability to obtain the wrong\n * result is less than 4^(-p).\n */\n// these 4 rules are not really used now because RabinMillerProbabilistic is only called for large enough n\n10 # RabinMillerProbabilistic(1, _p) <-- False;\n\n10 # RabinMillerProbabilistic(2, _p) <-- True;\n\n20 # RabinMillerProbabilistic(n_IsEven, _p) <-- False;\n\n20 # RabinMillerProbabilistic(3, _p) <-- True;\n\n30 # RabinMillerProbabilistic(n_IsPositiveInteger, p_IsPositiveInteger) <--\n[\n  Local(k, prime, b, roots'of'minus1, root);\n  k := 1+IntLog(IntLog(n,2),4)+p;\t// find k such that Ln(n)*4^(-k) < 4^(-p)\n  b := 1;\n  prime := True;\n  roots'of'minus1 := {0};\t// accumulate the set of roots of -1 modulo n\n  While (prime And k>0)\n    [\n      b := NextPseudoPrime(b);\t// use only prime bases, as suggested by Davenport; weak pseudo-primes are good enough\n      {root, prime} := IsStronglyProbablyPrime(b, n);\n\t  If(prime, roots'of'minus1 := Union(roots'of'minus1, {root}));\n\t  If(Length(roots'of'minus1)>3, prime := False);\n\t  If(InVerboseMode() And prime, Echo(\"RabinMiller: Info: \", n, \"is spp base\", b));\n\t  If( // this whole If() clause is only working when InVerboseMode() is in effect and the test is terminated in the unusual way\n\t  \tInVerboseMode() And Length(roots'of'minus1)>3,\n\t  \t[\t// we can actually find a factor of n now\n\t\t\tLocal(factor);\n\t\t\troots'of'minus1 := Difference(roots'of'minus1,{0});\n\t\t\tEcho(\"RabinMiller: Info: \", n, \"is composite via roots of -1 ; \", roots'of'minus1);\n\t\t\tfactor := Gcd(n, If(\n\t\t\t\troots'of'minus1[1]+roots'of'minus1[2]=n,\n\t\t\t\troots'of'minus1[1]+roots'of'minus1[3],\n\t\t\t\troots'of'minus1[1]+roots'of'minus1[2]\n\t\t\t));\n\t\t\tEcho(n, \" = \", factor, \" * \", n/factor);\n\t\t]\n\t  );\n      k--;\n    ];\n  prime;\n];\n\n\n/*\n * This is the frontend function, which uses RabinMillerSmall for\n * ``small'' numbers and RabinMillerProbabilistic for bigger ones.\n * \n * The probability to err is set to 1e-25, hopping this is less\n * than the one to step on a rattlesnake in northern Groenland. :-)\n */\n\nRabinMiller(n_IsPositiveInteger) <--\n[\n\tIf(InVerboseMode(), Echo(\"RabinMiller: Info: Testing \", n));\n\tIf(\n\t\tn < 34155071728321,\n\t\tRabinMillerSmall(n),\n\t\tRabinMillerProbabilistic(n, 40)\t// 4^(-40)\n\t);\n];\n"
  },
  {
    "path": "scripts/rabinmiller.rep/code.ys.def",
    "content": "RabinMiller\n}\n"
  },
  {
    "path": "scripts/radsimp.rep/code.ys",
    "content": "\n/* Simplification of nested radicals.\n*/\n\nRadSimp(_n) <--\n[\n  Local(max, result);\n  Set(max, MathCeil(N(Eval(n^2))));\n  Set(result,0);\n  Set(result,RadSimpTry(n,0,1,max));\n\n//Echo(\"result is \",result);\n  if (CheckRadicals(n,result))\n    result\n  else\n    n;\n];\n\n/*Echo({\"Try \",test}); */\n\nCheckRadicals(_n,_test) <-- Abs(N(Eval(n-test),20)) < 0.000001;\n\n10 # ClampRadicals(_r)_(N(Eval(Abs(r)), 20)<0.000001) <-- 0;\n20 # ClampRadicals(_r) <-- r;\n\n\n\nRadSimpTry(_n,_result,_current,_max)<--\n[\n//Echo(result,\" \",n,\" \",current);\n  if (LessThan(N(Eval(result-n)), 0))\n  [\n    Local(i);\n\n    // First, look for perfect match\n    i:=BSearch(max,Hold({{try},ClampRadicals(N(Eval((result+Sqrt(try))-n),20))}));\n    If(i>0,\n    [\n      Set(result,result+Sqrt(i));\n      Set(i,MathAdd(max,1));\n      Set(current,MathAdd(max,1));\n    ]);\n\n    // Otherwise, search for another solution\n    if (LessThan(N(Eval(result-n)), 0))\n    [\n      For (Set(i,current),i<=max,Set(i,MathAdd(i,1)))\n      [\n        Local(new, test);\n        Set(test,result+Sqrt(i));\n\n/* Echo({\"Full-try \",test}); */\n\n        Set(new,RadSimpTry(n,test,i,max));\n\tif (CheckRadicals(n,new))\n        [\n          Set(result,new);\n          Set(i,MathAdd(max,1));\n        ];\n      ];\n    ];\n  ];\n  result;\n];\n\n\n"
  },
  {
    "path": "scripts/radsimp.rep/code.ys.def",
    "content": "RadSimp\n}\n"
  },
  {
    "path": "scripts/random.rep/code.ys",
    "content": "/*\nRandom number generators implemented in an object-oriented manner.\n\nOld interface (still works):\n\n\tRandomSeed(123);\n\tRandom(); Random();\n\nIt provides only one global RNG with a globally assigned seed.\n\nNew interface allows creating many RNG objects:\n\n\tr1:=RngCreate();\t// create a default RNG object, assign structure to r1\n\tr2:=RngCreate(12345);\t// create RNG object with given seed\n\tr3:=RngCreate(seed==0, engine==advanced, dist==gauss); \t// extended options: specify seed, type of RNG engine and the type of statistical distribution\n\tRng(r1); Rng(r1); Rng(r2);\t// generate some floating-point numbers\n\tRngSeed(r1, 12345);\t// r1 is re-initialized with given seed, r2 is unaffected\n\nMore \"RNG engines\" and \"RNG distribution adaptors\" can be defined later (at run time).\n\nRngCreate() will return an object of the following structure:\n\t{SomeDist, SomeEngine, state }\n\nhere SomeEngine is a function atom that describes the RNG engine,\nSomeDist is a function atom that specifies the distribution adaptor,\nand state is a \"RNG state object\", e.g. a list of all numbers that specify the current RNG state (seeds, temporaries, etc.).\n\nRngSeed(r1, seed) expects an integer seed.\nIt will re-initialize the RNG object r1 with the given seed.\n\nThe \"RNG engine API\": calling RngCreate with engine==SomeEngine expects that:\n\tSomeEngine(seed_IsInteger) will create and initialize a state object with given seed and return the new state object (a list). SomeEngine can assume that \"seed\" is a positive integer.\n\tSomeEngine(state1_IsList) will update the RNG state object state1 and return the pair {new state object, new number}.\n\nThe \"RNG distribution adaptor API\": calling RngCreate with distribution==SomeDist expects that:\n\tSomeDist(r1) will update the RNG object r1 and return the pair {new state object, new number}. r1 is a full RNG object, not just a state object.\n\n\n*/\n\n//////////////////////////////////////////////////\n/// lists of defined RNG entities\n//////////////////////////////////////////////////\n\n/// The idea is that options must be easy to type, but procedure names could be long.\n\nLocalSymbols(knownRNGEngines, knownRNGDists) [\n  knownRNGEngines :=\n  {\n    { \"default\", \"RNGEngine'LCG'2\"},\n    { \"advanced\", \"RNGEngine'L'Ecuyer\"},\n  };\n\n  knownRNGDists :=\n  {\n    {\"default\", \"FlatRNGDist\"},\n    {\"flat\", \"FlatRNGDist\"},\n  //\t{\"uniform\", \"FlatRNGDist\"},\t// we probably don't need this alias...\n    {\"gauss\", \"GaussianRNGDist\"},\n  };\n\n  KnownRNGDists() := knownRNGDists;\n  KnownRNGEngines() := knownRNGEngines;\n];\n\n\n//////////////////////////////////////////////////\n/// RNG object API\n//////////////////////////////////////////////////\n\nFunction() RngCreate();\nFunction() RngCreate(seed, ...);\nHoldArg(\"RngCreate\", seed);\t// this is needed to prevent evaluation of = and also to prevent substitution of variables, e.g. if \"seed\" is defined\n//UnFence(\"RngCreate\", 0);\n//UnFence(\"RngCreate\", 1);\nFunction() RngSeed(r, seed);\n//UnFence(\"RngSeed\", 2);\n/// accessor for RNG objects\nFunction() Rng(r);\n//UnFence(\"Rng\", 1);\n\n\nRngCreate() <-- RngCreate(0);\n\n10 # RngCreate(a'seed_IsInteger) <-- (RngCreate @ {Atom(\"seed\") == a'seed});\n\n// a single option given: convert explicitly to a list\n20 # RngCreate(_key == _value) <-- (RngCreate @ {{key == value}});\n20 # RngCreate(_key = _value) <-- (RngCreate @ {{key == value}});\n\n// expect a list of options\n30 # RngCreate(options_IsList) <--\n[\n\toptions := ListToHash @ {options};\n\t// check options and assign defaults\n\tIf(\n\t\toptions[\"seed\"] = Empty Or options[\"seed\"] <= 0,\n\t\toptions[\"seed\"] := 76544321\t// some default seed out of the blue sky\n\t);\n\tIf(\n\t\toptions[\"engine\"] = Empty Or Not (Assert(\"warning\", {\"RngCreate: invalid engine\", options[\"engine\"]}) KnownRNGEngines()[options[\"engine\"] ] != Empty),\n\t\toptions[\"engine\"] := \"default\"\n\t);\n\tIf(\n\t\toptions[\"dist\"] = Empty Or Not (Assert(\"warning\", {\"RngCreate: invalid distribution\", options[\"dist\"]}) KnownRNGDists()[options[\"dist\"] ] != Empty),\n\t\toptions[\"dist\"] := \"default\"\n\t);\n\t\n\t// construct a new RNG object\n\t// a RNG object has the form {\"SomeDist\", \"SomeEngine\", {state}}\n\t{\n\t\tKnownRNGDists()[options[\"dist\"] ], KnownRNGEngines()[options[\"engine\"] ], \n\t\t// initialize object with given seed using \"SomeEngine\"(seed)\n\t\tKnownRNGEngines()[options[\"engine\"] ] @ { options[\"seed\"] }\n\t};\n];\n\n/// accessor function: will call SomeDist(r) and update r\nRng(_r) <--\n[\n\tLocal(state, result);\n\t{state, result} := (r[1] @ {r});\t// this calls SomeDist(r)\n\tDestructiveReplace(r, 3, state);\t// update RNG object \n\tresult;\t// return floating-point number\n];\n\n/// set seed: will call SomeEngine(r, seed) and update r\nRngSeed(_r, seed_IsInteger) <--\n[\n\tLocal(state);\n\t(Assert(\"warning\", {\"RngSeed: seed must be positive\", seed}) seed > 0\n\t) Or (seed:=76544321);\n\tstate := (r[2] @ {seed});\t// this calls SomeEngine(r)\n\tDestructiveReplace(r, 3, state);\t// update object \n\tTrue;\n];\n\n//////////////////////////////////////////////////\n/// RNG distribution adaptors\n//////////////////////////////////////////////////\n\n/// trivial distribution adaptor: flat distribution, simply calls SomeEngine(r)\n/* we have to return whole objects; we can't use references b/c the core\nfunction ApplyPure will not work properly on references, i.e. if r = {\"\", \"\", {1}} so that\nr[3] = {1}, then LCG'2(r[3]) modifies r[3], but LCG'2 @ r[3] or\nApplyPure(\"LCG'2\", {r[3]}) do not actually modify r[3].\n*/\n\n// return pair {state, number}\nFlatRNGDist(_r) <-- (r[2] @ {r[3]});\t// this calls SomeEngine(state)\n\n/// Gaussian distribution adaptor, returns a complex number with normal distribution with unit variance, i.e. Re and Im are independent and both have unit variance\n/* Gaussian random number, Using the Box-Muller transform, from Knuth, \n   \"The Art of Computer Programming\", \n   Volume 2 (Seminumerical algorithms, third edition), section 3.4.1 \n */\nGaussianRNGDist(_rng) <--\n[\n\t// a Gaussian distributed complex number p + I*q is made up of two uniformly distributed numbers x,y according to the formula:\n\t// a:=2*x-1, b:=2*y-1, m:=a^2+b^2; p = a*Sqrt(-2*Ln(m)/m); q:=b*Sqrt(-2*Ln(m)/m);\n\t// here we need to make sure that m is nonzero and strictly less than 1.\n\tLocal(a,b,m, new'state, rnumber);\n\tnew'state := rng[3];\t// this will be updated at the end\n\tm:=0;\n\tWhile(m=0 Or m>=1)\t// repeat generating new x,y  - should not take more than one iteration really\n\t[\n\t\t{new'state, rnumber} := (rng[2] @ {new'state});\n\t\ta:=2*rnumber-1;\n\t\t{new'state, rnumber} := (rng[2] @ {new'state});\n\t\tb:=2*rnumber-1;\n\t\tm:=a*a+b*b;\t\n\t];\n\t{new'state, (a+I*b)*MathSqrt(-2*MathDivide(Internal'LnNum(m),m))};\n];\n\n\n//////////////////////////////////////////////////\n/// RNG engines\n//////////////////////////////////////////////////\n\n/// default RNG engine: the LCG generator\n\n// first method: initialize a state object with given seed\nRNGEngine'LCG'1(seed_IsInteger) <-- {seed};\n// second method: update state object and return new number\nRNGEngine'LCG'1(state_IsList) <-- LCG'1(state);\n\n// first method: initialize a state object with given seed\nRNGEngine'LCG'2(seed_IsInteger) <-- {seed};\n// second method: update state object and return new number\nRNGEngine'LCG'2(state_IsList) <-- LCG'2(state);\n\n// first method: initialize a state object with given seed\nRNGEngine'LCG'3(seed_IsInteger) <-- {seed};\n// second method: update state object and return new number\nRNGEngine'LCG'3(state_IsList) <-- LCG'3(state);\n\n// first method: initialize a state object with given seed\nRNGEngine'LCG'4(seed_IsInteger) <-- {seed};\n// second method: update state object and return new number\nRNGEngine'LCG'4(state_IsList) <-- LCG'4(state);\n\n/// parameters from P. Hellekalek, 1994; see G. S. Fishman, Math. Comp. vol. 54, 331 (1990)\nLCG'1(state) := RandomLCG(state, 2147483647,950706376,0);\nLCG'2(state) := RandomLCG(state, 4294967296,1099087573,0);\nLCG'3(state) := RandomLCG(state, 281474976710656,68909602460261,0);\nLCG'4(state) := RandomLCG(state, 18014398509481984,2783377640906189,0);\n\n/// Linear congruential generator engine: backend\n// state is a list with one element\nRandomLCG(_state, _im, _ia, _ic) <--\n{\n\tDestructiveReplace(state,1, MathMod(state[1]*ia+ic,im)),\n\tMathDivide(state[1], im)\t// division should never give 1\n};\n\n/// Advanced RNG engine due to L'Ecuyer et al.\n/// RNG from P. L'ecuyer et al (2000). Period approximately 2^191\n// state information: 6 32-bit integers, corresponding to {x3,x2,x1,y3,y2,y1}\n\n// first method: initialize a state object with given seed\nRNGEngine'L'Ecuyer(a'seed_IsInteger) <--\n[\n\t// use LCG'2 as auxiliary RNG to fill the seeds\n\tLocal(rng'aux, result);\n\trng'aux := (RngCreate @ {a'seed});\n\t// this will be the state vector\n\tresult:=ZeroVector(6);\n\t// fill the state object with random numbers\n\tLocal(i);\n\tFor(i:=1, i<=6, i++)\n\t[\n\t\tRng(rng'aux);\n\t\tresult[i] := rng'aux[3][1];\t// hack to get the integer part\n\t];\n\t// return the state object\n\tresult;\n];\n\n// second method: update state object and return a new random number (floating-point)\nRNGEngine'L'Ecuyer(state_IsList) <--\n[\n\tLocal(new'state, result);\n\tnew'state := {\n\t\tMod(1403580*state[2]-810728*state[3], 4294967087), state[1], state[2],\n\t\tMod(527612*state[4]-1370589*state[6], 4294944433), state[4], state[5]\n\t};\n\tresult:=Mod(state[1]-state[4], 4294967087);\n\t{\n\t\tnew'state,\n\t\tMathDivide(If(result=0, 4294967087, result), 4294967088)\n\t};\n];\n\n//////////////////////////////////////////////////\n/// old interface: using one global RNG object\n//////////////////////////////////////////////////\n/* this is a little slower but entirely equivalent to the code below\nGlobalRNG := RngCreate(76544321);\nRandom() := Rng(GlobalRNG);\nRandomSeed(seed) := RngSeed(GlobalRNG, seed);\n*/\n\nLocalSymbols(RandSeed) [\n  // initial seed should be nonzero\n  RandSeed:=76544321;\n\n  /// assign random seed\n  Function(\"RandomSeed\", {seed}) Set(RandSeed, seed);\n\n  /// Linear congruential generator\n  RandomLCG(_im, _ia, _ic) <--\n  [\n    RandSeed:=MathMod(RandSeed*ia+ic,im);\n    MathDivide(RandSeed,im);\t// should never give 1\n  ];\n]; // LocalSymbols(RandSeed)\n\n\nFunction(\"Random1\",{}) RandomLCG(4294967296,1103515245,12345);\nFunction(\"Random6\",{}) RandomLCG(1771875,2416,374441);\n/// parameters from P. Hellekalek, 1994; see G. S. Fishman, Math. Comp. vol. 54, 331 (1990)\nFunction(\"Random2\",{}) RandomLCG(2147483647,950706376,0);\nFunction(\"Random3\",{}) RandomLCG(4294967296,1099087573,0);\nFunction(\"Random4\",{}) RandomLCG(281474976710656,68909602460261,0);\nFunction(\"Random5\",{}) RandomLCG(18014398509481984,2783377640906189,0);\n\n// select one of them\nFunction(\"Random\",{}) Random3();\n\n\n\n"
  },
  {
    "path": "scripts/random.rep/code.ys.def",
    "content": "RandomSeed\nRandom\nRng\nRngSeed\nRngCreate\n}\n"
  },
  {
    "path": "scripts/rational.rep/code.ys",
    "content": "\n10 # IsRationalFunction(_p, x_IsVariable)_CanBeUni(x, p) <-- True;\n10 # IsRationalFunction(_p / _q, x_IsVariable)_(CanBeUni(x, p) And CanBeUni(x, q)) <-- True;\n50 # IsRationalFunction(_f + _g, x_IsVariable)_(IsRationalFunction(f, x) And IsRationalFunction(g, x)) <-- True;\n50 # IsRationalFunction(_f - _g, x_IsVariable)_(IsRationalFunction(f, x) And IsRationalFunction(g, x)) <-- True;\n\n100 # IsRationalFunction(_p, x_IsVariable) <-- False;\n\n\n200 # Numer(p_CanBeUni) <-- p;\n300 # Numer(p_CanBeUni / q_CanBeUni) <-- p;\n300 # Numer(p_CanBeUni / q_CanBeUni + r_CanBeUni) <-- p + r * q;\n300 # Numer(p_CanBeUni / q_CanBeUni - r_CanBeUni) <-- p - r * q;\n300 # Numer(p_CanBeUni / q_CanBeUni + r_CanBeUni / s_CanBeUni) <-- p * s + r * q;\n300 # Numer(p_CanBeUni / q_CanBeUni - r_CanBeUni / s_CanBeUni) <-- p * s - r * q;\n\n200 # Denom(p_CanBeUni) <-- 1;\n300 # Denom(p_CanBeUni / q_CanBeUni) <-- q;\n300 # Denom(p_CanBeUni / q_CanBeUni + r_CanBeUni) <-- q;\n300 # Denom(p_CanBeUni / q_CanBeUni - r_CanBeUni) <-- q;\n300 # Denom(p_CanBeUni / q_CanBeUni + r_CanBeUni / s_CanBeUni) <-- q * s;\n300 # Denom(p_CanBeUni / q_CanBeUni - r_CanBeUni / s_CanBeUni) <-- q * s;\n\nIsPureRationalFunction(_p, x_IsVariable)_IsRationalFunction(p, x) <-- Degree(Numer(p), x) < Degree(Denom(p), x);\n"
  },
  {
    "path": "scripts/rational.rep/code.ys.def",
    "content": "IsRationalFunction\nIsPureRationalFunction\n}\n\n"
  },
  {
    "path": "scripts/simplify.rep/code.ys",
    "content": "\n\n10 # Simplify(expr_IsList) <-- MapSingle(\"Simplify\",expr);\n\n15 # Simplify(Complex(_r,_i)) <-- Complex(Simplify(r),Simplify(i));\n\n20 # Simplify((_xex) == (_yex)) <-- (Simplify(xex-yex) == 0);\n\n20 # Simplify((_xex) > (_yex)) <-- (Simplify(xex-yex) > 0);\n20 # Simplify((_xex) < (_yex)) <-- (Simplify(xex-yex) < 0);\n20 # Simplify((_xex) >= (_yex)) <-- (Simplify(xex-yex) >= 0);\n20 # Simplify((_xex) <= (_yex)) <-- (Simplify(xex-yex) <= 0);\n20 # Simplify((_xex) !== (_yex)) <-- (Simplify(xex-yex) !== 0);\n\n// conditionals\n25 # Simplify(if (_a) _b) <-- \"if\" @ {Simplify(a), Simplify(b)};\n25 # Simplify(_a else _b) <-- \"else\" @ {Simplify(a), Simplify(b)};\n\n50 # Simplify(_expr) <-- MultiSimp(Eval(expr));\n\n\nEliminate(_var,_replace,_function) <-- Simplify(Subst(var,replace)function);\n//ExpandBrackets(_xx) <-- SimpExpand(SimpImplode(SimpFlatten(xx)));\nExpandBrackets(x) := NormalForm(MM(x));\n\nFunction(\"Flatten\",{body,flattenoper})\n[\n  DoFlatten(body);\n];\n\nRuleBase(\"DoFlatten\",{doflattenx});\nUnFence(\"DoFlatten\",1);\n\n10 # DoFlatten(_doflattenx)_(Type(doflattenx)=flattenoper) <--\n     Apply(\"Concat\",MapSingle(\"DoFlatten\",Tail(Listify(doflattenx))));\n20 # DoFlatten(_doflattenx) <-- { doflattenx };\n\n\n10 # UnFlatten({},_op,_identity) <-- identity;\n20 # UnFlatten(list_IsList,_op,_identity) <--\n     Apply(op,{Head(list),UnFlatten(Tail(list),op,identity)});\n\n\nRuleBase(\"SimpAdd\",{x,y});\nRuleBase(\"SimpMul\",{x,y});\nRuleBase(\"SimpDiv\",{x,y});\n\n\n10 # SimpFlatten((_x)+(_y)) <-- SimpAdd(SimpFlatten(x),SimpFlatten(y));\n10 # SimpFlatten((_x)-(_y)) <-- SimpAdd(SimpFlatten(x),SimpMul(-1,SimpFlatten(y)));\n10 # SimpFlatten(    -(_y)) <-- SimpMul(-1,SimpFlatten(y));\n\n10 # SimpFlatten((_x)*(_y)) <-- SimpMul(SimpFlatten(x),SimpFlatten(y));\n10 # SimpFlatten((_x)/(_y)) <-- SimpDiv(SimpFlatten(x),SimpFlatten(y));\n10 # SimpFlatten((_x)^(n_IsPositiveInteger)) <--\n     SimpMul(SimpFlatten(x),SimpFlatten(x^(n-1)));\n\n100 # SimpFlatten(_x) <--\n[\n  x;\n];\n\n10 # SimpExpand(SimpAdd(_x,_y)) <-- SimpExpand(x) + SimpExpand(y);\n10 # SimpExpand(SimpMul(_x,_y)) <-- SimpExpand(x) * SimpExpand(y);\n10 # SimpExpand(SimpDiv(_x,_y)) <-- SimpExpand(x) / SimpExpand(y);\n20 # SimpExpand(_x) <-- x;\n\n/* Distributed multiplication rule */\n10 # SimpImplode(SimpMul(SimpAdd(_x,_y),_z)) <--\n     SimpImplode(SimpAdd(SimpImplode(SimpMul(x,z)),\n                 SimpImplode(SimpMul(y,z))));\n10 # SimpImplode(SimpMul(_z,SimpAdd(_x,_y))) <--\n     SimpImplode(SimpAdd(SimpImplode(SimpMul(z,x)),\n                 SimpImplode(SimpMul(z,y))));\n/* Distributed division rule  */\n10 # SimpImplode(SimpDiv(SimpAdd(_x,_y),_z)) <--\n     SimpImplode(SimpAdd(SimpImplode(SimpDiv(x,z)),\n     SimpImplode(SimpDiv(y,z))));\n\n\n\n20 # SimpImplode(SimpAdd(_x,_y)) <--\n     SimpAdd(SimpImplode(x),SimpImplode(y));\n20 # SimpImplode(SimpMul(_x,_y)) <--\n     SimpMul(SimpImplode(x),SimpImplode(y));\n20 # SimpImplode(SimpDiv(_x,_y)) <--\n     SimpDiv(SimpImplode(x),SimpImplode(y));\n30 # SimpImplode(_x) <-- x;\n\n\n//////////////////////////////////////////////////\n/// ExpandFrac --- normalize rational functions (no simplification)\n//////////////////////////////////////////////////\n\n5 # ExpandFrac(expr_IsList) <-- MapSingle(\"ExpandFrac\", expr);\n\n// expression does not contain fractions\n10 # ExpandFrac(_expr)_Not(HasFuncSome(expr, \"/\", {Atom(\"+\"), Atom(\"-\"), *, /, ^})) <-- expr;\n15 # ExpandFrac(a_IsRationalOrNumber) <-- a;\n20 # ExpandFrac(_expr) <-- ExpandFrac'combine(GetNumerDenom(expr));\n\nExpandFrac'combine({_a, _b}) <-- a/b;\n\n/// GetNumerDenom(x) returns a pair of expressions representing normalized numerator and denominator; GetNumerDenom(x, a) multiplies the numerator by the number a\nGetNumerDenom(_expr, _a) <-- GetNumerDenom(expr)*{a,1};\n\n// on expressions that are not fractions, we return unit denominator\n10 # GetNumerDenom(_expr)_Not(HasFuncSome(expr, \"/\", {Atom(\"+\"), Atom(\"-\"), *, /, ^})) <-- {expr, 1};\n// rational numbers are not simplified\n15 # GetNumerDenom(a_IsRationalOrNumber) <-- {a, 1};\n// arithmetic\n20 # GetNumerDenom(_a + _b) <-- ExpandFrac'add(GetNumerDenom(a), GetNumerDenom(b));\n20 # GetNumerDenom(_a - _b) <-- ExpandFrac'add(GetNumerDenom(a), GetNumerDenom(b, -1));\n20 # GetNumerDenom(- _a) <-- GetNumerDenom(a, -1);\n20 # GetNumerDenom(+ _a) <-- GetNumerDenom(a);\n20 # GetNumerDenom(_a * _b) <-- ExpandFrac'multiply(GetNumerDenom(a), GetNumerDenom(b));\n20 # GetNumerDenom(_a / _b) <-- ExpandFrac'divide(GetNumerDenom(a), GetNumerDenom(b));\n// integer powers\n20 # GetNumerDenom(_a ^ b_IsInteger)_(b > 1) <-- ExpandFrac'multiply(GetNumerDenom(a), GetNumerDenom(a^(b-1)));\n20 # GetNumerDenom(_a ^ b_IsInteger)_(b < -1) <-- ExpandFrac'divide(GetNumerDenom(1), GetNumerDenom(a^(-b)));\n20 # GetNumerDenom(_a ^ b_IsInteger)_(b = -1) <-- ExpandFrac'divide(GetNumerDenom(1), GetNumerDenom(a));\n// non-integer powers are not considered to be rational functions\n25 # GetNumerDenom(_a ^ _b) <-- {a^b, 1};\n\n// arithmetic on fractions; not doing any simplification here, whereas we might want to\nExpandFrac'add({_a, _b}, {_c, _d}) <-- {a*d+b*c, b*d};\nExpandFrac'multiply({_a, _b}, {_c, _d}) <-- {a*c, b*d};\nExpandFrac'divide({_a, _b}, {_c, _d}) <-- {a*d, b*c};\n\n"
  },
  {
    "path": "scripts/simplify.rep/code.ys.def",
    "content": "Eliminate\nExpandBrackets\nSimplify\nFlatten\nUnFlatten\nExpandFrac\n}\n"
  },
  {
    "path": "scripts/simplify.rep/factorial.ys",
    "content": "\n/* FactorialSimplify algorithm: \n   1) expand binomials into factors\n   2) expand brackets as much as possible\n   3) for the remaining rational expressions x/y,\n      take all the factors of x and y, and match them\n      up one by one to determine if they can be \n      factored out. The algorithm will look at expressions like x^n/x^m\n      where (n-m) is an integer, or at expressions x!/y! where (x-y)\n      is an integer. The routine CommonDivisors does these steps, and\n      returns the new numerator and denominator factor.\n  FactorialSimplifyWorker does the actual O(n^2) algorithm of\n  matching all terms up.\n*/\n\nFactorialNormalForm(x):=\n[\n  // Substitute binomials\n  x:=(x/:{Bin(_n,_m)<- (n!)/((m!)*(n-m)!)});\n  // Expand expression as much as possible so that the terms become\n  // simple rationals.\n\n  x:=(\n      x/::Hold({\n          (_a/_b)/_c <- (a)/(b*c),\n          (-(_a/_b))/_c <- (-a)/(b*c),\n          (_a/_b)*_c <- (a*c)/b,\n          (_a*_b)^_m <- a^m*b^m,\n          (_a/_b)^_m*_c <- (a^m*c)/b^m,\n          _a*(_b+_c) <- a*b+a*c,\n          (_b+_c)*_a <- a*b+a*c,\n          (_b+_c)/_a <- b/a+c/a,\n          _a*(_b-_c) <- a*b-a*c,\n          (_b-_c)*_a <- a*b-a*c,\n          (_b-_c)/_a <- b/a-c/a\n     }));\n  x;\n];\n\nFactorialSimplify(x):=\n[\n  x := FactorialNormalForm(x);\n  FactorialSimplifyWorker(x);\n];\n\n\n/* CommonDivisors takes two parameters x and y as input, determines a common divisor g \n   and then returns {x/g,y/g,g}.\n */\n10 # CommonDivisors(_x^(_n),_x^(_m)) <-- {x^Simplify(n-m),1,x^m};\n10 # CommonDivisors(_x^(_n),_x)  <-- {x^Simplify(n-1),1,x};\n10 # CommonDivisors(_x,_x^(_m)) <-- {x^Simplify(1-m),1,x^m};\n10 # CommonDivisors((_x) !,_x) <-- {(x-1)!,1,x};\n10 # CommonDivisors(_x,_x) <-- {1,1,x};\n10 # CommonDivisors(- _x,_x) <-- {-1,1,x};\n10 # CommonDivisors(_x,- _x) <-- {1,-1,x};\n10 # CommonDivisors((_x),(_x)!) <-- {1,(x-1)!,x};\n10 # CommonDivisors((_x)!, (_y)!)_IsInteger(Simplify(x-y))  <-- CommonFact(Simplify(x-y),y);\n\n\n10 # CommonDivisors((_x)! ^ _m, (_y)! ^ _m)_IsInteger(Simplify(x-y))  <-- CommonFact(Simplify(x-y),y)^m;\n\n10 # CommonFact(dist_IsNegativeInteger,_y) \n   <-- {1,Product(i,1,-dist,Simplify(y+i+dist)),Simplify(y+dist)!};\n11 # CommonFact(_dist,_y) \n   <-- {Product(i,1,dist,Simplify(y+i)),1,Simplify(y)!};\n60000 # CommonDivisors(_x,_y) <-- {x,y,1};\n\n10 # CommonFactors((_x)!,_y)_(Simplify(y-x) = 1) <-- {y!,1};\n10 # CommonFactors((_x)!,_y)_(Simplify((-y)-x) = 1) <-- {(-y)!,-1};\n\n10 # CommonFactors(_x^_n,_x^_m) <-- {x^Simplify(n+m),1};\n10 # CommonFactors(_x^_n,_x) <-- {x^Simplify(n+1),1};\n\n60000 # CommonFactors(_x,_y) <-- {x,y};\n\n10 # FactorialSimplifyWorker(_x+_y) <-- FactorialSimplifyWorker(x)+FactorialSimplifyWorker(y);\n10 # FactorialSimplifyWorker(_x-_y) <-- FactorialSimplifyWorker(x)-FactorialSimplifyWorker(y);\n10 # FactorialSimplifyWorker(  -_y) <--                     -FactorialSimplifyWorker(y);\n\nLocalSymbols(x,y,i,j,n,d)[\n\n20 # FactorialSimplifyWorker(_x/_y) <-- \n[\n  // first separate out factors of the denominator\n  Local(numerCommon,numerTerms);\n  {numerCommon,numerTerms}:=FactorialGroupCommonDivisors(x);\n  Local(denomCommon,denomTerms);\n  {denomCommon,denomTerms}:=FactorialGroupCommonDivisors(y);\n  Local(n,d,c);\n  {n,d,c} := FactorialDivideTerms(numerCommon,denomCommon);\n  (n/d)*Simplify((numerTerms)/(denomTerms));\n];\n\n\n\n20 # FactorialGcd(_x,_y) <-- \n[\n  // first separate out factors of the denominator\n  Local(numerCommon,numerTerms);\n  {numerCommon,numerTerms}:=FactorialGroupCommonDivisors(x);\n  Local(denomCommon,denomTerms);\n  {denomCommon,denomTerms}:=FactorialGroupCommonDivisors(y);\n  Local(n,d,c);\n  {n,d,c} := FactorialDivideTerms(numerCommon,denomCommon);\n  c;\n];\n\n\n\n\n\n10 # FactorialDivideTerms(- _x,- _y) <-- FactorialDivideTermsAux(x,y);\nLocalSymbols(n,d,c)\n[\n  20 # FactorialDivideTerms(- _x,  _y) \n    <-- \n    [\n      Local(n,d,c);\n      {n,d,c} := FactorialDivideTermsAux(x,y);\n      {-n,d,c};\n    ];\n  30 # FactorialDivideTerms(  _x,- _y) \n    <-- \n    [\n      Local(n,d,c);\n      {n,d,c} := FactorialDivideTermsAux(x,y);\n      {n,-d,c};\n    ];\n];\n40 # FactorialDivideTerms(  _x,  _y) \n   <-- \n   [\n//     Echo(\"GOTHERE 40\");\n     FactorialDivideTermsAux(x,y);\n   ];\n\nLocalSymbols(n,d,c)\n[\n  10 # FactorialDivideTermsAux(_x,_y) <--\n  [\n    x:=Flatten(x,\"*\");\n    y:=Flatten(y,\"*\");\n  \n    Local(i,j,common);\n    common:=1;\n    For(i:=1,i<=Length(x),i++)\n    For(j:=1,j<=Length(y),j++)\n    [\n      Local(n,d,c);\n//Echo(\"inp is \",x[i],\" \",y[j]);\n      {n,d,c} := CommonDivisors(x[i],y[j]);\n  \n//Echo(\"aux is \",{n,d,c});\n      x[i] := n;\n      y[j] := d;\n      common:=common*c;\n    ];\n//Echo(\"final \",{x,y,common});\n//Echo(\"finalor \",{Multiply(x),Multiply(y),common});\n    {Multiply(x),Multiply(y),common};\n  ];\n];\n\n];\n\n60000 # FactorialSimplifyWorker(_x) \n      <-- \n      [\n  // first separate out factors of the denominator\n  Local(numerCommon,numerTerms);\n  {numerCommon,numerTerms}:=FactorialGroupCommonDivisors(x);\n  numerCommon*numerTerms;\n      ];\n    \n/* FactorialFlattenAddition accepts an expression of form a+b+c-d+e-f+ ... +z with arbitrary additions\n   and subtractions, and converts it to a list of terms. Terms that need to be subtracted start with a \n   negation sign (useful for pattern matching).\n */\n10 # FactorialFlattenAddition(_x+_y) <-- Concat(FactorialFlattenAddition(x), FactorialFlattenAddition(y));\n10 # FactorialFlattenAddition(_x-_y) <-- Concat(FactorialFlattenAddition(x),-FactorialFlattenAddition(y));\n10 # FactorialFlattenAddition(  -_y) <--                           -FactorialFlattenAddition(y);\n20 # FactorialFlattenAddition(_x   ) <--                           {x};\n\nLocalSymbols(n,d,c)\n[\n  10 # FactorialGroupCommonDivisors(_x) <--\n  [\n    Local(terms,common,tail);\n    terms:=FactorialFlattenAddition(x);\n//Echo(\"terms is \",terms);\n    common := Head(terms);  \n    tail:=Tail(terms);\n    While (tail != {})\n    [\n      Local(n,d,c);\n      {n,d,c} := FactorialDivideTerms(common,Head(tail));\n  \n//Echo(common, \" \",Head(tail),\" \",c);\n      common := c;\n      tail:=Tail(tail);\n    ];\n    Local(i,j);\n  \n//  Echo(\"common is \",common);\n  \n    For(j:=1,j<=Length(terms),j++)\n    [\n      Local(n,d,c);\n//  Echo(\"IN = \",terms[j],\" \",common);\n//  Echo(\"n = \",n);\n      {n,d,c} := FactorialDivideTerms(terms[j],common);\n//  Echo(\"n = \",n);\n//  Echo(\"{n,d,c} = \",{n,d,c});\n      Check(d = 1,\n        ToString()[\n        Echo(\"FactorialGroupCommonDivisors failure 1 : \",d);\n        ]);\n/*\n      Check(Simplify(c-common) = 0,\n        ToString()\n        [\n          Echo(\"FactorialGroupCommonDivisors failure 2 : \");\n          Echo(c,\" \",common);\n          Echo(Simplify(c-common));\n        ]);\n*/\n      terms[j] := n;\n    ];\n    terms:=Add(terms);\n\n    common:=Flatten(common,\"*\");\n    For(j:=1,j<=Length(common),j++)\n    [\n      Local(f1,f2);\n      {f1,f2}:=CommonFactors(common[j],terms);\n      common[j]:=f1;\n      terms:=f2;\n\n      For(i:=1,i<=Length(common),i++)\n      If(i != j,\n        [\n          {f1,f2}:=CommonFactors(common[j],common[i]);\n          common[j]:=f1;\n          common[i]:=f2;\n        ]);\n    ];    \n    common := Multiply(common);\n    {common,terms};\n  ];\n];  \n  \n"
  },
  {
    "path": "scripts/simplify.rep/factorial.ys.def",
    "content": "FactorialSimplify\n}\n\n"
  },
  {
    "path": "scripts/solve.rep/code.ys",
    "content": "/*\n * Strategy for Solve(expr, x):\n *\n * 10.  Call Solve'System for systems of equations.\n * 20.  Check arguments.\n * 30.  Get rid of \"==\" in 'expr'.\n * 40.  Special cases.\n * 50.  If 'expr' is a polynomial in 'x', try to use PSolve.\n * 60.  If 'expr' is a product, solve for either factor.\n * 70.  If 'expr' is a quotient, solve for the denominator.\n * 80.  If 'expr' is a sum and one of the terms is free of 'x',\n *      try to use Solve'Simple.\n * 90.  If every occurance of 'x' is in the same context, use this to reduce\n *      the equation. For example, in 'Cos(x) + Cos(x)^2 == 1', the variable\n *      'x' always occurs in the context 'Cos(x)', and hence we can attack\n *      the equation by first solving 'y + y^2 == 1', and then 'Cos(x) == y'.\n *      This does not work for 'Exp(x) + Cos(x) == 2'.\n * 100. Apply Simplify to 'expr', and try again.\n * 110. Give up.\n */\n\nLocalSymbols(res)\n[\n   5  # Solve(expr_IsList, var_IsList)_(Length(expr) = 1 And Length(var) = 1 And IsAtom(Head(var))) <-- {Solve(Head(expr), Head(var))};\n  10  # Solve(expr_IsList, var_IsList) <-- Solve'System(expr, var);\n  20  # Solve(_expr, _var)_(Not IsAtom(var) Or IsNumber(var) Or IsString(var)) <--\n        [ Assert(\"Solve'TypeError\", \"Second argument, \":(ToString() Write(var)):\", is not the name of a variable\") False; {}; ];\n  30  # Solve(_lhs == _rhs, _var) <-- Solve(lhs - rhs, var);\n  40  # Solve(0, _var) <-- {var == var};\n  41  # Solve(a_IsConstant, _var) <-- {};\n  42  # Solve(_expr, _var)_(Not HasExpr(expr,var)) <--\n        [ Assert(\"Solve\", \"expression \":(ToString() Write(expr)):\" does not depend on \":ToString() Write(var)) False; {}; ];\n  50  # Solve(_expr, _var)_((res := Solve'Poly(expr, var)) != Failed) <-- res;\n  60  # Solve(_e1 * _e2, _var) <-- [\n      Local(t,u,s);\n      t := Union(Solve(e1,var), Solve(e2,var));\n      u := {};\n      ForEach(s, t) [\n         Local(v1,v2);\n         v1 := WithValue(var, s[2], e1);\n         v2 := WithValue(var, s[2], e2);\n         If(Not (IsInfinity(v1) Or (v1 = Undefined) Or\n                 IsInfinity(v2) Or (v2 = Undefined)),\n             DestructiveAppend(u, s));\n      ];\n      u;\n  ];\n  70  # Solve(_e1 / _e2, _var) <-- [\n      Local(tn, t, s);\n      tn := Solve(e1, var);\n      t := {};\n      ForEach(s, tn)\n          If(Not(IsZero(WithValue(var, s[2], e2))),\n              DestructiveAppend(t, s)\n          );\n      t;\n  ];\n  80  # Solve(_e1 + _e2, _var)_(Not HasExpr(e2,var) And (res := Solve'Simple(e1,-e2,var)) != Failed) <-- res;\n  80  # Solve(_e1 + _e2, _var)_(Not HasExpr(e1,var) And (res := Solve'Simple(e2,-e1,var)) != Failed) <-- res;\n  80  # Solve(_e1 - _e2, _var)_(Not HasExpr(e2,var) And (res := Solve'Simple(e1,e2,var)) != Failed) <-- res;\n  80  # Solve(_e1 - _e2, _var)_(Not HasExpr(e1,var) And (res := Solve'Simple(e2,e1,var)) != Failed) <-- res;\n  85  # Solve(_expr, _var)_((res := Solve'Simple(expr, 0, var)) != Failed) <-- res;\n  90  # Solve(_expr, _var)_((res := Solve'Reduce(expr, var)) != Failed) <-- res;\n  95  # Solve(_expr, _var)_((res := Solve'Divide(expr, var)) != Failed) <-- res;\n  100 # Solve(_expr, _var)_((res := Simplify(expr)) != expr) <-- Solve(res, var);\n  110 # Solve(_expr, _var) <--\n        [ Assert(\"Solve'Fails\", \"cannot solve equation \":(ToString() Write(expr)):\" for \":ToString() Write(var)) False; {}; ];\n];\n\n/********** Solve'Poly **********/\n\n/* Tries to solve by calling PSolve */\n/* Returns Failed if this doesn't work, and the solution otherwise */\n\n/* CanBeUni is not documented, but defined in univar.rep/code.ys */\n/* It returns True iff 'expr' is a polynomial in 'var' */\n\n10 # Solve'Poly(_expr, _var)_(Not CanBeUni(var, expr)) <-- Failed;\n\n15 # Solve'Poly(_expr, _var)_IsZero(ConstantTerm(expr, var)) <--\n[\n    Local(r);\n    r := Solve'Poly(NormalForm(Div(MakeUni(expr, var), MakeUni(var, var))), var);\n\n    If (Not IsList(r), r, Concat({var == 0}, r));\n];\n\nLocalSymbols(u, x) [\n    16 # Solve'Poly(_expr, _var)_([u := MakeUni(expr, var); Degree(u) > 1 And ConstantTerm(u) != 0 And Coef(u, 1 .. Degree(u) - 1) = ZeroVector(Degree(u) - 1);]) <-- [\n        MapSingle({{x},var==x}, PSolve(u));\n    ];\n];\n\nSolve'Poly'Divisors(n_IsInteger) <-- [\n    Local(f, nf, p, d, i, divisors);\n    f := Factors(n);\n    nf := Length(f);\n\n    p := ZeroVector(nf + 1);\n\n    divisors := {};\n\n    While (p[nf + 1] = 0) [\n        Local(d, i, t, divisor);\n        d := (\"^\" @ {Transpose(f)[1], p[1 .. nf]});\n        divisor := 1;\n        ForEach (t, d) divisor := divisor * t;\n        DestructiveAppend(divisors, divisor);\n        DestructiveReplace(p, 1, p[1] + 1);\n        i := 1;\n        While (i <= nf And p[i] > f[i][2]) [\n            DestructiveReplace(p, i, 0);\n            i := i + 1;\n            DestructiveReplace(p, i, p[i] + 1);\n        ];\n    ];\n    divisors;\n];\n\n20 # Solve'Poly(_expr, _var) <--\nLocalSymbols(x)\n[\n  Local(rational'roots, p, q);\n  rational'roots := {};\n  If ((\"And\" @ (MapSingle(Hold({{x},IsInteger(Eval(x))}), MakeUni(expr, var)[3]))), [\n    ForEach (p, Solve'Poly'Divisors(ConstantTerm(expr, var))) [\n        ForEach (q, Solve'Poly'Divisors(LeadingCoef(expr, var))) [\n            If (Eval(Subst(var, p / q) expr) = 0, [\n                DestructiveAppend(rational'roots, p / q);\n                expr := NormalForm(Div(MakeUni(expr, var), MakeUni(var - p / q, var)));\n            ]);\n            If (Eval(Subst(var, -p / q) expr) = 0, [\n                DestructiveAppend(rational'roots, -p / q);\n                expr := NormalForm(Div(MakeUni(expr, var), MakeUni(var + p / q, var)));\n            ]);\n        ];\n    ];\n  ]);\n\n  rational'roots := MapSingle({{x}, var==x}, rational'roots);\n\n  If (Degree(expr, var) < 1, [\n      // all roots are rational, and we've already found them\n      rational'roots;\n  ], [\n      // there are some not yet found roots, pass to PSolve\n\n      // The call to PSolve can have three kind of results\n      //   1) PSolve returns a single root\n      //   2) PSolve returns a list of roots\n      //   3) PSolve remains unevaluated\n      //\n      Local(roots);\n      roots := PSolve(expr, var);\n      If(Type(roots) = \"PSolve\",\n        Failed,                              // Case 3\n        If(Type(roots) = \"List\",\n          Concat(rational'roots, MapSingle({{x},var==x}, roots)), // Case 2\n          Concat(rational'roots, {var == roots})));               // Case 1\n  ]);\n];\n\n/********** Solve'Reduce **********/\n\n/* Tries to solve by reduction strategy */\n/* Returns Failed if this doesn't work, and the solution otherwise */\n\n10 # Solve'Reduce(_expr, _var) <--\n[\n  Local(context, expr2, var2, res, sol, sol2, i);\n  context := Solve'Context(expr, var);\n  If(context = False,\n     res := Failed,\n     [\n       expr2 := Eval(Subst(context, var2) expr);\n       If(CanBeUni(var2, expr2) And (Degree(expr2, var2) < 1 Or (Degree(expr2, var2) = 1 And Coef(expr2, var2, 1) = 1)),\n          res := Failed, /* to prevent infinite recursion */\n          [\n            ClearError(\"Solve'Fails\");\n            sol2 := Solve(expr2, var2);\n        If(IsError(\"Solve'Fails\"),\n           [\n             ClearError(\"Solve'Fails\");\n         res := Failed;\n               ],\n               [\n             res := {};\n             i := 1;\n             While(i <= Length(sol2) And res != Failed) [\n               sol := Solve(context == (var2 Where sol2[i]), var);\n               If(IsError(\"Solve'Fails\"),\n              [\n                ClearError(\"Solve'Fails\");\n                res := Failed;\n                      ],\n                  res := Union(res, sol));\n               i++;\n             ];\n               ]);\n           ]);\n     ]);\n  res;\n];\n\n/********** Solve'Context **********/\n\n/* Returns the unique context of 'var' in 'expr', */\n/* or {} if 'var' does not occur in 'expr',       */\n/* or False if the context is not unique.         */\n\n10 # Solve'Context(expr_IsAtom, _var) <-- If(expr=var, var, {});\n\n20 # Solve'Context(_expr, _var) <--\n[\n  Local(lst, foundVarP, context, i, res);\n  lst := Listify(expr);\n  foundVarP := False;\n  i := 2;\n  While(i <= Length(lst) And Not foundVarP) [\n    foundVarP := (lst[i] = var);\n    i++;\n  ];\n  If(foundVarP,\n     context := expr,\n     [\n       context := {};\n       i := 2;\n       While(i <= Length(lst) And context != False) [\n         res := Solve'Context(lst[i], var);\n     If(res != {} And context != {} And res != context, context := False);\n     If(res != {} And context = {}, context := res);\n     i++;\n       ];\n     ]);\n  context;\n];\n\n/********** Solve'Simple **********/\n\n/* Simple solver of equations\n *\n * Returns (possibly empty) list of solutions,\n * or Failed if it cannot handle the equation\n *\n * Calling format: Solve'Simple(lhs, rhs, var)\n *                 to solve 'lhs == rhs'.\n *\n * Note: 'rhs' should not contain 'var'.\n */\n\n20 # Solve'Simple(_e1 + _e2, _rhs, _var)_(e1 = var And Not HasExpr(e2,var)) <-- { var == rhs-e2 };\n20 # Solve'Simple(_e1 + _e2, _rhs, _var)_(e2 = var And Not HasExpr(e1,var)) <-- { var == rhs-e1 };\n\n20 # Solve'Simple(_e1 - _e2, _rhs, _var)_(e1 = var And Not HasExpr(e2,var)) <-- { var == rhs+e2 };\n20 # Solve'Simple(_e1 - _e2, _rhs, _var)_(e2 = var And Not HasExpr(e1,var)) <-- { var == e1-rhs };\n20 # Solve'Simple(-(_e1), _rhs, _var)_(e1 = var) <-- { var == -rhs };\n\n20 # Solve'Simple(_e1 * _e2, _rhs, _var)_(e1 = var And Not HasExpr(e2,var)) <-- { var == rhs/e2 };\n20 # Solve'Simple(_e1 * _e2, _rhs, _var)_(e2 = var And Not HasExpr(e1,var)) <-- { var == rhs/e1 };\n\n20 # Solve'Simple(_e1 / _e2, _rhs, _var)_(e1 = var And Not HasExpr(e2,var)) <-- { var == rhs*e2 };\n10 # Solve'Simple(_e1 / _e2, 0,    _var)_(e2 = var And Not HasExpr(e1,var)) <-- { };\n20 # Solve'Simple(_e1 / _e2, _rhs, _var)_(e2 = var And Not HasExpr(e1,var)) <-- { var == e1/rhs };\n\nLocalSymbols(x)\n[\n  20 # Solve'Simple(_e1 ^ _n, _rhs, _var)_(e1 = var And IsPositiveInteger(n))\n       <-- MapSingle({{x}, var == rhs^(1/n)*x}, Exp(2*Pi*I*(1 .. n)/n));\n  20 # Solve'Simple(_e1 ^ _n, _rhs, _var)_(e1 = var And IsNegativeInteger(n))\n       <-- MapSingle({{x}, var == rhs^(1/n)*x}, Exp(2*Pi*I*(1 .. (-n))/(-n)));\n];\n\n20 # Solve'Simple(_e1 ^ _e2, _rhs, _var)\n     _ (IsPositiveReal(e1) And e1 != 0 And e2 = var And IsPositiveReal(rhs) And rhs != 0)\n     <-- { var == Ln(rhs)/Ln(e1) };\n\n/* Note: These rules do not take the periodicity of the trig. functions into account */\n10 # Solve'Simple(Sin(_e1), 1,    _var)_(e1 = var) <-- { var == 1/2*Pi };\n10 # Solve'Simple(Sin(_e1), _rhs, _var)_(e1 = var And rhs = -1) <-- { var == 3/2*Pi };\n20 # Solve'Simple(Sin(_e1), _rhs, _var)_(e1 = var) <-- { var == ArcSin(rhs), var == Pi-ArcSin(rhs) };\n10 # Solve'Simple(Cos(_e1), 1,    _var)_(e1 = var) <-- { var == 0 };\n10 # Solve'Simple(Cos(_e1), _rhs, _var)_(e1 = var And rhs = -1) <-- { var == Pi };\n20 # Solve'Simple(Cos(_e1), _rhs, _var)_(e1 = var) <-- { var == ArcCos(rhs), var == -ArcCos(rhs) };\n20 # Solve'Simple(Tan(_e1), _rhs, _var)_(e1 = var) <-- { var == ArcTan(rhs) };\n\n20 # Solve'Simple(ArcSin(_e1), _rhs, _var)_(e1 = var) <-- { var == Sin(rhs) };\n20 # Solve'Simple(ArcCos(_e1), _rhs, _var)_(e1 = var) <-- { var == Cos(rhs) };\n20 # Solve'Simple(ArcTan(_e1), _rhs, _var)_(e1 = var) <-- { var == Tan(rhs) };\n\n/* Note: Second rule neglects (2*I*Pi)-periodicity of Exp() */\n10 # Solve'Simple(Exp(_e1), 0,    _var)_(e1 = var) <-- { };\n20 # Solve'Simple(Exp(_e1), _rhs, _var)_(e1 = var) <-- { var == Ln(rhs) };\n20 # Solve'Simple(Ln(_e1),  _rhs, _var)_(e1 = var) <-- { var == Exp(rhs) };\n20 # Solve'Simple(_b^_e1, _rhs, _var)_(e1 = var And IsFreeOf(var,b) And Not IsZero(b)) <-- { var == Ln(rhs) / Ln(b) };\n\n/* The range of Sqrt is the set of (complex) numbers with either\n * positive real part, together with the pure imaginary numbers with\n * nonnegative real part. */\n20 # Solve'Simple(Sqrt(_e1), _rhs, _var)_(e1 = var And IsPositiveReal(Re(rhs)) And Re(rhs) != 0) <-- { var == rhs^2 };\n20 # Solve'Simple(Sqrt(_e1), _rhs, _var)_(e1 = var And Re(rhs)=0 And IsPositiveReal(Im(rhs))) <-- { var == rhs^2 };\n20 # Solve'Simple(Sqrt(_e1), _rhs, _var)_(e1 = var And Re(rhs)=0 And IsNegativeReal(Im(rhs)) And Im(rhs) != 0) <-- { };\n20 # Solve'Simple(Sqrt(_e1), _rhs, _var)_(e1 = var And IsNegativeReal(Re(rhs)) And Re(rhs) != 0) <-- { };\n\n30 # Solve'Simple(_lhs, _rhs, _var) <-- Failed;\n\n\n/********** Solve'Divide **********/\n/* For some classes of equations, it may be easier to solve them if we\n * divide through by their first term.  A simple example of this is the\n * equation  Sin(x)+Cos(x)==0\n * One problem with this is that we may lose roots if the thing we\n * are dividing by shares roots with the whole equation.\n * The final HasExprs are an attempt to prevent infinite recursion caused by\n * the final Simplify step in Solve undoing what we do here.  It's conceivable\n * though that this won't always work if the recurring loop is more than two\n * steps long.  I can't think of any ways this can happen though :)\n */\n\n10 # Solve'Divide(_e1 + _e2, _var)_(HasExpr(e1, var) And HasExpr(e2, var)\n        And Not (HasExpr(Simplify(1 + (e2/e1)), e1)\n              Or HasExpr(Simplify(1 + (e2/e1)), e2)))\n                                           <-- Solve(1 + (e2/e1), var);\n10 # Solve'Divide(_e1 - _e2, _var)_(HasExpr(e1, var) And HasExpr(e2, var)\n        And Not (HasExpr(Simplify(1 - (e2/e1)), e1)\n              Or HasExpr(Simplify(1 - (e2/e1)), e2)))\n                                           <-- Solve(1 - (e2/e1), var);\n\n20 # Solve'Divide(_e, _v) <-- Failed;\n\n\n/********** Solve'System **********/\n\nSolve'System(_eqns, _vars) <-- [\n    Local(rules, e, ee, linear, A, b);\n\n    ee := (eqns /:: { _lhs == _rhs <- lhs - rhs });\n\n    linear := True;\n\n    b := {};\n    A := {};\n\n    ForEach (e, ee) [\n        Local(m, homogenous, Arow);\n\n        Arow := ZeroVector(Length(vars));\n\n        m := MM(e, vars);\n        homogenous := True;\n\n        While (linear And m[2] != {}) [\n            Local(mld, mlc);\n            mld := MultiDegree(m);\n            mlc := MultiLeadingCoef(m);\n\n            If (IsZeroVector(mld), [\n                DestructiveAppend(b, -mlc);\n                homogenous := False;\n            ], [\n                If (Min(mld) = 0 And Max(mld) = 1 And Add(mld) = 1, [\n                    Arow[Find(mld, 1)] := mlc;\n                ], [\n                    linear := False;\n                ]);\n            ]);\n\n            m := MultiDropLeadingZeroes(MultiNomialAdd(m, MultiNomialNegate(MultiLT(m))));\n        ];\n\n        If (homogenous, DestructiveAppend(b, 0));\n\n        DestructiveAppend(A, Arow);\n    ];\n\n    If (linear, [\n        Local(r, e);\n        r := {};\n        ForEach(e, Transpose({vars, MatrixSolve(A, b)})) [\n            DestructiveAppend(r, e[1] == e[2]);\n        ];\n        {r};\n    ], [\n        Local(polynomial);\n        polynomial := True;\n        ForEach (e, ee) [\n            Local(m);\n\n            Arow := ZeroVector(Length(vars));\n\n            m := MM(e, vars);\n\n            While (polynomial And m[2] != {}) [\n                Local(mld, mlc);\n                mld := MultiDegree(m);\n                mlc := MultiLeadingCoef(m);\n\n                polynomial := Min(mld) >= 0 And IsRationalOrNumber(mlc);\n\n                m := MultiDropLeadingZeroes(MultiNomialAdd(m, MultiNomialNegate(MultiLT(m))));\n            ];\n        ];\n\n        If (polynomial, [\n            Local(g, g1, i, j, x1, solutions, s, roots, r, solutions'final);\n            ee := Groebner(ee);\n            ForEach (i, 1 .. Length(ee))\n                ee[i] := MM(ee[i]);\n\n            g := FillList({}, Max(Lambda({x1},Length(MultiVars(x1))) /@ ee));\n\n            ForEach (e, ee)\n                DestructiveAppend(g[Length(MultiVars(e))], e);\n\n            ForEach (e, g)\n                Check(Length(e) >= 1, \"Wrong Groebner basis\");\n\n            solutions := {};\n\n            g1 := Head(g);\n\n            Until (g1 = {}) [\n                x1 := Head(MultiVars(Head(g1)));\n                roots := PSolve(NormalForm(Head(g1)), x1);\n                roots := If (Type(roots) = \"List\", RemoveDuplicates(roots), {roots});\n                ForEach (r, roots)\n                    DestructiveAppend(solutions, {{x1}, {r}});\n\n                g1 := Tail(g1);\n            ];\n\n            For (i := 2, i <= Length(g), i++) [\n                Local(solutions'new);\n                solutions'new := {};\n                ForEach (s, solutions) [\n                    Local(found, gij, gij'nf, gij'vars);\n                    found := {};\n                    For (j := 1, j <= Length(g[i]), j++) [\n                        gij := g[i][j];\n                        gij'nf := NormalForm(gij);\n                        gij'vars := MultiVars(gij);\n                        If (Length(Difference(gij'vars, s[1])) = 1, [\n                            Local(gij'unknown);\n                            gij'unknown := Head(Difference(gij'vars, s[1]));\n                            If (Not Contains(found, gij'unknown), [\n                                Local(gij'lc);\n                                gij'lc := LeadingCoef(gij'nf, gij'unknown);\n                                If (WithValue(s[1], s[2], gij'lc) != 0,  [\n                                    roots := PSolve(WithValue(s[1], s[2], gij'nf), gij'unknown);\n                                    roots := If (Type(roots) = \"List\", RemoveDuplicates(roots), {roots});\n                                    ForEach(r, roots)\n                                        DestructiveAppend(solutions'new, {Append(s[1], gij'unknown), Append(s[2], r)});\n                                    DestructiveAppend(found, gij'unknown);\n                                ]);\n                            ]);\n                        ]);\n                    ];\n                    solutions := solutions'new;\n                ];\n            ];\n\n            solutions'final := {};\n            ForEach (s, solutions) [\n                Local(ok);\n                ok := True;\n                For (i := 1, i <= Length(g) And ok, i++)\n                    For (j := 1, j <= Length(g[i]) And ok, j++)\n                        ok := WithValue(s[1], s[2], NormalForm(g[i][j])) = 0;\n                If (ok, DestructiveAppend(solutions'final, s));\n            ];\n            solutions := solutions'final;\n            solutions'final := {};\n            ForEach (s, solutions) [\n                t := {};\n                ForEach (v, vars)\n                    DestructiveAppend(t, v == s[2][Find(s[1], v)]);\n                DestructiveAppend(solutions'final, t);\n            ];\n            RemoveDuplicates(solutions'final);\n        ], [\n            // for anything else, just try to use a simple backsubstitution scheme\n            Solve'SimpleBackSubstitution(eqns,vars);\n        ]);\n    ]);\n];\n\n10 # Solve'SimpleBackSubstitution'FindAlternativeForms((_lx) == (_rx)) <--\n[\n  Local(newEq);\n  newEq := (Simplify(lx) == Simplify(rx));\n  If (newEq != (lx == rx) And newEq != (0==0),DestructiveAppend(eq,newEq));\n  newEq := (Simplify(lx - rx) == 0);\n  If (newEq != (lx == rx) And newEq != (0==0),DestructiveAppend(eq,newEq));\n];\n20 # Solve'SimpleBackSubstitution'FindAlternativeForms(_equation) <--\n[\n];\nUnFence(\"Solve'SimpleBackSubstitution'FindAlternativeForms\",1);\n\n/* Solving sets of equations using simple backsubstitution.\n * Solve'SimpleBackSubstitution takes all combinations of equations and\n * variables to solve for, and it then uses SuchThat to find an expression\n * for this variable, and then if found backsubstitutes it in the other\n * equations in the hope that they become simpler, resulting in a final\n * set of solutions.\n */\n10 # Solve'SimpleBackSubstitution(eq_IsList,var_IsList) <--\n[\n If(InVerboseMode(), Echo({\"Entering Solve'SimpleBackSubstitution\"}));\n\n  Local(result,i,j,nrvar,nreq,sub,nrSet,origEq);\n  eq:=FlatCopy(eq);\n  origEq:=FlatCopy(eq);\n  nrvar:=Length(var);\n  result:={FlatCopy(var)};\n  nrSet := 0;\n\n//Echo(\"Before: \",eq);\n  ForEach(equation,origEq)\n  [\n//Echo(\"equation \",equation);\n    Solve'SimpleBackSubstitution'FindAlternativeForms(equation);\n  ];\n//  eq:=Simplify(eq);\n//Echo(\"After: \",eq);\n\n  nreq:=Length(eq);\n\n  /* Loop over each variable, solving for it */\n\n/* Echo({eq});  */\n\n  For(j:=1,j<=nreq And nrSet < nrvar,j++)\n  [\n    Local(vlist);\n    vlist:=VarListAll(eq[j],`Lambda({pt},Contains(@var,pt)));\n    For(i:=1,i<=nrvar And nrSet < nrvar,i++)\n    [\n\n//Echo(\"eq[\",j,\"] = \",eq[j]);\n//Echo(\"var[\",i,\"] = \",var[i]);\n//Echo(\"varlist = \",vlist);\n//Echo();\n\n      If(Count(vlist,var[i]) = 1,\n         [\n           sub := Listify(eq[j]);\n           sub := sub[2]-sub[3];\n//Echo(\"using \",sub);\n           sub:=SuchThat(sub,var[i]);\n           If(InVerboseMode(), Echo({\"From \",eq[j],\" it follows that \",var[i],\" = \",sub}));\n           If(SolveFullSimplify=True,\n             result:=Simplify(Subst(var[i],sub)result),\n             result[1][i]:=sub\n             );\n//Echo(\"result = \",result,\" i = \",i);\n           nrSet++;\n\n//Echo(\"current result is \",result);\n           Local(k,reset);\n           reset:=False;\n           For(k:=1,k<=nreq  And nrSet < nrvar,k++)\n           If(Contains(VarListAll(eq[k],`Lambda({pt},Contains(@var,pt))),var[i]),\n           [\n             Local(original);\n             original:=eq[k];\n             eq[k]:=Subst(var[i],sub)eq[k];\n             If(Simplify(Simplify(eq[k])) = (0 == 0),\n               eq[k] := (0 == 0),\n               Solve'SimpleBackSubstitution'FindAlternativeForms(eq[k])\n               );\n//             eq[k]:=Simplify(eq[k]);\n//             eq[k]:=Simplify(eq[k]); //@@@??? TODO I found one example where simplifying twice gives a different result from simplifying once!\n             If(original!=(0==0) And eq[k] = (0 == 0),reset:=True);\n             If(InVerboseMode(), Echo({\"   \",original,\" simplifies to \",eq[k]}));\n           ]);\n           nreq:=Length(eq);\n           vlist:=VarListAll(eq[j],`Lambda({pt},Contains(@var,pt)));\n           i:=nrvar+1;\n           // restart at the beginning of the variables.\n           If(reset,j:=1);\n         ]);\n    ];\n  ];\n\n\n//Echo(\"Finished finding results \",var,\" = \",result);\n//  eq:=origEq;\n//  nreq := Length(eq);\n  Local(zeroeq,tested);\n  tested:={};\n//  zeroeq:=FillList(0==0,nreq);\n\n  ForEach(item,result)\n  [\n/*\n    Local(eqSimplified);\n    eqSimplified := eq;\n    ForEach(map,Transpose({var,item}))\n    [\n      eqSimplified := Subst(map[1],map[2])eqSimplified;\n    ];\n    eqSimplified := Simplify(Simplify(eqSimplified));\n\n    Echo(eqSimplified);\n\n    If(eqSimplified = zeroeq,\n    [\n      DestructiveAppend(tested,Map(\"==\",{var,item}));\n    ]);\n*/\n    DestructiveAppend(tested,Map(\"==\",{var,item}));\n  ];\n\n\n\n/* Echo({\"tested is \",tested});  */\n If(InVerboseMode(), Echo({\"Leaving Solve'SimpleBackSubstitution\"}));\n  tested;\n];\n\n\n\n\n/********** OldSolve **********/\n10 # OldSolve(eq_IsList,var_IsList) <-- Solve'SimpleBackSubstitution(eq,var);\n\n\n90 # OldSolve((left_IsList) == right_IsList,_var) <--\n      OldSolve(Map(\"==\",{left,right}),var);\n\n\n100 # OldSolve(_left == _right,_var) <--\n     SuchThat(left - right , 0 , var);\n\n/* HoldArg(\"OldSolve\",arg1); */\n/* HoldArg(\"OldSolve\",arg2); */\n\n\n10 # ContainsExpression(_body,_body) <-- True;\n15 # ContainsExpression(body_IsAtom,_expr) <-- False;\n20 # ContainsExpression(body_IsFunction,_expr) <--\n[\n  Local(result,args);\n  result:=False;\n  args:=Tail(Listify(body));\n  While(args != {})\n  [\n    result:=ContainsExpression(Head(args),expr);\n    args:=Tail(args);\n    if (result = True) (args:={});\n  ];\n  result;\n];\n\n\nSuchThat(_function,_var) <-- SuchThat(function,0,var);\n\n10 # SuchThat(_left,_right,_var)_(left = var) <-- right;\n\n/*This interferes a little with the multi-equation solver...\n15 # SuchThat(_left,_right,_var)_CanBeUni(var,left-right) <--\n     PSolve(MakeUni(left-right,var));\n*/\n\n20 # SuchThat(left_IsAtom,_right,_var) <-- var;\n\n30 # SuchThat((_x) + (_y),_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , right-y , var);\n30 # SuchThat((_y) + (_x),_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , right-y , var);\n\n30 # SuchThat(Complex(_r,_i),_right,_var)_ContainsExpression(r,var) <--\n    SuchThat(r , right-I*i , var);\n30 # SuchThat(Complex(_r,_i),_right,_var)_ContainsExpression(i,var) <--\n    SuchThat(i , right+I*r , var);\n\n30 # SuchThat(_x * _y,_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , right/y , var);\n30 # SuchThat(_y * _x,_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , right/y , var);\n\n30 # SuchThat(_x ^ _y,_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , right^(1/y) , var);\n30 # SuchThat(_x ^ _y,_right,_var)_ContainsExpression(y,var) <--\n    SuchThat(y , Ln(right)/Ln(x) , var);\n\n30 # SuchThat(Sin(_x),_right,_var) <--\n    SuchThat(x , ArcSin(right) , var);\n30 # SuchThat(ArcSin(_x),_right,_var) <--\n    SuchThat(x , Sin(right) , var);\n\n30 # SuchThat(Cos(_x),_right,_var) <--\n    SuchThat(x , ArcCos(right) , var);\n30 # SuchThat(ArcCos(_x),_right,_var) <--\n    SuchThat(x , Cos(right) , var);\n\n30 # SuchThat(Tan(_x),_right,_var) <--\n    SuchThat(x , ArcTan(right) , var);\n30 # SuchThat(ArcTan(_x),_right,_var) <--\n    SuchThat(x , Tan(right) , var);\n\n30 # SuchThat(Exp(_x),_right,_var) <--\n    SuchThat(x , Ln(right) , var);\n30 # SuchThat(Ln(_x),_right,_var) <--\n    SuchThat(x , Exp(right) , var);\n\n30 # SuchThat(_x / _y,_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , right*y , var);\n30 # SuchThat(_y / _x,_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , y/right , var);\n\n30 # SuchThat(- (_x),_right,_var) <--\n    SuchThat(x , -right , var);\n\n30 # SuchThat((_x) - (_y),_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , right+y , var);\n30 # SuchThat((_y) - (_x),_right,_var)_ContainsExpression(x,var) <--\n    SuchThat(x , y-right , var);\n\n30 # SuchThat(Sqrt(_x),_right,_var) <--\n    SuchThat(x , right^2 , var);\n\n\nFunction(\"SolveMatrix\",{matrix,vector})\n[\n    Local(perms,indices,inv,det,n);\n    n:=Length(matrix);\n    indices:=Table(i,i,1,n,1);\n    perms:=Permutations(indices);\n    inv:=ZeroVector(n);\n    det:=0;\n    ForEach(item,perms) [\n        Local(i,lc);\n        lc := LeviCivita(item);\n        det:=det+Product(i,1,n,matrix[i][item[i] ])* lc;\n        For(i:=1,i<=n,i++) [\n            Local(j, t);\n            t := 1;\n            For (j := 1, j <= Length(matrix), j++)\n                t := t * If(item[j] = i,vector[j],matrix[j][item[j]]);\n            inv[i] := inv[i] + t * lc;\n        ];\n    ];\n    Check(det != 0, \"Zero determinant\");\n    (1/det)*inv;\n];\n\n\n\nFunction(\"Newton\",{function,variable,initial,accuracy})\n[   // since we call a function with HoldArg(), we need to evaluate some variables by hand\n  `Newton(@function,@variable,initial,accuracy,-Infinity,Infinity);\n];\n\nFunction(\"Newton\",{function,variable,initial,accuracy,min,max})\n[\n  Local(result,adjust,delta,requiredPrec);\n  MacroLocal(variable);\n  requiredPrec := Builtin'Precision'Get();\n  accuracy:=N((accuracy/10)*10); // Making sure accuracy is rounded correctly\n  Builtin'Precision'Set(requiredPrec+2);\n  function:=N(function);\n  adjust:= -function/Apply(\"D\",{variable,function});\n  delta:=10000;\n  result:=initial;\n  While (result > min And result < max\n      // avoid numerical underflow due to fixed point math, FIXME when have real floating math\n      And N(Eval( Max(Re(delta), -Re(delta), Im(delta), -Im(delta)) ) ) > accuracy)\n  [\n    MacroSet(variable,result);\n    delta:=N(Eval(adjust));\n    result:=result+delta;\n  ];\n\n  Builtin'Precision'Set(requiredPrec);\n  result:=N(Eval((result/10)*10)); // making sure result is rounded to correct precision\n  if (result <= min Or result >= max) [result := Fail;];\n  result;\n];\n\n\n"
  },
  {
    "path": "scripts/solve.rep/code.ys.def",
    "content": "Solve\nOldSolve\nSuchThat\nNewton\nSolveMatrix\n}\n"
  },
  {
    "path": "scripts/solve.rep/om.ys",
    "content": "OMDef( \"Solve\"   , \"yacas\",\"Solve\"    );\n"
  },
  {
    "path": "scripts/specfunc.rep/bernou.ys",
    "content": "/// Simple implementation of the recurrence relation: create an array of Bernoulli numbers\n// special cases: n=0 or n=1\n10 # Internal'BernoulliArray(n_IsInteger)_(n=0 Or n=1) <-- [\n\tLocal(B);\n\tB:=Array'Create(n+1,0);\n\tB[1] := 1;\n\tIf(n=1, B[2] := -1/2);\n\tB;\n];\n/// Assume n>=2\n20 # Internal'BernoulliArray(n_IsInteger) <-- [\n\tLocal(B, i, k, k2, bin);\n\tIf (InVerboseMode(), Echo({\"Internal'BernoulliArray: using direct recursion, n = \", n}));\n\tB:=Array'Create(n+1, 0);\t// array of B[k], k=1,2,... where B[1] is the 0th Bernoulli number\n\t// it would be better not to store the odd elements but let's optimize this later\n\t// we could also maintain a global cache of Bernoulli numbers computed so far, but it won't really speed up things at large n\n\t// all odd elements after B[2] are zero\n\tB[1] := 1;\n\tB[2] := -1/2;\n\tB[3] := 1/6;\n\tFor(i:=4, i<=n, i := i+2)\t// compute and store B[i]\n\t[\t// maintain binomial coefficient\n\t\tbin := 1;\t// Bin(i+1,0)\n\t\t// do not sum over odd elements that are zero anyway - cuts time in half\n\t\tB[i+1] := 1/2-1/(i+1)*(1 + Sum(k, 1, i/2-1,\n\t\t\t[\n\t\t\t\tbin := bin * (i+3-2*k) * (i+2-2*k)/ (2*k-1) / (2*k);\n\t\t\t\tB[2*k+1]*bin;\t// *Bin(i+1, 2*k)\n\t\t\t]\n\t\t) );\n\t];\n\tB;\n];\n\n/// Find the fractional part of Bernoulli number with even index >=2\n/// return negative if the sign of the Bernoulli number is negative\nBernoulliFracPart(n_IsEven)_(n>=2) <-- [\n\tLocal(p, sum);\n\t// always 2 and 3\n\tsum := 1/2+1/3;\n\t// check whether n+1 and n/2+1 are prime\n\tIf(IsPrime(n+1), sum := sum+1/(n+1));\n\tIf(IsPrime(n/2+1), sum := sum+1/(n/2+1));\n\t// sum over all primes p such that n / p-1 is integer\n\t// enough to check up to n/3 now\n\tFor(p:=5, p<=n/3+1, p:=NextPrime(p))\n\t\tIf(Mod(n, p-1)=0, sum := sum + 1/p);\n\t// for negative Bernoulli numbers, let's change sign\n\t// Mod(n/2, 2) is 0 for negative Bernoulli numbers and 1 for positive ones\n\tDiv(Numer(sum), Denom(sum)) - sum\n\t\t + Mod(n/2,2);\t// we'll return a negative number if the Bernoulli itself is negative -- slightly against our definitions in the manual\n\t\t//+ 1;\t// this would be exactly like the manual says\n];\n\n/// Find one Bernoulli number for large index\n/// compute Riemann's zeta function and combine with the fractional part\nBernoulli1(n_IsEven)_(n>=2) <-- [\n\tLocal(B, prec);\n\tprec := Builtin'Precision'Get();\n\t// estimate the size of B[n] using Stirling formula\n\t// and compute Ln(B[n])/Ln(10) to find the number of digits\n\tBuiltin'Precision'Set(10);\n\tBuiltin'Precision'Set(\n\t\tCeil(N((1/2*Ln(8*Pi*n)-n+n*Ln(n/2/Pi))/Ln(10)))+3\t// 3 guard digits\n\t);\n\tIf (InVerboseMode(), Echo({\"Bernoulli: using zeta funcion, precision \", Builtin'Precision'Set(), \", n = \", n}));\n\tB := Floor(N(\t// compute integer part of B\n\t\tIf(\t// use different methods to compute Zeta function\n\t\t\tn>250,\t// threshold is roughly right for internal math\n\t\t\tInternal'ZetaNum2(n, n/17+1),\t// with this method, a single Bernoulli number n is computed in O(n*M(P)) operations where P = O(n*Ln(n)) is the required precision\n\t\t\t// Brent's method requires n^2*P+n*M(P)\n\t\t\t// simple array method requires \n\t\t\tInternal'ZetaNum1(n, n/17+1)\t// this gives O(n*Ln(n)*M(P))\n\t\t)\n\t\t*N(2*n! /(2*Pi)^n)))\n\t\t// 2*Pi*e is approx. 17, add 1 to guard precision\n\t\t* (2*Mod(n/2,2)-1)\t// sign of B\n\t\t+ BernoulliFracPart(n);\t// this already has the right sign\n\tBuiltin'Precision'Set(prec);\t// restore old precision\n\tB;\n];\n\n/// Bernoulli numbers; algorithm from: R. P. Brent, \"A FORTRAN multiple-precision arithmetic package\", ACM TOMS vol. 4, no. 1, p. 57 (1978).\n/// this may be good for floating-point (not exact) evaluation of B[n] at large n\n/// but is not good at all for exact evaluation! (too slow)\n/// Brent claims that the usual recurrence is numerically unstable\n/// but we can't check this because Yacas internal math is fixed-point and Brent's algorithm needs real floating point (C[k] are very small and then multiplied by (2*k)! )\nInternal'BernoulliArray1(n_IsEven) _ (n>=2) <--\n[\n\tLocal(C, f, k, j, denom, sum);\n\tC := Array'Create(n+1, 0);\n\tf := Array'Create(n/2, 0);\n\tC[1] := 1;\n\tC[2] := -1/2;\n\tC[3] := 1/12;\t// C[2*k+1] = B[2*k]/(2*k)!\n\tf[1] := 2;\t// f[k] = (2k)!\n\tFor(k:=2, k<=n/2, k++)\t// we could start with k=1 but it would be awkward to compute f[] recursively\n\t[\n\t\t// compute f[k]\n\t\tf[k] := f[k-1] * (2*k)*(2*k-1);\n\t\t// compute C[k]\n\t\tC[2*k+1] := 1/(1-4^(-k))/2*(\n\t\t\t[\n\t\t\t\tdenom := 4;\t// = 4^1\n\t\t\t\tsum := 0;\n\t\t\t\tFor(j:=1, j<k, j++)\n\t\t\t\t[\n\t\t\t\t\tsum := sum + C[2*(k-j)+1]/denom/f[j];\t// + C[k-j]/(2*j)! /4^j\n\t\t\t\t\tdenom := denom * 4;\n\t\t\t\t];\n\t\t\t\t(2*k-1)/denom/f[k] - sum;\n\t\t\t]\n\t\t);\n//\tEcho({n, k, denom, C[k]});\n\t];\n\t// multiply C's with factorials to get B's\n\tFor(k:=1, k<=n/2, k++)\n\t\tC[2*k+1] := C[2*k+1] * f[k];\n\t// return array object\n\tC;\n];\n"
  },
  {
    "path": "scripts/specfunc.rep/bernou.ys.def",
    "content": "BernoulliFracPart\nBernoulli1\nInternal'BernoulliArray\nInternal'BernoulliArray1\n}\n"
  },
  {
    "path": "scripts/specfunc.rep/bessel.ys",
    "content": "/// coded by Jonathan Leto\n\n// When x is <= 1, the series is monotonely decreasing from the\n// start, so we don't have to worry about loss of precision from the\n// series definition. \n// When {n} is an integer, this is fast.\n// When {n} is not, it is pretty slow due to Gamma() \n\nFunction(\"BesselNsmall\",{n,x,modified})\n[\n        Local(term,result,k);\n        Local(prec,eps,tmp);\n        prec:=Builtin'Precision'Get();\n        Builtin'Precision'Set(Ceil(1.2*prec)); // this is a guess\n        eps:=5*10^(-prec);\n\n        term:=1;\n        k:=0;\n        result:=0;\n        While( Abs(term) >= eps )[\n                term:=x^(2*k+n);\n\t\t// The only difference between BesselJ and BesselI\n\t\t// is an alternating term\n\t\tIf( k%2=1 And modified=0 , term:=term*-1 );\n\t\tterm:=N(term/(2^(2*k+n)* k! * Gamma(k+n+1) ));\n                //Echo({\"term is \",term});\n                result:=result+term;\n                k:=k+1;\n        ];\n        Builtin'Precision'Set(prec);\n\t// This should not round, only truncate\n\t// some outputs will be off by one in the last digit\n\tRoundTo(result,prec);\n\n];\n\n// Seems to get about 8 digits precision for most real numbers\n// Only about 2 digits precision for complex\n// This is just a temporary implementation, I would not want to\n// expose users to it until it is much more robust\n// I am still looking for a good arbitrary precision algorithm.\nFunction(\"BesselJN0\",{x})\n[\n\tLocal(ax,z,xx,y,result,res1,res2);\n\tLocal(c1,c2,c3,c4);\n\n\t// Coefficients of the rational polynomials to\n\t// approx J_0  for x < 8\n\tc1:={57568490574.0,-13362590354.0,651619640.7,\n\t\t-11214424.18,77392.33017,-184.9052456};\n\tc2:={57568490411.0,1029532985.0,9494680.718,\n\t\t59272.64853,267.8532712};\n\t// Coefficients of the rational polynomials to\n\t// approx J_0 for x >= 8\n\tc3:={-0.001098628627,0.00002734510407,-0.000002073370639,\n\t\t0.0000002093887211};\n\tc4:={-0.01562499995,0.0001430488765,-0.000006911147651,\n\t\t0.0000007621095161,0.0000000934935152};\n\tax:=Abs(x);\n\t\n\tIf( ax < 8.0,[ \n\t\ty:=x^2;\n\t\tres1:=c1[1]+y*(c1[2]+y*c1[3]+y*(c1[4]+y*(c1[5]+y*(c1[6]))));\n\t\tres2:=c1[1]+y*(c2[2]+y*c2[3]+y*(c2[4]+y*(c2[5]+y*1.0)));\n\t\tresult:=res1/res2;\n\t],[\n\t\tz:=8/ax;\n\t\ty:=z^2;\n\t\txx:=ax-0.785398164;\t\t\n\t\tres1:=1.0+y*(c3[1]+y*(c3[2]+y*(c3[3]+y*c4[4])));\n\t\tres2:=c4[1]+y*(c4[2]+y*(c4[3]+y*(c4[4]-y*c4[5])));\n\t\tresult:=Sqrt(2/(Pi*x))*(Cos(xx)*res1-z*Sin(xx)*res2);\n\t] );\n];\n"
  },
  {
    "path": "scripts/specfunc.rep/bessel.ys.def",
    "content": "BesselNsmall\nBesselJN\nBesselJN0\n}\n"
  },
  {
    "path": "scripts/specfunc.rep/code.ys",
    "content": "/// special functions coded for Yacas by Serge Winitzki: Gamma, Zeta, Bernoulli, LambertW\n\n/// coded by Jonathan Leto: PolyLog, Dirichlet*, Digamma, Bessel*, Erf*, Fresnel*, Beta,\n///\t\t\t    CatalanConstNum, Sinc, Beta, DawsonIntegral\n\n/////////////////////////////////////////////////\n/// Euler's Gamma function\n/////////////////////////////////////////////////\n\n/// User visible functions: Gamma(x), LnGamma(x)\n\n5 # Gamma(Infinity)\t<-- Infinity;\n\n10 # Gamma(_n)_(IsInteger(n) And n<=0) <-- Infinity;\n10 # LnGamma(_n)_(IsInteger(n) And n<=0) <-- Infinity;\n\n20 # Gamma(n_IsRationalOrNumber)_(IsPositiveInteger(n) Or FloatIsInt(2*n)) <-- (Round(2*n)/2-1)!;\n20 # LnGamma(n_IsRationalOrNumber)_(IsPositiveInteger(n) Or FloatIsInt(2*n)) <-- Ln((Round(2*n)/2-1)!);\n\n30 # Gamma(x_IsConstant)_(InNumericMode()) <-- Internal'GammaNum(N(Eval(x)));\n30 # LnGamma(x_IsConstant)_(InNumericMode()) <-- Internal'LnGammaNum(N(Eval(x)));\n\n5 # PolyGamma(0, Infinity) <-- Infinity;\n\n/////////////////////////////////////////////////\n/// Riemann's Zeta function\n/////////////////////////////////////////////////\n\n/// identities for exact values of Zeta\n\n10 # Zeta(1) <-- Infinity;\n10 # Zeta(0) <-- -1/2;\t// let's save time\n10 # Zeta(3)_InNumericMode() <-- Zeta3();\t// special case\n10 # Zeta(n_IsEven)_(n>0) <-- Pi^n*(2^(n-1)/n! *Abs(Bernoulli(n)));\n10 # Zeta(n_IsInteger)_(n<0) <-- -Bernoulli(-n+1)/(-n+1);\n11 # Zeta(n_IsInfinity) <-- 1;\n\n/// compute numeric value\n20 # Zeta(s_IsConstant)_(InNumericMode()) <-- Internal'ZetaNum(N(Eval(s)));\n\n/////////////////////////////////////////////////\n/// Bernoulli numbers and polynomials\n/////////////////////////////////////////////////\n\n/// Bernoulli(n): interface to Bernoulli numbers\n10 # Bernoulli(0) <-- 1;\n10 # Bernoulli(1) <-- -1/2;\n15 # Bernoulli(n_IsInteger)_(n<0) <-- Undefined;\n30 # Bernoulli(n_IsOdd) <-- 0;\n\n/// numerical computations of Bernulli numbers use two different methods, one good for small numbers and one good only for very large numbers (using Zeta function)\n20 # Bernoulli(n_IsEven)_(n<=Bernoulli1Threshold()) <-- Internal'BernoulliArray(n)[n+1];\n20 # Bernoulli(n_IsEven)_(n>Bernoulli1Threshold()) <-- Bernoulli1(n);\n\nLocalSymbols(bernoulli1Threshold) [\n  /// Bernoulli1Threshold could in principle be set by the user\n  If(Not IsBound(bernoulli1Threshold), bernoulli1Threshold := 20);\n\n  Bernoulli1Threshold() := bernoulli1Threshold;\n  SetBernoulli1Threshold(threshold) := [ bernoulli1Threshold := threshold;];\n\n] ; // LocalSymbols(bernoulli1Threshold)\n\n/// Bernoulli polynomials of degree n in variable x\nBernoulli(n_IsInteger, _x) <-- [\n\tLocal(B, i, result);\n\tB := Internal'BernoulliArray(n);\n\tresult := B[1];\n\tFor(i:=n-1, i>=0, i--) [\n\t\tresult := result * x + B[n-i+1]*Bin(n,i);\n\t];\n\tresult;\n];\n\n/////////////////////////////////////////////////\n/// Bessel and related functions\n/////////////////////////////////////////////////\n\n10 # BesselJ(0,0) \t<-- 1;\n10 # BesselI(0,0)\t<-- 1;\n10 # BesselJ(_n,0)_(n>0) <-- 0;\n10 # BesselI(_n,0)_(n>0) <-- 0;\n10 # BesselJ(_n,0)_(n<0 And IsInteger(n)) <-- 0;\n10 # BesselI(_n,0)_(n<0 And IsInteger(n)) <-- 0;\n10 # BesselJ(_n,0)_(n<0 And Not IsInteger(n)) <-- Infinity;\n\n// The following should be ComplexInfinity, if/when that is implemented\n10 # BesselI(_n,0)_(n<0 And Not IsInteger(n)) <-- Infinity;\n\n10 # BesselJ(0,Infinity)<-- 0;\n20 # BesselJ(1/2,_x)\t<-- Sqrt(2/(x*Pi))*Sin(x);\n20 # BesselI(1/2,_x)\t<-- Sqrt(2/(x*Pi))*Sinh(x);\n20 # BesselJ(-1/2,_x)\t<-- Sqrt(2/(x*Pi))*Cos(x);\n20 # BesselJ(3/2,_x)\t<-- Sqrt(2/(x*Pi))*(Sin(x)/x - Cos(x));\n\n20 # BesselI(3/2,_x)    <-- Sqrt(2/(x*Pi))*(Cosh(x) - Sinh(x)/x);\n\n20 # BesselJ(-3/2,_x)\t<-- Sqrt(2/(x*Pi))*(Cos(x)/x + Sin(x));\n\n20 # BesselJ(5/2,_x)\t<-- Sqrt(2/(x*Pi))*((3/x^2 - 1)*Sin(x) - 3*Cos(x)/x );\n20 # BesselI(5/2,_x)    <-- Sqrt(2/(x*Pi))*((3/x^2 + 1)*Sinh(x) - 3*Cosh(x)/x );\n\n20 # BesselJ(-5/2,_x)      <-- Sqrt(2/(x*Pi))*( (3/x^2 -1)*Cos(x) + 3*Sin(x)/x );\n\n\n// Forward recursion, works great, but really slow when n << x\n30 # BesselJ(_n,_x)_(IsConstant(x) And IsInteger(n) And N(Abs(x) > 2*Gamma(n))) <-- N((2*(n+1)/x)*BesselJ(n+1,x) - BesselJ(n+2,x));\n\n30 # BesselJ(_n,_z)_(n<0 And IsInteger(n) ) <-- (-1)^n*BesselJ(-n,z);\n30 # BesselI(_n,_z)_(n<0 And IsInteger(n) ) <-- BesselI(-n,z);\n\n\n// When I put \"And InNumericMode()\" on the next rule, I lose precision. Why ?\n// Also, if I move the the \"_IsComplex\" to the end with \"IsComplex(x)\" \n// I lose precision.\n\n//40 # BesselJ(_n,x_IsComplex)_(Abs(x)<= 2*Gamma(n) )  <-- N(BesselNsmall(n,x,0));\n//40 # BesselI(_n,x_IsComplex)_(Abs(x)<= 2*Gamma(n) )  <-- N(BesselNsmall(n,x,1));\n40 # BesselJ(_n,x_IsComplex)_(N(Abs(x)<= 2*Gamma(n)) )  <-- \n[\nApproxInfSum((-1)^k*(x/2)^(2*k+c[1])/(k! * Gamma(k+c[1]+1) ),0,x,{n} );\n];\n\n40 # BesselI(_n,x_IsComplex)_(IsConstant(x) And Abs(x)<= 2*Gamma(n) )  <--\n[\nApproxInfSum((x/2)^(2*k+c[1])/(k! * Gamma(k+c[1]+1) ),0,x,{n} );\n];\n\n\n// This is buggy\n40 # BesselY(_n,x_IsComplex)_(Abs(x)<= 2*Gamma(n) )  <-- N((Cos(n*Pi)*BesselJ(n,x) - BesselJ(-n,x))/Sin(Pi*n));\n\n50 # BesselJ(0,x_IsComplex)_(InNumericMode()) <-- N(BesselJN0(x));\n\n//50 # BesselJ(_n_IsPositiveNumber,_z_IsComplex) <-- BesselJN(n,z);\n\n\n// Ex:\n// Bessel of order n:\n// ApproxInfSum((-1)^k*(x/2)^(2*k+c[1])/(k! * Gamma(k+c[1]+1) ),1,x,{n} );\n\nFunction(\"ApproxInfSum\",{expr,start,x})[\n\tApproxInfSum(expr,start,x,{0});\n];\n\n/// FIXME this has a roundoff problem when InNumericMode()=True\n// Summation must be on k\nFunction(\"ApproxInfSum\",{expr,start,x,c})\n[\n        Local(term,result,k);\n        Local(prec,eps,tmp);\n        prec:=Builtin'Precision'Get();\n//        Builtin'Precision'Set(Ceil(1.2*prec)); // this is a guess\n        Builtin'Precision'Set(prec+2); // this is a guess\n//        eps:=5*10^(-prec);\n        eps:=10^(-prec);\n//Echo(expr);\n//Echo(\"     eps = \",N(Eval(eps)));\n\n        term:=1;\n        k:=start;\n        result:=0;\n        While( N(Abs(term) >= eps) )[\n                term:=N(Eval(expr));\n\t\t//Echo({\"term is \",term});\n                k:=k+1;\n\t\tresult:=result+term;\n\n        ];\n\t\tIf(InVerboseMode(), Echo(\"ApproxInfSum: Info: using \", k, \" terms of the series\"));\n        Builtin'Precision'Set(prec);\n        // This should not round, only truncate\n        // some outputs will be off by one in the last digit\n\n//Echo(\"lastterm = \",N(Eval(term)));\n\n//Echo(\"r1\",result);\n//Echo(\"r2\",RoundTo(result,prec));\n//Echo(\"r3\",N((result/10)*10));\n\n  result;\n];\n\n/////////////////////////////////////////////////\n/// Error and complementary error functions\n/////////////////////////////////////////////////\n\n10 # Erf(0)\t\t<-- 0;\n//10 # Erfc(0)\t\t<-- 1;\n10 # Erf(Infinity)\t<-- 1;\n10 # Erf(Undefined) <-- Undefined;\n//10 # Erfc(Infinity)\t<-- 0;\n10 # Erf(x_IsNumber)_(x<0)\t<-- -Erf(-x);\n//40 # Erf(x_IsNumber)_(Abs(x) <= 1 )  <-- N(2/Sqrt(Pi)*ApproxInfSum((-1)^k*x^(2*k+1)/((2*k+1)*k!),0,x));\n\nLocalSymbols(k)\n[\n\t40 # Erf(_x)_(InNumericMode() And (IsNumber(x) Or IsComplex(x)) And Abs(x) <= 1) <-- \n[\n  Local(prec);\n  prec := Builtin'Precision'Get(); // N(...) modifies the precision\n  2 / MathSqrt(Internal'Pi()) * x \n\t* SumTaylorNum(x^2, 1, {{k}, -(2*k-1)/(2*k+1)/k},\n\t// the number of terms n must satisfy n*Ln(n/Exp(1))>10^prec \n//\tHold({{k}, [Echo(k); k;]}) @\n\t\tN(1+87/32*Exp(LambertW(prec*421/497)), 20)\n\t);\n\n];\n\n];\t// LocalSymbols(k)\n\n// asymptotic expansion, can be used only for low enough precision or large enough |x| (see predicates). Also works for complex x.\nLocalSymbols(n'max, k)\n[\n\n\t50 # Erf(_x)_(InNumericMode() And (IsNumber(x) Or IsComplex(x))\n\t\tAnd (\n\t\t\t[\t// strongest condition: the exp(-x^2) asymptotic is already good\n\t\t\t\tn'max := 0;\n\t\t\t\tRe(x^2) > Builtin'Precision'Get()*3295/1431+0.121;\n\t\t\t]\n\t\t\tOr\n\t\t\t[\t// next condition: the exp(-x^2) helps but we need a few terms of the series too\n\t\t\t\tn'max := N(Min((Builtin'Precision'Get()*3295/1431+0.121)/Internal'LnNum(Abs(x)), 2*Internal'LnNum(Abs(x))), 10);\n\t\t\t\t2*Abs(x)+Re(x^2) > Builtin'Precision'Get()*3295/1431+0.121;\n\t\t\t]\n\t\t\tOr\n\t\t\t[\t// worst case: exp(-x^2) does not help and we need the full series\n\t// hack: save a value computed in the predicate to use in the body of rule\n\t\t\t\tn'max := N(({{k}, k+Internal'LnNum(k)} @ Builtin'Precision'Get()*3295/1431)/2 - 3/2, 10);\n\t\t\t\tAbs(x) > n'max+3/2;\n\t\t\t]\n\t\t)\n\t) <-- If(Re(x)!=0, Sign(Re(x)), 0) - Exp(-x^2)/x/MathSqrt(Internal'Pi())\n\t// the series is 1 - 1/2/x^2 + 1*3/2^2/x^4 - 1*3*5/2^3/x^6 + ...\n\t* SumTaylorNum(1/x^2, 1, {{k}, -(2*k-1)/2 }, Max(0, Floor(n'max)));\n\n];\t// LocalSymbols(n'max, k)\n\n10 # Erfc(_x)\t\t<-- 1 - Erf(x);\n10 # Erfi(_x)\t\t<-- -I*Erf(x*I);\n\n/////////////////////////////////////////////////\n/// Fresnel integrals\n/////////////////////////////////////////////////\n\n10 # FresnelSin(0)\t\t<-- 0;\n10 # FresnelSin(Infinity)\t<-- 1/2;\n10 # FresnelSin(x_IsNumber)_(x<0)\t<-- -FresnelSin(x);\n10 # FresnelCos(0)              <-- 0;\n10 # FresnelCos(Infinity)       <-- 1/2;\n10 # FresnelCos(x_IsNumber)_(x<0)       <-- -FresnelCos(x);\n\n40 # FresnelSin(x_IsNumber)_(Abs(x) <= 1) <-- N(Sqrt(2/Pi)*ApproxInfSum((-1)^(k+1)*x^(2*k+1)/(k! * (2*k+1)),1,x));\n40 # FresnelCos(x_IsNumber)_(Abs(x) <= 1) <-- N(Sqrt(2/Pi)*ApproxInfSum((-1)^(k+1)*x^(4*k-3)/((4*k-3) * (2*k-2)! ),1,x));\n\n/////////////////////////////////////////////////\n/// Lambert's $W$ function.\n/////////////////////////////////////////////////\n\n10 # LambertW(0) <-- 0;\n10 # LambertW(Infinity) <-- Infinity;\n10 # LambertW(Undefined) <-- Undefined;\n10 # LambertW(-Infinity) <-- Infinity + I*Pi;\n10 # LambertW(-Exp(-1)) <-- -1;\n20 # LambertW(_x * Ln(_x)) <-- Ln(x);\n20 # LambertW(Ln(_x) * _x) <-- Ln(x);\n\n30 # LambertW(x_IsConstant) _ InNumericMode() <-- Internal'LambertWNum(Eval(x));\n\n/* {Internal'LambertWNum} computes a numeric approximation of Lambert's $W$ function\nto the current precision. It uses a Halley iteration\n$$ W'=W-(W-x*Exp(-W))/(W+1-(W+2)/(W+1)*(W-x*Exp(-W))/2) $$.\nThe function has real values for real $x >= -Exp(-1)$. (This point is a logarithmic branching point.)\n*/\n10 # Internal'LambertWNum(x_IsNumber)_(x < -MathExp(-1)) <-- Undefined;\n20 # Internal'LambertWNum(x_IsNumber) <--\n[\n\tLocal(W);\n\tNewtonNum(\n\t  `Hold(\n\t  {\n\t  {W},\n\t  [\n\t  \tLocal(a);\n\t\ta:=W- @x*MathExp(-W);\n\t\tW-a/(W+1-(W+2)/(W+1)*a/2.);\n\t  ]}),\n\t// initial approximation is the two-point global Pade:\n\t  If(\n\t\tx<0,\n\t\tx*MathExp(1) / (1+1 / (1 / MathSqrt(2*(x*MathExp(1)+1)) - 1 / MathSqrt(2) + 1/(MathExp(1)-1))),\n\t\tInternal'LnNum(1+x)*(1-Internal'LnNum(1+Internal'LnNum(1+x))/(2+Internal'LnNum(1+x)))\n\t  ),\n\t  10,\t// initial approximation is good to about 3 digits\n\t  3\t// 3rd order scheme\n\t);\n];\n\n10 # Beta(_n,_m)\t<-- Gamma(m)*Gamma(n)/Gamma(m+n);\n10 # DirichletEta(_z)\t<-- (1-2/2^z)*Zeta(z);\n10 # DirichletLambda(_z)<-- (1-1/2^z)*Zeta(z);\n10 # Sinc(_x)\t\t<-- If(x=0,1,Sin(x)/x);\n\n\n////// Polylogarithm Function\n// Note: currently, the numerics are only working for x \\in [-1,1]\n\n10 # PolyLog(_n,0)\t\t<-- 0;\n// this is nicer than -Ln(1/2)\n10 # PolyLog(1,1/2)             <-- Ln(2);\n10 # PolyLog(_n,1)\t\t<-- Zeta(n);\n10 # PolyLog(_n,_m)_(m= -1)\t<-- DirichletEta(n);\n10 # PolyLog(_n,_x)_(n< 0)\t<-- (1/((1-x)^(-n+1)))*Sum(i,0,-n,Eulerian(-n,i)*x^(-n-i) );\n//10 # PolyLog(_n,_x)_(n= -3)\t<-- x*(x^2 + 4*x + 1)/(x-1)^4;\n//10 # PolyLog(_n,_x)_(n= -2)\t<-- x*(x+1)/(1-x)^3;\n//10 # PolyLog(_n,_x)_(n= -1)\t<-- x/(1-x)^2;\n10 # PolyLog(0,_x)\t\t<-- x/(1-x);\n10 # PolyLog(1,_x)\t\t<-- -Ln(1-x);\n// special values\n10 # PolyLog(2,1/2)\t\t<-- (Pi^2 - 6*Ln(2)^2)/12;\n10 # PolyLog(3,1/2)\t\t<-- (4*Ln(2)^3 - 2*Pi^2*Ln(2)+21*Zeta(3))/24;\n10 # PolyLog(2,2)\t\t<-- Pi^2/4 - Pi*I*Ln(2);\n\n20 # PolyLog(_n,_x)_(InNumericMode() And  x < -1 )  <-- [\n\tLocal(prec,result);\n\tprec:=Builtin'Precision'Get();\n\tBuiltin'Precision'Set(prec+5);\n\tEcho(\"Warning: PolyLog is only currently accurate for x in [-1,1]\");\n\tresult:= (-1)^(n-1)*PolyLog(n,1/x) - ((Ln(-x))^n)/n! - \n\tSum(r,1,Round(n/2), \n\t\t2^(2*r-2)*Pi^(2*r)*Abs(Bernoulli(2*r))*Ln(-x)^(n-2*r)/( (2*r)! * (n - 2*r)! ) );\n\tBuiltin'Precision'Set(prec);\n\tRoundTo(N(result),prec);\n];\n20 # PolyLog(_n,_x)_(InNumericMode() And x>= -1 And x < 0 ) <-- [\n\t// this makes the domain [-1,0) into [0,1],\n\t// so if the summation representation is used, it is monotone\n        Local(prec,result);\n        prec:=Builtin'Precision'Get();\n        Builtin'Precision'Set(prec+5);\n\n\tresult:=PolyLog(n,x^2)/2^(n-1) - PolyLog(n,-x) ;\t\n        Builtin'Precision'Set(prec);\n        RoundTo(N(result),prec);\n\n];\n/* this is very slow at high precision\n20 # PolyLog(_n,_x)_(InNumericMode() And x > 0 And x <= 1) <-- [\n\tLocal(result,prec,term,k,eps);\n\tprec:=Builtin'Precision'Get();\n  Builtin'Precision'Set(prec+5);\n\teps:=10^(-prec);\n\tresult:=0;\n\t// Sorry Serge, I was only getting 2 digits of precision with this\n\t\t// so why didn't you ask me? :) -- Serge\n\t//terms:=Floor(10 + N(prec*Ln(10)/Ln(prec) - 1));\n\t//Builtin'Precision'Set( prec + Floor(N(Ln(6*terms)/Ln(10))) );\n\t//result:=SumTaylorNum(x, {{k}, x^(k+1)/(k+1)^n }, terms );\n\tterm:=1;\n\tFor(k:=1,Abs(term)>eps,k++)[\n\t\tterm:=N(x^k/k^n);\n\t\tresult:=result+term;\n\t];\n\tBuiltin'Precision'Set(prec);\n\tRoundTo(result,prec);\n];\n*/\n\n20 # PolyLog(_n,_x)_(InNumericMode() And x > 0 And x < 1) <--\n[\t// use Taylor series x^(k+1)/(k+1)^n, converges for -1<x<1\n\tLocal(prec, result, terms);\n\tprec:=Builtin'Precision'Get();\n\tBuiltin'Precision'Set(15);\t// to calculate the number of terms\n\tterms := Floor(-prec*Ln(10)/Ln(x));\n\tterms := Floor(-(prec*Ln(10)-(n-1)*Ln(terms))/Ln(x));\n//\tEcho(\"used\", terms, \"terms\");\n\tIf(terms < 4, terms := 4);\n\tBuiltin'Precision'Set(prec+2*IntLog(prec,10)+5);\n\tresult := x*SumTaylorNum(x, {{k}, 1/(k+1)^n}, terms);\n\tBuiltin'Precision'Set(prec);\n\tRoundTo(result, prec);\n];\n\n// This is really slow for x <= 3\n5  # DirichletBeta(1)\t\t<-- Pi/4;\n5  # DirichletBeta(2)\t\t<-- Catalan;\n5  # DirichletBeta(3)\t\t<-- Pi^3/32;\n6  # DirichletBeta(n_IsOdd)\t<-- [\n\t\tLocal(k);\n\t\tk:=(n-1)/2;\n\t\t(-1)^k*Euler(2*k)*(Pi/2)^(2*k+1)/(2*(2*k)!);\n];\n\n\n10 # DirichletBeta(x_IsRationalOrNumber)_(InNumericMode() And x>=1 ) <-- [\n\tLocal(prec,eps,term,result,k);\n\tprec:=Builtin'Precision'Get();\n  Builtin'Precision'Set(prec+3);\n\teps:=10^(-prec);\n\tresult:=0;\n\tterm:=1;\n\tFor(k:=0, Abs(term) > eps, k++ )[\n\t\tterm:=(-1)^k/(2*k+1)^x;\n\t\tEcho(\"term is \",term);\n\t\tresult:=result+term;\n\t];\n\tBuiltin'Precision'Set(prec);\n\tRoundTo(result,prec);\n];\n\n/////////////////////////////////////////////////\n/// Catalan's constant, various algorithms for comparison. (SW)\n/////////////////////////////////////////////////\n\n/* Brent-Fee's method based on Ramanujan's identity and Brent's trick.\n * Geometric convergence as 2^(-n). */\nCatalanConstNum1() := \n[\n  Local(prec,Aterm,Bterm,nterms,result,n);\n  prec:=Builtin'Precision'Get();\n\tBuiltin'Precision'Set(10);\n\t// estimate the number of terms from above\n\tnterms := 1+Floor(N((prec*Ln(10)+Ln(prec*Ln(10)/Ln(2)))/Ln(2)));\n  Builtin'Precision'Set(prec+5);\n\tAterm:=N(1/2);\n  result:= Aterm;\n  Bterm:=Aterm;\n  For(n:=1, n<=nterms, n++ )\n\t[\n/*\n    Bterm := MultiplyNum(Bterm, n/(2*n+1));\n    Aterm:= MathDivide(MultiplyNum(Aterm,n)+Bterm, 2*n+1);\n/* this is faster: */\n    Bterm:=MathDivide(MathMultiply(Bterm,n), 2*n+1); // Bterm = (k!)^2*2^(k-1)/(2*k+1)!\n    Aterm:=MathDivide(MathMultiply(Aterm,n)+Bterm, 2*n+1); // Aterm = Bterm * Sum(k,0,n,1/(2*k+1))\n/**/\n    result := result + Aterm;\n  ];\n  Builtin'Precision'Set(prec);\n  RoundTo(result,prec);\t\n];\n\n/* Bailey 1997's method.\n * Geometric convergence as 4^(-n). */\n\nCatalanConstNum() :=\n[\n\tLocal(prec, n, result);\n\tprec:=Builtin'Precision'Get();\n\n\t// number of terms\n\tn := 1+Div(prec*1068+642,643); // prec*Ln(10)/Ln(4)\n\tBuiltin'Precision'Set(prec+2);\t// 2 guard digits\n\t\n\tresult := N(1/(2*n+1));\n\tWhile(n>0)\n\t[\n/*\n\t\tresult := MultiplyNum(result, n/(4*n+2))+N(1/(2*n-1));\n/* this is faster: */\n\t\tresult := MathDivide(MathMultiply(result, n), 4*n+2)+MathDivide(1,2*n-1);\n/**/\n\t\tn := n-1;\n\t];\n\tresult := MultiplyNum(result, 3/8) + N(Pi/8*Ln(2+Sqrt(3)));\n\tBuiltin'Precision'Set(prec);\n\tRoundTo(result,prec);\n];\n\n/* Broadhurst's series.\n * Geometric convergence as 16^(-n). */\n\nCatalanConstNum2() :=\n[\n\tLocal(prec, n, result1, result2);\n\tprec:=Builtin'Precision'Get();\n\n\t// first series\n\t// number of terms\n\tn := 1+Div(prec*534+642,643); // prec*Ln(10)/Ln(16)\n\tBuiltin'Precision'Set(prec+2);\t// 2 guard digits\n\t\n\tresult1 := 0;\n\tWhile(n>=0)\n\t[\n\t\tresult1 := MathDivide(result1, 16)+N(\n\t\t\t+1/(8*n+1)^2 -1/(8*n+2)^2 +1/2/(8*n+3)^2 -1/4/(8*n+5)^2 +1/4/(8*n+6)^2 -1/8/(8*n+7)^2 \n\t\t);\n\t\tn := n-1;\n\t];\n\n\t// second series\n\t// number of terms\n\tn := 1+Div(prec*178+642,643); // prec*Ln(10)/Ln(4096)\n\tBuiltin'Precision'Set(prec+2);\t// 2 guard digits\n\t\n\tresult2 := 0;\n\tWhile(n>=0)\n\t[\n\t\tresult2 := MathDivide(result2, 4096)+N(\n\t\t\t+1/(8*n+1)^2 +1/2/(8*n+2)^2 +1/8/(8*n+3)^2 -1/64/(8*n+5)^2 -1/128/(8*n+6)^2 -1/512/(8*n+7)^2 \n\t\t);\n\t\tn := n-1;\n\t];\n\tresult1 := MultiplyNum(result1, 3/2) - MultiplyNum(result2, 1/4);\n\tBuiltin'Precision'Set(prec);\n\tRoundTo(result1,prec);\n];\n\n\n\n10 # Digamma(_n)_(IsPositiveInteger(n)) <-- Sum(m,1,n-1,1/m) - gamma;\n// needs Erf() that takes complex argument\n/*\n10 # DawsonIntegral(_x) <-- [\n\tLocal(result,prec);\n\tprec:=Builtin'Precision'Get();\n\tBuiltin'Precision'Set(prec+5);\n\tresult:=N(I*Sqrt(Pi)*Exp(-x^2)*Erf(-I*x)/2);\n\tBuiltin'Precision'Set(prec);\n\tRoundTo(result,prec);\n];\n*/\n\t\t\n"
  },
  {
    "path": "scripts/specfunc.rep/code.ys.def",
    "content": "Gamma\nLnGamma\nPolyGamma\nZeta\nBernoulli\nApproxInfSum\nBesselJ\nBesselI\nBesselY\nErf\nErfc\nErfi\nFresnelSin\nFresnelCos\nLambertW\nBeta\nDirichletEta\nDirichletLambda\nDirichletBeta\nSinc\nPolyLog\nCatalanConstNum\nDigamma\nDawsonIntegral\n}\n"
  },
  {
    "path": "scripts/specfunc.rep/gamma.ys",
    "content": "/// special functions coded for Yacas by Serge Winitzki\n\n/////////////////////////////////////////////////\n/// Euler's Gamma function\n/////////////////////////////////////////////////\n\n/// This procedure computes the uniform approximation for the Gamma function\n/// due to Lanczos and Spouge (the so-called \"less precise coefficients\")\n/// evaluated at arbitrary precision by using a large number of terms\n/// See J. L. Spouge, SIAM J. of Num. Anal. 31, 931 (1994)\n/// See also Paul Godfrey 2001 (unpublished): http://winnie.fit.edu/~gabdo/gamma.txt for a discussion\n\n/// Calculate the uniform approximation to the logarithm of the Gamma function\n/// in the Re z > 0 half-plane; argument z may be symbolic or complex\n/// but current value of precision is used\n/// Note that we return LnGamma(z), not of z+1\n/// This function should not be used directly by applications\n10 # Internal'LnGammaNum(_z, _a)_(N(Re(z))<0) <-- [\n\tIf (InVerboseMode(), Echo({\"Internal'LnGammaNum: using 1-z identity\"}));\n\tN(Ln(Pi/Sin(Pi*z)) - Internal'LnGammaNum(1-z, a));\n];\n20 # Internal'LnGammaNum(_z, _a) <-- [\n\tLocal(e, k, tmpcoeff, coeff, result);\n\ta := Max(a, 4);\t// guard against low values\n\tIf (InVerboseMode(), Echo({\"Internal'LnGammaNum: precision parameter = \", a}));\n\te := N(Exp(1));\n\tk:=Ceil(a);\t// prepare k=N+1; the k=N term is probably never significant but we don't win much by excluding it\n\tresult := 0;\t// prepare for last term\n\t// use Horner scheme to prevent loss of precision\n\tWhile(k>1) [\t// 'result' will accumulate just the sum for now\n\t\tk:=k-1;\n\t\tresult := N( MathPower(a-k,k)/((z+k)*Sqrt(a-k))-result/(e*k) );\n\t];\n\tN(Ln(1+Exp(a-1)/Sqrt(2*Pi)*result) + Ln(2*Pi)/2 -a-z+(z+1/2)*Ln(z+a) - Ln(z));\n];\n\nInternal'LnGammaNum(z) := [\n\tLocal(a, prec, result);\n\tprec := Builtin'Precision'Get();\n\ta:= Div((prec-IntLog(prec,10))*659, 526) + 0.4;\t// see algorithm docs\n\t/// same as parameter \"g\" in Godfrey 2001.\n\t/// Chosen to satisfy Spouge's error bound:\n\t/// error < Sqrt(a)/Real(a+z)/(2*Pi)^(a+1/2)\n//\tEcho({\"parameter a = \", a, \" setting precision to \", Ceil(prec*1.4)});\n\tBuiltin'Precision'Set(Ceil(prec*1.4));\t// need more precision b/c of roundoff errors but don't know exactly how many digits\n\tresult := Internal'LnGammaNum(z,a);\n\tBuiltin'Precision'Set(prec);\n\tresult;\n];\n\nInternal'GammaNum(z) := N(Exp(Internal'LnGammaNum(z)));\n\n/// this should not be used by applications\nInternal'GammaNum(z,a) := N(Exp(Internal'LnGammaNum(z,a)));\n\n"
  },
  {
    "path": "scripts/specfunc.rep/gamma.ys.def",
    "content": "Internal'GammaNum\nInternal'LnGammaNum\n}\n"
  },
  {
    "path": "scripts/specfunc.rep/gammaconst.ys",
    "content": "\nGammaConstNum() :=\n[\n  Local(k, n, A, B, U'old, U, V'old, V, prec, result);\n  prec:=Builtin'Precision'Get();\n  NonN([\n    Builtin'Precision'Set(prec+IntLog(prec,10)+3);\t// 2 guard digits and 1 to compensate IntLog\n    n:= 1+Ceil(prec*0.5757+0.2862);\t// n>(P*Ln(10)+Ln(Pi))/4\n    A:= -Internal'LnNum(n);\n    B:=1;\n    U:=A;\n    V:=1;\n    k:=0;\n    U'old := 0;\t// these variables are for precision control\n    V'old := 0;\n    While(U'old-U != 0 Or V'old-V != 0)\n    [\n     k++;\n     U'old:=U;\n     V'old:=V;\n     // B:=N( B*n^2/k^2 );\n     B:=MultiplyNum(B,n^2/k^2);\t// slightly faster\n     // A:=N( (A*n^2/k+B)/k );\n     A:=MultiplyNum(MultiplyNum(A,n^2/k)+B, 1/k);\t// slightly faster\n     U:=U+A;\n     V:=V+B;\n    ];\n    If(InVerboseMode(), Echo(\"GammaConstNum: Info: used\", k, \"iterations at working precision\", Builtin'Precision'Get()));\n    result:=MathDivide(U,V);\t// N(U/V)\n  ]);\n  Builtin'Precision'Set(prec);\t// restore precision\n  RoundTo(result, prec);\t// return correctly rounded result\n];\n\n"
  },
  {
    "path": "scripts/specfunc.rep/gammaconst.ys.def",
    "content": "GammaConstNum\n}\n"
  },
  {
    "path": "scripts/specfunc.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef( \"Gamma\", \"nums1\", \"gamma\" );\nOMDef( \"LnGamma\"        , \"yacas\", \"LnGamma\" );\nOMDef( \"Zeta\"           , \"yacas\", \"Zeta\" );\nOMDef( \"Bernoulli\"      , \"yacas\", \"Bernoulli\" );\nOMDef( \"ApproxInfSum\"   , \"yacas\", \"ApproxInfSum\" );\nOMDef( \"BesselJ\"        , \"yacas\", \"BesselJ\" );\nOMDef( \"BesselI\"        , \"yacas\", \"BesselI\" );\nOMDef( \"BesselY\"        , \"yacas\", \"BesselY\" );\nOMDef( \"Erf\"            , \"yacas\", \"Erf\" );\nOMDef( \"Erfc\"           , \"yacas\", \"Erfc\" );\nOMDef( \"Erfi\"           , \"yacas\", \"Erfi\" );\nOMDef( \"FresnelSin\"     , \"yacas\", \"FresnelSin\" );\nOMDef( \"FresnelCos\"     , \"yacas\", \"FresnelCos\" );\nOMDef( \"LambertW\"       , \"yacas\", \"LambertW\" );\nOMDef( \"Beta\"           , \"yacas\", \"Beta\" );\nOMDef( \"DirichletEta\"   , \"yacas\", \"DirichletEta\" );\nOMDef( \"DirichletLambda\", \"yacas\", \"DirichletLambda\" );\nOMDef( \"DirichletBeta\"  , \"yacas\", \"DirichletBeta\" );\nOMDef( \"Sinc\"           , \"yacas\", \"Sinc\" );\nOMDef( \"PolyLog\"        , \"yacas\", \"PolyLog\" );\nOMDef( \"CatalanConstNum\", \"yacas\", \"CatalanConstNum\" );\nOMDef( \"Digamma\"        , \"yacas\", \"Digamma\" );\nOMDef( \"DawsonIntegral\" , \"yacas\", \"DawsonIntegral\" );\n"
  },
  {
    "path": "scripts/specfunc.rep/zeta.ys",
    "content": "/// special functions coded for Yacas by Serge Winitzki\n\n/////////////////////////////////////////////////\n/// Riemann's Zeta function\n/////////////////////////////////////////////////\n\n/// See: Bateman, Erdelyi: <i>Higher Transcendental Functions<i>, vol. 1;\n/// P. Borwein, <i>An efficient algorithm for Riemann Zeta function<i> (1995).\n\n/// Numerical computation of Zeta function using Borwein's \"third\" algorithm\n/// The value of $n$ must be large enough to ensure required precision\n/// Also $s$ must satisfy $Re(s)+n+1 > 0$\nInternal'ZetaNum(_s, n_IsInteger) <-- [\n\tLocal(result, j, sign);\n\tIf (InVerboseMode(), Echo({\"Internal'ZetaNum: Borwein's method, precision \", Builtin'Precision'Get(), \", n = \", n}));\n\tresult := 0;\n\tsign := 1;\t// flipping sign\n\tFor(j:=0, j<=2*n-1, j++)\n\t[\t// this is suboptimal b/c we can compute the coefficients a lot faster in this same loop, but ok for now\n\t\tresult := N(result + sign*Internal'ZetaNumCoeffEj(j,n)/(1+j)^s );\n\t\tsign := -sign;\n\t];\n\tN(result/(2^n)/(1-2^(1-s)));\n];\n\n/// direct method -- only good for large s\nInternal'ZetaNum1(s, limit) := [\n\tLocal(i, sum);\n\tIf (InVerboseMode(), Echo({\"Internal'ZetaNum: direct method (sum), precision \", Builtin'Precision'Get(), \", N = \", limit}));\n\tsum := 0;\n\tlimit := Ceil(N(limit));\n\tFor(i:=2, i<=limit, i++) sum := sum+N(1/MathPower(i, s));\n//\tsum := sum + ( N( 1/MathPower(limit, s-1)) + N(1/MathPower(limit+1, s-1)) )/2/(s-1); \t // these extra terms don't seem to help much\n\tsum+1;\t// add small terms together and then add 1\n];\n/// direct method -- using infinite product. For internal math, Internal'ZetaNum2 is faster for Bernoulli numbers > 250 or so.\nInternal'ZetaNum2(s, limit) := \n[\n\tLocal(i, prod);\n\tIf (InVerboseMode(), Echo({\"Internal'ZetaNum: direct method (product), precision \", Builtin'Precision'Get(), \", N = \", limit}));\n\tprod := N( (1-1/MathPower(2, s))*(1-1/MathPower(3,s)) );\n\tlimit := Ceil(N(limit));\n\tFor(i:=5, i<=limit, i:= NextPrime(i))\n\t\tprod := prod*N(1-1/MathPower(i, s));\n\t1/prod;\n];\n\n/// Compute coefficients e[j] (see Borwein -- excluding (-1)^j )\nInternal'ZetaNumCoeffEj(j,n) := [\n\tLocal(k);\n\t2^n-If(j<n,\n\t\t0,\n\t\tSum(k,0,j-n,Bin(n,k))\t// this is suboptimal but ok for now\n\t);\n];\n\n/// fast numerical calculation of Zeta(3) using a special series\n\n\n\n\nZeta3() :=\n[\n\tLocal(result, old'result, k, term);\n  N([\n    For(\n    [\n      k:=1;\n      result := 1;\n      old'result := -1;\n      term := 1;\n    ],\n    old'result!=result,\n    k++\n    )\n    [\n      old'result := result;\n      term := -term * k^2 / ((2*k+1)*(2*k));\n      result := result + term/(k+1)^2;\n    ];\n    result := 5/4*result;\n  ], Builtin'Precision'Get()+IntLog(Builtin'Precision'Get(),10)+1);\n\t\n\tresult;\n];\n\n\n/// User interface for Internal'ZetaNum(s,n)\n10 # Internal'ZetaNum(_s) _ (N(s)=0) <-- -0.5;\n10 # Internal'ZetaNum(_s) _ (N(s)=1) <-- Infinity;\n20 # Internal'ZetaNum(_s) <-- [\n\tLocal(n, prec, result);\n\tprec := Builtin'Precision'Get();\n\tIf(\t// use identity if s<1/2 to replace with larger s. Also must be sn!=0 or else we get infinity * zero\n\t\tN(Re(s)) < 0.5,\n\t\t// call ourselves with a different argument\n\t\t[\n\t\t\tIf(InVerboseMode(), Echo({\"Internal'ZetaNum: using s->1-s identity, s=\", s, \", precision \", prec}));\n\t\t\tresult :=  2*Exp(Internal'LnGammaNum(1-s)-(1-s)*Ln(2*Internal'Pi()))*Sin(Internal'Pi()*s/2) * Internal'ZetaNum(1-s);\n\t\t],\n\t\t// choose between methods\n\t\tIf (N(Re(s)) > N(1+(prec*Ln(10))/(Ln(prec)+0.1), 6),\n\t\t\t[\t// use direct summation\n\t\t\t\tn:= N(10^(prec/(s-1)), 6)+2;\t// 2 guard terms\n\t\t\t\tBuiltin'Precision'Set(prec+2);\t// 2 guard digits\n\t\t\t\tresult := Internal'ZetaNum1(s, n);\n\t\t\t],\n\t\t\t[\t// use Internal'ZetaNum(s, n)\n\t\t\t\tn := Ceil( N( prec*Ln(10)/Ln(8) + 2, 6 ) );\t// add 2 digits just in case\n\t\t\t\tBuiltin'Precision'Set(prec+2);\t// 2 guard digits\n\t\t\t\tresult := Internal'ZetaNum(s, n);\n\t\t\t]\n\t\t)\n\t);\n\tBuiltin'Precision'Set(prec);\n\tresult;\n];\n\n"
  },
  {
    "path": "scripts/specfunc.rep/zeta.ys.def",
    "content": "Internal'ZetaNum\nInternal'ZetaNum1\nInternal'ZetaNum2\nZeta3\n}\n"
  },
  {
    "path": "scripts/standard.ys",
    "content": "\n/* See the documentation on the assignment of the precedence of the rules.\n */\n\n/* Some very basic functions that are used always any way... */\n\n\n/* Implementation of Nth that allows extending. */\nRuleBase(\"Nth\",{alist,aindex});\nRule(\"Nth\",2,10,\n    And(Equals(IsFunction(alist),True),\n            Equals(IsInteger(aindex),True),\n            Not(Equals(Head(Listify(alist)),Nth))\n            ))\n     MathNth(alist,aindex);\n\n\n\n\nRule(\"Nth\",2,14,\n     And(Equals(IsString(alist),True),IsList(aindex))\n    )\n[\n  Local(result);\n  result:=\"\";\n  ForEach(i,aindex) [ result := result : StringMid'Get(i,1,alist); ];\n  result;\n];\n\nRule(\"Nth\",2,15,Equals(IsString(alist),True))\n[\n  StringMid'Get(aindex,1,alist);\n];\n\n\nRule(\"Nth\",2,20,Equals(IsList(aindex),True))\n[\n  Map({{ii},alist[ii]},{aindex});\n];\n\nRule(\"Nth\",2,30,\n   And(\n           Equals(IsGeneric(alist),True),\n           Equals(GenericTypeName(alist),\"Array\"),\n           Equals(IsInteger(aindex),True)\n          )\n    )\n[\n  Array'Get(alist,aindex);\n];\n\n\n\nRule(\"Nth\",2,40,Equals(IsString(aindex),True))\n[\n  Local(as);\n  as := Assoc(aindex,alist);\n  If (Not(Equals(as,Empty)),Set(as,Nth(as,2)));\n  as;\n];\n\nProtect(Nth);\n\nFunction(\"NrArgs\",{aLeft}) Length(Listify(aLeft))-1;\n\n10 # IsNonObject(Object(_x)) <-- False;\n20 # IsNonObject(_x)         <-- True;\n\n1 # Numer(_x / _y)      <-- x;\n2 # Numer(x_IsNumber)   <-- x;\n1 # Denom(_x / _y)      <-- y;\n2 # Denom(x_IsNumber)   <-- 1;\n\n/* Implementation of numeric mode */\nLocalSymbols(Numeric) [\n  Set(Numeric,False);\n\n  // evaluate numerically with given precision\n  LocalSymbols(prev'Numeric, prev'digits, numeric'result) Macro(\"N\",{expr,digits})\n  [ // we were in non-numeric mode\n      Local(prev'Numeric, prev'digits, numeric'result,errorString);\n      Set(prev'digits, Builtin'Precision'Get());\n      Builtin'Precision'Set(@digits);\n      AssignCachedConstantsN();\n      Set(prev'Numeric,Numeric);\n      Set(Numeric, True);\n      Set(errorString,\"\");\n      TrapError(Set(numeric'result, @expr),Set(errorString,GetCoreError()));\n      Set(Numeric,prev'Numeric);\n      If(Not Numeric,[\n          // clear constants\n          ClearCachedConstantsN();\n      ]);\n      Builtin'Precision'Set(prev'digits);\n      Check(errorString=\"\",errorString);\n      numeric'result;\n  ];\n\n  LocalSymbols(dig,ex) Macro(\"N\",{expr})\n  [\n    Local(dig,ex);\n    Set(dig,Builtin'Precision'Get());\n    Set(ex,Hold(@expr));\n    `N(@ex,@dig);\n  ];\n\n  LocalSymbols(result) Macro(\"NonN\",{expr})\n  [\n    Local(result);\n    GlobalPush(Numeric);\n    Numeric := False;\n    result := (@expr);\n    Numeric := GlobalPop();\n    result;\n  ];\n\n  Function(\"InNumericMode\",{}) Numeric;\n\n]; //LocalSymbols(Numeric)\n\nLocalSymbols(Verbose) [\n  Set(Verbose,False);\n  Function(\"V\",{aNumberBody})\n  [\n    Local(prevVerbose,result);\n    Set(prevVerbose,Verbose);\n    Set(Verbose,True);\n    Set(result,Eval(aNumberBody));\n    Set(Verbose,prevVerbose);\n    result;\n  ];\n  Function(\"InVerboseMode\",{}) Verbose;\n\n]; // LocalSymbols(Verbose)\nHoldArg(\"V\",aNumberBody);\nUnFence(\"V\",1);\n\nFunction(\"++\",{aVar})\n[\n   MacroSet(aVar,MathAdd(Eval(aVar),1));\n];\nUnFence(\"++\",1);\nHoldArg(\"++\",aVar);\n\n\nFunction(\"--\",{aVar})\n[\n   MacroSet(aVar,MathSubtract(Eval(aVar),1));\n];\nUnFence(\"--\",1);\nHoldArg(\"--\",aVar);\n\n\nFunction(\"TableForm\",{list})\n[\n  Local(i);\n  ForEach(i,list)\n  [\n    Write(i);\n    NewLine();\n  ];\n  True;\n];\n\nRuleBase(\"NormalForm\",{expression});\nRule(\"NormalForm\",1,1000,True) expression;\n\n\n\n\nRuleBase(\"==\",{left,right});\nRuleBase(\"!==\",{left,right});\n\nUnProtect(%);\n\na_IsNonNegativeInteger & b_IsNonNegativeInteger <-- BitAnd(a,b);\na_IsNonNegativeInteger | b_IsNonNegativeInteger <-- BitOr(a,b);\na_IsNonNegativeInteger % b_IsPositiveInteger <-- Mod(a,b);\n\nProtect(%);\n\nRuleBase(\"if\",{predicate,body});\n(if(True) _body) <-- Eval(body);\nHoldArg(\"if\",body);\nUnFence(\"if\",2);\n\nRuleBase(\"else\",{ifthen,otherwise});\n0 # (if (_predicate) _body else _otherwise)_(Eval(predicate) = True) <--\n     Eval(body);\n0 # (if (_predicate) _body else _otherwise)_(Eval(predicate) = False) <--\n     Eval(otherwise);\n1 # (if (_predicate) _body else _otherwise) <--\n    UnList({Atom(\"else\"),\n            UnList({Atom(\"if\"), (Eval(predicate)), body}),\n            otherwise});\nHoldArg(\"else\",ifthen);\nHoldArg(\"else\",otherwise);\nUnFence(\"else\",2);\n\n"
  },
  {
    "path": "scripts/standard.ys.def",
    "content": "Nth\nNrArgs\nIsNonObject\nNumer\nDenom\nNormalForm\n==\n!==\n+-\n/-\n*-\n^-\n:=-\n:=+\n&\n|\n%\nif\nelse\nN\nNonN\nInNumericMode\nV\nInVerboseMode\n}\n"
  },
  {
    "path": "scripts/statistics.rep/distributions.ys",
    "content": "/* Guard against distribution objects with senseless parameters \n   Anti-nominalism */\nBernoulliDistribution(p_IsRationalOrNumber)_(p<0 Or p>1) <-- Undefined;\nBinomialDistribution(_p, _n)_\n\t(If(IsRationalOrNumber(p),p<0 Or p>1, False)\n\t Or (IsConstant(n) And Not IsPositiveInteger(n)) ) \n\t<-- Undefined;\nDiscreteUniformDistribution(a_IsRationalOrNumber, b_IsRationalOrNumber)_(a>=b) \n   <-- Undefined;\nPoissonDistribution(l_IsRationalOrNumber)_(l<=0) <-- Undefined;\nGeometricDistribution(p_IsRationalOrNumber)_(p<0 Or p>1) <-- Undefined;\n\nExponentialDistribution(l_IsRationalOrNumber)_(l<0) <-- Undefined;\nNormalDistribution( _m , s2_IsRationalOrNumber)_(s2<=0) <-- Undefined;\nChiSquareDistribution(m_IsRationalOrNumber)_(m<=0) <-- Undefined;\ntDistribution(m_IsRationalOrNumber)_(Not IsPositiveInteger(m)) <-- Undefined;\n"
  },
  {
    "path": "scripts/statistics.rep/distributions.ys.def",
    "content": "BernoulliDistribution\nBinomialDistribution\nDiscreteUniformDistribution\nPoissonDistribution\nGeometricDistribution\n\nExponentialDistribution\nNormalDistribution\nChiSquareDistribution\ntDistribution\n}"
  },
  {
    "path": "scripts/statistics.rep/hypothesystest.ys",
    "content": "/* \n   Hypothesys testing routines\n   Andrei Zorine,2002 <zoav1@uic.nnov.ru>\n*/\n\n/* Stub: ChiSquare's CDF is computed as IncompleteGamma(x,dof/2)/Gamma(dof/2); */\n\n100 # ChiSquareTest( observed'freqs_IsList, expected'freqs_IsList, estimated'params_IsInteger)\n  <--\n [\n   Local( nominator, chi2, p'value, k, dof);\n   k:=Length(observed'freqs);\n   nominator:=(observed'freqs-expected'freqs)^2; //threading\n   chi2:=Sum(i,1,k,nominator[i]/(expected'freqs[i]));\n   dof := k-estimated'params-1; // degrees of freedom\n   p'value:=1-N(IncompleteGamma(chi2/2,dof/2)/Gamma(dof/2)); \n   { TestStatistics <- chi2 , P'value <- p'value,Atom(\"dof\") <- dof};\n\n ];\n\n\n100 # ChiSquareTest( observed'freqs_IsList, \n\t expected'freqs_IsList) <-- ChiSquareTest( observed'freqs, expected'freqs, 0);\n\n"
  },
  {
    "path": "scripts/statistics.rep/hypothesystest.ys.def",
    "content": "ChiSquareTest\n}\n\n"
  },
  {
    "path": "scripts/statistics.rep/incompletegamma.ys",
    "content": "/* IncompleteGamma function \\int\\limits_{0}^xt^{a-1}e^{-t}dt\n\n   Calculation is based on series\n   IncompleteGamma(x,a)=x^a*Sum(k,0,infinity,(-1)^k*x^k/k!/(a+k)\n   (see D.S.Kouznetsov. Special functions. Vysshaia Shkola, Moscow, 1965)\n   for small x, and on asymptotic expansion\n   IncompleteGamma(x,a)=Gamma(x)-x^(a-1)*Exp(-x)*(1+(a-1)/z+(a-1)(a-2)/z^2+...)\n   (see O.E.Barndorf-Nielsen & D.R.Cox. Asymptotic techniques for Use \n   in Statistics.. Russian translation is also available)\n   for large x.\n*/\n\nIncompleteGamma(_x, _a)_(x<=a+1) <--\n[ \n   Local(prec,eps);\n   prec:=Builtin'Precision'Get();\n   Builtin'Precision'Set(Ceil(prec+1)); // this is a guess\n   eps:=5*10^(-prec);\n\n   Local(term,result,k);\n   \n   term:=1/a;\n   k:=0;\n   result:=0;\n   While( Abs(term) >= eps )[\n\t\t  k:=k+1;\n\t\t  result:=result+term;\n\t\t  term:= -x*(a+k-1)*term/k/(a+k);\n   ];\n   result:= N(x^a*result);\n   Builtin'Precision'Set(prec);\n   // This should not round, only truncate\n   // some outputs will be off by one in the last digit\n   RoundTo(result,prec);\n];\n\n\n100 # IncompleteGamma(_x, _a)_(x>a+1) <--\n[ // Asymptotic expansion\n   Local(prec,eps);\n   prec:=Builtin'Precision'Get();\n   Builtin'Precision''Set(Ceil(prec+1)); // this is a guess\n   eps:=5*10^(-prec);\n\n   Local(term,result,k,expr);\n   \n   term:=1;\n   k:=0;\n   result:=0;\n   While( Abs(term) >= eps )[\n\t\t  k:=k+1;\n\t\t  result:=result+term;\n\t\t  term:=term*(a-k)/x;\n\t\t  //Echo({\"term is \",term});\n   ];\n  result:=N(Gamma(a)-x^(a-1)*Exp(-x)*result);\n  Builtin'Precision'Set(prec);\n  // This should not round, only truncate\n  // some outputs will be off by one in the last digit\n  RoundTo(result,prec);\n];\t\n"
  },
  {
    "path": "scripts/statistics.rep/incompletegamma.ys.def",
    "content": "IncompleteGamma\n}\n"
  },
  {
    "path": "scripts/statistics.rep/randomtest.ys",
    "content": "/* \n  Tests Yacas's Randomnumber generator \n  Author Andrei Zorine, zoav1@uic.nnov.ru\n*/\n\nDefaultDerivtory(\"c:/src/ys/prob\");\nLoad(\"incompletegamma.ys\");\nLoad(\"hypothesystest.ys\");\n\n\nFunction(\"DoTest\",{size})\n[\n  Local(arr,o'f,e'f,i,j,m);\n//  size:=200; // sample size\n  arr := Table(Random(),i,1,size,1);\n  arr := HeapSort(arr,\"<\"); \n  o'f := {};\n  e'f :={};\n  m:=1;\n  For(i:=1, i<=10 And m<=size, i++) \n   [\n     j:=0;\n     While(arr[m]<i/10 And m<size) \n     [ \n       j:=j+1; \n       m:=m+1;\n     ];\n     Push(o'f,j);\n     Push(e'f,0.1*size);\n   ];\n  Echo(o'f,e'f);\n  ChiSquareTest(o'f,e'f); \n];\n"
  },
  {
    "path": "scripts/statistics.rep/regression.ys",
    "content": "\n/* Finds the rengression of y onto x, that is\n   y == alpha + beta * x\n \n   Example usage:\n   x := 1 .. 5;\n   y := (2.34*x+2) +(2*Random()-1); \n   ans :=Regress(x,y);\n    \n   To find the residuals, we do\n   (y-alpha-beta*x) /: ans\n */\n\n\nRegress(x,y) :=\n[\n Local(xy,x2,i,mx,my);\n\n mx := Mean(x);\n my := Mean(y);\n xy := Add((x-mx)*(y-my));\n x2 := Add((x-mx)^2);  \n {alpha <- (my-xy*mx/x2) , beta <-  xy/x2}; \n];\n\n"
  },
  {
    "path": "scripts/statistics.rep/regression.ys.def",
    "content": "Regress\n}\n"
  },
  {
    "path": "scripts/statistics.rep/statistics.ys",
    "content": "\nMean(x) := Add(x)/Length(x);\n\nGeometricMean(x) := Multiply(x)^(1/Length(x));\n\nMedian(x) :=\n[\n Local(sx,n,n2); // s[orted]x\n sx := BubbleSort(x,\"<\");\n n := Length(x);\n n2 := (n>>1);\n If(Mod(n,2) = 1, sx[n2+1], (sx[n2]+sx[n2+1])/2);\n];\n\nVariance(x) := Add((x-Mean(x))^2)/Length(x);\nUnbiasedVariance(x) := Add((x-Mean(x))^2)/(Length(x)-1);\n\n// stdev in Wester benchmark\nStandardDeviation(x) := Sqrt(UnbiasedVariance(x)); \n// Why Sqrt(1.01) --> Sqrt(1.01) ?\n\n"
  },
  {
    "path": "scripts/statistics.rep/statistics.ys.def",
    "content": "Mean\nGeometricMean\nMedian\nVariance\nUnbiasedVariance\nStandardDeviation\n}\n\n"
  },
  {
    "path": "scripts/stats.rep/code.ys",
    "content": "10 # ExpressionDepth(expression_IsFunction) <--\n[\n  Local(result);\n  result:=0;\n  ForEach(item,Tail(Listify(expression)))\n  [\n    Local(newresult);\n    newresult:=ExpressionDepth(item);\n    result:=Max(result,newresult);\n  ];\n  result+1;\n];\n20 # ExpressionDepth(_expression) <-- 1;\nUnFence(\"ExpressionDepth\",1);\n\n"
  },
  {
    "path": "scripts/stats.rep/code.ys.def",
    "content": "ExpressionDepth\n}\n"
  },
  {
    "path": "scripts/stdarith.ys",
    "content": "/* Standard arithmetic */\n\n\n/* Addition */\n\n100 # + _x  <-- x;\n\n50 # x_IsNumber + y_IsNumber <-- MathAdd(x,y);\n\n100 # 0 + _x    <-- x;\n100 # _x + 0    <-- x;\n100 # _x + _x   <-- 2*x;\n100 # _x + n_IsConstant*(_x)   <-- (n+1)*x;\n100 # n_IsConstant*(_x) + _x   <-- (n+1)*x;\n100 # m_IsConstant*(_x) + n_IsConstant*(_x) <-- (m + n) * x;\n100 # _x / m_IsConstant + _x <-- (m + 1) * x / m;\n100 # _x + _x / m_IsConstant <-- (m + 1) * x / m;\n100 # _x / m_IsConstant + _x / n_IsConstant <-- (m + n) * x / (m * n);\n100 # (a_IsConstant * _x) / m_IsConstant + _x / n_IsConstant <-- (a * n + m) * x / (m * n);\n100 # _x / m_IsConstant + (b_IsConstant * _x) / n_IsConstant <-- (n + b * m) * x / (m * n);\n100 # (a_IsConstant * _x) / m_IsConstant + (b_IsConstant * _x) / n_IsConstant <-- (a * n + b * m) * x / (m * n);\n101 # _x + - _y <-- x-y;\n101 # _x + (- _y)/(_z) <-- x-(y/z);\n101 # (- _y)/(_z) + _x  <-- x-(y/z);\n101 # (- _x) + _y <-- y-x;\n102 # _x + y_IsNegativeNumber <-- x-(-y);\n102 # _x + y_IsNegativeNumber * _z <-- x-((-y)*z);\n102 # _x + (y_IsNegativeNumber)/(_z) <-- x-((-y)/z);\n102 # (y_IsNegativeNumber)/(_z) + _x  <-- x-((-y)/z);\n102 # (x_IsNegativeNumber) + _y <-- y-(-x);\n// fractions\n150 # _n1 / _d + _n2 / _d <-- (n1+n2)/d;\n\n200 # (x_IsNumber + _y)_Not(IsNumber(y)) <-- y+x;\n200 # ((_y + x_IsNumber) + _z)_Not(IsNumber(y) Or IsNumber(z)) <-- (y+z)+x;\n200 # ((x_IsNumber + _y) + z_IsNumber)_Not(IsNumber(y)) <-- y+(x+z);\n200 # ((_x + y_IsNumber) + z_IsNumber)_Not(IsNumber(x)) <-- x+(y+z);\n// fractions\n210 # x_IsNumber + (y_IsNumber / z_IsNumber) <--(x*z+y)/z;\n210 # (y_IsNumber / z_IsNumber) + x_IsNumber <--(x*z+y)/z;\n210 # (x_IsNumber / v_IsNumber) + (y_IsNumber / z_IsNumber) <--(x*z+y*v)/(v*z);\n\n\n//  220 # + x_IsList          <-- MapSingle(\"+\",x);\t// this rule is never active\n\n220 # (xlist_IsList + ylist_IsList)_(Length(xlist)=Length(ylist)) <-- Map(\"+\",{xlist,ylist});\n\nSumListSide(_x, y_IsList) <--\n[\n   Local(i,result);\n   result:={};\n   For(i:=1,i<=Length(y),i++)\n   [ DestructiveInsert(result,i,x + y[i]); ];\n   result;\n];\n\n240 # (x_IsList + _y)_Not(IsList(y)) <-- SumListSide(y,x);\n241 # (_x + y_IsList)_Not(IsList(x)) <-- SumListSide(x,y);\n\n250 # z_IsInfinity + Complex(_x,_y) <-- Complex(x+z,y);\n250 # Complex(_x,_y) + z_IsInfinity <-- Complex(x+z,y);\n\n251 # z_IsInfinity + _x <-- z;\n251 # _x + z_IsInfinity <-- z;\n\n\n250 # Undefined + _y <-- Undefined;\n250 # _x + Undefined <-- Undefined;\n\n\n\n/* Subtraction arity 1 */\n\n//50 # -0 <-- 0;\n51 # -Undefined <-- Undefined;\n54 # - (- _x)      <-- x;\n55 # (- (x_IsNumber)) <-- MathSubtract(0,x);\n100 # _x - n_IsConstant*(_x)   <-- (1-n)*x;\n100 # n_IsConstant*(_x) - _x   <-- (n-1)*x;\n\n110 # - (_x - _y) <-- y-x;\n111 # - (x_IsNumber / _y) <-- (-x)/y;\nLocalSymbols(x)\n[\n  200 # - (x_IsList) <-- MapSingle(\"-\",x);\n];\n\n/* Subtraction arity 2 */\n50  # x_IsNumber - y_IsNumber <-- MathSubtract(x,y);\n50  # x_IsNumber - y_IsNumber <-- MathSubtract(x,y);\n60  # Infinity - Infinity <-- Undefined;\n100 # 0 - _x <-- -x;\n100 # _x - 0 <-- x;\n100 # _x - _x <-- 0;\n\n110 # _x - (- _y) <-- x + y;\n110 # _x - (y_IsNegativeNumber) <-- x + (-y);\n111 # (_x + _y)- _x <-- y;\n111 # (_x + _y)- _y <-- x;\n112 # _x - (_x + _y) <-- - y;\n112 # _y - (_x + _y) <-- - x;\n113 # (- _x) - _y <-- -(x+y);\n113 # (x_IsNegativeNumber) - _y <-- -((-x)+y);\n113 # (x_IsNegativeNumber)/_y - _z <-- -((-x)/y+z);\n\n120 # ((_x-y_IsNumber) + z_IsNumber)_Not(IsNumber(x)) <-- x+(z-y);\n120 # ((_x-y_IsNumber) - z_IsNumber)_Not(IsNumber(x)) <-- x-(y+z);\n130 # ((_x-y_IsNumber) + _z)_(Not IsNumber(x) And Not IsNumber(z)) <-- (x+z)-y;\n130 # ((_x+y_IsNumber) - _z)_(Not IsNumber(x) And Not IsNumber(z)) <-- (x-z)+y;\n\n140 # (x_IsNumber - _y) + z_IsNumber <-- x+z-y;\n\n/* TODO move to this precedence everywhere? */\nLocalSymbols(x,y,xarg,yarg)\n[\n  10 # ((x_IsList) - (y_IsList))_(Length(x)=Length(y)) <--\n  [\n    Map({{xarg,yarg},xarg-yarg},{x,y});\n  ];\n];\n\n240 # (x_IsList - y_IsNonObject)_Not(IsList(y)) <-- -(y-x);\n\n241 # (x_IsNonObject - y_IsList)_Not(IsList(x)) <--\n[\n   Local(i,result);\n   result:={};\n   For(i:=1,i<=Length(y),i++)\n   [ DestructiveInsert(result,i,x - y[i]); ];\n   result;\n];\n\n250 # z_IsInfinity - Complex(_x,_y) <-- Complex(-x+z,-y);\n250 # Complex(_x,_y) - z_IsInfinity <-- Complex(x-z,y);\n\n251 # z_IsInfinity - _x <-- z;\n251 # _x - z_IsInfinity <-- -z;\n\n250 # Undefined - _y <-- Undefined;\n250 # _x - Undefined <-- Undefined;\n// fractions\n210 # x_IsNumber - (y_IsNumber / z_IsNumber) <--(x*z-y)/z;\n210 # (y_IsNumber / z_IsNumber) - x_IsNumber <--(y-x*z)/z;\n210 # (x_IsNumber / v_IsNumber) - (y_IsNumber / z_IsNumber) <--(x*z-y*v)/(v*z);\n\n\n/* Multiplication */\n\n50  # x_IsNumber * y_IsNumber <-- MathMultiply(x,y);\n100 #  1  * _x  <-- x;\n100 # _x  *  1  <-- x;\n100 # (_f  * _x)_(f= -1)  <-- -x;\n100 # (_x  * _f)_(f= -1)  <-- -x;\n\n95 # x_IsMatrix * y_IsMatrix <--\n[\n   Check(Length(x[1]) = Length(y), \"matrix product: incompatible matrix sizes\");\n   Local(i,j,k,row,result);\n   result:=ZeroMatrix(Length(x),Length(y[1]));\n   For(i:=1,i<=Length(x),i++)\n   For(j:=1,j<=Length(y),j++)\n   For(k:=1,k<=Length(y[1]),k++)\n   [\n     row:=result[i];\n     row[k]:= row[k]+x[i][j]*y[j][k];\n   ];\n   result;\n];\n\n\n96 # x_IsMatrix * y_IsList <--\n[\n   Local(i,result);\n   result:={};\n   For(i:=1,i<=Length(x),i++)\n   [ DestructiveInsert(result,i,x[i] . y); ];\n   result;\n];\n\n\n97 # (x_IsList * y_IsNonObject)_Not(IsList(y)) <-- y*x;\n98 # (x_IsNonObject * y_IsList)_Not(IsList(x)) <--\n[\n   Local(i,result);\n   result:={};\n   For(i:=1,i<=Length(y),i++)\n   [ DestructiveInsert(result,i,x * y[i]); ];\n   result;\n];\n\n\n50  # _x * Undefined <-- Undefined;\n50  # Undefined * _y <-- Undefined;\n\n\n100  # 0 * Infinity <-- Undefined;\n100  # Infinity * 0 <-- Undefined;\n\n101 # 0    * (_x) <-- 0;\n101 # (_x) *    0 <-- 0;\n\n100 # x_IsNumber * (y_IsNumber * _z) <-- (x*y)*z;\n100 # x_IsNumber * (_y * z_IsNumber) <-- (x*z)*y;\n\n100 # ((x_IsNumber * _y) * _z)_(Not IsNumber(y) And Not IsNumber(z)) <-- x*(y*z);\n\n100 # (_x * _y) * _y <-- x * y^2;\n100 # (_x * _y) * _x <-- y * x^2;\n100 # _y * (_x * _y) <-- x * y^2;\n100 # _x * (_x * _y) <-- y * x^2;\n100 # _x * (_y / _z) <-- (x*y)/z;\n// fractions\n100 # (_y / _z) * _x <-- (x*y)/z;\n100 # (_x * y_IsNumber)_Not(IsNumber(x)) <-- y*x;\n\n100 # (_x) * (_x) ^ (n_IsConstant) <-- x^(n+1);\n100 # (_x) ^ (n_IsConstant) * (_x) <-- x^(n+1);\n100 # (_x * _y)* _x ^ n_IsConstant <-- y * x^(n+1);\n100 # (_y * _x)* _x ^ n_IsConstant <-- y * x^(n+1);\n\n105 # x_IsNumber * -(_y) <-- (-x)*y;\n105 # (-(_x)) * (y_IsNumber) <-- (-y)*x;\n\n106 # _x * -(_y) <-- -(x*y);\n106 # (- _x) * _y <-- -(x*y);\n\n107 # -( (-(_x))/(_y)) <-- x/y;\n107 # -( (_x)/(-(_y))) <-- x/y;\n\n\n250  # x_IsNumber * y_IsInfinity <-- Sign(x)*y;\n250  # x_IsInfinity * y_IsNumber <-- Sign(y)*x;\n\n260 # x_IsInfinity * y_IsInfinity <-- Sign(x) * Sign(y) * Infinity;\n\n275 # (x_IsConstant * y_IsInfinity)_IsNumber(`N(@x)) <-- `N(@x) * y;\n275 # (x_IsInfinity * y_IsConstant)_IsNumber(`N(@y)) <-- x * `N(@y);\n\n/* Note: this rule MUST be past all the transformations on\n * matrices, since they are lists also.\n */\n230 # (aLeft_IsList * aRight_IsList)_(Length(aLeft)=Length(aRight)) <--\n\t Map(\"*\",{aLeft,aRight});\n// fractions\n242 # (x_IsInteger / y_IsInteger) * (v_IsInteger / w_IsInteger) <-- (x*v)/(y*w);\n243 #  x_IsInteger * (y_IsInteger / z_IsInteger) <--  (x*y)/z;\n243 #  (y_IsInteger / z_IsInteger) * x_IsInteger <--  (x*y)/z;\n\n400 # (_x) * (_x) <-- x^2;\n\n// 605 # ((_x * y_IsAtom)*z_IsAtom)_(LessThan(String(z), String(y))) <-- (x * z) * y;\n// 605 # ((_x * (y_IsAtom)^_p)*z_IsAtom)_(LessThan(String(z), String(y))) <-- (x * z) * y^p;\n// 605 # ((_x * y_IsAtom)*(z_IsAtom)^_q)_(LessThan(String(z), String(y))) <-- (x * z^q) * y;\n// 605 # ((_x * (y_IsAtom)^_p)*(z_IsAtom)^_q)_(LessThan(String(z), String(y))) <-- (x * z^q) * y^p;\n\n// 610 # (x_IsAtom * y_IsAtom)_(Not IsNumber(x) And LessThan(String(y), String(x))) <-- (y * x);\n// 610 # ((x_IsAtom)^_p * y_IsAtom)_(Not IsNumber(x) And LessThan(String(y), String(x))) <-- (y * x^p);\n// 610 # (x_IsAtom * (y_IsAtom)^_q)_(Not IsNumber(x) And LessThan(String(y), String(x))) <-- (y^q * x);\n// 610 # ((x_IsAtom)^_p * (y_IsAtom)^_q)_(Not IsNumber(x) And LessThan(String(y), String(x))) <-- (y^q * x^p);\n\n// 620 # ((_x * y_IsFunction) * z_IsAtom)_(Not Equals(Type(y),\"*\") And Not Equals(Type(y),\"^\")) <-- (x * z) * y;\n// 620 # ((_x * (y_IsFunction)^_p) * z_IsAtom)_(Not Equals(Type(y),\"*\") And Not Equals(Type(y),\"^\")) <-- (x * z) * y^p;\n// 620 # (x_IsFunction * y_IsAtom)_(Not Equals(Type(x),\"*\") And Not Equals(Type(x),\"^\") And y != Infinity) <-- y * x;\n// 620 # ((x_IsFunction)^_p * y_IsAtom)_(Not Equals(Type(x),\"*\") And Not Equals(Type(x),\"^\") And y != Infinity) <-- y * x^p;\n\n/* Division */\n\n50 # 0 / 0 <-- Undefined;\n\n52 # x_IsPositiveNumber / 0 <-- Infinity;\n52 # x_IsNegativeNumber / 0 <-- -Infinity;\n55 # (_x / y_IsNumber)_(IsZero(y)) <-- Undefined;\n55 # 0 / _x <-- 0;\n60 # (x_IsNumber / y_IsNumber)_(InNumericMode() Or\n                                Not(IsInteger(x) Or IsInteger(y))) <--\n    MathDivide(x,y);\n\n// unnecessary rule (see #100 below). TODO: REMOVE\n//55 # x_IsNumber / y_IsNegativeNumber <-- (-x)/(-y);\n\n56 # (x_IsNonZeroInteger / y_IsNonZeroInteger)_(MathGcd(x,y) > 1) <--\n     [\n       Local(gcd);\n       Set(x,x);\n       Set(y,y);\n       Set(gcd,MathGcd(x,y));\n       MathDiv(x,gcd)/MathDiv(y,gcd);\n     ];\n\n57 # ((x_IsNonZeroInteger * _expr) / y_IsNonZeroInteger)_(MathGcd(x,y) > 1) <--\n     [\n       Local(gcd);\n       Set(x,x);\n       Set(y,y);\n       Set(gcd,MathGcd(x,y));\n       (MathDiv(x,gcd)*expr)/MathDiv(y,gcd);\n     ];\n\n57 # ((x_IsNonZeroInteger) / (y_IsNonZeroInteger * _expr))_(MathGcd(x,y) > 1) <--\n     [\n       Local(gcd);\n       Set(x,x);\n       Set(y,y);\n       Set(gcd,MathGcd(x,y));\n       MathDiv(x,gcd)/(MathDiv(y,gcd)*expr);\n     ];\n\n57 # ((x_IsNonZeroInteger * _p) / (y_IsNonZeroInteger * _q))_(MathGcd(x,y) > 1) <--\n     [\n       Local(gcd);\n       Set(x,x);\n       Set(y,y);\n       Set(gcd,MathGcd(x,y));\n       (MathDiv(x,gcd)*p)/(MathDiv(y,gcd)*q);\n     ];\n\n\n90 # x_IsInfinity / y_IsInfinity <-- Undefined;\n95  # x_IsInfinity / y_IsNumber <-- Sign(y)*x;\n95  # x_IsInfinity / y_IsComplex <-- Infinity;\n\n90 # Undefined / _y <-- Undefined;\n90 # _y / Undefined <-- Undefined;\n\n\n100 # _x / _x <-- 1;\n100 # _x /  1 <-- x;\n100 # (_x / y_IsNegativeNumber) <-- -x/(-y);\n100 # (_x / - _y) <-- -x/y;\n// fractions\n200 # (_x / _y)/ _z <-- x/(y*z);\n230 # _x / (_y / _z) <-- (x*z)/y;\n\n240 # (xlist_IsList / ylist_IsList)_(Length(xlist)=Length(ylist)) <--\n\t Map(\"/\",{xlist,ylist});\n\n\n250 # (x_IsList / _y)_(Not(IsList(y))) <--\n[\n   Local(i,result);\n   result:={};\n   For(i:=1,i<=Length(x),i++)\n   [ DestructiveInsert(result,i,x[i] / y); ];\n   result;\n];\n\n250 # (_x / y_IsList)_(Not(IsList(x))) <--\n[\n   Local(i,result);\n   result:={};\n   For(i:=1,i<=Length(y),i++)\n   [ DestructiveInsert(result,i,x/y[i]); ];\n   result;\n];\n\n250 # _x / Infinity <-- 0;\n250 # _x / (-Infinity) <-- 0;\n\n\n400 # 0 / _x <-- 0;\n\n/* Faster version of raising power to 0.5 */\n50 # _x ^ (1/2) <-- Sqrt(x);\n50 # (x_IsPositiveNumber ^ (1/2))_IsInteger(MathSqrt(x)) <-- MathSqrt(x);\n58 # 1 ^ n_IsInfinity <-- Undefined;\n59 # _x ^ 1 <-- x;\n59 # 1 ^ _n <-- 1;\n59 # x_IsZero ^ y_IsZero <-- Undefined;\n60 # (x_IsZero ^ n_IsRationalOrNumber)_(n>0) <-- 0;\n60 # (x_IsZero ^ n_IsRationalOrNumber)_(n<0) <-- Infinity;\n// This is to fix:\n// In> 0.0000^2\n// Out> 0.0000^2;\n// In> 0.0^2/2\n// Out> 0.0^2/2;\n//60 # (x_IsNumber ^ n_IsRationalOrNumber)_(x+1=1) <-- 0;\n\n59 # _x ^ Undefined <-- Undefined;\n59 # Undefined ^ _x <-- Undefined;\n\n/* Regular raising to the power. */\n61 # Infinity ^ (y_IsNegativeNumber) <-- 0;\n61 # (-Infinity) ^ (y_IsNegativeNumber) <-- 0;\n//61 # x_IsPositiveNumber ^ y_IsPositiveNumber <-- MathPower(x,y);\n//61 # x_IsPositiveNumber ^ y_IsNegativeNumber <-- (1/MathPower(x,-y));\n// integer powers are very fast\n61 # x_IsPositiveNumber ^ y_IsPositiveInteger <-- MathIntPower(x,y);\n61 # x_IsPositiveNumber ^ y_IsNegativeInteger <-- 1/MathIntPower(x,-y);\n65 # (x_IsPositiveNumber ^ y_IsNumber)_InNumericMode() <-- Exp(y*Ln(x));\n\n90 # (-_x)^m_IsEven <-- x^m;\n91 # (x_IsConstant ^ (m_IsOdd / p_IsOdd))_(IsNegativeNumber(Re(N(Eval(x))))) <--\n     -((-x)^(m/p));\n92 # (x_IsNegativeNumber ^ y_IsNumber)_InNumericMode() <-- Exp(y*Ln(x));\n\n\n70  # (_x ^ m_IsRationalOrNumber) ^ n_IsRationalOrNumber <-- x^(n*m);\n\n80 # (x_IsNumber/y_IsNumber) ^ n_IsPositiveInteger <-- x^n/y^n;\n80 # (x_IsNumber/y_IsNumber) ^ n_IsNegativeInteger <-- y^(-n)/x^(-n);\n80 # x_IsNegativeNumber ^ n_IsEven <-- (-x)^n;\n80 # x_IsNegativeNumber ^ n_IsOdd <-- -((-x)^n);\n\n\n100  # ((_x)*(_x ^ _m)) <-- x^(m+1);\n100  # ((_x ^ _m)*(_x)) <-- x^(m+1);\n100  # ((_x ^ _n)*(_x ^ _m)) <-- x^(m+n);\n\n100  # ((x_IsNumber)^(n_IsInteger/(_m)))_(n>1) <-- MathIntPower(x,n)^(1/m);\n\n100 # Sqrt(_n)^(m_IsEven) <-- n^(m/2);\n\n\n200 # x_IsMatrix ^ n_IsPositiveInteger <-- x*(x^(n-1));\n204 # (xlist_IsList ^ nlist_IsList)_(Length(xlist)=Length(nlist)) <--\n\t Map(\"^\",{xlist,nlist});\n205 # (xlist_IsList ^ n_IsConstant)_(Not(IsList(n))) <--\n\t Map({{xx},xx^n},{xlist});\n206 # (_x ^ n_IsList)_(Not(IsList(x))) <-- Map({{xx},x^xx},{n});\n249 # x_IsInfinity ^ 0 <-- Undefined;\n250 # Infinity ^ (_n) <-- Infinity;\n250 # Infinity ^ (_x_IsComplex) <-- Infinity;\n250 # ((-Infinity) ^ (n_IsNumber))_(IsEven(n)) <-- Infinity;\n250 # ((-Infinity) ^ (n_IsNumber))_(IsOdd(n)) <-- -Infinity;\n\n250 # (x_IsNumber ^ Infinity)_(x> -1 And x < 1) <-- 0;\n250 # (x_IsNumber ^ Infinity)_(x> 1) <-- Infinity;\n\n// these Magnitude(x)s should probably be changed to Abs(x)s\n\n250 # (x_IsComplex ^ Infinity)_(Magnitude(x) > 1) <-- Infinity;\n250 # (x_IsComplex ^ Infinity)_(Magnitude(x) < -1) <-- -Infinity;\n250 # (x_IsComplex ^ Infinity)_(Magnitude(x) > -1 And Magnitude(x) < 1) <-- 0;\n\n250 # (x_IsNumber ^ -Infinity)_(x> -1 And x < 1) <-- Infinity;\n250 # (x_IsNumber ^ -Infinity)_(x< -1) <-- 0;\n250 # (x_IsNumber ^ -Infinity)_(x> 1) <-- 0;\n\n255 # (x_IsComplex ^ Infinity)_(Abs(x) = 1) <-- Undefined;\n255 # (x_IsComplex ^ -Infinity)_(Abs(x) = 1) <-- Undefined;\n\n\n\n400 # _x ^ 0 <-- 1;\n\n500 # ((x_IsPositiveInteger)^(1/y_IsPositiveInteger))_(IsEven(y) And IsInteger(MathSqrt(x))) <-- MathSqrt(x)^(1/(y/2));\n"
  },
  {
    "path": "scripts/stdarith.ys.def",
    "content": "+\n-\n*\n/\n^\n}\n"
  },
  {
    "path": "scripts/stdfuncs.rep/code.ys",
    "content": "/* Standard analytic functions */\n2 # Sin(x_IsNumber)_InNumericMode() <-- SinNum(x);\n4 # Sin(ArcSin(_x))           <-- x;\n4 # Sin(ArcCos(_x)) <-- Sqrt(1-x^2);\n4 # Sin(ArcTan(_x)) <-- x/Sqrt(1+x^2);\n5 # Sin(- _x)_(Not IsConstant(x))                 <-- -Sin(x);\n6 # (Sin(x_IsConstant))_(IsNegativeNumber(N(Eval(x))))   <-- -Sin(-x);\n\n// must prevent it from looping\n6 # Sin(x_IsInfinity)       <-- Undefined;\n6 # Sin(Undefined) <-- Undefined;\n\n110 # Sin(Complex(_r,_i)) <--\n    (Exp(I*Complex(r,i)) - Exp(- I*Complex(r,i))) / (I*2) ;\n\n1 # SinMap( _n )_(Not(IsRationalOrNumber(n))) <-- UnList({Atom(\"Sin\"),n*Pi});\n2 # SinMap( _n )_(n<0) <-- -SinMap(-n);\n2 # SinMap( _n )_(n>2) <-- SinMap(Mod(n,2));\n3 # SinMap( _n )_(n>1) <-- SinMap(n-2);\n4 # SinMap( _n )_(n>1/2) <-- SinMap(1-n);\n\n5 # SinMap( n_IsInteger ) <-- 0;\n5 # SinMap( 1/6 ) <-- 1/2;\n5 # SinMap( 1/4 ) <-- Sqrt(2)/2;\n5 # SinMap( 1/3 ) <-- Sqrt(3)/2;\n5 # SinMap( 1/2 ) <-- 1;\n5 # SinMap( 1/10) <-- (Sqrt(5)-1)/4;\n\n10 # SinMap(_n) <-- UnList({Atom(\"Sin\"),n*Pi});\n\n200 # Sin(v_CanBeUni(Pi))_(Not(InNumericMode()) And Degree(v,Pi) < 2 And Coef(v,Pi,0) = 0) <--\n[\n  SinMap(Coef(v,Pi,1));\n];\n\n2 # Cos(x_IsNumber)_InNumericMode() <-- CosNum(x);\n4 # Cos(ArcCos(_x))           <-- x;\n4 # Cos(ArcSin(_x)) <-- Sqrt(1-x^2);\n4 # Cos(ArcTan(_x)) <-- 1/Sqrt(1+x^2);\n5 # Cos(- _x)_(Not IsConstant(x))                 <-- Cos(x);\n6 # (Cos(x_IsConstant))_(IsNegativeNumber(N(Eval(x))))   <-- Cos(-x);\n// must prevent it from looping\n\n110 # Cos(Complex(_r,_i)) <--\n    (Exp(I*Complex(r,i)) + Exp(- I*Complex(r,i))) / (2) ;\n\n1 # CosMap( _n )_(Not(IsRationalOrNumber(n))) <-- UnList({Atom(\"Cos\"),n*Pi});\n2 # CosMap( _n )_(n<0) <-- CosMap(-n);\n2 # CosMap( _n )_(n>2) <-- CosMap(Mod(n,2));\n3 # CosMap( _n )_(n>1) <-- CosMap(2-n);\n4 # CosMap( _n )_(n>1/2) <-- -CosMap(1-n);\n\n5 # CosMap( 0 ) <-- 1;\n5 # CosMap( 1/6 ) <-- Sqrt(3)/2;\n5 # CosMap( 1/4 ) <-- Sqrt(2)/2;\n5 # CosMap( 1/3 ) <-- 1/2;\n5 # CosMap( 1/2 ) <-- 0;\n5 # CosMap( 2/5 ) <-- (Sqrt(5)-1)/4;\n\n6 # Cos(x_IsInfinity) <-- Undefined;\n6 # Cos(Undefined) <-- Undefined;\n10 # CosMap(_n) <-- UnList({Atom(\"Cos\"),n*Pi});\n\n200 # Cos(v_CanBeUni(Pi))_(Not(InNumericMode()) And Degree(v,Pi) < 2 And Coef(v,Pi,0) = 0) <--\n      CosMap(Coef(v,Pi,1));\n\n400 # Cos(x_IsRationalOrNumber) <--\n    [\n     Local(ll);\n     ll:= MathFloor(N(Eval(x/Pi)));\n     If(IsEven(ll),x:=(x - Pi*ll),x:=(-x + Pi*(ll+1)));\n     UnList({Cos,x});\n     ];\n\n400 # Cos(x_IsRationalOrNumber) <--\n    [\n     Local(ll);\n     ll:= MathFloor(N(Eval(Abs(x)/Pi)));\n     If(IsEven(ll),x:=(Abs(x) - Pi*ll),x:=(-Abs(x) + Pi*(ll+1)));\n     UnList({Cos,x});\n     ];\n\n\n2 # Tan(x_IsNumber)_InNumericMode() <-- TanNum(x);\n4 # Tan(ArcTan(_x))           <-- x;\n4 # Tan(ArcSin(_x)) <-- x/Sqrt(1-x^2);\n4 # Tan(ArcCos(_x)) <-- Sqrt(1-x^2)/x;\n5 # Tan(- _x)_(Not IsConstant(x))                  <-- -Tan(x);\n6 # (Tan(x_IsConstant))_(IsNegativeNumber(N(Eval(x))))   <-- -Tan(-x);\n\n// must prevent it from looping\n6 # Tan(Infinity) <-- Undefined;\n6 # Tan(Undefined) <-- Undefined;\n\n110 # Tan(Complex(_r,_i)) <-- Sin(Complex(r,i))/Cos(Complex(r,i));\n\n1 # TanMap( _n )_(Not(IsRationalOrNumber(n))) <-- UnList({Atom(\"Tan\"),n*Pi});\n2 # TanMap( _n )_(n<0) <-- -TanMap(-n);\n2 # TanMap( _n )_(n>1) <-- TanMap(Mod(n,1));\n4 # TanMap( _n )_(n>1/2) <-- -TanMap(1-n);\n\n5 # TanMap( 0 ) <-- 0;\n5 # TanMap( 1/6 ) <-- 1/3*Sqrt(3);\n5 # TanMap( 1/4 ) <-- 1;\n5 # TanMap( 1/3 ) <-- Sqrt(3);\n5 # TanMap( 1/2 ) <-- Infinity;\n\n10 # TanMap(_n) <-- UnList({Atom(\"Tan\"),n*Pi});\n\n200 # Tan(v_CanBeUni(Pi))_(Not(InNumericMode()) And Degree(v,Pi) < 2 And Coef(v,Pi,0) = 0) <--\n      TanMap(Coef(v,Pi,1));\n\n\n100 # Sin(_x)/Tan(_x) <-- Cos(x);\n100 # Sin(_x)/Cos(_x) <-- Tan(x);\n100 # Cos(_x)*Tan(_x) <-- Sin(x);\n100 # Cos(_x)/Sin(_x) <-- (1/Tan(x));\n100 # Tan(_x)/Sin(_x) <-- (1/Cos(x));\n100 # Tan(_x)*Cos(_x) <-- Sin(x);\n100 # 1/Cot(_x)     <-- Tan(x);\n100 # 1/Sec(_x)     <-- Cos(x);\n100 # 1/Csc(_x)     <-- Sin(x);\n100 # Sec(_x)       <-- 1/Cos(x);\n100 # Csc(_x)       <-- 1/Sin(x);\n100 # Cot(_x)       <-- 1/Tan(x);\n\n\n2 # Exp(x_IsNumber)_InNumericMode() <-- ExpNum(x);\n4 # Exp(Ln(_x))           <-- x;\n110 # Exp(Complex(_r,_i)) <--  Exp(r)*(Cos(i) + I*Sin(i));\n200 # Exp(0) <-- 1;\n200 # Exp(-Infinity) <-- 0;\n200 # Exp(Infinity) <-- Infinity;\n200 # Exp(Undefined) <-- Undefined;\n\n2 # Ln(0)                    <-- -Infinity;\n2 # Ln(1)                    <-- 0;\n2 # Ln(Infinity)                    <-- Infinity;\n2 # Ln(Undefined)                   <-- Undefined;\n\n/* 2 # Ln(-Infinity)                    <-- 0; */\n2 # Ln(x_IsNegativeNumber)_InNumericMode() <-- Complex(Ln(-x), Pi);\n3 # Ln(x_IsNumber)_(InNumericMode() And x>=1) <-- Internal'LnNum(x);\n4 # Ln(Exp(_x))              <-- x;\n\n3 # Ln(Complex(_r,_i)) <-- Complex(Ln(Abs(Complex(r,i))), Arg(Complex(r,i)));\n4 # Ln(x_IsNegativeNumber) <-- Complex(Ln(-x), Pi);\n5 # Ln(x_IsNumber)_(InNumericMode() And x<1) <-- - Internal'LnNum(MathDivide(1, x));\n\n\n2 # ArcSin(x_IsNumber)_(InNumericMode() And Abs(x)<=1) <-- ArcSinNum(x);\n/// complex ArcSin\n3 # ArcSin(x_IsNumber)_InNumericMode() <-- Sign(x)*(Pi/2+I*ArcCosh(x));\n// TODO: can we do this one correctly?\n//4 # ArcSin(Sin(_x))           <-- x;\n110 # ArcSin(Complex(_r,_i)) <--\n    (- I) * Ln((I*Complex(r,i)) + ((1-(Complex(r,i)^2))^(1/2)));\n\n150 # ArcSin(- _x)_(Not IsConstant(x))             <-- -ArcSin(x);\n160 # (ArcSin(x_IsConstant))_(IsNegativeNumber(N(Eval(x)))) <-- -ArcSin(-x);\n\n200 # ArcSin(0) <-- 0;\n200 # ArcSin(1/2) <-- Pi/6;\n200 # ArcSin(Sqrt(1/2)) <-- Pi/4;\n200 # ArcSin(Sqrt(3/4)) <-- Pi/3;\n200 # ArcSin(1) <-- Pi/2;\n200 # ArcSin(_n)_(n = -1) <-- -Pi/2;\n200 # ArcSin(_n)_(-n = Sqrt(3/4)) <-- -Pi/3;\n200 # ArcSin(_n)_(-n = Sqrt(1/2)) <-- -Pi/4;\n200 # ArcSin(_n)_(-n = 1/2) <-- -Pi/6;\n\n2 # ArcCos(x_IsNumber)_InNumericMode() <-- Internal'Pi()/2-ArcSin(x);\n// TODO: can we do this one correctly?\n//4 # ArcCos(Cos(_x))           <-- x;\n5 # (ArcTan(x_IsConstant))_(IsNegativeNumber(N(Eval(x))))   <-- -ArcTan(-x);\n110 # ArcCos(Complex(_r,_i)) <--\n    (- I)*Ln(Complex(r,i) + (Complex(r,i)^2 - 1)^(1/2));\n   /* TODO check! */\n\n200 # ArcCos(0) <-- Pi/2;\n200 # ArcCos(1/2) <-- Pi/3;\n200 # ArcCos(Sqrt(1/2)) <-- Pi/4;\n200 # ArcCos(Sqrt(3/4)) <-- Pi/6;\n200 # ArcCos(1) <-- 0;\n200 # ArcCos(_n)_(n = -1) <-- Pi;\n200 # ArcCos(_n)_(-n = Sqrt(3/4)) <-- 5/6*Pi;\n200 # ArcCos(_n)_(-n = Sqrt(1/2)) <-- 3/4*Pi;\n200 # ArcCos(_n)_(-n = 1/2) <-- 2/3*Pi;\n\n//TODO fix! 4 # ArcTan(Tan(_x))           <-- x;\n4 # ArcTan(-Tan(_x))           <-- -ArcTan(Tan(x));\n110 # ArcTan(Complex(_r,_i)) <--\n     (- I*0.5)*Ln(Complex(1,Complex(r,i))/ Complex(1, - Complex(r,i)));\n\n150 # ArcTan(- _x)_(Not IsConstant(x))             <-- -ArcTan(x);\n160 # (ArcTan(x_IsConstant))_(IsNegativeNumber(N(Eval(x)))) <-- -ArcTan(-x);\n\n200 # ArcTan(Sqrt(3)) <-- Pi/3;\n200 # ArcTan(-Sqrt(3)) <-- -Pi/3;\n200 # ArcTan(1) <-- Pi/4;\n200 # ArcTan(0) <-- 0;\n200 # ArcTan(_n)_(n = -1) <-- -Pi/4;\n\n200 # ArcTan(Infinity) <-- Pi/2;\n200 # ArcTan(-Infinity) <-- -Pi/2;\n200 # ArcTan(Undefined) <-- Undefined;\n200 # ArcSin(Undefined) <-- Undefined;\n200 # ArcCos(Undefined) <-- Undefined;\n\n2 # Sinh(_x)_(InNumericMode() And (IsNumber(x) Or Type(x) = \"Complex\")) <-- N(Eval( (Exp(x)-Exp(-x))/2 ));\n2 # Cosh(_x)_(InNumericMode() And (IsNumber(x) Or Type(x) = \"Complex\")) <-- N(Eval( (Exp(x)+Exp(-x))/2 ));\n2 # Tanh(_x)_(InNumericMode() And (IsNumber(x) Or Type(x) = \"Complex\")) <-- N(Eval( Sinh(x)/Cosh(x) ));\n\n\n10 # ArcSinh(_x)_(InNumericMode() And (IsNumber(x) Or Type(x) = \"Complex\")) <-- N(Eval( Ln(x+Sqrt(x^2+1)) ));\n10 # ArcCosh(_x)_(InNumericMode() And (IsNumber(x) Or Type(x) = \"Complex\")) <-- N(Eval( Ln(x+Sqrt(x^2-1)) ));\n10 # ArcTanh(_x)_(InNumericMode() And (IsNumber(x) Or Type(x) = \"Complex\")) <-- N(Eval( Ln((1+x)/(1-x))/2 ));\n\n200 # ArcSinh(Infinity) <-- Infinity;\n200 # ArcSinh(-Infinity) <-- -Infinity;\n200 # ArcSinh(Undefined) <-- Undefined;\n200 # ArcCosh(Infinity) <-- Infinity;\n200 # ArcCosh(-Infinity) <-- Infinity+I*Pi/2;\n200 # ArcCosh(Undefined) <-- Undefined;\n200 # ArcTanh(Infinity) <-- Infinity+I*Pi/2;\n200 # ArcTanh(-Infinity) <-- -Infinity-I*Pi/2;  // this is a little silly b/c we don't support correct branch cuts yet\n200 # ArcTanh(Undefined) <-- Undefined;\n\n/* hyperbolic stuff */\n100 # 1/Coth(_x)    <-- Tanh(x);\n100 # 1/Sech(_x)    <-- Cosh(x);\n100 # 1/Csch(_x)    <-- Sinh(x);\n100 # Sech(_x)      <-- 1/Cosh(x);\n100 # Csch(_x)      <-- 1/Sinh(x);\n100 # Coth(_x)      <-- 1/Tanh(x);\n\n5   # Cosh(- _x)    <-- Cosh(x);\n5   # Sinh(- _x)    <-- -Sinh(x);\n\n100 # Sinh(_x)^2-Cosh(_x)^2     <-- 1;\n100 # Sinh(_x)+Cosh(_x)     <-- Exp(x);\n100 # Sinh(_x)-Cosh(_x)     <-- Exp(-x);\n\n// this is never activated\n//100 # Sinh(I*_x)        <-- I*Sin(x);\n//100 # Cosh(I*_x)        <-- Cos(x);\n\n100 # Sinh(_x)/Cosh(_x) <-- Tanh(x);\n100 # Sinh(_x)*Csch(_x) <-- 1;\n100 # Cosh(_x)*Sech(_x) <-- 1;\n100 # Tanh(_x)*Cosh(_x) <-- Sinh(x);\n100 # Coth(_x)*Sinh(_x) <-- Cosh(x);\n\n200 # Sinh(0)       <-- 0;\n200 # Sinh(Infinity)    <-- Infinity;\n200 # Sinh(-Infinity)   <-- -Infinity;\n200 # Sinh(ArcSinh(_x)) <-- x;\n200 # Sinh(ArcCosh(_x)) <-- Sqrt((x-1)/(x+1))*(x+1);\n200 # Sinh(ArcTanh(_x)) <-- x/Sqrt(1-x^2);\n\n200 # Cosh(0)       <-- 1;\n200 # Cosh(Infinity)    <-- Infinity;\n200 # Cosh(-Infinity)   <-- Infinity;\n200 # Cosh(ArcCosh(_x)) <-- x;\n200 # Cosh(ArcSinh(_x)) <-- Sqrt(1+x^2);\n200 # Cosh(ArcTanh(_x)) <-- 1/Sqrt(1-x^2);\n\n200 # Tanh(0)           <-- 0;\n200 # Tanh(Infinity)    <-- 1;\n200 # Tanh(-Infinity)   <-- -1;\n200 # Tanh(ArcTanh(_x)) <-- x;\n200 # Tanh(ArcSinh(_x)) <-- x/Sqrt(1+x^2);\n200 # Tanh(ArcCosh(_x)) <-- Sqrt((x-1)/(x+1))*(x+1)/x;\n\n200 # Sinh(Undefined) <-- Undefined;\n200 # Cosh(Undefined) <-- Undefined;\n200 # Tanh(Undefined) <-- Undefined;\n\nUnProtect(Abs);\n10 # Abs(Infinity)  <-- Infinity;\nProtect(Abs);\n\n/* Threading of standard analytic functions */\nSin(xlist_IsList) <-- MapSingle(\"Sin\",xlist);\nCos(xlist_IsList) <-- MapSingle(\"Cos\",xlist);\nTan(xlist_IsList) <-- MapSingle(\"Tan\",xlist);\nSinh(xlist_IsList) <-- MapSingle(\"Sinh\",xlist);\nCosh(xlist_IsList) <-- MapSingle(\"Cosh\",xlist);\nTanh(xlist_IsList) <-- MapSingle(\"Tanh\",xlist);\n\n\nArcSin(xlist_IsList) <-- MapSingle(\"ArcSin\",xlist);\nArcCos(xlist_IsList) <-- MapSingle(\"ArcCos\",xlist);\nArcTan(xlist_IsList) <-- MapSingle(\"ArcTan\",xlist);\nArcSinh(xlist_IsList) <-- MapSingle(\"ArcSinh\",xlist);\nArcCosh(xlist_IsList) <-- MapSingle(\"ArcCosh\",xlist);\nArcTanh(xlist_IsList) <-- MapSingle(\"ArcTanh\",xlist);\n\n\nExp(xlist_IsList) <-- MapSingle(\"Exp\",xlist);\nLn(xlist_IsList) <-- MapSingle(\"Ln\",xlist);\n\n2 # ArcTan(x_IsNumber)_InNumericMode() <-- ArcTanNum(x);\n"
  },
  {
    "path": "scripts/stdfuncs.rep/code.ys.def",
    "content": "ArcSin\nArcCos\nArcTan\nArcSec\nArcCsc\nArcCot\nArcSinh\nArcCosh\nArcTanh\nArcSech\nArcCsch\nArcCoth\nSin\nCos\nTan\nSec\nCsc\nCot\nSinh\nCosh\nTanh\nSech\nCsch\nCoth\nExp\nLn\n}\n\n"
  },
  {
    "path": "scripts/stdfuncs.rep/elemfuncs.ys",
    "content": "/** This file contains routines for numerical evaluation of elementary functions:\n *  MathPower, MathExp, MathSin etc.\n *  It is assumed that the arguments are real (not complex) floating-point or integer numbers. (The {InNumericMode()} flag does not have to be set.)\n *  The result is an exact integer or a floating-point number correct to Builtin'Precision'Get() digits.\n *\n *  If a better optimized version of these functions is available through the kernel,\n *  then the kernel version will automatically shadow these functions.\n *  These implementations are not necessarily the best optimized versions.\n */\n\n/// BitsToDigits(n,base) and DigitsToBits(n,base). Enough to compute at low precision.\n// this is now a call to the kernel functions, so leave as a reference implementation\nBitsToDigits(n, base) := MathFloor(0.51+n*N(Ln(2)/Ln(base),10));\nDigitsToBits(n, base) := MathFloor(0.51+n*N(Ln(base)/Ln(2),10));\n\n\n\n///  MathBitCount: count number of bits in an integer or a float number.\n/*  MathBitCount is now implemented through BigNumber::BitCount() */\n/*  so this stays here as a reference implementation */\n10 # MathBitCount(0) <-- 1;\n20 # MathBitCount(_x) _ (x<0) <-- MathBitCount(-x);\n\n30 # MathBitCount(_value) <--\n[\n    Local(nbits);\n    nbits:=0;\n    If(value<1,\n    [   // float value < 1, need to multiply by 2\n        nbits := 1;\n        While(value<1)\n        [\n            nbits--;\n            value := MathMul2Exp(value,1);\n        ];\n    ],\n    [   // need to divide by 2\n        While(value>=1)\n        [\n            nbits++;\n            value := MathMul2Exp(value, -1);\n        ];\n    ]);\n    nbits;\n];\n/**/\n\n/// MathSqrt(x).\nMathSqrt(x) := MathSqrt1(x);    // to have another function is easier for debugging\n\n/// Compute square root(x) with nonnegative x. FIXME: No precision tracking yet.\n10 # MathSqrt1(0) <-- 0;\n/// negative or non-numeric arguments give error message\n100 # MathSqrt1(_x) <-- [ Echo(\"MathSqrt: invalid argument: \", x); False;];\n\n// this is too slow at the moment\n30 # MathSqrt1(x_IsPositiveNumber) <-- x*NewtonNum({{r}, r+r*(1-x*r^2)/2}, FastPower(x,-0.5), 4, 2);\n\n30 # MathSqrt1(x_IsPositiveNumber) <-- MathSqrtFloat(x);\n\n// for integers, we need to compute Sqrt(x) to (the number of bits in x) + 1 bits to figure out whether Sqrt(x) is itself an integer. If Sqrt(x) for integer x is exactly equal to an integer, we should return the integer answer rather than the float answer. For this answer, the current precision might be insufficient, therefore we compute with potentially more digits. This is slower but we assume this is what the user wants when calling MathSqrt() on an integer.\n20 # MathSqrt1(x_IsInteger) _ (GreaterThan(x,0)) <--\n[\n    Local(result);\n    If(MathMod(x,4)<2 And MathMod(x,3)<2 And MathMod(x+1,5)<3,\n        // now the number x has a nonzero chance of being an exact square\n        [\n            // check whether increased precision would be at all necessary\n//          Echo(\"checking integer case\");\n            GlobalPush(Builtin'Precision'Get());\n            If(MathBitCount(x)+3>DigitsToBits(Builtin'Precision'Get(), 10),\n              Builtin'Precision'Set(BitsToDigits(MathBitCount(x), 10)+1));\n                // need one more digit to decide whether Sqrt(x) is integer\n            // otherwise the current precision is sufficient\n\n            // convert x to float and use the float routine\n            result := MathSqrtFloat(x+0.);\n            // decide whether result is integer: decrease precision and compare\n            If(FloatIsInt(MathSetExactBits(result, MathGetExactBits(result)-3)), result:= Floor(result+0.5));\n            Builtin'Precision'Set(GlobalPop());\n        ],\n        // now the number x cannot be an exact square; current precision is sufficient\n        result := MathSqrtFloat(x+0.)\n    );\n    // need to set the correct precision on the result - will have no effect on integer answers\n    MathSetExactBits(result, DigitsToBits(Builtin'Precision'Get(),10));\n];\n\n// This function is *only* for float and positive A!\n// The answer is only obtained at the current precision.\nMathSqrtFloat(_A) <--\n[\n    Local(bitshift, a0, x0, x0sq, targetbits, subtargetbits, gotbits, targetprec);\n    bitshift := ShiftRight(MathBitCount(A)-1,1);\n    // this is how many bits of precision we need\n    targetprec := Builtin'Precision'Get();\n    // argument reduction: a0 is between 1 and 4 and has the full target precision\n    a0 := MathMul2Exp(A, -bitshift*2);  // this bit shift would be wrong for integer A\n    Builtin'Precision'Set(10);  // enough to compute at this point\n    // cannot get more target bits than 1 + (the bits in A)\n    // if this is less than the requested precision, the result will be silently less precise, but c'est la vie\n    targetbits := Min(DigitsToBits(targetprec, 10), 1+MathGetExactBits(A));\n    // initial approximation\n    x0 := MathDivide(14+22*a0, 31+5*a0);\n    // this approximation gives at least 7 bits (relative error < 0.005) of Sqrt(a0) for 1 <= a0 <= 4\n    gotbits := 7;\n    // find the conditions for the last 2 iterations to be done in almost optimal precision\n    subtargetbits := MathDiv(targetbits+8, 9);\n    If(gotbits >= subtargetbits, subtargetbits := MathDiv(targetbits+2, 3));\n    If(gotbits >= subtargetbits, subtargetbits := targetbits*4);\n//  Echo(\"debug: subtargetbits=\", subtargetbits, \"a0=\", a0, \"targetbits=\", targetbits, \"bitshift=\", bitshift, \"targetprec=\", targetprec);\n    // now perform Halley iterations until we get at least subtargetbits, then start with subtargetbits and perform further Halley iterations\n    While(gotbits < targetbits)\n    [\n        gotbits := 3*gotbits+1; // Halley iteration; get 3n+2 bits, allow 1 bit for roundoff\n        // check for suboptimal last iterations\n        If(gotbits >= subtargetbits,\n        [   // it could be very suboptimal to continue with our value of gotbits, so we curb precision for the last 2 iterations which dominate the calculation time at high precision\n            gotbits := subtargetbits;\n            subtargetbits := targetbits*4;  // make sure that the above condition never becomes true again\n        ]);\n        Builtin'Precision'Set(BitsToDigits(gotbits, 10)+2); // guard digits\n        x0 := MathSetExactBits(x0, gotbits+6);  // avoid roundoff\n        x0sq := MathMultiply(x0, x0);\n// this gives too much roundoff error       x0 := MathMultiply(x0, MathDivide(3*a0+x0sq, a0+3*x0sq));\n// rather use this equivalent formula:\n        x0 := MathAdd(x0, MathMultiply(x0*2, MathDivide(a0-x0sq, a0+3*x0sq)));\n//      Echo(\"debug: \", gotbits, x0, MathGetExactBits(x0), Builtin'Precision'Get());\n    ];\n    // avoid truncating a precise result in x0 by calling Builtin'Precision'Set() too soon\n    x0 := MathSetExactBits(MathMul2Exp(x0, bitshift), gotbits);\n    Builtin'Precision'Set(targetprec);\n//  Echo(\"debug: answer=\", x0);\n    x0;\n];\n\n//{BisectSqrt(N)} computes the integer part of $ Sqrt(N) $ for integer $N$.\n// BisectSqrt() works only on integers\n    //sqrt(1) = 1, sqrt(0) = 0\n10 # BisectSqrt(0) <-- 0;\n10 # BisectSqrt(1) <-- 1;\n\n20 # BisectSqrt(N_IsPositiveInteger) <--\n[\n  Local(l2,u,v,u2,v2,uv2,n);\n\n  // Find highest set bit, l2\n  u  := N;\n  l2 := MathBitCount(u)-1;\n\n  // 1<<(l2/2) now would be a good under estimate\n  // for the square root. 1<<(l2/2) is definitely\n  // set in the result. Also it is the highest\n  // set bit.\n  l2 := l2>>1;\n\n  // initialize u and u2 (u2==u^2).\n  u  := 1 << l2;\n  u2 := u << l2;\n\n  // Now for each lower bit:\n  While( l2 != 0 )\n  [\n     l2--;\n     // Get that bit in v, and v2 == v^2.\n      v  := 1<<l2;\n      v2 := v<<l2;\n\n      // uv2 == 2*u*v, where 2==1<<1, and\n      // v==1<<l2, thus 2*u*v ==\n      // (1<<1)*u*(1<<l2) == u<<(l2+1)\n      uv2 := u<<(l2 + 1);\n\n      // n = (u+v)^2  = u^2 + 2*u*v + v^2\n      //   = u2+uv2+v2\n       n := u2 + uv2 + v2;\n\n      // if n (possible new best estimate for\n      // sqrt(N)^2 is smaller than N, then the\n      // bit l2 is set in the result, and\n      // add v to u.\n      if( n <= N )\n      [\n    u  := u+v;  // u <- u+v\n    u2 := n;    // u^2 <- u^2 + 2*u*v + v^2\n      ];\n    ];\n    u; // return result, accumulated in u.\n];\n\n/// MathGcd(x,y). Compute the GCD of two integers using the binary Euclidean algorithm.\n5 # MathGcd(x_IsNegativeInteger, y_IsInteger) <-- MathGcd(-x, y);\n5 # MathGcd(y_IsNegativeInteger, x_IsNegativeInteger) <-- MathGcd(x, -y);\n6 # MathGcd(0, _x) <-- 0;\n6 # MathGcd(_x, 0) <-- 0;\n\n10 # MathGcd(x_IsInteger, y_IsInteger) <--\n[\n    Local(z);\n    While(x!=y)\n    [\n        While(x<y)\n        [\n            y:=y-x;\n            While((y&1) = 0)\n            [\n                y := ShiftRight(y,1);\n            ];\n        ];\n        z:=x;\n        x:=y;\n        y:=z;\n    ];\n    x;\n];\n\n/// Identity transformation, compute Exp(x)-1 from value=Exp(x/2^n)-1\n\nMathExp'Doubling1(value, n) :=\n[\n    Local(shift, result);\n    shift := n;\n    result := value;\n    While (shift>0) // lose 'shift' bits of precision here\n    [\n        result := MathMul2Exp(result, 1) + MathMultiply(result, result);\n        shift--;\n    ];\n    result;\n];\n\n/// Identity transformation, compute Exp(x) from value=Exp(x/2^n)\n/*\nMathExp'Doubling(value, n) :=\n[\n    Local(shift, result);\n    shift := n;\n    result := value;\n    While (shift>0) // lose 'shift' bits of precision here\n    [\n        result := MathMultiply(result, result);\n        shift--;\n    ];\n    result;\n];\n*/\n\n/// Compute Exp(x)-1 from the Taylor series for (Exp(x)-1)/x.\nMathExp'Taylor1(x) :=\n[\n    Local(num'terms, prec, Bx);\n    prec := MathDiv(Builtin'Precision'Get()*3919, 1702); // P*Ln(10)\n    Bx := -MathDiv(MathBitCount(x)*1143, 1649)-2; // -Ln(x)-2\n    num'terms := MathDiv( prec-1, MathDiv( MathBitCount( prec-1)*1588, 2291)+Bx)+1;\n    // (P*Ln(10)-1)/(Ln(P*Ln(10)-1)-Ln(x)-2); use Ln(x)<=B(x)*Ln(2)\n    x*SumTaylorNum(x, 1, {{k}, 1/(k+1)}, num'terms);\n];\n\n/// Compute Sin(x), Taylor series for Sin(x)/x\nMathSin'Taylor(x) :=\n[\n    Local(num'terms, prec, Bx);\n    prec := MathDiv(Builtin'Precision'Get()*3919, 1702); // P*Ln(10)\n    Bx := -MathDiv(MathBitCount(x)*1143, 1649)-2; // -Ln(x)-2\n    num'terms := MathDiv( MathDiv( prec+Bx, MathDiv( MathBitCount( prec+Bx)*1588, 2291)+Bx)+1, 2)+1;\n    // (P*Ln(10)-Ln(x)-2)/(Ln(P*Ln(10)-Ln(x)-2)-Ln(x)-2); use Ln(x)<=B(x)*Ln(2)\n    x*SumTaylorNum(MathMultiply(x,x), 1, {{k}, -1/(2*k*(2*k+1))}, num'terms);\n];\n\n/// Identity transformation, compute Sin(x) from value=Sin(x/3^n)\n\nMathSin'Tripling(value, n) :=\n[\n    Local(shift, result);\n    shift := n;\n    result := value;\n    While (shift>0) // lose 'shift' bits of precision here\n    [   // Sin(x)*(3-4*Sin(x)^2)\n        result := MathMultiply(result, 3 - MathMul2Exp(MathMultiply(result,result), 2) );\n        shift--;\n    ];\n    result;\n];\n\n\n/// Cos(x), Taylor series\nMathCos'Taylor(x) :=\n[\n    Local(num'terms, prec, Bx);\n    prec := MathDiv(Builtin'Precision'Get()*3919, 1702); // P*Ln(10)\n    Bx := -MathDiv(MathBitCount(x)*1143, 1649)-2; // -Ln(x)-2\n    num'terms := MathDiv( MathDiv( prec-1, MathDiv( MathBitCount( prec-1)*1588, 2291)+Bx), 2)+1;\n    // (P*Ln(10)-1)/(Ln(P*Ln(10)-1)-Ln(x)-2); use Ln(x)<=B(x)*Ln(2)\n    SumTaylorNum(MathMultiply(x,x), 1, {{k}, -1/(2*k*(2*k-1))}, num'terms);\n];\n\n/// Identity transformation, compute 1-Cos(x) from value=1-Cos(x/2^n)\n\nMathCos'Doubling1(value, n) :=\n[\n    Local(shift, result);\n    shift := n;\n    result := value;\n    While (shift>0) // lose 'shift' bits of precision here\n    [\n        result := MathMultiply(MathMul2Exp(result, 1), 2 - result);\n        shift--;\n    ];\n    result;\n];\n\n\n/// Ln(x), Taylor series for Ln(1+y)/y, use only with 1/2<x<3/2\nMathLn'Taylor(x) :=\n[\n    Local(num'terms, y);\n    y := x-1;\n    num'terms := MathDiv(Builtin'Precision'Get()*2136, -643*MathBitCount(y))+1;\n    // (P*Ln(10))/(-Ln(y)); use Ln(y)<=B(y)*Ln(2), only good for |y|<1/2\n    // here -Ln(y) must be positive\n    y*SumTaylorNum(-y, {{k}, 1/(k+1)}, num'terms);\n];\n\n/// Compute Ln(x) from Ln(x^(2^(1/n)))\nMathLn'Doubling(value, n) :=\n[\n    Local(shift, result);\n    shift := n;\n    result := value;\n    While (shift>0) // lose 'shift' bits of precision here\n    [\n        result := MathMultiply(result, result);\n        shift--;\n    ];\n    result;\n];\n\n/// ArcTan(x), Taylor series for ArcTan(x)/x, use only with -1/2<x<1/2\nMathArcTan'Taylor(x) :=\n[\n    Local(num'terms);\n    num'terms := MathDiv(Builtin'Precision'Get()*1068, -643*MathBitCount(x))+1;\n    // (P*Ln(10))/(-2*Ln(x)); use Ln(x)<=B(x)*Ln(2), only good for |x|<1/2\n    // here -Ln(x) must be positive\n    x*SumTaylorNum(-MathMultiply(x,x), {{k}, 1/(2*k+1)}, num'terms);\n];\n\nUnProtect(MathPi);\n\n/// The constant Pi. Using a simple method, solve Cos(x)=0.\n// iterate x := x + Cos(x) + 1/6 *Cos(x)^3 + ... to converge to x=Pi/2\nMathPi() :=\n[\n    Local(result, delta, deltasq, k, order, prec, curprec);\n    order := 13;    // order of approximation\n    prec := Builtin'Precision'Get();\n  N([\n    /* initial approximation */\n    curprec := 20;\n    Builtin'Precision'Set(curprec);\n    result := 3.14159265358979323846*0.5;\n    // find optimal initial precision\n    For(k:=prec, k>=curprec, k:=Div(k,order)+2) True;\n    If(k<5, curprec:=5, curprec:=k);\n  //    Echo(\"initial precision\", curprec);\n    // now k is the iteration counter\n    For(k:=0, curprec < prec, k := k+1) [\n    // at this iteration we know the result to curprec digits\n      curprec := Min(prec, curprec * order-2);  // 2 guard digits\n      Builtin'Precision'Set(curprec+2);\n  //        Echo(\"Iteration \", k, \" setting precision to \", Builtin'Precision'Get());\n  //        Echo(\"old result=\", MathCos(result));\n      /*Time*/([\n      delta := MathCos(result);\n      ]);\n      /*Time*/([\n      deltasq := MathMultiply(delta,delta);\n      ]);\n      result := /*Time*/(result + delta*(1 + deltasq*(1/6 + deltasq*(3/40 + deltasq*(5/112 + deltasq*(35/1152 + (deltasq*63)/2816))))));\n    ];\n  //    Echo({\"Method 3, using Pi/2 and order\", order, \":\", k, \"iterations\"});\n  ]);\n    result*2;\n];\n\nProtect(MathPi);\n"
  },
  {
    "path": "scripts/stdfuncs.rep/elemfuncs.ys.def",
    "content": "BitsToDigits\nDigitsToBits\nMathArcCos\nMathArcTan\nMathGcd\nMathSqrt\n}\n"
  },
  {
    "path": "scripts/stdfuncs.rep/numerical.ys",
    "content": "/// low-level numerical calculations of elementary functions.\n/// These are only called if InNumericMode() returns True\n\n//////////////////////////////////////////////////\n/// Trigonometric functions: Sin, Cos, Tan, ...\n//////////////////////////////////////////////////\n\n/* TruncRadian truncates the radian r so it is between 0 and 2*Pi.\n * It calculates r mod 2*Pi using the required precision.\n */\nTruncRadian(_r) <--\n[\n  Local(twopi);\n  // increase precision by the number of digits of r before decimal point; enough to evaluate Abs(r) with 1 digit of precision\n  N([\n    r:=Eval(r);\n    twopi:=2*Internal'Pi();\n    r:=r-MathFloor(r/twopi)*twopi;\n  ], Builtin'Precision'Get() + IntLog(Ceil(Abs(N(Eval(r), 1))), 10));\n  r;\n];\nHoldArg(\"TruncRadian\",r);\n\nSinNum(x) :=\n[\n  If(x<0 Or 113*x>710, x:=TruncRadian(x));\t// 710/113 is close to 2*Pi\n  MathSin(x);\n];\nCosNum(x) :=\n[\n  If(x<0 Or 113*x>710, x:=TruncRadian(x));\n  MathCos(x);\n];\nTanNum(x) :=\n[\n  If(x<0 Or 113*x>710, x:=TruncRadian(x));\n  MathTan(x);\n];\n\nArcSinNum(x) :=\n[\n\t// need to be careful when |x| close to 1\n\tIf(\n\t\t239*Abs(x) >= 169,\t// 169/239 is a good enough approximation of 1/Sqrt(2)\n\t\t// use trigonometric identity to avoid |x| close to 1\n\t\tSign(x)*(Internal'Pi()/2-MathArcSin(Sqrt(1-x^2))),\n\t\tMathArcSin(x)\n\t);\n];\n\n//////////////////////////////////////////////////\n/// Exponent\n//////////////////////////////////////////////////\n\nLocalSymbols(mathExpThreshold) [\n  // improve convergence of Exp(x) for large x\n  mathExpThreshold := If(Not IsBound(mathExpThreshold), 500);\n\n  MathExpThreshold() := mathExpThreshold;\n  SetMathExpThreshold(threshold) := [mathExpThreshold:= threshold; ]; \n];\n\n// large positive x\n10 # ExpNum(x_IsNumber) _ (x > MathExpThreshold()) <-- [\n\tLocal(i, y);\n\ti:=0;\n\tFor(i:=0, x > MathExpThreshold(), i++)\n\t\tx := MathDivide(x, 2.);\n\tFor(y:= MathExp(x), i>0, i--)\n\t\ty := MathMultiply(y, y);\n\ty;\n\t\n];\n// large negative x\n20 # ExpNum(x_IsNumber) _ (2*x < -MathExpThreshold()) <-- MathDivide(1, ExpNum(-x));\n// other values of x\n30 # ExpNum(x_IsNumber) <-- MathExp(x);\n\n//////////////////////////////////////////////////\n/// Natural logarithm\n//////////////////////////////////////////////////\n\n//  MathLog in the original C++ code hangs! Scripted implementation is much better\nMathLog(x) := Internal'LnNum(x);\n\n// natural logarithm: this should be called only for real x>1\n//Internal'LnNum(x) := MathLog(x);\n// right now the fastest algorithm is Halley's method for Exp(x)=a\n// when internal math is fixed, we may want to use Brent's method (below)\n// this method is using a cubically convergent Newton iteration for Exp(x/2)-a*Exp(-x/2)=0:\n// x' := x - 2 * (Exp(x)-a) / (Exp(x)+a) = x-2+4*a/(Exp(x)+a)\nInternal'LnNum(x_IsNumber)_(x>=1) <-- NewtonLn(x);\n\nInternal'LnNum(x_IsNumber)_(0<x And x<1) <-- - Internal'LnNum(MathDivide(1,x));\n\nNewtonLn(x) :=\n\tLocalSymbols(y)\n[\n// we need MathExp instead of Exp to avoid N() which is used in the definition of Exp.\n// and we need ExpNum() instead of MathExp so that it is faster for large arguments and to avoid the error generated when core functions like MathExp are called on symbolic arguments.\n\tNewtonNum({{y}, 4*x/(ExpNum(y)+x)-2+y},\n\t// initial guess is obtained as Ln(x^2)/Ln(2) * (Ln(2)/2)\n\t\tMathDivide(794*IntLog(Floor(x*x), 2), 2291), 10, 3);\n];\n\n/* The BrentLn() algorithm is currently slower in internal math but should be asymptotically faster.\n\n// compute Ln(x_IsInteger) using the AGM sequence. See: Brent paper rpb028 (1975).\n// this is currently faster than MathLog(n) for precision > 40 digits\n10 # BrentLn(x_IsInteger)_(Builtin'Precision'Get()>40) <--\n[\n\tLocal(y, n, k, eps);\n\tn := Builtin'Precision'Get();\t// decimal digits\n\t// initial power of x\n\tk := 1 + Div(IntLog(4*10^n, x), 2);\t// now x^(2*k)>4*10^n\n\tBuiltin'Precision'Set(n+5);\t// guard digits\n\teps := MathDivide(1, 10^n);\t// precision\n\ty := MathPower(x, k);\t// not yet divided by 4\n\t// this is Brent's AGM times y. This way we work around the Yacas limitation of fixed precision, at cost of slightly slower initial iterations\n\ty := MathDivide(Internal'Pi()*y, (2*k)*AG'Mean(4, y, eps));\n\tBuiltin'Precision'Set(n);\n\tRoundTo(y, n);\t// do not return a more precise number than we really have\n];\n\n15 # BrentLn(x_IsInteger)  <-- MathLog(x);\n\n/// calculation of Ln(x) using Brent's AGM sequence - use precomputed Pi and Ln2.\n20 # BrentLn(_x)_(x<1) <-- -BrentLn(1/x);\n\n// this is currently faster than MathLog() for precision > 85 digits and numbers >2\n30 # BrentLn(_x)_(Builtin'Precision'Get()>85) <--\n[\n\tLocal(y, n, n1, k, eps);\n  N([\n    n := Builtin'Precision'Get();\t// decimal digits\n    // effective precision is n+Ln(n)/Ln(10)\n    n1 := n + IntLog(n,10);\t// Ln(2) < 7050/10171\n    // initial power of 2\n    k := 2 + Div(n1*28738, 2*8651)\t// Ln(10)/Ln(2) < 28738/8651; now 2^(2*k)>4*10^n1\n    // find how many binary digits we already have in x, and multiply by a sufficiently large power of 2 so that y=x*2^k is larger than 2*10^(n1/2)\n    - IntLog(Floor(x), 2);\n    // now we need k*Ln(2)/Ln(10) additional digits to compensate for cancellation at the final subtraction\n    Builtin'Precision'Set(n1+2+Div(k*3361, 11165));\t// Ln(2)/Ln(10) < 3361/11165\n    eps := MathDivide(1, 10^(n1+1));\t// precision\n    y := x*2^(k-2);\t// divided already by 4\n    // initial values for AGM\n    // this is Brent's AGM times y. This way we work around the Yacas limitation of fixed precision, at cost of slightly slower initial iterations\n    y:=Internal'Pi()*y/(2*AG'Mean(1,y,eps)) - k*Ln2();\n    Builtin'Precision'Set(n);\n  ]);\n\ty;\t// do not return a more precise number than we really have\n];\n\n40 # BrentLn(x_IsNumber) <-- MathLog(x);\n\nLocalSymbols(CacheOfConstantsN) [\n\nCachedConstant(Ln2, CacheOfConstantsN, Internal'LnNum(2)); // this is only useful for BrentLn\n/**/\n//CachedConstant(Exp1, CacheOfConstantsN, MathExp(1));       // Exp1 is useless so far\n\n];\n\n//////////////////////////////////////////////////\n/// ArcTan(x)\n//////////////////////////////////////////////////\n\nArcTanNum(x) :=\n[\n\t// using trigonometric identities is faster for now\n\tIf(\n\t\tAbs(x)>1,\n\t\tSign(x)*(Internal'Pi()/2-ArcSin(1/Sqrt(x^2+1))),\n\t\tArcSin(x/Sqrt(x^2+1))\n\t);\n];\n\n/* old methods -- slower for now\n/// numerical evaluation of ArcTan using continued fractions: top level\n2 # ArcTan(x_IsNumber)_InNumericMode() <--\nSign(x) *\n// now we need to compute ArcTan of a nonnegative number Abs(x)\n[\n\tLocal(nterms, y);\n\ty := Abs(x);\n\t// use identities to improve convergence -- see essays book\n\tIf(\n\t\ty>1,\n\t\ty:=1/y\t// now y <= 1\n\t// we shall know that the first identity was used because Abs(x) > 1 still\n\t);\n\t// use the second identity \n\ty := y/(1+Sqrt(1+y^2));\t// now y <= Sqrt(2)-1\n\t// find the required number of terms in the continued fraction\n\tnterms := 1/y;\t// this needs to be calculated at full precision\n\t// see essays book on the choice of the number of terms (added 2 \"guard terms\").\n\t// we need Hold() because otherwise, if InNumericMode() returns True, N(..., 5) will not avoid the full precision calculation of Ln().\n\t// the value of x should not be greater than 1 here!\n\tnterms := 2 + Ceil( N(Hold(Ln(10)/(Ln(4)+2*Ln(nterms))), 5) * Builtin'Precision'Get() );\n\tIf(\t// call the actual routine\n\t\tAbs(x)>1,\n\t\tPi/2-2*MyArcTan(y, nterms),\t// this is for |x|>1\n\t\t2*MyArcTan(y, nterms)\n\t\t// MyArcTan(x, nterms)\n\t);\n];\n*/\n/// numerical evaluation of ArcTan using continued fractions: low level\n\n// evaluation using recursion -- slightly faster but lose some digits to roundoff errors and needs large recursion depth\n/*\n10 # ContArcTan(_x,_n,_n) <-- (2*n-1);\n20 # ContArcTan(_x,_n,_m) <--\n[\n  (2*n-1) + (n*x)^2/ContArcTan(x,n+1,m);\n];\n\nMyArcTan(x,n) :=\n[\n  x/ContArcTan(x,1,n);\n];\n*/\n/*\n/// evaluate n terms of the continued fraction for ArcTan(x) without recursion.\n/// better control of roundoff errors\nMyArcTan(x, n) :=\n[\n\tLocal(i, p, q, t);\n\t// initial numerator and denominator\n\tp:=1;\n\tq:=1;\n\t// start evaluating from the last term upwards\n\tFor(i:=n, i>=1, i--)\n\t[\n\t\t//{p,q} := {p + q*(i*x)^2/(4*i^2-1), p};\n\t//\tt := p*(2*i-1) + q*(i*x)^2; then have to start with p:=2*n+1\n\t\tt := p + q*(i*x)^2/(4*i^2-1);\n\t\tq := p;\n\t\tp := t;\n\t];\n\t// answer is x/(p/q)\n\tx*q/p;\n];\n*/\n"
  },
  {
    "path": "scripts/stdfuncs.rep/numerical.ys.def",
    "content": "TruncRadian\nSinNum\nCosNum\nTanNum\nArcSinNum\nArcTanNum\nExpNum\nMathExpThreshold\nSetMathExpThreshold \nMathLog\nInternal'LnNum\nBrentLn\nLn2\nNewtonLn\nExp1\n}\n"
  },
  {
    "path": "scripts/stdfuncs.rep/nummethods.ys",
    "content": "/// coded by Serge Winitzki. See essays documentation for algorithms.\n\n//////////////////////////////////////////////////\n/// Numerical method: AGM sequence\n//////////////////////////////////////////////////\n\n/// compute the AGM sequence up to a given precision\nAG'Mean(a, b, eps) :=\n[\n\tLocal(a1, b1);\n\tIf(InVerboseMode(), Echo(\"AG'Mean: Info: at prec. \", Builtin'Precision'Get()));\n\t// AGM main loop\n\tWhile(Abs(a-b)>=eps)\n\t[\n\t\ta1 := MathDivide(a+b, 2);\n\t\tb1 := MathSqrt(MathMultiply(a, b));\t// avoid Sqrt() which uses N() inside it\n\t\ta := a1;\n\t\tb := b1;\n\t];\n\tMathDivide(a+b, 2);\n];\n//UnFence(AG'Mean, 3);\n\n//////////////////////////////////////////////////\n/// Numerical method: Taylor series, rectangular summation\n//////////////////////////////////////////////////\n\n/// Fast summation of Taylor series using a rectangular scheme.\n/// SumTaylorNum(x, nth'term'func, n'terms) = Sum(k, 0, n'terms, nth'term'func(k)*x^k)\n/// Note that sufficient precision must be preset to avoid roundoff errors (these methods do not modify precision).\n/// The only reason to try making these functions HoldArg is to make sure that the closures nth'term'func and next'term'factor are passed intact. But it's probably not desired in most cases because a closure might contain parameters that should be evaluated.\n\n/// The short form is used when only the nth term is known but no simple relation between a term and the next term.\n/// The long form is used when there is a simple relation between consecutive terms. In that case, the n'th term function is not needed, only the 0th term value.\n\n/// SumTaylorNum0 is summing the terms with direct methods (Horner's scheme or simple summation). SumTaylorNum1 is for the rectangular method.\n\n/// nth'term'func and next'term'func must be functions applicable to one argument.\n\n/// interface\nSumTaylorNum0(_x, _nth'term'func, _n'terms) <-- SumTaylorNum0(x, nth'term'func, {}, n'terms);\n\nSumTaylorNum1(_x, _nth'term'func, _n'terms) <-- SumTaylorNum1(x, nth'term'func, {}, n'terms);\n\n/// interface\nSumTaylorNum(_x, _nth'term'func, _n'terms) <--\nIf(\n\tn'terms >= 30,\t// threshold for calculation with next'term'factor\n\t// use the rectangular algorithm for large enough number of terms\n\tSumTaylorNum1(x, nth'term'func, n'terms),\n\tSumTaylorNum0(x, nth'term'func, n'terms)\n);\n\nSumTaylorNum(_x, _nth'term'func, _next'term'factor, _n'terms) <--\nIf(\n\tn'terms >= 5,\t// threshold for calculation with next'term'factor\n\tSumTaylorNum1(x, nth'term'func, next'term'factor, n'terms),\n\tSumTaylorNum0(x, nth'term'func, next'term'factor, n'terms)\n);\n//HoldArgNr(SumTaylorNum, 3, 2);\n\n/// straightforward algorithms for a small number of terms\n1# SumTaylorNum0(_x, _nth'term'func, {}, _n'terms) <--\n[\n\tLocal(sum, k);\n  N([\n    // use Horner scheme starting from the last term\n    x:=Eval(x);\n    sum := 0;\n    For(k:=n'terms, k>=0, k--)\n      sum := MathAdd(sum*x, nth'term'func @ k);\n  ]);\n\tsum;\n];\n\n//HoldArgNr(SumTaylorNum0, 3, 2);\n\n2# SumTaylorNum0(_x, _nth'term'func, _next'term'factor, _n'terms) <--\n[\n\tLocal(sum, k, term, delta);\n  N([\n    x:=Eval(x);\t// x must be floating-point\n    If (IsConstant(nth'term'func),\n      term := nth'term'func,\n      term := (nth'term'func @ {0}),\n    );\n    sum := term;\t// sum must be floating-point\n  ]);\n  NonN([\n    delta := 1;\n    For(k:=1, k<=n'terms And delta != 0, k++)\n    [\n      term := MultiplyNum(term, next'term'factor @ {k}, x);\t// want to keep exact fractions here, but the result is floating-point\n      delta := sum;\n      sum := sum + term;\t// term must be floating-point\n      delta := Abs(sum-delta);\t// check for underflow\n    ];\n  ]);\n\tsum;\n];\n\n/// interface\nSumTaylorNum0(_x, _nth'term'func, _n'terms) <-- SumTaylorNum0(x, nth'term'func, {}, n'terms);\n\n//HoldArgNr(SumTaylorNum0, 4, 2);\n//HoldArgNr(SumTaylorNum0, 4, 3);\n\n/// this is to be used when a simple relation between a term and the next term is known.\n/// next'term'factor must be a function applicable to one argument, so that if term = nth'term'func(k-1), then nth'term'func(k) = term / next'term'factor(k). (This is optimized for Taylor series of elementary functions.) In this case, nth'term'func is either a number, value of the 0th term, or a function.\n/// A special case: when next'term'factor is an empty list; then we act as if there is no next'term'factor available.\n/// In this case, nth'term'func must be a function applicable to one argument.\n/// Need IntLog(n'terms, 10) + 1 guard digits due to accumulated roundoff error.\nSumTaylorNum1(x, nth'term'func, next'term'factor, n'terms) :=\n[\n\t// need Sqrt(n'terms/2) units of storage (rows) and Sqrt(n'terms*2) columns. Let's underestimate the storage.\n\tLocal(sum, rows, cols, rows'tmp, last'power, i, j, x'power, term'tmp);\n  N([ // want to keep exact fractions\n    x:=Eval(x);\t// x must be floating-point\n    rows := IntNthRoot(n'terms+1, 2);\n    cols := Div(n'terms+rows, rows);\t// now: rows*cols >= n'terms+1\n    Check(rows>1 And cols>1, \"SumTaylorNum1: Internal error: number of Taylor sum terms must be at least 4\");\n    rows'tmp := Array'Create(rows, 0);\n    x'power := x ^ rows;\t// do not use MathPower b/c x might be complex\n    // initialize partial sums (array rows'tmp) - the 0th column (i:=0)\n    // prepare term'tmp for the first element\n    // if we are using next'term'factor, then term'tmp is x^(rows*i)*a[rows*i]\n    // if we are not using it, then term'tmp is x^(rows*i)\n    If(\n      next'term'factor = {},\n      term'tmp := 1,\n  //\t\tterm'tmp := (nth'term'func @ 0)\t// floating-point\n      If (IsConstant(nth'term'func),\n        term'tmp := nth'term'func,\n        term'tmp := (nth'term'func @ {0}),\n      )\n    );\n  ]);\n  NonN([ // want to keep exact fractions below\n    // do horizontal summation using term'tmp to get the first element\n    For(i:=0, i<cols, i++)\n    [\n      // add i'th term to each row\n      For(j:=0, j<rows And (i<cols-1 Or i*rows+j<=n'terms), j++)\t// do this unless we are beyond the last term in the last column\n      [\n        // if we are using next'term'factor, then term'tmp is x^(rows*i)*a[rows*i]\n        // if we are not using it, then term'tmp is x^(rows*i)\n        If(\n          next'term'factor = {},\t// no next'term'factor, so nth'term'func must be given\n          [\n            rows'tmp[j+1] := rows'tmp[j+1] + MultiplyNum(term'tmp, nth'term'func @ {i*rows+j});\n          ],\n          [\n            rows'tmp[j+1] := rows'tmp[j+1] + term'tmp;\t// floating-point\n            term'tmp := MultiplyNum(term'tmp, next'term'factor @ {i*rows+j+1});\t// arguments may be rational but the result is floating-point\n          ]\n        );\n      ];\n      // update term'tmp for the next column\n      term'tmp := term'tmp*x'power;\t// both floating-point\n    ];\n    // do vertical summation using Horner's scheme\n    // now x'power = x^cols\n    For([j:=rows; sum:=0;], j>0, j--)\n      sum := sum*x + rows'tmp[j];\n  ]);\n\tsum;\n];\n\n//HoldArgNr(SumTaylorNum, 4, 2);\n//HoldArgNr(SumTaylorNum, 4, 3);\n\n/* \nExamples:\nIn> SumTaylorNum(1,{{k}, 1/k!},{{k}, 1/k}, 10 )\nOut> 2.7182818006;\nIn> SumTaylorNum(1,{{k},1/k!}, 10 )\nOut> 2.7182818007;\n*/\n\n//////////////////////////////////////////////////\n/// Numerical method: multiply floats by rationals\n//////////////////////////////////////////////////\n\n/// aux function: optimized numerical multiplication. Use MathMultiply() and MathDivide().\n/// optimization consists of multiplying or dividing by integers if one of the arguments is a rational number. This is presumably always better than floating-point calculations, except if we use Rationalize() on everything.\n/// note that currently this is not a big optimization b/c of slow arithmetic but it already helps for rational numbers under InNumericMode() returns True and it will help even more when faster math is done\n\nFunction() MultiplyNum(x, y, ...);\nFunction() MultiplyNum(x);\n\n10 # MultiplyNum(x_IsList)_(Length(x)>1) <-- MultiplyNum(Head(x), Tail(x));\n\n10 # MultiplyNum(x_IsRational, y_IsRationalOrNumber) <--\n[\n\tIf(\n        Type(y) = \"/\",  // IsRational(y), changed by Nobbi before redefinition of IsRational\n\t\tMathDivide(Numer(x)*Numer(y), Denom(x)*Denom(y)),\n\t\t// y is floating-point\n\t\t// avoid multiplication or division by 1\n\t\tIf(\n\t\t\tNumer(x)=1,\n\t\t\tMathDivide(y, Denom(x)),\n\t\t\tIf(\n\t\t\t\tDenom(x)=1,\n\t\t\t\tMathMultiply(y, Numer(x)),\n\t\t\t\tMathDivide(MathMultiply(y, Numer(x)), Denom(x))\n\t\t\t)\n\t\t)\n\t);\n];\n\n20 # MultiplyNum(x_IsNumber, y_IsRational) <-- MultiplyNum(y, x);\n\n25 # MultiplyNum(x_IsNumber, y_IsNumber) <-- MathMultiply(x,y);\n\n30 # MultiplyNum(Complex(r_IsNumber, i_IsNumber), y_IsRationalOrNumber) <-- Complex(MultiplyNum(r, y), MultiplyNum(i, y));\n\n35 # MultiplyNum(y_IsNumber, Complex(r_IsNumber, i_IsRationalOrNumber)) <-- MultiplyNum(Complex(r, i), y);\n\n40 # MultiplyNum(Complex(r1_IsNumber, i1_IsNumber), Complex(r2_IsNumber, i2_IsNumber)) <-- Complex(MultiplyNum(r1,r2)-MultiplyNum(i1,i2), MultiplyNum(r1,i2)+MultiplyNum(i1,r2));\n\n/// more than 2 operands\n30 # MultiplyNum(x_IsRationalOrNumber, y_IsNumericList)_(Length(y)>1) <-- MultiplyNum(MultiplyNum(x, Head(y)), Tail(y));\n40 # MultiplyNum(x_IsRationalOrNumber, y_IsNumericList)_(Length(y)=1) <-- MultiplyNum(x, Head(y));\n\n//////////////////////////////////////////////////\n/// Numerical method: Newton-like superconvergent iteration\n//////////////////////////////////////////////////\n\n// Newton's method, generalized, with precision control and diagnostics\n\n/// auxiliary utility: compute the number of common decimal digits of x and y (using relative precision)\nCommon'digits(x,y) :=\n[\n\tLocal(diff);\n\tdiff := Abs(x-y);\n\tIf(\n\t\tdiff=0,\n\t\tInfinity,\n\t\t// use approximation Ln(2)/Ln(10) > 351/1166\n\t\tDiv(IntLog(MathFloor(MathDivide(Max(Abs(x), Abs(y)), diff)), 2)*351, 1166)\n\t); \t// this many decimal digits in common\n];\n\n///interface\nNewtonNum(_func, _x0) <-- NewtonNum(func, x0, 5);\t// default prec0\nNewtonNum(_func, _x0, _prec0) <-- NewtonNum(func, x0, prec0, 2);\n\n// func is the function to iterate, i.e. x' = func(x).\n// prec0 is the initial precision necessary to get convergence started.\n// order is the order of convergence of the given sequence (e.g. 2 or 3).\n// x0 must be close enough so that x1 has a few common digits with x0 after at most 5 iterations.\nNewtonNum(_func, _x'init, _prec0, _order) <--\n[\n\tCheck(prec0>=4, \"NewtonNum: Error: initial precision must be at least 4\");\n\tCheck(IsInteger(order) And order>1, \"NewtonNum: Error: convergence order must be an integer and at least 2\");\n\tLocal(x0, x1, prec, exact'digits, int'part, initial'tries);\n  N([\n    x0 := x'init;\n    prec := Builtin'Precision'Get();\n    int'part := IntLog(Ceil(Abs(x0)), 10);\t// how many extra digits for numbers like 100.2223\n    // int'part must be set to 0 if we have true floating-point semantics of Builtin'Precision'Set()\n    Builtin'Precision'Set(2+prec0-int'part);\t// 2 guard digits\n    x1 := (func @ x0);\t// let's run one more iteration by hand\n    // first, we get prec0 exact digits\n    exact'digits := 0;\n    initial'tries := 5;\t// stop the loop the the initial value is not good\n    While(exact'digits*order < prec0 And initial'tries>0)\n    [\n      initial'tries--;\n      x0 := x1;\n      x1 := (func @ x0);\n      exact'digits := Common'digits(x0, x1);\n  //\t\tIf(InVerboseMode(), Echo(\"NewtonNum: Info: got\", exact'digits, \"exact digits at prec. \", Builtin'Precision'Get()));\n    ];\n    // need to check that the initial precision is achieved\n    If(\n      Assert(\"value\", {\"NewtonNum: Error: need a more accurate initial value than\", x'init})\n        exact'digits >= 1,\n    [\n    exact'digits :=Min(exact'digits, prec0+2);\n    // run until get prec/order exact digits\n    int'part := IntLog(Ceil(Abs(x1)), 10);\t// how many extra digits for numbers like 100.2223\n    While(exact'digits*order <= prec)\n    [\n      exact'digits := exact'digits*order;\n      Builtin'Precision'Set(2+Min(exact'digits, Div(prec,order)+1)-int'part);\n      x0 := x1;\n      x1 := (func @ x0);\n  //\t\tIf(InVerboseMode(), Echo(\"NewtonNum: Info: got\", Common'digits(x0, x1), \"exact digits at prec. \", Builtin'Precision'Get()));\n    ];\n    // last iteration by hand\n    Builtin'Precision'Set(2+prec);\n    x1 := RoundTo( (func @ x1), prec);\n    ],\n    // did not get a good initial value, so return what we were given\n    x1 := x'init\n    );\n    Builtin'Precision'Set(prec);\n  ]);\n\tx1;\n];\n\n/*\nexample: logarithm function using cubically convergent Newton iteration for\nExp(x/2)-a*Exp(-x/2)=0:\n\nx' := x - 2 * (Exp(x)-a) / (Exp(x)+a)\n\nLN(x_IsNumber)_(x>1 ) <--\n\tLocalSymbols(y)\n[\n// initial guess is obtained as Ln(x^2)/Ln(2) * (Ln(2)/2)\n\tNewtonNum({{y},4*x/(Exp(y)+x)-2+y}, N(794/2291*IntLog(Floor(x*x),2),5), 10, 3);\n];\n/**/\n\n//////////////////////////////////////////////////\n/// Numerical method: integer powers by binary reduction\n//////////////////////////////////////////////////\n\n/// generalized integer Power function using the classic binary method.\n5 # IntPowerNum(_x, 0, _func, _unity) <-- unity;\n10 # IntPowerNum(_x, n_IsInteger, _func, _unity) <--\n[\n\t// use binary method\n\tLocal(result);\n\t// unity might be of non-scalar type, avoid assignment\n\tWhile(n > 0)\n\t[\n\t\tIf(\n\t\t\t(n&1) = 1,\n\t\t\tIf(\n\t\t\t\tIsBound(result), // if result is already assigned\n\t\t\t\tresult := Apply(func, {result,x}),\n\t\t\t\tresult := x, // avoid multiplication\n\t\t\t)\n\t\t);\n\t\tx := Apply(func, {x,x});\n\t\tn := n>>1;\n\t];\n\tresult;\n];\n\n//////////////////////////////////////////////////\n/// Numerical method: binary splitting technique for simple series\n//////////////////////////////////////////////////\n\n/// Binary splitting for series of the form\n/// S(m,n) = Sum(k,m,n, a(k)/b(k)*(p(0)*...*p(k))/(q(0)*...*q(k)))\n\n\n/// High-level interface routine\nBinSplitNum(m,n,a,b,p,q) := BinSplitFinal(BinSplitData(m,n,a,b,p,q));\n\n/// Low-level routine: compute the floating-point answer from P, Q, B, T data\nBinSplitFinal({_P,_Q,_B,_T}) <-- MathDivide(T, MathMultiply(B, Q));\n\n/// Low-level routine: combine two binary-split intermediate results\nBinSplitCombine({_P1, _Q1, _B1, _T1}, {_P2, _Q2, _B2, _T2}) <-- {P1*P2, Q1*Q2, B1*B2, B1*P1*T2+B2*Q2*T1};\n\n/// Low-level routine: compute the list of four integers P, Q, B, T. (T=BQS)\n/// Input: m, n and four functions a,b,p,q of one integer argument.\n\n// base of recursion\n10 # BinSplitData(_m, _n, _a, _b, _p, _q)_(m>n) <-- {1,1,1,0};\n\n10 # BinSplitData(_m, _n, _a, _b, _p, _q)_(m=n) <-- {p@m, q@m, b@m, (a@m)*(p@m)};\n\n10 # BinSplitData(_m, _n, _a, _b, _p, _q)_(m+1=n) <-- {(p@m)*(p@n), (q@m)*(q@n), (b@m)*(b@n), (p@m)*((a@m)*(b@n)*(q@n)+(a@n)*(b@m)*(p@n))};\n\n// could implement some more cases of recursion base, to improve speed\n\n// main recursion step\n20 # BinSplitData(_m, _n, _a, _b, _p, _q) <--\n[\n\tBinSplitCombine(BinSplitData(m,(m+n)>>1, a,b,p,q), BinSplitData(1+((m+n)>>1),n, a,b,p,q));\n];\n\n"
  },
  {
    "path": "scripts/stdfuncs.rep/nummethods.ys.def",
    "content": "NewtonNum\nSumTaylorNum\nAG'Mean\nMultiplyNum\nIntPowerNum\nBinSplitNum\nBinSplitData\nBinSplitFinal\n}\n"
  },
  {
    "path": "scripts/stdfuncs.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef( \"ArcSin\" , \"transc1\",\"arcsin\"  );\nOMDef( \"ArcCos\" , \"transc1\",\"arccos\"  );\nOMDef( \"ArcTan\" , \"transc1\",\"arctan\"  );\nOMDef( \"ArcSec\" , \"transc1\",\"arcsec\"  );\nOMDef( \"ArcCsc\" , \"transc1\",\"arccsc\"  );\nOMDef( \"ArcCot\" , \"transc1\",\"arccot\"  );\nOMDef( \"ArcSinh\", \"transc1\",\"arcsinh\" );\nOMDef( \"ArcCosh\", \"transc1\",\"arccosh\" );\nOMDef( \"ArcTanh\", \"transc1\",\"arctanh\" );\nOMDef( \"ArcSech\", \"transc1\",\"arcsech\" );\nOMDef( \"ArcCsch\", \"transc1\",\"arccsch\" );\nOMDef( \"ArcCoth\", \"transc1\",\"arccoth\" );\nOMDef( \"Sin\"    , \"transc1\",\"sin\"     );\nOMDef( \"Cos\"    , \"transc1\",\"cos\"     );\nOMDef( \"Tan\"    , \"transc1\",\"tan\"     );\nOMDef( \"Sec\"    , \"transc1\",\"sec\"     );\nOMDef( \"Csc\"    , \"transc1\",\"csc\"     );\nOMDef( \"Cot\"    , \"transc1\",\"cot\"     );\nOMDef( \"Sinh\"   , \"transc1\",\"sinh\"    );\nOMDef( \"Cosh\"   , \"transc1\",\"cosh\"    );\nOMDef( \"Tanh\"   , \"transc1\",\"tanh\"    );\nOMDef( \"Sech\"   , \"transc1\",\"sech\"    );\nOMDef( \"Csch\"   , \"transc1\",\"csch\"    );\nOMDef( \"Coth\"   , \"transc1\",\"coth\"    );\nOMDef( \"Exp\"    , \"transc1\",\"exp\"     );\nOMDef( \"Ln\"     , \"transc1\",\"ln\"      );\n\n// Related OM symbols not yet defined in Yacas:\n//     \"log\"    , \"transc1\",\"log\"\n"
  },
  {
    "path": "scripts/stdopers.ys",
    "content": "\n/* stdopers is loaded immediately after Yacas is started. It contains\n * the definitions of the infix operators, so the parser can already\n * parse expressions containing these operators, even though the\n * function hasn't been defined yet.\n */\n\nInfix(\"=\",90);\nInfix(\"And\",1000);\nRightAssociative(\"And\");\nInfix(\"Or\", 1010);\nPrefix(\"Not\", 100);\nInfix(\"<\",90);\nInfix(\">\",90);\nInfix(\"<=\",90);\nInfix(\">=\",90);\nInfix(\"!=\",90);\n\nInfix(\":=\",10000);\nRightAssociative(\":=\");\n\nInfix(\"+\",70);\nInfix(\"-\",70);\nRightPrecedence(\"-\",40);\nInfix(\"/\",30);\nInfix(\"*\",40);\nInfix(\"^\",20);\nRightAssociative(\"^\");\nPrefix(\"+\",50);\nPrefix(\"-\",50);\nRightPrecedence(\"-\",40);\nBodied(\"For\",60000);\nBodied(\"Until\",60000);\nPostfix(\"++\",5);\nPostfix(\"--\",5);\nBodied(\"ForEach\",60000);\nInfix(\"<<\",10);\nInfix(\">>\",10);\nBodied(\"D\",60000);\nBodied(\"Deriv\",60000);\nInfix(\"X\",30);\nInfix(\".\",30);\nInfix(\"o\",30);\nPostfix(\"!\", 30);\nPostfix(\"!!\", 30);\nInfix(\"***\", 50);\nBodied(\"Integrate\",60000);\nBodied(\"NIntegrate\",60000);\n\nBodied(\"Limit\",60000);\n\n/* functional operators */\nInfix(\":\",70);\nRightAssociative(\":\");\nInfix(\"@\",600);\nInfix(\"/@\",600);\nInfix(\"..\",600);\n\nBodied(\"Taylor\",60000);\nBodied(\"Taylor1\",60000);\nBodied(\"Taylor2\",60000);\nBodied(\"Taylor3\",60000);\nBodied(\"InverseTaylor\",60000);\n\nInfix(\"<--\",10000);\nInfix(\"#\",9900);\n\nBodied(\"TSum\",60000);\nBodied(\"TExplicitSum\",60000);\nBodied(\"TD\",5);  /* Tell the Yacas interpreter that TD is to be used as TD(i)f */\n\n/* Operator to be used for non-evaluating comparisons */\nInfix(\"==\",90);\nInfix(\"!==\",90);\n\n/* Operators needed for propositional logic theorem prover */\nInfix(\"=>\",10000); /* implication, read as 'implies' */\n\n\nBodied(\"if\",5);\nInfix(\"else\",60000);\nRightAssociative(\"else\");\n/* Bitwise operations we REALLY need. Perhaps we should define them\n   also as Yacas operators?\n */\nInfix(\"&\",50);\nInfix(\"|\",50);\nInfix(\"%\",50);\n\n/* local pattern replacement operators */\nInfix(\"/:\",20000);\nInfix(\"/::\",20000);\nInfix(\"<-\",10000);\n\n/* Operators used for manual layout */\nInfix(\"<>\", OpPrecedence(\"=\"));\nInfix(\"<=>\", OpPrecedence(\"=\"));\n\n/* Operators for Solve: Where and AddTo */\nInfix(\"Where\", 11000);\nInfix(\"AddTo\", 2000);\n\nBodied(\"Function\",60000);\nBodied(\"Macro\",60000);\n\nBodied(Assert, 60000);\n\n// Defining very simple functions, in scripts that can be converted to plugin.\nBodied(\"Defun\",0);\n\n// Operators for defining graph edges\nInfix(\"<->\",90);\nInfix(\"->\",90);\n"
  },
  {
    "path": "scripts/stubs.rep/code.ys",
    "content": "/* Comparison operators. They call the internal comparison routines when\n * both arguments are numbers. The value Infinity is also understood.\n*/\n\n// Undefined is a very special case as we return False for everything\n1 # Undefined <  _x  <--  False;\n1 # Undefined <= _x  <--  False;\n1 # Undefined >  _x  <--  False;\n1 # Undefined >= _x  <--  False;\n1 # _x <  Undefined  <--  False;\n1 # _x <= Undefined  <--  False;\n1 # _x >  Undefined  <--  False;\n1 # _x >= Undefined  <--  False;\n\n\n// If n and m are numbers, use the standard LessThan function immediately\n5 # (n_IsNumber < m_IsNumber) <-- LessThan(n-m,0);\n\n\n// If n and m are symbolic after a single evaluation, see if they can be coerced in to a real-valued number.\nLocalSymbols(nNum,mNum)\n[\n  10 # (_n < _m)_[nNum:=N(Eval(n)); mNum:=N(Eval(m));IsNumber(nNum) And IsNumber(mNum);] <-- LessThan(nNum-mNum,0);\n];\n\n// Deal with Infinity\n20 #  (Infinity < _n)_(Not(IsInfinity(n)))  <-- False;\n20 #  (-Infinity < _n)_(Not(IsInfinity(n))) <-- True;\n20 #  (_n < Infinity)_(Not(IsInfinity(n)))  <-- True;\n20 #  (_n < -Infinity)_(Not(IsInfinity(n))) <-- False;\n\n// Lots of known identities go here\n30 # (_n1/_n2) < 0  <--  (n1 < 0) != (n2 < 0);\n30 # (_n1*_n2) < 0  <--  (n1 < 0) != (n2 < 0);\n\n// This doesn't sadly cover the case where a and b have opposite signs\n30 # ((_n1+_n2) < 0)_((n1 < 0) And (n2 < 0))  <--  True;\n30 # ((_n1+_n2) < 0)_((n1 > 0) And (n2 > 0))  <--  False;\n30 #  _x^a_IsOdd  < 0  <--  x < 0;\n30 #  _x^a_IsEven < 0  <--  False; // This is wrong for complex x\n\n// Add other functions here!  Everything we can compare to 0 should be here.\n40 # (Sqrt(_x))_(x > 0) < 0          <--  False;\n\n40 # (Sin(_x) < 0)_(Not(IsEven(N(x/Pi))) And IsEven(N(Floor(x/Pi)))) <-- False;\n40 # (Sin(_x) < 0)_(Not(IsOdd (N(x/Pi))) And IsOdd (N(Floor(x/Pi)))) <-- True;\n\n40 # Cos(_x) < 0 <-- Sin(Pi/2-x) < 0;\n\n40 # (Tan(_x) < 0)_(Not(IsEven(N(2*x/Pi))) And IsEven(N(Floor(2*x/Pi)))) <-- False;\n40 # (Tan(_x) < 0)_(Not(IsOdd (N(2*x/Pi))) And IsOdd (N(Floor(2*x/Pi)))) <-- True;\n\n// Functions that need special treatment with more than one of the comparison\n// operators as they always return true or false.  For these we must define\n// both the `<' and `>=' operators.\n40 # (Complex(_a,_b) <  0)_(b!=0) <--  False;\n40 # (Complex(_a,_b) >= 0)_(b!=0) <--  False;\n40 # (Sqrt(_x))_(x < 0) <  0      <--  False;\n40 # (Sqrt(_x))_(x < 0) >= 0      <--  False;\n\n// Deal with negated terms\n50 # -(_x) < 0 <-- Not((x<0) Or (x=0));\n\n// Define each of {>,<=,>=} in terms of <\n50 # _n >  _m <-- m < n;\n50 # _n <= _m <-- m >= n;\n50 # _n >= _m <-- Not(n<m);\n\n\nFunction(\"!=\",{aLeft,aRight}) Not(aLeft=aRight);\n\n/* Shifting operators */\n\nn_IsInteger << m_IsInteger <-- ShiftLeft(n,m);\nn_IsInteger >> m_IsInteger <-- ShiftRight(n,m);\n\n0 # Sqrt(0) <-- 0;\n0 # Sqrt(Infinity) <--  Infinity;\n0 # Sqrt(-Infinity) <-- Complex(0,Infinity);\n0 # Sqrt(Undefined) <--  Undefined;\n1 # Sqrt(x_IsPositiveInteger)_(IsInteger(MathSqrt(x))) <-- MathSqrt(x);\n2 # Sqrt(x_IsPositiveNumber)_InNumericMode() <-- MathSqrt(x);\n2 # Sqrt(x_IsNegativeNumber) <-- Complex(0,Sqrt(-x));\n/* 3 # Sqrt(x_IsNumber/y_IsNumber) <-- Sqrt(x)/Sqrt(y); */\n3 # Sqrt(x_IsComplex)_InNumericMode() <-- x^(1/2);\n/* Threading  */\nSqrt(xlist_IsList) <-- MapSingle(\"Sqrt\",xlist);\n\n90 # (Sqrt(x_IsConstant))_(IsNegativeNumber(N(x))) <-- Complex(0,Sqrt(-x));\n\n400 # x_IsRationalOrNumber * Sqrt(y_IsRationalOrNumber)  <-- Sign(x)*Sqrt(x^2*y);\n400 # Sqrt(y_IsRationalOrNumber) * x_IsRationalOrNumber  <-- Sign(x)*Sqrt(x^2*y);\n400 # x_IsRationalOrNumber / Sqrt(y_IsRationalOrNumber)  <-- Sign(x)*Sqrt(x^2/y);\n400 # Sqrt(y_IsRationalOrNumber) / x_IsRationalOrNumber  <-- Sign(x)*Sqrt(y/(x^2));\n400 # Sqrt(y_IsRationalOrNumber) / Sqrt(x_IsRationalOrNumber)  <-- Sqrt(y/x);\n400 # Sqrt(y_IsRationalOrNumber) * Sqrt(x_IsRationalOrNumber)  <-- Sqrt(y*x);\n400 # Sqrt(x_IsInteger)_IsInteger(MathSqrt(x)) <-- MathSqrt(x);\n400 # Sqrt(x_IsInteger/y_IsInteger)_(IsInteger(MathSqrt(x)) And IsInteger(MathSqrt(y))) <-- MathSqrt(x)/MathSqrt(y);\n\n/* Integer divisions */\n0 # Div(n_IsInteger,m_IsInteger) <-- MathDiv(n,m);\n1 # Div(0  ,_m) <-- 0;\n2 # Div(n_IsRationalOrNumber,m_IsRationalOrNumber) <--\n[\n  Local(n1,n2,m1,m2,sgn1,sgn2);\n  n1:=Numer(n);\n  n2:=Denom(n);\n  m1:=Numer(m);\n  m2:=Denom(m);\n  sgn1 := Sign(n1*m2);\n  sgn2 := Sign(m1*n2);\n  sgn1*sgn2*Floor(MathDivide(sgn1*n1*m2,sgn2*m1*n2));\n];\n30 # Div(n_CanBeUni,m_CanBeUni)_(Length(VarList(n*m))=1) <--\n[\n\n  Local(vars,nl,ml);\n  vars:=VarList(n*m);\n  nl := MakeUni(n,vars);\n  ml := MakeUni(m,vars);\n  NormalForm(Div(nl,ml));\n];\n\n0 # Mod(_n,m_IsRationalOrNumber)_(m<0) <-- `Hold(Mod(@n,@m));\n\n1 # Mod(n_IsNegativeInteger,m_IsPositiveInteger) <--\n[\n  Local(result);\n  result := MathMod(n,m);\n  If (result < 0,result := result + m);\n  result;\n];\n1 # Mod(n_IsPositiveInteger,m_IsPositiveInteger) <-- MathMod(n,m);\n2 # Mod(0,_m) <-- 0;\n2 # Mod(n_IsPositiveInteger,Infinity) <-- n;\n3 # Mod(n_IsInteger,m_IsInteger) <-- MathMod(n,m);\n4 # Mod(n_IsNumber,m_IsNumber) <-- NonN(Mod(Rationalize(n),Rationalize(m)));\n\n5 # Mod(n_IsRationalOrNumber,m_IsRationalOrNumber)/*_(n>0 And m>0)*/ <--\n[\n  Local(n1,n2,m1,m2);\n  n1:=Numer(n);\n  n2:=Denom(n);\n  m1:=Numer(m);\n  m2:=Denom(m);\n  Mod(n1*m2,m1*n2)/(n2*m2);\n];\n\n10 # Mod(c_IsConstant, b_IsRational * c_IsConstant) <-- Mod(1, b) * c;\n10 # Mod(a_IsRational * c_IsConstant, c_IsConstant) <-- Mod(a, 1) * c;\n\n10 # Mod(a_IsRational * c_IsConstant, b_IsRational * c_IsConstant) <-- Mod(a, b) * c;\n\n10 # Mod(c_IsConstant, c_IsConstant / bd_IsInteger) <-- Mod(1, 1 / bd) * c;\n10 # Mod(c_IsConstant / ad_IsInteger, c_IsConstant) <-- Mod(1 / ad, 1) * c;\n10 # Mod(c_IsConstant / ad_IsInteger, c_IsConstant / bd_IsInteger) <-- Mod(1/ad, 1/bd) * c;\n\n10 # Mod(c_IsConstant / ad_IsInteger, (bn_IsInteger * c_IsConstant) / bd_IsInteger) <-- Mod(1 / ad, bn / bd) * c;\n10 # Mod((an_IsInteger * c_IsConstant) / ad_IsInteger, c_IsConstant / bd_IsInteger) <-- Mod(an / ad, 1 / bd) * c;\n\n10 # Mod(c_IsConstant / ad_IsInteger, b_IsRational * c_IsConstant) <-- Mod(1 / ad, b) * c;\n10 # Mod(a_IsRational * c_IsConstant, c_IsConstant / bd_IsInteger) <-- Mod(a, 1 / bd) * c;\n\n\n10 # Mod((an_IsInteger * c_IsConstant) / ad_IsInteger, b_IsRational * c_IsConstant) <-- Mod(an / ad, b) * c;\n10 # Mod(a_IsRational * c_IsConstant, (bn_IsInteger * c_IsConstant) / bd_IsInteger) <-- Mod(a, bn / bd) * c;\n\n10 # Mod((an_IsInteger * c_IsConstant) / ad_IsInteger, (bn_IsInteger * c_IsConstant) / bd_IsInteger) <-- Mod(an / ad, bn / bd) * c;\n\n\n\n16 # Mod(n_IsList,m_IsList) <-- Map(\"Mod\",{n,m});\n17 # Mod(n_IsList,_m) <-- Map(\"Mod\",{n,FillList(m,Length(n))});\n\n\n30 # Mod(n_CanBeUni,m_CanBeUni) <--\n[\n  Local(vars);\n  vars:=VarList(n+m);\n  NormalForm(Mod(MakeUni(n,vars),MakeUni(m,vars)));\n];\n\n0 # Rem(n_IsNumber,m_IsNumber) <-- n-m*Div(n,m);\n30 # Rem(n_CanBeUni,m_CanBeUni) <--\n[\n  Local(vars);\n  vars:=VarList(n+m);\n  NormalForm(Mod(MakeUni(n,vars),MakeUni(m,vars)));\n];\n\n\n\n10 # Gcd(0,0) <-- 1;\n20 # Gcd(0,_m) <-- Abs(m);\n20 # Gcd(_n,0) <-- Abs(n);\n20 # Gcd(_m,_m) <-- Abs(m);\n22 # Gcd(m_IsInteger, 1) <-- 1;\n22 # Gcd(1, m_IsInteger) <-- 1;\n30 # Gcd(n_IsInteger,m_IsInteger) <-- MathGcd(n,m);\n35 # Gcd(m_IsRational, 1) <-- 1 / Denom(m);\n35 # Gcd(1, m_IsRational) <-- 1 / Denom(m);\n40 # Gcd(_n,_m)_(IsGaussianInteger(m) And IsGaussianInteger(n) )<-- GaussianGcd(n,m);\n\n45 # Gcd(-(_n), (_m)) <-- Gcd(n,m);\n45 # Gcd( (_n),-(_m)) <-- Gcd(n,m);\n45 # Gcd(Sqrt(n_IsInteger),Sqrt(m_IsInteger)) <-- Sqrt(Gcd(n,m));\n45 # Gcd(Sqrt(n_IsInteger),m_IsInteger) <-- Sqrt(Gcd(n,m^2));\n45 # Gcd(n_IsInteger,Sqrt(m_IsInteger)) <-- Sqrt(Gcd(n^2,m));\n\n45 # Gcd(Exp(n_IsInteger), Exp(m_IsInteger)) <-- Exp(Min(m, n));\n\n47 # Gcd(n_IsRational,m_IsRational) <-- Gcd(Numer(n),Numer(m))/Lcm(Denom(n),Denom(m));\n\n48 # Gcd(c_IsConstant, b_IsRational * c_IsConstant) <-- Gcd(1, b) * c;\n48 # Gcd(a_IsRational * c_IsConstant, c_IsConstant) <-- Gcd(a, 1) * c;\n\n48 # Gcd(a_IsRational * c_IsConstant, b_IsRational * c_IsConstant) <-- Gcd(a, b) * c;\n\n48 # Gcd(c_IsConstant, c_IsConstant / bd_IsInteger) <-- Gcd(1, 1 / bd) * c;\n48 # Gcd(c_IsConstant / ad_IsInteger, c_IsConstant) <-- Gcd(1 / ad, 1) * c;\n48 # Gcd(c_IsConstant / ad_IsInteger, c_IsConstant / bd_IsInteger) <-- Gcd(1/ad, 1/bd) * c;\n\n48 # Gcd(c_IsConstant / ad_IsInteger, (bn_IsInteger * c_IsConstant) / bd_IsInteger) <-- Gcd(1 / ad, bn / bd) * c;\n48 # Gcd((an_IsInteger * c_IsConstant) / ad_IsInteger, c_IsConstant / bd_IsInteger) <-- Gcd(an / ad, 1 / bd) * c;\n\n48 # Gcd(c_IsConstant / ad_IsInteger, b_IsRational * c_IsConstant) <-- Gcd(1 / ad, b) * c;\n48 # Gcd(a_IsRational * c_IsConstant, c_IsConstant / bd_IsInteger) <-- Gcd(a, 1 / bd) * c;\n\n\n48 # Gcd((an_IsInteger * c_IsConstant) / ad_IsInteger, b_IsRational * c_IsConstant) <-- Gcd(an / ad, b) * c;\n48 # Gcd(a_IsRational * c_IsConstant, (bn_IsInteger * c_IsConstant) / bd_IsInteger) <-- Gcd(a, bn / bd) * c;\n\n48 # Gcd((an_IsInteger * c_IsConstant) / ad_IsInteger, (bn_IsInteger * c_IsConstant) / bd_IsInteger) <-- Gcd(an / ad, bn / bd) * c;\n\n50 # Gcd(list_IsList)_(Length(list)>2) <--\n    [\n      Local(first);\n      first:=Gcd(list[1],list[2]);\n      Gcd(first:Tail(Tail(list)));\n    ];\n51 # Gcd({0}) <-- 1;\n53 # Gcd({_head}) <-- Abs(head);\n\n55 # Gcd(list_IsList)_(Length(list)=2) <-- Gcd(list[1],list[2]);\n\n60 # Gcd(n_CanBeUni,m_CanBeUni)_(Length(VarList(n*m))=1) <--\n[\n  Local(vars);\n  vars:=VarList(n*m);\n  NormalForm(Gcd(MakeUni(n,vars),MakeUni(m,vars)));\n];\n\n90 # Gcd(x_IsNumber, _y) <-- Check(False, \"Gcd: argument is not an exact number\");\n90 # Gcd(_x, y_IsNumber) <-- Check(False, \"Gcd: argument is not an exact number\");\n\n100 # Gcd(n_IsConstant,m_IsConstant) <-- 1;\n\n30 # PolynomialGcd(n_CanBeUni, m_CanBeUni)_(Length(VarList(n*m))=1) <--\n[\n  PolynomialGcd(n, m, VarList(n*m)[1]);\n];\n\n40 # PolynomialGcd(0, m_CanBeUni, x_IsVariable) <-- m;\n40 # PolynomialGcd(n_CanBeUni, 0, x_IsVariable) <-- n;\n\n50 # PolynomialGcd(n_CanBeUni, m_CanBeUni, x_IsVariable) <--\n[\n  Local(vars);\n  vars:=VarList(n*m);\n  NormalForm(Gcd(MakeUni(n,vars),MakeUni(m,vars)));\n];\n\n\n/* Least common multiple */\n5  # Lcm(a_IsInteger,b_IsInteger) <-- Div(Abs(a*b),Gcd(a,b));\n\n10 # Lcm(list_IsList)_(Length(list)>2) <--\n[\n        Local(first);\n        first:=Lcm(list[1],list[2]);\n        Lcm(first:Tail(Tail(list)));\n];\n\n10 # Lcm(list_IsList)_(Length(list)=2) <-- Lcm(list[1],list[2]);\n\n10 # Lcm(list_IsList)_(Length(list)=1) <-- Lcm(list[1],1);\n\n/* Expand expands polynomials.\n */\n10 # Expand(expr_CanBeUni) <-- NormalForm(MakeUni(expr));\n20 # Expand(_expr) <-- expr;\n\n10 # Expand(expr_CanBeUni(var),_var) <-- NormalForm(MakeUni(expr,var));\n20 # Expand(_expr,_var) <-- expr;\n\n\n\nRuleBase(\"Object\",{pred,x});\nRule(\"Object\",2,0,Apply(pred,{x})=True) x;\n\n10 # Abs(n_IsNumber) <-- MathAbs(n);\n10 # Abs(n_IsPositiveNumber/m_IsPositiveNumber) <-- n/m;\n10 # Abs(n_IsNegativeNumber/m_IsPositiveNumber) <-- (-n)/m;\n10 # Abs(n_IsPositiveNumber/m_IsNegativeNumber) <-- n/(-m);\n10 # Abs( Sqrt(_x)) <-- Sqrt(x);\n10 # Abs(-Sqrt(_x)) <-- Sqrt(x);\n10 # Abs(Complex(_r,_i)) <-- Sqrt(r^2 + i^2);\n10 # Abs(n_IsInfinity) <-- Infinity;\n10 # Abs(Undefined) <-- Undefined;\n20 # Abs(n_IsList) <-- MapSingle(\"Abs\",n);\n\n50 # Abs(c_IsConstant) <-- If (c > 0, c, -c);\n\n100 # Abs(_a^_n) <-- Abs(a)^n;\n100 # Abs(_a)^n_IsEven <-- a^n;\n100 # Abs(_a)^n_IsOdd <-- Sign(a)*a^n;\n\n10 # Sign(n_IsPositiveNumber) <-- 1;\n10 # Sign(n_IsZero) <-- 0;\n20 # Sign(n_IsNumber) <-- -1;\n15 # Sign(n_IsInfinity)_(n < 0) <-- -1;\n15 # Sign(n_IsInfinity)_(n > 0) <-- 1;\n15 # Sign(n_IsNumber/m_IsNumber) <-- Sign(n)*Sign(m);\n20 # Sign(n_IsList) <-- MapSingle(\"Sign\",n);\n\n100 # Sign(a_IsNonZero)^n_IsEven <-- 1;\n100 # Sign(_a)^n_IsOdd <-- Sign(a);\n\n5 # Floor(Infinity) <-- Infinity;\n5 # Floor(-Infinity) <-- -Infinity;\n5 # Floor(Undefined) <-- Undefined;\n5 # Ceil(Infinity) <-- Infinity;\n5 # Ceil(-Infinity) <-- -Infinity;\n5 # Ceil(Undefined) <-- Undefined;\n5 # Round(Infinity) <-- Infinity;\n5 # Round(-Infinity) <-- -Infinity;\n5 # Round(Undefined) <-- Undefined;\n\n/* Changed by Nobbi before redefinition of Rational\n10 # Floor(x_IsNumber) <-- MathFloor(x);\n10 # Ceil (x_IsNumber) <-- MathCeil (x);\n10 # Round(x_IsNumber) <-- MathFloor(x+0.5);\n\n20 # Floor(x_IsRational) _ (IsNumber(Numer(x)) And IsNumber(Denom(x))) <-- MathFloor(N(x));\n20 # Ceil (x_IsRational) _ (IsNumber(Numer(x)) And IsNumber(Denom(x))) <-- MathCeil (N(x));\n20 # Round(x_IsRational) _ (IsNumber(Numer(x)) And IsNumber(Denom(x))) <-- MathFloor(N(x+0.5));\n*/\n\n10 # Floor(x_IsRationalOrNumber)\n   <--\n   [\n     x:=N(Eval(x));\n//Echo(\"x = \",x);\n     Local(prec,result,n);\n     Set(prec,Builtin'Precision'Get());\n     If(IsZero(x),\n       Set(n,2),\n       If(x>0,\n         Set(n,2+MathFloor(N(FastLog(x)/FastLog(10)))),\n         Set(n,2+MathFloor(N(FastLog(-x)/FastLog(10))))\n       ));\n     If(n>prec,Builtin'Precision'Set(n));\n//Echo(\"Before\");\n     Set(result,MathFloor(x));\n//Echo(\"After\");\n     Builtin'Precision'Set(prec);\n     result;\n   ];\n\n//     MathFloor(N(x));\n\n10 # Ceil (x_IsRationalOrNumber)\n   <--\n   [\n     x:=N(Eval(x));\n     Local(prec,result,n);\n     Set(prec,Builtin'Precision'Get());\n     If(IsZero(x),Set(n,2),\n     If(x>0,\n       Set(n,2+MathFloor(N(FastLog(x)/FastLog(10)))),\n       Set(n,2+MathFloor(N(FastLog(-x)/FastLog(10))))\n       ));\n     If(n>prec,Builtin'Precision'Set(n));\n     Set(result,MathCeil(x));\n     Builtin'Precision'Set(prec);\n     result;\n   ];\n//   MathCeil (N(x));\n10 # Round(x_IsRationalOrNumber) <-- MathFloor(N(x+0.5));\n10 # Round(x_IsList) <-- MapSingle(\"Round\",x);\n\n20 # Round(x_IsComplex)  _ (IsRationalOrNumber(Re(x)) And IsRationalOrNumber(Im(x)) )\n                <-- MathFloor(N(Re(x)+0.5)) + MathFloor(N(Im(x)+0.5))*I;\n\n\n// Canonicalise an expression so its terms are grouped to the right\n// ie a+(b+(c+d))\n// This doesn't preserve order of terms, when doing this would cause more\n// subtractions and nested parentheses than necessary.\n1 # CanonicalAdd((_a+_b)+_c) <-- CanonicalAdd(CanonicalAdd(a)+\n                                              CanonicalAdd(CanonicalAdd(b)+\n                                                           CanonicalAdd(c)));\n1 # CanonicalAdd((_a-_b)+_c) <-- CanonicalAdd(CanonicalAdd(a)+\n                                              CanonicalAdd(CanonicalAdd(c)-\n                                                           CanonicalAdd(b)));\n1 # CanonicalAdd((_a+_b)-_c) <-- CanonicalAdd(CanonicalAdd(a)+\n                                              CanonicalAdd(CanonicalAdd(b)-\n                                                           CanonicalAdd(c)));\n1 # CanonicalAdd((_a-_b)-_c) <-- CanonicalAdd(CanonicalAdd(a)-\n                                              CanonicalAdd(CanonicalAdd(b)+\n                                                           CanonicalAdd(c)));\n2 # CanonicalAdd(_a)         <-- a;\n\n////////////////////// Log rules stuff //////////////////////\n\n// LnExpand\n1 # LnExpand(Ln(x_IsInteger))\n                            <-- Add(Map({{n,m},m*Ln(n)},Transpose(Factors(x))));\n1 # LnExpand(Ln(_a*_b))     <-- LnExpand(Ln(a))+LnExpand(Ln(b));\n1 # LnExpand(Ln(_a/_b))     <-- LnExpand(Ln(a))-LnExpand(Ln(b));\n1 # LnExpand(Ln(_a^_n))     <-- LnExpand(Ln(a))*n;\n2 # LnExpand(_a)            <-- a;\n\n// LnCombine is nice and simple now\nLnCombine(_a) <-- DoLnCombine(CanonicalAdd(a));\n\n// Combine single terms.  This can always be done without a recursive call.\n1 # DoLnCombine(Ln(_a))              <-- Ln(a);\n1 # DoLnCombine(Ln(_a)*_b)           <-- Ln(a^b);\n1 # DoLnCombine(_b*Ln(_a))           <-- Ln(a^b);\n\n// Deal with the first two terms so they are both simple logs if at all\n// possible.  This involves converting a*Ln(b) to Ln(b^a) and moving log terms\n// to the start of expressions.  One of either of these operations always takes\n// us to a strictly simpler form than we started in, so we can get away with\n// calling DoLnCombine again with the partly simplified argument.\n\n// TODO: Make this deal with division everywhere it deals with multiplication\n\n// first term is a log multiplied by something\n2 # DoLnCombine(Ln(_a)*_b+_c)        <-- DoLnCombine(Ln(a^b)+c);\n2 # DoLnCombine(Ln(_a)*_b-_c)        <-- DoLnCombine(Ln(a^b)-c);\n2 # DoLnCombine(_b*Ln(_a)+_c)        <-- DoLnCombine(Ln(a^b)+c);\n2 # DoLnCombine(_b*Ln(_a)-_c)        <-- DoLnCombine(Ln(a^b)-c);\n\n// second term of a two-term expression is a log multiplied by something\n2 # DoLnCombine(_a+(_c*Ln(_b)))      <-- DoLnCombine(a+Ln(b^c));\n2 # DoLnCombine(_a-(_c*Ln(_b)))      <-- DoLnCombine(a-Ln(b^c));\n2 # DoLnCombine(_a+(Ln(_b)*_c))      <-- DoLnCombine(a+Ln(b^c));\n2 # DoLnCombine(_a-(Ln(_b)*_c))      <-- DoLnCombine(a-Ln(b^c));\n\n// second term of a three-term expression is a log multiplied by something\n2 # DoLnCombine(_a+((Ln(_b)*_c)+_d)) <-- DoLnCombine(a+(Ln(b^c)+d));\n2 # DoLnCombine(_a+((Ln(_b)*_c)-_d)) <-- DoLnCombine(a+(Ln(b^c)-d));\n2 # DoLnCombine(_a-((Ln(_b)*_c)+_d)) <-- DoLnCombine(a-(Ln(b^c)+d));\n2 # DoLnCombine(_a-((Ln(_b)*_c)-_d)) <-- DoLnCombine(a-(Ln(b^c)-d));\n\n2 # DoLnCombine(_a+((_c*Ln(_b))+_d)) <-- DoLnCombine(a+(Ln(b^c)+d));\n2 # DoLnCombine(_a+((_c*Ln(_b))-_d)) <-- DoLnCombine(a+(Ln(b^c)-d));\n2 # DoLnCombine(_a-((_c*Ln(_b))+_d)) <-- DoLnCombine(a-(Ln(b^c)+d));\n2 # DoLnCombine(_a-((_c*Ln(_b))-_d)) <-- DoLnCombine(a-(Ln(b^c)-d));\n\n// Combine the first two terms if they are logs, otherwise move one or both to\n// the front, then recurse on the remaining possibly-log-containing portion.\n// (the code makes more sense than this comment)\n3 # DoLnCombine(Ln(_a)+Ln(_b))       <-- Ln(a*b);\n3 # DoLnCombine(Ln(_a)-Ln(_b))       <-- Ln(a/b);\n3 # DoLnCombine(Ln(_a)+(Ln(_b)+_c))  <-- DoLnCombine(Ln(a*b)+c);\n3 # DoLnCombine(Ln(_a)+(Ln(_b)-_c))  <-- DoLnCombine(Ln(a*b)-c);\n3 # DoLnCombine(Ln(_a)-(Ln(_b)+_c))  <-- DoLnCombine(Ln(a/b)-c);\n3 # DoLnCombine(Ln(_a)-(Ln(_b)-_c))  <-- DoLnCombine(Ln(a/b)+c);\n\n// We know that at least one of the first two terms isn't a log\n4 # DoLnCombine(Ln(_a)+(_b+_c))      <-- b+DoLnCombine(Ln(a)+c);\n4 # DoLnCombine(Ln(_a)+(_b-_c))      <-- b+DoLnCombine(Ln(a)-c);\n4 # DoLnCombine(Ln(_a)-(_b+_c))      <-- DoLnCombine(Ln(a)-c)-b;\n4 # DoLnCombine(Ln(_a)-(_b-_c))      <-- DoLnCombine(Ln(a)+c)-b;\n\n4 # DoLnCombine(_a+(Ln(_b)+_c))      <-- a+DoLnCombine(Ln(b)+c);\n4 # DoLnCombine(_a+(Ln(_b)-_c))      <-- a+DoLnCombine(Ln(b)-c);\n4 # DoLnCombine(_a-(Ln(_b)+_c))      <-- a-DoLnCombine(Ln(b)+c);\n4 # DoLnCombine(_a-(Ln(_b)-_c))      <-- a-DoLnCombine(Ln(b)-c);\n\n// If we get here we know that neither of the first two terms is a log\n5 # DoLnCombine(_a+(_b+_c))          <-- a+(b+DoLnCombine(c));\n\n// Finished\n6 # DoLnCombine(_a)                  <-- a;\n\n"
  },
  {
    "path": "scripts/stubs.rep/code.ys.def",
    "content": "=\nNot\n<\n>\n<=\n>=\n!=\n<<\n>>\nDiv\nMod\nGcd\nExpand\nObject\nSqrt\nAbs\nSign\nLcm\nFloor\nCeil\nRound\nPolynomialGcd\nLnExpand\nLnCombine\n}\n"
  },
  {
    "path": "scripts/stubs.rep/om.ys",
    "content": "// From code.ys.def:\nOMDef( \"Not\", \"logic1\",\"not\" );\nOMDef( \"=\" , \"relation1\",\"eq\"  );\nOMDef( \">=\", \"relation1\",\"geq\" );\nOMDef( \">\" , \"relation1\",\"gt\"  );\nOMDef( \"<=\", \"relation1\",\"leq\" );\nOMDef( \"<\" , \"relation1\",\"lt\"  );\nOMDef( \"!=\", \"relation1\",\"neq\" );\nOMDef( \"Gcd\", \"arith1\",\"gcd\" );\nOMDef( \"Sqrt\", \"arith1\",\"root\", { $, _1, 2 }, $(_1)_(_2=2) | (_1^(1/_2)) );\n// Test [result: Sqrt(16)]:\n// FromString(\"<OMOBJ><OMA><OMS cd=\\\"arith1\\\" name=\\\"root\\\"/><OMI>16</OMI><OMI>2</OMI></OMA></OMOBJ> \")OMRead()\n// Test [result: IntNthRoot(16,3))]:\n// FromString(\"<OMOBJ><OMA><OMS cd=\\\"arith1\\\" name=\\\"root\\\"/><OMI>16</OMI><OMI>3</OMI></OMA></OMOBJ> \")OMRead()\nOMDef( \"Abs\", \"arith1\",\"abs\" );\nOMDef( \"Lcm\", \"arith1\",\"lcm\" );\n\nOMDef( \"Floor\", \"rounding1\",\"floor\"   );\nOMDef( \"Ceil\" , \"rounding1\",\"ceiling\" );\nOMDef( \"Round\", \"rounding1\",\"round\"   );\n\nOMDef( \"Div\"   , \"integer1\",\"quotient\" );\nOMDef( \"Mod\"   , \"integer1\",\"remainder\");\nOMDef( \"Expand\", \"yacas\",\"expand\" );\nOMDef( \"Object\", \"yacas\",\"object\" );\nOMDef( \"Sign\"  , \"yacas\",\"sign\"   );\n"
  },
  {
    "path": "scripts/substitute.rep/code.ys",
    "content": "\n\nFunction(\"Substitute\",{body,predicate,change})\n[\n  Substitute(body);\n];\nHoldArg(\"Substitute\",predicate);\nHoldArg(\"Substitute\",change);\nUnFence(\"Substitute\",3);\nRuleBase(\"Substitute\",{body});\nUnFence(\"Substitute\",1);\n\nRule(\"Substitute\",1,1,Apply(predicate,{body}) = True)\n[\n  Apply(change,{body});\n];\nRule(\"Substitute\",1,2,IsFunction(body))\n[\n  Apply(\"MapArgs\",{body,\"Substitute\"});\n];\nRule(\"Substitute\",1,3,True) body;\n\n/*Extremely hacky workaround, MacroSubstitute is actually the same as Substitute,\n  but without re-evaluating its arguments. I could not just change Substitute, as\n  it changed behaviour such that tests started to break.\n */\nFunction(\"MacroSubstitute\",{body,predicate,change})\n[\n  `MacroSubstitute((Hold(@body)));\n];\nHoldArg(\"MacroSubstitute\",predicate);\nHoldArg(\"MacroSubstitute\",change);\nUnFence(\"MacroSubstitute\",3);\nRuleBase(\"MacroSubstitute\",{body});\nUnFence(\"MacroSubstitute\",1);\n\nRule(\"MacroSubstitute\",1,1,`ApplyPure(predicate,{Hold(Hold(@body))}) = True)\n[\n  `ApplyPure(change,{Hold(Hold(@body))});\n];\nRule(\"MacroSubstitute\",1,2,`IsFunction(Hold(@body)))\n[\n  `ApplyPure(\"MacroMapArgs\",{Hold(Hold(@body)),\"MacroSubstitute\"});\n];\nRule(\"MacroSubstitute\",1,3,True)\n[\n `Hold(@body);\n];\n\n\n\nLocalSymbols(predicate,list,result,item)\n[\n  Function(\"Select\",{predicate,list})\n  [\n    Local(result);\n    result:={};\n    ForEach(item,list)\n    [\n      If(Apply(predicate,{item}),DestructiveAppend(result,item));\n    ];\n    result;\n  ];\n  HoldArg(\"Select\",predicate);\n  UnFence(\"Select\",2);\n];\n"
  },
  {
    "path": "scripts/substitute.rep/code.ys.def",
    "content": "Substitute\nMacroSubstitute\nSelect\n}"
  },
  {
    "path": "scripts/sums.rep/code.ys",
    "content": "Function() Min(l1, l2, l3, ...);\nFunction() Max(l1, l2, l3, ...);\n\n10 # Min(_l1, _l2, l3_IsList) <-- Min(Concat({l1, l2}, l3));\n20 # Min(_l1, _l2, _l3) <-- Min({l1, l2, l3});\n\n10 # Max(_l1, _l2, l3_IsList) <-- Max(Concat({l1, l2}, l3));\n20 # Max(_l1, _l2, _l3) <-- Max({l1, l2, l3});\n/**/\n10 # Min(l1_IsList,l2_IsList) <-- Map(\"Min\",{l1,l2});\n10 # Max(l1_IsList,l2_IsList) <-- Map(\"Max\",{l1,l2});\n\n20 # Min(l1_IsRationalOrNumber,l2_IsRationalOrNumber) <-- If(l1<l2,l1,l2);\n20 # Max(l1_IsRationalOrNumber,l2_IsRationalOrNumber) <-- If(l1>l2,l1,l2);\n\n30 # Min(l1_IsConstant,l2_IsConstant) <-- If(N(Eval(l1-l2))<0,l1,l2);\n30 # Max(l1_IsConstant,l2_IsConstant) <-- If(N(Eval(l1-l2))>0,l1,l2);\n\n// Min and Max on empty lists\n10 # Min({}) <-- Undefined;\n10 # Max({}) <-- Undefined;\n\n20 # Min(list_IsList) <--\n[\n  Local(result);\n  result:= list[1];\n  ForEach(item,Tail(list)) result:=Min(result,item);\n  result;\n];\n20 # Max(list_IsList) <--\n[\n  Local(result);\n  result:= list[1];\n  ForEach(item,Tail(list)) result:=Max(result,item);\n  result;\n];\n\n30 # Min(_x) <-- x;\n30 # Max(_x) <-- x;\n\n/* Factorials */\n\n10 # 0! <-- 1;\n10 # (Infinity)! <-- Infinity;\n20 # ((n_IsPositiveInteger)!) <-- [\n    Check(n <= 65535, \"Factorial: Error: the argument \" : ( ToString() Write(n) ) : \" is too large, you may want to avoid exact calculation\");\n    MathFac(n);\n];\n\n25 # ((x_IsConstant)!)_(FloatIsInt(x) And x>0) <-- (Round(x)!);\n\n30 # ((x_IsNumber)!)_InNumericMode() <-- Internal'GammaNum(x+1);\n\n40 # (n_IsList)! <-- MapSingle(\"!\",n);\n\n/* formulae for half-integer factorials:\n\n(+(2*z+1)/2)! = Sqrt(Pi)*(2*z+1)! / (2^(2*z+1)*z!) for z >= 0\n(-(2*z+1)/2)! = Sqrt(Pi)*(-1)^z*z!*2^(2*z) / (2*z)! for z >= 0\n\nDouble factorials are more efficient:\n    (2*n-1)!! := 1*3*...*(2*n-1) = (2*n)! / (2^n*n!)\n    (2*n)!! := 2*4*...*(2*n) = 2^n*n!\n\n*/\n/* // old version - not using double factorials\nHalfIntegerFactorial(n_IsOdd) _ (n>0) <--\n    Sqrt(Pi) * ( n! / ( 2^n*((n-1)/2)! ) );\nHalfIntegerFactorial(n_IsOdd) _ (n<0)  <--\n    Sqrt(Pi) * ( (-1)^((-n-1)/2)*2^(-n-1)*((-n-1)/2)! / (-n-1)! );\n*/\n// new version using double factorials\nHalfIntegerFactorial(n_IsOdd) _ (n>0) <--\n    Sqrt(Pi) * ( n!! / 2^((n+1)/2) );\nHalfIntegerFactorial(n_IsOdd) _ (n<0)  <--\n    Sqrt(Pi) * ( (-1)^((-n-1)/2)*2^((-n-1)/2) / (-n-2)!! );\n//HalfIntegerFactorial(n_IsOdd) _ (n= -1)  <-- Sqrt(Pi);\n\n/* Want to also compute (2.5)! */\n40 # (n_IsRationalOrNumber)! _(Denom(Rationalize(n))=2) <-- HalfIntegerFactorial(Numer(Rationalize(n)));\n\n/// partial factorial\nn1_IsRationalOrNumber *** n2_IsRationalOrNumber <--\n[\n    Check(n2-n1 <= 65535, \"Partial factorial: Error: the range \" : ( ToString() Write(n2-n1) ) : \" is too large, you may want to avoid exact calculation\");\n    If(n2-n1<0,\n        1,\n        Factorial'partial(n1, n2)\n    );\n];\n\n/// recursive routine to evaluate \"partial factorial\" a*(a+1)*...*b\n// TODO lets document why the >>1 as used here is allowed (rounding down? What is the idea behind this algorithm?)\n2# Factorial'partial(_a, _b) _ (b-a>=4) <-- Factorial'partial(a, a+((b-a)>>1)) * Factorial'partial(a+((b-a)>>1)+1, b);\n3# Factorial'partial(_a, _b) _ (b-a>=3) <-- a*(a+1)*(a+2)*(a+3);\n4# Factorial'partial(_a, _b) _ (b-a>=2) <-- a*(a+1)*(a+2);\n5# Factorial'partial(_a, _b) _ (b-a>=1) <-- a*(a+1);\n6# Factorial'partial(_a, _b) _ (b-a>=0) <-- a;\n\n\n/* Binomials -- now using partial factorial for speed */\n// Bin(n,m) = Bin(n, n-m)\n10 # Bin(0,0)       <-- 1;\n10 # Bin(n_IsPositiveInteger,m_IsNonNegativeInteger)_(2*m <= n) <-- ((n-m+1) *** n) / m!;\n15 # Bin(n_IsPositiveInteger,m_IsNonNegativeInteger)_(2*m > n And m <= n) <-- Bin(n, n-m);\n20 # Bin(n_IsInteger,m_IsInteger) <-- 0;\n\n/// even/odd double factorial: product of even or odd integers up to n\n1# (n_IsPositiveInteger)!! _ (n<=3) <-- n;\n2# (n_IsPositiveInteger)!! <--\n[\n    Check(n<=65535, \"Double factorial: Error: the argument \" : ( ToString() Write(n) ) : \" is too large, you may want to avoid exact calculation\");\n    Factorial'double(2+Mod(n, 2), n);\n];\n// special cases\n3# (_n)!! _ (n= -1 Or n=0)<-- 1;\n\n// the purpose of this mess \"Div(a+b,2)+1+Mod(Div(a+b,2)+1-a, 2)\" is to obtain the smallest integer which is >= Div(a+b,2)+1 and is also odd or even when a is odd or even; we need to add at most 1 to (Div(a+b,2)+1)\n2# Factorial'double(_a, _b) _ (b-a>=6) <-- Factorial'double(a, Div(a+b,2)) * Factorial'double(Div(a+b,2)+1+Mod(Div(a+b,2)+1-a, 2), b);\n3# Factorial'double(_a, _b) _ (b-a>=4) <-- a*(a+2)*(a+4);\n4# Factorial'double(_a, _b) _ (b-a>=2) <-- a*(a+2);\n5# Factorial'double(_a, _b) <-- a;\n\n/// double factorial for lists is threaded\n30 # (n_IsList)!! <-- MapSingle(\"!!\",n);\n\n\n\n/* Sums */\n\nRuleBase(\"Sum\",{sumvar'arg,sumfrom'arg,sumto'arg,sumbody'arg});\n\n5  # Sum(_sumvar,sumfrom_IsNumber,sumto_IsNumber,_sumbody)_(sumfrom>sumto) <-- 0;\n\n10 # Sum(_sumvar,sumfrom_IsNumber,sumto_IsNumber,_sumbody)_(sumto<sumfrom) <--\n     ApplyPure(\"Sum\",{sumvar,sumto,sumfrom,sumbody});\n20 # Sum(_sumvar,sumfrom_IsNumber,sumto_IsNumber,_sumbody) <--\nLocalSymbols(sumi,sumsum)[\n   Local(sumi,sumsum);\n   sumsum:=0;\n   For(sumi:=sumfrom,sumi<=sumto,sumi++)\n       [\n        MacroLocal(sumvar);\n        MacroSet(sumvar,sumi);\n        sumsum:=sumsum+Eval(sumbody);\n       ];\n   sumsum;\n];\n\nUnFence(\"Sum\",4);\nHoldArg(\"Sum\",sumvar'arg);\nHoldArg(\"Sum\",sumbody'arg);\n\nFunction() Add(val, ...);\n\n10 # Add({}) <-- 0;\n20 # Add(values_IsList) <--\n[\n   Local(i, sum);\n   sum:=0;\n   ForEach(i, values) [ sum := sum + i; ];\n   sum;\n];\n\n// Add(1) should return 1\n30 # Add(_value) <-- value;\n\n/*COMMENT FROM AYAL: Jitse, I added some code to make Taylor2 work in the most general case too I believe.\n  Could you check to see if you agree with my changes? If that is correct, perhaps we can start calling Taylor2\n  by default in stead of Taylor1.\n */\nFunction(\"Taylor\",{taylorvariable,taylorat,taylororder,taylorfunction})\n  Taylor1(taylorvariable,taylorat,taylororder)(taylorfunction);\n\n/*COMMENT FROM AYAL: this is the old slow but working version of Taylor series expansion. Jitse wrote a\n * faster version which resides in taylor.ys, and uses lazy power series. This slow but correct version is still\n * useful for tests (the old and the new routine should yield identical results).\n */\nFunction(\"Taylor1\",{taylorvariable,taylorat,taylororder,taylorfunction})\n[\n  Local(n,result,dif,polf);\n  [\n    MacroLocal(taylorvariable);\n    [\n      MacroLocal(taylorvariable);\n      MacroSet(taylorvariable, taylorat);\n      result:=Eval(taylorfunction);\n    ];\n    If(result=Undefined,\n    [\n      result:=Apply(\"Limit\",{taylorvariable,taylorat,taylorfunction});\n    ]);\n/*\n    MacroSet(taylorvariable,taylorat);\n    result:=Eval(taylorfunction);\n*/\n  ];\n  dif:=taylorfunction;\n  polf:=(taylorvariable-taylorat);\n  For(n:=1,result != Undefined And n<=taylororder,n++)\n  [\n    dif:= Deriv(taylorvariable) dif;\n    Local(term);\n    MacroLocal(taylorvariable);\n    [\n      MacroLocal(taylorvariable);\n      MacroSet(taylorvariable, taylorat);\n      term:=Eval(dif);\n    ];\n    If(term=Undefined,\n    [\n      term:=Apply(\"Limit\",{taylorvariable,taylorat,dif});\n    ]);\n\n    result:=result+(term/(n!))*(polf^n);\n/*    result:=result+Apply(\"Limit\",{taylorvariable,taylorat,(dif/(n!))})*(polf^n); */\n/*\n    MacroSet(taylorvariable,taylorat);\n    result:=result+(Eval(dif)/(n!))*(polf^n);\n*/\n  ];\n  result;\n];\n\n\nFunction(\"Subfactorial\",{n})\n[\n    n! * Sum(k,0,n,(-1)^(k)/k!);\n];\n\n30 # Subfactorial(n_IsList) <-- MapSingle(\"Subfactorial\",n);\n\n10 # Fibonacci(0) <-- 0;\n\n20 # Fibonacci(n_IsPositiveInteger) <-- [\n    Local(a,b,c);\n    a := 0;\n    b := 1;\n    For(i:=1, i < n,i++) [\n        c := b + a;\n        a := b;\n        b := c;\n    ];\n\n    b;\n];\n\n30 # Fibonacci(n_IsInteger) <-- (-1)^(-n+1) * Fibonacci(-n);\n\n5 # LucasU(_n, 1, -1) <-- Fibonacci(n);\n\n10 # LucasU(0, p, q) <-- 0;\n\n20 # LucasU(n_IsPositiveInteger, p, q) <-- [\n    Local(a,b,c);\n    a := 0;\n    b := 1;\n    For(i:=1,i < n) [\n        c := p * b - q * a;\n        a := b;\n        b := c;\n    ];\n\n    b;\n];\n\n// Attempt to Sum series\n\nLocalSymbols(c,d,expr,from,to,summand,sum,predicate,k,n,r,var,x) [\n\nFunction() SumFunc(k,from,to,summand, sum, predicate );\nFunction() SumFunc(k,from,to,summand, sum);\nHoldArg(SumFunc,predicate);\nHoldArg(SumFunc,sum);\nHoldArg(SumFunc,summand);\n\n// Difference code does not work\nSumFunc(_sumvar,sumfrom_IsInteger,_sumto,_sumbody,_sum) <--\n[\n    // Take the given answer and create 2 rules, one for an exact match\n    // for sumfrom, and one which will catch sums starting at a different\n    // index and subtract off the difference\n\n    `(40 # Sum(@sumvar,@sumfrom,@sumto,@sumbody )   <-- Eval(@sum) );\n    `(41 # Sum(@sumvar,p_IsInteger,@sumto,@sumbody)_(p > @sumfrom)\n         <--\n         [\n              Local(sub);\n          (sub := Eval(UnList({Sum,sumvar'arg,@sumfrom,p-1,sumbody'arg})));\n          Simplify(Eval(@sum) - sub );\n             ]);\n];\n\nSumFunc(_sumvar,sumfrom_IsInteger,_sumto,_sumbody,_sum,_condition) <--\n[\n\n    `(40 # Sum(@sumvar,@sumfrom,@sumto,@sumbody)_(@condition)    <-- Eval(@sum) );\n    `(41 # Sum(@sumvar,p_IsInteger,@sumto,@sumbody )_(@condition And p > @sumfrom)\n         <--\n         [\n              Local(sub);\n          (sub := Eval(UnList({Sum,sumvar'arg,@sumfrom,p-1,sumbody'arg})));\n          Simplify(Eval(@sum) - sub );\n             ]);\n];\n\n// Some type of canonical form is needed so that these match when\n// given in a different order, like x^k/k! vs. (1/k!)*x^k\n// works !\nSumFunc(_k,1,_n,_c + _d,\n  Eval(UnList({Sum,sumvar'arg,1,n,c})) +\n  Eval(UnList({Sum,sumvar'arg,1,n,d}))\n);\nSumFunc(_k,1,_n,_c*_expr,Eval(c*UnList({Sum,sumvar'arg,1,n,expr})), IsFreeOf(k,c) );\nSumFunc(_k,1,_n,_expr/_c,Eval(UnList({Sum,sumvar'arg,1,n,expr})/c), IsFreeOf(k,c) );\n\n// ...same for sums starting at 0\nSumFunc(_k,0,_n,_c + _d,\n  Eval(UnList({Sum,sumvar'arg,0,n,c})) +\n  Eval(UnList({Sum,sumvar'arg,0,n,d}))\n);\nSumFunc(_k,0,_n,_c*_expr,Eval(c*UnList({Sum,sumvar'arg,0,n,expr})), IsFreeOf(k,c) );\nSumFunc(_k,0,_n,_expr/_c,Eval(UnList({Sum,sumvar'arg,0,n,expr})/c), IsFreeOf(k,c) );\n\n\n// this only works when the index=1\n// If the limit of the general term is not zero, then the series diverges\n// We need something like IsUndefined(term), because this croaks when limit return Undefined\n//SumFunc(_k,1,Infinity,_expr,Infinity,Eval(Abs(UnList({Limit,sumvar'arg,Infinity,expr})) > 0));\nSumFunc(_k,1,Infinity,1/_k,Infinity);\n\nSumFunc(_k,1,_n,_c,c*n,IsFreeOf(k,c) );\nSumFunc(_k,0,_n,_k, n*(n+1)/2 );\n//SumFunc(_k,1,_n,_k^2, n*(n+1)*(2*n+1)/6 );\n//SumFunc(_k,1,_n,_k^3, (n*(n+1))^2 / 4 );\nSumFunc(_k,1,_n,_k^_p,(Bernoulli(p+1,n+1) - Bernoulli(p+1))/(p+1), IsInteger(p) );\n// starting from 0 or 1 gives the same for IsPositiveInteger(p):\nSumFunc(_k,0,_n,_k^_p,(Bernoulli(p+1,n+1) - Bernoulli(p+1))/(p+1), IsPositiveInteger(p) );\n// for p = 0: 0^0 in algebraic setting considered equal to 1:\n// n'th power mean n'fold multiplication:\n//   0-th power: no multiplication at all, but multiply it by 1, as it doesn't change anything\n//               this way we obtain 1 for zeroth power of any number, 0 included.\nSumFunc(_k,0,_n,_k^0,n+1);\n\n\nSumFunc(_k,1,_n,2*_k-1, n^2 );\nSumFunc(_k,1,_n,HarmonicNumber(_k),(n+1)*HarmonicNumber(n) - n );\n\n// Geometric series! The simplest of them all ;-)\nSumFunc(_k,0,_n,(r_IsFreeOf(k))^(_k), (1-r^(n+1))/(1-r) );\n\n// Harmonic sum\nSumFunc(_k,0,_n,1/_k,Undefined);\nSumFunc(_k,0,_n,r_IsFreeOf(k)/_k,Undefined);\nSumFunc(_k,1,_n,1/_k,HarmonicNumber(n));\nSumFunc(_k,1,_n,r_IsFreeOf(k)/_k,r*HarmonicNumber(n));\n\n// Low-order polylogarithms (https://github.com/grzegorzmazur/yacas/issues/254)\n// _k is different from _k^1 because of Hold():\nSumFunc(_k, 1, _n, _k   * (z_IsFreeOf(k)^_k), z*( 1 - (n+1)*z^n + n*z^(n+1))/((1 - z)^2));\nSumFunc(_k, 1, _n, _k^1 * (z_IsFreeOf(k)^_k), z*( 1 - (n+1)*z^n + n*z^(n+1))/((1 - z)^2));\nSumFunc(_k, 1, _n, _k^2 * (z_IsFreeOf(k)^_k), z*( 1 + z - (n+1)^2 * (z^n) + (2*n^2 + 2*n - 1)*z^(n+1) - n^2 * z^(n+2))/(1-z)^3);\n\n\n// Infinite Series\n// this allows Zeta a complex argument, which is not supported yet\nSumFunc(_k,1,Infinity,1/(_k^_d), Zeta(d), IsFreeOf(k,d) );\nSumFunc(_k,1,Infinity,_k^(-_d), Zeta(d), IsFreeOf(k,d) );\n\nSumFunc(_k,0,Infinity,_x^(2*_k+1)/(2*_k+1)!,Sinh(x) );\nSumFunc(_k,0,Infinity,(-1)^k*_x^(2*_k+1)/(2*_k+1)!,Sin(x) );\nSumFunc(_k,0,Infinity,_x^(2*_k)/(2*_k)!,Cosh(x) );\nSumFunc(_k,0,Infinity,(-1)^k*_x^(2*_k)/(2*_k)!,Cos(x) );\nSumFunc(_k,0,Infinity,_x^(2*_k+1)/(2*_k+1),ArcTanh(x) );\nSumFunc(_k,0,Infinity,1/(_k)!,Exp(1) );\nSumFunc(_k,0,Infinity,_x^_k/(_k)!,Exp(x) );\n40 # Sum(_var,_from,Infinity,_expr)_( `(Limit(@var,Infinity)(@expr)) = Infinity) <-- Infinity;\n\nSumFunc(_k,1,Infinity,1/Bin(2*_k,_k), (2*Pi*Sqrt(3)+9)/27 );\nSumFunc(_k,1,Infinity,1/(_k*Bin(2*_k,_k)), (Pi*Sqrt(3))/9 );\nSumFunc(_k,1,Infinity,1/(_k^2*Bin(2*_k,_k)), Zeta(2)/3 );\nSumFunc(_k,1,Infinity,1/(_k^3*Bin(2*_k,_k)), 17*Zeta(4)/36 );\nSumFunc(_k,1,Infinity,(-1)^(_k-1)/_k, Ln(2) );\n\n];\n\n"
  },
  {
    "path": "scripts/sums.rep/code.ys.def",
    "content": "Min\nMax\n!\nBin\n!!\n***\nAdd\nSum\nAverage\nTaylor\nSubfactorial\nFibonacci\nLucasU\n}\n"
  },
  {
    "path": "scripts/sums.rep/om.ys",
    "content": "// From code.ys.def:\n// [2005-12-28 matmota]: I have to implement some better solution for the\n// Yacas -> OM mapping for these symbols. \nOMDef( \"Min\", \"minmax1\",\"min\",\n       { \"<OMA>\", \"<OMS cd=\\\"set1\\\" name=\\\"set\\\"/>\",\n         1,2,3,4,5,6,7,8,9,10,11,12,13,14,\n         \"</OMS>\", \"</OMA>\" },\n       ($):_1 );\nOMDef( \"Max\", \"minmax1\",\"max\",\n       { \"<OMA>\", \"<OMS cd=\\\"set1\\\" name=\\\"set\\\"/>\",\n         1,2,3,4,5,6,7,8,9,10,11,12,13,14,\n         \"</OMS>\", \"</OMA>\" },\n       ($):_1 );\nOMDef( \"!\", \"integer1\",\"factorial\" );\nOMDef( \"Bin\", \"combinat1\",\"binomial\" );\nOMDef( \"!!\",  \"yacas\",\"double_factorial\" );\nOMDef( \"***\", \"yacas\",\"partial_factorial\" );\nOMDef( \"Add\", \"yacas\",\"Add\" );\nOMDef( \"Sum\", \"arith1\",\"sum\", // Same argument reordering as Integrate.\n       { $, _2 .. _3, OMBIND(OMS(\"fns1\", \"lambda\"), OMBVAR(_1), _4) },\n       { $, _{2,2,1}, _{1,1}, _{1,2}, _{2,3} }\n      );\nOMDef( \"Product\", \"yacas\",\"Product\" );\nOMDef( \"Taylor\",    \"yacas\",\"Taylor\" );\nOMDef( \"Subfactorial\", \"yacas\",\"Subfactorial\" );\n"
  },
  {
    "path": "scripts/sums.rep/taylor.ys",
    "content": "/*\n * Taylor(x,a,n) y  ---  ENTRY POINT\n * ~~~~~~~~~~~~~~~\n * The n-th degree Taylor polynomial of y around x=a\n * \n * This function is implemented by doing calculus on power series.  For\n * instance, the Taylor series of Sin(x)^2 around x=0 is computed as\n * follows. First, we look up the series for Sin(x)\n *    Sin(x) = x - 1/6 x^3 + 1/120 x^5 - 1/5040 x^7 + ...\n * and then we compute the square of this series\n *    Sin(x)^2 = x^2 - x^4/3 + 2/45 x^6 - 1/315 x^8 + ...\n * \n * An alternative method is to use the formula\n *    Taylor(x,a,n) y = \\sum_{k=0}^n 1/k! a_k x^k,\n * where a_k is the k-th order derivative of y with respect to x,\n * evaluated at x=a. In fact, the old implementation of \"Taylor\", which\n * is retained in obsolete.ys, uses this method. However, we found out\n * that the expressions for the derivatives often grow very large, which\n * makes the computation too slow.\n * \n * The power series are implemented as lazy power series, which means\n * that the coefficients are computed on demand. Lazy power series are\n * encapsulated in expressions of the form\n *    Taylor'LPS(order, coeffs, var, expr).     \n * This represent the power series of \"expr\", seen as a function of\n * \"var\". \"coeffs\" is list of coefficients that have been computed thus \n * far. The integer \"order\" is the order of the first coefficient.\n * \n * For instance, the expression\n *    Taylor'LPS(1, {1,0,-1/6,0}, x, Sin(x))\n * contains the power series of Sin(x), viewed as a function of x, where\n * the four coefficients corresponding to x, x^2, x^3, and x^4 have been\n * computed. One can view this expression as x - 1/6 x^3 + O(x^5).\n * \n * \"coeffs\" is the empty list in the following special cases:\n * 1) order = Infinity represents the zero power series\n * 2) order = Undefined represents a power series of which no\n *    coefficients have yet been computed.\n * 3) order = n represents a power series of order at least n,\n *    of which no coefficients have yet been computed.\n *\n * \"expr\" may contain subexpressions of the form\n *    Taylor'LPS'Add(lps1, lps2)       = lps1)x) + lps2(x)\n *    Taylor'LPS'ScalarMult(a, lps)    = a*lps(x)  (a is scalar)\n *    Taylor'LPS'Multiply(lps1, lps2)  = lps1(x) * lps2(x)\n *    Taylor'LPS'Inverse(lps)          = 1/lps(x)\n *    Taylor'LPS'Power(lps, n)         = lps(x)^n  (n is natural number)\n *    Taylor'LPS'Compose(lps1, lps2)   = lps1(lps2(x))\n *\n * A well-formed LPS is an expression of the form \n *    Taylor'LPS(order, coeffs, var, expr)\n * satisfying the following conditions:     \n * 1) order is an integer, Infinity, or Undefined;\n * 2) coeffs is a list;\n * 3) if order is Infinity or Undefined, then coeffs is {};\n * 4) if order is an integer, then coeffs is empty \n *    or its first entry is nonzero;\n * 5) var does not appear in coeffs;\n * 6) expr is normalized with Taylor'LPS'NormalizeExpr.\n *\n */\n\n/* For the moment, the function is called Taylor2. */\n\n/* HELP: Is this the correct mechanism to signal incorrect input? */\n/*COMMENT FROM AYAL: Formally, I would do it the other way around, although this is more efficient. This \n  scheme says: all following rules hold if n>=0. Ideally you'd have a rule \"this transformation rule holds\n  if n>=0\". But then you would end up checking that n>=0 for each transformation rule, making things a little\n  bit slower (but more correct, more elegant).\n  */\n10 # (Taylor2(_x, _a, _n) _y)\n   _ (Not(IsPositiveInteger(n) Or IsZero(n)))\n   <-- Check(False, \n             \"Third argument to Taylor should be a nonnegative integer\"); \n\n20 # (Taylor2(_x, 0, _n) _y) <-- \n[\n   Local(res);\n   res := Taylor'LPS'PowerSeries(Taylor'LPS'Construct(x, y), n, x);\n   If (ClearError(\"singularity\"),\n       Echo(y, \"has a singularity at\", x, \"= 0.\"));\n   If (ClearError(\"dunno\"),\n       Echo(\"Cannot determine power series of\", y));\n   res;\n];\n\n30 # (Taylor2(_x, _a, _n) _y) \n   <-- Subst(x,x-a) Taylor2(x,0,n) Subst(x,x+a) y;\n\n/**********************************************************************\n *\n * Parameters \n * ~~~~~~~~~~\n * The number of coefficients to be computed before concluding that a\n * given power series is zero */\n\n\n\n/*TODO COMMENT FROM AYAL: This parameter, 15, seems to be a bit arbitrary. This implies that there is an input\n   with more than 15 zeroes, and then a non-zero coefficient, that this would fail on. Correct? Is there not\n   a more accurate estimation of this parameter?\n */\nTaylor'LPS'Param1() := 15;\n\n/**********************************************************************\n *\n * Taylor'LPS'Construct(var, expr)\n * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n * construct a LPS\n * PRE:  var is a name\n * POST: returns a well-formed LPS\n */\n\n10 # Taylor'LPS'Construct(_var, _expr)\n   <-- Taylor'LPS(Undefined, {}, var, \n                  Taylor'LPS'NormalizeExpr(var, expr));\n\n/**********************************************************************\n * \n * Taylor'LPS'Coeffs(lps, n1, n2)\n * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n * List of coefficients of order n1 up to n2\n * PRE:  lps is a well-formed LPS, n1 in Z, n2 in Z, n2 >= n1\n * POST: returns list of length n2-n1+1, \n *       or raises \"dunno\", \"div-by-zero\", or \"maybe-div-by-zero\"\n *       lps may be changed, but it's still a well-formed LPS\n */\n\nTaylor'LPS'Coeffs(_lps, _n1, _n2) <--\n[\n   Local(res, finished, order, j, k, n, tmp, c1, c2);\n   finished := False;\n\n   /* Case 1: Zero power series */\n\n   If (lps[1] = Infinity,\n   [\n      res := FillList(0, n2-n1+1); \n      finished := True;\n   ]);\n\n   /* Case 2: Coefficients are already computed */\n\n   If (Not finished And lps[1] != Undefined And n2 < lps[1]+Length(lps[2]),\n   [\n      If (n1 >= lps[1],\n          res := Take(lps[2], {n1-lps[1]+1, n2-lps[1]+1}),\n\t  If (n2 >= lps[1],\n              res := Concat(FillList(0, lps[1]-n1), \n                             Take(lps[2], n2-lps[1]+1)),\n\t      res := FillList(0, n2-n1+1)));\n      finished := True;\n   ]);\n\n   /* Case 3: We need to compute the coefficients */\n\n   If (Not finished,\n   [\n      /* Subcase 3a: Expression is recognized by Taylor'LPS'CompOrder */\n\n      order := Taylor'LPS'CompOrder(lps[3], lps[4]);\n      If (Not ClearError(\"dunno\"),\n      [\n         If (lps[1] = Undefined,\n         [\n\t    lps[1] := order;\n            If (order <= n2, \n            [\n               lps[2] := Table(Taylor'LPS'CompCoeff(lps[3], lps[4], n), \n                               n, order, n2, 1);\n            ]);\n         ],[\n\t    tmp := Table(Taylor'LPS'CompCoeff(lps[3], lps[4], n), \n                         n, lps[1]+Length(lps[2]), n2, 1);\n\t    lps[2] := Concat(lps[2], tmp);\n         ]);\n         finished := True;\n      ]);\n\n      /* Subcase 3b: Addition */\n   \n      If (Not finished And lps[4][0] = Taylor'LPS'Add,\n      [\n         lps[1] := Min(Taylor'LPS'GetOrder(lps[4][1])[1],\n                       Taylor'LPS'GetOrder(lps[4][2])[1], n2);\n         If (IsError(\"dunno\"),\n         [\n            ClearError(\"dunno\");\n            ClearError(\"dunno\");\n\t ],[\n   \t    If (lps[1] <= n2,\n            [\n               c1 := Taylor'LPS'Coeffs(lps[4][1], lps[1] + Length(lps[2]), n2);\n               c2 := Taylor'LPS'Coeffs(lps[4][2], lps[1] + Length(lps[2]), n2);\n   \t       lps[2] := Concat(lps[2], c1 + c2);\n            ]);\n   \t    finished := True;\n         ]);\n      ]);\n\n      /* Subcase 3c: Scalar multiplication */\n\n      If (Not finished And lps[4][0] = Taylor'LPS'ScalarMult,\n      [\n         lps[1] := Min(Taylor'LPS'GetOrder(lps[4][2])[1], n2);\n         If (Not ClearError(\"dunno\"),\n         [\n   \t    If (lps[1] <= n2,\n            [\n\t       tmp := Taylor'LPS'Coeffs(lps[4][2], \n                                        lps[1] + Length(lps[2]), n2);\n\t       tmp := lps[4][1] * tmp;\n               lps[2] := Concat(lps[2], tmp); \n            ]);\n   \t    finished := True;\n         ]);\n      ]);\n\n      /* Subcase 3d: Multiplication */\n\n      If (Not finished And lps[4][0] = Taylor'LPS'Multiply,\n      [\n         lps[1] := Taylor'LPS'GetOrder(lps[4][1])[1] \n                   + Taylor'LPS'GetOrder(lps[4][2])[1];\n         If (IsError(\"dunno\"),\n         [\n            ClearError(\"dunno\");\n            ClearError(\"dunno\");\n\t ],[\n   \t    If (lps[1] <= n2,\n            [\n               c1 := Taylor'LPS'Coeffs(lps[4][1], lps[4][1][1], \n                                       n2 - lps[4][2][1]);\n               c2 := Taylor'LPS'Coeffs(lps[4][2], lps[4][2][1], \n                                       n2 - lps[4][1][1]);\n               tmp := lps[2];\n\t       For(k:=(Length(lps[2])+1),k<=Length(c1),k++)\n\t          tmp := Append(tmp, Sum(j, 1, k, c1[j]*c2[k+1-j]));\n\t       lps[2] := tmp;\n            ]);\n   \t    finished := True;\n         ]);\n      ]);\n\n      /* Subcase 3e: Inversion */\n\n      If (Not finished And lps[4][0] = Taylor'LPS'Inverse,\n      [\n         If (lps[4][1][1] = Infinity,\n\t [\n\t    Assert(\"div-by-zero\") False;\n\t    finished := True;\n\t ]);\n\t If (Not finished And lps[2] = {}, \n         [\n\t    order := Taylor'LPS'GetOrder(lps[4][1])[1];\n\t    n := order;\n\t    c1 := Taylor'LPS'Coeffs(lps[4][1], n, n)[1];\n\t    While (c1 = 0 And n < order + Taylor'LPS'Param1())\n            [\n\t       n := n + 1;\n \t       c1 := Taylor'LPS'Coeffs(lps[4][1], n, n)[1];\n\t    ];\n\t    If (c1 = 0,\n\t    [\n\t       Assert(\"maybe-div-by-zero\") False;\n\t       finished := True;\n\t    ]);\n         ]);\n\t If (Not finished,\n\t [\n\t    lps[1] := -lps[4][1][1];\n\t    c1 := Taylor'LPS'Coeffs(lps[4][1], lps[4][1][1], \n                                    lps[4][1][1]+n2-lps[1]);\n\t    tmp := lps[2];\n\t    If (tmp = {}, tmp := {1/c1[1]});\n\t    If (Length(c1)>1, \n\t    [\n               For(k:=(Length(tmp)+1),k<=Length(c1),k++)\n               [\n\t          n := -Sum(j, 1, k-1, c1[k+1-j]*tmp[j]) / c1[1];\n\t          tmp := Append(tmp, n);\n               ];\n\t    ]);\n\t    lps[2] := tmp;\n            finished := True;\n\t ]);\n      ]);\n\t    \n      /* Subcase 3f: Composition */\n\n      If (Not finished And lps[4][0] = Taylor'LPS'Compose,\n      [\n\t j := Taylor'LPS'GetOrder(lps[4][1])[1];\n\t Check(j >= 0, \"Expansion of f(g(x)) where f has a\"\n                       : \"singularity is not implemented\");\n\t k := Taylor'LPS'GetOrder(lps[4][2])[1];\n         c1 := {j, Taylor'LPS'Coeffs(lps[4][1], j, n2)};\n         c2 := {k, Taylor'LPS'Coeffs(lps[4][2], k, n2)};\n\t c1 := Taylor'TPS'Compose(c1, c2);\n\t lps[1] := c1[1];\n\t lps[2] := c1[2];\n\t finished := True;\n      ]);\n\n      /* Case 3: The end */\n\n      If (finished,\n      [\n         /* normalization: remove initial zeros from lps[2] */\n\n\t While (lps[2] != {} And lps[2][1] = 0)\n\t [\n\t    lps[1] := lps[1] + 1;\n\t    lps[2] := Tail(lps[2]);\n\t ];\n\n\t /* get result */\n\n\t If (Not IsError(\"dunno\") And Not IsError(\"div-by-zero\")\n\t     And Not IsError(\"maybe-div-by-zero\"),\n\t [\n            If (lps[1] <= n1,\n                res := Take(lps[2], {n1-lps[1]+1, n2-lps[1]+1}),\n                If (lps[1] <= n2,\n                    res := Concat(FillList(0, lps[1]-n1), lps[2]),\n                    res := FillList(0, n2-n1+1)));\n         ]);\n      ],[\n         Assert(\"dunno\") False; \n         res := False;\n      ]);\n   ]);\n\n   /* Return res */\n\n   res;\n];\n\n\n/**********************************************************************\n *\n * Truncated power series\n * ~~~~~~~~~~~~~~~~~~~~~~\n * Here is the start of an implementation of truncated power series.\n * This should be cleaned up.\n *\n * {n, {a0,a1,a2,a3,...}} represents \n * a0 x^n + a1 x^(n+1) + a2 x^(n+2) + a3 x^(n+3) + ...\n *\n * The function Taylor'TPS'Add(tps1, tps2) adds two of such beasts,\n * and returns the sum in the same truncated power series form. \n * Similar for the other functions.\n */\n\n10 # Taylor'TPS'GetCoeff({_n,_c}, _k) _ (k < n) <-- 0;\n10 # Taylor'TPS'GetCoeff({_n,_c}, _k) _ (k >= n+Length(c)) <-- Undefined;\n20 # Taylor'TPS'GetCoeff({_n,_c}, _k) <-- c[k-n+1];\n\n\n10 # Taylor'TPS'Add({_n1,_c1}, {_n2,_c2}) <--\n[\n   Local(n, len, c1b, c2b);\n   n := Min(n1,n2);\n   len := Min(n1+Length(c1), n2+Length(c2)) - n;\n   c1b := Take(Concat(FillList(0, n1-n), c1), len);\n   c2b := Take(Concat(FillList(0, n2-n), c2), len);\n   {n, c1b+c2b};\n];\n\n10 # Taylor'TPS'ScalarMult(_a, {_n2,_c2}) <-- {n2, a*c2};\n\n10 # Taylor'TPS'Multiply({_n1,_c1}, {_n2,_c2}) <--\n[\n   Local(j,k,c);\n   c := {};\n   For (k:=1, k<=Min(Length(c1), Length(c2)), k++)\n   [\n      c := c : Sum(j, 1, k, c1[j]*c2[k+1-j]);\n   ];\n   {n1+n2, c};\n];\n\n10 # Taylor'TPS'Compose({_n1,_c1}, {_n2,_c2}) <--\n[\n   Local(res, tps, tps2, k, n);\n   n := Min(n1+Length(c1)-1, n2+Length(c2)-1);   \n   tps := {0, 1 : FillList(0, n)}; // tps = {n2,c2} ^ k\n   res := Taylor'TPS'ScalarMult(Taylor'TPS'GetCoeff({n1,c1}, 0), tps);   \n   For (k:=1, k<=n, k++)\n   [\n      tps := Taylor'TPS'Multiply(tps, {n2,c2});\n      tps2 := Taylor'TPS'ScalarMult(Taylor'TPS'GetCoeff({n1,c1}, k), tps);\n      res := Taylor'TPS'Add(res, tps2);\n   ];\n   res;\n];\n\n\n\n/**********************************************************************\n *\n * Taylor'LPS'NormalizeExpr(var, expr)\n * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n * Return expr, with \"+\" replaced by Taylor'LPS'Add, etc. \n * PRE:  var is a name\n */\n\n5 # Taylor'LPS'NormalizeExpr(_var, _e1)\n  _ [Taylor'LPS'CompOrder(var,e1); Not ClearError(\"dunno\");]\n  <-- e1;\n\n10 # Taylor'LPS'NormalizeExpr(_var, _e1 + _e2)\n   <-- Taylor'LPS'Add(Taylor'LPS'Construct(var, e1),\n                      Taylor'LPS'Construct(var, e2));\n\n10 # Taylor'LPS'NormalizeExpr(_var, - _e1)\n   <-- Taylor'LPS'ScalarMult(-1, Taylor'LPS'Construct(var, e1));\n\n10 # Taylor'LPS'NormalizeExpr(_var, _e1 - _e2)\n   <-- (Taylor'LPS'Add(Taylor'LPS'Construct(var, e1),\n                       Taylor'LPS'Construct(var, e3))\n        Where e3 == Taylor'LPS'ScalarMult(-1, Taylor'LPS'Construct(var, e2)));\n\n10 # Taylor'LPS'NormalizeExpr(_var, e1_IsFreeOf(var) * _e2)\n   <-- Taylor'LPS'ScalarMult(e1, Taylor'LPS'Construct(var, e2));\n\n10 # Taylor'LPS'NormalizeExpr(_var, _e1 * e2_IsFreeOf(var))\n   <-- Taylor'LPS'ScalarMult(e2, Taylor'LPS'Construct(var, e1));\n\n20 # Taylor'LPS'NormalizeExpr(_var, _e1 * _e2)\n   <-- Taylor'LPS'Multiply(Taylor'LPS'Construct(var, e1),\n                           Taylor'LPS'Construct(var, e2));\n\n10 # Taylor'LPS'NormalizeExpr(_var, _e1 / e2_IsFreeOf(var))\n   <-- Taylor'LPS'ScalarMult(1/e2, Taylor'LPS'Construct(var, e1));\n\n20 # Taylor'LPS'NormalizeExpr(_var, 1 / _e1)\n   <-- Taylor'LPS'Inverse(Taylor'LPS'Construct(var, e1));\n\n30 # Taylor'LPS'NormalizeExpr(_var, _e1 / _e2)\n   <-- (Taylor'LPS'Multiply(Taylor'LPS'Construct(var, e1),\n                            Taylor'LPS'Construct(var, e3))\n        Where e3 == Taylor'LPS'Inverse(Taylor'LPS'Construct(var, e2)));\n\n/* Implement powers as repeated multiplication, \n * which is seriously inefficient.\n */\n10 # Taylor'LPS'NormalizeExpr(_var, _e1 ^ (n_IsPositiveInteger))\n   _ (e1 != var)\n   <-- Taylor'LPS'Multiply(Taylor'LPS'Construct(var, e1),\n                           Taylor'LPS'Construct(var, e1^(n-1)));\n\n10 # Taylor'LPS'NormalizeExpr(_var, Tan(_x)) \n   <-- (Taylor'LPS'Multiply(Taylor'LPS'Construct(var, Sin(x)),\n                            Taylor'LPS'Construct(var, e3))\n        Where e3 == Taylor'LPS'Inverse(Taylor'LPS'Construct(var, Cos(x))));\n\nLocalSymbols(res) \n[\n50 # Taylor'LPS'NormalizeExpr(_var, _e1) \n_[ \n    Local(c, lps1, lps2, lps3, success);\n    success := True;\n    If (IsAtom(e1), success := False);\n    If (success And Length(e1) != 1, success := False);\n    If (success And IsAtom(e1[1]), success := False);\n    If (success And CanBeUni(var, e1[1]) And Degree(e1[1], var) = 1, \n    [\n       success := False;\n    ]);\n    If (success,\n    [\n       lps2 := Taylor'LPS'Construct(var, e1[1]);\n       c := Taylor'LPS'Coeffs(lps2, 0, 0)[1];\n       If (IsError(),\n       [\n          ClearErrors();\n\t  success := False;\n       ]);\n       If (success And Taylor'LPS'GetOrder(lps2)[1] < 0,\n       [\n          success := False;\n       ],[\n          If (c = 0,\n          [\n             lps1 := Taylor'LPS'Construct(var, Apply(e1[0], {var}));\n             res := Taylor'LPS'Compose(lps1, lps2);\n          ],[\n             lps1 := Taylor'LPS'Construct(var, Apply(e1[0], {var+c}));\n             lps3 := Taylor'LPS'Construct(var, -c);\n\t     lps2 := Taylor'LPS'Construct(var, Taylor'LPS'Add(lps2, lps3));\n             res := Taylor'LPS'Compose(lps1, lps2);\n          ]);\n       ]);\n    ]);\n    success;\n ] <-- res;\n];\n\n60000 # Taylor'LPS'NormalizeExpr(_var, _e1) <-- e1;\n\n\n/**********************************************************************\n *\n * Taylor'LPS'CompOrder(var, expr)  ---  HOOK\n * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n * Compute order of expr as a power series in var\n * PRE:  var is a name\n * POST: returns an integer, or raises \"dunno\"\n *\n * Taylor'LPS'CompCoeff(var, expr, n)  ---  HOOK\n * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n * Compute n-th coefficient of expr as a power series in var\n * PRE:  var is a name, n is an integer, \n *       Taylor'LPS'CompOrder(var, expr) does not raise \"dunno\"\n * POST: returns an expression not containing var\n */\n\n5  # Taylor'LPS'CompCoeff(_var, _expr, _n)\n   _ (n < Taylor'LPS'CompOrder(var, expr))\n   <-- 0;\n\n/* Zero */\n\n10 # Taylor'LPS'CompOrder(_x, 0) <-- Infinity;\n\n/* Constant */\n\n20 # Taylor'LPS'CompOrder(_x, e_IsFreeOf(x))     <-- 0;\n20 # Taylor'LPS'CompCoeff(_x, e_IsFreeOf(x), 0)  <-- e;\n21 # Taylor'LPS'CompCoeff(_x, e_IsFreeOf(x), _n) <-- 0;\n\n/* Identity */\n\n30 # Taylor'LPS'CompOrder(_x, _x)     <-- 1;\n30 # Taylor'LPS'CompCoeff(_x, _x, 1)  <-- 1;\n31 # Taylor'LPS'CompCoeff(_x, _x, _n) <-- 0;\n\n/* Powers */\n\n40 # Taylor'LPS'CompOrder(_x, _x^(k_IsPositiveInteger))     <-- k;\n40 # Taylor'LPS'CompCoeff(_x, _x^(k_IsPositiveInteger), _k) <-- 1;\n41 # Taylor'LPS'CompCoeff(_x, _x^(k_IsPositiveInteger), _n) <-- 0;\n\n/* Sqrt */\n\n50 # Taylor'LPS'CompOrder(_x, Sqrt(_y))\n   _ (CanBeUni(x,y) And Degree(y,x) = 1 And Coef(y,x,0) != 0)\n   <-- 0;\n\n50 # Taylor'LPS'CompCoeff(_x, Sqrt(_y), 0)\n   _ (CanBeUni(x,y) And Degree(y,x) = 1 And Coef(y,x,0) != 0) \n   <-- Sqrt(Coef(y,x,0));\n\n51 # Taylor'LPS'CompCoeff(_x, Sqrt(_y), _n)\n   _ (CanBeUni(x,y) And Degree(y,x) = 1 And Coef(y,x,0) != 0) <-- \n[ \n   Local(j); \n   Coef(y,x,0)^(1/2-n) * Product(j,0,n-1,1/2-j) * Coef(y,x,1)^n/n!;\n];\n\n/* Exp */\n\n60 # Taylor'LPS'CompOrder(_x, Exp(_x))     <-- 0;\n60 # Taylor'LPS'CompCoeff(_x, Exp(_x), _n) <-- 1/n!;\n\n70 # Taylor'LPS'CompOrder(_x, Exp(_y))_(CanBeUni(x,y) And Degree(y,x) = 1)\n   <-- 0;\n\n70 # Taylor'LPS'CompCoeff(_x, Exp(_y), _n)_(CanBeUni(x,y) And Degree(y,x) = 1)\n   <-- Exp(Coef(y,x,0)) * Coef(y,x,1)^n / n!;\n\n/* Ln */\n\n80 # Taylor'LPS'CompOrder(_x, Ln(_x+1))     <-- 1;\n80 # Taylor'LPS'CompCoeff(_x, Ln(_x+1), _n) <-- (-1)^(n+1)/n;\n\n/* Sin */\n\n90 # Taylor'LPS'CompOrder(_x, Sin(_x))           <-- 1;\n90 # Taylor'LPS'CompCoeff(_x, Sin(_x), n_IsOdd)  <-- (-1)^((n-1)/2) / n!;\n90 # Taylor'LPS'CompCoeff(_x, Sin(_x), n_IsEven) <-- 0;\n\n/* Cos */\n\n100 # Taylor'LPS'CompOrder(_x, Cos(_x))           <-- 0;\n100 # Taylor'LPS'CompCoeff(_x, Cos(_x), n_IsOdd)  <-- 0;\n100 # Taylor'LPS'CompCoeff(_x, Cos(_x), n_IsEven) <-- (-1)^(n/2) / n!;\n\n/* Inverse (not needed but speeds things up) */\n\n110 # Taylor'LPS'CompOrder(_x, 1/_x)     <-- -1;\n110 # Taylor'LPS'CompCoeff(_x, 1/_x, -1) <-- 1;\n111 # Taylor'LPS'CompCoeff(_x, 1/_x, _n) <-- 0;\n\n\n/*COMMENT FROM AYAL: Jitse, what do you think, fall-through defaulting to calculating the coefficient \n  the hard way? Worst-case, if people define a taylor series in this module it is faster, otherwise it uses\n  the old scheme that does explicit derivatives, which is slower, but still better than not returning a result \n  at all? With this change the new taylor code is at least as good as the old code? \n  \n  The ugly part is obvious: instead of having a rule here that says \"I work for the following input\" I had to\n  find out empirically what the \"exclude list\" is, eg. the input it will not work on. This because the system\n  as it works currently yields \"dunno\", at which moment some other routine picks up. \n  \n  I think we can refactor this.\n */\n\n\n\n\nTaylor'LPS'AcceptDeriv(_expr) <-- \n        (Contains({\"ArcTan\"},Type(expr)));\n/*\n        ( Type(Deriv(x)(expr)) != \"Deriv\"\n         And Not Contains({\n          \"/\",\"+\",\"*\",\"^\",\"-\",\"Sin\",\"Cos\",\"Sqrt\",\"Ln\",\"Exp\",\"Tan\"\n          },Type(expr)));\n*/\n\n200 # Taylor'LPS'CompOrder(_x, (_expr))_(Taylor'LPS'AcceptDeriv(expr)) \n    <-- \n    [\n//Echo(\"CompOrder for \",expr);\n//      0; //generic case, assume zeroeth coefficient is non-zero.\n      Local(n);\n      n:=0;\n      While ((Limit(x,0)expr) = 0 And n<Taylor'LPS'Param1())\n      [\n        expr := Deriv(x)expr;\n        n++;\n      ];\n//Echo(\" is \",n);\n      n;\n    ];\n200 # Taylor'LPS'CompCoeff(_x, (_expr), _n)_\n      (Taylor'LPS'AcceptDeriv(expr) And n>=0 ) <-- \n    [\n    // This routine is written out for debugging purposes\n      Local(result);\n      result:=(Limit(x,0)(Deriv(x,n)expr))/(n!);\nEcho(expr,\" \",n,\" \",result);\n      result;\n    ];\n\n/* Default */\n\n60000 # Taylor'LPS'CompOrder(_var, _expr) \n      <-- Assert(\"dunno\") False;\n\n60000 # Taylor'LPS'CompCoeff(_var, _expr, _n) \n      <-- Check(False, \"Taylor'LPS'CompCoeff'FallThrough\" \n                       : ToString() Write({var,expr,n}));\n\n/**********************************************************************\n *\n * Taylor'LPS'GetOrder(lps)\n * ~~~~~~~~~~~~~~~~~~~~~~~~\n * Returns a pair {n,flag}. If flag is True, then n is the order of\n * the LPS. If flag is False, then n is a lower bound on the order.\n * PRE:  lps is a well-formed LPS\n * POST: returns a pair {n,flag}, where n is an integer or Infinity,\n *       and flag is True or False, or raises \"dunno\"; \n *       may update lps.\n */\n\n20 # Taylor'LPS'GetOrder(Taylor'LPS(_order, _coeffs, _var, _expr))\n   _ (order != Undefined)\n   <-- {order, coeffs != {}};\n\n40 # Taylor'LPS'GetOrder(_lps) <--\n[\n   Local(res, computed, exact, res1, res2);\n   computed := False;\n\n   res := Taylor'LPS'CompOrder(lps[3], lps[4]); \n   If (Not ClearError(\"dunno\"), \n   [\n      res := {res, True};\n      computed := True;\n   ]);\n   \n   If (Not computed And lps[4][0] = Taylor'LPS'Add,\n   [\n      res1 := Taylor'LPS'GetOrder(lps[4][1]);\n      If (Not ClearError(\"dunno\"), \n      [ \n         res2 := Taylor'LPS'GetOrder(lps[4][2]);\n         If (Not ClearError(\"dunno\"), \n\t [\n\t    res := {Min(res1[1],res2[1]), False}; \n\t    /* flag = False, since terms may cancel */\n\t    computed := True;\n\t ]);\n      ]);\n   ]);\n\n   If (Not computed And lps[4][0] = Taylor'LPS'ScalarMult,\n   [\n      res := Taylor'LPS'GetOrder(lps[4][2]);\n      If (Not ClearError(\"dunno\"), computed := True);\n   ]);\n\n   If (Not computed And lps[4][0] = Taylor'LPS'Multiply,\n   [\n      res1 := Taylor'LPS'GetOrder(lps[4][1]);\n      If (Not ClearError(\"dunno\"), \n      [ \n         res2 := Taylor'LPS'GetOrder(lps[4][2]);\n         If (Not ClearError(\"dunno\"), \n\t [\n\t    res := {res1[1]+res2[1], res1[1] And res2[1]};\n\t    computed := True;\n\t ]);\n      ]);\n   ]);\n\n   If (Not computed And lps[4][0] = Taylor'LPS'Inverse,\n   [\n      res := Taylor'LPS'GetOrder(lps[4][1]);\n      If (Not ClearError(\"dunno\"), \n      [\n         If (res[1] = Infinity,\n\t [\n\t    res[1] = Undefined;\n\t    Assert(\"div-by-zero\") False;\n\t    computed := True;\n\t ]);\n         If (Not computed And res[2] = False,\n\t [\n\t    Local(c, n);\n\t    n := res[1];\n\t    c := Taylor'LPS'Coeffs(lps[4][1], res[1], res[1])[1];\n\t    While (c = 0 And res[1] < n + Taylor'LPS'Param1())\n            [\n\t       res[1] := res[1] + 1;\n \t       c := Taylor'LPS'Coeffs(lps[4][1], res[1], res[1])[1];\n\t    ];\n\t    If (c = 0,\n\t    [\n\t       res[1] := Undefined;\n\t       Assert(\"maybe-div-by-zero\") False;\n\t       computed := True;\n\t    ]);\n\t ]);\n\t If (Not computed,\n\t [\n\t    res := {-res[1], True};\n\t    computed := True;\n\t ]);\n      ]);\n   ]);\n\n   If (Not computed And lps[4][0] = Taylor'LPS'Compose,\n   [\n      res1 := Taylor'LPS'GetOrder(lps[4][1]);\n      If (Not ClearError(\"dunno\"), \n      [ \n         res2 := Taylor'LPS'GetOrder(lps[4][2]);\n         If (Not ClearError(\"dunno\"), \n\t [\n\t    res := {res1[1]*res2[1], res1[1] And res2[1]};\n\t    computed := True;\n\t ]);\n      ]);\n   ]);\n\n   If (computed, lps[1] := res[1]);\n   Assert(\"dunno\") computed;\n   res;\n];\n\n/**********************************************************************\n * \n * Taylor'LPS'PowerSeries(lps, n, var)\n * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n * Convert the LPS in a power series in var up to order n\n * PRE:  lps is a well-formed LPS, n is a natural number\n * POST: returns an expression, or raises \"singularity\" or \"dunno\"\n */\n\n10 # Taylor'LPS'PowerSeries(_lps, _n, _var) <--\n[\n   Local(ord, k, coeffs);\n   coeffs := Taylor'LPS'Coeffs(lps, 0, n);\n   If (IsError(\"dunno\"),\n   [\n      False;\n   ],[\n      If (lps[1] < 0,\n      [ \n         Assert(\"singularity\") False;\n         Undefined;\n      ],[\n         Sum(k, 0, n, coeffs[k+1]*var^k);\n      ]);\n   ]);\n];\n"
  },
  {
    "path": "scripts/sums.rep/taylor.ys.def",
    "content": "Taylor2\n}"
  },
  {
    "path": "scripts/sums.rep/taylor3.ys",
    "content": "\n\n/* Taylor3, implementation of Taylor series expansion by doing calculation on series directly.\n */\n\nDefun(\"Taylor3'MultiplyCoefs\",{coefs1,coefs2,degree})\n[\n  Local(result,i,j,jset,ilimit,jlimit);\n  Set(result, Array'Create(MathAdd(degree,1),0));\n  Set(i,1);\n  Set(ilimit,MathAdd(degree,2));\n  While (Not Equals(i,ilimit))\n  [\n//Echo(coefs1,coefs2);\n    Set(j,1);\n    Set(jlimit,MathAdd(degree,MathSubtract(3,i)));\n    While (Not Equals(j,jlimit))\n    [\n      Set(jset,MathAdd(i,MathSubtract(j,1)));\n//Echo(\"index = \",i+j-1);\n      Array'Set(result,jset,Array'Get(result,jset) + Array'Get(coefs1,i)*Array'Get(coefs2,j));\n      Set(j,MathAdd(j,1));\n    ];\n    Set(i,MathAdd(i,1));\n  ];\n  result;\n];\n\n\nBodied(\"Taylor3'TaylorCoefs\",0);\n10 # (Taylor3'TaylorCoefs(_var,_degree)(_var)) <-- \n[\n  Local(result);\n  Set(result,Array'Create(degree+1,0));\n  Array'Set(result,2, 1);\n  result;\n//Echo(\"degree = \",degree);\n//  BaseVector(2,degree+1);\n];\n20 # (Taylor3'TaylorCoefs(_var,_degree)(_atom))_(IsFreeOf(var,atom)) \n   <-- \n   [\n    Local(result);\n    Set(result,Array'Create(degree+1,0));\n    Array'Set(result,1, atom);\n    result;\n//     atom*BaseVector(1,degree+1);\n   ];\n30 # (Taylor3'TaylorCoefs(_var,_degree)(_X + _Y)) \n   <-- \n   [\n     Local(result,add,i);\n     Set(result,Taylor3'TaylorCoefs(var,degree)(X));\n     Set(add, Taylor3'TaylorCoefs(var,degree)(Y));\n     For(i:=1,i<=degree+1,i++)\n     [\n       Array'Set(result,i,Array'Get(result,i)+Array'Get(add,i));\n     ];\n     result;\n   ];\n   \n30 # (Taylor3'TaylorCoefs(_var,_degree)(_X - _Y)) \n   <-- \n   [\n     Local(result,add,i);\n     Set(result,Taylor3'TaylorCoefs(var,degree)(X));\n     Set(add, Taylor3'TaylorCoefs(var,degree)(Y));\n     For(i:=1,i<=degree+1,i++)\n     [\n       Array'Set(result,i,Array'Get(result,i)-Array'Get(add,i));\n     ];\n     result;\n   ];\n\n30 # (Taylor3'TaylorCoefs(_var,_degree)(   - _Y))\n   <-- \n   [\n     Local(result,add,i);\n     Set(result,Taylor3'TaylorCoefs(var,degree)(Y));\n     For(i:=1,i<=degree+1,i++)\n     [\n       Array'Set(result,i,-Array'Get(result,i));\n     ];\n     result;\n   ];\n\n30 # (Taylor3'TaylorCoefs(_var,_degree)(_X * _Y)) \n   <-- Taylor3'MultiplyCoefs(\n         Taylor3'TaylorCoefs(var,degree)(X),\n         Taylor3'TaylorCoefs(var,degree)(Y),\n         degree);\n\n30 # (Taylor3'TaylorCoefs(_var,_degree)((_X) ^ N_IsPositiveInteger)) \n  <-- \n[\n  Local(result,factor);\n  factor:=Taylor3'TaylorCoefs(var,degree)(X);\n  result:=Array'Create(degree+1,0);\n  result[1] := 1;\n  //TODO@@@ optimize\n  While(N>0)\n  [\n    result:=Taylor3'MultiplyCoefs(result,factor,degree);\n    N--;\n  ];\n  result;\n];\n\n60 # Taylor3'UniFunction(\"Exp\")     <-- True;\n60 # Taylor3'CompCoeff(\"Exp\", _n) <-- 1/n!;\n\n80 # Taylor3'UniFunction(\"Ln\")     <-- False; // False because this rule is only applicable for Ln(x+1)\n80 # Taylor3'CompCoeff(\"Ln\", 0) <-- 0;\n81 # Taylor3'CompCoeff(\"Ln\", _n) <-- (-1)^(n+1)/n;\n\n90 # Taylor3'UniFunction(\"Sin\")           <-- True;\n90 # Taylor3'CompCoeff(\"Sin\", n_IsOdd)  <-- (-1)^((n-1)/2) / n!;\n90 # Taylor3'CompCoeff(\"Sin\", n_IsEven) <-- 0;\n\n100 # Taylor3'UniFunction(\"Cos\")           <-- True;\n100 # Taylor3'CompCoeff(\"Cos\", n_IsOdd)  <-- 0;\n100 # Taylor3'CompCoeff(\"Cos\", n_IsEven) <-- (-1)^(n/2) / n!;\n\n\n210 # Taylor3'UniFunction(_any)_\n      (\n        [\n          Local(result);\n          result:= Deriv(var)UnList({Atom(any),var});\n          Type(result) != \"Deriv\";\n        ]\n      )           <-- \n      [\n        True;\n      ];\n210 # Taylor3'CompCoeff(_any, n_IsInteger)  \n    <-- \n    [\n      Limit(var,0)(Deriv(var,n)(UnList({Atom(any),var}))/n!);\n    ];\n\n\n\n60000 # Taylor3'UniFunction(_any) <-- False;\n\n\nTaylor3'FuncCoefs(_fname,_degree) <--\n[\n  Local(sins,i);\n  Set(sins, Array'Create(degree+1,0));\n  For (i:=0,i<=degree,Set(i,i+1))\n  [\n    Array'Set(sins,i+1, Taylor3'CompCoeff(fname,i));\n  ];\n  sins;\n];\n\n\n100 # (Taylor3'TaylorCoefs(_var,_degree)(Ln(_f)))_(Simplify(f-1) = var) <-- Taylor3'FuncCoefs(\"Ln\",degree);\n\n\n110 # (Taylor3'TaylorCoefs(_var,_degree)(f_IsFunction))_(NrArgs(f) = 1 And (Taylor3'UniFunction(Type(f)))) <-- \n[\n  Local(sins,i,j,result,xx,expr,sinfact);\n  expr := f[1];\n  sins:=Taylor3'FuncCoefs(Type(f),degree);\n//Echo(\"sins = \",sins);\n  expr:=Taylor3'TaylorCoefs(var,degree)expr;\n  result:=Array'Create(degree+1,0);\n  Array'Set(result,1, Array'Get(sins,1));\n  xx:=expr;\n//Echo(\"8...\",sins,expr);\n  For (i:=2,i<=degree+1,i++)\n  [\n    Set(sinfact,sins[i]);\n//Echo(\"8.1..\",i,\" \",j);\n    For (j:=1,j<=degree+1,j++)\n    [\n      Array'Set(result,j,Array'Get(result,j) + (Array'Get(xx,j) * sinfact));\n    ];    \n//Echo(\"8.2..\");\n    Set(xx,Taylor3'MultiplyCoefs(xx,expr,degree));    \n//Echo(\"8.3..\");\n  ];\n  result;\n];\n\n\n(Taylor3(_var,_degree)(_expr)) <-- Add((Taylor3'TaylorCoefs(var,degree)(expr))[1 .. degree+1]*var^(0 .. degree));\n10 # (Taylor3(_x,  0, _n) _y) <--              Taylor3(x,n)              y;\n20 # (Taylor3(_x, _a, _n) _y) <-- Subst(x,x-a) Taylor3(x,n) Subst(x,x+a) y;\n\n\n"
  },
  {
    "path": "scripts/sums.rep/taylor3.ys.def",
    "content": "Taylor3\n}"
  },
  {
    "path": "scripts/tensor.rep/code.ys",
    "content": "\n/* Tensor package. This code intends to simplify tensorial expressions.\n */\n\nUnProtect(X);\n\n/* functions internal to tensors */\nRuleBase(\"Delta\",{ind1,ind2});\nRuleBase(\"TList\",{head,tail});\nRuleBase(\"TSum\",{indices,body});\nRuleBase(\"TD\",{ind});\nRuleBase(\"X\",{ind});\n\n/* And the simplificaiton rules for X, addition, subtraction\n   and multiplication */\n10 # (TD(_i)X(_j)) <-- Delta(i,j);\n10 # (TD(_i) ( (_f) + (_g) ) ) <-- (TD(i)f) + (TD(i)g);\n10 # (TD(_i) ( (_f) - (_g) ) ) <-- (TD(i)f) - (TD(i)g);\n10 # (TD(_i) (      - (_g) ) ) <--          -  TD(i)g;\n10 # (TD(_i) ( (_f) * (_g) ) ) <-- (TD(i)f)*g + f*(TD(i)g);\n10 # (TD(_i) ( (_f) ^ (n_IsPositiveInteger) ) ) <-- n*(TD(i)f)*f^(n-1);\n10 # (TD(_i)Delta(_j,_k)) <-- 0;\n10 # (TD(_i)f_IsNumber) <-- 0;\n\nProtect(X);\n\n/* The only TSum summation simplification: summing over no indices\n   means no summation. */\n10 # (TSum({})(_body)) <-- body;\n\n/* Explicit summation when Ndim is defined. This summation will\n   be invoked when using TExplicitSum. */\n20 # (TSum(_indices)(_body))_(IsInteger(Ndim)) <--\n    LocalSymbols(index,i,sum)\n    [\n      Local(index,i,sum);\n      index:=indices[1];\n      sum:=0;\n      MacroLocal(index);\n      For(i:=1,i<=Ndim,i++)\n      [\n        MacroSet(index,i);\n        sum:=sum+Eval(TSum(Tail(indices))body);\n      ];\n      sum;\n    ];\n\n/* TExplicitSum sets the dimension of the space under consideration,\n   so summation can proceed */\n(TExplicitSum(Ndim_IsInteger)(_body)) <-- Eval(body);\n\n/* Move the delta factors to the front, so they can be simplified\n   away. It uses ApplyDelta to move a factor either to the front\n   or to the back of the list. Input is a list of factors, as\n   returned by Flatten(expressions,\"*\")\n   */\nMoveDeltas(_list) <--\n[\n  Local(result,i,nr);\n  result:={};\n  nr:=Length(list);\n  For(i:=1,i<=nr,i++)\n  [\n    ApplyDelta(result,list[i]);\n  ];\n  result;\n];\n\n\n10  # ApplyDelta(_result,Delta(_i,_j)) <--\n    DestructiveInsert(result,1,Delta(i,j));\n20 # ApplyDelta(_result,(_x) ^ (n_IsInteger))_(n>0) <--\n    [\n      Local(i);\n      For(i:=1,i<=n,i++)\n      [\n        ApplyDelta(result,x);\n      ];\n    ];\n100 # ApplyDelta(_result,_term) <--\n    DestructiveAppend(result,term);\n\n\n/* TSimplify : expand brackets, and send the expression of addition\n   of terms to TSimplifyAux */\nTSimplify(TSum(_indices)(_f)) <--\n[\n  TSimplifyAux(TSum(indices)ExpandBrackets(f));\n];\n\n\n/* TSimplifyAux : simplify each term independently */\n10 # TSimplifyAux(TSum(_indices)((_f) + (_g))) <--\n     TSimplifyAux(TSum(FlatCopy(indices))(f)) +\n     TSimplifyAux(TSum(FlatCopy(indices))(g));\n10 # TSimplifyAux(TSum(_indices)((_f) - (_g))) <--\n     TSimplifyAux(TSum(FlatCopy(indices))(f)) -\n     TSimplifyAux(TSum(FlatCopy(indices))(g));\n10 # TSimplifyAux(TSum(_indices)(   - (_g))) <--\n                                    -  TSimplifyAux(TSum(indices)(g));\n\n40 # TSimplifyAux(TSum(_indices)_body) <--\n[\n  Local(flat);\n\n  /* Convert expressions of the form (a*b*c) to {a,b,c} */\n  flat:=Flatten(body,\"*\");\n\n  /* Move the deltas to the front. */\n  flat:=MoveDeltas(flat);\n\n  /* Simplify the deltas away (removing the required indices) */\n  flat:=TSumRest(flat);\n\n  /* Determine if there are indices the summand still depends on */\n  Local(varlist,independ,nrdims);\n  varlist:=VarList(flat);\n  independ:=Intersection(indices,varlist);\n  nrdims:=Length(indices)-Length(independ);\n\n  /* Return result, still summing over the indices not removed by deltas */\n  Ndim^nrdims*TSum(independ)flat;\n];\n\n\n/* Terminating condition for the tensorial simplification */\n\n10 # TSumSimplify(TList(Delta(_ind,_ind),_list))_Contains(indices,ind) <--\n\n[\n  /* Remove the index from the list of indices to sum over, since\n     it is now implicitly summed over by simplifying the delta */\n  DestructiveDelete(indices,Find(indices,ind));\n\n/* Return result simplified for this delta */\n  Ndim*TSumRest(list);\n];\n\n11 # TSumSimplify(TList(Delta(_ind1,_ind2),_list))_\n     Contains(indices,ind2) <--\n[\n  /* Remove the index from the list of indices to sum over, since\n     it is now implicitly summed over by simplifying the delta */\n  DestructiveDelete(indices,Find(indices,ind2));\n\n  /* Return result simplified for this delta */\n  TSumRest( Subst(ind2,ind1)list );\n];\n11 # TSumSimplify(TList(Delta(_ind1,_ind2),_list))_\n     Contains(indices,ind1) <--\n[\n  /* Remove the index from the list of indices to sum over, since\n     it is now implicitly summed over by simplifying the delta */\n  DestructiveDelete(indices,Find(indices,ind1));\n\n  /* Return result simplified for this delta */\n  TSumRest( Subst(ind1,ind2)list );\n];\n\n\n\n1010 # TSumSimplify(TList(_term,_list)) <--\n[\n  term*TSumRest(list);\n];\n\n\n10 # TSumRest({}) <-- 1;\n20 # TSumRest(_list) <--\n[\n   TSumSimplify(TList(Head(list),Tail(list)));\n];\n\n\n\nUnFence(\"TSumSimplify\",1);\nUnFence(\"TSumRest\",1);\nUnFence(\"TSum\",2);\n\n\n"
  },
  {
    "path": "scripts/tensor.rep/code.ys.def",
    "content": "TSimplify\nTExplicitSum\nTSum\nDelta\nTD\n}\n"
  },
  {
    "path": "scripts/testers.rep/code.ys",
    "content": "\n/* Functions that aid in testing */\n\n/* Round to specified number of digits */\n10 # RoundTo(x_IsNumber, prec_IsPositiveInteger) <-- \n[\n  Local(oldPrec,result);\n  oldPrec:=Builtin'Precision'Get();\n  Builtin'Precision'Set(prec);\n  Set(result,MathDivide( Round( MathMultiply(x, 10^prec) ), 10^prec ));\n  Builtin'Precision'Set(oldPrec);\n  result;\n];\n// complex numbers too\n10 # RoundTo(Complex(r_IsNumber, i_IsNumber), prec_IsPositiveInteger) <-- Complex(RoundTo(r, prec), RoundTo(i, prec));\n\n// Infinities, rounding does not apply.\n20 # RoundTo( Infinity,prec_IsPositiveInteger) <--  Infinity;\n20 # RoundTo(-Infinity,prec_IsPositiveInteger) <-- -Infinity;\n\nMacro(NumericEqual,{left,right,precision})\n[\n  Verify(RoundTo((@left)-(@right),@precision),0);\n];\n\n\n// print current file and line\nShowLine() := [Echo({CurrentFile(),\": \",CurrentLine()});];\n\n\n/* Logging functions */\n// curline:=0;\n\n/*\nFunction(\"StartTests\",{})\n[\n  curline:=0;\n];\n*/\n/*\nFunction(\"NextTest\",{aLeft})\n[\n// curline++;\nWriteString(\"\nTest suite for \":aLeft:\" : \"\n           );\n  NewLine();\n];\n*/\n/*\nFunction(\"Testing\",{aLeft})\n[\n WriteString(aLeft); NewLine();\n];\n*/\n\nFunction(\"KnownFailure\",{expr})\n[\n  Local(rfail);\n  //Echo({\"Known failure: \", expr});\n  Set(rfail,Eval(expr));\n  If(rfail, Echo({\"Known failure: \", expr, \"resolved!\"}));\n];\nHoldArg(\"KnownFailure\",expr);\n\n\n/*\nMacro(\"Verify\",{aLeft,aRight})\n[\n\n\tLocal(result);\n\tresult := @aLeft;\t// to save time\n  If (Not(Equals(result,@aRight)),\n    [\n      WriteString(\"******************\");\n      NewLine();\n      ShowLine();\n      NewLine();\n      Write(Hold(@aLeft));\n      NewLine();\n      WriteString(\" evaluates to \");\n      NewLine();\n\t  Write(result);\n\t  WriteString(\" which differs from \");\n      NewLine();\n      Write(Hold(@aRight));\n      NewLine();\n      WriteString(\"******************\");\n      NewLine();\n      False;\n    ],\n    True\n  );\n];\n*/\n\n\nFunction(\"Verify\",{aLeft,aRight})\n[\n\n\tLocal(result);\n\tresult := Eval(aLeft);\t// to save time\n  If (Not(Equals(result,aRight)),\n    [\n      WriteString(\"******************\");\n      NewLine();\n      ShowLine();\n      NewLine();\n      Write(aLeft);\n      NewLine();\n      WriteString(\" evaluates to \");\n      NewLine();\n\t  Write(result);\n      NewLine();\n\t  WriteString(\" which differs from \");\n      NewLine();\n      Write(aRight);\n      NewLine();\n      WriteString(\"******************\");\n      NewLine();\n      False;\n    ],\n    True\n  );\n];\nHoldArg(\"Verify\",aLeft);\nUnFence(\"Verify\",2);\n/*\nHoldArg(\"Verify\",aRight);\n*/\n\nMacro(\"Verify\", {a,b,message})\n[\n\tEcho(\"test \", @message);\n\tVerify(@a, @b);\n];\n\n\nFunction(\"LogicVerify\",{aLeft,aRight})\n[\n  If(aLeft != aRight,\n    Verify(CanProve(aLeft => aRight),True)\n  );\n];\n\n\n\n/* LogicTest compares the truth tables of two expressions. */\nLocalSymbols(TrueFalse)\n[\n  MacroRuleBase(TrueFalse,{var,expr});\n  10 # TrueFalse(var_IsAtom,_expr) <-- `{(@expr) Where (@var)==False,(@expr) Where (@var)==True};\n  20 # TrueFalse({},_expr) <-- `(@expr);\n  30 # TrueFalse(var_IsList,_expr) <-- \n  `[\n    Local(t,h);\n    Set(h,Head(@var));\n    Set(t,Tail(@var));\n    TrueFalse(h,TrueFalse(t,@expr));\n  ];\n\n  Macro(LogicTest,{vars,expr1,expr2}) Verify(TrueFalse((@vars),(@expr1)), TrueFalse((@vars),(@expr2)));\n];\n\n\nLocalSymbols(f1,f2)\n[\n  // f1 and f2 are used inside VerifyArithmetic\n  f1(x,n,m):=(x^n-1)*(x^m-1);\n  f2(x,n,m):=x^(n+m)-(x^n)-(x^m)+1;\n\n  VerifyArithmetic(x,n,m):=\n  [\n    Verify(f1(x,n,m),f2(x,n,m));\n  ];\n];\n\nRandVerifyArithmetic(_n)<--\n[\n While(n>0)\n [\n   n--;\n   VerifyArithmetic(MathFloor(300*Random()),MathFloor(80*Random()),MathFloor(90*Random()));\n ];\n];\n\nVerifyDiv(_u,_v) <--\n[\n  Local(q,r);\n  q:=Div(u,v);\n  r:=Rem(u,v);\n\n  Verify(Expand(u),Expand(q*v+r));\n];\n\n10 # EchoInternal(string_IsString) <--\n[\n  WriteString(string);\n];\n\n20 # EchoInternal(_item) <--\n[\n  Write(item);Space();\n];\n\nRuleBaseListed(\"Echo\",{args});\n10 # Echo(list_IsList)<--\n[\n  ForEach(item,list) EchoInternal(item);\n  NewLine();\n];\n20 # Echo(_item)<--\n[\n  EchoInternal(item);\n  NewLine();\n];\n\n\nFunction(\"BenchCall\",{expr}) \n[\n  Echo({\"In&gt \",expr});\n  WriteString(\"<font color=ff0000>\");\n  Eval(expr);\n  WriteString(\"</font>\");\n  True;\n];\nHoldArg(\"BenchCall\",expr);\n\nFunction(\"BenchShow\",{expr}) \n[\n  Echo({\"In&gt \",expr});\n  WriteString(\"<font color=ff0000> \");\n  Echo({\"Out&gt \",Eval(expr),\"</font>\"});\n  True;\n];\nHoldArg(\"BenchShow\",expr);\n\n\n\n\n/* Testing Yacas functionality by checking expressions against correct\n   answer.\n   Use with algebraic expressions only, since we need Simplify() for that to work.\n */\n\n\n\n/*\nMacro (\"TestYacas\", {expr, ans})\n[\n\tLocal(diff,exprEval, ansEval);\n  exprEval:= @expr;\n  ansEval:= @ans;\n  \n\tdiff := Simplify(exprEval - ansEval);\n\t\tIf (Simplify(diff)=0, True,\n\t\t\t[\n\t\t\t  WriteString(\"******************\");\n\t\t\t  NewLine();\n\t\t\t  ShowLine();\n\t\t\t  Write(Hold(@expr));\n\t\t\t  WriteString(\" evaluates to \");\n\t\t\t  NewLine();\n\t\t\t  Write(exprEval);\n\t\t\t  NewLine();\n\t\t\t  WriteString(\" which differs from \");\n\t\t\t  NewLine();\n\t\t\t  Write(ansEval);\n\t\t\t  NewLine();\n\t\t\t  WriteString(\" by \");\n\t\t\t  NewLine();\n\t\t\t  Write(diff);\n\t\t\t  NewLine();\n\t\t\t  WriteString(\"******************\");\n\t\t\t  NewLine();\n\t\t\t  False;\n\t\t\t ]\n\t\t\t);\n];\n*/\n\n\n\n\n\n\n\nFunction (\"TestYacas\", {expr, ans})\n[\n\tLocal(diff);\n\tdiff := Simplify(Eval(expr)-Eval(ans));\n\t\tIf (Simplify(diff)=0, True,\n\t\t\t[\n\t\t\t  WriteString(\"******************\");\n\t\t\t  NewLine();\n\t\t\t  ShowLine();\n\t\t\t  Write(expr);\n\t\t\t  WriteString(\" evaluates to \");\n\t\t\t  NewLine();\n\t\t\t  Write(Eval(expr));\n\t\t\t  NewLine();\n\t\t\t  WriteString(\" which differs from \");\n\t\t\t  NewLine();\n\t\t\t  Write(Eval(ans));\n\t\t\t  NewLine();\n\t\t\t  WriteString(\" by \");\n\t\t\t  NewLine();\n\t\t\t  Write(diff);\n\t\t\t  NewLine();\n\t\t\t  WriteString(\"******************\");\n\t\t\t  NewLine();\n\t\t\t  False;\n\t\t\t ]\n\t\t\t);\n];\n\nHoldArg(\"TestYacas\", expr);\nHoldArg(\"TestYacas\", ans);\n\n\n\n\n\n\n\n"
  },
  {
    "path": "scripts/testers.rep/code.ys.def",
    "content": "Verify\nKnownFailure\nEcho\nVerifyArithmetic\nRandVerifyArithmetic\nVerifyDiv\nTestYacas\nRoundTo\nNumericEqual\nLogicVerify\nLogicTest\n}\n"
  },
  {
    "path": "scripts/texform.rep/code.ys",
    "content": "/* TeXForm: convert Yacas objects to TeX math mode strings */\n\n/* version 0.4 */\n\n/* Changelog\n\t0.1\tbasic functionality\n\t0.2 fixed bracketing of Exp, added all infix ops and math functions\n\t0.3 fixed bracketing of lists, changed bracketing of math functions, modified TeX representation of user-defined functions (up to two-letter functions are in italics), added TeX Greek letters\n\t0.4 added nth roots, Sum, Limit, Integrate, hyperbolics, set operations, Abs, Max, Min, \"==\", \":=\", Infinity; support indexed expressions A[i] and matrices.\n\t0.4.1 bugfixes for [] operator, support for multiple indices a[1][2][3]\n\t0.4.2 fix for variable names ending on digits \"a2\" represented as $a_2$\n\t0.4.3 bugfixes: complex I, indeterminate integration; relaxed bracketing of Sin()-like functions; implemented $TeX$ and $LaTeX$ correctly now (using \\textrm{})\n\t0.4.4 use ordinary instead of partial derivative if expression has only one variable\n\t0.4.5 fixes for bracketing of Sum(); added <> to render as \\sim and <=> to render as \\approx; added Bin()\n\t0.4.6 moved the <> and <=> operators to stdopers.ys\n\t0.4.7 added Factorize() i.e. Product()\n\t0.4.8 added D(x,n), Deriv(x,n), =>, and fixed errors with ArcSinh, ArcCosh, ArcTanh\n\t0.4.9 fixed omission: (fraction)^n was not put in brackets\n\t0.4.10 cosmetic change: insert \\cdot between numbers in cases like 2*10^n\n\t0.4.11 added DumpErrors() to TexForm for the benefit of TeXmacs notebooks\n\t0.4.12 implement the % operation as Mod\n\t0.4.13 added Bessel{I,J,K,Y}, Ortho{H,P,T,U}, with a general framework for usual two-argument functions of the form $A_n(x)$; fix for Max, Min\n\t0.4.14 added mathematical notation for Floor(), Ceil()\n\t0.4.15 added Prog() represented by ( )\n\t0.4.16 added Zeta()\n*/\n\n/* To do:\n\t0. Find and fix bugs.\n\t1. The current bracketing approach has limitations: can't omit extra brackets sometimes. \" sin a b\" is ambiguous, so need to do either \"sin a sin b\" or \"(sin a) b\" Hold((a*b)*Sqrt(x)). The current approach is *not* to bracket functions unless the enveloping operation is more binding than multiplication. This produces \"sin a b\" for both Sin(a*b) and Sin(a)*b but this is the current mathematical practice.\n\t2. Need to figure out how to deal with variable names such as \"alpha3\"\n*/\n\n/// TeXmacs prettyprinter\nTexForm(_expr) <-- [DumpErrors();WriteString(TeXForm(expr));NewLine();];\n\nRuleBase(\"TeXForm\",{expression});\nRuleBase(\"TeXForm\",{expression, precedence});\n\n/* Boolean predicate */\n\n\n/* this function will put TeX brackets around the string if predicate holds */\n\nFunction (\"TeXFormBracketIf\", {predicate, string})\n[\n\tCheck(IsBoolean(predicate) And IsString(string), \"TeXForm internal error: non-boolean and/or non-string argument of TeXFormBracketIf\");\n\tIf(predicate, ConcatStrings(\"\\\\left( \", string, \"\\\\right) \"), string);\n];\n\n/* First, we convert TeXForm(x) to TeXForm(x, precedence). The enveloping precedence will determine whether we need to bracket the results. So TeXForm(x, TeXFormMaxPrec()) will always print \"x\", while TeXForm(x,-TeXFormMaxPrec()) will always print \"(x)\".\n*/\n\nTeXFormMaxPrec() := 60000;\t /* This precedence will never be bracketed. It is equal to KMaxPrec */\n\nIf (Not IsNumber(TeXForm'FuncPrec), TeXForm'FuncPrec := OpPrecedence(\"*\"));\n\n/// main front-end\n100 # TeXForm(_x) <-- ConcatStrings(\"$\", TeXForm(x, TeXFormMaxPrec()), \"$\");\n\n/* Replace numbers and variables -- never bracketed except explicitly */\n\n110 # TeXForm(x_IsNumber, _p) <-- String(x);\n/* Variables */\n200 # TeXForm(x_IsAtom, _p) <-- TeXFormTeXify(String(x));\n\n/* Strings must be quoted but not bracketed */\n100 # TeXForm(x_IsString, _p) <-- ConcatStrings(\"\\\\mathrm{\", x, \"}\");\n\n/* Listify(...) can generate lists with atoms that would otherwise result in unparsable expressions. */\n100 # TeXForm(x_IsAtom, _p)_(IsInfix(String(x))) <-- ConcatStrings(\"\\\\mathrm{\", String(x), \"}\");\n\n\n/* Lists: make sure to have matrices processed before them. Enveloping precedence is irrelevant because lists are always bracketed. List items are never bracketed. Note that TeXFormFinishList({a,b}) generates \",a,b\" */\n\n100 # TeXForm(x_IsList, _p)_(Length(x)=0) <-- TeXFormBracketIf(True, \"\");\n110 # TeXForm(x_IsList, _p) <-- TeXFormBracketIf(True, ConcatStrings(TeXForm(Head(x), TeXFormMaxPrec()), TeXFormFinishList(Tail(x)) ) );\n100 # TeXFormFinishList(x_IsList)_(Length(x)=0) <-- \"\";\n110 # TeXFormFinishList(x_IsList) <-- ConcatStrings(\", \", TeXForm(Head(x), TeXFormMaxPrec()), TeXFormFinishList(Tail(x)));\n\n/* Replace operations */\n\n\n\t/* Template for \"regular\" binary infix operators:\n100 # TeXForm(_x + _y, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"+\"), ConcatStrings(TeXForm(x, OpLeftPrecedence(\"+\")), \" + \", TeXForm(y, OpRightPrecedence(\"+\")) ) );\n\t*/\n// special cases: things like x*2 and 2*10^x look ugly without a period\n// cases like x*2\n115 # TeXForm(_expr * n_IsNumber, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"*\"), ConcatStrings(TeXForm(expr, OpLeftPrecedence(\"*\")), \"\\\\cdot \", TeXForm(n, OpRightPrecedence(\"*\")) ) );\n// cases like a*20! and a*10^x\n116 # TeXForm(_n * _expr, _p) _ (IsFunction(expr) And Contains({\"^\", \"!\", \"!!\"}, Type(expr)) And IsNumber(Listify(expr)[2])) <-- TeXFormBracketIf(p<OpPrecedence(\"*\"), ConcatStrings(TeXForm(n, OpLeftPrecedence(\"*\")), \"\\\\cdot \", TeXForm(expr, OpRightPrecedence(\"*\")) ) );\n\n\t/* generic binary ops here */\n120 # TeXForm(expr_IsFunction, _p)_(NrArgs(expr)=2 And IsInfix(Type(expr)) ) <-- TeXFormBracketIf(p<OpPrecedence(Type(expr)), ConcatStrings(TeXForm(Listify(expr)[2], OpLeftPrecedence(Type(expr))), TeXFormTeXify(Type(expr)), TeXForm(Listify(expr)[3], OpRightPrecedence(Type(expr))) ) );\n\n\t/* Template for \"regular\" unary prefix operators:\n100 # TeXForm(+ _y, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"+\"), ConcatStrings(\" + \", TeXForm(y, OpRightPrecedence(\"+\")) ) );\n\tNote that OpRightPrecedence needs to be defined for prefix ops or else we won't be able to tell combined prefix/infix ops like \"-\" from strictly prefix ops.\n\t*/\n\n\t/* generic unary ops here */\n\t/* prefix */\n120 # TeXForm(expr_IsFunction, _p)_(NrArgs(expr)=1 And IsPrefix(Type(expr))) <-- TeXFormBracketIf(p<OpPrecedence(Type(expr)), ConcatStrings(\n\tTeXFormTeXify(Type(expr)),\n\tTeXForm(Listify(expr)[2], OpRightPrecedence(Type(expr)))\n) );\n\t/* postfix */\n120 # TeXForm(expr_IsFunction, _p)_(NrArgs(expr)=1 And IsPostfix(Type(expr))) <-- TeXFormBracketIf(p<OpLeftPrecedence(Type(expr)), ConcatStrings(\n\tTeXForm(Listify(expr)[2], OpLeftPrecedence(Type(expr))),\n\tTeXFormTeXify(Type(expr))\n) );\n\n\t/* fraction and its operands are never bracketed except when they are under power */\n100 # TeXForm(_x / _y, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(\"\\\\frac{\", TeXForm(x, TeXFormMaxPrec()), \"}{\", TeXForm(y, TeXFormMaxPrec()), \"} \") );\n\n\t/* power's argument is never bracketed but it must be put in braces. Chained powers must be bracketed. Powers of 1/n are displayed as roots. */\n100 # TeXForm(_x ^ (1/2), _p) <-- ConcatStrings(\"\\\\sqrt{\", TeXForm(x, TeXFormMaxPrec()), \"}\");\n101 # TeXForm(_x ^ (1/_y), _p) <-- ConcatStrings(\"\\\\sqrt[\", TeXForm(y, TeXFormMaxPrec()), \"]{\", TeXForm(x, TeXFormMaxPrec()), \"}\");\n\n\n120 # TeXForm(_x ^ _y, _p) <-- TeXFormBracketIf(p<=OpPrecedence(\"^\"), ConcatStrings(TeXForm(x, OpPrecedence(\"^\")), \" ^{\", TeXForm(y, TeXFormMaxPrec()), \"}\" ) );\n\n/* functions */\n\n\nLocalSymbols(TeXFormRegularOps, TeXFormRegularPrefixOps, TeXFormGreekLetters, TeXFormSpecialNames) [\n\n\t/* addition, subtraction, multiplication, all comparison and logical operations are \"regular\" */\n\n  TeXFormRegularOps :=\n  {\n    {\"+\",\" + \"},\n    {\"-\",\" - \"},\n    {\"*\",\" \"},\n    {\":=\",\"\\\\equiv \"},\n    {\"==\",\" = \"},\n    {\"=\",\" = \"},\n    {\"!=\",\"\\\\neq \"},\n    {\"<=\",\"\\\\leq \"},\n    {\">=\",\"\\\\geq \"},\n    {\"<\",\" < \"},\n    {\">\",\" > \"},\n    {\"And\",\"\\\\wedge \"},\n    {\"Or\", \"\\\\vee \"},\n    {\"<>\", \"\\\\sim \"},\n    {\"<=>\", \"\\\\approx \"},\n    {\"=>\", \"\\\\Rightarrow \"},\n    {\"%\", \"\\\\bmod \"},\n  };\n\n  TeXFormRegularPrefixOps := { {\"+\",\" + \"}, {\"-\",\" - \"}, {\"Not\",\" \\\\neg \"} };\n\n\n\n    /* Unknown function: precedence 200. Leave as is, never bracket the function itself and bracket the argument(s) automatically since it's a list. Other functions are precedence 100 */\n\n  TeXFormGreekLetters := {\"Gamma\", \"Delta\", \"Theta\", \"Lambda\", \"Xi\", \"Pi\", \"Sigma\", \"Upsilon\", \"Phi\", \"Psi\", \"Omega\", \"alpha\", \"beta\", \"gamma\", \"delta\", \"epsilon\", \"zeta\", \"eta\", \"theta\", \"iota\", \"kappa\", \"lambda\", \"mu\", \"nu\", \"xi\", \"pi\", \"rho\", \"sigma\", \"tau\", \"upsilon\", \"phi\", \"chi\", \"psi\", \"omega\", \"varpi\", \"varrho\", \"varsigma\", \"varphi\", \"varepsilon\"};\n  TeXFormSpecialNames := {\n    {\"I\", \"\\\\imath \"},\t// this prevents a real uppercase I, use BesselI instead\n    {\"Pi\", \"\\\\pi \"},\t// this makes it impossible to have an uppercase Pi... hopefully it's not needed\n    {\"Infinity\", \"\\\\infty \"},\n    {\"TeX\", \"\\\\textrm{\\\\TeX\\\\/}\"},\n    {\"LaTeX\", \"\\\\textrm{\\\\LaTeX\\\\/}\"},\n    {\"Max\", \"\\\\max \"},\t// this replaces these function names\n    {\"Min\", \"\\\\min \"},\n    {\"Prog\", \" \"},\n    {\"Zeta\", \"\\\\zeta \"},\n  };\n\n\n  /* this function will take a user-defined variable or function name and output either this name unmodified if it's only 2 characters long, or the name in normal text if it's longer, or a TeX Greek letter code */\n  Function (\"TeXFormTeXify\", {string})\n  [\n    Check(IsString(string), \"TeXForm internal error: non-string argument of TeXFormTeXify\");\n    /* Check if it's a greek letter or a special name */\n    If (Contains(AssocIndices(TeXFormSpecialNames), string), TeXFormSpecialNames[string],\n    If (Contains(TeXFormGreekLetters, string), ConcatStrings(\"\\\\\", string, \" \"),\n    If (Contains(AssocIndices(TeXFormRegularOps), string), TeXFormRegularOps[string],\n    If (Contains(AssocIndices(TeXFormRegularPrefixOps), string), TeXFormRegularPrefixOps[string],\n    If (Length(string) >= 2 And IsNumber(Atom(StringMid'Get(2, Length(string)-1, string))), ConcatStrings(StringMid'Get(1,1,string), \"_{\", StringMid'Get(2, Length(string)-1, string), \"}\"),\n    If (Length(string) > 2, ConcatStrings(\"\\\\mathrm{ \", string, \" }\"),\n    string\n    ))))));\n  ];\n\n];\n\n/* */\n\n/* Unknown bodied function */\n\n200 # TeXForm(x_IsFunction, _p) _ (IsBodied(Type(x))) <-- [\n\tLocal(func, args, last'arg);\n\tfunc := Type(x);\n\targs := Tail(Listify(x));\n\tlast'arg := PopBack(args);\n\tTeXFormBracketIf(p<OpPrecedence(func), ConcatStrings(\n\t  TeXFormTeXify(func), TeXForm(args, TeXFormMaxPrec()),  TeXForm(last'arg, OpPrecedence(func))\n\t));\n];\n\n/* Unknown infix function : already done above\n210 # TeXForm(x_IsFunction, _p)_(IsInfix(Type(x))) <-- ConcatStrings(TeXFormTeXify(Type(x)), TeXForm(Tail(Listify(x)), TeXFormMaxPrec()) );\n*/\n/* Unknown function that is not prefix, infix or postfix */\n220 # TeXForm(x_IsFunction, _p) <-- ConcatStrings(TeXFormTeXify(Type(x)), TeXForm(Tail(Listify(x)), TeXFormMaxPrec()) );\n\n\t/* Never bracket Sqrt or its arguments */\n100 # TeXForm(Sqrt(_x), _p) <-- ConcatStrings(\"\\\\sqrt{\", TeXForm(x, TeXFormMaxPrec()), \"}\");\n\n\t/* Always bracket Exp's arguments */\n100 # TeXForm(Exp(_x), _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(\"\\\\exp \", TeXFormBracketIf(True, TeXForm(x, TeXFormMaxPrec())) ) );\n\n\nLocalSymbols(TeXFormMathFunctions, TeXFormMathFunctions2) [\n\n  /* Sin, Cos, etc. and their argument is bracketed when it's a sum or product but not bracketed when it's a power. */\n  /// supported Yacas functions: \"mathematical\" functions of one argument which sometimes do not require parentheses (e.g. $\\sin x$ )\n  TeXFormMathFunctions := { {\"Cos\",\"\\\\cos \"}, {\"Sin\",\"\\\\sin \"}, {\"Tan\",\"\\\\tan \"}, {\"Cosh\",\"\\\\cosh \"}, {\"Sinh\",\"\\\\sinh \"}, {\"Tanh\",\"\\\\tanh \"}, {\"Ln\",\"\\\\ln \"}, {\"ArcCos\",\"\\\\arccos \"}, {\"ArcSin\",\"\\\\arcsin \"}, {\"ArcTan\",\"\\\\arctan \"}, {\"ArcCosh\",\"\\\\mathrm{arccosh}\\\\, \"}, {\"ArcSinh\",\"\\\\mathrm{arcsinh}\\\\, \"}, {\"ArcTanh\",\"\\\\mathrm{arctanh}\\\\, \"},\n  {\"Erf\", \"\\\\mathrm{erf}\\\\, \"}, {\"Erfc\", \"\\\\mathrm{erfc}\\\\, \"},\n  };\n\n  /// supported Yacas functions: functions of two arguments of the form $A_n(x)$\n  TeXFormMathFunctions2 := {\n  {\"BesselI\", \"I \"}, {\"BesselJ\", \"J \"},\n  {\"BesselK\", \"K \"}, {\"BesselY\", \"Y \"},\n  {\"OrthoH\", \"H \"}, {\"OrthoP\", \"P \"},\n  {\"OrthoT\", \"T \"}, {\"OrthoU\", \"U \"},\n  };\n\n  // generic two-argument functions of the form $A(x,y)$ where just the name has to be changed: handle this using the usual naming conversion scheme (TeXFormSpecialNames)\n\n  /* Precedence of 120 because we'd like to process other functions like sqrt or exp first */\n\n  // generic math functions of one argument\n  120 # TeXForm(expr_IsFunction, _p) _ (NrArgs(expr)=1 And Contains(AssocIndices(TeXFormMathFunctions), Type(expr)) ) <-- TeXFormBracketIf(p<OpPrecedence(\"*\"), ConcatStrings(TeXFormMathFunctions[Type(expr)], TeXForm( Listify(expr)[2], TeXForm'FuncPrec) ) );\n\n  /// math functions two arguments of the form $A_n(x)$\n  120 # TeXForm(expr_IsFunction, _p) _ (NrArgs(expr)=2 And Contains(AssocIndices(TeXFormMathFunctions2), Type(expr)) ) <-- TeXFormBracketIf(p<OpPrecedence(\"*\"),\n    ConcatStrings(\n    TeXFormMathFunctions2[Type(expr)],\n    \"_{\",\n    TeXForm( Listify(expr)[2], TeXFormMaxPrec()),\t// never bracket the subscript\n    \"}\",\n    TeXFormBracketIf(True, TeXForm(Listify(expr)[3], TeXFormMaxPrec()) ) // always bracket the function argument\n    )\n  );\n\n]; // LocalSymbols(TeXFormMathFunctions, TeXFormMathFunctions2)\n\n\n/* Complex numbers */\n100 # TeXForm(Complex(0, 1), _p) <-- TeXForm(Hold(I), p);\n100 # TeXForm(Complex(_x, 0), _p) <-- TeXForm(x, p);\n110 # TeXForm(Complex(_x, 1), _p) <-- TeXForm(x+Hold(I), p);\n110 # TeXForm(Complex(0, _y), _p) <-- TeXForm(Hold(I)*y, p);\n120 # TeXForm(Complex(_x, _y), _p) <-- TeXForm(x+Hold(I)*y, p);\n\n/* Abs(), Floor(), Ceil() are displayed as special brackets */\n\n100 # TeXForm(Abs(_x), _p) <-- ConcatStrings(\"\\\\left| \", TeXForm(x, TeXFormMaxPrec()), \"\\\\right| \");\n100 # TeXForm(Floor(_x), _p) <-- ConcatStrings(\"\\\\left\\\\lfloor \", TeXForm(x, TeXFormMaxPrec()), \"\\\\right\\\\rfloor \");\n100 # TeXForm(Ceil(_x), _p) <-- ConcatStrings(\"\\\\left\\\\lceil \", TeXForm(x, TeXFormMaxPrec()), \"\\\\right\\\\rceil \");\n\n/* Some functions which are displayed as infix: Mod, Union, Intersection, Difference, Contains */\n\n100 # TeXForm(Mod(_x, _y), _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(TeXForm(x, OpPrecedence(\"/\")), \"\\\\bmod \", TeXForm(y, OpPrecedence(\"/\")) ) );\n\n100 # TeXForm(Union(_x, _y), _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(TeXForm(x, OpPrecedence(\"/\")), \"\\\\cup \", TeXForm(y, OpPrecedence(\"/\")) ) );\n\n100 # TeXForm(Intersection(_x, _y), _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(TeXForm(x, OpPrecedence(\"/\")), \"\\\\cap \", TeXForm(y, OpPrecedence(\"/\")) ) );\n\n100 # TeXForm(Difference(_x, _y), _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(TeXForm(x, OpPrecedence(\"/\")), \"\\\\setminus \", TeXForm(y, OpPrecedence(\"/\")) ) );\n\n/* \"Contains\" is displayed right to left */\n\n100 # TeXForm(Contains(_x, _y), _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(TeXForm(y, OpPrecedence(\"/\")), \"\\\\in \", TeXForm(x, OpPrecedence(\"/\")) ) );\n\n/// Binomial coefficients: always bracketed\n100 # TeXForm(Bin(_n, _m), _p) <-- TeXFormBracketIf(False, ConcatStrings(\"{\", TeXForm(n, TeXFormMaxPrec()), \" \\\\choose \", TeXForm(m, TeXFormMaxPrec()), \"}\" )\n);\n\n/* Some functions with limits: Lim, Sum, Integrate */\n\n100 # TeXForm(Sum(_x, _x1, _x2, _expr), _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(\"\\\\sum _{\", TeXForm(x, TeXFormMaxPrec()), \" = \", TeXForm(x1, TeXFormMaxPrec()), \"} ^{\", TeXForm(x2, TeXFormMaxPrec()), \"} \", TeXForm(expr, OpPrecedence(\"*\")) ) );\n\n100 # TeXForm(Product(_x, _x1, _x2, _expr), _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(\"\\\\prod _{\", TeXForm(x, TeXFormMaxPrec()), \" = \", TeXForm(x1, TeXFormMaxPrec()), \"} ^{\", TeXForm(x2, TeXFormMaxPrec()), \"} \", TeXForm(expr, OpPrecedence(\"*\")) ) );\n\n100 # TeXForm(Integrate(_x, _x1, _x2) _expr, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(\n\"\\\\int _{\", TeXForm(x1, TeXFormMaxPrec()), \"} ^{\", TeXForm(x2, TeXFormMaxPrec()), \" } \", TeXForm(expr, OpPrecedence(\"*\")), \" d\", TeXForm(x, TeXFormMaxPrec())\n) );\n\n/* indeterminate integration */\n100 # TeXForm(Integrate(_x) _expr, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(\n\"\\\\int \", TeXForm(expr, OpPrecedence(\"*\")), \" d\", TeXForm(x, TeXFormMaxPrec())\n) );\n\n100 # TeXForm(Limit(_x, _x1) _expr, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"/\"), ConcatStrings(\"\\\\lim _{\", TeXForm(x, TeXFormMaxPrec()), \"\\\\rightarrow \", TeXForm(x1, TeXFormMaxPrec()), \"} \", TeXForm(expr, OpPrecedence(\"/\")) ) );\n\n/* Derivatives */\n\n/* Use partial derivative only when the expression has several variables */\n100 # TeXForm(Deriv(_x)_y, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"-\"), ConcatStrings(\n\tIf(Length(VarList(y))>1, \"\\\\frac{\\\\partial}{\\\\partial \", \"\\\\frac{d}{d \"\n\t), TeXForm(x, OpPrecedence(\"^\")), \"}\", TeXForm(y, OpPrecedence(\"/\")) ) );\n\n100 # TeXForm(Deriv(_x, _n)_y, _p) <-- TeXFormBracketIf(p<OpPrecedence(\"-\"), ConcatStrings(\n\tIf(\n\t\tLength(VarList(y))>1,\n\t\t\"\\\\frac{\\\\partial^\" : TeXForm(n, TeXFormMaxPrec()) : \"}{\\\\partial \",\n\t\t\"\\\\frac{d^\" : TeXForm(n, TeXFormMaxPrec()) : \"}{d \"\n\t), TeXForm(x, OpPrecedence(\"^\")), \" ^\", TeXForm(n, TeXFormMaxPrec()), \"}\", TeXForm(y, OpPrecedence(\"/\")) ) );\n100 # TeXForm(D(_x)_y, _p) <-- TeXForm(Deriv(x) y, p);\n100 # TeXForm(D(_x, _n)_y, _p) <-- TeXForm(Deriv(x, n) y, p);\n\n/* Indexed expressions */\n\n/* This seems not to work because x[i] is replaced by Nth(x,i) */\n/*\n100 # TeXForm(_x [ _i ], _p) <-- ConcatStrings(TeXForm(x, TeXFormMaxPrec()), \" _{\", TeXForm(i, TeXFormMaxPrec()), \"}\");\n*/\n/* Need to introduce auxiliary function, or else have trouble with arguments of Nth being lists */\n100 # TeXForm(Nth(Nth(_x, i_IsList), _j), _p) <-- TeXForm(TeXFormNth(x, Append(i,j)), p);\n100 # TeXForm(TeXFormNth(Nth(_x, i_IsList), _j), _p) <-- TeXForm(TeXFormNth(x, Append(i,j)), p);\n110 # TeXForm(Nth(Nth(_x, _i), _j), _p) <-- TeXForm(TeXFormNth(x, List(i,j)), p);\n120 # TeXForm(Nth(_x, _i), _p) <-- ConcatStrings(TeXForm(x, TeXFormMaxPrec()), \" _{\", TeXForm(i, TeXFormMaxPrec()), \"}\");\n120 # TeXForm(TeXFormNth(_x, _i), _p) <-- ConcatStrings(TeXForm(x, TeXFormMaxPrec()), \" _{\", TeXForm(i, TeXFormMaxPrec()), \"}\");\n\n/* Matrices are always bracketed. Precedence 80 because lists are at 100. */\n\n80 # TeXForm(M_IsMatrix, _p) <-- TeXFormBracketIf(True, TeXFormPrintMatrix(M));\n\nFunction (\"TeXFormPrintMatrix\", {M})\n[\n/*\n\tWant something like \"\\begin{array}{cc} a & b \\\\ c & d \\\\ e & f \\end{array}\"\n\there, \"cc\" is alignment and must be given for each column\n*/\n\tLocal(row, col, result, ncol);\n\tresult := \"\\\\begin{array}{\";\n\tForEach(col, M[1]) result:=ConcatStrings(result, \"c\");\n\tresult := ConcatStrings(result, \"}\");\n\n\tForEach(row, 1 .. Length(M)) [\n\t\tForEach(col, 1 .. Length(M[row])) [\n\t\t\tresult := ConcatStrings( result, \" \", TeXForm(M[row][col], TeXFormMaxPrec()), If(col = Length(M[row]), If(row = Length(M), \"\", \" \\\\\\\\\"), \" &\"));\n\t\t];\n\t];\n\n\tConcatStrings(result, \" \\\\end{array} \");\n];\n\n"
  },
  {
    "path": "scripts/texform.rep/code.ys.def",
    "content": "TexForm\nTeXForm\nTeXFormMaxPrec\n}\n\n"
  },
  {
    "path": "scripts/transforms.rep/code.ys",
    "content": "10 # LaplaceTransform(_var1,_var2, _expr )\t<-- LapTran(var1,var2,expr);\n\n// Linearity properties\n10 # LapTran(_var1,_var2,_x + _y)      \t\t<-- LapTran(var1,var2,x) + LapTran(var1,var2,y);\n10 # LapTran(_var1,_var2,_x - _y)\t\t<-- LapTran(var1,var2,x) - LapTran(var1,var2,y);\n10 # LapTran(_var1,_var2,    - _y)       \t<-- - LapTran(var1,var2,y);\n10 # LapTran(_var1,_var2, c_IsConstant*_y)\t<-- c*LapTran(var1,var2,y);\n10 # LapTran(_var1,_var2, _y*c_IsConstant)\t<-- c*LapTran(var1,var2,y);\n10 # LapTran(_var1,_var2, _y/c_IsConstant) \t<-- LapTran(var1,var2,y)/c;\n\n// Shift properties\n10 # LapTran(_var1,_var2, Exp(c_IsConstant*_var1)*_expr  ) <-- LapTran(var1,var2-c,expr);\n10 # LapTran(_var1,_var2, Exp(-c_IsConstant*_var1)*_expr ) <-- LapTran(var1,var2+c,expr);\n10 # LapTran(_var1,_var2, _expr*Exp(c_IsConstant*_var1)  ) <-- LapTran(var1,var2-c,expr);\n10 # LapTran(_var1,_var2, _expr*Exp(-c_IsConstant*_var1) ) <-- LapTran(var1,var2+c,expr);\n\n// Other operational properties\n10 # LapTran(_var1,_var2, _expr/_var1 )\t\t<-- Integrate(var2,var2,Infinity) LapTran(var1,var2,expr) ;\n10 # LapTran(_var1,_var2, _var1*_expr )\t\t<-- - Deriv(var2) LapTran(var1,var2,expr);\n10 # LapTran(_var1,_var2, _var1^(n_IsInteger)*_expr )  <-- (-1)^n * Deriv(var2,n) LapTran(var1,var2,expr);\n10 # LapTran(_var1,_var2, _expr*_var1 )                <-- - Deriv(var2) LapTran(var1,var2,expr);\n10 # LapTran(_var1,_var2, _expr*_var1^(n_IsInteger)  ) <-- (-1)^n * Deriv(var2,n) LapTran(var1,var2,expr);\n\n// didn't match, return unevaled\n100 # LapTran(_var1,_var2, _expr )\t<-- `Hold(LaplaceTransform(@var1,@var2,@expr));\n\nLapTranDef(_in,_out) <--\n[\n  Local(i,o);\n\n  //Echo(\"50 # LapTran(_t,_s,\",in,\") <-- \",out,\";\");\n  `(50 # LapTran(_t,_s,@in) <-- @out );\n\n  i:=Subst(_t,c_IsPositiveInteger*_t) in;\n  o:=Subst(s,s/c) out;\n\n  //Echo(\"50 # LapTran(_t,_s,\",i,\") <-- \",o/c,\";\");\n  `(50 # LapTran(_t,_s,@i ) <-- @o/c );\n\n  i:=Subst(_t,_t/c_IsPositiveInteger) in;\n  o:=Subst(s,s*c) out;\n\n  //Echo(\"50 # LapTran(_t,_s,\",i,\") <-- \",o/c,\";\");\n  `(50 # LapTran(_t,_s,@i ) <-- @o*c );\n\n];\n\n// transforms of specific functions\nLapTranDef( (_t)^(n_IsConstant),\tGamma(n+1)/s^(n+1) );\nLapTranDef( _t, \t\t\t1/s^2 );\nLapTranDef( Sqrt(_t), \t\t\tSqrt(Pi)/(2*s^(3/2)) );\nLapTranDef( c_IsFreeOf({t,s}),\t\tc/s );\nLapTranDef( Sin(_t),\t \t\t1/(s^2+1) );\nLapTranDef( Cos(_t), \t\t\ts/(s^2+1) );\nLapTranDef( Sinh(_t),\t\t\tc/(s^2-1) );\nLapTranDef( Cosh(_t),\t\t\ts/(s^2-1) );\nLapTranDef( Exp(_t),\t\t\t1/(s-1) );\nLapTranDef( BesselJ(n_IsConstant,_t),\t(Sqrt(s^2+1)-s)^n /Sqrt(s^2+1) );\nLapTranDef( BesselI(n_IsConstant,_t),\t(s-Sqrt(s^2+1))^n /Sqrt(s^2-1) );\nLapTranDef( Ln(_t),\t\t\t-(gamma+Ln(s))/s);\nLapTranDef( Ln(_t)^2,\t\t\tPi^2/(6*s)+(gamma+Ln(s))/s );\nLapTranDef( Erf(_t),\t\t\tExp(s^2/4)*Erfc(s/2)/s );\nLapTranDef( Erf(Sqrt(_t)),\t\t1/(Sqrt(s+1)*s) );\n"
  },
  {
    "path": "scripts/transforms.rep/code.ys.def",
    "content": "LaplaceTransform\n}\n"
  },
  {
    "path": "scripts/trigsimp.rep/code.ys",
    "content": "\n/* This file defines TrigSimpCombine. TrigSimpCombine is designed to\n   simplify expressions like Cos(a)*Sin(b) to additions\n   only (in effect, removing multiplications between\n   trigonometric functions).\n\n   The accepted expressions allow additions and multiplications\n   between trig. functions, and raising trig. functions to an\n   integer power.\n\n   You can invoke it by calling TrigSimpCombine(f). Examples:\n\tTrigSimpCombine(Cos(a)*Sin(a^2+b)^2)\n\tTrigSimpCombine(Cos(a)*Sin(a)^2)\n\tTrigSimpCombine(Cos(a)^3*Sin(a)^2)\n\tTrigSimpCombine(d*Cos(a)^3*Sin(a)^2)\n\tTrigSimpCombine(Cos(a)^3*Sin(a)^2)\n\tTrigSimpCombine(Cos(a)*Sin(a))\n\tTrigSimpCombine(Cos(a)*Sin(b)*Cos(c))\n   \n */\n\n\n/* FSin, FCos and :*: are used for the internal representation\n   of the expression to work on:\n   - a*b -> a:*:b   this is used because we want to expand powers,\n     without the standard engine collapsing them back again.\n   - a*Sin(b) -> FSin(a,b) and a*Cos(b) -> FCos(a,b). This makes\n     adding and multiplying expressions with trig. functions, non-trig.\n     functions, constants, etc. a lot easier.\n*/\nRuleBase(\"FSin\",{f,x});\nRuleBase(\"FCos\",{f,x});\nRuleBase(\":*:\",{x,y});\nInfix(\":*:\",3);\n\n\nIsTrig(f) := (Type(f) = \"Sin\" Or Type(f) = \"Cos\");\nIsFTrig(f) := (Type(f) = \"FSin\" Or Type(f) = \"FCos\");\nIsMul(f) := (Type(f) = \"*\");\nIsMulF(f) := (Type(f) = \":*:\");\n\nIsPow(f):=\n  (Type(f) = \"^\" And\n   IsInteger(f[2]) And\n   f[2] > 1\n  );\n\n\n/* Convert Sin/Cos to FSin/FCos */\nRuleBase(\"TrigChange\",{f});\nRule(\"TrigChange\",1,1,Type(f)=\"Cos\") FCos(1,f[1]);\nRule(\"TrigChange\",1,1,Type(f)=\"Sin\") FSin(1,f[1]);\n\nRuleBase(\"TrigUnChange\",{f});\nRule(\"TrigUnChange\",1,1,Type(f)=\"FCos\") Cos(f[2]);\nRule(\"TrigUnChange\",1,1,Type(f)=\"FSin\") Sin(f[2]);\n\n\n/* Do a full replacement to internal format on a term. */\nRuleBase(\"FReplace\",{f});\nUnFence(\"FReplace\",1);\nRule(\"FReplace\",1,1,IsMul(f))  Substitute(f[1]) :*: Substitute(f[2]);\nRule(\"FReplace\",1,2,IsPow(f))  (Substitute(f[1]) :*: Substitute(f[1])) :*: Substitute(f[1]^(f[2]-2));\n/*\nRule(\"FReplace\",1,2,IsPow(f))  \n[\n  Local(trm,i,res,n);\n  Set(trm,Substitute(f[1]));\n  Set(n,f[2]);\n  Set(res,trm);\n  For(i:=2,i<=n,i++)\n  [\n    Set(res,res :*: trm);\n  ];\n  res;\n];\n*/\n\nRule(\"FReplace\",1,3,IsTrig(f)) TrigChange(f);\nFTest(f):=(IsMul(f) Or IsPow(f) Or IsTrig(f));\n\n/* Central function that converts to internal format */\nFToInternal(f):=Substitute(f,\"FTest\",\"FReplace\");\n\nFReplaceBack(f):=(Substitute(f[1])*Substitute(f[2]));\nUnFence(\"FReplaceBack\",1);\nFFromInternal(f):=Substitute(f,\"IsMulF\",\"FReplaceBack\");\n\n\n/* FLog(s,f):=[WriteString(s:\" \");Write(f);NewLine();]; */\n FLog(s,f):=[]; \n\n\n/* FSimpTerm simplifies the current term, wrt. trigonometric functions. */\nRuleBase(\"FSimpTerm\",{f,rlist});\nUnFence(\"FSimpTerm\",2);\n\n/* Addition: add all the subterms */\nRule(\"FSimpTerm\",2,1,Type(f) = \"+\")\n[\n  Local(result,lst);\n  lst:=Flatten(f,\"+\");\n\n  result:={{},{}};\nFLog(\"simpadd\",lst);\n\n  ForEach(tt,lst)\n  [\n    Local(new);\n    new:=FSimpTerm(tt,{{},{}});\n    result:={Concat(result[1],new[1]),Concat(result[2],new[2])};\n  ];\n  result;\n];\n\n\nTrigNegate(f):=\n[\n  UnList({f[0],-(f[1]),f[2]});\n];\n\n\nFUnTrig(result) := Substitute(result,\"IsFTrig\",\"TrigUnChange\");\n\nRule(\"FSimpTerm\",2,1,Type(f) = \"-\" And NrArgs(f)=1)\n[\n  Local(result);\n  result:=FSimpTerm(f[1],{{},{}});\n  Substitute(result,\"IsFTrig\",\"TrigNegate\");\n];\nRule(\"FSimpTerm\",2,1,Type(f) = \"-\" And NrArgs(f)=2)\n[\n  Local(result1,result2);\n  result1:=FSimpTerm(f[1],{{},{}});\n  result2:=FSimpTerm(-(f[2]),{{},{}});\n  {Concat(result1[1],result2[1]),Concat(result1[2],result2[2])};\n];\n\nRule(\"FSimpTerm\",2,2,Type(f) = \":*:\")\n[\n  FSimpFactor({Flatten(f,\":*:\")});\n];\nRule(\"FSimpTerm\",2,3,Type(f) = \"FSin\")\n[\n  {rlist[1],f:(rlist[2])};\n];\nRule(\"FSimpTerm\",2,3,Type(f) = \"FCos\")\n[\n  {f:(rlist[1]),rlist[2]};\n];\n\nRule(\"FSimpTerm\",2,4,True)\n[\n  {(FCos(f,0)):(rlist[1]),rlist[2]};\n];\n\n/* FSimpFactor does the difficult part. it gets a list, representing\n   factors, a*b*c -> {{a,b,c}}, and has to add terms from it.\n   Special cases to deal with:\n   - (a+b)*c -> a*c+b*c -> {{a,c},{b,c}}\n   - {a,b,c} where one of them is not a trig function or an addition:\n     replace with FCos(b,0), which is b*Cos(0) = b\n   - otherwise, combine two factors and make them into an addition.\n   - the lists should get shorter, but the number of lists should\n     get longer, until there are only single terms to be added.\n */\nFSimpFactor(flist):=\n[\n  Local(rlist);\n  rlist:={{},{}};\n  /* Loop over each term */\n  While(flist != {})\n  [\n    Local(term);\nFLog(\"simpfact\",flist);\n    term:=Head(flist);\n    flist:=Tail(flist);\n    FProcessTerm(term);\n  ];\nFLog(\"simpfact\",flist);\n\nFLog(\"rlist\",rlist);\n  rlist;\n];\nUnFence(\"FSimpFactor\",1);\n\n\nRuleBase(\"FProcessTerm\",{t});\nUnFence(\"FProcessTerm\",1);\n\n/* Deal with (a+b)*c -> a*c+b*c */\nRule(\"FProcessTerm\",1,1,Type(t[1]) = \"+\")\n[\n  Local(split,term1,term2);\n  split:=t[1];\n  term1:=FlatCopy(t);\n  term2:=FlatCopy(t);\n  term1[1]:=split[1];\n  term2[1]:=split[2];\n  DestructiveInsert(flist,1,term1);\n  DestructiveInsert(flist,1,term2);\n];\nRule(\"FProcessTerm\",1,1,Type(t[1]) = \"-\" And NrArgs(t[1]) = 2)\n[\n  Local(split,term1,term2);\n  split:=t[1];\n  term1:=FlatCopy(t);\n  term2:=FlatCopy(t);\n  term1[1]:=split[1];\n  term2[1]:=split[2];\n  DestructiveInsert(term2,1,FCos(-1,0));\n  DestructiveInsert(flist,1,term1);\n  DestructiveInsert(flist,1,term2);\n];\n\nRule(\"FProcessTerm\",1,1,Length(t)>1 And Type(t[2]) = \"-\" And NrArgs(t[2]) = 2)\n[\n  Local(split,term1,term2);\n  split:=t[2];\n  term1:=FlatCopy(t);\n  term2:=FlatCopy(t);\n  term1[2]:=split[1];\n  term2[2]:=split[2];\n  DestructiveInsert(term2,1,FCos(-1,0));\n  DestructiveInsert(flist,1,term1);\n  DestructiveInsert(flist,1,term2);\n];\n\nRule(\"FProcessTerm\",1,1,Type(t[1]) = \":*:\")\n[\n  Local(split,term);\n  split:=t[1];\n  term:=FlatCopy(t);\n  term[1]:=split[1];\n  DestructiveInsert(term,1,split[2]);\n  DestructiveInsert(flist,1,term);\n];\n\nRule(\"FProcessTerm\",1,1,Length(t)>1 And Type(t[2]) = \":*:\")\n[\n  Local(split,term);\n  split:=t[2];\n  term:=FlatCopy(t);\n  term[2]:=split[1];\n  DestructiveInsert(term,1,split[2]);\n  DestructiveInsert(flist,1,term);\n];\n\nRule(\"FProcessTerm\",1,1,Type(t[1]) = \"-\" And NrArgs(t[1]) = 1)\n[\n  Local(split,term);\n  split:=t[1];\n  term:=FlatCopy(t);\n  term[1]:=split[1];\n  DestructiveInsert(term,1,FCos(-1,0));\n  DestructiveInsert(flist,1,term);\n];\nRule(\"FProcessTerm\",1,1,Length(t)>1 And Type(t[2]) = \"-\" And NrArgs(t[2]) = 1)\n[\n  Local(split,term);\n  split:=t[2];\n  term:=FlatCopy(t);\n  term[2]:=split[1];\n  DestructiveInsert(term,1,FCos(-1,0));\n  DestructiveInsert(flist,1,term);\n];\n\n\n/* Deal with (a*(b+c) -> a*b+a*c */\nRule(\"FProcessTerm\",1,1,Length(t)>1 And Type(t[2]) = \"+\")\n[\n  Local(split,term1,term2);\n  split:=t[2];\n  term1:=FlatCopy(t);\n  term2:=FlatCopy(t);\n  term1[2]:=split[1];\n  term2[2]:=split[2];\n  DestructiveInsert(flist,1,term1);\n  DestructiveInsert(flist,1,term2);\n];\n\n\n\n/* Deal with a*FCos(1,b) ->FCos(a,0)*FCos(1,b) */\nRule(\"FProcessTerm\",1,2,Not(IsFTrig(t[1])) )\n[\n  t[1]:=FCos(t[1],0);\n  DestructiveInsert(flist,1,t);\n];\nRule(\"FProcessTerm\",1,2,Length(t)>1 And Not(IsFTrig(t[2])) )\n[\n  t[2]:=FCos(t[2],0);\n  DestructiveInsert(flist,1,t);\n];\n\n\nRule(\"FProcessTerm\",1,4,Length(t)=1 And Type(t[1]) = \"FCos\") \n[\n  DestructiveInsert(rlist[1],1,t[1]);\n];\nRule(\"FProcessTerm\",1,4,Length(t)=1 And Type(t[1]) = \"FSin\") \n[\n  DestructiveInsert(rlist[2],1,t[1]);\n];\n\n/* Now deal with the real meat: FSin*FCos etc. Reduce the multiplication\n   of the first two terms to an addition, adding two new terms to\n   the pipe line.\n */\nRule(\"FProcessTerm\",1,5,Length(t)>1)\n[\n  Local(x,y,term1,term2,news);\n  x:=t[1];\n  y:=t[2];\n  news:=TrigSimpCombineB(x,y);\n  /* Drop one term */\n  t:=Tail(t);\n  term1:=FlatCopy(t);\n  term2:=FlatCopy(t);\n  term1[1]:=news[1];\n  term2[1]:=news[2];\n  DestructiveInsert(flist,1,term1);\n  DestructiveInsert(flist,1,term2);\n];\n\n/* TrigSimpCombineB : take two FSin/FCos factors, and write them out into two terms */\nRuleBase(\"TrigSimpCombineB\",{x,y});\nRule(\"TrigSimpCombineB\",2,1,Type(x) = \"FCos\" And Type(y) = \"FCos\")\n     { FCos((x[1]*y[1])/2,x[2]+y[2]) , FCos((x[1]*y[1])/2,x[2]-y[2]) };\nRule(\"TrigSimpCombineB\",2,1,Type(x) = \"FSin\" And Type(y) = \"FSin\")\n     { FCos(-(x[1]*y[1])/2,x[2]+y[2]) , FCos((x[1]*y[1])/2,x[2]-y[2]) };\nRule(\"TrigSimpCombineB\",2,1,Type(x) = \"FSin\" And Type(y) = \"FCos\")\n     { FSin((x[1]*y[1])/2,x[2]+y[2]) , FSin( (x[1]*y[1])/2,x[2]-y[2]) };\nRule(\"TrigSimpCombineB\",2,1,Type(x) = \"FCos\" And Type(y) = \"FSin\")\n     { FSin((x[1]*y[1])/2,x[2]+y[2]) , FSin(-(x[1]*y[1])/2,x[2]-y[2]) };\n\n\nRuleBase(\"TrigSimpCombine\",{f});\nRule(\"TrigSimpCombine\",1,1,IsList(f))\n  Map(\"TrigSimpCombine\",{f});\n\nRule(\"TrigSimpCombine\",1,10,True)\n[\n  Local(new,varlist);\n  new:=f;\n\n  /* varlist is used for normalizing the trig. arguments */\n  varlist:=VarList(f);\n  \n/* Convert to internal format. */\n  new:=FToInternal(new);\nFLog(\"Internal\",new);\n\n  /* terms will contain FSin/FCos entries, the final result */\n\n  /* rlist gathers the true final result */\n  Local(terms);\n  terms:=FSimpTerm(new,{{},{}});\n  /* terms now contains two lists: terms[1] is the list of cosines,\n     and terms[2] the list of sines.\n   */\nFLog(\"terms\",terms);\n\n  /* cassoc and sassoc will contain the assoc lists with the cos/sin\n     arguments as key.\n   */\n  Local(cassoc,sassoc);\n  cassoc:={};\n  sassoc:={};\n  ForEach(item,terms[1])\n  [\n    CosAdd(item);\n  ];\n  ForEach(item,terms[2])\n  [\n    SinAdd(item);\n  ];\nFLog(\"cassoc\",cassoc);\nFLog(\"sassoc\",sassoc);\n\n  /* Now rebuild the normal form */\n  Local(result);\n  result:=0;\n\n//Echo({cassoc});\n//Echo({sassoc});\n  ForEach(item,cassoc)\n  [\nLog(\"item\",item);\n    result:=result+Expand(FUnTrig(FFromInternal(item[2])))*Cos(item[1]);\n  ];\n  ForEach(item,sassoc)\n  [\nLog(\"item\",item);\n    result:=result+Expand(FUnTrig(FFromInternal(item[2])))*Sin(item[1]);\n  ];\n\n  result;\n];\n\n\n\nCosAdd(t):=\n[\n  Local(look,arg);\n  arg:=Expand(t[2],varlist);\n  look:=Assoc(arg,cassoc);\n  If(look = Empty,\n     [\n       arg:=Expand(-arg,varlist);\n       look:=Assoc(arg,cassoc); \n       If(look = Empty,\n         DestructiveInsert(cassoc,1,{arg,t[1]}),\n         look[2]:=look[2]+t[1]\n         );\n     ]\n     ,\n     look[2]:=look[2]+t[1]\n    );\n];\nUnFence(\"CosAdd\",1);\n\nSinAdd(t):=\n[\n  Local(look,arg);\n  arg:=Expand(t[2],varlist);\n  look:=Assoc(arg,sassoc);\n  If(look = Empty,\n     [\n       arg:=Expand(-arg,varlist);\n       look:=Assoc(arg,sassoc);\n       If(look = Empty,\n         DestructiveInsert(sassoc,1,{arg,-(t[1])}),\n\t look[2]:=look[2]-(t[1])\n         );\n     ]\n     ,\n     look[2]:=look[2]+t[1]\n    );\n];\nUnFence(\"SinAdd\",1);\n\n\n/*\nIn( 4 ) = Exp(I*a)*Exp(I*a)      \nOut( 4 ) = Complex(Cos(a)^2-Sin(a)^2,Cos(a)*Sin(a)+Sin(a)*Cos(a));\nIn( 5 ) = Exp(I*a)*Exp(-I*a)     \nOut( 5 ) = Complex(Cos(a)^2+Sin(a)^2,Sin(a)*Cos(a)-Cos(a)*Sin(a));\n\nIn( 5 ) = Exp(I*a)*Exp(I*b) \nOut( 5 ) = Complex(Cos(a)*Cos(b)-Sin(a)*Sin(b),Cos(a)*Sin(b)+Sin(a)*Cos(b));\nIn( 6 ) = Exp(I*a)*Exp(-I*b) \nOut( 6 ) = Complex(Cos(a)*Cos(b)+Sin(a)*Sin(b),Sin(a)*Cos(b)-Cos(a)*Sin(b));\n\n\n*/\n\n"
  },
  {
    "path": "scripts/trigsimp.rep/code.ys.def",
    "content": "TrigSimpCombine\n}\n\n"
  },
  {
    "path": "scripts/univar.rep/Cyclotomic.ys",
    "content": "//  Cyclotomic(n,x):\n//  Returns the cyclotomic polinomial in the variable x\n//  (which is the minimal polynomial of the n-th primitive\n//  roots of the unit). \n//  Autor: Pablo De Napoli\n\nUse(\"univar.rep/code.ys\");\n\n// Auxiliar function for Cyclotomic: returns the internal representation of\n// x^q+a as an univarate polinomial (like MakeUni(x^q+a) but more efficient)\n\nFunction (\"UniVariateBinomial\",{x,q,a}) \n[ \nLocal(L,i);\nL := {a};\nFor (i:=1,i<q,i++)\n DestructiveAppend(L,0);\nDestructiveAppend(L,1);\nUniVariate(x,0,L); \n];\n\n// Auxiliar function for Cyclotomic: substitute in the univariate\n// polinomial p the variable x by -x^k. The implementations assumes that \n// the polinomial p starts with x^0 \n\nFunction(\"SubstituteInUniVar\",{p,k})\n[\n Local(c,i,d,j,NL);\n L  := p[3];  // The coefficients list  \n NL := {};    // The new coefficients list\n d  := Degree(p);\n i  :=d;\n ForEach(c,L) [\n  // c is the coefficient of x^i in p\n  // We append k-1 zeros\n  If (i<d, For (j:=1,j<k,j++) DestructiveAppend(NL,0));\n  // We append (-1)^i*c as the coefficient of x^(k*i) \n  DestructiveAppend(NL,If(IsEven(i),c,-c));  \n  i--; \n ];\n UniVariate(Head(p),0,NL);\n];\n\n\n// Adapted from ExpandUniVariate\n// Auxiliar function for Cyclotomic: substitute in the univariate\n// polinomial p the variable x by -x^k, but returns the result in\n// expanded form \n\nFunction(\"SubstituteAndExpandInUniVar\",{p,k})\n[\n  Local(result,i,var,first,coefs,c,nc,exponent);\n  result:=0;\n  var := p[1];\n  first:= p[2];\n  coefs:= p[3];\n  For(i:=Length(coefs),i>0,i--)\n  [\n    Local(term);\n    exponent := first+i-1;\n    c:= coefs[i];\n    nc := If(IsEven(exponent),c,-c);\n    term:=NormalForm(nc*var^(exponent*k));\n    result:=result+term;\n  ];\n  result;\n];\n\n// Returns a list of elements of the form {d1,d2,m}\n// where \n// 1) d1,d2 runs through the square free divisors of n \n// 2) d1 divides d2 and d2/d1 is a prime factor of n\n// 3) m=Moebius(d1) \n// Addapted form: MoebiusDivisorsList \n\nCyclotomicDivisorsList(n_IsPositiveInteger) <--\n[\n Local(nFactors,f,result,oldresult,x);\n nFactors:= Factors(n);\n result := {{1,nFactors[1][1],1}};\n nFactors := Tail(nFactors);\n ForEach (f,nFactors)   \n    [ \n      oldresult := result;\n        ForEach (x,oldresult) \n\t  result:=Append(result,{x[1]*f[1],x[2]*f[1],-x[3]});\n    ]; \n  result;\n];\n\n// CyclotomicFactor(x,a,b): Auxiliary function that constructs the term list of \n// the polynomial\n// Div(x^a-1,x^b-1) =\n// x^(b*(p-1)) + x^(b^*(p-2)) + ... + x^(b) + 1 \n// p= a/b, b should divide a \n\n\nCyclotomicFactor(_a,_b) <--\n[\n Local(coef,p,i,j,result); p := a/b; result:= {{b*(p-1),1}}; For (i:=\n p-2,i>=0,i--)\n   DestructiveAppend(result,{b*i,1});\n result; \t\n];\n\n\n// OldInternalCyclotomic(n,x,WantNormalForm) is the internal implementation\n// WantNormalForm is a boolean parameter. If it is true, returns the normal\n// form, if it is false returns the UniVariate representation.\n\n// This (old) implementation makes use of the internal representations of univariate\n// polynomials as UniVariate(var,begining,coefficients).\n// There is also a version UniVariateCyclotomic(n,x) that returns the \n// cyclotomic polynomial in the UniVariate representation.\n\n\n10 # OldInternalCyclotomic(n_IsEven,_x,WantNormalForm_IsBoolean) <--\n     [\n      Local(k,m,p); \n       k := 1;\n       m := n;\n\tWhile(IsEven(m))\n       [\n\tk := k*2;\n        m := m/2;\n       ];\n       k := k/2 ;\n       If(m>1, [\n\t         p := OldInternalCyclotomic(m,x,False);\n                 If (WantNormalForm, SubstituteAndExpandInUniVar(p,k),SubstituteInUniVar(p,k)); \n               ],\n\t         If (WantNormalForm, x^k+1, UniVariateBinomial(x,k,1))\n        );\n     ]; \n\n20 # OldInternalCyclotomic(n_IsOdd,_x,WantNormalForm_IsBoolean)_(n>1) <--\n[\n Local(divisors,poly1,poly2,q,d,f,result);\n divisors := MoebiusDivisorsList(n); \n poly1 :=1 ;\n poly2 := 1;\n ForEach (d,divisors)\n [ \n   q:=n/d[1];\n   f:=UniVariateBinomial(x,q,-1);\n   If (d[2]=1,poly1:=poly1*f,poly2:=poly2*f);\n ];\n result := Div(poly1,poly2);\n If(WantNormalForm,NormalForm(result),result);\n];\n\n10  # OldCyclotomic(1,_x) <-- _x-1;\n20  # OldCyclotomic(n_IsInteger,_x) <-- OldInternalCyclotomic(n,x,True);\n\n// This new implementation makes use of the internal representations of univariate\n// polynomials as SparseUniVar(var,termlist).\n\n\n//  For n even, we write n= m*k, where k is a Power of 2 \n//  and m is odd, and redce it to the case m even since:\n//\n//   Cyclotomic(n,x) = Cyclotomic(m,-x^{k/2}) \n//\n// If m=1, n is a power of 2, and Cyclotomic(n,x)= x^k+1 */\n\n\n10 # InternalCyclotomic(n_IsEven,_x) <--\n     [\n      Local(k,m,result,p,t); \n       k := 1;\n       m := n;\n\tWhile(IsEven(m))\n       [\n\tk := k*2;\n        m := m/2;\n       ];\n       k := k/2 ;\n       If(m>1, [\n\t         p:= InternalCyclotomic(m,x)[2];\n                 // Substitute x by -x^k\n                 result:={};\n                 ForEach(t,p)\n                    DestructiveAppend(result, {t[1]*k,If(IsEven(t[1]),t[2],-t[2])}); \n               ],\n\t         result := {{k,1},{0,1}} // x^k+1\n        );\n\tSparseUniVar(x,result);\n     ]; \n\n\n//  For n odd, the algoritm is based on the formula\n//\n//     Cyclotomic(n,x) := Prod (x^(n/d)-1)^Moebius(d) \n// \n// where d runs through the divisors of n.\n\n// We compute in poly1 the product\n// of (x^(n/d)-1) with Moebius(d)=1 , and in poly2 the product of these polynomials\n// with  Moebius(d)=-1. Finally we compute the quotient poly1/poly2 \n\n// In order to compute this in a efficient way, we use the functions\n// CyclotomicDivisorsList and  CyclotomicFactors (in order to avoid\n// unnecesary polynomial divisions) \n\n\n20 # InternalCyclotomic(n_IsOdd,_x)_(n>1) <--\n[\n Local(divisors,poly1,poly2,q,d,f,coef,i,j,result);\n divisors := CyclotomicDivisorsList(n); \n poly1 := {{0,1}};\n poly2 := {{0,1}};\n ForEach (d,divisors)\n [ \n   If(InVerboseMode(),Echo(\"d=\",d));\n   f:= CyclotomicFactor(n/d[1],n/d[2]);\n   If (d[3]=1,poly1:=MultiplyTerms(poly1,f),poly2:=MultiplyTerms(poly2,f));\n   If(InVerboseMode(), \n     [ \n       Echo(\"poly1=\",poly1);\n       Echo(\"poly2=\",poly2);\n     ]);\n ];\n If(InVerboseMode(),Echo(\"End ForEach\"));\n result := If(poly2={{0,1}},poly1,DivTermList(poly1,poly2));\n SparseUniVar(x,result); \n];\n\n\n10  # Cyclotomic(1,_x) <-- x-1;\n20  # Cyclotomic(n_IsInteger,_x) <-- ExpandSparseUniVar(InternalCyclotomic(n,x));\n\n\n// This function returns the Cyclotomic polynomial, but in the univariate\n// representation\n\n10  # UniVariateCyclotomic(1,_x) <-- UniVariate(x,0,{-1,1});\n20  # UniVariateCyclotomic(n_IsInteger,_x) <-- OldInternalCyclotomic(n,x,False);\n\n       \n\n"
  },
  {
    "path": "scripts/univar.rep/Cyclotomic.ys.def",
    "content": "Cyclotomic\nOldCyclotomic\nUniVariateCyclotomic\n}\n"
  },
  {
    "path": "scripts/univar.rep/code.ys",
    "content": "/* todos for univariates:\n   - Factorize\n*/\n\n// explicitly load predicates before extending IsZero() to polynomials;\n// otherwise IsZero() will be defined for poynomials only until predicates\n// will be loaded for some other reason\nUse(\"predicates.rep/code.ys\");\n\nUniVarList(expr) := VarList(expr);\n\n\n0 # NormalForm(UniVariate(_var,_first,_coefs)) <--\n    ExpandUniVariate(var,first,coefs);\n\nFunction(\"ExpandUniVariate\",{var,first,coefs})\n[\n  Local(result,i);\n  result:=0;\n  For(i:=Length(coefs),i>0,i--)\n  [\n    Local(term);\n    term:=NormalForm(coefs[i])*var^(first+i-1);\n    result:=result+term;\n  ];\n  result;\n];\n\n\n10 # IsUniVar(UniVariate(_var,_first,_coefs)) <-- True;\n20 # IsUniVar(_anything) <-- False;\n\n\nRuleBase(\"UniVariate\",{var,first,coefs});\n\nRule(\"UniVariate\",3,10,Length(coefs)>0 And coefs[1]=0)\n  UniVariate(var,first+1,Tail(coefs));\nRule(\"UniVariate\",3,1000,IsComplex(var) Or IsList(var))\n    ExpandUniVariate(var,first,coefs);\n\nUnProtect(IsZero);\n\n20 # IsZero(UniVariate(_var,_first,_coefs)) <-- IsZeroVector(coefs);\n\nProtect(IsZero);\n\nRuleBase(\"Degree\",{expr});\nRule(\"Degree\",1,0, IsUniVar(expr))\n[\n  If (IsZero(expr),\n    -Infinity,\n    [\n        Local(i,min,max);\n        min:=expr[2];\n        max:=min+Length(expr[3]);\n        i:=max;\n        While(i >= min And IsZero(Coef(expr,i))) i--;\n        i;\n    ]\n  );\n];\n\n10 # Degree(_poly)      <-- Degree(MakeUni(poly));\n10 # Degree(_poly,_var) <-- Degree(MakeUni(poly,var));\n\n\n\n500 # UniVariate(_var,_f1,_c1) + UniVariate(_var,_f2,_c2) <--\n[\n  Local(from,result);\n  Local(curl,curr,left,right);\n\n  Set(curl, f1);\n  Set(curr, f2);\n  Set(left, c1);\n  Set(right, c2);\n  Set(result, {});\n  Set(from, Min(curl,curr));\n\n  While(And(LessThan(curl,curr),left != {}))\n  [\n    DestructiveAppend(result,Head(left));\n    Set(left,Tail(left));\n    Set(curl,MathAdd(curl,1));\n  ];\n  While(LessThan(curl,curr))\n  [\n    DestructiveAppend(result,0);\n    Set(curl,MathAdd(curl,1));\n  ];\n  While(And(LessThan(curr,curl), right != {}))\n  [\n    DestructiveAppend(result,Head(right));\n    Set(right,Tail(right));\n    Set(curr,MathAdd(curr,1));\n  ];\n  While(LessThan(curr,curl))\n  [\n    DestructiveAppend(result,0);\n    Set(curr,MathAdd(curr,1));\n  ];\n  While(And(left != {}, right != {}))\n  [\n    DestructiveAppend(result,Head(left)+Head(right));\n    Set(left, Tail(left));\n    Set(right, Tail(right));\n  ];\n  While(left != {})\n  [\n    DestructiveAppend(result,Head(left));\n    Set(left, Tail(left));\n  ];\n  While(right != {})\n  [\n    DestructiveAppend(result,Head(right));\n    Set(right, Tail(right));\n  ];\n\n  UniVariate(var,from,result);\n];\n\n\n200 # UniVariate(_var,_first,_coefs) + a_IsNumber <--\n      UniVariate(var,first,coefs) + UniVariate(var,0,{a});\n200 # a_IsNumber + UniVariate(_var,_first,_coefs) <--\n      UniVariate(var,first,coefs) + UniVariate(var,0,{a});\n\n\n200 # - UniVariate(_var,_first,_coefs) <-- UniVariate(var,first,-coefs);\n\n\n200 # aLeft_IsUniVar - aRight_IsUniVar <--\n[\n  Local(from,result);\n  Local(curl,curr,left,right);\n\n  curl:=aLeft[2];\n  curr:=aRight[2];\n  left:=aLeft[3];\n  right:=aRight[3];\n  result:={};\n  from:=Min(curl,curr);\n\n  While(curl<curr And left != {})\n  [\n    DestructiveAppend(result,Head(left));\n    left:=Tail(left);\n    curl++;\n  ];\n  While(curl<curr)\n  [\n    DestructiveAppend(result,0);\n    curl++;\n  ];\n  While(curr<curl And right != {})\n  [\n    DestructiveAppend(result,-Head(right));\n    right:=Tail(right);\n    curr++;\n  ];\n  While(curr<curl)\n  [\n    DestructiveAppend(result,0);\n    curr++;\n  ];\n  While(left != {} And right != {})\n  [\n    DestructiveAppend(result,Head(left)-Head(right));\n    left  := Tail(left);\n    right := Tail(right);\n  ];\n\n\n  While(left != {})\n  [\n    DestructiveAppend(result,Head(left));\n    left  := Tail(left);\n  ];\n  While(right != {})\n  [\n    DestructiveAppend(result,-Head(right));\n    right := Tail(right);\n  ];\n\n  UniVariate(aLeft[1],from,result);\n];\n\n/* Repeated squares multiplication\n TODO put somewhere else!!!\n */\n10 # RepeatedSquaresMultiply(_a,- (n_IsInteger)) <-- 1/RepeatedSquaresMultiply(a,n);\n\n15 #  RepeatedSquaresMultiply(UniVariate(_var,_first,{_coef}),(n_IsInteger)) <--\n      UniVariate(var,first*n,{coef^n});\n20 # RepeatedSquaresMultiply(_a,n_IsInteger) <--\n[\n  Local(m,b);\n  Set(m,1);\n  Set(b,1);\n  While(m<=n) Set(m,(ShiftLeft(m,1)));\n  Set(m, ShiftRight(m,1));\n  While(m>0)\n  [\n    Set(b,b*b);\n    If (Not(Equals(BitAnd(m,n), 0)),Set(b,b*a));\n    Set(m, ShiftRight(m,1));\n  ];\n  b;\n];\n\n200 # aLeft_IsUniVar ^ aRight_IsPositiveInteger <--\n      RepeatedSquaresMultiply(aLeft,aRight);\n\n\n\n/*TODO this can be made twice as fast!*/\n\n\n201 # (aLeft_IsUniVar * _aRight)_((IsFreeOf(aLeft[1],aRight))) <--\n[\n    aRight*aLeft;\n];\n\n200 # (_factor * UniVariate(_var,_first,_coefs))_((IsFreeOf(var,factor))) <--\n  UniVariate(var,first,coefs*factor);\n\n200 # (UniVariate(_var,_first,_coefs)/_factor)_((IsFreeOf(var,factor))) <--\n  UniVariate(var,first,coefs/factor);\n\n\nShiftUniVar(UniVariate(_var,_first,_coefs),_fact,_shift)\n   <--\n   [\n//Echo(\"fact, coefs = \",fact,coefs);\n     UniVariate(var,first+shift,fact*coefs);\n   ];\n\n\n200 # UniVariate(_var,_f1,_c1) * UniVariate(_var,_f2,_c2) <--\n[\n  Local(i,j,n,shifted,result);\n  Set(result,MakeUni(0,var));\n//Echo(\"c1 = \",var,f1,c1);\n//Echo(\"c2 = \",var,f2,c2);\n  Set(n,Length(c1));\n  For(i:=1,i<=n,i++)\n  [\n//Echo(\"before = \",result);\n//Echo(\"parms = \",var,c1,c2,f1,f2,f1+i-1);\n    Set(result,result+ShiftUniVar(UniVariate(var,f2,c2),MathNth(c1,i),f1+i-1));\n//Echo(\"after = \",result);\n  ];\n//Echo(\"result = \",result);\n  result;\n];\n\n\n5 # Coef(uv_IsUniVar,order_IsList) <--\n[\n  Local(result);\n  result:={};\n  ForEach(item,order)\n  [\n    DestructiveAppend(result,Coef(uv,item));\n  ];\n  result;\n];\n\n10 # Coef(uv_IsUniVar,order_IsInteger)_(order<uv[2]) <-- 0;\n10 # Coef(uv_IsUniVar,order_IsInteger)_(order>=uv[2]+Length(uv[3])) <-- 0;\n20 # Coef(uv_IsUniVar,order_IsInteger) <-- uv[3][(order-uv[2])+1];\n30 # Coef(uv_CanBeUni,_order)_(IsInteger(order) Or IsList(order)) <-- Coef(MakeUni(uv),order);\n\nFunction(\"Coef\",{expression,var,order})\n    NormalForm(Coef(MakeUni(expression,var),order));\n\n10 # LeadingCoef(uv_IsUniVar) <-- If (IsZero(uv), 0, Coef(uv,Degree(uv)));\n\n20 # LeadingCoef(uv_CanBeUni) <-- LeadingCoef(MakeUni(uv));\n20 # LeadingCoef(uv_CanBeUni(var),_var) <-- LeadingCoef(MakeUni(uv, var));\n\n10 # ConstantTerm(uv_IsUniVar) <-- If (IsZero(uv), 0, Coef(uv, 0));\n\n10 # ConstantTerm(uv_CanBeUni(var), _var) <-- Coef(MakeUni(uv, var), var, 0);\n20 # ConstantTerm(uv_CanBeUni) <-- Coef(MakeUni(uv), 0);\n\nFunction(\"UniTaylor\",{taylorfunction,taylorvariable,taylorat,taylororder})\n[\n  Local(n,result,dif,polf);\n  result:={};\n  [\n    MacroLocal(taylorvariable);\n    MacroSet(taylorvariable,taylorat);\n    DestructiveAppend(result,Eval(taylorfunction));\n  ];\n  dif:=taylorfunction;\n  polf:=(taylorvariable-taylorat);\n  For(n:=1,n<=taylororder,n++)\n  [\n    dif:= Deriv(taylorvariable) dif;\n    MacroLocal(taylorvariable);\n    MacroSet(taylorvariable,taylorat);\n    DestructiveAppend(result,(Eval(dif)/n!));\n  ];\n  UniVariate(taylorvariable,0,result);\n];\n\n\nFunction(\"MakeUni\",{expression}) MakeUni(expression,UniVarList(expression));\n\n/* Convert normal form to univariate expression */\nRuleBase(\"MakeUni\",{expression,var});\n\n5 # MakeUni(_expr,{}) <-- UniVariate(dummyvar,0,{expression});\n6 # MakeUni(_expr,var_IsList) <--\n[\n  Local(result,item);\n  result:=expression;\n  ForEach(item,var)\n  [\n    result:=MakeUni(result,item);\n  ];\n  result;\n];\n\n10 # MakeUni(UniVariate(_var,_first,_coefs),_var) <--\n    UniVariate(var,first,coefs);\n\n20 # MakeUni(UniVariate(_v,_first,_coefs),_var) <--\n[\n  Local(reslist,item);\n  reslist:={};\n  ForEach(item,expression[3])\n  [\n    If(IsFreeOf(var,item),\n      DestructiveAppend(reslist,item),\n      DestructiveAppend(reslist,MakeUni(item,var))\n      );\n  ];\n  UniVariate(expression[1],expression[2],reslist);\n];\n\n\nLocalSymbols(a,b,var,expression)\n[\n  20 # MakeUni(expression_IsFreeOf(var),_var)\n       <-- UniVariate(var,0,{expression});\n  30 # MakeUni(_var,_var) <-- UniVariate(var,1,{1});\n  30 # MakeUni(_a + _b,_var) <-- MakeUni(a,var) + MakeUni(b,var);\n  30 # MakeUni(_a - _b,_var) <-- MakeUni(a,var) - MakeUni(b,var);\n  30 # MakeUni(   - _b,_var) <--                - MakeUni(b,var);\n  30 # MakeUni(_a * _b,_var) <-- MakeUni(a,var) * MakeUni(b,var);\n  1 # MakeUni(_a ^ n_IsInteger,_var) <-- MakeUni(a,var) ^ n;\n  30 # MakeUni(_a / (b_IsFreeOf(var)),_var) <-- MakeUni(a,var) * (1/b);\n];\n\n\nUnProtect(Div);\nUnProtect(Mod);\n\n0 # Div(n_IsUniVar,m_IsUniVar)_(Degree(n) < Degree(m)) <-- 0;\n0 # Mod(n_IsUniVar,m_IsUniVar)_(Degree(n) < Degree(m)) <-- n;\n1 # Div(n_IsUniVar,m_IsUniVar)_\n    (n[1] = m[1] And Degree(n) >= Degree(m)) <--\n[\n    UniVariate(n[1],0,\n               UniDivide(Concat(ZeroVector(n[2]),n[3]),\n                         Concat(ZeroVector(m[2]),m[3]))[1]);\n];\n1 # Mod(n_IsUniVar,m_IsUniVar)_\n    (n[1] = m[1] And Degree(n) >= Degree(m)) <--\n[\n    UniVariate(n[1],0,\n               UniDivide(Concat(ZeroVector(n[2]),n[3]),\n                         Concat(ZeroVector(m[2]),m[3]))[2]);\n];\n\nProtect(Div);\nProtect(Mod);\n\n/* division algo: (for zero-base univariates:) */\nFunction(\"UniDivide\",{u,v})\n[\n  Local(m,n,q,r,k,j);\n  m := Length(u)-1;\n  n := Length(v)-1;\n  While (m>0 And IsZero(u[m+1])) m--;\n  While (n>0 And IsZero(v[n+1])) n--;\n  q := ZeroVector(m-n+1);\n  r := FlatCopy(u);  /*  (m should be >= n) */\n  For(k:=m-n,k>=0,k--)\n  [\n    q[k+1] := r[n+k+1]/v[n+1];\n    For (j:=n+k-1,j>=k,j--)\n    [\n      r[j+1] := r[j+1] - q[k+1]*v[j-k+1];\n    ];\n  ];\n  Local(end);\n  end:=Length(r);\n  While (end>n)\n  [\n    DestructiveDelete(r,end);\n    end:=end-1;\n  ];\n\n  {q,r};\n];\n\n\nDropEndZeroes(list):=\n[\n  Local(end);\n  end:=Length(list);\n  While(list[end] = 0)\n  [\n    DestructiveDelete(list,end);\n    end:=end-1;\n  ];\n];\n\n\n\nFunction(\"UniGcd\",{u,v})\n[\n  Local(l,div,mod,m);\n\n  DropEndZeroes(u);\n  DropEndZeroes(v);\n/*\n  If(Length(v)>Length(u),\n    [\n      Locap(swap);\n      swap:=u;\n      u:=v;\n      v:=swap;\n    ] );\n  If(Length(u)=Length(v) And v[Length(v)] > u[Length(u)],\n    [\n      Locap(swap);\n      swap:=u;\n      u:=v;\n      v:=swap;\n    ] );\n  */\n\n\n  l:=UniDivide(u,v);\n\n  div:=l[1];\n  mod:=l[2];\n\n  DropEndZeroes(mod);\n  m := Length(mod);\n\n/* Echo({\"v,mod = \",v,mod}); */\n/*  If(m <= 1, */\n  If(m = 0,\n     v,\n/*     v/v[Length(v)], */\n     UniGcd(v,mod));\n];\n\nUnProtect(Gcd);\n\n0 # Gcd(n_IsUniVar,m_IsUniVar)_\n    (n[1] = m[1] And Degree(n) < Degree(m)) <-- Gcd(m,n);\n\n1 # Gcd(nn_IsUniVar,mm_IsUniVar)_\n    (nn[1] = mm[1] And Degree(nn) >= Degree(mm)) <--\n[\n    Gcd(Content(nn), Content(mm)) *\n    PrimitivePart(\n        UniVariate(\n            nn[1], 0,\n            UniGcd(Concat(ZeroVector(nn[2]),nn[3]),\n                   Concat(ZeroVector(mm[2]),mm[3]))));\n];\n\nProtect(Gcd);\n\nRuleBase(\"PSolve\",{uni});\n\nRule(\"PSolve\",1,1,IsUniVar(uni) And Degree(uni) = 1)\n    -Coef(uni,0)/Coef(uni,1);\n\n\n// Special case: a * x^n\nRule(\"PSolve\", 1, 1, IsUniVar(uni) And Degree(uni) > 1 And Coef(uni, 0 .. Degree(uni) - 1) = ZeroVector(Degree(uni))) [\n    ZeroVector(Degree(uni));\n];\n\n// Special case: a * x^n + b, solution generated by roots of unity\nRule(\"PSolve\", 1, 1, IsUniVar(uni) And Degree(uni) > 1 And ConstantTerm(uni) != 0 And Coef(uni, 1 .. Degree(uni) - 1) = ZeroVector(Degree(uni) - 1)) [\n    Local(n, k, phi0);\n    n := Degree(uni);\n    phi0 := Arg(-ConstantTerm(uni) / LeadingCoef(uni));\n    (Abs(ConstantTerm(uni) / LeadingCoef(uni)))^(1/n) * MapSingle({{k}, Complex(Cos((phi0 + 2 * k * Pi) / n), Sin((phi0 + 2 * k * Pi) / n))}, 0 .. n - 1);\n];\n\nRule(\"PSolve\", 1, 10, IsUniVar(uni) And Degree(uni) = 2)\n    [\n     Local(a,b,c,d);\n     c:=Coef(uni,0);\n     b:=Coef(uni,1);\n     a:=Coef(uni,2);\n     d:=b*b-4*a*c;\n\n     nd := `N(@d);\n\n     If (IsNumber(nd), [\n        If (d < 0,\n            {Complex(-b,Sqrt(-d))/(2*a),Complex(-b,-Sqrt(-d))/(2*a)},\n            {(-b+Sqrt(d))/(2*a),(-b-Sqrt(d))/(2*a)});\n\n     ], [\n        {(-b+Sqrt(d))/(2*a),(-b-Sqrt(d))/(2*a)};\n     ]);\n    ];\n\n// Use Cardano's formula to solve cubic polynomial.\n// See http://www.proofwiki.org/wiki/Cardano's_Formula\n// for details\nRule(\"PSolve\", 1, 20, IsUniVar(uni) And Degree(uni) = 3)\n[\n    Local(a, b, c, d, Q, R, D, shift);\n\n    a := Coef(uni, 3);\n    b := Coef(uni, 2);\n    c := Coef(uni, 1);\n    d := Coef(uni, 0);\n\n    Q := (3 * a * c - b^2) / (9 * a^2);\n    R := (9 * a * b * c - 27 * a^2 * d - 2 * b^3) / (54 * a^3);\n\n    D := Q^3 + R^2;\n\n    shift := -b / (3 * a);\n\n    If (IsRationalOrNumber(D),\n        If (D = 0,\n            {2 * R^(1/3) + shift, -R^(1/3) + shift, -R^(1/3) + shift},\n            If (D < 0, [\n                Local(theta);\n                theta := ArcCos(R / Sqrt(-Q^3));\n                {\n                    2 * Sqrt(-Q) * Cos((theta + 0 * Pi) / 3) + shift,\n                    2 * Sqrt(-Q) * Cos((theta + 2 * Pi) / 3) + shift,\n                    2 * Sqrt(-Q) * Cos((theta + 4 * Pi) / 3) + shift\n                };\n            ], [\n                Local(S, T);\n                S := (R + Sqrt(D))^(1/3);\n                T := (R - Sqrt(D))^(1/3);\n                {\n                    S + T + shift,\n                    Complex(-(S + T) / 2 + shift,  Sqrt(3) / 2 * (S - T)),\n                    Complex(-(S + T) / 2 + shift, -Sqrt(3) / 2 * (S - T))\n                };\n            ])\n        ), [\n            Local(S, T);\n            S := (R + Sqrt(D))^(1/3);\n            T := (R - Sqrt(D))^(1/3);\n\n            {\n                S + T + shift,\n                Complex(-(S + T) / 2 + shift,  Sqrt(3) / 2 * (S - T)),\n                Complex(-(S + T) / 2 + shift, -Sqrt(3) / 2 * (S - T))\n            };\n        ]\n    );\n];\n\n/*\nHow to solve the quartic equation?\n\nThe equation is x^4 + a1 x^3 + a2 x^2 + a3 x + a4 = 0.\nThe idea is to write the left-hand side as the difference of two\nsquares: (x^2 + p x + q)^2 - (s x + t)^2.\nEliminating the parentheses and equation coefficients yields four\nequations for the four unknowns p, q, s and t:\n  a1 = 2p              (1)\n  a2 = p^2 + 2q - s^2  (2)\n  a3 = 2pq - 2st       (3)\n  a4 = q^2 - t^2       (4)\nFrom the first equation, we find that p = a1/2. Substituting this in\nthe other three equations and rearranging gives\n  s^2 = a1^2/4 - a2 + 2q   (5)\n  2st = a1 q - a3          (6)\n  t^2 = q^2 - a4           (7)\nWe now take the square (6) and substitute (5) and (7):\n  4 (a1^2/4 - a2 + 2q) (q^2 - a4) = (a1 q - a3)^2  <==>\n  8 q^3 - 4 a2 q^2 + (2 a1 a3 - 8 a4) q + 4 a2 a4 - a1^2 a4 - a3^2 = 0.\nMiraculously, we got a cubic equation for q. Suppose we can solve this\nequation. We can then compute t from (7): t = sqrt(q^2 - a4). If t is\nnonzero, we can compute s from (6). Note that we cannot compute s from\n(5), since we introduced an extra solution when squaring (6). However,\nif t is zero, then no extra solution was introduced and we can safely\nuse (5). Having found the values of p, q, s and t, we can factor the\ndifference of squares and solve the quartic:\n  x^4 + a1 x^3 + a2 x^2 + a3 x + a4 = (x^2 + p x + q)^2 - (s x + t)^2\n                 = (x^2 + p x + q + s x + t) (x^2 + p x + q - sx - t).\nThe four roots of the quartic are the two roots of the first quadratic\nfactor plus the two roots of the second quadratic factor.\n*/\n\nRule(\"PSolve\", 1, 20, IsUniVar(uni) And Degree(uni) = 4 )\n[\n    Local(coef4,a1,a2,a3,a4,y,y1,z,t,s);\n\n    coef4:=Coef(uni,4);\n    a1:=Coef(uni,3)/coef4;\n    a2:=Coef(uni,2)/coef4;\n    a3:=Coef(uni,1)/coef4;\n    a4:=Coef(uni,0)/coef4;\n\n    /* y1 = 2q, with q as above. */\n    y1:=Head(PSolve(y^3-a2*y^2+(a1*a3-4*a4)*y+(4*a2*a4-a3^2-a1^2*a4),y));\n    //y1:=Head(Solve(y^3-a2*y^2+(a1*a3-4*a4)*y+(4*a2*a4-a3^2-a1^2*a4),y))[2];\n    t := Sqrt(y1^2/4-a4);\n    If(t=0, s:=Sqrt(y1+a1^2/4-a2), s:=(a1*y1-2*a3)/(4*t));\n    Concat(PSolve(z^2+(a1/2+s)*z+y1/2+t,z),\n           PSolve(z^2+(a1/2-s)*z+y1/2-t,z));\n];\n\nFunction(\"PSolve\",{uni,var})\n    [\n     PSolve(MakeUni(uni,var));\n     ];\n\n\n/* Generate a random polynomial */\n\n\nRandomPoly(_var,_degree,_coefmin,_coefmax) <--\n  NormalForm(UniVariate(var,0,RandomIntegerVector(degree+1,coefmin,coefmax)));\n\n\n/* CanBeUni returns whether the function can be converted to a\n * univariate, with respect to a variable.\n */\nFunction(\"CanBeUni\",{expression}) CanBeUni(UniVarList(expression),expression);\n\n\n/* Accepting an expression as being convertable to univariate */\n\n/* Dealing wiht a list of variables. The poly should be expandable\n * to each of these variables (smells like tail recursion)\n */\n10 # CanBeUni({},_expression) <-- True;\n20 # CanBeUni(var_IsList,_expression) <--\n    CanBeUni(Head(var),expression) And CanBeUni(Tail(var),expression);\n\n/* Atom can always be a polynom to any variable */\n30 # CanBeUni(_var,expression_IsAtom) <-- True;\n35 # CanBeUni(_var,expression_IsFreeOf(var)) <-- True;\n\n/* Other patterns supported. */\n40 # CanBeUni(_var,_x + _y) <-- CanBeUni(var,x) And CanBeUni(var,y);\n40 # CanBeUni(_var,_x - _y) <-- CanBeUni(var,x) And CanBeUni(var,y);\n40 # CanBeUni(_var,   + _y) <-- CanBeUni(var,y);\n40 # CanBeUni(_var,   - _y) <-- CanBeUni(var,y);\n40 # CanBeUni(_var,_x * _y) <-- CanBeUni(var,x) And CanBeUni(var,y);\n40 # CanBeUni(_var,_x / _y) <-- CanBeUni(var,x) And IsFreeOf(var,y);\n/* Special case again: raising powers */\n40 # CanBeUni(_var,_x ^ y_IsInteger)_(y >= 0 And CanBeUni(var,x)) <-- True;\n41 # CanBeUni(_var,(x_IsFreeOf(var)) ^ (y_IsFreeOf(var))) <-- True;\n50 # CanBeUni(_var,UniVariate(_var,_first,_coefs)) <-- True;\n1000 # CanBeUni(_var,_f)_(Not(IsFreeOf(var,f))) <-- False;\n1001 # CanBeUni(_var,_f) <-- True;\n\n10 # Content(UniVariate(_var,_first,_coefs))_(Apply(And, IsRational /@ coefs)) <--  Sign(LeadingCoef(UniVariate(var, first, coefs))) * Gcd(coefs);\n\n20 # Content(poly_CanBeUni) <-- NormalForm(Content(MakeUni(poly)));\n\n10 # PrimitivePart(UniVariate(_var,_first,_coefs)) <-- UniVariate(var,first, coefs / Content(UniVariate(var, first, coefs)));\n\n20 # PrimitivePart(poly_CanBeUni) <-- NormalForm(PrimitivePart(MakeUni(poly)));\n\n10 # Monic(UniVariate(_var,_first,_coefs)) <--\n[\n  DropEndZeroes(coefs);\n  UniVariate(var,first,coefs/coefs[Length(coefs)]);\n];\n20 # Monic(poly_CanBeUni) <-- NormalForm(Monic(MakeUni(poly)));\n\n30 # Monic(_poly,_var)_CanBeUni(poly,var) <-- NormalForm(Monic(MakeUni(poly,var)));\n\n\n10 # BigOh(UniVariate(_var,_first,_coefs),_var,_degree) <--\n    [\n     While(first+Length(coefs)>=(degree+1) And Length(coefs)>0) DestructiveDelete(coefs,Length(coefs));\n     UniVariate(var,first,coefs);\n    ];\n20 # BigOh(_uv,_var,_degree)_CanBeUni(uv,var) <-- NormalForm(BigOh(MakeUni(uv,var),var,degree));\n\n\n\nHorner(_e,_v) <--\n[\n  Local(uni,coefs,result);\n  uni := MakeUni(e,v);\n  coefs:=DestructiveReverse(uni[3]);\n  result:=0;\n\n  While(coefs != {})\n  [\n    result := result*v;\n    result := result+Head(coefs);\n    coefs  := Tail(coefs);\n  ];\n  result:=result*v^uni[2];\n  result;\n];\n\n\nDivPoly(_A,_B,_var,_deg) <--\n[\n  Local(a,b,c,i,j,denom);\n  b:=MakeUni(B,var);\n  denom:=Coef(b,0);\n\n  if (denom = 0)\n  [\n    Local(f);\n    f:=Content(b);\n    b:=PrimitivePart(b);\n    A:=Simplify(A/f);\n    denom:=Coef(b,0);\n  ];\n  a:=MakeUni(A,var);\n\n  c:=FillList(0,deg+1);\n  For(i:=0,i<=deg,i++)\n  [\n    Local(sum,j);\n    sum:=0;\n    For(j:=0,j<i,j++)\n    [\n      sum := sum + c[j+1]*Coef(b,i-j);\n    ];\n    c[i+1] := (Coef(a,i)-sum) / denom;\n  ];\n  NormalForm(UniVariate(var,0,c));\n];\n"
  },
  {
    "path": "scripts/univar.rep/code.ys.def",
    "content": "ExpandUniVariate\nIsUniVar\nUniVariate\nDegree\nSetOrder\nCoef\nLeadingCoef\nConstantTerm\nMakeUni\nUniDivide\nUniTaylor\nMonic\nPSolve\nCanBeUni\nContent\nPrimitivePart\nFactorUniVar\nRandomPoly\nBigOh\nHorner\nDivPoly\nDropEndZeroes\nUniGCD\n}\n"
  },
  {
    "path": "scripts/univar.rep/sparse.ys",
    "content": "// SparceUniVariate(variable,termlist) implements an internal representation\n// for univariate polynomials\n// termlist is the list of terms in the form {exponent,coeficient}\n\nRuleBase(\"SparseUniVar\",{var,termlist});\n\n300 # SparseUniVar(_var,_terms1) * SparseUniVar(_var,_terms2) <-- \nSparseUniVar(var, MultiplyTerms(terms1,terms2));\n\n300 # SparseUniVar(_var,_terms1) + SparseUniVar(_var,_terms2) <-- \nSparseUniVar(var, AddTerms(terms1,terms2));\n\n300 # SparseUniVar(_var,_terms1) - SparseUniVar(_var,_terms2) <-- \nSparseUniVar(var, SubstractTerms(terms1,terms2));\n\n// Add a term into a termlist: this function assumes that \n//  1) the list of terms is sorted in decreasing order of exponents\n//  2) there are not two terms with the same exponent.\n//  3) There is no term with cero coefficient \n// This assumptions are preserved.\n\n// The parameter begining tell us where to begin the search\n// (it is used for increasing the efficency of the algorithms!)\n// The function returns the position at which the new term is added plus 1. \n// (to be used as begining for sucesive AddTerm calls\n\nFunction(\"AddTerm\",{termlist,term,begining})\n[\n Local(l,i);\n l := Length(termlist);\n If(term[2]!=0,\n [\n  i:=begining;\n// Fix-me: search by using binary search ?\n  If (l>=1, While ((i<=l) And (term[1]<termlist[i][1])) i++);\n  If  (i>l, [DestructiveAppend(termlist,term);i++;], \n          If (term[1]=termlist[i][1],\n             [ Local(nc);\n               nc:=termlist[i][2]+term[2];\n                 If(nc!=0,DestructiveReplace(termlist,i,{term[1],nc}),\n                          [DestructiveDelete(termlist,i);i--;]);\n             ],  DestructiveInsert(termlist,i,term))\n     );\n ]\n  );\n i+1;\n];\n\n\nFunction(\"AddTerms\",{terms1,terms2})\n[\n  Local(result,begining,t);\n  begining :=1;\n  ForEach (t,terms2)\n     begining :=AddTerm(terms1,t,begining);\n  terms1;\n];\n\n\nFunction(\"SubstractTerms\",{terms1,terms2})\n[\n  Local(result,t);\n  begining :=1 ;\n  ForEach (t,terms2)\n     begining := AddTerm(terms1,{t[1],-t[2]},1);\n  terms1;\n];\n\n// Multiply a list of terms by a Single tem\n\nFunction(\"MultiplySingleTerm\",{termlist,term}) \n[\n Local(result,t);\n result:={};\n If(term[2]!=0, \n       ForEach (t,termlist)\n         DestructiveAppend(result,{t[1]+term[1],t[2]*term[2]}) );\n result;\n];\n\n\nFunction(\"MultiplyTerms\",{terms1,terms2}) \n[\n Local(result,t1,t2,begining);\n result:={};\n ForEach (t1,terms1)\n [\n   begining :=1;\n   ForEach (t2,terms2)\n     begining := AddTerm(result,{t1[1]+t2[1],t1[2]*t2[2]},1);\n ];\n result;\n];\n\nFunction(\"ExpandSparseUniVar\",{s})\n[\n Local(result,t,var,termlist);\n result :=0;\n var := s[1];\n termlist := s[2];\n ForEach (t,termlist)\n [\n   Local(term);\n   term := NormalForm(t[2]*var^t[1]);\n   result := result + term;\n ];\n result;\n];\n\n// Implements the division of polynomials!\n\nFunction(\"DivTermList\",{a,b})\n[\n Local(q,nq,t,c,begining);\n q := {};\n // a[1][1] is the degree of a, b[1][1] is the degree of b\n While ((a!={}) And a[1][1]>=b[1][1])\n  [\n     begining := 1;\n     If(InVerboseMode(),Echo(\"degree=\",a[1][1]));\n     nq := {a[1][1]-b[1][1],a[1][2]/b[1][2]}; // a new term of the quotient\n     DestructiveAppend(q,nq);\n     // We compute a:= a - nq* b\n     ForEach (t,b)\n       begining := AddTerm(a,{t[1]+nq[1],-t[2]*nq[2]},begining);\n   ];  \n   // a is the rest at the end\n q;\n];\n\n\n"
  },
  {
    "path": "scripts/univar.rep/sparse.ys.def",
    "content": "MultiplyTerms\nExpandSparseUniVar\nDivTermList\n}\n"
  },
  {
    "path": "scripts/univar.rep/sturm.ys",
    "content": "\nSquareFree(_p) <--\n[\n  Local(dp,gcd);\n//Echo(\"1...\");\n  dp:=MakeMultiNomial(`(D(x)(@p)),{x});\n//  dp:=dp/MultiLeadingCoef(dp);\n  \n//Echo(\"2...\",dp);\n  p:=MakeMultiNomial(p,{x});\n//Echo(NormalForm(p));\n//Echo(NormalForm(dp));\n  gcd:=MultiGcd(p,dp);\n//Echo(NormalForm(gcd));\n//Echo(NormalForm(MultiDivide(p,{gcd})[1][1]));\n  NormalForm(MultiDivide(p,{gcd})[1][1]);\n//  Div(p,Gcd(p,Monic(`(D(x)(@p)))));\n];\n\n/** SturmSequence(p) : generate a Sturm sequence for a polynomial in x.\n */\nSturmSequence(_p) <--\n[\n  Local(result,i,deg,nt);\n  result:={p,`D(@x)(@p)};\n  deg:=Degree(p);\n  For(i:=3,i<=deg+1,i++)\n  [\n    nt := -NormalForm(MultiDivide(MM(result[i-2],{x}),{MM(result[i-1],{x})})[2]);\n    DestructiveAppend(result,nt);\n  ];\n  result;\n];\n\n10 # SturmVariations(_S,Infinity) <--\n[\n  Local(i,s);\n  s:=FillList(0,Length(S));\n  For(i:=1,i<=Length(S),i++)\n  [\n    s[i] := LeadingCoef(S[i]);\n  ];\n  SturmVariations(s);\n];\n10 # SturmVariations(_S,-Infinity) <--\n[\n  Local(i,s);\n  s:=FillList(0,Length(S));\n  For(i:=1,i<=Length(S),i++)\n  [\n    s[i] := ((-1)^Degree(S[i]))*LeadingCoef(S[i]);\n  ];\n  SturmVariations(s);\n];\n\n20 # SturmVariations(_S,_x) <-- SturmVariations(Eval(S));\nSturmVariations(_S) <--\n[\n  Local(result,prev);\n//Echo(\"S = \",S);\n  result:=0;\n  While(Length(S)>0 And IsZero(S[1])) S:=Tail(S);\n//Echo(\"S = \",S);\n  if (Length(S)>0)\n  [\n    prev:=S[1];\n    ForEach(item,Tail(S))\n    [\n      if(Not IsZero(item))\n      [\n        if (prev*item < 0) [result++;];\n        prev:=item;\n      ];\n    ];\n  ];\n  result;\n];\n\n\n/** Maximum bound on the absolute value of the roots of a\n  polynomial p in variable x, according to Knuth:\n\n  Max( Abs(a[n-1]/a[n]) , Abs(a[n-2]/a[n])^(1/2), ... , Abs(a[0]/a[n])^(1/n) )\n\n As described in Davenport.\n */\n 5 # MaximumBound(_p)_(IsZero(p Where x==0)) <-- MaximumBound(Simplify(p/x));\n10 # MaximumBound(_p)_(Degree(p)>0) <--\n[\n  Local(an);\n  an:=Coef(p,(Degree(p)-1) .. 0)/Coef(p,Degree(p));\n  an := N(Eval(Abs(an)^(1/(1 .. Degree(p)))));\n  Rationalize(2*Max(an));\n];\n\n20 # MaximumBound(_p) <-- Infinity;\n\n10 # MinimumBound(_p)_(IsZero(p Where x==0)) <-- 0;\n\n20 # MinimumBound(_p)_(Degree(p)>0) <--\n[\n  Local(an,result);\n  an:=Coef(p,1 .. (Degree(p)))/Coef(p,0);\n  an := N(Eval(Abs(an)^(1/(1 .. Degree(p)))));\n\n  result:=0;\n  an:=2*Max(an);\n  if(Not IsZero(an)) [result := 1/an;];\n  Simplify(Rationalize(result));\n];\n30 # MinimumBound(_p) <-- -Infinity;\n\n\nBoundRealRoots(_p) <--\n[\n  BoundRealRoots(p,MinimumBound(p),MaximumBound(p));\n];\n\nBoundRealRoots(_p,_Mmin,_Mmax) <--\n[\n  Local(S,N,work,result,Vmin,Vmax,a,b,Va,Vb,c,Vc,x);\n\n  result:={};\n  if (IsZero(p Where x==0))\n  [\n    p:=Simplify(p/x);\n    result:={{0,0}};\n  ];\n  S:=SturmSequence(p);\n  Vmin := SturmVariations(S,-Infinity);\n  Vmax := SturmVariations(S,Infinity);\n\n//Echo(\"Vmin,Vmax = \",Vmin,Vmax);\n\n  N:=Vmin - Vmax;\n\n//Echo(\"N = \",N);\n  \n//Echo(\"Mmin,Mmax = \",Mmin,Mmax);\n  work:={};\n  if (N=1)\n  [\n    result:={{-Mmax,Mmax}};\n  ];\n  if (N>1)\n  [\n    work :=\n    {\n      {-Mmax,-Mmin,Vmin,SturmVariations(S,-Mmin)},\n      { Mmin, Mmax,SturmVariations(S, Mmin),Vmax}\n    };\n  ];\n\n//Echo(\"Work start = \",work);\n    While(work != {})\n    [\n      {a,b,Va,Vb} := Head(work);\n      work := Tail(work);\n      c:=(a+b)/2;\n//Echo(a,b,c);\n      Vc := SturmVariations(S,c);\n      if (IsZero(p Where x == c))\n      [\n        Local(M,Vcmin,Vcplus,pnew);\n        pnew := Simplify((p Where x == x+c)/x);\n        M:=MinimumBound(pnew);\n//Echo(\"Mi = \",M);\n        Vcmin  := SturmVariations(S, c-M);\n        Vcplus := SturmVariations(S, c+M);\n        result:=Concat(result,{{c,c}});\n\n        if (Va = Vcmin+1)\n        [\n          result:=Concat(result,{{a,c-M}});\n        ];\n        if (Va > Vcmin+1)\n        [\n          work:=Concat(work,{{a,c-M,Va,Vcmin}});\n        ];\n        if (Vb = Vcplus-1)\n        [\n          result:=Concat(result,{{c+M,b}});\n        ];\n        if (Vb < Vcplus-1)\n        [\n          work:=Concat(work,{{c+M,b,Vcplus,Vb}});\n        ];\n      ]\n      else\n      [\n        if (Va = Vc+1)\n        [\n          result:=Concat(result,{{a,c}});\n        ];\n        if (Va > Vc+1)\n        [\n          work:=Concat(work,{{a,c,Va,Vc}});\n        ];\n        if (Vb = Vc-1)\n        [\n          result:=Concat(result,{{c,b}});\n        ];\n        if (Vb < Vc-1)\n        [\n          work:=Concat(work,{{c,b,Vc,Vb}});\n        ];\n      ];\n    ];\n    result;\n];\n\n\nFindRealRoots(_p) <--\n[\n//Echo(\"0...\");\n//Echo(\"0...\");\n  p:=SquareFree(Rationalize(p));\n//Echo(\"1...\");\n//Echo(\"2...\",MinimumBound(p));\n//Echo(\"3...\",MaximumBound(p));\n  FindRealRoots(p,MinimumBound(p),MaximumBound(p));\n];\n\nFindRealRoots(_p,_Mmin,_Mmax) <--\n[\n  Local(bounds,result,i,prec,requiredPrec);\n//Echo(\"bounds1\");\n  bounds := BoundRealRoots(p,Mmin,Mmax);\n//Echo(\"bounds2\");\n  result:=FillList(0,Length(bounds));\n  requiredPrec := Builtin'Precision'Get();\n  Builtin'Precision'Set(Builtin'Precision'Get()+2);\n  prec:=10^-(requiredPrec+1);\n\n  For(i:=1,i<=Length(bounds),i++)\n  [\n    Local(a,b,c,r);\n    {a,b} := bounds[i];\n    c:=N(Eval((a+b)/2));\n//Echo(a,b,c);\n    r := Fail;\n//Echo(\"newton1\",`Hold(Newton(@p,x,@c,@prec,@a,@b)));\n    if (a != b) [r := `Newton(@p,x,@c,prec,a,b);];\n//Echo(\"newton2\",r,\" \",CurrentFile(),CurrentLine());\n    if (r = Fail)\n    [\n      Local(c,cold,pa,pb,pc);\n      pa:=(p Where x==a);\n      pb:=(p Where x==b);\n      c:=((a+b)/2);\n      cold := a;\n      While (Abs(cold-c)>prec)\n      [\n        pc:=(p Where x==c);\n//Echo(a,b,c);\n        if (Abs(pc) < prec)\n        [\n          a:=c;\n          b:=c;\n        ]\n        else if (pa*pc < 0)\n        [\n          b:=c;\n          pb:=pc;\n        ]\n        else \n        [\n          a:=c;\n          pa:=pc;\n        ];\n        cold:=c;\n        c:=((a+b)/2);\n      ];\n      r:=c;\n    ];\n    result[i] := N(Eval((r/10)*(10)),requiredPrec);\n  ];\n  Builtin'Precision'Set(requiredPrec);\n  result;\n];\n\nNumRealRoots(_p) <--\n[\n  Local(S);\n  p:=SquareFree(Rationalize(p));\n  S:=SturmSequence(p);\n  SturmVariations(S,-Infinity)-SturmVariations(S,Infinity);\n];\n\n"
  },
  {
    "path": "scripts/univar.rep/sturm.ys.def",
    "content": "SquareFree\nSturmSequence\nSturmVariations\nMaximumBound\nMinimumBound\nBoundRealRoots\nFindRealRoots\nNumRealRoots\n}\n"
  },
  {
    "path": "scripts/yacasinit.ys",
    "content": "\n\n/* This is the basic initialization file for Yacas. It gets loaded\n * each time Yacas is started. All the basic files are loaded.\n */\n\n/* Set up drivers, configurable in the .yacasrc\n *   Set(MultiNomialDriver,\"multivar.rep/sparsenomial.ys\");\n *     or\n *   Set(MultiNomialDriver,\"multivar.rep/partialdensenomial.ys\");\n */\n\n/* The truly required files (Yacas NEEDS to load). */\n// syntax must be loaded first\nUse(\"stdopers.ys\");\n\n/* Set of functions to define very simple functions. There are scripts that can\n   be compiled to plugins. So Yacas either loads the plugin, or loads the\n   scripts at this point. The functions in these plugins need to be defined with\n   these \"Defun\" functions.\n */\nDefMacroRuleBase(\"Defun\",{func,args,body});\nRule(\"Defun\",3,0,True)\n[\n  Local(nrargs);\n  Set(nrargs,Length(@args));\n  Retract(@func, `(@nrargs));\n  RuleBase(@func,@args);\n  Local(fn,bd);\n  Set(fn,Hold(@func)); Set(bd,Hold(@body));\n  `Rule(@fn, @nrargs, 0,True)(@bd);\n];\n\n//TODO remove? Use(\"base.rep/math.ys\");\n\nUse(\"patterns.rep/code.ys\");\n// at this point <-- can be used\n\nUse(\"deffunc.rep/code.ys\");\n\n// at this point := and Function() can be used\n\nUse(\"constants.rep/code.ys\");\nUse(\"standard.ys\");\nUse(\"stdarith.ys\");\n\n// at this point arithmetic can be used\n\n/* Load the def files for the other modules. The def files contain lists\n * of functions defined in that file. So, in solve.def you can find the\n * functions defined in the file solve. Each time a function is invoked\n * for which the interpreter can not find a definition, the file is loaded.\n */\n\nRuleBase(LoadPackages,{packages});\nRule(LoadPackages, 1, 1, True)\n[\n    If(Equals(packages,{}), True,\n    [\n        DefLoad(Head(packages));\n        LoadPackages(Tail(packages));\n    ]);\n];\n\nUse(\"packages.ys\");\nLoadPackages(DefFileList());\n\nLocalSymbols(input, output) [\n  input := {};\n  output := {};\n\n  RuleBase(\"Input'Append\", {e});\n  Rule(\"Input'Append\", 1, 0, True) [\n    DestructiveAppend(input, e);\n  ];\n\n  RuleBase(\"Input\", {i});\n  Rule(\"Input\", 1, 0, IsInteger(i) And i > 0) [\n    Check(i <= Length(input), \"Input: wrong argument\");\n    input[i];\n  ];\n\n  Rule(\"Input\", 1, 0, IsInteger(i) And i <= 0) [\n    Echo(-i, Length(input), -i < Length(input));\n    Check(-i < Length(input), \"Input: wrong argument\");\n    input[Length(input) + i];\n  ];\n\n  RuleBase(\"Output'Append\", {e});\n  Rule(\"Output'Append\", 1, 0, True) [\n    DestructiveAppend(output, e);\n  ];\n\n  RuleBase(\"Output\", {i});\n  Rule(\"Output\", 1, 0, IsInteger(i) And i > 0) [\n    Check(i <= Length(output), \"Output: wrong argument\");\n    output[i];\n  ];\n\n  Rule(\"Output\", 1, 0, IsInteger(i) And i <= 0) [\n    Echo(-i, Length(output), -i < Length(output));\n    Check(-i < Length(output), \"Output: wrong argument\");\n    output[Length(output) + i];\n  ];\n];\n\n/* The read-eval-print loop */\nRuleBase(\"REP\",{});\nLocalSymbols(input,stringOut,result,errorString)\nRule(\"REP\",0,1,True)\n[\n  Local(input,stringOut,result,inprompt,outprompt);\n  While(Not(IsExitRequested()))\n  [\n    inprompt := If (IsPromptShown(), \"In> \", \"\");\n    outprompt := If (IsPromptShown(), \"Out> \", \"\");\n\n    Set(errorString, \"\");\n    If(And(IsString(PrettyReader'Get()),Not(PrettyReader'Get() = \"\")),\n      TrapError(Set(input, FromString(ReadCmdLineString(inprompt))ApplyPure(PrettyReader'Get(),{})),Set(errorString,GetCoreError())),\n      TrapError(Set(input, FromString(ConcatStrings(ReadCmdLineString(inprompt),\";\"))Read()),Set(errorString,GetCoreError())));\n    If(Not(errorString = \"\"), WriteString(errorString));\n    If (Not(IsExitRequested()) And errorString=\"\",\n    [\n      Set(stringOut,\"\");\n      Set(result,False);\n      Set(stringOut,ToString()[TrapError(Set(result,Eval(input)),Set(errorString,GetCoreError()));]);\n      If(Not(stringOut = \"\"), WriteString(stringOut));\n      If(Not(errorString = \"\"), WriteString(errorString));\n      UnProtect(%);\n      SetGlobalLazyVariable(%,result);\n      Protect(%);\n      Input'Append(input);\n      Output'Append(result);\n      If(PrettyPrinter'Get()=\"\",\n      [\n        Write(Atom(outprompt),result);\n        NewLine();\n      ],\n      Apply(PrettyPrinter'Get(),{result}));\n    ]);\n  ];\n];\n\n"
  },
  {
    "path": "tests/CMakeLists.txt",
    "content": "set (CTEST_PROJECT_NAME \"yacas\")\n\nset (YACAS_TESTS\n  arithmetic.yts\n  association.yts\n  binaryfactors.yts\n  bitops.yts\n  c_tex_form.yts\n  calculus.yts\n  calendar.yts\n  canprove.yts\n  comments.yts\n  complex.yts\n  cyclotomic.yts\n  deriv.yts\n  dimensions.yts\n  dot.yts\n  GaussianIntegers.yts\n  graphs.yts\n  integrate.yts\n  io.yts\n  journal.yts\n  linalg.yts\n  lists.yts\n  logic_simplify_test.yts\n  macro.yts\n  matrixpower.yts\n  multivar.yts\n  newly.yts\n  nthroot.yts\n  numbers.yts\n  numerics.yts\n  nummethods.yts\n  ode.yts\n  openmath.yts\n  orthopoly.yts\n  outer.yts\n  padic.yts\n  physics.yts\n  plots.yts\n  poly.yts\n  predicates.yts\n  products.yts\n  programming.yts\n  radsimp.yts\n  rational.yts\n  regress.yts\n  scopestack.yts\n  simplify.yts\n  solve.yts\n  sturm.yts\n  sums.yts\n  tensors.yts\n  tr.yts\n  trace.yts\n  transforms.yts)\n\n\ninstall (FILES ${YACAS_TESTS} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/tests COMPONENT app)\ninstall (PROGRAMS ${TEST_YACAS_CMD} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/yacas/tests COMPONENT app)\n\nif (ENABLE_CYACAS_CONSOLE)\n    foreach (_test ${YACAS_TESTS})\n        if (WIN32)\n            add_test (NAME cyacas-${_test} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND \"tests/test-yacas.bat\" \"$<TARGET_FILE:yacas> -pc --rootdir scripts\" \"tests\" \"${_test}\")\n        elseif (APPLE)\n            add_test (NAME cyacas-${_test} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND \"tests/test-yacas\" \"$<TARGET_FILE:yacas> -pc --rootdir scripts\" \"tests\" \"${_test}\")\n        else ()\n            add_test (NAME cyacas-${_test} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND \"tests/test-yacas\" \"'$<TARGET_FILE:yacas>' -pc --rootdir scripts\" \"tests\" \"${_test}\")\n        endif ()\n    endforeach ()\nendif ()\n\nif (ENABLE_JYACAS)\n    foreach (_test ${YACAS_TESTS})\n        add_test (NAME jyacas-${_test} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND \"${TEST_YACAS_CMD}\" \"${Java_JAVA_EXECUTABLE} -jar $<TARGET_PROPERTY:jyacas,JAR_FILE>\" ${PROJECT_SOURCE_DIR}/tests ${_test})\n    endforeach ()\nendif ()\n"
  },
  {
    "path": "tests/GaussianIntegers.yts",
    "content": "\nNextTest(\"Gaussian Integers\");\n\n/* TestGaussianFactors: test if Gaussian Factors Really works!\nComputes in r the product of the factors, and checks if each\none is a Gaussian prime and if r is associated to z (i.e. if r/z\nis a Gaussian Unit */\nTestGaussianFactors(z_IsGaussianInteger) <--\n[\n Local(r,gfactors,Ok);\n// Echo(\"TestGaussianFactors: factoring \",z);\n gfactors := GaussianFactors(z);\n// Echo(gfactors);\n Ok := True;\n r :=1;\n ForEach(p,gfactors)\n [\n  r  := r*p[1]^p[2];\n  Ok := Ok And IsGaussianPrime(p[1]);\n ];\n// Echo(r);\n Ok := Ok And IsGaussianUnit(r/z);\n If(Ok,True,Echo(\"FAILED: GaussianFactors(\", z, \")=\", gfactors, \" which is wrong.\"));\n];\n\nTestGaussianFactors((9!)+1);\nTestGaussianFactors(2+3*I);\nTestGaussianFactors(-1+2*I);\nTestGaussianFactors(17);\nTestGaussianFactors(41);\n\nVerify(GaussianFactors(157+28*I), {{Complex(5,2),1},{Complex(-29,6),1}});\nVerify(GaussianFactors(1), {});\t// is this the correct behavior? why not {{}} or {{1,1}}?\nVerify(GaussianFactors(-1), {});\t// is this the correct behavior?\nVerify(GaussianFactors(I), {});\t// is this the correct behavior?\nVerify(GaussianFactors(0), {});\t// is this the correct behavior?\nVerify(GaussianFactors(2), {{Complex(1,1),1},{Complex(1,-1),1}});\nVerify(GaussianFactors(-2), {{Complex(1,1),1},{Complex(1,-1),1}});\nVerify(GaussianFactors(3), {{3,1}});\nVerify(GaussianFactors(3*I), {{3,1}});\nVerify(GaussianFactors(4), {{Complex(1,1),2},{Complex(1,-1),2}});\nVerify(GaussianFactors(-5*I), {{Complex(2,1),1},{Complex(2,-1),1}});\nVerify(GaussianFactors(Complex(1,1)^11*163^4),{{Complex(1,1),11},{163,4}});\n\n"
  },
  {
    "path": "tests/arithmetic.yts",
    "content": "NextTest(\"Test arithmetic\");\n\nNextTest(\"Basic calculations\");\nVerify(3 + 2 , 5);\nVerify(3-7, -4);\nVerify(1 = 2 , 0 = -1);\nVerify(5 ^ 2 , 25);\n\nVerify(IsZero(0.000),True);\n\nVerify(0.1 + 0, 0.1);\nVerify(0.1 + 0.0, 0.1);\nVerify(0 + 0.1, 0.1);\nVerify(0.0 + 0.1, 0.1);\n\nVerify(-6.23 + 0, -6.23);\nVerify(-6.23 + 0.0, -6.23);\nVerify(0 - 6.23, -6.23);\nVerify(0.0 - 6.23, -6.23);\n\nVerify(3 = 3e-3, False);\nVerify(4.0e-3 - 1.0e-3, 3e-3);\nVerify(4.e-3 - 1.e-3, 3e-3);\nVerify(4e-3 - 1e-3, 3e-3);\n\nVerify(2/5,Hold(2/5));\nVerify(IsZero(N(2/5)-0.4), True);\nVerify(IsRational(2),True);\nVerify(IsRational(2/5),True);\nVerify(IsRational(-2/5),True);\nVerify(IsRational(2.0/5),False);\nVerify(IsRational(Pi/2),False);\nVerify(Numer(2/5),2);\nVerify(Denom(2/5),5);\n\nVerifyArithmetic(10,5,8);\nVerifyArithmetic(10000000000,5,8);\nVerifyArithmetic(10,50,80);\nVerifyArithmetic(10000,50,88);\n\nVerify(4!,24);\nVerify(Bin(2,1),2);\n\nVerify(a-1+1, a);\nVerify(a-1+b+1, a+b);\nVerify(a-1+b-1, a+b-2);\n\nVerify(a/3+2*a/3,a);\nVerify(a/3+(2*a)/3,a);\nVerify(a/2+3*a/2,2*a);\nVerify(a/2+(3*a)/2,2*a);\nVerify(1/(2*a)+3/(2*a),2/a);\nVerify(a/(2*b)+3*a/(2*b),(2*a)/b);\n\nNextTest(\"Testing math stuff\");\nVerify(1*a,a);\nVerify(a*1,a);\nVerify(0*a,0);\nVerify(a*0,0);\nVerify(aa-aa,0);\n\nVerify(2+3,5);\nVerify(2*3,6);\n\nVerify(2+3*4,14);\nVerify(3*4+2,14);\nVerify(3*(4+2),18);\nVerify((4+2)*3,18);\n\nVerify(15/5,3);\n\nVerify(-2+3,1);\nVerify(-2.01+3.01,1.);\n\nVerify(0+a,a);\nVerify(a+0,a);\nVerify(aa-aa,0);\n\nTesting(\"IntegerOperations\");\nVerify(1<<10,1024);\nVerify(1024>>10,1);\nVerify(MathGcd(55,10),5);\n\nTesting(\"Mod/Div\");\n\nVerify(Mod(10,3),1);\nVerify(Mod(1/2*Pi, Pi), Pi/2);\n\nVerify(Div(10,3),3);\n\nVerify(Mod(2,Infinity),2);\nVerify(Mod({0,1,2,3,4,5,6},2),{0,1,0,1,0,1,0});\nVerify(Mod({0,1,2,3,4,5,6},{2,2,2,2,2,2,2}),{0,1,0,1,0,1,0});\n\nTesting(\"MathPower\");\n// was broken in the gmp version\nVerify(MathPower(19, 0), 1);\nVerify(MathPower(1, -1), 1);\nVerify(MathPower(1, -2), 1);\nVerify(IsZero(MathPower(10, -2)- 0.01), True);\nVerify(MathPower(2, 3), 8);\nNumericEqual(MathPower(2, -3), 0.125,Builtin'Precision'Get());\n\nTesting(\"Rounding\");\nVerify(Floor(1.2),1);\nVerify(Floor(-1.2),-2);\nVerify(Ceil(1.2),2);\nVerify(Ceil(-1.2),-1);\nVerify(Round(1.49),1);\nVerify(Round(1.51),2);\nVerify(Round(-1.49),-1);\nVerify(Round(-1.51),-2);\n\nTesting(\"Bases\");\nVerify(ToBase(16,255),\"ff\");\nVerify(FromBase(2,\"100\"),4);\n\n// conversion between decimal and binary digits\nVerify(BitsToDigits(2000, 10), 602);\nVerify(DigitsToBits(602, 10), 2000);\n\nLocalSymbols(f,ft)\n[\n  f(x,y):=(Div(x,y)*y+Rem(x,y)-x);\n  ft(x,y):=\n  [\n    Verify(f(x,y),0);\n    Verify(f(-x,y),0);\n    Verify(f(x,-y),0);\n    Verify(f(-x,-y),0);\n  ];\n  ft(10,4);\n  ft(2.5,1.2);\n];\n\nTesting(\"Factorization\");\nVerify(\nEval(Factors(447738843))\n, {{3,1},{17,1},{2729,1},{3217,1}}\n);\n\n\n//Exponential notation is now supported in the native arithmetic library too...\nVerify(2e3+1,2001.);\nVerify(2.0e3+1,2001.);\nVerify(2.00e3+1,2001.);\nVerify(2.000e3+1,2001.);\nVerify(2.0000e3+1,2001.);\n\nVerify(1+2e3,2001.);\nVerify(1+2.0e3,2001.);\nVerify(1+2.00e3,2001.);\nVerify(1+2.000e3,2001.);\nVerify(1+2.0000e3,2001.);\n\nNumericEqual(N(Sqrt(1e4))-100,0,Builtin'Precision'Get());\nNumericEqual(N(Sqrt(1.0e4))-100,0,Builtin'Precision'Get());\n\nVerify(2.0000e3-1,1999.);\n[\n  Local(p);\n  p:=Builtin'Precision'Get();\n  Builtin'Precision'Set(12);//TODO this will fail if you drop precision to below 12, for some reason.\n  NumericEqual(RoundTo(10e3*1.2e-3,Builtin'Precision'Get()),12.,Builtin'Precision'Get());\n  Builtin'Precision'Set(p);\n];\nVerify((10e3*1.2e-4)-1.2,0);\n\nVerify(IsZero(N(Sin(0.1e1)-Sin(1),30)),True);\n[\n  /* In Dutch they have a saying \"dit verdient geen schoonheidsprijs\" ;-) We need to sort this out.\n   * But a passable result, for now.\n   */\n  Local(diff);\n  diff := N(Sin(10e-1)-Sin(1),30);\n//Builtin'Precision'Set(20);\n//Echo(\"diff = \",diff);\n//Echo(\"diff > -0.00001 = \",diff > -0.00001);\n//Echo(\"diff < 0.00001 = \",diff < 0.00001);\n  Verify(diff > -0.00001 And diff < 0.00001,True);\n];\n\nNextTest(\"Greatest common divisor\");\n\n/* Jonathan reported a problem with Simplify(-Sqrt(8)/2), which returned some\n * complex expression containing greatest common divisors of square roots.\n * This was fixed by adding some rules dealing with taking the gcd of two objects\n * where at least one is a square root.\n */\nVerify(-Sqrt(8)/2,-Sqrt(2));\nVerify(Sqrt(8)/2,Sqrt(2));\nVerify(Gcd(Sqrt(2),Sqrt(2)),Sqrt(2));\nVerify(Gcd(-Sqrt(2),-Sqrt(2)),Sqrt(2));\nVerify(Gcd(Sqrt(2),-Sqrt(2)),Sqrt(2));\nVerify(Gcd(-Sqrt(2),Sqrt(2)),Sqrt(2));\n\nVerify(Gcd(2/3, 1), 1/3);\nVerify(Gcd(1, 2/3), 1/3);\nVerify(Gcd(-2/3, 1), 1/3);\nVerify(Gcd(2/3, -1), 1/3);\nVerify(Gcd(2/3, 1/5), 1/15);\n\nVerify(Gcd({-1}), 1);\n\nVerify(Gcd(2/3*Pi, 1/5*Pi), 1/15*Pi);\nVerify(Gcd(3*Pi, 1/5*Pi), Pi/5);\nVerify(Gcd(Pi, 1/5*Pi), Pi/5);\nVerify(Gcd(-Pi, 1/5*Pi), Pi/5);\nVerify(Gcd(-Pi/2, 1/5*Pi), Pi/10);\nVerify(Gcd(Pi/2, Pi/3), Pi/6);\n\nVerify(Gcd(Exp(1),Exp(2)), Exp(1));\nVerify(Gcd(Exp(-2), Exp(-4)), Exp(-4));\n\nNextTest(\"Absolute value\");\n\nVerify(Abs(1), 1);\nVerify(Abs(-1), 1);\nVerify(Abs(Sqrt(x)), Sqrt(x));\nVerify(Abs(Pi), Pi);\nVerify(Abs(-Pi), Pi);\nVerify(Abs(-Exp(-1), Exp(-1)));"
  },
  {
    "path": "tests/association.yts",
    "content": "NextTest(\"StrictTotalOrder\");\n\nVerify(StrictTotalOrder(1, 2), True);\nVerify(StrictTotalOrder(2, 2), False);\nVerify(StrictTotalOrder(2, 1), False);\nVerify(StrictTotalOrder(3, \"1\"), True);\n\nNextTest(\"Association\");\n\n[\n    Local(a);\n\n    a := Association'Create();\n\n    Verify(Association'Size(a), 0);\n    Verify(Length(a), 0);\n\n    Verify(Association'Contains(a, x), False);\n\n    Verify(Association'Set(a, x, y), True);\n    Verify(Association'Set(a, p, q), True);\n    Verify(Association'Contains(a, x), True);\n    Verify(Association'Keys(a), {p, x});\n    Verify(Association'ToList(a), {{p,q}, {x,y}});\n    Verify(Association'Head(a), {p,q});\n    Verify(Association'Size(a), 2);\n    Verify(Length(a), 2);\n    Verify(Association'Get(a, x), y);\n    Verify(Association'Drop(a, x), True);\n    Verify(Association'Drop(a, x), False);\n    Verify(Association'Get(a, x), Undefined);\n    Verify(Association'Size(a), 1);\n    Verify(Length(a), 1);\n\n    a := Association'CreateFromList({{1,2},{3,4}});\n    Verify(Association'ToList(a), {{1,2}, {3,4}});\n];\n"
  },
  {
    "path": "tests/binaryfactors.yts",
    "content": "\n\nTestPoly(poly,requiredResult):=\n[\n//Echo(poly);\n  Local(realResult);\n  realResult:=BinaryFactors(poly);\n  Verify(Length(realResult),Length(requiredResult));\n\n//Echo(requiredResult,realResult);\n  Local(intersection);\n  intersection:={};\n  ForEach(item1,requiredResult)\n    ForEach(item2,realResult)\n    [\n      If(Simplify(item1-item2) = {0,0},\n        intersection := (item1:intersection));\n    ];\n  Verify(Length(realResult),Length(intersection/*Intersection(requiredResult,realResult)*/));\n  Verify(Simplify(poly-FW(realResult)),0);\n];\n\n// Simple factorizations\nTestPoly((x+1)*(x-1),{{x+1,1},{x-1,1}});\n\n// Simple with multiple factors\nTestPoly((x+1)^2,{{x+1,2}});\n\n// Test: term with lowest power not zero power\nTestPoly(x^2*(x+1)*(x-1),{{x,2},{x+1,1},{x-1,1}});\nTestPoly(x^3*(x+1)*(x-1),{{x,3},{x+1,1},{x-1,1}});\n\n// Variable different from x\nTestPoly((y+1)*(y-1),{{y+1,1},{y-1,1}});\n\n// Test from Wester 1994 test\nTestPoly(D(x)(x+1)^20,{{20,1},{x+1,19}});\n\n// From regression test, and verify that polys with unfactorizable parts works\nTestPoly((x^6-1),{{x^4+x^2+1,1},{x+1,1},{x-1,1}});\n\n// Non-monic polynomials\nTestPoly((x+13)^2*(3*x-5)^3,{{27,1},{x+13,2},{x-5/3,3}});\nTestPoly((x+13)^2*(4*x-5)^3,{{64,1},{x+13,2},{x-5/4,3}});\n\n// Heavy: binary coefficients\nTestPoly((x+1024)*(x+2048),{{x+1024,1},{x+2048,1}});\nTestPoly((x+1024)^2*(x+2048)^3,{{x+1024,2},{x+2048,3}});\nTestPoly((16*x+1024)*(x+2048),{{16,1},{x+64,1},{x+2048,1}});\nTestPoly((x+1024)*(x+2047),{{x+1024,1},{x+2047,1}});\nTestPoly((x+1024)*(x+2049),{{x+1024,1},{x+2049,1}});\n\nTestPoly((x+1024)*(x-2047),{{x+1024,1},{x-2047,1}});\nTestPoly((x-1024)*(x+2047),{{x-1024,1},{x+2047,1}});\nTestPoly((x-1024)*(x-2047),{{x-1024,1},{x-2047,1}});\n\n// Rational coefficients\nTestPoly((x+4/7)*(x-5/9),{{x+4/7,1},{x-5/9,1}});\n\n// More than two factors ;-)\nTestPoly((x+1)*(x-2)*(x+3)*(x-4)*(x+5)*(x-6),{{x+1,1},{x-2,1},{x+3,1},{x-4,1},{x+5,1},{x-6,1}});\n\n\n\n"
  },
  {
    "path": "tests/bitops.yts",
    "content": "NextTest(\"Test binary operations\");\n\nVerify(1 << 3, 8);\nVerify(14 << 75, 528905046081400263933952);\nVerify(15 | 16, 31);\nVerify(31 & 16, 16);\nVerify(BitXor(31, 15), 16);"
  },
  {
    "path": "tests/c_tex_form.yts",
    "content": "NextTest(\"TeXForm\");\n\n\nVerify(\nTeXForm(Hold(Cos(A-B)*Sqrt(C+D)-(a+b)*c^d+2*I+Complex(a+b,a-b)/Complex(0,1)))\n,\"$\\\\cos \\\\left( A - B\\\\right)  \\\\sqrt{C + D} - \\\\left( a + b\\\\right)  c ^{d} + 2 \\\\imath  + \\\\frac{a + b + \\\\imath  \\\\left( a - b\\\\right) }{\\\\imath } $\"\n);\n\nVerify(\nTeXForm(Hold(Exp(A*B)/C/D/(E+F)*G-(-(a+b)-(c-d))-b^(c^d) -(a^b)^c))\n,\"$\\\\frac{\\\\frac{\\\\frac{\\\\exp \\\\left( A B\\\\right) }{C} }{D} }{E + F}  G - \\\\left(  - \\\\left( a + b\\\\right)  - \\\\left( c - d\\\\right) \\\\right)  - b ^{c ^{d}} - \\\\left( a ^{b}\\\\right)  ^{c}$\"\n);\n\nVerify(\nTeXForm(Hold(Cos(A-B)*Sin(a)*f(b,c,d*(e+1))*Sqrt(C+D)-(g(a+b)^(c+d))^(c+d)))\n,\"$\\\\cos \\\\left( A - B\\\\right)  \\\\sin a f\\\\left( b, c, d \\\\left( e + 1\\\\right) \\\\right)  \\\\sqrt{C + D} - \\\\left( g\\\\left( a + b\\\\right)  ^{c + d}\\\\right)  ^{c + d}$\"\n);\n\n// testing latest features: \\\\cdot, %, (a/b)^n, Bin(), BesselI, OrthoH\nVerify(\nTeXForm(3*2^n+Hold(x*10!) + (x/y)^2 + Bin(x,y) + BesselI(n,x) + Max(a,b) + OrthoH(n,x))\n, \"$3\\\\cdot 2 ^{n} + x\\\\cdot 10! + \\\\left( \\\\frac{x}{y} \\\\right)  ^{2} + {x \\\\choose y} + I _{n}\\\\left( x\\\\right)  + \\\\max \\\\left( a, b\\\\right)  + H _{n}\\\\left( x\\\\right) $\"\n);\n\n/* this fails because of a bug that D(x) f(y) does not go to 0 */ /*\nVerify(\nTeXForm(3*D(x)f(x,y,z)*Cos(Omega)*Mod(Sin(a)*4,5/a^b))\n,\"$3 \\\\left( \\\\frac{\\\\partial}{\\\\partial x}f\\\\left( x, y, z\\\\right) \\\\right)  \\\\left( \\\\cos \\\\Omega \\\\right)  \\\\left( 4 \\\\left( \\\\sin a\\\\right) \\\\right) \\\\bmod \\\\frac{5}{a ^{b}} $\"\n);\n*/\n\nVerify(\nTeXForm(Hold(D(x)f(x)))\n,\"$\\\\frac{d}{d x}f\\\\left( x\\\\right) $\");\n\nVerify(\nTeXForm(Hold(Not (c<0) And (a+b)*c>= -d^e And (c<=0 Or b+1>0) Or a!=0 And Not (p=q)))\n,\"$ \\\\neg c < 0\\\\wedge \\\\left( a + b\\\\right)  c\\\\geq  - d ^{e}\\\\wedge \\\\left( c\\\\leq 0\\\\vee b + 1 > 0\\\\right) \\\\vee a\\\\neq 0\\\\wedge  \\\\neg p = q$\"\n);\n\n\nVerify(\nTeXForm((D(x)f(x,y,z))*Cos(Omega)*Mod(Sin(a)*4,5/a^b))\n,\"$\\\\left( \\\\frac{\\\\partial}{\\\\partial x}f\\\\left( x, y, z\\\\right) \\\\right)  \\\\cos \\\\Omega  \\\\left( 4 \\\\sin a\\\\right) \\\\bmod \\\\frac{5}{a ^{b}} $\"\n);\n\n\nVerify(\nTeXForm(Pi+Exp(1)-Theta-Integrate(x,x1,3/g(Pi))2*theta(x)*Exp(1/x))\n,\"$\\\\pi  + \\\\exp \\\\left( 1\\\\right)  - \\\\Theta  - \\\\int _{x_{1}} ^{\\\\frac{3}{g\\\\left( \\\\pi \\\\right) }  } 2 \\\\theta \\\\left( x\\\\right)  \\\\exp \\\\left( \\\\frac{1}{x} \\\\right)  dx$\"\n);\n\nVerify(\nTeXForm({a[3]*b[5]-c[1][2],{a,b,c,d}})\n,\"$\\\\left( a _{3} b _{5} - c _{\\\\left( 1, 2\\\\right) }, \\\\left( a, b, c, d\\\\right) \\\\right) $\" \n);\n\nBodied(\"aa\", 200);\nInfix(\"bar\", 100);\n\nVerify(\nTeXForm(aa(x,y) z + 1 bar y!)\n,\"$aa\\\\left( x, y\\\\right) z + 1\\\\mathrm{ bar }y!$\" \n);\n\nVerify(\nTeXForm(x^(1/3)+x^(1/2))\n, \"$\\\\sqrt[3]{x} + \\\\sqrt{x}$\"\n);\n\nNextTest(\"CForm\");\n\nVerify(\nCForm(Hold(Cos(A-B)*Sin(a)*func(b,c,d*(e+Pi))*Sqrt(Abs(C)+D)-(g(a+b)^(c+d))^(c+d)))\n,\"cos(A - B) * sin(a) * func(b, c, d * ( e + Pi) ) * sqrt(fabs(C) + D) - pow(pow(g(a + b), c + d), c + d)\" \n);\n\nVerify(\nCForm(Hold([i:=0;While(i<10)[i++; a:=a+Floor(i);];]))\n, \"{\n  i = 0;\n  while(i < 10)\n    {\n      ++(i);\n      a = a + floor(i);\n      }\n    ;\n    ;\n  }\n\"\n);\n\n/* Check that we can still force numbers to be floats in stead of integers if we want to */\nVerify(\nCForm(Hold([i:=0.;While(i<10.)[i++; a:=a+Floor(i);];]))\n, \"{\n  i = 0.;\n  while(i < 10.)\n    {\n      ++(i);\n      a = a + floor(i);\n      }\n    ;\n    ;\n  }\n\"\n);\n\n\nTesting(\"IsCFormable\");\nVerify(\nIsCFormable(e+Pi*Cos(A-B)/3-Floor(3.14)*2)\n, True\n);\nVerify(\nIsCFormable(e+Pi*Cos(A-B)/3-Floor(3.14)*2+bad'func(x+y))\n, False\n);\nVerify(\nIsCFormable(e+Pi*Cos(A-B)/3-Floor(3.14)*2+bad'func(x+y), {bad'func})\n, True\n);\nVerify(\nIsCFormable([i:=0;While(i<10)[i++; a:=a+i;];])\n, True\n);\nVerify(\nIsCFormable([i:=0;While(i<10)[i++; a:=a+i; {};];])\n, False\n);\n"
  },
  {
    "path": "tests/calculus.yts",
    "content": "Testing(\"UnaryFunctionInverses\");\nVerify(Sin(ArcSin(a)),a); \nVerify(Cos(ArcCos(a)),a); \n\n//TODO ??? Verify(Tan(ArcTan(a)),a);\n// FIXME: These tests are not correct\n//Verify(ArcSin(Sin(a)),a); \n//Verify(ArcCos(Cos(a)),a); \n//TODO ??? this is not always the correct answer! Verify(ArcTan(Tan(a)),a);\nVerify(Tan(Pi/2),Infinity);\nVerify(Tan(Pi),0);\n\nVerify( Limit(x,Infinity) Sin(x), Undefined );\nVerify( Limit(x,Infinity) Cos(x), Undefined );\nVerify( Limit(x,Infinity) Tan(x), Undefined );\nVerify( Limit(x,Infinity) Gamma(x), Infinity );\nVerify( Limit(x,Infinity) Abs(x), Infinity );\nVerify( Limit(x,Infinity) x!, Infinity);\n\nVerify( Sin(x)/Cos(x), Tan(x) );\nVerify( TrigSimpCombine(Sin(x)^2 + Cos(x)^2), 1 );\n\nVerify( Sinh(x)-Cosh(x), Exp(-x));\nVerify( Sinh(x)+Cosh(x), Exp(x) );\nVerify( Sinh(x)/Cosh(x), Tanh(x) );\nVerify( Sinh(Infinity), Infinity);\nVerify( Sinh(x)*Csch(x), 1);\nVerify( 1/Coth(x), Tanh(x) );\nVerify(2+I*3,Complex(2,3));\nVerify(Magnitude(I+1),Sqrt(2));\n\nVerify(Re(2+I*3),2);\nVerify(Im(2+I*3),3);\n// Shouldn't these be in linalg.yts?\nVerify(ZeroVector(3),{0,0,0});\nVerify(BaseVector(2,3),{0,1,0});\nVerify(Identity(3),{{1,0,0},{0,1,0},{0,0,1}});\n\nTesting(\"Derivatives\");\nVerify(D(x) a,0);\nVerify(D(x) x,1);\nVerify(D(x) (x+x),2);\nVerify(D(x) (x*x),2*x);\nVerify(D(x) D(x) Sin(x),-Sin(x));\n\nTesting(\"Limits\");\nVerify( Limit(x,0,Right) Ln(x)*Sin(x), 0 );\nKnownFailure( Limit(k,Infinity) ((k-phi)/k)^(k+1/2) = Exp(-phi) );\n\nVerify(Limit(x,Infinity)(1/x * Sin(x)), 0);\nVerify(Limit(x,Infinity)Sin(x)/x, 0);\nVerify(Limit(x, Infinity) (x^2 + Sin(x)), Infinity);\n\nVerify(Limit(x,+Infinity) (x^3-x)/x^2 - x, 0);\n\n// Some limit tests adapted from mpreduce via mathpiper\n\nVerify(Limit(x,0)(Exp(x)-1)/x, 1);\nVerify(Limit(x,1)((1-x)/Ln(x))^2, 1);\nVerify(Limit(x,0)x/(Exp(x)-1), 1);\nVerify(Limit(x,0)x/Ln(x), 0);\nVerify(Limit(x,Infinity)Ln(1+x)/Ln(x), 1);\nVerify(Limit(x,Infinity)Ln(x)/Sqrt(x), 0);\nVerify(Limit(x,0,Right)Sqrt(x)/Sin(x), Infinity);\nVerify(Limit(x,0)x*Ln(x), 0);\nVerify(Limit(x,0)Ln(x)/Ln(2*x), 1);\nVerify(Limit(x,0)x*Ln(x)*(1+x), 0);\nVerify(Limit(x,Infinity)Ln(x)/x,0);\nVerify(Limit(x,Infinity)Ln(x)/Sqrt(x),0);\nVerify(Limit(x,Infinity)Ln(x), Infinity);\nVerify(Limit(x,0)Ln(x+1)/Sin(x), 1);\n// Seems to hang yacas\n//Verify(Limit(x,0)Ln(x+1/x)*Sin(x), 0);\nVerify(Limit(x,0)-Ln(1+x)*(x+2)/Sin(x), -2);\nVerify(Limit(x,Infinity)Ln(x+1)^2/Sqrt(x), 0);\nVerify(Limit(x,Infinity)(Ln(x+1)-Ln(x)), 0);\nVerify(Limit(x,Infinity)-Ln(x+1)^2/Ln(Ln(x)), -Infinity);\n\n\n[\n  Local(z);\n  // This function satisfies Laplaces eqn: D(x,2)z + D(y,2)z = 0\n  z:= ArcTan((2*x*y)/(x^2 - y^2));\n  //TODO, this test is disabled, should it be re-enabled?\n  // Hangs\n  // Verify(Simplify((D(x,2) z) + D(y,2) z), 0 );\n];\n\nTesting(\"Pslq\");\nVerifyPslq(left,right):=\n[\n  If(left=right,\n    Verify(True,True),\n    `Verify(@left,-(@right)));\n];\n\nVerifyPslq(Pslq({ Pi+2*Exp(1) , Pi , Exp(1) },20),{1,-1,-2});\nVerifyPslq(Pslq({ 2*Pi+3*Exp(1) , Pi , Exp(1) },20),{1,-2,-3});\n\n\n\n"
  },
  {
    "path": "tests/calendar.yts",
    "content": "Testing(\"Calendar\");\n\nVerify(Easter(2012),{4,8});\n"
  },
  {
    "path": "tests/canprove.yts",
    "content": "\nNextTest(\"Propositional logic theorem prover\");\n\nVerify(CanProve(( (a=>b) And (b=>c) => (a=>c) )),True);\nVerify(CanProve((((a=>b) And (b=>c))=> (a=>c) )),True);\nVerify(CanProve(( (a=>b) And((b=>c) => (a=>c)))),((Not a Or b)And(Not a Or (b Or c))) );\n//KnownFailure(BadOutput + WhenPreviousLine + IsUncommented);\n//And *my* previous line (the KnownFailure) aborts.  (witnessed by no report from next line).\nVerify(CanProve( True ),True);\n\nVerify(CanProve(a Or Not a)                   ,True);\nVerify(CanProve(True Or a)                 ,True);\nVerify(CanProve(False Or a)                ,a   );\nVerify(CanProve(a And Not a)                   ,False);\nVerify(CanProve(a Or b Or (a And b))               ,a Or b  );\n\n/* Two theorems from the Pure Implicational Calculus (PIC), in which the\n * only operator is [material] implication.  From the first, all other\n * theorems in PIC can be proved using only the two transformation rules:\n * 1. Rule of substitution.  Uniform replacement in theorems yields theorems.\n * 2. Rule of detachment, or modus ponens.  If 'a' and 'a=>b' are theorems, then 'b' is a theorem.\n *\n * 1. Lukasiewicz, Jan, \"The Shortest Axiom of the Implicational Calculus\n *    of Propositions,\" Proceedings of the Royal Irish Academy, vol. 52,\n *    Sec. A, No. 3 (1948).  [ Can you say \"Polish Notation\"? ]\n * 2. Meredith, David, \"On a Property of Certain Propositional Formulae,\"\n *    Notre Dame Journal of Formal Logic, vol. XIV, No. 1, January 1973.\n */\nVerify(CanProve(\t/* 1. CCCpqrCCrpCsp */\n     ((p=>q) => r) => ((r=>p) => (s=>p))\n     ), True);\nVerify(CanProve(\t/* 2. CCpCqrCqCpr */\n     (p => (q=>r)) => (q => (p=>r))\n     ), True);\n"
  },
  {
    "path": "tests/comments.yts",
    "content": "\nNextTest(\"Checking comment syntax supported\");\n[\n  Local(a);\n  /* something here */\n  a:= 3;\n  // test 1\n\n  // /* test2 */\n\n  /* // test3 */\n\n  //Echo({a, Nl()});\n\n  // Check parsing\n  a==-b; // This would generate a parse error in Yacas versions 1.0.54 and earlier\n];\n\n\n[\n  Local(errorString);\n  errorString:=\"\";\n  TrapError(Check(False,\"some error\"),errorString:=GetCoreError());\n  Verify(IsString(errorString),True);\n  Verify(Length(errorString)>4,True);  \n];\nVerify(errorString,errorString);\n"
  },
  {
    "path": "tests/complex.yts",
    "content": "Verify( Limit(z,2*I) (I*z^4+3*z^2-10*I), Complex(-12,6) );\nKnownFailure( (Limit(n,Infinity) (n^2*I^n)/(n^3+1)) = 0 );\nVerify( Limit(n,Infinity) n*I^n, Undefined );\n\nVerify(1/I, -I);\nVerify(I^2, -1);\nVerify(2/(1+I), 1-I);\nVerify(I^3, -I);\nVerify(I^4, 1);\nVerify(I^5, I);\nVerify(1^I, 1);\nVerify(0^I, Undefined);\nVerify(I^(-I), Exp(Pi/2));\nVerify((1+I)^33, 65536+I*65536);\nVerify((1+I)^(-33), (1-I)/131072);\nVerify(Exp(I*Pi), -1);\nTestYacas((a+b*I)*(c+d*I), (a*c-b*d)+I*(a*d+b*c));\nVerify(Ln(-1), I*Pi);\nVerify(Ln(3+4*I), Ln(5)+I*ArcTan(4/3));\n\nVerify(Re(2*I-4), -4);\nVerify(Im(2*I-4), 2);\n\n"
  },
  {
    "path": "tests/cyclotomic.yts",
    "content": "NextTest(\"Cyclotomic Polynomials\");\n\nVerify(Cyclotomic(1,x),x-1);\nVerify(Cyclotomic(5,x),x^4+x^3+x^2+x+1);\nVerify(Cyclotomic(8,z),z^4+1);\nVerify(Cyclotomic(10,y),y^4-y^3+y^2-y+1);\nVerify(Cyclotomic(15,x),x^8-x^7+x^5-x^4+x^3-x+1);\n\n"
  },
  {
    "path": "tests/deriv.yts",
    "content": "TestYacas(Deriv(x)Ln(x),1/x);\nTestYacas(Deriv(x)Exp(x),Exp(x));\nTestYacas(Deriv(x)(x^4+x^3+x^2+x+1),4*x^3+3*x^2+2*x+1);\nTestYacas(Deriv(x)Sin(x),Cos(x));\nTestYacas(Deriv(x)Cos(x),-Sin(x));\nTestYacas(Deriv(x)Sinh(x),Cosh(x));\nTestYacas(Deriv(x)Cosh(x),Sinh(x));\nTestYacas(Deriv(x)ArcCos(x),-1/Sqrt(1-x^2));\nTestYacas(Deriv(x)ArcSin(x),1/Sqrt(1-x^2));\nTestYacas(Deriv(x)ArcTan(x),1/(x^2+1));\nTestYacas(Deriv(x)Sech(x),-Sech(x)*Tanh(x));\n"
  },
  {
    "path": "tests/dimensions.yts",
    "content": "//////\n// $Id: dimensions.yts,v 1.2 2006-03-26 12:49:15 ayalpinkus Exp $\n// Tests for Dimensions\n//////\n\nTesting(\"-- Dimensions (Tensor Rank)\");\n\nVerify(Dimensions(a),{});\nVerify(Dimensions({}),{0});\nVerify(Dimensions({a,b}),{2});\nVerify(Dimensions({{}}),{1,0});\nVerify(Dimensions({{a}}),{1,1});\nVerify(Dimensions({{},a}),{2});\nVerify(Dimensions({{a},b}),{2});\nVerify(Dimensions({{},{}}),{2,0});\nVerify(Dimensions({{},{{}}}),{2});\nVerify(Dimensions({{a,b},{c}}),{2});\nVerify(Dimensions({{a,b},{c,d}}),{2,2});\nVerify(Dimensions({{a,b},{c,d},{e,f}}),{3,2});\nVerify(Dimensions({{a,b,c},{d,e,f},{g,h,i}}),{3,3});\nVerify(Dimensions({{a,b,c},{d,e,f}}),{2,3});\nVerify(Dimensions({{{a,b}},{{c,d}}}), {2,1,2});\nVerify(Dimensions({{{{a},{b}}},{{{c},d}}}),{2,1,2});\nVerify(Dimensions({{{{{a,b}}}},{{{c,d}}}}),{2,1,1});\nVerify(Dimensions({{{{{a,b}}}},{{{c},{d}}}}),{2,1});\nVerify(Dimensions({{{}}}),{1,1,0});\nVerify(Dimensions({{{a}}}),{1,1,1});\nVerify(Dimensions({{{{a}}},{{{b}}}}),{2,1,1,1});\nVerify(Dimensions({{{{a},{b}}},{{{c},{d}}}}),{2,1,2,1});\nVerify(Dimensions({{{{a,b}}},{{{c,d}}}}),{2,1,1,2});\nVerify(Dimensions({{{{a,b}},{{c,d}}}}),{1,2,1,2});\nVerify(Dimensions({{{{{{a,b},{c}}}}},{{{d},{e,f,g}}}}), {2,1});\n\n//////\n//////\n"
  },
  {
    "path": "tests/dot.yts",
    "content": "//////\n// $Id: dot.yts,v 1.2 2006-03-26 12:49:15 ayalpinkus Exp $\n// Tests for Dot\n//////\n\nTesting(\"-- Dot\");\n\n// vector . vector\nVerify(Dot({},{}),0);\nVerify(Dot({},a),Hold(Dot({},a)));\nVerify(Dot(a,{}),Hold(Dot(a,{})));\nVerify(Dot({a},{}),Hold(Dot({a},{})));\nVerify(Dot({},{a}),Hold(Dot({},{a})));\nVerify(Dot({a},{b}),a*b);\nVerify(Dot({a},{b,c}),Hold(Dot({a},{b,c})));\nVerify(Dot({a,b},{c}),Hold(Dot({a,b},{c})));\nVerify(Dot({a,b},{c,d}),a*c+b*d);\nVerify(Dot({a,b},{c,{d}}),Hold(Dot({a,b},{c,{d}})));\nVerify(Dot({a,{b}},{c,d}),Hold(Dot({a,{b}},{c,d})));\nVerify(Dot({a,b},{c,d,e}),Hold(Dot({a,b},{c,d,e})));\nVerify(Dot({a,b,c},{d,e}),Hold(Dot({a,b,c},{d,e})));\nVerify(Dot({1,2,3},{4,5,6}),32);\n\n// matrix . vector\nVerify(Dot({{}},{}),{0});\nVerify(Dot({{}},{1}),Hold(Dot({{}},{1})));\nVerify(Dot({{},{}},{}),{0,0});\nVerify(Dot({{a}},{b}),{a*b});\nVerify(Dot({{a},{b}},{c}),{a*c,b*c});\nVerify(Dot({{1},{2}},{2}),{2,4});\nVerify(Dot({{1,2,3},{4,5,6}},{7,8,9}),{50,122});\n\n// vector . matrix\nVerify(Dot({},{{}}),Hold(Dot({},{{}})));\nVerify(Dot({},{{},{}}),Hold(Dot({},{{},{}})));\nVerify(Dot({1},{{}}),Hold(Dot({1},{{}})));\nVerify(Dot({1},{{},{}}),Hold(Dot({1},{{},{}})));\nVerify(Dot({a,b},{{c},{d}}),{a*c+b*d});\nVerify(Dot({1,2,3},{{4,5},{6,7},{8,9}}),{40,46});\n\n// matrix . matrix\nVerify(Dot({{}},{{}}),Hold(Dot({{}},{{}})));\nVerify(Dot({{a}},{{}}),Hold(Dot({{a}},{{}})));\nVerify(Dot({{}},{{b}}),Hold(Dot({{}},{{b}})));\nVerify(Dot({{1,2},{3,4},{5,6}},{{1,2,3},{4,5,6}}),{{9,12,15},{19,26,33},{29,40,51}});\nVerify(Dot({{1,2,3},{4,5,6}},{{1,2},{3,4},{5,6}}),{{22,28},{49,64}});\n\n//////\n"
  },
  {
    "path": "tests/graphs.yts",
    "content": "Testing(\"Graphs\");\n\nVerify(Graph({1->2,2->3,3->1}), Graph({1,2,3}, {1->2,2->3,3->1}));\n\nVerify(Vertices(Graph({1->2,2->3,3->1})), {1,2,3});\nVerify(Edges(Graph({1->2,2->3,3->1})), {1->2,2->3,3->1});\n\nVerify(AdjacencyMatrix(Graph({1->2,2->3,3->1})), {{0,1,0},{0,0,1},{1,0,0}});\nVerify(DFS(Graph({1->2,2->3,3->1}), {{x}, x}), {1,2,3});"
  },
  {
    "path": "tests/includetestfiles",
    "content": "\nNORMAL_TESTFILES = openmath.yts macro.yts arithmetic.yts\t\t\t  \\\n\tc_tex_form.yts calculus.yts canprove.yts comments.yts complex.yts \\\n\tderiv.yts dimensions.yts dot.yts journal.yts integrate.yts\t\t  \\\n\tlists.yts logic_simplify_test.yts matrixpower.yts nthroot.yts\t  \\\n\touter.yts predicates.yts ode.yts tensors.yts trace.yts tr.yts\t  \\\n\tmultivar.yts numbers.yts io.yts programming.yts regress.yts\t\t  \\\n\tsimplify.yts solve.yts sums.yts transforms.yts radsimp.yts\t\t  \\\n\tlinalg.yts orthopoly.yts poly.yts numerics.yts scopestack.yts\t  \\\n\tplots.yts GaussianIntegers.yts nummethods.yts sturm.yts\t\t\t  \\\n\tcyclotomic.yts binaryfactors.yts padic.yts calendar.yts newly.yts graphs.yts\n\nSPECIAL_TESTFILES = ../manmake/wester-1994.yts\n\nTESTFILES = $(NORMAL_TESTFILES) $(SPECIAL_TESTFILES)\nQUICKTESTFILES = simplify.yts sturm.yts\n\n"
  },
  {
    "path": "tests/integrate.yts",
    "content": "\n// verify that unknown integrals don't simplify\nVerify(Integrate(x,a,b)Exp(Sin(x)),Integrate(x,a,b)Exp(Sin(x)));\nVerify(Integrate(x    )Exp(Sin(x)),Integrate(x    )Exp(Sin(x)));\n\n// Verify that Yacas cannot integrate these expressions.\n// Yacas needs to return the integration unevaluated, or\n// return a correct answer (if it happens to be able to do\n// these integrals in the future).\nTestNonIntegrable(_expr) <-- Verify(Type(expr) = \"Integrate\",True);\n\n// The following two used to get the interpreter into an infinite\n// loop. Fixed in version 1.0.51\n// FIXED!!! TestNonIntegrable(Integrate(x)(x*Ln(x)));\nTestNonIntegrable(Integrate(x)Sin(Exp(x)));\nVerify(Integrate(x) x^(-1),Ln(x)); // Well done Jonathan! ;-)\nVerify(Integrate(x) 1/x,Ln(x) );\n\nVerify(Integrate(x) 1/x^2, -x^(-1));\nVerify(Integrate(x) 6/x^2, (-6)*x^-1);\nVerify(Integrate(x) (x + 4)/(x + 3)^2, Ln(x+3)-(x+3)^(-1));\nVerify(Integrate(x) 1/(4 * x^2 + 1), ArcTan(2*x)/2);\nVerify(Integrate(x) (x-1)/(x^2-1), Ln(x+1));\n\nVerify(Integrate(x) x/(x^3+1), Ln(3*(1-x+x^2))/6+Sqrt(1/3)*ArcTan((4*x-2)/Sqrt(12))-Ln(3*(x+1))/3);\n\nVerify(Integrate(x) 3/Sin(x),3*Ln(1/Sin(x)-Cos(x)/Sin(x)) );\n\nVerify(Integrate(x) Ln(x), x*Ln(x)-x );\nVerify(Integrate(x) x^5000, x^5001/5001 );\nVerify(Integrate(x) 1/Tan(x), Ln(Sin(x)) );\nVerify(Integrate(x) 1/Cosh(x)^2, Tanh(x) );\nVerify(Integrate(x) 1/Sqrt(3-x^2), ArcSin(x/Sqrt(3)) );\nVerify(Integrate(x) Erf(x), x*Erf(x)+1/(Exp(x^2)*Sqrt(Pi)) );\nVerify(Integrate(x) Sin(x)/(2*y+4),(-Cos(x))/(2*(y+2)));\n\nVerify(Integrate(x)x^2*Exp(-x), (-2)*(x+1)*Exp(-x)-x^2*Exp(-x));\n\nTestNonIntegrable(Integrate(x) x^(1/x));\nTestNonIntegrable(Integrate(x) x^(Sin(x)));\nTestNonIntegrable(Integrate(x) Exp(x^2));\nTestNonIntegrable(Integrate(x) Sin(x^2));\n\nTestYacas(Integrate(x,0,A)Sin(x),1 - Cos(A));\nTestYacas(Integrate(x,0,A)x^2,(A^3)/3);\nTestYacas(Integrate(x,0,A)Sin(B*x),1/B-Cos(A*B)/B);\nTestYacas(Integrate(x,0,A)(x^2+2*x+1)/(x+1),(A^2)/2+A);\nTestYacas(Integrate(x,0,A)(x+1)/(x^2+2*x+1),Ln(A+1));\n\n// Check that threaded integration works\nVerify((Integrate(x,0,1) {1,x*x,1+x})-{1,1/3,3/2},{0,0,0});\n\n\n// Test MatchLinear: code heavily used with integration\nLocalSymbols(TestMatchLinearTrue,TestMatchLinearFalse) [\n\n  TestMatchLinearTrue(_var,_expr,_expected) <--\n  [\n    Local(a,b);\n    Verify(MatchLinear(var,expr),True);\n    a:=Simplify(Matched'a()-expected[1]);\n    b:=Simplify(Matched'b()-expected[2]);\n    `TestYacas(@a,0);\n    `TestYacas(@b,0);\n  ];\n  TestMatchLinearFalse(_var,_expr) <--\n  [\n    Local(a,b);\n    Verify(MatchLinear(var,expr),False);\n  ];\n\n  TestMatchLinearTrue(x,(R+1)*x+(T-1),{(R+1),(T-1)});\n  TestMatchLinearTrue(x,x+T,{1,T});\n  TestMatchLinearTrue(x,a*x+b,{a,b});\n  TestMatchLinearFalse(x,Sin(x)*x+(T-1));\n  TestMatchLinearFalse(x,x+Sin(x));\n\n];\n\nVerify(Integrate(x)1/(Sinh(x)*Tanh(x)), -1/Sinh(x));\n\nVerify(IntegrateRationalFunction(1,x,x), SumLog(t,1-t,0,x));\n"
  },
  {
    "path": "tests/io.yts",
    "content": "Testing(\"LISP parsing and printing\");\n\nVerify(FromString(\"(+ a b)\") LispRead(), a + b);\nVerify(FromString(\"(List (Sin x) (- (Cos x)))\") LispRead(), {Sin(x),-Cos(x)});\nVerify(FromString(ToString() FullForm({Sin(x),-Cos(x)}) ) LispRead(), {Sin(x),-Cos(x)});\n\nTesting(\"Patching\");\n\nVerify(PatchString(\"2 + 2 = <? Echo(2 + 2); ?>\"), \"2 + 2 = 4 \" : Nl());\n\nTesting(\"Error reporting\");\n\n// generate no errors\nVerify(IsError(), False);\nVerify(IsError(\"testing\"), False);\nVerify(Assert(\"testing\") 1=1, True);\nVerify(IsError(), False);\nVerify(IsError(\"testing\"), False);\nVerify(Assert(\"testing1234\", {1,2,3,4}) 1=1, True);\nVerify(IsError(), False);\nVerify(IsError(\"testing\"), False);\nVerify(IsError(\"testing1234\"), False);\n\nVerify(ToString()DumpErrors(), \"\");\n\n// generate some errors\nVerify(Assert(\"testing\") 1=0, False);\nVerify(IsError(), True);\nVerify(IsError(\"testing\"), True);\nVerify(IsError(\"testing1234\"), False);\nVerify(Assert(\"testing1234\", {1,2,3,4}) 1=0, False);\nVerify(IsError(), True);\nVerify(IsError(\"testing\"), True);\nVerify(IsError(\"testing1234\"), True);\n\n// report errors\nVerify(ToString()DumpErrors(), \"Error: testing\nError: testing1234: {1, 2, 3, 4}\n\");\n\n// no more errors now\nVerify(IsError(), False);\nVerify(IsError(\"testing\"), False);\nVerify(IsError(\"testing1234\"), False);\n\n// generate some more errors\nVerify(Assert(\"testing\") 1=0, False);\nVerify(Assert(\"testing1234\", {1,2,3,4}) 1=0, False);\nVerify(GetError(\"testing1234567\"), False);\n\n// handle errors\nVerify(GetError(\"testing\"), True);\nVerify(IsError(), True);\nVerify(IsError(\"testing\"), True);\nVerify(IsError(\"testing1234\"), True);\n\nVerify(ClearError(\"testing\"), True);\nVerify(IsError(), True);\nVerify(IsError(\"testing\"), False);\nVerify(IsError(\"testing1234\"), True);\n// no more \"testing\" error\nVerify(ClearError(\"testing\"), False);\nVerify(IsError(), True);\nVerify(IsError(\"testing\"), False);\nVerify(IsError(\"testing1234\"), True);\n\nVerify(GetError(\"testing1234\"), {1,2,3,4});\nVerify(IsError(), True);\nVerify(IsError(\"testing\"), False);\nVerify(IsError(\"testing1234\"), True);\n\nVerify(ClearError(\"testing1234\"), True);\nVerify(IsError(), False);\nVerify(IsError(\"testing\"), False);\nVerify(IsError(\"testing1234\"), False);\nVerify(ClearError(\"testing1234\"), False);\n"
  },
  {
    "path": "tests/journal.yts",
    "content": "\n/*\n * This file contains tests to check constructs used in the \n * tutorials and journal entries.\n */\n\nVerify(1+1,2);\nVerify(\"This text\",\"This text\");\nVerify(2+3,5);\nVerify(3*4,12);\nVerify(-(3*4),-12);\nVerify(2+3*4,14);\nVerify(6/3,2);\nVerify(1/3,1/3);\nVerify(IsNumber(N(1/3)),True);\nVerify(Sin(Pi),0);\nVerify(Min(5,1,3,-5,10),-5);\nVerify(Sqrt(2),Sqrt(2));\nVerify({1,2,3},{1,2,3});\nVerify({a,b,c}[2],b);\nVerify(\"abc\"[2],\"b\");\n\n\n// Etcetera.... PLEASECHECK TODO fill out this file\n\n\n\n\n/* From derivatives example, I am using ^0.5 there because of the\n * fact that Yacas replaces x^(1/2) with Sqrt(x).\n */\nVerify(x^(1/2),Sqrt(x));\n\n\n\n\n\n\n"
  },
  {
    "path": "tests/linalg.yts",
    "content": "\n\nTesting(\"LeviCivita\");\nVerify(LeviCivita({1,2,3}),1);\nVerify(LeviCivita({2,1,3}),-1);\nVerify(LeviCivita({1,1,3}),0);\n\nTesting(\"Kronecker delta\");\nVerify(KroneckerDelta(1,2),0);\nVerify(KroneckerDelta(3,3),1);\nVerify(KroneckerDelta(i,i),1);\nVerify(KroneckerDelta({2,2,2}),1);\nVerify(KroneckerDelta(1 .. 5),0);\nVerify(KroneckerDelta({i,i,k,j,l}),0);\nVerify(KroneckerDelta({2*i,2*i,2*i}),1);\n\nTesting(\"VectorProducts\");\n[\n  Local(l,m,n);\n  l:={1,0,0};\n  m:={0,1,0};\n  n:={0,0,1};\n\n  Verify(l X m, {0,0,1});\n  Verify(m X n, {1,0,0});\n  Verify(n X l, {0,1,0});\n  Verify(l X n, {0,-1,0});\n\n  Verify(l . m, 0);\n  Verify(m . n, 0);\n  Verify(n . l, 0);\n\n  Verify(l . l, 1);\n];\n\n\n[\n  Local(a,b);\n\n/* Strangeness: change variable below into a, and the crossproducts\n * later on fail!\n */\n  a:={1,2,3};\n  b:={3,1,5};\n  Verify( a . b , 20);\n  Verify(CrossProduct({1,2,3} , {4,2,5}) , {4,7,-6});\n];\nVerify(aa,Hold(aa));\n\n[\n  Local(a,b);\n  NextTest(\"Inproduct\");\n  a:={1,2,3};\n  b:={3,1,5};\n  Verify( a . b , 20);\n];\n\nVerify(CrossProduct({1,2,3} , {4,2,5}) , {4,7,-6});\nVerify({1,2,3} X {4,2,5},{4,7,-6});\nClear(a,b);\n\nNextTest(\"Identity matrices\");\nVerify(Identity(4),\n   { {1,  0,  0,  0} ,\n     {0,  1,  0,  0} ,\n     {0,  0,  1,  0} ,\n     {0,  0,  0,  1} });\n\n\nNextTest(\"Check linear algebra\");\n/* Normalize */\nTesting(\"Normalize\");\nVerify(Normalize({3,4}),{3/5,4/5});\n/* DiagonalMatrix */\nTesting(\"DiagonalMatrix\");\nVerify(DiagonalMatrix({2,3,4}),{{2,0,0},{0,3,0},{0,0,4}});\n/* ZeroMatrix */\nTesting(\"ZeroMatrix\");\nVerify(ZeroMatrix(2,3),{{0,0,0},{0,0,0}});\n/* Transpose */\nTesting(\"Transpose\");\nVerify(Transpose({{a,b},{c,d}}),{{a,c},{b,d}});\n/* Determinant */\nTesting(\"Determinant\");\nVerify(Determinant({{2,3},{3,1}}),-7);\nVerify( Determinant(ToeplitzMatrix(1 .. 10)), -2816 );\n// check that Determinant gives correct symbolic result\nTestYacas(Determinant({{a,b},{c,d}}),a*d-b*c);\nTestYacas(Determinant({{a, b, c}, {d, e, f}, {g, h, i}}), a*e*i-a*f*h+c*d*h-b*d*i+b*f*g-c*e*g);\n\nTesting(\"Matrix product\");\nVerify({{a,b},{c,d}} * {{e,f},{g,h}}, {{a*e+b*g,a*f+b*h},{c*e+d*g,c*f+d*h}});\nVerify(TrapError({{a,b,x},{c,d,y}} * {{e,f},{g,h}}, True), True);\n\n[\n  Local(ll);\n  ll:={ {1,2,3},\n        {2,-1,4},\n        {3,4,3}\n      };\n  /* CoFactor */\n  Testing(\"CoFactor\");\n  Verify(N(CoFactor(ll,1,2)),6);\n  /* Minor */\n  Testing(\"Minor\");\n  Verify(N(Minor(ll,1,2)),-6);\n  /* Inverse */\n  Testing(\"Inverse\");\n  Verify(Inverse(ll)*ll,Identity(3));\n  Verify(Inverse({{1,0},{2,3}})*{{1,0},{2,3}}, Identity(2));\n  Verify(Inverse({{1,2},{0,3}})*{{1,2},{0,3}}, Identity(2));\n  Verify(Inverse({{0,-10,10},{8,0,0},{0,6,6}}) * {{0,-10,10},{8,0,0},{0,6,6}}, Identity(3));\n  /* SolveMatrix */\n  Testing(\"SolveMatrix\");\n  Verify(ll*SolveMatrix(ll,{1,2,3}),{1,2,3});\n  /* Trace */\n  Testing(\"Trace\");\n  Verify(Trace(ll),1-1+3);\n  /* IsVector */\n  Verify(IsList(ll),True);\n  Verify(IsList({1,2,3}),True);\n  /* IsMatrix */\n  Verify(IsMatrix(ll),True);\n  Clear(ll);\n];\n\n[\n  Local(A);\n  Verify( IsSymmetric(Identity(10)), True );\n  Verify( IsOrthogonal(2*Identity(10)), False );\n  A := {{1,2,2},{2,1,-2},{-2,2,-1}};\n  Verify( IsOrthogonal(A/3), True );\n  Verify( IsSymmetric(Identity(10)), True );\n  Verify( IsSymmetric({{1}}),True );\n  A := {{1,0,0,0,1},{0,2,0,0,0},{0,0,3,0,0},{0,0,0,4,0},{1,0,0,0,5}};\n  Verify( IsSymmetric(A),True );\n  A := {{0,2,0,0,1},{0,0,3,0,0},{0,0,0,4,0},{1,0,0,0,5}};\n  Verify( IsSymmetric(A),False);\n  A := {{0,-1},{1,0}};\n  Verify( IsSkewSymmetric(A), True );\n  Verify( IsSkewSymmetric(Identity(10)), False );\n  Verify( IsSkewSymmetric(ZeroMatrix(10,10)), True );\n  Verify( IsIdempotent(Identity(20)), True );\n  Verify( IsIdempotent(ZeroMatrix(10,10)), True );\n];\n\nVerify( VandermondeMatrix({1,2,3,4}),{{1,1,1,1},{1,2,3,4},{1,4,9,16},{1,8,27,64}});\n\nVerify( JacobianMatrix( {x^4*y,Cos(y)}, { x, y}), {{4*x^3*y,x^4},{0,-Sin(y)}} );\n\nVerify( WronskianMatrix( {Sin(x),Cos(x)}, x) , {{Sin(x),Cos(x)},{Cos(x),-Sin(x)}} );\n\nVerify( Determinant(HilbertMatrix(5)), 1/266716800000 );\n\nVerify( HilbertMatrix(6)*HilbertInverseMatrix(6), Identity(6) );\n\nVerify( FrobeniusNorm({{1,2},{3,4}}), Sqrt(30) );\n\nVerify( Norm({1,2,3}), Sqrt(14) );\n\nVerify( OrthogonalBasis({{1,1,0},{2,0,1},{2,2,1}}) , {{1,1,0},{1,-1,1},{-1/3,1/3,2/3}} );\nVerify( OrthogonalBasis({{1,0,1,0},{1,1,1,0},{0,1,0,1}}), {{1,0,1,0},{0,1,0,0},{0,0,0,1}} );\nVerify( OrthonormalBasis({{1,0,1,0},{1,1,1,0},{0,1,0,1}}),\n\t{{Sqrt(1/2),0,Sqrt(1/2),0},{0,1,0,0},{0,0,0,1}} );\nVerify( OrthonormalBasis({{1,1,1},{0,1,1},{0,0,1}}),\n\t{{Sqrt(1/3),Sqrt(1/3),Sqrt(1/3)},\n\t{-Sqrt(2/3),Sqrt(1/6),Sqrt(1/6)},\n\t{0,-Sqrt(1/2),Sqrt(1/2)}} );\n\n[\n  Local(A,b);\n  A:={{1,2,4},{1,3,9},{1,4,16}};\n  b:={2,4,7};\n  Verify( MatrixSolve(A,b) , {1,(-1)/2,1/2} );\n  A:={{2,4,-2,-2},{1,2,4,-3},{-3,-3,8,-2},{-1,1,6,-3}};\n  b:={-4,5,7,7};\n  Verify( MatrixSolve(A,b), {1,2,3,4} );\n];\n\n[\n  Local(A,R);\n  A:={{4,-2,4,2},{-2,10,-2,-7},{4,-2,8,4},{2,-7,4,7}};\n  R:=Cholesky(A);\n  Verify( R, {{2,-1,2,1},{0,3,0,-2},{0,0,2,1},{0,0,0,1}} );\n  Verify( A, Transpose(R)*R );\n];\n\n[\n  Local(A,L,U);\n  A:={{2,1,1},{2,2,-1},{4,-1,6}};\n  {L,U} := LU(A);\n  Verify( L*U, A );\n];\n\nVerify(HalfVectorize({{1,2,3},{2,4,5},{3,5,6}}), {1,2,3,4,5,6});"
  },
  {
    "path": "tests/lists.yts",
    "content": "\nVerify(Intersection({aa,b,c},{b,c,d}),{b,c});\nVerify(Union({aa,b,c},{b,c,d}),{aa,b,c,d});\nVerify(Difference({aa,b,c},{b,c,d}),{aa});\n\nNextTest(\"VarList\");\nVerify(VarList(x^2+y^3) , {x , y});\nVerify(List(1,2,3),{1 , 2 , 3});\n\nTesting(\"BubbleSort\");\nVerify(BubbleSort({},\"<\"),{});\nVerify(BubbleSort({2,3,1},\"<\"),{1,2,3});\nVerify(BubbleSort({2,3,1},\">\"),{3,2,1});\n\nTesting(\"HeapSort\");\nVerify(HeapSort({},\"<\"),{});\nVerify(HeapSort({2,3,1},\"<\"),{1,2,3});\nVerify(HeapSort({2,1,3},\">\"),{3,2,1});\nVerify(HeapSort({7,3,1,2,6},\"<\"),{1,2,3,6,7});\nVerify(HeapSort({6,7,1,3,2},\">\"),{7,6,3,2,1});\n\nVerify(Type(Cos(x)),\"Cos\");\nVerify(NrArgs(Cos(x)),1);\nVerify(Contains({a,b,c},b),True);\nVerify(Contains({a,b,c},d),False);\n\nVerify(Append({a,b,c},d),{a,b,c,d});\nVerify(RemoveDuplicates({a,b,b,c}),{a,b,c});\nVerify(Count({a,b,b,c},b),2);\nVerify(VarList(x*Cos(x)),{x});\n\n\n[\n  Local(l);\n  l:={1,2,3};\n  DestructiveDelete(l,1);\n  Verify(l,{2,3});\n  DestructiveInsert(l,1,1);\n  Verify(l,{1,2,3});\n  l[1] := 2;\n  Verify(l,{2,2,3});\n  l[1] := 1;\n  DestructiveDelete(l,3);\n  Verify(l,{1,2});\n  DestructiveInsert(l,3,3);\n  Verify(l,{1,2,3});\n  DestructiveDelete(FlatCopy(l),1);\n  Verify(l,{1,2,3});\n];\n\nVerify(Table(i!,i,1,4,1),{1,2,6,24});\nVerify(Permutations({a,b,c}),{{a,b,c},{a,c,b},{c,a,b},{b,a,c},{b,c,a},{c,b,a}});\n\nTesting(\"ListOperations\");\nVerify(Head({a,b,c}),a);\nVerify(Tail({a,b,c}),{b,c});\nVerify(DestructiveReverse({a,b,c}),{c,b,a});\nVerify(UnList({a,b,c}),a(b,c));\nVerify(Listify(a(b,c)),{a,b,c});\n\nVerify(Delete({a,b,c},2),{a,c});\nVerify(Insert({a,c},2,b),{a,b,c});\n\n[\n    Local(l);\n    l := FillList(FillList(0, 3), 2);\n    l[1][1] := 11;\n    Verify(l, {{11,0,0},{0,0,0}});\n    l := FillList(FillList(FillList(0, 3), 3), 3);\n    l[1][1][1] := 111;\n    Verify(l, {{{111,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0}}});\n];\n\nTesting(\"Length\");\nVerify(Length({a,b}),2);\nVerify(Length({}),0);\n\nTesting(\"Nth\");\nVerify(Nth({a,b},1),a);\nVerify({a,b,c}[2],b);\n\nTesting(\"Concat\");\nVerify(Concat({a,b},{c,d}),{a,b,c,d});\n//This is simply not true!!! Verify(Hold(Concat({a,b},{c,d})),Concat({a,b},{c,d}));\n\n\nTesting(\"Binary searching\");\nVerify(BSearch(100,{{n},n^2-15}), -1);\nVerify(BSearch(100,{{n},n^2-16}), 4);\nVerify(BSearch(100,{{n},n^2-100002}), -1);\nVerify(BSearch(100,{{n},n^2-0}), -1);\nVerify(FindIsq(100,{{n},n^2-15}), 3);\nVerify(FindIsq(100,{{n},n^2-16}), 4);\nVerify(FindIsq(100,{{n},n^2-100002}), 100);\nVerify(FindIsq(100,{{n},n^2-0}), 1);\n\nVerify(Difference(FuncList(a*b/c*d), {*,/}), {});\nVerify(Difference(FuncListArith(0*x*Sin(a/b)*Ln(Cos(y-z)+Sin(a))), {*,Ln,Sin}), {});\nVerify(Difference(VarListArith(x+a*y^2-1), {x,a,y^2}), {});\n\nVerify(Difference(FuncList(IsCFormable([i:=0;While(i<10)[i++; a--; a:=a+i; {};];])), {IsCFormable,Prog,:=,While,<,++,--,Atom(\"+\"),List}), {});\nVerify(FuncList({1,2,3}),{List});\nVerify(FuncList({{},{}}),{List});\nVerify(FuncList({}),{List});\n\nTesting(\"AssocDelete\");\n[\n  Local(hash);\n  hash:={{\"A\",1},{\"A\",2},{\"B\",3},{\"B\",4}};\n  AssocDelete(hash,{\"B\",3});\n  Verify(hash, {{\"A\",1},{\"A\",2},{\"B\",4}});\n  Verify(AssocDelete(hash,\"A\"),True);\n  Verify(hash, {{\"A\",2},{\"B\",4}});\n  Verify(AssocDelete(hash,\"C\"),False);\n  Verify(hash, {{\"A\",2},{\"B\",4}});\n  AssocDelete(hash,\"A\");\n  Verify(hash, {{\"B\",4}});\n  AssocDelete(hash, {\"A\",2});\n  AssocDelete(hash,\"A\");\n  Verify(hash, {{\"B\",4}});\n  Verify(AssocDelete(hash,\"B\"),True);\n  Verify(hash, {});\n  Verify(AssocDelete(hash,\"A\"),False);\n  Verify(hash, {});\n];\nTesting(\"-- Arithmetic Operations\");\nVerify(1+{3,4},{4,5});\nVerify({3,4}+1,{4,5});\nVerify({1}+{3,4},Hold({1}+{3,4}));\nVerify({3,4}+{1},Hold({3,4}+{1}));\nVerify({1,2}+{3,4},{4,6});\nVerify(1-{3,4},{-2,-3});\nVerify({3,4}-1,{2,3});\nVerify({1}-{3,4},Hold({1}-{3,4}));\nVerify({3,4}-{1},Hold({3,4}-{1}));\nVerify({1,2}-{3,4},{-2,-2});\nVerify(2*{3,4},{6,8});\nVerify({3,4}*2,{6,8});\nVerify({2}*{3,4},Hold({2}*{3,4}));\nVerify({3,4}*{2},Hold({3,4}*{2}));\nVerify({1,2}*{3,4},{3,8});\nVerify(2/{3,4},{2/3,1/2});\nVerify({3,4}/2,{3/2,2});\nVerify({2}/{3,4},Hold({2}/{3,4}));\nVerify({3,4}/{2},Hold({3,4}/{2}));\nVerify({1,2}/{3,4},{1/3,1/2});\nVerify(2^{3,4},{8,16});\nVerify({3,4}^2,{9,16});\nVerify({2}^{3,4},Hold({2}^{3,4}));\nVerify({3,4}^{2},Hold({3,4}^{2}));\nVerify({1,2}^{3,4},{1,16});\n\n// non-destructive Reverse operation\n[\n  Local(lst,revlst);\n  lst:={a,b,c,13,19};\n  revlst:=Reverse(lst);\n  Verify(revlst,{19,13,c,b,a});\n  Verify(lst,{a,b,c,13,19});\n];\nVerify(IsBound(lst),False);\nVerify(IsBound(revlst),False);\n\n"
  },
  {
    "path": "tests/logic_simplify_test.yts",
    "content": "\n//Use(\"logic.ys\");\n\n\nNextTest(\"CNF\");\n\n\n/*\n    The main point is that CNF should return an answer in CNF, that is,\n    as a conjunction of disjuncts.\n*/\nVerify(CNF(A And A),      A);\nVerify(CNF(A And True),   A);\n\n\nVerify(CNF(A And False),  False);\nVerify(CNF(A Or  True),   True);\nVerify(CNF(A Or  False),  A);\nVerify(CNF(A Or  Not A),  True);\nVerify(CNF(A And Not A),  False);\n\n\nVerify(CNF((A And B) Or (A And B)),             A And B);\nVerify(CNF(A Or (A And B)),                     A And(A Or B));\nVerify(CNF((A => B) And A),                     (Not A Or B)And A);\nVerify(CNF((A And B) And A),                    (A And B) And A);\nVerify(CNF(Not (A And B) And A),                (Not A Or Not B) And A);\n\nVerify(CanProve((A Or B) And Not A),            B And Not A);\nVerify(CanProve((A Or B) And (Not A Or C)),     (A Or B) And (C Or Not A));\nVerify(CanProve((B Or A) And (Not A Or C)),     (A Or B) And (C Or Not A));\nVerify(CanProve( A And (A Or B Or C)),       A);\nVerify(CanProve( A And (Not A Or B Or C)),  A And (B Or C));\n\n// this is a test of contradication, A==3 should kick A==2 out as they're contradictory\nVerify(CanProve( A==3 And (A==2 Or B Or C)),  A-3==0 And (B Or C));\n//TODO Verify(CanProve( A==3 And (A<2  Or B Or C)),  A-3==0 And (B Or C));\n//TODO Verify(CanProve( A==3 And (A>2  Or B Or C)),  (A-3==0) And (((A-2) > 0) Or B Or C));\n\nVerify(CanProve(Not(Not (p_2-NULL==0))Or Not(p_2-NULL==0)), True);\n\n\n\n\nLogicTest({A},A And A,      A);\nLogicTest({A},A And True,   A);\nLogicTest({A},A And False,  False);\nLogicTest({A},A Or  True,   True);\nLogicTest({A},A Or  False,  A);\nLogicTest({A},A Or  Not A,  True);\nLogicTest({A},A And Not A,  False);\nLogicTest({A,B},(A And B) Or (A And B),             A And B);\nLogicTest({A,B},A Or (A And B),                     A And(A Or B));\nLogicTest({A,B},(A And B) And A,                    (A And B) And A);\nLogicTest({A,B},Not (A And B) And A,                (Not A Or Not B) And A);\nLogicTest({A,B},(A Or B) And Not A,            B And Not A);\nLogicTest({A,B,C},(A Or B) And (Not A Or C),     (A Or B) And (C Or Not A));\nLogicTest({A,B,C},(B Or A) And (Not A Or C),     (A Or B) And (C Or Not A));\nLogicTest({A,B,C}, A And (A Or B Or C),       A);\nLogicTest({A,B,C}, A And (Not A Or B Or C),  A And (B Or C));\n\n\n\n\nLogicTest({A},CNF(A And A),      A);\nLogicTest({A},CNF(A And True),   A);\n\n\nLogicTest({A},CNF(A And False),  False);\nLogicTest({A},CNF(A Or  True),   True);\nLogicTest({A},CNF(A Or  False),  A);\nLogicTest({A},CNF(A Or  Not A),  True);\nLogicTest({A},CNF(A And Not A),  False);\n\n\nLogicTest({A,B},CNF((A And B) Or (A And B)),             A And B);\nLogicTest({A,B},CNF(A Or (A And B)),                     A And(A Or B));\nLogicTest({A,B},CNF((A => B) And A),                     (Not A Or B)And A);\nLogicTest({A,B},CNF((A And B) And A),                    (A And B) And A);\nLogicTest({A,B},CNF(Not (A And B) And A),                (Not A Or Not B) And A);\n\nLogicTest({A,B},CanProve((A Or B) And Not A),            B And Not A);\nLogicTest({A,B,C},CanProve((A Or B) And (Not A Or C)),     (A Or B) And (C Or Not A));\nLogicTest({A,B,C},CanProve((B Or A) And (Not A Or C)),     (A Or B) And (C Or Not A));\nLogicTest({A,B,C},CanProve( A And (A Or B Or C)),       A);\nLogicTest({A,B,C},CanProve( A And (Not A Or B Or C)),  A And (B Or C));\n\n\n"
  },
  {
    "path": "tests/macro.yts",
    "content": "\n[\n  Local(a,b,c,d);\n  DefMacroRuleBase(foo,{a,b});\n\n  // Simple check\n  foo(_c,_d) <-- {@c,@d};\n  Verify(foo(2,3),Hold({2,3}));\n\n  Macro(\"foo\",{a}) {@a,a};\n  a:=A; \n  Verify(foo(B),{B,A});\n  Retract(foo,1);\n  Retract(foo,2);\n  Verify(foo(2,3),foo(2,3));\n  Verify(foo(B),foo(B));\n];\n\n[\n  Local(a,i,tot);\n  a:=100;\n  Retract(forloop,4);\n  Macro(forloop,{init,pred,inc,body}) \n  [\n    @init;\n    While(@pred)\n    [\n      @body;\n      @inc;\n    ];\n    True;\n  ];\n  tot:=0;\n  forloop(i:=1,i<=10,i++,tot:=tot+a*i);\n  Verify(i,11);\n  Verify(tot,5500);\n];\n\n[\n  Macro(\"bar\",{list,...}) Length(@list);\n  Verify(bar(a,b,list,bar,list),5);\n];\n\n[\n  Local(x,y,z);\n  y:=x;\n  Verify(`{@x,@y},{x,x});\n  z:=u;\n  y:={@z,@z};\n  Verify(`{@x,@y},{x,{@z,@z}});\n  Verify(`{@x,`(@y)},{x,{@u,@u}});\n  y:=Hold(`{@z,@z});\n\n  Verify(`{@x,@y},{x,{u,u}});\n  Verify(`{@x,`(@y)},{x,{u,u}});\n];\n\n// check that a macro can reach a local from the calling environment.\n[\n  Macro(foo,{x}) a*(@x);\n  Function(bar,{x})\n  [\n    Local(a);\n    a:=2;\n    foo(x);\n  ];\n  Verify(bar(3),6);\n];\n\n//check that with nested backquotes expansion only expands the top-level expression\n[\n  Local(a,b);\n  a:=2;\n  b:=3;\n  Verify(\n  `[\n     Local(c);\n     c:=@a+@b;\n     `((@c)*(@c));\n  ],25);\n];\n\n\n"
  },
  {
    "path": "tests/matrixpower.yts",
    "content": "//////\n// test for MatrixPower (dr)\n//////\n\nTesting(\"-- MatrixPower\");\n\n//Verify(MatrixPower(,),);\nVerify(MatrixPower(a,0),Hold(MatrixPower(a,0)));\nVerify(MatrixPower(a,n),Hold(MatrixPower(a,n)));\nVerify(MatrixPower({a},0),Hold(MatrixPower({a},0)));\nVerify(MatrixPower({a},n),Hold(MatrixPower({a},n)));\nVerify(MatrixPower({{a}},0),{{1}});\nVerify(MatrixPower({{a}},1),{{a}});\nVerify(MatrixPower({{a}},-1),{{1/a}});\nVerify(MatrixPower({{a}},3/5),Hold(MatrixPower({{a}},3/5)));\nVerify(MatrixPower({{a}},10),{{a^10}});\nVerify(MatrixPower({{a}},-10),{{1/a^10}});\nVerify(MatrixPower({{a}},n),Hold(MatrixPower({{a}},n)));\n\nVerify(MatrixPower({{1,2},{3,4}},0),{{1,0},{0,1}});\nVerify(MatrixPower({{1,2},{3,4}},1),{{1,2},{3,4}});\nVerify(MatrixPower({{1,2},{3,4}},2),{{7,10},{15,22}});\nVerify(MatrixPower({{1,2},{3,4}},3),{{37,54},{81,118}});\nVerify(MatrixPower({{1,2},{3,4}},4),{{199,290},{435,634}});\nVerify(MatrixPower({{1,2},{3,4}},5),{{1069,1558},{2337,3406}});\nVerify(MatrixPower({{1,2},{3,4}},7),{{30853,44966},{67449,98302}});\nVerify(MatrixPower({{1,2},{3,4}},13),{{741736909,1081027478},{1621541217,2363278126}});\n\nVerify(MatrixPower({{1,2},{3,4}},-1),{{-2,1},{3/2,-1/2}});\nVerify(MatrixPower({{1,2},{3,4}},-2),{{11/2,-5/2},{-15/4,7/4}});\nVerify(MatrixPower({{1,2},{3,4}},-3),{{-59/4,27/4},{81/8,-37/8}});\nVerify(MatrixPower({{1,2},{3,4}},-4),{{317/8,-145/8},{-435/16,199/16}});\nVerify(MatrixPower({{1,2},{3,4}},-5),{{-1703/16,779/16},{2337/32,-1069/32}});\n//////\n//////\n"
  },
  {
    "path": "tests/multivar.yts",
    "content": "\nNextTest(\"Test arithmetic\");\n\nTestYacas(NormalForm(MM((x+y)^5)),y^5+5*x*y^4+10*x^2*y^3+10*x^3*y^2+5*x^4*y+x^5);\n\n"
  },
  {
    "path": "tests/newly.yts",
    "content": "Verify(PolyPseudoDivide(3*x^3+x^2+x+5, 5*x^2-3*x+1, x), {15*x+14,52*x+111});\nVerify(HermiteReduce(x^7-24*x^4-4*x^2+8*x-8, x^8+6*x^6+12*x^4+8*x^2, x), {(8*x^2+4)/(x^5+4*x^3+4*x)+3/(x^2+2),1/x});\nVerify(HermiteReduce(36, x^5-2*x^4-2*x^3+4*x^2+x-2, x), {(12*x+6)/(x^2-1),12/(x^2-x-2)});\nVerify(SubResultant(x^2+1, x^2-1, x), {4,{x^2+1,x^2-1,-2,0}});\nVerify(SubResultant(3*t*x^2-t^3-4, x^2+t^3*x-9, x), {(-3)*t^10-12*t^7+t^6-54*t^4+8*t^3+729*t^2-216*t+16,{3*t*x^2-t^3-4,x^2+t^3*x-9,3*t^4*x+t^3-27*t+4,(-3)*t^10-12*t^7+t^6-54*t^4+8*t^3+729*t^2-216*t+16,0}});\nVerify(IntRationalLogPart(x^4-3*x^2+6,x^6-5*x^4+5*x^2+4, x), SumLog(t,4*t^2+1,0,(-214)*t*x^3+107*x^2+642*t*x-214));\nVerify(IntegrateRationalFunction(x^4-3*x^2+6,x^6-5*x^4+5*x^2+4, x), SumLog(t,4*t^2+1,0,(-214)*t*x^3+107*x^2+642*t*x-214));\n"
  },
  {
    "path": "tests/nthroot.yts",
    "content": "//////\n// $Id: nthroot.yts,v 1.3 2006-03-26 12:49:15 ayalpinkus Exp $\n// tests for NthRoot\n//////\n\nTesting(\"-- NthRoot\");\n\n// you need to use UnList for this one as -1 is actually -(1), eg. a unary function (minus)\n// applied to a positive integer (1). UnList evaluates its arguments, resulting in a negative\n// integer (-1).\nVerify(NthRoot(-1,2),UnList({NthRoot,-1,2}));\n\nVerify(NthRoot(2,1),Hold(NthRoot(2,1)));\nVerify(NthRoot(2,2),{1,2});\nVerify(NthRoot(12,2),{2,3});\nVerify(NthRoot(12,3),{1,12});\nVerify(NthRoot(27,3),{3,1});\nVerify(NthRoot(17*13,2),{1,17*13});\nVerify(NthRoot(17*17*13,2),{17,13});\nVerify(NthRoot(17*17*17*13,2),{17,17*13});\nVerify(NthRoot(17*17*17*13,3),{17,13});\nVerify(NthRoot(17*17*17*17*13*13,2),{17*17*13,1});\nVerify(NthRoot(17*17*17*17*13*13,3),{17,17*13*13});\nVerify(NthRoot(17*17*17*17*13*13,4),{17,13*13});\nVerify(NthRoot(17*17*17*17*13*13,5),{1,17*17*17*17*13*13});\n\n//////\n//////"
  },
  {
    "path": "tests/numbers.yts",
    "content": "Verify( CatalanNumber(6), 132 );\nVerify( CatalanNumber(10), 16796 );\n\nTesting(\"Integer logarithms and roots\");\n\nVerify(IntLog(23^45, 67), 33);\n\nVerify(IntLog(1, 67), 0);\nVerify(IntLog(2, 67), 0);\nVerify(IntLog(0, 67), 0);\nVerify(IntLog(1, 1), Undefined);\nVerify(IntLog(2, 1), Undefined);\nVerify(IntLog(256^8, 4), 32);\nVerify(IntLog(256^8-1, 4), 31);\nVerify(IntNthRoot(65537^33, 11), 281487861809153);\n\nTesting(\"Factorial\");\nVerify(261! - 261*260!, 0);\nVerify(300! / 250!, 251***300);\n\nVerify(Repunit(3), 111 );\nVerify(HarmonicNumber(5), 137/60 );\n\nVerify( Subfactorial(0), 1 );\nVerify( Subfactorial(21), 18795307255050944540 );\n\nVerify( Divisors(180), 18 );\n\n\nVerify( IsAmicablePair(200958394875 ,209194708485 ), True );\nVerify( IsAmicablePair(220,284),True );\n\nVerify( IsComposite(100), True );\nVerify( IsComposite(1), False );\nVerify( IsComposite(37), False );\n\nVerify( IsTwinPrime(71), True );\nVerify( IsTwinPrime(1), False );\nVerify( IsTwinPrime(22), False );\n\nVerify( DigitalRoot(18), 9 );\nVerify( DigitalRoot(15), 6 );\n\nVerify( IsIrregularPrime(37), True );\nVerify( IsIrregularPrime(59), True );\nVerify( IsIrregularPrime(1), False );\nVerify( IsIrregularPrime(11), False );\n\nVerify( Gcd( 324 + 1608*I, -11800 + 7900*I ),Complex(-52,16) );\n// I changed from Complex(-4,4) to Complex(4,4) as the GaussianGcd algorithm suddenly returned this instead.\n// However, as it turned out it was a bug in MathFloor, introduced when\n// we moved to the new number classes (so the numbers did not get converted\n// to string and back any more). The number got prematurely truncated with\n// this test case (regression test added to regress.yts also).\nVerify( Gcd( 7300 + 12*I, 2700 + 100*I), Complex(-4,4) );\n\nVerifyGaussianGcd(x,y):=\n[\n  Local(gcd);\n  gcd:=Gcd(x,y);\n//  Echo(x/gcd);\n//  Echo(y/gcd);\n  Verify(IsGaussianInteger(x/gcd) And IsGaussianInteger(y/gcd),True);\n];\nVerifyGaussianGcd(324 + 1608*I, -11800 + 7900*I);\nVerifyGaussianGcd(7300 + 12*I, 2700 + 100*I);\nVerifyGaussianGcd(120-I*200,-336+50*I);\n//TODO we can expand this with randomized tests\n\nVerify( Lcm({7,11,13,17}), 7*11*13*17 );\nVerify( Lcm(-8, 20), Lcm(8, 20));\nVerify( IsCoprime(11,13), True );\nVerify( IsCoprime(1 .. 10), False );\nVerify( IsCoprime({9,40}), True );\n\nVerify( IsCarmichaelNumber( {561,1105,1729,2465,2821,6601,8911} ),{True,True,True,True,True,True,True} );\nVerify( IsCarmichaelNumber( {0,1,2,1727,2463,2823,6603} ),{False,False,False,False,False,False,False} );\n\nVerify(IsSmallPrime(137),True);\nVerify(IsSmallPrime(138),False);\nVerify(IsSmallPrime(65537),True);\nVerify(IsSmallPrime(65539),False);\nVerify(IsPrime(65539),True);\nVerify(RabinMiller(1037),False);\nVerify(RabinMiller(1038),False);\nVerify(RabinMiller(1039),True);\nVerify(NextPrime(65537), 65539);\nVerify(NextPrime(97192831),97192841);\nVerify(NextPrime(14987234876128361),14987234876128369);\nVerify(IsPrime(0),False);\nVerify(IsPrime(-1),False);\nVerify(IsPrime(1),False);\nVerify(IsPrime(2),True);\nVerify(IsPrime(3),True);\nVerify(IsPrime(4),False);\nVerify(IsPrime(5),True);\nVerify(IsPrime(6),False);\nVerify(IsPrime(7),True);\nVerify(IsPrime(-60000000000),False);\nVerify(IsPrime(6.1),False);\n\n\nTesting(\"Random numbers\");\nLocal(r1, r2, r3, x1, x2, x3);\n\nr1:=RngCreate();        // create a default RNG object, return structure\nr2:=RngCreate(12345);   // create RNG object with given seed\nRandomSeed(12345);      // initialize the global RNG with the same seed\nr3:=RngCreate(seed=12345, engine=advanced, dist=gauss); // test advanced options\nRng(r1);\nRng(r1);\nx1:=Rng(r2);\nVerify(x1, Random());\nx2:=Rng(r2);\nx3:=Rng(r3);\n\nVerify(Rng(r3)=x3, False);\nVerify(x1=x2, False);\nRngSeed(r2, 12345);\nVerify(Rng(r2), x1);    // reproducible number\nVerify(Rng(r2), x2);    // reproducible number\nRngSeed(r3, 12345);\nVerify(Rng(r3), x3);    // reproducible number\nVerify(PartitionsP(1),1);\nVerify(PartitionsP(2),2);\nVerify(PartitionsP(3),3);\nVerify(PartitionsP(4),5);\nVerify(PartitionsP(13),101);\n// This takes about 18 seconds, useful for benchmarking\n//Verify( PartitionsP(4096), 6927233917602120527467409170319882882996950147283323368445315320451 );\n\nVerify(Euler(16),19391512145);\nVerify(EulerArray(8), {1,0,-1,0,5,0,-61,0,1385});\n\nVerify(JacobiSymbol(165,1), 1);\nVerify(JacobiSymbol(1,3), 1);\nVerify(JacobiSymbol(1,13), 1);\nVerify(JacobiSymbol(2,15), 1);\nVerify(JacobiSymbol(3,15), 0);\nVerify(JacobiSymbol(7,15), -1);\nVerify(JacobiSymbol(3,7), -1);\nVerify(JacobiSymbol(0,3), 0);\nVerify(JacobiSymbol(0,1), 1);\nVerify(JacobiSymbol(1323132412,31312317), -1);\nVerify(JacobiSymbol(57173571,1976575123), 1);\nVerify(JacobiSymbol(-3,5), -1);\n"
  },
  {
    "path": "tests/numerics.yts",
    "content": "/* Numerical testers - all confirmed with Matlab 6r12.0 */\n\nBuiltin'Precision'Set(10);\n\nNumericEqual(N(Sqrt(2),5), 1.41421,5);      // no idea where the problem is\nNumericEqual(N(N(1+Pi,20)-Pi,20),1,20);     // \"N\" should have \"HoldArg\" in some way, so inner \"N\" is evaluated with outer precision 20\n\n/* Got the first digits of Pi from the following page:\n   http://www.cecm.sfu.ca/projects/ISC/dataB/isc/C/pi10000.txt\n  Just checking that Yacas agrees.\n*/\nNumericEqual(N(Pi,70),3.1415926535897932384626433832795028841971693993751058209749445923078164062862,70);\n\nNumericEqual( N(Sec(2),9), -2.402997962, 9);\nNumericEqual( N(Csc(2),9),  1.09975017,9);\nNumericEqual( N(Cot(2),9), -0.457657554, 9);\n\nIf(Interpreter() = \"yacas\",\n    NumericEqual( N(Sinh(2),10), 3.6268604078,10) // matter of discussion whether rounding should be to nearest\n);\n\nNumericEqual( N(ArcSin(2), 9), Complex(1.570796327,1.316957897),9);\nNumericEqual( N(ArcCos(2),9), Complex(0,-1.316957897),9);\n\nIf(Interpreter() = \"yacas\",\n    NumericEqual( N(ArcTan(2*I), 12), N(Complex(1.57079632679,0.54930614433),12),11) // calculating to precision+1 because RoundTo rounds... cluttering the last digit with round-off\n);\n\nNumericEqual( N(ArcSinh(2), 9), 1.443635475,9);\nNumericEqual( N(ArcCosh(2), 9), 1.316957897,9);\n\nIf(Interpreter() = \"yacas\",\n    NumericEqual( N(ArcCosh(-2), 8), Complex(-1.3169579,3.14159265),8)\n);\n\nIf(Interpreter() = \"yacas\",\n    NumericEqual( N(ArcTanh(2), 9), Complex(0.549306144,1.570796327),9)\n);\n\n/* Numerical tests - all confirmed with Maple */\nBuiltin'Precision'Set(50);\n\nNumericEqual(\nRoundTo(N(Pi), 50)\n, 3.14159265358979323846264338327950288419716939937511\n, 50);\n\nNumericEqual(\nRoundTo(N(Sin(2.0)), 49)\n, 0.9092974268256816953960198659117448427022549714479\n,49);\n\nNumericEqual(\nRoundTo(N(Sin(2.0)), 50)\n, 0.90929742682568169539601986591174484270225497144789\n,50);\n\nNumericEqual(\nRoundTo(N(Sin(2.0)), 51)\n, 0.90929742682568169539601986591174484270225497144789\n,51);\n\nNumericEqual(\nRoundTo(N(Cos(20.0)), 49)\n, 0.4080820618133919860622678609276449570992995103163\n, 49);\n\nNumericEqual(\nRoundTo(N(Tan(20.0)), 49)\n, 2.2371609442247422652871732477303491783724839749188\n, 49);\n\nNumericEqual(\nRoundTo(N(Exp(10.32),54), 54)\n, 30333.2575962246035600343483350109621778376486335450125\n,48);   // This one rounds off the wrong direction (125 rounded to 12 iso 13). But alas, change was needed because new interpretation means the required precision was actually higher (not number of decimals after point, but total number of digits were meant).\n\nNumericEqual(\nRoundTo(N(Ln(10.32/4.07)), 49)\n, 0.93044076059891305468974486564632598071134270468\n, 49);\n\nNumericEqual(\nRoundTo(N(1.3^10.32), 48)\n, 14.99323664825717956473936947123246987802978985306\n, 48);\n\nNumericEqual(\nRoundTo(N(Sqrt(5.3),51), 51)\n, 2.302172886644267644194841586420201850185830282633675\n,51);  // increased to 51 digits so round-off is obviously downwards (previous rounding was defendably wrong)\n\n// this failed in gmp due to broken MathSqrt()\nNumericEqual(\nRoundTo(N(Sqrt(25.3)), 50)\n, 5.0299105359837166789719353820984438468186649281130\n,50);\n\n// this failed due to broken RoundTo()\nNumericEqual(\nRoundTo(MathPower(13, -23), 50)\n, 0.23949855470974885180294666343025235387321690490245e-25\n, 50);\n\nIf(Interpreter() = \"yacas\",\n    NumericEqual(\n    RoundTo([Local(x);x:=Newton(x*Exp(x)-4,x,1,10^(-49)); N(x*Exp(x));], 49)\n    , 4.\n    ,49)\n);\n\nVerify(Newton(x^2+1,x,1,0.1,-3,3), Fail);\nNumericEqual(Newton(x^2-1,x,1,0.1,-3,3), 1.,Builtin'Precision'Get());\n\nNumericEqual(\nRoundTo(N(ArcSin(0.32)), 49)\n, 0.3257294872946301593103199105324500784354180998123\n,49);\n\nNumericEqual(\nRoundTo(N(Sin(N(ArcSin(0.1234567)))), 49)\n, 0.1234567\n,49);\n\n/* ArcSin(x) for x close to 1 */\n\nNumericEqual(\nRoundTo(N( (1-Sin(N(ArcSin(1-10^(-25)))))*10^25), 25)\n, 1.\n, 25);\n\nNumericEqual(\nN(ArcSin(N(Sin(1.234567),50)),50)\n, N(1.234567,50)\n, 49);  // calculating to precision+1 because RoundTo rounds... cluttering the last digit with round-off\n\nNumericEqual(\nRoundTo(N(ArcCos(0.32)), 49)\n, 1.2450668395002664599210017811073013636631665998753\n, 49);\n\nNumericEqual(\nRoundTo(N(ArcTan(0.32)), 49)\n, 0.3097029445424561999173808103924156700884366304804\n, 49);\n\nNumericEqual(\nRoundTo(N(Cos(N(ArcCos(0.1234567)))), 49)\n, 0.1234567\n, 49);\n\nNumericEqual(\nRoundTo(N(ArcCos(N(Cos(1.234567)))), 49)\n, 1.234567\n, 49);\n\nNumericEqual(\nRoundTo(N(Tan(N(ArcTan(20)))), 46)  // large roundoff error on Tan() calculation due to subtraction from Pi/2 -- unavoidable loss of precision\n, 20.\n, 46);\n//KnownFailure(\nNumericEqual(\nRoundTo(N(Tan(N(ArcTan(500000)))), 38)\n, 500000.\n//)\n, 38);\n\nBuiltin'Precision'Set(60);  // obviously, 50 is not enough for the following\n//KnownFailure(\nNumericEqual(\nRoundTo(N((Pi/2-ArcTan(N(Tan(N(Pi/2)-10^(-24)))))*10^24 ), 25)\n, 1.\n//)\n, 25);\n\n/// special functions\nBuiltin'Precision'Set(20);  // let's be gentle\n\nTestYacas(\nGamma(10.5)\n, (654729075*Sqrt(Pi))/1024\n);\n\nTestYacas(\nGamma(9/2)\n, (105*Sqrt(Pi))/16\n);\n\nTestYacas(\nGamma(-10.5)\n, (-2048*Sqrt(Pi))/13749310575\n);\n\nTestYacas(\nGamma(-7/2)\n, (16*Sqrt(Pi))/105\n);\n\nNumericEqual(RoundTo(N( Internal'GammaNum(10.5) ), 13), 1133278.3889487855673, 13);\nNumericEqual(RoundTo(N( Internal'GammaNum(-11.5) ), 20), 0.00000002295758104824, 20);\nNumericEqual(RoundTo(N( Internal'GammaNum(-12.5) ), 20), -0.00000000183660648386, 20);\n\n// Check for one example that N(Gamma(x)) returns the same as Internal'GammaNum\nNumericEqual(RoundTo(N( Gamma(10.5) ), 13), 1133278.3889487855673, 13);\n\n\n\nNumericEqual(   // lost 2 digits b/c of imprecise arithmetic\nRoundTo(N( Zeta(-11.5) ), 18)\n, 0.020396978715942792\n,18);\n\nTestYacas(\nZeta(40)\n, (261082718496449122051*Pi^40)/20080431172289638826798401128390556640625\n);\n\nTestYacas(\nZeta(-11)\n, 691/32760\n);\n\nTestYacas(\nZeta(-12)\n, 0\n);\n\nIf(Interpreter() = \"yacas\",\n    NumericEqual(\n    RoundTo(N(Zeta(40)), 19)\n    , 1.0000000000009094948\n    ,19)\n);\n\nNumericEqual(\nRoundTo(N(Zeta(1.5)), 19)\n, 2.6123753486854883433\n,19);\n\n// test correctness of Zeta(3)\nNumericEqual(\nRoundTo(Internal'ZetaNum(3)-N(Zeta(3)), 20)\n, 0\n,20);\n\nTestYacas(\nBernoulli(40)\n, -261082718496449122051/13530\n);\n\nVerify(\nContFracList(355/113)\n, {3,7,16}\n);\n\nVerify(\nContFracList(-24, 4)\n, {-24}\n);\n\nVerify(\nContFracList(-355/113)\n, {-4,1,6,16}\n);\n\nBuiltin'Precision'Set(7);\n\nVerify(\nGuessRational(N(Pi))\n, 355/113\n);\n\n/*\n  For the NearRational test, perhaps better would be a real test that\n  checks that the result is correct up to the required number of digits\n  accuracy.\n*/\nBuiltin'Precision'Set(10);\nVerify(\nNearRational(N(Pi))\n, 355/113,\n);\n\n// Lambert's W function\nNumericEqual(\nN(LambertW(-0.24),Builtin'Precision'Get())\n, -0.3357611648\n, Builtin'Precision'Get());\nNumericEqual(\nN(LambertW(10),Builtin'Precision'Get())\n, 1.7455280027\n, Builtin'Precision'Get());\n\n// Bessel Functions\n// These results are from GNU bc, matlab seems to suck.\nBuiltin'Precision'Set(50);\nNumericEqual( N(BesselJ(0,.5)), RoundTo(.93846980724081290422840467359971262556892679709682,50),50 );\nNumericEqual( N(BesselJ(0,.9)), RoundTo(.80752379812254477730240904228745534863542363027564,50),50 );\nNumericEqual( N(BesselJ(0,.99999)), RoundTo(.76520208704756659155313775543958045290339472808482,50),50 );\nNumericEqual( N(BesselJ(10,.75)), RoundTo(.00000000001496217131175968146987124836216828348578,50),50 );\nNumericEqual( N(BesselJ(5,1)), RoundTo(.00024975773021123443137506554098804519815836777698,50),50 );\nNumericEqual( N(BesselJ(4,2)), RoundTo(.03399571980756843414575921128853104471483296834631,50),50 );\nNumericEqual( N(BesselJ(10,3)), RoundTo( .00001292835164571588377753453080258017074342083284,50),50 );\n\nNumericEqual( N(BesselJ(11,11)), RoundTo( .20101400990926940339478738551009382430831534125484,50),50 );\nNumericEqual( N(BesselJ(-11,11)), RoundTo( -.20101400990926940339478738551009382430831534125484,50),50 );\nNumericEqual( RoundTo(N(BesselJ(1,10)),50), RoundTo( .04347274616886143666974876802585928830627286711859, 50),50 );\nNumericEqual( N(BesselJ(10,10)), RoundTo( .20748610663335885769727872351875342803274461128682, 50 ),50 );\nNumericEqual( RoundTo(N(BesselJ(1,3.6)),50), RoundTo( .09546554717787640384570674422606098601943275490885, 50 ),50) ;\n\nBuiltin'Precision'Set(20);\nVerify( RoundTo(N(Erf(Sqrt(0.8)),20),19), // verified with Maple\nRoundTo(.79409678926793169113034892342, 19)\n);\n\nIf(Interpreter() = \"yacas\",\n    Verify( RoundTo(N(Erf(50*I+20)/10^910,22),19), // verified with Maple\n    RoundTo(1.09317119002909585408+I*0.00475463306931818955275, 19)\n    ),\n    KnownFailure( RoundTo(N(Erf(50*I+20)/10^910,22),19), // verified with Maple\n    RoundTo(1.09317119002909585408+I*0.00475463306931818955275, 19)\n    )\n);\n\n// testing GammaConstNum against Maple\nTesting(\"Gamma constant\");\nBuiltin'Precision'Set(40);\nNumericEqual(Internal'gamma()+0, 0.5772156649015328606065120900824024310422,Builtin'Precision'Get());\nBuiltin'Precision'Set(20);\nVerify(gamma,Atom(\"gamma\"));\nNumericEqual(RoundTo(Internal'gamma()+0,19), 0.5772156649015328606,19);\nNumericEqual(RoundTo(N(1/2+gamma+Pi), 19), 4.2188083184913260991,19);\n\n// From GSL 1.0\n//NumericEqual( N(PolyLog(2,-0.001),20), -0.00099975011104865108, 20 );\n// PolyLog I didn't write PolyLog, but it seems to not always calculate correctly up to the last digit.\nVerify( RoundTo(N(PolyLog(2,-0.001)+0.00099975011104865108,20),20),0);\n\n// Round-off errors\nN([\n  Local(a,b);\n  a:= 77617;\n  b:= 33096;\n  // this expression gives a wrong answer on any hardware floating-point platform\n  NumericEqual( 333.75*b^6 + a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8 +a/(2*b), -0.827396,6);\n],40);\n"
  },
  {
    "path": "tests/nummethods.yts",
    "content": "// test some numerical methods\n\n// these examples are taken from the refman\n\nVerify(IntPowerNum(3*10^100, 0, MathMultiply,1), 1);\nVerify(IntPowerNum(3, 3, MathMultiply,1), 27);\nVerify(IntPowerNum(HilbertMatrix(2), 4, *,  Identity(2)), {{289/144,29/27},{29/27,745/1296}});\n\nVerify(IntPowerNum(3,100,{{x,y},Mod(x*y,7)},1), 4);\n\nBuiltin'Precision'Set(21);\nIf(Interpreter() = \"yacas\",\n    NumericEqual(RoundTo(SumTaylorNum(1, {{k},1/k!}, {{k},1/k}, 21),21), 2.718281828459045235359,21)\n);\n\nIf(Interpreter() = \"yacas\",\n    NumericEqual(RoundTo(SumTaylorNum(1, {{k},1/k!}, 21),21), 2.718281828459045235359,21)\n);\n\nBuiltin'Precision'Set(20);\nNumericEqual(NewtonNum({{x}, x+Sin(x)}, 3, 5, 3), 3.14159265358979323846,20);\n"
  },
  {
    "path": "tests/ode.yts",
    "content": "\n\nVerify( OdeTest(y''+y,       OdeSolve(y''+y==0)     ), 0 );\nVerify( OdeTest(y'/5-Sin(x), OdeSolve(y'/5==Sin(x)) ), 0 );\nVerify( OdeTest(x*y' - 1,    OdeSolve(x*y'==1)\t    ), 0 );\t\t\n"
  },
  {
    "path": "tests/openmath.yts",
    "content": "\nNextTest(\"Converting to and from OpenMath expressions\");\n\nVerify(ToString() OMForm(3), \"<OMOBJ>\" : Nl() : \"  <OMI>3</OMI>\" : Nl() : \"</OMOBJ>\" : Nl());\nVerify(ToString() OMForm(\"<OMSTR>a\\\"b'c&</OMSTR>\"), \"<OMOBJ>\" : Nl() : \"  <OMSTR>&lt;OMSTR&gt;a&quot;b&apos;c&amp;&lt;/OMSTR&gt;</OMSTR>\" : Nl() : \"</OMOBJ>\" : Nl());\n\nVerify(FromString(\"<OMOBJ> <OMI>3</OMI> </OMOBJ>\") OMRead(), 3);\nVerify(FromString(\"<OMOBJ> <OMSTR> a </OMSTR> </OMOBJ>\") OMRead(), \" a \");\nVerify(FromString(\"<OMOBJ><OMSTR>&lt;OMSTR&gt;a&quot;b&apos;c&amp;&lt;/OMSTR&gt;</OMSTR></OMOBJ>\") OMRead(), \"<OMSTR>a\\\"b'c&</OMSTR>\");\n\nVerify(FromString(\"<OMOBJ xmlns=\\\"http://www.openmath.org/OpenMath\\\" version=\\\"2.0\\\" cdbase=\\\"http://www.openmath.org/cd\\\"><OMF dec=\\\"1\\\"/></OMOBJ> \")OMRead(), 1);\nVerify(FromString(\"<OMOBJ><OMF dec=\\\"-INF\\\"/></OMOBJ> \")OMRead(), -Infinity);\n\nMacro(OMTest1,{expr})\n[\n  Local(string,result);\n  string:=ToString() OMForm(@expr);\n  result:=FromString(string)OMRead();\n//  Echo(Hold(@expr),`Hold(@result));\n  Verify(Hold(@expr),`Hold(@result));\n];\n\nOMTest1(2+3);\nOMTest1(2*a+3*Sin(Cos(a*x+b)));\n\n"
  },
  {
    "path": "tests/orthopoly.yts",
    "content": "NextTest(\"Testing orthogonal polynomials\");\n/* Symbolic calculations */\nTestYacas(OrthoG(3, 1/5, x), 88/125*x^3-12/25*x);\nTestYacas(OrthoG(9, 1/2, x), 12155/128*x^9-6435/32*x^7+9009/64*x^5-1155/32*x^3+315/128*x);\nTestYacas(OrthoH(4, x), 16*x^4-48*x^2+12);\nTestYacas(OrthoH(10, x), 1024*x^10-23040*x^8+161280*x^6-403200*x^4+302400*x^2-30240);\nTestYacas(OrthoL(4, 1/3, x), x^4/24-13/18*x^3+65/18*x^2-455/81*x+455/243);\nTestYacas(OrthoP(3,1/2,5/2,x), 21/2*x^3-7*x^2-35/16*x+7/8);\nTestYacas(OrthoP(7,x), (429*x^7-693*x^5+315*x^3-35*x)/16);\nTestYacas(OrthoT(15, x), 16384*x^15-61440*x^13+92160*x^11-70400*x^9+28800*x^7-6048*x^5+560*x^3-15*x);\nTestYacas(OrthoU(16, x), 65536*x^16-245760*x^14+372736*x^12-292864*x^10+126720*x^8-29568*x^6+3360*x^4-144*x^2+1);\n/* Numerical calculations */\nTestYacas(OrthoP(100, 1), 1);\nTestYacas(OrthoL(50,5/3,5/2), 956329424993407752478497541911420551314045339353541114044036291602395886513403153686689293955/143232645897909553890691033589829981069003266848814603996731044282564768594296559565258358784);\nTestYacas(OrthoP(15,1/7,1/9,2/3), 3891107589471727673898835091294644097395/16032477875245178148605931130545427636128);\n"
  },
  {
    "path": "tests/outer.yts",
    "content": "//////\n// $Id: outer.yts,v 1.2 2006-03-26 12:49:15 ayalpinkus Exp $\n// Tests for Outer\n//////\n\nTesting(\"-- Outer\");\n\nVerify(Outer({},{}),{});\nVerify(Outer({{}},{}),Hold(Outer({{}},{})));\nVerify(Outer({},{{}}),Hold(Outer({},{{}})));\nVerify(Outer({{}},{{}}),Hold(Outer({{}},{{}})));\nVerify(Outer(a,b),Hold(Outer(a,b)));\nVerify(Outer({a},{b}),{{a*b}});\nVerify(Outer({a,b},{c}),{{a*c},{b*c}});\nVerify(Outer({a},{b,c}),{{a*b,a*c}});\nVerify(Outer({a,b},{c,d,e}),{{a*c,a*d,a*e},{b*c,b*d,b*e}});\nVerify(Outer({a,b,c},{d,e}),{{a*d,a*e},{b*d,b*e},{c*d,c*e}});\n\n//////\n"
  },
  {
    "path": "tests/padic.yts",
    "content": "Testing(\"p-adic\");\n\nVerify(PAdicExpand(x^3, x-1), 3*(x-1)+3*(x-1)^2+(x-1)^3+1);\n\nVerify(Apart((x+4)/(x+3)^2), 1/(x+3)+1/(x+3)^2);\n"
  },
  {
    "path": "tests/physics.yts",
    "content": "NextTest(\"Clebsch-Gordan coefficients\");\n\nVerify(ClebschGordan({j,j},{j,j},{j,j}), 1);\n\nVerify(ClebschGordan({3/2, 3/2}, {1/2, -1/2}, {1, 1}), Sqrt(3/4));\n"
  },
  {
    "path": "tests/plots.yts",
    "content": "\n// some tests to verify that plotting works\n\nVerify(FromString((ToString()Write(Plot2D(a,-1:1,output=data,points=4,depth=0))) : \";\") Read() - {{{-1,-1},{-0.5,-0.5},{0,0},{0.5,0.5},{1.,1.}}}, {{{0,0},{0,0},{0,0},{0,0},{0,0}}});\nVerify(FromString((ToString()Write(Plot2D(b,b=-1:1,output=data,points=4))) : \";\") Read() - {{{-1,-1},{-0.5,-0.5},{0,0},{0.5,0.5},{1.,1.}}}, {{{0,0},{0,0},{0,0},{0,0},{0,0}}});\n\nVerify(FromString((ToString()Write(Plot3DS(a,-1:1,-1:1,output=data,points=2))) : \";\") Read() - {{{-1,-1,-1},{-1,0,-1},{-1,1.,-1},{0,-1,0},{0,0,0},{0,1.,0},{1.,-1,1.},{1.,0,1.},{1.,1.,1.}}}, {{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}});\nVerify(FromString((ToString()Write(Plot3DS(x1,x1 = -1:1,x2 = -1:1,output=data,points=2))) : \";\") Read() - {{{-1,-1,-1},{-1,0,-1},{-1,1.,-1},{0,-1,0},{0,0,0},{0,1.,0},{1.,-1,1.},{1.,0,1.},{1.,1.,1.}}}, {{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}});\n\n\n// test NFunction\nBuiltin'Precision'Set(10);\nRetract(\"f\",1);\nRetract(\"f1\",1);\nf(x) := N(Abs(1/x-1));\nVerify(f(0), Infinity);\nNumericEqual(RoundTo(f(3),Builtin'Precision'Get()), 0.6666666667,Builtin'Precision'Get());\nNFunction(\"f1\", \"f\", {x});\nVerify(f1(0), Undefined);\nNumericEqual(RoundTo(f1(3),Builtin'Precision'Get()), 0.6666666667,Builtin'Precision'Get());\n\n"
  },
  {
    "path": "tests/poly.yts",
    "content": "\nNextTest(\"Polynomials\");\nTestYacas(Expand((1+x)^2),1+2*x+x^2);\n\nNextTest(\"Degree\");\n\nVerify(Degree(0, x), -Infinity);\nVerify(Degree(6, x), 0);\nVerify(Degree(3 - 5*x + 2*x^5 - 7*x^9, x), 9);\nVerify(Degree((y - 3)*(2*y + 6)*(-4*y - 21), y), 3);\nVerify(Degree((3*z^8 + z^5 - 4*z^2 + 6) + (-3*z^8 + 8*z^4 + 2*z^3 + 14*z), z), 5);\n\nNextTest(\"Content\");\n\nVerify(Content(x^8+6*x^6+12*x^4+8*x^2), 1);\nVerify(Content(-10*x^2+5*x+5), -5);\nVerify(Content(1/3*x^5+7/2*x^2+2*x+1), 1/6);\n\nNextTest(\"Primitive part\");\n\nVerify(PrimitivePart(x^8+6*x^6+12*x^4+8*x^2), x^8+6*x^6+12*x^4+8*x^2);\nVerify(PrimitivePart(-10*x^2+5*x+5), 2*x^2-x-1);\nVerify(PrimitivePart(1/3*x^5+7/2*x^2+2*x+1), 2*x^5+21*x^2+12*x+6);\n\nNextTest(\"Greatest common divisor\");\n\nVerify(Gcd(2*x+2,4*x+4), 2*x+2);\nVerify(Gcd(x^2+7*x+6,x^2-5*x-6), x+1);\nVerify(Gcd(x^8+x^6-3*x^4-3*x^3+8*x^2+2*x-5,3*x^6+5*x^4-4*x^2-9*x+21), 1);\n\nVerify(PolynomialGcd(0, x, x), x);\nVerify(PolynomialGcd(x, 0, x), x);\nVerify(PolynomialGcd(2, 1/4, x), 1/4);\nVerify(PolynomialGcd(2*x+2, 4*x+4, x), 2*x+2);\nVerify(PolynomialGcd(x^2+7*x+6, x^2-5*x-6, x), x+1);\nVerify(PolynomialGcd(x^8+x^6-3*x^4-3*x^3+8*x^2+2*x-5, 3*x^6+5*x^4-4*x^2-9*x+21, x), 1);\n\n\nNextTest(\"Square-free factorization\");\n\nVerify(SquareFreeFactorize(x^2 + 2*x + 1, x), {{x+1,2}});\nVerify(SquareFreeFactorize(x^4 + x^3, x), {{x+1,1}, {x,3}});\nVerify(SquareFreeFactorize(2 - 2*x - 6*x^4 + 6*x^5 + 6*x^8 - 6*x^9 -2*x^12 + 2*x^13, x), {{x^3+x^2+x+1,3}, {x-1,4}});\nVerify(SquareFreeFactorize(2 + 5*x + 4*x^2 + x^3,x), {{x+2,1}, {x+1,2}});\nVerify(SquareFreeFactorize((x-1)^3*(x+2)^3*(x+1)^2*(x-2)^2*(x+3),x), {{x+3,1}, {x^2-x-2,2}, {x^2+x-2,3}});\nVerify(SquareFreeFactorize((x^2+1)*(x^2-1)^4*(x^3+3*x)^5,x), {{x^2+1,1}, {x^2-1,4}, {x^3+3*x,5}});\nVerify(SquareFreeFactorize(4*x^4 + 4*x^3 - 3*x^2 - 4*x - 1, x), {{x^2-1,1},{2*x+1,2}});\n\n// We need more polynomial tests\n\n"
  },
  {
    "path": "tests/predicates.yts",
    "content": "\nTesting(\"Predicates\");\nVerify(IsFunction(a(b)),True);\nVerify(IsFunction(a),False);\nVerify(IsList({a,b,c}),True);\nVerify(IsList(a),False);\nVerify(IsAtom({a,b,c}),False);\nVerify(IsAtom(a),True);\nVerify(IsAtom(123),True);\n\nVerify(IsNumber(123),True);\nVerify(IsNumber(123.123),True);\nVerify(IsNumber(a),False);\nVerify(IsNumber({a}),False);\n\nVerify(IsInteger(123),True);\nVerify(IsInteger(123.123),False);\nVerify(IsInteger(a),False);\nVerify(IsInteger({a}),False);\n\nTesting(\"Boolean Operations\");\nVerify(False And False,False);\nVerify(True And False,False);\nVerify(False And True,False);\nVerify(True And True,True);\n\nVerify(False Or False,False);\nVerify(True Or False,True);\nVerify(False Or True,True);\nVerify(True Or True,True);\n\nVerify(Not(True),False);\nVerify(Not(False),True);\n\nVerify(Equals(a,b),False);\nVerify(Equals(a,a),True);\nVerify(Equals({a,b},{a}),False);\nVerify(Equals({a,b},{a,b}),True);\n\nTesting(\"NumberCompares\");\nVerify(LessThan(2,3),True);\nVerify(LessThan(3,2),False);\nVerify(GreaterThan(2,3),False);\nVerify(GreaterThan(3,2),True);\n\nVerify(.1<2,True);\nVerify(0.1<2,True);\nVerify(.3<2,True);\nVerify(.1>2,False);\nVerify(0.1>2,False);\nVerify(.3>2,False);\n\nVerify(2<.1,False);\nVerify(2<0.1,False);\nVerify(2<.3,False);\nVerify(2>.1,True);\nVerify(2>0.1,True);\nVerify(2>.3,True);\n\nTesting(\"comparisons in exponential notation\");\n// some of these failed\nVerify(1e-5 < 1, True);\nVerify(1e-5 < 2e-5, True);\nVerify(1e-1 < 2e-1, True);\nVerify(1e-15 < 2e-15, True);\nVerify(1e-5 < 1e-10, False);\nVerify(1e-5 < 1e-2, True);\nVerify(-1e-5 < 1e-5, True);\nVerify(-1e-5 < 1e-6, True);\nVerify(1e-5 = 2e-5, False);\nVerify(1e-5 = 1e-6, False);\nVerify(1e-15 > 0, True);\nVerify(1e-5 > 0, True);\nVerify(1e-4 > 0, True);\nVerify(1e-3 > 0, True);\nVerify(1e-2 > 0, True);\nVerify(1e-1 > 0, True);\nVerify(1e5 > 0, True);\n\nVerify(1.0000000000000000000000000000111 > 1, True);\nVerify(0.999999999999999999999999999992 < 1, True);\n\nVerify(LessThan(-1e-115, 0), True);\nVerify(LessThan(-1e-15, 0), True);\nVerify(LessThan(-1e-10, 0), True);\nVerify(LessThan(-1e-5, 0), True);\nVerify(LessThan(-1e-1, 0), True);\n\nTesting(\"Matrix predicates\");\nVerify(IsHermitian({{0,I},{-I,0}}),True);\nVerify(IsHermitian({{0,I},{-I,1}}),True);\nVerify(IsHermitian({{0,I},{-2*I,0}}),False);\n\nVerify(IsUnitary({{0,I},{-I,0}}),True);\nVerify(IsUnitary({{0,I},{-I,1}}),False);\nVerify(IsUnitary({{0,I},{-2*I,0}}),False);\n\nVerify(IsVariable(a),True);\nVerify(IsVariable(Sin(a)),False);\nVerify(IsVariable(2),False);\nVerify(IsVariable(-2),False);\nVerify(IsVariable(2.1),False);\n\n\nVerify(HasExpr(a*b+1,1),True);\nVerify(HasExpr(a+Sin(b*c),c),True);\nVerify(HasExpr(a*b+1,2),False);\nVerify(HasExpr(a*b+f({b,c}),f),False);\nVerify(HasExprArith(a*b+1,Atom(\"+\")),False);\nVerify(HasExprArith(a*b+1,1),True);\nVerify(HasExprArith(a+Sin(b*c),c),False);\nVerify(HasExprArith(a+Sin(b*c),Sin(b*c)),True);\nVerify(HasExprArith(a*b+f({b,c}),c),False);\n\nVerify(HasFunc(a*b+1,*),True);\nVerify(HasFunc(a+Sin(b*c),*),True);\nVerify(HasFunc(a*b+1,List),False);\nVerify(HasFunc(a*b+f({b,c}),List),True);\nVerify(HasFuncArith(a*b+1,Atom(\"+\")),True);\nVerify(HasFuncArith(a+Sin(b*c),*),False);\nVerify(HasFuncArith(a+Sin(b*c),Sin),True);\nVerify(HasFuncArith(a*b+f({b,c}),List),False);\n\nVerify(IsGaussianInteger(3+4*I),True );\nVerify(IsGaussianInteger(5),True);\nVerify(IsGaussianInteger(1.1), False );\nVerify(IsGaussianPrime(5+2*I),True );\nVerify(IsGaussianPrime(13), False );\nVerify(IsGaussianPrime(0), False );\nVerify(IsGaussianPrime(3.5), False );\nVerify(IsGaussianPrime(2+3.1*I), False );\nVerify(IsPerfect(2305843008139952128), True );\nVerify(IsPerfect(137438691328),True );\nVerify(IsPerfect(234325),False );\n\nTesting(\"IsConstant\");\n\nVerify(IsConstant(Pi), True);\nVerify(IsConstant(Exp(1)+Sqrt(3)), True);\nVerify(IsConstant(x), False);\nVerify(IsConstant(Infinity), True);\nVerify(IsConstant(-Infinity), True);\nVerify(IsConstant(Undefined), True);\n\nTesting(\"-- IsScalar\");\nVerify(IsScalar(a),True);\nVerify(IsScalar({a}),False);\n\nTesting(\"-- IsVector\");\nVerify(IsVector(1),False);\nVerify(IsVector(a),False);\nVerify(IsVector(Sin(a)+2),False);\nVerify(IsVector({}),True);\nVerify(IsVector({{}}),False);\nVerify(IsVector({1,2,a,4}),True);\nVerify(IsVector({1,{2,a},4}),False);\nVerify(IsVector({{a,b,c}}),False);\n\nTesting(\"-- IsVector(IsNumber)\");\nVerify(IsVector(IsNumber,1),False);\nVerify(IsVector(IsNumber,{}),True);\nVerify(IsVector(IsNumber,{a,b,c}),False);\nVerify(IsVector(IsNumber,{a,2,c}),False);\nVerify(IsVector(IsNumber,{2,2.5,4}),True);\nVerify(IsVector(IsNumber,{Pi,2,3}),False);\nVerify(IsVector(IsNumber,{{1},{2}}),False);\n\nTesting(\"-- Matrix Predicates\");\n\nTesting(\"---- IsMatrix\");\nVerify(IsMatrix(1),False);\nVerify(IsMatrix({}),False);\nVerify(IsMatrix({a,b}),False);\nVerify(IsMatrix({{}}),True);\nVerify(IsMatrix({{a}}),True);\nVerify(IsMatrix({{{a}}}),False);\nVerify(IsMatrix({{},a}),False);\nVerify(IsMatrix({{a},b}),False);\nVerify(IsMatrix({{},{}}),True);\nVerify(IsMatrix({{{}},{}}),False);\nVerify(IsMatrix({{},{{}}}),False);\nVerify(IsMatrix({{a,b},{c}}),False);\nVerify(IsMatrix({{a,b},{c,d}}),True);\nVerify(IsMatrix({{a,b},{c,{d}}}),False);\nVerify(IsMatrix({{{}}}), False);\nVerify(IsMatrix({{{a}}}), False);\nVerify(IsMatrix({{{{a}}},{{{b}}}}),False);\n\nTesting(\"---- IsMatrix(IsInteger)\");\nVerify(IsMatrix(IsInteger,{{a,1}}),False);\nVerify(IsMatrix(IsInteger,{{1,2}}),True);\nVerify(IsMatrix(IsInteger,{{1,2/3}}),False);\nVerify(IsMatrix(IsInteger,{{1,2,3},{4,5,6}}),True);\nVerify(IsMatrix(IsInteger,{{1,{2},3},{4,5,6}}),False);\nVerify(IsMatrix(IsInteger,{{1,2,3},{4,5}}),False);\nVerify(IsMatrix(IsInteger,{{Sin(1),2,3},{4,5,6}}),False);\nVerify(IsMatrix(IsInteger,{{Sin(0),2,3},{4,5,6}}),True);\n\nTesting(\"---- IsSquareMatrix\");\nVerify(IsSquareMatrix({{}}),False);\nVerify(IsSquareMatrix({{a}}),True);\nVerify(IsSquareMatrix({{},{}}),False);\nVerify(IsSquareMatrix({{a,b}}),False);\nVerify(IsSquareMatrix({{a,b},{c,d}}),True);\nVerify(IsSquareMatrix({{a,b},{c,d},{e,f}}),False);\nVerify(IsSquareMatrix({{a,b,c},{d,e,f},{g,h,i}}),True);\nVerify(IsSquareMatrix({{a,b,c},{d,e,f}}),False);\nVerify(IsSquareMatrix({{{a,b}},{{c,d}}}), False);\n\nTesting(\"Function parity\");\nVerify(IsOddFunction(0,x), True);\nVerify(IsOddFunction(1,x), False);\nVerify(IsOddFunction(x,x), True);\nVerify(IsOddFunction(2*x,x), True);\nVerify(IsOddFunction(1/x,x), True);\nVerify(IsOddFunction(2/x,x), True);\nVerify(IsOddFunction(2*1/x,x), True);\nVerify(IsOddFunction(x^2,x), False);\n\nVerify(IsEvenFunction(0,x), True);\nVerify(IsEvenFunction(1,x), True);\nVerify(IsEvenFunction(x,x), False);\nVerify(IsEvenFunction(2*x,x), False);\nVerify(IsEvenFunction(1/x,x), False);\nVerify(IsEvenFunction(2/x,x), False);\nVerify(IsEvenFunction(2*1/x,x), False);"
  },
  {
    "path": "tests/products.yts",
    "content": "Testing(\"Product\");\n\nVerify(Product(i,1,3,i), 6);\nVerify(Product(k,1,n,k), n!);\nVerify(Product(k,1,n,2), 2^n);\nVerify(Product(k,1,Infinity,1), 1);\n"
  },
  {
    "path": "tests/programming.yts",
    "content": "\n\nTesting(\"Apply\");\nVerify(Apply(\"+\",{2,3}),5);\n[\n  Local(x,y);\n  Verify(Apply({{x,y},x+y},{2,3}),5);\n  Verify(Apply(Lambda({x,y},x+y),{2,3}),5);\n  Verify(Lambda({x,y},x+y) @ {2,3},5);\n\n  Verify(Apply(Lambda({x},Length(x)),{\"aaa\"}),3);\n\n  Verify(x,x);\n  Verify(y,y);\n\n  Testing(\"ThreadingListables\");\n  x:={bb,cc,dd};\n  Verify(Sin(aa*x),{Sin(aa*bb),Sin(aa*cc),Sin(aa*dd)});\n];\n\n\n\nTesting(\"MapSingle\");\nVerify(MapSingle(\"!\",{1,2,3,4}),{1,2,6,24});\n\n/* Example: using the for function. */\nFunction(\"count\",{from,to})\n[\n   Local(i);\n   Local(sum);\n   Set(sum,0);\n   For(i:=from,i<to,i:=i+1)\n   [\n     Set(sum,sum+i);\n   ];\n   sum;\n];\n\nTesting(\"Function definitions\");\nVerify(count(1,11),55);\n\nRetract(\"count\",2);\n\nTesting(\"LocalVariables\");\n[\n  Verify(IsBound({}),False);\n  Local(a);\n  Verify(IsBound(a),False);\n  a:=1;\n  Verify(IsBound(a),True);\n  Clear(a);\n  Verify(IsBound(a),False);\n];\n\nVerify(Atom(\"a\"),a);\nVerify(String(a),\"a\");\nVerify(ConcatStrings(\"a\",\"b\",\"c\"),\"abc\");\n\nTesting(\"Symbol protection\");\n\nVerify(TrapError(Cos := True, False), False);\n\nProtect(item);\nVerify(Simplify(x+x), 2*x);\nUnProtect(item);"
  },
  {
    "path": "tests/radsimp.yts",
    "content": "NextTest(\"Testing simplifying nested radicals\");\n\nTestYacas(RadSimp(Sqrt(9+4*Sqrt(2))), 1+Sqrt(8));\nTestYacas(RadSimp(Sqrt(5+2*Sqrt(6))+Sqrt(5-2*Sqrt(6))),Sqrt(12));\nTestYacas(RadSimp(Sqrt(14+3*Sqrt(3+2*Sqrt(5-12*Sqrt(3-2*Sqrt(2)))))), 3+Sqrt(2));\n\nTestYacas(RadSimp(Sqrt(3+2*Sqrt(2))),1+Sqrt(2));\nTestYacas(RadSimp(Sqrt(5+2*Sqrt(6))),Sqrt(2)+Sqrt(3));\n\n//FAILS??? TestYacas(RadSimp(Sqrt(5*Sqrt(3)+6*Sqrt(2))),Sqrt(Sqrt(27))+Sqrt(Sqrt(12)));\n//??? TestYacas(RadSimp(Sqrt(12+2*Sqrt(6)+2*Sqrt(14)+2*Sqrt(21))),Sqrt(2)+Sqrt(3)+Sqrt(7));\n\n\n"
  },
  {
    "path": "tests/rational.yts",
    "content": "Testing(\"Rational Functions\");\n\nVerify(IsRationalFunction(x,x), True);\nVerify(IsRationalFunction(x^2-1,x), True);\nVerify(IsRationalFunction((x^3-x)/x^2-x,x), True);\nVerify(IsRationalFunction(Sin(x),x), False);\nVerify(IsRationalFunction(x*Sqrt(x),x), False);\n\nVerify(IsPureRationalFunction(x,x), False);\nVerify(IsPureRationalFunction(x^2-1,x), False);\nVerify(IsPureRationalFunction(1/(x+1),x), True);\nVerify(IsPureRationalFunction((x^3-x)/x^2-x,x), True);\n"
  },
  {
    "path": "tests/regress.yts",
    "content": "\nNextTest(\"Regression on bug reports\");\n\nVerify(N(Sin(a)),Sin(a));\nLogicVerify(CanProve(P Or (Not P And Not Q)),P Or Not Q);\nVerify(Cos(0),1);\nVerify(Infinity/Infinity,Undefined);\nVerify(Sqrt(Infinity),Infinity);\nVerify(1^Infinity,Undefined);\nVerify((-2)*Infinity,-Infinity);\nVerify(Infinity*0,Undefined);\nVerify(Limit(x,Infinity) (-x^2+1)/(x+2),-Infinity);\nVerify(Limit(x,-Infinity)Exp(2*x),0);\nVerify(Limit(x,Infinity)(1+1/x)^x,Exp(1));\nVerify(Limit(x,Infinity)(1+2/x)^x,Exp(2));\nVerify(Limit(x,Infinity)(1+1/x)^(2*x),Exp(2));\nVerify(Limit(x,Infinity)-2*x,-Infinity);\nVerify(Limit(x,Infinity)(x^2+1)/(-x^3+1),0);\n\nVerify(Limit(x,0)1/x,Undefined);\nVerify(Limit(x,0,Right)1/x,Infinity);\nVerify(Limit(x,0,Left)1/x,-Infinity);\n\nVerify([Local(a);a:=0.1;Simplify((a*b*c)/(a*c*b));],1);\n\nLogicVerify(CanProve(P Or (Not P And Not Q)),P Or Not Q);\nLogicVerify(CanProve(A>0 And A<=0),False);\nLogicVerify(CanProve(A>0 Or A<=0),True);\nVerify(A<0,A<0);\nVerify(A>0,A>0);\nTestYacas(Arg(Exp(2*I*Pi/3)),2*Pi/3);\n\nTestYacas(Content(1/2*x+1/2),1/2);\nTestYacas(PrimitivePart(1/2*x+1/2),x+1);\nTestYacas(Content(1/2*x+1/3),1/6);\nTestYacas(PrimitivePart(1/2*x+1/3),3*x+2);\n\n// Mod generated a stack overflow on floats.\nVerify(Mod(1.2,3.4),6/5);\n//TODO I need to understand why we need to put Eval here. Mod(-1.2,3.4)-2.2 returns 0/5 where the 0 is not an integer according to the system. Round-off error?\nNumericEqual(N(Eval(Mod(-1.2,3.4))),2.2,Builtin'Precision'Get());\nVerify(Mod(-12/10,34/10),11/5);\n// just a test to see if Verify still gives correct error Verify(N(Mod(-12/10,34/10)),11/5);\n\n\n// some reports:\n\nLocalSymbols(f,p,a,b,x,n)\n[\n  f(_n) <-- Apply(\"D\",{x,n, x^n});\n  Verify(f(10)-(10!));\n\n  p := a+2-(a+1);\n  Verify(Simplify(x^p),x);\n];\n\nLocalSymbols(f,p,a,b,x,n,simple,u,v)\n[\n  simple := {\n            Exp(_a)*Exp(_b) <- Exp(a+b),\n            Exp(_a)*_u*Exp(_b) <- u*Exp(a+b),\n            _u*Exp(_a)*Exp(_b) <- u*Exp(a+b),\n            Exp(_a)*Exp(_b)*_u <- u*Exp(a+b),\n            _u*Exp(_a)*_v*Exp(_b) <- u*v*Exp(a+b),\n            Exp(_a)*_u*Exp(_b)*_v <- u*v*Exp(a+b),\n            _u*Exp(_a)*Exp(_b)*_v <- u*v*Exp(a+b),\n            _u*Exp(_a)*_v*Exp(_b)*_w <- u*v*w*Exp(a+b)\n          };\n\n  a := Simplify(Exp(x)*(D(x) x*Exp(-x)));\n  b := Exp(x)*Exp(-x)-Exp(x)*x*Exp(-x);\n\n  a:= (a /: simple);\n  b:= (b /: simple);\n\n  Verify(Simplify(a-(1-x)),0);\n  Verify(Simplify(b-(1-x)),0);\n\n];\n\n// Verify that postfix operators can be applied one after the other\n// without brackets\nVerify((3!) !, 720);\nVerify(3! !, 720);\n\nTestYacas(TrigSimpCombine(Exp(A*X)),Exp(A*X));\nTestYacas(TrigSimpCombine(x^Sin(a*x+b)),x^Sin(a*x+b));\nVerify(CanBeUni(x^(-1)),False);\n\n\nf(x):=Eval(Factor(x))=x;\nVerify(f(703), True);\nVerify(f(485), True);\nVerify(f(170410240), True);\n\n\n\n\n\n/* bug reported by Jonathan:\n   All functions that do not have Taylor Expansions about\n   the given point go into infinite loops.\n */\n\nVerify(Taylor(x,0,5) Ln(x),Undefined);\nVerify(Taylor(x,0,5) 1/x,Undefined);\nVerify(Taylor(x,0,5) 1/Sin(x),Undefined);\n\n// Yacas used to not simplify the following, due to Pi being\n// considered constant. The expression was thus not expanded\n// as a univariate polynomial in Pi\nTestYacas(2*Pi/3,(Pi-Pi/3));\n\nTestYacas(( a*(Sqrt(Pi))^2/2), (a*Pi)/2);\nTestYacas(( 3*(Sqrt(Pi))^2/2), (3*Pi)/2);\nTestYacas(( a*(Sqrt(b ))^2/2), (a*b)/2);\n\n// Bug was found: gcd sometimes returned 0! Very bad, since the\n// value returned by gcd is usually used to divide out greatest\n// common divisors, and dividing by zero is not a good idea.\nVerify(Gcd(0,0),1);\nVerify(Gcd({0}),1);\n\n// Multiply didn't check for correct input\nVerify(Multiply(10), Multiply(10));\nVerify(Multiply(-1), Multiply(-1));\nVerify(Multiply(Infinity), Multiply(Infinity));\nVerify(Multiply(1 .. 10),3628800);\n\n//\nTestYacas(Sin(Pi-22),-Sin(22-Pi));\nTestYacas(Cos(Pi-22), Cos(22-Pi));\n\n// Verify that some matrix functions accept only positive\n// integer arguments. Regression test for the fact that the functions\n// in linalg.rep/ didn't check their arguments.\n\n// Note: Jonathan, perhaps some functions could return something\n// useful if the argument passed in is just a number? I'd imagine\n// Inverse(-2) <-- -1/2 would not be inconsistent?\n\nVerify(ZeroMatrix(-2,-2),ZeroMatrix(-2,-2));\nVerify(Identity(-2),Identity(-2));\n//Verify(LeviCivita(2),LeviCivita(2));\n//Verify(Permutations(2),Permutations(2));\n//Verify(InProduct(-2,-2),InProduct(-2,-2));\n//Verify(CrossProduct(-2,-2),CrossProduct(-2,-2));\n//Verify(BaseVector(-2,-2),BaseVector(-2,-2));\n//Verify(DiagonalMatrix(-2),DiagonalMatrix(-2));\n//Verify(Normalize(-2),Normalize(-2));\n//Verify(Transpose(-2),Transpose(-2));\n//Verify(Determinant(-2),Determinant(-2));\n//Verify(CoFactor(-2,-2,-2),CoFactor(-2,-2,-2));\n//Verify(Inverse(-2),Inverse(-2));\n//Verify(Trace(-2),Trace(-2));\n//Verify(SylvesterMatrix(-2,-2,-2),SylvesterMatrix(-2,-2,-2));\nVerify(ZeroVector(-2),ZeroVector(-2));\n\nVerify(Sech(x),1/Cosh(x));\nVerify(Cot(x),1/Tan(x));\n\n// Matrix operations failed: a^2 performed the squaring on each element\nVerify({{1,2},{3,4}}^2,{{7,10},{15,22}});\n// And check that raising powers still works on lists/vectors (dotproduct?) correctly\nVerify({2,3}^2,{4,9});\n\nVerify( D(x,0) Sin(x), Sin(x) );\n\nVerify( 2/3 >= 1/3, True);\n\nVerify( Infinity + I, Complex(Infinity,1) );\nVerify( Infinity - I, Complex(Infinity,-1) );\nVerify( I - Infinity,Complex(-Infinity,1) );\nVerify( I + Infinity, Complex(Infinity,1) );\nVerify( I*Infinity,Complex(0,Infinity)); //Changed Ayal: I didn't like the old definition\nVerify(-I*Infinity,Complex(0,-Infinity)); //Changed Ayal: I didn't like the old definition\nVerify( Infinity*I,Complex(0,Infinity)); //Changed Ayal: I didn't like the old definition\nVerify(  Infinity^I,Undefined);//Changed Ayal: I didn't like the old definition (it is undefined, right?)\nVerify( (2*I)^Infinity, Infinity );\nVerify( Infinity/I,Infinity );\nVerify( Sign(Infinity), 1 );\nVerify( Sign(-Infinity), -1 );\n\nVerify( Limit(n, Infinity) (n+1)/(2*n+3)*I, Complex(0,1/2) );\nVerify( Limit(x, Infinity) x*I, Complex(0,Infinity) ); //Changed Ayal: I didn't like the old definition\n\nVerify(Integrate(x) z^100, z^100*x );\nVerify(Integrate(x) x^(-1),Ln(x) );\n\nNumericEqual(\nRoundTo(N(ArcSin(0.0000000321232123),50),50)\n, 0.00000003212321230000000552466124302049336784679316\n,50);\n\nVerify(Internal'LnNum(1), 0);\n\nVerify(Bin(0,0),1 );\n\nVerify(0|1, 1);\nVerify(0&1, 0);\nVerify(0%1, 0);\n\nVerify(0.0/Sqrt(2),0);\nVerify(0.0000000000/Sqrt(2),0);\nVerify(0.0000^(24),0);\n\nVerify(Bernoulli(24), -236364091/2730);\n\nVerify(Gamma(1/2), Sqrt(Pi));\n\n// Coef accepted non-integer arguments as second argument, and\n// crashed on it.\nVerify(Coef(3*Pi,Pi),Coef(3*Pi,Pi));\nVerify(Coef(3*Pi,x), Coef(3*Pi,x));\n\n// Univariates in Pi did not get handled well, due to Pi being\n// considered a constant, non-variable.\nVerify(Degree(Pi,Pi),1);\nVerify(Degree(2*Pi,Pi),1);\n\nVerify(Sin(2*Pi), 0);\nVerify(Cos(2*Pi), 1);\nVerify(Cos(4*Pi), 1);\nVerify(Sin(3*Pi/2)+1, 0);\nVerify(Sin(Pi/2), 1);\n\n// - and ! operators didn't get handled correctly in the\n// parser/pretty printer (did you fix this, Serge?)\nVerify(ToString()Write((-x)!),\"(-x)!\");\n\n// some interesting interaction between the rules...\nVerify(x*x*x,x^3,);\nVerify(x+x+x,3*x);\nVerify(x+x-x+x,2*x);\n\n\n// bugs with complex numbers\nVerify((1+I)^0, 1);\nVerify((-I)^0, 1);\nVerify((2*I)^(-10), -1/1024);\nVerify((-I)^(-10), -1);\nVerify((1-I)^(-10), Complex(0,1/32));\nVerify((1-I)^(+10), Complex(0,-32));\nVerify((1+2*I)^(-10), Complex(237/9765625,3116/9765625));\nVerify((1+2*I)^(+10), Complex(237,-3116));\n\n// expansion of negative powers of fractions\nVerify( (-1/2)^(-10), 1024);\n\nVerify( I^(Infinity), Undefined );\nVerify( I^(-Infinity), Undefined );\nVerify( Limit(n,Infinity) n*I^n, Undefined );\n\nVerify(1 <= 1.0, True);\nVerify(-1 <= -1.0, True);\nVerify(0 <= 0.0, True);\nVerify(0.0 <= 0, True);\nVerify(1 >= 1.0, True);\nVerify(-1 >= -1.0, True);\nVerify(0 >= 0.0, True);\nVerify(0.0 >= 0, True);\n\nVerify((1==1) != True, True);\nVerify((a==a) != True, True);\nVerify((1==2) != False, True);\nVerify((a==2) != False, True);\n\nVerify( Integrate(x) x^5000, x^5001/5001 );\n\nVerify( Integrate(x) Sin(x)/2, (-Cos(x))/2 );\n\nVerify( 2^(-10), 1/1024 );\n\n// The following line catches a bug reported where Simplify\n// would go into an infinite loop. It doesn't check the correctness\n// of the returned value as such, but merely the fact that this\n// simplification terminates in the first place.\n//\n// The problem was caused by a gcd calculation (from the multivariate\n// code) not terminating.\nVerify( Simplify((a^2+b^2)/(2*a)), (a^2+b^2)/(2*a) );\n\n// The following is a classical error: 0*x=0 is only true if\n// x is a number! In this case, it is checked for that the\n// multiplication of 0 with a vector returns a zero vector.\n// This would automatically be caught with type checking.\n// More tests of this ilk are possible: 0*matrix, etcetera.\nVerify(0*{a,b,c},{0,0,0});\n\n// the following broke evaluation (dr)\nVerify(Conjugate({a}),{a});\n\n// not yet fixed (dr)\nVerify(Abs(Undefined),Undefined);\n\n// broke Plot2D() on singular functions with Abs()\nVerify(Undefined<1, False);\nVerify(Undefined>Undefined, False);\nVerify(Undefined>1, False);\nVerify(Undefined >= -4, False);\nVerify(Undefined <= -4, False);\n\n// Jonathan's bug report\nBuiltin'Precision'Set(10);\nNumericEqual(N(Cos(Pi*.5)), 0,Builtin'Precision'Get());\n\n/* Jitse's bug report, extended with the changes that do not coerce integers to floats automatically\n   any more (just enter a dot and the number becomes float if that is what is intended).\n */\nVerify(CForm(4), \"4\");\nVerify(CForm(4.), \"4.\");\nVerify(CForm(0), \"0\");\nVerify(CForm(0.), \"0.\");\n\n// Discovered that Floor didn't handle new exponent notation\nVerify(Floor(1001.1e-1),100);\nVerify(Floor(10.01e1),100);\nVerify(Floor(100.1),100);\n\n// Bugs discovered by Jonathan:\nVerify(Undefined*0,Undefined);\n// Actually, the following Groebner test is just to check that the program doesn't crash on this,\n// more than on the exact result (which is hopefully correct also ;-) )\nVerify(Groebner({x*(y-1),y*(x-1)}),{x*y-x,x*y-y,y-x,y^2-y});\n\n// Reported by Yannick Versley\nVerify((Integrate(x,a,b)Cos(x)^2) - ((b-Sin((-2)*b)/2)/2-(a-Sin((-2)*a)/2)/2),0);\nVerify(D(t) Integrate(x,a,b) f(x,t),Integrate(x,a,b)Deriv(t)f(x,t));\n\n// This was returning FWatom(Sin(x))\nVerify( Factor(Sin(x)), Factor(Sin(x)) );\n\n// should return unevaled\nVerify( BesselJ(0,x), BesselJ(0,x) );\n\n\n// Listify and UnList coredumped when their arguments were invalid\nVerify(Listify(Cos(x)),{Cos,x});\nVerify(UnList({Cos,x}),Cos(x));\n[\n  Local(error);\n  error:=\"\";\n  TrapError(Listify(1.2),error:=GetCoreError());\n  Verify(IsString(error) And error != \"\");\n\n  error:=\"\";\n  TrapError(UnList(1.2),error:=GetCoreError());\n  Verify(IsString(error) And error != \"\");\n];\n\n// Reported by Serge: xml tokenizer not general enough\nVerify(XmlExplodeTag(\"<p/>\"),   XmlTag(\"P\",{},\"OpenClose\"));\nVerify(XmlExplodeTag(\"<p / >\"), XmlTag(\"P\",{},\"OpenClose\"));\n\nVerify(ToBase(16,30),\"1e\");\nVerify(FromBase(16,\"1e\"),30);\n\n// numbers are too small because of wrong precision handling\nBuiltin'Precision'Set(30);\nVerify(0.00000000000000000005421010862 = 0, False); // 2^(-64)\nVerify(0.00000000000000000005421010862 / 1 = 0, False);\nVerify(0.00000000000000000005421010862 / 2 = 0, False);\nVerify(0.00000000000000000001 = 0, False);\nVerify(0.00000000000000000001 / 2 = 0, False);\nVerify(0.00000000000000000000000000001 = 0, False);\nVerify(0.000000000000000000000000000001 = 0, False);\nVerify((0.0000000000000000000000000000000000000001 = 0), False);\n// I added another one, the code will currently say that 0.0000...00001=0 is True\n// for a sufficient amount of zeroes, regardless of precision. Either that is good\n// or that is bad, but the above tests didn't go far enough. This one makes it\n// more explicit, unless we move over to a 128-bits system ;-)\nVerify((0.0000000000000000000000000000000000000000000000001 = 0), False);\n\n\n// Problem with FloatIsInt and gmp\nVerify(FloatIsInt(3.1415926535e9), False);\nVerify(FloatIsInt(3.1415926535e10), True);\nVerify(FloatIsInt(3.1415926535e20), True);\nVerify(FloatIsInt(0.3e20), True);\n\n/* Regression on bug reports from docs/bugs.txt */\n\n/* Bug #1 */\n/* Can't test: 'Limit(x,0)D(x,2)Sin(x)/x' never terminates */\n\n/* Bug #2 */\nKnownFailure((Limit(x,Infinity) x^n/Ln(x)) = Infinity);\nKnownFailure((Limit(x,0,Right) x^(Ln(a)/(1+Ln(x)))) = a);\nVerify((Limit(x,0) (x+1)^(Ln(a)/x)), a);\n/* Note paren's around bodied operators like Limit, D, Integrate;\n   otherwise it's parsed as Limit (... = ...) */\n\n/* Bug #3 */\nVerify(Gcd(-10, 0), 10);\nVerify(Gcd(0, -10), 10);\n\n/* Bug #4 */\n/* How can we test for this? */\n/* Bug says: at startup, 2^Infinity does not simplify to Infinity */\n\n/* Bug #5 */\nVerify(Limit(n,Infinity) Sqrt(n+1)-Sqrt(n), 0);\n\n/* Bug #6 */\nKnownFailure((D(z) Conjugate(z)) = Undefined);\n\n/* Bug #7 */\nVerify(Im(3+I*Infinity), Infinity); /* resolved */\nVerify(Im(3+I*Undefined), Undefined);\n\n/* Bug #9 */\nVerify((Integrate(x,-1,1) 1/x), 0); /* or maybe Undefined? */\nVerify((Integrate(x,-1,1) 1/x^2), Infinity);\n\n/* Bug #10 */\nVerify(Simplify(x^(-2)/(1-x)^3) != 0);\n/* I don't know what we want to return, but '0' is definitely wrong! */\n\n/* Bug #11 */\nVerify(ArcCos(Cos(beta)) != beta);\n\n/* Bug #12 */\nVerify((Limit(n, Infinity) n^5/2^n) = 0);\n\n/* Bug #13 */\n/* Cannot test; TrigSimpCombine(x^500) floods stack */\n\n/* Bug #14 */\nVerify((Limit(x,Infinity) Zeta(x)), 1);\n// Actually, I changed the Factorial(x) to (x!)\nVerify((Limit(x,Infinity) (x!)), Infinity);\n\n/* Bug #15 */\nVerify(MathPower(0,0.55), 0);\n// MathLog(-1) locks up in gmpnumbers.cpp, will be fixed in scripts\n//FIXME this test should be uncommented eventually\n// Verify(TrapError(MathPower(-1,-0.5), error), error);\n\n/* Bug #16 */\n/* Can't test, bug in build system */\n\n/* Bug #17 */\nVerify(Assoc(x-1, Factors(x^6-1))[2], 1);\n\n/* Bug #18 */\n//Changed, see next line TestYacas(Integrate(x) x^(1/2), 2/3*x^(3/2));\nTestYacas(Integrate(x) x^(1/2), (2/3)*Sqrt(x)^(3));\n\nVerify(a[2]*Sin(x)/:{Sin(_x) <- sin(x)},a[2]*sin(x));\n\n// There was a bug, reported by Sebastian Ferraro, which caused the determinant\n// to return \"Undefined\" when one of the elements of the diagonal of a matrix\n// was zero. This was due to the numeric determinant algorithm applying\n// Gaussian elimination, but taking the elements on the diagonal as pivot points.\nVerify(IsZero(Determinant( {{1,-1,0,0},{0,0,-1,1},{1,0,0,1},{0,1,1,0}} )),True);\n\n// The following failed when numerics changed so that 0e-1 was not matched to 0 any more in\n// a transformation rule defining the less than operator.\nVerify(ExpNum(0),1);\nNumericEqual(ExpNum(0e-1),1.,Builtin'Precision'Get());\nVerify(500 < 0e-1,False);\n\n// version 1.0.56: Due to MathBitCount returning negative values sometimes, functions depending on\n// proper functioning failed. MathSqrtFloat failed for instance on N(1/2). It did give the right\n// result for 0.5.\nNumericEqual(N(Sqrt(500000e-6),20),N(Sqrt(0.0000005e6),20),20);\nNumericEqual(N(Sqrt(0.5),20),N(Sqrt(N(1/2)),20),20);\n\n// With the changes in numerics, RoundTo seems to have been broken. This line demonstrates the problem.\n// The last digit is suddenly rounded down (it used to be 4, correctly, and then gets rounded down to 3).\nKnownFailure(RoundTo(RoundTo(N(Cot(2),9),9),N(Cot(2),9),9)=0);\n\n// MathLog used to hang on *all* input\nVerify(MathLog(2)!=0,True);\n\n// Bug that was introduced when going to the new numeric setup where\n// numbers were not converted to strings any more. In the situation\n// -n*10^-m where n and m positive integers, the number got truncated\n// prematurely, resulting in a wrong rounding.\n[\n  Local(n,m,nkeep,lcl);\n  n:=7300 + 12*I;\n  m:=2700 + 100*I;\n  nkeep:=n;\n  n:=m;\n  m:=nkeep - m*Round(nkeep/m);\n  lcl:=Re(N(n/m))+0.5;\n  Verify(MathFloor(lcl),-3);\n];\n\n\n/* Here follow some tests for MathBitCount. These were written while creating\n   the Java version, fixing BitCount in the process.\n */\nVerify(MathBitCount(3),2);\nVerify(MathBitCount(3.0),2);\n\nVerify(MathBitCount(4),3);\nVerify(MathBitCount(4.0),3);\n\nVerify(MathBitCount(0),0);\nVerify(MathBitCount(0.0),0);\n\nVerify(MathBitCount(0.5),0);\nVerify(MathBitCount(0.25),-1);\nVerify(MathBitCount(0.125),-2);\nVerify(MathBitCount(0.0125),-6);\n\nVerify(MathBitCount(-3),2);\nVerify(MathBitCount(-3.0),2);\n\nVerify(MathBitCount(-4),3);\nVerify(MathBitCount(-4.0),3);\n\nVerify(MathBitCount(-0),0);\nVerify(MathBitCount(-0.0),0);\n\nVerify(MathBitCount(-0.5),0);\nVerify(MathBitCount(-0.25),-1);\nVerify(MathBitCount(-0.125),-2);\nVerify(MathBitCount(-0.0125),-6);\n\n// This one ended in an infinite loop because 1 is an even function, and the indefinite integrator\n// then kept on calling itself because the left and right boundaries were equal to zero.\nVerify(Integrate(x,0,0)1,0);\n\n// This code verifies that if integrating over a zero domain, the result\n// is zero.\nVerify(Integrate(x,1,1)Sin(Exp(x^2)),0);\n\n/* Reverse and FlatCopy (and some friends) would segfault in the past if passed a string as argument.\n * I am not opposed to overloading these functions to also work on strings per se, but for now just\n * check that they return an error in stead of segfaulting.\n */\nVerify(TrapError(Reverse(\"abc\"),True),True);\nVerify(TrapError(FlatCopy(\"abc\"),True),True);\n\n// Make sure Mod works threaded\nVerify(Mod(2,Infinity),2);\nVerify(Mod({2,1},{2,2}),{0,1});\nVerify(Mod({5,1},4),{1,1});\n\n/* In MatchLinear and MatchPureSquare, the matched coefficients were\n * assigned to global variables that were not protected with LocalSymbols.\n */\n[\n  Local(a,b,A);\n  a:=mystr;\n  A:=mystr;\n  /* The real test here is that no error is generated due to the\n   * fact that variables a or A are set.\n   */\n  Verify(Simplify((Integrate(x,a,b)Sin(x))-Cos(a)+Cos(b)),0);\n];\n\n// Factoring 2*x^2 used to generate an error\nVerify(Factor(2*x^2),x^2);\n\n/* Bug report from Magnus Petursson regarding determinants of matrices that have symbolic entries */\nVerify(CanBeUni(Determinant({{a,b},{c,d}})),True);\n\n/* Bug report from Michael Borcherds. The brackets were missing. */\nVerify(TeXForm(Hold(2*x*(-2))), \"$2 x \\\\left(  - 2\\\\right) $\");\n\n/* Bug reported by Adrian Vontobel. */\n[\n  Local(A1,A2);\n  A1:=Pi*20^2; // 400*Pi\n  A2:=Pi*18^2; // 324*Pi\n  Verify(Min(A1,A2), 324*Pi);\n  Verify(Max(A1,A2), 400*Pi);\n];\n\n/* One place where we forgot to change Sum to Add */\nTestYacas(Diverge({x*y,x*y,x*y},{x,y,z}),x+y);\n\n/* Bug reported by Adrian Vontobel: comparison operators should coerce\n * to a real value as much as possible before trying the comparison.\n */\n[\n  Local(F);\n  F:=0.2*Pi;\n  Verify(F>0.5, True);\n  Verify(F>0.7, False);\n  Verify(F<0.7, True);\n  Verify(F<0.6, False);\n];\n\n/* Bug reported by Michael Borcherds: Simplify(((4*x)-2.25)/2)\n   returned some expression with three calls to Gcd, which was technically\n   correct, but not the intended simplification.\n */\nVerify(IsZero(Simplify(Simplify(((4*x)-2.25)/2)-(2*x-2.25/2))),True);\n\n/* Bug reported by Adrian Vontobel: when assigning an expression to a variable,\n * it did not get re-evaluated in the calling environment when passing it in to Newton.\n * The resulting value was \"Undefined\", instead of the expected 1.5 .\n */\nNumericEqual([  Local(expr); expr := 1800*x/1.5 - 1800; Newton(expr, x,2,0.001); ],1.5,3);\n\n// Ticket 4\nVerify(Limit(n,Infinity) n/2^n, 0);\nVerify(Limit(n, Infinity) n^5/2^n, 0);\n\n// Ticket 14\nVerify(Factor(0), 0);\n\n// Ticket 26\nVerify(Limit(n,Infinity)(n!)/n, Infinity);\n\n// Ticket 40\nVerify(CDF(PoissonDistribution(5), 2), 6*Exp(-5));\ni := 0;\nVerify(CDF(PoissonDistribution(5), 2), 6*Exp(-5));\nClear(i);\n\n// Ticket 41\nVerify(StringMid'Set(3, \"XY\", \"abcdef\"), \"abXYef\");\nVerify(StringMid'Set(5, \"XY\", \"abcdef\"), \"abcdXY\");\n\n// Ticket 45\nVerify(PrimitivePart(x^2), x^2);\n\n// Ticket 46\nVerify(PrimitivePart(-10*x^2+5*x+5), 2*x^2-x-1);\n"
  },
  {
    "path": "tests/scopestack.yts",
    "content": "\n\nLocalSymbols(st)\n[\n  st:=NewStack();\n  Verify(IsOnStack(st,\"c\"),False);\n  PushStackFrame(st,fenced);\n    AddToStack(st,\"a\");\n    AddToStack(st,\"b\");\n    Verify(IsOnStack(st,\"a\"),True);\n    Verify(IsOnStack(st,\"c\"),False);\n    Verify(FindOnStack(st,\"a\"),{});\n    FindOnStack(st,\"b\")[\"set\"]:=True;\n    Verify(FindOnStack(st,\"b\"),{{\"set\",True}});\n    PushStackFrame(st,unfenced);\n      AddToStack(st,\"c\");\n      Verify(IsOnStack(st,\"c\"),True);\n      Verify(IsOnStack(st,\"a\"),True);\n    PopStackFrame(st);\n\n    PushStackFrame(st,fenced);\n      AddToStack(st,\"c\");\n      Verify(IsOnStack(st,\"c\"),True);\n      Verify(IsOnStack(st,\"a\"),False);\n    PopStackFrame(st);\n\n  PopStackFrame(st);\n  Verify(StackDepth(st),0);\n];\n\n\n"
  },
  {
    "path": "tests/simplify.yts",
    "content": "\n/* Test Simplify() */\nNextTest(\"Simplify\");\n\nTestYacas( Simplify((x+y)*(x-y)-(x+y)^2), -2*y^2-2*x*y );\nTestYacas( Simplify(1+x+x+3*y-4*(x+y+2)), -2*x-y-7 );\nTestYacas( Simplify((1+I)^4), -4 );\nTestYacas( Simplify((x-y)/(x*y)), 1/y-1/x );\n//See below, now handled with II KnownFailure(TestYacas( Simplify((x+I)^4), x^4+4*x^3*I-6*x^2-4*x*I+1 ));\n\nTestYacas( Simplify((xx+II)^4), xx^4+4*xx^3*II-6*xx^2-4*xx*II+1 );\n\nTestYacas( Simplify(D(x,4)Exp(-x^2/2)), Exp(-x^2/2)*(x^4-6*x^2+3));\n\nTestYacas( Simplify(1),1);\nTestYacas( Simplify(1/x ), 1/x );\nTestYacas( Simplify( 1/(1/x+1) ),x/(x+1) );\nTestYacas( Simplify(1/(1/(1/x+1)+1) ),(x+1)/(2*x+1) );\nTestYacas( Simplify(1/(1/(1/(1/x+1)+1)+1) ),(2*x+1)/(3*x+2) );\nTestYacas( Simplify(1/(1/(1/(1/(1/x+1)+1)+1)+1) ),(3*x+2)/(5*x+3) );\nTestYacas( Simplify(1/(1/(1/(1/(1/(1/x+1)+1)+1)+1)+1) ),(5*x+3)/(8*x+5) );\n\nTestYacas( Simplify(x^2*(1/x)^2+1), 2 );\n\nTestYacas( Simplify((x^2-y^2)/(x+y)), x-y );\n\nTestYacas(Simplify((6*Pi)/(4*Pi)), 3/2);\n\nTestYacas(ExpandFrac(x+y/x+1/3),(x^2+y+x/3)/x);\n\n// this did not work until the latest fix to ExpandBrackets using MM()\nVerify(\nExpandBrackets(x*(a+b)*y*z)\n, x*a*y*z+x*b*y*z\n);\n\nVerify(\nExpandBrackets(ExpandFrac((x+1)/(x-1)+1/x))\n, (x^2+2*x-1)/(x^2-x)\n);\n\n// these used to fail. Added by Serge, resolved by Ayal\nVerify([Local(a);a:=0.1;Simplify(a*b);], 0.1*b);\nVerify([Local(a);a:=0.1;Simplify(a/b);], 0.1/b);\n\n\n// Testing FactorialSimplify\n\nTestYacas(FactorialSimplify((n+1)! / n!),n+1);\nTestYacas(FactorialSimplify((n-k+2)! / (n-k)!),(n-k+2)*(n-k+1));\nTestYacas(FactorialSimplify(2^(n+2)/2^n),4);\nTestYacas(FactorialSimplify((-1)^(n+1)/(-1)^n),-1);\nTestYacas(FactorialSimplify((n+1)! / n! + (n-k+2)! / (n-k)!),n+1 + (n-k+2)*(n-k+1));\n\nTestYacas(FactorialSimplify((n+1)! / n! + (-1)^(n+1)/(-1)^n),n);\n\n/* And now for the piece de resistance: an example from\n   the book \"A=B\"\n */\n\nTestYacas(FactorialSimplify(\n  (\n    (n+1)! / (2*k! *(n+1-k)!) -\n    n! / (k! * (n-k)!)        +\n    n! / (2*k! * (n-k)!)      -\n    n! / (2*(k-1)! * (n-k+1)!)\n  )*(k! *(n+1-k)!)/(n!)\n),0);\n"
  },
  {
    "path": "tests/solve.yts",
    "content": "\n/*\n * VerifySolve(e1, e2) tests whether 'e1' evaluates to something\n * \"equal\" to 'e2', and complains if it doesn't.\n *\n * Here, \"equal\" means:\n *  o  for lists: having the same entries, possibly in a different\n *     order;\n *  o  for equations: having the same right-hand sides, possibly after\n *     'Simplify';\n *  o  in all other cases: equality, possible after 'Simplify'.\n * Hence, { a == 1, a == x+1 } is \"equal\" to { a == 1+x, a == 1 }.\n */\n\nVerifySolve(_e1, _e2) <--\nIf (VerifySolve'Equal(Eval(e1), Eval(e2)),\n    True,\n    [\n      WriteString(\"******************\");    NewLine();\n      ShowLine();                           NewLine();\n      Write(e1);                            NewLine();\n      WriteString(\" evaluates to \");        NewLine();\n      Write(Eval(e1));                      NewLine();\n      WriteString(\" which differs from \");  NewLine();\n      Write(e2);                            NewLine();\n      WriteString(\"******************\");    NewLine();\n      False;\n    ]);\nHoldArgNr(\"VerifySolve\", 2, 1);\n\n10 # VerifySolve'Equal({}, {}) <-- True;\n\n20 # VerifySolve'Equal({}, e2_IsList) <-- False;\n\n30 # VerifySolve'Equal(e1_IsList, e2_IsList) <--\n[\n  Local(i, found);\n  found := False;\n  i := 0;\n  While(i < Length(e2) And Not found) [\n    i++;\n    found := VerifySolve'Equal(Head(e1), e2[i]);\n  ];\n  If (found, VerifySolve'Equal(Tail(e1), Delete(e2, i)), False);\n];\n\n40 # VerifySolve'Equal(_l1 == _r1, _l2 == _r2)\n<-- Equals(l1,l2) And Simplify(r1-r2)=0;\n\n50 # VerifySolve'Equal(_e1, _e2) <-- Simplify(e1-e2) = 0;\n\n/**********************************************************************/\n\nTesting(\"Solve\");\n\nVerify(OldSolve(a+x*y==z,x),(z-a)/y);\nVerify(OldSolve({a+x*y==z},{x}),{{x==(z-a)/y}});\n\n// check that solving systems of equations works, at least at the\n// level of simple back-substitutions\nVerify(Solve({a+x*y==z},{x}),{{x==-(a-z)/y}});\nVerify(Solve({C + x + x}, {x}), {{x==-C/2}});\nVerify(Solve({C * x}, {x}), {{x==0}});\n\n[\n  Local(eq,res);\n  eq:={a-b==c,b==c};\n  res:=Solve(eq,{a,b});\n  Verify(eq Where res,{{c==c,c==c}});\n];\n\nVerifySolve(Solve(a+x*y == z, x), { x == (z-a)/y });\n\nVerifySolve(Solve(x^2-3*x+2, x), { x == 1, x == 2 });\n\nVerifySolve(Solve(2^n == 32, n), { n == Ln(32)/Ln(2) });\n            /* Of course, Ln(32)/Ln(2) = 5 */\n\nVerify(Solve(a * b^x == c, x), {x==Ln(c/a)/Ln(b)});\n\nVerifySolve(Solve(ArcTan(x^4) == Pi/4, x),\n            { x == 1, x == -1, x == I, x == -I });\n\nVerifySolve(Solve(Exp(x)/(1-Exp(x)) == a, x), {x == Ln(a/(a+1))});\nVerifySolve(Solve(Exp(x)/(1-Exp(x)) == a, a), {a == Exp(x)/(1-Exp(x))});\n\nVerifySolve(Solve(x^5 == 1, x),\n            { x == 1, x == Exp(2/5*I*Pi), x == Exp(4/5*I*Pi),\n              x == Exp(-2/5*I*Pi), x == Exp(-4/5*I*Pi)});\n\nVerifySolve(Solve(x^3 == 1, x),\n            {x==1,x==Complex((-1)/2,Sqrt(3/4)),x==Complex((-1)/2,-Sqrt(3/4))});\n\nVerifySolve(Solve(x^3 == -1, x),\n            {x==Complex(1/2,Sqrt(3/4)),x==(-1),x==Complex(1/2,-Sqrt(3/4))});\n\nVerifySolve(Solve(-x^3 == 1, x),\n            {x==Complex(1/2,Sqrt(3/4)),x==(-1),x==Complex(1/2,-Sqrt(3/4))});\n\nVerifySolve(Solve(-x^3 == -1, x),\n            {x==1,x==Complex((-1)/2,Sqrt(3/4)),x==Complex((-1)/2,-Sqrt(3/4))});\n\nVerifySolve(Solve({x*(y-1)==0,y*(x-1)==0}, {x, y}), {{x==1,y==1},{x==0,y==0}});\n\nVerifySolve(Solve({(x*y)/2-3*a == 0, x^2/4-(3*a)/2 == 0, 45-(3*x+(3*y)/2) == 0}, {x, y, a}),\n            {{x==0,y==30,a==0},{x==10,y==10,a==50/3}});\n\nVerifySolve(Solve({(-2)*(1-x)-400*x*(y-x^2), 200*(y-x^2)}, {x, y}), {{x==1,y==1}});\n\nVerifySolve(Solve(Sqrt(x) == 1, x),  { x == 1 });\nVerifySolve(Solve(Sqrt(x) == -1, x), { });\nVerifySolve(Solve(Sqrt(x) == I, x),  { x == -1 });\nVerifySolve(Solve(Sqrt(x) == -I, x), { });\nVerifySolve(Solve(Sqrt(x) == 0, x),  { x == 0 });\n\nVerifySolve(Solve(x * Ln(x) == 0, x), { x == 1 });\nVerifySolve(Solve(-(10 * c + 3)/(2 * (4 * c^2 - 9)) == -1/(2 * ((2 * c) - (3))), c), { c == 0 });\n\n/* The following equations have in fact infinitely many solutions */\n\nVerifySolve(Solve(Sin(x), x), { x == 0, x == Pi });\n\nVerifySolve(Solve(x*Exp(x), x), { x == 0 });\n\nVerifySolve(Solve(Cos(a)^2 == 1/2, a),\n            { a == Pi/4, a == 3/4*Pi, a == -3/4*Pi, a == -Pi/4 });\n\n/* This goes into an infinite recursion:\n * VerifySolve(Solve(Sin(a*Pi)^2-Sin(a*Pi)/2 == 1/2, a),\n *             { a == 1/2, a == 7/6 });\n */\n\nVerify(IsError(), False);\n\n/* This equation can be solved (the solution is x>0), but the current\n * code does not do this. The least we can expect is that no spurious\n * solutions are returned. */\nVerifySolve(Solve(0^x == 0, x), {});\nVerify(ClearError(\"Solve'Fails\"), True);\nVerify(IsError(), False);\n\n/* This equation could be solved using the Lambert W function */\nVerifySolve(Solve(x^x == 1, x), {});\nVerify(ClearError(\"Solve'Fails\"), True);\nVerify(IsError(), False);\n\n/* Another equation which cannot be solved at the moment */\nVerifySolve(Solve(BesselJ(1,x), x), {});\nVerify(ClearError(\"Solve'Fails\"), True);\nVerify(IsError(), False);\n\n/* And another one */\nVerifySolve(Solve(Exp(x)+Cos(x) == 3, x), {});\nVerify(ClearError(\"Solve'Fails\"), True);\nVerify(IsError(), False);\n\n/* This equation could be solved if we knew that x >= 0 */\nVerifySolve(Solve(Sqrt(x) == a, x),  { });\nVerify(ClearError(\"Solve'Fails\"), True);\nVerify(IsError(), False);\n\n/* Test the type-checking mechanism */\nVerifySolve(Solve(2*x == 1, 1), {});\nVerify(ClearError(\"Solve'TypeError\"), True);\nVerify(IsError(), False);\n\n/* This command is clearly nonsense, but it used to send Yacas in an\n * infinite recursion, which should never happen.  Note that 'D(y)x == 0'\n * is parsed as 'D(y)(x==0)'. */\nVerifySolve(Solve(D(y)(x == 0), x),  { });\nVerify(ClearError(\"Solve'Fails\"), True);\nVerify(IsError(), False);\n\n/**********************************************************************/\n\nTesting(\"PSolve\");\n\n/* Linear equations */\n\nVerifySolve(PSolve(x,x), 0);\nVerifySolve(PSolve(x+3*Sin(b)-1,x), 1-3*Sin(b));\nVerifySolve(PSolve(2*x-a,x), a/2);\nVerifySolve(PSolve(2*x-a,a), 2*x);\n\n/* Quadratic equations */\n\nVerifySolve(PSolve(x^2,x), {0,0});\nVerifySolve(PSolve(4*x^2-1,x), {1/2,-1/2});\nVerifySolve(PSolve(x^2+1,x), {I,-I});\nVerifySolve(PSolve(x^2-3*x+2,x), {1,2});\n\n/* Cubic equations */\n\nVerifySolve(PSolve(x^3,x), {0,0,0});\nVerifySolve(PSolve(x^3-1,x), {1, Exp(2/3*Pi*I), Exp(-2/3*Pi*I)});\nVerifySolve(PSolve(x^3+1,x), {-1, Exp(1/3*Pi*I), Exp(-1/3*Pi*I)});\nVerifySolve(PSolve(x^3-3*x^2+2*x,x), {0,1,2});\n\n/* Quartic equations */\n\nVerifySolve(PSolve(x^4,x), {0,0,0,0});\n// The result is not simplified correctly\n//VerifySolve(PSolve(16*x^4-1,x), {1/2, -1/2, 1/2*I, -1/2*I});\nVerifySolve(PSolve(x^4-x,x), {0, 1, Exp(2/3*Pi*I), Exp(-2/3*Pi*I)});\nVerifySolve(PSolve(x^4+x,x), {0, -1, Exp(1/3*Pi*I), Exp(-1/3*Pi*I)});\n/* Yacas has difficulties with more complicated equations, like the\n * biquadratic x^4 - 3*x^2 + 2. */\n\n/* Added the ability to Solve and Where to handle expressions more complex than just variables.\n   One can now Solve for say x[1], or Sin(x) (it only uses a simple comparison for now though).\n   The following test just assures that that will never break.\n */\nVerify(Simplify(x[1]-4*x[2]+x[3] Where (Solve({x[1]-4*x[2]+x[3]==0},{x[2]}))),{0});\n\n// check for possible name clashes\nVerify(({a,b,var,body} Where x==1 And y==1),{a,b,var,body});\n\n/*TODO MatrixSolve */\n"
  },
  {
    "path": "tests/sturm.yts",
    "content": "/*\n TESTS:\n - random-test code for roots, be generating random roots and\n   multiplicities.\n - find an example where bisection is needed, or better, a group\n   of examples where bisection is needed, for tests\n - GarbageCollect in TryRandomPoly causes some corruption, as is\n   visible when turning show file/line on.\n*/\n\nBuiltin'Precision'Set(5);\n\nVerifyZero(x) := (Abs(x)<10^ -Builtin'Precision'Get());\n\nTryRandomPoly(deg,coefmin,coefmax):=\n[\n  //GarbageCollect();\n  Local(coefs,p,roots,px);\n  coefs:=Table(MathFloor(coefmin+Random()*(coefmax-coefmin)),i,1,deg+1,1);\n  p:=Add(coefs*x^(0 .. deg));\n  p:=Rationalize(p);\n//Echo(\"Test polynom \",p);\n  Verify(Max(Abs(coefs))<=MaximumBound(p));\n  Verify(Min(Abs(coefs))>MinimumBound(p));\n//Echo(\"bounds \",BoundRealRoots(p));\n  roots:=FindRealRoots(p);\n//Echo(\"roots \",roots);\n  px := (p Where x==x);\n  Verify(px . px < 0.01);\n];\nTryRandomRoots(deg,coefmin,coefmax):=\n[\n  //GarbageCollect();\n  Local(coefs,p,roots,px,mult);\n  coefs:=RemoveDuplicates(Table(MathFloor(coefmin+Random()*(coefmax-coefmin)),i,1,deg+1,1));\n  deg:=Length(coefs)-1;\n  mult:=1+Abs(Table(MathFloor(coefmin+Random()*(coefmax-coefmin)),i,1,deg+1,1));\n  p:=Factorize((x-coefs)^mult);\n  p:=Rationalize(p);\n  Echo(\"Test polynom \",p);\n  Echo(\"minimum \",MinimumBound(p));\n  Echo(\"maximum \",MaximumBound(p));\n  Echo(\"bounds \",BoundRealRoots(p));\n  roots:=FindRealRoots(p);\n  Echo(\"roots \",roots);\n  Verify(Length(roots) = Length(coefs));\n  Verify(Length(RemoveDuplicates(roots)) = Length(coefs));\n  px := (p Where x==x);\n  Verify(px . px < 0.01);\n];\n\n[\n  Local(p);\n  p := FindRealRoots((x+2)^9*(x-4)^5*(x-1)^4)-{-2.,1.,4.};\n  If(Interpreter() = \"yacas\",\n    Verify(VerifyZero(p . p),True)\n  );\n];\n\n/*TODO\nTryRandomRoots(3,-10,10);\nTryRandomRoots(3,-10,10);\nTryRandomRoots(5,5,1000);\nTryRandomRoots(5,5,1000);\n*/\n\n// Bounds on coefficients\nVerify(MinimumBound(4),-Infinity);\nVerify(MaximumBound(4),Infinity);\n\n// NumRealRoots\nVerify(NumRealRoots(x^2-1),2);\nVerify(NumRealRoots(x^2+1),0);\n\n[\n  Local(p);\n  p:=FindRealRoots(Expand((x*(x-10)^3*(x+2)^2)))-{0,-2.,10.};\n  Verify(VerifyZero(p . p),True);\n];\nVerify(FindRealRoots((x^2+20)*(x^2+10)),{});\nVerify(NumRealRoots((x^2+20)*(x^2+10)),0);\n\n// Simple test on Squarefree\nTestYacas(Monic(SquareFree((x-1)^2*(x-3)^3)),Monic((x-1)*(x-3)));\n\n// Check the rare case where the bounds finder lands on\n// exactly a root\n[\n  Local(p);\n  p:=FindRealRoots((x+4)*(x-6),1,7)-{-4.,6.};\n  Verify(VerifyZero(p . p),True);\n];\n\n[\n  Local(p);\n\n  p:=Expand((x-3.1)*(x+6.23));\n  p:=FindRealRoots(p)-{-6.23,3.1};\n  Verify(VerifyZero(p . p),True);\n];\n\nVerify(Builtin'Precision'Get(),5);\n[\n  Local(res);\n  res:=FindRealRoots(Expand((x-3.1)*(x+6.23)))-{-6.23,3.1};\n  Verify(VerifyZero(res . res) , True);\n];\n\nTryRandomPoly(5,5,1000);\nTryRandomPoly(5,5,1000);\nTryRandomPoly(5,5,1000);\nTryRandomPoly(5,5,1000);\nTryRandomPoly(5,5,1000);\nTryRandomPoly(5,5,1000);\n"
  },
  {
    "path": "tests/sums.yts",
    "content": "\nVerify(Table(Fibonacci(i), i, 1, 10, 1), {1,1,2,3,5,8,13,21,34,55});\n\nTestYacas( Sum(k,1,n,k), n*(n+1)/2 );\nVerify( Simplify(Sum(k,1,n,k^3)), Simplify( (n*(n+1))^2 / 4 ) );\nVerify( Sum(k,1,Infinity,1/k^2), Zeta(2) );\nVerify( Sum(k,1,Infinity,1/k), Infinity );\nVerify( Sum(i,1,Infinity,1/i), Infinity );\nVerify( Sum(k,1,Infinity,Sqrt(k)), Infinity );\nVerify( Sum(k,2,Infinity,x^k/k!), Exp(x)-(x+1) );\nVerify( Sum(k,1,n,Sin(a)+Sin(b)+p),(Sin(a)+Sin(b)+p)*n );\nVerify( Sum(i, 0, n-1, r^i), (1-r^(n-1+1))/(1-r) );\n\n// New tests for Sum() ->\nVerify( Sum(k,0,n,k), n*(n+1)/2 );\nVerify( Sum(k,1,n,k), (n^2+n)/2 );\nTestYacas( Sum(k,0,n,k), Sum(k,1,n,k) );\n\nVerify( Sum(k,0,n,2*k), n*(n+1) );\nVerify( Sum(k,1,n,2*k), n^2+n );\nTestYacas( Sum(k,0,n,2*k), Sum(k,1,n,2*k) );\n\n// Geometric sums\nVerify( Sum(i, 0, n, r^i), (1-r^(n+1))/(1-r) );\nVerify( Sum(i, 0, n-1, r^i), (1-r^(n-1+1))/(1-r) );\nVerify( Sum(i, 1, n, r^i), (r-r^(n+1))/(1-r) );\nVerify( Sum(i, 1, n-1, r^i), (r-r^n)/(1-r) );\nVerify( Sum(i, 0, n, i^0), n+1 );\n\n// Sums of powers\nTestYacas( Sum(i, 1, n, i^2), n*(n+1)*(2*n+1)/6 );\nTestYacas( Sum(i, 1, n, i^3), (n*(n+1))^2 / 4 );\n// starting from 0 or 1 gives the same:\nTestYacas( Sum(i, 0, n, i^2), n*(n+1)*(2*n+1)/6 );\nTestYacas( Sum(i, 0, n, i^3), (n*(n+1))^2 / 4 );\nTestYacas( Sum(i, 0, n, i^2), Sum(i, 1, n, i^2) );\nTestYacas( Sum(i, 0, n, i^4), Sum(i, 1, n, i^4 ) );\n\n// Harmonic sums\nVerify( Sum(i, 0, n, 1/i), Undefined );\nVerify( Sum(i, 0, n, a/i), Undefined );\nVerify( Sum(i, 1, n, 1/i), HarmonicNumber(n) );\nVerify( Sum(i, 1, n, a/i), a*HarmonicNumber(n) );\n\n// Low-order polylogarithms\nVerify( Sum(i, 0, n, z^i), (1-z^(n+1))/(1-z) ); // Geometric\nVerify( Sum(i, 1, n, i*z^i), z*(1-(n+1)*z^n + n*z^(n+1))/(1-z)^2 );\nVerify( Sum(i, 1, n, i^2 * z^i), (z*(1+z-((n+1)^2)*(z^n) + (2*(n^2)+2*n-1)*z^(n+1) - (n^2)*z^(n+2))/(1-z)^3) );\n// <- New tests for Sum()\n\n\n\nVerify(Add({1,2,3,4}), 10);\nVerify(Add({1}), 1);\nVerify(Add({}), 0);\nVerify(Add(1,2,3,4), 10);\nVerify(Add(1), 1);\nVerify(Add(), Add());\n[\n  Local(list);\n  list:={1,2,3,4,5};\n  Verify(Add(list)/Length(list), 3);\n  list:={0};\n  Verify(Add(list)/Length(list), 0);\n  list:={};\n  Verify(Add(list)/Length(list), Undefined);\n];\n\nVerify(Min(0,1),0);\nVerify(Min({}), Undefined);\nVerify(Min({x}), x);\nVerify(Min(x), x);\nVerify(Min(Exp(x)), Exp(x));\nVerify(Min({1,2,3}), 1);\n// since Min(multiple args) is disabled, comment this out\nVerify(Min(1,2,3), 1);\nVerify(Min(1,2,0), 0);\nVerify(Min(5,2,3,4), 2);\nVerify(Min(5,2,0,4), 0);\n\n// ------------------------------------------------------------\n\nTesting(\"Taylor\");\n\n// Black-box testing\n\nVerify(Taylor2(x,0,9) Sin(x), x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880);\nVerify(Taylor2(x,0,6) Cos(x), 1 - x^2/2 + x^4/24 - x^6/720);\nVerify(Taylor2(x,0,6) Exp(x),\n       1 + x + x^2/2 + x^3/6 + x^4/24 + x^5/120 + x^6/720);\nVerify(Taylor2(x,1,6) 1/x,\n       1 - (x-1) + (x-1)^2 - (x-1)^3 + (x-1)^4 - (x-1)^5 + (x-1)^6);\nVerify(Taylor2(x,1,6) Ln(x),\n       (x-1) - (x-1)^2/2 + (x-1)^3/3 - (x-1)^4/4 + (x-1)^5/5 - (x-1)^6/6);\nVerify(Taylor2(x,0,6) x/(Exp(x)-1),\n       1 - x/2 + x^2/12 - x^4/720 + x^6/30240);\nVerify(Taylor2(x,0,6) Sin(x)^2+Cos(x)^2, 1);\nTestYacas(Taylor2(x,0,14) Sin(Tan(x)) - Tan(Sin(x)),\n          -1/30*x^7 - 29/756*x^9 - 1913/75600*x^11 - 95/7392*x^13);\nTestYacas((Taylor2(t,a+1,2) Exp(c*t)),\n          Exp(c*(a+1)) + c*Exp(c*(a+1))*(t-a-1) \n                       + c^2*Exp(c*(a+1))*(t-a-1)^2/2);\n\n// Consistency checks\n\nTestYacas(Taylor2(x,0,7) (Sin(x)+Cos(x)),\n          (Taylor2(x,0,7) Sin(x)) + (Taylor2(x,0,7) Cos(x)));\nTestYacas(Taylor2(x,0,7) (a*Sin(x)),\n          a * (Taylor2(x,0,7) Sin(x)));\nTestYacas(Taylor2(x,0,7) (Sin(x)-Cos(x)),\n          (Taylor2(x,0,7) Sin(x)) - (Taylor2(x,0,7) Cos(x)));\nTestYacas(Taylor2(x,0,7) (Sin(x)*Cos(x)),\n          Taylor2(x,0,7) ((Taylor2(x,0,7) Sin(x)) * (Taylor2(x,0,7) Cos(x))));\nTestYacas(Taylor2(x,0,7) (Sin(x)/Ln(1+x)), \n          Taylor2(x,0,7) ((Taylor2(x,0,8) Sin(x)) / Taylor2(x,0,8) Ln(1+x)));\nTestYacas(Taylor2(t,0,7) (Sin(t)^2),\n          Taylor2(t,0,7) ((Taylor2(t,0,7) Sin(t))^2));\nTestYacas(Taylor2(x,0,7) Cos(Ln(x+1)),\n          Taylor2(x,0,7) (Subst(y,Taylor2(x,0,7)Ln(x+1)) Cos(y)));\n\n100 # Taylor'LPS'CompOrder(_x, jn(_x)) <-- 5;\n100 # Taylor'LPS'CompCoeff(_x, jn(_x), _k) <-- Atom(\"jn\":String(k));\n\nVerify(Taylor2(t,0,8) jn(t), jn5*t^5 + jn6*t^6 + jn7*t^7 + jn8*t^8);\nVerify((Taylor2(x,0,10) Exp(jn(x))),\n       1 + jn5*x^5 + jn6*x^6 + jn7*x^7 + jn8*x^8 \n         + jn9*x^9 + (jn10+jn5^2/2)*x^10);\n\n// Some examples of power series\nLocalSymbols(p1,p2,p3,p4,p0,pj,pp,pju0,pj40,pj50,pj51,pj52,pj53,pj54,pc24,pc35,pc46,pc57,pc68) [\np1 := Taylor'LPS(0, {1,1,1/2,1/6}, x, Exp(x));\np2 := Taylor'LPS(1, {1,0,-1/6,0,1/120,0}, t, Sin(t));\np3 := Taylor'LPS(0, {a0,a1,a2,a3}, x, foo(x));\np4 := Taylor'LPS(-2, {1,0,-1/2,0,1/24}, x, Cos(x)/x^2);\np0 := Taylor'LPS(Infinity, {}, x, 0); // special case: zero\n\n// Taylor'LPS should not evaluate\n\nVerify(p1, Hold(Taylor'LPS(0, {1,1,1/2,1/6}, x, Exp(x))));\n\n// Taylor'LPS'Coeffs can get pre-computed coefficients\n\nVerify(Taylor'LPS'Coeffs(p1, 0, 3), {1,1,1/2,1/6});\nVerify(Taylor'LPS'Coeffs(p1, -3, -1), {0,0,0});\nVerify(Taylor'LPS'Coeffs(p2, -1, 3), {0,0,1,0,-1/6});\nVerify(Taylor'LPS'Coeffs(p3, 0, 3), {a0,a1,a2,a3});\nVerify(Taylor'LPS'Coeffs(p4, -1, 1), {0,-1/2,0});\nVerify(Taylor'LPS'Coeffs(p0, 1, 5), {0,0,0,0,0});\n\n// Conversion to power series \n\nVerify(Taylor'LPS'PowerSeries(p1, 3, x), 1+x+x^2/2+x^3/6);\nVerify(Taylor'LPS'PowerSeries(p2, 4, t), t-t^3/6);\nVerify(Taylor'LPS'PowerSeries(p3, 3, s), a0+a1*s+a2*s^2+a3*s^3);\nVerify({Taylor'LPS'PowerSeries(p4, 2, x), ClearError(\"singularity\")}, \n       {Undefined, True});\nVerify(Taylor'LPS'PowerSeries(p0, 3, x), 0);\n\n// Construction of new LPS\n\nVerify(Taylor'LPS'Construct(x, 1), Taylor'LPS(Undefined, {}, x, 1));\n\n// Taylor'LPS'Coeffs can compute new coefficients in-place\n\nVerify(Taylor'LPS'Coeffs(p1, 0, 4), {1,1,1/2,1/6,1/24});\nVerify(p1, Taylor'LPS(0, {1,1,1/2,1/6,1/24}, x, Exp(x)));\np1 := Taylor'LPS(0, {1,1,1/2,1/6}, x, Exp(x));\n\nVerify(Taylor'LPS'Coeffs(Taylor'LPS'Construct(x, 1), 0, 7),\n       {1, 0, 0, 0, 0, 0, 0, 0});\nVerify(Taylor'LPS'Coeffs(Taylor'LPS'Construct(x, 0), 0, 7),\n       {0, 0, 0, 0, 0, 0, 0, 0});\nVerify(Taylor'LPS'Coeffs(Taylor'LPS'Construct(x, 1/x), 0, 7),\n       {0, 0, 0, 0, 0, 0, 0, 0}); \nVerify(Taylor'LPS'Coeffs(Taylor'LPS'Construct(x, x^2), 0, 7),\n       {0, 0, 1, 0, 0, 0, 0, 0});\nVerify(Taylor'LPS'Coeffs(Taylor'LPS'Construct(x, Exp(x)), 0, 7),\n       {1, 1, 1/2, 1/6, 1/24, 1/120, 1/720, 1/5040});\nVerify(Taylor'LPS'Coeffs(Taylor'LPS'Construct(x, Ln(1+x)), 0, 7),\n       {0, 1, -1/2, 1/3, -1/4, 1/5, -1/6, 1/7});\nVerify(Taylor'LPS'Coeffs(Taylor'LPS'Construct(x, Sin(x)), 0, 7),\n       {0, 1, 0, -1/6, 0, 1/120, 0, -1/5040});\nVerify(Taylor'LPS'Coeffs(Taylor'LPS'Construct(x, Cos(x)), 0, 7),\n       {1, 0, -1/2, 0, 1/24, 0, -1/720, 0});\n\n// Check order of power series\n\nVerify(Taylor'LPS'GetOrder(p1), {0,True});\nVerify(Taylor'LPS'GetOrder(Taylor'LPS'Construct(x, Cos(x))), {0,True});\nVerify(Taylor'LPS'GetOrder(Taylor'LPS'Construct(x, Sin(x))), {1,True});\nVerify(Taylor'LPS'GetOrder(Taylor'LPS'Construct(x, x-Sin(x))), {1,False});\nVerify(Taylor'LPS'GetOrder(Taylor'LPS'Construct(x, 1/x)), {-1,True});\n\n// User-defined power series\n\npju0 := Taylor'LPS(Undefined, {}, x, jn(x));\npj40 := Taylor'LPS(5, {}, x, jn(x));\npj50 := Taylor'LPS(5, {}, x, jn(x));\npj51 := Taylor'LPS(5, {jn5}, x, jn(x));\npj52 := Taylor'LPS(5, {jn5,jn6}, x, jn(x));\npj53 := Taylor'LPS(5, {jn5,jn6,jn7}, x, jn(x));\npj54 := Taylor'LPS(5, {jn5,jn6,jn7,jn8}, x, jn(x));\n\npc24 := {0,0,0};\npc35 := {0,0,jn5};\npc46 := {0,jn5,jn6};\npc57 := {jn5,jn6,jn7};\npc68 := {jn6,jn7,jn8};\n\ntlc(_a,_b,_c) <-- Taylor'LPS'Coeffs(a,b,c);  // abbreviation\n\npj := FlatCopy(pju0); Verify(tlc(pj,2,4), pc24); Verify(pj, pj50);\npj := FlatCopy(pju0); Verify(tlc(pj,3,5), pc35); Verify(pj, pj51);\npj := FlatCopy(pju0); Verify(tlc(pj,4,6), pc46); Verify(pj, pj52);\npj := FlatCopy(pju0); Verify(tlc(pj,5,7), pc57); Verify(pj, pj53);\npj := FlatCopy(pju0); Verify(tlc(pj,6,8), pc68); Verify(pj, pj54);\n\npj := FlatCopy(pj40); Verify(tlc(pj,2,4), pc24); Verify(pj, pj50);\npj := FlatCopy(pj40); Verify(tlc(pj,3,5), pc35); Verify(pj, pj51);\npj := FlatCopy(pj40); Verify(tlc(pj,4,6), pc46); Verify(pj, pj52);\npj := FlatCopy(pj40); Verify(tlc(pj,5,7), pc57); Verify(pj, pj53);\npj := FlatCopy(pj40); Verify(tlc(pj,6,8), pc68); Verify(pj, pj54);\n\npj := FlatCopy(pj50); Verify(tlc(pj,2,4), pc24); Verify(pj, pj50);\npj := FlatCopy(pj50); Verify(tlc(pj,3,5), pc35); Verify(pj, pj51);\npj := FlatCopy(pj50); Verify(tlc(pj,4,6), pc46); Verify(pj, pj52);\npj := FlatCopy(pj50); Verify(tlc(pj,5,7), pc57); Verify(pj, pj53);\npj := FlatCopy(pj50); Verify(tlc(pj,6,8), pc68); Verify(pj, pj54);\n\npj := FlatCopy(pj51); Verify(tlc(pj,2,4), pc24); Verify(pj, pj51);\npj := FlatCopy(pj51); Verify(tlc(pj,3,5), pc35); Verify(pj, pj51);\npj := FlatCopy(pj51); Verify(tlc(pj,4,6), pc46); Verify(pj, pj52);\npj := FlatCopy(pj51); Verify(tlc(pj,5,7), pc57); Verify(pj, pj53);\npj := FlatCopy(pj51); Verify(tlc(pj,6,8), pc68); Verify(pj, pj54);\n\npj := FlatCopy(pj52); Verify(tlc(pj,2,4), pc24); Verify(pj, pj52);\npj := FlatCopy(pj52); Verify(tlc(pj,3,5), pc35); Verify(pj, pj52);\npj := FlatCopy(pj52); Verify(tlc(pj,4,6), pc46); Verify(pj, pj52);\npj := FlatCopy(pj52); Verify(tlc(pj,5,7), pc57); Verify(pj, pj53);\npj := FlatCopy(pj52); Verify(tlc(pj,6,8), pc68); Verify(pj, pj54);\n\npj := FlatCopy(pj53); Verify(tlc(pj,2,4), pc24); Verify(pj, pj53);\npj := FlatCopy(pj53); Verify(tlc(pj,3,5), pc35); Verify(pj, pj53);\npj := FlatCopy(pj53); Verify(tlc(pj,4,6), pc46); Verify(pj, pj53);\npj := FlatCopy(pj53); Verify(tlc(pj,5,7), pc57); Verify(pj, pj53);\npj := FlatCopy(pj53); Verify(tlc(pj,6,8), pc68); Verify(pj, pj54);\n\npj := FlatCopy(pj54); Verify(tlc(pj,2,4), pc24); Verify(pj, pj54);\npj := FlatCopy(pj54); Verify(tlc(pj,3,5), pc35); Verify(pj, pj54);\npj := FlatCopy(pj54); Verify(tlc(pj,4,6), pc46); Verify(pj, pj54);\npj := FlatCopy(pj54); Verify(tlc(pj,5,7), pc57); Verify(pj, pj54);\npj := FlatCopy(pj54); Verify(tlc(pj,6,8), pc68); Verify(pj, pj54);\n\n// Addition\n\npp := Taylor'LPS(Undefined, {}, x, \n                 Taylor'LPS'Add(FlatCopy(p1), FlatCopy(p3)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 3), {1+a0,1+a1,1/2+a2,1/6+a3});\nVerify(pp, Taylor'LPS(0, {1+a0,1+a1,1/2+a2,1/6+a3}, x, \n                      Taylor'LPS'Add(p1,p3)));\n\npp := Taylor'LPS(0, {1+a0}, x, \n                 Taylor'LPS'Add(FlatCopy(p1), FlatCopy(p3)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 3), {1+a0,1+a1,1/2+a2,1/6+a3});\nVerify(pp, Taylor'LPS(0, {1+a0,1+a1,1/2+a2,1/6+a3}, x, \n                      Taylor'LPS'Add(p1,p3)));\n\npp := Taylor'LPS'Construct(x, 1+Ln(x+1));\nVerify(Taylor'LPS'Coeffs(pp, 0, 4), {1, 1, -1/2, 1/3, -1/4});\nVerify(pp, Taylor'LPS(0, {1,1,-1/2,1/3,-1/4}, x, Taylor'LPS'Add(pp2,pp1))\n           Where {pp1 == Taylor'LPS(0, {1,0,0,0,0}, x, 1),\n                  pp2 == Taylor'LPS(1, {1,-1/2,1/3,-1/4}, x, Ln(x+1))});\n                      \npp := Taylor'LPS'Construct(a, Exp(a)+jn(a));\nVerify(Taylor'LPS'Coeffs(pp, -1, 5), {0, 1, 1, 1/2, 1/6, 1/24, 1/120+jn5});\nVerify(pp, Taylor'LPS(0, {1, 1, 1/2, 1/6, 1/24, 1/120+jn5}, \n                      a, Taylor'LPS'Add(pp1,pp2))\n           Where {pp1 == Taylor'LPS(0, {1,1,1/2,1/6,1/24,1/120}, a, Exp(a)),\n                  pp2 == Taylor'LPS(5, {jn5}, a, jn(a))});\n\n// Scalar multiplication\n\npp := Taylor'LPS(Undefined, {}, x, Taylor'LPS'ScalarMult(5, FlatCopy(p1)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 3), {5,5,5/2,5/6});\nVerify(pp, Taylor'LPS(0, {5,5,5/2,5/6}, x, Taylor'LPS'ScalarMult(5,p1)));\n\npp := Taylor'LPS(0, {5,5}, x, Taylor'LPS'ScalarMult(5, FlatCopy(p1)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 3), {5,5,5/2,5/6});\nVerify(pp, Taylor'LPS(0, {5,5,5/2,5/6}, x, Taylor'LPS'ScalarMult(5,p1)));\n\npp := Taylor'LPS'Construct(t, (-2)*Sin(t));\nVerify(Taylor'LPS'Coeffs(pp, -1, 4), {0, 0, -2, 0, 1/3, 0});\nVerify(pp, Taylor'LPS(1, {-2,0,1/3,0}, t, Taylor'LPS'ScalarMult(-2, pp1))\n           Where pp1 == Taylor'LPS(1, {1,0,-1/6,0}, t, Sin(t))); \n\n// Subtraction\n\npp := Taylor'LPS'Construct(x, Exp(x)-Cos(x)); \n      // zero order term cancels!\nVerify(Taylor'LPS'Coeffs(pp, 0, 4), {0, 1, 1, 1/6, 0});\nVerify(pp, Taylor'LPS(1, {1,1,1/6,0}, x, Taylor'LPS'Add(pp1, pp2))\n           Where pp1 == Taylor'LPS(0, {1,1,1/2,1/6,1/24}, x, Exp(x))\n           Where pp2 == Taylor'LPS(0, {-1,0,1/2,0,-1/24}, x, \n                                   Taylor'LPS'ScalarMult(-1, pp3))\n           Where pp3 == Taylor'LPS(0, {1,0,-1/2,0,1/24}, x, Cos(x)));\n           \n// Multiplication\n\npp := Taylor'LPS(Undefined, {}, x, \n                 Taylor'LPS'Multiply(FlatCopy(p1), FlatCopy(p3)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 2), {a0, a1+a0, a2+a1+1/2*a0});\nVerify(pp, Taylor'LPS(0, {a0, a1+a0, a2+a1+1/2*a0}, x, \n                      Taylor'LPS'Multiply(p1,p3)));\n\npp := Taylor'LPS(0, {a0}, x, \n                 Taylor'LPS'Multiply(FlatCopy(p1), FlatCopy(p3)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 2), {a0, a1+a0, a2+a1+1/2*a0});\nVerify(pp, Taylor'LPS(0, {a0, a1+a0, a2+a1+1/2*a0}, x, \n                      Taylor'LPS'Multiply(p1,p3)));\n\npp := Taylor'LPS'Construct(x, x^2*Ln(x+1));\nVerify(Taylor'LPS'Coeffs(pp, 0, 4), {0, 0, 0, 1, -1/2});\nVerify(pp, Taylor'LPS(3, {1,-1/2}, x, Taylor'LPS'Multiply(pp1,pp2))\n           Where {pp1 == Taylor'LPS(2, {1,0}, x, x^2),\n                  pp2 == Taylor'LPS(1, {1,-1/2}, x, Ln(x+1))});\n                      \n// Inversion\n\npp := Taylor'LPS(Undefined, {}, x, Taylor'LPS'Inverse(FlatCopy(p1)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 3), {1,-1,1/2,-1/6});\nVerify(pp, Taylor'LPS(0, {1,-1,1/2,-1/6}, x, Taylor'LPS'Inverse(p1)));\n\npp := Taylor'LPS(Undefined, {}, t, Taylor'LPS'Inverse(FlatCopy(p2)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 2), {0,1/6,-0});\nVerify(pp, Taylor'LPS(-1, {1,0,1/6,0}, t, Taylor'LPS'Inverse(p2)));\n\npp := Taylor'LPS(Undefined, {}, x, Taylor'LPS'Inverse(FlatCopy(p0)));\nVerify([Taylor'LPS'Coeffs(pp, 0, 0); ClearError(\"div-by-zero\");], True);\n\npp := Taylor'LPS'Construct(x, 1/jn(x));\nVerify(Taylor'LPS'Coeffs(pp, -7, -4), {0,0,1/jn5,-jn6/jn5^2});\nVerify(pp, Taylor'LPS(-5, {1/jn5,-jn6/jn5^2}, x, Taylor'LPS'Inverse(pp1))\n           Where pp1 == Taylor'LPS(5, {jn5,jn6}, x, jn(x)));\n\npp := Taylor'LPS'Construct(x, 1/(Cos(x)^2+Sin(x)^2-1));\nVerify([Taylor'LPS'Coeffs(pp, 0, 5); ClearError(\"maybe-div-by-zero\");], True);\n\n// Division\n\npp := Taylor'LPS'Construct(x, Exp(x)/Cos(x)); \nVerify(Taylor'LPS'Coeffs(pp, 0, 4), {1, 1, 1, 2/3, 1/2});\nVerify(pp, Taylor'LPS(0, {1,1,1,2/3,1/2}, x, Taylor'LPS'Multiply(pp1, pp2))\n           Where pp1 == Taylor'LPS(0, {1,1,1/2,1/6,1/24}, x, Exp(x))\n           Where pp2 == Taylor'LPS(0, {1,0,1/2,0,5/24}, x, \n                                   Taylor'LPS'Inverse(pp3))\n           Where pp3 == Taylor'LPS(0, {1,0,-1/2,0,1/24}, x, Cos(x)));\n\n// Raising to a natural power\n\n// No tests (Taylor'LPS'Power is not implemented yet)\n \n// Composition\n\nVerify(Taylor'LPS'Construct(x, Ln(Sin(x))),\n       Taylor'LPS(Undefined, {}, x, Taylor'LPS'Compose(pp1,pp2))\n       Where {pp1 == Taylor'LPS(Undefined, {}, x, Ln(x)),\n\t      pp2 == Taylor'LPS(1, {}, x, Sin(x))});\n\nVerify(Taylor'LPS'Construct(x, Ln(Cos(x))),\n       Taylor'LPS(Undefined, {}, x, Taylor'LPS'Compose(pp1,pp2))\n       Where {pp1 == Taylor'LPS(Undefined, {}, x, Ln(1+x)),\n\t      pp2 == Taylor'LPS(Undefined, {}, x, Taylor'LPS'Add(pp3,pp4)),\n\t      pp3 == Taylor'LPS(0, {1}, x, Cos(x)),\n\t      pp4 == Taylor'LPS(Undefined, {}, x, -1)});\n\npp := Taylor'LPS(Undefined, {}, x, \n                 Taylor'LPS'Compose(FlatCopy(p1), FlatCopy(p2)));\nVerify(Taylor'LPS'Coeffs(pp, 0, 3), {1, 1, 1/2, 0});\nVerify(pp, Taylor'LPS(0, {1,1,1/2,0}, x, Taylor'LPS'Compose(p1,p2)));\n\n]; // LocalSymbols(p*)\n\n"
  },
  {
    "path": "tests/tensors.yts",
    "content": "\n\nNextTest(\"Tensors\");\n\nTestYacas(TSimplify( TSum({j}) Delta(i,j)*v(j) ),v(i));\nTestYacas(TSimplify( TSum({j,i}) Delta(i,j)*Delta(i,j) ), Ndim);\nTestYacas(TSimplify( TSum({j,i}) Delta(i,j)*Delta(j,i) ), Ndim);\nTestYacas(TSimplify( TSum({j}) Delta(i,j)*Delta(j,k) ), Delta(i,k));\nTestYacas(TSimplify( TSum({i}) v(i)*v(i) ), TSum({i})(v(i)^2));\nRetract(\"v\",1);\nRuleBase(\"v\",{ii});\nf(i,j):=v(i)*v(j);\nTestYacas(f(i,i),v(i)^2);\nTestYacas(TSimplify( TSum({i}) f(i,i) ),TSum({i})(v(i)^2));\nTestYacas(TSimplify( TSum({j}) Delta(i,j)*f(j,k) ),v(i)*v(k));\n\nTestYacas(TSimplify(TSum({i,j}) Delta(i,j)*f(i,j) ),  TSum({j})v(j)^2);\nTestYacas(TSimplify(TSum({i})X(j)*TD(i)X(i)),  Ndim*X(j));\nTestYacas(TSimplify(TSum({i}) TD(i)(X(i)*X(j)) ), Ndim*X(j)+X(j));\nTestYacas(TSimplify(TSum({i}) X(i)*TD(i)X(j) ), X(j));\nTestYacas(TSimplify(TSum({i})TD(i)v(i)),  TSum({i})TD(i)v(i));\n\nTestYacas(TSimplify(TSum({i,j})TD(i)TD(j)(X(i)*X(j))), Ndim+Ndim^2);\nTestYacas(TSimplify(TSum({i})TD(i)(X(i)*X(j)*X(j))),  Ndim*X(j)^2+2*X(j)^2);\nTestYacas(TSimplify(TSum({i,j,k})TD(i)TD(j)TD(k)(X(i)*X(j)*X(k))),  3*Ndim^2+2*Ndim+Ndim^3);\n\n"
  },
  {
    "path": "tests/test-yacas",
    "content": "#! /bin/bash\n#\n# test-yacas -- Script for testing Yacas\n\n# Give help, if requested\n\nif [ $# -eq 0 ] || [ \"x$1\" = \"x-h\" ] || [ \"x$1\" = \"x--help\" ]; then\n    echo \"Usage: $0 <cmd> <dir> <script>...\"\n    echo \"  cmd       Command plus options, needed to run Yacas\"\n    echo \"  dir       Directory in which scripts reside\"\n    echo \"  script... Test scripts to be run\"\n    echo \"Test script may reside in <dir> or in the current directory\"\n    echo \"Exit status is number of tests scripts which fail\"\n    echo \"Example:\"\n    echo \"  $0 \\\"../src/Debug/yacas --archive ../src/scripts.dat\\\" . short*.yts\"\n    exit 0\nfi\n\n# Parse arguments\n\nif [ $# -lt 2 ]; then\n    echo \"Error: $0: Missing parameters\"\n    exit 255\nfi\n\nCMD=\"$1\"\nSCRIPTDIR=\"$2\"\nshift\nshift\nSCRIPTS=$*\n\n# run the tests\n\nFAILED_TESTS=\"\"  # list of failed tests\nFAILURES=0       # number of failed tests\nTOTALTESTS=0     # total number of tests\n\nTESTFILE=`mktemp`\nTIMEFILE=`mktemp`\nVERSIONF=`mktemp`\nLOGFILE=yacas-logfile.txt\necho \"Print(Version());\" > $VERSIONF\nVERSION=`bash -c \"$CMD $VERSIONF\"`\nCOMMENT=`bash -c \"$CMD $VERSIONF\"`\nrm $VERSIONF\n\necho \"/*\" >> $LOGFILE\necho \"Command = \\\"$CMD\\\"\"      | tee -a $LOGFILE\necho \"Version = $VERSION\"      | tee -a $LOGFILE\necho \"Comment = $COMMENT\"      | tee -a $LOGFILE\necho \"Date = \\\"`date \"+%F %T\"`\\\"\"   | tee -a $LOGFILE\necho \"Logfile = \\\"$LOGFILE\\\"\"  | tee -a $LOGFILE\necho \"*/\" >> $LOGFILE\n\nREALTOT=\"0\"\nUSERTOT=\"0\"\nSYSSTOT=\"0\"\n\nfor scr in $SCRIPTS; do\n    if [ -f $SCRIPTDIR/$scr ]; then\n\t   f=$SCRIPTDIR/$scr\n    else\n\t   f=$scr\n    fi\n#\t\tif grep -i \"interrupt\" $TESTFILE > /dev/null; then\n#\t\t\tPASSFAIL=Interrupted\n#\t\tfi\n    echo \"Running $scr\"\n\tif [ -f $TESTFILE ]; then rm $TESTFILE ; fi\n\t    bash -c \"time -p ($CMD $f || echo \\\"Error: exit status $?\\\") | tee $TESTFILE\" \\\n\t\t2> $TIMEFILE \\\n\t\t|| (echo \"Error -- User interrupt\" > $TESTFILE)\n#\tcat $TIMEFILE\n    if grep -E \"\\*\\*\\*\\*\\*\\*|Error|interrupt\" $TESTFILE > /dev/null; then\n        PASSFAIL=Fail\n        FAILED_TESTS=\"$FAILED_TESTS $scr\"\n        FAILURES=`expr $FAILURES + 1`\n\t\tif grep -i \"interrupt\" $TESTFILE > /dev/null; then\n\t\t\tPASSFAIL=Interrupted\n\t\tfi\n    else\n        PASSFAIL=Pass\n    fi\n    TOTALTESTS=`expr $TOTALTESTS + 1`\n\n    REAL=`grep real $TIMEFILE | sed 's/real//'`\n    USER=`grep user $TIMEFILE | sed 's/user//'`\n    SYSS=`grep sys  $TIMEFILE | sed 's/sys//'`\n    LOGLINE=\"{\\\"$scr\\\", $VERSION, \\\"`date \"+%F %T\"`\\\", $REAL, $USER, $SYSS, $PASSFAIL},\"\n    echo \"$LOGLINE\" | tee -a $LOGFILE\n\n\tREALTOT=\"$REALTOT+$REAL\"\n\tUSERTOT=\"$USERTOT+$USER\"\n\tSYSSTOT=\"$SYSSTOT+$SYSS\"\n### exit\n\ndone\n\nif [ $FAILURES -eq 0 ]; then\n    PASSFAIL=Pass\nelse\n    PASSFAIL=Fail\nfi\nREAL=`bash -c \"$CMD -i \\\"Print(RoundTo($REALTOT,2));\\\"\"`\nUSER=`bash -c \"$CMD -i \\\"Print(RoundTo($USERTOT,2));\\\"\"`\nSYSS=`bash -c \"$CMD -i \\\"Print(RoundTo($SYSSTOT,2));\\\"\"`\nLOGLINE=\"{\\\"Total\\\", $VERSION, \\\"`date \"+%F %T\"`\\\", $REAL, $USER, $SYSS, $PASSFAIL},\"\necho \"$LOGLINE\" | tee -a $LOGFILE\n\nrm $TESTFILE $TIMEFILE\n\n# report\n\nif [ $FAILURES -eq 0 ]; then\n    RES=\"All $TOTALTESTS tests PASSED\"\nelse\n    if [ $FAILURES -eq 1 ]; then\n        echo \"Failed test: $FAILED_TESTS\"\n    else\n        echo \"Failed tests: $FAILED_TESTS\"\n    fi\n    RES=\"$FAILURES of $TOTALTESTS tests FAILED\"\nfi\nEQS=`echo $RES | sed 's/./=/g'`\n\necho \"Command = \\\"$CMD\\\"\"\necho \"Version = $VERSION\"\necho \"Date = \\\"`date \"+%F %T\"`\\\"\"\necho \"Logfile = \\\"$LOGFILE\\\"\"\necho \"/*$EQS\" | tee -a $LOGFILE\nif [ \"x$FAILED_TESTS\" != \"x\" ]; then\n    echo \"Failed = $FAILED_TESTS\" | tee -a $LOGFILE\nfi\necho \" $RES \" | tee -a $LOGFILE\necho \"$EQS*/\" | tee -a $LOGFILE\n\nexit $FAILURES\n"
  },
  {
    "path": "tests/test-yacas.bat",
    "content": "@echo off\n\nsetlocal enabledelayedexpansion\n\nset ARGC=0\nfor %%x in (%*) do set /a ARGC+=1\n\nif %ARGC% equ 0 goto help\nif %ARGC% gtr 1 goto nohelp\n\nif \"%1\" == \"-h\" goto help\nif \"%1\" == \"--help\" goto help\nif \"%1\" == \"/h\" goto help\nif \"%1\" == \"/help\" goto help\n\ngoto nohelp\n\n:help\n\necho usage: %0 ^<cmd^> ^<dir^> ^<script^>...\necho   cmd       Command plus options, needed to run Yacas\necho   dir       Directory in which scripts reside\necho   script... Test scripts to be run\necho Test script may reside in <dir> or in the current directory\necho Exit status is number of tests scripts which fail\n\nexit /b 0\n\n:nohelp\n\nif %ARGC% geq 2 goto enoughparams\n\necho error: %0: missing parameters\nexit /b 255\n\n:enoughparams\n\nset CMD=%~1\nset CMD=%CMD:\\=/%\nset SCRIPTDIR=%2\nshift\nshift\n\nset \"SCRIPTS=\"\n\n:parse\nif \"%~1\" neq \"\" (\n  set SCRIPTS=%SCRIPTS% %1\n  shift\n  goto :parse\n)\nif defined SCRIPTS set SCRIPTS=%SCRIPTS:~1%\n\nset FAILED_TESTS=\nset FAILURES=0\nset TOTALTESTS=0\n\nset PID=123\n\nset TESTFILE=%TEMP%\\test-yacas.%PID%\nset TIMEFILE=%TEMP%\\time-yacas.%PID%\nset VERSIONF=%TEMP%\\version-yacas-%PID%.ys\nset VERSIONF=%VERSIONF:\\=/%\nset LOGFILE=yacas-logfile.txt\necho Print(Version()); > %VERSIONF%\n\nfor /f %%a in ('%CMD% %VERSIONF%') do (\n    if not \"%%a\" == \"Quitting...\" set VERSION=%%a\n)\n\nset COMMENT=!VERSION!\n\necho /* >> %LOGFILE%\necho Command = %CMD% >> %LOGFILE%\necho Version = %VERSION% >> %LOGFILE%\necho Comment = %COMMENT% >> %LOGFILE%\ndate /t >> %LOGFILE%\ntime /t >> %LOGFILE%\necho Logfile = %LOGFILE% >> %LOGFILE%\necho */ >> %LOGFILE%\n\necho Command = %CMD%\necho Version = %VERSION%\necho Comment = %COMMENT%\ndate /t\ntime /t\necho Logfile = %LOGFILE%\n\nset SCRIPTDIR=%SCRIPTDIR:\\=/%\n\nset /a succ=0\nset /a fail=0\n\nfor %%s in (%SCRIPTS%) do (\n\n    set f=%%s\n\n    if exist \"%SCRIPTDIR%/%%s\" set f=%SCRIPTDIR%/%%s\n\n    echo Running %%s\n\n    if exist %TESTFILE% del %TESTFILE%\n\n    %CMD% !f! > %TESTFILE% 2>&1\n\t\n\t\n\tfor %%A in (%TESTFILE%) do set size=%%~zA\n\n\tif !size! equ 0 (\n\t\tset /a succ+=1\n\t\techo OK!\n\t) else (\n\t\n\t\tfor /f \"delims=:\" %%i in ('FINDSTR  /N \"Quitting...\" %TESTFILE%') do set quittingLine=%%i\n\t\t\n\t\tif !quittingLine! equ 1 (\n\t\t\tset /a succ+=1\n\t\t\techo OK\n\t\t) else (\n\t\t\tset /a fail+=1\n\t\t\techo FAILED\n\t\t\ttype %TESTFILE% \n\t\t)\n\t)\n)\n\necho Tests succeeded: %succ%\necho Tests failed: %fail%\n\nexit /b %fail%"
  },
  {
    "path": "tests/tr.yts",
    "content": "//////\n// $Id: tr.yts,v 1.2 2006-03-26 12:49:15 ayalpinkus Exp $\n// Tests for Tr\n//////\n\nTesting(\"-- Tr (trace of tensor)\");\n\nVerify(Tr(a),Hold(Tr(a)));\nVerify(Tr({}),0);\nVerify(Tr({a,b}),a+b);\nVerify(Tr({{}}),0);\nVerify(Tr({{a}}),a);\nVerify(Tr({{},a}),{});\nVerify(Simplify(Tr({{a},b})-{a+b}),{0});\nVerify(Tr({{},{}}),0);\nVerify(Tr({{},{{}}}),Hold({}+{{}}));     // bug in list addition?\n//Verify(Tr({{a,b},{c}}),Hold({a,b}+{c})); // bug in list addition?\nVerify(Tr({{a,b},{c,d}}),a+d);\nVerify(Tr({{a,b},{c,d},{e,f}}),a+d);\nVerify(Tr({{a,b,c},{d,e,f},{g,h,i}}),a+e+i);\nVerify(Tr({{a,b,c},{d,e,f}}),a+e);\nVerify(Tr({{{a,b}},{{c,d}}}),a);\nVerify(Tr({{{{a},{b}}},{{{c},d}}}),{a});\nVerify(Tr({{{{{a,b}}}},{{{c,d}}}}),{{a,b}});\nVerify(Tr({{{{{a,b}}}},{{{c},{d}}}}),{{{a,b}}});\nVerify(Tr({{{}}}),0);\nVerify(Tr({{{a}}}),a);\nVerify(Tr({{{{a}}},{{{b}}}}),a);\nVerify(Tr({{{{a},{b}}},{{{c},{d}}}}),a);\nVerify(Tr({{{{a,b}}},{{{c,d}}}}),a);\nVerify(Tr({{{{a,b}},{{c,d}}}}),a);\nVerify(Tr({{{{{{a,b},{c}}}}},{{{d},{e,f,g}}}}),{{{{a, b}, {c}}}});\n\n//////\n//////\n"
  },
  {
    "path": "tests/trace.yts",
    "content": "//////\n// $Id: trace.yts,v 1.2 2006-03-26 12:49:15 ayalpinkus Exp $\n// Tests for Trace\n//////\n\nTesting(\"-- Trace\");\n\n  Verify(Trace(a),Hold(Trace(a)));\nVerify(Trace({}),0);\nVerify(Trace({a,b}),a+b);\n  Verify(Trace({{}}),0);\nVerify(Trace({{a}}),a);\n  Verify(Trace({{},a}),{});\nVerify(Simplify(Trace({{a},b})-{a+b}),{0});\n  Verify(Trace({{},{}}),0);\n  Verify(Trace({{},{{}}}),Hold({}+{{}}));     // bug in list addition?\n  Verify(Trace({{a,b},{c}}),Hold({a,b}+{c})); // bug in list addition?\nVerify(Trace({{a,b},{c,d}}),a+d);\n  Verify(Trace({{a,b},{c,d},{e,f}}),a+d);\nVerify(Trace({{a,b,c},{d,e,f},{g,h,i}}),a+e+i);\nVerify(Trace({{a,b,c},{d,e,f}}),a+e);\n  Verify(Trace({{{a,b}},{{c,d}}}),a);\n  Verify(Trace({{{{a},{b}}},{{{c},d}}}),{a});\n  Verify(Trace({{{{{a,b}}}},{{{c,d}}}}),{{a,b}});\n  Verify(Trace({{{{{a,b}}}},{{{c},{d}}}}),{{{a,b}}});\nVerify(Trace({{{}}}),0);\nVerify(Trace({{{a}}}),a);\n  Verify(Trace({{{{a}}},{{{b}}}}),a);\n  Verify(Trace({{{{a},{b}}},{{{c},{d}}}}),a);\n  Verify(Trace({{{{a,b}}},{{{c,d}}}}),a);\nVerify(Trace({{{{a,b}},{{c,d}}}}),a);\n  Verify(Trace({{{{{{a,b},{c}}}}},{{{d},{e,f,g}}}}),{{{{a, b}, {c}}}});\n\n//////\n//////\n"
  },
  {
    "path": "tests/transforms.yts",
    "content": "Verify( LaplaceTransform(t,s,1), 1/s );\nVerify( LaplaceTransform(t,s,t^3), 6/s^4);\nVerify( LaplaceTransform(t,s,t), 1/s^2 );\nVerify( LaplaceTransform(t,s,-t), -1/s^2 );\nVerify( LaplaceTransform(t,s,t*Exp(4*t)), 1/(4*(s/4-1))^2 );\nVerify( LaplaceTransform(t,s,Exp(4*t)*Cos(4*t)), (s-4)/(16*(((s-4)/4)^2+1)) );\nVerify( LaplaceTransform(t,s,-Exp(4*t)*Cos(4*t)), -(s-4)/(16*(((s-4)/4)^2+1)) );\nVerify( LaplaceTransform(t,s,t^3*Cosh(t)) Where s==2, 82/27 );\n"
  },
  {
    "path": "third_party/README.rst",
    "content": "*********************\nThird-party libraries\n*********************\n\n* CodeMirror\n  * https://github.com/Dominator008/CodeMirror-minified/archive/5.47.0.zip\n\n* MathJax\n  * https://github.com/mathjax/MathJax/archive/2.7.3.zip\n\n* Plotly.js\n  * https://cdn.plot.ly/plotly-1.49.0.min.js\n\n* vis.js\n  * https://github.com/almende/vis/archive/v4.21.0.zip\n\n"
  },
  {
    "path": "utils/pre-commit",
    "content": "#!/bin/env python\n\n\"\"\"\npre-commit hook script checking for yacas whitespace policy\n\nadapted from http://justanyone.blogspot.com/2013/05/subversion-pre-commit-hook-script.html\n\"\"\"\n\nimport sys\nimport os\nimport traceback\nfrom optparse import OptionParser\n\ndef command_output(cmd):\n    \" Capture a command's standard output. \"\n    import subprocess\n    return subprocess.Popen(cmd.split(), stdout=subprocess.PIPE).communicate()[0]\n\ndef files_changed(look_cmd):\n    \"\"\" List the files added or updated by this transaction.\n\n        \"svnlook changed\" gives output like:\n          U   trunk/file1.cpp\n          A   trunk/file2.py\n    \"\"\"\n    def filename(line):\n        return line[4:]\n\n    def added_or_updated(line):\n        return line and line[0] in (\"A\", \"U\")\n\n    retval = []\n    for line in command_output(look_cmd % \"changed\").split(\"\\n\"):\n        if added_or_updated(line):\n            retval.append(filename(line))\n\n    return retval\n\ndef file_contents(filename, look_cmd):\n    \" Return a file's contents for this transaction. \"\n    return command_output(\"%s %s\" % (look_cmd % \"cat\", filename))\n\ndef file_get_properties(filename, look_cmd):\n    propslines = command_output(\"%s %s\" % (look_cmd % \"proplist -v\", filename))\n    res = {}\n    for line in propslines.split('\\n'):\n        line = line.strip()\n        if not line:\n            continue\n        k, v = line.split(' : ')\n        res[k] = v\n    return res\n\ndef contains_tabs(filename, look_cmd):\n    \" Return True if this version of the file contains tabs. \"\n    return \"\\t\" in file_contents(filename, look_cmd)\n\ndef contains_trailing_spaces(filename, look_cmd):\n    \" Return True if this version of the file contains trailing whitespaces. \"\n    return \" \\n\" in file_contents(filename, look_cmd)\n\ndef check_src_files(look_cmd):\n    \" Check Python files in this transaction are tab-free. \"\n\n    def is_src_file(fname):\n        return os.path.splitext(fname)[1] in [\".h\", \".inl\", \".cpp\", \".java\", \".ys\", \".yts\"]\n\n    src_files_with_tabs = set()\n    src_files_with_trailing_spaces = set()\n\n    for ff in files_changed(look_cmd):\n        if not is_src_file(ff):\n            continue\n\n        if contains_tabs(ff, look_cmd):\n            src_files_with_tabs.add(ff)\n\n        if contains_trailing_spaces(ff, look_cmd):\n            src_files_with_trailing_spaces.add(ff)\n\n    prevent_commit = False\n\n    if len(src_files_with_tabs) > 0:\n        sys.stderr.write(\"The following files contain tabs:\\n%s\\n\"                                                                              % \"\\n\".join(src_files_with_tabs))\n        prevent_commit = True\n\n    if len(src_files_with_trailing_spaces) > 0:\n        sys.stderr.write(\"The following files contain trailing whitespaces:\\n%s\\n\"                                                              % \"\\n\".join(src_files_with_trailing_spaces))\n        prevent_commit = True\n\n    return prevent_commit\n\ndef main():\n    usage = \"\"\"usage: %prog REPOS TXN\n        Run pre-commit options on a repository transaction.\"\"\"\n\n    parser = OptionParser(usage=usage)\n    parser.add_option(\"-r\", \"--revision\",\n                      help=\"Test mode. TXN actually refers to a revision.\",\n                      action=\"store_true\", default=False)\n    errors = 0\n    try:\n        (opts, (repos, txn_or_rvn)) = parser.parse_args()\n        look_opt = (\"--transaction\", \"--revision\")[opts.revision]\n        look_cmd = \"svnlook %s %s %s %s\" % (\n            \"%s\", repos, look_opt, txn_or_rvn)\n        errors += check_src_files(look_cmd)\n    except:\n        parser.print_help()\n        errors += 1\n        sys.stderr.write(\"Pre-commit hook traceback: %s\" % (traceback.format_exc()))\n    return errors\n\nif __name__ == \"__main__\":\n    sys.exit(main())\n"
  },
  {
    "path": "yacas_UNINSTALL.sh",
    "content": "#!/bin/sh\n\n#  yacas_UNINSTALL.sh\n#  YACAS\n#\n#  Created by Marta Noga on 06.04.2014.\n#\n\nINSTALL_PATH=\"/usr/local\"\n\n\necho \"Removing binary\"\nrm ${INSTALL_PATH}/bin/yacas\n\necho \"Removing libraries\"\nrm ${INSTALL_PATH}/lib/libyacas.*\n\necho \"Removing scripts\"\nrm -rf ${INSTALL_PATH}/share/yacas\n\necho \"Removing headers\"\nrm -rf ${INSTALL_PATH}/include/yacas\n\nif [ APPLE ]\nthen\n  echo \"Removing framework\"\n  rm -rf /Library/Frameworks/yacas.framework\nfi"
  }
]